Skip to content

# [feat] agent: add Plan mode to the assistant - #546

Open
curealb wants to merge 7 commits into
ThinkFlowLab:mainfrom
curealb:ask-user-question
Open

curealb wants to merge 7 commits into
ThinkFlowLab:mainfrom
curealb:ask-user-question

Conversation

@curealb

@curealb curealb commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add Auto and Ask modes to the right-hand assistant, with a question summary and plan confirmation card in the conversation and an answer panel above the composer. Show options in recommendation order, keep custom answers separate from chat drafts, strip enriched decisions / tasks state via draftOf before saving drafts, and disable decision/plan mutations in multi-window preview mode.
  • Pause on ask_user, save and resume the original task, and require confirmation of the current plan revision before execution. Keep one active run chain per project alongside queued follow-up messages (POST /messages), share one-shot 409 session_expired lease recovery across JSON and SSE endpoints, merge updated conversation model selections when continuing or confirming a plan, and avoid resurrecting older historical plans after newer Ask tasks finish or are abandoned.
  • Deliver literal UTF-8 text/Markdown via opendirector asset write-text --text-file, record verifiable completion for read/inspection steps, release unbound call_id slots on pre-parse schema validation errors (plus local CLI --file "payload" envelope checks) so fixed stepOperationId commands can recover in the same turn, keep proven pre-write failures retryable with the same input, and reconcile committed writes by operation ID after a restart.
  • Support Ask in Default, OpenCode, Claude Code, Codex, and DeepSeek Harness (dsh). Unsupported runtimes (such as JiuwenSwarm) disable Ask in the UI and reject mode: ask API requests with 409 instead of silently falling back to Auto; Auto mode keeps direct execution under the existing edit-lease, node-lock, and validation rules.
  • Index and record turn timing (startedAt / finishedAt / durationMs) across ordinary turns and independent continuation/execution segments, anchor in-process session lease clocks monotonically (LocalProjects.now()) against wall-clock jumps, and display localized decision errors in the question summary and tool activity card.

Review map

  • packages/core/src/opendirector/agent/decisions.py: persistent task/decision/plan state machine, revision-scoped write gate, and crash/restart reconciliation.
  • packages/core/src/opendirector/agent/{gateway,tools}.py & packages/core/src/opendirector/cli.py: planning-stage write lock, step operation ID binding/recovery, --text-file, and ask-user / plan CLI subcommands.
  • apps/api/src/opendirector_api/agent.py & packages/core/src/opendirector/infrastructure/{local_projects,creation_projects,creation_catalog}.py: answer submission, continuation/execution SSE segments with per-segment timing in the Chain runner, and monotonic session-lease expiry.
  • src/canvas/{QuestionAnswerPanel,QuestionSummaryCard,questionAnswerDrafts,useAssistantChat,AssistantPanel}.* & src/backend/{api,chat}.ts: answer panel, summary/plan cards, per-question draft isolation, lease recovery, and preview-mode guards.
  • tests/{test_agent_decisions,test_deepseek_runtime,test_assistant_conversations,test_cli}.py & tests/browser/{assistant_sessions,jiuwenswarm_picker}.mjs: end-to-end state-machine, fault-injection, lease clock-jump, CLI forwarding, and Chromium verification.

Linked issue

#545

Labels

  • Apply type:feat, area:agent, and area:harness when opening the PR.

Test plan

  • Local:
    pytest (295 agent/CLI/lease/trace tests + 101 storage/API tests)
    node --test (1,031 frontend unit tests), npm run build, npm run check:i18n, npm run check:browser-locale, npm run check:browser-manifest
    python scripts/generate_contracts.py --check and git diff upstream/main --check
    node tests/browser/assistant_sessions.mjs (Chromium fixture run verifying Ask options, draft isolation, bilingual toggle, continuation, and plan confirmation)
  • Left to CI:
    lint-imports --no-cache (not installed in local .venv), full Python/browser Release matrix, packaging, and PR-diff pre-commit.

Evidence that it works

Auto Model

image

Plan Mode

Default Harness
image
image
image

DSH image image image
Codex image image

Provider verification

Real-provider calls and local CLI doubles are described honestly:
Live verification ran against Default (gpt-6.2-sol + gpt-image-2.5-flare), DeepSeek Harness (dsh), and Codex in isolated projects, covering structured questions, custom answers, plan revisioning, confirmation-gated execution, canvas/asset materialization, and reopening checks.
Standalone OpenCode and Claude Code share the same NativeRuntime transport and session-resume protocol; both were verified end-to-end through local CLI substitutes against the real OpenDirector API, tool gateway, and project storage (live vendor accounts for standalone OpenCode and Claude Code were not exercised in this run).

Bilingual UI

Both zh-CN and en-US message catalogs and user guides are updated together. Verified dynamic Chinese/English switching in Chromium (recommendation badge, plan confirmation actions, and step kind labels) alongside unit tests for bilingual decision tool errors.

# Conflicts:
#	apps/api/src/opendirector_api/agent.py
#	src/backend/chat.ts
#	tests/test_assistant_conversation_trace.py
## summary

- Instruct Ask continuation and plan-save replies to state key
  creative choices or trade-offs in 1 to 3 brief sentences instead of
  repeating the numbered step list rendered in the plan card below.
@github-actions github-actions Bot added area:agent Agent runtime, assistant chat and tools area:harness Harness and skill integration (Default, OpenCode, Codex, Claude Code, Jiuwen, DSH) type:feat New capability or behaviour labels Nov 27, 2026
@github-actions
github-actions Bot requested review from FayeSpica and wuzhf9 November 27, 2026 14:04
## summary

- Invalidate old autosave callbacks before installing changed remote
  content, preserving hidden nodes and valid undo operations.
- Exercise the due callback in Chromium and verify saved visibility,
  revisions, undo/redo, and viewport persistence after reopening.
- Update voice-tool fixtures to use real project storage and sessions,
  and align the CLI availability assertion with operation identity.
- Record the remote-refresh race and its validation boundary.

## validation

- 124 Python tests covering voice tools, capabilities, CLI and decisions.
- 1,031 frontend unit tests and all 32 isolated browser workflows.
- Production build, i18n, browser locale and manifest checks passed.
- Original failing cases passed with these changes on the CI merge tip.
## summary

- Hit-test the canvas before the regression's pan gesture and wait for
  the viewport transform to change before awaiting its autosave.
- Record the reproduced prompt-editor interception and why unrelated
  pending timers could mask the invalid fixed-coordinate gesture.

## validation

- The updated created_node_focus browser workflow passed with Node
  24.22.1 and Playwright 1.58.2 using local Chromium 148.
- A browser-only negative control removing the remote-refresh guard
  failed on persisted visibility: the old callback re-showed the node.
- Browser locale/manifest checks and applicable file hooks passed.
@FayeSpica

Copy link
Copy Markdown
Collaborator

@curealb please resolve conflicts

# Conflicts:
#	packages/core/src/opendirector/agent/native.py
#	packages/core/src/opendirector/agent/tools.py
#	packages/core/src/opendirector/infrastructure/creation_catalog.py
#	packages/core/src/opendirector/infrastructure/local_projects.py
#	src/backend/api.ts
@curealb

curealb commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

@curealb please resolve conflicts

@FayeSpica Conflicts with main have been resolved and pushed. I also enabled Plan mode support for the newly merged pi runtime and verified it locally.

@kunkunblueberry

kunkunblueberry commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

REQUEST CHANGES 0f89416 Refs #545

The change itself is well argued and the evidence is real: screenshots for Default and DSH, a review map naming which file holds which concern, and a local matrix that names the checks it left to CI. I am not asking for more evidence. I am asking for it in units a reviewer can actually certify.

  • The scope is at least five changes. CONTRIBUTING asks for one concern per pull request because a reviewer has to be able to hold the change in their head. This tip is 57 files and +8031/-522, and the body's own review map lists: the Plan/Ask state machine and its UI; opendirector asset write-text --text-file plus the --file payload envelope checks; releasing unbound call_id slots on pre-parse validation errors so a fixed stepOperationId can retry in the same turn; LocalProjects.now() monotonic session-lease clocks against wall-clock jumps; and the turn-timing index. The last three stand on their own and would each be reviewable in an afternoon. With all five in one diff, "the ask/plan semantics are correct" cannot be asserted by me or anyone else — and that is the part that must be right, since it pauses a turn, persists task state and gates writes on a plan revision.
  • Please split at least the transport/CLI fixes and the lease-clock change out of the Plan mode PR. If any of them is a hard prerequisite for the state machine, say which and why in one line; a genuine prerequisite is a reason to order the commits, not to leave them unreviewed.

Two smaller items:

  • The linked issue is a bare URL (https://github.com/.../issues/545). The template asks for Fixes #N or Refs #N, and the choice matters here: the body's "does not add retract/withdraw" and the preview-mode guards suggest the issue stays open.
  • You add startedAt / finishedAt / durationMs and segmentKind to the persisted turn index. [perf] agent: record where a turn spends its time (#449) #469 merged separately and records call-level spawn / work in agent-runs/timing/<turn>.json. I checked and these are not duplicates — yours is wall-clock per message and segment, [perf] agent: record where a turn spends its time (#449) #469's is monotonic per call — but a reader will ask. One sentence stating what each answers and which one a future performance question should read would settle it.

Ran: gh pr checks 546 on 0f89416 (13/13 pass); read the body, the review map, the file list, the i18n pairing, and the timing additions to the turn index; confirmed the base is current main (6e0b22a) so the diff is not inflated by a stale branch.
Not run: any local test. I did not review 8k lines in one pass, which is the substance of this verdict: read decisions.py, the gateway/tools write gate, and the answer/plan path end to end, then the transport changes on their own, and I will review the pieces.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent runtime, assistant chat and tools area:harness Harness and skill integration (Default, OpenCode, Codex, Claude Code, Jiuwen, DSH) type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants