@zhushanwen/pi-subagent-workflow 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-subagent-workflow",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "main": "index.ts",
6
6
  "description": "Unified subagent execution and multi-agent workflow orchestration for Pi — spawned-process agent runtime with sync/background modes, stateful workflow management with persistence, state machine, and execution tracing.",
@@ -47,7 +47,7 @@
47
47
  "@earendil-works/pi-ai": "*",
48
48
  "@earendil-works/pi-tui": "*",
49
49
  "typebox": "*",
50
- "@zhushanwen/pi-structured-output": "2.0.0"
50
+ "@zhushanwen/pi-structured-output": "2.0.1"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "@earendil-works/pi-coding-agent": {
@@ -46,12 +46,15 @@ describe("formatSchemaInstruction", () => {
46
46
  const out = formatSchemaInstruction({ type: "object" });
47
47
  // 完整结构快照——任何指令措辞/顺序/缩进漂移都会被捕获。
48
48
  // 注意第三行末尾的 em-dash(—),防止有人把它替换成普通连字符。
49
+ // [HISTORICAL] 方案 A 后文案更新:告知 LLM schema 由系统注入,只需传 data。
49
50
  expect(out).toBe(
50
51
  [
51
52
  "MANDATORY: Structured Output Requirement",
52
53
  "You MUST call the `structured-output` tool with your final answer.",
53
54
  "Do NOT output the JSON directly in your text response — you MUST use the structured-output tool.",
54
- "The schema for the structured output is:",
55
+ "The schema is enforced by the system — call structured-output with ONLY the `data` parameter.",
56
+ "Do NOT pass a `schema` parameter; the system validates `data` against the authoritative schema automatically.",
57
+ "The schema for your `data` is:",
55
58
  "```json",
56
59
  '{',
57
60
  ' "type": "object"',
@@ -109,6 +109,17 @@ function computeWatchdogMs(maxTurns: number | undefined | null): number {
109
109
  /** stderr 累积上限(字符)。防止失控子进程打满父进程内存。保留尾部便于诊断。 */
110
110
  const STDERR_MAX_CHARS = 64 * 1024;
111
111
 
112
+ /**
113
+ * 跨包契约 env 名:workflow 子进程把权威 JSON Schema 通过此 env 传给 structured-output 扩展。
114
+ *
115
+ * [跨包契约 SSOT] 此字面量是两个独立 npm 包(@zhushanwen/pi-subagent-workflow 与
116
+ * @zhushanwen/pi-structured-output)之间的隐式 env 契约。structured-output 包内同名常量为
117
+ * `ENV_SCHEMA = "PI_WORKFLOW_SCHEMA"`(见 extensions/structured-output/src/index.ts)。
118
+ * 两包是独立 npm 包不能直接 import,故各自保留常量但显式标注此契约关系——
119
+ * 任一端改名必须同步另一端,否则权威 schema 注入会静默断桥(子进程不注册 tool/hook)。
120
+ */
121
+ const SCHEMA_ENV_VAR = "PI_WORKFLOW_SCHEMA";
122
+
112
123
  // ============================================================
113
124
  // W4: ask_user RPC 系统提示词
114
125
  // ============================================================
@@ -266,7 +277,7 @@ export interface RunOptions {
266
277
  * workflow 路径(executeAndAwait)不传此字段——其 onEvent 是开的,
267
278
  * text_delta 经 onEvent 到 workflow liveRecord,不走 streaming 通道。 */
268
279
  stream?: SubagentStream;
269
- /** D-A6 bridge: workflow schema JSON 字符串,存在时注入 childEnv.PI_WORKFLOW_SCHEMA
280
+ /** D-A6 bridge: workflow schema JSON 字符串,存在时注入 childEnv[SCHEMA_ENV_VAR](PI_WORKFLOW_SCHEMA)。
270
281
  * workflow 编排层通过 ExecuteOptions.schemaEnv 透传此处,
271
282
  * runSpawn 将其注入子进程环境变量,激活 structured-output 扩展注册 tool。
272
283
  * tool 层 execute 不传此字段 → childEnv 不注入 → BC-6 行为不变。 */
@@ -287,7 +298,7 @@ export interface RunOptions {
287
298
  * 将 schemaEnv 注入 childEnv(D-A6 bridge)。
288
299
  *
289
300
  * [模块内直调] —— 纯 env 赋值。从 runSpawn 的 childEnv 构造块调用。
290
- * 存在时设 childEnv.PI_WORKFLOW_SCHEMA → 子进程 structured-output 扩展读取并注册 tool。
301
+ * 存在时设 childEnv[SCHEMA_ENV_VAR] → 子进程 structured-output 扩展读取并注册 tool。
291
302
  * 不存在时 childEnv 不变(BC-6:tool 层不传 schemaEnv → 行为与合并前一致)。
292
303
  */
293
304
  export function applySchemaEnvToChildEnv(
@@ -295,7 +306,7 @@ export function applySchemaEnvToChildEnv(
295
306
  schemaEnv?: string,
296
307
  ): void {
297
308
  if (schemaEnv) {
298
- childEnv.PI_WORKFLOW_SCHEMA = schemaEnv;
309
+ childEnv[SCHEMA_ENV_VAR] = schemaEnv;
299
310
  }
300
311
  }
301
312
 
@@ -315,7 +326,9 @@ export function formatSchemaInstruction(schema: Record<string, unknown>): string
315
326
  "MANDATORY: Structured Output Requirement",
316
327
  "You MUST call the `structured-output` tool with your final answer.",
317
328
  "Do NOT output the JSON directly in your text response — you MUST use the structured-output tool.",
318
- "The schema for the structured output is:",
329
+ "The schema is enforced by the system — call structured-output with ONLY the `data` parameter.",
330
+ "Do NOT pass a `schema` parameter; the system validates `data` against the authoritative schema automatically.",
331
+ "The schema for your `data` is:",
319
332
  "```json",
320
333
  JSON.stringify(schema, null, SCHEMA_JSON_INDENT),
321
334
  "```",
@@ -102,11 +102,14 @@ export function resolveAgentOpts(
102
102
  "This task requires structured output.",
103
103
  "Your FINAL action must be calling the `structured-output` tool.",
104
104
  "",
105
- `structured-output parameters:`,
106
- ` schema = ${schemaJson}`,
107
- ` data = <your result conforming to the schema above>`,
105
+ "The schema is enforced by the system (PI_WORKFLOW_SCHEMA). You only pass `data` — do NOT pass a `schema` parameter.",
106
+ `Your \`data\` must conform to this schema:`,
107
+ "```json",
108
+ schemaJson,
109
+ "```",
108
110
  "",
109
111
  "Rules:",
112
+ "- Call structured-output with ONLY the `data` parameter. The system validates it against the schema above automatically.",
110
113
  "- Do NOT output JSON in your text response — use the structured-output tool.",
111
114
  "- Do NOT skip this step. The structured-output call IS your result.",
112
115
  "- Complete all other work FIRST, then call structured-output as the last action.",