dsh-parallel-tools-prompt 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,25 +6,28 @@
6
6
 
7
7
  ## 行为
8
8
 
9
- - 插件启用后,默认通过 `contextReminder` 向所有 Agent(包括子智能体)提供提醒,覆盖所有 preset 以及没有 preset 的会话;`presetIds` 与根 Agent 筛选不限制此通道。插件重载前已存活的子智能体也会在下一步骤获得提醒。
9
+ - 插件启用后,默认通过 `contextReminder` 向所有 Agent(包括子智能体)提供提醒,覆盖除 `contextExcludePresetIds`(默认 `[ptc]`)以外的所有 preset 以及没有 preset 的会话;`presetIds` 与根 Agent 筛选不限制此通道。PTC 只暴露 `run_code`,根级调用是独占的,合批应发生在单个程序内部,所以默认跳过;排除判断每一步都做,会话中途切换 preset 后会按新 preset 补发或跳过。插件重载前已存活的子智能体也会在下一步骤获得提醒。
10
10
  - `systemPromptSection` 是默认关闭的可选通道;只有此通道按符合条件的根 Agent 与 `presetIds` 筛选,默认目标为 `standard` 根 Agent,跳过子智能体及不在列表中的 preset。
11
- - 使用公开 Agent 生命周期、session projection 与 `systemPrompt.section()`,不替换 preset。系统提示词 section 固定名称 `parallel-tools:guidance`、order 1050、禁止插值;不注入时间戳、工具列表或每轮变化的数据。
11
+ - 使用公开 Agent 生命周期、session projection 与 `systemPrompt.section()`,不替换 preset。系统提示词 section 固定名称 `parallel-tools:guidance`、order 3200(排在所有单工具 section 1000–3000 与 MCP_SERVERS 3100 之后,不拆散工具说明、不先于它引用的 jobs/subagent 说明;在 TOOLS_SDK 5000 与输出/人设 section 之前)、禁止插值;不注入时间戳、工具列表或每轮变化的数据。
12
12
  - 同一 Agent 幂等注册;插件卸载与 Agent 释放都清理 section。插件重载时为仍存活的目标根 Agent 补挂已启用的 section,并覆盖仍存活 Agent 的提醒通道;源码更新建议重启宿主加载新模块。
13
- - 两个独立开关选择注入通道(默认只走 CONTEXT 提醒):`contextReminder`(默认 `true`)与 `systemPromptSection`(默认 `false`,设为 `true` 输出 `systemPrompt.section()` 的指引内容)。提醒通过 `agent/pre-step` 在下一步骤追加一条带独立 `source.kind: parallel-tools-scheduling` 的 CONTEXT 消息,写入会话历史并渲染为 CONTEXT 块,与宿主 `time-context` 同一机制;已持久化的 source 用于去重,包括继承历史中的提醒,每个 Agent 最多交付一次,已有或继承的提醒不会重复注入。两者可同时开启;同时关闭则插件不注入任何内容。提醒进入历史,卸载不会删除。这不是每轮重复提醒,也不保证长期遵循。
13
+ - 两个独立开关选择注入通道(默认只走 CONTEXT 提醒):`contextReminder`(默认 `true`)与 `systemPromptSection`(默认 `false`,设为 `true` 输出 `systemPrompt.section()` 的指引内容)。提醒通过 `agent/pre-step` 在下一步骤追加一条带独立 `source.kind: parallel-tools-scheduling` 的 CONTEXT 消息,写入会话历史并渲染为 CONTEXT 块,与宿主 `time-context` 同一机制;去重以模型当前可见的历史(session surface)为准,而不是全量事件日志:可见历史里已有(含继承来的)提醒就不再注入;上下文压缩或裁剪把提醒替换掉之后(surface `replaceGeneration` 变化),下一步骤补发一次,压缩保留了提醒则不补发。CONTEXT 文本带前缀 `Tool-call scheduling (applies to every remaining step of this session):`,说明它对整个会话持续有效。两者可同时开启;同时关闭则插件不注入任何内容。提醒进入历史,卸载不会删除。这不是每轮重复提醒,也不保证长期遵循。
14
14
  - 插件详情页(Plugins → 本插件)在描述与组件列表之间提供这两个开关的设置表单,开关即时写入当前 profile 的 patch。两个字段声明为 `.volatile()`,修改不重启插件:`contextReminder` 在下一步骤生效;系统提示词开关对修改之后重新组装提示词的会话生效(已建立的会话沿用旧提示词)。浏览器端由 `src/client` 经 `scripts/build-client.mjs` 构建为 `lib/client.js`,按宿主客户端模块格式封装;表单要求 profile 里条目 id 为 `parallel-tools-prompt`。
15
- - 两个注入通道共用同一条 DAG 调度规则:工具调用是节点,前置结果、执行条件、审批与共享状态顺序是边。围绕当前子目标识别已满足前置条件且参数已知的有用调用,在工具/输出限制内同轮发出互不依赖的调用;结果返回后重新判断就绪集合,不重复已完成或仍在运行的工作。独立证据可一起收集,即使后续决策需要汇总它们。
16
- - DAG 仅是内部调度模型,不要求画图、逐轮列计划或添加调度专用轮次;正常的计划、todo 和审批流程仍须遵守。只有一个就绪调用时就单次执行,不凑调用;读后写、共享状态冲突以及由前序结果决定是否/如何执行的操作仍保持顺序。
15
+ - 两个注入通道共用同一条规则:每次带工具调用的响应前,在心里列出参数已知的调用,逐条问“尚未返回的结果会不会改变我是否调用它、或传什么参数”;不会就本轮一起发出。只有其他后续调用都依赖这一个结果时,单调用才正确。
16
+ - 同一响应里的调用可能并发、顺序不定,所以结果决定下一步、需要审批、或触及同一状态(先读后改、改后运行、同一文件两次编辑)时保持顺序。不凑批:不把无关命令串进一条 shell 调用、不为短调用开子智能体、不做投机调用;不打印计划或添加调度专用轮次,正常的计划、todo 和审批流程照常遵守。
17
17
  - 同轮多个工具调用不代表真正同时执行;执行并发仍由DSH调度器决定。
18
18
 
19
19
  ## 提示词设计逻辑
20
20
 
21
- ### 当前规则:先发现动作,再判断依赖并合批
21
+ ### 当前规则:逐条就绪检验,单调用要有理由
22
22
 
23
- 当前两个注入通道共用 [prompt.ts](<src/prompt.ts>) 中的稳定规则,分发的 skill 描述与其完全一致。工具调用前先简短检查:还有哪些有用工作不必等待这些结果、现在就能做?再用 DAG 判断先后关系;它是内部模型,不要求模型输出一张图,也不会创建新的执行器:
23
+ 两个注入通道共用 [prompt.ts](<src/prompt.ts>) 中的 `BATCH_RULE`(约 1000 字符),分发的 skill 描述与其完全一致。设计要点:
24
24
 
25
- - **节点**是完成当前子目标有用的工具调用;**边**是必需的前序结果(required results)、执行条件(conditions)、审批(approvals)与共享状态顺序(state ordering),包括先读后改。只有真实前置要求才构成等待理由。
26
- - **就绪**意味着前置条件已满足、输入参数已知。将当前已知、已就绪、互不依赖且有用的调用在工具与输出限制内同轮发出;拿到结果后重新判断。仅有一个就绪调用时,单调用完全正确,不为凑批量而发明工作。
27
- - **收集证据与汇总判断分开**:例如独立读取规则、包元数据与 Git 状态,可以一起做;最终发布决策需要三者,不等于这三项读取彼此依赖。相反,`test → failure → fix → retest` 中修复依赖失败信息、复测依赖修复,是合理串行,不应为了提高批量率打断这条调试链。
25
+ - **一个能逐条回答的判据**:对每个参数已知的调用问“尚未返回的结果会不会改变我是否调用它、或传什么参数”。比抽象的“依赖 DAG”更容易在每一步执行,也不要求输出任何图或计划。
26
+ - **单调用要有理由**:只有其他后续调用都依赖这一个结果时,单调用才正确。把默认从“能合批就合批”变成“不合批要说得出原因”,但 `test → read failure → fix → retest` 这样的真实依赖链仍然合法。
27
+ - **点名常被漏掉的合批**:任务开头的读取与搜索;一个结果同时指向的多个文件或符号(例如栈追踪里的每一帧);内容已确定后对不同文件的编辑;typecheck、lint、test 等只读检查。
28
+ - **用执行语义解释等待**:“同一响应里的调用可能并发、顺序不定”,所以结果决定下一步、需要审批、或触及同一状态(先读后改、改后运行、同一文件两次编辑)时要分开。
29
+ - **防凑批只禁真正的作弊**:不把无关命令串进一条 shell 调用、不为短调用开子智能体、不做投机调用;`build && test` 这类本身有依赖的串联不受影响。
30
+ - **删掉不改变行为的免责说明**:并发与收益的边界写在本文档里,不占提示词篇幅。
28
31
  - **合批与执行并发分开**:同一响应携带多个调用,目标是减少本可避免的模型往返;工具是否真正同时运行仍取决于 runtime/宿主调度、安全限制与资源情况。合批不保证延迟、tokens 或费用下降。
29
32
  - **后台重叠与同轮合批也分开**:后台任务运行期间,不依赖其结果、不会干扰其共享状态的独立工作可以继续。即使前后每轮都只有一个工具调用,实际工作仍可能重叠;应遵守宿主的任务跟踪、结果收集与禁止重复执行规则,而不是重复启动正在运行的工作。
30
33
 
@@ -40,18 +43,20 @@
40
43
 
41
44
  ### 本次改进(当前源码已启用,效果未证实)
42
45
 
43
- 本次尚未发布的 `0.2.1-rc.7` 不再仅含文档变更:已将候选措辞落实到两个运行提示通道共用的规则及 skill 描述/正文,**没有改变注入频率、默认开关、生命周期或宿主调度行为**。这是当前源码的默认规则文本,不表示已发布到 npm、已更新运行中的宿主,或已证实有效;加载与历史去重边界仍按上文行为执行。
46
+ 当前源码(`0.2.5`,尚未发布)的改动,不表示已更新运行中的宿主或已证实有效:
44
47
 
45
- - **动作先行,再检查 DAG**:以 “Before calling tools, briefly check what other useful work can run now without these results.” 开头,先寻找不需要等待当前结果的有用工作,再按结果、条件、审批与状态依赖筛选。它针对可能的动作发现不足,不能承诺找到更多机会。
46
- - **明确后台非干扰边界**:后台运行时继续不依赖其结果、不干扰其状态的独立工作;遵守宿主任务跟踪与结果收集规则,不忙轮询、不重复运行中或已完成的调用/委派,依赖结果的步骤仍等待。
47
- - **精简而非叠加长规则**:两个通道与 skill 描述共用完全相同的核心文本(描述不超过 1024 字符),正文展开例子;正面允许真实依赖链与单调用,保留审批、先读后改、共享状态和不凑工作等边界。
48
- - **不靠加压制造指标**:不增加提醒注入频率,不设最低工具数量,不打印 DAG,不添加调度专用轮次,不通过 shell 包装或 delegation 模拟合批;正常 plan/todo/approval 流程仍保留。收益仍须受控比较验证,实际并发由 runtime 决定。
48
+ - **规则重写**:用上文的逐条就绪检验替换原来的“先发现动作,再查依赖 DAG”措辞;两个通道和 skill 描述同步更新,skill 正文改为“合批 / 等待 / 不凑批 / 后台”四节,并给出正反例。
49
+ - **CONTEXT 前缀**:系统提示词通道仍用 `Tool-call scheduling:`;CONTEXT 通道改为 `Tool-call scheduling (applies to every remaining step of this session):`,因为它只交付一次,需要说明对后续所有步骤有效。
50
+ - **压缩后补发**:去重改看模型当前可见的 surface,而不是全量事件日志。原先压缩删掉提醒后不会补发,模型从此看不到规则;现在会在下一步骤补发一次。
51
+ - **默认跳过 PTC**:新增 `contextExcludePresetIds`(默认 `[ptc]`)。
52
+ - **section 排序**:order 从 1050 改为 3200,挪到全部工具说明之后。
53
+ - **未改动**:注入频率、默认开关、宿主调度行为。收益仍需受控对比验证,实际并发由 runtime 决定。
49
54
 
50
55
  ## 版本、依赖与发布
51
56
 
52
- 插件版本 `0.2.1-rc.7` 跟随 DSH 的 `0.2.1` 版本线,RC 序号独立递增,不等于宿主 RC 序号。最低宿主要求 `>=0.2.1-rc.3`,Node.js `>=24.9.0`。开发锁文件以 RC.5 为基线;RC.3 的相关接口已做源码比对,完整插件测试本次运行在 RC.5 依赖上,不冒充两套运行验收。
57
+ 插件版本 `0.2.5` 独立编号,不等于宿主版本。最低宿主要求 `>=0.2.3-alpha.2`,Node.js `>=24.9.0`。插件测试运行在 `0.2.3-alpha.2` 宿主依赖上。
53
58
 
54
- 宿主库以 peerDependencies 声明,同时列入 devDependencies 供构建测试:Cordis `4.0.5`、Schemastery `3.18.5`、DSH agent/llm/preset-registry/session-projection/system-prompt 使用 `^0.2.1-rc.3`。不将宿主服务打包为普通运行依赖,避免重复服务身份。semver caret 不跨 `0.3`,也不自动接纳不同版本号的预发布版本。
59
+ 宿主库以 peerDependencies 声明,同时列入 devDependencies 供构建测试:Cordis `4.2.0-alpha.1`、Schemastery `3.20.0-alpha.1`、DSH agent/llm/agent-preset-registry/session-projection/system-prompt 均为 `0.2.3-alpha.2`。不将宿主服务打包为普通运行依赖,避免重复服务身份。peer 依赖是精确版本,宿主升级后需要同步调整。
55
60
 
56
61
  建议使用 `npm ci` 配合 npm lock,避免交替更新两种锁文件。包发布白名单包含构建产物、bundle patch、README、许可证与分析脚本,不包含测试、原始会话或调试捕获。`prepack` 自动构建;预发布默认 `next` tag。确认版本未占用后由维护者执行 `npm publish`;已发布版本不能覆盖。
57
62
 
@@ -80,13 +85,14 @@ npm pack --dry-run
80
85
  ```yaml
81
86
  enabled: true
82
87
  systemPromptSection: false # 默认;设为 true 选择启用系统提示词通道
83
- contextReminder: true # 默认;所有 Agent(含子智能体),不限 preset
88
+ contextReminder: true # 默认;所有 Agent(含子智能体),排除下一项列出的 preset
89
+ contextExcludePresetIds: [ptc] # 默认;不接收 CONTEXT 提醒的精确 preset ID,最多 32 项
84
90
  presetIds: [standard] # 默认;只筛选系统提示词通道的目标根 Agent
85
91
  ```
86
92
 
87
93
  **注意:profile 的 `cordis.patch.yml` 覆盖本插件时,`config` 是整体替换、不与 bundle 默认值深合并。** 覆盖项必须写全需要的字段,尤其是 `enabled: true`;否则 `enabled` 回落为默认 `false`,插件静默不注入。省略的通道字段使用上述 schema 默认值;自定义系统提示词目标时也要保留所需 `presetIds`。已有 profile 中显式设置的值不会自动迁移:例如原来的 `contextReminder: false` 或 `systemPromptSection: true` 仍保留,需通过设置 UI 或手动修改 profile 才会改变。验收方式:系统提示词通道看新会话 `system/message` 中是否出现 `Tool-call scheduling:`;CONTEXT 通道看会话里是否出现 `source.kind` 为 `parallel-tools-scheduling` 的消息。
88
94
 
89
- `presetIds` 是精确 ID 列表,不是正则,且只控制选择启用后的系统提示词通道,不影响 CONTEXT 提醒。系统提示词的自定义目标仅适用于原生工具调用 preset;不要把 PTC 加入该列表,以免对专用执行模式施加额外系统指导。默认 CONTEXT 提醒仍覆盖 PTC、minimal、creator 等所有 preset、无 preset 会话及子智能体。根会话 fork 可以保留历史 parentSession,不会仅因此被当作子智能体;若继承了已有提醒,则不会再注入。
95
+ `presetIds` 是精确 ID 列表,不是正则,且只控制选择启用后的系统提示词通道,不影响 CONTEXT 提醒。系统提示词的自定义目标仅适用于原生工具调用 preset;不要把 PTC 加入该列表,以免对专用执行模式施加额外系统指导。CONTEXT 提醒由 `contextExcludePresetIds` 单独控制:默认跳过 PTC,覆盖 minimal、creator 等其他 preset、无 preset 会话及子智能体;同样是精确 ID 列表,设为 `[]` 则 PTC 也会收到提醒。根会话 fork 可以保留历史 parentSession,不会仅因此被当作子智能体;若继承了已有提醒,则不会再注入。
90
96
 
91
97
  卸载会释放注册;已有模型历史中的旧指令不会被改写或删除。若宿主需要重新投影系统提示,生效边界由宿主管理;稳妥方式是重启后继续原会话。首次安装可能改变system前缀并影响一次缓存复用;不能保证零缓存影响。
92
98
 
package/lib/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
22
22
  enabled: z<boolean, boolean, "defined">;
23
23
  systemPromptSection: z<boolean, boolean, "volatile-defined">;
24
24
  contextReminder: z<boolean, boolean, "volatile-defined">;
25
+ contextExcludePresetIds: z<string[], string[], "defined">;
25
26
  presetIds: z<string[], string[], "defined">;
26
27
  }>>, Schemastery.ObjectT<NoInfer<{
27
28
  debugEnabled: z<boolean, boolean, "defined">;
@@ -31,6 +32,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
31
32
  enabled: z<boolean, boolean, "defined">;
32
33
  systemPromptSection: z<boolean, boolean, "volatile-defined">;
33
34
  contextReminder: z<boolean, boolean, "volatile-defined">;
35
+ contextExcludePresetIds: z<string[], string[], "defined">;
34
36
  presetIds: z<string[], string[], "defined">;
35
37
  }>>, "plain">;
36
38
  export type Config = ReturnType<typeof Config>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAKnD,OAAO,CAAC,MAAM,0BAA0B,CAAC;AAKzC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/G,eAAO,MAAM,IAAI,0BAA0B,CAAC;AAC5C,eAAO,MAAM,MAAM,UAA6C,CAAC;AAEjE,qGAAqG;AACrG,eAAO,MAAM,mBAAmB,8BAA8B,CAAC;AAE/D,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,gBAAgB;QACxB,CAAC,mBAAmB,CAAC,EAAE;YAAE,IAAI,EAAE,OAAO,mBAAmB,CAAC;YAAC,IAAI,EAAE,QAAQ,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;KAC9F;CACF;AASD,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;aAkBjB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC;AA8E/C,8EAA8E;AAC9E,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAwDxD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAKnD,OAAO,CAAC,MAAM,0BAA0B,CAAC;AAKzC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/G,eAAO,MAAM,IAAI,0BAA0B,CAAC;AAC5C,eAAO,MAAM,MAAM,UAA6C,CAAC;AAEjE,qGAAqG;AACrG,eAAO,MAAM,mBAAmB,8BAA8B,CAAC;AAE/D,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,gBAAgB;QACxB,CAAC,mBAAmB,CAAC,EAAE;YAAE,IAAI,EAAE,OAAO,mBAAmB,CAAC;YAAC,IAAI,EAAE,QAAQ,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC;KAC9F;CACF;AAuCD,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;aAsBjB,CAAC;AAEH,MAAM,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC;AA8E/C,8EAA8E;AAC9E,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAsExD"}
package/lib/index.js CHANGED
@@ -7,10 +7,33 @@ export const name = 'parallel-tools-prompt';
7
7
  export const inject = ['agents', 'systemPrompt', 'agentPresets'];
8
8
  /** Source kind of the reminder message; the host renders unknown context kinds as CONTEXT blocks. */
9
9
  export const CONTEXT_SOURCE_KIND = 'parallel-tools-scheduling';
10
- /** True when the session transcript already carries our sourced reminder. */
10
+ function isReminderEvent(event) {
11
+ return event?.type === 'user/message'
12
+ && event.data?.source?.kind === CONTEXT_SOURCE_KIND;
13
+ }
14
+ /**
15
+ * True when the reminder is still model-visible. Reads the session surface
16
+ * (the projected history after compaction/pruning replacements), like the
17
+ * host's own agent-instructions plugin; the raw event log would still contain
18
+ * a reminder that compaction has already replaced with a summary. Hosts
19
+ * without a surface fall back to the full log.
20
+ */
11
21
  function hasReminder(agent) {
12
- return agent.session.snapshotEvents().some(event => event.type === 'user/message'
13
- && event.data?.source?.kind === CONTEXT_SOURCE_KIND);
22
+ const session = agent.session;
23
+ const { surface, eventAt } = session;
24
+ if (surface !== undefined && typeof eventAt === 'function') {
25
+ const nodes = surface.nodes;
26
+ for (let i = nodes.length - 1; i >= 0; i--) {
27
+ if (isReminderEvent(eventAt.call(session, nodes[i])))
28
+ return true;
29
+ }
30
+ return false;
31
+ }
32
+ return session.snapshotEvents().some(isReminderEvent);
33
+ }
34
+ /** Surface replacement counter; changes only on compaction/prune replacements. */
35
+ function surfaceGeneration(agent) {
36
+ return agent.session.surface?.replaceGeneration ?? 0;
14
37
  }
15
38
  export const Config = z.object({
16
39
  debugEnabled: z.boolean().default(false).description('Capture normalized LLM system prompts locally, only with an explicit session and enable sentinel. Sensitive: disable after diagnosis.'),
@@ -20,6 +43,8 @@ export const Config = z.object({
20
43
  enabled: z.boolean().default(false).description('Enable static tool-call scheduling guidance. The bundle explicitly opts in; direct plugin use is disabled by default.'),
21
44
  systemPromptSection: z.boolean().default(false).volatile().description('Inject static scheduling guidance as a system-prompt section for eligible roots (default false). May be combined with contextReminder; with both off the plugin injects nothing.'),
22
45
  contextReminder: z.boolean().default(true).volatile().description('Inject a one-time scheduling reminder as a CONTEXT message for all agents, including subagents and all presets, at the next step boundary (default true). Persists in the session transcript; never duplicated across reloads. Independent of systemPromptSection and presetIds.'),
46
+ contextExcludePresetIds: z.array(z.string().pattern(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/))
47
+ .max(32).default(['ptc']).description('Exact preset IDs that never receive the CONTEXT reminder (default [ptc]: PTC exposes only run_code, whose root calls are exclusive; batching there belongs inside one program). Agents without a preset are always reminded.'),
23
48
  presetIds: z.array(z.string().pattern(/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/))
24
49
  .max(32).default(['standard']).description('Exact preset IDs for the system-prompt channel only. Root agents only; use native-tool presets, not PTC. An empty list disables system-prompt targets, not context reminders.'),
25
50
  });
@@ -121,15 +146,31 @@ export function apply(ctx, config) {
121
146
  // downstream listeners accept the step, append one sourced message to the
122
147
  // step's messages; the host persists it and renders it as a CONTEXT block.
123
148
  {
124
- const delivered = new WeakSet();
149
+ // Per agent: the surface replacement generation at which the reminder was
150
+ // last confirmed visible (or delivered). Unchanged generation means no
151
+ // compaction since, so the reminder is still visible and nothing is
152
+ // re-scanned. After a compaction the surface is checked once more and the
153
+ // reminder is re-delivered only if the replacement removed it.
154
+ const checked = new WeakMap();
155
+ const excluded = new Set(config.contextExcludePresetIds);
125
156
  ctx.on('agent/pre-step', async ({ agent, signal }, next) => {
126
157
  const decision = await next();
127
158
  if (decision.kind === 'reject' || signal.aborted)
128
159
  return decision;
129
- if (!flag(config.contextReminder) || delivered.has(agent))
160
+ if (!flag(config.contextReminder))
161
+ return decision;
162
+ // Checked every step (cheap), before the generation cache, so a session
163
+ // that later switches away from an excluded preset still gets reminded.
164
+ if (excluded.size > 0) {
165
+ const preset = projectedPreset(ctx, agent.session) ?? agent.session.header.agentPreset;
166
+ if (preset != null && excluded.has(preset))
167
+ return decision;
168
+ }
169
+ const generation = surfaceGeneration(agent);
170
+ if (checked.get(agent) === generation)
130
171
  return decision;
172
+ checked.set(agent, generation);
131
173
  const present = hasReminder(agent) || decision.messages.some(m => m.source.kind === CONTEXT_SOURCE_KIND);
132
- delivered.add(agent);
133
174
  if (present)
134
175
  return decision;
135
176
  return {
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"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,CAAC"}
package/lib/prompt.d.ts CHANGED
@@ -1,10 +1,18 @@
1
1
  /** Stable prompt bytes: no runtime interpolation, tool inventory, or per-turn state. */
2
2
  export declare const SECTION_NAME = "parallel-tools:guidance";
3
- export declare const SECTION_ORDER = 1050;
3
+ /**
4
+ * After every per-tool section (TOOL_* 1000–3000, MCP_SERVERS 3100) so the
5
+ * guidance neither splits the tool descriptions nor precedes the jobs/subagent
6
+ * sections it refers to; before TOOLS_SDK (5000) and output/persona sections.
7
+ */
8
+ export declare const SECTION_ORDER = 3200;
4
9
  /** Shared by both injection channels and the distributed skill description. */
5
- export declare const BATCH_RULE = "Before calling tools, briefly check what other useful work can run now without these results. Use an internal dependency DAG for the current subgoal: batch all ready, independent tool calls together in one response, within tool/output limits, with known inputs and prerequisites met. Gather independent evidence together even if later combined. Wait for results that decide whether or how to act, approvals, or shared-state ordering (including read-before-edit). While background work runs, continue work independent of its results and non-interfering with its state. After results, reassess; never repeat running/completed work. Real dependency chains and single calls are valid; never invent work. Use tools as intended, not shell wrappers or delegation to simulate batching. No printed DAG or extra scheduling turns; preserve required plan, todo, and approval workflows. Aim to reduce model round trips; actual concurrency depends on runtime.";
10
+ export declare const BATCH_RULE = "Before each tool-using response, silently list every call whose arguments you already know and send them all together. Per call, ask: could a pending result change whether I make it or what I pass? If not, include it now. A lone call is right only when every other next call depends on its result. Typical batches: a task's opening reads and searches; every file or symbol one result points to (e.g. each frame of a stack trace); edits to different files once their content is known; read-only checks like typecheck, lint and tests. Calls in one response may run concurrently and in any order, so wait when a result decides the next call, approval is needed, or calls touch the same state (read before edit, edit before run, two edits to one file). Don't fake batches: no unrelated commands chained into one shell call, no subagents for quick calls, no speculative calls. While background work runs, do unrelated work; never poll or repeat running or finished calls. Never skip required plan, todo or approval steps.";
6
11
  /** The "Tool-call scheduling:" prefix is the verification marker searched for in system/message. */
7
- export declare const PARALLEL_TOOLS_PROMPT = "Tool-call scheduling: Before calling tools, briefly check what other useful work can run now without these results. Use an internal dependency DAG for the current subgoal: batch all ready, independent tool calls together in one response, within tool/output limits, with known inputs and prerequisites met. Gather independent evidence together even if later combined. Wait for results that decide whether or how to act, approvals, or shared-state ordering (including read-before-edit). While background work runs, continue work independent of its results and non-interfering with its state. After results, reassess; never repeat running/completed work. Real dependency chains and single calls are valid; never invent work. Use tools as intended, not shell wrappers or delegation to simulate batching. No printed DAG or extra scheduling turns; preserve required plan, todo, and approval workflows. Aim to reduce model round trips; actual concurrency depends on runtime.";
8
- /** Same rule in the history-backed context channel, without a second policy to maintain. */
9
- export declare const CONTEXT_REMINDER = "Before calling tools, briefly check what other useful work can run now without these results. Use an internal dependency DAG for the current subgoal: batch all ready, independent tool calls together in one response, within tool/output limits, with known inputs and prerequisites met. Gather independent evidence together even if later combined. Wait for results that decide whether or how to act, approvals, or shared-state ordering (including read-before-edit). While background work runs, continue work independent of its results and non-interfering with its state. After results, reassess; never repeat running/completed work. Real dependency chains and single calls are valid; never invent work. Use tools as intended, not shell wrappers or delegation to simulate batching. No printed DAG or extra scheduling turns; preserve required plan, todo, and approval workflows. Aim to reduce model round trips; actual concurrency depends on runtime.";
12
+ export declare const PARALLEL_TOOLS_PROMPT = "Tool-call scheduling: Before each tool-using response, silently list every call whose arguments you already know and send them all together. Per call, ask: could a pending result change whether I make it or what I pass? If not, include it now. A lone call is right only when every other next call depends on its result. Typical batches: a task's opening reads and searches; every file or symbol one result points to (e.g. each frame of a stack trace); edits to different files once their content is known; read-only checks like typecheck, lint and tests. Calls in one response may run concurrently and in any order, so wait when a result decides the next call, approval is needed, or calls touch the same state (read before edit, edit before run, two edits to one file). Don't fake batches: no unrelated commands chained into one shell call, no subagents for quick calls, no speculative calls. While background work runs, do unrelated work; never poll or repeat running or finished calls. Never skip required plan, todo or approval steps.";
13
+ /**
14
+ * Same rule in the history-backed context channel. Delivered once per visible
15
+ * history, so the prefix states it persists rather than describing one step.
16
+ */
17
+ export declare const CONTEXT_REMINDER = "Tool-call scheduling (applies to every remaining step of this session): Before each tool-using response, silently list every call whose arguments you already know and send them all together. Per call, ask: could a pending result change whether I make it or what I pass? If not, include it now. A lone call is right only when every other next call depends on its result. Typical batches: a task's opening reads and searches; every file or symbol one result points to (e.g. each frame of a stack trace); edits to different files once their content is known; read-only checks like typecheck, lint and tests. Calls in one response may run concurrently and in any order, so wait when a result decides the next call, approval is needed, or calls touch the same state (read before edit, edit before run, two edits to one file). Don't fake batches: no unrelated commands chained into one shell call, no subagents for quick calls, no speculative calls. While background work runs, do unrelated work; never poll or repeat running or finished calls. Never skip required plan, todo or approval steps.";
10
18
  //# sourceMappingURL=prompt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,eAAO,MAAM,YAAY,4BAA4B,CAAC;AACtD,eAAO,MAAM,aAAa,OAAO,CAAC;AAElC,+EAA+E;AAC/E,eAAO,MAAM,UAAU,s7BAAs7B,CAAC;AAE98B,oGAAoG;AACpG,eAAO,MAAM,qBAAqB,48BAAwC,CAAC;AAE3E,4FAA4F;AAC5F,eAAO,MAAM,gBAAgB,s7BAAa,CAAC"}
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,eAAO,MAAM,YAAY,4BAA4B,CAAC;AACtD;;;;GAIG;AACH,eAAO,MAAM,aAAa,OAAO,CAAC;AAElC,+EAA+E;AAC/E,eAAO,MAAM,UAAU,6/BAA6/B,CAAC;AAErhC,oGAAoG;AACpG,eAAO,MAAM,qBAAqB,mhCAAwC,CAAC;AAE3E;;;GAGG;AACH,eAAO,MAAM,gBAAgB,qkCAA0F,CAAC"}
package/lib/prompt.js CHANGED
@@ -1,10 +1,18 @@
1
1
  /** Stable prompt bytes: no runtime interpolation, tool inventory, or per-turn state. */
2
2
  export const SECTION_NAME = 'parallel-tools:guidance';
3
- export const SECTION_ORDER = 1050;
3
+ /**
4
+ * After every per-tool section (TOOL_* 1000–3000, MCP_SERVERS 3100) so the
5
+ * guidance neither splits the tool descriptions nor precedes the jobs/subagent
6
+ * sections it refers to; before TOOLS_SDK (5000) and output/persona sections.
7
+ */
8
+ export const SECTION_ORDER = 3200;
4
9
  /** Shared by both injection channels and the distributed skill description. */
5
- export const BATCH_RULE = `Before calling tools, briefly check what other useful work can run now without these results. Use an internal dependency DAG for the current subgoal: batch all ready, independent tool calls together in one response, within tool/output limits, with known inputs and prerequisites met. Gather independent evidence together even if later combined. Wait for results that decide whether or how to act, approvals, or shared-state ordering (including read-before-edit). While background work runs, continue work independent of its results and non-interfering with its state. After results, reassess; never repeat running/completed work. Real dependency chains and single calls are valid; never invent work. Use tools as intended, not shell wrappers or delegation to simulate batching. No printed DAG or extra scheduling turns; preserve required plan, todo, and approval workflows. Aim to reduce model round trips; actual concurrency depends on runtime.`;
10
+ export const BATCH_RULE = `Before each tool-using response, silently list every call whose arguments you already know and send them all together. Per call, ask: could a pending result change whether I make it or what I pass? If not, include it now. A lone call is right only when every other next call depends on its result. Typical batches: a task's opening reads and searches; every file or symbol one result points to (e.g. each frame of a stack trace); edits to different files once their content is known; read-only checks like typecheck, lint and tests. Calls in one response may run concurrently and in any order, so wait when a result decides the next call, approval is needed, or calls touch the same state (read before edit, edit before run, two edits to one file). Don't fake batches: no unrelated commands chained into one shell call, no subagents for quick calls, no speculative calls. While background work runs, do unrelated work; never poll or repeat running or finished calls. Never skip required plan, todo or approval steps.`;
6
11
  /** The "Tool-call scheduling:" prefix is the verification marker searched for in system/message. */
7
12
  export const PARALLEL_TOOLS_PROMPT = `Tool-call scheduling: ${BATCH_RULE}`;
8
- /** Same rule in the history-backed context channel, without a second policy to maintain. */
9
- export const CONTEXT_REMINDER = BATCH_RULE;
13
+ /**
14
+ * Same rule in the history-backed context channel. Delivered once per visible
15
+ * history, so the prefix states it persists rather than describing one step.
16
+ */
17
+ export const CONTEXT_REMINDER = `Tool-call scheduling (applies to every remaining step of this session): ${BATCH_RULE}`;
10
18
  //# sourceMappingURL=prompt.js.map
package/lib/prompt.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,CAAC,MAAM,YAAY,GAAG,yBAAyB,CAAC;AACtD,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AAElC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,UAAU,GAAG,m7BAAm7B,CAAC;AAE98B,oGAAoG;AACpG,MAAM,CAAC,MAAM,qBAAqB,GAAG,yBAAyB,UAAU,EAAE,CAAC;AAE3E,4FAA4F;AAC5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC"}
1
+ {"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,CAAC,MAAM,YAAY,GAAG,yBAAyB,CAAC;AACtD;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AAElC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,UAAU,GAAG,0/BAA0/B,CAAC;AAErhC,oGAAoG;AACpG,MAAM,CAAC,MAAM,qBAAqB,GAAG,yBAAyB,UAAU,EAAE,CAAC;AAE3E;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,2EAA2E,UAAU,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-parallel-tools-prompt",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Plan ready tool-call batches to reduce model round trips in DeepSeek Harness",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,17 +1,43 @@
1
1
  ---
2
2
  name: batch-tool-calls
3
- description: "Before calling tools, briefly check what other useful work can run now without these results. Use an internal dependency DAG for the current subgoal: batch all ready, independent tool calls together in one response, within tool/output limits, with known inputs and prerequisites met. Gather independent evidence together even if later combined. Wait for results that decide whether or how to act, approvals, or shared-state ordering (including read-before-edit). While background work runs, continue work independent of its results and non-interfering with its state. After results, reassess; never repeat running/completed work. Real dependency chains and single calls are valid; never invent work. Use tools as intended, not shell wrappers or delegation to simulate batching. No printed DAG or extra scheduling turns; preserve required plan, todo, and approval workflows. Aim to reduce model round trips; actual concurrency depends on runtime."
3
+ description: "Before each tool-using response, silently list every call whose arguments you already know and send them all together. Per call, ask: could a pending result change whether I make it or what I pass? If not, include it now. A lone call is right only when every other next call depends on its result. Typical batches: a task's opening reads and searches; every file or symbol one result points to (e.g. each frame of a stack trace); edits to different files once their content is known; read-only checks like typecheck, lint and tests. Calls in one response may run concurrently and in any order, so wait when a result decides the next call, approval is needed, or calls touch the same state (read before edit, edit before run, two edits to one file). Don't fake batches: no unrelated commands chained into one shell call, no subagents for quick calls, no speculative calls. While background work runs, do unrelated work; never poll or repeat running or finished calls. Never skip required plan, todo or approval steps."
4
4
  ---
5
5
 
6
6
  # Batch ready tool calls
7
7
 
8
- Before calling tools, briefly check what other useful work can run now without these results. Then use an internal dependency DAG for the current subgoal: calls are nodes; required results, conditions, approvals, and shared-state ordering are edges.
8
+ ## The test
9
9
 
10
- 1. Batch all useful, ready, independent calls in one response when inputs are known and prerequisites are met, within tool/output limits. Collect independent evidence together even if a later decision needs it all.
11
- 2. Wait when a result determines whether or how to act, approval is pending, or shared-state ordering requires it (including read-before-edit). Real dependency chains and single calls are valid; never invent work to fill a batch.
12
- 3. While background work runs, continue useful work that neither needs its results nor interferes with its state. Follow the host's job tracking and result collection rules; do not busy-poll or duplicate running/completed calls or delegations. After results arrive, reassess what is ready.
13
- 4. Use tools as intended, not shell wrappers or delegation solely to simulate batching. Do not print a DAG or add scheduling-only turns; required plan, todo, and approval workflows still apply.
10
+ Before each tool-using response, silently list every call whose arguments you already know. For each one ask: **could a pending result change whether I make this call, or what I pass to it?** If not, it is ready: send it in this response. Do not print the list or spend a turn on scheduling.
14
11
 
15
- For example, read independent files A and B together, then make the decision that needs both. If a search must discover B's path, search first rather than guessing it. A test failure must be read before choosing a fix, and the fix must finish before retesting: `test → failure → fix → retest` is a valid serial chain. While tests run in the background, inspect unrelated documentation if useful, but do not edit files those tests depend on or launch the same tests again.
12
+ A response with a single call is right only when every other call you would make next depends on that call's result.
16
13
 
17
- The aim is fewer avoidable model round trips, not a minimum batch size. Actual concurrency depends on the runtime/host scheduler; batching does not override it or guarantee lower latency, tokens, or cost.
14
+ If you think in dependency graphs: this test picks out the current ready layer, the calls with no unmet dependency. Send that whole layer at once; you never need to plan the full graph.
15
+
16
+ ## Batch these
17
+
18
+ - **Opening reads and searches.** Starting a task that names `src/a.ts`, `src/b.ts` and a config file: read all three and run the search for the symbol in one response.
19
+ - **One result, several follow-ups.** A stack trace names three files, or a search returns four matches you need to inspect: read all of them together, not one per turn.
20
+ - **Independent edits.** Once you know the change for each file, edit different files in the same response.
21
+ - **Read-only checks.** After edits are done, typecheck, lint and tests that do not write shared state go together.
22
+
23
+ ## Wait for these
24
+
25
+ Calls in one response may run concurrently and in any order. Keep calls in separate responses when:
26
+
27
+ - a result decides whether to make the next call or what it takes (a search must find a path before you read it; don't guess the path);
28
+ - approval is required first;
29
+ - they touch the same state: read before edit, edit before run, two edits to one file, write then read back.
30
+
31
+ `test → read failure → fix → retest` is a valid serial chain, and so is a single call when nothing else is ready.
32
+
33
+ ## Don't fake batches
34
+
35
+ - Don't chain unrelated commands into one shell call (`cat a; cat b; ls c`) to look parallel; use separate tool calls. A command whose steps really depend on each other (`build && test`) is fine.
36
+ - Don't launch subagents just to parallelize quick calls.
37
+ - Don't add speculative calls you would not otherwise make.
38
+
39
+ ## Background work
40
+
41
+ While a background job or subagent runs, do work that neither needs its result nor touches its state (e.g. read unrelated docs while tests run; don't edit files the tests depend on). Don't busy-poll, and never repeat a call or delegation that is running or finished.
42
+
43
+ Required plan, todo and approval workflows still apply. Actual concurrency is up to the host scheduler; the goal is fewer avoidable model round trips.