@arcforge/types 2.0.92 → 2.0.94

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,6 @@
1
1
  {
2
2
  "name": "@arcforge/types",
3
- "version": "2.0.92",
3
+ "version": "2.0.94",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./src/index.ts",
package/src/handle.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AxonEntry } from "./session"
1
+ import type { AxonEntry, AxonKernelEvent, AxonSessionEvent } from "./session"
2
2
  import type { AxonScript } from "./scripts"
3
3
  import type { AxonPrompt } from "./prompts"
4
4
  import type { AxonPartialBlueprint } from "./blueprint"
@@ -143,11 +143,28 @@ export type AxonHandle = {
143
143
  hooks: AxonHooksSurface
144
144
 
145
145
  /**
146
- * Minimal session identity — enough for a script to key its own state
147
- * or logging off which session it's running in. Everything else about
148
- * the session (log, kernelLog, raw commit) is core-internal.
146
+ * The session's identity and its logs, read-only.
147
+ *
148
+ * Reads are a supported surface: `GET /_axon/session` serves these same
149
+ * arrays to any authorized caller, so narrowing them here protected nothing
150
+ * and only made the runtime take a longer path to its own data. A consumer
151
+ * is trusted with its own agent's record — an author deciding what of it to
152
+ * show their own users is an application concern, not a runtime one.
153
+ *
154
+ * Writes stay core-internal. There is no commit path here on purpose: the
155
+ * session is the agent's continuity record, and authored code appending to
156
+ * it directly is how that record gets corrupted. Events reach the log by
157
+ * being emitted on the bus, never by being written.
149
158
  */
150
- session: { id: string }
159
+ session: {
160
+ id: string
161
+ /** The interaction log — what cognition and clients see. */
162
+ readonly entries: readonly AxonEntry[]
163
+ /** Runtime/continuity facts: boot, shutdown, errors. */
164
+ readonly log: readonly AxonSessionEvent[]
165
+ /** Internal tick/phase/system telemetry — the firehose behind devtools and flame graphs. */
166
+ readonly kernelLog: readonly AxonKernelEvent[]
167
+ }
151
168
  }
152
169
 
153
170
 
@@ -0,0 +1,45 @@
1
+ import { ENTRY_EVENT_PREFIXES } from "./events/entries"
2
+
3
+ /**
4
+ * Which of a session's three views an event belongs to.
5
+ *
6
+ * These predicates are the single definition. They lived as locals inside
7
+ * core's Session() while the TUI kept its own prefix sniff and the wake
8
+ * scheduler kept a third — three copies of one rule, which is exactly how a
9
+ * classification drifts. Anything routing an event into entries / kernelLog /
10
+ * log derives from here, on either side of the wire.
11
+ */
12
+
13
+ /**
14
+ * Internal machinery telemetry — devtools/flame-graph material, never a
15
+ * runtime/continuity fact. kernel:* is the machinery's own record; cognet:* is
16
+ * the brain narrating its world; capsule:* is the sandbox's own stream.
17
+ *
18
+ * Two carve-outs: entry families under cognet:* are entries, not telemetry (so
19
+ * isEntryEvent is checked first by classifyEvent), and capsule:attach/detach are
20
+ * the runtime's continuity facts — same namespace, different role — which
21
+ * hydration and humans read from the session view.
22
+ */
23
+ export function isKernelEvent(type: string): boolean {
24
+ if (type === "capsule:attach" || type === "capsule:detach") return false
25
+ return type.startsWith("kernel:") || type.startsWith("cognet:") || type.startsWith("capsule:")
26
+ }
27
+
28
+ /** An interaction — what cognition and clients see. Derived from the canonical prefix list. */
29
+ export function isEntryEvent(type: string): boolean {
30
+ return ENTRY_EVENT_PREFIXES.some(prefix => type.startsWith(prefix))
31
+ }
32
+
33
+ /** The three session views an event can land in. */
34
+ export type AxonEventView = "entries" | "kernelLog" | "log"
35
+
36
+ /**
37
+ * Route one event type to its view. Order matters: entry families live under
38
+ * cognet:*, so the entry check must come before the kernel check or every
39
+ * stimulus/output would be misfiled as telemetry.
40
+ */
41
+ export function classifyEvent(type: string): AxonEventView {
42
+ if (isEntryEvent(type)) return "entries"
43
+ if (isKernelEvent(type)) return "kernelLog"
44
+ return "log"
45
+ }
@@ -13,6 +13,7 @@ export type { AxonRuntimeEvent } from "./events/runtime"
13
13
  export type { AxonEngineBlock, AxonEngineDelta, AxonEngineEvent } from "./events/engine"
14
14
  export type { AxonEntryEvent } from "./events/entries"
15
15
  export { ENTRY_EVENT_PREFIXES } from "./events/entries"
16
+ export { isKernelEvent, isEntryEvent, classifyEvent, type AxonEventView } from "./classify"
16
17
  export type { AxonStimulusEntry, AxonStimulusEvent, AxonStimulusType, StimulusSource } from "./events/stdio/stimuli"
17
18
  export type { AxonOutputEvent, AxonOutputType } from "./events/stdio/output"
18
19
  export type { AxonChunk, StimulusRef } from "./events/stdio/shared"
@@ -28,6 +29,12 @@ export type {
28
29
  AxonTestStatus,
29
30
  } from "./events/test"
30
31
  export { foldChunks } from "./session"
32
+
33
+ export type {
34
+ AxonSessionSnapshot,
35
+ AxonSessionScope,
36
+ AxonSessionQuery,
37
+ } from "./snapshot"
31
38
  export type {
32
39
  AxonEntry,
33
40
  AxonEntryOf,
@@ -0,0 +1,54 @@
1
+ import type { AxonEntry, AxonKernelEvent, AxonSessionEvent } from "./session"
2
+
3
+ /**
4
+ * The wire form of a session — what `GET /_axon/session` returns and what a
5
+ * remote client hydrates from.
6
+ *
7
+ * This exists so a deployed agent renders identically to a local one. The TUI
8
+ * reads `entries` / `log` / `kernelLog` off a live local runtime; a remote
9
+ * instance has no such memory, so it fetches this once on attach and then
10
+ * appends from the SSE stream. Same arrays, same shapes, one rendering model
11
+ * either side of the wire.
12
+ *
13
+ * `cursor` is the high-water `time.seq` across everything included. It closes
14
+ * the hydrate/stream race: events emitted between the snapshot read and the
15
+ * stream opening would otherwise be lost or double-counted. A client keeps the
16
+ * cursor, drops any streamed event at or below it, and passes it back as
17
+ * `?since=` on reconnect. `seq` is a monotonic per-session counter (immune to
18
+ * clock skew), which is what makes this ordering authoritative rather than
19
+ * best-effort.
20
+ */
21
+ export type AxonSessionSnapshot = {
22
+ id: string
23
+ entries: AxonEntry[]
24
+ /** Runtime/continuity facts — boot, shutdown, errors. */
25
+ log: AxonSessionEvent[]
26
+ /**
27
+ * Internal tick/phase/system telemetry. Included by default: the client is
28
+ * fully trusted with its own agent's data and decides what to render. Ask
29
+ * for `?include=entries,log` to omit it — a long-lived agent's kernel log is
30
+ * the firehose and dwarfs everything else.
31
+ */
32
+ kernelLog: AxonKernelEvent[]
33
+ /** High-water time.seq across the returned events. 0 when nothing is included. */
34
+ cursor: number
35
+ /**
36
+ * True when a `limit` capped one of the logs, so the client knows its view
37
+ * is a tail rather than the whole history. Never silently truncate without
38
+ * saying so — a partial log that claims to be complete is a lie the UI
39
+ * cannot detect.
40
+ */
41
+ truncated: boolean
42
+ }
43
+
44
+ /** Which logs a snapshot request wants. Absent means all three. */
45
+ export type AxonSessionScope = "entries" | "log" | "kernelLog"
46
+
47
+ export type AxonSessionQuery = {
48
+ /** Only events with `time.seq` strictly greater than this. */
49
+ since?: number
50
+ /** Max events per log, keeping the most recent. */
51
+ limit?: number
52
+ /** Which logs to include. Defaults to all. */
53
+ include?: AxonSessionScope[]
54
+ }