ceulen 0.1.0 → 0.5.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.
- package/CHANGELOG.md +150 -0
- package/README.md +103 -14
- package/extensions/index.ts +113 -0
- package/extensions/lib/env.ts +75 -0
- package/extensions/lib/panel.ts +1720 -0
- package/extensions/lib/registry.ts +182 -0
- package/extensions/modules/composer/index.ts +128 -0
- package/extensions/modules/composer/lib/settings.ts +55 -0
- package/extensions/modules/composer/lib/shapes.ts +436 -0
- package/extensions/modules/composer/test/editor.test.ts +138 -0
- package/extensions/modules/composer/test/module.test.ts +218 -0
- package/extensions/modules/composer/test/screen.test.ts +195 -0
- package/extensions/modules/composer/test/shapes.test.ts +175 -0
- package/extensions/modules/config/index.ts +298 -0
- package/extensions/modules/config/piSettings.ts +467 -0
- package/extensions/modules/config/plugins.ts +290 -0
- package/extensions/modules/config/test/kernel.test.ts +523 -0
- package/extensions/modules/config/test/kernelV4.test.ts +196 -0
- package/extensions/modules/config/test/menu.test.ts +226 -0
- package/extensions/modules/config/test/panel.test.ts +395 -0
- package/extensions/modules/config/test/piSettings.test.ts +185 -0
- package/extensions/modules/config/test/plugins.test.ts +181 -0
- package/extensions/modules/config/test/preview-block.test.ts +88 -0
- package/extensions/modules/ponytail/UPSTREAM +26 -0
- package/extensions/modules/ponytail/index.ts +336 -0
- package/extensions/modules/ponytail/lib/config.ts +149 -0
- package/extensions/modules/ponytail/lib/instructions.ts +98 -0
- package/extensions/modules/ponytail/lib/subagent.ts +31 -0
- package/extensions/modules/ponytail/test/extension.test.ts +422 -0
- package/extensions/modules/ponytail/test/helpers.test.ts +163 -0
- package/extensions/modules/ponytail/test/subagent.test.ts +33 -0
- package/extensions/modules/router/commands/commands.ts +99 -0
- package/extensions/modules/router/configPanel.ts +89 -0
- package/extensions/modules/router/index.ts +75 -0
- package/extensions/modules/router/lib/client.ts +390 -0
- package/extensions/modules/router/lib/config.ts +142 -0
- package/extensions/modules/router/lib/migrate.ts +92 -0
- package/extensions/modules/router/lib/provider.ts +138 -0
- package/extensions/modules/router/lib/refresh.ts +19 -0
- package/extensions/modules/router/test/guard.test.ts +77 -0
- package/extensions/modules/router/test/unit.test.ts +1126 -0
- package/extensions/modules/usage/index.ts +1975 -0
- package/extensions/modules/usage/test/context.test.ts +387 -0
- package/extensions/modules/usage/test/env-gating.test.ts +113 -0
- package/extensions/modules/usage/test/opencode-go-usage.test.ts +139 -0
- package/extensions/modules/usage/test/parsers.test.ts +244 -0
- package/extensions/modules/usage/test/stale-ctx-regression.test.ts +294 -0
- package/extensions/modules/usage/test/zai-anthropic-adapter.test.ts +40 -0
- package/package.json +15 -3
- package/skills/ponytail/SKILL.md +124 -0
- package/skills/ponytail-audit/SKILL.md +41 -0
- package/skills/ponytail-debt/SKILL.md +44 -0
- package/skills/ponytail-gain/SKILL.md +51 -0
- package/skills/ponytail-help/SKILL.md +73 -0
- package/skills/ponytail-review/SKILL.md +57 -0
- package/extensions/index.js +0 -42
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugins group tests — Pi package enable/disable via the `packages` array.
|
|
3
|
+
*
|
|
4
|
+
* Contract under test (Pi's package-manager load rules):
|
|
5
|
+
* string entry → load everything
|
|
6
|
+
* object, no resource arrays / autoload unset → load everything
|
|
7
|
+
* object, all four arrays empty → load NONE (the off form)
|
|
8
|
+
* object with patterns / partial [] → filtered (read-only here)
|
|
9
|
+
* object, autoload: false → project delta (read-only here)
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, it, before, after } from "node:test";
|
|
13
|
+
import assert from "node:assert/strict";
|
|
14
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
|
|
18
|
+
const TMP_HOME = join(tmpdir(), "ceulen-plugins-test-" + process.pid);
|
|
19
|
+
before(() => {
|
|
20
|
+
mkdirSync(TMP_HOME, { recursive: true });
|
|
21
|
+
process.env.PI_CODING_AGENT_DIR = TMP_HOME;
|
|
22
|
+
});
|
|
23
|
+
after(() => {
|
|
24
|
+
delete process.env.PI_CODING_AGENT_DIR;
|
|
25
|
+
try { rmSync(TMP_HOME, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const settingsPath = () => join(TMP_HOME, "settings.json");
|
|
29
|
+
|
|
30
|
+
const load = async () => import("../plugins.js");
|
|
31
|
+
|
|
32
|
+
describe("plugins — state contract", () => {
|
|
33
|
+
it("classifies every entry shape by Pi's load rules", async () => {
|
|
34
|
+
const { packageState } = await load();
|
|
35
|
+
assert.equal(packageState("npm:@a/accordion"), "on");
|
|
36
|
+
assert.equal(packageState({ source: "npm:@a/accordion" }), "on");
|
|
37
|
+
assert.equal(packageState({ source: "npm:@a/accordion", autoload: false }), "filtered");
|
|
38
|
+
assert.equal(
|
|
39
|
+
packageState({ source: "npm:@a/accordion", extensions: [], skills: [], prompts: [], themes: [] }),
|
|
40
|
+
"off",
|
|
41
|
+
);
|
|
42
|
+
// Partial empty arrays / patterns → granular pi-config setup, read-only.
|
|
43
|
+
assert.equal(packageState({ source: "x", extensions: [] }), "filtered");
|
|
44
|
+
assert.equal(packageState({ source: "x", extensions: ["+a.ts", "-b.ts"] }), "filtered");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("labels npm, git, and local sources without version noise", async () => {
|
|
48
|
+
const { packageLabel } = await load();
|
|
49
|
+
assert.equal(packageLabel("npm:@a-fig/accordion@1.2.3"), "@a-fig/accordion");
|
|
50
|
+
assert.equal(packageLabel("npm:@a-fig/accordion"), "@a-fig/accordion");
|
|
51
|
+
assert.equal(packageLabel("git:github.com/example/pi-tools@v1"), "pi-tools");
|
|
52
|
+
assert.equal(packageLabel("https://github.com/example/pi-tools.git"), "pi-tools");
|
|
53
|
+
assert.equal(packageLabel("../../../../Volumes/Dev/agents/pi-extensions/pi-a2a"), "pi-a2a");
|
|
54
|
+
assert.equal(packageLabel("/Volumes/Dev/agents/ceulen"), "ceulen");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("flips on ⇄ off with the exact forms Pi understands", async () => {
|
|
58
|
+
const { flipPackage, packageState } = await load();
|
|
59
|
+
const off = flipPackage("npm:@a/x", false) as Record<string, unknown>;
|
|
60
|
+
assert.deepEqual(off, { source: "npm:@a/x", extensions: [], skills: [], prompts: [], themes: [] });
|
|
61
|
+
assert.equal(packageState(off), "off");
|
|
62
|
+
assert.equal(flipPackage(off, true), "npm:@a/x");
|
|
63
|
+
// Filtered entries pass through untouched.
|
|
64
|
+
const filtered = { source: "x", extensions: ["+a"] };
|
|
65
|
+
assert.equal(flipPackage(filtered, false), filtered);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("plugins — read", () => {
|
|
70
|
+
it("reads global + trusted-project entries, project first", async () => {
|
|
71
|
+
writeFileSync(settingsPath(), JSON.stringify({ packages: ["npm:global-one"] }));
|
|
72
|
+
const { readPackageEntries } = await load();
|
|
73
|
+
let entries = readPackageEntries(TMP_HOME); // untrusted cwd → global only
|
|
74
|
+
assert.deepEqual(entries.map((e) => [e.source, e.scope, e.state]), [["npm:global-one", "global", "on"]]);
|
|
75
|
+
|
|
76
|
+
// Trust the project cwd, add a project package.
|
|
77
|
+
const project = join(TMP_HOME, "proj");
|
|
78
|
+
mkdirSync(join(project, ".pi"), { recursive: true });
|
|
79
|
+
writeFileSync(join(TMP_HOME, "trust.json"), JSON.stringify({ [project]: true }));
|
|
80
|
+
writeFileSync(join(project, ".pi", "settings.json"), JSON.stringify({ packages: ["npm:proj-one"] }));
|
|
81
|
+
entries = readPackageEntries(project);
|
|
82
|
+
assert.deepEqual(entries.map((e) => [e.source, e.scope]), [["npm:proj-one", "project"], ["npm:global-one", "global"]]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("empty install shows the discoverability hint row", async () => {
|
|
86
|
+
writeFileSync(settingsPath(), JSON.stringify({}));
|
|
87
|
+
const { buildPluginsGroups, openPluginsWorking } = await load();
|
|
88
|
+
const groups = buildPluginsGroups(openPluginsWorking(TMP_HOME));
|
|
89
|
+
assert.equal(groups.length, 1, "one hint group when nothing is installed");
|
|
90
|
+
assert.equal(groups[0]!.rows.length, 1);
|
|
91
|
+
assert.equal(groups[0]!.rows[0]!.kind, "info");
|
|
92
|
+
assert.ok(groups[0]!.rows[0]!.description!.includes("pi install"));
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("toggleable rows expose toggle kind; filtered rows are info/read-only", async () => {
|
|
96
|
+
writeFileSync(settingsPath(), JSON.stringify({
|
|
97
|
+
packages: ["npm:on-one", { source: "npm:off-one", extensions: [], skills: [], prompts: [], themes: [] }, { source: "npm:custom", extensions: ["+x.ts"] }],
|
|
98
|
+
}));
|
|
99
|
+
const { buildPluginsGroups, openPluginsWorking } = await load();
|
|
100
|
+
const rows = buildPluginsGroups(openPluginsWorking(TMP_HOME)).flatMap((g: any) => g.rows);
|
|
101
|
+
assert.deepEqual(rows.map((r) => [r.label, r.kind, r.value]), [
|
|
102
|
+
["on-one", "toggle", true],
|
|
103
|
+
["off-one", "toggle", false],
|
|
104
|
+
["custom", "info", "custom filters"],
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("plugins — write", () => {
|
|
110
|
+
it("toggling off writes the all-empty-array form into the file that owns the entry", async () => {
|
|
111
|
+
writeFileSync(settingsPath(), JSON.stringify({ theme: "dark", packages: ["npm:k"] }));
|
|
112
|
+
const { buildPluginsGroups, openPluginsWorking, savePlugins } = await load();
|
|
113
|
+
const working = openPluginsWorking(TMP_HOME);
|
|
114
|
+
const row = buildPluginsGroups(working).flatMap((g: any) => g.rows)[0]!;
|
|
115
|
+
row.set(false);
|
|
116
|
+
const written = savePlugins(working);
|
|
117
|
+
assert.deepEqual(written, [settingsPath()]);
|
|
118
|
+
const json = JSON.parse(readFileSync(settingsPath(), "utf8"));
|
|
119
|
+
assert.equal(json.theme, "dark", "unrelated keys survive");
|
|
120
|
+
assert.deepEqual(json.packages, [{ source: "npm:k", extensions: [], skills: [], prompts: [], themes: [] }]);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("toggling back on restores the string form; no-op save writes nothing", async () => {
|
|
124
|
+
writeFileSync(settingsPath(), JSON.stringify({ packages: [{ source: "npm:k", extensions: [], skills: [], prompts: [], themes: [] }] }));
|
|
125
|
+
const { buildPluginsGroups, openPluginsWorking, savePlugins } = await load();
|
|
126
|
+
const working = openPluginsWorking(TMP_HOME);
|
|
127
|
+
assert.deepEqual(savePlugins(openPluginsWorking(TMP_HOME)), [], "no edits → no write");
|
|
128
|
+
const row = buildPluginsGroups(working).flatMap((g: any) => g.rows)[0]!;
|
|
129
|
+
assert.equal(row.value, false);
|
|
130
|
+
row.set(true);
|
|
131
|
+
savePlugins(working);
|
|
132
|
+
assert.deepEqual(JSON.parse(readFileSync(settingsPath(), "utf8")).packages, ["npm:k"]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("project entries write to the project file, global stays untouched", async () => {
|
|
136
|
+
const project = join(TMP_HOME, "proj2");
|
|
137
|
+
mkdirSync(join(project, ".pi"), { recursive: true });
|
|
138
|
+
writeFileSync(join(TMP_HOME, "trust.json"), JSON.stringify({ [project]: true }));
|
|
139
|
+
writeFileSync(settingsPath(), JSON.stringify({ packages: ["npm:g"] }));
|
|
140
|
+
writeFileSync(join(project, ".pi", "settings.json"), JSON.stringify({ packages: ["npm:p"] }));
|
|
141
|
+
const { buildPluginsGroups, openPluginsWorking, savePlugins } = await load();
|
|
142
|
+
const working = openPluginsWorking(project);
|
|
143
|
+
const groups = buildPluginsGroups(working);
|
|
144
|
+
// Both scopes share ONE tab; each scope is its own SECTION (sidebar).
|
|
145
|
+
assert.deepEqual(groups.map((g) => [g.tab, g.label]), [["Plugins", "Project"], ["Plugins", "Global"]]);
|
|
146
|
+
const rows = groups.flatMap((g: any) => g.rows);
|
|
147
|
+
assert.deepEqual(rows.map((r) => r.label), ["p", "g"], "project entries first");
|
|
148
|
+
rows[0]!.set(false);
|
|
149
|
+
const written = savePlugins(working);
|
|
150
|
+
assert.deepEqual(written, [join(project, ".pi", "settings.json")]);
|
|
151
|
+
assert.deepEqual(JSON.parse(readFileSync(settingsPath(), "utf8")).packages, ["npm:g"]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("an unreadable settings file degrades to no entries (nothing toggles, nothing writes)", async () => {
|
|
155
|
+
writeFileSync(settingsPath(), '{ "packages": ["npm:k"]\nOOPS');
|
|
156
|
+
const { readPackageEntries, buildPluginsGroups, openPluginsWorking, savePlugins } = await load();
|
|
157
|
+
assert.deepEqual(readPackageEntries(TMP_HOME), [], "corrupt read degrades like readDisabled");
|
|
158
|
+
const working = openPluginsWorking(TMP_HOME);
|
|
159
|
+
const groups = buildPluginsGroups(working);
|
|
160
|
+
assert.equal(groups[0]!.rows[0]!.kind, "info", "hint row, not a broken toggle");
|
|
161
|
+
assert.deepEqual(savePlugins(working), [], "nothing to write — corrupt file untouched");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("writePackages refuses a corrupt file (atomicity guard backstop)", async () => {
|
|
165
|
+
const { writePackages } = await load();
|
|
166
|
+
writeFileSync(settingsPath(), '{ "packages": ["npm:k"]\nOOPS');
|
|
167
|
+
const before = readFileSync(settingsPath(), "utf8");
|
|
168
|
+
assert.throws(() => writePackages(settingsPath(), ["npm:k"]), /not valid JSON/);
|
|
169
|
+
assert.equal(readFileSync(settingsPath(), "utf8"), before);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("read-only rows cannot be flipped by a stray set()", async () => {
|
|
173
|
+
writeFileSync(settingsPath(), JSON.stringify({ packages: [{ source: "npm:c", extensions: ["+x.ts"] }] }));
|
|
174
|
+
const { buildPluginsGroups, openPluginsWorking, savePlugins } = await load();
|
|
175
|
+
const working = openPluginsWorking(TMP_HOME);
|
|
176
|
+
const row = buildPluginsGroups(working).flatMap((g: any) => g.rows)[0]!;
|
|
177
|
+
row.set(false);
|
|
178
|
+
assert.deepEqual(savePlugins(working), [], "filtered entry unchanged");
|
|
179
|
+
assert.deepEqual(JSON.parse(readFileSync(settingsPath(), "utf8")).packages, [{ source: "npm:c", extensions: ["+x.ts"] }]);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel preview block — a selected row's (or open menu's highlighted
|
|
3
|
+
* option's) `previewLines` render as a read-only block under the rows pane,
|
|
4
|
+
* clamped into the remaining body budget; the frame geometry stays exact.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it } from "node:test";
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
10
|
+
import { ConfigPanelModel, row, type PanelGroup } from "../../../lib/panel.js";
|
|
11
|
+
|
|
12
|
+
const theme = null;
|
|
13
|
+
const plain = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, "");
|
|
14
|
+
|
|
15
|
+
const HEIGHT = 40;
|
|
16
|
+
// Frame chrome: top + tabs + divider + blank + 3 desc + divider + footer + bottom = 10.
|
|
17
|
+
const BODY_ROWS = HEIGHT - 10;
|
|
18
|
+
|
|
19
|
+
function panel(rows: PanelGroup["rows"], height = HEIGHT): ConfigPanelModel {
|
|
20
|
+
const g: PanelGroup[] = [{ key: "s", label: "Section", rows }];
|
|
21
|
+
const m = new ConfigPanelModel(g, theme, "T");
|
|
22
|
+
m.getHeight = () => height;
|
|
23
|
+
return m;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const body = (m: ConfigPanelModel) => m.render(100).slice(3, -7).map(plain);
|
|
27
|
+
|
|
28
|
+
const previewRow = (lines: string[]) =>
|
|
29
|
+
row("shape", "Shape", "string", "a", () => {}, {
|
|
30
|
+
values: ["a", "b"],
|
|
31
|
+
previewLines: (v: string) => [`${v}-one`, `${v}-two`, `${v}-three`],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("kernel preview block", () => {
|
|
35
|
+
it("renders under the rows pane for the selected row; absent without the hook", () => {
|
|
36
|
+
const withHook = body(panel([previewRow([])])).join("\n");
|
|
37
|
+
assert.ok(withHook.includes("Preview:"), "label present");
|
|
38
|
+
assert.ok(withHook.includes("a-one"), "current value previewed");
|
|
39
|
+
assert.ok(!withHook.includes("b-one"), "only the current value");
|
|
40
|
+
|
|
41
|
+
const noHook = body(panel([row("x", "X", "toggle", true, () => {})])).join("\n");
|
|
42
|
+
assert.ok(!noHook.includes("Preview:"), "no block without previewLines");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("follows the highlighted option while the submenu is open", () => {
|
|
46
|
+
const m = panel([previewRow([])]);
|
|
47
|
+
m.handleInput("\r"); // open menu, cursor on current value "a"
|
|
48
|
+
assert.ok(m.menuOpen);
|
|
49
|
+
let text = body(m).join("\n");
|
|
50
|
+
assert.ok(text.includes("a-one"), "preview shows option a");
|
|
51
|
+
m.handleInput("\u001b[B"); // ↓ to "b"
|
|
52
|
+
text = body(m).join("\n");
|
|
53
|
+
assert.ok(text.includes("b-one"), "preview followed to b");
|
|
54
|
+
assert.ok(!text.includes("a-one"), "stale preview gone");
|
|
55
|
+
m.handleInput("\u001b"); // close menu — selection unchanged
|
|
56
|
+
assert.equal(m.menuOpen, false);
|
|
57
|
+
assert.ok(body(m).join("\n").includes("a-one"), "back to the row's own value");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("clamps into the body budget; frame geometry invariant", () => {
|
|
61
|
+
const m = panel([previewRow([])]);
|
|
62
|
+
const out = m.render(100);
|
|
63
|
+
assert.equal(out.length, HEIGHT, "frame stays max(14, getHeight()) lines");
|
|
64
|
+
const many = body(panel([previewRow([])])).join("\n");
|
|
65
|
+
assert.ok(many.includes("Preview:"), "label present");
|
|
66
|
+
assert.ok(many.includes("a-two") || many.includes("a-one"), "at least one preview line fits");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("tight body: preview shrinks or skips cleanly, frame height honored", () => {
|
|
70
|
+
// max(14,13)=14 → body=4 rows: rows pane eats 1, blank+label+1 line fits.
|
|
71
|
+
const tiny = panel([previewRow([])], 13);
|
|
72
|
+
const out = tiny.render(100);
|
|
73
|
+
assert.equal(out.length, Math.max(14, 13), "height honored at small sizes");
|
|
74
|
+
const text = out.slice(3, -7).map(plain).join("\n");
|
|
75
|
+
assert.ok(text.includes("a-one") || !text.includes("Preview:"), "either fits or skips cleanly");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("preview lines are truncated to the inner width", () => {
|
|
79
|
+
const long = row("shape", "Shape", "string", "a", () => {}, {
|
|
80
|
+
values: ["a"],
|
|
81
|
+
previewLines: () => ["x".repeat(200)],
|
|
82
|
+
});
|
|
83
|
+
const m = panel([long]);
|
|
84
|
+
for (const line of m.render(100)) {
|
|
85
|
+
assert.ok(visibleWidth(line) <= 100, `line overflow: ${visibleWidth(line)}`);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
upstream-url: https://github.com/DietrichGebert/ponytail.git
|
|
2
|
+
upstream-version: 4.9.0
|
|
3
|
+
upstream-commit: 0a4dd63ad4541f4f655c4108a295916f3c1d8fda
|
|
4
|
+
upstream-date: 2026-08-07
|
|
5
|
+
fork-date: 2026-07-02
|
|
6
|
+
fork-commit: (initial import of pi-ponytail)
|
|
7
|
+
sync-date: 2026-09-04
|
|
8
|
+
|
|
9
|
+
# Sync state at 0.1.13 (v4.9.0):
|
|
10
|
+
# - All 6 skills carry full upstream v4.9.0 content; differences are pi trigger
|
|
11
|
+
# syntax (/skill:ponytail-*) and 4 local rule additions in skills/ponytail/SKILL.md.
|
|
12
|
+
# - Extension carries every pi-relevant v4.9.0 fix (#336, #439/#440, #514, #541,
|
|
13
|
+
# #544, #559, #571, #576, #99, BOM strip).
|
|
14
|
+
# - Post-v4.9.0 upstream commits are host adapters (Grok, VS Code Copilot,
|
|
15
|
+
# Claude.ai marketplace) — N/A for Pi.
|
|
16
|
+
# - Pi-native addition: subagent injection via tool_call hook (upstream #254/#522
|
|
17
|
+
# equivalent), PONYTAIL_SUBAGENT_SCOPE=off to disable.
|
|
18
|
+
|
|
19
|
+
# To diff against upstream:
|
|
20
|
+
# git remote add upstream https://github.com/DietrichGebert/ponytail.git
|
|
21
|
+
# git fetch upstream
|
|
22
|
+
# git diff upstream/main -- pi-ponytail/
|
|
23
|
+
#
|
|
24
|
+
# To cherry-pick a specific upstream commit into pi-ponytail's files:
|
|
25
|
+
# git fetch upstream
|
|
26
|
+
# git cherry-pick -X subtree=pi-ponytail <commit>
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
// ponytail module — lazy-senior-dev mode for Pi.
|
|
2
|
+
//
|
|
3
|
+
// Ported from pi-ponytail extensions/index.js (ESM JS → TS). Registers the
|
|
4
|
+
// /ponytail mode switcher + /ponytail-* skill aliases, the status-bar
|
|
5
|
+
// indicator, per-turn system-prompt injection, and subagent instruction
|
|
6
|
+
// inheritance. Exports the pure helpers for tests.
|
|
7
|
+
|
|
8
|
+
import type {
|
|
9
|
+
BeforeAgentStartEventResult,
|
|
10
|
+
CustomToolCallEvent,
|
|
11
|
+
ExtensionAPI,
|
|
12
|
+
ExtensionContext,
|
|
13
|
+
SessionEntry,
|
|
14
|
+
} from "@earendil-works/pi-coding-agent";
|
|
15
|
+
import {
|
|
16
|
+
DEFAULT_MODE,
|
|
17
|
+
RUNTIME_MODES,
|
|
18
|
+
VALID_MODES,
|
|
19
|
+
getDefaultMode,
|
|
20
|
+
getHideStatus,
|
|
21
|
+
getQuietStartup,
|
|
22
|
+
isDeactivationCommand,
|
|
23
|
+
normalizeMode,
|
|
24
|
+
normalizePersistedMode,
|
|
25
|
+
writeConfigBools,
|
|
26
|
+
writeDefaultMode,
|
|
27
|
+
type PonytailMode,
|
|
28
|
+
} from "./lib/config.js";
|
|
29
|
+
import { row, type PanelGroup } from "../../lib/panel.js";
|
|
30
|
+
import type { ModuleConfig } from "../../lib/registry.js";
|
|
31
|
+
import { filterSkillBodyForMode, getPonytailInstructions } from "./lib/instructions.js";
|
|
32
|
+
import { getSubagentInstructions, shouldInjectSubagentInstructions } from "./lib/subagent.js";
|
|
33
|
+
|
|
34
|
+
// ponytail: must match pi-subagent security.ts MAX_INSTRUCTIONS_LENGTH (instructions cap).
|
|
35
|
+
const SUBAGENT_INSTRUCTIONS_CAP = 16 * 1024;
|
|
36
|
+
|
|
37
|
+
export { filterSkillBodyForMode };
|
|
38
|
+
export const readDefaultMode = getDefaultMode;
|
|
39
|
+
export const readQuietStartup = getQuietStartup;
|
|
40
|
+
|
|
41
|
+
/** A persisted ponytail-mode session entry (written via pi.appendEntry). */
|
|
42
|
+
interface PonytailModeEntry {
|
|
43
|
+
type: string;
|
|
44
|
+
customType?: string;
|
|
45
|
+
data?: { mode?: unknown };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function resolveSessionMode(entries: unknown, fallbackMode: string = DEFAULT_MODE): PonytailMode {
|
|
49
|
+
const fallback = normalizePersistedMode(fallbackMode) || DEFAULT_MODE;
|
|
50
|
+
if (!Array.isArray(entries)) return fallback;
|
|
51
|
+
|
|
52
|
+
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
53
|
+
const entry = entries[i] as PonytailModeEntry | undefined;
|
|
54
|
+
if (entry?.type !== "custom" || entry?.customType !== "ponytail-mode") continue;
|
|
55
|
+
|
|
56
|
+
const mode = normalizePersistedMode(entry?.data?.mode);
|
|
57
|
+
if (mode) return mode;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return fallback;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface ParsedCommand {
|
|
64
|
+
type: "status" | "set-mode" | "invalid";
|
|
65
|
+
mode?: string;
|
|
66
|
+
reason?: "invalid-mode";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function parsePonytailCommand(text: unknown): ParsedCommand {
|
|
70
|
+
const normalizedText = String(text || "").trim().toLowerCase();
|
|
71
|
+
|
|
72
|
+
if (!normalizedText) {
|
|
73
|
+
// ponytail: bare invocation reports status instead of resetting (#99); explicit mode to change level.
|
|
74
|
+
return { type: "status" };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const primary = normalizedText.split(/\s+/)[0];
|
|
78
|
+
|
|
79
|
+
if (primary === "status") return { type: "status" };
|
|
80
|
+
|
|
81
|
+
const mode = normalizePersistedMode(primary);
|
|
82
|
+
return mode ? { type: "set-mode", mode } : { type: "invalid", reason: "invalid-mode", mode: primary };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { writeDefaultMode };
|
|
86
|
+
|
|
87
|
+
export interface PonytailSettings {
|
|
88
|
+
defaultMode: string;
|
|
89
|
+
quietStartup: boolean;
|
|
90
|
+
hideStatus: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Build the ponytail panel groups over a working copy (mutated by row
|
|
94
|
+
* setters). Exported for tests. */
|
|
95
|
+
export function buildPonytailGroups(cfg: PonytailSettings): PanelGroup[] {
|
|
96
|
+
return [
|
|
97
|
+
{
|
|
98
|
+
key: "ponytail",
|
|
99
|
+
label: "Ponytail",
|
|
100
|
+
tab: "Tasks",
|
|
101
|
+
icon: "🦥",
|
|
102
|
+
rows: [
|
|
103
|
+
row("ponytail.defaultMode", "Default mode", "string", cfg.defaultMode, (v) => {
|
|
104
|
+
cfg.defaultMode = String(v ?? "").trim();
|
|
105
|
+
}, {
|
|
106
|
+
values: RUNTIME_MODES,
|
|
107
|
+
defaultValue: DEFAULT_MODE,
|
|
108
|
+
description: "Ponytail intensity for new sessions (review is session-only, not a default). PONYTAIL_DEFAULT_MODE env overrides the saved value.",
|
|
109
|
+
}),
|
|
110
|
+
row("ponytail.quietStartup", "Quiet startup", "toggle", cfg.quietStartup, (v) => {
|
|
111
|
+
cfg.quietStartup = Boolean(v);
|
|
112
|
+
}, {
|
|
113
|
+
description: "Skip the startup mode banner. PONYTAIL_QUIET_STARTUP env overrides the saved value.",
|
|
114
|
+
defaultValue: false,
|
|
115
|
+
}),
|
|
116
|
+
row("ponytail.hideStatus", "Hide status bar", "toggle", cfg.hideStatus, (v) => {
|
|
117
|
+
cfg.hideStatus = Boolean(v);
|
|
118
|
+
}, {
|
|
119
|
+
description: "Hide the status-bar mode segment. PONYTAIL_HIDE_STATUS env overrides the saved value.",
|
|
120
|
+
defaultValue: false,
|
|
121
|
+
}),
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const OWNED_KEYS = ["ponytail.defaultMode", "ponytail.quietStartup", "ponytail.hideStatus"];
|
|
128
|
+
|
|
129
|
+
/** Ponytail's ModuleConfig for the central /config panel. Row descriptions +
|
|
130
|
+
* warnings disclose env precedence and next-session timing; the save notify
|
|
131
|
+
* stays a short confirmation (plus an env caveat when it actually bit). */
|
|
132
|
+
export function ponytailConfig(): ModuleConfig {
|
|
133
|
+
const before: PonytailSettings = {
|
|
134
|
+
defaultMode: getDefaultMode(),
|
|
135
|
+
quietStartup: getQuietStartup(),
|
|
136
|
+
hideStatus: getHideStatus(),
|
|
137
|
+
};
|
|
138
|
+
const working = structuredClone(before);
|
|
139
|
+
return {
|
|
140
|
+
groups: () => buildPonytailGroups(working),
|
|
141
|
+
save: async (edited, ctx) => {
|
|
142
|
+
if (!OWNED_KEYS.some((k) => edited.has(k))) return;
|
|
143
|
+
|
|
144
|
+
// Bools first: they're independent of the mode's validity.
|
|
145
|
+
if (working.quietStartup !== before.quietStartup || working.hideStatus !== before.hideStatus) {
|
|
146
|
+
writeConfigBools({
|
|
147
|
+
quietStartup: working.quietStartup !== before.quietStartup ? working.quietStartup : undefined,
|
|
148
|
+
hideStatus: working.hideStatus !== before.hideStatus ? working.hideStatus : undefined,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let modeNote = "";
|
|
153
|
+
if (working.defaultMode !== before.defaultMode) {
|
|
154
|
+
const mode = normalizeMode(working.defaultMode);
|
|
155
|
+
if (!mode) {
|
|
156
|
+
ctx.ui.notify(`Invalid ponytail default mode “${working.defaultMode}”. Use: ${RUNTIME_MODES.join(", ")}.`, "warning");
|
|
157
|
+
} else {
|
|
158
|
+
writeDefaultMode(mode);
|
|
159
|
+
// Report the EFFECTIVE default — PONYTAIL_DEFAULT_MODE env wins.
|
|
160
|
+
const effective = getDefaultMode();
|
|
161
|
+
if (effective !== mode) {
|
|
162
|
+
modeNote = ` PONYTAIL_DEFAULT_MODE env keeps the default at ${effective}.`;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Row descriptions already disclose env precedence; the notify adds the
|
|
168
|
+
// caveat only when an env var actually shadowed this save.
|
|
169
|
+
const envBooleans = process.env.PONYTAIL_HIDE_STATUS || process.env.PONYTAIL_QUIET_STARTUP;
|
|
170
|
+
ctx.ui.notify(
|
|
171
|
+
`Ponytail config saved.${modeNote}` +
|
|
172
|
+
(envBooleans ? " PONYTAIL_* env vars override the saved booleans." : "") +
|
|
173
|
+
" Applied from the next session (or /reload).",
|
|
174
|
+
modeNote || envBooleans ? "warning" : "info",
|
|
175
|
+
);
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export default function ponytailExtension(pi: ExtensionAPI) {
|
|
181
|
+
// Skills ship in-package (../skills/, 3 levels up from the module dir) and are
|
|
182
|
+
// contributed through resources_discover — NOT via the package.json `pi.skills`
|
|
183
|
+
// manifest — so the kill-switch gates them too: disabled module ⇒ factory never
|
|
184
|
+
// runs ⇒ no /skill:ponytail* entries registered.
|
|
185
|
+
pi.on("resources_discover", () => ({ skillPaths: [new URL("../../../skills/", import.meta.url).pathname] }));
|
|
186
|
+
|
|
187
|
+
let currentMode: PonytailMode = DEFAULT_MODE;
|
|
188
|
+
let configuredDefaultMode: PonytailMode = getDefaultMode();
|
|
189
|
+
let hideStatus = getHideStatus();
|
|
190
|
+
|
|
191
|
+
// -- Status bar --
|
|
192
|
+
function syncStatus(ctx: ExtensionContext | undefined | null) {
|
|
193
|
+
if (hideStatus) return;
|
|
194
|
+
if (!ctx?.ui?.setStatus) return;
|
|
195
|
+
// ponytail: try/catch guards against pi-web theme proxy throwing before initTheme (#336).
|
|
196
|
+
let theme: ExtensionContext["ui"]["theme"] | undefined;
|
|
197
|
+
try {
|
|
198
|
+
theme = ctx.ui.theme;
|
|
199
|
+
if (!theme?.fg) return;
|
|
200
|
+
} catch {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (currentMode === "off") {
|
|
204
|
+
try {
|
|
205
|
+
ctx.ui.setStatus("ponytail", "");
|
|
206
|
+
} catch {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
{
|
|
212
|
+
const levelIcons: Record<string, string> = { lite: "🌿", full: "⚡", ultra: "🔥", review: "🔍" };
|
|
213
|
+
const icon = levelIcons[currentMode] || "";
|
|
214
|
+
const label = currentMode.toUpperCase();
|
|
215
|
+
try {
|
|
216
|
+
ctx.ui.setStatus("ponytail", " 🐴 " + theme.fg("muted", "ponytail: ") + theme.fg("text", icon + " " + label));
|
|
217
|
+
} catch {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const setMode = (mode: string, ctx?: ExtensionContext | null) => {
|
|
224
|
+
const normalized = normalizePersistedMode(mode);
|
|
225
|
+
if (!normalized) return;
|
|
226
|
+
// ponytail: 'review' is session-only — it updates the live session but must
|
|
227
|
+
// not ride the persisted-entry channel (a reload can't resurrect it).
|
|
228
|
+
if (normalized !== "review") pi.appendEntry("ponytail-mode", { mode: normalized });
|
|
229
|
+
currentMode = normalized;
|
|
230
|
+
syncStatus(ctx);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
pi.registerCommand("ponytail", {
|
|
234
|
+
description: `Set mode: ${VALID_MODES.join("|")} (review is session-only), or status`,
|
|
235
|
+
getArgumentCompletions: (prefix) => {
|
|
236
|
+
const q = String(prefix || "").trim().toLowerCase();
|
|
237
|
+
const vocab = [...VALID_MODES, "status"];
|
|
238
|
+
const items = vocab.filter((k) => k.startsWith(q)).map((k) => ({ value: k, label: k }));
|
|
239
|
+
return items.length > 0 ? items : null;
|
|
240
|
+
},
|
|
241
|
+
handler: async (args, ctx) => {
|
|
242
|
+
const parsed = parsePonytailCommand(args);
|
|
243
|
+
|
|
244
|
+
if (parsed.type === "status") {
|
|
245
|
+
ctx?.ui?.notify?.(`Ponytail: current ${currentMode} • default ${configuredDefaultMode} • /ponytail <mode> to change`, "info");
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (parsed.type === "set-mode") {
|
|
250
|
+
setMode(parsed.mode!, ctx);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (parsed.type === "invalid") {
|
|
255
|
+
const msg = `Unknown mode: ${parsed.mode}. Use: lite, full, ultra, off, or status.`;
|
|
256
|
+
ctx?.ui?.notify?.(msg, "warning");
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
for (const name of ["review", "audit", "gain", "debt", "help"] as const) {
|
|
263
|
+
pi.registerCommand(`ponytail-${name}`, {
|
|
264
|
+
description: `Run /skill:ponytail-${name}`,
|
|
265
|
+
handler: async () => {
|
|
266
|
+
await pi.sendUserMessage(`/skill:ponytail-${name}`, { expandPromptTemplates: true });
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
pi.on("input", async (event, ctx) => {
|
|
272
|
+
if (event?.source === "extension") return;
|
|
273
|
+
|
|
274
|
+
const text = String(event?.text || "");
|
|
275
|
+
if (currentMode !== "off" && isDeactivationCommand(text)) {
|
|
276
|
+
setMode("off", ctx);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
pi.on("agent_start", async (_event, ctx) => {
|
|
281
|
+
syncStatus(ctx);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
pi.on("agent_end", async (_event, ctx) => {
|
|
285
|
+
syncStatus(ctx);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
289
|
+
const sessionManager = ctx?.sessionManager;
|
|
290
|
+
const entries: SessionEntry[] =
|
|
291
|
+
(typeof sessionManager?.getBranch === "function" ? sessionManager.getBranch() : undefined) ??
|
|
292
|
+
(typeof sessionManager?.getEntries === "function" ? sessionManager.getEntries() : []) ??
|
|
293
|
+
[];
|
|
294
|
+
configuredDefaultMode = getDefaultMode();
|
|
295
|
+
hideStatus = getHideStatus();
|
|
296
|
+
currentMode = resolveSessionMode(entries, configuredDefaultMode);
|
|
297
|
+
syncStatus(ctx);
|
|
298
|
+
if (!getQuietStartup()) {
|
|
299
|
+
ctx?.ui?.notify?.(`Ponytail loaded: ${currentMode}`, "info");
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
pi.on("before_agent_start", async (event): Promise<BeforeAgentStartEventResult | undefined> => {
|
|
304
|
+
if (!currentMode || currentMode === "off") return;
|
|
305
|
+
// ponytail: suppress only a *leading* marker — the real prior-injection shapes
|
|
306
|
+
// (injected prompt leads with the block; an inherited Task Contract leads with
|
|
307
|
+
// it after "## Task Contract\n"). An incidental mid-text mention must not
|
|
308
|
+
// suppress injection, mirroring the tool_call side below.
|
|
309
|
+
const basePrompt = typeof event?.systemPrompt === "string" ? event.systemPrompt : "";
|
|
310
|
+
if (basePrompt.startsWith("PONYTAIL MODE ACTIVE") || basePrompt.includes("\n## Task Contract\nPONYTAIL MODE ACTIVE")) return;
|
|
311
|
+
// Guard null/undefined event and missing systemPrompt (#439, #440).
|
|
312
|
+
const base = event?.systemPrompt ? `${event.systemPrompt}\n\n` : "";
|
|
313
|
+
return { systemPrompt: `${base}${getPonytailInstructions(currentMode)}` };
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// ponytail: subagents run with loadExtensions:false, so the ruleset never reaches them (#254).
|
|
317
|
+
// Prepend a compact block to the subagent tool's instructions; pi-subagent applies it to every child.
|
|
318
|
+
pi.on("tool_call", async (event) => {
|
|
319
|
+
if (event?.toolName !== "subagent") return;
|
|
320
|
+
// ponytail: off and review skip injection; review defers to the /ponytail-review skill,
|
|
321
|
+
// which lean (extension-less) children cannot load.
|
|
322
|
+
if (!currentMode || currentMode === "off" || currentMode === "review") return;
|
|
323
|
+
if (!shouldInjectSubagentInstructions()) return;
|
|
324
|
+
const input = (event as CustomToolCallEvent).input;
|
|
325
|
+
if (!input || typeof input !== "object") return;
|
|
326
|
+
const existing = typeof input.instructions === "string" ? input.instructions : "";
|
|
327
|
+
// ponytail: startsWith, not includes — an incidental mid-text mention must not suppress injection.
|
|
328
|
+
if (existing.startsWith("PONYTAIL MODE ACTIVE")) return;
|
|
329
|
+
const block = getSubagentInstructions(currentMode);
|
|
330
|
+
const candidate = block + (existing ? "\n\n" + existing : "");
|
|
331
|
+
// ponytail: pi-subagent slices instructions at SUBAGENT_INSTRUCTIONS_CAP; skip rather
|
|
332
|
+
// than silently truncating the caller's contract to fit the injected block.
|
|
333
|
+
if (candidate.length > SUBAGENT_INSTRUCTIONS_CAP) return;
|
|
334
|
+
input.instructions = candidate;
|
|
335
|
+
});
|
|
336
|
+
}
|