subharness 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -6
- package/dist/cli/args.d.ts +3 -0
- package/dist/cli/args.js +46 -12
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/catalog-worker.js +3 -2
- package/dist/cli/catalog-worker.js.map +1 -1
- package/dist/cli/extensions.d.ts +1 -0
- package/dist/cli/extensions.js +10 -4
- package/dist/cli/extensions.js.map +1 -1
- package/dist/cli/help.js +20 -13
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/main.js +48 -10
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/output.js +4 -1
- package/dist/cli/output.js.map +1 -1
- package/dist/config/access.d.ts +2 -1
- package/dist/config/access.js +18 -7
- package/dist/config/access.js.map +1 -1
- package/dist/config/loader.d.ts +2 -0
- package/dist/config/loader.js +20 -6
- package/dist/config/loader.js.map +1 -1
- package/dist/config/project-context.d.ts +9 -0
- package/dist/config/project-context.js +41 -0
- package/dist/config/project-context.js.map +1 -0
- package/dist/config/resolve-access.d.ts +2 -1
- package/dist/config/resolve-access.js +5 -2
- package/dist/config/resolve-access.js.map +1 -1
- package/dist/extensions/catalog.d.ts +1 -0
- package/dist/extensions/catalog.js +4 -2
- package/dist/extensions/catalog.js.map +1 -1
- package/dist/runtime/capture.d.ts +4 -4
- package/dist/runtime/capture.js +14 -2
- package/dist/runtime/capture.js.map +1 -1
- package/dist/runtime/catalog.d.ts +6 -1
- package/dist/runtime/catalog.js +1 -1
- package/dist/runtime/catalog.js.map +1 -1
- package/dist/runtime/coordinator.d.ts +1 -0
- package/dist/runtime/coordinator.js +2 -1
- package/dist/runtime/coordinator.js.map +1 -1
- package/dist/runtime/definition.d.ts +1 -1
- package/dist/runtime/definition.js +2 -2
- package/dist/runtime/definition.js.map +1 -1
- package/dist/runtime/extension-service.d.ts +1 -1
- package/dist/runtime/extension-service.js.map +1 -1
- package/dist/runtime/extension-supervisor.d.ts +1 -1
- package/dist/runtime/extension-supervisor.js +6 -3
- package/dist/runtime/extension-supervisor.js.map +1 -1
- package/dist/runtime/select-native.d.ts +2 -1
- package/dist/runtime/select-native.js +7 -4
- package/dist/runtime/select-native.js.map +1 -1
- package/dist/runtime/service.js +35 -11
- package/dist/runtime/service.js.map +1 -1
- package/dist/runtime/state.d.ts +1 -1
- package/dist/runtime/state.js.map +1 -1
- package/dist/runtime/types.d.ts +2 -0
- package/dist/runtime/types.js.map +1 -1
- package/dist/runtime/worker-server.js +3 -3
- package/dist/runtime/worker-server.js.map +1 -1
- package/package.json +1 -1
- package/sdk/access-config.md +9 -7
- package/sdk/agent-skill.md +5 -3
- package/sdk/cli/extensions.md +10 -10
- package/sdk/cli/index.md +30 -14
- package/sdk/cli/output.md +1 -1
- package/sdk/config.md +39 -14
- package/sdk/diagnostics.md +2 -2
- package/sdk/execution.md +7 -4
- package/sdk/extensions.md +17 -9
- package/sdk/index.md +1 -0
- package/sdk/plugins/sub-agents.md +3 -1
- package/sdk/project-root.md +97 -0
- package/sdk/v1-runtime.md +9 -5
package/sdk/config.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Agent Discovery
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
By default, repository agents live in `.subharness/agents/` at the Git worktree root, or in the execution directory outside Git. [Logical project roots](project-root.md) let `--root <directory>` select an app's `.subharness/` independently of execution `--cwd`. Global agents remain in `~/.subharness/agents/`. The `.subharness/` directory holds subharness configuration, agent definitions, shared modules and optional extension installations. Cross-harness skills conventionally remain in `.agents/skills/`, which subharness does not read.
|
|
4
4
|
|
|
5
5
|
```text
|
|
6
6
|
project/
|
|
@@ -44,7 +44,29 @@ export default agent({
|
|
|
44
44
|
|
|
45
45
|
The former `.agents/agents/` directory is not read. Definitions moved to `.subharness/agents/` can keep or drop an `.agent` file-name suffix; either way the file is an entry because it is a `.ts` file under `agents/`.
|
|
46
46
|
|
|
47
|
-
Discovery is required for listing and repository/global specialist lookup. Direct harness execution skips it. Declared-child execution
|
|
47
|
+
Discovery is required for listing and repository/global specialist lookup. Direct harness execution skips it. Declared-child execution selects from the parent's captured definition graph and direct child map; unrelated catalog entries are not dependencies of a `subagent:` invocation.
|
|
48
|
+
|
|
49
|
+
## Explicit definition files
|
|
50
|
+
|
|
51
|
+
The CLI accepts a TypeScript definition file as the target of `run` and `check`. The file can live anywhere accessible to the caller, including inside an individual monorepo application or outside the execution repository. It must be a regular `.ts` file, excluding `.d.ts` declarations, and default-export one valid `AgentDefinition`. Ordinary filesystem symlinks to regular files are allowed. Loading evaluates trusted executable code with the same definition validation and import resolution as catalog entries.
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
subharness check ./apps/storefront/.subharness/agents/reviewer.ts
|
|
55
|
+
subharness run ./apps/storefront/.subharness/agents/reviewer.ts \
|
|
56
|
+
--cwd ./apps/storefront --prompt "Review this app."
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Absolute paths and relative paths are accepted. Relative definition paths resolve from the invoking command's directory, independently of `--cwd` and `--root`. A target is a file path when it is absolute, starts with `./` or `../` (or the platform's equivalent), contains a platform path separator, or ends in `.ts`. Reserved harness targets and qualified `repo:`, `global:`, and `subagent:` references retain their existing meaning. A bare `reviewer.ts` selects a file; a bare `reviewer` remains a catalog lookup. There is no fallback from a missing file to catalog discovery.
|
|
60
|
+
|
|
61
|
+
Only the selected definition and its imports are evaluated. Repository and global catalogs are not discovered, so unrelated invalid entries and duplicate catalog names do not block this target. The file is not registered in a catalog, and `list` remains unchanged. An unavailable file, directory target, unsupported extension, or invalid definition fails with `INVALID_DEFINITION`, identifies the selected file safely, and exits with code `2`. Native startup failures retain their existing diagnostics and exit codes.
|
|
62
|
+
|
|
63
|
+
`--cwd` selects the execution directory. It defaults to the selected `--root`, or to the invoking command's directory when no root is selected. Definition evaluation runs in that execution directory; relative module imports follow normal Node resolution from the definition module, using the target directory when the file is a symlink. The definition file's location does not select personal access or extensions: these follow `--root` when supplied and execution-directory discovery otherwise. Workspace identity still describes the actual execution directory and Git worktree. File targets reject `--model` and `--effort` overrides just like catalog specialists. A successful `check` identifies the original target argument in its output.
|
|
64
|
+
|
|
65
|
+
Without `--root`, personal access inside a Git monorepo comes from `.subharness/agents.local.json` at the main checkout root; an app-local definition or `--cwd` alone does not change that. Use `--root ./apps/storefront` to select that app's access settings and extensions, including with an explicit definition file. In a linked worktree, access comes from the corresponding app in the main checkout. No enclosing catalog, settings, or extensions are merged into the selected project.
|
|
66
|
+
|
|
67
|
+
A session captures the loaded definition graph for follow-ups and declared children. New top-level sessions read the current file. Managed agents remain limited to their declared `subagent:` targets; an explicit file path does not bypass parent authorization. The public connected SDK continues to accept catalog references and harness configurations, not file-path strings. Embedded callers can import a definition and pass it to `createRunner().createSession()`.
|
|
68
|
+
|
|
69
|
+
## Catalog identities
|
|
48
70
|
|
|
49
71
|
The declared name determines identity. Duplicate names in the same scope are errors. `repo:reviewer` and `global:reviewer` remain distinct; bare `reviewer` is accepted only when unambiguous. The reserved CLI targets `codex`, `claude`, `fx`, `opencode`, `copilot`, and `cursor` always select native harnesses. Specialists with those names require a `repo:` or `global:` qualifier. Direct harness runs bypass definition discovery entirely, including invalid definition files. Global definitions can execute in any caller-supplied directory. Global and repository files resolve their own imports through normal Node package resolution.
|
|
50
72
|
|
|
@@ -52,9 +74,10 @@ The declared name determines identity. Duplicate names in the same scope are err
|
|
|
52
74
|
subharness list --cwd /repo/worktree
|
|
53
75
|
subharness check repo:developer --cwd /repo/worktree
|
|
54
76
|
subharness run repo:developer --cwd /repo/worktree --prompt "Implement the documented feature."
|
|
77
|
+
subharness run --root ./apps/storefront repo:reviewer --prompt "Review this app."
|
|
55
78
|
```
|
|
56
79
|
|
|
57
|
-
|
|
80
|
+
Without `--root`, an omitted `--cwd` uses the calling command's directory. Discovery uses the nearest Git worktree root, or the execution directory outside Git. With `--root`, discovery uses only that root's repository catalog and the global catalog; omitted `--cwd` uses the root. Explicit relative values for either flag resolve independently from the invoking directory. Bare repositories are not execution directories. Definitions are trusted executable TypeScript: catalog loading evaluates modules.
|
|
58
81
|
|
|
59
82
|
`check` resolves direct harnesses, repository and global specialists, unambiguous bare names, and declared children under the same rules as `run`. Direct harness checks bypass catalog discovery. Specialist checks evaluate the selected definition in an isolated worker, so they retain the same trust requirement and use the selected directory for definition loading and native startup. A check covers only that selected definition, not its declared children.
|
|
60
83
|
|
|
@@ -67,29 +90,31 @@ Extension consent is stored in `~/.subharness/extensions.json` with owner-only p
|
|
|
67
90
|
"version": 1,
|
|
68
91
|
"global": ["<id>"],
|
|
69
92
|
"repositories": {
|
|
70
|
-
"<canonical
|
|
93
|
+
"<canonical project root>": ["<id>"]
|
|
71
94
|
}
|
|
72
95
|
}
|
|
73
96
|
```
|
|
74
97
|
|
|
75
98
|
Enable and disable updates are serialized through the owner-private `~/.subharness/extensions.lock.sqlite` coordination file. The lock file contains no consent data. Each update re-reads `extensions.json` while it owns the lock before writing the replacement.
|
|
76
99
|
|
|
77
|
-
`global` contains enabled global extension IDs. Each `repositories` key is a canonical
|
|
100
|
+
`global` contains enabled global extension IDs. Each `repositories` key is a canonical project root whose array contains enabled repository extension IDs. Without `--root`, this is the Git worktree root or the selected directory outside Git. With `--root`, it is the selected directory. Existing checkout keys remain valid; app roots require their own consent, with no inheritance from parents, sibling apps, or other worktrees. Consent is never written into repository files. An instance is identified by its qualified reference plus its project root for repository extensions, or by its qualified reference alone for global extensions. Failure state, eligibility and re-enablement apply per instance. The [extension commands](cli/extensions.md) read and update this file; discovery alone does not grant consent.
|
|
78
101
|
|
|
79
|
-
The consent file is at most 256 KiB. `repositories` contains at most 1,024
|
|
102
|
+
The consent file is at most 256 KiB. `repositories` contains at most 1,024 project-root entries. Each scope contains at most 256 IDs: the `global` array and each repository array have that limit independently. Every extensions command rejects an existing consent file that is not owner-only, exits `1`, and directs the user to restrict its permissions with `chmod 600 ~/.subharness/extensions.json`. No command repairs permissions. The [extension-command exit codes](cli/extensions.md#output-and-failures) take precedence over general CLI configuration exit codes for these commands.
|
|
80
103
|
|
|
81
|
-
Global instances write stdout/stderr to `<stateDirectory>/extensions/global-<id>.log`. Repository instances use `<stateDirectory>/extensions/repo-<id>-<
|
|
104
|
+
Global instances write stdout/stderr to `<stateDirectory>/extensions/global-<id>.log`. Repository instances use `<stateDirectory>/extensions/repo-<id>-<root-hash>.log`, where `<root-hash>` is the first 12 hex characters of the SHA-256 of the canonical project-root path. Default checkout instances retain their existing log paths. Filenames contain no colons. The log uses owner-only access. It is compacted after it exceeds 1.5 MiB and trimmed to the most recent 1 MiB. The selected coordinator's state directory follows [execution discovery](execution.md#ownership-and-transport-boundaries): explicit `ConnectOptions.stateDirectory`, then `AGENT_STATE_DIR`, then `~/.subharness/state/shared`; CLI commands use the environment/default rule. Consent remains in `~/.subharness/extensions.json` regardless of the selected coordinator state directory. `subharness extensions list` shows each instance's actual log path, never its contents.
|
|
82
105
|
|
|
83
106
|
## Personal access and worktrees
|
|
84
107
|
|
|
85
|
-
|
|
108
|
+
Without `--root`, the optional [access file](access-config.md) is `.subharness/agents.local.json` at the repository's main checkout root, shared by its linked worktrees. This means the local checkout associated with those worktrees, not a branch named `main` or another clone of the same remote. With `--root`, the access directory is the corresponding app path in that main checkout; definitions and extensions stay in the selected worktree's app. See [personal access and worktrees](project-root.md#personal-access-and-worktrees) for counterpart validation and path anchoring.
|
|
86
109
|
|
|
87
|
-
| Resource |
|
|
88
|
-
| --- | --- |
|
|
89
|
-
| Repository definitions | Execution worktree |
|
|
90
|
-
| Personal access preferences | Main checkout |
|
|
91
|
-
| Native credentials |
|
|
110
|
+
| Resource | Default source | With `--root` |
|
|
111
|
+
| --- | --- | --- |
|
|
112
|
+
| Repository definitions | Execution worktree root | Selected project root |
|
|
113
|
+
| Personal access preferences | Main checkout root | Corresponding project root in the main checkout |
|
|
114
|
+
| Native credentials | Captured environment, configured files, and native credential store | Same sources; relative file/project references use the access root |
|
|
92
115
|
|
|
93
116
|
The library does not copy configuration or credentials into worktrees. An inaccessible main checkout is an error. A remote or isolated environment must have its own accessible preferences and credentials.
|
|
94
117
|
|
|
95
|
-
A session retains its loaded instructions, tools, and harness configuration.
|
|
118
|
+
A session retains its loaded instructions, tools, and harness configuration. Declared child sessions use the parent's captured definition graph, including when the source files have changed since the parent was created. New top-level sessions load definitions from the current files. In a managed parent context, `subharness list` shows the direct `subagent:` names from that captured graph. These names do not register the children in the global or repository catalog.
|
|
119
|
+
|
|
120
|
+
An explicitly selected project and its access root are retained for follow-ups and inherited by declared children. Managed `list`, `run`, and `check` calls cannot supply `--root`; child execution `--cwd` does not change the inherited access or extension scope. Settings and credentials are still read at each native session's startup, as defined in [sessions and managed children](project-root.md#sessions-and-managed-children).
|
package/sdk/diagnostics.md
CHANGED
|
@@ -80,11 +80,11 @@ Codex, fx, Copilot and Cursor SDK emit at most one adapter capture error per tur
|
|
|
80
80
|
|
|
81
81
|
The dashboard maps missing `session-events-v1` support to `COORDINATOR_OUTDATED` with coordinator restart guidance in place of live steps; core task content remains visible. An absent or false `taskDetails` marker on the dashboard snapshot keeps the dashboard running and displays `COORDINATOR_OUTDATED` with restart guidance instead of task details when the task screen opens. Missing `history` or `grouping` markers end the dashboard with `COORDINATOR_OUTDATED` and exit `1`. These presentation rules do not change the SDK event error code.
|
|
82
82
|
|
|
83
|
-
The CLI displays `EXTENSION_*` codes with their safe messages only through `subharness extensions list`; they also remain available through the coordinator's existing safe diagnostics. The dashboard does not display extension diagnostics. [User extensions](extensions.md#bounds-shutdown-and-diagnostics) defines `EXTENSION_LOAD_FAILED`, `EXTENSION_INCOMPATIBLE`, `EXTENSION_HANDLER_FAILED`, `EXTENSION_TIMEOUT`, `EXTENSION_BACKPRESSURE`, `EXTENSION_DISPOSE_FAILED`, `EXTENSION_EXITED` and `EXTENSION_LOG_UNAVAILABLE`. An unexpected extension-process exit uses `EXTENSION_EXITED` and disables that instance under the same failure and recovery rules as other extension failures. `EXTENSION_LOG_UNAVAILABLE` is informational: a log open, write or close failure discards unwritable output and never stops the instance. These diagnostics identify the qualified reference and canonical
|
|
83
|
+
The CLI displays `EXTENSION_*` codes with their safe messages only through `subharness extensions list`; they also remain available through the coordinator's existing safe diagnostics. The dashboard does not display extension diagnostics. [User extensions](extensions.md#bounds-shutdown-and-diagnostics) defines `EXTENSION_LOAD_FAILED`, `EXTENSION_INCOMPATIBLE`, `EXTENSION_HANDLER_FAILED`, `EXTENSION_TIMEOUT`, `EXTENSION_BACKPRESSURE`, `EXTENSION_DISPOSE_FAILED`, `EXTENSION_EXITED` and `EXTENSION_LOG_UNAVAILABLE`. An unexpected extension-process exit uses `EXTENSION_EXITED` and disables that instance under the same failure and recovery rules as other extension failures. `EXTENSION_LOG_UNAVAILABLE` is informational: a log open, write or close failure discards unwritable output and never stops the instance. These diagnostics identify the qualified reference and canonical logical project root for repository instances without exposing raw exception messages, stacks, event content or child output. They do not change the agent's task outcome.
|
|
84
84
|
|
|
85
85
|
Extension discovery and consent-read failures during session admission are fail-open. The session is admitted without extension delivery, and the problem is retained as a separate admission diagnostic for `subharness extensions list`; it is not attributed to an instance when no identity is known. The coordinator retains at most the 16 most recent admission diagnostics. Each instance separately retains at most its eight most recent diagnostics, including whether each one disabled the instance and when it occurred.
|
|
86
86
|
|
|
87
|
-
Extension stdout/stderr is kept only in its owner-private bounded log: `<stateDirectory>/extensions/global-<id>.log` for a global instance or `<stateDirectory>/extensions/repo-<id>-<
|
|
87
|
+
Extension stdout/stderr is kept only in its owner-private bounded log: `<stateDirectory>/extensions/global-<id>.log` for a global instance or `<stateDirectory>/extensions/repo-<id>-<root-hash>.log` for a repository instance. `<root-hash>` is the first 12 hex characters of the SHA-256 of the canonical project-root path. The filenames contain no colons. Logs are located using the selected coordinator's [state-directory selection rule](execution.md#ownership-and-transport-boundaries). A log is compacted after it exceeds 1.5 MiB and is trimmed to the most recent 1 MiB. List shows the actual instance log path; log contents are never included in execution output, safe diagnostics or the dashboard. If enable saves consent but cannot notify a running coordinator, it warns that the failure state clears on coordinator restart and exits `0`; it does not roll back consent or claim successful notification.
|
|
88
88
|
|
|
89
89
|
`subharness extensions list` and the coordinator's extension-status operation each report at most 256 instances and report the exact number of additional instances omitted. Every extensions command rejects an existing consent file that is not owner-only with exit `1` and guidance to run `chmod 600 ~/.subharness/extensions.json`; no command repairs permissions. The [extension-command exit codes](cli/extensions.md#output-and-failures) govern these commands and take precedence over general CLI configuration exit codes.
|
|
90
90
|
|
package/sdk/execution.md
CHANGED
|
@@ -65,13 +65,15 @@ A string selects a discovered qualified reference or unambiguous name. Reserved
|
|
|
65
65
|
|
|
66
66
|
Catalog discovery imports trusted definition modules in isolated coordinator-owned evaluation; it does not start native harnesses or call models. The finite discovered-definition inventory remains unpaginated; there is no artificial catalog-size cap. Discovery is not proof of readiness. `check` opens and closes a disposable native startup session without a prompt, retained conversation, or task; it rejects safely on startup/authentication/configuration/cleanup failure and does not promise a later model call will succeed.
|
|
67
67
|
|
|
68
|
+
Explicit definition-file targets belong to CLI `run` and `check`; connected SDK string targets do not accept paths. Embedded callers can import an arbitrary definition module and supply the definition object to `runner.createSession()`.
|
|
69
|
+
|
|
68
70
|
`create` resolves the target and captures its loaded definition graph and environment once, then returns an empty session. Editing definition files affects newly created sessions, not an existing captured conversation. Definition functions live on the coordinator host; client closures cannot be transferred. Native harness startup stays lazy until dispatch. Invalid creation returns no session. A separate invalid `prompt` can leave a valid empty session, which the caller may reuse or close. The CLI's atomic first-prompt boundary is preserved separately below.
|
|
69
71
|
|
|
70
72
|
For connected creation/check, omission of `env` snapshots the calling process environment at that operation. An explicit `env` replaces it, with undefined entries omitted. Inherited `AGENT_PARENT_TOKEN` and `AGENT_CLI_PATH` are stripped, and the selected coordinator supplies `AGENT_STATE_DIR`; managed authority is bound separately. This resulting environment governs definition resolution and module evaluation as well as native startup/execution, so environment-dependent imports use the same chosen values. Catalog listing evaluates definitions with its implicit caller snapshot under the same stripping/injection rules. Existing cwd-based project discovery and personal-settings conventions still apply. The environment is privately transferred and captured for the session; follow-ups do not replace it. No caller-supplied environment grants parent authority. Neither the host cwd nor the shared daemon's `process.env` is mutated, and environment/access values never appear in metadata or errors.
|
|
71
73
|
|
|
72
74
|
Connected and CLI-created sessions retain their loaded definition graph in an isolated owner process. Custom-tool callbacks execute in that graph owner's creation directory and captured environment, including callbacks used by managed children. A child's native harness may use a different requested working directory and native environment; that does not change the captured callback's ambient `process.cwd()` or `process.env`. Tools that operate on a child-specific location must use explicit paths or arguments. The graph owner does not inherit caller-supplied managed parent or launcher authority; native delegation instructions and launchers are bound separately to each session. This preserves closure state and avoids re-importing changed source or mutating shared process context.
|
|
73
75
|
|
|
74
|
-
|
|
76
|
+
Public connected creation/check retains the CLI's default cwd-based project discovery, personal settings, and native-worker access resolution. [CLI `--root`](project-root.md) adds no field to connected or embedded creation options. A connected client can inspect or continue a CLI-created session with its retained logical root; it does not reselect that project. Embedded runners retain their explicit `RunnerOptions.env`/`access` behavior and do not start reading those personal settings. Model credentials remain in the server/coordinator execution path, not UI payloads.
|
|
75
77
|
|
|
76
78
|
## Connect to CLI work
|
|
77
79
|
|
|
@@ -134,7 +136,7 @@ Session/task pages default to 100 entries, with integer `limit` from 1 through 1
|
|
|
134
136
|
|
|
135
137
|
There is no collection snapshot-watch API. Poll paged lists for retained metadata and attach `task.watch()` for race-free current-state observation of selected tasks. `events.open({ scope: { kind: "all" } })` can observe live session/task activity, including future sessions, but its live stream is not a collection snapshot. Per-task revisions and list cursors remain metadata interfaces, separate from live events. Lists contain no full prompts, responses, credentials, or environment values. `task.inspect()` adds the original admission prompt to the task snapshot; it is separate from every watch update. Steering does not overwrite that original prompt.
|
|
136
138
|
|
|
137
|
-
Task titles use the existing first nonempty prompt line, normalize whitespace/remove terminal controls, and cap at 120 Unicode code points. Task ordinals count admission within a session from one; steering retains the task's ordinal. Timestamps are Unix milliseconds. `updatedAt` starts at admission and records the coordinator's latest task activity update, not an observer read. `dispatchedAt` records first dispatch and is retained across native continuations and private recovery; it is absent for never-dispatched work. `failedAt` records the latest execution or stop-confirmation failure, and `finishedAt` records the terminal transition. Both terminal timestamps are cleared when private recovery reopens the task and are populated again on its next failure/terminal transition. Session summaries include execution cwd and workspace identity. Connected sessions
|
|
139
|
+
Task titles use the existing first nonempty prompt line, normalize whitespace/remove terminal controls, and cap at 120 Unicode code points. Task ordinals count admission within a session from one; steering retains the task's ordinal. Timestamps are Unix milliseconds. `updatedAt` starts at admission and records the coordinator's latest task activity update, not an observer read. `dispatchedAt` records first dispatch and is retained across native continuations and private recovery; it is absent for never-dispatched work. `failedAt` records the latest execution or stop-confirmation failure, and `finishedAt` records the terminal transition. Both terminal timestamps are cleared when private recovery reopens the task and are populated again on its next failure/terminal transition. Session summaries include execution cwd and workspace identity. Connected sessions resolve repository grouping from actual execution cwd using existing CLI behavior; a CLI-selected logical root does not replace that workspace identity. Embedded sessions use their directory without introducing Git discovery.
|
|
138
140
|
|
|
139
141
|
## Disconnect and reconnect
|
|
140
142
|
|
|
@@ -580,7 +582,7 @@ interface TaskResult {
|
|
|
580
582
|
}
|
|
581
583
|
```
|
|
582
584
|
|
|
583
|
-
`SessionEventSource` and its subscription/event types are defined in [Live session events](events.md). Opening a subscription registers live delivery before its promise resolves; it does not change session configuration. Routes requiring startup-only partial-output options enable them for every session. SDK applications consume events directly. Coordinator session admission also resolves the current user's enabled global and repository extensions, including for `client.sessions.create`; those modules run only in separate supervised children. Embedded runners never load user extensions.
|
|
585
|
+
`SessionEventSource` and its subscription/event types are defined in [Live session events](events.md). Opening a subscription registers live delivery before its promise resolves; it does not change session configuration. Routes requiring startup-only partial-output options enable them for every session. SDK applications consume events directly. Coordinator session admission also resolves the current user's enabled global and repository extensions, including for `client.sessions.create`; those modules run only in separate supervised children. CLI root-selected sessions use that root's repository extension scope independently of execution cwd, while public connected creation retains default cwd-based scope. Embedded runners never load user extensions.
|
|
584
586
|
|
|
585
587
|
`createSession` validates and captures the definition and existing absolute working directory, but starts native execution lazily when work is dispatched. A prompt must contain non-whitespace text and fit the existing 1 MiB limit. `prompt` returns after admission or acceptance of steering, not after native startup or completion. Invalid admission rejects without creating a task. A native startup failure after admission is a failed task.
|
|
586
588
|
|
|
@@ -651,7 +653,7 @@ The normalization covers the existing adapters without extending their native pe
|
|
|
651
653
|
|
|
652
654
|
### Ownership and transport boundaries
|
|
653
655
|
|
|
654
|
-
Discovery precedence is explicit `ConnectOptions.stateDirectory`, then `AGENT_STATE_DIR`, then `~/.subharness/state/shared`. Explicit paths must be nonempty absolute local paths and are canonicalized. The CLI uses the same environment/default selection rule; installation location and
|
|
656
|
+
Discovery precedence is explicit `ConnectOptions.stateDirectory`, then `AGENT_STATE_DIR`, then `~/.subharness/state/shared`. Explicit paths must be nonempty absolute local paths and are canonicalized. The CLI uses the same environment/default selection rule; installation location, cwd, and CLI `--root` do not create separate default coordinators. Endpoint metadata is owner-private, with a private authentication token and loopback-only transport. Invalid state-directory or endpoint configuration rejects with `INVALID_CONFIG`.
|
|
655
657
|
|
|
656
658
|
The handshake validates the endpoint's coordinator instance ID, SDK protocol version `1`, and the `sdk-v1` capability; the private CLI bridge additionally requires `cli-v1`. The handshake advertises `session-events-v1` for live event operations. Its absence rejects an event operation with `COORDINATOR_INCOMPATIBLE` while leaving supported execution and inspection operations usable. Package versions need not match. A missing/incompatible protocol or required capability rejects with `COORDINATOR_INCOMPATIBLE`; authentication rejection uses `COORDINATOR_AUTH_FAILED`. Missing strict-attachment targets and uncertain reachability use `COORDINATOR_UNAVAILABLE`. A live incompatible or unreachable coordinator is never replaced to make connection succeed.
|
|
657
659
|
|
|
@@ -674,6 +676,7 @@ The CLI consumes the same library connection, discovery, admission, observation,
|
|
|
674
676
|
| Private operation | Preserved behavior |
|
|
675
677
|
| --- | --- |
|
|
676
678
|
| Catalog and readiness | Ordinary top-level CLI `list`/`check` use the same library helpers behind `client.agents` without requiring or starting a coordinator. Managed calls carrying `AGENT_PARENT_TOKEN` must first attach to the existing coordinator, validate the active parent, and narrow the child capability before discovery/check. Validation failure never falls back to external-owner authority. Definition loading and disposable readiness startup keep their existing side effects. |
|
|
679
|
+
| Logical project selection | CLI `--root` selects and retains project/access roots independently of execution cwd, including for all target forms and managed descendants. Root-selected runs and managed `list`, `check`, or `run` commands supplying `--root` require `cli-root-v1`; unsupported live coordinators yield `COORDINATOR_OUTDATED` before submission. Public connected/embedded creation signatures remain unchanged. See [logical project roots](project-root.md). |
|
|
677
680
|
| Atomic `run` | Resolve/capture the target, environment, and first prompt before publishing one session and its first task together. Invalid input publishes neither; native failure after admission becomes task failure. It is not two independently visible public calls. |
|
|
678
681
|
| Attached run/send and `wait` | Use a one-observation helper returning the existing response, approval, or terminal record. Preserve response-cursor precedence, detach boundaries, and steering acknowledgement. Do not replace first-response waiting with final `task.result`. |
|
|
679
682
|
| Managed delegation | Bind the active parent capability out-of-band. Preserve declared-child discovery, lineage, maximum depth, self/ancestor restrictions, and strict-descendant authority. The public client neither accepts raw parent tokens nor infers them from environment variables. |
|
package/sdk/extensions.md
CHANGED
|
@@ -36,15 +36,15 @@ export interface ExtensionManifest {
|
|
|
36
36
|
}
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
`id` matches `[a-zA-Z][a-zA-Z0-9_-]{0,63}` and agrees with the manifest and installation directory. `context.extensionId` is that ID. `context.reference` is its qualified `"global:id"` or `"repo:id"` reference. `context.workspace` is the canonical
|
|
39
|
+
`id` matches `[a-zA-Z][a-zA-Z0-9_-]{0,63}` and agrees with the manifest and installation directory. `context.extensionId` is that ID. `context.reference` is its qualified `"global:id"` or `"repo:id"` reference. `context.workspace` is the canonical logical project root for a repository extension and is absent for a global extension. By default this is the Git worktree root, or the execution directory outside Git. With [CLI `--root`](project-root.md), it is the selected root, even when a session executes elsewhere; native session workspace metadata still describes its real execution directory and Git worktree. `signal` represents the extension instance's lifetime; aborting it does not cancel an agent. The context contains no CLI/dashboard handle, native session, execution controls, credentials or tool registry. Every authoring type, including `SessionEvent` and the types it references, is importable from `subharness/extensions`, without requiring a runtime import by the extension. Every event, subscription and capability type is exported from `subharness` and re-exported as a type from `subharness/extensions`.
|
|
40
40
|
|
|
41
41
|
`setup` allocates the instance's resources. `onEvent` receives `SessionEvent` objects directly, narrowed by their `type` discriminator. Calls are serial in delivery order within one instance, and the host awaits each returned promise before calling that instance again. Return values do not modify execution or consume events away from other subscribers. Separate processes have independent queues and handlers. `dispose` releases the instance's resources. These are the only extension hooks.
|
|
42
42
|
|
|
43
43
|
## Coordinator ownership and delivery
|
|
44
44
|
|
|
45
|
-
Within a coordinator, an extension instance is identified by its qualified reference and, for a repository extension, its canonical
|
|
45
|
+
Within a coordinator, an extension instance is identified by its qualified reference and, for a repository extension, its canonical project root. Global instances have no checkout component. Failure state, admission eligibility and re-enablement are tracked separately for each instance identity. Repository instances with the same `repo:id` in different project roots are independent; enabling one affects only that root's instance. Parent, sibling-app, and linked-worktree app roots do not share repository consent.
|
|
46
46
|
|
|
47
|
-
Enablement is resolved when a coordinator session is admitted, for both CLI and connected SDK creation. Every enabled global extension receives that session's events; enabled repository extensions receive only sessions admitted
|
|
47
|
+
Enablement is resolved when a coordinator session is admitted, for both CLI and connected SDK creation. Every enabled global extension receives that session's events; enabled repository extensions receive only sessions admitted with their canonical project root. CLI `--root` selects that scope independently of execution cwd; public connected SDK creation retains default cwd-based discovery. Sessions keep that admission-time selection. Enabling an extension does not attach it to already admitted sessions, and disabling stops its eligibility for newly admitted sessions. It does not cancel agents or withdraw delivery for sessions already assigned to the running instance.
|
|
48
48
|
|
|
49
49
|
Extension admission is fail-open. Extension discovery or consent-read failures never block session admission or change the agent's task outcome. The session is admitted without extension delivery, and the coordinator retains a safe admission diagnostic for `subharness extensions list`. Admission diagnostics are separate from instance diagnostics because these failures may occur before an extension identity is known.
|
|
50
50
|
|
|
@@ -54,7 +54,7 @@ A failed instance stays disabled for the rest of its coordinator's lifetime and
|
|
|
54
54
|
|
|
55
55
|
The coordinator supervises the child and forwards only normalized, redacted events for its assigned sessions over a private, bounded IPC channel. Execution workers do not import extension code. Crashes, synchronous hangs, rejected handlers, timeouts and backpressure are isolated to the affected child; they do not block agents, coordinator control operations or other extensions. Extension code is trusted user-privileged Node.js code, not a security sandbox. Process supervision isolates delivery/execution lifetimes but does not grant protection from arbitrary filesystem or network side effects of explicitly enabled code.
|
|
56
56
|
|
|
57
|
-
The child runs with the extension directory as its working directory and a minimal environment containing only `PATH`, `HOME`, `TMPDIR` and locale variables. `NODE_OPTIONS`, the coordinator token, all `AGENT_*` variables, provider credentials, Gateway or OIDC tokens, and dotenv values are excluded. Its stdin is closed. Stdout and stderr go to an owner-private log for that instance. The coordinator compacts the log after it exceeds 1.5 MiB, trimming it back to the most recent 1 MiB. Global instances use `<stateDirectory>/extensions/global-<id>.log`. Repository instances use `<stateDirectory>/extensions/repo-<id>-<
|
|
57
|
+
The child runs with the extension directory as its working directory and a minimal environment containing only `PATH`, `HOME`, `TMPDIR` and locale variables. `NODE_OPTIONS`, the coordinator token, all `AGENT_*` variables, provider credentials, Gateway or OIDC tokens, and dotenv values are excluded. Its stdin is closed. Stdout and stderr go to an owner-private log for that instance. The coordinator compacts the log after it exceeds 1.5 MiB, trimming it back to the most recent 1 MiB. Global instances use `<stateDirectory>/extensions/global-<id>.log`. Repository instances use `<stateDirectory>/extensions/repo-<id>-<root-hash>.log`, where `<root-hash>` is the first 12 hex characters of the SHA-256 of the canonical project-root path. These filenames contain no colons. The selected coordinator's state directory follows the existing [selection rule](execution.md#ownership-and-transport-boundaries): explicit `ConnectOptions.stateDirectory`, then `AGENT_STATE_DIR`, then `~/.subharness/state/shared`. CLI commands use the environment/default selection rule. `subharness extensions list` shows the actual log path for each instance. Log contents never enter execution output, safe diagnostics or the dashboard. Failure to open, write or close this log never stops the extension instance. Unwritable output is discarded, and the instance reports the informational `EXTENSION_LOG_UNAVAILABLE` diagnostic.
|
|
58
58
|
|
|
59
59
|
## Bounds, shutdown and diagnostics
|
|
60
60
|
|
|
@@ -62,7 +62,7 @@ Setup and each handler have a five-second deadline. At most 128 events or 1 MiB
|
|
|
62
62
|
|
|
63
63
|
On shutdown or disablement caused by failure, delivery stops and pending undelivered events are released. The child lifetime signal aborts and `dispose` is called once when the process can cooperate, with a one-second budget. The coordinator terminates an unresponsive child; a crash or forced termination cannot guarantee disposal or completion of a file write. Side effects already performed are not rolled back, and delivery is not an exactly-once transaction. A successful shutdown confirms the supervised process has stopped; cleanup failures are explicit.
|
|
64
64
|
|
|
65
|
-
Manifest/module/export/dependency failures use `EXTENSION_LOAD_FAILED`, and API/event-version mismatches use `EXTENSION_INCOMPATIBLE`. Disposal failures use `EXTENSION_DISPOSE_FAILED`. An unexpected extension-process exit uses `EXTENSION_EXITED` and disables the instance under the same failed-instance lifetime and re-enablement rules as other failures. Messages identify the qualified reference,
|
|
65
|
+
Manifest/module/export/dependency failures use `EXTENSION_LOAD_FAILED`, and API/event-version mismatches use `EXTENSION_INCOMPATIBLE`. Disposal failures use `EXTENSION_DISPOSE_FAILED`. An unexpected extension-process exit uses `EXTENSION_EXITED` and disables the instance under the same failed-instance lifetime and re-enablement rules as other failures. Messages identify the qualified reference, logical project root when applicable, and failure phase, contain at most 1 KiB of safe text, and omit event content, raw exception messages/stacks, credentials and raw stdout/stderr. The CLI displays `EXTENSION_*` codes with their safe messages only through `subharness extensions list`. These failures also remain available through the coordinator's existing safe diagnostics. The dashboard neither loads nor hosts extensions and does not display extension diagnostics. Extension output never enters execution-command output, these diagnostics or the dashboard. Runtime failures remain visible through `subharness extensions list` for the owning coordinator's lifetime; they disable that runtime instance without changing stored consent and are not task failures. Runtime status reports each instance as `running`, `idle` or `disabled` and retains at most its eight most recent diagnostics. Each diagnostic records whether it disabled the instance and when it occurred.
|
|
66
66
|
|
|
67
67
|
`subharness extensions list` and the coordinator's extension-status operation each report at most 256 instances. When more instances exist, each reports the exact number omitted. The status operation also retains at most the 16 most recent admission diagnostics, separately from instance diagnostics. An admission diagnostic includes a workspace when one was resolved safely.
|
|
68
68
|
|
|
@@ -71,13 +71,13 @@ Manifest/module/export/dependency failures use `EXTENSION_LOAD_FAILED`, and API/
|
|
|
71
71
|
Install a compiled extension in one of these directories:
|
|
72
72
|
|
|
73
73
|
- `~/.subharness/extensions/<id>/` for a global installation.
|
|
74
|
-
- `<
|
|
74
|
+
- `<project-root>/.subharness/extensions/<id>/` for a repository installation.
|
|
75
75
|
|
|
76
76
|
Each directory contains `extension.json`, a compiled ESM entry and any packaged dependencies. A compiled extension is self-contained: it must not require a runtime import of Subharness. A `.mjs` entry can use Node's ESM loading directly; a `.js` entry requires suitable ESM package metadata. There is no TypeScript evaluation or build during discovery or activation.
|
|
77
77
|
|
|
78
|
-
Discovery reads static manifests only, without importing agent or extension modules.
|
|
78
|
+
Discovery reads static manifests only, without importing agent or extension modules. Without `--root`, repository scope uses the nearest canonical Git worktree root, or the command's directory outside Git. With `--root`, discovery uses only that root's `.subharness/extensions/`. Enclosing project installations are not merged. Linked-worktree app roots are separate repository scopes. Discovery does not traverse symlink directories or search parent repositories. Each `extension.json` is at most 16 KiB, and any `package.json` read from an extension directory is at most 64 KiB. Unknown fields, invalid IDs/versions, unsupported schema versions, missing entries and entry paths escaping the installation directory fail validation. `version` is the extension artifact's semantic version. Manifest/API/event versions are independent of the core package's npm version. `eventVersion` names the `SessionEvent` schema version and must equal `EventBase.version`. `apiVersion` gates the `ExtensionDefinition` contract. A mismatch of either version uses `EXTENSION_INCOMPATIBLE`.
|
|
79
79
|
|
|
80
|
-
Nothing executes merely because a repository contains extension files. The current user explicitly enables an installation with `subharness extensions enable <global:id|repo:id>`. Consent is stored in `~/.subharness/extensions.json` with owner-only permissions, using the [extension consent schema](config.md#extension-consent-and-logs). Repository enablement is keyed by canonical
|
|
80
|
+
Nothing executes merely because a repository contains extension files. The current user explicitly enables an installation with `subharness extensions enable <global:id|repo:id>`. Consent is stored in `~/.subharness/extensions.json` with owner-only permissions, using the [extension consent schema](config.md#extension-consent-and-logs). Repository enablement is keyed by canonical project root and never stored in repository files. Existing checkout keys remain valid; app-root keys require their own consent with no store migration. Enabled repository code is that project's current code when the supervised process loads it. Consent persists after edits; a running process does not hot-reload its module. Installation sources do not silently replace one another: global and repository references remain qualified and independently enabled.
|
|
81
81
|
|
|
82
82
|
The consent file is at most 256 KiB, with at most 1,024 repository entries and 256 IDs per scope: 256 global IDs and 256 IDs for each repository entry. Every extensions command rejects an existing consent file that is not owner-only, exits `1`, and directs the user to restrict its permissions with `chmod 600 ~/.subharness/extensions.json`. No command repairs its permissions.
|
|
83
83
|
|
|
@@ -169,7 +169,7 @@ subharness extensions enable global:tool-result-logger
|
|
|
169
169
|
subharness extensions list
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
-
For repository scope, run from the worktree root:
|
|
172
|
+
For default repository scope, run from the worktree root:
|
|
173
173
|
|
|
174
174
|
```sh
|
|
175
175
|
mkdir -p .subharness/extensions
|
|
@@ -178,4 +178,12 @@ subharness extensions enable repo:tool-result-logger
|
|
|
178
178
|
subharness extensions list
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
+
For an app installation, place the artifact in `apps/my-app/.subharness/extensions/tool-result-logger/` and select the same root for consent and execution:
|
|
182
|
+
|
|
183
|
+
```sh
|
|
184
|
+
subharness extensions enable repo:tool-result-logger --root ./apps/my-app
|
|
185
|
+
subharness extensions list --root ./apps/my-app
|
|
186
|
+
subharness run --root ./apps/my-app codex --prompt "Review this app."
|
|
187
|
+
```
|
|
188
|
+
|
|
181
189
|
Enable only the installation(s) whose logging behavior is wanted. The first newly admitted matching coordinator session starts the extension. Its `item.completed` observations include succeeded, failed, cancelled or unknown tool outcomes without inferring success. Logs can contain source code and paths; the user owns their storage, permissions, retention and deletion. Directory/file mode arguments apply when this example creates them and do not tighten permissions on an existing path. A handler failure or slow storage disables the extension instance with a safe list diagnostic, without delaying the agent. An abrupt child exit can leave a partial final line; consumers must tolerate that outcome.
|
package/sdk/index.md
CHANGED
|
@@ -17,6 +17,7 @@ This index is the entry point to the authoritative subharness contracts. The Typ
|
|
|
17
17
|
- [CLI output](cli/output.md): compact text, typed JSONL records, states, and exit codes.
|
|
18
18
|
- [Dashboard presentation](cli/dashboard-design.md): the read-only live terminal hierarchy and interaction contract.
|
|
19
19
|
- [Extension commands](cli/extensions.md): manifest discovery, directory installation and explicit per-user enablement.
|
|
20
|
+
- [Logical project roots](project-root.md): app-specific agents, access and extensions, execution directories, and shared worktree access.
|
|
20
21
|
- [Agent discovery](config.md): repository and global definitions, naming, and personal worktree settings.
|
|
21
22
|
- [Agent skill](agent-skill.md): the installable skill that teaches a coding agent to delegate with the CLI.
|
|
22
23
|
|
|
@@ -37,7 +37,7 @@ Codex receives the same declared-child instructions and private launcher, but th
|
|
|
37
37
|
|
|
38
38
|
For every harness, the native execution environment must allow the CLI to read its private launcher and contact the coordinator over loopback HTTP. A native sandbox that blocks local networking also blocks CLI delegation. The library does not relax that policy automatically; the caller supplies explicit native permission options, native settings, or an external execution environment. A lead can instead own independent review outside a managed agent's native delegation flow when the environment cannot grant these prerequisites.
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
Managed runs use the ordinary prompt and execution options, with a declared `subagent:` target:
|
|
41
41
|
|
|
42
42
|
```sh
|
|
43
43
|
# Execute through the host's background-command controls when available.
|
|
@@ -47,6 +47,8 @@ subharness run subagent:reviewer --cwd /repo/worktree \
|
|
|
47
47
|
|
|
48
48
|
The suffix is the local map key. It resolves only against the current parent's direct declarations, with no ancestor/global/repository fallback. Missing parent context or an undeclared name is an error. Parent context is passed privately by the integration; no public parent-token flag is required.
|
|
49
49
|
|
|
50
|
+
An explicitly selected [logical project root](../project-root.md#sessions-and-managed-children) and its access root are inherited transitively. Managed `list`, `run`, and `check` cannot supply `--root`, even to repeat the inherited value. Child `--cwd` selects execution independently of inherited access and extension scope; when omitted, it uses the invoking managed command's directory. Parents without an explicit root retain default cwd-based discovery. Each native session still reads settings and credential sources at startup; inheritance does not copy a parent's resolved credentials.
|
|
51
|
+
|
|
50
52
|
Each invocation creates a child session and task. The same `send`, `wait`, `status`, `queue`, `cancel`, and `resume` commands apply. A caller can instead coordinate independently discovered agents directly; that does not implicitly create a nested pipeline.
|
|
51
53
|
|
|
52
54
|
## Context and results
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Logical project roots
|
|
2
|
+
|
|
3
|
+
`--root <directory>` selects a Subharness project independently of the Git repository root. An application inside a monorepo can own its agents, personal access settings, and extensions. The selected directory must already exist. Subharness does not create a repository, worktree, directory, sandbox, or native permission boundary.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
subharness list --root ./apps/my-app
|
|
7
|
+
subharness check --root ./apps/my-app repo:reviewer
|
|
8
|
+
subharness run --root ./apps/my-app repo:reviewer --prompt "Review this app."
|
|
9
|
+
subharness extensions list --root ./apps/my-app
|
|
10
|
+
subharness extensions enable repo:tool-result-logger --root ./apps/my-app
|
|
11
|
+
subharness extensions disable repo:tool-result-logger --root ./apps/my-app
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The option is supported by `list`, `check`, `run`, and extension `list`, `enable`, and `disable`. Options can precede or follow a run/check target or an extension enable/disable reference. Existing prompt sources, direct-harness options, and output formats remain unchanged. Other commands do not accept `--root`; session identifiers already identify the retained execution context. Extension commands remain text-only and do not accept `--cwd`. Help retains its existing no-execution behavior and option-combination restrictions.
|
|
15
|
+
|
|
16
|
+
## Selection and execution
|
|
17
|
+
|
|
18
|
+
Relative `--root` paths resolve from the invoking command's directory and are canonicalized. Absolute paths are accepted. A missing value, blank value, or repeated flag is `INVALID_ARGUMENT`. An inaccessible or non-directory root is `INVALID_CONFIG` with a safely quoted path. Root argument and directory-validation failures exit `2`, including extension commands. No parent directory search or automatic app discovery occurs.
|
|
19
|
+
|
|
20
|
+
Without `--root`, all existing discovery, access, execution, and extension rules remain unchanged. With `--root`, let `root` mean the canonical selected directory and `accessRoot` mean its personal-access counterpart defined below.
|
|
21
|
+
|
|
22
|
+
| Resource or argument | Explicit-root behavior |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| Repository agents | Discover only `root/.subharness/agents/`, retaining recursive `.ts` discovery and validation. |
|
|
25
|
+
| Global agents | Continue discovering `~/.subharness/agents/`. Qualified references and bare-name ambiguity rules are unchanged. |
|
|
26
|
+
| Execution directory | For a top-level invocation, an omitted `--cwd` defaults to `root`; managed children retain their invoking directory as described below. An explicit relative `--cwd` resolves from the invoking directory, independently of `--root`, and may be outside the selected project. |
|
|
27
|
+
| Personal settings | Load only `accessRoot/.subharness/agents.local.json`. |
|
|
28
|
+
| Credential and project references | Resolve relative `envFile` and `project` values, including OIDC's default project `.`, from `accessRoot`. Absolute references retain their supplied locations. |
|
|
29
|
+
| Repository extensions | Discover only `root/.subharness/extensions/`; use the selected root for repository consent and instance identity. |
|
|
30
|
+
| Global extensions | Retain their existing consent and applicability across projects. |
|
|
31
|
+
| Explicit definition file | Resolve relative to the invoking directory, independently of both flags. Load only the selected definition and its imports; the selected root still determines access and extensions. |
|
|
32
|
+
|
|
33
|
+
Repository catalogs, settings, and extensions are not merged with the enclosing Git repository or another app. A missing agent catalog contains no repository agents. The personal settings file remains optional: absence uses the existing documented per-harness defaults at that selected location, without reading the enclosing repository's settings. Invalid settings fail normally. Omitted harness entries, empty connection arrays, and ordered explicitly configured alternatives retain their existing access semantics.
|
|
34
|
+
|
|
35
|
+
All target forms use the selected project: repository/global specialists, unambiguous names, direct harnesses, and explicit definition files. An explicit file does not register itself in the project's catalog. A definition's module-relative imports and the native harness's own instruction discovery retain their existing rules.
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
subharness run --root ./apps/my-app --cwd ./scratch \
|
|
39
|
+
./shared-agents/reviewer.ts --prompt "Review the scratch directory."
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This command uses the app's access and enabled extensions, evaluates the selected definition in `scratch`, and runs the native harness there. Root selection does not expand native filesystem or tool permissions.
|
|
43
|
+
|
|
44
|
+
## Personal access and worktrees
|
|
45
|
+
|
|
46
|
+
For a selected root inside Git, find its containing worktree root and main checkout independently of execution `--cwd`. The access root is the main checkout followed by the selected root's path relative to its worktree root. Outside Git, the selected root is also the access root. Nested independent Git repositories use their own worktree relationship.
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
Selected root: /worktrees/feature/apps/my-app
|
|
50
|
+
Worktree root: /worktrees/feature
|
|
51
|
+
Main checkout: /checkouts/repo
|
|
52
|
+
Access root: /checkouts/repo/apps/my-app
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Definitions and extensions come from the selected worktree's app. Personal settings and relative credential/project paths come from the corresponding app in the main checkout. Changing execution `--cwd` does not change either root. No personal settings or credentials are copied into a worktree.
|
|
56
|
+
|
|
57
|
+
The counterpart must be an accessible directory at the corresponding canonical path inside the main checkout. A missing counterpart or a symlink redirect to a different location fails access startup with `INVALID_CONFIG`; it never selects the parent project's settings or worktree-local credentials instead. A missing optional settings file within an accessible counterpart retains the documented absence behavior. An app that exists only in a feature worktree therefore needs its corresponding personal-access directory in the main checkout before access startup. Listing agents or managing extensions does not require access startup.
|
|
58
|
+
|
|
59
|
+
An app-local access file can use the existing schema without repeating its monorepo path:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"access": {
|
|
64
|
+
"codex": [{ "type": "vercel-oidc", "envFile": ".env.local", "project": "." }]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The personal-file Git policy applies to the actual selected settings path. A tracked settings file is rejected before modifying local excludes. An untracked app settings file is excluded by its exact repository-relative path, with Git pattern characters escaped; the enclosing app and other files are not ignored. Git inspection and exclude updates use the owning repository, unaffected by inherited Git environment overrides. Existing errors remain explicit; Subharness does not untrack files or modify a committed `.gitignore`.
|
|
70
|
+
|
|
71
|
+
A repository-relative settings path containing a line feed or carriage return cannot be represented safely in Git's line-based exclude file. Loading an existing personal settings file at such a path fails with `INVALID_CONFIG` and a safely quoted path before changing local excludes. This restriction does not affect catalog listing, extension management, or settings outside Git.
|
|
72
|
+
|
|
73
|
+
The standalone OIDC renewal helper keeps its existing interface and prerequisites. For a root-selected session, resolve its absolute credential-file and project arguments from the selected connection and `accessRoot`. A subsequent top-level readiness check repeats `--root`; renewal does not change the selected account/project/billing route, refresh an already running native process, or replay work.
|
|
74
|
+
|
|
75
|
+
## Sessions and managed children
|
|
76
|
+
|
|
77
|
+
An explicitly selected project is retained as coordinator-owned session context. Follow-ups keep that selection. Declared children inherit the selected root and access root transitively. Their execution `--cwd` can differ, but does not change inherited access or extension scope. An omitted child `--cwd` retains the invoking managed command's directory; inheritance does not reset an explicitly different parent execution directory to the project root.
|
|
78
|
+
|
|
79
|
+
Managed `list` still lists only declared children. Managed `run` and `check` still require a declared `subagent:` target and the active parent context before loading definitions or settings. Managed `list`, `run`, and `check` cannot supply `--root`, even when it names the inherited root: after validating parent authority, such an override fails with `INVALID_ARGUMENT` at the CLI/coordinator boundary. Malformed command syntax retains normal argument validation. Parents with no explicit root retain their existing cwd-based child discovery rules. Extension management independently selects its installation scope from its own `--root` or invoking directory; it does not replace any running session's retained project selection.
|
|
80
|
+
|
|
81
|
+
The selection identifies locations, not a snapshot of JSON or credentials. Each native session reads its settings and credential sources at startup under the existing access contract; follow-ups retain their already selected native connection. Root inheritance does not copy a parent's resolved token or replace the child's captured environment. Definition closures retain their existing graph-owner cwd and environment. Session close, cancellation, detach, and reconnect retain their current lifecycle behavior.
|
|
82
|
+
|
|
83
|
+
Public connected and embedded SDK creation signatures are unchanged. Connected clients can inspect or continue CLI-created root-selected sessions, but their own creation and check operations retain the existing defaults. Embedded callers continue supplying definition objects and explicit runner access/environment.
|
|
84
|
+
|
|
85
|
+
## Extension scope and execution identity
|
|
86
|
+
|
|
87
|
+
Repository extension consent, instance identity, failure/re-enable state, status, and log hashing use the canonical selected project root. The existing consent file's `repositories` keys can represent app roots; no consent-store migration is needed. Existing checkout keys continue to apply to no-flag invocations and explicit roots equal to those checkouts. Parent, sibling-app, and linked-worktree app roots do not share repository consent. Global consent is unchanged.
|
|
88
|
+
|
|
89
|
+
`ExtensionContext.workspace` identifies the extension's logical project scope. With `--root`, it is the selected root. Enabled repository extensions receive sessions admitted to that root, even when their execution directory is elsewhere. Native session workspace metadata and dashboard Git grouping continue to describe the real execution directory and Git worktree; they are not rewritten to the logical project root.
|
|
90
|
+
|
|
91
|
+
Extension enablement retains its existing explicit consent requirement. Root selection alone does not enable an extension. Admission-time selection, retained delivery, process ownership, failure isolation, and per-instance limits remain unchanged.
|
|
92
|
+
|
|
93
|
+
## Coordinator compatibility
|
|
94
|
+
|
|
95
|
+
An explicit-root run requires the coordinator's `cli-root-v1` capability before admission. Managed `list`, `check`, and `run` invocations that supply `--root` also require this capability before submitting a parent operation. A reachable older coordinator returns `COORDINATOR_OUTDATED` with restart guidance; the client does not submit a request that could silently ignore the root, restart the coordinator automatically, fall back to a Git-root agent/access route, or replay a task. This compatibility check precedes coordinator-side parent authorization; a capable coordinator still validates parent authority before rejecting a root override. No-root invocations retain existing compatibility. Standalone top-level `list` and `check` remain coordinator-free. Extension management does not require `cli-root-v1`; its existing status-query and enable-notification compatibility behavior remains unchanged. Managed root inheritance and validation are owned by the coordinator, not by a caller-supplied environment variable.
|
|
96
|
+
|
|
97
|
+
The CLI resolves relative roots before submission; private coordinator admission requires an absolute project-root path and rejects a relative one with `INVALID_ARGUMENT`. Readiness execution requires the retained root and access root together. An incomplete private execution context fails with `INVALID_ARGUMENT` before native startup rather than reverting to cwd-based access, and releases its captured definition resources.
|
package/sdk/v1-runtime.md
CHANGED
|
@@ -16,11 +16,13 @@ Custom tools accept Zod 4 object schemas that can be represented as JSON Schema.
|
|
|
16
16
|
|
|
17
17
|
## Discovery and loading
|
|
18
18
|
|
|
19
|
-
Global definitions live in `~/.subharness/agents/`; repository definitions live in `.subharness/agents/` at the execution worktree root. Every `.ts` file under those directories except `.d.ts` declarations is a definition entry; see [agent discovery](config.md).
|
|
19
|
+
Global definitions live in `~/.subharness/agents/`; by default, repository definitions live in `.subharness/agents/` at the execution worktree root. Every `.ts` file under those directories except `.d.ts` declarations is a definition entry; see [agent discovery](config.md). Without `--root`, the execution directory is the project root outside Git, and nested repositories use the nearest Git worktree root. CLI [logical project selection](project-root.md) with `--root` instead selects that directory's repository catalog, access, and extensions without merging enclosing scopes. Bare repositories are unsupported execution directories. Symlink directories are not traversed during discovery.
|
|
20
|
+
|
|
21
|
+
CLI `run` and `check` can also select an [explicit definition file](config.md#explicit-definition-files) outside those catalog directories. Relative file targets resolve against the invoking command's directory, independently of execution `--cwd` and project `--root`. Loading skips unrelated catalogs and retains the existing captured-session, access-selection, and managed-child authorization rules.
|
|
20
22
|
|
|
21
23
|
Definitions are trusted executable TypeScript. Loading a catalog evaluates its modules, so callers must trust the selected project and global definition files. Imports resolve relative to each definition through normal Node package resolution, with TypeScript loading supplied by the CLI. Missing imports, invalid exports, and duplicate names fail with the source filename. A session retains its loaded instructions, tools, and harness configuration for follow-ups; new sessions load current definition sources.
|
|
22
24
|
|
|
23
|
-
An omitted `--cwd` uses the command's working directory. `--prompt-file` paths resolve against the calling command's directory
|
|
25
|
+
An omitted `--cwd` uses the explicit `--root`, or the command's working directory otherwise. Explicit relative `--cwd`, `--root`, and `--prompt-file` paths resolve independently against the calling command's directory; prompt files use UTF-8. Prompts must contain non-whitespace text and cannot exceed 1 MiB. One quoted positional prompt, `--prompt`, and `--prompt-file` are mutually exclusive. `--prompt-file -` reads bounded UTF-8 stdin to EOF and rejects a terminal input stream. Direct harness targets accept `--model` for `run` and `check`. Codex, Claude Code, and fx also accept `--effort`; OpenCode, Copilot, and Cursor reject it. Specialist targets reject both overrides.
|
|
24
26
|
|
|
25
27
|
`run` and task-creating `send` commands accept `--detach` with every prompt source. The option ends the requesting command's observation immediately after successful admission, so the command returns exactly the existing `started` record and exits `0`. The service explicitly completes that observation response; it does not rely on a caller abandoning a response body. Admission errors keep their records and exit codes, while later failures remain available through `wait` and `status`. Interrupt delivery confirms affected execution has stopped before replacement admission even when detached. Steering rejects `--detach` with `INVALID_ARGUMENT`. The option is an observation request and is never retained as session configuration.
|
|
26
28
|
|
|
@@ -36,6 +38,8 @@ The coordinator accepts local connections only. Its endpoint, instance identifie
|
|
|
36
38
|
|
|
37
39
|
Closing a response-reading command does not cancel work. The coordinator retains responses and session records for its lifetime. A coordinator restart does not replay tasks or reconstruct queues; unavailable identifiers return an explicit error. This version does not recover library sessions after coordinator or environment exit. Responses are not consumed by readers; each reader supplies its own position. Task/session metadata and complete-response records are not silently evicted while the coordinator is running. Live event delivery is separate and does not retain content for later subscribers.
|
|
38
40
|
|
|
41
|
+
Explicit project/access roots remain in coordinator-owned session context for follow-ups and declared children. Managed `list`, `run`, and `check` calls cannot supply `--root`; child execution cwd does not change inherited access or extension scope. Personal settings and relative credential/project references use the corresponding main-checkout app directory, or the selected root outside Git, with the validation and startup timing defined in [logical project roots](project-root.md). Actual execution workspace metadata and dashboard Git grouping remain cwd-based.
|
|
42
|
+
|
|
39
43
|
## Task states and responses
|
|
40
44
|
|
|
41
45
|
The coordinator supplies the terminal dashboard with a read-only snapshot of current session work followed by retained finished tasks, including failed active tasks that pause a queue. Each task appears at most once, and retained history is available to newly opened dashboards for the coordinator’s lifetime. The private snapshot includes `history: true` for finished history, `grouping: true` for grouped context, and `taskDetails: true` for the expanded task-detail fields. Missing `history` or `grouping` ends the dashboard with `COORDINATOR_OUTDATED` and exit `1`. Missing `taskDetails` keeps the dashboard running; opening a task screen shows `COORDINATOR_OUTDATED` with restart guidance instead of task details. It carries only session/task identity, selected harness, bounded prompt title, task state, canonical checkout/repository paths, and timestamps needed by the display; it excludes environment variables, credentials, definitions, transcripts, and native diagnostics. Reading it does not acknowledge responses or change task execution. Workers report the actual selected harness to the coordinator after native startup succeeds. Task timing records the first dispatch, latest failure, and terminal completion or confirmed-stop time without resetting on native continuations. Finished rows retain a fixed elapsed duration; recovery clears terminal timing for the resumed task. Snapshot observation adds no public SDK execution method or persistent history. The inspector uses a separate authenticated, read-only session-history projection for retained work requests, stable admission ordinals, queue state and direct child sessions. Full prompt/response content and summarized agent/model identity are fetched only for the open task screen through the task-detail projection. It omits already-cached prompt and response text on refresh and never acknowledges delegated outcomes or changes execution. The core task screen renders steps from a task-scoped live subscription; those events are absent from private dashboard projections. The private transport is defined in [Dashboard inspection](cli/dashboard-inspection.md); presentation is defined in [CLI](cli/index.md#live-dashboard).
|
|
@@ -68,7 +72,7 @@ Ordinary text/JSON tool results and complete responses are limited to 1 MiB. Ric
|
|
|
68
72
|
|
|
69
73
|
A managed task cannot delegate follow-up work into its own session or an ancestor's session. Such an admission returns `INVALID_PARENT` before changing any execution: that queued work would otherwise wait for the very task whose completion depends on it. Invalid delegation and replacement requests never cancel existing work.
|
|
70
74
|
|
|
71
|
-
The CLI and connected SDK select the same coordinator directory: an explicit SDK `stateDirectory`, otherwise `AGENT_STATE_DIR`, otherwise `~/.subharness/state/shared`. Connection authenticates the instance and requires protocol version 1 with the applicable `sdk-v1` or `cli-v1` capability.
|
|
75
|
+
The CLI and connected SDK select the same coordinator directory: an explicit SDK `stateDirectory`, otherwise `AGENT_STATE_DIR`, otherwise `~/.subharness/state/shared`. Connection authenticates the instance and requires protocol version 1 with the applicable `sdk-v1` or `cli-v1` capability. Explicit-root CLI runs and managed `list`, `check`, or `run` commands supplying `--root` additionally require `cli-root-v1` before submission; an older live coordinator yields `COORDINATOR_OUTDATED` without automatic restart, default-root fallback, or task replay.
|
|
72
76
|
|
|
73
77
|
Each candidate coordinator, rather than the CLI command that spawned it, holds an operating-system-backed startup lock from its final endpoint check through service startup and atomic endpoint publication. The lock is released automatically if the candidate exits. After acquiring it, a candidate retires without publishing when the retained endpoint gives a compatible authenticated health response for the recorded coordinator instance. It starts only when metadata is absent, or a well-formed stale record has a proven-dead owner and an unresponsive endpoint. Malformed, unauthorized, incompatible, or uncertain endpoints fail explicitly without replacement. This prevents a caller exit or a later candidate from exposing competing endpoint publication.
|
|
74
78
|
|
|
@@ -79,12 +83,12 @@ Lock contention is bounded by the spawning command's startup deadline. Waiting f
|
|
|
79
83
|
Coordinators leave endpoint records in place during shutdown. Legacy pathname lock artifacts do not grant startup ownership and are left untouched. An unavailable endpoint alone does not prove absence. A live or unknown owner, authentication failure, incompatible protocol, or instance mismatch forbids replacement startup. A permitted replacement atomically overwrites only a proven-stale record; tasks owned by the previous coordinator are not reconstructed. An interrupted coordinator response is reported as unavailable without exposing native diagnostics or automatically repeating the request. Disconnecting an observer detaches that observation; it does not cancel execution.
|
|
80
84
|
A successful detached task-creation request ends its service observation explicitly after the admission record while the coordinator continues to own the task.
|
|
81
85
|
|
|
82
|
-
Catalog discovery evaluates TypeScript in a short-lived process with the selected execution directory as its working directory. Module stdout and stderr are not mixed into CLI output.
|
|
86
|
+
Catalog discovery evaluates TypeScript in a short-lived process with the selected execution directory as its working directory. Module stdout and stderr are not mixed into CLI output. Sessions retain their loaded instructions, tools, and harness configuration in an isolated graph owner. Follow-ups and declared child sessions use that captured graph and its closures without re-importing changed files. New top-level sessions load the current definition source. Definition closures remain in their graph owner and are not serialized between processes.
|
|
83
87
|
|
|
84
88
|
## Live events and user extensions
|
|
85
89
|
|
|
86
90
|
The public [live event API](events.md) forwards normalized session events only to currently matching subscribers. With no subscriber, adapters skip event normalization and event IPC. Native startup options needed for partial output are enabled for every session so later subscribers receive supported deltas. Opening registers before its promise resolves, and only events accepted after that registration point are delivered. Adapters keep no extra observation content. Earlier content appears only when the native route later supplies it in a snapshot; for mid-item joins on chunk-only `fx-acp` and `cursor-acp`, turn-boundary snapshots cover only content normalized since registration and use state `"incomplete"`. Pending delivery is limited to 128 events or 1 MiB per subscriber; falling behind rejects observation with `EVENT_BACKPRESSURE` without delaying execution. Content limits and redaction apply before transfer.
|
|
87
91
|
|
|
88
|
-
Static extension manifests live in global and repository directories. Explicit per-user consent is stored in the owner-only `~/.subharness/extensions.json` file under the [extension consent schema](config.md#extension-consent-and-logs), with repository consent per canonical
|
|
92
|
+
Static extension manifests live in global and repository directories. Explicit per-user consent is stored in the owner-only `~/.subharness/extensions.json` file under the [extension consent schema](config.md#extension-consent-and-logs), with repository consent per canonical logical project root. Without `--root`, that remains the execution worktree root or execution directory outside Git. At every newly admitted coordinator session, including connected SDK creation, the coordinator selects all enabled global extensions and enabled repository extensions for the selected logical root, independently of execution cwd when `--root` is used. Instance identity is the qualified reference plus the canonical project root for repository extensions; global instances have no checkout component. Failure state, admission eligibility and re-enablement are scoped to that identity. Enabling one project root affects only that root's repository instance; app roots do not inherit consent from parent or sibling roots or other worktrees. Each applicable extension runs in a separately supervised child process from its first matching session until coordinator close, unless failure disables it. Execution workers, CLI dashboards and embedded runners do not load extension modules. Disabling removes eligibility for newly admitted sessions while existing assignments continue. A failed instance remains disabled and visible through `subharness extensions list` for the coordinator's lifetime, without automatic restart or failure of agents or other extensions. Explicitly enabling the selected instance identity again saves consent and notifies a running coordinator to permit a new process at the first newly admitted matching session; sessions assigned to the failed instance are not reassigned. If notification fails, consent stays saved and enable warns that the failure state clears on coordinator restart, exiting `0`. No notification is needed when no coordinator is running. Restarting the coordinator resets runtime failure state.
|
|
89
93
|
|
|
90
94
|
The CLI task screen itself opens the public task-scoped live subscription and renders incoming turns, assistant text, reasoning, tool and approval steps, and inline session-error notices. Approval and session-error rows count toward the display bound. Its original request, task error and latest complete response come from ordinary inspection. The open screen displays at most 500 steps, dropping the oldest with a visible omission notice; this bound belongs only to dashboard display state. Leaving closes the subscription and discards that state. Reopening does not retrieve past events. Earlier content appears only when the native route itself supplies it in a later snapshot; chunk-only mid-item views remain incomplete. The screen consumes events independently of rendering. After `EVENT_BACKPRESSURE`, it shows a missed-steps notice and follows the [dashboard retry bounds](cli/dashboard-design.md#refresh-and-compatibility): at most one reopen every 2 seconds, stopping after 3 consecutive failures within 60 seconds, counting failed reopens. It then shows “Live steps paused; reopen the task to retry.” SDK applications implement custom event handling through direct subscriptions. [User extensions](extensions.md) defines the plain-object module API, supervised lifetime, manifest, diagnostics and complete logger example.
|