Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
830714c
[docs] web: propose Agent and canvas workspace modes
congw729 Nov 17, 2026
af82227
[feat] workspace: persist the selected workspace mode
congw729 Nov 17, 2026
f3349c1
[feat] workspace: add Agent mode and a left-chat canvas layout
congw729 Nov 17, 2026
b30f15a
[test] workspace: cover mode switching and canvas interactions
congw729 Nov 17, 2026
cdadcfb
[test] canvas: use canvas bounds for interaction coordinates
congw729 Nov 17, 2026
3cfed8f
[fix] assistant: preserve active controls when chat loads
congw729 Nov 17, 2026
23c07d7
Merge remote-tracking branch 'origin/main' into codex/issue-373-works…
congw729 Nov 22, 2026
05d32e1
[feat] web: rename chat and canvas creation modes
congw729 Nov 22, 2026
b6a4c62
[test] web: scope model category choices to settings navigation
congw729 Nov 22, 2026
3475c11
[feat] web: add movable chat and simplify canvas creation tools
congw729 Nov 22, 2026
016148a
[chore] Merge main into the workspace modes branch
congw729 Nov 22, 2026
30ce51e
[test] canvas: reconnect through the source node's visible port
congw729 Nov 22, 2026
18e168c
[test] assistant: resize suggested replies from the left dock
congw729 Nov 22, 2026
bf16c17
[feat] assistant: show project results in chat creation
congw729 Nov 22, 2026
ff1b8e7
[feat] workspace: edit project media and timelines from chat
congw729 Nov 23, 2026
c401082
[test] workspace: pin the performance fixture locale
congw729 Nov 23, 2026
829feec
[chore] workspace: merge media model defaults from main
congw729 Nov 23, 2026
1ccb478
[test] assistant: wait for chat readiness after workspace reload
congw729 Nov 23, 2026
9a96419
[feat] web: guide first canvas setup and simplify chat docking
congw729 Nov 23, 2026
30085b7
Merge remote-tracking branch 'origin/main' into codex/issue-373-works…
congw729 Nov 23, 2026
cc06b1d
[bugfix] workspace: keep chat edits private and route model setup
congw729 Nov 25, 2026
fae0d67
[bugfix] workspace: preserve editing roles across chat and canvas
congw729 Nov 25, 2026
7d34aa8
[bugfix] agent: preserve result ownership across queued turns
congw729 Nov 25, 2026
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
85 changes: 64 additions & 21 deletions apps/api/src/opendirector_api/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ def path(self, project_id: UUID, session: str | None = None) -> Path:

def update(self, project_id: UUID, session: str | None = None, *, draft: Draft | None = None,
begin: dict | None = None, finish: dict | None = None, conversation_id: UUID | None = None,
finish_turn_id: UUID | None = None, edited_documents: dict[str, int] | None = None,
before_begin=None, agent_session: str | None = None) -> dict:
with self.projects.local.transaction() as db:
self.projects._recover()
directory, _, _ = self.projects._load(db, project_id)
directory, _, records = self.projects._load(db, project_id)
if session:
self.projects._lease(db, project_id, directory, session, browser_only=True)
folder = child(directory, 'agent-runs')
Expand All @@ -147,7 +148,10 @@ def update(self, project_id: UUID, session: str | None = None, *, draft: Draft |
value.update(draft.model_dump(mode="json", exclude={"conversationId"}))
changed = True
if begin is not None:
if any(message['id'] == begin['id'] for message in value['messages']):
# Tool commands and completed jobs use project + turn as their origin.
if any(message['id'] == begin['id']
for conversation in [value, *value.get('archivedConversations', [])]
for message in conversation['messages']):
raise ProjectError('这条消息已接受,请读取对话,不要重复发送。', 409)
if before_begin is not None:
before_begin()
Expand All @@ -160,6 +164,29 @@ def update(self, project_id: UUID, session: str | None = None, *, draft: Draft |
value.update(draft='', draftContent=None, assets=[], skills=[])
changed = True
if finish is not None:
# Unlike job results, directly published files can later be deleted.
# Keep just their immutable identity with the reply that delivered them.
if finish_turn_id is not None:
snapshot = records[0].snapshot
outputs = [{'id': str(asset.id), 'name': asset.name, 'fingerprint': asset.fingerprint}
for asset in snapshot.assets if asset.provenance.source == 'agent_written'
and asset.provenance.agentRunId == finish_turn_id]
if outputs:
finish = {**finish, 'publishedAssets': {'projectId': str(project_id),
'eventCursor': snapshot.eventCursor, 'assets': outputs}}
if edited_documents:
owners = {str(item.binding.objectRef.id): item for item in snapshot.canvasItems
if item.kind == 'timeline'}
timelines = []
for doc in snapshot.editorDocuments:
revision = edited_documents.get(str(doc.id))
if doc.kind == 'timeline' and revision is not None:
owner = owners.get(str(doc.id))
timelines.append({'editorId': str(doc.id), 'revision': revision,
'itemId': str(owner.id) if owner else None, 'title': owner.title if owner else ''})
if timelines:
finish = {**finish, 'publishedTimelines': {'projectId': str(project_id),
'eventCursor': snapshot.eventCursor, 'timelines': timelines}}
value['messages'] = [finish if message['id'] == finish['id'] else message for message in value['messages']]
changed = True
if changed:
Expand All @@ -177,15 +204,17 @@ def queue(self, project_id: UUID, session: str, message: dict, conversation_id:
with self.projects.local.transaction() as db:
self.projects._recover()
directory, _, _ = self.projects._load(db, project_id)
self.projects._lease(db, project_id, directory, session)
self.projects._lease(db, project_id, directory, session, browser_only=True)
folder = child(directory, 'agent-runs')
folder.mkdir(exist_ok=True)
file = child(folder, 'conversation.json')
value = read_json(file) if file.exists() else {'messages': [], **Draft().model_dump()}
value['conversationId'] = value.get('conversationId') or str(uuid5(project_id, 'assistant'))
if conversation_id is not None and str(conversation_id) != value['conversationId']:
raise ProjectError('当前对话已切换,请重新加载后重试;原对话未覆盖。', 409)
if any(item['id'] == message['id'] for item in value['messages']):
if any(item['id'] == message['id']
for conversation in [value, *value.get('archivedConversations', [])]
for item in conversation['messages']):
raise ProjectError('这条消息已接受,请读取对话,不要重复发送。', 409)
if 'queueSeq' in value:
value['_queueSeq'] = value.pop('queueSeq')
Expand All @@ -208,8 +237,6 @@ def dispatch(self, project_id: UUID, session: str | None = None,
directory, _, _ = self.projects._load(db, project_id)
if session:
self.projects._lease(db, project_id, directory, session)
if agent_session is not None:
self.projects.local.start_agent_session(db, project_id, directory, agent_session)
folder = child(directory, 'agent-runs')
folder.mkdir(exist_ok=True)
file = child(folder, 'conversation.json')
Expand All @@ -218,6 +245,8 @@ def dispatch(self, project_id: UUID, session: str | None = None,
pending = next((item for item in value['messages'] if item.get('status') == 'queued'), None)
if pending is None:
return None
if agent_session is not None:
self.projects.local.start_agent_session(db, project_id, directory, agent_session)
index = value['messages'].index(pending)
pending['status'] = 'complete'
value['messages'].insert(index + 1, {
Expand Down Expand Up @@ -599,14 +628,13 @@ async def prepare(project_id: UUID, value: Turn, session: str, accept_language:
'thinking': value.thinking, 'status': 'complete',
**({'modelConfigId': str(value.modelId)} if value.modelId else {})}}

async def plan_for(project_id: UUID, message: dict, session: str, accept_language: str | None) -> dict:
async def plan_for(project_id: UUID, message: dict, session: str, directory: Path, accept_language: str | None) -> dict:
"""Settings for a message that was accepted earlier and is due now.

The message was validated when the user sent it, so this rebuilds the
run settings without rejecting input that is already typed: a model that
has disappeared in the meantime falls back to the runtime default.
"""
directory = await asyncio.to_thread(conversations.path, project_id, session)
spec = runtime_spec(message['runtime'])
config = None
if spec.modelSource == 'settings' and message.get('modelConfigId'):
Expand All @@ -631,10 +659,11 @@ async def produce_one(chain: Chain, plan: dict) -> tuple[dict | None, str | None
turn_id = UUID(message['id'])
text, status, error = '', 'complete', None
activities: list[dict] = []
edited_documents: dict[str, int] = {}
sources: dict = {}
previous_sources: dict = {}
steps = None
run_session = plan.get('run_session') or chain.session
run_session = plan['run_session']
timing: dict = {}
turn_started = time.monotonic()
renewal: asyncio.Task | None = None
Expand Down Expand Up @@ -679,7 +708,7 @@ async def renew_session() -> None:
session=run_session, directory=plan['directory'], config=plan['config'], messages=context,
selected_skills=message.get('skills') or [], thinking=plan['thinking'],
model_selections=plan['model_selections'], runtime_model=message.get('runtimeModel'),
skills=plan['available'], conversation_id=chain.conversation_id)
skills=plan['available'], conversation_id=chain.conversation_id, edited_documents=edited_documents)
async with aclosing(runtimes.stream(run)) as stream:
async for event in stream:
if event['type'] == 'delta':
Expand Down Expand Up @@ -735,7 +764,8 @@ async def renew_session() -> None:
'model': plan['model'], 'modelIsCliDefault': plan.get('model_is_cli_default', False),
'runtime': message['runtime'], 'thinking': plan['thinking'], 'tools': activities,
'sources': list(sources.values()),
**({'plan': steps} if steps is not None else {})}, conversation_id=chain.conversation_id)
**({'plan': steps} if steps is not None else {})}, conversation_id=chain.conversation_id,
finish_turn_id=turn_id, edited_documents=edited_documents)
except Exception:
logger.exception(f'agent.turn.unfinished project_id={project_id} turn_id={turn_id}')
saved = None
Expand All @@ -745,17 +775,19 @@ async def renew_session() -> None:
with suppress(asyncio.CancelledError):
await renewal
try:
# Measurement and the lease are both best effort: losing
# either may cost a file or a lock, never the turn's reply.
await asyncio.to_thread(agent_timing.write, plan['directory'], turn_id, timing,
round(time.monotonic() - turn_started, 3))
if plan.get('run_session'):
await asyncio.to_thread(projects.local.release_agent_session, plan['run_session'])
except Exception:
logger.exception(f'agent.turn.timing.failed project_id={project_id} turn_id={turn_id}')
chain.last = saved
return saved, error, status

async def release_session(session: str) -> None:
try:
await asyncio.to_thread(projects.local.release_agent_session, session)
except Exception:
logger.exception('Could not release Agent project write session')

async def run_chain(chain: Chain, plan: dict) -> None:
"""Run a turn, then take the next queued message until the queue is empty.

Expand All @@ -766,29 +798,40 @@ async def run_chain(chain: Chain, plan: dict) -> None:
"""
project_id = chain.project_id
turn_id, saved, error, status = chain.turn, None, None, 'complete'
run_session = plan['run_session']
try:
while True:
saved, error, status = await produce_one(chain, plan)
turn_id = UUID(plan['message']['id'])
if status != 'complete' or chain.stopped:
break
run_session = str(uuid4())
next_session = str(uuid4())
async with admission.setdefault(project_id, asyncio.Lock()):
# The queue was admitted by the browser. Authorize its
# successor under the still-live project lease of this turn.
dispatched = None if chain.stopped else await asyncio.to_thread(
conversations.dispatch, project_id, chain.session, run_session)
if dispatched is None:
break
conversations.dispatch, project_id, run_session, next_session)
if dispatched is None:
# Keep admission closed until the empty chain releases
# its lease and synchronously leaves the active slot.
await release_session(run_session)
run_session = None
break
previous_session, run_session = run_session, next_session
await release_session(previous_session)
chain.turn = UUID(dispatched['message']['id'])
chain.events.put({'type': 'end', 'turnId': str(turn_id), 'nextTurnId': str(chain.turn),
'conversation': dispatched['conversation'], 'error': None})
plan = await plan_for(project_id, dispatched['message'], chain.session, None)
plan = await plan_for(project_id, dispatched['message'], chain.session, plan['directory'], None)
plan['start'] = dispatched['conversation']
plan['run_session'] = run_session
saved = None
except asyncio.CancelledError:
status, error = 'stopped', None
raise
finally:
if run_session is not None:
await release_session(run_session)
chain.events.put({'type': 'end', 'turnId': str(turn_id), 'nextTurnId': None,
'conversation': saved if saved is not None else chain.last, 'error': error})
if active.get(project_id) is chain:
Expand Down Expand Up @@ -907,7 +950,7 @@ async def message(project_id: UUID, value: Turn, x_opendirector_session: UUID =
dispatched = await asyncio.to_thread(conversations.dispatch, project_id, session, start_session)
if dispatched is None:
raise ProjectError('这条消息未能开始执行,请重新发送。', 409)
started = await plan_for(project_id, dispatched['message'], session, accept_language)
started = await plan_for(project_id, dispatched['message'], session, plan['directory'], accept_language)
started['start'] = dispatched['conversation']
started['run_session'] = start_session
return launch(project_id, started, UUID(dispatched['conversation']['conversationId']))
Expand Down
17 changes: 14 additions & 3 deletions apps/desktop/scripts/smoke-window.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,20 @@ async function smokeTraceWindows(window, projectId) {
.then(response => response.json()).then(({projects}) => projects.find(project => project.id === '${projectId}').path)`);
const folder = join(projectPath, 'agent-runs');
mkdirSync(folder, { recursive: true });
await evaluate("document.querySelector('.cw-chat-button').click()");
const openedChat = await evaluate(`(() => {
const toggle = document.querySelector('.cw-chat-button');
if (toggle.getAttribute('aria-expanded') === 'true') return false;
toggle.click();
return true;
})()`);
const editor = ".cw-assistant-composer [contenteditable=true]";
await waitFor(() => evaluate(`!!document.querySelector(${JSON.stringify(editor)})`), 'Assistant composer did not open');
await waitFor(() => evaluate(`document.querySelector(${JSON.stringify(editor)})?.checkVisibility()`), 'Assistant composer did not open');
await waitFor(() => evaluate(`(() => {
const chat = document.querySelector('#canvas-assistant').getBoundingClientRect();
const canvas = document.querySelector('.cw-canvas-region').getBoundingClientRect();
const sidebar = document.querySelector('.cw-workspace[data-desktop-sidebar=open] .od-project-sidebar');
return chat.left >= (sidebar?.getBoundingClientRect().right ?? 0) && chat.right <= canvas.left;
})()`), 'The project sidebar, conversation and canvas overlap');
await evaluate(`document.querySelector(${JSON.stringify(editor)}).focus()`);
await window.webContents.insertText('Draft before opening trace');
const draft = () => evaluate(`document.querySelector(${JSON.stringify(editor)})?.textContent`);
Expand Down Expand Up @@ -433,7 +444,7 @@ async function smokeTraceWindows(window, projectId) {
await evaluate(`document.querySelector(${JSON.stringify(editor)}).focus()`);
await window.webContents.insertText(' and continued afterward');
await waitFor(async () => (await draft())?.includes('continued afterward'), 'Assistant composer stopped accepting input');
await evaluate("document.querySelector('.cw-chat-button').click()");
if (openedChat) await evaluate("document.querySelector('.cw-chat-button').click()");
}

async function waitFor(check, message, attempts = 150) {
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This directory is the entry point for the repository's shared documentation. The
| [Development guidance](../AGENTS.md) | Product direction and enduring principles | Architecture principles or product boundaries change |
| [Contributing](../CONTRIBUTING.md) | Label taxonomy, how to pick labels, and what a PR must satisfy | Process, labels, or submission requirements change |
| [Unified project architecture](architecture/unified-project.md) | Business objects, shared entry points, and interaction rules | Object responsibilities, commands, persistence, or interaction rules change |
| [Workspace modes RFC (中文)](architecture/workspace-modes-rfc.zh-CN.md) | Chat and canvas creation, first-run selection, docked and floating chat, result editing, and acceptance criteria | The mode design or its acceptance criteria change |
| [Desktop architecture](architecture/desktop.md) ([中文](architecture/desktop.zh-CN.md)) | Electron, the Python Host, project storage, and shutdown behavior | Process, request, storage, or lifecycle boundaries change |
| [Test contracts](architecture/test-contracts.md) | Test/production boundaries, how to avoid stale assertions and environment-dependent red runs | Test infrastructure, capability gates, or contract ownership change |
| [Capability mapping contract](architecture/capability-contract.md) | Evidenced upstream vocabulary, the `(operation, profile) → capability` table, the untranslatable declarations, and how it feeds discovery | Upstream vocabulary, capability ids, or discovery matching change |
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading