@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
@@ -0,0 +1,178 @@
1
+ /**
2
+ * `way list`: the whole catalog. Text is one command line per task, the line
3
+ * Copy puts on the clipboard, then one `/<name>` line per agent skill;
4
+ * `--json` is the catalog document.
5
+ */
6
+ import { inDisplayOrder } from "../catalog.js";
7
+ import { documentGroups } from "../groups.js";
8
+ import { filterTasks } from "../core/filter.js";
9
+ import { filterSkills, skillLine } from "../core/skills.js";
10
+ import { CATALOG_DOCUMENT_VERSION, CatalogOutput, CatalogProgressOutput, } from "../documents.js";
11
+ import { taskLine } from "../core/copy-text.js";
12
+ import { terminalSafe } from "../terminal-text.js";
13
+ import { FILTER_FLAGS, filterFrom, kit, noteUnknowns, openSession } from "./shared.js";
14
+ /**
15
+ * The catalog document for `snapshot`: the catalog with its groups, cache
16
+ * verdicts, unknowns and the tools trusted on their own. With a filter, each
17
+ * report keeps only the tasks that pass it. The CLI and the web view send
18
+ * the same document.
19
+ */
20
+ export function catalogDocument(snapshot, unknowns, filter = {}, trustedTools = []) {
21
+ const { kind: _kind, schemaVersion: _version, ...catalog } = snapshot.catalog;
22
+ const filtered = Object.keys(filter).length > 0;
23
+ const reports = filtered
24
+ ? catalog.reports.map((r) => ({
25
+ ...r,
26
+ tasks: filterTasks([r], filter).map((h) => h.task),
27
+ }))
28
+ : catalog.reports;
29
+ const skills = filterSkills(snapshot.skills, filter).map((h) => h.skill);
30
+ return {
31
+ ...catalog,
32
+ ...sourceOf(snapshot),
33
+ reports,
34
+ groups: documentGroups(catalog.reports, skills.length),
35
+ skills,
36
+ cache: snapshot.cache,
37
+ unknowns,
38
+ trustedTools: [...trustedTools],
39
+ filter: {
40
+ ...(filter.servicesOnly === true ? { servicesOnly: true } : {}),
41
+ ...(filter.declaredOnly === true ? { declaredOnly: true } : {}),
42
+ ...(filter.maxDepth !== undefined ? { maxDepth: filter.maxDepth } : {}),
43
+ },
44
+ };
45
+ }
46
+ /**
47
+ * Whether the rows were probed in this call or came from the store, and when
48
+ * the stored ones were taken: the oldest stored runner's probe time.
49
+ */
50
+ export function sourceOf(snapshot) {
51
+ const cached = snapshot.origin === 'store' || snapshot.origin === 'saved';
52
+ return cached
53
+ ? { source: 'cached', storedAt: snapshot.catalog.generatedAt }
54
+ : { source: 'fresh', storedAt: null };
55
+ }
56
+ /**
57
+ * The largest progress line, in UTF-16 code units of its JSON. A runner
58
+ * whose line would be larger is sent without its report, as `omitted`; its
59
+ * rows come with the catalog document.
60
+ */
61
+ export const MAX_PROGRESS_LINE = 1024 * 1024;
62
+ /**
63
+ * A {@link CatalogProgress} that sends `session`'s probe as progress lines:
64
+ * the runners first, in the order the catalog will list them, then each
65
+ * runner as it answers, with its unknowns.
66
+ */
67
+ export function progressLines(session, emit, maxLine = MAX_PROGRESS_LINE) {
68
+ let pending = [];
69
+ let total = 0;
70
+ return {
71
+ onRunners(runners) {
72
+ pending = inDisplayOrder(runners.map((runner) => ({ runner })), session.runnerOrder()).map((r) => r.runner);
73
+ total = runners.length;
74
+ emit({ pending: [...pending], total });
75
+ },
76
+ onRunner(report, cache) {
77
+ pending = pending.filter((r) => r !== report.runner);
78
+ const unknowns = session.unknowns({ catalog: { reports: [report] }, cache: [cache] });
79
+ const line = { pending: [...pending], total, report, cache, unknowns };
80
+ emit(JSON.stringify(line).length <= maxLine
81
+ ? line
82
+ : { pending: [...pending], total, omitted: report.runner });
83
+ },
84
+ };
85
+ }
86
+ /** Every task in the document, in catalog order. */
87
+ function documentTasks(doc) {
88
+ return doc.reports.flatMap((r) => r.tasks);
89
+ }
90
+ /**
91
+ * Make the `list` command. `home` is the base for config, trust and cache
92
+ * paths. `share` is the web view's held catalog (see `catalog-share.ts`).
93
+ */
94
+ export function listCommand(home, share) {
95
+ return kit.command({
96
+ summary: 'the whole catalog: one pasteable command line per task, or the catalog document with --json',
97
+ description: 'Each task line is the command Copy gives, quoted and with a cd when the task runs from ' +
98
+ 'its own directory, so it pastes into a shell; "run" takes that line or the task id, which ' +
99
+ '--json shows. --output jsonl prints one runner report per line; with --progress it first ' +
100
+ 'prints a catalog-progress line as each runner answers. "query" with no terms ' +
101
+ 'prints one task per line. ' +
102
+ 'Probes every runner, so a script gets what the repository has now. --cached answers at ' +
103
+ 'once with the last listing saved under the same trust and settings, and does not check ' +
104
+ 'whether files changed since its storedAt. With no saved listing it reads the stored ' +
105
+ 'probes, checks their files and names the stale runners on stderr; a runner with nothing ' +
106
+ 'stored is probed now, and with nothing stored at all it probes every runner. The document ' +
107
+ 'says which it was: "source" is "fresh" or "cached", and "storedAt" is when the oldest ' +
108
+ 'stored rows were probed. --services, --declared and ' +
109
+ '--depth keep only some tasks; with --json each report keeps only those tasks. Notes on what ' +
110
+ 'could not be read (withheld runners, unknown parameters, missing tools) go to stderr; ' +
111
+ 'under --json the same notes are in "unknowns". Agent skills follow the tasks as /<name> ' +
112
+ 'lines; the skills setting chooses which (project, all or off).',
113
+ positionals: [{ name: 'dir', help: 'the directory to inspect (beats -C)' }],
114
+ flags: {
115
+ ...FILTER_FLAGS,
116
+ join: {
117
+ kind: 'boolean',
118
+ hidden: true,
119
+ help: 'in the web view, answer with a probe already running for the same catalog',
120
+ },
121
+ progress: {
122
+ kind: 'boolean',
123
+ help: 'send a catalog-progress line as each runner answers, before the document: with ' +
124
+ '--output jsonl, or as NDJSON over HTTP',
125
+ },
126
+ },
127
+ output: CatalogOutput,
128
+ kind: 'catalog',
129
+ schemaVersion: CATALOG_DOCUMENT_VERSION,
130
+ events: { schema: CatalogProgressOutput, kind: 'catalog-progress' },
131
+ items: { field: 'reports', kind: 'report' },
132
+ readOnly: true,
133
+ examples: ['list', 'list --json', 'list --services', '-C ../repo list --cached --json'],
134
+ async run({ flags, globals, positionals }, ctx) {
135
+ const filter = filterFrom(flags);
136
+ const sharing = share?.active === true && ctx.surface === 'http' && Object.keys(filter).length === 0;
137
+ // A shared probe outlives the request that started it, so the session
138
+ // runs on the share's signal; this request's own is passed to the share.
139
+ const session = await openSession(globals, sharing ? { ...ctx, signal: share.signal } : ctx, home, positionals[0]);
140
+ // Progress lines only when asked for, so --output jsonl is unchanged.
141
+ const own = flags.progress ? (line) => ctx.emit(line) : undefined;
142
+ const read = async (cached, signal, emit) => {
143
+ const snapshot = await session.catalog({
144
+ cached,
145
+ signal,
146
+ ...(emit !== undefined ? { progress: progressLines(session, emit) } : {}),
147
+ });
148
+ const unknowns = session.unknowns(snapshot);
149
+ noteUnknowns(ctx, session, snapshot, unknowns);
150
+ return catalogDocument(snapshot, unknowns, filter, session.settings().trustedTools);
151
+ };
152
+ if (sharing) {
153
+ const key = session.viewKey();
154
+ const shared = (join) => share.fresh(key, (signal, emit) => read(false, signal, emit), {
155
+ join,
156
+ signal: ctx.signal,
157
+ onEvent: own,
158
+ });
159
+ if (flags.cached) {
160
+ // With nothing held yet, the probe serve started is the answer.
161
+ const held = share.cached(key);
162
+ if (held !== null)
163
+ return held;
164
+ return share.probing(key) ? shared(true) : read(true, ctx.signal, own);
165
+ }
166
+ return shared(flags.join);
167
+ }
168
+ return read(flags.cached, undefined, own);
169
+ },
170
+ text(doc) {
171
+ const lines = [
172
+ ...documentTasks(doc).map((t) => taskLine(t)),
173
+ ...doc.skills.map((s) => terminalSafe(skillLine(s))),
174
+ ];
175
+ return lines.length > 0 ? `${lines.join('\n')}\n` : '';
176
+ },
177
+ });
178
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * `way query <terms>`: the terminal UI's search from a shell. The same
3
+ * matcher and ranking, one command line per match, as `list` prints it.
4
+ */
5
+ /** Make the `query` command. */
6
+ export declare function queryCommand(home: string): import("@osdlc/cli-tool/command").DataCommand<{
7
+ exact: {
8
+ kind: "boolean";
9
+ help: string;
10
+ };
11
+ cached: {
12
+ readonly kind: "boolean";
13
+ readonly help: "answer from the last saved listing (files unchecked), else the stored probe; stderr says which";
14
+ };
15
+ services: {
16
+ readonly kind: "boolean";
17
+ readonly help: "only tasks that run until you stop them";
18
+ };
19
+ declared: {
20
+ readonly kind: "boolean";
21
+ readonly help: "only tasks a file declares, not ones inferred from a convention";
22
+ };
23
+ depth: {
24
+ readonly kind: "string";
25
+ readonly valueName: "N";
26
+ readonly help: "only tasks declared at most N directories below the root (the web view calls this Scope)";
27
+ };
28
+ }, {
29
+ readonly dir: {
30
+ readonly kind: "string";
31
+ readonly short: "C";
32
+ readonly valueName: "PATH";
33
+ readonly help: "the directory to inspect (default: cwd)";
34
+ };
35
+ readonly exec: {
36
+ readonly kind: "tristate";
37
+ readonly help: "allow runners that must run a subprocess (moon), this run only";
38
+ readonly offHelp: "skip them, overriding a configured allowExec: true";
39
+ };
40
+ readonly only: {
41
+ readonly kind: "list";
42
+ readonly valueName: "a,b";
43
+ readonly hidden: true;
44
+ readonly help: "restrict to these runners";
45
+ };
46
+ readonly exclude: {
47
+ readonly kind: "list";
48
+ readonly valueName: "a,b";
49
+ readonly hidden: true;
50
+ readonly help: "skip these runners, REPLACING the configured runners.disabled";
51
+ };
52
+ readonly excludePath: {
53
+ readonly kind: "list";
54
+ readonly valueName: "P";
55
+ readonly commaSeparated: false;
56
+ readonly hidden: true;
57
+ readonly help: "skip a path; repeatable. A bare name matches any segment, a value with a slash matches a path from the root";
58
+ };
59
+ readonly discovery: {
60
+ readonly kind: "enum";
61
+ readonly choices: readonly ["git", "walk", "auto"];
62
+ readonly valueName: "M";
63
+ readonly hidden: true;
64
+ readonly help: "how to find directories. Default: auto";
65
+ };
66
+ readonly config: {
67
+ readonly kind: "list";
68
+ readonly valueName: "MODULE";
69
+ readonly commaSeparated: false;
70
+ readonly help: "load extra tools from a module, this run only; repeatable";
71
+ };
72
+ }, import("zod").ZodObject<{
73
+ root: import("zod").ZodString;
74
+ filter: import("zod").ZodObject<{
75
+ query: import("zod").ZodOptional<import("zod").ZodString>;
76
+ mode: import("zod").ZodOptional<import("zod").ZodEnum<{
77
+ exact: "exact";
78
+ fuzzy: "fuzzy";
79
+ }>>;
80
+ servicesOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
81
+ declaredOnly: import("zod").ZodOptional<import("zod").ZodBoolean>;
82
+ maxDepth: import("zod").ZodOptional<import("zod").ZodNumber>;
83
+ }, import("zod/v4/core").$strip>;
84
+ source: import("zod").ZodEnum<{
85
+ fresh: "fresh";
86
+ cached: "cached";
87
+ }>;
88
+ storedAt: import("zod").ZodNullable<import("zod").ZodString>;
89
+ tasks: import("zod").ZodArray<import("zod").ZodType<unknown, unknown, import("zod/v4/core").$ZodTypeInternals<unknown, unknown>>>;
90
+ skills: import("zod").ZodArray<import("zod").ZodObject<{
91
+ id: import("zod").ZodString;
92
+ name: import("zod").ZodString;
93
+ description: import("zod").ZodNullable<import("zod").ZodString>;
94
+ argumentHint: import("zod").ZodNullable<import("zod").ZodString>;
95
+ path: import("zod").ZodString;
96
+ scope: import("zod").ZodString;
97
+ origin: import("zod").ZodString;
98
+ harnesses: import("zod").ZodArray<import("zod").ZodString>;
99
+ invoke: import("zod").ZodString;
100
+ }, import("zod/v4/core").$strip>>;
101
+ cache: import("zod").ZodArray<import("zod").ZodObject<{
102
+ runner: import("zod").ZodString;
103
+ state: import("zod").ZodEnum<{
104
+ fresh: "fresh";
105
+ stale: "stale";
106
+ miss: "miss";
107
+ }>;
108
+ reason: import("zod").ZodOptional<import("zod").ZodEnum<{
109
+ changed: "changed";
110
+ "max-age": "max-age";
111
+ excludes: "excludes";
112
+ exec: "exec";
113
+ version: "version";
114
+ tool: "tool";
115
+ }>>;
116
+ ageMs: import("zod").ZodOptional<import("zod").ZodNumber>;
117
+ estimateMs: import("zod").ZodNullable<import("zod").ZodNumber>;
118
+ slow: import("zod").ZodBoolean;
119
+ cost: import("zod").ZodOptional<import("zod").ZodEnum<{
120
+ slow: "slow";
121
+ cheap: "cheap";
122
+ }>>;
123
+ probeMs: import("zod").ZodOptional<import("zod").ZodNumber>;
124
+ }, import("zod/v4/core").$strip>>;
125
+ unknowns: import("zod").ZodArray<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
126
+ kind: import("zod").ZodLiteral<"withheld">;
127
+ runner: import("zod").ZodString;
128
+ reason: import("zod").ZodEnum<{
129
+ untrusted: "untrusted";
130
+ "tool-untrusted": "tool-untrusted";
131
+ "exec-off": "exec-off";
132
+ }>;
133
+ missing: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
134
+ label: import("zod").ZodString;
135
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
136
+ kind: import("zod").ZodLiteral<"parameters">;
137
+ runner: import("zod").ZodString;
138
+ reason: import("zod").ZodEnum<{
139
+ "exec-withheld": "exec-withheld";
140
+ "tool-missing": "tool-missing";
141
+ "tool-failed": "tool-failed";
142
+ "not-read": "not-read";
143
+ "editor-variable": "editor-variable";
144
+ }>;
145
+ tasks: import("zod").ZodArray<import("zod").ZodString>;
146
+ label: import("zod").ZodString;
147
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
148
+ kind: import("zod").ZodLiteral<"stale">;
149
+ runner: import("zod").ZodString;
150
+ reason: import("zod").ZodOptional<import("zod").ZodEnum<{
151
+ changed: "changed";
152
+ "max-age": "max-age";
153
+ excludes: "excludes";
154
+ exec: "exec";
155
+ version: "version";
156
+ tool: "tool";
157
+ }>>;
158
+ ageMs: import("zod").ZodOptional<import("zod").ZodNumber>;
159
+ label: import("zod").ZodString;
160
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
161
+ kind: import("zod").ZodLiteral<"binary">;
162
+ runner: import("zod").ZodString;
163
+ binary: import("zod").ZodString;
164
+ label: import("zod").ZodString;
165
+ }, import("zod/v4/core").$strip>], "kind">>;
166
+ }, import("zod/v4/core").$strip>>;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * `way query <terms>`: the terminal UI's search from a shell. The same
3
+ * matcher and ranking, one command line per match, as `list` prints it.
4
+ */
5
+ import { outcome } from '@osdlc/cli-tool/command';
6
+ import { hasQuery } from "../core/filter.js";
7
+ import { skillLine } from "../core/skills.js";
8
+ import { QueryOutput } from "../documents.js";
9
+ import { sourceOf } from "./list.js";
10
+ import { taskLine } from "../core/copy-text.js";
11
+ import { terminalSafe } from "../terminal-text.js";
12
+ import { FILTER_FLAGS, filterFrom, kit, noteUnknowns, openSession } from "./shared.js";
13
+ /** Make the `query` command. */
14
+ export function queryCommand(home) {
15
+ return kit.command({
16
+ summary: 'the tasks matching a search, best match first',
17
+ description: "Terms are ANDed and matched fuzzily; a leading ' makes one term match exactly, and " +
18
+ '--exact does that to all of them. No terms is every task. Matching agent skills follow ' +
19
+ 'the tasks as /<name> lines. Each task line is the one "list" prints. --output jsonl ' +
20
+ 'prints one task per line, every task when there are no terms. Exits 1 when terms ' +
21
+ 'matched nothing, as grep does. --cached answers from the last saved listing as "list --cached" does; ' +
22
+ '"source" and "storedAt" in the document say which it was.',
23
+ positionals: [{ name: 'terms', variadic: true, help: 'the search terms' }],
24
+ flags: {
25
+ ...FILTER_FLAGS,
26
+ exact: { kind: 'boolean', help: 'terms match as substrings, not subsequences' },
27
+ },
28
+ output: QueryOutput,
29
+ kind: 'query',
30
+ items: { field: 'tasks', kind: 'task' },
31
+ exits: { 1: 'the terms matched nothing' },
32
+ readOnly: true,
33
+ examples: ['query build', "query 'dev web --json", 'query test --services'],
34
+ async run({ flags, globals, positionals }, ctx) {
35
+ const filter = {
36
+ ...filterFrom(flags),
37
+ // Joined, so a quoted "dep env" is two terms.
38
+ query: positionals.join(' '),
39
+ mode: flags.exact ? 'exact' : 'fuzzy',
40
+ };
41
+ const session = await openSession(globals, ctx, home);
42
+ const snapshot = await session.catalog({ cached: flags.cached });
43
+ const unknowns = session.unknowns(snapshot);
44
+ noteUnknowns(ctx, session, snapshot, unknowns);
45
+ const tasks = session.search(snapshot.catalog, filter).map((h) => h.task);
46
+ const skills = session.searchSkills(snapshot.skills, filter).map((h) => h.skill);
47
+ const doc = {
48
+ root: snapshot.catalog.root,
49
+ filter: {
50
+ query: filter.query,
51
+ mode: filter.mode,
52
+ ...(filter.servicesOnly === true ? { servicesOnly: true } : {}),
53
+ ...(filter.declaredOnly === true ? { declaredOnly: true } : {}),
54
+ ...(filter.maxDepth !== undefined ? { maxDepth: filter.maxDepth } : {}),
55
+ },
56
+ ...sourceOf(snapshot),
57
+ tasks,
58
+ skills,
59
+ cache: snapshot.cache,
60
+ unknowns,
61
+ };
62
+ const none = tasks.length === 0 && skills.length === 0;
63
+ return hasQuery(filter) && none ? outcome(doc, 1) : doc;
64
+ },
65
+ text(doc) {
66
+ const lines = [
67
+ ...doc.tasks.map((t) => taskLine(t)),
68
+ ...doc.skills.map((s) => terminalSafe(skillLine(s))),
69
+ ];
70
+ return lines.length > 0 ? `${lines.join('\n')}\n` : '';
71
+ },
72
+ });
73
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * `way run <id> [-- args]`: run one task by id, with the argument rules the
3
+ * terminal UI and the web view use.
4
+ */
5
+ /** Make the `run` command. */
6
+ export declare function runCommand(home: string): import("@osdlc/cli-tool/command").DataCommand<{
7
+ cached: {
8
+ kind: "boolean";
9
+ help: string;
10
+ };
11
+ dryRun: {
12
+ kind: "boolean";
13
+ help: string;
14
+ };
15
+ check: {
16
+ kind: "boolean";
17
+ hidden: true;
18
+ help: string;
19
+ };
20
+ }, {
21
+ readonly dir: {
22
+ readonly kind: "string";
23
+ readonly short: "C";
24
+ readonly valueName: "PATH";
25
+ readonly help: "the directory to inspect (default: cwd)";
26
+ };
27
+ readonly exec: {
28
+ readonly kind: "tristate";
29
+ readonly help: "allow runners that must run a subprocess (moon), this run only";
30
+ readonly offHelp: "skip them, overriding a configured allowExec: true";
31
+ };
32
+ readonly only: {
33
+ readonly kind: "list";
34
+ readonly valueName: "a,b";
35
+ readonly hidden: true;
36
+ readonly help: "restrict to these runners";
37
+ };
38
+ readonly exclude: {
39
+ readonly kind: "list";
40
+ readonly valueName: "a,b";
41
+ readonly hidden: true;
42
+ readonly help: "skip these runners, REPLACING the configured runners.disabled";
43
+ };
44
+ readonly excludePath: {
45
+ readonly kind: "list";
46
+ readonly valueName: "P";
47
+ readonly commaSeparated: false;
48
+ readonly hidden: true;
49
+ readonly help: "skip a path; repeatable. A bare name matches any segment, a value with a slash matches a path from the root";
50
+ };
51
+ readonly discovery: {
52
+ readonly kind: "enum";
53
+ readonly choices: readonly ["git", "walk", "auto"];
54
+ readonly valueName: "M";
55
+ readonly hidden: true;
56
+ readonly help: "how to find directories. Default: auto";
57
+ };
58
+ readonly config: {
59
+ readonly kind: "list";
60
+ readonly valueName: "MODULE";
61
+ readonly commaSeparated: false;
62
+ readonly help: "load extra tools from a module, this run only; repeatable";
63
+ };
64
+ }, import("zod").ZodObject<{
65
+ task: import("zod").ZodString;
66
+ display: import("zod").ZodString;
67
+ argv: import("zod").ZodArray<import("zod").ZodString>;
68
+ command: import("zod").ZodString;
69
+ cwd: import("zod").ZodString;
70
+ env: import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodString>;
71
+ ran: import("zod").ZodBoolean;
72
+ exit: import("zod").ZodNullable<import("zod").ZodNumber>;
73
+ unknowns: import("zod").ZodArray<import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
74
+ kind: import("zod").ZodLiteral<"withheld">;
75
+ runner: import("zod").ZodString;
76
+ reason: import("zod").ZodEnum<{
77
+ untrusted: "untrusted";
78
+ "tool-untrusted": "tool-untrusted";
79
+ "exec-off": "exec-off";
80
+ }>;
81
+ missing: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
82
+ label: import("zod").ZodString;
83
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
84
+ kind: import("zod").ZodLiteral<"parameters">;
85
+ runner: import("zod").ZodString;
86
+ reason: import("zod").ZodEnum<{
87
+ "exec-withheld": "exec-withheld";
88
+ "tool-missing": "tool-missing";
89
+ "tool-failed": "tool-failed";
90
+ "not-read": "not-read";
91
+ "editor-variable": "editor-variable";
92
+ }>;
93
+ tasks: import("zod").ZodArray<import("zod").ZodString>;
94
+ label: import("zod").ZodString;
95
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
96
+ kind: import("zod").ZodLiteral<"stale">;
97
+ runner: import("zod").ZodString;
98
+ reason: import("zod").ZodOptional<import("zod").ZodEnum<{
99
+ changed: "changed";
100
+ "max-age": "max-age";
101
+ excludes: "excludes";
102
+ exec: "exec";
103
+ version: "version";
104
+ tool: "tool";
105
+ }>>;
106
+ ageMs: import("zod").ZodOptional<import("zod").ZodNumber>;
107
+ label: import("zod").ZodString;
108
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
109
+ kind: import("zod").ZodLiteral<"binary">;
110
+ runner: import("zod").ZodString;
111
+ binary: import("zod").ZodString;
112
+ label: import("zod").ZodString;
113
+ }, import("zod/v4/core").$strip>], "kind">>;
114
+ }, import("zod/v4/core").$strip>>;
@@ -0,0 +1,139 @@
1
+ /**
2
+ * `way run <id> [-- args]`: run one task by id, with the argument rules the
3
+ * terminal UI and the web view use.
4
+ */
5
+ import { CommandError, UsageError, outcome } from '@osdlc/cli-tool/command';
6
+ import { commandString } from '@osdlc/command-seam';
7
+ import { handOff } from "../core/run.js";
8
+ import { SessionError } from "../core/session.js";
9
+ import { RunOutput } from "../documents.js";
10
+ import { terminalSafe } from "../terminal-text.js";
11
+ import { parametersUnknownLabel } from "../vocabulary.js";
12
+ import { kit, openSession } from "./shared.js";
13
+ function runDocument(plan, ran, exit, unknowns) {
14
+ return {
15
+ task: plan.task.id,
16
+ display: plan.task.display,
17
+ argv: plan.argv,
18
+ command: commandString(plan.argv, plan.task.cwd === '.' ? {} : { cwd: plan.task.cwd }),
19
+ cwd: plan.cwd,
20
+ env: plan.env,
21
+ ran,
22
+ exit,
23
+ unknowns,
24
+ };
25
+ }
26
+ /** Make the `run` command. */
27
+ export function runCommand(home) {
28
+ return kit.command({
29
+ summary: 'run one task by id; arguments after --',
30
+ description: 'Finds the task by its id ("list --json" shows ids), or by a command line only one task ' +
31
+ 'has, as "list" prints it, and runs it in this ' +
32
+ 'terminal with the arguments after --, bound the way its tool expects (npm run x -- a, ' +
33
+ 'just x a). The same rules as Enter in the terminal UI and Run in the web view. Exits ' +
34
+ "with the task's exit code. --dry-run prints what would run instead; with --json it is " +
35
+ 'the run document. A task that uses an editor variable is not run, and neither is an ' +
36
+ 'agent skill: type its /<name> in the agent.',
37
+ positionals: [
38
+ {
39
+ name: 'id',
40
+ required: true,
41
+ help: 'the task id, as "list --json" shows it, or its line from "list"',
42
+ },
43
+ ],
44
+ rest: { name: 'args' },
45
+ flags: {
46
+ cached: {
47
+ kind: 'boolean',
48
+ help: 'find the task in the last saved listing, not a new probe; files are not checked',
49
+ },
50
+ dryRun: { kind: 'boolean', help: 'print what would run, and run nothing' },
51
+ check: {
52
+ kind: 'boolean',
53
+ hidden: true,
54
+ help: "with --cached --dry-run, probe the task's runner again as a run does",
55
+ },
56
+ },
57
+ output: RunOutput,
58
+ kind: 'run',
59
+ examples: [
60
+ 'run just:justfile:build',
61
+ 'run npm:package.json:test -- --watch',
62
+ 'run x --dry-run --json',
63
+ ],
64
+ // Running a task is the command line's; an adapter may only ask what would run.
65
+ exposureOf: (input) => (input.flags.dryRun === true ? 'all' : 'cli-only'),
66
+ async run({ flags, globals, positionals, rest }, ctx) {
67
+ if (ctx.json && !flags.dryRun) {
68
+ throw new UsageError('--json needs --dry-run: a running task writes to stdout itself');
69
+ }
70
+ const session = await openSession(globals, ctx, home);
71
+ const snapshot = await session.catalog({ cached: flags.cached });
72
+ let plan;
73
+ try {
74
+ plan = session.resolveRun(snapshot.catalog, positionals[0], rest);
75
+ }
76
+ catch (err) {
77
+ const skill = snapshot.skills.find((s) => s.id === positionals[0] || s.invoke === positionals[0]);
78
+ if (err instanceof SessionError && err.code === 'task-not-found' && skill !== undefined) {
79
+ throw new CommandError(`${skill.invoke}: a skill runs in an agent, not here`, {
80
+ code: 'not-runnable',
81
+ hint: `type ${skill.invoke} in ${skill.harnesses.join(', ')}`,
82
+ });
83
+ }
84
+ if (err instanceof SessionError) {
85
+ throw new CommandError(err.message, {
86
+ code: err.code,
87
+ ...(err.code === 'bad-arguments' ? { exit: 2 } : {}),
88
+ ...(err.hint !== undefined ? { hint: err.hint } : {}),
89
+ });
90
+ }
91
+ throw err;
92
+ }
93
+ // A task from a saved or stored listing runs only as its runner reads it
94
+ // now. A dry run is a preview, so it may come from the listing.
95
+ const probedNow = snapshot.origin === 'probe' || snapshot.origin === 'empty-store';
96
+ if (!probedNow && (!flags.dryRun || flags.check)) {
97
+ try {
98
+ plan = await session.confirmRun(plan, rest, ctx.signal);
99
+ }
100
+ catch (err) {
101
+ if (err instanceof SessionError) {
102
+ throw new CommandError(err.message, {
103
+ code: err.code,
104
+ ...(err.hint !== undefined ? { hint: err.hint } : {}),
105
+ });
106
+ }
107
+ throw err;
108
+ }
109
+ }
110
+ const unknowns = session
111
+ .unknowns(snapshot)
112
+ .filter((u) => u.runner === plan.task.runner && u.kind !== 'stale');
113
+ const reason = plan.task.parametersUnknown;
114
+ if (reason !== undefined && rest.length === 0) {
115
+ ctx.note(`${terminalSafe(plan.task.display)}: ${parametersUnknownLabel(reason)}`);
116
+ }
117
+ if (flags.dryRun)
118
+ return runDocument(plan, false, null, unknowns);
119
+ // What actually runs, not `display`: for a task with parameters they differ.
120
+ ctx.io.stderr(`$ ${terminalSafe(commandString(plan.argv))}\n`);
121
+ const ended = handOff(plan);
122
+ if (ended.error !== undefined) {
123
+ throw new CommandError(`${plan.argv[0]}: ${ended.error}`, {
124
+ code: 'spawn',
125
+ ...(snapshot.origin === 'probe'
126
+ ? {}
127
+ : {
128
+ hint: 'the task came from a stored probe and may no longer exist; run without --cached',
129
+ }),
130
+ });
131
+ }
132
+ return outcome(runDocument(plan, true, ended.exit, unknowns), ended.exit);
133
+ },
134
+ text(doc) {
135
+ // After a real run the task has printed its own output.
136
+ return doc.ran ? '' : `${terminalSafe(doc.command)}\n`;
137
+ },
138
+ });
139
+ }