@osdlc/wayfinder 0.0.0-stage → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +231 -0
- package/CONTRIBUTING.md +62 -0
- package/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +507 -2
- package/SECURITY.md +44 -0
- package/bin/way.js +18 -0
- package/dist/app.d.ts +24 -0
- package/dist/app.js +24 -0
- package/dist/args.d.ts +44 -0
- package/dist/args.js +93 -0
- package/dist/cache.d.ts +7 -0
- package/dist/cache.js +15 -0
- package/dist/catalog.d.ts +38 -0
- package/dist/catalog.js +61 -0
- package/dist/clean-command.d.ts +43 -0
- package/dist/clean-command.js +274 -0
- package/dist/cli.d.ts +76 -0
- package/dist/cli.js +612 -0
- package/dist/config-command.d.ts +52 -0
- package/dist/config-command.js +342 -0
- package/dist/config.d.ts +367 -0
- package/dist/config.js +700 -0
- package/dist/devlink.d.ts +14 -0
- package/dist/devlink.js +30 -0
- package/dist/groups.d.ts +34 -0
- package/dist/groups.js +38 -0
- package/dist/guide.d.ts +32 -0
- package/dist/guide.js +411 -0
- package/dist/http.d.ts +22 -0
- package/dist/http.js +149 -0
- package/dist/origin-owner.d.ts +14 -0
- package/dist/origin-owner.js +69 -0
- package/dist/page.d.ts +15 -0
- package/dist/page.js +58 -0
- package/dist/providers-command.d.ts +40 -0
- package/dist/providers-command.js +132 -0
- package/dist/serve.d.ts +97 -0
- package/dist/serve.js +678 -0
- package/dist/tools.d.ts +46 -0
- package/dist/tools.js +102 -0
- package/dist/trust-command.d.ts +33 -0
- package/dist/trust-command.js +221 -0
- package/dist/trust-store.d.ts +18 -0
- package/dist/trust-store.js +46 -0
- package/dist/tui.d.ts +178 -0
- package/dist/tui.js +846 -0
- package/dist/web/main.js +2315 -0
- package/dist/web/page.html +110 -0
- package/dist/web/styles.css +1514 -0
- package/dist/xdg.d.ts +10 -0
- package/dist/xdg.js +17 -0
- package/package.json +72 -3
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The devlink spec: what `@osdlc/cli-tool/devlink` needs to recognise a
|
|
3
|
+
* wayfinder checkout, run it, and put `way` on PATH.
|
|
4
|
+
*
|
|
5
|
+
* The marker is the source entry, which only a checkout has: the installed
|
|
6
|
+
* package ships `dist/` alone. A selected checkout runs its source under Bun.
|
|
7
|
+
*/
|
|
8
|
+
import { type ToolSpec } from '@osdlc/cli-tool/devlink';
|
|
9
|
+
export declare const WAYFINDER_SPEC: ToolSpec;
|
|
10
|
+
/**
|
|
11
|
+
* The checkout this module runs from, or null for an installed package.
|
|
12
|
+
* `src/` and `dist/` are both one level below the package root.
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkoutRoot(): string | null;
|
package/dist/devlink.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The devlink spec: what `@osdlc/cli-tool/devlink` needs to recognise a
|
|
3
|
+
* wayfinder checkout, run it, and put `way` on PATH.
|
|
4
|
+
*
|
|
5
|
+
* The marker is the source entry, which only a checkout has: the installed
|
|
6
|
+
* package ships `dist/` alone. A selected checkout runs its source under Bun.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync } from 'node:fs';
|
|
9
|
+
import { resolve } from 'node:path';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { envVars } from '@osdlc/cli-tool';
|
|
12
|
+
import { validateSpec } from '@osdlc/cli-tool/devlink';
|
|
13
|
+
import { APP, BIN } from "./app.js";
|
|
14
|
+
const MARKER = 'src/cli.ts';
|
|
15
|
+
export const WAYFINDER_SPEC = validateSpec({
|
|
16
|
+
name: BIN,
|
|
17
|
+
marker: MARKER,
|
|
18
|
+
entry: MARKER,
|
|
19
|
+
launcher: 'bin/way.js',
|
|
20
|
+
aliases: [APP],
|
|
21
|
+
vendorDirs: { vendor: APP, envVars: envVars(BIN.toUpperCase()) },
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* The checkout this module runs from, or null for an installed package.
|
|
25
|
+
* `src/` and `dist/` are both one level below the package root.
|
|
26
|
+
*/
|
|
27
|
+
export function checkoutRoot() {
|
|
28
|
+
const root = resolve(fileURLToPath(import.meta.url), '..', '..');
|
|
29
|
+
return existsSync(resolve(root, MARKER)) ? root : null;
|
|
30
|
+
}
|
package/dist/groups.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The row groups every surface shows: tasks from runners, then the actions
|
|
3
|
+
* system-model synthesizes from package managers, tool managers and hook
|
|
4
|
+
* managers. Each synthesized group is one runner id, so grouping is a
|
|
5
|
+
* property of the report. Browser-safe: the page imports it.
|
|
6
|
+
*/
|
|
7
|
+
/** A group's stable id, as `--json` prints it. */
|
|
8
|
+
export type GroupId = 'tasks' | 'dependencies' | 'tools' | 'hooks';
|
|
9
|
+
export interface Group {
|
|
10
|
+
id: GroupId;
|
|
11
|
+
title: string;
|
|
12
|
+
/** The synthesized runner that fills it; absent for tasks, which every other runner fills. */
|
|
13
|
+
runner?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* In display order. The runner ids are `SYNTHESIZED_RUNNERS` from
|
|
17
|
+
* `@osdlc/system-model/detect`, restated because that entry is not
|
|
18
|
+
* browser-safe; a test checks they agree.
|
|
19
|
+
*/
|
|
20
|
+
export declare const GROUPS: readonly Group[];
|
|
21
|
+
/** The group a runner's report belongs to. */
|
|
22
|
+
export declare function groupOf(runner: string): Group;
|
|
23
|
+
/** Position of a runner's group in {@link GROUPS}. */
|
|
24
|
+
export declare function groupRank(runner: string): number;
|
|
25
|
+
/** What a tab shows for a runner: the group's name for a synthesized group, else the runner id. */
|
|
26
|
+
export declare function runnerLabel(runner: string): string;
|
|
27
|
+
/** The groups that have at least one report, each with its runners in report order. */
|
|
28
|
+
export declare function catalogGroups(reports: readonly {
|
|
29
|
+
runner: string;
|
|
30
|
+
}[]): Array<{
|
|
31
|
+
id: GroupId;
|
|
32
|
+
title: string;
|
|
33
|
+
runners: string[];
|
|
34
|
+
}>;
|
package/dist/groups.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The row groups every surface shows: tasks from runners, then the actions
|
|
3
|
+
* system-model synthesizes from package managers, tool managers and hook
|
|
4
|
+
* managers. Each synthesized group is one runner id, so grouping is a
|
|
5
|
+
* property of the report. Browser-safe: the page imports it.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* In display order. The runner ids are `SYNTHESIZED_RUNNERS` from
|
|
9
|
+
* `@osdlc/system-model/detect`, restated because that entry is not
|
|
10
|
+
* browser-safe; a test checks they agree.
|
|
11
|
+
*/
|
|
12
|
+
export const GROUPS = [
|
|
13
|
+
{ id: 'tasks', title: 'Tasks' },
|
|
14
|
+
{ id: 'dependencies', title: 'Dependencies', runner: 'package-manager' },
|
|
15
|
+
{ id: 'tools', title: 'Tools', runner: 'tool-manager' },
|
|
16
|
+
{ id: 'hooks', title: 'Git hooks', runner: 'hook-manager' },
|
|
17
|
+
];
|
|
18
|
+
/** The group a runner's report belongs to. */
|
|
19
|
+
export function groupOf(runner) {
|
|
20
|
+
return GROUPS.find((g) => g.runner === runner) ?? GROUPS[0];
|
|
21
|
+
}
|
|
22
|
+
/** Position of a runner's group in {@link GROUPS}. */
|
|
23
|
+
export function groupRank(runner) {
|
|
24
|
+
return GROUPS.indexOf(groupOf(runner));
|
|
25
|
+
}
|
|
26
|
+
/** What a tab shows for a runner: the group's name for a synthesized group, else the runner id. */
|
|
27
|
+
export function runnerLabel(runner) {
|
|
28
|
+
const group = groupOf(runner);
|
|
29
|
+
return group.runner === runner ? group.title.toLowerCase() : runner;
|
|
30
|
+
}
|
|
31
|
+
/** The groups that have at least one report, each with its runners in report order. */
|
|
32
|
+
export function catalogGroups(reports) {
|
|
33
|
+
return GROUPS.map((g) => ({
|
|
34
|
+
id: g.id,
|
|
35
|
+
title: g.title,
|
|
36
|
+
runners: reports.filter((r) => groupOf(r.runner) === g).map((r) => r.runner),
|
|
37
|
+
})).filter((g) => g.runners.length > 0);
|
|
38
|
+
}
|
package/dist/guide.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `guide` subcommand: Markdown for a person or a model who has the binary
|
|
3
|
+
* and not the README. `--help` lists the flags; this says what `--json` hands
|
|
4
|
+
* you, why a runner is missing, and how to add a tool.
|
|
5
|
+
*
|
|
6
|
+
* Sections are data, so `tests/guide.test.ts` can check each one against the
|
|
7
|
+
* code it describes. No roster is retyped: the built-in tools come from
|
|
8
|
+
* `builtins` and the settable keys from `CONFIG_KEYS`.
|
|
9
|
+
*/
|
|
10
|
+
import { type CliIo } from '@osdlc/cli-tool';
|
|
11
|
+
/** One section of the guide. The document is these, in this order. */
|
|
12
|
+
export type GuideTopic = 'usage' | 'config' | 'json' | 'trust' | 'extend';
|
|
13
|
+
export declare const GUIDE_TOPICS: readonly GuideTopic[];
|
|
14
|
+
/**
|
|
15
|
+
* What the guide takes from the CLI. `usage` is the same string `--help --all`
|
|
16
|
+
* prints, so the guide's flag list and the help cannot drift.
|
|
17
|
+
*/
|
|
18
|
+
export interface GuideTool {
|
|
19
|
+
usage: string;
|
|
20
|
+
extraUsage?: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The tool example. `tests/guide-example.ts` holds the same code as a module
|
|
24
|
+
* the typechecker compiles, and `tests/guide.test.ts` checks the two match.
|
|
25
|
+
*/
|
|
26
|
+
export declare const EXTEND_EXAMPLE = "import type { ToolDef } from '@osdlc/system-model/detect'\n\nexport const tools: ToolDef[] = [\n {\n id: 'acme',\n binary: 'acme',\n markers: [{ files: '/acme.json', tier: 'files' }],\n roles: {\n runner: {\n kind: 'parse',\n chain: [{ label: 'task', hint: 'the acme task to run' }],\n async collect(ctx) {\n const config = (await ctx.readJson('acme.json')) as { tasks?: string[] } | null\n const tasks = (config?.tasks ?? []).map((name) => ({\n id: `acme:${name}`,\n runner: 'acme',\n path: ['acme', name],\n argv: ['acme', 'run', name],\n cwd: '.',\n display: `acme run ${name}`,\n parameters: [],\n source: 'acme.json',\n origin: 'declared' as const,\n tags: [],\n persistent: { value: false, declared: false },\n executes: 'local' as const,\n }))\n return { status: 'ok', tasks, diagnostics: [] }\n },\n },\n },\n },\n]\n";
|
|
27
|
+
/** One section. Always ends with a newline. */
|
|
28
|
+
export declare function guideSection(topic: GuideTopic, tool: GuideTool): string;
|
|
29
|
+
/** Every section, in {@link GUIDE_TOPICS} order, under one title. */
|
|
30
|
+
export declare function guideDocument(tool: GuideTool): string;
|
|
31
|
+
/** `way guide …`. Returns the exit code. */
|
|
32
|
+
export declare function runGuideCommand(tool: GuideTool, argv: string[], io: CliIo): number;
|
package/dist/guide.js
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `guide` subcommand: Markdown for a person or a model who has the binary
|
|
3
|
+
* and not the README. `--help` lists the flags; this says what `--json` hands
|
|
4
|
+
* you, why a runner is missing, and how to add a tool.
|
|
5
|
+
*
|
|
6
|
+
* Sections are data, so `tests/guide.test.ts` can check each one against the
|
|
7
|
+
* code it describes. No roster is retyped: the built-in tools come from
|
|
8
|
+
* `builtins` and the settable keys from `CONFIG_KEYS`.
|
|
9
|
+
*/
|
|
10
|
+
import { EXIT } from '@osdlc/cli-tool';
|
|
11
|
+
import { builtins } from '@osdlc/system-model/builtins';
|
|
12
|
+
import { APP, BIN, CONFIG_ENV_VAR, LEGACY_APP, LEGACY_CONFIG_ENV_VAR, LEGACY_PROJECT_CONFIG_FILENAME, PROJECT_CONFIG_FILENAME, } from "./app.js";
|
|
13
|
+
import { CONFIG_KEYS } from "./config.js";
|
|
14
|
+
import { GROUPS } from "./groups.js";
|
|
15
|
+
export const GUIDE_TOPICS = ['usage', 'config', 'json', 'trust', 'extend'];
|
|
16
|
+
function isGuideTopic(value) {
|
|
17
|
+
return GUIDE_TOPICS.includes(value);
|
|
18
|
+
}
|
|
19
|
+
const code = '```';
|
|
20
|
+
/** The built-in runner ids, as an inline list. */
|
|
21
|
+
function runnerRoster() {
|
|
22
|
+
return builtins
|
|
23
|
+
.filter((t) => t.roles.runner !== undefined)
|
|
24
|
+
.map((t) => `\`${t.id}\``)
|
|
25
|
+
.join(', ');
|
|
26
|
+
}
|
|
27
|
+
/** The built-in runners that must shell out to be read. */
|
|
28
|
+
function execRoster() {
|
|
29
|
+
const ids = builtins.filter((t) => t.roles.runner?.kind === 'exec').map((t) => `\`${t.id}\``);
|
|
30
|
+
return ids.length > 0 ? ids.join(', ') : '(none)';
|
|
31
|
+
}
|
|
32
|
+
function configKeyList() {
|
|
33
|
+
return CONFIG_KEYS.map((k) => `\`${k}\``).join(', ');
|
|
34
|
+
}
|
|
35
|
+
function groupList() {
|
|
36
|
+
return GROUPS.map((g) => `- \`${g.id}\`: ${g.title}${g.runner ? ` (runner \`${g.runner}\`)` : ''}`).join('\n');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The tool example. `tests/guide-example.ts` holds the same code as a module
|
|
40
|
+
* the typechecker compiles, and `tests/guide.test.ts` checks the two match.
|
|
41
|
+
*/
|
|
42
|
+
export const EXTEND_EXAMPLE = `import type { ToolDef } from '@osdlc/system-model/detect'
|
|
43
|
+
|
|
44
|
+
export const tools: ToolDef[] = [
|
|
45
|
+
{
|
|
46
|
+
id: 'acme',
|
|
47
|
+
binary: 'acme',
|
|
48
|
+
markers: [{ files: '/acme.json', tier: 'files' }],
|
|
49
|
+
roles: {
|
|
50
|
+
runner: {
|
|
51
|
+
kind: 'parse',
|
|
52
|
+
chain: [{ label: 'task', hint: 'the acme task to run' }],
|
|
53
|
+
async collect(ctx) {
|
|
54
|
+
const config = (await ctx.readJson('acme.json')) as { tasks?: string[] } | null
|
|
55
|
+
const tasks = (config?.tasks ?? []).map((name) => ({
|
|
56
|
+
id: \`acme:\${name}\`,
|
|
57
|
+
runner: 'acme',
|
|
58
|
+
path: ['acme', name],
|
|
59
|
+
argv: ['acme', 'run', name],
|
|
60
|
+
cwd: '.',
|
|
61
|
+
display: \`acme run \${name}\`,
|
|
62
|
+
parameters: [],
|
|
63
|
+
source: 'acme.json',
|
|
64
|
+
origin: 'declared' as const,
|
|
65
|
+
tags: [],
|
|
66
|
+
persistent: { value: false, declared: false },
|
|
67
|
+
executes: 'local' as const,
|
|
68
|
+
}))
|
|
69
|
+
return { status: 'ok', tasks, diagnostics: [] }
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
]
|
|
75
|
+
`;
|
|
76
|
+
const JSON_EXAMPLE = `{
|
|
77
|
+
"root": "/home/you/repo",
|
|
78
|
+
"generatedAt": "2026-01-01T00:00:00.000Z",
|
|
79
|
+
"discovery": "git",
|
|
80
|
+
"allowExec": false,
|
|
81
|
+
"reports": [
|
|
82
|
+
{
|
|
83
|
+
"runner": "just",
|
|
84
|
+
"status": "ok",
|
|
85
|
+
"chain": [{ "label": "recipe", "hint": "the recipe to run" }],
|
|
86
|
+
"tasks": [
|
|
87
|
+
{
|
|
88
|
+
"id": "just:justfile:build",
|
|
89
|
+
"runner": "just",
|
|
90
|
+
"path": ["just", ".", "build"],
|
|
91
|
+
"argv": ["just", "build"],
|
|
92
|
+
"cwd": ".",
|
|
93
|
+
"display": "just build <target>",
|
|
94
|
+
"parameters": [{ "name": "target", "required": true, "variadic": false }],
|
|
95
|
+
"source": "justfile",
|
|
96
|
+
"origin": "declared",
|
|
97
|
+
"doc": "build one crate",
|
|
98
|
+
"tags": [],
|
|
99
|
+
"persistent": { "value": false, "declared": false },
|
|
100
|
+
"executes": "local"
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"diagnostics": [],
|
|
104
|
+
"tool": { "binary": "just", "found": true, "path": "/usr/bin/just" },
|
|
105
|
+
"skippedForExec": false
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"groups": [{ "id": "tasks", "title": "Tasks", "runners": ["just"] }]
|
|
109
|
+
}`;
|
|
110
|
+
function usageSection(tool) {
|
|
111
|
+
const extra = tool.extraUsage === undefined ? '' : `\n${tool.extraUsage.trim()}\n`;
|
|
112
|
+
return `## usage
|
|
113
|
+
|
|
114
|
+
\`${BIN}\` lists every task this repository can run, and runs one.
|
|
115
|
+
|
|
116
|
+
Point it at a directory; the directory is resolved upward to the project root,
|
|
117
|
+
so running from a subdirectory still inspects the whole repository.
|
|
118
|
+
|
|
119
|
+
${code}text
|
|
120
|
+
${tool.usage.trim()}
|
|
121
|
+
${code}
|
|
122
|
+
${extra}
|
|
123
|
+
Built-in runners: ${runnerRoster()}.
|
|
124
|
+
|
|
125
|
+
Rows come in groups. Tasks come from runners. Dependencies (installs and
|
|
126
|
+
frozen installs), Tools (\`mise install\`, \`mise trust\`, \`direnv allow\`) and
|
|
127
|
+
Git hooks (arming the hooks, and each hook as a task you can run by hand) are
|
|
128
|
+
synthesized from the package, tool and hook managers found. Every row is a
|
|
129
|
+
task, so search, run and arguments work the same for all of them.
|
|
130
|
+
|
|
131
|
+
Subcommands: \`config\` reads and writes the layered settings, \`trust\` records
|
|
132
|
+
that this repository may be read by running it, \`providers\` lists the
|
|
133
|
+
registered tools, \`clean\` removes the data ${APP} stores outside your
|
|
134
|
+
repositories, \`guide\` prints this document. Each takes \`--help\`. They are
|
|
135
|
+
claimed before the flag parse, so their own arguments are not read as this
|
|
136
|
+
tool's flags.
|
|
137
|
+
`;
|
|
138
|
+
}
|
|
139
|
+
function configSection() {
|
|
140
|
+
return `## config
|
|
141
|
+
|
|
142
|
+
Layers, lowest precedence first:
|
|
143
|
+
|
|
144
|
+
1. The built-in defaults, with \`allowExec: true\`: willing in principle,
|
|
145
|
+
still gated on trust.
|
|
146
|
+
2. The user file.
|
|
147
|
+
3. The project file.
|
|
148
|
+
4. Flags on this command line.
|
|
149
|
+
|
|
150
|
+
Files. The project file is \`${PROJECT_CONFIG_FILENAME}\` at the project root, the
|
|
151
|
+
root this tool resolved, not the working directory. The user file is
|
|
152
|
+
\`$XDG_CONFIG_HOME/${APP}/config.json\`, or \`~/.config/${APP}/config.json\` when
|
|
153
|
+
that variable is unset.
|
|
154
|
+
|
|
155
|
+
\`${CONFIG_ENV_VAR}\` replaces the USER file's location and nothing else. It does
|
|
156
|
+
not move the project file and it does not add a layer. A path in it may start
|
|
157
|
+
with a tilde, which is expanded, and a relative path resolves against the
|
|
158
|
+
project root rather than the working directory.
|
|
159
|
+
|
|
160
|
+
Old names. The tool was called ${LEGACY_APP} before its first release.
|
|
161
|
+
\`${LEGACY_CONFIG_ENV_VAR}\`, \`$XDG_CONFIG_HOME/${LEGACY_APP}/config.json\` and
|
|
162
|
+
\`${LEGACY_PROJECT_CONFIG_FILENAME}\` are still read when the new name is absent,
|
|
163
|
+
with a warning naming the new location.
|
|
164
|
+
|
|
165
|
+
Settable keys: ${configKeyList()}.
|
|
166
|
+
|
|
167
|
+
Merging. Objects merge key by key. An ARRAY answers "which ones" wholesale, so
|
|
168
|
+
a later layer replaces it rather than appending to it: \`--exclude\` REPLACES
|
|
169
|
+
\`runners.disabled\`, and \`--exclude-path\` replaces \`excludePaths\`.
|
|
170
|
+
|
|
171
|
+
\`runners.disabled\` turns a RUNNER off everywhere in this project.
|
|
172
|
+
\`excludePaths\` leaves every runner on and narrows WHERE they look, for a tree
|
|
173
|
+
that holds manifests nobody runs, such as a test-fixture repository. A bare
|
|
174
|
+
name matches any path segment; a value with a slash matches from the root and
|
|
175
|
+
takes the tree beneath it. Not glob syntax.
|
|
176
|
+
|
|
177
|
+
\`tools\` names modules that export more tools (see extend). A relative path
|
|
178
|
+
resolves against the file that names it.
|
|
179
|
+
|
|
180
|
+
Exit codes. 2 means the command cannot be run as typed: an unknown
|
|
181
|
+
subcommand, a wrong argument count, an unknown setting, a value of the wrong
|
|
182
|
+
type. 1 means a well-formed command failed against the state: a file that
|
|
183
|
+
will not parse, a key that is not set where you asked to unset it.
|
|
184
|
+
|
|
185
|
+
The project file cannot grant execution. It may LOWER \`allowExec\` to false,
|
|
186
|
+
never raise it, because it lives inside the repository being scanned. A
|
|
187
|
+
project file's \`allowExec: true\` and any trust block are dropped with a
|
|
188
|
+
warning. Its \`tools\` load only when the repository is trusted and execution
|
|
189
|
+
is allowed, since a tool module is code.
|
|
190
|
+
|
|
191
|
+
The effective gate: \`--no-exec\` forbids execution whatever is configured;
|
|
192
|
+
\`--exec\` allows it for that one run; with neither flag, execution needs a
|
|
193
|
+
configured \`allowExec\` of true and a trusted repository.
|
|
194
|
+
`;
|
|
195
|
+
}
|
|
196
|
+
function jsonSection() {
|
|
197
|
+
return `## json
|
|
198
|
+
|
|
199
|
+
\`--json\` prints the catalog as one JSON document. Field by field:
|
|
200
|
+
|
|
201
|
+
\`Catalog\`
|
|
202
|
+
- \`root\`: absolute path the collection ran against. Every \`cwd\` and
|
|
203
|
+
\`source\` below is relative to it.
|
|
204
|
+
- \`generatedAt\`: ISO timestamp of this collection.
|
|
205
|
+
- \`discovery\`: "git" or "walk", how file discovery resolved.
|
|
206
|
+
- \`allowExec\`: whether runners were permitted to run subprocesses.
|
|
207
|
+
- \`reports\`: one entry per runner, grouped, then in configured order.
|
|
208
|
+
- \`groups\`: the non-empty groups in display order, each
|
|
209
|
+
\`{ id, title, runners }\`. The ids:
|
|
210
|
+
|
|
211
|
+
${groupList()}
|
|
212
|
+
|
|
213
|
+
\`Task\`
|
|
214
|
+
- \`id\`: stable across a re-collect.
|
|
215
|
+
- \`runner\`: the owning runner's id.
|
|
216
|
+
- \`path\`: display and search chain, root first, with \`runner\` at index 0.
|
|
217
|
+
- \`argv\`: EXECUTABLE. Spawn it directly, never through a shell. It carries no
|
|
218
|
+
parameter placeholders. To add arguments, use the way the tool expects:
|
|
219
|
+
${BIN} puts them after \`--\` for npm, cargo, moon and the like.
|
|
220
|
+
- \`display\`: for showing and copying. It may carry \`<required>\`,
|
|
221
|
+
\`[optional]\` and \`*variadic\` markers, so it is NOT executable.
|
|
222
|
+
- \`cwd\`: directory the command expects, relative to the root ("." = root).
|
|
223
|
+
- \`parameters\`: each \`{ name, required, variadic, default? }\`.
|
|
224
|
+
- \`source\`: the file that declares the task.
|
|
225
|
+
- \`origin\`: "declared" means written in a file; "synthesized" means made from
|
|
226
|
+
a convention, such as \`cargo test\` for a crate or an install for a lockfile.
|
|
227
|
+
- \`doc\`, \`detail\`: a summary, and what the task executes when that differs
|
|
228
|
+
from \`display\`. Absent when the runner supplies none.
|
|
229
|
+
- \`tags\`: free-text facets for search and filtering.
|
|
230
|
+
- \`persistent\`: \`{ value, declared }\`. \`declared\` separates the runner
|
|
231
|
+
stating it from a guess from the task name.
|
|
232
|
+
- \`executes\`: "local", "remote" or "container".
|
|
233
|
+
|
|
234
|
+
\`RunnerReport\`
|
|
235
|
+
- \`runner\`, \`status\` ("absent", "ok" or "error"), \`tasks\`.
|
|
236
|
+
- \`chain\`: one \`{ label, hint }\` per position of \`Task.path\`.
|
|
237
|
+
- \`diagnostics\`: each \`{ severity, message, source? }\`.
|
|
238
|
+
- \`brand\`: optional icon and colour.
|
|
239
|
+
- \`tool\`: \`{ binary, found, path? }\`, from a PATH lookup. Absent when the
|
|
240
|
+
tool declares no binary.
|
|
241
|
+
- \`skippedForExec\`: true when the runner was withheld because it needed to
|
|
242
|
+
shell out.
|
|
243
|
+
|
|
244
|
+
\`cache\`: present only with \`--cached\`. One entry per runner:
|
|
245
|
+
- \`state\`: "fresh", "stale" (used, and out of date) or "miss" (nothing was
|
|
246
|
+
stored, so it was probed now).
|
|
247
|
+
- \`reason\`: "changed", "max-age" or "excludes", on a stale row only.
|
|
248
|
+
- \`ageMs\`: how old the stored answer is. Absent on a miss.
|
|
249
|
+
- \`estimateMs\`: the median re-probe cost measured in this repository, or null.
|
|
250
|
+
- \`slow\`: true when those measurements say this runner is slow here.
|
|
251
|
+
|
|
252
|
+
A cached \`generatedAt\` is the OLDEST contributing probe time.
|
|
253
|
+
|
|
254
|
+
Over HTTP, \`${BIN} --serve\` adds \`trustable\`, the server's own reading of
|
|
255
|
+
the gate it resolved.
|
|
256
|
+
|
|
257
|
+
Trimmed example:
|
|
258
|
+
|
|
259
|
+
${code}json
|
|
260
|
+
${JSON_EXAMPLE}
|
|
261
|
+
${code}
|
|
262
|
+
`;
|
|
263
|
+
}
|
|
264
|
+
function trustSection() {
|
|
265
|
+
return `## trust
|
|
266
|
+
|
|
267
|
+
Reading some runners means RUNNING them. Asking moon for its task graph
|
|
268
|
+
evaluates the repository's toolchain configuration, and asking mise for its
|
|
269
|
+
tasks can fire that repository's hooks. Pointing a tool at a repository you
|
|
270
|
+
did not write is code execution before you have run anything from the list.
|
|
271
|
+
|
|
272
|
+
Built-ins that must shell out: ${execRoster()}.
|
|
273
|
+
|
|
274
|
+
The store is \`$XDG_STATE_HOME/${APP}/trusted/\`, or
|
|
275
|
+
\`~/.local/state/${APP}/trusted/\` when that variable is unset: state, not
|
|
276
|
+
config, so consent does not travel in a dotfiles repository. One marker file
|
|
277
|
+
per trusted root. Grants in the old \`$XDG_STATE_HOME/${LEGACY_APP}/trusted/\`
|
|
278
|
+
store still count.
|
|
279
|
+
|
|
280
|
+
It is PATH-KEYED: the key is the absolute, symlink-resolved root, not a hash
|
|
281
|
+
of the contents. A repository you trusted that later pulls hostile changes
|
|
282
|
+
STAYS trusted, and \`${BIN} trust --untrust\` is the remedy. Hashing every
|
|
283
|
+
runner config would re-prompt on ordinary edits, which trains people to
|
|
284
|
+
approve without reading.
|
|
285
|
+
|
|
286
|
+
How the gate resolves:
|
|
287
|
+
|
|
288
|
+
${code}text
|
|
289
|
+
flag configured trusted effective allowExec reason
|
|
290
|
+
--no-exec any any false configured-off
|
|
291
|
+
--exec any any true allowed-by-flag
|
|
292
|
+
(none) false any false configured-off
|
|
293
|
+
(none) true false false untrusted
|
|
294
|
+
(none) true true true allowed
|
|
295
|
+
${code}
|
|
296
|
+
|
|
297
|
+
The exec flag grants execution for ONE run and records nothing.
|
|
298
|
+
|
|
299
|
+
The command: \`${BIN} trust\` grants, \`--untrust\` revokes, \`--show\` reports
|
|
300
|
+
this root, \`--list\` prints every trusted path. \`-C PATH\` reaches all of them.
|
|
301
|
+
|
|
302
|
+
A root can also be trusted with no marker, by a trust block in the USER
|
|
303
|
+
config: \`trust.paths\` (a glob over the resolved root) and \`trust.owners\`
|
|
304
|
+
(the \`origin\` remote's owner), decided in that order after the marker.
|
|
305
|
+
\`--show\` and \`--json\` name which layer decided (\`by\`:
|
|
306
|
+
\`marker\`/\`path\`/\`owner\`, plus the matching \`rule\` for a policy hit).
|
|
307
|
+
`;
|
|
308
|
+
}
|
|
309
|
+
function extendSection() {
|
|
310
|
+
return `## extend
|
|
311
|
+
|
|
312
|
+
A tool is a \`ToolDef\` from \`@osdlc/system-model/detect\`, the same shape as
|
|
313
|
+
the built-ins: an id, the binary, the files that show it is in use, and the
|
|
314
|
+
roles it plays. A tool with a \`runner\` role adds tasks.
|
|
315
|
+
|
|
316
|
+
Two rules for a runner.
|
|
317
|
+
|
|
318
|
+
1. It never spawns. \`ctx.runner(binary)\` hands back an injected runner.
|
|
319
|
+
2. It never reads the filesystem for discovery. \`ctx.files()\` applies the
|
|
320
|
+
caller's discovery, git-tracked or a directory walk.
|
|
321
|
+
|
|
322
|
+
\`kind\` is "parse" or "exec". This is a trust boundary: a parse runner reads
|
|
323
|
+
files; an exec runner runs the repository's code to be read, so it is
|
|
324
|
+
withheld until the repository is trusted.
|
|
325
|
+
|
|
326
|
+
The context gives \`root\`, \`files(pattern)\`, \`readJson(path)\`,
|
|
327
|
+
\`readText(path)\`, \`exists(path)\`, \`which(binary)\`, \`runner(binary)\`,
|
|
328
|
+
\`allowExec\`, \`discovery\` and \`signal\`.
|
|
329
|
+
|
|
330
|
+
A complete module:
|
|
331
|
+
|
|
332
|
+
${code}ts
|
|
333
|
+
${EXTEND_EXAMPLE.trim()}
|
|
334
|
+
${code}
|
|
335
|
+
|
|
336
|
+
Load it:
|
|
337
|
+
|
|
338
|
+
- for one run: \`${BIN} --config ./acme-tools.js\` (repeatable);
|
|
339
|
+
- always: \`${BIN} config set tools '["./acme-tools.js"]' --user\`;
|
|
340
|
+
- for one repository: \`tools\` in \`${PROJECT_CONFIG_FILENAME}\`, which loads only
|
|
341
|
+
when the repository is trusted and execution is allowed.
|
|
342
|
+
|
|
343
|
+
The module exports \`tools\`, an array, or a default that is an array or has
|
|
344
|
+
\`tools\`. Node loads it, so write JavaScript, or TypeScript on a Node that
|
|
345
|
+
strips types. A tool whose id matches a built-in is an error.
|
|
346
|
+
\`${BIN} providers\` lists every registered tool and where it came from.
|
|
347
|
+
`;
|
|
348
|
+
}
|
|
349
|
+
/** One section. Always ends with a newline. */
|
|
350
|
+
export function guideSection(topic, tool) {
|
|
351
|
+
switch (topic) {
|
|
352
|
+
case 'usage':
|
|
353
|
+
return usageSection(tool);
|
|
354
|
+
case 'config':
|
|
355
|
+
return configSection();
|
|
356
|
+
case 'json':
|
|
357
|
+
return jsonSection();
|
|
358
|
+
case 'trust':
|
|
359
|
+
return trustSection();
|
|
360
|
+
case 'extend':
|
|
361
|
+
return extendSection();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/** Every section, in {@link GUIDE_TOPICS} order, under one title. */
|
|
365
|
+
export function guideDocument(tool) {
|
|
366
|
+
const header = `# ${APP} guide
|
|
367
|
+
|
|
368
|
+
Instructions for using and extending this tool without the README. Topics:
|
|
369
|
+
${GUIDE_TOPICS.join(', ')}. Print one with \`${BIN} guide <topic>\`.
|
|
370
|
+
`;
|
|
371
|
+
return [header, ...GUIDE_TOPICS.map((t) => guideSection(t, tool))].join('\n');
|
|
372
|
+
}
|
|
373
|
+
/** `way guide --help`. Short on purpose: the document is the real help. */
|
|
374
|
+
function guideUsage() {
|
|
375
|
+
return `${BIN} guide — how to use and extend ${APP}, without the README
|
|
376
|
+
|
|
377
|
+
usage: ${BIN} guide [topic]
|
|
378
|
+
|
|
379
|
+
(no topic) the whole document
|
|
380
|
+
topics the topic names, one per line
|
|
381
|
+
<topic> one section: ${GUIDE_TOPICS.join(', ')}
|
|
382
|
+
-h, --help this text
|
|
383
|
+
`;
|
|
384
|
+
}
|
|
385
|
+
/** `way guide …`. Returns the exit code. */
|
|
386
|
+
export function runGuideCommand(tool, argv, io) {
|
|
387
|
+
if (argv.length === 0) {
|
|
388
|
+
io.stdout(guideDocument(tool));
|
|
389
|
+
return EXIT.ok;
|
|
390
|
+
}
|
|
391
|
+
const [first, ...rest] = argv;
|
|
392
|
+
if (first === '-h' || first === '--help') {
|
|
393
|
+
io.stdout(guideUsage());
|
|
394
|
+
return EXIT.ok;
|
|
395
|
+
}
|
|
396
|
+
const bad = (what) => {
|
|
397
|
+
io.stderr(`${APP}: guide: ${what} — topics are: ${GUIDE_TOPICS.join(', ')} (or "topics")\n`);
|
|
398
|
+
return EXIT.usage;
|
|
399
|
+
};
|
|
400
|
+
if (rest.length > 0)
|
|
401
|
+
return bad('expected at most one topic');
|
|
402
|
+
if (first === 'topics') {
|
|
403
|
+
io.stdout(`${GUIDE_TOPICS.join('\n')}\n`);
|
|
404
|
+
return EXIT.ok;
|
|
405
|
+
}
|
|
406
|
+
if (isGuideTopic(first)) {
|
|
407
|
+
io.stdout(guideSection(first, tool));
|
|
408
|
+
return EXIT.ok;
|
|
409
|
+
}
|
|
410
|
+
return bad(`unknown topic "${first}"`);
|
|
411
|
+
}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fetch-style server on `node:http`: the handler takes a web `Request` and
|
|
3
|
+
* returns a `Response`, and the body streams out chunk by chunk. Runs under
|
|
4
|
+
* Node and Bun.
|
|
5
|
+
*/
|
|
6
|
+
/** A running server. */
|
|
7
|
+
export interface FetchServer {
|
|
8
|
+
readonly port: number;
|
|
9
|
+
/** Stop accepting, let open responses finish, then resolve. */
|
|
10
|
+
stop(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export type FetchHandler = (req: Request, server: FetchServer) => Response | Promise<Response>;
|
|
13
|
+
export interface ServeFetchOptions {
|
|
14
|
+
hostname: string;
|
|
15
|
+
/** 0 lets the OS pick. */
|
|
16
|
+
port: number;
|
|
17
|
+
fetch: FetchHandler;
|
|
18
|
+
}
|
|
19
|
+
/** The largest request body read; every route takes a small JSON body. */
|
|
20
|
+
export declare const MAX_BODY_BYTES: number;
|
|
21
|
+
/** Bind `hostname:port` and answer every request with `fetch`. */
|
|
22
|
+
export declare function serveFetch(options: ServeFetchOptions): Promise<FetchServer>;
|