@arcforge/core 2.0.219 → 2.0.244

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.
package/package.json CHANGED
@@ -1,6 +1,8 @@
1
1
  {
2
2
  "name": "@arcforge/core",
3
- "version": "2.0.219",
3
+ "version": "2.0.244",
4
+ "license": "Apache-2.0",
5
+ "private": false,
4
6
  "type": "module",
5
7
  "main": "./src/index.ts",
6
8
  "exports": {
@@ -10,30 +12,32 @@
10
12
  "src"
11
13
  ],
12
14
  "scripts": {
13
- "test": "bun test",
15
+ "test": "bun run test:full",
16
+ "test:hot": "bun test tests/hot",
17
+ "test:full": "bun test --timeout 30000 tests/hot tests/integration",
14
18
  "test:coverage": "bun test --coverage"
15
19
  },
16
20
  "dependencies": {
17
- "@arcforge/air": "2.0.219",
18
- "@arcforge/capsule": "2.0.219",
19
- "@arcforge/cloud": "2.0.219",
20
- "@arcforge/cognet": "2.0.219",
21
- "@arcforge/engines": "2.0.219",
22
- "@arcforge/err": "2.0.219",
23
- "@arcforge/kernel": "2.0.219",
24
- "@arcforge/link": "2.0.219",
25
- "@arcforge/session": "2.0.219",
26
- "@arcforge/types": "2.0.219",
27
- "@arcforge/vstr": "2.0.219",
21
+ "@arcforge/air": "2.0.244",
22
+ "@arcforge/capsule": "2.0.244",
23
+ "@arcforge/cloud": "2.0.244",
24
+ "@arcforge/cognet": "2.0.244",
25
+ "@arcforge/engines": "2.0.244",
26
+ "@arcforge/err": "2.0.244",
27
+ "@arcforge/kernel": "2.0.244",
28
+ "@arcforge/link": "2.0.244",
29
+ "@arcforge/session": "2.0.244",
30
+ "@arcforge/types": "2.0.244",
31
+ "@arcforge/vstr": "2.0.244",
28
32
  "crossws": "^0.3.5",
29
33
  "h3": "^1.13.0",
30
34
  "hookable": "^5.5.3",
31
35
  "jose": "^5.9.6"
32
36
  },
33
37
  "devDependencies": {
34
- "@arclabs/repo": "1.0.0",
38
+ "@arclabs/repo": "workspace:*",
35
39
  "@types/bun": "latest",
36
40
  "typescript": "^5"
37
41
  },
38
- "axonRevision": "bfbb695da8a820cef52f99cbf6cc084f872c3f87"
42
+ "axonRevision": "6b7c31b386531c7829eb28a9f00480022cdc01f8"
39
43
  }
package/src/Axon.ts CHANGED
@@ -1,22 +1,18 @@
1
- import { AxonCloud } from "@arcforge/cloud"
2
- import type { AxonCloudClient } from "@arcforge/cloud"
3
- import type { AxonEngineDriver, AxonEscalate, AxonHost, AxonPartialBlueprint } from "@arcforge/types"
1
+ import { AxonCloud, type AxonCloudClient } from "@arcforge/cloud"
2
+ import type { AxonEscalate, AxonHost, AxonPartialBlueprint, RemoteEngines } from "@arcforge/types"
4
3
  import { err } from "@arcforge/err"
5
- import { AxonBlueprint } from "./platform"
6
- import { Inject } from "./platform"
7
- import { AxonBus } from "./platform"
8
- import { Hooks } from "./platform"
4
+ import { AxonBlueprint, AxonBus, Boot, Hooks, Inject } from "./platform"
9
5
  import { Kernel } from "@arcforge/kernel"
10
- import { Boot } from "./platform"
11
6
  import { AxonSession, home } from "@arcforge/session"
12
7
 
13
8
  import { AxonHandle } from "./runtime"
14
9
  import { AxonRuntime } from "./runtime/runtime"
15
10
  import { Inference } from "./runtime/inference"
11
+ import { Grants } from "./runtime/grants"
16
12
  import { Cognet } from "./cognet"
17
13
  import { Modules } from "./modules"
18
14
  import { Tools } from "./tools"
19
- import { dirname, join, resolve } from "node:path"
15
+ import { dirname, resolve } from "node:path"
20
16
 
21
17
  type AxonOpts = {
22
18
  blueprint: AxonPartialBlueprint
@@ -60,7 +56,7 @@ type AxonOpts = {
60
56
  * AIR, retries and the stall guard, and cannot tell the tokens crossed a
61
57
  * process boundary.
62
58
  */
63
- remote?: (role: string) => AxonEngineDriver
59
+ remote?: RemoteEngines
64
60
  }
65
61
 
66
62
  export type { AxonHost } from "@arcforge/types"
@@ -174,10 +170,15 @@ export async function Axon(opts?: AxonOpts) {
174
170
  // kernel as base() rather than living in ring 0.
175
171
  const boot = Boot({ blueprint, session })
176
172
 
173
+ // What fills each use the cognet declares — after resolution, which bound the engine roles uses may
174
+ // be served by. A required use nothing fills stops the boot here.
175
+ const grants = await Grants({ blueprint: blueprint, ...(engines ? { engines: engines } : {}), ...(opts?.remote ? { remote: opts.remote } : {}) })
176
+
177
177
  const kernel = await session.span("axon:kernel", {}, () => Kernel({
178
178
  blueprint: blueprint,
179
179
  ...(opts?.remote ? { remote: opts.remote } : {}),
180
180
  ...(engines ? { engines } : {}),
181
+ grants: grants,
181
182
  bus: bus,
182
183
  cloud: cloud,
183
184
  cognet: cognet,
@@ -1,10 +1,9 @@
1
1
  import { createHash } from "node:crypto"
2
- import { mkdir, readdir, rm, stat } from "node:fs/promises"
2
+ import { rm } from "node:fs/promises"
3
3
  import { dirname, join } from "node:path"
4
4
  import { pathToFileURL } from "node:url"
5
5
  import { err } from "@arcforge/err"
6
- import type { AxonBlueprint, AxonEventMap, AxonSpanName, CognetBlueprint, CognetDefinition, CognetWake, KernelAbi } from "@arcforge/types"
7
- import { KERNEL_ABI_VERSION } from "@arcforge/types"
6
+ import { KERNEL_ABI_VERSION, type AxonBlueprint, type AxonEventMap, type AxonSpanName, type CognetBlueprint, type CognetDefinition, type CognetWake, type KernelAbi } from "@arcforge/types"
8
7
 
9
8
  type CognetOpts = {
10
9
  blueprint: AxonBlueprint
@@ -48,7 +47,7 @@ type CognetOpts = {
48
47
  export async function Cognet(opts: CognetOpts) {
49
48
  let blueprint = opts.blueprint
50
49
  const slot = blueprint.cognet
51
- let resolved = opts.session
50
+ const resolved = opts.session
52
51
  ? await opts.session.span(
53
52
  "axon:cognet",
54
53
  { specifier: "path" in slot ? slot.path : null } as never,
@@ -181,16 +180,16 @@ function artifactChanged(before: CognetBlueprint, after: CognetBlueprint): boole
181
180
  * Blueprint slot → live definition.
182
181
  *
183
182
  * CLI form: verify the bundle's sha256 against the blueprint BEFORE
184
- * evaluating a single line of it, then import with the hash as a
185
- * cache-buster (the ES module registry keys on URL — a rebuilt bundle at
186
- * the same path must produce a FRESH module instance, whose module scope
187
- * becomes the new brain's resident RAM). The stale module of a swapped-out
188
- * brain cannot be evicted from the registry — one leaked scope per brain
189
- * reload, the standard HMR trade.
183
+ * evaluating a single line of it, then import it — where it is the first
184
+ * time, and as a sibling named for its hash when this process has already
185
+ * imported that path (a rebuilt bundle must be a FRESH module instance,
186
+ * whose module scope becomes the new brain's resident RAM). The stale module
187
+ * of a swapped-out brain cannot be evicted from the registry — one leaked
188
+ * scope per brain reload, the standard HMR trade.
190
189
  */
191
190
  type ResolvedCognet = {
192
191
  definition: CognetDefinition
193
- /** Removes the per-runtime module copy once its owning kernel has stopped. */
192
+ /** Removes the copy a hot reload imported, once that brain is swapped out. Absent for a bundle imported where it is. */
194
193
  dispose?: () => Promise<void>
195
194
  /** Bundle size on disk. Absent for the live-definition form, which reads nothing. */
196
195
  bytes?: number
@@ -222,77 +221,42 @@ async function resolve(slot: CognetBlueprint): Promise<ResolvedCognet> {
222
221
  })
223
222
  }
224
223
 
225
- // Module scope is a brain's resident RAM, and one brain belongs to one
226
- // kernel. Bun may reuse a file module even when only its query string
227
- // differs, so query-based cache busting is not a reliable isolation
228
- // boundary. Give every runtime a distinct physical entry instead.
229
- //
230
- // The copies live under .agent (already ignored by the project watcher)
231
- // and are removed with the owning runtime. The compiled cognet is a
232
- // self-contained ESM artifact, so no relative import graph needs copying.
233
- const instanceDir = join(dirname(slot.path), ".instances")
234
- const instancePath = join(instanceDir, `${slot.hash}.${crypto.randomUUID()}.mjs`)
235
- await mkdir(instanceDir, { recursive: true })
236
- await sweepStaleInstances(instanceDir)
237
- await Bun.write(instancePath, contents)
224
+ // An agent is its own process, so this process holds one brain at a time:
225
+ // the bundle is imported where it is, and its native module beside it
226
+ // resolves as built. Only a brain swapped in while running — a rebuild,
227
+ // `update()` — needs a path this process has not imported: Bun keys its
228
+ // module registry on the file, so the same path would hand back the
229
+ // previous brain's module. That copy sits BESIDE the bundle, named for its
230
+ // hash, so what it loads relative to itself still resolves; it is removed
231
+ // when that brain is swapped out, and one a crash leaves is cleared by the
232
+ // next compile.
233
+ const entry = imported.has(slot.path) ? join(dirname(slot.path), `cognet.${slot.hash.slice(0, 16)}.mjs`) : slot.path
234
+ if (entry !== slot.path) await Bun.write(entry, contents)
235
+ imported.add(slot.path)
238
236
 
239
237
  try {
240
238
  const importBegan = Date.now()
241
- const module = (await import(pathToFileURL(instancePath).href)) as { default?: unknown }
239
+ const module = (await import(pathToFileURL(entry).href)) as { default?: unknown }
242
240
  const importMs = Date.now() - importBegan
243
241
  return {
244
242
  definition: validate(slot, module.default),
245
- dispose: async () => { await rm(instancePath, { force: true }) },
243
+ ...(entry === slot.path ? {} : { dispose: async () => { await rm(entry, { force: true }) } }),
246
244
  bytes: contents.byteLength,
247
245
  hashMs: hashMs,
248
246
  importMs: importMs,
249
247
  }
250
248
  } catch (cause) {
251
- await rm(instancePath, { force: true })
249
+ if (entry !== slot.path) await rm(entry, { force: true })
252
250
  throw cause
253
251
  }
254
252
  }
255
253
 
256
254
  /**
257
- * How long an instance copy must be untouched before a later boot may delete
258
- * it. Comfortably longer than the window between `mkdir` and the `import` that
259
- * pins the file, so a runtime booting concurrently can never have its own copy
260
- * swept out from under it.
255
+ * Every bundle path this process has imported. Process-wide because the
256
+ * module registry it mirrors is: a path imported once is never imported
257
+ * fresh again.
261
258
  */
262
- const STALE_INSTANCE_MS = 60 * 60_000
263
-
264
- /**
265
- * Remove instance copies orphaned by runtimes that never disposed.
266
- *
267
- * `dispose()` deletes the copy on clean shutdown, but a `kill -9` — or a crash,
268
- * or a debugger stop — skips it, and nothing else ever did. Every such exit
269
- * leaked a full copy of the compiled cognet: 21 files / 1.8MB in one local
270
- * agent, growing without bound, and published into the release tarball.
271
- *
272
- * Age is the only safe signal, because a sibling runtime's copy is a live
273
- * import that must not be touched. Sweeping on boot (rather than on dispose)
274
- * is what makes it work at all — the process that leaked the file is by
275
- * definition not around to clean it up.
276
- *
277
- * Best-effort: a failure here must never stop a brain from loading.
278
- */
279
- async function sweepStaleInstances(instanceDir: string): Promise<void> {
280
- try {
281
- const cutoff = Date.now() - STALE_INSTANCE_MS
282
- const entries = await readdir(instanceDir)
283
- await Promise.all(entries.map(async entry => {
284
- const path = join(instanceDir, entry)
285
- try {
286
- const info = await stat(path)
287
- if (info.mtimeMs < cutoff) await rm(path, { force: true })
288
- } catch {
289
- // Raced with another runtime's dispose — already gone, fine.
290
- }
291
- }))
292
- } catch {
293
- // No directory yet, or an unreadable one. Not a reason to fail a boot.
294
- }
295
- }
259
+ const imported = new Set<string>()
296
260
 
297
261
  /** The bundle's default export must be a definition, and must be who the blueprint says it is. */
298
262
  function validate(slot: CognetBlueprint, candidate: unknown): CognetDefinition {
package/src/index.ts CHANGED
@@ -3,6 +3,11 @@ export { Axon } from "./Axon"
3
3
  // resolve a role, because resolution means building a driver from a
4
4
  // credential. The supervisor does it once on its own side and vends tokens.
5
5
  export { Inference } from "./runtime/inference"
6
+ // What can be known of an agent's grants before it runs — checked at prepare.
7
+ export { checked as checkGrants } from "./runtime/services"
8
+ // Every use held to its interface's conformance cases, filled as a boot fills it — what `axon conform` runs.
9
+ export { Conform, type Conformed } from "./runtime/conform"
10
+ export { AxonBlueprint } from "./platform"
6
11
  // The event bus, exported for the SUPERVISOR: a linked agent has no in-heap
7
12
  // runtime to announce on, so its commits fan out through one of these instead.
8
13
  export { AxonBus } from "./platform"
@@ -1,6 +1,6 @@
1
1
  import { resolve } from "node:path"
2
2
  import { err } from "@arcforge/err"
3
- import type { AxonBlueprint as AxonBlueprintT, AxonConfig, AxonPartialBlueprint } from "@arcforge/types"
3
+ import type { AxonBlueprint as AxonBlueprintT, AxonConfig, AxonPartialBlueprint, CognetBlueprint, CognetBlueprintInput } from "@arcforge/types"
4
4
 
5
5
  /**
6
6
  * Config every agent starts from before its own axon.config.ts is merged in.
@@ -70,11 +70,12 @@ export function AxonBlueprint(input?: AxonPartialBlueprint): AxonBlueprintT {
70
70
 
71
71
  // the brain, constructed by the CLI (or a test) and carried in live.
72
72
  // REQUIRED: an agent without a brain is not an agent — checked below.
73
- cognet: partial.cognet,
73
+ cognet: moded(partial.cognet),
74
74
 
75
75
  tools: partial.tools ?? [],
76
76
  prompts: partial.prompts ?? [],
77
77
  scripts: partial.scripts ?? [],
78
+ serviceProviders: partial.serviceProviders ?? [],
78
79
  knowledge: partial.knowledge ?? [],
79
80
 
80
81
  server: {
@@ -199,3 +200,16 @@ export function mergeBlueprint(
199
200
 
200
201
  return AxonBlueprint(merged)
201
202
  }
203
+
204
+ /**
205
+ * The cognet slot with its mode. A bundled brain's blueprint carries it; a
206
+ * live definition says its own, and is read here — the one seam where a slot
207
+ * becomes the strict shape every consumer trusts.
208
+ */
209
+ function moded(slot: CognetBlueprintInput): CognetBlueprint {
210
+ if ("path" in slot) return slot
211
+ if (slot.mode !== undefined && slot.mode.kind !== slot.definition.mode.kind) {
212
+ throw err("COGNET_INVALID", { detail: `the blueprint says the cognet is ${slot.mode.kind}, but its definition says ${slot.definition.mode.kind}` })
213
+ }
214
+ return { ...slot, mode: slot.definition.mode }
215
+ }
@@ -27,8 +27,7 @@ type BootOpts = {
27
27
  session: AxonSessionT
28
28
  }
29
29
 
30
- const LOG_LEVELS = ["info", "warning", "error"] as const
31
- type LogLevel = (typeof LOG_LEVELS)[number]
30
+ type LogLevel = "info" | "warning" | "error"
32
31
 
33
32
  /**
34
33
  * Boot — the agent's base context. Static `boot.md` is a plain string,
@@ -25,7 +25,7 @@ export type BusHistoryEntry = {
25
25
  * subscribes for live rendering, and tests assert against history(). An
26
26
  * event that only reaches the bus is gone when the process ends.
27
27
  *
28
- * Distinct from Hooks(): this is many-to-many fire-and-forget notification;
28
+ * Distinct from Hooks(): this is many-to-many notification;
29
29
  * hooks are call-and-await-to-completion at a fixed runtime call point.
30
30
  *
31
31
  * Generic EventMap lets user-defined events be typed alongside built-ins.
@@ -76,10 +76,11 @@ export type AxonBusT<EventMap extends Record<string, unknown> = AxonEventMap> =
76
76
 
77
77
  /**
78
78
  * Subscribe to ALL events. Handler receives the event name and payload.
79
+ * Async handlers are awaited, and failures are reported like named handlers.
79
80
  * Used by the WebSocket bus relay to forward events to connected TUI clients.
80
81
  * Returns an unsubscribe function.
81
82
  */
82
- onAny(handler: (event: string, payload: unknown) => void): () => void
83
+ onAny(handler: (event: string, payload: unknown) => void | Promise<void>): () => void
83
84
 
84
85
  /**
85
86
  * Relay an externally-typed event onto the bus without static payload
@@ -93,13 +94,12 @@ export type AxonBusT<EventMap extends Record<string, unknown> = AxonEventMap> =
93
94
 
94
95
  export function AxonBus<EventMap extends Record<string, unknown> = AxonEventMap>(opts?: { maxHistory?: number }): AxonBusT<EventMap> {
95
96
  const maxHistory = opts?.maxHistory ?? 1000
96
- type FullMap = AxonEventMap & EventMap
97
97
 
98
98
  // handler map: event name → ordered list of handlers
99
99
  const handlers = new Map<string, Array<EventHandler<unknown>>>()
100
100
 
101
101
  // wildcard handlers — called for every emitted event
102
- const anyHandlers = new Set<(event: string, payload: unknown) => void>()
102
+ const anyHandlers = new Set<(event: string, payload: unknown) => void | Promise<void>>()
103
103
 
104
104
  // history ring — all emitted events, in order
105
105
  const _history: BusHistoryEntry[] = []
@@ -150,37 +150,32 @@ export function AxonBus<EventMap extends Record<string, unknown> = AxonEventMap>
150
150
  try {
151
151
  await handler(payload)
152
152
  } catch (cause) {
153
- // A handler failure is a real failure — plugins and modules
154
- // register handlers, so a silently-broken one is invisible
155
- // rot. Constructing it through err() delivers it to the
156
- // session's error sink (errScope), which is what makes it
157
- // durable; previously this only reached the in-memory
158
- // history ring and stderr, so nothing about a failing
159
- // plugin handler ever survived the process.
160
- const failure = err("BUS_HANDLER_FAILED", {
161
- detail: `handler for "${event}" threw`,
162
- context: { event },
163
- cause,
164
- })
165
- // Recursion guard: a failing axon:bus:error handler must not
166
- // re-enter this path forever. Its own failure is already
167
- // recorded by err() above.
168
- if (event !== "axon:bus:error") {
169
- await emit("axon:bus:error", { event, error: failure })
170
- }
153
+ await reportHandlerFailure(event, cause)
171
154
  }
172
155
  }
173
156
 
174
- // Wildcard handlers are non-fatal, but failures are surfaced.
175
- for (const handler of anyHandlers) {
157
+ for (const handler of [...anyHandlers]) {
176
158
  try {
177
- handler(event, payload)
178
- } catch (anyHandlerError) {
179
- console.warn(`[axon:bus] wildcard handler error on "${event}":`, anyHandlerError)
159
+ await handler(event, payload)
160
+ } catch (cause) {
161
+ await reportHandlerFailure(event, cause)
180
162
  }
181
163
  }
182
164
  }
183
165
 
166
+ async function reportHandlerFailure(event: string, cause: unknown): Promise<void> {
167
+ // err() delivers the failure to the session's scoped sink. The bus
168
+ // error event informs live observers; its own failures cannot recurse.
169
+ const failure = err("BUS_HANDLER_FAILED", {
170
+ detail: `handler for "${event}" threw`,
171
+ context: { event },
172
+ cause,
173
+ })
174
+ if (event !== "axon:bus:error") {
175
+ await emit("axon:bus:error", { event, error: failure })
176
+ }
177
+ }
178
+
184
179
  return {
185
180
  emit: emit as AxonBusT<EventMap>["emit"],
186
181
  on: on as AxonBusT<EventMap>["on"],
@@ -196,7 +191,7 @@ export function AxonBus<EventMap extends Record<string, unknown> = AxonEventMap>
196
191
  return result
197
192
  },
198
193
  clearHistory(): void { _history.length = 0 },
199
- onAny(handler: (event: string, payload: unknown) => void): () => void {
194
+ onAny(handler: (event: string, payload: unknown) => void | Promise<void>): () => void {
200
195
  anyHandlers.add(handler)
201
196
  return () => { anyHandlers.delete(handler) }
202
197
  },
@@ -1,7 +1,6 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks"
2
2
  import { err } from "@arcforge/err"
3
- import { defineArgs, defineAxonPlugin, defineMiddleware, defineModule, defineProps, definePrompt } from "@arcforge/types"
4
- import type { AxonBlueprint, AxonHandle } from "@arcforge/types"
3
+ import { defineArgs, defineAxonPlugin, defineMiddleware, defineModule, defineProps, definePrompt, defineProvider, type AxonBlueprint, type AxonHandle } from "@arcforge/types"
5
4
 
6
5
  const argsStorage = new AsyncLocalStorage<Record<string, unknown>>()
7
6
 
@@ -97,6 +96,7 @@ export function Inject() {
97
96
  g.defineProps ??= defineProps
98
97
  g.defineMiddleware ??= defineMiddleware
99
98
  g.defineAxonPlugin ??= defineAxonPlugin
99
+ g.defineProvider ??= defineProvider
100
100
 
101
101
  g.axon = new Proxy({}, {
102
102
  get: outsideRuntime,
@@ -147,7 +147,7 @@ export function Inject() {
147
147
  // miss forwards to the live handle; `activity` is the one own
148
148
  // member.
149
149
  ? new Proxy(axon as object, {
150
- get: (target, key, receiver) => key === "activity"
150
+ get: (target, key) => key === "activity"
151
151
  ? ambient.activity
152
152
  : Reflect.get(target, key, target),
153
153
  has: (target, key) => key === "activity" || Reflect.has(target, key),
@@ -246,4 +246,3 @@ function installToolGlobals(g: Record<string, unknown>, loaded: Record<string, u
246
246
  installedToolGlobals.push(name)
247
247
  }
248
248
  }
249
-
@@ -0,0 +1,20 @@
1
+ import type { EngineCloud, ProviderEntry } from "@arcforge/types"
2
+
3
+ /** Discovers account sources only when the machine has no explicit provider policy. */
4
+ export function Accounts(opts: {
5
+ connections: EngineCloud["user"]["vault"]["connections"]
6
+ auth: EngineCloud["user"]["auth"]
7
+ profile: readonly ProviderEntry[] | undefined
8
+ }) {
9
+ return {
10
+ async list(): Promise<ProviderEntry[]> {
11
+ if (opts.profile !== undefined) return []
12
+ // Signed out is an ordinary state, not a failed vault request.
13
+ if (opts.auth !== undefined && opts.auth.token === undefined) return []
14
+ if (!opts.connections.list) throw new Error("Account provider discovery is not wired")
15
+ const connections = await opts.connections.list()
16
+ return connections.filter(connection => connection.status === "active")
17
+ .map(connection => ({ provider: connection.route }))
18
+ },
19
+ }
20
+ }
@@ -0,0 +1,34 @@
1
+ import type { AxonBlueprint, EngineCloud } from "@arcforge/types"
2
+ import { Inject } from "../platform"
3
+ import { Grants } from "./grants"
4
+ import { Inference } from "./inference"
5
+ import { Conformance, type Outcome } from "./services/conformance"
6
+
7
+ /** One use, checked: what filled it, and how each of its interface's cases went — null when it ships none, or nothing filled it. */
8
+ export type Conformed = { use: string; interface: string; provider: string | null; cases: Outcome[] | null }
9
+
10
+ /**
11
+ * Conform — every use an agent's cognet declares, filled as a boot would fill
12
+ * it, and held to its interface's conformance cases.
13
+ *
14
+ * Resolution and grants are the boot's own, so what is checked is what would
15
+ * run: the same route, the same provider the agent wrote, the same limits.
16
+ * Nothing is loaded into a kernel and no mind wakes.
17
+ */
18
+ export function Conform(opts: { blueprint: AxonBlueprint; cloud: EngineCloud }) {
19
+ return {
20
+ async run(): Promise<Conformed[]> {
21
+ // A provider the agent wrote calls defineProvider at import, as it does at boot.
22
+ Inject().macros()
23
+ const engines = await Inference({ blueprint: opts.blueprint, cloud: opts.cloud })
24
+ const grants = await Grants({ blueprint: opts.blueprint, ...(engines ? { engines: engines } : {}) })
25
+ const conformed: Conformed[] = []
26
+ for (const [name, use] of Object.entries(opts.blueprint.cognet.uses ?? {})) {
27
+ const provider = grants.granted(name)
28
+ const cases = provider && use.conformance ? await Conformance({ use: use, provider: provider, dir: use.conformance }).run() : null
29
+ conformed.push({ use: name, interface: use.named, provider: provider?.name ?? null, cases: cases })
30
+ }
31
+ return conformed
32
+ },
33
+ }
34
+ }
@@ -0,0 +1,43 @@
1
+ import { addressedTo, type AxonConnection, type AxonOutputEvent } from "@arcforge/types"
2
+ import type { AxonKernelT } from "@arcforge/kernel"
3
+ import type { AxonBusT } from "../platform"
4
+
5
+ /**
6
+ * Connections — clients talking to the running mind, each at its own address.
7
+ *
8
+ * A connection is the mind's sense door and its outputs, scoped to one
9
+ * client: what it sends arrives as a stimulus on its channel, and it hears
10
+ * what the mind addresses to that channel, or to no one. Nothing waits for an
11
+ * answer to end — a mind may answer, keep working, or speak unprompted, and a
12
+ * client renders whatever arrives.
13
+ */
14
+ export function Connections(opts: { kernel: AxonKernelT; bus: AxonBusT }) {
15
+ return {
16
+ open(at: { channel: string }): AxonConnection {
17
+ return {
18
+ send: content => opts.kernel.ingest({ content: content, channel: at.channel }),
19
+
20
+ on: (type, handler) => opts.bus.onAny(async (event: string, payload: unknown) => {
21
+ if (event !== type) return
22
+ const data = fact(payload) as AxonOutputEvent[typeof type]
23
+ if (!addressedTo(data, at.channel)) return
24
+ await handler(data)
25
+ }),
26
+
27
+ activity: handler => opts.bus.onAny((event: string, payload: unknown) => {
28
+ if (event !== "cognet:activity") return
29
+ handler((fact(payload) as { working: string[] }).working)
30
+ }),
31
+
32
+ interrupt: () => opts.kernel.interrupt("user"),
33
+ }
34
+ },
35
+ }
36
+ }
37
+
38
+ export type ConnectionsT = ReturnType<typeof Connections>
39
+
40
+ /** The bus carries whole envelopes; a client wants the fact inside. */
41
+ function fact(payload: unknown): unknown {
42
+ return (payload as { data?: unknown }).data ?? payload
43
+ }