@oyasmi/pipiclaw 0.9.1 → 0.9.2-beta.2

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 (167) hide show
  1. package/dist/agent/channel-runner.d.ts +15 -1
  2. package/dist/agent/channel-runner.js +76 -24
  3. package/dist/agent/effect-ledger.js +9 -2
  4. package/dist/agent/job-manager.d.ts +4 -0
  5. package/dist/agent/job-manager.js +17 -2
  6. package/dist/agent/prompt/manifest.d.ts +1 -1
  7. package/dist/agent/prompt/manifest.js +1 -1
  8. package/dist/agent/prompt/sections.js +8 -5
  9. package/dist/agent/session-events.d.ts +2 -0
  10. package/dist/agent/session-events.js +29 -14
  11. package/dist/agent/turn-recovery.js +2 -2
  12. package/dist/agent/type-guards.js +5 -1
  13. package/dist/agent/workspace-resources.d.ts +2 -2
  14. package/dist/agent/workspace-resources.js +41 -3
  15. package/dist/executor.d.ts +14 -0
  16. package/dist/executor.js +96 -24
  17. package/dist/file-store.d.ts +96 -0
  18. package/dist/file-store.js +189 -0
  19. package/dist/memory/consolidation.js +2 -26
  20. package/dist/memory/files.js +7 -7
  21. package/dist/memory/maintenance-jobs.js +2 -34
  22. package/dist/memory/maintenance-state.js +2 -1
  23. package/dist/memory/recall.d.ts +10 -0
  24. package/dist/memory/recall.js +15 -7
  25. package/dist/memory/session-search.js +6 -22
  26. package/dist/memory/transcript.d.ts +10 -0
  27. package/dist/memory/transcript.js +39 -0
  28. package/dist/playbooks/agent-delegation.md +7 -5
  29. package/dist/playbooks/background-jobs.md +1 -1
  30. package/dist/playbooks/catalog.d.ts +1 -1
  31. package/dist/playbooks/catalog.js +1 -1
  32. package/dist/playbooks/event-scheduling.md +2 -0
  33. package/dist/playbooks/memory-and-learning.md +11 -11
  34. package/dist/playbooks/runtime-orientation.md +3 -3
  35. package/dist/playbooks/task-driving.md +7 -7
  36. package/dist/playbooks/task-planning.md +5 -5
  37. package/dist/runtime/app-home.js +1 -1
  38. package/dist/runtime/bootstrap.js +10 -0
  39. package/dist/runtime/dingtalk.js +3 -2
  40. package/dist/runtime/durable-dispatch.d.ts +26 -1
  41. package/dist/runtime/durable-dispatch.js +51 -5
  42. package/dist/runtime/event-commands.js +7 -16
  43. package/dist/runtime/events.d.ts +4 -2
  44. package/dist/runtime/events.js +15 -20
  45. package/dist/runtime/subagent-commands.js +1 -1
  46. package/dist/runtime/task-commands.d.ts +1 -1
  47. package/dist/runtime/task-commands.js +17 -12
  48. package/dist/runtime/task-driver.js +2 -2
  49. package/dist/runtime/task-wake.d.ts +2 -2
  50. package/dist/runtime/task-wake.js +2 -2
  51. package/dist/security/block-message.d.ts +11 -0
  52. package/dist/security/block-message.js +12 -0
  53. package/dist/security/path-guard-check.d.ts +13 -0
  54. package/dist/security/path-guard-check.js +39 -0
  55. package/dist/security/path-guard.js +32 -14
  56. package/dist/settings.js +3 -2
  57. package/dist/shared/atomic-file.d.ts +17 -1
  58. package/dist/shared/atomic-file.js +50 -3
  59. package/dist/shared/duration.d.ts +2 -0
  60. package/dist/shared/duration.js +7 -0
  61. package/dist/shared/safe-id.d.ts +19 -0
  62. package/dist/shared/safe-id.js +24 -0
  63. package/dist/shared/text-utils.d.ts +1 -1
  64. package/dist/shared/text-utils.js +3 -8
  65. package/dist/shared/type-guards.d.ts +2 -0
  66. package/dist/shared/type-guards.js +4 -0
  67. package/dist/subagents/discovery.d.ts +44 -17
  68. package/dist/subagents/discovery.js +82 -111
  69. package/dist/subagents/external/claude-code.js +1 -3
  70. package/dist/subagents/external/harness.d.ts +1 -1
  71. package/dist/subagents/external/run.d.ts +6 -0
  72. package/dist/subagents/external/run.js +122 -58
  73. package/dist/subagents/external/settlement.d.ts +3 -0
  74. package/dist/subagents/external/settlement.js +19 -5
  75. package/dist/subagents/format.d.ts +3 -2
  76. package/dist/subagents/format.js +3 -7
  77. package/dist/subagents/runs.d.ts +45 -9
  78. package/dist/subagents/runs.js +184 -64
  79. package/dist/subagents/tool.d.ts +35 -24
  80. package/dist/subagents/tool.js +631 -577
  81. package/dist/subagents/verification-outcome.js +1 -1
  82. package/dist/subagents/workspace-lease.js +1 -1
  83. package/dist/tasks/artifact-subject.d.ts +30 -4
  84. package/dist/tasks/artifact-subject.js +257 -25
  85. package/dist/tasks/control.js +7 -9
  86. package/dist/tasks/ledger.d.ts +2 -2
  87. package/dist/tasks/ledger.js +3 -7
  88. package/dist/tasks/transitions.d.ts +5 -1
  89. package/dist/tasks/transitions.js +2 -2
  90. package/dist/tasks/verification.d.ts +24 -2
  91. package/dist/tasks/verification.js +113 -21
  92. package/dist/tools/bash.d.ts +0 -1
  93. package/dist/tools/bash.js +45 -40
  94. package/dist/tools/config.d.ts +6 -1
  95. package/dist/tools/config.js +9 -0
  96. package/dist/tools/edit.d.ts +2 -3
  97. package/dist/tools/edit.js +274 -86
  98. package/dist/tools/event-manage.d.ts +13 -7
  99. package/dist/tools/event-manage.js +52 -14
  100. package/dist/tools/glob-match.d.ts +11 -0
  101. package/dist/tools/glob-match.js +75 -0
  102. package/dist/tools/glob.d.ts +15 -0
  103. package/dist/tools/glob.js +113 -0
  104. package/dist/tools/grep.d.ts +0 -1
  105. package/dist/tools/grep.js +57 -42
  106. package/dist/tools/ignore-dirs.d.ts +6 -0
  107. package/dist/tools/ignore-dirs.js +15 -0
  108. package/dist/tools/index.d.ts +3 -0
  109. package/dist/tools/index.js +50 -40
  110. package/dist/tools/job.d.ts +0 -1
  111. package/dist/tools/job.js +1 -8
  112. package/dist/tools/line-index.d.ts +16 -0
  113. package/dist/tools/line-index.js +76 -0
  114. package/dist/tools/memory-manage.d.ts +20 -8
  115. package/dist/tools/memory-manage.js +65 -92
  116. package/dist/tools/presentation.d.ts +2 -0
  117. package/dist/tools/presentation.js +109 -0
  118. package/dist/tools/read.d.ts +2 -2
  119. package/dist/tools/read.js +97 -133
  120. package/dist/tools/registry.d.ts +4 -1
  121. package/dist/tools/registry.js +89 -22
  122. package/dist/tools/send-media.d.ts +6 -6
  123. package/dist/tools/send-media.js +16 -49
  124. package/dist/tools/session-search.d.ts +0 -1
  125. package/dist/tools/session-search.js +0 -1
  126. package/dist/tools/skill-security.d.ts +0 -2
  127. package/dist/tools/skill-security.js +0 -24
  128. package/dist/tools/skill.d.ts +31 -0
  129. package/dist/tools/skill.js +153 -0
  130. package/dist/tools/subagent-manage.d.ts +6 -5
  131. package/dist/tools/subagent-manage.js +60 -60
  132. package/dist/tools/task-manage/create.d.ts +2 -2
  133. package/dist/tools/task-manage/create.js +1 -3
  134. package/dist/tools/task-manage/lifecycle.d.ts +9 -6
  135. package/dist/tools/task-manage/lifecycle.js +56 -60
  136. package/dist/tools/task-manage/schema.d.ts +27 -15
  137. package/dist/tools/task-manage/schema.js +58 -74
  138. package/dist/tools/task-manage/shared.d.ts +11 -6
  139. package/dist/tools/task-manage/shared.js +30 -21
  140. package/dist/tools/task-manage/types.d.ts +14 -15
  141. package/dist/tools/task-manage/verification.d.ts +5 -5
  142. package/dist/tools/task-manage/verification.js +18 -15
  143. package/dist/tools/task-manage.d.ts +8 -11
  144. package/dist/tools/task-manage.js +63 -50
  145. package/dist/tools/tool-details.d.ts +17 -1
  146. package/dist/tools/tool-details.js +24 -0
  147. package/dist/tools/truncate.d.ts +5 -5
  148. package/dist/tools/truncate.js +5 -5
  149. package/dist/tools/web-fetch.d.ts +0 -1
  150. package/dist/tools/web-fetch.js +0 -1
  151. package/dist/tools/web-search.d.ts +0 -1
  152. package/dist/tools/web-search.js +0 -1
  153. package/dist/tools/write-content.d.ts +3 -3
  154. package/dist/tools/write-content.js +12 -51
  155. package/dist/tools/write.d.ts +2 -3
  156. package/dist/tools/write.js +3 -4
  157. package/dist/tui/pitui-frontend.js +3 -3
  158. package/dist/usage/ledger.js +7 -4
  159. package/examples/sub-agents/README.md +13 -13
  160. package/examples/sub-agents/documenter.md +2 -1
  161. package/examples/sub-agents/reviewer.md +2 -0
  162. package/examples/sub-agents/scout.md +2 -1
  163. package/examples/sub-agents/verifier.md +6 -4
  164. package/examples/sub-agents/worker.md +2 -1
  165. package/package.json +5 -5
  166. package/dist/tools/skill-manage.d.ts +0 -41
  167. package/dist/tools/skill-manage.js +0 -232
@@ -0,0 +1,24 @@
1
+ import { join, resolve, sep } from "node:path";
2
+ /** Validate/normalize an id (a file basename minus its suffix), rejecting path traversal. */
3
+ export function normalizeSafeId(id, options) {
4
+ const trimmed = id.trim();
5
+ const normalized = trimmed.endsWith(options.suffix) ? trimmed.slice(0, -options.suffix.length) : trimmed;
6
+ if (!normalized || normalized === "." || normalized === ".." || !options.pattern.test(normalized)) {
7
+ throw new Error(`Invalid ${options.label}: ${id}`);
8
+ }
9
+ return normalized;
10
+ }
11
+ /**
12
+ * {@link normalizeSafeId}, then resolves the id to a path confined under `dir` — defense in
13
+ * depth beyond the pattern check, for the one caller (`event_manage`) whose directory is
14
+ * agent-writable.
15
+ */
16
+ export function resolveSafeIdPath(dir, id, options) {
17
+ const normalizedId = normalizeSafeId(id, options);
18
+ const resolvedDir = resolve(dir);
19
+ const path = resolve(resolvedDir, `${normalizedId}${options.suffix}`);
20
+ if (path !== join(resolvedDir, `${normalizedId}${options.suffix}`) || !path.startsWith(`${resolvedDir}${sep}`)) {
21
+ throw new Error(`Invalid ${options.label}: ${id}`);
22
+ }
23
+ return { id: normalizedId, path };
24
+ }
@@ -2,11 +2,11 @@ import type { AssistantMessage } from "@earendil-works/pi-ai";
2
2
  export declare function clipText(text: string, maxChars: number, opts?: {
3
3
  headRatio?: number;
4
4
  omitHint?: string;
5
+ collapseWhitespace?: boolean;
5
6
  }): string;
6
7
  export declare function truncate(text: string, maxLen: number): string;
7
8
  export declare const HAN_REGEX: RegExp;
8
9
  /** Strip a trailing `.json` from an event filename to get its logical name. */
9
10
  export declare function eventNameFromFilename(filename: string): string;
10
- export declare function extractLabelFromArgs(args: unknown): string | null;
11
11
  export declare function errorMessage(err: unknown): string;
12
12
  export declare function extractAssistantText(message: AssistantMessage): string;
@@ -1,5 +1,7 @@
1
1
  export function clipText(text, maxChars, opts = {}) {
2
- const normalized = text.replace(/\s+\n/g, "\n").replace(/\r/g, "").trim();
2
+ const normalized = opts.collapseWhitespace
3
+ ? text.replace(/\s+/g, " ").trim()
4
+ : text.replace(/\s+\n/g, "\n").replace(/\r/g, "").trim();
3
5
  if (normalized.length <= maxChars) {
4
6
  return normalized;
5
7
  }
@@ -24,13 +26,6 @@ export const HAN_REGEX = /\p{Script=Han}/u;
24
26
  export function eventNameFromFilename(filename) {
25
27
  return filename.endsWith(".json") ? filename.slice(0, -".json".length) : filename;
26
28
  }
27
- export function extractLabelFromArgs(args) {
28
- if (!args || typeof args !== "object" || !("label" in args)) {
29
- return null;
30
- }
31
- const label = args.label;
32
- return typeof label === "string" && label.trim() ? label.trim() : null;
33
- }
34
29
  export function errorMessage(err) {
35
30
  return err instanceof Error ? err.message : String(err);
36
31
  }
@@ -1,5 +1,7 @@
1
1
  import type { AgentMessage } from "@earendil-works/pi-agent-core";
2
2
  import type { Message } from "@earendil-works/pi-ai";
3
3
  export declare function isRecord(value: unknown): value is Record<string, unknown>;
4
+ /** Like {@link isRecord}, but false for arrays — for parsing JSON where an array is not a valid shape. */
5
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
4
6
  export declare function isStandardAgentMessage(message: AgentMessage): message is Message;
5
7
  export declare function buildStandardMessages(messages: AgentMessage[]): Message[];
@@ -1,6 +1,10 @@
1
1
  export function isRecord(value) {
2
2
  return typeof value === "object" && value !== null;
3
3
  }
4
+ /** Like {@link isRecord}, but false for arrays — for parsing JSON where an array is not a valid shape. */
5
+ export function isPlainObject(value) {
6
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7
+ }
4
8
  export function isStandardAgentMessage(message) {
5
9
  return (typeof message === "object" &&
6
10
  message !== null &&
@@ -43,14 +43,6 @@ export declare const SUB_AGENT_EFFORT_PRESETS: {
43
43
  readonly bashTimeoutSec: 180;
44
44
  };
45
45
  };
46
- /**
47
- * External runs have no turn/tool-call budget (D5) — `effort` only ever moves wall time, and at
48
- * external scale, not the internal tuple above (P1-3: those numbers previously leaked onto
49
- * external roles unchanged, where `deep` at 900s was *shorter* than the external default).
50
- * `standard` and an unset `effort` both keep the role's own `maxWallTimeSec` (or the external
51
- * default), so this only has entries for the two presets that actually override it.
52
- */
53
- export declare const SUB_AGENT_EXTERNAL_EFFORT_WALL_TIME_SEC: Partial<Record<keyof typeof SUB_AGENT_EFFORT_PRESETS, number>>;
54
46
  export type SubAgentEffort = keyof typeof SUB_AGENT_EFFORT_PRESETS;
55
47
  /**
56
48
  * The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
@@ -109,17 +101,30 @@ export interface SubAgentDiscoveryResult {
109
101
  agents: SubAgentConfig[];
110
102
  warnings: string[];
111
103
  }
112
- export interface SubAgentInvocationOverrides {
113
- agent?: string;
114
- name?: string;
115
- systemPrompt?: string;
104
+ /**
105
+ * `subagent` (role-based) invocation surface (spec 046, D2.1). Deliberately has no override
106
+ * fields beyond `purpose`: everything else a configured role could vary — tools, model, effort,
107
+ * context, thinkingLevel, mutates — lives in the role file, which is the deployer's decision, not
108
+ * a per-call one. This is what makes "external role + tools/model/mutates" unrepresentable at the
109
+ * type level instead of rejected at runtime (spec 042 D3's three checks are now dead by construction).
110
+ */
111
+ export interface ConfiguredRoleOverrides {
112
+ agent: string;
113
+ /** Drives the thinkingLevel default: "verify" defaults on, everything else stays off. */
114
+ purpose?: string;
115
+ }
116
+ /**
117
+ * `subagent_inline` invocation surface (spec 046, D2.1) — a one-off executor with no role file,
118
+ * so every field a role file would otherwise supply is a call-time override here instead.
119
+ */
120
+ export interface InlineAgentOverrides {
121
+ systemPrompt: string;
116
122
  tools?: string[];
117
123
  model?: string;
118
124
  /** Named budget preset; wins over frontmatter numbers as a whole tuple, never field by field. */
119
125
  effort?: string;
120
126
  /** Collapsed `contextMode` + `memory`; see SubAgentContextChoice. */
121
127
  context?: string;
122
- paths?: string[];
123
128
  thinkingLevel?: string;
124
129
  /** Drives the thinkingLevel default: "verify" defaults on, everything else stays off. */
125
130
  purpose?: string;
@@ -158,12 +163,34 @@ type FieldSupport = "supported" | "rejected";
158
163
  */
159
164
  export declare const ROLE_FIELD_MATRIX: Record<string, Record<SubAgentRuntime, FieldSupport>>;
160
165
  export declare function discoverSubAgents(workspaceDir: string, availableModels: Model<Api>[]): SubAgentDiscoveryResult;
161
- export declare function resolveSubAgentConfig(availableModels: Model<Api>[], currentModel: Model<Api>, predefinedAgents: SubAgentConfig[], overrides: SubAgentInvocationOverrides,
162
166
  /**
163
- * `settings.subagentModel` (spec 032 D5): used only when neither the invocation nor the
164
- * predefined agent's frontmatter names a model. Unset/blank is "not configured" — the
165
- * caller (tool.ts) already normalizes that, this function just treats undefined as absent.
167
+ * Resolve a `subagent` (role-based) invocation (spec 046, D2.1).
168
+ *
169
+ * Everything the old combined resolver used to override for a configured role — `tools`,
170
+ * `model`, `effort`, `context`, `mutates` — now has nowhere to come from but the role file
171
+ * itself, so this is a lookup plus the two facts a role file cannot pin down: the default model
172
+ * (parent's current model, or `settings.subagentModel`) and the purpose-driven thinkingLevel
173
+ * default. Spec 042 D3's three "external + override" rejections no longer apply: `ConfiguredRoleOverrides`
174
+ * has no `tools`/`model`/`mutates` field to reject in the first place.
175
+ */
176
+ export declare function resolveConfiguredRole(availableModels: Model<Api>[], currentModel: Model<Api>, predefinedAgents: SubAgentConfig[], overrides: ConfiguredRoleOverrides,
177
+ /**
178
+ * `settings.subagentModel` (spec 032 D5): used only when neither the role file's frontmatter
179
+ * nor this call names a model (it cannot — there is no override field for it).
180
+ */
181
+ subagentDefaultModelRef?: string): {
182
+ config?: ResolvedSubAgentConfig;
183
+ error?: string;
184
+ };
185
+ /**
186
+ * Resolve a `subagent_inline` invocation (spec 046, D2.1) — a one-off executor with no role
187
+ * file. `runtime` is always `"internal"` here: only a configured role file can name `external`,
188
+ * and `InlineAgentOverrides` has no field for it, so the old function's external branches
189
+ * (budget table, unset-by-default thinkingLevel, model/tools/mutates rejections) simply do not
190
+ * apply to this path and are not reproduced here.
166
191
  */
192
+ export declare function resolveInlineAgent(availableModels: Model<Api>[], currentModel: Model<Api>, overrides: InlineAgentOverrides,
193
+ /** `settings.subagentModel` (spec 032 D5): used only when this call does not name a model. */
167
194
  subagentDefaultModelRef?: string): {
168
195
  config?: ResolvedSubAgentConfig;
169
196
  error?: string;
@@ -43,17 +43,6 @@ export const SUB_AGENT_EFFORT_PRESETS = {
43
43
  },
44
44
  deep: { maxTurns: 48, maxToolCalls: 96, maxWallTimeSec: 900, bashTimeoutSec: 180 },
45
45
  };
46
- /**
47
- * External runs have no turn/tool-call budget (D5) — `effort` only ever moves wall time, and at
48
- * external scale, not the internal tuple above (P1-3: those numbers previously leaked onto
49
- * external roles unchanged, where `deep` at 900s was *shorter* than the external default).
50
- * `standard` and an unset `effort` both keep the role's own `maxWallTimeSec` (or the external
51
- * default), so this only has entries for the two presets that actually override it.
52
- */
53
- export const SUB_AGENT_EXTERNAL_EFFORT_WALL_TIME_SEC = {
54
- quick: 600,
55
- deep: 5400,
56
- };
57
46
  const ALLOWED_EFFORTS = Object.keys(SUB_AGENT_EFFORT_PRESETS);
58
47
  /**
59
48
  * The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
@@ -640,59 +629,85 @@ export function discoverSubAgents(workspaceDir, availableModels) {
640
629
  const result = loadAgentsFromDir(directory, availableModels);
641
630
  return { directory, agents: result.agents, warnings: result.warnings };
642
631
  }
643
- export function resolveSubAgentConfig(availableModels, currentModel, predefinedAgents, overrides,
644
632
  /**
645
- * `settings.subagentModel` (spec 032 D5): used only when neither the invocation nor the
646
- * predefined agent's frontmatter names a model. Unset/blank is "not configured" — the
647
- * caller (tool.ts) already normalizes that, this function just treats undefined as absent.
633
+ * Resolve a `subagent` (role-based) invocation (spec 046, D2.1).
634
+ *
635
+ * Everything the old combined resolver used to override for a configured role — `tools`,
636
+ * `model`, `effort`, `context`, `mutates` — now has nowhere to come from but the role file
637
+ * itself, so this is a lookup plus the two facts a role file cannot pin down: the default model
638
+ * (parent's current model, or `settings.subagentModel`) and the purpose-driven thinkingLevel
639
+ * default. Spec 042 D3's three "external + override" rejections no longer apply: `ConfiguredRoleOverrides`
640
+ * has no `tools`/`model`/`mutates` field to reject in the first place.
641
+ */
642
+ export function resolveConfiguredRole(availableModels, currentModel, predefinedAgents, overrides,
643
+ /**
644
+ * `settings.subagentModel` (spec 032 D5): used only when neither the role file's frontmatter
645
+ * nor this call names a model (it cannot — there is no override field for it).
648
646
  */
649
647
  subagentDefaultModelRef) {
650
- const baseConfig = overrides.agent ? predefinedAgents.find((agent) => agent.name === overrides.agent) : undefined;
651
- if (overrides.agent && !baseConfig) {
648
+ const baseConfig = predefinedAgents.find((agent) => agent.name === overrides.agent);
649
+ if (!baseConfig) {
652
650
  const available = predefinedAgents.length > 0 ? predefinedAgents.map((agent) => agent.name).join(", ") : "none";
653
651
  return { error: `Unknown sub-agent "${overrides.agent}". Available sub-agents: ${available}.` };
654
652
  }
655
653
  // Listed, never dropped (spec 040, D5) — but refused here with the reason, not a fallback.
656
- if (baseConfig?.unavailable) {
654
+ if (baseConfig.unavailable) {
657
655
  return { error: `Sub-agent "${baseConfig.name}" is currently unavailable: ${baseConfig.unavailable}` };
658
656
  }
659
- if (!baseConfig && (!overrides.systemPrompt || !overrides.systemPrompt.trim())) {
660
- return { error: 'Provide either "agent" or "systemPrompt" to define the sub-agent.' };
661
- }
662
- const effectiveRuntime = baseConfig?.runtime ?? "internal";
663
- // Spec 042 D3: the invocation-side counterpart to the role-file field matrix (`ROLE_FIELD_MATRIX`
664
- // above) — a field only meaningful for one runtime is rejected outright when the resolved role
665
- // is the other, not silently ignored. `tools` and `model` were previously accepted and either
666
- // dropped on the floor or — for `model` — resolved against `models.json` and made to fail a
667
- // dispatch for a reason that has nothing to do with the external role actually named.
668
- if (effectiveRuntime === "external" && overrides.tools !== undefined) {
669
- return {
670
- error: `Sub-agent "${baseConfig?.name}" is external; its tool boundary comes from its own ` +
671
- 'command (e.g. "--sandbox read-only"), not the "tools" invocation parameter, which has no effect on external roles.',
672
- };
657
+ let model = baseConfig.model;
658
+ let modelRef = baseConfig.modelRef;
659
+ if (!model && subagentDefaultModelRef) {
660
+ const resolved = resolveModelReference(subagentDefaultModelRef, availableModels);
661
+ if (!resolved.model) {
662
+ return { error: resolved.error };
663
+ }
664
+ model = resolved.model;
665
+ modelRef = formatModelReference(resolved.model);
673
666
  }
674
- if (effectiveRuntime === "external" && overrides.model?.trim()) {
675
- return {
676
- error: `Sub-agent "${baseConfig?.name}" is external; its model can only be set in the role file's ` +
677
- '"model" frontmatter. The "model" invocation parameter has no effect on external roles and is never resolved against models.json.',
678
- };
667
+ const purpose = overrides.purpose === "verify" ? "verify" : "work";
668
+ // External work is not defaulted: pipiclaw has no standing to pick a reasoning effort for
669
+ // another CLI's own configuration. External verify still defaults — it is the last unattended
670
+ // gate before an attestation is trusted, and "whatever that machine happens to have configured"
671
+ // is not an acceptable substitute for real reasoning.
672
+ const thinkingLevel = baseConfig.thinkingLevel ??
673
+ (baseConfig.runtime === "external" && purpose !== "verify" ? undefined : DEFAULT_THINKING_LEVEL);
674
+ const mutates = baseConfig.mutates ?? inferMutatesFromTools(baseConfig.tools);
675
+ return {
676
+ config: {
677
+ ...baseConfig,
678
+ model: model ?? currentModel,
679
+ modelRef: modelRef ?? formatModelReference(model ?? currentModel),
680
+ thinkingLevel,
681
+ source: "predefined",
682
+ mutates,
683
+ },
684
+ };
685
+ }
686
+ /**
687
+ * Resolve a `subagent_inline` invocation (spec 046, D2.1) — a one-off executor with no role
688
+ * file. `runtime` is always `"internal"` here: only a configured role file can name `external`,
689
+ * and `InlineAgentOverrides` has no field for it, so the old function's external branches
690
+ * (budget table, unset-by-default thinkingLevel, model/tools/mutates rejections) simply do not
691
+ * apply to this path and are not reproduced here.
692
+ */
693
+ export function resolveInlineAgent(availableModels, currentModel, overrides,
694
+ /** `settings.subagentModel` (spec 032 D5): used only when this call does not name a model. */
695
+ subagentDefaultModelRef) {
696
+ const systemPrompt = overrides.systemPrompt.trim();
697
+ if (!systemPrompt) {
698
+ return { error: "Sub-agent system prompt cannot be empty." };
679
699
  }
680
- // External `mutates` is the role file's own self-declaration (checked against its harness/command),
681
- // same reasoning as `model` above — the caller cannot override what the external role attests about itself.
682
- if (effectiveRuntime === "external" && overrides.mutates !== undefined) {
683
- return {
684
- error: `Sub-agent "${baseConfig?.name}" is external; "mutates" comes from its role file, not the invocation parameter.`,
685
- };
700
+ const promptLengthError = validateSubAgentSystemPrompt(systemPrompt, "Inline sub-agent systemPrompt");
701
+ if (promptLengthError) {
702
+ return { error: promptLengthError };
686
703
  }
687
- const tools = overrides.tools
688
- ? validateToolNames(overrides.tools)
689
- : { tools: baseConfig?.tools ?? [...DEFAULT_SUB_AGENT_TOOLS] };
704
+ const tools = overrides.tools ? validateToolNames(overrides.tools) : { tools: [...DEFAULT_SUB_AGENT_TOOLS] };
690
705
  if (tools.error) {
691
706
  return { error: tools.error };
692
707
  }
693
- let model = baseConfig?.model;
694
- let modelRef = baseConfig?.modelRef;
695
- if (effectiveRuntime !== "external" && overrides.model?.trim()) {
708
+ let model;
709
+ let modelRef;
710
+ if (overrides.model?.trim()) {
696
711
  const resolved = resolveModelReference(overrides.model.trim(), availableModels);
697
712
  if (!resolved.model) {
698
713
  return { error: resolved.error };
@@ -700,7 +715,7 @@ subagentDefaultModelRef) {
700
715
  model = resolved.model;
701
716
  modelRef = formatModelReference(resolved.model);
702
717
  }
703
- else if (!model && subagentDefaultModelRef) {
718
+ else if (subagentDefaultModelRef) {
704
719
  const resolved = resolveModelReference(subagentDefaultModelRef, availableModels);
705
720
  if (!resolved.model) {
706
721
  return { error: resolved.error };
@@ -712,76 +727,40 @@ subagentDefaultModelRef) {
712
727
  if (effortOverride.error) {
713
728
  return { error: effortOverride.error };
714
729
  }
715
- // An explicit `effort` replaces the whole budget tuple rather than merging field by
716
- // field, so a preset never produces a combination no preset describes. External is a
717
- // separate branch (P1-3): it has no turn/tool-call budget, and effort's wall-time numbers
718
- // are at external scale, not the internal tuple.
719
- const budget = effectiveRuntime === "external"
720
- ? {
730
+ const budget = effortOverride.value
731
+ ? SUB_AGENT_EFFORT_PRESETS[effortOverride.value]
732
+ : {
721
733
  maxTurns: DEFAULT_MAX_TURNS,
722
734
  maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
723
- maxWallTimeSec: (effortOverride.value && SUB_AGENT_EXTERNAL_EFFORT_WALL_TIME_SEC[effortOverride.value]) ??
724
- baseConfig?.maxWallTimeSec ??
725
- DEFAULT_EXTERNAL_MAX_WALL_TIME_SEC,
735
+ maxWallTimeSec: DEFAULT_MAX_WALL_TIME_SEC,
726
736
  bashTimeoutSec: DEFAULT_BASH_TIMEOUT_SEC,
727
- }
728
- : effortOverride.value
729
- ? SUB_AGENT_EFFORT_PRESETS[effortOverride.value]
730
- : {
731
- maxTurns: baseConfig?.maxTurns ?? DEFAULT_MAX_TURNS,
732
- maxToolCalls: baseConfig?.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS,
733
- maxWallTimeSec: baseConfig?.maxWallTimeSec ?? DEFAULT_MAX_WALL_TIME_SEC,
734
- bashTimeoutSec: baseConfig?.bashTimeoutSec ?? DEFAULT_BASH_TIMEOUT_SEC,
735
- };
737
+ };
736
738
  const contextOverride = parseContextChoice(overrides.context);
737
739
  if (contextOverride.error) {
738
740
  return { error: contextOverride.error };
739
741
  }
740
- const contextMode = contextOverride.value?.contextMode ?? baseConfig?.contextMode ?? "isolated";
741
- const memory = contextOverride.value?.memory ?? baseConfig?.memory ?? (contextMode === "contextual" ? "relevant" : "none");
742
- const pathsOverride = overrides.paths ? parseStringList(overrides.paths, "paths") : undefined;
743
- if (pathsOverride?.error) {
744
- return { error: pathsOverride.error };
745
- }
746
- const paths = pathsOverride?.values ?? baseConfig?.paths ?? [];
742
+ const contextMode = contextOverride.value?.contextMode ?? "isolated";
743
+ const memory = contextOverride.value?.memory ?? (contextMode === "contextual" ? "relevant" : "none");
747
744
  const thinkingLevelOverride = overrides.thinkingLevel ? parseThinkingLevel(overrides.thinkingLevel) : undefined;
748
745
  if (thinkingLevelOverride?.error) {
749
746
  return { error: thinkingLevelOverride.error };
750
747
  }
751
- const purpose = overrides.purpose === "verify" ? "verify" : "work";
752
- const explicitThinkingLevel = thinkingLevelOverride?.value ?? baseConfig?.thinkingLevel;
753
- // External work is not defaulted: pipiclaw has no standing to pick a reasoning effort for
754
- // another CLI's own configuration. External verify still defaults — it is the last unattended
755
- // gate before an attestation is trusted, and "whatever that machine happens to have configured"
756
- // is not an acceptable substitute for real reasoning.
757
- const thinkingLevel = explicitThinkingLevel ??
758
- (effectiveRuntime === "external" && purpose !== "verify" ? undefined : DEFAULT_THINKING_LEVEL);
748
+ const thinkingLevel = thinkingLevelOverride?.value ?? DEFAULT_THINKING_LEVEL;
759
749
  const mutatesOverride = parseMutates(overrides.mutates);
760
750
  if (mutatesOverride.error) {
761
751
  return { error: mutatesOverride.error };
762
752
  }
763
- const mutates = mutatesOverride.value ?? baseConfig?.mutates ?? inferMutatesFromTools(tools.tools);
764
- // Same rationale as the predefined-role bashWithoutMutatesWarning above (D6): `bash` can write
765
- // regardless of what `tools` otherwise implies. Inline roles have no frontmatter to declare it
766
- // in, so the warning goes back to the model in the result text instead of a discovery-time log.
767
- const bashWithoutMutatesWarning = !baseConfig && tools.tools.includes("bash") && mutatesOverride.value === undefined
753
+ const mutates = mutatesOverride.value ?? inferMutatesFromTools(tools.tools);
754
+ // Inline roles have no frontmatter to declare `mutates` in, so this warning goes back to the
755
+ // model in the result text instead of a discovery-time log (D6 in the pre-split resolver).
756
+ const bashWithoutMutatesWarning = tools.tools.includes("bash") && mutatesOverride.value === undefined
768
757
  ? 'tools include bash but "mutates" is not declared; if this task writes to the workspace, pass mutates: "write" so it takes the exclusive workspace write lease'
769
758
  : undefined;
770
- const systemPrompt = overrides.systemPrompt?.trim() || baseConfig?.systemPrompt || "";
771
- if (!systemPrompt) {
772
- return { error: "Sub-agent system prompt cannot be empty." };
773
- }
774
- if (overrides.systemPrompt?.trim()) {
775
- const promptLengthError = validateSubAgentSystemPrompt(overrides.systemPrompt.trim(), "Inline sub-agent systemPrompt");
776
- if (promptLengthError) {
777
- return { error: promptLengthError };
778
- }
779
- }
780
759
  return {
781
760
  warning: bashWithoutMutatesWarning,
782
761
  config: {
783
- name: overrides.name?.trim() || baseConfig?.name || "dynamic-subagent",
784
- description: baseConfig?.description || "Inline sub-agent",
762
+ name: "dynamic-subagent",
763
+ description: "Inline sub-agent",
785
764
  systemPrompt,
786
765
  tools: tools.tools,
787
766
  model: model ?? currentModel,
@@ -792,19 +771,11 @@ subagentDefaultModelRef) {
792
771
  bashTimeoutSec: budget.bashTimeoutSec,
793
772
  contextMode,
794
773
  memory,
795
- paths,
774
+ paths: [],
796
775
  thinkingLevel,
797
- filePath: baseConfig?.filePath,
798
- source: baseConfig ? "predefined" : "inline",
799
- runtime: baseConfig?.runtime ?? "internal",
800
- harness: baseConfig?.harness,
801
- command: baseConfig?.command,
802
- shell: baseConfig?.shell,
803
- env: baseConfig?.env,
804
- workload: baseConfig?.workload,
776
+ source: "inline",
777
+ runtime: "internal",
805
778
  mutates,
806
- externalModelRef: baseConfig?.externalModelRef,
807
- unavailable: baseConfig?.unavailable,
808
779
  },
809
780
  };
810
781
  }
@@ -1,4 +1,5 @@
1
1
  import { randomUUID } from "node:crypto";
2
+ import { isRecord } from "../../shared/type-guards.js";
2
3
  import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, } from "./harness.js";
3
4
  /**
4
5
  * `claude-code` harness (spec 040, D3/D4). Same one-prompt-one-process model as codex-cli; the
@@ -29,9 +30,6 @@ function toClaudeEffort(level) {
29
30
  return undefined;
30
31
  return THINKING_LEVEL_TO_CLAUDE_EFFORT[level] ?? level;
31
32
  }
32
- function isRecord(value) {
33
- return typeof value === "object" && value !== null;
34
- }
35
33
  export const claudeCodeHarness = {
36
34
  id: "claude-code",
37
35
  // 2: parseOutcome now falls back to the last streamed `assistant` message's text/usage when a
@@ -18,7 +18,7 @@ export interface ExternalInvocationInput {
18
18
  /** Path to the role's system-prompt file (`<artifactDir>/system-prompt.txt`), for harnesses
19
19
  * that reference it by flag (e.g. claude-code's `--append-system-prompt-file`). */
20
20
  systemPromptFile: string;
21
- /** Set when this invocation continues an earlier run (`subagent_manage op=follow_up`, D6). */
21
+ /** Set when this invocation continues an earlier run (`subagent_run op=follow_up`, D6). */
22
22
  resumeSessionId?: string;
23
23
  }
24
24
  export interface BuildInvocationResult {
@@ -1,5 +1,6 @@
1
1
  import { spawn as nodeSpawn } from "node:child_process";
2
2
  import type { SecurityConfig } from "../../security/types.js";
3
+ import { probeCliVersion, readProcessStartTime } from "../../shared/host-process.js";
3
4
  import type { SubAgentThinkingLevel } from "../discovery.js";
4
5
  import { type RunMutates } from "../runs.js";
5
6
  /**
@@ -51,6 +52,11 @@ export interface LaunchExternalRunInput {
51
52
  securityConfig: SecurityConfig;
52
53
  /** Test seam: inject a fake `child_process.spawn`. */
53
54
  spawnFn?: typeof nodeSpawn;
55
+ /** Test seam: delay or replace the post-spawn process identity probe. The pid is persisted before
56
+ * this probe starts, so a daemon restart cannot mistake a live child for an intent-only run. */
57
+ readProcessStartTimeFn?: typeof readProcessStartTime;
58
+ /** Test seam: delay or replace the best-effort CLI version probe. */
59
+ probeCliVersionFn?: typeof probeCliVersion;
54
60
  }
55
61
  /**
56
62
  * Spec 042 D2: a pre-run failure (file open, spawn, or a cancel that lands before the process