@osdlc/wayfinder 0.7.4 → 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 +214 -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/SECURITY.md
CHANGED
|
@@ -56,7 +56,7 @@ making `way` run code the user did not choose to run are in scope.
|
|
|
56
56
|
- **Repository text cannot drive the terminal.** Task names, docs, paths and
|
|
57
57
|
config values have their control characters (C0, DEL, C1) and bidi controls
|
|
58
58
|
(U+202A-202E, U+2066-2069) replaced with U+FFFD before the terminal UI,
|
|
59
|
-
|
|
59
|
+
`list`, `query`, `trust`, `config`, `providers`, `dev`, the `serve`
|
|
60
60
|
summary or stderr prints them. Copied commands get the same text. `--json`,
|
|
61
61
|
`way dev … --json` included, keeps every value exact: C0 is escaped by JSON
|
|
62
62
|
itself, and DEL, C1 and the bidi controls are written as `\u` escapes, so
|
|
@@ -74,9 +74,23 @@ making `way` run code the user did not choose to run are in scope.
|
|
|
74
74
|
- **Tasks run without a shell.** A task is spawned from an argument vector.
|
|
75
75
|
Typed arguments are bound by the task's tool and never replace its binary.
|
|
76
76
|
- **The web view listens on 127.0.0.1.** Any local process and any page the
|
|
77
|
-
browser visits can reach the port.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
browser visits can reach the port. Requests must name a loopback `Host` and
|
|
78
|
+
carry no foreign `Origin`. A one-shot boot token signs the page in, and a
|
|
79
|
+
bearer token protects every command and `/run`. The boot token is in the
|
|
80
|
+
URL the server opens or prints; it works once and expires a minute after
|
|
81
|
+
it is shown. Sent again, it is refused and the server warns in its
|
|
82
|
+
terminal; sessions already signed in keep working. There is one bearer
|
|
83
|
+
token per server, so a program that redeemed the link first keeps its
|
|
84
|
+
session until the server stops, and a new link does not sign it out. If
|
|
85
|
+
you did not open the link twice, stop the server and start it again. The
|
|
86
|
+
bearer token is never in a URL or a cookie: the page keeps it in
|
|
87
|
+
`sessionStorage`, which belongs to one tab, survives a reload and is never
|
|
88
|
+
sent with a request. A script running in the page could read it, so the
|
|
89
|
+
page loads no third-party code. A new tab needs a new boot token: Enter in
|
|
90
|
+
the `way serve` terminal makes one and retires the previous one. `/run`
|
|
91
|
+
takes a task id from the server's own catalog, never a command. Commands
|
|
92
|
+
keep the flags `way serve` started with, so `--no-exec` cannot be lifted
|
|
93
|
+
from the page, and a write of `allowExec`, a trust setting or `tools` is
|
|
94
|
+
refused.
|
|
81
95
|
- **Trust is keyed on the resolved path.** A trusted repository that later
|
|
82
96
|
pulls hostile changes stays trusted until `way trust --untrust`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every action the terminal UI and the web view offer, and the command that
|
|
3
|
+
* does the same thing. A script or an agent never has to drive a UI: each
|
|
4
|
+
* row names the command. `tests/actions.test.ts` checks that every command
|
|
5
|
+
* and flag named here exists in the command tree.
|
|
6
|
+
*
|
|
7
|
+
* Browser-safe: no Node built-in.
|
|
8
|
+
*/
|
|
9
|
+
/** One action, where each surface offers it, and its command. */
|
|
10
|
+
export interface SurfaceAction {
|
|
11
|
+
/** What the person does. */
|
|
12
|
+
action: string;
|
|
13
|
+
/** The terminal UI's key, or null when it has none. */
|
|
14
|
+
tui: string | null;
|
|
15
|
+
/** The web view's control, or null when it has none. */
|
|
16
|
+
web: string | null;
|
|
17
|
+
/** The command words, such as `['trust']` or `['config', 'set']`. */
|
|
18
|
+
command: readonly string[];
|
|
19
|
+
/** The flags it takes for this action, by their JSON names (`untrust`, `scope`). */
|
|
20
|
+
flags: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
/** The table. */
|
|
23
|
+
export declare const SURFACE_ACTIONS: readonly SurfaceAction[];
|
package/dist/actions.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every action the terminal UI and the web view offer, and the command that
|
|
3
|
+
* does the same thing. A script or an agent never has to drive a UI: each
|
|
4
|
+
* row names the command. `tests/actions.test.ts` checks that every command
|
|
5
|
+
* and flag named here exists in the command tree.
|
|
6
|
+
*
|
|
7
|
+
* Browser-safe: no Node built-in.
|
|
8
|
+
*/
|
|
9
|
+
/** The table. */
|
|
10
|
+
export const SURFACE_ACTIONS = Object.freeze([
|
|
11
|
+
{ action: 'browse', tui: 'the list', web: 'the list', command: ['list'], flags: [] },
|
|
12
|
+
{
|
|
13
|
+
action: 'search',
|
|
14
|
+
tui: 'type, ^e exact',
|
|
15
|
+
web: 'search box, Fuzzy / Exact',
|
|
16
|
+
command: ['query'],
|
|
17
|
+
flags: ['exact'],
|
|
18
|
+
},
|
|
19
|
+
{ action: 'services only', tui: '^t', web: 'Services', command: ['list'], flags: ['services'] },
|
|
20
|
+
{ action: 'declared only', tui: '^d', web: 'Declared', command: ['list'], flags: ['declared'] },
|
|
21
|
+
{ action: 'scope', tui: '^o', web: 'Scope', command: ['list'], flags: ['depth'] },
|
|
22
|
+
{
|
|
23
|
+
action: 'one runner, hide runners',
|
|
24
|
+
tui: 'tab',
|
|
25
|
+
web: 'tabs, Runners',
|
|
26
|
+
command: ['list'],
|
|
27
|
+
flags: ['only', 'exclude'],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
action: 'reorder runners',
|
|
31
|
+
tui: 'settings [ ]',
|
|
32
|
+
web: 'drag a tab',
|
|
33
|
+
command: ['config', 'set'],
|
|
34
|
+
flags: ['user'],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
action: 'run, with arguments',
|
|
38
|
+
tui: 'enter',
|
|
39
|
+
web: 'run, Shift+Enter',
|
|
40
|
+
command: ['run'],
|
|
41
|
+
flags: [],
|
|
42
|
+
},
|
|
43
|
+
{ action: 'copy a command', tui: '^y', web: 'copy, Enter', command: ['list'], flags: [] },
|
|
44
|
+
{ action: 'refresh', tui: '^r', web: 'Refresh', command: ['list'], flags: [] },
|
|
45
|
+
{
|
|
46
|
+
action: 'trust the repository',
|
|
47
|
+
tui: '^s',
|
|
48
|
+
web: 'Trust this repository',
|
|
49
|
+
command: ['trust'],
|
|
50
|
+
flags: [],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
action: 'trust one tool',
|
|
54
|
+
tui: 'settings t',
|
|
55
|
+
web: 'settings, Trust',
|
|
56
|
+
command: ['trust'],
|
|
57
|
+
flags: ['scope'],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
action: 'untrust',
|
|
61
|
+
tui: 'settings u',
|
|
62
|
+
web: 'settings, Untrust',
|
|
63
|
+
command: ['trust'],
|
|
64
|
+
flags: ['untrust', 'scope'],
|
|
65
|
+
},
|
|
66
|
+
{ action: 'view settings', tui: ',', web: 'settings', command: ['config', 'list'], flags: [] },
|
|
67
|
+
{
|
|
68
|
+
action: 'edit a setting',
|
|
69
|
+
tui: 'settings',
|
|
70
|
+
web: 'settings, Save',
|
|
71
|
+
command: ['config', 'set'],
|
|
72
|
+
flags: ['user', 'project'],
|
|
73
|
+
},
|
|
74
|
+
{ action: 'theme', tui: null, web: 'theme button', command: ['config', 'set'], flags: ['user'] },
|
|
75
|
+
{
|
|
76
|
+
action: 'runner info',
|
|
77
|
+
tui: 'detail line, settings',
|
|
78
|
+
web: 'i',
|
|
79
|
+
command: ['providers'],
|
|
80
|
+
flags: [],
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
action: 'skills: list, search, copy /name',
|
|
84
|
+
tui: 'Skills tab',
|
|
85
|
+
web: 'Skills tab',
|
|
86
|
+
command: ['query'],
|
|
87
|
+
flags: [],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
action: 'withheld runners and why',
|
|
91
|
+
tui: 'status line',
|
|
92
|
+
web: 'trust bar',
|
|
93
|
+
command: ['list'],
|
|
94
|
+
flags: [],
|
|
95
|
+
},
|
|
96
|
+
{ action: 'help', tui: '?', web: '?', command: ['help'], flags: [] },
|
|
97
|
+
]);
|
package/dist/app.d.ts
CHANGED
|
@@ -2,23 +2,11 @@
|
|
|
2
2
|
* The app's names. Every user-facing name that carries the product name
|
|
3
3
|
* derives from here. Browser-safe: the page imports it too.
|
|
4
4
|
*/
|
|
5
|
-
/** The product name: config directory, cache directory
|
|
5
|
+
/** The product name: config directory, cache directory and trust store key. Messages start with {@link BIN}. */
|
|
6
6
|
export declare const APP = "wayfinder";
|
|
7
|
-
/**
|
|
8
|
-
* The name before the rename to wayfinder. Its user config, project config,
|
|
9
|
-
* trust store and config variable are still read when the new ones are
|
|
10
|
-
* absent. Nothing is written under it.
|
|
11
|
-
*/
|
|
12
|
-
export declare const LEGACY_APP = "waypost";
|
|
13
7
|
/** The installed command. */
|
|
14
8
|
export declare const BIN = "way";
|
|
15
9
|
/** Names the user config file, replacing its location only. */
|
|
16
10
|
export declare const CONFIG_ENV_VAR: string;
|
|
17
|
-
/** The old name of {@link CONFIG_ENV_VAR}, read when that one is unset. */
|
|
18
|
-
export declare const LEGACY_CONFIG_ENV_VAR: string;
|
|
19
11
|
/** The project config file, read from the project root. */
|
|
20
12
|
export declare const PROJECT_CONFIG_FILENAME = "wayfinder.config.json";
|
|
21
|
-
/** The old project config file, read when {@link PROJECT_CONFIG_FILENAME} is absent. */
|
|
22
|
-
export declare const LEGACY_PROJECT_CONFIG_FILENAME = "waypost.config.json";
|
|
23
|
-
/** The request header that carries the web view's session token. */
|
|
24
|
-
export declare const TOKEN_HEADER = "x-wayfinder-token";
|
package/dist/app.js
CHANGED
|
@@ -2,23 +2,11 @@
|
|
|
2
2
|
* The app's names. Every user-facing name that carries the product name
|
|
3
3
|
* derives from here. Browser-safe: the page imports it too.
|
|
4
4
|
*/
|
|
5
|
-
/** The product name: config directory, cache directory
|
|
5
|
+
/** The product name: config directory, cache directory and trust store key. Messages start with {@link BIN}. */
|
|
6
6
|
export const APP = 'wayfinder';
|
|
7
|
-
/**
|
|
8
|
-
* The name before the rename to wayfinder. Its user config, project config,
|
|
9
|
-
* trust store and config variable are still read when the new ones are
|
|
10
|
-
* absent. Nothing is written under it.
|
|
11
|
-
*/
|
|
12
|
-
export const LEGACY_APP = 'waypost';
|
|
13
7
|
/** The installed command. */
|
|
14
8
|
export const BIN = 'way';
|
|
15
9
|
/** Names the user config file, replacing its location only. */
|
|
16
10
|
export const CONFIG_ENV_VAR = `${APP.toUpperCase()}_CONFIG`;
|
|
17
|
-
/** The old name of {@link CONFIG_ENV_VAR}, read when that one is unset. */
|
|
18
|
-
export const LEGACY_CONFIG_ENV_VAR = `${LEGACY_APP.toUpperCase()}_CONFIG`;
|
|
19
11
|
/** The project config file, read from the project root. */
|
|
20
12
|
export const PROJECT_CONFIG_FILENAME = `${APP}.config.json`;
|
|
21
|
-
/** The old project config file, read when {@link PROJECT_CONFIG_FILENAME} is absent. */
|
|
22
|
-
export const LEGACY_PROJECT_CONFIG_FILENAME = `${LEGACY_APP}.config.json`;
|
|
23
|
-
/** The request header that carries the web view's session token. */
|
|
24
|
-
export const TOKEN_HEADER = `x-${APP}-token`;
|
package/dist/args.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type { Project, Task } from '@osdlc/system-model/detect';
|
|
|
14
14
|
* `--`.
|
|
15
15
|
*
|
|
16
16
|
* The binary is always `task.argv[0]`, from a catalog this process built by
|
|
17
|
-
* reading the repository, never from a request. `/
|
|
17
|
+
* reading the repository, never from a request. The web view's `/run` is reachable by any
|
|
18
18
|
* process on the machine and any site the browser visits, so a caller that
|
|
19
19
|
* could set element 0 could run anything. A tool whose `invoke` changes the
|
|
20
20
|
* binary is refused.
|
|
@@ -32,11 +32,16 @@ export declare function acceptArgs(value: unknown): string[];
|
|
|
32
32
|
* Split typed arguments into words the way a shell does, and do nothing else
|
|
33
33
|
* a shell does.
|
|
34
34
|
*
|
|
35
|
-
* Quotes group
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
35
|
+
* Quotes group words as in sh. Outside quotes a backslash escapes the next
|
|
36
|
+
* character. Inside single quotes every character is literal, a backslash
|
|
37
|
+
* too, so `'C:\tmp'` stays as typed. Inside double quotes a backslash escapes
|
|
38
|
+
* only `"`, `\`, `$` and a backtick, and is kept before anything else.
|
|
39
|
+
*
|
|
40
|
+
* There is no globbing, no variable expansion, no operators and no
|
|
41
|
+
* substitution. The result goes to an `execvp`-style spawn as separate argv
|
|
42
|
+
* entries, never to a shell, so `*.log` is passed through as the five
|
|
43
|
+
* characters typed. This is the same rule that keeps `argv` separate from
|
|
44
|
+
* `display`.
|
|
40
45
|
*
|
|
41
46
|
* This is not `.split(/\s+/)` for one reason: a quoted `"two words"` must stay
|
|
42
47
|
* one argument.
|
package/dist/args.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* `--`.
|
|
14
14
|
*
|
|
15
15
|
* The binary is always `task.argv[0]`, from a catalog this process built by
|
|
16
|
-
* reading the repository, never from a request. `/
|
|
16
|
+
* reading the repository, never from a request. The web view's `/run` is reachable by any
|
|
17
17
|
* process on the machine and any site the browser visits, so a caller that
|
|
18
18
|
* could set element 0 could run anything. A tool whose `invoke` changes the
|
|
19
19
|
* binary is refused.
|
|
@@ -43,11 +43,16 @@ export function acceptArgs(value) {
|
|
|
43
43
|
* Split typed arguments into words the way a shell does, and do nothing else
|
|
44
44
|
* a shell does.
|
|
45
45
|
*
|
|
46
|
-
* Quotes group
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
46
|
+
* Quotes group words as in sh. Outside quotes a backslash escapes the next
|
|
47
|
+
* character. Inside single quotes every character is literal, a backslash
|
|
48
|
+
* too, so `'C:\tmp'` stays as typed. Inside double quotes a backslash escapes
|
|
49
|
+
* only `"`, `\`, `$` and a backtick, and is kept before anything else.
|
|
50
|
+
*
|
|
51
|
+
* There is no globbing, no variable expansion, no operators and no
|
|
52
|
+
* substitution. The result goes to an `execvp`-style spawn as separate argv
|
|
53
|
+
* entries, never to a shell, so `*.log` is passed through as the five
|
|
54
|
+
* characters typed. This is the same rule that keeps `argv` separate from
|
|
55
|
+
* `display`.
|
|
51
56
|
*
|
|
52
57
|
* This is not `.split(/\s+/)` for one reason: a quoted `"two words"` must stay
|
|
53
58
|
* one argument.
|
|
@@ -59,8 +64,21 @@ export function splitArgs(input) {
|
|
|
59
64
|
let quote = null;
|
|
60
65
|
for (let i = 0; i < input.length; i++) {
|
|
61
66
|
const ch = input[i];
|
|
67
|
+
if (quote === "'") {
|
|
68
|
+
if (ch === "'")
|
|
69
|
+
quote = null;
|
|
70
|
+
else
|
|
71
|
+
current += ch;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
62
74
|
if (ch === '\\' && i + 1 < input.length) {
|
|
63
|
-
|
|
75
|
+
const next = input[i + 1];
|
|
76
|
+
if (quote === '"' && !'"\\$`'.includes(next)) {
|
|
77
|
+
current += ch;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
current += next;
|
|
81
|
+
i++;
|
|
64
82
|
started = true;
|
|
65
83
|
continue;
|
|
66
84
|
}
|
package/dist/cache.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Where stored runner probes live:
|
|
3
|
-
*
|
|
2
|
+
* Where stored runner probes live: `<cache>/wayfinder` (see `xdg.ts`).
|
|
3
|
+
* `@osdlc/system-model` owns the layout inside it.
|
|
4
4
|
*/
|
|
5
5
|
export declare function cacheDir(env?: Record<string, string | undefined>, home?: string): string;
|
|
6
|
-
/** The old waypost cache directory. Never read; `way clean` offers to remove it. */
|
|
7
|
-
export declare function legacyCacheDir(env?: Record<string, string | undefined>, home?: string): string;
|
package/dist/cache.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { APP, LEGACY_APP } from "./app.js";
|
|
1
|
+
import { homeDir } from '@osdlc/trust-repo';
|
|
2
|
+
import { appDirs } from "./xdg.js";
|
|
4
3
|
/**
|
|
5
|
-
* Where stored runner probes live:
|
|
6
|
-
*
|
|
4
|
+
* Where stored runner probes live: `<cache>/wayfinder` (see `xdg.ts`).
|
|
5
|
+
* `@osdlc/system-model` owns the layout inside it.
|
|
7
6
|
*/
|
|
8
7
|
export function cacheDir(env = process.env, home = homeDir()) {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
/** The old waypost cache directory. Never read; `way clean` offers to remove it. */
|
|
12
|
-
export function legacyCacheDir(env = process.env, home = homeDir()) {
|
|
13
|
-
return join(xdgHome(env, home, 'XDG_CACHE_HOME', '.cache'), LEGACY_APP);
|
|
8
|
+
return appDirs({ env, home }).cache;
|
|
14
9
|
}
|
package/dist/catalog.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* repository, then collect (or read the cache) with the options wayfinder
|
|
4
4
|
* resolved from flags, config and trust.
|
|
5
5
|
*/
|
|
6
|
-
import { type CachedCatalog, type Catalog, type DiscoveryMode, type Project, type
|
|
6
|
+
import { type CachedCatalog, type Catalog, type DiscoveryMode, type Project, type ToolDef } from '@osdlc/system-model/detect';
|
|
7
7
|
/**
|
|
8
8
|
* Everything one collection needs: detection settings and runner selection
|
|
9
9
|
* together, because both come from the same flags and config keys.
|
|
@@ -20,15 +20,42 @@ export interface WayOptions {
|
|
|
20
20
|
discovery?: DiscoveryMode | 'auto' | undefined;
|
|
21
21
|
excludePaths?: string[] | undefined;
|
|
22
22
|
signal?: AbortSignal | undefined;
|
|
23
|
+
/** Called with each probed runner's measured time. */
|
|
24
|
+
onProbe?: ((probe: {
|
|
25
|
+
runner: string;
|
|
26
|
+
durationMs: number;
|
|
27
|
+
}) => void) | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Per-tool trust, for a repository that is not trusted as a whole. Used
|
|
30
|
+
* only while `allowExec` is false. See {@link ToolTrust}.
|
|
31
|
+
*/
|
|
32
|
+
toolTrust?: ToolTrust | undefined;
|
|
23
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Trust grants for single tools. A runner may run its tool when its own id
|
|
36
|
+
* and each tool manager that wraps commands at the root (mise, proto) are
|
|
37
|
+
* trusted: `mise exec -- just` runs mise as well as just. Detection itself
|
|
38
|
+
* runs no tool under a tool grant.
|
|
39
|
+
*/
|
|
40
|
+
export interface ToolTrust {
|
|
41
|
+
/** The trusted scopes: runner and tool ids. Read on every collection. */
|
|
42
|
+
trusted: ReadonlySet<string>;
|
|
43
|
+
/** Called on every collection with each runner's scopes, once detection knows the wrappers. */
|
|
44
|
+
onScopes?: ((scopes: ReadonlyMap<string, readonly string[]>) => void) | undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The project root `dir` is in, found with the built-in tools only. Null when
|
|
48
|
+
* `dir` is not a directory, so a typo never names the enclosing repository.
|
|
49
|
+
*/
|
|
50
|
+
export declare function projectRootFor(dir: string): Promise<string | null>;
|
|
24
51
|
/** The built-in tools plus `extra`. Throws when two tools share an id. */
|
|
25
52
|
export declare function makeProject(extra?: readonly ToolDef[]): Project;
|
|
53
|
+
/** The ids of every registered tool with a runner role. */
|
|
54
|
+
export declare function runnerIds(project: Project): string[];
|
|
26
55
|
/** Detect, collect, and store each runner's result under `store`. */
|
|
27
56
|
export declare function collectAndCache(project: Project, root: string, options: WayOptions, store: string): Promise<Catalog>;
|
|
28
57
|
/** Detect, then read what `store` holds, without running any runner. */
|
|
29
58
|
export declare function readCachedCatalog(project: Project, root: string, options: WayOptions, store: string): Promise<CachedCatalog>;
|
|
30
|
-
/** Every report in `catalog`, marked fresh: the verdict right after a probe. */
|
|
31
|
-
export declare function freshStates(catalog: Catalog): RunnerCacheState[];
|
|
32
59
|
/** True when something came out of the store, not only withheld reports. */
|
|
33
60
|
export declare function fromStore(cached: CachedCatalog): boolean;
|
|
34
61
|
/**
|
package/dist/catalog.js
CHANGED
|
@@ -3,10 +3,21 @@
|
|
|
3
3
|
* repository, then collect (or read the cache) with the options wayfinder
|
|
4
4
|
* resolved from flags, config and trust.
|
|
5
5
|
*/
|
|
6
|
+
import { stat } from 'node:fs/promises';
|
|
6
7
|
import { builtins } from '@osdlc/system-model/builtins';
|
|
7
8
|
import { createProject, } from '@osdlc/system-model/detect';
|
|
8
9
|
import { orderRunners } from "./config.js";
|
|
9
10
|
import { groupRank } from "./groups.js";
|
|
11
|
+
/**
|
|
12
|
+
* The project root `dir` is in, found with the built-in tools only. Null when
|
|
13
|
+
* `dir` is not a directory, so a typo never names the enclosing repository.
|
|
14
|
+
*/
|
|
15
|
+
export async function projectRootFor(dir) {
|
|
16
|
+
const info = await stat(dir).catch(() => null);
|
|
17
|
+
if (info === null || !info.isDirectory())
|
|
18
|
+
return null;
|
|
19
|
+
return makeProject().findRoot(dir);
|
|
20
|
+
}
|
|
10
21
|
/** The built-in tools plus `extra`. Throws when two tools share an id. */
|
|
11
22
|
export function makeProject(extra = []) {
|
|
12
23
|
return createProject({ tools: [...builtins, ...extra] });
|
|
@@ -26,26 +37,91 @@ function collectOptions(o) {
|
|
|
26
37
|
allowExec: o.allowExec ?? false,
|
|
27
38
|
execWithheldHint: o.execWithheldHint,
|
|
28
39
|
signal: o.signal,
|
|
40
|
+
onProbe: o.onProbe,
|
|
29
41
|
};
|
|
30
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The tool managers detected at the root that run commands through
|
|
45
|
+
* themselves (`mise exec -- <binary>`), as trust scopes.
|
|
46
|
+
*/
|
|
47
|
+
function wrapperScopes(project, profile) {
|
|
48
|
+
const exec = new Set(project.tools.filter((t) => t.roles.toolManager?.exec !== undefined).map((t) => t.id));
|
|
49
|
+
return project
|
|
50
|
+
.toolManagers(profile)
|
|
51
|
+
.map((d) => d.tool)
|
|
52
|
+
.filter((id) => exec.has(id));
|
|
53
|
+
}
|
|
54
|
+
/** Every scope `runner` needs trusted: its own id, then each wrapper. */
|
|
55
|
+
function runnerScopes(runner, wrappers) {
|
|
56
|
+
return [runner, ...wrappers.filter((w) => w !== runner)];
|
|
57
|
+
}
|
|
58
|
+
/** The ids of every registered tool with a runner role. */
|
|
59
|
+
export function runnerIds(project) {
|
|
60
|
+
return project.tools.filter((t) => t.roles.runner !== undefined).map((t) => t.id);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The runners a tool grant lets run, or null when collection is not split:
|
|
64
|
+
* execution is allowed for all, or there is no per-tool trust. Reports each
|
|
65
|
+
* runner's scopes through `onScopes` first.
|
|
66
|
+
*/
|
|
67
|
+
function grantedRunners(project, profile, o) {
|
|
68
|
+
const trust = o.toolTrust;
|
|
69
|
+
if (o.allowExec === true || trust === undefined)
|
|
70
|
+
return null;
|
|
71
|
+
const wrappers = wrapperScopes(project, profile);
|
|
72
|
+
const scopes = new Map(runnerIds(project).map((r) => [r, runnerScopes(r, wrappers)]));
|
|
73
|
+
trust.onScopes?.(scopes);
|
|
74
|
+
const granted = [...scopes]
|
|
75
|
+
.filter(([runner, needs]) => {
|
|
76
|
+
if (o.only !== undefined && !o.only.includes(runner))
|
|
77
|
+
return false;
|
|
78
|
+
if (o.exclude?.includes(runner) === true)
|
|
79
|
+
return false;
|
|
80
|
+
return needs.every((s) => trust.trusted.has(s));
|
|
81
|
+
})
|
|
82
|
+
.map(([runner]) => runner);
|
|
83
|
+
return granted.length > 0 ? granted : null;
|
|
84
|
+
}
|
|
85
|
+
/** The collect options for the runners a tool grant covers, and for the rest. */
|
|
86
|
+
function splitOptions(o, granted) {
|
|
87
|
+
const base = collectOptions(o);
|
|
88
|
+
const { execWithheldHint: _hint, exclude: _exclude, ...rest } = base;
|
|
89
|
+
return {
|
|
90
|
+
granted: { ...rest, allowExec: true, only: granted },
|
|
91
|
+
others: { ...base, exclude: [...(o.exclude ?? []), ...granted] },
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function mergeCatalogs(granted, others) {
|
|
95
|
+
return { ...others, reports: [...granted.reports, ...others.reports] };
|
|
96
|
+
}
|
|
31
97
|
/** Detect, collect, and store each runner's result under `store`. */
|
|
32
98
|
export async function collectAndCache(project, root, options, store) {
|
|
33
99
|
const profile = await detect(project, root, options);
|
|
34
|
-
|
|
100
|
+
const granted = grantedRunners(project, profile, options);
|
|
101
|
+
if (granted === null) {
|
|
102
|
+
return project.runners.collectAndCache(profile, store, collectOptions(options));
|
|
103
|
+
}
|
|
104
|
+
const split = splitOptions(options, granted);
|
|
105
|
+
const a = await project.runners.collectAndCache(profile, store, split.granted);
|
|
106
|
+
const b = await project.runners.collectAndCache(profile, store, split.others);
|
|
107
|
+
return mergeCatalogs(a, b);
|
|
35
108
|
}
|
|
36
109
|
/** Detect, then read what `store` holds, without running any runner. */
|
|
37
110
|
export async function readCachedCatalog(project, root, options, store) {
|
|
38
111
|
const profile = await detect(project, root, options);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
112
|
+
const granted = grantedRunners(project, profile, options);
|
|
113
|
+
if (granted === null) {
|
|
114
|
+
return project.runners.readCached(profile, store, collectOptions(options));
|
|
115
|
+
}
|
|
116
|
+
const split = splitOptions(options, granted);
|
|
117
|
+
const a = await project.runners.readCached(profile, store, split.granted);
|
|
118
|
+
const b = await project.runners.readCached(profile, store, split.others);
|
|
119
|
+
const catalog = a.catalog === null
|
|
120
|
+
? b.catalog
|
|
121
|
+
: b.catalog === null
|
|
122
|
+
? a.catalog
|
|
123
|
+
: mergeCatalogs(a.catalog, b.catalog);
|
|
124
|
+
return { catalog, runners: [...a.runners, ...b.runners], allFresh: a.allFresh && b.allFresh };
|
|
49
125
|
}
|
|
50
126
|
/** True when something came out of the store, not only withheld reports. */
|
|
51
127
|
export function fromStore(cached) {
|
package/dist/clean-command.d.ts
CHANGED
|
@@ -1,43 +1,72 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* holds something.
|
|
2
|
+
* `way clean`: the data wayfinder keeps outside your repositories. Bare
|
|
3
|
+
* `clean` only reports what each store is, where it is, and whether anything
|
|
4
|
+
* is in it. A flag names what to remove; with no flag nothing is removed.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* | flag | store |
|
|
7
|
+
* |---|---|
|
|
8
|
+
* | `--cache` | stored probe results: derived, costs one slow probe |
|
|
9
|
+
* | `--trust` | the repositories you trusted: consent, asked again |
|
|
10
|
+
* | `--user-config` | your user config: the only store a person wrote, so it needs `--yes` |
|
|
11
|
+
* | `--dev` | `way dev` link state, and the `way dev install` shims on PATH |
|
|
12
|
+
* | `--legacy` | files kept under the tool's name before its first release |
|
|
8
13
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
14
|
+
* `--everything` is every one of them, and needs `--yes`. A store that is only
|
|
15
|
+
* listed when it holds something (shims, old files) is left out of the report
|
|
16
|
+
* when it is empty. Once a store is gone, the directories above it are removed
|
|
17
|
+
* while they are empty, up to the base directory (`~/.config`, say).
|
|
13
18
|
*
|
|
14
|
-
*
|
|
19
|
+
* Nothing inside a repository is touched: `wayfinder.config.json` belongs to
|
|
20
|
+
* the project. A user config that `WAYFINDER_CONFIG` names is named with the
|
|
21
|
+
* variable in the report and again before it is removed, since it may live in
|
|
22
|
+
* a dotfiles repository.
|
|
15
23
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* So `--config` (and `--all`, which includes it) also needs `--yes`.
|
|
25
|
-
*
|
|
26
|
-
* ## What it will not touch
|
|
27
|
-
*
|
|
28
|
-
* Anything inside a repository. `wayfinder.config.json` is a project file that
|
|
29
|
-
* belongs to whoever wrote it, not to this tool's data. Only paths under the
|
|
30
|
-
* user's home (or their XDG overrides) are removed.
|
|
31
|
-
*
|
|
32
|
-
* `stdout`, `stderr`, `env` and `home` are injected, so a test cannot read or
|
|
33
|
-
* delete the developer's real stores.
|
|
24
|
+
* Clean removes only what it owns. A file store must be a file (a symbolic
|
|
25
|
+
* link is removed, not its target), a directory store a directory, and no
|
|
26
|
+
* store may be the home directory, a directory above it or a filesystem root.
|
|
27
|
+
* A store whose path is, holds or sits in another flag's store is removed
|
|
28
|
+
* only with `--yes`.
|
|
29
|
+
* A file `WAYFINDER_CONFIG` names is removed only when its `$schema` names
|
|
30
|
+
* wayfinder's config schema, which every file wayfinder writes has.
|
|
34
31
|
*/
|
|
35
|
-
import {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
import { z } from 'zod';
|
|
33
|
+
import { type DataCommand } from '@osdlc/cli-tool/command';
|
|
34
|
+
import type { FlagSpec } from '@osdlc/cli-tool/define-cli';
|
|
35
|
+
import { type CommandEnvOptions } from './config-command.ts';
|
|
36
|
+
/** What a flag removes. */
|
|
37
|
+
export type StoreKey = 'cache' | 'trust' | 'config' | 'dev' | 'legacy';
|
|
38
|
+
/** `way clean`'s output. */
|
|
39
|
+
export declare const CleanOutputSchema: z.ZodObject<{
|
|
40
|
+
mode: z.ZodEnum<{
|
|
41
|
+
report: "report";
|
|
42
|
+
remove: "remove";
|
|
43
|
+
}>;
|
|
44
|
+
stores: z.ZodArray<z.ZodObject<{
|
|
45
|
+
key: z.ZodEnum<{
|
|
46
|
+
config: "config";
|
|
47
|
+
trust: "trust";
|
|
48
|
+
cache: "cache";
|
|
49
|
+
dev: "dev";
|
|
50
|
+
legacy: "legacy";
|
|
51
|
+
}>;
|
|
52
|
+
flag: z.ZodString;
|
|
53
|
+
what: z.ZodString;
|
|
54
|
+
path: z.ZodString;
|
|
55
|
+
bytes: z.ZodNullable<z.ZodNumber>;
|
|
56
|
+
removed: z.ZodBoolean;
|
|
57
|
+
envVar: z.ZodOptional<z.ZodString>;
|
|
58
|
+
}, z.core.$strip>>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
/** What {@link cleanCommand} takes, beside the app's global flags. */
|
|
61
|
+
export interface CleanCommandOptions extends CommandEnvOptions {
|
|
62
|
+
/** The platform the paths are for. Defaults to `process.platform`. */
|
|
63
|
+
platform?: string;
|
|
42
64
|
}
|
|
43
|
-
|
|
65
|
+
/**
|
|
66
|
+
* The `clean` command. Mount it as `clean: cleanCommand({ globals })`.
|
|
67
|
+
* A call with a flag that removes something is `cli-only`: the MCP and HTTP
|
|
68
|
+
* adapters refuse it. A bare `clean`, the report, is open to them.
|
|
69
|
+
*/
|
|
70
|
+
export declare function cleanCommand<G extends FlagSpec = Record<never, never>>(options?: CleanCommandOptions & {
|
|
71
|
+
globals?: G;
|
|
72
|
+
}): DataCommand;
|