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,242 @@
1
+ // ponytail: ported from oh-my-pi tools/read-selector.ts + pi-tui
2
+ // tools/line-ranges.ts (lean). Path-embedded line selectors for the wrapped
3
+ // read tool: `:50`, `:50-200`, `:50+150`, `:50-`, `:-60`, `:5-16,960-973`,
4
+ // `:19,59`, `:raw` compounds, `:conflicts`. `:img` is dropped (pi read does
5
+ // not render SVGs). Resolution contract (OMP issue #4618): a LITERAL path
6
+ // that exists on disk always wins — peel the selector only when the raw path
7
+ // does not exist and the remainder parses.
8
+
9
+ // ── Line ranges (OMP line-ranges.ts) ──
10
+
11
+ /** Inclusive line range; `endLine` undefined = open-ended (to EOF). */
12
+ export interface LineRange {
13
+ startLine: number;
14
+ endLine: number | undefined;
15
+ }
16
+
17
+ const LINE_RANGE_CHUNK_RE = /^L?(\d+)(?:(\.\.|[-+])L?(\d+)?)?$/i;
18
+
19
+ /** Parse one `N`, `N-M`, `N-`, `N+K`, or `..`-aliased chunk; null when not range-shaped. */
20
+ export function parseLineRangeChunk(sel: string): LineRange | null {
21
+ return parseChunk(sel, false);
22
+ }
23
+
24
+ /** `pinBare` makes a separator-less `N` the single line N instead of "from N onward". */
25
+ function parseChunk(sel: string, pinBare: boolean): LineRange | null {
26
+ const m = LINE_RANGE_CHUNK_RE.exec(sel);
27
+ if (!m) return null;
28
+ const rawStart = Number.parseInt(m[1], 10);
29
+ if (rawStart < 1) throw new SelectorError("Line selector 0 is invalid; lines are 1-indexed. Use :1.");
30
+ // `..` is a forgiving alias for `-` (2724..2727 == 2724-2727).
31
+ const sep = m[2] === ".." ? "-" : m[2];
32
+ const rhs = m[3] ? Number.parseInt(m[3], 10) : undefined;
33
+ let rawEnd: number | undefined;
34
+ if (sep === "+") {
35
+ if (rhs === undefined || rhs < 1) throw new SelectorError(`Invalid range ${rawStart}+${rhs ?? 0}: count must be >= 1.`);
36
+ rawEnd = rawStart + rhs - 1;
37
+ } else if (sep === "-") {
38
+ if (rhs !== undefined) {
39
+ if (rhs < rawStart) throw new SelectorError(`Invalid range ${rawStart}-${rhs}: end must be >= start.`);
40
+ rawEnd = rhs;
41
+ }
42
+ } else if (pinBare) {
43
+ rawEnd = rawStart;
44
+ }
45
+ return { startLine: rawStart, endLine: rawEnd };
46
+ }
47
+
48
+ /** Comma-separated ranges, ascending, overlapping/adjacent merged (OMP). */
49
+ export function parseLineRanges(sel: string): [LineRange, ...LineRange[]] | null {
50
+ const chunks = sel.split(",");
51
+ // A lone `:50` means "from line 50"; inside a comma list a bare number is
52
+ // that one line (`:19,59` = lines 19 and 59).
53
+ const pinBare = chunks.length > 1;
54
+ const parsed: LineRange[] = [];
55
+ for (const chunk of chunks) {
56
+ const range = parseChunk(chunk, pinBare);
57
+ if (!range) return null;
58
+ parsed.push(range);
59
+ }
60
+ if (parsed.length === 0) return null;
61
+ parsed.sort((a, b) => a.startLine - b.startLine);
62
+ const merged: LineRange[] = [parsed[0]];
63
+ for (let i = 1; i < parsed.length; i++) {
64
+ const current = parsed[i];
65
+ const last = merged[merged.length - 1];
66
+ if (last.endLine === undefined) continue; // open-ended absorbs everything later
67
+ if (current.startLine <= last.endLine + 1) {
68
+ if (current.endLine === undefined || current.endLine > last.endLine) {
69
+ merged[merged.length - 1] = { startLine: last.startLine, endLine: current.endLine };
70
+ }
71
+ continue;
72
+ }
73
+ merged.push(current);
74
+ }
75
+ return merged as [LineRange, ...LineRange[]];
76
+ }
77
+
78
+ // ── Selector grammar (OMP read-selector.ts) ──
79
+
80
+ export class SelectorError extends Error {}
81
+
82
+ export type ParsedSelector =
83
+ | { kind: "none" }
84
+ | { kind: "raw" }
85
+ | { kind: "conflicts" }
86
+ | { kind: "lines"; ranges: [LineRange, ...LineRange[]]; raw?: boolean }
87
+ /** `:-N` — the last N lines; needs the line count before slicing. */
88
+ | { kind: "tail"; count: number; raw?: boolean };
89
+
90
+ export function isRawSelector(parsed: ParsedSelector): boolean {
91
+ return parsed.kind === "raw" || ((parsed.kind === "lines" || parsed.kind === "tail") && parsed.raw === true);
92
+ }
93
+
94
+ export function isMultiRange(parsed: ParsedSelector): boolean {
95
+ return parsed.kind === "lines" && parsed.ranges.length > 1;
96
+ }
97
+
98
+ /** Pin a `:-N` tail selector to absolute lines against `totalLines`. */
99
+ export function resolveTailSelector(parsed: ParsedSelector, totalLines: number): Exclude<ParsedSelector, { kind: "tail" }> {
100
+ if (parsed.kind !== "tail") return parsed;
101
+ const startLine = Math.max(1, totalLines - parsed.count + 1);
102
+ // `raw: undefined` is omitted so strict deep-equal tests see the plain shape.
103
+ const resolved: Exclude<ParsedSelector, { kind: "tail" }> = {
104
+ kind: "lines",
105
+ ranges: [{ startLine, endLine: Math.max(startLine, totalLines) }],
106
+ };
107
+ if (parsed.raw === true) resolved.raw = true;
108
+ return resolved;
109
+ }
110
+
111
+ /** True when a compound chunk looks selector-like (drives the invalid-compound throw). */
112
+ function selectorChunkLooksReadLike(chunk: string): boolean {
113
+ const lower = chunk.toLowerCase();
114
+ return lower === "raw" || lower === "conflicts" || /^-\d+(?:[-+]\d+)?$/.test(chunk) || parseLineRanges(chunk) !== null;
115
+ }
116
+
117
+ function invalidSelector(sel: string): SelectorError {
118
+ return new SelectorError(
119
+ `Invalid selector ':${sel}'. Use :N, :N-M, :N+K, :N- (open-ended), :-N (last N lines), a comma-separated list of ranges, :raw, :conflicts, or a range combined with raw (e.g. :raw:50-100).`,
120
+ );
121
+ }
122
+
123
+ function parseRangeOrTail(chunk: string, raw: boolean): ParsedSelector | null {
124
+ const ranges = parseLineRanges(chunk);
125
+ if (ranges) return raw ? { kind: "lines", ranges, raw } : { kind: "lines", ranges };
126
+ const count = parseTailCount(chunk);
127
+ if (count !== null) return raw ? { kind: "tail", count, raw } : { kind: "tail", count };
128
+ return null;
129
+ }
130
+
131
+ /** Parse a `-N` tail selector (`:-60` → 60 last lines); null when not tail-shaped. */
132
+ export function parseTailCount(sel: string): number | null {
133
+ const match = /^-(\d+)$/.exec(sel);
134
+ if (!match) return null;
135
+ const count = Number.parseInt(match[1], 10);
136
+ if (count < 1) throw new SelectorError("Tail selector -0 is invalid; use :-N with N >= 1 to read the last N lines.");
137
+ return count;
138
+ }
139
+
140
+ export function parseSel(sel: string | undefined): ParsedSelector {
141
+ if (!sel || sel.length === 0) return { kind: "none" };
142
+
143
+ // Compound selector: `1-50:raw`, `raw:1-50`, `raw:-60` — exactly one range
144
+ // (or tail) plus the literal `raw`. Selector-like compounds outside that
145
+ // set are INVALID (never silently widened to "no selector").
146
+ if (sel.includes(":")) {
147
+ const chunks = sel.split(":");
148
+ if (chunks.length === 2) {
149
+ const [a, b] = chunks as [string, string];
150
+ const aIsRaw = a.toLowerCase() === "raw";
151
+ const bIsRaw = b.toLowerCase() === "raw";
152
+ const rangeChunk = aIsRaw ? b : bIsRaw ? a : null;
153
+ const rawChunk = aIsRaw ? a : bIsRaw ? b : null;
154
+ if (rangeChunk !== null && rawChunk !== null) {
155
+ const parsed = parseRangeOrTail(rangeChunk, true);
156
+ if (parsed) return parsed;
157
+ }
158
+ }
159
+ if (chunks.every(selectorChunkLooksReadLike)) throw invalidSelector(sel);
160
+ // Unrecognized compound — treat as no selector (literal-path semantics).
161
+ return { kind: "none" };
162
+ }
163
+
164
+ if (sel.toLowerCase() === "raw") return { kind: "raw" };
165
+ if (sel.toLowerCase() === "conflicts") return { kind: "conflicts" };
166
+ const parsed = parseRangeOrTail(sel, false);
167
+ if (parsed) return parsed;
168
+ // Unrecognized → no selector (the whole thing stays a literal path).
169
+ return { kind: "none" };
170
+ }
171
+
172
+ /** Single range → offset/limit; multi-range callers MUST branch on isMultiRange first. */
173
+ export function selToOffsetLimit(parsed: Exclude<ParsedSelector, { kind: "tail" }>): { offset?: number; limit?: number } {
174
+ if (parsed.kind === "lines") {
175
+ const first = parsed.ranges[0];
176
+ const limit = first.endLine !== undefined ? first.endLine - first.startLine + 1 : undefined;
177
+ return { offset: first.startLine, limit };
178
+ }
179
+ return {};
180
+ }
181
+
182
+ // ── Path peeling ──
183
+
184
+ /**
185
+ * Split `path:selector` → `{ stem, selector }` when the suffix parses as a
186
+ * selector, else `{ stem: path }`. Caller contract (OMP #4618): probe literal
187
+ * existence FIRST — only call this when the raw path does not exist.
188
+ */
189
+ export function peelPathSelector(rawPath: string): { stem: string; selector?: ParsedSelector } {
190
+ if (!rawPath.includes(":")) return { stem: rawPath };
191
+ // Scheme-like prefixes (artifact://) never carry selectors here; a Windows
192
+ // drive root (C:\, C:/) is part of the path, not a selector separator.
193
+ if (rawPath.includes("://") || /^[A-Za-z]:[\\/]/.test(rawPath)) return { stem: rawPath };
194
+ // Compound selectors (`f.ts:1-1:conflicts`) split at the FIRST colon whose
195
+ // remainder parses as a selector; lastIndexOf would split at the last one and
196
+ // misread `1-1:conflicts` as the stem.
197
+ for (let idx = rawPath.indexOf(":"); idx > 0; idx = rawPath.indexOf(":", idx + 1)) {
198
+ const stem = rawPath.slice(0, idx);
199
+ const sel = rawPath.slice(idx + 1);
200
+ if (!sel || stem.endsWith("/") || stem.endsWith(":")) continue;
201
+ try {
202
+ const parsed = parseSel(sel);
203
+ if (parsed.kind !== "none") return { stem, selector: parsed };
204
+ } catch (err) {
205
+ // Selector-like but invalid → surface the parse error (OMP semantics).
206
+ // The caller's literal-exists probe already ran: reaching here means the
207
+ // raw path does NOT exist, so an invalid selector is a loud model error,
208
+ // not a plausible literal filename.
209
+ throw new SelectorError(
210
+ `${rawPath}: ${err instanceof Error ? err.message : String(err)}`,
211
+ );
212
+ }
213
+ }
214
+ return { stem: rawPath };
215
+ }
216
+
217
+ /** True when any line of the file content is inside the ranges. */
218
+ export function isLineInRanges(lineNumber: number, ranges: readonly LineRange[]): boolean {
219
+ for (const range of ranges) {
220
+ if (lineNumber < range.startLine) continue;
221
+ if (range.endLine === undefined || lineNumber <= range.endLine) return true;
222
+ }
223
+ return false;
224
+ }
225
+
226
+ /** Extract merge-conflict blocks (<<<<<<< … >>>>>>>) from file lines. */
227
+ export function extractConflictBlocks(lines: readonly string[]): string[][] {
228
+ const blocks: string[][] = [];
229
+ let current: string[] | null = null;
230
+ for (const line of lines) {
231
+ if (line.startsWith("<<<<<<<")) {
232
+ current = [line];
233
+ } else if (current !== null) {
234
+ current.push(line);
235
+ if (line.startsWith(">>>>>>>")) {
236
+ blocks.push(current);
237
+ current = null;
238
+ }
239
+ }
240
+ }
241
+ return blocks;
242
+ }
@@ -108,7 +108,7 @@ export function writeRepairSection(patch: Partial<RepairSettings>): string {
108
108
  settings.repair = repair;
109
109
  mkdirSync(path.dirname(file), { recursive: true });
110
110
  const tmp = file + ".tmp";
111
- writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n");
111
+ writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n", { mode: 0o600 });
112
112
  renameSync(tmp, file);
113
113
  return file;
114
114
  }
@@ -0,0 +1,198 @@
1
+ // read path selector tests — parser unit cases + wrapper integration through
2
+ // the REAL createReadToolDefinition against temp files (the wrapper.test.ts
3
+ // lesson: faithful fakes don't prove the wiring).
4
+
5
+ import assert from "node:assert/strict";
6
+ import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
7
+ import { tmpdir } from "node:os";
8
+ import { join } from "node:path";
9
+ import { after, describe, it } from "node:test";
10
+ import { createReadToolDefinition } from "@earendil-works/pi-coding-agent";
11
+ import {
12
+ extractConflictBlocks,
13
+ isMultiRange,
14
+ parseLineRanges,
15
+ parseSel,
16
+ parseTailCount,
17
+ peelPathSelector,
18
+ resolveTailSelector,
19
+ selToOffsetLimit,
20
+ } from "../lib/read-selector.js";
21
+ import { wrapToolDefinition } from "../index.js";
22
+
23
+ const dirs: string[] = [];
24
+ const originalAgentDir = process.env.PI_CODING_AGENT_DIR;
25
+
26
+ after(async () => {
27
+ if (originalAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
28
+ else process.env.PI_CODING_AGENT_DIR = originalAgentDir;
29
+ await Promise.all(dirs.map((d) => rm(d, { recursive: true, force: true })));
30
+ });
31
+
32
+ async function tempDir(): Promise<string> {
33
+ const dir = await mkdtemp(join(tmpdir(), "read-sel-"));
34
+ dirs.push(dir);
35
+ process.env.PI_CODING_AGENT_DIR = dir;
36
+ return dir;
37
+ }
38
+
39
+ // ── Parser unit cases ──
40
+
41
+ describe("parseSel grammar", () => {
42
+ it("N means from-line-onward; in a list it pins the single line", () => {
43
+ assert.deepEqual(parseSel("50"), { kind: "lines", ranges: [{ startLine: 50, endLine: undefined }] });
44
+ assert.deepEqual(parseSel("19,59"), {
45
+ kind: "lines",
46
+ ranges: [{ startLine: 19, endLine: 19 }, { startLine: 59, endLine: 59 }],
47
+ });
48
+ });
49
+
50
+ it("ranges: N-M, N+K, N-, .. alias; commas merge", () => {
51
+ assert.deepEqual(parseSel("50-200"), { kind: "lines", ranges: [{ startLine: 50, endLine: 200 }] });
52
+ assert.deepEqual(parseSel("50+150"), { kind: "lines", ranges: [{ startLine: 50, endLine: 199 }] });
53
+ assert.deepEqual(parseSel("50-"), { kind: "lines", ranges: [{ startLine: 50, endLine: undefined }] });
54
+ assert.deepEqual(parseSel("10..12"), { kind: "lines", ranges: [{ startLine: 10, endLine: 12 }] });
55
+ const merged = parseSel("5-16,15-20");
56
+ assert.deepEqual(merged, { kind: "lines", ranges: [{ startLine: 5, endLine: 20 }] });
57
+ });
58
+
59
+ it("tail, raw, conflicts, compounds", () => {
60
+ assert.deepEqual(parseSel("-60"), { kind: "tail", count: 60 });
61
+ assert.deepEqual(parseSel("raw"), { kind: "raw" });
62
+ assert.deepEqual(parseSel("conflicts"), { kind: "conflicts" });
63
+ assert.deepEqual(parseSel("raw:50-100"), { kind: "lines", ranges: [{ startLine: 50, endLine: 100 }], raw: true });
64
+ assert.deepEqual(parseSel("50-100:raw"), { kind: "lines", ranges: [{ startLine: 50, endLine: 100 }], raw: true });
65
+ });
66
+
67
+ it("invalid bounds throw; selector-like compounds throw; unrecognized falls through to none", () => {
68
+ assert.throws(() => parseSel("0"), /1-indexed/);
69
+ assert.throws(() => parseSel("200-50"), /end must be >= start/);
70
+ assert.throws(() => parseSel("1-1:conflicts"), /Invalid selector/);
71
+ assert.throws(() => parseSel("-0"), /Tail selector -0/);
72
+ // Not selector-shaped → none (literal-path semantics, OMP fall-through).
73
+ assert.deepEqual(parseSel("bogus"), { kind: "none" });
74
+ assert.deepEqual(parseSel("a:b"), { kind: "none" });
75
+ });
76
+ });
77
+
78
+ describe("tail resolution + offset/limit", () => {
79
+ it("resolveTailSelector pins :-N against the line count", () => {
80
+ const pinned = resolveTailSelector({ kind: "tail", count: 3 }, 10);
81
+ assert.deepEqual(pinned, { kind: "lines", ranges: [{ startLine: 8, endLine: 10 }] });
82
+ // Count larger than the file clamps to line 1.
83
+ const clamped = resolveTailSelector({ kind: "tail", count: 99 }, 10);
84
+ if (clamped.kind !== "lines") throw new Error("unreachable");
85
+ assert.deepEqual(clamped.ranges[0].startLine, 1);
86
+ });
87
+
88
+ it("selToOffsetLimit converts single ranges", () => {
89
+ assert.deepEqual(selToOffsetLimit({ kind: "lines", ranges: [{ startLine: 50, endLine: 200 }] }), { offset: 50, limit: 151 });
90
+ assert.deepEqual(selToOffsetLimit({ kind: "lines", ranges: [{ startLine: 7, endLine: undefined }] }), { offset: 7, limit: undefined });
91
+ assert.deepEqual(selToOffsetLimit({ kind: "raw" }), {});
92
+ });
93
+
94
+ it("multi-range detection and tail parsing", () => {
95
+ assert.equal(isMultiRange(parseSel("5-16,960-973")), true);
96
+ assert.equal(isMultiRange(parseSel("5-16")), false);
97
+ assert.equal(parseTailCount("-60"), 60);
98
+ assert.equal(parseTailCount("60"), null);
99
+ assert.deepEqual(parseLineRanges("5-16,960-973"), [{ startLine: 5, endLine: 16 }, { startLine: 960, endLine: 973 }]);
100
+ });
101
+ });
102
+
103
+ describe("path peeling", () => {
104
+ it("peels a selector suffix; keeps schemes and drive letters literal", () => {
105
+ assert.deepEqual(peelPathSelector("src/foo.ts:50-200"), { stem: "src/foo.ts", selector: parseSel("50-200") });
106
+ assert.deepEqual(peelPathSelector("https://x/y:1-2"), { stem: "https://x/y:1-2" }); // scheme
107
+ assert.deepEqual(peelPathSelector("C:\\tmp\\x.ts:1-2"), { stem: "C:\\tmp\\x.ts:1-2" }); // drive
108
+ assert.deepEqual(peelPathSelector("no-colon.ts"), { stem: "no-colon.ts" });
109
+ });
110
+ });
111
+
112
+ describe("conflict extraction", () => {
113
+ it("pulls <<<<<<< … >>>>>>> blocks", () => {
114
+ const lines = [
115
+ "before",
116
+ "<<<<<<< HEAD",
117
+ "ours",
118
+ "=======",
119
+ "theirs",
120
+ ">>>>>>> feature",
121
+ "after",
122
+ ];
123
+ const blocks = extractConflictBlocks(lines);
124
+ assert.equal(blocks.length, 1);
125
+ assert.deepEqual(blocks[0], lines.slice(1, 6));
126
+ });
127
+ });
128
+
129
+ // ── Wrapper integration (real read tool + real temp files) ──
130
+
131
+ describe("wrapped read selectors (integration)", () => {
132
+ it("single range, tail, multi-range, conflicts, and literal-colon precedence", async () => {
133
+ const dir = await tempDir();
134
+ const lines = Array.from({ length: 100 }, (_, i) => `line${i + 1}`);
135
+ await writeFile(join(dir, "f.ts"), lines.join("\n") + "\n");
136
+ // A file whose NAME contains a colon-selector shape — must win literally.
137
+ await writeFile(join(dir, "g:1-2"), "COLON FILE");
138
+
139
+ const onRepairs: string[] = [];
140
+ const factory = (cwd: string) => createReadToolDefinition(cwd);
141
+ const wrapped = wrapToolDefinition(factory(process.cwd()), factory, () => false, () => onRepairs.push("x"));
142
+ const ctx = { cwd: dir };
143
+
144
+ // Single range → translated to offset/limit, content sliced.
145
+ const r1 = await wrapped.execute("t1", { path: "f.ts:10-12" }, undefined, undefined, ctx);
146
+ const t1 = r1.content[0].text;
147
+ assert.match(t1, /line10/);
148
+ assert.match(t1, /line12/);
149
+ assert.doesNotMatch(t1, /line13/);
150
+ assert.doesNotMatch(t1, /line9\n/);
151
+
152
+ // Tail :-3 → last three lines.
153
+ const r2 = await wrapped.execute("t2", { path: "f.ts:-3" }, undefined, undefined, ctx);
154
+ const t2 = r2.content[0].text;
155
+ assert.match(t2, /line98/);
156
+ assert.match(t2, /line100/);
157
+ assert.doesNotMatch(t2, /line97/);
158
+
159
+ // Multi-range → both slices + a skip marker.
160
+ const r3 = await wrapped.execute("t3", { path: "f.ts:1-2,98-100" }, undefined, undefined, ctx);
161
+ const t3 = r3.content[0].text;
162
+ assert.match(t3, /line1\nline2/);
163
+ assert.match(t3, /line98/);
164
+ assert.match(t3, /lines 1-2/);
165
+ assert.match(t3, /of 100 total/);
166
+ assert.doesNotMatch(t3, /line50/);
167
+
168
+ // Conflicts: fixture with merge markers.
169
+ await writeFile(
170
+ join(dir, "conflicted.txt"),
171
+ ["keep", "<<<<<<< HEAD", "ours", "=======", "theirs", ">>>>>>> branch", "tail"].join("\n"),
172
+ );
173
+ const r4 = await wrapped.execute("t4", { path: "conflicted.txt:conflicts" }, undefined, undefined, ctx);
174
+ const t4 = r4.content[0].text;
175
+ assert.match(t4, /1 conflict block/);
176
+ assert.match(t4, /<<<<<<< HEAD/);
177
+ assert.match(t4, />>>>>>> branch/);
178
+ assert.doesNotMatch(t4, /^keep$/m);
179
+
180
+ // Literal file named g:1-2 exists → read as-is, no selector.
181
+ const r5 = await wrapped.execute("t5", { path: "g:1-2" }, undefined, undefined, ctx);
182
+ assert.equal(r5.content[0].text, "COLON FILE");
183
+
184
+ // Invalid selector on a real stem → loud error, not silent widening.
185
+ await assert.rejects(
186
+ () => wrapped.execute("t6", { path: "f.ts:1-1:conflicts" }, undefined, undefined, ctx),
187
+ /Invalid selector/,
188
+ );
189
+ });
190
+
191
+ it("description carries the selector grammar after wrapping", async () => {
192
+ const dir = await tempDir();
193
+ const factory = (cwd: string) => createReadToolDefinition(cwd);
194
+ const wrapped = wrapToolDefinition(factory(dir), factory, () => false, () => {});
195
+ assert.match(wrapped.description, /Path suffixes/);
196
+ assert.match(wrapped.description, /:conflicts/);
197
+ });
198
+ });
@@ -120,15 +120,19 @@ export function registerProvider(pi: ExtensionAPI, settings: RouterSettings): vo
120
120
  // stale persisted flags self-heal — /v1/models vision metadata lies
121
121
  // in both directions (see client.ts VISION_OVERRIDES/VISION_DOWNGRADES)
122
122
  // and old caches froze it verbatim.
123
- return stored.map((m) =>
124
- (m as { type?: string }).type === "classifier"
125
- ? m
126
- : applyReasoning(
127
- // Array.isArray guards legacy/malformed store entries (treated as text-only).
128
- { ...m, input: resolveVision(m.id, Array.isArray(m.input) && m.input.includes("image")) ? ["text", "image"] : ["text"] } as PiModel,
129
- settings.enableReasoning,
130
- ),
131
- ) as unknown as ProviderModelConfig[];
123
+ // Non-object entries (null in a hand-edited/corrupted store) are
124
+ // dropped — a null here used to throw TypeError and break startup.
125
+ return stored
126
+ .filter((m): m is NonNullable<typeof m> => m !== null && typeof m === "object")
127
+ .map((m) =>
128
+ (m as { type?: string }).type === "classifier"
129
+ ? m
130
+ : applyReasoning(
131
+ // Array.isArray guards legacy/malformed store entries (treated as text-only).
132
+ { ...m, input: resolveVision(m.id, Array.isArray(m.input) && m.input.includes("image")) ? ["text", "image"] : ["text"] } as PiModel,
133
+ settings.enableReasoning,
134
+ ),
135
+ ) as unknown as ProviderModelConfig[];
132
136
  }
133
137
 
134
138
  const cred = context.credential as { type?: string; key?: string } | undefined;
@@ -76,6 +76,13 @@ export function buildSteeringGroups(cfg: SteeringSettings): PanelGroup[] {
76
76
  defaultValue: false,
77
77
  description: "A/B knob: prepend the 'We need…' thinking directive to the bootstrap prompt.",
78
78
  }),
79
+ row("steering.thinkTool", "Think scratchpad tool", "toggle", cfg.thinkTool, (v) => {
80
+ cfg.thinkTool = Boolean(v);
81
+ }, {
82
+ defaultValue: false,
83
+ warning: "Registers the private think tool at next session start (/reload); ceulen.disabledTools can keep it off.",
84
+ description: "OMP-parity scratchpad: a think tool whose call renders as one dim marker — planning notes stay out of the visible transcript. Scratchpad only; native reasoning is never suppressed.",
85
+ }),
79
86
  ],
80
87
  },
81
88
  ];
@@ -90,6 +97,7 @@ const OWNED_KEYS = [
90
97
  "steering.stripReasoning",
91
98
  "steering.dsAnchor",
92
99
  "steering.weNeed",
100
+ "steering.thinkTool",
93
101
  ];
94
102
 
95
103
  /** steering's ModuleConfig for the central /config panel. Reads the EFFECTIVE
@@ -81,6 +81,7 @@ import {
81
81
  type ErrorInfo,
82
82
  } from "./lib/errors.js";
83
83
  import { readSteeringSettings, type SteeringSettings } from "./lib/settings.js";
84
+ import { thinkTool } from "./lib/think.js";
84
85
 
85
86
  // The integrator may import the /config contribution from either file
86
87
  // (classifier imports configPanel, composer re-exports from index).
@@ -112,6 +113,11 @@ interface AssistantLike {
112
113
  }
113
114
 
114
115
  export default function steeringModule(pi: ExtensionAPI): void {
116
+ // OMP-parity scratchpad: registers only when `steering.thinkTool` is on.
117
+ // Presence binds at LOAD (the /config row carries the reload warning —
118
+ // repair autoBg precedent); the per-tool kill-switch stays live via
119
+ // `ceulen.disabledTools` + /config tool rows.
120
+ if (readSteeringSettings().thinkTool) pi.registerTool(thinkTool() as never);
115
121
  let sessionModel: { provider?: string; id?: string } | undefined;
116
122
  let activeFamily: ModelFamily | null = null;
117
123
  let hasErrorThisTurn = false;
@@ -14,7 +14,8 @@
14
14
  // "strictSerena": false, // escalate dedicated-tool misses to a block
15
15
  // "stripReasoning": true, // drop accumulated reasoning_content
16
16
  // "dsAnchor": true, // deepseek-v4-pro minimal-mode bootstrap
17
- // "weNeed": false // A/B: "We need…" bootstrap directive
17
+ // "weNeed": false, // A/B: "We need…" bootstrap directive
18
+ // "thinkTool": false // register the OMP-parity think scratchpad
18
19
  // }
19
20
 
20
21
  import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
@@ -32,6 +33,8 @@ export interface SteeringSettings {
32
33
  stripReasoning: boolean;
33
34
  dsAnchor: boolean;
34
35
  weNeed: boolean;
36
+ /** Register the OMP-parity `think` scratchpad tool. Presence binds at load. */
37
+ thinkTool: boolean;
35
38
  }
36
39
 
37
40
  export const DEFAULT_STEERING_SETTINGS: SteeringSettings = {
@@ -43,6 +46,7 @@ export const DEFAULT_STEERING_SETTINGS: SteeringSettings = {
43
46
  stripReasoning: true,
44
47
  dsAnchor: true,
45
48
  weNeed: false,
49
+ thinkTool: false,
46
50
  };
47
51
 
48
52
  function agentDir(): string {
@@ -75,7 +79,7 @@ function section(json: Record<string, unknown> | null): Record<string, unknown>
75
79
  /** Merge one settings layer's `steering` keys into out. */
76
80
  function mergeLayer(out: SteeringSettings, json: Record<string, unknown> | null): void {
77
81
  const s = section(json);
78
- for (const key of ["firstToolHints", "selectionGuidance", "superpower", "strictSerena", "stripReasoning", "dsAnchor", "weNeed"] as const) {
82
+ for (const key of ["firstToolHints", "selectionGuidance", "superpower", "strictSerena", "stripReasoning", "dsAnchor", "weNeed", "thinkTool"] as const) {
79
83
  if (typeof s[key] === "boolean") out[key] = s[key] as boolean;
80
84
  }
81
85
  if (typeof s.superpowerPrompt === "string") out.superpowerPrompt = s.superpowerPrompt.trim();
@@ -0,0 +1,66 @@
1
+ // think — OMP's private scratchpad tool, ported into steering.
2
+ //
3
+ // ponytail: ported from oh-my-pi packages/coding-agent/src/tools/think.ts —
4
+ // scratchpad only. OMP's companion `externalThinking` mode (suppressing native
5
+ // provider reasoning and replacing it with this tool) is deliberately NOT
6
+ // ported: OMP ships a "providers flagged this request shape as abuse" warning
7
+ // on that setting, and pi's per-model thinking levels are the honest off-switch.
8
+ //
9
+ // Value: models running with thinking off (cheap router tiers) get a place to
10
+ // plan that renders as one dim marker in the transcript instead of rambling
11
+ // assistant prose. The call args still reach the model on later rounds (that's
12
+ // the scratchpad); the user sees a dot.
13
+ //
14
+ // Renderers MUST return a pi-tui Component (Text), not a raw string — a string
15
+ // crashes ToolExecutionComponent with "this.child.render is not a function"
16
+ // (uncaughtException, live 2026-10-05). The todo module's renderResult is the
17
+ // precedent.
18
+
19
+ import { Text } from "@earendil-works/pi-tui";
20
+ import { Type } from "typebox";
21
+
22
+ import { readDisabledTools } from "../../../lib/tools.js";
23
+
24
+ /** The dim marker shown in place of the thoughts. */
25
+ export const THINK_MARKER = "·";
26
+
27
+ /** Minimal theme shim (todo lib/render.ts pattern) — pi's Theme is cast to
28
+ * this at the call site. */
29
+ export interface ThinkTheme {
30
+ fg(token: string, text: string): string;
31
+ }
32
+
33
+ export interface ThinkParams {
34
+ thoughts: string;
35
+ }
36
+
37
+ /** The `think` tool definition. Renderers receive pi's theme at render time —
38
+ * no theme captured at registration. */
39
+ export function thinkTool() {
40
+ return {
41
+ name: "think" as const,
42
+ label: "Think",
43
+ description:
44
+ "Private scratchpad for planning notes. The transcript shows only a dim marker — the user never sees the content. " +
45
+ "Use it to organize multi-step work before acting, especially on complex refactors or debugging.",
46
+ promptGuidelines: ["Use the think tool to plan before complex multi-step work."],
47
+ // kill-switch: ceulen.disabledTools names it → registers inactive (the
48
+ // config module's tool rows flip it live via setActiveTools).
49
+ defaultActive: !readDisabledTools().has("think"),
50
+ parameters: Type.Object(
51
+ { thoughts: Type.String({ description: "private scratchpad; not shown to user" }) },
52
+ { additionalProperties: false },
53
+ ),
54
+ async execute() {
55
+ return { content: [{ type: "text" as const, text: "—" }] };
56
+ },
57
+ renderCall(args: ThinkParams, theme?: ThinkTheme) {
58
+ const n = typeof args?.thoughts === "string" ? args.thoughts.length : 0;
59
+ const line = theme?.fg ? theme.fg("dim", `· think${n > 0 ? ` (${n} chars)` : ""}`) : `· think${n > 0 ? ` (${n} chars)` : ""}`;
60
+ return new Text(line, 0, 0);
61
+ },
62
+ renderResult(_result: unknown, _options: unknown, theme?: ThinkTheme) {
63
+ return new Text(theme?.fg ? theme.fg("dim", THINK_MARKER) : THINK_MARKER, 0, 0);
64
+ },
65
+ };
66
+ }
@@ -42,6 +42,8 @@ export interface FakePi {
42
42
  messages: Array<{ message: any; options: any }>;
43
43
  commands: Record<string, any>;
44
44
  notifications: string[];
45
+ /** Tools the module registered at load (think scratchpad when gated on). */
46
+ tools: Array<Record<string, unknown>>;
45
47
  }
46
48
 
47
49
  export function createFakePi(activeTools: string[] = ["bash", "read", "edit", "grep", "str_replace_editor"]): FakePi {
@@ -50,9 +52,11 @@ export function createFakePi(activeTools: string[] = ["bash", "read", "edit", "g
50
52
  const messages: Array<{ message: any; options: any }> = [];
51
53
  const notifications: string[] = [];
52
54
  let entries: any[] = [];
55
+ const tools: Array<Record<string, unknown>> = [];
53
56
 
54
57
  const pi: any = {
55
58
  registerCommand: (name: string, def: any) => { commands[name] = def; },
59
+ registerTool: (def: any) => { tools.push(def); },
56
60
  on: (name: string, fn: Hook) => { (hooks.get(name) ?? hooks.set(name, []).get(name)!).push(fn); },
57
61
  getActiveTools: () => activeTools,
58
62
  getAllTools: () => activeTools.map((name) => ({ name })),
@@ -89,5 +93,6 @@ export function createFakePi(activeTools: string[] = ["bash", "read", "edit", "g
89
93
  messages,
90
94
  commands,
91
95
  notifications,
96
+ tools,
92
97
  };
93
98
  }
@@ -54,6 +54,7 @@ describe("readSteeringSettings layering", () => {
54
54
  stripReasoning: true,
55
55
  dsAnchor: true,
56
56
  weNeed: false,
57
+ thinkTool: false,
57
58
  });
58
59
  });
59
60
 
@@ -134,6 +135,7 @@ describe("/config contribution", () => {
134
135
  "steering.stripReasoning",
135
136
  "steering.dsAnchor",
136
137
  "steering.weNeed",
138
+ "steering.thinkTool",
137
139
  ]);
138
140
  const anchor = groups[0].rows.find((r) => r.key === "steering.dsAnchor")!;
139
141
  assert.equal(anchor.kind, "toggle");