@osdlc/wayfinder 0.7.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +240 -0
- package/CONTRIBUTING.md +6 -0
- package/README.md +310 -150
- package/SECURITY.md +19 -5
- package/dist/actions.d.ts +23 -0
- package/dist/actions.js +97 -0
- package/dist/app.d.ts +1 -13
- package/dist/app.js +1 -13
- package/dist/args.d.ts +11 -6
- package/dist/args.js +25 -7
- package/dist/cache.d.ts +2 -4
- package/dist/cache.js +5 -10
- package/dist/catalog.d.ts +45 -4
- package/dist/catalog.js +134 -13
- package/dist/clean-command.d.ts +65 -36
- package/dist/clean-command.js +372 -226
- package/dist/cli.d.ts +24 -57
- package/dist/cli.js +139 -568
- package/dist/commands/browse.d.ts +128 -0
- package/dist/commands/browse.js +153 -0
- package/dist/commands/index.d.ts +25 -0
- package/dist/commands/index.js +71 -0
- package/dist/commands/list.d.ts +224 -0
- package/dist/commands/list.js +178 -0
- package/dist/commands/query.d.ts +166 -0
- package/dist/commands/query.js +73 -0
- package/dist/commands/run.d.ts +114 -0
- package/dist/commands/run.js +139 -0
- package/dist/commands/shared.d.ts +152 -0
- package/dist/commands/shared.js +209 -0
- package/dist/config-command.d.ts +27 -43
- package/dist/config-command.js +129 -330
- package/dist/config-keys.d.ts +25 -0
- package/dist/config-keys.js +29 -0
- package/dist/config.d.ts +272 -257
- package/dist/config.js +611 -460
- package/dist/core/copy-text.d.ts +30 -0
- package/dist/core/copy-text.js +50 -0
- package/dist/core/filter.d.ts +55 -0
- package/dist/core/filter.js +59 -0
- package/dist/core/run.d.ts +22 -0
- package/dist/core/run.js +59 -0
- package/dist/core/saved-view.d.ts +59 -0
- package/dist/core/saved-view.js +119 -0
- package/dist/core/session.d.ts +282 -0
- package/dist/core/session.js +602 -0
- package/dist/core/skills.d.ts +53 -0
- package/dist/core/skills.js +54 -0
- package/dist/core/unknowns.d.ts +72 -0
- package/dist/core/unknowns.js +68 -0
- package/dist/devlink.d.ts +3 -0
- package/dist/devlink.js +5 -2
- package/dist/document-schemas.generated.d.ts +22 -0
- package/dist/document-schemas.generated.js +916 -0
- package/dist/documents.d.ts +508 -0
- package/dist/documents.js +181 -0
- package/dist/groups.d.ts +22 -26
- package/dist/groups.js +13 -29
- package/dist/guide.d.ts +26 -13
- package/dist/guide.js +119 -103
- package/dist/index.d.ts +118 -0
- package/dist/index.js +61 -0
- package/dist/keys.d.ts +51 -0
- package/dist/keys.js +273 -0
- package/dist/page.d.ts +18 -8
- package/dist/page.js +28 -17
- package/dist/providers-command.d.ts +81 -20
- package/dist/providers-command.js +33 -75
- package/dist/schema.d.ts +48 -0
- package/dist/schema.js +61 -0
- package/dist/serve/auth.d.ts +46 -0
- package/dist/serve/auth.js +82 -0
- package/dist/serve/catalog-share.d.ts +63 -0
- package/dist/serve/catalog-share.js +155 -0
- package/dist/serve/index.d.ts +100 -0
- package/dist/serve/index.js +259 -0
- package/dist/serve/routes.d.ts +60 -0
- package/dist/serve/routes.js +186 -0
- package/dist/serve/terminal-input.d.ts +50 -0
- package/dist/serve/terminal-input.js +108 -0
- package/dist/skills.d.ts +19 -0
- package/dist/skills.js +54 -0
- package/dist/terminal-text.d.ts +8 -0
- package/dist/terminal-text.js +19 -6
- package/dist/tool-info.d.ts +24 -0
- package/dist/tool-info.js +17 -0
- package/dist/trust-command.d.ts +15 -27
- package/dist/trust-command.js +110 -208
- package/dist/trust-store.d.ts +5 -10
- package/dist/trust-store.js +9 -42
- package/dist/tui/app.d.ts +193 -0
- package/dist/tui/app.js +1400 -0
- package/dist/tui/copy.d.ts +29 -0
- package/dist/tui/copy.js +39 -0
- package/dist/tui/index.d.ts +33 -0
- package/dist/tui/index.js +97 -0
- package/dist/tui/keys-input.d.ts +27 -0
- package/dist/tui/keys-input.js +87 -0
- package/dist/tui/settings.d.ts +94 -0
- package/dist/tui/settings.js +198 -0
- package/dist/tui/style.d.ts +62 -0
- package/dist/tui/style.js +77 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.js +7 -0
- package/dist/vocabulary.d.ts +91 -0
- package/dist/vocabulary.js +155 -0
- package/dist/web/main.js +2232 -582
- package/dist/web/page.html +41 -33
- package/dist/web/styles.css +513 -329
- package/dist/xdg.d.ts +76 -4
- package/dist/xdg.js +77 -5
- package/package.json +27 -8
- package/schema/config.json +133 -0
- package/dist/http.d.ts +0 -22
- package/dist/http.js +0 -149
- package/dist/origin-owner.d.ts +0 -19
- package/dist/origin-owner.js +0 -85
- package/dist/serve.d.ts +0 -98
- package/dist/serve.js +0 -671
- package/dist/tui.d.ts +0 -177
- package/dist/tui.js +0 -840
package/dist/trust-command.js
CHANGED
|
@@ -1,219 +1,121 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* (
|
|
4
|
-
*
|
|
5
|
-
* `
|
|
6
|
-
* trusted with no marker, and `--show`/`--untrust` say which layer decided
|
|
7
|
-
* (`by`/`rule`).
|
|
2
|
+
* `way trust`: cli-tool's shared `trust` command over wayfinder's marker store
|
|
3
|
+
* (`trust-store.ts`) and the user file's `trust` policy. A root the policy
|
|
4
|
+
* covers reports trusted with no marker, and every answer says which layer
|
|
5
|
+
* decided (`by`, `rule`).
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* `--scope <tool>` grants, removes or shows one tool's trust instead of the
|
|
8
|
+
* whole repository's. Granting is `cli-only`: the web view's server refuses
|
|
9
|
+
* it.
|
|
12
10
|
*/
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
11
|
+
import { CommandError } from '@osdlc/cli-tool/command';
|
|
12
|
+
import { trustCommand as sharedTrustCommand, } from '@osdlc/cli-tool/trust-command';
|
|
13
|
+
import { WHOLE_REPO_SCOPE, parseTrustScope, policyExecGate, } from '@osdlc/trust-repo';
|
|
14
|
+
import { APP, BIN, PROJECT_CONFIG_FILENAME } from "./app.js";
|
|
15
|
+
import { commandEnv } from "./config-command.js";
|
|
16
|
+
import { ConfigError, loadConfig, trustPolicyFromConfig, trustPolicyOptions } from "./config.js";
|
|
18
17
|
import { appTrustStore } from "./trust-store.js";
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
`;
|
|
18
|
+
/** The `scope` field of an entry: absent for the whole repository. */
|
|
19
|
+
function scopeField(scope) {
|
|
20
|
+
return scope === undefined || scope === WHOLE_REPO_SCOPE ? {} : { scope };
|
|
52
21
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
else if (arg === '--untrust' || arg === '--show' || arg === '--list') {
|
|
75
|
-
const named = arg.slice(2);
|
|
76
|
-
if (mode !== undefined && mode !== named) {
|
|
77
|
-
return { error: `${arg} and --${mode} ask different things; give at most one` };
|
|
78
|
-
}
|
|
79
|
-
mode = named;
|
|
80
|
-
}
|
|
81
|
-
else if (arg.startsWith('-')) {
|
|
82
|
-
return { error: `unknown option: ${arg}` };
|
|
22
|
+
function entryOf(gate, scope) {
|
|
23
|
+
return {
|
|
24
|
+
root: gate.root,
|
|
25
|
+
trusted: gate.trusted,
|
|
26
|
+
by: gate.trusted ? gate.by : null,
|
|
27
|
+
...(gate.trusted && gate.rule !== undefined ? { rule: gate.rule } : {}),
|
|
28
|
+
...scopeField(scope),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** wayfinder's {@link TrustService}. */
|
|
32
|
+
function trustService(opts = {}) {
|
|
33
|
+
const env = commandEnv(opts);
|
|
34
|
+
const setup = async (ctx) => {
|
|
35
|
+
const home = env.home(ctx);
|
|
36
|
+
return { root: await env.root(ctx), home, store: appTrustStore({ env: ctx.env, home }) };
|
|
37
|
+
};
|
|
38
|
+
// Loaded only by the modes that decide about one root, so a broken config
|
|
39
|
+
// file cannot break `--list`.
|
|
40
|
+
const policyFor = async (ctx, root, home) => {
|
|
41
|
+
try {
|
|
42
|
+
return trustPolicyFromConfig((await loadConfig(root, ctx.env, home)).effective);
|
|
83
43
|
}
|
|
84
|
-
|
|
85
|
-
|
|
44
|
+
catch (err) {
|
|
45
|
+
if (err instanceof ConfigError)
|
|
46
|
+
throw new CommandError(err.message);
|
|
47
|
+
throw err;
|
|
86
48
|
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
49
|
+
};
|
|
50
|
+
// Decided by the function that gates a real run, so the answer always
|
|
51
|
+
// matches what controls execution. `configured: true` asks whether the
|
|
52
|
+
// marker or policy would allow it.
|
|
53
|
+
const decide = (store, policy, root, home, scope) => policyExecGate(store, policy, { root, configured: true, ...(scope !== undefined ? { scopes: [scope] } : {}) }, trustPolicyOptions(home));
|
|
54
|
+
return {
|
|
55
|
+
scopes: true,
|
|
56
|
+
parseScope: parseTrustScope,
|
|
57
|
+
async trust(ctx, req) {
|
|
58
|
+
const { root, home, store } = await setup(ctx);
|
|
59
|
+
const policy = await policyFor(ctx, root, home);
|
|
60
|
+
const result = await store.trust(root, req.scope);
|
|
61
|
+
const gate = await decide(store, policy, root, home, req.scope);
|
|
62
|
+
return { ...entryOf(gate, req.scope), root: result.root, changed: !result.alreadyTrusted };
|
|
63
|
+
},
|
|
64
|
+
async untrust(ctx, req) {
|
|
65
|
+
const { root, home, store } = await setup(ctx);
|
|
66
|
+
const policy = await policyFor(ctx, root, home);
|
|
67
|
+
// Resolved first, so the answer names the path the store is keyed on.
|
|
68
|
+
const resolved = await store.resolveRoot(root);
|
|
69
|
+
const removed = await store.untrust(resolved, req.scope);
|
|
70
|
+
// The root may still be trusted by policy once its marker is gone.
|
|
71
|
+
const gate = await decide(store, policy, root, home, req.scope);
|
|
72
|
+
return { ...entryOf(gate, req.scope), root: resolved, changed: removed };
|
|
73
|
+
},
|
|
74
|
+
async show(ctx, req) {
|
|
75
|
+
const { root, home, store } = await setup(ctx);
|
|
76
|
+
const policy = await policyFor(ctx, root, home);
|
|
77
|
+
return entryOf(await decide(store, policy, root, home, req.scope), req.scope);
|
|
78
|
+
},
|
|
79
|
+
async list(ctx) {
|
|
80
|
+
const grants = await appTrustStore({ env: ctx.env, home: env.home(ctx) }).listGrants();
|
|
81
|
+
return grants.map((g) => ({
|
|
82
|
+
root: g.root,
|
|
83
|
+
trusted: true,
|
|
84
|
+
by: 'marker',
|
|
85
|
+
...scopeField(g.scope),
|
|
86
|
+
}));
|
|
87
|
+
},
|
|
88
|
+
async untrustAll(ctx) {
|
|
89
|
+
const { root, store } = await setup(ctx);
|
|
90
|
+
const resolved = await store.resolveRoot(root);
|
|
91
|
+
const scopes = await store.untrustAll(resolved);
|
|
92
|
+
return {
|
|
93
|
+
root: resolved,
|
|
94
|
+
removed: scopes.map((scope) => ({
|
|
95
|
+
root: resolved,
|
|
96
|
+
trusted: false,
|
|
97
|
+
by: null,
|
|
98
|
+
...scopeField(scope),
|
|
99
|
+
})),
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
};
|
|
107
103
|
}
|
|
104
|
+
const DESCRIPTION = `Some runners can only be read by running them: reading moon's task graph evaluates the repository's toolchain configuration. Trust is that consent, kept per repository outside it, keyed on the resolved path, so you are asked once.
|
|
105
|
+
|
|
106
|
+
Trust is one of two conditions: execution must also be allowed. ${APP} allows it by default, so trust is enough unless a config file sets allowExec: false. A repository cannot trust itself: allowExec and trust in ${PROJECT_CONFIG_FILENAME} cannot raise the gate. Pass --exec to allow one run without recording anything.
|
|
107
|
+
|
|
108
|
+
A root can also be trusted with no marker, by trust.paths and trust.owners in the user config, and one tool by trust.tools.<tool>. --show names what decided: by marker, path or owner, with the rule that matched. --scope <tool> grants or removes one tool's trust; a run needs every tool it runs trusted, such as mise for a mise task. A tool's name is its id as "${BIN} providers" lists it (moon, mise, sbt). "${BIN} list" names the tools each withheld runner still needs, and "${BIN} list --json" has them as "missing" in "unknowns".`;
|
|
108
109
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* Exit codes follow `runConfigCommand`. 2 is a command that cannot run as
|
|
113
|
-
* typed, decided from the arguments alone. 1 is a valid command that failed
|
|
114
|
-
* against the state it found: here, `--untrust` on a root with no marker, or a
|
|
115
|
-
* config file that will not parse.
|
|
110
|
+
* The `trust` command. Mount it as `trust: trustCommand({ globals })`, with
|
|
111
|
+
* the app's global flags; `-C` must be declared as `dir`.
|
|
116
112
|
*/
|
|
117
|
-
export
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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 JSON answer for `trust`, `--untrust` and `--show`, in one shape: the
|
|
135
|
-
* root decided on, whether it is trusted now, whether this run changed the
|
|
136
|
-
* store, and which layer decided (`by`/`rule`, as `sdlc repo trust --show`
|
|
137
|
-
* reports). One shape means a caller does not branch on the flag it passed.
|
|
138
|
-
*/
|
|
139
|
-
const rootAnswer = (path, trusted, changed, by, rule) => `${jsonText({ root: path, trusted, changed, by, rule })}\n`;
|
|
140
|
-
switch (taken.mode) {
|
|
141
|
-
case 'list': {
|
|
142
|
-
const paths = await store.list();
|
|
143
|
-
if (taken.json)
|
|
144
|
-
io.stdout(`${jsonText({ trusted: paths })}\n`);
|
|
145
|
-
else
|
|
146
|
-
for (const path of paths)
|
|
147
|
-
io.stdout(`${terminalSafe(path)}\n`);
|
|
148
|
-
return EXIT.ok;
|
|
149
|
-
}
|
|
150
|
-
case 'show': {
|
|
151
|
-
// Both answers exit 0. "Not trusted" is the answer that was asked for,
|
|
152
|
-
// not a failure.
|
|
153
|
-
const policy = await loadPolicy(root, toolName, env, home);
|
|
154
|
-
if ('error' in policy) {
|
|
155
|
-
io.stderr(`${toolName}: ${policy.error}\n`);
|
|
156
|
-
return EXIT.error;
|
|
157
|
-
}
|
|
158
|
-
// Decided by the same function that checks a real run
|
|
159
|
-
// (`policyExecGate`), so this answer always matches what controls
|
|
160
|
-
// execution. `configured: true` asks "if execution were on, would this
|
|
161
|
-
// root's marker or policy allow it". That is the only question `--show`
|
|
162
|
-
// asks, so `allowExec` and `reason` are unused here.
|
|
163
|
-
const gate = await policyExecGate(store, policy, { root, configured: true }, policyOptions);
|
|
164
|
-
io.stdout(taken.json
|
|
165
|
-
? rootAnswer(gate.root, gate.trusted, false, gate.by, gate.rule)
|
|
166
|
-
: `${gate.trusted ? 'trusted' : 'not trusted'} ${terminalSafe(gate.root)}\n`);
|
|
167
|
-
return EXIT.ok;
|
|
168
|
-
}
|
|
169
|
-
case 'untrust': {
|
|
170
|
-
const policy = await loadPolicy(root, toolName, env, home);
|
|
171
|
-
if ('error' in policy) {
|
|
172
|
-
io.stderr(`${toolName}: ${policy.error}\n`);
|
|
173
|
-
return EXIT.error;
|
|
174
|
-
}
|
|
175
|
-
// Resolved first so the message names the path the store is keyed on,
|
|
176
|
-
// which is the path a later --list shows.
|
|
177
|
-
const resolved = await store.resolveRoot(root);
|
|
178
|
-
const removed = await store.untrust(resolved);
|
|
179
|
-
// Checked whether or not a marker was removed: the root may still be
|
|
180
|
-
// trusted by policy after its marker is gone.
|
|
181
|
-
const after = await policyExecGate(store, policy, { root, configured: true }, policyOptions);
|
|
182
|
-
// The JSON answer goes to stdout either way, so a --json caller that gets
|
|
183
|
-
// exit 1 still gets a document. The failure is reported by the exit code
|
|
184
|
-
// and a line on stderr, where every other side message in this package
|
|
185
|
-
// goes.
|
|
186
|
-
if (taken.json)
|
|
187
|
-
io.stdout(rootAnswer(resolved, after.trusted, removed, after.by, after.rule));
|
|
188
|
-
if (!removed) {
|
|
189
|
-
io.stderr(`${toolName}: not trusted: ${resolved}\n`);
|
|
190
|
-
return EXIT.error;
|
|
191
|
-
}
|
|
192
|
-
if (!taken.json) {
|
|
193
|
-
io.stdout(`untrusted ${terminalSafe(resolved)}\n`);
|
|
194
|
-
// Matches `sdlc repo untrust`'s note: when a policy rule covers this
|
|
195
|
-
// root, removing the marker did not change the answer.
|
|
196
|
-
if (after.trusted) {
|
|
197
|
-
io.stderr(`note: ${resolved} is still trusted by ${toolName}'s trust.${after.by}s ` +
|
|
198
|
-
`('${after.rule ?? ''}'); removing the marker changes nothing\n`);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return EXIT.ok;
|
|
202
|
-
}
|
|
203
|
-
default: {
|
|
204
|
-
const policy = await loadPolicy(root, toolName, env, home);
|
|
205
|
-
if ('error' in policy) {
|
|
206
|
-
io.stderr(`${toolName}: ${policy.error}\n`);
|
|
207
|
-
return EXIT.error;
|
|
208
|
-
}
|
|
209
|
-
const result = await store.trust(root);
|
|
210
|
-
// After the marker is written (or found), the marker is always the
|
|
211
|
-
// reason this root is trusted, because the marker is checked first.
|
|
212
|
-
const decision = await policyExecGate(store, policy, { root, configured: true }, policyOptions);
|
|
213
|
-
io.stdout(taken.json
|
|
214
|
-
? rootAnswer(result.root, true, !result.alreadyTrusted, decision.by, decision.rule)
|
|
215
|
-
: `${result.alreadyTrusted ? 'already trusted' : 'trusted'} ${terminalSafe(result.root)}\n`);
|
|
216
|
-
return EXIT.ok;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
113
|
+
export function trustCommand(options = {}) {
|
|
114
|
+
const { globals, ...env } = options;
|
|
115
|
+
return sharedTrustCommand(trustService(env), {
|
|
116
|
+
...(globals !== undefined ? { globals } : {}),
|
|
117
|
+
summary: "allow this repository's runners to be read by running them",
|
|
118
|
+
description: DESCRIPTION,
|
|
119
|
+
scopeHelp: `one tool, by its id in "${BIN} providers", such as moon or mise`,
|
|
120
|
+
});
|
|
219
121
|
}
|
package/dist/trust-store.d.ts
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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.
|
|
2
|
+
* wayfinder's trust store: `@osdlc/trust-repo`'s marker store in
|
|
3
|
+
* `<state>/wayfinder/trusted/` (see `xdg.ts`).
|
|
9
4
|
*/
|
|
10
5
|
import { type TrustStore } from '@osdlc/trust-repo';
|
|
11
6
|
export interface AppTrustStoreOptions {
|
|
12
|
-
/** Defaults to `process.env`. Supplies `XDG_STATE_HOME`. */
|
|
7
|
+
/** Defaults to `process.env`. Supplies `XDG_STATE_HOME` and `WAYFINDER_ROOT`. */
|
|
13
8
|
env?: Record<string, string | undefined>;
|
|
14
|
-
/** Defaults to `homeDir()` from `@osdlc/trust-repo`.
|
|
9
|
+
/** Defaults to `homeDir()` from `@osdlc/trust-repo`. */
|
|
15
10
|
home?: string;
|
|
16
11
|
}
|
|
17
|
-
/** The app's trust store
|
|
12
|
+
/** The app's trust store. */
|
|
18
13
|
export declare function appTrustStore(opts?: AppTrustStoreOptions): TrustStore;
|
package/dist/trust-store.js
CHANGED
|
@@ -1,46 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
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.
|
|
2
|
+
* wayfinder's trust store: `@osdlc/trust-repo`'s marker store in
|
|
3
|
+
* `<state>/wayfinder/trusted/` (see `xdg.ts`).
|
|
9
4
|
*/
|
|
10
|
-
import { trustStore } from '@osdlc/trust-repo';
|
|
11
|
-
import {
|
|
12
|
-
|
|
5
|
+
import { homeDir, trustStore } from '@osdlc/trust-repo';
|
|
6
|
+
import { APP } from "./app.js";
|
|
7
|
+
import { appDirs } from "./xdg.js";
|
|
8
|
+
/** The app's trust store. */
|
|
13
9
|
export function appTrustStore(opts = {}) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
};
|
|
10
|
+
const env = opts.env ?? process.env;
|
|
11
|
+
const home = opts.home ?? homeDir();
|
|
12
|
+
return trustStore({ tool: APP, env, home, dir: appDirs({ env, home }).trustStore });
|
|
46
13
|
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The terminal UI as an object: its state, the frame it draws and the keys it
|
|
3
|
+
* answers. `createTui` makes one over a {@link Session} and a {@link TuiHost};
|
|
4
|
+
* `runTui` in `./index.ts` gives it a real terminal. Tests give it a fake
|
|
5
|
+
* host, so every key and every frame can be checked without a terminal.
|
|
6
|
+
*
|
|
7
|
+
* Collection is async, which is what much of the state handling is for: keys
|
|
8
|
+
* arrive during a refresh, and a row can be stale. With nothing on screen,
|
|
9
|
+
* each runner's rows are drawn as that runner answers. Over rows already on
|
|
10
|
+
* screen, a refresh replaces them all at once when it ends.
|
|
11
|
+
*/
|
|
12
|
+
import type { Catalog, RunnerCacheState, RunnerReport, Task } from '@osdlc/system-model/detect';
|
|
13
|
+
import type { Mode } from '@osdlc/system-model/match';
|
|
14
|
+
import type { Settings } from '../config.ts';
|
|
15
|
+
import type { TaskHit } from '../core/filter.ts';
|
|
16
|
+
import type { HandOffResult } from '../core/run.ts';
|
|
17
|
+
import { type CacheState, type RunPlan, type Session } from '../core/session.ts';
|
|
18
|
+
import { type SkillHit, type SkillRow } from '../core/skills.ts';
|
|
19
|
+
import { type SettingsItem } from './settings.ts';
|
|
20
|
+
import { type Styles } from './style.ts';
|
|
21
|
+
/** What the terminal UI needs from the terminal it runs in. */
|
|
22
|
+
export interface TuiHost {
|
|
23
|
+
/** Write to the screen. */
|
|
24
|
+
write(text: string): void;
|
|
25
|
+
columns(): number;
|
|
26
|
+
rows(): number;
|
|
27
|
+
platform: NodeJS.Platform;
|
|
28
|
+
/** Put text on the clipboard; true when a program took it. */
|
|
29
|
+
clipboard(text: string): Promise<boolean>;
|
|
30
|
+
/** Give the terminal back: leave raw mode and the alternate screen. Idempotent. */
|
|
31
|
+
release(): void;
|
|
32
|
+
/** Run a task with the terminal, after {@link release}. */
|
|
33
|
+
handOff(plan: RunPlan): HandOffResult;
|
|
34
|
+
/** End the process. The real host never returns. */
|
|
35
|
+
exit(code: number): void;
|
|
36
|
+
}
|
|
37
|
+
/** A line of feedback on the status line. */
|
|
38
|
+
export interface Message {
|
|
39
|
+
text: string;
|
|
40
|
+
tone: 'note' | 'warning' | 'error';
|
|
41
|
+
}
|
|
42
|
+
/** The scopes `^o` cycles through, as the web view's Scope buttons. */
|
|
43
|
+
export declare const SCOPES: readonly {
|
|
44
|
+
label: string;
|
|
45
|
+
maxDepth: number | undefined;
|
|
46
|
+
}[];
|
|
47
|
+
/** The settings screen while it is open. */
|
|
48
|
+
export interface SettingsScreen {
|
|
49
|
+
settings: Settings;
|
|
50
|
+
/**
|
|
51
|
+
* The item the cursor is on. Held by item, not line, because an edit and
|
|
52
|
+
* the probe after it change the lines above it.
|
|
53
|
+
*/
|
|
54
|
+
at: SettingsItem | null;
|
|
55
|
+
/** The cursor's last line, to fall back near when its item is gone. */
|
|
56
|
+
hint: number;
|
|
57
|
+
scroll: number;
|
|
58
|
+
/** The excluded path being typed, or null. */
|
|
59
|
+
adding: string | null;
|
|
60
|
+
}
|
|
61
|
+
/** The `all` tab. */
|
|
62
|
+
export declare const ALL = "all";
|
|
63
|
+
/**
|
|
64
|
+
* The Skills tab. Its rows are agent skills, not a runner's tasks. The `#`
|
|
65
|
+
* keeps it apart from any runner id.
|
|
66
|
+
*/
|
|
67
|
+
export declare const SKILLS_TAB: string;
|
|
68
|
+
/** A row of the list: a task, or an agent skill. */
|
|
69
|
+
export type ListEntry = {
|
|
70
|
+
task: TaskHit;
|
|
71
|
+
skill?: undefined;
|
|
72
|
+
} | {
|
|
73
|
+
skill: SkillHit;
|
|
74
|
+
task?: undefined;
|
|
75
|
+
};
|
|
76
|
+
/** Everything the screen shows. */
|
|
77
|
+
export interface TuiState {
|
|
78
|
+
catalog: Catalog | null;
|
|
79
|
+
/**
|
|
80
|
+
* The reports the first probe has sent so far, while there is no catalog
|
|
81
|
+
* to show. Null once there is one, and before a probe starts.
|
|
82
|
+
*/
|
|
83
|
+
partial: RunnerReport[] | null;
|
|
84
|
+
/** The runners the running probe has not heard from yet. */
|
|
85
|
+
pending: string[];
|
|
86
|
+
/** How many runners the running probe reports; -1 until it names them. */
|
|
87
|
+
expected: number;
|
|
88
|
+
/** When the running probe started, in ms, so a long refresh can name what it waits on. */
|
|
89
|
+
loadStarted: number;
|
|
90
|
+
/** Where each runner's rows came from, one entry per selected runner. */
|
|
91
|
+
cache: CacheState[];
|
|
92
|
+
/** The agent skills from the last probe. */
|
|
93
|
+
skills: SkillRow[];
|
|
94
|
+
/** `runners.order`, applied to every catalog. */
|
|
95
|
+
runnerOrder: string[] | undefined;
|
|
96
|
+
/** True once a probe has finished, so an empty list is an answer. */
|
|
97
|
+
probed: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* True when the rows came from a probe in this run. Until then they come
|
|
100
|
+
* from the saved listing or the store, and a task is probed again before
|
|
101
|
+
* it runs.
|
|
102
|
+
*/
|
|
103
|
+
fromProbe: boolean;
|
|
104
|
+
/** The selected tab: `all`, a runner id or {@link SKILLS_TAB}. */
|
|
105
|
+
runner: string;
|
|
106
|
+
query: string;
|
|
107
|
+
mode: Mode;
|
|
108
|
+
servicesOnly: boolean;
|
|
109
|
+
declaredOnly: boolean;
|
|
110
|
+
/** Index into {@link SCOPES}. */
|
|
111
|
+
scope: number;
|
|
112
|
+
/** Held by task or skill id, not row index, so a refresh cannot move it to another row. */
|
|
113
|
+
selectedId: string | null;
|
|
114
|
+
scroll: number;
|
|
115
|
+
message: Message | null;
|
|
116
|
+
loading: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* A trust grant waiting for `y`. Trust lets the repository's code run, so
|
|
119
|
+
* one key cannot grant it; `^s` is also flow control on many terminals.
|
|
120
|
+
*/
|
|
121
|
+
confirmingTrust: boolean;
|
|
122
|
+
/** The tool the pending grant is for, or null for the whole repository. */
|
|
123
|
+
trustScope: string | null;
|
|
124
|
+
/** The task whose arguments are being typed, and the text so far. */
|
|
125
|
+
entering: {
|
|
126
|
+
task: Task;
|
|
127
|
+
text: string;
|
|
128
|
+
} | null;
|
|
129
|
+
view: 'list' | 'settings' | 'help';
|
|
130
|
+
/** The view `?` was pressed in, to go back to. */
|
|
131
|
+
helpFrom: 'list' | 'settings';
|
|
132
|
+
helpScroll: number;
|
|
133
|
+
settings: SettingsScreen | null;
|
|
134
|
+
/** The trust grant was removed in this run. */
|
|
135
|
+
revoked: boolean;
|
|
136
|
+
/** Increased on each refresh, so an older result cannot overwrite a newer one. */
|
|
137
|
+
generation: number;
|
|
138
|
+
inFlight: AbortController | null;
|
|
139
|
+
/** The tasks that pass the filters, in the selected tab. */
|
|
140
|
+
rows: TaskHit[];
|
|
141
|
+
/** The skills that pass the filters, listed after the tasks. */
|
|
142
|
+
skillRows: SkillHit[];
|
|
143
|
+
}
|
|
144
|
+
/** One terminal UI. */
|
|
145
|
+
export interface Tui {
|
|
146
|
+
readonly state: TuiState;
|
|
147
|
+
readonly session: Session;
|
|
148
|
+
/** The whole screen as one string. */
|
|
149
|
+
frame(width: number, height: number): string;
|
|
150
|
+
/** One key. */
|
|
151
|
+
handle(key: string): void;
|
|
152
|
+
/** One read from the terminal: each key, with the rows rebuilt after each. */
|
|
153
|
+
feed(chunk: string): void;
|
|
154
|
+
/** Rebuild the rows and keep the selection on a task that is still there. */
|
|
155
|
+
recompute(): void;
|
|
156
|
+
/** Index of the selected row. */
|
|
157
|
+
cursor(): number;
|
|
158
|
+
/** The list's rows: the tasks, then the skills. */
|
|
159
|
+
entries(): ListEntry[];
|
|
160
|
+
/** Write a frame to the host. */
|
|
161
|
+
draw(): void;
|
|
162
|
+
/** Show the stored probe, then probe. */
|
|
163
|
+
boot(): Promise<void>;
|
|
164
|
+
/** Probe again. */
|
|
165
|
+
refresh(): Promise<void>;
|
|
166
|
+
/** Stop any probe, give the terminal back and exit. */
|
|
167
|
+
quit(code: number): void;
|
|
168
|
+
/** Resolves when the work keys started has finished. For tests. */
|
|
169
|
+
idle(): Promise<void>;
|
|
170
|
+
}
|
|
171
|
+
/** What {@link createTui} takes. */
|
|
172
|
+
export interface CreateTuiOptions {
|
|
173
|
+
session: Session;
|
|
174
|
+
host: TuiHost;
|
|
175
|
+
styles: Styles;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* `text` wrapped at word breaks to `width` columns. Each later line is
|
|
179
|
+
* indented to where the text after a key column starts (the first run of two
|
|
180
|
+
* spaces after the first word), so a key's action lines up under itself.
|
|
181
|
+
*/
|
|
182
|
+
export declare function wrapHanging(text: string, width: number): string[];
|
|
183
|
+
/**
|
|
184
|
+
* What the status line says about stale rows, in three states. Fresh says
|
|
185
|
+
* nothing. Stale and measured slow is kept apart from ordinary stale,
|
|
186
|
+
* because it is the case the store exists for.
|
|
187
|
+
*/
|
|
188
|
+
export declare function refreshNote(rows: readonly RunnerCacheState[], loading: boolean): {
|
|
189
|
+
text: string;
|
|
190
|
+
slow: boolean;
|
|
191
|
+
} | null;
|
|
192
|
+
/** Make a terminal UI. Nothing is drawn or probed until {@link Tui.boot}. */
|
|
193
|
+
export declare function createTui({ session, host, styles: s }: CreateTuiOptions): Tui;
|