@oyasmi/pipiclaw 0.9.0-beta.6 → 0.9.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/agent/channel-runner.d.ts +8 -0
  2. package/dist/agent/channel-runner.js +154 -132
  3. package/dist/agent/commands.d.ts +6 -0
  4. package/dist/agent/job-manager.js +6 -10
  5. package/dist/agent/progress-formatter.js +3 -3
  6. package/dist/index.d.ts +2 -1
  7. package/dist/index.js +2 -1
  8. package/dist/main.js +2 -1
  9. package/dist/memory/extraction.js +0 -1
  10. package/dist/memory/maintenance-gates.d.ts +1 -1
  11. package/dist/memory/maintenance-jobs.js +2 -3
  12. package/dist/memory/metadata.d.ts +0 -15
  13. package/dist/memory/metadata.js +0 -7
  14. package/dist/memory/probation.d.ts +1 -5
  15. package/dist/memory/probation.js +2 -6
  16. package/dist/memory/review-log.js +0 -0
  17. package/dist/memory/scheduler.d.ts +1 -0
  18. package/dist/memory/scheduler.js +64 -6
  19. package/dist/models/auth-cli.d.ts +1 -1
  20. package/dist/models/auth-cli.js +3 -2
  21. package/dist/paths.d.ts +0 -6
  22. package/dist/paths.js +0 -6
  23. package/dist/playbooks/agent-delegation.md +2 -2
  24. package/dist/runtime/app-home.d.ts +32 -0
  25. package/dist/runtime/app-home.js +319 -0
  26. package/dist/runtime/bootstrap.d.ts +1 -67
  27. package/dist/runtime/bootstrap.js +114 -512
  28. package/dist/runtime/delivery.js +1 -1
  29. package/dist/runtime/dingtalk.d.ts +7 -6
  30. package/dist/runtime/dingtalk.js +5 -13
  31. package/dist/runtime/durable-dispatch.d.ts +1 -0
  32. package/dist/runtime/durable-dispatch.js +36 -25
  33. package/dist/runtime/subagent-commands.js +48 -10
  34. package/dist/runtime/task-wake.d.ts +54 -0
  35. package/dist/runtime/task-wake.js +99 -0
  36. package/dist/shared/host-process.d.ts +25 -9
  37. package/dist/shared/host-process.js +59 -10
  38. package/dist/shared/wake-claim.d.ts +23 -0
  39. package/dist/shared/wake-claim.js +26 -0
  40. package/dist/subagents/discovery.d.ts +25 -1
  41. package/dist/subagents/discovery.js +108 -17
  42. package/dist/subagents/external/claude-code.js +13 -5
  43. package/dist/subagents/external/codex-cli.js +9 -3
  44. package/dist/subagents/external/exec.js +1 -0
  45. package/dist/subagents/external/harness.d.ts +22 -0
  46. package/dist/subagents/external/harness.js +40 -7
  47. package/dist/subagents/external/run.d.ts +23 -3
  48. package/dist/subagents/external/run.js +113 -123
  49. package/dist/subagents/external/settlement.d.ts +50 -0
  50. package/dist/subagents/external/settlement.js +123 -0
  51. package/dist/subagents/format.d.ts +4 -0
  52. package/dist/subagents/format.js +7 -0
  53. package/dist/subagents/runs.d.ts +70 -13
  54. package/dist/subagents/runs.js +202 -118
  55. package/dist/subagents/tool.d.ts +27 -2
  56. package/dist/subagents/tool.js +92 -48
  57. package/dist/subagents/verification-outcome.d.ts +26 -0
  58. package/dist/subagents/verification-outcome.js +16 -0
  59. package/dist/subagents/workspace-lease.d.ts +10 -1
  60. package/dist/subagents/workspace-lease.js +15 -2
  61. package/dist/tools/index.js +6 -0
  62. package/dist/tools/memory-manage.js +0 -1
  63. package/dist/tools/subagent-manage.d.ts +20 -6
  64. package/dist/tools/subagent-manage.js +86 -16
  65. package/dist/tui/app.d.ts +1 -1
  66. package/dist/tui/app.js +3 -2
  67. package/dist/tui/cli.d.ts +1 -1
  68. package/dist/tui/cli.js +1 -1
  69. package/dist/tui/terminal-media-sender.d.ts +1 -1
  70. package/examples/sub-agents/README.md +15 -14
  71. package/examples/sub-agents/builder-hard.md +9 -8
  72. package/examples/sub-agents/builder.md +12 -11
  73. package/examples/sub-agents/documenter.md +11 -12
  74. package/examples/sub-agents/explorer.md +16 -13
  75. package/examples/sub-agents/git-committer.md +17 -16
  76. package/examples/sub-agents/log-sifter.md +19 -16
  77. package/examples/sub-agents/planner.md +17 -17
  78. package/examples/sub-agents/reviewer.md +13 -21
  79. package/examples/sub-agents/scout.md +5 -4
  80. package/examples/sub-agents/verifier.md +8 -12
  81. package/examples/sub-agents/worker.md +7 -6
  82. package/package.json +1 -1
@@ -85,7 +85,7 @@ export interface SubAgentConfig {
85
85
  /** External only: the raw, unvalidated command line. Tokenized by the harness at invocation
86
86
  * time (D4), never by discovery — discovery only checks that it is non-empty. */
87
87
  command?: string;
88
- /** External only: run `command` through `/bin/sh -lc` instead of argv-direct spawn (D4). */
88
+ /** exec harness only: run `command` through `/bin/sh -lc` instead of argv-direct spawn (D4). */
89
89
  shell?: boolean;
90
90
  /** External only: env vars appended to (and overriding) the inherited environment (D8.2). */
91
91
  env?: Record<string, string>;
@@ -142,6 +142,17 @@ export declare function validateToolNames(values: string[] | undefined): {
142
142
  tools: SubAgentToolName[];
143
143
  error?: string;
144
144
  };
145
+ type FieldSupport = "supported" | "rejected";
146
+ /**
147
+ * Which role-file fields mean something under which runtime (spec 040 D5's "对某种 runtime 无意义
148
+ * 的字段一律驳回", made into data per spec 042 D3/F3). A field present under a runtime marked
149
+ * `"rejected"` here is rejected outright, not silently ignored — silently ignoring one is a
150
+ * defect, not a leniency (the review that produced spec 042 found `shell`/`env` on an internal
151
+ * role doing exactly that before this table existed). `cwd` is deliberately absent: it is rejected
152
+ * for *both* runtimes with a different message ("not a role field at all"), handled separately in
153
+ * `loadAgentsFromDir` rather than as a per-runtime mismatch.
154
+ */
155
+ export declare const ROLE_FIELD_MATRIX: Record<string, Record<SubAgentRuntime, FieldSupport>>;
145
156
  export declare function discoverSubAgents(workspaceDir: string, availableModels: Model<Api>[]): SubAgentDiscoveryResult;
146
157
  export declare function resolveSubAgentConfig(availableModels: Model<Api>[], currentModel: Model<Api>, predefinedAgents: SubAgentConfig[], overrides: SubAgentInvocationOverrides,
147
158
  /**
@@ -154,4 +165,17 @@ subagentDefaultModelRef?: string): {
154
165
  error?: string;
155
166
  };
156
167
  export declare function formatSubAgentList(agents: SubAgentConfig[], maxItems?: number): string;
168
+ /**
169
+ * Spec 042 D7: a fingerprint of the parts of an external role that decide *how a launched process
170
+ * is built* — `command`, `externalModelRef`, `shell`. Persisted on a run at launch and compared
171
+ * against the role's current config on `follow_up`: a mismatch means the role was hot-edited in a
172
+ * way that would resume under a harness or executable it never actually wrote, so `follow_up`
173
+ * refuses rather than silently reinterpreting the old session with the new config.
174
+ *
175
+ * Deliberately narrow — `systemPrompt` and `maxWallTimeSec` are excluded on purpose. A resumed
176
+ * session already carries its own context, and folding prompt edits in would mean "fix a typo in
177
+ * the role" breaks every in-flight follow-up; a full invocation snapshot was considered and
178
+ * rejected for the same reason (spec 042 design doc, "已驳回的方案").
179
+ */
180
+ export declare function externalRoleFingerprint(role: Pick<SubAgentConfig, "command" | "externalModelRef" | "shell">): string;
157
181
  export {};
@@ -1,3 +1,4 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { existsSync as existsSyncFs } from "node:fs";
2
3
  import { join as joinPath, delimiter as pathDelimiter } from "node:path";
3
4
  import { parseFrontmatter } from "@earendil-works/pi-coding-agent";
@@ -204,16 +205,23 @@ function parseContextChoice(raw) {
204
205
  }
205
206
  return { value: { contextMode: "contextual", memory: normalized } };
206
207
  }
207
- function parseMemoryMode(raw, contextMode) {
208
+ /**
209
+ * `defaultValue` is computed per call site rather than derived from `contextMode` inside this
210
+ * function (spec 042 D4): internal keeps following `contextMode` (`contextual` → `relevant`),
211
+ * but an external role's default is always `none` regardless of `contextMode` — a role that
212
+ * merely wants `paths` injected (via `contextMode: contextual`) should not also silently start
213
+ * sending session/memory content to a third-party process.
214
+ */
215
+ function parseMemoryMode(raw, defaultValue) {
208
216
  const normalized = readOptionalTrimmedString(raw);
209
217
  if (!normalized) {
210
- return { value: contextMode === "contextual" ? "relevant" : "none" };
218
+ return { value: defaultValue };
211
219
  }
212
220
  if (ALLOWED_MEMORY_MODES.includes(normalized)) {
213
221
  return { value: normalized };
214
222
  }
215
223
  return {
216
- value: contextMode === "contextual" ? "relevant" : "none",
224
+ value: defaultValue,
217
225
  error: `Unknown memory "${normalized}". Allowed values: ${ALLOWED_MEMORY_MODES.join(", ")}`,
218
226
  };
219
227
  }
@@ -348,18 +356,33 @@ function isExecutableAvailable(token) {
348
356
  const pathEnv = process.env.PATH ?? "";
349
357
  return pathEnv.split(pathDelimiter).some((dir) => dir && existsSyncFs(joinPath(dir, token)));
350
358
  }
351
- /** Fields that only mean something for one runtime; present under the other, they are rejected
352
- * outright rather than silently ignored (spec 040, D5 — "对某种 runtime 无意义的字段一律驳回"). */
353
- const FIELDS_REJECTED_FOR_INTERNAL = ["harness", "command"];
354
- const FIELDS_REJECTED_FOR_EXTERNAL = ["tools", "maxTurns", "maxToolCalls", "bashTimeoutSec"];
355
- function rejectedFieldNames(frontmatter, names) {
356
- return names.filter((name) => frontmatter[name] !== undefined);
359
+ /**
360
+ * Which role-file fields mean something under which runtime (spec 040 D5's "对某种 runtime 无意义
361
+ * 的字段一律驳回", made into data per spec 042 D3/F3). A field present under a runtime marked
362
+ * `"rejected"` here is rejected outright, not silently ignored — silently ignoring one is a
363
+ * defect, not a leniency (the review that produced spec 042 found `shell`/`env` on an internal
364
+ * role doing exactly that before this table existed). `cwd` is deliberately absent: it is rejected
365
+ * for *both* runtimes with a different message ("not a role field at all"), handled separately in
366
+ * `loadAgentsFromDir` rather than as a per-runtime mismatch.
367
+ */
368
+ export const ROLE_FIELD_MATRIX = {
369
+ harness: { internal: "rejected", external: "supported" },
370
+ command: { internal: "rejected", external: "supported" },
371
+ shell: { internal: "rejected", external: "supported" },
372
+ env: { internal: "rejected", external: "supported" },
373
+ tools: { internal: "supported", external: "rejected" },
374
+ maxTurns: { internal: "supported", external: "rejected" },
375
+ maxToolCalls: { internal: "supported", external: "rejected" },
376
+ bashTimeoutSec: { internal: "supported", external: "rejected" },
377
+ };
378
+ function rejectedFieldNames(frontmatter, runtime) {
379
+ return Object.keys(ROLE_FIELD_MATRIX).filter((field) => frontmatter[field] !== undefined && ROLE_FIELD_MATRIX[field][runtime] === "rejected");
357
380
  }
358
381
  function inferMutatesFromTools(tools) {
359
382
  return tools.includes("write") || tools.includes("edit") ? "write" : "read";
360
383
  }
361
384
  function parseInternalAgent(entryName, filePath, frontmatter, body, name, description, availableModels) {
362
- const rejected = rejectedFieldNames(frontmatter, FIELDS_REJECTED_FOR_INTERNAL);
385
+ const rejected = rejectedFieldNames(frontmatter, "internal");
363
386
  if (rejected.length > 0) {
364
387
  return { warning: `${entryName}: field(s) ${rejected.join(", ")} are only valid for runtime: external` };
365
388
  }
@@ -369,7 +392,7 @@ function parseInternalAgent(entryName, filePath, frontmatter, body, name, descri
369
392
  const contextMode = parseContextMode(frontmatter.contextMode);
370
393
  if (contextMode.error)
371
394
  return { warning: `${entryName}: ${contextMode.error}` };
372
- const memoryMode = parseMemoryMode(frontmatter.memory, contextMode.value);
395
+ const memoryMode = parseMemoryMode(frontmatter.memory, contextMode.value === "contextual" ? "relevant" : "none");
373
396
  if (memoryMode.error)
374
397
  return { warning: `${entryName}: ${memoryMode.error}` };
375
398
  const parsedPaths = parseStringList(frontmatter.paths, "paths");
@@ -405,8 +428,16 @@ function parseInternalAgent(entryName, filePath, frontmatter, body, name, descri
405
428
  const promptLengthError = validateSubAgentSystemPrompt(trimmedBody, "Sub-agent system prompt");
406
429
  if (promptLengthError)
407
430
  return { warning: `${entryName}: ${promptLengthError}` };
431
+ // Spec 042 D6: `bash` can write regardless of what `tools` otherwise implies, and the default
432
+ // tool set (`read,bash`) is inferred "read" — a role that actually writes through bash and never
433
+ // says so does not take the workspace write lease. Not rejected (`bash` is normal and common for
434
+ // read-only inspection too) — just surfaced so the declaration is a conscious choice.
435
+ const bashWithoutMutatesWarning = toolParse.tools.includes("bash") && mutates.value === undefined
436
+ ? 'tools include bash but "mutates" is not declared; if this role writes to the workspace, declare mutates: write so it participates in the workspace write lease'
437
+ : undefined;
438
+ const combinedWarningBody = [numericWarning, bashWithoutMutatesWarning].filter(Boolean).join("; ");
408
439
  return {
409
- warning: numericWarning ? `${entryName}: ${numericWarning}` : undefined,
440
+ warning: combinedWarningBody ? `${entryName}: ${combinedWarningBody}` : undefined,
410
441
  agent: {
411
442
  name,
412
443
  description,
@@ -431,7 +462,7 @@ function parseInternalAgent(entryName, filePath, frontmatter, body, name, descri
431
462
  };
432
463
  }
433
464
  function parseExternalAgent(entryName, filePath, frontmatter, body, name, description) {
434
- const rejected = rejectedFieldNames(frontmatter, FIELDS_REJECTED_FOR_EXTERNAL);
465
+ const rejected = rejectedFieldNames(frontmatter, "external");
435
466
  if (rejected.length > 0) {
436
467
  return { warning: `${entryName}: field(s) ${rejected.join(", ")} are not valid for runtime: external` };
437
468
  }
@@ -451,6 +482,11 @@ function parseExternalAgent(entryName, filePath, frontmatter, body, name, descri
451
482
  const shell = parseBooleanField(frontmatter.shell, "shell");
452
483
  if (shell.error)
453
484
  return { warning: `${entryName}: ${shell.error}` };
485
+ if (shell.value && harness.value !== "exec") {
486
+ return {
487
+ warning: `${entryName}: "shell: true" is only supported with harness: exec; structured harnesses must assemble their own argv`,
488
+ };
489
+ }
454
490
  const env = parseEnvMap(frontmatter.env);
455
491
  if (env.error)
456
492
  return { warning: `${entryName}: ${env.error}` };
@@ -466,9 +502,16 @@ function parseExternalAgent(entryName, filePath, frontmatter, body, name, descri
466
502
  const contextMode = parseContextMode(frontmatter.contextMode);
467
503
  if (contextMode.error)
468
504
  return { warning: `${entryName}: ${contextMode.error}` };
469
- const memoryMode = parseMemoryMode(frontmatter.memory, contextMode.value);
505
+ // Spec 042 D4: external default is always "none", never following contextMode the way internal
506
+ // does — a role that only wants `paths` injected (contextMode: contextual) should not also
507
+ // silently start sending session/memory content to a third-party process. Explicitly declaring
508
+ // `memory: session|relevant` is a real, informed choice; it gets a disclosure warning below.
509
+ const memoryMode = parseMemoryMode(frontmatter.memory, "none");
470
510
  if (memoryMode.error)
471
511
  return { warning: `${entryName}: ${memoryMode.error}` };
512
+ const memoryDisclosureWarning = memoryMode.value !== "none"
513
+ ? `${entryName}: memory: ${memoryMode.value} sends channel session state / recalled memory content to this external process`
514
+ : undefined;
472
515
  const maxWallTimeSec = parsePositiveInteger(frontmatter.maxWallTimeSec, DEFAULT_EXTERNAL_MAX_WALL_TIME_SEC);
473
516
  const trimmedBody = body.trim();
474
517
  if (!trimmedBody)
@@ -483,14 +526,28 @@ function parseExternalAgent(entryName, filePath, frontmatter, body, name, descri
483
526
  const unavailable = executable && !isExecutableAvailable(executable)
484
527
  ? `executable "${executable}" was not found on PATH; install it or fix "command" in ${filePath}`
485
528
  : undefined;
529
+ const externalModelRef = readOptionalTrimmedString(frontmatter.model);
530
+ // Spec 042 D10: a role's `model:` can only ever come from its own frontmatter (external `model`
531
+ // is never taken from the invocation) — so if `command` references `$MODEL` and none is
532
+ // configured here, every dispatch of this role will silently drop that argv token. Surface it
533
+ // at discovery time, where the fix (add `model:`) is obvious, instead of only as a per-run
534
+ // warning after the fact. `$EFFORT` gets no equivalent check: `thinkingLevel` can be supplied
535
+ // per invocation, so an unset frontmatter value does not mean "no value ever".
536
+ const modelPlaceholderWarning = command.includes("$MODEL") && !externalModelRef
537
+ ? `${entryName}: command references $MODEL but no "model" is configured; that argv token will be dropped on every dispatch`
538
+ : undefined;
539
+ // Both are non-fatal (the role still loads); joined rather than picking one so an unlucky
540
+ // combination never silently loses one of them.
541
+ const combinedWarning = [memoryDisclosureWarning, modelPlaceholderWarning].filter(Boolean).join("; ") || undefined;
486
542
  return {
543
+ warning: combinedWarning,
487
544
  agent: {
488
545
  name,
489
546
  description,
490
547
  systemPrompt: trimmedBody,
491
548
  tools: [],
492
549
  modelRef: undefined,
493
- externalModelRef: readOptionalTrimmedString(frontmatter.model),
550
+ externalModelRef,
494
551
  maxTurns: DEFAULT_MAX_TURNS,
495
552
  maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
496
553
  maxWallTimeSec: maxWallTimeSec.value,
@@ -601,6 +658,24 @@ subagentDefaultModelRef) {
601
658
  if (!baseConfig && (!overrides.systemPrompt || !overrides.systemPrompt.trim())) {
602
659
  return { error: 'Provide either "agent" or "systemPrompt" to define the sub-agent.' };
603
660
  }
661
+ const effectiveRuntime = baseConfig?.runtime ?? "internal";
662
+ // Spec 042 D3: the invocation-side counterpart to the role-file field matrix (`ROLE_FIELD_MATRIX`
663
+ // above) — a field only meaningful for one runtime is rejected outright when the resolved role
664
+ // is the other, not silently ignored. `tools` and `model` were previously accepted and either
665
+ // dropped on the floor or — for `model` — resolved against `models.json` and made to fail a
666
+ // dispatch for a reason that has nothing to do with the external role actually named.
667
+ if (effectiveRuntime === "external" && overrides.tools !== undefined) {
668
+ return {
669
+ error: `Sub-agent "${baseConfig?.name}" is external; its tool boundary comes from its own ` +
670
+ 'command (e.g. "--sandbox read-only"), not the "tools" invocation parameter, which has no effect on external roles.',
671
+ };
672
+ }
673
+ if (effectiveRuntime === "external" && overrides.model?.trim()) {
674
+ return {
675
+ error: `Sub-agent "${baseConfig?.name}" is external; its model can only be set in the role file's ` +
676
+ '"model" frontmatter. The "model" invocation parameter has no effect on external roles and is never resolved against models.json.',
677
+ };
678
+ }
604
679
  const tools = overrides.tools
605
680
  ? validateToolNames(overrides.tools)
606
681
  : { tools: baseConfig?.tools ?? [...DEFAULT_SUB_AGENT_TOOLS] };
@@ -609,7 +684,7 @@ subagentDefaultModelRef) {
609
684
  }
610
685
  let model = baseConfig?.model;
611
686
  let modelRef = baseConfig?.modelRef;
612
- if (overrides.model?.trim()) {
687
+ if (effectiveRuntime !== "external" && overrides.model?.trim()) {
613
688
  const resolved = resolveModelReference(overrides.model.trim(), availableModels);
614
689
  if (!resolved.model) {
615
690
  return { error: resolved.error };
@@ -629,7 +704,6 @@ subagentDefaultModelRef) {
629
704
  if (effortOverride.error) {
630
705
  return { error: effortOverride.error };
631
706
  }
632
- const effectiveRuntime = baseConfig?.runtime ?? "internal";
633
707
  // An explicit `effort` replaces the whole budget tuple rather than merging field by
634
708
  // field, so a preset never produces a combination no preset describes. External is a
635
709
  // separate branch (P1-3): it has no turn/tool-call budget, and effort's wall-time numbers
@@ -720,3 +794,20 @@ export function formatSubAgentList(agents, maxItems = 12) {
720
794
  }
721
795
  return `${listed.join("\n")}\n- ... and ${agents.length - maxItems} more`;
722
796
  }
797
+ /**
798
+ * Spec 042 D7: a fingerprint of the parts of an external role that decide *how a launched process
799
+ * is built* — `command`, `externalModelRef`, `shell`. Persisted on a run at launch and compared
800
+ * against the role's current config on `follow_up`: a mismatch means the role was hot-edited in a
801
+ * way that would resume under a harness or executable it never actually wrote, so `follow_up`
802
+ * refuses rather than silently reinterpreting the old session with the new config.
803
+ *
804
+ * Deliberately narrow — `systemPrompt` and `maxWallTimeSec` are excluded on purpose. A resumed
805
+ * session already carries its own context, and folding prompt edits in would mean "fix a typo in
806
+ * the role" breaks every in-flight follow-up; a full invocation snapshot was considered and
807
+ * rejected for the same reason (spec 042 design doc, "已驳回的方案").
808
+ */
809
+ export function externalRoleFingerprint(role) {
810
+ return createHash("sha256")
811
+ .update(JSON.stringify([role.command ?? "", role.externalModelRef ?? "", Boolean(role.shell)]))
812
+ .digest("hex");
813
+ }
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { detectExistingFlags, expandPlaceholders, } from "./harness.js";
2
+ import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, } from "./harness.js";
3
3
  /**
4
4
  * `claude-code` harness (spec 040, D3/D4). Same one-prompt-one-process model as codex-cli; the
5
5
  * differences are argv shape and stdout schema.
@@ -31,16 +31,15 @@ function toClaudeEffort(level) {
31
31
  }
32
32
  export const claudeCodeHarness = {
33
33
  id: "claude-code",
34
+ parserVersion: 1,
34
35
  buildInvocation(input) {
35
36
  if (input.argv.length === 0) {
36
37
  throw new Error("claude-code: command produced no argv tokens");
37
38
  }
38
39
  const [executable, ...rest] = input.argv;
39
40
  const existing = detectExistingFlags(rest);
40
- // D4's addendum table lists no auto-appended effort flag for claude-code — only $EFFORT
41
- // expansion for a role author whose wrapper accepts one.
42
41
  const effort = toClaudeEffort(input.thinkingLevel);
43
- const { argv: expandedRest, used } = expandPlaceholders(rest, {
42
+ const { argv: expandedRest, used, dropped, } = expandPlaceholders(rest, {
44
43
  $MODEL: input.model,
45
44
  $EFFORT: effort,
46
45
  $PROMPT_FILE: input.promptFile,
@@ -50,6 +49,9 @@ export const claudeCodeHarness = {
50
49
  if (!existing.model && input.model && !used.has("$MODEL")) {
51
50
  args.push("--model", input.model);
52
51
  }
52
+ if (!existing.effort && effort && !used.has("$EFFORT")) {
53
+ args.push("--effort", effort);
54
+ }
53
55
  if (!used.has("$SYSTEM_PROMPT_FILE")) {
54
56
  args.push("--append-system-prompt-file", input.systemPromptFile);
55
57
  }
@@ -61,7 +63,13 @@ export const claudeCodeHarness = {
61
63
  presetSessionId = randomUUID();
62
64
  args.push("--session-id", presetSessionId);
63
65
  }
64
- return { executable, args, resumable: true, presetSessionId };
66
+ return {
67
+ executable,
68
+ args,
69
+ resumable: true,
70
+ presetSessionId,
71
+ warnings: dropped.length > 0 ? formatDroppedPlaceholderWarnings(dropped) : undefined,
72
+ };
65
73
  },
66
74
  parseOutcome(input) {
67
75
  let finalText = "";
@@ -1,4 +1,4 @@
1
- import { detectExistingFlags, expandPlaceholders, } from "./harness.js";
1
+ import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, } from "./harness.js";
2
2
  /**
3
3
  * `codex-cli` harness (spec 040, D3/D4). One prompt, one short-lived process, NDJSON on stdout
4
4
  * (`--json -`). Chosen as the first structured harness because its process model already matches
@@ -28,6 +28,7 @@ function toCodexEffort(level) {
28
28
  }
29
29
  export const codexCliHarness = {
30
30
  id: "codex-cli",
31
+ parserVersion: 1,
31
32
  buildInvocation(input) {
32
33
  if (input.argv.length === 0) {
33
34
  throw new Error("codex-cli: command produced no argv tokens");
@@ -35,7 +36,7 @@ export const codexCliHarness = {
35
36
  const [executable, ...rest] = input.argv;
36
37
  const existing = detectExistingFlags(rest);
37
38
  const effort = toCodexEffort(input.thinkingLevel);
38
- const { argv: expandedRest, used } = expandPlaceholders(rest, {
39
+ const { argv: expandedRest, used, dropped, } = expandPlaceholders(rest, {
39
40
  $MODEL: input.model,
40
41
  $EFFORT: effort,
41
42
  $PROMPT_FILE: input.promptFile,
@@ -53,7 +54,12 @@ export const codexCliHarness = {
53
54
  const args = input.resumeSessionId
54
55
  ? [...baseArgs, "resume", input.resumeSessionId, "--json", "-"]
55
56
  : [...baseArgs, "--json", "-"];
56
- return { executable, args, resumable: true };
57
+ return {
58
+ executable,
59
+ args,
60
+ resumable: true,
61
+ warnings: dropped.length > 0 ? formatDroppedPlaceholderWarnings(dropped) : undefined,
62
+ };
57
63
  },
58
64
  parseOutcome(input) {
59
65
  let finalText = "";
@@ -12,6 +12,7 @@
12
12
  const MAX_OUTPUT_CHARS = 16_000;
13
13
  export const execHarness = {
14
14
  id: "exec",
15
+ parserVersion: 1,
15
16
  buildInvocation(input) {
16
17
  if (input.argv.length === 0) {
17
18
  throw new Error("exec: command produced no argv tokens");
@@ -33,6 +33,10 @@ export interface BuildInvocationResult {
33
33
  * not just at settlement.
34
34
  */
35
35
  presetSessionId?: string;
36
+ /** Spec 042 D10: non-fatal invocation-time warnings (e.g. an argv token dropped because its
37
+ * placeholder had no value) — persisted onto the run record so `/subagents show` can surface
38
+ * them, since a silently-dropped flag can otherwise look identical to a role that never wanted it. */
39
+ warnings?: string[];
36
40
  }
37
41
  export type ExternalProtocolStatus = "completed" | "failed" | "absent" | "unparsable";
38
42
  export interface ExternalOutcome {
@@ -60,6 +64,13 @@ export interface ParseOutcomeInput {
60
64
  }
61
65
  export interface ExternalHarness {
62
66
  readonly id: "claude-code" | "codex-cli" | "exec";
67
+ /**
68
+ * Spec 042 D12: bumped by hand whenever this adapter's `parseOutcome` schema assumptions
69
+ * change. Persisted on the run and shown by `/subagents show`, so a failure caused by upstream
70
+ * CLI schema drift is distinguishable from a failure the target CLI itself reported — "the
71
+ * adapter is stale" and "the agent failed" look identical from a run's status alone otherwise.
72
+ */
73
+ readonly parserVersion: number;
63
74
  /** Assemble argv. The command line is never joined into a single shell string (D4). */
64
75
  buildInvocation(input: ExternalInvocationInput): BuildInvocationResult;
65
76
  /** Parse stdout into a unified outcome. Must never throw — a parse failure degrades to
@@ -91,9 +102,20 @@ export type Placeholder = (typeof PLACEHOLDERS)[number];
91
102
  * (D4). Returns which placeholders were actually found, so a harness knows whether it still needs
92
103
  * to *append* the corresponding flag (a placeholder present ⇒ never append; absent ⇒ append per
93
104
  * the harness's own rule).
105
+ *
106
+ * Spec 042 D10: a token that still references a placeholder after substitution (its value was
107
+ * `undefined`, e.g. `--model $MODEL` on a role with no `model:` configured) is dropped from argv
108
+ * entirely rather than reaching the process as a literal `"$MODEL"` string — that literal-string
109
+ * failure is exactly what D4's "argv, not a shell string" design exists to prevent, just arriving
110
+ * through a different door (a missing value instead of a shell-quoting bug). `dropped` carries the
111
+ * original tokens so the caller can turn them into a run-visible warning.
94
112
  */
95
113
  export declare function expandPlaceholders(argv: string[], values: Partial<Record<Placeholder, string>>): {
96
114
  argv: string[];
97
115
  used: Set<Placeholder>;
116
+ dropped: string[];
98
117
  };
118
+ /** Turn `expandPlaceholders`'s `dropped` tokens into run-visible warning strings (spec 042 D10),
119
+ * shared so every structured harness reports the same wording. */
120
+ export declare function formatDroppedPlaceholderWarnings(dropped: string[]): string[];
99
121
  export {};
@@ -33,7 +33,8 @@ export function classifyExternalOutcome(harnessId, outcome) {
33
33
  }
34
34
  const MODEL_FLAG_PATTERN = /^(--model|-m)$/;
35
35
  const EFFORT_FLAG_PATTERN = /^(--effort|--thinking)$/;
36
- const CODEX_EFFORT_FLAG_PATTERN = /^-c$/;
36
+ const CODEX_CONFIG_FLAG_PATTERN = /^(-c|--config)$/;
37
+ const CODEX_MODEL_VALUE_PREFIX = "model=";
37
38
  const CODEX_EFFORT_VALUE_PREFIX = "model_reasoning_effort=";
38
39
  /** Which flags the user's own `command` already spells out, so a harness never injects a duplicate (D4). */
39
40
  export function detectExistingFlags(argv) {
@@ -45,10 +46,24 @@ export function detectExistingFlags(argv) {
45
46
  model = true;
46
47
  if (EFFORT_FLAG_PATTERN.test(token))
47
48
  effort = true;
48
- if (CODEX_EFFORT_FLAG_PATTERN.test(token) && argv[i + 1]?.startsWith(CODEX_EFFORT_VALUE_PREFIX))
49
- effort = true;
49
+ if (CODEX_CONFIG_FLAG_PATTERN.test(token)) {
50
+ const value = argv[i + 1];
51
+ if (value?.startsWith(CODEX_MODEL_VALUE_PREFIX))
52
+ model = true;
53
+ if (value?.startsWith(CODEX_EFFORT_VALUE_PREFIX))
54
+ effort = true;
55
+ }
50
56
  if (token.startsWith("--model=") || token.startsWith("-m="))
51
57
  model = true;
58
+ if (token.startsWith("--effort=") || token.startsWith("--thinking="))
59
+ effort = true;
60
+ if (token.startsWith("-c=") || token.startsWith("--config=")) {
61
+ const value = token.slice(token.indexOf("=") + 1);
62
+ if (value.startsWith(CODEX_MODEL_VALUE_PREFIX))
63
+ model = true;
64
+ if (value.startsWith(CODEX_EFFORT_VALUE_PREFIX))
65
+ effort = true;
66
+ }
52
67
  }
53
68
  return { model, effort };
54
69
  }
@@ -58,10 +73,19 @@ const PLACEHOLDERS = ["$MODEL", "$EFFORT", "$PROMPT_FILE", "$SYSTEM_PROMPT_FILE"
58
73
  * (D4). Returns which placeholders were actually found, so a harness knows whether it still needs
59
74
  * to *append* the corresponding flag (a placeholder present ⇒ never append; absent ⇒ append per
60
75
  * the harness's own rule).
76
+ *
77
+ * Spec 042 D10: a token that still references a placeholder after substitution (its value was
78
+ * `undefined`, e.g. `--model $MODEL` on a role with no `model:` configured) is dropped from argv
79
+ * entirely rather than reaching the process as a literal `"$MODEL"` string — that literal-string
80
+ * failure is exactly what D4's "argv, not a shell string" design exists to prevent, just arriving
81
+ * through a different door (a missing value instead of a shell-quoting bug). `dropped` carries the
82
+ * original tokens so the caller can turn them into a run-visible warning.
61
83
  */
62
84
  export function expandPlaceholders(argv, values) {
63
85
  const used = new Set();
64
- const expanded = argv.map((token) => {
86
+ const dropped = [];
87
+ const expanded = [];
88
+ for (const token of argv) {
65
89
  let result = token;
66
90
  for (const placeholder of PLACEHOLDERS) {
67
91
  const value = values[placeholder];
@@ -70,7 +94,16 @@ export function expandPlaceholders(argv, values) {
70
94
  result = result.split(placeholder).join(value);
71
95
  }
72
96
  }
73
- return result;
74
- });
75
- return { argv: expanded, used };
97
+ if (PLACEHOLDERS.some((placeholder) => result.includes(placeholder))) {
98
+ dropped.push(token);
99
+ continue;
100
+ }
101
+ expanded.push(result);
102
+ }
103
+ return { argv: expanded, used, dropped };
104
+ }
105
+ /** Turn `expandPlaceholders`'s `dropped` tokens into run-visible warning strings (spec 042 D10),
106
+ * shared so every structured harness reports the same wording. */
107
+ export function formatDroppedPlaceholderWarnings(dropped) {
108
+ return dropped.map((token) => `Dropped argv token "${token}": it references a placeholder with no value configured for this run (e.g. no "model:" set for $MODEL).`);
76
109
  }
@@ -40,6 +40,9 @@ export interface LaunchExternalRunInput {
40
40
  resumeSessionId?: string;
41
41
  /** The role's own `mutates` declaration, carried through to the dispatch audit event (D8.1). */
42
42
  mutates?: RunMutates;
43
+ /** Spec 042 D7: fingerprint of the role's `command`/`externalModelRef`/`shell`, persisted so a
44
+ * later `follow_up` can detect a hot-edited role before resuming under it. */
45
+ roleFingerprint?: string;
43
46
  /** Where the audit trail lives (`<workspaceDir>/.pipiclaw/security.log` by default) and whether
44
47
  * it is enabled — every external dispatch writes an `external-agent` audit event (D8.1), since
45
48
  * external processes never pass through command-guard and this is the only record of what
@@ -49,6 +52,23 @@ export interface LaunchExternalRunInput {
49
52
  /** Test seam: inject a fake `child_process.spawn`. */
50
53
  spawnFn?: typeof nodeSpawn;
51
54
  }
52
- /** Launches an external run. Returns once the process is confirmed spawned (or fails fast if it
53
- * never starts); the wait-for-exit-and-settle work continues in the background afterward. */
54
- export declare function launchExternalRun(input: LaunchExternalRunInput): Promise<void>;
55
+ /**
56
+ * Spec 042 D2: a pre-run failure (file open, spawn, or a cancel that lands before the process
57
+ * exists) used to settle the run and return `void`, leaving the caller no way to tell the model
58
+ * anything went wrong in this same turn — it would see "[Dispatched] ... running" and then, for
59
+ * two of the three cases, never be woken at all. `missing-binary` (spawn `ENOENT`/`EACCES`) needs
60
+ * a human to install the CLI or fix `command`, so callers should surface it as a plain `Error`
61
+ * (AGENTS.md's "can the model resolve this alone?" test says no); the other two are model-fixable
62
+ * (retry the dispatch, or accept that a race cancelled it) and should be a `RecoverableToolError`.
63
+ */
64
+ export type ExternalLaunchResult = {
65
+ ok: true;
66
+ } | {
67
+ ok: false;
68
+ kind: "missing-binary" | "launch-failed" | "cancelled";
69
+ reason: string;
70
+ };
71
+ /** Launches an external run. Resolves once the process is confirmed spawned (or fails fast if it
72
+ * never starts, spec 042 D2); the wait-for-exit-and-settle work continues in the background
73
+ * afterward. */
74
+ export declare function launchExternalRun(input: LaunchExternalRunInput): Promise<ExternalLaunchResult>;