@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.
- package/LANGUAGE.md +56 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +2 -2
- package/SPEC.md +5 -0
- package/assets/host-launcher.mjs +167 -0
- package/dist/acquire.d.ts +13 -0
- package/dist/acquire.d.ts.map +1 -0
- package/dist/acquire.js +46 -0
- package/dist/acquire.js.map +1 -0
- package/dist/archive.d.ts +20 -0
- package/dist/archive.d.ts.map +1 -0
- package/dist/archive.js +165 -0
- package/dist/archive.js.map +1 -0
- package/dist/authoring-assets.d.ts +11 -0
- package/dist/authoring-assets.d.ts.map +1 -0
- package/dist/authoring-assets.js +251 -0
- package/dist/authoring-assets.js.map +1 -0
- package/dist/bounded-fetch.d.ts +17 -0
- package/dist/bounded-fetch.d.ts.map +1 -0
- package/dist/bounded-fetch.js +67 -0
- package/dist/bounded-fetch.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +51 -0
- package/dist/cli.js.map +1 -0
- package/dist/command.d.ts +6 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +189 -0
- package/dist/command.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +43 -0
- package/dist/config.js.map +1 -0
- package/dist/decisions.d.ts +26 -0
- package/dist/decisions.d.ts.map +1 -0
- package/dist/decisions.js +119 -0
- package/dist/decisions.js.map +1 -0
- package/dist/files.d.ts +38 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +224 -0
- package/dist/files.js.map +1 -0
- package/dist/guard-registration.d.ts +95 -0
- package/dist/guard-registration.d.ts.map +1 -0
- package/dist/guard-registration.js +282 -0
- package/dist/guard-registration.js.map +1 -0
- package/dist/host-home.d.ts +33 -0
- package/dist/host-home.d.ts.map +1 -0
- package/dist/host-home.js +116 -0
- package/dist/host-home.js.map +1 -0
- package/dist/host-modes.d.ts +13 -0
- package/dist/host-modes.d.ts.map +1 -0
- package/dist/host-modes.js +36 -0
- package/dist/host-modes.js.map +1 -0
- package/dist/host-observe.d.ts +24 -0
- package/dist/host-observe.d.ts.map +1 -0
- package/dist/host-observe.js +233 -0
- package/dist/host-observe.js.map +1 -0
- package/dist/host.d.ts +100 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +505 -0
- package/dist/host.js.map +1 -0
- package/dist/hosts.d.ts +66 -0
- package/dist/hosts.d.ts.map +1 -0
- package/dist/hosts.js +39 -0
- package/dist/hosts.js.map +1 -0
- package/dist/ia-home.d.ts +15 -0
- package/dist/ia-home.d.ts.map +1 -0
- package/dist/ia-home.js +101 -0
- package/dist/ia-home.js.map +1 -0
- package/dist/install.d.ts +56 -0
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +402 -0
- package/dist/install.js.map +1 -0
- package/dist/installation-core.d.ts +41 -0
- package/dist/installation-core.d.ts.map +1 -0
- package/dist/installation-core.js +163 -0
- package/dist/installation-core.js.map +1 -0
- package/dist/inventory.d.ts +3 -0
- package/dist/inventory.d.ts.map +1 -0
- package/dist/inventory.js +49 -0
- package/dist/inventory.js.map +1 -0
- package/dist/json-edit.d.ts +19 -0
- package/dist/json-edit.d.ts.map +1 -0
- package/dist/json-edit.js +81 -0
- package/dist/json-edit.js.map +1 -0
- package/dist/lifecycle-registration.d.ts +47 -0
- package/dist/lifecycle-registration.d.ts.map +1 -0
- package/dist/lifecycle-registration.js +351 -0
- package/dist/lifecycle-registration.js.map +1 -0
- package/dist/minting.d.ts +46 -0
- package/dist/minting.d.ts.map +1 -0
- package/dist/minting.js +192 -0
- package/dist/minting.js.map +1 -0
- package/dist/native-command.d.ts +6 -0
- package/dist/native-command.d.ts.map +1 -0
- package/dist/native-command.js +273 -0
- package/dist/native-command.js.map +1 -0
- package/dist/pack.d.ts +4 -0
- package/dist/pack.d.ts.map +1 -0
- package/dist/pack.js +30 -0
- package/dist/pack.js.map +1 -0
- package/dist/plugin-home.d.ts +45 -0
- package/dist/plugin-home.d.ts.map +1 -0
- package/dist/plugin-home.js +371 -0
- package/dist/plugin-home.js.map +1 -0
- package/dist/program.d.ts +64 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +126 -0
- package/dist/program.js.map +1 -0
- package/dist/projection.d.ts +45 -0
- package/dist/projection.d.ts.map +1 -0
- package/dist/projection.js +218 -0
- package/dist/projection.js.map +1 -0
- package/dist/publication.d.ts +20 -0
- package/dist/publication.d.ts.map +1 -0
- package/dist/publication.js +284 -0
- package/dist/publication.js.map +1 -0
- package/dist/registry-admission.d.ts +5 -0
- package/dist/registry-admission.d.ts.map +1 -0
- package/dist/registry-admission.js +17 -0
- package/dist/registry-admission.js.map +1 -0
- package/dist/registry-build.d.ts +35 -0
- package/dist/registry-build.d.ts.map +1 -0
- package/dist/registry-build.js +156 -0
- package/dist/registry-build.js.map +1 -0
- package/dist/registry-config.d.ts +32 -0
- package/dist/registry-config.d.ts.map +1 -0
- package/dist/registry-config.js +191 -0
- package/dist/registry-config.js.map +1 -0
- package/dist/registry-layout.d.ts +41 -0
- package/dist/registry-layout.d.ts.map +1 -0
- package/dist/registry-layout.js +142 -0
- package/dist/registry-layout.js.map +1 -0
- package/dist/registry-resolve.d.ts +56 -0
- package/dist/registry-resolve.d.ts.map +1 -0
- package/dist/registry-resolve.js +406 -0
- package/dist/registry-resolve.js.map +1 -0
- package/dist/registry-source.d.ts +37 -0
- package/dist/registry-source.d.ts.map +1 -0
- package/dist/registry-source.js +101 -0
- package/dist/registry-source.js.map +1 -0
- package/dist/registry.d.ts +10 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +6 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolve.d.ts +31 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +115 -0
- package/dist/resolve.js.map +1 -0
- package/dist/services.d.ts +179 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +290 -0
- package/dist/services.js.map +1 -0
- package/dist/snapshot.d.ts +24 -0
- package/dist/snapshot.d.ts.map +1 -0
- package/dist/snapshot.js +343 -0
- package/dist/snapshot.js.map +1 -0
- package/dist/system-package.d.ts +71 -0
- package/dist/system-package.d.ts.map +1 -0
- package/dist/system-package.js +169 -0
- package/dist/system-package.js.map +1 -0
- package/dist/transfer.d.ts +22 -0
- package/dist/transfer.d.ts.map +1 -0
- package/dist/transfer.js +98 -0
- package/dist/transfer.js.map +1 -0
- package/dist/updates.d.ts +57 -0
- package/dist/updates.d.ts.map +1 -0
- package/dist/updates.js +201 -0
- package/dist/updates.js.map +1 -0
- package/dist/ustar.d.ts +28 -0
- package/dist/ustar.d.ts.map +1 -0
- package/dist/ustar.js +145 -0
- package/dist/ustar.js.map +1 -0
- package/package.json +323 -3
- package/references/system-package.md +13 -0
package/dist/hosts.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { fail } from './files.js';
|
|
2
|
+
const ROWS = [
|
|
3
|
+
{
|
|
4
|
+
id: 'claude',
|
|
5
|
+
label: 'Claude Code',
|
|
6
|
+
status: 'supported',
|
|
7
|
+
user: 'plugin',
|
|
8
|
+
workspace: true,
|
|
9
|
+
hooks: true,
|
|
10
|
+
invocations: { init: '/ia:init', doctor: '/ia:doctor' },
|
|
11
|
+
},
|
|
12
|
+
{ id: 'codex', label: 'Codex', status: 'partial', user: 'none', workspace: true, hooks: false, invocations: {} },
|
|
13
|
+
{ id: 'cursor', label: 'Cursor', status: 'planned', user: 'none', workspace: false, hooks: false, invocations: {} },
|
|
14
|
+
];
|
|
15
|
+
/** The widened view: callers indexing `invocations[intent]` while iterating get `HostRow`, not one row's own narrow literal type. */
|
|
16
|
+
export const HOSTS = ROWS;
|
|
17
|
+
/** The one place that knows a workspace row from a non-workspace row; lookups narrow through this instead of casting. */
|
|
18
|
+
export const isWorkspace = (row) => row.workspace;
|
|
19
|
+
export const WORKSPACE_HOSTS = ROWS.filter(isWorkspace).map((row) => row.id);
|
|
20
|
+
export const hostRow = (id) => HOSTS.find((row) => row.id === id);
|
|
21
|
+
/** As `hostRow`, but the result is a workspace row or nothing: later CLI code that only ever wants a `WorkspaceHost` needs no cast. */
|
|
22
|
+
export const workspaceRow = (id) => {
|
|
23
|
+
const row = ROWS.find((candidate) => candidate.id === id);
|
|
24
|
+
return row && isWorkspace(row) ? row : undefined;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The M5.3 refusal, message unchanged: a host whose row has no workspace set is not a workspace host. The CLI
|
|
28
|
+
* above already refuses a planned host first, with its own host-naming message (spec §4); this mechanism layer
|
|
29
|
+
* keeps the historical "Expected Claude or Codex" text for whatever reaches it directly.
|
|
30
|
+
*/
|
|
31
|
+
export function asWorkspaceHost(value) {
|
|
32
|
+
const row = typeof value === 'string' ? ROWS.find((candidate) => candidate.id === value) : undefined;
|
|
33
|
+
if (!row || !isWorkspace(row))
|
|
34
|
+
fail('HOST-UNSUPPORTED', 'Expected Claude or Codex');
|
|
35
|
+
return row.id;
|
|
36
|
+
}
|
|
37
|
+
/** §7.3 `nextActions`: the host's own invocation where the row declares one, otherwise the plain command. */
|
|
38
|
+
export const invocation = (id, intent, argv) => hostRow(id)?.invocations[intent] ?? argv.join(' ');
|
|
39
|
+
//# sourceMappingURL=hosts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosts.js","sourceRoot":"","sources":["../src/hosts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAiBlC,MAAM,IAAI,GAAG;IACX;QACE,EAAE,EAAE,QAAQ;QACZ,KAAK,EAAE,aAAa;QACpB,MAAM,EAAE,WAAW;QACnB,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,IAAI;QACX,WAAW,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAA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C,KAAc;IAC5C,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACrG,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;QAAE,IAAI,CAAC,kBAAkB,EAAE,0BAA0B,CAAC,CAAC;IACpF,OAAO,GAAG,CAAC,EAAE,CAAC;AAChB,CAAC;AACD,6GAA6G;AAC7G,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAU,EAAE,MAAc,EAAE,IAAuB,EAAU,EAAE,CACxF,OAAO,CAAC,EAAE,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Host plugin distribution spec §3: the user-level IA home and which variable placed it. IA_HOST_HOME is a one-release alias. */
|
|
2
|
+
export type HomeSource = 'IA_HOME' | 'IA_HOST_HOME' | 'default';
|
|
3
|
+
export declare function resolveIaHome(env: Readonly<Record<string, string | undefined>>, userHome: string): {
|
|
4
|
+
readonly home: string;
|
|
5
|
+
readonly source: HomeSource;
|
|
6
|
+
};
|
|
7
|
+
export declare const HOME_MARKER = "home.json";
|
|
8
|
+
/** §3: the home names itself and never holds src/, so root discovery can never take it for a workspace. Read-only: never creates or writes anything, so a caller can refuse at plan time before any write is attempted. */
|
|
9
|
+
export declare function assertIaHomeUsable(home: string): void;
|
|
10
|
+
/** Refuses a home that already looks like a workspace, then creates it and marks it. */
|
|
11
|
+
export declare function ensureIaHome(home: string): void;
|
|
12
|
+
/** One file under the home, replaced atomically: written beside its target with fsync, then renamed over it. Refuses a `path` that is empty or escapes the home, before the home is even created or marked. */
|
|
13
|
+
export declare function writeHomeFile(home: string, path: string, text: string): void;
|
|
14
|
+
export declare function readHomeFile(home: string, path: string): string | null;
|
|
15
|
+
//# sourceMappingURL=ia-home.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ia-home.d.ts","sourceRoot":"","sources":["../src/ia-home.ts"],"names":[],"mappings":"AAeA,kIAAkI;AAClI,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,cAAc,GAAG,SAAS,CAAC;AAChE,wBAAgB,aAAa,CAC3B,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EACjD,QAAQ,EAAE,MAAM,GACf;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAAE,CASxD;AACD,eAAO,MAAM,WAAW,cAAc,CAAC;AACvC,2NAA2N;AAC3N,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAMrD;AAgCD,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAI/C;AACD,+MAA+M;AAC/M,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAqB5E;AACD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOtE"}
|
package/dist/ia-home.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
|
|
3
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
import { fail, syncDirectory } from './files.js';
|
|
5
|
+
export function resolveIaHome(env, userHome) {
|
|
6
|
+
for (const name of ['IA_HOME', 'IA_HOST_HOME']) {
|
|
7
|
+
const value = env[name];
|
|
8
|
+
if (value !== undefined && value !== '') {
|
|
9
|
+
if (!isAbsolute(value))
|
|
10
|
+
fail('INPUT-INVALID', `${name} must be absolute`);
|
|
11
|
+
return { home: resolve(value), source: name };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return { home: join(userHome, '.ia'), source: 'default' };
|
|
15
|
+
}
|
|
16
|
+
export const HOME_MARKER = 'home.json';
|
|
17
|
+
/** §3: the home names itself and never holds src/, so root discovery can never take it for a workspace. Read-only: never creates or writes anything, so a caller can refuse at plan time before any write is attempted. */
|
|
18
|
+
export function assertIaHomeUsable(home) {
|
|
19
|
+
if (existsSync(join(home, 'src')))
|
|
20
|
+
fail('PATH-UNSAFE', `The IA home ${home} contains src/; move that directory away, because the home must never look like a workspace`);
|
|
21
|
+
}
|
|
22
|
+
/** Atomic (stage then rename) and tolerant of a concurrent creator: a marker that already parses is left alone; an empty or unparseable one is rewritten. */
|
|
23
|
+
function markHome(home) {
|
|
24
|
+
const target = join(home, HOME_MARKER);
|
|
25
|
+
let existing = null;
|
|
26
|
+
try {
|
|
27
|
+
existing = readFileSync(target, 'utf8');
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error.code !== 'ENOENT')
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
if (existing !== null && existing.trim() !== '') {
|
|
34
|
+
try {
|
|
35
|
+
JSON.parse(existing);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
/* falls through: an unparseable marker is rewritten below */
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const stage = `${target}.${randomUUID()}.tmp`;
|
|
43
|
+
try {
|
|
44
|
+
const fd = openSync(stage, 'wx', 0o600);
|
|
45
|
+
try {
|
|
46
|
+
writeFileSync(fd, JSON.stringify({ schema: 'ia.home.v1' }) + '\n');
|
|
47
|
+
fsyncSync(fd);
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
closeSync(fd);
|
|
51
|
+
}
|
|
52
|
+
renameSync(stage, target);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
if (existsSync(stage))
|
|
56
|
+
rmSync(stage, { force: true });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Refuses a home that already looks like a workspace, then creates it and marks it. */
|
|
60
|
+
export function ensureIaHome(home) {
|
|
61
|
+
assertIaHomeUsable(home);
|
|
62
|
+
mkdirSync(home, { recursive: true });
|
|
63
|
+
markHome(home);
|
|
64
|
+
}
|
|
65
|
+
/** One file under the home, replaced atomically: written beside its target with fsync, then renamed over it. Refuses a `path` that is empty or escapes the home, before the home is even created or marked. */
|
|
66
|
+
export function writeHomeFile(home, path, text) {
|
|
67
|
+
const target = join(home, path);
|
|
68
|
+
const escaped = relative(home, target);
|
|
69
|
+
if (escaped === '' || escaped === '..' || escaped.startsWith('..' + sep) || isAbsolute(escaped))
|
|
70
|
+
fail('PATH-UNSAFE', `${path} escapes the IA home ${home}`);
|
|
71
|
+
ensureIaHome(home);
|
|
72
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
73
|
+
const stage = `${target}.${randomUUID()}.tmp`;
|
|
74
|
+
try {
|
|
75
|
+
const fd = openSync(stage, 'wx', 0o600);
|
|
76
|
+
try {
|
|
77
|
+
writeFileSync(fd, text);
|
|
78
|
+
fsyncSync(fd);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
closeSync(fd);
|
|
82
|
+
}
|
|
83
|
+
renameSync(stage, target);
|
|
84
|
+
syncDirectory(dirname(target));
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
if (existsSync(stage))
|
|
88
|
+
rmSync(stage, { force: true });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export function readHomeFile(home, path) {
|
|
92
|
+
try {
|
|
93
|
+
return readFileSync(join(home, path), 'utf8');
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error.code === 'ENOENT')
|
|
97
|
+
return null;
|
|
98
|
+
throw error;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=ia-home.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ia-home.js","sourceRoot":"","sources":["../src/ia-home.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,MAAM,EACN,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAIjD,MAAM,UAAU,aAAa,CAC3B,GAAiD,EACjD,QAAgB;IAEhB,KAAK,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE,cAAc,CAAU,EAAE,CAAC;QACxD,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;YACxC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC;gBAAE,IAAI,CAAC,eAAe,EAAE,GAAG,IAAI,mBAAmB,CAAC,CAAC;YAC1E,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAChD,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAC5D,CAAC;AACD,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;AACv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B,CAAC;QACD,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1B,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACjC,CAAC;YAAS,CAAC;QACT,IAAI,UAAU,CAAC,KAAK,CAAC;YAAE,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,CAAC;AACH,CAAC;AACD,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,IAAY;IACrD,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QACpE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ActivationPointer, DistributionLock } from '@inventarch/db/distribution';
|
|
2
|
+
import type { VerifiedArchive } from './archive.js';
|
|
3
|
+
import { type InstallOperation } from './installation-core.js';
|
|
4
|
+
export type { InstallOperation } from './installation-core.js';
|
|
5
|
+
export interface InstallationPlan {
|
|
6
|
+
readonly formatVersion: 1;
|
|
7
|
+
readonly operation: InstallOperation;
|
|
8
|
+
readonly root: string;
|
|
9
|
+
readonly engine: string;
|
|
10
|
+
readonly binding: {
|
|
11
|
+
readonly source: string;
|
|
12
|
+
readonly active: string | null;
|
|
13
|
+
readonly lock: string | null;
|
|
14
|
+
};
|
|
15
|
+
readonly lock: DistributionLock;
|
|
16
|
+
readonly pointer: ActivationPointer;
|
|
17
|
+
readonly changes: {
|
|
18
|
+
readonly added: readonly string[];
|
|
19
|
+
readonly removed: readonly string[];
|
|
20
|
+
readonly updated: readonly string[];
|
|
21
|
+
readonly shadowed: readonly string[];
|
|
22
|
+
};
|
|
23
|
+
readonly digest: string;
|
|
24
|
+
}
|
|
25
|
+
export interface InstallOptions {
|
|
26
|
+
readonly checkpoint?: (name: string) => void;
|
|
27
|
+
}
|
|
28
|
+
/** The workspace archive cache: `<digest>.ia.tgz` files only, each written once by `cacheArchive`. */
|
|
29
|
+
export declare const ARCHIVE_CACHE = ".ia/distributions/cache";
|
|
30
|
+
/** A cache entry's name; group 1 is the archive digest. */
|
|
31
|
+
export declare const CACHED_ARCHIVE_NAME: RegExp;
|
|
32
|
+
export declare const cachePath: (digest: string) => string;
|
|
33
|
+
export declare function cacheArchive(rootInput: string, content: Uint8Array, expectedDigest?: string): VerifiedArchive;
|
|
34
|
+
/** Qualify an exact selected closure before publishing any immutable cache member. */
|
|
35
|
+
export declare function cacheSelectedArchiveClosure(rootInput: string, lockInput: unknown, input: ReadonlyMap<string, Uint8Array>): ReadonlyMap<string, VerifiedArchive>;
|
|
36
|
+
/** Read exact bounded cache bytes without cache writes or installation activation. Admission belongs to the consuming operation. */
|
|
37
|
+
export declare function readCachedArchiveSelection(rootInput: string, lockInput: unknown): ReadonlyMap<string, Buffer>;
|
|
38
|
+
export declare function cachedReleases(root: string, lock: DistributionLock): ReadonlyMap<string, VerifiedArchive>;
|
|
39
|
+
export declare function planInstallation(rootInput: string, lockInput: unknown, operation: InstallOperation): InstallationPlan;
|
|
40
|
+
export declare function applyInstallation(input: unknown, options?: InstallOptions): {
|
|
41
|
+
status: 'installed';
|
|
42
|
+
generation: string;
|
|
43
|
+
counter: number;
|
|
44
|
+
host: 'pending';
|
|
45
|
+
};
|
|
46
|
+
export declare function recoverInstallation(rootInput: string, options?: InstallOptions): {
|
|
47
|
+
status: 'current' | 'recovered';
|
|
48
|
+
committed?: boolean;
|
|
49
|
+
};
|
|
50
|
+
/** Conservative explicit GC: retain every generation, and collect only verified orphan archives/stores. */
|
|
51
|
+
export declare function collectInstallationGarbage(rootInput: string, apply?: boolean): {
|
|
52
|
+
status: 'planned' | 'collected';
|
|
53
|
+
archives: readonly string[];
|
|
54
|
+
retainedGener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AC3B;IAAE,MAAM,EAAE,SAAS,GAAG,WAAW,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,CAmD1D;AACD,2GAA2G;AAC3G,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,KAAK,UAAQ,GACZ;IAAE,MAAM,EAAE,SAAS,GAAG,WAAW,CAAC;IAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,mBAAmB,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,CAkG1G"}
|
package/dist/install.js
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { closeSync, existsSync, fsyncSync, lstatSync, mkdirSync, openSync, readdirSync, rmdirSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { open, readInputs } from '@inventarch/db';
|
|
4
|
+
import { canonicalDistributionJson as json, decodeActivationPointer, decodeDistributionJson, decodeDistributionLock, DISTRIBUTION_ENGINE_VERSION, DISTRIBUTION_LIMITS, installationWorkspace, INSTALL_PATHS, metadataDigest, platformDebris, readExpandedBundle, readInstalledGeneration, } from '@inventarch/db/distribution';
|
|
5
|
+
import { verifyArchive, verifySelectedArchiveClosure } from './archive.js';
|
|
6
|
+
import { bytes, contained, createFile, fail, object, replace, sha256, syncDirectory, utf8, workspace, } from './files.js';
|
|
7
|
+
import { planInstallationSnapshot } from './installation-core.js';
|
|
8
|
+
import { distributionSnapshot } from './snapshot.js';
|
|
9
|
+
/** The workspace archive cache: `<digest>.ia.tgz` files only, each written once by `cacheArchive`. */
|
|
10
|
+
export const ARCHIVE_CACHE = '.ia/distributions/cache';
|
|
11
|
+
/** A cache entry's name; group 1 is the archive digest. */
|
|
12
|
+
export const CACHED_ARCHIVE_NAME = /^([a-f0-9]{64})\.ia\.tgz$/;
|
|
13
|
+
export const cachePath = (digest) => {
|
|
14
|
+
if (!/^[a-f0-9]{64}$/.test(digest))
|
|
15
|
+
fail('INPUT-INVALID', 'Invalid archive digest');
|
|
16
|
+
return `${ARCHIVE_CACHE}/${digest}.ia.tgz`;
|
|
17
|
+
};
|
|
18
|
+
const hashOrNull = (content) => (content === null ? null : sha256(content));
|
|
19
|
+
function state(root) {
|
|
20
|
+
return {
|
|
21
|
+
source: readInputs(root, { candidateInstallation: null }).fingerprint,
|
|
22
|
+
active: hashOrNull(bytes(root, INSTALL_PATHS.active)),
|
|
23
|
+
lock: hashOrNull(bytes(root, INSTALL_PATHS.lock, DISTRIBUTION_LIMITS.metadata)),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function immutable(root, path, content) {
|
|
27
|
+
const current = bytes(root, path, Math.max(content.length, DISTRIBUTION_LIMITS.file));
|
|
28
|
+
if (current) {
|
|
29
|
+
if (!current.equals(content))
|
|
30
|
+
fail('LOCAL-MODIFICATION', `Managed immutable content differs: ${path}`);
|
|
31
|
+
}
|
|
32
|
+
else
|
|
33
|
+
createFile(root, path, content);
|
|
34
|
+
}
|
|
35
|
+
export function cacheArchive(rootInput, content, expectedDigest) {
|
|
36
|
+
const root = workspace(rootInput), release = verifyArchive(content, expectedDigest);
|
|
37
|
+
immutable(root, cachePath(release.archiveDigest), Buffer.from(content));
|
|
38
|
+
return release;
|
|
39
|
+
}
|
|
40
|
+
/** Qualify an exact selected closure before publishing any immutable cache member. */
|
|
41
|
+
export function cacheSelectedArchiveClosure(rootInput, lockInput, input) {
|
|
42
|
+
const root = workspace(rootInput), lock = decodeDistributionLock(lockInput);
|
|
43
|
+
if (!(input instanceof Map) || input.size !== new Set(lock.packages.map((pkg) => pkg.archive)).size)
|
|
44
|
+
fail('INPUT-INVALID', 'Expected exact selected archive map');
|
|
45
|
+
const archives = new Map();
|
|
46
|
+
let total = 0;
|
|
47
|
+
for (const [digest, content] of input) {
|
|
48
|
+
cachePath(digest);
|
|
49
|
+
if (!(content instanceof Uint8Array) || content.byteLength > DISTRIBUTION_LIMITS.compressed)
|
|
50
|
+
fail('LIMIT-EXCEEDED', 'Invalid or oversized selected archive');
|
|
51
|
+
total += content.byteLength;
|
|
52
|
+
if (total > DISTRIBUTION_LIMITS.expanded)
|
|
53
|
+
fail('LIMIT-EXCEEDED', 'Combined selected archives exceed their ceiling');
|
|
54
|
+
archives.set(digest, Buffer.from(content));
|
|
55
|
+
}
|
|
56
|
+
const releases = verifySelectedArchiveClosure(lock, archives);
|
|
57
|
+
// Preflight the entire selection, so an existing collision or alias cannot cause
|
|
58
|
+
// earlier members to be published before that refusal. Writes still recheck.
|
|
59
|
+
for (const [digest, content] of archives) {
|
|
60
|
+
const path = cachePath(digest), current = bytes(root, path, DISTRIBUTION_LIMITS.compressed);
|
|
61
|
+
if (current && !current.equals(content))
|
|
62
|
+
fail('LOCAL-MODIFICATION', `Managed immutable content differs: ${path}`);
|
|
63
|
+
}
|
|
64
|
+
for (const [digest, content] of archives)
|
|
65
|
+
immutable(root, cachePath(digest), content);
|
|
66
|
+
return releases;
|
|
67
|
+
}
|
|
68
|
+
function cachedArchiveBytes(root, lock) {
|
|
69
|
+
let total = 0;
|
|
70
|
+
return new Map(lock.packages.map((pkg) => {
|
|
71
|
+
const content = bytes(root, cachePath(pkg.archive), DISTRIBUTION_LIMITS.compressed);
|
|
72
|
+
if (!content)
|
|
73
|
+
fail('RESTORE-REQUIRED', `Missing cached archive ${pkg.archive}; supply its exact bytes`);
|
|
74
|
+
total += content.length;
|
|
75
|
+
if (total > DISTRIBUTION_LIMITS.expanded)
|
|
76
|
+
fail('LIMIT-EXCEEDED', 'Combined archive cache selection exceeds its ceiling');
|
|
77
|
+
return [pkg.archive, content];
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
/** Read exact bounded cache bytes without cache writes or installation activation. Admission belongs to the consuming operation. */
|
|
81
|
+
export function readCachedArchiveSelection(rootInput, lockInput) {
|
|
82
|
+
return cachedArchiveBytes(workspace(rootInput), decodeDistributionLock(lockInput));
|
|
83
|
+
}
|
|
84
|
+
export function cachedReleases(root, lock) {
|
|
85
|
+
return verifySelectedArchiveClosure(lock, cachedArchiveBytes(root, lock));
|
|
86
|
+
}
|
|
87
|
+
function noPending(root) {
|
|
88
|
+
if (bytes(root, INSTALL_PATHS.pending, 4 * DISTRIBUTION_LIMITS.metadata))
|
|
89
|
+
fail('RECOVERY-REQUIRED', 'Recover the pending native transaction first');
|
|
90
|
+
}
|
|
91
|
+
function candidate(root, lock, operation) {
|
|
92
|
+
const source = readInputs(root, { candidateInstallation: null }), activeBytes = bytes(root, INSTALL_PATHS.active), previousLock = bytes(root, INSTALL_PATHS.lock, DISTRIBUTION_LIMITS.metadata);
|
|
93
|
+
return planInstallationSnapshot({
|
|
94
|
+
base: distributionSnapshot({ sources: source.sources, folders: source.folders, floorOrigin: source.floorOrigin }),
|
|
95
|
+
current: {
|
|
96
|
+
pointer: activeBytes ? decodeActivationPointer(utf8(activeBytes)) : null,
|
|
97
|
+
lock: previousLock ? decodeDistributionLock(utf8(previousLock)) : null,
|
|
98
|
+
},
|
|
99
|
+
lock,
|
|
100
|
+
operation,
|
|
101
|
+
archives: cachedArchiveBytes(root, lock),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
export function planInstallation(rootInput, lockInput, operation) {
|
|
105
|
+
const root = workspace(rootInput);
|
|
106
|
+
noPending(root);
|
|
107
|
+
const binding = state(root), lock = decodeDistributionLock(lockInput);
|
|
108
|
+
if (operation !== 'restore' && (bytes(root, INSTALL_PATHS.active) || bytes(root, INSTALL_PATHS.lock)))
|
|
109
|
+
readInstalledGeneration(root);
|
|
110
|
+
const checked = candidate(root, lock, operation);
|
|
111
|
+
if (json(state(root)) !== json(binding))
|
|
112
|
+
fail('SOURCE-CHANGED', 'Workspace changed while planning');
|
|
113
|
+
const body = {
|
|
114
|
+
formatVersion: 1,
|
|
115
|
+
operation,
|
|
116
|
+
root,
|
|
117
|
+
engine: DISTRIBUTION_ENGINE_VERSION,
|
|
118
|
+
binding,
|
|
119
|
+
lock,
|
|
120
|
+
pointer: checked.pointer,
|
|
121
|
+
changes: checked.changes,
|
|
122
|
+
};
|
|
123
|
+
return Object.freeze({ ...body, digest: metadataDigest(body) });
|
|
124
|
+
}
|
|
125
|
+
function decodePlan(input) {
|
|
126
|
+
const row = object(typeof input === 'string' ? decodeDistributionJson(input) : decodeDistributionJson(json(input)), [
|
|
127
|
+
'formatVersion',
|
|
128
|
+
'operation',
|
|
129
|
+
'root',
|
|
130
|
+
'engine',
|
|
131
|
+
'binding',
|
|
132
|
+
'lock',
|
|
133
|
+
'pointer',
|
|
134
|
+
'changes',
|
|
135
|
+
'digest',
|
|
136
|
+
]);
|
|
137
|
+
if (row['formatVersion'] !== 1 ||
|
|
138
|
+
!['install', 'update', 'remove', 'restore', 'rollback'].includes(String(row['operation'])) ||
|
|
139
|
+
typeof row['root'] !== 'string' ||
|
|
140
|
+
row['engine'] !== DISTRIBUTION_ENGINE_VERSION)
|
|
141
|
+
fail('INPUT-INVALID', 'Invalid installation plan');
|
|
142
|
+
const { digest, ...body } = row;
|
|
143
|
+
if (digest !== metadataDigest(body))
|
|
144
|
+
fail('INPUT-INVALID', 'Installation plan digest differs');
|
|
145
|
+
decodeDistributionLock(row['lock']);
|
|
146
|
+
decodeActivationPointer(row['pointer']);
|
|
147
|
+
object(row['binding'], ['source', 'active', 'lock']);
|
|
148
|
+
object(row['changes'], ['added', 'removed', 'updated', 'shadowed']);
|
|
149
|
+
return row;
|
|
150
|
+
}
|
|
151
|
+
function acquire(root, recovering = false) {
|
|
152
|
+
const path = '.ia/distributions/install-lock.json', target = contained(root, path);
|
|
153
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
154
|
+
if (recovering && existsSync(target)) {
|
|
155
|
+
const value = object(decodeDistributionJson(utf8(bytes(root, path, 4096))), ['pid']);
|
|
156
|
+
const pid = value['pid'];
|
|
157
|
+
if (!Number.isSafeInteger(pid) || pid <= 0)
|
|
158
|
+
fail('INSTALL-BUSY', 'Invalid native lock requires manual reconciliation');
|
|
159
|
+
try {
|
|
160
|
+
process.kill(pid, 0);
|
|
161
|
+
fail('INSTALL-BUSY', 'Native lock belongs to a running process');
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
if (error.code !== 'ESRCH')
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
unlinkSync(target);
|
|
168
|
+
}
|
|
169
|
+
let fd;
|
|
170
|
+
try {
|
|
171
|
+
fd = openSync(target, 'wx', 0o600);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
if (error.code === 'EEXIST')
|
|
175
|
+
fail('INSTALL-BUSY', 'Another installer holds the workspace lock');
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
writeFileSync(fd, json({ pid: process.pid }));
|
|
180
|
+
fsyncSync(fd);
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
closeSync(fd);
|
|
184
|
+
}
|
|
185
|
+
return () => {
|
|
186
|
+
unlinkSync(target);
|
|
187
|
+
syncDirectory(dirname(target));
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
export function applyInstallation(input, options = {}) {
|
|
191
|
+
const plan = decodePlan(input), root = workspace(plan.root), release = acquire(root), checkpoint = options.checkpoint ?? (() => { });
|
|
192
|
+
try {
|
|
193
|
+
noPending(root);
|
|
194
|
+
if (json(state(root)) !== json(plan.binding) ||
|
|
195
|
+
json(planInstallation(root, plan.lock, plan.operation)) !== json(plan))
|
|
196
|
+
fail('STALE-PLAN', 'Installation bindings changed; create a fresh plan');
|
|
197
|
+
const releases = cachedReleases(root, plan.lock), checked = candidate(root, plan.lock, plan.operation);
|
|
198
|
+
for (const pkg of plan.lock.packages) {
|
|
199
|
+
const artifact = releases.get(pkg.id), directory = `${INSTALL_PATHS.store}/${pkg.archive}`;
|
|
200
|
+
for (const [path, content] of artifact.files) {
|
|
201
|
+
immutable(root, `${directory}/${path}`, content);
|
|
202
|
+
checkpoint(`store:${pkg.id}:${path}`);
|
|
203
|
+
}
|
|
204
|
+
immutable(root, `${directory}/distribution.json`, Buffer.from(json(artifact.manifest)));
|
|
205
|
+
checkpoint(`manifest:${pkg.id}`);
|
|
206
|
+
}
|
|
207
|
+
const directory = `${INSTALL_PATHS.generations}/${plan.pointer.generation}`, generated = installationWorkspace(plan.lock, checked.inputs, releases);
|
|
208
|
+
for (const [path, content] of [
|
|
209
|
+
['lock.json', json(plan.lock)],
|
|
210
|
+
['inputs.json', json(checked.inputs)],
|
|
211
|
+
...(generated === null ? [] : [['workspace.ia', generated]]),
|
|
212
|
+
]) {
|
|
213
|
+
immutable(root, `${directory}/${path}`, Buffer.from(content));
|
|
214
|
+
checkpoint(`generation:${path}`);
|
|
215
|
+
}
|
|
216
|
+
const reader = open(root, { cache: false, candidateInstallation: plan.pointer });
|
|
217
|
+
try {
|
|
218
|
+
if (reader.report.findings.some((f) => f.severity === 'error'))
|
|
219
|
+
fail('ADMISSION-FAILED', 'Staged installation failed native admission');
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
reader.close();
|
|
223
|
+
}
|
|
224
|
+
if (json(state(root)) !== json(plan.binding))
|
|
225
|
+
fail('STALE-PLAN', 'Workspace changed before activation');
|
|
226
|
+
const beforeActive = bytes(root, INSTALL_PATHS.active)?.toString('utf8') ?? null, beforeLock = bytes(root, INSTALL_PATHS.lock, DISTRIBUTION_LIMITS.metadata)?.toString('utf8') ?? null;
|
|
227
|
+
const pending = {
|
|
228
|
+
formatVersion: 1,
|
|
229
|
+
beforeActive,
|
|
230
|
+
beforeLock,
|
|
231
|
+
afterActive: json(plan.pointer),
|
|
232
|
+
afterLock: json(plan.lock),
|
|
233
|
+
};
|
|
234
|
+
replace(root, INSTALL_PATHS.pending, Buffer.from(json(pending)));
|
|
235
|
+
checkpoint('pending');
|
|
236
|
+
if (json(state(root)) !== json(plan.binding))
|
|
237
|
+
fail('STALE-PLAN', 'Workspace changed after pending write');
|
|
238
|
+
replace(root, INSTALL_PATHS.lock, Buffer.from(pending.afterLock));
|
|
239
|
+
checkpoint('portable-lock');
|
|
240
|
+
// Lock replacement is expected; recheck source and the old pointer immediately before commit.
|
|
241
|
+
const current = state(root);
|
|
242
|
+
if (current.source !== plan.binding.source ||
|
|
243
|
+
current.active !== plan.binding.active ||
|
|
244
|
+
current.lock !== sha256(pending.afterLock))
|
|
245
|
+
fail('STALE-PLAN', 'Activation inputs changed');
|
|
246
|
+
readInstalledGeneration(root, plan.pointer);
|
|
247
|
+
replace(root, INSTALL_PATHS.active, Buffer.from(pending.afterActive));
|
|
248
|
+
checkpoint('active');
|
|
249
|
+
replace(root, INSTALL_PATHS.pending, null);
|
|
250
|
+
checkpoint('complete');
|
|
251
|
+
return { status: 'installed', generation: plan.pointer.generation, counter: plan.pointer.counter, host: 'pending' };
|
|
252
|
+
}
|
|
253
|
+
finally {
|
|
254
|
+
release();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
export function recoverInstallation(rootInput, options = {}) {
|
|
258
|
+
const root = workspace(rootInput), release = acquire(root, true), checkpoint = options.checkpoint ?? (() => { });
|
|
259
|
+
try {
|
|
260
|
+
const content = bytes(root, INSTALL_PATHS.pending, 4 * DISTRIBUTION_LIMITS.metadata);
|
|
261
|
+
if (!content)
|
|
262
|
+
return { status: 'current' };
|
|
263
|
+
const pending = object(decodeDistributionJson(utf8(content)), [
|
|
264
|
+
'formatVersion',
|
|
265
|
+
'beforeActive',
|
|
266
|
+
'beforeLock',
|
|
267
|
+
'afterActive',
|
|
268
|
+
'afterLock',
|
|
269
|
+
]);
|
|
270
|
+
if (pending['formatVersion'] !== 1)
|
|
271
|
+
fail('RECOVERY-REQUIRED', 'Unknown pending format');
|
|
272
|
+
const decode = (key, nullable, parser) => {
|
|
273
|
+
const v = pending[key];
|
|
274
|
+
if (nullable && v === null)
|
|
275
|
+
return null;
|
|
276
|
+
if (typeof v !== 'string' || json(parser(v)) !== v)
|
|
277
|
+
fail('RECOVERY-REQUIRED', 'Invalid pending state bytes');
|
|
278
|
+
return v;
|
|
279
|
+
};
|
|
280
|
+
const beforeActive = decode('beforeActive', true, decodeActivationPointer), beforeLock = decode('beforeLock', true, decodeDistributionLock), afterActive = decode('afterActive', false, decodeActivationPointer), afterLock = decode('afterLock', false, decodeDistributionLock);
|
|
281
|
+
const currentActive = bytes(root, INSTALL_PATHS.active)?.toString('utf8') ?? null, currentLock = bytes(root, INSTALL_PATHS.lock, DISTRIBUTION_LIMITS.metadata)?.toString('utf8') ?? null;
|
|
282
|
+
if ((currentActive !== beforeActive && currentActive !== afterActive) ||
|
|
283
|
+
(currentLock !== beforeLock && currentLock !== afterLock))
|
|
284
|
+
fail('RECOVERY-REQUIRED', 'Unknown edited pointer/lock; manual reconciliation required');
|
|
285
|
+
const committed = currentActive === afterActive;
|
|
286
|
+
const next = decodeActivationPointer(afterActive), previous = beforeActive === null ? null : decodeActivationPointer(beforeActive);
|
|
287
|
+
if (next.counter !== (previous?.counter ?? 0) + 1 || next.previous !== (previous?.generation ?? null))
|
|
288
|
+
fail('RECOVERY-REQUIRED', 'Invalid pending activation sequence');
|
|
289
|
+
if (committed && json(readInstalledGeneration(root, next).lock) !== afterLock)
|
|
290
|
+
fail('RECOVERY-REQUIRED', 'Committed lock differs from its generation');
|
|
291
|
+
replace(root, INSTALL_PATHS.lock, committed ? Buffer.from(afterLock) : beforeLock === null ? null : Buffer.from(beforeLock));
|
|
292
|
+
checkpoint('recovery-lock');
|
|
293
|
+
replace(root, INSTALL_PATHS.pending, null);
|
|
294
|
+
checkpoint('recovery-complete');
|
|
295
|
+
return { status: 'recovered', committed };
|
|
296
|
+
}
|
|
297
|
+
finally {
|
|
298
|
+
release();
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/** Conservative explicit GC: retain every generation, and collect only verified orphan archives/stores. */
|
|
302
|
+
export function collectInstallationGarbage(rootInput, apply = false) {
|
|
303
|
+
const root = workspace(rootInput), release = acquire(root);
|
|
304
|
+
try {
|
|
305
|
+
noPending(root);
|
|
306
|
+
const binding = state(root), referenced = new Set(), retained = [];
|
|
307
|
+
const portable = bytes(root, INSTALL_PATHS.lock, DISTRIBUTION_LIMITS.metadata);
|
|
308
|
+
if (portable)
|
|
309
|
+
decodeDistributionLock(utf8(portable)).packages.forEach((p) => referenced.add(p.archive));
|
|
310
|
+
const generations = contained(root, INSTALL_PATHS.generations);
|
|
311
|
+
if (existsSync(generations)) {
|
|
312
|
+
const entries = readdirSync(generations, { withFileTypes: true });
|
|
313
|
+
if (entries.length > 1024)
|
|
314
|
+
fail('LIMIT-EXCEEDED', 'Retained generation inventory exceeds 1024 entries');
|
|
315
|
+
for (const entry of entries) {
|
|
316
|
+
if (entry.isFile() && platformDebris(entry.name))
|
|
317
|
+
continue;
|
|
318
|
+
if (!entry.isDirectory() || entry.isSymbolicLink() || !/^[a-f0-9]{64}$/.test(entry.name))
|
|
319
|
+
fail('LOCAL-MODIFICATION', 'Unrecognized generation entry');
|
|
320
|
+
const generation = readInstalledGeneration(root, {
|
|
321
|
+
formatVersion: 1,
|
|
322
|
+
generation: entry.name,
|
|
323
|
+
previous: null,
|
|
324
|
+
counter: 1,
|
|
325
|
+
});
|
|
326
|
+
generation.lock.packages.forEach((p) => referenced.add(p.archive));
|
|
327
|
+
retained.push(entry.name);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const candidates = [], cache = contained(root, ARCHIVE_CACHE);
|
|
331
|
+
if (existsSync(cache))
|
|
332
|
+
for (const entry of readdirSync(cache, { withFileTypes: true })) {
|
|
333
|
+
if (entry.isFile() && platformDebris(entry.name))
|
|
334
|
+
continue;
|
|
335
|
+
const match = CACHED_ARCHIVE_NAME.exec(entry.name);
|
|
336
|
+
if (!match || !entry.isFile() || entry.isSymbolicLink())
|
|
337
|
+
fail('LOCAL-MODIFICATION', 'Unrecognized cache entry');
|
|
338
|
+
const archive = match[1];
|
|
339
|
+
if (referenced.has(archive))
|
|
340
|
+
continue;
|
|
341
|
+
const archivePath = cachePath(archive), content = bytes(root, archivePath, DISTRIBUTION_LIMITS.compressed), artifact = verifyArchive(content, archive), paths = [], dirs = new Set(), hashes = new Map();
|
|
342
|
+
const directory = `${INSTALL_PATHS.store}/${archive}`;
|
|
343
|
+
if (existsSync(contained(root, directory))) {
|
|
344
|
+
readExpandedBundle(root, {
|
|
345
|
+
id: artifact.manifest.id,
|
|
346
|
+
version: artifact.manifest.version,
|
|
347
|
+
archive,
|
|
348
|
+
manifest: artifact.manifestDigest,
|
|
349
|
+
location: `sha256:${archive}`,
|
|
350
|
+
dependencies: artifact.manifest.dependencies.map((d) => d.id),
|
|
351
|
+
});
|
|
352
|
+
for (const file of [...artifact.manifest.files.map((f) => f.path), 'distribution.json']) {
|
|
353
|
+
const path = `${directory}/${file}`;
|
|
354
|
+
paths.push(path);
|
|
355
|
+
hashes.set(path, sha256(bytes(root, path, DISTRIBUTION_LIMITS.file)));
|
|
356
|
+
const parts = path.split('/');
|
|
357
|
+
while (parts.length > 4) {
|
|
358
|
+
parts.pop();
|
|
359
|
+
dirs.add(parts.join('/'));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
dirs.add(directory);
|
|
363
|
+
}
|
|
364
|
+
paths.push(archivePath);
|
|
365
|
+
hashes.set(archivePath, sha256(content));
|
|
366
|
+
candidates.push({ archive, paths, dirs: [...dirs].sort((a, b) => b.length - a.length), hashes });
|
|
367
|
+
}
|
|
368
|
+
if (apply) {
|
|
369
|
+
if (json(state(root)) !== json(binding))
|
|
370
|
+
fail('STALE-PLAN', 'Workspace changed during garbage collection planning');
|
|
371
|
+
// Preflight the complete deletion set before removing a single owned file.
|
|
372
|
+
for (const candidate of candidates)
|
|
373
|
+
for (const path of candidate.paths)
|
|
374
|
+
if (sha256(bytes(root, path, DISTRIBUTION_LIMITS.compressed)) !== candidate.hashes.get(path))
|
|
375
|
+
fail('LOCAL-MODIFICATION', 'Garbage collection target changed');
|
|
376
|
+
// The Finder and AppleDouble files the readers skipped go with the directory they sit in, or it would outlive its archive (#323).
|
|
377
|
+
for (const candidate of candidates) {
|
|
378
|
+
for (const path of candidate.paths)
|
|
379
|
+
replace(root, path, null);
|
|
380
|
+
for (const dir of candidate.dirs) {
|
|
381
|
+
const target = contained(root, dir);
|
|
382
|
+
if (!existsSync(target))
|
|
383
|
+
continue;
|
|
384
|
+
for (const entry of readdirSync(target, { withFileTypes: true }))
|
|
385
|
+
if (entry.isFile() && platformDebris(entry.name) && lstatSync(join(target, entry.name)).isFile())
|
|
386
|
+
unlinkSync(join(target, entry.name));
|
|
387
|
+
if (readdirSync(target).length === 0)
|
|
388
|
+
rmdirSync(target);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return {
|
|
393
|
+
status: apply ? 'collected' : 'planned',
|
|
394
|
+
archives: candidates.map((c) => c.archive).sort(),
|
|
395
|
+
retainedGenerations: retained.sort(),
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
finally {
|
|
399
|
+
release();
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
//# sourceMappingURL=install.js.map
|