@agimon-ai/po 0.0.0-alpha.7 → 0.0.0-alpha.9

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.7",
5
+ "version": "0.0.0-alpha.9",
6
6
  "dependencies": [
7
7
  "@agimon-ai/po-artifact",
8
8
  "@agimon-ai/po-autostop",
@@ -23,7 +23,7 @@
23
23
  ]
24
24
  },
25
25
  "@agimon-ai/po-artifact": {
26
- "version": "0.0.0-alpha.6",
26
+ "version": "0.0.0-alpha.7",
27
27
  "dependencies": [
28
28
  "@agimon-ai/po-core",
29
29
  "@agimon-ai/po-web-components",
@@ -31,7 +31,7 @@
31
31
  ]
32
32
  },
33
33
  "@agimon-ai/po-author": {
34
- "version": "0.0.0-alpha.7",
34
+ "version": "0.0.0-alpha.8",
35
35
  "dependencies": [
36
36
  "@agimon-ai/po-artifact",
37
37
  "@agimon-ai/po-core",
@@ -41,7 +41,7 @@
41
41
  ]
42
42
  },
43
43
  "@agimon-ai/po-autocompact": {
44
- "version": "0.0.0-alpha.7",
44
+ "version": "0.0.0-alpha.8",
45
45
  "dependencies": [
46
46
  "@agimon-ai/po-config",
47
47
  "@agimon-ai/po-core",
@@ -49,25 +49,25 @@
49
49
  ]
50
50
  },
51
51
  "@agimon-ai/po-autostop": {
52
- "version": "0.0.0-alpha.7",
52
+ "version": "0.0.0-alpha.8",
53
53
  "dependencies": [
54
54
  "@agimon-ai/po-core",
55
55
  "@agimon-ai/po-telemetry"
56
56
  ]
57
57
  },
58
58
  "@agimon-ai/po-browse": {
59
- "version": "0.0.1-alpha.5",
59
+ "version": "0.0.1-alpha.6",
60
60
  "dependencies": [
61
61
  "@agimon-ai/po-core",
62
62
  "@agimon-ai/po-web-components"
63
63
  ]
64
64
  },
65
65
  "@agimon-ai/po-build": {
66
- "version": "0.0.0-alpha.7",
66
+ "version": "0.0.0-alpha.8",
67
67
  "dependencies": []
68
68
  },
69
69
  "@agimon-ai/po-cache": {
70
- "version": "0.0.0-alpha.7",
70
+ "version": "0.0.0-alpha.8",
71
71
  "dependencies": [
72
72
  "@agimon-ai/po-config",
73
73
  "@agimon-ai/po-core",
@@ -75,7 +75,7 @@
75
75
  ]
76
76
  },
77
77
  "@agimon-ai/po-computer-use": {
78
- "version": "0.0.0-alpha.7",
78
+ "version": "0.0.0-alpha.8",
79
79
  "dependencies": [
80
80
  "@agimon-ai/po-config",
81
81
  "@agimon-ai/po-core",
@@ -85,7 +85,7 @@
85
85
  ]
86
86
  },
87
87
  "@agimon-ai/po-config": {
88
- "version": "0.0.0-alpha.7",
88
+ "version": "0.0.0-alpha.8",
89
89
  "dependencies": [
90
90
  "@agimon-ai/po-core",
91
91
  "@agimon-ai/po-telemetry",
@@ -93,14 +93,14 @@
93
93
  ]
94
94
  },
95
95
  "@agimon-ai/po-core": {
96
- "version": "0.0.0-alpha.7",
96
+ "version": "0.0.0-alpha.8",
97
97
  "dependencies": [
98
98
  "@agimon-ai/po-telemetry",
99
99
  "@agimon-ai/po-web-security"
100
100
  ]
101
101
  },
102
102
  "@agimon-ai/po-domain": {
103
- "version": "0.0.0-alpha.7",
103
+ "version": "0.0.0-alpha.8",
104
104
  "dependencies": [
105
105
  "@agimon-ai/po-config",
106
106
  "@agimon-ai/po-core",
@@ -109,7 +109,7 @@
109
109
  ]
110
110
  },
111
111
  "@agimon-ai/po-edit": {
112
- "version": "0.0.0-alpha.7",
112
+ "version": "0.0.0-alpha.8",
113
113
  "dependencies": [
114
114
  "@agimon-ai/po-core",
115
115
  "@agimon-ai/po-hashline",
@@ -118,7 +118,7 @@
118
118
  ]
119
119
  },
120
120
  "@agimon-ai/po-file-edit": {
121
- "version": "0.0.0-alpha.7",
121
+ "version": "0.0.0-alpha.8",
122
122
  "dependencies": [
123
123
  "@agimon-ai/po-config",
124
124
  "@agimon-ai/po-core",
@@ -129,7 +129,7 @@
129
129
  ]
130
130
  },
131
131
  "@agimon-ai/po-git": {
132
- "version": "0.0.0-alpha.7",
132
+ "version": "0.0.0-alpha.8",
133
133
  "dependencies": [
134
134
  "@agimon-ai/po-core",
135
135
  "@agimon-ai/po-session",
@@ -138,7 +138,7 @@
138
138
  ]
139
139
  },
140
140
  "@agimon-ai/po-goal": {
141
- "version": "0.0.0-alpha.7",
141
+ "version": "0.0.0-alpha.8",
142
142
  "dependencies": [
143
143
  "@agimon-ai/po-core",
144
144
  "@agimon-ai/po-minor-mode",
@@ -147,7 +147,7 @@
147
147
  ]
148
148
  },
149
149
  "@agimon-ai/po-grep": {
150
- "version": "0.0.0-alpha.7",
150
+ "version": "0.0.0-alpha.8",
151
151
  "dependencies": [
152
152
  "@agimon-ai/po-core",
153
153
  "@agimon-ai/po-hashline",
@@ -156,11 +156,11 @@
156
156
  ]
157
157
  },
158
158
  "@agimon-ai/po-hashline": {
159
- "version": "0.0.0-alpha.7",
159
+ "version": "0.0.0-alpha.8",
160
160
  "dependencies": []
161
161
  },
162
162
  "@agimon-ai/po-help": {
163
- "version": "0.0.0-alpha.7",
163
+ "version": "0.0.0-alpha.8",
164
164
  "dependencies": [
165
165
  "@agimon-ai/po-core",
166
166
  "@agimon-ai/po-minor-mode",
@@ -168,7 +168,7 @@
168
168
  ]
169
169
  },
170
170
  "@agimon-ai/po-hook": {
171
- "version": "0.0.0-alpha.7",
171
+ "version": "0.0.0-alpha.8",
172
172
  "dependencies": [
173
173
  "@agimon-ai/po-config",
174
174
  "@agimon-ai/po-core",
@@ -176,7 +176,7 @@
176
176
  ]
177
177
  },
178
178
  "@agimon-ai/po-image-gen": {
179
- "version": "0.0.0-alpha.6",
179
+ "version": "0.0.0-alpha.7",
180
180
  "dependencies": [
181
181
  "@agimon-ai/po-core",
182
182
  "@agimon-ai/po-web-components",
@@ -184,7 +184,7 @@
184
184
  ]
185
185
  },
186
186
  "@agimon-ai/po-log": {
187
- "version": "0.0.0-alpha.7",
187
+ "version": "0.0.0-alpha.8",
188
188
  "dependencies": [
189
189
  "@agimon-ai/po-core",
190
190
  "@agimon-ai/po-telemetry",
@@ -193,7 +193,7 @@
193
193
  ]
194
194
  },
195
195
  "@agimon-ai/po-loop": {
196
- "version": "0.0.0-alpha.7",
196
+ "version": "0.0.0-alpha.8",
197
197
  "dependencies": [
198
198
  "@agimon-ai/po-core",
199
199
  "@agimon-ai/po-minor-mode",
@@ -202,7 +202,7 @@
202
202
  ]
203
203
  },
204
204
  "@agimon-ai/po-major-mode": {
205
- "version": "0.0.0-alpha.7",
205
+ "version": "0.0.0-alpha.8",
206
206
  "dependencies": [
207
207
  "@agimon-ai/po-config",
208
208
  "@agimon-ai/po-core",
@@ -211,7 +211,7 @@
211
211
  ]
212
212
  },
213
213
  "@agimon-ai/po-mcp": {
214
- "version": "0.0.0-alpha.7",
214
+ "version": "0.0.0-alpha.8",
215
215
  "dependencies": [
216
216
  "@agimon-ai/po-config",
217
217
  "@agimon-ai/po-core",
@@ -220,33 +220,33 @@
220
220
  ]
221
221
  },
222
222
  "@agimon-ai/po-minor-mode": {
223
- "version": "0.0.0-alpha.7",
223
+ "version": "0.0.0-alpha.8",
224
224
  "dependencies": [
225
225
  "@agimon-ai/po-core",
226
226
  "@agimon-ai/po-telemetry"
227
227
  ]
228
228
  },
229
229
  "@agimon-ai/po-model-guidance": {
230
- "version": "0.0.0-alpha.7",
230
+ "version": "0.0.0-alpha.8",
231
231
  "dependencies": [
232
232
  "@agimon-ai/po-config",
233
233
  "@agimon-ai/po-core"
234
234
  ]
235
235
  },
236
236
  "@agimon-ai/po-native-components": {
237
- "version": "0.0.0-alpha.7",
237
+ "version": "0.0.0-alpha.8",
238
238
  "dependencies": [
239
239
  "@agimon-ai/po-web-components"
240
240
  ]
241
241
  },
242
242
  "@agimon-ai/po-notification": {
243
- "version": "0.0.0-alpha.7",
243
+ "version": "0.0.0-alpha.8",
244
244
  "dependencies": [
245
245
  "@agimon-ai/po-core"
246
246
  ]
247
247
  },
248
248
  "@agimon-ai/po-plan": {
249
- "version": "0.0.0-alpha.7",
249
+ "version": "0.0.0-alpha.8",
250
250
  "dependencies": [
251
251
  "@agimon-ai/po-config",
252
252
  "@agimon-ai/po-core",
@@ -257,7 +257,7 @@
257
257
  ]
258
258
  },
259
259
  "@agimon-ai/po-profile": {
260
- "version": "0.0.0-alpha.7",
260
+ "version": "0.0.0-alpha.8",
261
261
  "dependencies": [
262
262
  "@agimon-ai/po-config",
263
263
  "@agimon-ai/po-core",
@@ -266,7 +266,7 @@
266
266
  ]
267
267
  },
268
268
  "@agimon-ai/po-prompt": {
269
- "version": "0.0.0-alpha.7",
269
+ "version": "0.0.0-alpha.8",
270
270
  "dependencies": [
271
271
  "@agimon-ai/po-core",
272
272
  "@agimon-ai/po-web-components",
@@ -274,7 +274,7 @@
274
274
  ]
275
275
  },
276
276
  "@agimon-ai/po-read": {
277
- "version": "0.0.0-alpha.7",
277
+ "version": "0.0.0-alpha.8",
278
278
  "dependencies": [
279
279
  "@agimon-ai/po-config",
280
280
  "@agimon-ai/po-core",
@@ -284,7 +284,7 @@
284
284
  ]
285
285
  },
286
286
  "@agimon-ai/po-runner": {
287
- "version": "0.0.0-alpha.7",
287
+ "version": "0.0.0-alpha.8",
288
288
  "dependencies": [
289
289
  "@agimon-ai/po-core",
290
290
  "@agimon-ai/po-telemetry",
@@ -294,19 +294,19 @@
294
294
  ]
295
295
  },
296
296
  "@agimon-ai/po-sandbox": {
297
- "version": "0.0.0-alpha.7",
297
+ "version": "0.0.0-alpha.8",
298
298
  "dependencies": [
299
299
  "@agimon-ai/po-core"
300
300
  ]
301
301
  },
302
302
  "@agimon-ai/po-session": {
303
- "version": "0.0.0-alpha.7",
303
+ "version": "0.0.0-alpha.8",
304
304
  "dependencies": [
305
305
  "@agimon-ai/po-core"
306
306
  ]
307
307
  },
308
308
  "@agimon-ai/po-skill": {
309
- "version": "0.0.0-alpha.7",
309
+ "version": "0.0.0-alpha.8",
310
310
  "dependencies": [
311
311
  "@agimon-ai/po-config",
312
312
  "@agimon-ai/po-core",
@@ -316,7 +316,7 @@
316
316
  ]
317
317
  },
318
318
  "@agimon-ai/po-style-system": {
319
- "version": "0.0.0-alpha.7",
319
+ "version": "0.0.0-alpha.8",
320
320
  "dependencies": [
321
321
  "@agimon-ai/po-core",
322
322
  "@agimon-ai/po-web-components",
@@ -324,7 +324,7 @@
324
324
  ]
325
325
  },
326
326
  "@agimon-ai/po-task": {
327
- "version": "0.0.0-alpha.7",
327
+ "version": "0.0.0-alpha.8",
328
328
  "dependencies": [
329
329
  "@agimon-ai/po-core",
330
330
  "@agimon-ai/po-telemetry",
@@ -333,7 +333,7 @@
333
333
  ]
334
334
  },
335
335
  "@agimon-ai/po-team": {
336
- "version": "0.0.0-alpha.7",
336
+ "version": "0.0.0-alpha.8",
337
337
  "dependencies": [
338
338
  "@agimon-ai/po-cache",
339
339
  "@agimon-ai/po-config",
@@ -346,11 +346,11 @@
346
346
  ]
347
347
  },
348
348
  "@agimon-ai/po-telemetry": {
349
- "version": "0.0.0-alpha.7",
349
+ "version": "0.0.0-alpha.8",
350
350
  "dependencies": []
351
351
  },
352
352
  "@agimon-ai/po-template-advanced": {
353
- "version": "0.0.0-alpha.7",
353
+ "version": "0.0.0-alpha.8",
354
354
  "dependencies": [
355
355
  "@agimon-ai/po-core",
356
356
  "@agimon-ai/po-web-components",
@@ -358,7 +358,7 @@
358
358
  ]
359
359
  },
360
360
  "@agimon-ai/po-template-elegant": {
361
- "version": "0.0.0-alpha.7",
361
+ "version": "0.0.0-alpha.8",
362
362
  "dependencies": [
363
363
  "@agimon-ai/po-core",
364
364
  "@agimon-ai/po-web-components",
@@ -366,7 +366,7 @@
366
366
  ]
367
367
  },
368
368
  "@agimon-ai/po-ui": {
369
- "version": "0.0.0-alpha.7",
369
+ "version": "0.0.0-alpha.8",
370
370
  "dependencies": [
371
371
  "@agimon-ai/po-core",
372
372
  "@agimon-ai/po-hashline",
@@ -376,7 +376,7 @@
376
376
  ]
377
377
  },
378
378
  "@agimon-ai/po-user-feedback": {
379
- "version": "0.0.0-alpha.7",
379
+ "version": "0.0.0-alpha.8",
380
380
  "dependencies": [
381
381
  "@agimon-ai/po-core",
382
382
  "@agimon-ai/po-minor-mode",
@@ -384,7 +384,7 @@
384
384
  ]
385
385
  },
386
386
  "@agimon-ai/po-voice": {
387
- "version": "0.0.0-alpha.7",
387
+ "version": "0.0.0-alpha.8",
388
388
  "dependencies": [
389
389
  "@agimon-ai/po-config",
390
390
  "@agimon-ai/po-core",
@@ -397,11 +397,11 @@
397
397
  ]
398
398
  },
399
399
  "@agimon-ai/po-web-components": {
400
- "version": "0.0.0-alpha.7",
400
+ "version": "0.0.0-alpha.8",
401
401
  "dependencies": []
402
402
  },
403
403
  "@agimon-ai/po-web-dashboard": {
404
- "version": "0.0.0-alpha.7",
404
+ "version": "0.0.0-alpha.8",
405
405
  "dependencies": [
406
406
  "@agimon-ai/po-core",
407
407
  "@agimon-ai/po-web-components",
@@ -409,18 +409,18 @@
409
409
  ]
410
410
  },
411
411
  "@agimon-ai/po-web-search": {
412
- "version": "0.0.0-alpha.6",
412
+ "version": "0.0.0-alpha.7",
413
413
  "dependencies": [
414
414
  "@agimon-ai/po-core",
415
415
  "@agimon-ai/po-web-components"
416
416
  ]
417
417
  },
418
418
  "@agimon-ai/po-web-security": {
419
- "version": "0.0.0-alpha.7",
419
+ "version": "0.0.0-alpha.8",
420
420
  "dependencies": []
421
421
  },
422
422
  "@agimon-ai/po-workflow": {
423
- "version": "0.0.0-alpha.7",
423
+ "version": "0.0.0-alpha.8",
424
424
  "dependencies": [
425
425
  "@agimon-ai/po-core",
426
426
  "@agimon-ai/po-minor-mode",
@@ -51,7 +51,7 @@ function overridePackageName(selector) {
51
51
  * cannot carry these fixes in their own manifests.
52
52
  */
53
53
  const SAFE_TRANSITIVE_OVERRIDES = {
54
- "@earendil-works/pi-codemode": "1.2.0",
54
+ "@earendil-works/pi-codemode": "1.3.0",
55
55
  "@hono/node-server@2.0.0 - 2.0.9": "^2.0.10",
56
56
  "@opentelemetry/core@2.0.0 - 2.7.999": "2.8.0",
57
57
  "brace-expansion@1.0.0 - 1.1.20": "^1.1.21",
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["isLocalPackageSpecifier","fs","path","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';\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 { writeFileAtomic } from '@agimon-ai/po-core/runtimeJson';\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.2.0's declaration API; advance with the host's Pi version.\n '@earendil-works/pi-codemode': '1.2.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\nfunction readRuntimeManifest(manifestPath: string): { current: string | undefined; manifest: Record<string, unknown> } {\n const current = fs.existsSync(manifestPath) ? fs.readFileSync(manifestPath, 'utf8') : undefined;\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. */\nfunction declaredRuntimePackages(runtimeDirectory: string): Set<string> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) return new Set();\n return new Set(Object.keys(recordValue(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 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): boolean {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n const { current, manifest } = 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 fs.mkdirSync(runtimeDirectory, { recursive: true });\n writeFileAtomic(manifestPath, serialized);\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`. */\nfunction ownsPackage(name: string, root: string): boolean {\n for (let directory = path.resolve(root); ; directory = path.dirname(directory)) {\n if (fs.existsSync(path.join(directory, NODE_MODULES, name, PACKAGE_MANIFEST))) 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 function runtimeLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n root: string,\n): string[] {\n return configuredPackageSpecifiers(config, layers).filter(\n (specifier) => !ownsPackage(splitPackageSpecifier(specifier).name, root),\n );\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 */\nfunction packageCatalogPath(environment: NodeJS.ProcessEnv): string | undefined {\n const configured = environment[PACKAGE_CATALOG_ENV]?.trim();\n if (configured) return configured;\n const bundledCatalogPath = defaultBundledCatalogPath();\n return bundledCatalogPath !== undefined && fs.existsSync(bundledCatalogPath) ? bundledCatalogPath : undefined;\n}\n\nfunction readPackageCatalog(manifestPath: string | undefined): PackageCatalog {\n if (!manifestPath) return EMPTY_CATALOG;\n const parsed: unknown = JSON.parse(fs.readFileSync(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 if (!fs.existsSync(archive)) throw new Error(`Po package catalog archive is missing: ${archive}`);\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 function catalogInstallSpecifiers(environment: NodeJS.ProcessEnv = process.env): string[] {\n const catalog = readPackageCatalog(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 function catalogPackageRoots(globalRoot: string, environment: NodeJS.ProcessEnv = process.env): string[] {\n const roots: string[] = [];\n for (const name of readPackageCatalog(packageCatalogPath(environment)).install) {\n const manifest = consumerPackageEntry(`${name}/${PACKAGE_MANIFEST}`, globalRoot, environment);\n if (manifest !== undefined) roots.push(path.dirname(fs.realpathSync(manifest)));\n }\n return roots;\n}\n\n/** SHA-256 of the catalogue file in use, or `none` when no catalogue is present. */\nexport function packageCatalogHash(environment: NodeJS.ProcessEnv = process.env): string {\n const catalogPath = packageCatalogPath(environment);\n if (!catalogPath) return 'none';\n return crypto.createHash('sha256').update(fs.readFileSync(catalogPath)).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 */\nfunction extractPackageArchive(archive: string, destination: string): void {\n const data = zlib.gunzipSync(fs.readFileSync(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 fs.mkdirSync(target, { recursive: true });\n continue;\n }\n fs.mkdirSync(path.dirname(target), { recursive: true });\n const executable = (tarNumber(header, 100, 8) & TAR_EXECUTABLE_BITS) !== 0;\n fs.writeFileSync(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 */\nfunction stageCatalogArchive(\n runtimeDirectory: string,\n archive: string,\n archiveNames: ReadonlySet<string>,\n): { relative: string; dependencies: string[] } {\n const hash = crypto\n .createHash('sha256')\n .update(fs.readFileSync(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 if (!fs.existsSync(stagedManifest)) {\n const temporary = `${directory}.${String(process.pid)}.${crypto.randomUUID()}.tmp`;\n try {\n extractPackageArchive(archive, temporary);\n const manifestPath = path.join(temporary, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) throw new Error(`Po package catalog archive has no package.json: ${archive}`);\n const manifest: unknown = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\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 fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\\n`);\n try {\n fs.renameSync(temporary, directory);\n } catch (error) {\n // Another process staged the same bytes first; its copy is identical.\n if (!fs.existsSync(stagedManifest)) throw error;\n }\n } finally {\n fs.rmSync(temporary, { recursive: true, force: true });\n }\n }\n const staged = recordValue(JSON.parse(fs.readFileSync(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 */\nfunction stageCatalogArchives(\n runtimeDirectory: string,\n catalog: PackageCatalog,\n names: Iterable<string>,\n): 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 } = 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 function pruneStagedCatalogArchives(runtimeDirectory: string): string[] {\n const stagingDirectory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY);\n if (!fs.existsSync(stagingDirectory)) return [];\n const { manifest } = readRuntimeManifest(path.join(runtimeDirectory, PACKAGE_MANIFEST));\n const kept = new Set((stringList(manifest.workspaces) ?? []).map((relative) => path.basename(relative)));\n return fs\n .readdirSync(stagingDirectory)\n .filter((entry) => !kept.has(entry))\n .map((entry) => {\n fs.rmSync(path.join(stagingDirectory, entry), { recursive: true, force: true });\n return entry;\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. */\nfunction managedPackageVersion(runtimeDirectory: string, name: string): string | undefined {\n const manifestPath = path.join(runtimeDirectory, NODE_MODULES, name, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) return undefined;\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(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 = sources\n .map((source) => ({\n name: packageName(source),\n from: managedPackageVersion(runtimeDirectory, packageName(source)),\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 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 = 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 = readPackageCatalog(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 = requested\n .filter(({ name, version }) => {\n const installed = managedPackageVersion(runtimeDirectory, name);\n const entry = catalog.packages.get(name);\n const expected = entry?.archive === undefined ? version : entry.version;\n return installed === undefined || (expected !== undefined && installed !== expected);\n })\n .map(({ name }) => name);\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 })),\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 = stageCatalogArchives(runtimeDirectory, catalog, stagedNames);\n const manifestChanged = 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 // 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"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,MAAM,oBAAoB;AAC1B,MAAM,wBAAwB;AAC9B,MAAM,6BAA6B;;AAEnC,MAAM,2BAA2B;;AAEjC,MAAM,4BAA4B;AAClC,MAA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AO,MAAM,CACjB;CACF;CAEA,MAAM,aAAa,QAAQ,QAAQ,cAAc,CAAC,sBAAsB,WAAW,SAAS,CAAC,EAAE,MAAM;CACrG,IAAI,WAAW,SAAS,GACtB,MAAM,IAAI,MACR,6EAA6E,WAAW,KAAK,IAAI,GACnG;CAEF,OAAO;EAAE,WAAW;EAAgB;EAAS;CAAU;AACzD"}
1
+ {"version":3,"file":"index.cjs","names":["isLocalPackageSpecifier","fs","path","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';\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 { writeFileAtomic } from '@agimon-ai/po-core/runtimeJson';\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.3.0's declaration API; advance with the host's Pi version.\n '@earendil-works/pi-codemode': '1.3.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\nfunction readRuntimeManifest(manifestPath: string): { current: string | undefined; manifest: Record<string, unknown> } {\n const current = fs.existsSync(manifestPath) ? fs.readFileSync(manifestPath, 'utf8') : undefined;\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. */\nfunction declaredRuntimePackages(runtimeDirectory: string): Set<string> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) return new Set();\n return new Set(Object.keys(recordValue(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 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): boolean {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n const { current, manifest } = 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 fs.mkdirSync(runtimeDirectory, { recursive: true });\n writeFileAtomic(manifestPath, serialized);\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`. */\nfunction ownsPackage(name: string, root: string): boolean {\n for (let directory = path.resolve(root); ; directory = path.dirname(directory)) {\n if (fs.existsSync(path.join(directory, NODE_MODULES, name, PACKAGE_MANIFEST))) 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 function runtimeLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n root: string,\n): string[] {\n return configuredPackageSpecifiers(config, layers).filter(\n (specifier) => !ownsPackage(splitPackageSpecifier(specifier).name, root),\n );\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 */\nfunction packageCatalogPath(environment: NodeJS.ProcessEnv): string | undefined {\n const configured = environment[PACKAGE_CATALOG_ENV]?.trim();\n if (configured) return configured;\n const bundledCatalogPath = defaultBundledCatalogPath();\n return bundledCatalogPath !== undefined && fs.existsSync(bundledCatalogPath) ? bundledCatalogPath : undefined;\n}\n\nfunction readPackageCatalog(manifestPath: string | undefined): PackageCatalog {\n if (!manifestPath) return EMPTY_CATALOG;\n const parsed: unknown = JSON.parse(fs.readFileSync(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 if (!fs.existsSync(archive)) throw new Error(`Po package catalog archive is missing: ${archive}`);\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 function catalogInstallSpecifiers(environment: NodeJS.ProcessEnv = process.env): string[] {\n const catalog = readPackageCatalog(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 function catalogPackageRoots(globalRoot: string, environment: NodeJS.ProcessEnv = process.env): string[] {\n const roots: string[] = [];\n for (const name of readPackageCatalog(packageCatalogPath(environment)).install) {\n const manifest = consumerPackageEntry(`${name}/${PACKAGE_MANIFEST}`, globalRoot, environment);\n if (manifest !== undefined) roots.push(path.dirname(fs.realpathSync(manifest)));\n }\n return roots;\n}\n\n/** SHA-256 of the catalogue file in use, or `none` when no catalogue is present. */\nexport function packageCatalogHash(environment: NodeJS.ProcessEnv = process.env): string {\n const catalogPath = packageCatalogPath(environment);\n if (!catalogPath) return 'none';\n return crypto.createHash('sha256').update(fs.readFileSync(catalogPath)).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 */\nfunction extractPackageArchive(archive: string, destination: string): void {\n const data = zlib.gunzipSync(fs.readFileSync(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 fs.mkdirSync(target, { recursive: true });\n continue;\n }\n fs.mkdirSync(path.dirname(target), { recursive: true });\n const executable = (tarNumber(header, 100, 8) & TAR_EXECUTABLE_BITS) !== 0;\n fs.writeFileSync(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 */\nfunction stageCatalogArchive(\n runtimeDirectory: string,\n archive: string,\n archiveNames: ReadonlySet<string>,\n): { relative: string; dependencies: string[] } {\n const hash = crypto\n .createHash('sha256')\n .update(fs.readFileSync(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 if (!fs.existsSync(stagedManifest)) {\n const temporary = `${directory}.${String(process.pid)}.${crypto.randomUUID()}.tmp`;\n try {\n extractPackageArchive(archive, temporary);\n const manifestPath = path.join(temporary, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) throw new Error(`Po package catalog archive has no package.json: ${archive}`);\n const manifest: unknown = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\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 fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\\n`);\n try {\n fs.renameSync(temporary, directory);\n } catch (error) {\n // Another process staged the same bytes first; its copy is identical.\n if (!fs.existsSync(stagedManifest)) throw error;\n }\n } finally {\n fs.rmSync(temporary, { recursive: true, force: true });\n }\n }\n const staged = recordValue(JSON.parse(fs.readFileSync(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 */\nfunction stageCatalogArchives(\n runtimeDirectory: string,\n catalog: PackageCatalog,\n names: Iterable<string>,\n): 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 } = 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 function pruneStagedCatalogArchives(runtimeDirectory: string): string[] {\n const stagingDirectory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY);\n if (!fs.existsSync(stagingDirectory)) return [];\n const { manifest } = readRuntimeManifest(path.join(runtimeDirectory, PACKAGE_MANIFEST));\n const kept = new Set((stringList(manifest.workspaces) ?? []).map((relative) => path.basename(relative)));\n return fs\n .readdirSync(stagingDirectory)\n .filter((entry) => !kept.has(entry))\n .map((entry) => {\n fs.rmSync(path.join(stagingDirectory, entry), { recursive: true, force: true });\n return entry;\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. */\nfunction managedPackageVersion(runtimeDirectory: string, name: string): string | undefined {\n const manifestPath = path.join(runtimeDirectory, NODE_MODULES, name, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) return undefined;\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(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 = sources\n .map((source) => ({\n name: packageName(source),\n from: managedPackageVersion(runtimeDirectory, packageName(source)),\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 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 = 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 = readPackageCatalog(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 = requested\n .filter(({ name, version }) => {\n const installed = managedPackageVersion(runtimeDirectory, name);\n const entry = catalog.packages.get(name);\n const expected = entry?.archive === undefined ? version : entry.version;\n return installed === undefined || (expected !== undefined && installed !== expected);\n })\n .map(({ name }) => name);\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 })),\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 = stageCatalogArchives(runtimeDirectory, catalog, stagedNames);\n const manifestChanged = 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 // 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"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,MAAM,oBAAoB;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,UAAU,eAAA,CAEU,KAAK,IAAI,EAAE,IAAI,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KAC1H,EAAE,OAAO,MAAM,CACjB;CACF;CAEA,MAAM,aAAa,QAAQ,QAAQ,cAAc,CAAC,sBAAsB,WAAW,SAAS,CAAC,EAAE,MAAM;CACrG,IAAI,WAAW,SAAS,GACtB,MAAM,IAAI,MACR,6EAA6E,WAAW,KAAK,IAAI,GACnG;CAEF,OAAO;EAAE,WAAW;EAAgB;EAAS;CAAU;AACzD"}
@@ -45,7 +45,7 @@ function overridePackageName(selector) {
45
45
  * cannot carry these fixes in their own manifests.
46
46
  */
47
47
  const SAFE_TRANSITIVE_OVERRIDES = {
48
- "@earendil-works/pi-codemode": "1.2.0",
48
+ "@earendil-works/pi-codemode": "1.3.0",
49
49
  "@hono/node-server@2.0.0 - 2.0.9": "^2.0.10",
50
50
  "@opentelemetry/core@2.0.0 - 2.7.999": "2.8.0",
51
51
  "brace-expansion@1.0.0 - 1.1.20": "^1.1.21",
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["isRecord"],"sources":["../../../../src/composition/layerPackageInstaller/index.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\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 { writeFileAtomic } from '@agimon-ai/po-core/runtimeJson';\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.2.0's declaration API; advance with the host's Pi version.\n '@earendil-works/pi-codemode': '1.2.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\nfunction readRuntimeManifest(manifestPath: string): { current: string | undefined; manifest: Record<string, unknown> } {\n const current = fs.existsSync(manifestPath) ? fs.readFileSync(manifestPath, 'utf8') : undefined;\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. */\nfunction declaredRuntimePackages(runtimeDirectory: string): Set<string> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) return new Set();\n return new Set(Object.keys(recordValue(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 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): boolean {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n const { current, manifest } = 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 fs.mkdirSync(runtimeDirectory, { recursive: true });\n writeFileAtomic(manifestPath, serialized);\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`. */\nfunction ownsPackage(name: string, root: string): boolean {\n for (let directory = path.resolve(root); ; directory = path.dirname(directory)) {\n if (fs.existsSync(path.join(directory, NODE_MODULES, name, PACKAGE_MANIFEST))) 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 function runtimeLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n root: string,\n): string[] {\n return configuredPackageSpecifiers(config, layers).filter(\n (specifier) => !ownsPackage(splitPackageSpecifier(specifier).name, root),\n );\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 */\nfunction packageCatalogPath(environment: NodeJS.ProcessEnv): string | undefined {\n const configured = environment[PACKAGE_CATALOG_ENV]?.trim();\n if (configured) return configured;\n const bundledCatalogPath = defaultBundledCatalogPath();\n return bundledCatalogPath !== undefined && fs.existsSync(bundledCatalogPath) ? bundledCatalogPath : undefined;\n}\n\nfunction readPackageCatalog(manifestPath: string | undefined): PackageCatalog {\n if (!manifestPath) return EMPTY_CATALOG;\n const parsed: unknown = JSON.parse(fs.readFileSync(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 if (!fs.existsSync(archive)) throw new Error(`Po package catalog archive is missing: ${archive}`);\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 function catalogInstallSpecifiers(environment: NodeJS.ProcessEnv = process.env): string[] {\n const catalog = readPackageCatalog(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 function catalogPackageRoots(globalRoot: string, environment: NodeJS.ProcessEnv = process.env): string[] {\n const roots: string[] = [];\n for (const name of readPackageCatalog(packageCatalogPath(environment)).install) {\n const manifest = consumerPackageEntry(`${name}/${PACKAGE_MANIFEST}`, globalRoot, environment);\n if (manifest !== undefined) roots.push(path.dirname(fs.realpathSync(manifest)));\n }\n return roots;\n}\n\n/** SHA-256 of the catalogue file in use, or `none` when no catalogue is present. */\nexport function packageCatalogHash(environment: NodeJS.ProcessEnv = process.env): string {\n const catalogPath = packageCatalogPath(environment);\n if (!catalogPath) return 'none';\n return crypto.createHash('sha256').update(fs.readFileSync(catalogPath)).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 */\nfunction extractPackageArchive(archive: string, destination: string): void {\n const data = zlib.gunzipSync(fs.readFileSync(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 fs.mkdirSync(target, { recursive: true });\n continue;\n }\n fs.mkdirSync(path.dirname(target), { recursive: true });\n const executable = (tarNumber(header, 100, 8) & TAR_EXECUTABLE_BITS) !== 0;\n fs.writeFileSync(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 */\nfunction stageCatalogArchive(\n runtimeDirectory: string,\n archive: string,\n archiveNames: ReadonlySet<string>,\n): { relative: string; dependencies: string[] } {\n const hash = crypto\n .createHash('sha256')\n .update(fs.readFileSync(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 if (!fs.existsSync(stagedManifest)) {\n const temporary = `${directory}.${String(process.pid)}.${crypto.randomUUID()}.tmp`;\n try {\n extractPackageArchive(archive, temporary);\n const manifestPath = path.join(temporary, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) throw new Error(`Po package catalog archive has no package.json: ${archive}`);\n const manifest: unknown = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\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 fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\\n`);\n try {\n fs.renameSync(temporary, directory);\n } catch (error) {\n // Another process staged the same bytes first; its copy is identical.\n if (!fs.existsSync(stagedManifest)) throw error;\n }\n } finally {\n fs.rmSync(temporary, { recursive: true, force: true });\n }\n }\n const staged = recordValue(JSON.parse(fs.readFileSync(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 */\nfunction stageCatalogArchives(\n runtimeDirectory: string,\n catalog: PackageCatalog,\n names: Iterable<string>,\n): 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 } = 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 function pruneStagedCatalogArchives(runtimeDirectory: string): string[] {\n const stagingDirectory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY);\n if (!fs.existsSync(stagingDirectory)) return [];\n const { manifest } = readRuntimeManifest(path.join(runtimeDirectory, PACKAGE_MANIFEST));\n const kept = new Set((stringList(manifest.workspaces) ?? []).map((relative) => path.basename(relative)));\n return fs\n .readdirSync(stagingDirectory)\n .filter((entry) => !kept.has(entry))\n .map((entry) => {\n fs.rmSync(path.join(stagingDirectory, entry), { recursive: true, force: true });\n return entry;\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. */\nfunction managedPackageVersion(runtimeDirectory: string, name: string): string | undefined {\n const manifestPath = path.join(runtimeDirectory, NODE_MODULES, name, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) return undefined;\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(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 = sources\n .map((source) => ({\n name: packageName(source),\n from: managedPackageVersion(runtimeDirectory, packageName(source)),\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 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 = 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 = readPackageCatalog(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 = requested\n .filter(({ name, version }) => {\n const installed = managedPackageVersion(runtimeDirectory, name);\n const entry = catalog.packages.get(name);\n const expected = entry?.archive === undefined ? version : entry.version;\n return installed === undefined || (expected !== undefined && installed !== expected);\n })\n .map(({ name }) => name);\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 })),\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 = stageCatalogArchives(runtimeDirectory, catalog, stagedNames);\n const manifestChanged = 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 // 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"],"mappings":";;;;;;;;;;;;;AAmBA,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,SAASA,WAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,YAAY,OAAyC;CAC5D,OAAOA,WAAS,KAAK,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC;A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import crypto from 'node:crypto';\nimport fs from 'node:fs';\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 { writeFileAtomic } from '@agimon-ai/po-core/runtimeJson';\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.3.0's declaration API; advance with the host's Pi version.\n '@earendil-works/pi-codemode': '1.3.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\nfunction readRuntimeManifest(manifestPath: string): { current: string | undefined; manifest: Record<string, unknown> } {\n const current = fs.existsSync(manifestPath) ? fs.readFileSync(manifestPath, 'utf8') : undefined;\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. */\nfunction declaredRuntimePackages(runtimeDirectory: string): Set<string> {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) return new Set();\n return new Set(Object.keys(recordValue(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 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): boolean {\n const manifestPath = path.join(runtimeDirectory, PACKAGE_MANIFEST);\n const { current, manifest } = 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 fs.mkdirSync(runtimeDirectory, { recursive: true });\n writeFileAtomic(manifestPath, serialized);\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`. */\nfunction ownsPackage(name: string, root: string): boolean {\n for (let directory = path.resolve(root); ; directory = path.dirname(directory)) {\n if (fs.existsSync(path.join(directory, NODE_MODULES, name, PACKAGE_MANIFEST))) 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 function runtimeLayerPackageSpecifiers(\n config: MajorModesConfig,\n layers: readonly string[],\n root: string,\n): string[] {\n return configuredPackageSpecifiers(config, layers).filter(\n (specifier) => !ownsPackage(splitPackageSpecifier(specifier).name, root),\n );\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 */\nfunction packageCatalogPath(environment: NodeJS.ProcessEnv): string | undefined {\n const configured = environment[PACKAGE_CATALOG_ENV]?.trim();\n if (configured) return configured;\n const bundledCatalogPath = defaultBundledCatalogPath();\n return bundledCatalogPath !== undefined && fs.existsSync(bundledCatalogPath) ? bundledCatalogPath : undefined;\n}\n\nfunction readPackageCatalog(manifestPath: string | undefined): PackageCatalog {\n if (!manifestPath) return EMPTY_CATALOG;\n const parsed: unknown = JSON.parse(fs.readFileSync(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 if (!fs.existsSync(archive)) throw new Error(`Po package catalog archive is missing: ${archive}`);\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 function catalogInstallSpecifiers(environment: NodeJS.ProcessEnv = process.env): string[] {\n const catalog = readPackageCatalog(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 function catalogPackageRoots(globalRoot: string, environment: NodeJS.ProcessEnv = process.env): string[] {\n const roots: string[] = [];\n for (const name of readPackageCatalog(packageCatalogPath(environment)).install) {\n const manifest = consumerPackageEntry(`${name}/${PACKAGE_MANIFEST}`, globalRoot, environment);\n if (manifest !== undefined) roots.push(path.dirname(fs.realpathSync(manifest)));\n }\n return roots;\n}\n\n/** SHA-256 of the catalogue file in use, or `none` when no catalogue is present. */\nexport function packageCatalogHash(environment: NodeJS.ProcessEnv = process.env): string {\n const catalogPath = packageCatalogPath(environment);\n if (!catalogPath) return 'none';\n return crypto.createHash('sha256').update(fs.readFileSync(catalogPath)).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 */\nfunction extractPackageArchive(archive: string, destination: string): void {\n const data = zlib.gunzipSync(fs.readFileSync(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 fs.mkdirSync(target, { recursive: true });\n continue;\n }\n fs.mkdirSync(path.dirname(target), { recursive: true });\n const executable = (tarNumber(header, 100, 8) & TAR_EXECUTABLE_BITS) !== 0;\n fs.writeFileSync(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 */\nfunction stageCatalogArchive(\n runtimeDirectory: string,\n archive: string,\n archiveNames: ReadonlySet<string>,\n): { relative: string; dependencies: string[] } {\n const hash = crypto\n .createHash('sha256')\n .update(fs.readFileSync(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 if (!fs.existsSync(stagedManifest)) {\n const temporary = `${directory}.${String(process.pid)}.${crypto.randomUUID()}.tmp`;\n try {\n extractPackageArchive(archive, temporary);\n const manifestPath = path.join(temporary, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) throw new Error(`Po package catalog archive has no package.json: ${archive}`);\n const manifest: unknown = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\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 fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\\n`);\n try {\n fs.renameSync(temporary, directory);\n } catch (error) {\n // Another process staged the same bytes first; its copy is identical.\n if (!fs.existsSync(stagedManifest)) throw error;\n }\n } finally {\n fs.rmSync(temporary, { recursive: true, force: true });\n }\n }\n const staged = recordValue(JSON.parse(fs.readFileSync(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 */\nfunction stageCatalogArchives(\n runtimeDirectory: string,\n catalog: PackageCatalog,\n names: Iterable<string>,\n): 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 } = 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 function pruneStagedCatalogArchives(runtimeDirectory: string): string[] {\n const stagingDirectory = path.join(runtimeDirectory, CATALOG_STAGING_DIRECTORY);\n if (!fs.existsSync(stagingDirectory)) return [];\n const { manifest } = readRuntimeManifest(path.join(runtimeDirectory, PACKAGE_MANIFEST));\n const kept = new Set((stringList(manifest.workspaces) ?? []).map((relative) => path.basename(relative)));\n return fs\n .readdirSync(stagingDirectory)\n .filter((entry) => !kept.has(entry))\n .map((entry) => {\n fs.rmSync(path.join(stagingDirectory, entry), { recursive: true, force: true });\n return entry;\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. */\nfunction managedPackageVersion(runtimeDirectory: string, name: string): string | undefined {\n const manifestPath = path.join(runtimeDirectory, NODE_MODULES, name, PACKAGE_MANIFEST);\n if (!fs.existsSync(manifestPath)) return undefined;\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(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 = sources\n .map((source) => ({\n name: packageName(source),\n from: managedPackageVersion(runtimeDirectory, packageName(source)),\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 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 = 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 = readPackageCatalog(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 = requested\n .filter(({ name, version }) => {\n const installed = managedPackageVersion(runtimeDirectory, name);\n const entry = catalog.packages.get(name);\n const expected = entry?.archive === undefined ? version : entry.version;\n return installed === undefined || (expected !== undefined && installed !== expected);\n })\n .map(({ name }) => name);\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 })),\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 = stageCatalogArchives(runtimeDirectory, catalog, stagedNames);\n const manifestChanged = 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 // 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"],"mappings":";;;;;;;;;;;;;AAmBA,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,M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;GACpD;EACF,GACA,QAAQ,UACV;CACF,SAAS,OAAO;EAEd,MAAM,IAAI,MACR,6CAFgB,kBAAkB,UAAU,eAAA,CAEU,KAAK,IAAI,EAAE,IAAI,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KAC1H,EAAE,OAAO,MAAM,CACjB;CACF;CAEA,MAAM,aAAa,QAAQ,QAAQ,cAAc,CAAC,sBAAsB,WAAW,SAAS,CAAC,EAAE,MAAM;CACrG,IAAI,WAAW,SAAS,GACtB,MAAM,IAAI,MACR,6EAA6E,WAAW,KAAK,IAAI,GACnG;CAEF,OAAO;EAAE,WAAW;EAAgB;EAAS;CAAU;AACzD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/po",
3
- "version": "0.0.0-alpha.7",
3
+ "version": "0.0.0-alpha.9",
4
4
  "description": "Opinionated, composable agent harness for scoped tools, skills, MCP servers, and developer workflows.",
5
5
  "keywords": [
6
6
  "agent-harness",
@@ -213,25 +213,25 @@
213
213
  },
214
214
  "dependencies": {
215
215
  "@agimon-ai/log-sink-mcp": "0.30.13",
216
- "@agimon-ai/po-artifact": "0.0.0-alpha.6",
217
- "@agimon-ai/po-autostop": "0.0.0-alpha.7",
218
- "@agimon-ai/po-cache": "0.0.0-alpha.7",
219
- "@agimon-ai/po-config": "0.0.0-alpha.7",
220
- "@agimon-ai/po-core": "0.0.0-alpha.7",
221
- "@agimon-ai/po-domain": "0.0.0-alpha.7",
222
- "@agimon-ai/po-major-mode": "0.0.0-alpha.7",
223
- "@agimon-ai/po-minor-mode": "0.0.0-alpha.7",
224
- "@agimon-ai/po-notification": "0.0.0-alpha.7",
225
- "@agimon-ai/po-profile": "0.0.0-alpha.7",
226
- "@agimon-ai/po-session": "0.0.0-alpha.7",
227
- "@agimon-ai/po-skill": "0.0.0-alpha.7",
228
- "@agimon-ai/po-telemetry": "0.0.0-alpha.7",
229
- "@agimon-ai/po-ui": "0.0.0-alpha.7",
230
- "@agimon-ai/po-web-components": "0.0.0-alpha.7",
231
- "@agimon-ai/po-web-security": "0.0.0-alpha.7",
216
+ "@agimon-ai/po-artifact": "0.0.0-alpha.7",
217
+ "@agimon-ai/po-autostop": "0.0.0-alpha.8",
218
+ "@agimon-ai/po-cache": "0.0.0-alpha.8",
219
+ "@agimon-ai/po-config": "0.0.0-alpha.8",
220
+ "@agimon-ai/po-core": "0.0.0-alpha.8",
221
+ "@agimon-ai/po-domain": "0.0.0-alpha.8",
222
+ "@agimon-ai/po-major-mode": "0.0.0-alpha.8",
223
+ "@agimon-ai/po-minor-mode": "0.0.0-alpha.8",
224
+ "@agimon-ai/po-notification": "0.0.0-alpha.8",
225
+ "@agimon-ai/po-profile": "0.0.0-alpha.8",
226
+ "@agimon-ai/po-session": "0.0.0-alpha.8",
227
+ "@agimon-ai/po-skill": "0.0.0-alpha.8",
228
+ "@agimon-ai/po-telemetry": "0.0.0-alpha.8",
229
+ "@agimon-ai/po-ui": "0.0.0-alpha.8",
230
+ "@agimon-ai/po-web-components": "0.0.0-alpha.8",
231
+ "@agimon-ai/po-web-security": "0.0.0-alpha.8",
232
232
  "@deepseek-ai/cordis": "4.0.4",
233
- "@earendil-works/pi-agent-core": "1.2.0",
234
- "@earendil-works/pi-coding-agent": "1.2.0",
233
+ "@earendil-works/pi-agent-core": "1.3.0",
234
+ "@earendil-works/pi-coding-agent": "1.3.0",
235
235
  "@hono/node-server": "2.1.5",
236
236
  "@simplewebauthn/server": "^14.0.3",
237
237
  "@tailwindcss/vite": "4.3.3",
@@ -249,9 +249,9 @@
249
249
  "yaml": "2.9.1"
250
250
  },
251
251
  "devDependencies": {
252
- "@agimon-ai/po-runner": "0.0.0-alpha.7",
253
- "@agimon-ai/vibe-lint-plugin-po-cli": "0.0.0-alpha.7",
254
- "@earendil-works/pi-ai": "1.2.0",
252
+ "@agimon-ai/po-runner": "0.0.0-alpha.8",
253
+ "@agimon-ai/vibe-lint-plugin-po-cli": "0.0.0-alpha.8",
254
+ "@earendil-works/pi-ai": "1.3.0",
255
255
  "@modelcontextprotocol/ext-apps": "2.0.3",
256
256
  "@modelcontextprotocol/server": "2.3.1",
257
257
  "@playwright/test": "^1.64.0",