ceulen 0.1.0 → 0.5.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 (56) hide show
  1. package/CHANGELOG.md +150 -0
  2. package/README.md +103 -14
  3. package/extensions/index.ts +113 -0
  4. package/extensions/lib/env.ts +75 -0
  5. package/extensions/lib/panel.ts +1720 -0
  6. package/extensions/lib/registry.ts +182 -0
  7. package/extensions/modules/composer/index.ts +128 -0
  8. package/extensions/modules/composer/lib/settings.ts +55 -0
  9. package/extensions/modules/composer/lib/shapes.ts +436 -0
  10. package/extensions/modules/composer/test/editor.test.ts +138 -0
  11. package/extensions/modules/composer/test/module.test.ts +218 -0
  12. package/extensions/modules/composer/test/screen.test.ts +195 -0
  13. package/extensions/modules/composer/test/shapes.test.ts +175 -0
  14. package/extensions/modules/config/index.ts +298 -0
  15. package/extensions/modules/config/piSettings.ts +467 -0
  16. package/extensions/modules/config/plugins.ts +290 -0
  17. package/extensions/modules/config/test/kernel.test.ts +523 -0
  18. package/extensions/modules/config/test/kernelV4.test.ts +196 -0
  19. package/extensions/modules/config/test/menu.test.ts +226 -0
  20. package/extensions/modules/config/test/panel.test.ts +395 -0
  21. package/extensions/modules/config/test/piSettings.test.ts +185 -0
  22. package/extensions/modules/config/test/plugins.test.ts +181 -0
  23. package/extensions/modules/config/test/preview-block.test.ts +88 -0
  24. package/extensions/modules/ponytail/UPSTREAM +26 -0
  25. package/extensions/modules/ponytail/index.ts +336 -0
  26. package/extensions/modules/ponytail/lib/config.ts +149 -0
  27. package/extensions/modules/ponytail/lib/instructions.ts +98 -0
  28. package/extensions/modules/ponytail/lib/subagent.ts +31 -0
  29. package/extensions/modules/ponytail/test/extension.test.ts +422 -0
  30. package/extensions/modules/ponytail/test/helpers.test.ts +163 -0
  31. package/extensions/modules/ponytail/test/subagent.test.ts +33 -0
  32. package/extensions/modules/router/commands/commands.ts +99 -0
  33. package/extensions/modules/router/configPanel.ts +89 -0
  34. package/extensions/modules/router/index.ts +75 -0
  35. package/extensions/modules/router/lib/client.ts +390 -0
  36. package/extensions/modules/router/lib/config.ts +142 -0
  37. package/extensions/modules/router/lib/migrate.ts +92 -0
  38. package/extensions/modules/router/lib/provider.ts +138 -0
  39. package/extensions/modules/router/lib/refresh.ts +19 -0
  40. package/extensions/modules/router/test/guard.test.ts +77 -0
  41. package/extensions/modules/router/test/unit.test.ts +1126 -0
  42. package/extensions/modules/usage/index.ts +1975 -0
  43. package/extensions/modules/usage/test/context.test.ts +387 -0
  44. package/extensions/modules/usage/test/env-gating.test.ts +113 -0
  45. package/extensions/modules/usage/test/opencode-go-usage.test.ts +139 -0
  46. package/extensions/modules/usage/test/parsers.test.ts +244 -0
  47. package/extensions/modules/usage/test/stale-ctx-regression.test.ts +294 -0
  48. package/extensions/modules/usage/test/zai-anthropic-adapter.test.ts +40 -0
  49. package/package.json +15 -3
  50. package/skills/ponytail/SKILL.md +124 -0
  51. package/skills/ponytail-audit/SKILL.md +41 -0
  52. package/skills/ponytail-debt/SKILL.md +44 -0
  53. package/skills/ponytail-gain/SKILL.md +51 -0
  54. package/skills/ponytail-help/SKILL.md +73 -0
  55. package/skills/ponytail-review/SKILL.md +57 -0
  56. package/extensions/index.js +0 -42
@@ -0,0 +1,422 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test from "node:test";
6
+
7
+ import ponytailExtension from "../index.ts";
8
+
9
+ /* Untyped harness stub: only the API surface the module actually touches.
10
+ * (Kept loose on purpose — pi's SDK types require a full context object.) */
11
+ function createPiHarness() {
12
+ const events = new Map();
13
+ const commands = new Map();
14
+ const appendedEntries = [];
15
+ const sentUserMessages = [];
16
+
17
+ const pi = {
18
+ on(eventName, handler) {
19
+ events.set(eventName, handler);
20
+ },
21
+ registerCommand(name, options) {
22
+ commands.set(name, options);
23
+ },
24
+ appendEntry(customType, data) {
25
+ appendedEntries.push({ customType, data });
26
+ },
27
+ sendUserMessage(text, options) {
28
+ sentUserMessages.push({ text, options });
29
+ },
30
+ };
31
+
32
+ ponytailExtension(pi);
33
+ return { events, commands, appendedEntries, sentUserMessages };
34
+ }
35
+
36
+ function createCommandContext(overrides = {}) {
37
+ return {
38
+ isIdle: () => true,
39
+ sessionManager: { getEntries: () => [] },
40
+ ui: { notify() {} },
41
+ ...overrides,
42
+ };
43
+ }
44
+
45
+ function withTempConfig(fn) {
46
+ const tempConfigHome = mkdtempSync(join(tmpdir(), "ponytail-test-"));
47
+ const previousXdg = process.env.XDG_CONFIG_HOME;
48
+ const previousHide = process.env.PONYTAIL_HIDE_STATUS;
49
+ process.env.XDG_CONFIG_HOME = tempConfigHome;
50
+ delete process.env.PONYTAIL_HIDE_STATUS;
51
+
52
+ return Promise.resolve()
53
+ .then(fn)
54
+ .finally(() => {
55
+ if (previousXdg === undefined) delete process.env.XDG_CONFIG_HOME;
56
+ else process.env.XDG_CONFIG_HOME = previousXdg;
57
+ if (previousHide === undefined) delete process.env.PONYTAIL_HIDE_STATUS;
58
+ else process.env.PONYTAIL_HIDE_STATUS = previousHide;
59
+ rmSync(tempConfigHome, { recursive: true, force: true });
60
+ });
61
+ }
62
+
63
+ test("extension registers Ponytail commands", () => {
64
+ const { commands } = createPiHarness();
65
+
66
+ assert.deepEqual([...commands.keys()].sort(), [
67
+ "ponytail", "ponytail-audit", "ponytail-debt",
68
+ "ponytail-gain", "ponytail-help", "ponytail-review",
69
+ ]);
70
+ });
71
+
72
+ test("/ponytail updates session mode and injects instructions", async () => withTempConfig(async () => {
73
+ const { commands, events, appendedEntries } = createPiHarness();
74
+ const ctx = createCommandContext();
75
+
76
+ await events.get("session_start")({ reason: "startup" }, ctx);
77
+ await commands.get("ponytail").handler("ultra", ctx);
78
+
79
+ assert.deepEqual(appendedEntries.at(-1), {
80
+ customType: "ponytail-mode",
81
+ data: { mode: "ultra" },
82
+ });
83
+
84
+ const result = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
85
+ assert.ok(result.systemPrompt.includes("PONYTAIL MODE ACTIVE"));
86
+ assert.ok(result.systemPrompt.includes("ultra"));
87
+ }));
88
+
89
+ test("before_agent_start guards missing event and missing systemPrompt (#439, #440)", async () => withTempConfig(async () => {
90
+ const { events } = createPiHarness();
91
+ const ctx = createCommandContext();
92
+
93
+ await events.get("session_start")({ reason: "startup" }, ctx);
94
+
95
+ // #439: a null/undefined event must not crash.
96
+ for (const bad of [undefined, null]) {
97
+ const r = await events.get("before_agent_start")(bad, ctx);
98
+ assert.ok(r.systemPrompt.includes("PONYTAIL MODE ACTIVE"));
99
+ assert.ok(!r.systemPrompt.includes("undefined"), "must not contain the literal 'undefined'");
100
+ }
101
+
102
+ // #440: an event without a systemPrompt must not prepend the literal "undefined".
103
+ const empty = await events.get("before_agent_start")({}, ctx);
104
+ assert.ok(empty.systemPrompt.includes("PONYTAIL MODE ACTIVE"));
105
+ assert.ok(!empty.systemPrompt.startsWith("undefined"), "must not start with 'undefined'");
106
+
107
+ // A real base prompt is still preserved and prepended.
108
+ const withBase = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
109
+ assert.ok(withBase.systemPrompt.startsWith("BASE\n\n"));
110
+ assert.ok(withBase.systemPrompt.includes("PONYTAIL MODE ACTIVE"));
111
+ }));
112
+
113
+ test("session_start restores latest persisted mode", async () => withTempConfig(async () => {
114
+ const { events } = createPiHarness();
115
+ const ctx = createCommandContext({
116
+ sessionManager: {
117
+ getEntries: () => [
118
+ { type: "custom", customType: "ponytail-mode", data: { mode: "lite" } },
119
+ ],
120
+ },
121
+ });
122
+
123
+ await events.get("session_start")({ reason: "resume" }, ctx);
124
+ const result = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
125
+
126
+ assert.ok(result.systemPrompt.includes("lite"));
127
+ }));
128
+
129
+ test("tool_call prepends ponytail block to subagent instructions", async () => withTempConfig(async () => {
130
+ const { events } = createPiHarness();
131
+ const ctx = createCommandContext();
132
+ await events.get("session_start")({ reason: "startup" }, ctx);
133
+
134
+ const input = { agent: "worker", task: "Do it", instructions: "Repo context here." };
135
+ await events.get("tool_call")({ toolName: "subagent", input }, ctx);
136
+
137
+ assert.ok(input.instructions.startsWith("PONYTAIL MODE ACTIVE"));
138
+ assert.ok(input.instructions.includes("deliver in full"));
139
+ assert.ok(input.instructions.endsWith("Repo context here."));
140
+ }));
141
+
142
+ test("tool_call creates instructions when the caller sent none", async () => withTempConfig(async () => {
143
+ const { events } = createPiHarness();
144
+ const ctx = createCommandContext();
145
+ await events.get("session_start")({ reason: "startup" }, ctx);
146
+
147
+ const input = { agent: "scout", task: "Recon" };
148
+ await events.get("tool_call")({ toolName: "subagent", input }, ctx);
149
+
150
+ assert.ok(input.instructions.startsWith("PONYTAIL MODE ACTIVE"));
151
+ }));
152
+
153
+ test("tool_call injection is idempotent only when the marker leads", async () => withTempConfig(async () => {
154
+ const { events } = createPiHarness();
155
+ const ctx = createCommandContext();
156
+ await events.get("session_start")({ reason: "startup" }, ctx);
157
+
158
+ // Marker at offset 0 = prior injection: untouched.
159
+ const injected = { instructions: "PONYTAIL MODE ACTIVE — already set by caller." };
160
+ await events.get("tool_call")({ toolName: "subagent", input: injected }, ctx);
161
+ assert.equal(injected.instructions, "PONYTAIL MODE ACTIVE — already set by caller.");
162
+
163
+ // Incidental mid-text mention: injection still happens.
164
+ const mentioned = { instructions: "Check that PONYTAIL MODE ACTIVE appears in the status bar." };
165
+ await events.get("tool_call")({ toolName: "subagent", input: mentioned }, ctx);
166
+ assert.ok(mentioned.instructions.startsWith("PONYTAIL MODE ACTIVE"));
167
+ assert.ok(mentioned.instructions.endsWith("Check that PONYTAIL MODE ACTIVE appears in the status bar."));
168
+ }));
169
+
170
+ test("tool_call skips injection in review mode", async () => withTempConfig(async () => {
171
+ const { events } = createPiHarness();
172
+ const ctx = createCommandContext({
173
+ sessionManager: {
174
+ getEntries: () => [
175
+ { type: "custom", customType: "ponytail-mode", data: { mode: "review" } },
176
+ ],
177
+ },
178
+ });
179
+ await events.get("session_start")({ reason: "resume" }, ctx);
180
+
181
+ const input = { agent: "worker", task: "Implement x" };
182
+ await events.get("tool_call")({ toolName: "subagent", input }, ctx);
183
+
184
+ assert.equal(input.instructions, undefined, "review mode must not inject the build ladder");
185
+ }));
186
+
187
+ test("tool_call skips injection that would truncate the caller contract past 16KB", async () => withTempConfig(async () => {
188
+ const { events } = createPiHarness();
189
+ const ctx = createCommandContext();
190
+ await events.get("session_start")({ reason: "startup" }, ctx);
191
+
192
+ const huge = { instructions: "x".repeat(16300) };
193
+ await events.get("tool_call")({ toolName: "subagent", input: huge }, ctx);
194
+ assert.equal(huge.instructions, "x".repeat(16300), "near-cap contract must stay untouched");
195
+
196
+ const small = { instructions: "y".repeat(100) };
197
+ await events.get("tool_call")({ toolName: "subagent", input: small }, ctx);
198
+ assert.ok(small.instructions.startsWith("PONYTAIL MODE ACTIVE"));
199
+ assert.ok(small.instructions.endsWith("y".repeat(100)));
200
+ }));
201
+
202
+ test("before_agent_start skips when the marker is already present (extension-loaded child)", async () => withTempConfig(async () => {
203
+ const { events } = createPiHarness();
204
+ const ctx = createCommandContext();
205
+ await events.get("session_start")({ reason: "startup" }, ctx);
206
+
207
+ const result = await events.get("before_agent_start")({
208
+ systemPrompt: "agent prompt\n\n## Task Contract\nPONYTAIL MODE ACTIVE — level: full (inherited from parent).",
209
+ }, ctx);
210
+
211
+ assert.equal(result, undefined, "must not double-inject into children that already carry the block");
212
+ }));
213
+
214
+ test("before_agent_start skips a leading marker but injects past an incidental mention", async () => withTempConfig(async () => {
215
+ const { events } = createPiHarness();
216
+ const ctx = createCommandContext();
217
+ await events.get("session_start")({ reason: "startup" }, ctx);
218
+
219
+ // Leading marker = prior injection: untouched.
220
+ const injected = await events.get("before_agent_start")({
221
+ systemPrompt: "PONYTAIL MODE ACTIVE — level: full (inherited).",
222
+ }, ctx);
223
+ assert.equal(injected, undefined, "leading marker means the block is already in place");
224
+
225
+ // Incidental mid-text mention (e.g. Task Contract quoting the marker): must still inject.
226
+ const mentioned = await events.get("before_agent_start")({
227
+ systemPrompt: "BASE\n\n## Task Contract\nCheck that PONYTAIL MODE ACTIVE appears in the output.",
228
+ }, ctx);
229
+ assert.ok(mentioned, "mid-text mention must not suppress injection");
230
+ assert.ok(mentioned.systemPrompt.startsWith("BASE\n\n"));
231
+ assert.ok(mentioned.systemPrompt.includes("PONYTAIL MODE ACTIVE — level: full"));
232
+ }));
233
+
234
+ test("bare /ponytail handler reports status with a re-activation hint", async () => withTempConfig(async () => {
235
+ const { commands } = createPiHarness();
236
+ const noted = [];
237
+ const ctx = createCommandContext({ ui: { notify: (msg) => noted.push(String(msg)) } });
238
+
239
+ await commands.get("ponytail").handler("", ctx);
240
+
241
+ const status = noted.at(-1);
242
+ assert.match(status, /current \w+/);
243
+ assert.match(status, /default \w+/);
244
+ assert.match(status, /\/ponytail <mode>/);
245
+ }));
246
+
247
+ test("/ponytail review is session-only: sets the live mode, never persists (0.1.15)", async () => withTempConfig(async () => {
248
+ // The command path (not just the parser): review must activate now —
249
+ // instructions injected on the next turn, status shows REVIEW — but must not
250
+ // ride the persisted session-entry channel (a reload can't resurrect it).
251
+ const { commands, events, appendedEntries } = createPiHarness();
252
+ const ctx = createCommandContext();
253
+ await events.get("session_start")({ reason: "startup" }, ctx);
254
+
255
+ await commands.get("ponytail").handler("review", ctx);
256
+ assert.equal(appendedEntries.length, 0, "review must not persist via appendEntry");
257
+
258
+ const injected = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
259
+ assert.ok(injected?.systemPrompt.includes("level: review"), "review instructions active this session");
260
+
261
+ // Control: a runtime mode persists as expected.
262
+ await commands.get("ponytail").handler("ultra", ctx);
263
+ assert.equal(appendedEntries.length, 1);
264
+ assert.equal(appendedEntries[0].data.mode, "ultra");
265
+ }));
266
+
267
+ test("tool_call skips other tools, off mode, and disabled scope", async () => withTempConfig(async () => {
268
+ const previousScope = process.env.PONYTAIL_SUBAGENT_SCOPE;
269
+ try {
270
+ const { events } = createPiHarness();
271
+ const ctx = createCommandContext();
272
+ await events.get("session_start")({ reason: "startup" }, ctx);
273
+
274
+ // Other tools untouched.
275
+ const bashInput = { command: "ls" };
276
+ await events.get("tool_call")({ toolName: "bash", input: bashInput }, ctx);
277
+ assert.equal(bashInput.instructions, undefined);
278
+
279
+ // Scope off.
280
+ process.env.PONYTAIL_SUBAGENT_SCOPE = "off";
281
+ const scopedInput = { task: "Do it" };
282
+ await events.get("tool_call")({ toolName: "subagent", input: scopedInput }, ctx);
283
+ assert.equal(scopedInput.instructions, undefined);
284
+ delete process.env.PONYTAIL_SUBAGENT_SCOPE;
285
+
286
+ // Mode off.
287
+ await events.get("input")({ text: "stop ponytail" }, ctx);
288
+ const offInput = { task: "Do it" };
289
+ await events.get("tool_call")({ toolName: "subagent", input: offInput }, ctx);
290
+ assert.equal(offInput.instructions, undefined);
291
+ } finally {
292
+ if (previousScope === undefined) delete process.env.PONYTAIL_SUBAGENT_SCOPE;
293
+ else process.env.PONYTAIL_SUBAGENT_SCOPE = previousScope;
294
+ }
295
+ }));
296
+
297
+ test("skill alias commands delegate to Pi skill commands", async () => {
298
+ const { commands, sentUserMessages } = createPiHarness();
299
+ const ctx = createCommandContext();
300
+
301
+ await commands.get("ponytail-review").handler("", ctx);
302
+ await commands.get("ponytail-audit").handler("", ctx);
303
+ await commands.get("ponytail-debt").handler("", ctx);
304
+ await commands.get("ponytail-gain").handler("", ctx);
305
+ await commands.get("ponytail-help").handler("", ctx);
306
+
307
+ assert.deepEqual(sentUserMessages.map((entry) => entry.text), [
308
+ "/skill:ponytail-review",
309
+ "/skill:ponytail-audit",
310
+ "/skill:ponytail-debt",
311
+ "/skill:ponytail-gain",
312
+ "/skill:ponytail-help",
313
+ ]);
314
+ // Since pi 0.84.2, sendUserMessage must opt in to skill/command expansion.
315
+ for (const entry of sentUserMessages) {
316
+ assert.deepEqual(entry.options, { expandPromptTemplates: true });
317
+ }
318
+ });
319
+
320
+ test("normal mode disables persistent instructions", async () => withTempConfig(async () => {
321
+ const { commands, events } = createPiHarness();
322
+ const ctx = createCommandContext();
323
+
324
+ await events.get("session_start")({ reason: "startup" }, ctx);
325
+ await commands.get("ponytail").handler("ultra", ctx);
326
+ await events.get("input")({ text: "normal mode", source: "interactive" }, ctx);
327
+
328
+ const disabled = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
329
+ assert.equal(disabled, undefined);
330
+ }));
331
+
332
+ test("a request mentioning normal mode stays active", async () => withTempConfig(async () => {
333
+ const { commands, events } = createPiHarness();
334
+ const ctx = createCommandContext();
335
+
336
+ await events.get("session_start")({ reason: "startup" }, ctx);
337
+ await commands.get("ponytail").handler("ultra", ctx);
338
+ await events.get("input")({ text: "add a normal mode toggle next to dark mode", source: "interactive" }, ctx);
339
+
340
+ const result = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
341
+ assert.match(result.systemPrompt, /PONYTAIL MODE ACTIVE/);
342
+ }));
343
+
344
+ test("status bar renders the mode and flips active on agent_start", async () => withTempConfig(async () => {
345
+ const { events } = createPiHarness();
346
+ const statusWrites = [];
347
+ const ctx = createCommandContext({
348
+ sessionManager: { getEntries: () => [{ type: "custom", customType: "ponytail-mode", data: { mode: "ultra" } }] },
349
+ ui: { notify() {}, setStatus: (key, text) => statusWrites.push({ key, text }), theme: { fg: (_color, text) => text } },
350
+ });
351
+
352
+ await events.get("session_start")({ reason: "resume" }, ctx);
353
+ await events.get("agent_start")({}, ctx);
354
+
355
+ assert.equal(statusWrites.at(-2).key, "ponytail");
356
+ assert.match(statusWrites.at(-2).text, /ULTRA/);
357
+ assert.match(statusWrites.at(-1).text, /ULTRA/);
358
+ }));
359
+
360
+ test("status bar stays silent when ui lacks a theme", async () => withTempConfig(async () => {
361
+ const { events } = createPiHarness();
362
+ const calls = [];
363
+ const ctx = createCommandContext({
364
+ sessionManager: { getEntries: () => [{ type: "custom", customType: "ponytail-mode", data: { mode: "ultra" } }] },
365
+ ui: { notify() {}, setStatus: (_key, text) => calls.push(text) }, // setStatus present, theme absent
366
+ });
367
+
368
+ await events.get("session_start")({ reason: "resume" }, ctx);
369
+ await events.get("agent_start")({}, ctx);
370
+
371
+ assert.deepEqual(calls, []);
372
+ }));
373
+
374
+ test("PONYTAIL_HIDE_STATUS hides the indicator but keeps ponytail active (#324)", async () => withTempConfig(async () => {
375
+ process.env.PONYTAIL_HIDE_STATUS = "1";
376
+ const { events } = createPiHarness();
377
+ const statusWrites = [];
378
+ const ctx = createCommandContext({
379
+ sessionManager: { getEntries: () => [{ type: "custom", customType: "ponytail-mode", data: { mode: "ultra" } }] },
380
+ ui: { notify() {}, setStatus: (key, text) => statusWrites.push({ key, text }), theme: { fg: (_c, t) => t } },
381
+ });
382
+
383
+ await events.get("session_start")({ reason: "resume" }, ctx);
384
+ await events.get("agent_start")({}, ctx);
385
+ const injected = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
386
+
387
+ assert.deepEqual(statusWrites, [], "status bar must not be drawn when hidden");
388
+ assert.match(injected.systemPrompt, /PONYTAIL MODE ACTIVE/, "ruleset must still inject while status is hidden");
389
+ }));
390
+
391
+ test("config.hideStatus hides the indicator but keeps ponytail active (#324)", async () => withTempConfig(async () => {
392
+ mkdirSync(join(process.env.XDG_CONFIG_HOME, "ponytail"), { recursive: true });
393
+ writeFileSync(join(process.env.XDG_CONFIG_HOME, "ponytail", "config.json"), JSON.stringify({ hideStatus: true }));
394
+
395
+ const { events } = createPiHarness();
396
+ const statusWrites = [];
397
+ const ctx = createCommandContext({
398
+ ui: { notify() {}, setStatus: (key, text) => statusWrites.push({ key, text }), theme: { fg: (_c, t) => t } },
399
+ });
400
+
401
+ await events.get("session_start")({ reason: "startup" }, ctx);
402
+ await events.get("agent_start")({}, ctx);
403
+ const injected = await events.get("before_agent_start")({ systemPrompt: "BASE" }, ctx);
404
+
405
+ assert.deepEqual(statusWrites, [], "config.hideStatus must suppress the status bar");
406
+ assert.match(injected.systemPrompt, /PONYTAIL MODE ACTIVE/, "ruleset must still inject while status is hidden");
407
+ }));
408
+
409
+ test("PONYTAIL_HIDE_STATUS=0 does not hide the indicator", async () => withTempConfig(async () => {
410
+ process.env.PONYTAIL_HIDE_STATUS = "0";
411
+ const { events } = createPiHarness();
412
+ const statusWrites = [];
413
+ const ctx = createCommandContext({
414
+ sessionManager: { getEntries: () => [{ type: "custom", customType: "ponytail-mode", data: { mode: "ultra" } }] },
415
+ ui: { notify() {}, setStatus: (key, text) => statusWrites.push({ key, text }), theme: { fg: (_c, t) => t } },
416
+ });
417
+
418
+ await events.get("session_start")({ reason: "resume" }, ctx);
419
+ await events.get("agent_start")({}, ctx);
420
+
421
+ assert.ok(statusWrites.length > 0, "0 must be treated as 'do not hide'");
422
+ }));
@@ -0,0 +1,163 @@
1
+ import assert from "node:assert/strict";
2
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test from "node:test";
6
+
7
+ import {
8
+ filterSkillBodyForMode,
9
+ parsePonytailCommand,
10
+ readDefaultMode,
11
+ readQuietStartup,
12
+ resolveSessionMode,
13
+ writeDefaultMode,
14
+ } from "../index.ts";
15
+
16
+ test("parsePonytailCommand reports status when invoked bare (#99), instead of resetting to default", () => {
17
+ assert.deepEqual(parsePonytailCommand(""), { type: "status" });
18
+ assert.notDeepEqual(parsePonytailCommand(""), { type: "set-mode", mode: "full" });
19
+ });
20
+
21
+ test("parsePonytailCommand parses modes and status", () => {
22
+ assert.deepEqual(parsePonytailCommand("ultra"), { type: "set-mode", mode: "ultra" });
23
+ assert.deepEqual(parsePonytailCommand("review"), { type: "set-mode", mode: "review" });
24
+ assert.deepEqual(parsePonytailCommand("status"), { type: "status" });
25
+ });
26
+
27
+ test("parsePonytailCommand rejects the removed default subcommand", () => {
28
+ assert.deepEqual(parsePonytailCommand("default lite"), { type: "invalid", reason: "invalid-mode", mode: "default" });
29
+ });
30
+
31
+ test("resolveSessionMode still honors review as a session mode (not a default)", () => {
32
+ const entries = [{ type: "custom", customType: "ponytail-mode", data: { mode: "review" } }];
33
+ assert.equal(resolveSessionMode(entries, "full"), "review");
34
+ });
35
+
36
+ test("resolveSessionMode prefers latest persisted session mode", () => {
37
+ const entries = [
38
+ { type: "custom", customType: "ponytail-mode", data: { mode: "lite" } },
39
+ { type: "custom", customType: "ponytail-mode", data: { mode: "ultra" } },
40
+ ];
41
+
42
+ assert.equal(resolveSessionMode(entries, "full"), "ultra");
43
+ });
44
+
45
+ test("resolveSessionMode returns fallback when entries is not an array", () => {
46
+ assert.equal(resolveSessionMode(null, "ultra"), "ultra");
47
+ assert.equal(resolveSessionMode(undefined, "lite"), "lite");
48
+ assert.equal(resolveSessionMode({}, "full"), "full");
49
+ assert.equal(resolveSessionMode("not an array"), "full"); // DEFAULT_MODE fallback
50
+ });
51
+
52
+ test("readDefaultMode and writeDefaultMode use XDG config path", () => {
53
+ const tempDir = mkdtempSync(join(tmpdir(), "ponytail-config-"));
54
+ const previousXdg = process.env.XDG_CONFIG_HOME;
55
+ const previousDefault = process.env.PONYTAIL_DEFAULT_MODE;
56
+ const configPath = join(tempDir, "ponytail", "config.json");
57
+ process.env.XDG_CONFIG_HOME = tempDir;
58
+ delete process.env.PONYTAIL_DEFAULT_MODE;
59
+
60
+ try {
61
+ assert.equal(readDefaultMode(), "full");
62
+ assert.equal(writeDefaultMode("ultra"), "ultra");
63
+ assert.equal(readDefaultMode(), "ultra");
64
+ assert.ok(existsSync(configPath));
65
+ assert.deepEqual(JSON.parse(readFileSync(configPath, "utf8")), { defaultMode: "ultra" });
66
+ } finally {
67
+ if (previousXdg === undefined) delete process.env.XDG_CONFIG_HOME;
68
+ else process.env.XDG_CONFIG_HOME = previousXdg;
69
+ if (previousDefault === undefined) delete process.env.PONYTAIL_DEFAULT_MODE;
70
+ else process.env.PONYTAIL_DEFAULT_MODE = previousDefault;
71
+ rmSync(tempDir, { recursive: true, force: true });
72
+ }
73
+ });
74
+
75
+ test("readQuietStartup resolves env var, config file, and default in that order", () => {
76
+ const tempDir = mkdtempSync(join(tmpdir(), "ponytail-quiet-"));
77
+ const previousXdg = process.env.XDG_CONFIG_HOME;
78
+ const previousEnv = process.env.PONYTAIL_QUIET_STARTUP;
79
+ const configDir = join(tempDir, "ponytail");
80
+ const configPath = join(configDir, "config.json");
81
+ process.env.XDG_CONFIG_HOME = tempDir;
82
+ delete process.env.PONYTAIL_QUIET_STARTUP;
83
+
84
+ try {
85
+ // No env, no config -> default false (toast still shows)
86
+ assert.equal(readQuietStartup(), false);
87
+
88
+ // Config file true -> respected
89
+ mkdirSync(configDir, { recursive: true });
90
+ writeFileSync(configPath, JSON.stringify({ quietStartup: true }), "utf8");
91
+ assert.equal(readQuietStartup(), true);
92
+
93
+ // Env var overrides config
94
+ process.env.PONYTAIL_QUIET_STARTUP = "false";
95
+ assert.equal(readQuietStartup(), false);
96
+ process.env.PONYTAIL_QUIET_STARTUP = "1";
97
+ assert.equal(readQuietStartup(), true);
98
+ } finally {
99
+ if (previousXdg === undefined) delete process.env.XDG_CONFIG_HOME;
100
+ else process.env.XDG_CONFIG_HOME = previousXdg;
101
+ if (previousEnv === undefined) delete process.env.PONYTAIL_QUIET_STARTUP;
102
+ else process.env.PONYTAIL_QUIET_STARTUP = previousEnv;
103
+ rmSync(tempDir, { recursive: true, force: true });
104
+ }
105
+ });
106
+
107
+ test("filterSkillBodyForMode keeps only requested intensity examples and rows", () => {
108
+ // Examples are quoted in the real SKILL.md (`- lite: "..."`) — match that
109
+ // shape here too; see the next test for why the quote is load-bearing.
110
+ const body = `---
111
+ name: ponytail
112
+ ---
113
+ | **lite** | keep lite |
114
+ | **full** | keep full |
115
+ | **ultra** | keep ultra |
116
+ - lite: "Lite example"
117
+ - full: "Full example"
118
+ - ultra: "Ultra example"
119
+ Other line`;
120
+
121
+ const filtered = filterSkillBodyForMode(body, "ultra");
122
+
123
+ assert.ok(!filtered.includes("keep lite"));
124
+ assert.ok(!filtered.includes("keep full"));
125
+ assert.ok(filtered.includes("keep ultra"));
126
+ assert.ok(!filtered.includes("Lite example"));
127
+ assert.ok(filtered.includes("Ultra example"));
128
+ assert.ok(filtered.includes("Other line"));
129
+ });
130
+
131
+ test("filterSkillBodyForMode does not drop a rule bullet whose label matches a mode name", () => {
132
+ // A rule bullet like "- Full:..." has the same "label: text" shape as a
133
+ // worked example, but isn't one — it must survive in every mode. Only the
134
+ // quoted `- lite: "..."`-style bullets are real per-mode examples.
135
+ const body = `- Full: do not confuse this rule label with the mode name.
136
+ - Lite: same risk, this is a real rule bullet.
137
+ - lite: "real worked example"
138
+ - ultra: "real worked example"`;
139
+
140
+ const filtered = filterSkillBodyForMode(body, "ultra");
141
+
142
+ assert.ok(filtered.includes("Full: do not confuse"), "an unquoted rule bullet must not be treated as a mode example");
143
+ assert.ok(filtered.includes("Lite: same risk"), "an unquoted rule bullet must not be treated as a mode example");
144
+ assert.ok(!filtered.includes("- lite:"), "the real quoted lite example must still be filtered out in ultra mode");
145
+ assert.ok(filtered.includes('ultra: "real worked example"'));
146
+ });
147
+
148
+ test("filterSkillBodyForMode keeps rule bullets that contain a colon", () => {
149
+ // Regression: rule bullets outside the Intensity section (e.g. the
150
+ // "No unrequested abstractions:" rule or the `ponytail:` comment convention)
151
+ // contain a colon and must not be mistaken for mode-example lines.
152
+ const skillPath = new URL("../../../../skills/ponytail/SKILL.md", import.meta.url);
153
+ const body = readFileSync(skillPath, "utf8");
154
+
155
+ const filtered = filterSkillBodyForMode(body, "full");
156
+
157
+ assert.ok(filtered.includes("No unrequested abstractions"));
158
+ assert.ok(filtered.includes("Mark deliberate simplifications"));
159
+ // The Intensity examples are still filtered down to the active mode.
160
+ assert.ok(filtered.includes('full: "`@lru_cache'));
161
+ assert.ok(!filtered.includes('lite: "Done'));
162
+ assert.ok(!filtered.includes('ultra: "No cache'));
163
+ });
@@ -0,0 +1,33 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+
4
+ import { getSubagentInstructions, shouldInjectSubagentInstructions } from "../lib/subagent.ts";
5
+
6
+ test("getSubagentInstructions includes the ladder, mode name, and full-output carve-out", () => {
7
+ const block = getSubagentInstructions("ultra");
8
+ assert.match(block, /level: ultra \(inherited from parent\)/);
9
+ assert.match(block, /The ladder \(stop at the first rung that holds\)/);
10
+ assert.match(block, /Already in this codebase\? Reuse it/);
11
+ assert.match(block, /`ponytail:` comment/);
12
+ assert.match(block, /ONE runnable check/);
13
+ assert.match(block, /deliver in full/);
14
+ // Output-format rules must NOT squash planner/reviewer reports.
15
+ assert.doesNotMatch(block, /Code first/);
16
+ });
17
+
18
+ test("shouldInjectSubagentInstructions defaults on and honors PONYTAIL_SUBAGENT_SCOPE=off", () => {
19
+ const prev = process.env.PONYTAIL_SUBAGENT_SCOPE;
20
+ try {
21
+ delete process.env.PONYTAIL_SUBAGENT_SCOPE;
22
+ assert.equal(shouldInjectSubagentInstructions(), true);
23
+ process.env.PONYTAIL_SUBAGENT_SCOPE = "off";
24
+ assert.equal(shouldInjectSubagentInstructions(), false);
25
+ process.env.PONYTAIL_SUBAGENT_SCOPE = "OFF ";
26
+ assert.equal(shouldInjectSubagentInstructions(), false);
27
+ process.env.PONYTAIL_SUBAGENT_SCOPE = "all";
28
+ assert.equal(shouldInjectSubagentInstructions(), true);
29
+ } finally {
30
+ if (prev === undefined) delete process.env.PONYTAIL_SUBAGENT_SCOPE;
31
+ else process.env.PONYTAIL_SUBAGENT_SCOPE = prev;
32
+ }
33
+ });