ceulen 0.10.0 → 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 (57) hide show
  1. package/CHANGELOG.md +98 -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/lib/skill-path.test.ts +35 -0
  6. package/extensions/lib/skill-path.ts +22 -0
  7. package/extensions/modules/a2a/index.ts +5 -3
  8. package/extensions/modules/a2a/lib/config.ts +1 -1
  9. package/extensions/modules/a2a/lib/registry.ts +1 -1
  10. package/extensions/modules/attachments/configPanel.ts +91 -0
  11. package/extensions/modules/attachments/index.ts +274 -0
  12. package/extensions/modules/attachments/lib/clipboard-files.ts +80 -0
  13. package/extensions/modules/attachments/lib/pastes.ts +45 -0
  14. package/extensions/modules/attachments/lib/paths.ts +74 -0
  15. package/extensions/modules/attachments/lib/registry.ts +70 -0
  16. package/extensions/modules/attachments/lib/settings.ts +99 -0
  17. package/extensions/modules/attachments/lib/tray.ts +74 -0
  18. package/extensions/modules/attachments/test/configPanel.test.ts +122 -0
  19. package/extensions/modules/attachments/test/index.test.ts +870 -0
  20. package/extensions/modules/attachments/test/module.test.ts +53 -0
  21. package/extensions/modules/composer/index.ts +19 -1
  22. package/extensions/modules/composer/lib/footer.ts +7 -7
  23. package/extensions/modules/composer/lib/shapes.ts +237 -112
  24. package/extensions/modules/composer/test/editor.test.ts +3 -3
  25. package/extensions/modules/composer/test/footer.test.ts +1 -1
  26. package/extensions/modules/composer/test/module.test.ts +8 -7
  27. package/extensions/modules/composer/test/screen.test.ts +10 -9
  28. package/extensions/modules/composer/test/shapes.test.ts +83 -61
  29. package/extensions/modules/config/index.ts +3 -0
  30. package/extensions/modules/config/test/renderTools.test.ts +1 -1
  31. package/extensions/modules/cron/configPanel.ts +103 -0
  32. package/extensions/modules/cron/index.ts +638 -0
  33. package/extensions/modules/cron/lib/jobs.ts +201 -0
  34. package/extensions/modules/cron/lib/schedule.ts +161 -0
  35. package/extensions/modules/cron/test/cwd-repro.test.ts +98 -0
  36. package/extensions/modules/cron/test/index.test.ts +859 -0
  37. package/extensions/modules/cron/test/schedule.test.ts +93 -0
  38. package/extensions/modules/munin/index.ts +4 -2
  39. package/extensions/modules/permission/index.ts +567 -0
  40. package/extensions/modules/permission/test/permission.test.ts +789 -0
  41. package/extensions/modules/plan/index.ts +5 -0
  42. package/extensions/modules/ponytail/index.ts +2 -2
  43. package/extensions/modules/repair/index.ts +134 -3
  44. package/extensions/modules/repair/lib/settings.ts +1 -1
  45. package/extensions/modules/repair/test/freshness.test.ts +169 -0
  46. package/extensions/modules/router/lib/provider.ts +13 -9
  47. package/extensions/modules/subagent/index.ts +38 -5
  48. package/extensions/modules/subagent/lib/runner.ts +352 -14
  49. package/extensions/modules/subagent/test/worktree.test.ts +230 -0
  50. package/extensions/modules/usage/index.ts +193 -71
  51. package/extensions/modules/usage/test/context.test.ts +160 -120
  52. package/extensions/modules/ux/index.ts +2 -2
  53. package/extensions/modules/web/index.ts +4 -2
  54. package/extensions/modules/web/lib/chrome.ts +1 -1
  55. package/extensions/modules/web/test/a11y.test.ts +1 -1
  56. package/package.json +2 -2
  57. package/skills/cron/SKILL.md +58 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,103 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.11.0 — 2026-10-07
6
+
7
+ - **Worktree sandbox hardening + multi-session repo safety** (subagent module;
8
+ OMP/Claude-Code mechanisms ported at ponytail scale — no new deps, no new
9
+ settings):
10
+ - **Per-repo lock** (`withRepoLock`, keyed by resolved repo root):
11
+ serializes the parent-mutating git calls — `worktree add`, `worktree
12
+ remove`, and the `git apply --3way` merge — which previously raced on
13
+ git's no-waiter O_EXCL locks when parallel children finished together.
14
+ - **Owner marker + GC sweep**: each sandbox records a sibling
15
+ `<id>.owner.json` (`{pid, id, createdAt}`, 0600) OUTSIDE the sandbox dir
16
+ so it can never leak into the captured diff (an in-sandbox marker made
17
+ two parallel merges add/add-conflict — caught by the live race test);
18
+ `sweepStaleWorktrees` runs fire-and-forget on `session_start` and removes
19
+ dead-owner sandboxes (registration-aware: `worktree remove` for
20
+ registered entries, `rm -rf` for CoW copies). `/subagent worktrees
21
+ [clean]` lists or forces the sweep.
22
+ - **`<repoRoot>/.pi-worktrees/.gitignore`** (content `*`) auto-created so
23
+ sandboxes never pollute the parent's `git status` or the untracked
24
+ baseline capture — no user-file edits.
25
+ - **CoW backend (darwin)**: `createWorktree` prefers a per-top-level-entry
26
+ `cp -cR` clone staged OUTSIDE the copied tree (sibling temp dir, skip
27
+ `.pi-worktrees`), then atomic-renames into place — BSD cp lacks GNU's
28
+ self-copy guard, and whole-tree copies would compound prior sandboxes.
29
+ The copy IS the working tree (uncommitted state, node_modules, .env come
30
+ free; the copied `.git` is fully independent). Any failure/EXDEV falls
31
+ back to the detached `git worktree add`. Linux is deliberately
32
+ worktree-only (`--reflink=auto` silently full-copies big trees).
33
+ - **Baseline carry** (git-worktree fallback): `captureParentBaseline`
34
+ composes the parent's WIP as PURE READS — `git diff --cached --binary` +
35
+ `git diff --binary` + per-untracked-file `git diff --no-index --binary
36
+ /dev/null <f>` — never `git add`/`stash create` on the parent (both
37
+ mutate it). 256 MiB cap (constant; OMP #8939 lesson). The child's delta
38
+ then 3-way-merges cleanly onto a parent holding the same baseline.
39
+ - **`.worktreeinclude`**: repo-root gitignore-style lines; matching
40
+ gitignored files (zero-dep glob matcher, 500-file cap) copied into
41
+ git-worktree sandboxes. Fail-open per file.
42
+ - **repair module — multi-session guards** (always-on, deterministic):
43
+ - **Conflict-marker footer**: full-file reads append a footer naming
44
+ detected `<<<<<<<`/`=======`/`>>>>>>>` blocks (OMP conflict-detect
45
+ workflow; zero extra I/O; `:conflicts` stays the explicit listing path).
46
+ - **Write freshness guard**: reads record each file's mtime (capped map);
47
+ a `write` to a file changed since this session last read it fails BEFORE
48
+ writing with a re-read-first error — no more blind clobbering of a
49
+ foreign session's edit. `apply_patch`/`str_replace_editor` refresh the
50
+ baseline via a `refreshMtime` seam; `edit` needs no guard (its
51
+ exact-match anchor already fails loudly).
52
+ - **README**: documents every module in the bundle (subagent, repair,
53
+ steering, zai, a2a, todo, rules, gh, attachments, cron, permission were
54
+ missing) — the subagent section leads with the multi-session safety work.
55
+ - Live-verified end to end on this machine: baseline carry through a real
56
+ `sandbox:"worktree"` child, GC sweep in a fresh headless `pi -p` session,
57
+ herdr-pane load, both repair guards through real wrapped tools, and a
58
+ concurrent two-child `merge:"3way"` race (both patches landed, no
59
+ conflicts, no lock leftovers). 23 new tests; suite at 2639 green.
60
+
61
+ ## 0.10.1 — 2026-10-07
62
+
63
+ - **Windows fix**: extension load crashed with `ENOENT ... lstat 'D:\C:'` —
64
+ the resources_discover skill path was built with `new URL(...).pathname`,
65
+ which on Windows yields `/C:/...` (leading slash before the drive letter);
66
+ realpathSync resolved it against the current drive. The bug existed in FIVE
67
+ modules (web, munin, a2a, ponytail, ux). One shared helper
68
+ `extensions/lib/skill-path.ts` (`fileURLToPath`) now serves all call sites,
69
+ with a regression test.
70
+
71
+ - **Security & robustness review** (12 files): three settings writers (a2a
72
+ `writeSettingsA2A`, repair settings, a2a session registry) now write
73
+ `mode: 0o600` like every sibling writer — the files carry API keys/tokens;
74
+ router `refreshModels` no longer throws on null entries in a hand-edited
75
+ models-store.json; web `--virtual-time-budget` clamped non-negative;
76
+ subagent worktree patch temp file gets a randomUUID name + exclusive
77
+ (`wx`) write (shared-/tmp symlink hardening; cleanup already existed).
78
+
79
+ - **composer**: status layer aligned with OMP's actual rendering (source-level
80
+ study of `packages/tui/src/components/composer/*` + `status-line/component.ts`):
81
+ band/box embed OMP's POWERLINE row — bg-filled left group
82
+ `π > ⬢ model · level > 📁 dir > ⑂ git` (thin `>` separators, model icon,
83
+ dot-joined thinking level) over the context-reactive GAUGE (accent used-
84
+ portion, rounded `N%` label riding the used cells, `┃` at pi's compaction
85
+ threshold (window − 16384) when armed, window figure right-justified), with
86
+ the session-title chip on box (`─ omp ─╮`); the band starts FLUSH (OMP's
87
+ `sep.powerlineCapLeft` is empty outside the nerd set — no `╭─` cap). claude
88
+ and rule dock the title chip on the top rule and render the left group +
89
+ `◫ N%/window ⟲` context segment on a standalone BOTTOM status bar (after
90
+ the closing rule for claude, after a spacer row for rule) — pi/borderless/
91
+ field/rail render the full bar with the title right-justified. Context
92
+ segment steps at OMP's thresholds (>50 warning, >90 error) and carries the
93
+ `⟲` auto-compact icon; git indicators get OMP's per-indicator colors
94
+ (`*n` warn, `+n` success, `?n` dim; branch warns only when dirty); token
95
+ figures use OMP's formatNumber (`200K`, `1.0M`, trailing `.0` trimmed);
96
+ thinking level rides the model segment as `⬢ model · level` (was
97
+ `(provider) model (level)`). Session title sourced from
98
+ `sessionManager.getSessionName()`; line 1 (rate · token stats · quota
99
+ windows) unchanged.
100
+
3
101
  ## 0.10.0 — 2026-10-05
4
102
 
5
103
  - **gh module**: new module — ONE read-only `github` tool over the `gh` CLI
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **The Pi coding agent, fully dressed.**
4
4
 
5
- One extension bundle that turns [Pi](https://github.com/earendil-works/pi) into a fully equipped coding agent: a router provider, a second-model reviewer, long-term memory, usage display, themes, and a central settings panel — one install, one command surface, most modules individually switchable.
5
+ One extension bundle that turns [Pi](https://github.com/earendil-works/pi) into a fully equipped coding agent: a router provider, a second-model reviewer, long-term memory, subagent delegation with multi-session repo safety, usage display, themes, and a central settings panel — one install, one command surface, most modules individually switchable.
6
6
 
7
7
  Named for Ludolph van Ceulen, who computed π to 35 digits — they're carved on his tombstone.
8
8
 
@@ -75,6 +75,33 @@ Pick the input editor's look from `/config` → Appearance → Composer Shape: S
75
75
 
76
76
  `/ponytail off|lite|full|ultra` switches an over-engineering discipline: simplest solution that works, stdlib first, no speculative abstraction. Also ships `/ponytail-review`, `/ponytail-audit`, `/ponytail-debt`, `/ponytail-gain` skills. Deactivate with `stop ponytail`.
77
77
 
78
+ ### subagent — delegate work, safely
79
+
80
+ One `subagent` tool fans work out to specialized agents — `scout` (recon), `tester`, `worker`, `planner`, `reviewer` — in three modes: single, parallel (up to 8 tasks), or chained pipelines. Background tasks report liveness (`operation:"status"/"wait"/"cancel"`); when Pi runs inside herdr, tasks can delegate to visible interactive panes instead. Model tier and thinking effort are routed per task by the classifier module; `/subagent` manages roles, `/agent` inspects threads.
81
+
82
+ Multi-session repo safety (isolated children never clobber you or each other):
83
+
84
+ - **Worktree sandbox** — `sandbox:"worktree"` runs the child in a copy-on-write clone of your working tree (macOS `clonefile` — near-zero time and disk; carries your uncommitted changes, `node_modules`, and `.env` for free), falling back to a detached git worktree elsewhere. The child's changes come back as a patch; `merge:"3way"` applies it to your checkout with conflicts **reported, never silently resolved**.
85
+ - **Baseline carry** — on the worktree fallback the parent's uncommitted state is composed as pure reads (`git diff`/`--no-index`) and seeded into the sandbox, so children never work a stale tree and patches merge cleanly.
86
+ - **`.worktreeinclude`** — gitignore-style file listing copied into fresh worktrees (env files, configs).
87
+ - **Repo lock + GC** — parent-mutating git operations serialize per repo (no `index.lock` races between parallel children); crashed runs' sandboxes are swept on session start. `/subagent worktrees [clean]` lists or forces the sweep.
88
+ - **Write freshness guard** (repair module) — a `write` to a file another session changed since you last read it fails with a re-read-first error instead of clobbering.
89
+ - **Conflict footer** (repair module) — full-file reads surface unresolved `<<<<<<<` conflict markers automatically.
90
+
91
+ Config: `/config` → Tasks → Subagents (model pools, routing, timeouts).
92
+
93
+ ### repair — tool-call hardening
94
+
95
+ Wraps the built-in read/write/edit/grep/find/ls/bash once each: schema argument repair, edit-mismatch trim-tolerant retry with `apply_patch` escalation, destructive-bash + guessed-path guards, and read path suffixes — `file.ts:50`, `:50-200`, `:50+150`, `:-60` (tail), comma-joined ranges, `:raw`, and `:conflicts` (list merge-conflict blocks). Registers `apply_patch` (Codex-style V4D diffs) and `str_replace_editor` as standalone tools. Config: `/config` → Tools → Repair.
96
+
97
+ ### steering — model-family guidance
98
+
99
+ Provider-agnostic deepseek/glm family detection with first-tool hints, reasoning stripping, error categorization + recovery hints, and the ds-anchor two-phase bootstrap for DeepSeek minimal mode. `/steering` shows status.
100
+
101
+ ### zai — Z.AI provider (GLM)
102
+
103
+ Registers a `zai-anthropic` provider serving GLM through Z.ai's Anthropic endpoint: explicit prompt caching, `speed:"fast"` serving tier, effort-based reasoning, a cross-process rate-limit throttle, and optional ZCode request signing. `/zai` = status; config in `/config` → Providers.
104
+
78
105
  ### ux — anti-slop UI discipline
79
106
 
80
107
  `/ux off|lite|strict` injects a UI design method (tokens only, full interaction states, no AI-slop tells) for any UI work; `strict` blocks handoff until the deterministic `ux_audit` tool passes (APCA contrast, token, and state gates — no model needed). Ships the `ux-*` skills. Deactivate with `stop ux`.
@@ -90,6 +117,34 @@ Pick the input editor's look from `/config` → Appearance → Composer Shape: S
90
117
  - Config: `/config` → Tools → **Web** — 16 provider rows (endpoints, keys, timeouts, Gemini cookie, image/chat providers). Written to the global `web` settings section and read per tool call, so saves apply without `/reload`; `BRAVE_API_KEY`, `SEARXNG_BASE_URL`, `FIRECRAWL_*`, `CRAWL4AI_*`, `GEMINI_WEB_*`, `ZAI_API_KEY`, `WEB_IMAGE_*`, `WEB_CHAT_*` env vars still win. Secrets are masked. Individual tools toggle from the same section.
91
118
  - Static extraction uses vendored readability/turndown (no extra install); `jsdom` and `gemini-reverse` are the module's only runtime dependencies.
92
119
 
120
+ ### a2a — Agent2Agent protocol
121
+
122
+ Talk to remote agents (Hermes, ADK, LangChain, CrewAI, any A2A peer): 7 outbound tools (`a2a_call` with async dispatch, `a2a_status`, `a2a_discover`, `a2a_list`, `a2a_history`, `a2a_orchestrate` fan-out, `a2a_peers`) and an opt-in inbound server that serves isolated child sessions. Discovery spans a local registry, mDNS, and a2a-switchboard gateways. `/a2a-help` for everything; config in `/config` → Tasks → A2A.
123
+
124
+ ### todo — phased task board
125
+
126
+ One `todo` tool tracks an ordered phase list with `blockedBy` edges, auto-start, and a live TUI HUD; `/todo` prints the board. Follows the batch contract (call it alongside real work, never alone).
127
+
128
+ ### rules — sticky rules + rulebook
129
+
130
+ `<dir>/.pi/RULES.md` files (walking to repo root, plus a user-level file) inject sticky rules into every request; `## name` sections with a `description:` line become an on-demand rulebook served by the `rule_get` tool. Edits apply without `/reload`; `/rules` = status.
131
+
132
+ ### gh — GitHub (read-only)
133
+
134
+ One `github` tool over the `gh` CLI: `repo_view`, `file_read`, `pr_view`, `pr_diff`, issue/PR/code/commit/repo search with date qualifiers, and `run_watch` for Actions runs with failed-job log tails. Zero npm deps; fails open when `gh` is absent. Mutating flows stay with bash `gh` — which keeps the tool auto-allowed in plan mode.
135
+
136
+ ### attachments — paste files into prompts
137
+
138
+ Pasting file paths (or big text) collapses to `[[attach:name]]` tokens with a tray widget; on submit they become real image parts, path chips, or inline file blocks. `alt+shift+v` pastes clipboard file references. Config: `/config` → Files → Attachments.
139
+
140
+ ### cron — scheduled jobs
141
+
142
+ The `cron` tool + `/cron` manage recurring prompts in `<agentDir>/cron/jobs.json` (vixie-cron schedules, hand-rolled matcher — zero deps). Jobs fire as follow-up turns; pinned jobs run headless in their own Pi process. `/cron test` previews fire times; config in `/config` → Tasks → Cron.
143
+
144
+ ### permission — config-driven tool permissions
145
+
146
+ Opt-in `permission` settings section: allow/ask/deny rules per tool with wildcards, an `external_directory` deny boundary, and a doom-loop guard on repeated identical calls. No section = no opinion. Headless asks fail closed; `--yolo`/`--auto` auto-approve.
147
+
93
148
  ### serena / fff / rtk — code navigation & search (bundled tools)
94
149
 
95
150
  - **serena** — semantic code tools (find symbol, references, rename, diagnostics) via a persistent language-server worker
@@ -0,0 +1,18 @@
1
+ // Cross-module contract: the plan module publishes whether plan mode is
2
+ // currently active; the permission module reads it to stay silent while plan
3
+ // mode owns tool gating (otherwise both fire tool_call prompts on the same
4
+ // call — double prompting). Flag, not event chaining, so registration order
5
+ // never matters. Inert unless both modules are loaded: with plan disabled the
6
+ // flag simply never becomes true.
7
+ let planActive = false;
8
+
9
+ /** True while plan mode is on (plan module writes, permission module reads). */
10
+ export function isPlanActive(): boolean {
11
+ return planActive;
12
+ }
13
+
14
+ /** Publish the plan-mode state. Called by the plan module at every
15
+ * `planModeEnabled` assignment site (toggle, restore, exit-for-execution). */
16
+ export function setPlanActive(active: boolean): void {
17
+ planActive = active;
18
+ }
@@ -45,6 +45,11 @@ import { webConfig } from "../modules/web/configPanel.ts";
45
45
  import ghModule from "../modules/gh/index.ts";
46
46
  import { ghConfig } from "../modules/gh/configPanel.js";
47
47
  import rulesModule from "../modules/rules/index.ts";
48
+ import attachmentsModule from "../modules/attachments/index.ts";
49
+ import { attachmentsConfig } from "../modules/attachments/configPanel.ts";
50
+ import cronModule from "../modules/cron/index.ts";
51
+ import { cronConfig } from "../modules/cron/configPanel.ts";
52
+ import permissionModule from "../modules/permission/index.ts";
48
53
  import configModule from "../modules/config/index.ts";
49
54
 
50
55
  /** A module's contribution to the central `/config` panel. */
@@ -132,6 +137,9 @@ export const MODULES: ModuleEntry[] = [
132
137
  // child sessions reuse the host-only session guards in the module.
133
138
  { name: "a2a", category: "Tasks", describe: "A2A Protocol v1.0 peer: call remote agents (a2a_call…), be called by them (opt-in inbound server), local/mDNS/gateway discovery.", load: a2aModule, config: a2aConfig, tools: ["a2a_call", "a2a_status", "a2a_discover", "a2a_list", "a2a_history", "a2a_orchestrate", "a2a_peers"] },
134
139
  { name: "todo", category: "Tasks", describe: "Phased task board: the `todo` tool (init/start/done/block/unblock) with session persistence, blockers, an above-editor HUD, and a status-segment progress readout.", load: todoModule, config: todoConfig, tools: ["todo"] },
140
+ // Cron after todo: scheduled prompts into the live session (the clock-driven
141
+ // sibling of the task board). No before_agent_start → no ordering constraint.
142
+ { name: "cron", category: "Tasks", describe: "Scheduled jobs firing prompts into the live session: add/remove/list/run/enable/disable/test/logs/export, headless pinned runs, crontab export.", load: cronModule, config: cronConfig, tools: ["cron"] },
135
143
  // ── Tools ─────────────────────────────────────────────────────────────
136
144
  // Repair first in the section: it wraps the built-in tools; serena/fff ride
137
145
  // on top (no load-order dependency — hooks resolve at call time).
@@ -155,6 +163,9 @@ export const MODULES: ModuleEntry[] = [
155
163
  "web_search", "web_extract", "web_map", "web_crawl", "web_screenshot", "web_pdf", "web_interact", "web_research", "web_image", "web_chat", "web_status", "web_a11y",
156
164
  ] },
157
165
  { name: "rules", category: "Context", describe: "Sticky RULES.md constraints carried in every request + a rulebook of on-demand rules served by rule_get. Nearest-first project walk over user-level.", load: rulesModule, tools: ["rule_get"] },
166
+ // Attachments: paste/drop files become real attachments. No tools/commands —
167
+ // input hook + widget + shortcut only; no load-order constraint.
168
+ { name: "attachments", category: "Files", describe: "Real attachments from pasted/dropped files: [[attach:]] tokens + 📎 chips, image ImageContent parts, large-paste collapse, clipboard file paste.", load: attachmentsModule, config: attachmentsConfig },
158
169
  // gh after web: same class of external-fetch tooling; fail-open on a missing
159
170
  // gh binary (registers nothing until installed). Read-only ops only, so
160
171
  // plan mode auto-allows it (plan-tools.ts READ_ONLY_TOOLS).
@@ -171,6 +182,9 @@ export const MODULES: ModuleEntry[] = [
171
182
  { name: "steering", category: "Model", describe: "Per-model-family steering (DeepSeek/GLM): first-tool hints, reasoning strip, leak cleaning, error recovery hints, DeepSeek guidance + v4-pro minimal-mode anchor.", load: steeringModule, config: steeringConfig, tools: ["think"] },
172
183
  // ── Shell ──────────────────────────────────────────────────────────────
173
184
  { name: "rtk", category: "Shell", describe: "Route shell commands through RTK for token savings.", load: rtkModule },
185
+ // Permission after rtk: persistent allow/ask/deny gating. Inert until rules
186
+ // exist; defers to plan mode via the shared plan-bridge flag (order-free).
187
+ { name: "permission", category: "Shell", describe: "Persistent allow/ask/deny permission rules per tool (wildcards, external-directory boundary, doom-loop guard) — opt-in via the `permission` settings section; inert until configured.", load: permissionModule },
174
188
  // ── Plugins ────────────────────────────────────────────────────────────
175
189
  // Config last: it owns /config and reads the contrib map. CORE: the panel is
176
190
  // the only in-app way back from a misconfiguration — it can never be the
@@ -0,0 +1,35 @@
1
+ // Windows regression: `new URL("../../../skills/", import.meta.url).pathname`
2
+ // yields "/C:/repo/skills/" — a leading slash before the drive letter — and
3
+ // fs.realpathSync then resolves it against the CURRENT drive, dying with
4
+ // `ENOENT ... lstat 'D:\C:'` at extension load. skillsRoot() must return a
5
+ // native path (fileURLToPath), i.e. never the drive-slash shape.
6
+
7
+ import { describe, it } from "node:test";
8
+ import assert from "node:assert/strict";
9
+ import { existsSync, realpathSync } from "node:fs";
10
+ import { isAbsolute, join } from "node:path";
11
+
12
+ import { skillsRoot } from "./skill-path.js";
13
+
14
+ describe("skillsRoot", () => {
15
+ it("resolves the in-package skills/ dir on disk", () => {
16
+ const root = skillsRoot();
17
+ assert.ok(existsSync(root), `skills root exists: ${root}`);
18
+ // realpathSync is the call that blew up on Windows — it must not throw.
19
+ assert.equal(typeof realpathSync(root), "string");
20
+ });
21
+
22
+ it("never produces a drive-letter path with a leading slash", () => {
23
+ assert.doesNotMatch(skillsRoot(), /^\/[A-Za-z]:\//);
24
+ });
25
+
26
+ it("joins to this package's own skill dirs", () => {
27
+ for (const name of ["web", "munin", "a2a", "ponytail", "ux-design"]) {
28
+ assert.ok(existsSync(join(skillsRoot(), name)), `skill dir exists: ${name}`);
29
+ }
30
+ });
31
+
32
+ it("is absolute (never resolved against cwd)", () => {
33
+ assert.ok(isAbsolute(skillsRoot()));
34
+ });
35
+ });
@@ -0,0 +1,22 @@
1
+ // Shared skills/ root resolution for every module's resources_discover handler.
2
+ //
3
+ // `new URL("../../../skills/", import.meta.url).pathname` is WRONG on Windows:
4
+ // the WHATWG URL pathname keeps the authority-style leading slash and percent
5
+ // encoding, so a file URL like file:///C:/repo/skills/ yields "/C:/repo/skills/".
6
+ // fs.realpathSync("/C:/...") then resolves against the CURRENT drive's root
7
+ // (e.g. D:\) and load dies with `ENOENT ... lstat 'D:\C:'`.
8
+ // fileURLToPath decodes and strips the leading slash on drive-letter paths,
9
+ // giving the native `C:\repo\skills\` shape.
10
+
11
+ import { fileURLToPath } from "node:url";
12
+
13
+ // This file sits at extensions/lib/, so the repo-root skills/ dir is TWO
14
+ // levels up (modules/<name>/index.ts callers need three — they import this
15
+ // helper instead of building the URL themselves).
16
+ //
17
+ // ponytail: assumes the standard in-repo layout (extensions/lib/ next to
18
+ // skills/). A future relocated build should set an explicit package-root
19
+ // constant here rather than deepen the relative walk.
20
+ export function skillsRoot(): string {
21
+ return fileURLToPath(new URL("../../skills/", import.meta.url));
22
+ }
@@ -13,7 +13,7 @@
13
13
  */
14
14
 
15
15
  import { homedir } from "node:os";
16
- import { chmodSync, realpathSync } from "node:fs";
16
+ import { chmodSync } from "node:fs";
17
17
  import { join } from "node:path";
18
18
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
19
19
  import { Type } from "typebox";
@@ -41,6 +41,7 @@ import { Container, Text } from "@earendil-works/pi-tui";
41
41
  // (configPanel.ts). ceulen deltas: ceulen-a2a-inbound customType/status key,
42
42
  // per-tool kill-switch wrap, resources_discover skill, restart bridge export.
43
43
  import { readDisabledTools } from "../../lib/tools.js";
44
+ import { skillsRoot } from "../../lib/skill-path.js";
44
45
 
45
46
  // ---------------------------------------------------------------------------
46
47
  // Module state
@@ -546,8 +547,9 @@ export default function a2aExtension(pi: ExtensionAPI): void {
546
547
  // resources_discover — NOT via the package.json pi.skills manifest — so the
547
548
  // kill-switch gates it too (web module pattern).
548
549
  pi.on("resources_discover", () => {
549
- const skillsRoot = new URL("../../../skills/", import.meta.url).pathname;
550
- return { skillPaths: [join(realpathSync(skillsRoot), "a2a")] };
550
+ // skillsRoot() is already a native absolute path (fileURLToPath) — no
551
+ // realpath needed; a throw here would kill the whole module load.
552
+ return { skillPaths: [join(skillsRoot(), "a2a")] };
551
553
  });
552
554
 
553
555
  pi.registerTool({
@@ -768,7 +768,7 @@ export function writeSettingsA2A(opts: {
768
768
 
769
769
  // Atomic write: temp file + rename.
770
770
  const tmp = target + ".tmp";
771
- writeFileSync(tmp, JSON.stringify(json, null, 2) + "\n", "utf-8");
771
+ writeFileSync(tmp, JSON.stringify(json, null, 2) + "\n", { encoding: "utf-8", mode: 0o600 });
772
772
  renameSync(tmp, target);
773
773
  return target;
774
774
  }
@@ -62,7 +62,7 @@ export function register(desc: SessionDescriptor, piDir: string): void {
62
62
  try {
63
63
  const p = fileFor(piDir, desc.pid);
64
64
  mkdirSync(dir(piDir), { recursive: true });
65
- writeFileSync(p, JSON.stringify(desc, null, 2), { encoding: "utf-8" });
65
+ writeFileSync(p, JSON.stringify(desc, null, 2), { encoding: "utf-8", mode: 0o600 });
66
66
  } catch {
67
67
  /* best-effort */
68
68
  }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * attachments' /config contribution — Files tab, Attachments section.
3
+ *
4
+ * Rows write the GLOBAL agent-dir settings.json `attachments` section
5
+ * (lib/settings.ts — the same file the module re-reads on session_start, so a
6
+ * save applies to the NEXT session without /reload; the paste-file shortcut
7
+ * additionally binds at module load and needs a full restart).
8
+ */
9
+ import { row, type PanelGroup } from "../../lib/panel.js";
10
+ import type { ModuleConfig } from "../../lib/registry.js";
11
+ import { DEFAULTS, loadSettings, writeAttachmentsSection, type AttachmentsSettings } from "./lib/settings.js";
12
+
13
+ /** Build the attachments panel groups over a working copy (mutated by row
14
+ * setters). Exported for tests. */
15
+ export function buildAttachmentsGroups(cfg: AttachmentsSettings): PanelGroup[] {
16
+ return [
17
+ {
18
+ key: "attachments",
19
+ label: "Attachments",
20
+ tab: "Files",
21
+ icon: "📎",
22
+ rows: [
23
+ row("attachments.inlineTextFiles", "Inline text files", "toggle", cfg.inlineTextFiles, (v) => {
24
+ cfg.inlineTextFiles = Boolean(v);
25
+ }, {
26
+ description: "Inline text-file paths as <file> content blocks instead of 📎 path chips — convenient, but re-read on every turn.",
27
+ defaultValue: DEFAULTS.inlineTextFiles,
28
+ }),
29
+ row("attachments.maxInlineBytes", "Max inline bytes", "number", cfg.maxInlineBytes, (v) => {
30
+ const n = Number(v);
31
+ if (Number.isFinite(n) && n > 0) cfg.maxInlineBytes = n;
32
+ }, {
33
+ description: "Size cap for text-file inlining (inline mode only). Larger files keep the 📎 path chip.",
34
+ defaultValue: DEFAULTS.maxInlineBytes,
35
+ }),
36
+ row("attachments.pasteFileShortcut", "Paste-file shortcut", "string", cfg.pasteFileShortcut, (v) => {
37
+ const s = String(v ?? "").trim();
38
+ if (s) cfg.pasteFileShortcut = s;
39
+ }, {
40
+ warning: "Takes effect after a full restart — the shortcut binds when the extension loads.",
41
+ description: "Keybinding for paste-file-from-clipboard (pi-tui KeyId grammar, e.g. alt+shift+v, ctrl+shift+v, f2).",
42
+ defaultValue: DEFAULTS.pasteFileShortcut,
43
+ }),
44
+ row("attachments.pasteCollapseLines", "Paste collapse lines", "number", cfg.pasteCollapseLines, (v) => {
45
+ const n = Number(v);
46
+ if (Number.isFinite(n) && n >= 0) cfg.pasteCollapseLines = n;
47
+ }, {
48
+ description: "Pastes with ≥ this many lines collapse to a paste file + one token. 0 disables.",
49
+ defaultValue: DEFAULTS.pasteCollapseLines,
50
+ }),
51
+ row("attachments.pasteCollapseChars", "Paste collapse chars", "number", cfg.pasteCollapseChars, (v) => {
52
+ const n = Number(v);
53
+ if (Number.isFinite(n) && n >= 0) cfg.pasteCollapseChars = n;
54
+ }, {
55
+ description: "Pastes with ≥ this many characters collapse even below the line threshold (minified JSON walls). 0 disables.",
56
+ defaultValue: DEFAULTS.pasteCollapseChars,
57
+ }),
58
+ ],
59
+ },
60
+ ];
61
+ }
62
+
63
+ const OWNED_PREFIX = "attachments.";
64
+
65
+ /** attachments' ModuleConfig for the central /config panel. */
66
+ export function attachmentsConfig(): ModuleConfig {
67
+ const before = loadSettings();
68
+ const working: AttachmentsSettings = { ...before };
69
+
70
+ return {
71
+ groups: () => buildAttachmentsGroups(working),
72
+ save: async (edited, ctx) => {
73
+ const FIELDS: (keyof AttachmentsSettings)[] = [
74
+ "inlineTextFiles", "maxInlineBytes", "pasteFileShortcut", "pasteCollapseLines", "pasteCollapseChars",
75
+ ];
76
+ const patch: Partial<AttachmentsSettings> = {};
77
+ for (const key of edited) {
78
+ if (!key.startsWith(OWNED_PREFIX)) continue;
79
+ const field = key.slice(OWNED_PREFIX.length) as keyof AttachmentsSettings;
80
+ if (FIELDS.includes(field)) (patch as Record<string, unknown>)[field] = working[field];
81
+ }
82
+ if (!Object.keys(patch).length) return;
83
+ try {
84
+ const file = writeAttachmentsSection(patch);
85
+ ctx.ui.notify(`Attachments settings saved to ${file} — applies next session (shortcut: full restart).`, "info");
86
+ } catch (e) {
87
+ ctx.ui.notify(`Attachments save failed: ${e instanceof Error ? e.message : e}`, "error");
88
+ }
89
+ },
90
+ };
91
+ }