@oyasmi/pipiclaw 0.9.1 → 0.9.2-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/dist/agent/channel-runner.d.ts +15 -1
  2. package/dist/agent/channel-runner.js +76 -24
  3. package/dist/agent/effect-ledger.js +9 -2
  4. package/dist/agent/job-manager.d.ts +4 -0
  5. package/dist/agent/job-manager.js +17 -2
  6. package/dist/agent/prompt/manifest.d.ts +1 -1
  7. package/dist/agent/prompt/manifest.js +1 -1
  8. package/dist/agent/prompt/sections.js +8 -5
  9. package/dist/agent/session-events.d.ts +2 -0
  10. package/dist/agent/session-events.js +29 -14
  11. package/dist/agent/turn-recovery.js +2 -2
  12. package/dist/agent/type-guards.js +5 -1
  13. package/dist/agent/workspace-resources.d.ts +2 -2
  14. package/dist/agent/workspace-resources.js +41 -3
  15. package/dist/executor.d.ts +14 -0
  16. package/dist/executor.js +96 -24
  17. package/dist/file-store.d.ts +96 -0
  18. package/dist/file-store.js +189 -0
  19. package/dist/memory/consolidation.js +2 -26
  20. package/dist/memory/files.js +7 -7
  21. package/dist/memory/maintenance-jobs.js +2 -34
  22. package/dist/memory/maintenance-state.js +2 -1
  23. package/dist/memory/recall.d.ts +10 -0
  24. package/dist/memory/recall.js +15 -7
  25. package/dist/memory/session-search.js +6 -22
  26. package/dist/memory/transcript.d.ts +10 -0
  27. package/dist/memory/transcript.js +39 -0
  28. package/dist/playbooks/agent-delegation.md +7 -5
  29. package/dist/playbooks/background-jobs.md +1 -1
  30. package/dist/playbooks/catalog.d.ts +1 -1
  31. package/dist/playbooks/catalog.js +1 -1
  32. package/dist/playbooks/event-scheduling.md +2 -0
  33. package/dist/playbooks/memory-and-learning.md +11 -11
  34. package/dist/playbooks/runtime-orientation.md +3 -3
  35. package/dist/playbooks/task-driving.md +7 -7
  36. package/dist/playbooks/task-planning.md +5 -5
  37. package/dist/runtime/app-home.js +1 -1
  38. package/dist/runtime/bootstrap.js +10 -0
  39. package/dist/runtime/dingtalk.js +3 -2
  40. package/dist/runtime/durable-dispatch.d.ts +26 -1
  41. package/dist/runtime/durable-dispatch.js +51 -5
  42. package/dist/runtime/event-commands.js +7 -16
  43. package/dist/runtime/events.d.ts +4 -2
  44. package/dist/runtime/events.js +15 -20
  45. package/dist/runtime/subagent-commands.js +1 -1
  46. package/dist/runtime/task-commands.d.ts +1 -1
  47. package/dist/runtime/task-commands.js +17 -12
  48. package/dist/runtime/task-driver.js +2 -2
  49. package/dist/runtime/task-wake.d.ts +2 -2
  50. package/dist/runtime/task-wake.js +2 -2
  51. package/dist/security/block-message.d.ts +11 -0
  52. package/dist/security/block-message.js +12 -0
  53. package/dist/security/path-guard-check.d.ts +13 -0
  54. package/dist/security/path-guard-check.js +39 -0
  55. package/dist/security/path-guard.js +32 -14
  56. package/dist/settings.js +3 -2
  57. package/dist/shared/atomic-file.d.ts +17 -1
  58. package/dist/shared/atomic-file.js +50 -3
  59. package/dist/shared/duration.d.ts +2 -0
  60. package/dist/shared/duration.js +7 -0
  61. package/dist/shared/safe-id.d.ts +19 -0
  62. package/dist/shared/safe-id.js +24 -0
  63. package/dist/shared/text-utils.d.ts +1 -1
  64. package/dist/shared/text-utils.js +3 -8
  65. package/dist/shared/type-guards.d.ts +2 -0
  66. package/dist/shared/type-guards.js +4 -0
  67. package/dist/subagents/discovery.d.ts +44 -17
  68. package/dist/subagents/discovery.js +82 -111
  69. package/dist/subagents/external/claude-code.js +1 -3
  70. package/dist/subagents/external/harness.d.ts +1 -1
  71. package/dist/subagents/external/run.d.ts +6 -0
  72. package/dist/subagents/external/run.js +122 -58
  73. package/dist/subagents/external/settlement.d.ts +3 -0
  74. package/dist/subagents/external/settlement.js +19 -5
  75. package/dist/subagents/format.d.ts +3 -2
  76. package/dist/subagents/format.js +3 -7
  77. package/dist/subagents/runs.d.ts +45 -9
  78. package/dist/subagents/runs.js +184 -64
  79. package/dist/subagents/tool.d.ts +35 -24
  80. package/dist/subagents/tool.js +631 -577
  81. package/dist/subagents/verification-outcome.js +1 -1
  82. package/dist/subagents/workspace-lease.js +1 -1
  83. package/dist/tasks/artifact-subject.d.ts +30 -4
  84. package/dist/tasks/artifact-subject.js +257 -25
  85. package/dist/tasks/control.js +7 -9
  86. package/dist/tasks/ledger.d.ts +2 -2
  87. package/dist/tasks/ledger.js +3 -7
  88. package/dist/tasks/transitions.d.ts +5 -1
  89. package/dist/tasks/transitions.js +2 -2
  90. package/dist/tasks/verification.d.ts +24 -2
  91. package/dist/tasks/verification.js +113 -21
  92. package/dist/tools/bash.d.ts +0 -1
  93. package/dist/tools/bash.js +45 -40
  94. package/dist/tools/config.d.ts +6 -1
  95. package/dist/tools/config.js +9 -0
  96. package/dist/tools/edit.d.ts +2 -3
  97. package/dist/tools/edit.js +274 -86
  98. package/dist/tools/event-manage.d.ts +13 -7
  99. package/dist/tools/event-manage.js +52 -14
  100. package/dist/tools/glob-match.d.ts +11 -0
  101. package/dist/tools/glob-match.js +75 -0
  102. package/dist/tools/glob.d.ts +15 -0
  103. package/dist/tools/glob.js +113 -0
  104. package/dist/tools/grep.d.ts +0 -1
  105. package/dist/tools/grep.js +57 -42
  106. package/dist/tools/ignore-dirs.d.ts +6 -0
  107. package/dist/tools/ignore-dirs.js +15 -0
  108. package/dist/tools/index.d.ts +3 -0
  109. package/dist/tools/index.js +50 -40
  110. package/dist/tools/job.d.ts +0 -1
  111. package/dist/tools/job.js +1 -8
  112. package/dist/tools/line-index.d.ts +16 -0
  113. package/dist/tools/line-index.js +76 -0
  114. package/dist/tools/memory-manage.d.ts +20 -8
  115. package/dist/tools/memory-manage.js +65 -92
  116. package/dist/tools/presentation.d.ts +2 -0
  117. package/dist/tools/presentation.js +109 -0
  118. package/dist/tools/read.d.ts +2 -2
  119. package/dist/tools/read.js +97 -133
  120. package/dist/tools/registry.d.ts +4 -1
  121. package/dist/tools/registry.js +89 -22
  122. package/dist/tools/send-media.d.ts +6 -6
  123. package/dist/tools/send-media.js +16 -49
  124. package/dist/tools/session-search.d.ts +0 -1
  125. package/dist/tools/session-search.js +0 -1
  126. package/dist/tools/skill-security.d.ts +0 -2
  127. package/dist/tools/skill-security.js +0 -24
  128. package/dist/tools/skill.d.ts +31 -0
  129. package/dist/tools/skill.js +153 -0
  130. package/dist/tools/subagent-manage.d.ts +6 -5
  131. package/dist/tools/subagent-manage.js +60 -60
  132. package/dist/tools/task-manage/create.d.ts +2 -2
  133. package/dist/tools/task-manage/create.js +1 -3
  134. package/dist/tools/task-manage/lifecycle.d.ts +9 -6
  135. package/dist/tools/task-manage/lifecycle.js +56 -60
  136. package/dist/tools/task-manage/schema.d.ts +27 -15
  137. package/dist/tools/task-manage/schema.js +58 -74
  138. package/dist/tools/task-manage/shared.d.ts +11 -6
  139. package/dist/tools/task-manage/shared.js +30 -21
  140. package/dist/tools/task-manage/types.d.ts +14 -15
  141. package/dist/tools/task-manage/verification.d.ts +5 -5
  142. package/dist/tools/task-manage/verification.js +18 -15
  143. package/dist/tools/task-manage.d.ts +8 -11
  144. package/dist/tools/task-manage.js +63 -50
  145. package/dist/tools/tool-details.d.ts +17 -1
  146. package/dist/tools/tool-details.js +24 -0
  147. package/dist/tools/truncate.d.ts +5 -5
  148. package/dist/tools/truncate.js +5 -5
  149. package/dist/tools/web-fetch.d.ts +0 -1
  150. package/dist/tools/web-fetch.js +0 -1
  151. package/dist/tools/web-search.d.ts +0 -1
  152. package/dist/tools/web-search.js +0 -1
  153. package/dist/tools/write-content.d.ts +3 -3
  154. package/dist/tools/write-content.js +12 -51
  155. package/dist/tools/write.d.ts +2 -3
  156. package/dist/tools/write.js +3 -4
  157. package/dist/tui/pitui-frontend.js +3 -3
  158. package/dist/usage/ledger.js +7 -4
  159. package/examples/sub-agents/README.md +13 -13
  160. package/examples/sub-agents/documenter.md +2 -1
  161. package/examples/sub-agents/reviewer.md +2 -0
  162. package/examples/sub-agents/scout.md +2 -1
  163. package/examples/sub-agents/verifier.md +6 -4
  164. package/examples/sub-agents/worker.md +2 -1
  165. package/package.json +5 -5
  166. package/dist/tools/skill-manage.d.ts +0 -41
  167. package/dist/tools/skill-manage.js +0 -232
@@ -1,10 +1,12 @@
1
1
  import { createHash } from "node:crypto";
2
+ import { realpathSync, statSync } from "node:fs";
2
3
  import { mkdir, readFile } from "node:fs/promises";
3
- import { join } from "node:path";
4
+ import { isAbsolute, join, win32 } from "node:path";
4
5
  import { writeFileAtomically } from "../shared/atomic-file.js";
5
6
  import { parseLocalTime } from "../shared/local-time.js";
6
7
  import { errorMessage } from "../shared/text-utils.js";
7
8
  import { readStoredTask, taskBodyHash } from "./store.js";
9
+ const FULL_COMMIT_PATTERN = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/i;
8
10
  function attestationFilename(runId) {
9
11
  return `${createHash("sha256").update(runId).digest("hex")}.json`;
10
12
  }
@@ -18,10 +20,43 @@ export function parseVerificationVerdict(output) {
18
20
  const value = /(?:^|\n)VERDICT:\s*(PASS|FAIL)\s*$/i.exec(output.trim())?.[1]?.toLowerCase();
19
21
  return value === "pass" || value === "fail" ? value : undefined;
20
22
  }
23
+ /** Translate an attestation's subject metadata into the hash options used by verify/close. */
24
+ export function getVerificationSubjectHashOptions(attestation) {
25
+ if (attestation.subjectMode !== "base-relative" && attestation.subjectBaseCommit === undefined)
26
+ return undefined;
27
+ if (attestation.subjectBaseCommit === undefined)
28
+ return undefined;
29
+ if (attestation.subjectMode === "base-relative" && attestation.subjectBaselineUntrackedPaths === undefined)
30
+ return undefined;
31
+ return {
32
+ baseCommit: attestation.subjectBaseCommit,
33
+ baselineUntrackedPaths: attestation.subjectBaselineUntrackedPaths ?? [],
34
+ };
35
+ }
21
36
  export async function writeVerificationAttestation(channelDir, input) {
22
37
  const task = await readStoredTask(channelDir, input.taskId);
23
38
  if (!task)
24
39
  throw new Error(`Cannot attest verification: task "${input.taskId}" does not exist.`);
40
+ const hasSubjectHash = input.subjectHash !== undefined;
41
+ const subjectMode = hasSubjectHash
42
+ ? (input.subjectMode ?? (input.subjectBaseCommit !== undefined ? "base-relative" : "legacy-head"))
43
+ : input.subjectMode;
44
+ if (subjectMode === "base-relative" &&
45
+ (input.subjectBaseCommit === undefined ||
46
+ !FULL_COMMIT_PATTERN.test(input.subjectBaseCommit.trim()) ||
47
+ !input.subjectBaselineUntrackedPaths)) {
48
+ throw new Error("Cannot attest verification: base-relative subject metadata is incomplete.");
49
+ }
50
+ if (subjectMode === "legacy-head" &&
51
+ (input.subjectBaseCommit !== undefined || input.subjectBaselineUntrackedPaths !== undefined)) {
52
+ throw new Error("Cannot attest verification: legacy-head subject cannot carry base-relative metadata.");
53
+ }
54
+ if (!hasSubjectHash &&
55
+ (subjectMode !== undefined ||
56
+ input.subjectBaseCommit !== undefined ||
57
+ input.subjectBaselineUntrackedPaths !== undefined)) {
58
+ throw new Error("Cannot attest verification: subject metadata requires a subject hash.");
59
+ }
25
60
  const attestation = {
26
61
  version: 1,
27
62
  runId: input.runId,
@@ -32,14 +67,39 @@ export async function writeVerificationAttestation(channelDir, input) {
32
67
  evidence: input.evidence,
33
68
  workspaceChanged: input.workspaceChanged,
34
69
  subjectHash: input.subjectHash,
35
- subjectDir: input.subjectHash ? input.subjectDir : undefined,
70
+ subjectDir: hasSubjectHash ? input.subjectDir : undefined,
71
+ subjectMode,
72
+ subjectBaseCommit: subjectMode === "base-relative" ? input.subjectBaseCommit : undefined,
73
+ subjectBaselineUntrackedPaths: subjectMode === "base-relative" ? [...(input.subjectBaselineUntrackedPaths ?? [])] : undefined,
36
74
  verificationStrength: input.verificationStrength,
37
75
  };
38
76
  await mkdir(verificationDir(channelDir), { recursive: true });
39
77
  await writeFileAtomically(verificationAttestationPath(channelDir, input.runId), `${JSON.stringify(attestation, null, 2)}\n`);
40
78
  return attestation;
41
79
  }
42
- export async function readVerificationAttestation(channelDir, runId) {
80
+ function canonicalDirectory(path) {
81
+ try {
82
+ const canonical = realpathSync(path);
83
+ return statSync(canonical).isDirectory() ? canonical : undefined;
84
+ }
85
+ catch {
86
+ return undefined;
87
+ }
88
+ }
89
+ function bindSubjectDirectory(runId, subjectDir, options) {
90
+ if (!options || subjectDir === undefined)
91
+ return subjectDir;
92
+ if (!options.trustedWorkingDirectory) {
93
+ throw new Error(`Verification run "${runId}" has a subjectDir but no persisted workingDirectory is available; refusing to trust this attestation. Rerun the verifier.`);
94
+ }
95
+ const canonicalSubjectDir = canonicalDirectory(subjectDir);
96
+ const canonicalWorkingDirectory = canonicalDirectory(options.trustedWorkingDirectory);
97
+ if (!canonicalSubjectDir || !canonicalWorkingDirectory || canonicalSubjectDir !== canonicalWorkingDirectory) {
98
+ throw new Error(`Verification run "${runId}" subjectDir does not match its persisted workingDirectory; refusing to trust this attestation. Rerun the verifier.`);
99
+ }
100
+ return canonicalSubjectDir;
101
+ }
102
+ export async function readVerificationAttestation(channelDir, runId, options) {
43
103
  let value;
44
104
  try {
45
105
  value = JSON.parse(await readFile(verificationAttestationPath(channelDir, runId), "utf-8"));
@@ -47,29 +107,61 @@ export async function readVerificationAttestation(channelDir, runId) {
47
107
  catch (error) {
48
108
  throw new Error(`Verification run "${runId}" was not found or is unreadable. Run a subagent with purpose=verify and taskId first. ${errorMessage(error)}`);
49
109
  }
110
+ const raw = (typeof value === "object" && value !== null ? value : {});
111
+ const subjectMode = raw.subjectMode !== undefined
112
+ ? raw.subjectMode
113
+ : raw.subjectBaseCommit !== undefined
114
+ ? "base-relative"
115
+ : "legacy-head";
116
+ const safeSubjectPath = (path) => {
117
+ const normalized = path.replaceAll("\\", "/");
118
+ return (path.length > 0 &&
119
+ !isAbsolute(path) &&
120
+ !win32.isAbsolute(path) &&
121
+ !path.includes("\0") &&
122
+ !normalized.split("/").includes(".."));
123
+ };
50
124
  if (typeof value !== "object" ||
51
125
  value === null ||
52
- value.version !== 1 ||
53
- value.runId !== runId ||
54
- typeof value.taskId !== "string" ||
55
- (value.verdict !== "pass" && value.verdict !== "fail") ||
56
- typeof value.checkedAt !== "string" ||
57
- parseLocalTime(value.checkedAt) === undefined ||
58
- !/^[a-f0-9]{64}$/i.test(String(value.bodyHash)) ||
59
- typeof value.evidence !== "string" ||
60
- typeof value.workspaceChanged !== "boolean" ||
61
- (value.subjectHash !== undefined &&
62
- !/^[a-f0-9]{64}$/i.test(String(value.subjectHash))) ||
63
- (value.subjectDir !== undefined &&
64
- typeof value.subjectDir !== "string") ||
65
- (value.verificationStrength !== undefined &&
66
- value.verificationStrength !== "enforced" &&
67
- value.verificationStrength !== "advisory")) {
126
+ raw.version !== 1 ||
127
+ raw.runId !== runId ||
128
+ typeof raw.taskId !== "string" ||
129
+ (raw.verdict !== "pass" && raw.verdict !== "fail") ||
130
+ typeof raw.checkedAt !== "string" ||
131
+ parseLocalTime(raw.checkedAt) === undefined ||
132
+ !/^[a-f0-9]{64}$/i.test(String(raw.bodyHash)) ||
133
+ typeof raw.evidence !== "string" ||
134
+ typeof raw.workspaceChanged !== "boolean" ||
135
+ (raw.subjectHash !== undefined && !/^[a-f0-9]{64}$/i.test(String(raw.subjectHash))) ||
136
+ (raw.subjectDir !== undefined && typeof raw.subjectDir !== "string") ||
137
+ (raw.subjectMode !== undefined && subjectMode !== "legacy-head" && subjectMode !== "base-relative") ||
138
+ (raw.subjectBaseCommit !== undefined &&
139
+ (typeof raw.subjectBaseCommit !== "string" || !FULL_COMMIT_PATTERN.test(raw.subjectBaseCommit.trim()))) ||
140
+ (raw.subjectBaselineUntrackedPaths !== undefined &&
141
+ (!Array.isArray(raw.subjectBaselineUntrackedPaths) ||
142
+ raw.subjectBaselineUntrackedPaths.some((path) => typeof path !== "string" || !safeSubjectPath(path)))) ||
143
+ (raw.subjectHash === undefined &&
144
+ (raw.subjectMode !== undefined ||
145
+ raw.subjectBaseCommit !== undefined ||
146
+ raw.subjectBaselineUntrackedPaths !== undefined)) ||
147
+ (raw.subjectHash !== undefined &&
148
+ (subjectMode === "base-relative"
149
+ ? typeof raw.subjectBaseCommit !== "string" || !Array.isArray(raw.subjectBaselineUntrackedPaths)
150
+ : raw.subjectBaseCommit !== undefined || raw.subjectBaselineUntrackedPaths !== undefined)) ||
151
+ (raw.verificationStrength !== undefined &&
152
+ raw.verificationStrength !== "enforced" &&
153
+ raw.verificationStrength !== "advisory")) {
68
154
  throw new Error(`Verification run "${runId}" has an invalid attestation. Run the verifier again.`);
69
155
  }
70
- // Pre-spec-040 attestations predate this field; every verifier back then was built-in.
71
- return {
156
+ // Pre-spec-040 attestations predate this field; every verifier back then was built-in. When an
157
+ // old attestation also lacks subjectDir, consumers may keep its legacy subject semantics. A
158
+ // subjectDir-bearing attestation is newer and, when read by task lifecycle code, must be bound to
159
+ // a still-available persisted run record instead of choosing an arbitrary checkout.
160
+ const attestation = {
72
161
  ...value,
162
+ subjectMode: subjectMode,
73
163
  verificationStrength: value.verificationStrength ?? "enforced",
74
164
  };
165
+ const boundSubjectDir = bindSubjectDirectory(runId, attestation.subjectDir, options);
166
+ return boundSubjectDir === attestation.subjectDir ? attestation : { ...attestation, subjectDir: boundSubjectDir };
75
167
  }
@@ -11,7 +11,6 @@ import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.j
11
11
  */
12
12
  export declare const DEFAULT_BASH_TIMEOUT_SECONDS = 300;
13
13
  declare const bashSchema: Type.TObject<{
14
- label: Type.TString;
15
14
  command: Type.TString;
16
15
  timeout: Type.TOptional<Type.TInteger>;
17
16
  async: Type.TOptional<Type.TBoolean>;
@@ -1,11 +1,13 @@
1
1
  import { randomBytes } from "node:crypto";
2
- import { writeFile } from "node:fs/promises";
2
+ import { unlink } from "node:fs/promises";
3
3
  import { Type } from "typebox";
4
4
  import { CommandTerminatedError } from "../executor.js";
5
+ import { formatBlockMessage } from "../security/block-message.js";
5
6
  import { guardCommand } from "../security/command-guard.js";
6
7
  import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
7
8
  import { logSecurityEvent } from "../security/logger.js";
8
9
  import { RecoverableToolError } from "../shared/recoverable-error.js";
10
+ import { clipText } from "../shared/text-utils.js";
9
11
  import { maybeOptimizeCommand } from "./command-optimizer.js";
10
12
  import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateTail } from "./truncate.js";
11
13
  /**
@@ -25,7 +27,6 @@ function getSpillFilePath() {
25
27
  return `/tmp/pipiclaw-bash-${id}.log`;
26
28
  }
27
29
  const bashSchema = Type.Object({
28
- label: Type.String({ description: "Brief description of what this command does (shown to user)" }),
29
30
  command: Type.String({ description: "Bash command to execute" }),
30
31
  timeout: Type.Optional(Type.Integer({
31
32
  minimum: 1,
@@ -61,6 +62,16 @@ const BASH_INTERCEPTOR_RULES = [
61
62
  why: "it groups, paginates, and bounds output instead of flooding the context",
62
63
  },
63
64
  { test: /^\s*rg\b[^|&;]*$/, tool: "grep", why: "it groups, paginates, and bounds output" },
65
+ {
66
+ test: /^\s*find\s+[^|&;<>`$()]*-name\b[^|&;<>`$()]*$/,
67
+ tool: "glob",
68
+ why: "it discovers paths by pattern without a platform-dependent find dialect, and bounds/sorts the result",
69
+ },
70
+ {
71
+ test: /^\s*ls\s+-[A-Za-z]*R[A-Za-z]*\b[^|&;<>]*$/,
72
+ tool: "glob",
73
+ why: "it discovers file paths without listing directories, and bounds/sorts the result",
74
+ },
64
75
  {
65
76
  test: /\b(?:sed|perl)\b[^|&;]*\s-i\b/,
66
77
  tool: "edit",
@@ -76,18 +87,11 @@ function checkBashInterception(command) {
76
87
  return null;
77
88
  }
78
89
  function formatCommandBlockMessage(command, category, reason, matchedText) {
79
- const lines = [`Command blocked${category ? ` [${category}]` : ""}`];
80
- if (reason) {
81
- lines.push(`Reason: ${reason}`);
82
- }
83
- if (matchedText) {
84
- lines.push(`Matched: ${matchedText}`);
85
- }
86
- else {
87
- lines.push(`Command: ${command}`);
88
- }
89
- lines.push("If this operation is genuinely needed, explain the intent to the user so they can adjust security.json.");
90
- return lines.join("\n");
90
+ const details = [];
91
+ if (reason)
92
+ details.push({ label: "Reason", value: reason });
93
+ details.push(matchedText ? { label: "Matched", value: matchedText } : { label: "Command", value: command });
94
+ return `${formatBlockMessage("Command", category, details)}\nIf this operation is genuinely needed, explain the intent to the user so they can adjust security.json.`;
91
95
  }
92
96
  export function createBashTool(executor, options = {}) {
93
97
  const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
@@ -100,7 +104,7 @@ export function createBashTool(executor, options = {}) {
100
104
  label: "bash",
101
105
  description: `Execute a bash command in the current working directory. Returns stdout, stderr, and the exit code (a non-zero exit code is reported in the output, not raised as an error). Output is truncated to the last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, the full output is saved to a temp file whose path is included. Commands time out after ${DEFAULT_BASH_TIMEOUT_SECONDS}s unless you pass a larger \`timeout\`.`,
102
106
  parameters: bashSchema,
103
- execute: async (_toolCallId, { label, command, timeout, async: runAsync, notify, taskId, }, signal) => {
107
+ execute: async (_toolCallId, { command, timeout, async: runAsync, notify, taskId, }, signal) => {
104
108
  if (securityConfig.enabled && securityConfig.commandGuard.enabled) {
105
109
  const guardResult = guardCommand(command, securityConfig.commandGuard);
106
110
  if (!guardResult.allowed) {
@@ -138,7 +142,8 @@ export function createBashTool(executor, options = {}) {
138
142
  throw new RecoverableToolError("Background execution is not available here (enable tools.jobs.enabled, and note it is off for sub-agents). Run the command without async, or shorten it.");
139
143
  }
140
144
  const willNotify = notify ?? true;
141
- const job = await options.jobManager.start(effectiveCommand, label, effectiveTimeout, {
145
+ const jobLabel = clipText(effectiveCommand, 60, { collapseWhitespace: true });
146
+ const job = await options.jobManager.start(effectiveCommand, jobLabel, effectiveTimeout, {
142
147
  signal,
143
148
  notify: willNotify,
144
149
  ...(taskId ? { taskId } : {}),
@@ -147,7 +152,7 @@ export function createBashTool(executor, options = {}) {
147
152
  content: [
148
153
  {
149
154
  type: "text",
150
- text: `Background job ${job.id} started: ${label}\n` +
155
+ text: `Background job ${job.id} started: ${jobLabel}\n` +
151
156
  (willNotify
152
157
  ? "It runs off-turn; end your turn now. You will be woken automatically when it finishes, " +
153
158
  "with its exit code and output — do not schedule a check-in for it."
@@ -161,7 +166,13 @@ export function createBashTool(executor, options = {}) {
161
166
  // result and one cut short by timeout/abort (fix plan §2.2): a timed-out `npm test` used
162
167
  // to reject with up to 10MB of raw output stuffed straight into the tool-call error
163
168
  // message, which the pi SDK puts into the model's context verbatim and unbounded.
164
- const buildOutputText = async (stdout, stderr) => {
169
+ //
170
+ // `spillPath` was written by the executor as stdout/stderr arrived (`ExecOptions.spillTo`,
171
+ // spec 044 D6.3) -- unlike the in-memory `stdout`/`stderr` here, it is never capped at
172
+ // the 10MB capture bound, so it is the one place that can honestly be called "full
173
+ // output" for a command whose real output exceeds that cap. It is deleted below when it
174
+ // turns out not to be needed.
175
+ const buildOutputText = async (stdout, stderr, spillPath) => {
165
176
  let output = "";
166
177
  if (stdout)
167
178
  output += stdout;
@@ -170,31 +181,14 @@ export function createBashTool(executor, options = {}) {
170
181
  output += "\n";
171
182
  output += stderr;
172
183
  }
173
- const totalBytes = Buffer.byteLength(output, "utf-8");
174
- // Spill the full output to a temp file when it exceeds the inline limit, so the model
175
- // can page through the rest with `read`. Written straight to disk rather than piped
176
- // through a second `sh -c 'cat > file'`: that spawned a process and copied the whole
177
- // (up to 10MB) buffer over a pipe to reach the same local filesystem the executor
178
- // already runs on. Best-effort: on failure we simply omit the path hint.
179
- let tempFilePath;
180
- if (totalBytes > DEFAULT_MAX_BYTES) {
181
- const candidatePath = getSpillFilePath();
182
- try {
183
- await writeFile(candidatePath, output, { mode: 0o600 });
184
- tempFilePath = candidatePath;
185
- }
186
- catch {
187
- // Ignore spill failures; the truncated output is still returned.
188
- }
189
- }
190
184
  const truncation = truncateTail(output);
191
185
  let text = truncation.content || "(no output)";
192
186
  let details;
193
187
  if (truncation.truncated) {
194
- details = { truncation, fullOutputPath: tempFilePath };
188
+ details = { truncation, fullOutputPath: spillPath };
195
189
  const startLine = truncation.totalLines - truncation.outputLines + 1;
196
190
  const endLine = truncation.totalLines;
197
- const fullOutputHint = tempFilePath ? ` Full output: ${tempFilePath}` : "";
191
+ const fullOutputHint = ` Full output: ${spillPath}`;
198
192
  if (truncation.lastLinePartial) {
199
193
  const lastLineSize = formatSize(Buffer.byteLength(output.split("\n").pop() || "", "utf-8"));
200
194
  text += `\n\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}).${fullOutputHint}]`;
@@ -206,11 +200,22 @@ export function createBashTool(executor, options = {}) {
206
200
  text += `\n\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit).${fullOutputHint}]`;
207
201
  }
208
202
  }
203
+ else {
204
+ // No truncation happened after all -- the spill file was insurance against the
205
+ // in-memory capture cap, not a promised artifact; clean it up rather than leaving
206
+ // tmp clutter behind on every single bash call.
207
+ await unlink(spillPath).catch(() => undefined);
208
+ }
209
209
  return { text, details: { ...details, producedOutput: output.trim().length > 0 } };
210
210
  };
211
+ const spillPath = getSpillFilePath();
211
212
  try {
212
- const result = await executor.exec(effectiveCommand, { timeout: effectiveTimeout, signal });
213
- const built = await buildOutputText(result.stdout, result.stderr);
213
+ const result = await executor.exec(effectiveCommand, {
214
+ timeout: effectiveTimeout,
215
+ signal,
216
+ spillTo: spillPath,
217
+ });
218
+ const built = await buildOutputText(result.stdout, result.stderr, spillPath);
214
219
  let outputText = built.text;
215
220
  // A non-zero exit code is a normal result, not a tool failure: commands like
216
221
  // `grep` (no match), `diff` (differences), and `test` use exit codes as data.
@@ -228,7 +233,7 @@ export function createBashTool(executor, options = {}) {
228
233
  if (!(error instanceof CommandTerminatedError)) {
229
234
  throw error;
230
235
  }
231
- const built = await buildOutputText(error.stdout, error.stderr);
236
+ const built = await buildOutputText(error.stdout, error.stderr, spillPath);
232
237
  const nextStep = error.reason === "timeout"
233
238
  ? `Retry with a larger \`timeout\` (currently ${error.timeoutSeconds}s), or pass \`async: true\` to run it in the background and be woken when it finishes.`
234
239
  : "The command was stopped (e.g. by /stop or a run cancellation); partial output above.";
@@ -27,7 +27,7 @@ export interface PipiclawToolsConfig {
27
27
  web: PipiclawWebToolsConfig;
28
28
  /**
29
29
  * Master switch for the autonomous long-running task mechanism: gates the
30
- * `task_manage` tool, the native TaskDriver, and the per-turn task digest
30
+ * task_* tools, the native TaskDriver, and the per-turn task digest
31
31
  * together. Core capabilities (read/bash/edit/write/grep, memory, skills,
32
32
  * events, background jobs) are always on and have no switches.
33
33
  */
@@ -40,6 +40,11 @@ export interface PipiclawToolsConfig {
40
40
  rtk: {
41
41
  enabled: boolean;
42
42
  };
43
+ /** Gates the `subagent_inline` tool (spec 046, D2.3). Default true; the role directory
44
+ * covers most delegation, so a deployment can turn this off once it does. */
45
+ subagentInline: {
46
+ enabled: boolean;
47
+ };
43
48
  };
44
49
  }
45
50
  export interface LoadedToolsConfig {
@@ -35,6 +35,9 @@ export const DEFAULT_TOOLS_CONFIG = {
35
35
  rtk: {
36
36
  enabled: false,
37
37
  },
38
+ subagentInline: {
39
+ enabled: true,
40
+ },
38
41
  },
39
42
  };
40
43
  function clampInteger(value, fallback, minimum, maximum) {
@@ -81,6 +84,7 @@ function mergeToolsConfig(source, configPath, diagnostics) {
81
84
  const tasks = isRecord(tools.tasks) ? tools.tasks : {};
82
85
  const bashInterceptor = isRecord(tools.bashInterceptor) ? tools.bashInterceptor : {};
83
86
  const rtk = isRecord(tools.rtk) ? tools.rtk : {};
87
+ const subagentInline = isRecord(tools.subagentInline) ? tools.subagentInline : {};
84
88
  const search = isRecord(web.search) ? web.search : {};
85
89
  const fetch = isRecord(web.fetch) ? web.fetch : {};
86
90
  const providerValue = asTrimmedString(search.provider, DEFAULT_TOOLS_CONFIG.tools.web.search.provider).toLowerCase();
@@ -156,6 +160,11 @@ function mergeToolsConfig(source, configPath, diagnostics) {
156
160
  rtk: {
157
161
  enabled: typeof rtk.enabled === "boolean" ? rtk.enabled : DEFAULT_TOOLS_CONFIG.tools.rtk.enabled,
158
162
  },
163
+ subagentInline: {
164
+ enabled: typeof subagentInline.enabled === "boolean"
165
+ ? subagentInline.enabled
166
+ : DEFAULT_TOOLS_CONFIG.tools.subagentInline.enabled,
167
+ },
159
168
  },
160
169
  };
161
170
  }
@@ -1,9 +1,8 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import { Type } from "typebox";
3
- import type { Executor } from "../executor.js";
3
+ import { type FileStore } from "../file-store.js";
4
4
  import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
5
5
  declare const editSchema: Type.TObject<{
6
- label: Type.TString;
7
6
  path: Type.TString;
8
7
  oldText: Type.TString;
9
8
  newText: Type.TString;
@@ -14,5 +13,5 @@ export interface EditToolOptions {
14
13
  securityContext?: SecurityRuntimeContext;
15
14
  channelId?: string;
16
15
  }
17
- export declare function createEditTool(executor: Executor, options?: EditToolOptions): AgentTool<typeof editSchema>;
16
+ export declare function createEditTool(fileStore: FileStore, options?: EditToolOptions): AgentTool<typeof editSchema>;
18
17
  export {};