@oyasmi/pipiclaw 0.8.9 → 0.8.10-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 (75) hide show
  1. package/README.md +3 -3
  2. package/dist/agent/channel-runner.d.ts +1 -0
  3. package/dist/agent/channel-runner.js +6 -10
  4. package/dist/agent/maintenance-context.d.ts +0 -1
  5. package/dist/agent/maintenance-context.js +0 -7
  6. package/dist/agent/session-events.d.ts +1 -0
  7. package/dist/agent/session-events.js +10 -0
  8. package/dist/agent/types.d.ts +7 -0
  9. package/dist/agent/types.js +2 -0
  10. package/dist/index.d.ts +16 -34
  11. package/dist/index.js +14 -32
  12. package/dist/memory/consolidation.js +0 -1
  13. package/dist/memory/extraction.d.ts +1 -7
  14. package/dist/memory/extraction.js +2 -46
  15. package/dist/memory/lifecycle.js +3 -3
  16. package/dist/memory/maintenance-gates.d.ts +4 -16
  17. package/dist/memory/maintenance-gates.js +11 -51
  18. package/dist/memory/maintenance-jobs.d.ts +3 -14
  19. package/dist/memory/maintenance-jobs.js +12 -103
  20. package/dist/memory/maintenance-state.d.ts +2 -6
  21. package/dist/memory/maintenance-state.js +14 -10
  22. package/dist/memory/maintenance-tuning.d.ts +37 -0
  23. package/dist/memory/maintenance-tuning.js +46 -0
  24. package/dist/memory/promotion.d.ts +0 -22
  25. package/dist/memory/promotion.js +1 -8
  26. package/dist/memory/review-log.d.ts +1 -1
  27. package/dist/memory/scheduler.d.ts +1 -9
  28. package/dist/memory/scheduler.js +3 -15
  29. package/dist/memory/source-window.d.ts +2 -2
  30. package/dist/memory/task-digest.js +2 -5
  31. package/dist/models/utils.d.ts +5 -0
  32. package/dist/models/utils.js +10 -0
  33. package/dist/paths.d.ts +0 -1
  34. package/dist/paths.js +0 -1
  35. package/dist/playbooks/task-closeout.md +2 -0
  36. package/dist/playbooks/task-delegation.md +8 -14
  37. package/dist/playbooks/task-driving.md +3 -4
  38. package/dist/playbooks/task-planning.md +8 -9
  39. package/dist/runtime/bootstrap.d.ts +14 -0
  40. package/dist/runtime/bootstrap.js +9 -4
  41. package/dist/runtime/task-commands.js +46 -73
  42. package/dist/runtime/task-driver.js +6 -23
  43. package/dist/settings.d.ts +39 -40
  44. package/dist/settings.js +87 -107
  45. package/dist/shared/task-ledger.d.ts +19 -2
  46. package/dist/shared/task-ledger.js +194 -5
  47. package/dist/subagents/discovery.d.ts +41 -7
  48. package/dist/subagents/discovery.js +74 -24
  49. package/dist/subagents/tool.d.ts +3 -12
  50. package/dist/subagents/tool.js +11 -115
  51. package/dist/tasks/control.d.ts +57 -27
  52. package/dist/tasks/control.js +94 -93
  53. package/dist/tasks/store.d.ts +1 -4
  54. package/dist/tasks/store.js +1 -39
  55. package/dist/tasks/transitions.d.ts +1 -1
  56. package/dist/tasks/transitions.js +1 -0
  57. package/dist/tasks/verification.d.ts +10 -6
  58. package/dist/tasks/verification.js +0 -6
  59. package/dist/tools/memory-manage.js +46 -24
  60. package/dist/tools/task-manage/create.js +1 -2
  61. package/dist/tools/task-manage/lifecycle.d.ts +7 -0
  62. package/dist/tools/task-manage/lifecycle.js +52 -32
  63. package/dist/tools/task-manage/schema.d.ts +2 -9
  64. package/dist/tools/task-manage/schema.js +9 -19
  65. package/dist/tools/task-manage/shared.d.ts +0 -2
  66. package/dist/tools/task-manage/shared.js +8 -69
  67. package/dist/tools/task-manage/types.d.ts +1 -1
  68. package/dist/tools/task-manage/verification.js +5 -6
  69. package/dist/tools/task-manage.js +4 -2
  70. package/examples/sub-agents/README.md +1 -1
  71. package/package.json +3 -1
  72. package/dist/memory/post-turn-review.d.ts +0 -43
  73. package/dist/memory/post-turn-review.js +0 -136
  74. package/dist/memory/promotion-signals.d.ts +0 -5
  75. package/dist/memory/promotion-signals.js +0 -33
@@ -14,6 +14,12 @@ export const STANDARD_TASK_SECTIONS = [
14
14
  { label: "Current Cycle", names: ["Current Cycle", "当前周期"] },
15
15
  { label: "History", names: ["History", "历史"] },
16
16
  ];
17
+ /** Recurring task files are working context, not an unbounded audit log. */
18
+ export const MAX_INLINE_TASK_HISTORY_ENTRIES = 8;
19
+ export const MAX_INLINE_TASK_HISTORY_CHARS = 24 * 1024;
20
+ const MAX_INLINE_TASK_HISTORY_ENTRY_CHARS = 4 * 1024;
21
+ const HISTORY_OMISSION_NOTE = "- Older cycle details omitted from working context; use session_search with the task id or cycle id to inspect cold history.";
22
+ 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.";
17
23
  /** Validate/normalize a task id (filename without `.md`), rejecting path traversal. */
18
24
  export function normalizeTaskId(id) {
19
25
  const trimmed = id.trim();
@@ -73,6 +79,12 @@ export function parseTaskFrontmatter(content) {
73
79
  frontmatter.controlReadable = false;
74
80
  }
75
81
  else {
82
+ try {
83
+ frontmatter.rawControl = JSON.parse(value);
84
+ }
85
+ catch {
86
+ // Leave rawControl unset; the parse below reports the real problem.
87
+ }
76
88
  try {
77
89
  frontmatter.control = parseTaskControl(value);
78
90
  frontmatter.controlReadable = true;
@@ -198,7 +210,6 @@ export function renderStandardTaskBody(input) {
198
210
  const manual = input.manual?.trim() || DEFAULT_TASK_MANUAL;
199
211
  const verificationPlan = input.verificationPlan?.trim() ||
200
212
  "- Check every DoD item against concrete evidence.\n- Run the relevant deterministic checks before declaring PASS.";
201
- const verificationMode = input.verificationMode ?? "independent";
202
213
  return [
203
214
  `# ${input.title}`,
204
215
  "",
@@ -212,7 +223,9 @@ export function renderStandardTaskBody(input) {
212
223
  manual,
213
224
  "",
214
225
  "## Verification",
215
- `Mode: ${verificationMode}`,
226
+ // Only stated when it constrains closing the task; an unverified task says nothing
227
+ // rather than advertising a second, weaker mode (spec 036, D5).
228
+ ...(input.verificationRequired ? ["Independent verification: required"] : []),
216
229
  verificationPlan,
217
230
  "",
218
231
  "## Current Cycle",
@@ -271,6 +284,7 @@ export function appendCurrentCycleNote(content, note) {
271
284
  continue;
272
285
  sectionStart = index;
273
286
  sectionLevel = match[1]?.length ?? 0;
287
+ break;
274
288
  }
275
289
  if (sectionStart === -1) {
276
290
  throw new Error('Task body has no "Current Cycle" section; normalize the task skeleton first.');
@@ -289,6 +303,165 @@ export function appendCurrentCycleNote(content, note) {
289
303
  lines.splice(insertAt, 0, `- ${trimmedNote}`);
290
304
  return lines.join("\n");
291
305
  }
306
+ /**
307
+ * Upsert the completion evidence subsection inside Current Cycle.
308
+ *
309
+ * Evidence is part of the cycle log, not a new top-level section. This makes the next
310
+ * `startTaskCycle` fold it into the matching History entry and prevents repeated `done`
311
+ * attempts from appending duplicate evidence blocks.
312
+ */
313
+ export function upsertCurrentCycleCompletionEvidence(content, evidenceLines) {
314
+ const lines = content.split("\n");
315
+ let currentStart = -1;
316
+ let currentLevel = 0;
317
+ for (let index = 0; index < lines.length; index++) {
318
+ const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
319
+ if (!match || !matchesTaskSectionTitle(match[2] ?? "", ["Current Cycle", "当前周期"]))
320
+ continue;
321
+ currentStart = index;
322
+ currentLevel = match[1]?.length ?? 0;
323
+ break;
324
+ }
325
+ if (currentStart === -1 || currentLevel >= 6) {
326
+ // Legacy/non-standard one-shot tasks were historically completable without the
327
+ // canonical skeleton. Keep that compatibility, but upsert one bounded top-level
328
+ // block instead of returning to the old append-only behavior.
329
+ const stripped = stripLegacyCompletionEvidence(content).content.replace(/\n+$/, "");
330
+ return `${stripped}\n\n## Completion Evidence\n\n${evidenceLines.join("\n")}\n`;
331
+ }
332
+ let currentEnd = lines.length;
333
+ for (let index = currentStart + 1; index < lines.length; index++) {
334
+ const match = /^(#{1,6})\s+/.exec(lines[index] ?? "");
335
+ if (match && (match[1]?.length ?? 7) <= currentLevel) {
336
+ currentEnd = index;
337
+ break;
338
+ }
339
+ }
340
+ const evidenceLevel = currentLevel + 1;
341
+ let evidenceStart = -1;
342
+ let evidenceEnd = -1;
343
+ for (let index = currentStart + 1; index < currentEnd; index++) {
344
+ const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
345
+ if (!match)
346
+ continue;
347
+ const level = match[1]?.length ?? 7;
348
+ if (level === evidenceLevel && matchesTaskSectionTitle(match[2] ?? "", ["Completion Evidence"])) {
349
+ evidenceStart = index;
350
+ evidenceEnd = currentEnd;
351
+ for (let nested = index + 1; nested < currentEnd; nested++) {
352
+ const nestedHeading = /^(#{1,6})\s+/.exec(lines[nested] ?? "");
353
+ if (nestedHeading && (nestedHeading[1]?.length ?? 7) <= evidenceLevel) {
354
+ evidenceEnd = nested;
355
+ break;
356
+ }
357
+ }
358
+ break;
359
+ }
360
+ }
361
+ if (evidenceStart !== -1) {
362
+ lines.splice(evidenceStart, evidenceEnd - evidenceStart);
363
+ currentEnd -= evidenceEnd - evidenceStart;
364
+ }
365
+ while (currentEnd > currentStart + 1 && (lines[currentEnd - 1] ?? "").trim() === "")
366
+ currentEnd--;
367
+ const block = [`${"#".repeat(evidenceLevel)} Completion Evidence`, "", ...evidenceLines, ""];
368
+ lines.splice(currentEnd, 0, ...block);
369
+ return lines.join("\n");
370
+ }
371
+ function stripLegacyCompletionEvidence(content) {
372
+ const lines = content.split("\n");
373
+ const blocks = [];
374
+ for (let index = 0; index < lines.length;) {
375
+ const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
376
+ if (!heading ||
377
+ (heading[1]?.length ?? 0) !== 2 ||
378
+ !matchesTaskSectionTitle(heading[2] ?? "", ["Completion Evidence"])) {
379
+ index++;
380
+ continue;
381
+ }
382
+ let end = lines.length;
383
+ for (let nested = index + 1; nested < lines.length; nested++) {
384
+ const nextHeading = /^(#{1,6})\s+/.exec(lines[nested] ?? "");
385
+ if (nextHeading && (nextHeading[1]?.length ?? 7) <= 2) {
386
+ end = nested;
387
+ break;
388
+ }
389
+ }
390
+ blocks.push(lines.slice(index, end).join("\n").trim());
391
+ lines.splice(index, end - index);
392
+ while (index > 0 &&
393
+ index < lines.length &&
394
+ (lines[index - 1] ?? "").trim() === "" &&
395
+ (lines[index] ?? "").trim() === "") {
396
+ lines.splice(index, 1);
397
+ }
398
+ }
399
+ return { content: lines.join("\n"), blocks };
400
+ }
401
+ function clipHistoryEntry(entry) {
402
+ if (entry.length <= MAX_INLINE_TASK_HISTORY_ENTRY_CHARS)
403
+ return entry.trim();
404
+ const suffix = `\n${HISTORY_TRUNCATION_NOTE}`;
405
+ const limit = Math.max(0, MAX_INLINE_TASK_HISTORY_ENTRY_CHARS - suffix.length);
406
+ let clipped = entry.slice(0, limit);
407
+ const lastNewline = clipped.lastIndexOf("\n");
408
+ if (lastNewline > 0)
409
+ clipped = clipped.slice(0, lastNewline);
410
+ return `${clipped.trimEnd()}${suffix}`;
411
+ }
412
+ function compactTaskHistory(content, alreadyOmitted = false) {
413
+ const lines = content.split("\n");
414
+ let historyStart = -1;
415
+ let historyLevel = 0;
416
+ for (let index = 0; index < lines.length; index++) {
417
+ const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
418
+ if (heading && matchesTaskSectionTitle(heading[2] ?? "", ["History", "历史"])) {
419
+ historyStart = index;
420
+ historyLevel = heading[1]?.length ?? 0;
421
+ break;
422
+ }
423
+ }
424
+ if (historyStart === -1 || historyLevel >= 6)
425
+ return content;
426
+ let historyEnd = lines.length;
427
+ for (let index = historyStart + 1; index < lines.length; index++) {
428
+ const heading = /^(#{1,6})\s+/.exec(lines[index] ?? "");
429
+ if (heading && (heading[1]?.length ?? 7) <= historyLevel) {
430
+ historyEnd = index;
431
+ break;
432
+ }
433
+ }
434
+ const entryStarts = [];
435
+ for (let index = historyStart + 1; index < historyEnd; index++) {
436
+ const heading = /^(#{1,6})\s+/.exec(lines[index] ?? "");
437
+ if ((heading?.[1]?.length ?? 0) === historyLevel + 1)
438
+ entryStarts.push(index);
439
+ }
440
+ if (entryStarts.length === 0)
441
+ return content;
442
+ const entries = entryStarts.map((start, index) => clipHistoryEntry(lines
443
+ .slice(start, entryStarts[index + 1] ?? historyEnd)
444
+ .join("\n")
445
+ .trim()));
446
+ const kept = [];
447
+ let chars = 0;
448
+ for (const entry of entries) {
449
+ const nextChars = chars + entry.length + (kept.length > 0 ? 2 : 0);
450
+ if (kept.length >= MAX_INLINE_TASK_HISTORY_ENTRIES || nextChars > MAX_INLINE_TASK_HISTORY_CHARS)
451
+ break;
452
+ kept.push(entry);
453
+ chars = nextChars;
454
+ }
455
+ const omitted = alreadyOmitted || kept.length < entries.length;
456
+ const replacement = [
457
+ "",
458
+ ...kept.flatMap((entry, index) => (index === kept.length - 1 ? [entry] : [entry, ""])),
459
+ ...(omitted ? ["", HISTORY_OMISSION_NOTE] : []),
460
+ "",
461
+ ];
462
+ lines.splice(historyStart + 1, historyEnd - historyStart - 1, ...replacement);
463
+ return lines.join("\n");
464
+ }
292
465
  /**
293
466
  * Close the visible current-cycle notes into History and open a fresh cycle.
294
467
  * Periodic task cycles deliberately use this small, deterministic transformation
@@ -299,7 +472,8 @@ export function startTaskCycle(content, cycleId) {
299
472
  const normalizedCycleId = cycleId.trim();
300
473
  if (!normalizedCycleId)
301
474
  throw new Error("Cycle id must not be empty.");
302
- const lines = content.split("\n");
475
+ const legacy = stripLegacyCompletionEvidence(content);
476
+ const lines = legacy.content.split("\n");
303
477
  let currentStart = -1;
304
478
  let currentLevel = 0;
305
479
  let historyStart = -1;
@@ -328,10 +502,24 @@ export function startTaskCycle(content, cycleId) {
328
502
  break;
329
503
  }
330
504
  }
331
- const previous = lines
505
+ let previous = lines
332
506
  .slice(currentStart + 1, currentEnd)
333
507
  .join("\n")
334
508
  .trim();
509
+ const latestLegacyEvidence = legacy.blocks.at(-1);
510
+ if (latestLegacyEvidence && !/^(#{1,6})\s+Completion Evidence\b/im.test(previous)) {
511
+ previous = `${previous}\n\n${latestLegacyEvidence.replace(/^##\s+/, "### ")}`.trim();
512
+ }
513
+ // The archived cycle gets its own H3 entry under History. Demote subsections that
514
+ // were nested under the H2 Current Cycle so they remain children of that entry.
515
+ previous = previous
516
+ .split("\n")
517
+ .map((line) => {
518
+ const heading = /^(#{1,6})(\s+.*)$/.exec(line);
519
+ const level = heading?.[1]?.length ?? 0;
520
+ return heading && level > currentLevel && level < 6 ? `#${line}` : line;
521
+ })
522
+ .join("\n");
335
523
  const previousHeading = (lines[currentStart] ?? "## Current Cycle").replace(/^#+\s*/, "").trim();
336
524
  const replacement = [
337
525
  `${"#".repeat(currentLevel)} Current Cycle (${normalizedCycleId})`,
@@ -347,7 +535,8 @@ export function startTaskCycle(content, cycleId) {
347
535
  // A nested history heading would be unusual; inserting directly after the
348
536
  // canonical History heading remains predictable and preserves all older notes.
349
537
  lines.splice(shiftedHistoryStart + 1, 0, ...historyEntry);
350
- return resetTaskAcceptanceCheckboxes(lines.join("\n"));
538
+ const compacted = compactTaskHistory(lines.join("\n"), legacy.blocks.length > 1);
539
+ return resetTaskAcceptanceCheckboxes(compacted);
351
540
  }
352
541
  /**
353
542
  * Uncheck every "- [x]" under DoD/Verification.
@@ -1,5 +1,5 @@
1
1
  import type { Api, Model } from "@earendil-works/pi-ai";
2
- declare const ALLOWED_SUB_AGENT_TOOLS: readonly ["read", "bash", "edit", "write", "web_search", "web_fetch"];
2
+ declare const ALLOWED_SUB_AGENT_TOOLS: readonly ["read", "grep", "bash", "edit", "write", "web_search", "web_fetch"];
3
3
  declare const ALLOWED_CONTEXT_MODES: readonly ["isolated", "contextual"];
4
4
  declare const ALLOWED_MEMORY_MODES: readonly ["none", "session", "relevant"];
5
5
  declare const ALLOWED_THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh"];
@@ -7,6 +7,42 @@ export type SubAgentToolName = (typeof ALLOWED_SUB_AGENT_TOOLS)[number];
7
7
  export type SubAgentContextMode = (typeof ALLOWED_CONTEXT_MODES)[number];
8
8
  export type SubAgentMemoryMode = (typeof ALLOWED_MEMORY_MODES)[number];
9
9
  export type SubAgentThinkingLevel = (typeof ALLOWED_THINKING_LEVELS)[number];
10
+ /**
11
+ * Execution budgets as a single named tuple. Frontmatter keeps the four numeric knobs
12
+ * (a human editing a config file has grounds to pick numbers); the invocation surface
13
+ * only offers these presets, because a model choosing `maxToolCalls` per delegation is
14
+ * guessing. `standard` is byte-identical to the DEFAULT_* values, so omitting `effort`
15
+ * leaves behavior unchanged.
16
+ */
17
+ export declare const SUB_AGENT_EFFORT_PRESETS: {
18
+ readonly quick: {
19
+ readonly maxTurns: 8;
20
+ readonly maxToolCalls: 16;
21
+ readonly maxWallTimeSec: 120;
22
+ readonly bashTimeoutSec: 60;
23
+ };
24
+ readonly standard: {
25
+ readonly maxTurns: 24;
26
+ readonly maxToolCalls: 48;
27
+ readonly maxWallTimeSec: 300;
28
+ readonly bashTimeoutSec: 120;
29
+ };
30
+ readonly deep: {
31
+ readonly maxTurns: 48;
32
+ readonly maxToolCalls: 96;
33
+ readonly maxWallTimeSec: 900;
34
+ readonly bashTimeoutSec: 180;
35
+ };
36
+ };
37
+ export type SubAgentEffort = keyof typeof SUB_AGENT_EFFORT_PRESETS;
38
+ /**
39
+ * The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
40
+ * encode only four meaningful states (`isolated` implies `memory: none`), so the calling
41
+ * surface collapses them into one enum. The dropped state — contextual with `memory: none`,
42
+ * i.e. paths-only injection — remains expressible in frontmatter.
43
+ */
44
+ declare const ALLOWED_CONTEXT_CHOICES: readonly ["none", "session", "relevant"];
45
+ export type SubAgentContextChoice = (typeof ALLOWED_CONTEXT_CHOICES)[number];
10
46
  export interface SubAgentConfig {
11
47
  name: string;
12
48
  description: string;
@@ -42,12 +78,10 @@ export interface SubAgentInvocationOverrides {
42
78
  systemPrompt?: string;
43
79
  tools?: string[];
44
80
  model?: string;
45
- maxTurns?: number;
46
- maxToolCalls?: number;
47
- maxWallTimeSec?: number;
48
- bashTimeoutSec?: number;
49
- contextMode?: string;
50
- memory?: string;
81
+ /** Named budget preset; wins over frontmatter numbers as a whole tuple, never field by field. */
82
+ effort?: string;
83
+ /** Collapsed `contextMode` + `memory`; see SubAgentContextChoice. */
84
+ context?: string;
51
85
  paths?: string[];
52
86
  thinkingLevel?: string;
53
87
  /** Drives the thinkingLevel default: "verify" defaults on, everything else stays off. */
@@ -4,7 +4,7 @@ import { join } from "path";
4
4
  import { findExactModelReferenceMatch, formatModelReference } from "../models/utils.js";
5
5
  import { SUB_AGENTS_DIR_NAME } from "../paths.js";
6
6
  import { errorMessage } from "../shared/text-utils.js";
7
- const ALLOWED_SUB_AGENT_TOOLS = ["read", "bash", "edit", "write", "web_search", "web_fetch"];
7
+ const ALLOWED_SUB_AGENT_TOOLS = ["read", "grep", "bash", "edit", "write", "web_search", "web_fetch"];
8
8
  const DEFAULT_SUB_AGENT_TOOLS = ["read", "bash"];
9
9
  const DEFAULT_MAX_TURNS = 24;
10
10
  const DEFAULT_MAX_TOOL_CALLS = 48;
@@ -15,6 +15,31 @@ const MAX_SUB_AGENT_SYSTEM_PROMPT_CHARS = 16000;
15
15
  const ALLOWED_CONTEXT_MODES = ["isolated", "contextual"];
16
16
  const ALLOWED_MEMORY_MODES = ["none", "session", "relevant"];
17
17
  const ALLOWED_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"];
18
+ /**
19
+ * Execution budgets as a single named tuple. Frontmatter keeps the four numeric knobs
20
+ * (a human editing a config file has grounds to pick numbers); the invocation surface
21
+ * only offers these presets, because a model choosing `maxToolCalls` per delegation is
22
+ * guessing. `standard` is byte-identical to the DEFAULT_* values, so omitting `effort`
23
+ * leaves behavior unchanged.
24
+ */
25
+ export const SUB_AGENT_EFFORT_PRESETS = {
26
+ quick: { maxTurns: 8, maxToolCalls: 16, maxWallTimeSec: 120, bashTimeoutSec: 60 },
27
+ standard: {
28
+ maxTurns: DEFAULT_MAX_TURNS,
29
+ maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
30
+ maxWallTimeSec: DEFAULT_MAX_WALL_TIME_SEC,
31
+ bashTimeoutSec: DEFAULT_BASH_TIMEOUT_SEC,
32
+ },
33
+ deep: { maxTurns: 48, maxToolCalls: 96, maxWallTimeSec: 900, bashTimeoutSec: 180 },
34
+ };
35
+ const ALLOWED_EFFORTS = Object.keys(SUB_AGENT_EFFORT_PRESETS);
36
+ /**
37
+ * The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
38
+ * encode only four meaningful states (`isolated` implies `memory: none`), so the calling
39
+ * surface collapses them into one enum. The dropped state — contextual with `memory: none`,
40
+ * i.e. paths-only injection — remains expressible in frontmatter.
41
+ */
42
+ const ALLOWED_CONTEXT_CHOICES = ["none", "session", "relevant"];
18
43
  /** verify is the last unattended gate before an attestation is trusted; give it real reasoning by default. */
19
44
  const DEFAULT_VERIFY_THINKING_LEVEL = "medium";
20
45
  const DEFAULT_WORK_THINKING_LEVEL = "off";
@@ -114,6 +139,31 @@ function parseThinkingLevel(raw) {
114
139
  error: `Unknown thinkingLevel "${normalized}". Allowed values: ${ALLOWED_THINKING_LEVELS.join(", ")}`,
115
140
  };
116
141
  }
142
+ function parseEffort(raw) {
143
+ const normalized = readOptionalTrimmedString(raw);
144
+ if (!normalized) {
145
+ return {};
146
+ }
147
+ if (ALLOWED_EFFORTS.includes(normalized)) {
148
+ return { value: normalized };
149
+ }
150
+ return { error: `Unknown effort "${normalized}". Allowed values: ${ALLOWED_EFFORTS.join(", ")}` };
151
+ }
152
+ function parseContextChoice(raw) {
153
+ const normalized = readOptionalTrimmedString(raw);
154
+ if (!normalized) {
155
+ return {};
156
+ }
157
+ if (!ALLOWED_CONTEXT_CHOICES.includes(normalized)) {
158
+ return {
159
+ error: `Unknown context "${normalized}". Allowed values: ${ALLOWED_CONTEXT_CHOICES.join(", ")}`,
160
+ };
161
+ }
162
+ if (normalized === "none") {
163
+ return { value: { contextMode: "isolated", memory: "none" } };
164
+ }
165
+ return { value: { contextMode: "contextual", memory: normalized } };
166
+ }
117
167
  function parseMemoryMode(raw, contextMode) {
118
168
  const normalized = readOptionalTrimmedString(raw);
119
169
  if (!normalized) {
@@ -171,12 +221,6 @@ function parsePositiveInteger(raw, fallback) {
171
221
  }
172
222
  return { value: parsed };
173
223
  }
174
- function resolvePositiveOverride(value, fallback) {
175
- if (!Number.isFinite(value) || value === undefined || value <= 0) {
176
- return fallback;
177
- }
178
- return Math.floor(value);
179
- }
180
224
  function resolveModelReference(modelRef, availableModels) {
181
225
  const { match, ambiguous } = findExactModelReferenceMatch(modelRef, availableModels);
182
226
  if (match) {
@@ -346,20 +390,26 @@ subagentDefaultModelRef) {
346
390
  model = resolved.model;
347
391
  modelRef = formatModelReference(resolved.model);
348
392
  }
349
- const maxTurns = resolvePositiveOverride(overrides.maxTurns, baseConfig?.maxTurns ?? DEFAULT_MAX_TURNS);
350
- const maxToolCalls = resolvePositiveOverride(overrides.maxToolCalls, baseConfig?.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS);
351
- const maxWallTimeSec = resolvePositiveOverride(overrides.maxWallTimeSec, baseConfig?.maxWallTimeSec ?? DEFAULT_MAX_WALL_TIME_SEC);
352
- const bashTimeoutSec = resolvePositiveOverride(overrides.bashTimeoutSec, baseConfig?.bashTimeoutSec ?? DEFAULT_BASH_TIMEOUT_SEC);
353
- const contextModeOverride = overrides.contextMode ? parseContextMode(overrides.contextMode) : undefined;
354
- if (contextModeOverride?.error) {
355
- return { error: contextModeOverride.error };
356
- }
357
- const contextMode = contextModeOverride?.value ?? baseConfig?.contextMode ?? "isolated";
358
- const memoryOverride = overrides.memory ? parseMemoryMode(overrides.memory, contextMode) : undefined;
359
- if (memoryOverride?.error) {
360
- return { error: memoryOverride.error };
393
+ const effortOverride = parseEffort(overrides.effort);
394
+ if (effortOverride.error) {
395
+ return { error: effortOverride.error };
396
+ }
397
+ // An explicit `effort` replaces the whole budget tuple rather than merging field by
398
+ // field, so a preset never produces a combination no preset describes.
399
+ const budget = effortOverride.value
400
+ ? SUB_AGENT_EFFORT_PRESETS[effortOverride.value]
401
+ : {
402
+ maxTurns: baseConfig?.maxTurns ?? DEFAULT_MAX_TURNS,
403
+ maxToolCalls: baseConfig?.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS,
404
+ maxWallTimeSec: baseConfig?.maxWallTimeSec ?? DEFAULT_MAX_WALL_TIME_SEC,
405
+ bashTimeoutSec: baseConfig?.bashTimeoutSec ?? DEFAULT_BASH_TIMEOUT_SEC,
406
+ };
407
+ const contextOverride = parseContextChoice(overrides.context);
408
+ if (contextOverride.error) {
409
+ return { error: contextOverride.error };
361
410
  }
362
- const memory = memoryOverride?.value ?? baseConfig?.memory ?? (contextMode === "contextual" ? "relevant" : "none");
411
+ const contextMode = contextOverride.value?.contextMode ?? baseConfig?.contextMode ?? "isolated";
412
+ const memory = contextOverride.value?.memory ?? baseConfig?.memory ?? (contextMode === "contextual" ? "relevant" : "none");
363
413
  const pathsOverride = overrides.paths ? parseStringList(overrides.paths, "paths") : undefined;
364
414
  if (pathsOverride?.error) {
365
415
  return { error: pathsOverride.error };
@@ -391,10 +441,10 @@ subagentDefaultModelRef) {
391
441
  tools: tools.tools,
392
442
  model: model ?? currentModel,
393
443
  modelRef: modelRef ?? formatModelReference(model ?? currentModel),
394
- maxTurns,
395
- maxToolCalls,
396
- maxWallTimeSec,
397
- bashTimeoutSec,
444
+ maxTurns: budget.maxTurns,
445
+ maxToolCalls: budget.maxToolCalls,
446
+ maxWallTimeSec: budget.maxWallTimeSec,
447
+ bashTimeoutSec: budget.bashTimeoutSec,
398
448
  contextMode,
399
449
  memory,
400
450
  paths,
@@ -16,17 +16,11 @@ declare const subagentSchema: Type.TObject<{
16
16
  systemPrompt: Type.TOptional<Type.TString>;
17
17
  tools: Type.TOptional<Type.TArray<Type.TString>>;
18
18
  model: Type.TOptional<Type.TString>;
19
- maxTurns: Type.TOptional<Type.TNumber>;
20
- maxToolCalls: Type.TOptional<Type.TNumber>;
21
- maxWallTimeSec: Type.TOptional<Type.TNumber>;
22
- bashTimeoutSec: Type.TOptional<Type.TNumber>;
23
- contextMode: Type.TOptional<Type.TUnion<[Type.TLiteral<"isolated">, Type.TLiteral<"contextual">]>>;
24
- memory: Type.TOptional<Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"session">, Type.TLiteral<"relevant">]>>;
19
+ effort: Type.TOptional<Type.TUnion<[Type.TLiteral<"quick">, Type.TLiteral<"standard">, Type.TLiteral<"deep">]>>;
20
+ context: Type.TOptional<Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"session">, Type.TLiteral<"relevant">]>>;
25
21
  paths: Type.TOptional<Type.TArray<Type.TString>>;
26
22
  purpose: Type.TOptional<Type.TUnion<[Type.TLiteral<"work">, Type.TLiteral<"verify">]>>;
27
23
  taskId: Type.TOptional<Type.TString>;
28
- isolation: Type.TOptional<Type.TUnion<[Type.TLiteral<"shared">, Type.TLiteral<"worktree">]>>;
29
- worktreePath: Type.TOptional<Type.TString>;
30
24
  returns: Type.TOptional<Type.TUnion<[Type.TLiteral<"text">, Type.TLiteral<"artifact">]>>;
31
25
  thinkingLevel: Type.TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">]>>;
32
26
  }>;
@@ -45,9 +39,6 @@ export interface SubAgentToolDetails {
45
39
  runId: string;
46
40
  purpose: "work" | "verify";
47
41
  taskId?: string;
48
- isolation: "shared" | "worktree";
49
- worktreePath?: string;
50
- worktreeBranch?: string;
51
42
  verificationVerdict?: "pass" | "fail";
52
43
  /** Always populated (spec 032 D4): the full output is saved to `${artifactDir}/output.md` regardless of `returns`. */
53
44
  artifactDir: string;
@@ -58,7 +49,7 @@ export interface SubAgentToolDetails {
58
49
  }
59
50
  export interface SubAgentToolOptions {
60
51
  executor: Executor;
61
- /** Host checkout used as the shared cwd and worktree source. Defaults to process.cwd(). */
52
+ /** Host checkout used as the sub-agent's cwd. Defaults to process.cwd(). */
62
53
  workingDirectory?: string;
63
54
  getCurrentModel: () => Model<Api>;
64
55
  getAvailableModels: () => Model<Api>[];