@osdlc/wayfinder 0.0.0-stage → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +231 -0
  2. package/CONTRIBUTING.md +62 -0
  3. package/LICENSE-APACHE +202 -0
  4. package/LICENSE-MIT +21 -0
  5. package/README.md +507 -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 +72 -3
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Downstream tools: modules that export `ToolDef`s, registered beside the
3
+ * built-ins. A module is code, so where it was named decides whether it loads:
4
+ *
5
+ * --config <module> always; you typed it
6
+ * user config `tools` always; it is your own file
7
+ * project file `tools` only when the repository is trusted and execution
8
+ * is allowed, since the repository wrote it
9
+ *
10
+ * A module exports `tools` (an array), or a default that is an array or has
11
+ * `tools`.
12
+ */
13
+ import type { ToolDef } from '@osdlc/system-model/detect';
14
+ import type { LoadedConfig } from './config.ts';
15
+ /** A tool module that could not be loaded or does not export tools. */
16
+ export declare class ToolModuleError extends Error {
17
+ constructor(message: string);
18
+ }
19
+ /** One registered tool and where it came from. */
20
+ export interface LoadedTool {
21
+ def: ToolDef;
22
+ /** The module path it was loaded from. */
23
+ module: string;
24
+ }
25
+ /** Import one module and return its `ToolDef`s. Throws {@link ToolModuleError}. */
26
+ export declare function loadToolModule(path: string): Promise<ToolDef[]>;
27
+ /** Where tool modules were named, already split by layer. */
28
+ export interface ToolSources {
29
+ /** `--config` values, relative to `cwd`. */
30
+ flag: readonly string[];
31
+ cwd: string;
32
+ config: LoadedConfig;
33
+ home: string;
34
+ /** Whether project-file entries may load: the repository is trusted and execution is allowed. */
35
+ projectAllowed: boolean;
36
+ }
37
+ /**
38
+ * Load every tool module the sources name, in order: flags, user file,
39
+ * project file. Returns the tools and a warning when project entries are
40
+ * skipped because the repository is not trusted or execution is off. A tool id that is built in or defined twice is a
41
+ * {@link ToolModuleError}.
42
+ */
43
+ export declare function loadTools(sources: ToolSources): Promise<{
44
+ tools: LoadedTool[];
45
+ warnings: string[];
46
+ }>;
package/dist/tools.js ADDED
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Downstream tools: modules that export `ToolDef`s, registered beside the
3
+ * built-ins. A module is code, so where it was named decides whether it loads:
4
+ *
5
+ * --config <module> always; you typed it
6
+ * user config `tools` always; it is your own file
7
+ * project file `tools` only when the repository is trusted and execution
8
+ * is allowed, since the repository wrote it
9
+ *
10
+ * A module exports `tools` (an array), or a default that is an array or has
11
+ * `tools`.
12
+ */
13
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
14
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
15
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
16
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
17
+ });
18
+ }
19
+ return path;
20
+ };
21
+ import { dirname, resolve } from 'node:path';
22
+ import { pathToFileURL } from 'node:url';
23
+ import { BUILTIN_TOOL_IDS } from '@osdlc/system-model/builtins';
24
+ import { BIN } from "./app.js";
25
+ import { expandTilde } from "./xdg.js";
26
+ /** A tool module that could not be loaded or does not export tools. */
27
+ export class ToolModuleError extends Error {
28
+ constructor(message) {
29
+ super(message);
30
+ this.name = 'ToolModuleError';
31
+ }
32
+ }
33
+ function isToolDef(value) {
34
+ if (typeof value !== 'object' || value === null)
35
+ return false;
36
+ const v = value;
37
+ return typeof v['id'] === 'string' && typeof v['roles'] === 'object' && v['roles'] !== null;
38
+ }
39
+ /** Import one module and return its `ToolDef`s. Throws {@link ToolModuleError}. */
40
+ export async function loadToolModule(path) {
41
+ let mod;
42
+ try {
43
+ mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(path).href)));
44
+ }
45
+ catch (err) {
46
+ throw new ToolModuleError(`${path}: cannot be loaded: ${err instanceof Error ? err.message : String(err)}`);
47
+ }
48
+ const fromDefault = Array.isArray(mod.default)
49
+ ? mod.default
50
+ : mod.default?.tools;
51
+ const list = mod.tools ?? fromDefault;
52
+ if (!Array.isArray(list)) {
53
+ throw new ToolModuleError(`${path}: export \`tools\`, an array of ToolDefs`);
54
+ }
55
+ const bad = list.findIndex((t) => !isToolDef(t));
56
+ if (bad !== -1) {
57
+ throw new ToolModuleError(`${path}: tools[${bad}] is not a ToolDef (needs an id and roles)`);
58
+ }
59
+ return list;
60
+ }
61
+ /**
62
+ * Load every tool module the sources name, in order: flags, user file,
63
+ * project file. Returns the tools and a warning when project entries are
64
+ * skipped because the repository is not trusted or execution is off. A tool id that is built in or defined twice is a
65
+ * {@link ToolModuleError}.
66
+ */
67
+ export async function loadTools(sources) {
68
+ const { config, home } = sources;
69
+ const paths = [];
70
+ const at = (base, p) => resolve(base, expandTilde(p, home));
71
+ for (const p of sources.flag)
72
+ paths.push(at(sources.cwd, p));
73
+ for (const p of config.layers.user?.tools ?? []) {
74
+ paths.push(at(dirname(config.locations.user), p));
75
+ }
76
+ const warnings = [];
77
+ const projectTools = config.layers.project?.tools ?? [];
78
+ if (projectTools.length > 0) {
79
+ if (sources.projectAllowed) {
80
+ for (const p of projectTools)
81
+ paths.push(at(dirname(config.locations.project), p));
82
+ }
83
+ else {
84
+ warnings.push(`${config.locations.project}: tools not loaded — they need a trusted repository ("${BIN} trust") with execution allowed`);
85
+ }
86
+ }
87
+ const tools = [];
88
+ const builtin = new Set(BUILTIN_TOOL_IDS);
89
+ for (const module of new Set(paths)) {
90
+ for (const def of await loadToolModule(module)) {
91
+ if (builtin.has(def.id)) {
92
+ throw new ToolModuleError(`${module}: tool "${def.id}" is already a built-in tool`);
93
+ }
94
+ const first = tools.find((t) => t.def.id === def.id);
95
+ if (first !== undefined) {
96
+ throw new ToolModuleError(`tool "${def.id}" is defined twice: in ${first.module} and in ${module}`);
97
+ }
98
+ tools.push({ def, module });
99
+ }
100
+ }
101
+ return { tools, warnings };
102
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The `trust` subcommand over `@osdlc/trust-repo`'s marker store
3
+ * (`$XDG_STATE_HOME/wayfinder/trusted/`, plus grants still held in the old
4
+ * `waypost` store; see `trust-store.ts`) and the user file's
5
+ * `trust.paths`/`trust.owners` policy. A root the policy covers reports
6
+ * trusted with no marker, and `--show`/`--untrust` say which layer decided
7
+ * (`by`/`rule`).
8
+ *
9
+ * `stdout`, `stderr`, `env` and `home` are injected, so a test never grants
10
+ * trust on the developer's machine. The caller strips `-C` with
11
+ * `takeConfigDir` and hands in a resolved root.
12
+ */
13
+ import { type CliIo } from '@osdlc/cli-tool';
14
+ /**
15
+ * A VIEW of `CliIo`: the same output seam, plus the environment this command
16
+ * needs injected — not a third pattern alongside `CliIo` and `ConfigCommandIO`.
17
+ */
18
+ export interface TrustCommandIO extends CliIo {
19
+ /** Defaults to `process.env`. Supplies `XDG_STATE_HOME`. */
20
+ env?: Record<string, string | undefined>;
21
+ /** Defaults to `os.homedir()`. The base for the non-XDG state path. */
22
+ home?: string;
23
+ }
24
+ /**
25
+ * `<tool> trust [--untrust|--show|--list]`. `root` is the resolved project
26
+ * root. Returns the exit code.
27
+ *
28
+ * Exit codes follow `runConfigCommand`: 2 for a command that cannot run as
29
+ * typed, decided from the argument list alone; 1 for a well-formed command that
30
+ * failed against the state it found — here, `--untrust` on a root that was
31
+ * never trusted, or a project config file that will not parse.
32
+ */
33
+ export declare function runTrustCommand(toolName: string, root: string, argv: string[], io: TrustCommandIO): Promise<number>;
@@ -0,0 +1,221 @@
1
+ /**
2
+ * The `trust` subcommand over `@osdlc/trust-repo`'s marker store
3
+ * (`$XDG_STATE_HOME/wayfinder/trusted/`, plus grants still held in the old
4
+ * `waypost` store; see `trust-store.ts`) and the user file's
5
+ * `trust.paths`/`trust.owners` policy. A root the policy covers reports
6
+ * trusted with no marker, and `--show`/`--untrust` say which layer decided
7
+ * (`by`/`rule`).
8
+ *
9
+ * `stdout`, `stderr`, `env` and `home` are injected, so a test never grants
10
+ * trust on the developer's machine. The caller strips `-C` with
11
+ * `takeConfigDir` and hands in a resolved root.
12
+ */
13
+ import { homedir } from 'node:os';
14
+ import { EXIT } from '@osdlc/cli-tool';
15
+ import { policyExecGate } from '@osdlc/trust-repo';
16
+ import { APP, BIN } from "./app.js";
17
+ import { ConfigError, PROJECT_CONFIG_FILENAME, loadConfig, trustPolicyFromConfig, trustPolicyOptions, } from "./config.js";
18
+ import { appTrustStore } from "./trust-store.js";
19
+ function usage() {
20
+ return `${BIN} trust — remember that this repository may run subprocesses to be read
21
+
22
+ usage: ${BIN} trust [options]
23
+
24
+ (no options) trust the repository at the resolved root
25
+ --untrust remove this repository's trust
26
+ --show report this root's trust status
27
+ --list every trusted path, one per line
28
+ --json the same answer as one JSON object, for a script or agent
29
+ -C, --dir PATH the directory to inspect (default: cwd)
30
+ -h, --help this text
31
+
32
+ Some runners can only be read by running them — reading moon's task graph
33
+ evaluates the repository's toolchain configuration. Trust is that consent,
34
+ remembered per repository and keyed on the resolved path, so you are asked
35
+ once.
36
+
37
+ Trust is one of two conditions, not the whole gate: execution must also be
38
+ enabled. ${APP} enables it by default, so trust alone is enough unless a
39
+ config file sets allowExec: false. A repository cannot trust itself: allowExec
40
+ in ${PROJECT_CONFIG_FILENAME} cannot raise the gate. Pass --exec instead to
41
+ allow a single run without recording anything. Trust, with execution
42
+ allowed, also loads the tools a project file names.
43
+
44
+ A root can also be trusted with no marker at all, by the user file's
45
+ trust.paths/trust.owners policy ("${BIN} config path" names it; a
46
+ project-layer trust block is ignored the same way allowExec is). --show and
47
+ --json report which layer decided (by=marker|path|owner, and the matching
48
+ rule for a policy hit); the plain form still writes a marker on a
49
+ policy-trusted root, and --untrust says when the policy still covers it after
50
+ the marker is gone.
51
+ `;
52
+ }
53
+ /**
54
+ * Split the mode flag off the argument list.
55
+ *
56
+ * The three modes contradict each other and two of them WRITE, so a
57
+ * last-one-wins reading would act on a store the user named the other of. A
58
+ * pair is a usage error instead, as `--user` and `--project` are for `config`.
59
+ */
60
+ function takeMode(argv) {
61
+ let mode;
62
+ let help = false;
63
+ let json = false;
64
+ for (const arg of argv) {
65
+ if (arg === '-h' || arg === '--help') {
66
+ help = true;
67
+ }
68
+ else if (arg === '--json') {
69
+ // Not a mode: it asks the SAME question in the machine form, so it
70
+ // combines with each of the three rather than contradicting them.
71
+ json = true;
72
+ }
73
+ else if (arg === '--untrust' || arg === '--show' || arg === '--list') {
74
+ const named = arg.slice(2);
75
+ if (mode !== undefined && mode !== named) {
76
+ return { error: `${arg} and --${mode} ask different things; give at most one` };
77
+ }
78
+ mode = named;
79
+ }
80
+ else if (arg.startsWith('-')) {
81
+ return { error: `unknown option: ${arg}` };
82
+ }
83
+ else {
84
+ return { error: `trust takes no arguments, got ${arg}` };
85
+ }
86
+ }
87
+ return { ...(mode !== undefined ? { mode } : {}), help, json };
88
+ }
89
+ /**
90
+ * The USER-layer trust.paths/trust.owners policy for `root`, or the rendered
91
+ * message when the project's config file will not parse. Lazy — computed only
92
+ * by the modes that need a per-root decision (`show`, `untrust`, the plain
93
+ * grant), so `--list` and `--help` ask nothing about a particular root and a
94
+ * broken project config cannot break them, matching how `main()` only loads
95
+ * config for the collection path.
96
+ */
97
+ async function loadPolicy(root, toolName, env, home) {
98
+ try {
99
+ const cfg = await loadConfig(root, env, home);
100
+ return trustPolicyFromConfig(cfg.effective);
101
+ }
102
+ catch (err) {
103
+ if (err instanceof ConfigError)
104
+ return { error: err.message };
105
+ throw err;
106
+ }
107
+ }
108
+ /**
109
+ * `<tool> trust [--untrust|--show|--list]`. `root` is the resolved project
110
+ * root. Returns the exit code.
111
+ *
112
+ * Exit codes follow `runConfigCommand`: 2 for a command that cannot run as
113
+ * typed, decided from the argument list alone; 1 for a well-formed command that
114
+ * failed against the state it found — here, `--untrust` on a root that was
115
+ * never trusted, or a project config file that will not parse.
116
+ */
117
+ export async function runTrustCommand(toolName, root, argv, io) {
118
+ const env = io.env ?? process.env;
119
+ const home = io.home ?? homedir();
120
+ // Keyed on the app name, not `toolName`, so a grant lands in one store
121
+ // whichever name the caller printed.
122
+ const store = appTrustStore({ env, home });
123
+ const policyOptions = trustPolicyOptions(home);
124
+ const taken = takeMode(argv);
125
+ if ('error' in taken) {
126
+ io.stderr(`${toolName}: ${taken.error}\n\n${usage()}`);
127
+ return EXIT.usage;
128
+ }
129
+ if (taken.help) {
130
+ io.stdout(usage());
131
+ return EXIT.ok;
132
+ }
133
+ /**
134
+ * The machine form of every root-scoped answer, in ONE shape across `trust`,
135
+ * `--untrust` and `--show`: which root was decided on, whether it is trusted
136
+ * now, whether THIS invocation changed the store, and which layer decided
137
+ * (`by`/`rule`, mirroring `sdlc repo trust --show`). Three questions with
138
+ * three JSON shapes would make a caller branch on the flag it just passed.
139
+ */
140
+ const rootAnswer = (path, trusted, changed, by, rule) => `${JSON.stringify({ root: path, trusted, changed, by, rule })}\n`;
141
+ switch (taken.mode) {
142
+ case 'list': {
143
+ const paths = await store.list();
144
+ if (taken.json)
145
+ io.stdout(`${JSON.stringify({ trusted: paths })}\n`);
146
+ else
147
+ for (const path of paths)
148
+ io.stdout(`${path}\n`);
149
+ return EXIT.ok;
150
+ }
151
+ case 'show': {
152
+ // Both answers are exit 0: "not trusted" is a fact this command was asked
153
+ // for, not a failure to report it.
154
+ const policy = await loadPolicy(root, toolName, env, home);
155
+ if ('error' in policy) {
156
+ io.stderr(`${toolName}: ${policy.error}\n`);
157
+ return EXIT.error;
158
+ }
159
+ // Decided through the SAME function that gates a real run
160
+ // (`policyExecGate`), so this answer cannot drift from what actually
161
+ // governs execution. `configured: true` asks "if execution were on,
162
+ // would this root's marker or policy allow it" — the only question
163
+ // `--show` has, so `allowExec`/`reason` are unused here.
164
+ const gate = await policyExecGate(store, policy, { root, configured: true }, policyOptions);
165
+ io.stdout(taken.json
166
+ ? rootAnswer(gate.root, gate.trusted, false, gate.by, gate.rule)
167
+ : `${gate.trusted ? 'trusted' : 'not trusted'} ${gate.root}\n`);
168
+ return EXIT.ok;
169
+ }
170
+ case 'untrust': {
171
+ const policy = await loadPolicy(root, toolName, env, home);
172
+ if ('error' in policy) {
173
+ io.stderr(`${toolName}: ${policy.error}\n`);
174
+ return EXIT.error;
175
+ }
176
+ // Resolved first so the message names the path the store is keyed on,
177
+ // which is the path a later --list will show.
178
+ const resolved = await store.resolveRoot(root);
179
+ const removed = await store.untrust(resolved);
180
+ // Independent of the marker either way, so it answers the same question
181
+ // whether or not this call removed one — the root may still be trusted
182
+ // by policy after its marker is gone.
183
+ const after = await policyExecGate(store, policy, { root, configured: true }, policyOptions);
184
+ // The answer goes to stdout either way. A --json caller that gets exit 1
185
+ // still gets a document saying what the store held; the failure itself is
186
+ // the exit code and the line on stderr, which is where every other aside
187
+ // in this package already goes.
188
+ if (taken.json)
189
+ io.stdout(rootAnswer(resolved, after.trusted, removed, after.by, after.rule));
190
+ if (!removed) {
191
+ io.stderr(`${toolName}: not trusted: ${resolved}\n`);
192
+ return EXIT.error;
193
+ }
194
+ if (!taken.json) {
195
+ io.stdout(`untrusted ${resolved}\n`);
196
+ // Mirrors `sdlc repo untrust`'s note: removing the marker did not
197
+ // change the answer when a policy rule covers this root regardless.
198
+ if (after.trusted) {
199
+ io.stderr(`note: ${resolved} is still trusted by ${toolName}'s trust.${after.by}s ` +
200
+ `('${after.rule ?? ''}'); removing the marker changes nothing\n`);
201
+ }
202
+ }
203
+ return EXIT.ok;
204
+ }
205
+ default: {
206
+ const policy = await loadPolicy(root, toolName, env, home);
207
+ if ('error' in policy) {
208
+ io.stderr(`${toolName}: ${policy.error}\n`);
209
+ return EXIT.error;
210
+ }
211
+ const result = await store.trust(root);
212
+ // After granting (or confirming) the marker, the marker itself is
213
+ // always why this root is trusted — `trustDecision` checks it first.
214
+ const decision = await policyExecGate(store, policy, { root, configured: true }, policyOptions);
215
+ io.stdout(taken.json
216
+ ? rootAnswer(result.root, true, !result.alreadyTrusted, decision.by, decision.rule)
217
+ : `${result.alreadyTrusted ? 'already trusted' : 'trusted'} ${result.root}\n`);
218
+ return EXIT.ok;
219
+ }
220
+ }
221
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * The trust store, with the old waypost store read as a fallback.
3
+ *
4
+ * Grants live in `$XDG_STATE_HOME/wayfinder/trusted/`. A grant made before the
5
+ * rename sits in `$XDG_STATE_HOME/waypost/trusted/` and still counts:
6
+ * `isTrusted` and `list` read both stores, `trust` writes only the new one,
7
+ * and `untrust` removes the root from both, so a revoked grant cannot survive
8
+ * in the old store.
9
+ */
10
+ import { type TrustStore } from '@osdlc/trust-repo';
11
+ export interface AppTrustStoreOptions {
12
+ /** Defaults to `process.env`. Supplies `XDG_STATE_HOME`. */
13
+ env?: Record<string, string | undefined>;
14
+ /** Defaults to `os.homedir()`. The base for the non-XDG state path. */
15
+ home?: string;
16
+ }
17
+ /** The app's trust store: the wayfinder store, plus grants from the waypost one. */
18
+ export declare function appTrustStore(opts?: AppTrustStoreOptions): TrustStore;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * The trust store, with the old waypost store read as a fallback.
3
+ *
4
+ * Grants live in `$XDG_STATE_HOME/wayfinder/trusted/`. A grant made before the
5
+ * rename sits in `$XDG_STATE_HOME/waypost/trusted/` and still counts:
6
+ * `isTrusted` and `list` read both stores, `trust` writes only the new one,
7
+ * and `untrust` removes the root from both, so a revoked grant cannot survive
8
+ * in the old store.
9
+ */
10
+ import { trustStore } from '@osdlc/trust-repo';
11
+ import { LEGACY_TRUST_STORE_TOOL, TRUST_STORE_TOOL } from "./config.js";
12
+ /** The app's trust store: the wayfinder store, plus grants from the waypost one. */
13
+ export function appTrustStore(opts = {}) {
14
+ const scope = {
15
+ ...(opts.env !== undefined ? { env: opts.env } : {}),
16
+ ...(opts.home !== undefined ? { home: opts.home } : {}),
17
+ };
18
+ const current = trustStore({ tool: TRUST_STORE_TOOL, ...scope });
19
+ const legacy = trustStore({ tool: LEGACY_TRUST_STORE_TOOL, ...scope });
20
+ return {
21
+ tool: current.tool,
22
+ dir: current.dir,
23
+ resolveRoot: current.resolveRoot,
24
+ markerPath: current.markerPath,
25
+ async isTrusted(root) {
26
+ return (await current.isTrusted(root)) || (await legacy.isTrusted(root));
27
+ },
28
+ async trust(root) {
29
+ const result = await current.trust(root);
30
+ if (result.alreadyTrusted)
31
+ return result;
32
+ // Granted again under the new name: still reported as already trusted
33
+ // when the old store held the grant, since nothing changed for the user.
34
+ return (await legacy.isTrusted(root)) ? { ...result, alreadyTrusted: true } : result;
35
+ },
36
+ async untrust(root) {
37
+ const removedCurrent = await current.untrust(root);
38
+ const removedLegacy = await legacy.untrust(root);
39
+ return removedCurrent || removedLegacy;
40
+ },
41
+ async list() {
42
+ const paths = new Set([...(await current.list()), ...(await legacy.list())]);
43
+ return [...paths].sort();
44
+ },
45
+ };
46
+ }
package/dist/tui.d.ts ADDED
@@ -0,0 +1,178 @@
1
+ /**
2
+ * The terminal UI — browse every task in a repository, and run one.
3
+ *
4
+ * The affordance a browser cannot have: Enter RUNS the selected task, in this
5
+ * shell, with the terminal handed to it. A web view can only ever offer you
6
+ * something to paste.
7
+ *
8
+ * Dependency-free: raw mode, ANSI, and one frame string per keystroke. A TUI
9
+ * toolkit would be a heavier dependency than the code it saves, and this has to
10
+ * keep working from a checkout whose node_modules is the thing you are trying
11
+ * to repair. The CLI routes its output through the `CliIo` seam so
12
+ * `main()` is testable without touching a real stream, but this file writes
13
+ * to `process.stdout` directly — owning the interactive terminal, raw mode,
14
+ * the alternate screen, handing the terminal to a spawned task, is the whole
15
+ * point of it, and that job is outside the seam by design.
16
+ *
17
+ * Collection is asynchronous, which is what most of the state machinery below
18
+ * is for: keystrokes arrive mid-refresh, and a row can be stale.
19
+ */
20
+ import { type Catalog, type Project, type RunnerCacheState, type Task } from '@osdlc/system-model/detect';
21
+ import { type Mode } from '@osdlc/system-model/match';
22
+ import type { ExecGate } from '@osdlc/trust-repo';
23
+ import { type WayOptions } from './catalog.ts';
24
+ export interface Row {
25
+ task: Task;
26
+ score: number;
27
+ labelHits: number[] | null;
28
+ }
29
+ interface State {
30
+ catalog: Catalog | null;
31
+ /** The registered tools, built-ins plus any loaded. */
32
+ project: Project;
33
+ /** The project file names tools that were not loaded because the repository is untrusted or execution is off. */
34
+ projectToolsPending: boolean;
35
+ root: string;
36
+ options: WayOptions;
37
+ /** `runners.order` from config; applied to every collected catalog. */
38
+ runnerOrder: string[] | undefined;
39
+ /**
40
+ * The trust store's environment and home, threaded from the CLI. Injectable
41
+ * for the reason every sibling in this lane is: a test that let them default
42
+ * would grant trust in the developer's own `~/.local/state/wayfinder/`. Nothing but
43
+ * a test ever passes them.
44
+ */
45
+ env: Record<string, string | undefined> | undefined;
46
+ home: string | undefined;
47
+ /** Where stored probes live, resolved once from the injected env and home. */
48
+ store: string;
49
+ /**
50
+ * Where each runner's rows came from — one entry per selected provider.
51
+ *
52
+ * The boot sequence paints from the store before anything is probed, so a row
53
+ * on screen may be an hour old. This is what says which, and it is cleared to
54
+ * all-fresh the moment a real probe lands.
55
+ */
56
+ cache: RunnerCacheState[];
57
+ runner: string;
58
+ query: string;
59
+ mode: Mode;
60
+ /** Show only services — tasks that run until you stop them. Toggled by ^t. */
61
+ servicesOnly: boolean;
62
+ /** Selection is held by task id, not row index — see `refresh`. */
63
+ selectedId: string | null;
64
+ scroll: number;
65
+ message: string;
66
+ loading: boolean;
67
+ /**
68
+ * Why execution came out the way it did, resolved once by the CLI. Only
69
+ * `"untrusted"` earns the ^s affordance: when a config file turned execution
70
+ * off, trusting the repository would change nothing, and offering it would be
71
+ * a wrong instruction.
72
+ */
73
+ gate: ExecGate | null;
74
+ /**
75
+ * True once ^s has asked and is waiting for `y`. Trust permits this
76
+ * repository's code to run, so it cannot be granted by one keystroke —
77
+ * least of all ^s, which is flow control on many terminals and arrives
78
+ * unintentionally. The second key is what makes it a decision.
79
+ */
80
+ confirmingTrust: boolean;
81
+ /**
82
+ * The task whose arguments are being typed, and what has been typed so far.
83
+ *
84
+ * Non-null only for a task that declares parameters: `argv` omits them, so
85
+ * running one straight off Enter spawns `just deploy` with no environment
86
+ * and the terminal is gone before anything can say so. Null is the ordinary
87
+ * case and costs an unparameterised task nothing — Enter still runs it.
88
+ */
89
+ entering: {
90
+ task: Task;
91
+ text: string;
92
+ } | null;
93
+ /**
94
+ * The settings screen's rendered lines, or null when it is closed.
95
+ *
96
+ * Rendered once on open rather than on every frame: it reads the config
97
+ * from disk, which is IO, and a screen that re-read it per keystroke would
98
+ * be doing that for a view nothing can change from here.
99
+ */
100
+ settings: string[] | null;
101
+ /** Bumped per refresh so a superseded result cannot overwrite a newer one. */
102
+ generation: number;
103
+ inFlight: AbortController | null;
104
+ rows: Row[];
105
+ }
106
+ /**
107
+ * The module singleton.
108
+ *
109
+ * Exported for one reason: `runTui` owns a real terminal and never returns, so
110
+ * the selection rule — the thing that must survive a refresh reordering and
111
+ * dropping rows underneath the cursor — is only testable through this and
112
+ * { recompute}. Nothing outside a test writes to it.
113
+ */
114
+ export declare const state: State;
115
+ /**
116
+ * What the status line says about the rows on screen, in three states.
117
+ *
118
+ * Fresh says NOTHING: a line that is always there is a line nobody reads, and
119
+ * there is nothing here to report.
120
+ *
121
+ * Stale-and-slow is separated from ordinary stale because it is the case the
122
+ * whole cache exists for. A runner this repository has MEASURED at several
123
+ * seconds is why the screen would otherwise have been empty, and telling the
124
+ * user "a moment" in the same voice as a 200ms refresh would waste the one
125
+ * warning that matters. Slow is measured, never declared — a runner that is
126
+ * quick here is not called slow because it is slow elsewhere.
127
+ */
128
+ export declare function refreshNote(rows: readonly RunnerCacheState[], loading: boolean): {
129
+ text: string;
130
+ slow: boolean;
131
+ } | null;
132
+ /** Index of the selected task, or 0 when its id is no longer present. */
133
+ export declare function cursor(): number;
134
+ /**
135
+ * The whole screen as one string.
136
+ *
137
+ * Exported alongside {@link state} and {@link recompute} so the three cache
138
+ * states can be asserted as RENDERED lines rather than as the helper that feeds
139
+ * them — the status line is the surface a user reads, and a note that is
140
+ * correct but composed into the wrong line helps nobody.
141
+ */
142
+ export declare function frame(width: number, height: number): string;
143
+ /**
144
+ * Rebuild the visible rows and re-anchor the selection onto a task that is
145
+ * still there.
146
+ *
147
+ * Split out of {@link draw} so it can be exercised without a terminal. It is
148
+ * the whole reason selection is held by task id: a refresh reorders rows and
149
+ * drops some of them, and an index would silently point at a different task —
150
+ * which is the same keystroke running the wrong command.
151
+ */
152
+ export declare function recompute(): void;
153
+ /**
154
+ * One keystroke.
155
+ *
156
+ * Exported for the same reason `state` is: `runTui` owns a real terminal and
157
+ * never returns, so the keys that reach disk — settings, trust — are only
158
+ * reachable from a test through this.
159
+ */
160
+ export declare function handle(key: string): void;
161
+ /**
162
+ * `gate` is the CLI's already-resolved trust decision. The TUI needs it, not
163
+ * just the boolean it produced, because "no exec because a file said so" and
164
+ * "no exec because this repository is not trusted" call for different offers —
165
+ * only the second one has an action a keystroke can take.
166
+ */
167
+ export interface TuiOptions {
168
+ project: Project;
169
+ projectToolsPending?: boolean | undefined;
170
+ root: string;
171
+ options: WayOptions;
172
+ runnerOrder?: string[] | undefined;
173
+ gate?: ExecGate | undefined;
174
+ env?: Record<string, string | undefined> | undefined;
175
+ home?: string | undefined;
176
+ }
177
+ export declare function runTui({ project, projectToolsPending, root, options, runnerOrder, gate, env, home, }: TuiOptions): Promise<number>;
178
+ export {};