@osdlc/wayfinder 0.7.1 → 0.7.3

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.
@@ -2,7 +2,19 @@
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 { spawnRunner } from '@osdlc/command-seam';
5
6
  import { Git, parseGitUrl } from '@osdlc/typed-git';
7
+ /**
8
+ * `git` with `core.fsmonitor` off. The lookup runs before the repository is
9
+ * trusted, and `.git/config` belongs to whoever made the directory.
10
+ * `remote get-url` does not run fsmonitor today; the flag keeps it that way.
11
+ */
12
+ function safeGit(git) {
13
+ return {
14
+ binary: 'git',
15
+ run: (argv, opts) => git.run(['-c', 'core.fsmonitor=false', ...argv], opts),
16
+ };
17
+ }
6
18
  /**
7
19
  * Git variables the caller's environment must not apply to the owner lookup:
8
20
  * they point git at another repository or add config that rewrites the
@@ -48,16 +60,20 @@ const SCP_REMOTE = /^(?:[^@/:\s]+@)?[^@/:\s]+:(?!\/\/)/;
48
60
  */
49
61
  const SHORTCUT_REMOTE = /^(?:github|gitlab|bitbucket|gist|sourcehut):/;
50
62
  /**
51
- * `root`'s `origin` remote owner, or null when there is none we can read.
63
+ * `root`'s `origin` remote host and owner as `host/owner`
64
+ * (`github.com/acme`), or null when there is none we can read. The host is
65
+ * part of the answer because the same owner name on another host is another
66
+ * account.
52
67
  * Git runs in `root` with the caller's git location and config variables
53
68
  * removed, so they cannot point it at another repository. Git still searches
54
69
  * upward from `root`, so a directory without its own `.git` inside a
55
70
  * repository gets that repository's owner. A remote that is neither a URL nor
56
71
  * scp-style is a local path (`owner/repo` is one) and has no owner. A host
57
72
  * hosted-git-info does not know (a self-hosted server) has no owner either.
73
+ * `git` is for tests; it defaults to the real binary.
58
74
  */
59
- export function originOwner(root) {
60
- const res = withoutGitOverrides(() => new Git(root).try.remoteGetUrl('origin'));
75
+ export function originOwner(root, git = spawnRunner('git', { absolutePathOnly: true })) {
76
+ const res = withoutGitOverrides(() => new Git(root, { runner: safeGit(git) }).try.remoteGetUrl('origin'));
61
77
  if (!res.ok || res.value === null)
62
78
  return null;
63
79
  if (SHORTCUT_REMOTE.test(res.value))
@@ -65,5 +81,5 @@ export function originOwner(root) {
65
81
  if (!URL_REMOTE.test(res.value) && !SCP_REMOTE.test(res.value))
66
82
  return null;
67
83
  const info = parseGitUrl(res.value);
68
- return info?.user && info.project ? info.user : null;
84
+ return info?.user && info.project ? `${info.domain}/${info.user}` : null;
69
85
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * `way providers`: every registered tool, built-in or loaded from a module,
3
3
  * with its roles, its runner kind, its binary and whether that binary is on
4
- * the PATH. Reads files only; runs nothing.
4
+ * an absolute PATH entry. Reads files only; runs nothing.
5
5
  */
6
6
  import { type CliIo } from '@osdlc/cli-tool';
7
7
  import type { Project, RoleName, ToolDef } from '@osdlc/system-model/detect';
@@ -1,15 +1,14 @@
1
1
  /**
2
2
  * `way providers`: every registered tool, built-in or loaded from a module,
3
3
  * with its roles, its runner kind, its binary and whether that binary is on
4
- * the PATH. Reads files only; runs nothing.
4
+ * an absolute PATH entry. Reads files only; runs nothing.
5
5
  */
6
- import { accessSync, constants, statSync } from 'node:fs';
7
- import { homedir } from 'node:os';
8
- import { delimiter, join } from 'node:path';
9
6
  import { EXIT } from '@osdlc/cli-tool';
10
- import { policyExecGate } from '@osdlc/trust-repo';
7
+ import { which } from '@osdlc/command-seam';
8
+ import { homeDir, policyExecGate } from '@osdlc/trust-repo';
11
9
  import { APP, BIN } from "./app.js";
12
10
  import { ConfigError, loadConfig, trustPolicyFromConfig, trustPolicyOptions, } from "./config.js";
11
+ import { jsonText, terminalSafe } from "./terminal-text.js";
13
12
  import { appTrustStore } from "./trust-store.js";
14
13
  const ROLE_ORDER = ['runner', 'packageManager', 'toolManager', 'hookManager'];
15
14
  function usage() {
@@ -28,22 +27,10 @@ allowed. kind is the runner
28
27
  role's: parse reads files, exec runs the repository's tools and needs trust.
29
28
  `;
30
29
  }
30
+ /** Found on an absolute PATH entry, as detection finds a binary. */
31
31
  function onPath(binary, env) {
32
- for (const dir of (env['PATH'] ?? '').split(delimiter)) {
33
- if (dir === '')
34
- continue;
35
- try {
36
- const file = join(dir, binary);
37
- if (!statSync(file).isFile())
38
- continue;
39
- accessSync(file, constants.X_OK);
40
- return true;
41
- }
42
- catch {
43
- // Not here.
44
- }
45
- }
46
- return false;
32
+ const lookup = { absolutePathOnly: true, env: { PATH: env['PATH'], PATHEXT: env['PATHEXT'] } };
33
+ return which(binary, lookup) !== undefined;
47
34
  }
48
35
  /** One row per registered tool, in registry order. */
49
36
  export function providerRows(tools, custom, env) {
@@ -61,6 +48,7 @@ export function providerRows(tools, custom, env) {
61
48
  });
62
49
  }
63
50
  function table(rows) {
51
+ // Tool ids and module paths can come from a project's config.
64
52
  const cells = rows.map((r) => [
65
53
  r.id,
66
54
  r.roles.join(',') || '-',
@@ -68,7 +56,7 @@ function table(rows) {
68
56
  r.binary ?? '-',
69
57
  r.onPath === null ? '-' : r.onPath ? 'yes' : 'no',
70
58
  r.source === 'custom' && r.module !== undefined ? `custom ${r.module}` : r.source,
71
- ]);
59
+ ].map((cell) => terminalSafe(cell)));
72
60
  const head = ['tool', 'roles', 'kind', 'binary', 'on PATH', 'source'];
73
61
  const widths = head.map((h, i) => Math.max(h.length, ...cells.map((c) => c[i].length)));
74
62
  const fmt = (c) => c
@@ -80,7 +68,7 @@ function table(rows) {
80
68
  /** `way providers …`. Returns the exit code. */
81
69
  export async function runProvidersCommand(root, argv, io) {
82
70
  const env = io.env ?? process.env;
83
- const home = io.home ?? homedir();
71
+ const home = io.home ?? homeDir();
84
72
  let json = false;
85
73
  const modules = [];
86
74
  for (let i = 0; i < argv.length; i++) {
@@ -127,6 +115,6 @@ export async function runProvidersCommand(root, argv, io) {
127
115
  for (const warning of built.warnings)
128
116
  io.stderr(`warning: ${warning}\n`);
129
117
  const rows = providerRows(built.project.tools, built.tools, env);
130
- io.stdout(json ? `${JSON.stringify(rows, null, 2)}\n` : table(rows));
118
+ io.stdout(json ? `${jsonText(rows, 2)}\n` : table(rows));
131
119
  return EXIT.ok;
132
120
  }
package/dist/serve.d.ts CHANGED
@@ -1,35 +1,34 @@
1
1
  /**
2
- * The web view — the same catalog as a page you can search in a browser.
2
+ * The web view: the same catalog as a page you can search in a browser.
3
3
  *
4
- * A SERVER rather than a generated file, because a file would be a snapshot:
5
- * add a task and the page is wrong with no signal that it is. Every
6
- * `/api/catalog` request re-probes, and the page re-fetches on focus and on a
7
- * slow poll, so what is on screen is what the repository currently has.
4
+ * It is a server rather than a generated file, because a file goes out of date
5
+ * as soon as a task is added, with no sign that it has. `/api/catalog`
6
+ * re-probes (requests close together share one probe), and the page re-fetches
7
+ * on focus and on a slow poll, so the screen shows what the repository has now.
8
8
  *
9
- * Loopback is not by itself a boundary, so every route is behind a token.
9
+ * Loopback alone does not keep other callers out, so every route needs a token.
10
10
  *
11
11
  * Other local users on this machine can reach 127.0.0.1, and can read a
12
- * process's argv and environment for as long as it runs. So the session token
13
- * never appears in a URL or an argv. What does appear in a URL is the boot
14
- * token, which is single-use and expires in a minute; burning it on first use
15
- * bounds the window to the moment between opening the browser and the page
16
- * loading.
12
+ * process's argv and environment while it runs. So the session token never
13
+ * appears in a URL or an argv. The URL carries the boot token instead. It works
14
+ * once and expires after a minute, so it is only usable between opening the
15
+ * browser and the page loading.
17
16
  *
18
- * Any website the user visits can also issue cross-origin requests to
19
- * 127.0.0.1. A cookie would ride along on those — that is CSRF — while a
20
- * request header does not, and the token header is a non-simple header, so a
21
- * cross-origin fetch must first pass a CORS preflight this server never
22
- * answers. Hence header auth, and hence the boot token is accepted on the page
23
- * routes only, never on the API.
17
+ * Any website the user visits can also send cross-origin requests to
18
+ * 127.0.0.1. A cookie would be sent with those (that is CSRF), but a request
19
+ * header is not. The token header is not a CORS-safelisted header, so a
20
+ * cross-origin fetch must first pass a CORS preflight, which this server never
21
+ * answers. That is why auth uses a header, and why the boot token is accepted
22
+ * on the page routes only, never on the API.
24
23
  *
25
24
  * `/api/run` hands this server's own terminal to a task and exits. It takes a
26
- * task id and nothing else — see the note on the route.
25
+ * task id and nothing else (see the note on the route).
27
26
  *
28
- * `/api/trust` POST permits this repository's code to run from now on, so it is
29
- * gated a third time, beyond the method and the token: the grant must be
30
- * APPLICABLE — the same condition that decides whether the page may offer the
31
- * button at all. Without it a grant would override `--no-exec` or write the
32
- * store under `--exec`. DELETE revokes and carries no such gate.
27
+ * `POST /api/trust` lets this repository's code run from now on, so it has a
28
+ * third check beyond the method and the token: the grant must be applicable.
29
+ * That is the same condition that decides whether the page shows the button.
30
+ * Without it a grant would override `--no-exec` or write the store under
31
+ * `--exec`. DELETE revokes and has no such check.
33
32
  */
34
33
  import { type Catalog, type Project, type RunnerCacheState } from '@osdlc/system-model/detect';
35
34
  import { type WayOptions } from './catalog.ts';
@@ -38,8 +37,9 @@ export interface ServeOptions {
38
37
  /** The registered tools, built-ins plus any loaded. */
39
38
  project: Project;
40
39
  /**
41
- * The project file names tools that were not loaded because the repository is untrusted or execution is off.
42
- * A grant from the page does not load them; the response says so.
40
+ * The project file names tools that were not loaded, because the repository
41
+ * is untrusted or execution is off. A grant from the page does not load them,
42
+ * and the response says so.
43
43
  */
44
44
  projectToolsPending?: boolean | undefined;
45
45
  root: string;
@@ -50,20 +50,18 @@ export interface ServeOptions {
50
50
  runnerOrder?: string[] | undefined;
51
51
  /**
52
52
  * Which `collectOptions` keys came from a command-line flag rather than the
53
- * config file. Saving a setting re-derives the config's slice of the collect
54
- * options in the running process; a key named here is left alone, because a
55
- * flag is the user's most recent explicit instruction about it and a write
56
- * to some other setting must not revoke it.
53
+ * config file. Saving a setting re-reads the config's collect options in the
54
+ * running process. A key named here is left alone, because the flag is the
55
+ * user's latest explicit choice and saving another setting must not undo it.
57
56
  *
58
- * Only the keys `collectOptionsFromConfig` produces are meaningful:
57
+ * Only the keys `collectOptionsFromConfig` returns have an effect:
59
58
  * `exclude`, `discovery`, `excludePaths`.
60
59
  */
61
60
  pinnedByFlag?: readonly string[] | undefined;
62
61
  /**
63
- * The trust store's environment and home, threaded from the CLI. Injectable
64
- * for the reason every sibling in this lane is: a test that let them default
65
- * would grant trust in the developer's own `~/.local/state/wayfinder/`. Nothing but
66
- * a test ever passes them.
62
+ * The trust store's environment and home, passed from the CLI. Injectable so
63
+ * a test does not grant trust in the developer's own
64
+ * `~/.local/state/wayfinder/`. Only tests pass them.
67
65
  */
68
66
  env?: Record<string, string | undefined> | undefined;
69
67
  home?: string | undefined;
@@ -77,21 +75,24 @@ export interface CatalogSnapshot {
77
75
  /**
78
76
  * Bind the port and return the server's handle, without printing or opening anything.
79
77
  *
80
- * Split out of {@link serve} because `serve` never returns — it is the process's
81
- * last statement — and a function that never returns cannot be tested. The
82
- * mutating endpoint is the one part of this file that must not regress silently,
83
- * so it needs a caller that can bind an ephemeral port, drive real requests and
84
- * stop again.
78
+ * Split out of {@link serve} because `serve` never returns, and a function
79
+ * that never returns cannot be tested. Tests need to bind an ephemeral port,
80
+ * send real requests to the endpoints that write, and stop again.
85
81
  *
86
- * The catalog source comes back with the handle because it is the server's, not
87
- * a second one: the startup banner must report the probe the page will see.
82
+ * The catalog source is returned with the handle, so the startup banner
83
+ * reports the same probe the page will see.
88
84
  */
89
85
  export declare function startServer(options: ServeOptions): Promise<{
90
86
  server: FetchServer;
91
87
  catalog: (force: boolean) => Promise<CatalogSnapshot>;
92
88
  /** The one-shot token that signs a browser in; spent on first use. */
93
89
  bootToken: string;
94
- /** Starts the boot token's expiry window — call when the URL is handed over. */
90
+ /** Starts the boot token's expiry timer. Call it when the URL is shown to the user. */
95
91
  armBoot: () => void;
96
92
  }>;
93
+ /**
94
+ * The first lines `--serve` prints: the address, the root, what was collected
95
+ * and what came from the cache. Repository text in them is terminal-safe.
96
+ */
97
+ export declare function startupSummary(address: string, first: CatalogSnapshot): string;
97
98
  export declare function serve(options: ServeOptions): Promise<number>;