@sublang/spex 4.2.0 → 6.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.
Files changed (100) hide show
  1. package/README.md +438 -89
  2. package/dist/cli.js +80 -42
  3. package/dist/commands/add.d.ts +12 -0
  4. package/dist/commands/add.js +138 -0
  5. package/dist/commands/auth-target.d.ts +12 -0
  6. package/dist/commands/auth-target.js +52 -0
  7. package/dist/commands/environment.d.ts +117 -0
  8. package/dist/commands/environment.js +399 -0
  9. package/dist/commands/export.d.ts +21 -0
  10. package/dist/commands/export.js +663 -0
  11. package/dist/commands/home.d.ts +56 -0
  12. package/dist/commands/home.js +215 -0
  13. package/dist/commands/install.d.ts +2 -0
  14. package/dist/commands/install.js +48 -0
  15. package/dist/commands/list.d.ts +2 -0
  16. package/dist/commands/list.js +87 -0
  17. package/dist/commands/login.d.ts +2 -0
  18. package/dist/commands/login.js +211 -0
  19. package/dist/commands/logout.d.ts +2 -0
  20. package/dist/commands/logout.js +74 -0
  21. package/dist/commands/publish.d.ts +2 -0
  22. package/dist/commands/publish.js +120 -0
  23. package/dist/commands/remove.d.ts +2 -0
  24. package/dist/commands/remove.js +34 -0
  25. package/dist/commands/run.d.ts +50 -0
  26. package/dist/commands/run.js +312 -0
  27. package/dist/commands/search.d.ts +2 -0
  28. package/dist/commands/search.js +34 -0
  29. package/dist/commands/settle.d.ts +124 -0
  30. package/dist/commands/settle.js +475 -0
  31. package/dist/commands/update.d.ts +2 -0
  32. package/dist/commands/update.js +37 -0
  33. package/dist/commands/whoami.d.ts +2 -0
  34. package/dist/commands/whoami.js +71 -0
  35. package/dist/lib/environment/agent-folders.d.ts +14 -0
  36. package/dist/lib/environment/agent-folders.js +11 -0
  37. package/dist/lib/environment/archive.d.ts +39 -0
  38. package/dist/lib/environment/archive.js +122 -0
  39. package/dist/lib/environment/builtins.d.ts +112 -0
  40. package/dist/lib/environment/builtins.js +539 -0
  41. package/dist/lib/environment/citations.d.ts +75 -0
  42. package/dist/lib/environment/citations.js +267 -0
  43. package/dist/lib/environment/exports.d.ts +190 -0
  44. package/dist/lib/environment/exports.js +1029 -0
  45. package/dist/lib/environment/format.d.ts +133 -0
  46. package/dist/lib/environment/format.js +651 -0
  47. package/dist/lib/environment/git-source.d.ts +41 -0
  48. package/dist/lib/environment/git-source.js +159 -0
  49. package/dist/lib/environment/index.d.ts +20 -0
  50. package/dist/lib/environment/index.js +27 -0
  51. package/dist/lib/environment/install.d.ts +140 -0
  52. package/dist/lib/environment/install.js +694 -0
  53. package/dist/lib/environment/layout.d.ts +15 -0
  54. package/dist/lib/environment/layout.js +50 -0
  55. package/dist/lib/environment/lock.d.ts +87 -0
  56. package/dist/lib/environment/lock.js +305 -0
  57. package/dist/lib/environment/marker.d.ts +15 -0
  58. package/dist/lib/environment/marker.js +31 -0
  59. package/dist/lib/environment/own-paths.d.ts +59 -0
  60. package/dist/lib/environment/own-paths.js +174 -0
  61. package/dist/lib/environment/placed-record.d.ts +32 -0
  62. package/dist/lib/environment/placed-record.js +72 -0
  63. package/dist/lib/environment/registries.d.ts +23 -0
  64. package/dist/lib/environment/registries.js +48 -0
  65. package/dist/lib/environment/registry.d.ts +172 -0
  66. package/dist/lib/environment/registry.js +390 -0
  67. package/dist/lib/environment/requests.d.ts +109 -0
  68. package/dist/lib/environment/requests.js +401 -0
  69. package/dist/lib/environment/resolve.d.ts +70 -0
  70. package/dist/lib/environment/resolve.js +451 -0
  71. package/dist/lib/environment/semver.d.ts +30 -0
  72. package/dist/lib/environment/semver.js +130 -0
  73. package/dist/lib/environment/store.d.ts +23 -0
  74. package/dist/lib/environment/store.js +123 -0
  75. package/dist/lib/environment/tar.d.ts +27 -0
  76. package/dist/lib/environment/tar.js +219 -0
  77. package/dist/lib/files.d.ts +66 -0
  78. package/dist/lib/files.js +233 -0
  79. package/dist/lib/git-host.d.ts +579 -0
  80. package/dist/lib/git-host.js +1363 -0
  81. package/dist/lib/home-file.d.ts +124 -0
  82. package/dist/lib/home-file.js +288 -0
  83. package/dist/lib/instance.d.ts +63 -0
  84. package/dist/lib/instance.js +130 -0
  85. package/dist/lib/words.d.ts +32 -0
  86. package/dist/lib/words.js +27 -0
  87. package/dist/lint.js +8 -0
  88. package/dist/testing/index.d.ts +1 -0
  89. package/dist/testing/index.js +7 -0
  90. package/dist/testing/standin-registry.d.ts +94 -0
  91. package/dist/testing/standin-registry.js +449 -0
  92. package/package.json +37 -3
  93. package/dist/attached-cli.d.ts +0 -13
  94. package/dist/attached-cli.js +0 -249
  95. package/dist/attached-client.d.ts +0 -53
  96. package/dist/attached-client.js +0 -237
  97. package/dist/generated-protocol.d.ts +0 -2
  98. package/dist/generated-protocol.js +0 -6
  99. package/dist/package-init.d.ts +0 -21
  100. package/dist/package-init.js +0 -442
@@ -0,0 +1,15 @@
1
+ /** The folder at an environment's root holding what Spex installs and
2
+ * generates for it (environments-26). */
3
+ export declare const SPEX_DIR = ".spex";
4
+ /** `<root>/.spex/`. */
5
+ export declare function spexDir(root: string): string;
6
+ /** `<root>/.spex/packages/`: the installed spec packages and the install
7
+ * record (environments-7). */
8
+ export declare function installedDir(root: string): string;
9
+ /** `<root>/.spex/skills/`: the generated and copied skills an export
10
+ * mirrors into agent folders (environments-8). */
11
+ export declare function skillsDir(root: string): string;
12
+ /** Make `<root>/.spex/` with its `.gitignore` of one line, `*`, so Git
13
+ * ignores everything in it (environments-26). The root itself is never
14
+ * made: one gone meanwhile fails here. */
15
+ export declare function ensureSpexDir(root: string): string;
@@ -0,0 +1,50 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
+ // An environment's layout at its root (environments-26, DR-165):
4
+ // `spex.yaml` and `spex.lock` at the root, and under `.spex/` what Spex
5
+ // installs and generates — the installed spec packages with their
6
+ // install record, and the skills an export mirrors — beside a
7
+ // `.gitignore` of `*`, so the reader commits the two files and Git never
8
+ // sees the installed tree.
9
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
10
+ import { join } from "node:path";
11
+ import { VersionConflictError } from "../files.js";
12
+ /** The folder at an environment's root holding what Spex installs and
13
+ * generates for it (environments-26). */
14
+ export const SPEX_DIR = ".spex";
15
+ /** `<root>/.spex/`. */
16
+ export function spexDir(root) {
17
+ return join(root, SPEX_DIR);
18
+ }
19
+ /** `<root>/.spex/packages/`: the installed spec packages and the install
20
+ * record (environments-7). */
21
+ export function installedDir(root) {
22
+ return join(root, SPEX_DIR, "packages");
23
+ }
24
+ /** `<root>/.spex/skills/`: the generated and copied skills an export
25
+ * mirrors into agent folders (environments-8). */
26
+ export function skillsDir(root) {
27
+ return join(root, SPEX_DIR, "skills");
28
+ }
29
+ const SPEX_GITIGNORE = "*\n";
30
+ /** Make `<root>/.spex/` with its `.gitignore` of one line, `*`, so Git
31
+ * ignores everything in it (environments-26). The root itself is never
32
+ * made: one gone meanwhile fails here. */
33
+ export function ensureSpexDir(root) {
34
+ const dir = spexDir(root);
35
+ if (!existsSync(root))
36
+ throw new VersionConflictError(root);
37
+ mkdirSync(dir, { recursive: true });
38
+ const ignore = join(dir, ".gitignore");
39
+ let current = null;
40
+ try {
41
+ current = readFileSync(ignore, "utf8");
42
+ }
43
+ catch {
44
+ current = null;
45
+ }
46
+ if (current !== SPEX_GITIGNORE)
47
+ writeFileSync(ignore, SPEX_GITIGNORE);
48
+ return dir;
49
+ }
50
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1,87 @@
1
+ import { type FileVersion } from "../files.js";
2
+ import { type Issue, type Manifest } from "./format.js";
3
+ /** A selected file as the lock records it. */
4
+ export interface LockedFile {
5
+ path: string;
6
+ sha256: string;
7
+ executable: boolean;
8
+ }
9
+ export type RegistrySourceLock = {
10
+ registry: string;
11
+ version: string;
12
+ checksum: string;
13
+ };
14
+ export type PathSourceLock = {
15
+ path: string;
16
+ version: string;
17
+ dependencies: Record<string, string>;
18
+ requires: Record<string, string[]>;
19
+ };
20
+ export type GitSourceLock = {
21
+ git: string;
22
+ commit: string;
23
+ path?: string;
24
+ };
25
+ export type SourceLock = RegistrySourceLock | PathSourceLock | GitSourceLock;
26
+ export interface LockedArtifact {
27
+ language: string | null;
28
+ fallback: boolean;
29
+ }
30
+ export interface Resolution {
31
+ source: SourceLock;
32
+ /** The spec packages that required it; `[]` for a direct request alone. */
33
+ requiredBy: string[];
34
+ artifacts: Record<string, LockedArtifact>;
35
+ files: LockedFile[];
36
+ /** Exported Agent Skills name to artifact id. */
37
+ exports: Record<string, string>;
38
+ }
39
+ export interface Lock {
40
+ format: 1;
41
+ /** SHA-256 of the `spex.yaml` this lock resolved. */
42
+ requests: string;
43
+ packages: Record<string, Resolution>;
44
+ }
45
+ export declare class LockError extends Error {
46
+ readonly issues: Issue[];
47
+ /** The format a lock from a newer Spex names, where it names one. */
48
+ readonly newerFormat?: number;
49
+ constructor(issues: Issue[], newerFormat?: number);
50
+ }
51
+ export declare function isRegistrySource(source: SourceLock): source is RegistrySourceLock;
52
+ export declare function isPathSource(source: SourceLock): source is PathSourceLock;
53
+ export declare function isGitSource(source: SourceLock): source is GitSourceLock;
54
+ /** The version a resolution stands at, where the lock records one. */
55
+ export declare function resolutionVersion(resolution: Resolution): string | undefined;
56
+ /** A source as the lock writes it: its own fields, in one order. */
57
+ export declare function sourceValue(source: SourceLock): Record<string, unknown>;
58
+ /** The lock's bytes: fixed field order, names and paths sorted. */
59
+ export declare function serializeLock(lock: Lock): string;
60
+ /** Read a parsed `spex.lock` value, or throw. Reads `required-by` and
61
+ * the in-memory `requiredBy` alike. */
62
+ export declare function parseLockValue(raw: unknown): Lock;
63
+ export declare function parseLock(text: string): Lock;
64
+ /** Read `spex.lock`; null where there is none. */
65
+ export declare function readLock(file: string): Promise<Lock | null>;
66
+ /** Write `spex.lock` atomically, no folder made; returns the bytes
67
+ * written. Given the version the writer read, the write is refused as a
68
+ * conflict where the lock changed meanwhile (DR-111). */
69
+ export declare function writeLock(file: string, lock: Lock, expected?: FileVersion): Promise<string>;
70
+ /** The `requires` a path source's manifest states, as the lock keeps it. */
71
+ export declare function manifestRequires(manifest: Manifest): Record<string, string[]>;
72
+ export type Staleness = {
73
+ stale: false;
74
+ } | {
75
+ stale: true;
76
+ reasons: string[];
77
+ };
78
+ /** Whether a lock no longer stands (environments-7): its `requests`
79
+ * digest no longer matches `spex.yaml`, or a path source's manifest no
80
+ * longer states the version, dependencies and `requires` it recorded or
81
+ * lacks an artifact it selected. A path source missing on this device
82
+ * (`null`) is missing, not stale. Each reason is a phrase of a project's
83
+ * Packages tab (DR-172): a folder package "changed in" its folder, with
84
+ * what changed. */
85
+ export declare function lockStaleness(lock: Lock, requestsText: string | null, pathSources: (path: string) => Manifest | null): Staleness;
86
+ /** A content digest of the lock's bytes, for comparing two locks. */
87
+ export declare function lockDigest(lock: Lock): string;
@@ -0,0 +1,305 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
+ // The lock: a spex repository's `spex.lock` (environments-3, DR-104).
4
+ // Exactly `{format: 1, requests, packages}`: the digest of the
5
+ // `spex.yaml` it resolved, and per spec package the exact source, who
6
+ // required it, the selected artifacts with their languages, every
7
+ // selected file with its digest and executable flag, and the exported
8
+ // names. Written as YAML in one fixed order, so one resolution always
9
+ // writes the same bytes on every device.
10
+ import { existsSync } from "node:fs";
11
+ import { readFile } from "node:fs/promises";
12
+ import { Document, isMap, isSeq, parseDocument } from "yaml";
13
+ import { writeApplicationBytes, writeVersionedBytes } from "../files.js";
14
+ import { isPackageName, sha256Hex } from "./format.js";
15
+ import { requestsDigest } from "./requests.js";
16
+ export class LockError extends Error {
17
+ issues;
18
+ /** The format a lock from a newer Spex names, where it names one. */
19
+ newerFormat;
20
+ constructor(issues, newerFormat) {
21
+ super(newerFormat !== undefined
22
+ ? `spex.lock is from a newer Spex (format ${newerFormat})`
23
+ : `spex.lock cannot be read: ${issues.map((issue) => issue.message).join("; ")}`);
24
+ this.issues = issues;
25
+ this.name = "LockError";
26
+ if (newerFormat !== undefined)
27
+ this.newerFormat = newerFormat;
28
+ }
29
+ }
30
+ export function isRegistrySource(source) {
31
+ return "registry" in source;
32
+ }
33
+ export function isPathSource(source) {
34
+ return "path" in source && !("git" in source) && !("registry" in source);
35
+ }
36
+ export function isGitSource(source) {
37
+ return "git" in source;
38
+ }
39
+ /** The version a resolution stands at, where the lock records one. */
40
+ export function resolutionVersion(resolution) {
41
+ const source = resolution.source;
42
+ return isGitSource(source) ? undefined : source.version;
43
+ }
44
+ const byPath = (a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
45
+ const sortedKeys = (record) => Object.keys(record).sort();
46
+ /** A source as the lock writes it: its own fields, in one order. */
47
+ export function sourceValue(source) {
48
+ if (isRegistrySource(source))
49
+ return { registry: source.registry, version: source.version, checksum: source.checksum };
50
+ if (isGitSource(source))
51
+ return { git: source.git, commit: source.commit, ...(source.path !== undefined ? { path: source.path } : {}) };
52
+ const requires = {};
53
+ for (const id of sortedKeys(source.requires))
54
+ requires[id] = [...source.requires[id]];
55
+ const dependencies = {};
56
+ for (const name of sortedKeys(source.dependencies))
57
+ dependencies[name] = source.dependencies[name];
58
+ return { path: source.path, version: source.version, dependencies, requires };
59
+ }
60
+ /** The lock's bytes: fixed field order, names and paths sorted. */
61
+ export function serializeLock(lock) {
62
+ const packages = {};
63
+ for (const name of sortedKeys(lock.packages)) {
64
+ const resolution = lock.packages[name];
65
+ const artifacts = {};
66
+ for (const id of sortedKeys(resolution.artifacts)) {
67
+ const artifact = resolution.artifacts[id];
68
+ artifacts[id] = { language: artifact.language, fallback: artifact.fallback };
69
+ }
70
+ const exports = {};
71
+ for (const exported of sortedKeys(resolution.exports))
72
+ exports[exported] = resolution.exports[exported];
73
+ packages[name] = {
74
+ source: sourceValue(resolution.source),
75
+ "required-by": [...resolution.requiredBy].sort(),
76
+ artifacts,
77
+ files: [...resolution.files].sort(byPath).map((file) => ({ path: file.path, sha256: file.sha256, executable: file.executable })),
78
+ exports,
79
+ };
80
+ }
81
+ const doc = new Document({ format: 1, requests: lock.requests, packages });
82
+ // One line per file and per artifact keeps the lock short to read.
83
+ const packagesNode = doc.get("packages", true);
84
+ if (isMap(packagesNode)) {
85
+ for (const item of packagesNode.items) {
86
+ const resolution = item.value;
87
+ if (!isMap(resolution))
88
+ continue;
89
+ const files = resolution.get("files", true);
90
+ if (isSeq(files))
91
+ for (const file of files.items)
92
+ if (isMap(file))
93
+ file.flow = true;
94
+ const artifacts = resolution.get("artifacts", true);
95
+ if (isMap(artifacts))
96
+ for (const artifact of artifacts.items)
97
+ if (isMap(artifact.value))
98
+ artifact.value.flow = true;
99
+ for (const key of ["required-by"]) {
100
+ const node = resolution.get(key, true);
101
+ if (isSeq(node))
102
+ node.flow = true;
103
+ }
104
+ }
105
+ }
106
+ return doc.toString({ lineWidth: 0 });
107
+ }
108
+ function isPlainObject(value) {
109
+ return typeof value === "object" && value !== null && !Array.isArray(value);
110
+ }
111
+ function closed(value, keys, at, issues) {
112
+ for (const key of Object.keys(value))
113
+ if (!keys.includes(key))
114
+ issues.push({ path: at, rule: "field", message: `${at} has unknown field "${key}"` });
115
+ }
116
+ const isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
117
+ const isHex64 = (value) => typeof value === "string" && /^[0-9a-f]{64}$/.test(value);
118
+ function parseSource(raw, at, issues) {
119
+ if (!isPlainObject(raw)) {
120
+ issues.push({ path: at, rule: "source", message: `${at} is not a source` });
121
+ return undefined;
122
+ }
123
+ if ("registry" in raw) {
124
+ closed(raw, ["registry", "version", "checksum"], at, issues);
125
+ if (typeof raw.registry !== "string" || typeof raw.version !== "string" || typeof raw.checksum !== "string") {
126
+ issues.push({ path: at, rule: "source", message: `${at} is not {registry, version, checksum}` });
127
+ return undefined;
128
+ }
129
+ return { registry: raw.registry, version: raw.version, checksum: raw.checksum };
130
+ }
131
+ if ("git" in raw) {
132
+ closed(raw, ["git", "commit", "path"], at, issues);
133
+ if (typeof raw.git !== "string" || typeof raw.commit !== "string" || (raw.path !== undefined && typeof raw.path !== "string")) {
134
+ issues.push({ path: at, rule: "source", message: `${at} is not {git, commit, path?}` });
135
+ return undefined;
136
+ }
137
+ return { git: raw.git, commit: raw.commit, ...(typeof raw.path === "string" ? { path: raw.path } : {}) };
138
+ }
139
+ closed(raw, ["path", "version", "dependencies", "requires"], at, issues);
140
+ const dependencies = raw.dependencies ?? {};
141
+ const requires = raw.requires ?? {};
142
+ if (typeof raw.path !== "string" || typeof raw.version !== "string" || !isPlainObject(dependencies)
143
+ || !Object.values(dependencies).every((value) => typeof value === "string")
144
+ || !isPlainObject(requires) || !Object.values(requires).every(isStringArray)) {
145
+ issues.push({ path: at, rule: "source", message: `${at} is not {path, version, dependencies, requires}` });
146
+ return undefined;
147
+ }
148
+ return { path: raw.path, version: raw.version, dependencies: dependencies, requires: requires };
149
+ }
150
+ /** Read a parsed `spex.lock` value, or throw. Reads `required-by` and
151
+ * the in-memory `requiredBy` alike. */
152
+ export function parseLockValue(raw) {
153
+ const issues = [];
154
+ if (!isPlainObject(raw))
155
+ throw new LockError([{ rule: "lock", message: "it is not a mapping" }]);
156
+ if (typeof raw.format === "number" && Number.isInteger(raw.format) && raw.format > 1) {
157
+ throw new LockError([{ rule: "format", message: `spex.lock is from a newer Spex (format ${raw.format})` }], raw.format);
158
+ }
159
+ if (raw.format !== 1)
160
+ throw new LockError([{ rule: "format", message: `format ${JSON.stringify(raw.format ?? null)} is not format 1` }]);
161
+ closed(raw, ["format", "requests", "packages"], "spex.lock", issues);
162
+ if (typeof raw.requests !== "string")
163
+ issues.push({ rule: "requests", message: "requests is not a digest" });
164
+ const packages = {};
165
+ const rawPackages = raw.packages ?? {};
166
+ if (!isPlainObject(rawPackages))
167
+ issues.push({ rule: "packages", message: "packages is not a mapping" });
168
+ else {
169
+ for (const [name, value] of Object.entries(rawPackages)) {
170
+ const at = `packages.${name}`;
171
+ if (!isPackageName(name)) {
172
+ issues.push({ path: at, rule: "name", message: `"${name}" is not a <org>/<pkg> name` });
173
+ continue;
174
+ }
175
+ if (!isPlainObject(value)) {
176
+ issues.push({ path: at, rule: "resolution", message: `${at} is not a resolution` });
177
+ continue;
178
+ }
179
+ closed(value, ["source", "required-by", "requiredBy", "artifacts", "files", "exports"], at, issues);
180
+ const source = parseSource(value.source, `${at}.source`, issues);
181
+ const requiredBy = value["required-by"] ?? value.requiredBy ?? [];
182
+ if (!isStringArray(requiredBy))
183
+ issues.push({ path: at, rule: "required-by", message: `${at}.required-by is not a list of names` });
184
+ const artifacts = {};
185
+ if (!isPlainObject(value.artifacts))
186
+ issues.push({ path: at, rule: "artifacts", message: `${at}.artifacts is not a mapping` });
187
+ else
188
+ for (const [id, artifact] of Object.entries(value.artifacts)) {
189
+ if (!isPlainObject(artifact) || !(artifact.language === null || typeof artifact.language === "string") || typeof artifact.fallback !== "boolean") {
190
+ issues.push({ path: at, rule: "artifacts", message: `${at}.artifacts.${id} is not {language, fallback}` });
191
+ continue;
192
+ }
193
+ artifacts[id] = { language: artifact.language, fallback: artifact.fallback };
194
+ }
195
+ const files = [];
196
+ if (!Array.isArray(value.files))
197
+ issues.push({ path: at, rule: "files", message: `${at}.files is not a list` });
198
+ else
199
+ for (const file of value.files) {
200
+ if (!isPlainObject(file) || typeof file.path !== "string" || !isHex64(file.sha256) || typeof file.executable !== "boolean") {
201
+ issues.push({ path: at, rule: "files", message: `${at}.files holds an entry that is not {path, sha256, executable}` });
202
+ continue;
203
+ }
204
+ files.push({ path: file.path, sha256: file.sha256, executable: file.executable });
205
+ }
206
+ const exports = {};
207
+ if (!isPlainObject(value.exports ?? {}))
208
+ issues.push({ path: at, rule: "exports", message: `${at}.exports is not a mapping` });
209
+ else
210
+ for (const [exported, id] of Object.entries((value.exports ?? {}))) {
211
+ if (typeof id === "string")
212
+ exports[exported] = id;
213
+ else
214
+ issues.push({ path: at, rule: "exports", message: `${at}.exports.${exported} is not an artifact id` });
215
+ }
216
+ if (source && isStringArray(requiredBy))
217
+ packages[name] = { source, requiredBy: [...requiredBy], artifacts, files, exports };
218
+ }
219
+ }
220
+ if (issues.length > 0)
221
+ throw new LockError(issues);
222
+ return { format: 1, requests: raw.requests, packages };
223
+ }
224
+ export function parseLock(text) {
225
+ const doc = parseDocument(text, { prettyErrors: false, uniqueKeys: true });
226
+ if (doc.errors.length > 0)
227
+ throw new LockError(doc.errors.map((error) => ({ rule: "yaml", message: error.message })));
228
+ return parseLockValue(doc.toJS());
229
+ }
230
+ /** Read `spex.lock`; null where there is none. */
231
+ export async function readLock(file) {
232
+ if (!existsSync(file))
233
+ return null;
234
+ return parseLock(await readFile(file, "utf8"));
235
+ }
236
+ /** Write `spex.lock` atomically, no folder made; returns the bytes
237
+ * written. Given the version the writer read, the write is refused as a
238
+ * conflict where the lock changed meanwhile (DR-111). */
239
+ export async function writeLock(file, lock, expected) {
240
+ const text = serializeLock(lock);
241
+ if (expected === undefined)
242
+ writeApplicationBytes(file, text);
243
+ else
244
+ writeVersionedBytes(file, text, expected);
245
+ return text;
246
+ }
247
+ /** The `requires` a path source's manifest states, as the lock keeps it. */
248
+ export function manifestRequires(manifest) {
249
+ const requires = {};
250
+ for (const id of Object.keys(manifest.artifacts).sort()) {
251
+ const list = manifest.artifacts[id].requires;
252
+ if (list.length > 0)
253
+ requires[id] = [...list];
254
+ }
255
+ return requires;
256
+ }
257
+ const canonical = (value) => JSON.stringify(value, (_key, inner) => isPlainObject(inner) ? Object.fromEntries(Object.keys(inner).sort().map((key) => [key, inner[key]])) : inner);
258
+ /** Whether a lock no longer stands (environments-7): its `requests`
259
+ * digest no longer matches `spex.yaml`, or a path source's manifest no
260
+ * longer states the version, dependencies and `requires` it recorded or
261
+ * lacks an artifact it selected. A path source missing on this device
262
+ * (`null`) is missing, not stale. Each reason is a phrase of a project's
263
+ * Packages tab (DR-172): a folder package "changed in" its folder, with
264
+ * what changed. */
265
+ export function lockStaleness(lock, requestsText, pathSources) {
266
+ const reasons = [];
267
+ if (requestsText === null)
268
+ reasons.push("spex.yaml is missing");
269
+ else if (requestsDigest(requestsText) !== lock.requests)
270
+ reasons.push("spex.yaml changed");
271
+ for (const name of Object.keys(lock.packages).sort()) {
272
+ const resolution = lock.packages[name];
273
+ const source = resolution.source;
274
+ if (!isPathSource(source))
275
+ continue;
276
+ let manifest;
277
+ try {
278
+ manifest = pathSources(source.path);
279
+ }
280
+ catch (error) {
281
+ reasons.push(`${name} changed in ${source.path}: its meta.yaml cannot be read: ${error.message}`);
282
+ continue;
283
+ }
284
+ if (manifest === null)
285
+ continue;
286
+ if (`${manifest.org}/${manifest.name}` !== name)
287
+ reasons.push(`${name} changed in ${source.path}: it is now ${manifest.org}/${manifest.name}`);
288
+ if (manifest.version !== source.version)
289
+ reasons.push(`${name} changed in ${source.path}: version ${source.version} is now ${manifest.version}`);
290
+ if (canonical(manifest.dependencies) !== canonical(source.dependencies))
291
+ reasons.push(`${name} changed in ${source.path}: the packages it needs`);
292
+ if (canonical(manifestRequires(manifest)) !== canonical(source.requires))
293
+ reasons.push(`${name} changed in ${source.path}: what it needs installed`);
294
+ for (const id of Object.keys(resolution.artifacts).sort()) {
295
+ if (!manifest.artifacts[id])
296
+ reasons.push(`${name} changed in ${source.path}: it no longer has ${id}`);
297
+ }
298
+ }
299
+ return reasons.length > 0 ? { stale: true, reasons } : { stale: false };
300
+ }
301
+ /** A content digest of the lock's bytes, for comparing two locks. */
302
+ export function lockDigest(lock) {
303
+ return sha256Hex(serializeLock(lock));
304
+ }
305
+ //# sourceMappingURL=lock.js.map
@@ -0,0 +1,15 @@
1
+ /** The first line of a placed spec, derived from `<org>/<pkg>` at
2
+ * `version` (environments-41). */
3
+ export declare function placedMarker(name: string, version: string): string;
4
+ /** The package and version a file's first line names where it is the
5
+ * marker, a byte order mark and a carriage return disregarded; null for
6
+ * any other line. */
7
+ export declare function parsePlacedMarker(firstLine: string): {
8
+ name: string;
9
+ version: string;
10
+ } | null;
11
+ /** The marker on `text`'s first line, if any. */
12
+ export declare function readPlacedMarker(text: string): {
13
+ name: string;
14
+ version: string;
15
+ } | null;
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
+ // The marker a placed spec opens with (environments-41, lint-9,
4
+ // spec-view-10, DR-174): one comment line naming the spec package and
5
+ // the version the install derived the file from, so a reader, the
6
+ // linter and the spec view know a placed spec from the project's own
7
+ // without the install record, which a fresh clone lacks.
8
+ import { isPackageName } from "./format.js";
9
+ import { isVersion } from "./semver.js";
10
+ /** The first line of a placed spec, derived from `<org>/<pkg>` at
11
+ * `version` (environments-41). */
12
+ export function placedMarker(name, version) {
13
+ return `<!-- Placed by Spex from ${name} ${version}; an edit makes this file yours. -->`;
14
+ }
15
+ const MARKER = /^<!-- Placed by Spex from (\S+) (\S+); an edit makes this file yours\. -->$/;
16
+ /** The package and version a file's first line names where it is the
17
+ * marker, a byte order mark and a carriage return disregarded; null for
18
+ * any other line. */
19
+ export function parsePlacedMarker(firstLine) {
20
+ const match = MARKER.exec(firstLine.replace(/^/, "").replace(/\r$/, ""));
21
+ if (match === null)
22
+ return null;
23
+ const [, name, version] = match;
24
+ return isPackageName(name) && isVersion(version) ? { name, version } : null;
25
+ }
26
+ /** The marker on `text`'s first line, if any. */
27
+ export function readPlacedMarker(text) {
28
+ const end = text.indexOf("\n");
29
+ return parsePlacedMarker(end === -1 ? text : text.slice(0, end));
30
+ }
31
+ //# sourceMappingURL=marker.js.map
@@ -0,0 +1,59 @@
1
+ /** Why a folder of your own group's clone cannot be a path source; an
2
+ * `entry` or a `file` is its path in the clone. */
3
+ export type OwnPathIssue = {
4
+ reason: "root";
5
+ } | {
6
+ reason: "spex";
7
+ } | {
8
+ reason: "ignored";
9
+ } | {
10
+ reason: "link";
11
+ } | {
12
+ reason: "repository";
13
+ entry: string;
14
+ } | {
15
+ reason: "ignored_file";
16
+ file: string;
17
+ } | {
18
+ reason: "unshared_file";
19
+ file: string;
20
+ } | {
21
+ reason: "link_entry";
22
+ entry: string;
23
+ } | {
24
+ reason: "special";
25
+ entry: string;
26
+ } | {
27
+ reason: "unreadable";
28
+ entry: string;
29
+ };
30
+ /** The paths of `paths`, relative to the clone, its Git rules ignore —
31
+ * the managed rules, authored ones and this device's excludes alike —
32
+ * as Git reads them: a path Git tracks is never ignored, so a rule only
33
+ * this device's excludes hold refuses no file another device committed.
34
+ * A path ending `/` is read as a folder. A clone that is no repository
35
+ * yet ignores nothing. */
36
+ export declare function ignoredInClone(clone: string, paths: readonly string[]): string[];
37
+ /**
38
+ * The first reason `path` cannot name a path source of your own group's
39
+ * clone by what its path shows (environments-32): below the root,
40
+ * outside Spex's own paths, not ignored, reached through no link and in
41
+ * no Git repository of its own. Null where none: a folder not made yet
42
+ * is checked by these alone.
43
+ */
44
+ export declare function ownPathIssue(clone: string, path: string): OwnPathIssue | null;
45
+ /**
46
+ * The first reason the folder at `path`, standing in your own group's
47
+ * clone, holds what its sync drops or refuses (environments-32): a file
48
+ * of its release, `files` relative to the folder, the clone's Git rules
49
+ * ignore or of an ignored family a Save refuses to share (space-15); or,
50
+ * at any depth and where those rules do not ignore it, a Git repository
51
+ * of its own, a link, or an entry that is no regular file or folder.
52
+ * Null where none, or where the folder does not stand.
53
+ */
54
+ export declare function ownFolderIssue(clone: string, path: string, files: readonly string[]): OwnPathIssue | null;
55
+ /** A path your own group's clone refuses, in the library's words
56
+ * (environments-32), after the spec package's name: your own group is
57
+ * Personal and its clone your Personal records on every surface
58
+ * (DR-172); a host phrases the reason with what to do from the issue. */
59
+ export declare function ownPathMessage(name: string, path: string, issue: OwnPathIssue): string;