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
package/CHANGELOG.md ADDED
@@ -0,0 +1,150 @@
1
+ # Changelog
2
+
3
+ ## 0.5.0 — 2026-09-30
4
+
5
+ - **pi 0.99.1 compatibility**: peer dependencies widened from
6
+ `>=0.80.8 <0.88.0` to `>=0.99.1 <0.101.0` for both
7
+ `@earendil-works/pi-coding-agent` and `@earendil-works/pi-tui`. No code changes — all surfaces verified:
8
+ registration API (guarded() claims), composer `CustomEditor` duck-typing,
9
+ theme Proxy/`setTheme` semantics, `session_start` re-fire, trust.json
10
+ gating, jiti extension loading (the 0.99 tsx→type-stripping switch affects
11
+ pi's own build only). 306 tests + live `pi --mode rpc` smoke pass.
12
+
13
+ ## Unreleased
14
+
15
+ - **composer** (new CORE module): Composer Shape for the input editor with
16
+ OMP's full vocabulary and copy — **Status Band** (default) · **Rounded Box**
17
+ · **Claude Code** · **Pi** · **Borderless** · **Top Rule Dock** · **Compact
18
+ Field** · **Accent Rail**. Browsing the Shape row renders a live preview
19
+ block in the panel through the same chrome builders the running editor
20
+ uses (no drift); Enter applies to the running editor immediately
21
+ (text/autocomplete/app keybindings preserved via `CustomEditor`
22
+ duck-typing) and persists `composer.shape`. Side borders, prompt gutters
23
+ and filled surfaces are composed by re-laying the editor out at the
24
+ shape's content width and wrapping each row — the cursor marker survives,
25
+ so wrapping and hardware-cursor placement stay exact. Status-bearing
26
+ shapes show live model · cwd · context-%; the working spinner stays
27
+ visible in every shape. Always on: no kill-switch (a half-configured
28
+ composer is worse than none).
29
+ - **config**: rows can carry a `previewLines` hook — a read-only preview
30
+ block under the rows pane / selection menu that follows the highlighted
31
+ option (OMP's settings-screen preview window).
32
+ - **registry**: modules are categorized — `ModuleEntry.category` (the OMP
33
+ tab) is now the single source for /config tab placement, synthesized
34
+ Enable-only sections, and `/ceulen` status grouping (now rendered per
35
+ category: `Providers: router · Appearance: usage, composer · …`).
36
+ - **config**: multi-choice rows now open an **OMP-style selection menu**
37
+ instead of cycling — press Enter on Theme, Default thinking level, Transport,
38
+ Mermaid mode, ponytail mode, … and the panel swaps to a full option list:
39
+ `↑↓` browse (clamped), typing filters options live, `Enter` selects and
40
+ `Esc` backs out (clearing the filter first). The row's description/warning
41
+ stays visible below the menu, options can carry their own one-line
42
+ descriptions, the current value is marked `(current)`, and the footer
43
+ switches to the menu's key hints. **Theme previews live while browsing** —
44
+ moving through the theme list restyles the whole terminal (panel included)
45
+ immediately, `Esc` restores the previous theme, and `Enter` persists it.
46
+ The Default model row opens a `provider/id` picker built from the model
47
+ catalogue (`ctx.modelRegistry`), writing provider + model as one pair.
48
+ Everything goes through pi's public extension API (`ctx.ui.getAllThemes`/
49
+ `getTheme`/`setTheme`, `ctx.modelRegistry.getAvailable`).
50
+ - **config**: `/config` now spans **pi core settings + ceulen modules** under
51
+ OMP's taxonomy — tabs are Appearance · Model · Interaction · Context · Shell ·
52
+ Tasks · Providers · Plugins (empty categories don't render). Pi-core rows are
53
+ backed by Pi's own public `SettingsManager` (theme, thinking, transport/retry,
54
+ steering, trust & telemetry, shell, images, fullscreen…), so they read the
55
+ effective global ⊕ project value and save to the global `settings.json` via
56
+ Pi's typed setters (apply after `/reload`). The standalone **Modules** kill-switch
57
+ tab is gone: each module's **Enabled** row now sits at the top of its own
58
+ section — Router → Providers, ponytail → Tasks, usage → Appearance, the config
59
+ panel → Plugins — and stays visible (and togglable) even while the module is
60
+ off.
61
+ - **config**: OMP-parity chrome pass — the frame is a closed box
62
+ (`╭─┤│╰─╯`, every content row `│ … │`); section headings render underlined
63
+ in-pane beside the sidebar (OMP shows both) with rows outside the active
64
+ section dim-washed; the sidebar width is pinned across every tab so the `│`
65
+ rail never jumps, and hides below a 60-column rows pane (headings remain);
66
+ changed-from-default values render warning-colored on the label too (a
67
+ selected+changed row keeps an accent label + warning value); the tab bar
68
+ collapses inactive tabs to icons starting farthest from the active one (the
69
+ active tab keeps its label); and the browse footer hint now derives from the
70
+ active tab (`Enter toggle` for toggle/enum-only tabs, no Enter pair for
71
+ read-only tabs, no section jump for single-section tabs).
72
+ - **config**: `/config` is now a fullscreen panel (OMP `/settings` parity): the
73
+ frame fills the terminal as a 100%×100% overlay — title border, tab row, and a
74
+ pinned key-hint footer as the last row (the hints follow the mode: browse,
75
+ search, inline edit, action prompt), with the unsaved-changes marker
76
+ right-aligned on that footer. The rows pane is height-driven (it grows with a
77
+ taller terminal instead of the fixed 18-row window), and the chat underneath
78
+ is untouched while the panel is open.
79
+ - **router/ponytail**: individual config commands removed now that `/config` is
80
+ the single settings surface — `/router-config` and `/router-reasoning` are the
81
+ Providers tab's Router section, `/ponytail default <mode>` is the Tasks tab's
82
+ Default-mode row.
83
+ `/router-status`, `/router-model`, and `/ponytail <mode>|status` are unchanged
84
+ (status / model picking / session-mode switching, not persisted config).
85
+ - **config**: `/config` now follows OMP's tab → section → rows hierarchy, and tab
86
+ navigation actually works in every terminal. Fixes: `←`/`→` used raw escape-byte
87
+ comparisons, so application-cursor-mode (SS3 `\u001bOD`) and kitty-protocol
88
+ terminals never moved backward — navigation now goes through pi-tui's `matchesKey`
89
+ (CSI/SS3/CSI-u all match), and tab stepping WRAPS like OMP's TabBar instead of
90
+ clamping. Structure: adjacent groups sharing a `tab` merge into one tab
91
+ (Router's Endpoint + Models are now one Router section under the Providers tab), each group's label renders
92
+ as a left-sidebar section beside its detail rows, `PageUp`/`PageDown` jump
93
+ sections, and rows outside the active section get OMP's dim wash. Plugins splits
94
+ into Project/Global sections under one 📦 tab.
95
+ - **config**: tab bar polish — per-group icons (`PanelGroup.icon`; the bundled
96
+ groups use 🌐 Router / 🦥 Ponytail / 📦 Plugins),
97
+ active tab inverse-highlighted (`selectedBg`, falls back to bold accent) with
98
+ an icon-only fallback on narrow bars, a middle accent heading naming the
99
+ category being configured (icon + label + setting count), and footer key
100
+ hints that color each key glyph in accent with its meaning dimmed (OMP
101
+ style). Also fixes the description area leaking a neighbor row's text while
102
+ the active tab is empty, and enables `←/→` category jumps during search in
103
+ the keybinding-less input path.
104
+ - **config**: `/config` is now TABBED — one tab per category (Modules, Endpoint, Models,
105
+ Ponytail, Plugins…) with `←/→`/`Tab`/`Shift+Tab` switching, so each category renders
106
+ in its own view instead of one long mixed list. Per-tab selection memory, ↑/↓ clamped
107
+ to the active tab, active-tab highlighting (inverse/selectedBg), narrow-terminal tab
108
+ windowing with `…` edge markers, and a single-group panel that renders no tab bar.
109
+ Search still spans all tabs; `←/→` during a search jumps between matching categories,
110
+ and clearing it snaps the panel to the selected row's tab.
111
+ - **config**: new **Plugins** group in the `/config` panel — every installed Pi package
112
+ (`packages` in settings.json, project entries first when trusted) gets an on/off toggle.
113
+ Off writes Pi's whole-off form (`{source, extensions: [], skills: [], prompts: [], themes: []}`
114
+ — the load contract's "empty array disables all resources"), on restores the plain
115
+ string; each row writes back to the file its entry lives in, atomically, refusing a
116
+ corrupt file. Packages carrying granular `pi config` filters or `autoload: false`
117
+ project deltas render as read-only "custom filters" rows. New kernel `info` row kind
118
+ (display-only derived state); `/config show` lists plugins too.
119
+ - **config**: `/config` panel v2 — OMP-style split layout (module rail + rows pane with a dim wash outside the active group, selection-derived active section, fixed 3-row help area showing the selected row's description/warning), enum rows (`Enter` cycles a closed value set — ponytail default mode no longer accepts free text), changed-vs-default values rendered warning-styled, `←→`/`Tab` section jumps, type-to-search fuzzy filter (printable text; `Esc` clears, then closes), width-dependent flat fallback below 60 pane columns. Kernel `extensions/lib/panel.ts` is now a fork evolved in-repo (was: fixed vendor snapshot of `@bacnh85/pi-config-panel` 0.1.10). Rows gain optional `description`/`warning`/`values`/`defaultValue`; `ModuleEntry.describe` feeds each module's kill-switch help line; `/config show` appends help text.
120
+ - **config** (new module): `/config` — one central settings panel for every ceulen module, on top of the vendored panel kernel. Module kill-switches (writes `ceulen.disabled` to the effective settings layer — project when trusted and it carries the section, else agent dir; disclosed in the panel), router endpoint + thinking levels (save re-registers the provider, force-refreshes the catalog, revalidates the active model), ponytail default mode / quiet startup / status bar (own config file; next session). Non-TUI/multi-arg shells get `/config show` text. `/settings` is a Pi builtin and cannot be overridden by extensions — `/config` is the ceulen surface.
121
+ - **bundle**: `MODULES` registry + kill-switch settings I/O moved from `extensions/index.ts` to `extensions/lib/registry.ts` (the config module iterates it without a circular import). Modules may now declare `config?: (pi) => ModuleConfig` — a `{ groups(), save(editedKeys, ctx) }` contribution; the loader hands each module a `ModuleLoadDeps` map whose factories close over that module's own guarded `pi`.
122
+ - **router**: panel + save logic extracted to `modules/router/configPanel.ts` (`buildRouterGroups`/`saveRouterConfig`), the central panel's single save path; `writeRouterSection` moved from `commands/commands.ts` to `lib/config.ts`.
123
+ - **ponytail**: `writeConfigBools` helper added to `lib/config.ts`; central-panel contribution for `defaultMode`/`quietStartup`/`hideStatus`.
124
+
125
+ - **usage** (renamed from **sub**): the module and its command are now `/usage` (`/sub` survives only as the deprecated kill-switch key `"sub"` → treated as `"usage"`). Status-bar key is `ceulen-usage`; message customTypes are `ceulen-usage-status` / `ceulen-usage-context`; User-Agent is `ceulen/x.y.z`. Sessions recorded before this change replay the old `pi-sub-*` messages as raw text (the renderer was renamed with the module).
126
+ - **bundle**: new cross-module duplicate-registration guard — all ceulen modules share one extension object, where a repeated name silently overwrites; a claim by a DIFFERENT module now throws at load (same-module re-claims stay legal, e.g. router's runtime provider refresh). Env ingestion (`.env.local`/`.env`, trust-gated) moved to `extensions/lib/env.ts` — bundle infrastructure, no longer exported from a feature module.
127
+ - **bundle**: trusted cwd `.env` ingestion (`loadCwdEnvFilesIfTrusted`) is now also registered at the bundle entry, before every module's `session_start` — sub previously loaded it in its own handler, which runs after router's, so a trusted repo's `.env`-provided `ROUTER_BASE_URL`/`ROUTER_ENABLE_REASONING` was invisible to router for the entire first session.
128
+ - **sub**: backported the nightly-review security fix from pi-sub — cwd `.env.local`/`.env` are no longer ingested at import time (an untrusted checkout could inject `ROUTER_MGMT_TOKEN` etc.); they now load in `session_start` only behind `ctx.isProjectTrusted()`, with global agent-dir env files still injected at import and trusted-cwd files overriding only those. Also backported the expired-Codex-JWT fix: a plan label no longer renders from a token whose `exp` has passed (shows `expired`).
129
+
130
+ ## 0.3.0 — 2026-09-28
131
+
132
+ Wave 2: ponytail merged into the bundle.
133
+
134
+ - **ponytail** (from pi-ponytail 0.1.17, fork of DietrichGebert/ponytail 4.9.0): lazy-senior-dev mode — `/ponytail off|lite|full|ultra|review` switcher (session-persisted), status-bar indicator, per-turn system-prompt injection, subagent instruction inheritance. The six `ponytail*` skills ship in-package and register through the module's `resources_discover` handler, so the kill-switch removes them along with the commands.
135
+ - Commands: `/ponytail [mode|status|default <mode>]`, plus `/ponytail-review|audit|gain|debt|help` skill aliases.
136
+ - Config unchanged (`~/.config/ponytail/config.json`, `PONYTAIL_*` envs) — existing pi-ponytail users keep everything; kill-switch via `"ceulen": { "disabled": ["ponytail"] }`.
137
+
138
+ ## 0.2.0 — 2026-09-28
139
+
140
+ Wave 1: first two production modules merged into the bundle.
141
+
142
+ - **router** (from pi-router 1.2.3): generic `router` provider for any OpenAI-compatible router (`/v1/models` + `/v1/chat/completions`), commands `/router-status`, `/router-config`, `/router-reasoning`, `/router-model`.
143
+ - **sub** (from pi-sub 0.1.52): subscription-usage footer + `/sub` + `/context`, including the Yardmaster usage display (`GET <router.baseUrl>/usage?provider=<prefix>`).
144
+ - `@bacnh85/pi-config-panel` vendored into `extensions/lib/panel.ts` — ceulen ships with zero runtime dependencies.
145
+ - Kill-switch: `"ceulen": { "disabled": ["sub"] }` in settings.json skips modules.
146
+ - Research `docs/` removed (captured in git history and project memory).
147
+
148
+ ## 0.1.0 — 2026-09-21
149
+
150
+ Name reservation + bundle scaffold.
package/README.md CHANGED
@@ -2,37 +2,126 @@
2
2
 
3
3
  **The Pi coding agent, fully dressed.**
4
4
 
5
- Pi's minimal core + one bundle extension carrying the complete toolkit — everything wired behind a single `/ceulen config` command. Named for Ludolph van Ceulen, who spent his life computing π to 35 digits (they're carved on his tombstone); in 17th-century Germany, π was literally called *die Ceulensche Zahl*.
5
+ Pi's minimal core + one bundle extension carrying the complete toolkit, wired behind a single `/ceulen` command. Named for Ludolph van Ceulen, who computed π to 35 digits — they're carved on his tombstone.
6
6
 
7
7
  ## What it is
8
8
 
9
9
  A [Pi](https://github.com/earendil-works/pi) distro in the form of one extension bundle:
10
10
 
11
- - **One install** — no assembling 38 separate extensions; the suite ships as a unit
12
- - **One command** — `/ceulen config` for every knob (or plain `/config` when ceulen is active)
13
- - **One surface** — modules register cleanly into Pi's native UX: tools, commands, flags, events
14
- - **Selective adoption** — every module has an individual kill-switch; disable what you don't use, keep the rest of the bundle intact
15
- - **No core patches** — ceulen rides Pi's public extension API only, so upstream Pi upgrades stay drop-in
11
+ - **One install** — the suite ships as a unit
12
+ - **One surface** — modules register into Pi's native UX: tools, commands, events
13
+ - **Selective adoption** — every module has an individual kill-switch; disable what you don't use
14
+ - **No core patches** — Pi's public extension API only, so upstream upgrades stay drop-in
15
+ - **Zero runtime dependencies** — everything is vendored
16
16
 
17
17
  ## Install
18
18
 
19
19
  ```sh
20
- npm install -g ceulen
20
+ pi install npm:ceulen
21
21
  ```
22
22
 
23
- Then start Pi in your project directory — ceulen's modules load automatically.
23
+ Add `-l` to install into the current project instead of your user scope. Update with `pi update --extensions`. Then start Pi in your project directory — ceulen's modules load automatically.
24
24
 
25
- ## Status
25
+ ## Modules
26
26
 
27
- **Pre-release (0.1.0).** Name reserved; module consolidation from the pi-extensions fleet in progress. Design record: [`docs/`](./docs) — architecture decision, extension audit, naming research.
27
+ ### router — any OpenAI-compatible router as a Pi provider
28
28
 
29
- ## Modules
29
+ Registers the generic `router` provider (models via `GET /v1/models`, chat via `/v1/chat/completions`) against 9router, OmniRoute, yardmaster, or any OpenAI-compatible router.
30
+
31
+ - Config: `router.baseUrl` in `~/.pi/agent/settings.json` (or `ROUTER_BASE_URL` env)
32
+ - Auth: `/login router` in Pi (or `ROUTER_API_KEY` env)
33
+ - Commands: `/router-status`, `/router-model` — settings via `/config` (Providers tab)
34
+
35
+ ### usage — subscription-usage footer
36
+
37
+ A status footer showing subscription/provider usage (5-hour, weekly, monthly windows, credits). Commands: `/usage` (usage detail), `/context` (context-window detail).
30
38
 
31
- Planned (consolidating from the pi-extensions fleet — see the audit in `docs/`):
39
+ **Yardmaster**: if `router.baseUrl` points at a yardmaster instance, the footer polls `GET <baseUrl>/usage?provider=<prefix>` (falling back to the aggregate `GET /usage`, then OmniRoute's `om-usage` endpoint) and renders remaining % per window plus credit balance:
32
40
 
33
- notify · cron · references · ponytail · classifier · a2a · budget · checkpoint · model-tools · permission · plan · web · memory · review · … (full list in the compatibility audit)
41
+ ```
42
+ Router · command-code 5h:82% W:64% M:31% M:$12.40
43
+ ```
44
+
45
+ Needs a yardmaster API key with the **usage** permission — the same key you `/login router` with works if it has that permission.
46
+
47
+ ### composer — Composer Shape for the input editor
48
+
49
+ Re-chrome Pi's input editor from `/config` (Appearance → Composer Shape) with
50
+ OMP's full composer vocabulary — **Status Band** (default) · **Rounded Box** ·
51
+ **Claude Code** · **Pi** · **Borderless** · **Top Rule Dock** · **Compact
52
+ Field** · **Accent Rail** — each with OMP's own label and one-line
53
+ description in the selection menu. Browsing the Shape row previews the shape
54
+ right in the panel (rendered through the same chrome builders the live editor
55
+ uses — no drift); Enter applies it to the running editor immediately — text,
56
+ autocomplete and all app keybindings intact (the custom editor extends Pi's
57
+ `CustomEditor`) — and persists `composer.shape` to the global settings.json.
58
+ Status-bearing shapes (Band, Box, Claude, Top Rule Dock) show live session
59
+ data — model · directory · context %; the working spinner stays visible in
60
+ every shape. **Core module**: always loaded, no kill-switch — a
61
+ half-configured composer is worse than none.
62
+
63
+ - Config: `composer.shape` in `~/.pi/agent/settings.json` — via `/config` (Appearance tab)
64
+
65
+ ### ponytail — lazy-senior-dev mode
66
+
67
+ Lazy mode for the agent itself: `/ponytail off|lite|full|ultra|review` switches the over-engineering discipline level (persisted per session); `stop ponytail` / `normal mode` deactivates. The active level is injected into the system prompt each turn, shown in the status bar, and inherited by subagents. Ships the six `ponytail*` skills (`/ponytail-review|audit|gain|debt|help`).
68
+
69
+ - Config: `~/.config/ponytail/config.json` or `PONYTAIL_*` envs
70
+ - Command: `/ponytail [mode|status]` — default mode via `/config` (Tasks tab)
71
+
72
+ ### config — central settings panel
73
+
74
+ `/config` opens one fullscreen panel for **pi core settings and every ceulen
75
+ module** — the frame fills the terminal (boxed corners, tab row, pinned
76
+ key-hint footer), so the chat is replaced while you configure and comes back
77
+ untouched on close. Tabs follow OMP's settings taxonomy: **Appearance · Model ·
78
+ Interaction · Context · Shell · Tasks · Providers · Plugins** (empty
79
+ categories don't render). A tab with several settings groups shows them as a
80
+ left sidebar of sections with the underlined section headings repeated beside
81
+ the detail rows, OMP style; the sidebar geometry stays identical across tabs.
82
+
83
+ - **Appearance** — pi theme, display/editor/fullscreen/terminal-image settings, plus the usage-footer and composer module switches
84
+ - **Model** — default model/provider, thinking, network transport/timeouts, retry, cache warming
85
+ - **Interaction** — steering/follow-up modes, double-escape + tree filter, startup notices, trust & telemetry
86
+ - **Context / Shell** — auto-compact, shell path/prefix, npm command
87
+ - **Tasks** — ponytail (default mode `off/lite/full/ultra`, quiet startup, status-bar visibility; applies next session)
88
+ - **Providers** — router (base URL + thinking levels; saves re-register the provider and refresh the catalog live)
89
+ - **Plugins** — every installed Pi package (`packages` in settings.json) with an on/off
90
+ toggle; disabling writes the package in Pi's all-empty-resource-list form. Packages
91
+ with granular `pi config` filters or project filter deltas show as read-only
92
+ ("custom filters"). Toggles apply after `/reload`.
93
+
94
+ Each module's on/off switch lives at the top of its own section (Router → Providers,
95
+ ponytail → Tasks, usage → Appearance, the config panel itself → Plugins) as an
96
+ **Enabled** row writing the `ceulen.disabled` list — a feature is turned on where
97
+ it is configured. Pi-core rows are backed by Pi's `SettingsManager` and save to the
98
+ global `settings.json`; they apply after `/reload` (or a new session).
99
+
100
+ Keyboard: `←→`/`Tab`/`Shift+Tab` switch tabs (wrapping), `↑↓` move, `PageUp`/
101
+ `PageDown` jump sections, `Enter` toggles a switch or opens the selection menu,
102
+ type any text to fuzzy-search across every tab (`←→` jumps between matching
103
+ categories), `Esc` saves and closes (a second `Esc` clears the search first).
104
+ Multi-choice rows (theme, thinking level, transport, model, …) open an
105
+ OMP-style **selection menu** in place: `↑↓` browse, type to filter, `Enter`
106
+ selects, `Esc` backs out. **Theme changes preview live** as you browse (the
107
+ whole terminal restyles; `Esc` restores the previous theme) and the model
108
+ picker lists `provider/id` from the model catalogue. Values differing
109
+ from their default render in warning color; rows that env vars can override
110
+ say so in the help area.
111
+
112
+ Pi's builtin `/settings` cannot be overridden by extensions (a colliding
113
+ command is renamed `/settings:1`); `/config` adds the ceulen modules around
114
+ pi's own settings. Non-TUI shells get a text summary (`/config show`).
115
+
116
+ ## Kill-switches
117
+
118
+ In `~/.pi/agent/settings.json` (or a trusted project's `.pi/settings.json`):
119
+
120
+ ```json
121
+ { "ceulen": { "disabled": ["usage"] } }
122
+ ```
34
123
 
35
- Each module can be disabled individually via Pi settings — see `/ceulen config` once shipped.
124
+ Disabled modules don't register anything; `/ceulen` lists what's active and disabled. `/config` toggles the same list — it writes to whichever file currently carries the `ceulen` section (project file when that's the effective one, disclosed in the panel).
36
125
 
37
126
  ## License
38
127
 
@@ -0,0 +1,113 @@
1
+ /**
2
+ * ceulen — the Pi coding agent, fully dressed.
3
+ *
4
+ * One bundle extension: feature modules loaded by a single entry, each with
5
+ * a per-module kill-switch. Every module registers only through
6
+ * Pi's public extension API — no core patches, so upstream Pi upgrades stay
7
+ * drop-in.
8
+ *
9
+ * Modules land in waves. Wave 1: router + usage. Wave 2: ponytail. Wave 3: config.
10
+ */
11
+
12
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
13
+ import { loadCwdEnvFilesIfTrusted } from "./lib/env.js";
14
+ import { MODULES, readDisabled, type ModuleConfig, type ModuleLoadDeps } from "./lib/registry.js";
15
+
16
+ // Guards the ONE namespace bundle modules share: pi merges every module's
17
+ // registrations into a single extension object, where a duplicate name
18
+ // silently overwrites (Map.set). A claim by a DIFFERENT module throws;
19
+ // same-owner re-claims pass (router re-registers its provider at runtime).
20
+ // `owner` MUST be one map shared by every module in the load loop — created
21
+ // in ceulen() and passed in; per-module maps would make this a no-op.
22
+ // Exported for the guard contract test. ponytail: ~20-line ownership map,
23
+ // not a registration framework.
24
+ export function guarded(pi: ExtensionAPI, mod: string, owner: Map<string, string>): ExtensionAPI {
25
+ const claim = (kind: string, nameOf: (first: never) => string, pass: (...args: never[]) => unknown) => (...args: never[]) => {
26
+ const key = `${kind}:${nameOf(args[0])}`;
27
+ const first = owner.get(key);
28
+ if (first && first !== mod) throw new Error(`ceulen: module "${mod}" re-registered ${key} (already owned by "${first}")`);
29
+ owner.set(key, mod);
30
+ return pass(...args);
31
+ };
32
+ const keyOf = {
33
+ command: (n: string) => n,
34
+ tool: (t: { name: string }) => t.name,
35
+ flag: (n: string) => n,
36
+ shortcut: (k: string) => k,
37
+ renderer: (t: string) => t,
38
+ provider: (p: string | { name: string }) => (typeof p === "string" ? p : p.name),
39
+ };
40
+ return {
41
+ ...pi,
42
+ registerCommand: claim("command", keyOf.command, pi.registerCommand.bind(pi)),
43
+ registerTool: claim("tool", keyOf.tool, pi.registerTool.bind(pi)),
44
+ registerFlag: claim("flag", keyOf.flag, pi.registerFlag.bind(pi)),
45
+ registerShortcut: claim("shortcut", keyOf.shortcut, pi.registerShortcut.bind(pi)),
46
+ registerMessageRenderer: claim("renderer", keyOf.renderer, pi.registerMessageRenderer.bind(pi)),
47
+ registerEntryRenderer: claim("entry-renderer", keyOf.renderer, pi.registerEntryRenderer.bind(pi)),
48
+ registerProvider: claim("provider", keyOf.provider, pi.registerProvider.bind(pi)),
49
+ } as ExtensionAPI;
50
+ }
51
+
52
+ export default function ceulen(pi: ExtensionAPI) {
53
+ // Kill-switch: "ceulen": { "disabled": ["usage"] } in settings.json skips those
54
+ // modules entirely. Minimal form of the per-module toggle promise.
55
+ // ponytail: SDK ExtensionAPI has no getSetting — read settings.json directly
56
+ // (trusted repo scope, then agent dir), mirroring pi-evolve/pi-selfskills.
57
+ const disabled = new Set(readDisabled());
58
+
59
+ pi.registerCommand("ceulen", {
60
+ description: "Ceulen config — module status",
61
+ handler: async (_args, ctx) => {
62
+ // Grouped by each module's registry category (OMP taxonomy) — same
63
+ // order as the registry, which is the /config tab order too.
64
+ const byCat = new Map<string, { active: string[]; off: string[] }>();
65
+ for (const m of MODULES) {
66
+ const g = byCat.get(m.category) ?? { active: [], off: [] };
67
+ (disabled.has(m.name) ? g.off : g.active).push(m.name);
68
+ byCat.set(m.category, g);
69
+ }
70
+ const lines: string[] = [];
71
+ for (const [cat, g] of byCat) {
72
+ lines.push(`${cat}: ${g.active.join(", ")}${g.off.length ? ` (disabled: ${g.off.join(", ")})` : ""}`);
73
+ }
74
+ const activeCount = MODULES.length - disabled.size;
75
+ const core = MODULES.filter((m) => m.core).map((m) => m.name);
76
+ ctx.ui.notify(
77
+ `Ceulen ${activeCount} module(s) active:\n ${lines.join("\n ")}` +
78
+ (core.length ? `\nCore (always on): ${core.join(", ")}` : "") +
79
+ "\nConfigure: /config",
80
+ "info",
81
+ );
82
+ },
83
+ });
84
+
85
+ // Trusted cwd .env ingestion must precede every module's session_start:
86
+ // router reads ROUTER_BASE_URL/ROUTER_ENABLE_REASONING in its own handler, so
87
+ // a trusted repo's .env loaded any later is invisible for the whole first
88
+ // session. Registered first (handlers fire in registration order); sub keeps
89
+ // its own idempotent call as a safety net when this entry is bypassed.
90
+ pi.on("session_start", async (_event, ctx) => {
91
+ loadCwdEnvFilesIfTrusted(ctx);
92
+ });
93
+
94
+ // One ownership map for the whole loop — this is what makes guarded() able
95
+ // to see every module's claims (see guarded() docstring).
96
+ const owner = new Map<string, string>();
97
+ // Per-module config contribution factories, closed over THAT module's guarded
98
+ // pi (router's save re-registers its provider — a claim that must stay the
99
+ // router module's). The config module receives this map and calls the
100
+ // factories per /config open.
101
+ const configContribs = new Map<string, () => ModuleConfig>();
102
+ const deps: ModuleLoadDeps = { configContribs };
103
+ for (const m of MODULES) {
104
+ if (disabled.has(m.name)) continue;
105
+ const g = guarded(pi, m.name, owner);
106
+ if (m.config) configContribs.set(m.name, () => m.config!(g));
107
+ try {
108
+ m.load(g, deps);
109
+ } catch (err) {
110
+ console.error(`ceulen: module ${m.name} failed to load: ${err instanceof Error ? err.message : err}`);
111
+ }
112
+ }
113
+ }
@@ -0,0 +1,75 @@
1
+ // Bundle-level .env ingestion — trusted-gated. Shared by the bundle entry
2
+ // (which registers the session_start pass before every module, so
3
+ // session_start readers like router's ROUTER_BASE_URL see .env values) and by
4
+ // the usage module (which keeps an idempotent safety-net call in case the
5
+ // bundle entry is bypassed).
6
+
7
+ import fs from "node:fs";
8
+ import os from "node:os";
9
+ import path from "node:path";
10
+
11
+ /** Parse .env-style text into KEY→VALUE entries: `export ` prefix allowed,
12
+ * single/double quotes stripped, comment/blank/non-assignment lines ignored.
13
+ * No inline-comment stripping (a `#` in the value stays part of the value).
14
+ * Exported for tests. */
15
+ export function parseEnvText(text: string): Record<string, string> {
16
+ const out: Record<string, string> = {};
17
+ for (const line of text.split(/\r?\n/)) {
18
+ const m = line.match(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/);
19
+ if (!m) continue;
20
+ let v = m[2].trim();
21
+ if ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'"))) v = v.slice(1, -1);
22
+ out[m[1]] = v;
23
+ }
24
+ return out;
25
+ }
26
+
27
+ /** Read a .env-style file into entries; missing/unreadable → {} (optional). */
28
+ function readEnvFile(file: string): Record<string, string> {
29
+ try {
30
+ return parseEnvText(fs.readFileSync(file, "utf8"));
31
+ } catch {
32
+ return {}; // optional file
33
+ }
34
+ }
35
+
36
+ /** Keys injected at import from global env files. Trusted-project cwd files
37
+ * may still override these (the pre-gating cwd-first precedence); values from
38
+ * the real environment are never touched by either pass. */
39
+ const globalEnvFileKeys = new Set<string>();
40
+
41
+ /** Import-time pass: ONLY global/PI_CODING_AGENT_DIR env files. Cwd .env files
42
+ * are untrusted repo content — loading them here would let any repo inject
43
+ * ROUTER_MGMT_TOKEN, COMMAND_CODE_BASE_URL, etc. They load in session_start
44
+ * behind ctx.isProjectTrusted() instead (see loadCwdEnvFilesIfTrusted). */
45
+ function loadGlobalEnvFiles(): void {
46
+ const dirs = process.env.PI_CODING_AGENT_DIR
47
+ ? [process.env.PI_CODING_AGENT_DIR]
48
+ : [path.join(os.homedir(), ".pi", "agent"), path.join(os.homedir(), ".pi", "agents")];
49
+ for (const dir of dirs) {
50
+ for (const file of [path.join(dir, ".env.local"), path.join(dir, ".env")]) {
51
+ for (const [key, value] of Object.entries(readEnvFile(file))) {
52
+ if (process.env[key] === undefined) {
53
+ process.env[key] = value;
54
+ globalEnvFileKeys.add(key);
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ loadGlobalEnvFiles();
61
+
62
+ let cwdEnvLoaded = false;
63
+
64
+ /** session_start pass: ingest cwd .env.local/.env, but ONLY for trusted
65
+ * projects. Idempotent (first trusted session wins), first-wins per candidate
66
+ * order, and never overrides the real environment. */
67
+ export function loadCwdEnvFilesIfTrusted(ctx: { isProjectTrusted?: () => boolean }): void {
68
+ if (cwdEnvLoaded || ctx.isProjectTrusted?.() !== true) return;
69
+ cwdEnvLoaded = true;
70
+ for (const file of [path.resolve(process.cwd(), ".env.local"), path.resolve(process.cwd(), ".env")]) {
71
+ for (const [key, value] of Object.entries(readEnvFile(file))) {
72
+ if (process.env[key] === undefined || globalEnvFileKeys.has(key)) process.env[key] = value;
73
+ }
74
+ }
75
+ }