@pi-unipi/utility 0.2.8 → 0.2.9

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 (2) hide show
  1. package/README.md +70 -144
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,94 +1,68 @@
1
1
  # @pi-unipi/utility
2
2
 
3
- Comprehensive utility suite for the Pi coding agent part of the Unipi extension suite.
3
+ Environment info, diagnostics, cleanup, name badge, and diff rendering. The grab-bag package for maintaining your development environment and making tool output readable.
4
4
 
5
- ## Features
5
+ The diff rendering is the standout feature — Shiki-powered syntax-highlighted diffs for `write` and `edit` tool output. Side-by-side view for edits, unified view for writes, with color presets and auto-fallback on narrow terminals.
6
6
 
7
- ### Commands
7
+ ## Commands
8
8
 
9
9
  | Command | Description |
10
10
  |---------|-------------|
11
- | `/unipi:continue` | Continue agent without polluting context |
12
- | `/unipi:reload` | Explain how to reload extensions |
13
- | `/unipi:status` | Show status of all unipi modules |
14
- | `/unipi:cleanup` | Clean stale DBs, temp files, old sessions |
15
11
  | `/unipi:env` | Show environment info (Node, Pi, OS, paths) |
16
12
  | `/unipi:doctor` | Run diagnostics across all modules |
17
- | `/unipi:name-badge` | Toggle name badge overlay (shows session name) |
13
+ | `/unipi:status` | Show status of all unipi modules |
14
+ | `/unipi:cleanup` | Clean stale DBs, temp files, old sessions |
15
+ | `/unipi:reload` | Explain how to reload extensions |
16
+ | `/unipi:name-badge` | Toggle name badge overlay |
18
17
  | `/unipi:badge-gen` | Generate session name via LLM and enable badge |
19
- | `/unipi:util-settings` | **Unified settings** badge + diff rendering config |
20
- | `/unipi:badge-settings` | Settings overlay (deprecated alias for `/unipi:util-settings`) |
18
+ | `/unipi:util-settings` | Unified settings for badge and diff rendering |
21
19
 
22
- ### Tools
20
+ ### Examples
23
21
 
24
- | Tool | Description |
25
- |------|-------------|
26
- | `ctx_batch` | Atomic batch execution with rollback support |
27
- | `ctx_env` | Environment inspection for debugging |
28
- | `write` | Write file with **syntax-highlighted diff** (when diff enabled) |
29
- | `edit` | Edit file with **split/unified diff view** (when diff enabled) |
22
+ ```
23
+ /unipi:env # Show environment
24
+ /unipi:doctor # Run diagnostics
25
+ /unipi:cleanup # Clean stale files
26
+ /unipi:cleanup --dry-run # Preview what would be cleaned
27
+ /unipi:name-badge # Toggle the session name badge
28
+ /unipi:badge-gen # Generate a session name via LLM
29
+ ```
30
30
 
31
- ### Modules (Programmatic API)
31
+ ## Special Triggers
32
32
 
33
- | Module | Path | Description |
34
- |--------|------|-------------|
35
- | **ProcessLifecycle** | `lifecycle/process` | Parent PID polling, orphan detection, signal handlers, cleanup registry |
36
- | **cleanupStale** | `lifecycle/cleanup` | Stale DB/temp/session/cache cleanup with dry-run support |
37
- | **TTLCache** | `cache/ttl-cache` | Memory or SQLite-backed TTL cache with auto-expiration |
38
- | **AnalyticsCollector** | `analytics/collector` | Privacy-respecting event collection with daily rollup |
39
- | **runDiagnostics** | `diagnostics/engine` | Cross-module health checks with plugin architecture |
40
- | **detectCapabilities** | `display/capabilities` | Terminal feature detection (color, Nerd Font, unicode) |
41
- | **Width Utilities** | `display/width` | ANSI-aware clamp, wrap, collapse, pad, center |
42
- | **SettingsInspector** | `tui/settings-inspector` | Reusable settings overlay data model |
43
-
44
- ## Installation
45
-
46
- ```bash
47
- pi install npm:@pi-unipi/utility
48
- ```
33
+ Utility registers with the info-screen dashboard, showing module status and diagnostic results. The footer subscribes to utility events for its extension status segment.
49
34
 
50
- Or install the full Unipi suite:
35
+ The diff rendering feature wraps Pi's built-in `write` and `edit` tools. When enabled, these tools show syntax-highlighted diffs instead of plain output. This is a transparent replacement — the agent doesn't need to know about it.
51
36
 
52
- ```bash
53
- pi install npm:@pi-unipi/unipi
54
- ```
37
+ ## Agent Tools
55
38
 
56
- ## Usage
39
+ | Tool | Description |
40
+ |------|-------------|
41
+ | `ctx_batch` | Atomic batch execution with rollback support |
42
+ | `ctx_env` | Environment inspection for debugging |
43
+ | `write` | Write file with syntax-highlighted diff (when diff enabled) |
44
+ | `edit` | Edit file with split/unified diff view (when diff enabled) |
57
45
 
58
- ### Commands
46
+ ### Batch Execution
59
47
 
60
- ```
61
- /unipi:continue # Resume agent cleanly
62
- /unipi:cleanup # Clean stale files
63
- /unipi:cleanup --dry-run # Preview what would be cleaned
64
- /unipi:env # Show environment
65
- /unipi:doctor # Run diagnostics
66
- ```
48
+ ```typescript
49
+ import { BatchBuilder } from "@pi-unipi/utility/tools/batch";
67
50
 
68
- ### Name Badge
51
+ const report = await new BatchBuilder()
52
+ .addCommand("search", { query: "refactor" })
53
+ .addTool("memory_search", { query: "patterns" })
54
+ .withOptions({ failFast: true, commandTimeoutMs: 30000 })
55
+ .execute(myExecutor);
69
56
 
70
- ```
71
- /unipi:name-badge # Toggle the session name badge on/off
72
- /unipi:badge-gen # Generate a session name via LLM
57
+ if (!report.success) {
58
+ console.log("Failed:", report.results.find(r => !r.success)?.error);
59
+ }
73
60
  ```
74
61
 
75
- The badge is a persistent HUD overlay in the top-right corner showing the current session name.
76
- It auto-restores visibility on session restart.
62
+ ## Configurables
77
63
 
78
64
  ### Diff Rendering
79
65
 
80
- Shiki-powered, syntax-highlighted diffs for `write` and `edit` tool output. When enabled, the default tools are replaced with enhanced versions that show side-by-side or stacked diffs with syntax highlighting.
81
-
82
- **Features:**
83
- - Split view (side-by-side) for `edit` tool, auto-falls back to unified on narrow terminals
84
- - Unified view (stacked single-column) for `write` tool overwrites
85
- - 4 color presets: default, midnight, subtle, neon
86
- - LRU cache (192 entries) for Shiki highlights
87
- - Large diff fallback (skip highlighting above 80k chars)
88
- - Environment variable color overrides (`DIFF_ADD_BG`, `DIFF_REM_BG`, etc.)
89
-
90
- **Configuration:**
91
-
92
66
  ```
93
67
  /unipi:util-settings # Open unified settings TUI
94
68
  ```
@@ -106,26 +80,38 @@ Or edit `.unipi/config/util-settings.json` directly:
106
80
  }
107
81
  ```
108
82
 
109
- **Diff themes:** default, midnight, subtle, neon
110
- **Shiki themes:** github-dark, dracula, one-dark-pro, catppuccin-mocha, nord, tokyo-night, and more
83
+ | Setting | Default | Options |
84
+ |---------|---------|---------|
85
+ | `enabled` | true | true/false |
86
+ | `theme` | "default" | default, midnight, subtle, neon |
87
+ | `shikiTheme` | "github-dark" | github-dark, dracula, one-dark-pro, catppuccin-mocha, nord, tokyo-night |
88
+ | `splitMinWidth` | 150 | Minimum terminal width for split view |
111
89
 
112
- ### Batch Execution (Code)
90
+ Environment variable overrides: `DIFF_ADD_BG`, `DIFF_REM_BG`, etc.
113
91
 
114
- ```typescript
115
- import { BatchBuilder } from "@pi-unipi/utility/tools/batch";
92
+ Features:
93
+ - Split view (side-by-side) for `edit`, auto-falls back to unified on narrow terminals
94
+ - Unified view (stacked) for `write` overwrites
95
+ - LRU cache (192 entries) for Shiki highlights
96
+ - Large diff fallback (skip highlighting above 80k chars)
116
97
 
117
- const report = await new BatchBuilder()
118
- .addCommand("search", { query: "refactor" })
119
- .addTool("memory_search", { query: "patterns" })
120
- .withOptions({ failFast: true, commandTimeoutMs: 30000 })
121
- .execute(myExecutor);
98
+ ### Name Badge
122
99
 
123
- if (!report.success) {
124
- console.log("Failed:", report.results.find(r => !r.success)?.error);
125
- }
126
- ```
100
+ The badge is a persistent HUD overlay in the top-right corner showing the current session name. It auto-restores visibility on session restart.
101
+
102
+ ## Programmatic API
103
+
104
+ | Module | Path | Description |
105
+ |--------|------|-------------|
106
+ | ProcessLifecycle | `lifecycle/process` | Parent PID polling, orphan detection, signal handlers |
107
+ | cleanupStale | `lifecycle/cleanup` | Stale DB/temp/session/cache cleanup with dry-run |
108
+ | TTLCache | `cache/ttl-cache` | Memory or SQLite-backed TTL cache |
109
+ | AnalyticsCollector | `analytics/collector` | Privacy-respecting event collection with daily rollup |
110
+ | runDiagnostics | `diagnostics/engine` | Cross-module health checks with plugin architecture |
111
+ | detectCapabilities | `display/capabilities` | Terminal feature detection (color, Nerd Font, unicode) |
112
+ | Width Utilities | `display/width` | ANSI-aware clamp, wrap, collapse, pad, center |
127
113
 
128
- ### TTL Cache (Code)
114
+ ### TTL Cache
129
115
 
130
116
  ```typescript
131
117
  import { TTLCache } from "@pi-unipi/utility/cache/ttl-cache";
@@ -135,16 +121,7 @@ await cache.set("key", { data: "value" });
135
121
  const value = await cache.get("key");
136
122
  ```
137
123
 
138
- ### Diagnostics (Code)
139
-
140
- ```typescript
141
- import { runDiagnostics, formatDiagnosticsReport } from "@pi-unipi/utility/diagnostics/engine";
142
-
143
- const report = await runDiagnostics();
144
- console.log(formatDiagnosticsReport(report));
145
- ```
146
-
147
- ### Terminal Capabilities (Code)
124
+ ### Terminal Capabilities
148
125
 
149
126
  ```typescript
150
127
  import { detectCapabilities, getIcon } from "@pi-unipi/utility/display/capabilities";
@@ -154,64 +131,13 @@ console.log("Nerd Font:", caps.nerdFont);
154
131
  console.log(getIcon("󰘳", "[OK]")); // Uses Nerd Font if available
155
132
  ```
156
133
 
157
- ## Architecture
158
-
159
- ```
160
- packages/utility/src/
161
- ├── index.ts # Extension entry point
162
- ├── commands.ts # Command registration
163
- ├── types.ts # Shared types
164
- ├── info-screen.ts # Info-screen integration
165
- ├── lifecycle/
166
- │ ├── process.ts # Process lifecycle manager
167
- │ └── cleanup.ts # Stale cleanup utility
168
- ├── cache/
169
- │ └── ttl-cache.ts # TTL cache (memory + SQLite)
170
- ├── analytics/
171
- │ └── collector.ts # Event collection + rollup
172
- ├── diagnostics/
173
- │ └── engine.ts # Health check engine
174
- ├── display/
175
- │ ├── capabilities.ts # Terminal detection
176
- │ └── width.ts # Width utilities
177
- ├── diff/
178
- │ ├── settings.ts # Unified settings (badge + diff) read/write + migration
179
- │ ├── theme.ts # Diff color presets, resolution chain, hex ↔ ANSI
180
- │ ├── parser.ts # Diff parsing (structuredPatch, word diff analysis)
181
- │ ├── highlighter.ts # Shiki singleton, LRU cache, language detection
182
- │ ├── renderer.ts # Split/unified renderers, ANSI utilities
183
- │ └── wrapper.ts # write/edit tool wrapping with diff output
184
- ├── tui/
185
- │ ├── settings-inspector.ts # Settings overlay model
186
- │ ├── name-badge.ts # Name badge overlay component
187
- │ ├── name-badge-state.ts # Name badge state manager
188
- │ ├── badge-settings.ts # Badge settings (thin wrapper over diff/settings)
189
- │ └── util-settings-tui.ts # Unified settings TUI (badge + diff)
190
- └── tools/
191
- ├── batch.ts # Batch execution
192
- └── env.ts # Environment info
193
- ```
194
-
195
134
  ## Privacy
196
135
 
197
- The analytics collector is **privacy-respecting** by design:
198
- - No file contents are recorded
136
+ The analytics collector is privacy-respecting:
137
+ - No file contents recorded
199
138
  - No sensitive data (API keys, tokens, passwords) — redacted automatically
200
139
  - Strings truncated to 500 characters
201
- - All data stays local (in-memory by default, optional SQLite)
202
-
203
- ## Dependencies
204
-
205
- - `@pi-unipi/core` — Shared constants, events, utilities
206
- - `@mariozechner/pi-coding-agent` — Pi extension API
207
- - `@sinclair/typebox` — Schema validation (peer dependency)
208
- - `diff` — Unified diff generation (for diff rendering)
209
- - `@shikijs/cli` — Shiki syntax highlighting (for diff rendering)
210
- - `sqlite3` — Optional, for persistent cache/analytics
211
-
212
- ### Dev Dependencies
213
-
214
- - `@types/diff` — TypeScript types for the diff library
140
+ - All data stays local
215
141
 
216
142
  ## License
217
143
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/utility",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Utility commands and tools for Pi coding agent — lifecycle, diagnostics, cache, analytics, display, batch execution",
5
5
  "type": "module",
6
6
  "license": "MIT",