@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.
- package/dist/agent/channel-runner.d.ts +15 -1
- package/dist/agent/channel-runner.js +76 -24
- package/dist/agent/effect-ledger.js +9 -2
- package/dist/agent/job-manager.d.ts +4 -0
- package/dist/agent/job-manager.js +17 -2
- package/dist/agent/prompt/manifest.d.ts +1 -1
- package/dist/agent/prompt/manifest.js +1 -1
- package/dist/agent/prompt/sections.js +8 -5
- package/dist/agent/session-events.d.ts +2 -0
- package/dist/agent/session-events.js +29 -14
- package/dist/agent/turn-recovery.js +2 -2
- package/dist/agent/type-guards.js +5 -1
- package/dist/agent/workspace-resources.d.ts +2 -2
- package/dist/agent/workspace-resources.js +41 -3
- package/dist/executor.d.ts +14 -0
- package/dist/executor.js +96 -24
- package/dist/file-store.d.ts +96 -0
- package/dist/file-store.js +189 -0
- package/dist/memory/consolidation.js +2 -26
- package/dist/memory/files.js +7 -7
- package/dist/memory/maintenance-jobs.js +2 -34
- package/dist/memory/maintenance-state.js +2 -1
- package/dist/memory/recall.d.ts +10 -0
- package/dist/memory/recall.js +15 -7
- package/dist/memory/session-search.js +6 -22
- package/dist/memory/transcript.d.ts +10 -0
- package/dist/memory/transcript.js +39 -0
- package/dist/playbooks/agent-delegation.md +7 -5
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.d.ts +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/event-scheduling.md +2 -0
- package/dist/playbooks/memory-and-learning.md +11 -11
- package/dist/playbooks/runtime-orientation.md +3 -3
- package/dist/playbooks/task-driving.md +7 -7
- package/dist/playbooks/task-planning.md +5 -5
- package/dist/runtime/app-home.js +1 -1
- package/dist/runtime/bootstrap.js +10 -0
- package/dist/runtime/dingtalk.js +3 -2
- package/dist/runtime/durable-dispatch.d.ts +26 -1
- package/dist/runtime/durable-dispatch.js +51 -5
- package/dist/runtime/event-commands.js +7 -16
- package/dist/runtime/events.d.ts +4 -2
- package/dist/runtime/events.js +15 -20
- package/dist/runtime/subagent-commands.js +1 -1
- package/dist/runtime/task-commands.d.ts +1 -1
- package/dist/runtime/task-commands.js +17 -12
- package/dist/runtime/task-driver.js +2 -2
- package/dist/runtime/task-wake.d.ts +2 -2
- package/dist/runtime/task-wake.js +2 -2
- package/dist/security/block-message.d.ts +11 -0
- package/dist/security/block-message.js +12 -0
- package/dist/security/path-guard-check.d.ts +13 -0
- package/dist/security/path-guard-check.js +39 -0
- package/dist/security/path-guard.js +32 -14
- package/dist/settings.js +3 -2
- package/dist/shared/atomic-file.d.ts +17 -1
- package/dist/shared/atomic-file.js +50 -3
- package/dist/shared/duration.d.ts +2 -0
- package/dist/shared/duration.js +7 -0
- package/dist/shared/safe-id.d.ts +19 -0
- package/dist/shared/safe-id.js +24 -0
- package/dist/shared/text-utils.d.ts +1 -1
- package/dist/shared/text-utils.js +3 -8
- package/dist/shared/type-guards.d.ts +2 -0
- package/dist/shared/type-guards.js +4 -0
- package/dist/subagents/discovery.d.ts +44 -17
- package/dist/subagents/discovery.js +82 -111
- package/dist/subagents/external/claude-code.js +1 -3
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/run.d.ts +6 -0
- package/dist/subagents/external/run.js +122 -58
- package/dist/subagents/external/settlement.d.ts +3 -0
- package/dist/subagents/external/settlement.js +19 -5
- package/dist/subagents/format.d.ts +3 -2
- package/dist/subagents/format.js +3 -7
- package/dist/subagents/runs.d.ts +45 -9
- package/dist/subagents/runs.js +184 -64
- package/dist/subagents/tool.d.ts +35 -24
- package/dist/subagents/tool.js +631 -577
- package/dist/subagents/verification-outcome.js +1 -1
- package/dist/subagents/workspace-lease.js +1 -1
- package/dist/tasks/artifact-subject.d.ts +30 -4
- package/dist/tasks/artifact-subject.js +257 -25
- package/dist/tasks/control.js +7 -9
- package/dist/tasks/ledger.d.ts +2 -2
- package/dist/tasks/ledger.js +3 -7
- package/dist/tasks/transitions.d.ts +5 -1
- package/dist/tasks/transitions.js +2 -2
- package/dist/tasks/verification.d.ts +24 -2
- package/dist/tasks/verification.js +113 -21
- package/dist/tools/bash.d.ts +0 -1
- package/dist/tools/bash.js +45 -40
- package/dist/tools/config.d.ts +6 -1
- package/dist/tools/config.js +9 -0
- package/dist/tools/edit.d.ts +2 -3
- package/dist/tools/edit.js +274 -86
- package/dist/tools/event-manage.d.ts +13 -7
- package/dist/tools/event-manage.js +52 -14
- package/dist/tools/glob-match.d.ts +11 -0
- package/dist/tools/glob-match.js +75 -0
- package/dist/tools/glob.d.ts +15 -0
- package/dist/tools/glob.js +113 -0
- package/dist/tools/grep.d.ts +0 -1
- package/dist/tools/grep.js +57 -42
- package/dist/tools/ignore-dirs.d.ts +6 -0
- package/dist/tools/ignore-dirs.js +15 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.js +50 -40
- package/dist/tools/job.d.ts +0 -1
- package/dist/tools/job.js +1 -8
- package/dist/tools/line-index.d.ts +16 -0
- package/dist/tools/line-index.js +76 -0
- package/dist/tools/memory-manage.d.ts +20 -8
- package/dist/tools/memory-manage.js +65 -92
- package/dist/tools/presentation.d.ts +2 -0
- package/dist/tools/presentation.js +109 -0
- package/dist/tools/read.d.ts +2 -2
- package/dist/tools/read.js +97 -133
- package/dist/tools/registry.d.ts +4 -1
- package/dist/tools/registry.js +89 -22
- package/dist/tools/send-media.d.ts +6 -6
- package/dist/tools/send-media.js +16 -49
- package/dist/tools/session-search.d.ts +0 -1
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-security.d.ts +0 -2
- package/dist/tools/skill-security.js +0 -24
- package/dist/tools/skill.d.ts +31 -0
- package/dist/tools/skill.js +153 -0
- package/dist/tools/subagent-manage.d.ts +6 -5
- package/dist/tools/subagent-manage.js +60 -60
- package/dist/tools/task-manage/create.d.ts +2 -2
- package/dist/tools/task-manage/create.js +1 -3
- package/dist/tools/task-manage/lifecycle.d.ts +9 -6
- package/dist/tools/task-manage/lifecycle.js +56 -60
- package/dist/tools/task-manage/schema.d.ts +27 -15
- package/dist/tools/task-manage/schema.js +58 -74
- package/dist/tools/task-manage/shared.d.ts +11 -6
- package/dist/tools/task-manage/shared.js +30 -21
- package/dist/tools/task-manage/types.d.ts +14 -15
- package/dist/tools/task-manage/verification.d.ts +5 -5
- package/dist/tools/task-manage/verification.js +18 -15
- package/dist/tools/task-manage.d.ts +8 -11
- package/dist/tools/task-manage.js +63 -50
- package/dist/tools/tool-details.d.ts +17 -1
- package/dist/tools/tool-details.js +24 -0
- package/dist/tools/truncate.d.ts +5 -5
- package/dist/tools/truncate.js +5 -5
- package/dist/tools/web-fetch.d.ts +0 -1
- package/dist/tools/web-fetch.js +0 -1
- package/dist/tools/web-search.d.ts +0 -1
- package/dist/tools/web-search.js +0 -1
- package/dist/tools/write-content.d.ts +3 -3
- package/dist/tools/write-content.js +12 -51
- package/dist/tools/write.d.ts +2 -3
- package/dist/tools/write.js +3 -4
- package/dist/tui/pitui-frontend.js +3 -3
- package/dist/usage/ledger.js +7 -4
- package/examples/sub-agents/README.md +13 -13
- package/examples/sub-agents/documenter.md +2 -1
- package/examples/sub-agents/reviewer.md +2 -0
- package/examples/sub-agents/scout.md +2 -1
- package/examples/sub-agents/verifier.md +6 -4
- package/examples/sub-agents/worker.md +2 -1
- package/package.json +5 -5
- package/dist/tools/skill-manage.d.ts +0 -41
- 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 =
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
* `
|
|
164
|
-
*
|
|
165
|
-
*
|
|
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
|
-
* `
|
|
646
|
-
*
|
|
647
|
-
*
|
|
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 =
|
|
651
|
-
if (
|
|
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
|
|
654
|
+
if (baseConfig.unavailable) {
|
|
657
655
|
return { error: `Sub-agent "${baseConfig.name}" is currently unavailable: ${baseConfig.unavailable}` };
|
|
658
656
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
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
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
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
|
-
|
|
681
|
-
|
|
682
|
-
|
|
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
|
|
694
|
-
let modelRef
|
|
695
|
-
if (
|
|
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 (
|
|
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
|
-
|
|
716
|
-
|
|
717
|
-
|
|
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:
|
|
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 ??
|
|
741
|
-
const memory = contextOverride.value?.memory ??
|
|
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
|
|
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 ??
|
|
764
|
-
//
|
|
765
|
-
//
|
|
766
|
-
|
|
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:
|
|
784
|
-
description:
|
|
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
|
-
|
|
798
|
-
|
|
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 (`
|
|
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
|