@oyasmi/pipiclaw 0.8.11 → 0.9.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/channel-runner.d.ts +3 -0
- package/dist/agent/channel-runner.js +9 -0
- package/dist/agent/commands.d.ts +1 -1
- package/dist/agent/commands.js +9 -0
- package/dist/agent/job-manager.d.ts +5 -3
- package/dist/agent/job-manager.js +8 -5
- package/dist/agent/prompt/sections.js +46 -7
- package/dist/agent/prompt/types.d.ts +9 -0
- package/dist/agent/session-events.js +7 -42
- package/dist/agent/types.d.ts +4 -0
- package/dist/playbooks/agent-delegation.md +46 -21
- package/dist/playbooks/runtime-orientation.md +2 -2
- package/dist/runtime/bootstrap.js +45 -1
- package/dist/runtime/dingtalk.d.ts +1 -0
- package/dist/runtime/dingtalk.js +3 -0
- package/dist/runtime/store.d.ts +7 -0
- package/dist/runtime/subagent-commands.d.ts +15 -0
- package/dist/runtime/subagent-commands.js +122 -0
- package/dist/runtime/task-commands.js +5 -1
- package/dist/security/logger.js +3 -1
- package/dist/security/types.d.ts +17 -1
- package/dist/shared/host-process.d.ts +15 -0
- package/dist/shared/host-process.js +40 -0
- package/dist/shared/shell-words.d.ts +9 -0
- package/dist/shared/shell-words.js +52 -0
- package/dist/subagents/discovery.d.ts +42 -1
- package/dist/subagents/discovery.js +302 -69
- package/dist/subagents/external/claude-code.d.ts +2 -0
- package/dist/subagents/external/claude-code.js +152 -0
- package/dist/subagents/external/codex-cli.d.ts +2 -0
- package/dist/subagents/external/codex-cli.js +133 -0
- package/dist/subagents/external/exec.d.ts +2 -0
- package/dist/subagents/external/exec.js +38 -0
- package/dist/subagents/external/harness.d.ts +102 -0
- package/dist/subagents/external/harness.js +76 -0
- package/dist/subagents/external/registry.d.ts +2 -0
- package/dist/subagents/external/registry.js +11 -0
- package/dist/subagents/external/run.d.ts +39 -0
- package/dist/subagents/external/run.js +220 -0
- package/dist/subagents/runs.d.ts +216 -0
- package/dist/subagents/runs.js +522 -0
- package/dist/subagents/tool.d.ts +8 -0
- package/dist/subagents/tool.js +350 -124
- package/dist/subagents/workspace-lease.d.ts +36 -0
- package/dist/subagents/workspace-lease.js +48 -0
- package/dist/tasks/artifact-subject.js +50 -2
- package/dist/tasks/verification.d.ts +8 -0
- package/dist/tasks/verification.js +10 -2
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +10 -1
- package/dist/tools/registry.js +1 -0
- package/dist/tools/subagent-manage.d.ts +18 -0
- package/dist/tools/subagent-manage.js +141 -0
- package/dist/tools/tool-details.d.ts +1 -1
- package/dist/tui/app.js +2 -0
- package/dist/tui/commands.d.ts +1 -0
- package/dist/tui/commands.js +2 -0
- package/dist/tui/turn-controller.d.ts +1 -0
- package/dist/tui/turn-controller.js +1 -0
- package/dist/usage/ledger.d.ts +6 -0
- package/examples/sub-agents/README.md +59 -12
- package/examples/sub-agents/builder-hard.md +45 -0
- package/examples/sub-agents/builder.md +41 -0
- package/examples/sub-agents/documenter.md +53 -0
- package/examples/sub-agents/log-sifter.md +43 -0
- package/examples/sub-agents/planner.md +42 -0
- package/examples/sub-agents/reviewer.md +33 -39
- package/examples/sub-agents/scout.md +31 -0
- package/examples/sub-agents/verifier.md +29 -36
- package/examples/sub-agents/worker.md +36 -0
- package/package.json +1 -1
- package/examples/sub-agents/researcher.md +0 -41
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
4
|
+
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
5
|
+
function usage() {
|
|
6
|
+
return `# Subagents
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
|
|
10
|
+
- \`/subagents list\`
|
|
11
|
+
- \`/subagents show <runId>\`
|
|
12
|
+
- \`/subagents cancel <runId>\``;
|
|
13
|
+
}
|
|
14
|
+
function parseSubagentsCommand(args) {
|
|
15
|
+
const parts = args.trim().split(/\s+/).filter(Boolean);
|
|
16
|
+
const action = parts[0];
|
|
17
|
+
if (!action || action === "list") {
|
|
18
|
+
if (parts.length > 1)
|
|
19
|
+
throw new Error("Usage: /subagents list");
|
|
20
|
+
return { action: "list" };
|
|
21
|
+
}
|
|
22
|
+
if (action === "show") {
|
|
23
|
+
if (!parts[1] || parts.length > 2)
|
|
24
|
+
throw new Error("Usage: /subagents show <runId>");
|
|
25
|
+
return { action: "show", runId: parts[1] };
|
|
26
|
+
}
|
|
27
|
+
if (action === "cancel") {
|
|
28
|
+
if (!parts[1] || parts.length > 2)
|
|
29
|
+
throw new Error("Usage: /subagents cancel <runId>");
|
|
30
|
+
return { action: "cancel", runId: parts[1] };
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`Unknown /subagents action: ${action}`);
|
|
33
|
+
}
|
|
34
|
+
function formatDuration(ms) {
|
|
35
|
+
const seconds = Math.round(ms / 1000);
|
|
36
|
+
if (seconds < 60)
|
|
37
|
+
return `${seconds}s`;
|
|
38
|
+
return `${Math.floor(seconds / 60)}m${seconds % 60}s`;
|
|
39
|
+
}
|
|
40
|
+
function elapsedMs(record) {
|
|
41
|
+
return (record.finishedAt ?? Date.now()) - record.startedAt;
|
|
42
|
+
}
|
|
43
|
+
function formatRunLine(record) {
|
|
44
|
+
const harness = record.harness ? `${record.runtime}/${record.harness}` : record.runtime;
|
|
45
|
+
const task = record.taskId ? `, task ${record.taskId}` : "";
|
|
46
|
+
return `- [${record.runId}] ${record.agent} (${harness}) — ${record.status} (${formatDuration(elapsedMs(record))}${task})`;
|
|
47
|
+
}
|
|
48
|
+
function formatHealthTail(discovery) {
|
|
49
|
+
const unavailable = discovery.agents.filter((agent) => agent.unavailable);
|
|
50
|
+
const lines = [];
|
|
51
|
+
if (unavailable.length > 0 || discovery.warnings.length > 0) {
|
|
52
|
+
lines.push("", "## Role directory health");
|
|
53
|
+
}
|
|
54
|
+
for (const agent of unavailable) {
|
|
55
|
+
lines.push(`- \`${agent.name}\`: unavailable (${agent.unavailable})`);
|
|
56
|
+
}
|
|
57
|
+
for (const warning of discovery.warnings) {
|
|
58
|
+
lines.push(`- discovery warning: ${warning}`);
|
|
59
|
+
}
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
|
62
|
+
async function listRuns(channelId, discovery) {
|
|
63
|
+
const records = getSubAgentRunManager(channelId).list();
|
|
64
|
+
const body = records.length === 0
|
|
65
|
+
? "No delegation runs."
|
|
66
|
+
: records
|
|
67
|
+
.sort((a, b) => b.startedAt - a.startedAt)
|
|
68
|
+
.map(formatRunLine)
|
|
69
|
+
.join("\n");
|
|
70
|
+
const tail = discovery ? formatHealthTail(discovery) : "";
|
|
71
|
+
return `# Subagent runs\n\n${body}${tail}`;
|
|
72
|
+
}
|
|
73
|
+
const STDERR_TAIL_CHARS = 2_000;
|
|
74
|
+
async function formatRunDetail(record) {
|
|
75
|
+
const parts = [`# Run ${record.runId}`, "", "```json", JSON.stringify(record, null, 2), "```"];
|
|
76
|
+
// D6: "show" is the human/model escape hatch for a stuck or failed external run, so its
|
|
77
|
+
// stderr belongs here even though it never rides the completion wake (that only carries
|
|
78
|
+
// the harness's own parsed output).
|
|
79
|
+
if (record.runtime === "external") {
|
|
80
|
+
const stderrTail = await readFile(join(record.artifactDir, "stderr.log"), "utf-8")
|
|
81
|
+
.then((text) => text.slice(-STDERR_TAIL_CHARS))
|
|
82
|
+
.catch(() => undefined);
|
|
83
|
+
if (stderrTail?.trim()) {
|
|
84
|
+
parts.push("", "## stderr (tail)", "```", stderrTail, "```");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return parts.join("\n");
|
|
88
|
+
}
|
|
89
|
+
async function showRun(channelId, runId) {
|
|
90
|
+
const record = getSubAgentRunManager(channelId).get(runId);
|
|
91
|
+
if (!record)
|
|
92
|
+
return `Run not found: ${runId}`;
|
|
93
|
+
return formatRunDetail(record);
|
|
94
|
+
}
|
|
95
|
+
async function cancelRun(channelId, runId) {
|
|
96
|
+
const status = await getSubAgentRunManager(channelId).cancel(runId);
|
|
97
|
+
if (status === "not_found")
|
|
98
|
+
return `Run not found: ${runId}`;
|
|
99
|
+
return `Cancel requested for run \`${runId}\`: ${status}`;
|
|
100
|
+
}
|
|
101
|
+
export async function handleSubagentsCommand(options) {
|
|
102
|
+
let command;
|
|
103
|
+
try {
|
|
104
|
+
command = parseSubagentsCommand(options.args);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
return `${errorMessage(error)}\n\n${usage()}`;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
switch (command.action) {
|
|
111
|
+
case "list":
|
|
112
|
+
return await listRuns(options.channelId, options.discovery);
|
|
113
|
+
case "show":
|
|
114
|
+
return await showRun(options.channelId, command.runId);
|
|
115
|
+
case "cancel":
|
|
116
|
+
return await cancelRun(options.channelId, command.runId);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
return `Could not ${command.action} subagent run(s): ${errorMessage(error)}`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -7,6 +7,7 @@ import { parseTaskEventName, taskEventPrefix } from "../shared/task-events.js";
|
|
|
7
7
|
import { nextTaskWake, validateTaskSchedule } from "../shared/task-schedule.js";
|
|
8
8
|
import { errorMessage } from "../shared/text-utils.js";
|
|
9
9
|
import { isRecord } from "../shared/type-guards.js";
|
|
10
|
+
import { channelDelegationTaskIds } from "../subagents/runs.js";
|
|
10
11
|
import { applyTaskControlPatch, createDefaultTaskControl, retiredTaskControlKeys, TASK_PRIORITIES, taskBudgetViolation, } from "../tasks/control.js";
|
|
11
12
|
import { countTaskDodItems, extractTaskTitle, isTaskParked, missingStandardTaskSections, normalizeTaskId, readActiveTasks, recurringTaskMissedOccurrence, } from "../tasks/ledger.js";
|
|
12
13
|
import { withTaskMutation } from "../tasks/mutation-lock.js";
|
|
@@ -474,6 +475,7 @@ async function doctor(options) {
|
|
|
474
475
|
const archivedIds = await readArchivedTaskIds(options.channelDir);
|
|
475
476
|
const events = await readTaskEvents(options.workspaceDir, options.channelId);
|
|
476
477
|
const runningJobTaskIds = channelJobTaskIds(options.channelId);
|
|
478
|
+
const runningDelegationTaskIds = channelDelegationTaskIds(options.channelId);
|
|
477
479
|
const issues = [];
|
|
478
480
|
for (const entry of entries) {
|
|
479
481
|
const status = entry.frontmatter.status ?? "active";
|
|
@@ -582,7 +584,9 @@ async function doctor(options) {
|
|
|
582
584
|
// no running job carrying this id, whether it ever resumes is entirely up to the user.
|
|
583
585
|
// That is legitimate when it is waiting on an answer — and indistinguishable, on disk,
|
|
584
586
|
// from a task everyone has forgotten. Report the fact and name every way out.
|
|
585
|
-
const hasDurableWaitingSource = control?.waitingFor === "verification" ||
|
|
587
|
+
const hasDurableWaitingSource = control?.waitingFor === "verification" ||
|
|
588
|
+
(control?.waitingFor === "job" && runningJobTaskIds.has(entry.id)) ||
|
|
589
|
+
(control?.waitingFor === "external-signal" && runningDelegationTaskIds.has(entry.id));
|
|
586
590
|
if (isTaskParked(entry.frontmatter) && !hasDurableWaitingSource) {
|
|
587
591
|
issues.push(issue(`tasks/${entry.id}.md is parked (waiting, no wake) and no running background job will wake it.`, `It resumes only when you reply to it, run /tasks run ${entry.id}, or give it a wake with /tasks set ${entry.id} wake <local time or +2h>; cancel it if what it waits for is gone.`));
|
|
588
592
|
}
|
package/dist/security/logger.js
CHANGED
|
@@ -20,7 +20,9 @@ function getAppender(path) {
|
|
|
20
20
|
}
|
|
21
21
|
/** Persist a blocked operation without synchronously stalling the Node event loop. */
|
|
22
22
|
export async function logSecurityEvent(workspaceDir, config, event) {
|
|
23
|
-
|
|
23
|
+
// external-agent records a permitted action, not a blocked one (spec 040, D8.1): it must not
|
|
24
|
+
// disappear just because the operator only wants blocked-action logging.
|
|
25
|
+
if (!config.audit.logBlocked && event.type !== "external-agent")
|
|
24
26
|
return;
|
|
25
27
|
let timer;
|
|
26
28
|
try {
|
package/dist/security/types.d.ts
CHANGED
|
@@ -77,4 +77,20 @@ export interface BlockedNetworkLogEvent extends SecurityLogEventBase {
|
|
|
77
77
|
category?: string;
|
|
78
78
|
reason?: string;
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* A *permitted* external delegation dispatch (spec 040, D8.1). Unlike the three events above,
|
|
82
|
+
* this records an action that was executed, not one that was blocked — external runs never pass
|
|
83
|
+
* through command-guard, so the argv actually spawned has to be captured somewhere. `audit.logBlocked`
|
|
84
|
+
* must not suppress it: see `logSecurityEvent`.
|
|
85
|
+
*/
|
|
86
|
+
export interface ExternalAgentLogEvent extends SecurityLogEventBase {
|
|
87
|
+
type: "external-agent";
|
|
88
|
+
runId: string;
|
|
89
|
+
agent: string;
|
|
90
|
+
harness: string;
|
|
91
|
+
argv: string[];
|
|
92
|
+
workingDirectory: string;
|
|
93
|
+
mutates: "read" | "write";
|
|
94
|
+
model?: string;
|
|
95
|
+
}
|
|
96
|
+
export type SecurityLogEvent = BlockedPathLogEvent | BlockedCommandLogEvent | BlockedNetworkLogEvent | ExternalAgentLogEvent;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateless host-process operations shared by background jobs and external delegation runs
|
|
3
|
+
* (spec 040, D1): a liveness probe and a process-group kill. Nothing here is job- or run-specific
|
|
4
|
+
* — both callers bring their own persisted pid and decide what "gone" means for their own state
|
|
5
|
+
* machine. `job-manager.ts` still probes through its shell `Executor` (its jobs are shell
|
|
6
|
+
* children); this is for callers that spawn argv-direct, detached children of their own (D3/D4).
|
|
7
|
+
*/
|
|
8
|
+
/** True if `pid` names a live process this user can at least see, without sending a real signal. */
|
|
9
|
+
export declare function isProcessAlive(pid: number): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* SIGTERM the process group, then SIGKILL it after a short grace period if it is still alive.
|
|
12
|
+
* `detached: true` at spawn time makes the child its own process-group leader, so `-pid` reaches
|
|
13
|
+
* it and everything it spawned.
|
|
14
|
+
*/
|
|
15
|
+
export declare function killProcessGroup(pid: number, graceMs?: number): Promise<void>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateless host-process operations shared by background jobs and external delegation runs
|
|
3
|
+
* (spec 040, D1): a liveness probe and a process-group kill. Nothing here is job- or run-specific
|
|
4
|
+
* — both callers bring their own persisted pid and decide what "gone" means for their own state
|
|
5
|
+
* machine. `job-manager.ts` still probes through its shell `Executor` (its jobs are shell
|
|
6
|
+
* children); this is for callers that spawn argv-direct, detached children of their own (D3/D4).
|
|
7
|
+
*/
|
|
8
|
+
/** True if `pid` names a live process this user can at least see, without sending a real signal. */
|
|
9
|
+
export function isProcessAlive(pid) {
|
|
10
|
+
try {
|
|
11
|
+
process.kill(pid, 0);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
// EPERM: the process exists but belongs to someone else — still alive from our view.
|
|
16
|
+
return error.code === "EPERM";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* SIGTERM the process group, then SIGKILL it after a short grace period if it is still alive.
|
|
21
|
+
* `detached: true` at spawn time makes the child its own process-group leader, so `-pid` reaches
|
|
22
|
+
* it and everything it spawned.
|
|
23
|
+
*/
|
|
24
|
+
export async function killProcessGroup(pid, graceMs = 300) {
|
|
25
|
+
try {
|
|
26
|
+
process.kill(-pid, "SIGTERM");
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return; // Already gone.
|
|
30
|
+
}
|
|
31
|
+
if (!isProcessAlive(pid))
|
|
32
|
+
return;
|
|
33
|
+
await new Promise((resolve) => setTimeout(resolve, graceMs));
|
|
34
|
+
try {
|
|
35
|
+
process.kill(-pid, "SIGKILL");
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Already gone.
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split a shell-style command line into argv tokens, respecting single/double quotes and
|
|
3
|
+
* backslash escapes, without invoking a shell (spec 040, D4 — external delegation runs never go
|
|
4
|
+
* through `sh -c`, so the "argv, not a shell string" guarantee has to start at tokenization).
|
|
5
|
+
*
|
|
6
|
+
* This is word-splitting only: no globbing, no variable expansion, no command substitution.
|
|
7
|
+
* An unterminated quote is tolerated by treating the rest of the string as part of that token.
|
|
8
|
+
*/
|
|
9
|
+
export declare function splitShellWords(command: string): string[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split a shell-style command line into argv tokens, respecting single/double quotes and
|
|
3
|
+
* backslash escapes, without invoking a shell (spec 040, D4 — external delegation runs never go
|
|
4
|
+
* through `sh -c`, so the "argv, not a shell string" guarantee has to start at tokenization).
|
|
5
|
+
*
|
|
6
|
+
* This is word-splitting only: no globbing, no variable expansion, no command substitution.
|
|
7
|
+
* An unterminated quote is tolerated by treating the rest of the string as part of that token.
|
|
8
|
+
*/
|
|
9
|
+
export function splitShellWords(command) {
|
|
10
|
+
const tokens = [];
|
|
11
|
+
let current = "";
|
|
12
|
+
let inToken = false;
|
|
13
|
+
let quote;
|
|
14
|
+
for (let i = 0; i < command.length; i++) {
|
|
15
|
+
const ch = command[i];
|
|
16
|
+
if (quote) {
|
|
17
|
+
if (ch === quote) {
|
|
18
|
+
quote = undefined;
|
|
19
|
+
}
|
|
20
|
+
else if (quote === '"' && ch === "\\" && i + 1 < command.length && /["\\$`]/.test(command[i + 1])) {
|
|
21
|
+
current += command[++i];
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
current += ch;
|
|
25
|
+
}
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (ch === "'" || ch === '"') {
|
|
29
|
+
quote = ch;
|
|
30
|
+
inToken = true;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (ch === "\\" && i + 1 < command.length) {
|
|
34
|
+
current += command[++i];
|
|
35
|
+
inToken = true;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (/\s/.test(ch)) {
|
|
39
|
+
if (inToken) {
|
|
40
|
+
tokens.push(current);
|
|
41
|
+
current = "";
|
|
42
|
+
inToken = false;
|
|
43
|
+
}
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
current += ch;
|
|
47
|
+
inToken = true;
|
|
48
|
+
}
|
|
49
|
+
if (inToken)
|
|
50
|
+
tokens.push(current);
|
|
51
|
+
return tokens;
|
|
52
|
+
}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { SecurityConfig } from "../security/types.js";
|
|
2
3
|
declare const ALLOWED_SUB_AGENT_TOOLS: readonly ["read", "grep", "bash", "edit", "write", "web_search", "web_fetch"];
|
|
3
4
|
declare const ALLOWED_CONTEXT_MODES: readonly ["isolated", "contextual"];
|
|
4
5
|
declare const ALLOWED_MEMORY_MODES: readonly ["none", "session", "relevant"];
|
|
5
|
-
declare const ALLOWED_THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
6
|
+
declare const ALLOWED_THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
7
|
+
declare const ALLOWED_RUNTIMES: readonly ["internal", "external"];
|
|
8
|
+
declare const ALLOWED_HARNESSES: readonly ["claude-code", "codex-cli", "exec"];
|
|
9
|
+
declare const ALLOWED_WORKLOADS: readonly ["light", "heavy"];
|
|
10
|
+
declare const ALLOWED_MUTATES: readonly ["read", "write"];
|
|
6
11
|
export type SubAgentToolName = (typeof ALLOWED_SUB_AGENT_TOOLS)[number];
|
|
7
12
|
export type SubAgentContextMode = (typeof ALLOWED_CONTEXT_MODES)[number];
|
|
8
13
|
export type SubAgentMemoryMode = (typeof ALLOWED_MEMORY_MODES)[number];
|
|
9
14
|
export type SubAgentThinkingLevel = (typeof ALLOWED_THINKING_LEVELS)[number];
|
|
15
|
+
export type SubAgentRuntime = (typeof ALLOWED_RUNTIMES)[number];
|
|
16
|
+
export type SubAgentHarness = (typeof ALLOWED_HARNESSES)[number];
|
|
17
|
+
export type SubAgentWorkload = (typeof ALLOWED_WORKLOADS)[number];
|
|
18
|
+
export type SubAgentMutates = (typeof ALLOWED_MUTATES)[number];
|
|
10
19
|
/**
|
|
11
20
|
* Execution budgets as a single named tuple. Frontmatter keeps the four numeric knobs
|
|
12
21
|
* (a human editing a config file has grounds to pick numbers); the invocation surface
|
|
@@ -61,6 +70,27 @@ export interface SubAgentConfig {
|
|
|
61
70
|
thinkingLevel?: SubAgentThinkingLevel;
|
|
62
71
|
filePath?: string;
|
|
63
72
|
source: "predefined" | "inline";
|
|
73
|
+
/** Defaults to "internal"; existing role files therefore parse unchanged (spec 040, D5). */
|
|
74
|
+
runtime: SubAgentRuntime;
|
|
75
|
+
/** External only. */
|
|
76
|
+
harness?: SubAgentHarness;
|
|
77
|
+
/** External only: the raw, unvalidated command line. Tokenized by the harness at invocation
|
|
78
|
+
* time (D4), never by discovery — discovery only checks that it is non-empty. */
|
|
79
|
+
command?: string;
|
|
80
|
+
/** External only: run `command` through `/bin/sh -lc` instead of argv-direct spawn (D4). */
|
|
81
|
+
shell?: boolean;
|
|
82
|
+
/** External only: env vars appended to (and overriding) the inherited environment (D8.2). */
|
|
83
|
+
env?: Record<string, string>;
|
|
84
|
+
/** Drives system-prompt directory grouping (D11); defaults by runtime when unset. */
|
|
85
|
+
workload?: SubAgentWorkload;
|
|
86
|
+
/** Required for external (an explicit declaration); optional for internal (inferred from `tools`). */
|
|
87
|
+
mutates?: SubAgentMutates;
|
|
88
|
+
/** External only: the harness's own model string, passed through unresolved (D5) — never
|
|
89
|
+
* looked up in `models.json`, because pipiclaw cannot validate another CLI's model names. */
|
|
90
|
+
externalModelRef?: string;
|
|
91
|
+
/** Set when the role is otherwise valid but currently cannot be invoked (e.g. missing binary).
|
|
92
|
+
* The role is still listed — never silently dropped (D5) — and invocation must explain why. */
|
|
93
|
+
unavailable?: string;
|
|
64
94
|
}
|
|
65
95
|
export interface ResolvedSubAgentConfig extends Omit<SubAgentConfig, "model" | "modelRef" | "thinkingLevel"> {
|
|
66
96
|
model: Model<Api>;
|
|
@@ -89,6 +119,17 @@ export interface SubAgentInvocationOverrides {
|
|
|
89
119
|
}
|
|
90
120
|
export declare function validateSubAgentTask(task: string): string | undefined;
|
|
91
121
|
export declare function getSubAgentsDir(workspaceDir: string): string;
|
|
122
|
+
/**
|
|
123
|
+
* Deny `write`/`edit` on `workspace/sub-agents/` itself (spec 040, D8.1).
|
|
124
|
+
*
|
|
125
|
+
* `DEFAULT_SECURITY_CONFIG.writeAllow` is empty and `pathAllowedByDefaults` permits the whole
|
|
126
|
+
* workspace, so without this the main agent (and a sub-agent it dispatches) can write a
|
|
127
|
+
* `runtime: external` role file with an arbitrary `command` and then invoke it — a command-guard
|
|
128
|
+
* bypass wearing a delegation costume. This closes the `write`/`edit` path; it does not close
|
|
129
|
+
* `bash` (same known gap as the memory-write-deny it mirrors — see the spec's risk list). The
|
|
130
|
+
* role directory hot-reloads on purpose (P4): this is the only gate, and it must stay cheap.
|
|
131
|
+
*/
|
|
132
|
+
export declare function withSubAgentsDirWriteDeny(config: SecurityConfig, workspaceDir: string): SecurityConfig;
|
|
92
133
|
export declare function validateToolNames(values: string[] | undefined): {
|
|
93
134
|
tools: SubAgentToolName[];
|
|
94
135
|
error?: string;
|