@osdlc/wayfinder 0.7.3 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +221 -0
- package/CONTRIBUTING.md +6 -0
- package/README.md +295 -150
- package/SECURITY.md +19 -5
- package/dist/actions.d.ts +23 -0
- package/dist/actions.js +97 -0
- package/dist/app.d.ts +1 -13
- package/dist/app.js +1 -13
- package/dist/args.d.ts +11 -6
- package/dist/args.js +25 -7
- package/dist/cache.d.ts +2 -4
- package/dist/cache.js +5 -10
- package/dist/catalog.d.ts +30 -3
- package/dist/catalog.js +87 -11
- package/dist/clean-command.d.ts +65 -36
- package/dist/clean-command.js +372 -226
- package/dist/cli.d.ts +24 -57
- package/dist/cli.js +139 -568
- package/dist/commands/browse.d.ts +128 -0
- package/dist/commands/browse.js +151 -0
- package/dist/commands/index.d.ts +25 -0
- package/dist/commands/index.js +71 -0
- package/dist/commands/list.d.ts +208 -0
- package/dist/commands/list.js +127 -0
- package/dist/commands/query.d.ts +166 -0
- package/dist/commands/query.js +73 -0
- package/dist/commands/run.d.ts +114 -0
- package/dist/commands/run.js +139 -0
- package/dist/commands/shared.d.ts +152 -0
- package/dist/commands/shared.js +209 -0
- package/dist/config-command.d.ts +27 -43
- package/dist/config-command.js +129 -330
- package/dist/config-keys.d.ts +25 -0
- package/dist/config-keys.js +29 -0
- package/dist/config.d.ts +271 -257
- package/dist/config.js +610 -460
- package/dist/core/copy-text.d.ts +30 -0
- package/dist/core/copy-text.js +50 -0
- package/dist/core/filter.d.ts +55 -0
- package/dist/core/filter.js +59 -0
- package/dist/core/run.d.ts +22 -0
- package/dist/core/run.js +59 -0
- package/dist/core/saved-view.d.ts +59 -0
- package/dist/core/saved-view.js +119 -0
- package/dist/core/session.d.ts +262 -0
- package/dist/core/session.js +589 -0
- package/dist/core/skills.d.ts +53 -0
- package/dist/core/skills.js +54 -0
- package/dist/core/unknowns.d.ts +72 -0
- package/dist/core/unknowns.js +68 -0
- package/dist/devlink.d.ts +3 -0
- package/dist/devlink.js +5 -2
- package/dist/document-schemas.generated.d.ts +22 -0
- package/dist/document-schemas.generated.js +916 -0
- package/dist/documents.d.ts +432 -0
- package/dist/documents.js +163 -0
- package/dist/groups.d.ts +22 -26
- package/dist/groups.js +13 -29
- package/dist/guide.d.ts +26 -13
- package/dist/guide.js +119 -103
- package/dist/index.d.ts +112 -0
- package/dist/index.js +58 -0
- package/dist/keys.d.ts +51 -0
- package/dist/keys.js +273 -0
- package/dist/page.d.ts +18 -8
- package/dist/page.js +28 -17
- package/dist/providers-command.d.ts +81 -20
- package/dist/providers-command.js +33 -75
- package/dist/schema.d.ts +48 -0
- package/dist/schema.js +61 -0
- package/dist/serve/auth.d.ts +46 -0
- package/dist/serve/auth.js +82 -0
- package/dist/serve/catalog-share.d.ts +51 -0
- package/dist/serve/catalog-share.js +116 -0
- package/dist/serve/index.d.ts +98 -0
- package/dist/serve/index.js +251 -0
- package/dist/serve/routes.d.ts +60 -0
- package/dist/serve/routes.js +186 -0
- package/dist/serve/terminal-input.d.ts +50 -0
- package/dist/serve/terminal-input.js +108 -0
- package/dist/skills.d.ts +19 -0
- package/dist/skills.js +54 -0
- package/dist/terminal-text.d.ts +8 -0
- package/dist/terminal-text.js +19 -6
- package/dist/tool-info.d.ts +24 -0
- package/dist/tool-info.js +17 -0
- package/dist/trust-command.d.ts +15 -27
- package/dist/trust-command.js +110 -208
- package/dist/trust-store.d.ts +5 -10
- package/dist/trust-store.js +9 -42
- package/dist/tui/app.d.ts +180 -0
- package/dist/tui/app.js +1278 -0
- package/dist/tui/copy.d.ts +29 -0
- package/dist/tui/copy.js +39 -0
- package/dist/tui/index.d.ts +33 -0
- package/dist/tui/index.js +97 -0
- package/dist/tui/keys-input.d.ts +27 -0
- package/dist/tui/keys-input.js +87 -0
- package/dist/tui/settings.d.ts +94 -0
- package/dist/tui/settings.js +198 -0
- package/dist/tui/style.d.ts +62 -0
- package/dist/tui/style.js +77 -0
- package/dist/version.d.ts +6 -0
- package/dist/version.js +7 -0
- package/dist/vocabulary.d.ts +89 -0
- package/dist/vocabulary.js +153 -0
- package/dist/web/main.js +1965 -568
- package/dist/web/page.html +39 -33
- package/dist/web/styles.css +457 -329
- package/dist/xdg.d.ts +76 -4
- package/dist/xdg.js +77 -5
- package/package.json +28 -9
- package/schema/config.json +133 -0
- package/dist/http.d.ts +0 -22
- package/dist/http.js +0 -149
- package/dist/origin-owner.d.ts +0 -19
- package/dist/origin-owner.js +0 -85
- package/dist/serve.d.ts +0 -98
- package/dist/serve.js +0 -671
- package/dist/tui.d.ts +0 -177
- package/dist/tui.js +0 -840
package/dist/config-command.js
CHANGED
|
@@ -1,346 +1,145 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* `way config`: cli-tool's shared `config` group over wayfinder's files.
|
|
3
|
+
* {@link configStore} is the {@link ConfigStore} it runs on; this module also
|
|
4
|
+
* holds what every wayfinder command needs from its context (the home
|
|
5
|
+
* directory and the project root).
|
|
6
|
+
*
|
|
7
|
+
* `trust`, `allowExec` and `tools` are written from the command line only
|
|
8
|
+
* ({@link CLI_ONLY_KEYS}): the web view's server refuses them.
|
|
5
9
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { EXIT } from '@osdlc/cli-tool';
|
|
10
|
+
import { stat } from 'node:fs/promises';
|
|
11
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
12
|
+
import { CommandError, UsageError } from '@osdlc/cli-tool/command';
|
|
13
|
+
import { ConfigUsageError, configCommands, } from '@osdlc/cli-tool/config-command';
|
|
11
14
|
import { homeDir } from '@osdlc/trust-repo';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
get <key> one setting's effective value, as JSON
|
|
19
|
-
set <key> <value> [--user|--project] write a setting (default --project)
|
|
20
|
-
unset <key> [--user|--project] remove a setting (default --project)
|
|
21
|
-
path where each layer's file lives
|
|
22
|
-
-h, --help this text
|
|
23
|
-
|
|
24
|
-
Keys are dotted: runners.disabled, runners.order, allowExec, discovery,
|
|
25
|
-
excludePaths, trust.paths, trust.owners, tools.
|
|
26
|
-
|
|
27
|
-
A value is read as JSON, falling back to the bare string when that fails — so
|
|
28
|
-
\`set discovery git\` and \`set runners.order '["moon","just"]'\` both work, and a
|
|
29
|
-
plain word needs no quoting.
|
|
30
|
-
|
|
31
|
-
Layers, lowest precedence first: built-in defaults, the user file, the project
|
|
32
|
-
file, then this tool's own flags. ${CONFIG_ENV_VAR} replaces the user file's
|
|
33
|
-
location and nothing else.
|
|
34
|
-
`;
|
|
15
|
+
import { projectRootFor } from "./catalog.js";
|
|
16
|
+
import { CLI_ONLY_KEYS, CONFIG_KEYS, ConfigError, DEFAULT_CONFIG, configLocations, envIgnoredWarning, getConfigValue, loadConfig, projectIgnoreReason, readSettings, removeSetting, resolveConfigKey, writeSetting, } from "./config.js";
|
|
17
|
+
/** The home directory for `ctx`: an absolute `HOME`, else the OS account's home. */
|
|
18
|
+
function homeOf(ctx) {
|
|
19
|
+
const home = ctx.env['HOME'];
|
|
20
|
+
return home !== undefined && isAbsolute(home) ? home : homeDir();
|
|
35
21
|
}
|
|
36
22
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* still came from no file, so `(default)` is still the right label. Only the
|
|
41
|
-
* value next to that label changes.
|
|
23
|
+
* The project root for `ctx`: the directory `-C` names (`ctx.globals.dir`),
|
|
24
|
+
* else `ctx.cwd`, resolved upward to the project root. A directory that does
|
|
25
|
+
* not exist is an error, so a typo never edits the enclosing repository.
|
|
42
26
|
*/
|
|
43
|
-
async function
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
async function exists(file) {
|
|
52
|
-
try {
|
|
53
|
-
await access(file);
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
27
|
+
async function projectRootOf(ctx) {
|
|
28
|
+
const named = ctx.globals['dir'];
|
|
29
|
+
const dir = resolve(ctx.cwd, typeof named === 'string' && named !== '' ? named : '.');
|
|
30
|
+
const root = await projectRootFor(dir);
|
|
31
|
+
if (root === null)
|
|
32
|
+
throw new CommandError(`no such directory: ${dir}`);
|
|
33
|
+
return root;
|
|
59
34
|
}
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
return
|
|
35
|
+
/** {@link homeOf} and {@link projectRootOf}, or the caller's own. */
|
|
36
|
+
export function commandEnv(opts = {}) {
|
|
37
|
+
return { home: opts.home ?? homeOf, root: opts.root ?? projectRootOf };
|
|
63
38
|
}
|
|
64
|
-
|
|
65
|
-
|
|
39
|
+
/** A broken file, as the command's failure (exit 1). */
|
|
40
|
+
function asCommandError(err) {
|
|
41
|
+
if (err instanceof ConfigError)
|
|
42
|
+
throw new CommandError(err.message);
|
|
43
|
+
throw err;
|
|
66
44
|
}
|
|
67
45
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* The two name different files, and both callers write. If the last flag won,
|
|
71
|
-
* a typo could silently edit the wrong file. Giving both is a usage error.
|
|
46
|
+
* wayfinder's {@link ConfigStore}: the user and project files, with the
|
|
47
|
+
* project file the default for `set` and `unset`.
|
|
72
48
|
*/
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
49
|
+
function configStore(opts = {}) {
|
|
50
|
+
const env = commandEnv(opts);
|
|
51
|
+
const load = async (ctx) => loadConfig(await env.root(ctx), ctx.env, env.home(ctx)).catch(asCommandError);
|
|
52
|
+
const settings = async (ctx) => readSettings(await env.root(ctx), ctx.env, env.home(ctx)).catch(asCommandError);
|
|
53
|
+
const target = async (ctx, layer) => ({
|
|
54
|
+
layer: layer,
|
|
55
|
+
root: await env.root(ctx),
|
|
56
|
+
env: ctx.env,
|
|
57
|
+
home: env.home(ctx),
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
layers: ['user', 'project'],
|
|
61
|
+
defaultLayer: 'project',
|
|
62
|
+
keys: CONFIG_KEYS,
|
|
63
|
+
cliOnlyKeys: CLI_ONLY_KEYS,
|
|
64
|
+
resolveKey: resolveConfigKey,
|
|
65
|
+
async list(ctx) {
|
|
66
|
+
const read = await settings(ctx);
|
|
67
|
+
return {
|
|
68
|
+
settings: read.settings.map(({ key, value, source }) => ({ key, value, source })),
|
|
69
|
+
warnings: read.warnings,
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
// Existence only: `config path` is what you run when a file will not load.
|
|
73
|
+
async locations(ctx) {
|
|
74
|
+
const locations = configLocations(await env.root(ctx), ctx.env, env.home(ctx));
|
|
75
|
+
const ignored = envIgnoredWarning(locations);
|
|
76
|
+
if (ignored !== null)
|
|
77
|
+
ctx.warn(ignored);
|
|
78
|
+
const exists = async (file) => (await stat(file).catch(() => null)) !== null;
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
layer: 'user',
|
|
82
|
+
path: locations.user,
|
|
83
|
+
exists: await exists(locations.user),
|
|
84
|
+
envVar: locations.userEnvVar,
|
|
85
|
+
},
|
|
86
|
+
{ layer: 'project', path: locations.project, exists: await exists(locations.project) },
|
|
87
|
+
];
|
|
88
|
+
},
|
|
89
|
+
async set(ctx, layer, key, value) {
|
|
90
|
+
if (resolveConfigKey(key) === undefined)
|
|
91
|
+
throw new ConfigUsageError(`unknown setting: ${key}`);
|
|
92
|
+
try {
|
|
93
|
+
return await writeSetting(await target(ctx, layer), key, value);
|
|
81
94
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
else {
|
|
124
|
-
rest.push(arg);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return { ...(dir !== undefined ? { dir } : {}), rest };
|
|
95
|
+
catch (err) {
|
|
96
|
+
// An empty `file` is about what was typed: a wrong value, or a key
|
|
97
|
+
// the project file may not hold.
|
|
98
|
+
if (err instanceof ConfigError && err.file === '')
|
|
99
|
+
throw new UsageError(err.message);
|
|
100
|
+
return asCommandError(err);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
async unset(ctx, layer, key) {
|
|
104
|
+
return removeSetting(await target(ctx, layer), key).catch(asCommandError);
|
|
105
|
+
},
|
|
106
|
+
async explain(ctx, key) {
|
|
107
|
+
if (resolveConfigKey(key) === undefined)
|
|
108
|
+
throw new ConfigUsageError(`unknown setting: ${key}`);
|
|
109
|
+
const loaded = await load(ctx);
|
|
110
|
+
const fallback = getConfigValue(DEFAULT_CONFIG, key);
|
|
111
|
+
const user = loaded.files.user === null ? undefined : getConfigValue(loaded.files.user, key);
|
|
112
|
+
const project = loaded.files.project === null ? undefined : getConfigValue(loaded.files.project, key);
|
|
113
|
+
const projectApplied = loaded.layers.project === null ? undefined : getConfigValue(loaded.layers.project, key);
|
|
114
|
+
const reason = project === undefined ? null : projectIgnoreReason(key, project);
|
|
115
|
+
const layers = [
|
|
116
|
+
{ layer: 'default', set: fallback !== undefined, value: fallback },
|
|
117
|
+
{
|
|
118
|
+
layer: 'user',
|
|
119
|
+
set: user !== undefined,
|
|
120
|
+
value: user,
|
|
121
|
+
file: loaded.locations.user,
|
|
122
|
+
...(loaded.locations.userEnvVar !== null ? { envVar: loaded.locations.userEnvVar } : {}),
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
layer: 'project',
|
|
126
|
+
set: project !== undefined,
|
|
127
|
+
value: project,
|
|
128
|
+
file: loaded.locations.project,
|
|
129
|
+
allowed: project === undefined || projectApplied !== undefined,
|
|
130
|
+
...(reason !== null ? { note: reason } : {}),
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
return { layers, warnings: loaded.warnings };
|
|
134
|
+
},
|
|
135
|
+
};
|
|
128
136
|
}
|
|
129
137
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* Exit codes: 0 means success. 2 means the command cannot run as typed: an
|
|
134
|
-
* unknown subcommand or option, a wrong number of arguments, conflicting
|
|
135
|
-
* flags, an unknown setting name, or a value of the wrong type. Each is
|
|
136
|
-
* decided from the arguments and the schema alone, with no file involved, so
|
|
137
|
-
* running it again gives the same answer. 1 means a valid command that
|
|
138
|
-
* failed: a file that will not parse, a key that is not set where you asked
|
|
139
|
-
* to unset it, or a `get` that found nothing.
|
|
140
|
-
*
|
|
141
|
-
* A script can act on the difference: 2 means fix the command, 1 means look
|
|
142
|
-
* at the state.
|
|
138
|
+
* The `config` group: `list` (the default), `get`, `set`, `unset`, `path` and
|
|
139
|
+
* `explain`. Mount it as `config: configCommand({ globals })`, with the app's
|
|
140
|
+
* global flags; `-C` must be declared as `dir`.
|
|
143
141
|
*/
|
|
144
|
-
export
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
const fail = (message) => {
|
|
148
|
-
io.stderr(`${toolName}: ${message}\n`);
|
|
149
|
-
return EXIT.error;
|
|
150
|
-
};
|
|
151
|
-
const [sub, ...rest] = argv;
|
|
152
|
-
try {
|
|
153
|
-
switch (sub) {
|
|
154
|
-
// Usage on stdout with exit 0, because `--help` asked for it.
|
|
155
|
-
case '-h':
|
|
156
|
-
case '--help':
|
|
157
|
-
io.stdout(usage());
|
|
158
|
-
return EXIT.ok;
|
|
159
|
-
case undefined:
|
|
160
|
-
case 'list':
|
|
161
|
-
return await listCommand(toolName, root, rest, io, env, home);
|
|
162
|
-
case 'get':
|
|
163
|
-
return await getCommand(toolName, root, rest, io, env, home);
|
|
164
|
-
case 'set':
|
|
165
|
-
return await setCommand(toolName, root, rest, io, env, home);
|
|
166
|
-
case 'unset':
|
|
167
|
-
return await unsetCommand(toolName, root, rest, io, env, home);
|
|
168
|
-
case 'path':
|
|
169
|
-
return await pathCommand(toolName, rest, io, env, home, root);
|
|
170
|
-
default:
|
|
171
|
-
io.stderr(`${toolName}: unknown config command: ${sub}\n\n${usage()}`);
|
|
172
|
-
return EXIT.usage;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
// A ConfigError names its file and its problem. A setting that quietly did
|
|
177
|
-
// not apply is worse than one that refused to load, so there is no silent
|
|
178
|
-
// fallback.
|
|
179
|
-
if (error instanceof ConfigError)
|
|
180
|
-
return fail(error.message);
|
|
181
|
-
throw error;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
async function listCommand(toolName, root, argv, io, env, home) {
|
|
185
|
-
let json = false;
|
|
186
|
-
for (const arg of argv) {
|
|
187
|
-
if (arg === '--json')
|
|
188
|
-
json = true;
|
|
189
|
-
else {
|
|
190
|
-
io.stderr(`${toolName}: unknown option: ${arg}\n\n${usage()}`);
|
|
191
|
-
return EXIT.usage;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
const loaded = await load(toolName, root, env, home, io.defaults);
|
|
195
|
-
if (json) {
|
|
196
|
-
const sources = {};
|
|
197
|
-
for (const [key, layer] of loaded.sources)
|
|
198
|
-
sources[key] = layer;
|
|
199
|
-
io.stdout(`${jsonText({ effective: loaded.effective, sources, locations: loaded.locations }, 2)}\n`);
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
// JSON.stringify leaves DEL and C1 characters raw, so the human listing
|
|
203
|
-
// still goes through terminalSafe.
|
|
204
|
-
const rows = [...loaded.sources].map(([key, layer]) => ({
|
|
205
|
-
key: terminalSafe(key),
|
|
206
|
-
value: terminalSafe(JSON.stringify(getConfigValue(loaded.effective, key))),
|
|
207
|
-
layer,
|
|
208
|
-
}));
|
|
209
|
-
const keyWidth = rows.reduce((n, r) => Math.max(n, r.key.length), 0);
|
|
210
|
-
const valueWidth = rows.reduce((n, r) => Math.max(n, r.value.length), 0);
|
|
211
|
-
for (const row of rows) {
|
|
212
|
-
io.stdout(`${pad(row.key, keyWidth)} ${pad(row.value, valueWidth)} (${row.layer})\n`);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
// Context and warnings go to stderr so `--json` stays machine-readable and
|
|
216
|
-
// the plain listing stays greppable.
|
|
217
|
-
io.stderr(`user: ${await describeFile(loaded.locations.user)}\n`);
|
|
218
|
-
if (loaded.locations.userEnvVar !== null)
|
|
219
|
-
io.stderr(` (from ${loaded.locations.userEnvVar})\n`);
|
|
220
|
-
io.stderr(`project: ${await describeFile(loaded.locations.project)}\n`);
|
|
221
|
-
for (const warning of loaded.warnings)
|
|
222
|
-
io.stderr(`warning: ${warning}\n`);
|
|
223
|
-
return EXIT.ok;
|
|
224
|
-
}
|
|
225
|
-
async function getCommand(toolName, root, argv, io, env, home) {
|
|
226
|
-
const key = argv[0];
|
|
227
|
-
if (key === undefined || argv.length > 1) {
|
|
228
|
-
io.stderr(`${toolName}: config get takes exactly one key\n\n${usage()}`);
|
|
229
|
-
return EXIT.usage;
|
|
230
|
-
}
|
|
231
|
-
const loaded = await load(toolName, root, env, home, io.defaults);
|
|
232
|
-
const value = getConfigValue(loaded.effective, key);
|
|
233
|
-
// Warnings go to stderr rather than being hidden. `get` stays scriptable
|
|
234
|
-
// because its stdout is only the value, and the user should hear about an
|
|
235
|
-
// ignored key wherever they read the config.
|
|
236
|
-
for (const warning of loaded.warnings)
|
|
237
|
-
io.stderr(`warning: ${warning}\n`);
|
|
238
|
-
if (value === undefined) {
|
|
239
|
-
io.stderr(`${toolName}: no value for ${key}\n`);
|
|
240
|
-
return EXIT.error;
|
|
241
|
-
}
|
|
242
|
-
io.stdout(`${jsonText(value)}\n`);
|
|
243
|
-
return EXIT.ok;
|
|
244
|
-
}
|
|
245
|
-
async function setCommand(toolName, root, argv, io, env, home) {
|
|
246
|
-
const taken = takeTarget(argv);
|
|
247
|
-
if ('error' in taken) {
|
|
248
|
-
io.stderr(`${toolName}: ${taken.error}\n\n${usage()}`);
|
|
249
|
-
return EXIT.usage;
|
|
250
|
-
}
|
|
251
|
-
const [key, raw] = taken.rest;
|
|
252
|
-
if (key === undefined || raw === undefined || taken.rest.length > 2) {
|
|
253
|
-
io.stderr(`${toolName}: config set takes a key and a value\n\n${usage()}`);
|
|
254
|
-
return EXIT.usage;
|
|
255
|
-
}
|
|
256
|
-
// configLocations rather than loadConfig: where to write must not depend on
|
|
257
|
-
// the other layer parsing, and `set --user` has to work when
|
|
258
|
-
// WAYFINDER_CONFIG names a file that does not exist yet.
|
|
259
|
-
const locations = configLocations(root, env, home);
|
|
260
|
-
const file = taken.target === 'user' ? locations.user : locations.project;
|
|
261
|
-
// The raw record, not the validated one. Validation drops keys this version
|
|
262
|
-
// does not know, so writing a validated document back would silently delete
|
|
263
|
-
// a setting a newer version had written to the same file.
|
|
264
|
-
const document = (await readRawConfigFile(file)) ?? {};
|
|
265
|
-
let next;
|
|
266
|
-
try {
|
|
267
|
-
next = setConfigValue(document, key, parseConfigValue(raw));
|
|
268
|
-
}
|
|
269
|
-
catch (error) {
|
|
270
|
-
// A ConfigError with no file is about what was typed: an unknown setting
|
|
271
|
-
// name, or a value of the wrong type. An empty `file` tells these apart
|
|
272
|
-
// from the errors below, which are about a file.
|
|
273
|
-
if (error instanceof ConfigError && error.file === '') {
|
|
274
|
-
io.stderr(`${toolName}: ${error.message}\n\n${usage()}`);
|
|
275
|
-
return EXIT.usage;
|
|
276
|
-
}
|
|
277
|
-
throw error;
|
|
278
|
-
}
|
|
279
|
-
// Validate the whole document before writing it. A refused value is only a
|
|
280
|
-
// message, but a bad written value makes the file fail to load on every
|
|
281
|
-
// later run. A failure here is a bad value already in the file, so the
|
|
282
|
-
// error names the file and exits 1.
|
|
283
|
-
validateConfig(next, file);
|
|
284
|
-
await writeConfigFile(file, next);
|
|
285
|
-
// Written, then warned about. Refusing the write would be odd, since the key
|
|
286
|
-
// is real and the value is valid. But a silent write would let the author
|
|
287
|
-
// believe the setting took effect, with only `loadConfig`'s warning, which
|
|
288
|
-
// they may never read, saying otherwise.
|
|
289
|
-
if (taken.target === 'project' && key === 'allowExec' && getConfigValue(next, key) === true) {
|
|
290
|
-
io.stderr(`${toolName}: warning: allowExec: true in a project file is ignored — a repository cannot grant itself permission to run subprocesses; run "${BIN} trust" to trust this repository\n`);
|
|
291
|
-
}
|
|
292
|
-
if (taken.target === 'project' && (key === 'trust.paths' || key === 'trust.owners')) {
|
|
293
|
-
const written = getConfigValue(next, key);
|
|
294
|
-
if (Array.isArray(written) && written.length > 0) {
|
|
295
|
-
io.stderr(`${toolName}: warning: ${key} in a project file is ignored — a repository cannot grant itself trust; set it in your user config instead\n`);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
io.stdout(terminalSafe(`${file}: ${key} = ${JSON.stringify(getConfigValue(next, key))}`) + '\n');
|
|
299
|
-
return EXIT.ok;
|
|
300
|
-
}
|
|
301
|
-
async function unsetCommand(toolName, root, argv, io, env, home) {
|
|
302
|
-
const taken = takeTarget(argv);
|
|
303
|
-
if ('error' in taken) {
|
|
304
|
-
io.stderr(`${toolName}: ${taken.error}\n\n${usage()}`);
|
|
305
|
-
return EXIT.usage;
|
|
306
|
-
}
|
|
307
|
-
const key = taken.rest[0];
|
|
308
|
-
if (key === undefined || taken.rest.length > 1) {
|
|
309
|
-
io.stderr(`${toolName}: config unset takes exactly one key\n\n${usage()}`);
|
|
310
|
-
return EXIT.usage;
|
|
311
|
-
}
|
|
312
|
-
const locations = configLocations(root, env, home);
|
|
313
|
-
const file = taken.target === 'user' ? locations.user : locations.project;
|
|
314
|
-
const document = await readRawConfigFile(file);
|
|
315
|
-
if (document === null || getConfigValue(document, key) === undefined) {
|
|
316
|
-
// Reported as an error. Succeeding on a key that was not there would
|
|
317
|
-
// suggest the setting is gone, which is wrong when the value is set in
|
|
318
|
-
// the other layer.
|
|
319
|
-
io.stderr(`${toolName}: ${key} is not set in ${file}\n`);
|
|
320
|
-
return EXIT.error;
|
|
321
|
-
}
|
|
322
|
-
const next = unsetConfigValue(document, key);
|
|
323
|
-
await writeConfigFile(file, next);
|
|
324
|
-
io.stdout(terminalSafe(`${file}: removed ${key}`) + '\n');
|
|
325
|
-
return EXIT.ok;
|
|
326
|
-
}
|
|
327
|
-
async function pathCommand(toolName, argv, io, env, home, root) {
|
|
328
|
-
// Every other subcommand rejects arguments it does not understand. If `path`
|
|
329
|
-
// ignored them, a typo here would look like it worked.
|
|
330
|
-
if (argv.length > 0) {
|
|
331
|
-
io.stderr(`${toolName}: config path takes no arguments\n\n${usage()}`);
|
|
332
|
-
return EXIT.usage;
|
|
333
|
-
}
|
|
334
|
-
// Locations are resolved without reading either file's contents. Only
|
|
335
|
-
// existence is checked. You use `config path` when a file will not load, so
|
|
336
|
-
// it must not fail on the file it names.
|
|
337
|
-
const locations = configLocations(root, env, home);
|
|
338
|
-
const ignored = envIgnoredWarning(locations);
|
|
339
|
-
if (ignored !== null)
|
|
340
|
-
io.stderr(`warning: ${ignored}\n`);
|
|
341
|
-
io.stdout(`user: ${await describeFile(locations.user)}\n`);
|
|
342
|
-
if (locations.userEnvVar !== null)
|
|
343
|
-
io.stdout(` (from ${locations.userEnvVar})\n`);
|
|
344
|
-
io.stdout(`project: ${await describeFile(locations.project)}\n`);
|
|
345
|
-
return EXIT.ok;
|
|
142
|
+
export function configCommand(options = {}) {
|
|
143
|
+
const { globals, ...env } = options;
|
|
144
|
+
return configCommands(configStore(env), globals !== undefined ? { globals } : {});
|
|
346
145
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config key lists that the page needs as well as the CLI. Browser-safe: no
|
|
3
|
+
* Node built-in, so the web view imports it.
|
|
4
|
+
*/
|
|
5
|
+
/** The `theme` values for the web view. `system` follows the browser. */
|
|
6
|
+
export declare const THEME_VALUES: readonly ["system", "light", "dark"];
|
|
7
|
+
/** The web view's theme. */
|
|
8
|
+
export type Theme = (typeof THEME_VALUES)[number];
|
|
9
|
+
/**
|
|
10
|
+
* The keys `config set` and `config unset` change from the command line only.
|
|
11
|
+
* cli-tool's adapters, such as the HTTP one the web view's server runs,
|
|
12
|
+
* refuse a write of any of them: an agent or a page must not grant trust,
|
|
13
|
+
* turn execution on, or name code to load.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CLI_ONLY_KEYS: readonly string[];
|
|
16
|
+
/** The top-level keys only the user layer may set. */
|
|
17
|
+
export declare const USER_ONLY_KEYS: readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* The file a settings screen writes `key` to, given where its value comes
|
|
20
|
+
* from now (`default`, `user` or `project`). A user-only key goes to the
|
|
21
|
+
* user file. `runners.order` goes to the file that sets it, else the user
|
|
22
|
+
* file, so a reorder always takes effect. Every other key goes to the
|
|
23
|
+
* project file.
|
|
24
|
+
*/
|
|
25
|
+
export declare function settingLayer(key: string, source: string): 'user' | 'project';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config key lists that the page needs as well as the CLI. Browser-safe: no
|
|
3
|
+
* Node built-in, so the web view imports it.
|
|
4
|
+
*/
|
|
5
|
+
/** The `theme` values for the web view. `system` follows the browser. */
|
|
6
|
+
export const THEME_VALUES = ['system', 'light', 'dark'];
|
|
7
|
+
/**
|
|
8
|
+
* The keys `config set` and `config unset` change from the command line only.
|
|
9
|
+
* cli-tool's adapters, such as the HTTP one the web view's server runs,
|
|
10
|
+
* refuse a write of any of them: an agent or a page must not grant trust,
|
|
11
|
+
* turn execution on, or name code to load.
|
|
12
|
+
*/
|
|
13
|
+
export const CLI_ONLY_KEYS = ['trust', 'allowExec', 'tools'];
|
|
14
|
+
/** The top-level keys only the user layer may set. */
|
|
15
|
+
export const USER_ONLY_KEYS = ['trust', 'open', 'theme', 'skills'];
|
|
16
|
+
/**
|
|
17
|
+
* The file a settings screen writes `key` to, given where its value comes
|
|
18
|
+
* from now (`default`, `user` or `project`). A user-only key goes to the
|
|
19
|
+
* user file. `runners.order` goes to the file that sets it, else the user
|
|
20
|
+
* file, so a reorder always takes effect. Every other key goes to the
|
|
21
|
+
* project file.
|
|
22
|
+
*/
|
|
23
|
+
export function settingLayer(key, source) {
|
|
24
|
+
if (USER_ONLY_KEYS.includes(key.split('.')[0]))
|
|
25
|
+
return 'user';
|
|
26
|
+
if (key === 'runners.order')
|
|
27
|
+
return source === 'project' ? 'project' : 'user';
|
|
28
|
+
return 'project';
|
|
29
|
+
}
|