@arcforge/types 2.0.59

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 (59) hide show
  1. package/package.json +29 -0
  2. package/src/bench/aggregate.ts +67 -0
  3. package/src/bench/artifact.ts +39 -0
  4. package/src/bench/bench.ts +62 -0
  5. package/src/bench/contribution.ts +40 -0
  6. package/src/bench/dimension.ts +15 -0
  7. package/src/bench/execution.ts +76 -0
  8. package/src/bench/factor.ts +69 -0
  9. package/src/bench/index.ts +108 -0
  10. package/src/bench/manifest.ts +49 -0
  11. package/src/bench/measurement.ts +41 -0
  12. package/src/bench/observation.ts +42 -0
  13. package/src/bench/protocol.ts +21 -0
  14. package/src/bench/result.ts +32 -0
  15. package/src/bench/value.ts +7 -0
  16. package/src/bench/workspace.ts +76 -0
  17. package/src/blueprint.ts +125 -0
  18. package/src/capsule-config.ts +111 -0
  19. package/src/cognet/blueprint.ts +38 -0
  20. package/src/cognet/cognet.ts +69 -0
  21. package/src/cognet/hooks.ts +43 -0
  22. package/src/cognet/index.ts +3 -0
  23. package/src/config.ts +72 -0
  24. package/src/define.ts +184 -0
  25. package/src/deploy.ts +54 -0
  26. package/src/engine.ts +254 -0
  27. package/src/error.ts +88 -0
  28. package/src/handle.ts +137 -0
  29. package/src/hooks.ts +31 -0
  30. package/src/http.ts +49 -0
  31. package/src/index.ts +23 -0
  32. package/src/kernel/abi.ts +244 -0
  33. package/src/kernel/index.ts +2 -0
  34. package/src/middleware.ts +7 -0
  35. package/src/module.ts +193 -0
  36. package/src/plugin.ts +9 -0
  37. package/src/policy.ts +89 -0
  38. package/src/prompts.ts +25 -0
  39. package/src/route.ts +15 -0
  40. package/src/scope.ts +29 -0
  41. package/src/scripts.ts +21 -0
  42. package/src/session/envelope.ts +61 -0
  43. package/src/session/events/activity.ts +77 -0
  44. package/src/session/events/bench.ts +49 -0
  45. package/src/session/events/capsule.ts +114 -0
  46. package/src/session/events/cognet.ts +51 -0
  47. package/src/session/events/engine.ts +46 -0
  48. package/src/session/events/entries.ts +66 -0
  49. package/src/session/events/kernel.ts +44 -0
  50. package/src/session/events/log.ts +27 -0
  51. package/src/session/events/runtime.ts +76 -0
  52. package/src/session/events/stdio/output.ts +94 -0
  53. package/src/session/events/stdio/shared.ts +50 -0
  54. package/src/session/events/stdio/stimuli.ts +110 -0
  55. package/src/session/events/test.ts +52 -0
  56. package/src/session/index.ts +40 -0
  57. package/src/session/session.ts +107 -0
  58. package/src/tools.ts +54 -0
  59. package/tsconfig.base.json +14 -0
@@ -0,0 +1,114 @@
1
+ /**
2
+ * CapsuleEventMap — everything the capsule can emit. The capsule package's
3
+ * own vocabulary (its subprocess bus serializes these over stdout as JSONL;
4
+ * the host wire validates and re-emits them), registered HERE because every
5
+ * event type that can reach a session log lives in this package's registry
6
+ * — @axon/capsule re-exports it (types/events.ts), it does not own it.
7
+ *
8
+ * Naming: start/complete/failed verb suffixes throughout, matching the
9
+ * kernel/cognet conventions — capsule spans (cmd, fn, proc) pair up in a
10
+ * flame graph exactly like kernel:run/cognet:tick do.
11
+ *
12
+ * Durability: committed to the session log (telemetry view) by the
13
+ * kernel's AxonCapsule forwarder — EXCEPT the byte streams named in
14
+ * CAPSULE_TRANSIENT_EVENTS below, which stay bus-only: heavy payloads
15
+ * never enter the log (envelope rule 2), and a command's stdout already
16
+ * reaches the durable record as cognet:action:result's folded content.
17
+ *
18
+ * capsule:attach/detach (runtime.ts) are not here — same namespace, but
19
+ * they're the runtime's continuity facts about attachment, committed at
20
+ * the runtime's lifecycle seams; this map is what the capsule itself emits.
21
+ */
22
+ import type { Activity } from "./activity"
23
+
24
+ export type CapsuleEventMap = {
25
+ // ── Lifecycle ────────────────────────────────────────────────────────────
26
+ "capsule:boot:start": {}
27
+ "capsule:boot:complete": { durationMs: number }
28
+ "capsule:boot:failed": { durationMs: number; error: string }
29
+ "capsule:ready": {}
30
+ "capsule:shutdown": {}
31
+ /** Unhandled error inside the subprocess. Exit usually follows. */
32
+ "capsule:crash": { error: string }
33
+ /** The capsule subprocess itself exited (not a managed child process). */
34
+ "capsule:exit": { code: number | null; reason?: string }
35
+ /** A wire line failed to parse — the sandbox is speaking garbage. Never dropped silently. */
36
+ "capsule:parse:error": { reason: string; line?: string }
37
+
38
+ // ── Supervision (host-side) ──────────────────────────────────────────────
39
+ "capsule:restarting": { restartCount: number }
40
+ "capsule:restarted": { restartCount: number }
41
+ "capsule:dead": { reason: string }
42
+
43
+ // ── Command execution (one run() = one command id) ──────────────────────
44
+ "capsule:cmd:start": { id: string }
45
+ "capsule:cmd:stdout": { id: string; data: string }
46
+ "capsule:cmd:complete": { id: string; result: unknown; durationMs: number }
47
+ "capsule:cmd:failed": { id: string; error: string; durationMs: number }
48
+ "capsule:cmd:interrupt:requested": { id: string; reason: "abort" | "timeout" }
49
+ "capsule:cmd:interrupted": { id: string; durationMs: number }
50
+ "capsule:cmd:hard-killed": { id: string; graceMs: number }
51
+
52
+ // ── Tool call spans (mediated fn calls inside a command) ────────────────
53
+ "capsule:fn:start": { commandId: string; module: string; fn: string; args: unknown[] }
54
+ "capsule:fn:complete": { commandId: string; module: string; fn: string; durationMs: number; result: unknown }
55
+ "capsule:fn:failed": { commandId: string; module: string; fn: string; durationMs: number; error: string }
56
+
57
+ // ── Tool loading ─────────────────────────────────────────────────────────
58
+ "capsule:tool:loaded": { namespace: string; fns: string[] }
59
+ "capsule:tool:unloaded": { namespace: string }
60
+ "capsule:tool:error": { namespace: string; error: string }
61
+
62
+ // ── Trusted host bridge ─────────────────────────────────────────────────
63
+ /** Private request transport for the capsule Axon facade. Never durable. */
64
+ "capsule:host:request": { id: string; commandId: string | null; method: string; input: unknown }
65
+
66
+ // ── Managed child processes ──────────────────────────────────────────────
67
+ "capsule:proc:spawned": { procId: string; pid: number; command: string; cwd: string; kind: "managed" | "run" }
68
+ "capsule:proc:stdout": { procId: string; data: string }
69
+ "capsule:proc:stderr": { procId: string; data: string }
70
+ "capsule:proc:exit": { procId: string; code: number; durationMs?: number }
71
+ "capsule:proc:denied": { procId: string; command: string; error: string }
72
+ "capsule:proc:stdin:error": { procId: string; error: string }
73
+
74
+ // ── Policy ───────────────────────────────────────────────────────────────
75
+ "capsule:policy:updated": {}
76
+ "capsule:policy:denied": { id: string; module: string; fn: string; args: unknown[]; rule: string }
77
+ "capsule:policy:escalation": { id: string; module: string; fn: string; args: unknown[]; rule: string }
78
+ /** Host-side: the escalate callback's verdict for a pending escalation. */
79
+ "capsule:policy:decision": { id: string; allow: boolean; durationMs: number }
80
+ "capsule:resource:exceeded": { id: string; limit: string; value: number; max: number }
81
+
82
+ // ── Activities (semantic tool emissions) ─────────────────────────────────
83
+ /**
84
+ * A tool declared or settled a renderable activity (activity.ts) via the
85
+ * ambient axon.activity(). Correlated to the running command the same way
86
+ * capsule:console is; null only if emitted outside any command.
87
+ */
88
+ "capsule:activity": Activity & { commandId: string | null }
89
+
90
+ // ── Console + state ──────────────────────────────────────────────────────
91
+ /** User console output, captured — correlated to the running command, never raw on stdout. */
92
+ "capsule:console": { level: "log" | "info" | "warn" | "error" | "debug"; commandId: string | null; args: unknown[] }
93
+ "capsule:cwd": { cwd: string }
94
+ }
95
+
96
+ export type CapsuleEventName = keyof CapsuleEventMap
97
+
98
+ /** One event as it travels the wire and the buses: { type } + payload, flat. */
99
+ export type AnyCapsuleEvent = {
100
+ [K in CapsuleEventName]: { type: K } & CapsuleEventMap[K]
101
+ }[CapsuleEventName]
102
+
103
+ /**
104
+ * The byte streams — live wire material, never committed. Everything not
105
+ * in this set is durable. The one canonical list; the kernel's forwarder
106
+ * derives its split from here, never from its own type sniff.
107
+ */
108
+ export const CAPSULE_TRANSIENT_EVENTS = new Set<CapsuleEventName>([
109
+ "capsule:cmd:stdout",
110
+ "capsule:proc:stdout",
111
+ "capsule:proc:stderr",
112
+ "capsule:console",
113
+ "capsule:host:request",
114
+ ])
@@ -0,0 +1,51 @@
1
+ import type { AxonError } from "../../error"
2
+ import type { AxonLogEvents } from "./log"
3
+
4
+ /**
5
+ * Cognet telemetry — the cognition artifact's own observability record.
6
+ *
7
+ * Semantically distinct from kernel:* and enforced at the seam: this map is
8
+ * the ONLY vocabulary abi.emit accepts, so a cognet can narrate its world
9
+ * (ticks, phases, systems, entity/component writes) but can never forge
10
+ * kernel machinery events (run records, engine calls).
11
+ *
12
+ * Fire-and-forget for the cognet, durable in the machine: abi.emit commits
13
+ * these to the session's log (telemetry view, alongside kernel:*) and the
14
+ * commit pipeline forwards them to the bus — flame-graph and devtools
15
+ * material, never rendered to the user. At some level cognet events have
16
+ * to reach a log for the brain to be debuggable; this is that level. The
17
+ * durable record around a wake (kernel:run:*) remains the kernel's and
18
+ * only the kernel's.
19
+ *
20
+ * The world clock lives HERE, not in kernel:* — since cognition moved into
21
+ * the cognet layer, ticks and phases are the program's own clock; the
22
+ * kernel neither knows nor cares that a program ticks.
23
+ */
24
+ export type CognetEventMap = AxonLogEvents<"cognet"> & {
25
+ // ── World clock ──────────────────────────────────────────────────────────
26
+ "cognet:tick:start": { tick: number }
27
+ "cognet:tick:complete": { tick: number }
28
+ "cognet:tick:failed": { tick: number; error: AxonError }
29
+ /** The tick's own work threw because the wake was interrupted (Escape/Ctrl+C, engine abort) — cancellation, not a bug. Distinct from :failed so devtools/telemetry never conflate the two. */
30
+ "cognet:tick:interrupted": { tick: number }
31
+
32
+ "cognet:phase:start": { tick: number; phase: string }
33
+ "cognet:phase:complete": { tick: number; phase: string }
34
+ "cognet:phase:failed": { tick: number; phase: string; error: AxonError }
35
+ /** Same rule as cognet:tick:interrupted, one level down. */
36
+ "cognet:phase:interrupted": { tick: number; phase: string }
37
+
38
+ "cognet:system:start": { tick: number; phase: string | null; system: string }
39
+ "cognet:system:complete": { tick: number; phase: string | null; system: string; durationMs: number }
40
+ "cognet:system:failed": { tick: number; phase: string | null; system: string; error: AxonError }
41
+ /** Same rule as cognet:tick:interrupted, one level down. */
42
+ "cognet:system:interrupted": { tick: number; phase: string | null; system: string }
43
+
44
+ // ── World writes ─────────────────────────────────────────────────────────
45
+ "cognet:entity:add": { tick: number; phase: string | null; entity: string }
46
+ "cognet:entity:remove": { tick: number; phase: string | null; entity: string }
47
+
48
+ "cognet:component:add": { tick: number; phase: string | null; entity: string; component: string }
49
+ "cognet:component:update": { tick: number; phase: string | null; entity: string; component: string }
50
+ "cognet:component:remove": { tick: number; phase: string | null; entity: string; component: string }
51
+ }
@@ -0,0 +1,46 @@
1
+ import type { AxonEngineResponse } from "../../engine"
2
+
3
+ /**
4
+ * The engine wire contract — what every AxonEngine.stream() yields, and what
5
+ * kernel.stream() hands the cognet raw. Honestly named: this is engine:*,
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.
11
+ *
12
+ * Reasoning/"thinking" tokens are dropped at the adapter boundary (engine.ts
13
+ * in core) and never reach this wire at all — thinking was never a data
14
+ * kind, it was one specific inference pipeline's internal stage. If a
15
+ * distributed multi-model cognet has something analogous, that's an
16
+ * inference-side concern with no single causal stream to represent here.
17
+ *
18
+ * Deltas are wire-only — forwarded live to clients, never persisted.
19
+ * Blocks are complete — the cognet decides what becomes a durable fact.
20
+ */
21
+
22
+ /** Streaming chunks — transient, never enter a log. */
23
+ export type AxonEngineDelta =
24
+ { type: "engine:text:delta"; content: string }
25
+
26
+ /** Complete parsed blocks. */
27
+ export type AxonEngineBlock =
28
+ | { type: "engine:text"; content: string }
29
+ /** id is minted at parse time by the AIR parser. The kernel's run() mints its own action id independently, so this parse-time id is currently unconsumed downstream. */
30
+ | { type: "engine:typescript"; id: string; content: string }
31
+ /** A format violation in the model's output. */
32
+ | { type: "engine:output:error"; code: string; message: string; excerpt?: string }
33
+
34
+ export type AxonEngineEvent =
35
+ | AxonEngineDelta
36
+ | AxonEngineBlock
37
+ /**
38
+ * The model emitted <done/> this tick — its own explicit stop signal.
39
+ * Causal, not inferred: a loop def reads this directly rather than
40
+ * guessing from what blocks did or didn't appear (a text-only tick is
41
+ * NOT implicitly terminal — a model can speak across several ticks and
42
+ * only stop when it actually says so).
43
+ */
44
+ | { type: "engine:stop" }
45
+ /** Terminal — carries the authoritative full response and billing meta. Always emitted once per call, independent of <done/>. */
46
+ | { type: "engine:done"; response: AxonEngineResponse }
@@ -0,0 +1,66 @@
1
+ import type { AxonStimulusEvent } from "./stdio/stimuli"
2
+ import type { AxonOutputEvent } from "./stdio/output"
3
+
4
+ /**
5
+ * Entry registry — everything that can be a durable entry in the session's
6
+ * one log. There is no thread/branching concept: one cognet instance is
7
+ * always exactly one continuous stream. A temporally-extended emission is
8
+ * ordinary chunked entries (the AxonChunk standard, stdio/shared.ts) —
9
+ * every chunk is itself a durable committed entry, so streaming rides the
10
+ * same log as everything else; there is no separate transient delta wire.
11
+ * Raw engine-level deltas (AxonEngineDelta) still exist, but only inside
12
+ * kernel.stream()'s engine wire — they never reach this log. A user who
13
+ * wants multiple independent conversations runs multiple Axon() instances
14
+ * — a host-level (TUI) concern, never something the log or the cognet has
15
+ * to represent internally.
16
+ *
17
+ * Four families:
18
+ * - stimulus:* — exteroception: the world reaching the agent (stdio/stimuli.ts).
19
+ * A user message is cognet:stimulus:text on channel "user".
20
+ * - output:* — effectorception: the cognet reaching the world, unmediated
21
+ * (stdio/output.ts). Committed exclusively by kernel.output()
22
+ * — the cognet never calls session.commit directly; it has
23
+ * no session access at all, only output() and run().
24
+ * - action:* — a mediated request the cognet made (run()) and its
25
+ * outcome. Committed exclusively by the kernel's run()
26
+ * implementation, the moment the capsule's own
27
+ * cmd:complete/cmd:failed lands — same pattern as
28
+ * capsule:attach/detach, never something cognet code writes.
29
+ * - the rest — interoception: machine-body facts (interrupts).
30
+ */
31
+ /**
32
+ * The entry namespaces — the only event families that may appear in the
33
+ * session's log. Anything filtering "is this a log entry?" (wire filters,
34
+ * renderers) derives from THIS list, never from its own prefix sniff: a new
35
+ * family added to AxonEntryEvent must be added here in the same change.
36
+ */
37
+ export const ENTRY_EVENT_PREFIXES = ["cognet:stimulus:", "cognet:output:", "cognet:action:", "axon:interrupt", "axon:system:"] as const
38
+
39
+ export type AxonEntryEvent = AxonStimulusEvent & AxonOutputEvent & {
40
+ /** Kernel signal record — an interrupt is machinery, never a stimulus. */
41
+ "axon:interrupt": { reason: "user" | "shutdown" }
42
+
43
+ /** Code the cognet ran via kernel.run(). `id` is referenced by cognet:action:result.for. */
44
+ "cognet:action:typescript": { id: string; content: string }
45
+ /** The outcome of one run() call — without this, a resumed log renders code with its stdout missing. */
46
+ "cognet:action:result": {
47
+ /** id of the cognet:action:typescript block this answers */
48
+ for: string
49
+ ok: boolean
50
+ content: string
51
+ error?: { kind: "timeout" | "policy" | "interrupt" | "exception"; message: string }
52
+ }
53
+
54
+ /**
55
+ * A durable system interaction in the session's causal timeline.
56
+ * AIR renders every member through the single <system> emitter; `type`
57
+ * narrows its meaning and `lang` describes the content representation.
58
+ */
59
+ "axon:system:message": {
60
+ type: string
61
+ lang: string
62
+ content: string
63
+ /** Additional trusted AIR attributes. `type` and `lang` are reserved. */
64
+ attributes?: Record<string, string>
65
+ }
66
+ }
@@ -0,0 +1,44 @@
1
+ import type { AxonEngineFault, AxonEngineMessage, AxonEngineMeta } from "../../engine"
2
+ import type { AxonLogEvents } from "./log"
3
+
4
+ /**
5
+ * Kernel telemetry — the machinery's own record, emitted by the kernel and
6
+ * ONLY the kernel. Programs cannot produce these (abi.emit is typed against
7
+ * program:* alone); their world clock lives in AxonProgramEventMap.
8
+ *
9
+ * Session-level: these describe how the machinery ran, never what the model
10
+ * or client sees. runId rides in the event context.
11
+ */
12
+ export type AxonKernelEventMap = AxonLogEvents<"kernel"> & {
13
+ // ── Run — one wake, exec to quiescence. The process accounting record. ──
14
+ "kernel:run:start": {}
15
+ "kernel:run:complete": { durationMs: number }
16
+ // No error payload — err()'s sink already emitted the canonical "error"
17
+ // session event at the throw site (see @axon/err/sink.ts). This is
18
+ // pure run-accounting: the wake ended, and it ended badly.
19
+ "kernel:run:failed": {}
20
+ "kernel:run:interrupted": { reason: "user" | "shutdown" }
21
+
22
+ // ── Engine calls — the billing and latency record ────────────────────────
23
+ // Emitted by the Engine() manager around every call — a program cannot
24
+ // skip them: every token passes this meter by construction.
25
+ "kernel:engine:start": { provider: string; model?: string }
26
+ /**
27
+ * The rendered AIR document handed to the engine for this call — what the
28
+ * model actually saw. Same spanId as the paired kernel:engine:start, so
29
+ * a trace can pull a call's input by shared span without extra plumbing.
30
+ * Devtools-only: never rendered to the user, never part of entry state.
31
+ */
32
+ "kernel:engine:input": { messages: AxonEngineMessage[]; bytes: number }
33
+ "kernel:engine:retry": { attempt: number; nextAttempt: number; delayMs: number; fault: AxonEngineFault }
34
+ /**
35
+ * The other half of the call kernel:engine:input opened, same spanId —
36
+ * together they tell the whole story: input (what the model saw),
37
+ * output (exactly what it produced, raw, pre-AIR-parse), meta (billing/
38
+ * observability). text/thinking are the same fields AxonEngineResponse
39
+ * already carries in-process; this is that response actually made
40
+ * durable instead of being dropped after the AIR parser consumes it.
41
+ */
42
+ "kernel:engine:complete": { attempts: number; text: string; thinking?: string; stopReason: "end" | "length" | "abort"; meta: AxonEngineMeta }
43
+ "kernel:engine:failed": { attempts: number; fault: AxonEngineFault }
44
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The log-event convention: every event namespace can carry a
3
+ * `<namespace>:log:<level>` event alongside its own vocabulary — kernel
4
+ * telemetry can log, cognet can log, without a bespoke logging channel per
5
+ * subsystem. A log pane derives
6
+ * "is this a log line?" purely from the type suffix (`:log:info` /
7
+ * `:log:warning` / `:log:error`), same as any other classification in
8
+ * this system — see envelope.ts rule 3 ("classification comes from the
9
+ * type namespace").
10
+ *
11
+ * `value` is deliberately `unknown`, not `string` — a log line may be a
12
+ * plain message, a structured object, an array of args (console.log-style
13
+ * variadic capture), anything. The log view renders whatever shape shows
14
+ * up: a string prints as-is, anything else gets stringified/inspected.
15
+ * Emitters are never forced to pre-format into text.
16
+ */
17
+ export type AxonLogEvents<Namespace extends string> = {
18
+ [K in `${Namespace}:log:info` | `${Namespace}:log:warning` | `${Namespace}:log:error`]: { value: unknown }
19
+ }
20
+
21
+ /** Every `:log:info` / `:log:warning` / `:log:error` suffix, regardless of namespace — the one place a log-classifying reader should derive this from. */
22
+ export const LOG_EVENT_SUFFIXES = [":log:info", ":log:warning", ":log:error"] as const
23
+
24
+ /** True for any event type following the `<namespace>:log:<level>` convention. */
25
+ export function isLogEventType(type: string): boolean {
26
+ return LOG_EVENT_SUFFIXES.some(suffix => type.endsWith(suffix))
27
+ }
@@ -0,0 +1,76 @@
1
+ import type { AxonError } from "../../error"
2
+ import type { AxonLogEvents } from "./log"
3
+
4
+ /**
5
+ * Runtime + continuity events — the session's own lifecycle record.
6
+ *
7
+ * Two families in one map:
8
+ * - Runtime facts (boot/shutdown/reload/server): "a runtime attached to this
9
+ * session and did things". A session can span many boots.
10
+ * - Continuity facts (session/capsule/compress): the small, load-bearing
11
+ * subset hydration reads on resume.
12
+ *
13
+ * No single prefix covers this map (boot:/shutdown:/session:/capsule:/
14
+ * server:), so its log events use "runtime" as the namespace —
15
+ * axon:log:info/warning/error — rather than picking one arbitrary
16
+ * existing prefix to own logging for the whole map.
17
+ *
18
+ * axon:log:* is a distinct namespace within this same map: console output
19
+ * captured from agent-authored code (boot.vue today; the CLI config layer
20
+ * once it's wired to a session too). "axon" names the runtime the user's
21
+ * own code is running inside — not any one lifecycle prefix above — so it
22
+ * gets its own namespace rather than folding into axon:log:*.
23
+ */
24
+ export type AxonRuntimeEvent = AxonLogEvents<"axon"> & {
25
+ // ── Runtime lifecycle ────────────────────────────────────────────────────
26
+ "axon:boot:start": { version: string; agentRoot: string; mode: "local" | "cloud" }
27
+ "axon:boot:complete": { durationMs: number }
28
+ "axon:boot:failed": { error: AxonError }
29
+
30
+ "axon:shutdown:start": { reason?: string }
31
+ "axon:shutdown:complete": { durationMs: number }
32
+ "axon:shutdown:failed": { error: AxonError }
33
+
34
+ // ── Surface reload (blueprint/tools changed under a live runtime) ───────
35
+ "axon:reload:start": { revision: number }
36
+ "axon:reload:complete": { revision: number; durationMs: number; toolCount: number }
37
+ "axon:reload:failed": { revision?: number; error: AxonError }
38
+
39
+ // ── Module install/uninstall (registry op, then a reload rides the same
40
+ // hot-swap path above) ─────────────────────────────────────────────
41
+ "axon:install:start": { name: string; version?: string }
42
+ "axon:install:complete": { name: string; version: string; durationMs: number; alreadyInstalled: boolean }
43
+ /**
44
+ * No module by that name in the registry — a typo or an unpublished
45
+ * package. A settled outcome, not a failure: nothing broke, so it must
46
+ * not render as an error. Distinct from :failed, which means the
47
+ * install itself went wrong (network, disk, a bad tarball).
48
+ */
49
+ "axon:install:not-found": { name: string; durationMs: number }
50
+ "axon:install:failed": { name: string; version?: string; error: AxonError }
51
+
52
+ "axon:uninstall:start": { name: string }
53
+ "axon:uninstall:complete": { name: string; durationMs: number }
54
+ "axon:uninstall:failed": { name: string; error: AxonError }
55
+
56
+ // ── Session continuity ───────────────────────────────────────────────────
57
+ "axon:session:start": {}
58
+ "axon:session:restored": {}
59
+ "axon:session:end": {}
60
+ "axon:session:error": { error: AxonError }
61
+
62
+ // ── Capsule attachment (one capsule per session; telemetry lives in the capsule package) ──
63
+ "capsule:attach": { capsuleId: string; cwd: string }
64
+ "capsule:detach": { capsuleId: string; reason: "shutdown" | "crash" | "reload" }
65
+
66
+ // ── Compression — summaries replacing aged entries ──────────────────────
67
+ "axon:compress": { replaced: number; summaryEntryId: string }
68
+
69
+ // ── Server ───────────────────────────────────────────────────────────────
70
+ "axon:server:request": { method: string; path: string; status: number; durationMs: number }
71
+
72
+ // ── Errors ───────────────────────────────────────────────────────────────
73
+ "axon:error": { event?: string; error: AxonError }
74
+ /** Matches the literal string the bus actually emits (platform/bus.ts) — "axon" names the runtime layer the failure happened in, not any one lifecycle prefix above. */
75
+ "axon:bus:error": { event: string; error: string }
76
+ }
@@ -0,0 +1,94 @@
1
+ import type { AxonChunk, StimulusRef } from "./shared"
2
+
3
+ /**
4
+ * Output — the effector protocol. Every fact a cognet emits TO the world
5
+ * that isn't a mediated request (that's run() — a tool call, policy-gated,
6
+ * may fail) goes through here. The mirror image of stimuli.ts: stimuli are
7
+ * exteroception (the world reaching the agent), output is effectorception
8
+ * (the agent reaching the world) — same design rules, same reasoning,
9
+ * applied to the opposite direction.
10
+ *
11
+ * DESIGN RULES (identical to stimuli.ts, mirrored):
12
+ *
13
+ * 1. Top-level types are INFORMATION KINDS, not pipeline stages. A kind
14
+ * describes what the data IS (text, audio, visual, a measured value),
15
+ * never WHEN or HOW a cognet produced it. "Thinking" is deliberately
16
+ * absent: it never described a data kind — it described a stage in one
17
+ * specific engine's pipeline (LLM reasoning-before-answer), the same
18
+ * category error kernel:engine:* telemetry would be if it leaked into
19
+ * this protocol. A cognet with something analogous to reasoning is free
20
+ * to emit it as cognet:output:text like anything else; if it wants to mark it
21
+ * distinctly for a renderer, that's optional per-kind metadata, not a
22
+ * new top-level type — a "was this exploratory" flag is cognet-internal
23
+ * narrative, not a property of the output protocol.
24
+ *
25
+ * 2. Heavy payloads NEVER enter the log — same ref/digest split as stimuli:
26
+ * a `ref` into content-addressed storage, plus whatever symbolic digest
27
+ * makes the emission durable and replayable without the bytes.
28
+ *
29
+ * 3. Output is EFFECTORCEPTION — the cognet reaching the world. Unmediated
30
+ * at the call site: writing to your own stdout can't itself harm
31
+ * anything, so there is nothing here for the kernel to refuse (contrast
32
+ * run() — a request whose EFFECT needs permission before it happens).
33
+ * Any filtering, redaction, or policy a host wants to apply happens
34
+ * downstream of the commit, on the delivery/render path — never as a
35
+ * gate the emitting call has to pass through, the same way a shell
36
+ * pipeline filters a process's stdout without the process negotiating
37
+ * with the pipe.
38
+ *
39
+ * 4. Outputhood is a DELIVERY ROLE, not a type property — same as
40
+ * stimulushood. These are ordinary log entries; a renderer or
41
+ * devtools view derives "is this an output?" from the type prefix, the
42
+ * same way it derives "is this a stimulus?" from stimulus:*.
43
+ */
44
+
45
+ // ── The output set ───────────────────────────────────────────────────────────
46
+
47
+ /**
48
+ * The output registry — log entries, unmediated at the call site.
49
+ *
50
+ * Four kinds, mirroring stimuli exactly:
51
+ * text — symbolic language out (an LLM cognet's natural output)
52
+ * audio — synthesized sound out (a cognet that speaks directly)
53
+ * visual — an image or clip produced/selected by the cognet
54
+ * field — a measured/declared value emitted outward (a fish declaring
55
+ * a homeostatic reading, telemetry, a structured status)
56
+ */
57
+ export type AxonOutputEvent = {
58
+ /** Symbolic language output. Inline — text IS its own digest. */
59
+ "cognet:output:text": {
60
+ content: string
61
+ /** chunking standard (shared.ts) — absent = self-contained complete emission */
62
+ chunk?: AxonChunk
63
+ }
64
+
65
+ /** Synthesized or selected audio segment. */
66
+ "cognet:output:audio": {
67
+ ref: StimulusRef
68
+ /** symbolic digest — what the emission means without fetching audio */
69
+ transcript?: string
70
+ durationMs?: number
71
+ /** chunking standard (shared.ts) — audio's natural durable shape is chunked */
72
+ chunk?: AxonChunk
73
+ }
74
+
75
+ /** An image or clip the cognet produced or selected. */
76
+ "cognet:output:visual": {
77
+ ref: StimulusRef
78
+ /** symbolic digest — caption / description */
79
+ caption?: string
80
+ kind: "image" | "video"
81
+ /** chunking standard (shared.ts) — absent = self-contained complete emission */
82
+ chunk?: AxonChunk
83
+ }
84
+
85
+ /** A value the cognet declares outward — status, telemetry, a homeostatic reading. */
86
+ "cognet:output:field": {
87
+ reading: { value: number | string | boolean; unit?: string }
88
+ ref?: StimulusRef
89
+ /** chunking standard (shared.ts) — absent = self-contained complete emission */
90
+ chunk?: AxonChunk
91
+ }
92
+ }
93
+
94
+ export type AxonOutputType = keyof AxonOutputEvent
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Shapes shared by both directions of the stdio protocol — stimuli (world
3
+ * → cognet) and output (cognet → world). Neither file imports from the
4
+ * other; anything both need lives here so the two stay siblings, not one
5
+ * depending on the other's internals.
6
+ */
7
+
8
+ /**
9
+ * Content-addressed reference to a heavy payload (audio segment, frame,
10
+ * clip) held OUTSIDE the log — device buffer, blob store, agent home.
11
+ * The log entry stays ~bytes regardless of modality; replay never needs
12
+ * the blob (the digest is what cognition folds).
13
+ */
14
+ export type StimulusRef = {
15
+ /** content address or storage uri */
16
+ uri: string
17
+ mime: string
18
+ bytes?: number
19
+ }
20
+
21
+ /**
22
+ * The chunking standard — how a temporally-extended emission is recorded.
23
+ *
24
+ * An emission is a correlated GROUP of 1..n committed entries: every chunk
25
+ * of one emission carries the same `of` id, and the group closes when a
26
+ * chunk arrives with `final: true`. The group — not any single entry — is
27
+ * the fact; the complete content is the in-order concatenation/assembly of
28
+ * its chunks. `chunk` absent means the entry is a self-contained complete
29
+ * emission (the degenerate 1-chunk case, no folding required).
30
+ *
31
+ * This is a standard DIMENSION of every output kind, not a type family —
32
+ * a chunk of text is still cognet:output:text (information kind), the same way
33
+ * time.seq is a dimension of the envelope. Every observer applies ONE
34
+ * folding rule to every kind forever: group by `of`, order by seq, closed
35
+ * by `final`. A group that never receives its final chunk was truncated
36
+ * (interrupt, crash) — truncation is representable in the durable record,
37
+ * not a lie of omission.
38
+ *
39
+ * Granularity is entirely the EMITTER's dial: one self-contained entry
40
+ * (zero overhead) or token-level chunks (live typing, one durable append +
41
+ * bus forward per chunk — a chosen cost, never a surprise). The cognet
42
+ * just emits at whatever granularity is natural to it; rate/size ceilings
43
+ * are a runtime/consumer concern, never the emitter's.
44
+ */
45
+ export type AxonChunk = {
46
+ /** correlation id shared by every chunk of one emission */
47
+ of: string
48
+ /** closes the group — the emission is complete */
49
+ final?: boolean
50
+ }