@osdlc/wayfinder 0.7.4 → 0.9.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.
Files changed (121) hide show
  1. package/CHANGELOG.md +240 -0
  2. package/CONTRIBUTING.md +6 -0
  3. package/README.md +310 -150
  4. package/SECURITY.md +19 -5
  5. package/dist/actions.d.ts +23 -0
  6. package/dist/actions.js +97 -0
  7. package/dist/app.d.ts +1 -13
  8. package/dist/app.js +1 -13
  9. package/dist/args.d.ts +11 -6
  10. package/dist/args.js +25 -7
  11. package/dist/cache.d.ts +2 -4
  12. package/dist/cache.js +5 -10
  13. package/dist/catalog.d.ts +45 -4
  14. package/dist/catalog.js +134 -13
  15. package/dist/clean-command.d.ts +65 -36
  16. package/dist/clean-command.js +372 -226
  17. package/dist/cli.d.ts +24 -57
  18. package/dist/cli.js +139 -568
  19. package/dist/commands/browse.d.ts +128 -0
  20. package/dist/commands/browse.js +153 -0
  21. package/dist/commands/index.d.ts +25 -0
  22. package/dist/commands/index.js +71 -0
  23. package/dist/commands/list.d.ts +224 -0
  24. package/dist/commands/list.js +178 -0
  25. package/dist/commands/query.d.ts +166 -0
  26. package/dist/commands/query.js +73 -0
  27. package/dist/commands/run.d.ts +114 -0
  28. package/dist/commands/run.js +139 -0
  29. package/dist/commands/shared.d.ts +152 -0
  30. package/dist/commands/shared.js +209 -0
  31. package/dist/config-command.d.ts +27 -43
  32. package/dist/config-command.js +129 -330
  33. package/dist/config-keys.d.ts +25 -0
  34. package/dist/config-keys.js +29 -0
  35. package/dist/config.d.ts +272 -257
  36. package/dist/config.js +611 -460
  37. package/dist/core/copy-text.d.ts +30 -0
  38. package/dist/core/copy-text.js +50 -0
  39. package/dist/core/filter.d.ts +55 -0
  40. package/dist/core/filter.js +59 -0
  41. package/dist/core/run.d.ts +22 -0
  42. package/dist/core/run.js +59 -0
  43. package/dist/core/saved-view.d.ts +59 -0
  44. package/dist/core/saved-view.js +119 -0
  45. package/dist/core/session.d.ts +282 -0
  46. package/dist/core/session.js +602 -0
  47. package/dist/core/skills.d.ts +53 -0
  48. package/dist/core/skills.js +54 -0
  49. package/dist/core/unknowns.d.ts +72 -0
  50. package/dist/core/unknowns.js +68 -0
  51. package/dist/devlink.d.ts +3 -0
  52. package/dist/devlink.js +5 -2
  53. package/dist/document-schemas.generated.d.ts +22 -0
  54. package/dist/document-schemas.generated.js +916 -0
  55. package/dist/documents.d.ts +508 -0
  56. package/dist/documents.js +181 -0
  57. package/dist/groups.d.ts +22 -26
  58. package/dist/groups.js +13 -29
  59. package/dist/guide.d.ts +26 -13
  60. package/dist/guide.js +119 -103
  61. package/dist/index.d.ts +118 -0
  62. package/dist/index.js +61 -0
  63. package/dist/keys.d.ts +51 -0
  64. package/dist/keys.js +273 -0
  65. package/dist/page.d.ts +18 -8
  66. package/dist/page.js +28 -17
  67. package/dist/providers-command.d.ts +81 -20
  68. package/dist/providers-command.js +33 -75
  69. package/dist/schema.d.ts +48 -0
  70. package/dist/schema.js +61 -0
  71. package/dist/serve/auth.d.ts +46 -0
  72. package/dist/serve/auth.js +82 -0
  73. package/dist/serve/catalog-share.d.ts +63 -0
  74. package/dist/serve/catalog-share.js +155 -0
  75. package/dist/serve/index.d.ts +100 -0
  76. package/dist/serve/index.js +259 -0
  77. package/dist/serve/routes.d.ts +60 -0
  78. package/dist/serve/routes.js +186 -0
  79. package/dist/serve/terminal-input.d.ts +50 -0
  80. package/dist/serve/terminal-input.js +108 -0
  81. package/dist/skills.d.ts +19 -0
  82. package/dist/skills.js +54 -0
  83. package/dist/terminal-text.d.ts +8 -0
  84. package/dist/terminal-text.js +19 -6
  85. package/dist/tool-info.d.ts +24 -0
  86. package/dist/tool-info.js +17 -0
  87. package/dist/trust-command.d.ts +15 -27
  88. package/dist/trust-command.js +110 -208
  89. package/dist/trust-store.d.ts +5 -10
  90. package/dist/trust-store.js +9 -42
  91. package/dist/tui/app.d.ts +193 -0
  92. package/dist/tui/app.js +1400 -0
  93. package/dist/tui/copy.d.ts +29 -0
  94. package/dist/tui/copy.js +39 -0
  95. package/dist/tui/index.d.ts +33 -0
  96. package/dist/tui/index.js +97 -0
  97. package/dist/tui/keys-input.d.ts +27 -0
  98. package/dist/tui/keys-input.js +87 -0
  99. package/dist/tui/settings.d.ts +94 -0
  100. package/dist/tui/settings.js +198 -0
  101. package/dist/tui/style.d.ts +62 -0
  102. package/dist/tui/style.js +77 -0
  103. package/dist/version.d.ts +6 -0
  104. package/dist/version.js +7 -0
  105. package/dist/vocabulary.d.ts +91 -0
  106. package/dist/vocabulary.js +155 -0
  107. package/dist/web/main.js +2232 -582
  108. package/dist/web/page.html +41 -33
  109. package/dist/web/styles.css +513 -329
  110. package/dist/xdg.d.ts +76 -4
  111. package/dist/xdg.js +77 -5
  112. package/package.json +27 -8
  113. package/schema/config.json +133 -0
  114. package/dist/http.d.ts +0 -22
  115. package/dist/http.js +0 -149
  116. package/dist/origin-owner.d.ts +0 -19
  117. package/dist/origin-owner.js +0 -85
  118. package/dist/serve.d.ts +0 -98
  119. package/dist/serve.js +0 -671
  120. package/dist/tui.d.ts +0 -177
  121. package/dist/tui.js +0 -840
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * `@osdlc/wayfinder`: build the catalog `way` shows, from code. The answer is
3
+ * the document `way list --json` prints: the runner reports with their
4
+ * tasks, the groups, the agent skills, the cache verdicts and what could not
5
+ * be read.
6
+ *
7
+ * Detection is `@osdlc/system-model`'s. This entry adds what wayfinder layers
8
+ * on top: configuration, trust, the probe store, groups and skills. It runs
9
+ * on Node; it is not for a browser.
10
+ *
11
+ * The exported names follow semver from 1.0. Before 1.0 a minor release may
12
+ * change them, and the changelog says how.
13
+ */
14
+ import { catalogDocument } from "./commands/list.js";
15
+ import { flushViews } from "./core/saved-view.js";
16
+ import { createSession, } from "./core/session.js";
17
+ import { CATALOG_DOCUMENT_VERSION } from "./documents.js";
18
+ export { SessionError, } from "./core/session.js";
19
+ export { filterTasks, hasQuery, keepsTask, sourceDepth } from "./core/filter.js";
20
+ export { filterSkills, skillLine, SKILLS_SETTING_VALUES } from "./core/skills.js";
21
+ export { unknownLine, unknownsOf } from "./core/unknowns.js";
22
+ export { GROUPS, SKILLS_GROUP, catalogGroups, documentGroups, groupOf, } from "./groups.js";
23
+ export { jsonText, terminalSafe } from "./terminal-text.js";
24
+ export { toolSummary } from "./tool-info.js";
25
+ export { ANY_LANGUAGE, languageLabel, runnerLabel, withheldLabel } from "./vocabulary.js";
26
+ // Fails to compile when CatalogDocument and the document schema name different fields.
27
+ const catalogFieldsMatch = true;
28
+ void catalogFieldsMatch;
29
+ /**
30
+ * The catalog for `dir`, as `way list --json` builds it: the same config,
31
+ * trust gate and probe store. Nothing in the repository runs unless the
32
+ * repository (or the tool) is trusted and execution is allowed. A probe
33
+ * writes the store, as `way list` does.
34
+ *
35
+ * Throws {@link SessionError}: `no-such-directory`, `config` for a config
36
+ * file that cannot be used, `tool-module` for a tool module that cannot be
37
+ * loaded.
38
+ *
39
+ * Task names, skill text and other strings come from the repository. Pass
40
+ * them through {@link terminalSafe} before printing them to a terminal.
41
+ */
42
+ export async function buildCatalog(options) {
43
+ const session = await createSession({
44
+ dir: options.dir,
45
+ cwd: options.cwd ?? process.cwd(),
46
+ env: options.env ?? process.env,
47
+ home: options.home,
48
+ flags: options.flags,
49
+ signal: options.signal,
50
+ });
51
+ for (const warning of session.warnings)
52
+ options.onWarning?.(warning);
53
+ const snapshot = await session.catalog({
54
+ cached: options.cached === true,
55
+ progress: options.progress,
56
+ });
57
+ // A library caller gets a call whose writes are done.
58
+ await flushViews();
59
+ const body = catalogDocument(snapshot, session.unknowns(snapshot), options.filter ?? {}, session.settings().trustedTools);
60
+ return { schemaVersion: CATALOG_DOCUMENT_VERSION, kind: 'catalog', ...body };
61
+ }
package/dist/keys.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Every key the terminal UI and the web view answer, in one table. The
3
+ * terminal UI's footer and `?` screen, the web view's key help and the
4
+ * `browse` command's help all read it, so a key is described in one place.
5
+ *
6
+ * The table describes keys; it does not dispatch them. Each surface maps the
7
+ * bytes or `KeyboardEvent`s it receives itself.
8
+ *
9
+ * Browser-safe: no Node built-in, so the page imports it.
10
+ */
11
+ /** The surface a key works on. */
12
+ export type KeySurface = 'tui' | 'web';
13
+ /**
14
+ * The view a key works in. The terminal UI has `list`, `arguments` (the
15
+ * entry line for a task's arguments), `settings` and `help`. The web view has
16
+ * `list` and `arguments` (the run bar).
17
+ */
18
+ export type KeyView = 'list' | 'arguments' | 'settings' | 'help';
19
+ /** One key, or a set of keys that do one thing. */
20
+ export interface KeyBinding {
21
+ surface: KeySurface;
22
+ view: KeyView;
23
+ /** The keys as a person reads them: `enter`, `^y`, `shift+tab`. */
24
+ keys: readonly string[];
25
+ /** What it does, for a help screen. */
26
+ action: string;
27
+ /** The footer's short form, such as `^y copy`. Absent: help only. */
28
+ hint?: string | undefined;
29
+ /** The footer's form while a skill row is selected, when the key does something else there. */
30
+ skillHint?: string | undefined;
31
+ /** The footer shows it at every width. */
32
+ always?: boolean | undefined;
33
+ /** When the footer is short of room it drops the highest rank first. */
34
+ rank?: number | undefined;
35
+ }
36
+ /** The table. Within a view, in the order a help screen lists them. */
37
+ export declare const KEY_TABLE: readonly KeyBinding[];
38
+ /** The keys of one view on one surface, in table order. */
39
+ export declare function keysFor(surface: KeySurface, view: KeyView): KeyBinding[];
40
+ /**
41
+ * The footer for `bindings` in at most `width` columns: every hint marked
42
+ * `always`, then the others by rank while they fit, shown in table order and
43
+ * joined by `separator`. A hint is plain ASCII or one column per character,
44
+ * so its length is its width.
45
+ */
46
+ export declare function footerHints(bindings: readonly KeyBinding[], width: number, separator?: string, row?: 'task' | 'skill'): string;
47
+ /**
48
+ * The keys of one view as aligned text lines, ` enter run the selected
49
+ * task`, for a help screen or `--help`.
50
+ */
51
+ export declare function keyLines(surface: KeySurface, view: KeyView, indent?: string): string[];
package/dist/keys.js ADDED
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Every key the terminal UI and the web view answer, in one table. The
3
+ * terminal UI's footer and `?` screen, the web view's key help and the
4
+ * `browse` command's help all read it, so a key is described in one place.
5
+ *
6
+ * The table describes keys; it does not dispatch them. Each surface maps the
7
+ * bytes or `KeyboardEvent`s it receives itself.
8
+ *
9
+ * Browser-safe: no Node built-in, so the page imports it.
10
+ */
11
+ /** The table. Within a view, in the order a help screen lists them. */
12
+ export const KEY_TABLE = Object.freeze([
13
+ // The terminal UI's list.
14
+ { surface: 'tui', view: 'list', keys: ['type'], action: 'narrow the list' },
15
+ {
16
+ surface: 'tui',
17
+ view: 'list',
18
+ keys: ['enter'],
19
+ action: 'run the task, asking for arguments first; copy a skill',
20
+ hint: 'enter run',
21
+ skillHint: 'enter copy /name',
22
+ rank: 1,
23
+ },
24
+ {
25
+ surface: 'tui',
26
+ view: 'list',
27
+ keys: ['^y'],
28
+ action: "copy the selected task's command line, or a skill's /name",
29
+ hint: '^y copy',
30
+ rank: 2,
31
+ },
32
+ {
33
+ surface: 'tui',
34
+ view: 'list',
35
+ keys: ['tab', 'shift+tab'],
36
+ action: 'next / previous tab: all, each runner, skills',
37
+ hint: 'tab runner',
38
+ rank: 3,
39
+ },
40
+ {
41
+ surface: 'tui',
42
+ view: 'list',
43
+ keys: [','],
44
+ action: 'settings: runners, discovery, excluded paths and trust',
45
+ hint: ', settings',
46
+ rank: 4,
47
+ },
48
+ {
49
+ surface: 'tui',
50
+ view: 'list',
51
+ keys: ['^s'],
52
+ action: 'trust this repository, after a y/n question',
53
+ hint: '^s trust',
54
+ rank: 5,
55
+ },
56
+ {
57
+ surface: 'tui',
58
+ view: 'list',
59
+ keys: ['^r'],
60
+ action: 'refresh: probe the repository again',
61
+ hint: '^r refresh',
62
+ rank: 6,
63
+ },
64
+ {
65
+ surface: 'tui',
66
+ view: 'list',
67
+ keys: ['^t'],
68
+ action: 'only services: tasks that run until you stop them',
69
+ hint: '^t services',
70
+ rank: 7,
71
+ },
72
+ {
73
+ surface: 'tui',
74
+ view: 'list',
75
+ keys: ['^e'],
76
+ action: 'exact search instead of fuzzy',
77
+ hint: '^e exact',
78
+ rank: 8,
79
+ },
80
+ {
81
+ surface: 'tui',
82
+ view: 'list',
83
+ keys: ['^d'],
84
+ action: 'only tasks a file declares, not inferred ones',
85
+ hint: '^d declared',
86
+ rank: 9,
87
+ },
88
+ {
89
+ surface: 'tui',
90
+ view: 'list',
91
+ keys: ['^o'],
92
+ action: 'scope: all, the root only, or at most 2 or 3 levels down',
93
+ hint: '^o scope',
94
+ rank: 10,
95
+ },
96
+ { surface: 'tui', view: 'list', keys: ['↑', '↓', '^p', '^n'], action: 'move by one row' },
97
+ { surface: 'tui', view: 'list', keys: ['pgup', 'pgdn'], action: 'move by a screenful' },
98
+ { surface: 'tui', view: 'list', keys: ['home', 'end', '^a'], action: 'first / last row' },
99
+ {
100
+ surface: 'tui',
101
+ view: 'list',
102
+ keys: ['backspace', '^u'],
103
+ action: 'delete a character / clear the query',
104
+ },
105
+ {
106
+ surface: 'tui',
107
+ view: 'list',
108
+ keys: ['?'],
109
+ action: 'this list of keys',
110
+ hint: '? help',
111
+ always: true,
112
+ },
113
+ {
114
+ surface: 'tui',
115
+ view: 'list',
116
+ keys: ['esc', '^c'],
117
+ action: 'quit, stopping any probe that is running',
118
+ hint: 'esc quit',
119
+ always: true,
120
+ },
121
+ // The terminal UI's entry line for arguments.
122
+ {
123
+ surface: 'tui',
124
+ view: 'arguments',
125
+ keys: ['type'],
126
+ action: 'the arguments; quotes group words as in sh',
127
+ },
128
+ {
129
+ surface: 'tui',
130
+ view: 'arguments',
131
+ keys: ['enter'],
132
+ action: 'run with what you typed, which may be nothing',
133
+ hint: 'enter run',
134
+ always: true,
135
+ },
136
+ {
137
+ surface: 'tui',
138
+ view: 'arguments',
139
+ keys: ['backspace', '^u'],
140
+ action: 'delete a character / clear the line',
141
+ },
142
+ {
143
+ surface: 'tui',
144
+ view: 'arguments',
145
+ keys: ['esc'],
146
+ action: 'back to the list; nothing runs',
147
+ hint: 'esc back',
148
+ always: true,
149
+ },
150
+ // The terminal UI's settings screen.
151
+ { surface: 'tui', view: 'settings', keys: ['↑', '↓'], action: 'move between settings' },
152
+ { surface: 'tui', view: 'settings', keys: ['pgup', 'pgdn'], action: 'move by a screenful' },
153
+ {
154
+ surface: 'tui',
155
+ view: 'settings',
156
+ keys: ['space', 'enter'],
157
+ action: 'turn a runner on or off, or change discovery',
158
+ hint: 'space change',
159
+ rank: 1,
160
+ },
161
+ {
162
+ surface: 'tui',
163
+ view: 'settings',
164
+ keys: ['[', ']'],
165
+ action: 'move a runner earlier / later in the order',
166
+ hint: '[ ] order',
167
+ rank: 3,
168
+ },
169
+ {
170
+ surface: 'tui',
171
+ view: 'settings',
172
+ keys: ['a'],
173
+ action: 'add an excluded path',
174
+ hint: 'a add path',
175
+ rank: 2,
176
+ },
177
+ {
178
+ surface: 'tui',
179
+ view: 'settings',
180
+ keys: ['x'],
181
+ action: 'remove the selected excluded path',
182
+ hint: 'x remove',
183
+ rank: 4,
184
+ },
185
+ {
186
+ surface: 'tui',
187
+ view: 'settings',
188
+ keys: ['t', 'u'],
189
+ action: 'trust the repository or the selected tool (after a y/n question) / remove it',
190
+ hint: 't/u trust',
191
+ rank: 5,
192
+ },
193
+ { surface: 'tui', view: 'settings', keys: ['?'], action: 'the list of keys', hint: '? help' },
194
+ {
195
+ surface: 'tui',
196
+ view: 'settings',
197
+ keys: ['esc', ','],
198
+ action: 'back to the list',
199
+ hint: 'esc back',
200
+ always: true,
201
+ },
202
+ // The terminal UI's help screen.
203
+ { surface: 'tui', view: 'help', keys: ['↑', '↓', 'pgup', 'pgdn'], action: 'scroll' },
204
+ {
205
+ surface: 'tui',
206
+ view: 'help',
207
+ keys: ['esc', '?'],
208
+ action: 'close this screen',
209
+ hint: 'esc back',
210
+ always: true,
211
+ },
212
+ // The web view.
213
+ { surface: 'web', view: 'list', keys: ['/'], action: 'search' },
214
+ {
215
+ surface: 'web',
216
+ view: 'list',
217
+ keys: ['enter'],
218
+ action: 'copy the top hit, or the focused task',
219
+ },
220
+ {
221
+ surface: 'web',
222
+ view: 'list',
223
+ keys: ['shift+enter'],
224
+ action: 'run the top hit, or the focused task',
225
+ },
226
+ { surface: 'web', view: 'list', keys: ['↑', '↓'], action: 'move through the tasks' },
227
+ { surface: 'web', view: 'list', keys: ['esc'], action: 'back to search; again to clear it' },
228
+ { surface: 'web', view: 'list', keys: ['?'], action: 'this help' },
229
+ { surface: 'web', view: 'arguments', keys: ['enter'], action: 'run with what you typed' },
230
+ { surface: 'web', view: 'arguments', keys: ['esc'], action: 'close the run bar; nothing runs' },
231
+ ]);
232
+ /** The keys of one view on one surface, in table order. */
233
+ export function keysFor(surface, view) {
234
+ return KEY_TABLE.filter((k) => k.surface === surface && k.view === view);
235
+ }
236
+ /**
237
+ * The footer for `bindings` in at most `width` columns: every hint marked
238
+ * `always`, then the others by rank while they fit, shown in table order and
239
+ * joined by `separator`. A hint is plain ASCII or one column per character,
240
+ * so its length is its width.
241
+ */
242
+ export function footerHints(bindings, width, separator = ' ', row = 'task') {
243
+ const hinted = bindings
244
+ .filter((k) => k.hint !== undefined)
245
+ .map((k) => (row === 'skill' && k.skillHint !== undefined ? { ...k, hint: k.skillHint } : k));
246
+ const kept = new Set(hinted.filter((k) => k.always === true));
247
+ const widthOf = (set) => [...set].reduce((n, k) => n + k.hint.length, 0) + Math.max(0, set.size - 1) * separator.length;
248
+ const optional = hinted
249
+ .filter((k) => k.always !== true)
250
+ .sort((a, b) => (a.rank ?? Infinity) - (b.rank ?? Infinity));
251
+ for (const k of optional) {
252
+ kept.add(k);
253
+ if (widthOf(kept) > width)
254
+ kept.delete(k);
255
+ }
256
+ return hinted
257
+ .filter((k) => kept.has(k))
258
+ .map((k) => k.hint)
259
+ .join(separator);
260
+ }
261
+ /** The key names of a binding as one column: `tab, shift+tab`. */
262
+ function keyNames(binding) {
263
+ return binding.keys.join(', ');
264
+ }
265
+ /**
266
+ * The keys of one view as aligned text lines, ` enter run the selected
267
+ * task`, for a help screen or `--help`.
268
+ */
269
+ export function keyLines(surface, view, indent = ' ') {
270
+ const rows = keysFor(surface, view);
271
+ const pad = Math.max(...rows.map((k) => keyNames(k).length));
272
+ return rows.map((k) => `${indent}${keyNames(k).padEnd(pad)} ${k.action}`);
273
+ }
package/dist/page.d.ts CHANGED
@@ -2,14 +2,24 @@
2
2
  * The page builder: assemble `web/` into one self-contained HTML response.
3
3
  *
4
4
  * The web view is authored as parts (a skeleton, a stylesheet, TypeScript
5
- * modules) and served as one document, with no request beyond the catalog
6
- * API. The installed package reads the script the build bundled into
5
+ * modules) and served as one document, with no request beyond the API. The
6
+ * colours come from `@osdlc/ux`'s tokens, as `--wf-*` custom properties. The
7
+ * installed package reads the script the build bundled into
7
8
  * `dist/web/main.js`. A checkout running the source bundles it per request,
8
9
  * so an edit is a browser reload, not a restart.
10
+ *
11
+ * The page holds no secret. It gets its token from `POST /session` (see
12
+ * `serve/auth.ts`).
9
13
  */
10
- /**
11
- * @param sessionToken handed to the page so its fetches can authenticate. It
12
- * is JSON-encoded into an inline script rather than put in a URL or a cookie:
13
- * the page keeps it in module state only.
14
- */
15
- export declare function buildPage(sessionToken: string): Promise<string>;
14
+ import type { Theme } from './config-keys.ts';
15
+ /** What the page is built with. */
16
+ export interface PageOptions {
17
+ /** The `theme` setting. `system` leaves the choice to the browser. */
18
+ theme?: Theme | undefined;
19
+ /** The server's platform, which picks the shell Copy quotes for. Default `process.platform`. */
20
+ platform?: NodeJS.Platform | undefined;
21
+ /** The `nonce` on the script tag, which the page's content security policy names. */
22
+ nonce?: string | undefined;
23
+ }
24
+ /** Build the page. Each replacement is a function, so a `$` in a part is kept as it is. */
25
+ export declare function buildPage(options?: PageOptions): Promise<string>;
package/dist/page.js CHANGED
@@ -2,10 +2,14 @@
2
2
  * The page builder: assemble `web/` into one self-contained HTML response.
3
3
  *
4
4
  * The web view is authored as parts (a skeleton, a stylesheet, TypeScript
5
- * modules) and served as one document, with no request beyond the catalog
6
- * API. The installed package reads the script the build bundled into
5
+ * modules) and served as one document, with no request beyond the API. The
6
+ * colours come from `@osdlc/ux`'s tokens, as `--wf-*` custom properties. The
7
+ * installed package reads the script the build bundled into
7
8
  * `dist/web/main.js`. A checkout running the source bundles it per request,
8
9
  * so an edit is a browser reload, not a restart.
10
+ *
11
+ * The page holds no secret. It gets its token from `POST /session` (see
12
+ * `serve/auth.ts`).
9
13
  */
10
14
  var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
11
15
  if (typeof path === "string" && /^\.\.?\//.test(path)) {
@@ -18,27 +22,34 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
18
22
  import { existsSync } from 'node:fs';
19
23
  import { readFile } from 'node:fs/promises';
20
24
  import { fileURLToPath } from 'node:url';
21
- import { APP } from "./app.js";
25
+ import { cssSheet } from '@osdlc/ux';
26
+ import { APP, BIN } from "./app.js";
22
27
  const DIR = new URL('./web/', import.meta.url);
23
28
  const path = (name) => fileURLToPath(new URL(name, DIR));
24
- /**
25
- * @param sessionToken handed to the page so its fetches can authenticate. It
26
- * is JSON-encoded into an inline script rather than put in a URL or a cookie:
27
- * the page keeps it in module state only.
28
- */
29
- export async function buildPage(sessionToken) {
29
+ /** The custom-property prefix of the page's tokens: `--wf-bg-base`. */
30
+ const TOKEN_PREFIX = 'wf';
31
+ /** Build the page. Each replacement is a function, so a `$` in a part is kept as it is. */
32
+ export async function buildPage(options = {}) {
30
33
  const [skeleton, styles, script] = await Promise.all([
31
34
  readFile(path('page.html'), 'utf8'),
32
35
  readFile(path('styles.css'), 'utf8'),
33
36
  buildScript(),
34
37
  ]);
35
- // `<\/` keeps a token that somehow contained "</script>" from closing the
36
- // tag early; JSON.stringify handles the rest.
37
- const token = JSON.stringify(sessionToken).replaceAll('</', '<\\/');
38
- return skeleton
39
- .replace('<!-- @STYLE@ -->', `<style>\n${styles}</style>`)
40
- .replace('<!-- @TOKEN@ -->', `<script>window.__WAYFINDER_TOKEN__ = ${token};</script>`)
41
- .replace('<!-- @SCRIPT@ -->', `<script type="module">\n${script.replaceAll('</script>', '<\\/script>')}</script>`);
38
+ const theme = options.theme ?? 'system';
39
+ const platform = (options.platform ?? process.platform).replace(/[^a-z0-9]/g, '');
40
+ const nonce = (options.nonce ?? '').replace(/[^A-Za-z0-9+/=]/g, '');
41
+ return (skeleton
42
+ // The template has no <html> tag, which keeps it plain for the
43
+ // formatter. The theme goes on the element so it applies before the
44
+ // first paint.
45
+ .replace('<!doctype html>\n', () => '<!doctype html>\n<html lang="en"' +
46
+ (theme === 'system' ? '' : ` data-theme="${theme}"`) +
47
+ ` data-platform="${platform}"` +
48
+ '>\n')
49
+ .replaceAll('@APP@', () => APP)
50
+ .replace('<!-- @STYLE@ -->', () => `<style>\n${cssSheet({ prefix: TOKEN_PREFIX })}${styles}</style>`)
51
+ .replace('<!-- @SCRIPT@ -->', () => `<script type="module"${nonce === '' ? '' : ` nonce="${nonce}"`}>\n` +
52
+ `${script.replaceAll('</script>', '<\\/script>')}</script>`));
42
53
  }
43
54
  async function buildScript() {
44
55
  const built = path('main.js');
@@ -53,6 +64,6 @@ async function buildScript() {
53
64
  catch (err) {
54
65
  // Fail loudly in the page rather than serve a stale or empty script.
55
66
  const detail = err instanceof Error ? err.message : String(err);
56
- return `document.body.innerHTML = "<pre></pre>";document.querySelector("pre").textContent = ${JSON.stringify(`${APP}: the page script failed to build\n\n${detail}`)};`;
67
+ return `document.body.innerHTML = "<pre></pre>";document.querySelector("pre").textContent = ${JSON.stringify(`${BIN}: the page script failed to build\n\n${detail}`)};`;
57
68
  }
58
69
  }
@@ -3,25 +3,9 @@
3
3
  * with its roles, its runner kind, its binary and whether that binary is on
4
4
  * an absolute PATH entry. Reads files only; runs nothing.
5
5
  */
6
- import { type CliIo } from '@osdlc/cli-tool';
7
- import type { Project, RoleName, ToolDef } from '@osdlc/system-model/detect';
8
- import { type LoadedConfig } from './config.ts';
6
+ import type { RoleName, ToolDef } from '@osdlc/system-model/detect';
9
7
  import type { LoadedTool } from './tools.ts';
10
- export interface ProvidersCommandIO extends CliIo {
11
- env?: Record<string, string | undefined>;
12
- home?: string;
13
- /** The configured `allowExec`, with wayfinder's default; `main` supplies it. */
14
- configuredAllowExec: (cfg: LoadedConfig) => boolean;
15
- /** Load the tool modules and build the project; `main` supplies it. */
16
- load: (cfg: LoadedConfig, modules: readonly string[], projectAllowed: boolean) => Promise<{
17
- project: Project;
18
- tools: LoadedTool[];
19
- warnings: string[];
20
- } | {
21
- error: string;
22
- }>;
23
- }
24
- /** One row of the listing, as `--json` prints it. */
8
+ /** One row of the listing, as `--json` prints it in `providers`. */
25
9
  export interface ProviderRow {
26
10
  id: string;
27
11
  roles: RoleName[];
@@ -33,8 +17,85 @@ export interface ProviderRow {
33
17
  source: 'built-in' | 'custom';
34
18
  /** The module a custom tool came from. */
35
19
  module?: string;
20
+ /** The tool's site, `http` or `https` only. Null when it names none. */
21
+ homepage: string | null;
22
+ /** One sentence on what the tool is. */
23
+ description: string | null;
24
+ /** The ecosystem id, such as `node`. Null for a tool of no one language. */
25
+ ecosystem: string | null;
26
+ /** The language label, or `any language`. */
27
+ language: string;
36
28
  }
37
29
  /** One row per registered tool, in registry order. */
38
30
  export declare function providerRows(tools: readonly ToolDef[], custom: readonly LoadedTool[], env: Record<string, string | undefined>): ProviderRow[];
39
- /** `way providers …`. Returns the exit code. */
40
- export declare function runProvidersCommand(root: string, argv: string[], io: ProvidersCommandIO): Promise<number>;
31
+ /** Make the `providers` command. */
32
+ export declare function providersCommand(home: string): import("@osdlc/cli-tool/command").DataCommand<Record<never, never>, {
33
+ readonly dir: {
34
+ readonly kind: "string";
35
+ readonly short: "C";
36
+ readonly valueName: "PATH";
37
+ readonly help: "the directory to inspect (default: cwd)";
38
+ };
39
+ readonly exec: {
40
+ readonly kind: "tristate";
41
+ readonly help: "allow runners that must run a subprocess (moon), this run only";
42
+ readonly offHelp: "skip them, overriding a configured allowExec: true";
43
+ };
44
+ readonly only: {
45
+ readonly kind: "list";
46
+ readonly valueName: "a,b";
47
+ readonly hidden: true;
48
+ readonly help: "restrict to these runners";
49
+ };
50
+ readonly exclude: {
51
+ readonly kind: "list";
52
+ readonly valueName: "a,b";
53
+ readonly hidden: true;
54
+ readonly help: "skip these runners, REPLACING the configured runners.disabled";
55
+ };
56
+ readonly excludePath: {
57
+ readonly kind: "list";
58
+ readonly valueName: "P";
59
+ readonly commaSeparated: false;
60
+ readonly hidden: true;
61
+ readonly help: "skip a path; repeatable. A bare name matches any segment, a value with a slash matches a path from the root";
62
+ };
63
+ readonly discovery: {
64
+ readonly kind: "enum";
65
+ readonly choices: readonly ["git", "walk", "auto"];
66
+ readonly valueName: "M";
67
+ readonly hidden: true;
68
+ readonly help: "how to find directories. Default: auto";
69
+ };
70
+ readonly config: {
71
+ readonly kind: "list";
72
+ readonly valueName: "MODULE";
73
+ readonly commaSeparated: false;
74
+ readonly help: "load extra tools from a module, this run only; repeatable";
75
+ };
76
+ }, import("zod").ZodObject<{
77
+ providers: import("zod").ZodArray<import("zod").ZodObject<{
78
+ id: import("zod").ZodString;
79
+ roles: import("zod").ZodArray<import("zod").ZodEnum<{
80
+ runner: "runner";
81
+ packageManager: "packageManager";
82
+ toolManager: "toolManager";
83
+ hookManager: "hookManager";
84
+ }>>;
85
+ kind: import("zod").ZodNullable<import("zod").ZodEnum<{
86
+ exec: "exec";
87
+ parse: "parse";
88
+ }>>;
89
+ binary: import("zod").ZodNullable<import("zod").ZodString>;
90
+ onPath: import("zod").ZodNullable<import("zod").ZodBoolean>;
91
+ source: import("zod").ZodEnum<{
92
+ custom: "custom";
93
+ "built-in": "built-in";
94
+ }>;
95
+ module: import("zod").ZodOptional<import("zod").ZodString>;
96
+ homepage: import("zod").ZodNullable<import("zod").ZodString>;
97
+ description: import("zod").ZodNullable<import("zod").ZodString>;
98
+ ecosystem: import("zod").ZodNullable<import("zod").ZodString>;
99
+ language: import("zod").ZodString;
100
+ }, import("zod/v4/core").$strip>>;
101
+ }, import("zod/v4/core").$strip>>;