@starsharryzhu/complete-subagent 0.1.0 → 0.2.0

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/AGENTS.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## 1. Role
4
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 family's router sessions delegate and approve, and their workers do the work. The plugin supports hosts from 0.2.1-rc.5 on and reads what each host offers; `src/host/legacy.ts` holds what differs on a host older than 0.2.2-alpha.2.
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, guided by a model notes table that every parent on the machine shares: the delegation tools show each listed model's strengths, weaknesses, and suitable effort for light, normal, and hard work, ask the parent to have a model without a note researched by a child with web search, and the parent records the findings with `model_notes_set`. When a child's model runs out of quota mid-task, the parent's context says so and `switch_child_model` moves the child to another listed model, where it continues its own conversation, as a user switches models in a chat; a parent never forces a task onto a model whose notes do not fit it without asking its user first. 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 `maxDepth` setting, 0 by default, can give this copy's delegation tools their own depth limit instead of the host'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
6
 
7
7
  ## 2. Constraints
8
8
 
@@ -11,14 +11,19 @@ complete-subagent is a DeepSeek Harness plugin with its own delegation tools bes
11
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
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
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.
14
+ - A package may carry its own copy of the built plugin and start it with `embed` instead of mounting a row (the user's rule, 2026-12-03: `dsh-assisstant` uses only its own copy). An embedded copy keeps its bindings and model notes in the folder it is given, provides no service, and registers tools and prompt texts only where `mount` puts them, which is in front of any global tool of the same name. It claims its presets (`globalThis`, under `Symbol.for('complete-subagent.claimedPresets')`), and a copy with an empty `presets` then neither serves nor filters their agents, whichever loaded first.
15
+ - The settings page never shows `presets`, `childPreset`, `ownModel`, or `maxDepth`: a bundle that mounts the plugin sets them in its patch.
16
+ - `maxDepth` 0 (the default) keeps the host's subagent depth setting; above 0 it replaces that setting for this copy's delegation tools only, both for whether a tool is offered and in the start request, and leaves the user's setting and the official tools alone.
15
17
  - 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
18
  - 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
19
  - 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
20
  - Fail closed: a child is bound before it starts, a failed start drops its binding, and an uncertain inherited chain leaves no access.
19
21
  - 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
22
  - 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
- - Package identity: `@starsharryzhu/complete-subagent` version `0.1.0`, `engines.dsh` `>=0.2.1-rc.5 <0.3.0-0`; `tests/manifest.test.ts` pins them.
23
+ - 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`.
24
+ - The model notes are for the model choice only: they live in one JSON file under the DSH home (`plugin-data/complete-subagent/model-notes.json`), reach parents through the delegation descriptions alone (never a runtime context, which the host re-sends in full on every change), and only a parent that can delegate among listed models may write them. The plugin starts no research of its own: the parent decides when, and a child does it with the parent's tools and model (the user's request, 2026-11-30).
25
+ - A child stopped by its model is continued, never started over: the host fixes a step's model before the request, so the switch applies from the child's next step, and the parent's message wakes it with its session, binding, and grants intact. Where no listed model fits the task, the parent asks its user before trying one anyway (the user's rule, 2026-11-30).
26
+ - Package identity: `@starsharryzhu/complete-subagent` version `0.2.0`, `engines.dsh` `>=0.2.1-rc.5 <0.3.0-0`; `tests/manifest.test.ts` pins them.
22
27
  - `lib/` is generated by `node build.js` and committed, because `link:` and git installs do not build.
23
28
  - Every folder carries this four-section English file; `tests/agents-md.test.ts` enforces it.
24
29
 
@@ -38,13 +43,23 @@ complete-subagent is a DeepSeek Harness plugin with its own delegation tools bes
38
43
  - `vitest.config.ts` — test runner settings.
39
44
  - `README.md` — user documentation in Chinese.
40
45
  - `.gitignore` — ignores dependencies, browser compile output, and local notes, keeps `lib/`.
46
+ - `.github/workflows/publish.yml` — tag-triggered npm publish with OIDC provenance.
41
47
 
42
48
  ## 4. Progress
43
49
 
44
50
  - 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.
45
- - 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 stays `0.1.0`, as it was never published.
51
+ - 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.
52
+ - 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.
46
53
  - 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.
47
54
  - 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.
55
+ - 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.
56
+ - 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.
57
+ - 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. Published since; the real app with the real model has not been tried.
58
+ - Done (2026-11-30, user request): 0.2.0 adds the model notes table and `model_notes_set`. A note holds strengths, weaknesses, the effort for light, normal, and hard work (checked against what the model allows), sources, and the day it was recorded; the delegation descriptions show it under each listed model, name the models without a note, and say to have them researched by a child with web search beside the real work, and again after 90 days. Not yet published or installed.
59
+ - Done (2026-11-30, user request): 0.2.0 also continues a child whose model runs out of quota. When a child's turn ends with `QUOTA`, `ACCOUNT_QUOTA`, `RATE_LIMIT`, or HTTP 402, its parent's context names the child, the model, the reason, and the models left; `switch_child_model` records another listed model for the child's next step and wakes it, and it goes on with its whole conversation. A model that refused a child is not offered to it again until it finishes a turn; when every model has refused, the parent is told it cannot go on. Every text says to ask the user before forcing a task onto a model that does not fit it. Run inside the `dsh-assisstant` bundle on 0.2.2-rc.5 and 0.2.1-rc.5 hosts installed from npm, with a fake home and a mock model: a worker on `mock/fast` ran one tool call, then got HTTP 402 Insufficient Balance; the router's context named it with QUOTA, the router switched it to `mock/deep`, and the same worker continued there with its task, its earlier tool call, and the switch note, and reported back (through `agent.model.select` on 0.2.2-rc.5 and the session controller on 0.2.1-rc.5); no host warning or error. Not tried with a real quota failure.
60
+ - Done (2026-11-30, for `dsh-assisstant`'s complex tasks): the `maxDepth` setting, so a bundle can let its workers delegate one level further without changing the user's depth setting; specs cover the offer and the start request. Not yet published or installed.
61
+ - Done (2026-12-03, user request, for `dsh-assisstant`): `embed`, the claimed presets, and a sandbox wrapper that passes everything through once its copy is gone, also under a later copy's. 180 specs pass. Run on the 0.2.2-rc.5 and 0.2.1-rc.5 hosts installed from npm with a mock model, the assistant's embedded copy beside an installed one: each served only its own sessions, through the whole flow from `delegate` to a granted write, with its files in its own folder. Not yet published.
62
+ - Done (2026-12-04, user request: an unknown error is for the model to look up, never swallowed): the parent's context now carries the words of every error a child's turn ended in, and asks it to read them, to have them searched when it does not know them, and not to guess. 182 specs pass. Run inside `dsh-assisstant` on the 0.2.2-rc.5 and 0.2.1-rc.5 hosts from npm with a mock model and an adapter that failed as dsh-agy-link does (a used-up quota under its own code `AGY_ERROR`): the parent read the error, had it looked up by a child on another model, and moved the stopped child there with `switch_child_model`, where it finished its task.
48
63
  - 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.
49
64
  - 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.
50
65
  - 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.
package/README.md CHANGED
@@ -38,6 +38,40 @@ DeepSeek Harness 插件:一套**独立的子代理工具**,带**子工作区
38
38
  - **写入申请的等待时间(秒)**:最少 10 秒,默认 600 秒。
39
39
  - 改完保存,AI 的下一步就生效,不用重启。
40
40
 
41
+ ## 模型能力表:`model_notes_set`
42
+
43
+ 父代理选子代理的模型和推理强度时,可以参考一张**模型能力表**。表里每个可选模型一行:擅长什么、不擅长什么(包括快慢和价格)、轻活 / 一般的活 / 难活各用哪一档推理强度、资料来源、记录日期。
44
+
45
+ - **表从哪来**:设置里列出的模型还没有记录时,`delegate` 的说明会点出这些模型,并让父代理在下次派活时**顺带派一个能联网搜索的子代理**去查(官方文档、模型卡、价格、第三方评测),查完由父代理用 `model_notes_set` 记下来。调研和正事并行,不耽误正事;在记录出来之前,父代理按模型名字来选。
46
+ - **怎么用**:记下之后,每个模型的那一行就显示在 `delegate` / `delegate_fork` 的说明里,模型名下面。以后每次派活都按这张表选模型和推理强度,新对话里也一样。
47
+ - **过期**:记录超过 90 天,说明里会提醒父代理重新查一次。父代理在实际使用中发现某个模型哪类活做得不好,也可以随时更新。
48
+ - **检查**:只能记设置里列出的模型;推理强度必须是该模型允许的档位(和派活时同样的检查);每段文字最多 600 字符,来源最多 8 个 http(s) 链接。
49
+ - **存在哪**:`$DSH_HOME/plugin-data/complete-subagent/model-notes.json`(默认 `~/.dsh/...`),这台电脑上所有父代理共用一张表。资料来源只存在文件里,不放进说明,省 token。
50
+ - **为什么放在工具说明里**:宿主每当任何一段运行时上下文变化,就会把全部上下文重新发一遍;表放在工具说明里,只有表本身变化时才变。
51
+ - 插件自己不会主动去查:什么时候查、派哪个子代理查,由父代理决定,用的也是父代理能派的模型。
52
+
53
+ ## 子代理的模型额度用完:`switch_child_model`
54
+
55
+ 子代理做到一半,它的模型额度用完(余额不足、配额用尽,或限流且宿主重试后仍不行)时,**不从头再派一次**,而是换个模型接着做:
56
+
57
+ - 宿主会照常通知父代理「子代理失败了」,同时父代理的上下文里会说明是哪个子代理、哪个模型、什么原因,以及还剩哪些模型可换。
58
+ - 父代理用 `switch_child_model`(子代理 id、新模型、可选的推理强度和留言)把子代理换到列表里另一个模型。子代理带着**完整的原有对话**从停下的地方接着做,就像聊天时用户换了个模型;子工作区和授权都还在,结果照常回到父代理。
59
+ - 宿主在每一步开始前就定好了模型,同一步里重试只会再撞同一个模型,所以换模型从子代理的下一步生效,由父代理发一条消息叫醒它。
60
+ - 已经拒绝过这个子代理的模型,在它完整做完一轮之前不能再选;所有模型都拒绝了,上下文会告诉父代理这件事做不下去了。
61
+ - **没有合适的模型时先问**:按模型能力表,剩下的模型都不适合这个任务时,父代理不能硬换一个试,要先问用户,得到许可才试。这条写在工具说明和上下文里。
62
+ - 也可以用它给做得不好的子代理换模型。
63
+ - 判断「额度用完」用的是宿主的错误码 `QUOTA`、`ACCOUNT_QUOTA`、`RATE_LIMIT` 或 HTTP 402,0.2.1-rc.5 起都一样。在 0.2.1-rc.5 上换模型走宿主会话控制器的内部接口。等待中的记录只在内存里,重启后父代理仍有宿主的失败通知。
64
+
65
+ ## 子代理因为别的错误停下
66
+
67
+ 宿主只告诉父代理「子代理失败了」,不说原因。所以子代理的一轮以任何错误结束时,父代理的上下文里都会有**报错原文**(错误码、HTTP 状态和错误信息,最多 1500 字),并要求它:
68
+
69
+ - 先读报错,不许猜原因;
70
+ - 看不懂就先联网查报错原文(自己查,或者派一个用别的模型的子代理去查),查的时候去掉私人信息;
71
+ - 再按原因处理:让子代理接着做、换模型,或者如实说明为什么做不下去。
72
+
73
+ 报错显示到这个子代理重新开始为止,最多显示一天。被用户或父代理停下的不算错误。
74
+
41
75
  ## 只在指定 preset 里生效:`presets`
42
76
 
43
77
  插件还有两个配置项设置页上不显示,主要给**把本插件当子插件挂载的总包**在 patch 里写。第一个是 `presets`(字符串数组)。
@@ -58,6 +92,13 @@ DeepSeek Harness 插件:一套**独立的子代理工具**,带**子工作区
58
92
  - `delegate_fork` 走 `fork` 后端,继承父代理的上下文,**永远不指定** preset,子代理照旧跟父代理同一个 preset。
59
93
  - 子代理在不在服务范围内,按它自己的 preset 判断。所以配置了 `presets` 时,`childPreset` 也要写进 `presets`,否则子代理看不到 `request_write_access`,也收不到本插件的说明(它仍然受限制)。
60
94
 
95
+ ## 委派深度:`maxDepth`
96
+
97
+ `maxDepth`(自然数)同样不在设置页显示,由总包在 patch 里写。
98
+
99
+ - **默认 `0`**:用宿主「子代理」设置里的深度上限(宿主默认 1,只能派一层)。
100
+ - **大于 0**:本插件的 `delegate` / `delegate_fork` 按这个上限判断能不能派,并把它带进启动请求。`2` 表示子代理还能再派一层孙代理,孙代理不能再派。不改用户的全局设置,官方工具不受影响。
101
+
61
102
  ## 只用列表里的模型:`ownModel`
62
103
 
63
104
  `ownModel`(布尔)同样不在设置页显示,由总包在 patch 里写。
@@ -89,24 +130,27 @@ ctx.inject(['completeSubagent'], (child) => {
89
130
  - 只有这一份配了 `childPreset` 才生效,否则什么都不做:单独安装的本插件没有 `childPreset`,它的列表属于用户的普通会话,总包不能改。
90
131
  - 设成空列表,或者列表里没有一项合法,就回到列表为空时的规则。
91
132
 
92
- ## 用途:助理
93
-
94
- 助理(`@starsharryzhu/dsh-assistant`)把本插件挂成子插件,分两层:
133
+ ## 包里自带一份:`embed`
95
134
 
96
- - 家人的会话跑在隐藏的 `dsh-assisstant` preset(router)上,没有写文件的工具,只负责派活,以及审批子代理的写入申请。
97
- - 子代理跑在 `dsh-assisstant-worker` preset 上,有完整工具,要改子工作区以外的东西时用 `request_write_access` 向 router 申请。
98
- - `presets` 只列这两个 preset,所以这些工具不会出现在普通会话里。
135
+ 别的包可以把本插件的 `lib/` 放进自己的包里,用 `embed` 启动,不用另外挂一行:
99
136
 
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
137
+ ```ts
138
+ const own = embed(ctx, {
139
+ dataDirectory, // 绑定和模型能力表存在这里
140
+ presets: [router, worker], // 只服务这些 preset
141
+ childPreset: worker, // delegate 派出的子代理跑在这个 preset 上
142
+ maxDepth: 2,
143
+ withhold: { [router]: ['delegate_fork'] }, // 某个 preset 不给的工具
144
+ })
145
+ own?.mount(presetCtx) // 在每个 preset 自己的作用域里注册工具和说明
146
+ own?.setChildModels(models) // 子代理能用的模型
107
147
  ```
108
148
 
109
- 嵌在组里的行不能在设置页编辑,所以模型列表由总包用 `setChildModels` 设置,申请超时用默认的 600 秒。
149
+ - 自带的这份不提供 `completeSubagent` 服务,不注册全局工具,文件只放在 `dataDirectory`。
150
+ - 它服务的 preset 归它:同一个 DSH 里再单独装一份本插件,`presets` 留空的那份会跳过这些 preset,两份互不影响,装了、升级、停用、删掉哪一份都不影响另一份。
151
+ - 从 0.2.0 起才有。单独安装的那份如果更旧,在宿主 0.2.1-rc.5 上会把这些 preset 的同名工具一起藏掉。
152
+
153
+ 助理(`@starsharryzhu/dsh-assistant`)就是这样用的:用户的会话跑在隐藏的 `dsh-assisstant` preset 上,没有写文件的工具,只负责派活,以及审批子代理的写入申请;子代理跑在 `dsh-assisstant-worker` preset 上,有完整工具,要改子工作区以外的东西时用 `request_write_access` 申请。
110
154
 
111
155
  ## 授权规则
112
156
 
@@ -126,7 +170,9 @@ ctx.inject(['completeSubagent'], (child) => {
126
170
 
127
171
  ## 支持的宿主版本
128
172
 
129
- DeepSeek Harness 0.2.1-rc.5 及以后、0.3 以前。DSH Desktop 现在用的就是 rc.5。
173
+ 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 模型)。
174
+
175
+ 0.2.2-rc.2 起宿主改了启动子代理的参数写法,0.1.0 在这些宿主上派不出子代理(报 `Cannot read properties of undefined (reading 'id')`)。0.1.1 两种写法一起传,新旧宿主都能用,请升级。
130
176
 
131
177
  rc.5 比 0.2.2-alpha.2 少三样东西,插件会自己判断并换一种做法,不用配置:
132
178
 
package/lib/client.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @starsharryzhu/complete-subagent 0.1.0 — generated by build.js from src/; do not edit. */
1
+ /* @starsharryzhu/complete-subagent 0.2.0 — generated by build.js from src/; do not edit. */
2
2
  window.__ModuleLoader__.load({
3
3
  id: "@starsharryzhu/complete-subagent",
4
4
  factory: (require) => {
@@ -327,6 +327,7 @@ window.__ModuleLoader__.load({
327
327
  exports.readModels = readModels;
328
328
  exports.readPresets = readPresets;
329
329
  exports.readChildPreset = readChildPreset;
330
+ exports.readMaxDepth = readMaxDepth;
330
331
  exports.readOwnModel = readOwnModel;
331
332
  exports.readTimeout = readTimeout;
332
333
  /** The npm package name: the browser bundle's registration id and the Plugins page key. */
@@ -391,6 +392,14 @@ window.__ModuleLoader__.load({
391
392
  function readChildPreset(value) {
392
393
  return typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined;
393
394
  }
395
+ /**
396
+ * Read a stored depth limit.
397
+ * @param value - the stored `maxDepth` field.
398
+ * @returns a whole number above 0, or undefined when the host's own limit applies.
399
+ */
400
+ function readMaxDepth(value) {
401
+ return typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined;
402
+ }
394
403
  /**
395
404
  * Read the stored `ownModel` flag.
396
405
  * @param value - the stored field.
@@ -13,6 +13,7 @@
13
13
  import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
14
14
  import type { ChildModel } from '../shared/settings.ts';
15
15
  import type { AccessDeps } from './access.ts';
16
+ import type { ModelNotes } from './notes.ts';
16
17
  import type { AgentLike, DelegateTool, LlmLike, SubagentsLike } from './types.ts';
17
18
  /** What the delegation tools read. */
18
19
  export interface DelegateDeps extends AccessDeps {
@@ -25,10 +26,16 @@ export interface DelegateDeps extends AccessDeps {
25
26
  readonly childPreset?: string;
26
27
  /** False keeps a `delegate` child off the parent's own model when models are listed. */
27
28
  readonly ownModel?: boolean;
29
+ /** The model notes table, shown under each listed model. */
30
+ readonly notes?: ModelNotes;
31
+ /** Depth limit of this copy; undefined uses the host's setting. */
32
+ readonly maxDepth?: number;
28
33
  }
29
34
  /**
30
35
  * Build one delegation tool for the current settings. The model list is fixed
31
36
  * into the schema, so the entry rebuilds the tools when the settings change.
37
+ * The model notes are not: the description reads them whenever the host
38
+ * projects the schema, so a note shows from the parent's next step.
32
39
  * @param tool - which tool.
33
40
  * @param models - the settings' model list.
34
41
  * @param deps - shared state and services.
@@ -37,11 +44,13 @@ export interface DelegateDeps extends AccessDeps {
37
44
  export declare function createDelegateTool(tool: DelegateTool, models: readonly ChildModel[], deps: DelegateDeps): ToolDefinition;
38
45
  /**
39
46
  * Whether an agent may delegate on a backend now: the backend is registered
40
- * and the agent is below the user's depth limit. A limit that cannot be read
41
- * leaves the tool visible; the runtime then rejects the start.
47
+ * and the agent is below the depth limit, this copy's own or else the user's.
48
+ * A limit that cannot be read leaves the tool visible; the runtime then
49
+ * rejects the start.
42
50
  * @param subagents - the subagent runtime.
43
51
  * @param tool - which tool.
44
52
  * @param agent - the would-be parent.
53
+ * @param configured - this copy's depth limit; undefined uses the host's setting.
45
54
  * @returns true when the tool should be offered.
46
55
  */
47
- export declare function canStart(subagents: SubagentsLike, tool: DelegateTool, agent: AgentLike): boolean;
56
+ export declare function canStart(subagents: SubagentsLike, tool: DelegateTool, agent: AgentLike, configured?: number): boolean;
@@ -20,6 +20,8 @@ import { DELEGATE_TOOLS } from "./types.js";
20
20
  /**
21
21
  * Build one delegation tool for the current settings. The model list is fixed
22
22
  * into the schema, so the entry rebuilds the tools when the settings change.
23
+ * The model notes are not: the description reads them whenever the host
24
+ * projects the schema, so a note shows from the parent's next step.
23
25
  * @param tool - which tool.
24
26
  * @param models - the settings' model list.
25
27
  * @param deps - shared state and services.
@@ -29,9 +31,10 @@ export function createDelegateTool(tool, models, deps) {
29
31
  const provider = DELEGATE_TOOLS[tool];
30
32
  // A fork continues the parent's conversation, so its own model stays the default there.
31
33
  const ownModel = provider === 'spawn' ? deps.ownModel !== false : true;
32
- return defineTool({
34
+ const describe = () => delegateDescription(tool, describeModels(models, ownModel, model => deps.notes?.get(model)));
35
+ const definition = defineTool({
33
36
  name: tool,
34
- description: delegateDescription(tool, describeModels(models, ownModel)),
37
+ description: describe(),
35
38
  parameters: {
36
39
  description: {
37
40
  type: 'string',
@@ -73,24 +76,28 @@ export function createDelegateTool(tool, models, deps) {
73
76
  ownModel,
74
77
  });
75
78
  exec.signal.throwIfAborted();
76
- const maxDepth = deps.subagents.resolveMaxDepth();
79
+ const maxDepth = deps.maxDepth ?? deps.subagents.resolveMaxDepth();
77
80
  // The fork backend inherits the parent's context, so only spawn may select a preset.
78
81
  const agentPreset = provider === 'spawn' ? deps.childPreset : undefined;
79
82
  const childId = deps.newId?.() ?? randomUUID();
80
83
  deps.store.set({ version: 1, child: childId, parent: parent.session.id, workspace: access.workspace, grants: access.grants });
84
+ const task = {
85
+ ...access.cwd === undefined ? {} : { cwd: access.cwd },
86
+ prompt: [{ type: 'text', text: args.prompt }],
87
+ parent,
88
+ ...agentPreset === undefined ? {} : { agentPreset },
89
+ ...route === undefined ? {} : { agentOptions: route },
90
+ ...maxDepth === undefined ? {} : { maxDepth },
91
+ };
81
92
  try {
93
+ // The task goes both ways: hosts from 0.2.2-rc.2 read it at the top level and those before under
94
+ // `request`, and neither reads the other's fields, so one call starts the child on every host.
82
95
  const started = await deps.subagents.startActivation({
83
96
  provider,
84
97
  label: args.description,
85
98
  childId,
86
- request: {
87
- ...access.cwd === undefined ? {} : { cwd: access.cwd },
88
- prompt: [{ type: 'text', text: args.prompt }],
89
- parent,
90
- ...agentPreset === undefined ? {} : { agentPreset },
91
- ...route === undefined ? {} : { agentOptions: route },
92
- ...maxDepth === undefined ? {} : { maxDepth },
93
- },
99
+ ...task,
100
+ request: task,
94
101
  signal: exec.signal,
95
102
  delivery: 'parent',
96
103
  });
@@ -102,22 +109,28 @@ export function createDelegateTool(tool, models, deps) {
102
109
  }
103
110
  },
104
111
  });
112
+ // A note changes while the tool stays registered: the host's step admits a tool only while its registered
113
+ // definition is unchanged, so swapping the definition would fail a call still running on the old one.
114
+ Object.defineProperty(definition, 'description', { enumerable: true, configurable: true, get: describe });
115
+ return definition;
105
116
  }
106
117
  /**
107
118
  * Whether an agent may delegate on a backend now: the backend is registered
108
- * and the agent is below the user's depth limit. A limit that cannot be read
109
- * leaves the tool visible; the runtime then rejects the start.
119
+ * and the agent is below the depth limit, this copy's own or else the user's.
120
+ * A limit that cannot be read leaves the tool visible; the runtime then
121
+ * rejects the start.
110
122
  * @param subagents - the subagent runtime.
111
123
  * @param tool - which tool.
112
124
  * @param agent - the would-be parent.
125
+ * @param configured - this copy's depth limit; undefined uses the host's setting.
113
126
  * @returns true when the tool should be offered.
114
127
  */
115
- export function canStart(subagents, tool, agent) {
128
+ export function canStart(subagents, tool, agent, configured) {
116
129
  if (subagents.getProvider(DELEGATE_TOOLS[tool]) === undefined)
117
130
  return false;
118
- let maxDepth;
131
+ let maxDepth = configured;
119
132
  try {
120
- maxDepth = subagents.resolveMaxDepth();
133
+ maxDepth ??= subagents.resolveMaxDepth();
121
134
  }
122
135
  catch {
123
136
  return true;
@@ -12,9 +12,14 @@
12
12
  * model is the first one, an effort-only call sets that model's effort, and an
13
13
  * omitted effort never comes from the parent, even when the parent runs the
14
14
  * same model. An empty list leaves the rules above.
15
+ *
16
+ * The description lists each model with its note from the model notes table
17
+ * (`notes.ts`), names the models without one, and tells the parent to have
18
+ * those researched by a child with web search and to record what it finds.
15
19
  * @module complete-subagent/host/models
16
20
  */
17
21
  import type { ChildModel } from '../shared/settings.ts';
22
+ import type { ModelNote } from './notes.ts';
18
23
  import type { AgentLike, LlmLike } from './types.ts';
19
24
  /** A route with its provider and model known. */
20
25
  export interface Route {
@@ -35,6 +40,18 @@ export interface ModelRequest {
35
40
  * @returns its route, or undefined when the provider or model is unknown.
36
41
  */
37
42
  export declare function routeOf(agent: AgentLike): Route | undefined;
43
+ /**
44
+ * The efforts a child on one model may run: the listed ones, else every one the model advertises.
45
+ * @param route - the model.
46
+ * @param listed - the efforts the settings list for it.
47
+ * @param llm - the LLM runtime.
48
+ * @param signal - aborts the lookup.
49
+ * @returns the effort ids, empty for a model without selectable efforts.
50
+ */
51
+ export declare function offeredEfforts(route: {
52
+ readonly provider: string;
53
+ readonly model: string;
54
+ }, listed: readonly string[], llm: LlmLike, signal?: AbortSignal): Promise<readonly string[]>;
38
55
  /**
39
56
  * Validate one call's model and effort and turn them into child options.
40
57
  * @param options - the parent, the settings list, the call's fields, the LLM runtime, and the `ownModel` rule.
@@ -50,10 +67,17 @@ export declare function chooseRoute(options: {
50
67
  /** False keeps the child off the parent's own model when models are listed. */
51
68
  readonly ownModel?: boolean;
52
69
  }): Promise<Route | undefined>;
70
+ /**
71
+ * One model's note as the line under its entry.
72
+ * @param note - the stored note.
73
+ * @returns the indented line.
74
+ */
75
+ export declare function noteLine(note: ModelNote): string;
53
76
  /**
54
77
  * The model-selection paragraph of a delegation tool's description.
55
78
  * @param models - the settings list.
56
79
  * @param ownModel - false keeps the child off the parent's own model when models are listed.
80
+ * @param noteOf - the stored note on a model, shown under its entry.
57
81
  * @returns the text the parent reads.
58
82
  */
59
- export declare function describeModels(models: readonly ChildModel[], ownModel?: boolean): string;
83
+ export declare function describeModels(models: readonly ChildModel[], ownModel?: boolean, noteOf?: (model: string) => ModelNote | undefined): string;
@@ -12,9 +12,15 @@
12
12
  * model is the first one, an effort-only call sets that model's effort, and an
13
13
  * omitted effort never comes from the parent, even when the parent runs the
14
14
  * same model. An empty list leaves the rules above.
15
+ *
16
+ * The description lists each model with its note from the model notes table
17
+ * (`notes.ts`), names the models without one, and tells the parent to have
18
+ * those researched by a child with web search and to record what it finds.
15
19
  * @module complete-subagent/host/models
16
20
  */
17
21
  import { modelKey } from "../shared/settings.js";
22
+ import { STALE_DAYS, WORK_KINDS } from "./notes.js";
23
+ import { NOTES_TOOL } from "./types.js";
18
24
  /**
19
25
  * The route an agent's next request uses, as the host hands it to a child
20
26
  * (`parentAgentOptionsForDelegation`): the session's request header once it
@@ -32,6 +38,19 @@ export function routeOf(agent) {
32
38
  ...source.reasoningEffort === undefined ? {} : { reasoningEffort: source.reasoningEffort },
33
39
  };
34
40
  }
41
+ /**
42
+ * The efforts a child on one model may run: the listed ones, else every one the model advertises.
43
+ * @param route - the model.
44
+ * @param listed - the efforts the settings list for it.
45
+ * @param llm - the LLM runtime.
46
+ * @param signal - aborts the lookup.
47
+ * @returns the effort ids, empty for a model without selectable efforts.
48
+ */
49
+ export async function offeredEfforts(route, listed, llm, signal) {
50
+ if (listed.length > 0)
51
+ return listed;
52
+ return (await llm.resolveModelInfo(route.provider, route.model, signal)).reasoning?.efforts.map(item => item.id) ?? [];
53
+ }
35
54
  /** The choices as one line for an error message. */
36
55
  function choicesLine(models) {
37
56
  return models.length === 0 ? 'none are listed in the settings' : models.map(modelKey).join(', ');
@@ -84,9 +103,7 @@ export async function chooseRoute(options) {
84
103
  throw new Error('The child model cannot be checked because the `llm` service is unavailable.');
85
104
  let chosen = effort;
86
105
  if (effort !== undefined) {
87
- const offered = allowed.length > 0
88
- ? allowed
89
- : (await llm.resolveModelInfo(route.provider, route.model, options.signal)).reasoning?.efforts.map(item => item.id) ?? [];
106
+ const offered = await offeredEfforts(route, allowed, llm, options.signal);
90
107
  if (!offered.includes(effort)) {
91
108
  throw new Error(offered.length === 0
92
109
  ? `${key} has no selectable reasoning effort; omit \`reasoning_effort\`.`
@@ -109,31 +126,78 @@ export async function chooseRoute(options) {
109
126
  }, options.signal);
110
127
  return { provider: route.provider, model: route.model, ...chosen === undefined ? {} : { reasoningEffort: chosen } };
111
128
  }
129
+ /** Text as a sentence: trimmed, with a closing full stop when it has no closing mark. */
130
+ function sentence(text) {
131
+ const trimmed = text.trim();
132
+ return /[.!?。!?]$/u.test(trimmed) ? trimmed : `${trimmed}.`;
133
+ }
134
+ /**
135
+ * One model's note as the line under its entry.
136
+ * @param note - the stored note.
137
+ * @returns the indented line.
138
+ */
139
+ export function noteLine(note) {
140
+ const efforts = WORK_KINDS.flatMap(kind => note.efforts[kind] === undefined ? [] : [`${kind} work ${note.efforts[kind]}`]);
141
+ return [
142
+ ` Notes (checked ${note.checked}). Strong at: ${sentence(note.strengths)} Weak at: ${sentence(note.weaknesses)}`,
143
+ ...efforts.length === 0 ? [] : [`Effort: ${efforts.join(', ')}.`],
144
+ ].join(' ');
145
+ }
146
+ /**
147
+ * What the parent does with the notes: research the models without one, and
148
+ * choose from them.
149
+ * @param models - the settings list, not empty.
150
+ * @param noteOf - the stored note on a model.
151
+ * @returns the paragraph.
152
+ */
153
+ function notesParagraph(models, noteOf) {
154
+ const missing = models.map(modelKey).filter(key => noteOf(key) === undefined);
155
+ const research = 'start one research child that can search the web, beside the real work, and ask it to look up each of these models '
156
+ + 'in its provider\'s documentation, model card, and pricing and in independent evaluations, and to report its strengths, weaknesses, '
157
+ + 'speed, and price, and which reasoning effort suits light, normal, and hard work';
158
+ return [
159
+ ...missing.length === 0 ? [] : [
160
+ `No notes yet on ${missing.join(', ')}. The next time you delegate, also ${research}; then record each with \`${NOTES_TOOL}\`. `
161
+ + 'Until a model has a note, choose by its name.',
162
+ ],
163
+ `Choose each child's model and effort from these notes. When no listed model's notes fit a task, do not force the task onto one anyway: `
164
+ + 'ask your user first, and try a model only with their permission. '
165
+ + `A note checked more than ${STALE_DAYS} days ago may be out of date: `
166
+ + `have that model researched again the same way. Record what you learn later, such as a model doing poorly at some kind of work, with \`${NOTES_TOOL}\`.`,
167
+ ].join('\n');
168
+ }
112
169
  /**
113
170
  * The model-selection paragraph of a delegation tool's description.
114
171
  * @param models - the settings list.
115
172
  * @param ownModel - false keeps the child off the parent's own model when models are listed.
173
+ * @param noteOf - the stored note on a model, shown under its entry.
116
174
  * @returns the text the parent reads.
117
175
  */
118
- export function describeModels(models, ownModel = true) {
176
+ export function describeModels(models, ownModel = true, noteOf = () => undefined) {
119
177
  const efforts = (entry) => entry.reasoningEfforts.length === 0
120
178
  ? 'any effort it supports'
121
179
  : `efforts ${entry.reasoningEfforts.join(', ')}`;
180
+ const entries = models.flatMap(entry => {
181
+ const note = noteOf(modelKey(entry));
182
+ return [`- ${modelKey(entry)}: ${efforts(entry)}`, ...note === undefined ? [] : [noteLine(note)]];
183
+ });
122
184
  if (models.length === 0) {
123
185
  return 'Model: the child uses your own model. `reasoning_effort` may be any effort your model supports; omitted, the child keeps your current effort.';
124
186
  }
125
187
  if (!ownModel) {
126
188
  return [
127
189
  'Model: the child runs one of these models, never your own. Omit `model` to use the first; `reasoning_effort` applies to the model the child runs.',
128
- ...models.map(entry => `- ${modelKey(entry)}: ${efforts(entry)}`),
190
+ ...entries,
129
191
  'An omitted effort uses the model\'s default, or its first listed effort when the default is not listed.',
192
+ notesParagraph(models, noteOf),
130
193
  ].join('\n');
131
194
  }
132
195
  return [
133
196
  'Model: omit `model` to give the child your own model; `reasoning_effort` may then be any effort your model supports '
134
197
  + '(only the listed ones if your model is listed below), and an omitted effort keeps your current one.',
135
198
  'Other models you may choose with `model`:',
136
- ...models.map(entry => `- ${modelKey(entry)}: ${efforts(entry)}`),
199
+ ...entries,
137
200
  'On another model, an omitted effort uses that model\'s default, or its first listed effort when the default is not listed.',
201
+ notesParagraph(models, noteOf),
138
202
  ].join('\n');
139
203
  }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * `model_notes_set`: a parent records what it found out about a model its
3
+ * children may run, usually from a research child with web search, so the
4
+ * delegation tools show it from then on, in this and every later conversation.
5
+ * @module complete-subagent/host/notes-tool
6
+ */
7
+ import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
8
+ import type { ChildModel } from '../shared/settings.ts';
9
+ import type { ModelNotes } from './notes.ts';
10
+ import type { LlmLike } from './types.ts';
11
+ /** What the tool reads. */
12
+ export interface NotesToolDeps {
13
+ readonly notes: ModelNotes;
14
+ /** The LLM runtime, read at call time because it is optional. */
15
+ readonly llm: () => LlmLike | undefined;
16
+ /** The current time; replaceable in tests. */
17
+ readonly now?: () => Date;
18
+ }
19
+ /**
20
+ * Build the tool for the current model list, which its `model` parameter names.
21
+ * @param models - the settings' model list.
22
+ * @param deps - the table and services.
23
+ * @returns a registry-ready definition.
24
+ */
25
+ export declare function createNotesTool(models: readonly ChildModel[], deps: NotesToolDeps): ToolDefinition;