@theholocron/cli 5.0.0-alpha.335 → 5.0.0-alpha.337
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/dist/cli.mjs +427 -336
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +13 -35
- package/dist/index.mjs +138 -96
- package/package.json +8 -7
package/dist/cli.mjs
CHANGED
|
@@ -6,17 +6,17 @@ import yargs from "yargs";
|
|
|
6
6
|
import { hideBin } from "yargs/helpers";
|
|
7
7
|
import { createLogger, isCI, parseLogLevel, resolveAxiomFromEnv } from "@theholocron/observability/logger";
|
|
8
8
|
import { AuthError, ProviderApiError, ProviderApiError as ProviderApiError$1, createRestClient, onRetry } from "@theholocron/http-client";
|
|
9
|
-
import { createEnvLookup, firstEnv, withEnvPrefix } from "@theholocron/env-utils/lookup";
|
|
10
|
-
import { Entry, findCredentials } from "@napi-rs/keyring";
|
|
11
|
-
import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
12
9
|
import path, { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
10
|
+
import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
13
11
|
import { parse } from "dotenv";
|
|
14
12
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
13
|
+
import { createEnvLookup, firstEnv, withEnvPrefix } from "@theholocron/env-utils/lookup";
|
|
14
|
+
import { Entry, findCredentials } from "@napi-rs/keyring";
|
|
15
15
|
import chalk from "chalk";
|
|
16
|
-
import search from "@inquirer/search";
|
|
17
16
|
import ora from "ora";
|
|
18
|
-
import { Separator, checkbox, confirm, input, password, select } from "@inquirer/prompts";
|
|
19
17
|
import { createInterface } from "node:readline";
|
|
18
|
+
import search from "@inquirer/search";
|
|
19
|
+
import { Separator, checkbox, confirm, input, password, select } from "@inquirer/prompts";
|
|
20
20
|
import { homedir, hostname, tmpdir, userInfo } from "node:os";
|
|
21
21
|
import { PostHogSink } from "@theholocron/observability/analytics";
|
|
22
22
|
import { SentrySink } from "@theholocron/observability/errors";
|
|
@@ -34,24 +34,101 @@ import { access, copyFile, lstat, mkdir, open, readFile, readdir, realpath, rena
|
|
|
34
34
|
import { ADR_DIR, ADR_STATUSES, CLOSED_STATUSES, SPEC_DIRS, SPEC_STATUSES, WITHDRAWN_STATE, assignSpecIds, checkSpecs, classifySpecPath, discussionBody, discussionIdLine, discussionPrLine, discussionTitle, evaluateDocsPresence, isAddedDocComment, isFeat, packageOf, parseFrontmatter, parseSkipDocs, reconcileSpecStatus, specSummary, specTitle, updateFrontmatter } from "@theholocron/astromech/repo-validation";
|
|
35
35
|
import { lintCommitMsgFile } from "@theholocron/astromech/lint";
|
|
36
36
|
import { createGitHubClient } from "@theholocron/github-client";
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// ../kyber/dist/token-args-BgrCq_kK.mjs
|
|
38
|
+
var TokenParseError = class extends Error {
|
|
39
|
+
name = "TokenParseError";
|
|
40
|
+
};
|
|
40
41
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
42
|
+
* Converts raw --token CLI values into a typed result.
|
|
43
|
+
*
|
|
44
|
+
* Bare form: --token ghp_xxx → { cliToken: "ghp_xxx" }
|
|
45
|
+
* Keyed form: --token github=ghp_xxx → { cliTokens: { github: "ghp_xxx" } }
|
|
46
|
+
* Mixed: --token github=ghp_xxx --token v_yyy
|
|
47
|
+
* → { cliToken: "v_yyy", cliTokens: { github: "ghp_xxx" } }
|
|
48
|
+
*
|
|
49
|
+
* Values may contain "=" (e.g. base64 strings) — only the first "=" is treated as a separator.
|
|
45
50
|
*/
|
|
46
|
-
|
|
51
|
+
function parseTokenArgs(tokens) {
|
|
52
|
+
if (tokens.length === 0) return {};
|
|
53
|
+
const cliTokens = {};
|
|
54
|
+
const bare = [];
|
|
55
|
+
for (const raw of tokens) {
|
|
56
|
+
const eqIdx = raw.indexOf("=");
|
|
57
|
+
if (eqIdx === -1) {
|
|
58
|
+
bare.push(raw);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const vendor = raw.slice(0, eqIdx);
|
|
62
|
+
const value = raw.slice(eqIdx + 1);
|
|
63
|
+
if (vendor.trim() === "") throw new TokenParseError(`invalid --token value "${raw}": vendor name must not be empty`);
|
|
64
|
+
if (/\s/.test(vendor)) throw new TokenParseError(`invalid --token value "${raw}": vendor name must not contain whitespace`);
|
|
65
|
+
if (value === "") throw new TokenParseError(`invalid --token value "${raw}": token value must not be empty`);
|
|
66
|
+
cliTokens[vendor] = value;
|
|
67
|
+
}
|
|
68
|
+
if (bare.length > 1) throw new TokenParseError(`only one bare --token value is allowed; got ${bare.length.toString()} — use vendor=value form for multiple tokens`);
|
|
69
|
+
const result = {};
|
|
70
|
+
if (bare.length === 1) result.cliToken = bare[0];
|
|
71
|
+
if (Object.keys(cliTokens).length > 0) result.cliTokens = cliTokens;
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
// ../kyber/dist/flags.mjs
|
|
47
75
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
76
|
+
* Declares the options every command of a tool takes, once, on the root parser: `--dry-run`, a repeatable `--token`
|
|
77
|
+
* (a bare value, or `vendor=value`, parsed by `parseTokenArgs`) and `--cwd`. A tool adds its own to the same parser;
|
|
78
|
+
* a command module's arguments extend {@link GlobalArgs}.
|
|
50
79
|
*/
|
|
51
|
-
function
|
|
52
|
-
|
|
80
|
+
function addGlobalOptions(parser, options = {}) {
|
|
81
|
+
const describe = options.describe ?? {};
|
|
82
|
+
return parser.option("dry-run", {
|
|
83
|
+
type: "boolean",
|
|
84
|
+
default: false,
|
|
85
|
+
describe: describe.dryRun ?? "Print what would change without changing it. Read-only commands ignore it."
|
|
86
|
+
}).option("token", {
|
|
87
|
+
type: "string",
|
|
88
|
+
array: true,
|
|
89
|
+
describe: describe.token ?? "Token override. Bare form: --token <value>. Keyed form: --token vendor=value (repeat for each vendor)."
|
|
90
|
+
}).option("cwd", {
|
|
91
|
+
type: "string",
|
|
92
|
+
default: options.cwd ?? process.cwd(),
|
|
93
|
+
describe: describe.cwd ?? "The directory to work from"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The hidden default command (`$0`) of a command group, so that typing just the group (`tool repo`) does something
|
|
98
|
+
* useful: `open` is called with the group's name and the parsed arguments, usually to open a menu of its subcommands.
|
|
99
|
+
*/
|
|
100
|
+
const groupMenu$1 = (parent, open) => ({
|
|
101
|
+
command: "$0",
|
|
102
|
+
describe: false,
|
|
103
|
+
builder: (y) => y,
|
|
104
|
+
handler: async (argv) => {
|
|
105
|
+
await open(parent, argv);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* Parses the values of a repeatable `--token` flag. An empty or missing flag is `{}`. A value that does not parse is
|
|
110
|
+
* reported through `report` (as `--token: <why>`), sets `process.exitCode` to 1 and gives `null`, so the command can stop
|
|
111
|
+
* without a stack trace; any other error is thrown.
|
|
112
|
+
*/
|
|
113
|
+
function tokenContext$1(rawTokens, report) {
|
|
114
|
+
if (!rawTokens?.length) return {};
|
|
115
|
+
try {
|
|
116
|
+
return parseTokenArgs(rawTokens);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
if (err instanceof TokenParseError) {
|
|
119
|
+
report(`--token: ${err.message}`);
|
|
120
|
+
process.exitCode = 1;
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// ../kyber/dist/secrets.mjs
|
|
127
|
+
/** Puts `text` on the system clipboard through `clipboardy`, which uses the platform's own tool. Loaded only when called. */
|
|
128
|
+
async function copyToClipboard(text) {
|
|
129
|
+
const { default: clipboard } = await import("clipboardy");
|
|
130
|
+
await clipboard.write(text);
|
|
53
131
|
}
|
|
54
|
-
// src/auth/credential-store/credential-store.ts
|
|
55
132
|
/**
|
|
56
133
|
* The variables the `credentials` providers returned, kept for the life of the process.
|
|
57
134
|
*
|
|
@@ -82,135 +159,6 @@ function getCredential(...names) {
|
|
|
82
159
|
if (value) return value;
|
|
83
160
|
}
|
|
84
161
|
}
|
|
85
|
-
// src/auth/keyring/keyring.ts
|
|
86
|
-
/**
|
|
87
|
-
* Keyring-backed bootstrap credential store.
|
|
88
|
-
*
|
|
89
|
-
* Every holocron plugin's bootstrap token (the one it needs before it
|
|
90
|
-
* can talk to its vendor's API) can be stored in the OS keyring under
|
|
91
|
-
* a single reverse-DNS service scope. Managed via `holocron auth`
|
|
92
|
-
* subcommands; consulted at position 4 in every plugin's auth
|
|
93
|
-
* precedence chain (after --token / HOLOCRON_<X>_TOKEN / <native>_TOKEN).
|
|
94
|
-
*
|
|
95
|
-
* See `docs/wiki/specifications/tech-auth-bootstrap.spec.md` for the design rationale.
|
|
96
|
-
*
|
|
97
|
-
* Failure model: keyring access is best-effort. Platforms without a
|
|
98
|
-
* supported credential store (some Linux CI images, sandboxed
|
|
99
|
-
* environments) will throw from the underlying library. Every export
|
|
100
|
-
* here catches and returns a null/empty result rather than propagating
|
|
101
|
-
* — the plugin's precedence chain then falls through to
|
|
102
|
-
* env-var-only paths, which is exactly how CI is meant to work.
|
|
103
|
-
*/
|
|
104
|
-
const SERVICE = "com.theholocron.cli";
|
|
105
|
-
/**
|
|
106
|
-
* What `getToken` has already read, by provider, for the life of this process. A miss (`null`) is remembered too, so
|
|
107
|
-
* a token that is not stored, or a keyring that is unavailable, is asked about once, not on every lookup. The OS
|
|
108
|
-
* keyring can prompt on each read, and several resolvers ask for the same entry in one command.
|
|
109
|
-
*
|
|
110
|
-
* It lives in memory only. A cache that outlived the process would mean writing tokens somewhere else, which is
|
|
111
|
-
* what the keyring is there to avoid.
|
|
112
|
-
*/
|
|
113
|
-
const cache = /* @__PURE__ */ new Map();
|
|
114
|
-
/**
|
|
115
|
-
* Store or overwrite a bootstrap token for a provider. Returns true on
|
|
116
|
-
* success, false when the underlying keyring is unsupported or errored.
|
|
117
|
-
*/
|
|
118
|
-
function setToken(provider, token) {
|
|
119
|
-
try {
|
|
120
|
-
new Entry(SERVICE, provider).setPassword(token);
|
|
121
|
-
cache.set(provider, token);
|
|
122
|
-
return true;
|
|
123
|
-
} catch {
|
|
124
|
-
cache.delete(provider);
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Read the bootstrap token for a provider. Returns `null` for both
|
|
130
|
-
* "not stored" and "keyring unavailable" — callers can treat them the
|
|
131
|
-
* same way (fall through to env-var precedence). The answer is
|
|
132
|
-
* remembered for the rest of the process, so the keyring is asked once
|
|
133
|
-
* per provider.
|
|
134
|
-
*/
|
|
135
|
-
function getToken(provider) {
|
|
136
|
-
if (cache.has(provider)) return cache.get(provider);
|
|
137
|
-
let token;
|
|
138
|
-
try {
|
|
139
|
-
token = new Entry(SERVICE, provider).getPassword();
|
|
140
|
-
} catch {
|
|
141
|
-
token = null;
|
|
142
|
-
}
|
|
143
|
-
cache.set(provider, token);
|
|
144
|
-
return token;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Whether the OS keyring can be used at all. `getToken` answers `null` for a missing entry and for a keyring that
|
|
148
|
-
* cannot be reached alike; a caller that must tell an outage from an empty keyring asks this first.
|
|
149
|
-
*/
|
|
150
|
-
function isKeyringAvailable() {
|
|
151
|
-
try {
|
|
152
|
-
findCredentials(SERVICE);
|
|
153
|
-
return true;
|
|
154
|
-
} catch {
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Delete a stored token. Returns true when a token was removed, false
|
|
160
|
-
* when there was nothing to delete or the keyring is unavailable.
|
|
161
|
-
* Distinguishing the two cases isn't worth the surface area — the
|
|
162
|
-
* command output makes the situation clear either way.
|
|
163
|
-
*/
|
|
164
|
-
function deleteToken(provider) {
|
|
165
|
-
try {
|
|
166
|
-
const removed = new Entry(SERVICE, provider).deletePassword();
|
|
167
|
-
cache.set(provider, null);
|
|
168
|
-
return removed;
|
|
169
|
-
} catch {
|
|
170
|
-
cache.delete(provider);
|
|
171
|
-
return false;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* List provider slugs with a stored token in this service scope.
|
|
176
|
-
* Uses the library's `findCredentials(service)` — supported on all
|
|
177
|
-
* platforms the underlying credential store supports.
|
|
178
|
-
*/
|
|
179
|
-
function listStoredProviders() {
|
|
180
|
-
try {
|
|
181
|
-
return findCredentials(SERVICE).map((c) => c.account);
|
|
182
|
-
} catch {
|
|
183
|
-
return [];
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
// src/auth/auth-resolver/auth-resolver.ts
|
|
187
|
-
/**
|
|
188
|
-
* Build a strict, single-feature token resolver.
|
|
189
|
-
*
|
|
190
|
-
* Resolution chain: `--token flag → envName env var → the `credentials` providers' envName → keyring(keyringKey)`.
|
|
191
|
-
* No broad-token fallback — if the feature-specific token is absent the
|
|
192
|
-
* operation fails with a message naming the exact env var to set.
|
|
193
|
-
*/
|
|
194
|
-
function createFeatureResolver(config) {
|
|
195
|
-
const resolveFeatureToken = (input = {}) => {
|
|
196
|
-
const env = makeEnv(input.env);
|
|
197
|
-
const keyring = input.keyring ?? ((provider) => getCredential(config.envName) ?? getToken(provider));
|
|
198
|
-
const token = input.cliToken || env.get(config.envName) || keyring(config.keyringKey);
|
|
199
|
-
if (!token) throw new AuthError(`no ${config.vendor ?? "GitHub"} token found for this operation. Pass --token <token>, set ${config.envName}, or run: holocron auth set ${config.keyringKey} <token>`);
|
|
200
|
-
return token;
|
|
201
|
-
};
|
|
202
|
-
return Object.assign(resolveFeatureToken, { token: {
|
|
203
|
-
envName: config.envName,
|
|
204
|
-
keyringKey: config.keyringKey
|
|
205
|
-
} });
|
|
206
|
-
}
|
|
207
|
-
// src/auth/copy-to-clipboard/copy-to-clipboard.ts
|
|
208
|
-
/** Puts `text` on the system clipboard through `clipboardy`, which uses the platform's own tool. Loaded only when called. */
|
|
209
|
-
async function copyToClipboard(text) {
|
|
210
|
-
const { default: clipboard } = await import("clipboardy");
|
|
211
|
-
await clipboard.write(text);
|
|
212
|
-
}
|
|
213
|
-
// src/auth/private-file/private-file.ts
|
|
214
162
|
/**
|
|
215
163
|
* Create `path` as a new file only its owner can read (mode `0600`, set again on the open file so a loose `umask`
|
|
216
164
|
* cannot widen it), write `text` to it and return which file it is, with its descriptor left open. It fails if the path
|
|
@@ -237,7 +185,6 @@ function createPrivateFile(path, text, write = writeSync) {
|
|
|
237
185
|
throw err;
|
|
238
186
|
}
|
|
239
187
|
}
|
|
240
|
-
// src/auth/shred-file/shred-file.ts
|
|
241
188
|
/**
|
|
242
189
|
* Overwrite the file `identity` names with zeros, close it, and remove it from `path`, so the tokens it held are not
|
|
243
190
|
* left in a deleted-but-recoverable file.
|
|
@@ -277,7 +224,6 @@ function shredFile(path, identity, remove = unlinkSync) {
|
|
|
277
224
|
remove(path);
|
|
278
225
|
return "deleted";
|
|
279
226
|
}
|
|
280
|
-
// src/auth/credentials-file/credentials-file.ts
|
|
281
227
|
/**
|
|
282
228
|
* Write `text` to `path` as a file only its owner can read (mode `0600`), and return which file that is, with its
|
|
283
229
|
* descriptor still open, so cleanup can remove only it. Without `force` it will not replace a file that is already
|
|
@@ -330,7 +276,6 @@ function openExisting(path) {
|
|
|
330
276
|
fd
|
|
331
277
|
};
|
|
332
278
|
}
|
|
333
|
-
// src/auth/dotenv-file/dotenv-file.ts
|
|
334
279
|
/** The name of the file, at the repo root, that holds a developer's own tokens. */
|
|
335
280
|
const DOTENV_FILE = ".env";
|
|
336
281
|
/**
|
|
@@ -347,7 +292,6 @@ function readDotenvFile(repoRoot) {
|
|
|
347
292
|
return null;
|
|
348
293
|
}
|
|
349
294
|
}
|
|
350
|
-
// src/auth/dotenv-line/dotenv-line.ts
|
|
351
295
|
/** A value dotenv reads back as written without any quoting: no space, quote, `#`, backslash or line break. */
|
|
352
296
|
const PLAIN = /^[A-Za-z0-9_@%+=:,./-]*$/;
|
|
353
297
|
/** The quotes dotenv accepts around a value, in the order they are tried. Single quotes keep the value exactly as written. */
|
|
@@ -374,7 +318,6 @@ function dotenvLine(name, value) {
|
|
|
374
318
|
const quote = QUOTES.find((q) => !value.includes(q));
|
|
375
319
|
return quote ? `${name}=${quote}${value}${quote}` : null;
|
|
376
320
|
}
|
|
377
|
-
// src/auth/git-ignored/git-ignored.ts
|
|
378
321
|
/**
|
|
379
322
|
* Ask git whether it ignores `path` (see {@link GitIgnoreState}). A caller that must not leave a file where it could be
|
|
380
323
|
* committed accepts only `ignored` and `no-repo`. Reads only; it changes nothing.
|
|
@@ -402,42 +345,176 @@ function isGitIgnored(path) {
|
|
|
402
345
|
return status === 128 && /not a git repository/i.test(String(stderr)) ? "no-repo" : "unknown";
|
|
403
346
|
}
|
|
404
347
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
}
|
|
348
|
+
function loadBinding() {
|
|
349
|
+
try {
|
|
350
|
+
return createRequire(import.meta.url)("@napi-rs/keyring");
|
|
351
|
+
} catch {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
409
355
|
/**
|
|
410
|
-
*
|
|
356
|
+
* A tool's secrets in the OS keyring, under one service name.
|
|
411
357
|
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
358
|
+
* Keyring access is best-effort. Platforms without a supported credential store (some Linux CI images, sandboxed
|
|
359
|
+
* environments) throw from the underlying library, and `@napi-rs/keyring` is an optional peer that may not be installed
|
|
360
|
+
* at all. Every method catches that and answers `null`, `false` or an empty list rather than propagating, so a caller's
|
|
361
|
+
* chain (a flag, then the environment, then the keyring) falls through to the paths that do work, which is how CI is
|
|
362
|
+
* meant to run.
|
|
416
363
|
*
|
|
417
|
-
*
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
const
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
if (
|
|
426
|
-
|
|
427
|
-
|
|
364
|
+
* Reads are remembered in memory only, for the life of the process. A cache that outlived the process would mean writing
|
|
365
|
+
* secrets somewhere else, which is what the keyring is there to avoid.
|
|
366
|
+
*/
|
|
367
|
+
function createKeyring(options) {
|
|
368
|
+
const { service } = options;
|
|
369
|
+
const cache = /* @__PURE__ */ new Map();
|
|
370
|
+
let binding = options.binding;
|
|
371
|
+
const loaded = () => {
|
|
372
|
+
if (binding === void 0) binding = loadBinding();
|
|
373
|
+
return binding;
|
|
374
|
+
};
|
|
375
|
+
const entry = (account) => {
|
|
376
|
+
const b = loaded();
|
|
377
|
+
if (!b) throw new Error("no OS keyring available");
|
|
378
|
+
return new b.Entry(service, account);
|
|
379
|
+
};
|
|
380
|
+
return {
|
|
381
|
+
get(account) {
|
|
382
|
+
if (cache.has(account)) return cache.get(account);
|
|
383
|
+
let secret;
|
|
384
|
+
try {
|
|
385
|
+
secret = entry(account).getPassword();
|
|
386
|
+
} catch {
|
|
387
|
+
secret = null;
|
|
388
|
+
}
|
|
389
|
+
cache.set(account, secret);
|
|
390
|
+
return secret;
|
|
391
|
+
},
|
|
392
|
+
set(account, secret) {
|
|
393
|
+
try {
|
|
394
|
+
entry(account).setPassword(secret);
|
|
395
|
+
cache.set(account, secret);
|
|
396
|
+
return true;
|
|
397
|
+
} catch {
|
|
398
|
+
cache.delete(account);
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
delete(account) {
|
|
403
|
+
try {
|
|
404
|
+
const removed = entry(account).deletePassword();
|
|
405
|
+
cache.set(account, null);
|
|
406
|
+
return removed;
|
|
407
|
+
} catch {
|
|
408
|
+
cache.delete(account);
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
list() {
|
|
413
|
+
try {
|
|
414
|
+
const b = loaded();
|
|
415
|
+
return b ? b.findCredentials(service).map((c) => c.account) : [];
|
|
416
|
+
} catch {
|
|
417
|
+
return [];
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
isAvailable() {
|
|
421
|
+
try {
|
|
422
|
+
const b = loaded();
|
|
423
|
+
if (!b) return false;
|
|
424
|
+
b.findCredentials(service);
|
|
425
|
+
return true;
|
|
426
|
+
} catch {
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
clearCache() {
|
|
431
|
+
cache.clear();
|
|
428
432
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
// src/env/env.ts
|
|
436
|
+
/** Singleton env for simple global lookups throughout the CLI. */
|
|
437
|
+
const env = createEnvLookup();
|
|
438
|
+
/**
|
|
439
|
+
* `get("KEY")` tries `HOLOCRON_KEY` first, then `KEY`. Use it for settings that
|
|
440
|
+
* have both a Holocron-namespaced override and a vendor-native name; do not use
|
|
441
|
+
* it for `HOLOCRON_*` variables that have no bare fallback (`HOLOCRON_ORG`,
|
|
442
|
+
* `HOLOCRON_LOG_LEVEL`, …), where the bare name would be wrong.
|
|
443
|
+
*/
|
|
444
|
+
const holocronEnv = withEnvPrefix(env, "HOLOCRON");
|
|
445
|
+
/**
|
|
446
|
+
* Create an injectable env for commands that accept a fake env in tests.
|
|
447
|
+
* Pass `input.env` when available, falls back to `process.env`.
|
|
448
|
+
*/
|
|
449
|
+
function makeEnv(source) {
|
|
450
|
+
return createEnvLookup(source);
|
|
451
|
+
}
|
|
452
|
+
// src/auth/keyring/keyring.ts
|
|
453
|
+
/**
|
|
454
|
+
* Keyring-backed bootstrap credential store.
|
|
455
|
+
*
|
|
456
|
+
* Every holocron plugin's bootstrap token (the one it needs before it can talk to its vendor's API) can be stored in
|
|
457
|
+
* the OS keyring under a single reverse-DNS service scope. Managed via `holocron auth` subcommands; consulted at
|
|
458
|
+
* position 4 in every plugin's auth precedence chain (after --token / HOLOCRON_<X>_TOKEN / <native>_TOKEN).
|
|
459
|
+
*
|
|
460
|
+
* The keyring itself, with its best-effort failure model and its per-process cache, is `createKeyring` in
|
|
461
|
+
* `@theholocron/kyber/secrets`; this file only names the service and keeps the function names the CLI uses.
|
|
462
|
+
*
|
|
463
|
+
* See `docs/wiki/specifications/tech-auth-bootstrap.spec.md` for the design rationale.
|
|
464
|
+
*/
|
|
465
|
+
const keyring = createKeyring({
|
|
466
|
+
service: "com.theholocron.cli",
|
|
467
|
+
binding: {
|
|
468
|
+
Entry,
|
|
469
|
+
findCredentials
|
|
435
470
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
471
|
+
});
|
|
472
|
+
/** Store or overwrite a bootstrap token for a provider. Returns true on success, false when the keyring is unsupported or errored. */
|
|
473
|
+
function setToken(provider, token) {
|
|
474
|
+
return keyring.set(provider, token);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Read the bootstrap token for a provider. Returns `null` for both "not stored" and "keyring unavailable", so callers
|
|
478
|
+
* fall through to env-var precedence. The answer is remembered for the rest of the process.
|
|
479
|
+
*/
|
|
480
|
+
function getToken(provider) {
|
|
481
|
+
return keyring.get(provider);
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Whether the OS keyring can be used at all. `getToken` answers `null` for a missing entry and for a keyring that
|
|
485
|
+
* cannot be reached alike; a caller that must tell an outage from an empty keyring asks this first.
|
|
486
|
+
*/
|
|
487
|
+
function isKeyringAvailable() {
|
|
488
|
+
return keyring.isAvailable();
|
|
489
|
+
}
|
|
490
|
+
/** Delete a stored token. Returns true when a token was removed, false when there was nothing to delete or the keyring is unavailable. */
|
|
491
|
+
function deleteToken(provider) {
|
|
492
|
+
return keyring.delete(provider);
|
|
493
|
+
}
|
|
494
|
+
/** List the provider slugs that have a stored token under the holocron service scope. */
|
|
495
|
+
function listStoredProviders() {
|
|
496
|
+
return keyring.list();
|
|
497
|
+
}
|
|
498
|
+
// src/auth/auth-resolver/auth-resolver.ts
|
|
499
|
+
/**
|
|
500
|
+
* Build a strict, single-feature token resolver.
|
|
501
|
+
*
|
|
502
|
+
* Resolution chain: `--token flag → envName env var → the `credentials` providers' envName → keyring(keyringKey)`.
|
|
503
|
+
* No broad-token fallback — if the feature-specific token is absent the
|
|
504
|
+
* operation fails with a message naming the exact env var to set.
|
|
505
|
+
*/
|
|
506
|
+
function createFeatureResolver(config) {
|
|
507
|
+
const resolveFeatureToken = (input = {}) => {
|
|
508
|
+
const env = makeEnv(input.env);
|
|
509
|
+
const keyring = input.keyring ?? ((provider) => getCredential(config.envName) ?? getToken(provider));
|
|
510
|
+
const token = input.cliToken || env.get(config.envName) || keyring(config.keyringKey);
|
|
511
|
+
if (!token) throw new AuthError(`no ${config.vendor ?? "GitHub"} token found for this operation. Pass --token <token>, set ${config.envName}, or run: holocron auth set ${config.keyringKey} <token>`);
|
|
512
|
+
return token;
|
|
513
|
+
};
|
|
514
|
+
return Object.assign(resolveFeatureToken, { token: {
|
|
515
|
+
envName: config.envName,
|
|
516
|
+
keyringKey: config.keyringKey
|
|
517
|
+
} });
|
|
441
518
|
}
|
|
442
519
|
// src/commands/contexts/contexts.ts
|
|
443
520
|
/**
|
|
@@ -528,7 +605,7 @@ function contextForCommand(name) {
|
|
|
528
605
|
function commandsInContext(context) {
|
|
529
606
|
return Object.entries(COMMAND_CONTEXTS).filter(([, c]) => c === context).map(([name]) => name);
|
|
530
607
|
}
|
|
531
|
-
//
|
|
608
|
+
// ../kyber/dist/non-interactive-error-Mm_Mn79M.mjs
|
|
532
609
|
/**
|
|
533
610
|
* Raised when a prompt is needed but stdin isn't a TTY. A non-TTY run (CI, a
|
|
534
611
|
* script, a pipe) throws this instead of hanging on `@inquirer/prompts`, which
|
|
@@ -536,9 +613,10 @@ function commandsInContext(context) {
|
|
|
536
613
|
* `USER_FACING_ERRORS` catch prints the message cleanly.
|
|
537
614
|
*/
|
|
538
615
|
var NonInteractiveError = class extends Error {
|
|
616
|
+
/** The error's name, `NonInteractiveError`, so a catch can tell it from any other error. */
|
|
539
617
|
name = "NonInteractiveError";
|
|
540
618
|
};
|
|
541
|
-
//
|
|
619
|
+
// ../kyber/dist/ui.mjs
|
|
542
620
|
function isContainer(value) {
|
|
543
621
|
return typeof value === "object" && value !== null;
|
|
544
622
|
}
|
|
@@ -756,39 +834,6 @@ async function viewJson(value, options = {}) {
|
|
|
756
834
|
const lines = renderTree(value, { expanded: expandToDepth(value, depth) });
|
|
757
835
|
console.log(lines.map((l) => l.text).join("\n"));
|
|
758
836
|
}
|
|
759
|
-
// src/ui/menu/menu.ts
|
|
760
|
-
/**
|
|
761
|
-
* Searchable autocomplete over one menu level's `items`. `select()` would work too
|
|
762
|
-
* at these list sizes, but `search()` degrades gracefully as the surface grows and
|
|
763
|
-
* costs nothing when it doesn't. Resolves to the picked item's `value`.
|
|
764
|
-
*/
|
|
765
|
-
async function pickMenuItem(items, message = "What would you like to do?") {
|
|
766
|
-
return search({
|
|
767
|
-
message,
|
|
768
|
-
source: (term) => searchChoices(items, term)
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* `@inquirer/search`'s `source` callback, factored out as a plain function —
|
|
773
|
-
* unit-testable directly instead of only through a mocked `search()` call.
|
|
774
|
-
* Empty/undefined `term` (nothing typed yet) returns every item.
|
|
775
|
-
*/
|
|
776
|
-
function searchChoices(items, term) {
|
|
777
|
-
const needle = term?.toLowerCase();
|
|
778
|
-
const pool = !needle ? items : items.filter((i) => i.haystack.includes(needle));
|
|
779
|
-
const rank = (i) => {
|
|
780
|
-
if (!needle) return 0;
|
|
781
|
-
const name = i.name.toLowerCase();
|
|
782
|
-
return name.startsWith(needle) ? 0 : name.includes(needle) ? 1 : 2;
|
|
783
|
-
};
|
|
784
|
-
return [...pool].sort((a, b) => rank(a) - rank(b)).map((i) => ({
|
|
785
|
-
name: i.name,
|
|
786
|
-
value: i.value,
|
|
787
|
-
description: i.description,
|
|
788
|
-
short: i.name.replace(/ ›$/, "")
|
|
789
|
-
}));
|
|
790
|
-
}
|
|
791
|
-
// src/ui/open-path/open-path.ts
|
|
792
837
|
/** Platform-appropriate command to open a path in the OS's file browser. */
|
|
793
838
|
function openCommand(path) {
|
|
794
839
|
if (process.platform === "darwin") return {
|
|
@@ -824,7 +869,6 @@ function openPath(path) {
|
|
|
824
869
|
child.on("error", () => {});
|
|
825
870
|
child.unref();
|
|
826
871
|
}
|
|
827
|
-
// src/ui/progress/progress.ts
|
|
828
872
|
/**
|
|
829
873
|
* Runs `fn`, showing an ora spinner for its duration in TTY environments.
|
|
830
874
|
* In non-TTY environments (CI, pipes, tests) the spinner is skipped entirely.
|
|
@@ -855,9 +899,10 @@ function progressEnabled() {
|
|
|
855
899
|
}
|
|
856
900
|
/**
|
|
857
901
|
* A spinner for one step at a time that a step can print through. Steps that only return a result use {@link
|
|
858
|
-
* withProgress}; a step that prints its own result line while it runs
|
|
902
|
+
* withProgress}; a step that prints its own result line while it runs prints through `print`. A `listen` hook can change the
|
|
903
|
+
* spinner's text while the step runs, for instance to say that a request is being sent again.
|
|
859
904
|
*/
|
|
860
|
-
function createProgress(print, enabled = progressEnabled) {
|
|
905
|
+
function createProgress$1(print, enabled = progressEnabled, listen) {
|
|
861
906
|
let active;
|
|
862
907
|
return {
|
|
863
908
|
async run(label, fn) {
|
|
@@ -868,13 +913,13 @@ function createProgress(print, enabled = progressEnabled) {
|
|
|
868
913
|
discardStdin: false
|
|
869
914
|
}).start();
|
|
870
915
|
active = spinner;
|
|
871
|
-
const stopListening =
|
|
872
|
-
spinner.text =
|
|
916
|
+
const stopListening = listen?.(label, (text) => {
|
|
917
|
+
spinner.text = text;
|
|
873
918
|
});
|
|
874
919
|
try {
|
|
875
920
|
return await fn();
|
|
876
921
|
} finally {
|
|
877
|
-
stopListening();
|
|
922
|
+
stopListening?.();
|
|
878
923
|
spinner.stop();
|
|
879
924
|
active = void 0;
|
|
880
925
|
}
|
|
@@ -889,10 +934,113 @@ function createProgress(print, enabled = progressEnabled) {
|
|
|
889
934
|
};
|
|
890
935
|
}
|
|
891
936
|
/** `fn` under a cleared-when-done spinner named `label`, on a terminal only. */
|
|
937
|
+
function withProgress$1(label, fn, listen) {
|
|
938
|
+
return createProgress$1(() => {}, progressEnabled, listen).run(label, fn);
|
|
939
|
+
}
|
|
940
|
+
/** Formats a message with a status marker and colour: one helper per kind of line a command prints. */
|
|
941
|
+
const style = {
|
|
942
|
+
/** A green `✓` for something that worked. */
|
|
943
|
+
success: (msg) => `${chalk.green("✓")} ${msg}`,
|
|
944
|
+
/** A yellow `⚠` for something worth a second look. */
|
|
945
|
+
warn: (msg) => `${chalk.yellow("⚠")} ${msg}`,
|
|
946
|
+
/** A red `✗` for something that failed. */
|
|
947
|
+
fail: (msg) => `${chalk.red("✗")} ${msg}`,
|
|
948
|
+
/** A cyan `→` for a step being taken. */
|
|
949
|
+
step: (msg) => `${chalk.cyan("→")} ${msg}`,
|
|
950
|
+
/** A dim `·` marker for a row that's neither a pass nor a failure — loaded but inactive, or skipped. */
|
|
951
|
+
skip: (msg) => chalk.dim(`· ${msg}`),
|
|
952
|
+
/** Dimmed text for a suggestion or a next step. */
|
|
953
|
+
hint: (msg) => chalk.dim(msg),
|
|
954
|
+
/** Dimmed text for detail that should recede. */
|
|
955
|
+
dim: (msg) => chalk.dim(msg),
|
|
956
|
+
/** Bold text for a heading. */
|
|
957
|
+
header: (msg) => chalk.bold(msg)
|
|
958
|
+
};
|
|
959
|
+
/** Right-pads `s` to `width` with spaces — never truncates. */
|
|
960
|
+
function pad(s, width) {
|
|
961
|
+
return s.length >= width ? s : s + " ".repeat(width - s.length);
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* One row of a status report: a 2-space indent, the status icon (✓ / ✗ / ·),
|
|
965
|
+
* then `columns` joined with a two-space gap (blank columns dropped, so a
|
|
966
|
+
* row that has nothing for its last column doesn't trail whitespace).
|
|
967
|
+
* Column padding (`pad`) is the caller's job — `doctor` pads capability and
|
|
968
|
+
* provider to a fixed width; `clone`'s repo names and paths don't, since
|
|
969
|
+
* they vary too widely for fixed-width alignment to read cleanly.
|
|
970
|
+
*
|
|
971
|
+
* Shared by `doctor` (capability / provider / message) and `clone` (repo /
|
|
972
|
+
* destination / reason) so every status table in the CLI reads the same way.
|
|
973
|
+
*/
|
|
974
|
+
function statusRow(status, columns) {
|
|
975
|
+
const joined = columns.filter((c) => c.length > 0).join(" ");
|
|
976
|
+
return ` ${status === "ok" ? style.success(joined) : status === "fail" ? style.fail(joined) : style.skip(joined)}`;
|
|
977
|
+
}
|
|
978
|
+
/**
|
|
979
|
+
* Print `message` and wait until Enter is pressed, the input ends, or Ctrl-C is pressed, whichever comes first, and
|
|
980
|
+
* return which: `enter`, or `closed` for the other two. It never hangs on a closed input. It reads from stdin and
|
|
981
|
+
* writes to stderr, so a pipe on stdout is never touched; the caller checks there is a terminal to answer it. The
|
|
982
|
+
* streams are parameters so a test can answer for the user.
|
|
983
|
+
*/
|
|
984
|
+
function waitForEnter(message, input = process.stdin, output = process.stderr) {
|
|
985
|
+
return new Promise((resolve) => {
|
|
986
|
+
const rl = createInterface({
|
|
987
|
+
input,
|
|
988
|
+
output
|
|
989
|
+
});
|
|
990
|
+
let answered = false;
|
|
991
|
+
rl.on("close", () => resolve(answered ? "enter" : "closed"));
|
|
992
|
+
rl.on("SIGINT", () => rl.close());
|
|
993
|
+
rl.question(message, () => {
|
|
994
|
+
answered = true;
|
|
995
|
+
rl.close();
|
|
996
|
+
});
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
// src/ui/progress/progress.ts
|
|
1000
|
+
/** Says on the spinner when a request is being sent again, so a slow step is not mistaken for a stuck one. */
|
|
1001
|
+
const retryNotice = (label, setText) => onRetry((e) => {
|
|
1002
|
+
setText(`${label} (retrying ${e.vendor ?? "the request"}, attempt ${e.attempt} of ${e.of})`);
|
|
1003
|
+
});
|
|
1004
|
+
/** {@link createSpinnerProgress} with the retry notice hooked in. */
|
|
1005
|
+
function createProgress(print, enabled = progressEnabled) {
|
|
1006
|
+
return createProgress$1(print, enabled, retryNotice);
|
|
1007
|
+
}
|
|
1008
|
+
/** `fn` under a cleared-when-done spinner named `label`, on a terminal only, with the retry notice hooked in. */
|
|
892
1009
|
function withProgress(label, fn) {
|
|
893
|
-
return
|
|
1010
|
+
return withProgress$1(label, fn, retryNotice);
|
|
1011
|
+
}
|
|
1012
|
+
// ../kyber/dist/prompts.mjs
|
|
1013
|
+
/**
|
|
1014
|
+
* Searchable autocomplete over one menu level's `items`. `select()` would work too
|
|
1015
|
+
* at these list sizes, but `search()` degrades gracefully as the surface grows and
|
|
1016
|
+
* costs nothing when it doesn't. Resolves to the picked item's `value`.
|
|
1017
|
+
*/
|
|
1018
|
+
async function pickMenuItem(items, message = "What would you like to do?") {
|
|
1019
|
+
return search({
|
|
1020
|
+
message,
|
|
1021
|
+
source: (term) => searchChoices(items, term)
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* `@inquirer/search`'s `source` callback, factored out as a plain function —
|
|
1026
|
+
* unit-testable directly instead of only through a mocked `search()` call.
|
|
1027
|
+
* Empty/undefined `term` (nothing typed yet) returns every item.
|
|
1028
|
+
*/
|
|
1029
|
+
function searchChoices(items, term) {
|
|
1030
|
+
const needle = term?.toLowerCase();
|
|
1031
|
+
const pool = !needle ? items : items.filter((i) => i.haystack.includes(needle));
|
|
1032
|
+
const rank = (i) => {
|
|
1033
|
+
if (!needle) return 0;
|
|
1034
|
+
const name = i.name.toLowerCase();
|
|
1035
|
+
return name.startsWith(needle) ? 0 : name.includes(needle) ? 1 : 2;
|
|
1036
|
+
};
|
|
1037
|
+
return [...pool].sort((a, b) => rank(a) - rank(b)).map((i) => ({
|
|
1038
|
+
name: i.name,
|
|
1039
|
+
value: i.value,
|
|
1040
|
+
description: i.description,
|
|
1041
|
+
short: i.name.replace(/ ›$/, "")
|
|
1042
|
+
}));
|
|
894
1043
|
}
|
|
895
|
-
// src/ui/prompt-options/prompt-options.ts
|
|
896
1044
|
/**
|
|
897
1045
|
* A required option must not resolve to an empty answer — `optionArgv`/
|
|
898
1046
|
* `secretEnv` (child-argv.ts) both drop an empty-string value entirely,
|
|
@@ -1085,7 +1233,6 @@ async function promptForDeferredOptions(deferred) {
|
|
|
1085
1233
|
for (const option of deferred) answers[option.key] = await promptOne(option);
|
|
1086
1234
|
return answers;
|
|
1087
1235
|
}
|
|
1088
|
-
// src/ui/prompt-positionals/prompt-positionals.ts
|
|
1089
1236
|
/**
|
|
1090
1237
|
* For each of `entry.positionals` not already present in `argv`, prompts for
|
|
1091
1238
|
* it (`input()` or `select()`, per the positional's `type`) and returns the
|
|
@@ -1119,60 +1266,6 @@ async function promptForPositionals(entry, argv) {
|
|
|
1119
1266
|
}
|
|
1120
1267
|
return out;
|
|
1121
1268
|
}
|
|
1122
|
-
// src/ui/style/style.ts
|
|
1123
|
-
const style = {
|
|
1124
|
-
success: (msg) => `${chalk.green("✓")} ${msg}`,
|
|
1125
|
-
warn: (msg) => `${chalk.yellow("⚠")} ${msg}`,
|
|
1126
|
-
fail: (msg) => `${chalk.red("✗")} ${msg}`,
|
|
1127
|
-
step: (msg) => `${chalk.cyan("→")} ${msg}`,
|
|
1128
|
-
/** A dim `·` marker for a row that's neither a pass nor a failure — loaded but inactive, or skipped. */
|
|
1129
|
-
skip: (msg) => chalk.dim(`· ${msg}`),
|
|
1130
|
-
hint: (msg) => chalk.dim(msg),
|
|
1131
|
-
dim: (msg) => chalk.dim(msg),
|
|
1132
|
-
header: (msg) => chalk.bold(msg)
|
|
1133
|
-
};
|
|
1134
|
-
// src/ui/status-row/status-row.ts
|
|
1135
|
-
/** Right-pads `s` to `width` with spaces — never truncates. */
|
|
1136
|
-
function pad(s, width) {
|
|
1137
|
-
return s.length >= width ? s : s + " ".repeat(width - s.length);
|
|
1138
|
-
}
|
|
1139
|
-
/**
|
|
1140
|
-
* One row of a status report: a 2-space indent, the status icon (✓ / ✗ / ·),
|
|
1141
|
-
* then `columns` joined with a two-space gap (blank columns dropped, so a
|
|
1142
|
-
* row that has nothing for its last column doesn't trail whitespace).
|
|
1143
|
-
* Column padding (`pad`) is the caller's job — `doctor` pads capability and
|
|
1144
|
-
* provider to a fixed width; `clone`'s repo names and paths don't, since
|
|
1145
|
-
* they vary too widely for fixed-width alignment to read cleanly.
|
|
1146
|
-
*
|
|
1147
|
-
* Shared by `doctor` (capability / provider / message) and `clone` (repo /
|
|
1148
|
-
* destination / reason) so every status table in the CLI reads the same way.
|
|
1149
|
-
*/
|
|
1150
|
-
function statusRow(status, columns) {
|
|
1151
|
-
const joined = columns.filter((c) => c.length > 0).join(" ");
|
|
1152
|
-
return ` ${status === "ok" ? style.success(joined) : status === "fail" ? style.fail(joined) : style.skip(joined)}`;
|
|
1153
|
-
}
|
|
1154
|
-
// src/ui/wait-for-enter/wait-for-enter.ts
|
|
1155
|
-
/**
|
|
1156
|
-
* Print `message` and wait until Enter is pressed, the input ends, or Ctrl-C is pressed, whichever comes first, and
|
|
1157
|
-
* return which: `enter`, or `closed` for the other two. It never hangs on a closed input. It reads from stdin and
|
|
1158
|
-
* writes to stderr, so a pipe on stdout is never touched; the caller checks there is a terminal to answer it. The
|
|
1159
|
-
* streams are parameters so a test can answer for the user.
|
|
1160
|
-
*/
|
|
1161
|
-
function waitForEnter(message, input = process.stdin, output = process.stderr) {
|
|
1162
|
-
return new Promise((resolve) => {
|
|
1163
|
-
const rl = createInterface({
|
|
1164
|
-
input,
|
|
1165
|
-
output
|
|
1166
|
-
});
|
|
1167
|
-
let answered = false;
|
|
1168
|
-
rl.on("close", () => resolve(answered ? "enter" : "closed"));
|
|
1169
|
-
rl.on("SIGINT", () => rl.close());
|
|
1170
|
-
rl.question(message, () => {
|
|
1171
|
-
answered = true;
|
|
1172
|
-
rl.close();
|
|
1173
|
-
});
|
|
1174
|
-
});
|
|
1175
|
-
}
|
|
1176
1269
|
// src/observability/logger/logger.ts
|
|
1177
1270
|
/**
|
|
1178
1271
|
* Dataset for `global`-context commands (`clone`, `auth set`, `upgrade
|
|
@@ -2655,14 +2748,7 @@ async function launchGroupMenu(parent, argv) {
|
|
|
2655
2748
|
await launchMenu(COMMAND_REGISTRY, argv, `${parent} — choose a subcommand:`, `Run \`holocron ${parent} --help\` to see available ${parent} subcommands.`, parent.split(" "));
|
|
2656
2749
|
}
|
|
2657
2750
|
/** The hidden `$0` of a command group: bare `holocron <group>` opens the menu at that group. */
|
|
2658
|
-
const groupMenu = (parent) => (
|
|
2659
|
-
command: "$0",
|
|
2660
|
-
describe: false,
|
|
2661
|
-
builder: (y) => y,
|
|
2662
|
-
handler: async (argv) => {
|
|
2663
|
-
await launchGroupMenu(parent, argv);
|
|
2664
|
-
}
|
|
2665
|
-
});
|
|
2751
|
+
const groupMenu = (parent) => groupMenu$1(parent, launchGroupMenu);
|
|
2666
2752
|
// src/cli-support/parse-scope/parse-scope.ts
|
|
2667
2753
|
/** `--scope` / `--github-secret-scope`: `repo`, `env=<name>` or `org=<name>`. */
|
|
2668
2754
|
function parseScope(s) {
|
|
@@ -2680,17 +2766,7 @@ function parseScope(s) {
|
|
|
2680
2766
|
// src/cli-support/token-context/token-context.ts
|
|
2681
2767
|
/** Parses --token values and returns the context spread, or null on parse error (exits with code 1). */
|
|
2682
2768
|
function tokenContext(rawTokens) {
|
|
2683
|
-
|
|
2684
|
-
try {
|
|
2685
|
-
return parseTokenArgs(rawTokens);
|
|
2686
|
-
} catch (err) {
|
|
2687
|
-
if (err instanceof TokenParseError) {
|
|
2688
|
-
reportError(`--token: ${err.message}`);
|
|
2689
|
-
process.exitCode = 1;
|
|
2690
|
-
return null;
|
|
2691
|
-
}
|
|
2692
|
-
throw err;
|
|
2693
|
-
}
|
|
2769
|
+
return tokenContext$1(rawTokens, reportError);
|
|
2694
2770
|
}
|
|
2695
2771
|
// src/plugin/capabilities/capabilities.ts
|
|
2696
2772
|
/** How many providers each capability resolves to: one (`"single"`) or several active at once (`"many"`). */
|
|
@@ -22805,32 +22881,26 @@ const tunnelCommand = {
|
|
|
22805
22881
|
builder: (y) => y.command(tunnelUpCommand).command(groupMenu("tunnel")),
|
|
22806
22882
|
handler: () => {}
|
|
22807
22883
|
};
|
|
22808
|
-
//
|
|
22809
|
-
const
|
|
22884
|
+
// ../kyber/dist/notifier.mjs
|
|
22885
|
+
const CACHE_FILE = "update-check.json";
|
|
22810
22886
|
const CACHE_TTL_MS = 864e5;
|
|
22811
22887
|
const FETCH_TIMEOUT_MS = 3e3;
|
|
22812
|
-
function
|
|
22813
|
-
return env.get("HOLOCRON_CACHE_DIR") ?? join(homedir(), ".cache", "holocron");
|
|
22814
|
-
}
|
|
22815
|
-
function getCachePath() {
|
|
22816
|
-
return join(getCacheDir(), "update-check.json");
|
|
22817
|
-
}
|
|
22818
|
-
function readCache() {
|
|
22888
|
+
function readCache(cacheDir) {
|
|
22819
22889
|
try {
|
|
22820
|
-
return JSON.parse(readFileSync(
|
|
22890
|
+
return JSON.parse(readFileSync(join(cacheDir, CACHE_FILE), "utf8"));
|
|
22821
22891
|
} catch {
|
|
22822
22892
|
return null;
|
|
22823
22893
|
}
|
|
22824
22894
|
}
|
|
22825
|
-
function writeCache(entry) {
|
|
22895
|
+
function writeCache(cacheDir, entry) {
|
|
22826
22896
|
try {
|
|
22827
|
-
mkdirSync(
|
|
22828
|
-
writeFileSync(
|
|
22897
|
+
mkdirSync(cacheDir, { recursive: true });
|
|
22898
|
+
writeFileSync(join(cacheDir, CACHE_FILE), JSON.stringify(entry));
|
|
22829
22899
|
} catch {}
|
|
22830
22900
|
}
|
|
22831
|
-
async function fetchLatestVersion(channel) {
|
|
22901
|
+
async function fetchLatestVersion(name, channel) {
|
|
22832
22902
|
try {
|
|
22833
|
-
const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(
|
|
22903
|
+
const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(name)}`, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
22834
22904
|
if (!res.ok) return null;
|
|
22835
22905
|
const data = await res.json();
|
|
22836
22906
|
return data["dist-tags"][channel] ?? data["dist-tags"]["latest"] ?? null;
|
|
@@ -22841,6 +22911,10 @@ async function fetchLatestVersion(channel) {
|
|
|
22841
22911
|
function getChannel(version) {
|
|
22842
22912
|
return /^[^-]+-([a-zA-Z]+)/.exec(version)?.[1] ?? "latest";
|
|
22843
22913
|
}
|
|
22914
|
+
/**
|
|
22915
|
+
* Whether `latest` is newer than `current`: release parts compare as numbers, a stable release is newer than any
|
|
22916
|
+
* prerelease of it, and prereleases compare segment by segment. A leading `v` is ignored.
|
|
22917
|
+
*/
|
|
22844
22918
|
function isUpdateAvailable(current, latest) {
|
|
22845
22919
|
const normalize = (v) => v.replace(/^v/, "");
|
|
22846
22920
|
const c = normalize(current);
|
|
@@ -22880,8 +22954,7 @@ function isUpdateAvailable(current, latest) {
|
|
|
22880
22954
|
}
|
|
22881
22955
|
return false;
|
|
22882
22956
|
}
|
|
22883
|
-
function formatNotice(current, latest) {
|
|
22884
|
-
const installCmd = `npm install -g ${PACKAGE_NAME}`;
|
|
22957
|
+
function formatNotice(current, latest, installCmd) {
|
|
22885
22958
|
const raw1 = `Update available: ${current} → ${latest}`;
|
|
22886
22959
|
const raw2 = `Run ${installCmd} to update`;
|
|
22887
22960
|
const width = Math.max(raw1.length, raw2.length) + 4;
|
|
@@ -22897,25 +22970,51 @@ function formatNotice(current, latest) {
|
|
|
22897
22970
|
""
|
|
22898
22971
|
].join("\n");
|
|
22899
22972
|
}
|
|
22900
|
-
|
|
22901
|
-
|
|
22973
|
+
/**
|
|
22974
|
+
* Looks for a newer version of a package on npm, at most once a day, and returns a function that prints a boxed notice to
|
|
22975
|
+
* stderr, or `null` when there is nothing to say. It is best-effort: a network error, a bad answer or an unwritable cache
|
|
22976
|
+
* is `null`, never a thrown error. It says nothing in CI or when `NO_UPDATE_NOTIFIER` is set. A prerelease is compared
|
|
22977
|
+
* with the newest version on its own channel (`2.0.0-alpha.3` with the `alpha` tag).
|
|
22978
|
+
*/
|
|
22979
|
+
async function checkForUpdates$1(options) {
|
|
22980
|
+
const { name, currentVersion, cacheDir } = options;
|
|
22981
|
+
const env = options.env ?? process.env;
|
|
22982
|
+
if (env["CI"] || env["NO_UPDATE_NOTIFIER"]) return null;
|
|
22902
22983
|
const channel = getChannel(currentVersion);
|
|
22903
|
-
const cache = readCache();
|
|
22984
|
+
const cache = readCache(cacheDir);
|
|
22904
22985
|
const now = Date.now();
|
|
22905
22986
|
let latestVersion = null;
|
|
22906
22987
|
if (cache && now - cache.checkedAt < CACHE_TTL_MS) latestVersion = cache.latestVersion;
|
|
22907
22988
|
else {
|
|
22908
|
-
latestVersion = await fetchLatestVersion(channel);
|
|
22909
|
-
if (latestVersion) writeCache({
|
|
22989
|
+
latestVersion = await fetchLatestVersion(name, channel);
|
|
22990
|
+
if (latestVersion) writeCache(cacheDir, {
|
|
22910
22991
|
latestVersion,
|
|
22911
22992
|
checkedAt: now
|
|
22912
22993
|
});
|
|
22913
22994
|
}
|
|
22914
22995
|
if (!latestVersion || !isUpdateAvailable(currentVersion, latestVersion)) return null;
|
|
22996
|
+
const installCommand = options.installCommand ?? `npm install -g ${name}`;
|
|
22915
22997
|
return () => {
|
|
22916
|
-
process.stderr.write(formatNotice(currentVersion, latestVersion) + "\n");
|
|
22998
|
+
process.stderr.write(formatNotice(currentVersion, latestVersion, installCommand) + "\n");
|
|
22917
22999
|
};
|
|
22918
23000
|
}
|
|
23001
|
+
// src/update-notifier/update-notifier.ts
|
|
23002
|
+
const PACKAGE_NAME = "@theholocron/cli";
|
|
23003
|
+
/**
|
|
23004
|
+
* Looks for a newer `@theholocron/cli` and returns a function that prints the notice, or `null` when there is none. The
|
|
23005
|
+
* answer is kept in `HOLOCRON_CACHE_DIR`, `~/.cache/holocron` by default.
|
|
23006
|
+
*/
|
|
23007
|
+
function checkForUpdates(currentVersion) {
|
|
23008
|
+
return checkForUpdates$1({
|
|
23009
|
+
name: PACKAGE_NAME,
|
|
23010
|
+
currentVersion,
|
|
23011
|
+
cacheDir: env.get("HOLOCRON_CACHE_DIR") ?? join(homedir(), ".cache", "holocron"),
|
|
23012
|
+
env: {
|
|
23013
|
+
CI: env.get("CI"),
|
|
23014
|
+
NO_UPDATE_NOTIFIER: env.get("NO_UPDATE_NOTIFIER")
|
|
23015
|
+
}
|
|
23016
|
+
});
|
|
23017
|
+
}
|
|
22919
23018
|
// src/cli.ts
|
|
22920
23019
|
const { version: CLI_VERSION } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
|
|
22921
23020
|
/** Whether to print the correlation id at command end (`--debug` / `--verbose`). */
|
|
@@ -22926,25 +23025,17 @@ let finishCommand = () => {};
|
|
|
22926
23025
|
/** Set by `.fail()` once it has printed an error, so the outer catch doesn't repeat it. */
|
|
22927
23026
|
let errorReported = false;
|
|
22928
23027
|
try {
|
|
22929
|
-
await yargs(hideBin(process.argv)).scriptName("").usage("holocron <command> [options]").version(CLI_VERSION).alias("version", "v").parserConfiguration({ "populate--": true })
|
|
22930
|
-
|
|
22931
|
-
|
|
22932
|
-
|
|
22933
|
-
}).option("skip-dry-run", {
|
|
23028
|
+
await addGlobalOptions(yargs(hideBin(process.argv)).scriptName("").usage("holocron <command> [options]").version(CLI_VERSION).alias("version", "v").parserConfiguration({ "populate--": true }), { describe: {
|
|
23029
|
+
dryRun: "Print what would be mutated without calling capability mutators. Commands branch on this; read-only commands ignore it.",
|
|
23030
|
+
token: "Vendor token override for plugins. Bare form: --token <value> (fallback for all plugins, single-plugin commands). Keyed form: --token vendor=value (targets a specific provider; repeat for each). Example: --token github=ghp_xxx --token vercel=v_yyy",
|
|
23031
|
+
cwd: "Directory to search for holocron.config.json"
|
|
23032
|
+
} }).option("skip-dry-run", {
|
|
22934
23033
|
type: "boolean",
|
|
22935
23034
|
default: false,
|
|
22936
23035
|
describe: "Interactive mode only: skip the automatic dry-run preview for a dry-run-capable command and run for real immediately."
|
|
22937
|
-
}).option("token", {
|
|
22938
|
-
type: "string",
|
|
22939
|
-
array: true,
|
|
22940
|
-
describe: "Vendor token override for plugins. Bare form: --token <value> (fallback for all plugins, single-plugin commands). Keyed form: --token vendor=value (targets a specific provider; repeat for each). Example: --token github=ghp_xxx --token vercel=v_yyy"
|
|
22941
23036
|
}).option("org", {
|
|
22942
23037
|
type: "string",
|
|
22943
23038
|
describe: "Active org name for namespaced keyring lookup. Overrides HOLOCRON_ORG env var and the `org` field in holocron.config.ts. Example: --org theholocron"
|
|
22944
|
-
}).option("cwd", {
|
|
22945
|
-
type: "string",
|
|
22946
|
-
default: process.cwd(),
|
|
22947
|
-
describe: "Directory to search for holocron.config.json"
|
|
22948
23039
|
}).option("verbose", {
|
|
22949
23040
|
type: "boolean",
|
|
22950
23041
|
default: false,
|