@rivetos/den-protocol 0.0.0-stage → 0.5.0

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/LICENSE ADDED
@@ -0,0 +1,200 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but not
33
+ limited to compiled object code, generated documentation, and
34
+ conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. Please also get an
186
+ information on the current year.
187
+
188
+ Copyright 2026 Philip Tompkins
189
+
190
+ Licensed under the Apache License, Version 2.0 (the "License");
191
+ you may not use this file except in compliance with the License.
192
+ You may obtain a copy of the License at
193
+
194
+ http://www.apache.org/licenses/LICENSE-2.0
195
+
196
+ Unless required by applicable law or agreed to in writing, software
197
+ distributed under the License is distributed on an "AS IS" BASIS,
198
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
199
+ See the License for the specific language governing permissions and
200
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # @rivetos/den-protocol
2
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.
3
+ Event protocol + pure room-state reducer for **rivet-den**, the live pixel-art
4
+ diorama of an agent session. Zero dependencies, renderer-agnostic: adapters
5
+ emit `AgentEvent`s, `reduceDen` folds them into per-session `RoomState`, any
6
+ renderer draws it.
7
+
8
+ See [PROTOCOL.md](./PROTOCOL.md) for the full contract.
9
+
10
+ ```ts
11
+ import { initialDenState, reduceDen, parseEvent } from '@rivetos/den-protocol';
12
+
13
+ let den = initialDenState;
14
+ const ev = parseEvent(JSON.parse(body)); // null if malformed
15
+ if (ev) den = reduceDen(den, ev);
16
+ den.rooms[ev.session]; // → RoomState for the renderer
17
+ ```
@@ -0,0 +1,112 @@
1
+ export declare const PROTOCOL_VERSION: 1;
2
+ /** Coarse activity vocabulary. Packs key pose sets on these; per-tool
3
+ * overrides refine them (tool → activity → 'idle' fallback chain). */
4
+ export type Activity = 'idle' | 'thinking' | 'searching_web' | 'editing_code' | 'running_command' | 'writing_plan' | 'listening' | 'speaking' | 'sleeping';
5
+ export declare const ACTIVITIES: readonly Activity[];
6
+ /** Harness that produced an event. Free-form for forward-compat; well-known
7
+ * values are listed. */
8
+ export type Harness = 'claude-code' | 'grok-build' | 'rivetos' | (string & {});
9
+ /** Event payloads, discriminated on `type`. */
10
+ export type AgentEventBody = {
11
+ type: 'session.start';
12
+ title: string;
13
+ } | {
14
+ type: 'session.end';
15
+ }
16
+ /** End of ONE agent turn (harness Stop hook) — the session stays alive.
17
+ * Chat clients commit the streamed reply and release their send queue on
18
+ * this; the room just goes idle. Distinct from session.end (harness exit). */
19
+ | {
20
+ type: 'turn.end';
21
+ } | {
22
+ type: 'task.plan';
23
+ tasks: string[];
24
+ } | {
25
+ type: 'task.check';
26
+ index: number;
27
+ } | {
28
+ type: 'activity';
29
+ activity: Activity;
30
+ }
31
+ /** Raw tool invocation. `tool` is the harness's tool name verbatim
32
+ * (e.g. 'Bash', 'WebSearch', 'mcp:rivetos:memory_search'). Adapters may
33
+ * suggest a coarse `activity`; the reducer otherwise derives one. */
34
+ /** Optional `args` are a summarized tool_input map for Hub titles/chips
35
+ * (never required; unknown producers still emit name-only). */
36
+ | {
37
+ type: 'tool.start';
38
+ tool: string;
39
+ activity?: Activity;
40
+ args?: Record<string, unknown>;
41
+ } | {
42
+ type: 'tool.end';
43
+ tool?: string;
44
+ } | {
45
+ type: 'thinking.delta';
46
+ text: string;
47
+ } | {
48
+ type: 'thinking.end';
49
+ } | {
50
+ type: 'speech.stt';
51
+ active: boolean;
52
+ } | {
53
+ type: 'message.user';
54
+ text: string;
55
+ }
56
+ /** Assistant text block. On the FINAL block of a turn the adapter may attach
57
+ * `usage`/`model`/`durationMs` (Claude Code reads them from its transcript);
58
+ * the den reducer ignores them, but the RivetHub bridge threads them onto
59
+ * the committed chat message. Interim blocks omit them. */
60
+ | {
61
+ type: 'message.agent';
62
+ text: string;
63
+ usage?: TokenUsage;
64
+ model?: string;
65
+ durationMs?: number;
66
+ } | {
67
+ type: 'term.line';
68
+ text: string;
69
+ };
70
+ /** Token accounting attachable to a final message.agent event.
71
+ * `completionTokens` is summed over the turn; `promptTokens` is the final
72
+ * request's input (context size at turn end), including cached input;
73
+ * `cachedTokens` is the cache-read portion of that. */
74
+ export interface TokenUsage {
75
+ promptTokens: number;
76
+ completionTokens: number;
77
+ cachedTokens: number;
78
+ }
79
+ /** Envelope common to every event. */
80
+ export interface AgentEventMeta {
81
+ /** Protocol version. Always 1 for this schema. */
82
+ v: typeof PROTOCOL_VERSION;
83
+ /** Stable session identifier — one den room per session. */
84
+ session: string;
85
+ /** Optional human-readable session display name. */
86
+ name?: string;
87
+ /** Producing harness. */
88
+ harness?: Harness;
89
+ /**
90
+ * The harness's OWN session id, when it is not the same string as `session`.
91
+ *
92
+ * Claude Code and Grok Build are spawned with `--session-id <den room key>`,
93
+ * so for them the two ids coincide and this is omitted. Hermes has no flag to
94
+ * pin a new session's id and mints its own (`20260802_225647_6ad0b9`), so its
95
+ * hook reports both: `session` stays the den room everything joins on, and
96
+ * this carries the id the harness store and capture key. It is also the only
97
+ * place on the wire a session-id ROTATION is observable — the hermes driver
98
+ * watches this field change within one room (docs/ARCHITECTURE.md
99
+ * § Session identity).
100
+ */
101
+ harnessSession?: string;
102
+ /** Milliseconds since epoch at emit time. */
103
+ ts?: number;
104
+ }
105
+ export type AgentEvent = AgentEventMeta & AgentEventBody;
106
+ /** Default mapping from raw tool names to coarse activities, used when the
107
+ * adapter didn't supply one. Unknown tools fall back to 'running_command'. */
108
+ export declare function toolActivity(name: string): Activity;
109
+ /** Runtime validation for events arriving over the wire (POST /hook, WS).
110
+ * Returns the typed event, or null if the value is not a valid v1 event. */
111
+ export declare function parseEvent(raw: unknown): AgentEvent | null;
112
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB,EAAG,CAAU,CAAA;AAE1C;uEACuE;AACvE,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,UAAU,GACV,eAAe,GACf,cAAc,GACd,iBAAiB,GACjB,cAAc,GACd,WAAW,GACX,UAAU,GACV,UAAU,CAAA;AAEd,eAAO,MAAM,UAAU,EAAE,SAAS,QAAQ,EAUzC,CAAA;AAED;yBACyB;AACzB,MAAM,MAAM,OAAO,GAAG,aAAa,GAAG,YAAY,GAAG,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAE9E,+CAA+C;AAC/C,MAAM,MAAM,cAAc,GACtB;IAAE,I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AM,WAAW,UAAU;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,gBAAgB,EAAE,MAAM,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC7B,kDAAkD;IAClD,CAAC,EAAE,OAAO,gBAAgB,CAAA;IAC1B,4DAA4D;IAC5D,OAAO,EAAE,MAAM,CAAA;IACf,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,yBAAyB;IACzB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,6CAA6C;IAC7C,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ;AAED,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,cAAc,CAAA;AAExD;+EAC+E;AAC/E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAqBnD;AAED;6EAC6E;AAC7E,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAuE1D"}
package/dist/events.js ADDED
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ // rivet-den event protocol, version 1.
3
+ // Normalized agent events emitted by harness adapters (Claude Code, Grok
4
+ // Build, rivetos-native) and consumed by the den reducer/renderer.
5
+ // See PROTOCOL.md for the full contract.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.ACTIVITIES = exports.PROTOCOL_VERSION = void 0;
8
+ exports.toolActivity = toolActivity;
9
+ exports.parseEvent = parseEvent;
10
+ exports.PROTOCOL_VERSION = 1;
11
+ exports.ACTIVITIES = [
12
+ 'idle',
13
+ 'thinking',
14
+ 'searching_web',
15
+ 'editing_code',
16
+ 'running_command',
17
+ 'writing_plan',
18
+ 'listening',
19
+ 'speaking',
20
+ 'sleeping',
21
+ ];
22
+ /** Default mapping from raw tool names to coarse activities, used when the
23
+ * adapter didn't supply one. Unknown tools fall back to 'running_command'. */
24
+ function toolActivity(name) {
25
+ const n = name.toLowerCase();
26
+ if (n.includes('websearch') ||
27
+ n.includes('webfetch') ||
28
+ n.includes('web_search') ||
29
+ n.includes('web_fetch') ||
30
+ n.includes('internet_search'))
31
+ return 'searching_web';
32
+ if (n === 'edit' || n === 'write' || n === 'notebookedit' || n.includes('applypatch'))
33
+ return 'editing_code';
34
+ if (n === 'taskcreate' || n === 'taskupdate' || n === 'exitplanmode' || n === 'enterplanmode')
35
+ return 'writing_plan';
36
+ if (n === 'read' || n === 'grep' || n === 'glob')
37
+ return 'thinking';
38
+ // CLI/shell runs happen at the computer — the desk terminal is already
39
+ // echoing the command. The toolbox (running_command) is for plugin/MCP
40
+ // tools and anything else without a station of its own.
41
+ if (n === 'bash' || n === 'run_terminal_cmd' || n === 'shell' || n.includes('terminal'))
42
+ return 'editing_code';
43
+ return 'running_command';
44
+ }
45
+ /** Runtime validation for events arriving over the wire (POST /hook, WS).
46
+ * Returns the typed event, or null if the value is not a valid v1 event. */
47
+ function parseEvent(raw) {
48
+ if (typeof raw !== 'object' || raw === null)
49
+ return null;
50
+ const e = raw;
51
+ if (e.v !== exports.PROTOCOL_VERSION)
52
+ return null;
53
+ if (typeof e.session !== 'string' || e.session.length === 0)
54
+ return null;
55
+ if (typeof e.type !== 'string')
56
+ return null;
57
+ // envelope optionals: wrong-typed metadata (ts: "abc", name: 42) would
58
+ // otherwise flow into the recency sort / display untouched
59
+ if (e.name !== undefined && typeof e.name !== 'string')
60
+ return null;
61
+ if (e.harness !== undefined && typeof e.harness !== 'string')
62
+ return null;
63
+ if (e.harnessSession !== undefined && typeof e.harnessSession !== 'string')
64
+ return null;
65
+ if (e.ts !== undefined && (typeof e.ts !== 'number' || !Number.isFinite(e.ts)))
66
+ return null;
67
+ const str = (k) => typeof e[k] === 'string';
68
+ switch (e.type) {
69
+ case 'session.start':
70
+ return str('title') ? raw : null;
71
+ case 'session.end':
72
+ case 'turn.end':
73
+ case 'thinking.end':
74
+ return raw;
75
+ case 'task.plan':
76
+ return Array.isArray(e.tasks) && e.tasks.every((t) => typeof t === 'string')
77
+ ? raw
78
+ : null;
79
+ case 'task.check':
80
+ return typeof e.index === 'number' && Number.isInteger(e.index) && e.index >= 0
81
+ ? raw
82
+ : null;
83
+ case 'activity':
84
+ return exports.ACTIVITIES.includes(e.activity)
85
+ ? raw
86
+ : null;
87
+ case 'tool.start':
88
+ if (!str('tool'))
89
+ return null;
90
+ if (e.activity !== undefined &&
91
+ !exports.ACTIVITIES.includes(e.activity))
92
+ return null;
93
+ return raw;
94
+ case 'tool.end':
95
+ return e.tool === undefined || str('tool') ? raw : null;
96
+ case 'speech.stt':
97
+ return typeof e.active === 'boolean' ? raw : null;
98
+ case 'thinking.delta':
99
+ case 'message.user':
100
+ case 'term.line':
101
+ return str('text') ? raw : null;
102
+ case 'message.agent': {
103
+ if (!str('text'))
104
+ return null;
105
+ // optional turn stats — reject malformed rather than pass junk downstream
106
+ if (e.model !== undefined && typeof e.model !== 'string')
107
+ return null;
108
+ // durationMs / token counts must be finite and non-negative
109
+ const nonNeg = (v) => typeof v === 'number' && Number.isFinite(v) && v >= 0;
110
+ if (e.durationMs !== undefined && !nonNeg(e.durationMs))
111
+ return null;
112
+ if (e.usage !== undefined) {
113
+ const u = e.usage;
114
+ if (typeof u !== 'object' ||
115
+ u === null ||
116
+ !nonNeg(u.promptTokens) ||
117
+ !nonNeg(u.completionTokens) ||
118
+ !nonNeg(u.cachedTokens))
119
+ return null;
120
+ }
121
+ return raw;
122
+ }
123
+ default:
124
+ return null;
125
+ }
126
+ }
127
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,yEAAyE;AACzE,mEAAmE;AACnE,yCAAyC;;;AA6GzC,oCAqBC;AAID,gCAuEC;AA3MY,QAAA,gBAAgB,GAAG,CAAU,CAAA;AAe7B,QA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C,CAAC,CAAC;YACrB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,OAAO,IAAI,CAAA;YAC7B,0EAA0E;YAC1E,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ;gBAAE,OAAO,IAAI,CAAA;YACrE,4DAA4D;YAC5D,MAAM,MAAM,GAAG,CAAC,CAAU,EAAW,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YAC7F,IAAI,CAAC,CAAC,UAAU,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC;gBAAE,OAAO,IAAI,CAAA;YACpE,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBAC1B,MAAM,CAAC,GAAG,CAAC,CAAC,KAAuC,CAAA;gBACnD,IACE,OAAO,CAAC,KAAK,QAAQ;oBACrB,CAAC,KAAK,IAAI;oBACV,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC;oBACvB,CAAC,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC;oBAC3B,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC;oBAEvB,OAAO,IAAI,CAAA;YACf,CAAC;YACD,OAAO,GAAiB,CAAA;QAC1B,CAAC;QACD;YACE,OAAO,IAAI,CAAA;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { PROTOCOL_VERSION, ACTIVITIES, toolActivity, parseEvent, type Activity, type Harness, type AgentEvent, type AgentEventBody, type AgentEventMeta, type TokenUsage, } from './events.js';
2
+ export { initialRoomState, reduceRoom, initialDenState, reduceDen, listSessions, type Task, type LogEntry, type RoomState, type SessionInfo, type DenState, } from './reducer.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,UAAU,EACV,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,UAAU,GAChB,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,SAAS,EACT,YAAY,EACZ,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,QAAQ,GACd,MAAM,cAAc,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listSessions = exports.reduceDen = exports.initialDenState = exports.reduceRoom = exports.initialRoomState = exports.parseEvent = exports.toolActivity = exports.ACTIVITIES = exports.PROTOCOL_VERSION = void 0;
4
+ var events_js_1 = require("./events.js");
5
+ Object.defineProperty(exports, "PROTOCOL_VERSION", { enumerable: true, get: function () { return events_js_1.PROTOCOL_VERSION; } });
6
+ Object.defineProperty(exports, "ACTIVITIES", { enumerable: true, get: function () { return events_js_1.ACTIVITIES; } });
7
+ Object.defineProperty(exports, "toolActivity", { enumerable: true, get: function () { return events_js_1.toolActivity; } });
8
+ Object.defineProperty(exports, "parseEvent", { enumerable: true, get: function () { return events_js_1.parseEvent; } });
9
+ var reducer_js_1 = require("./reducer.js");
10
+ Object.defineProperty(exports, "initialRoomState", { enumerable: true, get: function () { return reducer_js_1.initialRoomState; } });
11
+ Object.defineProperty(exports, "reduceRoom", { enumerable: true, get: function () { return reducer_js_1.reduceRoom; } });
12
+ Object.defineProperty(exports, "initialDenState", { enumerable: true, get: function () { return reducer_js_1.initialDenState; } });
13
+ Object.defineProperty(exports, "reduceDen", { enumerable: true, get: function () { return reducer_js_1.reduceDen; } });
14
+ Object.defineProperty(exports, "listSessions", { enumerable: true, get: function () { return reducer_js_1.listSessions; } });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,yCAWoB;AAVlB,6GAAA,gBAAgB,OAAA;AAChB,uGAAA,UAAU,OAAA;AACV,yGAAA,YAAY,OAAA;AACZ,uGAAA,UAAU,OAAA;AASZ,2CAWqB;AAVnB,8GAAA,gBAAgB,OAAA;AAChB,wGAAA,UAAU,OAAA;AACV,6GAAA,eAAe,OAAA;AACf,uGAAA,SAAS,OAAA;AACT,0GAAA,YAAY,OAAA"}
@@ -0,0 +1,41 @@
1
+ import { type Activity, type AgentEvent } from './events.js';
2
+ export interface Task {
3
+ label: string;
4
+ done: boolean;
5
+ }
6
+ export interface LogEntry {
7
+ who: 'user' | 'agent';
8
+ text: string;
9
+ }
10
+ export interface RoomState {
11
+ title: string;
12
+ activity: Activity;
13
+ /** Raw tool name while a tool runs, else null. Packs use this for
14
+ * per-tool pose overrides (fallback: activity, then 'idle'). */
15
+ tool: string | null;
16
+ tasks: Task[];
17
+ thought: string;
18
+ lastMessage: string;
19
+ log: LogEntry[];
20
+ term: string[];
21
+ ended: boolean;
22
+ }
23
+ export declare const initialRoomState: RoomState;
24
+ export declare function reduceRoom(state: RoomState, ev: AgentEvent): RoomState;
25
+ export interface SessionInfo {
26
+ id: string;
27
+ /** Display name — last non-empty `name` seen on the wire, else the id. */
28
+ name: string;
29
+ harness?: string;
30
+ /** ts of the most recent event, when events carry timestamps. */
31
+ lastEventTs?: number;
32
+ }
33
+ export interface DenState {
34
+ rooms: Record<string, RoomState>;
35
+ sessions: Record<string, SessionInfo>;
36
+ }
37
+ export declare const initialDenState: DenState;
38
+ export declare function reduceDen(state: DenState, ev: AgentEvent): DenState;
39
+ /** Session list ordered by recency (most recent event first, unknown last). */
40
+ export declare function listSessions(state: DenState): SessionInfo[];
41
+ //# sourceMappingURL=reducer.d.ts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AS,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,UAAU,GAAG,QAAQ,CAenE;AAED,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,WAAW,EAAE,CAE3D"}
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ // Pure room-state reducer: feed AgentEvents in, get RoomState out.
3
+ // Renderer-agnostic — no PixiJS, no DOM, no timers.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.initialDenState = exports.initialRoomState = void 0;
6
+ exports.reduceRoom = reduceRoom;
7
+ exports.reduceDen = reduceDen;
8
+ exports.listSessions = listSessions;
9
+ const events_js_1 = require("./events.js");
10
+ exports.initialRoomState = {
11
+ title: '',
12
+ activity: 'idle',
13
+ tool: null,
14
+ tasks: [],
15
+ thought: '',
16
+ lastMessage: '',
17
+ log: [],
18
+ term: [],
19
+ ended: false,
20
+ };
21
+ const THOUGHT_MAX = 220;
22
+ const LOG_MAX = 60; // the chat panel scrolls now — keep real history
23
+ const TERM_MAX = 6;
24
+ function reduceRoom(state, ev) {
25
+ // an ended room only wakes up on a new session.start — late tool.end /
26
+ // speech events from a dying harness must not reanimate it
27
+ if (state.ended && ev.type !== 'session.start')
28
+ return state;
29
+ switch (ev.type) {
30
+ case 'session.start':
31
+ // the conversation log survives session boundaries (compaction, resume)
32
+ return { ...exports.initialRoomState, title: ev.title, log: state.log };
33
+ case 'session.end':
34
+ return { ...state, activity: 'sleeping', tool: null, thought: '', ended: true };
35
+ case 'task.plan':
36
+ return {
37
+ ...state,
38
+ tasks: ev.tasks.map((label) => ({ label, done: false })),
39
+ activity: 'writing_plan',
40
+ };
41
+ case 'task.check': {
42
+ const tasks = state.tasks.map((t, i) => (i === ev.index ? { ...t, done: true } : t));
43
+ return { ...state, tasks };
44
+ }
45
+ case 'activity':
46
+ return {
47
+ ...state,
48
+ activity: ev.activity,
49
+ tool: null,
50
+ thought: ev.activity === 'thinking' ? state.thought : '',
51
+ };
52
+ case 'tool.start':
53
+ return {
54
+ ...state,
55
+ tool: ev.tool,
56
+ activity: ev.activity ?? (0, events_js_1.toolActivity)(ev.tool),
57
+ thought: '',
58
+ };
59
+ case 'tool.end':
60
+ return { ...state, tool: null, activity: 'thinking' };
61
+ case 'turn.end':
62
+ // reply complete, harness waiting for the next prompt — settle to idle
63
+ // (message.agent just set 'speaking'; without this the bot orates until
64
+ // the next event). Thought bubble clears; the log keeps the reply.
65
+ return { ...state, activity: 'idle', tool: null, thought: '' };
66
+ case 'thinking.delta': {
67
+ // spinner-style status lines ("✳ Architecting… (28s · …)") replace the
68
+ // bubble wholesale; real streamed thinking appends as before
69
+ if (/^[✳✢✻✽·] /.test(ev.text))
70
+ return { ...state, activity: 'thinking', tool: null, thought: ev.text };
71
+ let thought = (state.thought + ev.text).slice(-THOUGHT_MAX);
72
+ // when the window is full, trim to a word boundary so the stream never
73
+ // opens mid-word
74
+ if (thought.length === THOUGHT_MAX)
75
+ thought = thought.replace(/^\S*\s+/, '');
76
+ return { ...state, activity: 'thinking', tool: null, thought };
77
+ }
78
+ case 'thinking.end':
79
+ return { ...state, thought: '' };
80
+ case 'speech.stt':
81
+ return ev.active
82
+ ? { ...state, activity: 'listening', tool: null, thought: '' }
83
+ : { ...state, activity: 'thinking' };
84
+ case 'message.user':
85
+ return {
86
+ ...state,
87
+ log: [...state.log, { who: 'user', text: ev.text }].slice(-LOG_MAX),
88
+ };
89
+ case 'message.agent':
90
+ return {
91
+ ...state,
92
+ lastMessage: ev.text,
93
+ activity: 'speaking',
94
+ tool: null,
95
+ thought: '',
96
+ log: [...state.log, { who: 'agent', text: ev.text }].slice(-LOG_MAX),
97
+ };
98
+ case 'term.line':
99
+ return { ...state, term: [...state.term, ev.text].slice(-TERM_MAX) };
100
+ default:
101
+ // additive-within-v1: consumers ignore event types they don't know
102
+ return state;
103
+ }
104
+ }
105
+ exports.initialDenState = { rooms: {}, sessions: {} };
106
+ function reduceDen(state, ev) {
107
+ const room = state.rooms[ev.session] ?? exports.initialRoomState;
108
+ const prev = state.sessions[ev.session];
109
+ const info = {
110
+ id: ev.session,
111
+ name: ev.name || prev?.name || ev.session,
112
+ harness: ev.harness ?? prev?.harness,
113
+ // monotonic: a stale out-of-order event must not drop the session down
114
+ // the recency-sorted picker
115
+ lastEventTs: ev.ts === undefined ? prev?.lastEventTs : Math.max(ev.ts, prev?.lastEventTs ?? 0),
116
+ };
117
+ return {
118
+ rooms: { ...state.rooms, [ev.session]: reduceRoom(room, ev) },
119
+ sessions: { ...state.sessions, [ev.session]: info },
120
+ };
121
+ }
122
+ /** Session list ordered by recency (most recent event first, unknown last). */
123
+ function listSessions(state) {
124
+ return Object.values(state.sessions).sort((a, b) => (b.lastEventTs ?? 0) - (a.lastEventTs ?? 0));
125
+ }
126
+ //# sourceMappingURL=reducer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducer.js","sourceRoot":"","sources":["../src/reducer.ts"],"names":[],"mappings":";AAAA,mEAAmE;AACnE,oDAAoD;;;AA4CpD,gCA8EC;AAqBD,8BAeC;AAGD,oCAEC;AAjKD,2CAA0E;AA0B7D,QAAA,gBAAgB,GAAc;IACzC,KAAK,EAAE,EAAE;IACT,QAAQ,EAAE,MAAM;IAChB,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,EAAE;IACT,OAAO,EAAE,EAAE;IACX,WAAW,EAAE,EAAE;IACf,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,KAAK;CACb,CAAA;AAED,MAAM,WAAW,GAAG,GAAG,CAAA;AACvB,MAAM,OAAO,GAAG,EAAE,CAAA,CAAC,iDAAiD;AACpE,MAAM,QAAQ,GAAG,CAAC,CAAA;AAElB,SAAgB,UAAU,CAAC,KAAgB,EAAE,EAAc;IACzD,uEAAuE;IACvE,2DAA2D;IAC3D,IAAI,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,KAAK,eAAe;QAAE,OAAO,KAAK,CAAA;IAC5D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O,CAAC,CAAA;IACjF,MAAM,IAAI,GAAgB;QACxB,EAAE,EAAE,EAAE,CAAC,OAAO;QACd,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO;QACzC,OAAO,EAAE,EAAE,CAAC,OAAO,IAAI,IAAI,EAAE,OAAO;QACpC,uEAAuE;QACvE,4BAA4B;QAC5B,WAAW,EAAE,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,IAAI,CAAC,CAAC;KAC/F,CAAA;IACD,OAAO;QACL,KAAK,EAAE,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE;QAC7D,QAAQ,EAAE,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE;KACpD,CAAA;AACH,CAAC;AAED,+EAA+E;AAC/E,SAAgB,YAAY,CAAC,KAAe;IAC1C,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,CAAC,CAAA;AAClG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@rivetos/den-protocol",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.5.0",
4
+ "description": "rivet-den event protocol — normalized agent events + pure room-state reducer",
5
+ "license": "Apache-2.0",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc -p tsconfig.json",
10
+ "typecheck": "tsc --noEmit -p tsconfig.json",
11
+ "lint": "eslint src/ package.json",
12
+ "test": "vitest run",
13
+ "clean": "rm -rf dist",
14
+ "prepublishOnly": "npm run build"
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.js"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/philbert440/rivetOS.git",
31
+ "directory": "packages/den-protocol"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "engines": {
37
+ "node": ">=22.0.0"
38
+ },
39
+ "nx": {
40
+ "tags": [
41
+ "scope:contract",
42
+ "type:lib",
43
+ "domain:shared"
44
+ ]
45
+ }
46
+ }