@inventarch/runtime 3.4.1 → 3.5.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 (72) hide show
  1. package/SPEC.md +7 -1
  2. package/dist/method/bindings.d.ts +51 -0
  3. package/dist/method/bindings.d.ts.map +1 -0
  4. package/dist/method/bindings.js +166 -0
  5. package/dist/method/bindings.js.map +1 -0
  6. package/dist/method/catalogue.d.ts +39 -0
  7. package/dist/method/catalogue.d.ts.map +1 -0
  8. package/dist/method/catalogue.js +126 -0
  9. package/dist/method/catalogue.js.map +1 -0
  10. package/dist/method/errors.d.ts +28 -0
  11. package/dist/method/errors.d.ts.map +1 -0
  12. package/dist/method/errors.js +39 -0
  13. package/dist/method/errors.js.map +1 -0
  14. package/dist/method/index.d.ts +30 -0
  15. package/dist/method/index.d.ts.map +1 -0
  16. package/dist/method/index.js +16 -0
  17. package/dist/method/index.js.map +1 -0
  18. package/dist/method/installed-kits.d.ts +49 -0
  19. package/dist/method/installed-kits.d.ts.map +1 -0
  20. package/dist/method/installed-kits.js +194 -0
  21. package/dist/method/installed-kits.js.map +1 -0
  22. package/dist/method/kit-root.d.ts +31 -0
  23. package/dist/method/kit-root.d.ts.map +1 -0
  24. package/dist/method/kit-root.js +120 -0
  25. package/dist/method/kit-root.js.map +1 -0
  26. package/dist/method/kits.d.ts +130 -0
  27. package/dist/method/kits.d.ts.map +1 -0
  28. package/dist/method/kits.js +381 -0
  29. package/dist/method/kits.js.map +1 -0
  30. package/dist/method/packet.d.ts +51 -0
  31. package/dist/method/packet.d.ts.map +1 -0
  32. package/dist/method/packet.js +62 -0
  33. package/dist/method/packet.js.map +1 -0
  34. package/dist/method/pin.d.ts +71 -0
  35. package/dist/method/pin.d.ts.map +1 -0
  36. package/dist/method/pin.js +164 -0
  37. package/dist/method/pin.js.map +1 -0
  38. package/dist/method/reader.d.ts +38 -0
  39. package/dist/method/reader.d.ts.map +1 -0
  40. package/dist/method/reader.js +97 -0
  41. package/dist/method/reader.js.map +1 -0
  42. package/dist/method/registry.d.ts +39 -0
  43. package/dist/method/registry.d.ts.map +1 -0
  44. package/dist/method/registry.js +129 -0
  45. package/dist/method/registry.js.map +1 -0
  46. package/dist/method/releases.d.ts +47 -0
  47. package/dist/method/releases.d.ts.map +1 -0
  48. package/dist/method/releases.js +104 -0
  49. package/dist/method/releases.js.map +1 -0
  50. package/dist/method/resolve.d.ts +44 -0
  51. package/dist/method/resolve.d.ts.map +1 -0
  52. package/dist/method/resolve.js +448 -0
  53. package/dist/method/resolve.js.map +1 -0
  54. package/dist/method/retained.d.ts +8 -0
  55. package/dist/method/retained.d.ts.map +1 -0
  56. package/dist/method/retained.js +182 -0
  57. package/dist/method/retained.js.map +1 -0
  58. package/dist/method/root.d.ts +12 -0
  59. package/dist/method/root.d.ts.map +1 -0
  60. package/dist/method/root.js +43 -0
  61. package/dist/method/root.js.map +1 -0
  62. package/dist/method/session.d.ts +64 -0
  63. package/dist/method/session.d.ts.map +1 -0
  64. package/dist/method/session.js +109 -0
  65. package/dist/method/session.js.map +1 -0
  66. package/dist/packet-host.d.ts +1 -1
  67. package/dist/packet-host.d.ts.map +1 -1
  68. package/dist/packet.d.ts +1 -1
  69. package/dist/packet.d.ts.map +1 -1
  70. package/dist/packet.js +3 -2
  71. package/dist/packet.js.map +1 -1
  72. package/package.json +8 -4
@@ -0,0 +1,62 @@
1
+ import { createHash } from 'node:crypto';
2
+ /**
3
+ * The method packet and its canonical digest. The digest covers what the agent acts on (closure, scope, instructions,
4
+ * references, role, requested operations, evidence and effective operations), serialized with sorted keys; the
5
+ * envelope (host, CLI, kit root, latency) and the binding are excluded, so one resolution digests the same everywhere.
6
+ */
7
+ export const PACKET_CONTRACT = 1;
8
+ export const EVIDENCE_STATES = ['proposed', 'attempted', 'executed', 'verified', 'accepted'];
9
+ export const DIGESTED = [
10
+ 'closure',
11
+ 'scope',
12
+ 'instructions',
13
+ 'references',
14
+ 'role',
15
+ 'requestedOperations',
16
+ 'evidence',
17
+ 'effectiveOperations',
18
+ ];
19
+ /** JSON with every object's keys sorted, recursively; undefined members dropped. */
20
+ export function canonical(value) {
21
+ if (Array.isArray(value))
22
+ return '[' + value.map((v) => canonical(v === undefined ? null : v)).join(',') + ']';
23
+ if (value && typeof value === 'object') {
24
+ const record = value;
25
+ return ('{' +
26
+ Object.keys(record)
27
+ .filter((key) => record[key] !== undefined)
28
+ .sort()
29
+ .map((key) => JSON.stringify(key) + ':' + canonical(record[key]))
30
+ .join(',') +
31
+ '}');
32
+ }
33
+ return JSON.stringify(value);
34
+ }
35
+ export function packetDigest(packet) {
36
+ const subject = {};
37
+ for (const key of DIGESTED)
38
+ subject[key] = packet[key] ?? null;
39
+ return createHash('sha256').update(canonical(subject)).digest('hex');
40
+ }
41
+ /** Assembles a packet and stamps its digest; `required` is the capability's checks, the runner's by default. */
42
+ export function assemblePacket(parts) {
43
+ const packet = {
44
+ contract: PACKET_CONTRACT,
45
+ resolver: parts.resolver,
46
+ binding: parts.binding,
47
+ closure: parts.closure,
48
+ scope: parts.scope,
49
+ instructions: parts.instructions,
50
+ references: parts.references,
51
+ role: parts.role,
52
+ requestedOperations: parts.requestedOperations,
53
+ effectiveOperations: { status: 'host-determined', runner: parts.runner },
54
+ missing: parts.missing,
55
+ evidence: { required: parts.required ?? parts.runner, states: EVIDENCE_STATES },
56
+ kitUpdateAvailable: parts.kitUpdateAvailable ?? null,
57
+ envelope: parts.envelope,
58
+ };
59
+ packet.digest = packetDigest(packet);
60
+ return packet;
61
+ }
62
+ //# sourceMappingURL=packet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packet.js","sourceRoot":"","sources":["../../src/method/packet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,UAAU,EAAE,WAAW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,CAAC,IAAI,IAAI,CAAC;IAC/D,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACvE,CAAC;AAoBD,gHAAgH;AAChH,MAAM,UAAU,cAAc,CAAC,KAc9B;IACC,MAAM,MAAM,GAAiB;QAC3B,QAAQ,EAAE,eAAe;QACzB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,mBAAmB,EAAE,KAAK,CAAC,mBAAmB;QAC9C,mBAAmB,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;QACxE,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,QAAQ,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE;QAC/E,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,IAAI,IAAI;QACpD,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC;IACF,MAAM,CAAC,MAAM,GAAG,YAAY,CAAC,MAA4C,CAAC,CAAC;IAC3E,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The task binding (pin): which kit versions and capabilities a task resolved, one entry per activity key, kept at
3
+ * `<IA home>/work-v1/<project>/<task>/binding.json` with every earlier revision as `binding.<n>.json`. Format 3:
4
+ * `{ format: 3, revision, workspace: { root, revision }, task, kits: { <kit id>: { version, archive, sources,
5
+ * implementation, retained } }, keys: { <entry>.<activity>: { kit, capability, profile, records, scopeKey, intent } },
6
+ * createdAt, supersedes }`. A format 1 pin (one kit and capability) reads as format 3 with its one key. A pin belongs
7
+ * to one workspace: a read for another root refuses.
8
+ */
9
+ export declare const PIN_FORMAT = 3;
10
+ export interface PinnedKit {
11
+ readonly version: string | null;
12
+ readonly archive?: string | null;
13
+ readonly sources?: string | null;
14
+ readonly implementation?: string | null;
15
+ readonly retained?: string | null;
16
+ }
17
+ export interface PinnedKey {
18
+ readonly kit: string;
19
+ readonly capability: string;
20
+ readonly profile?: string | null;
21
+ readonly records?: readonly string[];
22
+ readonly scopeKey?: unknown;
23
+ readonly intent?: unknown;
24
+ }
25
+ export interface Pin {
26
+ readonly format: number;
27
+ readonly revision: number;
28
+ readonly workspace: {
29
+ readonly root: string;
30
+ readonly revision?: string;
31
+ };
32
+ readonly task?: string | null;
33
+ readonly kits: Readonly<Record<string, PinnedKit>>;
34
+ readonly keys: Readonly<Record<string, PinnedKey>>;
35
+ readonly createdAt?: string;
36
+ readonly supersedes?: number | null;
37
+ readonly path: string;
38
+ }
39
+ /** The folder that holds the task's binding, or null for a stateless resolve. */
40
+ export declare function pinRootFor(options?: {
41
+ readonly env?: NodeJS.ProcessEnv;
42
+ readonly project?: string | undefined;
43
+ readonly task?: string | undefined;
44
+ readonly run?: string | undefined;
45
+ }): string | null;
46
+ /**
47
+ * The project a pin folder is named by when the caller names a task but no project: the workspace root's folder name,
48
+ * each character outside `[A-Za-z0-9._-]` as `-`, leading characters that cannot open a slug dropped, cut to 128, and
49
+ * `workspace` when nothing is left. The `ia` plugin's `lib/pin.mjs` takes `--project` from its caller and derives none;
50
+ * the door's callers name a task only, so the door's pins sit under the folder this names.
51
+ */
52
+ export declare function projectOf(root: string): string;
53
+ /** The current pin in the folder for this workspace, or null; a pin naming another workspace root refuses. */
54
+ export declare function readPin(pinRoot: string | null, workspaceRoot: string): Pin | null;
55
+ /** Writes the next revision; the previous current file is kept as `binding.<n>.json`. */
56
+ export declare function writePin(pinRoot: string, record: Pick<Pin, 'workspace' | 'task' | 'kits' | 'keys'>, previous: Pin | undefined): Pin;
57
+ /** Null when the pinned kit is the available version, else both. */
58
+ export declare function kitUpdate(pinnedKit: PinnedKit | null | undefined, available: {
59
+ readonly version: string | null | undefined;
60
+ readonly archive: string | null | undefined;
61
+ } | null): {
62
+ readonly pinned: {
63
+ readonly version: string | null;
64
+ readonly archive: string | null;
65
+ };
66
+ readonly available: {
67
+ readonly version: string | null | undefined;
68
+ readonly archive: string | null;
69
+ };
70
+ } | null;
71
+ //# sourceMappingURL=pin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pin.d.ts","sourceRoot":"","sources":["../../src/method/pin.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AACD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AACD,MAAM,WAAW,GAAG;IAClB,QAAQ,CAAC,MAAM,EAA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AAC,GAAG,EAAE,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,EACzD,QAAQ,EAAE,GAAG,GAAG,SAAS,GACxB,GAAG,CAmDL;AAED,oEAAoE;AACpE,wBAAgB,SAAS,CACvB,SAAS,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,EACvC,SAAS,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CAAE,GAAG,IAAI,GAC7G;IACD,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;IACtF,QAAQ,CAAC,SAAS,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC;CACtG,GAAG,IAAI,CAQP"}
@@ -0,0 +1,164 @@
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { basename, join, resolve } from 'node:path';
3
+ import { MethodError } from './errors.js';
4
+ import { iaHome } from './kits.js';
5
+ /**
6
+ * The task binding (pin): which kit versions and capabilities a task resolved, one entry per activity key, kept at
7
+ * `<IA home>/work-v1/<project>/<task>/binding.json` with every earlier revision as `binding.<n>.json`. Format 3:
8
+ * `{ format: 3, revision, workspace: { root, revision }, task, kits: { <kit id>: { version, archive, sources,
9
+ * implementation, retained } }, keys: { <entry>.<activity>: { kit, capability, profile, records, scopeKey, intent } },
10
+ * createdAt, supersedes }`. A format 1 pin (one kit and capability) reads as format 3 with its one key. A pin belongs
11
+ * to one workspace: a read for another root refuses.
12
+ */
13
+ export const PIN_FORMAT = 3;
14
+ const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
15
+ /** The folder that holds the task's binding, or null for a stateless resolve. */
16
+ export function pinRootFor(options = {}) {
17
+ const env = options.env ?? process.env;
18
+ for (const [name, value] of [
19
+ ['project', options.project],
20
+ ['task', options.task],
21
+ ['run', options.run],
22
+ ])
23
+ if (value !== undefined && !SLUG.test(value))
24
+ throw new MethodError(`--${name} must be a slug (letters, digits, . _ -): ${value}`, 'IA-CORE-USAGE');
25
+ if (env['IA_CORE_RUN_ROOT'])
26
+ return resolve(env['IA_CORE_RUN_ROOT']);
27
+ if (!options.project && !options.task)
28
+ return null;
29
+ if (!options.project || !options.task)
30
+ throw new MethodError('a task binding needs --project and --task together (or IA_CORE_RUN_ROOT); --run only names the run that attaches', 'IA-CORE-USAGE');
31
+ return join(iaHome(env), 'work-v1', options.project, options.task);
32
+ }
33
+ /**
34
+ * The project a pin folder is named by when the caller names a task but no project: the workspace root's folder name,
35
+ * each character outside `[A-Za-z0-9._-]` as `-`, leading characters that cannot open a slug dropped, cut to 128, and
36
+ * `workspace` when nothing is left. The `ia` plugin's `lib/pin.mjs` takes `--project` from its caller and derives none;
37
+ * the door's callers name a task only, so the door's pins sit under the folder this names.
38
+ */
39
+ export function projectOf(root) {
40
+ const slug = basename(resolve(root))
41
+ .replace(/[^A-Za-z0-9._-]/g, '-')
42
+ .replace(/^[^A-Za-z0-9]+/, '')
43
+ .slice(0, 128);
44
+ return SLUG.test(slug) ? slug : 'workspace';
45
+ }
46
+ const same = (a, b) => resolve(a).replace(/\\/g, '/').toLowerCase() === resolve(b).replace(/\\/g, '/').toLowerCase();
47
+ function upgrade(pin) {
48
+ const { kit, capability, records, scopeKey, intent, ...rest } = pin;
49
+ const key = `${intent?.entry}.${intent?.activity}`;
50
+ return {
51
+ ...rest,
52
+ format: PIN_FORMAT,
53
+ legacyFormat: 1,
54
+ kits: { [kit.id]: { version: kit.version, archive: kit.archive ?? null, sources: kit.sources ?? null } },
55
+ keys: {
56
+ [key]: { kit: kit.id, capability, records: records ?? [], scopeKey: scopeKey ?? null, intent: intent ?? null },
57
+ },
58
+ };
59
+ }
60
+ /** The current pin in the folder for this workspace, or null; a pin naming another workspace root refuses. */
61
+ export function readPin(pinRoot, workspaceRoot) {
62
+ if (!pinRoot)
63
+ return null;
64
+ const path = join(pinRoot, 'binding.json');
65
+ if (!existsSync(path))
66
+ return null;
67
+ let pin;
68
+ try {
69
+ pin = JSON.parse(readFileSync(path, 'utf8'));
70
+ }
71
+ catch (error) {
72
+ throw new MethodError(`${path} is not JSON: ${error.message}`, 'IA-CORE-PIN-MALFORMED');
73
+ }
74
+ const legacy = pin;
75
+ if (pin['format'] === 1 &&
76
+ legacy.workspace?.root &&
77
+ legacy.kit?.id &&
78
+ legacy.intent?.entry &&
79
+ legacy.intent?.activity)
80
+ pin = upgrade(pin);
81
+ if (pin['format'] === 2)
82
+ pin = { ...pin, format: PIN_FORMAT, legacyFormat: 2 };
83
+ const shaped = pin;
84
+ const kits = shaped.kits, keys = shaped.keys;
85
+ const valid = shaped.format === PIN_FORMAT &&
86
+ Boolean(shaped.workspace?.root) &&
87
+ kits !== undefined &&
88
+ typeof kits === 'object' &&
89
+ keys !== undefined &&
90
+ typeof keys === 'object' &&
91
+ Object.values(keys).every((k) => k && typeof k.kit === 'string' && typeof k.capability === 'string' && kits[k.kit] !== undefined);
92
+ if (!valid)
93
+ throw new MethodError(`${path} is not a format ${PIN_FORMAT} task binding (nor a format 1 one)`, 'IA-CORE-PIN-MALFORMED');
94
+ const root = shaped.workspace.root;
95
+ if (!same(root, workspaceRoot))
96
+ throw new MethodError(`${path} binds a task in ${root}, not in ${workspaceRoot}: a task belongs to one repository; use that repository or another task folder`, 'IA-CORE-RUN-MISMATCH', { pinnedRoot: root });
97
+ return { ...pin, path };
98
+ }
99
+ /** Writes the next revision; the previous current file is kept as `binding.<n>.json`. */
100
+ export function writePin(pinRoot, record, previous) {
101
+ mkdirSync(pinRoot, { recursive: true });
102
+ const path = join(pinRoot, 'binding.json'), lock = join(pinRoot, '.binding.lock');
103
+ const deadline = Date.now() + 5000;
104
+ for (;;) {
105
+ try {
106
+ mkdirSync(lock);
107
+ break;
108
+ }
109
+ catch (error) {
110
+ if (error.code !== 'EEXIST')
111
+ throw error;
112
+ if (Date.now() >= deadline)
113
+ throw new MethodError('task pin is locked; retry after its writer completes', 'IA-CORE-PIN-CONFLICT');
114
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 50);
115
+ }
116
+ }
117
+ const temporary = join(pinRoot, `.binding-${process.pid}-${Date.now()}.tmp`);
118
+ try {
119
+ const currentBytes = existsSync(path) ? readFileSync(path, 'utf8') : null;
120
+ const current = currentBytes ? JSON.parse(currentBytes) : null;
121
+ if ((current?.revision ?? null) !== (previous?.revision ?? null))
122
+ throw new MethodError('task pin changed during resolution; resolve again against the current revision', 'IA-CORE-PIN-CONFLICT');
123
+ const revision = (previous?.revision ?? 0) + 1;
124
+ const pin = {
125
+ format: PIN_FORMAT,
126
+ revision,
127
+ ...record,
128
+ createdAt: new Date().toISOString(),
129
+ supersedes: previous ? previous.revision : null,
130
+ };
131
+ writeFileSync(temporary, JSON.stringify(pin, null, 2) + '\n', { flag: 'wx' });
132
+ if (previous) {
133
+ const history = join(pinRoot, `binding.${previous.revision}.json`);
134
+ // Created exclusively and never checked first: a history that already exists must hold the same bytes.
135
+ try {
136
+ writeFileSync(history, currentBytes ?? '', { flag: 'wx' });
137
+ }
138
+ catch (error) {
139
+ if (error.code !== 'EEXIST')
140
+ throw error;
141
+ if (readFileSync(history, 'utf8') !== currentBytes)
142
+ throw new MethodError('task pin history already contains different bytes', 'IA-CORE-PIN-CONFLICT');
143
+ }
144
+ }
145
+ renameSync(temporary, path);
146
+ return { ...pin, path };
147
+ }
148
+ finally {
149
+ rmSync(temporary, { force: true });
150
+ rmSync(lock, { recursive: true });
151
+ }
152
+ }
153
+ /** Null when the pinned kit is the available version, else both. */
154
+ export function kitUpdate(pinnedKit, available) {
155
+ if (!pinnedKit || !available)
156
+ return null;
157
+ if (pinnedKit.version === available.version && (pinnedKit.archive ?? null) === (available.archive ?? null))
158
+ return null;
159
+ return {
160
+ pinned: { version: pinnedKit.version, archive: pinnedKit.archive ?? null },
161
+ available: { version: available.version, archive: available.archive ?? null },
162
+ };
163
+ }
164
+ //# sourceMappingURL=pin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pin.js","sourceRoot":"","sources":["../../src/method/pin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC;AA6B5B,MAAM,IAAI,GAAG,oCAAoC,CAAC;AAElD,iFAAiF;AACjF,MAAM,UAAU,UAAU,CACxB,UAKI,EAAE;IAEN,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI;QAC1B,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC;QAC5B,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC;QACtB,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC;KACZ;QACR,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;YAC1C,MAAM,IAAI,WAAW,CAAC,KAAK,IAAI,6CAA6C,KAAK,EAAE,EAAE,eAAe,CAAC,CAAC;IAC1G,IAAI,GAAG,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,SAAS,EAAE,IAAI,CAAC,CAAC;QAC5B,OAAO,EAAE,GAAG,GAAG,EAAE,IAAI,EAAE,CAAC;IAC1B,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACnC,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,CAAC;AACH,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,SAAS,CACvB,SAAuC,EACvC,SAA8G;IAK9G,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,SAAS,CAAC,OAAO,KAAK,SAAS,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,IAAI,IAAI,CAAC;QACxG,OAAO,IAAI,CAAC;IACd,OAAO;QACL,MAAM,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,IAAI,IAAI,EAAE;QAC1E,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,IAAI,IAAI,EAAE;KAC9E,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * One workspace read in process, answering what `ia position --json`, `ia inspect --json` and `ia read --json` answer
3
+ * for it: the same bodies, records and directed rows, as JSON values. The workspace opens once, without the db cache, so
4
+ * nothing is written.
5
+ */
6
+ export interface PositionAnswer {
7
+ readonly ok: boolean;
8
+ readonly body?: Record<string, unknown>;
9
+ readonly digest?: string;
10
+ readonly code?: string;
11
+ readonly message?: string;
12
+ readonly next?: string;
13
+ }
14
+ export type JsonRecord = Record<string, unknown>;
15
+ export declare class WorkspaceReader {
16
+ #private;
17
+ readonly root: string;
18
+ constructor(root: string);
19
+ /** The position body for a shape and phase, and an optional seat: an identity, else a workspace path. */
20
+ position(key: {
21
+ readonly shape: string;
22
+ readonly phase: string;
23
+ readonly seat?: string | undefined;
24
+ }): PositionAnswer;
25
+ /** The admitted record of an identity as `ia inspect` lists it, or null. */
26
+ record(identity: string): JsonRecord | null;
27
+ /** The inbound rows of an identity's directed view, as `ia inspect --edges in` lists them at depth 1, or null. */
28
+ inbound(identity: string): readonly JsonRecord[] | null;
29
+ /** The body and digest behind a locator, or the refusal's message. */
30
+ read(locator: string): {
31
+ readonly body: string;
32
+ readonly digest: string;
33
+ } | {
34
+ readonly message: string;
35
+ };
36
+ close(): void;
37
+ }
38
+ //# sourceMappingURL=reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.d.ts","sourceRoot":"","sources":["../../src/method/reader.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AACD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAajD,qBAAa,eAAe;;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAGV,IAAI,EAAE,MAAM;IAcxB,yGAAyG;IACzG,QAAQ,CAAC,GAAG,EAAE;QACZ,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;KACpC,GAAG,cAAc;IAYlB,4EAA4E;IAC5E,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI;IAU3C,kHAAkH;IAClH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,UAAU,EAAE,GAAG,IAAI;IAYvD,sEAAsE;IACtE,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE;IAaxG,KAAK,IAAI,IAAI;CAId"}
@@ -0,0 +1,97 @@
1
+ import { adoptedBindings, open, readWorkspaceBytes } from '@inventarch/db';
2
+ import { DISTRIBUTION_LIMITS } from '@inventarch/db/distribution';
3
+ import { parseLocator, readBody } from '../locator.js';
4
+ import { position } from '../position.js';
5
+ const plain = (value) => JSON.parse(JSON.stringify(value));
6
+ const failure = (error) => {
7
+ const object = (error ?? {});
8
+ return {
9
+ ok: false,
10
+ code: typeof object.code === 'string' ? object.code : 'IA-CORE-ERROR',
11
+ message: error instanceof Error ? error.message : String(error),
12
+ ...(typeof object.next === 'string' ? { next: object.next } : {}),
13
+ };
14
+ };
15
+ export class WorkspaceReader {
16
+ root;
17
+ #handle;
18
+ #opened;
19
+ constructor(root) {
20
+ this.root = root;
21
+ }
22
+ #open() {
23
+ if (this.#handle !== undefined)
24
+ return this.#handle;
25
+ if (this.#opened !== undefined)
26
+ throw this.#opened;
27
+ try {
28
+ this.#handle = open(this.root, { cache: false });
29
+ return this.#handle;
30
+ }
31
+ catch (error) {
32
+ this.#opened = error;
33
+ throw error;
34
+ }
35
+ }
36
+ /** The position body for a shape and phase, and an optional seat: an identity, else a workspace path. */
37
+ position(key) {
38
+ try {
39
+ const handle = this.#open();
40
+ const partial = { shape: key.shape, phase: key.phase };
41
+ if (key.seat !== undefined)
42
+ partial['seat'] = parseLocator(key.seat)?.form === 'identity' ? key.seat : { path: key.seat };
43
+ const got = position(handle, handle.resolveScope().token, partial);
44
+ return { ok: true, body: plain(got.body), digest: got.digest };
45
+ }
46
+ catch (error) {
47
+ return failure(error);
48
+ }
49
+ }
50
+ /** The admitted record of an identity as `ia inspect` lists it, or null. */
51
+ record(identity) {
52
+ try {
53
+ const found = this.#open()
54
+ .records()
55
+ .find((record) => record.identity === identity);
56
+ return found === undefined ? null : plain(found);
57
+ }
58
+ catch {
59
+ return null;
60
+ }
61
+ }
62
+ /** The inbound rows of an identity's directed view, as `ia inspect --edges in` lists them at depth 1, or null. */
63
+ inbound(identity) {
64
+ try {
65
+ const handle = this.#open();
66
+ if (!handle.records().some((record) => record.identity === identity))
67
+ return null;
68
+ return handle
69
+ .directedView(identity)
70
+ .filter((row) => row.direction === 'in')
71
+ .map((row) => plain({ identity, depth: 1, ...row }));
72
+ }
73
+ catch {
74
+ return null;
75
+ }
76
+ }
77
+ /** The body and digest behind a locator, or the refusal's message. */
78
+ read(locator) {
79
+ try {
80
+ const handle = this.#open();
81
+ const root = handle.root;
82
+ const got = readBody(handle, locator, {
83
+ read: (path) => readWorkspaceBytes(root, path, DISTRIBUTION_LIMITS.metadata),
84
+ mounts: new Map(adoptedBindings(root).map((binding) => [binding.tree, binding.path])),
85
+ });
86
+ return got.ok ? { body: got.body.body, digest: got.body.digest } : { message: got.message };
87
+ }
88
+ catch (error) {
89
+ return { message: error instanceof Error ? error.message : String(error) };
90
+ }
91
+ }
92
+ close() {
93
+ this.#handle?.close();
94
+ this.#handle = undefined;
95
+ }
96
+ }
97
+ //# sourceMappingURL=reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.js","sourceRoot":"","sources":["../../src/method/reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,C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C,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;aACtF,CAAC,CAAC;YACH,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,CAAC;QAC9F,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7E,CAAC;IACH,CAAC;IACD,KAAK;QACH,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;IAC3B,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The workspace registry: `<IA home>/workspace-locations.json`, the workspace roots one person keeps. Format 2 is
3
+ * `{ format: "ia-workspace-locations-2", workspaces: [{ id, root, label?, added }] }`. Readers also accept the two
4
+ * earlier files and normalise them: `personal-workspace-locations-1`, whose `workspaces` object maps an id to
5
+ * `{ root, ... }`, and Studio's `format: 1`, whose `locations` object maps an id to `{ path, ... }`. Writers write
6
+ * format 2 only. User-facing workspaces default to `~/Documents/ia/<domain>`; the IA home holds the registry, never a
7
+ * workspace.
8
+ */
9
+ export declare const REGISTRY_FORMAT = "ia-workspace-locations-2";
10
+ export declare const REGISTRY_FILE = "workspace-locations.json";
11
+ export interface RegisteredWorkspace {
12
+ readonly id: string;
13
+ readonly root: string;
14
+ readonly label?: string;
15
+ readonly added: string;
16
+ }
17
+ export interface WorkspaceRegistry {
18
+ readonly format: typeof REGISTRY_FORMAT;
19
+ readonly workspaces: readonly RegisteredWorkspace[];
20
+ }
21
+ export declare const registryPath: (home: string) => string;
22
+ /** The default root of a user-facing workspace for a domain: `~/Documents/ia/<domain>`. */
23
+ export declare const defaultWorkspaceRoot: (domain: string, home?: string) => string;
24
+ /** The registry, normalised to format 2 whichever format the file holds; an empty one when there is no file. */
25
+ export declare function readRegistry(home: string): WorkspaceRegistry;
26
+ /** Writes the registry as format 2, atomically. */
27
+ export declare function writeRegistry(home: string, registry: Pick<WorkspaceRegistry, 'workspaces'>): string;
28
+ /**
29
+ * Adds or replaces one workspace and writes the registry as format 2, keeping every other row. A root inside the IA
30
+ * home is refused: the home holds configuration and state, never a workspace.
31
+ */
32
+ export declare function registerWorkspace(home: string, workspace: {
33
+ readonly id: string;
34
+ readonly root: string;
35
+ readonly label?: string;
36
+ }, now?: Date): RegisteredWorkspace;
37
+ /** Whether two paths name one folder, case folded where the platform folds it. */
38
+ export declare const samePath: (a: string, b: string) => boolean;
39
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/method/registry.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAC1D,eAAO,MAAM,aAAa,6BAA6B,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AACD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,OAAO,eAAe,CAAC;IACxC,QAAQ,CAAC,UAAU,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACrD;AAGD,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,MAAmC,CAAC;AAChF,2FAA2F;AAC3F,eAAO,MAAM,oBAAoB,GAAI,QAAQ,MAAM,EAAE,OAAM,MAAkB,KAAG,MAG/E,CAAC;AAKF,gHAAgH;AAChH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAsC5D;AAED,mDAAmD;AACnD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,GAAG,MAAM,CAYnG;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,EAClF,GAAG,GAAE,IAAiB,GACrB,mBAAmB,CAmBrB;AAYD,kFAAkF;AAClF,eAAO,MAAM,QAAQ,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,OAA4B,CAAC"}
@@ -0,0 +1,129 @@
1
+ import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { isAbsolute, join, resolve } from 'node:path';
4
+ import { MethodError } from './errors.js';
5
+ /**
6
+ * The workspace registry: `<IA home>/workspace-locations.json`, the workspace roots one person keeps. Format 2 is
7
+ * `{ format: "ia-workspace-locations-2", workspaces: [{ id, root, label?, added }] }`. Readers also accept the two
8
+ * earlier files and normalise them: `personal-workspace-locations-1`, whose `workspaces` object maps an id to
9
+ * `{ root, ... }`, and Studio's `format: 1`, whose `locations` object maps an id to `{ path, ... }`. Writers write
10
+ * format 2 only. User-facing workspaces default to `~/Documents/ia/<domain>`; the IA home holds the registry, never a
11
+ * workspace.
12
+ */
13
+ export const REGISTRY_FORMAT = 'ia-workspace-locations-2';
14
+ export const REGISTRY_FILE = 'workspace-locations.json';
15
+ const ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
16
+ export const registryPath = (home) => join(home, REGISTRY_FILE);
17
+ /** The default root of a user-facing workspace for a domain: `~/Documents/ia/<domain>`. */
18
+ export const defaultWorkspaceRoot = (domain, home = homedir()) => {
19
+ if (!ID.test(domain))
20
+ throw new MethodError(`a workspace domain must be a slug: ${domain}`, 'IA-CORE-USAGE');
21
+ return join(home, 'Documents', 'ia', domain);
22
+ };
23
+ const malformed = (path, why) => new MethodError(`${path} is not a workspace registry: ${why}`, 'IA-CORE-REGISTRY');
24
+ /** The registry, normalised to format 2 whichever format the file holds; an empty one when there is no file. */
25
+ export function readRegistry(home) {
26
+ const path = registryPath(home);
27
+ if (!existsSync(path))
28
+ return { format: REGISTRY_FORMAT, workspaces: [] };
29
+ let parsed;
30
+ try {
31
+ parsed = JSON.parse(readFileSync(path, 'utf8'));
32
+ }
33
+ catch (error) {
34
+ throw malformed(path, error.message);
35
+ }
36
+ const fallback = statSync(path).mtime.toISOString();
37
+ const entry = (id, value, rootKey) => {
38
+ const row = (value ?? {});
39
+ const root = row[rootKey];
40
+ if (typeof root !== 'string' || !isAbsolute(root))
41
+ throw malformed(path, `${id} names no absolute ${rootKey}`);
42
+ const label = typeof row['label'] === 'string' ? row['label'] : undefined;
43
+ const added = typeof row['added'] === 'string' ? row['added'] : fallback;
44
+ return { id, root, ...(label === undefined ? {} : { label }), added };
45
+ };
46
+ const keyed = (value, rootKey) => {
47
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
48
+ throw malformed(path, 'no object of ids');
49
+ return Object.entries(value).map(([id, row]) => entry(id, row, rootKey));
50
+ };
51
+ let workspaces;
52
+ if (parsed['format'] === REGISTRY_FORMAT) {
53
+ if (!Array.isArray(parsed['workspaces']))
54
+ throw malformed(path, 'format 2 needs a workspaces list');
55
+ workspaces = parsed['workspaces'].map((row) => {
56
+ if (typeof row?.['id'] !== 'string')
57
+ throw malformed(path, 'a workspace has no id');
58
+ return entry(row['id'], row, 'root');
59
+ });
60
+ }
61
+ else if (parsed['format'] === 'personal-workspace-locations-1')
62
+ workspaces = keyed(parsed['workspaces'], 'root');
63
+ else if (parsed['format'] === 1)
64
+ workspaces = keyed(parsed['locations'], 'path');
65
+ else
66
+ throw malformed(path, `unknown format ${JSON.stringify(parsed['format'])}`);
67
+ const ids = new Set();
68
+ for (const workspace of workspaces) {
69
+ if (ids.has(workspace.id))
70
+ throw malformed(path, `${workspace.id} is listed twice`);
71
+ ids.add(workspace.id);
72
+ }
73
+ return { format: REGISTRY_FORMAT, workspaces };
74
+ }
75
+ /** Writes the registry as format 2, atomically. */
76
+ export function writeRegistry(home, registry) {
77
+ const path = registryPath(home);
78
+ mkdirSync(home, { recursive: true });
79
+ const temporary = `${path}.${process.pid}.${Date.now()}.tmp`;
80
+ const body = { format: REGISTRY_FORMAT, workspaces: registry.workspaces };
81
+ try {
82
+ writeFileSync(temporary, JSON.stringify(body, null, 2) + '\n', { flag: 'wx' });
83
+ renameSync(temporary, path);
84
+ }
85
+ finally {
86
+ rmSync(temporary, { force: true });
87
+ }
88
+ return path;
89
+ }
90
+ /**
91
+ * Adds or replaces one workspace and writes the registry as format 2, keeping every other row. A root inside the IA
92
+ * home is refused: the home holds configuration and state, never a workspace.
93
+ */
94
+ export function registerWorkspace(home, workspace, now = new Date()) {
95
+ if (!ID.test(workspace.id))
96
+ throw new MethodError(`a workspace id must be a slug: ${workspace.id}`, 'IA-CORE-USAGE');
97
+ if (!isAbsolute(workspace.root))
98
+ throw new MethodError(`a workspace root must be absolute: ${workspace.root}`, 'IA-CORE-USAGE');
99
+ const root = resolve(workspace.root);
100
+ if (sameOrInside(root, home))
101
+ throw new MethodError(`${root} is inside the IA home ${home}; a workspace lives elsewhere`, 'IA-CORE-USAGE');
102
+ const current = readRegistry(home);
103
+ const prior = current.workspaces.find((row) => row.id === workspace.id);
104
+ const row = {
105
+ id: workspace.id,
106
+ root,
107
+ ...(workspace.label === undefined ? {} : { label: workspace.label }),
108
+ added: prior?.added ?? now.toISOString(),
109
+ };
110
+ writeRegistry(home, {
111
+ workspaces: [...current.workspaces.filter((other) => other.id !== workspace.id), row],
112
+ });
113
+ return row;
114
+ }
115
+ /** The text without its trailing slashes, in one pass: a pattern anchored only at its end backtracks on a run of them. */
116
+ const trimSlashes = (text) => {
117
+ let end = text.length;
118
+ while (end > 0 && text[end - 1] === '/')
119
+ end -= 1;
120
+ return text.slice(0, end);
121
+ };
122
+ const key = (path) => {
123
+ const plain = trimSlashes(resolve(path).replace(/\\/g, '/'));
124
+ return process.platform === 'win32' || process.platform === 'darwin' ? plain.toLowerCase() : plain;
125
+ };
126
+ /** Whether two paths name one folder, case folded where the platform folds it. */
127
+ export const samePath = (a, b) => key(a) === key(b);
128
+ const sameOrInside = (path, parent) => samePath(path, parent) || key(path).startsWith(key(parent) + '/');
129
+ //# sourceMappingURL=registry.js.map