@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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `^y`: a task's command line on the clipboard.
|
|
3
|
+
*/
|
|
4
|
+
/** One clipboard program and its arguments. */
|
|
5
|
+
export interface ClipboardCommand {
|
|
6
|
+
binary: string;
|
|
7
|
+
args: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The clipboard programs to try, in order: `pbcopy` on macOS; `wl-copy` under
|
|
11
|
+
* Wayland, then `xclip` and `xsel` elsewhere. None on Windows yet.
|
|
12
|
+
*/
|
|
13
|
+
export declare function clipboardCommands(platform: NodeJS.Platform, env: Record<string, string | undefined>): ClipboardCommand[];
|
|
14
|
+
/** How long a clipboard program may take before it is given up on. */
|
|
15
|
+
export declare const CLIPBOARD_TIMEOUT_MS = 2000;
|
|
16
|
+
/**
|
|
17
|
+
* Put `text` on the clipboard. True when a program took it.
|
|
18
|
+
*
|
|
19
|
+
* Async with a deadline, so the screen keeps answering keys. `xclip` and
|
|
20
|
+
* `wl-copy` fork a child that holds the selection and can keep the output
|
|
21
|
+
* pipes open; the async runner settles soon after the program itself exits
|
|
22
|
+
* and closes the pipes, and the child keeps the selection. stdin is closed
|
|
23
|
+
* once the text is written.
|
|
24
|
+
*/
|
|
25
|
+
export declare function writeClipboard(text: string, opts: {
|
|
26
|
+
cwd: string;
|
|
27
|
+
platform: NodeJS.Platform;
|
|
28
|
+
env: Record<string, string | undefined>;
|
|
29
|
+
}): Promise<boolean>;
|
package/dist/tui/copy.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `^y`: a task's command line on the clipboard.
|
|
3
|
+
*/
|
|
4
|
+
import { spawnRunnerAsync } from '@osdlc/command-seam';
|
|
5
|
+
/**
|
|
6
|
+
* The clipboard programs to try, in order: `pbcopy` on macOS; `wl-copy` under
|
|
7
|
+
* Wayland, then `xclip` and `xsel` elsewhere. None on Windows yet.
|
|
8
|
+
*/
|
|
9
|
+
export function clipboardCommands(platform, env) {
|
|
10
|
+
if (platform === 'darwin')
|
|
11
|
+
return [{ binary: 'pbcopy', args: [] }];
|
|
12
|
+
if (platform === 'win32')
|
|
13
|
+
return [];
|
|
14
|
+
const x11 = [
|
|
15
|
+
{ binary: 'xclip', args: ['-selection', 'clipboard'] },
|
|
16
|
+
{ binary: 'xsel', args: ['--clipboard', '--input'] },
|
|
17
|
+
];
|
|
18
|
+
return env['WAYLAND_DISPLAY'] ? [{ binary: 'wl-copy', args: [] }, ...x11] : x11;
|
|
19
|
+
}
|
|
20
|
+
/** How long a clipboard program may take before it is given up on. */
|
|
21
|
+
export const CLIPBOARD_TIMEOUT_MS = 2000;
|
|
22
|
+
/**
|
|
23
|
+
* Put `text` on the clipboard. True when a program took it.
|
|
24
|
+
*
|
|
25
|
+
* Async with a deadline, so the screen keeps answering keys. `xclip` and
|
|
26
|
+
* `wl-copy` fork a child that holds the selection and can keep the output
|
|
27
|
+
* pipes open; the async runner settles soon after the program itself exits
|
|
28
|
+
* and closes the pipes, and the child keeps the selection. stdin is closed
|
|
29
|
+
* once the text is written.
|
|
30
|
+
*/
|
|
31
|
+
export async function writeClipboard(text, opts) {
|
|
32
|
+
for (const command of clipboardCommands(opts.platform, opts.env)) {
|
|
33
|
+
const res = await spawnRunnerAsync(command.binary, { absolutePathOnly: true }).run(command.args, { cwd: opts.cwd, input: text, timeoutMs: CLIPBOARD_TIMEOUT_MS });
|
|
34
|
+
if (res.reason === 'spawn')
|
|
35
|
+
continue;
|
|
36
|
+
return res.exitCode === 0;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The terminal UI: browse every task in a repository, and run one. Enter
|
|
3
|
+
* runs the selected task in this shell and hands it the terminal.
|
|
4
|
+
*
|
|
5
|
+
* No TUI toolkit: raw mode, ANSI, and one frame string per read. A toolkit
|
|
6
|
+
* would weigh more than the code it saves, and this has to keep working from
|
|
7
|
+
* a checkout whose node_modules is what you are trying to repair.
|
|
8
|
+
*
|
|
9
|
+
* `./app.ts` holds the state, the frame and the keys over a host interface.
|
|
10
|
+
* This file is the real host: it controls the terminal through
|
|
11
|
+
* `process.stdout` and `process.stdin`, restores it on every way out, and
|
|
12
|
+
* hands it to a task.
|
|
13
|
+
*/
|
|
14
|
+
import type { Session } from '../core/session.ts';
|
|
15
|
+
export { createTui, refreshNote, SCOPES, type Tui, type TuiHost, type TuiState } from './app.ts';
|
|
16
|
+
export { clipboardCommands, writeClipboard } from './copy.ts';
|
|
17
|
+
export { splitKeys } from './keys-input.ts';
|
|
18
|
+
/** The signals that end the terminal UI, each with the shell's exit code, 128 + its number. */
|
|
19
|
+
export declare const QUIT_SIGNALS: readonly ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"];
|
|
20
|
+
/**
|
|
21
|
+
* Quit on SIGINT, SIGTERM, SIGHUP and SIGQUIT with 128 + the signal's
|
|
22
|
+
* number. Raw mode turns the terminal's Ctrl-C into a key, so these come
|
|
23
|
+
* from another process. `quit` stops the probe and restores the terminal.
|
|
24
|
+
* command-seam's forwarding, installed by the CLI, still kills the probe
|
|
25
|
+
* groups: with a listener here, it signals them and leaves the exit to this
|
|
26
|
+
* one. Returns a function that removes the listeners.
|
|
27
|
+
*/
|
|
28
|
+
export declare function installQuitHandlers(quit: (code: number) => void, target?: NodeJS.EventEmitter): () => void;
|
|
29
|
+
/**
|
|
30
|
+
* Take over the terminal and run the UI over `session`. Returns 2 without a
|
|
31
|
+
* TTY. Otherwise it never settles: every way out calls `process.exit`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function runTui(session: Session): Promise<number>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The terminal UI: browse every task in a repository, and run one. Enter
|
|
3
|
+
* runs the selected task in this shell and hands it the terminal.
|
|
4
|
+
*
|
|
5
|
+
* No TUI toolkit: raw mode, ANSI, and one frame string per read. A toolkit
|
|
6
|
+
* would weigh more than the code it saves, and this has to keep working from
|
|
7
|
+
* a checkout whose node_modules is what you are trying to repair.
|
|
8
|
+
*
|
|
9
|
+
* `./app.ts` holds the state, the frame and the keys over a host interface.
|
|
10
|
+
* This file is the real host: it controls the terminal through
|
|
11
|
+
* `process.stdout` and `process.stdin`, restores it on every way out, and
|
|
12
|
+
* hands it to a task.
|
|
13
|
+
*/
|
|
14
|
+
import { constants } from 'node:os';
|
|
15
|
+
import { BIN } from "../app.js";
|
|
16
|
+
import { handOff } from "../core/run.js";
|
|
17
|
+
import { flushViews } from "../core/saved-view.js";
|
|
18
|
+
import { createTui } from "./app.js";
|
|
19
|
+
import { writeClipboard } from "./copy.js";
|
|
20
|
+
import { stylesFor } from "./style.js";
|
|
21
|
+
export { createTui, refreshNote, SCOPES } from "./app.js";
|
|
22
|
+
export { clipboardCommands, writeClipboard } from "./copy.js";
|
|
23
|
+
export { splitKeys } from "./keys-input.js";
|
|
24
|
+
const ALT_ON = '\x1b[?1049h';
|
|
25
|
+
const ALT_OFF = '\x1b[?1049l';
|
|
26
|
+
const HIDE = '\x1b[?25l';
|
|
27
|
+
const SHOW = '\x1b[?25h';
|
|
28
|
+
/** The signals that end the terminal UI, each with the shell's exit code, 128 + its number. */
|
|
29
|
+
export const QUIT_SIGNALS = ['SIGINT', 'SIGTERM', 'SIGHUP', 'SIGQUIT'];
|
|
30
|
+
/**
|
|
31
|
+
* Quit on SIGINT, SIGTERM, SIGHUP and SIGQUIT with 128 + the signal's
|
|
32
|
+
* number. Raw mode turns the terminal's Ctrl-C into a key, so these come
|
|
33
|
+
* from another process. `quit` stops the probe and restores the terminal.
|
|
34
|
+
* command-seam's forwarding, installed by the CLI, still kills the probe
|
|
35
|
+
* groups: with a listener here, it signals them and leaves the exit to this
|
|
36
|
+
* one. Returns a function that removes the listeners.
|
|
37
|
+
*/
|
|
38
|
+
export function installQuitHandlers(quit, target = process) {
|
|
39
|
+
const listeners = QUIT_SIGNALS.map((signal) => {
|
|
40
|
+
const listener = () => quit(128 + constants.signals[signal]);
|
|
41
|
+
target.on(signal, listener);
|
|
42
|
+
return [signal, listener];
|
|
43
|
+
});
|
|
44
|
+
return () => {
|
|
45
|
+
for (const [signal, listener] of listeners)
|
|
46
|
+
target.off(signal, listener);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Take over the terminal and run the UI over `session`. Returns 2 without a
|
|
51
|
+
* TTY. Otherwise it never settles: every way out calls `process.exit`.
|
|
52
|
+
*/
|
|
53
|
+
export async function runTui(session) {
|
|
54
|
+
if (!process.stdin.isTTY) {
|
|
55
|
+
process.stderr.write(`${BIN}: the terminal UI needs a TTY; use "${BIN} serve" for the page, or "${BIN} list --json" for data.\n`);
|
|
56
|
+
return 2;
|
|
57
|
+
}
|
|
58
|
+
let restored = false;
|
|
59
|
+
let uninstall = () => { };
|
|
60
|
+
const host = {
|
|
61
|
+
write: (text) => void process.stdout.write(text),
|
|
62
|
+
columns: () => process.stdout.columns,
|
|
63
|
+
rows: () => process.stdout.rows,
|
|
64
|
+
platform: process.platform,
|
|
65
|
+
clipboard: (text) => writeClipboard(text, { cwd: session.root, platform: process.platform, env: process.env }),
|
|
66
|
+
release() {
|
|
67
|
+
if (restored)
|
|
68
|
+
return;
|
|
69
|
+
restored = true;
|
|
70
|
+
// The task, not this process, handles signals while it has the terminal.
|
|
71
|
+
uninstall();
|
|
72
|
+
process.stdin.removeAllListeners('data');
|
|
73
|
+
process.stdin.pause();
|
|
74
|
+
if (process.stdin.isTTY)
|
|
75
|
+
process.stdin.setRawMode(false);
|
|
76
|
+
process.stdout.write(SHOW + ALT_OFF);
|
|
77
|
+
},
|
|
78
|
+
handOff,
|
|
79
|
+
// A view write still in flight would be dropped by process.exit.
|
|
80
|
+
exit: (code) => void flushViews().finally(() => process.exit(code)),
|
|
81
|
+
};
|
|
82
|
+
const tui = createTui({
|
|
83
|
+
session,
|
|
84
|
+
host,
|
|
85
|
+
styles: stylesFor(process.env, process.stdout.isTTY === true),
|
|
86
|
+
});
|
|
87
|
+
process.stdout.write(ALT_ON + HIDE);
|
|
88
|
+
process.stdin.setRawMode(true);
|
|
89
|
+
process.stdin.resume();
|
|
90
|
+
process.stdin.setEncoding('utf8');
|
|
91
|
+
process.on('exit', () => host.release());
|
|
92
|
+
uninstall = installQuitHandlers((code) => tui.quit(code));
|
|
93
|
+
process.stdout.on('resize', () => tui.draw());
|
|
94
|
+
process.stdin.on('data', (chunk) => tui.feed(chunk));
|
|
95
|
+
await tui.boot();
|
|
96
|
+
return new Promise(() => { });
|
|
97
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning what the terminal sends into keys.
|
|
3
|
+
*
|
|
4
|
+
* One read can hold several keys: a paste, a fast key repeat, or an arrow
|
|
5
|
+
* followed by typed text. Each escape sequence is one key, and every other
|
|
6
|
+
* character is a key of its own.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Split one read from a raw-mode terminal into keys.
|
|
10
|
+
*
|
|
11
|
+
* - `ESC [` then parameter bytes, then a final byte from `@` to `~`, is one key
|
|
12
|
+
* (`ESC [ A`, `ESC [ 1 ; 2 A`, `ESC [ 5 ~`).
|
|
13
|
+
* - `ESC O` and one more character is one key (`ESC O H` from some terminals).
|
|
14
|
+
* - `ESC` followed by another character is that character with Alt, one key.
|
|
15
|
+
* - `ESC` at the end of the read, or before another `ESC`, is the Escape key.
|
|
16
|
+
* - Anything else is one key per code point, so a paste becomes typed text.
|
|
17
|
+
*
|
|
18
|
+
* A sequence cut off at the end of the read is passed on whole, so the rest
|
|
19
|
+
* of it is not typed into the query.
|
|
20
|
+
*/
|
|
21
|
+
export declare function splitKeys(chunk: string): string[];
|
|
22
|
+
/** The names the key handler matches on, for the keys that have several encodings. */
|
|
23
|
+
export type NamedKey = 'up' | 'down' | 'pageUp' | 'pageDown' | 'home' | 'end' | 'shiftTab';
|
|
24
|
+
/** The name of a key with several encodings, or undefined. */
|
|
25
|
+
export declare function namedKey(key: string): NamedKey | undefined;
|
|
26
|
+
/** Whether `key` is typed text: one printable character, not a control or a sequence. */
|
|
27
|
+
export declare function isText(key: string): boolean;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning what the terminal sends into keys.
|
|
3
|
+
*
|
|
4
|
+
* One read can hold several keys: a paste, a fast key repeat, or an arrow
|
|
5
|
+
* followed by typed text. Each escape sequence is one key, and every other
|
|
6
|
+
* character is a key of its own.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Split one read from a raw-mode terminal into keys.
|
|
10
|
+
*
|
|
11
|
+
* - `ESC [` then parameter bytes, then a final byte from `@` to `~`, is one key
|
|
12
|
+
* (`ESC [ A`, `ESC [ 1 ; 2 A`, `ESC [ 5 ~`).
|
|
13
|
+
* - `ESC O` and one more character is one key (`ESC O H` from some terminals).
|
|
14
|
+
* - `ESC` followed by another character is that character with Alt, one key.
|
|
15
|
+
* - `ESC` at the end of the read, or before another `ESC`, is the Escape key.
|
|
16
|
+
* - Anything else is one key per code point, so a paste becomes typed text.
|
|
17
|
+
*
|
|
18
|
+
* A sequence cut off at the end of the read is passed on whole, so the rest
|
|
19
|
+
* of it is not typed into the query.
|
|
20
|
+
*/
|
|
21
|
+
export function splitKeys(chunk) {
|
|
22
|
+
const keys = [];
|
|
23
|
+
let i = 0;
|
|
24
|
+
while (i < chunk.length) {
|
|
25
|
+
if (chunk[i] !== '\x1b') {
|
|
26
|
+
const ch = String.fromCodePoint(chunk.codePointAt(i));
|
|
27
|
+
keys.push(ch);
|
|
28
|
+
i += ch.length;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const next = chunk[i + 1];
|
|
32
|
+
if (next === undefined || next === '\x1b') {
|
|
33
|
+
keys.push('\x1b');
|
|
34
|
+
i += 1;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (next === '[') {
|
|
38
|
+
let j = i + 2;
|
|
39
|
+
// Parameter and intermediate bytes, 0x20-0x3f.
|
|
40
|
+
while (j < chunk.length && chunk.charCodeAt(j) >= 0x20 && chunk.charCodeAt(j) <= 0x3f)
|
|
41
|
+
j++;
|
|
42
|
+
const final = chunk.charCodeAt(j);
|
|
43
|
+
const end = final >= 0x40 && final <= 0x7e ? j + 1 : j;
|
|
44
|
+
keys.push(chunk.slice(i, end));
|
|
45
|
+
i = end;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (next === 'O') {
|
|
49
|
+
const end = Math.min(chunk.length, i + 3);
|
|
50
|
+
keys.push(chunk.slice(i, end));
|
|
51
|
+
i = end;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const alt = String.fromCodePoint(chunk.codePointAt(i + 1));
|
|
55
|
+
keys.push(`\x1b${alt}`);
|
|
56
|
+
i += 1 + alt.length;
|
|
57
|
+
}
|
|
58
|
+
return keys;
|
|
59
|
+
}
|
|
60
|
+
const NAMED = {
|
|
61
|
+
'\x1b[A': 'up',
|
|
62
|
+
'\x1bOA': 'up',
|
|
63
|
+
'\x1b[B': 'down',
|
|
64
|
+
'\x1bOB': 'down',
|
|
65
|
+
'\x1b[5~': 'pageUp',
|
|
66
|
+
'\x1b[6~': 'pageDown',
|
|
67
|
+
'\x1b[H': 'home',
|
|
68
|
+
'\x1bOH': 'home',
|
|
69
|
+
'\x1b[1~': 'home',
|
|
70
|
+
'\x1b[7~': 'home',
|
|
71
|
+
'\x1b[F': 'end',
|
|
72
|
+
'\x1bOF': 'end',
|
|
73
|
+
'\x1b[4~': 'end',
|
|
74
|
+
'\x1b[8~': 'end',
|
|
75
|
+
'\x1b[Z': 'shiftTab',
|
|
76
|
+
};
|
|
77
|
+
/** The name of a key with several encodings, or undefined. */
|
|
78
|
+
export function namedKey(key) {
|
|
79
|
+
return NAMED[key];
|
|
80
|
+
}
|
|
81
|
+
/** Whether `key` is typed text: one printable character, not a control or a sequence. */
|
|
82
|
+
export function isText(key) {
|
|
83
|
+
if (key.length === 0 || key.startsWith('\x1b'))
|
|
84
|
+
return false;
|
|
85
|
+
const code = key.codePointAt(0);
|
|
86
|
+
return code >= 0x20 && code !== 0x7f && !(code >= 0x80 && code <= 0x9f);
|
|
87
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settings screen: what it shows, and the edits its keys make.
|
|
3
|
+
*
|
|
4
|
+
* Values come from the session, which reads them as `way config` does, so
|
|
5
|
+
* the screen, `way config` and the web view show the same answer. Edits go
|
|
6
|
+
* through `session.saveSetting`, which picks the file with `settingLayer`,
|
|
7
|
+
* the rule the web view uses too.
|
|
8
|
+
*/
|
|
9
|
+
import type { RunnerReport } from '@osdlc/system-model/detect';
|
|
10
|
+
import type { ExecGate } from '@osdlc/trust-repo';
|
|
11
|
+
import { type Settings } from '../config.ts';
|
|
12
|
+
import { type Unknown } from '../core/unknowns.ts';
|
|
13
|
+
import type { ToolSummary } from '../tool-info.ts';
|
|
14
|
+
import { type WithheldReason } from '../vocabulary.ts';
|
|
15
|
+
/** A withheld runner, as the session's unknowns describe it. */
|
|
16
|
+
export type WithheldRunner = Extract<Unknown, {
|
|
17
|
+
kind: 'withheld';
|
|
18
|
+
}>;
|
|
19
|
+
/** A line the cursor can stop on, and what its keys change. */
|
|
20
|
+
export type SettingsItem = {
|
|
21
|
+
kind: 'runner';
|
|
22
|
+
runner: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'discovery';
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'path';
|
|
27
|
+
path: string;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'add-path';
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'trust';
|
|
32
|
+
}
|
|
33
|
+
/** A trust scope: a tool trusted on its own, or one a withheld runner needs. */
|
|
34
|
+
| {
|
|
35
|
+
kind: 'tool';
|
|
36
|
+
tool: string;
|
|
37
|
+
trusted: boolean;
|
|
38
|
+
};
|
|
39
|
+
/** One line of the screen. */
|
|
40
|
+
export interface SettingsLine {
|
|
41
|
+
text: string;
|
|
42
|
+
heading?: boolean | undefined;
|
|
43
|
+
/** Present on a line the cursor can stop on. */
|
|
44
|
+
item?: SettingsItem | undefined;
|
|
45
|
+
}
|
|
46
|
+
/** What the screen describes. */
|
|
47
|
+
export interface SettingsFacts {
|
|
48
|
+
settings: Settings;
|
|
49
|
+
/** The execution decision for this run. */
|
|
50
|
+
gate: Pick<ExecGate, 'allowExec' | 'trusted' | 'reason'>;
|
|
51
|
+
/** Whether a trust grant would change this run. */
|
|
52
|
+
trustable: boolean;
|
|
53
|
+
/** The grant was removed in this run; execution stays as it was. */
|
|
54
|
+
revoked: boolean;
|
|
55
|
+
/** The catalog's reports, in display order. */
|
|
56
|
+
reports: readonly RunnerReport[];
|
|
57
|
+
/** Why withheld runners are withheld, or null when nothing is. */
|
|
58
|
+
withheld: WithheldReason | null;
|
|
59
|
+
/** Each withheld runner, with its label and the trust scopes it still needs. */
|
|
60
|
+
withheldRunners: readonly WithheldRunner[];
|
|
61
|
+
/** The registered tools, for a runner's language, description and homepage. */
|
|
62
|
+
tools: readonly ToolSummary[];
|
|
63
|
+
/** The tool ids trusted on their own here. */
|
|
64
|
+
trustedTools: readonly string[];
|
|
65
|
+
}
|
|
66
|
+
/** The runner ids in display order: collected ones, then disabled ones. */
|
|
67
|
+
export declare function knownRunners(facts: Pick<SettingsFacts, 'settings' | 'reports'>): string[];
|
|
68
|
+
/**
|
|
69
|
+
* What the settings screen says about a runner beyond on or off: its
|
|
70
|
+
* language when it has one, homepage and description, from its tool's
|
|
71
|
+
* summary. A custom tool's text is repository text, so it is filtered.
|
|
72
|
+
*/
|
|
73
|
+
export declare function toolNote(tools: readonly ToolSummary[], runner: string): string;
|
|
74
|
+
/** Why execution is off, in words, for the screen and the status line. */
|
|
75
|
+
export declare function execOffCause(settings: Settings, gate: Pick<ExecGate, 'reason'>): string;
|
|
76
|
+
/** The screen's lines. */
|
|
77
|
+
export declare function settingsLines(facts: SettingsFacts): SettingsLine[];
|
|
78
|
+
/** A write the screen makes: which key, and the new value. */
|
|
79
|
+
export interface SettingsEdit {
|
|
80
|
+
key: string;
|
|
81
|
+
value: unknown;
|
|
82
|
+
}
|
|
83
|
+
/** The edit that turns `runner` on or off. */
|
|
84
|
+
export declare function toggleRunner(settings: Settings, runner: string): SettingsEdit;
|
|
85
|
+
/** The edit that moves `runner` by `step` places in the display order, or null at an end. */
|
|
86
|
+
export declare function moveRunner(facts: Pick<SettingsFacts, 'settings' | 'reports'>, runner: string, step: -1 | 1): SettingsEdit | null;
|
|
87
|
+
/** The edit that moves discovery to its next value. */
|
|
88
|
+
export declare function cycleDiscovery(settings: Settings): SettingsEdit;
|
|
89
|
+
/** The edit that adds or removes an excluded path. Null when nothing would change. */
|
|
90
|
+
export declare function editPaths(settings: Settings, change: {
|
|
91
|
+
add: string;
|
|
92
|
+
} | {
|
|
93
|
+
remove: string;
|
|
94
|
+
}): SettingsEdit | null;
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settings screen: what it shows, and the edits its keys make.
|
|
3
|
+
*
|
|
4
|
+
* Values come from the session, which reads them as `way config` does, so
|
|
5
|
+
* the screen, `way config` and the web view show the same answer. Edits go
|
|
6
|
+
* through `session.saveSetting`, which picks the file with `settingLayer`,
|
|
7
|
+
* the rule the web view uses too.
|
|
8
|
+
*/
|
|
9
|
+
import { DISCOVERY_VALUES } from "../config.js";
|
|
10
|
+
import { execOffSource } from "../core/unknowns.js";
|
|
11
|
+
import { terminalSafe } from "../terminal-text.js";
|
|
12
|
+
import { execOffLabel, missingBinaryLabel, runnerLabel, withheldLabel, } from "../vocabulary.js";
|
|
13
|
+
const LAYER_WORDS = {
|
|
14
|
+
default: 'default',
|
|
15
|
+
user: 'your user config',
|
|
16
|
+
project: 'this project',
|
|
17
|
+
};
|
|
18
|
+
/** `this project`, `your user config` or `default`. */
|
|
19
|
+
function layerWords(layer) {
|
|
20
|
+
return LAYER_WORDS[layer];
|
|
21
|
+
}
|
|
22
|
+
function valueOf(settings, key) {
|
|
23
|
+
const found = settings.settings.find((s) => s.key === key);
|
|
24
|
+
return { value: found?.value, source: found?.source ?? 'default' };
|
|
25
|
+
}
|
|
26
|
+
/** The runner ids in display order: collected ones, then disabled ones. */
|
|
27
|
+
export function knownRunners(facts) {
|
|
28
|
+
const disabled = valueOf(facts.settings, 'runners.disabled').value ?? [];
|
|
29
|
+
const listed = facts.reports.map((r) => r.runner);
|
|
30
|
+
return [...listed, ...disabled.filter((d) => !listed.includes(d)).sort()];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What the settings screen says about a runner beyond on or off: its
|
|
34
|
+
* language when it has one, homepage and description, from its tool's
|
|
35
|
+
* summary. A custom tool's text is repository text, so it is filtered.
|
|
36
|
+
*/
|
|
37
|
+
export function toolNote(tools, runner) {
|
|
38
|
+
const tool = tools.find((t) => t.id === runner);
|
|
39
|
+
if (tool === undefined)
|
|
40
|
+
return '';
|
|
41
|
+
return terminalSafe([tool.ecosystem === null ? null : tool.language, tool.homepage, tool.description]
|
|
42
|
+
.filter((s) => s !== null && s !== '')
|
|
43
|
+
.join(' '));
|
|
44
|
+
}
|
|
45
|
+
/** Why execution is off, in words, for the screen and the status line. */
|
|
46
|
+
export function execOffCause(settings, gate) {
|
|
47
|
+
if (gate.reason === 'untrusted')
|
|
48
|
+
return 'this repository is not trusted';
|
|
49
|
+
return execOffLabel(execOffSource(settings));
|
|
50
|
+
}
|
|
51
|
+
/** The screen's lines. */
|
|
52
|
+
export function settingsLines(facts) {
|
|
53
|
+
const out = [];
|
|
54
|
+
const { settings } = facts;
|
|
55
|
+
const disabled = new Set(valueOf(settings, 'runners.disabled').value ?? []);
|
|
56
|
+
const disabledSource = valueOf(settings, 'runners.disabled').source;
|
|
57
|
+
const order = valueOf(settings, 'runners.order');
|
|
58
|
+
out.push({ text: `RUNNERS (on or off: ${layerWords(disabledSource)})`, heading: true });
|
|
59
|
+
const runners = knownRunners(facts);
|
|
60
|
+
if (runners.length === 0)
|
|
61
|
+
out.push({ text: ' no runners found' });
|
|
62
|
+
const pad = Math.max(0, ...runners.map((r) => runnerLabel(r).length));
|
|
63
|
+
for (const runner of runners) {
|
|
64
|
+
const report = facts.reports.find((r) => r.runner === runner);
|
|
65
|
+
const off = disabled.has(runner);
|
|
66
|
+
const held = facts.withheldRunners.find((w) => w.runner === runner);
|
|
67
|
+
const note = off
|
|
68
|
+
? 'not collected'
|
|
69
|
+
: report?.skippedForExec === true && facts.withheld !== null
|
|
70
|
+
? (held?.label ?? withheldLabel(facts.withheld))
|
|
71
|
+
: report?.tool !== undefined && !report.tool.found
|
|
72
|
+
? missingBinaryLabel(report.tool.binary)
|
|
73
|
+
: toolNote(facts.tools, runner);
|
|
74
|
+
out.push({
|
|
75
|
+
text: `${off ? 'off' : 'on '} ${runnerLabel(runner).padEnd(pad)} ${note}`.trimEnd(),
|
|
76
|
+
item: { kind: 'runner', runner },
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
out.push({
|
|
80
|
+
text: ` order: ${order.value === undefined || order.value.length === 0 ? 'alphabetical' : order.value.join(' ')} (${layerWords(order.source)})`,
|
|
81
|
+
});
|
|
82
|
+
out.push({ text: '' });
|
|
83
|
+
out.push({ text: 'EXECUTION', heading: true });
|
|
84
|
+
out.push({ text: trustText(facts), item: { kind: 'trust' } });
|
|
85
|
+
out.push({
|
|
86
|
+
text: ` this run: ${facts.gate.allowExec ? 'on' : `off — ${execOffCause(settings, facts.gate)}`}`,
|
|
87
|
+
});
|
|
88
|
+
const allowExec = valueOf(settings, 'allowExec');
|
|
89
|
+
out.push({
|
|
90
|
+
text: ` allowExec: ${String(allowExec.value === true)} (${layerWords(allowExec.source)})`,
|
|
91
|
+
});
|
|
92
|
+
out.push({ text: ' a project file can only turn execution off; trust is what turns it on' });
|
|
93
|
+
out.push({ text: '' });
|
|
94
|
+
out.push(...toolTrustLines(facts));
|
|
95
|
+
const discovery = valueOf(settings, 'discovery');
|
|
96
|
+
out.push({ text: `DISCOVERY (${layerWords(discovery.source)})`, heading: true });
|
|
97
|
+
out.push({ text: `${String(discovery.value)}`, item: { kind: 'discovery' } });
|
|
98
|
+
out.push({ text: '' });
|
|
99
|
+
const excluded = valueOf(settings, 'excludePaths');
|
|
100
|
+
out.push({ text: `EXCLUDED PATHS (${layerWords(excluded.source)})`, heading: true });
|
|
101
|
+
for (const path of excluded.value ?? [])
|
|
102
|
+
out.push({ text: path, item: { kind: 'path', path } });
|
|
103
|
+
out.push({ text: '+ add a path', item: { kind: 'add-path' } });
|
|
104
|
+
out.push({ text: '' });
|
|
105
|
+
out.push({ text: `project file: ${settings.loaded.locations.project}` });
|
|
106
|
+
out.push({ text: `user file: ${settings.loaded.locations.user}` });
|
|
107
|
+
for (const warning of settings.warnings)
|
|
108
|
+
out.push({ text: `warning: ${warning}` });
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The TOOL TRUST section: each tool trusted on its own, then each scope a
|
|
113
|
+
* withheld runner still needs. Empty when per-tool trust does not apply.
|
|
114
|
+
*/
|
|
115
|
+
function toolTrustLines(facts) {
|
|
116
|
+
const needed = new Map();
|
|
117
|
+
for (const w of facts.withheldRunners) {
|
|
118
|
+
for (const scope of w.missing ?? []) {
|
|
119
|
+
if (facts.trustedTools.includes(scope))
|
|
120
|
+
continue;
|
|
121
|
+
needed.set(scope, [...(needed.get(scope) ?? []), w.runner]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (facts.trustedTools.length === 0 && needed.size === 0)
|
|
125
|
+
return [];
|
|
126
|
+
const out = [{ text: 'TOOL TRUST (one tool at a time)', heading: true }];
|
|
127
|
+
const pad = Math.max(...[...facts.trustedTools, ...needed.keys()].map((t) => t.length));
|
|
128
|
+
for (const tool of facts.trustedTools) {
|
|
129
|
+
out.push({
|
|
130
|
+
text: `trusted ${tool.padEnd(pad)} (u removes)`,
|
|
131
|
+
item: { kind: 'tool', tool, trusted: true },
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
for (const [tool, runners] of needed) {
|
|
135
|
+
const by = runners.map(runnerLabel).join(', ');
|
|
136
|
+
out.push({
|
|
137
|
+
text: `not trusted ${tool.padEnd(pad)} needed by ${by}` +
|
|
138
|
+
(facts.trustable ? ' (t trusts it)' : ''),
|
|
139
|
+
item: { kind: 'tool', tool, trusted: false },
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
out.push({ text: '' });
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
function trustText(facts) {
|
|
146
|
+
if (facts.revoked)
|
|
147
|
+
return 'trust: removed; this run keeps its execution setting';
|
|
148
|
+
if (facts.gate.trusted)
|
|
149
|
+
return 'trust: trusted (u removes the grant)';
|
|
150
|
+
if (facts.trustable)
|
|
151
|
+
return 'trust: not trusted (t to trust)';
|
|
152
|
+
return 'trust: not trusted';
|
|
153
|
+
}
|
|
154
|
+
/** The edit that turns `runner` on or off. */
|
|
155
|
+
export function toggleRunner(settings, runner) {
|
|
156
|
+
const disabled = valueOf(settings, 'runners.disabled').value ?? [];
|
|
157
|
+
const value = disabled.includes(runner)
|
|
158
|
+
? disabled.filter((d) => d !== runner)
|
|
159
|
+
: [...disabled, runner];
|
|
160
|
+
return { key: 'runners.disabled', value };
|
|
161
|
+
}
|
|
162
|
+
/** The edit that moves `runner` by `step` places in the display order, or null at an end. */
|
|
163
|
+
export function moveRunner(facts, runner, step) {
|
|
164
|
+
const order = knownRunners(facts);
|
|
165
|
+
const at = order.indexOf(runner);
|
|
166
|
+
const to = at + step;
|
|
167
|
+
if (at === -1 || to < 0 || to >= order.length)
|
|
168
|
+
return null;
|
|
169
|
+
order.splice(at, 1);
|
|
170
|
+
order.splice(to, 0, runner);
|
|
171
|
+
return { key: 'runners.order', value: order };
|
|
172
|
+
}
|
|
173
|
+
/** The edit that moves discovery to its next value. */
|
|
174
|
+
export function cycleDiscovery(settings) {
|
|
175
|
+
const now = valueOf(settings, 'discovery').value;
|
|
176
|
+
const at = DISCOVERY_VALUES.indexOf(now);
|
|
177
|
+
return {
|
|
178
|
+
key: 'discovery',
|
|
179
|
+
value: DISCOVERY_VALUES[(at + 1) % DISCOVERY_VALUES.length],
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/** The edit that adds or removes an excluded path. Null when nothing would change. */
|
|
183
|
+
export function editPaths(settings, change) {
|
|
184
|
+
const now = valueOf(settings, 'excludePaths').value ?? [];
|
|
185
|
+
let value;
|
|
186
|
+
if ('add' in change) {
|
|
187
|
+
const path = change.add.trim();
|
|
188
|
+
if (path === '' || now.includes(path))
|
|
189
|
+
return null;
|
|
190
|
+
value = [...now, path];
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
if (!now.includes(change.remove))
|
|
194
|
+
return null;
|
|
195
|
+
value = now.filter((p) => p !== change.remove);
|
|
196
|
+
}
|
|
197
|
+
return { key: 'excludePaths', value };
|
|
198
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the terminal UI paints text, and how it fits a line to the width.
|
|
3
|
+
*
|
|
4
|
+
* Colors come from `@osdlc/ux` tokens. Text attributes (bold, dim, underline,
|
|
5
|
+
* inverse) are kept apart from color: `NO_COLOR` turns color off, not
|
|
6
|
+
* emphasis, so the selected row and a match stay visible. A state is never
|
|
7
|
+
* shown by color alone; each one also has a text mark (`>`, `[ ]`, `~`, `*`).
|
|
8
|
+
*/
|
|
9
|
+
import { type ColorLevel, type Theme } from '@osdlc/ux';
|
|
10
|
+
/** Paints a string. Plain text in, text with escapes out. */
|
|
11
|
+
export type Paint = (text: string) => string;
|
|
12
|
+
/** The paints the terminal UI uses, by meaning rather than by color. */
|
|
13
|
+
export interface Styles {
|
|
14
|
+
/** Secondary text: chains above the leaf, counts, hints. */
|
|
15
|
+
dim: Paint;
|
|
16
|
+
bold: Paint;
|
|
17
|
+
/** The prompt, the cursor and the selection mark. */
|
|
18
|
+
accent: Paint;
|
|
19
|
+
/** The service mark. */
|
|
20
|
+
success: Paint;
|
|
21
|
+
/** Warnings only: withheld runners, stale rows, a question waiting. */
|
|
22
|
+
warning: Paint;
|
|
23
|
+
error: Paint;
|
|
24
|
+
/** The selected tab. */
|
|
25
|
+
selected: Paint;
|
|
26
|
+
/** Matched characters: bold and underlined, so they show without color. */
|
|
27
|
+
match: Paint;
|
|
28
|
+
/** A note that is not a warning: `copied`, `refreshing`. */
|
|
29
|
+
note: Paint;
|
|
30
|
+
}
|
|
31
|
+
/** What decides the styles: the color level, the terminal's theme, and whether attributes show. */
|
|
32
|
+
export interface StyleInput {
|
|
33
|
+
level: ColorLevel;
|
|
34
|
+
theme: Theme;
|
|
35
|
+
/** Bold, dim, underline and inverse. Off when the output is not a terminal. */
|
|
36
|
+
attributes: boolean;
|
|
37
|
+
}
|
|
38
|
+
/** The styles for `input`. */
|
|
39
|
+
export declare function makeStyles(input: StyleInput): Styles;
|
|
40
|
+
/**
|
|
41
|
+
* The terminal's background, from `COLORFGBG` (`15;0` is light text on a
|
|
42
|
+
* dark ground). Dark when it says nothing.
|
|
43
|
+
*/
|
|
44
|
+
export declare function terminalTheme(env: Record<string, string | undefined>): Theme;
|
|
45
|
+
/** The styles for a stream with this environment and TTY state. */
|
|
46
|
+
export declare function stylesFor(env: Record<string, string | undefined>, isTTY: boolean): Styles;
|
|
47
|
+
/** A run of text plus how to paint it. Its width is measured before painting. */
|
|
48
|
+
export interface Chunk {
|
|
49
|
+
text: string;
|
|
50
|
+
paint?: Paint | undefined;
|
|
51
|
+
}
|
|
52
|
+
/** Clear to the end of the line. */
|
|
53
|
+
export declare const CLEAR_EOL = "\u001B[K";
|
|
54
|
+
/** The columns `chunks` take, after {@link terminalSafe}. */
|
|
55
|
+
export declare function chunksWidth(chunks: readonly Chunk[]): number;
|
|
56
|
+
/**
|
|
57
|
+
* Compose chunks into one line of at most `width` columns. The text is cut
|
|
58
|
+
* before it is painted, since an escape sequence has no width. Every chunk
|
|
59
|
+
* goes through {@link terminalSafe} first, so repository text never writes a
|
|
60
|
+
* control sequence; only `paint` adds escapes.
|
|
61
|
+
*/
|
|
62
|
+
export declare function line(chunks: readonly Chunk[], width: number): string;
|