@oyasmi/pipiclaw 0.9.3-beta.3 → 0.9.3-beta.4

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 (95) hide show
  1. package/dist/agent/channel-runner.d.ts +4 -18
  2. package/dist/agent/channel-runner.js +25 -120
  3. package/dist/agent/context-budget.js +1 -1
  4. package/dist/agent/job-manager.d.ts +11 -17
  5. package/dist/agent/job-manager.js +76 -65
  6. package/dist/agent/prompt/builder.js +1 -17
  7. package/dist/agent/prompt/manifest.d.ts +0 -1
  8. package/dist/agent/prompt/manifest.js +2 -2
  9. package/dist/agent/prompt/sections.js +0 -9
  10. package/dist/agent/prompt/types.d.ts +2 -18
  11. package/dist/agent/prompt/types.js +1 -1
  12. package/dist/agent/runner-factory.d.ts +4 -0
  13. package/dist/agent/session-adapter.d.ts +19 -0
  14. package/dist/agent/session-adapter.js +77 -0
  15. package/dist/app-services.d.ts +18 -0
  16. package/dist/app-services.js +43 -0
  17. package/dist/{runtime → events}/events.d.ts +1 -1
  18. package/dist/memory/journal.js +1 -1
  19. package/dist/memory/maintenance-gates.d.ts +0 -3
  20. package/dist/memory/maintenance-gates.js +2 -2
  21. package/dist/memory/maintenance-migration.d.ts +5 -0
  22. package/dist/memory/maintenance-migration.js +91 -0
  23. package/dist/memory/maintenance-state.js +5 -44
  24. package/dist/memory/migrate.js +1 -1
  25. package/dist/memory/reflect-job.d.ts +1 -9
  26. package/dist/memory/reflect-job.js +1 -3
  27. package/dist/memory/reflect.js +1 -1
  28. package/dist/memory/session-corpus.js +1 -1
  29. package/dist/memory/store.js +1 -1
  30. package/dist/models/auth-cli.js +1 -1
  31. package/dist/runtime/bootstrap.d.ts +5 -15
  32. package/dist/runtime/bootstrap.js +32 -56
  33. package/dist/runtime/subagent-commands.d.ts +2 -1
  34. package/dist/runtime/subagent-commands.js +10 -12
  35. package/dist/runtime/task-wake.d.ts +4 -5
  36. package/dist/runtime/task-wake.js +2 -12
  37. package/dist/security/types.d.ts +7 -0
  38. package/dist/security/types.js +16 -1
  39. package/dist/settings.d.ts +8 -0
  40. package/dist/settings.js +24 -1
  41. package/dist/shared/exact-keys.d.ts +13 -0
  42. package/dist/shared/exact-keys.js +1 -0
  43. package/dist/shared/format.d.ts +20 -0
  44. package/dist/shared/format.js +64 -0
  45. package/dist/shared/{fs-utils.d.ts → os.d.ts} +6 -0
  46. package/dist/shared/{fs-utils.js → os.js} +8 -0
  47. package/dist/subagents/discovery.d.ts +16 -3
  48. package/dist/subagents/discovery.js +9 -7
  49. package/dist/subagents/external/run.d.ts +2 -1
  50. package/dist/subagents/external/run.js +1 -2
  51. package/dist/subagents/external/settlement.js +10 -5
  52. package/dist/subagents/format.d.ts +1 -1
  53. package/dist/subagents/format.js +1 -1
  54. package/dist/subagents/runs.d.ts +13 -12
  55. package/dist/subagents/runs.js +108 -89
  56. package/dist/subagents/tool.d.ts +7 -7
  57. package/dist/subagents/tool.js +11 -11
  58. package/dist/tasks/brief.js +1 -0
  59. package/dist/tools/command-optimizer.js +1 -1
  60. package/dist/tools/config.d.ts +7 -0
  61. package/dist/tools/config.js +16 -1
  62. package/dist/tools/event-manage.d.ts +1 -1
  63. package/dist/tools/event-manage.js +3 -3
  64. package/dist/tools/grep.js +1 -1
  65. package/dist/tools/index.d.ts +4 -0
  66. package/dist/tools/index.js +4 -2
  67. package/dist/tools/job.js +1 -1
  68. package/dist/tools/read.js +1 -1
  69. package/dist/tools/registry.d.ts +3 -3
  70. package/dist/tools/registry.js +18 -56
  71. package/dist/tools/skill.js +1 -1
  72. package/dist/tools/subagent-manage.d.ts +2 -0
  73. package/dist/tools/subagent-manage.js +7 -7
  74. package/dist/tools/subagent-tool-names.d.ts +2 -2
  75. package/dist/tools/subagent-tool-names.js +2 -2
  76. package/dist/tools/task-manage/shared.js +4 -9
  77. package/dist/tools/task-manage/types.d.ts +4 -0
  78. package/dist/tui/app.js +22 -7
  79. package/dist/web/config.js +1 -1
  80. package/package.json +2 -1
  81. package/dist/shared/duration.d.ts +0 -2
  82. package/dist/shared/duration.js +0 -7
  83. package/dist/shared/file-stamp.d.ts +0 -10
  84. package/dist/shared/file-stamp.js +0 -19
  85. package/dist/shared/numeric.d.ts +0 -7
  86. package/dist/shared/numeric.js +0 -19
  87. package/dist/shared/shell-escape.d.ts +0 -5
  88. package/dist/shared/shell-escape.js +0 -7
  89. package/dist/shared/token-estimate.d.ts +0 -1
  90. package/dist/shared/token-estimate.js +0 -19
  91. /package/dist/{runtime → events}/event-commands.d.ts +0 -0
  92. /package/dist/{runtime → events}/event-commands.js +0 -0
  93. /package/dist/{runtime → events}/event-validation.d.ts +0 -0
  94. /package/dist/{runtime → events}/event-validation.js +0 -0
  95. /package/dist/{runtime → events}/events.js +0 -0
@@ -1,8 +1,23 @@
1
1
  import { join } from "node:path";
2
2
  import { APP_HOME_DIR } from "../paths.js";
3
3
  import { loadJsonConfig, pushConfigWarning } from "../shared/config-diagnostic.js";
4
- import { clampInteger } from "../shared/numeric.js";
4
+ import { clampInteger } from "../shared/format.js";
5
5
  import { isRecord } from "../shared/type-guards.js";
6
+ /**
7
+ * Every `tools.<key>` section in `tools.json`, read by `test/config-reference-coverage.test.ts`
8
+ * to check that `docs/configuration-reference.md` still mentions each one. Kept in sync with
9
+ * `PipiclawToolsConfig["tools"]` by `satisfies` (rejects an extra/misspelled entry) and
10
+ * `AssertNoMissingKeys` (rejects a section with no entry here) — both at `npm run typecheck`.
11
+ */
12
+ export const TOOLS_CONFIG_SECTION_KEYS = [
13
+ "web",
14
+ "tasks",
15
+ "bashInterceptor",
16
+ "rtk",
17
+ "subagentInline",
18
+ ];
19
+ const _toolsConfigKeysComplete = true;
20
+ void _toolsConfigKeysComplete;
6
21
  const WEB_SEARCH_PROVIDERS = ["brave", "tavily", "jina", "searxng", "duckduckgo"];
7
22
  export const DEFAULT_TOOLS_CONFIG = {
8
23
  tools: {
@@ -1,6 +1,6 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import { Type } from "typebox";
3
- import { type ScheduledEvent } from "../runtime/events.js";
3
+ import { type ScheduledEvent } from "../events/events.js";
4
4
  import type { SecurityConfig } from "../security/types.js";
5
5
  declare const eventManageSchema: Type.TObject<{
6
6
  action: Type.TUnion<[Type.TLiteral<"list">, Type.TLiteral<"show">, Type.TLiteral<"create">, Type.TLiteral<"update">, Type.TLiteral<"delete">]>;
@@ -2,9 +2,9 @@ import { existsSync } from "node:fs";
2
2
  import { readdir, readFile, unlink } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { Type } from "typebox";
5
- import { resolveEventPath } from "../runtime/event-commands.js";
6
- import { EventValidationError, MAX_EVENT_FILES, validateScheduledEvent } from "../runtime/event-validation.js";
7
- import { parseScheduledEventContent } from "../runtime/events.js";
5
+ import { resolveEventPath } from "../events/event-commands.js";
6
+ import { EventValidationError, MAX_EVENT_FILES, validateScheduledEvent } from "../events/event-validation.js";
7
+ import { parseScheduledEventContent } from "../events/events.js";
8
8
  import { writeFileAtomically } from "../shared/atomic-file.js";
9
9
  import { RecoverableToolError } from "../shared/recoverable-error.js";
10
10
  import { clipText, errorMessage } from "../shared/text-utils.js";
@@ -3,8 +3,8 @@ import { Type } from "typebox";
3
3
  import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
4
4
  import { checkPathGuard } from "../security/path-guard-check.js";
5
5
  import { partitionByReadGuard, readGuardAllows } from "../security/path-guard-filter.js";
6
+ import { shellEscape } from "../shared/os.js";
6
7
  import { RecoverableToolError } from "../shared/recoverable-error.js";
7
- import { shellEscape } from "../shared/shell-escape.js";
8
8
  import { IGNORED_DIR_SEGMENTS } from "./ignore-dirs.js";
9
9
  import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
10
10
  /**
@@ -1,5 +1,6 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import type { Api, Model } from "@earendil-works/pi-ai";
3
+ import type { ChannelJobManager } from "../agent/job-manager.js";
3
4
  import type { MediaSender } from "../channel/channel-context.js";
4
5
  import type { Executor } from "../executor.js";
5
6
  import type { FileStore } from "../file-store.js";
@@ -7,8 +8,11 @@ import type { ProjectScope } from "../security/project-scope.js";
7
8
  import type { SecurityConfig } from "../security/types.js";
8
9
  import type { PipiclawSessionSearchSettings } from "../settings.js";
9
10
  import { type SubAgentDiscoveryResult } from "../subagents/discovery.js";
11
+ import type { SubAgentRunManager } from "../subagents/runs.js";
10
12
  import type { PipiclawToolsConfig } from "./config.js";
11
13
  export interface CreatePipiclawToolsOptions {
14
+ jobManager: ChannelJobManager;
15
+ runManager: SubAgentRunManager;
12
16
  executor: Executor;
13
17
  /** File-content port for the generic file tools (spec 044, D1); `Executor` stays command-only. */
14
18
  fileStore: FileStore;
@@ -1,4 +1,3 @@
1
- import { getChannelJobManager } from "../agent/job-manager.js";
2
1
  import { APP_HOME_DIR } from "../paths.js";
3
2
  import { loadSecurityConfig } from "../security/config.js";
4
3
  import { withSubAgentsDirWriteDeny } from "../subagents/discovery.js";
@@ -37,7 +36,8 @@ export function createPipiclawTools(options) {
37
36
  webConfig: toolsConfig.tools.web,
38
37
  toolsConfig,
39
38
  rtkEnabled: toolsConfig.tools.rtk.enabled,
40
- jobManager: getChannelJobManager(options.channelId, options.executor),
39
+ jobManager: options.jobManager,
40
+ runManager: options.runManager,
41
41
  getCurrentModel: options.getCurrentModel,
42
42
  getAvailableModels: options.getAvailableModels,
43
43
  resolveApiKey: options.resolveApiKey,
@@ -47,6 +47,7 @@ export function createPipiclawTools(options) {
47
47
  getToolsUsed: options.getToolsUsed,
48
48
  });
49
49
  const subAgentToolOptions = {
50
+ getRunManager: () => options.runManager,
50
51
  executor: options.executor,
51
52
  fileStore: options.fileStore,
52
53
  getCurrentModel: options.getCurrentModel,
@@ -69,6 +70,7 @@ export function createPipiclawTools(options) {
69
70
  },
70
71
  };
71
72
  const subAgentManageOptions = {
73
+ runManager: options.runManager,
72
74
  channelId: options.channelId,
73
75
  channelDir: options.channelDir,
74
76
  getSubAgentDiscovery: options.getSubAgentDiscovery,
package/dist/tools/job.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Type } from "typebox";
2
- import { formatDuration } from "../shared/duration.js";
2
+ import { formatDuration } from "../shared/format.js";
3
3
  import { RecoverableToolError } from "../shared/recoverable-error.js";
4
4
  import { truncateTail } from "./truncate.js";
5
5
  const jobSchema = Type.Object({
@@ -2,8 +2,8 @@ import { extname } from "path";
2
2
  import { Type } from "typebox";
3
3
  import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
4
4
  import { checkPathGuard } from "../security/path-guard-check.js";
5
+ import { shellEscape } from "../shared/os.js";
5
6
  import { RecoverableToolError } from "../shared/recoverable-error.js";
6
- import { shellEscape } from "../shared/shell-escape.js";
7
7
  import { resolveLineOffset } from "./line-index.js";
8
8
  import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, MAX_INLINE_BINARY_BYTES, truncateHead, } from "./truncate.js";
9
9
  /**
@@ -6,6 +6,7 @@ import type { Executor } from "../executor.js";
6
6
  import type { FileStore } from "../file-store.js";
7
7
  import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
8
8
  import type { PipiclawSessionSearchSettings } from "../settings.js";
9
+ import type { SubAgentRunManager } from "../subagents/runs.js";
9
10
  import type { PipiclawToolsConfig, PipiclawWebToolsConfig } from "./config.js";
10
11
  import { type ToolDetailsKind } from "./tool-details.js";
11
12
  /**
@@ -45,6 +46,7 @@ export interface ToolBuildContext {
45
46
  * The sub-agent set never supplies it, so sub-agents get neither.
46
47
  */
47
48
  jobManager?: ChannelJobManager;
49
+ runManager?: SubAgentRunManager;
48
50
  getCurrentModel?: () => Model<Api>;
49
51
  getAvailableModels?: () => Model<Api>[];
50
52
  resolveApiKey?: (model: Model<Api>) => Promise<string>;
@@ -69,8 +71,6 @@ export interface ToolBuildContext {
69
71
  export interface ToolRegistration {
70
72
  /** Also the tool's `details.kind`: the name is the authoritative discriminator. */
71
73
  name: ToolDetailsKind;
72
- /** Whether this tool is included in a sub-agent's tool set. */
73
- availableToSubagents: boolean;
74
74
  /** Config gate; when omitted the tool is always enabled. */
75
75
  enabledBy?: (ctx: ToolBuildContext) => boolean;
76
76
  create: (ctx: ToolBuildContext) => AgentTool<any>;
@@ -95,7 +95,7 @@ export declare const TOOL_REGISTRY: ToolRegistration[];
95
95
  */
96
96
  export declare const TOOL_NAMES: ReadonlySet<string>;
97
97
  export interface BuildToolSetOptions {
98
- /** When true, include only tools flagged `availableToSubagents`. */
98
+ /** When true, include only tools in the sub-agent whitelist. */
99
99
  forSubagent?: boolean;
100
100
  }
101
101
  /**
@@ -9,6 +9,7 @@ import { createReadTool } from "./read.js";
9
9
  import { createSendMediaTool } from "./send-media.js";
10
10
  import { createSessionSearchTool } from "./session-search.js";
11
11
  import { createSkillTool } from "./skill.js";
12
+ import { SUBAGENT_TOOL_NAMES } from "./subagent-tool-names.js";
12
13
  import { createTaskCloseTool, createTaskCreateTool, createTaskListTool, createTaskLogTool, createTaskStepEndTool, createTaskUpdateTool, } from "./task-manage.js";
13
14
  import { withToolDetails } from "./tool-details.js";
14
15
  import { createWebFetchTool } from "./web-fetch.js";
@@ -34,6 +35,16 @@ function memoryToolOptions(ctx) {
34
35
  workspaceDir: ctx.workspaceDir,
35
36
  };
36
37
  }
38
+ function taskToolOptions(ctx) {
39
+ return {
40
+ jobManager: req(ctx.jobManager, "jobManager"),
41
+ runManager: req(ctx.runManager, "runManager"),
42
+ workspaceDir: ctx.workspaceDir,
43
+ channelDir: ctx.channelDir,
44
+ channelId: ctx.channelId,
45
+ workingDirectory: ctx.securityContext.projectRoot,
46
+ };
47
+ }
37
48
  function webEnabled(ctx) {
38
49
  return ctx.webConfig != null && ctx.webConfig.enable !== false;
39
50
  }
@@ -46,12 +57,10 @@ function webEnabled(ctx) {
46
57
  export const TOOL_REGISTRY = [
47
58
  {
48
59
  name: "read",
49
- availableToSubagents: true,
50
60
  create: (ctx) => createReadTool(ctx.executor, ctx.fileStore, fileToolOptions(ctx)),
51
61
  },
52
62
  {
53
63
  name: "bash",
54
- availableToSubagents: true,
55
64
  create: (ctx) => createBashTool(ctx.executor, {
56
65
  ...fileToolOptions(ctx),
57
66
  rtkEnabled: ctx.rtkEnabled === true,
@@ -67,27 +76,22 @@ export const TOOL_REGISTRY = [
67
76
  },
68
77
  {
69
78
  name: "edit",
70
- availableToSubagents: true,
71
79
  create: (ctx) => createEditTool(ctx.fileStore, fileToolOptions(ctx)),
72
80
  },
73
81
  {
74
82
  name: "grep",
75
- availableToSubagents: true,
76
83
  create: (ctx) => createGrepTool(ctx.executor, fileToolOptions(ctx)),
77
84
  },
78
85
  {
79
86
  name: "glob",
80
- availableToSubagents: true,
81
87
  create: (ctx) => createGlobTool(ctx.fileStore, fileToolOptions(ctx)),
82
88
  },
83
89
  {
84
90
  name: "write",
85
- availableToSubagents: true,
86
91
  create: (ctx) => createWriteTool(ctx.fileStore, fileToolOptions(ctx)),
87
92
  },
88
93
  {
89
94
  name: "web_search",
90
- availableToSubagents: true,
91
95
  enabledBy: webEnabled,
92
96
  create: (ctx) => createWebSearchTool({
93
97
  webConfig: req(ctx.webConfig, "webConfig"),
@@ -98,7 +102,6 @@ export const TOOL_REGISTRY = [
98
102
  },
99
103
  {
100
104
  name: "web_fetch",
101
- availableToSubagents: true,
102
105
  enabledBy: webEnabled,
103
106
  create: (ctx) => createWebFetchTool({
104
107
  webConfig: req(ctx.webConfig, "webConfig"),
@@ -110,7 +113,6 @@ export const TOOL_REGISTRY = [
110
113
  },
111
114
  {
112
115
  name: "send_media",
113
- availableToSubagents: false,
114
116
  // Enabled only when the driving transport supplied a media sender (the DingTalk
115
117
  // bot, or the terminal). Absent it, the tool is not built or advertised.
116
118
  enabledBy: (ctx) => ctx.mediaSender != null,
@@ -123,7 +125,6 @@ export const TOOL_REGISTRY = [
123
125
  },
124
126
  {
125
127
  name: "session_search",
126
- availableToSubagents: false,
127
128
  create: (ctx) => createSessionSearchTool({
128
129
  channelId: ctx.channelId,
129
130
  channelDir: ctx.channelDir,
@@ -135,27 +136,22 @@ export const TOOL_REGISTRY = [
135
136
  // Spec 047, P4: one tool per payload shape. All three share the same build options.
136
137
  {
137
138
  name: "memory_save",
138
- availableToSubagents: false,
139
139
  create: (ctx) => createMemorySaveTool(memoryToolOptions(ctx)),
140
140
  },
141
141
  {
142
142
  name: "memory_search",
143
- availableToSubagents: false,
144
143
  create: (ctx) => createMemorySearchTool(memoryToolOptions(ctx)),
145
144
  },
146
145
  {
147
146
  name: "memory_forget",
148
- availableToSubagents: false,
149
147
  create: (ctx) => createMemoryForgetTool(memoryToolOptions(ctx)),
150
148
  },
151
149
  {
152
150
  name: "skill",
153
- availableToSubagents: false,
154
151
  create: (ctx) => createSkillTool({ workspaceDir: ctx.workspaceDir, ...fileToolOptions(ctx) }),
155
152
  },
156
153
  {
157
154
  name: "event_manage",
158
- availableToSubagents: false,
159
155
  create: (ctx) => createEventManageTool({
160
156
  workspaceDir: ctx.workspaceDir,
161
157
  channelId: ctx.channelId,
@@ -167,68 +163,35 @@ export const TOOL_REGISTRY = [
167
163
  // shape (spec 046, D3.1) — all share it, since none is meaningful without the others.
168
164
  {
169
165
  name: "task_list",
170
- availableToSubagents: false,
171
166
  enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
172
- create: (ctx) => createTaskListTool({
173
- workspaceDir: ctx.workspaceDir,
174
- channelDir: ctx.channelDir,
175
- channelId: ctx.channelId,
176
- workingDirectory: ctx.securityContext.projectRoot,
177
- }),
167
+ create: (ctx) => createTaskListTool(taskToolOptions(ctx)),
178
168
  },
179
169
  {
180
170
  name: "task_create",
181
- availableToSubagents: false,
182
171
  enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
183
- create: (ctx) => createTaskCreateTool({
184
- workspaceDir: ctx.workspaceDir,
185
- channelDir: ctx.channelDir,
186
- channelId: ctx.channelId,
187
- workingDirectory: ctx.securityContext.projectRoot,
188
- }),
172
+ create: (ctx) => createTaskCreateTool(taskToolOptions(ctx)),
189
173
  },
190
174
  {
191
175
  name: "task_update",
192
- availableToSubagents: false,
193
176
  enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
194
- create: (ctx) => createTaskUpdateTool({
195
- workspaceDir: ctx.workspaceDir,
196
- channelDir: ctx.channelDir,
197
- channelId: ctx.channelId,
198
- workingDirectory: ctx.securityContext.projectRoot,
199
- }),
177
+ create: (ctx) => createTaskUpdateTool(taskToolOptions(ctx)),
200
178
  },
201
179
  {
202
180
  name: "task_close",
203
- availableToSubagents: false,
204
181
  enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
205
- create: (ctx) => createTaskCloseTool({
206
- workspaceDir: ctx.workspaceDir,
207
- channelDir: ctx.channelDir,
208
- channelId: ctx.channelId,
209
- workingDirectory: ctx.securityContext.projectRoot,
210
- }),
182
+ create: (ctx) => createTaskCloseTool(taskToolOptions(ctx)),
211
183
  },
212
184
  {
213
185
  name: "task_log",
214
- availableToSubagents: false,
215
186
  enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
216
- create: (ctx) => createTaskLogTool({
217
- workspaceDir: ctx.workspaceDir,
218
- channelDir: ctx.channelDir,
219
- channelId: ctx.channelId,
220
- }),
187
+ create: (ctx) => createTaskLogTool(taskToolOptions(ctx)),
221
188
  },
222
189
  {
223
190
  name: "task_step_end",
224
- availableToSubagents: false,
225
191
  // Only inside a task session: it is the loop's closing move, not a chat action.
226
192
  enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false && ctx.taskLoop !== undefined,
227
193
  create: (ctx) => createTaskStepEndTool({
228
- workspaceDir: ctx.workspaceDir,
229
- channelDir: ctx.channelDir,
230
- channelId: ctx.channelId,
231
- workingDirectory: ctx.securityContext.projectRoot,
194
+ ...taskToolOptions(ctx),
232
195
  taskId: ctx.taskLoop?.taskId,
233
196
  cycleId: ctx.taskLoop?.cycleId,
234
197
  getToolsUsed: ctx.getToolsUsed,
@@ -236,7 +199,6 @@ export const TOOL_REGISTRY = [
236
199
  },
237
200
  {
238
201
  name: "job",
239
- availableToSubagents: false,
240
202
  // Present only when a job manager was supplied (always on the main path,
241
203
  // never for sub-agents).
242
204
  enabledBy: (ctx) => ctx.jobManager !== undefined,
@@ -272,7 +234,7 @@ export const TOOL_NAMES = new Set([
272
234
  export function buildToolSet(ctx, options = {}) {
273
235
  const result = [];
274
236
  for (const registration of TOOL_REGISTRY) {
275
- if (options.forSubagent && !registration.availableToSubagents) {
237
+ if (options.forSubagent && !SUBAGENT_TOOL_NAMES.some((name) => name === registration.name)) {
276
238
  continue;
277
239
  }
278
240
  if (registration.enabledBy && !registration.enabledBy(ctx)) {
@@ -5,7 +5,7 @@ import { Type } from "typebox";
5
5
  import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
6
6
  import { checkPathGuard } from "../security/path-guard-check.js";
7
7
  import { readGuardAllows } from "../security/path-guard-filter.js";
8
- import { isNodeError } from "../shared/fs-utils.js";
8
+ import { isNodeError } from "../shared/os.js";
9
9
  import { RecoverableToolError } from "../shared/recoverable-error.js";
10
10
  import { resolveSkillPath, scanSkillContent, validateSkillFrontmatter, validateSkillName } from "./skill-security.js";
11
11
  import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
@@ -2,6 +2,7 @@ import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import { Type } from "typebox";
3
3
  import type { SecurityConfig } from "../security/types.js";
4
4
  import { type SubAgentDiscoveryResult } from "../subagents/discovery.js";
5
+ import type { SubAgentRunManager } from "../subagents/runs.js";
5
6
  declare const subagentListSchema: Type.TObject<{}>;
6
7
  declare const subagentRunSchema: Type.TObject<{
7
8
  op: Type.TUnion<[Type.TLiteral<"show">, Type.TLiteral<"cancel">, Type.TLiteral<"follow_up">]>;
@@ -9,6 +10,7 @@ declare const subagentRunSchema: Type.TObject<{
9
10
  task: Type.TOptional<Type.TString>;
10
11
  }>;
11
12
  export interface SubAgentManageToolOptions {
13
+ runManager: SubAgentRunManager;
12
14
  channelId: string;
13
15
  /**
14
16
  * Spec 042 D7: required, not defaulted. `follow_up` dispatches a new external process through
@@ -6,7 +6,6 @@ import { RecoverableToolError } from "../shared/recoverable-error.js";
6
6
  import { externalRoleFingerprint, validateSubAgentTask } from "../subagents/discovery.js";
7
7
  import { launchExternalRun } from "../subagents/external/run.js";
8
8
  import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
9
- import { getSubAgentRunManager } from "../subagents/runs.js";
10
9
  import { assertVerifyAdmissible, assertWithinProjectBoundary, buildContextualBlocks, buildSubAgentTask, } from "../subagents/tool.js";
11
10
  import { acquireWorkspaceLease, formatWorkspaceLeaseConflict, releaseWorkspaceLease, } from "../subagents/workspace-lease.js";
12
11
  // Spec 047, P3: `subagent_list` is zero-argument and shape-independent (like `task_list`); the
@@ -91,7 +90,7 @@ function resumableHarnessOf(record) {
91
90
  return record.harness === "codex-cli" || record.harness === "claude-code" ? record.harness : undefined;
92
91
  }
93
92
  export function createSubAgentListTool(options) {
94
- const manager = () => getSubAgentRunManager(options.channelId);
93
+ const manager = options.runManager;
95
94
  return {
96
95
  name: "subagent_list",
97
96
  label: "subagent_list",
@@ -102,7 +101,7 @@ export function createSubAgentListTool(options) {
102
101
  // text and `details.runs` — a long-lived channel could dump thousands of historical
103
102
  // records into a single tool result. Running runs (the ones a decision might depend
104
103
  // on) are never dropped; only the terminal tail is capped, newest first.
105
- const allRuns = manager().list();
104
+ const allRuns = manager.list();
106
105
  const running = allRuns.filter((record) => record.status === "running");
107
106
  const terminal = allRuns
108
107
  .filter((record) => record.status !== "running")
@@ -121,7 +120,7 @@ export function createSubAgentListTool(options) {
121
120
  };
122
121
  }
123
122
  export function createSubAgentRunTool(options) {
124
- const manager = () => getSubAgentRunManager(options.channelId);
123
+ const manager = options.runManager;
125
124
  return {
126
125
  name: "subagent_run",
127
126
  label: "subagent_run",
@@ -129,7 +128,7 @@ export function createSubAgentRunTool(options) {
129
128
  "(no wake — your decision, not a failure). follow_up: continue a resumable run with a new instruction (new runId).",
130
129
  parameters: subagentRunSchema,
131
130
  execute: async (_toolCallId, { op, runId, task }) => {
132
- const resolution = manager().resolveRef(runId);
131
+ const resolution = manager.resolveRef(runId);
133
132
  if (resolution.kind === "ambiguous") {
134
133
  throw new RecoverableToolError(`"${runId}" matches multiple runs on this channel: ${resolution.candidates.map((candidate) => candidate.runId).join(", ")}. Use the full runId.`);
135
134
  }
@@ -145,7 +144,7 @@ export function createSubAgentRunTool(options) {
145
144
  };
146
145
  }
147
146
  if (op === "cancel") {
148
- const status = await manager().cancel(resolvedRunId);
147
+ const status = await manager.cancel(resolvedRunId);
149
148
  return {
150
149
  content: [{ type: "text", text: `Cancel requested for run ${resolvedRunId}: ${status}` }],
151
150
  details: { op, runId: resolvedRunId, status },
@@ -213,7 +212,7 @@ export function createSubAgentRunTool(options) {
213
212
  }
214
213
  // A short, human-typeable id (spec 041) — the follow-up gets a fresh identity, not the
215
214
  // dispatching tool call's own id.
216
- const newRunId = manager().mintRunId();
215
+ const newRunId = manager.mintRunId();
217
216
  let leaseKey;
218
217
  if (role.mutates === "write") {
219
218
  const lease = acquireWorkspaceLease({
@@ -250,6 +249,7 @@ export function createSubAgentRunTool(options) {
250
249
  });
251
250
  const envelopedTask = buildSubAgentTask(task, role, { workspaceDir: options.workspaceDir, channelId: options.channelId }, contextualBlocks, runContext);
252
251
  launchResult = await launchExternalRun({
252
+ runManager: manager,
253
253
  runId: newRunId,
254
254
  channelId: options.channelId,
255
255
  channelDir: options.channelDir,
@@ -2,10 +2,10 @@
2
2
  * The single source of truth for which tools a sub-agent role may request.
3
3
  *
4
4
  * This is a leaf module with no imports so both ends can read it without pulling in a cycle:
5
- * `registry.ts` stamps `availableToSubagents` from it when building the sub-agent tool set, and
5
+ * `registry.ts` filters the sub-agent tool set through it, and
6
6
  * `subagents/discovery.ts` validates a role file's `tools:` list against it. They used to be two
7
7
  * hand-maintained lists and had already drifted (`glob` was build-available but validation-rejected).
8
- * A test asserts the two ends still agree.
8
+ * A test checks that every allowed name has a registered implementation.
9
9
  */
10
10
  export declare const SUBAGENT_TOOL_NAMES: readonly ["read", "grep", "glob", "bash", "edit", "write", "web_search", "web_fetch"];
11
11
  export type SubAgentToolName = (typeof SUBAGENT_TOOL_NAMES)[number];
@@ -2,10 +2,10 @@
2
2
  * The single source of truth for which tools a sub-agent role may request.
3
3
  *
4
4
  * This is a leaf module with no imports so both ends can read it without pulling in a cycle:
5
- * `registry.ts` stamps `availableToSubagents` from it when building the sub-agent tool set, and
5
+ * `registry.ts` filters the sub-agent tool set through it, and
6
6
  * `subagents/discovery.ts` validates a role file's `tools:` list against it. They used to be two
7
7
  * hand-maintained lists and had already drifted (`glob` was build-available but validation-rejected).
8
- * A test asserts the two ends still agree.
8
+ * A test checks that every allowed name has a registered implementation.
9
9
  */
10
10
  export const SUBAGENT_TOOL_NAMES = [
11
11
  "read",
@@ -1,13 +1,10 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { readdir, readFile, unlink } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
- import { getChannelJobManager } from "../../agent/job-manager.js";
5
- import { createExecutor } from "../../executor.js";
4
+ import { parseScheduledEventContent } from "../../events/events.js";
6
5
  import * as log from "../../log.js";
7
- import { parseScheduledEventContent } from "../../runtime/events.js";
8
6
  import { parseLocalTime } from "../../shared/local-time.js";
9
7
  import { errorMessage } from "../../shared/text-utils.js";
10
- import { getSubAgentRunManager } from "../../subagents/runs.js";
11
8
  import { createCycle, nextCycleId } from "../../tasks/cycle.js";
12
9
  import { renderStandardTaskBody, renderTaskDocument } from "../../tasks/ledger.js";
13
10
  import { parseTaskEventName } from "../../tasks/task-events.js";
@@ -128,10 +125,8 @@ export function describeTaskState(fields) {
128
125
  * validation matrix unit-testable against plain fakes.
129
126
  */
130
127
  export async function buildTicketContext(options, taskId, schedule, now = new Date()) {
131
- const runManager = getSubAgentRunManager(options.channelId);
132
- const jobs = await getChannelJobManager(options.channelId, createExecutor())
133
- .list()
134
- .catch(() => []);
128
+ const runManager = options.runManager;
129
+ const jobs = await options.jobManager.list().catch(() => []);
135
130
  const events = await readChannelEvents(options);
136
131
  return {
137
132
  now,
@@ -216,7 +211,7 @@ export async function cleanupTaskEvents(options, id) {
216
211
  export async function assertVerificationHoldsForClose(options, document, id) {
217
212
  if (document.fields.verify !== "required")
218
213
  return;
219
- const runManager = getSubAgentRunManager(options.channelId);
214
+ const runManager = options.runManager;
220
215
  const reason = await completionVerificationBlockReason({
221
216
  channelDir: options.channelDir,
222
217
  taskId: id,
@@ -1,4 +1,6 @@
1
1
  import type { Static } from "typebox";
2
+ import type { ChannelJobManager } from "../../agent/job-manager.js";
3
+ import type { SubAgentRunManager } from "../../subagents/runs.js";
2
4
  import type { taskCloseSchema, taskCreateSchema, taskLogSchema, taskStepEndSchema, taskUpdateSchema } from "./schema.js";
3
5
  export interface TaskManageResult {
4
6
  action: "create" | "update" | "close" | "list" | "log" | "step_end";
@@ -31,6 +33,8 @@ export type TaskCloseRequest = Static<typeof taskCloseSchema>;
31
33
  export type TaskLogRequest = Static<typeof taskLogSchema>;
32
34
  export type TaskStepEndRequest = Static<typeof taskStepEndSchema>;
33
35
  export interface TaskManageToolOptions {
36
+ jobManager: ChannelJobManager;
37
+ runManager: SubAgentRunManager;
34
38
  workspaceDir: string;
35
39
  channelDir: string;
36
40
  channelId: string;
package/dist/tui/app.js CHANGED
@@ -7,22 +7,24 @@
7
7
  * preparation shares `prepareAppServices` with the DingTalk path.
8
8
  */
9
9
  import { userInfo } from "node:os";
10
- import { channelRunningJobLines } from "../agent/job-manager.js";
10
+ import { createJobRuntime } from "../agent/job-manager.js";
11
11
  import { createRunner } from "../agent/runner-factory.js";
12
+ import { prepareAppServices } from "../app-services.js";
12
13
  import { ensureChannelDir } from "../channel/channel-paths.js";
13
14
  import { ChannelStore } from "../channel/store.js";
14
15
  import { renderBuiltInHelp } from "../commands/catalog.js";
16
+ import { handleEventsCommand } from "../events/event-commands.js";
17
+ import { createExecutor } from "../executor.js";
15
18
  import * as log from "../log.js";
19
+ import { migrateMemoryMaintenanceStates } from "../memory/maintenance-migration.js";
16
20
  import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, printBootstrapSummary, readCliVersion, } from "../runtime/app-home.js";
17
- import { prepareAppServices } from "../runtime/bootstrap.js";
18
21
  import { finalDeliveryOf, progressStyleOf } from "../runtime/dingtalk.js";
19
- import { handleEventsCommand } from "../runtime/event-commands.js";
20
22
  import { handleProjectCommand } from "../runtime/project-commands.js";
21
23
  import { handleSkillsCommand } from "../runtime/skill-commands.js";
22
24
  import { handleSubagentsCommand } from "../runtime/subagent-commands.js";
23
25
  import { handleTasksCommand } from "../runtime/task-commands.js";
24
26
  import { flushSecurityLogs } from "../security/logger.js";
25
- import { getSubAgentRunManager } from "../subagents/runs.js";
27
+ import { createSubAgentRuntime } from "../subagents/runs.js";
26
28
  import { getUsageLedger } from "../usage/ledger.js";
27
29
  import { parseUsageMode, renderUsageReport } from "../usage/render.js";
28
30
  import { TUI_SLASH_COMMANDS } from "./commands.js";
@@ -99,9 +101,14 @@ export async function runTuiApp(options) {
99
101
  const { settingsManager } = prepareAppServices(paths);
100
102
  log.configureLogging(settingsManager.getLoggingSettings());
101
103
  log.logStartup(paths.workspaceDir);
104
+ await migrateMemoryMaintenanceStates(paths.appHomeDir);
102
105
  const channelDir = ensureChannelDir(paths.workspaceDir, channelId);
103
106
  const store = new ChannelStore({ workingDir: paths.workspaceDir });
107
+ const jobs = createJobRuntime(createExecutor());
108
+ const runs = createSubAgentRuntime();
104
109
  const buildRunner = () => createRunner(channelId, channelDir, {
110
+ jobManager: jobs.get(channelId),
111
+ runManager: runs.get(channelId),
105
112
  appHomeDir: paths.appHomeDir,
106
113
  authConfigPath: paths.authConfigPath,
107
114
  modelsConfigPath: paths.modelsConfigPath,
@@ -139,7 +146,12 @@ export async function runTuiApp(options) {
139
146
  workspaceDir: paths.workspaceDir,
140
147
  channelId,
141
148
  }),
142
- runSubagents: (args) => handleSubagentsCommand({ args, channelId, discovery: runner.getSubAgentDiscoverySnapshot() }),
149
+ runSubagents: (args) => handleSubagentsCommand({
150
+ runManager: runs.get(channelId),
151
+ args,
152
+ channelId,
153
+ discovery: runner.getSubAgentDiscoverySnapshot(),
154
+ }),
143
155
  runSkills: (args) => handleSkillsCommand({ args, workspaceDir: paths.workspaceDir, appHomeDir: paths.appHomeDir, channelId }),
144
156
  runProject: (args) => handleProjectCommand({
145
157
  args,
@@ -149,11 +161,12 @@ export async function runTuiApp(options) {
149
161
  actor: "tui-command",
150
162
  isBusy: () => runner.isBusy(),
151
163
  listActiveBlockers: () => [
152
- ...getSubAgentRunManager(channelId)
164
+ ...runs
165
+ .get(channelId)
153
166
  .list()
154
167
  .filter((record) => record.status === "running")
155
168
  .map((record) => `subagent run \`${record.runId}\` (${record.agent})`),
156
- ...channelRunningJobLines(channelId),
169
+ ...jobs.runningLines(channelId),
157
170
  ],
158
171
  onScopeChanged: async () => {
159
172
  await runner.dispose();
@@ -172,6 +185,8 @@ export async function runTuiApp(options) {
172
185
  }
173
186
  finally {
174
187
  await runner.dispose();
188
+ runs.stop();
189
+ jobs.stop();
175
190
  await waitForStorageFlush(Promise.allSettled([store.close(), getUsageLedger().flush?.() ?? Promise.resolve(), flushSecurityLogs()]));
176
191
  await waitForStorageFlush(log.flushLogging());
177
192
  }
@@ -1,4 +1,4 @@
1
- import { clampInteger } from "../shared/numeric.js";
1
+ import { clampInteger } from "../shared/format.js";
2
2
  export function resolveWebSearchRequest(config, query, count) {
3
3
  return {
4
4
  query: query.trim(),