@agimon-ai/po 0.0.0-alpha.101 → 0.0.0-alpha.102

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.101",
5
+ "version": "0.0.0-alpha.102",
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.100",
31
+ "version": "0.0.0-alpha.101",
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.99",
38
+ "version": "0.0.0-alpha.100",
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.100",
46
+ "version": "0.0.0-alpha.101",
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.100",
56
+ "version": "0.0.0-alpha.101",
57
57
  "dependencies": [
58
58
  "@agimon-ai/po-artifact",
59
59
  "@agimon-ai/po-config",
@@ -62,24 +62,24 @@
62
62
  ]
63
63
  },
64
64
  "@agimon-ai/po-autostop": {
65
- "version": "0.0.0-alpha.100",
65
+ "version": "0.0.0-alpha.101",
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.98",
71
+ "version": "0.0.1-alpha.99",
72
72
  "dependencies": [
73
73
  "@agimon-ai/po-core",
74
74
  "@agimon-ai/po-web-components"
75
75
  ]
76
76
  },
77
77
  "@agimon-ai/po-build": {
78
- "version": "0.0.0-alpha.100",
78
+ "version": "0.0.0-alpha.101",
79
79
  "dependencies": []
80
80
  },
81
81
  "@agimon-ai/po-cache": {
82
- "version": "0.0.0-alpha.100",
82
+ "version": "0.0.0-alpha.101",
83
83
  "dependencies": [
84
84
  "@agimon-ai/po-config",
85
85
  "@agimon-ai/po-core",
@@ -87,7 +87,7 @@
87
87
  ]
88
88
  },
89
89
  "@agimon-ai/po-calendar": {
90
- "version": "0.0.1-alpha.59",
90
+ "version": "0.0.1-alpha.60",
91
91
  "dependencies": [
92
92
  "@agimon-ai/po-config",
93
93
  "@agimon-ai/po-core",
@@ -98,15 +98,11 @@
98
98
  ]
99
99
  },
100
100
  "@agimon-ai/po-claude-bridge": {
101
- "version": "0.1.1-alpha.80",
102
- "dependencies": []
103
- },
104
- "@agimon-ai/po-cloudflare": {
105
- "version": "0.0.2-alpha.0",
101
+ "version": "0.1.1-alpha.81",
106
102
  "dependencies": []
107
103
  },
108
104
  "@agimon-ai/po-codemode": {
109
- "version": "0.0.1-alpha.73",
105
+ "version": "0.0.1-alpha.74",
110
106
  "dependencies": [
111
107
  "@agimon-ai/po-config",
112
108
  "@agimon-ai/po-core",
@@ -114,7 +110,7 @@
114
110
  ]
115
111
  },
116
112
  "@agimon-ai/po-computer-use": {
117
- "version": "0.0.0-alpha.100",
113
+ "version": "0.0.0-alpha.101",
118
114
  "dependencies": [
119
115
  "@agimon-ai/po-config",
120
116
  "@agimon-ai/po-core",
@@ -124,26 +120,26 @@
124
120
  ]
125
121
  },
126
122
  "@agimon-ai/po-config": {
127
- "version": "0.0.0-alpha.100",
123
+ "version": "0.0.0-alpha.101",
128
124
  "dependencies": [
129
125
  "@agimon-ai/po-core",
130
126
  "@agimon-ai/po-web-components"
131
127
  ]
132
128
  },
133
129
  "@agimon-ai/po-core": {
134
- "version": "0.0.0-alpha.100",
130
+ "version": "0.0.0-alpha.101",
135
131
  "dependencies": [
136
132
  "@agimon-ai/po-web-security"
137
133
  ]
138
134
  },
139
135
  "@agimon-ai/po-db": {
140
- "version": "0.0.0-alpha.100",
136
+ "version": "0.0.0-alpha.101",
141
137
  "dependencies": [
142
138
  "@agimon-ai/po-core"
143
139
  ]
144
140
  },
145
141
  "@agimon-ai/po-domain": {
146
- "version": "0.0.0-alpha.100",
142
+ "version": "0.0.0-alpha.101",
147
143
  "dependencies": [
148
144
  "@agimon-ai/po-config",
149
145
  "@agimon-ai/po-core",
@@ -151,7 +147,7 @@
151
147
  ]
152
148
  },
153
149
  "@agimon-ai/po-edit": {
154
- "version": "0.0.0-alpha.100",
150
+ "version": "0.0.0-alpha.101",
155
151
  "dependencies": [
156
152
  "@agimon-ai/po-core",
157
153
  "@agimon-ai/po-hashline",
@@ -160,7 +156,7 @@
160
156
  ]
161
157
  },
162
158
  "@agimon-ai/po-file-edit": {
163
- "version": "0.0.0-alpha.100",
159
+ "version": "0.0.0-alpha.101",
164
160
  "dependencies": [
165
161
  "@agimon-ai/po-config",
166
162
  "@agimon-ai/po-core",
@@ -170,7 +166,7 @@
170
166
  ]
171
167
  },
172
168
  "@agimon-ai/po-git": {
173
- "version": "0.0.0-alpha.100",
169
+ "version": "0.0.0-alpha.101",
174
170
  "dependencies": [
175
171
  "@agimon-ai/po-core",
176
172
  "@agimon-ai/po-session",
@@ -179,7 +175,7 @@
179
175
  ]
180
176
  },
181
177
  "@agimon-ai/po-goal": {
182
- "version": "0.0.0-alpha.100",
178
+ "version": "0.0.0-alpha.101",
183
179
  "dependencies": [
184
180
  "@agimon-ai/po-core",
185
181
  "@agimon-ai/po-minor-mode",
@@ -188,7 +184,7 @@
188
184
  ]
189
185
  },
190
186
  "@agimon-ai/po-grep": {
191
- "version": "0.0.0-alpha.100",
187
+ "version": "0.0.0-alpha.101",
192
188
  "dependencies": [
193
189
  "@agimon-ai/po-core",
194
190
  "@agimon-ai/po-hashline",
@@ -197,11 +193,11 @@
197
193
  ]
198
194
  },
199
195
  "@agimon-ai/po-hashline": {
200
- "version": "0.0.0-alpha.100",
196
+ "version": "0.0.0-alpha.101",
201
197
  "dependencies": []
202
198
  },
203
199
  "@agimon-ai/po-help": {
204
- "version": "0.0.0-alpha.100",
200
+ "version": "0.0.0-alpha.101",
205
201
  "dependencies": [
206
202
  "@agimon-ai/po-core",
207
203
  "@agimon-ai/po-minor-mode",
@@ -209,14 +205,14 @@
209
205
  ]
210
206
  },
211
207
  "@agimon-ai/po-identity": {
212
- "version": "0.0.2-alpha.47",
208
+ "version": "0.0.2-alpha.48",
213
209
  "dependencies": [
214
210
  "@agimon-ai/po-core",
215
211
  "@agimon-ai/po-web-security"
216
212
  ]
217
213
  },
218
214
  "@agimon-ai/po-image-gen": {
219
- "version": "0.0.0-alpha.99",
215
+ "version": "0.0.0-alpha.100",
220
216
  "dependencies": [
221
217
  "@agimon-ai/po-core",
222
218
  "@agimon-ai/po-web-components",
@@ -224,7 +220,7 @@
224
220
  ]
225
221
  },
226
222
  "@agimon-ai/po-ios": {
227
- "version": "0.0.1-alpha.35",
223
+ "version": "0.0.1-alpha.36",
228
224
  "dependencies": [
229
225
  "@agimon-ai/po-artifact",
230
226
  "@agimon-ai/po-config",
@@ -234,7 +230,7 @@
234
230
  ]
235
231
  },
236
232
  "@agimon-ai/po-log": {
237
- "version": "0.0.0-alpha.100",
233
+ "version": "0.0.0-alpha.101",
238
234
  "dependencies": [
239
235
  "@agimon-ai/po-core",
240
236
  "@agimon-ai/po-web-components",
@@ -242,7 +238,7 @@
242
238
  ]
243
239
  },
244
240
  "@agimon-ai/po-major-mode": {
245
- "version": "0.0.0-alpha.100",
241
+ "version": "0.0.0-alpha.101",
246
242
  "dependencies": [
247
243
  "@agimon-ai/po-config",
248
244
  "@agimon-ai/po-core",
@@ -250,7 +246,7 @@
250
246
  ]
251
247
  },
252
248
  "@agimon-ai/po-mcp": {
253
- "version": "0.0.0-alpha.100",
249
+ "version": "0.0.0-alpha.101",
254
250
  "dependencies": [
255
251
  "@agimon-ai/po-config",
256
252
  "@agimon-ai/po-core",
@@ -261,43 +257,43 @@
261
257
  ]
262
258
  },
263
259
  "@agimon-ai/po-mcp-proxy": {
264
- "version": "0.0.1-alpha.79",
260
+ "version": "0.0.1-alpha.80",
265
261
  "dependencies": []
266
262
  },
267
263
  "@agimon-ai/po-minor-mode": {
268
- "version": "0.0.0-alpha.100",
264
+ "version": "0.0.0-alpha.101",
269
265
  "dependencies": [
270
266
  "@agimon-ai/po-core"
271
267
  ]
272
268
  },
273
269
  "@agimon-ai/po-model-guidance": {
274
- "version": "0.0.0-alpha.100",
270
+ "version": "0.0.0-alpha.101",
275
271
  "dependencies": [
276
272
  "@agimon-ai/po-config",
277
273
  "@agimon-ai/po-core"
278
274
  ]
279
275
  },
280
276
  "@agimon-ai/po-native-components": {
281
- "version": "0.0.0-alpha.100",
277
+ "version": "0.0.0-alpha.101",
282
278
  "dependencies": [
283
279
  "@agimon-ai/po-web-components"
284
280
  ]
285
281
  },
286
282
  "@agimon-ai/po-network": {
287
- "version": "0.0.2-alpha.47",
283
+ "version": "0.0.2-alpha.48",
288
284
  "dependencies": [
289
285
  "@agimon-ai/po-core",
290
286
  "@agimon-ai/po-web-security"
291
287
  ]
292
288
  },
293
289
  "@agimon-ai/po-notification": {
294
- "version": "0.0.0-alpha.100",
290
+ "version": "0.0.0-alpha.101",
295
291
  "dependencies": [
296
292
  "@agimon-ai/po-core"
297
293
  ]
298
294
  },
299
295
  "@agimon-ai/po-plan": {
300
- "version": "0.0.0-alpha.100",
296
+ "version": "0.0.0-alpha.101",
301
297
  "dependencies": [
302
298
  "@agimon-ai/po-config",
303
299
  "@agimon-ai/po-core",
@@ -307,7 +303,7 @@
307
303
  ]
308
304
  },
309
305
  "@agimon-ai/po-profile": {
310
- "version": "0.0.0-alpha.100",
306
+ "version": "0.0.0-alpha.101",
311
307
  "dependencies": [
312
308
  "@agimon-ai/po-config",
313
309
  "@agimon-ai/po-core",
@@ -315,7 +311,7 @@
315
311
  ]
316
312
  },
317
313
  "@agimon-ai/po-prompt": {
318
- "version": "0.0.0-alpha.100",
314
+ "version": "0.0.0-alpha.101",
319
315
  "dependencies": [
320
316
  "@agimon-ai/po-core",
321
317
  "@agimon-ai/po-web-components",
@@ -323,7 +319,7 @@
323
319
  ]
324
320
  },
325
321
  "@agimon-ai/po-read": {
326
- "version": "0.0.0-alpha.100",
322
+ "version": "0.0.0-alpha.101",
327
323
  "dependencies": [
328
324
  "@agimon-ai/po-config",
329
325
  "@agimon-ai/po-core",
@@ -333,7 +329,7 @@
333
329
  ]
334
330
  },
335
331
  "@agimon-ai/po-runner": {
336
- "version": "0.0.0-alpha.100",
332
+ "version": "0.0.0-alpha.101",
337
333
  "dependencies": [
338
334
  "@agimon-ai/po-core",
339
335
  "@agimon-ai/po-ui",
@@ -342,13 +338,13 @@
342
338
  ]
343
339
  },
344
340
  "@agimon-ai/po-sandbox": {
345
- "version": "0.0.0-alpha.100",
341
+ "version": "0.0.0-alpha.101",
346
342
  "dependencies": [
347
343
  "@agimon-ai/po-core"
348
344
  ]
349
345
  },
350
346
  "@agimon-ai/po-session": {
351
- "version": "0.0.0-alpha.100",
347
+ "version": "0.0.0-alpha.101",
352
348
  "dependencies": [
353
349
  "@agimon-ai/po-config",
354
350
  "@agimon-ai/po-core",
@@ -356,7 +352,7 @@
356
352
  ]
357
353
  },
358
354
  "@agimon-ai/po-skill": {
359
- "version": "0.0.0-alpha.100",
355
+ "version": "0.0.0-alpha.101",
360
356
  "dependencies": [
361
357
  "@agimon-ai/po-config",
362
358
  "@agimon-ai/po-core",
@@ -365,7 +361,7 @@
365
361
  ]
366
362
  },
367
363
  "@agimon-ai/po-style-system": {
368
- "version": "0.0.0-alpha.100",
364
+ "version": "0.0.0-alpha.101",
369
365
  "dependencies": [
370
366
  "@agimon-ai/po-core",
371
367
  "@agimon-ai/po-web-components",
@@ -373,7 +369,7 @@
373
369
  ]
374
370
  },
375
371
  "@agimon-ai/po-task": {
376
- "version": "0.0.0-alpha.100",
372
+ "version": "0.0.0-alpha.101",
377
373
  "dependencies": [
378
374
  "@agimon-ai/po-core",
379
375
  "@agimon-ai/po-ui",
@@ -381,7 +377,7 @@
381
377
  ]
382
378
  },
383
379
  "@agimon-ai/po-team": {
384
- "version": "0.0.0-alpha.100",
380
+ "version": "0.0.0-alpha.101",
385
381
  "dependencies": [
386
382
  "@agimon-ai/po-cache",
387
383
  "@agimon-ai/po-config",
@@ -393,7 +389,7 @@
393
389
  ]
394
390
  },
395
391
  "@agimon-ai/po-template-advanced": {
396
- "version": "0.0.0-alpha.100",
392
+ "version": "0.0.0-alpha.101",
397
393
  "dependencies": [
398
394
  "@agimon-ai/po-core",
399
395
  "@agimon-ai/po-web-components",
@@ -401,7 +397,7 @@
401
397
  ]
402
398
  },
403
399
  "@agimon-ai/po-template-elegant": {
404
- "version": "0.0.0-alpha.100",
400
+ "version": "0.0.0-alpha.101",
405
401
  "dependencies": [
406
402
  "@agimon-ai/po-core",
407
403
  "@agimon-ai/po-web-components",
@@ -409,7 +405,7 @@
409
405
  ]
410
406
  },
411
407
  "@agimon-ai/po-ui": {
412
- "version": "0.0.0-alpha.100",
408
+ "version": "0.0.0-alpha.101",
413
409
  "dependencies": [
414
410
  "@agimon-ai/po-core",
415
411
  "@agimon-ai/po-hashline",
@@ -418,7 +414,7 @@
418
414
  ]
419
415
  },
420
416
  "@agimon-ai/po-user-feedback": {
421
- "version": "0.0.0-alpha.100",
417
+ "version": "0.0.0-alpha.101",
422
418
  "dependencies": [
423
419
  "@agimon-ai/po-core",
424
420
  "@agimon-ai/po-minor-mode",
@@ -427,14 +423,14 @@
427
423
  ]
428
424
  },
429
425
  "@agimon-ai/po-vault": {
430
- "version": "0.0.0-alpha.100",
426
+ "version": "0.0.0-alpha.101",
431
427
  "dependencies": [
432
428
  "@agimon-ai/po-core",
433
429
  "@agimon-ai/po-db"
434
430
  ]
435
431
  },
436
432
  "@agimon-ai/po-vibe-lint": {
437
- "version": "0.0.1-alpha.69",
433
+ "version": "0.0.1-alpha.70",
438
434
  "dependencies": [
439
435
  "@agimon-ai/po-config",
440
436
  "@agimon-ai/po-core",
@@ -444,7 +440,7 @@
444
440
  ]
445
441
  },
446
442
  "@agimon-ai/po-voice": {
447
- "version": "0.0.0-alpha.100",
443
+ "version": "0.0.0-alpha.101",
448
444
  "dependencies": [
449
445
  "@agimon-ai/po-config",
450
446
  "@agimon-ai/po-core",
@@ -456,11 +452,11 @@
456
452
  ]
457
453
  },
458
454
  "@agimon-ai/po-web-components": {
459
- "version": "0.0.0-alpha.100",
455
+ "version": "0.0.0-alpha.101",
460
456
  "dependencies": []
461
457
  },
462
458
  "@agimon-ai/po-web-dashboard": {
463
- "version": "0.0.0-alpha.100",
459
+ "version": "0.0.0-alpha.101",
464
460
  "dependencies": [
465
461
  "@agimon-ai/po-core",
466
462
  "@agimon-ai/po-web-components",
@@ -468,18 +464,18 @@
468
464
  ]
469
465
  },
470
466
  "@agimon-ai/po-web-search": {
471
- "version": "0.0.0-alpha.99",
467
+ "version": "0.0.0-alpha.100",
472
468
  "dependencies": [
473
469
  "@agimon-ai/po-core",
474
470
  "@agimon-ai/po-web-components"
475
471
  ]
476
472
  },
477
473
  "@agimon-ai/po-web-security": {
478
- "version": "0.0.0-alpha.100",
474
+ "version": "0.0.0-alpha.101",
479
475
  "dependencies": []
480
476
  },
481
477
  "@agimon-ai/po-workflow": {
482
- "version": "0.0.0-alpha.100",
478
+ "version": "0.0.0-alpha.101",
483
479
  "dependencies": [
484
480
  "@agimon-ai/po-core",
485
481
  "@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.101";
2
+ var version = "0.0.0-alpha.102";
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.101";
2
+ var version = "0.0.0-alpha.102";
3
3
  //#endregion
4
4
  export { version };
5
5
 
@@ -52,7 +52,7 @@ function overridePackageName(selector) {
52
52
  * cannot carry these fixes in their own manifests.
53
53
  */
54
54
  const SAFE_TRANSITIVE_OVERRIDES = {
55
- "@earendil-works/pi-codemode": "1.4.0",
55
+ "@earendil-works/pi-codemode": "1.5.0",
56
56
  "@hono/node-server@2.0.0 - 2.0.9": "^2.0.10",
57
57
  "@opentelemetry/core@2.0.0 - 2.7.999": "2.8.0",
58
58
  "brace-expansion@1.0.0 - 1.1.20": "^1.1.21",
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["isLocalPackageSpecifier","fs","path","writeFileAtomic","createNodePlatform","BACKGROUND_CONTEXT","splitPackageSpecifier","poPackageRoot","consumerPackageEntry","crypto","zlib","os","poHomeDirectory","poRuntimeDirectory","createLayerResolvers","testPackageRoot","resolveNewest","installRuntimePackages"],"sources":["../../../../src/composition/layerPackageInstaller/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport os from 'node:os';\nimport path from 'node:path';\nimport zlib from 'node:zlib';\n\nimport { isLocalPackageSpecifier, type MajorModesConfig } from '@agimon-ai/po-config/majorModes';\nimport { consumerPackageEntry, splitPackageSpecifier, testPackageRoot } from '@agimon-ai/po-core/moduleResolution';\nimport { createNodePlatform } from '@agimon-ai/po-core/nodePlatform';\nimport { BACKGROUND_CONTEXT, writeFileAtomic } from '@agimon-ai/po-core/platform';\nimport {\n installRuntimePackages,\n type InstallRuntimePackagesOptions,\n resolveNewest,\n} from '@agimon-ai/po-core/runtimePackages';\nimport { poHomeDirectory, poRuntimeDirectory } from '@agimon-ai/po-core/runtimePiSettings';\n\nimport { poPackageRoot } from '../../builders/cli/entryResolution';\nimport { createLayerResolvers, type ExtensionLayerResolvers } from '../../builders/cli/extensionAssembler';\n\nconst NPM_SOURCE_PREFIX = 'npm:';\nconst FILE_SPECIFIER_PREFIX = 'file:';\nconst WORKSPACE_SPECIFIER_PREFIX = 'workspace:';\n/** Root target of a staged catalogue archive: always the staged workspace, never the registry. */\nconst CATALOG_WORKSPACE_TARGET = 'workspace:*';\n/** Where catalogue archives are unpacked inside the runtime, one directory per archive hash. */\nconst CATALOG_STAGING_DIRECTORY = 'catalog';\nconst RUNTIME_PACKAGE_NAME = 'po-runtime';\nconst UNPINNED_PACKAGE_RANGE = '*';\nconst PACKAGE_MANIFEST = 'package.json';\nconst NODE_MODULES = 'node_modules';\nconst PACKAGE_CATALOG_ENV = 'PO_PACKAGE_CATALOG';\n/** The registry catalogue a release writes into the CLI package: `<package root>/dist/catalog/index.json`. */\nconst BUNDLED_CATALOG_SEGMENTS = ['dist', 'catalog', 'index.json'] as const;\n/** upm error codes that mean the registry could not be reached, so the store may still answer. */\nconst NETWORK_FAILURE_CODES = new Set(['ENETWORK', 'ETIMEDOUT', 'EREGISTRY']);\n\nfunction overridePackageName(selector: string): string {\n const separatorIndex = selector.indexOf('@', selector.startsWith('@') ? 1 : 0);\n return separatorIndex === -1 ? selector : selector.slice(0, separatorIndex);\n}\n\n/**\n * Runtime compatibility pins and same-major patches for current foundation packages.\n * Package managers only honor overrides from the install root, so published extensions\n * cannot carry these fixes in their own manifests.\n */\nexport const SAFE_TRANSITIVE_OVERRIDES = {\n // ponytail: Pin for Pi 1.4.0's declaration API; advance with the host's Pi version.\n '@earendil-works/pi-codemode': '1.4.0',\n '@hono/node-server@2.0.0 - 2.0.9': '^2.0.10',\n '@opentelemetry/core@2.0.0 - 2.7.999': '2.8.0',\n 'brace-expansion@1.0.0 - 1.1.20': '^1.1.21',\n 'brace-expansion@5.0.0 - 5.0.11': '^5.0.12',\n 'hono@4.0.0 - 4.13.7': '4.13.8',\n 'js-yaml@4.0.0 - 4.3.1': '^4.3.2',\n 'js-yaml@5.0.0 - 5.2.1': '^5.2.2',\n 'liquidjs@10.0.0 - 10.27.1': '^10.27.2',\n 'protobufjs@8.0.0 - 8.7.1': '^8.7.2',\n 'undici@7.0.0 - 7.29.0': '^7.29.1',\n} as const satisfies Readonly<Record<string, string>>;\n\nconst SAFE_TRANSITIVE_PACKAGE_NAMES = new Set(Object.keys(SAFE_TRANSITIVE_OVERRIDES).map(overridePackageName));\n\nexport interface EnsureLayerPackagesOptions {\n /**\n * The Po root whose layers name the packages. Its own node_modules chain is\n * resolved first; what it cannot provide is installed into the one runtime\n * every root shares, `<po home>/runtime`.\n */\n repoRoot: string;\n config: MajorModesConfig;\n layers: readonly string[];\n environment?: NodeJS.ProcessEnv;\n /**\n * Move every managed package to its newest published version.\n *\n * Launch installs what a selection needs and nothing more, so a session never\n * pays for a registry round trip. Sync is the explicit maintenance command and\n * is the only caller that asks for this.\n */\n refresh?: boolean;\n /**\n * Packages installed into the runtime whatever the root resolves itself, such as the\n * catalogue's `install` list. A `name@version` specifier pins that exact version; a\n * catalogue archive for the name still wins. Refresh never moves a pinned name.\n */\n specifiers?: readonly string[];\n /**\n * Make the runtime manifest declare exactly this run's packages (the specifiers, the\n * selected names and their catalogue dependencies), so pruning can drop anything else.\n * Without it the manifest only grows.\n */\n exactManifest?: boolean;\n /** Receives one human-readable line per package decision. */\n onProgress?: (message: string) => void;\n}\n\nexport interface LayerPackageInstallerDependencies {\n /** Install seam; the default installs `<po home>/runtime` with upm. */\n install?: (options: InstallRuntimePackagesOptions) => Promise<unknown>;\n resolvers?: ExtensionLayerResolvers;\n /** Registry lookup seam; the default resolves the newest allowed version with upm. */\n publishedVersion?: (name: string) => Promise<string>;\n}\n\n/** One managed package moving from the installed version to the newest published one. */\nexport interface LayerPackageUpdate {\n name: string;\n from: string;\n to: string;\n}\n\nexport interface LayerPackageResult {\n /** Sources installed because a configured extension could not be resolved. */\n installed: string[];\n /** Packages this run moved to a newer published version. */\n updated: LayerPackageUpdate[];\n /** Packages left at the installed version because the registry could not be read. */\n unchecked: string[];\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction recordValue(value: unknown): Record<string, unknown> {\n return isRecord(value) ? { ...value } : {};\n}\n\nfunction withoutConflictingTransitiveOverrides(value: unknown): Record<string, unknown> {\n const overrides = recordValue(value);\n for (const [selector, replacement] of Object.entries(overrides)) {\n if (SAFE_TRANSITIVE_PACKAGE_NAMES.has(overridePackageName(selector))) {\n delete overrides[selector];\n } else if (isRecord(replacement)) {\n overrides[selector] = withoutConflictingTransitiveOverrides(replacement);\n }\n }\n return overrides;\n}\n\n/** Earlier versions overrode catalog packages with relative `file:` targets; any other override is not Po's. */\nfunction withoutCatalogOverrides(overrides: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(overrides).filter(\n ([, replacement]) => !(typeof replacement === 'string' && replacement.startsWith(FILE_SPECIFIER_PREFIX)),\n ),\n );\n}\n\n/** The published (non-local, required) package specifiers the default and the given layers name. */\nfunction configuredPackageSpecifiers(config: MajorModesConfig, layers: readonly string[]): string[] {\n const specifiers = new Set<string>();\n const selectedDefinitions = [\n ...(config.default ? [config.default] : []),\n ...layers.map((layerName) => {\n const layer = config.layers[layerName];\n if (!layer) throw new Error(`Unknown layer: ${layerName}`);\n return layer;\n }),\n ];\n for (const layer of selectedDefinitions) {\n for (const configured of layer.packages ?? []) {\n const specifier = typeof configured === 'string' ? configured : configured.name;\n const optional = typeof configured !== 'string' && configured.optional === true;\n if (!optional && !isLocalPackageSpecifier(specifier)) specifiers.add(specifier);\n }\n }\n return [...specifiers];\n}\n\nfunction resolvePackageEntries(resolvers: ExtensionLayerResolvers, specifier: string): string[] | undefined {\n const entries = resolvers.optionalPackageEntries?.(specifier);\n if (entries !== undefined) return entries;\n const entry = resolvers.optionalPackageEntry(specifier);\n return entry ? [entry] : undefined;\n}\n\nasync function readRuntimeManifest(\n manifestPath: string,\n): Promise<{ current: string | undefined; manifest: Record<string, unknown> }> {\n const current = await fs.readFile(manifestPath, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (current === undefined) return { current, manifest: { name: RUNTIME_PACKAGE_NAME, private: true } };\n const parsed: unknown = JSON.parse(current);\n if (!isRecord(parsed)) throw new Error(`Po runtime package manifest at ${manifestPath} must be a JSON object.`);\n return { current, manifest: parsed };\n}\n\n/** Names the runtime manifest already declares: what earlier runs, from any root, installed there. */\nasync function declaredRuntimePackages(runtimeDirectory: string): Promise<Set<string>> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n return new Set(Object.keys(recordValue((await readRuntimeManifest(manifestPath)).manifest.dependencies)));\n}\n\n/**\n * Adds a package set and the patched transitive policy to the shared runtime manifest.\n *\n * `targets` pins names to exact versions or `workspace:*`. `catalogWorkspaces` maps each\n * staged catalogue archive's name to its directory relative to the runtime; the manifest\n * lists exactly those directories as its `workspaces`, so a catalogue package's dependency\n * on another one links the staged copy instead of reaching the registry. Both `overrides` and\n * `pnpm.overrides` are written; upm reads both.\n * With `exact`, declared names outside `sources` are dropped instead of kept.\n */\nexport async function ensureManagedPackageManifest(\n runtimeDirectory: string,\n sources: readonly string[],\n targets: ReadonlyMap<string, string> = new Map(),\n catalogWorkspaces: Readonly<Record<string, string>> = {},\n exact = false,\n): Promise<boolean> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n const { current, manifest } = await readRuntimeManifest(manifestPath);\n\n const declared = recordValue(manifest.dependencies);\n const sourceNames = new Set(sources.map(packageName));\n const dependencies = exact\n ? Object.fromEntries(Object.entries(declared).filter(([name]) => sourceNames.has(name)))\n : declared;\n // Every root shares this manifest, so a catalog archive another process staged (a desktop\n // build, say) may not exist for this one: without a staged copy here it falls back to the\n // registry, which keeps the whole set installable. `file:` targets are what earlier\n // versions wrote for archives.\n for (const [name, declared] of Object.entries(dependencies)) {\n if (Object.hasOwn(catalogWorkspaces, name)) {\n dependencies[name] = CATALOG_WORKSPACE_TARGET;\n } else if (\n typeof declared === 'string' &&\n (declared.startsWith(FILE_SPECIFIER_PREFIX) || declared.startsWith(WORKSPACE_SPECIFIER_PREFIX))\n ) {\n dependencies[name] = UNPINNED_PACKAGE_RANGE;\n }\n }\n for (const source of sources) {\n const name = packageName(source);\n const target = targets.get(name);\n // An exact target is what makes an update reach the store: a package manager keeps a\n // locked version whenever the recorded range still admits it.\n if (target !== undefined) dependencies[name] = target;\n else if (!Object.hasOwn(dependencies, name)) dependencies[name] = UNPINNED_PACKAGE_RANGE;\n }\n manifest.dependencies = dependencies;\n // Po owns the runtime's workspaces: exactly the staged archives, which reach only each other.\n const workspaces = Object.values(catalogWorkspaces).sort();\n if (workspaces.length > 0) manifest.workspaces = workspaces;\n else delete manifest.workspaces;\n // Nested and overlapping consumer rules can take precedence in cases that retain\n // vulnerable versions, so Po owns these package-specific selectors recursively.\n manifest.overrides = {\n ...withoutCatalogOverrides(withoutConflictingTransitiveOverrides(manifest.overrides)),\n ...SAFE_TRANSITIVE_OVERRIDES,\n };\n const pnpm = recordValue(manifest.pnpm);\n pnpm.overrides = {\n ...withoutCatalogOverrides(withoutConflictingTransitiveOverrides(pnpm.overrides)),\n ...SAFE_TRANSITIVE_OVERRIDES,\n };\n manifest.pnpm = pnpm;\n\n const serialized = `${JSON.stringify(manifest, null, 2)}\\n`;\n if (serialized === current) return false;\n await fs.mkdir(runtimeDirectory, { recursive: true });\n await writeFileAtomic(createNodePlatform().env(runtimeDirectory), manifestPath, serialized, BACKGROUND_CONTEXT);\n return true;\n}\n\n/** Finds required npm packages selected by defaults and active layers that Po cannot resolve. */\nexport function missingLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n resolvers: ExtensionLayerResolvers,\n): string[] {\n return configuredPackageSpecifiers(config, layers).filter(\n (specifier) => resolvePackageEntries(resolvers, specifier) === undefined,\n );\n}\n\n/** Whether `root`'s own node_modules chain holds the package, walked the way Node looks it up from `root`. */\nasync function ownsPackage(name: string, root: string): Promise<boolean> {\n for (let directory = path.resolve(root); ; directory = path.dirname(directory)) {\n if (\n await fs.access(path.join(directory, NODE_MODULES, name, PACKAGE_MANIFEST)).then(\n () => true,\n (error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return false;\n throw error;\n },\n )\n )\n return true;\n if (path.dirname(directory) === directory) return false;\n }\n}\n\n/**\n * The required npm packages the default and the given layers name that `root` does not get\n * from its own node_modules chain: what the shared runtime provides for it, whether it does so\n * already or not yet. Sync declares exactly these, over every root, in the runtime manifest; a\n * name the runtime already provides still counts, or the next exact manifest would drop it.\n */\nexport async function runtimeLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n root: string,\n): Promise<string[]> {\n const specifiers = configuredPackageSpecifiers(config, layers);\n const owned = await Promise.all(\n specifiers.map((specifier) => ownsPackage(splitPackageSpecifier(specifier).name, root)),\n );\n return specifiers.filter((_specifier, index) => !owned[index]);\n}\n\nfunction packageName(source: string): string {\n const specifier = source.startsWith(NPM_SOURCE_PREFIX) ? source.slice(NPM_SOURCE_PREFIX.length) : source;\n if (specifier.startsWith('@')) {\n const slash = specifier.indexOf('/');\n const version = slash === -1 ? -1 : specifier.indexOf('@', slash);\n return version === -1 ? specifier : specifier.slice(0, version);\n }\n const version = specifier.indexOf('@');\n return version === -1 ? specifier : specifier.slice(0, version);\n}\n\ninterface PackageCatalogEntry {\n /** Absolute path of the bundled archive; it takes precedence over `version`. */\n archive?: string;\n /** Exact registry version, pinned when the entry has no archive. */\n version?: string;\n dependencies: readonly string[];\n}\n\ninterface PackageCatalog {\n packages: ReadonlyMap<string, PackageCatalogEntry>;\n /** Feature packages Po installs out of the box, by name. */\n install: readonly string[];\n}\n\nconst EMPTY_CATALOG: PackageCatalog = { packages: new Map(), install: [] };\n\nfunction stringList(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const strings = value.filter((item): item is string => typeof item === 'string');\n return strings.length === value.length ? strings : undefined;\n}\n\nfunction defaultBundledCatalogPath(): string | undefined {\n try {\n return path.join(poPackageRoot(), ...BUNDLED_CATALOG_SEGMENTS);\n } catch {\n // A bundle with no locatable Po package root has no bundled catalogue to read.\n return undefined;\n }\n}\n\n/**\n * The first catalogue present: `PO_PACKAGE_CATALOG` (desktop's archives), then the one\n * a release bundles into the CLI. With neither, the runtime installs only what roots name.\n */\nasync function packageCatalogPath(environment: NodeJS.ProcessEnv): Promise<string | undefined> {\n const configured = environment[PACKAGE_CATALOG_ENV]?.trim();\n if (configured) return configured;\n const bundledCatalogPath = defaultBundledCatalogPath();\n if (bundledCatalogPath === undefined) return undefined;\n return fs.access(bundledCatalogPath).then(\n () => bundledCatalogPath,\n (error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n },\n );\n}\n\nasync function readPackageCatalog(manifestPath: string | undefined): Promise<PackageCatalog> {\n if (!manifestPath) return EMPTY_CATALOG;\n const parsed: unknown = JSON.parse(await fs.readFile(manifestPath, 'utf8'));\n if (!isRecord(parsed) || parsed.version !== 1 || !isRecord(parsed.packages)) {\n throw new Error(`Unsupported Po package catalog: ${manifestPath}`);\n }\n const packages = new Map<string, PackageCatalogEntry>();\n for (const [name, value] of Object.entries(parsed.packages)) {\n if (\n !isRecord(value) ||\n !Array.isArray(value.dependencies) ||\n (value.archive !== undefined && typeof value.archive !== 'string') ||\n (value.version !== undefined && typeof value.version !== 'string') ||\n (value.archive === undefined && value.version === undefined)\n ) {\n throw new Error(`Invalid package entry for ${name} in ${manifestPath}`);\n }\n const dependencies = stringList(value.dependencies);\n if (!dependencies) throw new Error(`Invalid dependencies for ${name} in ${manifestPath}`);\n const version = typeof value.version === 'string' ? value.version : undefined;\n if (typeof value.archive !== 'string') {\n packages.set(name, { version, dependencies });\n continue;\n }\n const archive = path.resolve(path.dirname(manifestPath), value.archive);\n await fs.access(archive).catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') throw new Error(`Po package catalog archive is missing: ${archive}`);\n throw error;\n });\n packages.set(name, { archive, version, dependencies });\n }\n const install = parsed.install === undefined ? [] : stringList(parsed.install);\n if (!install) throw new Error(`Invalid install list in ${manifestPath}`);\n const unknown = install.filter((name) => !packages.has(name));\n if (unknown.length > 0) throw new Error(`Po package catalog installs unlisted package(s): ${unknown.join(', ')}`);\n return { packages, install };\n}\n\n/**\n * The catalogue's `install` list as exact `name@version` specifiers for\n * `EnsureLayerPackagesOptions.specifiers`; empty when no catalogue is present.\n */\nexport async function catalogInstallSpecifiers(environment: NodeJS.ProcessEnv = process.env): Promise<string[]> {\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n return catalog.install.map((name) => {\n const version = catalog.packages.get(name)?.version;\n return version ? `${name}@${version}` : name;\n });\n}\n\n/**\n * The installed package roots of the catalogue's `install` list, resolved the way a root\n * resolves a bare name (its own node_modules, then the shared runtime). The global web build\n * covers them, so every first-party plugin has a slot; a name not installed yet is left out.\n */\nexport async function catalogPackageRoots(\n globalRoot: string,\n environment: NodeJS.ProcessEnv = process.env,\n): Promise<string[]> {\n const roots: string[] = [];\n for (const name of (await readPackageCatalog(await packageCatalogPath(environment))).install) {\n const manifest = consumerPackageEntry(`${name}/${PACKAGE_MANIFEST}`, globalRoot, environment);\n if (manifest !== undefined) roots.push(path.dirname(await fs.realpath(manifest)));\n }\n return roots;\n}\n\n/** SHA-256 of the catalogue file in use, or `none` when no catalogue is present. */\nexport async function packageCatalogHash(environment: NodeJS.ProcessEnv = process.env): Promise<string> {\n const catalogPath = await packageCatalogPath(environment);\n if (!catalogPath) return 'none';\n return crypto\n .createHash('sha256')\n .update(await fs.readFile(catalogPath))\n .digest('hex');\n}\n\n/** Exact target per catalogue name: its staged workspace for an archive, else its registry version. */\nfunction catalogTargets(catalog: PackageCatalog): Map<string, string> {\n return new Map(\n [...catalog.packages].flatMap(([name, entry]) => {\n if (entry.archive !== undefined) return [[name, CATALOG_WORKSPACE_TARGET] as const];\n return entry.version !== undefined ? [[name, entry.version] as const] : [];\n }),\n );\n}\n\nconst TAR_BLOCK_SIZE = 512;\nconst TAR_EXECUTABLE_BITS = 0o111;\n\nfunction tarString(block: Buffer, start: number, length: number): string {\n const field = block.subarray(start, start + length);\n const end = field.indexOf(0);\n return field.subarray(0, end === -1 ? field.length : end).toString('utf8');\n}\n\nfunction tarNumber(block: Buffer, start: number, length: number): number {\n const field = block.subarray(start, start + length);\n // GNU base-256: the high bit of the first byte marks a big-endian binary number.\n if ((field[0]! & 0x80) !== 0) return field.subarray(1).reduce((value, byte) => value * 256 + byte, field[0]! & 0x7f);\n const text = tarString(block, start, length).trim();\n return text === '' ? 0 : Number.parseInt(text, 8);\n}\n\n/** The `path` record of a pax extended header, if it has one. */\nfunction paxPath(data: Buffer): string | undefined {\n let found: string | undefined;\n let offset = 0;\n while (offset < data.length) {\n const space = data.indexOf(0x20, offset);\n if (space === -1) break;\n const length = Number.parseInt(data.subarray(offset, space).toString('utf8'), 10);\n if (!Number.isFinite(length) || length <= 0) break;\n const record = data.subarray(space + 1, offset + length - 1).toString('utf8');\n const separator = record.indexOf('=');\n if (record.slice(0, separator) === 'path') found = record.slice(separator + 1);\n offset += length;\n }\n return found;\n}\n\n/**\n * Unpacks a gzipped npm package archive into `destination`, dropping the archive's top\n * directory (`package/`) as npm does. Only files and directories are written: npm package\n * archives carry no links, and an entry that would land outside `destination` is refused.\n */\nasync function extractPackageArchive(archive: string, destination: string): Promise<void> {\n const data = zlib.gunzipSync(await fs.readFile(archive));\n let offset = 0;\n let nextPath: string | undefined;\n while (offset + TAR_BLOCK_SIZE <= data.length) {\n const header = data.subarray(offset, offset + TAR_BLOCK_SIZE);\n if (header.every((byte) => byte === 0)) break;\n const size = tarNumber(header, 124, 12);\n const type = String.fromCharCode(header[156]!);\n const body = data.subarray(offset + TAR_BLOCK_SIZE, offset + TAR_BLOCK_SIZE + size);\n offset += TAR_BLOCK_SIZE + Math.ceil(size / TAR_BLOCK_SIZE) * TAR_BLOCK_SIZE;\n if (type === 'x' || type === 'L') {\n nextPath = type === 'x' ? (paxPath(body) ?? nextPath) : tarString(body, 0, body.length);\n continue;\n }\n if (type === 'g') continue;\n const prefix = tarString(header, 345, 155);\n const name = nextPath ?? (prefix ? `${prefix}/${tarString(header, 0, 100)}` : tarString(header, 0, 100));\n nextPath = undefined;\n if (type !== '0' && type !== '\\0' && type !== '5') continue;\n const relative = name.split('/').slice(1).join('/');\n if (relative === '') continue;\n const target = path.resolve(destination, relative);\n if (!target.startsWith(`${destination}${path.sep}`)) {\n throw new Error(`Po package catalog archive ${archive} has an entry outside the package: ${name}`);\n }\n if (type === '5') {\n await fs.mkdir(target, { recursive: true });\n continue;\n }\n await fs.mkdir(path.dirname(target), { recursive: true });\n const executable = (tarNumber(header, 100, 8) & TAR_EXECUTABLE_BITS) !== 0;\n await fs.writeFile(target, body, { mode: executable ? 0o755 : 0o644 });\n }\n}\n\n/** Dependency fields of a staged manifest that may name another catalogue package. */\nconst STAGED_DEPENDENCY_FIELDS = ['dependencies', 'optionalDependencies', 'peerDependencies'] as const;\n\n/**\n * Unpacks one catalogue archive into `<runtime>/catalog/<hash>` and returns that directory\n * relative to the runtime, with the catalogue names its manifest depends on.\n *\n * upm only installs a package from a directory as a workspace: a `file:` archive takes its own\n * dependencies from the registry, so one catalogue archive could not depend on another. In the\n * staged manifest every dependency on another catalogue archive becomes `workspace:*`, so the\n * catalogue's copy wins whatever range the package declared, and `devDependencies`, which a\n * workspace would otherwise install, are dropped. The hash covers the archive bytes and the\n * catalogue's archive names, everything that rewrite reads, so a staged directory is reused.\n */\nasync function stageCatalogArchive(\n runtimeDirectory: string,\n archive: string,\n archiveNames: ReadonlySet<string>,\n): Promise<{ relative: string; dependencies: string[] }> {\n const hash = crypto\n .createHash('sha256')\n .update(await fs.readFile(archive))\n .update(`\\0${[...archiveNames].sort().join('\\n')}`)\n .digest('hex');\n const relative = `${CATALOG_STAGING_DIRECTORY}/${hash}`;\n const directory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY, hash);\n const stagedManifest = path.join(directory, PACKAGE_MANIFEST);\n const existing = await fs.readFile(stagedManifest, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (existing === undefined) {\n const temporary = `${directory}.${String(process.pid)}.${crypto.randomUUID()}.tmp`;\n try {\n await extractPackageArchive(archive, temporary);\n const manifestPath = path.join(temporary, PACKAGE_MANIFEST);\n const bytes = await fs.readFile(manifestPath, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') throw new Error(`Po package catalog archive has no package.json: ${archive}`);\n throw error;\n });\n const manifest: unknown = JSON.parse(bytes);\n if (!isRecord(manifest)) throw new Error(`Po package catalog archive has an invalid package.json: ${archive}`);\n delete manifest.devDependencies;\n for (const field of STAGED_DEPENDENCY_FIELDS) {\n if (!isRecord(manifest[field])) continue;\n const declared = { ...manifest[field] };\n for (const name of Object.keys(declared)) {\n if (archiveNames.has(name)) declared[name] = CATALOG_WORKSPACE_TARGET;\n }\n manifest[field] = declared;\n }\n await fs.writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\\n`);\n try {\n await fs.rename(temporary, directory);\n } catch (error) {\n // Another process staged the same bytes first; its copy is identical.\n await fs.access(stagedManifest).catch(() => {\n throw error;\n });\n }\n } finally {\n await fs.rm(temporary, { recursive: true, force: true });\n }\n }\n const staged = recordValue(JSON.parse(existing ?? (await fs.readFile(stagedManifest, 'utf8'))));\n const dependencies = STAGED_DEPENDENCY_FIELDS.flatMap((field) => Object.keys(recordValue(staged[field])));\n return { relative, dependencies: dependencies.filter((name) => archiveNames.has(name)) };\n}\n\n/**\n * Stages the archive of every named catalogue package and of every catalogue package those\n * name in turn, since a staged manifest's `workspace:*` needs that workspace present. The\n * result, name to staged directory, feeds `ensureManagedPackageManifest`.\n */\nasync function stageCatalogArchives(\n runtimeDirectory: string,\n catalog: PackageCatalog,\n names: Iterable<string>,\n): Promise<Record<string, string>> {\n const archiveNames = new Set(\n [...catalog.packages].flatMap(([name, entry]) => (entry.archive === undefined ? [] : [name])),\n );\n const staged: Record<string, string> = {};\n const pending = [...names].filter((name) => archiveNames.has(name));\n while (pending.length > 0) {\n const name = pending.shift()!;\n if (Object.hasOwn(staged, name)) continue;\n const { relative, dependencies } = await stageCatalogArchive(\n runtimeDirectory,\n catalog.packages.get(name)!.archive!,\n archiveNames,\n );\n staged[name] = relative;\n pending.push(...dependencies);\n }\n return staged;\n}\n\n/**\n * Removes staged archives the runtime manifest no longer lists as workspaces, and returns their\n * folder names. An install never calls this: a running server imports from these folders (its\n * `.po-snapshots` live there), so sync prunes them under the same gate as the runtime store.\n */\nexport async function pruneStagedCatalogArchives(runtimeDirectory: string): Promise<string[]> {\n const stagingDirectory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY);\n const entries = await fs.readdir(stagingDirectory).catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return [];\n throw error;\n });\n const { manifest } = await readRuntimeManifest(path.join(runtimeDirectory, PACKAGE_MANIFEST));\n const kept = new Set((stringList(manifest.workspaces) ?? []).map((relative) => path.basename(relative)));\n return Promise.all(\n entries\n .filter((entry) => !kept.has(entry))\n .map(async (entry) => {\n await fs.rm(path.join(stagingDirectory, entry), { recursive: true, force: true });\n return entry;\n }),\n );\n}\n\n/** Splits `name@version` (scoped or not); the version is absent for a bare name or subpath. */\nfunction splitVersionedSpecifier(specifier: string): { name: string; version?: string } {\n const separator = specifier.indexOf('@', specifier.startsWith('@') ? 1 : 0);\n if (separator === -1) return { name: splitPackageSpecifier(specifier).name };\n return { name: specifier.slice(0, separator), version: specifier.slice(separator + 1) };\n}\n\nfunction npmSources(\n specifiers: readonly string[],\n catalog: PackageCatalog,\n targets: ReadonlyMap<string, string>,\n includeCatalogDependencies = false,\n): string[] {\n const names = [...new Set(specifiers.map((specifier) => splitPackageSpecifier(specifier).name))];\n if (includeCatalogDependencies) {\n for (let index = 0; index < names.length; index += 1) {\n for (const dependency of catalog.packages.get(names[index]!)?.dependencies ?? []) {\n if (!names.includes(dependency)) names.push(dependency);\n }\n }\n }\n return names.map((name) => {\n const target = targets.get(name);\n return `${NPM_SOURCE_PREFIX}${name}${target ? `@${target}` : ''}`;\n });\n}\n\nfunction pluralize(count: number, noun: string): string {\n return `${count} ${noun}${count === 1 ? '' : 's'}`;\n}\n\n/** Version of a package inside the shared runtime, absent when Po did not install it there. */\nasync function managedPackageVersion(runtimeDirectory: string, name: string): Promise<string | undefined> {\n const manifestPath = path.join(runtimeDirectory, NODE_MODULES, name, PACKAGE_MANIFEST);\n try {\n const parsed: unknown = JSON.parse(await fs.readFile(manifestPath, 'utf8'));\n return isRecord(parsed) && typeof parsed.version === 'string' ? parsed.version : undefined;\n } catch {\n // An unreadable manifest carries the same meaning as an absent one: nothing\n // usable is installed, so the caller treats the package as uninstalled.\n return undefined;\n }\n}\n\nfunction errorCode(error: unknown): unknown {\n return typeof error === 'object' && error !== null ? (error as { code?: unknown }).code : undefined;\n}\n\n/**\n * Installs the runtime, and when the registry cannot be reached installs it again offline:\n * an unchanged lockfile whose packages the store already holds needs no network.\n */\nasync function installWithOfflineRetry(\n install: NonNullable<LayerPackageInstallerDependencies['install']>,\n options: InstallRuntimePackagesOptions,\n onProgress: ((message: string) => void) | undefined,\n): Promise<void> {\n try {\n await install(options);\n } catch (error) {\n const code = errorCode(error);\n if (typeof code !== 'string' || !NETWORK_FAILURE_CODES.has(code)) throw error;\n onProgress?.(`the registry is unreachable (${code}); installing offline from the store`);\n try {\n await install({ ...options, preferOffline: false, offline: true });\n } catch {\n // The offline attempt only ever narrows the original failure: the network error\n // explains why the install could not complete, an EOFFLINE miss does not.\n throw error;\n }\n }\n}\n\ninterface CheckedPackage {\n name: string;\n from: string;\n to?: string;\n failure?: string;\n}\n\n/**\n * Compares every package sync installed against the registry.\n *\n * Only the shared runtime is consulted: a package that resolves from the\n * repository's own modules is not sync's to move, and a package that is not\n * installed yet is already covered by the missing-package path.\n */\nasync function resolveUpdates(\n runtimeDirectory: string,\n sources: readonly string[],\n publishedVersion: (name: string) => Promise<string>,\n onProgress: ((message: string) => void) | undefined,\n): Promise<Pick<LayerPackageResult, 'updated' | 'unchecked'>> {\n const managed = (\n await Promise.all(\n sources.map(async (source) => ({\n name: packageName(source),\n from: await managedPackageVersion(runtimeDirectory, packageName(source)),\n })),\n )\n ).filter((entry): entry is { name: string; from: string } => entry.from !== undefined);\n const checked: CheckedPackage[] = await Promise.all(\n managed.map(async (entry) => {\n try {\n return { ...entry, to: await publishedVersion(entry.name) };\n } catch (error) {\n return { ...entry, failure: (error instanceof Error ? error.message : String(error)).split('\\n')[0] };\n }\n }),\n );\n\n const updated: LayerPackageUpdate[] = [];\n const unchecked: string[] = [];\n for (const entry of checked) {\n if (entry.to === undefined) {\n unchecked.push(entry.name);\n onProgress?.(`kept ${entry.name} ${entry.from}: ${entry.failure ?? 'no published version'}`);\n continue;\n }\n if (entry.to === entry.from) continue;\n updated.push({ name: entry.name, from: entry.from, to: entry.to });\n onProgress?.(`${entry.name} ${entry.from} -> ${entry.to}`);\n }\n return { updated, unchecked };\n}\n\n/**\n * Installs the selected layer packages a root cannot resolve into the shared runtime,\n * `<po home>/runtime`, and verifies they now resolve.\n *\n * The runtime manifest is the union of what every root asked for. A root adds the\n * packages it is missing; a package it already resolves from its own node_modules stays\n * out unless an earlier run put it there. One name has one version: an exact target\n * (a sync update, a catalog archive or registry pin) replaces the declared range, last\n * writer wins, and a plain `*` never replaces a range already declared.\n *\n * `specifiers` and `exactManifest` only add behaviour: without them, and without a\n * catalogue, a run behaves as it always has.\n */\nexport async function ensureLayerPackages(\n options: EnsureLayerPackagesOptions,\n dependencies: LayerPackageInstallerDependencies = {},\n): Promise<LayerPackageResult> {\n const environment = options.environment ?? process.env;\n const homeDirectory = environment.HOME ?? os.homedir();\n const poHome = poHomeDirectory(homeDirectory, environment);\n const runtimeDirectory = poRuntimeDirectory(homeDirectory, environment);\n // The root's own .npmrc routes and authenticates the registries its layers name.\n const npmrcFiles = [path.join(options.repoRoot, '.npmrc')];\n const resolvers = dependencies.resolvers ?? createLayerResolvers(options.repoRoot, environment);\n const external = (specifier: string): boolean => testPackageRoot(packageName(specifier), environment) === undefined;\n const configured = configuredPackageSpecifiers(options.config, options.layers).filter(external);\n const missing = configured.filter((specifier) => resolvePackageEntries(resolvers, specifier) === undefined);\n const declared = await declaredRuntimePackages(runtimeDirectory);\n const managed = configured.filter(\n (specifier) => missing.includes(specifier) || declared.has(splitPackageSpecifier(specifier).name),\n );\n const requested = (options.specifiers ?? []).filter(external).map(splitVersionedSpecifier);\n if (managed.length === 0 && requested.length === 0 && options.exactManifest !== true) {\n return { installed: [], updated: [], unchecked: [] };\n }\n\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n const pins = catalogTargets(catalog);\n for (const { name, version } of requested) {\n if (version !== undefined && catalog.packages.get(name)?.archive === undefined) pins.set(name, version);\n }\n // A requested package is missing until the runtime holds it at the version it is pinned to.\n const requestedMissing: string[] = [];\n for (const { name, version } of requested) {\n const installed = await managedPackageVersion(runtimeDirectory, name);\n const entry = catalog.packages.get(name);\n const expected = entry?.archive === undefined ? version : entry.version;\n if (installed === undefined || (expected !== undefined && installed !== expected)) requestedMissing.push(name);\n }\n const missingSources = npmSources([...missing, ...requestedMissing], catalog, pins);\n const sources = npmSources([...managed, ...requested.map(({ name }) => name)], catalog, pins, true).filter(external);\n const missingCount = missing.length + requestedMissing.length;\n\n // Refresh never moves a pinned name: catalogue entries and versioned specifiers stay put.\n const fixedNames = new Set([\n ...catalog.packages.keys(),\n ...requested.filter(({ version }) => version !== undefined).map(({ name }) => name),\n ]);\n const registrySources = sources.filter((source) => !fixedNames.has(packageName(source)));\n const { updated, unchecked } = options.refresh\n ? await resolveUpdates(\n runtimeDirectory,\n registrySources,\n dependencies.publishedVersion ?? ((name) => resolveNewest(name, { dir: runtimeDirectory, poHome, npmrcFiles })),\n options.onProgress,\n )\n : { updated: [], unchecked: [] };\n const targets = new Map(\n sources.flatMap((source) => {\n const target = pins.get(packageName(source));\n return target ? [[packageName(source), target] as const] : [];\n }),\n );\n for (const update of updated) targets.set(update.name, update.to);\n // A kept manifest still declares names earlier runs added; their archives are staged too.\n const stagedNames = new Set([...sources.map(packageName), ...(options.exactManifest === true ? [] : declared)]);\n const staged = await stageCatalogArchives(runtimeDirectory, catalog, stagedNames);\n const manifestChanged = await ensureManagedPackageManifest(\n runtimeDirectory,\n sources,\n targets,\n staged,\n options.exactManifest === true,\n );\n if (missingCount === 0 && !manifestChanged) return { installed: [], updated: [], unchecked };\n\n options.onProgress?.(\n `installing ${\n updated.length > 0\n ? pluralize(updated.length, 'update')\n : missingCount > 0\n ? pluralize(missingCount, 'missing package')\n : 'the package manifest'\n }`,\n );\n try {\n // One install reconciles the complete dependency set written to package.json.\n await installWithOfflineRetry(\n dependencies.install ?? installRuntimePackages,\n {\n dir: runtimeDirectory,\n poHome,\n npmrcFiles,\n // A launch never waits on registry revalidation; sync is the command that refreshes.\n preferOffline: options.refresh !== true,\n log: (message, level) => {\n if (level === 'warn') options.onProgress?.(message);\n },\n },\n options.onProgress,\n );\n } catch (error) {\n const attempted = manifestChanged ? sources : missingSources;\n throw new Error(\n `Failed to reconcile Po layer package(s): ${attempted.join(', ')}: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n\n const unresolved = missing.filter((specifier) => !resolvePackageEntries(resolvers, specifier)?.length);\n if (unresolved.length > 0) {\n throw new Error(\n `Installed Po layer package(s) did not expose the configured Pi extension: ${unresolved.join(', ')}`,\n );\n }\n return { installed: missingSources, updated, unchecked };\n}\n\n/** One selector per name in the shared runtime. Caller holds the sync lock throughout. */\nexport async function ensureRuntimeImportPackage(\n name: string,\n version: string,\n options: { homeDirectory: string; environment: Readonly<Record<string, string | undefined>> },\n): Promise<void> {\n const environment = { ...options.environment, HOME: options.homeDirectory };\n const poHome = poHomeDirectory(options.homeDirectory, environment);\n const directory = poRuntimeDirectory(options.homeDirectory, environment);\n const manifestPath = path.join(directory, PACKAGE_MANIFEST);\n const { manifest } = await readRuntimeManifest(manifestPath);\n const declared = recordValue(manifest.dependencies);\n const imports = recordValue(manifest.poCodemodeDependencies);\n const imported = recordValue(imports[name]);\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n if (catalog.packages.has(name) || (Object.hasOwn(declared, name) && declared[name] !== imported.selector)) {\n throw new Error(\n `Cannot import ${name}: Po manages this runtime dependency (${JSON.stringify(declared[name] ?? 'catalogue')}).`,\n );\n }\n if (Object.hasOwn(imports, name) && imported.selector !== version) {\n throw new Error(`Cannot import ${name}@${version}: the hub already uses ${name}@${String(imported.selector)}.`);\n }\n const installed = await managedPackageVersion(directory, name);\n if (declared[name] === version && installed !== undefined && imported.resolved === installed) return;\n // Only a successful reconciliation is cacheable, not the manifest upm writes ahead of a failed install.\n manifest.poCodemodeDependencies = { ...imports, [name]: { selector: version } };\n await writeFileAtomic(\n createNodePlatform().env(directory),\n manifestPath,\n `${JSON.stringify(manifest, null, 2)}\\n`,\n BACKGROUND_CONTEXT,\n );\n const pins = new Map([[name, version]]);\n const sources = npmSources([`${name}@${version}`], catalog, pins, true);\n const staged = await stageCatalogArchives(\n directory,\n catalog,\n new Set([...sources.map(packageName), ...Object.keys(declared)]),\n );\n await ensureManagedPackageManifest(directory, sources, pins, staged);\n await installWithOfflineRetry(installRuntimePackages, { dir: directory, poHome, preferOffline: true }, undefined);\n const resolved = await managedPackageVersion(directory, name);\n if (resolved === undefined) throw new Error(`Runtime import ${name}@${version} was not installed.`);\n const reconciled = (await readRuntimeManifest(manifestPath)).manifest;\n reconciled.poCodemodeDependencies = {\n ...recordValue(reconciled.poCodemodeDependencies),\n [name]: { selector: version, resolved },\n };\n await writeFileAtomic(\n createNodePlatform().env(directory),\n manifestPath,\n `${JSON.stringify(reconciled, null, 2)}\\n`,\n BACKGROUND_CONTEXT,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;AAC1B,MAAM,wBAAwB;AAC9B,MAAM,6BAA6B;;AAEnC,MAAM,2BAA2B;;AAEjC,MAAM,4BAA4B;AA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A,MAAM,uBAAO,IAAI,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC;CACtC,MAAM,UAAU,WAAW,CAAC,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,MAAM,IAAI;CAMtE,MAAM,6BAA6B,WAAW,SAAS,MAAM,MALxC,qBACnB,WACA,yBACA,IAAI,IAAI,CAAC,GAAG,QAAQ,IAAI,WAAW,GAAG,GAAG,OAAO,KAAK,QAAQ,CAAC,CAAC,CACjE,CACmE;CACnE,MAAM,wBAAwBY,mCAAAA,wBAAwB;EAAE,KAAK;EAAW;EAAQ,eAAe;CAAK,GAAG,KAAA,CAAS;CAChH,MAAM,WAAW,MAAM,sBAAsB,WAAW,IAAI;CAC5D,IAAI,aAAa,KAAA,GAAW,MAAM,IAAI,MAAM,kBAAkB,KAAK,GAAG,QAAQ,oBAAoB;CAClG,MAAM,cAAc,MAAM,oBAAoB,YAAY,EAAA,CAAG;CAC7D,WAAW,yBAAyB;EAClC,GAAG,YAAY,WAAW,sBAAsB;GAC/C,OAAO;GAAE,UAAU;GAAS;EAAS;CACxC;CACA,OAAA,GAAMd,4BAAAA,gBAAAA,EAAAA,GACJC,gCAAAA,mBAAAA,CAAmB,CAAC,CAAC,IAAI,SAAS,GAClC,cACA,GAAG,KAAK,UAAU,YAAY,MAAM,CAAC,EAAE,KACvCC,4BAAAA,kBACF;AACF"}
1
+ {"version":3,"file":"index.cjs","names":["isLocalPackageSpecifier","fs","path","writeFileAtomic","createNodePlatform","BACKGROUND_CONTEXT","splitPackageSpecifier","poPackageRoot","consumerPackageEntry","crypto","zlib","os","poHomeDirectory","poRuntimeDirectory","createLayerResolvers","testPackageRoot","resolveNewest","installRuntimePackages"],"sources":["../../../../src/composition/layerPackageInstaller/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport os from 'node:os';\nimport path from 'node:path';\nimport zlib from 'node:zlib';\n\nimport { isLocalPackageSpecifier, type MajorModesConfig } from '@agimon-ai/po-config/majorModes';\nimport { consumerPackageEntry, splitPackageSpecifier, testPackageRoot } from '@agimon-ai/po-core/moduleResolution';\nimport { createNodePlatform } from '@agimon-ai/po-core/nodePlatform';\nimport { BACKGROUND_CONTEXT, writeFileAtomic } from '@agimon-ai/po-core/platform';\nimport {\n installRuntimePackages,\n type InstallRuntimePackagesOptions,\n resolveNewest,\n} from '@agimon-ai/po-core/runtimePackages';\nimport { poHomeDirectory, poRuntimeDirectory } from '@agimon-ai/po-core/runtimePiSettings';\n\nimport { poPackageRoot } from '../../builders/cli/entryResolution';\nimport { createLayerResolvers, type ExtensionLayerResolvers } from '../../builders/cli/extensionAssembler';\n\nconst NPM_SOURCE_PREFIX = 'npm:';\nconst FILE_SPECIFIER_PREFIX = 'file:';\nconst WORKSPACE_SPECIFIER_PREFIX = 'workspace:';\n/** Root target of a staged catalogue archive: always the staged workspace, never the registry. */\nconst CATALOG_WORKSPACE_TARGET = 'workspace:*';\n/** Where catalogue archives are unpacked inside the runtime, one directory per archive hash. */\nconst CATALOG_STAGING_DIRECTORY = 'catalog';\nconst RUNTIME_PACKAGE_NAME = 'po-runtime';\nconst UNPINNED_PACKAGE_RANGE = '*';\nconst PACKAGE_MANIFEST = 'package.json';\nconst NODE_MODULES = 'node_modules';\nconst PACKAGE_CATALOG_ENV = 'PO_PACKAGE_CATALOG';\n/** The registry catalogue a release writes into the CLI package: `<package root>/dist/catalog/index.json`. */\nconst BUNDLED_CATALOG_SEGMENTS = ['dist', 'catalog', 'index.json'] as const;\n/** upm error codes that mean the registry could not be reached, so the store may still answer. */\nconst NETWORK_FAILURE_CODES = new Set(['ENETWORK', 'ETIMEDOUT', 'EREGISTRY']);\n\nfunction overridePackageName(selector: string): string {\n const separatorIndex = selector.indexOf('@', selector.startsWith('@') ? 1 : 0);\n return separatorIndex === -1 ? selector : selector.slice(0, separatorIndex);\n}\n\n/**\n * Runtime compatibility pins and same-major patches for current foundation packages.\n * Package managers only honor overrides from the install root, so published extensions\n * cannot carry these fixes in their own manifests.\n */\nexport const SAFE_TRANSITIVE_OVERRIDES = {\n // ponytail: Pin for Pi 1.5.0's declaration API; advance with the host's Pi version.\n '@earendil-works/pi-codemode': '1.5.0',\n '@hono/node-server@2.0.0 - 2.0.9': '^2.0.10',\n '@opentelemetry/core@2.0.0 - 2.7.999': '2.8.0',\n 'brace-expansion@1.0.0 - 1.1.20': '^1.1.21',\n 'brace-expansion@5.0.0 - 5.0.11': '^5.0.12',\n 'hono@4.0.0 - 4.13.7': '4.13.8',\n 'js-yaml@4.0.0 - 4.3.1': '^4.3.2',\n 'js-yaml@5.0.0 - 5.2.1': '^5.2.2',\n 'liquidjs@10.0.0 - 10.27.1': '^10.27.2',\n 'protobufjs@8.0.0 - 8.7.1': '^8.7.2',\n 'undici@7.0.0 - 7.29.0': '^7.29.1',\n} as const satisfies Readonly<Record<string, string>>;\n\nconst SAFE_TRANSITIVE_PACKAGE_NAMES = new Set(Object.keys(SAFE_TRANSITIVE_OVERRIDES).map(overridePackageName));\n\nexport interface EnsureLayerPackagesOptions {\n /**\n * The Po root whose layers name the packages. Its own node_modules chain is\n * resolved first; what it cannot provide is installed into the one runtime\n * every root shares, `<po home>/runtime`.\n */\n repoRoot: string;\n config: MajorModesConfig;\n layers: readonly string[];\n environment?: NodeJS.ProcessEnv;\n /**\n * Move every managed package to its newest published version.\n *\n * Launch installs what a selection needs and nothing more, so a session never\n * pays for a registry round trip. Sync is the explicit maintenance command and\n * is the only caller that asks for this.\n */\n refresh?: boolean;\n /**\n * Packages installed into the runtime whatever the root resolves itself, such as the\n * catalogue's `install` list. A `name@version` specifier pins that exact version; a\n * catalogue archive for the name still wins. Refresh never moves a pinned name.\n */\n specifiers?: readonly string[];\n /**\n * Make the runtime manifest declare exactly this run's packages (the specifiers, the\n * selected names and their catalogue dependencies), so pruning can drop anything else.\n * Without it the manifest only grows.\n */\n exactManifest?: boolean;\n /** Receives one human-readable line per package decision. */\n onProgress?: (message: string) => void;\n}\n\nexport interface LayerPackageInstallerDependencies {\n /** Install seam; the default installs `<po home>/runtime` with upm. */\n install?: (options: InstallRuntimePackagesOptions) => Promise<unknown>;\n resolvers?: ExtensionLayerResolvers;\n /** Registry lookup seam; the default resolves the newest allowed version with upm. */\n publishedVersion?: (name: string) => Promise<string>;\n}\n\n/** One managed package moving from the installed version to the newest published one. */\nexport interface LayerPackageUpdate {\n name: string;\n from: string;\n to: string;\n}\n\nexport interface LayerPackageResult {\n /** Sources installed because a configured extension could not be resolved. */\n installed: string[];\n /** Packages this run moved to a newer published version. */\n updated: LayerPackageUpdate[];\n /** Packages left at the installed version because the registry could not be read. */\n unchecked: string[];\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction recordValue(value: unknown): Record<string, unknown> {\n return isRecord(value) ? { ...value } : {};\n}\n\nfunction withoutConflictingTransitiveOverrides(value: unknown): Record<string, unknown> {\n const overrides = recordValue(value);\n for (const [selector, replacement] of Object.entries(overrides)) {\n if (SAFE_TRANSITIVE_PACKAGE_NAMES.has(overridePackageName(selector))) {\n delete overrides[selector];\n } else if (isRecord(replacement)) {\n overrides[selector] = withoutConflictingTransitiveOverrides(replacement);\n }\n }\n return overrides;\n}\n\n/** Earlier versions overrode catalog packages with relative `file:` targets; any other override is not Po's. */\nfunction withoutCatalogOverrides(overrides: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(overrides).filter(\n ([, replacement]) => !(typeof replacement === 'string' && replacement.startsWith(FILE_SPECIFIER_PREFIX)),\n ),\n );\n}\n\n/** The published (non-local, required) package specifiers the default and the given layers name. */\nfunction configuredPackageSpecifiers(config: MajorModesConfig, layers: readonly string[]): string[] {\n const specifiers = new Set<string>();\n const selectedDefinitions = [\n ...(config.default ? [config.default] : []),\n ...layers.map((layerName) => {\n const layer = config.layers[layerName];\n if (!layer) throw new Error(`Unknown layer: ${layerName}`);\n return layer;\n }),\n ];\n for (const layer of selectedDefinitions) {\n for (const configured of layer.packages ?? []) {\n const specifier = typeof configured === 'string' ? configured : configured.name;\n const optional = typeof configured !== 'string' && configured.optional === true;\n if (!optional && !isLocalPackageSpecifier(specifier)) specifiers.add(specifier);\n }\n }\n return [...specifiers];\n}\n\nfunction resolvePackageEntries(resolvers: ExtensionLayerResolvers, specifier: string): string[] | undefined {\n const entries = resolvers.optionalPackageEntries?.(specifier);\n if (entries !== undefined) return entries;\n const entry = resolvers.optionalPackageEntry(specifier);\n return entry ? [entry] : undefined;\n}\n\nasync function readRuntimeManifest(\n manifestPath: string,\n): Promise<{ current: string | undefined; manifest: Record<string, unknown> }> {\n const current = await fs.readFile(manifestPath, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (current === undefined) return { current, manifest: { name: RUNTIME_PACKAGE_NAME, private: true } };\n const parsed: unknown = JSON.parse(current);\n if (!isRecord(parsed)) throw new Error(`Po runtime package manifest at ${manifestPath} must be a JSON object.`);\n return { current, manifest: parsed };\n}\n\n/** Names the runtime manifest already declares: what earlier runs, from any root, installed there. */\nasync function declaredRuntimePackages(runtimeDirectory: string): Promise<Set<string>> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n return new Set(Object.keys(recordValue((await readRuntimeManifest(manifestPath)).manifest.dependencies)));\n}\n\n/**\n * Adds a package set and the patched transitive policy to the shared runtime manifest.\n *\n * `targets` pins names to exact versions or `workspace:*`. `catalogWorkspaces` maps each\n * staged catalogue archive's name to its directory relative to the runtime; the manifest\n * lists exactly those directories as its `workspaces`, so a catalogue package's dependency\n * on another one links the staged copy instead of reaching the registry. Both `overrides` and\n * `pnpm.overrides` are written; upm reads both.\n * With `exact`, declared names outside `sources` are dropped instead of kept.\n */\nexport async function ensureManagedPackageManifest(\n runtimeDirectory: string,\n sources: readonly string[],\n targets: ReadonlyMap<string, string> = new Map(),\n catalogWorkspaces: Readonly<Record<string, string>> = {},\n exact = false,\n): Promise<boolean> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n const { current, manifest } = await readRuntimeManifest(manifestPath);\n\n const declared = recordValue(manifest.dependencies);\n const sourceNames = new Set(sources.map(packageName));\n const dependencies = exact\n ? Object.fromEntries(Object.entries(declared).filter(([name]) => sourceNames.has(name)))\n : declared;\n // Every root shares this manifest, so a catalog archive another process staged (a desktop\n // build, say) may not exist for this one: without a staged copy here it falls back to the\n // registry, which keeps the whole set installable. `file:` targets are what earlier\n // versions wrote for archives.\n for (const [name, declared] of Object.entries(dependencies)) {\n if (Object.hasOwn(catalogWorkspaces, name)) {\n dependencies[name] = CATALOG_WORKSPACE_TARGET;\n } else if (\n typeof declared === 'string' &&\n (declared.startsWith(FILE_SPECIFIER_PREFIX) || declared.startsWith(WORKSPACE_SPECIFIER_PREFIX))\n ) {\n dependencies[name] = UNPINNED_PACKAGE_RANGE;\n }\n }\n for (const source of sources) {\n const name = packageName(source);\n const target = targets.get(name);\n // An exact target is what makes an update reach the store: a package manager keeps a\n // locked version whenever the recorded range still admits it.\n if (target !== undefined) dependencies[name] = target;\n else if (!Object.hasOwn(dependencies, name)) dependencies[name] = UNPINNED_PACKAGE_RANGE;\n }\n manifest.dependencies = dependencies;\n // Po owns the runtime's workspaces: exactly the staged archives, which reach only each other.\n const workspaces = Object.values(catalogWorkspaces).sort();\n if (workspaces.length > 0) manifest.workspaces = workspaces;\n else delete manifest.workspaces;\n // Nested and overlapping consumer rules can take precedence in cases that retain\n // vulnerable versions, so Po owns these package-specific selectors recursively.\n manifest.overrides = {\n ...withoutCatalogOverrides(withoutConflictingTransitiveOverrides(manifest.overrides)),\n ...SAFE_TRANSITIVE_OVERRIDES,\n };\n const pnpm = recordValue(manifest.pnpm);\n pnpm.overrides = {\n ...withoutCatalogOverrides(withoutConflictingTransitiveOverrides(pnpm.overrides)),\n ...SAFE_TRANSITIVE_OVERRIDES,\n };\n manifest.pnpm = pnpm;\n\n const serialized = `${JSON.stringify(manifest, null, 2)}\\n`;\n if (serialized === current) return false;\n await fs.mkdir(runtimeDirectory, { recursive: true });\n await writeFileAtomic(createNodePlatform().env(runtimeDirectory), manifestPath, serialized, BACKGROUND_CONTEXT);\n return true;\n}\n\n/** Finds required npm packages selected by defaults and active layers that Po cannot resolve. */\nexport function missingLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n resolvers: ExtensionLayerResolvers,\n): string[] {\n return configuredPackageSpecifiers(config, layers).filter(\n (specifier) => resolvePackageEntries(resolvers, specifier) === undefined,\n );\n}\n\n/** Whether `root`'s own node_modules chain holds the package, walked the way Node looks it up from `root`. */\nasync function ownsPackage(name: string, root: string): Promise<boolean> {\n for (let directory = path.resolve(root); ; directory = path.dirname(directory)) {\n if (\n await fs.access(path.join(directory, NODE_MODULES, name, PACKAGE_MANIFEST)).then(\n () => true,\n (error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return false;\n throw error;\n },\n )\n )\n return true;\n if (path.dirname(directory) === directory) return false;\n }\n}\n\n/**\n * The required npm packages the default and the given layers name that `root` does not get\n * from its own node_modules chain: what the shared runtime provides for it, whether it does so\n * already or not yet. Sync declares exactly these, over every root, in the runtime manifest; a\n * name the runtime already provides still counts, or the next exact manifest would drop it.\n */\nexport async function runtimeLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n root: string,\n): Promise<string[]> {\n const specifiers = configuredPackageSpecifiers(config, layers);\n const owned = await Promise.all(\n specifiers.map((specifier) => ownsPackage(splitPackageSpecifier(specifier).name, root)),\n );\n return specifiers.filter((_specifier, index) => !owned[index]);\n}\n\nfunction packageName(source: string): string {\n const specifier = source.startsWith(NPM_SOURCE_PREFIX) ? source.slice(NPM_SOURCE_PREFIX.length) : source;\n if (specifier.startsWith('@')) {\n const slash = specifier.indexOf('/');\n const version = slash === -1 ? -1 : specifier.indexOf('@', slash);\n return version === -1 ? specifier : specifier.slice(0, version);\n }\n const version = specifier.indexOf('@');\n return version === -1 ? specifier : specifier.slice(0, version);\n}\n\ninterface PackageCatalogEntry {\n /** Absolute path of the bundled archive; it takes precedence over `version`. */\n archive?: string;\n /** Exact registry version, pinned when the entry has no archive. */\n version?: string;\n dependencies: readonly string[];\n}\n\ninterface PackageCatalog {\n packages: ReadonlyMap<string, PackageCatalogEntry>;\n /** Feature packages Po installs out of the box, by name. */\n install: readonly string[];\n}\n\nconst EMPTY_CATALOG: PackageCatalog = { packages: new Map(), install: [] };\n\nfunction stringList(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const strings = value.filter((item): item is string => typeof item === 'string');\n return strings.length === value.length ? strings : undefined;\n}\n\nfunction defaultBundledCatalogPath(): string | undefined {\n try {\n return path.join(poPackageRoot(), ...BUNDLED_CATALOG_SEGMENTS);\n } catch {\n // A bundle with no locatable Po package root has no bundled catalogue to read.\n return undefined;\n }\n}\n\n/**\n * The first catalogue present: `PO_PACKAGE_CATALOG` (desktop's archives), then the one\n * a release bundles into the CLI. With neither, the runtime installs only what roots name.\n */\nasync function packageCatalogPath(environment: NodeJS.ProcessEnv): Promise<string | undefined> {\n const configured = environment[PACKAGE_CATALOG_ENV]?.trim();\n if (configured) return configured;\n const bundledCatalogPath = defaultBundledCatalogPath();\n if (bundledCatalogPath === undefined) return undefined;\n return fs.access(bundledCatalogPath).then(\n () => bundledCatalogPath,\n (error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n },\n );\n}\n\nasync function readPackageCatalog(manifestPath: string | undefined): Promise<PackageCatalog> {\n if (!manifestPath) return EMPTY_CATALOG;\n const parsed: unknown = JSON.parse(await fs.readFile(manifestPath, 'utf8'));\n if (!isRecord(parsed) || parsed.version !== 1 || !isRecord(parsed.packages)) {\n throw new Error(`Unsupported Po package catalog: ${manifestPath}`);\n }\n const packages = new Map<string, PackageCatalogEntry>();\n for (const [name, value] of Object.entries(parsed.packages)) {\n if (\n !isRecord(value) ||\n !Array.isArray(value.dependencies) ||\n (value.archive !== undefined && typeof value.archive !== 'string') ||\n (value.version !== undefined && typeof value.version !== 'string') ||\n (value.archive === undefined && value.version === undefined)\n ) {\n throw new Error(`Invalid package entry for ${name} in ${manifestPath}`);\n }\n const dependencies = stringList(value.dependencies);\n if (!dependencies) throw new Error(`Invalid dependencies for ${name} in ${manifestPath}`);\n const version = typeof value.version === 'string' ? value.version : undefined;\n if (typeof value.archive !== 'string') {\n packages.set(name, { version, dependencies });\n continue;\n }\n const archive = path.resolve(path.dirname(manifestPath), value.archive);\n await fs.access(archive).catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') throw new Error(`Po package catalog archive is missing: ${archive}`);\n throw error;\n });\n packages.set(name, { archive, version, dependencies });\n }\n const install = parsed.install === undefined ? [] : stringList(parsed.install);\n if (!install) throw new Error(`Invalid install list in ${manifestPath}`);\n const unknown = install.filter((name) => !packages.has(name));\n if (unknown.length > 0) throw new Error(`Po package catalog installs unlisted package(s): ${unknown.join(', ')}`);\n return { packages, install };\n}\n\n/**\n * The catalogue's `install` list as exact `name@version` specifiers for\n * `EnsureLayerPackagesOptions.specifiers`; empty when no catalogue is present.\n */\nexport async function catalogInstallSpecifiers(environment: NodeJS.ProcessEnv = process.env): Promise<string[]> {\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n return catalog.install.map((name) => {\n const version = catalog.packages.get(name)?.version;\n return version ? `${name}@${version}` : name;\n });\n}\n\n/**\n * The installed package roots of the catalogue's `install` list, resolved the way a root\n * resolves a bare name (its own node_modules, then the shared runtime). The global web build\n * covers them, so every first-party plugin has a slot; a name not installed yet is left out.\n */\nexport async function catalogPackageRoots(\n globalRoot: string,\n environment: NodeJS.ProcessEnv = process.env,\n): Promise<string[]> {\n const roots: string[] = [];\n for (const name of (await readPackageCatalog(await packageCatalogPath(environment))).install) {\n const manifest = consumerPackageEntry(`${name}/${PACKAGE_MANIFEST}`, globalRoot, environment);\n if (manifest !== undefined) roots.push(path.dirname(await fs.realpath(manifest)));\n }\n return roots;\n}\n\n/** SHA-256 of the catalogue file in use, or `none` when no catalogue is present. */\nexport async function packageCatalogHash(environment: NodeJS.ProcessEnv = process.env): Promise<string> {\n const catalogPath = await packageCatalogPath(environment);\n if (!catalogPath) return 'none';\n return crypto\n .createHash('sha256')\n .update(await fs.readFile(catalogPath))\n .digest('hex');\n}\n\n/** Exact target per catalogue name: its staged workspace for an archive, else its registry version. */\nfunction catalogTargets(catalog: PackageCatalog): Map<string, string> {\n return new Map(\n [...catalog.packages].flatMap(([name, entry]) => {\n if (entry.archive !== undefined) return [[name, CATALOG_WORKSPACE_TARGET] as const];\n return entry.version !== undefined ? [[name, entry.version] as const] : [];\n }),\n );\n}\n\nconst TAR_BLOCK_SIZE = 512;\nconst TAR_EXECUTABLE_BITS = 0o111;\n\nfunction tarString(block: Buffer, start: number, length: number): string {\n const field = block.subarray(start, start + length);\n const end = field.indexOf(0);\n return field.subarray(0, end === -1 ? field.length : end).toString('utf8');\n}\n\nfunction tarNumber(block: Buffer, start: number, length: number): number {\n const field = block.subarray(start, start + length);\n // GNU base-256: the high bit of the first byte marks a big-endian binary number.\n if ((field[0]! & 0x80) !== 0) return field.subarray(1).reduce((value, byte) => value * 256 + byte, field[0]! & 0x7f);\n const text = tarString(block, start, length).trim();\n return text === '' ? 0 : Number.parseInt(text, 8);\n}\n\n/** The `path` record of a pax extended header, if it has one. */\nfunction paxPath(data: Buffer): string | undefined {\n let found: string | undefined;\n let offset = 0;\n while (offset < data.length) {\n const space = data.indexOf(0x20, offset);\n if (space === -1) break;\n const length = Number.parseInt(data.subarray(offset, space).toString('utf8'), 10);\n if (!Number.isFinite(length) || length <= 0) break;\n const record = data.subarray(space + 1, offset + length - 1).toString('utf8');\n const separator = record.indexOf('=');\n if (record.slice(0, separator) === 'path') found = record.slice(separator + 1);\n offset += length;\n }\n return found;\n}\n\n/**\n * Unpacks a gzipped npm package archive into `destination`, dropping the archive's top\n * directory (`package/`) as npm does. Only files and directories are written: npm package\n * archives carry no links, and an entry that would land outside `destination` is refused.\n */\nasync function extractPackageArchive(archive: string, destination: string): Promise<void> {\n const data = zlib.gunzipSync(await fs.readFile(archive));\n let offset = 0;\n let nextPath: string | undefined;\n while (offset + TAR_BLOCK_SIZE <= data.length) {\n const header = data.subarray(offset, offset + TAR_BLOCK_SIZE);\n if (header.every((byte) => byte === 0)) break;\n const size = tarNumber(header, 124, 12);\n const type = String.fromCharCode(header[156]!);\n const body = data.subarray(offset + TAR_BLOCK_SIZE, offset + TAR_BLOCK_SIZE + size);\n offset += TAR_BLOCK_SIZE + Math.ceil(size / TAR_BLOCK_SIZE) * TAR_BLOCK_SIZE;\n if (type === 'x' || type === 'L') {\n nextPath = type === 'x' ? (paxPath(body) ?? nextPath) : tarString(body, 0, body.length);\n continue;\n }\n if (type === 'g') continue;\n const prefix = tarString(header, 345, 155);\n const name = nextPath ?? (prefix ? `${prefix}/${tarString(header, 0, 100)}` : tarString(header, 0, 100));\n nextPath = undefined;\n if (type !== '0' && type !== '\\0' && type !== '5') continue;\n const relative = name.split('/').slice(1).join('/');\n if (relative === '') continue;\n const target = path.resolve(destination, relative);\n if (!target.startsWith(`${destination}${path.sep}`)) {\n throw new Error(`Po package catalog archive ${archive} has an entry outside the package: ${name}`);\n }\n if (type === '5') {\n await fs.mkdir(target, { recursive: true });\n continue;\n }\n await fs.mkdir(path.dirname(target), { recursive: true });\n const executable = (tarNumber(header, 100, 8) & TAR_EXECUTABLE_BITS) !== 0;\n await fs.writeFile(target, body, { mode: executable ? 0o755 : 0o644 });\n }\n}\n\n/** Dependency fields of a staged manifest that may name another catalogue package. */\nconst STAGED_DEPENDENCY_FIELDS = ['dependencies', 'optionalDependencies', 'peerDependencies'] as const;\n\n/**\n * Unpacks one catalogue archive into `<runtime>/catalog/<hash>` and returns that directory\n * relative to the runtime, with the catalogue names its manifest depends on.\n *\n * upm only installs a package from a directory as a workspace: a `file:` archive takes its own\n * dependencies from the registry, so one catalogue archive could not depend on another. In the\n * staged manifest every dependency on another catalogue archive becomes `workspace:*`, so the\n * catalogue's copy wins whatever range the package declared, and `devDependencies`, which a\n * workspace would otherwise install, are dropped. The hash covers the archive bytes and the\n * catalogue's archive names, everything that rewrite reads, so a staged directory is reused.\n */\nasync function stageCatalogArchive(\n runtimeDirectory: string,\n archive: string,\n archiveNames: ReadonlySet<string>,\n): Promise<{ relative: string; dependencies: string[] }> {\n const hash = crypto\n .createHash('sha256')\n .update(await fs.readFile(archive))\n .update(`\\0${[...archiveNames].sort().join('\\n')}`)\n .digest('hex');\n const relative = `${CATALOG_STAGING_DIRECTORY}/${hash}`;\n const directory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY, hash);\n const stagedManifest = path.join(directory, PACKAGE_MANIFEST);\n const existing = await fs.readFile(stagedManifest, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (existing === undefined) {\n const temporary = `${directory}.${String(process.pid)}.${crypto.randomUUID()}.tmp`;\n try {\n await extractPackageArchive(archive, temporary);\n const manifestPath = path.join(temporary, PACKAGE_MANIFEST);\n const bytes = await fs.readFile(manifestPath, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') throw new Error(`Po package catalog archive has no package.json: ${archive}`);\n throw error;\n });\n const manifest: unknown = JSON.parse(bytes);\n if (!isRecord(manifest)) throw new Error(`Po package catalog archive has an invalid package.json: ${archive}`);\n delete manifest.devDependencies;\n for (const field of STAGED_DEPENDENCY_FIELDS) {\n if (!isRecord(manifest[field])) continue;\n const declared = { ...manifest[field] };\n for (const name of Object.keys(declared)) {\n if (archiveNames.has(name)) declared[name] = CATALOG_WORKSPACE_TARGET;\n }\n manifest[field] = declared;\n }\n await fs.writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\\n`);\n try {\n await fs.rename(temporary, directory);\n } catch (error) {\n // Another process staged the same bytes first; its copy is identical.\n await fs.access(stagedManifest).catch(() => {\n throw error;\n });\n }\n } finally {\n await fs.rm(temporary, { recursive: true, force: true });\n }\n }\n const staged = recordValue(JSON.parse(existing ?? (await fs.readFile(stagedManifest, 'utf8'))));\n const dependencies = STAGED_DEPENDENCY_FIELDS.flatMap((field) => Object.keys(recordValue(staged[field])));\n return { relative, dependencies: dependencies.filter((name) => archiveNames.has(name)) };\n}\n\n/**\n * Stages the archive of every named catalogue package and of every catalogue package those\n * name in turn, since a staged manifest's `workspace:*` needs that workspace present. The\n * result, name to staged directory, feeds `ensureManagedPackageManifest`.\n */\nasync function stageCatalogArchives(\n runtimeDirectory: string,\n catalog: PackageCatalog,\n names: Iterable<string>,\n): Promise<Record<string, string>> {\n const archiveNames = new Set(\n [...catalog.packages].flatMap(([name, entry]) => (entry.archive === undefined ? [] : [name])),\n );\n const staged: Record<string, string> = {};\n const pending = [...names].filter((name) => archiveNames.has(name));\n while (pending.length > 0) {\n const name = pending.shift()!;\n if (Object.hasOwn(staged, name)) continue;\n const { relative, dependencies } = await stageCatalogArchive(\n runtimeDirectory,\n catalog.packages.get(name)!.archive!,\n archiveNames,\n );\n staged[name] = relative;\n pending.push(...dependencies);\n }\n return staged;\n}\n\n/**\n * Removes staged archives the runtime manifest no longer lists as workspaces, and returns their\n * folder names. An install never calls this: a running server imports from these folders (its\n * `.po-snapshots` live there), so sync prunes them under the same gate as the runtime store.\n */\nexport async function pruneStagedCatalogArchives(runtimeDirectory: string): Promise<string[]> {\n const stagingDirectory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY);\n const entries = await fs.readdir(stagingDirectory).catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return [];\n throw error;\n });\n const { manifest } = await readRuntimeManifest(path.join(runtimeDirectory, PACKAGE_MANIFEST));\n const kept = new Set((stringList(manifest.workspaces) ?? []).map((relative) => path.basename(relative)));\n return Promise.all(\n entries\n .filter((entry) => !kept.has(entry))\n .map(async (entry) => {\n await fs.rm(path.join(stagingDirectory, entry), { recursive: true, force: true });\n return entry;\n }),\n );\n}\n\n/** Splits `name@version` (scoped or not); the version is absent for a bare name or subpath. */\nfunction splitVersionedSpecifier(specifier: string): { name: string; version?: string } {\n const separator = specifier.indexOf('@', specifier.startsWith('@') ? 1 : 0);\n if (separator === -1) return { name: splitPackageSpecifier(specifier).name };\n return { name: specifier.slice(0, separator), version: specifier.slice(separator + 1) };\n}\n\nfunction npmSources(\n specifiers: readonly string[],\n catalog: PackageCatalog,\n targets: ReadonlyMap<string, string>,\n includeCatalogDependencies = false,\n): string[] {\n const names = [...new Set(specifiers.map((specifier) => splitPackageSpecifier(specifier).name))];\n if (includeCatalogDependencies) {\n for (let index = 0; index < names.length; index += 1) {\n for (const dependency of catalog.packages.get(names[index]!)?.dependencies ?? []) {\n if (!names.includes(dependency)) names.push(dependency);\n }\n }\n }\n return names.map((name) => {\n const target = targets.get(name);\n return `${NPM_SOURCE_PREFIX}${name}${target ? `@${target}` : ''}`;\n });\n}\n\nfunction pluralize(count: number, noun: string): string {\n return `${count} ${noun}${count === 1 ? '' : 's'}`;\n}\n\n/** Version of a package inside the shared runtime, absent when Po did not install it there. */\nasync function managedPackageVersion(runtimeDirectory: string, name: string): Promise<string | undefined> {\n const manifestPath = path.join(runtimeDirectory, NODE_MODULES, name, PACKAGE_MANIFEST);\n try {\n const parsed: unknown = JSON.parse(await fs.readFile(manifestPath, 'utf8'));\n return isRecord(parsed) && typeof parsed.version === 'string' ? parsed.version : undefined;\n } catch {\n // An unreadable manifest carries the same meaning as an absent one: nothing\n // usable is installed, so the caller treats the package as uninstalled.\n return undefined;\n }\n}\n\nfunction errorCode(error: unknown): unknown {\n return typeof error === 'object' && error !== null ? (error as { code?: unknown }).code : undefined;\n}\n\n/**\n * Installs the runtime, and when the registry cannot be reached installs it again offline:\n * an unchanged lockfile whose packages the store already holds needs no network.\n */\nasync function installWithOfflineRetry(\n install: NonNullable<LayerPackageInstallerDependencies['install']>,\n options: InstallRuntimePackagesOptions,\n onProgress: ((message: string) => void) | undefined,\n): Promise<void> {\n try {\n await install(options);\n } catch (error) {\n const code = errorCode(error);\n if (typeof code !== 'string' || !NETWORK_FAILURE_CODES.has(code)) throw error;\n onProgress?.(`the registry is unreachable (${code}); installing offline from the store`);\n try {\n await install({ ...options, preferOffline: false, offline: true });\n } catch {\n // The offline attempt only ever narrows the original failure: the network error\n // explains why the install could not complete, an EOFFLINE miss does not.\n throw error;\n }\n }\n}\n\ninterface CheckedPackage {\n name: string;\n from: string;\n to?: string;\n failure?: string;\n}\n\n/**\n * Compares every package sync installed against the registry.\n *\n * Only the shared runtime is consulted: a package that resolves from the\n * repository's own modules is not sync's to move, and a package that is not\n * installed yet is already covered by the missing-package path.\n */\nasync function resolveUpdates(\n runtimeDirectory: string,\n sources: readonly string[],\n publishedVersion: (name: string) => Promise<string>,\n onProgress: ((message: string) => void) | undefined,\n): Promise<Pick<LayerPackageResult, 'updated' | 'unchecked'>> {\n const managed = (\n await Promise.all(\n sources.map(async (source) => ({\n name: packageName(source),\n from: await managedPackageVersion(runtimeDirectory, packageName(source)),\n })),\n )\n ).filter((entry): entry is { name: string; from: string } => entry.from !== undefined);\n const checked: CheckedPackage[] = await Promise.all(\n managed.map(async (entry) => {\n try {\n return { ...entry, to: await publishedVersion(entry.name) };\n } catch (error) {\n return { ...entry, failure: (error instanceof Error ? error.message : String(error)).split('\\n')[0] };\n }\n }),\n );\n\n const updated: LayerPackageUpdate[] = [];\n const unchecked: string[] = [];\n for (const entry of checked) {\n if (entry.to === undefined) {\n unchecked.push(entry.name);\n onProgress?.(`kept ${entry.name} ${entry.from}: ${entry.failure ?? 'no published version'}`);\n continue;\n }\n if (entry.to === entry.from) continue;\n updated.push({ name: entry.name, from: entry.from, to: entry.to });\n onProgress?.(`${entry.name} ${entry.from} -> ${entry.to}`);\n }\n return { updated, unchecked };\n}\n\n/**\n * Installs the selected layer packages a root cannot resolve into the shared runtime,\n * `<po home>/runtime`, and verifies they now resolve.\n *\n * The runtime manifest is the union of what every root asked for. A root adds the\n * packages it is missing; a package it already resolves from its own node_modules stays\n * out unless an earlier run put it there. One name has one version: an exact target\n * (a sync update, a catalog archive or registry pin) replaces the declared range, last\n * writer wins, and a plain `*` never replaces a range already declared.\n *\n * `specifiers` and `exactManifest` only add behaviour: without them, and without a\n * catalogue, a run behaves as it always has.\n */\nexport async function ensureLayerPackages(\n options: EnsureLayerPackagesOptions,\n dependencies: LayerPackageInstallerDependencies = {},\n): Promise<LayerPackageResult> {\n const environment = options.environment ?? process.env;\n const homeDirectory = environment.HOME ?? os.homedir();\n const poHome = poHomeDirectory(homeDirectory, environment);\n const runtimeDirectory = poRuntimeDirectory(homeDirectory, environment);\n // The root's own .npmrc routes and authenticates the registries its layers name.\n const npmrcFiles = [path.join(options.repoRoot, '.npmrc')];\n const resolvers = dependencies.resolvers ?? createLayerResolvers(options.repoRoot, environment);\n const external = (specifier: string): boolean => testPackageRoot(packageName(specifier), environment) === undefined;\n const configured = configuredPackageSpecifiers(options.config, options.layers).filter(external);\n const missing = configured.filter((specifier) => resolvePackageEntries(resolvers, specifier) === undefined);\n const declared = await declaredRuntimePackages(runtimeDirectory);\n const managed = configured.filter(\n (specifier) => missing.includes(specifier) || declared.has(splitPackageSpecifier(specifier).name),\n );\n const requested = (options.specifiers ?? []).filter(external).map(splitVersionedSpecifier);\n if (managed.length === 0 && requested.length === 0 && options.exactManifest !== true) {\n return { installed: [], updated: [], unchecked: [] };\n }\n\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n const pins = catalogTargets(catalog);\n for (const { name, version } of requested) {\n if (version !== undefined && catalog.packages.get(name)?.archive === undefined) pins.set(name, version);\n }\n // A requested package is missing until the runtime holds it at the version it is pinned to.\n const requestedMissing: string[] = [];\n for (const { name, version } of requested) {\n const installed = await managedPackageVersion(runtimeDirectory, name);\n const entry = catalog.packages.get(name);\n const expected = entry?.archive === undefined ? version : entry.version;\n if (installed === undefined || (expected !== undefined && installed !== expected)) requestedMissing.push(name);\n }\n const missingSources = npmSources([...missing, ...requestedMissing], catalog, pins);\n const sources = npmSources([...managed, ...requested.map(({ name }) => name)], catalog, pins, true).filter(external);\n const missingCount = missing.length + requestedMissing.length;\n\n // Refresh never moves a pinned name: catalogue entries and versioned specifiers stay put.\n const fixedNames = new Set([\n ...catalog.packages.keys(),\n ...requested.filter(({ version }) => version !== undefined).map(({ name }) => name),\n ]);\n const registrySources = sources.filter((source) => !fixedNames.has(packageName(source)));\n const { updated, unchecked } = options.refresh\n ? await resolveUpdates(\n runtimeDirectory,\n registrySources,\n dependencies.publishedVersion ?? ((name) => resolveNewest(name, { dir: runtimeDirectory, poHome, npmrcFiles })),\n options.onProgress,\n )\n : { updated: [], unchecked: [] };\n const targets = new Map(\n sources.flatMap((source) => {\n const target = pins.get(packageName(source));\n return target ? [[packageName(source), target] as const] : [];\n }),\n );\n for (const update of updated) targets.set(update.name, update.to);\n // A kept manifest still declares names earlier runs added; their archives are staged too.\n const stagedNames = new Set([...sources.map(packageName), ...(options.exactManifest === true ? [] : declared)]);\n const staged = await stageCatalogArchives(runtimeDirectory, catalog, stagedNames);\n const manifestChanged = await ensureManagedPackageManifest(\n runtimeDirectory,\n sources,\n targets,\n staged,\n options.exactManifest === true,\n );\n if (missingCount === 0 && !manifestChanged) return { installed: [], updated: [], unchecked };\n\n options.onProgress?.(\n `installing ${\n updated.length > 0\n ? pluralize(updated.length, 'update')\n : missingCount > 0\n ? pluralize(missingCount, 'missing package')\n : 'the package manifest'\n }`,\n );\n try {\n // One install reconciles the complete dependency set written to package.json.\n await installWithOfflineRetry(\n dependencies.install ?? installRuntimePackages,\n {\n dir: runtimeDirectory,\n poHome,\n npmrcFiles,\n // A launch never waits on registry revalidation; sync is the command that refreshes.\n preferOffline: options.refresh !== true,\n log: (message, level) => {\n if (level === 'warn') options.onProgress?.(message);\n },\n },\n options.onProgress,\n );\n } catch (error) {\n const attempted = manifestChanged ? sources : missingSources;\n throw new Error(\n `Failed to reconcile Po layer package(s): ${attempted.join(', ')}: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n\n const unresolved = missing.filter((specifier) => !resolvePackageEntries(resolvers, specifier)?.length);\n if (unresolved.length > 0) {\n throw new Error(\n `Installed Po layer package(s) did not expose the configured Pi extension: ${unresolved.join(', ')}`,\n );\n }\n return { installed: missingSources, updated, unchecked };\n}\n\n/** One selector per name in the shared runtime. Caller holds the sync lock throughout. */\nexport async function ensureRuntimeImportPackage(\n name: string,\n version: string,\n options: { homeDirectory: string; environment: Readonly<Record<string, string | undefined>> },\n): Promise<void> {\n const environment = { ...options.environment, HOME: options.homeDirectory };\n const poHome = poHomeDirectory(options.homeDirectory, environment);\n const directory = poRuntimeDirectory(options.homeDirectory, environment);\n const manifestPath = path.join(directory, PACKAGE_MANIFEST);\n const { manifest } = await readRuntimeManifest(manifestPath);\n const declared = recordValue(manifest.dependencies);\n const imports = recordValue(manifest.poCodemodeDependencies);\n const imported = recordValue(imports[name]);\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n if (catalog.packages.has(name) || (Object.hasOwn(declared, name) && declared[name] !== imported.selector)) {\n throw new Error(\n `Cannot import ${name}: Po manages this runtime dependency (${JSON.stringify(declared[name] ?? 'catalogue')}).`,\n );\n }\n if (Object.hasOwn(imports, name) && imported.selector !== version) {\n throw new Error(`Cannot import ${name}@${version}: the hub already uses ${name}@${String(imported.selector)}.`);\n }\n const installed = await managedPackageVersion(directory, name);\n if (declared[name] === version && installed !== undefined && imported.resolved === installed) return;\n // Only a successful reconciliation is cacheable, not the manifest upm writes ahead of a failed install.\n manifest.poCodemodeDependencies = { ...imports, [name]: { selector: version } };\n await writeFileAtomic(\n createNodePlatform().env(directory),\n manifestPath,\n `${JSON.stringify(manifest, null, 2)}\\n`,\n BACKGROUND_CONTEXT,\n );\n const pins = new Map([[name, version]]);\n const sources = npmSources([`${name}@${version}`], catalog, pins, true);\n const staged = await stageCatalogArchives(\n directory,\n catalog,\n new Set([...sources.map(packageName), ...Object.keys(declared)]),\n );\n await ensureManagedPackageManifest(directory, sources, pins, staged);\n await installWithOfflineRetry(installRuntimePackages, { dir: directory, poHome, preferOffline: true }, undefined);\n const resolved = await managedPackageVersion(directory, name);\n if (resolved === undefined) throw new Error(`Runtime import ${name}@${version} was not installed.`);\n const reconciled = (await readRuntimeManifest(manifestPath)).manifest;\n reconciled.poCodemodeDependencies = {\n ...recordValue(reconciled.poCodemodeDependencies),\n [name]: { selector: version, resolved },\n };\n await writeFileAtomic(\n createNodePlatform().env(directory),\n manifestPath,\n `${JSON.stringify(reconciled, null, 2)}\\n`,\n BACKGROUND_CONTEXT,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;AAC1B,MAAM,wBAAwB;AAC9B,MAAM,6BAA6B;;AAEnC,MAAM,2BAA2B;;AAEjC,MAAM,4BAA4B;AAClC,MAAM,uBAAuB;AAC7B,MAAM,yBAAyB;AAC/B,MAAM,mBAAmB;AACzB,MAAM,eAAe;AACrB,MAAM,sBAAsB;;AAE5B,MAAM,2BAA2B;CAAC;CAAQ;CAAW;AAAY;;AAEjE,MAAM,wCAAwB,IAAI,IAAI;CAAC;CAAY;CAAa;AAAW,CAAC;AAE5E,SAAS,oBAAoB,UAA0B;CACrD,MAAM,iBAAiB,SAAS,QAAQ,KAAK,SAAS,WAAW,GAAG,IAAI,IAAI,CAAC;CAC7E,OAAO,mBAAmB,KAAK,WAAW,SAAS,MAAM,GAAG,cAAc;AAC5E;;;;;;AAOA,MAAa,4BAA4B;CAEvC,+BAA+B;CAC/B,mCAAmC;CACnC,uCAAuC;CACvC,kCAAkC;CAClC,kCAAkC;CAClC,uBAAuB;CACvB,yBAAyB;CACzB,yBAAyB;CACzB,6BAA6B;CAC7B,4BAA4B;CAC5B,yBAAyB;AAC3B;AAEA,MAAM,gCAAgC,IAAI,IAAI,OAAO,KAAK,yBAAyB,CAAC,CAAC,IAAI,mBAAmB,CAAC;AA4D7G,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,YAAY,O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,KAAK,UAAU,YAAY,MAAM,CAAC,EAAE,KACvCC,4BAAAA,kBACF;AACF"}
@@ -46,7 +46,7 @@ function overridePackageName(selector) {
46
46
  * cannot carry these fixes in their own manifests.
47
47
  */
48
48
  const SAFE_TRANSITIVE_OVERRIDES = {
49
- "@earendil-works/pi-codemode": "1.4.0",
49
+ "@earendil-works/pi-codemode": "1.5.0",
50
50
  "@hono/node-server@2.0.0 - 2.0.9": "^2.0.10",
51
51
  "@opentelemetry/core@2.0.0 - 2.7.999": "2.8.0",
52
52
  "brace-expansion@1.0.0 - 1.1.20": "^1.1.21",
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/composition/layerPackageInstaller/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport os from 'node:os';\nimport path from 'node:path';\nimport zlib from 'node:zlib';\n\nimport { isLocalPackageSpecifier, type MajorModesConfig } from '@agimon-ai/po-config/majorModes';\nimport { consumerPackageEntry, splitPackageSpecifier, testPackageRoot } from '@agimon-ai/po-core/moduleResolution';\nimport { createNodePlatform } from '@agimon-ai/po-core/nodePlatform';\nimport { BACKGROUND_CONTEXT, writeFileAtomic } from '@agimon-ai/po-core/platform';\nimport {\n installRuntimePackages,\n type InstallRuntimePackagesOptions,\n resolveNewest,\n} from '@agimon-ai/po-core/runtimePackages';\nimport { poHomeDirectory, poRuntimeDirectory } from '@agimon-ai/po-core/runtimePiSettings';\n\nimport { poPackageRoot } from '../../builders/cli/entryResolution';\nimport { createLayerResolvers, type ExtensionLayerResolvers } from '../../builders/cli/extensionAssembler';\n\nconst NPM_SOURCE_PREFIX = 'npm:';\nconst FILE_SPECIFIER_PREFIX = 'file:';\nconst WORKSPACE_SPECIFIER_PREFIX = 'workspace:';\n/** Root target of a staged catalogue archive: always the staged workspace, never the registry. */\nconst CATALOG_WORKSPACE_TARGET = 'workspace:*';\n/** Where catalogue archives are unpacked inside the runtime, one directory per archive hash. */\nconst CATALOG_STAGING_DIRECTORY = 'catalog';\nconst RUNTIME_PACKAGE_NAME = 'po-runtime';\nconst UNPINNED_PACKAGE_RANGE = '*';\nconst PACKAGE_MANIFEST = 'package.json';\nconst NODE_MODULES = 'node_modules';\nconst PACKAGE_CATALOG_ENV = 'PO_PACKAGE_CATALOG';\n/** The registry catalogue a release writes into the CLI package: `<package root>/dist/catalog/index.json`. */\nconst BUNDLED_CATALOG_SEGMENTS = ['dist', 'catalog', 'index.json'] as const;\n/** upm error codes that mean the registry could not be reached, so the store may still answer. */\nconst NETWORK_FAILURE_CODES = new Set(['ENETWORK', 'ETIMEDOUT', 'EREGISTRY']);\n\nfunction overridePackageName(selector: string): string {\n const separatorIndex = selector.indexOf('@', selector.startsWith('@') ? 1 : 0);\n return separatorIndex === -1 ? selector : selector.slice(0, separatorIndex);\n}\n\n/**\n * Runtime compatibility pins and same-major patches for current foundation packages.\n * Package managers only honor overrides from the install root, so published extensions\n * cannot carry these fixes in their own manifests.\n */\nexport const SAFE_TRANSITIVE_OVERRIDES = {\n // ponytail: Pin for Pi 1.4.0's declaration API; advance with the host's Pi version.\n '@earendil-works/pi-codemode': '1.4.0',\n '@hono/node-server@2.0.0 - 2.0.9': '^2.0.10',\n '@opentelemetry/core@2.0.0 - 2.7.999': '2.8.0',\n 'brace-expansion@1.0.0 - 1.1.20': '^1.1.21',\n 'brace-expansion@5.0.0 - 5.0.11': '^5.0.12',\n 'hono@4.0.0 - 4.13.7': '4.13.8',\n 'js-yaml@4.0.0 - 4.3.1': '^4.3.2',\n 'js-yaml@5.0.0 - 5.2.1': '^5.2.2',\n 'liquidjs@10.0.0 - 10.27.1': '^10.27.2',\n 'protobufjs@8.0.0 - 8.7.1': '^8.7.2',\n 'undici@7.0.0 - 7.29.0': '^7.29.1',\n} as const satisfies Readonly<Record<string, string>>;\n\nconst SAFE_TRANSITIVE_PACKAGE_NAMES = new Set(Object.keys(SAFE_TRANSITIVE_OVERRIDES).map(overridePackageName));\n\nexport interface EnsureLayerPackagesOptions {\n /**\n * The Po root whose layers name the packages. Its own node_modules chain is\n * resolved first; what it cannot provide is installed into the one runtime\n * every root shares, `<po home>/runtime`.\n */\n repoRoot: string;\n config: MajorModesConfig;\n layers: readonly string[];\n environment?: NodeJS.ProcessEnv;\n /**\n * Move every managed package to its newest published version.\n *\n * Launch installs what a selection needs and nothing more, so a session never\n * pays for a registry round trip. Sync is the explicit maintenance command and\n * is the only caller that asks for this.\n */\n refresh?: boolean;\n /**\n * Packages installed into the runtime whatever the root resolves itself, such as the\n * catalogue's `install` list. A `name@version` specifier pins that exact version; a\n * catalogue archive for the name still wins. Refresh never moves a pinned name.\n */\n specifiers?: readonly string[];\n /**\n * Make the runtime manifest declare exactly this run's packages (the specifiers, the\n * selected names and their catalogue dependencies), so pruning can drop anything else.\n * Without it the manifest only grows.\n */\n exactManifest?: boolean;\n /** Receives one human-readable line per package decision. */\n onProgress?: (message: string) => void;\n}\n\nexport interface LayerPackageInstallerDependencies {\n /** Install seam; the default installs `<po home>/runtime` with upm. */\n install?: (options: InstallRuntimePackagesOptions) => Promise<unknown>;\n resolvers?: ExtensionLayerResolvers;\n /** Registry lookup seam; the default resolves the newest allowed version with upm. */\n publishedVersion?: (name: string) => Promise<string>;\n}\n\n/** One managed package moving from the installed version to the newest published one. */\nexport interface LayerPackageUpdate {\n name: string;\n from: string;\n to: string;\n}\n\nexport interface LayerPackageResult {\n /** Sources installed because a configured extension could not be resolved. */\n installed: string[];\n /** Packages this run moved to a newer published version. */\n updated: LayerPackageUpdate[];\n /** Packages left at the installed version because the registry could not be read. */\n unchecked: string[];\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction recordValue(value: unknown): Record<string, unknown> {\n return isRecord(value) ? { ...value } : {};\n}\n\nfunction withoutConflictingTransitiveOverrides(value: unknown): Record<string, unknown> {\n const overrides = recordValue(value);\n for (const [selector, replacement] of Object.entries(overrides)) {\n if (SAFE_TRANSITIVE_PACKAGE_NAMES.has(overridePackageName(selector))) {\n delete overrides[selector];\n } else if (isRecord(replacement)) {\n overrides[selector] = withoutConflictingTransitiveOverrides(replacement);\n }\n }\n return overrides;\n}\n\n/** Earlier versions overrode catalog packages with relative `file:` targets; any other override is not Po's. */\nfunction withoutCatalogOverrides(overrides: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(overrides).filter(\n ([, replacement]) => !(typeof replacement === 'string' && replacement.startsWith(FILE_SPECIFIER_PREFIX)),\n ),\n );\n}\n\n/** The published (non-local, required) package specifiers the default and the given layers name. */\nfunction configuredPackageSpecifiers(config: MajorModesConfig, layers: readonly string[]): string[] {\n const specifiers = new Set<string>();\n const selectedDefinitions = [\n ...(config.default ? [config.default] : []),\n ...layers.map((layerName) => {\n const layer = config.layers[layerName];\n if (!layer) throw new Error(`Unknown layer: ${layerName}`);\n return layer;\n }),\n ];\n for (const layer of selectedDefinitions) {\n for (const configured of layer.packages ?? []) {\n const specifier = typeof configured === 'string' ? configured : configured.name;\n const optional = typeof configured !== 'string' && configured.optional === true;\n if (!optional && !isLocalPackageSpecifier(specifier)) specifiers.add(specifier);\n }\n }\n return [...specifiers];\n}\n\nfunction resolvePackageEntries(resolvers: ExtensionLayerResolvers, specifier: string): string[] | undefined {\n const entries = resolvers.optionalPackageEntries?.(specifier);\n if (entries !== undefined) return entries;\n const entry = resolvers.optionalPackageEntry(specifier);\n return entry ? [entry] : undefined;\n}\n\nasync function readRuntimeManifest(\n manifestPath: string,\n): Promise<{ current: string | undefined; manifest: Record<string, unknown> }> {\n const current = await fs.readFile(manifestPath, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (current === undefined) return { current, manifest: { name: RUNTIME_PACKAGE_NAME, private: true } };\n const parsed: unknown = JSON.parse(current);\n if (!isRecord(parsed)) throw new Error(`Po runtime package manifest at ${manifestPath} must be a JSON object.`);\n return { current, manifest: parsed };\n}\n\n/** Names the runtime manifest already declares: what earlier runs, from any root, installed there. */\nasync function declaredRuntimePackages(runtimeDirectory: string): Promise<Set<string>> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n return new Set(Object.keys(recordValue((await readRuntimeManifest(manifestPath)).manifest.dependencies)));\n}\n\n/**\n * Adds a package set and the patched transitive policy to the shared runtime manifest.\n *\n * `targets` pins names to exact versions or `workspace:*`. `catalogWorkspaces` maps each\n * staged catalogue archive's name to its directory relative to the runtime; the manifest\n * lists exactly those directories as its `workspaces`, so a catalogue package's dependency\n * on another one links the staged copy instead of reaching the registry. Both `overrides` and\n * `pnpm.overrides` are written; upm reads both.\n * With `exact`, declared names outside `sources` are dropped instead of kept.\n */\nexport async function ensureManagedPackageManifest(\n runtimeDirectory: string,\n sources: readonly string[],\n targets: ReadonlyMap<string, string> = new Map(),\n catalogWorkspaces: Readonly<Record<string, string>> = {},\n exact = false,\n): Promise<boolean> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n const { current, manifest } = await readRuntimeManifest(manifestPath);\n\n const declared = recordValue(manifest.dependencies);\n const sourceNames = new Set(sources.map(packageName));\n const dependencies = exact\n ? Object.fromEntries(Object.entries(declared).filter(([name]) => sourceNames.has(name)))\n : declared;\n // Every root shares this manifest, so a catalog archive another process staged (a desktop\n // build, say) may not exist for this one: without a staged copy here it falls back to the\n // registry, which keeps the whole set installable. `file:` targets are what earlier\n // versions wrote for archives.\n for (const [name, declared] of Object.entries(dependencies)) {\n if (Object.hasOwn(catalogWorkspaces, name)) {\n dependencies[name] = CATALOG_WORKSPACE_TARGET;\n } else if (\n typeof declared === 'string' &&\n (declared.startsWith(FILE_SPECIFIER_PREFIX) || declared.startsWith(WORKSPACE_SPECIFIER_PREFIX))\n ) {\n dependencies[name] = UNPINNED_PACKAGE_RANGE;\n }\n }\n for (const source of sources) {\n const name = packageName(source);\n const target = targets.get(name);\n // An exact target is what makes an update reach the store: a package manager keeps a\n // locked version whenever the recorded range still admits it.\n if (target !== undefined) dependencies[name] = target;\n else if (!Object.hasOwn(dependencies, name)) dependencies[name] = UNPINNED_PACKAGE_RANGE;\n }\n manifest.dependencies = dependencies;\n // Po owns the runtime's workspaces: exactly the staged archives, which reach only each other.\n const workspaces = Object.values(catalogWorkspaces).sort();\n if (workspaces.length > 0) manifest.workspaces = workspaces;\n else delete manifest.workspaces;\n // Nested and overlapping consumer rules can take precedence in cases that retain\n // vulnerable versions, so Po owns these package-specific selectors recursively.\n manifest.overrides = {\n ...withoutCatalogOverrides(withoutConflictingTransitiveOverrides(manifest.overrides)),\n ...SAFE_TRANSITIVE_OVERRIDES,\n };\n const pnpm = recordValue(manifest.pnpm);\n pnpm.overrides = {\n ...withoutCatalogOverrides(withoutConflictingTransitiveOverrides(pnpm.overrides)),\n ...SAFE_TRANSITIVE_OVERRIDES,\n };\n manifest.pnpm = pnpm;\n\n const serialized = `${JSON.stringify(manifest, null, 2)}\\n`;\n if (serialized === current) return false;\n await fs.mkdir(runtimeDirectory, { recursive: true });\n await writeFileAtomic(createNodePlatform().env(runtimeDirectory), manifestPath, serialized, BACKGROUND_CONTEXT);\n return true;\n}\n\n/** Finds required npm packages selected by defaults and active layers that Po cannot resolve. */\nexport function missingLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n resolvers: ExtensionLayerResolvers,\n): string[] {\n return configuredPackageSpecifiers(config, layers).filter(\n (specifier) => resolvePackageEntries(resolvers, specifier) === undefined,\n );\n}\n\n/** Whether `root`'s own node_modules chain holds the package, walked the way Node looks it up from `root`. */\nasync function ownsPackage(name: string, root: string): Promise<boolean> {\n for (let directory = path.resolve(root); ; directory = path.dirname(directory)) {\n if (\n await fs.access(path.join(directory, NODE_MODULES, name, PACKAGE_MANIFEST)).then(\n () => true,\n (error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return false;\n throw error;\n },\n )\n )\n return true;\n if (path.dirname(directory) === directory) return false;\n }\n}\n\n/**\n * The required npm packages the default and the given layers name that `root` does not get\n * from its own node_modules chain: what the shared runtime provides for it, whether it does so\n * already or not yet. Sync declares exactly these, over every root, in the runtime manifest; a\n * name the runtime already provides still counts, or the next exact manifest would drop it.\n */\nexport async function runtimeLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n root: string,\n): Promise<string[]> {\n const specifiers = configuredPackageSpecifiers(config, layers);\n const owned = await Promise.all(\n specifiers.map((specifier) => ownsPackage(splitPackageSpecifier(specifier).name, root)),\n );\n return specifiers.filter((_specifier, index) => !owned[index]);\n}\n\nfunction packageName(source: string): string {\n const specifier = source.startsWith(NPM_SOURCE_PREFIX) ? source.slice(NPM_SOURCE_PREFIX.length) : source;\n if (specifier.startsWith('@')) {\n const slash = specifier.indexOf('/');\n const version = slash === -1 ? -1 : specifier.indexOf('@', slash);\n return version === -1 ? specifier : specifier.slice(0, version);\n }\n const version = specifier.indexOf('@');\n return version === -1 ? specifier : specifier.slice(0, version);\n}\n\ninterface PackageCatalogEntry {\n /** Absolute path of the bundled archive; it takes precedence over `version`. */\n archive?: string;\n /** Exact registry version, pinned when the entry has no archive. */\n version?: string;\n dependencies: readonly string[];\n}\n\ninterface PackageCatalog {\n packages: ReadonlyMap<string, PackageCatalogEntry>;\n /** Feature packages Po installs out of the box, by name. */\n install: readonly string[];\n}\n\nconst EMPTY_CATALOG: PackageCatalog = { packages: new Map(), install: [] };\n\nfunction stringList(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const strings = value.filter((item): item is string => typeof item === 'string');\n return strings.length === value.length ? strings : undefined;\n}\n\nfunction defaultBundledCatalogPath(): string | undefined {\n try {\n return path.join(poPackageRoot(), ...BUNDLED_CATALOG_SEGMENTS);\n } catch {\n // A bundle with no locatable Po package root has no bundled catalogue to read.\n return undefined;\n }\n}\n\n/**\n * The first catalogue present: `PO_PACKAGE_CATALOG` (desktop's archives), then the one\n * a release bundles into the CLI. With neither, the runtime installs only what roots name.\n */\nasync function packageCatalogPath(environment: NodeJS.ProcessEnv): Promise<string | undefined> {\n const configured = environment[PACKAGE_CATALOG_ENV]?.trim();\n if (configured) return configured;\n const bundledCatalogPath = defaultBundledCatalogPath();\n if (bundledCatalogPath === undefined) return undefined;\n return fs.access(bundledCatalogPath).then(\n () => bundledCatalogPath,\n (error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n },\n );\n}\n\nasync function readPackageCatalog(manifestPath: string | undefined): Promise<PackageCatalog> {\n if (!manifestPath) return EMPTY_CATALOG;\n const parsed: unknown = JSON.parse(await fs.readFile(manifestPath, 'utf8'));\n if (!isRecord(parsed) || parsed.version !== 1 || !isRecord(parsed.packages)) {\n throw new Error(`Unsupported Po package catalog: ${manifestPath}`);\n }\n const packages = new Map<string, PackageCatalogEntry>();\n for (const [name, value] of Object.entries(parsed.packages)) {\n if (\n !isRecord(value) ||\n !Array.isArray(value.dependencies) ||\n (value.archive !== undefined && typeof value.archive !== 'string') ||\n (value.version !== undefined && typeof value.version !== 'string') ||\n (value.archive === undefined && value.version === undefined)\n ) {\n throw new Error(`Invalid package entry for ${name} in ${manifestPath}`);\n }\n const dependencies = stringList(value.dependencies);\n if (!dependencies) throw new Error(`Invalid dependencies for ${name} in ${manifestPath}`);\n const version = typeof value.version === 'string' ? value.version : undefined;\n if (typeof value.archive !== 'string') {\n packages.set(name, { version, dependencies });\n continue;\n }\n const archive = path.resolve(path.dirname(manifestPath), value.archive);\n await fs.access(archive).catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') throw new Error(`Po package catalog archive is missing: ${archive}`);\n throw error;\n });\n packages.set(name, { archive, version, dependencies });\n }\n const install = parsed.install === undefined ? [] : stringList(parsed.install);\n if (!install) throw new Error(`Invalid install list in ${manifestPath}`);\n const unknown = install.filter((name) => !packages.has(name));\n if (unknown.length > 0) throw new Error(`Po package catalog installs unlisted package(s): ${unknown.join(', ')}`);\n return { packages, install };\n}\n\n/**\n * The catalogue's `install` list as exact `name@version` specifiers for\n * `EnsureLayerPackagesOptions.specifiers`; empty when no catalogue is present.\n */\nexport async function catalogInstallSpecifiers(environment: NodeJS.ProcessEnv = process.env): Promise<string[]> {\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n return catalog.install.map((name) => {\n const version = catalog.packages.get(name)?.version;\n return version ? `${name}@${version}` : name;\n });\n}\n\n/**\n * The installed package roots of the catalogue's `install` list, resolved the way a root\n * resolves a bare name (its own node_modules, then the shared runtime). The global web build\n * covers them, so every first-party plugin has a slot; a name not installed yet is left out.\n */\nexport async function catalogPackageRoots(\n globalRoot: string,\n environment: NodeJS.ProcessEnv = process.env,\n): Promise<string[]> {\n const roots: string[] = [];\n for (const name of (await readPackageCatalog(await packageCatalogPath(environment))).install) {\n const manifest = consumerPackageEntry(`${name}/${PACKAGE_MANIFEST}`, globalRoot, environment);\n if (manifest !== undefined) roots.push(path.dirname(await fs.realpath(manifest)));\n }\n return roots;\n}\n\n/** SHA-256 of the catalogue file in use, or `none` when no catalogue is present. */\nexport async function packageCatalogHash(environment: NodeJS.ProcessEnv = process.env): Promise<string> {\n const catalogPath = await packageCatalogPath(environment);\n if (!catalogPath) return 'none';\n return crypto\n .createHash('sha256')\n .update(await fs.readFile(catalogPath))\n .digest('hex');\n}\n\n/** Exact target per catalogue name: its staged workspace for an archive, else its registry version. */\nfunction catalogTargets(catalog: PackageCatalog): Map<string, string> {\n return new Map(\n [...catalog.packages].flatMap(([name, entry]) => {\n if (entry.archive !== undefined) return [[name, CATALOG_WORKSPACE_TARGET] as const];\n return entry.version !== undefined ? [[name, entry.version] as const] : [];\n }),\n );\n}\n\nconst TAR_BLOCK_SIZE = 512;\nconst TAR_EXECUTABLE_BITS = 0o111;\n\nfunction tarString(block: Buffer, start: number, length: number): string {\n const field = block.subarray(start, start + length);\n const end = field.indexOf(0);\n return field.subarray(0, end === -1 ? field.length : end).toString('utf8');\n}\n\nfunction tarNumber(block: Buffer, start: number, length: number): number {\n const field = block.subarray(start, start + length);\n // GNU base-256: the high bit of the first byte marks a big-endian binary number.\n if ((field[0]! & 0x80) !== 0) return field.subarray(1).reduce((value, byte) => value * 256 + byte, field[0]! & 0x7f);\n const text = tarString(block, start, length).trim();\n return text === '' ? 0 : Number.parseInt(text, 8);\n}\n\n/** The `path` record of a pax extended header, if it has one. */\nfunction paxPath(data: Buffer): string | undefined {\n let found: string | undefined;\n let offset = 0;\n while (offset < data.length) {\n const space = data.indexOf(0x20, offset);\n if (space === -1) break;\n const length = Number.parseInt(data.subarray(offset, space).toString('utf8'), 10);\n if (!Number.isFinite(length) || length <= 0) break;\n const record = data.subarray(space + 1, offset + length - 1).toString('utf8');\n const separator = record.indexOf('=');\n if (record.slice(0, separator) === 'path') found = record.slice(separator + 1);\n offset += length;\n }\n return found;\n}\n\n/**\n * Unpacks a gzipped npm package archive into `destination`, dropping the archive's top\n * directory (`package/`) as npm does. Only files and directories are written: npm package\n * archives carry no links, and an entry that would land outside `destination` is refused.\n */\nasync function extractPackageArchive(archive: string, destination: string): Promise<void> {\n const data = zlib.gunzipSync(await fs.readFile(archive));\n let offset = 0;\n let nextPath: string | undefined;\n while (offset + TAR_BLOCK_SIZE <= data.length) {\n const header = data.subarray(offset, offset + TAR_BLOCK_SIZE);\n if (header.every((byte) => byte === 0)) break;\n const size = tarNumber(header, 124, 12);\n const type = String.fromCharCode(header[156]!);\n const body = data.subarray(offset + TAR_BLOCK_SIZE, offset + TAR_BLOCK_SIZE + size);\n offset += TAR_BLOCK_SIZE + Math.ceil(size / TAR_BLOCK_SIZE) * TAR_BLOCK_SIZE;\n if (type === 'x' || type === 'L') {\n nextPath = type === 'x' ? (paxPath(body) ?? nextPath) : tarString(body, 0, body.length);\n continue;\n }\n if (type === 'g') continue;\n const prefix = tarString(header, 345, 155);\n const name = nextPath ?? (prefix ? `${prefix}/${tarString(header, 0, 100)}` : tarString(header, 0, 100));\n nextPath = undefined;\n if (type !== '0' && type !== '\\0' && type !== '5') continue;\n const relative = name.split('/').slice(1).join('/');\n if (relative === '') continue;\n const target = path.resolve(destination, relative);\n if (!target.startsWith(`${destination}${path.sep}`)) {\n throw new Error(`Po package catalog archive ${archive} has an entry outside the package: ${name}`);\n }\n if (type === '5') {\n await fs.mkdir(target, { recursive: true });\n continue;\n }\n await fs.mkdir(path.dirname(target), { recursive: true });\n const executable = (tarNumber(header, 100, 8) & TAR_EXECUTABLE_BITS) !== 0;\n await fs.writeFile(target, body, { mode: executable ? 0o755 : 0o644 });\n }\n}\n\n/** Dependency fields of a staged manifest that may name another catalogue package. */\nconst STAGED_DEPENDENCY_FIELDS = ['dependencies', 'optionalDependencies', 'peerDependencies'] as const;\n\n/**\n * Unpacks one catalogue archive into `<runtime>/catalog/<hash>` and returns that directory\n * relative to the runtime, with the catalogue names its manifest depends on.\n *\n * upm only installs a package from a directory as a workspace: a `file:` archive takes its own\n * dependencies from the registry, so one catalogue archive could not depend on another. In the\n * staged manifest every dependency on another catalogue archive becomes `workspace:*`, so the\n * catalogue's copy wins whatever range the package declared, and `devDependencies`, which a\n * workspace would otherwise install, are dropped. The hash covers the archive bytes and the\n * catalogue's archive names, everything that rewrite reads, so a staged directory is reused.\n */\nasync function stageCatalogArchive(\n runtimeDirectory: string,\n archive: string,\n archiveNames: ReadonlySet<string>,\n): Promise<{ relative: string; dependencies: string[] }> {\n const hash = crypto\n .createHash('sha256')\n .update(await fs.readFile(archive))\n .update(`\\0${[...archiveNames].sort().join('\\n')}`)\n .digest('hex');\n const relative = `${CATALOG_STAGING_DIRECTORY}/${hash}`;\n const directory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY, hash);\n const stagedManifest = path.join(directory, PACKAGE_MANIFEST);\n const existing = await fs.readFile(stagedManifest, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (existing === undefined) {\n const temporary = `${directory}.${String(process.pid)}.${crypto.randomUUID()}.tmp`;\n try {\n await extractPackageArchive(archive, temporary);\n const manifestPath = path.join(temporary, PACKAGE_MANIFEST);\n const bytes = await fs.readFile(manifestPath, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') throw new Error(`Po package catalog archive has no package.json: ${archive}`);\n throw error;\n });\n const manifest: unknown = JSON.parse(bytes);\n if (!isRecord(manifest)) throw new Error(`Po package catalog archive has an invalid package.json: ${archive}`);\n delete manifest.devDependencies;\n for (const field of STAGED_DEPENDENCY_FIELDS) {\n if (!isRecord(manifest[field])) continue;\n const declared = { ...manifest[field] };\n for (const name of Object.keys(declared)) {\n if (archiveNames.has(name)) declared[name] = CATALOG_WORKSPACE_TARGET;\n }\n manifest[field] = declared;\n }\n await fs.writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\\n`);\n try {\n await fs.rename(temporary, directory);\n } catch (error) {\n // Another process staged the same bytes first; its copy is identical.\n await fs.access(stagedManifest).catch(() => {\n throw error;\n });\n }\n } finally {\n await fs.rm(temporary, { recursive: true, force: true });\n }\n }\n const staged = recordValue(JSON.parse(existing ?? (await fs.readFile(stagedManifest, 'utf8'))));\n const dependencies = STAGED_DEPENDENCY_FIELDS.flatMap((field) => Object.keys(recordValue(staged[field])));\n return { relative, dependencies: dependencies.filter((name) => archiveNames.has(name)) };\n}\n\n/**\n * Stages the archive of every named catalogue package and of every catalogue package those\n * name in turn, since a staged manifest's `workspace:*` needs that workspace present. The\n * result, name to staged directory, feeds `ensureManagedPackageManifest`.\n */\nasync function stageCatalogArchives(\n runtimeDirectory: string,\n catalog: PackageCatalog,\n names: Iterable<string>,\n): Promise<Record<string, string>> {\n const archiveNames = new Set(\n [...catalog.packages].flatMap(([name, entry]) => (entry.archive === undefined ? [] : [name])),\n );\n const staged: Record<string, string> = {};\n const pending = [...names].filter((name) => archiveNames.has(name));\n while (pending.length > 0) {\n const name = pending.shift()!;\n if (Object.hasOwn(staged, name)) continue;\n const { relative, dependencies } = await stageCatalogArchive(\n runtimeDirectory,\n catalog.packages.get(name)!.archive!,\n archiveNames,\n );\n staged[name] = relative;\n pending.push(...dependencies);\n }\n return staged;\n}\n\n/**\n * Removes staged archives the runtime manifest no longer lists as workspaces, and returns their\n * folder names. An install never calls this: a running server imports from these folders (its\n * `.po-snapshots` live there), so sync prunes them under the same gate as the runtime store.\n */\nexport async function pruneStagedCatalogArchives(runtimeDirectory: string): Promise<string[]> {\n const stagingDirectory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY);\n const entries = await fs.readdir(stagingDirectory).catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return [];\n throw error;\n });\n const { manifest } = await readRuntimeManifest(path.join(runtimeDirectory, PACKAGE_MANIFEST));\n const kept = new Set((stringList(manifest.workspaces) ?? []).map((relative) => path.basename(relative)));\n return Promise.all(\n entries\n .filter((entry) => !kept.has(entry))\n .map(async (entry) => {\n await fs.rm(path.join(stagingDirectory, entry), { recursive: true, force: true });\n return entry;\n }),\n );\n}\n\n/** Splits `name@version` (scoped or not); the version is absent for a bare name or subpath. */\nfunction splitVersionedSpecifier(specifier: string): { name: string; version?: string } {\n const separator = specifier.indexOf('@', specifier.startsWith('@') ? 1 : 0);\n if (separator === -1) return { name: splitPackageSpecifier(specifier).name };\n return { name: specifier.slice(0, separator), version: specifier.slice(separator + 1) };\n}\n\nfunction npmSources(\n specifiers: readonly string[],\n catalog: PackageCatalog,\n targets: ReadonlyMap<string, string>,\n includeCatalogDependencies = false,\n): string[] {\n const names = [...new Set(specifiers.map((specifier) => splitPackageSpecifier(specifier).name))];\n if (includeCatalogDependencies) {\n for (let index = 0; index < names.length; index += 1) {\n for (const dependency of catalog.packages.get(names[index]!)?.dependencies ?? []) {\n if (!names.includes(dependency)) names.push(dependency);\n }\n }\n }\n return names.map((name) => {\n const target = targets.get(name);\n return `${NPM_SOURCE_PREFIX}${name}${target ? `@${target}` : ''}`;\n });\n}\n\nfunction pluralize(count: number, noun: string): string {\n return `${count} ${noun}${count === 1 ? '' : 's'}`;\n}\n\n/** Version of a package inside the shared runtime, absent when Po did not install it there. */\nasync function managedPackageVersion(runtimeDirectory: string, name: string): Promise<string | undefined> {\n const manifestPath = path.join(runtimeDirectory, NODE_MODULES, name, PACKAGE_MANIFEST);\n try {\n const parsed: unknown = JSON.parse(await fs.readFile(manifestPath, 'utf8'));\n return isRecord(parsed) && typeof parsed.version === 'string' ? parsed.version : undefined;\n } catch {\n // An unreadable manifest carries the same meaning as an absent one: nothing\n // usable is installed, so the caller treats the package as uninstalled.\n return undefined;\n }\n}\n\nfunction errorCode(error: unknown): unknown {\n return typeof error === 'object' && error !== null ? (error as { code?: unknown }).code : undefined;\n}\n\n/**\n * Installs the runtime, and when the registry cannot be reached installs it again offline:\n * an unchanged lockfile whose packages the store already holds needs no network.\n */\nasync function installWithOfflineRetry(\n install: NonNullable<LayerPackageInstallerDependencies['install']>,\n options: InstallRuntimePackagesOptions,\n onProgress: ((message: string) => void) | undefined,\n): Promise<void> {\n try {\n await install(options);\n } catch (error) {\n const code = errorCode(error);\n if (typeof code !== 'string' || !NETWORK_FAILURE_CODES.has(code)) throw error;\n onProgress?.(`the registry is unreachable (${code}); installing offline from the store`);\n try {\n await install({ ...options, preferOffline: false, offline: true });\n } catch {\n // The offline attempt only ever narrows the original failure: the network error\n // explains why the install could not complete, an EOFFLINE miss does not.\n throw error;\n }\n }\n}\n\ninterface CheckedPackage {\n name: string;\n from: string;\n to?: string;\n failure?: string;\n}\n\n/**\n * Compares every package sync installed against the registry.\n *\n * Only the shared runtime is consulted: a package that resolves from the\n * repository's own modules is not sync's to move, and a package that is not\n * installed yet is already covered by the missing-package path.\n */\nasync function resolveUpdates(\n runtimeDirectory: string,\n sources: readonly string[],\n publishedVersion: (name: string) => Promise<string>,\n onProgress: ((message: string) => void) | undefined,\n): Promise<Pick<LayerPackageResult, 'updated' | 'unchecked'>> {\n const managed = (\n await Promise.all(\n sources.map(async (source) => ({\n name: packageName(source),\n from: await managedPackageVersion(runtimeDirectory, packageName(source)),\n })),\n )\n ).filter((entry): entry is { name: string; from: string } => entry.from !== undefined);\n const checked: CheckedPackage[] = await Promise.all(\n managed.map(async (entry) => {\n try {\n return { ...entry, to: await publishedVersion(entry.name) };\n } catch (error) {\n return { ...entry, failure: (error instanceof Error ? error.message : String(error)).split('\\n')[0] };\n }\n }),\n );\n\n const updated: LayerPackageUpdate[] = [];\n const unchecked: string[] = [];\n for (const entry of checked) {\n if (entry.to === undefined) {\n unchecked.push(entry.name);\n onProgress?.(`kept ${entry.name} ${entry.from}: ${entry.failure ?? 'no published version'}`);\n continue;\n }\n if (entry.to === entry.from) continue;\n updated.push({ name: entry.name, from: entry.from, to: entry.to });\n onProgress?.(`${entry.name} ${entry.from} -> ${entry.to}`);\n }\n return { updated, unchecked };\n}\n\n/**\n * Installs the selected layer packages a root cannot resolve into the shared runtime,\n * `<po home>/runtime`, and verifies they now resolve.\n *\n * The runtime manifest is the union of what every root asked for. A root adds the\n * packages it is missing; a package it already resolves from its own node_modules stays\n * out unless an earlier run put it there. One name has one version: an exact target\n * (a sync update, a catalog archive or registry pin) replaces the declared range, last\n * writer wins, and a plain `*` never replaces a range already declared.\n *\n * `specifiers` and `exactManifest` only add behaviour: without them, and without a\n * catalogue, a run behaves as it always has.\n */\nexport async function ensureLayerPackages(\n options: EnsureLayerPackagesOptions,\n dependencies: LayerPackageInstallerDependencies = {},\n): Promise<LayerPackageResult> {\n const environment = options.environment ?? process.env;\n const homeDirectory = environment.HOME ?? os.homedir();\n const poHome = poHomeDirectory(homeDirectory, environment);\n const runtimeDirectory = poRuntimeDirectory(homeDirectory, environment);\n // The root's own .npmrc routes and authenticates the registries its layers name.\n const npmrcFiles = [path.join(options.repoRoot, '.npmrc')];\n const resolvers = dependencies.resolvers ?? createLayerResolvers(options.repoRoot, environment);\n const external = (specifier: string): boolean => testPackageRoot(packageName(specifier), environment) === undefined;\n const configured = configuredPackageSpecifiers(options.config, options.layers).filter(external);\n const missing = configured.filter((specifier) => resolvePackageEntries(resolvers, specifier) === undefined);\n const declared = await declaredRuntimePackages(runtimeDirectory);\n const managed = configured.filter(\n (specifier) => missing.includes(specifier) || declared.has(splitPackageSpecifier(specifier).name),\n );\n const requested = (options.specifiers ?? []).filter(external).map(splitVersionedSpecifier);\n if (managed.length === 0 && requested.length === 0 && options.exactManifest !== true) {\n return { installed: [], updated: [], unchecked: [] };\n }\n\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n const pins = catalogTargets(catalog);\n for (const { name, version } of requested) {\n if (version !== undefined && catalog.packages.get(name)?.archive === undefined) pins.set(name, version);\n }\n // A requested package is missing until the runtime holds it at the version it is pinned to.\n const requestedMissing: string[] = [];\n for (const { name, version } of requested) {\n const installed = await managedPackageVersion(runtimeDirectory, name);\n const entry = catalog.packages.get(name);\n const expected = entry?.archive === undefined ? version : entry.version;\n if (installed === undefined || (expected !== undefined && installed !== expected)) requestedMissing.push(name);\n }\n const missingSources = npmSources([...missing, ...requestedMissing], catalog, pins);\n const sources = npmSources([...managed, ...requested.map(({ name }) => name)], catalog, pins, true).filter(external);\n const missingCount = missing.length + requestedMissing.length;\n\n // Refresh never moves a pinned name: catalogue entries and versioned specifiers stay put.\n const fixedNames = new Set([\n ...catalog.packages.keys(),\n ...requested.filter(({ version }) => version !== undefined).map(({ name }) => name),\n ]);\n const registrySources = sources.filter((source) => !fixedNames.has(packageName(source)));\n const { updated, unchecked } = options.refresh\n ? await resolveUpdates(\n runtimeDirectory,\n registrySources,\n dependencies.publishedVersion ?? ((name) => resolveNewest(name, { dir: runtimeDirectory, poHome, npmrcFiles })),\n options.onProgress,\n )\n : { updated: [], unchecked: [] };\n const targets = new Map(\n sources.flatMap((source) => {\n const target = pins.get(packageName(source));\n return target ? [[packageName(source), target] as const] : [];\n }),\n );\n for (const update of updated) targets.set(update.name, update.to);\n // A kept manifest still declares names earlier runs added; their archives are staged too.\n const stagedNames = new Set([...sources.map(packageName), ...(options.exactManifest === true ? [] : declared)]);\n const staged = await stageCatalogArchives(runtimeDirectory, catalog, stagedNames);\n const manifestChanged = await ensureManagedPackageManifest(\n runtimeDirectory,\n sources,\n targets,\n staged,\n options.exactManifest === true,\n );\n if (missingCount === 0 && !manifestChanged) return { installed: [], updated: [], unchecked };\n\n options.onProgress?.(\n `installing ${\n updated.length > 0\n ? pluralize(updated.length, 'update')\n : missingCount > 0\n ? pluralize(missingCount, 'missing package')\n : 'the package manifest'\n }`,\n );\n try {\n // One install reconciles the complete dependency set written to package.json.\n await installWithOfflineRetry(\n dependencies.install ?? installRuntimePackages,\n {\n dir: runtimeDirectory,\n poHome,\n npmrcFiles,\n // A launch never waits on registry revalidation; sync is the command that refreshes.\n preferOffline: options.refresh !== true,\n log: (message, level) => {\n if (level === 'warn') options.onProgress?.(message);\n },\n },\n options.onProgress,\n );\n } catch (error) {\n const attempted = manifestChanged ? sources : missingSources;\n throw new Error(\n `Failed to reconcile Po layer package(s): ${attempted.join(', ')}: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n\n const unresolved = missing.filter((specifier) => !resolvePackageEntries(resolvers, specifier)?.length);\n if (unresolved.length > 0) {\n throw new Error(\n `Installed Po layer package(s) did not expose the configured Pi extension: ${unresolved.join(', ')}`,\n );\n }\n return { installed: missingSources, updated, unchecked };\n}\n\n/** One selector per name in the shared runtime. Caller holds the sync lock throughout. */\nexport async function ensureRuntimeImportPackage(\n name: string,\n version: string,\n options: { homeDirectory: string; environment: Readonly<Record<string, string | undefined>> },\n): Promise<void> {\n const environment = { ...options.environment, HOME: options.homeDirectory };\n const poHome = poHomeDirectory(options.homeDirectory, environment);\n const directory = poRuntimeDirectory(options.homeDirectory, environment);\n const manifestPath = path.join(directory, PACKAGE_MANIFEST);\n const { manifest } = await readRuntimeManifest(manifestPath);\n const declared = recordValue(manifest.dependencies);\n const imports = recordValue(manifest.poCodemodeDependencies);\n const imported = recordValue(imports[name]);\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n if (catalog.packages.has(name) || (Object.hasOwn(declared, name) && declared[name] !== imported.selector)) {\n throw new Error(\n `Cannot import ${name}: Po manages this runtime dependency (${JSON.stringify(declared[name] ?? 'catalogue')}).`,\n );\n }\n if (Object.hasOwn(imports, name) && imported.selector !== version) {\n throw new Error(`Cannot import ${name}@${version}: the hub already uses ${name}@${String(imported.selector)}.`);\n }\n const installed = await managedPackageVersion(directory, name);\n if (declared[name] === version && installed !== undefined && imported.resolved === installed) return;\n // Only a successful reconciliation is cacheable, not the manifest upm writes ahead of a failed install.\n manifest.poCodemodeDependencies = { ...imports, [name]: { selector: version } };\n await writeFileAtomic(\n createNodePlatform().env(directory),\n manifestPath,\n `${JSON.stringify(manifest, null, 2)}\\n`,\n BACKGROUND_CONTEXT,\n );\n const pins = new Map([[name, version]]);\n const sources = npmSources([`${name}@${version}`], catalog, pins, true);\n const staged = await stageCatalogArchives(\n directory,\n catalog,\n new Set([...sources.map(packageName), ...Object.keys(declared)]),\n );\n await ensureManagedPackageManifest(directory, sources, pins, staged);\n await installWithOfflineRetry(installRuntimePackages, { dir: directory, poHome, preferOffline: true }, undefined);\n const resolved = await managedPackageVersion(directory, name);\n if (resolved === undefined) throw new Error(`Runtime import ${name}@${version} was not installed.`);\n const reconciled = (await readRuntimeManifest(manifestPath)).manifest;\n reconciled.poCodemodeDependencies = {\n ...recordValue(reconciled.poCodemodeDependencies),\n [name]: { selector: version, resolved },\n };\n await writeFileAtomic(\n createNodePlatform().env(directory),\n manifestPath,\n `${JSON.stringify(reconciled, null, 2)}\\n`,\n BACKGROUND_CONTEXT,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;AAC1B,MAAM,wBAAwB;AAC9B,MAAM,6BAA6B;;AAEnC,MAAM,2BAA2B;;AAEjC,MAAM,4BAA4B;AAClC,MAAM,uBAAuB;AAC7B,MAAM,yBAAyB;AAC/B,MAAM,mBAAmB;AACzB,MAAM,eAAe;AACrB,MAAM,sBAAsB;;AAE5B,MAAM,2BAA2B;CAAC;CAAQ;CAAW;AAAY;;AAEjE,MAAM,wCAAwB,IAAI,IAAI;CAAC;CAAY;CAAa;AAA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AG;GAAU,OAAO,EAAE,UAAU,QAAQ;CAAE;CAC9E,MAAM,gBACJ,mBAAmB,CAAC,CAAC,IAAI,SAAS,GAClC,cACA,GAAG,KAAK,UAAU,UAAU,MAAM,CAAC,EAAE,KACrC,kBACF;CACA,MAAM,uBAAO,IAAI,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,CAAC;CACtC,MAAM,UAAU,WAAW,CAAC,GAAG,KAAK,GAAG,SAAS,GAAG,SAAS,MAAM,IAAI;CAMtE,MAAM,6BAA6B,WAAW,SAAS,MAAM,MALxC,qBACnB,WACA,yBACA,IAAI,IAAI,CAAC,GAAG,QAAQ,IAAI,WAAW,GAAG,GAAG,OAAO,KAAK,QAAQ,CAAC,CAAC,CACjE,CACmE;CACnE,MAAM,wBAAwB,wBAAwB;EAAE,KAAK;EAAW;EAAQ,eAAe;CAAK,GAAG,KAAA,CAAS;CAChH,MAAM,WAAW,MAAM,sBAAsB,WAAW,IAAI;CAC5D,IAAI,aAAa,KAAA,GAAW,MAAM,IAAI,MAAM,kBAAkB,KAAK,GAAG,QAAQ,oBAAoB;CAClG,MAAM,cAAc,MAAM,oBAAoB,YAAY,EAAA,CAAG;CAC7D,WAAW,yBAAyB;EAClC,GAAG,YAAY,WAAW,sBAAsB;GAC/C,OAAO;GAAE,UAAU;GAAS;EAAS;CACxC;CACA,MAAM,gBACJ,mBAAmB,CAAC,CAAC,IAAI,SAAS,GAClC,cACA,GAAG,KAAK,UAAU,YAAY,MAAM,CAAC,EAAE,KACvC,kBACF;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/composition/layerPackageInstaller/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport os from 'node:os';\nimport path from 'node:path';\nimport zlib from 'node:zlib';\n\nimport { isLocalPackageSpecifier, type MajorModesConfig } from '@agimon-ai/po-config/majorModes';\nimport { consumerPackageEntry, splitPackageSpecifier, testPackageRoot } from '@agimon-ai/po-core/moduleResolution';\nimport { createNodePlatform } from '@agimon-ai/po-core/nodePlatform';\nimport { BACKGROUND_CONTEXT, writeFileAtomic } from '@agimon-ai/po-core/platform';\nimport {\n installRuntimePackages,\n type InstallRuntimePackagesOptions,\n resolveNewest,\n} from '@agimon-ai/po-core/runtimePackages';\nimport { poHomeDirectory, poRuntimeDirectory } from '@agimon-ai/po-core/runtimePiSettings';\n\nimport { poPackageRoot } from '../../builders/cli/entryResolution';\nimport { createLayerResolvers, type ExtensionLayerResolvers } from '../../builders/cli/extensionAssembler';\n\nconst NPM_SOURCE_PREFIX = 'npm:';\nconst FILE_SPECIFIER_PREFIX = 'file:';\nconst WORKSPACE_SPECIFIER_PREFIX = 'workspace:';\n/** Root target of a staged catalogue archive: always the staged workspace, never the registry. */\nconst CATALOG_WORKSPACE_TARGET = 'workspace:*';\n/** Where catalogue archives are unpacked inside the runtime, one directory per archive hash. */\nconst CATALOG_STAGING_DIRECTORY = 'catalog';\nconst RUNTIME_PACKAGE_NAME = 'po-runtime';\nconst UNPINNED_PACKAGE_RANGE = '*';\nconst PACKAGE_MANIFEST = 'package.json';\nconst NODE_MODULES = 'node_modules';\nconst PACKAGE_CATALOG_ENV = 'PO_PACKAGE_CATALOG';\n/** The registry catalogue a release writes into the CLI package: `<package root>/dist/catalog/index.json`. */\nconst BUNDLED_CATALOG_SEGMENTS = ['dist', 'catalog', 'index.json'] as const;\n/** upm error codes that mean the registry could not be reached, so the store may still answer. */\nconst NETWORK_FAILURE_CODES = new Set(['ENETWORK', 'ETIMEDOUT', 'EREGISTRY']);\n\nfunction overridePackageName(selector: string): string {\n const separatorIndex = selector.indexOf('@', selector.startsWith('@') ? 1 : 0);\n return separatorIndex === -1 ? selector : selector.slice(0, separatorIndex);\n}\n\n/**\n * Runtime compatibility pins and same-major patches for current foundation packages.\n * Package managers only honor overrides from the install root, so published extensions\n * cannot carry these fixes in their own manifests.\n */\nexport const SAFE_TRANSITIVE_OVERRIDES = {\n // ponytail: Pin for Pi 1.5.0's declaration API; advance with the host's Pi version.\n '@earendil-works/pi-codemode': '1.5.0',\n '@hono/node-server@2.0.0 - 2.0.9': '^2.0.10',\n '@opentelemetry/core@2.0.0 - 2.7.999': '2.8.0',\n 'brace-expansion@1.0.0 - 1.1.20': '^1.1.21',\n 'brace-expansion@5.0.0 - 5.0.11': '^5.0.12',\n 'hono@4.0.0 - 4.13.7': '4.13.8',\n 'js-yaml@4.0.0 - 4.3.1': '^4.3.2',\n 'js-yaml@5.0.0 - 5.2.1': '^5.2.2',\n 'liquidjs@10.0.0 - 10.27.1': '^10.27.2',\n 'protobufjs@8.0.0 - 8.7.1': '^8.7.2',\n 'undici@7.0.0 - 7.29.0': '^7.29.1',\n} as const satisfies Readonly<Record<string, string>>;\n\nconst SAFE_TRANSITIVE_PACKAGE_NAMES = new Set(Object.keys(SAFE_TRANSITIVE_OVERRIDES).map(overridePackageName));\n\nexport interface EnsureLayerPackagesOptions {\n /**\n * The Po root whose layers name the packages. Its own node_modules chain is\n * resolved first; what it cannot provide is installed into the one runtime\n * every root shares, `<po home>/runtime`.\n */\n repoRoot: string;\n config: MajorModesConfig;\n layers: readonly string[];\n environment?: NodeJS.ProcessEnv;\n /**\n * Move every managed package to its newest published version.\n *\n * Launch installs what a selection needs and nothing more, so a session never\n * pays for a registry round trip. Sync is the explicit maintenance command and\n * is the only caller that asks for this.\n */\n refresh?: boolean;\n /**\n * Packages installed into the runtime whatever the root resolves itself, such as the\n * catalogue's `install` list. A `name@version` specifier pins that exact version; a\n * catalogue archive for the name still wins. Refresh never moves a pinned name.\n */\n specifiers?: readonly string[];\n /**\n * Make the runtime manifest declare exactly this run's packages (the specifiers, the\n * selected names and their catalogue dependencies), so pruning can drop anything else.\n * Without it the manifest only grows.\n */\n exactManifest?: boolean;\n /** Receives one human-readable line per package decision. */\n onProgress?: (message: string) => void;\n}\n\nexport interface LayerPackageInstallerDependencies {\n /** Install seam; the default installs `<po home>/runtime` with upm. */\n install?: (options: InstallRuntimePackagesOptions) => Promise<unknown>;\n resolvers?: ExtensionLayerResolvers;\n /** Registry lookup seam; the default resolves the newest allowed version with upm. */\n publishedVersion?: (name: string) => Promise<string>;\n}\n\n/** One managed package moving from the installed version to the newest published one. */\nexport interface LayerPackageUpdate {\n name: string;\n from: string;\n to: string;\n}\n\nexport interface LayerPackageResult {\n /** Sources installed because a configured extension could not be resolved. */\n installed: string[];\n /** Packages this run moved to a newer published version. */\n updated: LayerPackageUpdate[];\n /** Packages left at the installed version because the registry could not be read. */\n unchecked: string[];\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction recordValue(value: unknown): Record<string, unknown> {\n return isRecord(value) ? { ...value } : {};\n}\n\nfunction withoutConflictingTransitiveOverrides(value: unknown): Record<string, unknown> {\n const overrides = recordValue(value);\n for (const [selector, replacement] of Object.entries(overrides)) {\n if (SAFE_TRANSITIVE_PACKAGE_NAMES.has(overridePackageName(selector))) {\n delete overrides[selector];\n } else if (isRecord(replacement)) {\n overrides[selector] = withoutConflictingTransitiveOverrides(replacement);\n }\n }\n return overrides;\n}\n\n/** Earlier versions overrode catalog packages with relative `file:` targets; any other override is not Po's. */\nfunction withoutCatalogOverrides(overrides: Record<string, unknown>): Record<string, unknown> {\n return Object.fromEntries(\n Object.entries(overrides).filter(\n ([, replacement]) => !(typeof replacement === 'string' && replacement.startsWith(FILE_SPECIFIER_PREFIX)),\n ),\n );\n}\n\n/** The published (non-local, required) package specifiers the default and the given layers name. */\nfunction configuredPackageSpecifiers(config: MajorModesConfig, layers: readonly string[]): string[] {\n const specifiers = new Set<string>();\n const selectedDefinitions = [\n ...(config.default ? [config.default] : []),\n ...layers.map((layerName) => {\n const layer = config.layers[layerName];\n if (!layer) throw new Error(`Unknown layer: ${layerName}`);\n return layer;\n }),\n ];\n for (const layer of selectedDefinitions) {\n for (const configured of layer.packages ?? []) {\n const specifier = typeof configured === 'string' ? configured : configured.name;\n const optional = typeof configured !== 'string' && configured.optional === true;\n if (!optional && !isLocalPackageSpecifier(specifier)) specifiers.add(specifier);\n }\n }\n return [...specifiers];\n}\n\nfunction resolvePackageEntries(resolvers: ExtensionLayerResolvers, specifier: string): string[] | undefined {\n const entries = resolvers.optionalPackageEntries?.(specifier);\n if (entries !== undefined) return entries;\n const entry = resolvers.optionalPackageEntry(specifier);\n return entry ? [entry] : undefined;\n}\n\nasync function readRuntimeManifest(\n manifestPath: string,\n): Promise<{ current: string | undefined; manifest: Record<string, unknown> }> {\n const current = await fs.readFile(manifestPath, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (current === undefined) return { current, manifest: { name: RUNTIME_PACKAGE_NAME, private: true } };\n const parsed: unknown = JSON.parse(current);\n if (!isRecord(parsed)) throw new Error(`Po runtime package manifest at ${manifestPath} must be a JSON object.`);\n return { current, manifest: parsed };\n}\n\n/** Names the runtime manifest already declares: what earlier runs, from any root, installed there. */\nasync function declaredRuntimePackages(runtimeDirectory: string): Promise<Set<string>> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n return new Set(Object.keys(recordValue((await readRuntimeManifest(manifestPath)).manifest.dependencies)));\n}\n\n/**\n * Adds a package set and the patched transitive policy to the shared runtime manifest.\n *\n * `targets` pins names to exact versions or `workspace:*`. `catalogWorkspaces` maps each\n * staged catalogue archive's name to its directory relative to the runtime; the manifest\n * lists exactly those directories as its `workspaces`, so a catalogue package's dependency\n * on another one links the staged copy instead of reaching the registry. Both `overrides` and\n * `pnpm.overrides` are written; upm reads both.\n * With `exact`, declared names outside `sources` are dropped instead of kept.\n */\nexport async function ensureManagedPackageManifest(\n runtimeDirectory: string,\n sources: readonly string[],\n targets: ReadonlyMap<string, string> = new Map(),\n catalogWorkspaces: Readonly<Record<string, string>> = {},\n exact = false,\n): Promise<boolean> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n const { current, manifest } = await readRuntimeManifest(manifestPath);\n\n const declared = recordValue(manifest.dependencies);\n const sourceNames = new Set(sources.map(packageName));\n const dependencies = exact\n ? Object.fromEntries(Object.entries(declared).filter(([name]) => sourceNames.has(name)))\n : declared;\n // Every root shares this manifest, so a catalog archive another process staged (a desktop\n // build, say) may not exist for this one: without a staged copy here it falls back to the\n // registry, which keeps the whole set installable. `file:` targets are what earlier\n // versions wrote for archives.\n for (const [name, declared] of Object.entries(dependencies)) {\n if (Object.hasOwn(catalogWorkspaces, name)) {\n dependencies[name] = CATALOG_WORKSPACE_TARGET;\n } else if (\n typeof declared === 'string' &&\n (declared.startsWith(FILE_SPECIFIER_PREFIX) || declared.startsWith(WORKSPACE_SPECIFIER_PREFIX))\n ) {\n dependencies[name] = UNPINNED_PACKAGE_RANGE;\n }\n }\n for (const source of sources) {\n const name = packageName(source);\n const target = targets.get(name);\n // An exact target is what makes an update reach the store: a package manager keeps a\n // locked version whenever the recorded range still admits it.\n if (target !== undefined) dependencies[name] = target;\n else if (!Object.hasOwn(dependencies, name)) dependencies[name] = UNPINNED_PACKAGE_RANGE;\n }\n manifest.dependencies = dependencies;\n // Po owns the runtime's workspaces: exactly the staged archives, which reach only each other.\n const workspaces = Object.values(catalogWorkspaces).sort();\n if (workspaces.length > 0) manifest.workspaces = workspaces;\n else delete manifest.workspaces;\n // Nested and overlapping consumer rules can take precedence in cases that retain\n // vulnerable versions, so Po owns these package-specific selectors recursively.\n manifest.overrides = {\n ...withoutCatalogOverrides(withoutConflictingTransitiveOverrides(manifest.overrides)),\n ...SAFE_TRANSITIVE_OVERRIDES,\n };\n const pnpm = recordValue(manifest.pnpm);\n pnpm.overrides = {\n ...withoutCatalogOverrides(withoutConflictingTransitiveOverrides(pnpm.overrides)),\n ...SAFE_TRANSITIVE_OVERRIDES,\n };\n manifest.pnpm = pnpm;\n\n const serialized = `${JSON.stringify(manifest, null, 2)}\\n`;\n if (serialized === current) return false;\n await fs.mkdir(runtimeDirectory, { recursive: true });\n await writeFileAtomic(createNodePlatform().env(runtimeDirectory), manifestPath, serialized, BACKGROUND_CONTEXT);\n return true;\n}\n\n/** Finds required npm packages selected by defaults and active layers that Po cannot resolve. */\nexport function missingLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n resolvers: ExtensionLayerResolvers,\n): string[] {\n return configuredPackageSpecifiers(config, layers).filter(\n (specifier) => resolvePackageEntries(resolvers, specifier) === undefined,\n );\n}\n\n/** Whether `root`'s own node_modules chain holds the package, walked the way Node looks it up from `root`. */\nasync function ownsPackage(name: string, root: string): Promise<boolean> {\n for (let directory = path.resolve(root); ; directory = path.dirname(directory)) {\n if (\n await fs.access(path.join(directory, NODE_MODULES, name, PACKAGE_MANIFEST)).then(\n () => true,\n (error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return false;\n throw error;\n },\n )\n )\n return true;\n if (path.dirname(directory) === directory) return false;\n }\n}\n\n/**\n * The required npm packages the default and the given layers name that `root` does not get\n * from its own node_modules chain: what the shared runtime provides for it, whether it does so\n * already or not yet. Sync declares exactly these, over every root, in the runtime manifest; a\n * name the runtime already provides still counts, or the next exact manifest would drop it.\n */\nexport async function runtimeLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n root: string,\n): Promise<string[]> {\n const specifiers = configuredPackageSpecifiers(config, layers);\n const owned = await Promise.all(\n specifiers.map((specifier) => ownsPackage(splitPackageSpecifier(specifier).name, root)),\n );\n return specifiers.filter((_specifier, index) => !owned[index]);\n}\n\nfunction packageName(source: string): string {\n const specifier = source.startsWith(NPM_SOURCE_PREFIX) ? source.slice(NPM_SOURCE_PREFIX.length) : source;\n if (specifier.startsWith('@')) {\n const slash = specifier.indexOf('/');\n const version = slash === -1 ? -1 : specifier.indexOf('@', slash);\n return version === -1 ? specifier : specifier.slice(0, version);\n }\n const version = specifier.indexOf('@');\n return version === -1 ? specifier : specifier.slice(0, version);\n}\n\ninterface PackageCatalogEntry {\n /** Absolute path of the bundled archive; it takes precedence over `version`. */\n archive?: string;\n /** Exact registry version, pinned when the entry has no archive. */\n version?: string;\n dependencies: readonly string[];\n}\n\ninterface PackageCatalog {\n packages: ReadonlyMap<string, PackageCatalogEntry>;\n /** Feature packages Po installs out of the box, by name. */\n install: readonly string[];\n}\n\nconst EMPTY_CATALOG: PackageCatalog = { packages: new Map(), install: [] };\n\nfunction stringList(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const strings = value.filter((item): item is string => typeof item === 'string');\n return strings.length === value.length ? strings : undefined;\n}\n\nfunction defaultBundledCatalogPath(): string | undefined {\n try {\n return path.join(poPackageRoot(), ...BUNDLED_CATALOG_SEGMENTS);\n } catch {\n // A bundle with no locatable Po package root has no bundled catalogue to read.\n return undefined;\n }\n}\n\n/**\n * The first catalogue present: `PO_PACKAGE_CATALOG` (desktop's archives), then the one\n * a release bundles into the CLI. With neither, the runtime installs only what roots name.\n */\nasync function packageCatalogPath(environment: NodeJS.ProcessEnv): Promise<string | undefined> {\n const configured = environment[PACKAGE_CATALOG_ENV]?.trim();\n if (configured) return configured;\n const bundledCatalogPath = defaultBundledCatalogPath();\n if (bundledCatalogPath === undefined) return undefined;\n return fs.access(bundledCatalogPath).then(\n () => bundledCatalogPath,\n (error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n },\n );\n}\n\nasync function readPackageCatalog(manifestPath: string | undefined): Promise<PackageCatalog> {\n if (!manifestPath) return EMPTY_CATALOG;\n const parsed: unknown = JSON.parse(await fs.readFile(manifestPath, 'utf8'));\n if (!isRecord(parsed) || parsed.version !== 1 || !isRecord(parsed.packages)) {\n throw new Error(`Unsupported Po package catalog: ${manifestPath}`);\n }\n const packages = new Map<string, PackageCatalogEntry>();\n for (const [name, value] of Object.entries(parsed.packages)) {\n if (\n !isRecord(value) ||\n !Array.isArray(value.dependencies) ||\n (value.archive !== undefined && typeof value.archive !== 'string') ||\n (value.version !== undefined && typeof value.version !== 'string') ||\n (value.archive === undefined && value.version === undefined)\n ) {\n throw new Error(`Invalid package entry for ${name} in ${manifestPath}`);\n }\n const dependencies = stringList(value.dependencies);\n if (!dependencies) throw new Error(`Invalid dependencies for ${name} in ${manifestPath}`);\n const version = typeof value.version === 'string' ? value.version : undefined;\n if (typeof value.archive !== 'string') {\n packages.set(name, { version, dependencies });\n continue;\n }\n const archive = path.resolve(path.dirname(manifestPath), value.archive);\n await fs.access(archive).catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') throw new Error(`Po package catalog archive is missing: ${archive}`);\n throw error;\n });\n packages.set(name, { archive, version, dependencies });\n }\n const install = parsed.install === undefined ? [] : stringList(parsed.install);\n if (!install) throw new Error(`Invalid install list in ${manifestPath}`);\n const unknown = install.filter((name) => !packages.has(name));\n if (unknown.length > 0) throw new Error(`Po package catalog installs unlisted package(s): ${unknown.join(', ')}`);\n return { packages, install };\n}\n\n/**\n * The catalogue's `install` list as exact `name@version` specifiers for\n * `EnsureLayerPackagesOptions.specifiers`; empty when no catalogue is present.\n */\nexport async function catalogInstallSpecifiers(environment: NodeJS.ProcessEnv = process.env): Promise<string[]> {\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n return catalog.install.map((name) => {\n const version = catalog.packages.get(name)?.version;\n return version ? `${name}@${version}` : name;\n });\n}\n\n/**\n * The installed package roots of the catalogue's `install` list, resolved the way a root\n * resolves a bare name (its own node_modules, then the shared runtime). The global web build\n * covers them, so every first-party plugin has a slot; a name not installed yet is left out.\n */\nexport async function catalogPackageRoots(\n globalRoot: string,\n environment: NodeJS.ProcessEnv = process.env,\n): Promise<string[]> {\n const roots: string[] = [];\n for (const name of (await readPackageCatalog(await packageCatalogPath(environment))).install) {\n const manifest = consumerPackageEntry(`${name}/${PACKAGE_MANIFEST}`, globalRoot, environment);\n if (manifest !== undefined) roots.push(path.dirname(await fs.realpath(manifest)));\n }\n return roots;\n}\n\n/** SHA-256 of the catalogue file in use, or `none` when no catalogue is present. */\nexport async function packageCatalogHash(environment: NodeJS.ProcessEnv = process.env): Promise<string> {\n const catalogPath = await packageCatalogPath(environment);\n if (!catalogPath) return 'none';\n return crypto\n .createHash('sha256')\n .update(await fs.readFile(catalogPath))\n .digest('hex');\n}\n\n/** Exact target per catalogue name: its staged workspace for an archive, else its registry version. */\nfunction catalogTargets(catalog: PackageCatalog): Map<string, string> {\n return new Map(\n [...catalog.packages].flatMap(([name, entry]) => {\n if (entry.archive !== undefined) return [[name, CATALOG_WORKSPACE_TARGET] as const];\n return entry.version !== undefined ? [[name, entry.version] as const] : [];\n }),\n );\n}\n\nconst TAR_BLOCK_SIZE = 512;\nconst TAR_EXECUTABLE_BITS = 0o111;\n\nfunction tarString(block: Buffer, start: number, length: number): string {\n const field = block.subarray(start, start + length);\n const end = field.indexOf(0);\n return field.subarray(0, end === -1 ? field.length : end).toString('utf8');\n}\n\nfunction tarNumber(block: Buffer, start: number, length: number): number {\n const field = block.subarray(start, start + length);\n // GNU base-256: the high bit of the first byte marks a big-endian binary number.\n if ((field[0]! & 0x80) !== 0) return field.subarray(1).reduce((value, byte) => value * 256 + byte, field[0]! & 0x7f);\n const text = tarString(block, start, length).trim();\n return text === '' ? 0 : Number.parseInt(text, 8);\n}\n\n/** The `path` record of a pax extended header, if it has one. */\nfunction paxPath(data: Buffer): string | undefined {\n let found: string | undefined;\n let offset = 0;\n while (offset < data.length) {\n const space = data.indexOf(0x20, offset);\n if (space === -1) break;\n const length = Number.parseInt(data.subarray(offset, space).toString('utf8'), 10);\n if (!Number.isFinite(length) || length <= 0) break;\n const record = data.subarray(space + 1, offset + length - 1).toString('utf8');\n const separator = record.indexOf('=');\n if (record.slice(0, separator) === 'path') found = record.slice(separator + 1);\n offset += length;\n }\n return found;\n}\n\n/**\n * Unpacks a gzipped npm package archive into `destination`, dropping the archive's top\n * directory (`package/`) as npm does. Only files and directories are written: npm package\n * archives carry no links, and an entry that would land outside `destination` is refused.\n */\nasync function extractPackageArchive(archive: string, destination: string): Promise<void> {\n const data = zlib.gunzipSync(await fs.readFile(archive));\n let offset = 0;\n let nextPath: string | undefined;\n while (offset + TAR_BLOCK_SIZE <= data.length) {\n const header = data.subarray(offset, offset + TAR_BLOCK_SIZE);\n if (header.every((byte) => byte === 0)) break;\n const size = tarNumber(header, 124, 12);\n const type = String.fromCharCode(header[156]!);\n const body = data.subarray(offset + TAR_BLOCK_SIZE, offset + TAR_BLOCK_SIZE + size);\n offset += TAR_BLOCK_SIZE + Math.ceil(size / TAR_BLOCK_SIZE) * TAR_BLOCK_SIZE;\n if (type === 'x' || type === 'L') {\n nextPath = type === 'x' ? (paxPath(body) ?? nextPath) : tarString(body, 0, body.length);\n continue;\n }\n if (type === 'g') continue;\n const prefix = tarString(header, 345, 155);\n const name = nextPath ?? (prefix ? `${prefix}/${tarString(header, 0, 100)}` : tarString(header, 0, 100));\n nextPath = undefined;\n if (type !== '0' && type !== '\\0' && type !== '5') continue;\n const relative = name.split('/').slice(1).join('/');\n if (relative === '') continue;\n const target = path.resolve(destination, relative);\n if (!target.startsWith(`${destination}${path.sep}`)) {\n throw new Error(`Po package catalog archive ${archive} has an entry outside the package: ${name}`);\n }\n if (type === '5') {\n await fs.mkdir(target, { recursive: true });\n continue;\n }\n await fs.mkdir(path.dirname(target), { recursive: true });\n const executable = (tarNumber(header, 100, 8) & TAR_EXECUTABLE_BITS) !== 0;\n await fs.writeFile(target, body, { mode: executable ? 0o755 : 0o644 });\n }\n}\n\n/** Dependency fields of a staged manifest that may name another catalogue package. */\nconst STAGED_DEPENDENCY_FIELDS = ['dependencies', 'optionalDependencies', 'peerDependencies'] as const;\n\n/**\n * Unpacks one catalogue archive into `<runtime>/catalog/<hash>` and returns that directory\n * relative to the runtime, with the catalogue names its manifest depends on.\n *\n * upm only installs a package from a directory as a workspace: a `file:` archive takes its own\n * dependencies from the registry, so one catalogue archive could not depend on another. In the\n * staged manifest every dependency on another catalogue archive becomes `workspace:*`, so the\n * catalogue's copy wins whatever range the package declared, and `devDependencies`, which a\n * workspace would otherwise install, are dropped. The hash covers the archive bytes and the\n * catalogue's archive names, everything that rewrite reads, so a staged directory is reused.\n */\nasync function stageCatalogArchive(\n runtimeDirectory: string,\n archive: string,\n archiveNames: ReadonlySet<string>,\n): Promise<{ relative: string; dependencies: string[] }> {\n const hash = crypto\n .createHash('sha256')\n .update(await fs.readFile(archive))\n .update(`\\0${[...archiveNames].sort().join('\\n')}`)\n .digest('hex');\n const relative = `${CATALOG_STAGING_DIRECTORY}/${hash}`;\n const directory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY, hash);\n const stagedManifest = path.join(directory, PACKAGE_MANIFEST);\n const existing = await fs.readFile(stagedManifest, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return undefined;\n throw error;\n });\n if (existing === undefined) {\n const temporary = `${directory}.${String(process.pid)}.${crypto.randomUUID()}.tmp`;\n try {\n await extractPackageArchive(archive, temporary);\n const manifestPath = path.join(temporary, PACKAGE_MANIFEST);\n const bytes = await fs.readFile(manifestPath, 'utf8').catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') throw new Error(`Po package catalog archive has no package.json: ${archive}`);\n throw error;\n });\n const manifest: unknown = JSON.parse(bytes);\n if (!isRecord(manifest)) throw new Error(`Po package catalog archive has an invalid package.json: ${archive}`);\n delete manifest.devDependencies;\n for (const field of STAGED_DEPENDENCY_FIELDS) {\n if (!isRecord(manifest[field])) continue;\n const declared = { ...manifest[field] };\n for (const name of Object.keys(declared)) {\n if (archiveNames.has(name)) declared[name] = CATALOG_WORKSPACE_TARGET;\n }\n manifest[field] = declared;\n }\n await fs.writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\\n`);\n try {\n await fs.rename(temporary, directory);\n } catch (error) {\n // Another process staged the same bytes first; its copy is identical.\n await fs.access(stagedManifest).catch(() => {\n throw error;\n });\n }\n } finally {\n await fs.rm(temporary, { recursive: true, force: true });\n }\n }\n const staged = recordValue(JSON.parse(existing ?? (await fs.readFile(stagedManifest, 'utf8'))));\n const dependencies = STAGED_DEPENDENCY_FIELDS.flatMap((field) => Object.keys(recordValue(staged[field])));\n return { relative, dependencies: dependencies.filter((name) => archiveNames.has(name)) };\n}\n\n/**\n * Stages the archive of every named catalogue package and of every catalogue package those\n * name in turn, since a staged manifest's `workspace:*` needs that workspace present. The\n * result, name to staged directory, feeds `ensureManagedPackageManifest`.\n */\nasync function stageCatalogArchives(\n runtimeDirectory: string,\n catalog: PackageCatalog,\n names: Iterable<string>,\n): Promise<Record<string, string>> {\n const archiveNames = new Set(\n [...catalog.packages].flatMap(([name, entry]) => (entry.archive === undefined ? [] : [name])),\n );\n const staged: Record<string, string> = {};\n const pending = [...names].filter((name) => archiveNames.has(name));\n while (pending.length > 0) {\n const name = pending.shift()!;\n if (Object.hasOwn(staged, name)) continue;\n const { relative, dependencies } = await stageCatalogArchive(\n runtimeDirectory,\n catalog.packages.get(name)!.archive!,\n archiveNames,\n );\n staged[name] = relative;\n pending.push(...dependencies);\n }\n return staged;\n}\n\n/**\n * Removes staged archives the runtime manifest no longer lists as workspaces, and returns their\n * folder names. An install never calls this: a running server imports from these folders (its\n * `.po-snapshots` live there), so sync prunes them under the same gate as the runtime store.\n */\nexport async function pruneStagedCatalogArchives(runtimeDirectory: string): Promise<string[]> {\n const stagingDirectory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY);\n const entries = await fs.readdir(stagingDirectory).catch((error: NodeJS.ErrnoException) => {\n if (error.code === 'ENOENT') return [];\n throw error;\n });\n const { manifest } = await readRuntimeManifest(path.join(runtimeDirectory, PACKAGE_MANIFEST));\n const kept = new Set((stringList(manifest.workspaces) ?? []).map((relative) => path.basename(relative)));\n return Promise.all(\n entries\n .filter((entry) => !kept.has(entry))\n .map(async (entry) => {\n await fs.rm(path.join(stagingDirectory, entry), { recursive: true, force: true });\n return entry;\n }),\n );\n}\n\n/** Splits `name@version` (scoped or not); the version is absent for a bare name or subpath. */\nfunction splitVersionedSpecifier(specifier: string): { name: string; version?: string } {\n const separator = specifier.indexOf('@', specifier.startsWith('@') ? 1 : 0);\n if (separator === -1) return { name: splitPackageSpecifier(specifier).name };\n return { name: specifier.slice(0, separator), version: specifier.slice(separator + 1) };\n}\n\nfunction npmSources(\n specifiers: readonly string[],\n catalog: PackageCatalog,\n targets: ReadonlyMap<string, string>,\n includeCatalogDependencies = false,\n): string[] {\n const names = [...new Set(specifiers.map((specifier) => splitPackageSpecifier(specifier).name))];\n if (includeCatalogDependencies) {\n for (let index = 0; index < names.length; index += 1) {\n for (const dependency of catalog.packages.get(names[index]!)?.dependencies ?? []) {\n if (!names.includes(dependency)) names.push(dependency);\n }\n }\n }\n return names.map((name) => {\n const target = targets.get(name);\n return `${NPM_SOURCE_PREFIX}${name}${target ? `@${target}` : ''}`;\n });\n}\n\nfunction pluralize(count: number, noun: string): string {\n return `${count} ${noun}${count === 1 ? '' : 's'}`;\n}\n\n/** Version of a package inside the shared runtime, absent when Po did not install it there. */\nasync function managedPackageVersion(runtimeDirectory: string, name: string): Promise<string | undefined> {\n const manifestPath = path.join(runtimeDirectory, NODE_MODULES, name, PACKAGE_MANIFEST);\n try {\n const parsed: unknown = JSON.parse(await fs.readFile(manifestPath, 'utf8'));\n return isRecord(parsed) && typeof parsed.version === 'string' ? parsed.version : undefined;\n } catch {\n // An unreadable manifest carries the same meaning as an absent one: nothing\n // usable is installed, so the caller treats the package as uninstalled.\n return undefined;\n }\n}\n\nfunction errorCode(error: unknown): unknown {\n return typeof error === 'object' && error !== null ? (error as { code?: unknown }).code : undefined;\n}\n\n/**\n * Installs the runtime, and when the registry cannot be reached installs it again offline:\n * an unchanged lockfile whose packages the store already holds needs no network.\n */\nasync function installWithOfflineRetry(\n install: NonNullable<LayerPackageInstallerDependencies['install']>,\n options: InstallRuntimePackagesOptions,\n onProgress: ((message: string) => void) | undefined,\n): Promise<void> {\n try {\n await install(options);\n } catch (error) {\n const code = errorCode(error);\n if (typeof code !== 'string' || !NETWORK_FAILURE_CODES.has(code)) throw error;\n onProgress?.(`the registry is unreachable (${code}); installing offline from the store`);\n try {\n await install({ ...options, preferOffline: false, offline: true });\n } catch {\n // The offline attempt only ever narrows the original failure: the network error\n // explains why the install could not complete, an EOFFLINE miss does not.\n throw error;\n }\n }\n}\n\ninterface CheckedPackage {\n name: string;\n from: string;\n to?: string;\n failure?: string;\n}\n\n/**\n * Compares every package sync installed against the registry.\n *\n * Only the shared runtime is consulted: a package that resolves from the\n * repository's own modules is not sync's to move, and a package that is not\n * installed yet is already covered by the missing-package path.\n */\nasync function resolveUpdates(\n runtimeDirectory: string,\n sources: readonly string[],\n publishedVersion: (name: string) => Promise<string>,\n onProgress: ((message: string) => void) | undefined,\n): Promise<Pick<LayerPackageResult, 'updated' | 'unchecked'>> {\n const managed = (\n await Promise.all(\n sources.map(async (source) => ({\n name: packageName(source),\n from: await managedPackageVersion(runtimeDirectory, packageName(source)),\n })),\n )\n ).filter((entry): entry is { name: string; from: string } => entry.from !== undefined);\n const checked: CheckedPackage[] = await Promise.all(\n managed.map(async (entry) => {\n try {\n return { ...entry, to: await publishedVersion(entry.name) };\n } catch (error) {\n return { ...entry, failure: (error instanceof Error ? error.message : String(error)).split('\\n')[0] };\n }\n }),\n );\n\n const updated: LayerPackageUpdate[] = [];\n const unchecked: string[] = [];\n for (const entry of checked) {\n if (entry.to === undefined) {\n unchecked.push(entry.name);\n onProgress?.(`kept ${entry.name} ${entry.from}: ${entry.failure ?? 'no published version'}`);\n continue;\n }\n if (entry.to === entry.from) continue;\n updated.push({ name: entry.name, from: entry.from, to: entry.to });\n onProgress?.(`${entry.name} ${entry.from} -> ${entry.to}`);\n }\n return { updated, unchecked };\n}\n\n/**\n * Installs the selected layer packages a root cannot resolve into the shared runtime,\n * `<po home>/runtime`, and verifies they now resolve.\n *\n * The runtime manifest is the union of what every root asked for. A root adds the\n * packages it is missing; a package it already resolves from its own node_modules stays\n * out unless an earlier run put it there. One name has one version: an exact target\n * (a sync update, a catalog archive or registry pin) replaces the declared range, last\n * writer wins, and a plain `*` never replaces a range already declared.\n *\n * `specifiers` and `exactManifest` only add behaviour: without them, and without a\n * catalogue, a run behaves as it always has.\n */\nexport async function ensureLayerPackages(\n options: EnsureLayerPackagesOptions,\n dependencies: LayerPackageInstallerDependencies = {},\n): Promise<LayerPackageResult> {\n const environment = options.environment ?? process.env;\n const homeDirectory = environment.HOME ?? os.homedir();\n const poHome = poHomeDirectory(homeDirectory, environment);\n const runtimeDirectory = poRuntimeDirectory(homeDirectory, environment);\n // The root's own .npmrc routes and authenticates the registries its layers name.\n const npmrcFiles = [path.join(options.repoRoot, '.npmrc')];\n const resolvers = dependencies.resolvers ?? createLayerResolvers(options.repoRoot, environment);\n const external = (specifier: string): boolean => testPackageRoot(packageName(specifier), environment) === undefined;\n const configured = configuredPackageSpecifiers(options.config, options.layers).filter(external);\n const missing = configured.filter((specifier) => resolvePackageEntries(resolvers, specifier) === undefined);\n const declared = await declaredRuntimePackages(runtimeDirectory);\n const managed = configured.filter(\n (specifier) => missing.includes(specifier) || declared.has(splitPackageSpecifier(specifier).name),\n );\n const requested = (options.specifiers ?? []).filter(external).map(splitVersionedSpecifier);\n if (managed.length === 0 && requested.length === 0 && options.exactManifest !== true) {\n return { installed: [], updated: [], unchecked: [] };\n }\n\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n const pins = catalogTargets(catalog);\n for (const { name, version } of requested) {\n if (version !== undefined && catalog.packages.get(name)?.archive === undefined) pins.set(name, version);\n }\n // A requested package is missing until the runtime holds it at the version it is pinned to.\n const requestedMissing: string[] = [];\n for (const { name, version } of requested) {\n const installed = await managedPackageVersion(runtimeDirectory, name);\n const entry = catalog.packages.get(name);\n const expected = entry?.archive === undefined ? version : entry.version;\n if (installed === undefined || (expected !== undefined && installed !== expected)) requestedMissing.push(name);\n }\n const missingSources = npmSources([...missing, ...requestedMissing], catalog, pins);\n const sources = npmSources([...managed, ...requested.map(({ name }) => name)], catalog, pins, true).filter(external);\n const missingCount = missing.length + requestedMissing.length;\n\n // Refresh never moves a pinned name: catalogue entries and versioned specifiers stay put.\n const fixedNames = new Set([\n ...catalog.packages.keys(),\n ...requested.filter(({ version }) => version !== undefined).map(({ name }) => name),\n ]);\n const registrySources = sources.filter((source) => !fixedNames.has(packageName(source)));\n const { updated, unchecked } = options.refresh\n ? await resolveUpdates(\n runtimeDirectory,\n registrySources,\n dependencies.publishedVersion ?? ((name) => resolveNewest(name, { dir: runtimeDirectory, poHome, npmrcFiles })),\n options.onProgress,\n )\n : { updated: [], unchecked: [] };\n const targets = new Map(\n sources.flatMap((source) => {\n const target = pins.get(packageName(source));\n return target ? [[packageName(source), target] as const] : [];\n }),\n );\n for (const update of updated) targets.set(update.name, update.to);\n // A kept manifest still declares names earlier runs added; their archives are staged too.\n const stagedNames = new Set([...sources.map(packageName), ...(options.exactManifest === true ? [] : declared)]);\n const staged = await stageCatalogArchives(runtimeDirectory, catalog, stagedNames);\n const manifestChanged = await ensureManagedPackageManifest(\n runtimeDirectory,\n sources,\n targets,\n staged,\n options.exactManifest === true,\n );\n if (missingCount === 0 && !manifestChanged) return { installed: [], updated: [], unchecked };\n\n options.onProgress?.(\n `installing ${\n updated.length > 0\n ? pluralize(updated.length, 'update')\n : missingCount > 0\n ? pluralize(missingCount, 'missing package')\n : 'the package manifest'\n }`,\n );\n try {\n // One install reconciles the complete dependency set written to package.json.\n await installWithOfflineRetry(\n dependencies.install ?? installRuntimePackages,\n {\n dir: runtimeDirectory,\n poHome,\n npmrcFiles,\n // A launch never waits on registry revalidation; sync is the command that refreshes.\n preferOffline: options.refresh !== true,\n log: (message, level) => {\n if (level === 'warn') options.onProgress?.(message);\n },\n },\n options.onProgress,\n );\n } catch (error) {\n const attempted = manifestChanged ? sources : missingSources;\n throw new Error(\n `Failed to reconcile Po layer package(s): ${attempted.join(', ')}: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error },\n );\n }\n\n const unresolved = missing.filter((specifier) => !resolvePackageEntries(resolvers, specifier)?.length);\n if (unresolved.length > 0) {\n throw new Error(\n `Installed Po layer package(s) did not expose the configured Pi extension: ${unresolved.join(', ')}`,\n );\n }\n return { installed: missingSources, updated, unchecked };\n}\n\n/** One selector per name in the shared runtime. Caller holds the sync lock throughout. */\nexport async function ensureRuntimeImportPackage(\n name: string,\n version: string,\n options: { homeDirectory: string; environment: Readonly<Record<string, string | undefined>> },\n): Promise<void> {\n const environment = { ...options.environment, HOME: options.homeDirectory };\n const poHome = poHomeDirectory(options.homeDirectory, environment);\n const directory = poRuntimeDirectory(options.homeDirectory, environment);\n const manifestPath = path.join(directory, PACKAGE_MANIFEST);\n const { manifest } = await readRuntimeManifest(manifestPath);\n const declared = recordValue(manifest.dependencies);\n const imports = recordValue(manifest.poCodemodeDependencies);\n const imported = recordValue(imports[name]);\n const catalog = await readPackageCatalog(await packageCatalogPath(environment));\n if (catalog.packages.has(name) || (Object.hasOwn(declared, name) && declared[name] !== imported.selector)) {\n throw new Error(\n `Cannot import ${name}: Po manages this runtime dependency (${JSON.stringify(declared[name] ?? 'catalogue')}).`,\n );\n }\n if (Object.hasOwn(imports, name) && imported.selector !== version) {\n throw new Error(`Cannot import ${name}@${version}: the hub already uses ${name}@${String(imported.selector)}.`);\n }\n const installed = await managedPackageVersion(directory, name);\n if (declared[name] === version && installed !== undefined && imported.resolved === installed) return;\n // Only a successful reconciliation is cacheable, not the manifest upm writes ahead of a failed install.\n manifest.poCodemodeDependencies = { ...imports, [name]: { selector: version } };\n await writeFileAtomic(\n createNodePlatform().env(directory),\n manifestPath,\n `${JSON.stringify(manifest, null, 2)}\\n`,\n BACKGROUND_CONTEXT,\n );\n const pins = new Map([[name, version]]);\n const sources = npmSources([`${name}@${version}`], catalog, pins, true);\n const staged = await stageCatalogArchives(\n directory,\n catalog,\n new Set([...sources.map(packageName), ...Object.keys(declared)]),\n );\n await ensureManagedPackageManifest(directory, sources, pins, staged);\n await installWithOfflineRetry(installRuntimePackages, { dir: directory, poHome, preferOffline: true }, undefined);\n const resolved = await managedPackageVersion(directory, name);\n if (resolved === undefined) throw new Error(`Runtime import ${name}@${version} was not installed.`);\n const reconciled = (await readRuntimeManifest(manifestPath)).manifest;\n reconciled.poCodemodeDependencies = {\n ...recordValue(reconciled.poCodemodeDependencies),\n [name]: { selector: version, resolved },\n };\n await writeFileAtomic(\n createNodePlatform().env(directory),\n manifestPath,\n `${JSON.stringify(reconciled, null, 2)}\\n`,\n BACKGROUND_CONTEXT,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;AAC1B,MAAM,wBAAwB;AAC9B,MAAM,6BAA6B;;AAEnC,MAAM,2BAA2B;;AAEjC,MAAM,4BAA4B;AAClC,MAAM,uBAAuB;AAC7B,MAAM,yBAAyB;AAC/B,MAAM,mBAAmB;AACzB,MAAM,eAAe;AACrB,MAAM,sBAAsB;;AAE5B,MAAM,2BAA2B;CAAC;CAAQ;CAAW;AAAY;;AAEjE,MAAM,wCAAwB,IAAI,IAAI;CAAC;CAAY;CAAa;AAAW,CAAC;AAE5E,SAAS,oBAAoB,UAA0B;CACrD,MAAM,iBAAiB,SAAS,QAAQ,KAAK,SAAS,WAAW,GAAG,IAAI,IAAI,CAAC;CAC7E,OAAO,mBAAmB,KAAK,WAAW,SAAS,MAAM,GAAG,cAAc;AAC5E;;;;;;AAOA,MAAa,4BAA4B;CAEvC,+BAA+B;CAC/B,mCAAmC;CACnC,uCAAuC;CACvC,kCAAkC;CAClC,kCAAkC;CAClC,uBAAuB;CACvB,yBAAyB;CACzB,yBAAyB;CACzB,6BAA6B;CAC7B,4BAA4B;CAC5B,yBAAyB;AAC3B;AAEA,MAAM,gCAAgC,IAAI,IAAI,OAAO,KAAK,yBAAyB,CAAC,CAAC,IAAI,mBAAmB,CAAC;AA4D7G,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,YAAY,OAAyC;CAC5D,OAAO,SAAS,KAAK,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC;AAC3C;AAEA,S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AAQ,oBAAoB;CAClG,MAAM,cAAc,MAAM,oBAAoB,YAAY,EAAA,CAAG;CAC7D,WAAW,yBAAyB;EAClC,GAAG,YAAY,WAAW,sBAAsB;GAC/C,OAAO;GAAE,UAAU;GAAS;EAAS;CACxC;CACA,MAAM,gBACJ,mBAAmB,CAAC,CAAC,IAAI,SAAS,GAClC,cACA,GAAG,KAAK,UAAU,YAAY,MAAM,CAAC,EAAE,KACvC,kBACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/po",
3
- "version": "0.0.0-alpha.101",
3
+ "version": "0.0.0-alpha.102",
4
4
  "description": "Opinionated, composable agent harness for scoped tools, skills, MCP servers, and developer workflows.",
5
5
  "keywords": [
6
6
  "agent-harness",
@@ -177,31 +177,31 @@
177
177
  "registry": "https://registry.npmjs.org/"
178
178
  },
179
179
  "dependencies": {
180
- "@agimon-ai/po-approval": "0.0.0-alpha.100",
181
- "@agimon-ai/po-artifact": "0.0.0-alpha.99",
182
- "@agimon-ai/po-autostop": "0.0.0-alpha.100",
183
- "@agimon-ai/po-cache": "0.0.0-alpha.100",
184
- "@agimon-ai/po-config": "0.0.0-alpha.100",
185
- "@agimon-ai/po-core": "0.0.0-alpha.100",
186
- "@agimon-ai/po-db": "0.0.0-alpha.100",
187
- "@agimon-ai/po-domain": "0.0.0-alpha.100",
188
- "@agimon-ai/po-logsink": "0.0.1-alpha.82",
189
- "@agimon-ai/po-major-mode": "0.0.0-alpha.100",
190
- "@agimon-ai/po-mcp-proxy": "0.0.1-alpha.79",
191
- "@agimon-ai/po-minor-mode": "0.0.0-alpha.100",
192
- "@agimon-ai/po-native-components": "0.0.0-alpha.100",
193
- "@agimon-ai/po-network": "0.0.2-alpha.47",
194
- "@agimon-ai/po-notification": "0.0.0-alpha.100",
195
- "@agimon-ai/po-profile": "0.0.0-alpha.100",
196
- "@agimon-ai/po-session": "0.0.0-alpha.100",
197
- "@agimon-ai/po-skill": "0.0.0-alpha.100",
198
- "@agimon-ai/po-ui": "0.0.0-alpha.100",
199
- "@agimon-ai/po-vault": "0.0.0-alpha.100",
200
- "@agimon-ai/po-web-components": "0.0.0-alpha.100",
201
- "@agimon-ai/po-web-security": "0.0.0-alpha.100",
180
+ "@agimon-ai/po-approval": "0.0.0-alpha.101",
181
+ "@agimon-ai/po-artifact": "0.0.0-alpha.100",
182
+ "@agimon-ai/po-autostop": "0.0.0-alpha.101",
183
+ "@agimon-ai/po-cache": "0.0.0-alpha.101",
184
+ "@agimon-ai/po-config": "0.0.0-alpha.101",
185
+ "@agimon-ai/po-core": "0.0.0-alpha.101",
186
+ "@agimon-ai/po-db": "0.0.0-alpha.101",
187
+ "@agimon-ai/po-domain": "0.0.0-alpha.101",
188
+ "@agimon-ai/po-logsink": "0.0.1-alpha.83",
189
+ "@agimon-ai/po-major-mode": "0.0.0-alpha.101",
190
+ "@agimon-ai/po-mcp-proxy": "0.0.1-alpha.80",
191
+ "@agimon-ai/po-minor-mode": "0.0.0-alpha.101",
192
+ "@agimon-ai/po-native-components": "0.0.0-alpha.101",
193
+ "@agimon-ai/po-network": "0.0.2-alpha.48",
194
+ "@agimon-ai/po-notification": "0.0.0-alpha.101",
195
+ "@agimon-ai/po-profile": "0.0.0-alpha.101",
196
+ "@agimon-ai/po-session": "0.0.0-alpha.101",
197
+ "@agimon-ai/po-skill": "0.0.0-alpha.101",
198
+ "@agimon-ai/po-ui": "0.0.0-alpha.101",
199
+ "@agimon-ai/po-vault": "0.0.0-alpha.101",
200
+ "@agimon-ai/po-web-components": "0.0.0-alpha.101",
201
+ "@agimon-ai/po-web-security": "0.0.0-alpha.101",
202
202
  "@deepseek-ai/cordis": "4.0.5",
203
- "@earendil-works/pi-agent-core": "1.4.0",
204
- "@earendil-works/pi-coding-agent": "1.4.0",
203
+ "@earendil-works/pi-agent-core": "1.5.0",
204
+ "@earendil-works/pi-coding-agent": "1.5.0",
205
205
  "@hono/node-server": "2.1.5",
206
206
  "@simplewebauthn/server": "^14.0.3",
207
207
  "@tailwindcss/vite": "4.3.3",
@@ -220,11 +220,11 @@
220
220
  "yaml": "2.9.1"
221
221
  },
222
222
  "devDependencies": {
223
- "@agimon-ai/po-calendar": "0.0.1-alpha.59",
224
- "@agimon-ai/po-identity": "0.0.2-alpha.47",
225
- "@agimon-ai/po-runner": "0.0.0-alpha.100",
226
- "@agimon-ai/vibe-lint-plugin-po-cli": "0.0.0-alpha.100",
227
- "@earendil-works/pi-ai": "1.4.0",
223
+ "@agimon-ai/po-calendar": "0.0.1-alpha.60",
224
+ "@agimon-ai/po-identity": "0.0.2-alpha.48",
225
+ "@agimon-ai/po-runner": "0.0.0-alpha.101",
226
+ "@agimon-ai/vibe-lint-plugin-po-cli": "0.0.0-alpha.101",
227
+ "@earendil-works/pi-ai": "1.5.0",
228
228
  "@modelcontextprotocol/ext-apps": "2.0.3",
229
229
  "@modelcontextprotocol/server": "2.3.1",
230
230
  "@playwright/test": "^1.64.1",