operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.21

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 (289) hide show
  1. package/dist/agent/agent.d.ts +8 -7
  2. package/dist/agent/compose-hooks.d.ts +10 -1
  3. package/dist/agent/compose-hooks.js +61 -6
  4. package/dist/agent/concurrency.js +1 -1
  5. package/dist/agent/context-report.d.ts +2 -2
  6. package/dist/agent/durable-state.d.ts +22 -0
  7. package/dist/agent/durable-state.js +54 -0
  8. package/dist/agent/index.d.ts +2 -2
  9. package/dist/agent/index.js +1 -1
  10. package/dist/agent/instruction-context.d.ts +6 -6
  11. package/dist/agent/instruction-context.js +23 -23
  12. package/dist/agent/profile-builtins.js +1 -1
  13. package/dist/agent/run-support.d.ts +1 -1
  14. package/dist/agent/run-support.js +6 -5
  15. package/dist/agent/runner.d.ts +25 -22
  16. package/dist/agent/runner.js +217 -121
  17. package/dist/agent/session.d.ts +262 -156
  18. package/dist/agent/session.js +590 -418
  19. package/dist/agent/subagent-tools.js +3 -3
  20. package/dist/agent/subagent.js +28 -13
  21. package/dist/agent/toolset.d.ts +1 -0
  22. package/dist/agent/toolset.js +13 -7
  23. package/dist/agent/workflow/journal.d.ts +2 -2
  24. package/dist/agent/workflow/journal.js +2 -2
  25. package/dist/agent/workflow/manager.d.ts +1 -1
  26. package/dist/agent/workflow/manager.js +1 -1
  27. package/dist/agent/workflow/prompt.js +2 -2
  28. package/dist/agent/workflow/sandbox.d.ts +1 -1
  29. package/dist/agent/workflow/sandbox.js +1 -1
  30. package/dist/agent/workflow/tool.js +30 -43
  31. package/dist/agent/worktree.d.ts +8 -8
  32. package/dist/agent/worktree.js +15 -15
  33. package/dist/capabilities/assembler.d.ts +29 -5
  34. package/dist/capabilities/assembler.js +85 -9
  35. package/dist/capabilities/background/code-task.d.ts +43 -0
  36. package/dist/capabilities/background/code-task.js +75 -0
  37. package/dist/capabilities/background/command-task.d.ts +9 -2
  38. package/dist/capabilities/background/command-task.js +22 -6
  39. package/dist/capabilities/background/index.d.ts +6 -1
  40. package/dist/capabilities/background/index.js +26 -20
  41. package/dist/capabilities/background/manager.d.ts +57 -1
  42. package/dist/capabilities/background/manager.js +210 -45
  43. package/dist/capabilities/background/persist-disk.d.ts +1 -1
  44. package/dist/capabilities/background/persist-disk.js +1 -1
  45. package/dist/capabilities/background/persist.js +4 -2
  46. package/dist/capabilities/background/projections.d.ts +16 -0
  47. package/dist/capabilities/background/projections.js +86 -0
  48. package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
  49. package/dist/capabilities/background/stall-watchdog.js +85 -0
  50. package/dist/capabilities/background/task.d.ts +8 -7
  51. package/dist/capabilities/background/tools.js +33 -7
  52. package/dist/capabilities/capability-data.d.ts +52 -0
  53. package/dist/capabilities/capability-data.js +88 -0
  54. package/dist/capabilities/capability-state.d.ts +2 -4
  55. package/dist/capabilities/capability-state.js +5 -23
  56. package/dist/capabilities/capability.d.ts +203 -38
  57. package/dist/capabilities/compaction/index.js +10 -4
  58. package/dist/capabilities/compaction/service.d.ts +20 -5
  59. package/dist/capabilities/compaction/service.js +27 -11
  60. package/dist/capabilities/goal/goal-store.d.ts +76 -12
  61. package/dist/capabilities/goal/goal-store.js +137 -53
  62. package/dist/capabilities/goal/index.d.ts +1 -1
  63. package/dist/capabilities/goal/index.js +30 -7
  64. package/dist/capabilities/index.d.ts +9 -6
  65. package/dist/capabilities/index.js +4 -3
  66. package/dist/capabilities/plan/index.js +22 -5
  67. package/dist/capabilities/plan/plan-mode.d.ts +30 -9
  68. package/dist/capabilities/plan/plan-mode.js +57 -32
  69. package/dist/capabilities/plan/tools.js +1 -1
  70. package/dist/capabilities/skills/flow-provider.js +3 -3
  71. package/dist/capabilities/skills/index.d.ts +13 -1
  72. package/dist/capabilities/skills/index.js +30 -21
  73. package/dist/capabilities/skills/parser.d.ts +2 -2
  74. package/dist/capabilities/skills/parser.js +3 -3
  75. package/dist/capabilities/skills/registry.d.ts +5 -6
  76. package/dist/capabilities/skills/registry.js +6 -9
  77. package/dist/capabilities/skills/scanner.d.ts +3 -3
  78. package/dist/capabilities/skills/scanner.js +14 -14
  79. package/dist/capabilities/skills/service.d.ts +2 -1
  80. package/dist/capabilities/skills/service.js +3 -3
  81. package/dist/capabilities/skills/skill-tool.d.ts +2 -0
  82. package/dist/capabilities/skills/skill-tool.js +1 -1
  83. package/dist/capabilities/task/index.js +2 -1
  84. package/dist/capabilities/task/persist-disk.d.ts +1 -1
  85. package/dist/capabilities/task/persist-disk.js +1 -1
  86. package/dist/capabilities/task/persist.js +1 -1
  87. package/dist/capabilities/todo/index.js +11 -6
  88. package/dist/capabilities/todo/injector.js +2 -1
  89. package/dist/capabilities/todo/todo-store.d.ts +28 -7
  90. package/dist/capabilities/todo/todo-store.js +44 -11
  91. package/dist/capabilities/todo/tools.js +8 -3
  92. package/dist/capabilities/tool-provider.d.ts +3 -3
  93. package/dist/capabilities/user-hooks/engine.d.ts +3 -3
  94. package/dist/capabilities/user-hooks/engine.js +7 -7
  95. package/dist/capabilities/user-hooks/index.js +2 -1
  96. package/dist/capabilities/workflow/index.d.ts +5 -3
  97. package/dist/capabilities/workflow/index.js +3 -2
  98. package/dist/commands/index.js +34 -32
  99. package/dist/config/index.d.ts +1 -1
  100. package/dist/config/provider-manager.js +0 -28
  101. package/dist/config/schema.d.ts +53 -4
  102. package/dist/config/schema.js +53 -1
  103. package/dist/events/events.d.ts +43 -11
  104. package/dist/events/events.js +1 -0
  105. package/dist/events/index.d.ts +2 -2
  106. package/dist/events/index.js +1 -1
  107. package/dist/events/projection.d.ts +49 -1
  108. package/dist/events/projection.js +144 -19
  109. package/dist/events/publisher.js +2 -21
  110. package/dist/home.d.ts +1 -1
  111. package/dist/home.js +1 -1
  112. package/dist/index.d.ts +3 -2
  113. package/dist/index.js +2 -1
  114. package/dist/internal.d.ts +5 -2
  115. package/dist/internal.js +5 -2
  116. package/dist/llm/define-model.d.ts +4 -0
  117. package/dist/llm/define-model.js +63 -25
  118. package/dist/llm/index.d.ts +1 -0
  119. package/dist/llm/index.js +1 -0
  120. package/dist/llm/model.d.ts +2 -0
  121. package/dist/llm/provider.d.ts +17 -0
  122. package/dist/llm/provider.js +14 -0
  123. package/dist/llm/retry.js +1 -1
  124. package/dist/loop/context.d.ts +21 -1
  125. package/dist/loop/context.js +47 -9
  126. package/dist/loop/events.d.ts +5 -1
  127. package/dist/loop/index.d.ts +2 -2
  128. package/dist/loop/index.js +1 -1
  129. package/dist/loop/interruption.d.ts +9 -4
  130. package/dist/loop/interruption.js +11 -25
  131. package/dist/loop/run-turn.d.ts +16 -3
  132. package/dist/loop/run-turn.js +13 -4
  133. package/dist/loop/steer.d.ts +78 -12
  134. package/dist/loop/steer.js +101 -38
  135. package/dist/loop/tool-call.d.ts +13 -2
  136. package/dist/loop/tool-call.js +135 -5
  137. package/dist/loop/turn-step.d.ts +13 -2
  138. package/dist/loop/turn-step.js +29 -7
  139. package/dist/loop/types.d.ts +6 -0
  140. package/dist/mcp/auth-tool.d.ts +3 -1
  141. package/dist/mcp/auth-tool.js +2 -2
  142. package/dist/mcp/capability.d.ts +13 -0
  143. package/dist/mcp/capability.js +36 -17
  144. package/dist/mcp/config-loader.d.ts +5 -5
  145. package/dist/mcp/config-loader.js +17 -17
  146. package/dist/mcp/credentials.d.ts +35 -0
  147. package/dist/mcp/credentials.js +2 -0
  148. package/dist/mcp/filter.d.ts +2 -2
  149. package/dist/mcp/index.d.ts +4 -3
  150. package/dist/mcp/index.js +1 -1
  151. package/dist/mcp/manager.d.ts +108 -6
  152. package/dist/mcp/manager.js +262 -18
  153. package/dist/mcp/oauth/callback-server.d.ts +10 -1
  154. package/dist/mcp/oauth/callback-server.js +82 -16
  155. package/dist/mcp/oauth/index.d.ts +2 -2
  156. package/dist/mcp/oauth/provider.d.ts +18 -0
  157. package/dist/mcp/oauth/provider.js +31 -1
  158. package/dist/mcp/oauth/service.d.ts +9 -3
  159. package/dist/mcp/oauth/service.js +29 -4
  160. package/dist/mcp/sdk-transport.js +1 -1
  161. package/dist/mcp/server.js +1 -1
  162. package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
  163. package/dist/permission/auto-approver/prompts-data.js +1 -1
  164. package/dist/permission/manager.d.ts +5 -3
  165. package/dist/permission/manager.js +7 -3
  166. package/dist/permission/policies.d.ts +2 -2
  167. package/dist/permission/policies.js +4 -4
  168. package/dist/plugins/fields.d.ts +14 -0
  169. package/dist/plugins/fields.js +30 -0
  170. package/dist/plugins/hooks.d.ts +2 -2
  171. package/dist/plugins/hooks.js +12 -12
  172. package/dist/plugins/index.js +1 -0
  173. package/dist/plugins/manager.d.ts +8 -3
  174. package/dist/plugins/manager.js +18 -7
  175. package/dist/plugins/manifest.d.ts +2 -2
  176. package/dist/plugins/manifest.js +101 -91
  177. package/dist/plugins/marketplace.js +76 -57
  178. package/dist/plugins/store.d.ts +3 -3
  179. package/dist/plugins/store.js +6 -6
  180. package/dist/protocol/index.d.ts +1 -1
  181. package/dist/store/catalog-store.d.ts +4 -1
  182. package/dist/store/catalog-store.js +5 -1
  183. package/dist/store/checkpointing-store.d.ts +41 -0
  184. package/dist/store/checkpointing-store.js +86 -0
  185. package/dist/store/disk-store.d.ts +8 -0
  186. package/dist/store/disk-store.js +127 -5
  187. package/dist/store/index.d.ts +3 -2
  188. package/dist/store/index.js +2 -1
  189. package/dist/store/log-store.d.ts +9 -1
  190. package/dist/store/log-store.js +68 -4
  191. package/dist/store/migrate.d.ts +8 -2
  192. package/dist/store/migrate.js +9 -2
  193. package/dist/store/origin.d.ts +31 -6
  194. package/dist/store/origin.js +0 -14
  195. package/dist/store/pg.d.ts +1 -0
  196. package/dist/store/pg.js +37 -2
  197. package/dist/store/redis.d.ts +1 -0
  198. package/dist/store/redis.js +30 -0
  199. package/dist/store/repository.d.ts +13 -1
  200. package/dist/store/repository.js +45 -2
  201. package/dist/store/session-catalog.d.ts +4 -0
  202. package/dist/store/session-catalog.js +6 -0
  203. package/dist/store/storage.js +3 -0
  204. package/dist/store/store.d.ts +97 -34
  205. package/dist/store/store.js +64 -10
  206. package/dist/telemetry/appender.d.ts +43 -0
  207. package/dist/telemetry/appender.js +46 -0
  208. package/dist/telemetry/events.d.ts +142 -0
  209. package/dist/telemetry/events.js +141 -0
  210. package/dist/telemetry/index.d.ts +10 -0
  211. package/dist/telemetry/index.js +6 -0
  212. package/dist/telemetry/projection.d.ts +23 -0
  213. package/dist/telemetry/projection.js +185 -0
  214. package/dist/telemetry/redact.d.ts +20 -0
  215. package/dist/telemetry/redact.js +40 -0
  216. package/dist/telemetry/service.d.ts +49 -0
  217. package/dist/telemetry/service.js +137 -0
  218. package/dist/testing.d.ts +58 -0
  219. package/dist/testing.js +123 -0
  220. package/dist/tool/background.d.ts +9 -6
  221. package/dist/tool/background.js +7 -1
  222. package/dist/tool/builtin/ask-user-question.js +6 -5
  223. package/dist/tool/builtin/bash.d.ts +6 -0
  224. package/dist/tool/builtin/bash.js +79 -42
  225. package/dist/tool/builtin/edit.js +82 -109
  226. package/dist/tool/builtin/glob.js +13 -13
  227. package/dist/tool/builtin/grep.js +13 -13
  228. package/dist/tool/builtin/read.js +25 -15
  229. package/dist/tool/builtin/write.js +49 -33
  230. package/dist/tool/define.d.ts +14 -8
  231. package/dist/tool/define.js +8 -2
  232. package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +37 -37
  233. package/dist/tool/{machine-base.js → environment-base.js} +45 -119
  234. package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +9 -8
  235. package/dist/tool/{machine-local.js → environment-local.js} +60 -81
  236. package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +9 -9
  237. package/dist/tool/{machine-null.js → environment-null.js} +9 -9
  238. package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +33 -18
  239. package/dist/tool/{machine-ssh.js → environment-ssh.js} +118 -149
  240. package/dist/tool/{machine.d.ts → environment.d.ts} +53 -82
  241. package/dist/tool/environment.js +2 -0
  242. package/dist/tool/file-freshness.d.ts +33 -19
  243. package/dist/tool/file-freshness.js +39 -30
  244. package/dist/tool/filesystem-tools.d.ts +1 -1
  245. package/dist/tool/filesystem-tools.js +1 -1
  246. package/dist/tool/git-context.d.ts +2 -2
  247. package/dist/tool/git-context.js +8 -8
  248. package/dist/tool/index.d.ts +12 -12
  249. package/dist/tool/index.js +12 -10
  250. package/dist/tool/policies/path-access.d.ts +4 -4
  251. package/dist/tool/policies/path-access.js +12 -12
  252. package/dist/tool/questions.d.ts +8 -0
  253. package/dist/tool/search/catalog.d.ts +37 -0
  254. package/dist/tool/search/catalog.js +182 -0
  255. package/dist/tool/search/deferral.d.ts +3 -2
  256. package/dist/tool/search/loaded.d.ts +32 -0
  257. package/dist/tool/search/loaded.js +96 -0
  258. package/dist/tool/search/search-tool.d.ts +2 -6
  259. package/dist/tool/search/search-tool.js +16 -15
  260. package/dist/tool/shell-env.js +4 -0
  261. package/dist/tool/support/bash-paths.js +38 -7
  262. package/dist/tool/support/{machine-ops.d.ts → environment-ops.d.ts} +12 -14
  263. package/dist/tool/support/{machine-ops.js → environment-ops.js} +21 -2
  264. package/dist/tool/support/git-worktree.d.ts +3 -3
  265. package/dist/tool/support/git-worktree.js +6 -6
  266. package/dist/tool/support/rg-locator.d.ts +6 -6
  267. package/dist/tool/support/rg-locator.js +6 -6
  268. package/dist/tool/support/ripgrep-run.d.ts +5 -5
  269. package/dist/tool/support/ripgrep-run.js +3 -3
  270. package/dist/tool/support/tool-path.d.ts +3 -3
  271. package/dist/tool/support/tool-path.js +7 -7
  272. package/dist/tool/types.d.ts +54 -10
  273. package/dist/tool/web/fetch-url.js +1 -1
  274. package/dist/tool/web/web-search.js +1 -1
  275. package/dist/tool/workspace-spec.d.ts +3 -3
  276. package/dist/tool/workspace-spec.js +27 -27
  277. package/dist/tracing/bridge.d.ts +9 -1
  278. package/dist/tracing/bridge.js +307 -77
  279. package/dist/tracing/index.d.ts +2 -2
  280. package/dist/tracing/otel.d.ts +28 -1
  281. package/dist/tracing/otel.js +150 -38
  282. package/dist/tracing/processor.d.ts +22 -0
  283. package/dist/tracing/processor.js +2 -0
  284. package/dist/tracing/spans.d.ts +54 -0
  285. package/dist/tracing/spans.js +5 -0
  286. package/package.json +6 -2
  287. package/dist/tool/machine.js +0 -15
  288. package/dist/tool/search/activation.d.ts +0 -13
  289. package/dist/tool/search/activation.js +0 -31
@@ -6,7 +6,7 @@ export function flowSkillToolName(skillName) {
6
6
  const suffix = skillName.replace(/[^a-zA-Z0-9_-]+/g, "_").toLowerCase() || "skill";
7
7
  return `skill_${suffix}`;
8
8
  }
9
- function flowSkillTool(skill, registry, executor) {
9
+ function flowSkillTool(skill, registry, executor, sessionId) {
10
10
  const toolName = flowSkillToolName(skill.name);
11
11
  return defineTool({
12
12
  name: toolName,
@@ -34,7 +34,7 @@ function flowSkillTool(skill, registry, executor) {
34
34
  isError: true,
35
35
  };
36
36
  }
37
- const instructions = registry.renderSkillPrompt(skill, "");
37
+ const instructions = registry.renderSkillPrompt(skill, "", sessionId);
38
38
  const output = await executor({ skill, instructions, input: args.input, signal: ctx.signal });
39
39
  return { content: [{ type: "text", text: output }], details: { skill: skill.name, source: skill.source } };
40
40
  },
@@ -44,7 +44,7 @@ function flowSkillTool(skill, registry, executor) {
44
44
  export function flowSkillProvider(registry, executor) {
45
45
  return {
46
46
  id: "skill-flow",
47
- listTools: () => registry.listFlowSkills().map((skill) => flowSkillTool(skill, registry, executor)),
47
+ listTools: (ctx) => registry.listFlowSkills().map((skill) => flowSkillTool(skill, registry, executor, ctx.sessionId)),
48
48
  };
49
49
  }
50
50
  //# sourceMappingURL=flow-provider.js.map
@@ -1,9 +1,10 @@
1
1
  import type { Capability } from "../capability.ts";
2
+ import type { Environment } from "../../tool/environment.ts";
2
3
  import { SkillRegistry } from "./registry.ts";
3
4
  import type { FlowSkillExecutor, SkillDefinition, SkillRoot } from "./types.ts";
4
5
  export type { SkillRegistryOptions } from "./registry.ts";
5
6
  export { SkillRegistry, SkillNotFoundError } from "./registry.ts";
6
- export { parseSkillText, parseSkillFromMachine, parseFrontmatter, expandSkillParameters, skillArgumentNames, SkillParseError, FrontmatterError, UnsupportedSkillTypeError, } from "./parser.ts";
7
+ export { parseSkillText, parseSkillFromEnvironment, parseFrontmatter, expandSkillParameters, skillArgumentNames, SkillParseError, FrontmatterError, UnsupportedSkillTypeError, } from "./parser.ts";
7
8
  export { discoverSkills, resolveSkillRoots } from "./scanner.ts";
8
9
  export type { ResolveSkillRootsOptions, DiscoverSkillsOptions } from "./scanner.ts";
9
10
  export { skillTool, MAX_SKILL_QUERY_DEPTH, NestedSkillTooDeepError } from "./skill-tool.ts";
@@ -14,7 +15,11 @@ export type { ActivateSkillRequest, SkillActivationResult, SkillActivationTrigge
14
15
  export { normalizeSkillName, isInlineSkillType, isFlowSkillType, isUserActivatableSkillType, isSupportedSkillType, summarizeSkill, } from "./types.ts";
15
16
  export type { SkillCatalog, SkillDefinition, SkillMetadata, SkillSource, SkillSummary, SkillRoot, SkillPluginContext, SkippedSkill, FlowSkillExecutor, FlowSkillRequest, } from "./types.ts";
16
17
  export interface SkillsOptions {
18
+ /** A pre-built registry — e.g. the harness's shared one (`HarnessParts.skillRegistry`). */
17
19
  readonly registry?: SkillRegistry;
20
+ /** `false` = the registry is already loaded (the harness scanned it once); skip the per-session
21
+ * scan and only bind this session to it. Default `true`. */
22
+ readonly scan?: boolean;
18
23
  readonly roots?: readonly SkillRoot[];
19
24
  /**
20
25
  * Additional skill roots resolved lazily at session-open (merged after `roots`). Use this for
@@ -39,5 +44,12 @@ export interface SkillsOptions {
39
44
  readonly flowExecutor?: FlowSkillExecutor;
40
45
  readonly onWarning?: (message: string, cause?: unknown) => void;
41
46
  }
47
+ /**
48
+ * Scan the skill roots into `registry` — the static roots, the lazily-provided ones (e.g. enabled
49
+ * plugins' skill dirs), and the default project/user roots when asked. Called per session by
50
+ * `skillsCapability` (unless `scan: false`), or once per process by a host that shares one
51
+ * registry across all its sessions.
52
+ */
53
+ export declare function loadSkillRoots(environment: Environment, registry: SkillRegistry, options?: Omit<SkillsOptions, "registry" | "scan" | "flowExecutor" | "onWarning">): Promise<void>;
42
54
  export declare function skillsCapability(options?: SkillsOptions): Capability;
43
55
  //# sourceMappingURL=index.d.ts.map
@@ -5,42 +5,51 @@ import { flowSkillProvider } from "./flow-provider.js";
5
5
  import { SkillCatalogInjector } from "./injector.js";
6
6
  import { SkillsService } from "./service.js";
7
7
  export { SkillRegistry, SkillNotFoundError } from "./registry.js";
8
- export { parseSkillText, parseSkillFromMachine, parseFrontmatter, expandSkillParameters, skillArgumentNames, SkillParseError, FrontmatterError, UnsupportedSkillTypeError, } from "./parser.js";
8
+ export { parseSkillText, parseSkillFromEnvironment, parseFrontmatter, expandSkillParameters, skillArgumentNames, SkillParseError, FrontmatterError, UnsupportedSkillTypeError, } from "./parser.js";
9
9
  export { discoverSkills, resolveSkillRoots } from "./scanner.js";
10
10
  export { skillTool, MAX_SKILL_QUERY_DEPTH, NestedSkillTooDeepError } from "./skill-tool.js";
11
11
  export { flowSkillProvider, flowSkillToolName } from "./flow-provider.js";
12
12
  export { SkillCatalogInjector } from "./injector.js";
13
13
  export { SkillsService, UnsupportedSkillActivationError } from "./service.js";
14
14
  export { normalizeSkillName, isInlineSkillType, isFlowSkillType, isUserActivatableSkillType, isSupportedSkillType, summarizeSkill, } from "./types.js";
15
+ /**
16
+ * Scan the skill roots into `registry` — the static roots, the lazily-provided ones (e.g. enabled
17
+ * plugins' skill dirs), and the default project/user roots when asked. Called per session by
18
+ * `skillsCapability` (unless `scan: false`), or once per process by a host that shares one
19
+ * registry across all its sessions.
20
+ */
21
+ export async function loadSkillRoots(environment, registry, options = {}) {
22
+ for (const skill of options.builtinSkills ?? [])
23
+ registry.registerBuiltinSkill(skill);
24
+ const dynamic = options.dynamicRoots ? await options.dynamicRoots() : [];
25
+ const explicitRoots = [...(options.roots ?? []), ...dynamic];
26
+ const roots = await resolveSkillRoots(environment, {
27
+ ...(explicitRoots.length > 0 ? { explicitRoots } : {}),
28
+ ...(options.includeDefaultRoots === true ? { includeDefaults: true } : {}),
29
+ // Default the project root to the environment's working directory, so `<cwd>/.agents/skills`
30
+ // is scanned for the directory this environment actually operates.
31
+ projectDir: options.projectDir ?? environment.getcwd(),
32
+ ...(options.userHomeDir !== undefined ? { userHomeDir: options.userHomeDir } : {}),
33
+ ...(options.builtinDir !== undefined ? { builtinDir: options.builtinDir } : {}),
34
+ ...(options.extraDirs !== undefined ? { extraDirs: options.extraDirs } : {}),
35
+ });
36
+ await registry.loadRoots(environment, roots);
37
+ }
15
38
  export function skillsCapability(options = {}) {
16
39
  const registry = options.registry ?? new SkillRegistry({ onWarning: options.onWarning });
17
40
  const service = new SkillsService(registry);
41
+ let sessionId;
18
42
  return {
19
43
  name: "skills",
20
- tools: [skillTool(registry)],
44
+ contract: "detachable",
45
+ tools: [skillTool(registry, { sessionId: () => sessionId })],
21
46
  toolProviders: [flowSkillProvider(registry, options.flowExecutor)],
22
47
  injectors: [new SkillCatalogInjector(registry)],
23
48
  service,
24
49
  openSession: async (ctx) => {
25
- registry.setSessionId(ctx.sessionId);
26
- for (const skill of options.builtinSkills ?? [])
27
- registry.registerBuiltinSkill(skill);
28
- // Static roots + any lazily-provided ones (e.g. enabled plugins' skill dirs). The provider
29
- // runs per session-open so it reflects the current set even though the harness is shared.
30
- const dynamic = options.dynamicRoots ? await options.dynamicRoots() : [];
31
- const explicitRoots = [...(options.roots ?? []), ...dynamic];
32
- const roots = await resolveSkillRoots(ctx.machine, {
33
- ...(explicitRoots.length > 0 ? { explicitRoots } : {}),
34
- ...(options.includeDefaultRoots === true ? { includeDefaults: true } : {}),
35
- // Default the project root to the session's working directory so
36
- // `<cwd>/.agents/skills` is scanned per-session (the harness is shared,
37
- // so this can't be a static option).
38
- projectDir: options.projectDir ?? ctx.machine.getcwd(),
39
- ...(options.userHomeDir !== undefined ? { userHomeDir: options.userHomeDir } : {}),
40
- ...(options.builtinDir !== undefined ? { builtinDir: options.builtinDir } : {}),
41
- ...(options.extraDirs !== undefined ? { extraDirs: options.extraDirs } : {}),
42
- });
43
- await registry.loadRoots(ctx.machine, roots);
50
+ sessionId = ctx.sessionId;
51
+ if (options.scan !== false)
52
+ await loadSkillRoots(ctx.environment, registry, options);
44
53
  service.attach({ sessionId: ctx.sessionId, events: ctx.events, steer: ctx.steer });
45
54
  },
46
55
  };
@@ -1,4 +1,4 @@
1
- import type { Machine } from "../../tool/machine.ts";
1
+ import type { Environment } from "../../tool/environment.ts";
2
2
  import type { SkillDefinition, SkillMetadata, SkillSource } from "./types.ts";
3
3
  export declare class FrontmatterError extends Error {
4
4
  constructor(message: string, cause?: unknown);
@@ -28,7 +28,7 @@ export interface ParsedFrontmatter {
28
28
  readonly data: Record<string, unknown> | null;
29
29
  readonly body: string;
30
30
  }
31
- export declare function parseSkillFromMachine(machine: Machine, options: ParseSkillOptions): Promise<SkillDefinition>;
31
+ export declare function parseSkillFromEnvironment(environment: Environment, options: ParseSkillOptions): Promise<SkillDefinition>;
32
32
  export declare function parseFrontmatter(text: string): ParsedFrontmatter;
33
33
  export declare function parseSkillText(options: ParseSkillTextOptions): SkillDefinition;
34
34
  export declare function expandSkillParameters(body: string, rawArgs: string, context: SkillExpandContext): string;
@@ -1,6 +1,6 @@
1
1
  import path from "pathe";
2
2
  import { isSupportedSkillType } from "./types.js";
3
- import { readTextFile } from "../../tool/support/machine-ops.js";
3
+ import { readTextFile } from "../../tool/support/environment-ops.js";
4
4
  export class FrontmatterError extends Error {
5
5
  constructor(message, cause) {
6
6
  super(message);
@@ -33,10 +33,10 @@ const METADATA_ALIASES = {
33
33
  "disable-model-invocation": "disableModelInvocation",
34
34
  disable_model_invocation: "disableModelInvocation",
35
35
  };
36
- export async function parseSkillFromMachine(machine, options) {
36
+ export async function parseSkillFromEnvironment(environment, options) {
37
37
  let text;
38
38
  try {
39
- text = await readTextFile(machine, options.skillMdPath);
39
+ text = await readTextFile(environment, options.skillMdPath);
40
40
  }
41
41
  catch (error) {
42
42
  throw new SkillParseError(`Failed to read ${options.skillMdPath}`, error);
@@ -1,4 +1,4 @@
1
- import type { Machine } from "../../tool/machine.ts";
1
+ import type { Environment } from "../../tool/environment.ts";
2
2
  import type { SkillCatalog, SkillDefinition, SkillRoot, SkippedSkill } from "./types.ts";
3
3
  export declare class SkillNotFoundError extends Error {
4
4
  readonly skillName: string;
@@ -6,17 +6,14 @@ export declare class SkillNotFoundError extends Error {
6
6
  }
7
7
  export interface SkillRegistryOptions {
8
8
  readonly onWarning?: (message: string, cause?: unknown) => void;
9
- readonly sessionId?: string;
10
9
  }
11
10
  export declare class SkillRegistry implements SkillCatalog {
12
11
  private readonly byName;
13
12
  private readonly roots;
14
13
  private readonly skipped;
15
14
  private readonly onWarning;
16
- private sessionId?;
17
15
  constructor(options?: SkillRegistryOptions);
18
- setSessionId(sessionId: string): void;
19
- loadRoots(machine: Machine, roots: readonly SkillRoot[]): Promise<void>;
16
+ loadRoots(environment: Environment, roots: readonly SkillRoot[]): Promise<void>;
20
17
  registerBuiltinSkill(skill: SkillDefinition): void;
21
18
  register(skill: SkillDefinition, options?: {
22
19
  readonly replace?: boolean;
@@ -27,7 +24,9 @@ export declare class SkillRegistry implements SkillCatalog {
27
24
  listFlowSkills(): readonly SkillDefinition[];
28
25
  getSkillRoots(): readonly string[];
29
26
  getSkippedByPolicy(): readonly SkippedSkill[];
30
- renderSkillPrompt(skill: SkillDefinition, rawArgs: string): string;
27
+ /** `sessionId` fills `${SESSION_ID}`: the registry is shareable across sessions, so the
28
+ * caller (a session's tool or service) supplies its own. */
29
+ renderSkillPrompt(skill: SkillDefinition, rawArgs: string, sessionId?: string): string;
31
30
  getModelSkillListing(): string;
32
31
  }
33
32
  //# sourceMappingURL=registry.d.ts.map
@@ -15,20 +15,15 @@ export class SkillRegistry {
15
15
  roots = [];
16
16
  skipped = [];
17
17
  onWarning;
18
- sessionId;
19
18
  constructor(options = {}) {
20
19
  this.onWarning = options.onWarning ?? (() => { });
21
- this.sessionId = options.sessionId;
22
20
  }
23
- setSessionId(sessionId) {
24
- this.sessionId = sessionId;
25
- }
26
- async loadRoots(machine, roots) {
21
+ async loadRoots(environment, roots) {
27
22
  for (const root of roots) {
28
23
  if (!this.roots.includes(root.path))
29
24
  this.roots.push(root.path);
30
25
  }
31
- const skills = await discoverSkills(machine, {
26
+ const skills = await discoverSkills(environment, {
32
27
  roots,
33
28
  onWarning: this.onWarning,
34
29
  onSkippedByPolicy: (skill) => this.skipped.push(skill),
@@ -65,10 +60,12 @@ export class SkillRegistry {
65
60
  getSkippedByPolicy() {
66
61
  return [...this.skipped];
67
62
  }
68
- renderSkillPrompt(skill, rawArgs) {
63
+ /** `sessionId` fills `${SESSION_ID}`: the registry is shareable across sessions, so the
64
+ * caller (a session's tool or service) supplies its own. */
65
+ renderSkillPrompt(skill, rawArgs, sessionId) {
69
66
  const content = expandSkillParameters(skill.content, rawArgs, {
70
67
  skillDir: skill.dir,
71
- sessionId: this.sessionId,
68
+ sessionId,
72
69
  argumentNames: skillArgumentNames(skill.metadata),
73
70
  });
74
71
  const plugin = skill.plugin;
@@ -1,4 +1,4 @@
1
- import type { Machine } from "../../tool/machine.ts";
1
+ import type { Environment } from "../../tool/environment.ts";
2
2
  import type { SkillDefinition, SkillRoot, SkippedSkill } from "./types.ts";
3
3
  export interface ResolveSkillRootsOptions {
4
4
  readonly projectDir?: string;
@@ -21,6 +21,6 @@ export interface DiscoverSkillsOptions {
21
21
  readonly onSkippedByPolicy?: (skill: SkippedSkill) => void;
22
22
  readonly onDiscoveredSkill?: (skill: SkillDefinition) => void;
23
23
  }
24
- export declare function resolveSkillRoots(machine: Machine, options: ResolveSkillRootsOptions): Promise<readonly SkillRoot[]>;
25
- export declare function discoverSkills(machine: Machine, options: DiscoverSkillsOptions): Promise<readonly SkillDefinition[]>;
24
+ export declare function resolveSkillRoots(environment: Environment, options: ResolveSkillRootsOptions): Promise<readonly SkillRoot[]>;
25
+ export declare function discoverSkills(environment: Environment, options: DiscoverSkillsOptions): Promise<readonly SkillDefinition[]>;
26
26
  //# sourceMappingURL=scanner.d.ts.map
@@ -1,13 +1,13 @@
1
1
  import { homedir } from "node:os";
2
2
  import path from "pathe";
3
- import { SkillParseError, UnsupportedSkillTypeError, parseSkillFromMachine } from "./parser.js";
3
+ import { SkillParseError, UnsupportedSkillTypeError, parseSkillFromEnvironment } from "./parser.js";
4
4
  import { normalizeSkillName } from "./types.js";
5
5
  const PROJECT_SKILL_DIR = ".agents/skills";
6
6
  const USER_SKILL_DIR = ".agents/skills";
7
7
  const MAX_SKILL_SCAN_DEPTH = 8;
8
- async function statKind(machine, p) {
8
+ async function statKind(environment, p) {
9
9
  try {
10
- const kind = (await machine.fileInfo(p)).kind;
10
+ const kind = (await environment.fileInfo(p)).kind;
11
11
  if (kind === "dir")
12
12
  return "dir";
13
13
  if (kind === "file")
@@ -18,29 +18,29 @@ async function statKind(machine, p) {
18
18
  return "none";
19
19
  }
20
20
  }
21
- async function listDir(machine, p) {
21
+ async function listDir(environment, p) {
22
22
  // Sorted so first-wins collision resolution across siblings is deterministic.
23
- return (await machine.listDir(p)).toSorted((a, b) => a.name.localeCompare(b.name));
23
+ return (await environment.listDir(p)).toSorted((a, b) => a.name.localeCompare(b.name));
24
24
  }
25
25
  /**
26
26
  * The listing's kind, with symlinks resolved to what they point AT — a skills root full of
27
27
  * symlinked bundles is normal, and treating those as neither file nor dir would silently
28
28
  * hide them. Only `"symlink"` entries cost a stat; everything else is already decided.
29
29
  */
30
- async function resolveEntryKind(machine, dirPath, entry) {
30
+ async function resolveEntryKind(environment, dirPath, entry) {
31
31
  if (entry.kind === "dir")
32
32
  return "dir";
33
33
  if (entry.kind === "file")
34
34
  return "file";
35
35
  if (entry.kind !== "symlink")
36
36
  return "none";
37
- return statKind(machine, path.join(dirPath, entry.name));
37
+ return statKind(environment, path.join(dirPath, entry.name));
38
38
  }
39
- export async function resolveSkillRoots(machine, options) {
39
+ export async function resolveSkillRoots(environment, options) {
40
40
  const roots = [];
41
41
  const push = async (dir, source, plugin) => {
42
42
  const resolved = path.resolve(dir);
43
- if ((await statKind(machine, resolved)) !== "dir")
43
+ if ((await statKind(environment, resolved)) !== "dir")
44
44
  return;
45
45
  if (roots.some((root) => root.path === resolved))
46
46
  return;
@@ -62,7 +62,7 @@ export async function resolveSkillRoots(machine, options) {
62
62
  await push(options.builtinDir, "builtin");
63
63
  return roots;
64
64
  }
65
- export async function discoverSkills(machine, options) {
65
+ export async function discoverSkills(environment, options) {
66
66
  const warn = options.onWarning ?? (() => { });
67
67
  const skip = options.onSkippedByPolicy ?? (() => { });
68
68
  const byName = new Map();
@@ -73,7 +73,7 @@ export async function discoverSkills(machine, options) {
73
73
  */
74
74
  const parseSkill = async (skillMdPath, skillDirName, root) => {
75
75
  try {
76
- const parsed = await parseSkillFromMachine(machine, { skillMdPath, skillDirName, source: root.source });
76
+ const parsed = await parseSkillFromEnvironment(environment, { skillMdPath, skillDirName, source: root.source });
77
77
  return root.plugin === undefined ? parsed : { ...parsed, plugin: root.plugin };
78
78
  }
79
79
  catch (error) {
@@ -102,13 +102,13 @@ export async function discoverSkills(machine, options) {
102
102
  return [];
103
103
  let entries;
104
104
  try {
105
- entries = await listDir(machine, dirPath);
105
+ entries = await listDir(environment, dirPath);
106
106
  }
107
107
  catch (error) {
108
108
  warn(`Failed to read skill directory ${dirPath}`, error);
109
109
  return [];
110
110
  }
111
- const kinds = await Promise.all(entries.map((entry) => resolveEntryKind(machine, dirPath, entry)));
111
+ const kinds = await Promise.all(entries.map((entry) => resolveEntryKind(environment, dirPath, entry)));
112
112
  const dirNames = [];
113
113
  const fileNames = [];
114
114
  for (const [i, entry] of entries.entries()) {
@@ -119,7 +119,7 @@ export async function discoverSkills(machine, options) {
119
119
  }
120
120
  // A directory is a bundle iff it holds a SKILL.md. Probed for directories only — the old
121
121
  // scan asked this of every entry, including plain files, which can never answer yes.
122
- const bundleFlags = await Promise.all(dirNames.map(async (name) => (await statKind(machine, path.join(dirPath, name, "SKILL.md"))) === "file"));
122
+ const bundleFlags = await Promise.all(dirNames.map(async (name) => (await statKind(environment, path.join(dirPath, name, "SKILL.md"))) === "file"));
123
123
  const bundles = new Set(dirNames.filter((_, i) => bundleFlags[i]));
124
124
  const bundleSkills = await Promise.all([...bundles].map((name) => parseSkill(path.join(dirPath, name, "SKILL.md"), name, root)));
125
125
  // Flat `.md` skills count only at a root's top level; deeper `.md` files are payload.
@@ -16,7 +16,8 @@ export interface SkillActivationResult {
16
16
  readonly trigger: SkillActivationTrigger;
17
17
  readonly skillPath: string;
18
18
  readonly skillSource: SkillSource;
19
- readonly turnId: string | null;
19
+ /** Matches `steer.queued.steerId` and the consuming `message.appended.origin.steerId`. */
20
+ readonly steerId: string;
20
21
  }
21
22
  export declare class UnsupportedSkillActivationError extends Error {
22
23
  readonly skillName: string;
@@ -36,10 +36,10 @@ export class SkillsService {
36
36
  const activationId = randomUUID();
37
37
  const skillArgs = request.args ?? "";
38
38
  const trigger = request.trigger ?? "user-slash";
39
- const body = this.registry.renderSkillPrompt(skill, skillArgs);
39
+ const body = this.registry.renderSkillPrompt(skill, skillArgs, runtime.sessionId);
40
40
  const argsAttr = skillArgs.length > 0 ? ` args="${escapeXmlAttr(skillArgs)}"` : "";
41
41
  const wrapped = systemReminder(`<skill-loaded name="${escapeXmlAttr(skill.name)}"${argsAttr}>\n${body}\n</skill-loaded>`);
42
- const { wakeTurnId: turnId } = runtime.steer.steer(wrapped, { kind: "user" });
42
+ const { steerId } = runtime.steer.steer(wrapped, { kind: "user" });
43
43
  await runtime.events.emit({
44
44
  type: "skill.activated",
45
45
  address: request.address ?? "main",
@@ -58,7 +58,7 @@ export class SkillsService {
58
58
  trigger,
59
59
  skillPath: skill.path,
60
60
  skillSource: skill.source,
61
- turnId,
61
+ steerId,
62
62
  };
63
63
  }
64
64
  }
@@ -8,6 +8,8 @@ export declare class NestedSkillTooDeepError extends Error {
8
8
  }
9
9
  export interface SkillToolOptions {
10
10
  readonly initialQueryDepth?: number;
11
+ /** The session whose `${SESSION_ID}` a rendered skill expands to (the registry is shareable). */
12
+ readonly sessionId?: () => string | undefined;
11
13
  }
12
14
  export declare function skillTool(registry: SkillRegistry, options?: SkillToolOptions): Tool;
13
15
  //# sourceMappingURL=skill-tool.d.ts.map
@@ -51,7 +51,7 @@ export function skillTool(registry, options = {}) {
51
51
  return errorResult(`Skill "${skill.name}" is a flow skill — invoke it via its skill_${toToolSuffix(skill.name)} tool, not Skill.`);
52
52
  }
53
53
  const skillArgs = args.args ?? "";
54
- const body = registry.renderSkillPrompt(skill, skillArgs);
54
+ const body = registry.renderSkillPrompt(skill, skillArgs, options.sessionId?.());
55
55
  const argsAttr = skillArgs.length > 0 ? ` args="${escapeXmlAttr(skillArgs)}"` : "";
56
56
  return {
57
57
  content: [
@@ -18,9 +18,10 @@ export { taskCreateTool, taskUpdateTool, taskListTool, taskGetTool, renderTaskLi
18
18
  export function taskCapability(store = new TaskStore()) {
19
19
  return {
20
20
  name: "task",
21
+ contract: "detachable",
21
22
  tools: [taskCreateTool(store), taskUpdateTool(store), taskListTool(store), taskGetTool(store)],
22
- service: store,
23
23
  injectors: [new TaskListInjector(store)],
24
+ service: store,
24
25
  openSession: async (ctx) => {
25
26
  store.attach(makeTaskListPersistence(ctx.store));
26
27
  await store.load();
@@ -2,7 +2,7 @@ import { type Task, type TaskListPersistence } from "./persist.ts";
2
2
  /**
3
3
  * Disk-directory task list: one JSON file per task under `<sessionDir>/tasklist/<id>.json`,
4
4
  * co-located under the SessionStore's home (next
5
- * to `agents/`, `blobs/`, `tasks/`), off the Machine sandbox. Atomic writes (temp + rename)
5
+ * to `agents/`, `blobs/`, `tasks/`), off the Environment sandbox. Atomic writes (temp + rename)
6
6
  * so a crash mid-write never leaves a torn file. Single live loop per session ⇒ no file locking.
7
7
  */
8
8
  export declare class DiskTaskListPersistence implements TaskListPersistence {
@@ -7,7 +7,7 @@ const ID_RE = /^[A-Za-z0-9_-]+$/;
7
7
  /**
8
8
  * Disk-directory task list: one JSON file per task under `<sessionDir>/tasklist/<id>.json`,
9
9
  * co-located under the SessionStore's home (next
10
- * to `agents/`, `blobs/`, `tasks/`), off the Machine sandbox. Atomic writes (temp + rename)
10
+ * to `agents/`, `blobs/`, `tasks/`), off the Environment sandbox. Atomic writes (temp + rename)
11
11
  * so a crash mid-write never leaves a torn file. Single live loop per session ⇒ no file locking.
12
12
  */
13
13
  export class DiskTaskListPersistence {
@@ -35,7 +35,7 @@ export function isValidTask(value) {
35
35
  }
36
36
  // ── SessionStore KV backend ──────────────────────────────────────────────────
37
37
  // One key per task + an index + the high-water-mark, mirroring the background task store's KV
38
- // backend. Kept off the Machine (agent bookkeeping, per the cron/background rule).
38
+ // backend. Kept off the Environment (agent bookkeeping, per the cron/background rule).
39
39
  const INDEX_KEY = "tasklist:index";
40
40
  const HWM_KEY = "tasklist:hwm";
41
41
  const taskKey = (id) => `tasklist:task:${id}`;
@@ -1,4 +1,3 @@
1
- import { readSessionLog } from "../capability-state.js";
2
1
  import { TodoListInjector } from "./injector.js";
3
2
  import { TodoStore } from "./todo-store.js";
4
3
  import { todoListTool } from "./tools.js";
@@ -8,13 +7,19 @@ export { TodoListInjector } from "./injector.js";
8
7
  export function todoCapability(store = new TodoStore()) {
9
8
  return {
10
9
  name: "todo",
10
+ contract: "detachable",
11
11
  tools: [todoListTool(store)],
12
- service: store,
13
12
  injectors: [new TodoListInjector(store)],
14
- // Rebuild the list from the session log (the latest TodoList result), not a KV side
15
- // channel — so resume restores it and a fork reconstructs the list at the fork point.
16
- openSession: async (ctx) => {
17
- store.reconstruct(await readSessionLog(ctx));
13
+ service: store,
14
+ // FRAME state: each address stores and restores its own agent's list. A lost write only
15
+ // leaves the list one change behind, which the agent's next TodoList call rewrites — so
16
+ // nothing waits for it.
17
+ durableState: {
18
+ snapshot: (address) => store.snapshot(address),
19
+ restore: (address, value) => store.restore(address, value),
20
+ },
21
+ openSession: (ctx) => {
22
+ store.attachPersistence((address) => void ctx.persistState(address));
18
23
  },
19
24
  };
20
25
  }
@@ -14,7 +14,8 @@ export class TodoListInjector extends BoundaryInjector {
14
14
  }
15
15
  getInjection(ctx) {
16
16
  this.restoreInjectedAt(ctx, ["todo_reminder"]);
17
- const todos = this.store.get();
17
+ // The reminder is for the frame being injected into — never another agent's list.
18
+ const todos = this.store.get(ctx.address);
18
19
  if (todos.length === 0)
19
20
  return null;
20
21
  const turnsSinceWrite = assistantTurnsSinceTodoWrite(ctx.history);
@@ -1,19 +1,40 @@
1
- import type { AgentRecord } from "../../store/index.ts";
2
1
  export declare const TODO_LIST_TOOL_NAME = "TodoList";
3
2
  export type TodoStatus = "pending" | "in_progress" | "done";
4
3
  export interface TodoItem {
5
4
  readonly title: string;
6
5
  readonly status: TodoStatus;
7
6
  }
8
- /** Snapshot carried in the TodoList tool result `details`, folded back on session open. */
7
+ /** The frame's whole list: carried in the TodoList tool result `details` for the transcript,
8
+ * and what is stored as the frame's durable state. */
9
9
  export interface TodoDetails {
10
10
  readonly todos: readonly TodoItem[];
11
11
  }
12
+ /**
13
+ * One todo list PER FRAME, keyed by journal address (`main`, `main/<agentId>`).
14
+ *
15
+ * A task list belongs to the agent working through it, not to the conversation: a subagent plans
16
+ * its own work, and until this was keyed, its first `TodoList` call replaced the main agent's
17
+ * list outright — silently, since the parent's transcript still carried its own last result.
18
+ * The service stays a single session-lived object (it owns nothing that needs closing); what is
19
+ * per-frame is the DATA, so it is indexed rather than duplicated. See docs/state-and-lifetime.md.
20
+ */
12
21
  export declare class TodoStore {
13
- private todos;
14
- get(): readonly TodoItem[];
15
- set(todos: readonly TodoItem[]): readonly TodoItem[];
16
- /** Rebuild from the log: the latest TodoList tool result is the current list. */
17
- reconstruct(entries: readonly AgentRecord[]): void;
22
+ private readonly byFrame;
23
+ /** Persists one frame's list after a change. Absent in a bare store (tests). */
24
+ private persist;
25
+ /** Where a change to a frame's list becomes durable (`SessionContext.persistState`). */
26
+ attachPersistence(persist: (address: string) => void): void;
27
+ /** The list for one frame. Defaults to the root agent's, which is what `session.todo` reads. */
28
+ get(address?: string): readonly TodoItem[];
29
+ set(address: string, todos: readonly TodoItem[]): readonly TodoItem[];
30
+ /** Every frame that has one, in insertion order. */
31
+ frames(): readonly string[];
32
+ /** One frame's list as its durable state; undefined when the frame has none. */
33
+ snapshot(address: string): TodoDetails | undefined;
34
+ /**
35
+ * Restore one frame's list from the value stored for it (undefined: none). A frame's list is
36
+ * restored when its shard is reopened — `main` at open, a subagent's on resume.
37
+ */
38
+ restore(address: string, value: unknown): void;
18
39
  }
19
40
  //# sourceMappingURL=todo-store.d.ts.map
@@ -1,18 +1,51 @@
1
- import { latestToolDetails } from "../capability-state.js";
1
+ import { DEFAULT_ADDRESS } from "../../store/index.js";
2
2
  export const TODO_LIST_TOOL_NAME = "TodoList";
3
+ const NO_TODOS = [];
4
+ /**
5
+ * One todo list PER FRAME, keyed by journal address (`main`, `main/<agentId>`).
6
+ *
7
+ * A task list belongs to the agent working through it, not to the conversation: a subagent plans
8
+ * its own work, and until this was keyed, its first `TodoList` call replaced the main agent's
9
+ * list outright — silently, since the parent's transcript still carried its own last result.
10
+ * The service stays a single session-lived object (it owns nothing that needs closing); what is
11
+ * per-frame is the DATA, so it is indexed rather than duplicated. See docs/state-and-lifetime.md.
12
+ */
3
13
  export class TodoStore {
4
- todos = [];
5
- get() {
6
- return this.todos;
14
+ byFrame = new Map();
15
+ /** Persists one frame's list after a change. Absent in a bare store (tests). */
16
+ persist;
17
+ /** Where a change to a frame's list becomes durable (`SessionContext.persistState`). */
18
+ attachPersistence(persist) {
19
+ this.persist = persist;
7
20
  }
8
- set(todos) {
9
- this.todos = normalizeTodos(todos);
10
- return this.todos;
21
+ /** The list for one frame. Defaults to the root agent's, which is what `session.todo` reads. */
22
+ get(address = DEFAULT_ADDRESS) {
23
+ return this.byFrame.get(address) ?? NO_TODOS;
11
24
  }
12
- /** Rebuild from the log: the latest TodoList tool result is the current list. */
13
- reconstruct(entries) {
14
- const details = latestToolDetails(entries, TODO_LIST_TOOL_NAME);
15
- this.todos = isTodoDetails(details) ? normalizeTodos(details.todos) : [];
25
+ set(address, todos) {
26
+ const normalized = normalizeTodos(todos);
27
+ this.byFrame.set(address, normalized);
28
+ this.persist?.(address);
29
+ return normalized;
30
+ }
31
+ /** Every frame that has one, in insertion order. */
32
+ frames() {
33
+ return [...this.byFrame.keys()];
34
+ }
35
+ /** One frame's list as its durable state; undefined when the frame has none. */
36
+ snapshot(address) {
37
+ const todos = this.byFrame.get(address);
38
+ return todos === undefined ? undefined : { todos };
39
+ }
40
+ /**
41
+ * Restore one frame's list from the value stored for it (undefined: none). A frame's list is
42
+ * restored when its shard is reopened — `main` at open, a subagent's on resume.
43
+ */
44
+ restore(address, value) {
45
+ if (isTodoDetails(value))
46
+ this.byFrame.set(address, normalizeTodos(value.todos));
47
+ else
48
+ this.byFrame.delete(address);
16
49
  }
17
50
  }
18
51
  function normalizeTodos(todos) {