ceulen 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +56 -1
  3. package/extensions/lib/plan-bridge.ts +18 -0
  4. package/extensions/lib/registry.ts +14 -0
  5. package/extensions/modules/a2a/index.ts +4 -2
  6. package/extensions/modules/attachments/configPanel.ts +91 -0
  7. package/extensions/modules/attachments/index.ts +274 -0
  8. package/extensions/modules/attachments/lib/clipboard-files.ts +80 -0
  9. package/extensions/modules/attachments/lib/pastes.ts +45 -0
  10. package/extensions/modules/attachments/lib/paths.ts +74 -0
  11. package/extensions/modules/attachments/lib/registry.ts +70 -0
  12. package/extensions/modules/attachments/lib/settings.ts +99 -0
  13. package/extensions/modules/attachments/lib/tray.ts +74 -0
  14. package/extensions/modules/attachments/test/configPanel.test.ts +122 -0
  15. package/extensions/modules/attachments/test/index.test.ts +870 -0
  16. package/extensions/modules/attachments/test/module.test.ts +53 -0
  17. package/extensions/modules/composer/test/module.test.ts +2 -2
  18. package/extensions/modules/config/index.ts +3 -0
  19. package/extensions/modules/config/test/renderTools.test.ts +1 -1
  20. package/extensions/modules/cron/configPanel.ts +103 -0
  21. package/extensions/modules/cron/index.ts +638 -0
  22. package/extensions/modules/cron/lib/jobs.ts +201 -0
  23. package/extensions/modules/cron/lib/schedule.ts +161 -0
  24. package/extensions/modules/cron/test/cwd-repro.test.ts +98 -0
  25. package/extensions/modules/cron/test/index.test.ts +859 -0
  26. package/extensions/modules/cron/test/schedule.test.ts +93 -0
  27. package/extensions/modules/munin/index.ts +3 -1
  28. package/extensions/modules/permission/index.ts +567 -0
  29. package/extensions/modules/permission/test/permission.test.ts +789 -0
  30. package/extensions/modules/plan/index.ts +5 -0
  31. package/extensions/modules/repair/index.ts +134 -3
  32. package/extensions/modules/repair/test/freshness.test.ts +169 -0
  33. package/extensions/modules/subagent/index.ts +38 -5
  34. package/extensions/modules/subagent/lib/runner.ts +348 -12
  35. package/extensions/modules/subagent/test/worktree.test.ts +230 -0
  36. package/extensions/modules/usage/index.ts +193 -71
  37. package/extensions/modules/usage/test/context.test.ts +160 -120
  38. package/extensions/modules/web/index.ts +3 -1
  39. package/extensions/modules/web/test/a11y.test.ts +1 -1
  40. package/package.json +2 -2
  41. package/skills/cron/SKILL.md +58 -0
@@ -0,0 +1,53 @@
1
+ // attachments module wiring: the ceulen- widget key, the node:test conversion
2
+ // invariants, and the registry entry shape.
3
+ import assert from "node:assert/strict";
4
+ import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from "node:fs";
5
+ import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
+ import { after, before, describe, it } from "node:test";
8
+ import { readFileSync } from "node:fs";
9
+ import { MODULES } from "../../../lib/registry.js";
10
+ import attachmentsModule from "../index.js";
11
+
12
+ let TMP: string;
13
+
14
+ before(() => {
15
+ TMP = mkdtempSync(join(tmpdir(), "ceulen-att-mod-"));
16
+ mkdirSync(join(TMP, "agent"), { recursive: true });
17
+ process.env.PI_CODING_AGENT_DIR = join(TMP, "agent");
18
+ });
19
+
20
+ after(() => {
21
+ rmSync(TMP, { recursive: true, force: true });
22
+ if (process.env.PI_CODING_AGENT_DIR === join(TMP, "agent")) delete process.env.PI_CODING_AGENT_DIR;
23
+ });
24
+
25
+ describe("attachments module wiring", () => {
26
+ it("registers in the MODULES registry on the Files tab with its config factory", () => {
27
+ const entry = MODULES.find((m) => m.name === "attachments");
28
+ assert.ok(entry, "registry entry exists");
29
+ assert.equal(entry.category, "Files");
30
+ assert.equal(entry.load, attachmentsModule);
31
+ assert.ok(entry.config, "config factory wired");
32
+ assert.ok(!("tools" in entry) || entry.tools === undefined, "no tools to per-toggle");
33
+ assert.ok(!entry.core, "kill-switchable");
34
+ });
35
+
36
+ it("widget key is ceulen-prefixed (source scan — no pi- attachments key)", () => {
37
+ const src = readFileSync(new URL("../index.ts", import.meta.url), "utf8");
38
+ assert.ok(src.includes('"ceulen-attachments"'), "ceulen-attachments widget key present");
39
+ assert.ok(!src.includes('"pi-attachments"'), "upstream widget key gone");
40
+ assert.ok(!src.includes("pi-attachments-test"), "no upstream temp-dir prefix");
41
+ });
42
+
43
+ it("factory registers the shortcut + input/session handlers via guarded pi surface", () => {
44
+ const registered: string[] = [];
45
+ const shortcuts: string[] = [];
46
+ attachmentsModule({
47
+ on: (event: string) => registered.push(event),
48
+ registerShortcut: (key: string) => shortcuts.push(key),
49
+ } as any);
50
+ assert.deepEqual(registered.sort(), ["input", "session_start"]);
51
+ assert.equal(shortcuts.length, 1);
52
+ });
53
+ });
@@ -306,8 +306,8 @@ describe("core module contract", () => {
306
306
  it("nextDisabled excludes core modules; withEnableRow adds no row for them", async () => {
307
307
  const { nextDisabled, withEnableRow } = await import("../../config/index.js");
308
308
  // working = enabled set; nextDisabled lists the NOT-enabled non-core modules.
309
- assert.deepEqual(nextDisabled(new Set(["munin"])), ["zai", "ponytail", "subagent", "plan", "a2a", "todo", "repair", "serena", "fff", "web", "rules", "gh", "steering", "rtk"]);
310
- assert.deepEqual(nextDisabled(new Set(["router", "classifier", "ux", "munin", "usage", "ponytail", "subagent", "plan", "a2a", "todo", "repair", "serena", "fff", "web", "gh", "rules", "steering", "zai", "rtk", "config"])), [], "all-on → nothing disabled");
309
+ assert.deepEqual(nextDisabled(new Set(["munin"])), ["zai", "ponytail", "subagent", "plan", "a2a", "todo", "cron", "repair", "serena", "fff", "web", "rules", "attachments", "gh", "steering", "rtk", "permission"]);
310
+ assert.deepEqual(nextDisabled(new Set(["router", "classifier", "ux", "munin", "usage", "ponytail", "subagent", "plan", "a2a", "todo", "cron", "repair", "serena", "fff", "web", "gh", "rules", "steering", "zai", "rtk", "config", "attachments", "permission"])), [], "all-on → nothing disabled");
311
311
  for (const core of ["composer", "advisor", "router", "classifier", "usage", "ux", "config"]) {
312
312
  assert.ok(!nextDisabled(new Set()).includes(core), `core (${core}) is never disableable`);
313
313
  }
@@ -254,6 +254,9 @@ export default function configModule(pi: ExtensionAPI, deps?: ModuleLoadDeps): v
254
254
  ponytail: { section: "Ponytail", icon: "🦥" },
255
255
  plan: { section: "Plan mode", icon: "🗺️" },
256
256
  todo: { section: "Todo", icon: "☑" },
257
+ cron: { section: "Cron", icon: "⏰" },
258
+ attachments: { section: "Attachments", icon: "📎" },
259
+ permission: { section: "Permissions", icon: "🛡" },
257
260
  serena: { section: "Serena" },
258
261
  repair: { section: "Repair", icon: "🔧" },
259
262
  fff: { section: "FFF search" },
@@ -34,7 +34,7 @@ function toolGroups(): PanelGroup[] {
34
34
  describe("render smoke — ported modules' /config sections", () => {
35
35
  it("renders Enable + per-tool rows inside the boxed frame with zero overflow", () => {
36
36
  const groups = toolGroups();
37
- assert.equal(groups.length, 15, "serena + fff + ux + munin + classifier + advisor + subagent + repair + plan + todo + web + rules + a2a + gh + steering·think (rtk has no tools)");
37
+ assert.equal(groups.length, 16, "serena + fff + ux + munin + classifier + advisor + subagent + repair + plan + todo + web + rules + a2a + gh + cron + steering·think (rtk has no tools)");
38
38
  const m = new ConfigPanelModel(groups, theme, "Settings");
39
39
  m.getHeight = () => 40;
40
40
  for (const w of [110, 100, 80, 60]) {
@@ -0,0 +1,103 @@
1
+ /**
2
+ * cron's /config contribution — Tasks tab, Cron section.
3
+ *
4
+ * Rows write the GLOBAL agent-dir settings.json `cron` section (a
5
+ * writeCronSection sibling of readCronSettings). The module re-reads settings
6
+ * at load (global-only) and on every session_start (project overlay), so a
7
+ * save applies to the next session without /reload; the tick interval also
8
+ * re-arms on session_start.
9
+ */
10
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
11
+ import { homedir } from "node:os";
12
+ import { join } from "node:path";
13
+ import { row, type PanelGroup } from "../../lib/panel.js";
14
+ import type { ModuleConfig } from "../../lib/registry.js";
15
+ import { readCronSettings, type CronSettings } from "./index.ts";
16
+
17
+ /** Effective settings for the panel — the same chain the scheduler uses. */
18
+ export function loadCronSettings(): CronSettings {
19
+ return readCronSettings();
20
+ }
21
+
22
+ /** Write ONE patch into the GLOBAL agent-dir `cron` section (never the merged
23
+ * snapshot — a project-overlay value must not be promoted to global). */
24
+ export function writeCronSection(patch: Partial<CronSettings>): string {
25
+ const file = join(process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent"), "settings.json");
26
+ let settings: Record<string, unknown>;
27
+ try {
28
+ settings = existsSync(file) ? (JSON.parse(readFileSync(file, "utf8")) as Record<string, unknown>) : {};
29
+ } catch {
30
+ throw new Error(`${file} is not valid JSON — fix or remove it before saving.`);
31
+ }
32
+ const s = (settings.cron ?? {}) as Record<string, unknown>;
33
+ Object.assign(s, patch);
34
+ settings.cron = s;
35
+ mkdirSync(join(file, ".."), { recursive: true });
36
+ const tmp = file + ".tmp";
37
+ writeFileSync(tmp, JSON.stringify(settings, null, 2) + "\n", { mode: 0o600 });
38
+ renameSync(tmp, file);
39
+ return file;
40
+ }
41
+
42
+ /** Build the cron panel groups over a working copy (mutated by row setters).
43
+ * Exported for tests. */
44
+ export function buildCronGroups(cfg: CronSettings): PanelGroup[] {
45
+ return [
46
+ {
47
+ key: "cron",
48
+ label: "Cron",
49
+ tab: "Tasks",
50
+ icon: "⏰",
51
+ rows: [
52
+ row("cron.enabled", "Scheduler enabled", "toggle", cfg.enabled, (v) => {
53
+ cfg.enabled = Boolean(v);
54
+ }, {
55
+ description: "Global kill switch for the in-process scheduler (30s ticks fire due jobs into the live session).",
56
+ defaultValue: true,
57
+ }),
58
+ row("cron.tickMs", "Tick interval (ms)", "number", cfg.tickMs, (v) => {
59
+ const n = Number(v);
60
+ if (Number.isFinite(n) && n > 0) cfg.tickMs = n;
61
+ }, {
62
+ description: "How often due jobs are checked. Clamped 5s–10min on read (default 30s). Re-arms on next session.",
63
+ defaultValue: 30_000,
64
+ }),
65
+ row("cron.timeoutMs", "Headless child cap (ms)", "number", cfg.timeoutMs, (v) => {
66
+ const n = Number(v);
67
+ if (Number.isFinite(n) && n > 0) cfg.timeoutMs = n;
68
+ }, {
69
+ description: "Hard cap for pinned (headless) job runs: SIGTERM at the cap, SIGKILL after 5s grace. Clamped 1min–24h (default 10min).",
70
+ defaultValue: 600_000,
71
+ }),
72
+ ],
73
+ },
74
+ ];
75
+ }
76
+
77
+ const OWNED_PREFIX = "cron.";
78
+
79
+ /** cron's ModuleConfig for the central /config panel. */
80
+ export function cronConfig(): ModuleConfig {
81
+ const before = loadCronSettings();
82
+ const working: CronSettings = { ...before };
83
+
84
+ return {
85
+ groups: () => buildCronGroups(working),
86
+ save: async (edited, ctx) => {
87
+ const FIELDS: (keyof CronSettings)[] = ["enabled", "tickMs", "timeoutMs"];
88
+ const patch: Partial<CronSettings> = {};
89
+ for (const key of edited) {
90
+ if (!key.startsWith(OWNED_PREFIX)) continue;
91
+ const field = key.slice(OWNED_PREFIX.length) as keyof CronSettings;
92
+ if (FIELDS.includes(field)) (patch as Record<string, unknown>)[field] = working[field];
93
+ }
94
+ if (!Object.keys(patch).length) return;
95
+ try {
96
+ const file = writeCronSection(patch);
97
+ ctx.ui.notify(`Cron settings saved to ${file} — applies next session (project .pi/settings.json may shadow per field).`, "info");
98
+ } catch (e) {
99
+ ctx.ui.notify(`Cron save failed: ${e instanceof Error ? e.message : e}`, "error");
100
+ }
101
+ },
102
+ };
103
+ }