@arcforge/types 2.0.114 → 2.0.116
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 +1 -1
- package/src/capsule-scope.ts +38 -0
- package/src/config.ts +0 -16
- package/src/define.ts +8 -5
- package/src/engine.ts +44 -2
- package/src/handle.ts +29 -0
- package/src/index.ts +1 -0
- package/src/kernel/abi.ts +70 -12
- package/src/kernel/index.ts +2 -1
- package/src/prompts.ts +12 -8
- package/src/session/events/capsule.ts +2 -1
- package/src/session/events/engine.ts +91 -35
- package/src/session/index.ts +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The bindings a capsule run left behind — what a rendered template may
|
|
3
|
+
* interpolate.
|
|
4
|
+
*
|
|
5
|
+
* Bun's REPL transform hoists every top-level declaration onto the sandbox's
|
|
6
|
+
* real globalThis, which is what makes "declarations persist into later
|
|
7
|
+
* blocks" true. Scope extraction reads that same state: it is a diff of
|
|
8
|
+
* globalThis across one submission, never a second capture mechanism.
|
|
9
|
+
*
|
|
10
|
+
* Values cross a process boundary, so only JSON-representable ones can come
|
|
11
|
+
* with. Everything else is reported by NAME with a reason instead of being
|
|
12
|
+
* silently dropped — a template interpolating a function would otherwise
|
|
13
|
+
* render `undefined` with nothing to explain it, and the model would have no
|
|
14
|
+
* way to know what it did wrong.
|
|
15
|
+
*/
|
|
16
|
+
export type CapsuleScope = {
|
|
17
|
+
/** Bindings whose values crossed intact. */
|
|
18
|
+
values: Record<string, unknown>
|
|
19
|
+
/** Bindings that exist in the sandbox but could not cross, by name. */
|
|
20
|
+
unavailable: CapsuleScopeUnavailable[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type CapsuleScopeUnavailable = {
|
|
24
|
+
name: string
|
|
25
|
+
/**
|
|
26
|
+
* function — a callable; meaningless outside the sandbox that owns it.
|
|
27
|
+
* circular — self-referencing structure; not representable as JSON.
|
|
28
|
+
* unserializable — threw during serialization (getters, BigInt, ...).
|
|
29
|
+
* oversized — the run's scope budget was exhausted before this binding.
|
|
30
|
+
* A script may build anything in the sandbox, but the scope crosses a
|
|
31
|
+
* process boundary every run; a runaway accumulation is reported by
|
|
32
|
+
* name rather than put on the wire.
|
|
33
|
+
*/
|
|
34
|
+
reason: "function" | "circular" | "unserializable" | "oversized"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** An empty scope — the honest value for a run that declared nothing. */
|
|
38
|
+
export const EMPTY_CAPSULE_SCOPE: CapsuleScope = { values: {}, unavailable: [] }
|
package/src/config.ts
CHANGED
|
@@ -105,22 +105,6 @@ export type AxonConfig<EventMap extends Record<string, unknown> = Record<string,
|
|
|
105
105
|
*/
|
|
106
106
|
modules?: ModuleEntry[]
|
|
107
107
|
|
|
108
|
-
/**
|
|
109
|
-
* Prompt packages to load into this agent.
|
|
110
|
-
*
|
|
111
|
-
* Each entry is a registry name — `"@cody/eslint-scout"` — auto-installed
|
|
112
|
-
* at `axon prepare` / `axon dev` like a module. Every top-level .vue/.md
|
|
113
|
-
* in the package becomes an invokable prompt, namespaced by the package
|
|
114
|
-
* so an installed one can never shadow the agent's own:
|
|
115
|
-
*
|
|
116
|
-
* src/prompts/scout.vue → `axon run scout`
|
|
117
|
-
* @cody/eslint-scout:scout → `axon run @cody/eslint-scout:scout`
|
|
118
|
-
*
|
|
119
|
-
* A prompt is the smallest shareable unit of work — an instruction, not a
|
|
120
|
-
* capability. Modules bring tools; prompts bring tasks.
|
|
121
|
-
*/
|
|
122
|
-
prompts?: string[]
|
|
123
|
-
|
|
124
108
|
/**
|
|
125
109
|
* Opt this agent into the repository workspace layer.
|
|
126
110
|
* When true, Axon discovers the nearest .agents/ directory (walking up from cwd)
|
package/src/define.ts
CHANGED
|
@@ -119,13 +119,16 @@ export function defineBench<Schema extends Record<string, unknown> = Record<stri
|
|
|
119
119
|
* top-level `.vue`/`.md` file in the folder is an invokable prompt;
|
|
120
120
|
* `components/` holds the fragments they compose and is never invokable.
|
|
121
121
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
122
|
+
* A prompt has no build step, no dependencies, and no runtime surface of its
|
|
123
|
+
* own. It is text an agent is handed.
|
|
124
|
+
*
|
|
125
|
+
* The config is EMPTY today, deliberately: identity (name, version,
|
|
126
|
+
* description) lives in package.json, which is what publish reads. The call
|
|
127
|
+
* exists because the file's presence is how a prompt package is identified,
|
|
128
|
+
* and configuration is expected to land here.
|
|
124
129
|
*
|
|
125
130
|
* ```ts
|
|
126
|
-
* export default definePrompt({
|
|
127
|
-
* description: "Scouts a codebase and files proposals",
|
|
128
|
-
* })
|
|
131
|
+
* export default definePrompt({})
|
|
129
132
|
* ```
|
|
130
133
|
*/
|
|
131
134
|
export function definePrompt(config: PromptConfig): PromptDefinition {
|
package/src/engine.ts
CHANGED
|
@@ -169,11 +169,53 @@ export type AxonEngineRawEvent =
|
|
|
169
169
|
*/
|
|
170
170
|
export type AxonEngine = {
|
|
171
171
|
/** Stream block events in real time, terminated by a single agent:done. */
|
|
172
|
-
stream: (req:
|
|
172
|
+
stream: (req: AxonEngineCall) => AsyncGenerator<AxonEngineEvent>
|
|
173
173
|
/** Single-shot completion. Same response shape as the stream's done event. */
|
|
174
|
-
request: (req:
|
|
174
|
+
request: (req: AxonEngineCall) => Promise<AxonEngineResponse>
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
/**
|
|
178
|
+
* One call through the engine MANAGER — the driver request plus the grammar
|
|
179
|
+
* to parse the reply with.
|
|
180
|
+
*
|
|
181
|
+
* Protocol lives here rather than on AxonEngineRequest because a driver is a
|
|
182
|
+
* dumb token pipe that never parses anything; only the manager runs the AIR
|
|
183
|
+
* parser. It is per-call rather than per-runtime so one cognet can hold a
|
|
184
|
+
* cortex loop on "classic" and a one-shot classification on "raw" against the
|
|
185
|
+
* same kernel.
|
|
186
|
+
*
|
|
187
|
+
* Omitted means the manager's default. The caller that rendered the context
|
|
188
|
+
* owns this: a cognet rendering one grammar while the kernel parses another
|
|
189
|
+
* would silently discard every block the model emitted.
|
|
190
|
+
*/
|
|
191
|
+
export type AxonEngineCall = AxonEngineRequest & {
|
|
192
|
+
/** The output grammar to parse the reply with. Must match what the caller rendered. */
|
|
193
|
+
protocol?: AirProtocolName
|
|
194
|
+
/**
|
|
195
|
+
* The shape this response must produce, already compiled.
|
|
196
|
+
*
|
|
197
|
+
* Structural rather than a named type because @arcforge/types must not
|
|
198
|
+
* depend on @arcforge/air (which depends on it) — the compiled contract
|
|
199
|
+
* is `CompiledOutput` there, and this is the same shape spelled at the
|
|
200
|
+
* seam. The engine enforces it and retries a response that misses it; no
|
|
201
|
+
* cognet ever sees the check.
|
|
202
|
+
*/
|
|
203
|
+
output?: {
|
|
204
|
+
declaration: string
|
|
205
|
+
check(script: string): readonly { message: string; line?: number }[]
|
|
206
|
+
}
|
|
207
|
+
/** Attempts after a response fails `output`. Ignored without one. Default 2. */
|
|
208
|
+
retries?: number
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The named AIR output grammars. Declared here, not imported from
|
|
213
|
+
* @arcforge/air: the kernel ABI is ring 0 and must not depend on a library
|
|
214
|
+
* above it. The two are kept in step by AirProtocolName in air/types.ts
|
|
215
|
+
* being assignable to this — one is the library's, this is the contract's.
|
|
216
|
+
*/
|
|
217
|
+
export type AirProtocolName = "classic" | "raw"
|
|
218
|
+
|
|
177
219
|
export type AxonEngineMessage = {
|
|
178
220
|
role: "user" | "assistant" | "system"
|
|
179
221
|
content: string
|
package/src/handle.ts
CHANGED
|
@@ -23,6 +23,35 @@ import type { AxonAmbient } from "./session/events/activity"
|
|
|
23
23
|
export type AxonRequestInput = {
|
|
24
24
|
/** One stimulus, or an ordered batch committed before a single wake. */
|
|
25
25
|
prompt: string | string[]
|
|
26
|
+
/**
|
|
27
|
+
* The shape this response must have, as a TypeScript type.
|
|
28
|
+
*
|
|
29
|
+
* output: "{ files: number, issues: { file: string }[] }"
|
|
30
|
+
* output: "type Issue = { file: string }\ntype Output = { issues: Issue[] }"
|
|
31
|
+
*
|
|
32
|
+
* Either a type expression, or declarations whose target is named
|
|
33
|
+
* `Output` — the second form is how a recursive or shared shape is
|
|
34
|
+
* expressed. TypeScript rather than a schema library because the agent's
|
|
35
|
+
* whole model-facing surface is already TypeScript declarations: the
|
|
36
|
+
* model sees its target in the same language as its tools, and there is
|
|
37
|
+
* nothing new for anyone to learn or install.
|
|
38
|
+
*
|
|
39
|
+
* Checked before the model is called (an invalid type throws at the call
|
|
40
|
+
* site, costing no inference), rendered into the model's context, and
|
|
41
|
+
* enforced against the script it writes. A mismatch returns to the model
|
|
42
|
+
* as a real TypeScript diagnostic — which it repairs far more reliably
|
|
43
|
+
* than schema-validator prose.
|
|
44
|
+
*/
|
|
45
|
+
output?: string
|
|
46
|
+
/**
|
|
47
|
+
* Further attempts allowed after a response fails its `output` check.
|
|
48
|
+
* Defaults to 2, so a request makes at most 3 model calls. On
|
|
49
|
+
* exhaustion the invocation throws with the accumulated diagnostics —
|
|
50
|
+
* it never returns a response that does not satisfy the contract.
|
|
51
|
+
*
|
|
52
|
+
* Ignored when `output` is absent: there is nothing to fail.
|
|
53
|
+
*/
|
|
54
|
+
retries?: number
|
|
26
55
|
}
|
|
27
56
|
|
|
28
57
|
/** Result of a completed agent invocation. */
|
package/src/index.ts
CHANGED
package/src/kernel/abi.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AxonEngineCall } from "../engine"
|
|
2
2
|
import type { AxonEngineEvent } from "../session/events/engine"
|
|
3
3
|
import type { AxonEntry } from "../session/session"
|
|
4
4
|
import type { AxonOutputEvent } from "../session/events/stdio/output"
|
|
5
5
|
import type { AxonStimulusEntry } from "../session/events/stdio/stimuli"
|
|
6
6
|
import type { CognetEventMap } from "../session/events/cognet"
|
|
7
7
|
import type { AxonScope } from "../scope"
|
|
8
|
+
import type { CapsuleScope } from "../capsule-scope"
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* The current kernel ABI contract version. Program definitions declare the
|
|
@@ -14,7 +15,7 @@ import type { AxonScope } from "../scope"
|
|
|
14
15
|
*
|
|
15
16
|
* THE VERSIONED SURFACE IS MORE THAN THE FUNCTION SHAPES. A cognet is a
|
|
16
17
|
* prebuilt bundle: it compiled against a snapshot of every payload type
|
|
17
|
-
* this file references — AxonOutputEvent (output),
|
|
18
|
+
* this file references — AxonOutputEvent (output), AxonEngineCall /
|
|
18
19
|
* AxonEngineEvent (stream), CognetEventMap (emit), AxonEntry
|
|
19
20
|
* (the wake wire). A breaking change to ANY of those is a breaking change to the
|
|
20
21
|
* ABI and requires a version bump, even though no signature here moved —
|
|
@@ -104,6 +105,13 @@ export type AxonRunResult = {
|
|
|
104
105
|
value?: unknown
|
|
105
106
|
/** console.* output from this block, in order, one entry per call. */
|
|
106
107
|
stdout: string[]
|
|
108
|
+
/**
|
|
109
|
+
* The top-level bindings this block declared — what a template rendered
|
|
110
|
+
* from the same turn interpolates against. Empty on failure, and empty
|
|
111
|
+
* for a block that declared nothing; never absent, so a caller never has
|
|
112
|
+
* to distinguish "no scope" from "scope unavailable".
|
|
113
|
+
*/
|
|
114
|
+
scope: CapsuleScope
|
|
107
115
|
error?: { kind: "timeout" | "interrupt" | "exception"; message: string }
|
|
108
116
|
}
|
|
109
117
|
|
|
@@ -134,6 +142,17 @@ export type AxonRunResult = {
|
|
|
134
142
|
* It guards the user's base identity and reports the capsule's executable
|
|
135
143
|
* scope; the program alone decides how either enters model context.
|
|
136
144
|
*/
|
|
145
|
+
/**
|
|
146
|
+
* What a cognet may ask of an engine.
|
|
147
|
+
*
|
|
148
|
+
* AxonEngineCall minus the fields the KERNEL owns. `signal` is the wake's
|
|
149
|
+
* cancellation, applied by the kernel unconditionally — a program never
|
|
150
|
+
* passes one and so can never omit one. `output`/`retries` are the caller's
|
|
151
|
+
* structured-output contract, attached from the invocation; a cognet has no
|
|
152
|
+
* business knowing a shape was demanded.
|
|
153
|
+
*/
|
|
154
|
+
export type CognetEngineCall = Omit<AxonEngineCall, "signal" | "output" | "retries">
|
|
155
|
+
|
|
137
156
|
export type KernelAbi = {
|
|
138
157
|
/**
|
|
139
158
|
* Emit a fact to the world — text, audio, visual, or a declared field
|
|
@@ -153,8 +172,14 @@ export type KernelAbi = {
|
|
|
153
172
|
* decides what to do with each: output() a text block, run() a
|
|
154
173
|
* typescript block. The kernel never pre-labels these as the cognet's
|
|
155
174
|
* own committed output; that decision belongs to the cognet alone.
|
|
175
|
+
*
|
|
176
|
+
* `protocol` selects the grammar the reply is parsed with, and belongs
|
|
177
|
+
* to the caller because the caller is what rendered the context — a
|
|
178
|
+
* cognet showing the model one contract while the kernel parsed
|
|
179
|
+
* classic tags would discard every block silently. Omitted keeps the
|
|
180
|
+
* default, so a cognet that never mentions it is unaffected.
|
|
156
181
|
*/
|
|
157
|
-
stream(req:
|
|
182
|
+
stream(req: CognetEngineCall): AsyncGenerator<AxonEngineEvent>
|
|
158
183
|
|
|
159
184
|
/**
|
|
160
185
|
* Execute code in the capsule — ring 3, policy-mediated. The only
|
|
@@ -176,14 +201,8 @@ export type KernelAbi = {
|
|
|
176
201
|
* common "await several tool calls to respond" case needs no manual
|
|
177
202
|
* fan-out.
|
|
178
203
|
*/
|
|
179
|
-
run(code: string
|
|
180
|
-
|
|
181
|
-
signal?: AbortSignal
|
|
182
|
-
}): Promise<AxonRunResult>
|
|
183
|
-
run(code: string[], opts?: {
|
|
184
|
-
/** Wake cancellation. The capsule must stop every in-flight block when aborted. */
|
|
185
|
-
signal?: AbortSignal
|
|
186
|
-
}): Promise<AxonRunResult[]>
|
|
204
|
+
run(code: string): Promise<AxonRunResult>
|
|
205
|
+
run(code: string[]): Promise<AxonRunResult[]>
|
|
187
206
|
|
|
188
207
|
/**
|
|
189
208
|
* The complete TypeScript scope implemented by the current capsule
|
|
@@ -192,6 +211,7 @@ export type KernelAbi = {
|
|
|
192
211
|
*/
|
|
193
212
|
scope(): AxonScope
|
|
194
213
|
|
|
214
|
+
|
|
195
215
|
/**
|
|
196
216
|
* The agent's base context, rendered — boot.md / boot.vue. Kernel-
|
|
197
217
|
* mediated because it's the USER's identity contract, not program
|
|
@@ -209,6 +229,31 @@ export type KernelAbi = {
|
|
|
209
229
|
*/
|
|
210
230
|
emit<K extends keyof CognetEventMap>(type: K, data: CognetEventMap[K]): void
|
|
211
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Report a format violation in the model's output — the model broke the
|
|
234
|
+
* grammar this cognet gave it.
|
|
235
|
+
*
|
|
236
|
+
* Separate from emit() because the OUTCOME is not telemetry: the kernel
|
|
237
|
+
* commits it as axon:system:message, so AIR renders it into the next
|
|
238
|
+
* tick's <system> block and the model reads its own violation and
|
|
239
|
+
* corrects. That is a system fact, and a cognet may not forge one
|
|
240
|
+
* directly (see emit's typing) — so it describes the fault and the kernel
|
|
241
|
+
* writes it.
|
|
242
|
+
*
|
|
243
|
+
* Why a cognet needs this at all: the runtime detects violations it can
|
|
244
|
+
* see in the token stream (an unclosed block), but a cognet that renders
|
|
245
|
+
* the model's output detects its own class of them — an interpolation
|
|
246
|
+
* naming a binding the script never declared. Without this verb the only
|
|
247
|
+
* way to make such a fault visible was to speak it as the agent's own
|
|
248
|
+
* message, which puts a diagnostic in the agent's voice and shows the
|
|
249
|
+
* user machinery they cannot act on.
|
|
250
|
+
*
|
|
251
|
+
* Deliberately NOT user-facing: hosts hide these (see the TUI's
|
|
252
|
+
* isEntryVisible) so a violation is a retry the model performs, not an
|
|
253
|
+
* error the user watches it make.
|
|
254
|
+
*/
|
|
255
|
+
fault(input: { code: string; message: string; excerpt?: string }): Promise<void>
|
|
256
|
+
|
|
212
257
|
/**
|
|
213
258
|
* Private cognitive state + read-only episodic access — see KernelStore.
|
|
214
259
|
* Persistence is a mediated resource like inference (stream) and
|
|
@@ -323,6 +368,19 @@ export type CognetWake = {
|
|
|
323
368
|
* receive.
|
|
324
369
|
*/
|
|
325
370
|
stimuli: readonly AxonStimulusEntry[]
|
|
326
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* Kernel interrupt, for the cognet's OWN work.
|
|
373
|
+
*
|
|
374
|
+
* Everything the kernel mediates — run(), stream() — is cancelled by the
|
|
375
|
+
* kernel itself, unconditionally: a wake's cancellation is not something
|
|
376
|
+
* a program opts into, and threading a signal by hand meant one missing
|
|
377
|
+
* argument made an operation unkillable. Those verbs take no signal at
|
|
378
|
+
* all now.
|
|
379
|
+
*
|
|
380
|
+
* This is what remains: the loop's own units of work between those
|
|
381
|
+
* calls — folding state, evaluating a stop condition, anything running
|
|
382
|
+
* in cognet code. A JS function cannot be preempted, so honouring this
|
|
383
|
+
* is cooperative and always will be. Check it between units and return.
|
|
384
|
+
*/
|
|
327
385
|
signal: AbortSignal
|
|
328
386
|
}
|
package/src/kernel/index.ts
CHANGED
package/src/prompts.ts
CHANGED
|
@@ -38,16 +38,20 @@ export type AxonPrompt = {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* `prompt.config.ts` — a prompt package's
|
|
41
|
+
* `prompt.config.ts` — a prompt package's marker.
|
|
42
42
|
*
|
|
43
|
-
* Deliberately
|
|
44
|
-
* runtime surface: the folder's top-level .vue/.md files ARE the artifact
|
|
45
|
-
*
|
|
43
|
+
* Deliberately EMPTY. A prompt has no dependencies, no build output and no
|
|
44
|
+
* runtime surface: the folder's top-level .vue/.md files ARE the artifact.
|
|
45
|
+
*
|
|
46
|
+
* Identity (name, version, description) lives in package.json, which is what
|
|
47
|
+
* publish actually reads — see `bundle/source.ts`. This type carried a
|
|
48
|
+
* `description` that no code ever read, so a package could set it and watch
|
|
49
|
+
* the registry list something else.
|
|
50
|
+
*
|
|
51
|
+
* The config FILE stays: its presence is how `detectKind()` identifies a
|
|
52
|
+
* prompt package, and real per-prompt configuration is expected here.
|
|
46
53
|
*/
|
|
47
|
-
export type PromptConfig =
|
|
48
|
-
/** One line, shown in the registry listing and `axon prompt list`. */
|
|
49
|
-
description?: string
|
|
50
|
-
}
|
|
54
|
+
export type PromptConfig = Record<string, never>
|
|
51
55
|
|
|
52
56
|
/** Return shape produced by `definePrompt()`. */
|
|
53
57
|
export type PromptDefinition = {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import type { Activity } from "./activity"
|
|
23
23
|
import type { AxonErrorJSON } from "../../error"
|
|
24
24
|
import type { AxonCancellableSpan, AxonSpan } from "./span"
|
|
25
|
+
import type { CapsuleScope } from "../../capsule-scope"
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Capsule failures carry AxonErrorJSON, not AxonError.
|
|
@@ -71,7 +72,7 @@ export type CapsuleEventMap =
|
|
|
71
72
|
& AxonCancellableSpan<
|
|
72
73
|
"capsule:cmd",
|
|
73
74
|
{ id: string },
|
|
74
|
-
{ id: string; result: unknown },
|
|
75
|
+
{ id: string; result: unknown; scope: CapsuleScope },
|
|
75
76
|
{ id: string; error: AxonErrorJSON },
|
|
76
77
|
{ id: string; durationMs: number }
|
|
77
78
|
>
|
|
@@ -1,46 +1,102 @@
|
|
|
1
1
|
import type { AxonEngineResponse } from "../../engine"
|
|
2
|
+
import type { AxonError } from "../../error"
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
* The engine wire contract — what
|
|
5
|
-
* kernel.stream() hands
|
|
6
|
-
* not agent:* cosplaying as the cognet's own committed vocabulary — the
|
|
7
|
-
* cognet reads these and DECIDES whether/how to act (output() a block,
|
|
8
|
-
* run() a code block); it never receives something pre-labeled as its own
|
|
9
|
-
* output. kernel:engine:* (the tick/phase telemetry, unrelated file) is the
|
|
10
|
-
* durable accounting span around a call; this is the call's actual content.
|
|
5
|
+
* The engine wire contract — what AxonEngine.stream() yields and what
|
|
6
|
+
* kernel.stream() hands a cognet.
|
|
11
7
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
8
|
+
* EVERY EVENT HERE IS A FINISHED MECHANISM, NOT A DECISION. The kernel owns
|
|
9
|
+
* the output half of the model service: parsing AIR, running the script,
|
|
10
|
+
* rendering the template against its bindings, enforcing a declared output
|
|
11
|
+
* shape, retrying a malformed response. A cognet receives what the model
|
|
12
|
+
* PRODUCED, never machinery it has to finish itself.
|
|
17
13
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
14
|
+
* What the kernel never decides is whether any of it reaches the world.
|
|
15
|
+
* These are engine:* — the call's content — and emitting is still the
|
|
16
|
+
* cognet's own act through output(). A brain may call an engine to classify
|
|
17
|
+
* a stimulus or judge its own stop condition, and neither is the agent
|
|
18
|
+
* speaking; the kernel cannot tell those apart from a reply, because which
|
|
19
|
+
* is which is a cognitive fact. So it hands back what happened and the
|
|
20
|
+
* cognet routes it.
|
|
21
|
+
*
|
|
22
|
+
* The vocabulary is deliberately small, and named for DATA rather than for
|
|
23
|
+
* the tag that produced it. Every model response reduces to the same two
|
|
24
|
+
* things: a structure it produced, and optionally the computation it ran to
|
|
25
|
+
* get there. `<text>` is a template with lang="md" and no script; a JSON
|
|
26
|
+
* response is lang="json". So there is one spoken event and one action event,
|
|
27
|
+
* whatever protocol was in force.
|
|
28
|
+
*
|
|
29
|
+
* Reasoning/"thinking" tokens are dropped at the adapter boundary and never
|
|
30
|
+
* reach this wire — thinking was never a data kind, it was one inference
|
|
31
|
+
* pipeline's internal stage.
|
|
20
32
|
*/
|
|
33
|
+
export type AxonEngineEvent =
|
|
34
|
+
/** The call began. The bracket's open half — a consumer showing "thinking" starts here rather than inferring from the first token. */
|
|
35
|
+
| { type: "engine:start" }
|
|
21
36
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The agent spoke — already interpolated, exactly as a user reads it.
|
|
39
|
+
* Never unrendered template source and never a raw brace.
|
|
40
|
+
*
|
|
41
|
+
* `lang` is the structure the model produced ("md" prose, "json" for a
|
|
42
|
+
* declared output shape), so a consumer can tell a message from a value
|
|
43
|
+
* without knowing which protocol was rendered.
|
|
44
|
+
*
|
|
45
|
+
* `chunk` carries the AxonChunk correlation group while streaming; a
|
|
46
|
+
* complete one-shot block has none. NOTE these are chunks of RENDERED
|
|
47
|
+
* output, so they no longer correspond 1:1 to model tokens — one delta
|
|
48
|
+
* can emit nothing (buffered mid-interpolation) or a great deal (a large
|
|
49
|
+
* interpolated value).
|
|
50
|
+
*/
|
|
51
|
+
| {
|
|
52
|
+
type: "engine:text"
|
|
53
|
+
content: string
|
|
54
|
+
lang: "md" | "json"
|
|
55
|
+
chunk?: { of: string; final?: boolean }
|
|
56
|
+
}
|
|
25
57
|
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
58
|
+
/**
|
|
59
|
+
* The model ran code. Reported for the record — the kernel already
|
|
60
|
+
* executed it and committed the result, so a cognet reads this to know
|
|
61
|
+
* what happened, never to act on it.
|
|
62
|
+
*/
|
|
63
|
+
| { type: "engine:script"; id: string; content: string }
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The call could not produce a usable response — a malformed reply the
|
|
67
|
+
* model failed to correct within its retries, or a declared output shape
|
|
68
|
+
* it never satisfied. Terminal for this call: no `engine:done` follows.
|
|
69
|
+
*/
|
|
70
|
+
| { type: "engine:failure"; error: AxonError }
|
|
33
71
|
|
|
34
|
-
export type AxonEngineEvent =
|
|
35
|
-
| AxonEngineDelta
|
|
36
|
-
| AxonEngineBlock
|
|
37
72
|
/**
|
|
38
|
-
* The
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
73
|
+
* The call ended. Exactly once per successful call, carrying the
|
|
74
|
+
* authoritative response and billing meta.
|
|
75
|
+
*
|
|
76
|
+
* The booleans are SIGNALS, not decisions — reductions over what this
|
|
77
|
+
* call produced, from which a loop derives its own stop condition. The
|
|
78
|
+
* kernel never acts on them and deliberately does not decide whether a
|
|
79
|
+
* turn is over: that is the one thing a loop is for.
|
|
80
|
+
*
|
|
81
|
+
* `yielded` is the model's own <done/>, and it is here under protest.
|
|
82
|
+
* Whether a turn is over is a SEMANTIC question — "I see the issue" and
|
|
83
|
+
* "the fix is deployed" are structurally identical, same block and no
|
|
84
|
+
* script — so no reduction over what a response DID can separate a
|
|
85
|
+
* progress report from a final answer. Deriving it structurally ends a
|
|
86
|
+
* long run the first time the model narrates between actions.
|
|
87
|
+
*
|
|
88
|
+
* So the model is asked, which works consistently enough. It stays a
|
|
89
|
+
* SIGNAL: the kernel never acts on it, and a loop weighs it against the
|
|
90
|
+
* structural facts beside it. Replacing it needs something that can judge
|
|
91
|
+
* the situation rather than the response.
|
|
43
92
|
*/
|
|
44
|
-
| {
|
|
45
|
-
|
|
46
|
-
|
|
93
|
+
| {
|
|
94
|
+
type: "engine:done"
|
|
95
|
+
response: AxonEngineResponse
|
|
96
|
+
/** The agent produced user-facing output this call. */
|
|
97
|
+
spoke: boolean
|
|
98
|
+
/** The model emitted a script this call — code it has not yet seen the result of. */
|
|
99
|
+
acted: boolean
|
|
100
|
+
/** The model emitted <done/> — its own claim that it is handing control back. */
|
|
101
|
+
yielded: boolean
|
|
102
|
+
}
|
package/src/session/index.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { isBuildEvent } from "./events/build"
|
|
|
12
12
|
export type { Activity, ActivityHandle, ActivityPayloads, ActivityPhase, ActivityType, AxonAmbient } from "./events/activity"
|
|
13
13
|
export { CAPSULE_TRANSIENT_EVENTS } from "./events/capsule"
|
|
14
14
|
export type { AxonRuntimeEvent } from "./events/runtime"
|
|
15
|
-
export type {
|
|
15
|
+
export type { AxonEngineEvent } from "./events/engine"
|
|
16
16
|
export type { AxonEntryEvent } from "./events/entries"
|
|
17
17
|
export { ENTRY_EVENT_PREFIXES } from "./events/entries"
|
|
18
18
|
export { isKernelEvent, isEntryEvent, classifyEvent, type AxonEventView } from "./classify"
|