@oyasmi/pipiclaw 0.9.5 → 0.9.6-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/README.en.md +220 -126
- package/README.md +217 -123
- package/dist/agent/channel-runner.d.ts +1 -1
- package/dist/agent/channel-runner.js +1 -1
- package/dist/agent/prompt/sections.js +1 -1
- package/dist/agent/prompt/types.d.ts +2 -1
- package/dist/agent/session/compaction.d.ts +2 -0
- package/dist/agent/session/compaction.js +22 -14
- package/dist/agent/session/session-host.d.ts +1 -1
- package/dist/agent/session/session-host.js +3 -1
- package/dist/agent/stop-watchdog.js +5 -1
- package/dist/agent/turn/turn-state.d.ts +2 -0
- package/dist/agent/turn/turn-state.js +2 -1
- package/dist/agent/types.d.ts +3 -1
- package/dist/channel/attachments.d.ts +4 -0
- package/dist/channel/attachments.js +4 -0
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +25 -9
- package/dist/commands/router.js +5 -1
- package/dist/desk/commands.d.ts +14 -2
- package/dist/desk/commands.js +68 -20
- package/dist/desk/registry.d.ts +6 -2
- package/dist/desk/registry.js +70 -4
- package/dist/desk/types.d.ts +17 -0
- package/dist/dingtalk/bot.d.ts +1 -1
- package/dist/dingtalk/bot.js +4 -3
- package/dist/dingtalk/delivery.js +13 -8
- package/dist/dingtalk/inbound-media.d.ts +36 -14
- package/dist/dingtalk/inbound-media.js +71 -12
- package/dist/dingtalk/inbound.d.ts +9 -2
- package/dist/dingtalk/inbound.js +18 -2
- package/dist/dingtalk/media.d.ts +4 -10
- package/dist/dingtalk/media.js +58 -32
- package/dist/events/commands.d.ts +2 -0
- package/dist/events/commands.js +13 -8
- package/dist/events/history.d.ts +9 -0
- package/dist/events/history.js +66 -0
- package/dist/events/parse.js +7 -3
- package/dist/events/types.d.ts +3 -0
- package/dist/events/watcher.d.ts +3 -7
- package/dist/events/watcher.js +51 -56
- package/dist/jobs/kill.d.ts +23 -0
- package/dist/jobs/kill.js +65 -0
- package/dist/jobs/manager.d.ts +19 -18
- package/dist/jobs/manager.js +36 -103
- package/dist/memory/reflect.js +23 -3
- package/dist/memory/session-corpus.d.ts +1 -1
- package/dist/memory/session-corpus.js +70 -1
- package/dist/memory/session-search.js +13 -11
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +19 -9
- package/dist/playbooks/agent-delegation.md +5 -4
- package/dist/playbooks/memory-and-learning.md +1 -1
- package/dist/playbooks/task-lead.md +4 -4
- package/dist/runtime/bootstrap.d.ts +6 -0
- package/dist/runtime/bootstrap.js +11 -7
- package/dist/runtime/desk-runtime.d.ts +8 -2
- package/dist/runtime/desk-runtime.js +35 -4
- package/dist/runtime/durable-dispatch.d.ts +14 -2
- package/dist/runtime/durable-dispatch.js +207 -65
- package/dist/runtime/ingress-busy.js +17 -8
- package/dist/runtime/ingress-deps.d.ts +4 -1
- package/dist/runtime/ingress.js +6 -1
- package/dist/runtime/request-execution.js +7 -6
- package/dist/runtime/shutdown.d.ts +1 -0
- package/dist/runtime/shutdown.js +87 -35
- package/dist/runtime/task-control.d.ts +1 -0
- package/dist/runtime/task-control.js +25 -2
- package/dist/runtime/task-lane.d.ts +1 -0
- package/dist/runtime/task-lane.js +21 -6
- package/dist/runtime/task-step.js +11 -2
- package/dist/runtime/turn-run.js +103 -66
- package/dist/security/command-guard.d.ts +1 -1
- package/dist/security/command-guard.js +237 -314
- package/dist/security/path-guard.js +48 -7
- package/dist/security/shell-parse.d.ts +10 -0
- package/dist/security/shell-parse.js +224 -0
- package/dist/security/types.d.ts +2 -0
- package/dist/subagents/commands.d.ts +1 -1
- package/dist/subagents/detached-discovery.d.ts +1 -1
- package/dist/subagents/discovery.d.ts +18 -199
- package/dist/subagents/discovery.js +35 -289
- package/dist/subagents/dispatch.d.ts +1 -2
- package/dist/subagents/dispatch.js +39 -20
- package/dist/subagents/external/antigravity-cli.d.ts +2 -0
- package/dist/subagents/external/antigravity-cli.js +517 -0
- package/dist/subagents/external/claude-code.js +8 -17
- package/dist/subagents/external/codex-cli.js +8 -18
- package/dist/subagents/external/cursor-cli.js +34 -31
- package/dist/subagents/external/dispatch.d.ts +21 -7
- package/dist/subagents/external/dispatch.js +139 -11
- package/dist/subagents/external/exec.js +3 -0
- package/dist/subagents/external/harness.d.ts +57 -33
- package/dist/subagents/external/harness.js +69 -40
- package/dist/subagents/external/reconciliation.js +1 -0
- package/dist/subagents/external/registry.js +4 -1
- package/dist/subagents/external/role-warnings.d.ts +4 -13
- package/dist/subagents/external/role-warnings.js +4 -28
- package/dist/subagents/external/run.d.ts +1 -2
- package/dist/subagents/external/run.js +11 -11
- package/dist/subagents/external/settlement.d.ts +2 -0
- package/dist/subagents/external/settlement.js +8 -2
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/internal/outcome.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.js +1 -1
- package/dist/subagents/internal/run.d.ts +1 -2
- package/dist/subagents/internal/state.d.ts +1 -2
- package/dist/subagents/internal/worker.d.ts +1 -2
- package/dist/subagents/internal/worker.js +3 -1
- package/dist/subagents/resolve.d.ts +56 -0
- package/dist/subagents/resolve.js +202 -0
- package/dist/subagents/result.d.ts +1 -2
- package/dist/subagents/result.js +7 -3
- package/dist/subagents/run-record.d.ts +33 -2
- package/dist/subagents/run-record.js +2 -0
- package/dist/subagents/runs.d.ts +2 -24
- package/dist/subagents/runs.js +6 -0
- package/dist/subagents/task-envelope.d.ts +1 -2
- package/dist/subagents/task-envelope.js +8 -4
- package/dist/subagents/types.d.ts +93 -4
- package/dist/subagents/types.js +16 -1
- package/dist/subagents/workspace-lease.d.ts +11 -21
- package/dist/subagents/workspace-lease.js +48 -21
- package/dist/subagents/worktree.d.ts +10 -0
- package/dist/subagents/worktree.js +77 -0
- package/dist/tasks/archive.js +4 -0
- package/dist/tasks/commands.d.ts +3 -0
- package/dist/tasks/commands.js +16 -2
- package/dist/tasks/control.d.ts +2 -0
- package/dist/tasks/delivery.d.ts +2 -0
- package/dist/tasks/delivery.js +141 -21
- package/dist/tasks/loop-log.d.ts +2 -0
- package/dist/tasks/loop-log.js +9 -0
- package/dist/tools/bash.js +2 -0
- package/dist/tools/contract/presentation.js +3 -4
- package/dist/tools/event-manage.d.ts +2 -0
- package/dist/tools/event-manage.js +20 -2
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/registry.js +3 -1
- package/dist/tools/send-media.js +9 -5
- package/dist/tools/session-search.js +1 -1
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +15 -149
- package/dist/tools/subagent.d.ts +2 -0
- package/dist/tools/subagent.js +6 -1
- package/dist/tools/task-manage/factory.js +2 -2
- package/dist/tools/task-manage/lifecycle.d.ts +3 -3
- package/dist/tools/task-manage/lifecycle.js +49 -9
- package/dist/tools/task-manage/schema.d.ts +4 -1
- package/dist/tools/task-manage/schema.js +4 -1
- package/dist/tools/task-manage/types.d.ts +4 -1
- package/dist/tui/cli.d.ts +1 -6
- package/dist/tui/cli.js +29 -3
- package/dist/tui/client.d.ts +2 -0
- package/dist/tui/client.js +13 -4
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/render.js +1 -1
- package/examples/sub-agents/README.md +39 -73
- package/examples/sub-agents/agents/agy-main.md +23 -0
- package/examples/sub-agents/agents/claude-high.md +9 -9
- package/examples/sub-agents/agents/claude-main.md +9 -9
- package/examples/sub-agents/agents/codex-flash.md +9 -9
- package/examples/sub-agents/agents/codex-high.md +9 -9
- package/examples/sub-agents/agents/codex-main.md +9 -9
- package/examples/sub-agents/agents/codex-review.md +9 -9
- package/examples/sub-agents/agents/cursor-high.md +9 -9
- package/examples/sub-agents/agents/cursor-main.md +9 -9
- package/examples/sub-agents/agents/glm-flash.md +9 -9
- package/examples/sub-agents/agents/glm-high.md +9 -9
- package/package.json +8 -8
- package/examples/sub-agents/agents/scout.md +0 -30
- package/examples/sub-agents/roles/builder-hard.md +0 -34
- package/examples/sub-agents/roles/builder.md +0 -34
- package/examples/sub-agents/roles/explorer.md +0 -39
- package/examples/sub-agents/roles/git-committer.md +0 -43
- package/examples/sub-agents/roles/planner.md +0 -33
- package/examples/sub-agents/roles/reviewer.md +0 -33
- package/examples/sub-agents/roles/verifier.md +0 -35
- package/examples/sub-agents/roles/worker.md +0 -34
|
@@ -26,8 +26,37 @@ const HOME_SENSITIVE_PREFIXES = [
|
|
|
26
26
|
"~/Library/Application Support/Firefox/",
|
|
27
27
|
"~/.config/google-chrome/",
|
|
28
28
|
"~/.mozilla/firefox/",
|
|
29
|
+
"~/.pipiclaw/state/",
|
|
29
30
|
];
|
|
30
|
-
const HOME_SENSITIVE_FILES = [
|
|
31
|
+
const HOME_SENSITIVE_FILES = [
|
|
32
|
+
"~/.netrc",
|
|
33
|
+
"~/.npmrc",
|
|
34
|
+
"~/.pypirc",
|
|
35
|
+
"~/.bash_history",
|
|
36
|
+
"~/.zsh_history",
|
|
37
|
+
"~/.pipiclaw/auth.json",
|
|
38
|
+
"~/.pipiclaw/channel.json",
|
|
39
|
+
"~/.pipiclaw/security.json",
|
|
40
|
+
"~/.pipiclaw/models.json",
|
|
41
|
+
"~/.pipiclaw/tools.json",
|
|
42
|
+
"~/.pipiclaw/settings.json",
|
|
43
|
+
"~/.claude/.credentials.json",
|
|
44
|
+
"~/.codex/auth.json",
|
|
45
|
+
];
|
|
46
|
+
/**
|
|
47
|
+
* Pipiclaw's own control-plane files and daemon state inside `appHomeDir` (spec 044 / P0 self-protection).
|
|
48
|
+
* Listed explicitly rather than blocking the whole `appHomeDir` prefix because `workspace/` (and in custom
|
|
49
|
+
* deployments, desk working directories) legitimately live under `appHomeDir`.
|
|
50
|
+
*/
|
|
51
|
+
const APP_HOME_SENSITIVE_FILES = [
|
|
52
|
+
"auth.json",
|
|
53
|
+
"channel.json",
|
|
54
|
+
"security.json",
|
|
55
|
+
"models.json",
|
|
56
|
+
"tools.json",
|
|
57
|
+
"settings.json",
|
|
58
|
+
];
|
|
59
|
+
const APP_HOME_SENSITIVE_PREFIXES = ["state/"];
|
|
31
60
|
const WRITE_DENY_HOME_FILES = ["~/.bashrc", "~/.zshrc", "~/.profile", "~/.bash_profile", "~/.config/fish/config.fish"];
|
|
32
61
|
const SYSTEM_SENSITIVE_PREFIXES = ["/etc/sudoers.d/", "/var/run/secrets/"];
|
|
33
62
|
const SYSTEM_SENSITIVE_FILES = ["/etc/shadow", "/etc/gshadow", "/etc/sudoers", "/proc/kcore"];
|
|
@@ -170,9 +199,16 @@ const SENSITIVE_SYSTEM_PREFIXES = SYSTEM_SENSITIVE_PREFIXES.map((item) => normal
|
|
|
170
199
|
const SENSITIVE_SYSTEM_FILES = SYSTEM_SENSITIVE_FILES.map((item) => normalize(item));
|
|
171
200
|
const NORMALIZED_SYSTEM_DENY_PREFIXES = SYSTEM_DENY_PREFIXES.map((prefix) => normalize(prefix));
|
|
172
201
|
const NORMALIZED_TEMP_PREFIXES = TEMP_PREFIXES.map((prefix) => normalize(prefix));
|
|
173
|
-
function
|
|
202
|
+
function matchesAppHomeControlPlane(path, appHomeDir) {
|
|
203
|
+
if (!appHomeDir)
|
|
204
|
+
return false;
|
|
205
|
+
const exactPaths = APP_HOME_SENSITIVE_FILES.map((file) => resolve(appHomeDir, file));
|
|
206
|
+
const prefixes = APP_HOME_SENSITIVE_PREFIXES.map((prefix) => resolve(appHomeDir, prefix));
|
|
207
|
+
return matchesAnyPath(path, exactPaths, prefixes);
|
|
208
|
+
}
|
|
209
|
+
function matchesSensitiveReadPath(path, homeDir, appHomeDir) {
|
|
174
210
|
const table = getSensitivePathTable(homeDir);
|
|
175
|
-
if (matchesAnyPath(path, table.homeFiles, table.homePrefixes)) {
|
|
211
|
+
if (matchesAnyPath(path, table.homeFiles, table.homePrefixes) || matchesAppHomeControlPlane(path, appHomeDir)) {
|
|
176
212
|
return true;
|
|
177
213
|
}
|
|
178
214
|
if (matchesAnyPath(path, SENSITIVE_SYSTEM_FILES, SENSITIVE_SYSTEM_PREFIXES)) {
|
|
@@ -188,8 +224,8 @@ function matchesSensitiveReadPath(path, homeDir) {
|
|
|
188
224
|
}
|
|
189
225
|
return PRIVATE_KEY_NAME_HINTS.test(lowerBase) && lowerBase.startsWith("id_");
|
|
190
226
|
}
|
|
191
|
-
function matchesSensitiveWritePath(path, homeDir) {
|
|
192
|
-
if (matchesSensitiveReadPath(path, homeDir)) {
|
|
227
|
+
function matchesSensitiveWritePath(path, homeDir, appHomeDir) {
|
|
228
|
+
if (matchesSensitiveReadPath(path, homeDir, appHomeDir)) {
|
|
193
229
|
return true;
|
|
194
230
|
}
|
|
195
231
|
return getSensitivePathTable(homeDir).writeDenyHomeFiles.includes(path);
|
|
@@ -263,20 +299,25 @@ export function guardPath(rawPath, operation, ctx) {
|
|
|
263
299
|
return { allowed: true, operation, rawPath, resolvedPath: resolveForGuard(resolveTargetPath(rawPath, ctx), ctx) };
|
|
264
300
|
}
|
|
265
301
|
const homeDir = ctx.homeDir ?? homedir();
|
|
302
|
+
const rawAppHome = ctx.appHomeDir ?? process.env.PIPICLAW_HOME?.trim();
|
|
303
|
+
const resolvedAppHome = rawAppHome ? resolveRootForGuard(resolve(rawAppHome), ctx) : undefined;
|
|
266
304
|
const effectiveCtx = {
|
|
267
305
|
...ctx,
|
|
268
306
|
agentWorkspaceDir: resolveRootForGuard(ctx.agentWorkspaceDir, ctx),
|
|
269
307
|
homeDir: resolveRootForGuard(homeDir, ctx),
|
|
308
|
+
...(resolvedAppHome ? { appHomeDir: resolvedAppHome } : {}),
|
|
270
309
|
};
|
|
271
310
|
const resolvedTarget = resolveTargetPath(rawPath, ctx);
|
|
272
311
|
const guardedPath = resolveForGuard(resolvedTarget, ctx);
|
|
273
312
|
if (matchesConfiguredPath(guardedPath, operation === "read" ? effectiveCtx.config.readDeny : effectiveCtx.config.writeDeny, effectiveCtx)) {
|
|
274
313
|
return formatBlockedResult(operation, rawPath, guardedPath, "configured-deny", "Path is denied by security config");
|
|
275
314
|
}
|
|
276
|
-
if (operation === "read" &&
|
|
315
|
+
if (operation === "read" &&
|
|
316
|
+
matchesSensitiveReadPath(guardedPath, effectiveCtx.homeDir ?? homeDir, resolvedAppHome)) {
|
|
277
317
|
return formatBlockedResult(operation, rawPath, guardedPath, "sensitive-read-path", "Reading sensitive paths is not allowed");
|
|
278
318
|
}
|
|
279
|
-
if (operation === "write" &&
|
|
319
|
+
if (operation === "write" &&
|
|
320
|
+
matchesSensitiveWritePath(guardedPath, effectiveCtx.homeDir ?? homeDir, resolvedAppHome)) {
|
|
280
321
|
return formatBlockedResult(operation, rawPath, guardedPath, "sensitive-write-path", "Writing sensitive paths is not allowed");
|
|
281
322
|
}
|
|
282
323
|
if (operation === "write" && existsSync(resolvedTarget)) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** A deliberately bounded shell grammar. Parse executable positions, never scan operands as commands.
|
|
2
|
+
* Unsupported control/expansion syntax throws: guessing a command boundary is unsafe. */
|
|
3
|
+
export declare class ShellSyntaxError extends Error {
|
|
4
|
+
}
|
|
5
|
+
export declare const SHELL_DYNAMIC: {
|
|
6
|
+
readonly substitution: "\0substitution\0";
|
|
7
|
+
readonly expansion: "\0expansion\0";
|
|
8
|
+
readonly glob: "\0glob\0";
|
|
9
|
+
};
|
|
10
|
+
export declare function shellCommands(input: string, backtickDepth?: number): string[][];
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/** A deliberately bounded shell grammar. Parse executable positions, never scan operands as commands.
|
|
2
|
+
* Unsupported control/expansion syntax throws: guessing a command boundary is unsafe. */
|
|
3
|
+
export class ShellSyntaxError extends Error {
|
|
4
|
+
}
|
|
5
|
+
// Raw NUL is refused at the boundary, so literal/quoted text cannot forge these parser tags.
|
|
6
|
+
export const SHELL_DYNAMIC = {
|
|
7
|
+
substitution: "\0substitution\0",
|
|
8
|
+
expansion: "\0expansion\0",
|
|
9
|
+
glob: "\0glob\0",
|
|
10
|
+
};
|
|
11
|
+
export function shellCommands(input, backtickDepth = 0) {
|
|
12
|
+
if (backtickDepth > 32)
|
|
13
|
+
throw new ShellSyntaxError("Backtick nesting limit");
|
|
14
|
+
if (input.includes("\0"))
|
|
15
|
+
throw new ShellSyntaxError("NUL in command");
|
|
16
|
+
const commands = [];
|
|
17
|
+
let i = 0;
|
|
18
|
+
let nesting = 0;
|
|
19
|
+
const fail = (reason) => {
|
|
20
|
+
throw new ShellSyntaxError(reason);
|
|
21
|
+
};
|
|
22
|
+
function sequence(end) {
|
|
23
|
+
if (++nesting > 32)
|
|
24
|
+
fail("Shell nesting limit");
|
|
25
|
+
let words = [];
|
|
26
|
+
const flush = () => {
|
|
27
|
+
if (words.length)
|
|
28
|
+
commands.push(words);
|
|
29
|
+
words = [];
|
|
30
|
+
};
|
|
31
|
+
while (i < input.length) {
|
|
32
|
+
const c = input[i];
|
|
33
|
+
if (c === end) {
|
|
34
|
+
flush();
|
|
35
|
+
i++;
|
|
36
|
+
nesting--;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (c === " " || c === "\t" || c === "\r") {
|
|
40
|
+
i++;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (c === "#") {
|
|
44
|
+
while (i < input.length && input[i] !== "\n")
|
|
45
|
+
i++;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (c === "\n" || c === ";" || c === "|" || (c === "&" && input[i + 1] !== ">")) {
|
|
49
|
+
flush();
|
|
50
|
+
i++;
|
|
51
|
+
if ((c === "|" || c === "&") && input[i] === c)
|
|
52
|
+
i++;
|
|
53
|
+
else if (c === "|" && input[i] === "&")
|
|
54
|
+
i++;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (c === "(") {
|
|
58
|
+
if (words.length)
|
|
59
|
+
fail("Unexpected subshell");
|
|
60
|
+
i++;
|
|
61
|
+
sequence(")");
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (c === ")")
|
|
65
|
+
fail("Unsupported shell grouping");
|
|
66
|
+
// IO_NUMBER only counts when immediately adjacent to a redirection.
|
|
67
|
+
const fd = /^\d+(?=[<>])/.exec(input.slice(i));
|
|
68
|
+
if (fd)
|
|
69
|
+
i += fd[0].length;
|
|
70
|
+
if (input[i] === "&" && input[i + 1] === ">")
|
|
71
|
+
i++;
|
|
72
|
+
if (input[i] === "<" || input[i] === ">") {
|
|
73
|
+
const op = input[i++];
|
|
74
|
+
if (input[i] === "(") {
|
|
75
|
+
i++;
|
|
76
|
+
sequence(")");
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (input[i] === op) {
|
|
80
|
+
i++;
|
|
81
|
+
if (op === "<")
|
|
82
|
+
fail("Here documents/strings are unsupported");
|
|
83
|
+
}
|
|
84
|
+
if (input[i] === "&" || input[i] === "|" || input[i] === ">")
|
|
85
|
+
i++;
|
|
86
|
+
while (input[i] === " " || input[i] === "\t")
|
|
87
|
+
i++;
|
|
88
|
+
if (i >= input.length || /[\n;|&<>]/.test(input[i]))
|
|
89
|
+
fail("Missing redirection target");
|
|
90
|
+
const target = word(); // substitutions in redirections still execute
|
|
91
|
+
if (Object.values(SHELL_DYNAMIC).some((tag) => target.includes(tag)))
|
|
92
|
+
fail("Dynamic redirection target is unsupported");
|
|
93
|
+
if (/^\/dev\/(?:tcp|udp)\//.test(target))
|
|
94
|
+
fail("Shell network redirection is unsupported");
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const value = word();
|
|
98
|
+
if (!words.length && value === end) {
|
|
99
|
+
nesting--;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!words.length && value === "for") {
|
|
103
|
+
forLoop();
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (!words.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(value))
|
|
107
|
+
continue;
|
|
108
|
+
if (!words.length &&
|
|
109
|
+
/^(?:\{|\}|if|then|else|elif|fi|for|while|until|do|done|case|esac|function|select|eval|source|\.|exec|command|builtin|!)$/.test(value))
|
|
110
|
+
fail("Unsupported shell control or execution builtin");
|
|
111
|
+
words.push(value);
|
|
112
|
+
}
|
|
113
|
+
if (end)
|
|
114
|
+
fail("Unclosed shell group");
|
|
115
|
+
flush();
|
|
116
|
+
nesting--;
|
|
117
|
+
}
|
|
118
|
+
function forLoop() {
|
|
119
|
+
const space = () => {
|
|
120
|
+
while (input[i] === " " || input[i] === "\t")
|
|
121
|
+
i++;
|
|
122
|
+
};
|
|
123
|
+
space();
|
|
124
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(word()))
|
|
125
|
+
fail("Invalid for variable");
|
|
126
|
+
space();
|
|
127
|
+
if (word() !== "in")
|
|
128
|
+
fail("Only explicit for lists are supported");
|
|
129
|
+
space();
|
|
130
|
+
while (i < input.length && input[i] !== ";" && input[i] !== "\n") {
|
|
131
|
+
word();
|
|
132
|
+
space();
|
|
133
|
+
}
|
|
134
|
+
if (i >= input.length)
|
|
135
|
+
fail("Missing for body");
|
|
136
|
+
i++;
|
|
137
|
+
while (/\s/.test(input[i] ?? "") && i < input.length)
|
|
138
|
+
i++;
|
|
139
|
+
if (word() !== "do")
|
|
140
|
+
fail("Missing for do");
|
|
141
|
+
sequence("done");
|
|
142
|
+
}
|
|
143
|
+
function word() {
|
|
144
|
+
let value = "";
|
|
145
|
+
let quote = "";
|
|
146
|
+
let consumed = false;
|
|
147
|
+
while (i < input.length) {
|
|
148
|
+
const c = input[i];
|
|
149
|
+
if (!quote && /[\s;|&<>()]/.test(c))
|
|
150
|
+
break;
|
|
151
|
+
consumed = true;
|
|
152
|
+
if (c === "\\" && quote !== "'") {
|
|
153
|
+
i++;
|
|
154
|
+
if (i >= input.length)
|
|
155
|
+
fail("Trailing escape");
|
|
156
|
+
if (input[i] === "\n") {
|
|
157
|
+
i++;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (quote === '"' && !/[$`"\\]/.test(input[i]))
|
|
161
|
+
value += "\\";
|
|
162
|
+
value += input[i++];
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (c === "'" || c === '"') {
|
|
166
|
+
if (!quote) {
|
|
167
|
+
quote = c;
|
|
168
|
+
i++;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (quote === c) {
|
|
172
|
+
quote = "";
|
|
173
|
+
i++;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (quote !== "'" && c === "$" && input[i + 1] === "(") {
|
|
178
|
+
i += 2;
|
|
179
|
+
if (input[i] === "(")
|
|
180
|
+
fail("Arithmetic expansion is unsupported");
|
|
181
|
+
sequence(")");
|
|
182
|
+
value += SHELL_DYNAMIC.substitution;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (quote !== "'" && c === "`") {
|
|
186
|
+
i++;
|
|
187
|
+
let body = "";
|
|
188
|
+
while (i < input.length && input[i] !== "`") {
|
|
189
|
+
if (input[i] === "\\") {
|
|
190
|
+
i++;
|
|
191
|
+
if (i >= input.length)
|
|
192
|
+
fail("Unclosed backtick");
|
|
193
|
+
}
|
|
194
|
+
body += input[i++];
|
|
195
|
+
}
|
|
196
|
+
if (input[i++] !== "`")
|
|
197
|
+
fail("Unclosed backtick");
|
|
198
|
+
commands.push(...shellCommands(body, backtickDepth + 1));
|
|
199
|
+
value += SHELL_DYNAMIC.substitution;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (quote !== "'" && c === "$" && /[\w{['"?*@!#-]/.test(input[i + 1] ?? "")) {
|
|
203
|
+
const expansion = /^\$(?:[A-Za-z_][A-Za-z0-9_]*|[0-9]+|[?$!#*@-]|\{[A-Za-z_][A-Za-z0-9_]*\})/.exec(input.slice(i)) ??
|
|
204
|
+
fail("Unsupported shell expansion");
|
|
205
|
+
value += SHELL_DYNAMIC.expansion;
|
|
206
|
+
i += expansion[0].length;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (!quote && c === "{" && /^\{[^}]*[,.][^}]*\}/.test(input.slice(i)))
|
|
210
|
+
fail("Brace expansion is unsupported");
|
|
211
|
+
if (!quote && /[*?[]/.test(c))
|
|
212
|
+
value += SHELL_DYNAMIC.glob;
|
|
213
|
+
value += c;
|
|
214
|
+
i++;
|
|
215
|
+
}
|
|
216
|
+
if (quote)
|
|
217
|
+
fail("Unclosed quote");
|
|
218
|
+
if (!consumed)
|
|
219
|
+
fail("Unexpected shell token");
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
sequence();
|
|
223
|
+
return commands;
|
|
224
|
+
}
|
package/dist/security/types.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface SecurityRuntimeContext {
|
|
|
36
36
|
/** Base for relative paths — the desk directory for a desk-bound caller; `process.cwd()` when omitted. */
|
|
37
37
|
cwd?: string;
|
|
38
38
|
homeDir?: string;
|
|
39
|
+
/** App-home root (`~/.pipiclaw` or `PIPICLAW_HOME`) whose control-plane files and `state/` are sensitive. */
|
|
40
|
+
appHomeDir?: string;
|
|
39
41
|
}
|
|
40
42
|
export interface PathGuardContext extends SecurityRuntimeContext {
|
|
41
43
|
config: SecurityConfig["pathGuard"];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { SubAgentDiscoveryResult } from "./discovery.js";
|
|
2
1
|
import type { RunNotice } from "./run-record.js";
|
|
3
2
|
import type { SubAgentRunManager } from "./runs.js";
|
|
3
|
+
import type { SubAgentDiscoveryResult } from "./types.js";
|
|
4
4
|
/**
|
|
5
5
|
* `/subagents` — the human control path that does not depend on the model (spec 040 D6, polished
|
|
6
6
|
* by spec 041). Mirrors `tasks/commands.ts`'s shape: pure functions returning markdown, no
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SubAgentDiscoveryResult } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Resolve the role directory for `/subagents roles` when no `ChannelRunner` is currently active
|
|
4
4
|
* for the channel (spec 041) — mirrors `loadDetachedMaintenanceContext` in
|
|
@@ -1,153 +1,8 @@
|
|
|
1
1
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
2
2
|
import type { SecurityConfig } from "../security/types.js";
|
|
3
3
|
import { type SubAgentToolName } from "../tools/contract/names.js";
|
|
4
|
-
|
|
5
|
-
declare
|
|
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", "cursor-cli", "exec"];
|
|
9
|
-
declare const ALLOWED_WORKLOADS: readonly ["light", "heavy"];
|
|
10
|
-
declare const ALLOWED_MUTATES: readonly ["read", "write"];
|
|
11
|
-
export type { SubAgentToolName };
|
|
12
|
-
export type SubAgentContextMode = (typeof ALLOWED_CONTEXT_MODES)[number];
|
|
13
|
-
export type SubAgentMemoryMode = (typeof ALLOWED_MEMORY_MODES)[number];
|
|
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];
|
|
19
|
-
/**
|
|
20
|
-
* Execution budgets as a single named tuple. Frontmatter keeps the four numeric knobs
|
|
21
|
-
* (a human editing a config file has grounds to pick numbers); the invocation surface
|
|
22
|
-
* only offers these presets, because a model choosing `maxToolCalls` per delegation is
|
|
23
|
-
* guessing. `standard` is byte-identical to the DEFAULT_* values, so omitting `effort`
|
|
24
|
-
* leaves behavior unchanged.
|
|
25
|
-
*/
|
|
26
|
-
export declare const SUB_AGENT_EFFORT_PRESETS: {
|
|
27
|
-
readonly quick: {
|
|
28
|
-
readonly maxTurns: 8;
|
|
29
|
-
readonly maxToolCalls: 16;
|
|
30
|
-
readonly maxWallTimeSec: 120;
|
|
31
|
-
readonly bashTimeoutSec: 60;
|
|
32
|
-
};
|
|
33
|
-
readonly standard: {
|
|
34
|
-
readonly maxTurns: 32;
|
|
35
|
-
readonly maxToolCalls: 96;
|
|
36
|
-
readonly maxWallTimeSec: 600;
|
|
37
|
-
readonly bashTimeoutSec: 120;
|
|
38
|
-
};
|
|
39
|
-
readonly deep: {
|
|
40
|
-
readonly maxTurns: 64;
|
|
41
|
-
readonly maxToolCalls: 160;
|
|
42
|
-
readonly maxWallTimeSec: 1800;
|
|
43
|
-
readonly bashTimeoutSec: 300;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
export type SubAgentEffort = keyof typeof SUB_AGENT_EFFORT_PRESETS;
|
|
47
|
-
/**
|
|
48
|
-
* The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
|
|
49
|
-
* encode only four meaningful states (`isolated` implies `memory: none`), so the calling
|
|
50
|
-
* surface collapses them into one enum. The dropped state — contextual with `memory: none`,
|
|
51
|
-
* i.e. paths-only injection — remains expressible in frontmatter.
|
|
52
|
-
*/
|
|
53
|
-
declare const ALLOWED_CONTEXT_CHOICES: readonly ["none", "index"];
|
|
54
|
-
export type SubAgentContextChoice = (typeof ALLOWED_CONTEXT_CHOICES)[number];
|
|
55
|
-
interface SubAgentConfigFields {
|
|
56
|
-
name: string;
|
|
57
|
-
description: string;
|
|
58
|
-
systemPrompt: string;
|
|
59
|
-
tools: SubAgentToolName[];
|
|
60
|
-
model?: Model<Api>;
|
|
61
|
-
modelRef?: string;
|
|
62
|
-
maxTurns: number;
|
|
63
|
-
maxToolCalls: number;
|
|
64
|
-
maxWallTimeSec: number;
|
|
65
|
-
bashTimeoutSec: number;
|
|
66
|
-
contextMode: SubAgentContextMode;
|
|
67
|
-
memory: SubAgentMemoryMode;
|
|
68
|
-
paths: string[];
|
|
69
|
-
/** Unset means "apply the purpose-based default at resolution time" (spec 032 D3). */
|
|
70
|
-
thinkingLevel?: SubAgentThinkingLevel;
|
|
71
|
-
filePath?: string;
|
|
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
|
-
/** exec harness 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;
|
|
94
|
-
}
|
|
95
|
-
export interface InternalSubAgentConfig extends SubAgentConfigFields {
|
|
96
|
-
runtime: "internal";
|
|
97
|
-
}
|
|
98
|
-
export interface ExternalSubAgentConfig extends SubAgentConfigFields {
|
|
99
|
-
runtime: "external";
|
|
100
|
-
harness: SubAgentHarness;
|
|
101
|
-
command: string;
|
|
102
|
-
mutates: SubAgentMutates;
|
|
103
|
-
model?: never;
|
|
104
|
-
modelRef?: never;
|
|
105
|
-
}
|
|
106
|
-
export type SubAgentConfig = InternalSubAgentConfig | ExternalSubAgentConfig;
|
|
107
|
-
export interface ResolvedInternalSubAgentConfig extends InternalSubAgentConfig {
|
|
108
|
-
model: Model<Api>;
|
|
109
|
-
modelRef: string;
|
|
110
|
-
}
|
|
111
|
-
export type ResolvedSubAgentConfig = ResolvedInternalSubAgentConfig | ExternalSubAgentConfig;
|
|
112
|
-
export interface SubAgentDiscoveryResult {
|
|
113
|
-
directory: string;
|
|
114
|
-
agents: SubAgentConfig[];
|
|
115
|
-
warnings: string[];
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* `subagent` (role-based) invocation surface (spec 046, D2.1). Deliberately has no override
|
|
119
|
-
* fields beyond `purpose`: everything else a configured role could vary — tools, model, effort,
|
|
120
|
-
* context, thinkingLevel, mutates — lives in the role file, which is the deployer's decision, not
|
|
121
|
-
* a per-call one. This is what makes "external role + tools/model/mutates" unrepresentable at the
|
|
122
|
-
* type level instead of rejected at runtime (spec 042 D3's three checks are now dead by construction).
|
|
123
|
-
*/
|
|
124
|
-
export interface ConfiguredRoleOverrides {
|
|
125
|
-
agent: string;
|
|
126
|
-
/** Drives the thinkingLevel default: "verify" defaults on, everything else stays off. */
|
|
127
|
-
purpose?: string;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* `subagent_inline` invocation surface (spec 046, D2.1) — a one-off executor with no role file,
|
|
131
|
-
* so every field a role file would otherwise supply is a call-time override here instead.
|
|
132
|
-
*/
|
|
133
|
-
export interface InlineAgentOverrides {
|
|
134
|
-
systemPrompt: string;
|
|
135
|
-
tools?: string[];
|
|
136
|
-
model?: string;
|
|
137
|
-
/** Named budget preset; wins over frontmatter numbers as a whole tuple, never field by field. */
|
|
138
|
-
effort?: string;
|
|
139
|
-
/** Collapsed `contextMode` + `memory`; see SubAgentContextChoice. */
|
|
140
|
-
context?: string;
|
|
141
|
-
thinkingLevel?: string;
|
|
142
|
-
/** Drives the thinkingLevel default: "verify" defaults on, everything else stays off. */
|
|
143
|
-
purpose?: string;
|
|
144
|
-
mutates?: string;
|
|
145
|
-
}
|
|
146
|
-
/** Internal work/verify default, aligned with the main agent's DEFAULT_MAIN_THINKING_LEVEL
|
|
147
|
-
* (channel-runner.ts). External work leaves thinkingLevel unset instead (see resolveSubAgentConfig):
|
|
148
|
-
* pipiclaw has no standing to pick a reasoning effort for another CLI's own configuration. */
|
|
149
|
-
export declare const DEFAULT_THINKING_LEVEL: SubAgentThinkingLevel;
|
|
150
|
-
export declare function validateSubAgentTask(task: string): string | undefined;
|
|
4
|
+
import { type SubAgentConfig, type SubAgentDiscoveryResult, type SubAgentMutates } from "./types.js";
|
|
5
|
+
export declare function validateSubAgentSystemPrompt(systemPrompt: string, label: string): string | undefined;
|
|
151
6
|
export declare function getSubAgentsDir(workspaceDir: string): string;
|
|
152
7
|
/**
|
|
153
8
|
* Deny `write`/`edit` on `workspace/sub-agents/` itself (spec 040, D8.1).
|
|
@@ -160,66 +15,30 @@ export declare function getSubAgentsDir(workspaceDir: string): string;
|
|
|
160
15
|
* role directory hot-reloads on purpose (P4): this is the only gate, and it must stay cheap.
|
|
161
16
|
*/
|
|
162
17
|
export declare function withSubAgentsDirWriteDeny(config: SecurityConfig, workspaceDir: string): SecurityConfig;
|
|
163
|
-
export declare function
|
|
164
|
-
tools: SubAgentToolName[];
|
|
165
|
-
error?: string;
|
|
166
|
-
};
|
|
167
|
-
type FieldSupport = "supported" | "rejected";
|
|
18
|
+
export declare function readOptionalTrimmedString(value: unknown): string | undefined;
|
|
168
19
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* `
|
|
172
|
-
* defect, not a leniency (the review that produced spec 042 found `shell`/`env` on an internal
|
|
173
|
-
* role doing exactly that before this table existed). `cwd` is deliberately absent: it is rejected
|
|
174
|
-
* for *both* runtimes with a different message ("not a role field at all"), handled separately in
|
|
175
|
-
* `loadAgentsFromDir` rather than as a per-runtime mismatch.
|
|
20
|
+
* Shared shape for every frontmatter/override field whose only validation is "one of a fixed
|
|
21
|
+
* allow-list, else report an error and fall back": `contextMode`, `thinkingLevel`, `effort`,
|
|
22
|
+
* `runtime`, `harness`, `workload`, `mutates` all share this logic.
|
|
176
23
|
*/
|
|
177
|
-
export declare
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Resolve a `subagent` (role-based) invocation (spec 046, D2.1).
|
|
181
|
-
*
|
|
182
|
-
* Everything the old combined resolver used to override for a configured role — `tools`,
|
|
183
|
-
* `model`, `effort`, `context`, `mutates` — now has nowhere to come from but the role file
|
|
184
|
-
* itself, so this is a lookup plus the two facts a role file cannot pin down: the default model
|
|
185
|
-
* (parent's current model, or `settings.subagentModel`) and the purpose-driven thinkingLevel
|
|
186
|
-
* default. Spec 042 D3's three "external + override" rejections no longer apply: `ConfiguredRoleOverrides`
|
|
187
|
-
* has no `tools`/`model`/`mutates` field to reject in the first place.
|
|
188
|
-
*/
|
|
189
|
-
export declare function resolveConfiguredRole(availableModels: Model<Api>[], currentModel: Model<Api>, predefinedAgents: SubAgentConfig[], overrides: ConfiguredRoleOverrides,
|
|
190
|
-
/**
|
|
191
|
-
* `settings.subagentModel` (spec 032 D5): used only when neither the role file's frontmatter
|
|
192
|
-
* nor this call names a model (it cannot — there is no override field for it).
|
|
193
|
-
*/
|
|
194
|
-
subagentDefaultModelRef?: string): {
|
|
195
|
-
config?: ResolvedSubAgentConfig;
|
|
24
|
+
export declare function parseEnumField<T extends string>(raw: unknown, label: string, allowed: readonly T[], fallback?: T): {
|
|
25
|
+
value?: T;
|
|
196
26
|
error?: string;
|
|
197
27
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
* file. `runtime` is always `"internal"` here: only a configured role file can name `external`,
|
|
201
|
-
* and `InlineAgentOverrides` has no field for it, so the old function's external branches
|
|
202
|
-
* (budget table, unset-by-default thinkingLevel, model/tools/mutates rejections) simply do not
|
|
203
|
-
* apply to this path and are not reproduced here.
|
|
204
|
-
*/
|
|
205
|
-
export declare function resolveInlineAgent(availableModels: Model<Api>[], currentModel: Model<Api>, overrides: InlineAgentOverrides,
|
|
206
|
-
/** `settings.subagentModel` (spec 032 D5): used only when this call does not name a model. */
|
|
207
|
-
subagentDefaultModelRef?: string): {
|
|
208
|
-
config?: ResolvedInternalSubAgentConfig;
|
|
28
|
+
export declare function validateToolNames(values: string[] | undefined): {
|
|
29
|
+
tools: SubAgentToolName[];
|
|
209
30
|
error?: string;
|
|
210
|
-
warning?: string;
|
|
211
31
|
};
|
|
212
|
-
export declare function
|
|
32
|
+
export declare function resolveModelReference(modelRef: string, availableModels: Model<Api>[]): {
|
|
33
|
+
model?: Model<Api>;
|
|
34
|
+
error?: string;
|
|
35
|
+
};
|
|
36
|
+
export declare function inferMutatesFromTools(tools: SubAgentToolName[]): SubAgentMutates;
|
|
37
|
+
export declare function discoverSubAgents(workspaceDir: string, availableModels: Model<Api>[]): SubAgentDiscoveryResult;
|
|
213
38
|
/**
|
|
214
39
|
* Spec 042 D7: a fingerprint of the parts of an external role that decide *how a launched process
|
|
215
40
|
* is built* — `command`, `externalModelRef`, `shell`. Persisted on a run at launch and compared
|
|
216
|
-
* against the role's current config on `follow_up
|
|
217
|
-
*
|
|
218
|
-
* refuses rather than silently reinterpreting the old session with the new config.
|
|
219
|
-
*
|
|
220
|
-
* Deliberately narrow — `systemPrompt` and `maxWallTimeSec` are excluded on purpose. A resumed
|
|
221
|
-
* session already carries its own context, and folding prompt edits in would mean "fix a typo in
|
|
222
|
-
* the role" breaks every in-flight follow-up; a full invocation snapshot was considered and
|
|
223
|
-
* rejected for the same reason (spec 042 design doc, "已驳回的方案").
|
|
41
|
+
* against the role's current config on `follow_up` so hot-edited roles cannot silently resume an
|
|
42
|
+
* older session under a changed executable/model/shell mode.
|
|
224
43
|
*/
|
|
225
44
|
export declare function externalRoleFingerprint(role: Pick<SubAgentConfig, "command" | "externalModelRef" | "shell">): string;
|