Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
920 changes: 794 additions & 126 deletions apps/api/src/opendirector_api/agent.py

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions apps/api/src/opendirector_api/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@
"local_only": "Only this computer can access the project service.",
"cross_origin": "File access from another site is not allowed.",
"invalid_local_request": "This is not a valid local app request.",
"ask_mode_runtime_unsupported": "Ask mode is available for Default, OpenCode, Claude Code, Codex, DeepSeek Harness, and Pi only.",
"task_waiting_input": "This task is waiting for the user to answer the current question. Subsequent operations are paused.",
"plan_confirmation_required": "This task is in the interactive planning stage. Confirm the current plan before modifying the project or starting generation.",
"decision_answer_invalid": "Check the answers for each question and try again.",
"decision_answer_conflict": "A different answer was already submitted for this question in another tab. Showing the saved answer.",
"decision_version_invalidated": "Related assets or the plan version changed. This question is no longer valid and will not overwrite newer content.",
"decision_not_answered": "Save an answer to this question before continuing the task.",
"continuation_resume_failed": "Could not start the continuation. Check the Agent configuration and try again.",
"continuation_status_unknown": "The previous execution status needs verification. To avoid duplicate paid calls, it was not resent automatically.",
"plan_missing": "This task does not have a confirmable plan revision yet.",
"plan_revision_stale": "The plan version changed and the previous confirmation is no longer valid. Confirm the latest plan version.",
"plan_step_kind_mismatch": "Only inspection steps can record an inspection result.",
"task_conversation_changed": "Return to the task's original conversation to continue.",
"task_model_unavailable": "The original Agent model configuration could not be resolved.",
"project_assistant_busy": "Another reply is currently running in this project. Wait for it to finish and then continue.",
}

ENGLISH_BY_STATUS = {
Expand Down
26 changes: 24 additions & 2 deletions docs/architecture/agent-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,33 @@ On Windows, Codex explicitly sets `windows.sandbox="elevated"` so ignoring user

CLI 通过环境变量中的本轮本地 Socket 地址连接业务网关,不使用连接令牌或凭据文件。网关继续校验工程范围、轮次生命周期及业务输入。

## 交互式规划与恢复 / Interactive planning and recovery

右侧助手默认使用自动模式。Default、OpenCode、Claude Code、Codex 和 DeepSeek Harness 可选择询问模式。其他运行时在界面禁用询问入口,API 收到显式 `mode: ask` 时返回 `409 ask_mode_runtime_unsupported`。由 `mode: ask` 或显式 `planOnly: true` 进入规划阶段。规划与接续阶段允许查询和规划工具,工程写入和生成提交须经当前计划版本授权。

`agent-runs/decisions.json` 随工程保存任务、题组、答案、计划版本、已确认版本和执行回执。任务及其申请、回答、接续与执行标识关联原会话。`ask_user` 使当前片段进入等待回答,释放工程的运行名额。答案保存后,接续使用固定的续跑 ID,并按该任务最新要求保存计划。确认以计划版本为准,改版后旧确认失效。

提交答案返回任务和决策回执,调整计划返回更新后的任务。回执中的 `task.conversationId` 标识所属会话。完整会话通过助手会话接口或流事件读取。

计划步骤保存为 `write`、`read` 或 `inspection`,文本步骤采用 `write`。写入步骤凭业务回执完成。只读步骤凭使用对应操作 ID 的查询结果完成,原生检查步骤通过 `plan complete-step` 登记结果。CLI 的 `asset write-text --file` 接受命令 JSON,`--text-file` 接受字面文本,两者均可用 `-` 读取标准输入。文本大小限制按解码后的内容计算。

执行前记录操作 ID、输入指纹及 `pendingWrites`。确认发生在业务提交前的文件读取和本地校验失败会清除待处理记录,并保留按原操作 ID 和输入重试的能力。DeepSeek 完成 ACP 初始化和模型配置后,在发送 `session/prompt` 前记录模型派发。重启时根据新版计划的接续 ID 和已提交业务回执恢复状态,时间线导入也核对最终批次回执。读取失败和状态未明的远端提交保留待核对记录。

English summary: the right-hand assistant defaults to Auto. Default, OpenCode, Claude Code, Codex, and DeepSeek Harness support Ask mode. The UI disables Ask on other runtimes, and an explicit unsupported `mode: ask` request receives `409 ask_mode_runtime_unsupported`. Ask or explicit `planOnly: true` enters planning. Planning and continuation permit read and planning tools. Project writes and generation submissions require authorization for the current plan revision.

The project stores tasks, question groups, answers, plan revisions, confirmations, and execution receipts in `agent-runs/decisions.json`. Questions, answers, continuations, and execution segments belong to the original conversation. `ask_user` pauses the segment and releases the project's run slot. A saved answer has a stable continuation ID. A revised plan supersedes authorization for the previous revision.

Submitting answers returns the task and decision receipt. Adjusting a plan returns the updated task. Both identify the owning conversation through `task.conversationId`. Read the full conversation through the assistant conversation endpoint or stream.

Plan step kinds are `write`, `read`, and `inspection`. A plain text step defaults to `write`. Write steps require business receipts, read steps record queries under the matching operation ID, and native inspection steps record their findings via `plan complete-step`. The CLI accepts command JSON via `asset write-text --file` and literal content via `--text-file`. Either option accepts `-` for standard input. The asset size limit applies to the decoded text.

Before dispatch, the service records the operation ID, input fingerprint, and `pendingWrites` entry. Confirmed preflight failures clear the pending write and allow retry with the same ID and input. DeepSeek records model dispatch after ACP setup and immediately before sending `session/prompt`. Restart recovery uses the saved plan's continuation ID and authoritative business receipts, including the final batch receipt for timeline imports. Unreadable records and uncertain remote submissions remain pending verification.

## 对话轨迹页 / Conversation trace page

轨迹页 `/?traceProject=…&conversation=…&turn=…` 在一页内按顺序列出一个对话的全部已执行轮次,每轮可独立展开,展开时才读取该轮日志与关联 Job;“下载原始轨迹”是用户显式触发的例外,见下。轮次索引来自只读接口 `GET .../assistant/conversations/{conversation_id}/trace`,它解析当前对话、已归档对话和 `reusedCreateIds` 别名,只返回轮次元数据(序号、用户输入摘要、运行时、状态),不读取日志正文,不激活对话,不获取编辑租约。轮次由持久化的身份关系确定:用户消息与 id 为 `uuid5(用户消息 id, 'assistant')` 的助手消息成对才算已执行的一轮;没有该助手记录的用户消息(例如排队中、未执行)不出现。每轮使用自己记录的运行时选择日志源和解析器,仅 Default(opencode)显示模型原始请求。`GET .../traces/{turn_id}/conversation` 供旧的单轮链接查找所属对话;找不到时保持原单轮页面。
轨迹页 `/?traceProject=…&conversation=…&turn=…` 在一页内按顺序列出一个对话的全部已执行轮次和独立分段,每项可独立展开,展开时才读取其日志与关联 Job;“下载原始轨迹”是用户显式触发的例外,见下。轮次索引来自只读接口 `GET .../assistant/conversations/{conversation_id}/trace`,它解析当前对话、已归档对话和 `reusedCreateIds` 别名,只返回序号、摘要、运行时、状态等元数据,不读取日志正文,不激活对话,不获取编辑租约。普通轮次由持久化的身份关系确定:用户消息与 id 为 `uuid5(用户消息 id, 'assistant')` 的助手消息成对才算已执行的一轮,只计一次;没有该助手记录的用户消息(例如排队中、未执行)不出现。`segmentKind` 为 `continuation` 或 `execution` 的独立助手消息按自己的 `turnId` 入列。每项使用自己记录的运行时选择日志源和解析器,仅 Default(opencode)显示模型原始请求。`GET .../traces/{turn_id}/conversation` 供旧的单轮链接查找所属对话;找不到时保持原单轮页面。

English summary: the trace page lists every executed turn of a conversation, expanded one at a time, and reads a turn's logs and linked Jobs only when it is opened; the user-triggered original trace download is the one exception (below). The turn index comes from the read-only `GET .../assistant/conversations/{conversation_id}/trace`, which resolves current, archived and aliased (`reusedCreateIds`) conversation ids and returns metadata only (number, input summary, runtime, status). It never reads log bodies, activates a conversation or takes a lease. A turn is a user message paired with the assistant message whose id is `uuid5(user id, 'assistant')`, so queued or never executed user messages are not listed. Each turn uses its own recorded runtime for the log source and parser, and raw model requests are offered for the Default (opencode) runtime only. `GET .../traces/{turn_id}/conversation` lets old single-turn links find their conversation; when none is found the single-turn page remains.
English summary: the trace page lists every executed turn and standalone segment of a conversation, expanded one at a time, and reads a row's logs and linked Jobs only when it is opened; the user-triggered original trace download is the one exception (below). The turn index comes from the read-only `GET .../assistant/conversations/{conversation_id}/trace`, which resolves current, archived and aliased (`reusedCreateIds`) conversation ids and returns metadata only (number, summary, runtime, status). It never reads log bodies, activates a conversation or takes an editing lease. An ordinary turn is a user message paired with the assistant message whose id is `uuid5(user id, 'assistant')`, appearing once, so queued or never executed user messages are not listed. Standalone assistant records with `segmentKind` of `continuation` or `execution` appear under their own `turnId`. Each row uses its own recorded runtime for the log source and parser, and raw model requests are offered for the Default (opencode) runtime only. `GET .../traces/{turn_id}/conversation` lets old single-turn links find their conversation; when none is found the single-turn page remains.

轨迹浏览使用 `GET .../traces/{turn_id}/{source}?cursor=…` 按字节读取追加日志。空游标从头开始,之后使用响应返回的游标;每个响应最多读取 512 KiB。浏览器跨响应保留未完成的 UTF-8 和 JSONL 记录,并增量合并同一消息或工具调用。回合结束后,浏览器读完剩余字节即停止轮询。无游标的同一路径继续提供原始文件。

Expand Down
2 changes: 2 additions & 0 deletions docs/development/lessons.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ When work exposes a consequential risk or a recurring problem, add a lesson or u
- **Lesson:** A timer may run after the editor's saving flag clears but before React installs the new document. Comparing that old closure against the new baseline can turn a view-only save into a business rollback, invalidating a previously captured publication version.
- **Check:** Invalidate scheduled automatic callbacks when the editor transaction starts, drain queued saves and explicitly persist the current draft before the edit. Preserve publication CAS checks. Exercise the real due callback at the acknowledgment boundary; isolate projection-test gates by snapshot identity, assert release/restoration and always clean up. Distinguish a forced reproduction from proof of the exact CI schedule.
- **Queued-edit follow-up:** The H3 browser regression in [PR #266](https://github.com/ThinkFlowLab/OpenDirector/pull/266) holds the first import's background hydration until the second import queues an edit. A ref updated during render can still describe the old document; a late refresh then replaces both nodes with one. Track requested and rendered history writes, defer refreshes while they differ, and recheck when hydration finishes. Resume after a no-op write too. Verify both saved nodes, their bytes, and subsequent edits after reopening. / **排队编辑补充:** React 尚未显示的编辑也需要保护;后台刷新必须检查已经请求的修改,并在页面更新后继续。回归检查两张图片的保存内容及重开后的编辑,不能把人工控制的执行顺序当作原 CI 顺序的证明。
- **Remote-refresh follow-up:** Investigating [PR #546's undo failure](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/46012590478/job/140551857483) reproduced a due autosave publishing `canvas.show` after a remote hide installed its baseline, causing undo to reject the changed field. Invalidate preceding callbacks before installing changed background content; retain pending view saves when the content is unchanged. Exercise the real due callback at that boundary, inspect persisted visibility and revision, and verify undo/redo and view persistence. The controlled reproduction does not establish the exact original CI schedule. / **后台刷新补充:** 新内容成为保存基线前,应使旧自动保存回调失效;内容未变化时保留待保存的视图。用真实到期回调验证隐藏状态、版本、撤销重做及视图持久化,不能将人工复现顺序当作原 CI 顺序的证明。
- **Gesture setup follow-up:** [The next PR #546 run](https://github.com/ThinkFlowLab/OpenDirector/actions/runs/46024450895/job/140592409452) timed out waiting for that callback. Local inspection reproduced a fixed-coordinate drag hitting the selected node's prompt editor without moving the viewport. Hit-test exposed canvas and assert the viewport changes before waiting for its autosave; unrelated pending timers can otherwise mask a broken setup. / **手势准备补充:** 固定坐标拖动可能落在所选节点的提示词编辑器,未移动画布却等待保存。应先命中无遮挡画布并验证视图变化,避免其他待保存定时器掩盖准备步骤失败。
- **Preset editor follow-up:** Selecting an image preset used to queue a settings edit and a prompt-chip edit that still held the old settings. Render the chip from the saved preset and publish preset changes caused by prompt editing in the same command as the prompt. Check the saved parameters after autosave and reopening. Chrome can move the caret past a wrapped hint through native mouse-down selection. Verify the caret's rendered position after the chip with a visible multiline hint before releasing the button. Check that typing replaces the hint, retains the first character and saves only the user's text.
- **Preset submission follow-up:** Treat the selected preset as a prompt in both the button preflight and the generation service. Freeze its instructions in the accepted job, since updating only the draft's plain prompt can be ignored by structured references and can duplicate instructions on a second run. Check preset-only submission, the structured provider prompt, and adoption without modifying the draft.
- **Image preset prompt variants:** Use the resolved image inputs to choose between image-guided and text-guided instructions. Publish both variants so the preview can make the same choice from usable references. Check that enabling face emphasis and adding or removing the last image change both the preview and the submitted prompt. Keep the ordered steps of multi-shot presets in both variants.
Expand Down
2 changes: 2 additions & 0 deletions docs/guides/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ Click a source number to view its full URL in a bordered information card, then

Click **Chat with AI** at the bottom right, select a chat model, and describe what you want to create. You can upload, drag and drop, or paste assets, or type `@` to reference canvas content. The assistant can save text as requested and call configured generation models to create assets.

With Default, OpenCode, Claude Code, Codex, or DeepSeek Harness, choose **Ask** beside the composer to plan interactively. You can select a numbered option on the question card or type your own answer directly in the chat box below. When the assistant is waiting for an answer, you can switch conversations. Refreshing the page or returning to a conversation with an unfinished Ask plan restores **Ask**. Review the current plan and select **Confirm and execute** when you want the assistant to act. Steps that submit generation jobs show progress until their jobs finish. If a step is rejected, adjust and confirm a new revision. If execution status needs verification after an interruption, check the saved results before retrying.

When the latest reply offers next steps, three to five suggested replies appear beneath it and stay visible as you type. Select one to fill the composer or replace the text you have already written. Attachments, references and skills stay in your draft. You can edit the text or undo the replacement. Press **Send** or `Enter` when you are ready.

Use **New conversation** at the top of the panel to start a separate chat. **Conversation history** lets you search and switch between this canvas's conversations. Switching saves your draft and restores the selected conversation's messages, reference attachments, and model choices; the active conversation also survives a page reload. Wait for uploads or replies to finish, or stop the reply, before switching.
Expand Down
2 changes: 2 additions & 0 deletions docs/guides/user-guide.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ Codex 网页检索引用在具有匹配来源时显示为编号链接;复制

点击右下角“与 AI 对话”,选择对话模型后输入创作要求。可上传、拖放、粘贴素材,或输入 `@` 引用画布中的内容。助手可按要求保存文本,并调用已配置的生成模型制作素材。

使用 Default、OpenCode、Claude Code、Codex 或 DeepSeek Harness 时,可在输入区选择「询问」来交互式规划。问题卡片弹出后可直接点选编号选项,也可以直接在下方聊天输入框填写其他回答并发送。助手等待回答时可以切换会话。刷新页面或回到还有未完成询问计划的会话时,输入区会恢复「询问」。审阅当前计划后,选择「确认并执行」开始交付。提交生成任务的步骤会显示进度,直到任务完成。若某一步明确被拒绝,可以调整并确认新版计划。若中断后显示「执行状态待核对」,请先检查已保存的产物再决定是否重试。

当助手在最新回复中给出后续建议时,回复下方会显示 3~5 个建议回复按钮,输入时仍可参考。点选一条即可填入输入框,替换已有文字,保留附件、引用和技能。你可以继续编辑或撤销替换,准备好后点击「发送」或按 `Enter`。

点击对话框顶部“新建”开始独立会话;点击“历史会话”可搜索并切换当前画布的旧会话。切换前会保存草稿,切回后恢复消息、参考附件和模型选择,刷新页面仍保留当前会话。回复或参考上传进行中,请先等待完成或停止回复后再切换。
Expand Down
Loading
Loading