@osdlc/wayfinder 0.7.1 → 0.7.2

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/dist/config.js CHANGED
@@ -1,49 +1,50 @@
1
1
  /**
2
- * wayfinder's configuration: layered, and readable without running anything.
3
- * The settings people want every time (runners to skip, paths that are not
2
+ * wayfinder's configuration. It is layered, and reading it runs nothing.
3
+ * Settings people want on every run (runners to skip, paths that are not
4
4
  * project structure, whether execution is allowed, extra tools) are set once,
5
- * per user and per project; flags stay for the exceptions.
5
+ * per user and per project. Flags are for one-off changes.
6
6
  *
7
7
  * ## Layers, lowest precedence first
8
8
  *
9
9
  * 1. `DEFAULT_CONFIG` — the built-in defaults.
10
10
  * 2. USER — `$XDG_CONFIG_HOME/wayfinder/config.json`, or `~/.config/wayfinder/config.json`
11
- * when `XDG_CONFIG_HOME` is unset.
11
+ * when `XDG_CONFIG_HOME` is unset or relative.
12
12
  * 3. PROJECT — `wayfinder.config.json` at the root `findRoot` resolves.
13
- * 4. CLI flags — not this module's business. {@link collectOptionsFromConfig}
14
- * produces the slice a caller spreads its own flags on top of.
13
+ * 4. CLI flags, applied by the caller. {@link collectOptionsFromConfig}
14
+ * returns the options a caller spreads its own flags on top of.
15
15
  *
16
- * `allowExec` IS AN EXCEPTION TO THIS ORDER. The project layer may lower it to
17
- * `false` — a repository asking not to be shelled out for is safe to honour —
18
- * but it can never raise it to `true`. `wayfinder.config.json` lives INSIDE the
19
- * repository being scanned, so honouring `allowExec: true` from it would let a
20
- * repository authorize the execution of its own code. The key is therefore
21
- * stripped from the project layer before merging, with a warning, and only the
22
- * user layer and the CLI flags can turn execution on. Granting a repository
23
- * standing permission is `way trust`, which records the consent outside the
24
- * repository.
16
+ * `allowExec` is an exception to this order. The project layer may lower it to
17
+ * `false`, since a repository asking not to be run is safe to honour. It can
18
+ * never raise it to `true`. `wayfinder.config.json` lives inside the repository
19
+ * being scanned, so honouring `allowExec: true` from it would let a repository
20
+ * authorize running its own code. So `allowExec: true` is removed from the
21
+ * project layer before merging, with a warning. Only the user layer and the CLI
22
+ * flags can turn execution on. To give a repository lasting permission, run
23
+ * `way trust`, which records the consent outside the repository.
25
24
  *
26
25
  * `tools` is gated too, because a tool module is code. User-layer entries
27
26
  * always load; project-layer entries load only when the repository is trusted
28
27
  * and execution is allowed (see `tools.ts`).
29
28
  *
30
- * `trust` IS THE SAME EXCEPTION, more strongly: it has no "lower" state to
31
- * honour from the project layer at all, so ANY project-layer `trust.paths` or
32
- * `trust.owners` entry is dropped, with a warning — a repository must not be
33
- * able to pre-authorize itself, or any class of repositories including
34
- * itself. Only the USER layer's `trust` reaches `@osdlc/trust-repo`'s
35
- * `policyExecGate`, which combines it with the marker store that
36
- * `way trust` writes to. See that package's README for the glob dialect,
37
- * and `origin-owner.ts` for the origin-remote lookup `trust.owners` rests on.
29
+ * `trust` is a stricter exception. It has no lower setting a project could
30
+ * choose, so the whole project-layer `trust` block is dropped, with a warning
31
+ * when it is not empty. A repository must not be able to pre-authorize itself,
32
+ * or any group of repositories that includes it. Only the user layer's `trust`
33
+ * reaches `@osdlc/trust-repo`'s `policyExecGate`, which combines it with the
34
+ * marker store that `way trust` writes to. See that package's README for the
35
+ * glob dialect, and `origin-owner.ts` for the origin-remote lookup that
36
+ * `trust.owners` uses.
38
37
  *
39
- * XDG is used on every platform, macOS included, as `gh` does: a developer
40
- * with a dotfiles repository expects this beside their other tool config.
38
+ * XDG paths are used on every platform, macOS included, as `gh` does. A
39
+ * developer with a dotfiles repository expects this file beside their other
40
+ * tool config.
41
41
  *
42
- * `WAYFINDER_CONFIG=/path/to/file` replaces the USER layer's LOCATION and nothing
43
- * else. The named file is read INSTEAD OF the XDG path; the project layer is
44
- * still read from the project root, still merges on top, and cannot be turned
45
- * off this way. Naming a file that does not exist is an error rather than a
46
- * silent empty layer — an env var pointing at nothing is a typo, not a choice.
42
+ * `WAYFINDER_CONFIG=/path/to/file` changes only where the user layer is read
43
+ * from. The named file is read instead of the XDG path. The project layer is
44
+ * still read from the project root and still merges on top. Naming a file that
45
+ * does not exist is an error, not an empty layer: an env var that points at
46
+ * nothing is a typo. A relative value is ignored with a warning, and the XDG
47
+ * path is read instead.
47
48
  *
48
49
  * ## The old waypost names
49
50
  *
@@ -59,10 +60,10 @@
59
60
  *
60
61
  * ## Merge rule
61
62
  *
62
- * Objects merge key-wise; everything else — scalars and arrays alike —
63
- * REPLACES wholesale. Arrays replace because both of ours are answers to
64
- * "which ones, in what order", and a project that says `order: ["just"]` means
65
- * that list, not that list appended to whatever the user happened to have.
63
+ * Objects merge key by key. Everything else, scalars and arrays alike,
64
+ * replaces the lower value whole. Arrays replace because each array setting
65
+ * answers "which ones, in what order". A project that says `order: ["just"]`
66
+ * means that list, not that list appended to the user's.
66
67
  *
67
68
  * user { runners: { disabled: ["cargo"], order: ["moon"] } }
68
69
  * project { runners: { order: ["just"] } }
@@ -70,19 +71,18 @@
70
71
  *
71
72
  * ## Unknown keys and broken files
72
73
  *
73
- * An unknown key is a WARNING naming the file and the key, and the rest of the
74
- * file still loads — a config written for a newer version must not brick an
75
- * older one. A file that is malformed, or that holds a wrong-typed value where
76
- * the type is knowable, is a {@link ConfigError} naming the file and the
77
- * problem. There is no silent fallback: a setting that quietly did not apply is
78
- * worse than one that refused to load.
74
+ * An unknown key is a warning naming the file and the key, and the rest of the
75
+ * file still loads. A config written for a newer version must not break an
76
+ * older one. A malformed file, or a value of the wrong type for a known key, is
77
+ * a {@link ConfigError} naming the file and the problem. There is no silent
78
+ * fallback: a setting that quietly did not apply is worse than one that refused
79
+ * to load.
79
80
  */
80
81
  import { existsSync } from 'node:fs';
81
82
  import { mkdir, writeFile } from 'node:fs/promises';
82
- import { homedir } from 'node:os';
83
- import { dirname, join, resolve } from 'node:path';
83
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
84
84
  import { readParsedFile } from '@osdlc/config-layers';
85
- import { resolveTrustRoot } from '@osdlc/trust-repo';
85
+ import { homeDir, resolveTrustRoot, } from '@osdlc/trust-repo';
86
86
  import { APP, BIN, CONFIG_ENV_VAR, LEGACY_APP, LEGACY_CONFIG_ENV_VAR, LEGACY_PROJECT_CONFIG_FILENAME, PROJECT_CONFIG_FILENAME, } from "./app.js";
87
87
  import { originOwner } from "./origin-owner.js";
88
88
  import { expandTilde } from "./xdg.js";
@@ -100,8 +100,8 @@ export const USER_CONFIG_FILENAME = 'config.json';
100
100
  /**
101
101
  * The built-in defaults layer.
102
102
  *
103
- * Every leaf is present, which is what makes {@link LoadedConfig.sources}
104
- * total: a key with no answer anywhere would otherwise have no layer to name.
103
+ * Every leaf is present, so {@link LoadedConfig.sources} has an entry for
104
+ * every key. A key set in no file is attributed to this layer.
105
105
  */
106
106
  export const DEFAULT_CONFIG = {
107
107
  runners: { disabled: [], order: [] },
@@ -128,9 +128,9 @@ export class ConfigError extends Error {
128
128
  }
129
129
  }
130
130
  /**
131
- * Every settable key, by dotted path. This is the single list: validation,
132
- * {@link setConfigValue} and "is that a real setting" all read it, so a new
133
- * setting cannot be accepted in one path and rejected in another.
131
+ * Every settable key, by dotted path. Validation, {@link setConfigValue} and
132
+ * the known-key check all read this one list, so a setting cannot be accepted
133
+ * in one place and rejected in another.
134
134
  */
135
135
  const FIELDS = {
136
136
  'runners.disabled': 'string-array',
@@ -145,16 +145,16 @@ const FIELDS = {
145
145
  /**
146
146
  * Every settable key, in schema order — the dotted names `config set` accepts.
147
147
  *
148
- * Derived from {@link FIELDS} rather than retyped, so a surface that lists the
149
- * keys (the `guide` command's config section) cannot fall behind the schema.
148
+ * Derived from {@link FIELDS}, so anything that lists the keys (the `guide`
149
+ * command's config section) stays in step with the schema.
150
150
  */
151
151
  export const CONFIG_KEYS = Object.keys(FIELDS);
152
152
  const DISCOVERY_VALUES = ['git', 'walk', 'auto'];
153
153
  /**
154
- * Canonical key order for writing, schema order rather than alphabetical, so a
155
- * written file reads like the documented schema. Keys not listed here are
156
- * unknown to this version and are written after the known ones in the order the
157
- * file already had them.
154
+ * Key order for writing: schema order, not alphabetical, so a written file
155
+ * reads like the documented schema. Keys not listed here are unknown to this
156
+ * version. They are written after the known ones, in the order the file
157
+ * already had them.
158
158
  */
159
159
  const KEY_ORDER = {
160
160
  '': ['runners', 'allowExec', 'discovery', 'excludePaths', 'trust', 'tools'],
@@ -207,46 +207,50 @@ function unknownKeyWarning(file, key) {
207
207
  return `${file}: unknown setting "${key}" (ignored)`;
208
208
  }
209
209
  /**
210
- * Resolve where each layer's file lives. `env` and `home` are injectable
211
- * because a test that consulted the real environment would read the developer's
212
- * own `~/.config`, and pass or fail according to what is in it. The only other
213
- * input is whether a file exists, which picks between a new name and its old
214
- * waypost fallback (see the module docblock).
210
+ * Resolve where each layer's file lives. `env` and `home` are injectable so a
211
+ * test does not read the developer's own `~/.config`. The only other input is
212
+ * whether a file exists, which picks between a new name and its old waypost
213
+ * name (see the module docblock).
215
214
  *
216
- * Two details of how a path out of the environment is read:
215
+ * Rules for a path taken from the environment:
217
216
  *
218
217
  * A leading `~` is expanded against `home`. A shell expands it before exec, but
219
- * `.env` loaders, direnv and CI YAML hand the literal tilde through, and
220
- * `~/config.json` quietly becoming `<somewhere>/~/config.json` is the silent
221
- * wrong answer this module refuses to give anywhere else.
218
+ * `.env` loaders, direnv and CI YAML pass the literal tilde through. Without
219
+ * this, `~/config.json` would silently become `<somewhere>/~/config.json`.
222
220
  *
223
- * A RELATIVE path resolves against `root`, not the process working directory.
224
- * This function is otherwise a pure function of its arguments; reading
225
- * `process.cwd()` would smuggle an ambient input in, so a library consumer
226
- * scanning some other directory would get a user-layer path unrelated to the
227
- * directory being scanned while the project layer tracked it.
221
+ * A relative `XDG_CONFIG_HOME` is ignored, as the XDG spec says. A relative
222
+ * `WAYFINDER_CONFIG` is ignored too, and `userEnvIgnored` says so. Resolved
223
+ * against the root, or against the cwd, which is usually the root, it would
224
+ * name a file inside the repository being scanned, and the user layer can
225
+ * turn execution on and load tools.
228
226
  */
229
- export function configLocations(root, env = process.env, home = homedir()) {
227
+ export function configLocations(root, env = process.env, home = homeDir()) {
230
228
  const base = resolve(root);
231
- const absolute = (path) => resolve(base, expandTilde(path, home));
232
229
  const fromVar = (name) => {
233
230
  const value = env[name]?.trim();
234
231
  return value !== undefined && value !== '' ? value : null;
235
232
  };
236
233
  const named = fromVar(CONFIG_ENV_VAR);
237
234
  const legacyNamed = named === null ? fromVar(LEGACY_CONFIG_ENV_VAR) : null;
238
- const userEnvVar = named !== null ? CONFIG_ENV_VAR : legacyNamed !== null ? LEGACY_CONFIG_ENV_VAR : null;
239
- const envPath = named ?? legacyNamed;
240
- const xdg = env['XDG_CONFIG_HOME']?.trim();
241
- const configHome = xdg !== undefined && xdg !== '' ? absolute(xdg) : join(home, '.config');
235
+ const namedVar = named !== null ? CONFIG_ENV_VAR : legacyNamed !== null ? LEGACY_CONFIG_ENV_VAR : null;
236
+ const envValue = named ?? legacyNamed;
237
+ const expanded = envValue === null ? null : expandTilde(envValue, home);
238
+ const envPath = expanded !== null && isAbsolute(expanded) ? expanded : null;
239
+ const userEnvVar = envPath !== null ? namedVar : null;
240
+ const userEnvIgnored = namedVar !== null && envValue !== null && envPath === null
241
+ ? { variable: namedVar, value: envValue }
242
+ : null;
243
+ const xdg = expandTilde(env['XDG_CONFIG_HOME']?.trim() ?? '', home);
244
+ const configHome = isAbsolute(xdg) ? xdg : join(home, '.config');
242
245
  const xdgUser = preferNew(join(configHome, USER_CONFIG_DIR, USER_CONFIG_FILENAME), join(configHome, LEGACY_USER_CONFIG_DIR, USER_CONFIG_FILENAME));
243
246
  const project = preferNew(join(base, PROJECT_CONFIG_FILENAME), join(base, LEGACY_PROJECT_CONFIG_FILENAME));
244
247
  return {
245
- user: envPath !== null ? absolute(envPath) : xdgUser.path,
248
+ user: envPath !== null ? resolve(envPath) : xdgUser.path,
246
249
  userFromEnv: envPath !== null,
247
250
  userEnvVar,
248
251
  userLegacy: envPath === null && xdgUser.legacy,
249
252
  userIgnored: envPath === null ? xdgUser.ignored : null,
253
+ userEnvIgnored,
250
254
  project: project.path,
251
255
  projectLegacy: project.legacy,
252
256
  projectIgnored: project.ignored,
@@ -266,10 +270,9 @@ function preferNew(path, legacy) {
266
270
  /**
267
271
  * Validate a parsed JSON document against schema v1.
268
272
  *
269
- * Throws {@link ConfigError} on a type violation; returns the recognized subset
270
- * plus one warning per unknown key. The returned config holds ONLY known keys,
271
- * which is why the write path never round-trips through this shape — see
272
- * {@link readRawConfigFile}.
273
+ * Throws {@link ConfigError} on a type error. Returns the known keys plus one
274
+ * warning per unknown key. Because the result holds only known keys, the write
275
+ * path never goes through this shape (see {@link readRawConfigFile}).
273
276
  */
274
277
  export function validateConfig(raw, file) {
275
278
  if (!isPlainObject(raw)) {
@@ -336,11 +339,10 @@ export function validateConfig(raw, file) {
336
339
  return { config, warnings };
337
340
  }
338
341
  /**
339
- * Copy a value deeply enough that the result shares no mutable structure with
340
- * its source. A shallow spread is not enough here: `DEFAULT_CONFIG` is an
341
- * exported process-wide singleton that every `loadConfig` merges on top of, so
342
- * a branch aliased out of it would let one caller mutating `effective` corrupt
343
- * the built-in defaults for every later load in the process.
342
+ * Deep-copy a value so the result shares no mutable structure with its source.
343
+ * A shallow spread is not enough. Every `loadConfig` merges on top of the
344
+ * exported `DEFAULT_CONFIG` object, so a shared branch would let a caller that
345
+ * mutates `effective` corrupt the defaults for every later load.
344
346
  */
345
347
  function cloneValue(value) {
346
348
  if (Array.isArray(value))
@@ -371,22 +373,20 @@ function deepMerge(base, over) {
371
373
  return out;
372
374
  }
373
375
  /**
374
- * Merge `over` onto `base` per the module's rule: objects key-wise, scalars and
375
- * arrays wholesale.
376
+ * Merge `over` onto `base` per the module's rule: objects key by key, scalars
377
+ * and arrays replaced whole.
376
378
  *
377
- * Non-mutating in both directions: neither argument is touched, and the result
378
- * shares no object or array with either of them — including branches `over`
379
- * never mentioned. Mutating a loaded config must not reach back into
380
- * `DEFAULT_CONFIG`.
379
+ * Neither argument is changed, and the result shares no object or array with
380
+ * either, including branches `over` does not mention. Mutating a loaded config
381
+ * must not change `DEFAULT_CONFIG`.
381
382
  */
382
383
  export function mergeConfig(base, over) {
383
384
  return deepMerge(base, over);
384
385
  }
385
386
  /**
386
- * One layer file as a plain object, read through `@osdlc/config-layers`'s
387
- * file read (the one read of a config file's bytes). `null` when the file does
388
- * not exist; a file that is unreadable, not JSON, or not an object throws
389
- * {@link ConfigError} naming it.
387
+ * One layer file as a plain object, read with `@osdlc/config-layers`'s
388
+ * `readParsedFile`. `null` when the file does not exist. A file that is
389
+ * unreadable, not JSON, or not an object throws {@link ConfigError} naming it.
390
390
  */
391
391
  async function readJsonFile(file) {
392
392
  const read = readParsedFile(file, 'json');
@@ -407,19 +407,18 @@ async function readJsonFile(file) {
407
407
  /**
408
408
  * The file's parsed object, unvalidated and with every key intact.
409
409
  *
410
- * This is the read half of an edit that preserves what this version does not
411
- * understand. `set` and `unset` must apply to THIS, not to the validated shape,
412
- * because validation drops unknown keys — so writing a validated document back
413
- * would silently delete a setting a newer version had written. `null` when the
414
- * file does not exist.
410
+ * `set` and `unset` edit this object, not the validated shape, because
411
+ * validation drops unknown keys. Writing a validated document back would
412
+ * silently delete a setting a newer version had written. `null` when the file
413
+ * does not exist.
415
414
  */
416
415
  export async function readRawConfigFile(file) {
417
416
  return readJsonFile(file);
418
417
  }
419
418
  /**
420
- * Read, parse and validate one layer. `null` when the file does not exist —
421
- * absence is normal and is not an error. A file that exists and is broken
422
- * throws {@link ConfigError}.
419
+ * Read, parse and validate one layer. `null` when the file does not exist,
420
+ * which is normal and not an error. A file that exists and is broken throws
421
+ * {@link ConfigError}.
423
422
  */
424
423
  export async function readConfigFile(file) {
425
424
  const raw = await readJsonFile(file);
@@ -449,11 +448,11 @@ function stabilize(record, section) {
449
448
  * Parent directories are created.
450
449
  *
451
450
  * The order is fixed so that writing an unchanged document produces an
452
- * unchanged file — a config under version control should not churn its diff
451
+ * unchanged file. A config under version control should not show a diff
453
452
  * because a key moved.
454
453
  *
455
- * Accepts a raw record as well as a {@link TaskConfig}, which is what makes the
456
- * unknown-key-preserving edit path writable.
454
+ * Accepts a raw record as well as a {@link TaskConfig}, so an edit can keep
455
+ * unknown keys.
457
456
  */
458
457
  export async function writeConfigFile(file, config) {
459
458
  const body = JSON.stringify(stabilize(config, ''), null, 2);
@@ -469,7 +468,7 @@ function leafPaths(value, prefix) {
469
468
  * Load every layer and merge them. `env` and `home` are injectable for the same
470
469
  * reason {@link configLocations} takes them.
471
470
  */
472
- export async function loadConfig(root, env = process.env, home = homedir()) {
471
+ export async function loadConfig(root, env = process.env, home = homeDir()) {
473
472
  const locations = configLocations(root, env, home);
474
473
  const userRead = await readConfigFile(locations.user);
475
474
  if (userRead === null && locations.userFromEnv) {
@@ -481,27 +480,25 @@ export async function loadConfig(root, env = process.env, home = homedir()) {
481
480
  const warnings = [...(userRead?.warnings ?? []), ...(projectRead?.warnings ?? [])];
482
481
  warnings.push(...legacyWarnings(locations));
483
482
  // A repository cannot grant itself permission to run its own code. Lowering
484
- // to false is honoured; raising to true is dropped here, BEFORE the merge and
485
- // before `sources`, so `config list` attributes the value to the layer that
486
- // really supplied it rather than to the file that was ignored.
483
+ // to false is honoured. Raising to true is dropped here, before the merge and
484
+ // before `sources`, so `config list` names the layer that really supplied the
485
+ // value, not the ignored file.
487
486
  //
488
- // Not in validateConfig: that function is layer-agnostic and is also the
489
- // `config set` write path's check. This rule is about which layer a value
490
- // came from, which only layer resolution knows.
487
+ // Not in validateConfig: that check is the same for every layer and is also
488
+ // used by `config set`. This rule depends on which layer a value came from.
491
489
  if (project?.allowExec === true) {
492
- // Warned even when the user layer already said true. The author's intent —
493
- // grant exec — is never honoured from this file, and silence would let them
494
- // believe it worked and rely on it in a repo where it does not.
490
+ // Warn even when the user layer already said true. The file's setting is
491
+ // never honoured, and without a warning its author might rely on it in a
492
+ // repo where it has no effect.
495
493
  warnings.push(`${locations.project}: allowExec: true is ignored in a project file — a repository cannot grant itself permission to run subprocesses; run "${BIN} trust" to trust this repository`);
496
494
  const { allowExec: _ignored, ...rest } = project;
497
495
  project = rest;
498
496
  }
499
- // Same rule, more strongly: a project-layer `trust` block is dropped
500
- // whole, whatever it holds — a repository must not be able to pre-authorize
501
- // itself or any class of repositories, and even an empty `paths: []` would
502
- // otherwise deep-merge over the user's list and silently narrow it. The
503
- // warning is for a non-empty block only, matching allowExec's silence on
504
- // `false`: an empty block granted nothing worth naming.
497
+ // A stricter version of the same rule: a project-layer `trust` block is
498
+ // dropped whole, whatever it holds. A repository must not pre-authorize
499
+ // itself or any group of repositories. Even an empty `paths: []` would
500
+ // otherwise replace the user's list in the merge. Only a non-empty block is
501
+ // warned about, since an empty one granted nothing.
505
502
  if (project?.trust !== undefined) {
506
503
  if ((project.trust.paths?.length ?? 0) > 0 || (project.trust.owners?.length ?? 0) > 0) {
507
504
  warnings.push(`${locations.project}: trust is ignored in a project file — a repository cannot grant ` +
@@ -528,9 +525,20 @@ export async function loadConfig(root, env = process.env, home = homedir()) {
528
525
  warnings,
529
526
  };
530
527
  }
531
- /** One warning per old waypost name in use, naming the new one. */
528
+ /** The warning for a relative `WAYFINDER_CONFIG` that was ignored, or null. */
529
+ export function envIgnoredWarning(locations) {
530
+ if (locations.userEnvIgnored === null)
531
+ return null;
532
+ const { variable, value } = locations.userEnvIgnored;
533
+ return (`${variable}=${value} is ignored because it is not an absolute path; ` +
534
+ `use an absolute path or ~/. Reading ${locations.user} instead`);
535
+ }
536
+ /** One warning per old waypost name in use, naming the new one, and one for an ignored env path. */
532
537
  function legacyWarnings(locations) {
533
538
  const out = [];
539
+ const ignored = envIgnoredWarning(locations);
540
+ if (ignored !== null)
541
+ out.push(ignored);
534
542
  if (locations.userEnvVar === LEGACY_CONFIG_ENV_VAR) {
535
543
  out.push(`${LEGACY_CONFIG_ENV_VAR} is the old name; set ${CONFIG_ENV_VAR} instead`);
536
544
  }
@@ -560,14 +568,13 @@ export function getConfigValue(config, key) {
560
568
  return cursor;
561
569
  }
562
570
  /**
563
- * Set a dotted path, returning a new document. Non-mutating and creating any
564
- * intermediate objects, so `set` works on an empty file.
571
+ * Set a dotted path, returning a new document. The input is not changed.
572
+ * Missing intermediate objects are created, so `set` works on an empty file.
565
573
  *
566
- * The key must be a known setting and the value must match its type; both throw
567
- * {@link ConfigError} rather than writing something that will fail to load
568
- * next time, as does an existing intermediate value that is not an object. The
569
- * generic return means a raw record edits to a raw record with its unknown keys
570
- * untouched.
574
+ * Throws {@link ConfigError} for an unknown key, a value of the wrong type, or
575
+ * an existing intermediate value that is not an object, rather than writing a
576
+ * file that will fail to load. Given a raw record, it returns a raw record with
577
+ * its unknown keys untouched.
571
578
  */
572
579
  export function setConfigValue(config, key, value) {
573
580
  if (!(key in FIELDS)) {
@@ -581,8 +588,8 @@ export function setConfigValue(config, key, value) {
581
588
  for (const segment of segments.slice(0, -1)) {
582
589
  walked = walked === '' ? segment : `${walked}.${segment}`;
583
590
  const existing = cursor[segment];
584
- // A container of the wrong type is a broken file, not a slot to overwrite:
585
- // silently replacing it would delete whatever the user meant by it.
591
+ // A container of the wrong type means the file is broken. Replacing it
592
+ // would silently delete whatever the user meant by it.
586
593
  if (existing !== undefined && !isPlainObject(existing)) {
587
594
  throw new ConfigError(`cannot set ${key}: ${walked} is ${describe(existing)}, not an object`, '');
588
595
  }
@@ -598,8 +605,8 @@ export function setConfigValue(config, key, value) {
598
605
  * removal is removed too, so unsetting the last `runners.*` key does not leave
599
606
  * `"runners": {}` behind.
600
607
  *
601
- * Unlike `set`, any key may be unset — including one this version does not know
602
- * — because removing a stale setting is exactly when you need that.
608
+ * Unlike `set`, any key may be unset, including one this version does not
609
+ * know, so a stale setting can be removed.
603
610
  */
604
611
  export function unsetConfigValue(config, key) {
605
612
  const segments = key.split('.');
@@ -624,9 +631,9 @@ export function unsetConfigValue(config, key) {
624
631
  return out;
625
632
  }
626
633
  /**
627
- * Parse a value typed on a command line. JSON first, so `true`, `3` and
628
- * `["a","b"]` arrive as themselves; a bare word that is not valid JSON falls
629
- * back to the string, so `moon` does not have to be typed as `"moon"`.
634
+ * Parse a value typed on a command line. It is parsed as JSON first, so
635
+ * `true`, `3` and `["a","b"]` keep their types. A bare word that is not valid
636
+ * JSON is kept as a string, so `moon` need not be typed as `"moon"`.
630
637
  */
631
638
  export function parseConfigValue(raw) {
632
639
  try {
@@ -637,8 +644,8 @@ export function parseConfigValue(raw) {
637
644
  }
638
645
  }
639
646
  /**
640
- * The {@link WayOptions} slice this configuration owns. Only keys the config
641
- * sets are present, so a caller spreads its own flags after it.
647
+ * The {@link WayOptions} fields this configuration controls. Only keys the
648
+ * config sets are present, so a caller spreads its own flags after it.
642
649
  */
643
650
  export function collectOptionsFromConfig(config) {
644
651
  const options = {};
@@ -658,14 +665,14 @@ export function trustPolicyFromConfig(config) {
658
665
  return { paths: config.trust?.paths ?? [], owners: config.trust?.owners ?? [] };
659
666
  }
660
667
  /**
661
- * Expand a `trust.paths` entry's leading `~` against `home`, then
662
- * symlink-resolve the pattern's static prefix — the part before the first
663
- * glob character — through `resolveTrustRoot`.
668
+ * Expand a `trust.paths` entry's leading `~` against `home`, then resolve
669
+ * symlinks in the pattern's static prefix (the part before the first glob
670
+ * character) with `resolveTrustRoot`.
664
671
  *
665
- * The injected `expandPath` `policyExecGate`/`policyDecision` take. Without it, a pattern written against the spelling a person typed
666
- * (`/tmp/…`, which on macOS is really `/private/tmp/…`) would silently never
667
- * match the RESOLVED root `@osdlc/trust-repo`'s `policyDecision` compares it
668
- * against.
672
+ * This is the `expandPath` that `policyExecGate` and `policyDecision` take.
673
+ * Without it, a pattern written as a person typed it (`/tmp/…`, which on macOS
674
+ * is really `/private/tmp/…`) would never match the resolved root that
675
+ * `policyDecision` compares it with.
669
676
  */
670
677
  export async function expandTrustPath(raw, home) {
671
678
  const abs = resolve(expandTilde(raw, home));
@@ -678,9 +685,9 @@ export async function expandTrustPath(raw, home) {
678
685
  }
679
686
  /**
680
687
  * The options every `@osdlc/trust-repo` gate call takes: {@link expandTrustPath}
681
- * against `home`, and the git-backed {@link originOwner} lookup `trust.owners`
682
- * rests on. One home for the binding, so a call site cannot leave `ownerOf` out
683
- * and silently stop honouring `trust.owners`.
688
+ * against `home`, and the {@link originOwner} lookup that `trust.owners` needs.
689
+ * Built in one place, so a call site cannot leave out `ownerOf` and silently
690
+ * stop honouring `trust.owners`.
684
691
  */
685
692
  export function trustPolicyOptions(home) {
686
693
  return { expandPath: (raw) => expandTrustPath(raw, home), ownerOf: originOwner };
@@ -688,7 +695,7 @@ export function trustPolicyOptions(home) {
688
695
  /**
689
696
  * Sort runner-keyed items for display: the ids named in `order` first, in that
690
697
  * order, then everything else alphabetically. Alphabetical rather than
691
- * registry order, so adding a tool does not reshuffle the list.
698
+ * registry order, so adding a tool does not reorder the list.
692
699
  */
693
700
  export function orderRunners(items, order) {
694
701
  const rank = new Map((order ?? []).map((id, index) => [id, index]));
package/dist/devlink.d.ts CHANGED
@@ -2,8 +2,12 @@
2
2
  * The devlink spec: what `@osdlc/cli-tool/devlink` needs to recognise a
3
3
  * wayfinder checkout, run it, and put `way` on PATH.
4
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.
5
+ * A checkout has the source entry and a `package.json` named
6
+ * `@osdlc/wayfinder`. The installed package ships `dist/` alone, so it never
7
+ * counts. A selected checkout runs its source under Bun.
8
+ *
9
+ * The cwd layer stays off. Only `WAY_HOME` or `way dev link` hand off to a
10
+ * checkout, so standing in a repository never runs that repository's code.
7
11
  */
8
12
  import { type ToolSpec } from '@osdlc/cli-tool/devlink';
9
13
  export declare const WAYFINDER_SPEC: ToolSpec;
package/dist/devlink.js CHANGED
@@ -2,8 +2,12 @@
2
2
  * The devlink spec: what `@osdlc/cli-tool/devlink` needs to recognise a
3
3
  * wayfinder checkout, run it, and put `way` on PATH.
4
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.
5
+ * A checkout has the source entry and a `package.json` named
6
+ * `@osdlc/wayfinder`. The installed package ships `dist/` alone, so it never
7
+ * counts. A selected checkout runs its source under Bun.
8
+ *
9
+ * The cwd layer stays off. Only `WAY_HOME` or `way dev link` hand off to a
10
+ * checkout, so standing in a repository never runs that repository's code.
7
11
  */
8
12
  import { existsSync } from 'node:fs';
9
13
  import { resolve } from 'node:path';
@@ -15,6 +19,7 @@ const MARKER = 'src/cli.ts';
15
19
  export const WAYFINDER_SPEC = validateSpec({
16
20
  name: BIN,
17
21
  marker: MARKER,
22
+ packageName: '@osdlc/wayfinder',
18
23
  entry: MARKER,
19
24
  launcher: 'bin/way.js',
20
25
  aliases: [APP],
package/dist/guide.js CHANGED
@@ -150,12 +150,12 @@ Layers, lowest precedence first:
150
150
  Files. The project file is \`${PROJECT_CONFIG_FILENAME}\` at the project root, the
151
151
  root this tool resolved, not the working directory. The user file is
152
152
  \`$XDG_CONFIG_HOME/${APP}/config.json\`, or \`~/.config/${APP}/config.json\` when
153
- that variable is unset.
153
+ that variable is unset or relative.
154
154
 
155
155
  \`${CONFIG_ENV_VAR}\` replaces the USER file's location and nothing else. It does
156
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.
157
+ with a tilde, which is expanded. A relative path is ignored with a warning,
158
+ because from the project root it would name a file in the repository.
159
159
 
160
160
  Old names. The tool was called ${LEGACY_APP} before its first release.
161
161
  \`${LEGACY_CONFIG_ENV_VAR}\`, \`$XDG_CONFIG_HOME/${LEGACY_APP}/config.json\` and
@@ -301,7 +301,8 @@ this root, \`--list\` prints every trusted path. \`-C PATH\` reaches all of them
301
301
 
302
302
  A root can also be trusted with no marker, by a trust block in the USER
303
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.
304
+ (the \`origin\` remote's \`host/owner\`; a bare owner means github.com), decided in
305
+ that order after the marker.
305
306
  \`--show\` and \`--json\` name which layer decided (\`by\`:
306
307
  \`marker\`/\`path\`/\`owner\`, plus the matching \`rule\` for a policy hit).
307
308
  `;
@@ -2,13 +2,18 @@
2
2
  * The git-backed `ownerOf` handed to `@osdlc/trust-repo`, which knows no git.
3
3
  * Without it `trust.owners` never matches.
4
4
  */
5
+ import { type CommandRunner } from '@osdlc/command-seam';
5
6
  /**
6
- * `root`'s `origin` remote owner, or null when there is none we can read.
7
+ * `root`'s `origin` remote host and owner as `host/owner`
8
+ * (`github.com/acme`), or null when there is none we can read. The host is
9
+ * part of the answer because the same owner name on another host is another
10
+ * account.
7
11
  * Git runs in `root` with the caller's git location and config variables
8
12
  * removed, so they cannot point it at another repository. Git still searches
9
13
  * upward from `root`, so a directory without its own `.git` inside a
10
14
  * repository gets that repository's owner. A remote that is neither a URL nor
11
15
  * scp-style is a local path (`owner/repo` is one) and has no owner. A host
12
16
  * hosted-git-info does not know (a self-hosted server) has no owner either.
17
+ * `git` is for tests; it defaults to the real binary.
13
18
  */
14
- export declare function originOwner(root: string): string | null;
19
+ export declare function originOwner(root: string, git?: CommandRunner): string | null;