@oyasmi/pipiclaw 0.9.0-beta.7 → 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 (35) hide show
  1. package/dist/memory/review-log.js +0 -0
  2. package/dist/memory/scheduler.d.ts +1 -0
  3. package/dist/memory/scheduler.js +64 -6
  4. package/dist/playbooks/agent-delegation.md +2 -2
  5. package/dist/runtime/bootstrap.js +9 -5
  6. package/dist/runtime/durable-dispatch.d.ts +1 -0
  7. package/dist/runtime/durable-dispatch.js +36 -25
  8. package/dist/runtime/subagent-commands.js +48 -10
  9. package/dist/shared/host-process.d.ts +25 -9
  10. package/dist/shared/host-process.js +59 -10
  11. package/dist/subagents/discovery.d.ts +24 -0
  12. package/dist/subagents/discovery.js +103 -17
  13. package/dist/subagents/external/claude-code.js +10 -3
  14. package/dist/subagents/external/codex-cli.js +9 -3
  15. package/dist/subagents/external/exec.js +1 -0
  16. package/dist/subagents/external/harness.d.ts +22 -0
  17. package/dist/subagents/external/harness.js +22 -4
  18. package/dist/subagents/external/run.d.ts +23 -3
  19. package/dist/subagents/external/run.js +110 -123
  20. package/dist/subagents/external/settlement.d.ts +50 -0
  21. package/dist/subagents/external/settlement.js +123 -0
  22. package/dist/subagents/format.d.ts +4 -0
  23. package/dist/subagents/format.js +7 -0
  24. package/dist/subagents/runs.d.ts +70 -13
  25. package/dist/subagents/runs.js +195 -108
  26. package/dist/subagents/tool.d.ts +27 -2
  27. package/dist/subagents/tool.js +92 -48
  28. package/dist/subagents/verification-outcome.d.ts +26 -0
  29. package/dist/subagents/verification-outcome.js +16 -0
  30. package/dist/subagents/workspace-lease.d.ts +10 -1
  31. package/dist/subagents/workspace-lease.js +15 -2
  32. package/dist/tools/index.js +6 -0
  33. package/dist/tools/subagent-manage.d.ts +20 -6
  34. package/dist/tools/subagent-manage.js +86 -16
  35. package/package.json +1 -1
@@ -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
  }
@@ -471,9 +502,16 @@ function parseExternalAgent(entryName, filePath, frontmatter, body, name, descri
471
502
  const contextMode = parseContextMode(frontmatter.contextMode);
472
503
  if (contextMode.error)
473
504
  return { warning: `${entryName}: ${contextMode.error}` };
474
- 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");
475
510
  if (memoryMode.error)
476
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;
477
515
  const maxWallTimeSec = parsePositiveInteger(frontmatter.maxWallTimeSec, DEFAULT_EXTERNAL_MAX_WALL_TIME_SEC);
478
516
  const trimmedBody = body.trim();
479
517
  if (!trimmedBody)
@@ -488,14 +526,28 @@ function parseExternalAgent(entryName, filePath, frontmatter, body, name, descri
488
526
  const unavailable = executable && !isExecutableAvailable(executable)
489
527
  ? `executable "${executable}" was not found on PATH; install it or fix "command" in ${filePath}`
490
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;
491
542
  return {
543
+ warning: combinedWarning,
492
544
  agent: {
493
545
  name,
494
546
  description,
495
547
  systemPrompt: trimmedBody,
496
548
  tools: [],
497
549
  modelRef: undefined,
498
- externalModelRef: readOptionalTrimmedString(frontmatter.model),
550
+ externalModelRef,
499
551
  maxTurns: DEFAULT_MAX_TURNS,
500
552
  maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
501
553
  maxWallTimeSec: maxWallTimeSec.value,
@@ -606,6 +658,24 @@ subagentDefaultModelRef) {
606
658
  if (!baseConfig && (!overrides.systemPrompt || !overrides.systemPrompt.trim())) {
607
659
  return { error: 'Provide either "agent" or "systemPrompt" to define the sub-agent.' };
608
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
+ }
609
679
  const tools = overrides.tools
610
680
  ? validateToolNames(overrides.tools)
611
681
  : { tools: baseConfig?.tools ?? [...DEFAULT_SUB_AGENT_TOOLS] };
@@ -614,7 +684,7 @@ subagentDefaultModelRef) {
614
684
  }
615
685
  let model = baseConfig?.model;
616
686
  let modelRef = baseConfig?.modelRef;
617
- if (overrides.model?.trim()) {
687
+ if (effectiveRuntime !== "external" && overrides.model?.trim()) {
618
688
  const resolved = resolveModelReference(overrides.model.trim(), availableModels);
619
689
  if (!resolved.model) {
620
690
  return { error: resolved.error };
@@ -634,7 +704,6 @@ subagentDefaultModelRef) {
634
704
  if (effortOverride.error) {
635
705
  return { error: effortOverride.error };
636
706
  }
637
- const effectiveRuntime = baseConfig?.runtime ?? "internal";
638
707
  // An explicit `effort` replaces the whole budget tuple rather than merging field by
639
708
  // field, so a preset never produces a combination no preset describes. External is a
640
709
  // separate branch (P1-3): it has no turn/tool-call budget, and effort's wall-time numbers
@@ -725,3 +794,20 @@ export function formatSubAgentList(agents, maxItems = 12) {
725
794
  }
726
795
  return `${listed.join("\n")}\n- ... and ${agents.length - maxItems} more`;
727
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,6 +31,7 @@ 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");
@@ -38,7 +39,7 @@ export const claudeCodeHarness = {
38
39
  const [executable, ...rest] = input.argv;
39
40
  const existing = detectExistingFlags(rest);
40
41
  const effort = toClaudeEffort(input.thinkingLevel);
41
- const { argv: expandedRest, used } = expandPlaceholders(rest, {
42
+ const { argv: expandedRest, used, dropped, } = expandPlaceholders(rest, {
42
43
  $MODEL: input.model,
43
44
  $EFFORT: effort,
44
45
  $PROMPT_FILE: input.promptFile,
@@ -62,7 +63,13 @@ export const claudeCodeHarness = {
62
63
  presetSessionId = randomUUID();
63
64
  args.push("--session-id", presetSessionId);
64
65
  }
65
- 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
+ };
66
73
  },
67
74
  parseOutcome(input) {
68
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 {};
@@ -73,10 +73,19 @@ const PLACEHOLDERS = ["$MODEL", "$EFFORT", "$PROMPT_FILE", "$SYSTEM_PROMPT_FILE"
73
73
  * (D4). Returns which placeholders were actually found, so a harness knows whether it still needs
74
74
  * to *append* the corresponding flag (a placeholder present ⇒ never append; absent ⇒ append per
75
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.
76
83
  */
77
84
  export function expandPlaceholders(argv, values) {
78
85
  const used = new Set();
79
- const expanded = argv.map((token) => {
86
+ const dropped = [];
87
+ const expanded = [];
88
+ for (const token of argv) {
80
89
  let result = token;
81
90
  for (const placeholder of PLACEHOLDERS) {
82
91
  const value = values[placeholder];
@@ -85,7 +94,16 @@ export function expandPlaceholders(argv, values) {
85
94
  result = result.split(placeholder).join(value);
86
95
  }
87
96
  }
88
- return result;
89
- });
90
- 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).`);
91
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>;