dsh-taskbridge 0.0.0-stage → 1.3.1
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/CHANGELOG.md +754 -0
- package/LICENSE +21 -0
- package/README.md +624 -3
- package/bin/dsh-delegate-codex-agent.js +115 -0
- package/bin/dsh-delegate-control.d.ts +90 -0
- package/bin/dsh-delegate-control.js +450 -0
- package/bin/dsh-delegate-mcp.d.ts +121 -0
- package/bin/dsh-delegate-mcp.js +273 -0
- package/codex/dsh-delegate.toml +245 -0
- package/cordis.patch.yml +6 -0
- package/docs/INTRODUCTION.md +15 -0
- package/docs/INTRODUCTION.zh.md +32 -0
- package/docs/auth-contract.md +138 -0
- package/docs/claude-code.md +31 -0
- package/docs/codex-integration.md +922 -0
- package/docs/contracts-stage-b.md +443 -0
- package/docs/conversation-placement.md +293 -0
- package/docs/plugin-market.md +30 -0
- package/docs/redaction-contract.md +127 -0
- package/docs/runtime-compatibility.md +220 -0
- package/docs/silent-wait.md +191 -0
- package/docs/taskbridge-upgrade.md +28 -0
- package/docs/taskdispatch-upgrade.md +25 -0
- package/docs/worker-permissions.md +347 -0
- package/docs/workspace-contract.md +538 -0
- package/icon.svg +1 -0
- package/lib/client.d.ts +118 -0
- package/lib/client.js +3232 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +135 -4
- package/src/auth/fence.js +361 -0
- package/src/auth/grants.js +789 -0
- package/src/client/api.js +2322 -0
- package/src/client/index.jsx +2333 -0
- package/src/client/styles.js +251 -0
- package/src/codex/installer.js +3260 -0
- package/src/codex/seam.js +429 -0
- package/src/codex/toml.js +784 -0
- package/src/config/defaults.js +164 -0
- package/src/config/redact.js +184 -0
- package/src/config/settings.js +629 -0
- package/src/config/store.js +186 -0
- package/src/config/validate.js +763 -0
- package/src/credentials/seam.js +202 -0
- package/src/http/execution-plane.js +454 -0
- package/src/http/respond.js +175 -0
- package/src/http/user-plane.js +1122 -0
- package/src/index.d.ts +332 -0
- package/src/index.js +657 -0
- package/src/jobs/activity.js +1008 -0
- package/src/jobs/engine.js +3609 -0
- package/src/jobs/history.js +1467 -0
- package/src/mcp/server.js +1820 -0
- package/src/mcp/wait.js +536 -0
- package/src/model/connectivity.js +371 -0
- package/src/model/discovery.js +582 -0
- package/src/model/native-catalog.js +68 -0
- package/src/model/openai-adapter.js +671 -0
- package/src/model/probe.js +264 -0
- package/src/model/providers.js +756 -0
- package/src/model/routing.js +321 -0
- package/src/review/preset.js +868 -0
- package/src/review/prompts.js +126 -0
- package/src/review/reviewer.js +933 -0
- package/src/runtime/agent-runner.js +1738 -0
- package/src/runtime/endpoint-discovery.js +118 -0
- package/src/runtime/permissions.js +1429 -0
- package/src/runtime/sandbox.js +358 -0
- package/src/runtime/session-placement.js +1103 -0
- package/src/workspace/audit.js +775 -0
- package/src/workspace/locks.js +167 -0
- package/src/workspace/preflight.js +424 -0
- package/src/workspace/worktrees.js +613 -0
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
# Workspace contract: preflight, audit evidence and worktree isolation
|
|
2
|
+
|
|
3
|
+
This document is the contract between the workspace layer
|
|
4
|
+
(`src/workspace/preflight.js`, `src/workspace/audit.js`,
|
|
5
|
+
`src/workspace/worktrees.js`) and the job engine (`src/jobs/engine.js`). It states
|
|
6
|
+
what the layer guarantees, what it refuses, and the exact shapes that cross the
|
|
7
|
+
boundary, so the engine can be wired to it without either side guessing.
|
|
8
|
+
|
|
9
|
+
All three modules are read-only with respect to the repository they inspect, with
|
|
10
|
+
one deliberate exception: `WorktreeManager` creates and removes its own worktrees
|
|
11
|
+
using `git worktree` only. `preflight.js` (§3.5) is the strictly read-only one: it
|
|
12
|
+
runs five git reads and nothing else.
|
|
13
|
+
|
|
14
|
+
### Repository root
|
|
15
|
+
|
|
16
|
+
A **workspace** in this contract is a repository **root** — the directory
|
|
17
|
+
`git rev-parse --show-toplevel` reports — not merely a directory inside one.
|
|
18
|
+
|
|
19
|
+
Both the preflight and the worktree manager measure that top level with
|
|
20
|
+
`git rev-parse --show-toplevel` before deciding anything, and both refuse a path
|
|
21
|
+
that is inside a repository without being its root:
|
|
22
|
+
|
|
23
|
+
- `preflightWorkspace` answers `block` / `PREFLIGHT_NOT_A_REPOSITORY_ROOT` and
|
|
24
|
+
names the measured root. A subdirectory is **not** a workspace: an isolated
|
|
25
|
+
tree created "for" it would land inside the user's checkout, which is exactly
|
|
26
|
+
what isolation is supposed to prevent. It is never recommended `worktree` or
|
|
27
|
+
`shared`.
|
|
28
|
+
- `WorktreeManager.prepare` refuses with `WORKTREE_NESTED_DESTINATION` when its
|
|
29
|
+
configured `rootDir` lies anywhere inside the **repository root**, even when the
|
|
30
|
+
supplied `sourcePath` is a subdirectory that does not contain the root. The
|
|
31
|
+
containment boundary is the measured top level, never the supplied path.
|
|
32
|
+
|
|
33
|
+
`git rev-parse --is-inside-work-tree` answers `true` for *any* directory inside a
|
|
34
|
+
work tree, so it is a necessary fact but never a sufficient one. An unmeasurable
|
|
35
|
+
top level is a refusal, never an assumed root: "could not tell" must not read as
|
|
36
|
+
"this is the root".
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 1. What "audited" means
|
|
41
|
+
|
|
42
|
+
The claim this layer supports is narrow and checkable:
|
|
43
|
+
|
|
44
|
+
> The diff the host reviews was produced by git, against a commit that was
|
|
45
|
+
> recorded before the run started, with credential material excluded before git
|
|
46
|
+
> read it.
|
|
47
|
+
|
|
48
|
+
It does **not** claim the run is sandboxed, that the agent could not write
|
|
49
|
+
elsewhere on disk, or that the evidence is complete when a bound was hit. Bounds
|
|
50
|
+
are reported, not hidden.
|
|
51
|
+
|
|
52
|
+
### Fixed comparison point
|
|
53
|
+
|
|
54
|
+
`captureBaseline` records `head` as a resolved 40-hex commit id. Every later
|
|
55
|
+
`captureDiff` compares against **that commit**, never against the string `HEAD`.
|
|
56
|
+
This matters because a delegated run can commit: with a mutable `HEAD`, a run
|
|
57
|
+
that commits its work would diff to nothing and appear to have done nothing.
|
|
58
|
+
|
|
59
|
+
A baseline without a pinned `head` is refused (`AUDIT_BASELINE_INVALID`) rather
|
|
60
|
+
than defaulted to `HEAD`.
|
|
61
|
+
|
|
62
|
+
### NUL parsing
|
|
63
|
+
|
|
64
|
+
Status and numstat are read with `-z`. In that form git never quotes or escapes a
|
|
65
|
+
path, so a filename containing a space, a quote, a backslash, `*`, `[` or
|
|
66
|
+
non-ASCII bytes is reported as itself.
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
$ git status --porcelain=v1 -z --untracked-files=all
|
|
70
|
+
XY <path>\0 regular record
|
|
71
|
+
R <new path>\0<old path>\0 rename/copy: one extra token, new path first
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
A status read that returns no NUL delimiter at all is refused
|
|
75
|
+
(`AUDIT_GIT_FAILED`, `details.step = "status"`): filenames in that output have
|
|
76
|
+
been rewritten, and re-parsing them would mis-attribute a change to a file that
|
|
77
|
+
does not exist. The layer does not guess.
|
|
78
|
+
|
|
79
|
+
Rename and copy records keep **both** paths. `sensitive` is true when either side
|
|
80
|
+
is sensitive, because a rename *from* `.env` to `notes.txt` is exactly how
|
|
81
|
+
credential content would otherwise enter a patch under a harmless name.
|
|
82
|
+
|
|
83
|
+
### Sensitive paths
|
|
84
|
+
|
|
85
|
+
Sensitivity is decided by `isSensitivePath` in `src/config/redact.js` (`.env*`,
|
|
86
|
+
`credentials*`, `secret*`, `id_rsa*`, `id_ed25519*`, `*.pem`, `*.key`, `*.pfx`,
|
|
87
|
+
`*.p12` — matched per path segment, case-insensitive).
|
|
88
|
+
|
|
89
|
+
The order of operations is the security property:
|
|
90
|
+
|
|
91
|
+
1. `git status -z` lists what changed;
|
|
92
|
+
2. sensitive paths are collected from **both** sides of every rename, for
|
|
93
|
+
**tracked and untracked** entries, and checked against
|
|
94
|
+
`AUDIT_LIMITS.sensitivePaths`;
|
|
95
|
+
3. those paths are handed to `git diff` as literal exclusion pathspecs
|
|
96
|
+
(`:(exclude,literal)<path>`);
|
|
97
|
+
4. untracked non-sensitive files are `lstat`-described and only then rendered;
|
|
98
|
+
5. resulting text passes through `redactText` as a safety net.
|
|
99
|
+
|
|
100
|
+
So the content of a sensitive path is never read by this process, and a sensitive
|
|
101
|
+
untracked file is never opened at all. `literal` is mandatory in step 3: a
|
|
102
|
+
filename containing `[` would otherwise be interpreted as a glob that matches a
|
|
103
|
+
different file — either leaking the excluded file back in or excluding the wrong
|
|
104
|
+
one.
|
|
105
|
+
|
|
106
|
+
If more sensitive paths were touched than `sensitivePaths` (100), the patch is
|
|
107
|
+
**withheld entirely** and `patchWithheld: true` is set. A partially filtered diff
|
|
108
|
+
over an unbounded set is precisely the leak the bound exists to prevent.
|
|
109
|
+
|
|
110
|
+
### Bounds
|
|
111
|
+
|
|
112
|
+
| Bound | Value | Effect when exceeded |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| `files` | 500 | `files` list truncated; `fileCount` keeps the true total; `truncatedFiles: true` |
|
|
115
|
+
| `statusEntries` | 2000 | extra entries not parsed; `truncatedFiles: true` |
|
|
116
|
+
| `patchBytes` | 64 KiB | patch cut on a byte boundary with a truncation marker; `patchTruncated: true` |
|
|
117
|
+
| `patchFiles` | 50 | further untracked files not rendered; `patchTruncated: true` |
|
|
118
|
+
| `sensitivePaths` | 100 | patch withheld (above) |
|
|
119
|
+
| `statLines` | 200 | `changes` truncated |
|
|
120
|
+
| `gitTimeoutMs` | 8000 | the invocation is killed; refusal |
|
|
121
|
+
| `gitMaxBytes` | 8 MiB | stdout/stderr capture refuses rather than truncating |
|
|
122
|
+
|
|
123
|
+
A file larger than `patchBytes` is skipped with an explicit
|
|
124
|
+
`diff -- omitted <path>: <n> bytes exceeds the patch budget` marker, so its
|
|
125
|
+
absence is visible in the evidence rather than silent.
|
|
126
|
+
|
|
127
|
+
### Git hardening
|
|
128
|
+
|
|
129
|
+
Every diff invocation carries `--no-ext-diff --no-textconv`, and every
|
|
130
|
+
invocation is an argv array with `shell: false`. `--no-ext-diff` stops a
|
|
131
|
+
repository-configured diff driver and `--no-textconv` stops a textconv filter
|
|
132
|
+
from running against a file being excluded — both are configured *inside the
|
|
133
|
+
audited repository*, so neither can be trusted to be absent.
|
|
134
|
+
|
|
135
|
+
Nothing in `audit.js` runs a mutating git command: no `add`, `commit`,
|
|
136
|
+
`checkout`, `reset`, `switch`, `stash`, `merge`, `rebase`, `clean`, `worktree`.
|
|
137
|
+
|
|
138
|
+
### Fail closed
|
|
139
|
+
|
|
140
|
+
Every git read either succeeds or throws an `AuditError`. The codes:
|
|
141
|
+
|
|
142
|
+
| Code | Meaning |
|
|
143
|
+
|---|---|
|
|
144
|
+
| `AUDIT_GIT_UNAVAILABLE` | git cannot be executed here (missing or denied by the sandbox) |
|
|
145
|
+
| `AUDIT_NOT_A_REPOSITORY` | not inside a git work tree |
|
|
146
|
+
| `AUDIT_NOT_A_REPOSITORY_ROOT` | inside a work tree but not its top level; used by the preflight, which maps it to `PREFLIGHT_NOT_A_REPOSITORY_ROOT` |
|
|
147
|
+
| `AUDIT_NO_COMMITS` | repository exists but has no commit |
|
|
148
|
+
| `AUDIT_GIT_FAILED` | a git read failed; `details.step` / `details.exitCode` / bounded `details.stderr` |
|
|
149
|
+
| `AUDIT_BASELINE_INVALID` | the baseline has no pinned `head` |
|
|
150
|
+
|
|
151
|
+
There is no "empty diff" fallback. A workspace that cannot be audited refuses
|
|
152
|
+
job execution; the engine maps this to `JOB_AUDIT_UNAVAILABLE`.
|
|
153
|
+
|
|
154
|
+
Bounded, redacted stderr is the only diagnostic text kept — never file content,
|
|
155
|
+
never a full git error dump.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 2. `captureBaseline(deps, workspacePath)`
|
|
160
|
+
|
|
161
|
+
`deps` must expose `runGit(cwd, argv) => Promise<{ stdout: string, stderr: string, code: number }>`.
|
|
162
|
+
`src/workspace/audit.js` exports `createGitRunner()` as the production
|
|
163
|
+
implementation. A runner that throws `EPERM`/`EACCES`/`ENOENT` (or throws
|
|
164
|
+
synchronously) is normalised to `AUDIT_GIT_UNAVAILABLE`.
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"head": "5d0f…(40 hex, the pinned comparison commit)",
|
|
169
|
+
"dirtyBaseline": true,
|
|
170
|
+
"preexistingChanges": 3,
|
|
171
|
+
"preexistingPaths": ["src/a.js", "notes.txt", ".env"],
|
|
172
|
+
"statusTruncated": false,
|
|
173
|
+
"statusFormat": "porcelain-v1-z",
|
|
174
|
+
"capturedAt": 1792400000000
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`preexistingPaths` is names only, bounded to 100: the host needs to know the
|
|
179
|
+
checkout was already dirty, not what was already in it.
|
|
180
|
+
|
|
181
|
+
## 3. `captureDiff(deps, workspacePath, baseline)`
|
|
182
|
+
|
|
183
|
+
Optional `deps.statPath(absolutePath) => { kind, size }` overrides the file
|
|
184
|
+
inspector used for untracked files (default `describePath`, which uses `lstat`).
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"head": "5d0f…",
|
|
189
|
+
"baseHead": "5d0f…",
|
|
190
|
+
"dirtyBaseline": false,
|
|
191
|
+
"preexistingChanges": 0,
|
|
192
|
+
"files": [{ "code": " M", "path": "src/a.js", "from": null, "status": "modified", "sensitive": false }],
|
|
193
|
+
"fileCount": 1,
|
|
194
|
+
"truncatedFiles": false,
|
|
195
|
+
"changes": [{ "added": "3", "removed": "1", "path": "src/a.js", "from": null }],
|
|
196
|
+
"sensitivePaths": [],
|
|
197
|
+
"sensitiveTouchedCount": 0,
|
|
198
|
+
"sensitiveContentWithheld": true,
|
|
199
|
+
"patchWithheld": false,
|
|
200
|
+
"patchText": "diff --git a/src/a.js b/src/a.js\n…",
|
|
201
|
+
"patchTruncated": false,
|
|
202
|
+
"patchBytes": 412,
|
|
203
|
+
"capturedAt": 1792400000000
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
`files[].path` is always a string; `status` is one of `added`, `modified`,
|
|
208
|
+
`deleted`, `renamed`, `copied`, `conflicted`, `changed`. Sensitive paths appear in
|
|
209
|
+
`files` and in `sensitivePaths` by name — that is the point, an operator must know
|
|
210
|
+
a credential file was touched — but never in `patchText`.
|
|
211
|
+
|
|
212
|
+
`changes` is `[]` and `patchWithheld` is `true` when the sensitive bound was
|
|
213
|
+
exceeded; in that case no diff invocation was issued at all.
|
|
214
|
+
|
|
215
|
+
`captureDiff` is safe to call after a failed or cancelled run: the engine always
|
|
216
|
+
records whatever it can measure.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## 3.5 `preflightWorkspace(deps, request)` — the pre-admission check
|
|
221
|
+
|
|
222
|
+
`src/workspace/preflight.js`. This answers the question the engine used to answer
|
|
223
|
+
*by failing*: what is this workspace, and which isolation does it need? It runs
|
|
224
|
+
with no side effects — no commit, stash, branch, worktree, lock, task, grant or
|
|
225
|
+
settings write — and it is not authorization: it creates nothing, so it cannot
|
|
226
|
+
substitute for the switch or a grant.
|
|
227
|
+
|
|
228
|
+
```js
|
|
229
|
+
const decision = await preflightWorkspace({ runGit }, { workspacePath, allowShared });
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
`runGit` is the same argv runner the audit layer uses (`createGitRunner()` when
|
|
233
|
+
omitted), so a test can inject a refusal. `workspacePath` must be absolute and is
|
|
234
|
+
resolved with `realpath` exactly as `resolveWorkspacePath` does for the engine, so
|
|
235
|
+
a `worktree` recommendation can never be rejected later for naming an unusable
|
|
236
|
+
path.
|
|
237
|
+
|
|
238
|
+
Only these five invocations are ever issued, in this order, and the ordered list
|
|
239
|
+
is asserted by `tests/preflight.test.js`:
|
|
240
|
+
|
|
241
|
+
```
|
|
242
|
+
git --version
|
|
243
|
+
git rev-parse --is-inside-work-tree
|
|
244
|
+
git rev-parse --show-toplevel
|
|
245
|
+
git rev-parse --verify HEAD
|
|
246
|
+
git status --porcelain=v1 -z --untracked-files=all
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
`rev-parse --show-toplevel` is the root measurement: its output is compared
|
|
250
|
+
against the resolved workspace path (case-folded on Windows) to decide whether
|
|
251
|
+
the named path *is* the repository root or merely sits inside one. The status read
|
|
252
|
+
is not attempted at all for a path that fails that comparison.
|
|
253
|
+
|
|
254
|
+
### Answer
|
|
255
|
+
|
|
256
|
+
```json
|
|
257
|
+
{
|
|
258
|
+
"ok": true,
|
|
259
|
+
"readOnly": true,
|
|
260
|
+
"workspacePath": "<resolved path>",
|
|
261
|
+
"isolation": "worktree | shared | block",
|
|
262
|
+
"reason": "PREFLIGHT_…",
|
|
263
|
+
"sharedExplicit": false,
|
|
264
|
+
"decisionRequired": false,
|
|
265
|
+
"facts": {
|
|
266
|
+
"gitAvailable": true,
|
|
267
|
+
"repository": true,
|
|
268
|
+
"hasCommits": true,
|
|
269
|
+
"clean": false,
|
|
270
|
+
"head": "5d0f…",
|
|
271
|
+
"changedFiles": 3,
|
|
272
|
+
"changedPaths": ["src/a.js", "notes.txt", ".env"],
|
|
273
|
+
"changedPathsTruncated": false,
|
|
274
|
+
"sensitivePaths": [".env"]
|
|
275
|
+
},
|
|
276
|
+
"guidance": "one sentence naming the next action",
|
|
277
|
+
"checkedAt": 1792400000000
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Every branch returns exactly this key set, so a caller never has to guard a field.
|
|
282
|
+
`facts.clean` is `null` — **unknown**, not "clean" — whenever the state could not
|
|
283
|
+
be measured; `changedFiles` is the true status total and `changedPaths` is the
|
|
284
|
+
bounded list, with `changedPathsTruncated: true` when they differ. Paths are names
|
|
285
|
+
only: content is never read (`git diff` and `git show` are never invoked), and a
|
|
286
|
+
sensitive name appears in `sensitivePaths` by name alone.
|
|
287
|
+
|
|
288
|
+
### Decision table
|
|
289
|
+
|
|
290
|
+
| Facts | `isolation` | `reason` | flags |
|
|
291
|
+
|---|---|---|---|
|
|
292
|
+
| not a directory / relative / unresolvable path | `block` | `PREFLIGHT_WORKSPACE_INVALID` or `PREFLIGHT_NOT_A_DIRECTORY` | — |
|
|
293
|
+
| git cannot be executed | `block` | `PREFLIGHT_GIT_UNAVAILABLE` | — |
|
|
294
|
+
| not inside a git work tree | `block` | `PREFLIGHT_NOT_A_REPOSITORY` | — |
|
|
295
|
+
| inside a repository but not its root (a subdirectory) | `block` | `PREFLIGHT_NOT_A_REPOSITORY_ROOT` | — |
|
|
296
|
+
| repository with no commit | `block` | `PREFLIGHT_NO_COMMITS` | — |
|
|
297
|
+
| a read-only git read failed | `block` | `PREFLIGHT_GIT_FAILED` | — |
|
|
298
|
+
| clean repository root | `worktree` | `PREFLIGHT_CLEAN_REPOSITORY` | — |
|
|
299
|
+
| dirty, `allowShared` not passed | `block` | `PREFLIGHT_DIRTY_NEEDS_DECISION` | `decisionRequired: true` |
|
|
300
|
+
| dirty, `allowShared: true` | `shared` | `PREFLIGHT_DIRTY_SHARED_EXPLICIT` | `sharedExplicit: true` |
|
|
301
|
+
|
|
302
|
+
**There is no automatic downgrade.** A dirty checkout is exactly the state in which
|
|
303
|
+
`WorktreeManager.prepare` refuses with `WORKTREE_SOURCE_DIRTY` (§3.6), which is why
|
|
304
|
+
the same condition is measured here — but the remedy is a decision, not a default.
|
|
305
|
+
`allowShared` is a per-call request, never a stored setting: the plugin does not
|
|
306
|
+
record that shared isolation is "fine" and cannot be made to prefer it silently.
|
|
307
|
+
|
|
308
|
+
**A subdirectory is not a workspace.** It has its own reason
|
|
309
|
+
(`PREFLIGHT_NOT_A_REPOSITORY_ROOT`) because the honest remedy is different:
|
|
310
|
+
`allowShared` decides *where* a dirty run executes and is not permission to treat a
|
|
311
|
+
subdirectory as a workspace, so the refusal is decided before status is read and
|
|
312
|
+
holds with or without `allowShared`. `facts.repository` is `true` for such a path
|
|
313
|
+
(it really is inside a repository) while `facts.clean` stays `null` (unmeasured),
|
|
314
|
+
and `guidance` names the measured repository root — it never suggests `worktree`
|
|
315
|
+
or `shared`, because neither is safe for a path that is not the root.
|
|
316
|
+
|
|
317
|
+
### Surfaces
|
|
318
|
+
|
|
319
|
+
| Surface | Shape |
|
|
320
|
+
|---|---|
|
|
321
|
+
| MCP tool | `delegate_preflight { workspacePath, allowShared? }`, `additionalProperties: false`; `allowShared` must be a real boolean |
|
|
322
|
+
| execution plane | `POST /dsh-delegate/x/workspace/preflight` → `200` with the decision, `400 WORKSPACE_PATH_REQUIRED` for a missing path |
|
|
323
|
+
|
|
324
|
+
The route is behind the same transport fence and connection identity as every other
|
|
325
|
+
execution-plane route, but it is deliberately **not** gated on the switch or on the
|
|
326
|
+
concurrency cap: it authorizes nothing and consumes nothing, so it stays answerable
|
|
327
|
+
while delegation is off (that is when a coordinator decides whether a dispatch is
|
|
328
|
+
worthwhile) and while every slot is busy. It is the only execution-plane route
|
|
329
|
+
besides `/status` and `/tasks` reads that answers with the switch off.
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
## 3.6 `WorktreeManager`
|
|
334
|
+
|
|
335
|
+
```js
|
|
336
|
+
const manager = new WorktreeManager({ runGit }, { rootDir });
|
|
337
|
+
const prepared = await manager.prepare({ taskId, sourcePath, signal });
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
`rootDir` must be absolute. It is created once (`mode: 0o700`) and resolved with
|
|
341
|
+
`realpath`, and every containment check compares real paths.
|
|
342
|
+
|
|
343
|
+
### `prepare({ taskId, sourcePath, signal })`
|
|
344
|
+
|
|
345
|
+
Returns:
|
|
346
|
+
|
|
347
|
+
```json
|
|
348
|
+
{
|
|
349
|
+
"taskId": "task-…",
|
|
350
|
+
"workspacePath": "<rootDir>/<safe-task-id>-<suffix>",
|
|
351
|
+
"sourcePath": "<real path of the source repository>",
|
|
352
|
+
"baseHead": "5d0f…",
|
|
353
|
+
"isolated": true,
|
|
354
|
+
"detached": true,
|
|
355
|
+
"state": "active",
|
|
356
|
+
"createdAt": 1792400000000,
|
|
357
|
+
"completedAt": null,
|
|
358
|
+
"sourcePreexistingChanges": 0,
|
|
359
|
+
"disposable": true
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Steps, in order — each can refuse:
|
|
364
|
+
|
|
365
|
+
1. validate `taskId`, `sourcePath`, signal;
|
|
366
|
+
2. resolve `sourcePath` with `realpath`;
|
|
367
|
+
3. measure the repository top level with `git rev-parse --show-toplevel` and
|
|
368
|
+
resolve it with `realpath`; an unmeasurable top level is
|
|
369
|
+
`WORKTREE_NOT_A_REPOSITORY`;
|
|
370
|
+
4. refuse if `rootDir` (declared or resolved) is anywhere inside that
|
|
371
|
+
**repository root** — not merely inside `sourcePath`;
|
|
372
|
+
5. probe the source: git available, a work tree, at least one commit → pin `head`;
|
|
373
|
+
6. require a clean source (`git status -z` reports nothing);
|
|
374
|
+
7. claim a unique destination under the root and refuse if it exists, or if it
|
|
375
|
+
falls inside the repository root;
|
|
376
|
+
8. `git worktree add --detach <path> <pinned-head>`;
|
|
377
|
+
9. verify `rev-parse --verify HEAD` in the new tree equals the pinned commit;
|
|
378
|
+
10. refuse if the signal aborted at any point.
|
|
379
|
+
|
|
380
|
+
Step 4 is the containment decision, and it is deliberately made against the
|
|
381
|
+
measured top level rather than against the supplied path. When `sourcePath` is a
|
|
382
|
+
subdirectory of its repository, a `rootDir` located elsewhere in that same
|
|
383
|
+
repository is outside `sourcePath` but still inside the user's checkout; only the
|
|
384
|
+
top level catches it. Step 7 repeats the check on the final destination.
|
|
385
|
+
|
|
386
|
+
A refusal at steps 1–7 touches nothing: the top-level read is read-only and
|
|
387
|
+
`rootDir` is not created until the containment check has passed. A refusal at
|
|
388
|
+
step 9 or a cancellation at step 10 removes the tree it just made
|
|
389
|
+
(`git worktree remove --force` + `prune`) and drops the registry entry, because
|
|
390
|
+
the caller never received the path — no unreviewed work can exist there.
|
|
391
|
+
|
|
392
|
+
**Why a clean source is required.** A worktree is built from a commit. If the
|
|
393
|
+
source has uncommitted edits, those edits are simply absent from the tree, and
|
|
394
|
+
the run fails for a reason nobody can see. The refusal says how many changes were
|
|
395
|
+
found and names them (bounded), never what they contain.
|
|
396
|
+
|
|
397
|
+
**Why `--detach`.** The tree is bound to a commit, not a branch. Nothing the run
|
|
398
|
+
does can move a ref in the user's repository, and no branch is checked out twice.
|
|
399
|
+
|
|
400
|
+
**Refusal codes**
|
|
401
|
+
|
|
402
|
+
| Code | Meaning |
|
|
403
|
+
|---|---|
|
|
404
|
+
| `WORKTREE_GIT_UNAVAILABLE` | git cannot be executed here |
|
|
405
|
+
| `WORKTREE_NOT_A_REPOSITORY` | the source is not inside a git work tree, or its top level cannot be measured |
|
|
406
|
+
| `WORKTREE_NO_COMMITS` | the source has no commit; commit first |
|
|
407
|
+
| `WORKTREE_SOURCE_DIRTY` | the source has uncommitted changes (`details.changes`, `details.paths`) |
|
|
408
|
+
| `WORKTREE_ROOT_INVALID` | `rootDir` is not absolute, or `sourcePath` is not absolute |
|
|
409
|
+
| `WORKTREE_PATH_ESCAPE` | the generated destination left the root |
|
|
410
|
+
| `WORKTREE_NESTED_DESTINATION` | `rootDir` or the destination is inside the **repository root** (`details.sourcePath`, `details.repositoryRoot`) |
|
|
411
|
+
| `WORKTREE_DESTINATION_EXISTS` | the chosen path already exists |
|
|
412
|
+
| `WORKTREE_CANCELLED` | the signal was aborted (`details.phase`: `before-probe`, `before-create`, `after-create`) |
|
|
413
|
+
| `WORKTREE_GIT_FAILED` | a git invocation failed (`details.step`, `details.exitCode`, bounded `stderr`) |
|
|
414
|
+
| `WORKTREE_TASK_ID_INVALID` | no usable task id |
|
|
415
|
+
| `WORKTREE_UNKNOWN_TREE` | not a tree this manager owns |
|
|
416
|
+
| `WORKTREE_NOT_REVIEWED` | refusing to delete a tree that is still active |
|
|
417
|
+
|
|
418
|
+
Cancellation is checked before the probe, before creation and again after
|
|
419
|
+
verification. A caller that receives `WORKTREE_CANCELLED` must not start a run;
|
|
420
|
+
there is no path where a cancelled request yields a usable workspace.
|
|
421
|
+
|
|
422
|
+
### `markComplete(workspacePath)`
|
|
423
|
+
|
|
424
|
+
Moves a tree to `awaiting-host-review` and stamps `completedAt`. It is **not**
|
|
425
|
+
approval: host acceptance is a separate, host-owned action, exactly as for a task.
|
|
426
|
+
|
|
427
|
+
### `list(filter)` / `get(workspacePath)`
|
|
428
|
+
|
|
429
|
+
Metadata only. The returned object has exactly these keys: `taskId`,
|
|
430
|
+
`workspacePath`, `sourcePath`, `baseHead`, `isolated`, `detached`, `state`,
|
|
431
|
+
`createdAt`, `completedAt`, `sourcePreexistingChanges`, `disposable`. No file
|
|
432
|
+
content, no diff, no error text. `filter` accepts `taskId` and `state`. Newest
|
|
433
|
+
first.
|
|
434
|
+
|
|
435
|
+
### `dispose(workspacePath, { reviewed })`
|
|
436
|
+
|
|
437
|
+
Removes one tree with `git worktree remove --force` + `prune`, then marks the
|
|
438
|
+
record `disposed`.
|
|
439
|
+
|
|
440
|
+
- A tree in `awaiting-host-review` may be disposed (the host looked at it).
|
|
441
|
+
- A tree still `active` is refused with `WORKTREE_NOT_REVIEWED` unless the caller
|
|
442
|
+
passes `reviewed: true`. Deleting a tree a run may still be using would destroy
|
|
443
|
+
the only evidence of what the run changed.
|
|
444
|
+
- An unmanaged path is refused with `WORKTREE_UNKNOWN_TREE`; the manager never
|
|
445
|
+
deletes a directory it did not create.
|
|
446
|
+
- Removing an already-disposed tree is refused, so a double dispose cannot look
|
|
447
|
+
like success.
|
|
448
|
+
|
|
449
|
+
**Trees are kept after a run.** Nothing in this module deletes a tree on a timer,
|
|
450
|
+
at startup, or when a task ends. A forgotten tree is still on disk and still
|
|
451
|
+
reviewable; a silently deleted one is lost evidence. The registry is in memory
|
|
452
|
+
only, so a restart forgets metadata and leaves the trees — that is stated here so
|
|
453
|
+
nobody mistakes `list()` being empty for the trees being gone.
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
## 5. Engine integration contract
|
|
458
|
+
|
|
459
|
+
The engine (`src/jobs/engine.js`) is not modified by this document; these are the
|
|
460
|
+
call shapes it should use, and the properties it can rely on.
|
|
461
|
+
|
|
462
|
+
### 5.1 Isolation is chosen before anything else happens
|
|
463
|
+
|
|
464
|
+
```js
|
|
465
|
+
if (effective.worker.isolation === 'worktree') {
|
|
466
|
+
const manager = new WorktreeManager({ runGit: this.deps.runGit }, { rootDir: worktreeRoot(dataDir) });
|
|
467
|
+
const prepared = await manager.prepare({ taskId, sourcePath: resolvedWorkspacePath, signal: task.controller.signal });
|
|
468
|
+
}
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
- `taskId` must be generated *before* `prepare` (the manager uses it in the path).
|
|
472
|
+
- `sourcePath` must already be resolved with `realpath` (`resolveWorkspacePath`).
|
|
473
|
+
- The workspace the agent runs in is `prepared.workspacePath`; the workspace the
|
|
474
|
+
lock is keyed on and the baseline is captured in must be the **same** value.
|
|
475
|
+
- A refusal here is `JOB_ISOLATION_REFUSED` with `details.cause` set to the
|
|
476
|
+
`WORKTREE_*` code. It must not fall back to `shared`: silently downgrading
|
|
477
|
+
isolation executes a job with weaker isolation than the operator asked for.
|
|
478
|
+
|
|
479
|
+
### 5.2 Ordering with authorization and concurrency
|
|
480
|
+
|
|
481
|
+
Authorization is consumed before a worktree exists (one grant, one attempt). The
|
|
482
|
+
concurrency cap and the workspace lock are checked against the **source** path's
|
|
483
|
+
job slot before `prepare`, because creating a worktree is a side effect on disk.
|
|
484
|
+
Two jobs that request worktree isolation in the same source repository are
|
|
485
|
+
independent trees, but they still mutate the same git repository's administrative
|
|
486
|
+
area, so the source-path lock may be held for the duration of a run; that is a
|
|
487
|
+
policy decision for the engine, and it is the engine's to make explicitly.
|
|
488
|
+
|
|
489
|
+
### 5.3 Baseline and diff
|
|
490
|
+
|
|
491
|
+
Inside the tree, `captureBaseline` and `captureDiff` work unchanged: the tree is a
|
|
492
|
+
normal git work tree at a detached commit. `baseline.head` will equal
|
|
493
|
+
`prepared.baseHead` unless the run commits, and a run that commits is precisely
|
|
494
|
+
what the pinned comparison point protects against.
|
|
495
|
+
|
|
496
|
+
### 5.4 Cancellation
|
|
497
|
+
|
|
498
|
+
Pass `task.controller.signal` into `prepare`. A rejection with
|
|
499
|
+
`WORKTREE_CANCELLED` means no run may start. Do not catch it and continue to
|
|
500
|
+
`runAgent`.
|
|
501
|
+
|
|
502
|
+
### 5.5 Completion and disposal
|
|
503
|
+
|
|
504
|
+
When a run terminates, call `manager.markComplete(prepared.workspacePath)` and
|
|
505
|
+
record the metadata on the task view. Do **not** dispose. The host reviews the
|
|
506
|
+
tree (through the diff evidence, or directly) and only then calls
|
|
507
|
+
`dispose(workspacePath, { reviewed: true })`.
|
|
508
|
+
|
|
509
|
+
`manager.dispose()` on plugin shutdown must not remove trees; at most it should
|
|
510
|
+
stop tracking them, leaving the directories for the host. This module offers no
|
|
511
|
+
shutdown-time deletion, by design.
|
|
512
|
+
|
|
513
|
+
### 5.6 What the engine must not do
|
|
514
|
+
|
|
515
|
+
- Do not pass a caller-supplied path as `rootDir` or as the destination.
|
|
516
|
+
- Do not treat `isolated: true` as a security boundary statement — it means "the
|
|
517
|
+
agent's cwd is a different checkout". Same OS account, same filesystem.
|
|
518
|
+
- Do not reuse a disposed tree, and do not re-enter `prepare` with a task id that
|
|
519
|
+
already has a live tree; the manager will create a second tree, which is
|
|
520
|
+
correct behaviour for a retry but must be a deliberate engine decision.
|
|
521
|
+
|
|
522
|
+
---
|
|
523
|
+
|
|
524
|
+
## 6. Known limits
|
|
525
|
+
|
|
526
|
+
1. **Not a sandbox.** Worktree isolation keeps the human's working tree clean. It
|
|
527
|
+
does not confine a hostile process; an agent with the same OS account can write
|
|
528
|
+
anywhere that account can.
|
|
529
|
+
2. **In-process registry.** A second DSH process, or a restart, sees no trees. The
|
|
530
|
+
directories remain on disk.
|
|
531
|
+
3. **Crash orphans.** A plugin crash between `worktree add` and the registry write
|
|
532
|
+
can leave a directory under the root with no record. It is inert and
|
|
533
|
+
reviewable; nothing here deletes it automatically.
|
|
534
|
+
4. **Sensitivity is name-based.** A secret inside a file with an ordinary name is
|
|
535
|
+
caught only by the `redactText` safety net, not by exclusion.
|
|
536
|
+
5. **Renames are detected by git's own similarity heuristic.** A move that git
|
|
537
|
+
reports as delete+add yields two records; both sides are still inspected for
|
|
538
|
+
sensitivity, so the outcome is the same.
|
package/icon.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128"><rect width="128" height="128" rx="28" fill="#14253b"/><path d="M30 43h58m-14-14 14 14-14 14M98 85H40m14-14L40 85l14 14" fill="none" stroke="#6dd6c5" stroke-width="10" stroke-linecap="round" stroke-linejoin="round"/><circle cx="29" cy="85" r="6" fill="#b9cfff"/><circle cx="99" cy="43" r="6" fill="#b9cfff"/></svg>
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Type declarations for the dsh-delegate browser half (`lib/client.js`).
|
|
2
|
+
//
|
|
3
|
+
// `lib/client.js` is not an ordinary ES module: it is a *registration* for the DSH
|
|
4
|
+
// client's module table, produced by `scripts/build-client.mjs` from
|
|
5
|
+
// `src/client/index.jsx`:
|
|
6
|
+
//
|
|
7
|
+
// window.__ModuleLoader__.load({ id: "dsh-taskbridge", factory: (require) => … })
|
|
8
|
+
//
|
|
9
|
+
// The factory returns `module.exports`, whose shape is declared here as
|
|
10
|
+
// {@link DelegateClientModule}. The bundle declares `dsh.client.platform: "web"`,
|
|
11
|
+
// which is the only platform `dsh-client-modules` in 0.2.x selects; Desktop and
|
|
12
|
+
// Web both run that client module system, so the same declaration serves both.
|
|
13
|
+
// Its module requests are limited to the platform table (`react`,
|
|
14
|
+
// `react/jsx-runtime`) — that is why no `dsh.client.external` entry is needed.
|
|
15
|
+
// Ordering against the Plugins manager comes from `dsh.client.inject`, whose row
|
|
16
|
+
// for this package must name `@deepseek-ai/dsh-client-ui-plugin-manager`.
|
|
17
|
+
//
|
|
18
|
+
// This file documents the contract for editors and type-aware tests; nothing
|
|
19
|
+
// imports it at runtime.
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The slot this page occupies: the Plugins manager's per-bundle configuration
|
|
23
|
+
* slot (`kind: 'keyed'`, `scope: 'root'`), rendered only with `view: 'page'` on
|
|
24
|
+
* the bundle's own details page.
|
|
25
|
+
*/
|
|
26
|
+
export declare const PLUGIN_CONFIG_SLOT: 'plugins.bundle.config';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Key of the registration: exactly the bundle's npm package name. The manager
|
|
30
|
+
* looks the entry up by `pkg.name`; any other key never renders.
|
|
31
|
+
*/
|
|
32
|
+
export declare const PLUGIN_BUNDLE_KEY: 'dsh-taskbridge';
|
|
33
|
+
|
|
34
|
+
/** Required client services: slot registration only. */
|
|
35
|
+
export declare const inject: readonly ['slots'];
|
|
36
|
+
|
|
37
|
+
/** Options accepted by {@link registerBundleConfiguration}. */
|
|
38
|
+
export interface DelegateBundleConfigOptions {
|
|
39
|
+
/** Page store; the component subscribes to it itself. */
|
|
40
|
+
store: unknown;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Register the bundle configuration page on a client context.
|
|
45
|
+
* @param ctx - client context exposing `slots`.
|
|
46
|
+
* @param options - the page store.
|
|
47
|
+
* @returns the slot disposer.
|
|
48
|
+
*/
|
|
49
|
+
export declare function registerBundleConfiguration(
|
|
50
|
+
ctx: unknown,
|
|
51
|
+
options: DelegateBundleConfigOptions,
|
|
52
|
+
): () => void;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Client plugin apply hook: injects the scoped stylesheet and registers one
|
|
56
|
+
* `plugins.bundle.config` entry, and nothing else. It never registers a
|
|
57
|
+
* `settings.section`, and it never dispatches a task.
|
|
58
|
+
* @param ctx - client Cordis context.
|
|
59
|
+
*/
|
|
60
|
+
export declare function apply(ctx: unknown): void;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* React component that renders the whole configuration page. It receives the
|
|
64
|
+
* registration's `inject` face (`{ store }`) plus the slot owner props
|
|
65
|
+
* (`{ view: 'page', form? }`), and deliberately ignores `form`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function DelegateConfigPage(props: Record<string, unknown>): unknown;
|
|
68
|
+
|
|
69
|
+
/** Re-exported client helpers that the page and the tests both use. */
|
|
70
|
+
export declare const documentFromDraft: (...args: unknown[]) => unknown;
|
|
71
|
+
export declare const describeError: (...args: unknown[]) => string;
|
|
72
|
+
export declare const exportDocument: (...args: unknown[]) => unknown;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Actions the Codex panel may send. `status` is absent on purpose: the page reads
|
|
76
|
+
* that state through a `GET`, so only a real change is ever a `POST`.
|
|
77
|
+
*/
|
|
78
|
+
export declare const CODEX_ACTIONS: readonly ['install', 'repair', 'remove'];
|
|
79
|
+
|
|
80
|
+
/** The user-plane path the Codex panel uses (`GET` diagnoses, `POST` acts). */
|
|
81
|
+
export declare const ROUTES: Readonly<Record<string, string>> & { codex: '/api/dsh-delegate/codex' };
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* One target's presentation state: agent file, MCP entry or DSH switch.
|
|
85
|
+
*
|
|
86
|
+
* The three are reported separately because they are independent: an installed
|
|
87
|
+
* agent does not imply a configured MCP entry, and neither implies that the DSH
|
|
88
|
+
* local-call switch is on.
|
|
89
|
+
*/
|
|
90
|
+
export interface DelegateCodexTargetView {
|
|
91
|
+
key: 'agent' | 'mcp' | 'switch';
|
|
92
|
+
label: string;
|
|
93
|
+
state: string;
|
|
94
|
+
tone: 'on' | 'off' | 'warn';
|
|
95
|
+
detail: string;
|
|
96
|
+
path?: string;
|
|
97
|
+
paths?: string[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Map a served Codex status document onto one target's presentation state. */
|
|
101
|
+
export declare function codexTargetView(
|
|
102
|
+
codex: unknown,
|
|
103
|
+
switchState: unknown,
|
|
104
|
+
target: 'agent' | 'mcp' | 'switch',
|
|
105
|
+
): DelegateCodexTargetView;
|
|
106
|
+
|
|
107
|
+
/** Chinese one-line summary of an action outcome (`changed` / `refused`). */
|
|
108
|
+
export declare function describeCodexOutcome(outcome: unknown): string;
|
|
109
|
+
|
|
110
|
+
/** Shape the registration factory returns as `module.exports`. */
|
|
111
|
+
export interface DelegateClientModule {
|
|
112
|
+
PLUGIN_CONFIG_SLOT: typeof PLUGIN_CONFIG_SLOT;
|
|
113
|
+
PLUGIN_BUNDLE_KEY: typeof PLUGIN_BUNDLE_KEY;
|
|
114
|
+
inject: typeof inject;
|
|
115
|
+
registerBundleConfiguration: typeof registerBundleConfiguration;
|
|
116
|
+
apply: typeof apply;
|
|
117
|
+
DelegateConfigPage: typeof DelegateConfigPage;
|
|
118
|
+
}
|