@agimon-ai/po-session 0.0.0-alpha.21 → 0.0.0-alpha.210
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 -149
- package/README.md +47 -1
- package/dist/apiContracts.cjs +34 -2
- package/dist/apiContracts.cjs.map +1 -1
- package/dist/apiContracts.d.mts +2 -2
- package/dist/apiContracts.d.mts.map +1 -1
- package/dist/apiContracts.mjs +35 -2
- package/dist/apiContracts.mjs.map +1 -1
- package/dist/extensions/native.mjs +410 -0
- package/dist/extensions/native.mjs.map +1 -0
- package/dist/extensions/server.cjs +1661 -113
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.d.mts.map +1 -1
- package/dist/extensions/server.mjs +1657 -109
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/extensions/web.mjs +361 -0
- package/dist/extensions/web.mjs.map +1 -0
- package/dist/index.cjs +410 -25
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +599 -82
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +358 -1
- package/dist/index.mjs.map +1 -0
- package/dist/po-runtime-identity.json +1 -0
- package/dist/type-BlbiS10p.mjs +2622 -0
- package/dist/type-BlbiS10p.mjs.map +1 -0
- package/dist/type-DZtqhE4a.cjs +3083 -0
- package/dist/type-DZtqhE4a.cjs.map +1 -0
- package/llms.txt +4 -1
- package/locales/vi.json +29 -0
- package/locales/zh-CN.json +29 -0
- package/package.json +96 -11
- package/src/prompts/codemode-how-to-network/SKILL.md +49 -0
- package/src/prompts/codemode-how-to-session/SKILL.md +25 -0
- package/dist/sessionDelivery-4svjzWUW.mjs +0 -1028
- package/dist/sessionDelivery-4svjzWUW.mjs.map +0 -1
- package/dist/sessionDelivery-CGWuQyLV.cjs +0 -1219
- package/dist/sessionDelivery-CGWuQyLV.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,26 +1,411 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
2
|
+
const require_type = require("./type-DZtqhE4a.cjs");
|
|
3
|
+
let _agimon_ai_po_core_hubChannel = require("@agimon-ai/po-core/hubChannel");
|
|
4
|
+
let _agimon_ai_po_web_security_nodeSealedChannel = require("@agimon-ai/po-web-security/nodeSealedChannel");
|
|
5
|
+
let _agimon_ai_po_web_security_deviceProof = require("@agimon-ai/po-web-security/deviceProof");
|
|
6
|
+
//#region src/services/sessionCoordination/policy.ts
|
|
7
|
+
/** ponytail: a fixed per-coordinator budget; add configuration only when another number is needed. */
|
|
8
|
+
const COORDINATOR_STARTS_PER_HOUR = 5;
|
|
9
|
+
const COORDINATOR_START_WINDOW_MS = 36e5;
|
|
10
|
+
function assertCoordinatorStartBudget(count) {
|
|
11
|
+
if (count >= 5) throw new Error(`A coordinator can start at most 5 sessions an hour.`);
|
|
12
|
+
}
|
|
13
|
+
function assertCoordinatorStartScope(callerWorkspaceId, homeWorkspaceId, workspace, hasCoordinator) {
|
|
14
|
+
if (workspace === void 0 || workspace.available === false || workspace.sandbox !== void 0) throw new Error("The target workspace is unavailable.");
|
|
15
|
+
if (workspace.id === callerWorkspaceId) return;
|
|
16
|
+
if (callerWorkspaceId === void 0 || callerWorkspaceId !== homeWorkspaceId || workspace.kind === "session") throw new Error("Only the home coordinator can target another workspace.");
|
|
17
|
+
if (hasCoordinator) throw new Error("This workspace has a coordinator. Ask it to start the session.");
|
|
18
|
+
}
|
|
19
|
+
const coordinates = (session) => session.sessionProvenance === _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE;
|
|
20
|
+
const remote = (session) => session.sessionProvenance === _agimon_ai_po_core_hubChannel.REMOTE_CONVERSATION_SESSION_PROVENANCE;
|
|
21
|
+
/** The coordinator of the internal Home workspace. */
|
|
22
|
+
const home = (input, session) => coordinates(session) && session.workspaceId !== void 0 && input.workspaces.some((workspace) => workspace.id === session.workspaceId && workspace.kind === "session");
|
|
23
|
+
/** Home stands in for a workspace that has no live or dormant coordinator of its own. */
|
|
24
|
+
const homeFallback = (input, coordinator, peer) => {
|
|
25
|
+
if (!home(input, coordinator) || peer.workspaceId === void 0) return false;
|
|
26
|
+
const workspace = input.workspaces.find((entry) => entry.id === peer.workspaceId);
|
|
27
|
+
if (!workspace || workspace.kind === "session" || workspace.sandbox !== void 0 || workspace.available === false) return false;
|
|
28
|
+
return !input.sessions.some((session) => session.workspaceId === workspace.id && coordinates(session)) && !input.dormantSessions.some((record) => record.workspaceId === workspace.id && record.sessionProvenance === _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE && !input.sessions.some((session) => session.id === record.sessionId));
|
|
29
|
+
};
|
|
30
|
+
/** Communication is symmetric. A message grant never grants lifecycle authority. */
|
|
31
|
+
const canSessionsCommunicate = (input) => {
|
|
32
|
+
const { source, target } = input;
|
|
33
|
+
if (source.id === target.id) return false;
|
|
34
|
+
if (source.parentSessionId === target.id || target.parentSessionId === source.id) return true;
|
|
35
|
+
if (remote(source) || remote(target)) return false;
|
|
36
|
+
if (input.mentioned === true) return true;
|
|
37
|
+
if (input.launched === true) return true;
|
|
38
|
+
if ((coordinates(source) || coordinates(target)) && source.workspaceId !== void 0 && source.workspaceId === target.workspaceId) return true;
|
|
39
|
+
if (coordinates(source) && coordinates(target) && (home(input, source) || home(input, target))) return true;
|
|
40
|
+
if (homeFallback(input, source, target) || homeFallback(input, target, source)) return true;
|
|
41
|
+
if (source.workspaceId !== void 0 && source.workspaceId === target.workspaceId && input.filesOverlap) return true;
|
|
42
|
+
return (source.groups ?? []).some((group) => target.groups?.includes(group) === true);
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The hierarchy only, never a group, a mention, shared files or a parent link: `target` coordinates
|
|
46
|
+
* `source` when it is the coordinator of `source`'s workspace, Home standing in for a workspace
|
|
47
|
+
* without one, or Home over a workspace coordinator.
|
|
48
|
+
*/
|
|
49
|
+
const sessionCoordinates = (input) => {
|
|
50
|
+
const { source, target } = input;
|
|
51
|
+
if (source.id === target.id || !coordinates(target) || remote(source) || remote(target)) return false;
|
|
52
|
+
if (coordinates(source)) return home(input, target) && !home(input, source);
|
|
53
|
+
if (source.workspaceId !== void 0 && source.workspaceId === target.workspaceId) return true;
|
|
54
|
+
return homeFallback(input, target, source);
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/services/sessionCoordination/index.ts
|
|
58
|
+
const FALLBACK_SLUG = "workspace";
|
|
59
|
+
/** Kebab-case from the workspace name, else its folder name. */
|
|
60
|
+
function workspaceSlug(workspace) {
|
|
61
|
+
return (workspace.name?.trim() || workspace.root.split(/[\\/]/u).filter(Boolean).pop() || "").toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-+|-+$/gu, "") || FALLBACK_SLUG;
|
|
62
|
+
}
|
|
63
|
+
function createCoordinatorService(options) {
|
|
64
|
+
const opening = /* @__PURE__ */ new Map();
|
|
65
|
+
const starts = /* @__PURE__ */ new Map();
|
|
66
|
+
const now = () => options.now?.() ?? Date.now();
|
|
67
|
+
const homeWorkspace = () => options.workspaces().find((workspace) => workspace.kind === "session");
|
|
68
|
+
/** Live sessions first, so a live coordinator's record is never mistaken for a dormant one. Oldest wins. */
|
|
69
|
+
const coordinatorsIn = (workspaceId) => {
|
|
70
|
+
const liveSessions = options.liveSessions();
|
|
71
|
+
const live = liveSessions.filter((session) => session.sessionProvenance === _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE && session.workspaceId === workspaceId).map((session) => ({
|
|
72
|
+
sessionId: session.id,
|
|
73
|
+
createdAt: session.createdAt,
|
|
74
|
+
live: true
|
|
75
|
+
}));
|
|
76
|
+
const dormant = options.records().filter((record) => record.sessionProvenance === _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE && record.workspaceId === workspaceId && !liveSessions.some((session) => session.id === record.sessionId)).map((record) => ({
|
|
77
|
+
sessionId: record.sessionId,
|
|
78
|
+
createdAt: record.createdAt,
|
|
79
|
+
live: false
|
|
80
|
+
}));
|
|
81
|
+
return [...live, ...dormant].sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
82
|
+
};
|
|
83
|
+
const oldestCoordinator = (workspaceId) => {
|
|
84
|
+
const found = coordinatorsIn(workspaceId);
|
|
85
|
+
if (found.length > 1) options.notice(`Workspace '${workspaceId}' has ${found.length} coordinators; using the oldest, '${found[0]?.sessionId}'.`);
|
|
86
|
+
return found[0];
|
|
87
|
+
};
|
|
88
|
+
const open = async (target, settings) => {
|
|
89
|
+
const workspace = target === "home" ? homeWorkspace() : options.workspaces().find((entry) => entry.id === target);
|
|
90
|
+
if (target !== "home") {
|
|
91
|
+
if (workspace === void 0) throw new Error(`Workspace '${target}' not found.`);
|
|
92
|
+
if (workspace.kind === "session") throw new Error("The home workspace takes the home coordinator.");
|
|
93
|
+
if (!coordinated(workspace)) throw new Error("This workspace cannot have a coordinator.");
|
|
94
|
+
}
|
|
95
|
+
if (workspace?.sandbox !== void 0) throw new Error("This workspace cannot have a coordinator.");
|
|
96
|
+
const existing = workspace === void 0 ? void 0 : oldestCoordinator(workspace.id);
|
|
97
|
+
if (existing !== void 0) {
|
|
98
|
+
if (!existing.live) {
|
|
99
|
+
const record = options.records().find((entry) => entry.sessionId === existing.sessionId);
|
|
100
|
+
if (record === void 0) throw new Error("The coordinator record disappeared while reviving it.");
|
|
101
|
+
await options.revive(record);
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
sessionId: existing.sessionId,
|
|
105
|
+
created: false
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const request = {
|
|
109
|
+
name: settings.name,
|
|
110
|
+
sessionProvenance: _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE,
|
|
111
|
+
selection: { profile: settings.profile },
|
|
112
|
+
...settings.model === void 0 ? {} : { model: settings.model }
|
|
113
|
+
};
|
|
114
|
+
const { sessionId } = workspace === void 0 || target === "home" ? await options.createGeneral(request) : await options.createInWorkspace(workspace, request);
|
|
115
|
+
const record = options.records().find((entry) => entry.sessionId === sessionId);
|
|
116
|
+
const coordinator = {
|
|
117
|
+
profile: settings.profile,
|
|
118
|
+
name: settings.name,
|
|
119
|
+
...settings.model === void 0 ? {} : { model: settings.model }
|
|
120
|
+
};
|
|
121
|
+
if (record === void 0 || !options.saveRecord({
|
|
122
|
+
...record,
|
|
123
|
+
coordinator
|
|
124
|
+
})) options.notice(`Coordinator '${sessionId}' persona could not be recorded.`);
|
|
125
|
+
return {
|
|
126
|
+
sessionId,
|
|
127
|
+
created: true
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const ensureCoordinator = (target, settings) => {
|
|
131
|
+
const pending = opening.get(target);
|
|
132
|
+
if (pending !== void 0) return pending;
|
|
133
|
+
const run = open(target, settings).finally(() => opening.delete(target));
|
|
134
|
+
opening.set(target, run);
|
|
135
|
+
return run;
|
|
136
|
+
};
|
|
137
|
+
const workspaceSettings = (workspace, home) => ({
|
|
138
|
+
profile: home.profile,
|
|
139
|
+
name: `${home.name}-${workspaceSlug(workspace)}`,
|
|
140
|
+
...home.model === void 0 ? {} : { model: home.model }
|
|
141
|
+
});
|
|
142
|
+
const coordinated = (workspace) => workspace.kind !== "session" && workspace.available !== false && workspace.sandbox === void 0;
|
|
143
|
+
const homePersona = () => {
|
|
144
|
+
const general = homeWorkspace();
|
|
145
|
+
const home = general === void 0 ? void 0 : oldestCoordinator(general.id);
|
|
146
|
+
return home === void 0 ? void 0 : options.records().find((record) => record.sessionId === home.sessionId)?.coordinator;
|
|
147
|
+
};
|
|
148
|
+
const recordPersona = (sessionId, coordinator) => {
|
|
149
|
+
const record = options.records().find((entry) => entry.sessionId === sessionId);
|
|
150
|
+
if (record === void 0) return;
|
|
151
|
+
const { coordinator: _dropped, ...rest } = record;
|
|
152
|
+
if (!options.saveRecord(coordinator === void 0 ? rest : {
|
|
153
|
+
...rest,
|
|
154
|
+
coordinator
|
|
155
|
+
})) options.notice(`Coordinator '${sessionId}' persona could not be recorded.`);
|
|
156
|
+
};
|
|
157
|
+
const demote = async (sessionId) => {
|
|
158
|
+
if (options.liveSessions().some((session) => session.id === sessionId)) await options.reopen(sessionId, {});
|
|
159
|
+
else {
|
|
160
|
+
const record = options.records().find((entry) => entry.sessionId === sessionId);
|
|
161
|
+
if (record === void 0) return;
|
|
162
|
+
const { sessionProvenance: _dropped, ...rest } = record;
|
|
163
|
+
if (!options.saveRecord(rest)) throw new Error(`Session '${sessionId}' could not be made regular.`);
|
|
164
|
+
}
|
|
165
|
+
recordPersona(sessionId, void 0);
|
|
166
|
+
};
|
|
167
|
+
const ensureHome = (settings) => ensureCoordinator("home", settings);
|
|
168
|
+
return {
|
|
169
|
+
ensureCoordinator,
|
|
170
|
+
ensureHome,
|
|
171
|
+
async startSession(coordinatorSessionId, request) {
|
|
172
|
+
const caller = options.liveSessions().find((session) => session.id === coordinatorSessionId);
|
|
173
|
+
if (caller?.sessionProvenance !== _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE) throw new Error("Only a coordinator can start sessions.");
|
|
174
|
+
const name = request.name.trim();
|
|
175
|
+
const brief = request.brief.trim();
|
|
176
|
+
if (name === "" || brief === "") throw new Error("A started session needs a name and a brief.");
|
|
177
|
+
if (brief.length > 4e3) throw new Error(`A brief is at most ${require_type.BRIEF_MAX} characters, and this one is ${brief.length}. Put the detail in a file and name the file in the brief.`);
|
|
178
|
+
if (request.workspaceId !== void 0 && (typeof request.workspaceId !== "string" || request.workspaceId.trim() === "")) throw new Error("A target workspace ID must be non-empty text.");
|
|
179
|
+
const workspace = options.workspaces().find((entry) => entry.id === (request.workspaceId ?? caller.workspaceId));
|
|
180
|
+
assertCoordinatorStartScope(caller.workspaceId, homeWorkspace()?.id, workspace, workspace !== void 0 && oldestCoordinator(workspace.id) !== void 0);
|
|
181
|
+
const at = now();
|
|
182
|
+
const recent = (starts.get(coordinatorSessionId) ?? []).filter((time) => at - time < COORDINATOR_START_WINDOW_MS);
|
|
183
|
+
assertCoordinatorStartBudget(recent.length);
|
|
184
|
+
starts.set(coordinatorSessionId, [...recent, at]);
|
|
185
|
+
const { sessionId } = workspace.kind === "session" ? await options.createGeneral({ name }) : await options.createInWorkspace(workspace, { name });
|
|
186
|
+
try {
|
|
187
|
+
return {
|
|
188
|
+
sessionId,
|
|
189
|
+
goal: (await options.prompt(sessionId, `/goal -- ${brief}`))?.handledCommand === true
|
|
190
|
+
};
|
|
191
|
+
} catch (error) {
|
|
192
|
+
return {
|
|
193
|
+
sessionId,
|
|
194
|
+
promptError: error instanceof Error ? error.message : String(error)
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
async add(workspaceId, profile) {
|
|
199
|
+
if (profile !== void 0 && (typeof profile !== "string" || profile.trim() === "")) throw new Error("A coordinator profile must be non-empty text.");
|
|
200
|
+
const workspace = workspaceId === void 0 ? homeWorkspace() : options.workspaces().find((entry) => entry.id === workspaceId);
|
|
201
|
+
if (workspaceId !== void 0) {
|
|
202
|
+
if (workspace === void 0) throw new Error(`Workspace '${workspaceId}' not found.`);
|
|
203
|
+
if (!coordinated(workspace)) throw new Error("This workspace cannot have a coordinator.");
|
|
204
|
+
}
|
|
205
|
+
const existing = workspace === void 0 ? void 0 : oldestCoordinator(workspace.id);
|
|
206
|
+
const inherited = homePersona();
|
|
207
|
+
const selected = profile?.trim() ?? inherited?.profile ?? options.defaultProfile(workspaceId === void 0 ? void 0 : workspace?.root);
|
|
208
|
+
if (selected === void 0 && existing === void 0) return {
|
|
209
|
+
profileRequired: true,
|
|
210
|
+
error: "Choose a profile before adding a coordinator."
|
|
211
|
+
};
|
|
212
|
+
if (selected === void 0 && existing !== void 0) {
|
|
213
|
+
if (!existing.live) {
|
|
214
|
+
const record = options.records().find((entry) => entry.sessionId === existing.sessionId);
|
|
215
|
+
if (record === void 0) throw new Error("The coordinator record disappeared while reviving it.");
|
|
216
|
+
await options.revive(record);
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
sessionId: existing.sessionId,
|
|
220
|
+
created: false
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
const settings = profile !== void 0 ? {
|
|
224
|
+
profile: selected,
|
|
225
|
+
name: selected
|
|
226
|
+
} : inherited ?? {
|
|
227
|
+
profile: selected ?? "",
|
|
228
|
+
name: selected ?? ""
|
|
229
|
+
};
|
|
230
|
+
if (profile !== void 0 && existing === void 0) await options.validateProfile?.(selected, workspaceId === void 0 ? void 0 : workspace);
|
|
231
|
+
return workspaceId === void 0 ? ensureHome(settings) : ensureCoordinator(workspaceId, workspaceSettings(workspace, settings));
|
|
232
|
+
},
|
|
233
|
+
async setRole(sessionId, coordinator) {
|
|
234
|
+
let live = options.liveSessions().find((session) => session.id === sessionId);
|
|
235
|
+
const record = options.records().find((entry) => entry.sessionId === sessionId);
|
|
236
|
+
const current = live ?? (record === void 0 ? void 0 : {
|
|
237
|
+
...record,
|
|
238
|
+
id: record.sessionId
|
|
239
|
+
});
|
|
240
|
+
if (current?.workspaceId === void 0) throw new Error("Session not found.");
|
|
241
|
+
if (current.sessionProvenance === _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE === coordinator) return;
|
|
242
|
+
if (!coordinator) return demote(sessionId);
|
|
243
|
+
if (current.parentSessionId !== void 0) throw new Error("A nested session cannot become a coordinator.");
|
|
244
|
+
if (current.sessionProvenance !== void 0) throw new Error(`A ${current.sessionProvenance} session cannot become a coordinator.`);
|
|
245
|
+
const workspace = options.workspaces().find((entry) => entry.id === current.workspaceId);
|
|
246
|
+
if (workspace === void 0 || workspace.sandbox !== void 0 || workspace.kind !== "session" && !coordinated(workspace)) throw new Error("This workspace cannot have a coordinator.");
|
|
247
|
+
for (const other of coordinatorsIn(workspace.id)) await demote(other.sessionId);
|
|
248
|
+
if (live === void 0) {
|
|
249
|
+
await options.revive(record);
|
|
250
|
+
live = options.liveSessions().find((session) => session.id === sessionId);
|
|
251
|
+
}
|
|
252
|
+
const profile = live?.profile?.name ?? options.defaultProfile(workspace.root);
|
|
253
|
+
await options.reopen(sessionId, {
|
|
254
|
+
sessionProvenance: _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE,
|
|
255
|
+
...live?.profile === void 0 && profile !== void 0 ? { profile } : {}
|
|
256
|
+
});
|
|
257
|
+
if (profile !== void 0) recordPersona(sessionId, {
|
|
258
|
+
profile,
|
|
259
|
+
name: current.name ?? profile
|
|
260
|
+
});
|
|
261
|
+
else options.notice(`Coordinator '${sessionId}' has no profile; new workspaces will not copy its persona.`);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/services/peerLink/roster.ts
|
|
267
|
+
const LINK_TTL = 6e4;
|
|
268
|
+
/** Account links are separate from legacy session-peer secrets and permissions.
|
|
269
|
+
* A fresh signed ephemeral exchange uses the host key in the verified C6 roster.
|
|
270
|
+
* Coordinator availability is irrelevant. Roster removal or rotation fences all
|
|
271
|
+
* existing channel uses; applications must sync and persist C6 before exposing it.
|
|
272
|
+
*/
|
|
273
|
+
function createRosterPeerLink(ports) {
|
|
274
|
+
const consumed = /* @__PURE__ */ new Map();
|
|
275
|
+
function check(proof) {
|
|
276
|
+
const snapshot = ports.roster();
|
|
277
|
+
const payload = proof.payload;
|
|
278
|
+
const host = snapshot.hosts.find((h) => h.hostId === payload.hostId);
|
|
279
|
+
if (!host || payload.hostId === ports.hostId || payload.destinationHostId !== ports.hostId || payload.networkId !== snapshot.networkId || payload.epoch !== snapshot.epoch || !payload.publicKey || !payload.challenge || typeof payload.echo !== "string" || payload.expiresAt - payload.issuedAt > LINK_TTL || !(0, _agimon_ai_po_web_security_deviceProof.verifyEnvelope)(host.publicKey, "po/host-request/v1", proof, ports.now())) throw new Error("Roster link refused");
|
|
280
|
+
return payload;
|
|
281
|
+
}
|
|
282
|
+
function wrap(channel, hostId, epoch) {
|
|
283
|
+
const snapshot = ports.roster();
|
|
284
|
+
const remote = snapshot.hosts.find((h) => h.hostId === hostId)?.publicKey;
|
|
285
|
+
const local = snapshot.hosts.find((h) => h.hostId === ports.hostId)?.publicKey;
|
|
286
|
+
const valid = () => {
|
|
287
|
+
const current = ports.roster();
|
|
288
|
+
return !!remote && !!local && current.networkId === snapshot.networkId && current.epoch === epoch && current.hosts.some((h) => h.hostId === hostId && h.publicKey === remote) && current.hosts.some((h) => h.hostId === ports.hostId && h.publicKey === local);
|
|
289
|
+
};
|
|
290
|
+
return {
|
|
291
|
+
seal(plaintext) {
|
|
292
|
+
if (!valid()) return {
|
|
293
|
+
ok: false,
|
|
294
|
+
failure: "auth"
|
|
295
|
+
};
|
|
296
|
+
return channel.seal(plaintext);
|
|
297
|
+
},
|
|
298
|
+
async open(envelope) {
|
|
299
|
+
if (!valid()) return void 0;
|
|
300
|
+
const opened = channel.open(envelope);
|
|
301
|
+
if (!opened.ok || !await ports.verifyRequest(opened.plaintext, hostId) || !valid()) return void 0;
|
|
302
|
+
return opened.plaintext;
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
async connect(hostId, token, exchange) {
|
|
308
|
+
const snapshot = ports.roster();
|
|
309
|
+
if (!snapshot.hosts.some((h) => h.hostId === ports.hostId) || !snapshot.hosts.some((h) => h.hostId === hostId)) throw new Error("Host is not in roster");
|
|
310
|
+
const handshake = (0, _agimon_ai_po_web_security_nodeSealedChannel.createClientHandshake)();
|
|
311
|
+
const issuedAt = ports.now();
|
|
312
|
+
const payload = {
|
|
313
|
+
networkId: snapshot.networkId,
|
|
314
|
+
epoch: snapshot.epoch,
|
|
315
|
+
hostId: ports.hostId,
|
|
316
|
+
destinationHostId: hostId,
|
|
317
|
+
publicKey: handshake.publicKey,
|
|
318
|
+
challenge: crypto.randomUUID(),
|
|
319
|
+
echo: "",
|
|
320
|
+
issuedAt,
|
|
321
|
+
expiresAt: issuedAt + LINK_TTL
|
|
322
|
+
};
|
|
323
|
+
const reply = check(await exchange(ports.sign(payload), token));
|
|
324
|
+
if (reply.hostId !== hostId || reply.challenge !== payload.challenge || reply.echo !== payload.publicKey || reply.epoch !== payload.epoch) throw new Error("Roster link response mismatch");
|
|
325
|
+
const channel = handshake.accept(reply.publicKey);
|
|
326
|
+
if (!channel) throw new Error("Invalid roster channel");
|
|
327
|
+
return wrap(channel, hostId, payload.epoch);
|
|
328
|
+
},
|
|
329
|
+
async accept(proof, token) {
|
|
330
|
+
const payload = check(proof);
|
|
331
|
+
if (payload.echo !== "" || !await ports.authorize(token, payload.hostId, payload.networkId)) throw new Error("Roster link denied");
|
|
332
|
+
check(proof);
|
|
333
|
+
for (const [id, expiry] of consumed) if (expiry <= ports.now()) consumed.delete(id);
|
|
334
|
+
const id = JSON.stringify([payload.hostId, payload.challenge]);
|
|
335
|
+
if (consumed.has(id) || consumed.size >= 1024) throw new Error("Roster link replayed");
|
|
336
|
+
consumed.set(id, payload.expiresAt);
|
|
337
|
+
const handshake = (0, _agimon_ai_po_web_security_nodeSealedChannel.createHostHandshake)();
|
|
338
|
+
const channel = handshake.accept(payload.publicKey);
|
|
339
|
+
if (!channel) throw new Error("Invalid roster channel");
|
|
340
|
+
const issuedAt = ports.now();
|
|
341
|
+
return {
|
|
342
|
+
proof: ports.sign({
|
|
343
|
+
...payload,
|
|
344
|
+
hostId: ports.hostId,
|
|
345
|
+
destinationHostId: payload.hostId,
|
|
346
|
+
publicKey: handshake.publicKey,
|
|
347
|
+
echo: payload.publicKey,
|
|
348
|
+
issuedAt,
|
|
349
|
+
expiresAt: issuedAt + LINK_TTL
|
|
350
|
+
}),
|
|
351
|
+
channel: wrap(channel, payload.hostId, payload.epoch)
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
//#endregion
|
|
357
|
+
exports.COORDINATOR_STARTS_PER_HOUR = COORDINATOR_STARTS_PER_HOUR;
|
|
358
|
+
exports.COORDINATOR_START_WINDOW_MS = COORDINATOR_START_WINDOW_MS;
|
|
359
|
+
exports.PO_ROSTER_PEER_CONTRACT = require_type.PO_ROSTER_PEER_CONTRACT;
|
|
360
|
+
exports.PO_ROSTER_PEER_SERVICE = require_type.PO_ROSTER_PEER_SERVICE;
|
|
361
|
+
exports.PO_SESSION_DELIVERY_SERVICE = require_type.PO_SESSION_DELIVERY_SERVICE;
|
|
362
|
+
exports.PO_SESSION_GROUP_BRIDGE_SERVICE = require_type.PO_SESSION_GROUP_BRIDGE_SERVICE;
|
|
363
|
+
exports.PO_SESSION_INTERCOM_SERVICE = require_type.PO_SESSION_INTERCOM_SERVICE;
|
|
364
|
+
exports.PO_SESSION_OPERATIONS_SERVICE = require_type.PO_SESSION_OPERATIONS_SERVICE;
|
|
365
|
+
exports.PO_SESSION_PEERS_CONTRACT = require_type.PO_SESSION_PEERS_CONTRACT;
|
|
366
|
+
exports.PO_SESSION_PEERS_SERVICE = require_type.PO_SESSION_PEERS_SERVICE;
|
|
367
|
+
exports.START_SESSION_TOOL_NAME = require_type.START_SESSION_TOOL_NAME;
|
|
368
|
+
exports.SessionGroupRevisionError = require_type.SessionGroupRevisionError;
|
|
369
|
+
exports.StartSessionParamsSchema = require_type.StartSessionParamsSchema;
|
|
370
|
+
exports.assertCoordinatorStartBudget = assertCoordinatorStartBudget;
|
|
371
|
+
exports.assertCoordinatorStartScope = assertCoordinatorStartScope;
|
|
372
|
+
exports.canSessionsCommunicate = canSessionsCommunicate;
|
|
373
|
+
exports.createBackgroundWorkService = require_type.createBackgroundWorkService;
|
|
374
|
+
exports.createCoordinatorService = createCoordinatorService;
|
|
375
|
+
exports.createPeerCommunication = require_type.createPeerCommunication;
|
|
376
|
+
exports.createPeerLink = require_type.createPeerLink;
|
|
377
|
+
exports.createPeerReplayGuard = require_type.createPeerReplayGuard;
|
|
378
|
+
exports.createPeerReplayGuardAsync = require_type.createPeerReplayGuardAsync;
|
|
379
|
+
exports.createRosterPeerLink = createRosterPeerLink;
|
|
380
|
+
exports.createSessionDeliveryService = require_type.createSessionDeliveryService;
|
|
381
|
+
exports.createSessionDirectory = require_type.createSessionDirectory;
|
|
382
|
+
exports.createSessionGroupDeliveryAuthorizer = require_type.createSessionGroupDeliveryAuthorizer;
|
|
383
|
+
exports.createSessionGroupStore = require_type.createSessionGroupStore;
|
|
384
|
+
exports.createSessionIntercom = require_type.createSessionIntercom;
|
|
385
|
+
exports.createSessionPeers = require_type.createSessionPeers;
|
|
386
|
+
exports.createSessionsNamespace = require_type.createSessionsNamespace;
|
|
387
|
+
exports.createStartSessionTool = require_type.createStartSessionTool;
|
|
388
|
+
exports.namedSessionGroupId = require_type.namedSessionGroupId;
|
|
389
|
+
exports.parseRemoteSessionReference = require_type.parseRemoteSessionReference;
|
|
390
|
+
exports.parseStartSessionInput = require_type.parseStartSessionInput;
|
|
391
|
+
exports.peerOrigin = require_type.peerOrigin;
|
|
392
|
+
exports.peerRequestHeaders = require_type.peerRequestHeaders;
|
|
393
|
+
exports.peerSessionReference = require_type.peerSessionReference;
|
|
394
|
+
exports.provideBackgroundWorkService = require_type.provideBackgroundWorkService;
|
|
395
|
+
exports.provideSessionDeliveryService = require_type.provideSessionDeliveryService;
|
|
396
|
+
exports.readPoSessionDelivery = require_type.readPoSessionDelivery;
|
|
397
|
+
exports.readSessionGroupBridge = require_type.readSessionGroupBridge;
|
|
398
|
+
exports.readSessionIntercom = require_type.readSessionIntercom;
|
|
399
|
+
exports.readSessionOperations = require_type.readSessionOperations;
|
|
400
|
+
exports.readSessionPeerConfig = require_type.readSessionPeerConfig;
|
|
401
|
+
exports.readSessionPeerConfigAsync = require_type.readSessionPeerConfigAsync;
|
|
402
|
+
exports.requireSessionIntercom = require_type.requireSessionIntercom;
|
|
403
|
+
exports.requireSessionPeers = require_type.requireSessionPeers;
|
|
404
|
+
exports.sendSessionMessage = require_type.sendSessionMessage;
|
|
405
|
+
exports.sessionCoordinates = sessionCoordinates;
|
|
406
|
+
exports.sessionPeerConfigPath = require_type.sessionPeerConfigPath;
|
|
407
|
+
exports.startCoordinatedSession = require_type.startCoordinatedSession;
|
|
408
|
+
exports.verifyPeerRequest = require_type.verifyPeerRequest;
|
|
409
|
+
exports.workspaceSlug = workspaceSlug;
|
|
410
|
+
|
|
411
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["COORDINATOR_SESSION_PROVENANCE","REMOTE_CONVERSATION_SESSION_PROVENANCE","COORDINATOR_SESSION_PROVENANCE","BRIEF_MAX","verifyEnvelope","createClientHandshake","createHostHandshake"],"sources":["../src/services/sessionCoordination/policy.ts","../src/services/sessionCoordination/index.ts","../src/services/peerLink/roster.ts"],"sourcesContent":["import {\n COORDINATOR_SESSION_PROVENANCE,\n REMOTE_CONVERSATION_SESSION_PROVENANCE,\n type PoSessionCommunicationPolicy,\n type PoSessionCommunicationPolicyInput,\n type PoSessionCommunicationSubject,\n type PoSessionCoordinationPolicy,\n} from '@agimon-ai/po-core/hubChannel';\n\n/** ponytail: a fixed per-coordinator budget; add configuration only when another number is needed. */\nexport const COORDINATOR_STARTS_PER_HOUR = 5;\nexport const COORDINATOR_START_WINDOW_MS = 60 * 60 * 1000;\n\nexport function assertCoordinatorStartBudget(count: number): void {\n if (count >= COORDINATOR_STARTS_PER_HOUR)\n throw new Error(`A coordinator can start at most ${COORDINATOR_STARTS_PER_HOUR} sessions an hour.`);\n}\n\nexport function assertCoordinatorStartScope(\n callerWorkspaceId: string | undefined,\n homeWorkspaceId: string | undefined,\n workspace: { id: string; kind?: 'session'; available?: boolean; sandbox?: string } | undefined,\n hasCoordinator: boolean,\n): void {\n if (workspace === undefined || workspace.available === false || workspace.sandbox !== undefined)\n throw new Error('The target workspace is unavailable.');\n if (workspace.id === callerWorkspaceId) return;\n if (callerWorkspaceId === undefined || callerWorkspaceId !== homeWorkspaceId || workspace.kind === 'session')\n throw new Error('Only the home coordinator can target another workspace.');\n if (hasCoordinator) throw new Error('This workspace has a coordinator. Ask it to start the session.');\n}\n\nconst coordinates = (session: PoSessionCommunicationSubject): boolean =>\n session.sessionProvenance === COORDINATOR_SESSION_PROVENANCE;\n\nconst remote = (session: PoSessionCommunicationSubject): boolean =>\n session.sessionProvenance === REMOTE_CONVERSATION_SESSION_PROVENANCE;\n\n/** The coordinator of the internal Home workspace. */\nconst home = (input: PoSessionCommunicationPolicyInput, session: PoSessionCommunicationSubject): boolean =>\n coordinates(session) &&\n session.workspaceId !== undefined &&\n input.workspaces.some((workspace) => workspace.id === session.workspaceId && workspace.kind === 'session');\n\n/** Home stands in for a workspace that has no live or dormant coordinator of its own. */\nconst homeFallback = (\n input: PoSessionCommunicationPolicyInput,\n coordinator: PoSessionCommunicationSubject,\n peer: PoSessionCommunicationSubject,\n): boolean => {\n if (!home(input, coordinator) || peer.workspaceId === undefined) return false;\n const workspace = input.workspaces.find((entry) => entry.id === peer.workspaceId);\n if (!workspace || workspace.kind === 'session' || workspace.sandbox !== undefined || workspace.available === false)\n return false;\n return (\n !input.sessions.some((session) => session.workspaceId === workspace.id && coordinates(session)) &&\n !input.dormantSessions.some(\n (record) =>\n record.workspaceId === workspace.id &&\n record.sessionProvenance === COORDINATOR_SESSION_PROVENANCE &&\n !input.sessions.some((session) => session.id === record.sessionId),\n )\n );\n};\n\n/** Communication is symmetric. A message grant never grants lifecycle authority. */\nexport const canSessionsCommunicate: PoSessionCommunicationPolicy = (input) => {\n const { source, target } = input;\n if (source.id === target.id) return false;\n if (source.parentSessionId === target.id || target.parentSessionId === source.id) return true;\n if (remote(source) || remote(target)) return false;\n // The person linked the two by naming one to the other with `@session:`.\n if (input.mentioned === true) return true;\n // A host package placed one for the other as its owner, as Calendar does for an event's session.\n if (input.launched === true) return true;\n if (\n (coordinates(source) || coordinates(target)) &&\n source.workspaceId !== undefined &&\n source.workspaceId === target.workspaceId\n )\n return true;\n if (coordinates(source) && coordinates(target) && (home(input, source) || home(input, target))) return true;\n if (homeFallback(input, source, target) || homeFallback(input, target, source)) return true;\n if (source.workspaceId !== undefined && source.workspaceId === target.workspaceId && input.filesOverlap) return true;\n return (source.groups ?? []).some((group) => target.groups?.includes(group) === true);\n};\n\n/**\n * The hierarchy only, never a group, a mention, shared files or a parent link: `target` coordinates\n * `source` when it is the coordinator of `source`'s workspace, Home standing in for a workspace\n * without one, or Home over a workspace coordinator.\n */\nexport const sessionCoordinates: PoSessionCoordinationPolicy = (input) => {\n const { source, target } = input;\n if (source.id === target.id || !coordinates(target) || remote(source) || remote(target)) return false;\n if (coordinates(source)) return home(input, target) && !home(input, source);\n if (source.workspaceId !== undefined && source.workspaceId === target.workspaceId) return true;\n return homeFallback(input, target, source);\n};\n","import { COORDINATOR_SESSION_PROVENANCE } from '@agimon-ai/po-core/hubChannel';\n\nimport { BRIEF_MAX } from '../../schemas/startSession';\nimport { assertCoordinatorStartBudget, assertCoordinatorStartScope, COORDINATOR_START_WINDOW_MS } from './policy';\nimport type {\n CoordinatorSettings,\n CoordinatorResult,\n CoordinatorWorkspace,\n CoordinatorCreateRequest,\n CoordinatorServiceOptions,\n CoordinatorService,\n} from './type';\n\nexport { COORDINATOR_STARTS_PER_HOUR } from './policy';\nconst FALLBACK_SLUG = 'workspace';\n\nexport type {\n CoordinatorSettings,\n CoordinatorResult,\n CoordinatorAddResult,\n CoordinatorCreateRequest,\n CoordinatorServiceOptions,\n CoordinatorService,\n} from './type';\n\n/** Kebab-case from the workspace name, else its folder name. */\nexport function workspaceSlug(workspace: { readonly name?: string; readonly root: string }): string {\n const source = workspace.name?.trim() || workspace.root.split(/[\\\\/]/u).filter(Boolean).pop() || '';\n const slug = source\n .toLowerCase()\n .replace(/[^a-z0-9]+/gu, '-')\n .replace(/^-+|-+$/gu, '');\n return slug || FALLBACK_SLUG;\n}\n\nexport function createCoordinatorService(options: CoordinatorServiceOptions): CoordinatorService {\n const opening = new Map<string, Promise<CoordinatorResult>>();\n const starts = new Map<string, number[]>();\n const now = (): number => options.now?.() ?? Date.now();\n\n const homeWorkspace = (): CoordinatorWorkspace | undefined =>\n options.workspaces().find((workspace) => workspace.kind === 'session');\n\n /** Live sessions first, so a live coordinator's record is never mistaken for a dormant one. Oldest wins. */\n const coordinatorsIn = (workspaceId: string): { sessionId: string; createdAt: string; live: boolean }[] => {\n const liveSessions = options.liveSessions();\n const live = liveSessions\n .filter(\n (session) =>\n session.sessionProvenance === COORDINATOR_SESSION_PROVENANCE && session.workspaceId === workspaceId,\n )\n .map((session) => ({ sessionId: session.id, createdAt: session.createdAt, live: true }));\n const dormant = options\n .records()\n .filter(\n (record) =>\n record.sessionProvenance === COORDINATOR_SESSION_PROVENANCE &&\n record.workspaceId === workspaceId &&\n !liveSessions.some((session) => session.id === record.sessionId),\n )\n .map((record) => ({ sessionId: record.sessionId, createdAt: record.createdAt, live: false }));\n return [...live, ...dormant].sort((a, b) => a.createdAt.localeCompare(b.createdAt));\n };\n\n const oldestCoordinator = (workspaceId: string) => {\n const found = coordinatorsIn(workspaceId);\n if (found.length > 1)\n options.notice(\n `Workspace '${workspaceId}' has ${found.length} coordinators; using the oldest, '${found[0]?.sessionId}'.`,\n );\n return found[0];\n };\n\n const open = async (target: string, settings: CoordinatorSettings): Promise<CoordinatorResult> => {\n const workspace = target === 'home' ? homeWorkspace() : options.workspaces().find((entry) => entry.id === target);\n if (target !== 'home') {\n if (workspace === undefined) throw new Error(`Workspace '${target}' not found.`);\n if (workspace.kind === 'session') throw new Error('The home workspace takes the home coordinator.');\n if (!coordinated(workspace)) throw new Error('This workspace cannot have a coordinator.');\n }\n if (workspace?.sandbox !== undefined) throw new Error('This workspace cannot have a coordinator.');\n const existing = workspace === undefined ? undefined : oldestCoordinator(workspace.id);\n if (existing !== undefined) {\n if (!existing.live) {\n const record = options.records().find((entry) => entry.sessionId === existing.sessionId);\n if (record === undefined) throw new Error('The coordinator record disappeared while reviving it.');\n await options.revive(record);\n }\n return { sessionId: existing.sessionId, created: false };\n }\n const request: CoordinatorCreateRequest = {\n name: settings.name,\n sessionProvenance: COORDINATOR_SESSION_PROVENANCE,\n selection: { profile: settings.profile },\n ...(settings.model === undefined ? {} : { model: settings.model }),\n };\n const { sessionId } =\n workspace === undefined || target === 'home'\n ? await options.createGeneral(request)\n : await options.createInWorkspace(workspace, request);\n // The persona rides on the record, so the admit path still knows it after a restart.\n const record = options.records().find((entry) => entry.sessionId === sessionId);\n const coordinator = {\n profile: settings.profile,\n name: settings.name,\n ...(settings.model === undefined ? {} : { model: settings.model }),\n };\n if (record === undefined || !options.saveRecord({ ...record, coordinator }))\n options.notice(`Coordinator '${sessionId}' persona could not be recorded.`);\n return { sessionId, created: true };\n };\n\n const ensureCoordinator = (target: string, settings: CoordinatorSettings): Promise<CoordinatorResult> => {\n const pending = opening.get(target);\n if (pending !== undefined) return pending;\n const run = open(target, settings).finally(() => opening.delete(target));\n opening.set(target, run);\n return run;\n };\n\n const workspaceSettings = (workspace: CoordinatorWorkspace, home: CoordinatorSettings): CoordinatorSettings => ({\n profile: home.profile,\n name: `${home.name}-${workspaceSlug(workspace)}`,\n ...(home.model === undefined ? {} : { model: home.model }),\n });\n\n // Sandboxed workspaces get no coordinator; their sessions live in the sandbox's own records.\n const coordinated = (workspace: CoordinatorWorkspace): boolean =>\n workspace.kind !== 'session' && workspace.available !== false && workspace.sandbox === undefined;\n\n const homePersona = (): CoordinatorSettings | undefined => {\n const general = homeWorkspace();\n const home = general === undefined ? undefined : oldestCoordinator(general.id);\n return home === undefined\n ? undefined\n : options.records().find((record) => record.sessionId === home.sessionId)?.coordinator;\n };\n\n const recordPersona = (sessionId: string, coordinator: CoordinatorSettings | undefined): void => {\n const record = options.records().find((entry) => entry.sessionId === sessionId);\n if (record === undefined) return;\n const { coordinator: _dropped, ...rest } = record;\n if (!options.saveRecord(coordinator === undefined ? rest : { ...rest, coordinator }))\n options.notice(`Coordinator '${sessionId}' persona could not be recorded.`);\n };\n\n const demote = async (sessionId: string): Promise<void> => {\n if (options.liveSessions().some((session) => session.id === sessionId)) await options.reopen(sessionId, {});\n else {\n const record = options.records().find((entry) => entry.sessionId === sessionId);\n if (record === undefined) return;\n const { sessionProvenance: _dropped, ...rest } = record;\n if (!options.saveRecord(rest)) throw new Error(`Session '${sessionId}' could not be made regular.`);\n }\n recordPersona(sessionId, undefined);\n };\n\n // Only the home coordinator. It reaches workspaces without their own coordinator through the communication policy.\n const ensureHome = (settings: CoordinatorSettings): Promise<CoordinatorResult> => ensureCoordinator('home', settings);\n\n return {\n ensureCoordinator,\n ensureHome,\n async startSession(coordinatorSessionId, request) {\n const caller = options.liveSessions().find((session) => session.id === coordinatorSessionId);\n if (caller?.sessionProvenance !== COORDINATOR_SESSION_PROVENANCE)\n throw new Error('Only a coordinator can start sessions.');\n const name = request.name.trim();\n const brief = request.brief.trim();\n if (name === '' || brief === '') throw new Error('A started session needs a name and a brief.');\n // Refused before anything is created or a start is spent.\n if (brief.length > BRIEF_MAX)\n throw new Error(\n `A brief is at most ${BRIEF_MAX} characters, and this one is ${brief.length}. Put the detail in a file and name the file in the brief.`,\n );\n if (\n request.workspaceId !== undefined &&\n (typeof request.workspaceId !== 'string' || request.workspaceId.trim() === '')\n )\n throw new Error('A target workspace ID must be non-empty text.');\n const workspace = options.workspaces().find((entry) => entry.id === (request.workspaceId ?? caller.workspaceId));\n assertCoordinatorStartScope(\n caller.workspaceId,\n homeWorkspace()?.id,\n workspace,\n workspace !== undefined && oldestCoordinator(workspace.id) !== undefined,\n );\n const at = now();\n const recent = (starts.get(coordinatorSessionId) ?? []).filter((time) => at - time < COORDINATOR_START_WINDOW_MS);\n assertCoordinatorStartBudget(recent.length);\n starts.set(coordinatorSessionId, [...recent, at]);\n // No parent link: a parent may close its children, and a coordinator never stops sessions.\n const { sessionId } =\n workspace!.kind === 'session'\n ? await options.createGeneral({ name })\n : await options.createInWorkspace(workspace!, { name });\n try {\n // As its goal, the brief keeps the session at work until it is done, not for one turn only.\n // ponytail: a session without Goal reads the brief behind this prefix; the upgrade is a command-only\n // prompt option in the hub.\n const receipt = await options.prompt(sessionId, `/goal -- ${brief}`);\n return { sessionId, goal: (receipt as { handledCommand?: unknown } | undefined)?.handledCommand === true };\n } catch (error) {\n // Creation committed and spent its quota. Report the id so callers do not blindly retry.\n return { sessionId, promptError: error instanceof Error ? error.message : String(error) };\n }\n },\n async add(workspaceId, profile) {\n if (profile !== undefined && (typeof profile !== 'string' || profile.trim() === ''))\n throw new Error('A coordinator profile must be non-empty text.');\n const workspace =\n workspaceId === undefined ? homeWorkspace() : options.workspaces().find((entry) => entry.id === workspaceId);\n if (workspaceId !== undefined) {\n if (workspace === undefined) throw new Error(`Workspace '${workspaceId}' not found.`);\n if (!coordinated(workspace)) throw new Error('This workspace cannot have a coordinator.');\n }\n // Reuse does not need a new persona, even when the default has since disappeared.\n const existing = workspace === undefined ? undefined : oldestCoordinator(workspace.id);\n const inherited = homePersona();\n const selected =\n profile?.trim() ??\n inherited?.profile ??\n options.defaultProfile(workspaceId === undefined ? undefined : workspace?.root);\n if (selected === undefined && existing === undefined)\n return { profileRequired: true, error: 'Choose a profile before adding a coordinator.' };\n if (selected === undefined && existing !== undefined) {\n if (!existing.live) {\n const record = options.records().find((entry) => entry.sessionId === existing.sessionId);\n if (record === undefined) throw new Error('The coordinator record disappeared while reviving it.');\n await options.revive(record);\n }\n return { sessionId: existing.sessionId, created: false };\n }\n const settings =\n profile !== undefined\n ? { profile: selected!, name: selected! }\n : (inherited ?? { profile: selected ?? '', name: selected ?? '' });\n if (profile !== undefined && existing === undefined)\n await options.validateProfile?.(selected!, workspaceId === undefined ? undefined : workspace);\n return workspaceId === undefined\n ? ensureHome(settings)\n : ensureCoordinator(workspaceId, workspaceSettings(workspace!, settings));\n },\n async setRole(sessionId, coordinator) {\n let live = options.liveSessions().find((session) => session.id === sessionId);\n const record = options.records().find((entry) => entry.sessionId === sessionId);\n const current = live ?? (record === undefined ? undefined : { ...record, id: record.sessionId });\n if (current?.workspaceId === undefined) throw new Error('Session not found.');\n if ((current.sessionProvenance === COORDINATOR_SESSION_PROVENANCE) === coordinator) return;\n if (!coordinator) return demote(sessionId);\n if (current.parentSessionId !== undefined) throw new Error('A nested session cannot become a coordinator.');\n // A worktree, workflow or voice session keeps the role its provenance gives it.\n if (current.sessionProvenance !== undefined)\n throw new Error(`A ${current.sessionProvenance} session cannot become a coordinator.`);\n const workspace = options.workspaces().find((entry) => entry.id === current.workspaceId);\n if (\n workspace === undefined ||\n workspace.sandbox !== undefined ||\n (workspace.kind !== 'session' && !coordinated(workspace))\n )\n throw new Error('This workspace cannot have a coordinator.');\n for (const other of coordinatorsIn(workspace.id)) await demote(other.sessionId);\n if (live === undefined) {\n await options.revive(record!);\n live = options.liveSessions().find((session) => session.id === sessionId);\n }\n // The session keeps its own persona; one without gets the default.\n const profile = live?.profile?.name ?? options.defaultProfile(workspace.root);\n await options.reopen(sessionId, {\n sessionProvenance: COORDINATOR_SESSION_PROVENANCE,\n ...(live?.profile === undefined && profile !== undefined ? { profile } : {}),\n });\n if (profile !== undefined) recordPersona(sessionId, { profile, name: current.name ?? profile });\n else options.notice(`Coordinator '${sessionId}' has no profile; new workspaces will not copy its persona.`);\n },\n };\n}\n","import { verifyEnvelope } from '@agimon-ai/po-web-security/deviceProof';\nimport {\n createClientHandshake,\n createHostHandshake,\n type SealedChannel,\n} from '@agimon-ai/po-web-security/nodeSealedChannel';\n\nimport type {\n RosterLinkProof,\n RosterPeerChannel,\n RosterPeerLinkPorts,\n RosterPeerLinks,\n SignedRosterLinkProof,\n} from './type';\n\nconst LINK_TTL = 60_000;\n\n/** Account links are separate from legacy session-peer secrets and permissions.\n * A fresh signed ephemeral exchange uses the host key in the verified C6 roster.\n * Coordinator availability is irrelevant. Roster removal or rotation fences all\n * existing channel uses; applications must sync and persist C6 before exposing it.\n */\nexport function createRosterPeerLink(ports: RosterPeerLinkPorts): RosterPeerLinks {\n const consumed = new Map<string, number>();\n function check(proof: SignedRosterLinkProof): RosterLinkProof {\n const snapshot = ports.roster();\n const payload = proof.payload;\n const host = snapshot.hosts.find((h) => h.hostId === payload.hostId);\n if (\n !host ||\n payload.hostId === ports.hostId ||\n payload.destinationHostId !== ports.hostId ||\n payload.networkId !== snapshot.networkId ||\n payload.epoch !== snapshot.epoch ||\n !payload.publicKey ||\n !payload.challenge ||\n typeof payload.echo !== 'string' ||\n payload.expiresAt - payload.issuedAt > LINK_TTL ||\n !verifyEnvelope(host.publicKey, 'po/host-request/v1', proof, ports.now())\n )\n throw new Error('Roster link refused');\n return payload;\n }\n function wrap(channel: SealedChannel, hostId: string, epoch: number): RosterPeerChannel {\n const snapshot = ports.roster();\n const remote = snapshot.hosts.find((h) => h.hostId === hostId)?.publicKey;\n const local = snapshot.hosts.find((h) => h.hostId === ports.hostId)?.publicKey;\n const valid = () => {\n const current = ports.roster();\n return (\n !!remote &&\n !!local &&\n current.networkId === snapshot.networkId &&\n current.epoch === epoch &&\n current.hosts.some((h) => h.hostId === hostId && h.publicKey === remote) &&\n current.hosts.some((h) => h.hostId === ports.hostId && h.publicKey === local)\n );\n };\n return {\n seal(plaintext) {\n if (!valid()) return { ok: false, failure: 'auth' };\n return channel.seal(plaintext);\n },\n async open(envelope) {\n if (!valid()) return undefined;\n const opened = channel.open(envelope);\n if (!opened.ok || !(await ports.verifyRequest(opened.plaintext, hostId)) || !valid()) return undefined;\n return opened.plaintext;\n },\n };\n }\n return {\n async connect(hostId, token, exchange) {\n const snapshot = ports.roster();\n if (!snapshot.hosts.some((h) => h.hostId === ports.hostId) || !snapshot.hosts.some((h) => h.hostId === hostId))\n throw new Error('Host is not in roster');\n const handshake = createClientHandshake();\n const issuedAt = ports.now();\n const payload: RosterLinkProof = {\n networkId: snapshot.networkId,\n epoch: snapshot.epoch,\n hostId: ports.hostId,\n destinationHostId: hostId,\n publicKey: handshake.publicKey,\n challenge: crypto.randomUUID(),\n echo: '',\n issuedAt,\n expiresAt: issuedAt + LINK_TTL,\n };\n const reply = check(await exchange(ports.sign(payload), token));\n if (\n reply.hostId !== hostId ||\n reply.challenge !== payload.challenge ||\n reply.echo !== payload.publicKey ||\n reply.epoch !== payload.epoch\n )\n throw new Error('Roster link response mismatch');\n const channel = handshake.accept(reply.publicKey);\n if (!channel) throw new Error('Invalid roster channel');\n return wrap(channel, hostId, payload.epoch);\n },\n async accept(proof, token) {\n const payload = check(proof);\n if (payload.echo !== '' || !(await ports.authorize(token, payload.hostId, payload.networkId)))\n throw new Error('Roster link denied');\n // Authorization may await a roster sync. Recheck before committing the link.\n check(proof);\n for (const [id, expiry] of consumed) if (expiry <= ports.now()) consumed.delete(id);\n const id = JSON.stringify([payload.hostId, payload.challenge]);\n if (consumed.has(id) || consumed.size >= 1024) throw new Error('Roster link replayed');\n consumed.set(id, payload.expiresAt);\n const handshake = createHostHandshake();\n const channel = handshake.accept(payload.publicKey);\n if (!channel) throw new Error('Invalid roster channel');\n const issuedAt = ports.now();\n return {\n proof: ports.sign({\n ...payload,\n hostId: ports.hostId,\n destinationHostId: payload.hostId,\n publicKey: handshake.publicKey,\n echo: payload.publicKey,\n issuedAt,\n expiresAt: issuedAt + LINK_TTL,\n }),\n channel: wrap(channel, payload.hostId, payload.epoch),\n };\n },\n };\n}\n"],"mappings":";;;;;;;AAUA,MAAa,8BAA8B;AAC3C,MAAa,8BAA8B;AAE3C,SAAgB,6BAA6B,OAAqB;CAChE,IAAI,SAAA,GACF,MAAM,IAAI,MAAM,qDAAkF;AACtG;AAEA,SAAgB,4BACd,mBACA,iBACA,WACA,gBACM;CACN,IAAI,cAAc,KAAA,KAAa,UAAU,cAAc,SAAS,UAAU,YAAY,KAAA,GACpF,MAAM,IAAI,MAAM,sCA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