ceulen 0.9.0 → 0.10.1

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 (52) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/extensions/lib/registry.ts +8 -2
  3. package/extensions/lib/skill-path.test.ts +35 -0
  4. package/extensions/lib/skill-path.ts +22 -0
  5. package/extensions/modules/a2a/index.ts +2 -2
  6. package/extensions/modules/a2a/lib/config.ts +1 -1
  7. package/extensions/modules/a2a/lib/registry.ts +1 -1
  8. package/extensions/modules/composer/index.ts +19 -1
  9. package/extensions/modules/composer/lib/footer.ts +7 -7
  10. package/extensions/modules/composer/lib/shapes.ts +237 -112
  11. package/extensions/modules/composer/test/editor.test.ts +3 -3
  12. package/extensions/modules/composer/test/footer.test.ts +1 -1
  13. package/extensions/modules/composer/test/module.test.ts +8 -7
  14. package/extensions/modules/composer/test/screen.test.ts +10 -9
  15. package/extensions/modules/composer/test/shapes.test.ts +83 -61
  16. package/extensions/modules/config/index.ts +1 -0
  17. package/extensions/modules/config/test/renderTools.test.ts +1 -1
  18. package/extensions/modules/gh/configPanel.ts +82 -0
  19. package/extensions/modules/gh/index.ts +86 -0
  20. package/extensions/modules/gh/lib/gh-cli.ts +337 -0
  21. package/extensions/modules/gh/lib/ops.ts +771 -0
  22. package/extensions/modules/gh/test/gh.test.ts +280 -0
  23. package/extensions/modules/munin/index.ts +2 -2
  24. package/extensions/modules/plan/lib/plan-tools.ts +8 -0
  25. package/extensions/modules/ponytail/index.ts +2 -2
  26. package/extensions/modules/repair/index.ts +138 -0
  27. package/extensions/modules/repair/lib/guards.ts +1 -1
  28. package/extensions/modules/repair/lib/read-selector.ts +242 -0
  29. package/extensions/modules/repair/lib/settings.ts +1 -1
  30. package/extensions/modules/repair/test/read-selector.test.ts +198 -0
  31. package/extensions/modules/router/lib/provider.ts +13 -9
  32. package/extensions/modules/steering/configPanel.ts +8 -0
  33. package/extensions/modules/steering/index.ts +6 -0
  34. package/extensions/modules/steering/lib/settings.ts +6 -2
  35. package/extensions/modules/steering/lib/think.ts +66 -0
  36. package/extensions/modules/steering/test/harness.ts +5 -0
  37. package/extensions/modules/steering/test/settings.test.ts +2 -0
  38. package/extensions/modules/steering/test/think.test.ts +77 -0
  39. package/extensions/modules/subagent/lib/runner.ts +4 -2
  40. package/extensions/modules/ux/index.ts +2 -2
  41. package/extensions/modules/web/index.ts +39 -3
  42. package/extensions/modules/web/lib/a11y.ts +252 -0
  43. package/extensions/modules/web/lib/chrome.ts +1 -1
  44. package/extensions/modules/web/test/a11y.test.ts +218 -0
  45. package/extensions/modules/web/test/extension.test.ts +2 -2
  46. package/extensions/modules/web/test/hook.test.ts +2 -2
  47. package/extensions/modules/web/vendor/axe/LICENSE +362 -0
  48. package/extensions/modules/web/vendor/axe/LICENSE-3RD-PARTY.txt +66 -0
  49. package/extensions/modules/web/vendor/axe/README.md +19 -0
  50. package/extensions/modules/web/vendor/axe/axe.min.js +12 -0
  51. package/package.json +2 -2
  52. package/skills/web/SKILL.md +1 -0
@@ -0,0 +1,337 @@
1
+ // ponytail: ported from oh-my-pi packages/coding-agent src/utils/github.ts +
2
+ // src/tools/gh-common.ts (lean) — the sanctioned `gh` CLI runner, repo-ref
3
+ // normalization, and shared formatters. Zero deps: everything spawns `gh`.
4
+
5
+ import { spawn, spawnSync } from "node:child_process";
6
+
7
+ /** Deadline for `gh` subprocesses (OMP GH_COMMAND_TIMEOUT_MS). */
8
+ export const GH_TIMEOUT_MS = 5 * 60_000;
9
+ /** Captured-output cap — gh can emit enormous diffs/logs. */
10
+ export const GH_OUTPUT_LIMIT_BYTES = 8 * 1024 * 1024;
11
+ const GH_TRUNCATED_MARKER = "\n[gh subprocess output truncated after 8 MiB]\n";
12
+
13
+ /** OMP's non-interactive env: gh must never hang on a prompt or colorize piped
14
+ * output (a CLICOLOR_FORCE=1 in the user's shell breaks JSON parsing). */
15
+ export function ghEnv(): NodeJS.ProcessEnv {
16
+ return {
17
+ ...process.env,
18
+ GIT_ASKPASS: "true",
19
+ GIT_EDITOR: "true",
20
+ GIT_TERMINAL_PROMPT: "0",
21
+ LC_MESSAGES: "C",
22
+ GH_PROMPT_DISABLED: "1",
23
+ GH_PAGER: "cat",
24
+ PAGER: "cat",
25
+ // Force color OFF — CLICOLOR_FORCE wins over gh's own TTY detection.
26
+ NO_COLOR: "1",
27
+ CLICOLOR: "0",
28
+ CLICOLOR_FORCE: "0",
29
+ };
30
+ }
31
+
32
+ export interface GhCommandOptions {
33
+ /** Caller passed an explicit repo; suppresses "run inside a checkout" hints. */
34
+ repoProvided?: boolean;
35
+ }
36
+
37
+ export interface GhCommandResult {
38
+ exitCode: number;
39
+ stdout: string;
40
+ stderr: string;
41
+ }
42
+
43
+ /** The seam every op goes through — swapped for a fake in tests. */
44
+ export interface GhRunner {
45
+ /** Run `gh`; does NOT throw on non-zero exit. */
46
+ run(cwd: string, args: string[], signal?: AbortSignal, options?: GhCommandOptions): Promise<GhCommandResult>;
47
+ /** Run `gh` expecting JSON on stdout; throws on non-zero exit / bad JSON. */
48
+ json<T = unknown>(cwd: string, args: string[], signal?: AbortSignal, options?: GhCommandOptions): Promise<T>;
49
+ /** Run `gh` expecting text on stdout; throws on non-zero exit. */
50
+ text(cwd: string, args: string[], signal?: AbortSignal, options?: GhCommandOptions): Promise<string>;
51
+ }
52
+
53
+ let availableCache: boolean | undefined;
54
+
55
+ /** True when the `gh` CLI is installed (cached after the first probe). */
56
+ export function ghAvailable(): boolean {
57
+ if (availableCache === undefined) {
58
+ try {
59
+ const probe = spawnSync("gh", ["--version"], { stdio: "ignore", timeout: 10_000 });
60
+ availableCache = !probe.error && probe.status === 0;
61
+ } catch {
62
+ availableCache = false;
63
+ }
64
+ }
65
+ return availableCache;
66
+ }
67
+
68
+ /** The real runner over `node:child_process`. */
69
+ export const realGh: GhRunner = {
70
+ async run(cwd, args, signal, options) {
71
+ if (!ghAvailable()) {
72
+ throw new Error("GitHub CLI (gh) is not installed. Install it from https://cli.github.com/.");
73
+ }
74
+ const timeout = AbortSignal.timeout(GH_TIMEOUT_MS);
75
+ const combined = signal ? AbortSignal.any([signal, timeout]) : timeout;
76
+ return await new Promise<GhCommandResult>((resolveP, rejectP) => {
77
+ const child = spawn("gh", args, { cwd, env: ghEnv(), stdio: ["ignore", "pipe", "pipe"], signal: combined });
78
+ const out: Buffer[] = [];
79
+ const err: Buffer[] = [];
80
+ let outTotal = 0;
81
+ let errTotal = 0;
82
+ child.stdout!.on("data", (chunk: Buffer) => {
83
+ outTotal += chunk.length;
84
+ if (outTotal <= GH_OUTPUT_LIMIT_BYTES) out.push(chunk);
85
+ });
86
+ child.stderr!.on("data", (chunk: Buffer) => {
87
+ errTotal += chunk.length;
88
+ if (errTotal <= GH_OUTPUT_LIMIT_BYTES) err.push(chunk);
89
+ });
90
+ child.on("error", rejectP);
91
+ child.on("close", (code) => {
92
+ let stdout = Buffer.concat(out).toString("utf8");
93
+ if (outTotal > GH_OUTPUT_LIMIT_BYTES) stdout += GH_TRUNCATED_MARKER;
94
+ let stderr = Buffer.concat(err).toString("utf8");
95
+ if (errTotal > GH_OUTPUT_LIMIT_BYTES) stderr += GH_TRUNCATED_MARKER;
96
+ resolveP({ exitCode: code ?? -1, stdout, stderr });
97
+ });
98
+ });
99
+ },
100
+
101
+ async json(cwd, args, signal, options) {
102
+ const r = await this.run(cwd, args, signal, options);
103
+ if (r.exitCode !== 0) throw new Error(formatGhJsonFailure(args, r.stdout, r.stderr, options));
104
+ try {
105
+ return JSON.parse(r.stdout) as never;
106
+ } catch {
107
+ throw new Error(`gh ${args.join(" ")} returned invalid JSON: ${r.stdout.slice(0, 300)}`);
108
+ }
109
+ },
110
+
111
+ async text(cwd, args, signal, options) {
112
+ const r = await this.run(cwd, args, signal, options);
113
+ if (r.exitCode !== 0) throw new Error(formatGhFailure(args, r.stdout, r.stderr, options));
114
+ return r.stdout;
115
+ },
116
+ };
117
+
118
+ // ── Failure formatting (OMP utils/github.ts) ──
119
+
120
+ export function formatGhFailure(args: readonly string[], stdout: string, stderr: string, options?: GhCommandOptions): string {
121
+ const message = (stderr || stdout).trim();
122
+ if (message.includes("gh auth login") || message.includes("not logged into any GitHub hosts")) {
123
+ return "GitHub CLI is not authenticated. Run `gh auth login`.";
124
+ }
125
+ if (
126
+ !options?.repoProvided &&
127
+ (message.includes("not a git repository") ||
128
+ message.includes("no git remotes found") ||
129
+ message.includes("unable to determine current repository"))
130
+ ) {
131
+ return "GitHub repository context is unavailable. Pass `repo` explicitly or run the tool inside a GitHub checkout.";
132
+ }
133
+ if (message) return message;
134
+ return `GitHub CLI command failed: gh ${args.join(" ")}`;
135
+ }
136
+
137
+ function describeGitHubApiError(value: unknown): string | undefined {
138
+ if (typeof value === "string") return value.trim() || undefined;
139
+ if (!value || typeof value !== "object") return undefined;
140
+ const rec = value as Record<string, unknown>;
141
+ if (typeof rec.message === "string") return rec.message.trim() || undefined;
142
+ const resource = typeof rec.resource === "string" ? rec.resource.trim() : "";
143
+ const field = typeof rec.field === "string" ? rec.field.trim() : "";
144
+ const target = [resource, field].filter(Boolean).join(".");
145
+ const code = typeof rec.code === "string" ? rec.code.trim() : "";
146
+ return `${target}: ${code}` || target || code || undefined;
147
+ }
148
+
149
+ function parseGitHubApiErrorMessages(stdout: string): string[] {
150
+ let payload: unknown;
151
+ try {
152
+ payload = JSON.parse(stdout);
153
+ } catch {
154
+ return [];
155
+ }
156
+ if (!payload || typeof payload !== "object") return [];
157
+ const rec = payload as Record<string, unknown>;
158
+ const messages = new Set<string>();
159
+ const summary = describeGitHubApiError(rec.message);
160
+ if (summary) messages.add(summary);
161
+ if (Array.isArray(rec.errors)) {
162
+ for (const error of rec.errors) {
163
+ const message = describeGitHubApiError(error);
164
+ if (message) messages.add(message);
165
+ }
166
+ }
167
+ return [...messages];
168
+ }
169
+
170
+ function formatGhJsonFailure(args: readonly string[], stdout: string, stderr: string, options?: GhCommandOptions): string {
171
+ const rawMessage = (stderr || stdout).trim();
172
+ const fallback = formatGhFailure(args, stdout, stderr, options);
173
+ if (fallback !== rawMessage) return fallback;
174
+ const details = parseGitHubApiErrorMessages(stdout).filter((message) => !fallback.includes(message));
175
+ if (details.length === 0) return fallback;
176
+ return `${fallback}\nGitHub details:\n${details.map((m) => `- ${m}`).join("\n")}`;
177
+ }
178
+
179
+ // ── Repo refs (OMP gh-common.ts) ──
180
+
181
+ const GITHUB_HOST = "github.com";
182
+
183
+ /**
184
+ * A repository in `gh`'s `[HOST/]OWNER/REPO` form. A ref naming no host is
185
+ * left for `gh` to resolve against GH_HOST (github.com by default).
186
+ */
187
+ export interface GhRepoRef {
188
+ host?: string;
189
+ /** `OWNER/REPO`, never host-qualified. */
190
+ slug: string;
191
+ }
192
+
193
+ /** Split `[HOST/]OWNER/REPO`; anything with another shape is taken as a slug. */
194
+ export function parseRepoRef(repo: string): GhRepoRef {
195
+ const firstSlash = repo.indexOf("/");
196
+ if (firstSlash < 0) return { slug: repo };
197
+ const secondSlash = repo.indexOf("/", firstSlash + 1);
198
+ if (secondSlash < 0 || repo.includes("/", secondSlash + 1)) return { slug: repo };
199
+ return { host: repo.slice(0, firstSlash), slug: repo.slice(firstSlash + 1) };
200
+ }
201
+
202
+ /** Join a known host and `OWNER/REPO` into the form `--repo` accepts. */
203
+ export function formatRepoRef(host: string | undefined, slug: string): string {
204
+ return host ? `${host}/${slug}` : slug;
205
+ }
206
+
207
+ /** `gh api` endpoint paths carry no host, so a ref names its host with a flag. */
208
+ export function ghApiHostArgs(ref: GhRepoRef): string[] {
209
+ return ref.host ? ["--hostname", ref.host] : [];
210
+ }
211
+
212
+ export function defaultGhHost(): string {
213
+ return (process.env.GH_HOST || GITHUB_HOST).toLowerCase();
214
+ }
215
+
216
+ const REPO_URL_PATTERN = /^https?:\/\/([^/]+)\/([^/]+)\/([^/?#]+)/;
217
+
218
+ /** `https://HOST/OWNER/REPO` → repository identity, keeping non-default hosts. */
219
+ export function repoFromUrl(value: string | undefined): string | undefined {
220
+ const match = REPO_URL_PATTERN.exec(value?.trim() ?? "");
221
+ if (!match) return undefined;
222
+ const host = match[1].toLowerCase();
223
+ const slug = `${match[2]}/${match[3]}`;
224
+ return host === defaultGhHost() ? slug : formatRepoRef(host, slug);
225
+ }
226
+
227
+ /** A full URL identifier already names host/repo/number; `--repo` would clash. */
228
+ export function appendRepoFlag(args: string[], repo: string | undefined, identifier?: string): void {
229
+ if (!repo || identifier?.startsWith("https://")) return;
230
+ args.push("--repo", repo);
231
+ }
232
+
233
+ function effectiveHost(ref: GhRepoRef): string {
234
+ return ref.host?.toLowerCase() ?? defaultGhHost();
235
+ }
236
+
237
+ /** Case-insensitive repo comparison over the instance each ref resolves to. */
238
+ export function githubRepoSlugEquals(left: string | undefined, right: string): boolean {
239
+ if (left === undefined) return false;
240
+ const leftRef = parseRepoRef(left);
241
+ const rightRef = parseRepoRef(right);
242
+ if (effectiveHost(leftRef) !== effectiveHost(rightRef)) return false;
243
+ return leftRef.slug.toLowerCase() === rightRef.slug.toLowerCase();
244
+ }
245
+
246
+ // ── Default-repo resolution (memoized per cwd, OMP gh-common.ts) ──
247
+
248
+ const DEFAULT_REPO_RESOLVED = new Map<string, string>();
249
+
250
+ async function resolveRepoFromCwd(cwd: string, signal?: AbortSignal): Promise<string> {
251
+ const url = await realGh.text(cwd, ["repo", "view", "--json", "url", "-q", ".url"], signal);
252
+ const repo = repoFromUrl(url);
253
+ if (!repo) throw new Error(`GitHub CLI returned an unrecognized repository URL: ${url}`);
254
+ return repo;
255
+ }
256
+
257
+ /** Current checkout → `[HOST/]OWNER/REPO`, memoized per absolute cwd. */
258
+ export async function resolveDefaultRepoMemoized(cwd: string, signal?: AbortSignal): Promise<string> {
259
+ const key = cwd;
260
+ const ready = DEFAULT_REPO_RESOLVED.get(key);
261
+ if (ready) return ready;
262
+ const value = await resolveRepoFromCwd(key, signal);
263
+ DEFAULT_REPO_RESOLVED.set(key, value);
264
+ return value;
265
+ }
266
+
267
+ /** Best-effort memoized cwd → repo; failures swallow to undefined. */
268
+ export async function tryResolveCurrentRepo(cwd: string, signal?: AbortSignal): Promise<string | undefined> {
269
+ try {
270
+ return await resolveDefaultRepoMemoized(cwd, signal);
271
+ } catch {
272
+ return undefined;
273
+ }
274
+ }
275
+
276
+ /**
277
+ * Resolve the effective repo for an op: explicit `repo` param wins, then a
278
+ * run/PR URL's embedded repo, then the cwd checkout. A mismatch between an
279
+ * explicit repo and the URL's repo is an error (OMP resolveGitHubRepo).
280
+ */
281
+ export async function resolveGitHubRepo(cwd: string, repo: string | undefined, urlRepo: string | undefined, signal?: AbortSignal): Promise<string> {
282
+ if (repo && urlRepo && !githubRepoSlugEquals(repo, urlRepo)) {
283
+ throw new Error("URL repository does not match the provided repo");
284
+ }
285
+ if (repo) return repo;
286
+ if (urlRepo) return urlRepo;
287
+ try {
288
+ return await resolveDefaultRepoMemoized(cwd, signal);
289
+ } catch (err) {
290
+ throw new Error(
291
+ `${err instanceof Error ? err.message : String(err)}\nGitHub repository context is unavailable. Pass \`repo\` explicitly or run the tool inside a GitHub checkout.`,
292
+ );
293
+ }
294
+ }
295
+
296
+ // ── Shared text formatters (OMP gh-common.ts) ──
297
+
298
+ export function normalizeText(value: string | null | undefined): string {
299
+ return (value ?? "").replaceAll("\r\n", "\n").replaceAll("\r", "\n").replaceAll("\t", " ").trim();
300
+ }
301
+
302
+ export function normalizeBlock(value: string | null | undefined): string {
303
+ return (value ?? "").replaceAll("\r\n", "\n").replaceAll("\r", "\n").replaceAll("\t", " ").trimEnd();
304
+ }
305
+
306
+ export function normalizeOptionalString(value: unknown): string | undefined {
307
+ const normalized = typeof value === "string" ? value.trim() : "";
308
+ return normalized || undefined;
309
+ }
310
+
311
+ export function requireNonEmpty(value: unknown, label: string): string {
312
+ const normalized = normalizeOptionalString(value);
313
+ if (!normalized) throw new Error(`${label} must not be empty`);
314
+ return normalized;
315
+ }
316
+
317
+ /** Push `Label: value` only when value is non-empty (OMP pushLine). */
318
+ export function pushLine(lines: string[], label: string, value: string | number | boolean | undefined | null): void {
319
+ if (value === undefined || value === null || value === "") return;
320
+ lines.push(`${label}: ${value}`);
321
+ }
322
+
323
+ export function formatShortSha(sha: string | undefined | null): string | undefined {
324
+ return sha ? sha.slice(0, 8) : undefined;
325
+ }
326
+
327
+ export function formatAuthor(author: { login?: string; name?: string } | null | undefined): string | undefined {
328
+ if (!author) return undefined;
329
+ if (author.login) return `@${author.login}`;
330
+ if (author.name) return author.name;
331
+ return undefined;
332
+ }
333
+
334
+ export function formatLabels(labels: { name?: string }[] | undefined): string | undefined {
335
+ const names = labels?.map((l) => l.name).filter((n): n is string => Boolean(n)) ?? [];
336
+ return names.length > 0 ? names.join(", ") : undefined;
337
+ }