@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/groups.d.ts CHANGED
@@ -1,34 +1,30 @@
1
1
  /**
2
2
  * The row groups every surface shows: tasks from runners, then the actions
3
3
  * system-model synthesizes from package managers, tool managers and hook
4
- * managers. Each synthesized group is one runner id, so grouping is a
5
- * property of the report. Browser-safe: the page imports it.
4
+ * managers, then agent skills. The report groups are
5
+ * `@osdlc/system-model/groups`; this module adds the order wayfinder sorts
6
+ * reports by and the Skills group, whose rows are `CatalogSnapshot.skills`
7
+ * rather than a report. Browser-safe: the page imports it.
6
8
  */
7
- /** A group's stable id, as `--json` prints it. */
8
- export type GroupId = 'tasks' | 'dependencies' | 'tools' | 'hooks';
9
- export interface Group {
10
- id: GroupId;
11
- title: string;
12
- /** The synthesized runner that fills it; absent for tasks, which every other runner fills. */
13
- runner?: string;
14
- }
15
- /**
16
- * In display order. The runner ids are `SYNTHESIZED_RUNNERS` from
17
- * `@osdlc/system-model/detect`, restated because that entry is not
18
- * browser-safe; a test checks they agree.
19
- */
20
- export declare const GROUPS: readonly Group[];
21
- /** The group a runner's report belongs to. */
22
- export declare function groupOf(runner: string): Group;
9
+ import { type GroupId } from '@osdlc/system-model/groups';
10
+ export { GROUPS, catalogGroups, groupOf } from '@osdlc/system-model/groups';
11
+ export type { Group, GroupId } from '@osdlc/system-model/groups';
12
+ export { runnerLabel } from './vocabulary.ts';
23
13
  /** Position of a runner's group in {@link GROUPS}. */
24
14
  export declare function groupRank(runner: string): number;
25
- /** What a tab shows for a runner: the group's name for a synthesized group, else the runner id. */
26
- export declare function runnerLabel(runner: string): string;
27
- /** The groups that have at least one report, each with its runners in report order. */
28
- export declare function catalogGroups(reports: readonly {
29
- runner: string;
30
- }[]): Array<{
31
- id: GroupId;
15
+ /** The Skills group. Its rows are skills, not a runner's tasks, so it names no runner. */
16
+ export declare const SKILLS_GROUP: {
17
+ readonly id: "skills";
18
+ readonly title: "Skills";
19
+ };
20
+ /** A group as a document lists it. */
21
+ export interface DocumentGroup {
22
+ id: GroupId | typeof SKILLS_GROUP.id;
32
23
  title: string;
24
+ /** The runners whose reports fill it. Empty for Skills. */
33
25
  runners: string[];
34
- }>;
26
+ }
27
+ /** The groups with rows, in display order: the report groups, then Skills when there are skills. */
28
+ export declare function documentGroups(reports: readonly {
29
+ runner: string;
30
+ }[], skillCount: number): DocumentGroup[];
package/dist/groups.js CHANGED
@@ -1,38 +1,22 @@
1
1
  /**
2
2
  * The row groups every surface shows: tasks from runners, then the actions
3
3
  * system-model synthesizes from package managers, tool managers and hook
4
- * managers. Each synthesized group is one runner id, so grouping is a
5
- * property of the report. Browser-safe: the page imports it.
4
+ * managers, then agent skills. The report groups are
5
+ * `@osdlc/system-model/groups`; this module adds the order wayfinder sorts
6
+ * reports by and the Skills group, whose rows are `CatalogSnapshot.skills`
7
+ * rather than a report. Browser-safe: the page imports it.
6
8
  */
7
- /**
8
- * In display order. The runner ids are `SYNTHESIZED_RUNNERS` from
9
- * `@osdlc/system-model/detect`, restated because that entry is not
10
- * browser-safe; a test checks they agree.
11
- */
12
- export const GROUPS = [
13
- { id: 'tasks', title: 'Tasks' },
14
- { id: 'dependencies', title: 'Dependencies', runner: 'package-manager' },
15
- { id: 'tools', title: 'Tools', runner: 'tool-manager' },
16
- { id: 'hooks', title: 'Git hooks', runner: 'hook-manager' },
17
- ];
18
- /** The group a runner's report belongs to. */
19
- export function groupOf(runner) {
20
- return GROUPS.find((g) => g.runner === runner) ?? GROUPS[0];
21
- }
9
+ import { GROUPS, catalogGroups, groupOf } from '@osdlc/system-model/groups';
10
+ export { GROUPS, catalogGroups, groupOf } from '@osdlc/system-model/groups';
11
+ export { runnerLabel } from "./vocabulary.js";
22
12
  /** Position of a runner's group in {@link GROUPS}. */
23
13
  export function groupRank(runner) {
24
14
  return GROUPS.indexOf(groupOf(runner));
25
15
  }
26
- /** What a tab shows for a runner: the group's name for a synthesized group, else the runner id. */
27
- export function runnerLabel(runner) {
28
- const group = groupOf(runner);
29
- return group.runner === runner ? group.title.toLowerCase() : runner;
30
- }
31
- /** The groups that have at least one report, each with its runners in report order. */
32
- export function catalogGroups(reports) {
33
- return GROUPS.map((g) => ({
34
- id: g.id,
35
- title: g.title,
36
- runners: reports.filter((r) => groupOf(r.runner) === g).map((r) => r.runner),
37
- })).filter((g) => g.runners.length > 0);
16
+ /** The Skills group. Its rows are skills, not a runner's tasks, so it names no runner. */
17
+ export const SKILLS_GROUP = { id: 'skills', title: 'Skills' };
18
+ /** The groups with rows, in display order: the report groups, then Skills when there are skills. */
19
+ export function documentGroups(reports, skillCount) {
20
+ const groups = catalogGroups(reports);
21
+ return skillCount > 0 ? [...groups, { ...SKILLS_GROUP, runners: [] }] : groups;
38
22
  }
package/dist/guide.d.ts CHANGED
@@ -1,19 +1,21 @@
1
1
  /**
2
- * The `guide` subcommand: Markdown for a person or a model who has the binary
3
- * and not the README. `--help` lists the flags; this says what `--json` hands
4
- * you, why a runner is missing, and how to add a tool.
2
+ * `way guide`: cli-tool's shared `guide` command over wayfinder's topics,
3
+ * Markdown for a person or a model who has the binary and not the README.
4
+ * `--help` lists the flags; this says what `--json` hands you, why a runner is
5
+ * missing, and how to add a tool.
5
6
  *
6
7
  * Sections are data, so `tests/guide.test.ts` can check each one against the
7
8
  * code it describes. No roster is retyped: the built-in tools come from
8
9
  * `builtins` and the settable keys from `CONFIG_KEYS`.
9
10
  */
10
- import { type CliIo } from '@osdlc/cli-tool';
11
+ import type { CommandContext, DataCommand } from '@osdlc/cli-tool/command';
12
+ import type { FlagSpec } from '@osdlc/cli-tool/define-cli';
11
13
  /** One section of the guide. The document is these, in this order. */
12
- export type GuideTopic = 'usage' | 'config' | 'json' | 'trust' | 'extend';
13
- export declare const GUIDE_TOPICS: readonly GuideTopic[];
14
+ export type GuideTopicId = 'usage' | 'config' | 'json' | 'trust' | 'extend';
15
+ export declare const GUIDE_TOPICS: readonly GuideTopicId[];
14
16
  /**
15
- * What the guide takes from the CLI. `usage` is the same string `--help --all`
16
- * prints, so the guide's flag list and the help cannot drift.
17
+ * What the guide takes from the CLI. `usage` is the same string the complete
18
+ * help prints, so the guide's flag list and the help cannot drift.
17
19
  */
18
20
  export interface GuideTool {
19
21
  usage: string;
@@ -24,9 +26,20 @@ export interface GuideTool {
24
26
  * the typechecker compiles, and `tests/guide.test.ts` checks the two match.
25
27
  */
26
28
  export declare const EXTEND_EXAMPLE = "import type { ToolDef } from '@osdlc/system-model/detect'\n\nexport const tools: ToolDef[] = [\n {\n id: 'acme',\n binary: 'acme',\n markers: [{ files: '/acme.json', tier: 'files' }],\n roles: {\n runner: {\n kind: 'parse',\n chain: [{ label: 'task', hint: 'the acme task to run' }],\n async collect(ctx) {\n const config = (await ctx.readJson('acme.json')) as { tasks?: string[] } | null\n const tasks = (config?.tasks ?? []).map((name) => ({\n id: `acme:${name}`,\n runner: 'acme',\n path: ['acme', name],\n argv: ['acme', 'run', name],\n cwd: '.',\n display: `acme run ${name}`,\n parameters: [],\n source: 'acme.json',\n origin: 'declared' as const,\n tags: [],\n persistent: { value: false, declared: false },\n executes: 'local' as const,\n }))\n return { status: 'ok', tasks, diagnostics: [] }\n },\n },\n },\n },\n]\n";
27
- /** One section. Always ends with a newline. */
28
- export declare function guideSection(topic: GuideTopic, tool: GuideTool): string;
29
- /** Every section, in {@link GUIDE_TOPICS} order, under one title. */
29
+ /** One section with its heading, as `guide <topic>` prints it. */
30
+ export declare function guideSection(topic: GuideTopicId, tool: GuideTool): string;
31
+ /** The guide's title. */
32
+ export declare const GUIDE_TITLE = "wayfinder guide";
33
+ /** The paragraph under the title. */
34
+ export declare const GUIDE_INTRO: string;
35
+ /** Every section, in {@link GUIDE_TOPICS} order, under the title, as `guide` prints it. */
30
36
  export declare function guideDocument(tool: GuideTool): string;
31
- /** `way guide …`. Returns the exit code. */
32
- export declare function runGuideCommand(tool: GuideTool, argv: string[], io: CliIo): number;
37
+ /**
38
+ * The `guide` command. Mount it as `guide: guideCommand({ globals })`. The
39
+ * usage topic shows `tool(ctx).usage`; by default that is the app's complete
40
+ * root help.
41
+ */
42
+ export declare function guideCommand<G extends FlagSpec = Record<never, never>>(options?: {
43
+ globals?: G;
44
+ tool?: (ctx: CommandContext) => GuideTool;
45
+ }): DataCommand;
package/dist/guide.js CHANGED
@@ -1,21 +1,27 @@
1
1
  /**
2
- * The `guide` subcommand: Markdown for a person or a model who has the binary
3
- * and not the README. `--help` lists the flags; this says what `--json` hands
4
- * you, why a runner is missing, and how to add a tool.
2
+ * `way guide`: cli-tool's shared `guide` command over wayfinder's topics,
3
+ * Markdown for a person or a model who has the binary and not the README.
4
+ * `--help` lists the flags; this says what `--json` hands you, why a runner is
5
+ * missing, and how to add a tool.
5
6
  *
6
7
  * Sections are data, so `tests/guide.test.ts` can check each one against the
7
8
  * code it describes. No roster is retyped: the built-in tools come from
8
9
  * `builtins` and the settable keys from `CONFIG_KEYS`.
9
10
  */
10
- import { EXIT } from '@osdlc/cli-tool';
11
+ import { guideCommand as sharedGuideCommand } from '@osdlc/cli-tool/guide';
11
12
  import { builtins } from '@osdlc/system-model/builtins';
12
- import { APP, BIN, CONFIG_ENV_VAR, LEGACY_APP, LEGACY_CONFIG_ENV_VAR, LEGACY_PROJECT_CONFIG_FILENAME, PROJECT_CONFIG_FILENAME, } from "./app.js";
13
- import { CONFIG_KEYS } from "./config.js";
13
+ import { APP, BIN, CONFIG_ENV_VAR, PROJECT_CONFIG_FILENAME } from "./app.js";
14
+ import { CONFIG_KEYS, OPEN_VALUES, THEME_VALUES } from "./config.js";
14
15
  import { GROUPS } from "./groups.js";
15
16
  export const GUIDE_TOPICS = ['usage', 'config', 'json', 'trust', 'extend'];
16
- function isGuideTopic(value) {
17
- return GUIDE_TOPICS.includes(value);
18
- }
17
+ /** One line per topic, for `guide topics`. */
18
+ const SUMMARIES = {
19
+ usage: 'the surfaces, the flags and the row groups',
20
+ config: 'the layered settings files and every key',
21
+ json: 'what --json prints, field by field',
22
+ trust: 'why some runners need trust, and how it is decided',
23
+ extend: 'adding your own tools',
24
+ };
19
25
  const code = '```';
20
26
  /** The built-in runner ids, as an inline list. */
21
27
  function runnerRoster() {
@@ -74,6 +80,8 @@ export const tools: ToolDef[] = [
74
80
  ]
75
81
  `;
76
82
  const JSON_EXAMPLE = `{
83
+ "schemaVersion": 1,
84
+ "kind": "catalog",
77
85
  "root": "/home/you/repo",
78
86
  "generatedAt": "2026-01-01T00:00:00.000Z",
79
87
  "discovery": "git",
@@ -105,13 +113,14 @@ const JSON_EXAMPLE = `{
105
113
  "skippedForExec": false
106
114
  }
107
115
  ],
108
- "groups": [{ "id": "tasks", "title": "Tasks", "runners": ["just"] }]
116
+ "groups": [{ "id": "tasks", "title": "Tasks", "runners": ["just"] }],
117
+ "cache": [{ "runner": "just", "state": "fresh", "ageMs": 0, "probeMs": 12, "estimateMs": 12, "slow": false }],
118
+ "unknowns": [],
119
+ "filter": {}
109
120
  }`;
110
- function usageSection(tool) {
121
+ function usageBody(tool) {
111
122
  const extra = tool.extraUsage === undefined ? '' : `\n${tool.extraUsage.trim()}\n`;
112
- return `## usage
113
-
114
- \`${BIN}\` lists every task this repository can run, and runs one.
123
+ return `\`${BIN}\` lists every task this repository can run, and runs one.
115
124
 
116
125
  Point it at a directory; the directory is resolved upward to the project root,
117
126
  so running from a subdirectory still inspects the whole repository.
@@ -136,10 +145,8 @@ claimed before the flag parse, so their own arguments are not read as this
136
145
  tool's flags.
137
146
  `;
138
147
  }
139
- function configSection() {
140
- return `## config
141
-
142
- Layers, lowest precedence first:
148
+ function configBody() {
149
+ return `Layers, lowest precedence first:
143
150
 
144
151
  1. The built-in defaults, with \`allowExec: true\`: willing in principle,
145
152
  still gated on trust.
@@ -150,19 +157,26 @@ Layers, lowest precedence first:
150
157
  Files. The project file is \`${PROJECT_CONFIG_FILENAME}\` at the project root, the
151
158
  root this tool resolved, not the working directory. The user file is
152
159
  \`$XDG_CONFIG_HOME/${APP}/config.json\`, or \`~/.config/${APP}/config.json\` when
153
- that variable is unset or relative.
160
+ that variable is unset or relative; on Windows it is under \`%APPDATA%\`.
161
+ \`WAYFINDER_ROOT\` moves every file ${APP} keeps outside your repositories under
162
+ one directory.
154
163
 
155
164
  \`${CONFIG_ENV_VAR}\` replaces the USER file's location and nothing else. It does
156
165
  not move the project file and it does not add a layer. A path in it may start
157
166
  with a tilde, which is expanded. A relative path is ignored with a warning,
158
167
  because from the project root it would name a file in the repository.
159
168
 
160
- Old names. The tool was called ${LEGACY_APP} before its first release.
161
- \`${LEGACY_CONFIG_ENV_VAR}\`, \`$XDG_CONFIG_HOME/${LEGACY_APP}/config.json\` and
162
- \`${LEGACY_PROJECT_CONFIG_FILENAME}\` are still read when the new name is absent,
163
- with a warning naming the new location.
169
+ Settable keys: ${configKeyList()}. A key under \`trust.tools\` names one tool:
170
+ \`trust.tools.<tool>.paths\`.
164
171
 
165
- Settable keys: ${configKeyList()}.
172
+ \`open\` is what a bare \`${BIN}\` opens: ${OPEN_VALUES.map((v) => `"${v}"`).join(' or ')}.
173
+ \`theme\` is the web view's theme: ${THEME_VALUES.map((v) => `"${v}"`).join(', ')}.
174
+ Both are personal, so only the user file may set them.
175
+
176
+ A file may start with \`"$schema"\`, naming the JSON Schema an editor checks it
177
+ against; every file ${BIN} writes has one. An unknown key is a warning that
178
+ names the closest known key, and the rest of the file still loads. A value of
179
+ the wrong type is an error.
166
180
 
167
181
  Merging. Objects merge key by key. An ARRAY answers "which ones" wholesale, so
168
182
  a later layer replaces it rather than appending to it: \`--exclude\` REPLACES
@@ -177,26 +191,33 @@ takes the tree beneath it. Not glob syntax.
177
191
  \`tools\` names modules that export more tools (see extend). A relative path
178
192
  resolves against the file that names it.
179
193
 
194
+ \`${BIN} config explain <key>\` shows each layer's value for a key, which one won,
195
+ and why a project value was ignored.
196
+
180
197
  Exit codes. 2 means the command cannot be run as typed: an unknown
181
198
  subcommand, a wrong argument count, an unknown setting, a value of the wrong
182
- type. 1 means a well-formed command failed against the state: a file that
183
- will not parse, a key that is not set where you asked to unset it.
199
+ type, a key the project file may not hold. 1 means a well-formed command
200
+ failed against the state: a file that will not parse, a key that is not set
201
+ where you asked to unset it.
184
202
 
185
203
  The project file cannot grant execution. It may LOWER \`allowExec\` to false,
186
204
  never raise it, because it lives inside the repository being scanned. A
187
- project file's \`allowExec: true\` and any trust block are dropped with a
188
- warning. Its \`tools\` load only when the repository is trusted and execution
189
- is allowed, since a tool module is code.
205
+ project file's \`allowExec: true\`, its trust block, \`open\`, \`theme\` and
206
+ \`skills\` are dropped with a warning, and \`config set\` refuses to write them
207
+ there. Its \`tools\` load only when the repository is trusted and execution is
208
+ allowed, since a tool module is code. The web view cannot set \`allowExec\`,
209
+ \`tools\` or the trust keys.
190
210
 
191
211
  The effective gate: \`--no-exec\` forbids execution whatever is configured;
192
212
  \`--exec\` allows it for that one run; with neither flag, execution needs a
193
213
  configured \`allowExec\` of true and a trusted repository.
194
214
  `;
195
215
  }
196
- function jsonSection() {
197
- return `## json
198
-
199
- \`--json\` prints the catalog as one JSON document. Field by field:
216
+ function jsonBody() {
217
+ return `Every command answers \`--json\` with one JSON document whose first fields are
218
+ \`schemaVersion\` and \`kind\`. \`${BIN} schema\` prints each one's JSON Schema, and
219
+ \`@osdlc/wayfinder/schema\` exports them. \`${BIN} list --json\` prints the
220
+ catalog document (\`kind\` "catalog"). Field by field:
200
221
 
201
222
  \`Catalog\`
202
223
  - \`root\`: absolute path the collection ran against. Every \`cwd\` and
@@ -241,17 +262,24 @@ ${groupList()}
241
262
  - \`skippedForExec\`: true when the runner was withheld because it needed to
242
263
  shell out.
243
264
 
244
- \`cache\`: present only with \`--cached\`. One entry per runner:
265
+ \`cache\`: one entry per runner:
245
266
  - \`state\`: "fresh", "stale" (used, and out of date) or "miss" (nothing was
246
- stored, so it was probed now).
247
- - \`reason\`: "changed", "max-age" or "excludes", on a stale row only.
248
- - \`ageMs\`: how old the stored answer is. Absent on a miss.
249
- - \`estimateMs\`: the median re-probe cost measured in this repository, or null.
267
+ stored).
268
+ - \`reason\`: why a stale row is stale, such as "changed".
269
+ - \`ageMs\`: how old the stored answer is; 0 when probed just now.
270
+ - \`probeMs\`: how long the probe took, when it ran in this call.
271
+ - \`estimateMs\`: the expected re-probe cost, or null when never measured.
250
272
  - \`slow\`: true when those measurements say this runner is slow here.
251
273
 
274
+ \`unknowns\`: what could not be read, each with the \`label\` the terminal
275
+ shows: \`withheld\` runners, tasks whose \`parameters\` are unknown, \`stale\`
276
+ stored answers and a \`binary\` not on the PATH.
277
+
278
+ \`filter\`: the filters \`--services\`, \`--declared\` and \`--depth\` applied.
279
+
252
280
  A cached \`generatedAt\` is the OLDEST contributing probe time.
253
281
 
254
- Over HTTP, \`${BIN} --serve\` adds \`trustable\`, the server's own reading of
282
+ Over HTTP, \`${BIN} serve\` adds \`trustable\`, the server's own reading of
255
283
  the gate it resolved.
256
284
 
257
285
  Trimmed example:
@@ -261,10 +289,8 @@ ${JSON_EXAMPLE}
261
289
  ${code}
262
290
  `;
263
291
  }
264
- function trustSection() {
265
- return `## trust
266
-
267
- Reading some runners means RUNNING them. Asking moon for its task graph
292
+ function trustBody() {
293
+ return `Reading some runners means RUNNING them. Asking moon for its task graph
268
294
  evaluates the repository's toolchain configuration, and asking mise for its
269
295
  tasks can fire that repository's hooks. Pointing a tool at a repository you
270
296
  did not write is code execution before you have run anything from the list.
@@ -274,8 +300,7 @@ Built-ins that must shell out: ${execRoster()}.
274
300
  The store is \`$XDG_STATE_HOME/${APP}/trusted/\`, or
275
301
  \`~/.local/state/${APP}/trusted/\` when that variable is unset: state, not
276
302
  config, so consent does not travel in a dotfiles repository. One marker file
277
- per trusted root. Grants in the old \`$XDG_STATE_HOME/${LEGACY_APP}/trusted/\`
278
- store still count.
303
+ per trusted root, and one per tool granted alone.
279
304
 
280
305
  It is PATH-KEYED: the key is the absolute, symlink-resolved root, not a hash
281
306
  of the contents. A repository you trusted that later pulls hostile changes
@@ -296,21 +321,25 @@ ${code}
296
321
 
297
322
  The exec flag grants execution for ONE run and records nothing.
298
323
 
299
- The command: \`${BIN} trust\` grants, \`--untrust\` revokes, \`--show\` reports
300
- this root, \`--list\` prints every trusted path. \`-C PATH\` reaches all of them.
324
+ The command: \`${BIN} trust\` grants, \`--untrust\` revokes, \`--untrust-all\`
325
+ revokes every grant of this root, \`--show\` reports this root, \`--list\`
326
+ prints every grant. \`--scope <tool>\` grants, revokes or shows one tool's
327
+ trust instead of the whole repository's. \`-C PATH\` reaches all of them.
328
+ Granting works from the command line only: the web view cannot grant
329
+ trust.
301
330
 
302
331
  A root can also be trusted with no marker, by a trust block in the USER
303
332
  config: \`trust.paths\` (a glob over the resolved root) and \`trust.owners\`
304
333
  (the \`origin\` remote's \`host/owner\`; a bare owner means github.com), decided in
305
- that order after the marker.
334
+ that order after the marker. \`trust.tools.<tool>\` holds the same two lists for
335
+ one tool. A run needs every tool it runs trusted: a mise task needs mise as
336
+ well as its own runner.
306
337
  \`--show\` and \`--json\` name which layer decided (\`by\`:
307
338
  \`marker\`/\`path\`/\`owner\`, plus the matching \`rule\` for a policy hit).
308
339
  `;
309
340
  }
310
- function extendSection() {
311
- return `## extend
312
-
313
- A tool is a \`ToolDef\` from \`@osdlc/system-model/detect\`, the same shape as
341
+ function extendBody() {
342
+ return `A tool is a \`ToolDef\` from \`@osdlc/system-model/detect\`, the same shape as
314
343
  the built-ins: an id, the binary, the files that show it is in use, and the
315
344
  roles it plays. A tool with a \`runner\` role adds tasks.
316
345
 
@@ -347,66 +376,53 @@ strips types. A tool whose id matches a built-in is an error.
347
376
  \`${BIN} providers\` lists every registered tool and where it came from.
348
377
  `;
349
378
  }
350
- /** One section. Always ends with a newline. */
351
- export function guideSection(topic, tool) {
379
+ /** One section's Markdown body, without its heading. */
380
+ function guideBody(topic, tool) {
352
381
  switch (topic) {
353
382
  case 'usage':
354
- return usageSection(tool);
383
+ return usageBody(tool);
355
384
  case 'config':
356
- return configSection();
385
+ return configBody();
357
386
  case 'json':
358
- return jsonSection();
387
+ return jsonBody();
359
388
  case 'trust':
360
- return trustSection();
389
+ return trustBody();
361
390
  case 'extend':
362
- return extendSection();
391
+ return extendBody();
363
392
  }
364
393
  }
365
- /** Every section, in {@link GUIDE_TOPICS} order, under one title. */
394
+ /** One section with its heading, as `guide <topic>` prints it. */
395
+ export function guideSection(topic, tool) {
396
+ return `## ${topic}\n\n${guideBody(topic, tool).trim()}\n`;
397
+ }
398
+ /** The guide's title. */
399
+ export const GUIDE_TITLE = `${APP} guide`;
400
+ /** The paragraph under the title. */
401
+ export const GUIDE_INTRO = `Instructions for using and extending this tool without the README. Topics: ${GUIDE_TOPICS.join(', ')}. Print one with \`${BIN} guide <topic>\`.`;
402
+ /** Every section, in {@link GUIDE_TOPICS} order, under the title, as `guide` prints it. */
366
403
  export function guideDocument(tool) {
367
- const header = `# ${APP} guide
368
-
369
- Instructions for using and extending this tool without the README. Topics:
370
- ${GUIDE_TOPICS.join(', ')}. Print one with \`${BIN} guide <topic>\`.
371
- `;
372
- return [header, ...GUIDE_TOPICS.map((t) => guideSection(t, tool))].join('\n');
404
+ return (`# ${GUIDE_TITLE}\n\n${GUIDE_INTRO}\n\n` +
405
+ GUIDE_TOPICS.map((t) => guideSection(t, tool)).join('\n'));
373
406
  }
374
- /** `way guide --help`. Short on purpose: the document is the real help. */
375
- function guideUsage() {
376
- return `${BIN} guide — how to use and extend ${APP}, without the README
377
-
378
- usage: ${BIN} guide [topic]
379
-
380
- (no topic) the whole document
381
- topics the topic names, one per line
382
- <topic> one section: ${GUIDE_TOPICS.join(', ')}
383
- -h, --help this text
384
- `;
407
+ /** The topics for cli-tool's `guide` command. `tool` gives the usage text for a run. */
408
+ function guideTopics(tool) {
409
+ return GUIDE_TOPICS.map((id) => ({
410
+ id,
411
+ title: id,
412
+ summary: SUMMARIES[id],
413
+ body: (ctx) => guideBody(id, tool(ctx)),
414
+ }));
385
415
  }
386
- /** `way guide …`. Returns the exit code. */
387
- export function runGuideCommand(tool, argv, io) {
388
- if (argv.length === 0) {
389
- io.stdout(guideDocument(tool));
390
- return EXIT.ok;
391
- }
392
- const [first, ...rest] = argv;
393
- if (first === '-h' || first === '--help') {
394
- io.stdout(guideUsage());
395
- return EXIT.ok;
396
- }
397
- const bad = (what) => {
398
- io.stderr(`${APP}: guide: ${what} — topics are: ${GUIDE_TOPICS.join(', ')} (or "topics")\n`);
399
- return EXIT.usage;
400
- };
401
- if (rest.length > 0)
402
- return bad('expected at most one topic');
403
- if (first === 'topics') {
404
- io.stdout(`${GUIDE_TOPICS.join('\n')}\n`);
405
- return EXIT.ok;
406
- }
407
- if (isGuideTopic(first)) {
408
- io.stdout(guideSection(first, tool));
409
- return EXIT.ok;
410
- }
411
- return bad(`unknown topic "${first}"`);
416
+ /**
417
+ * The `guide` command. Mount it as `guide: guideCommand({ globals })`. The
418
+ * usage topic shows `tool(ctx).usage`; by default that is the app's complete
419
+ * root help.
420
+ */
421
+ export function guideCommand(options = {}) {
422
+ const tool = options.tool ?? ((ctx) => ({ usage: ctx.app.helpText([], { full: true }) }));
423
+ return sharedGuideCommand(guideTopics(tool), {
424
+ title: GUIDE_TITLE,
425
+ intro: GUIDE_INTRO,
426
+ ...(options.globals !== undefined ? { globals: options.globals } : {}),
427
+ });
412
428
  }
@@ -0,0 +1,118 @@
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 type { DiscoveryMode, RunnerReport } from '@osdlc/system-model/detect';
15
+ import type { TaskFilter } from './core/filter.ts';
16
+ import { type CacheState, type CatalogProgress, type SessionFlags } from './core/session.ts';
17
+ import type { SkillRow } from './core/skills.ts';
18
+ import type { Unknown } from './core/unknowns.ts';
19
+ import type { DocumentGroup } from './groups.ts';
20
+ export { SessionError, type CacheState, type CatalogProgress, type SessionFlags, } from './core/session.ts';
21
+ export { filterTasks, hasQuery, keepsTask, sourceDepth } from './core/filter.ts';
22
+ export type { TaskFilter, TaskHit } from './core/filter.ts';
23
+ export { filterSkills, skillLine, SKILLS_SETTING_VALUES } from './core/skills.ts';
24
+ export type { SkillHit, SkillRow, SkillsSetting } from './core/skills.ts';
25
+ export { unknownLine, unknownsOf, type Unknown, type UnknownsInput } from './core/unknowns.ts';
26
+ export { GROUPS, SKILLS_GROUP, catalogGroups, documentGroups, groupOf, type DocumentGroup, type Group, type GroupId, } from './groups.ts';
27
+ export { jsonText, terminalSafe } from './terminal-text.ts';
28
+ export { toolSummary, type ToolSummary } from './tool-info.ts';
29
+ export { ANY_LANGUAGE, languageLabel, runnerLabel, withheldLabel } from './vocabulary.ts';
30
+ export type { WithheldReason } from './vocabulary.ts';
31
+ export type { Catalog, DiscoveryMode, Param, ParametersUnknownReason, RunnerCacheState, RunnerReport, StaleReason, Task, ToolDef, } from '@osdlc/system-model/detect';
32
+ export type { Mode } from '@osdlc/system-model/match';
33
+ /** What {@link buildCatalog} reads, and the choices the CLI makes with flags. */
34
+ export interface BuildCatalogOptions {
35
+ /** The directory to read: absolute, or relative to `cwd`. It must exist. */
36
+ dir: string;
37
+ /** The base for a relative `dir` and tool module paths. Default `process.cwd()`. */
38
+ cwd?: string | undefined;
39
+ /** Where config, trust and the probe store are found. Default `process.env`. */
40
+ env?: Record<string, string | undefined> | undefined;
41
+ /** The home directory. Default: the OS account's. */
42
+ home?: string | undefined;
43
+ /**
44
+ * What the CLI's flags choose: `allowExec` is `--exec` or `--no-exec`,
45
+ * `toolModules` is `--config`. Absent fields come from the config files.
46
+ */
47
+ flags?: SessionFlags | undefined;
48
+ /**
49
+ * Answer as `--cached` does: from the last saved listing, which checks no
50
+ * files, else from the stored probe, probing only the runners missing from it.
51
+ */
52
+ cached?: boolean | undefined;
53
+ /** Keep only some tasks and skills, as `--services`, `--declared` and `--depth`. */
54
+ filter?: TaskFilter | undefined;
55
+ /** Stops every probe. */
56
+ signal?: AbortSignal | undefined;
57
+ /**
58
+ * Hears about each runner the call probes as it answers: `onRunners`
59
+ * once, then `onRunner` per runner. An answer from the saved listing or
60
+ * the store probes none. The document is still the answer to use.
61
+ */
62
+ progress?: CatalogProgress | undefined;
63
+ /**
64
+ * Called with each warning from the config files and tool modules, such
65
+ * as a project file key that is ignored. The CLI prints these on stderr.
66
+ */
67
+ onWarning?: ((message: string) => void) | undefined;
68
+ }
69
+ /** The catalog document: what `way list --json` prints. */
70
+ export interface CatalogDocument {
71
+ schemaVersion: number;
72
+ kind: 'catalog';
73
+ /** Absolute. Every `cwd` and `source` is relative to it. */
74
+ root: string;
75
+ generatedAt: string;
76
+ discovery: DiscoveryMode;
77
+ /** Whether every runner was allowed to run subprocesses. */
78
+ allowExec: boolean;
79
+ /**
80
+ * `fresh`: every runner was probed in this call. `cached` (under `cached:
81
+ * true`): the rows came from the last saved listing, which checks no
82
+ * files, or else from the stored probes, where `cache` says which runners
83
+ * were stale or probed now.
84
+ */
85
+ source: 'fresh' | 'cached';
86
+ /** With `source: "cached"`, when the oldest stored rows were probed (ISO 8601). Null when fresh. */
87
+ storedAt: string | null;
88
+ /** Grouped, and in the configured runner order. */
89
+ reports: RunnerReport[];
90
+ /** The groups with rows, in display order. */
91
+ groups: DocumentGroup[];
92
+ /** The agent skills, as the `skills` setting chooses. */
93
+ skills: SkillRow[];
94
+ cache: CacheState[];
95
+ /** What could not be read, each with the label every surface shows. */
96
+ unknowns: Unknown[];
97
+ /**
98
+ * The tool ids trusted on their own here. Empty when the repository is
99
+ * trusted as a whole, or trust does not decide execution.
100
+ */
101
+ trustedTools: string[];
102
+ /** The filter applied. Absent fields were not given. */
103
+ filter: Pick<TaskFilter, 'servicesOnly' | 'declaredOnly' | 'maxDepth'>;
104
+ }
105
+ /**
106
+ * The catalog for `dir`, as `way list --json` builds it: the same config,
107
+ * trust gate and probe store. Nothing in the repository runs unless the
108
+ * repository (or the tool) is trusted and execution is allowed. A probe
109
+ * writes the store, as `way list` does.
110
+ *
111
+ * Throws {@link SessionError}: `no-such-directory`, `config` for a config
112
+ * file that cannot be used, `tool-module` for a tool module that cannot be
113
+ * loaded.
114
+ *
115
+ * Task names, skill text and other strings come from the repository. Pass
116
+ * them through {@link terminalSafe} before printing them to a terminal.
117
+ */
118
+ export declare function buildCatalog(options: BuildCatalogOptions): Promise<CatalogDocument>;