@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
@@ -43,17 +43,6 @@ export const SUB_AGENT_EFFORT_PRESETS = {
43
43
  },
44
44
  deep: { maxTurns: 48, maxToolCalls: 96, maxWallTimeSec: 900, bashTimeoutSec: 180 },
45
45
  };
46
- /**
47
- * External runs have no turn/tool-call budget (D5) — `effort` only ever moves wall time, and at
48
- * external scale, not the internal tuple above (P1-3: those numbers previously leaked onto
49
- * external roles unchanged, where `deep` at 900s was *shorter* than the external default).
50
- * `standard` and an unset `effort` both keep the role's own `maxWallTimeSec` (or the external
51
- * default), so this only has entries for the two presets that actually override it.
52
- */
53
- export const SUB_AGENT_EXTERNAL_EFFORT_WALL_TIME_SEC = {
54
- quick: 600,
55
- deep: 5400,
56
- };
57
46
  const ALLOWED_EFFORTS = Object.keys(SUB_AGENT_EFFORT_PRESETS);
58
47
  /**
59
48
  * The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
@@ -640,59 +629,85 @@ export function discoverSubAgents(workspaceDir, availableModels) {
640
629
  const result = loadAgentsFromDir(directory, availableModels);
641
630
  return { directory, agents: result.agents, warnings: result.warnings };
642
631
  }
643
- export function resolveSubAgentConfig(availableModels, currentModel, predefinedAgents, overrides,
644
632
  /**
645
- * `settings.subagentModel` (spec 032 D5): used only when neither the invocation nor the
646
- * predefined agent's frontmatter names a model. Unset/blank is "not configured" — the
647
- * caller (tool.ts) already normalizes that, this function just treats undefined as absent.
633
+ * Resolve a `subagent` (role-based) invocation (spec 046, D2.1).
634
+ *
635
+ * Everything the old combined resolver used to override for a configured role — `tools`,
636
+ * `model`, `effort`, `context`, `mutates` — now has nowhere to come from but the role file
637
+ * itself, so this is a lookup plus the two facts a role file cannot pin down: the default model
638
+ * (parent's current model, or `settings.subagentModel`) and the purpose-driven thinkingLevel
639
+ * default. Spec 042 D3's three "external + override" rejections no longer apply: `ConfiguredRoleOverrides`
640
+ * has no `tools`/`model`/`mutates` field to reject in the first place.
641
+ */
642
+ export function resolveConfiguredRole(availableModels, currentModel, predefinedAgents, overrides,
643
+ /**
644
+ * `settings.subagentModel` (spec 032 D5): used only when neither the role file's frontmatter
645
+ * nor this call names a model (it cannot — there is no override field for it).
648
646
  */
649
647
  subagentDefaultModelRef) {
650
- const baseConfig = overrides.agent ? predefinedAgents.find((agent) => agent.name === overrides.agent) : undefined;
651
- if (overrides.agent && !baseConfig) {
648
+ const baseConfig = predefinedAgents.find((agent) => agent.name === overrides.agent);
649
+ if (!baseConfig) {
652
650
  const available = predefinedAgents.length > 0 ? predefinedAgents.map((agent) => agent.name).join(", ") : "none";
653
651
  return { error: `Unknown sub-agent "${overrides.agent}". Available sub-agents: ${available}.` };
654
652
  }
655
653
  // Listed, never dropped (spec 040, D5) — but refused here with the reason, not a fallback.
656
- if (baseConfig?.unavailable) {
654
+ if (baseConfig.unavailable) {
657
655
  return { error: `Sub-agent "${baseConfig.name}" is currently unavailable: ${baseConfig.unavailable}` };
658
656
  }
659
- if (!baseConfig && (!overrides.systemPrompt || !overrides.systemPrompt.trim())) {
660
- return { error: 'Provide either "agent" or "systemPrompt" to define the sub-agent.' };
661
- }
662
- const effectiveRuntime = baseConfig?.runtime ?? "internal";
663
- // Spec 042 D3: the invocation-side counterpart to the role-file field matrix (`ROLE_FIELD_MATRIX`
664
- // above) — a field only meaningful for one runtime is rejected outright when the resolved role
665
- // is the other, not silently ignored. `tools` and `model` were previously accepted and either
666
- // dropped on the floor or — for `model` — resolved against `models.json` and made to fail a
667
- // dispatch for a reason that has nothing to do with the external role actually named.
668
- if (effectiveRuntime === "external" && overrides.tools !== undefined) {
669
- return {
670
- error: `Sub-agent "${baseConfig?.name}" is external; its tool boundary comes from its own ` +
671
- 'command (e.g. "--sandbox read-only"), not the "tools" invocation parameter, which has no effect on external roles.',
672
- };
657
+ let model = baseConfig.model;
658
+ let modelRef = baseConfig.modelRef;
659
+ if (!model && subagentDefaultModelRef) {
660
+ const resolved = resolveModelReference(subagentDefaultModelRef, availableModels);
661
+ if (!resolved.model) {
662
+ return { error: resolved.error };
663
+ }
664
+ model = resolved.model;
665
+ modelRef = formatModelReference(resolved.model);
673
666
  }
674
- if (effectiveRuntime === "external" && overrides.model?.trim()) {
675
- return {
676
- error: `Sub-agent "${baseConfig?.name}" is external; its model can only be set in the role file's ` +
677
- '"model" frontmatter. The "model" invocation parameter has no effect on external roles and is never resolved against models.json.',
678
- };
667
+ const purpose = overrides.purpose === "verify" ? "verify" : "work";
668
+ // External work is not defaulted: pipiclaw has no standing to pick a reasoning effort for
669
+ // another CLI's own configuration. External verify still defaults — it is the last unattended
670
+ // gate before an attestation is trusted, and "whatever that machine happens to have configured"
671
+ // is not an acceptable substitute for real reasoning.
672
+ const thinkingLevel = baseConfig.thinkingLevel ??
673
+ (baseConfig.runtime === "external" && purpose !== "verify" ? undefined : DEFAULT_THINKING_LEVEL);
674
+ const mutates = baseConfig.mutates ?? inferMutatesFromTools(baseConfig.tools);
675
+ return {
676
+ config: {
677
+ ...baseConfig,
678
+ model: model ?? currentModel,
679
+ modelRef: modelRef ?? formatModelReference(model ?? currentModel),
680
+ thinkingLevel,
681
+ source: "predefined",
682
+ mutates,
683
+ },
684
+ };
685
+ }
686
+ /**
687
+ * Resolve a `subagent_inline` invocation (spec 046, D2.1) — a one-off executor with no role
688
+ * file. `runtime` is always `"internal"` here: only a configured role file can name `external`,
689
+ * and `InlineAgentOverrides` has no field for it, so the old function's external branches
690
+ * (budget table, unset-by-default thinkingLevel, model/tools/mutates rejections) simply do not
691
+ * apply to this path and are not reproduced here.
692
+ */
693
+ export function resolveInlineAgent(availableModels, currentModel, overrides,
694
+ /** `settings.subagentModel` (spec 032 D5): used only when this call does not name a model. */
695
+ subagentDefaultModelRef) {
696
+ const systemPrompt = overrides.systemPrompt.trim();
697
+ if (!systemPrompt) {
698
+ return { error: "Sub-agent system prompt cannot be empty." };
679
699
  }
680
- // External `mutates` is the role file's own self-declaration (checked against its harness/command),
681
- // same reasoning as `model` above — the caller cannot override what the external role attests about itself.
682
- if (effectiveRuntime === "external" && overrides.mutates !== undefined) {
683
- return {
684
- error: `Sub-agent "${baseConfig?.name}" is external; "mutates" comes from its role file, not the invocation parameter.`,
685
- };
700
+ const promptLengthError = validateSubAgentSystemPrompt(systemPrompt, "Inline sub-agent systemPrompt");
701
+ if (promptLengthError) {
702
+ return { error: promptLengthError };
686
703
  }
687
- const tools = overrides.tools
688
- ? validateToolNames(overrides.tools)
689
- : { tools: baseConfig?.tools ?? [...DEFAULT_SUB_AGENT_TOOLS] };
704
+ const tools = overrides.tools ? validateToolNames(overrides.tools) : { tools: [...DEFAULT_SUB_AGENT_TOOLS] };
690
705
  if (tools.error) {
691
706
  return { error: tools.error };
692
707
  }
693
- let model = baseConfig?.model;
694
- let modelRef = baseConfig?.modelRef;
695
- if (effectiveRuntime !== "external" && overrides.model?.trim()) {
708
+ let model;
709
+ let modelRef;
710
+ if (overrides.model?.trim()) {
696
711
  const resolved = resolveModelReference(overrides.model.trim(), availableModels);
697
712
  if (!resolved.model) {
698
713
  return { error: resolved.error };
@@ -700,7 +715,7 @@ subagentDefaultModelRef) {
700
715
  model = resolved.model;
701
716
  modelRef = formatModelReference(resolved.model);
702
717
  }
703
- else if (!model && subagentDefaultModelRef) {
718
+ else if (subagentDefaultModelRef) {
704
719
  const resolved = resolveModelReference(subagentDefaultModelRef, availableModels);
705
720
  if (!resolved.model) {
706
721
  return { error: resolved.error };
@@ -712,76 +727,40 @@ subagentDefaultModelRef) {
712
727
  if (effortOverride.error) {
713
728
  return { error: effortOverride.error };
714
729
  }
715
- // An explicit `effort` replaces the whole budget tuple rather than merging field by
716
- // field, so a preset never produces a combination no preset describes. External is a
717
- // separate branch (P1-3): it has no turn/tool-call budget, and effort's wall-time numbers
718
- // are at external scale, not the internal tuple.
719
- const budget = effectiveRuntime === "external"
720
- ? {
730
+ const budget = effortOverride.value
731
+ ? SUB_AGENT_EFFORT_PRESETS[effortOverride.value]
732
+ : {
721
733
  maxTurns: DEFAULT_MAX_TURNS,
722
734
  maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
723
- maxWallTimeSec: (effortOverride.value && SUB_AGENT_EXTERNAL_EFFORT_WALL_TIME_SEC[effortOverride.value]) ??
724
- baseConfig?.maxWallTimeSec ??
725
- DEFAULT_EXTERNAL_MAX_WALL_TIME_SEC,
735
+ maxWallTimeSec: DEFAULT_MAX_WALL_TIME_SEC,
726
736
  bashTimeoutSec: DEFAULT_BASH_TIMEOUT_SEC,
727
- }
728
- : effortOverride.value
729
- ? SUB_AGENT_EFFORT_PRESETS[effortOverride.value]
730
- : {
731
- maxTurns: baseConfig?.maxTurns ?? DEFAULT_MAX_TURNS,
732
- maxToolCalls: baseConfig?.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS,
733
- maxWallTimeSec: baseConfig?.maxWallTimeSec ?? DEFAULT_MAX_WALL_TIME_SEC,
734
- bashTimeoutSec: baseConfig?.bashTimeoutSec ?? DEFAULT_BASH_TIMEOUT_SEC,
735
- };
737
+ };
736
738
  const contextOverride = parseContextChoice(overrides.context);
737
739
  if (contextOverride.error) {
738
740
  return { error: contextOverride.error };
739
741
  }
740
- const contextMode = contextOverride.value?.contextMode ?? baseConfig?.contextMode ?? "isolated";
741
- const memory = contextOverride.value?.memory ?? baseConfig?.memory ?? (contextMode === "contextual" ? "relevant" : "none");
742
- const pathsOverride = overrides.paths ? parseStringList(overrides.paths, "paths") : undefined;
743
- if (pathsOverride?.error) {
744
- return { error: pathsOverride.error };
745
- }
746
- const paths = pathsOverride?.values ?? baseConfig?.paths ?? [];
742
+ const contextMode = contextOverride.value?.contextMode ?? "isolated";
743
+ const memory = contextOverride.value?.memory ?? (contextMode === "contextual" ? "relevant" : "none");
747
744
  const thinkingLevelOverride = overrides.thinkingLevel ? parseThinkingLevel(overrides.thinkingLevel) : undefined;
748
745
  if (thinkingLevelOverride?.error) {
749
746
  return { error: thinkingLevelOverride.error };
750
747
  }
751
- const purpose = overrides.purpose === "verify" ? "verify" : "work";
752
- const explicitThinkingLevel = thinkingLevelOverride?.value ?? baseConfig?.thinkingLevel;
753
- // External work is not defaulted: pipiclaw has no standing to pick a reasoning effort for
754
- // another CLI's own configuration. External verify still defaults — it is the last unattended
755
- // gate before an attestation is trusted, and "whatever that machine happens to have configured"
756
- // is not an acceptable substitute for real reasoning.
757
- const thinkingLevel = explicitThinkingLevel ??
758
- (effectiveRuntime === "external" && purpose !== "verify" ? undefined : DEFAULT_THINKING_LEVEL);
748
+ const thinkingLevel = thinkingLevelOverride?.value ?? DEFAULT_THINKING_LEVEL;
759
749
  const mutatesOverride = parseMutates(overrides.mutates);
760
750
  if (mutatesOverride.error) {
761
751
  return { error: mutatesOverride.error };
762
752
  }
763
- const mutates = mutatesOverride.value ?? baseConfig?.mutates ?? inferMutatesFromTools(tools.tools);
764
- // Same rationale as the predefined-role bashWithoutMutatesWarning above (D6): `bash` can write
765
- // regardless of what `tools` otherwise implies. Inline roles have no frontmatter to declare it
766
- // in, so the warning goes back to the model in the result text instead of a discovery-time log.
767
- const bashWithoutMutatesWarning = !baseConfig && tools.tools.includes("bash") && mutatesOverride.value === undefined
753
+ const mutates = mutatesOverride.value ?? inferMutatesFromTools(tools.tools);
754
+ // Inline roles have no frontmatter to declare `mutates` in, so this warning goes back to the
755
+ // model in the result text instead of a discovery-time log (D6 in the pre-split resolver).
756
+ const bashWithoutMutatesWarning = tools.tools.includes("bash") && mutatesOverride.value === undefined
768
757
  ? 'tools include bash but "mutates" is not declared; if this task writes to the workspace, pass mutates: "write" so it takes the exclusive workspace write lease'
769
758
  : undefined;
770
- const systemPrompt = overrides.systemPrompt?.trim() || baseConfig?.systemPrompt || "";
771
- if (!systemPrompt) {
772
- return { error: "Sub-agent system prompt cannot be empty." };
773
- }
774
- if (overrides.systemPrompt?.trim()) {
775
- const promptLengthError = validateSubAgentSystemPrompt(overrides.systemPrompt.trim(), "Inline sub-agent systemPrompt");
776
- if (promptLengthError) {
777
- return { error: promptLengthError };
778
- }
779
- }
780
759
  return {
781
760
  warning: bashWithoutMutatesWarning,
782
761
  config: {
783
- name: overrides.name?.trim() || baseConfig?.name || "dynamic-subagent",
784
- description: baseConfig?.description || "Inline sub-agent",
762
+ name: "dynamic-subagent",
763
+ description: "Inline sub-agent",
785
764
  systemPrompt,
786
765
  tools: tools.tools,
787
766
  model: model ?? currentModel,
@@ -792,19 +771,11 @@ subagentDefaultModelRef) {
792
771
  bashTimeoutSec: budget.bashTimeoutSec,
793
772
  contextMode,
794
773
  memory,
795
- paths,
774
+ paths: [],
796
775
  thinkingLevel,
797
- filePath: baseConfig?.filePath,
798
- source: baseConfig ? "predefined" : "inline",
799
- runtime: baseConfig?.runtime ?? "internal",
800
- harness: baseConfig?.harness,
801
- command: baseConfig?.command,
802
- shell: baseConfig?.shell,
803
- env: baseConfig?.env,
804
- workload: baseConfig?.workload,
776
+ source: "inline",
777
+ runtime: "internal",
805
778
  mutates,
806
- externalModelRef: baseConfig?.externalModelRef,
807
- unavailable: baseConfig?.unavailable,
808
779
  },
809
780
  };
810
781
  }
@@ -1,4 +1,5 @@
1
1
  import { randomUUID } from "node:crypto";
2
+ import { isRecord } from "../../shared/type-guards.js";
2
3
  import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, } from "./harness.js";
3
4
  /**
4
5
  * `claude-code` harness (spec 040, D3/D4). Same one-prompt-one-process model as codex-cli; the
@@ -29,9 +30,6 @@ function toClaudeEffort(level) {
29
30
  return undefined;
30
31
  return THINKING_LEVEL_TO_CLAUDE_EFFORT[level] ?? level;
31
32
  }
32
- function isRecord(value) {
33
- return typeof value === "object" && value !== null;
34
- }
35
33
  export const claudeCodeHarness = {
36
34
  id: "claude-code",
37
35
  // 2: parseOutcome now falls back to the last streamed `assistant` message's text/usage when a
@@ -18,7 +18,7 @@ export interface ExternalInvocationInput {
18
18
  /** Path to the role's system-prompt file (`<artifactDir>/system-prompt.txt`), for harnesses
19
19
  * that reference it by flag (e.g. claude-code's `--append-system-prompt-file`). */
20
20
  systemPromptFile: string;
21
- /** Set when this invocation continues an earlier run (`subagent_manage op=follow_up`, D6). */
21
+ /** Set when this invocation continues an earlier run (`subagent_run op=follow_up`, D6). */
22
22
  resumeSessionId?: string;
23
23
  }
24
24
  export interface BuildInvocationResult {
@@ -1,11 +1,12 @@
1
+ import { formatDuration } from "../shared/duration.js";
1
2
  import type { RunRecord } from "./runs.js";
2
3
  /**
3
4
  * Shared display primitives for delegation runs (spec 041), used by both the model-facing
4
- * `subagent_manage` tool and the human-facing `/subagents` runtime command. Only the pieces that
5
+ * `subagent_list`/`subagent_run` tools and the human-facing `/subagents` runtime command. Only the pieces that
5
6
  * are genuinely language/audience-neutral live here — duration math, the harness label, and the
6
7
  * cost guard — not full line templates, since the two surfaces render in different languages.
7
8
  */
8
- export declare function formatDuration(ms: number): string;
9
+ export { formatDuration };
9
10
  export declare function elapsedMs(record: RunRecord, now?: number): number;
10
11
  /** Spec 042 D1: a restart-reconciled run's duration is an estimate (from the artifact file's mtime
11
12
  * or a wall-clock fallback), not a measured process lifetime — prefix it so a reader does not
@@ -1,15 +1,11 @@
1
+ import { formatDuration } from "../shared/duration.js";
1
2
  /**
2
3
  * Shared display primitives for delegation runs (spec 041), used by both the model-facing
3
- * `subagent_manage` tool and the human-facing `/subagents` runtime command. Only the pieces that
4
+ * `subagent_list`/`subagent_run` tools and the human-facing `/subagents` runtime command. Only the pieces that
4
5
  * are genuinely language/audience-neutral live here — duration math, the harness label, and the
5
6
  * cost guard — not full line templates, since the two surfaces render in different languages.
6
7
  */
7
- export function formatDuration(ms) {
8
- const seconds = Math.round(ms / 1000);
9
- if (seconds < 60)
10
- return `${seconds}s`;
11
- return `${Math.floor(seconds / 60)}m${seconds % 60}s`;
12
- }
8
+ export { formatDuration };
13
9
  export function elapsedMs(record, now = Date.now()) {
14
10
  return (record.finishedAt ?? now) - record.startedAt;
15
11
  }
@@ -283,7 +283,7 @@ export declare class SubAgentRunManager {
283
283
  * harmless — this is the same fix as job-manager's `announce()` reordering (D7).
284
284
  */
285
285
  private announce;
286
- /** Explicit cancel (`subagent_manage op=cancel`, spec 040 D6). Does not wake — it is the model's own decision. */
286
+ /** Explicit cancel (`subagent_run op=cancel`, spec 040 D6). Does not wake — it is the model's own decision. */
287
287
  cancel(runId: string): Promise<RunStatus | "not_found">;
288
288
  /**
289
289
  * Rebuild in-memory state after a restart. Internal runs cannot survive a restart by
@@ -2,6 +2,7 @@ import { mkdir, readdir, readFile, rmdir, stat, unlink } from "node:fs/promises"
2
2
  import { join } from "node:path";
3
3
  import * as log from "../log.js";
4
4
  import { writeFileAtomically } from "../shared/atomic-file.js";
5
+ import { formatDuration } from "../shared/duration.js";
5
6
  import { isProcessAlive, killProcessGroup, readProcessStartTime } from "../shared/host-process.js";
6
7
  import { RecoverableToolError } from "../shared/recoverable-error.js";
7
8
  import { createSerialQueue } from "../shared/serial-queue.js";
@@ -82,12 +83,6 @@ function parseRunRecord(raw) {
82
83
  }
83
84
  return value;
84
85
  }
85
- function formatDuration(ms) {
86
- const seconds = Math.round(ms / 1000);
87
- if (seconds < 60)
88
- return `${seconds}s`;
89
- return `${Math.floor(seconds / 60)}m${seconds % 60}s`;
90
- }
91
86
  /**
92
87
  * Per-channel manager for delegation runs — the single settlement/usage/wake authority for both
93
88
  * internal sub-agents and (once wired) external harnesses (D7). Modeled directly on
@@ -218,7 +213,7 @@ export class SubAgentRunManager {
218
213
  // non-goals). Checked before anything is persisted, so a rejected run costs nothing.
219
214
  if (this.runningCount() >= MAX_RUNNING_SUBAGENT_RUNS_PER_CHANNEL) {
220
215
  throw new RecoverableToolError(`Too many delegation runs already running on this channel (>= ${MAX_RUNNING_SUBAGENT_RUNS_PER_CHANNEL}). ` +
221
- "Wait for one to finish, or cancel one with subagent_manage first.");
216
+ "Wait for one to finish, or cancel one with subagent_run op=cancel first.");
222
217
  }
223
218
  if (totalRunningSubAgentRuns() >= MAX_RUNNING_SUBAGENT_RUNS_PER_HOST) {
224
219
  throw new RecoverableToolError(`Too many delegation runs already running host-wide (>= ${MAX_RUNNING_SUBAGENT_RUNS_PER_HOST}). ` +
@@ -467,7 +462,7 @@ export class SubAgentRunManager {
467
462
  const tail = outputText.slice(-WAKE_OUTPUT_TAIL_CHARS).trim();
468
463
  const harnessLabel = record.harness ? `${record.runtime}/${record.harness}` : record.runtime;
469
464
  // K parallel fan-out runs otherwise produce K wake turns, each re-asking "is this the only
470
- // one?" via a fresh subagent_manage op=list call — this answers it inline (review 2026-08-23
465
+ // one?" via a fresh subagent_list call — this answers it inline (review 2026-08-23
471
466
  // §3.3), so the model can reliably reply [SILENT] to every wake but the last.
472
467
  const siblingCount = record.taskId
473
468
  ? Array.from(this.runs.values()).filter((other) => other.taskId === record.taskId && other.status === "running" && other.runId !== record.runId).length
@@ -528,7 +523,7 @@ export class SubAgentRunManager {
528
523
  record.wakeEnqueued = true;
529
524
  await this.persist(record);
530
525
  }
531
- /** Explicit cancel (`subagent_manage op=cancel`, spec 040 D6). Does not wake — it is the model's own decision. */
526
+ /** Explicit cancel (`subagent_run op=cancel`, spec 040 D6). Does not wake — it is the model's own decision. */
532
527
  async cancel(runId) {
533
528
  let adoptedRecord;
534
529
  const status = await this.queue.run(runId, async () => {
@@ -2,6 +2,7 @@ import { type AgentEvent, type AgentMessage, type AgentTool } from "@earendil-wo
2
2
  import type { Api, Model } from "@earendil-works/pi-ai";
3
3
  import { Type } from "typebox";
4
4
  import type { Executor } from "../executor.js";
5
+ import type { FileStore } from "../file-store.js";
5
6
  import type { MemoryCandidateStore } from "../memory/candidates.js";
6
7
  import type { SecurityConfig } from "../security/types.js";
7
8
  import type { PipiclawMemoryRecallSettings } from "../settings.js";
@@ -9,23 +10,34 @@ import { type UsageTotals } from "../shared/types.js";
9
10
  import type { PipiclawWebToolsConfig } from "../tools/config.js";
10
11
  import { type ResolvedSubAgentConfig, type SubAgentConfig, type SubAgentDiscoveryResult } from "./discovery.js";
11
12
  import { getSubAgentRunManager } from "./runs.js";
13
+ /**
14
+ * Role-based delegation (spec 046, D2.1): the common path. No override fields beyond routing
15
+ * ones — tools, model, effort, context, thinkingLevel and mutates all live in the role file, so
16
+ * a call naming an external role cannot pass any of them (there is nowhere for it to put them).
17
+ */
12
18
  declare const subagentSchema: Type.TObject<{
13
- label: Type.TString;
14
- agent: Type.TOptional<Type.TString>;
15
- name: Type.TOptional<Type.TString>;
19
+ agent: Type.TString;
16
20
  task: Type.TString;
17
- systemPrompt: Type.TOptional<Type.TString>;
21
+ workingDirectory: Type.TOptional<Type.TString>;
22
+ purpose: Type.TOptional<Type.TUnion<[Type.TLiteral<"work">, Type.TLiteral<"verify">]>>;
23
+ taskId: Type.TOptional<Type.TString>;
24
+ }>;
25
+ /**
26
+ * Inline delegation (spec 046, D2.1): a one-off executor for when no configured role fits.
27
+ * Carries every field a role file would otherwise supply.
28
+ */
29
+ declare const subagentInlineSchema: Type.TObject<{
30
+ task: Type.TString;
31
+ systemPrompt: Type.TString;
18
32
  tools: Type.TOptional<Type.TArray<Type.TString>>;
19
33
  model: Type.TOptional<Type.TString>;
20
34
  effort: Type.TOptional<Type.TUnion<[Type.TLiteral<"quick">, Type.TLiteral<"standard">, Type.TLiteral<"deep">]>>;
21
35
  context: Type.TOptional<Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"session">, Type.TLiteral<"relevant">]>>;
22
- paths: Type.TOptional<Type.TArray<Type.TString>>;
36
+ thinkingLevel: Type.TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
37
+ mutates: Type.TOptional<Type.TUnion<[Type.TLiteral<"read">, Type.TLiteral<"write">]>>;
23
38
  workingDirectory: Type.TOptional<Type.TString>;
24
39
  purpose: Type.TOptional<Type.TUnion<[Type.TLiteral<"work">, Type.TLiteral<"verify">]>>;
25
40
  taskId: Type.TOptional<Type.TString>;
26
- returns: Type.TOptional<Type.TUnion<[Type.TLiteral<"text">, Type.TLiteral<"artifact">]>>;
27
- thinkingLevel: Type.TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">, Type.TLiteral<"max">]>>;
28
- mutates: Type.TOptional<Type.TUnion<[Type.TLiteral<"read">, Type.TLiteral<"write">]>>;
29
41
  }>;
30
42
  /**
31
43
  * Fields the `subagent` tool itself constructs. `kind` is not among them: `withToolDetails`
@@ -46,10 +58,8 @@ export interface SubAgentToolFields {
46
58
  purpose: "work" | "verify";
47
59
  taskId?: string;
48
60
  verificationVerdict?: "pass" | "fail";
49
- /** Always populated (spec 032 D4): the full output is saved to `${artifactDir}/output.md` regardless of `returns`. */
61
+ /** Always populated (spec 032 D4): the full output is saved to `${artifactDir}/output.md`. */
50
62
  artifactDir: string;
51
- /** Set only when `returns: "artifact"` and the sub-agent emitted a valid ARTIFACT: marker. */
52
- artifactPath?: string;
53
63
  /** True when the reply text was truncated against MAX_SUBAGENT_RESULT_UNITS; the full text is still on disk. */
54
64
  resultTruncated: boolean;
55
65
  /**
@@ -61,10 +71,11 @@ export interface SubAgentToolFields {
61
71
  }
62
72
  /** The shape consumers read post-wrap, once `withToolDetails` has stamped `kind`. */
63
73
  export type SubAgentToolDetails = SubAgentToolFields & {
64
- kind: "subagent";
74
+ kind: "subagent" | "subagent_inline";
65
75
  };
66
76
  export interface SubAgentToolOptions {
67
77
  executor: Executor;
78
+ fileStore: FileStore;
68
79
  /** Host checkout used as the sub-agent's cwd. Defaults to process.cwd(). */
69
80
  workingDirectory?: string;
70
81
  /** Mirrors the parent channel's ProjectScope.boundary onto the sub-agent's own tool set (spec 043, D6.2). */
@@ -117,7 +128,7 @@ interface SubAgentWorker {
117
128
  * only caps what gets echoed into the parent's context.
118
129
  */
119
130
  export declare const MAX_SUBAGENT_RESULT_UNITS = 1200;
120
- /** Exported for `subagent_manage op=follow_up` (spec 042 D7), which constructs one of these for
131
+ /** Exported for `subagent_run op=follow_up` (spec 042 D7), which constructs one of these for
121
132
  * its own new run rather than a hand-rolled envelope. */
122
133
  export interface SubAgentRunContext {
123
134
  runId: string;
@@ -142,30 +153,31 @@ export declare function assertWithinProjectBoundary(target: string, base: string
142
153
  * (rooted at the sub-agent workspace) and their own per-invocation bash timeout.
143
154
  */
144
155
  declare function buildSubagentTools(executor: Executor, bashTimeoutSec: number, options: SubAgentToolOptions, runContext: SubAgentRunContext): AgentTool<any>[];
145
- /** Shared by both runtimes' task envelopes and `subagent_manage`'s verify follow-up (spec 040, D9). */
156
+ /** Shared by both runtimes' task envelopes and `subagent_run`'s verify follow-up (spec 040, D9). */
146
157
  export declare function buildVerificationProtocol(taskPath: string): string;
147
158
  /**
148
159
  * D9 verify admission — a role that admits it writes cannot also be the checker, `exec` has no
149
160
  * protocol terminal to prove it even ran to completion, and a target with an active write lease
150
161
  * is refused up front (cheaper than explaining afterward why the attestation would be worthless).
151
- * Spec 042 D7: exported so `subagent_manage op=follow_up` runs the exact same checks the initial
162
+ * Spec 042 D7: exported so `subagent_run op=follow_up` runs the exact same checks the initial
152
163
  * dispatch does — before this function existed, follow_up on a role that had since been hot-edited
153
164
  * to `mutates: write` would silently take the write lease and dispatch instead of refusing.
154
165
  */
155
166
  export declare function assertVerifyAdmissible(config: Pick<ResolvedSubAgentConfig, "name" | "mutates" | "runtime" | "harness">, purpose: "work" | "verify", workingDirectory: string): void;
156
167
  /**
157
- * Exported for `subagent_manage op=follow_up` (spec 042 D7), which builds a follow-up run's task
168
+ * Exported for `subagent_run op=follow_up` (spec 042 D7), which builds a follow-up run's task
158
169
  * envelope the same way the initial dispatch does rather than a hand-rolled approximation.
159
170
  * `config` is deliberately narrowed to `{ name }` — the only field this function reads — so a
160
171
  * caller with a raw (unresolved) `SubAgentConfig` from discovery does not need to fabricate a
161
172
  * `model`/`modelRef`/`thinkingLevel` just to satisfy a wider type it never touches.
162
173
  */
163
- export declare function buildSubAgentTask(task: string, config: Pick<SubAgentConfig, "name">, runtimeContext: SubAgentToolOptions["runtimeContext"], contextBlocks: string[], runContext: SubAgentRunContext, returns: "text" | "artifact"): string;
164
- /** Exported for `subagent_manage op=follow_up` (spec 042 D7) — same reason as `buildSubAgentTask`. */
174
+ export declare function buildSubAgentTask(task: string, config: Pick<SubAgentConfig, "name">, runtimeContext: SubAgentToolOptions["runtimeContext"], contextBlocks: string[], runContext: SubAgentRunContext): string;
175
+ /** Exported for `subagent_run op=follow_up` (spec 042 D7) — same reason as `buildSubAgentTask`. */
165
176
  /** The slice of `SubAgentToolOptions` `buildContextualBlocks` actually reads — narrowed (spec 042
166
- * D7) so `subagent_manage op=follow_up` only needs to wire these six fields, not the full tool
177
+ * D7) so `subagent_run op=follow_up` only needs to wire these six fields, not the full tool
167
178
  * option surface (executor, discovery, web config, etc. that a context-block build never touches). */
168
179
  export type ContextualBlocksOptions = Pick<SubAgentToolOptions, "channelDir" | "getMemoryRecallSettings" | "runtimeContext" | "workspaceDir" | "resolveApiKey" | "memoryCandidateStore">;
169
180
  export declare function buildContextualBlocks(task: string, config: Pick<SubAgentConfig, "contextMode" | "paths" | "memory" | "description">, options: ContextualBlocksOptions, currentModel: Model<Api>): Promise<string[]>;
170
181
  export declare function createSubAgentTool(options: SubAgentToolOptions): AgentTool<typeof subagentSchema, SubAgentToolFields>;
182
+ export declare function createSubAgentInlineTool(options: SubAgentToolOptions): AgentTool<typeof subagentInlineSchema, SubAgentToolFields>;
171
183
  export {};