@ccmsg/protocol 0.1.1 → 0.2.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/hello.ts +14 -0
- package/src/control/peers.ts +67 -22
- package/src/index.ts +1 -0
- package/src/messaging/message.ts +12 -0
- package/src/session-meta.ts +33 -0
package/package.json
CHANGED
package/src/common/hello.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Static, Type } from "@sinclair/typebox";
|
|
2
2
|
import { request, response } from "../envelope.ts";
|
|
3
3
|
import { Capability, InstanceId, Role, Sid, Timestamp } from "../identifiers.ts";
|
|
4
|
+
import { SessionMetaFields } from "../session-meta.ts";
|
|
4
5
|
|
|
5
6
|
/** The mesh handshake's opening claim, carried by a `role: "instance"` hello.
|
|
6
7
|
*
|
|
@@ -36,6 +37,19 @@ export const HelloArgs = Type.Object({
|
|
|
36
37
|
mesh: Type.Optional(MeshHello),
|
|
37
38
|
/** The client build, for display in diagnostics. Nothing gates on it. */
|
|
38
39
|
client_version: Type.Optional(Type.String()),
|
|
40
|
+
/** What a `role: "session"` connection says about itself. All optional: a
|
|
41
|
+
* session states what it knows, and the instance derives or leaves unknown
|
|
42
|
+
* what it is not told. The instance repeats these on the `peers` topic, so
|
|
43
|
+
* they are the same fields under the same names there. */
|
|
44
|
+
repo: Type.Optional(SessionMetaFields.repo),
|
|
45
|
+
ws: Type.Optional(SessionMetaFields.ws),
|
|
46
|
+
cwd: Type.Optional(SessionMetaFields.cwd),
|
|
47
|
+
transcript_path: Type.Optional(SessionMetaFields.transcript_path),
|
|
48
|
+
repo_root: Type.Optional(SessionMetaFields.repo_root),
|
|
49
|
+
branch: Type.Optional(SessionMetaFields.branch),
|
|
50
|
+
title: Type.Optional(SessionMetaFields.title),
|
|
51
|
+
model: Type.Optional(SessionMetaFields.model),
|
|
52
|
+
effort: Type.Optional(SessionMetaFields.effort),
|
|
39
53
|
});
|
|
40
54
|
export type HelloArgs = Static<typeof HelloArgs>;
|
|
41
55
|
|
package/src/control/peers.ts
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
import { type Static, Type } from "@sinclair/typebox";
|
|
2
2
|
import { topicFrame } from "../envelope.ts";
|
|
3
3
|
import { InstanceId, Sid, Timestamp } from "../identifiers.ts";
|
|
4
|
+
import { SessionMetaFields } from "../session-meta.ts";
|
|
5
|
+
|
|
6
|
+
/** How a session stands, as the instance holding it derives it.
|
|
7
|
+
*
|
|
8
|
+
* The instance states the classification rather than the raw inputs it read,
|
|
9
|
+
* so every client shows the same session the same way. The first three appear
|
|
10
|
+
* on connected sessions, the last two on sessions the instance has lost; a
|
|
11
|
+
* client that groups its list groups on this field alone.
|
|
12
|
+
*
|
|
13
|
+
* Being pinned is not one of these: a person pins a session, and the mark
|
|
14
|
+
* travels beside the classification rather than replacing it. */
|
|
15
|
+
export const SessionState = Type.Union(
|
|
16
|
+
[
|
|
17
|
+
/** Stopped at something a person has to answer: a dialog it opened, or a
|
|
18
|
+
* turn that ended in an upstream error. */
|
|
19
|
+
Type.Literal("waiting"),
|
|
20
|
+
Type.Literal("live"),
|
|
21
|
+
/** Alive, but reachable through neither a client connection nor a
|
|
22
|
+
* terminal, so nothing here can act on it. */
|
|
23
|
+
Type.Literal("live_unmanaged"),
|
|
24
|
+
/** Gone, having said it was stopping. */
|
|
25
|
+
Type.Literal("paused"),
|
|
26
|
+
/** Gone without saying so. */
|
|
27
|
+
Type.Literal("disappeared"),
|
|
28
|
+
],
|
|
29
|
+
{ $id: "SessionState" },
|
|
30
|
+
);
|
|
31
|
+
export type SessionState = Static<typeof SessionState>;
|
|
32
|
+
|
|
33
|
+
/** How long a session stays in `last_live` after it was last seen. The same
|
|
34
|
+
* window the inbox keeps undelivered messages for: what a person comes back to
|
|
35
|
+
* is one thing — the session and what was said to it — so the two cannot expire
|
|
36
|
+
* at different times. */
|
|
37
|
+
export const LAST_LIVE_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
4
38
|
|
|
5
39
|
/** A client of one session whose greeting was refused.
|
|
6
40
|
*
|
|
@@ -31,17 +65,20 @@ export const PeerInfo = Type.Object(
|
|
|
31
65
|
{
|
|
32
66
|
sid: Sid,
|
|
33
67
|
instance: InstanceId,
|
|
34
|
-
repo:
|
|
35
|
-
ws:
|
|
36
|
-
cwd:
|
|
37
|
-
/** Present when the session announced
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
68
|
+
repo: SessionMetaFields.repo,
|
|
69
|
+
ws: SessionMetaFields.ws,
|
|
70
|
+
cwd: SessionMetaFields.cwd,
|
|
71
|
+
/** Present when the session announced one the instance accepted. */
|
|
72
|
+
transcript_path: Type.Optional(SessionMetaFields.transcript_path),
|
|
73
|
+
repo_root: Type.Optional(SessionMetaFields.repo_root),
|
|
74
|
+
branch: Type.Optional(SessionMetaFields.branch),
|
|
75
|
+
/** How this session stands. One of `waiting`, `live` or `live_unmanaged`:
|
|
76
|
+
* a session in this list is connected, so it is by definition not gone.
|
|
77
|
+
* Absent from an instance that states no classification, and a client then
|
|
78
|
+
* shows the session without grouping it rather than guessing one. */
|
|
79
|
+
state: Type.Optional(SessionState),
|
|
80
|
+
/** Set while a person has pinned this session. Absent means not pinned. */
|
|
81
|
+
pinned: Type.Optional(Type.Boolean()),
|
|
45
82
|
/** When this session first registered with the instance. Stable across its
|
|
46
83
|
* reconnections, and reset when the instance restarts. */
|
|
47
84
|
connected_at: Type.Optional(Timestamp),
|
|
@@ -88,23 +125,31 @@ export const LastLiveSession = Type.Object(
|
|
|
88
125
|
{
|
|
89
126
|
sid: Sid,
|
|
90
127
|
instance: InstanceId,
|
|
91
|
-
repo:
|
|
92
|
-
ws:
|
|
93
|
-
cwd:
|
|
128
|
+
repo: SessionMetaFields.repo,
|
|
129
|
+
ws: SessionMetaFields.ws,
|
|
130
|
+
cwd: SessionMetaFields.cwd,
|
|
94
131
|
/** Also where the model and effort below were read from. */
|
|
95
|
-
transcript_path: Type.Optional(
|
|
96
|
-
repo_root: Type.Optional(
|
|
97
|
-
branch: Type.Optional(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
132
|
+
transcript_path: Type.Optional(SessionMetaFields.transcript_path),
|
|
133
|
+
repo_root: Type.Optional(SessionMetaFields.repo_root),
|
|
134
|
+
branch: Type.Optional(SessionMetaFields.branch),
|
|
135
|
+
title: Type.Optional(SessionMetaFields.title),
|
|
136
|
+
/** How this session stands: `paused` or `disappeared`, which the
|
|
137
|
+
* `stopped_at` below is what separates. Absent from an instance that states
|
|
138
|
+
* no classification. */
|
|
139
|
+
state: Type.Optional(SessionState),
|
|
140
|
+
/** Set while a person has pinned this session. Absent means not pinned. */
|
|
141
|
+
pinned: Type.Optional(Type.Boolean()),
|
|
101
142
|
connected_at: Type.Optional(Timestamp),
|
|
102
143
|
/** The newest instant this session is known to have been alive. */
|
|
103
144
|
last_seen_at: Timestamp,
|
|
145
|
+
/** When the session said it was stopping. Its presence is what makes this a
|
|
146
|
+
* pause rather than a disappearance: a session that goes without a word
|
|
147
|
+
* leaves nothing to stamp here. */
|
|
148
|
+
stopped_at: Type.Optional(Timestamp),
|
|
104
149
|
/** What its last turn ran as, in the transcript's own spelling. A resume
|
|
105
150
|
* must not quietly switch the session to something else. */
|
|
106
|
-
model: Type.Optional(
|
|
107
|
-
effort: Type.Optional(
|
|
151
|
+
model: Type.Optional(SessionMetaFields.model),
|
|
152
|
+
effort: Type.Optional(SessionMetaFields.effort),
|
|
108
153
|
},
|
|
109
154
|
{ $id: "LastLiveSession" },
|
|
110
155
|
);
|
package/src/index.ts
CHANGED
package/src/messaging/message.ts
CHANGED
|
@@ -87,6 +87,18 @@ export const InboxMessage = Type.Object(
|
|
|
87
87
|
);
|
|
88
88
|
export type InboxMessage = Static<typeof InboxMessage>;
|
|
89
89
|
|
|
90
|
+
/** How long an undelivered message is kept for its recipient. The same window
|
|
91
|
+
* a lost session stays listed for: a message outliving the session it was
|
|
92
|
+
* addressed to would be offered to no one, and a session outliving what was
|
|
93
|
+
* said to it would come back to an empty inbox. */
|
|
94
|
+
export const INBOX_RETENTION_MS = 7 * 24 * 60 * 60 * 1000;
|
|
95
|
+
|
|
96
|
+
/** How many undelivered messages one session's inbox holds. Beyond it the
|
|
97
|
+
* oldest is dropped for the newest and the sender is told `inbox_full`. Matched
|
|
98
|
+
* to what the harness itself will hold for a session, so a message the inbox
|
|
99
|
+
* accepts is one the recipient can still be handed. */
|
|
100
|
+
export const INBOX_MAX_PER_SID = 256;
|
|
101
|
+
|
|
90
102
|
/** The `inbox` topic. Its snapshot is whatever is still undelivered for this
|
|
91
103
|
* session; each later frame is one newly arrived message. */
|
|
92
104
|
export const InboxFrame = topicFrame("inbox", Type.Array(InboxMessage));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
|
|
3
|
+
/** The fields that describe where a session lives and what it runs as.
|
|
4
|
+
*
|
|
5
|
+
* Stated once and referenced wherever a session is described: the session names
|
|
6
|
+
* them itself in `hello`, and the instance repeats them on the `peers` topic
|
|
7
|
+
* for connected and last-known sessions alike. Which of them are required
|
|
8
|
+
* differs by place — a greeting may leave any of them unsaid — so each place
|
|
9
|
+
* wraps what it needs in `Type.Optional`, but the name and the type of a field
|
|
10
|
+
* never differ between them. */
|
|
11
|
+
export const SessionMetaFields = {
|
|
12
|
+
/** The repository the session works in, as a display name. */
|
|
13
|
+
repo: Type.String(),
|
|
14
|
+
/** The workspace (worktree) name within that repository. */
|
|
15
|
+
ws: Type.String(),
|
|
16
|
+
/** The session's working directory. */
|
|
17
|
+
cwd: Type.String(),
|
|
18
|
+
/** The transcript file, which is what decides whether the session's
|
|
19
|
+
* transcript can be read at all. */
|
|
20
|
+
transcript_path: Type.String(),
|
|
21
|
+
/** The repository container. File browsing is rooted here rather than at the
|
|
22
|
+
* working directory, so sibling workspaces are reachable. An instance that is
|
|
23
|
+
* not told one derives it from `cwd`. */
|
|
24
|
+
repo_root: Type.String(),
|
|
25
|
+
/** The branch checked out in that workspace. */
|
|
26
|
+
branch: Type.String(),
|
|
27
|
+
/** The session's own title. Absent means not known, never untitled. */
|
|
28
|
+
title: Type.String(),
|
|
29
|
+
/** The model the session runs as, in its own spelling. */
|
|
30
|
+
model: Type.String(),
|
|
31
|
+
/** The reasoning effort the session runs at, in its own spelling. */
|
|
32
|
+
effort: Type.String(),
|
|
33
|
+
};
|