@inventarch/distribution 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +2 -2
  4. package/SPEC.md +3 -0
  5. package/assets/host-launcher.mjs +167 -0
  6. package/dist/acquire.d.ts +13 -0
  7. package/dist/acquire.d.ts.map +1 -0
  8. package/dist/acquire.js +46 -0
  9. package/dist/acquire.js.map +1 -0
  10. package/dist/archive.d.ts +20 -0
  11. package/dist/archive.d.ts.map +1 -0
  12. package/dist/archive.js +158 -0
  13. package/dist/archive.js.map +1 -0
  14. package/dist/authoring-assets.d.ts +11 -0
  15. package/dist/authoring-assets.d.ts.map +1 -0
  16. package/dist/authoring-assets.js +251 -0
  17. package/dist/authoring-assets.js.map +1 -0
  18. package/dist/bounded-fetch.d.ts +17 -0
  19. package/dist/bounded-fetch.d.ts.map +1 -0
  20. package/dist/bounded-fetch.js +67 -0
  21. package/dist/bounded-fetch.js.map +1 -0
  22. package/dist/cli.d.ts +3 -0
  23. package/dist/cli.d.ts.map +1 -0
  24. package/dist/cli.js +29 -0
  25. package/dist/cli.js.map +1 -0
  26. package/dist/command.d.ts +6 -0
  27. package/dist/command.d.ts.map +1 -0
  28. package/dist/command.js +189 -0
  29. package/dist/command.js.map +1 -0
  30. package/dist/config.d.ts +4 -0
  31. package/dist/config.d.ts.map +1 -0
  32. package/dist/config.js +43 -0
  33. package/dist/config.js.map +1 -0
  34. package/dist/decisions.d.ts +26 -0
  35. package/dist/decisions.d.ts.map +1 -0
  36. package/dist/decisions.js +119 -0
  37. package/dist/decisions.js.map +1 -0
  38. package/dist/files.d.ts +38 -0
  39. package/dist/files.d.ts.map +1 -0
  40. package/dist/files.js +224 -0
  41. package/dist/files.js.map +1 -0
  42. package/dist/guard-registration.d.ts +95 -0
  43. package/dist/guard-registration.d.ts.map +1 -0
  44. package/dist/guard-registration.js +282 -0
  45. package/dist/guard-registration.js.map +1 -0
  46. package/dist/host-home.d.ts +33 -0
  47. package/dist/host-home.d.ts.map +1 -0
  48. package/dist/host-home.js +116 -0
  49. package/dist/host-home.js.map +1 -0
  50. package/dist/host-modes.d.ts +13 -0
  51. package/dist/host-modes.d.ts.map +1 -0
  52. package/dist/host-modes.js +36 -0
  53. package/dist/host-modes.js.map +1 -0
  54. package/dist/host-observe.d.ts +24 -0
  55. package/dist/host-observe.d.ts.map +1 -0
  56. package/dist/host-observe.js +233 -0
  57. package/dist/host-observe.js.map +1 -0
  58. package/dist/host.d.ts +100 -0
  59. package/dist/host.d.ts.map +1 -0
  60. package/dist/host.js +505 -0
  61. package/dist/host.js.map +1 -0
  62. package/dist/hosts.d.ts +66 -0
  63. package/dist/hosts.d.ts.map +1 -0
  64. package/dist/hosts.js +39 -0
  65. package/dist/hosts.js.map +1 -0
  66. package/dist/ia-home.d.ts +15 -0
  67. package/dist/ia-home.d.ts.map +1 -0
  68. package/dist/ia-home.js +101 -0
  69. package/dist/ia-home.js.map +1 -0
  70. package/dist/install.d.ts +56 -0
  71. package/dist/install.d.ts.map +1 -0
  72. package/dist/install.js +402 -0
  73. package/dist/install.js.map +1 -0
  74. package/dist/installation-core.d.ts +41 -0
  75. package/dist/installation-core.d.ts.map +1 -0
  76. package/dist/installation-core.js +163 -0
  77. package/dist/installation-core.js.map +1 -0
  78. package/dist/inventory.d.ts +3 -0
  79. package/dist/inventory.d.ts.map +1 -0
  80. package/dist/inventory.js +49 -0
  81. package/dist/inventory.js.map +1 -0
  82. package/dist/json-edit.d.ts +19 -0
  83. package/dist/json-edit.d.ts.map +1 -0
  84. package/dist/json-edit.js +81 -0
  85. package/dist/json-edit.js.map +1 -0
  86. package/dist/lifecycle-registration.d.ts +46 -0
  87. package/dist/lifecycle-registration.d.ts.map +1 -0
  88. package/dist/lifecycle-registration.js +332 -0
  89. package/dist/lifecycle-registration.js.map +1 -0
  90. package/dist/minting.d.ts +46 -0
  91. package/dist/minting.d.ts.map +1 -0
  92. package/dist/minting.js +192 -0
  93. package/dist/minting.js.map +1 -0
  94. package/dist/native-command.d.ts +6 -0
  95. package/dist/native-command.d.ts.map +1 -0
  96. package/dist/native-command.js +273 -0
  97. package/dist/native-command.js.map +1 -0
  98. package/dist/pack.d.ts +4 -0
  99. package/dist/pack.d.ts.map +1 -0
  100. package/dist/pack.js +30 -0
  101. package/dist/pack.js.map +1 -0
  102. package/dist/plugin-home.d.ts +45 -0
  103. package/dist/plugin-home.d.ts.map +1 -0
  104. package/dist/plugin-home.js +371 -0
  105. package/dist/plugin-home.js.map +1 -0
  106. package/dist/projection.d.ts +45 -0
  107. package/dist/projection.d.ts.map +1 -0
  108. package/dist/projection.js +218 -0
  109. package/dist/projection.js.map +1 -0
  110. package/dist/publication.d.ts +20 -0
  111. package/dist/publication.d.ts.map +1 -0
  112. package/dist/publication.js +284 -0
  113. package/dist/publication.js.map +1 -0
  114. package/dist/registry-admission.d.ts +5 -0
  115. package/dist/registry-admission.d.ts.map +1 -0
  116. package/dist/registry-admission.js +17 -0
  117. package/dist/registry-admission.js.map +1 -0
  118. package/dist/registry-build.d.ts +35 -0
  119. package/dist/registry-build.d.ts.map +1 -0
  120. package/dist/registry-build.js +156 -0
  121. package/dist/registry-build.js.map +1 -0
  122. package/dist/registry-config.d.ts +32 -0
  123. package/dist/registry-config.d.ts.map +1 -0
  124. package/dist/registry-config.js +191 -0
  125. package/dist/registry-config.js.map +1 -0
  126. package/dist/registry-layout.d.ts +41 -0
  127. package/dist/registry-layout.d.ts.map +1 -0
  128. package/dist/registry-layout.js +142 -0
  129. package/dist/registry-layout.js.map +1 -0
  130. package/dist/registry-resolve.d.ts +56 -0
  131. package/dist/registry-resolve.d.ts.map +1 -0
  132. package/dist/registry-resolve.js +406 -0
  133. package/dist/registry-resolve.js.map +1 -0
  134. package/dist/registry-source.d.ts +37 -0
  135. package/dist/registry-source.d.ts.map +1 -0
  136. package/dist/registry-source.js +101 -0
  137. package/dist/registry-source.js.map +1 -0
  138. package/dist/registry.d.ts +10 -0
  139. package/dist/registry.d.ts.map +1 -0
  140. package/dist/registry.js +6 -0
  141. package/dist/registry.js.map +1 -0
  142. package/dist/resolve.d.ts +31 -0
  143. package/dist/resolve.d.ts.map +1 -0
  144. package/dist/resolve.js +115 -0
  145. package/dist/resolve.js.map +1 -0
  146. package/dist/services.d.ts +179 -0
  147. package/dist/services.d.ts.map +1 -0
  148. package/dist/services.js +290 -0
  149. package/dist/services.js.map +1 -0
  150. package/dist/snapshot.d.ts +19 -0
  151. package/dist/snapshot.d.ts.map +1 -0
  152. package/dist/snapshot.js +309 -0
  153. package/dist/snapshot.js.map +1 -0
  154. package/dist/transfer.d.ts +22 -0
  155. package/dist/transfer.d.ts.map +1 -0
  156. package/dist/transfer.js +98 -0
  157. package/dist/transfer.js.map +1 -0
  158. package/dist/updates.d.ts +57 -0
  159. package/dist/updates.d.ts.map +1 -0
  160. package/dist/updates.js +174 -0
  161. package/dist/updates.js.map +1 -0
  162. package/dist/ustar.d.ts +28 -0
  163. package/dist/ustar.d.ts.map +1 -0
  164. package/dist/ustar.js +145 -0
  165. package/dist/ustar.js.map +1 -0
  166. package/package.json +305 -3
@@ -0,0 +1,371 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ import { caseFold } from '@inventarch/db';
5
+ import { fail, portable } from './files.js';
6
+ import { assertIaHomeUsable, ensureIaHome } from './ia-home.js';
7
+ /** Host plugin distribution spec §6.3: the materialized Claude marketplace lives here, in every channel. */
8
+ export const MARKETPLACE_DIR = 'claude/marketplace';
9
+ const PLUGIN_JSON = 'plugins/ia/.claude-plugin/plugin.json', META_JSON = 'plugins/ia/ia-plugin.json';
10
+ const LEFTOVER_PREFIXES = ['.stage-', '.previous-', '.remove-'];
11
+ const describe = (error) => (error instanceof Error ? error.message : String(error));
12
+ /** Win32 renames a directory holding an open file with EPERM/EBUSY/EACCES depending on what holds it; elsewhere only EBUSY means "busy" — EPERM/EACCES there are a real permission problem, not a lock to wait out. */
13
+ const BUSY_CODES = new Set(process.platform === 'win32' ? ['EPERM', 'EBUSY', 'EACCES'] : ['EBUSY']);
14
+ const PERMISSION_CODES = new Set(process.platform === 'win32' ? [] : ['EPERM', 'EACCES']);
15
+ /** Synchronous backoff; `Atomics.wait` blocks this thread only, which is what a CLI process wants here. */
16
+ function waitBusy(ms) {
17
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
18
+ }
19
+ /**
20
+ * Retries a rename across a lock briefly held by an editor, indexer or another `ia` process; ~1.5s total, backing
21
+ * off 50ms to 400ms, before refusing as INSTALL-BUSY naming `contextDir`. Off win32, EPERM/EACCES are not treated as
22
+ * a transient lock: they fail immediately as INPUT-INVALID. Any other error is rethrown as-is.
23
+ */
24
+ function renameRetrying(from, to, contextDir) {
25
+ const deadline = Date.now() + 1500;
26
+ let delay = 50;
27
+ for (;;) {
28
+ try {
29
+ renameSync(from, to);
30
+ return;
31
+ }
32
+ catch (error) {
33
+ const code = error.code;
34
+ if (code && BUSY_CODES.has(code)) {
35
+ if (Date.now() >= deadline)
36
+ fail('INSTALL-BUSY', `A process holds files open under ${contextDir}; close Claude Code sessions, editors or terminals using it, then rerun ia host claude --user --apply`);
37
+ waitBusy(delay);
38
+ delay = Math.min(delay * 2, 400);
39
+ continue;
40
+ }
41
+ if (code && PERMISSION_CODES.has(code))
42
+ fail('INPUT-INVALID', `${contextDir} cannot be renamed (${code}); check its permissions`);
43
+ throw error;
44
+ }
45
+ }
46
+ }
47
+ const LOCK_NAME = '.lock', LOCK_STALE_MS = 10 * 60 * 1000, LOCK_EMPTY_GRACE_MS = 10 * 1000, LOCK_TAKEOVER_ATTEMPTS = 5;
48
+ /** `process.kill(pid, 0)` throwing ESRCH is the only "not alive" case; any other outcome, including an unreadable errno, is treated as alive so a live run is never stolen from under itself. */
49
+ function isPidAlive(pid) {
50
+ try {
51
+ process.kill(pid, 0);
52
+ }
53
+ catch (error) {
54
+ return error.code !== 'ESRCH';
55
+ }
56
+ return true;
57
+ }
58
+ /**
59
+ * Held for the lifetime of a materialize's recovery-through-swap, or of a whole `removeMarketplace`, so two
60
+ * concurrent `ia host --user` runs cannot interleave their renames. A lock is taken over — never trusted blindly —
61
+ * only once its pid has parsed and died, or it is older than `LOCK_STALE_MS`, or (an empty/unparseable pid, the
62
+ * short window between another run's `openSync` and its pid write) it is older than `LOCK_EMPTY_GRACE_MS`;
63
+ * otherwise this refuses INSTALL-BUSY. Bounded at `LOCK_TAKEOVER_ATTEMPTS`, so a lock file that keeps coming back
64
+ * (removal failing, or another process winning the race) fails loudly instead of spinning forever. The sweep
65
+ * functions below must never touch this file.
66
+ */
67
+ function acquireLock(parent) {
68
+ mkdirSync(parent, { recursive: true });
69
+ const path = join(parent, LOCK_NAME);
70
+ const busy = () => fail('INSTALL-BUSY', `Another ia host --user run holds ${path}; wait for it or delete the file if no run is active`);
71
+ for (let attempts = 0;; attempts++) {
72
+ try {
73
+ const fd = openSync(path, 'wx');
74
+ try {
75
+ writeFileSync(fd, String(process.pid));
76
+ }
77
+ finally {
78
+ closeSync(fd);
79
+ }
80
+ return path;
81
+ }
82
+ catch (error) {
83
+ if (error.code !== 'EEXIST')
84
+ throw error;
85
+ if (attempts >= LOCK_TAKEOVER_ATTEMPTS)
86
+ busy();
87
+ let ageMs;
88
+ try {
89
+ ageMs = Date.now() - statSync(path).mtimeMs;
90
+ }
91
+ catch {
92
+ continue;
93
+ } // vanished mid-check: just retry the open
94
+ let pid = Number.NaN;
95
+ try {
96
+ pid = Number.parseInt(readFileSync(path, 'utf8'), 10);
97
+ }
98
+ catch {
99
+ /* vanished between stat and read: pid stays NaN, judged on age alone below */
100
+ }
101
+ const parsed = Number.isInteger(pid);
102
+ const stale = (parsed && !isPidAlive(pid)) || ageMs > LOCK_STALE_MS || (!parsed && ageMs > LOCK_EMPTY_GRACE_MS);
103
+ if (!stale)
104
+ busy();
105
+ try {
106
+ rmSync(path, { force: true });
107
+ }
108
+ catch {
109
+ /* removal itself failing too; the attempt bound above stops the spin */
110
+ }
111
+ }
112
+ }
113
+ }
114
+ function releaseLock(path) {
115
+ try {
116
+ rmSync(path, { force: true });
117
+ }
118
+ catch {
119
+ /* best-effort */
120
+ }
121
+ }
122
+ /**
123
+ * Validates every path once (portability, duplicates, prefix collisions) before anything is created; returns the portable
124
+ * form in the same order. Folded on every platform: the set is installed wherever the plugin is, macOS and Windows volumes
125
+ * both open `a` and `A` as one file (#315), and APFS also opens `ß` and `ss` as one (`caseFold`, #323).
126
+ */
127
+ function assertPortableFileSet(files) {
128
+ const entries = files.map((file) => {
129
+ const path = portable(file.path);
130
+ return { path, key: caseFold(path) };
131
+ });
132
+ const seen = new Set();
133
+ for (const entry of entries) {
134
+ if (seen.has(entry.key))
135
+ fail('PATH-UNSAFE', `Duplicate marketplace path: ${entry.path}`);
136
+ seen.add(entry.key);
137
+ }
138
+ for (const a of entries)
139
+ for (const b of entries)
140
+ if (a !== b && b.key.startsWith(a.key + '/'))
141
+ fail('PATH-UNSAFE', `${b.path} is nested under file path ${a.path}`);
142
+ return entries.map((entry) => entry.path);
143
+ }
144
+ /** A staged `plugin.json`/`ia-plugin.json`, when present, must round-trip through disk as JSON; anything else is written verbatim. */
145
+ function assertStagedMetadataParses(stage, paths) {
146
+ for (const path of paths) {
147
+ if (path !== PLUGIN_JSON && path !== META_JSON)
148
+ continue;
149
+ try {
150
+ JSON.parse(readFileSync(join(stage, path), 'utf8'));
151
+ }
152
+ catch (error) {
153
+ fail('INPUT-INVALID', `${path} was staged but does not parse as JSON (${describe(error)})`);
154
+ }
155
+ }
156
+ }
157
+ /**
158
+ * Idempotent startup repair for a call that crashed or was killed mid-swap: if `target` is missing and exactly one
159
+ * `.previous-*` sits beside it, that is the marketplace that survived the last attempt, so it is renamed back. Then
160
+ * every `.stage-*` and `.remove-*` is swept (always disposable), and a `.previous-*` is swept only once `target`
161
+ * exists again (never delete the one surviving copy while the marketplace itself is still missing). Best-effort:
162
+ * a failure here is left for the next call or for `rename it back … or rerun ia host claude --user --apply`.
163
+ */
164
+ function recoverMarketplaceState(parent, target) {
165
+ if (!existsSync(parent))
166
+ return;
167
+ let entries;
168
+ try {
169
+ entries = readdirSync(parent);
170
+ }
171
+ catch {
172
+ return;
173
+ }
174
+ if (!existsSync(target)) {
175
+ const previousDirs = entries.filter((name) => name.startsWith('.previous-'));
176
+ if (previousDirs.length === 1) {
177
+ try {
178
+ renameSync(join(parent, previousDirs[0]), target);
179
+ }
180
+ catch {
181
+ /* left for the next call, or for manual recovery */
182
+ }
183
+ }
184
+ }
185
+ let after;
186
+ try {
187
+ after = readdirSync(parent);
188
+ }
189
+ catch {
190
+ return;
191
+ }
192
+ for (const name of after) {
193
+ const sweepable = name.startsWith('.stage-') ||
194
+ name.startsWith('.remove-') ||
195
+ (name.startsWith('.previous-') && existsSync(target));
196
+ if (sweepable) {
197
+ try {
198
+ rmSync(join(parent, name), { recursive: true, force: true });
199
+ }
200
+ catch {
201
+ /* best-effort */
202
+ }
203
+ }
204
+ }
205
+ }
206
+ /**
207
+ * Stage beside the target and swap it in whole, holding `claude/.lock` from just before recovery through the end of
208
+ * the swap. `previous` is deleted only after the swap has succeeded, or after a restore of it has succeeded; if
209
+ * both the swap and the restore fail, `previous` is kept on disk (never deleted) and the call refuses with
210
+ * RECOVERY-REQUIRED naming it, so no attempt here can ever lose the marketplace that was already there. The stage
211
+ * is always disposable and its cleanup is best-effort either way.
212
+ */
213
+ export function materializeMarketplace(home, files) {
214
+ assertIaHomeUsable(home);
215
+ const paths = assertPortableFileSet(files);
216
+ ensureIaHome(home);
217
+ const parent = join(home, 'claude'), target = join(home, MARKETPLACE_DIR);
218
+ const lock = acquireLock(parent);
219
+ try {
220
+ recoverMarketplaceState(parent, target);
221
+ const stage = join(parent, `.stage-${randomUUID()}`), previous = join(parent, `.previous-${randomUUID()}`);
222
+ mkdirSync(stage, { recursive: true });
223
+ let removePrevious = false;
224
+ try {
225
+ files.forEach((file, index) => {
226
+ const path = join(stage, paths[index]);
227
+ mkdirSync(dirname(path), { recursive: true });
228
+ writeFileSync(path, file.text, { flag: 'wx' });
229
+ });
230
+ assertStagedMetadataParses(stage, paths);
231
+ const demoted = existsSync(target);
232
+ if (demoted)
233
+ renameRetrying(target, previous, target);
234
+ try {
235
+ renameRetrying(stage, target, target);
236
+ removePrevious = demoted;
237
+ }
238
+ catch (swapError) {
239
+ if (!demoted)
240
+ throw swapError;
241
+ try {
242
+ renameRetrying(previous, target, target);
243
+ }
244
+ catch (restoreError) {
245
+ fail('RECOVERY-REQUIRED', `Marketplace swap failed (${describe(swapError)}) and restoring the previous copy also failed (${describe(restoreError)}); rename ${previous} back to ${target}, or rerun ia host claude --user --apply`);
246
+ }
247
+ throw swapError;
248
+ }
249
+ }
250
+ finally {
251
+ try {
252
+ if (existsSync(stage))
253
+ rmSync(stage, { recursive: true, force: true });
254
+ }
255
+ catch {
256
+ /* best-effort; never masks the real result */
257
+ }
258
+ try {
259
+ if (removePrevious && existsSync(previous))
260
+ rmSync(previous, { recursive: true, force: true });
261
+ }
262
+ catch {
263
+ /* best-effort; a stray .previous-* is swept by the next materialize */
264
+ }
265
+ }
266
+ }
267
+ finally {
268
+ releaseLock(lock);
269
+ }
270
+ return { directory: target };
271
+ }
272
+ /** What `doctor` reports: `absent` (no directory), `invalid` (present but unreadable, unparseable or the wrong shape — `reason` is the read error's code, `'parse'` or `'shape'`), or `ok`. */
273
+ export function inspectMaterializedPlugin(home) {
274
+ const target = join(home, MARKETPLACE_DIR);
275
+ if (!existsSync(target))
276
+ return { state: 'absent' };
277
+ const read = (path) => {
278
+ let text;
279
+ try {
280
+ text = readFileSync(join(target, path), 'utf8');
281
+ }
282
+ catch (error) {
283
+ return { ok: false, reason: error.code ?? describe(error) };
284
+ }
285
+ try {
286
+ return { ok: true, value: JSON.parse(text) };
287
+ }
288
+ catch {
289
+ return { ok: false, reason: 'parse' };
290
+ }
291
+ };
292
+ const plugin = read(PLUGIN_JSON);
293
+ if (!plugin.ok)
294
+ return { state: 'invalid', reason: plugin.reason };
295
+ const meta = read(META_JSON);
296
+ if (!meta.ok)
297
+ return { state: 'invalid', reason: meta.reason };
298
+ const p = plugin.value, m = meta.value;
299
+ if (p === null ||
300
+ typeof p !== 'object' ||
301
+ typeof p.version !== 'string' ||
302
+ m === null ||
303
+ typeof m !== 'object' ||
304
+ typeof m['cli'] !== 'string' ||
305
+ typeof m['channel'] !== 'string' ||
306
+ typeof m['entry'] !== 'string')
307
+ return { state: 'invalid', reason: 'shape' };
308
+ return {
309
+ state: 'ok',
310
+ version: p.version,
311
+ cli: m['cli'],
312
+ channel: m['channel'],
313
+ entry: m['entry'],
314
+ };
315
+ }
316
+ /** What `doctor` and `ia host --user` compare: the plugin version and the CLI it was rendered by, or null. Delegates to `inspectMaterializedPlugin`, collapsing `absent`/`invalid` to null. */
317
+ export function readMaterializedPlugin(home) {
318
+ const inspected = inspectMaterializedPlugin(home);
319
+ return inspected.state === 'ok'
320
+ ? { version: inspected.version, cli: inspected.cli, channel: inspected.channel, entry: inspected.entry }
321
+ : null;
322
+ }
323
+ /**
324
+ * Renames `target` out of the way first (retried the same as a materialize swap), then, holding the same lock,
325
+ * best-effort sweeps every `.stage-*`, `.previous-*` and `.remove-*` left beside it — all garbage once the caller
326
+ * asked to remove the marketplace, including a `.previous-*` a prior RECOVERY-REQUIRED left behind. Returns true if
327
+ * `target` or any leftover was actually removed. Never touches `.lock`.
328
+ */
329
+ export function removeMarketplace(home) {
330
+ const parent = join(home, 'claude'), target = join(home, MARKETPLACE_DIR);
331
+ if (!existsSync(parent))
332
+ return false;
333
+ const lock = acquireLock(parent);
334
+ try {
335
+ let removed = false;
336
+ if (existsSync(target)) {
337
+ const removing = join(parent, `.remove-${randomUUID()}`);
338
+ renameRetrying(target, removing, target);
339
+ removed = true;
340
+ try {
341
+ rmSync(removing, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
342
+ }
343
+ catch {
344
+ /* best-effort; swept below or by the next materialize */
345
+ }
346
+ }
347
+ let entries;
348
+ try {
349
+ entries = readdirSync(parent);
350
+ }
351
+ catch {
352
+ entries = [];
353
+ }
354
+ for (const name of entries) {
355
+ if (name === LOCK_NAME || !LEFTOVER_PREFIXES.some((prefix) => name.startsWith(prefix)))
356
+ continue;
357
+ try {
358
+ rmSync(join(parent, name), { recursive: true, force: true });
359
+ removed = true;
360
+ }
361
+ catch {
362
+ /* best-effort */
363
+ }
364
+ }
365
+ return removed;
366
+ }
367
+ finally {
368
+ releaseLock(lock);
369
+ }
370
+ }
371
+ //# sourceMappingURL=plugin-home.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-home.js","sourceRoot":"","sources":["../src/plugin-home.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,UAAU,EACV,MAAM,EACN,QAAQ,EACR,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhE,4GAA4G;AAC5G,MAAM,CAAC,MAAM,eAAe,GAAG,oBAAoB,CAAC;AAKpD,MAAM,WAAW,GAAG,uCAAuC,EACzD,SAAS,GAAG,2BAA2B,CAAC;AAC1C,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU,CAAU,CAAC;AACzE,MAAM,QAAQ,GAAG,CAAC,KAAc,EA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B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;gBAAE,SAAS;YACjG,IAAI,CAAC;gBACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC7D,OAAO,GAAG,IAAI,CAAC;YACjB,CAAC;YAAC,MAAM,CAAC;gBACP,iBAAiB;YACnB,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;YAAS,CAAC;QACT,WAAW,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;AACH,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { WorkspaceHost as Host } from './hosts.js';
2
+ export interface Artifact {
3
+ readonly path: string;
4
+ readonly text: string;
5
+ }
6
+ export type ProjectionAction = {
7
+ readonly path: string;
8
+ readonly action: 'create' | 'update' | 'unchanged' | 'remove' | 'unowned';
9
+ };
10
+ export type ProjectionDrift = {
11
+ readonly path: string;
12
+ readonly drift: 'changed' | 'missing' | 'outdated' | 'unmanaged' | 'unowned';
13
+ };
14
+ export interface ProjectionPlan {
15
+ readonly format: 'ia.host-projection-plan.v1';
16
+ readonly root: string;
17
+ readonly host: Host;
18
+ readonly marker: string;
19
+ readonly artifacts: readonly Artifact[];
20
+ readonly actions: readonly ProjectionAction[];
21
+ readonly before: string | null;
22
+ readonly digest: string;
23
+ }
24
+ /** Spec §6.3: exact paths per host; subagent files are the one pattern. */
25
+ export declare const PROJECTION_PATHS: Readonly<Record<Host, readonly string[]>>;
26
+ export declare function planProjection(input: {
27
+ readonly root: string;
28
+ readonly host: Host;
29
+ readonly artifacts: readonly Artifact[];
30
+ readonly marker: string;
31
+ }): ProjectionPlan;
32
+ /** State first (an expanded accepted-hash set for every path being written), then bytes, then the collapsed final state: an interrupted run never looks hand-edited on the next plan. */
33
+ export declare function applyProjection(input: ProjectionPlan, checkpoint?: (name: string) => void): {
34
+ status: 'projected';
35
+ written: number;
36
+ removed: number;
37
+ };
38
+ /** Spec §7: changed (hand edit), missing, outdated (would render differently), unmanaged (no marker), unowned (marked but not ours). Never writes. A file that cannot be read is refused at that file, as planning refuses it. */
39
+ export declare function observeProjection(input: {
40
+ readonly root: string;
41
+ readonly host: Host;
42
+ readonly artifacts: readonly Artifact[] | null;
43
+ readonly marker: string;
44
+ }): ProjectionDrift[];
45
+ //# sourceMappingURL=projection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../src/projection.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,IAAI,IAAI,EAAE,MAAM,YAAY,CAAC;AAIxD,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AACD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;CAC3E,CAAC;AACF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC;CAC9E,CAAC;AACF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,4BAA4B,CAAC;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AACD,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC,CAGrE,CAAC;AAmFH,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GAAG,cAAc,CAyDjB;AACD,yLAAyL;AACzL,wBAAgB,eAAe,CAC7B,KAAK,EAAE,cAAc,EACrB,UAAU,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAe,GAC5C;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAkD3D;AACD,kOAAkO;AAClO,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,GAAG,IAAI,CAAC;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GAAG,eAAe,EAAE,CA8BpB"}
@@ -0,0 +1,218 @@
1
+ import { readdirSync } from 'node:fs';
2
+ import { decodeDistributionJson } from '@inventarch/db/distribution';
3
+ import { bytes, contained, digest, fail, json, locate, object, portable, replace, sha256, utf8, workspace, } from './files.js';
4
+ import { acquireHostRegistrationLock } from './host.js';
5
+ /** Spec §6.3: exact paths per host; subagent files are the one pattern. */
6
+ export const PROJECTION_PATHS = Object.freeze({
7
+ claude: ['.claude/rules/ia-workspace.md', '.claude/skills/ia-authoring/SKILL.md'],
8
+ codex: ['AGENTS.md', '.agents/skills/ia-authoring/SKILL.md'],
9
+ });
10
+ const asHost = (value) => {
11
+ if (value !== 'claude' && value !== 'codex')
12
+ fail('INPUT-INVALID', 'Expected Claude or Codex');
13
+ return value;
14
+ };
15
+ const allowed = (host, path) => PROJECTION_PATHS[host].includes(path) || (host === 'claude' && /^\.claude\/agents\/[a-z][a-z0-9-]*\.md$/.test(path));
16
+ const statePath = (host) => `.ia/distributions/hosts/${host}-projection.json`;
17
+ const read = (root, path) => {
18
+ const value = bytes(root, path, 1024 * 1024);
19
+ return value === null ? null : utf8(value);
20
+ };
21
+ const hasMarker = (text, marker) => text.split(/\r?\n/).includes(marker);
22
+ const acceptedHashes = (value) => value === undefined ? [] : typeof value === 'string' ? [value] : [...value];
23
+ const accepts = (value, hash) => acceptedHashes(value).includes(hash);
24
+ /** CRLF is the one hand-edit shape worth naming: it is what an editor does on its own, not a content change. */
25
+ function handEditMessage(path, existing, accepted) {
26
+ const suffix = accepts(accepted, sha256(existing.replace(/\r\n/g, '\n'))) ? ' (line endings differ)' : '';
27
+ return `Managed file was edited by hand${suffix}: ${path}`;
28
+ }
29
+ /** Every recorded path must still be portable and allowlisted, and every hash a bare SHA-256 (or a small set of them mid-apply). */
30
+ function owned(root, host) {
31
+ const text = read(root, statePath(host));
32
+ if (text === null)
33
+ return {};
34
+ const row = object(decodeDistributionJson(text), ['format', 'host', 'files']), files = row['files'];
35
+ if (row['format'] !== 'ia.host-projection-state.v1' ||
36
+ row['host'] !== host ||
37
+ files === null ||
38
+ typeof files !== 'object' ||
39
+ Array.isArray(files))
40
+ fail('INPUT-INVALID', 'Invalid projection ownership state');
41
+ const result = {};
42
+ for (const [path, value] of Object.entries(files)) {
43
+ let safe;
44
+ try {
45
+ safe = portable(path);
46
+ }
47
+ catch {
48
+ safe = null;
49
+ }
50
+ const hashes = Array.isArray(value) ? value : [value];
51
+ if (safe !== path ||
52
+ !allowed(host, path) ||
53
+ !hashes.length ||
54
+ hashes.length > 2 ||
55
+ hashes.some((h) => typeof h !== 'string' || !/^[a-f0-9]{64}$/.test(h)) ||
56
+ new Set(hashes).size !== hashes.length)
57
+ fail('INPUT-INVALID', 'Invalid projection ownership state');
58
+ result[path] = Array.isArray(value) ? value : value;
59
+ }
60
+ return result;
61
+ }
62
+ /** Spec §6.3: a marked `.claude/agents/*.md` file neither rendered nor owned is reported, never touched. Claude only. */
63
+ function orphanStewardFiles(root, host, exclude, marker) {
64
+ if (host !== 'claude')
65
+ return [];
66
+ let entries;
67
+ try {
68
+ entries = readdirSync(contained(root, '.claude/agents'), { withFileTypes: true });
69
+ }
70
+ catch (error) {
71
+ if (error.code === 'ENOENT')
72
+ return [];
73
+ throw error;
74
+ }
75
+ const found = [];
76
+ for (const entry of entries) {
77
+ if (!entry.isFile() || !/^[a-z][a-z0-9-]*\.md$/.test(entry.name))
78
+ continue;
79
+ const path = `.claude/agents/${entry.name}`;
80
+ if (exclude.has(path))
81
+ continue;
82
+ // A user's own file at this path may be too large, non-UTF-8 or hard-linked; the scan skips it rather than failing the whole plan/observe.
83
+ let existing;
84
+ try {
85
+ existing = read(root, path);
86
+ }
87
+ catch {
88
+ continue;
89
+ }
90
+ if (existing !== null && hasMarker(existing, marker))
91
+ found.push(path);
92
+ }
93
+ return found;
94
+ }
95
+ export function planProjection(input) {
96
+ const root = workspace(input.root), host = asHost(input.host), files = locate(statePath(host), () => owned(root, host)), actions = [], seen = new Set();
97
+ for (const artifact of input.artifacts)
98
+ locate(artifact.path, () => {
99
+ portable(artifact.path);
100
+ if (Buffer.byteLength(artifact.text) > 1024 * 1024)
101
+ fail('LIMIT-EXCEEDED', `Projection artifact exceeds 1048576 bytes: ${artifact.path}`);
102
+ if (seen.has(artifact.path))
103
+ fail('INPUT-INVALID', 'Duplicate projection path');
104
+ if (!allowed(host, artifact.path))
105
+ fail('PATH-UNSAFE', `Projection path is outside the ${host} allowlist: ${artifact.path}`);
106
+ if (!hasMarker(artifact.text, input.marker))
107
+ fail('INPUT-INVALID', `Projection artifact is missing the marker line: ${artifact.path}`);
108
+ seen.add(artifact.path);
109
+ const existing = read(root, artifact.path);
110
+ if (existing === null) {
111
+ actions.push({ path: artifact.path, action: 'create' });
112
+ return;
113
+ }
114
+ if (existing === artifact.text) {
115
+ actions.push({ path: artifact.path, action: 'unchanged' });
116
+ return;
117
+ }
118
+ if (!hasMarker(existing, input.marker))
119
+ fail('LOCAL-MODIFICATION', `Refusing unmanaged file at a managed path: ${artifact.path}`);
120
+ if (files[artifact.path] === undefined)
121
+ fail('LOCAL-MODIFICATION', `Marked file is not owned by this workspace's projection state: ${artifact.path}; remove it, then rerun`);
122
+ if (!accepts(files[artifact.path], sha256(existing)))
123
+ fail('LOCAL-MODIFICATION', handEditMessage(artifact.path, existing, files[artifact.path]));
124
+ actions.push({ path: artifact.path, action: 'update' });
125
+ });
126
+ for (const [path, value] of Object.entries(files))
127
+ if (!seen.has(path))
128
+ locate(path, () => {
129
+ const existing = read(root, path);
130
+ if (existing !== null && !accepts(value, sha256(existing)))
131
+ fail('LOCAL-MODIFICATION', handEditMessage(path, existing, value));
132
+ actions.push({ path, action: 'remove' });
133
+ });
134
+ for (const path of orphanStewardFiles(root, host, new Set([...seen, ...Object.keys(files)]), input.marker))
135
+ actions.push({ path, action: 'unowned' });
136
+ const body = {
137
+ format: 'ia.host-projection-plan.v1',
138
+ root,
139
+ host,
140
+ marker: input.marker,
141
+ artifacts: input.artifacts,
142
+ actions: actions.sort((a, b) => (a.path < b.path ? -1 : 1)),
143
+ before: read(root, statePath(host)),
144
+ };
145
+ return { ...body, digest: digest(body) };
146
+ }
147
+ /** State first (an expanded accepted-hash set for every path being written), then bytes, then the collapsed final state: an interrupted run never looks hand-edited on the next plan. */
148
+ export function applyProjection(input, checkpoint = () => { }) {
149
+ const root = workspace(input.root), unlock = acquireHostRegistrationLock(root);
150
+ try {
151
+ const plan = planProjection(input);
152
+ if (json(plan) !== json(input))
153
+ fail('PLAN-STALE', 'Projection plan no longer matches its current inputs');
154
+ const host = plan.host, prior = owned(root, host), mutating = plan.actions.filter((a) => a.action === 'create' || a.action === 'update' || a.action === 'remove');
155
+ if (mutating.length) {
156
+ const pending = { ...prior };
157
+ for (const action of mutating)
158
+ if (action.action !== 'remove') {
159
+ const newHash = sha256(plan.artifacts.find((a) => a.path === action.path).text);
160
+ const onDisk = read(root, action.path), currentHash = onDisk === null ? null : sha256(onDisk);
161
+ // Bounded to at most 2: whatever is really on disk right now (if it was already accepted), plus the new target. Stale accepted hashes from earlier interrupted rounds are dropped.
162
+ const keep = currentHash !== null && accepts(prior[action.path], currentHash) ? [currentHash] : [];
163
+ const merged = [...new Set([...keep, newHash])];
164
+ pending[action.path] = merged.length === 1 ? merged[0] : merged;
165
+ }
166
+ replace(root, statePath(host), Buffer.from(json({ format: 'ia.host-projection-state.v1', host, files: pending })));
167
+ checkpoint('pending');
168
+ for (const action of mutating) {
169
+ if (action.action === 'remove')
170
+ replace(root, action.path, null);
171
+ else
172
+ replace(root, action.path, Buffer.from(plan.artifacts.find((a) => a.path === action.path).text));
173
+ checkpoint(action.path);
174
+ }
175
+ }
176
+ const files = Object.fromEntries(plan.artifacts.map((a) => [a.path, sha256(a.text)]).sort(([a], [b]) => (a < b ? -1 : 1)));
177
+ replace(root, statePath(host), plan.artifacts.length ? Buffer.from(json({ format: 'ia.host-projection-state.v1', host, files })) : null);
178
+ checkpoint('complete');
179
+ return {
180
+ status: 'projected',
181
+ written: mutating.filter((a) => a.action !== 'remove').length,
182
+ removed: mutating.filter((a) => a.action === 'remove').length,
183
+ };
184
+ }
185
+ finally {
186
+ unlock();
187
+ }
188
+ }
189
+ /** Spec §7: changed (hand edit), missing, outdated (would render differently), unmanaged (no marker), unowned (marked but not ours). Never writes. A file that cannot be read is refused at that file, as planning refuses it. */
190
+ export function observeProjection(input) {
191
+ const root = workspace(input.root), host = asHost(input.host), files = locate(statePath(host), () => owned(root, host)), drift = [];
192
+ for (const [path, value] of Object.entries(files))
193
+ locate(path, () => {
194
+ const existing = read(root, path);
195
+ if (existing === null)
196
+ drift.push({ path, drift: 'missing' });
197
+ else if (!accepts(value, sha256(existing)))
198
+ drift.push({ path, drift: 'changed' });
199
+ else if (input.artifacts !== null && input.artifacts.find((a) => a.path === path)?.text !== existing)
200
+ drift.push({ path, drift: 'outdated' });
201
+ });
202
+ if (input.artifacts !== null && Object.keys(files).length)
203
+ for (const artifact of input.artifacts)
204
+ if (files[artifact.path] === undefined)
205
+ locate(artifact.path, () => {
206
+ const existing = read(root, artifact.path);
207
+ if (existing === null)
208
+ drift.push({ path: artifact.path, drift: 'missing' });
209
+ else if (!hasMarker(existing, input.marker))
210
+ drift.push({ path: artifact.path, drift: 'unmanaged' });
211
+ else
212
+ drift.push({ path: artifact.path, drift: 'unowned' });
213
+ });
214
+ for (const path of orphanStewardFiles(root, host, new Set([...Object.keys(files), ...(input.artifacts ?? []).map((a) => a.path)]), input.marker))
215
+ drift.push({ path, drift: 'unowned' });
216
+ return drift.sort((a, b) => (a.path < b.path ? -1 : 1));
217
+ }
218
+ //# sourceMappingURL=projection.js.map