@ccmsg/protocol 1.19.0 → 1.20.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/package.json +1 -1
- package/src/common/topics.ts +12 -2
- package/src/control/agents.ts +23 -4
- package/src/control/instances.ts +21 -0
- package/src/control/peers.ts +52 -68
- package/src/fixtures/index.ts +1 -0
- package/src/fixtures/topics.ts +31 -10
- package/src/index.ts +1 -0
- package/src/schemas.ts +2 -0
package/package.json
CHANGED
package/src/common/topics.ts
CHANGED
|
@@ -7,6 +7,7 @@ export const PLAIN_TOPICS = [
|
|
|
7
7
|
"inbox",
|
|
8
8
|
"notify",
|
|
9
9
|
"peers",
|
|
10
|
+
"instances",
|
|
10
11
|
"agents",
|
|
11
12
|
"session_errors",
|
|
12
13
|
"llm_requests",
|
|
@@ -89,8 +90,17 @@ export interface TopicAttributes {
|
|
|
89
90
|
export const TOPIC_ATTRIBUTES = {
|
|
90
91
|
inbox: { roles: ["session", "user"], granularity: "element" },
|
|
91
92
|
notify: { roles: ["session", "user"], granularity: "event" },
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
// A row here changes on its own — one session becomes busy while the rest
|
|
94
|
+
// stand still — so a frame carries the rows that changed rather than every
|
|
95
|
+
// row the instance knows.
|
|
96
|
+
peers: { roles: ["session", "user"], granularity: "element" },
|
|
97
|
+
// One instance's whole reading of its links, taken together, which is why it
|
|
98
|
+
// is apart from the rows of `peers`.
|
|
99
|
+
instances: { roles: ["session", "user"], granularity: "per_instance_whole" },
|
|
100
|
+
agents: { roles: ["user"], granularity: "element" },
|
|
101
|
+
// A set the instance derives whole, by folding one error pattern over its
|
|
102
|
+
// sessions: it learns which sessions are stopped, not that one of them
|
|
103
|
+
// changed, so each frame is that reading entire.
|
|
94
104
|
session_errors: { roles: ["user"], granularity: "per_instance_whole" },
|
|
95
105
|
llm_requests: {
|
|
96
106
|
roles: ["user"],
|
package/src/control/agents.ts
CHANGED
|
@@ -50,15 +50,34 @@ export const AgentInfo = Type.Object(
|
|
|
50
50
|
);
|
|
51
51
|
export type AgentInfo = Static<typeof AgentInfo>;
|
|
52
52
|
|
|
53
|
-
/**
|
|
53
|
+
/** A row that is gone: the harness no longer reports this session, or the
|
|
54
|
+
* instance that polled it stopped. Marked rather than absent, since a frame
|
|
55
|
+
* carries only what changed. */
|
|
56
|
+
export const AgentRemoved = Type.Object(
|
|
57
|
+
{
|
|
58
|
+
sid: Sid,
|
|
59
|
+
instance: InstanceId,
|
|
60
|
+
removed: Type.Literal(true),
|
|
61
|
+
},
|
|
62
|
+
{ $id: "AgentRemoved" },
|
|
63
|
+
);
|
|
64
|
+
export type AgentRemoved = Static<typeof AgentRemoved>;
|
|
65
|
+
|
|
66
|
+
export const AgentElement = Type.Union([AgentInfo, AgentRemoved], { $id: "AgentElement" });
|
|
67
|
+
export type AgentElement = Static<typeof AgentElement>;
|
|
68
|
+
|
|
69
|
+
/** The `agents` topic. Elements, like `peers`: the rows that changed since the
|
|
70
|
+
* last frame, matched by their `instance` and `sid`.
|
|
54
71
|
*
|
|
55
72
|
* The instance polls the harness only while somebody is listening here, so the
|
|
56
|
-
* list is as fresh as the subscription is old
|
|
73
|
+
* list is as fresh as the subscription is old — and a poll that finds one
|
|
74
|
+
* session's status changed says that, rather than restating every row it read.
|
|
75
|
+
*/
|
|
57
76
|
export const AgentsFrame = topicFrame(
|
|
58
77
|
"agents",
|
|
59
78
|
Type.Object({
|
|
60
|
-
agents: Type.Array(
|
|
61
|
-
/** When the poll behind
|
|
79
|
+
agents: Type.Array(AgentElement),
|
|
80
|
+
/** When the poll behind these rows ran. Absent before the first one. */
|
|
62
81
|
polled_at: Type.Optional(Timestamp),
|
|
63
82
|
}),
|
|
64
83
|
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { InstanceInfo } from "../common/hello.ts";
|
|
3
|
+
import { topicFrame } from "../envelope.ts";
|
|
4
|
+
|
|
5
|
+
/** The `instances` topic: the mesh as one instance sees it, itself included,
|
|
6
|
+
* as `hello` answers it.
|
|
7
|
+
*
|
|
8
|
+
* Carried as a topic so that a link going down is something a subscriber
|
|
9
|
+
* learns where it is already listening, rather than by greeting again to find
|
|
10
|
+
* out.
|
|
11
|
+
*
|
|
12
|
+
* Whole-value per instance: `reachable` is one instance's reading of every
|
|
13
|
+
* link it has, taken together, and two instances may legitimately disagree
|
|
14
|
+
* about the same link — so a frame states one sender's whole view and leaves
|
|
15
|
+
* every other sender's alone. It is apart from `peers` for the same reason it
|
|
16
|
+
* is whole: a mesh view is one value, while a session row is a row, and an
|
|
17
|
+
* entry here may also stand before its instance has an id to be matched by. */
|
|
18
|
+
export const InstancesFrame = topicFrame(
|
|
19
|
+
"instances",
|
|
20
|
+
Type.Object({ instances: Type.Array(InstanceInfo) }),
|
|
21
|
+
);
|
package/src/control/peers.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type Static, Type } from "@sinclair/typebox";
|
|
2
|
-
import { InstanceInfo } from "../common/hello.ts";
|
|
3
2
|
import { topicFrame } from "../envelope.ts";
|
|
4
3
|
import { InstanceId, Sid, Timestamp } from "../identifiers.ts";
|
|
5
4
|
import { SessionMetaFields } from "../session-meta.ts";
|
|
@@ -31,8 +30,9 @@ export const SessionState = Type.Union(
|
|
|
31
30
|
);
|
|
32
31
|
export type SessionState = Static<typeof SessionState>;
|
|
33
32
|
|
|
34
|
-
/** How long a session
|
|
35
|
-
*
|
|
33
|
+
/** How long a lost session's row is kept after it was last seen, before the
|
|
34
|
+
* instance forgets it and the row leaves as a removal. The same window the inbox
|
|
35
|
+
* keeps undelivered messages for: what a person comes back to
|
|
36
36
|
* is one thing — the session and what was said to it — so the two cannot expire
|
|
37
37
|
* at different times. */
|
|
38
38
|
export const LAST_LIVE_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
@@ -57,11 +57,20 @@ export const StaleClientInfo = Type.Object(
|
|
|
57
57
|
);
|
|
58
58
|
export type StaleClientInfo = Static<typeof StaleClientInfo>;
|
|
59
59
|
|
|
60
|
-
/** One session an instance
|
|
60
|
+
/** One session an instance knows of, connected or lost.
|
|
61
61
|
*
|
|
62
62
|
* The paths are the host's, so the entry names the instance holding them:
|
|
63
63
|
* `peers` carries every instance's sessions in one list, and two hosts' paths
|
|
64
|
-
* would otherwise be indistinguishable.
|
|
64
|
+
* would otherwise be indistinguishable. The pair `instance` and `sid` is also
|
|
65
|
+
* what a later row is matched against, since one session lives on one
|
|
66
|
+
* instance.
|
|
67
|
+
*
|
|
68
|
+
* Connected and lost sessions are one kind of row rather than two lists: a
|
|
69
|
+
* session registering or going quiet moves it between the two, and a row that
|
|
70
|
+
* changed lists while keeping its identity is an update of that row. Which it
|
|
71
|
+
* is now is the `state` below, and the fields that only a lost session has
|
|
72
|
+
* (`last_seen_at`, `stopped_at`, and what it must resume as) are stated
|
|
73
|
+
* alongside the connection fields it kept. */
|
|
65
74
|
export const PeerInfo = Type.Object(
|
|
66
75
|
{
|
|
67
76
|
sid: Sid,
|
|
@@ -81,10 +90,10 @@ export const PeerInfo = Type.Object(
|
|
|
81
90
|
* notification's `sid_label` — so the material for those is on the row that
|
|
82
91
|
* every client already holds. */
|
|
83
92
|
title: Type.Optional(SessionMetaFields.title),
|
|
84
|
-
/** How this session stands
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
93
|
+
/** How this session stands, which is also what separates a connected row
|
|
94
|
+
* from one its instance has lost. Absent from an instance that states no
|
|
95
|
+
* classification, and a client then shows the session without grouping it
|
|
96
|
+
* rather than guessing one. */
|
|
88
97
|
state: Type.Optional(SessionState),
|
|
89
98
|
/** Set while a person has pinned this session. Absent means not pinned. */
|
|
90
99
|
pinned: Type.Optional(Type.Boolean()),
|
|
@@ -129,77 +138,52 @@ export const PeerInfo = Type.Object(
|
|
|
129
138
|
protocol_version: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
130
139
|
/** Set while some client of this session is being refused. */
|
|
131
140
|
stale_client: Type.Optional(StaleClientInfo),
|
|
141
|
+
/** The newest instant this session is known to have been alive. Stated on a
|
|
142
|
+
* row its instance has lost, where it is what the retention window above is
|
|
143
|
+
* measured from; a connected row is alive now and states none. */
|
|
144
|
+
last_seen_at: Type.Optional(Timestamp),
|
|
145
|
+
/** When the session said it was stopping. Its presence is what makes a lost
|
|
146
|
+
* session a pause rather than a disappearance: one that goes without a word
|
|
147
|
+
* leaves nothing to stamp here. */
|
|
148
|
+
stopped_at: Type.Optional(Timestamp),
|
|
149
|
+
/** What its last turn ran as, in the transcript's own spelling, read back
|
|
150
|
+
* from the transcript rather than copied from the connection: what a lost
|
|
151
|
+
* session must resume as is a property of where it actually stopped. A
|
|
152
|
+
* resume must not quietly switch the session to something else. */
|
|
153
|
+
model: Type.Optional(SessionMetaFields.model),
|
|
154
|
+
effort: Type.Optional(SessionMetaFields.effort),
|
|
132
155
|
},
|
|
133
156
|
{ $id: "PeerInfo" },
|
|
134
157
|
);
|
|
135
158
|
export type PeerInfo = Static<typeof PeerInfo>;
|
|
136
159
|
|
|
137
|
-
/**
|
|
138
|
-
*
|
|
160
|
+
/** A row that is gone: the session has been forgotten by the instance that
|
|
161
|
+
* held it, whether its retention window ran out or a person dropped it.
|
|
139
162
|
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
|
|
145
|
-
* written. An entry leaves this list the moment its session registers again, so
|
|
146
|
-
* a fully recovered host shows none. */
|
|
147
|
-
export const LastLiveSession = Type.Object(
|
|
163
|
+
* A removal has to be a marked element rather than an absence, since a frame
|
|
164
|
+
* carries only what changed and an absence in it says nothing. It names the
|
|
165
|
+
* same pair every row is matched by and nothing else — there is no row left to
|
|
166
|
+
* describe. */
|
|
167
|
+
export const PeerRemoved = Type.Object(
|
|
148
168
|
{
|
|
149
169
|
sid: Sid,
|
|
150
170
|
instance: InstanceId,
|
|
151
|
-
|
|
152
|
-
ws: SessionMetaFields.ws,
|
|
153
|
-
cwd: SessionMetaFields.cwd,
|
|
154
|
-
/** Also where the model and effort below were read from. */
|
|
155
|
-
transcript_path: Type.Optional(SessionMetaFields.transcript_path),
|
|
156
|
-
repo_root: Type.Optional(SessionMetaFields.repo_root),
|
|
157
|
-
branch: Type.Optional(SessionMetaFields.branch),
|
|
158
|
-
title: Type.Optional(SessionMetaFields.title),
|
|
159
|
-
/** How this session stands: `paused` or `disappeared`, which the
|
|
160
|
-
* `stopped_at` below is what separates. Absent from an instance that states
|
|
161
|
-
* no classification. */
|
|
162
|
-
state: Type.Optional(SessionState),
|
|
163
|
-
/** Set while a person has pinned this session. Absent means not pinned. */
|
|
164
|
-
pinned: Type.Optional(Type.Boolean()),
|
|
165
|
-
connected_at: Type.Optional(Timestamp),
|
|
166
|
-
/** The newest instant this session is known to have been alive. */
|
|
167
|
-
last_seen_at: Timestamp,
|
|
168
|
-
/** When the session said it was stopping. Its presence is what makes this a
|
|
169
|
-
* pause rather than a disappearance: a session that goes without a word
|
|
170
|
-
* leaves nothing to stamp here. */
|
|
171
|
-
stopped_at: Type.Optional(Timestamp),
|
|
172
|
-
/** What its last turn ran as, in the transcript's own spelling. A resume
|
|
173
|
-
* must not quietly switch the session to something else. */
|
|
174
|
-
model: Type.Optional(SessionMetaFields.model),
|
|
175
|
-
effort: Type.Optional(SessionMetaFields.effort),
|
|
171
|
+
removed: Type.Literal(true),
|
|
176
172
|
},
|
|
177
|
-
{ $id: "
|
|
173
|
+
{ $id: "PeerRemoved" },
|
|
178
174
|
);
|
|
179
|
-
export type
|
|
175
|
+
export type PeerRemoved = Static<typeof PeerRemoved>;
|
|
176
|
+
|
|
177
|
+
export const PeerElement = Type.Union([PeerInfo, PeerRemoved], { $id: "PeerElement" });
|
|
178
|
+
export type PeerElement = Static<typeof PeerElement>;
|
|
180
179
|
|
|
181
180
|
/** The `peers` topic.
|
|
182
181
|
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
182
|
+
* Elements: each frame carries the rows that changed, matched by their
|
|
183
|
+
* `instance` and `sid`, and rows it does not name are left as they were. A row
|
|
184
|
+
* changes on its own — one session becoming busy, another going quiet — and
|
|
185
|
+
* restating every row an instance knows would send a list to report one field.
|
|
186
186
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
export const PeersFrame = topicFrame(
|
|
190
|
-
"peers",
|
|
191
|
-
Type.Object({
|
|
192
|
-
peers: Type.Array(PeerInfo),
|
|
193
|
-
last_live: Type.Array(LastLiveSession),
|
|
194
|
-
/** The instances the sending one can see, itself included, as `hello`
|
|
195
|
-
* answers it. Carried here so that a link going down is something a
|
|
196
|
-
* subscriber learns from the topic it is already on, rather than by
|
|
197
|
-
* greeting again to find out. It is the sender's own view like the two
|
|
198
|
-
* lists above — `reachable` says whether that instance can reach the one it
|
|
199
|
-
* names, which two instances may legitimately disagree about.
|
|
200
|
-
*
|
|
201
|
-
* Absent from an instance that states no view; a client then keeps what it
|
|
202
|
-
* last knew rather than reading the omission as nothing being reachable. */
|
|
203
|
-
instances: Type.Optional(Type.Array(InstanceInfo)),
|
|
204
|
-
}),
|
|
205
|
-
);
|
|
187
|
+
* The opening `snapshot: true` frame carries every row the instance holds,
|
|
188
|
+
* connected and lost alike. */
|
|
189
|
+
export const PeersFrame = topicFrame("peers", Type.Object({ peers: Type.Array(PeerElement) }));
|
package/src/fixtures/index.ts
CHANGED
|
@@ -163,6 +163,7 @@ export const TOPIC_FIXTURES = {
|
|
|
163
163
|
inbox: topics.INBOX_FRAME,
|
|
164
164
|
notify: topics.NOTIFY_FRAME,
|
|
165
165
|
peers: topics.PEERS_FRAME,
|
|
166
|
+
instances: topics.INSTANCES_FRAME,
|
|
166
167
|
agents: topics.AGENTS_FRAME,
|
|
167
168
|
session_status: topics.SESSION_STATUS_FRAME,
|
|
168
169
|
transcript: topics.TRANSCRIPT_FRAME,
|
package/src/fixtures/topics.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Static } from "@sinclair/typebox";
|
|
2
2
|
import type { AuthRecordsFrame } from "../common/auth.ts";
|
|
3
3
|
import type { AgentsFrame } from "../control/agents.ts";
|
|
4
|
+
import type { InstancesFrame } from "../control/instances.ts";
|
|
4
5
|
import type { KvFrame } from "../control/kv.ts";
|
|
5
6
|
import type { LlmRequestsFrame, LlmStatusFrame } from "../control/llm.ts";
|
|
6
7
|
import type { PeersFrame } from "../control/peers.ts";
|
|
@@ -94,16 +95,6 @@ export const PEERS_FRAME: Static<typeof PeersFrame> = {
|
|
|
94
95
|
repo: "ccmsg",
|
|
95
96
|
ws: "daemon-v2",
|
|
96
97
|
cwd: "/repos/kawaz/ccmsg/daemon-v2",
|
|
97
|
-
state: "live_unmanaged",
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
last_live: [
|
|
101
|
-
{
|
|
102
|
-
sid: other_sid,
|
|
103
|
-
instance,
|
|
104
|
-
repo: "ccmsg",
|
|
105
|
-
ws: "daemon-v2",
|
|
106
|
-
cwd: "/repos/kawaz/ccmsg/daemon-v2",
|
|
107
98
|
state: "paused",
|
|
108
99
|
last_seen_at: FIXTURE_NOW - 1_200_000,
|
|
109
100
|
stopped_at: FIXTURE_NOW - 1_000_000,
|
|
@@ -111,6 +102,28 @@ export const PEERS_FRAME: Static<typeof PeersFrame> = {
|
|
|
111
102
|
effort: "high",
|
|
112
103
|
},
|
|
113
104
|
],
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** A later frame: one row moved on, and one the instance forgot. */
|
|
109
|
+
export const PEERS_CHANGE_FRAME: Static<typeof PeersFrame> = {
|
|
110
|
+
ev: "topic",
|
|
111
|
+
topic: "peers",
|
|
112
|
+
instance,
|
|
113
|
+
data: {
|
|
114
|
+
peers: [
|
|
115
|
+
{ ...PEER, state: "live", gateway_active_at: FIXTURE_NOW + 1_000 },
|
|
116
|
+
{ sid: "1c2d3e4f-5a6b-4c7d-8e9f-0a1b2c3d4e5f", instance, removed: true },
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const INSTANCES_FRAME: Static<typeof InstancesFrame> = {
|
|
122
|
+
ev: "topic",
|
|
123
|
+
topic: "instances",
|
|
124
|
+
snapshot: true,
|
|
125
|
+
instance,
|
|
126
|
+
data: {
|
|
114
127
|
instances: [
|
|
115
128
|
{ id: instance, endpoint, host: "mba", reachable: true },
|
|
116
129
|
{ id: other_instance, endpoint: other_endpoint, host: "nuc", reachable: false },
|
|
@@ -144,6 +157,14 @@ export const AGENTS_FRAME: Static<typeof AgentsFrame> = {
|
|
|
144
157
|
},
|
|
145
158
|
};
|
|
146
159
|
|
|
160
|
+
/** A later frame: the harness no longer reports one of the rows above. */
|
|
161
|
+
export const AGENTS_CHANGE_FRAME: Static<typeof AgentsFrame> = {
|
|
162
|
+
ev: "topic",
|
|
163
|
+
topic: "agents",
|
|
164
|
+
instance,
|
|
165
|
+
data: { agents: [{ sid: other_sid, instance, removed: true }], polled_at: FIXTURE_NOW + 5_000 },
|
|
166
|
+
};
|
|
167
|
+
|
|
147
168
|
export const SESSION_STATUS_FRAME: Static<typeof SessionStatusFrame> = {
|
|
148
169
|
ev: "topic",
|
|
149
170
|
topic: `session_status:${sid}`,
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./common/topics.ts";
|
|
|
7
7
|
export * from "./control/agents.ts";
|
|
8
8
|
export * from "./control/dump.ts";
|
|
9
9
|
export * from "./control/files.ts";
|
|
10
|
+
export * from "./control/instances.ts";
|
|
10
11
|
export * from "./control/kv.ts";
|
|
11
12
|
export * from "./control/launcher.ts";
|
|
12
13
|
export * from "./control/llm.ts";
|
package/src/schemas.ts
CHANGED
|
@@ -77,6 +77,7 @@ import {
|
|
|
77
77
|
LlmUsageReadRequest,
|
|
78
78
|
LlmUsageReadResponse,
|
|
79
79
|
} from "./control/llm.ts";
|
|
80
|
+
import { InstancesFrame } from "./control/instances.ts";
|
|
80
81
|
import { PeersFrame } from "./control/peers.ts";
|
|
81
82
|
import {
|
|
82
83
|
SandboxGrantRequest,
|
|
@@ -201,6 +202,7 @@ export const TOPIC_SCHEMAS = {
|
|
|
201
202
|
inbox: InboxFrame,
|
|
202
203
|
notify: NotifyFrame,
|
|
203
204
|
peers: PeersFrame,
|
|
205
|
+
instances: InstancesFrame,
|
|
204
206
|
agents: AgentsFrame,
|
|
205
207
|
session_status: SessionStatusFrame,
|
|
206
208
|
transcript: TranscriptFrame,
|