@osdlc/wayfinder 0.7.3 → 0.8.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 +221 -0
- package/CONTRIBUTING.md +6 -0
- package/README.md +295 -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 +30 -3
- package/dist/catalog.js +87 -11
- 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 +151 -0
- package/dist/commands/index.d.ts +25 -0
- package/dist/commands/index.js +71 -0
- package/dist/commands/list.d.ts +208 -0
- package/dist/commands/list.js +127 -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 +271 -257
- package/dist/config.js +610 -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 +262 -0
- package/dist/core/session.js +589 -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 +432 -0
- package/dist/documents.js +163 -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 +112 -0
- package/dist/index.js +58 -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 +51 -0
- package/dist/serve/catalog-share.js +116 -0
- package/dist/serve/index.d.ts +98 -0
- package/dist/serve/index.js +251 -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 +180 -0
- package/dist/tui/app.js +1278 -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 +89 -0
- package/dist/vocabulary.js +153 -0
- package/dist/web/main.js +1965 -568
- package/dist/web/page.html +39 -33
- package/dist/web/styles.css +457 -329
- package/dist/xdg.d.ts +76 -4
- package/dist/xdg.js +77 -5
- package/package.json +28 -9
- 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/skills.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the agent skills for the Skills group from `@osdlc/detect-harness`.
|
|
3
|
+
* It reads files only. No harness program runs, and no skill runs.
|
|
4
|
+
*/
|
|
5
|
+
import { isAbsolute, relative } from 'node:path';
|
|
6
|
+
import { detect } from '@osdlc/detect-harness';
|
|
7
|
+
/** `path` relative to `root` with `/` separators when it is inside it, else as given. */
|
|
8
|
+
function underRoot(root, path) {
|
|
9
|
+
const rel = relative(root, path);
|
|
10
|
+
const outside = rel === '' || rel === '..' || /^\.\.[\\/]/.test(rel) || isAbsolute(rel);
|
|
11
|
+
return outside ? path : rel.split('\\').join('/');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The skills for `root`, project ones first, then by name. A skill file
|
|
15
|
+
* several agents read is one row that names each of them. `off` reads
|
|
16
|
+
* nothing.
|
|
17
|
+
*/
|
|
18
|
+
export async function readSkills(root, opts) {
|
|
19
|
+
if (opts.setting === 'off')
|
|
20
|
+
return [];
|
|
21
|
+
const catalog = await detect({
|
|
22
|
+
projectRoot: root,
|
|
23
|
+
home: opts.home,
|
|
24
|
+
env: opts.env,
|
|
25
|
+
mode: opts.setting === 'all' ? 'full' : 'project',
|
|
26
|
+
allowExec: false,
|
|
27
|
+
...(opts.signal !== undefined ? { signal: opts.signal } : {}),
|
|
28
|
+
});
|
|
29
|
+
const byPath = new Map();
|
|
30
|
+
for (const report of catalog.reports) {
|
|
31
|
+
for (const skill of report.skills) {
|
|
32
|
+
const path = underRoot(root, skill.path);
|
|
33
|
+
const seen = byPath.get(path);
|
|
34
|
+
if (seen !== undefined) {
|
|
35
|
+
if (!seen.harnesses.includes(report.harness))
|
|
36
|
+
seen.harnesses.push(report.harness);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
byPath.set(path, {
|
|
40
|
+
id: `skill:${path}`,
|
|
41
|
+
name: skill.name,
|
|
42
|
+
description: skill.description,
|
|
43
|
+
argumentHint: skill.argumentHint,
|
|
44
|
+
path,
|
|
45
|
+
scope: skill.scope,
|
|
46
|
+
origin: skill.origin,
|
|
47
|
+
harnesses: [report.harness],
|
|
48
|
+
invoke: `/${skill.name}`,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const rank = (s) => (s.origin === 'project' || s.origin === 'local' ? 0 : 1);
|
|
53
|
+
return [...byPath.values()].sort((a, b) => rank(a) - rank(b) || a.name.localeCompare(b.name));
|
|
54
|
+
}
|
package/dist/terminal-text.d.ts
CHANGED
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Each control character becomes one U+FFFD, so the text keeps its length and
|
|
15
15
|
* a match offset into it still points at the same character.
|
|
16
|
+
*
|
|
17
|
+
* This is wayfinder's one filter for repository text. `stripControls` from
|
|
18
|
+
* `@osdlc/ux` covers the same characters but removes them, and whole escape
|
|
19
|
+
* sequences with them. That changes the length, so the terminal UI's match
|
|
20
|
+
* highlights would point at the wrong characters, and a person would not see
|
|
21
|
+
* that the name held anything. Both filters remove the same set of controls.
|
|
16
22
|
*/
|
|
17
23
|
import { type CliIo } from '@osdlc/cli-tool';
|
|
18
24
|
/**
|
|
@@ -23,6 +29,8 @@ import { type CliIo } from '@osdlc/cli-tool';
|
|
|
23
29
|
export declare function terminalSafe(text: string, opts?: {
|
|
24
30
|
multiline?: boolean;
|
|
25
31
|
}): string;
|
|
32
|
+
/** True when `text` holds a character {@link terminalSafe} replaces. */
|
|
33
|
+
export declare function hasControls(text: string): boolean;
|
|
26
34
|
/**
|
|
27
35
|
* `JSON.stringify(value, null, indent)` with DEL, C1 and the bidi controls
|
|
28
36
|
* written as `\u` escapes. It parses to the same value, and is safe to print
|
package/dist/terminal-text.js
CHANGED
|
@@ -13,17 +13,26 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Each control character becomes one U+FFFD, so the text keeps its length and
|
|
15
15
|
* a match offset into it still points at the same character.
|
|
16
|
+
*
|
|
17
|
+
* This is wayfinder's one filter for repository text. `stripControls` from
|
|
18
|
+
* `@osdlc/ux` covers the same characters but removes them, and whole escape
|
|
19
|
+
* sequences with them. That changes the length, so the terminal UI's match
|
|
20
|
+
* highlights would point at the wrong characters, and a person would not see
|
|
21
|
+
* that the name held anything. Both filters remove the same set of controls.
|
|
16
22
|
*/
|
|
17
23
|
import { EXIT } from '@osdlc/cli-tool';
|
|
18
|
-
import {
|
|
19
|
-
/**
|
|
20
|
-
|
|
24
|
+
import { BIN } from "./app.js";
|
|
25
|
+
/**
|
|
26
|
+
* C0 (tab and newline included), DEL, C1, and the bidi controls: the marks
|
|
27
|
+
* U+061C, U+200E and U+200F, and U+202A-202E and U+2066-2069.
|
|
28
|
+
*/
|
|
29
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;
|
|
21
30
|
/** The same, but tab and newline are kept. */
|
|
22
|
-
const CONTROL_KEEP_LINES = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g;
|
|
31
|
+
const CONTROL_KEEP_LINES = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;
|
|
23
32
|
/** C0 without tab and newline. */
|
|
24
33
|
const C0_KEEP_LINES = /[\u0000-\u0008\u000b-\u001f]/g;
|
|
25
34
|
/** What `JSON.stringify` leaves raw of the above: it escapes C0 itself. */
|
|
26
|
-
const JSON_RAW = /[\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g;
|
|
35
|
+
const JSON_RAW = /[\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g;
|
|
27
36
|
const REPLACEMENT = '�';
|
|
28
37
|
/**
|
|
29
38
|
* `text` with every C0 control character (ESC included), DEL, C1 control
|
|
@@ -33,6 +42,10 @@ const REPLACEMENT = '�';
|
|
|
33
42
|
export function terminalSafe(text, opts = {}) {
|
|
34
43
|
return text.replace(opts.multiline === true ? CONTROL_KEEP_LINES : CONTROL, REPLACEMENT);
|
|
35
44
|
}
|
|
45
|
+
/** True when `text` holds a character {@link terminalSafe} replaces. */
|
|
46
|
+
export function hasControls(text) {
|
|
47
|
+
return new RegExp(CONTROL.source).test(text);
|
|
48
|
+
}
|
|
36
49
|
/**
|
|
37
50
|
* `JSON.stringify(value, null, indent)` with DEL, C1 and the bidi controls
|
|
38
51
|
* written as `\u` escapes. It parses to the same value, and is safe to print
|
|
@@ -85,7 +98,7 @@ export async function guardedExit(run, stderr = (text) => process.stderr.write(t
|
|
|
85
98
|
}
|
|
86
99
|
catch (err) {
|
|
87
100
|
const message = err instanceof Error ? err.message : String(err);
|
|
88
|
-
stderr(`${
|
|
101
|
+
stderr(`${BIN}: ${terminalSafe(message)}\n`);
|
|
89
102
|
return EXIT.error;
|
|
90
103
|
}
|
|
91
104
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a settings screen and `way providers` say about a tool: what it is,
|
|
3
|
+
* its homepage and its language, from `@osdlc/system-model`'s `ToolDef`.
|
|
4
|
+
*/
|
|
5
|
+
import type { ToolDef } from '@osdlc/system-model/detect';
|
|
6
|
+
/** One tool's description, homepage and language. */
|
|
7
|
+
export interface ToolSummary {
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The project's site, `https://` or `http://` only, so a page can link it.
|
|
11
|
+
* Null for a custom tool that sets none or sets another scheme.
|
|
12
|
+
*/
|
|
13
|
+
homepage: string | null;
|
|
14
|
+
/** One sentence on what the tool is. Null for a custom tool that sets none. */
|
|
15
|
+
description: string | null;
|
|
16
|
+
/** The ecosystem id, such as `node`. Null for a tool of no one language. */
|
|
17
|
+
ecosystem: string | null;
|
|
18
|
+
/** The language a person reads: `JavaScript`, or `any language` (see `languageLabel`). */
|
|
19
|
+
language: string;
|
|
20
|
+
/** The runner role's kind: `exec` needs trust to be read. Null with no runner role. */
|
|
21
|
+
runnerKind: 'parse' | 'exec' | null;
|
|
22
|
+
}
|
|
23
|
+
/** The summary of `tool`. A custom tool's `homepage` and `description` are repository text. */
|
|
24
|
+
export declare function toolSummary(tool: ToolDef): ToolSummary;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a settings screen and `way providers` say about a tool: what it is,
|
|
3
|
+
* its homepage and its language, from `@osdlc/system-model`'s `ToolDef`.
|
|
4
|
+
*/
|
|
5
|
+
import { languageLabel } from "./vocabulary.js";
|
|
6
|
+
/** The summary of `tool`. A custom tool's `homepage` and `description` are repository text. */
|
|
7
|
+
export function toolSummary(tool) {
|
|
8
|
+
const ecosystem = tool.ecosystem?.id ?? null;
|
|
9
|
+
return {
|
|
10
|
+
id: tool.id,
|
|
11
|
+
homepage: tool.homepage !== undefined && /^https?:\/\//i.test(tool.homepage) ? tool.homepage : null,
|
|
12
|
+
description: tool.description ?? null,
|
|
13
|
+
ecosystem,
|
|
14
|
+
language: languageLabel(ecosystem),
|
|
15
|
+
runnerKind: tool.roles.runner?.kind ?? null,
|
|
16
|
+
};
|
|
17
|
+
}
|
package/dist/trust-command.d.ts
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
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 { type
|
|
11
|
+
import { type DataCommand } from '@osdlc/cli-tool/command';
|
|
12
|
+
import type { FlagSpec } from '@osdlc/cli-tool/define-cli';
|
|
13
|
+
import { type CommandEnvOptions } from './config-command.ts';
|
|
14
14
|
/**
|
|
15
|
-
* `
|
|
15
|
+
* The `trust` command. Mount it as `trust: trustCommand({ globals })`, with
|
|
16
|
+
* the app's global flags; `-C` must be declared as `dir`.
|
|
16
17
|
*/
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/** Defaults to `homeDir()` from `@osdlc/trust-repo`. The base for the non-XDG state path. */
|
|
21
|
-
home?: string;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* `<tool> trust [--untrust|--show|--list]`. `root` is the resolved project
|
|
25
|
-
* root. Returns the exit code.
|
|
26
|
-
*
|
|
27
|
-
* Exit codes follow `runConfigCommand`. 2 is a command that cannot run as
|
|
28
|
-
* typed, decided from the arguments alone. 1 is a valid command that failed
|
|
29
|
-
* against the state it found: here, `--untrust` on a root with no marker, or a
|
|
30
|
-
* config file that will not parse.
|
|
31
|
-
*/
|
|
32
|
-
export declare function runTrustCommand(toolName: string, root: string, argv: string[], io: TrustCommandIO): Promise<number>;
|
|
18
|
+
export declare function trustCommand<G extends FlagSpec = Record<never, never>>(options?: CommandEnvOptions & {
|
|
19
|
+
globals?: G;
|
|
20
|
+
}): DataCommand;
|
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
|
}
|