@sublang/spex 5.0.0 → 7.0.0-beta.2
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/README.md +453 -41
- package/dist/cli.js +12 -1
- package/dist/commands/add.d.ts +1 -1
- package/dist/commands/add.js +3 -3
- package/dist/commands/auth-target.d.ts +1 -0
- package/dist/commands/auth-target.js +4 -2
- package/dist/commands/environment.d.ts +15 -21
- package/dist/commands/environment.js +43 -57
- package/dist/commands/export.js +2 -2
- package/dist/commands/home.d.ts +2 -2
- package/dist/commands/home.js +3 -3
- package/dist/commands/list.js +1 -1
- package/dist/commands/login.js +12 -7
- package/dist/commands/logout.js +2 -3
- package/dist/commands/publish.js +16 -16
- package/dist/commands/remove.js +1 -1
- package/dist/commands/run.d.ts +1 -1
- package/dist/commands/run.js +22 -3
- package/dist/commands/search.js +1 -1
- package/dist/commands/settle.d.ts +1 -1
- package/dist/commands/settle.js +3 -3
- package/dist/commands/whoami.js +2 -6
- package/dist/guards/approval.d.ts +56 -0
- package/dist/guards/approval.js +158 -0
- package/dist/guards/checks.d.ts +207 -0
- package/dist/guards/checks.js +681 -0
- package/dist/guards/commands.d.ts +15 -0
- package/dist/guards/commands.js +313 -0
- package/dist/guards/copy.d.ts +67 -0
- package/dist/guards/copy.js +306 -0
- package/dist/guards/declaration.d.ts +45 -0
- package/dist/guards/declaration.js +224 -0
- package/dist/guards/files.d.ts +137 -0
- package/dist/guards/files.js +544 -0
- package/dist/guards/harness.d.ts +58 -0
- package/dist/guards/harness.js +420 -0
- package/dist/guards/items.d.ts +61 -0
- package/dist/guards/items.js +161 -0
- package/dist/guards/patch.d.ts +55 -0
- package/dist/guards/patch.js +258 -0
- package/dist/guards/processes.d.ts +49 -0
- package/dist/guards/processes.js +233 -0
- package/dist/guards/proofs.d.ts +88 -0
- package/dist/guards/proofs.js +503 -0
- package/dist/guards/records.d.ts +176 -0
- package/dist/guards/records.js +513 -0
- package/dist/guards/report.d.ts +26 -0
- package/dist/guards/report.js +492 -0
- package/dist/guards/runner.d.ts +42 -0
- package/dist/guards/runner.js +167 -0
- package/dist/guards/tla.d.ts +51 -0
- package/dist/guards/tla.js +352 -0
- package/dist/guards/tlapm.d.ts +81 -0
- package/dist/guards/tlapm.js +172 -0
- package/dist/guards/tlc.d.ts +191 -0
- package/dist/guards/tlc.js +457 -0
- package/dist/guards/translation.d.ts +66 -0
- package/dist/guards/translation.js +202 -0
- package/dist/guards/types.d.ts +185 -0
- package/dist/guards/types.js +437 -0
- package/dist/guards/verify.d.ts +290 -0
- package/dist/guards/verify.js +1191 -0
- package/dist/guards/xml.d.ts +18 -0
- package/dist/guards/xml.js +105 -0
- package/dist/lib/environment/archive.d.ts +16 -3
- package/dist/lib/environment/archive.js +39 -8
- package/dist/lib/environment/builtins.d.ts +10 -12
- package/dist/lib/environment/builtins.js +18 -20
- package/dist/lib/environment/exports.d.ts +14 -13
- package/dist/lib/environment/exports.js +31 -16
- package/dist/lib/environment/format.d.ts +2 -2
- package/dist/lib/environment/format.js +3 -3
- package/dist/lib/environment/git-source.js +6 -3
- package/dist/lib/environment/install.d.ts +14 -16
- package/dist/lib/environment/install.js +66 -61
- package/dist/lib/environment/lock.d.ts +4 -3
- package/dist/lib/environment/lock.js +6 -5
- package/dist/lib/environment/marker.js +1 -2
- package/dist/lib/environment/own-paths.d.ts +7 -10
- package/dist/lib/environment/own-paths.js +10 -13
- package/dist/lib/environment/placed-record.d.ts +3 -2
- package/dist/lib/environment/placed-record.js +5 -4
- package/dist/lib/environment/registries.d.ts +7 -9
- package/dist/lib/environment/registries.js +9 -36
- package/dist/lib/environment/registry.d.ts +6 -7
- package/dist/lib/environment/registry.js +12 -12
- package/dist/lib/environment/requests.d.ts +6 -5
- package/dist/lib/environment/requests.js +6 -8
- package/dist/lib/environment/resolve.d.ts +4 -4
- package/dist/lib/environment/resolve.js +3 -4
- package/dist/lib/environment/store.d.ts +34 -8
- package/dist/lib/environment/store.js +138 -43
- package/dist/lib/files.d.ts +72 -12
- package/dist/lib/files.js +200 -65
- package/dist/lib/git-host.d.ts +52 -258
- package/dist/lib/git-host.js +52 -265
- package/dist/lib/home-file.d.ts +13 -10
- package/dist/lib/home-file.js +28 -18
- package/dist/lib/instance.d.ts +1 -1
- package/dist/lib/instance.js +1 -1
- package/dist/lint.d.ts +22 -0
- package/dist/lint.js +36 -0
- package/dist/testing/standin-registry.js +1 -1
- package/package.json +7 -3
- package/scaffold/.file-history.json +14 -7
- package/scaffold/i18n/zh/source-pins.json +41 -0
- package/scaffold/i18n/zh/specs/decisions/000-spec-structure-format.md +0 -1
- package/scaffold/i18n/zh/specs/intents/000-spdx-headers.md +0 -1
- package/scaffold/i18n/zh/specs/map.md +0 -1
- package/scaffold/i18n/zh/specs/meta.md +18 -35
- package/scaffold/i18n/zh/specs/packages/git.md +0 -1
- package/scaffold/i18n/zh/specs/packages/licensing.md +0 -1
- package/scaffold/specs/meta.md +18 -3
- package/scripts/test-exit-guard.mjs +28 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type RegistrySource } from "./registry.js";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* origin and so is never asked. */
|
|
2
|
+
/** A pinned package registry, or an invalid address kept for an honest
|
|
3
|
+
* failure report without making a request. */
|
|
5
4
|
export type InstallRegistry = {
|
|
6
5
|
origin: string;
|
|
7
6
|
} | {
|
|
@@ -9,13 +8,12 @@ export type InstallRegistry = {
|
|
|
9
8
|
};
|
|
10
9
|
/**
|
|
11
10
|
* The order an install asks registries for a registry package's files
|
|
12
|
-
* (environments-7):
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* trusted equivalents, keeping sign-in separate from package trust.
|
|
11
|
+
* (environments-7): the registry its lock records and explicitly trusted
|
|
12
|
+
* equivalents. The former instance, signed-in list and independent
|
|
13
|
+
* option remain accepted for published API compatibility but confer no
|
|
14
|
+
* package trust or account authority.
|
|
17
15
|
*/
|
|
18
|
-
export declare function installRegistryOrder(
|
|
16
|
+
export declare function installRegistryOrder(_instance: string, recorded: string, _signedIn: readonly string[], options?: {
|
|
19
17
|
independent?: boolean;
|
|
20
18
|
trusted?: readonly string[];
|
|
21
19
|
}): InstallRegistry[];
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
3
|
// Registry installs retain the exact source in the lock (DR-168).
|
|
4
|
-
//
|
|
5
|
-
// independent manifests never scan unrelated signed-in Spaces.
|
|
4
|
+
// Package trust never follows the list of signed-in Spaces.
|
|
6
5
|
import { canonicalOrigin } from "../instance.js";
|
|
7
6
|
import { RegistryError } from "./registry.js";
|
|
8
7
|
/**
|
|
9
8
|
* The order an install asks registries for a registry package's files
|
|
10
|
-
* (environments-7):
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* trusted equivalents, keeping sign-in separate from package trust.
|
|
9
|
+
* (environments-7): the registry its lock records and explicitly trusted
|
|
10
|
+
* equivalents. The former instance, signed-in list and independent
|
|
11
|
+
* option remain accepted for published API compatibility but confer no
|
|
12
|
+
* package trust or account authority.
|
|
15
13
|
*/
|
|
16
|
-
export function installRegistryOrder(
|
|
14
|
+
export function installRegistryOrder(_instance, recorded, _signedIn, options = {}) {
|
|
17
15
|
const out = [];
|
|
18
16
|
const asked = new Set();
|
|
19
17
|
const add = (origin) => {
|
|
@@ -22,39 +20,14 @@ export function installRegistryOrder(instance, recorded, signedIn, options = {})
|
|
|
22
20
|
asked.add(origin);
|
|
23
21
|
out.push({ origin });
|
|
24
22
|
};
|
|
25
|
-
if (options.independent) {
|
|
26
|
-
try {
|
|
27
|
-
add(canonicalOrigin(recorded));
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
out.push({ unasked: recorded });
|
|
31
|
-
}
|
|
32
|
-
for (const origin of options.trusted ?? [])
|
|
33
|
-
add(canonicalOrigin(origin));
|
|
34
|
-
return out;
|
|
35
|
-
}
|
|
36
|
-
add(canonicalOrigin(instance));
|
|
37
|
-
let origin;
|
|
38
23
|
try {
|
|
39
|
-
|
|
24
|
+
add(canonicalOrigin(recorded));
|
|
40
25
|
}
|
|
41
26
|
catch {
|
|
42
|
-
origin = null;
|
|
43
|
-
}
|
|
44
|
-
if (origin !== null)
|
|
45
|
-
add(origin);
|
|
46
|
-
else
|
|
47
27
|
out.push({ unasked: recorded });
|
|
48
|
-
for (const entry of signedIn) {
|
|
49
|
-
let at;
|
|
50
|
-
try {
|
|
51
|
-
at = canonicalOrigin(entry);
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
add(at);
|
|
57
28
|
}
|
|
29
|
+
for (const origin of options.trusted ?? [])
|
|
30
|
+
add(canonicalOrigin(origin));
|
|
58
31
|
return out;
|
|
59
32
|
}
|
|
60
33
|
/** A registry a lock records under no instance's origin
|
|
@@ -112,8 +112,8 @@ export declare function readVersionIndex(name: string, raw: unknown): VersionInd
|
|
|
112
112
|
/** Validate a version resource answer: a format this client does not
|
|
113
113
|
* know is refused naming it (environments-12). */
|
|
114
114
|
export declare function readVersionResource(name: string, version: string, raw: unknown): VersionResource;
|
|
115
|
-
/** The codes
|
|
116
|
-
*
|
|
115
|
+
/** The codes that invalidate only the presented registry grant
|
|
116
|
+
* (environments-12); `token_expired` is not one
|
|
117
117
|
* of them, an expired access secret being a failure of its call. */
|
|
118
118
|
export declare const SIGN_OUT_CODES: readonly string[];
|
|
119
119
|
export interface RegistryDescriptor {
|
|
@@ -128,19 +128,18 @@ export interface SpaceDirectoryEntry {
|
|
|
128
128
|
}
|
|
129
129
|
export interface RegistryClientOptions {
|
|
130
130
|
url: string;
|
|
131
|
-
/** The
|
|
132
|
-
* home is signed in there; a getter that throws fails the call as
|
|
131
|
+
/** The independent registry grant; a getter that throws fails the call as
|
|
133
132
|
* `unavailable`. */
|
|
134
133
|
token?: () => Promise<string | null>;
|
|
135
134
|
/** Told the token a call presented when the registry refused it with
|
|
136
135
|
* one of `SIGN_OUT_CODES`, before that call fails (environments-12):
|
|
137
|
-
* awaited; where it throws — the token no longer the
|
|
138
|
-
* one
|
|
136
|
+
* awaited; where it throws — the token no longer the registry's stored
|
|
137
|
+
* one — the call fails with what it threw in place of the
|
|
139
138
|
* registry's words, still `unauthenticated`. */
|
|
140
139
|
refused?: (token: string, code: string) => void | Promise<void>;
|
|
141
140
|
fetch?: typeof fetch;
|
|
142
141
|
}
|
|
143
|
-
/**
|
|
142
|
+
/** The package service over HTTP (environments-12). */
|
|
144
143
|
export declare class RegistryClient implements RegistrySource {
|
|
145
144
|
readonly url: string;
|
|
146
145
|
private readonly token?;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
-
// The registry source (environments-12)
|
|
4
|
-
//
|
|
3
|
+
// The package registry source (environments-12), using its independent
|
|
4
|
+
// registry account. The version index carries every
|
|
5
5
|
// version with its dependencies and artifacts, so a dependency graph
|
|
6
6
|
// resolves from indexes alone; a version resource is read only for a
|
|
7
7
|
// version picked; files come by raw URL or the release archive, each
|
|
8
|
-
// verified by its digest elsewhere.
|
|
9
|
-
//
|
|
10
|
-
// in there; an answer refusing it as the instance's sign-out is reported
|
|
11
|
-
// with the token it refused (environments-12, DR-127).
|
|
8
|
+
// verified by its digest elsewhere. Registry-grant refusals are reported
|
|
9
|
+
// with the token refused and never affect Space grants.
|
|
12
10
|
import { canonicalOrigin } from "../instance.js";
|
|
13
11
|
import { isPackageName } from "./format.js";
|
|
14
12
|
export class RegistryError extends Error {
|
|
@@ -157,11 +155,11 @@ export function readVersionResource(name, version, raw) {
|
|
|
157
155
|
...(isPlainObject(raw.dist) && typeof raw.dist.tarball === "string" ? { dist: { tarball: raw.dist.tarball, sha256: String(raw.dist.sha256 ?? raw.checksum) } } : {}),
|
|
158
156
|
};
|
|
159
157
|
}
|
|
160
|
-
/** The codes
|
|
161
|
-
*
|
|
158
|
+
/** The codes that invalidate only the presented registry grant
|
|
159
|
+
* (environments-12); `token_expired` is not one
|
|
162
160
|
* of them, an expired access secret being a failure of its call. */
|
|
163
161
|
export const SIGN_OUT_CODES = ["invalid_token", "token_revoked", "reauth_required"];
|
|
164
|
-
/**
|
|
162
|
+
/** The package service over HTTP (environments-12). */
|
|
165
163
|
export class RegistryClient {
|
|
166
164
|
url;
|
|
167
165
|
token;
|
|
@@ -249,14 +247,16 @@ export class RegistryClient {
|
|
|
249
247
|
if (response.status === 410)
|
|
250
248
|
throw new RegistryError("not_found", name, `${about}withdrawn at ${host}`, code ?? "suppressed", undefined, answered);
|
|
251
249
|
if (response.status === 401) {
|
|
252
|
-
// A refusal answers the token this call presented
|
|
250
|
+
// A refusal answers the token this call presented; a
|
|
253
251
|
// hook that throws says why the call fails instead.
|
|
254
252
|
if (token && code !== undefined && SIGN_OUT_CODES.includes(code) && this.refused) {
|
|
255
253
|
try {
|
|
256
254
|
await this.refused(token, code);
|
|
257
255
|
}
|
|
258
256
|
catch (error) {
|
|
259
|
-
|
|
257
|
+
const refusal = new RegistryError("unauthenticated", name, `${about}${error instanceof Error ? error.message : String(error)}`, code, undefined, answered);
|
|
258
|
+
refusal.cause = error;
|
|
259
|
+
throw refusal;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
throw new RegistryError("unauthenticated", name, `${about}sign-in expired at ${host}`, code, undefined, answered);
|
|
@@ -347,7 +347,7 @@ export class RegistryClient {
|
|
|
347
347
|
return null;
|
|
348
348
|
orgs.push({ name: org.name, path: org.path, role: org.role, ...(typeof org.provider === "string" ? { provider: org.provider } : {}) });
|
|
349
349
|
}
|
|
350
|
-
return orgs;
|
|
350
|
+
return orgs.sort((a, b) => a.name.localeCompare(b.name));
|
|
351
351
|
})();
|
|
352
352
|
return Promise.race([asked, late]);
|
|
353
353
|
}
|
|
@@ -47,7 +47,7 @@ export declare function packageNameRefusal(name: string): string;
|
|
|
47
47
|
/** Whether a request path stays inside the working folder. */
|
|
48
48
|
export declare function isInsidePath(path: string): boolean;
|
|
49
49
|
/** Every reason a request for a name is refused (environments-2,
|
|
50
|
-
* environments-
|
|
50
|
+
* environments-65): a bad name, no or several sources, a malformed
|
|
51
51
|
* requirement, a path that is not relative or leads out of the folder
|
|
52
52
|
* it is relative to, a bad select or alias. */
|
|
53
53
|
export declare function requestIssues(name: string, request: unknown): Issue[];
|
|
@@ -67,9 +67,10 @@ export interface EnvironmentRegistry {
|
|
|
67
67
|
scope: AuthScope;
|
|
68
68
|
legacy: boolean;
|
|
69
69
|
}
|
|
70
|
-
/**
|
|
71
|
-
*
|
|
72
|
-
|
|
70
|
+
/** Package routing never inherits collaboration settings or grants.
|
|
71
|
+
* Existing locked sources keep their provenance when installed. The
|
|
72
|
+
* home argument remains for compatibility with published callers. */
|
|
73
|
+
export declare function environmentRegistry(requests: Pick<Requests, "space" | "registry"> | null, _home: Pick<HomeFile, "origin" | "instances">): EnvironmentRegistry;
|
|
73
74
|
/** Name a package registry without changing the Space binding. */
|
|
74
75
|
export declare function setRegistryIn(doc: Document, origin: string): void;
|
|
75
76
|
/** Parse `spex.yaml` text, or throw. */
|
|
@@ -99,7 +100,7 @@ export declare function editRequests(file: string, edit: (doc: Document) => void
|
|
|
99
100
|
text: string;
|
|
100
101
|
digest: string;
|
|
101
102
|
}>;
|
|
102
|
-
/** Set one package's request, or remove it with null (environments-
|
|
103
|
+
/** Set one package's request, or remove it with null (environments-65). */
|
|
103
104
|
export declare function setRequest(file: string, name: string, request: Request | null): Promise<{
|
|
104
105
|
requests: Requests;
|
|
105
106
|
text: string;
|
|
@@ -57,7 +57,7 @@ export function isInsidePath(path) {
|
|
|
57
57
|
}
|
|
58
58
|
const REQUEST_FIELDS = new Set(["version", "path", "git", "rev", "select", "alias"]);
|
|
59
59
|
/** Every reason a request for a name is refused (environments-2,
|
|
60
|
-
* environments-
|
|
60
|
+
* environments-65): a bad name, no or several sources, a malformed
|
|
61
61
|
* requirement, a path that is not relative or leads out of the folder
|
|
62
62
|
* it is relative to, a bad select or alias. */
|
|
63
63
|
export function requestIssues(name, request) {
|
|
@@ -227,12 +227,10 @@ export function environmentInstance(requests, home) {
|
|
|
227
227
|
}
|
|
228
228
|
/** The public package service used explicitly by new environments. */
|
|
229
229
|
export const PUBLIC_REGISTRY_ORIGIN = "https://spex.sublang.ai";
|
|
230
|
-
/**
|
|
231
|
-
*
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
return { origin: environmentInstance(requests, home), scope: "space", legacy: true };
|
|
235
|
-
}
|
|
230
|
+
/** Package routing never inherits collaboration settings or grants.
|
|
231
|
+
* Existing locked sources keep their provenance when installed. The
|
|
232
|
+
* home argument remains for compatibility with published callers. */
|
|
233
|
+
export function environmentRegistry(requests, _home) {
|
|
236
234
|
return { origin: canonicalOrigin(requests?.registry ?? PUBLIC_REGISTRY_ORIGIN), scope: "registry", legacy: false };
|
|
237
235
|
}
|
|
238
236
|
/** Name a package registry without changing the Space binding. */
|
|
@@ -377,7 +375,7 @@ export async function editRequests(file, edit) {
|
|
|
377
375
|
writeVersionedBytes(file, text, version);
|
|
378
376
|
return { requests, text, digest: requestsDigest(text) };
|
|
379
377
|
}
|
|
380
|
-
/** Set one package's request, or remove it with null (environments-
|
|
378
|
+
/** Set one package's request, or remove it with null (environments-65). */
|
|
381
379
|
export async function setRequest(file, name, request) {
|
|
382
380
|
if (request !== null) {
|
|
383
381
|
const issues = requestIssues(name, request);
|
|
@@ -26,11 +26,11 @@ export interface ResolveInput {
|
|
|
26
26
|
requestsText?: string;
|
|
27
27
|
registry: RegistrySource;
|
|
28
28
|
/** The folder a request's `path` is relative to (environments-2): the
|
|
29
|
-
* paired working folder's root, or
|
|
29
|
+
* paired working folder's root, or the global records repository's; null
|
|
30
30
|
* where this device has none. */
|
|
31
31
|
pathRoot: string | null;
|
|
32
|
-
/** Whether `pathRoot` is
|
|
33
|
-
* path name only a folder that syncs with it
|
|
32
|
+
/** Whether `pathRoot` is the global records repository, whose requests by
|
|
33
|
+
* path name only a folder that syncs with it. */
|
|
34
34
|
confined?: boolean;
|
|
35
35
|
git: GitSource;
|
|
36
36
|
/** The credential for a Git repository, where one applies. */
|
|
@@ -48,7 +48,7 @@ export type ResolveErrorKind = "no_working_folder" | "path_outside" | "path_conf
|
|
|
48
48
|
* the request's folder or Git repository at its revision; whether the
|
|
49
49
|
* folder itself is missing; the package a folder holds in place of the
|
|
50
50
|
* one asked; the issues of a `meta.yaml` that does not read; and the
|
|
51
|
-
* reason
|
|
51
|
+
* reason the global records repository refuses a folder. */
|
|
52
52
|
export interface ResolveErrorDetail {
|
|
53
53
|
path?: string;
|
|
54
54
|
git?: string;
|
|
@@ -52,8 +52,7 @@ function selectionHolds(selection, artifacts) {
|
|
|
52
52
|
return artifact !== undefined && (entry.language === undefined || artifact.languages.includes(entry.language));
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
/** A path
|
|
56
|
-
* (environments-32), with its reason for a host to phrase. */
|
|
55
|
+
/** A path the global records repository refuses, in the library's words, with its reason for a host to phrase. */
|
|
57
56
|
function confinedError(name, path, issue) {
|
|
58
57
|
return new ResolveError("path_confined", name, ownPathMessage(name, path, issue), { path, confined: issue });
|
|
59
58
|
}
|
|
@@ -96,7 +95,7 @@ async function loadFixed(name, request, input) {
|
|
|
96
95
|
if (real.startsWith("..") || isAbsolute(real))
|
|
97
96
|
throw new ResolveError("path_outside", name, `${name}: ${path} leads out of ${place} through a link`, { path });
|
|
98
97
|
const release = await readRequested(name, dir, path, { path });
|
|
99
|
-
//
|
|
98
|
+
// The global records repository syncs the files it tracks.
|
|
100
99
|
if (input.confined) {
|
|
101
100
|
const issue = ownFolderIssue(root, request.path, release.files.map((file) => file.path));
|
|
102
101
|
if (issue)
|
|
@@ -419,7 +418,7 @@ export async function resolve(input) {
|
|
|
419
418
|
.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))
|
|
420
419
|
: [];
|
|
421
420
|
// 4. Exports: one skill per provided skill and playbook under its
|
|
422
|
-
// id, and per provided spec under `<org>-<pkg>` (DR-
|
|
421
|
+
// id, and per provided spec under `<org>-<pkg>` (DR-174), or alias;
|
|
423
422
|
// a selected artifact its release does not provide — a sibling's
|
|
424
423
|
// support, or of a kind `provides` leaves out — is installed with the
|
|
425
424
|
// rest and placed nowhere, so its name clashes with none.
|
|
@@ -5,19 +5,45 @@ export declare class DigestError extends Error {
|
|
|
5
5
|
readonly what: string;
|
|
6
6
|
constructor(expected: string, actual: string, what: string);
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
export declare function storeKey(sha256: string, executable: boolean): string;
|
|
10
|
-
/** Every store entry the given locks select. */
|
|
8
|
+
/** Every stored file the given locks select, by digest. */
|
|
11
9
|
export declare function lockStoreKeys(locks: Iterable<Lock>): Set<string>;
|
|
12
10
|
export declare class ContentStore {
|
|
13
11
|
readonly root: string;
|
|
14
12
|
constructor(homeDir: string);
|
|
15
|
-
pathOf(sha256: string
|
|
16
|
-
has(sha256: string
|
|
13
|
+
pathOf(sha256: string): string;
|
|
14
|
+
has(sha256: string): boolean;
|
|
17
15
|
/** Store bytes under their digest, verified first; written once. */
|
|
18
|
-
put(bytes: Uint8Array, sha256: string,
|
|
19
|
-
/**
|
|
16
|
+
put(bytes: Uint8Array, sha256: string, what?: string): string;
|
|
17
|
+
/** Take a file's former copy under `x/` as the stored file where the
|
|
18
|
+
* store lacks it, verified as any bytes are (environments-7): whether
|
|
19
|
+
* the store now holds the file. A copy that does not match its digest
|
|
20
|
+
* is no stored file; one that cannot be taken for another reason is
|
|
21
|
+
* none here either, an install then fetching the file. */
|
|
22
|
+
adoptFormer(sha256: string): boolean;
|
|
23
|
+
/** `adoptFormer`, throwing where the copy stands and matches or cannot
|
|
24
|
+
* be read, yet cannot be stored: the store refusing the write, or the
|
|
25
|
+
* device full. False where no copy stands or it does not match. */
|
|
26
|
+
private takeFormer;
|
|
27
|
+
/** Every stored file's digest. */
|
|
20
28
|
keys(): string[];
|
|
21
|
-
/**
|
|
29
|
+
/** Copy a stored file to `to`, where no file stands, as an ordinary
|
|
30
|
+
* writable file, executable or not as the lock says, whatever the
|
|
31
|
+
* umask. The bytes are checked against their digest as they are read:
|
|
32
|
+
* a stored file that no longer matches is removed and nothing is
|
|
33
|
+
* written (environments-7). */
|
|
34
|
+
copy(sha256: string, executable: boolean, to: string, what?: string): void;
|
|
35
|
+
/** Remove every stored file no lock selects, read-only as it is, and
|
|
36
|
+
* the former `x/`, each of its copies a lock selects taken as the
|
|
37
|
+
* stored file first where the store lacks it — a lock whose install
|
|
38
|
+
* did not run, stale or with no folder here, keeps its bytes. A
|
|
39
|
+
* selected copy that could not be taken for another reason than its
|
|
40
|
+
* digest stands, with `x/`, for a later collection. Every step is
|
|
41
|
+
* tried whatever another's failure, and the failures are thrown once
|
|
42
|
+
* all are done; returns the removed digests (environments-7). */
|
|
22
43
|
gc(selected: Set<string>): string[];
|
|
44
|
+
/** The former `x/` at a collection: each copy a lock selects taken as
|
|
45
|
+
* the stored file, then removed with every copy no lock selects and
|
|
46
|
+
* every one that does not match its digest; one that could not be
|
|
47
|
+
* taken stands, its cause noted in `failures`, and `x/` with it. */
|
|
48
|
+
private collectFormer;
|
|
23
49
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
-
// The content-addressed store under the home (environments-7, DR-104
|
|
4
|
-
// each distinct file once, named by
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// The content-addressed store under the home (environments-7, DR-104,
|
|
4
|
+
// DR-251): a cache of verified bytes, each distinct file once, named by
|
|
5
|
+
// its SHA-256, written once after its digest is verified. An install
|
|
6
|
+
// copies a file out, its digest checked again as it is read, so an
|
|
7
|
+
// installed tree shares nothing with the store. A stored file is written
|
|
8
|
+
// read-only against an edit by mistake; nothing relies on that mark. A
|
|
9
|
+
// file stays while a lock of an environment the home knows selects it.
|
|
8
10
|
import { randomUUID } from "node:crypto";
|
|
9
|
-
import { chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readdirSync,
|
|
11
|
+
import { chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
10
12
|
import { join } from "node:path";
|
|
13
|
+
import { removeTree } from "../files.js";
|
|
11
14
|
import { sha256Hex } from "./format.js";
|
|
12
15
|
export class DigestError extends Error {
|
|
13
16
|
expected;
|
|
@@ -21,45 +24,43 @@ export class DigestError extends Error {
|
|
|
21
24
|
this.name = "DigestError";
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
|
-
/**
|
|
25
|
-
export function storeKey(sha256, executable) {
|
|
26
|
-
return executable ? `x/${sha256}` : sha256;
|
|
27
|
-
}
|
|
28
|
-
/** Every store entry the given locks select. */
|
|
27
|
+
/** Every stored file the given locks select, by digest. */
|
|
29
28
|
export function lockStoreKeys(locks) {
|
|
30
29
|
const keys = new Set();
|
|
31
30
|
for (const lock of locks) {
|
|
32
31
|
for (const resolution of Object.values(lock.packages)) {
|
|
33
32
|
for (const file of resolution.files)
|
|
34
|
-
keys.add(
|
|
33
|
+
keys.add(file.sha256);
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
return keys;
|
|
38
37
|
}
|
|
39
38
|
const SHA_RE = /^[0-9a-f]{64}$/;
|
|
39
|
+
/** Where an earlier release kept an executable file's own copy, links
|
|
40
|
+
* sharing one mode (DR-251). */
|
|
41
|
+
const FORMER_COPIES = "x";
|
|
40
42
|
export class ContentStore {
|
|
41
43
|
root;
|
|
42
44
|
constructor(homeDir) {
|
|
43
45
|
this.root = join(homeDir, "store");
|
|
44
46
|
}
|
|
45
|
-
pathOf(sha256
|
|
47
|
+
pathOf(sha256) {
|
|
46
48
|
if (!SHA_RE.test(sha256))
|
|
47
49
|
throw new Error(`"${sha256}" is not a SHA-256 digest`);
|
|
48
|
-
return
|
|
50
|
+
return join(this.root, sha256);
|
|
49
51
|
}
|
|
50
|
-
has(sha256
|
|
51
|
-
return existsSync(this.pathOf(sha256
|
|
52
|
+
has(sha256) {
|
|
53
|
+
return existsSync(this.pathOf(sha256));
|
|
52
54
|
}
|
|
53
55
|
/** Store bytes under their digest, verified first; written once. */
|
|
54
|
-
put(bytes, sha256,
|
|
55
|
-
const target = this.pathOf(sha256
|
|
56
|
+
put(bytes, sha256, what = "file") {
|
|
57
|
+
const target = this.pathOf(sha256);
|
|
56
58
|
const actual = sha256Hex(bytes);
|
|
57
59
|
if (actual !== sha256)
|
|
58
60
|
throw new DigestError(sha256, actual, what);
|
|
59
61
|
if (existsSync(target))
|
|
60
62
|
return target;
|
|
61
|
-
|
|
62
|
-
mkdirSync(dir, { recursive: true });
|
|
63
|
+
mkdirSync(this.root, { recursive: true });
|
|
63
64
|
const temporary = join(this.root, `.tmp-${randomUUID()}`);
|
|
64
65
|
const fd = openSync(temporary, "wx", 0o600);
|
|
65
66
|
try {
|
|
@@ -71,40 +72,105 @@ export class ContentStore {
|
|
|
71
72
|
finally {
|
|
72
73
|
closeSync(fd);
|
|
73
74
|
}
|
|
74
|
-
chmodSync(temporary,
|
|
75
|
+
chmodSync(temporary, 0o444);
|
|
75
76
|
if (existsSync(target))
|
|
76
|
-
|
|
77
|
+
removeTree(temporary);
|
|
77
78
|
else
|
|
78
79
|
renameSync(temporary, target);
|
|
79
80
|
return target;
|
|
80
81
|
}
|
|
81
|
-
/**
|
|
82
|
+
/** Take a file's former copy under `x/` as the stored file where the
|
|
83
|
+
* store lacks it, verified as any bytes are (environments-7): whether
|
|
84
|
+
* the store now holds the file. A copy that does not match its digest
|
|
85
|
+
* is no stored file; one that cannot be taken for another reason is
|
|
86
|
+
* none here either, an install then fetching the file. */
|
|
87
|
+
adoptFormer(sha256) {
|
|
88
|
+
try {
|
|
89
|
+
return this.takeFormer(sha256);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** `adoptFormer`, throwing where the copy stands and matches or cannot
|
|
96
|
+
* be read, yet cannot be stored: the store refusing the write, or the
|
|
97
|
+
* device full. False where no copy stands or it does not match. */
|
|
98
|
+
takeFormer(sha256) {
|
|
99
|
+
if (this.has(sha256))
|
|
100
|
+
return true;
|
|
101
|
+
let bytes;
|
|
102
|
+
try {
|
|
103
|
+
bytes = readFileSync(join(this.root, FORMER_COPIES, sha256));
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error.code === "ENOENT")
|
|
107
|
+
return false;
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
this.put(bytes, sha256);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
if (error instanceof DigestError)
|
|
115
|
+
return false;
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
/** Every stored file's digest. */
|
|
82
121
|
keys() {
|
|
83
|
-
const out = [];
|
|
84
122
|
if (!existsSync(this.root))
|
|
85
|
-
return
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
123
|
+
return [];
|
|
124
|
+
return readdirSync(this.root).filter((name) => SHA_RE.test(name));
|
|
125
|
+
}
|
|
126
|
+
/** Copy a stored file to `to`, where no file stands, as an ordinary
|
|
127
|
+
* writable file, executable or not as the lock says, whatever the
|
|
128
|
+
* umask. The bytes are checked against their digest as they are read:
|
|
129
|
+
* a stored file that no longer matches is removed and nothing is
|
|
130
|
+
* written (environments-7). */
|
|
131
|
+
copy(sha256, executable, to, what = "file") {
|
|
132
|
+
const from = this.pathOf(sha256);
|
|
133
|
+
const bytes = readFileSync(from);
|
|
134
|
+
const actual = sha256Hex(bytes);
|
|
135
|
+
if (actual !== sha256) {
|
|
136
|
+
removeTree(from);
|
|
137
|
+
throw new DigestError(sha256, actual, `the stored copy of ${what}`);
|
|
138
|
+
}
|
|
139
|
+
const mode = executable ? 0o755 : 0o644;
|
|
140
|
+
writeFileSync(to, bytes, { flag: "wx", mode });
|
|
141
|
+
chmodSync(to, mode);
|
|
95
142
|
}
|
|
96
|
-
/** Remove every
|
|
143
|
+
/** Remove every stored file no lock selects, read-only as it is, and
|
|
144
|
+
* the former `x/`, each of its copies a lock selects taken as the
|
|
145
|
+
* stored file first where the store lacks it — a lock whose install
|
|
146
|
+
* did not run, stale or with no folder here, keeps its bytes. A
|
|
147
|
+
* selected copy that could not be taken for another reason than its
|
|
148
|
+
* digest stands, with `x/`, for a later collection. Every step is
|
|
149
|
+
* tried whatever another's failure, and the failures are thrown once
|
|
150
|
+
* all are done; returns the removed digests (environments-7). */
|
|
97
151
|
gc(selected) {
|
|
98
152
|
const removed = [];
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
153
|
+
if (!existsSync(this.root))
|
|
154
|
+
return removed;
|
|
155
|
+
const failures = [];
|
|
156
|
+
const step = (run) => { try {
|
|
157
|
+
run();
|
|
104
158
|
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
failures.push(error);
|
|
161
|
+
} };
|
|
162
|
+
step(() => this.collectFormer(selected, failures));
|
|
163
|
+
step(() => {
|
|
164
|
+
for (const key of this.keys()) {
|
|
165
|
+
if (selected.has(key))
|
|
166
|
+
continue;
|
|
167
|
+
removeTree(join(this.root, key));
|
|
168
|
+
removed.push(key);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
105
171
|
// A temporary file an interrupted put left behind, once it is old
|
|
106
172
|
// enough not to be a put still running.
|
|
107
|
-
|
|
173
|
+
step(() => {
|
|
108
174
|
const before = Date.now() - 60 * 60 * 1000;
|
|
109
175
|
for (const name of readdirSync(this.root)) {
|
|
110
176
|
if (!name.startsWith(".tmp-"))
|
|
@@ -112,12 +178,41 @@ export class ContentStore {
|
|
|
112
178
|
const file = join(this.root, name);
|
|
113
179
|
try {
|
|
114
180
|
if (statSync(file).mtimeMs < before)
|
|
115
|
-
|
|
181
|
+
removeTree(file);
|
|
116
182
|
}
|
|
117
183
|
catch { /* gone */ }
|
|
118
184
|
}
|
|
119
|
-
}
|
|
185
|
+
});
|
|
186
|
+
if (failures.length === 1)
|
|
187
|
+
throw failures[0];
|
|
188
|
+
if (failures.length > 1)
|
|
189
|
+
throw new AggregateError(failures, failures.map((failure) => (failure instanceof Error ? failure.message : String(failure))).join("; "));
|
|
120
190
|
return removed;
|
|
121
191
|
}
|
|
192
|
+
/** The former `x/` at a collection: each copy a lock selects taken as
|
|
193
|
+
* the stored file, then removed with every copy no lock selects and
|
|
194
|
+
* every one that does not match its digest; one that could not be
|
|
195
|
+
* taken stands, its cause noted in `failures`, and `x/` with it. */
|
|
196
|
+
collectFormer(selected, failures) {
|
|
197
|
+
const former = join(this.root, FORMER_COPIES);
|
|
198
|
+
if (!existsSync(former))
|
|
199
|
+
return;
|
|
200
|
+
let kept = false;
|
|
201
|
+
for (const name of readdirSync(former)) {
|
|
202
|
+
if (selected.has(name)) {
|
|
203
|
+
try {
|
|
204
|
+
this.takeFormer(name);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
kept = true;
|
|
208
|
+
failures.push(new Error(`store/${FORMER_COPIES}/${name} stays, not taken as the stored file: ${error instanceof Error ? error.message : String(error)}`, { cause: error }));
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
removeTree(join(former, name));
|
|
213
|
+
}
|
|
214
|
+
if (!kept)
|
|
215
|
+
removeTree(former);
|
|
216
|
+
}
|
|
122
217
|
}
|
|
123
218
|
//# sourceMappingURL=store.js.map
|