@spellkave/agent-observability 0.0.0-bootstrap → 0.0.0-stage

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Temporary Holding Version
2
+
3
+ This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
package/package.json CHANGED
@@ -1,35 +1,6 @@
1
1
  {
2
2
  "name": "@spellkave/agent-observability",
3
- "version": "0.0.0-bootstrap",
4
- "description": "World-actor run observability (ADR-0074): the agent-run-events/v1 schema, emit API + sinks, and the read/projection API. NOT ADR-0030 coding-agent telemetry.",
5
- "type": "module",
6
- "main": "./src/index.ts",
7
- "types": "./src/index.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./src/index.ts",
11
- "default": "./src/index.ts"
12
- },
13
- "./resource": {
14
- "types": "./src/node-resource.ts",
15
- "default": "./src/node-resource.ts"
16
- },
17
- "./node": {
18
- "types": "./src/node.ts",
19
- "default": "./src/node.ts"
20
- }
21
- },
22
- "files": [
23
- "src"
24
- ],
25
- "license": "PolyForm-Shield-1.0.0",
26
- "repository": {
27
- "type": "git",
28
- "url": "git+https://github.com/b4mad-technologies/sk-sdk.git",
29
- "directory": "packages/spellkave-agent-observability"
30
- },
31
- "publishConfig": {
32
- "access": "public",
33
- "registry": "https://registry.npmjs.org/"
34
- }
35
- }
3
+ "version": "0.0.0-stage",
4
+ "stub": true,
5
+ "description": "Temporary package placeholder for staged publishing"
6
+ }
package/LICENSE DELETED
@@ -1,89 +0,0 @@
1
- # PolyForm Shield License 1.0.0
2
-
3
- <https://polyformproject.org/licenses/shield/1.0.0>
4
-
5
- ## Acceptance
6
-
7
- In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
8
-
9
- ## Copyright License
10
-
11
- The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
12
-
13
- ## Distribution License
14
-
15
- The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
16
-
17
- ## Notices
18
-
19
- You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
20
-
21
- > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
22
-
23
- ## Changes and New Works License
24
-
25
- The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
26
-
27
- ## Patent License
28
-
29
- The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
30
-
31
- ## Noncompete
32
-
33
- Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
34
-
35
- ## Competition
36
-
37
- Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
38
-
39
- ## New Products
40
-
41
- If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
42
-
43
- ## Discontinued Products
44
-
45
- You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
46
-
47
- > Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
48
-
49
- ## Sales of Business
50
-
51
- If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce [Noncompete](#noncompete) for that product.
52
-
53
- ## Fair Use
54
-
55
- You may have "fair use" rights for the software under the law. These terms do not limit them.
56
-
57
- ## No Other Rights
58
-
59
- These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
60
-
61
- ## Patent Defense
62
-
63
- If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
64
-
65
- ## Violations
66
-
67
- The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
68
-
69
- ## No Liability
70
-
71
- ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
72
-
73
- ## Definitions
74
-
75
- The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
76
-
77
- A **product** can be a good or service, or a combination of them.
78
-
79
- **You** refers to the individual or entity agreeing to these terms.
80
-
81
- **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
82
-
83
- **Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
84
-
85
- **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
86
-
87
- **Your licenses** are all the licenses granted to you for the software under these terms.
88
-
89
- **Use** means anything you do with the software requiring one of your licenses.
@@ -1,84 +0,0 @@
1
- // Host-neutral causal references for WORLD-ACTOR evidence. These are explicit
2
- // query attributes, not W3C trace parentage: an asynchronous actor reaction
3
- // links to the authoritative world row that caused it without pretending to
4
- // be an in-process child call.
5
-
6
- export const WORLD_ACTOR_CAUSAL_FIELDS = [
7
- "correlation_id",
8
- "world_slug",
9
- "cause_kind",
10
- "cause_id",
11
- "action_id",
12
- "target_ref",
13
- "provenance_id",
14
- "provenance_status",
15
- "provenance_kind",
16
- "failure_class",
17
- ] as const;
18
-
19
- export type WorldActorCausalField = (typeof WORLD_ACTOR_CAUSAL_FIELDS)[number];
20
-
21
- export interface WorldActorCausalContext {
22
- /** Fresh non-secret identifier for one synchronous host request. */
23
- correlation_id?: string;
24
- /** Public deployment routing slug, never a database URL or credential. */
25
- world_slug?: string;
26
- /** Kind and id of an authoritative asynchronous world cause. */
27
- cause_kind?: string;
28
- cause_id?: string;
29
- action_id?: string;
30
- target_ref?: string;
31
- provenance_id?: string;
32
- provenance_status?: string;
33
- provenance_kind?: string;
34
- /** Safe classification only; never the full server failure detail. */
35
- failure_class?: string;
36
- }
37
-
38
- const MAX_CAUSAL_VALUE_LENGTH = 256;
39
-
40
- function boundedNonEmptyString(value: unknown): string | undefined {
41
- if (typeof value !== "string") return undefined;
42
- const trimmed = value.trim();
43
- if (trimmed === "") return undefined;
44
- return trimmed.slice(0, MAX_CAUSAL_VALUE_LENGTH);
45
- }
46
-
47
- /** Parse an untrusted protocol/object value into the closed safe context.
48
- * Unknown fields are dropped. An incomplete asynchronous cause is dropped as
49
- * a pair so callers never manufacture a misleading half-link. */
50
- export function normalizeWorldActorCausalContext(
51
- value: unknown,
52
- ): WorldActorCausalContext | undefined {
53
- if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined;
54
- const source = value as Record<string, unknown>;
55
- const context: WorldActorCausalContext = {};
56
- for (const field of WORLD_ACTOR_CAUSAL_FIELDS) {
57
- const safe = boundedNonEmptyString(source[field]);
58
- if (safe !== undefined) context[field] = safe;
59
- }
60
- if (context.cause_kind === undefined || context.cause_id === undefined) {
61
- delete context.cause_kind;
62
- delete context.cause_id;
63
- }
64
- return Object.keys(context).length === 0 ? undefined : context;
65
- }
66
-
67
- /** Copy the normalized fields into an event-data payload. */
68
- export function worldActorCausalEventData(
69
- context: WorldActorCausalContext | undefined,
70
- ): Record<string, string> {
71
- const safe = normalizeWorldActorCausalContext(context);
72
- return safe === undefined ? {} : Object.fromEntries(Object.entries(safe));
73
- }
74
-
75
- /** Copy normalized context to the shared trace attribute namespace. */
76
- export function worldActorCausalAttributes(
77
- context: WorldActorCausalContext | undefined,
78
- ): Record<string, string> {
79
- const safe = normalizeWorldActorCausalContext(context);
80
- if (safe === undefined) return {};
81
- return Object.fromEntries(
82
- Object.entries(safe).map(([key, value]) => [`spellkave.${key}`, value]),
83
- );
84
- }
package/src/emit.ts DELETED
@@ -1,231 +0,0 @@
1
- // Emit API (ADR-0074 S2). Two callers, one stream:
2
- // - `@spellkave/agent-runtime` (S3) emits NATIVELY from inside
3
- // `runAgentSession` — hosts inject sinks, they cannot bypass emission
4
- // (today's three-partial-channels failure mode is prevented by
5
- // construction).
6
- // - Deterministic NPC/companion runners (ADR-0034) call this API directly —
7
- // they never touch agent-runtime, which is why this module has zero
8
- // LLM/pi dependencies.
9
- import {
10
- AGENT_RUN_EVENTS_VERSION,
11
- type AgentRunEnvelope,
12
- type AgentRunEvent,
13
- type AgentRunEventType,
14
- type ControllerKind,
15
- type RunKind,
16
- type RunRole,
17
- type SinkTruncatedData,
18
- } from "./events.ts";
19
-
20
- /** Where emitted events go. Sinks must never throw into the actor's run —
21
- * the emitter guards every write (a failing sink loses ITS copy only). */
22
- export interface AgentRunSink {
23
- write(event: AgentRunEvent): void;
24
- /** Flush/close when the run ends. Optional; errors are swallowed. */
25
- close?(): void | Promise<void>;
26
- }
27
-
28
- /**
29
- * Synthetic clock for commit-stable / replayable run artifacts.
30
- * Envelope `ts` is required by agent-run-events/v1 — freeze it rather than omit.
31
- */
32
- export interface DeterministicClockOptions {
33
- /** Epoch for the first emit. Default: 2026-01-01T00:00:00.000Z UTC. */
34
- epochMs?: number;
35
- /** Advance per emit call. Default: 1. */
36
- stepMs?: number;
37
- }
38
-
39
- /** Default epoch used when `deterministic: true` with no custom options. */
40
- export const DETERMINISTIC_TS_EPOCH_MS = Date.UTC(2026, 0, 1, 0, 0, 0);
41
-
42
- /**
43
- * Clock that returns epoch, then epoch+step, epoch+2*step, … — one tick per call.
44
- * Pass as `now` to {@link createRunEmitter}, or enable via `deterministic: true`.
45
- */
46
- export function createDeterministicClock(
47
- options: DeterministicClockOptions | number = {},
48
- ): () => Date {
49
- const opts: DeterministicClockOptions =
50
- typeof options === "number" ? { epochMs: options } : options;
51
- const epochMs = opts.epochMs ?? DETERMINISTIC_TS_EPOCH_MS;
52
- const stepMs = opts.stepMs ?? 1;
53
- let tick = 0;
54
- return () => {
55
- const d = new Date(epochMs + tick * stepMs);
56
- tick += 1;
57
- return d;
58
- };
59
- }
60
-
61
- /** Static (per-run) envelope fields — everything but `ts`. */
62
- export interface RunEmitterOptions {
63
- run_id: string;
64
- run_kind: RunKind;
65
- actor_id: string;
66
- role: RunRole;
67
- controller_kind: ControllerKind;
68
- driver: string;
69
- model?: string;
70
- seed?: string;
71
- /**
72
- * Injectable clock. Defaults to wall clock, unless `deterministic` is set
73
- * (then a synthetic advancing clock from {@link DETERMINISTIC_TS_EPOCH_MS}).
74
- * Explicit `now` always wins over `deterministic`.
75
- */
76
- now?: () => Date;
77
- /**
78
- * Commit-stable / replayable timestamps at the emitter (not post-process):
79
- * - `true` → {@link createDeterministicClock} with package defaults
80
- * - options object → same with overrides
81
- * Does not change `run_id` (caller chooses a stable id when wanted).
82
- */
83
- deterministic?: boolean | DeterministicClockOptions;
84
- /**
85
- * When true, any `duration_ms` / `durationMs` on the event `data` payload
86
- * is forced to `0` at emit time (wall-clock timing is the usual churn
87
- * source in committed JSONL). Defaults to `true` when `deterministic` is
88
- * set, else `false`. Explicit value always wins.
89
- */
90
- freezeDurationMs?: boolean;
91
- }
92
-
93
- export interface RunEmitter {
94
- /** The frozen envelope this emitter stamps (without `ts`). */
95
- readonly envelope: Omit<AgentRunEnvelope, "ts">;
96
- emit(type: AgentRunEventType, data?: Record<string, unknown>): void;
97
- /** Close every sink (best-effort, errors swallowed). */
98
- close(): Promise<void>;
99
- }
100
-
101
- function resolveNow(options: RunEmitterOptions): () => Date {
102
- if (options.now !== undefined) return options.now;
103
- if (options.deterministic === undefined || options.deterministic === false) {
104
- return () => new Date();
105
- }
106
- if (options.deterministic === true) return createDeterministicClock();
107
- return createDeterministicClock(options.deterministic);
108
- }
109
-
110
- function resolveFreezeDurationMs(options: RunEmitterOptions): boolean {
111
- if (options.freezeDurationMs !== undefined) return options.freezeDurationMs;
112
- return options.deterministic !== undefined && options.deterministic !== false;
113
- }
114
-
115
- /** Zero volatile duration fields on a data payload (emit-time, not post-hoc). */
116
- export function freezeDurationFields(data: Record<string, unknown>): Record<string, unknown> {
117
- let out: Record<string, unknown> | undefined;
118
- for (const key of ["duration_ms", "durationMs"] as const) {
119
- if (key in data && data[key] !== 0) {
120
- out ??= { ...data };
121
- out[key] = 0;
122
- }
123
- }
124
- return out ?? data;
125
- }
126
-
127
- /**
128
- * Create a per-run emitter that stamps the `agent-run-events/v1` envelope on
129
- * every event and fans it out to the injected sinks.
130
- */
131
- export function createRunEmitter(
132
- options: RunEmitterOptions,
133
- sinks: readonly AgentRunSink[],
134
- ): RunEmitter {
135
- const now = resolveNow(options);
136
- const freezeDurations = resolveFreezeDurationMs(options);
137
- const envelope: Omit<AgentRunEnvelope, "ts"> = {
138
- v: AGENT_RUN_EVENTS_VERSION,
139
- run_id: options.run_id,
140
- run_kind: options.run_kind,
141
- actor_id: options.actor_id,
142
- role: options.role,
143
- controller_kind: options.controller_kind,
144
- driver: options.driver,
145
- ...(options.model !== undefined ? { model: options.model } : {}),
146
- seed: options.seed ?? "",
147
- };
148
- return {
149
- envelope,
150
- emit(type, data = {}) {
151
- const payload = freezeDurations ? freezeDurationFields(data) : data;
152
- const event: AgentRunEvent = {
153
- ...envelope,
154
- ts: now().toISOString(),
155
- type,
156
- data: payload,
157
- };
158
- for (const sink of sinks) {
159
- try {
160
- sink.write(event);
161
- } catch {
162
- // Observability must never break the observed run: a failing sink
163
- // loses its own copy of the event, nothing else.
164
- }
165
- }
166
- },
167
- async close() {
168
- for (const sink of sinks) {
169
- try {
170
- await sink.close?.();
171
- } catch {
172
- // best-effort close
173
- }
174
- }
175
- },
176
- };
177
- }
178
-
179
- /** Hardening (2026-08-06, wedged-session incident): a live incident wedged a
180
- * deterministic-NPC fight loop for 150s and grew that seat's `createMemorySink`
181
- * transcript to 1.1GB via a zero-delay spin — the `events` array is the actual
182
- * unbounded-growth vector IN MEMORY (`createJsonlFileSink` appends straight to
183
- * disk per line and never buffers). `maxEvents` bounds it.
184
- *
185
- * That parenthesis was read as "the file sink is safe" and it is not: a 24/7
186
- * appender fills a disk just as surely, only slower (sk-jay0.6.15.40 — 150-250MB
187
- * per seat on a shared transcript volume). The file sink's own bound is `maxBytes`
188
- * (rotation) in `./node.ts`; the two caps are independent and neither implies
189
- * the other. */
190
- export interface MemorySinkOptions {
191
- /** Stop appending once this many events have been accepted, and emit
192
- * exactly one `sink_truncated` marker in place of the event that would
193
- * have exceeded the cap — every write after that is a silent no-op (the
194
- * marker is emitted once, not once per dropped event). Default:
195
- * `undefined` (uncapped) — existing behavior, byte-identical. */
196
- maxEvents?: number;
197
- }
198
-
199
- /** In-memory sink — tests and the browser gateway's buffer. */
200
- export function createMemorySink(
201
- options: MemorySinkOptions = {},
202
- ): AgentRunSink & { events: AgentRunEvent[] } {
203
- const { maxEvents } = options;
204
- const events: AgentRunEvent[] = [];
205
- let truncated = false;
206
- return {
207
- events,
208
- write(event) {
209
- if (truncated) return;
210
- if (maxEvents !== undefined && events.length >= maxEvents) {
211
- truncated = true;
212
- const data: SinkTruncatedData = { max_events: maxEvents, events_written: events.length };
213
- events.push({ ...event, type: "sink_truncated", data: { ...data } });
214
- return;
215
- }
216
- events.push(event);
217
- },
218
- };
219
- }
220
-
221
- /**
222
- * Browser-gateway sink: hands each event to a host callback (the chat UI's
223
- * live turn status). Deliberately dependency-free — the host owns transport.
224
- */
225
- export function createGatewaySink(onEvent: (event: AgentRunEvent) => void): AgentRunSink {
226
- return {
227
- write(event) {
228
- onEvent(event);
229
- },
230
- };
231
- }