@starsharryzhu/complete-subagent 0.0.0-stage → 0.1.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.
Files changed (68) hide show
  1. package/AGENTS.md +58 -0
  2. package/LICENSE +21 -0
  3. package/README.md +168 -2
  4. package/cordis.patch.yml +11 -0
  5. package/lib/client.js +439 -0
  6. package/lib/client.modules.txt +8 -0
  7. package/lib/host/access.d.ts +46 -0
  8. package/lib/host/access.js +54 -0
  9. package/lib/host/call-scope.d.ts +21 -0
  10. package/lib/host/call-scope.js +26 -0
  11. package/lib/host/delegate.d.ts +47 -0
  12. package/lib/host/delegate.js +133 -0
  13. package/lib/host/grants.d.ts +51 -0
  14. package/lib/host/grants.js +62 -0
  15. package/lib/host/legacy.d.ts +57 -0
  16. package/lib/host/legacy.js +85 -0
  17. package/lib/host/models.d.ts +59 -0
  18. package/lib/host/models.js +139 -0
  19. package/lib/host/paths.d.ts +51 -0
  20. package/lib/host/paths.js +100 -0
  21. package/lib/host/policy.d.ts +72 -0
  22. package/lib/host/policy.js +169 -0
  23. package/lib/host/prompt.d.ts +41 -0
  24. package/lib/host/prompt.js +100 -0
  25. package/lib/host/requests.d.ts +82 -0
  26. package/lib/host/requests.js +109 -0
  27. package/lib/host/scope.d.ts +33 -0
  28. package/lib/host/scope.js +46 -0
  29. package/lib/host/store.d.ts +89 -0
  30. package/lib/host/store.js +128 -0
  31. package/lib/host/tools.d.ts +58 -0
  32. package/lib/host/tools.js +298 -0
  33. package/lib/host/types.d.ts +184 -0
  34. package/lib/host/types.js +26 -0
  35. package/lib/index.d.ts +55 -0
  36. package/lib/index.js +245 -0
  37. package/lib/shared/settings.d.ts +69 -0
  38. package/lib/shared/settings.js +86 -0
  39. package/locale/AGENTS.md +22 -0
  40. package/locale/en.json +6 -0
  41. package/locale/zh.json +6 -0
  42. package/package.json +95 -4
  43. package/src/AGENTS.md +26 -0
  44. package/src/client/AGENTS.md +28 -0
  45. package/src/client/css.d.ts +5 -0
  46. package/src/client/host.ts +82 -0
  47. package/src/client/index.ts +81 -0
  48. package/src/client/locales.ts +61 -0
  49. package/src/client/settings.tsx +222 -0
  50. package/src/client/styles.css +44 -0
  51. package/src/host/AGENTS.md +53 -0
  52. package/src/host/access.ts +82 -0
  53. package/src/host/call-scope.ts +31 -0
  54. package/src/host/delegate.ts +166 -0
  55. package/src/host/grants.ts +82 -0
  56. package/src/host/legacy.ts +86 -0
  57. package/src/host/models.ts +155 -0
  58. package/src/host/paths.ts +100 -0
  59. package/src/host/policy.ts +169 -0
  60. package/src/host/prompt.ts +113 -0
  61. package/src/host/requests.ts +149 -0
  62. package/src/host/scope.ts +54 -0
  63. package/src/host/store.ts +159 -0
  64. package/src/host/tools.ts +318 -0
  65. package/src/host/types.ts +192 -0
  66. package/src/index.ts +316 -0
  67. package/src/shared/AGENTS.md +20 -0
  68. package/src/shared/settings.ts +104 -0
package/AGENTS.md ADDED
@@ -0,0 +1,58 @@
1
+ # AGENTS.md
2
+
3
+ ## 1. Role
4
+
5
+ complete-subagent is a DeepSeek Harness plugin with its own delegation tools beside the official ones: `delegate` starts a fresh child and `delegate_fork` a child that inherits the conversation. The `cwd` a parent passes becomes the child's sub-workspace and `writable_paths` grants more up front; the child may modify files only there (plus temporary directories). To modify anything else it calls `request_write_access` and is paused until the parent answers with `answer_write_request`; the parent can also grant or revoke at any time with `grant_write_access` and `revoke_write_access`. A parent may choose the child's model and reasoning effort among the models the user lists on the plugin's settings page. Children run on the host's own subagent runtime, so messaging, the child conversations in the UI, result notices, and cold resume behave as for the official tools, which stay installed and untouched. Access is enforced by narrowing the sandbox policy the host already applies to bash, file tools, terminals, and code mode, and anything a confined agent starts by other means is confined the same way. The `presets` setting limits the tools and prompt texts to the agents of the listed agent presets: empty (the default) serves every preset. The `childPreset` setting names the agent preset `delegate` children run instead of their parent's. The `ownModel` setting, on by default, can keep `delegate` children off the parent's own model, and a bundle can set the model list at run time through the `completeSubagent` service. The `dsh-assisstant` bundle mounts the plugin as a sub-plugin with `presets: [dsh-assisstant, dsh-assisstant-worker]` and `childPreset: dsh-assisstant-worker`: the assistant's router sessions delegate and approve, and their workers do the work. The plugin supports hosts from 0.2.1-rc.5 up to 0.3 and reads what each host offers: `src/host/legacy.ts` holds what differs on a host older than 0.2.2-alpha.2, and a start carries its task in both shapes, the one hosts before 0.2.2-rc.2 read and the one later hosts read.
6
+
7
+ ## 2. Constraints
8
+
9
+ - Never modify the harness checkout, the official subagent packages, or a preset: the plugin is one top-level bundle row that works in every preset.
10
+ - With `presets` empty the plugin behaves exactly as without the setting. With presets listed, an agent whose session does not run one of them (as `agentPresets.presetForSession` reports, or on 0.2.1-rc.5 the `agentPreset` session projection, including none recorded) sees no tool and no prompt text, and neither it nor its children get a binding; the fence itself is not scoped and keeps enforcing every binding that exists.
11
+ - With `childPreset` empty (the default) a child keeps its parent's preset, as without the setting. Set, it goes with every `delegate` start as `agentPreset`; `delegate_fork` never selects a preset, because the fork backend inherits the parent's context and the host refuses a preset there. A child is served by its own preset, so a bundle that lists `presets` lists `childPreset` there too.
12
+ - With `ownModel` on (the default) nothing changes. Off, with models listed, a `delegate` child runs only listed models: an omitted model is the first one, an effort-only call sets that model's effort, the parent's own model cannot be chosen unless it is listed, and an omitted effort never comes from the parent. An empty list leaves the usual rules. `delegate_fork` never follows the setting, though it offers the same list.
13
+ - `ctx.completeSubagent.setChildModels` replaces the `models` setting in memory until the row reloads, and rebuilds the delegation tools. It does nothing on a copy without `childPreset`, because that is a standalone install whose list belongs to the user's normal sessions.
14
+ - The settings page never shows `presets`, `childPreset`, or `ownModel`: a bundle that mounts the plugin sets them in its patch.
15
+ - Never register a tool named `subagent` or `subagent_fork`, and never change the official definitions: the official tools stay exactly as the host ships them.
16
+ - Host runtime imports are limited to `@deepseek-ai/cordis`, `@deepseek-ai/schemastery`, `@deepseek-ai/dsh-tools`, and Node built-ins; the browser half uses only the page's `react` and `react/jsx-runtime`. Other host types are structural mirrors.
17
+ - The only host behavior changed is `ctx.sandboxPolicy.resolve`, wrapped on its prototype while the plugin is loaded and restored on dispose; without that method the plugin logs a warning and stays disabled.
18
+ - Fail closed: a child is bound before it starts, a failed start drops its binding, and an uncertain inherited chain leaves no access.
19
+ - A plugin failure must not reach the host: event listeners, visibility checks, and prompt texts run for every session of every preset, so they log a warning and fall back instead of throwing. `tools/execute` passes through only what `next` throws, which is the host's own pipeline.
20
+ - A host older than 0.2.2-alpha.2 silently drops `when` and ignores `additionalWritableRoots`. The plugin must keep working there: the same visibility conditions become per-agent `tools.restrict` filters, and a granted `write` or `edit` call is rooted at its grant. Newer hosts are detected by `ctx.tools.resolve`, which arrived with `when`, and never get the filters.
21
+ - A start (`subagents.startActivation`) carries its task twice: at the top level of the spec, where hosts from 0.2.2-rc.2 read it, and under `request`, where older hosts read it. Each host ignores the other copy, so no host version is detected; drop neither while both generations are in `engines.dsh`.
22
+ - Package identity: `@starsharryzhu/complete-subagent` version `0.1.1`, `engines.dsh` `>=0.2.1-rc.5 <0.3.0-0`; `tests/manifest.test.ts` pins them.
23
+ - `lib/` is generated by `node build.js` and committed, because `link:` and git installs do not build.
24
+ - Every folder carries this four-section English file; `tests/agents-md.test.ts` enforces it.
25
+
26
+ ## 3. Contents
27
+
28
+ - `src` — plugin source: the host entry, the host modules, the settings page, and the shared settings shape.
29
+ - `tests` — vitest specs with fake host services, the built settings page under jsdom, and the documentation check.
30
+ - `scripts` — the development toolchain linker.
31
+ - `locale` — Plugins page title and description in English and Chinese.
32
+ - `lib` — generated build output (committed).
33
+ - `build.js` — type-check, emit the host half, bundle and self-check the browser half.
34
+ - `cordis.patch.yml` — the bundle patch: one top-level row with default settings.
35
+ - `package.json` — identity, peers, engine range, `dsh.bundle.patch`, and the browser half.
36
+ - `tsconfig.json` — host type-check settings.
37
+ - `tsconfig.build.json` — host emit settings for `lib/`.
38
+ - `tsconfig.client.json` — browser half compile settings.
39
+ - `vitest.config.ts` — test runner settings.
40
+ - `README.md` — user documentation in Chinese.
41
+ - `.gitignore` — ignores dependencies, browser compile output, and local notes, keeps `lib/`.
42
+ - `.github/workflows/publish.yml` — tag-triggered npm publish with OIDC provenance.
43
+
44
+ ## 4. Progress
45
+
46
+ - Done (2026-11-01): standalone `delegate` / `delegate_fork` on the host's `spawn` and `fork` backends with sub-workspaces, `writable_paths`, reserved child ids bound before start, model and reasoning-effort choice limited by the settings, a settings page on the Plugins screen, inherited confinement for children a confined agent starts by other means, and the four write-access tools; all specs pass.
47
+ - Done (2026-11-01): the `presets` setting, so `dsh-assisstant` can mount the plugin for its hidden presets only, and the `childPreset` setting for its two-layer router and worker design; version `0.1.0` is published on npm.
48
+ - Done (2026-11-05): the package source is at StarsHarryZhu/complete-subagent with a tag-triggered publish workflow; its npm trusted publisher is configured and pending validation, which the next version tag will complete.
49
+ - Done (2026-11-02): support for DSH Desktop 0.2.1-rc.5, which has neither `presetForSession` nor `when` nor `additionalWritableRoots`, and no plugin failure reaches the host. The built plugin passed a throwaway check on the real rc.5 tool, prompt, projection, and sandbox-policy services, with small stand-ins for the agents, the subagent start, and the working directory; the host's real subagent start and the web app are not exercised on rc.5.
50
+ - Done (2026-11-02): the `ownModel` setting and the `completeSubagent` service, so a bundle can offer only the worker models it picks. A throwaway check on real hosts, 0.2.1-rc.5 and the 0.2.2-alpha.2 checkout, with a mock model and two probe presets, read each child's first recorded request: it runs the chosen model and effort on both, through the host's real subagent start. A standalone row ignored the service on both. The `dsh-assisstant` bundle itself was not part of that check.
51
+ - Found (2026-11-16, on Desktop 0.2.2-rc.3 and in the user's real assistant): 0.1.0 could not start any child on hosts from 0.2.2-rc.2, which read `parent`, `prompt`, `cwd`, `agentPreset`, `agentOptions`, and `maxDepth` at the top level of the start spec, where 0.1.0 nested them under `request`; every `delegate` call failed with `Cannot read properties of undefined (reading 'id')` before a child existed.
52
+ - Fixed (2026-11-17): 0.1.1 sends the task in both shapes. Run on four real hosts installed from npm (0.2.1-rc.5, 0.2.2-rc.1, 0.2.2-rc.2, 0.2.2-rc.3) inside the `dsh-assisstant` bundle, with a mock model and a workspace outside the temporary directory: the router's `delegate` started a worker on the worker preset; the worker wrote inside its sub-workspace and was refused next to it; its `request_write_access` reached the router, whose `answer_write_request` allowed it; the worker then wrote the granted file and its report came back to the router. No host logged a warning or an error. A control run on 0.2.2-rc.3 with 0.1.0 in the same setup failed with exactly that error. Not exercised there: `delegate_fork`, shell commands, a standalone install, the settings page.
53
+ - Done (2026-11-17, user approved): 0.1.1 is installed in the user's Desktop profile from a local tarball, and the installed copy passed the same run on the packaged 0.2.2-rc.3 host in a fake-home copy of that plugin set. Not yet published; the real app with the real model has not been tried.
54
+ - Carried over from dsh-better-subagent and verified there in the web app (host 0.2.2-alpha.2, 2026-10-29 to 2026-11-01): the kernel-level fence for the write tool and bash, file and directory grants, denials with notes, read-only children without `cwd`, parallel children, grants after a restart and cold resume, a four-child team run, `writable_paths`, grant, and revoke.
55
+ - Open: the new tools, the model choice, the settings page, inherited confinement, and the `presets`, `childPreset`, and `ownModel` settings are not yet verified in the web app; the desktop app, which runs 0.2.1-rc.5, is not verified.
56
+ - Known limits on 0.2.1-rc.5: shell commands cannot reach any grant, only `write` and `edit` can, and the child context says so; a visibility change other than a new agent or a preset selection takes effect on the agent's next step, so a parent at the depth limit that gets a request sees `answer_write_request` one step late, and the request may time out as denied.
57
+ - Known limits: children started outside a confined agent by anything but `delegate` / `delegate_fork` (the official tools, workflows, other plugins' agents such as Mnemon's review agents) keep the official behavior; a single granted file is writable through the `write` and `edit` tools only, not shell commands; a request reaches a parent that is inside a long tool call only at its next step; the web UI draws the new tools' calls as generic tool cards; with `presets` listed, a child a confined agent starts in another preset stays confined but is not told so, and a binding stored while its session was served keeps its fence but loses its tools and texts, and its new children are not confined; two loaded copies of the plugin (a standalone row and a bundle's sub-plugin row) would register the same tool names.
58
+ - Goal later: nothing planned.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Starfield
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,169 @@
1
- # Temporary Holding Version
1
+ # complete-subagent(完全子代理)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ DeepSeek Harness 插件:一套**独立的子代理工具**,带**子工作区**、**向父代理申请权限**,以及**由父代理选择子代理的模型和推理强度**。
4
+
5
+ 官方子代理(`subagent` / `subagent_fork`)默认能改父代理整个项目里的任何文件,而且它的审批策略固定为「自动拒绝」,越权请求到不了父代理。本插件另外提供两个工具:
6
+
7
+ - `delegate`:派生一个全新的子代理,它看不到当前对话。
8
+ - `delegate_fork`:派生一个继承当前对话(已完成的轮次)的子代理。
9
+
10
+ 用这两个工具派出的子代理:
11
+
12
+ - 父代理传的 `cwd` 就是子代理的**子工作区**,不存在时自动创建。子代理只能在子工作区和临时目录(如 `/tmp`)里修改文件。
13
+ - `writable_paths`:派生时就预先授权子工作区以外的路径,省掉一次申请。
14
+ - 不传 `cwd`,或 `cwd` 在父代理自己能写的范围之外,子代理就**没有子工作区**:能读,不能改(`writable_paths` 照样生效)。
15
+ - 子代理要改别的地方,调用 `request_write_access`(写明路径和理由)后**暂停等待**。父代理收到一条 `[write-access request wr-…]` 消息,用 `answer_write_request` 允许(可以收窄路径)或拒绝。超时没人回复就按拒绝处理(默认 10 分钟,可在设置里改)。
16
+ - 父代理随时可以用 `grant_write_access` 主动加授权、用 `revoke_write_access` 收回授权,立即生效。
17
+ - `model` / `reasoning_effort`:父代理可以给子代理换模型、调推理强度,范围由设置页决定(见下文)。
18
+
19
+ 这些规则都写在工具说明和参数说明里,AI 一看工具就知道怎么用。
20
+
21
+ ## 和官方子代理的关系
22
+
23
+ 两套并存,互不修改:
24
+
25
+ - 官方的 `subagent` / `subagent_fork` 原样保留,用它们派出的子代理仍是官方行为,不受子工作区限制。
26
+ - 本插件的子代理跑在宿主自己的子代理运行时上(`spawn` / `fork` 两个后端),所以 `send_message`、`list_agents`、`interrupt_agent`、网页上点开子代理会话、完成通知、重启后恢复,都和官方子代理一样。用户设置的最大委派深度同样生效,到了深度上限这两个工具就不再出现。
27
+ - 一个**被限制的**子代理如果再用官方工具(或 workflow 等其他方式)派出下一级,下一级**继承它的限制**:只能改它能改的地方,而且不能再申请。所以官方工具不能拿来绕过子工作区。
28
+ - 网页上,这两个工具的调用显示为普通工具卡片,不是官方的「创建子智能体」卡片。
29
+
30
+ ## 设置:可选的子代理模型和推理强度
31
+
32
+ 在网页「插件」页打开本插件,就是设置页:
33
+
34
+ - **可选的子代理模型**:从模型列表里添加模型,每个模型下勾选允许的推理强度(都不勾就是全部)。
35
+ - 父代理只能从这个列表里给子代理选模型。父代理**自己的模型**总能用:不在列表里时可以选它支持的任何推理强度;在列表里就只能选勾选的那几档。
36
+ - 列表为空时,子代理只用父代理的模型,但父代理仍然可以调推理强度。
37
+ - 不传 `reasoning_effort` 时:用父代理的模型就沿用父代理当前的强度;换了模型就用该模型的默认强度,如果默认强度不在勾选范围内,就用勾选的第一档。
38
+ - **写入申请的等待时间(秒)**:最少 10 秒,默认 600 秒。
39
+ - 改完保存,AI 的下一步就生效,不用重启。
40
+
41
+ ## 只在指定 preset 里生效:`presets`
42
+
43
+ 插件还有两个配置项设置页上不显示,主要给**把本插件当子插件挂载的总包**在 patch 里写。第一个是 `presets`(字符串数组)。
44
+
45
+ - **默认 `[]`**:所有 preset 都生效。单独安装时就是这样,行为和没有这个配置项时完全一样。
46
+ - **非空**:只对这些 preset 的 agent 生效。agent 属于哪个 preset,按宿主记录的会话 preset 判断(`agentPresets.presetForSession`)。不在列表里的 agent(包括读不到 preset 的):
47
+ - 看不到 `delegate`、`delegate_fork`、`request_write_access`、`answer_write_request`、`grant_write_access`、`revoke_write_access` 这六个工具;
48
+ - 提示词里不注入本插件的说明;
49
+ - 它和它派出的子代理都不会产生绑定(不会被限制)。
50
+ - 列表里 preset 的 agent 用 `delegate` 派出的子代理继承父代理的 preset,所以照常可用。被限制的子代理用官方工具派出下一级时,即使下一级选了别的 preset,也照样继承限制,只是看不到本插件的工具和说明。
51
+
52
+ ## 指定子代理的 preset:`childPreset`
53
+
54
+ 另一个配置项 `childPreset`(字符串),同样不在设置页显示,由总包在 patch 里写。
55
+
56
+ - **默认空字符串**:不指定,子代理继承父代理的 preset,就是现在的行为。
57
+ - **非空**:`delegate` 派出的子代理跑在这个 preset 上(启动时在请求里带 `agentPreset`,和官方 `subagent` 工具的做法一样)。宿主只允许不继承父上下文的后端(`spawn`)指定 preset。
58
+ - `delegate_fork` 走 `fork` 后端,继承父代理的上下文,**永远不指定** preset,子代理照旧跟父代理同一个 preset。
59
+ - 子代理在不在服务范围内,按它自己的 preset 判断。所以配置了 `presets` 时,`childPreset` 也要写进 `presets`,否则子代理看不到 `request_write_access`,也收不到本插件的说明(它仍然受限制)。
60
+
61
+ ## 只用列表里的模型:`ownModel`
62
+
63
+ `ownModel`(布尔)同样不在设置页显示,由总包在 patch 里写。
64
+
65
+ - **默认 `true`**:就是上面说的规则,父代理自己的模型总能用。
66
+ - **`false`,且模型列表非空**:`delegate` 派出的子代理只能跑列表里的模型。
67
+ - 不传 `model`,用列表第一个,不再继承父代理的模型。
68
+ - 只传 `reasoning_effort`,强度作用在列表第一个模型上。
69
+ - 父代理自己的模型不在列表里就不能选,报错会列出可选项。
70
+ - 不传强度时不沿用父代理的强度,即使父代理跑的正是这个模型:用该模型的默认强度,默认强度不在勾选范围内就用勾选的第一档。
71
+ - 列表为空时规则不变,子代理继承父代理的模型。
72
+ - `delegate_fork` 不受这个配置影响:它继承父代理的对话,默认还是父代理的模型。它的 `model` 可选项和 `delegate` 用同一份列表。
73
+
74
+ ## 总包在运行时设置模型列表:`completeSubagent` 服务
75
+
76
+ 总包可以让用户在自己的设置页选模型,再把列表交给本插件:
77
+
78
+ ```ts
79
+ ctx.inject(['completeSubagent'], (child) => {
80
+ child.completeSubagent.setChildModels([
81
+ { provider: 'deepseek', model: 'model-a', reasoningEfforts: ['high'] },
82
+ { provider: 'deepseek', model: 'model-b' }, // 不写强度,模型支持的都行
83
+ ])
84
+ })
85
+ ```
86
+
87
+ - 设置后取代配置里的 `models`,并重建两个工具,下一次请求就生效,不用重启。正在跑的子代理不受影响。
88
+ - 列表只存在内存里,这一行重新加载后就没了,所以要在服务出现时设一次(上面的 `ctx.inject`),设置变化时再设。
89
+ - 只有这一份配了 `childPreset` 才生效,否则什么都不做:单独安装的本插件没有 `childPreset`,它的列表属于用户的普通会话,总包不能改。
90
+ - 设成空列表,或者列表里没有一项合法,就回到列表为空时的规则。
91
+
92
+ ## 用途:助理
93
+
94
+ 助理(`@starsharryzhu/dsh-assistant`)把本插件挂成子插件,分两层:
95
+
96
+ - 用户的会话跑在隐藏的 `dsh-assisstant` preset(router)上,没有写文件的工具,只负责派活,以及审批子代理的写入申请。
97
+ - 子代理跑在 `dsh-assisstant-worker` preset 上,有完整工具,要改子工作区以外的东西时用 `request_write_access` 向 router 申请。
98
+ - `presets` 只列这两个 preset,所以这些工具不会出现在普通会话里。
99
+
100
+ ```yaml
101
+ - id: dsh-assisstant-complete-subagent
102
+ name: '@starsharryzhu/complete-subagent'
103
+ config:
104
+ presets: [dsh-assisstant, dsh-assisstant-worker]
105
+ childPreset: dsh-assisstant-worker
106
+ ownModel: false
107
+ ```
108
+
109
+ 嵌在组里的行不能在设置页编辑,所以模型列表由总包用 `setChildModels` 设置,申请超时用默认的 600 秒。
110
+
111
+ ## 授权规则
112
+
113
+ - 路径以 `/` 结尾,或本来就是已存在的目录:**目录授权**,对所有工具生效,包括 bash。不存在的目录会由父代理的权限自动创建。
114
+ - 其他路径是**文件授权**,只对 `write` / `edit` / `str_replace_editor` 生效,bash 不行(宿主沙箱只接受目录形式的额外可写根)。
115
+ - 三种授权来源(`writable_paths`、`answer_write_request`、`grant_write_access`)规则相同:父代理只能授权它自己能改的路径。孙代理要的东西如果子代理也没权限,子代理得先向它的父代理申请。
116
+ - `revoke_write_access` 只能收回授权,不能收回子工作区本身。
117
+ - 授权跟着子代理走:子代理结束后再被 `send_message` 唤醒,或者重启 DSH 后,子工作区和授权仍然有效(存在 `~/.dsh/plugin-data/complete-subagent/children/`,按 `DSH_HOME` 定位)。
118
+
119
+ ## 怎么做到的
120
+
121
+ - **不改 DSH 本身**,也不改任何 preset,也不改官方子代理工具。插件是一行顶层 bundle row,全局生效,所以标准模式、ptc、助理模式等所有 preset 都能用(配置了 `presets` 时只对列出的 preset 生效)。
122
+ - 宿主的 bash 内核沙箱、文件写入围栏、终端和代码模式,每次写入前都会问 `ctx.sandboxPolicy.resolve({ session })`。插件在加载期间包装这个方法,把子代理的可写范围收窄成「子工作区 + 授权」,卸载时还原。所以限制是内核级的,bash 也绕不过去。
123
+ - 派生时插件先算好子工作区和授权、检查模型和推理强度,再用预先分配的子代理 id 存好绑定,最后才启动子代理。所以子代理从第一步起就受限;启动失败就删掉绑定。
124
+ - 申请走宿主的相邻 agent 消息通道(`ctx.subagents.sendMessage`):父代理在运行,就在下一步看到;空闲就自动开新一轮。
125
+ - 设置页是插件自带的网页端部分,通过宿主的设置表单读写配置,模型列表和模型选择器用的是同一份目录。
126
+
127
+ ## 支持的宿主版本
128
+
129
+ DeepSeek Harness 0.2.1-rc.5 及以后、0.3 以前。在 0.2.1-rc.5、0.2.2-rc.1、0.2.2-rc.2、0.2.2-rc.3 四个宿主上实测过派子代理、限制写入、申请和批准写权限(mock 模型)。
130
+
131
+ 0.2.2-rc.2 起宿主改了启动子代理的参数写法,0.1.0 在这些宿主上派不出子代理(报 `Cannot read properties of undefined (reading 'id')`)。0.1.1 两种写法一起传,新旧宿主都能用,请升级。
132
+
133
+ rc.5 比 0.2.2-alpha.2 少三样东西,插件会自己判断并换一种做法,不用配置:
134
+
135
+ | rc.5 没有 | 插件怎么做 | 区别 |
136
+ |---|---|---|
137
+ | `presetForSession` | 从会话的 `agentPreset` 投影读 preset | 没有 |
138
+ | 工具的 `when` 条件 | 给每个 agent 单独加 `tools.restrict` 过滤 | 新 agent 和切换 preset 立刻生效,其他变化下一步才生效 |
139
+ | `additionalWritableRoots` | write / edit 写授权路径时,把这一次调用的根目录换成授权的目录 | **bash 写不了任何授权路径**,子代理的说明里会写明 |
140
+
141
+ ## 已知限制
142
+
143
+ - 父代理不受限时,它用官方工具、workflow 或其他插件(比如 Mnemon 的复盘代理)派出的子代理保持官方行为。
144
+ - 单个文件的授权只对 write / edit 工具有效,bash 写不了。在 0.2.1-rc.5 上,目录授权也一样。
145
+ - 父代理正在跑一个很长的工具调用时,申请要等那一步结束才能看到。
146
+ - 设置页只在网页版里有;桌面版还没测过。
147
+ - 在 0.2.1-rc.5 上:父代理已到深度上限时收到申请,`answer_write_request` 要晚一步才出现,申请可能因此超时并算作拒绝。这种情况只在用户中途调低深度上限时才会发生。
148
+ - 配置了 `presets` 时:以前在列表外的会话里存下的绑定,围栏照样生效,但那些会话看不到工具和说明,它们再派出的子代理也不受限制。
149
+ - 不要同时加载两份本插件(单独安装的一行加上总包里的子插件行):两份会注册同名工具。
150
+
151
+ ## 本地安装
152
+
153
+ 在 DSH checkout 目录里运行(把路径换成本目录):
154
+
155
+ ```bash
156
+ pnpm dsh plugin --profile web add link:<本目录>
157
+ ```
158
+
159
+ 它会把本插件加进 `~/.dsh/profiles/web/package.json` 的依赖和 `dsh.profile.bundles`。然后重启 DSH。`link:` 安装不会构建,所以 `lib/` 要先构建好,本目录的 `node_modules`(`link-dev` 建的符号链接)也不能删。
160
+
161
+ ## 开发
162
+
163
+ ```bash
164
+ node scripts/link-dev.mjs
165
+ node build.js
166
+ node node_modules/vitest/vitest.mjs run
167
+ ```
168
+
169
+ `link-dev` 从 `../../deepseek-harness`(或 `DSH_CHECKOUT`)链接 TypeScript、vitest、jsdom、Testing Library、React 和三个宿主包。`lib/` 是构建产物,但要提交。
@@ -0,0 +1,11 @@
1
+ # complete-subagent bundle layer: register the plugin as one top-level row.
2
+ # This file is the `dsh.bundle.patch` layer (see package.json#dsh.bundle.patch).
3
+ # The row is global on purpose: its delegation tools and the fence serve every
4
+ # agent in every preset, and it never edits a preset's rows. Its browser half
5
+ # (the settings page) loads on this row, whose specifier is the package name.
6
+ # A bundle that mounts the plugin for its own preset sets `presets` (and, when
7
+ # its children run another preset, `childPreset`, and when they run only listed
8
+ # models, `ownModel: false`) on its row.
9
+ - insert:
10
+ - id: complete-subagent
11
+ name: '@starsharryzhu/complete-subagent'