@cogenta/cli 0.4.0 → 0.6.0

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 (171) hide show
  1. package/CHANGELOG.md +3856 -0
  2. package/dist/admin-assets/assets/index-CxZHGwVA.css +1 -0
  3. package/dist/admin-assets/assets/index-fYXyHpn8.js +1090 -0
  4. package/dist/admin-assets/assets/vips-_dmTUXFO.wasm +0 -0
  5. package/dist/admin-assets/assets/vips-es6-DrQTTS8Q.js +7 -0
  6. package/dist/admin-assets/branding/logo-cogenta-dark.png +0 -0
  7. package/dist/admin-assets/branding/logo-cogenta-icon.png +0 -0
  8. package/dist/admin-assets/branding/logo-cogenta-light.png +0 -0
  9. package/dist/admin-assets/branding/logo-cogenta-small.png +0 -0
  10. package/dist/admin-assets/branding/logo-cogenta-transparent.png +0 -0
  11. package/dist/admin-assets/branding/logo-cogenta.png +0 -0
  12. package/dist/admin-assets/favicon.png +0 -0
  13. package/dist/admin-assets/fonts/jetbrains-mono-var.woff2 +0 -0
  14. package/dist/admin-assets/fonts/space-grotesk-var.woff2 +0 -0
  15. package/dist/admin-assets/index.html +3 -2
  16. package/dist/bin.js +6 -0
  17. package/dist/bin.js.map +1 -1
  18. package/dist/commands/admin-assets.d.ts +1 -0
  19. package/dist/commands/admin-assets.d.ts.map +1 -1
  20. package/dist/commands/admin-assets.js +19 -1
  21. package/dist/commands/admin-assets.js.map +1 -1
  22. package/dist/commands/agent-runtime.d.ts +151 -0
  23. package/dist/commands/agent-runtime.d.ts.map +1 -0
  24. package/dist/commands/agent-runtime.js +519 -0
  25. package/dist/commands/agent-runtime.js.map +1 -0
  26. package/dist/commands/assistant.d.ts +89 -3
  27. package/dist/commands/assistant.d.ts.map +1 -1
  28. package/dist/commands/assistant.js +206 -39
  29. package/dist/commands/assistant.js.map +1 -1
  30. package/dist/commands/audit-integrity-alert.d.ts +23 -0
  31. package/dist/commands/audit-integrity-alert.d.ts.map +1 -0
  32. package/dist/commands/audit-integrity-alert.js +33 -0
  33. package/dist/commands/audit-integrity-alert.js.map +1 -0
  34. package/dist/commands/backup.d.ts +78 -0
  35. package/dist/commands/backup.d.ts.map +1 -0
  36. package/dist/commands/backup.js +238 -0
  37. package/dist/commands/backup.js.map +1 -0
  38. package/dist/commands/channels.d.ts +47 -0
  39. package/dist/commands/channels.d.ts.map +1 -0
  40. package/dist/commands/channels.js +277 -0
  41. package/dist/commands/channels.js.map +1 -0
  42. package/dist/commands/default-logo.d.ts +27 -0
  43. package/dist/commands/default-logo.d.ts.map +1 -0
  44. package/dist/commands/default-logo.js +30 -0
  45. package/dist/commands/default-logo.js.map +1 -0
  46. package/dist/commands/doctor.d.ts +5 -1
  47. package/dist/commands/doctor.d.ts.map +1 -1
  48. package/dist/commands/doctor.js +74 -2
  49. package/dist/commands/doctor.js.map +1 -1
  50. package/dist/commands/export.d.ts +22 -0
  51. package/dist/commands/export.d.ts.map +1 -0
  52. package/dist/commands/export.js +182 -0
  53. package/dist/commands/export.js.map +1 -0
  54. package/dist/commands/forms-page.d.ts +75 -0
  55. package/dist/commands/forms-page.d.ts.map +1 -0
  56. package/dist/commands/forms-page.js +191 -0
  57. package/dist/commands/forms-page.js.map +1 -0
  58. package/dist/commands/import.d.ts.map +1 -1
  59. package/dist/commands/import.js +13 -1
  60. package/dist/commands/import.js.map +1 -1
  61. package/dist/commands/mcp.d.ts +35 -0
  62. package/dist/commands/mcp.d.ts.map +1 -0
  63. package/dist/commands/mcp.js +277 -0
  64. package/dist/commands/mcp.js.map +1 -0
  65. package/dist/commands/roles.d.ts +22 -0
  66. package/dist/commands/roles.d.ts.map +1 -0
  67. package/dist/commands/roles.js +79 -0
  68. package/dist/commands/roles.js.map +1 -0
  69. package/dist/commands/search-page.d.ts +15 -0
  70. package/dist/commands/search-page.d.ts.map +1 -1
  71. package/dist/commands/search-page.js +22 -16
  72. package/dist/commands/search-page.js.map +1 -1
  73. package/dist/commands/seo.d.ts +92 -4
  74. package/dist/commands/seo.d.ts.map +1 -1
  75. package/dist/commands/seo.js +168 -4
  76. package/dist/commands/seo.js.map +1 -1
  77. package/dist/commands/serve.d.ts +439 -7
  78. package/dist/commands/serve.d.ts.map +1 -1
  79. package/dist/commands/serve.js +3498 -181
  80. package/dist/commands/serve.js.map +1 -1
  81. package/dist/commands/site-plan.d.ts +27 -1
  82. package/dist/commands/site-plan.d.ts.map +1 -1
  83. package/dist/commands/site-plan.js +71 -4
  84. package/dist/commands/site-plan.js.map +1 -1
  85. package/dist/commands/term-archive-page.d.ts +94 -0
  86. package/dist/commands/term-archive-page.d.ts.map +1 -0
  87. package/dist/commands/term-archive-page.js +195 -0
  88. package/dist/commands/term-archive-page.js.map +1 -0
  89. package/dist/commands/theme-css.d.ts +22 -7
  90. package/dist/commands/theme-css.d.ts.map +1 -1
  91. package/dist/commands/theme-css.js +33 -8
  92. package/dist/commands/theme-css.js.map +1 -1
  93. package/dist/commands/theme-registry.d.ts +94 -0
  94. package/dist/commands/theme-registry.d.ts.map +1 -0
  95. package/dist/commands/theme-registry.js +130 -0
  96. package/dist/commands/theme-registry.js.map +1 -0
  97. package/dist/commands/theme-render.d.ts +330 -9
  98. package/dist/commands/theme-render.d.ts.map +1 -1
  99. package/dist/commands/theme-render.js +932 -66
  100. package/dist/commands/theme-render.js.map +1 -1
  101. package/dist/commands/theme-wiring.d.ts +107 -0
  102. package/dist/commands/theme-wiring.d.ts.map +1 -0
  103. package/dist/commands/theme-wiring.js +295 -0
  104. package/dist/commands/theme-wiring.js.map +1 -0
  105. package/dist/commands/tools.d.ts +71 -0
  106. package/dist/commands/tools.d.ts.map +1 -0
  107. package/dist/commands/tools.js +330 -0
  108. package/dist/commands/tools.js.map +1 -0
  109. package/dist/commands/update.d.ts +25 -0
  110. package/dist/commands/update.d.ts.map +1 -0
  111. package/dist/commands/update.js +193 -0
  112. package/dist/commands/update.js.map +1 -0
  113. package/dist/index.d.ts +15 -0
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.js +146 -4
  116. package/dist/index.js.map +1 -1
  117. package/dist/invite-mail.d.ts +39 -0
  118. package/dist/invite-mail.d.ts.map +1 -0
  119. package/dist/invite-mail.js +39 -0
  120. package/dist/invite-mail.js.map +1 -0
  121. package/dist/update/apply.d.ts +54 -0
  122. package/dist/update/apply.d.ts.map +1 -0
  123. package/dist/update/apply.js +77 -0
  124. package/dist/update/apply.js.map +1 -0
  125. package/dist/update/changelog-risk.d.ts +20 -0
  126. package/dist/update/changelog-risk.d.ts.map +1 -0
  127. package/dist/update/changelog-risk.js +55 -0
  128. package/dist/update/changelog-risk.js.map +1 -0
  129. package/dist/update/check.d.ts +60 -0
  130. package/dist/update/check.d.ts.map +1 -0
  131. package/dist/update/check.js +56 -0
  132. package/dist/update/check.js.map +1 -0
  133. package/dist/update/contract-risk.d.ts +55 -0
  134. package/dist/update/contract-risk.d.ts.map +1 -0
  135. package/dist/update/contract-risk.js +75 -0
  136. package/dist/update/contract-risk.js.map +1 -0
  137. package/dist/update/history.d.ts +30 -0
  138. package/dist/update/history.d.ts.map +1 -0
  139. package/dist/update/history.js +38 -0
  140. package/dist/update/history.js.map +1 -0
  141. package/dist/update/index.d.ts +28 -0
  142. package/dist/update/index.d.ts.map +1 -0
  143. package/dist/update/index.js +11 -0
  144. package/dist/update/index.js.map +1 -0
  145. package/dist/update/list-restore-points.d.ts +20 -0
  146. package/dist/update/list-restore-points.d.ts.map +1 -0
  147. package/dist/update/list-restore-points.js +35 -0
  148. package/dist/update/list-restore-points.js.map +1 -0
  149. package/dist/update/npm-registry.d.ts +11 -0
  150. package/dist/update/npm-registry.d.ts.map +1 -0
  151. package/dist/update/npm-registry.js +74 -0
  152. package/dist/update/npm-registry.js.map +1 -0
  153. package/dist/update/restore-point.d.ts +26 -0
  154. package/dist/update/restore-point.d.ts.map +1 -0
  155. package/dist/update/restore-point.js +23 -0
  156. package/dist/update/restore-point.js.map +1 -0
  157. package/dist/update/tar.d.ts +27 -0
  158. package/dist/update/tar.d.ts.map +1 -0
  159. package/dist/update/tar.js +56 -0
  160. package/dist/update/tar.js.map +1 -0
  161. package/dist/update/version-compare.d.ts +17 -0
  162. package/dist/update/version-compare.d.ts.map +1 -0
  163. package/dist/update/version-compare.js +42 -0
  164. package/dist/update/version-compare.js.map +1 -0
  165. package/dist/version.d.ts +13 -0
  166. package/dist/version.d.ts.map +1 -0
  167. package/dist/version.js +18 -0
  168. package/dist/version.js.map +1 -0
  169. package/package.json +33 -16
  170. package/dist/admin-assets/assets/index-C9a7O_Xs.css +0 -1
  171. package/dist/admin-assets/assets/index-DXvMgWvn.js +0 -74
@@ -0,0 +1,519 @@
1
+ import { join } from 'node:path';
2
+ import { createAgentRunner, createContentCollectionsTool, createContentDeleteTool, createContentListTool, createContentPublishTool, createContentReadTool, createContentSchemaTool, createContentWriteDraftTool, createDepsScanTool, createDocumentExtractTool, createFileAgentConversationStore, createFileAgentDeclarationStore, createFileAgentSkillStore, createFilePromptTemplateStore, createFileProviderConfigStore, createKillSwitch, createMediaReadTool, createMediaWriteTool, createMemoryApprovalQueue, createNotFoundLogReadTool, createProviderRegistry, createRedirectCreateTool, createSiteConfigReadTool, createToolRegistry, ensureBuiltinAgentSkills, ensureBuiltinAgents, ensureBuiltinPromptTemplates, KNOWN_PROVIDER_CATALOG, resolveProviderRegistryConfig, } from '@cogenta/agents';
3
+ import { createProposeThemeTool } from '@cogenta/agents-builtin';
4
+ import { buildMcpToolDefinitions } from '@cogenta/mcp';
5
+ import { buildPath } from '@cogenta/schema';
6
+ /**
7
+ * L22 tasks 1/1bis — where the runtime `@cogenta/agents` provides finally
8
+ * meets a running site. `@cogenta/agents` knows how to run an agent given a
9
+ * tool registry, a provider registry and stores for declarations/skills/
10
+ * provider config; it does not know how to build a `ContentServiceLike` out
11
+ * of this codebase's real `ContentService`, or where on disk a site keeps
12
+ * its data — that translation is this module's whole job, the same role
13
+ * `assistant.ts` already plays for L18's toolset.
14
+ *
15
+ * Tool availability is not gated by whether a provider is configured (R2):
16
+ * the tool registry, the agent/skill/provider stores, and every CRUD route
17
+ * all work with zero LLM provider set up. Only `AgentRunner.run()` — one
18
+ * synchronous provider lookup before any network call — refuses, per
19
+ * `agents/orchestrator.ts`'s own `AGENT_NO_PROVIDER` guarantee.
20
+ */
21
+ /**
22
+ * Exported for the same reason `PROVIDERS_SUBDIR` below is — `theme-wiring
23
+ * .ts` reads the "Cogenta Theme Creator" agent's own admin-configured
24
+ * `model.preferred`/`model.fallback` from a second `AgentDeclarationStore`
25
+ * instance pointed at this same directory, rather than duplicating a
26
+ * hardcoded guess at that agent's provider preference.
27
+ */
28
+ export const AGENTS_SUBDIR = 'agents';
29
+ const SKILLS_SUBDIR = 'skills';
30
+ /**
31
+ * Exported so `theme-wiring.ts` can point its own `ProviderConfigStore` at
32
+ * the exact same directory `buildAgentRuntime` uses — two independent,
33
+ * file-backed store instances reading the same encrypted files, the same
34
+ * consistency model every other per-request store in this app already
35
+ * relies on. A second, differently-scoped constant here would have let the
36
+ * two silently drift apart, which is exactly the bug this constant's reuse
37
+ * closes (L26 task 5's theme generator answering "no provider" from a
38
+ * config file no admin who configured one through the UI ever touched).
39
+ */
40
+ export const PROVIDERS_SUBDIR = 'providers';
41
+ /**
42
+ * Fiche 45 — under the same `dataDir` (`.cogenta/agents-runtime`)
43
+ * `runServe` also points its own, separately-constructed
44
+ * `PromptTemplateStore` at, ahead of this function (`buildAssistant` runs
45
+ * before `assembleSite`/`buildAgentRuntime` does). Two file-store instances
46
+ * pointed at the same directory is safe: neither caches across calls, so an
47
+ * edit either one makes is visible to the other on its very next read — the
48
+ * same property `createFileAgentSkillStore` already relies on for this
49
+ * reason.
50
+ */
51
+ const PROMPT_TEMPLATES_SUBDIR = 'prompt-templates';
52
+ const CONVERSATIONS_SUBDIR = 'conversations';
53
+ /**
54
+ * `ContentService` (real, `@cogenta/api`) adapted to the narrow
55
+ * `ContentServiceLike` the core content tools declare against — the exact
56
+ * same seam `packages/cli/src/commands/mcp.ts`'s `contentServiceLikeOf`
57
+ * already uses, duplicated rather than shared across two CLI entry points
58
+ * that otherwise have nothing else in common (one is a stdio command, the
59
+ * other lives inside a long-running server).
60
+ */
61
+ function contentServiceLikeOf(service) {
62
+ return {
63
+ read: (context, collection, id, opts) => service.read(context, collection, id, opts),
64
+ create: (context, collection, input, opts) => service.create(context, collection, input, opts),
65
+ update: (context, collection, id, input, opts) => service.update(context, collection, id, input, opts),
66
+ publish: (context, collection, id, input, opts) => service.publish(context, collection, id, input, opts),
67
+ remove: (context, collection, id) => service.remove(context, collection, id),
68
+ };
69
+ }
70
+ /** The first string field a list item is worth labelling by — `title`/`name`/`heading` cover every blueprint collection this project ships; a collection using none of those still lists, just with a null title the model reads as "no obvious title" rather than a guess. */
71
+ function titleOf(values) {
72
+ const candidate = values.title ?? values.name ?? values.heading;
73
+ return typeof candidate === 'string' && candidate.length > 0 ? candidate : null;
74
+ }
75
+ /**
76
+ * `ContentService` adapted to `content.collections`/`content.list`'s
77
+ * `ContentBrowseServiceLike` (L22 task 3) — a second, separate adapter from
78
+ * `contentServiceLikeOf` above, on purpose: those four CRUD tools and these
79
+ * two read/browse ones need different shapes out of the same service
80
+ * (`summary`/`list`/route-building versus single-entry read/write), and nothing
81
+ * here overlaps with `ContentServiceLike`'s own contract enough to be worth
82
+ * merging.
83
+ *
84
+ * `path` is computed here, not by the tool: this is the one place that has
85
+ * both an entry's field values (`SerialisedEntry.values`) and its
86
+ * collection's route pattern (`CollectionDefinition.routing`) in scope.
87
+ * `buildPath` throws for a required param the values do not fill (`Content
88
+ * Route Invalid`) — caught and turned into `null`, the same "cannot offer
89
+ * this as a redirect target" signal an unrouted collection gets, rather than
90
+ * a tool call failing over a values shape this adapter cannot second-guess.
91
+ */
92
+ function contentBrowseServiceLikeOf(service, collections) {
93
+ const byName = new Map(collections.map((collection) => [collection.name, collection]));
94
+ function pathOf(collection, entry) {
95
+ if (collection.routing === undefined)
96
+ return null;
97
+ const params = {};
98
+ for (const [key, value] of Object.entries(entry.values)) {
99
+ if (typeof value === 'string')
100
+ params[key] = value;
101
+ }
102
+ try {
103
+ return buildPath(collection, params, entry.locale);
104
+ }
105
+ catch {
106
+ return null;
107
+ }
108
+ }
109
+ return {
110
+ collections: async (context) => {
111
+ const summaries = await service.summary(context);
112
+ return summaries.map((summary) => ({
113
+ collection: summary.collection,
114
+ total: summary.total,
115
+ published: summary.published,
116
+ routed: byName.get(summary.collection)?.routing !== undefined,
117
+ }));
118
+ },
119
+ list: async (context, collectionName, options) => {
120
+ const collection = byName.get(collectionName);
121
+ if (collection === undefined)
122
+ return undefined;
123
+ const page = await service.list(context, collectionName, {
124
+ filter: undefined,
125
+ sort: { field: 'updatedAt', direction: 'desc' },
126
+ limit: options.limit,
127
+ cursor: undefined,
128
+ locale: undefined,
129
+ requestedState: 'published',
130
+ requestedStatus: undefined,
131
+ trashed: undefined,
132
+ depth: 0,
133
+ });
134
+ return {
135
+ items: page.items.map((item) => ({
136
+ id: item.id,
137
+ title: titleOf(item.values),
138
+ path: pathOf(collection, { values: item.values, locale: item.locale }),
139
+ status: item.status,
140
+ })),
141
+ };
142
+ },
143
+ };
144
+ }
145
+ /**
146
+ * `CollectionDefinition` adapted to `content.schema`'s
147
+ * `ContentSchemaServiceLike` — a third adapter over the same `collections`
148
+ * config `contentBrowseServiceLikeOf` above already reads, on purpose:
149
+ * schema is static site config, not stored data, so `describe` performs no
150
+ * database read of its own; it only calls `service.summary(context)` for
151
+ * the exact same permission check `contentBrowseServiceLikeOf`'s
152
+ * `collections()` already makes, so `content.schema` never describes a
153
+ * collection this actor could not otherwise read.
154
+ */
155
+ function contentSchemaServiceLikeOf(service, collections) {
156
+ const byName = new Map(collections.map((collection) => [collection.name, collection]));
157
+ function fieldsOf(collection) {
158
+ return Object.entries(collection.fields).map(([key, field]) => ({
159
+ key,
160
+ kind: field.kind,
161
+ label: field.admin?.label ?? null,
162
+ required: field.required ?? false,
163
+ options: field.options,
164
+ }));
165
+ }
166
+ function summaryOf(collection) {
167
+ return {
168
+ collection: collection.name,
169
+ labelSingular: collection.labels.singular,
170
+ labelPlural: collection.labels.plural,
171
+ routed: collection.routing !== undefined,
172
+ fields: fieldsOf(collection),
173
+ };
174
+ }
175
+ return {
176
+ describe: async (context, collectionName) => {
177
+ const readable = new Set((await service.summary(context)).map((entry) => entry.collection));
178
+ if (collectionName !== undefined) {
179
+ const collection = byName.get(collectionName);
180
+ if (collection === undefined || !readable.has(collectionName))
181
+ return [];
182
+ return [summaryOf(collection)];
183
+ }
184
+ return collections
185
+ .filter((collection) => readable.has(collection.name))
186
+ .map((collection) => summaryOf(collection));
187
+ },
188
+ };
189
+ }
190
+ /**
191
+ * Refreshed after every write to `ProviderConfigStore` (the providers
192
+ * router calls `refresh()` after each mutation) — an admin who saves a new
193
+ * key takes effect on the next agent run, no restart, without this
194
+ * runtime's one long-lived `AgentRunner` (and the per-agent budget
195
+ * trackers it holds) being torn down and rebuilt on every request.
196
+ *
197
+ * Fiche 56: `has`/`get` used to narrow an arbitrary `string` down to the
198
+ * closed `ProviderName` union before trusting `registry`'s own lookup —
199
+ * `ProviderName` is a plain string now (any catalog id or operator-chosen
200
+ * custom id `store.ts` accepted at write time), so `registry.has`/`get`
201
+ * already answer correctly for every key it was actually built with; no
202
+ * second allowlist to keep in sync here.
203
+ */
204
+ function createLiveProviderRegistry(store) {
205
+ let registry = createProviderRegistry({});
206
+ return {
207
+ async refresh() {
208
+ registry = createProviderRegistry(await resolveProviderRegistryConfig(store));
209
+ },
210
+ has: (name) => registry.has(name),
211
+ get: (name) => registry.get(name),
212
+ };
213
+ }
214
+ function buildToolRegistry(options) {
215
+ const contentServiceLike = contentServiceLikeOf(options.contentService);
216
+ const contentBrowseServiceLike = contentBrowseServiceLikeOf(options.contentService, options.collections);
217
+ const contentSchemaServiceLike = contentSchemaServiceLikeOf(options.contentService, options.collections);
218
+ const definitions = [
219
+ createContentReadTool(contentServiceLike),
220
+ createContentWriteDraftTool(contentServiceLike),
221
+ createContentPublishTool(contentServiceLike),
222
+ createContentDeleteTool(contentServiceLike),
223
+ createMediaReadTool(options.mediaStore),
224
+ createMediaWriteTool(options.mediaStore),
225
+ createSiteConfigReadTool(),
226
+ createDocumentExtractTool(),
227
+ createDepsScanTool({ projectRoot: options.projectRoot }),
228
+ // L22 task 3 — the Site Monitor's toolset.
229
+ createNotFoundLogReadTool(options.notFoundLog),
230
+ createContentCollectionsTool(contentBrowseServiceLike),
231
+ createContentListTool(contentBrowseServiceLike),
232
+ // The missing half of the browse pair — a collection's field shape,
233
+ // not just its entries.
234
+ createContentSchemaTool(contentSchemaServiceLike),
235
+ createRedirectCreateTool(options.redirects),
236
+ ...options.mcpDefinitions,
237
+ // L26 task 5 — "Cogenta Theme Creator"'s only tool. `sideEffects: false`,
238
+ // no write path at any autonomy level (see the tool's own doc comment).
239
+ ...(options.themeCreator === undefined ? [] : [createProposeThemeTool(options.themeCreator)]),
240
+ ];
241
+ return createToolRegistry(definitions);
242
+ }
243
+ /**
244
+ * Adapts `@cogenta/agents`' async `AgentDeclarationStore` to `@cogenta/api`'s
245
+ * synchronous `AgentRegistryLike` — an in-memory cache, and a per-agent kill
246
+ * switch shared with `AgentRunner` so `disable()` stops a run in flight, not
247
+ * only future ones (mirrors `createAgentRegistry`'s own guarantee). The
248
+ * cache is populated once, synchronously awaited, by `buildAgentRuntime`
249
+ * calling `refresh()` before this runtime is handed to anything else — every
250
+ * caller (the REST router, the runner) expects `list()`/`get()` to answer
251
+ * correctly from the moment they receive this object, never after a first,
252
+ * implicit mutation.
253
+ */
254
+ function createRegistryAdapter(store) {
255
+ let cache = [];
256
+ const killSwitches = new Map();
257
+ function killSwitchFor(name) {
258
+ const existing = killSwitches.get(name);
259
+ if (existing !== undefined)
260
+ return existing;
261
+ const created = createKillSwitch(false);
262
+ killSwitches.set(name, created);
263
+ return created;
264
+ }
265
+ async function refresh() {
266
+ cache = await store.list();
267
+ for (const agent of cache) {
268
+ const kill = killSwitchFor(agent.name);
269
+ if (agent.enabled)
270
+ kill.deactivate();
271
+ else
272
+ kill.activate();
273
+ }
274
+ }
275
+ const registry = {
276
+ list: () => cache,
277
+ get: (name) => cache.find((agent) => agent.name === name),
278
+ enable(name) {
279
+ killSwitchFor(name).deactivate();
280
+ void store.setEnabled(name, true).then(refresh);
281
+ },
282
+ disable(name) {
283
+ killSwitchFor(name).activate();
284
+ void store.setEnabled(name, false).then(refresh);
285
+ },
286
+ isEnabled: (name) => !killSwitchFor(name).isActive(),
287
+ async create(input) {
288
+ await store.create(input);
289
+ await refresh();
290
+ },
291
+ async update(name, patch) {
292
+ await store.update(name, patch);
293
+ await refresh();
294
+ },
295
+ async remove(name) {
296
+ await store.remove(name);
297
+ await refresh();
298
+ },
299
+ readIdentity: (name) => store.readIdentity(name),
300
+ };
301
+ return { registry, killSwitchFor, refresh };
302
+ }
303
+ function createSkillRegistryAdapter(store) {
304
+ return {
305
+ list: () => store.list(),
306
+ get: (id) => store.get(id),
307
+ create: (input) => store.create(input),
308
+ update: (id, patch) => store.update(id, patch),
309
+ remove: (id) => store.remove(id),
310
+ listResources: (id) => store.listResources(id),
311
+ addResource: (id, relativePath, content) => store.addResource(id, relativePath, content),
312
+ removeResource: (id, relativePath) => store.removeResource(id, relativePath),
313
+ };
314
+ }
315
+ /** `@cogenta/api`'s `ProviderRegistryLike.catalog` shape — kept as a plain
316
+ * structural type here rather than importing `ProviderCatalogEntry` from
317
+ * `@cogenta/agents`, so `@cogenta/api` never needs a runtime dependency on
318
+ * `@cogenta/agents` (it is a devDependency only) to serve `GET
319
+ * /api/providers/catalog`; this module already depends on both. */
320
+ function providerCatalogSummary() {
321
+ return KNOWN_PROVIDER_CATALOG;
322
+ }
323
+ function createPromptTemplateRegistryAdapter(store) {
324
+ return {
325
+ list: () => store.list(),
326
+ get: (id) => store.get(id),
327
+ create: (input) => store.create(input),
328
+ update: (id, patch) => store.update(id, patch),
329
+ remove: (id) => store.remove(id),
330
+ };
331
+ }
332
+ function createProviderRegistryAdapter(store, onMutated) {
333
+ return {
334
+ names: KNOWN_PROVIDER_CATALOG.map((entry) => entry.id),
335
+ catalog: providerCatalogSummary(),
336
+ list: () => store.list(),
337
+ async upsert(input) {
338
+ const saved = await store.upsert(input);
339
+ await onMutated();
340
+ return saved;
341
+ },
342
+ async setEnabled(provider, enabled) {
343
+ const saved = await store.setEnabled(provider, enabled);
344
+ await onMutated();
345
+ return saved;
346
+ },
347
+ async updateSettings(provider, patch) {
348
+ const saved = await store.updateSettings(provider, patch);
349
+ await onMutated();
350
+ return saved;
351
+ },
352
+ async remove(provider) {
353
+ await store.remove(provider);
354
+ await onMutated();
355
+ },
356
+ };
357
+ }
358
+ /**
359
+ * Fiche 58 task 4's "no restart needed" half — same idiom as
360
+ * `createLiveProviderRegistry` above, applied to the whole tool registry
361
+ * rather than just the provider one: `replace` swaps which underlying
362
+ * `ToolRegistry` `list`/`get` read from, so an agent mid-run that already
363
+ * holds a reference to this wrapper sees the new set on its very next
364
+ * lookup, while a call already dispatched to an old `ExecutableTool`
365
+ * finishes against the client it was actually built with (never torn out
366
+ * from under it — see `refreshMcpTools`'s own comment on disposal order).
367
+ */
368
+ function createLiveToolRegistry(initial) {
369
+ let current = initial;
370
+ return {
371
+ list: () => current.list(),
372
+ get: (name) => current.get(name),
373
+ replace(next) {
374
+ current = next;
375
+ },
376
+ };
377
+ }
378
+ /**
379
+ * Assembles the whole L22 task 1/1bis runtime for one site: three file
380
+ * stores (agents, agent skills, provider config — all under `dataDir`, R1),
381
+ * the real tool registry, and the one `AgentRunner` this site's `/api/agents`
382
+ * `run` route and any future trigger (cron, channel, chat — later tasks)
383
+ * will share. Idempotent: safe to call on every `cogenta serve` boot,
384
+ * including an upgrade from a pre-L22 site (`ensureBuiltinAgents`/
385
+ * `ensureBuiltinAgentSkills` only ever add what is missing).
386
+ */
387
+ export async function buildAgentRuntime(options) {
388
+ const agentStore = createFileAgentDeclarationStore({ dir: join(options.dataDir, AGENTS_SUBDIR) });
389
+ const skillStore = createFileAgentSkillStore({ dir: join(options.dataDir, SKILLS_SUBDIR) });
390
+ const providerStore = createFileProviderConfigStore({
391
+ dir: join(options.dataDir, PROVIDERS_SUBDIR),
392
+ signingKey: options.signingKey,
393
+ });
394
+ const promptTemplateStore = createFilePromptTemplateStore({
395
+ dir: join(options.dataDir, PROMPT_TEMPLATES_SUBDIR),
396
+ });
397
+ const conversationStore = createFileAgentConversationStore({
398
+ dir: join(options.dataDir, CONVERSATIONS_SUBDIR),
399
+ });
400
+ await ensureBuiltinAgents(agentStore);
401
+ await ensureBuiltinAgentSkills(skillStore);
402
+ await ensureBuiltinPromptTemplates(promptTemplateStore);
403
+ const { registry: agentRegistry, killSwitchFor, refresh: refreshAgentRegistry, } = createRegistryAdapter(agentStore);
404
+ await refreshAgentRegistry();
405
+ const liveProviders = createLiveProviderRegistry(providerStore);
406
+ await liveProviders.refresh();
407
+ const coreToolOptions = {
408
+ contentService: options.contentService,
409
+ mediaStore: options.mediaStore,
410
+ projectRoot: options.projectRoot,
411
+ collections: options.collections,
412
+ notFoundLog: options.notFoundLog,
413
+ redirects: options.redirects,
414
+ ...(options.themeCreator === undefined ? {} : { themeCreator: options.themeCreator }),
415
+ };
416
+ // Fiche 58 task 4 — built once, here, before the tool registry: every
417
+ // enabled connection with at least one checked tool gets its own
418
+ // sandboxed `McpClient` (`../client/stdio-client.js`'s floor — no
419
+ // inherited environment, a dedicated cwd, a hard per-call timeout, a
420
+ // best-effort resource watchdog), shared by every one of that
421
+ // connection's exposed tools. A connection that fails to initialize is
422
+ // logged and skipped, never thrown — one misbehaving external server
423
+ // must not keep this whole runtime from starting (R2's own posture,
424
+ // applied here to a different kind of "capability that may be absent").
425
+ let mcpAssembly = options.mcpConnections === undefined
426
+ ? { definitions: [], dispose: async () => undefined }
427
+ : await buildMcpToolDefinitions({ store: options.mcpConnections, logger: options.logger });
428
+ // A live wrapper, not a fixed `ToolRegistry`: `refreshMcpTools` below
429
+ // swaps what it points at, so an admin creating a connection or checking
430
+ // a new tool from the "MCP Clients" screen takes effect on this
431
+ // runtime's very next `createAgentRunner` lookup — no `cogenta serve`
432
+ // restart, the same "no restart needed" guarantee `liveProviders`
433
+ // already gives `/api/providers`.
434
+ const tools = createLiveToolRegistry(buildToolRegistry({ ...coreToolOptions, mcpDefinitions: mcpAssembly.definitions }));
435
+ // Built once (or reused from `options.approvalQueue`, injectable for
436
+ // tests) and handed both to the runner (where `co-pilot` autonomy files a
437
+ // request) and back out on `AgentRuntimeAssembly` (where `serve.ts` reads
438
+ // pending ones for the L22 task 3 notice source, and a channel/chat
439
+ // surface or future approvals route could decide one) — the same object,
440
+ // never two queues that could disagree.
441
+ const approvalQueue = options.approvalQueue ?? createMemoryApprovalQueue();
442
+ const runner = createAgentRunner({
443
+ agents: agentStore,
444
+ skills: skillStore,
445
+ tools,
446
+ providers: liveProviders,
447
+ auditLog: options.auditLog,
448
+ approvalQueue,
449
+ site: options.site,
450
+ killSwitchFor,
451
+ });
452
+ const agentRunner = {
453
+ async run(name, instruction, trigger, history) {
454
+ return runner.run(name, {
455
+ instruction,
456
+ ...(trigger === undefined ? {} : { trigger }),
457
+ ...(history === undefined ? {} : { history }),
458
+ });
459
+ },
460
+ };
461
+ const providerRegistry = createProviderRegistryAdapter(providerStore, () => liveProviders.refresh());
462
+ const skillRegistry = createSkillRegistryAdapter(skillStore);
463
+ const promptTemplateRegistry = createPromptTemplateRegistryAdapter(promptTemplateStore);
464
+ /**
465
+ * Fiche 58 task 4 — rebuilds the MCP portion of the tool registry from
466
+ * the connection store's *current* state (every enabled connection,
467
+ * whatever is exposed right now) and swaps it into `tools` atomically
468
+ * (`createLiveToolRegistry`'s `replace`). The *old* clients are closed
469
+ * only after the swap, never before: a tool call already in flight
470
+ * against the previous `McpClient` finishes normally, and nothing new
471
+ * can be dispatched to it once `tools.replace` has taken effect.
472
+ */
473
+ async function doRefreshMcpTools() {
474
+ if (options.mcpConnections === undefined)
475
+ return;
476
+ const nextAssembly = await buildMcpToolDefinitions({
477
+ store: options.mcpConnections,
478
+ logger: options.logger,
479
+ });
480
+ const previous = mcpAssembly;
481
+ tools.replace(buildToolRegistry({ ...coreToolOptions, mcpDefinitions: nextAssembly.definitions }));
482
+ mcpAssembly = nextAssembly;
483
+ await previous.dispose();
484
+ }
485
+ // Serialised, not called bare: two `refreshMcpTools()` calls racing (an
486
+ // admin's own double-click on "test connection", or two REST calls
487
+ // overlapping) would otherwise let one call's freshly-built assembly —
488
+ // including its own genuinely spawned `stdio` processes and sandbox
489
+ // directories — be overwritten by the other's `mcpAssembly = ...` before
490
+ // ever being disposed, leaking an unsandboxed process that outlives even
491
+ // this runtime's own `mcpDispose()` at shutdown (found by the fiche 58
492
+ // security review). Chaining onto the same promise, success or failure,
493
+ // guarantees at most one `doRefreshMcpTools` runs at a time and every
494
+ // built assembly is either adopted or disposed, never orphaned.
495
+ let refreshChain = Promise.resolve();
496
+ function refreshMcpTools() {
497
+ refreshChain = refreshChain.then(doRefreshMcpTools, doRefreshMcpTools);
498
+ return refreshChain;
499
+ }
500
+ const configuredProviders = (await providerStore.list()).filter((p) => p.enabled);
501
+ const summary = configuredProviders.length === 0
502
+ ? 'agents: registered, no LLM provider configured (runs refuse before any network call)'
503
+ : `agents: registered, ${configuredProviders.length} provider(s) configured (${configuredProviders
504
+ .map((p) => p.provider)
505
+ .join(', ')})`;
506
+ return {
507
+ agentRegistry,
508
+ agentRunner,
509
+ providerRegistry,
510
+ skillRegistry,
511
+ promptTemplateRegistry,
512
+ conversations: conversationStore,
513
+ approvalQueue,
514
+ summary,
515
+ refreshMcpTools,
516
+ mcpDispose: () => mcpAssembly.dispose(),
517
+ };
518
+ }
519
+ //# sourceMappingURL=agent-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-runtime.js","sourceRoot":"","sources":["../../src/commands/agent-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAYL,iBAAiB,EACjB,4BAA4B,EAC5B,uBAAuB,EACvB,qBAAqB,E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