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
@@ -1,9 +1,9 @@
1
- import { type Machine } from "../index.ts";
1
+ import { type Environment } from "../index.ts";
2
2
  import { type PluginDiagnostic, type PluginManifest } from "./types.ts";
3
3
  export interface ParsedManifestResult {
4
4
  readonly manifest?: PluginManifest;
5
5
  readonly manifestPath?: string;
6
6
  readonly diagnostics: readonly PluginDiagnostic[];
7
7
  }
8
- export declare function parseManifest(machine: Machine, pluginRoot: string): Promise<ParsedManifestResult>;
8
+ export declare function parseManifest(environment: Environment, pluginRoot: string): Promise<ParsedManifestResult>;
9
9
  //# sourceMappingURL=manifest.d.ts.map
@@ -1,8 +1,10 @@
1
1
  import path from "node:path";
2
+ import { z } from "zod";
2
3
  import { McpServerConfigSchema } from "../index.js";
3
4
  import { loadPluginHooks } from "./hooks.js";
4
5
  import { PLUGIN_NAME_REGEX } from "./types.js";
5
- import { readTextFile } from "../tool/support/machine-ops.js";
6
+ import { readTextFile } from "../tool/support/environment-ops.js";
7
+ import { describeIssue, optionalText } from "./fields.js";
6
8
  const PLUGIN_ROOT_MANIFEST = "agents.plugin.json";
7
9
  const PLUGIN_DIR_MANIFEST = ".agents-plugin/plugin.json";
8
10
  // Codex-format plugins (github.com/openai/plugins): same manifest shape, different filename, and
@@ -10,12 +12,46 @@ const PLUGIN_DIR_MANIFEST = ".agents-plugin/plugin.json";
10
12
  const CODEX_DIR_MANIFEST = ".codex-plugin/plugin.json";
11
13
  // Runtime fields we still do not execute. `hooks` is supported (see loadPluginHooks).
12
14
  const UNSUPPORTED_RUNTIME_FIELDS = ["tools", "commands", "apps", "inject", "configFile", "bootstrap"];
13
- export async function parseManifest(machine, pluginRoot) {
15
+ const AuthorSchema = z.union([
16
+ z.string().transform((name) => ({ name })),
17
+ z.object({ name: optionalText, email: optionalText }).transform(({ name, email }) => (name === undefined && email === undefined ? undefined : { name, email })),
18
+ ]);
19
+ const InterfaceSchema = z
20
+ .object({ displayName: optionalText, shortDescription: optionalText, longDescription: optionalText })
21
+ .transform((iface) => (Object.values(iface).some((v) => v !== undefined) ? iface : undefined));
22
+ /**
23
+ * The manifest as written. Fields that need the filesystem to be resolved (`skills`,
24
+ * `mcpServers`, `hooks`) are shape-checked here and resolved below; everything else lands in
25
+ * the `PluginManifest` as is. Unknown fields pass through so a newer plugin still loads.
26
+ */
27
+ const RawManifestSchema = z.looseObject({
28
+ name: z.string({ error: "is required" }).refine((name) => name.trim().length > 0, "is required"),
29
+ version: optionalText,
30
+ description: optionalText,
31
+ keywords: z.array(z.string()).optional(),
32
+ homepage: optionalText,
33
+ license: optionalText,
34
+ author: AuthorSchema.optional(),
35
+ skills: z.union([z.string(), z.array(z.string())], { error: "must be a string or string[]" }).optional(),
36
+ sessionStart: z.object({ skill: z.string().refine((skill) => skill.trim().length > 0, "is required when sessionStart is present") }).optional(),
37
+ mcpServers: z.union([z.string(), z.record(z.string(), z.unknown())], { error: "must be an object or a path to a .mcp.json" }).optional(),
38
+ hooks: z.unknown().optional(),
39
+ interface: InterfaceSchema.optional(),
40
+ skillInstructions: z.string().optional(),
41
+ });
42
+ // A malformed optional field is reported and dropped, not fatal: the plugin still loads with
43
+ // what was valid, the way it always has. `name` and `skills` are the two a plugin cannot do
44
+ // without, so those stay errors.
45
+ const FATAL_FIELDS = new Set(["name"]);
46
+ const ERROR_FIELDS = new Set(["skills"]);
47
+ const DEFAULT_SKILLS_DIR = "skills";
48
+ const DEFAULT_MCP_CONFIG_FILE = ".mcp.json";
49
+ export async function parseManifest(environment, pluginRoot) {
14
50
  const candidates = [PLUGIN_ROOT_MANIFEST, PLUGIN_DIR_MANIFEST, CODEX_DIR_MANIFEST];
15
51
  let manifestPath;
16
52
  for (const candidate of candidates) {
17
53
  const candidatePath = path.join(pluginRoot, candidate);
18
- if (await isFile(machine, candidatePath)) {
54
+ if (await isFile(environment, candidatePath)) {
19
55
  manifestPath = candidatePath;
20
56
  break;
21
57
  }
@@ -23,64 +59,86 @@ export async function parseManifest(machine, pluginRoot) {
23
59
  if (manifestPath === undefined) {
24
60
  return { diagnostics: [{ severity: "error", message: `No manifest at ${candidates.join(", ")}` }] };
25
61
  }
26
- let raw;
62
+ let json;
27
63
  try {
28
- raw = JSON.parse(await readTextFile(machine, manifestPath));
64
+ json = JSON.parse(await readTextFile(environment, manifestPath));
29
65
  }
30
66
  catch (error) {
31
67
  return { manifestPath, diagnostics: [{ severity: "error", message: `Failed to parse ${manifestPath}: ${error.message}` }] };
32
68
  }
33
- if (!isObject(raw)) {
69
+ if (!isObject(json)) {
34
70
  return { manifestPath, diagnostics: [{ severity: "error", message: "manifest must be a JSON object" }] };
35
71
  }
36
72
  const diagnostics = [];
37
- const name = typeof raw["name"] === "string" ? raw["name"].trim() : "";
38
- if (name.length === 0) {
39
- diagnostics.push({ severity: "error", message: '"name" is required' });
73
+ const raw = parseTolerant(json, diagnostics);
74
+ if (raw === undefined)
40
75
  return { manifestPath, diagnostics };
41
- }
76
+ const name = raw.name.trim();
42
77
  if (!PLUGIN_NAME_REGEX.test(name)) {
43
78
  diagnostics.push({ severity: "error", message: `"name" must match ${PLUGIN_NAME_REGEX} (got "${name}")` });
44
79
  return { manifestPath, diagnostics };
45
80
  }
46
- let skills = await resolveSkillsField(machine, pluginRoot, raw["skills"], diagnostics);
47
- if (raw["skills"] === undefined && (await isFile(machine, path.join(pluginRoot, "SKILL.md")))) {
81
+ // Codex convention: a manifest that doesn't name its skills / MCP file still gets the plugin's
82
+ // `skills/` dir and root `.mcp.json` (most curated plugins rely on this — e.g. Vercel, Slack).
83
+ const skillsField = raw.skills ?? ((await isDir(environment, path.join(pluginRoot, DEFAULT_SKILLS_DIR))) ? `./${DEFAULT_SKILLS_DIR}` : undefined);
84
+ const mcpServersField = raw.mcpServers ?? ((await isFile(environment, path.join(pluginRoot, DEFAULT_MCP_CONFIG_FILE))) ? `./${DEFAULT_MCP_CONFIG_FILE}` : undefined);
85
+ let skills = await resolveSkillsField(environment, pluginRoot, skillsField, diagnostics);
86
+ if (skillsField === undefined && (await isFile(environment, path.join(pluginRoot, "SKILL.md")))) {
48
87
  skills = [pluginRoot];
49
88
  }
50
89
  for (const field of UNSUPPORTED_RUNTIME_FIELDS) {
51
90
  if (raw[field] !== undefined)
52
91
  diagnostics.push({ severity: "info", message: `"${field}" is present but not supported` });
53
92
  }
54
- const hooks = await loadPluginHooks(machine, pluginRoot, raw["hooks"], diagnostics);
93
+ const hooks = await loadPluginHooks(environment, pluginRoot, raw.hooks, diagnostics);
55
94
  const manifest = {
56
95
  name,
57
- version: stringField(raw, "version"),
58
- description: stringField(raw, "description"),
59
- keywords: stringArrayField(raw, "keywords"),
60
- homepage: stringField(raw, "homepage"),
61
- license: stringField(raw, "license"),
62
- author: readAuthor(raw["author"]),
96
+ version: raw.version,
97
+ description: raw.description,
98
+ keywords: raw.keywords,
99
+ homepage: raw.homepage,
100
+ license: raw.license,
101
+ author: raw.author,
63
102
  skills,
64
- sessionStart: readSessionStart(raw["sessionStart"], diagnostics),
65
- mcpServers: await readMcpServers(machine, pluginRoot, raw["mcpServers"], diagnostics),
103
+ sessionStart: raw.sessionStart === undefined ? undefined : { skill: raw.sessionStart.skill.trim() },
104
+ mcpServers: await readMcpServers(environment, pluginRoot, mcpServersField, diagnostics),
66
105
  ...(hooks.length > 0 ? { hooks } : {}),
67
- interface: readInterface(raw["interface"]),
68
- skillInstructions: typeof raw["skillInstructions"] === "string" ? raw["skillInstructions"] : undefined,
106
+ interface: raw.interface,
107
+ skillInstructions: raw.skillInstructions,
69
108
  };
70
109
  return { manifest, manifestPath, diagnostics };
71
110
  }
72
- async function resolveSkillsField(machine, pluginRoot, raw, diagnostics) {
111
+ /**
112
+ * Validate the manifest, reporting each malformed field by name. A bad `name` ends parsing;
113
+ * any other bad field is dropped and the rest is parsed again, so one typo in `author` does
114
+ * not cost the plugin its skills.
115
+ */
116
+ function parseTolerant(json, diagnostics) {
117
+ const first = RawManifestSchema.safeParse(json);
118
+ if (first.success)
119
+ return first.data;
120
+ const dropped = new Set();
121
+ for (const issue of first.error.issues) {
122
+ const field = String(issue.path[0] ?? "");
123
+ if (FATAL_FIELDS.has(field) || issue.path.length === 0) {
124
+ diagnostics.push({ severity: "error", message: describeIssue(issue) });
125
+ return undefined;
126
+ }
127
+ diagnostics.push({ severity: ERROR_FIELDS.has(field) ? "error" : "warn", message: describeIssue(issue) });
128
+ dropped.add(field);
129
+ }
130
+ const pruned = Object.fromEntries(Object.entries(json).filter(([key]) => !dropped.has(key)));
131
+ const second = RawManifestSchema.safeParse(pruned);
132
+ if (second.success)
133
+ return second.data;
134
+ for (const issue of second.error.issues)
135
+ diagnostics.push({ severity: "error", message: describeIssue(issue) });
136
+ return undefined;
137
+ }
138
+ async function resolveSkillsField(environment, pluginRoot, raw, diagnostics) {
73
139
  if (raw === undefined)
74
140
  return [];
75
- const entries = [];
76
- if (typeof raw === "string")
77
- entries.push(raw);
78
- else if (Array.isArray(raw) && raw.every((e) => typeof e === "string"))
79
- entries.push(...raw);
80
- else {
81
- diagnostics.push({ severity: "error", message: '"skills" must be a string or string[]' });
82
- return [];
83
- }
141
+ const entries = typeof raw === "string" ? [raw] : raw;
84
142
  const resolved = [];
85
143
  for (const entry of entries) {
86
144
  if (!entry.startsWith("./")) {
@@ -92,7 +150,7 @@ async function resolveSkillsField(machine, pluginRoot, raw, diagnostics) {
92
150
  diagnostics.push({ severity: "error", message: `"skills" path resolves outside the plugin (${entry})` });
93
151
  continue;
94
152
  }
95
- if (!(await isDir(machine, absolute))) {
153
+ if (!(await isDir(environment, absolute))) {
96
154
  diagnostics.push({ severity: "warn", message: `"skills" path is not a directory (${entry})` });
97
155
  continue;
98
156
  }
@@ -100,21 +158,7 @@ async function resolveSkillsField(machine, pluginRoot, raw, diagnostics) {
100
158
  }
101
159
  return resolved;
102
160
  }
103
- function readSessionStart(raw, diagnostics) {
104
- if (raw === undefined)
105
- return undefined;
106
- if (!isObject(raw)) {
107
- diagnostics.push({ severity: "warn", message: '"sessionStart" must be an object' });
108
- return undefined;
109
- }
110
- const skill = typeof raw["skill"] === "string" ? raw["skill"].trim() : "";
111
- if (skill.length === 0) {
112
- diagnostics.push({ severity: "warn", message: '"sessionStart.skill" is required when sessionStart is present' });
113
- return undefined;
114
- }
115
- return { skill };
116
- }
117
- async function readMcpServers(machine, pluginRoot, raw, diagnostics) {
161
+ async function readMcpServers(environment, pluginRoot, raw, diagnostics) {
118
162
  if (raw === undefined)
119
163
  return undefined;
120
164
  // Codex format: `mcpServers` is a path to a `.mcp.json` ({ "mcpServers": { … } }). Read it and
@@ -132,7 +176,7 @@ async function readMcpServers(machine, pluginRoot, raw, diagnostics) {
132
176
  return undefined;
133
177
  }
134
178
  try {
135
- const parsed = JSON.parse(await readTextFile(machine, absolute));
179
+ const parsed = JSON.parse(await readTextFile(environment, absolute));
136
180
  servers = isObject(parsed) && isObject(parsed["mcpServers"]) ? parsed["mcpServers"] : parsed;
137
181
  }
138
182
  catch (error) {
@@ -156,16 +200,16 @@ async function readMcpServers(machine, pluginRoot, raw, diagnostics) {
156
200
  diagnostics.push({ severity: "warn", message: `Invalid MCP server "${trimmedName}": ${parsed.error.message}` });
157
201
  continue;
158
202
  }
159
- out[trimmedName] = await normalizePluginMcpServer(machine, pluginRoot, trimmedName, parsed.data, diagnostics);
203
+ out[trimmedName] = await normalizePluginMcpServer(environment, pluginRoot, trimmedName, parsed.data, diagnostics);
160
204
  }
161
205
  return Object.keys(out).length === 0 ? undefined : out;
162
206
  }
163
- async function normalizePluginMcpServer(machine, pluginRoot, name, config, diagnostics) {
207
+ async function normalizePluginMcpServer(environment, pluginRoot, name, config, diagnostics) {
164
208
  // stdio `./command` resolves within the plugin root; bare names stay PATH commands.
165
209
  if (config.transport === "stdio" && typeof config.command === "string" && config.command.startsWith("./")) {
166
210
  const absolute = path.resolve(pluginRoot, config.command);
167
211
  if (isWithin(absolute, pluginRoot)) {
168
- if (!(await isFile(machine, absolute))) {
212
+ if (!(await isFile(environment, absolute))) {
169
213
  diagnostics.push({ severity: "warn", message: `"mcpServers.${name}.command" not found (${config.command})` });
170
214
  }
171
215
  return { ...config, command: absolute };
@@ -174,40 +218,6 @@ async function normalizePluginMcpServer(machine, pluginRoot, name, config, diagn
174
218
  }
175
219
  return config;
176
220
  }
177
- function readAuthor(raw) {
178
- if (typeof raw === "string")
179
- return { name: raw };
180
- if (!isObject(raw))
181
- return undefined;
182
- const name = stringField(raw, "name");
183
- const email = stringField(raw, "email");
184
- if (name === undefined && email === undefined)
185
- return undefined;
186
- return { name, email };
187
- }
188
- function readInterface(raw) {
189
- if (!isObject(raw))
190
- return undefined;
191
- const out = {
192
- displayName: stringField(raw, "displayName"),
193
- shortDescription: stringField(raw, "shortDescription"),
194
- longDescription: stringField(raw, "longDescription"),
195
- };
196
- return Object.values(out).some((v) => v !== undefined) ? out : undefined;
197
- }
198
- function stringField(raw, key) {
199
- const value = raw[key];
200
- if (typeof value !== "string")
201
- return undefined;
202
- const trimmed = value.trim();
203
- return trimmed.length === 0 ? undefined : trimmed;
204
- }
205
- function stringArrayField(raw, key) {
206
- const value = raw[key];
207
- if (!Array.isArray(value) || !value.every((e) => typeof e === "string"))
208
- return undefined;
209
- return value;
210
- }
211
221
  function isObject(value) {
212
222
  return typeof value === "object" && value !== null && !Array.isArray(value);
213
223
  }
@@ -215,17 +225,17 @@ function isWithin(child, parent) {
215
225
  const relative = path.relative(parent, child);
216
226
  return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
217
227
  }
218
- async function isFile(machine, p) {
228
+ async function isFile(environment, p) {
219
229
  try {
220
- return (await machine.fileInfo(p)).kind === "file";
230
+ return (await environment.fileInfo(p)).kind === "file";
221
231
  }
222
232
  catch {
223
233
  return false;
224
234
  }
225
235
  }
226
- async function isDir(machine, p) {
236
+ async function isDir(environment, p) {
227
237
  try {
228
- return (await machine.fileInfo(p)).kind === "dir";
238
+ return (await environment.fileInfo(p)).kind === "dir";
229
239
  }
230
240
  catch {
231
241
  return false;
@@ -1,6 +1,8 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
+ import { z } from "zod";
3
4
  import { downloadZip, extractZip } from "./archive.js";
5
+ import { describeIssue, optionalText, optionalTextList } from "./fields.js";
4
6
  import { codeloadZipUrl } from "./github-resolver.js";
5
7
  import { resolveInstallSource, sanitizeSubdir } from "./source.js";
6
8
  // Codex's marketplace index path inside a repo.
@@ -22,24 +24,48 @@ export async function materializeGithubRepo(options) {
22
24
  const buffer = await downloadZip(codeloadZipUrl(options.owner, options.repo, ref));
23
25
  return extractZip(buffer, options.destDir);
24
26
  }
27
+ /** Codex source object: { source: "local"|"git-subdir"|"url", path|url, ref|sha }. */
28
+ const CodexSourceSchema = z.object({
29
+ source: optionalText,
30
+ path: optionalText,
31
+ url: optionalText,
32
+ ref: optionalText,
33
+ sha: optionalText,
34
+ });
35
+ const MarketplaceEntrySchema = z.object({
36
+ id: optionalText,
37
+ name: optionalText,
38
+ displayName: optionalText,
39
+ source: CodexSourceSchema,
40
+ tier: optionalText,
41
+ version: optionalText,
42
+ description: optionalText,
43
+ shortDescription: optionalText,
44
+ homepage: optionalText,
45
+ websiteURL: optionalText,
46
+ keywords: optionalTextList,
47
+ });
48
+ const MarketplaceSchema = z.object({
49
+ version: optionalText,
50
+ plugins: z.array(MarketplaceEntrySchema),
51
+ });
25
52
  /** Parse + validate a marketplace registry string against a cached repo location. */
26
53
  export function parseMarketplace(raw, location) {
27
- let parsed;
54
+ let json;
28
55
  try {
29
- parsed = JSON.parse(raw);
56
+ json = JSON.parse(raw);
30
57
  }
31
58
  catch (error) {
32
59
  throw new Error(`Plugin marketplace is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
33
60
  }
34
- if (!isRecord(parsed))
35
- throw new TypeError("Plugin marketplace must be an object.");
36
- const rawPlugins = parsed["plugins"];
37
- if (!Array.isArray(rawPlugins))
38
- throw new TypeError('Plugin marketplace must contain a "plugins" array.');
61
+ const parsed = MarketplaceSchema.safeParse(json);
62
+ if (!parsed.success) {
63
+ throw new TypeError(`Plugin marketplace is malformed: ${parsed.error.issues.map(describeIssue).join("; ")}`);
64
+ }
39
65
  return {
40
66
  source: location.source,
41
- version: stringField(parsed, "version"),
42
- plugins: rawPlugins.map((entry, index) => parseEntry(entry, index, location)),
67
+ version: parsed.data.version,
68
+ plugins: parsed.data.plugins.map((entry, index) => toEntry(entry, index, location)),
43
69
  };
44
70
  }
45
71
  function resolveLocation(source, repoDir) {
@@ -80,33 +106,24 @@ export function parseGithubMarketplaceSource(source) {
80
106
  return undefined;
81
107
  return { owner: m[1], repo: m[2].replace(/\.git$/, ""), ...(m[3] ? { ref: m[3] } : {}) };
82
108
  }
83
- function parseEntry(value, index, location) {
84
- if (!isRecord(value))
85
- throw new TypeError(`Plugin marketplace entry ${index + 1} must be an object.`);
86
- const id = stringField(value, "id") ?? stringField(value, "name");
109
+ function toEntry(value, index, location) {
110
+ const id = value.id ?? value.name;
87
111
  if (id === undefined)
88
112
  throw new Error(`Plugin marketplace entry ${index + 1} must define "id" or "name".`);
89
113
  return {
90
114
  id,
91
- displayName: stringField(value, "displayName") ?? stringField(value, "name") ?? id,
92
- source: resolveSource(value, location, id),
93
- tier: stringField(value, "tier"),
94
- version: stringField(value, "version"),
95
- description: stringField(value, "description") ?? stringField(value, "shortDescription"),
96
- homepage: stringField(value, "homepage") ?? stringField(value, "websiteURL"),
97
- keywords: stringArrayField(value, "keywords"),
115
+ displayName: value.displayName ?? value.name ?? id,
116
+ source: resolveCodexSource(value.source, location, id),
117
+ tier: value.tier,
118
+ version: value.version,
119
+ description: value.description ?? value.shortDescription,
120
+ homepage: value.homepage ?? value.websiteURL,
121
+ keywords: value.keywords,
98
122
  };
99
123
  }
100
- function resolveSource(value, location, id) {
101
- const raw = value["source"];
102
- if (!isRecord(raw))
103
- throw new Error(`Plugin marketplace entry ${id} must define an object "source" (Codex format).`);
104
- return resolveCodexSource(raw, location, id);
105
- }
106
- /** Codex source object: { source: "local"|"git-subdir"|"url", path|url, ref|sha }. */
107
124
  function resolveCodexSource(obj, location, id) {
108
- const kind = stringField(obj, "source");
109
- const path = stringField(obj, "path");
125
+ const kind = obj.source;
126
+ const path = obj.path;
110
127
  if (kind === "local" || (kind === undefined && path !== undefined)) {
111
128
  if (path === undefined)
112
129
  throw new Error(`Plugin marketplace entry ${id}: local source requires "path".`);
@@ -114,16 +131,16 @@ function resolveCodexSource(obj, location, id) {
114
131
  return join(location.repoRoot, cleanSubdir(path));
115
132
  }
116
133
  if (kind === "git-subdir") {
117
- const url = stringField(obj, "url");
134
+ const url = obj.url;
118
135
  if (url === undefined)
119
136
  throw new Error(`Plugin marketplace entry ${id}: git-subdir source requires "url".`);
120
- const ref = stringField(obj, "ref") ?? stringField(obj, "sha") ?? "HEAD";
137
+ const ref = obj.ref ?? obj.sha ?? "HEAD";
121
138
  const sub = path !== undefined ? cleanSubdir(path) : undefined;
122
139
  const base = `${stripTrailingSlash(url)}/tree/${ref}`;
123
140
  return sub !== undefined ? `${base}#path=${sub}` : base;
124
141
  }
125
142
  if (kind === "url") {
126
- const url = stringField(obj, "url") ?? path;
143
+ const url = obj.url ?? path;
127
144
  if (url === undefined)
128
145
  throw new Error(`Plugin marketplace entry ${id}: url source requires "url".`);
129
146
  return url;
@@ -138,23 +155,6 @@ function cleanSubdir(p) {
138
155
  function stripTrailingSlash(s) {
139
156
  return s.replace(/\/$/, "");
140
157
  }
141
- function stringField(value, field) {
142
- const raw = value[field];
143
- if (typeof raw !== "string")
144
- return undefined;
145
- const trimmed = raw.trim();
146
- return trimmed.length > 0 ? trimmed : undefined;
147
- }
148
- function stringArrayField(value, field) {
149
- const raw = value[field];
150
- if (!Array.isArray(raw))
151
- return undefined;
152
- const out = raw.filter((item) => typeof item === "string").map((item) => item.trim()).filter((item) => item.length > 0);
153
- return out.length > 0 ? out : undefined;
154
- }
155
- function isRecord(value) {
156
- return typeof value === "object" && value !== null && !Array.isArray(value);
157
- }
158
158
  // Manifest filenames to try, in order (Codex first, then operon). Mirrors plugins/manifest.ts.
159
159
  const ENTRY_MANIFEST_CANDIDATES = [".codex-plugin/plugin.json", "agents.plugin.json", ".agents-plugin/plugin.json"];
160
160
  /**
@@ -168,10 +168,10 @@ export async function loadMarketplaceEntryDetails(source) {
168
168
  return null;
169
169
  for (const candidate of ENTRY_MANIFEST_CANDIDATES) {
170
170
  try {
171
- const manifest = JSON.parse(await readFile(join(resolved.path, candidate), "utf8"));
172
- if (!isRecord(manifest))
171
+ const manifest = DetailsManifestSchema.safeParse(JSON.parse(await readFile(join(resolved.path, candidate), "utf8")));
172
+ if (!manifest.success)
173
173
  continue;
174
- return extractEntryDetails(manifest, resolved.path);
174
+ return extractEntryDetails(manifest.data, resolved.path);
175
175
  }
176
176
  catch {
177
177
  // Missing/parse error for this candidate — try the next, then give up (null).
@@ -179,13 +179,32 @@ export async function loadMarketplaceEntryDetails(source) {
179
179
  }
180
180
  return null;
181
181
  }
182
+ // Display metadata only: a field of the wrong type is ignored, never a reason to hide the entry.
183
+ const lenientText = optionalText.catch(undefined);
184
+ const DetailsManifestSchema = z.looseObject({
185
+ interface: z
186
+ .looseObject({
187
+ displayName: lenientText,
188
+ shortDescription: lenientText,
189
+ longDescription: lenientText,
190
+ logo: lenientText,
191
+ composerIcon: lenientText,
192
+ brandColor: lenientText,
193
+ })
194
+ .catch({}),
195
+ displayName: lenientText,
196
+ name: lenientText,
197
+ description: lenientText,
198
+ logo: lenientText,
199
+ icon: lenientText,
200
+ });
182
201
  function extractEntryDetails(manifest, dir) {
183
202
  // Codex puts the user-facing fields under `interface`; operon uses top-level fields.
184
- const iface = isRecord(manifest["interface"]) ? manifest["interface"] : {};
185
- const displayName = stringField(iface, "displayName") ?? stringField(manifest, "displayName") ?? stringField(manifest, "name");
186
- const description = stringField(iface, "shortDescription") ?? stringField(iface, "longDescription") ?? stringField(manifest, "description");
187
- const logoRel = stringField(iface, "logo") ?? stringField(iface, "composerIcon") ?? stringField(manifest, "logo") ?? stringField(manifest, "icon");
188
- const brandColor = stringField(iface, "brandColor");
203
+ const iface = manifest.interface;
204
+ const displayName = iface.displayName ?? manifest.displayName ?? manifest.name;
205
+ const description = iface.shortDescription ?? iface.longDescription ?? manifest.description;
206
+ const logoRel = iface.logo ?? iface.composerIcon ?? manifest.logo ?? manifest.icon;
207
+ const brandColor = iface.brandColor;
189
208
  let logoUrl;
190
209
  let logoPath;
191
210
  if (logoRel !== undefined) {
@@ -1,4 +1,4 @@
1
- import type { Machine } from "../index.ts";
1
+ import type { Environment } from "../index.ts";
2
2
  import type { PluginCapabilityState, PluginGithubMetadata, PluginSource } from "./types.ts";
3
3
  export interface InstalledRecord {
4
4
  readonly id: string;
@@ -15,6 +15,6 @@ export interface InstalledFile {
15
15
  readonly version: 1;
16
16
  readonly plugins: readonly InstalledRecord[];
17
17
  }
18
- export declare function readInstalled(machine: Machine, homeDir: string): Promise<InstalledFile>;
19
- export declare function writeInstalled(machine: Machine, homeDir: string, data: InstalledFile): Promise<void>;
18
+ export declare function readInstalled(environment: Environment, homeDir: string): Promise<InstalledFile>;
19
+ export declare function writeInstalled(environment: Environment, homeDir: string, data: InstalledFile): Promise<void>;
20
20
  //# sourceMappingURL=store.d.ts.map
@@ -1,13 +1,13 @@
1
1
  import path from "node:path";
2
- import { readTextFile, writeTextFile } from "../tool/support/machine-ops.js";
2
+ import { readTextFile, writeTextFile } from "../tool/support/environment-ops.js";
3
3
  const EMPTY = { version: 1, plugins: [] };
4
4
  function installedPath(homeDir) {
5
5
  return path.join(homeDir, "plugins", "installed.json");
6
6
  }
7
- export async function readInstalled(machine, homeDir) {
7
+ export async function readInstalled(environment, homeDir) {
8
8
  let text;
9
9
  try {
10
- text = await readTextFile(machine, installedPath(homeDir));
10
+ text = await readTextFile(environment, installedPath(homeDir));
11
11
  }
12
12
  catch {
13
13
  return EMPTY; // missing file → empty registry
@@ -23,8 +23,8 @@ export async function readInstalled(machine, homeDir) {
23
23
  throw new Error(`Failed to parse ${installedPath(homeDir)}: ${error.message}`, { cause: error });
24
24
  }
25
25
  }
26
- export async function writeInstalled(machine, homeDir, data) {
27
- await machine.mkdir(path.join(homeDir, "plugins"), { parents: true, existOk: true });
28
- await writeTextFile(machine, installedPath(homeDir), JSON.stringify(data, null, 2));
26
+ export async function writeInstalled(environment, homeDir, data) {
27
+ await environment.mkdir(path.join(homeDir, "plugins"), { parents: true, existOk: true });
28
+ await writeTextFile(environment, installedPath(homeDir), JSON.stringify(data, null, 2));
29
29
  }
30
30
  //# sourceMappingURL=store.js.map
@@ -1,4 +1,4 @@
1
- export type { Message, UserMessage, AssistantMessage, ToolResultMessage, ToolCall, TextContent, ThinkingContent, ImageContent, Usage, Context, Model, Api, KnownApi, KnownProvider, ThinkingLevel, ThinkingBudgets, ProviderHeaders, Transport, Tool as PiTool, AssistantMessageEvent, AssistantMessageEventStream, } from "@earendil-works/pi-ai";
1
+ export type { Message, SystemMessage, UserMessage, AssistantMessage, ToolResultMessage, ToolCall, TextContent, ThinkingContent, ImageContent, Usage, Context, Model, Api, KnownApi, KnownProvider, ThinkingLevel, ThinkingBudgets, ProviderHeaders, Transport, Tool as PiTool, AssistantMessageEvent, AssistantMessageEventStream, JsonObject, JsonValue, } from "@earendil-works/pi-ai";
2
2
  export type { ProviderId as Provider } from "@earendil-works/pi-ai";
3
3
  export type { ToolSchema } from "./tool-schema.ts";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,12 @@
1
- import type { AgentRecord, ReadRecordPageOptions, ReadRecordsFilter, RecordPage, SessionStore, StateKey } from "./store.ts";
1
+ import type { Usage } from "../protocol/index.ts";
2
+ import { type AgentRecord, type ReadRecordPageOptions, type ReadRecordsFilter, type RecordPage, type SessionStore, type StateKey } from "./store.ts";
2
3
  export type DurableSessionState = "idle" | "interrupted";
3
4
  export interface SessionCatalogObserver {
4
5
  activity(at: number, source: "log" | "state"): void | Promise<void>;
5
6
  durableState(state: DurableSessionState, at: number): void | Promise<void>;
6
7
  metadata?(value: unknown, at: number): void | Promise<void>;
8
+ /** The session's running usage moved (a root-agent turn ended; see `SessionSummary.usage`). */
9
+ usage?(usage: Usage, at: number): void | Promise<void>;
7
10
  flush?(): Promise<void>;
8
11
  }
9
12
  /**
@@ -1,3 +1,4 @@
1
+ import { SESSION_USAGE_KEY, } from "./store.js";
1
2
  /**
2
3
  * Decorates a repository-owned store with catalog maintenance. The session KV/log remains
3
4
  * authoritative: callbacks run only after the corresponding write succeeds, and a broken
@@ -19,7 +20,8 @@ export class CatalogSessionStore {
19
20
  }
20
21
  async appendRecord(record) {
21
22
  const sequence = await this.inner.appendRecord(record);
22
- await this.notify(() => this.observer.activity(Date.now(), "log"));
23
+ const at = Date.now();
24
+ await this.notify(() => this.observer.activity(at, "log"));
23
25
  return sequence;
24
26
  }
25
27
  readRecords(filter) {
@@ -36,6 +38,8 @@ export class CatalogSessionStore {
36
38
  return this.observer.durableState("interrupted", at);
37
39
  if (key === "meta" && this.observer.metadata !== undefined)
38
40
  return this.observer.metadata(value, at);
41
+ if (key === SESSION_USAGE_KEY && this.observer.usage !== undefined)
42
+ return this.observer.usage(value, at);
39
43
  return this.observer.activity(at, "state");
40
44
  });
41
45
  }
@@ -0,0 +1,41 @@
1
+ import { type AgentRecord, type ReadRecordPageOptions, type ReadRecordsFilter, type RecordPage, type SessionStore, type StateKey, type StoredAgentRecord, type WatchRecordsOptions } from "./store.ts";
2
+ /**
3
+ * Stamps every history checkpoint a session writes with the shard's lifecycle at that instant
4
+ * (`#frame`: agent, open turn, queued steers — see `FrameCheckpoint`).
5
+ *
6
+ * The stamp happens inside `appendRecord`, which a `ConversationContext` calls synchronously in
7
+ * the same block as the history reset — so it is of exactly the lifecycle every record before
8
+ * the checkpoint produced, and of nothing after it. Doing it here rather than in each context
9
+ * means no context, wherever it is built, can write a checkpoint without it. A record that
10
+ * already carries `checkpoint` passes through untouched.
11
+ *
12
+ * The lifecycle is folded here from every record that passes through: this store sits UNDER the
13
+ * event publisher, so the lifecycle records the publisher journals pass through it too, in
14
+ * exactly the order they reach the log. Session and capability state are not stamped — they are
15
+ * kept as current values in the store's key/value side (see `CapabilityDurableState`).
16
+ */
17
+ export declare class CheckpointingSessionStore implements SessionStore {
18
+ private readonly inner;
19
+ /** The lifecycle side of every shard written or restored in this process, without history. */
20
+ private readonly frames;
21
+ readonly listStateKeys?: () => Promise<readonly StateKey[]>;
22
+ readonly watch?: (options: WatchRecordsOptions) => AsyncIterable<StoredAgentRecord>;
23
+ readonly flush?: () => Promise<void>;
24
+ readonly close?: () => Promise<void>;
25
+ readonly rewrite?: (address?: string) => Promise<void>;
26
+ readonly storageDir?: () => string | undefined;
27
+ constructor(inner: SessionStore, sessionId: string);
28
+ /**
29
+ * Fold a shard's records read back from the log (from its checkpoint on, or whole) into the
30
+ * lifecycle state, before this process writes to it again. A shard already folded here is
31
+ * left alone: what this process wrote is newer than anything it could read.
32
+ */
33
+ restoreFrame(address: string, records: readonly AgentRecord[]): void;
34
+ appendRecord(record: AgentRecord): Promise<string>;
35
+ readRecords(filter?: ReadRecordsFilter): AsyncIterable<AgentRecord>;
36
+ readRecordPage(options: ReadRecordPageOptions): Promise<RecordPage>;
37
+ putState(key: StateKey, value: unknown): Promise<void>;
38
+ getState(key: StateKey): Promise<unknown | null>;
39
+ deleteState(key: StateKey): Promise<void>;
40
+ }
41
+ //# sourceMappingURL=checkpointing-store.d.ts.map