ceulen 0.8.0 → 0.10.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 (122) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/extensions/lib/registry.ts +16 -3
  3. package/extensions/modules/a2a/configPanel.ts +435 -0
  4. package/extensions/modules/a2a/index.ts +1117 -0
  5. package/extensions/modules/a2a/lib/activity.ts +173 -0
  6. package/extensions/modules/a2a/lib/client.ts +1061 -0
  7. package/extensions/modules/a2a/lib/config.ts +920 -0
  8. package/extensions/modules/a2a/lib/discovery.ts +158 -0
  9. package/extensions/modules/a2a/lib/gateway.ts +889 -0
  10. package/extensions/modules/a2a/lib/mdns.ts +233 -0
  11. package/extensions/modules/a2a/lib/outcome.ts +48 -0
  12. package/extensions/modules/a2a/lib/persistence.ts +123 -0
  13. package/extensions/modules/a2a/lib/protocol.ts +506 -0
  14. package/extensions/modules/a2a/lib/registry.ts +146 -0
  15. package/extensions/modules/a2a/lib/retry.ts +86 -0
  16. package/extensions/modules/a2a/lib/security.ts +394 -0
  17. package/extensions/modules/a2a/lib/server.ts +1436 -0
  18. package/extensions/modules/a2a/test/activity.test.ts +138 -0
  19. package/extensions/modules/a2a/test/bridge.test.ts +101 -0
  20. package/extensions/modules/a2a/test/broadcast-parse.test.ts +31 -0
  21. package/extensions/modules/a2a/test/chai.ts +101 -0
  22. package/extensions/modules/a2a/test/client.test.ts +856 -0
  23. package/extensions/modules/a2a/test/completion-guard.test.ts +73 -0
  24. package/extensions/modules/a2a/test/config.test.ts +1396 -0
  25. package/extensions/modules/a2a/test/configPanel.test.ts +393 -0
  26. package/extensions/modules/a2a/test/discovery.test.ts +144 -0
  27. package/extensions/modules/a2a/test/extension.test.ts +135 -0
  28. package/extensions/modules/a2a/test/gateway.test.ts +1449 -0
  29. package/extensions/modules/a2a/test/helpers.ts +39 -0
  30. package/extensions/modules/a2a/test/mdns.test.ts +131 -0
  31. package/extensions/modules/a2a/test/outcome.test.ts +61 -0
  32. package/extensions/modules/a2a/test/persistence.test.ts +92 -0
  33. package/extensions/modules/a2a/test/protocol.test.ts +217 -0
  34. package/extensions/modules/a2a/test/registry.test.ts +114 -0
  35. package/extensions/modules/a2a/test/retry.test.ts +136 -0
  36. package/extensions/modules/a2a/test/security.test.ts +281 -0
  37. package/extensions/modules/a2a/test/server.test.ts +1966 -0
  38. package/extensions/modules/a2a/test/tmp.ts +59 -0
  39. package/extensions/modules/a2a/test/vendor.test.ts +57 -0
  40. package/extensions/modules/a2a/types/bonjour-service.d.ts +22 -0
  41. package/extensions/modules/a2a/vendor/VENDORED.md +18 -0
  42. package/extensions/modules/a2a/vendor/package.json +1 -0
  43. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/LICENSE +23 -0
  44. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.d.ts +14 -0
  45. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.js +57 -0
  46. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.d.ts +4 -0
  47. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.js +3 -0
  48. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.d.ts +13 -0
  49. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.js +50 -0
  50. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.d.ts +41 -0
  51. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.js +209 -0
  52. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.d.ts +9 -0
  53. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.js +42 -0
  54. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.d.ts +14 -0
  55. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.js +119 -0
  56. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.d.ts +14 -0
  57. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.js +142 -0
  58. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.d.ts +7 -0
  59. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.js +53 -0
  60. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.d.ts +58 -0
  61. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.js +130 -0
  62. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.d.ts +1 -0
  63. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.js +13 -0
  64. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.d.ts +1 -0
  65. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.js +17 -0
  66. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.d.ts +4 -0
  67. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.js +22 -0
  68. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.d.ts +3 -0
  69. package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.js +6 -0
  70. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/LICENSE +21 -0
  71. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/classes.js +23 -0
  72. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/index.js +1761 -0
  73. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/opcodes.js +50 -0
  74. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/optioncodes.js +59 -0
  75. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/rcodes.js +50 -0
  76. package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/types.js +103 -0
  77. package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/LICENSE +21 -0
  78. package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/es6.js +73 -0
  79. package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/index.js +46 -0
  80. package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/LICENSE +21 -0
  81. package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/index.cjs +250 -0
  82. package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/LICENSE +21 -0
  83. package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/index.js +205 -0
  84. package/extensions/modules/a2a/vendor/vendored_deps/thunky/LICENSE +21 -0
  85. package/extensions/modules/a2a/vendor/vendored_deps/thunky/index.js +55 -0
  86. package/extensions/modules/composer/test/module.test.ts +2 -2
  87. package/extensions/modules/config/index.ts +3 -0
  88. package/extensions/modules/config/test/renderTools.test.ts +1 -1
  89. package/extensions/modules/gh/configPanel.ts +82 -0
  90. package/extensions/modules/gh/index.ts +86 -0
  91. package/extensions/modules/gh/lib/gh-cli.ts +337 -0
  92. package/extensions/modules/gh/lib/ops.ts +771 -0
  93. package/extensions/modules/gh/test/gh.test.ts +280 -0
  94. package/extensions/modules/plan/lib/plan-tools.ts +8 -0
  95. package/extensions/modules/repair/index.ts +138 -0
  96. package/extensions/modules/repair/lib/guards.ts +1 -1
  97. package/extensions/modules/repair/lib/read-selector.ts +242 -0
  98. package/extensions/modules/repair/test/read-selector.test.ts +198 -0
  99. package/extensions/modules/steering/configPanel.ts +8 -0
  100. package/extensions/modules/steering/index.ts +6 -0
  101. package/extensions/modules/steering/lib/settings.ts +6 -2
  102. package/extensions/modules/steering/lib/think.ts +66 -0
  103. package/extensions/modules/steering/test/harness.ts +5 -0
  104. package/extensions/modules/steering/test/settings.test.ts +2 -0
  105. package/extensions/modules/steering/test/think.test.ts +77 -0
  106. package/extensions/modules/todo/configPanel.ts +55 -0
  107. package/extensions/modules/todo/index.ts +46 -13
  108. package/extensions/modules/todo/lib/render.ts +271 -0
  109. package/extensions/modules/todo/lib/settings.ts +73 -0
  110. package/extensions/modules/todo/test/todo.test.ts +276 -0
  111. package/extensions/modules/web/index.ts +37 -1
  112. package/extensions/modules/web/lib/a11y.ts +252 -0
  113. package/extensions/modules/web/test/a11y.test.ts +218 -0
  114. package/extensions/modules/web/test/extension.test.ts +2 -2
  115. package/extensions/modules/web/test/hook.test.ts +2 -2
  116. package/extensions/modules/web/vendor/axe/LICENSE +362 -0
  117. package/extensions/modules/web/vendor/axe/LICENSE-3RD-PARTY.txt +66 -0
  118. package/extensions/modules/web/vendor/axe/README.md +19 -0
  119. package/extensions/modules/web/vendor/axe/axe.min.js +12 -0
  120. package/package.json +2 -2
  121. package/skills/a2a/SKILL.md +63 -0
  122. package/skills/web/SKILL.md +1 -0
@@ -0,0 +1,280 @@
1
+ // gh module unit tests — every op against an injected GhRunner fake.
2
+ // No network, no gh binary: arg building, scoping, formatting, error
3
+ // surfacing, and the run_watch poll loop (scripted statuses, tiny intervals).
4
+
5
+ import assert from "node:assert/strict";
6
+ import { describe, it } from "node:test";
7
+ import {
8
+ formatGhFailure,
9
+ ghAvailable,
10
+ parseRepoRef,
11
+ repoFromUrl,
12
+ ghApiHostArgs,
13
+ githubRepoSlugEquals,
14
+ type GhCommandOptions,
15
+ type GhRunner,
16
+ } from "../lib/gh-cli.js";
17
+ import {
18
+ buildSearchDateQualifier,
19
+ executeFileRead,
20
+ executeOp,
21
+ executePrDiff,
22
+ executePrView,
23
+ executeRepoView,
24
+ executeRunWatch,
25
+ executeSearchCode,
26
+ executeSearchIssues,
27
+ executeSearchPrs,
28
+ executeSearchRepos,
29
+ isFailedJob,
30
+ parseRunReference,
31
+ parseSearchDateBound,
32
+ resolveTailLimit,
33
+ } from "../lib/ops.js";
34
+
35
+ /** Scripted fake: maps `gh <first args>` prefixes to canned responses. */
36
+ function fakeGh(routes: { match: (args: string[]) => boolean; respond: (args: string[]) => { exitCode?: number; stdout?: string; stderr?: string } }[]): { gh: GhRunner; calls: string[][] } {
37
+ const calls: string[][] = [];
38
+ const gh: GhRunner = {
39
+ async run(_cwd, args) {
40
+ calls.push(args);
41
+ const route = routes.find((r) => r.match(args));
42
+ if (!route) throw new Error(`fakeGh: no route for gh ${args.join(" ")}`);
43
+ const r = route.respond(args);
44
+ return { exitCode: r.exitCode ?? 0, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
45
+ },
46
+ async json(cwd, args, signal, options) {
47
+ const r = await this.run(cwd, args, signal, options);
48
+ if (r.exitCode !== 0) throw new Error(formatGhFailure(args, r.stdout, r.stderr, options));
49
+ return JSON.parse(r.stdout);
50
+ },
51
+ async text(cwd, args, signal, options) {
52
+ const r = await this.run(cwd, args, signal, options);
53
+ if (r.exitCode !== 0) throw new Error(formatGhFailure(args, r.stdout, r.stderr, options));
54
+ return r.stdout;
55
+ },
56
+ };
57
+ return { gh, calls };
58
+ }
59
+
60
+ const CWD = "/tmp/fake-checkout";
61
+
62
+ describe("repo-ref normalization (gh-cli)", () => {
63
+ it("splits [host/]owner/repo", () => {
64
+ assert.deepEqual(parseRepoRef("owner/repo"), { slug: "owner/repo" });
65
+ assert.deepEqual(parseRepoRef("ghe.example.com/owner/repo"), { host: "ghe.example.com", slug: "owner/repo" });
66
+ assert.deepEqual(parseRepoRef("justaname"), { slug: "justaname" });
67
+ });
68
+
69
+ it("keeps non-default hosts in URLs, drops github.com", () => {
70
+ delete process.env.GH_HOST;
71
+ assert.equal(repoFromUrl("https://github.com/a/b"), "a/b");
72
+ assert.equal(repoFromUrl("https://ghe.example.com/a/b"), "ghe.example.com/a/b");
73
+ assert.equal(repoFromUrl("not a url"), undefined);
74
+ });
75
+
76
+ it("ghApiHostArgs only names non-default hosts", () => {
77
+ assert.deepEqual(ghApiHostArgs({ slug: "a/b" }), []);
78
+ assert.deepEqual(ghApiHostArgs({ host: "ghe.example.com", slug: "a/b" }), ["--hostname", "ghe.example.com"]);
79
+ });
80
+
81
+ it("host-less refs compare against GH_HOST, not as wildcards", () => {
82
+ delete process.env.GH_HOST;
83
+ assert.equal(githubRepoSlugEquals("a/b", "ghe.example.com/a/b"), false);
84
+ assert.equal(githubRepoSlugEquals("a/b", "A/B"), true);
85
+ });
86
+ });
87
+
88
+ describe("search ops", () => {
89
+ it("search_issues scopes to the cwd repo and adds is:issue", async () => {
90
+ const { gh, calls } = fakeGh([
91
+ { match: (a) => a[0] === "repo" && a[1] === "view", respond: () => ({ stdout: "https://github.com/acme/widget" }) },
92
+ { match: (a) => a[0] === "api", respond: () => ({ stdout: JSON.stringify({ total_count: 1, items: [{ number: 7, title: "Bug", state: "OPEN", repository_url: "https://api.github.com/repos/acme/widget" }] }) }) },
93
+ ]);
94
+ const text = await executeSearchIssues(gh, CWD, { query: "crash" });
95
+ assert.match(text, /#7 Bug/);
96
+ assert.match(text, /Repo: acme\/widget/);
97
+ const apiArgs = calls.find((a) => a[0] === "api")!;
98
+ const q = apiArgs.find((x) => x.startsWith("q="))!;
99
+ assert.equal(q, "q=crash repo:acme/widget is:issue");
100
+ assert.ok(apiArgs.includes("/search/issues"));
101
+ });
102
+
103
+ it("search_prs uses is:pr over the issues endpoint", async () => {
104
+ const { gh } = fakeGh([
105
+ { match: (a) => a[0] === "repo" && a[1] === "view", respond: () => ({ stdout: "https://github.com/acme/widget" }) },
106
+ { match: (a) => a[0] === "api", respond: () => ({ stdout: JSON.stringify({ items: [] }) }) },
107
+ ]);
108
+ const text = await executeSearchPrs(gh, CWD, { query: "release" });
109
+ assert.match(text, /No pull requests found/);
110
+ });
111
+
112
+ it("an explicit repo: qualifier in the query suppresses the default scope", async () => {
113
+ const { gh, calls } = fakeGh([
114
+ { match: (a) => a[0] === "api", respond: () => ({ stdout: JSON.stringify({ items: [] }) }) },
115
+ ]);
116
+ await executeSearchIssues(gh, CWD, { query: "repo:other/thing crash" });
117
+ const apiArgs = calls.find((a) => a[0] === "api")!;
118
+ const q = apiArgs.find((x) => x.startsWith("q="))!;
119
+ assert.equal(q, "q=repo:other/thing crash is:issue");
120
+ });
121
+
122
+ it("search_code rejects since/until and passes the text-match header", async () => {
123
+ const { gh } = fakeGh([]);
124
+ await assert.rejects(() => executeSearchCode(gh, CWD, { query: "x", since: "3d" }), /no date qualifier/);
125
+ });
126
+
127
+ it("search_code builds the code endpoint query", async () => {
128
+ const { gh, calls } = fakeGh([
129
+ { match: (a) => a[0] === "repo" && a[1] === "view", respond: () => ({ stdout: "https://github.com/acme/widget" }) },
130
+ { match: (a) => a[0] === "api", respond: () => ({ stdout: JSON.stringify({ items: [{ path: "src/a.ts", sha: "abcdef123456", repository: { full_name: "acme/widget" }, text_matches: [{ fragment: "hello world" }] }] }) }) },
131
+ ]);
132
+ const text = await executeSearchCode(gh, CWD, { query: "hello" });
133
+ assert.match(text, /src\/a\.ts/);
134
+ assert.match(text, /Match: hello world/);
135
+ const apiArgs = calls.find((a) => a[0] === "api")!;
136
+ assert.ok(apiArgs.includes("-H") && apiArgs.includes("Accept: application/vnd.github.text-match+json"));
137
+ });
138
+
139
+ it("search_repos needs no repo scope", async () => {
140
+ const { gh, calls } = fakeGh([
141
+ { match: (a) => a[0] === "api", respond: () => ({ stdout: JSON.stringify({ items: [{ full_name: "acme/widget", stargazers_count: 42 }] }) }) },
142
+ ]);
143
+ const text = await executeSearchRepos(gh, CWD, { query: "widget" });
144
+ assert.match(text, /acme\/widget/);
145
+ assert.match(text, /Stars: 42/);
146
+ assert.equal(calls.find((a) => a[0] === "repo"), undefined);
147
+ });
148
+
149
+ it("since/until compose a date qualifier", () => {
150
+ assert.equal(buildSearchDateQualifier("created", "2026-01-01", "2026-02-01"), "created:2026-01-01..2026-02-01");
151
+ assert.equal(buildSearchDateQualifier("created", "3d", undefined, new Date("2026-10-05T00:00:00Z")), "created:>=2026-10-02");
152
+ assert.equal(parseSearchDateBound("2w", new Date("2026-10-05T00:00:00Z")), "2026-09-21");
153
+ });
154
+ });
155
+
156
+ describe("repo_view / file_read", () => {
157
+ it("repo_view renders metadata", async () => {
158
+ const { gh, calls } = fakeGh([
159
+ { match: (a) => a[0] === "repo", respond: () => ({ stdout: JSON.stringify({ nameWithOwner: "acme/widget", description: "A widget", url: "https://github.com/acme/widget", stargazerCount: 5, defaultBranchRef: { name: "main" } }) }) },
160
+ ]);
161
+ const text = await executeRepoView(gh, CWD, { repo: "acme/widget" });
162
+ assert.match(text, /# acme\/widget/);
163
+ assert.match(text, /Default branch: main/);
164
+ assert.match(text, /Stars: 5/);
165
+ assert.ok(calls[0].includes("--json"));
166
+ });
167
+
168
+ it("file_read decodes base64 text and caps size", async () => {
169
+ const content = Buffer.from("hello github").toString("base64");
170
+ const { gh, calls } = fakeGh([
171
+ { match: (a) => a[0] === "api", respond: () => ({ stdout: JSON.stringify({ type: "file", encoding: "base64", content, html_url: "https://github.com/acme/widget/blob/main/README.md" }) }) },
172
+ ]);
173
+ const r = await executeFileRead(gh, CWD, { repo: "acme/widget", path: "README.md" });
174
+ assert.match(r.text, /hello github/);
175
+ const apiArgs = calls.find((a) => a[0] === "api")!;
176
+ assert.ok(apiArgs.some((x) => x.includes("/repos/acme/widget/contents/README.md")));
177
+ });
178
+
179
+ it("file_read flags binary content and returns the image block for images", async () => {
180
+ const binary = Buffer.from([0x00, 0x01, 0x02]).toString("base64");
181
+ const png = Buffer.from("89504e47", "hex").toString("base64");
182
+ const { gh } = fakeGh([
183
+ { match: (a) => a.some((x) => String(x).includes("bin.dat")), respond: () => ({ stdout: JSON.stringify({ encoding: "base64", content: binary }) }) },
184
+ { match: (a) => a.some((x) => String(x).includes("img.png")), respond: () => ({ stdout: JSON.stringify({ encoding: "base64", content: png }) }) },
185
+ ]);
186
+ const bin = await executeFileRead(gh, CWD, { repo: "acme/widget", path: "bin.dat" });
187
+ assert.match(bin.text, /Cannot read binary file/);
188
+ const img = await executeFileRead(gh, CWD, { repo: "acme/widget", path: "img.png" });
189
+ assert.equal(img.image?.mimeType, "image/png");
190
+ });
191
+ });
192
+
193
+ describe("pr_view / pr_diff", () => {
194
+ it("pr_view accepts a URL and prefers its repo", async () => {
195
+ const { gh, calls } = fakeGh([
196
+ { match: (a) => a[0] === "pr", respond: () => ({ stdout: JSON.stringify({ number: 9, title: "Add feature", state: "OPEN", files: [{ path: "a.ts", additions: 1, deletions: 0 }] }) }) },
197
+ ]);
198
+ const text = await executePrView(gh, CWD, { pr: "https://github.com/acme/widget/pull/9" });
199
+ assert.match(text, /# Pull Request #9: Add feature/);
200
+ assert.match(text, /a\.ts \[CHANGED\] \(\+1 -0\)/);
201
+ const prArgs = calls.find((a) => a[0] === "pr")!;
202
+ // URL identifier → no competing --repo flag (OMP appendRepoFlag).
203
+ assert.equal(prArgs.includes("--repo"), false);
204
+ });
205
+
206
+ it("pr_diff passes through the unified diff", async () => {
207
+ const { gh } = fakeGh([
208
+ { match: (a) => a[0] === "pr", respond: () => ({ stdout: "diff --git a/x b/x\n" }) },
209
+ ]);
210
+ const text = await executePrDiff(gh, CWD, { repo: "acme/widget", pr: "9" });
211
+ assert.match(text, /diff --git a\/x b\/x/);
212
+ });
213
+ });
214
+
215
+ describe("run_watch", () => {
216
+ it("parses run references", () => {
217
+ assert.deepEqual(parseRunReference("12345"), { runId: 12345 });
218
+ // The host is KEPT (OMP parity): a ref that names a host pins the request to it.
219
+ assert.deepEqual(parseRunReference("https://github.com/a/b/actions/runs/77/attempt/1"), { repo: "github.com/a/b", runId: 77 });
220
+ assert.throws(() => parseRunReference("not-a-run"), /numeric workflow run ID/);
221
+ });
222
+
223
+ it("tails failed-job logs on failure", async () => {
224
+ const completed = { id: 1, name: "CI", status: "completed", conclusion: "failure", html_url: "https://ci/1" };
225
+ const { gh } = fakeGh([
226
+ { match: (a) => a[0] === "repo" && a[1] === "view", respond: () => ({ stdout: "https://github.com/acme/widget" }) },
227
+ { match: (a) => a.some((x) => String(x).endsWith("/actions/runs/1")), respond: () => ({ stdout: JSON.stringify(completed) }) },
228
+ { match: (a) => a.some((x) => String(x).includes("/actions/runs/1/jobs")), respond: () => ({ stdout: JSON.stringify({ jobs: [{ id: 11, name: "build", status: "completed", conclusion: "failure" }] }) }) },
229
+ { match: (a) => a.some((x) => String(x).includes("/actions/jobs/11/logs")), respond: () => ({ stdout: "l1\nl2\nl3" }) },
230
+ ]);
231
+ const text = await executeRunWatch(gh, CWD, { run: "1", tail: 2 }, undefined, 5_000);
232
+ assert.match(text, /Run failed\./);
233
+ assert.match(text, /l2\nl3/); // tail=2 keeps the last two lines
234
+ });
235
+
236
+ it("reports the still-running state when the budget elapses", async () => {
237
+ const inProgress = { id: 2, name: "CI", status: "in_progress", html_url: "https://ci/2" };
238
+ const { gh } = fakeGh([
239
+ { match: (a) => a[0] === "repo" && a[1] === "view", respond: () => ({ stdout: "https://github.com/acme/widget" }) },
240
+ { match: (a) => a.some((x) => String(x).endsWith("/actions/runs/2")), respond: () => ({ stdout: JSON.stringify(inProgress) }) },
241
+ { match: (a) => a.some((x) => String(x).includes("/actions/runs/2/jobs")), respond: () => ({ stdout: JSON.stringify({ jobs: [] }) }) },
242
+ ]);
243
+ const text = await executeRunWatch(gh, CWD, { run: "2" }, undefined, 1);
244
+ assert.match(text, /watch budget elapsed/);
245
+ });
246
+
247
+ it("classifies failed jobs and clamps tail", () => {
248
+ assert.equal(isFailedJob({ id: 1, name: "j", conclusion: "failure" }), true);
249
+ assert.equal(isFailedJob({ id: 1, name: "j", conclusion: "success" }), false);
250
+ assert.equal(isFailedJob({ id: 1, name: "j", conclusion: undefined }), false);
251
+ assert.equal(resolveTailLimit(undefined), 15);
252
+ assert.equal(resolveTailLimit(999_999), 200);
253
+ assert.throws(() => resolveTailLimit(0), /positive/);
254
+ });
255
+ });
256
+
257
+ describe("dispatcher + availability", () => {
258
+ it("unknown op throws", async () => {
259
+ const { gh } = fakeGh([]);
260
+ await assert.rejects(() => executeOp("pr_merge", gh, CWD, {}), /Unknown github op/);
261
+ });
262
+
263
+ it("ghAvailable returns a boolean without throwing", () => {
264
+ assert.equal(typeof ghAvailable(), "boolean");
265
+ });
266
+
267
+ it("formatGhFailure maps auth and checkout failures", () => {
268
+ assert.match(formatGhFailure([], "", "run gh auth login first"), /not authenticated/);
269
+ assert.match(
270
+ formatGhFailure([], "", "fatal: not a git repository"),
271
+ /Pass `repo` explicitly/,
272
+ );
273
+ assert.equal(formatGhFailure(["repo", "view"], "", ""), "GitHub CLI command failed: gh repo view");
274
+ // An explicit repo suppresses the checkout hint.
275
+ assert.equal(
276
+ formatGhFailure(["repo", "view"], "", "fatal: not a git repository", { repoProvided: true } satisfies GhCommandOptions),
277
+ "fatal: not a git repository",
278
+ );
279
+ });
280
+ });
@@ -25,6 +25,14 @@ export const READ_ONLY_TOOLS = new Set([
25
25
  "ux_audit",
26
26
  // Decision model: typed questions about caller-supplied state, no side effects.
27
27
  "classify",
28
+ // GitHub tool — v1 surface is strictly read-only (views, searches, run_watch);
29
+ // mutating ops must never be added without re-checking this tier.
30
+ "github",
31
+ // OMP-parity scratchpad — no side effects; thoughts stay in the transcript.
32
+ "think",
33
+ // Rendered-page accessibility audit — reads the page in a local headless
34
+ // Chrome, mutates nothing.
35
+ "web_a11y",
28
36
  // NOTE: herdr is deliberately NOT here — its prompt action can drive a
29
37
  // write-capable child, so every herdr call takes the confirm tier.
30
38
  ]);
@@ -57,6 +57,112 @@ import { checkDangerousCommand, isRecord, looksLikeCodePath } from "./lib/guards
57
57
  import { repairToolArguments, type RepairKind } from "./lib/input-repair.js";
58
58
  import { applyPatchToFiles, parsePatch, PatchParseError } from "./lib/patch.js";
59
59
  import { readRepairSettings } from "./lib/settings.js";
60
+ import {
61
+ extractConflictBlocks,
62
+ isMultiRange,
63
+ peelPathSelector,
64
+ resolveTailSelector,
65
+ selToOffsetLimit,
66
+ type ParsedSelector,
67
+ } from "./lib/read-selector.js";
68
+
69
+ // ── Read path selectors (OMP grammar — see lib/read-selector.ts) ──
70
+
71
+ /** Non-enumerable stash marker so host schema validation never sees it. */
72
+ function stashSelector(args: Record<string, unknown>, selector: ParsedSelector): void {
73
+ Object.defineProperty(args, "__mtSelector", { value: selector, enumerable: false, configurable: true });
74
+ }
75
+
76
+ /**
77
+ * Peel `path:selector` (execute-time — needs ctx.cwd for the existence
78
+ * probes). A literal path that exists ALWAYS wins (OMP issue #4618) — the
79
+ * selector is peeled only when the raw path is missing and the suffix parses.
80
+ * Single-range selectors translate straight to offset/limit; tail / multi-
81
+ * range / conflicts / raw return a stash for readWithSelector (they need the
82
+ * file's bytes or line count).
83
+ */
84
+ function applyReadSelector(args: Record<string, unknown>, cwd: string): unknown {
85
+ if (!isRecord(args) || typeof args.path !== "string") return args;
86
+ const raw = args.path;
87
+ const colonIdx = raw.lastIndexOf(":");
88
+ if (colonIdx <= 0) return args;
89
+ if (existsSync(resolvePath(cwd, raw))) return args; // literal wins
90
+ let peeled: { stem: string; selector?: ParsedSelector };
91
+ try {
92
+ peeled = peelPathSelector(raw);
93
+ } catch (err) {
94
+ throw new Error(err instanceof Error ? err.message : String(err));
95
+ }
96
+ if (!peeled.selector || !existsSync(resolvePath(cwd, peeled.stem))) return args;
97
+ const out: Record<string, unknown> = { ...args, path: peeled.stem };
98
+ const sel = peeled.selector;
99
+ if (sel.kind === "lines" && !isMultiRange(sel)) {
100
+ // Single range → the built-in's own offset/limit machinery.
101
+ const { offset, limit } = selToOffsetLimit(sel);
102
+ if (offset !== undefined) out.offset = offset;
103
+ if (limit !== undefined) out.limit = limit;
104
+ if (sel.raw !== true) return out;
105
+ }
106
+ stashSelector(out, sel);
107
+ return out;
108
+ }
109
+
110
+ /** In-memory slice for multi-range / raw / conflicts selectors. */
111
+ async function readWithSelector(
112
+ stem: string,
113
+ cwd: string,
114
+ selector: ParsedSelector,
115
+ paramsOffset: number | undefined,
116
+ paramsLimit: number | undefined,
117
+ ): Promise<{ content: Array<{ type: "text"; text: string }>; details?: unknown }> {
118
+ const buf = await readFile(resolvePath(cwd, stem));
119
+ const text = buf.toString("utf-8");
120
+ const lines = text.split("\n");
121
+ // A trailing newline is a terminator, not a 101st line — drop the phantom
122
+ // empty tail element so totals and :-N tails match editor line numbers.
123
+ if (lines.length > 1 && lines[lines.length - 1] === "") lines.pop();
124
+ const total = lines.length;
125
+ let sel: Exclude<ParsedSelector, { kind: "tail" }>;
126
+ try {
127
+ sel = resolveTailSelector(selector, total);
128
+ } catch (err) {
129
+ throw new Error(err instanceof Error ? err.message : String(err));
130
+ }
131
+
132
+ if (sel.kind === "conflicts") {
133
+ const blocks = extractConflictBlocks(lines);
134
+ if (blocks.length === 0) return { content: [{ type: "text", text: `No merge conflicts in ${stem}.` }] };
135
+ const body = blocks.map((b) => b.join("\n")).join("\n");
136
+ return {
137
+ content: [{ type: "text", text: `[${blocks.length} conflict block(s) in ${stem}]\n${body}` }],
138
+ };
139
+ }
140
+
141
+ if (sel.kind === "lines" && isMultiRange(sel)) {
142
+ const parts: string[] = [];
143
+ for (const range of sel.ranges) {
144
+ const end = Math.min(range.endLine ?? total, total);
145
+ const slice = lines.slice(range.startLine - 1, end);
146
+ parts.push(`── lines ${range.startLine}-${end} of ${total} ──\n${slice.join("\n")}`);
147
+ }
148
+ const shown = sel.ranges.reduce((acc, r) => acc + (Math.min(r.endLine ?? total, total) - r.startLine + 1), 0);
149
+ return {
150
+ content: [{ type: "text", text: `[lines ${sel.ranges.map((r) => `${r.startLine}-${r.endLine ?? total}`).join(", ")} of ${total} total — ${shown} lines shown]\n\n${parts.join("\n\n")}` }],
151
+ };
152
+ }
153
+
154
+ // Single range (explicit or a resolved :-N tail) or :raw — pi's read is
155
+ // already unprefixed, so slice here from the resolved range; params
156
+ // offset/limit only fill in when the selector carried none (:raw + args).
157
+ const range = sel.kind === "lines" ? sel.ranges[0] : undefined;
158
+ const offset = range?.startLine ?? paramsOffset ?? 1;
159
+ const limit = range ? (range.endLine !== undefined ? range.endLine - range.startLine + 1 : undefined) : paramsLimit;
160
+ const end = limit !== undefined ? offset + limit - 1 : total;
161
+ const slice = lines.slice(offset - 1, Math.min(end, total));
162
+ return {
163
+ content: [{ type: "text", text: `[lines ${offset}-${Math.min(end, total)} of ${total}]\n${slice.join("\n")}` }],
164
+ };
165
+ }
60
166
 
61
167
  // ── Wrapper helpers (ported from upstream extensions/index.ts) ──
62
168
 
@@ -130,6 +236,12 @@ export function wrapToolDefinition(
130
236
  ): any {
131
237
  return {
132
238
  ...base,
239
+ // The selector grammar sits in the wrapped read's description, which binds
240
+ // per wrapped instance (cache-safe: byte-stable for the session).
241
+ description:
242
+ base.name === "read"
243
+ ? `${base.description}\n\nPath suffixes: file.ts:50 starts at line 50; :50-200 inclusive; :50+150 counts lines; :50- to EOF; :-60 last 60 lines; commas join ranges (:5-16,960-973) or single lines (:19,59); :conflicts lists merge-conflict blocks; :raw compounds with a range. A literal path that exists always wins over selector parsing.`
244
+ : base.description,
133
245
  prepareArguments(args: unknown) {
134
246
  let prepared = base.prepareArguments ? base.prepareArguments(args as never) : args;
135
247
  if (shouldRepair()) {
@@ -150,6 +262,30 @@ export function wrapToolDefinition(
150
262
  const freshDef = factory(cwd);
151
263
  const readNote = base.name === "read" && isRecord(params) ? params.__mtReadNote : undefined;
152
264
  if (isRecord(params)) delete params.__mtReadNote;
265
+ const selector: ParsedSelector | undefined =
266
+ base.name === "read" && isRecord(params) ? (params.__mtSelector as ParsedSelector | undefined) : undefined;
267
+ if (isRecord(params)) delete params.__mtSelector;
268
+
269
+ // Selector peel (execute-time: needs ctx.cwd for the literal-wins probe).
270
+ if (base.name === "read" && !selector && isRecord(params) && typeof params.path === "string" && params.path.includes(":")) {
271
+ params = applyReadSelector(params, cwd);
272
+ }
273
+ const peeledSelector: ParsedSelector | undefined =
274
+ base.name === "read" && isRecord(params) ? (params.__mtSelector as ParsedSelector | undefined) : undefined;
275
+ if (isRecord(params)) delete params.__mtSelector;
276
+
277
+ // Selector slice path: multi-range / tail / conflicts / raw need the
278
+ // file's bytes, which the built-in read can't hand back pre-slice.
279
+ if (base.name === "read" && (selector ?? peeledSelector) && isRecord(params) && typeof params.path === "string") {
280
+ const result = await readWithSelector(
281
+ params.path,
282
+ cwd,
283
+ (selector ?? peeledSelector)!,
284
+ typeof params.offset === "number" ? params.offset : undefined,
285
+ typeof params.limit === "number" ? params.limit : undefined,
286
+ );
287
+ return { ...result, details: base.name === "read" ? undefined : result.details };
288
+ }
153
289
 
154
290
  if (base.name !== "edit") {
155
291
  try {
@@ -261,6 +397,8 @@ export default function repairModule(pi: ExtensionAPI) {
261
397
 
262
398
  // ── Wrapped built-ins, registered ONCE each ──
263
399
  const toolFactories: Record<string, (cwd: string) => any> = {
400
+ // The selector grammar sits in the wrapped read's description, which binds
401
+ // ONCE at load (cache-safe request head — autoBg precedent).
264
402
  read: createReadToolDefinition,
265
403
  write: createWriteToolDefinition,
266
404
  edit: createEditToolDefinition,
@@ -16,7 +16,7 @@ function normalizedTarget(value: unknown): string {
16
16
 
17
17
  /** True when the value looks like an indexable source file (extension match). */
18
18
  export function looksLikeCodePath(value: unknown): boolean {
19
- return /\.(ts|tsx|js|jsx|mjs|cjs|mts|cts|py|go|rs|java|kt|kts|scala|rb|php|cs|cpp|cc|cxx|c|h|hpp|swift|sh|bash|zsh|fish|lua|r|jl|ex|exs|erl|hrl|clj|cljs|fs|fsx|ml|mli|dart|vue|svelte)$/i.test(normalizedTarget(value));
19
+ return /\.(ts|tsx|js|jsx|mjs|cjs|mts|cts|py|go|rs|java|kt|kts|scala|rb|php|cs|cpp|cc|cxx|c|h|hpp|swift|sh|bash|zsh|fish|lua|r|jl|ex|exs|erl|hrl|clj|cljs|fs|fsx|ml|mli|dart|vue|svelte)$/i.test(normalizedTarget(value).replace(/:\d.*$/, ""));
20
20
  }
21
21
 
22
22
  /** Returns a human reason when a bash command is destructively dangerous. */