Skip to content
Closed
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
2 changes: 1 addition & 1 deletion docs/design/contracts/resource-owner-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ draining its admitted work before unloading.
| --- | --- | --- |
| Agents, Session catalog, grants and worktree clients → store → sqliteStorage | Reuse the store request/reply shapes for `createOwnedSession, fork, owner, creationRecord, hasRecords, sessionConfig, sessionConfigText, catalog, addGrant, removeGrant, grants, setSessionLanguage, associateWorktree, worktreeDirectories, worktreeUsages, sessionsUnderWorkspace, removeWorktreeDirectory`. | SQLite creates the Session, main branch, ownership and optional worktree association in one transaction. Fork uses bounded copy transactions on its own connection; only the final transaction inserts the Session row and makes the fork visible. Association commits the directory and Session link together. |
| Session deletion and worktree removal → store | `store.delete` uses `sqliteStorage.hasRecords, removableOutputDirectories, touchWorktreeDirectories, rollbackSession`. `store.removeWorktree` uses the existing association/workspace checks and directory deletion; `store.removeUnregisteredDirectory` uses the existing directory-record and workspace checks and the caller's deletion. | SessionStore holds its ownership lock across the checks and the filesystem removal, including a recursive `--force` deletion with no time limit, so Session creation, fork, deletion and worktree association or removal wait for it. Dropping the caller does not release the lock while the removal runs. SQLite owns each database step. File deletion and Git removal run outside SQL transactions. |
| SessionTitle and Session rename → store → sqliteStorage | `readMetadata(sessionId)`, `setTitle(existing title request)`; existing metadata replies. FileAccess → `store.associateWorktree` with the existing association record. | SQLite checks the title revision and commits the write. SessionStore serializes title writes and publishes the committed notice before admitting the next one. |
| SessionTitle and Session rename → store → sqliteStorage | `title({id}) → {revision, title?: {text, source}}`, `setTitle({id}, change) → {revision}` ([SessionTitle](../plugins/SessionTitle.md#own-contract), target, pending [#2091](https://github.com/arcships/dim/pull/2091)); FileAccess → `store.associateWorktree` with the existing association record. | The change decides the next title under SessionStore's serialization; SQLite commits it and SessionStore publishes the committed notice before admitting the next write. |
| Timeline clients → timelineStore; SessionStore → sqliteStorage | Bind existing `createSession, rollbackSession, releaseSession, sessionConfig, branches, head, batchEnd, batchEndAt, readPage, readSegments, query, trace, saveSnapshot, latestSnapshot` requests at the native boundary. `commitTimelineRound({batches: Append[]}) → {sessions: [{sessionId, result}]}` accepts ordered batches grouped by Session. | SessionStore admits appends synchronously, groups the existing writer round, and serves commit subscriptions and release/drain. SQLite owns encoding, the grouped transaction, per-Session fallback on failure and writer memo settlement. One accepted round produces the existing ordered batch outcomes after commit. Release or unload drops generation-local reader/writer state after drain. |
| Session file put/import and read → sessionFiles → sqliteStorage | `reserveFile(sessionId,fileId,generation)`, `commitFile(sessionId,fileId,generation)`, `abandonFile(fileId,generation)`; ownership and path reads via `ownsFile, ownsOutput, ownedPaths`; `registerOutput(sessionId,path)`. | SessionStore reserves, writes or imports bytes through the file owner, then finalizes. SQLite verifies the Session and writer generation, clears the reservation and inserts ownership atomically. Bytes, path validation and fileId transfer stay with the file owner. |
| Session file sweep → sqliteStorage | `releaseStaleFileWriters(generation), unownedFiles(), deleteIfUnowned(fileId), recordedFiles(names)`. | SessionStore removes files outside SQLite. SQLite rechecks ownership when deleting the row. Failed cleanup remains retryable. |
Expand Down
6 changes: 3 additions & 3 deletions docs/design/contracts/runtime-owner-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
| --- | --- |
| Branch directory readers → `timelineTree` | `timelineTree.directory({}) → [{info, head, state, endEvent?}]`, including ending and ended branches. |
| Skills content and MCP publication → Session loader | `sessionLoader.create({group, definitionId, instanceData}) → {instanceId}`; `remove({instanceId}) → void`. The Session loader admits groups whose configured parent is the Session group. Registered Session extension definitions must activate their instance rows. Host-added optional groups retain their optional rows. Skills supplies its content definition; MCP supplies its connection definition ID and retains the resolved transport configuration. |
| Goal → timelineTree | `inputs(id, inputs) → committed events`. One validated atomic batch for the Goal record and trigger. |
| Goal → the line's input owner ([Goal](../plugins/Goal.md#own-contract)) | Superseded: Goal writes one command input through `inputQueue.submit` and appends its business fact and state record with `timeline.append`, in that order. `timelineTree.inputs` is not used. |
| Branch-detail RPC → timelineTree | `display(id) → {entry,purpose?,cutMessages?,end?}`. |
| History RPC and line-read tools → timelineTree | `batchEnd(id, sequence) → void`, `pageEnd(id, after, limit, through) → sequence`, and `page` at the same cutoff. Preserve complete batches and the fixed head of ended lines. |
| Context RPC → target branch | `agentLoop.compact` and `contextUsage.read`. |
| Goal and Shell admission → timelineTree | `directory({id})` returns the matching directory entry or the unknown-branch error using a single-branch lookup. Goal reads ended history through `query`; writes retain the ended/unknown errors. |
| Goal and Shell admission → timelineTree | `directory()` answers the lines and the default; `line({line})` answers one record or `unknown_branch`. Goal reads ended history through `read`; writes retain the ended and unknown errors. |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem: this changed row still says line({line}) answers unknown_branch, but PR #2092's line answers unknown (TimelineTree.md:133), and Goal.md:105 publishes that as session_invalid_input. The row also says Goal reads ended history through read, while Goal.md:136 and :162 say the entry no longer folds or answers an ended line. Failure scenario: an implementer handles an unknown_branch kind the owner never returns and misses unknown; the ended-line read path is reintroduced, reverting Goal's first client-visible change. Evidence: this row; PR #2092 docs/architecture/rust-agent/plugins/TimelineTree.md:98, :133; docs/design/plugins/Goal.md:105, :136, :162. Fix: say line({line}) answers unknown; say the client reads an ended line's history through read (or drop the clause), and remove Goal's ended-line read.

| InputQueue and Collaboration approvals → target branch | `timelineTree.input`, `inputQueue.withdraw` after submission checks, and `approval.pending/decide` on the selected branch. |
| PromptSuggestion → ContextUsage; Report and Agent configuration → Prompt | `contextUsage.read`, `prompt.adoptedConfiguration({}) → adopted configuration or null`. Report also uses `timelineTree.query` at the selected head for evidence. |
| Prompt and ToolBinding → `branchLifecycle` | `registerOpening(completion) → void`. Opening waits for admitted completions under its existing deadline and propagates their errors. |
Expand Down Expand Up @@ -73,5 +73,5 @@ substitutes a newer head.
| Loop and ContextPreparation → HistoryRenderer | `context({branchId, through}) → ContextHistory`, `renderedContext({branchId, through}) → {context, history: HistoryEntry[]}`, `snapshot({context, retainFrom, anchor}) → RecoverySnapshot`, `streamCheckpoint({branchId, through, retainFrom, batch}) → ProjectionCheckpoint`. |
| Loop and ModelProvider → ContextPreparation | `prepare({source: ContextPrepareData, projection?}, cancelled) → ModelRequest`, `validate({requestId, request}, cancelled) → void`. Reuse the prepared projection at the original cutoff. |
| ContextPreparation and usage readers → ContextUsage | `read({through?}, cancelled) → {through, contextWindow, outputTokens, thresholdTokens, estimatedInputTokens, baselineSource}`. |
| Loop, ToolExecutor and Code Mode definition readers → `toolBinding` | `bind({requestId, through, tools, toolSources}) → void`, `bindCurrent({requestId, declared?}) → ToolDefinition[]`, `definitions({requestId}) → ToolDefinition[]`, `transfer({from, to}) → void`, `release({requestId}) → void`. ToolBinding retains the pinned handler generation. |
| Loop, ToolExecutor and Code Mode readers → `toolBinding` | `bind({requestId, turnId, through, declared, sources}) → void`, `adopted({requestId}) → {adoption, tools}`, `claim({requestId, calls, context}) → void`, `transfer({from, to}) → void`, `release({requestId}) → void`, `retain_only({requestId}) → void`([ToolBinding](https://github.com/arcships/dim/pull/2100)). Settlement follows the line's `step/tool-result` and `turn/end`; `retain_only` is the Loop's own rebuild step. |
| Nested tool execution → `toolExecutor` | `open({parentCallId, context}, cancelled) → gateId`, `invoke({gateId, call}) → ToolResult`, `close({gateId}) → ToolEffect[]`. Close joins children in order; interruption releases the gate. |
6 changes: 3 additions & 3 deletions docs/design/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Green parts are new and orange-bordered parts are changed. Each new plugin part
| Plugin | Process | Session | Branch | Reason |
| --- | --- | --- | --- | --- |
| Questions | — | `ask_user` tool; `session.question.*` methods; in non-interactive Sessions `ask_user` answers that no one is available to answer | — (waiters of running `ask_user` calls live in the Session part; no events, the answer is the tool result) | The waiter is the Session-scoped tool handler's own call |
| Goal | — | `goal_update` tool and `session.goal.*` methods, which only write one `input/message` with `goal:objective` and/or `goal:status` keyed blocks | Goal state folded in sequence order from consumed goal change blocks; continuation decided by Goal when it consumes `turn/end`, `stop/interrupt` or `input/deleted` through the Dispatcher | A goal belongs to exactly one branch: the fold uses only that branch's own events, so child branches and forked Sessions start with no goal; continuation follows its events in order |
| Goal | — | `goal_update` tool and `session.goal.*` methods, which write one command `input/message`; the goal owner writes the state record (superseded by [Goal](plugins/Goal.md), target, pending [#2099](https://github.com/arcships/dim/pull/2099)) | Goal state folded in sequence order from consumed goal change blocks; continuation decided by Goal when it consumes `turn/end`, `stop/interrupt` or `input/deleted` through the Dispatcher | A goal belongs to exactly one branch: the fold uses only that branch's own events, so child branches and forked Sessions start with no goal; continuation follows its events in order |
| ModelRecovery (proposal) | — | — | Proposed disposer registration (Loop port not implemented); the handover input it writes through the branch input entrance | The part decides only from committed branch facts and writes one input; the Loop keeps the turn and the batch |
| Hooks | Configuration (`hooks`, `hooks-projects` and `hooks-plugins` Settings sources, `hooks.*` management methods and plugin `register`/`withdraw`/`plugins()`, `HookSources` port) in App Server | Hook documents (user, project and plugin); runner; a submit check registered with the Session's `submitChecks`, which the operator-input entries call (`UserPromptSubmit`) | advice registered with Permission (`PreToolUse`); `PermissionRequest` answered through Approval; `PostToolUse`, `PostToolUseFailure`, `Stop`, `SessionStart`, `Notification` from the Dispatcher | Rules apply to a Session; execution happens in a branch |
| ShellInput | — | `shell.*` Session methods; runs in the Session's workspace and writes its input | — | Commands belong to the Session |
Expand Down Expand Up @@ -163,7 +163,7 @@ Index of plugin design documents: [plugins/README.md](plugins/README.md).
| ShellInput | Session | `!command` / `!!command` as `shell.run/stop/list` Session methods | P1 | Rust | [ShellInput](plugins/ShellInput.md) |
| Attachments | Session | `attachment.put` for large text; Session files | P1 | Rust | [Attachments](plugins/Attachments.md) |
| SessionTitle | Session | Title from the first adopted user input; `session.rename` | P1 | Rust | [SessionTitle](plugins/SessionTitle.md) |
| Goal | Session + branch | Goal state folded from `goal:objective` and `goal:status` input blocks; continuation; `goal_update`; `session.goal.*` | P2 | Rust | [Goal](plugins/Goal.md) |
| Goal | Session + branch | Goal state published by the line's owner; continuation; `goal_update`; `session.goal.*` (superseded shape: [Goal](plugins/Goal.md), target, pending [#2099](https://github.com/arcships/dim/pull/2099)) | P2 | Rust | [Goal](plugins/Goal.md) |
| Web | Session | `web_search`, `web_fetch` | P2 | TypeScript first | [Web](plugins/Web.md) |
| Hooks | Process + Session + branch | Command hooks in Dim's own configuration, with a Claude Code / Codex compatible document shape and script protocol, attached to business owners: Permission (pre-tool advice), Approval (permission requests), the operator-input entries (prompt check), branch inputs (post-tool, Stop, Session start) | M1 | Rust | [Hooks](plugins/Hooks.md) |
| Scheduler | Process + Session | Scheduled jobs; `schedule` tool; run-outcome report | P2 | TypeScript first | [Scheduler](plugins/Scheduler.md) |
Expand Down Expand Up @@ -226,7 +226,7 @@ sequenceDiagram
IQ->>TL: input/message, then turn/start
```

Every goal change (set, edit, pause, resume, clear, and the model's completed or blocked report through `goal_update`) is one `input/message` whose raw blocks carry the key `goal:objective` (set, edit), `goal:status` (set, pause, resume, completed, blocked, automatic pause) or retire both (clear); continuations carry no key and are only counted. Compaction ([ContextCompaction](https://github.com/arcships/dim/blob/roadmap/f1-production-compaction-host-compact-and-u/docs/design/plugins/ContextCompaction.md), F1; branch link until PR #108 merges) keeps the events from `retain_from` (the last turns) verbatim and replays the latest live block of each key placed before it, so the model keeps the current objective and status; it is a Loop step that writes no `turn/*`, so it never triggers a continuation decision. The tool and the `session.goal.*` methods only write that event; they never read Goal's state or decide. Goal's state is the fold of the consumed blocks in sequence order, with no exceptions: the latest live block of each key is the current objective and status, so what compaction replays always equals the fold, and a goal exists only while `goal:objective` is live. Goal decides continuation itself when it consumes `turn/end`, `stop/interrupt` or `input/deleted` through the Dispatcher, from consumed state only; it registers the write as owned work, returns, and rechecks consumed state before writing. Deleted inputs never change the state. A goal belongs to exactly one branch: the fold uses only the events written on that branch, never the inherited prefix, so a child branch and a forked Session's `main` start with no goal and a change there affects only that branch; when Goal consumes a new branch's `branch/start` and the inherited prefix still has a live goal key, it writes one `clear` there as owned work, so the model on the new branch does not take the parent's goal as its own. A `stop/interrupt` pauses the goal. If the interrupt lands after the continuation input, at most one extra turn runs, and the model sees the paused block.
Superseded by [Goal](plugins/Goal.md) (target, pending [#2099](https://github.com/arcships/dim/pull/2099)): the command is one input, the state record is written by the goal owner after its business fact, and a reader that needs the goal reads the owner's value. The paragraph below describes the pre-contract shape. Every goal change (set, edit, pause, resume, clear, and the model's completed or blocked report through `goal_update`) is one `input/message` whose raw blocks carry the key `goal:objective` (set, edit), `goal:status` (set, pause, resume, completed, blocked, automatic pause) or retire both (clear); continuations carry no key and are only counted. Compaction ([ContextCompaction](https://github.com/arcships/dim/blob/roadmap/f1-production-compaction-host-compact-and-u/docs/design/plugins/ContextCompaction.md), F1; branch link until PR #108 merges) keeps the events from `retain_from` (the last turns) verbatim and replays the latest live block of each key placed before it, so the model keeps the current objective and status; it is a Loop step that writes no `turn/*`, so it never triggers a continuation decision. The tool and the `session.goal.*` methods only write that event; they never read Goal's state or decide. Goal's state is the fold of the consumed blocks in sequence order, with no exceptions: the latest live block of each key is the current objective and status, so what compaction replays always equals the fold, and a goal exists only while `goal:objective` is live. Goal decides continuation itself when it consumes `turn/end`, `stop/interrupt` or `input/deleted` through the Dispatcher, from consumed state only; it registers the write as owned work, returns, and rechecks consumed state before writing. Deleted inputs never change the state. A goal belongs to exactly one branch: the fold uses only the events written on that branch, never the inherited prefix, so a child branch and a forked Session's `main` start with no goal and a change there affects only that branch; when Goal consumes a new branch's `branch/start` and the inherited prefix still has a live goal key, it writes one `clear` there as owned work, so the model on the new branch does not take the parent's goal as its own. A `stop/interrupt` pauses the goal. If the interrupt lands after the continuation input, at most one extra turn runs, and the model sees the paused block.

### 5.3 Observer through the Session broadcast (SessionTitle)

Expand Down
2 changes: 1 addition & 1 deletion docs/design/plugin-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ R4). This table says what each name Dim defines is for.
| --- | --- | --- | --- | --- |
| `sessions` | process | Agents | yes | Start or drive another Session |
| `sessionPermissions` | process | Agents | yes | Marked `#[rutis::service]` |
| `sessionMetadata` | process | SessionStore | yes | SessionTitle is the title's one writer |
| the store's title operations ([SessionTitle](plugins/SessionTitle.md#own-contract), target, pending [#2091](https://github.com/arcships/dim/pull/2091)) | process | SessionStore | yes | SessionTitle is the title's one writer |
| `settings` | process | Settings | yes | Business configuration |
| `auxiliaryModel` | process | the profile's model-selection owner | yes | Auxiliary model requests |
| `pluginFiles` | process | host | yes, when the host supplies a root | A process part's own files |
Expand Down
Loading