@inventarch/distribution 0.0.0-stage → 1.1.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 (176) hide show
  1. package/LANGUAGE.md +56 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +4 -0
  4. package/README.md +2 -2
  5. package/SPEC.md +5 -0
  6. package/assets/host-launcher.mjs +167 -0
  7. package/dist/acquire.d.ts +13 -0
  8. package/dist/acquire.d.ts.map +1 -0
  9. package/dist/acquire.js +46 -0
  10. package/dist/acquire.js.map +1 -0
  11. package/dist/archive.d.ts +20 -0
  12. package/dist/archive.d.ts.map +1 -0
  13. package/dist/archive.js +165 -0
  14. package/dist/archive.js.map +1 -0
  15. package/dist/authoring-assets.d.ts +11 -0
  16. package/dist/authoring-assets.d.ts.map +1 -0
  17. package/dist/authoring-assets.js +251 -0
  18. package/dist/authoring-assets.js.map +1 -0
  19. package/dist/bounded-fetch.d.ts +17 -0
  20. package/dist/bounded-fetch.d.ts.map +1 -0
  21. package/dist/bounded-fetch.js +67 -0
  22. package/dist/bounded-fetch.js.map +1 -0
  23. package/dist/cli.d.ts +3 -0
  24. package/dist/cli.d.ts.map +1 -0
  25. package/dist/cli.js +51 -0
  26. package/dist/cli.js.map +1 -0
  27. package/dist/command.d.ts +6 -0
  28. package/dist/command.d.ts.map +1 -0
  29. package/dist/command.js +189 -0
  30. package/dist/command.js.map +1 -0
  31. package/dist/config.d.ts +4 -0
  32. package/dist/config.d.ts.map +1 -0
  33. package/dist/config.js +43 -0
  34. package/dist/config.js.map +1 -0
  35. package/dist/decisions.d.ts +26 -0
  36. package/dist/decisions.d.ts.map +1 -0
  37. package/dist/decisions.js +119 -0
  38. package/dist/decisions.js.map +1 -0
  39. package/dist/files.d.ts +38 -0
  40. package/dist/files.d.ts.map +1 -0
  41. package/dist/files.js +224 -0
  42. package/dist/files.js.map +1 -0
  43. package/dist/guard-registration.d.ts +95 -0
  44. package/dist/guard-registration.d.ts.map +1 -0
  45. package/dist/guard-registration.js +282 -0
  46. package/dist/guard-registration.js.map +1 -0
  47. package/dist/host-home.d.ts +33 -0
  48. package/dist/host-home.d.ts.map +1 -0
  49. package/dist/host-home.js +116 -0
  50. package/dist/host-home.js.map +1 -0
  51. package/dist/host-modes.d.ts +13 -0
  52. package/dist/host-modes.d.ts.map +1 -0
  53. package/dist/host-modes.js +36 -0
  54. package/dist/host-modes.js.map +1 -0
  55. package/dist/host-observe.d.ts +24 -0
  56. package/dist/host-observe.d.ts.map +1 -0
  57. package/dist/host-observe.js +233 -0
  58. package/dist/host-observe.js.map +1 -0
  59. package/dist/host.d.ts +100 -0
  60. package/dist/host.d.ts.map +1 -0
  61. package/dist/host.js +505 -0
  62. package/dist/host.js.map +1 -0
  63. package/dist/hosts.d.ts +66 -0
  64. package/dist/hosts.d.ts.map +1 -0
  65. package/dist/hosts.js +39 -0
  66. package/dist/hosts.js.map +1 -0
  67. package/dist/ia-home.d.ts +15 -0
  68. package/dist/ia-home.d.ts.map +1 -0
  69. package/dist/ia-home.js +101 -0
  70. package/dist/ia-home.js.map +1 -0
  71. package/dist/install.d.ts +56 -0
  72. package/dist/install.d.ts.map +1 -0
  73. package/dist/install.js +402 -0
  74. package/dist/install.js.map +1 -0
  75. package/dist/installation-core.d.ts +41 -0
  76. package/dist/installation-core.d.ts.map +1 -0
  77. package/dist/installation-core.js +163 -0
  78. package/dist/installation-core.js.map +1 -0
  79. package/dist/inventory.d.ts +3 -0
  80. package/dist/inventory.d.ts.map +1 -0
  81. package/dist/inventory.js +49 -0
  82. package/dist/inventory.js.map +1 -0
  83. package/dist/json-edit.d.ts +19 -0
  84. package/dist/json-edit.d.ts.map +1 -0
  85. package/dist/json-edit.js +81 -0
  86. package/dist/json-edit.js.map +1 -0
  87. package/dist/lifecycle-registration.d.ts +47 -0
  88. package/dist/lifecycle-registration.d.ts.map +1 -0
  89. package/dist/lifecycle-registration.js +351 -0
  90. package/dist/lifecycle-registration.js.map +1 -0
  91. package/dist/minting.d.ts +46 -0
  92. package/dist/minting.d.ts.map +1 -0
  93. package/dist/minting.js +192 -0
  94. package/dist/minting.js.map +1 -0
  95. package/dist/native-command.d.ts +6 -0
  96. package/dist/native-command.d.ts.map +1 -0
  97. package/dist/native-command.js +273 -0
  98. package/dist/native-command.js.map +1 -0
  99. package/dist/pack.d.ts +4 -0
  100. package/dist/pack.d.ts.map +1 -0
  101. package/dist/pack.js +30 -0
  102. package/dist/pack.js.map +1 -0
  103. package/dist/plugin-home.d.ts +45 -0
  104. package/dist/plugin-home.d.ts.map +1 -0
  105. package/dist/plugin-home.js +371 -0
  106. package/dist/plugin-home.js.map +1 -0
  107. package/dist/program.d.ts +64 -0
  108. package/dist/program.d.ts.map +1 -0
  109. package/dist/program.js +126 -0
  110. package/dist/program.js.map +1 -0
  111. package/dist/projection.d.ts +45 -0
  112. package/dist/projection.d.ts.map +1 -0
  113. package/dist/projection.js +218 -0
  114. package/dist/projection.js.map +1 -0
  115. package/dist/publication.d.ts +20 -0
  116. package/dist/publication.d.ts.map +1 -0
  117. package/dist/publication.js +284 -0
  118. package/dist/publication.js.map +1 -0
  119. package/dist/registry-admission.d.ts +5 -0
  120. package/dist/registry-admission.d.ts.map +1 -0
  121. package/dist/registry-admission.js +17 -0
  122. package/dist/registry-admission.js.map +1 -0
  123. package/dist/registry-build.d.ts +35 -0
  124. package/dist/registry-build.d.ts.map +1 -0
  125. package/dist/registry-build.js +156 -0
  126. package/dist/registry-build.js.map +1 -0
  127. package/dist/registry-config.d.ts +32 -0
  128. package/dist/registry-config.d.ts.map +1 -0
  129. package/dist/registry-config.js +191 -0
  130. package/dist/registry-config.js.map +1 -0
  131. package/dist/registry-layout.d.ts +41 -0
  132. package/dist/registry-layout.d.ts.map +1 -0
  133. package/dist/registry-layout.js +142 -0
  134. package/dist/registry-layout.js.map +1 -0
  135. package/dist/registry-resolve.d.ts +56 -0
  136. package/dist/registry-resolve.d.ts.map +1 -0
  137. package/dist/registry-resolve.js +406 -0
  138. package/dist/registry-resolve.js.map +1 -0
  139. package/dist/registry-source.d.ts +37 -0
  140. package/dist/registry-source.d.ts.map +1 -0
  141. package/dist/registry-source.js +101 -0
  142. package/dist/registry-source.js.map +1 -0
  143. package/dist/registry.d.ts +10 -0
  144. package/dist/registry.d.ts.map +1 -0
  145. package/dist/registry.js +6 -0
  146. package/dist/registry.js.map +1 -0
  147. package/dist/resolve.d.ts +31 -0
  148. package/dist/resolve.d.ts.map +1 -0
  149. package/dist/resolve.js +115 -0
  150. package/dist/resolve.js.map +1 -0
  151. package/dist/services.d.ts +179 -0
  152. package/dist/services.d.ts.map +1 -0
  153. package/dist/services.js +290 -0
  154. package/dist/services.js.map +1 -0
  155. package/dist/snapshot.d.ts +24 -0
  156. package/dist/snapshot.d.ts.map +1 -0
  157. package/dist/snapshot.js +343 -0
  158. package/dist/snapshot.js.map +1 -0
  159. package/dist/system-package.d.ts +71 -0
  160. package/dist/system-package.d.ts.map +1 -0
  161. package/dist/system-package.js +169 -0
  162. package/dist/system-package.js.map +1 -0
  163. package/dist/transfer.d.ts +22 -0
  164. package/dist/transfer.d.ts.map +1 -0
  165. package/dist/transfer.js +98 -0
  166. package/dist/transfer.js.map +1 -0
  167. package/dist/updates.d.ts +57 -0
  168. package/dist/updates.d.ts.map +1 -0
  169. package/dist/updates.js +201 -0
  170. package/dist/updates.js.map +1 -0
  171. package/dist/ustar.d.ts +28 -0
  172. package/dist/ustar.d.ts.map +1 -0
  173. package/dist/ustar.js +145 -0
  174. package/dist/ustar.js.map +1 -0
  175. package/package.json +323 -3
  176. package/references/system-package.md +13 -0
@@ -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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AAiB,CAAC;QACtB,IAAI,CAAC;YACH,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,GAAG,EAAE,CAAC;QACf,CAAC;QACD,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAC3B,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,iBAAiB,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,64 @@
1
+ export type Env = Readonly<Record<string, string | undefined>>;
2
+ /** The file system a lookup reads. Injected only by tests that run the Windows rules on another platform. */
3
+ export interface LookupFs {
4
+ readonly statSync: (path: string) => {
5
+ isFile(): boolean;
6
+ isDirectory(): boolean;
7
+ };
8
+ readonly accessSync: (path: string, mode: number) => void;
9
+ }
10
+ export interface ProgramSystem {
11
+ readonly platform: NodeJS.Platform;
12
+ readonly fs: LookupFs;
13
+ }
14
+ export declare const SYSTEM: ProgramSystem;
15
+ /**
16
+ * What a lookup accepts. `program`: what starts without a shell, an executable regular file on POSIX and, on Windows,
17
+ * `name.com` or `name.exe`, the two names libuv tries for a bare name. `script`: on Windows only, `name.bat` or
18
+ * `name.cmd`, in that order, which only cmd.exe runs; never PATHEXT's script types, which start through Windows Script Host.
19
+ */
20
+ export type ProgramKind = 'program' | 'script';
21
+ /**
22
+ * An entry that may be searched: absolute and, on Windows, naming a drive or a share. An empty or relative entry names
23
+ * the working directory or below it, and a Windows entry rooted without a drive (`\tools`) depends on the current drive.
24
+ */
25
+ export declare function qualifiedPath(path: string, platform: NodeJS.Platform): boolean;
26
+ /**
27
+ * The PATH entries a lookup searches, in order. Windows may quote an entry and allows no quote in a file name, so the
28
+ * quotes go there; on POSIX every entry is taken as written. Without PATH, POSIX searches /usr/bin and /bin, where a
29
+ * spawn by bare name looked, and Windows searches nothing.
30
+ */
31
+ export declare function qualifiedEntries(env: Env, platform: NodeJS.Platform): readonly string[];
32
+ /**
33
+ * The absolute path of `name` in the first qualified PATH entry that holds it, or null. An entry that is not a
34
+ * directory costs one check. On POSIX the first executable regular file wins, as the shell's search would; there is no
35
+ * `script` kind there. On Windows a script whose path holds `%` is passed over, because cmd.exe would expand it.
36
+ */
37
+ export declare function findProgram(name: string, env: Env, kind?: ProgramKind, system?: ProgramSystem): string | null;
38
+ /**
39
+ * The environment of a started program: `env` with PATH reduced to its qualified entries and, on Windows,
40
+ * `NoDefaultCurrentDirectoryInExePath=1`, which cmd.exe and libuv honor, so the program's own lookups (npm's
41
+ * `claude.cmd` starts `node` by name) cannot reach its working directory either. POSIX reads an empty PATH as the
42
+ * working directory, so a PATH with no qualified entry becomes /usr/bin:/bin there. Every spelling of both names is
43
+ * replaced, so the environment block holds each once.
44
+ */
45
+ export declare function programEnv(env: Env, platform?: NodeJS.Platform): Record<string, string>;
46
+ /**
47
+ * The working directory of a started program whose result does not depend on it: the user's home, which the repository
48
+ * does not control. A version manager's shim (asdf, mise, nodenv) on a qualified entry still reads version files
49
+ * upward from there, so the home's choice applies, not the repository's.
50
+ */
51
+ export declare const programHome: () => string;
52
+ /**
53
+ * cmd.exe, which a Windows script needs, by a qualified path: `%SystemRoot%\System32\cmd.exe`, or the default
54
+ * Windows directory's when SystemRoot is missing or not qualified. Never ComSpec: Node gives a shell cmd.exe's
55
+ * switches only when its path matches cmd.exe with backslashes, so the caller passes them itself.
56
+ */
57
+ export declare function windowsShell(env: Env): string;
58
+ /**
59
+ * cmd.exe's arguments for a script found by absolute path, passed with `windowsVerbatimArguments`: /d skips AutoRun
60
+ * commands, /v:off stops a delayed expansion the registry may turn on from reading a `!`, and /s /c runs the line
61
+ * inside the outer quotes as written. Each argument must already be safe on a cmd.exe line.
62
+ */
63
+ export declare function windowsShellArgs(file: string, args: readonly string[]): string[];
64
+ //# sourceMappingURL=program.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAC/D,6GAA6G;AAC7G,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK;QAAE,MAAM,IAAI,OAAO,CAAC;QAAC,WAAW,IAAI,OAAO,CAAA;KAAE,CAAC;IACnF,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3D;AACD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC;IACnC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;CACvB;AACD,eAAO,MAAM,MAAM,EAAE,aAA4E,CAAC;AAClG;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,CAAC;AAU/C;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,GAAG,OAAO,CAG9E;AACD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,GAAG,SAAS,MAAM,EAAE,CAOvF;AAKD;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,GAAG,EACR,IAAI,GAAE,WAAuB,EAC7B,MAAM,GAAE,aAAsB,GAC7B,MAAM,GAAG,IAAI,CAwBf;AACD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,GAAE,MAAM,CAAC,QAA2B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUzG;AACD;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAAO,MAAmB,CAAC;AACnD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAG7C;AACD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAEhF"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * How `ia-distribution refresh-updates` finds and starts `npm` and `git`. A user may run it by hand from a
3
+ * directory the repository controls, so no step of the launch may search that directory. It looks the program up
4
+ * itself, on qualified PATH entries only, and runs what it found by absolute path; the program gets only those entries
5
+ * in its PATH and, on Windows, `NoDefaultCurrentDirectoryInExePath=1`, so its own lookups skip its working directory
6
+ * too. This is the rule the session hook applies to `ia`, and the same module as apps/cli/src/program.ts, which can
7
+ * import this one once it is exported.
8
+ */
9
+ import { accessSync, constants, statSync } from 'node:fs';
10
+ import { homedir } from 'node:os';
11
+ import { posix, win32 } from 'node:path';
12
+ export const SYSTEM = { platform: process.platform, fs: { statSync, accessSync } };
13
+ const paths = (platform) => (platform === 'win32' ? win32 : posix);
14
+ /** An environment value by name, whatever its case on Windows, which reads environment names without regard to case. */
15
+ function variable(env, name, platform) {
16
+ if (platform !== 'win32')
17
+ return env[name];
18
+ for (const [key, value] of Object.entries(env))
19
+ if (key.toUpperCase() === name.toUpperCase() && value !== undefined)
20
+ return value;
21
+ return undefined;
22
+ }
23
+ /**
24
+ * An entry that may be searched: absolute and, on Windows, naming a drive or a share. An empty or relative entry names
25
+ * the working directory or below it, and a Windows entry rooted without a drive (`\tools`) depends on the current drive.
26
+ */
27
+ export function qualifiedPath(path, platform) {
28
+ const p = paths(platform);
29
+ return p.isAbsolute(path) && (platform !== 'win32' || p.parse(path).root.length > 1);
30
+ }
31
+ /**
32
+ * The PATH entries a lookup searches, in order. Windows may quote an entry and allows no quote in a file name, so the
33
+ * quotes go there; on POSIX every entry is taken as written. Without PATH, POSIX searches /usr/bin and /bin, where a
34
+ * spawn by bare name looked, and Windows searches nothing.
35
+ */
36
+ export function qualifiedEntries(env, platform) {
37
+ const value = variable(env, 'PATH', platform);
38
+ if (value === undefined)
39
+ return platform === 'win32' ? [] : ['/usr/bin', '/bin'];
40
+ const entries = value.split(paths(platform).delimiter);
41
+ return (platform === 'win32' ? entries.map((entry) => entry.replace(/"/g, '')) : entries).filter((entry) => qualifiedPath(entry, platform));
42
+ }
43
+ const EXTENSIONS = {
44
+ program: ['.com', '.exe'],
45
+ script: ['.bat', '.cmd'],
46
+ };
47
+ /**
48
+ * The absolute path of `name` in the first qualified PATH entry that holds it, or null. An entry that is not a
49
+ * directory costs one check. On POSIX the first executable regular file wins, as the shell's search would; there is no
50
+ * `script` kind there. On Windows a script whose path holds `%` is passed over, because cmd.exe would expand it.
51
+ */
52
+ export function findProgram(name, env, kind = 'program', system = SYSTEM) {
53
+ const { platform, fs } = system, windows = platform === 'win32';
54
+ if (!windows && kind === 'script')
55
+ return null;
56
+ const names = windows ? EXTENSIONS[kind].map((extension) => name + extension) : [name];
57
+ for (const dir of qualifiedEntries(env, platform)) {
58
+ try {
59
+ if (!fs.statSync(dir).isDirectory())
60
+ continue;
61
+ }
62
+ catch {
63
+ continue;
64
+ }
65
+ for (const candidate of names) {
66
+ const file = paths(platform).join(dir, candidate);
67
+ if (kind === 'script' && file.includes('%'))
68
+ continue;
69
+ try {
70
+ if (!fs.statSync(file).isFile())
71
+ continue;
72
+ if (!windows)
73
+ fs.accessSync(file, constants.X_OK);
74
+ return file;
75
+ }
76
+ catch {
77
+ // Absent or not executable: keep looking, as the shell would.
78
+ }
79
+ }
80
+ }
81
+ return null;
82
+ }
83
+ /**
84
+ * The environment of a started program: `env` with PATH reduced to its qualified entries and, on Windows,
85
+ * `NoDefaultCurrentDirectoryInExePath=1`, which cmd.exe and libuv honor, so the program's own lookups (npm's
86
+ * `claude.cmd` starts `node` by name) cannot reach its working directory either. POSIX reads an empty PATH as the
87
+ * working directory, so a PATH with no qualified entry becomes /usr/bin:/bin there. Every spelling of both names is
88
+ * replaced, so the environment block holds each once.
89
+ */
90
+ export function programEnv(env, platform = process.platform) {
91
+ const replaced = platform === 'win32' ? ['PATH', 'NODEFAULTCURRENTDIRECTORYINEXEPATH'] : ['PATH'];
92
+ const result = {};
93
+ for (const [key, value] of Object.entries(env))
94
+ if (value !== undefined && !replaced.includes(platform === 'win32' ? key.toUpperCase() : key))
95
+ result[key] = value;
96
+ const entries = qualifiedEntries(env, platform);
97
+ result['PATH'] =
98
+ entries.length > 0 || platform === 'win32' ? entries.join(paths(platform).delimiter) : '/usr/bin:/bin';
99
+ if (platform === 'win32')
100
+ result['NoDefaultCurrentDirectoryInExePath'] = '1';
101
+ return result;
102
+ }
103
+ /**
104
+ * The working directory of a started program whose result does not depend on it: the user's home, which the repository
105
+ * does not control. A version manager's shim (asdf, mise, nodenv) on a qualified entry still reads version files
106
+ * upward from there, so the home's choice applies, not the repository's.
107
+ */
108
+ export const programHome = () => homedir();
109
+ /**
110
+ * cmd.exe, which a Windows script needs, by a qualified path: `%SystemRoot%\System32\cmd.exe`, or the default
111
+ * Windows directory's when SystemRoot is missing or not qualified. Never ComSpec: Node gives a shell cmd.exe's
112
+ * switches only when its path matches cmd.exe with backslashes, so the caller passes them itself.
113
+ */
114
+ export function windowsShell(env) {
115
+ const root = variable(env, 'SystemRoot', 'win32');
116
+ return win32.join(root !== undefined && qualifiedPath(root, 'win32') ? root : 'C:\\Windows', 'System32', 'cmd.exe');
117
+ }
118
+ /**
119
+ * cmd.exe's arguments for a script found by absolute path, passed with `windowsVerbatimArguments`: /d skips AutoRun
120
+ * commands, /v:off stops a delayed expansion the registry may turn on from reading a `!`, and /s /c runs the line
121
+ * inside the outer quotes as written. Each argument must already be safe on a cmd.exe line.
122
+ */
123
+ export function windowsShellArgs(file, args) {
124
+ return ['/d', '/v:off', '/s', '/c', `"${[`"${file}"`, ...args].join(' ')}"`];
125
+ }
126
+ //# sourceMappingURL=program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.js","sourceRoot":"","sources":["../src/program.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAYzC,MAAM,CAAC,MAAM,MAAM,GAAkB,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,CAAC;AAQlG,MAAM,KAAK,GAAG,CAAC,QAAyB,EAAE,EAAE,CAAC,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACpF,wHAAwH;AACxH,SAAS,QAAQ,CAAC,GAAQ,EAAE,IAAY,EAAE,QAAyB;IACjE,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;QAC5C,IAAI,GAAG,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,WAAW,EAAE,I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AAK,SAAS,IAAI,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;AACtH,CAAC;AACD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,IAAuB;IACpE,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAC/E,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,C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