@oyasmi/pipiclaw 0.9.1 → 0.9.2-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.
Files changed (149) hide show
  1. package/dist/agent/channel-runner.d.ts +2 -1
  2. package/dist/agent/channel-runner.js +9 -5
  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 +6 -4
  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 +5 -5
  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 +10 -10
  48. package/dist/runtime/task-driver.js +2 -2
  49. package/dist/security/block-message.d.ts +11 -0
  50. package/dist/security/block-message.js +12 -0
  51. package/dist/security/path-guard-check.d.ts +13 -0
  52. package/dist/security/path-guard-check.js +39 -0
  53. package/dist/security/path-guard.js +32 -14
  54. package/dist/settings.js +3 -2
  55. package/dist/shared/atomic-file.d.ts +17 -1
  56. package/dist/shared/atomic-file.js +50 -3
  57. package/dist/shared/duration.d.ts +2 -0
  58. package/dist/shared/duration.js +7 -0
  59. package/dist/shared/safe-id.d.ts +19 -0
  60. package/dist/shared/safe-id.js +24 -0
  61. package/dist/shared/text-utils.d.ts +1 -1
  62. package/dist/shared/text-utils.js +3 -8
  63. package/dist/shared/type-guards.d.ts +2 -0
  64. package/dist/shared/type-guards.js +4 -0
  65. package/dist/subagents/discovery.d.ts +44 -17
  66. package/dist/subagents/discovery.js +82 -111
  67. package/dist/subagents/external/claude-code.js +1 -3
  68. package/dist/subagents/external/harness.d.ts +1 -1
  69. package/dist/subagents/format.d.ts +3 -2
  70. package/dist/subagents/format.js +3 -7
  71. package/dist/subagents/runs.d.ts +1 -1
  72. package/dist/subagents/runs.js +4 -9
  73. package/dist/subagents/tool.d.ts +31 -19
  74. package/dist/subagents/tool.js +582 -561
  75. package/dist/subagents/workspace-lease.js +1 -1
  76. package/dist/tasks/control.js +7 -9
  77. package/dist/tasks/ledger.d.ts +2 -2
  78. package/dist/tasks/ledger.js +3 -7
  79. package/dist/tasks/transitions.d.ts +5 -1
  80. package/dist/tasks/transitions.js +2 -2
  81. package/dist/tools/bash.d.ts +0 -1
  82. package/dist/tools/bash.js +45 -40
  83. package/dist/tools/config.d.ts +6 -1
  84. package/dist/tools/config.js +9 -0
  85. package/dist/tools/edit.d.ts +2 -3
  86. package/dist/tools/edit.js +274 -86
  87. package/dist/tools/event-manage.d.ts +13 -7
  88. package/dist/tools/event-manage.js +52 -14
  89. package/dist/tools/glob-match.d.ts +11 -0
  90. package/dist/tools/glob-match.js +75 -0
  91. package/dist/tools/glob.d.ts +15 -0
  92. package/dist/tools/glob.js +113 -0
  93. package/dist/tools/grep.d.ts +0 -1
  94. package/dist/tools/grep.js +57 -42
  95. package/dist/tools/ignore-dirs.d.ts +6 -0
  96. package/dist/tools/ignore-dirs.js +15 -0
  97. package/dist/tools/index.d.ts +3 -0
  98. package/dist/tools/index.js +50 -40
  99. package/dist/tools/job.d.ts +0 -1
  100. package/dist/tools/job.js +1 -8
  101. package/dist/tools/line-index.d.ts +16 -0
  102. package/dist/tools/line-index.js +76 -0
  103. package/dist/tools/memory-manage.d.ts +20 -8
  104. package/dist/tools/memory-manage.js +65 -92
  105. package/dist/tools/presentation.d.ts +2 -0
  106. package/dist/tools/presentation.js +109 -0
  107. package/dist/tools/read.d.ts +2 -2
  108. package/dist/tools/read.js +97 -133
  109. package/dist/tools/registry.d.ts +4 -1
  110. package/dist/tools/registry.js +89 -22
  111. package/dist/tools/send-media.d.ts +6 -6
  112. package/dist/tools/send-media.js +16 -49
  113. package/dist/tools/session-search.d.ts +0 -1
  114. package/dist/tools/session-search.js +0 -1
  115. package/dist/tools/skill-security.d.ts +0 -2
  116. package/dist/tools/skill-security.js +0 -24
  117. package/dist/tools/skill.d.ts +31 -0
  118. package/dist/tools/skill.js +153 -0
  119. package/dist/tools/subagent-manage.d.ts +6 -5
  120. package/dist/tools/subagent-manage.js +47 -47
  121. package/dist/tools/task-manage/create.d.ts +2 -2
  122. package/dist/tools/task-manage/create.js +1 -3
  123. package/dist/tools/task-manage/lifecycle.d.ts +9 -6
  124. package/dist/tools/task-manage/lifecycle.js +49 -56
  125. package/dist/tools/task-manage/schema.d.ts +27 -15
  126. package/dist/tools/task-manage/schema.js +58 -74
  127. package/dist/tools/task-manage/shared.d.ts +11 -6
  128. package/dist/tools/task-manage/shared.js +30 -21
  129. package/dist/tools/task-manage/types.d.ts +14 -15
  130. package/dist/tools/task-manage/verification.d.ts +4 -4
  131. package/dist/tools/task-manage/verification.js +6 -8
  132. package/dist/tools/task-manage.d.ts +8 -11
  133. package/dist/tools/task-manage.js +63 -50
  134. package/dist/tools/tool-details.d.ts +17 -1
  135. package/dist/tools/tool-details.js +24 -0
  136. package/dist/tools/truncate.d.ts +5 -5
  137. package/dist/tools/truncate.js +5 -5
  138. package/dist/tools/web-fetch.d.ts +0 -1
  139. package/dist/tools/web-fetch.js +0 -1
  140. package/dist/tools/web-search.d.ts +0 -1
  141. package/dist/tools/web-search.js +0 -1
  142. package/dist/tools/write-content.d.ts +3 -3
  143. package/dist/tools/write-content.js +12 -51
  144. package/dist/tools/write.d.ts +2 -3
  145. package/dist/tools/write.js +3 -4
  146. package/dist/usage/ledger.js +7 -4
  147. package/package.json +1 -1
  148. package/dist/tools/skill-manage.d.ts +0 -41
  149. package/dist/tools/skill-manage.js +0 -232
@@ -57,5 +57,5 @@ export function findWorkspaceLeaseHolder(workingDirectory) {
57
57
  export function formatWorkspaceLeaseConflict(heldBy) {
58
58
  return (`Workspace "${heldBy.workingDirectory}" is already held by a running write delegation ` +
59
59
  `(runId ${heldBy.runId}, channel ${heldBy.channelId}). Wait for it to finish, cancel it with ` +
60
- "subagent_manage, or use a separate `git worktree add` checkout via workingDirectory.");
60
+ "subagent_run op=cancel, or use a separate `git worktree add` checkout via workingDirectory.");
61
61
  }
@@ -1,10 +1,8 @@
1
1
  import { formatLocalTime, parseLocalTime } from "../shared/local-time.js";
2
2
  import { errorMessage } from "../shared/text-utils.js";
3
+ import { isPlainObject } from "../shared/type-guards.js";
3
4
  const WAITING_FOR = ["time", "user", "job", "external-signal"];
4
5
  const VERIFICATION_STATUSES = ["pending", "passed", "failed"];
5
- function isRecord(value) {
6
- return typeof value === "object" && value !== null && !Array.isArray(value);
7
- }
8
6
  function optionalString(value) {
9
7
  if (typeof value !== "string")
10
8
  return undefined;
@@ -22,7 +20,7 @@ function enumValue(value, values, fallback) {
22
20
  function parseStop(value) {
23
21
  if (value === undefined)
24
22
  return undefined;
25
- if (!isRecord(value))
23
+ if (!isPlainObject(value))
26
24
  throw new Error("control.stop must be an object");
27
25
  const by = enumValue(value.by, ["user", "governor"], "user");
28
26
  const reason = optionalString(value.reason);
@@ -47,10 +45,10 @@ export function parseTaskControl(raw) {
47
45
  catch (error) {
48
46
  throw new Error(`control is not valid JSON: ${errorMessage(error)}`);
49
47
  }
50
- if (!isRecord(value) || value.version !== 3) {
51
- throw new Error("control must be a version 3 JSON object; repair it with task_manage set.");
48
+ if (!isPlainObject(value) || value.version !== 3) {
49
+ throw new Error("control must be a version 3 JSON object; repair it with task_update (no note).");
52
50
  }
53
- const verification = isRecord(value.verification) ? value.verification : {};
51
+ const verification = isPlainObject(value.verification) ? value.verification : {};
54
52
  const deadline = optionalString(value.deadline);
55
53
  if (deadline && parseLocalTime(deadline) === undefined) {
56
54
  throw new Error("control.deadline must be a valid local time");
@@ -83,10 +81,10 @@ export function parseLegacyTaskControl(raw) {
83
81
  catch (error) {
84
82
  throw new Error(`control is not valid JSON: ${errorMessage(error)}`);
85
83
  }
86
- if (!isRecord(value) || (value.version !== 1 && value.version !== 2)) {
84
+ if (!isPlainObject(value) || (value.version !== 1 && value.version !== 2)) {
87
85
  throw new Error("legacy control must be a version 1 or version 2 JSON object");
88
86
  }
89
- const verification = isRecord(value.verification) ? value.verification : {};
87
+ const verification = isPlainObject(value.verification) ? value.verification : {};
90
88
  const deadline = optionalString(value.deadline);
91
89
  const waitingFor = value.waitingFor === undefined ? undefined : enumValue(value.waitingFor, WAITING_FOR, "external-signal");
92
90
  let stop = parseStop(value.stop);
@@ -10,7 +10,7 @@ export type TaskArchiveOutcome = "completed" | "cancelled";
10
10
  * has a single owner. The parsing stays deliberately literal (flat `key: value` fields,
11
11
  * live-vs-archived, wake gating, fail-open on unreadable frontmatter) because task files
12
12
  * are hand-editable and must degrade toward "wake me up so I can be fixed".
13
- * `/tasks`, the task digest, and `task_manage list` all read through here.
13
+ * `/tasks`, the task digest, and `task_list` all read through here.
14
14
  */
15
15
  export interface TaskFrontmatter {
16
16
  /** false => frontmatter could not be read (fail-open: the task is treated as actionable). */
@@ -183,7 +183,7 @@ export declare function missingStandardTaskSections(content: string): string[];
183
183
  * Without the "no checklist items" case, a DoD written as prose or a numbered
184
184
  * list (no `- [ ]` anywhere) makes this function return an empty array —
185
185
  * indistinguishable from "everything is checked" — which would silently let
186
- * `task_manage complete` through with nothing ever actually verified.
186
+ * `task_close outcome=complete` through with nothing ever actually verified.
187
187
  */
188
188
  export declare function uncheckedTaskAcceptanceItems(content: string): string[];
189
189
  /**
@@ -2,6 +2,7 @@ import { readdir, readFile, stat } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { formatLocalTime, parseLocalTime } from "../shared/local-time.js";
4
4
  import { RecoverableToolError } from "../shared/recoverable-error.js";
5
+ import { normalizeSafeId } from "../shared/safe-id.js";
5
6
  import { parseTaskControl } from "./control.js";
6
7
  import { nextTaskWake } from "./task-schedule.js";
7
8
  import { normalizeStoredStatus } from "./transitions.js";
@@ -30,12 +31,7 @@ const HISTORY_OMISSION_NOTE = "- Older cycle details omitted from working contex
30
31
  const HISTORY_TRUNCATION_NOTE = "- Entry truncated in working context; use session_search with the task id or cycle id to inspect the complete cold history.";
31
32
  /** Validate/normalize a task id (filename without `.md`), rejecting path traversal. */
32
33
  export function normalizeTaskId(id) {
33
- const trimmed = id.trim();
34
- const normalized = trimmed.endsWith(".md") ? trimmed.slice(0, -".md".length) : trimmed;
35
- if (!normalized || normalized === "." || normalized === ".." || !TASK_ID_PATTERN.test(normalized)) {
36
- throw new Error(`Invalid task id: ${id}`);
37
- }
38
- return normalized;
34
+ return normalizeSafeId(id, { suffix: ".md", pattern: TASK_ID_PATTERN, label: "task id" });
39
35
  }
40
36
  /** The document body after the leading frontmatter block, or the whole content when there is none. */
41
37
  export function taskBody(content) {
@@ -366,7 +362,7 @@ export function missingStandardTaskSections(content) {
366
362
  * Without the "no checklist items" case, a DoD written as prose or a numbered
367
363
  * list (no `- [ ]` anywhere) makes this function return an empty array —
368
364
  * indistinguishable from "everything is checked" — which would silently let
369
- * `task_manage complete` through with nothing ever actually verified.
365
+ * `task_close outcome=complete` through with nothing ever actually verified.
370
366
  */
371
367
  export function uncheckedTaskAcceptanceItems(content) {
372
368
  const unchecked = [];
@@ -4,7 +4,11 @@ export type TaskStatus = (typeof TASK_STATUSES)[number];
4
4
  /** Statuses a model/user may set directly; recurring sleeping is runtime-owned but repairable. */
5
5
  export declare const SETTABLE_TASK_STATUSES: readonly ["active", "waiting", "sleeping"];
6
6
  export type SettableTaskStatus = (typeof SETTABLE_TASK_STATUSES)[number];
7
- export type TaskLifecycleAction = "create" | "progress" | "verify" | "complete" | "skip" | "cancel" | "set" | "pause" | "resume" | "run" | "governor-stop" | "wait-due" | "cycle-due";
7
+ export type TaskLifecycleAction = "create"
8
+ /** task_update with a `note` — a checkpoint on an open cycle. */
9
+ | "checkpoint" | "verify" | "complete" | "skip" | "cancel"
10
+ /** task_update with no `note` — a metadata-only edit (spec 046, D3.2). */
11
+ | "metadata" | "pause" | "resume" | "run" | "governor-stop" | "wait-due" | "cycle-due";
8
12
  /** Canonicalize a stored status value, fail-open to `active` for anything not in the current vocabulary. */
9
13
  export declare function normalizeStoredStatus(raw: string | undefined): TaskStatus;
10
14
  export declare function isSettableTaskStatus(value: string): value is SettableTaskStatus;
@@ -7,7 +7,7 @@ const LIVE = ["active", "waiting", "sleeping"];
7
7
  const WORKABLE = ["active", "waiting"];
8
8
  const TRANSITIONS = {
9
9
  create: { from: [], to: "active" },
10
- progress: { from: WORKABLE, to: "caller" },
10
+ checkpoint: { from: WORKABLE, to: "caller" },
11
11
  // Not gated on a specific waitingFor value: the wake that reactivates a task parked for a
12
12
  // purpose=verify sub-agent already flips it to active before this runs (the same as any other
13
13
  // delegation wake), but `verify` also accepts waiting so it is not sensitive to exactly when
@@ -16,7 +16,7 @@ const TRANSITIONS = {
16
16
  complete: { from: ["active"], to: "caller" },
17
17
  skip: { from: WORKABLE, to: "sleeping" },
18
18
  cancel: { from: LIVE, to: "caller" },
19
- set: { from: LIVE, to: "caller" },
19
+ metadata: { from: LIVE, to: "caller" },
20
20
  pause: { from: LIVE, to: "caller" },
21
21
  resume: { from: LIVE, to: "caller" },
22
22
  run: { from: LIVE, to: "active" },
@@ -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 {};