@dsh-cc/coordinator 0.5.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ # Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
2
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
+ # after editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write packages/subagent/coordinator/README.md
5
+ README.md: bc1add74cb3269a3ca12fb644e78ab2ecb8e3f44
6
+ README.zh.md: adff7bdffee7e3020ade7393b173e646d42fa530
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @dsh-cc/coordinator
2
+
3
+ English | [中文](README.zh.md)
4
+
5
+ Coordinator mode is an agent-scoped orchestration role over continuable subagents: when active, the hosting agent stops editing the workspace directly and instead delegates work to named background workers and routes messages among them. Activation is a deployment flag — Config `enabled` or the `DSH_COORDINATOR_MODE` env — and it takes effect on the agent whose scope mounts this package, so a preset [composes it](../preset/agent-presets/README.md) into a session and the mode survives resume by being re-mounted from that pinned composition.
6
+
7
+ ## Activation and tool restriction
8
+
9
+ `apply(ctx, config)` resolves `config.enabled ?? DSH_COORDINATOR_MODE`, and when inactive registers nothing — a preset may mount it unconditionally. When active it requires an agent-scoped context (it reads the mounted `agent`), because tool restriction is an agent-scoped operation; mounting it on a plain context fails loud rather than masking every agent. It then installs, all scoped to that agent:
10
+
11
+ - a `coordinator:mode` system-prompt section (`installCoordinatorMode`'s `sectionOrder`, default prompt-order 110) stating the orchestration role, the delegation tool list, and the result-return protocol;
12
+ - the scheduling tools `spawn_worker`, `send_to_worker`, `worker_broadcast`, and `worker_tasks`;
13
+ - a scoped [tool restriction](../../core/tools/README.md) via `ctx.tools.restrict()`, defaulting to `{ deny: ['write', 'edit'] }` (Config `restrict` overrides, and may use an `allow` mask instead).
14
+
15
+ Disposing the plugin fiber reverses every registration in one pass, so disabling coordinator mode restores the agent's full tool surface.
16
+
17
+ ## Delegation surface
18
+
19
+ The scheduling tools are thin adapters over the subagent service, so residency, cold resume, and delivery authority remain the service's:
20
+
21
+ - `spawn_worker(name, prompt)` calls `ctx.subagents.startContinuable()` and records the durable child id under the given name.
22
+ - `send_to_worker(worker, message)` resolves a name (or durable id) and delivers one next-turn message through `ctx.subagents.followup()`, sourcing it `{ kind: 'coordinator', form: 'relay' }`.
23
+ - `worker_broadcast(message)` follows up the same content with every registered worker.
24
+ - `worker_tasks()` lists registered workers with a live status from the Agent registry.
25
+
26
+ An unknown worker reference is an errored result; a scheduling tool invoked without a calling agent fails loud.
27
+
28
+ ## Result return and completion (reused protocols)
29
+
30
+ Coordinator mode does not reinvent worker-to-coordinator reporting. A worker reports through the independently installed [`@deepseek-ai/dsh-tool-subagent-report`](../tool-subagent-report/README.md) `report` tool, and the subagent service delivers that as a parent message. When a worker settles, the subagent service's continuation settlement already injects its `subagent-settled` notice into the coordinator agent's session as a waking message ([`dsh-subagent` continuation settlement delivery](../subagent/README.md)) — the completion notification that wakes the coordinator's loop. This package documents that reuse rather than duplicating the wake; its tests assert the notice reaches the coordinator session.
31
+
32
+ ## Directory
33
+
34
+ The `Section` texts and constants live in `src/section.ts`; the worker bookkeeping, scheduling tools, activation gate, and disposer live in `src/index.ts`.
package/README.zh.md ADDED
@@ -0,0 +1,34 @@
1
+ # @dsh-cc/coordinator
2
+
3
+ [English](README.md) | 中文
4
+
5
+ 协调模式是一种基于可继续子代理(continuable subagent)的、作用于单个 agent 作用域的编排角色:激活后,宿主 agent 不再直接修改工作区,而是把任务委派给有名字的后台 worker,并在它们之间路由消息。激活由部署开关控制——Config 的 `enabled` 或 `DSH_COORDINATOR_MODE` 环境变量——它作用于挂载本包的 agent 作用域,因此 preset 会[把该组合编排进会话](../preset/agent-presets/README.md),并通过在 resume 时从固定的组合中重新挂载来保持该模式。
6
+
7
+ ## 激活与工具限制
8
+
9
+ `apply(ctx, config)` 解析 `config.enabled ?? DSH_COORDINATOR_MODE`,未激活时不注册任何内容——preset 可以无条件挂载它。激活时需要 agent 作用域的上下文(它读取被挂载的 `agent`),因为工具限制是 agent 作用域操作;挂载到普通上下文会明确报错,而不是遮蔽所有 agent。随后它会安装以下内容(全部限定在该 agent 作用域):
10
+
11
+ - 一个 `coordinator:mode` system-prompt 区段(`installCoordinatorMode` 的 `sectionOrder`,默认 prompt-order 110),说明编排职责、委派工具清单以及结果回流协议;
12
+ - 调度工具 `spawn_worker`、`send_to_worker`、`worker_broadcast` 和 `worker_tasks`;
13
+ - 通过 `ctx.tools.restrict()` 施加的[作用域工具限制](../../core/tools/README.md),默认为 `{ deny: ['write', 'edit'] }`(Config `restrict` 可覆盖,也可改用 `allow` 掩码)。
14
+
15
+ 释放插件 fiber 会一次性撤销全部注册,因此关闭协调模式即可恢复该 agent 的完整工具面。
16
+
17
+ ## 委派面
18
+
19
+ 调度工具是 subagent 服务之上的薄适配层,因此驻留、冷恢复和投递权限仍归服务所有:
20
+
21
+ - `spawn_worker(name, prompt)` 调用 `ctx.subagents.startContinuable()`,并把持久子 id 记录在给定名称之下。
22
+ - `send_to_worker(worker, message)` 解析名称(或持久 id),并通过 `ctx.subagents.followup()` 投递一条下一轮消息,其来源记为 `{ kind: 'coordinator', form: 'relay' }`。
23
+ - `worker_broadcast(message)` 把相同内容发送给每个已注册 worker。
24
+ - `worker_tasks()` 列出已注册 worker,并附带来自 Agent 注册表的实时状态。
25
+
26
+ 未知的 worker 引用会得到出错结果;在无调用 agent 的情况下调用调度工具会明确失败。
27
+
28
+ ## 结果回流与完成(复用既有协议)
29
+
30
+ 协调模式不会重新实现 worker 到协调者的结果回流。worker 通过独立安装的 [`@deepseek-ai/dsh-tool-subagent-report`](../tool-subagent-report/README.md) 的 `report` 工具上报,subagent 服务会将其作为一条父级消息投递。当某 worker 结束(settle)时,subagent 服务的 continuation 结算已把它的 `subagent-settled` 通知作为唤醒消息注入协调者 agent 的会话(参见 [`dsh-subagent` continuation 结算投递](../subagent/README.md))——这正是唤醒协调者循环的完成通知。本包记录这一复用而不是重复实现唤醒;其测试断言该通知确实到达协调者会话。
31
+
32
+ ## 目录
33
+
34
+ `src/section.ts` 中的 Section 文本与常量;worker 记账、调度工具、激活开关与释放器均位于 `src/index.ts`。
package/lib/index.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Coordinator mode: an agent-scoped orchestration role over continuable
3
+ * subagents. Activation (Config `enabled` or the `DSH_COORDINATOR_MODE` env)
4
+ * restricts the agent's correspondence to delegation and read-only tools,
5
+ * installs a coordinator prompt section, and brings up the model-facing
6
+ * scheduling tools ({@link spawn_worker}, {@link send_to_worker},
7
+ * {@link worker_broadcast}, {@link worker_tasks}).
8
+ *
9
+ * Result return and completion waking are NOT reimplemented here: a worker
10
+ * reports through the existing `report` tool (`tool-subagent-report`),
11
+ * and the subagent manager already injects its `subagent-settled` notice into
12
+ * this coordinator's inbox as a waking message when a worker settles
13
+ * (`@deepseek-ai/dsh-subagent`'s continuation settlement delivery). This
14
+ * package adds the coordinator role and its naming/messaging surface around
15
+ * those seams and documents the reuse.
16
+ * @module @dsh-cc/coordinator
17
+ */
18
+ import type { Agent } from '@deepseek-ai/dsh-agent';
19
+ import { Context } from '@deepseek-ai/cordis';
20
+ import { type ToolRestriction } from '@dsh-cc/tools';
21
+ /** Default tool visibility mask: deny the two canonical code-editing tools. */
22
+ export declare const DEFAULT_COORDINATOR_RESTRICT: ToolRestriction;
23
+ /** Config governing one coordinator agent's mode activation. */
24
+ export interface CoordinatorConfig {
25
+ /**
26
+ * Activate coordinator mode. Defaults to the `DSH_COORDINATOR_MODE` env flag
27
+ * (`1`, `true`, or `yes`), so a deployment toggles it without config edits.
28
+ */
29
+ readonly enabled?: boolean;
30
+ /**
31
+ * The tool visibility mask applied to the coordinator agent's scope on
32
+ * activation. Deployment-chosen write-tool names go in `deny`; a curated
33
+ * `allow` list narrows to a fixed set instead. Defaults to
34
+ * {@link DEFAULT_COORDINATOR_RESTRICT}.
35
+ */
36
+ readonly restrict?: ToolRestriction;
37
+ /** Prompt order of the coordinator section (default 110). */
38
+ readonly sectionOrder?: number;
39
+ }
40
+ /**
41
+ * Resolve whether coordinator mode is active for this configuration.
42
+ * @param config - resolved deployment config.
43
+ * @returns whether to activate coordinator mode on this agent's scope.
44
+ */
45
+ export declare function isCoordinatorActive(config: CoordinatorConfig): boolean;
46
+ /**
47
+ * The registrations installed when coordinator mode activates on one agent's
48
+ * scope. Each registration is scoped to that agent's context and owned by the
49
+ * returned disposer, so disabling the mode (fiber disposal) removes the prompt
50
+ * section, the scheduling tools, and the tool restriction together.
51
+ * @param agent - the coordinator agent whose scope receives the registrations.
52
+ * @param ctx - context carrying the tool registry and subagent service.
53
+ * @param config - resolved deployment config.
54
+ * @returns a disposer that restores the coordinator agent's full surface.
55
+ */
56
+ export declare function installCoordinatorMode(agent: Agent, ctx: Context, config?: CoordinatorConfig): () => void;
57
+ /**
58
+ * The coordinator-mode namespace plugin. Mount it in an agent's scope (as a
59
+ * preset composes into `agent.ctx`) to activate coordinator mode for that
60
+ * agent. When mode is inactive this is a no-op that registers nothing, so a
61
+ * preset may mount it unconditionally and Coordination engages only when
62
+ * enabled. Requires an agent scope when active, because tool restriction is an
63
+ * agent-scoped operation.
64
+ * @param ctx - context; must carry an `agent` when mode is active.
65
+ * @param config - deployment config, optionally overriding the env flag.
66
+ */
67
+ export declare function apply(ctx: Context, config?: CoordinatorConfig): () => void;
68
+ export declare const name = "coordinator";
69
+ export declare const inject: string[];
70
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAI7C,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,eAAe,CAAA;AAWhE,+EAA+E;AAC/E,eAAO,MAAM,4BAA4B,EAAE,eAA6C,CAAA;AAExF,gEAAgE;AAChE,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAA;IACnC,6DAA6D;IAC7D,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAC/B;AAOD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAKtE;AAuDD;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,OAAO,EACZ,MAAM,GAAE,iBAAsB,GAC7B,MAAM,IAAI,CAgNZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,iBAAsB,GAAG,MAAM,IAAI,CAS9E;AAED,eAAO,MAAM,IAAI,gBAAgB,CAAA;AACjC,eAAO,MAAM,MAAM,UAAmD,CAAA"}
package/lib/index.js ADDED
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Coordinator mode: an agent-scoped orchestration role over continuable
3
+ * subagents. Activation (Config `enabled` or the `DSH_COORDINATOR_MODE` env)
4
+ * restricts the agent's correspondence to delegation and read-only tools,
5
+ * installs a coordinator prompt section, and brings up the model-facing
6
+ * scheduling tools ({@link spawn_worker}, {@link send_to_worker},
7
+ * {@link worker_broadcast}, {@link worker_tasks}).
8
+ *
9
+ * Result return and completion waking are NOT reimplemented here: a worker
10
+ * reports through the existing `report` tool (`tool-subagent-report`),
11
+ * and the subagent manager already injects its `subagent-settled` notice into
12
+ * this coordinator's inbox as a waking message when a worker settles
13
+ * (`@deepseek-ai/dsh-subagent`'s continuation settlement delivery). This
14
+ * package adds the coordinator role and its naming/messaging surface around
15
+ * those seams and documents the reuse.
16
+ * @module @dsh-cc/coordinator
17
+ */
18
+ import { defineTool } from '@dsh-cc/tools';
19
+ import { COORDINATOR_SECTION_ORDER, COORDINATOR_SECTION_TEXT } from "./section.js";
20
+ /** Default tool visibility mask: deny the two canonical code-editing tools. */
21
+ export const DEFAULT_COORDINATOR_RESTRICT = { deny: ['write', 'edit'] };
22
+ const SPAWN_WORKER = 'spawn_worker';
23
+ const SEND_TO_WORKER = 'send_to_worker';
24
+ const WORKER_BROADCAST = 'worker_broadcast';
25
+ const WORKER_TASKS = 'worker_tasks';
26
+ /**
27
+ * Resolve whether coordinator mode is active for this configuration.
28
+ * @param config - resolved deployment config.
29
+ * @returns whether to activate coordinator mode on this agent's scope.
30
+ */
31
+ export function isCoordinatorActive(config) {
32
+ if (config.enabled !== undefined)
33
+ return config.enabled;
34
+ const env = process.env.DSH_COORDINATOR_MODE;
35
+ if (env === undefined)
36
+ return false;
37
+ return env === '1' || env === 'true' || env === 'yes';
38
+ }
39
+ /**
40
+ * The durable `name -> childId` and `childId -> name` worker bookkeeping for
41
+ * one coordinator agent. Owned solely by the installed mode; no worker outlives
42
+ * the containing CoordinatorInstall properly (each entry is disposable).
43
+ */
44
+ class WorkerRegistry {
45
+ nameToId = new Map();
46
+ idToName = new Map();
47
+ /** The coordinator-scoped spawn provider name. */
48
+ provider;
49
+ constructor(provider) {
50
+ this.provider = provider;
51
+ }
52
+ /** Record one named worker after its durable child id is known. */
53
+ track(name, childId) {
54
+ this.nameToId.set(name, childId);
55
+ this.idToName.set(childId, name);
56
+ }
57
+ /** Resolve one name to its durable child id, or `undefined` when unknown. */
58
+ resolve(name) {
59
+ return this.nameToId.get(name);
60
+ }
61
+ /**
62
+ * Resolve a worker reference that is either a registered name or one of the
63
+ * tracked durable child ids, or `undefined` when it matches neither.
64
+ */
65
+ resolveAny(reference) {
66
+ const byName = this.nameToId.get(reference);
67
+ if (byName !== undefined)
68
+ return byName;
69
+ for (const childId of this.idToName.keys()) {
70
+ if (String(childId) === reference)
71
+ return childId;
72
+ }
73
+ return undefined;
74
+ }
75
+ /** Drop a worker from the registry without touching its session. */
76
+ untrack(name) {
77
+ const childId = this.nameToId.get(name);
78
+ this.nameToId.delete(name);
79
+ if (childId !== undefined)
80
+ this.idToName.delete(childId);
81
+ }
82
+ /** Snapshot of the registered named workers in insertion order. */
83
+ entries() {
84
+ return [...this.nameToId].map(([name, childId]) => ({ name, childId }));
85
+ }
86
+ }
87
+ /**
88
+ * The registrations installed when coordinator mode activates on one agent's
89
+ * scope. Each registration is scoped to that agent's context and owned by the
90
+ * returned disposer, so disabling the mode (fiber disposal) removes the prompt
91
+ * section, the scheduling tools, and the tool restriction together.
92
+ * @param agent - the coordinator agent whose scope receives the registrations.
93
+ * @param ctx - context carrying the tool registry and subagent service.
94
+ * @param config - resolved deployment config.
95
+ * @returns a disposer that restores the coordinator agent's full surface.
96
+ */
97
+ export function installCoordinatorMode(agent, ctx, config = {}) {
98
+ const provider = ctx.subagents;
99
+ const registry = new WorkerRegistry('spawn');
100
+ const taskSource = (sendingId) => ({
101
+ kind: 'coordinator',
102
+ form: 'relay',
103
+ senderSessionId: sendingId,
104
+ });
105
+ // Scoped tool registration helper: each tool's execute resolves the live
106
+ // coordinator agent and its durable id for authority and attribution.
107
+ const disposals = [];
108
+ disposals.push(agent.ctx.systemPrompt.section({
109
+ name: 'coordinator:mode',
110
+ order: config.sectionOrder ?? COORDINATOR_SECTION_ORDER,
111
+ text: COORDINATOR_SECTION_TEXT,
112
+ }));
113
+ disposals.push(agent.ctx.tools.register(defineTool({
114
+ name: SPAWN_WORKER,
115
+ description: 'Start one named background worker to carry out a task in the shared workspace. '
116
+ + 'Name it for later send_to_worker and worker_tasks use. The worker reports its result through the '
117
+ + 'report tool, which arrives back here as a waking message; when it finishes you are told either way. '
118
+ + 'Delegation is the only way to change the workspace in coordinator mode.',
119
+ parameters: {
120
+ name: {
121
+ type: 'string',
122
+ required: true,
123
+ description: 'A stable name to address the worker by later; must be unique among your active workers.',
124
+ },
125
+ prompt: {
126
+ type: 'string',
127
+ required: true,
128
+ description: 'A self-contained task for the worker. It shares your workspace.',
129
+ },
130
+ },
131
+ output: {
132
+ schema: {
133
+ type: 'object',
134
+ additionalProperties: false,
135
+ properties: {
136
+ worker: { type: 'string', required: true },
137
+ worker_id: { type: 'string', required: true },
138
+ },
139
+ },
140
+ render: (args, value) => [{
141
+ type: 'text',
142
+ text: `worker ${args.name} started as ${value.worker_id}`,
143
+ }],
144
+ },
145
+ async execute(args, exec) {
146
+ const started = await provider.startContinuable({
147
+ provider: registry.provider,
148
+ label: args.name,
149
+ request: {
150
+ prompt: [{ type: 'text', text: args.prompt }],
151
+ parent: agent,
152
+ },
153
+ signal: exec.signal,
154
+ });
155
+ registry.track(args.name, started.childId);
156
+ return { worker: args.name, worker_id: started.childId };
157
+ },
158
+ })));
159
+ disposals.push(agent.ctx.tools.register(defineTool({
160
+ name: SEND_TO_WORKER,
161
+ description: 'Send a message to one of your named workers, continuing its conversation on the same turn queue. '
162
+ + 'Use it to redirect, extend, or clarify work already delegated. Returns only delivery confirmation; '
163
+ + 'the worker answers with a later report or its finish notice.',
164
+ parameters: {
165
+ worker: {
166
+ type: 'string',
167
+ required: true,
168
+ description: 'The name the worker was started with, or its durable worker id.',
169
+ },
170
+ message: {
171
+ type: 'string',
172
+ required: true,
173
+ description: 'The message to deliver as the worker\'s next turn.',
174
+ },
175
+ },
176
+ output: {
177
+ schema: {
178
+ type: 'object',
179
+ additionalProperties: false,
180
+ properties: {
181
+ worker: { type: 'string', required: true },
182
+ messageId: { type: 'string', required: true },
183
+ },
184
+ },
185
+ render: (args, value) => [{
186
+ type: 'text',
187
+ text: `message queued for worker ${args.worker} as message ${value.messageId}`,
188
+ }],
189
+ },
190
+ async execute(args, exec) {
191
+ const childId = registry.resolveAny(args.worker);
192
+ if (childId === undefined) {
193
+ throw new Error(`unknown worker "${args.worker}": start it with spawn_worker first`);
194
+ }
195
+ const messageId = await provider.followup(agent, childId, [{ type: 'text', text: args.message }], { source: taskSource(agent.id), signal: exec.signal });
196
+ return { worker: args.worker, messageId };
197
+ },
198
+ })));
199
+ disposals.push(agent.ctx.tools.register(defineTool({
200
+ name: WORKER_BROADCAST,
201
+ description: 'Send the same message to every one of your active named workers as their next turn. ',
202
+ parameters: {
203
+ message: {
204
+ type: 'string',
205
+ required: true,
206
+ description: 'The message to deliver to every active worker.',
207
+ },
208
+ },
209
+ output: {
210
+ schema: {
211
+ type: 'object',
212
+ additionalProperties: false,
213
+ properties: {
214
+ sent: { type: 'number', required: true },
215
+ },
216
+ },
217
+ render: (_args, value) => [{
218
+ type: 'text',
219
+ text: `broadcast delivered to ${value.sent} worker${value.sent === 1 ? '' : 's'}`,
220
+ }],
221
+ },
222
+ async execute(args, exec) {
223
+ const entries = registry.entries();
224
+ let sent = 0;
225
+ for (const entry of entries) {
226
+ await provider.followup(agent, entry.childId, [{ type: 'text', text: args.message }], { source: taskSource(agent.id), signal: exec.signal });
227
+ sent += 1;
228
+ }
229
+ return { sent };
230
+ },
231
+ })));
232
+ disposals.push(agent.ctx.tools.register(defineTool({
233
+ name: WORKER_TASKS,
234
+ description: 'List your active named workers and their durable ids, with a live status. '
235
+ + 'Use it to recall what you delegated, not to poll for results — you are told when one finishes. '
236
+ + 'One-shot children and workers you cannot read are omitted from the live view.',
237
+ parameters: {},
238
+ output: {
239
+ schema: {
240
+ type: 'array',
241
+ items: {
242
+ type: 'object',
243
+ additionalProperties: false,
244
+ properties: {
245
+ worker: { type: 'string', required: true },
246
+ worker_id: { type: 'string', required: true },
247
+ status: { type: 'string', required: true, enum: ['running', 'idle', 'ready'] },
248
+ },
249
+ },
250
+ },
251
+ render: (_args, value) => value.length === 0
252
+ ? [{ type: 'text', text: '(no active workers)' }]
253
+ : [{
254
+ type: 'text',
255
+ text: value.map(row => `${row.worker} [${row.status}] — ${row.worker_id}`).join('\n'),
256
+ }],
257
+ },
258
+ async execute(_args, _exec) {
259
+ const entries = registry.entries();
260
+ const rows = [];
261
+ for (const entry of entries) {
262
+ const live = ctx.agents.get(entry.childId);
263
+ const status = live === undefined ? 'ready' : (live.status === 'running' ? 'running' : 'idle');
264
+ rows.push({ worker: entry.name, worker_id: entry.childId, status });
265
+ }
266
+ return rows;
267
+ },
268
+ })));
269
+ disposals.push(agent.ctx.tools.restrict(config.restrict ?? DEFAULT_COORDINATOR_RESTRICT));
270
+ return () => {
271
+ const failures = [];
272
+ for (const dispose of disposals.splice(0).reverse()) {
273
+ try {
274
+ dispose();
275
+ }
276
+ catch (error) {
277
+ failures.push(error);
278
+ }
279
+ }
280
+ if (failures.length > 0) {
281
+ throw new AggregateError(failures, 'failed to revoke coordinator mode registrations');
282
+ }
283
+ };
284
+ }
285
+ /**
286
+ * The coordinator-mode namespace plugin. Mount it in an agent's scope (as a
287
+ * preset composes into `agent.ctx`) to activate coordinator mode for that
288
+ * agent. When mode is inactive this is a no-op that registers nothing, so a
289
+ * preset may mount it unconditionally and Coordination engages only when
290
+ * enabled. Requires an agent scope when active, because tool restriction is an
291
+ * agent-scoped operation.
292
+ * @param ctx - context; must carry an `agent` when mode is active.
293
+ * @param config - deployment config, optionally overriding the env flag.
294
+ */
295
+ export function apply(ctx, config = {}) {
296
+ if (!isCoordinatorActive(config))
297
+ return () => { };
298
+ const agent = ctx.get('agent');
299
+ if (agent === undefined) {
300
+ // A coordinator masked across every agent would be a deployment mistake;
301
+ // refusing keeps the misconfiguration visible at load time.
302
+ throw new Error('dsh-coordinator requires an agent-scoped context (agent.ctx) when coordinator mode is active');
303
+ }
304
+ return installCoordinatorMode(agent, ctx, config);
305
+ }
306
+ export const name = 'coordinator';
307
+ export const inject = ['tools', 'subagents', 'agents', 'systemPrompt'];
308
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;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,CAAC;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,aAAa,CAAA;AACjC,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAA"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Package-owned invariant companion for `@dsh-cc/coordinator`.
3
+ * @module @dsh-cc/coordinator/invariant
4
+ */
5
+ import type { Context } from '@deepseek-ai/cordis';
6
+ /** Cordis companion plugin name. */
7
+ export declare const name = "coordinator-invariant";
8
+ /** Service required before the companion can reserve package ownership. */
9
+ export declare const inject: string[];
10
+ /**
11
+ * Register this package's invariant companion.
12
+ * @param ctx - Cordis context carrying the invariant service.
13
+ * @returns the installed registration's disposer after setup succeeds.
14
+ */
15
+ export declare const apply: (ctx: Context) => Promise<() => void>;
16
+ //# sourceMappingURL=invariant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAKlD,oCAAoC;AACpC,eAAO,MAAM,IAAI,0BAA0B,CAAA;AAC3C,2EAA2E;AAC3E,eAAO,MAAM,MAAM,UAAiB,CAAA;AASpC;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAI,KAAK,OAAO,KAAG,OAAO,CAAC,MAAM,IAAI,CACU,CAAA"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Package-owned invariant companion for `@dsh-cc/coordinator`.
3
+ * @module @dsh-cc/coordinator/invariant
4
+ */
5
+ const PACKAGE_NAME = '@dsh-cc/coordinator';
6
+ /** Cordis companion plugin name. */
7
+ export const name = 'coordinator-invariant';
8
+ /** Service required before the companion can reserve package ownership. */
9
+ export const inject = ['invariants'];
10
+ /**
11
+ * No runtime invariant: this agent-scoped adapter has no independent lifecycle
12
+ * stream; restriction, prompt-section, and worker bookkeeping effects are
13
+ * owned by the subagent service it calls and are asserted directly by tests.
14
+ */
15
+ const install = () => { };
16
+ /**
17
+ * Register this package's invariant companion.
18
+ * @param ctx - Cordis context carrying the invariant service.
19
+ * @returns the installed registration's disposer after setup succeeds.
20
+ */
21
+ export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
22
+ /* jscpd:ignore-end */
23
+ //# sourceMappingURL=invariant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invariant.js","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,YAAY,GAAG,qBAAqB,CAAA;AAE1C,oCAAoC;AACpC,MAAM,CAAC,MAAM,IAAI,GAAG,uBAAuB,CAAA;AAC3C,2EAA2E;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,YAAY,CAAC,CAAA;AAEpC;;;;GAIG;AACH,MAAM,OAAO,GAAuB,GAAG,EAAE,GAAE,CAAC,CAAA;AAE5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAY,EAAuB,EAAE,CACzD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;AACjE,sBAAsB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The coordinator-mode system-prompt section: states the orchestration role, the
3
+ * available delegation tools, and the result-return protocol a coordinator agent
4
+ * runs under.
5
+ *
6
+ * @module @dsh-cc/coordinator/section
7
+ */
8
+ /** Prompt order: within the tool-guidance band, before per-tool sections. */
9
+ export declare const COORDINATOR_SECTION_ORDER = 110;
10
+ /**
11
+ * The fixed orchestration guidance installed when coordinator mode is active.
12
+ * It names the delegation surface a coordinator acts through and pins the
13
+ * result-return protocol to the subagent report seam, so a coordinator never
14
+ * mistakes direct code-editing for its job and knows how worker results come
15
+ * back.
16
+ */
17
+ export declare const COORDINATOR_SECTION_TEXT: string;
18
+ //# sourceMappingURL=section.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"section.d.ts","sourceRoot":"","sources":["../src/section.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,yBAAyB,MAAM,CAAA;AAE5C;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,QAO6B,CAAA"}
package/lib/section.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The coordinator-mode system-prompt section: states the orchestration role, the
3
+ * available delegation tools, and the result-return protocol a coordinator agent
4
+ * runs under.
5
+ *
6
+ * @module @dsh-cc/coordinator/section
7
+ */
8
+ /** Prompt order: within the tool-guidance band, before per-tool sections. */
9
+ export const COORDINATOR_SECTION_ORDER = 110;
10
+ /**
11
+ * The fixed orchestration guidance installed when coordinator mode is active.
12
+ * It names the delegation surface a coordinator acts through and pins the
13
+ * result-return protocol to the subagent report seam, so a coordinator never
14
+ * mistakes direct code-editing for its job and knows how worker results come
15
+ * back.
16
+ */
17
+ export const COORDINATOR_SECTION_TEXT = 'Coordinator mode: you orchestrate workers instead of doing the work yourself. '
18
+ + 'Delegate tasks with spawn_worker, redirect or extend one with send_to_worker, '
19
+ + 'reach all of them with worker_broadcast, and review them with worker_tasks. '
20
+ + 'Do not edit the workspace directly: assign that work to a worker. Each worker '
21
+ + 'reports its result through the report tool, which lands back in your conversation '
22
+ + 'as a waking message naming the worker; a worker that ends without reporting '
23
+ + 'still notifies you so you can decide whether to resume it.';
24
+ //# sourceMappingURL=section.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"section.js","sourceRoot":"","sources":["../src/section.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAA;AAE5C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,wBAAwB,GACjC,gFAAgF;MAC9E,gFAAgF;MAChF,8EAA8E;MAC9E,gFAAgF;MAChF,oFAAoF;MACpF,8EAA8E;MAC9E,4DAA4D,CAAA"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@dsh-cc/coordinator",
3
+ "description": "Coordinator-mode orchestration over continuable subagents for the DeepSeek Harness",
4
+ "version": "0.5.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/dsh-cc/dsh-cc.git",
8
+ "directory": "packages/subagent/coordinator"
9
+ },
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/index.d.ts",
14
+ "default": "./lib/index.js"
15
+ },
16
+ "./invariant": {
17
+ "types": "./lib/invariant.d.ts",
18
+ "default": "./lib/invariant.js"
19
+ },
20
+ "./src/*": "./src/*",
21
+ "./package.json": "./package.json"
22
+ },
23
+ "files": [
24
+ "lib"
25
+ ],
26
+ "license": "Apache-2.0",
27
+ "peerDependencies": {
28
+ "@deepseek-ai/dsh-agent": ">=0.1.1-rc.2",
29
+ "@deepseek-ai/dsh-invariants": ">=0.1.1-rc.2",
30
+ "@deepseek-ai/dsh-llm": ">=0.1.1-rc.2",
31
+ "@deepseek-ai/dsh-subagent": ">=0.1.1-rc.2",
32
+ "@deepseek-ai/dsh-system-prompt": ">=0.1.1-rc.2",
33
+ "@deepseek-ai/cordis": ">=0.1.1-rc.2",
34
+ "@dsh-cc/tools": "^0.5.0"
35
+ },
36
+ "devDependencies": {
37
+ "@deepseek-ai/dsh-agent": "link:../../../../deepseek-harness/packages/core/agent",
38
+ "@deepseek-ai/dsh-agent-loop": "link:../../../../deepseek-harness/packages/core/agent-loop",
39
+ "@deepseek-ai/dsh-agent-loop-testkit": "link:../../../../deepseek-harness/packages/test-support/agent-loop-testkit",
40
+ "@deepseek-ai/dsh-invariants": "link:../../../../deepseek-harness/packages/runtime-diagnostics/invariants",
41
+ "@deepseek-ai/dsh-llm": "link:../../../../deepseek-harness/packages/llm/llm",
42
+ "@deepseek-ai/dsh-session": "link:../../../../deepseek-harness/packages/core/session",
43
+ "@deepseek-ai/dsh-session-persistence": "link:../../../../deepseek-harness/packages/session/session-persistence",
44
+ "@deepseek-ai/dsh-session-persistence-jsonl": "link:../../../../deepseek-harness/packages/session/session-persistence-jsonl",
45
+ "@deepseek-ai/dsh-session-projection": "link:../../../../deepseek-harness/packages/session/session-projection",
46
+ "@deepseek-ai/dsh-subagent": "link:../../../../deepseek-harness/packages/subagent/subagent",
47
+ "@deepseek-ai/dsh-subagent-spawn-in-process": "link:../../../../deepseek-harness/packages/subagent/subagent-spawn-in-process",
48
+ "@deepseek-ai/dsh-system-prompt": "link:../../../../deepseek-harness/packages/core/system-prompt",
49
+ "@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
50
+ "@dsh-cc/tools": "^0.5.0",
51
+ "@dsh-cc/agent-loop-mock": "^0.1.0"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ }
56
+ }