@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,411 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
|
|
3
|
+
// The environment a package command acts on (cli-1, environments-26,
|
|
4
|
+
// DR-165): its root is the nearest folder, the current one included,
|
|
5
|
+
// holding `spex.yaml`, else the top level of the Git work tree the
|
|
6
|
+
// current folder lies in, else the current folder. Its instance is the
|
|
7
|
+
// `space` its `spex.yaml` names, else the home's default instance
|
|
8
|
+
// (environments-2). The home is `SPEX_HOME` else `~/.spex`, read with
|
|
9
|
+
// no folder check; the store and the cache are the ones the app's core
|
|
10
|
+
// uses under it, so both hosts share one store (environments-7). No
|
|
11
|
+
// clone, lease, session or record of the home is read or written: a
|
|
12
|
+
// root inside the home, other than a seat's project under `projects/`,
|
|
13
|
+
// is refused, as is the user's home folder, whose agent folders are the
|
|
14
|
+
// user-level ones your own group's export writes (environments-8).
|
|
15
|
+
import { spawnSync } from "node:child_process";
|
|
16
|
+
import { realpathSync, statSync } from "node:fs";
|
|
17
|
+
import { homedir } from "node:os";
|
|
18
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
19
|
+
import { builtinRegistrySource, compositeRegistry, ContentStore, environmentInstance, environmentRegistry, FormatError, gitSource, installRegistryOrder, LockError, parseLock, parseRequests, RegistryClient, RegistryError, RequestsError, unaskedRegistry, } from "../lib/environment/index.js";
|
|
20
|
+
import { readVersioned } from "../lib/files.js";
|
|
21
|
+
import { accountAt, instanceAt, updateHomeFile, withSignOut } from "../lib/home-file.js";
|
|
22
|
+
import { canonicalOrigin } from "../lib/instance.js";
|
|
23
|
+
import { clientOf, credentialsOf, defaultInstance, homeDir, hostCause, nameOf, readHome, registryName } from "./home.js";
|
|
24
|
+
import { Refusal } from "./run.js";
|
|
25
|
+
/** Where a path is on disk, spelled as the file system spells it: its
|
|
26
|
+
* nearest standing ancestor with every link resolved and every short
|
|
27
|
+
* name made long, and the rest as written. */
|
|
28
|
+
export function actualPath(path) {
|
|
29
|
+
const rest = [];
|
|
30
|
+
for (let current = resolve(path);; current = dirname(current)) {
|
|
31
|
+
try {
|
|
32
|
+
return join(realpathSync.native(current), ...rest.reverse());
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
if (dirname(current) === current)
|
|
36
|
+
return resolve(path);
|
|
37
|
+
rest.push(basename(current));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Whether `inner` is `outer` or lies below it. */
|
|
42
|
+
function within(outer, inner) {
|
|
43
|
+
const path = relative(outer, inner);
|
|
44
|
+
return path === "" || (path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path));
|
|
45
|
+
}
|
|
46
|
+
/** Why a folder cannot be an environment's root (cli-1), or null: the
|
|
47
|
+
* user's home folder, a folder inside the Spex home other than a seat's
|
|
48
|
+
* project below `projects/`, and a folder whose `.spex` holds the home. */
|
|
49
|
+
export function refusedRoot(dir, home) {
|
|
50
|
+
const at = actualPath(dir);
|
|
51
|
+
const spexHome = actualPath(home);
|
|
52
|
+
if (at === actualPath(homedir()))
|
|
53
|
+
return "is your home folder, where spex manages no packages";
|
|
54
|
+
if (within(spexHome, at) && !(within(join(spexHome, "projects"), at) && at !== join(spexHome, "projects"))) {
|
|
55
|
+
return `lies in the Spex home ${home}, which the app keeps`;
|
|
56
|
+
}
|
|
57
|
+
if (within(join(at, ".spex"), spexHome))
|
|
58
|
+
return `holds the Spex home ${home} as its .spex`;
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/** The environment root of a command run in `cwd` (cli-1), spelled as
|
|
62
|
+
* `cwd` is, so a path given from `cwd` compares with it as text. A
|
|
63
|
+
* `spex.yaml` in a folder that cannot be a root is passed over; a root
|
|
64
|
+
* that cannot be one refuses the command. */
|
|
65
|
+
export function environmentRoot(cwd = process.cwd(), home = homeDir()) {
|
|
66
|
+
const start = resolve(cwd);
|
|
67
|
+
let root = null;
|
|
68
|
+
for (let dir = start;; dir = dirname(dir)) {
|
|
69
|
+
if (isFile(join(dir, "spex.yaml")) && refusedRoot(dir, home) === null) {
|
|
70
|
+
root = dir;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
if (dirname(dir) === dir)
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
root ??= gitTopLevel(start) ?? start;
|
|
77
|
+
const refused = refusedRoot(root, home);
|
|
78
|
+
if (refused !== null)
|
|
79
|
+
throw new Refusal(`${root} ${refused} — run spex in a project folder`);
|
|
80
|
+
return root;
|
|
81
|
+
}
|
|
82
|
+
/** The top level of `start`'s Git work tree as Git names it, spelled as
|
|
83
|
+
* `start` is where the two are one folder. */
|
|
84
|
+
function spelledAs(start, top) {
|
|
85
|
+
const real = actualPath(top);
|
|
86
|
+
const path = relative(real, actualPath(start));
|
|
87
|
+
if (path === "")
|
|
88
|
+
return start;
|
|
89
|
+
if (path === ".." || path.startsWith(`..${sep}`) || isAbsolute(path))
|
|
90
|
+
return top;
|
|
91
|
+
const candidate = resolve(start, ...path.split(sep).map(() => ".."));
|
|
92
|
+
return actualPath(candidate) === real ? candidate : top;
|
|
93
|
+
}
|
|
94
|
+
function isFile(path) {
|
|
95
|
+
try {
|
|
96
|
+
return statSync(path).isFile();
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** The top level of the Git work tree `cwd` lies in; none where Git is
|
|
103
|
+
* absent or `cwd` lies in no work tree. */
|
|
104
|
+
function gitTopLevel(cwd) {
|
|
105
|
+
let result;
|
|
106
|
+
try {
|
|
107
|
+
result = spawnSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const top = result.status === 0 ? result.stdout.trim() : "";
|
|
113
|
+
return top === "" ? null : spelledAs(cwd, resolve(top));
|
|
114
|
+
}
|
|
115
|
+
/** A path under the root as a reader sees it, `/`-separated. */
|
|
116
|
+
export function shown(root, path) {
|
|
117
|
+
const inside = relative(root, path);
|
|
118
|
+
return inside === "" ? "." : inside.split(sep).join("/");
|
|
119
|
+
}
|
|
120
|
+
export class Environment {
|
|
121
|
+
root;
|
|
122
|
+
homeDir;
|
|
123
|
+
/** `home.yaml` as it stood when the command began; null where none. */
|
|
124
|
+
home;
|
|
125
|
+
requestsFile;
|
|
126
|
+
lockFile;
|
|
127
|
+
store;
|
|
128
|
+
cache;
|
|
129
|
+
git;
|
|
130
|
+
registries = new Map();
|
|
131
|
+
clients = new Map();
|
|
132
|
+
builtin;
|
|
133
|
+
constructor(cwd = process.cwd()) {
|
|
134
|
+
this.homeDir = homeDir();
|
|
135
|
+
this.root = environmentRoot(cwd, this.homeDir);
|
|
136
|
+
this.home = readHome(this.homeDir);
|
|
137
|
+
this.requestsFile = join(this.root, "spex.yaml");
|
|
138
|
+
this.lockFile = join(this.root, "spex.lock");
|
|
139
|
+
this.store = new ContentStore(this.homeDir);
|
|
140
|
+
this.cache = join(this.homeDir, "cache");
|
|
141
|
+
this.git = gitSource(this.cache);
|
|
142
|
+
}
|
|
143
|
+
/** `spex.yaml` as it stands, null where absent; one that does not read
|
|
144
|
+
* refuses the command saying why and what to do (environments-2,
|
|
145
|
+
* cli-13). */
|
|
146
|
+
readRequests() {
|
|
147
|
+
const { bytes, version } = readVersioned(this.requestsFile);
|
|
148
|
+
if (bytes === null)
|
|
149
|
+
return null;
|
|
150
|
+
const text = bytes.toString("utf8");
|
|
151
|
+
try {
|
|
152
|
+
return { requests: parseRequests(text), text, version };
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (error instanceof RequestsError && error.newerFormat !== undefined)
|
|
156
|
+
throw new Refusal("spex.yaml is from a newer Spex — update Spex");
|
|
157
|
+
// The same words as the Packages tab's (DR-172).
|
|
158
|
+
throw new Refusal(`${error.message} — fix the file, then retry`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** `spex.lock` as it stands, null where absent; one from a newer Spex,
|
|
162
|
+
* or one that does not read, refuses the command saying what to do
|
|
163
|
+
* (environments-3, cli-13): `spex update` writes it again, where the
|
|
164
|
+
* Packages tab, whose Update refuses a lock that does not read, says
|
|
165
|
+
* to remove it first. */
|
|
166
|
+
readLock() {
|
|
167
|
+
const read = this.readLockForUpdate();
|
|
168
|
+
if (read !== null && read.lock === null)
|
|
169
|
+
throw new Refusal(`${read.cause} — spex update rewrites it`);
|
|
170
|
+
return read;
|
|
171
|
+
}
|
|
172
|
+
/** `spex.lock` as `spex update` reads it: one that does not read stands
|
|
173
|
+
* with its version and no lock, for the update to rewrite under that
|
|
174
|
+
* version; one from a newer Spex still refuses the command, as this
|
|
175
|
+
* Spex would lose what it records. */
|
|
176
|
+
readLockForUpdate() {
|
|
177
|
+
const { bytes, version } = readVersioned(this.lockFile);
|
|
178
|
+
if (bytes === null)
|
|
179
|
+
return null;
|
|
180
|
+
const text = bytes.toString("utf8");
|
|
181
|
+
try {
|
|
182
|
+
return { lock: parseLock(text), text, version };
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error instanceof LockError && error.newerFormat !== undefined)
|
|
186
|
+
throw new Refusal("spex.lock is from a newer Spex — update Spex");
|
|
187
|
+
return { lock: null, text, version, cause: error.message };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/** The home's default instance (storage-2). */
|
|
191
|
+
defaultOrigin() {
|
|
192
|
+
return canonicalOrigin(defaultInstance(this.home).origin);
|
|
193
|
+
}
|
|
194
|
+
/** The environment's instance (environments-2): the `space` the
|
|
195
|
+
* requests name, else the home's default instance. */
|
|
196
|
+
instanceOf(requests) {
|
|
197
|
+
return environmentInstance(requests, { origin: defaultInstance(this.home).origin, instances: this.home?.instances ?? [] });
|
|
198
|
+
}
|
|
199
|
+
registryOf(requests) {
|
|
200
|
+
return environmentRegistry(requests, { origin: defaultInstance(this.home).origin, instances: this.home?.instances ?? [] });
|
|
201
|
+
}
|
|
202
|
+
/** A registry as the reader knows it (cli-22): its descriptor's
|
|
203
|
+
* display name, else its host; never a Space entry's name. */
|
|
204
|
+
registryName(origin) {
|
|
205
|
+
return registryName(this.homeDir, origin);
|
|
206
|
+
}
|
|
207
|
+
/** The login a registry call presents at an origin, for a refusal to
|
|
208
|
+
* name (cli-13): null where this computer holds no sign-in for that
|
|
209
|
+
* purpose there; undefined where it holds one whose login cannot be
|
|
210
|
+
* read now. A Space's login is its home entry's; a registry's is read
|
|
211
|
+
* from its account API. */
|
|
212
|
+
async loginAt(origin, scope) {
|
|
213
|
+
if (scope === "space")
|
|
214
|
+
return this.home ? accountAt(this.home, origin)?.login ?? null : null;
|
|
215
|
+
const credentials = credentialsOf(this.homeDir, origin, scope);
|
|
216
|
+
try {
|
|
217
|
+
if (!(await credentials.read()))
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
return (await clientOf(origin, credentials, undefined, scope).me()).login;
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
try {
|
|
228
|
+
return (await credentials.read()) ? undefined : null;
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/** A registry's refusal or failure as one phrase ending in what to do
|
|
236
|
+
* (cli-13): the registry named as cli-22 names it, a private package by
|
|
237
|
+
* the sign-in state, a 403 by the operation refused. */
|
|
238
|
+
async registryRefusal(error, context) {
|
|
239
|
+
if (error instanceof Refusal)
|
|
240
|
+
return error;
|
|
241
|
+
if (error instanceof FormatError) {
|
|
242
|
+
const issues = error.issues.map((issue) => (issue.path ? `${issue.path}: ${issue.message}` : issue.message)).join("; ");
|
|
243
|
+
return new Refusal(`the package is not ready: ${issues} — fix its meta.yaml, then retry`);
|
|
244
|
+
}
|
|
245
|
+
if (!(error instanceof RegistryError))
|
|
246
|
+
return new Refusal(`${error instanceof Error ? error.message : String(error)} — retry`);
|
|
247
|
+
let origin = context.origin;
|
|
248
|
+
try {
|
|
249
|
+
if (error.registry !== undefined)
|
|
250
|
+
origin = canonicalOrigin(error.registry);
|
|
251
|
+
}
|
|
252
|
+
catch { /* the registry asked */ }
|
|
253
|
+
const name = await this.registryName(origin);
|
|
254
|
+
const pkg = error.packageName;
|
|
255
|
+
// `spex login` here signs in at this folder's registry for packages
|
|
256
|
+
// (cli-10); another registry, or a Space's sign-in — what a
|
|
257
|
+
// `spex.yaml` naming no `registry` reads with (environments-38) — is
|
|
258
|
+
// named.
|
|
259
|
+
const login = context.scope === "space" ? `spex login --space ${origin}` : origin === context.origin ? "spex login" : `spex login --registry ${origin}`;
|
|
260
|
+
const about = pkg ? `${pkg}: ` : "";
|
|
261
|
+
switch (error.kind) {
|
|
262
|
+
case "not_found": {
|
|
263
|
+
if (error.code === "suppressed")
|
|
264
|
+
return new Refusal(`${about}withdrawn at ${name} — spex update picks another version`);
|
|
265
|
+
const who = await this.loginAt(origin, context.scope);
|
|
266
|
+
if (who === null)
|
|
267
|
+
return new Refusal(`${about}not at ${name}, or private — ${login}, then retry`);
|
|
268
|
+
return new Refusal(`${about}not at ${name}, or not shared with ${who === undefined ? "this account" : `@${who}`} — check the name, or ask its owner`);
|
|
269
|
+
}
|
|
270
|
+
case "forbidden": {
|
|
271
|
+
if (context.operation === "publish") {
|
|
272
|
+
const org = pkg?.split("/")[0] ?? "this org";
|
|
273
|
+
return new Refusal(`${org} is not yours at ${name} — claim it at ${origin}/account/orgs?scope=registry`);
|
|
274
|
+
}
|
|
275
|
+
const who = await this.loginAt(origin, context.scope);
|
|
276
|
+
return new Refusal(`${about}not shared with ${typeof who === "string" ? `@${who}` : "this account"} at ${name} — ask its owner`);
|
|
277
|
+
}
|
|
278
|
+
case "unauthenticated":
|
|
279
|
+
return new Refusal(`sign-in expired at ${name} — ${login}`);
|
|
280
|
+
case "unavailable":
|
|
281
|
+
if (error.code === "orgs_unavailable")
|
|
282
|
+
return new Refusal(`Your orgs at ${name} could not be read — check the connection, then retry`);
|
|
283
|
+
if (error.code === "unreachable")
|
|
284
|
+
return new Refusal(`${name} could not be reached — check the connection, then retry`);
|
|
285
|
+
// A registry the lock names by no address is never asked.
|
|
286
|
+
if (error.code === "unasked")
|
|
287
|
+
return new Refusal(`${about}spex.lock names no registry address for it — spex update writes spex.lock again`);
|
|
288
|
+
if (error.status !== undefined && error.status >= 500)
|
|
289
|
+
return new Refusal(`${name} is down (${error.status}) — retry later`);
|
|
290
|
+
if (error.status !== undefined)
|
|
291
|
+
return new Refusal(`${name} answered ${error.status} — retry later`);
|
|
292
|
+
// No sign-in to present: its cause, which says what to do.
|
|
293
|
+
return new Refusal(/ — /.test(error.message) ? error.message : `${error.message} — retry later`);
|
|
294
|
+
case "rejected": {
|
|
295
|
+
const release = pkg && context.version ? `${pkg}@${context.version}` : pkg ?? "the package";
|
|
296
|
+
if (error.status === 409)
|
|
297
|
+
return new Refusal(`${release} is already at ${name} — raise the version in meta.yaml, then retry`);
|
|
298
|
+
if (error.status === 413)
|
|
299
|
+
return new Refusal(`${release} is too large for ${name} — leave out what it does not need, then retry`);
|
|
300
|
+
const details = (error.details ?? []).map((detail) => typeof detail === "object" && detail !== null && "message" in detail ? String(detail.message) : JSON.stringify(detail));
|
|
301
|
+
return new Refusal(`${name} refused ${release}${details.length > 0 ? `: ${details.join("; ")}` : ""} — fix the package, then retry`);
|
|
302
|
+
}
|
|
303
|
+
case "format":
|
|
304
|
+
return new Refusal(`${error.message} — update Spex`);
|
|
305
|
+
case "unreadable":
|
|
306
|
+
return new Refusal(`${error.message} — retry later, or update Spex`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/** A Space as the reader knows it: its display name where the home
|
|
310
|
+
* holds one, else its host. */
|
|
311
|
+
nameOf(origin) {
|
|
312
|
+
const entry = (this.home && instanceAt(this.home, origin)) ?? { origin, clientId: "spex" };
|
|
313
|
+
return nameOf(entry);
|
|
314
|
+
}
|
|
315
|
+
/** Whether the device is signed in at an instance: the home lists it
|
|
316
|
+
* with its account, not signed out. */
|
|
317
|
+
signedInAt(origin) {
|
|
318
|
+
return this.home !== null && accountAt(this.home, origin) !== null;
|
|
319
|
+
}
|
|
320
|
+
/** Every instance the home is signed in to, in its order. */
|
|
321
|
+
signedIn() {
|
|
322
|
+
return (this.home?.instances ?? []).filter((entry) => this.signedInAt(entry.origin)).map((entry) => entry.origin);
|
|
323
|
+
}
|
|
324
|
+
/** The app token a registry call presents at an instance
|
|
325
|
+
* (environments-12): its access secret, kept current by its client,
|
|
326
|
+
* where the device is signed in there; none otherwise. */
|
|
327
|
+
async tokenAt(origin, scope = "space") {
|
|
328
|
+
if (scope === "space" ? !this.signedInAt(origin) : !(await credentialsOf(this.homeDir, origin, scope).read()))
|
|
329
|
+
return null;
|
|
330
|
+
try {
|
|
331
|
+
return await this.clientAt(origin, scope).accessSecret();
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
throw new Error(hostCause(error, await this.registryName(origin)));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/** An instance's client, one per command: a refresh the instance
|
|
338
|
+
* refuses removes its token and marks it signed out in `home.yaml` in
|
|
339
|
+
* one step, as the app's sign-out does (git-host-4). */
|
|
340
|
+
clientAt(origin, scope = "space") {
|
|
341
|
+
const at = canonicalOrigin(origin);
|
|
342
|
+
const key = `${scope}:${at}`;
|
|
343
|
+
let client = this.clients.get(key);
|
|
344
|
+
if (!client) {
|
|
345
|
+
client = clientOf(at, credentialsOf(this.homeDir, at, scope), scope === "space" ? () => this.markSignedOut(at) : undefined, scope);
|
|
346
|
+
this.clients.set(key, client);
|
|
347
|
+
}
|
|
348
|
+
return client;
|
|
349
|
+
}
|
|
350
|
+
markSignedOut(origin) {
|
|
351
|
+
try {
|
|
352
|
+
updateHomeFile(this.homeDir, (current) => withSignOut(current, origin));
|
|
353
|
+
}
|
|
354
|
+
catch { /* the token is gone; whoami may still list it */ }
|
|
355
|
+
}
|
|
356
|
+
/** The built-in spec package as this device's seed holds it
|
|
357
|
+
* (environments-7, environments-11): what the app seeded into the
|
|
358
|
+
* shared store, read from `cache/builtins/`; the command line ships
|
|
359
|
+
* none of its own. */
|
|
360
|
+
seed() {
|
|
361
|
+
this.builtin ??= builtinRegistrySource({ store: this.store, cacheDir: this.cache });
|
|
362
|
+
return this.builtin;
|
|
363
|
+
}
|
|
364
|
+
/** The registry answering under an instance's origin, presenting its
|
|
365
|
+
* app token where the device is signed in there; a refusal that signs
|
|
366
|
+
* the device out there marks it signed out in `home.yaml`
|
|
367
|
+
* (environments-12, git-host-4). The built-in spec package is answered
|
|
368
|
+
* from this device's seed first, as the app answers it. */
|
|
369
|
+
registry(origin, scope) {
|
|
370
|
+
const at = canonicalOrigin(origin);
|
|
371
|
+
const key = `${scope}:${at}`;
|
|
372
|
+
let registry = this.registries.get(key);
|
|
373
|
+
if (!registry) {
|
|
374
|
+
const remote = new RegistryClient({
|
|
375
|
+
url: at,
|
|
376
|
+
token: () => this.tokenAt(at, scope),
|
|
377
|
+
refused: async (token) => {
|
|
378
|
+
if (!(await this.clientAt(at, scope).signOutRefused(token)))
|
|
379
|
+
throw new Error(`your sign-in at ${await this.registryName(at)} changed meanwhile — retry`);
|
|
380
|
+
if (scope === "space")
|
|
381
|
+
this.markSignedOut(at);
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
registry = { remote, source: compositeRegistry(this.seed(), remote) };
|
|
385
|
+
this.registries.set(key, registry);
|
|
386
|
+
}
|
|
387
|
+
return registry;
|
|
388
|
+
}
|
|
389
|
+
registryAt(origin, scope = "space") {
|
|
390
|
+
return this.registry(origin, scope).source;
|
|
391
|
+
}
|
|
392
|
+
registryClientAt(origin, scope = "registry") {
|
|
393
|
+
return this.registry(origin, scope).remote;
|
|
394
|
+
}
|
|
395
|
+
/** The registries an install asks for a registry package's files, in
|
|
396
|
+
* the library's order (environments-7). */
|
|
397
|
+
installRegistries(instance, source, scope = "space") {
|
|
398
|
+
return installRegistryOrder(instance, source.registry, this.signedIn(), { independent: scope === "registry" })
|
|
399
|
+
.map((entry) => ("origin" in entry ? this.registryAt(entry.origin, scope) : compositeRegistry(this.seed(), unaskedRegistry(entry.unasked))));
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/** Whether a folder stands at a path. */
|
|
403
|
+
export function isDirectory(path) {
|
|
404
|
+
try {
|
|
405
|
+
return statSync(path).isDirectory();
|
|
406
|
+
}
|
|
407
|
+
catch {
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Command } from "./run.js";
|
|
2
|
+
interface Frontmatter {
|
|
3
|
+
name?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
/** The field whose unquoted value YAML refuses (`: ` inside it). */
|
|
6
|
+
unreadable?: "name" | "description";
|
|
7
|
+
}
|
|
8
|
+
/** The top-level string fields of a SKILL.md's YAML frontmatter that
|
|
9
|
+
* matter here — `name` and `description` — read from the common YAML
|
|
10
|
+
* forms: plain, single- or double-quoted, and `|` or `>` blocks. A field
|
|
11
|
+
* of another form reads as absent. The frontmatter is found as a
|
|
12
|
+
* release's readers find it, from the text's first character: nothing
|
|
13
|
+
* before `---`, a byte order mark included, is skipped. */
|
|
14
|
+
export declare function skillFrontmatter(text: string): Frontmatter;
|
|
15
|
+
/** The first paragraph under a spec's Intent heading, its lines joined. */
|
|
16
|
+
export declare function intentParagraph(text: string): string | undefined;
|
|
17
|
+
/** The license a root's LICENSE names (cli-23). */
|
|
18
|
+
export declare function detectLicense(text: string | undefined): string;
|
|
19
|
+
/** `spex export` (cli-23): build the folder from the project's files. */
|
|
20
|
+
export declare const exportPackage: Command;
|
|
21
|
+
export {};
|