@yefengr/remote-pi 0.7.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 +21 -0
- package/README.md +674 -0
- package/dist/actions/handlers.d.ts +122 -0
- package/dist/actions/handlers.js +160 -0
- package/dist/actions/handlers.js.map +1 -0
- package/dist/actions/registry.d.ts +39 -0
- package/dist/actions/registry.js +58 -0
- package/dist/actions/registry.js.map +1 -0
- package/dist/bin/supervisord.d.ts +2 -0
- package/dist/bin/supervisord.js +86 -0
- package/dist/bin/supervisord.js.map +1 -0
- package/dist/config.d.ts +55 -0
- package/dist/config.js +118 -0
- package/dist/config.js.map +1 -0
- package/dist/daemon/client.d.ts +20 -0
- package/dist/daemon/client.js +131 -0
- package/dist/daemon/client.js.map +1 -0
- package/dist/daemon/control_protocol.d.ts +176 -0
- package/dist/daemon/control_protocol.js +63 -0
- package/dist/daemon/control_protocol.js.map +1 -0
- package/dist/daemon/cron_log.d.ts +45 -0
- package/dist/daemon/cron_log.js +72 -0
- package/dist/daemon/cron_log.js.map +1 -0
- package/dist/daemon/cron_registry.d.ts +80 -0
- package/dist/daemon/cron_registry.js +194 -0
- package/dist/daemon/cron_registry.js.map +1 -0
- package/dist/daemon/id.d.ts +24 -0
- package/dist/daemon/id.js +36 -0
- package/dist/daemon/id.js.map +1 -0
- package/dist/daemon/install.d.ts +170 -0
- package/dist/daemon/install.js +547 -0
- package/dist/daemon/install.js.map +1 -0
- package/dist/daemon/registry.d.ts +63 -0
- package/dist/daemon/registry.js +153 -0
- package/dist/daemon/registry.js.map +1 -0
- package/dist/daemon/rpc_child.d.ts +194 -0
- package/dist/daemon/rpc_child.js +389 -0
- package/dist/daemon/rpc_child.js.map +1 -0
- package/dist/daemon/supervisor.d.ts +93 -0
- package/dist/daemon/supervisor.js +596 -0
- package/dist/daemon/supervisor.js.map +1 -0
- package/dist/extension_ui_bridge.d.ts +26 -0
- package/dist/extension_ui_bridge.js +341 -0
- package/dist/extension_ui_bridge.js.map +1 -0
- package/dist/index.d.ts +214 -0
- package/dist/index.js +5410 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/mesh_result.d.ts +10 -0
- package/dist/mcp/mesh_result.js +42 -0
- package/dist/mcp/mesh_result.js.map +1 -0
- package/dist/mcp/mesh_server.d.ts +16 -0
- package/dist/mcp/mesh_server.js +327 -0
- package/dist/mcp/mesh_server.js.map +1 -0
- package/dist/mesh/canonical.d.ts +30 -0
- package/dist/mesh/canonical.js +61 -0
- package/dist/mesh/canonical.js.map +1 -0
- package/dist/mesh/client.d.ts +18 -0
- package/dist/mesh/client.js +125 -0
- package/dist/mesh/client.js.map +1 -0
- package/dist/mesh/encoding.d.ts +38 -0
- package/dist/mesh/encoding.js +216 -0
- package/dist/mesh/encoding.js.map +1 -0
- package/dist/mesh/self_revoke.d.ts +73 -0
- package/dist/mesh/self_revoke.js +401 -0
- package/dist/mesh/self_revoke.js.map +1 -0
- package/dist/mesh/siblings.d.ts +49 -0
- package/dist/mesh/siblings.js +159 -0
- package/dist/mesh/siblings.js.map +1 -0
- package/dist/mesh/types.d.ts +34 -0
- package/dist/mesh/types.js +11 -0
- package/dist/mesh/types.js.map +1 -0
- package/dist/mesh/verify.d.ts +17 -0
- package/dist/mesh/verify.js +86 -0
- package/dist/mesh/verify.js.map +1 -0
- package/dist/pairing/crypto.d.ts +8 -0
- package/dist/pairing/crypto.js +22 -0
- package/dist/pairing/crypto.js.map +1 -0
- package/dist/pairing/qr.d.ts +59 -0
- package/dist/pairing/qr.js +125 -0
- package/dist/pairing/qr.js.map +1 -0
- package/dist/pairing/storage.d.ts +120 -0
- package/dist/pairing/storage.js +604 -0
- package/dist/pairing/storage.js.map +1 -0
- package/dist/protocol/codec.d.ts +7 -0
- package/dist/protocol/codec.js +49 -0
- package/dist/protocol/codec.js.map +1 -0
- package/dist/protocol/types.d.ts +393 -0
- package/dist/protocol/types.js +2 -0
- package/dist/protocol/types.js.map +1 -0
- package/dist/protocol/v2/codec.d.ts +26 -0
- package/dist/protocol/v2/codec.js +207 -0
- package/dist/protocol/v2/codec.js.map +1 -0
- package/dist/protocol/v2/index.d.ts +3 -0
- package/dist/protocol/v2/index.js +4 -0
- package/dist/protocol/v2/index.js.map +1 -0
- package/dist/protocol/v2/schemas.d.ts +1939 -0
- package/dist/protocol/v2/schemas.js +409 -0
- package/dist/protocol/v2/schemas.js.map +1 -0
- package/dist/protocol/v2/session_state.d.ts +75 -0
- package/dist/protocol/v2/session_state.js +176 -0
- package/dist/protocol/v2/session_state.js.map +1 -0
- package/dist/rooms.d.ts +29 -0
- package/dist/rooms.js +57 -0
- package/dist/rooms.js.map +1 -0
- package/dist/session/bridge.d.ts +37 -0
- package/dist/session/bridge.js +130 -0
- package/dist/session/bridge.js.map +1 -0
- package/dist/session/broker.d.ts +189 -0
- package/dist/session/broker.js +507 -0
- package/dist/session/broker.js.map +1 -0
- package/dist/session/broker_remote.d.ts +74 -0
- package/dist/session/broker_remote.js +583 -0
- package/dist/session/broker_remote.js.map +1 -0
- package/dist/session/cwd_lock.d.ts +33 -0
- package/dist/session/cwd_lock.js +126 -0
- package/dist/session/cwd_lock.js.map +1 -0
- package/dist/session/envelope.d.ts +33 -0
- package/dist/session/envelope.js +117 -0
- package/dist/session/envelope.js.map +1 -0
- package/dist/session/global_config.d.ts +33 -0
- package/dist/session/global_config.js +73 -0
- package/dist/session/global_config.js.map +1 -0
- package/dist/session/ipc.d.ts +27 -0
- package/dist/session/ipc.js +22 -0
- package/dist/session/ipc.js.map +1 -0
- package/dist/session/leader_election.d.ts +32 -0
- package/dist/session/leader_election.js +106 -0
- package/dist/session/leader_election.js.map +1 -0
- package/dist/session/local_config.d.ts +55 -0
- package/dist/session/local_config.js +157 -0
- package/dist/session/local_config.js.map +1 -0
- package/dist/session/mesh_node.d.ts +116 -0
- package/dist/session/mesh_node.js +573 -0
- package/dist/session/mesh_node.js.map +1 -0
- package/dist/session/peer.d.ts +139 -0
- package/dist/session/peer.js +451 -0
- package/dist/session/peer.js.map +1 -0
- package/dist/session/peer_inventory.d.ts +13 -0
- package/dist/session/peer_inventory.js +48 -0
- package/dist/session/peer_inventory.js.map +1 -0
- package/dist/session/peer_limits.d.ts +9 -0
- package/dist/session/peer_limits.js +21 -0
- package/dist/session/peer_limits.js.map +1 -0
- package/dist/session/setup_wizard.d.ts +39 -0
- package/dist/session/setup_wizard.js +63 -0
- package/dist/session/setup_wizard.js.map +1 -0
- package/dist/session/tools.d.ts +24 -0
- package/dist/session/tools.js +252 -0
- package/dist/session/tools.js.map +1 -0
- package/dist/session/wizard.d.ts +13 -0
- package/dist/session/wizard.js +20 -0
- package/dist/session/wizard.js.map +1 -0
- package/dist/timeline/history.d.ts +35 -0
- package/dist/timeline/history.js +381 -0
- package/dist/timeline/history.js.map +1 -0
- package/dist/timeline/runtime.d.ts +76 -0
- package/dist/timeline/runtime.js +428 -0
- package/dist/timeline/runtime.js.map +1 -0
- package/dist/timeline/v2_service.d.ts +54 -0
- package/dist/timeline/v2_service.js +351 -0
- package/dist/timeline/v2_service.js.map +1 -0
- package/dist/transport/peer_channel.d.ts +57 -0
- package/dist/transport/peer_channel.js +170 -0
- package/dist/transport/peer_channel.js.map +1 -0
- package/dist/transport/pi_forward_client.d.ts +29 -0
- package/dist/transport/pi_forward_client.js +62 -0
- package/dist/transport/pi_forward_client.js.map +1 -0
- package/dist/transport/relay_client.d.ts +91 -0
- package/dist/transport/relay_client.js +206 -0
- package/dist/transport/relay_client.js.map +1 -0
- package/dist/ui/footer.d.ts +32 -0
- package/dist/ui/footer.js +34 -0
- package/dist/ui/footer.js.map +1 -0
- package/docs/daemon.md +289 -0
- package/package.json +87 -0
- package/service-templates/launchd.plist.template +35 -0
- package/service-templates/systemd.service.template +19 -0
- package/service-templates/task-launcher.vbs.template +10 -0
- package/service-templates/task-scheduler.xml.template +38 -0
- package/skills/agent-network/SKILL.md +310 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
export class V2SessionState {
|
|
3
|
+
generationValue;
|
|
4
|
+
maxEntries;
|
|
5
|
+
ttlMs;
|
|
6
|
+
clock;
|
|
7
|
+
channels = new Map();
|
|
8
|
+
records = new Map();
|
|
9
|
+
constructor(options) {
|
|
10
|
+
if (!options.generation)
|
|
11
|
+
throw new Error("generation is required");
|
|
12
|
+
this.generationValue = options.generation;
|
|
13
|
+
this.maxEntries = Math.max(1, Math.floor(options.maxEntries ?? 512));
|
|
14
|
+
this.ttlMs = Math.max(1, options.ttlMs ?? 10 * 60 * 1000);
|
|
15
|
+
this.clock = options.clock ?? Date.now;
|
|
16
|
+
}
|
|
17
|
+
get generation() {
|
|
18
|
+
return this.generationValue;
|
|
19
|
+
}
|
|
20
|
+
setGeneration(generation) {
|
|
21
|
+
if (!generation)
|
|
22
|
+
throw new Error("generation is required");
|
|
23
|
+
if (generation === this.generationValue)
|
|
24
|
+
return;
|
|
25
|
+
this.generationValue = generation;
|
|
26
|
+
this.records.clear();
|
|
27
|
+
}
|
|
28
|
+
hello(senderRef, channelId) {
|
|
29
|
+
this.assertId(senderRef, "senderRef");
|
|
30
|
+
this.assertId(channelId, "channelId");
|
|
31
|
+
const state = {
|
|
32
|
+
senderRef,
|
|
33
|
+
channelId,
|
|
34
|
+
ready: true,
|
|
35
|
+
lastSeen: this.clock(),
|
|
36
|
+
};
|
|
37
|
+
this.channels.set(this.channelKey(senderRef, channelId), state);
|
|
38
|
+
return state;
|
|
39
|
+
}
|
|
40
|
+
touch(senderRef, channelId) {
|
|
41
|
+
const current = this.get(senderRef, channelId);
|
|
42
|
+
if (!current)
|
|
43
|
+
return undefined;
|
|
44
|
+
const state = { ...current, lastSeen: this.clock() };
|
|
45
|
+
this.channels.set(this.channelKey(senderRef, channelId), state);
|
|
46
|
+
return state;
|
|
47
|
+
}
|
|
48
|
+
get(senderRef, channelId) {
|
|
49
|
+
return this.channels.get(this.channelKey(senderRef, channelId));
|
|
50
|
+
}
|
|
51
|
+
removeChannel(senderRef, channelId) {
|
|
52
|
+
this.channels.delete(this.channelKey(senderRef, channelId));
|
|
53
|
+
}
|
|
54
|
+
removeOwner(senderRef) {
|
|
55
|
+
for (const [key, channel] of this.channels) {
|
|
56
|
+
if (channel.senderRef === senderRef)
|
|
57
|
+
this.channels.delete(key);
|
|
58
|
+
}
|
|
59
|
+
for (const [key, record] of this.records) {
|
|
60
|
+
if (record.senderRef === senderRef)
|
|
61
|
+
this.records.delete(key);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
begin(request) {
|
|
65
|
+
this.prune();
|
|
66
|
+
this.assertId(request.senderRef, "senderRef");
|
|
67
|
+
this.assertId(request.clientRequestId, "clientRequestId");
|
|
68
|
+
const key = this.recordKey(request.senderRef, request.clientRequestId);
|
|
69
|
+
const fingerprint = fingerprintPayload(request.payload);
|
|
70
|
+
const existing = this.records.get(key);
|
|
71
|
+
if (existing) {
|
|
72
|
+
existing.touchedAt = this.clock();
|
|
73
|
+
this.records.delete(key);
|
|
74
|
+
this.records.set(key, existing);
|
|
75
|
+
return {
|
|
76
|
+
kind: existing.fingerprint === fingerprint ? "replay" : "conflict",
|
|
77
|
+
record: { ...existing },
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const record = {
|
|
81
|
+
key,
|
|
82
|
+
generation: this.generationValue,
|
|
83
|
+
senderRef: request.senderRef,
|
|
84
|
+
clientRequestId: request.clientRequestId,
|
|
85
|
+
fingerprint,
|
|
86
|
+
status: "received",
|
|
87
|
+
touchedAt: this.clock(),
|
|
88
|
+
};
|
|
89
|
+
this.records.set(key, record);
|
|
90
|
+
this.pruneCapacity();
|
|
91
|
+
return { kind: "new", record: { ...record } };
|
|
92
|
+
}
|
|
93
|
+
update(key, status, details = {}) {
|
|
94
|
+
this.prune();
|
|
95
|
+
const record = this.records.get(key);
|
|
96
|
+
if (!record)
|
|
97
|
+
return undefined;
|
|
98
|
+
record.status = status;
|
|
99
|
+
if (details.messageId !== undefined)
|
|
100
|
+
record.messageId = details.messageId;
|
|
101
|
+
if (details.groupId !== undefined)
|
|
102
|
+
record.groupId = details.groupId;
|
|
103
|
+
record.touchedAt = this.clock();
|
|
104
|
+
this.records.delete(key);
|
|
105
|
+
this.records.set(key, record);
|
|
106
|
+
return { ...record };
|
|
107
|
+
}
|
|
108
|
+
rememberUnknownDelivery(key) {
|
|
109
|
+
return this.update(key, "unknown_delivery");
|
|
110
|
+
}
|
|
111
|
+
getRecord(key) {
|
|
112
|
+
this.prune();
|
|
113
|
+
const record = this.records.get(key);
|
|
114
|
+
return record ? { ...record } : undefined;
|
|
115
|
+
}
|
|
116
|
+
forget(key) {
|
|
117
|
+
return this.records.delete(key);
|
|
118
|
+
}
|
|
119
|
+
snapshot() {
|
|
120
|
+
this.prune();
|
|
121
|
+
return {
|
|
122
|
+
channels: [...this.channels.values()].map((channel) => ({ ...channel })),
|
|
123
|
+
records: [...this.records.values()].map((record) => ({ ...record })),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
prune() {
|
|
127
|
+
const now = this.clock();
|
|
128
|
+
for (const [key, record] of this.records) {
|
|
129
|
+
if (now - record.touchedAt >= this.ttlMs)
|
|
130
|
+
this.records.delete(key);
|
|
131
|
+
}
|
|
132
|
+
this.pruneCapacity();
|
|
133
|
+
}
|
|
134
|
+
pruneCapacity() {
|
|
135
|
+
while (this.records.size > this.maxEntries) {
|
|
136
|
+
const oldest = this.records.keys().next().value;
|
|
137
|
+
if (oldest === undefined)
|
|
138
|
+
break;
|
|
139
|
+
this.records.delete(oldest);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
recordKey(senderRef, clientRequestId) {
|
|
143
|
+
return `${this.generationValue}\u0000${senderRef}\u0000${clientRequestId}`;
|
|
144
|
+
}
|
|
145
|
+
channelKey(senderRef, channelId) {
|
|
146
|
+
return `${senderRef}\u0000${channelId}`;
|
|
147
|
+
}
|
|
148
|
+
assertId(value, name) {
|
|
149
|
+
if (!value || value.length > 256)
|
|
150
|
+
throw new Error(`${name} is invalid`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function fingerprintPayload(value) {
|
|
154
|
+
const canonical = canonicalize(value);
|
|
155
|
+
return createHash("sha256").update(JSON.stringify(canonical), "utf8").digest("hex");
|
|
156
|
+
}
|
|
157
|
+
function canonicalize(value) {
|
|
158
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
159
|
+
return value;
|
|
160
|
+
if (typeof value === "number")
|
|
161
|
+
return Number.isFinite(value) ? value : null;
|
|
162
|
+
if (Array.isArray(value))
|
|
163
|
+
return value.map(canonicalize);
|
|
164
|
+
if (typeof value === "object") {
|
|
165
|
+
const result = {};
|
|
166
|
+
for (const key of Object.keys(value).sort()) {
|
|
167
|
+
result[key] = canonicalize(value[key]);
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
return String(value);
|
|
172
|
+
}
|
|
173
|
+
export function fingerprintV2Payload(value) {
|
|
174
|
+
return fingerprintPayload(value);
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=session_state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session_state.js","sourceRoot":"","sources":["../../../src/protocol/v2/session_state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA2CzC,MAAM,OAAO,cAAc;IACjB,eAAe,CAAS;IACf,UAAU,CAAS;IACnB,KAAK,CAAS;IACd,KAAK,CAAQ;IACb,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC7C,OAAO,GAAG,IAAI,GAAG,EAA+B,CAAC;IAElE,YAAY,OAA8B;QACxC,IAAI,CAAC,OAAO,CAAC,UAAU;YAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QACnE,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,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ds produce different ids
|
|
4
|
+
* (with cryptographic-strength collision resistance). Symlinks are resolved
|
|
5
|
+
* via `realpath` so `/a` and `/symlink-to-a` map to the same room.
|
|
6
|
+
*
|
|
7
|
+
* Format: first 12 chars of base64url(sha256(realpath)).
|
|
8
|
+
*/
|
|
9
|
+
export declare function roomIdForCwd(cwd: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* THE single derivation of the App↔Pi `room_id` (plan/41) — keyed by
|
|
12
|
+
* `(cwd, name)` so several agents in the SAME folder get distinct rooms (the
|
|
13
|
+
* app then renders one tile per agent instead of merging them into one).
|
|
14
|
+
*
|
|
15
|
+
* Default-preserving: when `name` is absent OR equals `defaultAgentName(cwd)`
|
|
16
|
+
* (an agent with no custom `agent_name`), it returns the LEGACY `roomIdForCwd`
|
|
17
|
+
* EXACTLY — so a single unnamed agent's existing conversation is NOT re-keyed
|
|
18
|
+
* on upgrade. A custom or `#N`-suffixed name → a name-scoped id (same formula
|
|
19
|
+
* the cwd-lock uses).
|
|
20
|
+
*
|
|
21
|
+
* Using the ASSIGNED leaf name (the broker's `#N` on collision) disambiguates
|
|
22
|
+
* even two unnamed agents: the 1st stays `folder` (== default → legacy room),
|
|
23
|
+
* the 2nd becomes `folder#2` (≠ default → name-scoped room).
|
|
24
|
+
*
|
|
25
|
+
* INVARIANT: every callsite that derives the App↔Pi room for the same agent
|
|
26
|
+
* MUST go through this function — otherwise the app would pair on a room the
|
|
27
|
+
* Pi never announces.
|
|
28
|
+
*/
|
|
29
|
+
export declare function roomIdFor(cwd: string, name?: string): string;
|
package/dist/rooms.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { defaultAgentName } from "./session/local_config.js";
|
|
4
|
+
/**
|
|
5
|
+
* Deterministic room id derived from a cwd. Two Pi processes in the same
|
|
6
|
+
* directory produce the same id; different cwds produce different ids
|
|
7
|
+
* (with cryptographic-strength collision resistance). Symlinks are resolved
|
|
8
|
+
* via `realpath` so `/a` and `/symlink-to-a` map to the same room.
|
|
9
|
+
*
|
|
10
|
+
* Format: first 12 chars of base64url(sha256(realpath)).
|
|
11
|
+
*/
|
|
12
|
+
export function roomIdForCwd(cwd) {
|
|
13
|
+
let target;
|
|
14
|
+
try {
|
|
15
|
+
target = realpathSync(cwd);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// cwd doesn't exist (unlikely in production) — fallback to raw path.
|
|
19
|
+
target = cwd;
|
|
20
|
+
}
|
|
21
|
+
return createHash("sha256").update(target).digest("base64url").slice(0, 12);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* THE single derivation of the App↔Pi `room_id` (plan/41) — keyed by
|
|
25
|
+
* `(cwd, name)` so several agents in the SAME folder get distinct rooms (the
|
|
26
|
+
* app then renders one tile per agent instead of merging them into one).
|
|
27
|
+
*
|
|
28
|
+
* Default-preserving: when `name` is absent OR equals `defaultAgentName(cwd)`
|
|
29
|
+
* (an agent with no custom `agent_name`), it returns the LEGACY `roomIdForCwd`
|
|
30
|
+
* EXACTLY — so a single unnamed agent's existing conversation is NOT re-keyed
|
|
31
|
+
* on upgrade. A custom or `#N`-suffixed name → a name-scoped id (same formula
|
|
32
|
+
* the cwd-lock uses).
|
|
33
|
+
*
|
|
34
|
+
* Using the ASSIGNED leaf name (the broker's `#N` on collision) disambiguates
|
|
35
|
+
* even two unnamed agents: the 1st stays `folder` (== default → legacy room),
|
|
36
|
+
* the 2nd becomes `folder#2` (≠ default → name-scoped room).
|
|
37
|
+
*
|
|
38
|
+
* INVARIANT: every callsite that derives the App↔Pi room for the same agent
|
|
39
|
+
* MUST go through this function — otherwise the app would pair on a room the
|
|
40
|
+
* Pi never announces.
|
|
41
|
+
*/
|
|
42
|
+
export function roomIdFor(cwd, name) {
|
|
43
|
+
if (!name || name === defaultAgentName(cwd))
|
|
44
|
+
return roomIdForCwd(cwd);
|
|
45
|
+
let target;
|
|
46
|
+
try {
|
|
47
|
+
target = realpathSync(cwd);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
target = cwd;
|
|
51
|
+
}
|
|
52
|
+
// NUL separator (U+0000): impossible in a POSIX path and stripped from any
|
|
53
|
+
// sanitized name, so the cwd/name boundary is unambiguous.
|
|
54
|
+
const sep = String.fromCharCode(0);
|
|
55
|
+
return createHash("sha256").update(target + sep + name).digest("base64url").slice(0, 12);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=rooms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rooms.js","sourceRoot":"","sources":["../src/rooms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,qEAAqE;QACrE,MAAM,GAAG,GAAG,CAAC;IACf,CAAC;IACD,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC9E,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,IAAa;IAClD,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,gBAAgB,CAAC,GAAG,CAAC;QAAE,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;IACtE,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,GAAG,GAAG,CAAC;IACf,CAAC;IACD,2EAA2E;IAC3E,2DAA2D;IAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IACnC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3F,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Broker } from "./broker.js";
|
|
2
|
+
import { BrokerRemote } from "./broker_remote.js";
|
|
3
|
+
import { PiForwardClient } from "../transport/pi_forward_client.js";
|
|
4
|
+
import type { RelayClient } from "../transport/relay_client.js";
|
|
5
|
+
import { type MeshTopologySnapshot } from "../mesh/siblings.js";
|
|
6
|
+
import type { Ed25519Keypair } from "../pairing/crypto.js";
|
|
7
|
+
/**
|
|
8
|
+
* Cross-PC mesh bridge composition. Discovery finishes before either transport
|
|
9
|
+
* half is constructed, and the returned bridge stays dormant until its caller
|
|
10
|
+
* has re-checked lifecycle ownership and calls `activate()`.
|
|
11
|
+
*/
|
|
12
|
+
export interface AttachBridgeOptions {
|
|
13
|
+
/** The leader's local Broker (from SessionPeer.localBroker()). */
|
|
14
|
+
broker: Broker;
|
|
15
|
+
/** Live relay connection. Caller owns its lifecycle. */
|
|
16
|
+
relay: RelayClient;
|
|
17
|
+
/** Relay URL in http(s):// form — for standalone topology discovery. */
|
|
18
|
+
relayUrl: string;
|
|
19
|
+
/** This host's Ed25519 identity (machine Pi-key). */
|
|
20
|
+
keypair: Ed25519Keypair;
|
|
21
|
+
/** Retained Pi-produced topology. Supplying it bypasses discovery. */
|
|
22
|
+
topology?: MeshTopologySnapshot;
|
|
23
|
+
/** Standalone discovery deadline per mesh request. Defaults to 5 seconds. */
|
|
24
|
+
meshRequestTimeoutMs?: number;
|
|
25
|
+
/** Diagnostic logger. Defaults to a no-op (avoids TUI leaks). */
|
|
26
|
+
log?: (msg: string) => void;
|
|
27
|
+
}
|
|
28
|
+
export interface CrossPcBridge {
|
|
29
|
+
brokerRemote: BrokerRemote;
|
|
30
|
+
piForward: PiForwardClient;
|
|
31
|
+
topology: MeshTopologySnapshot;
|
|
32
|
+
/** Publish the already-built router exactly once. */
|
|
33
|
+
activate(): void;
|
|
34
|
+
/** Safe before or after activation; tears down both halves exactly once. */
|
|
35
|
+
detach(): void;
|
|
36
|
+
}
|
|
37
|
+
export declare function attachCrossPcBridge(opts: AttachBridgeOptions): Promise<CrossPcBridge>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { BrokerRemote } from "./broker_remote.js";
|
|
2
|
+
import { PiForwardClient } from "../transport/pi_forward_client.js";
|
|
3
|
+
import { MeshClient } from "../mesh/client.js";
|
|
4
|
+
import { buildTopologySnapshot, discoverTopology, } from "../mesh/siblings.js";
|
|
5
|
+
import { canonicalizeEd25519PublicKey, encodeEd25519PublicKey, } from "../mesh/encoding.js";
|
|
6
|
+
import { listOwnerPubkeys } from "../pairing/storage.js";
|
|
7
|
+
function compareAscii(left, right) {
|
|
8
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
9
|
+
}
|
|
10
|
+
function validateAlias(alias, field) {
|
|
11
|
+
if (typeof alias !== "string" || alias.length === 0 || alias.includes(":")) {
|
|
12
|
+
throw new Error(`mesh: ${field} is not a valid routing alias`);
|
|
13
|
+
}
|
|
14
|
+
return alias;
|
|
15
|
+
}
|
|
16
|
+
function validateLegacyPcLabel(label, field) {
|
|
17
|
+
if (typeof label !== "string" || label.length === 0) {
|
|
18
|
+
throw new Error(`mesh: ${field} is not a valid legacy PC label`);
|
|
19
|
+
}
|
|
20
|
+
return label;
|
|
21
|
+
}
|
|
22
|
+
function ownTopology(snapshot, expectedSelfPubkey) {
|
|
23
|
+
const selfPubkey = canonicalizeEd25519PublicKey(snapshot.self?.pcPubkey, "self public key");
|
|
24
|
+
if (selfPubkey !== expectedSelfPubkey) {
|
|
25
|
+
throw new Error("mesh: topology self public key does not match relay identity");
|
|
26
|
+
}
|
|
27
|
+
const selfLabel = validateAlias(snapshot.self.pcLabel, "self.pcLabel");
|
|
28
|
+
const selfLegacyPcLabel = validateLegacyPcLabel(snapshot.self.legacyPcLabel, "self.legacyPcLabel");
|
|
29
|
+
const self = Object.freeze({
|
|
30
|
+
pcLabel: selfLabel,
|
|
31
|
+
pcPubkey: selfPubkey,
|
|
32
|
+
legacyPcLabel: selfLegacyPcLabel,
|
|
33
|
+
});
|
|
34
|
+
const siblingKeys = new Set();
|
|
35
|
+
const siblingAliases = new Set();
|
|
36
|
+
const normalizedSiblings = [];
|
|
37
|
+
for (const [index, sibling] of snapshot.siblings.entries()) {
|
|
38
|
+
const pcPubkey = canonicalizeEd25519PublicKey(sibling.pcPubkey, `siblings[${index}].pcPubkey`);
|
|
39
|
+
if (pcPubkey === selfPubkey)
|
|
40
|
+
continue;
|
|
41
|
+
const pcLabel = validateAlias(sibling.pcLabel, `siblings[${index}].pcLabel`);
|
|
42
|
+
const legacyPcLabel = validateLegacyPcLabel(sibling.legacyPcLabel, `siblings[${index}].legacyPcLabel`);
|
|
43
|
+
if (pcLabel === selfLabel || siblingAliases.has(pcLabel)) {
|
|
44
|
+
throw new Error("mesh: duplicate sibling routing alias");
|
|
45
|
+
}
|
|
46
|
+
if (siblingKeys.has(pcPubkey)) {
|
|
47
|
+
throw new Error("mesh: duplicate sibling public key");
|
|
48
|
+
}
|
|
49
|
+
siblingAliases.add(pcLabel);
|
|
50
|
+
siblingKeys.add(pcPubkey);
|
|
51
|
+
normalizedSiblings.push(Object.freeze({ pcLabel, pcPubkey, legacyPcLabel }));
|
|
52
|
+
}
|
|
53
|
+
normalizedSiblings.sort((left, right) => compareAscii(left.pcPubkey, right.pcPubkey));
|
|
54
|
+
return Object.freeze({ self, siblings: Object.freeze(normalizedSiblings) });
|
|
55
|
+
}
|
|
56
|
+
async function discoverStandaloneTopology(opts) {
|
|
57
|
+
const silent = { warn: (_message) => { } };
|
|
58
|
+
try {
|
|
59
|
+
const owners = await listOwnerPubkeys();
|
|
60
|
+
return await discoverTopology({
|
|
61
|
+
client: new MeshClient(opts.relayUrl, {
|
|
62
|
+
...(opts.meshRequestTimeoutMs !== undefined
|
|
63
|
+
? { requestTimeoutMs: opts.meshRequestTimeoutMs }
|
|
64
|
+
: {}),
|
|
65
|
+
}),
|
|
66
|
+
ownerEpks: owners,
|
|
67
|
+
myPubkey: opts.keypair.publicKey,
|
|
68
|
+
log: silent,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return buildTopologySnapshot(opts.keypair.publicKey, []);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export async function attachCrossPcBridge(opts) {
|
|
76
|
+
const expectedSelfPubkey = encodeEd25519PublicKey(opts.keypair.publicKey, "relay public key");
|
|
77
|
+
const topology = ownTopology(opts.topology ?? await discoverStandaloneTopology(opts), expectedSelfPubkey);
|
|
78
|
+
// No Relay listeners exist until all standalone discovery has completed.
|
|
79
|
+
const piForward = new PiForwardClient(opts.relay);
|
|
80
|
+
let brokerRemote;
|
|
81
|
+
try {
|
|
82
|
+
brokerRemote = new BrokerRemote({
|
|
83
|
+
broker: opts.broker,
|
|
84
|
+
pi: piForward,
|
|
85
|
+
topology,
|
|
86
|
+
activateOnConstruct: false,
|
|
87
|
+
log: opts.log ?? (() => { }),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
piForward.detach();
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
let state = "dormant";
|
|
95
|
+
return {
|
|
96
|
+
brokerRemote,
|
|
97
|
+
piForward,
|
|
98
|
+
topology,
|
|
99
|
+
activate() {
|
|
100
|
+
if (state !== "dormant")
|
|
101
|
+
return;
|
|
102
|
+
try {
|
|
103
|
+
brokerRemote.activate();
|
|
104
|
+
state = "active";
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
state = "detached";
|
|
108
|
+
try {
|
|
109
|
+
brokerRemote.detach();
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
piForward.detach();
|
|
113
|
+
}
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
detach() {
|
|
118
|
+
if (state === "detached")
|
|
119
|
+
return;
|
|
120
|
+
state = "detached";
|
|
121
|
+
try {
|
|
122
|
+
brokerRemote.detach();
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
piForward.detach();
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/session/bridge.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GAEjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAoCzD,SAAS,YAAY,CAAC,IAAY,EAAE,KAAa;IAC/C,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,aAAa,CAAC,KAAc,EAAE,KAAa;IAClD,IAAI,OAAO,KAAK,KAAK,QAA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;SAClC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,SAAS,CAAC,MAAM,EAAE,CAAC;QACnB,MAAM,KAAK,CAAC;IACd,CAAC;IAED,IAAI,KAAK,GAAsC,SAAS,CAAC;IACzD,OAAO;QACL,YAAY;QACZ,SAAS;QACT,QAAQ;QACR,QAAQ;YACN,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO;YAChC,IAAI,CAAC;gBACH,YAAY,CAAC,QAAQ,EAAE,CAAC;gBACxB,KAAK,GAAG,QAAQ,CAAC;YACnB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,KAAK,GAAG,UAAU,CAAC;gBACnB,IAAI,CAAC;oBACH,YAAY,CAAC,MAAM,EAAE,CAAC;gBACxB,CAAC;wBAAS,CAAC;oBACT,SAAS,CAAC,MAAM,EAAE,CAAC;gBACrB,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QACD,MAAM;YACJ,IAAI,KAAK,KAAK,UAAU;gBAAE,OAAO;YACjC,KAAK,GAAG,UAAU,CAAC;YACnB,IAAI,CAAC;gBACH,YAAY,CAAC,MAAM,EAAE,CAAC;YACxB,CAAC;oBAAS,CAAC;gBACT,SAAS,CAAC,MAAM,EAAE,CAAC;YACrB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { Server } from "node:net";
|
|
2
|
+
import { type Envelope } from "./envelope.js";
|
|
3
|
+
/**
|
|
4
|
+
* Structured view of one mesh peer (plan/38). The `address` is the canonical
|
|
5
|
+
* routing key; the other fields let a client group/label peers WITHOUT parsing
|
|
6
|
+
* the address string. `pc` is undefined for local peers (filled cross-PC in
|
|
7
|
+
* Fase 2). Returned by `list_peers` as `peers_detailed`.
|
|
8
|
+
*/
|
|
9
|
+
export interface PeerInfo {
|
|
10
|
+
/** Cross-PC label; undefined for a local peer. */
|
|
11
|
+
pc?: string;
|
|
12
|
+
/** Working directory (realpath). Empty string for a legacy peer (no cwd). */
|
|
13
|
+
cwd: string;
|
|
14
|
+
/** Clean leaf name (carries a `#N` only on a same-(cwd,name) collision). */
|
|
15
|
+
name: string;
|
|
16
|
+
/** Canonical address — the broker's Map key and the `to`/`from` on the wire. */
|
|
17
|
+
address: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* THE sole encoder of a peer address (plan/38): `[<pc>:]<cwd>@<nome>`.
|
|
21
|
+
*
|
|
22
|
+
* - `cwd` present → `<cwd>@<nome>` (the `@` separates name from path so a `/`
|
|
23
|
+
* in the path never confuses lookup, which is exact-match anyway).
|
|
24
|
+
* - `cwd` empty (legacy peer that sent no cwd) → `address == name`, preserving
|
|
25
|
+
* pre-plan/38 behavior so a mixed mesh keeps routing.
|
|
26
|
+
* - `pc` present (cross-PC, Fase 2) → prefixed `<pc>:`.
|
|
27
|
+
*
|
|
28
|
+
* Does NOT sanitize — callers sanitize the `name` once (see `sanitizeMeshName`)
|
|
29
|
+
* before composing, so an already-appended `#N` collision suffix survives.
|
|
30
|
+
* Everyone else ECHOES `peer.address` verbatim; only the broker composes.
|
|
31
|
+
*/
|
|
32
|
+
export declare function composeAddress(parts: {
|
|
33
|
+
pc?: string;
|
|
34
|
+
cwd: string;
|
|
35
|
+
name: string;
|
|
36
|
+
}): string;
|
|
37
|
+
/**
|
|
38
|
+
* Sanitize a requested mesh name to a safe leaf while PRESERVING a trailing
|
|
39
|
+
* `#N` collision suffix (which the cwd-lock or a prior assignment may have
|
|
40
|
+
* added — `sanitizeSegment` alone would mangle `#`→`-`). The base is run through
|
|
41
|
+
* `sanitizeSegment` (af66d04); an unusable base (empty / reserved keyword) falls
|
|
42
|
+
* back to `"agent"`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function sanitizeMeshName(raw: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Broker hosted by the session leader. Accepts UDS connections, maintains a
|
|
47
|
+
* `name → connection` map, routes envelopes per the `to` field, and appends
|
|
48
|
+
* each routed message to an `audit.jsonl` log.
|
|
49
|
+
*
|
|
50
|
+
* Auto-suffix on name collision: when a peer registers a name already taken,
|
|
51
|
+
* the broker assigns `<name>#N` and returns it in the register ack.
|
|
52
|
+
*
|
|
53
|
+
* ## ACK protocol (plan/25 Wave 0; reliable delivery per plan/34)
|
|
54
|
+
*
|
|
55
|
+
* For **unicast non-broker** envelopes the broker synchronously emits an ACK
|
|
56
|
+
* envelope back to the sender once it has delivered:
|
|
57
|
+
*
|
|
58
|
+
* - target online → deliver envelope, ACK `received`
|
|
59
|
+
* - no such peer → silent drop (sender times out)
|
|
60
|
+
*
|
|
61
|
+
* plan/34 removed the busy-drop: a message that arrives while the target is
|
|
62
|
+
* mid-turn is **always delivered**, never dropped. The Pi harness
|
|
63
|
+
* (`sendMessage(triggerTurn:true)`) enqueues mid-turn messages and processes
|
|
64
|
+
* them in the upcoming turn, so the broker needs no busy gate or mailbox.
|
|
65
|
+
* Consequently `busy` is no longer a possible ACK status for unicast new
|
|
66
|
+
* work — the sender always gets `received`. (Turn-lifecycle / working
|
|
67
|
+
* indicators live in `index.ts` via room_meta over the relay, not here.)
|
|
68
|
+
*
|
|
69
|
+
* Broadcast/multicast/broker-addressed envelopes are not ACKed (no single
|
|
70
|
+
* authoritative recipient or no semantic match). The audit log carries the
|
|
71
|
+
* ACK status (`received | denied | none`) per envelope.
|
|
72
|
+
*/
|
|
73
|
+
export interface BrokerOptions {
|
|
74
|
+
server: Server;
|
|
75
|
+
auditPath?: string;
|
|
76
|
+
/** Optional callback invoked after each successful route (testing/observability). */
|
|
77
|
+
onRouted?: (env: Envelope, deliveredTo: string[]) => void;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Hook the broker calls before doing local routing, so cross-PC prefixes
|
|
81
|
+
* (`<pc_label>:<peer_name>`) can be handed off to a remote forwarder
|
|
82
|
+
* without baking transport knowledge into the broker. Wave C (plan/25)
|
|
83
|
+
* wires `broker_remote.ts` here.
|
|
84
|
+
*/
|
|
85
|
+
export interface RemoteRouter {
|
|
86
|
+
/**
|
|
87
|
+
* Try to claim responsibility for routing this envelope cross-PC.
|
|
88
|
+
* Returns true if claimed (broker MUST NOT also deliver locally). Returns
|
|
89
|
+
* false if the envelope should fall through to local routing — e.g., the
|
|
90
|
+
* prefix matches the local `pc_label`, the prefix is not a known remote
|
|
91
|
+
* label (backward-compat for local names containing `:`), or there's no
|
|
92
|
+
* prefix at all.
|
|
93
|
+
*/
|
|
94
|
+
tryRouteOutbound(env: Envelope): boolean;
|
|
95
|
+
/** Aggregated remote peer addresses (`<pc_label>:<cwd>@<nome>`) for the
|
|
96
|
+
* `list_peers` reply's `peers` (string) field. Empty when nothing known. */
|
|
97
|
+
listRemotePeers(): string[];
|
|
98
|
+
/** Structured remote roster (plan/38 Fase 2): one `PeerInfo` per cross-PC
|
|
99
|
+
* peer with `pc` filled (the sibling label), `cwd`/`name` from the sibling's
|
|
100
|
+
* inventory, and `address` prefixed `<pc>:<cwd>@<nome>`. Powers the
|
|
101
|
+
* `peers_detailed` half of `list_peers` so clients group by `pc`/`cwd`
|
|
102
|
+
* without parsing. Empty when nothing known. */
|
|
103
|
+
listRemotePeerInfos(): PeerInfo[];
|
|
104
|
+
}
|
|
105
|
+
export interface ConditionalRemoteRouterHost {
|
|
106
|
+
clearRemoteRouter(expected: RemoteRouter): void;
|
|
107
|
+
}
|
|
108
|
+
/** Local outcome of a cross-PC envelope injection. broker_remote uses this
|
|
109
|
+
* to construct the ACK envelope it sends back via the relay. plan/34: `busy`
|
|
110
|
+
* is gone — injection always delivers when the peer exists. */
|
|
111
|
+
export type RemoteInjectStatus = "received" | "denied";
|
|
112
|
+
export declare class Broker {
|
|
113
|
+
private readonly peers;
|
|
114
|
+
private readonly auditPath?;
|
|
115
|
+
private readonly onRouted?;
|
|
116
|
+
private readonly server;
|
|
117
|
+
/** Plan/25 Wave C: optional handoff for cross-PC routing. Null = local only. */
|
|
118
|
+
private remoteRouter;
|
|
119
|
+
constructor(opts: BrokerOptions);
|
|
120
|
+
/** Attach (or detach with null) a cross-PC router. Idempotent. */
|
|
121
|
+
setRemoteRouter(router: RemoteRouter | null): void;
|
|
122
|
+
/** Clear only when the caller still owns the active router slot. */
|
|
123
|
+
clearRemoteRouter(expected: RemoteRouter): void;
|
|
124
|
+
/**
|
|
125
|
+
* Plan/25 Wave C entry point: deliver an envelope that arrived from a
|
|
126
|
+
* remote PC (via relay forward) into the local UDS mesh. Skips the
|
|
127
|
+
* `force from = conn.name` rule (that defense is anti-spoof for local
|
|
128
|
+
* peers; cross-PC has its own defense via the relay's verified `from_pc`).
|
|
129
|
+
*
|
|
130
|
+
* Returns the ACK status so the caller (broker_remote) can pack and
|
|
131
|
+
* forward an ACK envelope back across the relay:
|
|
132
|
+
* - `received` — target exists, envelope delivered (plan/34: always
|
|
133
|
+
* delivered when the peer is online — the Pi harness enqueues mid-turn
|
|
134
|
+
* messages, so there is no busy-drop)
|
|
135
|
+
* - `denied` — no such local peer (or write failed) — caller maps to
|
|
136
|
+
* transport_error or denied ACK as it sees fit
|
|
137
|
+
*/
|
|
138
|
+
injectFromRemote(env: Envelope): RemoteInjectStatus;
|
|
139
|
+
/** Peers currently registered. Snapshot, safe to read. */
|
|
140
|
+
peerNames(): string[];
|
|
141
|
+
close(): Promise<void>;
|
|
142
|
+
private _handleConnection;
|
|
143
|
+
private _onData;
|
|
144
|
+
private _handleLine;
|
|
145
|
+
private _handleRegister;
|
|
146
|
+
/**
|
|
147
|
+
* Answer a read-only `list_peers` request from an UNREGISTERED connection
|
|
148
|
+
* (the `remote-pi peers` CLI probe). Returns true when the line was such a
|
|
149
|
+
* probe — the reply is written and the connection stays unregistered: no
|
|
150
|
+
* name assigned, no `peer_joined`/`peer_left` broadcast, no sibling push, so
|
|
151
|
+
* querying the roster from the shell never perturbs the mesh. Returns false
|
|
152
|
+
* (not a probe) so the caller falls through to the register handshake.
|
|
153
|
+
*/
|
|
154
|
+
private _tryObserverProbe;
|
|
155
|
+
/** Local UDS peer names plus cross-PC `<pc>:<peer>` entries from the remote
|
|
156
|
+
* router (empty when no bridge). Shared by the registered `list_peers`
|
|
157
|
+
* handler and the unregistered observer probe. */
|
|
158
|
+
private _allPeerNames;
|
|
159
|
+
/** Structured roster of LOCAL UDS peers (plan/38): one `PeerInfo` each, no
|
|
160
|
+
* `pc` (they're on this machine). Public so the cross-PC router
|
|
161
|
+
* (`broker_remote`) can read the authoritative local inventory directly to
|
|
162
|
+
* push to siblings — no `list_peers` round-trip, no stale cache. */
|
|
163
|
+
localPeerInfos(): PeerInfo[];
|
|
164
|
+
/** Structured roster (plan/38): local peers (no `pc`) + cross-PC peers with
|
|
165
|
+
* `pc`/`cwd`/`name` filled by the remote router (Fase 2). */
|
|
166
|
+
private _allPeerInfos;
|
|
167
|
+
/**
|
|
168
|
+
* Resolve a free `(name, address)` for a register, keyed by **(cwd, name)**
|
|
169
|
+
* (plan/38): the collision check is on the composed ADDRESS, so a name only
|
|
170
|
+
* collides with another peer in the SAME cwd. `#N` is appended to the name
|
|
171
|
+
* (matching the cwd-lock's suffix scheme) until the address is free; for a
|
|
172
|
+
* legacy peer (cwd "") the address is the name, preserving global-name `#N`.
|
|
173
|
+
*/
|
|
174
|
+
private _identityForRegister;
|
|
175
|
+
private _dropPeerAt;
|
|
176
|
+
private _onClose;
|
|
177
|
+
private _route;
|
|
178
|
+
private _resolveTargets;
|
|
179
|
+
/**
|
|
180
|
+
* Writes an ACK envelope to the original sender's socket. Synchronous —
|
|
181
|
+
* the caller is inside `_route` and must keep busy-check/busy-set atomic.
|
|
182
|
+
* Broker → sender: `from="broker"`, `to=env.from`, `re=env.id`,
|
|
183
|
+
* `body={type:"ack", status, target}`.
|
|
184
|
+
*/
|
|
185
|
+
private _sendAckToSender;
|
|
186
|
+
private _handleBrokerMessage;
|
|
187
|
+
private _broadcastSystem;
|
|
188
|
+
private _appendAudit;
|
|
189
|
+
}
|