@agimon-ai/po 0.0.0-alpha.123 → 0.0.0-alpha.125

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.
@@ -2,7 +2,7 @@
2
2
  "version": 1,
3
3
  "packages": {
4
4
  "@agimon-ai/po": {
5
- "version": "0.0.0-alpha.123",
5
+ "version": "0.0.0-alpha.125",
6
6
  "dependencies": [
7
7
  "@agimon-ai/po-approval",
8
8
  "@agimon-ai/po-artifact",
@@ -28,14 +28,14 @@
28
28
  ]
29
29
  },
30
30
  "@agimon-ai/po-approval": {
31
- "version": "0.0.0-alpha.122",
31
+ "version": "0.0.0-alpha.124",
32
32
  "dependencies": [
33
33
  "@agimon-ai/po-core",
34
34
  "@agimon-ai/po-web-components"
35
35
  ]
36
36
  },
37
37
  "@agimon-ai/po-artifact": {
38
- "version": "0.0.0-alpha.121",
38
+ "version": "0.0.0-alpha.123",
39
39
  "dependencies": [
40
40
  "@agimon-ai/po-core",
41
41
  "@agimon-ai/po-web-components",
@@ -43,7 +43,7 @@
43
43
  ]
44
44
  },
45
45
  "@agimon-ai/po-author": {
46
- "version": "0.0.0-alpha.122",
46
+ "version": "0.0.0-alpha.124",
47
47
  "dependencies": [
48
48
  "@agimon-ai/po-artifact",
49
49
  "@agimon-ai/po-core",
@@ -53,7 +53,7 @@
53
53
  ]
54
54
  },
55
55
  "@agimon-ai/po-autocompact": {
56
- "version": "0.0.0-alpha.122",
56
+ "version": "0.0.0-alpha.124",
57
57
  "dependencies": [
58
58
  "@agimon-ai/po-artifact",
59
59
  "@agimon-ai/po-config",
@@ -62,13 +62,13 @@
62
62
  ]
63
63
  },
64
64
  "@agimon-ai/po-autostop": {
65
- "version": "0.0.0-alpha.122",
65
+ "version": "0.0.0-alpha.124",
66
66
  "dependencies": [
67
67
  "@agimon-ai/po-core"
68
68
  ]
69
69
  },
70
70
  "@agimon-ai/po-browse": {
71
- "version": "0.0.1-alpha.120",
71
+ "version": "0.0.1-alpha.122",
72
72
  "dependencies": [
73
73
  "@agimon-ai/po-config",
74
74
  "@agimon-ai/po-core",
@@ -76,11 +76,11 @@
76
76
  ]
77
77
  },
78
78
  "@agimon-ai/po-build": {
79
- "version": "0.0.0-alpha.122",
79
+ "version": "0.0.0-alpha.124",
80
80
  "dependencies": []
81
81
  },
82
82
  "@agimon-ai/po-cache": {
83
- "version": "0.0.0-alpha.122",
83
+ "version": "0.0.0-alpha.124",
84
84
  "dependencies": [
85
85
  "@agimon-ai/po-config",
86
86
  "@agimon-ai/po-core",
@@ -88,7 +88,7 @@
88
88
  ]
89
89
  },
90
90
  "@agimon-ai/po-calendar": {
91
- "version": "0.0.1-alpha.81",
91
+ "version": "0.0.1-alpha.83",
92
92
  "dependencies": [
93
93
  "@agimon-ai/po-config",
94
94
  "@agimon-ai/po-core",
@@ -100,11 +100,11 @@
100
100
  ]
101
101
  },
102
102
  "@agimon-ai/po-claude-bridge": {
103
- "version": "0.1.1-alpha.102",
103
+ "version": "0.1.1-alpha.104",
104
104
  "dependencies": []
105
105
  },
106
106
  "@agimon-ai/po-codemode": {
107
- "version": "0.0.1-alpha.95",
107
+ "version": "0.0.1-alpha.97",
108
108
  "dependencies": [
109
109
  "@agimon-ai/po-config",
110
110
  "@agimon-ai/po-core",
@@ -112,7 +112,7 @@
112
112
  ]
113
113
  },
114
114
  "@agimon-ai/po-computer-use": {
115
- "version": "0.0.0-alpha.122",
115
+ "version": "0.0.0-alpha.124",
116
116
  "dependencies": [
117
117
  "@agimon-ai/po-config",
118
118
  "@agimon-ai/po-core",
@@ -122,26 +122,26 @@
122
122
  ]
123
123
  },
124
124
  "@agimon-ai/po-config": {
125
- "version": "0.0.0-alpha.122",
125
+ "version": "0.0.0-alpha.124",
126
126
  "dependencies": [
127
127
  "@agimon-ai/po-core",
128
128
  "@agimon-ai/po-web-components"
129
129
  ]
130
130
  },
131
131
  "@agimon-ai/po-core": {
132
- "version": "0.0.0-alpha.122",
132
+ "version": "0.0.0-alpha.124",
133
133
  "dependencies": [
134
134
  "@agimon-ai/po-web-security"
135
135
  ]
136
136
  },
137
137
  "@agimon-ai/po-db": {
138
- "version": "0.0.0-alpha.122",
138
+ "version": "0.0.0-alpha.124",
139
139
  "dependencies": [
140
140
  "@agimon-ai/po-core"
141
141
  ]
142
142
  },
143
143
  "@agimon-ai/po-domain": {
144
- "version": "0.0.0-alpha.122",
144
+ "version": "0.0.0-alpha.124",
145
145
  "dependencies": [
146
146
  "@agimon-ai/po-config",
147
147
  "@agimon-ai/po-core",
@@ -151,7 +151,7 @@
151
151
  ]
152
152
  },
153
153
  "@agimon-ai/po-edit": {
154
- "version": "0.0.0-alpha.122",
154
+ "version": "0.0.0-alpha.124",
155
155
  "dependencies": [
156
156
  "@agimon-ai/po-core",
157
157
  "@agimon-ai/po-hashline",
@@ -160,7 +160,7 @@
160
160
  ]
161
161
  },
162
162
  "@agimon-ai/po-file-edit": {
163
- "version": "0.0.0-alpha.122",
163
+ "version": "0.0.0-alpha.124",
164
164
  "dependencies": [
165
165
  "@agimon-ai/po-config",
166
166
  "@agimon-ai/po-core",
@@ -170,13 +170,13 @@
170
170
  ]
171
171
  },
172
172
  "@agimon-ai/po-gateway": {
173
- "version": "0.0.1-alpha.1",
173
+ "version": "0.0.1-alpha.3",
174
174
  "dependencies": [
175
175
  "@agimon-ai/po-core"
176
176
  ]
177
177
  },
178
178
  "@agimon-ai/po-git": {
179
- "version": "0.0.0-alpha.122",
179
+ "version": "0.0.0-alpha.124",
180
180
  "dependencies": [
181
181
  "@agimon-ai/po-core",
182
182
  "@agimon-ai/po-session",
@@ -185,7 +185,7 @@
185
185
  ]
186
186
  },
187
187
  "@agimon-ai/po-goal": {
188
- "version": "0.0.0-alpha.122",
188
+ "version": "0.0.0-alpha.124",
189
189
  "dependencies": [
190
190
  "@agimon-ai/po-core",
191
191
  "@agimon-ai/po-minor-mode",
@@ -194,7 +194,7 @@
194
194
  ]
195
195
  },
196
196
  "@agimon-ai/po-grep": {
197
- "version": "0.0.0-alpha.122",
197
+ "version": "0.0.0-alpha.124",
198
198
  "dependencies": [
199
199
  "@agimon-ai/po-core",
200
200
  "@agimon-ai/po-hashline",
@@ -203,11 +203,11 @@
203
203
  ]
204
204
  },
205
205
  "@agimon-ai/po-hashline": {
206
- "version": "0.0.0-alpha.122",
206
+ "version": "0.0.0-alpha.124",
207
207
  "dependencies": []
208
208
  },
209
209
  "@agimon-ai/po-help": {
210
- "version": "0.0.0-alpha.122",
210
+ "version": "0.0.0-alpha.124",
211
211
  "dependencies": [
212
212
  "@agimon-ai/po-core",
213
213
  "@agimon-ai/po-minor-mode",
@@ -216,14 +216,14 @@
216
216
  ]
217
217
  },
218
218
  "@agimon-ai/po-identity": {
219
- "version": "0.0.2-alpha.69",
219
+ "version": "0.0.2-alpha.71",
220
220
  "dependencies": [
221
221
  "@agimon-ai/po-core",
222
222
  "@agimon-ai/po-web-security"
223
223
  ]
224
224
  },
225
225
  "@agimon-ai/po-image-gen": {
226
- "version": "0.0.0-alpha.121",
226
+ "version": "0.0.0-alpha.123",
227
227
  "dependencies": [
228
228
  "@agimon-ai/po-core",
229
229
  "@agimon-ai/po-web-components",
@@ -231,7 +231,7 @@
231
231
  ]
232
232
  },
233
233
  "@agimon-ai/po-ios": {
234
- "version": "0.0.1-alpha.57",
234
+ "version": "0.0.1-alpha.59",
235
235
  "dependencies": [
236
236
  "@agimon-ai/po-artifact",
237
237
  "@agimon-ai/po-config",
@@ -241,7 +241,7 @@
241
241
  ]
242
242
  },
243
243
  "@agimon-ai/po-log": {
244
- "version": "0.0.0-alpha.122",
244
+ "version": "0.0.0-alpha.124",
245
245
  "dependencies": [
246
246
  "@agimon-ai/po-core",
247
247
  "@agimon-ai/po-web-components",
@@ -249,7 +249,7 @@
249
249
  ]
250
250
  },
251
251
  "@agimon-ai/po-major-mode": {
252
- "version": "0.0.0-alpha.122",
252
+ "version": "0.0.0-alpha.124",
253
253
  "dependencies": [
254
254
  "@agimon-ai/po-config",
255
255
  "@agimon-ai/po-core",
@@ -257,7 +257,7 @@
257
257
  ]
258
258
  },
259
259
  "@agimon-ai/po-mcp": {
260
- "version": "0.0.0-alpha.122",
260
+ "version": "0.0.0-alpha.124",
261
261
  "dependencies": [
262
262
  "@agimon-ai/po-config",
263
263
  "@agimon-ai/po-core",
@@ -268,44 +268,44 @@
268
268
  ]
269
269
  },
270
270
  "@agimon-ai/po-mcp-proxy": {
271
- "version": "0.0.1-alpha.101",
271
+ "version": "0.0.1-alpha.103",
272
272
  "dependencies": []
273
273
  },
274
274
  "@agimon-ai/po-minor-mode": {
275
- "version": "0.0.0-alpha.122",
275
+ "version": "0.0.0-alpha.124",
276
276
  "dependencies": [
277
277
  "@agimon-ai/po-core"
278
278
  ]
279
279
  },
280
280
  "@agimon-ai/po-model-guidance": {
281
- "version": "0.0.0-alpha.122",
281
+ "version": "0.0.0-alpha.124",
282
282
  "dependencies": [
283
283
  "@agimon-ai/po-config",
284
284
  "@agimon-ai/po-core"
285
285
  ]
286
286
  },
287
287
  "@agimon-ai/po-native-components": {
288
- "version": "0.0.0-alpha.122",
288
+ "version": "0.0.0-alpha.124",
289
289
  "dependencies": [
290
290
  "@agimon-ai/po-web-components"
291
291
  ]
292
292
  },
293
293
  "@agimon-ai/po-network": {
294
- "version": "0.0.2-alpha.69",
294
+ "version": "0.0.2-alpha.71",
295
295
  "dependencies": [
296
296
  "@agimon-ai/po-core",
297
297
  "@agimon-ai/po-web-security"
298
298
  ]
299
299
  },
300
300
  "@agimon-ai/po-notification": {
301
- "version": "0.0.0-alpha.122",
301
+ "version": "0.0.0-alpha.124",
302
302
  "dependencies": [
303
303
  "@agimon-ai/po-autostop",
304
304
  "@agimon-ai/po-core"
305
305
  ]
306
306
  },
307
307
  "@agimon-ai/po-plan": {
308
- "version": "0.0.0-alpha.122",
308
+ "version": "0.0.0-alpha.124",
309
309
  "dependencies": [
310
310
  "@agimon-ai/po-config",
311
311
  "@agimon-ai/po-core",
@@ -315,7 +315,7 @@
315
315
  ]
316
316
  },
317
317
  "@agimon-ai/po-profile": {
318
- "version": "0.0.0-alpha.122",
318
+ "version": "0.0.0-alpha.124",
319
319
  "dependencies": [
320
320
  "@agimon-ai/po-config",
321
321
  "@agimon-ai/po-core",
@@ -323,7 +323,7 @@
323
323
  ]
324
324
  },
325
325
  "@agimon-ai/po-prompt": {
326
- "version": "0.0.0-alpha.122",
326
+ "version": "0.0.0-alpha.124",
327
327
  "dependencies": [
328
328
  "@agimon-ai/po-core",
329
329
  "@agimon-ai/po-web-components",
@@ -331,7 +331,7 @@
331
331
  ]
332
332
  },
333
333
  "@agimon-ai/po-read": {
334
- "version": "0.0.0-alpha.122",
334
+ "version": "0.0.0-alpha.124",
335
335
  "dependencies": [
336
336
  "@agimon-ai/po-config",
337
337
  "@agimon-ai/po-core",
@@ -341,7 +341,7 @@
341
341
  ]
342
342
  },
343
343
  "@agimon-ai/po-runner": {
344
- "version": "0.0.0-alpha.122",
344
+ "version": "0.0.0-alpha.124",
345
345
  "dependencies": [
346
346
  "@agimon-ai/po-core",
347
347
  "@agimon-ai/po-ui",
@@ -350,13 +350,13 @@
350
350
  ]
351
351
  },
352
352
  "@agimon-ai/po-sandbox": {
353
- "version": "0.0.0-alpha.122",
353
+ "version": "0.0.0-alpha.124",
354
354
  "dependencies": [
355
355
  "@agimon-ai/po-core"
356
356
  ]
357
357
  },
358
358
  "@agimon-ai/po-session": {
359
- "version": "0.0.0-alpha.122",
359
+ "version": "0.0.0-alpha.124",
360
360
  "dependencies": [
361
361
  "@agimon-ai/po-config",
362
362
  "@agimon-ai/po-core",
@@ -364,7 +364,7 @@
364
364
  ]
365
365
  },
366
366
  "@agimon-ai/po-skill": {
367
- "version": "0.0.0-alpha.122",
367
+ "version": "0.0.0-alpha.124",
368
368
  "dependencies": [
369
369
  "@agimon-ai/po-config",
370
370
  "@agimon-ai/po-core",
@@ -373,7 +373,7 @@
373
373
  ]
374
374
  },
375
375
  "@agimon-ai/po-style-system": {
376
- "version": "0.0.0-alpha.122",
376
+ "version": "0.0.0-alpha.124",
377
377
  "dependencies": [
378
378
  "@agimon-ai/po-core",
379
379
  "@agimon-ai/po-web-components",
@@ -381,7 +381,7 @@
381
381
  ]
382
382
  },
383
383
  "@agimon-ai/po-task": {
384
- "version": "0.0.0-alpha.122",
384
+ "version": "0.0.0-alpha.124",
385
385
  "dependencies": [
386
386
  "@agimon-ai/po-core",
387
387
  "@agimon-ai/po-ui",
@@ -389,7 +389,7 @@
389
389
  ]
390
390
  },
391
391
  "@agimon-ai/po-team": {
392
- "version": "0.0.0-alpha.122",
392
+ "version": "0.0.0-alpha.124",
393
393
  "dependencies": [
394
394
  "@agimon-ai/po-cache",
395
395
  "@agimon-ai/po-config",
@@ -401,7 +401,7 @@
401
401
  ]
402
402
  },
403
403
  "@agimon-ai/po-template-advanced": {
404
- "version": "0.0.0-alpha.122",
404
+ "version": "0.0.0-alpha.124",
405
405
  "dependencies": [
406
406
  "@agimon-ai/po-core",
407
407
  "@agimon-ai/po-web-components",
@@ -409,7 +409,7 @@
409
409
  ]
410
410
  },
411
411
  "@agimon-ai/po-template-elegant": {
412
- "version": "0.0.0-alpha.122",
412
+ "version": "0.0.0-alpha.124",
413
413
  "dependencies": [
414
414
  "@agimon-ai/po-core",
415
415
  "@agimon-ai/po-web-components",
@@ -417,7 +417,7 @@
417
417
  ]
418
418
  },
419
419
  "@agimon-ai/po-ui": {
420
- "version": "0.0.0-alpha.122",
420
+ "version": "0.0.0-alpha.124",
421
421
  "dependencies": [
422
422
  "@agimon-ai/po-core",
423
423
  "@agimon-ai/po-hashline",
@@ -426,7 +426,7 @@
426
426
  ]
427
427
  },
428
428
  "@agimon-ai/po-user-feedback": {
429
- "version": "0.0.0-alpha.122",
429
+ "version": "0.0.0-alpha.124",
430
430
  "dependencies": [
431
431
  "@agimon-ai/po-core",
432
432
  "@agimon-ai/po-minor-mode",
@@ -435,7 +435,7 @@
435
435
  ]
436
436
  },
437
437
  "@agimon-ai/po-vault": {
438
- "version": "0.0.0-alpha.122",
438
+ "version": "0.0.0-alpha.124",
439
439
  "dependencies": [
440
440
  "@agimon-ai/po-core",
441
441
  "@agimon-ai/po-db",
@@ -444,7 +444,7 @@
444
444
  ]
445
445
  },
446
446
  "@agimon-ai/po-vibe-lint": {
447
- "version": "0.0.1-alpha.91",
447
+ "version": "0.0.1-alpha.93",
448
448
  "dependencies": [
449
449
  "@agimon-ai/po-config",
450
450
  "@agimon-ai/po-core",
@@ -454,7 +454,7 @@
454
454
  ]
455
455
  },
456
456
  "@agimon-ai/po-voice": {
457
- "version": "0.0.0-alpha.122",
457
+ "version": "0.0.0-alpha.124",
458
458
  "dependencies": [
459
459
  "@agimon-ai/po-config",
460
460
  "@agimon-ai/po-core",
@@ -467,11 +467,11 @@
467
467
  ]
468
468
  },
469
469
  "@agimon-ai/po-web-components": {
470
- "version": "0.0.0-alpha.122",
470
+ "version": "0.0.0-alpha.124",
471
471
  "dependencies": []
472
472
  },
473
473
  "@agimon-ai/po-web-dashboard": {
474
- "version": "0.0.0-alpha.122",
474
+ "version": "0.0.0-alpha.124",
475
475
  "dependencies": [
476
476
  "@agimon-ai/po-core",
477
477
  "@agimon-ai/po-web-components",
@@ -479,18 +479,18 @@
479
479
  ]
480
480
  },
481
481
  "@agimon-ai/po-web-search": {
482
- "version": "0.0.0-alpha.121",
482
+ "version": "0.0.0-alpha.123",
483
483
  "dependencies": [
484
484
  "@agimon-ai/po-core",
485
485
  "@agimon-ai/po-web-components"
486
486
  ]
487
487
  },
488
488
  "@agimon-ai/po-web-security": {
489
- "version": "0.0.0-alpha.122",
489
+ "version": "0.0.0-alpha.124",
490
490
  "dependencies": []
491
491
  },
492
492
  "@agimon-ai/po-workflow": {
493
- "version": "0.0.0-alpha.122",
493
+ "version": "0.0.0-alpha.124",
494
494
  "dependencies": [
495
495
  "@agimon-ai/po-core",
496
496
  "@agimon-ai/po-ui",
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.0.0-alpha.123";
2
+ var version = "0.0.0-alpha.125";
3
3
  //#endregion
4
4
  Object.defineProperty(exports, "version", {
5
5
  enumerable: true,
package/dist/package.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.0.0-alpha.123";
2
+ var version = "0.0.0-alpha.125";
3
3
  //#endregion
4
4
  export { version };
5
5
 
@@ -12,12 +12,13 @@ function createCoordinatorService(options) {
12
12
  const homeWorkspace = () => options.workspaces().find((workspace) => workspace.kind === "session");
13
13
  /** Live sessions first, so a live coordinator's record is never mistaken for a dormant one. Oldest wins. */
14
14
  const coordinatorsIn = (workspaceId) => {
15
- const live = options.liveSessions().filter((session) => session.sessionProvenance === _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE && session.workspaceId === workspaceId).map((session) => ({
15
+ const liveSessions = options.liveSessions();
16
+ const live = liveSessions.filter((session) => session.sessionProvenance === _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE && session.workspaceId === workspaceId).map((session) => ({
16
17
  sessionId: session.id,
17
18
  createdAt: session.createdAt,
18
19
  live: true
19
20
  }));
20
- const dormant = options.records().filter((record) => record.sessionProvenance === _agimon_ai_po_core_hubChannel.COORDINATOR_SESSION_PROVENANCE && record.workspaceId === workspaceId && !live.some((session) => session.sessionId === record.sessionId)).map((record) => ({
21
+ 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) => ({
21
22
  sessionId: record.sessionId,
22
23
  createdAt: record.createdAt,
23
24
  live: false
@@ -142,11 +143,16 @@ function createCoordinatorService(options) {
142
143
  const name = request.name.trim();
143
144
  const brief = request.brief.trim();
144
145
  if (name === "" || brief === "") throw new Error("A started session needs a name and a brief.");
146
+ if (request.workspaceId !== void 0 && (typeof request.workspaceId !== "string" || request.workspaceId.trim() === "")) throw new Error("A target workspace ID must be non-empty text.");
147
+ const workspace = options.workspaces().find((entry) => entry.id === (request.workspaceId ?? caller.workspaceId));
148
+ if (workspace === void 0 || workspace.available === false || workspace.sandbox !== void 0) throw new Error("The target workspace is unavailable.");
149
+ if (workspace.id !== caller.workspaceId) {
150
+ if (caller.workspaceId !== homeWorkspace()?.id || workspace.kind === "session") throw new Error("Only the home coordinator can target another workspace.");
151
+ if (oldestCoordinator(workspace.id) !== void 0) throw new Error("This workspace has a coordinator. Ask it to start the session.");
152
+ }
145
153
  const at = now();
146
154
  const recent = (starts.get(coordinatorSessionId) ?? []).filter((time) => at - time < HOUR_MS);
147
155
  if (recent.length >= 5) throw new Error(`A coordinator can start at most 5 sessions an hour.`);
148
- const workspace = options.workspaces().find((entry) => entry.id === caller.workspaceId);
149
- if (workspace === void 0) throw new Error("The coordinator workspace is unavailable.");
150
156
  starts.set(coordinatorSessionId, [...recent, at]);
151
157
  const { sessionId } = workspace.kind === "session" ? await options.createGeneral({ name }) : await options.createInWorkspace(workspace, { name });
152
158
  await options.prompt(sessionId, brief);
@@ -1 +1 @@
1
- {"version":3,"file":"coordinators.cjs","names":["COORDINATOR_SESSION_PROVENANCE"],"sources":["../../../../src/builders/server/coordinators.ts"],"sourcesContent":["import type { OpenSessionRecord } from '@agimon-ai/po-core/history';\nimport { COORDINATOR_SESSION_PROVENANCE } from '@agimon-ai/po-core/hubChannel';\nimport type { PoHubSessionSelection } from '@agimon-ai/po-core/hubChannel';\n\n/** ponytail: a fixed per-coordinator budget; move it to team limits config when someone needs another number. */\nexport const COORDINATOR_STARTS_PER_HOUR = 5;\nconst HOUR_MS = 60 * 60 * 1000;\nconst FALLBACK_SLUG = 'workspace';\n\n/** The persona every coordinator of one person shares. */\nexport interface CoordinatorSettings {\n readonly profile: string;\n readonly model?: string;\n readonly name: string;\n}\n\nexport interface CoordinatorResult {\n readonly sessionId: string;\n readonly created: boolean;\n}\n\ninterface CoordinatorWorkspace {\n readonly id: string;\n readonly kind?: 'session';\n readonly root: string;\n readonly name?: string;\n readonly available?: boolean;\n readonly sandbox?: string;\n}\n\ninterface CoordinatorLiveSession {\n readonly id: string;\n readonly name?: string;\n readonly workspaceId?: string;\n readonly sessionProvenance?: string;\n readonly createdAt: string;\n readonly profile?: { readonly name: string };\n}\n\nexport interface CoordinatorCreateRequest {\n readonly name: string;\n readonly sessionProvenance?: string;\n readonly selection?: PoHubSessionSelection;\n readonly model?: string;\n}\n\nexport interface CoordinatorServiceOptions {\n liveSessions(): readonly CoordinatorLiveSession[];\n /** Every open-session record this host keeps, live or dormant. */\n records(): readonly OpenSessionRecord[];\n saveRecord(record: OpenSessionRecord): boolean;\n workspaces(): readonly CoordinatorWorkspace[];\n revive(record: OpenSessionRecord): Promise<void>;\n /** A session in the general (`kind: 'session'`) workspace, in a folder the host allocates. */\n createGeneral(request: CoordinatorCreateRequest): Promise<{ sessionId: string }>;\n createInWorkspace(workspace: CoordinatorWorkspace, request: CoordinatorCreateRequest): Promise<{ sessionId: string }>;\n prompt(sessionId: string, text: string): Promise<unknown>;\n /** The profile catalog's default under this root, or the personal one when no root is given. */\n defaultProfile(root?: string): string | undefined;\n /** Closes a live session and reopens it under the same id with this provenance, and this profile when given. */\n reopen(sessionId: string, role: { sessionProvenance?: string; profile?: string }): Promise<void>;\n now?(): number;\n notice(message: string): void;\n}\n\nexport interface CoordinatorService {\n /**\n * Finds the oldest live or dormant coordinator of the target (`'home'` or a workspace id), revives it, or creates\n * one. Single-flight per target.\n */\n ensureCoordinator(target: string, settings: CoordinatorSettings): Promise<CoordinatorResult>;\n /** Ensures the home coordinator, then a coordinator in every existing workspace with the same persona. */\n ensureHome(settings: CoordinatorSettings): Promise<CoordinatorResult>;\n /** A new workspace gets a coordinator only once a home coordinator exists. */\n workspaceAdmitted(workspaceId: string): Promise<void>;\n /** Starts a briefed session in the calling coordinator's own workspace. */\n startSession(coordinatorSessionId: string, request: { name: string; brief: string }): Promise<{ sessionId: string }>;\n /**\n * The person's explicit add: the home coordinator when no workspace is named, else that workspace's. The persona\n * is the home coordinator's when one is recorded, else the default profile.\n */\n add(workspaceId?: string): Promise<CoordinatorResult>;\n /**\n * Promotes a session to its workspace's coordinator, demoting any other one, or demotes it. A live session\n * restarts to take on its role; a dormant one being demoted only has its record rewritten.\n */\n setRole(sessionId: string, coordinator: boolean): Promise<void>;\n}\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 live = options\n .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 !live.some((session) => session.sessionId === 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 }\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 defaultPersona = (root?: string): CoordinatorSettings => {\n const profile = options.defaultProfile(root);\n if (profile === undefined) throw new Error('Choose a default profile before adding a coordinator.');\n return { profile, name: profile };\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 const ensureHome = async (settings: CoordinatorSettings): Promise<CoordinatorResult> => {\n const home = await ensureCoordinator('home', settings);\n const outcomes = await Promise.allSettled(\n options\n .workspaces()\n .filter(coordinated)\n .map((workspace) => ensureCoordinator(workspace.id, workspaceSettings(workspace, settings))),\n );\n for (const outcome of outcomes)\n if (outcome.status === 'rejected')\n options.notice(`A workspace coordinator could not be opened: ${String(outcome.reason)}`);\n return home;\n };\n\n return {\n ensureCoordinator,\n ensureHome,\n async workspaceAdmitted(workspaceId) {\n const workspace = options.workspaces().find((entry) => entry.id === workspaceId);\n const general = homeWorkspace();\n if (workspace === undefined || general === undefined || !coordinated(workspace)) return;\n const home = oldestCoordinator(general.id);\n if (home === undefined) return;\n const persona = options.records().find((record) => record.sessionId === home.sessionId)?.coordinator;\n if (persona === undefined) {\n options.notice(\n `Home coordinator '${home.sessionId}' has no recorded persona; workspace '${workspaceId}' gets none.`,\n );\n return;\n }\n await ensureCoordinator(workspaceId, workspaceSettings(workspace, persona));\n },\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 const at = now();\n const recent = (starts.get(coordinatorSessionId) ?? []).filter((time) => at - time < HOUR_MS);\n if (recent.length >= COORDINATOR_STARTS_PER_HOUR)\n throw new Error(`A coordinator can start at most ${COORDINATOR_STARTS_PER_HOUR} sessions an hour.`);\n const workspace = options.workspaces().find((entry) => entry.id === caller.workspaceId);\n if (workspace === undefined) throw new Error('The coordinator workspace is unavailable.');\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 await options.prompt(sessionId, brief);\n return { sessionId };\n },\n async add(workspaceId) {\n if (workspaceId === undefined) return ensureHome(homePersona() ?? defaultPersona());\n const workspace = options.workspaces().find((entry) => entry.id === workspaceId);\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 return ensureCoordinator(\n workspaceId,\n workspaceSettings(workspace, homePersona() ?? defaultPersona(workspace.root)),\n );\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 // 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 (workspace === undefined || (workspace.kind !== 'session' && !coordinated(workspace)))\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"],"mappings":";AAMA,MAAM,UAAU;AAChB,MAAM,gBAAgB;;AAmFtB,SAAgB,cAAc,WAAsE;CAMlG,QALe,UAAU,MAAM,KAAK,KAAK,UAAU,KAAK,MAAM,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,IAAI,KAAK,GAAA,CAE9F,YAAY,CAAC,CACb,QAAQ,gBAAgB,GAAG,CAAC,CAC5B,QAAQ,aAAa,EACd,KAAK;AACjB;AAEA,SAAgB,yBAAyB,SAAwD;CAC/F,MAAM,0BAAU,IAAI,IAAwC;CAC5D,MAAM,yBAAS,IAAI,IAAsB;CACzC,MAAM,YAAoB,QAAQ,MAAM,KAAK,KAAK,IAAI;CAEtD,MAAM,sBACJ,QAAQ,WAAW,CAAC,CAAC,MAAM,cAAc,UAAU,SAAS,SAAS;;CAGvE,MAAM,kBAAkB,gBAAmF;EACzG,MAAM,OAAO,QACV,aAAa,CAAC,CACd,QACE,YACC,QAAQ,sBAAsBA,8BAAAA,kCAAkC,QAAQ,gBAAgB,WAC5F,CAAC,CAC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,CAAC,aAAa,OAAO,OAAO,SAAS;GAEzC,IAAI,QAAQ,sBAAsB,KAAA,GAChC,MAAM,IAAI,MAAM,KAAK,QAAQ,kBAAkB,sCAAsC;GACvF,MAAM,YAAY,QAAQ,WAAW,CAAC,CAAC,MAAM,UAAU,MAAM,OAAO,QAAQ,WAAW;GACvF,IAAI,cAAc,KAAA,KAAc,UAAU,SAAS,aAAa,CAAC,YAAY,SAAS,GACpF,MAAM,IAAI,MAAM,2CAA2C;GAC7D,KAAK,MAAM,SAAS,eAAe,UAAU,EAAE,GAAG,MAAM,OAAO,MAAM,SAAS;GAC9E,IAAI,SAAS,KAAA,GAAW;IACtB,MAAM,QAAQ,OAAO,MAAO;IAC5B,OAAO,QAAQ,aAAa,CAAC,CAAC,MAAM,YAAY,QAAQ,OAAO,SAAS;GAC1E;GAEA,MAAM,UAAU,MAAM,SAAS,QAAQ,QAAQ,eAAe,UAAU,IAAI;GAC5E,MAAM,QAAQ,OAAO,WAAW;IAC9B,mBAAmBA,8BAAAA;IACnB,GAAI,MAAM,YAAY,KAAA,KAAa,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;GAC5E,CAAC;GACD,IAAI,YAAY,KAAA,GAAW,cAAc,WAAW;IAAE;IAAS,MAAM,QAAQ,QAAQ;GAAQ,CAAC;QACzF,QAAQ,OAAO,gBAAgB,UAAU,4DAA4D;EAC5G;CACF;AACF"}
1
+ {"version":3,"file":"coordinators.cjs","names":["COORDINATOR_SESSION_PROVENANCE"],"sources":["../../../../src/builders/server/coordinators.ts"],"sourcesContent":["import type { OpenSessionRecord } from '@agimon-ai/po-core/history';\nimport { COORDINATOR_SESSION_PROVENANCE } from '@agimon-ai/po-core/hubChannel';\nimport type { PoHubSessionSelection } from '@agimon-ai/po-core/hubChannel';\n\n/** ponytail: a fixed per-coordinator budget; move it to team limits config when someone needs another number. */\nexport const COORDINATOR_STARTS_PER_HOUR = 5;\nconst HOUR_MS = 60 * 60 * 1000;\nconst FALLBACK_SLUG = 'workspace';\n\n/** The persona every coordinator of one person shares. */\nexport interface CoordinatorSettings {\n readonly profile: string;\n readonly model?: string;\n readonly name: string;\n}\n\nexport interface CoordinatorResult {\n readonly sessionId: string;\n readonly created: boolean;\n}\n\ninterface CoordinatorWorkspace {\n readonly id: string;\n readonly kind?: 'session';\n readonly root: string;\n readonly name?: string;\n readonly available?: boolean;\n readonly sandbox?: string;\n}\n\ninterface CoordinatorLiveSession {\n readonly id: string;\n readonly name?: string;\n readonly workspaceId?: string;\n readonly sessionProvenance?: string;\n readonly createdAt: string;\n readonly profile?: { readonly name: string };\n}\n\nexport interface CoordinatorCreateRequest {\n readonly name: string;\n readonly sessionProvenance?: string;\n readonly selection?: PoHubSessionSelection;\n readonly model?: string;\n}\n\nexport interface CoordinatorServiceOptions {\n liveSessions(): readonly CoordinatorLiveSession[];\n /** Every open-session record this host keeps, live or dormant. */\n records(): readonly OpenSessionRecord[];\n saveRecord(record: OpenSessionRecord): boolean;\n workspaces(): readonly CoordinatorWorkspace[];\n revive(record: OpenSessionRecord): Promise<void>;\n /** A session in the general (`kind: 'session'`) workspace, in a folder the host allocates. */\n createGeneral(request: CoordinatorCreateRequest): Promise<{ sessionId: string }>;\n createInWorkspace(workspace: CoordinatorWorkspace, request: CoordinatorCreateRequest): Promise<{ sessionId: string }>;\n prompt(sessionId: string, text: string): Promise<unknown>;\n /** The profile catalog's default under this root, or the personal one when no root is given. */\n defaultProfile(root?: string): string | undefined;\n /** Closes a live session and reopens it under the same id with this provenance, and this profile when given. */\n reopen(sessionId: string, role: { sessionProvenance?: string; profile?: string }): Promise<void>;\n now?(): number;\n notice(message: string): void;\n}\n\nexport interface CoordinatorService {\n /**\n * Finds the oldest live or dormant coordinator of the target (`'home'` or a workspace id), revives it, or creates\n * one. Single-flight per target.\n */\n ensureCoordinator(target: string, settings: CoordinatorSettings): Promise<CoordinatorResult>;\n /** Ensures the home coordinator, then a coordinator in every existing workspace with the same persona. */\n ensureHome(settings: CoordinatorSettings): Promise<CoordinatorResult>;\n /** A new workspace gets a coordinator only once a home coordinator exists. */\n workspaceAdmitted(workspaceId: string): Promise<void>;\n /** Starts a briefed session in the caller's scope, or an uncoordinated workspace targeted by the home coordinator. */\n startSession(\n coordinatorSessionId: string,\n request: { name: string; brief: string; workspaceId?: string },\n ): Promise<{ sessionId: string }>;\n /**\n * The person's explicit add: the home coordinator when no workspace is named, else that workspace's. The persona\n * is the home coordinator's when one is recorded, else the default profile.\n */\n add(workspaceId?: string): Promise<CoordinatorResult>;\n /**\n * Promotes a session to its workspace's coordinator, demoting any other one, or demotes it. A live session\n * restarts to take on its role; a dormant one being demoted only has its record rewritten.\n */\n setRole(sessionId: string, coordinator: boolean): Promise<void>;\n}\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 }\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 defaultPersona = (root?: string): CoordinatorSettings => {\n const profile = options.defaultProfile(root);\n if (profile === undefined) throw new Error('Choose a default profile before adding a coordinator.');\n return { profile, name: profile };\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 const ensureHome = async (settings: CoordinatorSettings): Promise<CoordinatorResult> => {\n const home = await ensureCoordinator('home', settings);\n const outcomes = await Promise.allSettled(\n options\n .workspaces()\n .filter(coordinated)\n .map((workspace) => ensureCoordinator(workspace.id, workspaceSettings(workspace, settings))),\n );\n for (const outcome of outcomes)\n if (outcome.status === 'rejected')\n options.notice(`A workspace coordinator could not be opened: ${String(outcome.reason)}`);\n return home;\n };\n\n return {\n ensureCoordinator,\n ensureHome,\n async workspaceAdmitted(workspaceId) {\n const workspace = options.workspaces().find((entry) => entry.id === workspaceId);\n const general = homeWorkspace();\n if (workspace === undefined || general === undefined || !coordinated(workspace)) return;\n const home = oldestCoordinator(general.id);\n if (home === undefined) return;\n const persona = options.records().find((record) => record.sessionId === home.sessionId)?.coordinator;\n if (persona === undefined) {\n options.notice(\n `Home coordinator '${home.sessionId}' has no recorded persona; workspace '${workspaceId}' gets none.`,\n );\n return;\n }\n await ensureCoordinator(workspaceId, workspaceSettings(workspace, persona));\n },\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 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 if (workspace === undefined || workspace.available === false || workspace.sandbox !== undefined)\n throw new Error('The target workspace is unavailable.');\n if (workspace.id !== caller.workspaceId) {\n if (caller.workspaceId !== homeWorkspace()?.id || workspace.kind === 'session')\n throw new Error('Only the home coordinator can target another workspace.');\n if (oldestCoordinator(workspace.id) !== undefined)\n throw new Error('This workspace has a coordinator. Ask it to start the session.');\n }\n const at = now();\n const recent = (starts.get(coordinatorSessionId) ?? []).filter((time) => at - time < HOUR_MS);\n if (recent.length >= COORDINATOR_STARTS_PER_HOUR)\n throw new Error(`A coordinator can start at most ${COORDINATOR_STARTS_PER_HOUR} sessions an hour.`);\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 await options.prompt(sessionId, brief);\n return { sessionId };\n },\n async add(workspaceId) {\n if (workspaceId === undefined) return ensureHome(homePersona() ?? defaultPersona());\n const workspace = options.workspaces().find((entry) => entry.id === workspaceId);\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 return ensureCoordinator(\n workspaceId,\n workspaceSettings(workspace, homePersona() ?? defaultPersona(workspace.root)),\n );\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 // 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 (workspace === undefined || (workspace.kind !== 'session' && !coordinated(workspace)))\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"],"mappings":";AAMA,MAAM,UAAU;AAChB,MAAM,gBAAgB;;AAsFtB,SAAgB,cAAc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AAS,aAAa,CAAC,YAAY,SAAS,GACpF,MAAM,IAAI,MAAM,2CAA2C;GAC7D,KAAK,MAAM,SAAS,eAAe,UAAU,EAAE,GAAG,MAAM,OAAO,MAAM,SAAS;GAC9E,IAAI,SAAS,KAAA,GAAW;IACtB,MAAM,QAAQ,OAAO,MAAO;IAC5B,OAAO,QAAQ,aAAa,CAAC,CAAC,MAAM,YAAY,QAAQ,OAAO,SAAS;GAC1E;GAEA,MAAM,UAAU,MAAM,SAAS,QAAQ,QAAQ,eAAe,UAAU,IAAI;GAC5E,MAAM,QAAQ,OAAO,WAAW;IAC9B,mBAAmBA,8BAAAA;IACnB,GAAI,MAAM,YAAY,KAAA,KAAa,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;GAC5E,CAAC;GACD,IAAI,YAAY,KAAA,GAAW,cAAc,WAAW;IAAE;IAAS,MAAM,QAAQ,QAAQ;GAAQ,CAAC;QACzF,QAAQ,OAAO,gBAAgB,UAAU,4DAA4D;EAC5G;CACF;AACF"}
@@ -12,12 +12,13 @@ function createCoordinatorService(options) {
12
12
  const homeWorkspace = () => options.workspaces().find((workspace) => workspace.kind === "session");
13
13
  /** Live sessions first, so a live coordinator's record is never mistaken for a dormant one. Oldest wins. */
14
14
  const coordinatorsIn = (workspaceId) => {
15
- const live = options.liveSessions().filter((session) => session.sessionProvenance === COORDINATOR_SESSION_PROVENANCE && session.workspaceId === workspaceId).map((session) => ({
15
+ const liveSessions = options.liveSessions();
16
+ const live = liveSessions.filter((session) => session.sessionProvenance === COORDINATOR_SESSION_PROVENANCE && session.workspaceId === workspaceId).map((session) => ({
16
17
  sessionId: session.id,
17
18
  createdAt: session.createdAt,
18
19
  live: true
19
20
  }));
20
- const dormant = options.records().filter((record) => record.sessionProvenance === COORDINATOR_SESSION_PROVENANCE && record.workspaceId === workspaceId && !live.some((session) => session.sessionId === record.sessionId)).map((record) => ({
21
+ const dormant = options.records().filter((record) => record.sessionProvenance === COORDINATOR_SESSION_PROVENANCE && record.workspaceId === workspaceId && !liveSessions.some((session) => session.id === record.sessionId)).map((record) => ({
21
22
  sessionId: record.sessionId,
22
23
  createdAt: record.createdAt,
23
24
  live: false
@@ -142,11 +143,16 @@ function createCoordinatorService(options) {
142
143
  const name = request.name.trim();
143
144
  const brief = request.brief.trim();
144
145
  if (name === "" || brief === "") throw new Error("A started session needs a name and a brief.");
146
+ if (request.workspaceId !== void 0 && (typeof request.workspaceId !== "string" || request.workspaceId.trim() === "")) throw new Error("A target workspace ID must be non-empty text.");
147
+ const workspace = options.workspaces().find((entry) => entry.id === (request.workspaceId ?? caller.workspaceId));
148
+ if (workspace === void 0 || workspace.available === false || workspace.sandbox !== void 0) throw new Error("The target workspace is unavailable.");
149
+ if (workspace.id !== caller.workspaceId) {
150
+ if (caller.workspaceId !== homeWorkspace()?.id || workspace.kind === "session") throw new Error("Only the home coordinator can target another workspace.");
151
+ if (oldestCoordinator(workspace.id) !== void 0) throw new Error("This workspace has a coordinator. Ask it to start the session.");
152
+ }
145
153
  const at = now();
146
154
  const recent = (starts.get(coordinatorSessionId) ?? []).filter((time) => at - time < HOUR_MS);
147
155
  if (recent.length >= 5) throw new Error(`A coordinator can start at most 5 sessions an hour.`);
148
- const workspace = options.workspaces().find((entry) => entry.id === caller.workspaceId);
149
- if (workspace === void 0) throw new Error("The coordinator workspace is unavailable.");
150
156
  starts.set(coordinatorSessionId, [...recent, at]);
151
157
  const { sessionId } = workspace.kind === "session" ? await options.createGeneral({ name }) : await options.createInWorkspace(workspace, { name });
152
158
  await options.prompt(sessionId, brief);
@@ -1 +1 @@
1
- {"version":3,"file":"coordinators.mjs","names":[],"sources":["../../../../src/builders/server/coordinators.ts"],"sourcesContent":["import type { OpenSessionRecord } from '@agimon-ai/po-core/history';\nimport { COORDINATOR_SESSION_PROVENANCE } from '@agimon-ai/po-core/hubChannel';\nimport type { PoHubSessionSelection } from '@agimon-ai/po-core/hubChannel';\n\n/** ponytail: a fixed per-coordinator budget; move it to team limits config when someone needs another number. */\nexport const COORDINATOR_STARTS_PER_HOUR = 5;\nconst HOUR_MS = 60 * 60 * 1000;\nconst FALLBACK_SLUG = 'workspace';\n\n/** The persona every coordinator of one person shares. */\nexport interface CoordinatorSettings {\n readonly profile: string;\n readonly model?: string;\n readonly name: string;\n}\n\nexport interface CoordinatorResult {\n readonly sessionId: string;\n readonly created: boolean;\n}\n\ninterface CoordinatorWorkspace {\n readonly id: string;\n readonly kind?: 'session';\n readonly root: string;\n readonly name?: string;\n readonly available?: boolean;\n readonly sandbox?: string;\n}\n\ninterface CoordinatorLiveSession {\n readonly id: string;\n readonly name?: string;\n readonly workspaceId?: string;\n readonly sessionProvenance?: string;\n readonly createdAt: string;\n readonly profile?: { readonly name: string };\n}\n\nexport interface CoordinatorCreateRequest {\n readonly name: string;\n readonly sessionProvenance?: string;\n readonly selection?: PoHubSessionSelection;\n readonly model?: string;\n}\n\nexport interface CoordinatorServiceOptions {\n liveSessions(): readonly CoordinatorLiveSession[];\n /** Every open-session record this host keeps, live or dormant. */\n records(): readonly OpenSessionRecord[];\n saveRecord(record: OpenSessionRecord): boolean;\n workspaces(): readonly CoordinatorWorkspace[];\n revive(record: OpenSessionRecord): Promise<void>;\n /** A session in the general (`kind: 'session'`) workspace, in a folder the host allocates. */\n createGeneral(request: CoordinatorCreateRequest): Promise<{ sessionId: string }>;\n createInWorkspace(workspace: CoordinatorWorkspace, request: CoordinatorCreateRequest): Promise<{ sessionId: string }>;\n prompt(sessionId: string, text: string): Promise<unknown>;\n /** The profile catalog's default under this root, or the personal one when no root is given. */\n defaultProfile(root?: string): string | undefined;\n /** Closes a live session and reopens it under the same id with this provenance, and this profile when given. */\n reopen(sessionId: string, role: { sessionProvenance?: string; profile?: string }): Promise<void>;\n now?(): number;\n notice(message: string): void;\n}\n\nexport interface CoordinatorService {\n /**\n * Finds the oldest live or dormant coordinator of the target (`'home'` or a workspace id), revives it, or creates\n * one. Single-flight per target.\n */\n ensureCoordinator(target: string, settings: CoordinatorSettings): Promise<CoordinatorResult>;\n /** Ensures the home coordinator, then a coordinator in every existing workspace with the same persona. */\n ensureHome(settings: CoordinatorSettings): Promise<CoordinatorResult>;\n /** A new workspace gets a coordinator only once a home coordinator exists. */\n workspaceAdmitted(workspaceId: string): Promise<void>;\n /** Starts a briefed session in the calling coordinator's own workspace. */\n startSession(coordinatorSessionId: string, request: { name: string; brief: string }): Promise<{ sessionId: string }>;\n /**\n * The person's explicit add: the home coordinator when no workspace is named, else that workspace's. The persona\n * is the home coordinator's when one is recorded, else the default profile.\n */\n add(workspaceId?: string): Promise<CoordinatorResult>;\n /**\n * Promotes a session to its workspace's coordinator, demoting any other one, or demotes it. A live session\n * restarts to take on its role; a dormant one being demoted only has its record rewritten.\n */\n setRole(sessionId: string, coordinator: boolean): Promise<void>;\n}\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 live = options\n .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 !live.some((session) => session.sessionId === 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 }\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 defaultPersona = (root?: string): CoordinatorSettings => {\n const profile = options.defaultProfile(root);\n if (profile === undefined) throw new Error('Choose a default profile before adding a coordinator.');\n return { profile, name: profile };\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 const ensureHome = async (settings: CoordinatorSettings): Promise<CoordinatorResult> => {\n const home = await ensureCoordinator('home', settings);\n const outcomes = await Promise.allSettled(\n options\n .workspaces()\n .filter(coordinated)\n .map((workspace) => ensureCoordinator(workspace.id, workspaceSettings(workspace, settings))),\n );\n for (const outcome of outcomes)\n if (outcome.status === 'rejected')\n options.notice(`A workspace coordinator could not be opened: ${String(outcome.reason)}`);\n return home;\n };\n\n return {\n ensureCoordinator,\n ensureHome,\n async workspaceAdmitted(workspaceId) {\n const workspace = options.workspaces().find((entry) => entry.id === workspaceId);\n const general = homeWorkspace();\n if (workspace === undefined || general === undefined || !coordinated(workspace)) return;\n const home = oldestCoordinator(general.id);\n if (home === undefined) return;\n const persona = options.records().find((record) => record.sessionId === home.sessionId)?.coordinator;\n if (persona === undefined) {\n options.notice(\n `Home coordinator '${home.sessionId}' has no recorded persona; workspace '${workspaceId}' gets none.`,\n );\n return;\n }\n await ensureCoordinator(workspaceId, workspaceSettings(workspace, persona));\n },\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 const at = now();\n const recent = (starts.get(coordinatorSessionId) ?? []).filter((time) => at - time < HOUR_MS);\n if (recent.length >= COORDINATOR_STARTS_PER_HOUR)\n throw new Error(`A coordinator can start at most ${COORDINATOR_STARTS_PER_HOUR} sessions an hour.`);\n const workspace = options.workspaces().find((entry) => entry.id === caller.workspaceId);\n if (workspace === undefined) throw new Error('The coordinator workspace is unavailable.');\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 await options.prompt(sessionId, brief);\n return { sessionId };\n },\n async add(workspaceId) {\n if (workspaceId === undefined) return ensureHome(homePersona() ?? defaultPersona());\n const workspace = options.workspaces().find((entry) => entry.id === workspaceId);\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 return ensureCoordinator(\n workspaceId,\n workspaceSettings(workspace, homePersona() ?? defaultPersona(workspace.root)),\n );\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 // 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 (workspace === undefined || (workspace.kind !== 'session' && !coordinated(workspace)))\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"],"mappings":";AAMA,MAAM,UAAU;AAChB,MAAM,gBAAgB;;AAmFtB,SAAgB,cAAc,WAAsE;CAMlG,QALe,UAAU,MAAM,KAAK,KAAK,UAAU,KAAK,MAAM,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,IAAI,KAAK,GAAA,CAE9F,YAAY,CAAC,CACb,QAAQ,gBAAgB,GAAG,CAAC,CAC5B,QAAQ,aAAa,EACd,KAAK;AACjB;AAEA,SAAgB,yBAAyB,SAAwD;CAC/F,MAAM,0BAAU,IAAI,IAAwC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Q,CAAC,CAAC,MAAM,UAAU,MAAM,cAAc,SAAS;GAC9E,MAAM,UAAU,SAAS,WAAW,KAAA,IAAY,KAAA,IAAY;IAAE,GAAG;IAAQ,IAAI,OAAO;GAAU;GAC9F,IAAI,SAAS,gBAAgB,KAAA,GAAW,MAAM,IAAI,MAAM,oBAAoB;GAC5E,IAAK,QAAQ,sBAAsB,mCAAoC,aAAa;GACpF,IAAI,CAAC,aAAa,OAAO,OAAO,SAAS;GAEzC,IAAI,QAAQ,sBAAsB,KAAA,GAChC,MAAM,IAAI,MAAM,KAAK,QAAQ,kBAAkB,sCAAsC;GACvF,MAAM,YAAY,QAAQ,WAAW,CAAC,CAAC,MAAM,UAAU,MAAM,OAAO,QAAQ,WAAW;GACvF,IAAI,cAAc,KAAA,KAAc,UAAU,SAAS,aAAa,CAAC,YAAY,SAAS,GACpF,MAAM,IAAI,MAAM,2CAA2C;GAC7D,KAAK,MAAM,SAAS,eAAe,UAAU,EAAE,GAAG,MAAM,OAAO,MAAM,SAAS;GAC9E,IAAI,SAAS,KAAA,GAAW;IACtB,MAAM,QAAQ,OAAO,MAAO;IAC5B,OAAO,QAAQ,aAAa,CAAC,CAAC,MAAM,YAAY,QAAQ,OAAO,SAAS;GAC1E;GAEA,MAAM,UAAU,MAAM,SAAS,QAAQ,QAAQ,eAAe,UAAU,IAAI;GAC5E,MAAM,QAAQ,OAAO,WAAW;IAC9B,mBAAmB;IACnB,GAAI,MAAM,YAAY,KAAA,KAAa,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;GAC5E,CAAC;GACD,IAAI,YAAY,KAAA,GAAW,cAAc,WAAW;IAAE;IAAS,MAAM,QAAQ,QAAQ;GAAQ,CAAC;QACzF,QAAQ,OAAO,gBAAgB,UAAU,4DAA4D;EAC5G;CACF;AACF"}
1
+ {"version":3,"file":"coordinators.mjs","names":[],"sources":["../../../../src/builders/server/coordinators.ts"],"sourcesContent":["import type { OpenSessionRecord } from '@agimon-ai/po-core/history';\nimport { COORDINATOR_SESSION_PROVENANCE } from '@agimon-ai/po-core/hubChannel';\nimport type { PoHubSessionSelection } from '@agimon-ai/po-core/hubChannel';\n\n/** ponytail: a fixed per-coordinator budget; move it to team limits config when someone needs another number. */\nexport const COORDINATOR_STARTS_PER_HOUR = 5;\nconst HOUR_MS = 60 * 60 * 1000;\nconst FALLBACK_SLUG = 'workspace';\n\n/** The persona every coordinator of one person shares. */\nexport interface CoordinatorSettings {\n readonly profile: string;\n readonly model?: string;\n readonly name: string;\n}\n\nexport interface CoordinatorResult {\n readonly sessionId: string;\n readonly created: boolean;\n}\n\ninterface CoordinatorWorkspace {\n readonly id: string;\n readonly kind?: 'session';\n readonly root: string;\n readonly name?: string;\n readonly available?: boolean;\n readonly sandbox?: string;\n}\n\ninterface CoordinatorLiveSession {\n readonly id: string;\n readonly name?: string;\n readonly workspaceId?: string;\n readonly sessionProvenance?: string;\n readonly createdAt: string;\n readonly profile?: { readonly name: string };\n}\n\nexport interface CoordinatorCreateRequest {\n readonly name: string;\n readonly sessionProvenance?: string;\n readonly selection?: PoHubSessionSelection;\n readonly model?: string;\n}\n\nexport interface CoordinatorServiceOptions {\n liveSessions(): readonly CoordinatorLiveSession[];\n /** Every open-session record this host keeps, live or dormant. */\n records(): readonly OpenSessionRecord[];\n saveRecord(record: OpenSessionRecord): boolean;\n workspaces(): readonly CoordinatorWorkspace[];\n revive(record: OpenSessionRecord): Promise<void>;\n /** A session in the general (`kind: 'session'`) workspace, in a folder the host allocates. */\n createGeneral(request: CoordinatorCreateRequest): Promise<{ sessionId: string }>;\n createInWorkspace(workspace: CoordinatorWorkspace, request: CoordinatorCreateRequest): Promise<{ sessionId: string }>;\n prompt(sessionId: string, text: string): Promise<unknown>;\n /** The profile catalog's default under this root, or the personal one when no root is given. */\n defaultProfile(root?: string): string | undefined;\n /** Closes a live session and reopens it under the same id with this provenance, and this profile when given. */\n reopen(sessionId: string, role: { sessionProvenance?: string; profile?: string }): Promise<void>;\n now?(): number;\n notice(message: string): void;\n}\n\nexport interface CoordinatorService {\n /**\n * Finds the oldest live or dormant coordinator of the target (`'home'` or a workspace id), revives it, or creates\n * one. Single-flight per target.\n */\n ensureCoordinator(target: string, settings: CoordinatorSettings): Promise<CoordinatorResult>;\n /** Ensures the home coordinator, then a coordinator in every existing workspace with the same persona. */\n ensureHome(settings: CoordinatorSettings): Promise<CoordinatorResult>;\n /** A new workspace gets a coordinator only once a home coordinator exists. */\n workspaceAdmitted(workspaceId: string): Promise<void>;\n /** Starts a briefed session in the caller's scope, or an uncoordinated workspace targeted by the home coordinator. */\n startSession(\n coordinatorSessionId: string,\n request: { name: string; brief: string; workspaceId?: string },\n ): Promise<{ sessionId: string }>;\n /**\n * The person's explicit add: the home coordinator when no workspace is named, else that workspace's. The persona\n * is the home coordinator's when one is recorded, else the default profile.\n */\n add(workspaceId?: string): Promise<CoordinatorResult>;\n /**\n * Promotes a session to its workspace's coordinator, demoting any other one, or demotes it. A live session\n * restarts to take on its role; a dormant one being demoted only has its record rewritten.\n */\n setRole(sessionId: string, coordinator: boolean): Promise<void>;\n}\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 }\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 defaultPersona = (root?: string): CoordinatorSettings => {\n const profile = options.defaultProfile(root);\n if (profile === undefined) throw new Error('Choose a default profile before adding a coordinator.');\n return { profile, name: profile };\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 const ensureHome = async (settings: CoordinatorSettings): Promise<CoordinatorResult> => {\n const home = await ensureCoordinator('home', settings);\n const outcomes = await Promise.allSettled(\n options\n .workspaces()\n .filter(coordinated)\n .map((workspace) => ensureCoordinator(workspace.id, workspaceSettings(workspace, settings))),\n );\n for (const outcome of outcomes)\n if (outcome.status === 'rejected')\n options.notice(`A workspace coordinator could not be opened: ${String(outcome.reason)}`);\n return home;\n };\n\n return {\n ensureCoordinator,\n ensureHome,\n async workspaceAdmitted(workspaceId) {\n const workspace = options.workspaces().find((entry) => entry.id === workspaceId);\n const general = homeWorkspace();\n if (workspace === undefined || general === undefined || !coordinated(workspace)) return;\n const home = oldestCoordinator(general.id);\n if (home === undefined) return;\n const persona = options.records().find((record) => record.sessionId === home.sessionId)?.coordinator;\n if (persona === undefined) {\n options.notice(\n `Home coordinator '${home.sessionId}' has no recorded persona; workspace '${workspaceId}' gets none.`,\n );\n return;\n }\n await ensureCoordinator(workspaceId, workspaceSettings(workspace, persona));\n },\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 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 if (workspace === undefined || workspace.available === false || workspace.sandbox !== undefined)\n throw new Error('The target workspace is unavailable.');\n if (workspace.id !== caller.workspaceId) {\n if (caller.workspaceId !== homeWorkspace()?.id || workspace.kind === 'session')\n throw new Error('Only the home coordinator can target another workspace.');\n if (oldestCoordinator(workspace.id) !== undefined)\n throw new Error('This workspace has a coordinator. Ask it to start the session.');\n }\n const at = now();\n const recent = (starts.get(coordinatorSessionId) ?? []).filter((time) => at - time < HOUR_MS);\n if (recent.length >= COORDINATOR_STARTS_PER_HOUR)\n throw new Error(`A coordinator can start at most ${COORDINATOR_STARTS_PER_HOUR} sessions an hour.`);\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 await options.prompt(sessionId, brief);\n return { sessionId };\n },\n async add(workspaceId) {\n if (workspaceId === undefined) return ensureHome(homePersona() ?? defaultPersona());\n const workspace = options.workspaces().find((entry) => entry.id === workspaceId);\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 return ensureCoordinator(\n workspaceId,\n workspaceSettings(workspace, homePersona() ?? defaultPersona(workspace.root)),\n );\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 // 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 (workspace === undefined || (workspace.kind !== 'session' && !coordinated(workspace)))\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"],"mappings":";AAMA,MAAM,UAAU;AAChB,MAAM,gBAAgB;;AAsFtB,SAAgB,cAAc,WAAsE;CAMlG,QALe,UAAU,MAAM,KAAK,KAAK,UAAU,KAAK,MAAM,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,IAAI,KAAK,GAAA,CAE9F,YAAY,CAAC,CACb,QAAQ,gBAAgB,GAAG,CAAC,CAC5B,QAAQ,aAAa,EACd,KAAK;AACjB;AAEA,SAAgB,yBAAyB,SAAwD;CAC/F,MAAM,0BAAU,IAAI,IAAwC;CAC5D,MAAM,yBAAS,IAAI,IAAsB;CACzC,MAAM,YAAoB,QAAQ,MAAM,KAAK,KAAK,IAAI;CAEtD,MAAM,sBACJ,QAAQ,WAAW,CAAC,CAAC,MAAM,cAAc,UAAU,SAAS,SAAS;;CAGvE,MAAM,kBAAkB,gBAAmF;EACzG,MAAM,eAAe,QAAQ,aAAa;EAC1C,MAAM,OAAO,aACV,QACE,YACC,QAAQ,sBAAsB,kCAAkC,QAAQ,gBAAgB,WAC5F,CAAC,CACA,KAAK,aAAa;GAAE,WAAW,QAAQ;GAAI,WAAW,QAAQ;GAAW,MAAM;EAAK,EAAE;EACzF,MAAM,UAAU,QACb,QAAQ,CAAC,CACT,QACE,WACC,OAAO,sBAAsB,kCAC7B,OAAO,gBAAgB,eACvB,CAAC,aAAa,MAAM,YAAY,QAAQ,OAAO,OAAO,SAAS,CACnE,CAAC,CACA,KAAK,YAAY;GAAE,WAAW,OAAO;GAAW,WAAW,OAAO;GAAW,MAAM;EAAM,EAAE;EAC9F,OAAO,CAAC,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,UAAU,cAAc,EAAE,SAAS,CAAC;CAC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AA,GAChC,MAAM,IAAI,MAAM,KAAK,QAAQ,kBAAkB,sCAAsC;GACvF,MAAM,YAAY,QAAQ,WAAW,CAAC,CAAC,MAAM,UAAU,MAAM,OAAO,QAAQ,WAAW;GACvF,IAAI,cAAc,KAAA,KAAc,UAAU,SAAS,aAAa,CAAC,YAAY,SAAS,GACpF,MAAM,IAAI,MAAM,2CAA2C;GAC7D,KAAK,MAAM,SAAS,eAAe,UAAU,EAAE,GAAG,MAAM,OAAO,MAAM,SAAS;GAC9E,IAAI,SAAS,KAAA,GAAW;IACtB,MAAM,QAAQ,OAAO,MAAO;IAC5B,OAAO,QAAQ,aAAa,CAAC,CAAC,MAAM,YAAY,QAAQ,OAAO,SAAS;GAC1E;GAEA,MAAM,UAAU,MAAM,SAAS,QAAQ,QAAQ,eAAe,UAAU,IAAI;GAC5E,MAAM,QAAQ,OAAO,WAAW;IAC9B,mBAAmB;IACnB,GAAI,MAAM,YAAY,KAAA,KAAa,YAAY,KAAA,IAAY,EAAE,QAAQ,IAAI,CAAC;GAC5E,CAAC;GACD,IAAI,YAAY,KAAA,GAAW,cAAc,WAAW;IAAE;IAAS,MAAM,QAAQ,QAAQ;GAAQ,CAAC;QACzF,QAAQ,OAAO,gBAAgB,UAAU,4DAA4D;EAC5G;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/po",
3
- "version": "0.0.0-alpha.123",
3
+ "version": "0.0.0-alpha.125",
4
4
  "description": "Opinionated, composable agent harness for scoped tools, skills, MCP servers, and developer workflows.",
5
5
  "keywords": [
6
6
  "agent-harness",
@@ -177,28 +177,28 @@
177
177
  "registry": "https://registry.npmjs.org/"
178
178
  },
179
179
  "dependencies": {
180
- "@agimon-ai/po-approval": "0.0.0-alpha.122",
181
- "@agimon-ai/po-artifact": "0.0.0-alpha.121",
182
- "@agimon-ai/po-autostop": "0.0.0-alpha.122",
183
- "@agimon-ai/po-cache": "0.0.0-alpha.122",
184
- "@agimon-ai/po-config": "0.0.0-alpha.122",
185
- "@agimon-ai/po-core": "0.0.0-alpha.122",
186
- "@agimon-ai/po-db": "0.0.0-alpha.122",
187
- "@agimon-ai/po-domain": "0.0.0-alpha.122",
188
- "@agimon-ai/po-logsink": "0.0.1-alpha.104",
189
- "@agimon-ai/po-major-mode": "0.0.0-alpha.122",
190
- "@agimon-ai/po-mcp-proxy": "0.0.1-alpha.101",
191
- "@agimon-ai/po-minor-mode": "0.0.0-alpha.122",
192
- "@agimon-ai/po-native-components": "0.0.0-alpha.122",
193
- "@agimon-ai/po-network": "0.0.2-alpha.69",
194
- "@agimon-ai/po-notification": "0.0.0-alpha.122",
195
- "@agimon-ai/po-profile": "0.0.0-alpha.122",
196
- "@agimon-ai/po-session": "0.0.0-alpha.122",
197
- "@agimon-ai/po-skill": "0.0.0-alpha.122",
198
- "@agimon-ai/po-ui": "0.0.0-alpha.122",
199
- "@agimon-ai/po-vault": "0.0.0-alpha.122",
200
- "@agimon-ai/po-web-components": "0.0.0-alpha.122",
201
- "@agimon-ai/po-web-security": "0.0.0-alpha.122",
180
+ "@agimon-ai/po-approval": "0.0.0-alpha.124",
181
+ "@agimon-ai/po-artifact": "0.0.0-alpha.123",
182
+ "@agimon-ai/po-autostop": "0.0.0-alpha.124",
183
+ "@agimon-ai/po-cache": "0.0.0-alpha.124",
184
+ "@agimon-ai/po-config": "0.0.0-alpha.124",
185
+ "@agimon-ai/po-core": "0.0.0-alpha.124",
186
+ "@agimon-ai/po-db": "0.0.0-alpha.124",
187
+ "@agimon-ai/po-domain": "0.0.0-alpha.124",
188
+ "@agimon-ai/po-logsink": "0.0.1-alpha.106",
189
+ "@agimon-ai/po-major-mode": "0.0.0-alpha.124",
190
+ "@agimon-ai/po-mcp-proxy": "0.0.1-alpha.103",
191
+ "@agimon-ai/po-minor-mode": "0.0.0-alpha.124",
192
+ "@agimon-ai/po-native-components": "0.0.0-alpha.124",
193
+ "@agimon-ai/po-network": "0.0.2-alpha.71",
194
+ "@agimon-ai/po-notification": "0.0.0-alpha.124",
195
+ "@agimon-ai/po-profile": "0.0.0-alpha.124",
196
+ "@agimon-ai/po-session": "0.0.0-alpha.124",
197
+ "@agimon-ai/po-skill": "0.0.0-alpha.124",
198
+ "@agimon-ai/po-ui": "0.0.0-alpha.124",
199
+ "@agimon-ai/po-vault": "0.0.0-alpha.124",
200
+ "@agimon-ai/po-web-components": "0.0.0-alpha.124",
201
+ "@agimon-ai/po-web-security": "0.0.0-alpha.124",
202
202
  "@deepseek-ai/cordis": "4.0.5",
203
203
  "@earendil-works/pi-agent-core": "1.5.0",
204
204
  "@earendil-works/pi-coding-agent": "1.5.0",
@@ -220,10 +220,10 @@
220
220
  "yaml": "2.9.1"
221
221
  },
222
222
  "devDependencies": {
223
- "@agimon-ai/po-calendar": "0.0.1-alpha.81",
224
- "@agimon-ai/po-identity": "0.0.2-alpha.69",
225
- "@agimon-ai/po-runner": "0.0.0-alpha.122",
226
- "@agimon-ai/vibe-lint-plugin-po-cli": "0.0.0-alpha.122",
223
+ "@agimon-ai/po-calendar": "0.0.1-alpha.83",
224
+ "@agimon-ai/po-identity": "0.0.2-alpha.71",
225
+ "@agimon-ai/po-runner": "0.0.0-alpha.124",
226
+ "@agimon-ai/vibe-lint-plugin-po-cli": "0.0.0-alpha.124",
227
227
  "@earendil-works/pi-ai": "1.5.0",
228
228
  "@modelcontextprotocol/ext-apps": "2.0.3",
229
229
  "@modelcontextprotocol/server": "2.3.1",