@arcforge/types 2.0.110 → 2.0.112
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/cognet/blueprint.ts +12 -0
- package/src/cognet/cognet.ts +58 -0
- package/src/cognet/index.ts +1 -1
- package/src/handle.ts +46 -15
- package/src/kernel/abi.ts +85 -1
- package/src/kernel/index.ts +1 -1
- package/src/prompts.ts +13 -0
- package/src/session/events/build.ts +151 -0
- package/src/session/events/runtime.ts +11 -0
- package/src/session/events/stdio/stimuli.ts +29 -0
- package/src/session/index.ts +3 -0
- package/src/session/read.ts +27 -2
- package/src/session/session.ts +12 -2
package/package.json
CHANGED
package/src/cognet/blueprint.ts
CHANGED
|
@@ -24,6 +24,18 @@ export type CognetBlueprint = {
|
|
|
24
24
|
abi: string
|
|
25
25
|
/** Declarative wake mask — overrides the definition's own default. */
|
|
26
26
|
wakeOn?: Array<keyof AxonEntryEvent>
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Resolved model weights — the cognet's local name → an absolute path on
|
|
30
|
+
* THIS machine, already fetched and verified.
|
|
31
|
+
*
|
|
32
|
+
* Carried on the blueprint rather than resolved by the kernel because
|
|
33
|
+
* acquisition is a build-time concern (it downloads, it verifies, it can
|
|
34
|
+
* fail loudly at prepare); the runtime only hands the paths over. That
|
|
35
|
+
* also keeps the seam where a deployment image bakes weights in at build
|
|
36
|
+
* time and the runtime cannot tell the difference.
|
|
37
|
+
*/
|
|
38
|
+
models?: Readonly<Record<string, string>>
|
|
27
39
|
} & (
|
|
28
40
|
| {
|
|
29
41
|
/** Absolute path to the compiled bundle — <agent>/.agent/cognet/cognet.mjs. */
|
package/src/cognet/cognet.ts
CHANGED
|
@@ -59,8 +59,66 @@ export type CognetConfig = {
|
|
|
59
59
|
|
|
60
60
|
/** Hard safety bound for one wake. Strategy may stop earlier; default is 8 ticks. */
|
|
61
61
|
maxTicksPerWake?: number
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Model weights this brain needs, by the name IT calls them.
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* models: {
|
|
68
|
+
* vad: "hf:runanywhere/silero-vad-v5/silero_vad.onnx",
|
|
69
|
+
* asr: "hf:ggerganov/whisper.cpp/ggml-base.en.bin",
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* Weights are DATA, not code — a `.onnx` file is inert until something
|
|
74
|
+
* reads it. The runtime that executes it (onnxruntime, llama.cpp) is an
|
|
75
|
+
* ordinary npm dependency the cognet imports, chosen by the author. This
|
|
76
|
+
* field only says which bytes are needed; how to run them is cognition.
|
|
77
|
+
*
|
|
78
|
+
* That is also why there is no unified `runModel()`: every model has its
|
|
79
|
+
* own tensor signature, so a generic invoke could only pass `unknown`
|
|
80
|
+
* through. Acquisition collapses to one mechanism; inference cannot.
|
|
81
|
+
*
|
|
82
|
+
* A MAP, not a list, because the key is the brain's own vocabulary.
|
|
83
|
+
* `kernel.models.vad` says what the weight is FOR; the specifier says
|
|
84
|
+
* where it came from. Swapping to a different VAD is one line here rather
|
|
85
|
+
* than an edit at every call site — and a brain that referenced its
|
|
86
|
+
* supply chain at every use would have learned something it does not
|
|
87
|
+
* need to know.
|
|
88
|
+
*
|
|
89
|
+
* Axon fetches, verifies and caches these; the resolved paths arrive at
|
|
90
|
+
* load through `kernel.models`, never read from this config. A path is
|
|
91
|
+
* environmental, and a cognet learns nothing about its environment except
|
|
92
|
+
* through the kernel.
|
|
93
|
+
*/
|
|
94
|
+
models?: Record<string, ModelRef>
|
|
62
95
|
}
|
|
63
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Where a weight comes from.
|
|
99
|
+
*
|
|
100
|
+
* `"hf:owner/repo/path/to/file.onnx"` is the short form and covers almost
|
|
101
|
+
* everything. The object form exists for the two things a string cannot
|
|
102
|
+
* carry: a revision pin, and an expected hash.
|
|
103
|
+
*
|
|
104
|
+
* `sha256` is the difference between "verified" and "verified against
|
|
105
|
+
* something I chose". Without it, first fetch is trust-on-first-use — the
|
|
106
|
+
* bytes that arrived become the bytes that are correct forever. With it, a
|
|
107
|
+
* compromised or silently-replaced upstream file fails loudly.
|
|
108
|
+
*/
|
|
109
|
+
export type ModelRef =
|
|
110
|
+
| string
|
|
111
|
+
| {
|
|
112
|
+
/** `owner/repo` on Hugging Face. */
|
|
113
|
+
hf: string
|
|
114
|
+
/** Path within the repo — a repo is a directory, and repos hold many weights. */
|
|
115
|
+
file: string
|
|
116
|
+
/** Git revision. Defaults to `main`. */
|
|
117
|
+
rev?: string
|
|
118
|
+
/** Expected content hash. Pin it and a changed upstream is an error, not a surprise. */
|
|
119
|
+
sha256?: string
|
|
120
|
+
}
|
|
121
|
+
|
|
64
122
|
export type CognetDefinition = CognetConfig & {
|
|
65
123
|
|
|
66
124
|
/** exec(): receives the syscall table. Runs once, before any wake. */
|
package/src/cognet/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type { CognetConfig, CognetDefinition, CognetSchedule } from "./cognet"
|
|
1
|
+
export type { CognetConfig, CognetDefinition, CognetSchedule, ModelRef } from "./cognet"
|
|
2
2
|
export type { CognetBlueprint } from "./blueprint"
|
|
3
3
|
export type { CognetHooks, CognetHookName, CognetPlugin, CognetPluginContext } from "./hooks"
|
package/src/handle.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AxonEntry, AxonKernelEvent, AxonSessionEvent, AxonStimulusEvent, AxonStimulusType } from "./session"
|
|
2
|
+
import type { AxonOutputEvent } from "./session/events/stdio/output"
|
|
2
3
|
import type { AxonScript } from "./scripts"
|
|
3
4
|
import type { AxonPrompt } from "./prompts"
|
|
4
5
|
import type { AxonPartialBlueprint } from "./blueprint"
|
|
@@ -178,26 +179,56 @@ export type AxonHandle = {
|
|
|
178
179
|
stim<K extends AxonStimulusType>(type: K, data: AxonStimulusEvent[K]): Promise<AxonEntry>
|
|
179
180
|
|
|
180
181
|
/**
|
|
181
|
-
*
|
|
182
|
-
* have arrived since the last one. The clock is yours: a body knows how
|
|
183
|
-
* fast its world turns, a brain does not.
|
|
182
|
+
* Observe what the brain emits — the counterpart to `stim()`.
|
|
184
183
|
*
|
|
185
184
|
* ```ts
|
|
186
|
-
* // server/plugins/
|
|
187
|
-
*
|
|
188
|
-
* world.step(dt)
|
|
189
|
-
* await axon.stim("cognet:stimulus:field", { ... })
|
|
190
|
-
* await axon.tick()
|
|
191
|
-
* }, 33)
|
|
185
|
+
* // server/plugins/speaker.ts
|
|
186
|
+
* axon.on("cognet:output:audio", async ({ ref }) => play(ref))
|
|
192
187
|
* ```
|
|
193
188
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
189
|
+
* A body could always send sensations IN and never see what came OUT. The
|
|
190
|
+
* asymmetry was invisible while every effect was a tool call — those reach
|
|
191
|
+
* the body through the capsule — but `kernel.output()` is the unmediated
|
|
192
|
+
* door, and nothing downstream could listen at it. A cognet that speaks
|
|
193
|
+
* had no way to be heard.
|
|
194
|
+
*
|
|
195
|
+
* Typed against the OUTPUT protocol only, not the whole entry vocabulary.
|
|
196
|
+
* Stimuli are the body's own input and it does not need to observe what it
|
|
197
|
+
* sent; actions already arrive as tool calls. What was missing is exactly
|
|
198
|
+
* this: the four kinds a mind emits.
|
|
199
|
+
*
|
|
200
|
+
* The brain is never told whether anyone listened, and must not be. That
|
|
201
|
+
* is what lets the same cognet run in a body with a speaker, a body with a
|
|
202
|
+
* WebRTC track, and a body with neither — emitting identically in all
|
|
203
|
+
* three. A handler that throws is logged and swallowed for the same
|
|
204
|
+
* reason: a broken speaker is not the mind's problem, and an emission that
|
|
205
|
+
* already committed cannot be un-emitted.
|
|
206
|
+
*
|
|
207
|
+
* Returns an unsubscribe.
|
|
199
208
|
*/
|
|
200
|
-
|
|
209
|
+
on<K extends keyof AxonOutputEvent>(
|
|
210
|
+
type: K,
|
|
211
|
+
handler: (data: AxonOutputEvent[K]) => void | Promise<void>,
|
|
212
|
+
): () => void
|
|
213
|
+
|
|
214
|
+
// There is deliberately no tick()/wake() here. A body emits stimuli and
|
|
215
|
+
// never decides when the brain looks at them:
|
|
216
|
+
//
|
|
217
|
+
// ```ts
|
|
218
|
+
// // server/plugins/body.ts — sense, unconditionally
|
|
219
|
+
// setInterval(async () => {
|
|
220
|
+
// world.step(dt)
|
|
221
|
+
// await axon.stim("cognet:stimulus:field", { ... })
|
|
222
|
+
// }, 16)
|
|
223
|
+
// ```
|
|
224
|
+
//
|
|
225
|
+
// How fast frames arrive is a property of a sensor. How often it is worth
|
|
226
|
+
// thinking about them is a property of a mind — so the brain drives its
|
|
227
|
+
// own rhythm through `kernel.wake()`, from a cognet plugin. That keeps
|
|
228
|
+
// bodies swappable (one that drove a specific brain had to be rewritten
|
|
229
|
+
// whenever the brain changed) and is the only answer that survives
|
|
230
|
+
// composition, where two sensors at different rates have equal claim to
|
|
231
|
+
// being "the" tick.
|
|
201
232
|
|
|
202
233
|
scripts: {
|
|
203
234
|
request(name: string, args?: Record<string, unknown>): Promise<unknown>
|
package/src/kernel/abi.ts
CHANGED
|
@@ -23,7 +23,7 @@ import type { AxonScope } from "../scope"
|
|
|
23
23
|
* the rule is the enforcement. (Additive changes — new event types, new
|
|
24
24
|
* optional fields — are compatible, like new syscalls.)
|
|
25
25
|
*/
|
|
26
|
-
export const KERNEL_ABI_VERSION = "
|
|
26
|
+
export const KERNEL_ABI_VERSION = "10"
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* The cognet's own store schema — EMPTY here by design. A cognet declares
|
|
@@ -217,6 +217,90 @@ export type KernelAbi = {
|
|
|
217
217
|
* tomorrow, invisible either way).
|
|
218
218
|
*/
|
|
219
219
|
store: KernelStore
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Wake the brain — the mind's own rhythm, driven from inside it.
|
|
223
|
+
*
|
|
224
|
+
* THE BODY DOES NOT DRIVE THE BRAIN. This used to be `axon.tick()` on the
|
|
225
|
+
* agent handle, so a plugin in the body decided how often the mind ran.
|
|
226
|
+
* That is the body asserting a fact about cognition it cannot know: how
|
|
227
|
+
* fast frames arrive is a property of a sensor, how often it is worth
|
|
228
|
+
* thinking about them is a property of a mind. It also broke the swap
|
|
229
|
+
* test — a body that drives a specific brain has to be rewritten when the
|
|
230
|
+
* brain changes, which is exactly the coupling the split exists to
|
|
231
|
+
* prevent. And it has no answer under composition: two sensors at 31Hz
|
|
232
|
+
* and 60Hz cannot both be "the" tick rate.
|
|
233
|
+
*
|
|
234
|
+
* So the body only ever emits stimuli, and the brain decides when to
|
|
235
|
+
* look. A cognet plugin owns the clock:
|
|
236
|
+
*
|
|
237
|
+
* ```ts
|
|
238
|
+
* // plugins/clock.ts
|
|
239
|
+
* export default definePlugin(({ hooks }) => {
|
|
240
|
+
* hooks.on("boot", () => {
|
|
241
|
+
* setInterval(() => void kernel.wake(), 1000 / 30)
|
|
242
|
+
* })
|
|
243
|
+
* })
|
|
244
|
+
* ```
|
|
245
|
+
*
|
|
246
|
+
* Resolves with this wake's ordinal AS SOON AS IT IS ADMITTED — never
|
|
247
|
+
* when it completes. A driver that awaited completion would serialise the
|
|
248
|
+
* overlap that continuous mode exists to allow, turning `await tick()`
|
|
249
|
+
* into skip-on-overlap by the back door.
|
|
250
|
+
*
|
|
251
|
+
* Continuous cognets only. An invocation cognet is woken by a stimulus
|
|
252
|
+
* arriving, and waking itself would be a second, contradictory trigger.
|
|
253
|
+
*
|
|
254
|
+
* Named `wake`, not `tick`, because that is what it does: it invokes the
|
|
255
|
+
* loop. A tick is one ITERATION inside a wake — the counter `phase()`
|
|
256
|
+
* telemetry stamps against (`cognet:tick:*`). Two scales, two words.
|
|
257
|
+
*/
|
|
258
|
+
wake(): Promise<number>
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* A snapshot of the scheduler's clock. A function, not a live getter:
|
|
262
|
+
* with wakes overlapping, the count moves between reads, and a value read
|
|
263
|
+
* at a moment is honest where a live reference is not.
|
|
264
|
+
*/
|
|
265
|
+
clock(): KernelClock
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Absolute paths to the weights this cognet declared, by the name it gave
|
|
269
|
+
* them. Empty when none were declared.
|
|
270
|
+
*
|
|
271
|
+
* ```ts
|
|
272
|
+
* const session = await ort.InferenceSession.create(kernel.models.vad)
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* Handed over at load rather than read from the cognet's own config,
|
|
276
|
+
* because a filesystem path is ENVIRONMENTAL: the same brain gets a
|
|
277
|
+
* different absolute path on every machine, and must never learn that.
|
|
278
|
+
* The config says which weights are needed; this says where they landed.
|
|
279
|
+
*
|
|
280
|
+
* Whether they were fetched from a registry, restored from a shared
|
|
281
|
+
* cache, or baked into a deployment image is invisible here — the kernel
|
|
282
|
+
* guarantees the file exists and was verified, nothing more.
|
|
283
|
+
*/
|
|
284
|
+
models: Readonly<Record<string, string>>
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* What the brain can know about its own rhythm.
|
|
289
|
+
*
|
|
290
|
+
* Deliberately thin. `ticks` is what a multi-rate mind needs to schedule
|
|
291
|
+
* itself against — "every fourth tick, do the slow thing" — and nothing more
|
|
292
|
+
* has earned a place here yet.
|
|
293
|
+
*/
|
|
294
|
+
export type KernelClock = {
|
|
295
|
+
/**
|
|
296
|
+
* Wakes admitted since boot. Process-lifetime and monotonic.
|
|
297
|
+
*
|
|
298
|
+
* NOT the per-wake tick counter that `phase()` telemetry stamps against
|
|
299
|
+
* (see Clock in @arcforge/cognet, which resets every wake). Two different
|
|
300
|
+
* numbers at two scales: this counts how many times the brain has been
|
|
301
|
+
* woken, that counts how far the current wake has got.
|
|
302
|
+
*/
|
|
303
|
+
wakes: number
|
|
220
304
|
}
|
|
221
305
|
|
|
222
306
|
/**
|
package/src/kernel/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { KERNEL_ABI_VERSION } from "./abi"
|
|
2
|
-
export type { KernelAbi, CognetWake, AxonRunResult, KernelStore } from "./abi"
|
|
2
|
+
export type { KernelAbi, CognetWake, AxonRunResult, KernelStore, KernelClock } from "./abi"
|
package/src/prompts.ts
CHANGED
|
@@ -13,6 +13,19 @@ export type AxonPrompt = {
|
|
|
13
13
|
* Present for agent-owned and module prompts; absent for inline prompts.
|
|
14
14
|
*/
|
|
15
15
|
filePath?: string
|
|
16
|
+
/**
|
|
17
|
+
* Components this prompt may compose, as PascalCase name → absolute path.
|
|
18
|
+
*
|
|
19
|
+
* Resolved at scan time rather than at render: the renderer would
|
|
20
|
+
* otherwise have to re-derive the owning root from filePath and hit the
|
|
21
|
+
* filesystem on every call, and a prompt package's components sit at a
|
|
22
|
+
* different depth from an agent's. Scanning already knows both.
|
|
23
|
+
*
|
|
24
|
+
* Components are not prompts — they are never invokable, and exist only
|
|
25
|
+
* to be inlined into one at render time.
|
|
26
|
+
*/
|
|
27
|
+
components?: Record<string, string>
|
|
28
|
+
|
|
16
29
|
/** Props required by a dynamic prompt. Present only for dynamic prompts. */
|
|
17
30
|
props?: Array<{
|
|
18
31
|
/** Prop name. */
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { AxonError } from "../../error"
|
|
2
|
+
import type { AxonSpan } from "./span"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* BuildEventMap — everything that happens BEFORE a runtime exists.
|
|
6
|
+
*
|
|
7
|
+
* The `build:` namespace is the boundary marker. Every other family in
|
|
8
|
+
* this registry (`axon:`, `kernel:`, `cognet:`, `capsule:`) is emitted BY
|
|
9
|
+
* a running Axon; these are emitted while one is being made. Reading a
|
|
10
|
+
* log, the first `axon:boot:start` is exactly where the build ended and
|
|
11
|
+
* the runtime began — no other signal is needed to place that line.
|
|
12
|
+
*
|
|
13
|
+
* WHY THIS EXISTS. The build phase was the largest untraced path in the
|
|
14
|
+
* system, and the one that fails most often while you are actively
|
|
15
|
+
* changing things. A cognet ABI mismatch, an unresolvable module, a failed
|
|
16
|
+
* `bun install` — all threw straight to the terminal and left nothing on
|
|
17
|
+
* disk, because the session was opened by `Axon()` and `Axon()` had not
|
|
18
|
+
* run yet. The debugger was blind precisely when it was needed most: the
|
|
19
|
+
* agent that failed to boot produced no instance, no session, and no
|
|
20
|
+
* trace of why.
|
|
21
|
+
*
|
|
22
|
+
* The fix is ordering, not a new artifact: the session opens first, the
|
|
23
|
+
* build reports into it, and a failed build leaves a readable session
|
|
24
|
+
* instead of nothing. Every existing surface — the Events pane, the flame
|
|
25
|
+
* graph, Fleet's Sessions group — reads it unchanged, because it is the
|
|
26
|
+
* same log with the same span convention.
|
|
27
|
+
*
|
|
28
|
+
* THREE STAGES, IN ORDER. `build:open` finds and opens the project;
|
|
29
|
+
* `build:prepare` installs, compiles and reconciles it; `build:load` scans
|
|
30
|
+
* it into a blueprint. They are siblings under `build` rather than one
|
|
31
|
+
* flat sequence because each can fail on its own terms, and knowing WHICH
|
|
32
|
+
* failed is most of the diagnosis.
|
|
33
|
+
*
|
|
34
|
+
* Durability: every event here is committed. There are no transient build
|
|
35
|
+
* events — the phase is seconds long and low-volume, and its whole purpose
|
|
36
|
+
* is to be readable after the fact.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/** Which sub-stage of prepare a unit belongs to — the flame graph groups on it. */
|
|
40
|
+
export type BuildStage =
|
|
41
|
+
| "framework"
|
|
42
|
+
| "modules"
|
|
43
|
+
| "cognet"
|
|
44
|
+
| "tree"
|
|
45
|
+
| "scan"
|
|
46
|
+
| "typegen"
|
|
47
|
+
|
|
48
|
+
export type BuildEventMap =
|
|
49
|
+
// ── The whole pre-runtime phase ─────────────────────────────────────────
|
|
50
|
+
// One span around everything below, so a reader sees the total cost of
|
|
51
|
+
// "getting to a runtime" without summing its parts.
|
|
52
|
+
& AxonSpan<
|
|
53
|
+
"build",
|
|
54
|
+
{ root: string; agent?: string },
|
|
55
|
+
{ root: string },
|
|
56
|
+
{ root: string; stage: BuildStage | "open" | "prepare" | "load"; error: AxonError }
|
|
57
|
+
>
|
|
58
|
+
|
|
59
|
+
// ── Stage 1: open ───────────────────────────────────────────────────────
|
|
60
|
+
// Find the project from a cwd and open it. Fails when there is no
|
|
61
|
+
// project at or above the path, or when it is the wrong kind.
|
|
62
|
+
& AxonSpan<
|
|
63
|
+
"build:open",
|
|
64
|
+
{ cwd: string },
|
|
65
|
+
{ root: string; kind: string; name: string }
|
|
66
|
+
>
|
|
67
|
+
|
|
68
|
+
// ── Stage 2: prepare ────────────────────────────────────────────────────
|
|
69
|
+
// Everything that makes the project runnable. The expensive stage —
|
|
70
|
+
// a cold `bun install` dominates it — and the one with the most ways
|
|
71
|
+
// to fail, which is why its interior is broken out below.
|
|
72
|
+
& AxonSpan<"build:prepare", { root: string }, { warnings: number }>
|
|
73
|
+
|
|
74
|
+
// ── Prepare's units ─────────────────────────────────────────────────────
|
|
75
|
+
// One span each, at the granularity where a failure is actionable:
|
|
76
|
+
// knowing the cognet's ABI gate rejected the build tells you what to
|
|
77
|
+
// fix, and knowing which line of it did would not.
|
|
78
|
+
& AxonSpan<
|
|
79
|
+
"build:framework",
|
|
80
|
+
{ version: string },
|
|
81
|
+
{ version: string; changed: boolean }
|
|
82
|
+
>
|
|
83
|
+
& AxonSpan<
|
|
84
|
+
"build:modules",
|
|
85
|
+
{ specifiers: string[] },
|
|
86
|
+
{ installed: string[]; alreadyPresent: string[] }
|
|
87
|
+
>
|
|
88
|
+
& AxonSpan<
|
|
89
|
+
"build:cognet",
|
|
90
|
+
{ specifier: string | null },
|
|
91
|
+
{ name: string; version: string; abi: string; compiled: boolean }
|
|
92
|
+
>
|
|
93
|
+
/** `bun install` in the project. Usually the slowest span in the phase. */
|
|
94
|
+
& AxonSpan<
|
|
95
|
+
"build:tree",
|
|
96
|
+
{ reason: "framework" | "modules" | "reconcile" },
|
|
97
|
+
{ durationMs: number }
|
|
98
|
+
>
|
|
99
|
+
& AxonSpan<"build:typegen", {}, { files: string[] }>
|
|
100
|
+
|
|
101
|
+
// ── Stage 3: load ───────────────────────────────────────────────────────
|
|
102
|
+
// Scan the prepared project into a blueprint. The last thing before
|
|
103
|
+
// `Axon()`, and the point at which the agent's shape is known.
|
|
104
|
+
& AxonSpan<
|
|
105
|
+
"build:load",
|
|
106
|
+
{ root: string },
|
|
107
|
+
{ agent: string; tools: number; prompts: number; modules: number; warnings: number }
|
|
108
|
+
>
|
|
109
|
+
/**
|
|
110
|
+
* One scanned domain — tools, prompts, routes, components, plugins,
|
|
111
|
+
* middleware. Nested inside build:load, so the flame graph shows which
|
|
112
|
+
* part of a slow scan is slow.
|
|
113
|
+
*/
|
|
114
|
+
& AxonSpan<
|
|
115
|
+
"build:scan",
|
|
116
|
+
{ domain: string },
|
|
117
|
+
{ domain: string; found: number },
|
|
118
|
+
{ domain: string; error: AxonError }
|
|
119
|
+
>
|
|
120
|
+
|
|
121
|
+
& {
|
|
122
|
+
/**
|
|
123
|
+
* A recoverable defect found during the build — a tool shadowed by
|
|
124
|
+
* one of the same name, a component that will not resolve.
|
|
125
|
+
*
|
|
126
|
+
* Deliberately NOT a `:failed`: the build continues and produces a
|
|
127
|
+
* working agent, but something the author declared is not in it.
|
|
128
|
+
* These were previously committed as `axon:scan:warning` from
|
|
129
|
+
* inside the runtime, which meant they arrived AFTER boot and only
|
|
130
|
+
* for builds that got that far.
|
|
131
|
+
*/
|
|
132
|
+
"build:warning": { domain: string; message: string; stage?: BuildStage }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type BuildEventName = keyof BuildEventMap
|
|
136
|
+
|
|
137
|
+
/** One build event as it travels the bus: { type } + payload, flat. */
|
|
138
|
+
export type AnyBuildEvent = {
|
|
139
|
+
[K in BuildEventName]: { type: K } & BuildEventMap[K]
|
|
140
|
+
}[BuildEventName]
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* True for anything emitted before the runtime existed.
|
|
144
|
+
*
|
|
145
|
+
* The one place a reader should decide "is this a build event" — the
|
|
146
|
+
* prefix is the contract, and a consumer sniffing for individual names
|
|
147
|
+
* breaks the moment a stage is added.
|
|
148
|
+
*/
|
|
149
|
+
export function isBuildEvent(type: string): boolean {
|
|
150
|
+
return type === "build" || type.startsWith("build:")
|
|
151
|
+
}
|
|
@@ -60,6 +60,17 @@ export type AxonRuntimeEvent =
|
|
|
60
60
|
{ name: string },
|
|
61
61
|
{ name: string; error: AxonError }
|
|
62
62
|
>
|
|
63
|
+
// ── Model change (config edit, then a reload rides the hot-swap path) ───
|
|
64
|
+
// The agent is the same agent; only the engine underneath it moved.
|
|
65
|
+
// `dropped` names options the previous provider had that the new one
|
|
66
|
+
// does not accept (e.g. Codex's `effort`), so the change is never a
|
|
67
|
+
// silent loss of the author's configuration.
|
|
68
|
+
& AxonSpan<
|
|
69
|
+
"axon:model",
|
|
70
|
+
{ name: string },
|
|
71
|
+
{ name: string; changed: boolean; dropped: string[] },
|
|
72
|
+
{ name: string; error: AxonError }
|
|
73
|
+
>
|
|
63
74
|
// ── Module setup/teardown (boot-time defineModule() setup execution) ─────
|
|
64
75
|
// The determinism ledger: one start/complete (or failed) per module,
|
|
65
76
|
// in blueprint order, carrying the config content hash so two boots of
|
|
@@ -113,6 +113,35 @@ export type AxonStimulusEvent = {
|
|
|
113
113
|
|
|
114
114
|
export type AxonStimulusType = keyof AxonStimulusEvent
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Dense sense streams — delivered to the cognet, never written to the log.
|
|
118
|
+
* Everything not in this set is durable.
|
|
119
|
+
*
|
|
120
|
+
* A stimulus is a SENSATION, and the protocol has always described it as one:
|
|
121
|
+
* delivered once, then gone, with no second chance to attend to it. The
|
|
122
|
+
* delivery queue was already built that way (drain-and-forget, no history) —
|
|
123
|
+
* but ingest() committed every stimulus first, so the runtime kept a
|
|
124
|
+
* permanent record of exactly the thing it told cognets was transient.
|
|
125
|
+
*
|
|
126
|
+
* That is affordable for text and sparse field readings, and impossible for
|
|
127
|
+
* a live sensor. A 30Hz microphone commits ~2.6M entries a day whose bytes
|
|
128
|
+
* nobody will ever replay; the useful record is what the mind DID with them
|
|
129
|
+
* — its outputs and actions — which stays durable and is unaffected.
|
|
130
|
+
*
|
|
131
|
+
* Durability is a property of the KIND, not a runtime mode, for the same
|
|
132
|
+
* reason CAPSULE_TRANSIENT_EVENTS is: whether a sensation is worth
|
|
133
|
+
* remembering follows from what it is. Text is what someone said and belongs
|
|
134
|
+
* in the record. Frames are what a retina saw.
|
|
135
|
+
*
|
|
136
|
+
* A cognet that needs a frame beyond the tick it arrived in keeps it in its
|
|
137
|
+
* own resident state — which is what an organism does, and what the runtime
|
|
138
|
+
* must not do on its behalf.
|
|
139
|
+
*/
|
|
140
|
+
export const STIMULUS_TRANSIENT_EVENTS = new Set<AxonStimulusType>([
|
|
141
|
+
"cognet:stimulus:audio",
|
|
142
|
+
"cognet:stimulus:visual",
|
|
143
|
+
])
|
|
144
|
+
|
|
116
145
|
/**
|
|
117
146
|
* One enveloped stimulus — the shape CognetWake.stimuli actually delivers.
|
|
118
147
|
* Narrower than AxonEntry on purpose: a cognet's input contract is
|
package/src/session/index.ts
CHANGED
|
@@ -7,6 +7,8 @@ export type {
|
|
|
7
7
|
export type { AxonKernelEventMap } from "./events/kernel"
|
|
8
8
|
export type { CognetEventMap } from "./events/cognet"
|
|
9
9
|
export type { CapsuleEventMap, CapsuleEventName, AnyCapsuleEvent } from "./events/capsule"
|
|
10
|
+
export type { BuildEventMap, BuildEventName, AnyBuildEvent, BuildStage } from "./events/build"
|
|
11
|
+
export { isBuildEvent } from "./events/build"
|
|
10
12
|
export type { Activity, ActivityHandle, ActivityPayloads, ActivityPhase, ActivityType, AxonAmbient } from "./events/activity"
|
|
11
13
|
export { CAPSULE_TRANSIENT_EVENTS } from "./events/capsule"
|
|
12
14
|
export type { AxonRuntimeEvent } from "./events/runtime"
|
|
@@ -15,6 +17,7 @@ export type { AxonEntryEvent } from "./events/entries"
|
|
|
15
17
|
export { ENTRY_EVENT_PREFIXES } from "./events/entries"
|
|
16
18
|
export { isKernelEvent, isEntryEvent, classifyEvent, type AxonEventView } from "./classify"
|
|
17
19
|
export type { AxonStimulusEntry, AxonStimulusEvent, AxonStimulusType, StimulusSource } from "./events/stdio/stimuli"
|
|
20
|
+
export { STIMULUS_TRANSIENT_EVENTS } from "./events/stdio/stimuli"
|
|
18
21
|
export type { AxonOutputEvent, AxonOutputType } from "./events/stdio/output"
|
|
19
22
|
export type { AxonChunk, StimulusRef } from "./events/stdio/shared"
|
|
20
23
|
export type { AxonLogEvents } from "./events/log"
|
package/src/session/read.ts
CHANGED
|
@@ -96,10 +96,35 @@ export function readSession<E extends ReadableEvent>(events: readonly E[]): Read
|
|
|
96
96
|
const ordered = [...events].sort((a, b) => a.time.seq - b.time.seq)
|
|
97
97
|
|
|
98
98
|
const roots: ReadNode<E>[] = []
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* One open-span stack PER RUN, not one globally.
|
|
102
|
+
*
|
|
103
|
+
* Time containment only implies nesting within a single line of
|
|
104
|
+
* execution. A continuous cognet's wakes overlap by design — deliberation
|
|
105
|
+
* that outlasts a tick keeps running while the next tick wakes — so their
|
|
106
|
+
* spans interleave in `seq` order without being nested at all. A single
|
|
107
|
+
* stack read that interleaving as containment and hung wake B's phases
|
|
108
|
+
* inside wake A's run, producing a flame graph that was not merely
|
|
109
|
+
* imprecise but describing a call structure that never happened.
|
|
110
|
+
*
|
|
111
|
+
* `context.runId` already separates them, which is why no parentSpanId is
|
|
112
|
+
* needed here either: within one run, innermost-still-open is still
|
|
113
|
+
* exact. Events with no runId (session lifecycle, boot) share one stack
|
|
114
|
+
* keyed on "" — they are genuinely one line of execution.
|
|
115
|
+
*/
|
|
116
|
+
const stacks = new Map<string, SpanNode<E>[]>()
|
|
117
|
+
const stackFor = (event: E): SpanNode<E>[] => {
|
|
118
|
+
const runId = (event.context as { runId?: string } | undefined)?.runId ?? ""
|
|
119
|
+
let stack = stacks.get(runId)
|
|
120
|
+
if (!stack) stacks.set(runId, stack = [])
|
|
121
|
+
return stack
|
|
122
|
+
}
|
|
101
123
|
|
|
102
124
|
for (const event of ordered) {
|
|
125
|
+
const stack = stackFor(event)
|
|
126
|
+
const siblings = () => (stack.length > 0 ? stack[stack.length - 1]!.children : roots)
|
|
127
|
+
|
|
103
128
|
if (isSpanStart(event.type)) {
|
|
104
129
|
const node: SpanNode<E> = {
|
|
105
130
|
stem: spanStem(event.type),
|
package/src/session/session.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { AxonKernelEventMap } from "./events/kernel"
|
|
|
3
3
|
import type { AxonRuntimeEvent } from "./events/runtime"
|
|
4
4
|
import type { CognetEventMap } from "./events/cognet"
|
|
5
5
|
import type { CapsuleEventMap } from "./events/capsule"
|
|
6
|
+
import type { BuildEventMap } from "./events/build"
|
|
6
7
|
import type { AxonEntryEvent } from "./events/entries"
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -33,8 +34,17 @@ export type AxonSession = {
|
|
|
33
34
|
|
|
34
35
|
// ── Registry maps ────────────────────────────────────────────────────────────
|
|
35
36
|
|
|
36
|
-
/**
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Everything that can appear in a session's logs (and on the runtime bus).
|
|
39
|
+
* Telemetry (kernel/cognet/capsule) is durable like everything else; only
|
|
40
|
+
* the capsule byte streams (CAPSULE_TRANSIENT_EVENTS) stay bus-only.
|
|
41
|
+
*
|
|
42
|
+
* BuildEventMap is the one family emitted with no runtime present — the
|
|
43
|
+
* session is opened before the build so a failed one leaves a readable
|
|
44
|
+
* record. It is in this map because it reaches the same log and must
|
|
45
|
+
* satisfy the same envelope; nothing else about it is special.
|
|
46
|
+
*/
|
|
47
|
+
export type AxonEventMap = AxonKernelEventMap & AxonRuntimeEvent & CognetEventMap & CapsuleEventMap & BuildEventMap
|
|
38
48
|
|
|
39
49
|
// ── Enveloped unions (what actually sits in the JSONL) ──────────────────────
|
|
40
50
|
|