@osdlc/wayfinder 0.0.1-stage → 0.7.1

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 (53) hide show
  1. package/CHANGELOG.md +245 -0
  2. package/CONTRIBUTING.md +62 -0
  3. package/{LICENSE → LICENSE-APACHE} +1 -11
  4. package/LICENSE-MIT +21 -0
  5. package/README.md +505 -2
  6. package/SECURITY.md +44 -0
  7. package/bin/way.js +18 -0
  8. package/dist/app.d.ts +24 -0
  9. package/dist/app.js +24 -0
  10. package/dist/args.d.ts +44 -0
  11. package/dist/args.js +93 -0
  12. package/dist/cache.d.ts +7 -0
  13. package/dist/cache.js +15 -0
  14. package/dist/catalog.d.ts +38 -0
  15. package/dist/catalog.js +61 -0
  16. package/dist/clean-command.d.ts +43 -0
  17. package/dist/clean-command.js +274 -0
  18. package/dist/cli.d.ts +76 -0
  19. package/dist/cli.js +612 -0
  20. package/dist/config-command.d.ts +52 -0
  21. package/dist/config-command.js +342 -0
  22. package/dist/config.d.ts +367 -0
  23. package/dist/config.js +700 -0
  24. package/dist/devlink.d.ts +14 -0
  25. package/dist/devlink.js +30 -0
  26. package/dist/groups.d.ts +34 -0
  27. package/dist/groups.js +38 -0
  28. package/dist/guide.d.ts +32 -0
  29. package/dist/guide.js +411 -0
  30. package/dist/http.d.ts +22 -0
  31. package/dist/http.js +149 -0
  32. package/dist/origin-owner.d.ts +14 -0
  33. package/dist/origin-owner.js +69 -0
  34. package/dist/page.d.ts +15 -0
  35. package/dist/page.js +58 -0
  36. package/dist/providers-command.d.ts +40 -0
  37. package/dist/providers-command.js +132 -0
  38. package/dist/serve.d.ts +97 -0
  39. package/dist/serve.js +678 -0
  40. package/dist/tools.d.ts +46 -0
  41. package/dist/tools.js +102 -0
  42. package/dist/trust-command.d.ts +33 -0
  43. package/dist/trust-command.js +221 -0
  44. package/dist/trust-store.d.ts +18 -0
  45. package/dist/trust-store.js +46 -0
  46. package/dist/tui.d.ts +178 -0
  47. package/dist/tui.js +846 -0
  48. package/dist/web/main.js +2315 -0
  49. package/dist/web/page.html +110 -0
  50. package/dist/web/styles.css +1514 -0
  51. package/dist/xdg.d.ts +10 -0
  52. package/dist/xdg.js +17 -0
  53. package/package.json +54 -9
package/dist/args.js ADDED
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Turning a typed argument tail into argv entries, shared by the terminal's
3
+ * entry line and the page's run bar so the two never disagree about a quote.
4
+ *
5
+ * {@link runArgv} and {@link acceptArgs} are the boundary: what a caller may
6
+ * contribute to a spawn, and what it may not. As pure functions they can be
7
+ * asserted; the route they protect cannot, because succeeding at it hands over
8
+ * the terminal and exits the process.
9
+ */
10
+ /**
11
+ * The argv a task runs with: the caller's arguments bound the way the task's
12
+ * tool expects (`project.runners.invoke`), so `npm run x -- --flag` gets its
13
+ * `--`.
14
+ *
15
+ * The binary is always `task.argv[0]`, from a catalog this process built by
16
+ * reading the repository, never from a request. `/api/run` is reachable by any
17
+ * process on the machine and any site the browser visits, so a caller that
18
+ * could set element 0 could run anything. A tool whose `invoke` changes the
19
+ * binary is refused.
20
+ */
21
+ export function runArgv(project, task, args = []) {
22
+ if (args.length === 0)
23
+ return [...task.argv];
24
+ const argv = project.runners.invoke(task, args);
25
+ if (argv[0] !== task.argv[0]) {
26
+ throw new Error(`${task.runner}: invoke changed the binary from ${task.argv[0]} to ${argv[0]}`);
27
+ }
28
+ return argv;
29
+ }
30
+ /**
31
+ * The argument list from an untrusted JSON body, or an empty one.
32
+ *
33
+ * Non-strings are DROPPED rather than coerced: `String(value)` would quietly
34
+ * hand a spawn `"[object Object]"` or `"null"` as a real argument, and an
35
+ * argument nobody typed is worse than a missing one.
36
+ */
37
+ export function acceptArgs(value) {
38
+ if (!Array.isArray(value))
39
+ return [];
40
+ return value.filter((a) => typeof a === 'string');
41
+ }
42
+ /**
43
+ * Split a typed argument tail the way a shell splits words, and in no other
44
+ * way a shell behaves.
45
+ *
46
+ * Quotes group and a backslash escapes the next character. There is no
47
+ * globbing, no variable expansion, no operators, no substitution: the result
48
+ * goes to an `execvp`-style spawn as separate argv entries, never to a shell,
49
+ * so `*.log` is passed through as the four characters somebody typed. That is
50
+ * the same rule `argv` and `display` exist to keep.
51
+ *
52
+ * Splitting rather than `.split(/\s+/)` for exactly one reason: a quoted
53
+ * `"two words"` has to stay ONE argument.
54
+ */
55
+ export function splitArgs(input) {
56
+ const out = [];
57
+ let current = '';
58
+ let started = false;
59
+ let quote = null;
60
+ for (let i = 0; i < input.length; i++) {
61
+ const ch = input[i];
62
+ if (ch === '\\' && i + 1 < input.length) {
63
+ current += input[++i];
64
+ started = true;
65
+ continue;
66
+ }
67
+ if (quote === null && (ch === '"' || ch === "'")) {
68
+ quote = ch;
69
+ started = true;
70
+ continue;
71
+ }
72
+ if (quote === ch) {
73
+ quote = null;
74
+ continue;
75
+ }
76
+ if (quote === null && /\s/.test(ch)) {
77
+ if (started) {
78
+ out.push(current);
79
+ current = '';
80
+ started = false;
81
+ }
82
+ continue;
83
+ }
84
+ current += ch;
85
+ started = true;
86
+ }
87
+ // An unterminated quote keeps what was typed rather than dropping it. The
88
+ // user is mid-word; losing their text would be worse than passing a token
89
+ // they can see in the command echoed above the run.
90
+ if (started)
91
+ out.push(current);
92
+ return out;
93
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Where stored runner probes live: `$XDG_CACHE_HOME/wayfinder`, else
3
+ * `~/.cache/wayfinder`. `@osdlc/system-model` owns the layout inside it.
4
+ */
5
+ export declare function cacheDir(env?: Record<string, string | undefined>, home?: string): string;
6
+ /** The old waypost cache directory. Never read; `way clean` offers to remove it. */
7
+ export declare function legacyCacheDir(env?: Record<string, string | undefined>, home?: string): string;
package/dist/cache.js ADDED
@@ -0,0 +1,15 @@
1
+ import { homedir } from 'node:os';
2
+ import { join } from 'node:path';
3
+ import { xdgHome } from '@osdlc/trust-repo';
4
+ import { APP, LEGACY_APP } from "./app.js";
5
+ /**
6
+ * Where stored runner probes live: `$XDG_CACHE_HOME/wayfinder`, else
7
+ * `~/.cache/wayfinder`. `@osdlc/system-model` owns the layout inside it.
8
+ */
9
+ export function cacheDir(env = process.env, home = homedir()) {
10
+ return join(xdgHome(env, home, 'XDG_CACHE_HOME', '.cache'), APP);
11
+ }
12
+ /** The old waypost cache directory. Never read; `way clean` offers to remove it. */
13
+ export function legacyCacheDir(env = process.env, home = homedir()) {
14
+ return join(xdgHome(env, home, 'XDG_CACHE_HOME', '.cache'), LEGACY_APP);
15
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The one place wayfinder asks `@osdlc/system-model` for a catalog: detect the
3
+ * repository, then collect (or read the cache) with the options wayfinder
4
+ * resolved from flags, config and trust.
5
+ */
6
+ import { type CachedCatalog, type Catalog, type DiscoveryMode, type Project, type RunnerCacheState, type ToolDef } from '@osdlc/system-model/detect';
7
+ /**
8
+ * Everything one collection needs: detection settings and runner selection
9
+ * together, because both come from the same flags and config keys.
10
+ */
11
+ export interface WayOptions {
12
+ /** Restrict to these runner ids. */
13
+ only?: string[] | undefined;
14
+ /** Skip these runner ids. */
15
+ exclude?: string[] | undefined;
16
+ /** Let runners and `describe` functions run the repository's own tools. */
17
+ allowExec?: boolean | undefined;
18
+ /** Appended to a withheld runner's diagnostic. */
19
+ execWithheldHint?: string | undefined;
20
+ discovery?: DiscoveryMode | 'auto' | undefined;
21
+ excludePaths?: string[] | undefined;
22
+ signal?: AbortSignal | undefined;
23
+ }
24
+ /** The built-in tools plus `extra`. Throws when two tools share an id. */
25
+ export declare function makeProject(extra?: readonly ToolDef[]): Project;
26
+ /** Detect, collect, and store each runner's result under `store`. */
27
+ export declare function collectAndCache(project: Project, root: string, options: WayOptions, store: string): Promise<Catalog>;
28
+ /** Detect, then read what `store` holds, without running any runner. */
29
+ export declare function readCachedCatalog(project: Project, root: string, options: WayOptions, store: string): Promise<CachedCatalog>;
30
+ /** Every report in `catalog`, marked fresh: the verdict right after a probe. */
31
+ export declare function freshStates(catalog: Catalog): RunnerCacheState[];
32
+ /** True when something came out of the store, not only withheld reports. */
33
+ export declare function fromStore(cached: CachedCatalog): boolean;
34
+ /**
35
+ * A copy of `catalog` with its reports grouped (tasks, dependencies, tools,
36
+ * git hooks) and, within a group, in the configured order.
37
+ */
38
+ export declare function orderedCatalog(catalog: Catalog, order: string[] | undefined): Catalog;
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The one place wayfinder asks `@osdlc/system-model` for a catalog: detect the
3
+ * repository, then collect (or read the cache) with the options wayfinder
4
+ * resolved from flags, config and trust.
5
+ */
6
+ import { builtins } from '@osdlc/system-model/builtins';
7
+ import { createProject, } from '@osdlc/system-model/detect';
8
+ import { orderRunners } from "./config.js";
9
+ import { groupRank } from "./groups.js";
10
+ /** The built-in tools plus `extra`. Throws when two tools share an id. */
11
+ export function makeProject(extra = []) {
12
+ return createProject({ tools: [...builtins, ...extra] });
13
+ }
14
+ function detect(project, root, o) {
15
+ return project.detect(root, {
16
+ allowExec: o.allowExec ?? false,
17
+ discovery: o.discovery,
18
+ excludePaths: o.excludePaths,
19
+ signal: o.signal,
20
+ });
21
+ }
22
+ function collectOptions(o) {
23
+ return {
24
+ only: o.only,
25
+ exclude: o.exclude,
26
+ allowExec: o.allowExec ?? false,
27
+ execWithheldHint: o.execWithheldHint,
28
+ signal: o.signal,
29
+ };
30
+ }
31
+ /** Detect, collect, and store each runner's result under `store`. */
32
+ export async function collectAndCache(project, root, options, store) {
33
+ const profile = await detect(project, root, options);
34
+ return project.runners.collectAndCache(profile, store, collectOptions(options));
35
+ }
36
+ /** Detect, then read what `store` holds, without running any runner. */
37
+ export async function readCachedCatalog(project, root, options, store) {
38
+ const profile = await detect(project, root, options);
39
+ return project.runners.readCached(profile, store, collectOptions(options));
40
+ }
41
+ /** Every report in `catalog`, marked fresh: the verdict right after a probe. */
42
+ export function freshStates(catalog) {
43
+ return catalog.reports.map((r) => ({
44
+ runner: r.runner,
45
+ state: 'fresh',
46
+ estimateMs: null,
47
+ slow: false,
48
+ }));
49
+ }
50
+ /** True when something came out of the store, not only withheld reports. */
51
+ export function fromStore(cached) {
52
+ return cached.catalog !== null && cached.runners.some((r) => r.ageMs !== undefined);
53
+ }
54
+ /**
55
+ * A copy of `catalog` with its reports grouped (tasks, dependencies, tools,
56
+ * git hooks) and, within a group, in the configured order.
57
+ */
58
+ export function orderedCatalog(catalog, order) {
59
+ const reports = orderRunners(catalog.reports, order).sort((a, b) => groupRank(a.runner) - groupRank(b.runner));
60
+ return { ...catalog, reports };
61
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The `clean` subcommand: the three stores wayfinder keeps outside your
3
+ * repositories (cache, trust, config). `--cache` and `--trust` also clear
4
+ * the old waypost cache and trust store. Each is listed only when it holds
5
+ * something.
6
+ *
7
+ * ## Nothing is removed unless asked
8
+ *
9
+ * Bare `clean` REPORTS: what each store is, where it is, and whether anything
10
+ * is in it. A `--dry-run` flag would put the safe behaviour behind a flag people
11
+ * forget, so instead the flags name what to remove, and no flag removes nothing.
12
+ *
13
+ * ## Why `--config` alone needs `--yes`
14
+ *
15
+ * The three stores are not equally replaceable, and the guard follows that
16
+ * rather than being uniform for tidiness:
17
+ *
18
+ * - the CACHE is derived. Deleting it costs one slow probe.
19
+ * - the TRUST store is consent. Deleting it costs re-answering a question
20
+ * you have already answered, per repository — annoying, not lossy.
21
+ * - the CONFIG is the only thing here a person WROTE. Nothing regenerates it.
22
+ *
23
+ * So `--config` (and `--all`, which includes it) additionally wants `--yes`.
24
+ *
25
+ * ## What it will not touch
26
+ *
27
+ * Anything inside a repository. `wayfinder.config.json` is a project file that
28
+ * belongs to whoever wrote it, and a tool that deletes files from a checkout
29
+ * because it was asked to clean its own data has misunderstood whose data it
30
+ * is. Only paths under the user's home (or their XDG overrides) are candidates.
31
+ *
32
+ * Everything outside that is injected — `stdout`, `stderr`, `env`, `home` — so
33
+ * a test cannot read or delete the developer's real stores.
34
+ */
35
+ import { type CliIo } from '@osdlc/cli-tool';
36
+ /** `CliIo` plus the environment this command needs injected. */
37
+ export interface CleanCommandIO extends CliIo {
38
+ /** Defaults to `process.env`. Supplies the XDG overrides. */
39
+ env?: Record<string, string | undefined>;
40
+ /** Defaults to `os.homedir()`. The base for every non-XDG path. */
41
+ home?: string;
42
+ }
43
+ export declare function runCleanCommand(toolName: string, argv: string[], io: CleanCommandIO): Promise<number>;
@@ -0,0 +1,274 @@
1
+ /**
2
+ * The `clean` subcommand: the three stores wayfinder keeps outside your
3
+ * repositories (cache, trust, config). `--cache` and `--trust` also clear
4
+ * the old waypost cache and trust store. Each is listed only when it holds
5
+ * something.
6
+ *
7
+ * ## Nothing is removed unless asked
8
+ *
9
+ * Bare `clean` REPORTS: what each store is, where it is, and whether anything
10
+ * is in it. A `--dry-run` flag would put the safe behaviour behind a flag people
11
+ * forget, so instead the flags name what to remove, and no flag removes nothing.
12
+ *
13
+ * ## Why `--config` alone needs `--yes`
14
+ *
15
+ * The three stores are not equally replaceable, and the guard follows that
16
+ * rather than being uniform for tidiness:
17
+ *
18
+ * - the CACHE is derived. Deleting it costs one slow probe.
19
+ * - the TRUST store is consent. Deleting it costs re-answering a question
20
+ * you have already answered, per repository — annoying, not lossy.
21
+ * - the CONFIG is the only thing here a person WROTE. Nothing regenerates it.
22
+ *
23
+ * So `--config` (and `--all`, which includes it) additionally wants `--yes`.
24
+ *
25
+ * ## What it will not touch
26
+ *
27
+ * Anything inside a repository. `wayfinder.config.json` is a project file that
28
+ * belongs to whoever wrote it, and a tool that deletes files from a checkout
29
+ * because it was asked to clean its own data has misunderstood whose data it
30
+ * is. Only paths under the user's home (or their XDG overrides) are candidates.
31
+ *
32
+ * Everything outside that is injected — `stdout`, `stderr`, `env`, `home` — so
33
+ * a test cannot read or delete the developer's real stores.
34
+ */
35
+ import { readdir, rm, rmdir, stat } from 'node:fs/promises';
36
+ import { homedir } from 'node:os';
37
+ import { dirname } from 'node:path';
38
+ import { BIN } from "./app.js";
39
+ import { cacheDir, legacyCacheDir } from "./cache.js";
40
+ import { LEGACY_TRUST_STORE_TOOL, TRUST_STORE_TOOL, configLocations } from "./config.js";
41
+ import { EXIT } from '@osdlc/cli-tool';
42
+ import { trustStoreDir } from '@osdlc/trust-repo';
43
+ function usage() {
44
+ return `${BIN} clean — remove the data this tool stores outside your repositories
45
+
46
+ usage: ${BIN} clean [options]
47
+
48
+ (no options) show each store, where it is, and whether it holds anything
49
+ --cache remove stored probe results (derived; costs one slow probe)
50
+ --trust forget which repositories you have trusted
51
+ --config remove your user configuration file (needs --yes)
52
+ --all all three (needs --yes)
53
+ --yes confirm removing something that cannot be regenerated
54
+ --json the same answer as one JSON object, for a script or agent
55
+ -h, --help this text
56
+
57
+ Nothing is removed without one of --cache, --trust, --config or --all.
58
+ Nothing inside a repository is ever touched: a project's own config file
59
+ belongs to that project, not to this tool.
60
+ `;
61
+ }
62
+ /** Bytes under a path, or null when it does not exist. */
63
+ async function weigh(path, file) {
64
+ try {
65
+ const info = await stat(path);
66
+ if (file)
67
+ return info.size;
68
+ let total = 0;
69
+ const walk = async (dir) => {
70
+ for (const entry of await readdir(dir, { withFileTypes: true })) {
71
+ const child = `${dir}/${entry.name}`;
72
+ if (entry.isDirectory())
73
+ await walk(child);
74
+ else
75
+ total += (await stat(child)).size;
76
+ }
77
+ };
78
+ await walk(path);
79
+ return total;
80
+ }
81
+ catch {
82
+ return null;
83
+ }
84
+ }
85
+ function humanBytes(bytes) {
86
+ if (bytes < 1024)
87
+ return `${bytes} B`;
88
+ if (bytes < 1024 * 1024)
89
+ return `${Math.round(bytes / 1024)} KB`;
90
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
91
+ }
92
+ function storesFor(env, home) {
93
+ // The root is irrelevant to the USER config path, which is what this command
94
+ // touches; the project layer is deliberately out of scope. `home` stands in
95
+ // so the call is well-formed without pretending a repository is involved.
96
+ const user = configLocations(home, env, home).user;
97
+ return [
98
+ {
99
+ key: 'cache',
100
+ flag: '--cache',
101
+ what: 'stored probe results',
102
+ path: cacheDir(env, home),
103
+ file: false,
104
+ },
105
+ {
106
+ key: 'cache',
107
+ flag: '--cache',
108
+ what: 'stored probe results under the old waypost name',
109
+ path: legacyCacheDir(env, home),
110
+ file: false,
111
+ legacy: true,
112
+ },
113
+ {
114
+ key: 'trust',
115
+ flag: '--trust',
116
+ what: 'repositories you have trusted',
117
+ path: trustStoreDir(TRUST_STORE_TOOL, env, home),
118
+ file: false,
119
+ },
120
+ {
121
+ key: 'trust',
122
+ flag: '--trust',
123
+ what: 'repositories you trusted under the old waypost name',
124
+ path: trustStoreDir(LEGACY_TRUST_STORE_TOOL, env, home),
125
+ file: false,
126
+ legacy: true,
127
+ },
128
+ { key: 'config', flag: '--config', what: 'your user configuration', path: user, file: true },
129
+ ];
130
+ }
131
+ /** A store's reportable fields — `file` is an implementation detail, not an answer. */
132
+ function reportOf(store, bytes, removed) {
133
+ return { key: store.key, flag: store.flag, what: store.what, path: store.path, bytes, removed };
134
+ }
135
+ function parse(argv) {
136
+ const chosen = new Set();
137
+ let help = false;
138
+ let yes = false;
139
+ let json = false;
140
+ for (const arg of argv) {
141
+ switch (arg) {
142
+ case '-h':
143
+ case '--help':
144
+ help = true;
145
+ break;
146
+ case '--yes':
147
+ yes = true;
148
+ break;
149
+ case '--json':
150
+ json = true;
151
+ break;
152
+ case '--cache':
153
+ chosen.add('cache');
154
+ break;
155
+ case '--trust':
156
+ chosen.add('trust');
157
+ break;
158
+ case '--config':
159
+ chosen.add('config');
160
+ break;
161
+ case '--all':
162
+ chosen.add('cache').add('trust').add('config');
163
+ break;
164
+ default:
165
+ return { error: `unknown option: ${arg}` };
166
+ }
167
+ }
168
+ return { help, yes, json, chosen };
169
+ }
170
+ export async function runCleanCommand(toolName, argv, io) {
171
+ const parsed = parse(argv);
172
+ if ('error' in parsed) {
173
+ io.stderr(`${toolName}: ${parsed.error}\n\n${usage()}`);
174
+ return EXIT.usage;
175
+ }
176
+ if (parsed.help) {
177
+ io.stdout(usage());
178
+ return EXIT.ok;
179
+ }
180
+ const env = io.env ?? process.env;
181
+ const home = io.home ?? homedir();
182
+ const stores = storesFor(env, home);
183
+ // The report. Also what a bare `clean` prints, which is why it is built
184
+ // before anything is removed rather than inside the removal branch.
185
+ if (parsed.chosen.size === 0) {
186
+ const reports = [];
187
+ for (const store of stores) {
188
+ const bytes = await weigh(store.path, store.file);
189
+ if (store.legacy === true && bytes === null)
190
+ continue;
191
+ reports.push(reportOf(store, bytes, false));
192
+ }
193
+ if (parsed.json) {
194
+ io.stdout(`${JSON.stringify({ stores: reports }, null, 2)}\n`);
195
+ return EXIT.ok;
196
+ }
197
+ const lines = [`${toolName} stores three things outside your repositories:\n`];
198
+ for (const report of reports) {
199
+ const held = report.bytes === null ? 'nothing stored' : humanBytes(report.bytes);
200
+ lines.push(` ${report.flag.padEnd(9)} ${report.what}`);
201
+ lines.push(` ${' '.repeat(9)} ${report.path} (${held})`);
202
+ }
203
+ lines.push(`\nPass a flag above to remove one, or --all for every one.`);
204
+ lines.push(`Nothing was removed.\n`);
205
+ io.stdout(lines.join('\n'));
206
+ return EXIT.ok;
207
+ }
208
+ if (parsed.chosen.has('config') && !parsed.yes) {
209
+ io.stderr(`${toolName}: removing your user configuration needs --yes.\n` +
210
+ `Nothing else here is written by hand, so nothing else asks.\n`);
211
+ return EXIT.usage;
212
+ }
213
+ const reports = [];
214
+ let removed = 0;
215
+ let failed = false;
216
+ for (const store of stores) {
217
+ if (!parsed.chosen.has(store.key))
218
+ continue;
219
+ const size = await weigh(store.path, store.file);
220
+ if (size === null) {
221
+ if (store.legacy === true)
222
+ continue;
223
+ reports.push(reportOf(store, null, false));
224
+ if (!parsed.json)
225
+ io.stdout(`${store.what}: nothing stored at ${store.path}\n`);
226
+ continue;
227
+ }
228
+ try {
229
+ await rm(store.path, { recursive: true, force: true });
230
+ // A config file leaves its directory behind. Remove it when this was the
231
+ // last thing in it, and leave it alone when it was not — the directory is
232
+ // shared with anything else a future version puts there.
233
+ if (store.file) {
234
+ const dir = dirname(store.path);
235
+ try {
236
+ if ((await readdir(dir)).length === 0)
237
+ await rmdir(dir);
238
+ }
239
+ catch {
240
+ // Not ours to insist on. The file is gone, which is what was asked.
241
+ }
242
+ }
243
+ reports.push(reportOf(store, size, true));
244
+ if (!parsed.json) {
245
+ io.stdout(`removed ${store.what} (${humanBytes(size)}) from ${store.path}\n`);
246
+ }
247
+ removed += 1;
248
+ }
249
+ catch (err) {
250
+ io.stderr(`${toolName}: could not remove ${store.path}: ${String(err)}\n`);
251
+ // Recorded and then abandoned, exactly as before: a store that would not
252
+ // delete is not a reason to keep deleting the others.
253
+ reports.push(reportOf(store, size, false));
254
+ failed = true;
255
+ break;
256
+ }
257
+ }
258
+ // One document, printed once, so a --json caller parses a single object
259
+ // whether the run finished or stopped on a failure.
260
+ if (parsed.json)
261
+ io.stdout(`${JSON.stringify({ stores: reports }, null, 2)}\n`);
262
+ if (failed)
263
+ return EXIT.error;
264
+ if (removed > 0 && parsed.chosen.has('trust')) {
265
+ // An aside rather than the answer, so under --json it goes to stderr and
266
+ // leaves the document one object.
267
+ const note = 'Trusted repositories will ask again the next time you read them.\n';
268
+ if (parsed.json)
269
+ io.stderr(note);
270
+ else
271
+ io.stdout(`\n${note}`);
272
+ }
273
+ return EXIT.ok;
274
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * `way`: browse and run every task in a repository.
3
+ *
4
+ * wayfinder is willing to run a repository's tools in principle (`allowExec:
5
+ * true` by default): you are standing in your own repository, and a task
6
+ * browser that cannot see the build graph is not much of a browser.
7
+ * `--no-exec` opts out.
8
+ *
9
+ * The default is not the gate. Per-repository trust is: `@osdlc/trust-repo`'s
10
+ * `policyExecGate` combines the configured value with the marker store and the
11
+ * user file's `trust.paths`/`trust.owners` policy, so willingness becomes
12
+ * execution only once a person, or a policy they configured, has said yes to
13
+ * this repository. A configured `false` means no exec however trusted the
14
+ * repository is.
15
+ */
16
+ import { type CliIo } from '@osdlc/cli-tool';
17
+ import { type Catalog, type RunnerCacheState } from '@osdlc/system-model/detect';
18
+ import { type Mode } from '@osdlc/system-model/match';
19
+ import { type GuideTool } from './guide.ts';
20
+ /** What the `guide` command needs: the complete help, and what it cannot say. */
21
+ export declare const GUIDE_TOOL: GuideTool;
22
+ /**
23
+ * Optional fields are absent unless their flag was given, so the config layer
24
+ * can answer instead. wayfinder's `allowExec: true` default lives in
25
+ * {@link main}, below that layer.
26
+ */
27
+ interface Flags {
28
+ mode: 'tui' | 'serve' | 'json' | 'list' | 'query';
29
+ dir: string;
30
+ /** Answer --json/--list from the stored probe. The UI surfaces do it always. */
31
+ cached: boolean;
32
+ allowExec?: boolean;
33
+ open: boolean;
34
+ port?: number;
35
+ only?: string[];
36
+ exclude?: string[];
37
+ /**
38
+ * Repeatable: `--exclude-path a --exclude-path b` means both. Passing any
39
+ * at all replaces the configured list, as every other array setting merges.
40
+ */
41
+ excludePaths?: string[];
42
+ discovery?: 'git' | 'walk' | 'auto';
43
+ help: boolean;
44
+ /**
45
+ * `query`'s search terms, and the marker that this IS a query: absent for
46
+ * every other mode, whose one positional is a directory instead.
47
+ */
48
+ terms?: string[];
49
+ /** `query --json`: the matching tasks, rather than one command line each. */
50
+ json: boolean;
51
+ /** `query --exact`, the terminal UI's `^e`. */
52
+ matchMode: Mode;
53
+ /** `query --services`, the terminal UI's `^t`. */
54
+ servicesOnly: boolean;
55
+ /** `--help --all`: the complete {@link USAGE} rather than {@link SHORT_USAGE}. */
56
+ all: boolean;
57
+ /** `--config` modules, as typed. */
58
+ toolModules: string[];
59
+ }
60
+ /**
61
+ * `query` is claimed before the flag parse like `config` and `trust` (see
62
+ * {@link main}), but only because it changes what a positional MEANS, from a
63
+ * directory to search terms. Every collection flag still applies after it,
64
+ * which is why it is not a command with its own flag list.
65
+ */
66
+ export declare function parseArgs(argv: readonly string[], io: CliIo, cwd?: string): Flags | {
67
+ error: string;
68
+ };
69
+ /** `--json`'s document: the catalog, its groups, and the cache verdict under `--cached`. */
70
+ export declare function catalogJson(catalog: Catalog, cache?: RunnerCacheState[]): object;
71
+ /**
72
+ * `env` and `home` are injectable so a test never reads the developer's own
73
+ * config, cache or trust store. `io` defaults to the real process streams.
74
+ */
75
+ export declare function main(argv: string[], env?: Record<string, string | undefined>, home?: string, io?: CliIo): Promise<number>;
76
+ export {};