@sublang/spex 4.1.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +438 -54
- package/dist/cli.js +81 -31
- package/dist/commands/add.d.ts +12 -0
- package/dist/commands/add.js +138 -0
- package/dist/commands/auth-target.d.ts +11 -0
- package/dist/commands/auth-target.js +50 -0
- package/dist/commands/environment.d.ts +123 -0
- package/dist/commands/environment.js +411 -0
- package/dist/commands/export.d.ts +21 -0
- package/dist/commands/export.js +663 -0
- package/dist/commands/home.d.ts +56 -0
- package/dist/commands/home.js +215 -0
- package/dist/commands/install.d.ts +2 -0
- package/dist/commands/install.js +48 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.js +87 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.js +211 -0
- package/dist/commands/logout.d.ts +2 -0
- package/dist/commands/logout.js +74 -0
- package/dist/commands/publish.d.ts +2 -0
- package/dist/commands/publish.js +120 -0
- package/dist/commands/remove.d.ts +2 -0
- package/dist/commands/remove.js +34 -0
- package/dist/commands/run.d.ts +50 -0
- package/dist/commands/run.js +309 -0
- package/dist/commands/search.d.ts +2 -0
- package/dist/commands/search.js +34 -0
- package/dist/commands/settle.d.ts +124 -0
- package/dist/commands/settle.js +475 -0
- package/dist/commands/update.d.ts +2 -0
- package/dist/commands/update.js +37 -0
- package/dist/commands/whoami.d.ts +2 -0
- package/dist/commands/whoami.js +75 -0
- package/dist/lib/environment/agent-folders.d.ts +14 -0
- package/dist/lib/environment/agent-folders.js +11 -0
- package/dist/lib/environment/archive.d.ts +26 -0
- package/dist/lib/environment/archive.js +91 -0
- package/dist/lib/environment/builtins.d.ts +112 -0
- package/dist/lib/environment/builtins.js +539 -0
- package/dist/lib/environment/citations.d.ts +75 -0
- package/dist/lib/environment/citations.js +267 -0
- package/dist/lib/environment/exports.d.ts +190 -0
- package/dist/lib/environment/exports.js +1029 -0
- package/dist/lib/environment/format.d.ts +133 -0
- package/dist/lib/environment/format.js +651 -0
- package/dist/lib/environment/git-source.d.ts +41 -0
- package/dist/lib/environment/git-source.js +159 -0
- package/dist/lib/environment/index.d.ts +20 -0
- package/dist/lib/environment/index.js +27 -0
- package/dist/lib/environment/install.d.ts +140 -0
- package/dist/lib/environment/install.js +694 -0
- package/dist/lib/environment/layout.d.ts +15 -0
- package/dist/lib/environment/layout.js +50 -0
- package/dist/lib/environment/lock.d.ts +87 -0
- package/dist/lib/environment/lock.js +305 -0
- package/dist/lib/environment/marker.d.ts +15 -0
- package/dist/lib/environment/marker.js +31 -0
- package/dist/lib/environment/own-paths.d.ts +59 -0
- package/dist/lib/environment/own-paths.js +174 -0
- package/dist/lib/environment/placed-record.d.ts +32 -0
- package/dist/lib/environment/placed-record.js +72 -0
- package/dist/lib/environment/registries.d.ts +25 -0
- package/dist/lib/environment/registries.js +75 -0
- package/dist/lib/environment/registry.d.ts +173 -0
- package/dist/lib/environment/registry.js +390 -0
- package/dist/lib/environment/requests.d.ts +108 -0
- package/dist/lib/environment/requests.js +403 -0
- package/dist/lib/environment/resolve.d.ts +70 -0
- package/dist/lib/environment/resolve.js +451 -0
- package/dist/lib/environment/semver.d.ts +30 -0
- package/dist/lib/environment/semver.js +130 -0
- package/dist/lib/environment/store.d.ts +23 -0
- package/dist/lib/environment/store.js +123 -0
- package/dist/lib/environment/tar.d.ts +27 -0
- package/dist/lib/environment/tar.js +219 -0
- package/dist/lib/files.d.ts +66 -0
- package/dist/lib/files.js +233 -0
- package/dist/lib/git-host.d.ts +579 -0
- package/dist/lib/git-host.js +1363 -0
- package/dist/lib/home-file.d.ts +124 -0
- package/dist/lib/home-file.js +288 -0
- package/dist/lib/instance.d.ts +63 -0
- package/dist/lib/instance.js +130 -0
- package/dist/lib/words.d.ts +32 -0
- package/dist/lib/words.js +27 -0
- package/dist/lint.js +8 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/standin-registry.d.ts +94 -0
- package/dist/testing/standin-registry.js +449 -0
- package/package.json +37 -3
- package/dist/attached-cli.d.ts +0 -13
- package/dist/attached-cli.js +0 -247
- package/dist/attached-client.d.ts +0 -36
- package/dist/attached-client.js +0 -189
- package/dist/generated-protocol.d.ts +0 -2
- package/dist/generated-protocol.js +0 -6
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
// Your own group's requests by path (environments-32, DR-125): the path
|
|
4
|
+
// is relative to its clone's root, and names a folder below it that lies
|
|
5
|
+
// outside Spex's own paths, is reached through no link, lies in no Git
|
|
6
|
+
// repository of its own, and holds nothing the clone's sync drops or
|
|
7
|
+
// refuses — so the folder syncs with the clone to every device, and a
|
|
8
|
+
// sync takes it whole (storage-11).
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import { existsSync, lstatSync, readdirSync } from "node:fs";
|
|
11
|
+
import { join, posix } from "node:path";
|
|
12
|
+
import { portable } from "../files.js";
|
|
13
|
+
import { isInsidePath } from "./requests.js";
|
|
14
|
+
/** The first segments of the paths Spex keeps in a clone (storage-1):
|
|
15
|
+
* its records, its settings, its placement files (DR-128), its
|
|
16
|
+
* installed and exported files under `.spex/` (DR-165) and the former
|
|
17
|
+
* `packages/` and `skills/`, its device-local files and its root
|
|
18
|
+
* files. */
|
|
19
|
+
const SPEX_PATHS = new Set([
|
|
20
|
+
"config", "sessions", "intents", "authoring", "placements", ".spex", "packages", "skills", "local", ".git", ".spex-uploads",
|
|
21
|
+
"spex.yaml", "spex.lock", "project.json", ".gitignore", ".gitattributes", ".spex-apply.json",
|
|
22
|
+
]);
|
|
23
|
+
/** Whether a first segment names a path Spex keeps, compared without
|
|
24
|
+
* case after compatibility normalization, as a file system folding
|
|
25
|
+
* names would place it: `ſessions` and `Sessions` are `sessions`. */
|
|
26
|
+
function keptBySpex(name) {
|
|
27
|
+
const folded = name.normalize("NFKC").toLowerCase();
|
|
28
|
+
return SPEX_PATHS.has(folded) || folded.startsWith(".lock");
|
|
29
|
+
}
|
|
30
|
+
/** Whether a folder holds `.git` — a directory or a file pointing at
|
|
31
|
+
* one — making it a Git repository of its own. */
|
|
32
|
+
function holdsGit(dir) {
|
|
33
|
+
try {
|
|
34
|
+
lstatSync(join(dir, ".git"));
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** The paths of `paths`, relative to the clone, its Git rules ignore —
|
|
42
|
+
* the managed rules, authored ones and this device's excludes alike —
|
|
43
|
+
* as Git reads them: a path Git tracks is never ignored, so a rule only
|
|
44
|
+
* this device's excludes hold refuses no file another device committed.
|
|
45
|
+
* A path ending `/` is read as a folder. A clone that is no repository
|
|
46
|
+
* yet ignores nothing. */
|
|
47
|
+
export function ignoredInClone(clone, paths) {
|
|
48
|
+
if (paths.length === 0 || !existsSync(join(clone, ".git")))
|
|
49
|
+
return [];
|
|
50
|
+
const run = spawnSync("git", ["-C", clone, "check-ignore", "--stdin", "-z"], {
|
|
51
|
+
input: `${paths.join("\0")}\0`,
|
|
52
|
+
encoding: "utf8",
|
|
53
|
+
env: { ...process.env, LC_ALL: "C" },
|
|
54
|
+
});
|
|
55
|
+
// 1: nothing ignored; 0: some; anything else: Git could not tell.
|
|
56
|
+
if (run.status === 1)
|
|
57
|
+
return [];
|
|
58
|
+
if (run.status !== 0)
|
|
59
|
+
throw new Error(`Git could not read ${clone}'s rules: ${(run.stderr || String(run.error ?? "")).trim()}`);
|
|
60
|
+
return run.stdout.split("\0").filter(Boolean);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The first reason `path` cannot name a path source of your own group's
|
|
64
|
+
* clone by what its path shows (environments-32): below the root,
|
|
65
|
+
* outside Spex's own paths, not ignored, reached through no link and in
|
|
66
|
+
* no Git repository of its own. Null where none: a folder not made yet
|
|
67
|
+
* is checked by these alone.
|
|
68
|
+
*/
|
|
69
|
+
export function ownPathIssue(clone, path) {
|
|
70
|
+
if (!isInsidePath(path))
|
|
71
|
+
return { reason: "root" };
|
|
72
|
+
const folder = posix.normalize(path).replace(/\/+$/, "");
|
|
73
|
+
if (folder === "" || folder === ".")
|
|
74
|
+
return { reason: "root" };
|
|
75
|
+
const segments = folder.split("/");
|
|
76
|
+
const first = segments[0];
|
|
77
|
+
if (keptBySpex(first))
|
|
78
|
+
return { reason: "spex" };
|
|
79
|
+
// A link first: Git reads no rule for a path beyond one.
|
|
80
|
+
let current = clone;
|
|
81
|
+
let repository = null;
|
|
82
|
+
for (let index = 0; index < segments.length; index += 1) {
|
|
83
|
+
current = join(current, segments[index]);
|
|
84
|
+
let stat;
|
|
85
|
+
try {
|
|
86
|
+
stat = lstatSync(current);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
if (stat.isSymbolicLink())
|
|
92
|
+
return { reason: "link" };
|
|
93
|
+
if (repository === null && stat.isDirectory() && holdsGit(current))
|
|
94
|
+
repository = segments.slice(0, index + 1).join("/");
|
|
95
|
+
}
|
|
96
|
+
if (ignoredInClone(clone, [`${folder}/meta.yaml`]).length > 0)
|
|
97
|
+
return { reason: "ignored" };
|
|
98
|
+
if (repository !== null)
|
|
99
|
+
return { reason: "repository", entry: repository };
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The first reason the folder at `path`, standing in your own group's
|
|
104
|
+
* clone, holds what its sync drops or refuses (environments-32): a file
|
|
105
|
+
* of its release, `files` relative to the folder, the clone's Git rules
|
|
106
|
+
* ignore or of an ignored family a Save refuses to share (space-15); or,
|
|
107
|
+
* at any depth and where those rules do not ignore it, a Git repository
|
|
108
|
+
* of its own, a link, or an entry that is no regular file or folder.
|
|
109
|
+
* Null where none, or where the folder does not stand.
|
|
110
|
+
*/
|
|
111
|
+
export function ownFolderIssue(clone, path, files) {
|
|
112
|
+
const folder = posix.normalize(path).replace(/\/+$/, "");
|
|
113
|
+
const inClone = files.map((file) => `${folder}/${file}`);
|
|
114
|
+
const ignored = ignoredInClone(clone, inClone);
|
|
115
|
+
if (ignored.length > 0)
|
|
116
|
+
return { reason: "ignored_file", file: ignored[0] };
|
|
117
|
+
const unshared = inClone.find((file) => !portable(file));
|
|
118
|
+
if (unshared !== undefined)
|
|
119
|
+
return { reason: "unshared_file", file: unshared };
|
|
120
|
+
// Every entry, nothing skipped, read without following a link; a Git
|
|
121
|
+
// repository of its own is not entered, as Git enters none.
|
|
122
|
+
const found = [];
|
|
123
|
+
const walk = (rel) => {
|
|
124
|
+
let entries;
|
|
125
|
+
try {
|
|
126
|
+
entries = readdirSync(join(clone, ...rel.split("/")), { withFileTypes: true });
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
// Missing folders remain missing; every other failed inspection
|
|
130
|
+
// proves nothing about a standing subtree. Like a forbidden entry,
|
|
131
|
+
// it is harmless only where the clone's Git rules ignore it.
|
|
132
|
+
if (error.code !== "ENOENT")
|
|
133
|
+
found.push({ probe: `${rel}/`, issue: { reason: "unreadable", entry: rel } });
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
for (const entry of entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))) {
|
|
137
|
+
const child = `${rel}/${entry.name}`;
|
|
138
|
+
if (entry.isSymbolicLink())
|
|
139
|
+
found.push({ probe: child, issue: { reason: "link_entry", entry: child } });
|
|
140
|
+
else if (entry.isDirectory()) {
|
|
141
|
+
if (holdsGit(join(clone, ...child.split("/"))))
|
|
142
|
+
found.push({ probe: `${child}/`, issue: { reason: "repository", entry: child } });
|
|
143
|
+
else
|
|
144
|
+
walk(child);
|
|
145
|
+
}
|
|
146
|
+
else if (!entry.isFile())
|
|
147
|
+
found.push({ probe: child, issue: { reason: "special", entry: child } });
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
walk(folder);
|
|
151
|
+
if (found.length === 0)
|
|
152
|
+
return null;
|
|
153
|
+
const kept = new Set(ignoredInClone(clone, found.map((item) => item.probe)));
|
|
154
|
+
return found.find((item) => !kept.has(item.probe))?.issue ?? null;
|
|
155
|
+
}
|
|
156
|
+
/** A path your own group's clone refuses, in the library's words
|
|
157
|
+
* (environments-32), after the spec package's name: your own group is
|
|
158
|
+
* Personal and its clone your Personal records on every surface
|
|
159
|
+
* (DR-172); a host phrases the reason with what to do from the issue. */
|
|
160
|
+
export function ownPathMessage(name, path, issue) {
|
|
161
|
+
switch (issue.reason) {
|
|
162
|
+
case "root": return `${name}: ${path} is not a folder inside your Personal records`;
|
|
163
|
+
case "spex": return `${name}: ${path} is a folder Spex keeps in your Personal records`;
|
|
164
|
+
case "ignored": return `${name}: ${path} is ignored by Git in your Personal records, so it would not sync`;
|
|
165
|
+
case "link": return `${name}: ${path} is reached through a link, which your Personal records do not sync`;
|
|
166
|
+
case "repository": return `${name}: ${path}: ${issue.entry} is a Git repository of its own, which your Personal records do not sync`;
|
|
167
|
+
case "ignored_file": return `${name}: ${path} holds ${issue.file}, which Git ignores in your Personal records, so it would not sync`;
|
|
168
|
+
case "unshared_file": return `${name}: ${path} holds ${issue.file}, which your Personal records never share`;
|
|
169
|
+
case "link_entry": return `${name}: ${path}: ${issue.entry} is a link, which your Personal records do not sync`;
|
|
170
|
+
case "special": return `${name}: ${path}: ${issue.entry} is no regular file or folder, so your Personal records do not sync it`;
|
|
171
|
+
case "unreadable": return `${name}: ${path}: ${issue.entry} cannot be read to confirm it syncs with your Personal records`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=own-paths.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** The placed specs' record, beside the installed packages under
|
|
2
|
+
* `<root>/.spex/` (environments-26). */
|
|
3
|
+
export declare const PLACED_RECORD = "placed.json";
|
|
4
|
+
/** One placed spec: its path from the root, `specs/packages/<pkg>.md`,
|
|
5
|
+
* the version of the release it was derived from, the SHA-256 in hex of
|
|
6
|
+
* the bytes the install wrote there, and each package `<org>/<pkg>` its
|
|
7
|
+
* links wait for with their count (environments-41). */
|
|
8
|
+
export type PlacedSpec = {
|
|
9
|
+
path: string;
|
|
10
|
+
version: string;
|
|
11
|
+
sha256: string;
|
|
12
|
+
waiting: Record<string, number>;
|
|
13
|
+
};
|
|
14
|
+
/** The record of placed specs, keyed by spec package `<org>/<pkg>`. */
|
|
15
|
+
export type PlacedRecord = {
|
|
16
|
+
format: 1;
|
|
17
|
+
specs: Record<string, PlacedSpec>;
|
|
18
|
+
};
|
|
19
|
+
/** `<root>/.spex/placed.json`. */
|
|
20
|
+
export declare function placedRecordPath(root: string): string;
|
|
21
|
+
/** The root's record of placed specs, or null where none reads: a
|
|
22
|
+
* missing or unreadable file, one that is no JSON, a format other than 1,
|
|
23
|
+
* or an entry of another shape — so a reader never takes for placed what
|
|
24
|
+
* the record does not vouch for. */
|
|
25
|
+
export declare function readPlacedRecord(root: string): PlacedRecord | null;
|
|
26
|
+
/** The record's bytes as an install writes them: compact JSON, its
|
|
27
|
+
* specs in name order. */
|
|
28
|
+
export declare function serializePlacedRecord(record: PlacedRecord): string;
|
|
29
|
+
/** Write the root's record of placed specs whole, through a temporary
|
|
30
|
+
* file renamed into place, so a reader never finds it half-written.
|
|
31
|
+
* `<root>/.spex/` must stand. */
|
|
32
|
+
export declare function writePlacedRecord(root: string, record: PlacedRecord): void;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
// The install record of placed specs (environments-41, lint-9, DR-174):
|
|
4
|
+
// at `<root>/.spex/placed.json`, each provided spec an install placed
|
|
5
|
+
// under the root's `specs/`, by its spec package, with the path it
|
|
6
|
+
// stands at, the release's version, the SHA-256 of the bytes written and
|
|
7
|
+
// the packages its links wait for — so an install knows its own copy
|
|
8
|
+
// from an edited one, and the linter a placed spec from the project's
|
|
9
|
+
// own. An install writes it whole, atomically, as compact JSON.
|
|
10
|
+
import { readFileSync } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { writeApplicationBytes } from "../files.js";
|
|
13
|
+
import { SPEX_DIR } from "./layout.js";
|
|
14
|
+
/** The placed specs' record, beside the installed packages under
|
|
15
|
+
* `<root>/.spex/` (environments-26). */
|
|
16
|
+
export const PLACED_RECORD = "placed.json";
|
|
17
|
+
/** `<root>/.spex/placed.json`. */
|
|
18
|
+
export function placedRecordPath(root) {
|
|
19
|
+
return join(root, SPEX_DIR, PLACED_RECORD);
|
|
20
|
+
}
|
|
21
|
+
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22
|
+
function placedSpec(value) {
|
|
23
|
+
if (!isObject(value))
|
|
24
|
+
return null;
|
|
25
|
+
const { path, version, sha256, waiting } = value;
|
|
26
|
+
if (typeof path !== "string" || typeof version !== "string" || typeof sha256 !== "string" || !isObject(waiting))
|
|
27
|
+
return null;
|
|
28
|
+
const counts = Object.entries(waiting);
|
|
29
|
+
if (!counts.every(([, count]) => typeof count === "number" && Number.isInteger(count) && count >= 0))
|
|
30
|
+
return null;
|
|
31
|
+
return { path, version, sha256, waiting: Object.fromEntries(counts) };
|
|
32
|
+
}
|
|
33
|
+
/** The root's record of placed specs, or null where none reads: a
|
|
34
|
+
* missing or unreadable file, one that is no JSON, a format other than 1,
|
|
35
|
+
* or an entry of another shape — so a reader never takes for placed what
|
|
36
|
+
* the record does not vouch for. */
|
|
37
|
+
export function readPlacedRecord(root) {
|
|
38
|
+
let value;
|
|
39
|
+
try {
|
|
40
|
+
value = JSON.parse(readFileSync(placedRecordPath(root), "utf8"));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (!isObject(value) || value.format !== 1 || !isObject(value.specs))
|
|
46
|
+
return null;
|
|
47
|
+
const specs = [];
|
|
48
|
+
for (const [name, entry] of Object.entries(value.specs)) {
|
|
49
|
+
const spec = placedSpec(entry);
|
|
50
|
+
if (spec === null)
|
|
51
|
+
return null;
|
|
52
|
+
specs.push([name, spec]);
|
|
53
|
+
}
|
|
54
|
+
return { format: 1, specs: Object.fromEntries(specs) };
|
|
55
|
+
}
|
|
56
|
+
/** The record's bytes as an install writes them: compact JSON, its
|
|
57
|
+
* specs in name order. */
|
|
58
|
+
export function serializePlacedRecord(record) {
|
|
59
|
+
const specs = Object.keys(record.specs).sort().map((name) => {
|
|
60
|
+
const { path, version, sha256, waiting } = record.specs[name];
|
|
61
|
+
const counts = Object.keys(waiting).sort().map((other) => [other, waiting[other]]);
|
|
62
|
+
return [name, { path, version, sha256, waiting: Object.fromEntries(counts) }];
|
|
63
|
+
});
|
|
64
|
+
return JSON.stringify({ format: 1, specs: Object.fromEntries(specs) });
|
|
65
|
+
}
|
|
66
|
+
/** Write the root's record of placed specs whole, through a temporary
|
|
67
|
+
* file renamed into place, so a reader never finds it half-written.
|
|
68
|
+
* `<root>/.spex/` must stand. */
|
|
69
|
+
export function writePlacedRecord(root, record) {
|
|
70
|
+
writeApplicationBytes(placedRecordPath(root), serializePlacedRecord(record));
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=placed-record.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type RegistrySource } from "./registry.js";
|
|
2
|
+
/** One place an install asks, in order: an instance's registry by its
|
|
3
|
+
* canonical origin, or a recorded registry that names no instance's
|
|
4
|
+
* origin and so is never asked. */
|
|
5
|
+
export type InstallRegistry = {
|
|
6
|
+
origin: string;
|
|
7
|
+
} | {
|
|
8
|
+
unasked: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The order an install asks registries for a registry package's files
|
|
12
|
+
* (environments-7): `instance`, the environment's instance; `recorded`,
|
|
13
|
+
* the registry its lock records for the package; `signedIn`, the origin
|
|
14
|
+
* of every instance the home is signed in to, in the home's order.
|
|
15
|
+
* Independent mode instead asks only the pinned registry and explicitly
|
|
16
|
+
* trusted equivalents, keeping sign-in separate from package trust.
|
|
17
|
+
*/
|
|
18
|
+
export declare function installRegistryOrder(instance: string, recorded: string, signedIn: readonly string[], options?: {
|
|
19
|
+
independent?: boolean;
|
|
20
|
+
trusted?: readonly string[];
|
|
21
|
+
}): InstallRegistry[];
|
|
22
|
+
/** A registry a lock records under no instance's origin
|
|
23
|
+
* (environments-7): never asked, every call failing naming it, so an
|
|
24
|
+
* install no other registry serves says why this one was not asked. */
|
|
25
|
+
export declare function unaskedRegistry(url: string): RegistrySource;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
// Registry installs retain the exact source in the lock (DR-168).
|
|
4
|
+
// Legacy manifests retain their previous ordered fallback during migration;
|
|
5
|
+
// independent manifests never scan unrelated signed-in Spaces.
|
|
6
|
+
import { canonicalOrigin } from "../instance.js";
|
|
7
|
+
import { RegistryError } from "./registry.js";
|
|
8
|
+
/**
|
|
9
|
+
* The order an install asks registries for a registry package's files
|
|
10
|
+
* (environments-7): `instance`, the environment's instance; `recorded`,
|
|
11
|
+
* the registry its lock records for the package; `signedIn`, the origin
|
|
12
|
+
* of every instance the home is signed in to, in the home's order.
|
|
13
|
+
* Independent mode instead asks only the pinned registry and explicitly
|
|
14
|
+
* trusted equivalents, keeping sign-in separate from package trust.
|
|
15
|
+
*/
|
|
16
|
+
export function installRegistryOrder(instance, recorded, signedIn, options = {}) {
|
|
17
|
+
const out = [];
|
|
18
|
+
const asked = new Set();
|
|
19
|
+
const add = (origin) => {
|
|
20
|
+
if (asked.has(origin))
|
|
21
|
+
return;
|
|
22
|
+
asked.add(origin);
|
|
23
|
+
out.push({ origin });
|
|
24
|
+
};
|
|
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
|
+
try {
|
|
39
|
+
origin = canonicalOrigin(recorded);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
origin = null;
|
|
43
|
+
}
|
|
44
|
+
if (origin !== null)
|
|
45
|
+
add(origin);
|
|
46
|
+
else
|
|
47
|
+
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
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
/** A registry a lock records under no instance's origin
|
|
61
|
+
* (environments-7): never asked, every call failing naming it, so an
|
|
62
|
+
* install no other registry serves says why this one was not asked. */
|
|
63
|
+
export function unaskedRegistry(url) {
|
|
64
|
+
const unasked = (name) => Promise.reject(new RegistryError("unavailable", name, `${name}: spex.lock names its registry as ${JSON.stringify(url)}, which is no registry address, so it is not asked`, "unasked"));
|
|
65
|
+
return {
|
|
66
|
+
url,
|
|
67
|
+
index: (name) => unasked(name),
|
|
68
|
+
version: (name) => unasked(name),
|
|
69
|
+
file: (name) => unasked(name),
|
|
70
|
+
archive: (name) => unasked(name),
|
|
71
|
+
publish: (name) => unasked(name),
|
|
72
|
+
search: () => Promise.resolve([]),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=registries.js.map
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
export type RegistryErrorKind = "not_found" | "forbidden" | "unauthenticated" | "unavailable" | "unreadable" | "format" | "rejected";
|
|
2
|
+
export declare class RegistryError extends Error {
|
|
3
|
+
readonly kind: RegistryErrorKind;
|
|
4
|
+
/** The spec package the answer was about, where there is one. */
|
|
5
|
+
readonly packageName: string | undefined;
|
|
6
|
+
/** The registry's error code and issues, for a refused publish. */
|
|
7
|
+
readonly code?: string | undefined;
|
|
8
|
+
readonly details?: unknown[] | undefined;
|
|
9
|
+
/** The HTTP status the registry answered, where it answered one. */
|
|
10
|
+
readonly status?: number;
|
|
11
|
+
/** The registry that answered, by its URL, where one did. */
|
|
12
|
+
readonly registry?: string;
|
|
13
|
+
constructor(kind: RegistryErrorKind,
|
|
14
|
+
/** The spec package the answer was about, where there is one. */
|
|
15
|
+
packageName: string | undefined, message: string,
|
|
16
|
+
/** The registry's error code and issues, for a refused publish. */
|
|
17
|
+
code?: string | undefined, details?: unknown[] | undefined, answer?: {
|
|
18
|
+
status?: number;
|
|
19
|
+
registry?: string;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** A registry's URL as a reader reads it: its host, with its port where
|
|
23
|
+
* it names one. */
|
|
24
|
+
export declare function registryHost(url: string): string;
|
|
25
|
+
export interface IndexArtifact {
|
|
26
|
+
kind: string;
|
|
27
|
+
language?: string;
|
|
28
|
+
languages: string[];
|
|
29
|
+
}
|
|
30
|
+
export interface VersionIndexEntry {
|
|
31
|
+
version: string;
|
|
32
|
+
format: number;
|
|
33
|
+
published_at?: string;
|
|
34
|
+
checksum: string;
|
|
35
|
+
yanked: boolean;
|
|
36
|
+
suppressed: boolean;
|
|
37
|
+
dependencies: Record<string, string>;
|
|
38
|
+
artifacts: Record<string, IndexArtifact>;
|
|
39
|
+
}
|
|
40
|
+
export interface VersionIndex {
|
|
41
|
+
org: string;
|
|
42
|
+
name: string;
|
|
43
|
+
latest?: string | null;
|
|
44
|
+
versions: VersionIndexEntry[];
|
|
45
|
+
}
|
|
46
|
+
export interface ResourceArtifact extends IndexArtifact {
|
|
47
|
+
from?: string;
|
|
48
|
+
requires?: string[];
|
|
49
|
+
"generated-by"?: {
|
|
50
|
+
agent: string;
|
|
51
|
+
model: string;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export interface VersionResource {
|
|
55
|
+
org: string;
|
|
56
|
+
name: string;
|
|
57
|
+
version: string;
|
|
58
|
+
format: number;
|
|
59
|
+
description?: string;
|
|
60
|
+
license?: string;
|
|
61
|
+
repository?: string;
|
|
62
|
+
languages?: string[];
|
|
63
|
+
artifacts: Record<string, ResourceArtifact>;
|
|
64
|
+
dependencies: Record<string, string>;
|
|
65
|
+
checksum: string;
|
|
66
|
+
size?: number;
|
|
67
|
+
published_at?: string;
|
|
68
|
+
yanked: boolean;
|
|
69
|
+
suppressed: boolean;
|
|
70
|
+
files?: {
|
|
71
|
+
path: string;
|
|
72
|
+
size: number;
|
|
73
|
+
sha256: string;
|
|
74
|
+
executable: boolean;
|
|
75
|
+
}[];
|
|
76
|
+
dist?: {
|
|
77
|
+
tarball: string;
|
|
78
|
+
sha256: string;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export interface SearchResult {
|
|
82
|
+
name: string;
|
|
83
|
+
description: string;
|
|
84
|
+
versions: string[];
|
|
85
|
+
}
|
|
86
|
+
/** An org the signed-in person may publish to (environments-27): its
|
|
87
|
+
* name, its group's path in the instance, and the person's role there. */
|
|
88
|
+
export interface RegistryOrg {
|
|
89
|
+
provider?: string;
|
|
90
|
+
name: string;
|
|
91
|
+
path: string;
|
|
92
|
+
role: string;
|
|
93
|
+
}
|
|
94
|
+
/** How long the core waits for the registry's orgs (environments-27). */
|
|
95
|
+
export declare const ORGS_TIMEOUT_MS = 2000;
|
|
96
|
+
/** What resolving and installing read from a registry (environments-12),
|
|
97
|
+
* served by Spex Space, the stand-in and the built-in spec package alike. */
|
|
98
|
+
export interface RegistrySource {
|
|
99
|
+
/** The registry the lock names in a registry source. */
|
|
100
|
+
readonly url: string;
|
|
101
|
+
index(name: string): Promise<VersionIndex>;
|
|
102
|
+
version(name: string, version: string): Promise<VersionResource>;
|
|
103
|
+
file(name: string, version: string, path: string): Promise<Uint8Array>;
|
|
104
|
+
archive(name: string, version: string): Promise<Uint8Array>;
|
|
105
|
+
publish(name: string, version: string, tgz: Uint8Array): Promise<void>;
|
|
106
|
+
search(query: string): Promise<SearchResult[]>;
|
|
107
|
+
}
|
|
108
|
+
/** The only manifest format this client reads (DR-104 schema versions). */
|
|
109
|
+
export declare const KNOWN_FORMAT = 2;
|
|
110
|
+
/** Validate a version index answer, or throw `unreadable`. */
|
|
111
|
+
export declare function readVersionIndex(name: string, raw: unknown): VersionIndex;
|
|
112
|
+
/** Validate a version resource answer: a format this client does not
|
|
113
|
+
* know is refused naming it (environments-12). */
|
|
114
|
+
export declare function readVersionResource(name: string, version: string, raw: unknown): VersionResource;
|
|
115
|
+
/** The codes a registry refuses an instance's token with that sign that
|
|
116
|
+
* instance out (environments-12, git-host-4); `token_expired` is not one
|
|
117
|
+
* of them, an expired access secret being a failure of its call. */
|
|
118
|
+
export declare const SIGN_OUT_CODES: readonly string[];
|
|
119
|
+
export interface RegistryDescriptor {
|
|
120
|
+
origin: string;
|
|
121
|
+
displayName: string;
|
|
122
|
+
providers: string[];
|
|
123
|
+
}
|
|
124
|
+
export interface SpaceDirectoryEntry {
|
|
125
|
+
origin: string;
|
|
126
|
+
displayName: string;
|
|
127
|
+
signIn: string[];
|
|
128
|
+
}
|
|
129
|
+
export interface RegistryClientOptions {
|
|
130
|
+
url: string;
|
|
131
|
+
/** The app token of the instance the registry answers for, where the
|
|
132
|
+
* home is signed in there; a getter that throws fails the call as
|
|
133
|
+
* `unavailable`. */
|
|
134
|
+
token?: () => Promise<string | null>;
|
|
135
|
+
/** Told the token a call presented when the registry refused it with
|
|
136
|
+
* one of `SIGN_OUT_CODES`, before that call fails (environments-12):
|
|
137
|
+
* awaited; where it throws — the token no longer the instance's stored
|
|
138
|
+
* one (git-host-4) — the call fails with what it threw in place of the
|
|
139
|
+
* registry's words, still `unauthenticated`. */
|
|
140
|
+
refused?: (token: string, code: string) => void | Promise<void>;
|
|
141
|
+
fetch?: typeof fetch;
|
|
142
|
+
}
|
|
143
|
+
/** Spex Space over HTTP (environments-12). */
|
|
144
|
+
export declare class RegistryClient implements RegistrySource {
|
|
145
|
+
readonly url: string;
|
|
146
|
+
private readonly token?;
|
|
147
|
+
private readonly refused?;
|
|
148
|
+
private readonly fetcher;
|
|
149
|
+
constructor(options: RegistryClientOptions);
|
|
150
|
+
/** Public discovery never presents a stored credential. */
|
|
151
|
+
private discovery;
|
|
152
|
+
describe(): Promise<RegistryDescriptor>;
|
|
153
|
+
spaces(): Promise<SpaceDirectoryEntry[]>;
|
|
154
|
+
private request;
|
|
155
|
+
private json;
|
|
156
|
+
index(name: string): Promise<VersionIndex>;
|
|
157
|
+
version(name: string, version: string): Promise<VersionResource>;
|
|
158
|
+
file(name: string, version: string, path: string): Promise<Uint8Array>;
|
|
159
|
+
archive(name: string, version: string): Promise<Uint8Array>;
|
|
160
|
+
/** A publish's refusals name what the publisher can act on: an org
|
|
161
|
+
* not theirs, a version already there, or the registry's checks. */
|
|
162
|
+
publish(name: string, version: string, tgz: Uint8Array): Promise<void>;
|
|
163
|
+
/** The orgs the signed-in person may publish to (environments-27):
|
|
164
|
+
* `GET /api/v1/account/orgs` with the device's app token, read within
|
|
165
|
+
* the timeout; null for no answer — a refusal, any other status, a
|
|
166
|
+
* body not in its shape, a network failure, or none in time. */
|
|
167
|
+
orgs(timeoutMs?: number): Promise<RegistryOrg[] | null>;
|
|
168
|
+
private readOrgs;
|
|
169
|
+
/** Check publishing rights before a preview or upload. An unreadable
|
|
170
|
+
* answer is not an empty list: neither case authorizes publishing. */
|
|
171
|
+
checkPublishOrg(name: string, timeoutMs?: number): Promise<void>;
|
|
172
|
+
search(query: string): Promise<SearchResult[]>;
|
|
173
|
+
}
|