@pi-unipi/compactor 0.1.6 → 0.2.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.
- package/README.md +50 -24
- package/index.ts +7 -0
- package/package.json +2 -1
- package/skills/compactor/SKILL.md +21 -65
- package/skills/compactor-detail/SKILL.md +133 -0
- package/src/commands/index.ts +186 -109
- package/src/compaction/filter-noise.ts +4 -3
- package/src/compaction/hooks.ts +22 -1
- package/src/compaction/search-entries.ts +51 -4
- package/src/config/manager.ts +55 -6
- package/src/config/presets.ts +69 -5
- package/src/config/schema.ts +9 -0
- package/src/index.ts +183 -10
- package/src/info-screen.ts +10 -4
- package/src/security/policy.ts +23 -0
- package/src/session/auto-inject.ts +60 -0
- package/src/session/db.ts +70 -9
- package/src/session/resume-inject.ts +13 -1
- package/src/store/db-base.ts +11 -0
- package/src/store/index.ts +150 -4
- package/src/store/unified.ts +109 -0
- package/src/tools/context-budget.ts +50 -0
- package/src/tools/ctx-batch-execute.ts +2 -5
- package/src/tools/ctx-fetch-and-index.ts +3 -8
- package/src/tools/ctx-index.ts +3 -9
- package/src/tools/ctx-search.ts +3 -7
- package/src/tools/ctx-stats.ts +6 -4
- package/src/tools/register.ts +251 -216
- package/src/tui/settings-overlay.ts +359 -149
- package/src/types.ts +25 -1
- package/skills/compactor-ops/SKILL.md +0 -65
- package/skills/compactor-tools/SKILL.md +0 -120
package/README.md
CHANGED
|
@@ -15,45 +15,71 @@ Context engine for Pi coding agent. Fuses zero-LLM compaction, session continuit
|
|
|
15
15
|
| Command | Description |
|
|
16
16
|
|---------|-------------|
|
|
17
17
|
| `/unipi:compact` | Manual compaction with stats |
|
|
18
|
-
| `/unipi:
|
|
18
|
+
| `/unipi:session-recall` | Search session history (BM25 or regex) |
|
|
19
|
+
| `/unipi:content-index` | Index current project into FTS5 |
|
|
20
|
+
| `/unipi:content-search` | Search indexed content |
|
|
21
|
+
| `/unipi:content-purge` | Wipe all indexed content |
|
|
19
22
|
| `/unipi:compact-stats` | Context savings dashboard |
|
|
20
23
|
| `/unipi:compact-doctor` | Run diagnostics |
|
|
21
24
|
| `/unipi:compact-settings` | TUI settings overlay |
|
|
22
25
|
| `/unipi:compact-preset <name>` | Apply quick preset |
|
|
23
|
-
| `/unipi:compact-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
|
30
|
-
|
|
31
|
-
| `
|
|
32
|
-
| `
|
|
33
|
-
| `
|
|
34
|
-
| `
|
|
35
|
-
| `
|
|
36
|
-
| `
|
|
37
|
-
| `
|
|
38
|
-
| `
|
|
39
|
-
| `
|
|
40
|
-
|
|
26
|
+
| `/unipi:compact-help` | Show detailed documentation |
|
|
27
|
+
|
|
28
|
+
## Agent Tools
|
|
29
|
+
|
|
30
|
+
| Tool | Family | Description |
|
|
31
|
+
|------|--------|-------------|
|
|
32
|
+
| `compact` | compaction | Trigger manual compaction (dryRun: true to preview) |
|
|
33
|
+
| `session_recall` | session | BM25 session history search |
|
|
34
|
+
| `sandbox` | sandbox | Run code in sandbox (11 languages) |
|
|
35
|
+
| `sandbox_file` | sandbox | Execute file via FILE_CONTENT |
|
|
36
|
+
| `sandbox_batch` | sandbox | Atomic batch of commands + searches |
|
|
37
|
+
| `content_index` | content | Chunk content → FTS5 index |
|
|
38
|
+
| `content_search` | content | Query indexed content |
|
|
39
|
+
| `content_fetch` | content | Fetch URL → index |
|
|
40
|
+
| `compactor_stats` | compactor | Context savings dashboard |
|
|
41
|
+
| `compactor_doctor` | compactor | Diagnostics checklist |
|
|
42
|
+
| `context_budget` | compactor | Estimate remaining context window |
|
|
43
|
+
|
|
44
|
+
## Two-Tier Skills
|
|
45
|
+
|
|
46
|
+
- **Tier 1** (`compactor`): ~175 tokens, always loaded. Routing + critical rules + Ralph awareness.
|
|
47
|
+
- **Tier 2** (`compactor-detail`): On-demand. Full tool reference, anti-patterns, sandbox languages, FTS5 modes, workflows.
|
|
41
48
|
|
|
42
49
|
## Configuration
|
|
43
50
|
|
|
44
|
-
Config lives at `~/.unipi/config/compactor/config.json`.
|
|
51
|
+
Config lives at `~/.unipi/config/compactor/config.json`. Per-project overrides at `<project>/.unipi/config/compactor.json`.
|
|
45
52
|
|
|
46
53
|
### Presets
|
|
47
54
|
|
|
48
55
|
| Preset | Description |
|
|
49
56
|
|--------|-------------|
|
|
50
|
-
| `
|
|
51
|
-
| `balanced` |
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
57
|
+
| `precise` | Code-heavy, minimal waste — compaction: full, pipeline: 2/6 on |
|
|
58
|
+
| `balanced` | Daily use (default) — all strategies moderate, pipeline: all on |
|
|
59
|
+
| `thorough` | Debug/audit — everything on, full transcript |
|
|
60
|
+
| `lean` | Quick fixes — compaction only, pipeline: all off |
|
|
54
61
|
|
|
55
62
|
Apply via `/unipi:compact-preset <name>`.
|
|
56
63
|
|
|
64
|
+
### Pipeline Features
|
|
65
|
+
|
|
66
|
+
| Feature | Description | Context |
|
|
67
|
+
|---------|-------------|---------|
|
|
68
|
+
| TTL Cache | Cache with time-based expiry | On Compaction |
|
|
69
|
+
| Auto Injection | Inject behavioral state after compaction | On Compaction |
|
|
70
|
+
| MMap Pragma | Use mmap for SQLite I/O | On Compaction |
|
|
71
|
+
| Proximity Reranking | Rerank search results by proximity | On Search |
|
|
72
|
+
| Timeline Sort | Sort session events chronologically | On Search |
|
|
73
|
+
| Progressive Throttling | Slow down indexing for large projects | On Index |
|
|
74
|
+
|
|
75
|
+
### TUI
|
|
76
|
+
|
|
77
|
+
Tabbed settings interface (Presets / Strategies / Pipeline):
|
|
78
|
+
- `/` key opens search filter in Strategies tab
|
|
79
|
+
- Preset selection shows 3-line preview
|
|
80
|
+
- Per-project override checkbox (`o` key)
|
|
81
|
+
- Keyboard: `←→` cycle modes, `Space` toggle, `s` save, `Esc` cancel
|
|
82
|
+
|
|
57
83
|
## Architecture
|
|
58
84
|
|
|
59
85
|
```
|
package/index.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-unipi/compactor",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Context engine for Pi — zero-LLM compaction, session continuity, sandbox execution, FTS5 search, and tool display optimization",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"fts5"
|
|
22
22
|
],
|
|
23
23
|
"files": [
|
|
24
|
+
"index.ts",
|
|
24
25
|
"src/**/*.ts",
|
|
25
26
|
"skills/**/*",
|
|
26
27
|
"README.md"
|
|
@@ -1,74 +1,30 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: compactor
|
|
3
|
-
description:
|
|
3
|
+
description: Context management — compact session, recall history, run code, search content.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Compactor
|
|
6
|
+
# Compactor — Context Management
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## When Context Is Tight
|
|
9
|
+
- `context_budget` → check % full. `compact` → free tokens (zero-LLM, 98%+ reduction).
|
|
10
|
+
Compact BEFORE complex work. `compact(dryRun: true)` to preview without compacting.
|
|
11
|
+
- `compactor_stats` → check savings. `compactor_doctor` → diagnose.
|
|
9
12
|
|
|
10
|
-
##
|
|
13
|
+
## Finding Past Work
|
|
14
|
+
- `session_recall(query)` → search this session (BM25 or regex).
|
|
15
|
+
- `content_search(query)` → search indexed files/docs.
|
|
16
|
+
→ Index first: `content_index` or `content_fetch(url)`.
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
│ └── /unipi:compact or `compact` tool
|
|
16
|
-
│
|
|
17
|
-
├── Find something from earlier in the session
|
|
18
|
-
│ └── /unipi:compact-recall <query> or `vcc_recall` tool
|
|
19
|
-
│
|
|
20
|
-
├── Run code safely
|
|
21
|
-
│ └── `ctx_execute` tool (single) or `ctx_batch_execute` (batch)
|
|
22
|
-
│
|
|
23
|
-
├── Index project files for search
|
|
24
|
-
│ └── /unipi:compact-index or `ctx_index` tool
|
|
25
|
-
│
|
|
26
|
-
├── Search indexed content
|
|
27
|
-
│ └── /unipi:compact-search <query> or `ctx_search` tool
|
|
28
|
-
│
|
|
29
|
-
├── Fetch and index a URL
|
|
30
|
-
│ └── `ctx_fetch_and_index` tool
|
|
31
|
-
│
|
|
32
|
-
├── View compactor stats
|
|
33
|
-
│ └── /unipi:compact-stats or `ctx_stats` tool
|
|
34
|
-
│
|
|
35
|
-
├── Diagnose issues
|
|
36
|
-
│ └── /unipi:compact-doctor or `ctx_doctor` tool
|
|
37
|
-
│
|
|
38
|
-
├── Change settings
|
|
39
|
-
│ └── /unipi:compact-settings (TUI overlay)
|
|
40
|
-
│ └── /unipi:compact-preset <name> (quick preset)
|
|
41
|
-
│
|
|
42
|
-
└── Wipe indexed content
|
|
43
|
-
└── /unipi:compact-purge
|
|
44
|
-
```
|
|
18
|
+
## Running Code
|
|
19
|
+
- `sandbox(lang, code)` → single script. `sandbox_batch(items)` → atomic.
|
|
20
|
+
`sandbox_file(lang, path)` → run file. Only stdout enters context.
|
|
45
21
|
|
|
46
|
-
##
|
|
22
|
+
## Complex Multi-Step Tasks
|
|
23
|
+
⚠ When the task spans many operations, PREFER Ralph loops
|
|
24
|
+
(`/unipi:work`, `ralph_start`) if available — they manage
|
|
25
|
+
context pressure better than monolithic runs.
|
|
47
26
|
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
|
|
53
|
-
## When to Recall
|
|
54
|
-
|
|
55
|
-
- User references something from earlier
|
|
56
|
-
- Need to find a file path mentioned before
|
|
57
|
-
- Looking for a previous error or decision
|
|
58
|
-
- Searching for a specific code snippet
|
|
59
|
-
|
|
60
|
-
## When to Index
|
|
61
|
-
|
|
62
|
-
- Starting work on a large codebase
|
|
63
|
-
- Need fast search across many files
|
|
64
|
-
- Documentation or reference material
|
|
65
|
-
- Before a research-heavy task
|
|
66
|
-
|
|
67
|
-
## Presets
|
|
68
|
-
|
|
69
|
-
| Preset | Best For |
|
|
70
|
-
|--------|----------|
|
|
71
|
-
| `opencode` | Code-heavy work, minimal context waste |
|
|
72
|
-
| `balanced` | General use, good defaults |
|
|
73
|
-
| `verbose` | Maximum context preservation |
|
|
74
|
-
| `minimal` | Maximum token savings |
|
|
27
|
+
## Critical Rules
|
|
28
|
+
- Compact BEFORE starting, not when full.
|
|
29
|
+
- `session_recall` instead of scrolling history.
|
|
30
|
+
- Index project files early if you'll search often.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: compactor-detail
|
|
3
|
+
description: Full compactor reference — tool parameters, anti-patterns, sandbox languages, FTS5 modes, workflows.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Compactor — Full Reference
|
|
7
|
+
|
|
8
|
+
## Tool Parameter Reference
|
|
9
|
+
|
|
10
|
+
### compact
|
|
11
|
+
```
|
|
12
|
+
compact()
|
|
13
|
+
```
|
|
14
|
+
Trigger manual context compaction. Zero LLM — pure regex/text processing.
|
|
15
|
+
Returns stats after next `session_compact` event.
|
|
16
|
+
|
|
17
|
+
### session_recall
|
|
18
|
+
```
|
|
19
|
+
session_recall(query: string, mode?: "bm25" | "regex", limit?: number, offset?: number, expand?: boolean)
|
|
20
|
+
```
|
|
21
|
+
Search session history. BM25 is default (TF-IDF ranked). Regex is fallback.
|
|
22
|
+
|
|
23
|
+
### sandbox
|
|
24
|
+
```
|
|
25
|
+
sandbox(language: string, code: string, timeout?: number)
|
|
26
|
+
```
|
|
27
|
+
Run code in sandboxed env. Only stdout enters context. 100MB output cap. 30s default timeout.
|
|
28
|
+
|
|
29
|
+
### sandbox_file
|
|
30
|
+
```
|
|
31
|
+
sandbox_file(language: string, path: string, timeout?: number)
|
|
32
|
+
```
|
|
33
|
+
Execute file. Content injected as `FILE_CONTENT` variable.
|
|
34
|
+
|
|
35
|
+
### sandbox_batch
|
|
36
|
+
```
|
|
37
|
+
sandbox_batch(items: Array<{type: "execute", language, code} | {type: "search", query}>)
|
|
38
|
+
```
|
|
39
|
+
Atomic batch — all items run, results returned together.
|
|
40
|
+
|
|
41
|
+
### content_index
|
|
42
|
+
```
|
|
43
|
+
content_index(label: string, content?: string, filePath?: string, contentType?: "markdown"|"json"|"plain", chunkSize?: number)
|
|
44
|
+
```
|
|
45
|
+
Index content into FTS5. Provide either `content` or `filePath`. Auto-chunks by type.
|
|
46
|
+
|
|
47
|
+
### content_search
|
|
48
|
+
```
|
|
49
|
+
content_search(query: string, limit?: number, offset?: number)
|
|
50
|
+
```
|
|
51
|
+
Search FTS5 index. Returns ranked results with title, content, source, rank.
|
|
52
|
+
|
|
53
|
+
### content_fetch
|
|
54
|
+
```
|
|
55
|
+
content_fetch(url: string, label?: string, chunkSize?: number)
|
|
56
|
+
```
|
|
57
|
+
Fetch URL → markdown → index. Auto-indexes for later search.
|
|
58
|
+
|
|
59
|
+
### compactor_stats
|
|
60
|
+
```
|
|
61
|
+
compactor_stats()
|
|
62
|
+
```
|
|
63
|
+
Dashboard: session events, compactions, tokens saved, indexed docs, sandbox runs, search queries.
|
|
64
|
+
|
|
65
|
+
### compactor_doctor
|
|
66
|
+
```
|
|
67
|
+
compactor_doctor()
|
|
68
|
+
```
|
|
69
|
+
Diagnostics: config file, session DB, content store, runtimes (node, python3, bash).
|
|
70
|
+
|
|
71
|
+
### context_budget
|
|
72
|
+
```
|
|
73
|
+
context_budget()
|
|
74
|
+
```
|
|
75
|
+
Estimate remaining context tokens and % full. Returns guidance on whether to compact.
|
|
76
|
+
|
|
77
|
+
## Sandbox Language Reference
|
|
78
|
+
|
|
79
|
+
| Language | Binaries | Timeout | Notes |
|
|
80
|
+
|----------|----------|---------|-------|
|
|
81
|
+
| javascript | Bun/node | 30s | Default: Bun if available |
|
|
82
|
+
| typescript | Bun/node | 30s | Compiled via Bun transform |
|
|
83
|
+
| python | python3 | 30s | - |
|
|
84
|
+
| shell | bash | 30s | Pipelines supported |
|
|
85
|
+
| ruby | ruby | 30s | - |
|
|
86
|
+
| go | go | 30s | go run |
|
|
87
|
+
| rust | rustc+cargo | 30s | cargo script or rustc |
|
|
88
|
+
| php | php | 30s | - |
|
|
89
|
+
| perl | perl | 30s | - |
|
|
90
|
+
| r | Rscript | 30s | - |
|
|
91
|
+
| elixir | elixir | 30s | - |
|
|
92
|
+
|
|
93
|
+
## FTS5 Search Modes
|
|
94
|
+
|
|
95
|
+
| Mode | When To Use |
|
|
96
|
+
|------|-------------|
|
|
97
|
+
| **porter** | Exact term matching with stemming |
|
|
98
|
+
| **trigram** | Fuzzy/spelling errors, partial matches |
|
|
99
|
+
| **rrf** | Best overall (Reciprocal Rank Fusion of porter+trigram) |
|
|
100
|
+
| **fuzzy** | Auto-correction of misspellings from vocabulary |
|
|
101
|
+
|
|
102
|
+
Default: `rrf` (best general-purpose).
|
|
103
|
+
|
|
104
|
+
## Anti-Patterns
|
|
105
|
+
|
|
106
|
+
1. **Don't call `compact` in a tight loop.** It triggers the full compaction pipeline. Call once before complex work.
|
|
107
|
+
2. **Don't search without indexing.** `content_search` has nothing to search until you `content_index` or `content_fetch`.
|
|
108
|
+
3. **Don't use `sandbox` for file ops.** Use bash instead. Sandbox is for computation.
|
|
109
|
+
4. **Don't use `session_recall` with empty query.** It needs meaningful search terms.
|
|
110
|
+
5. **Don't index node_modules.** Stick to source files and documentation.
|
|
111
|
+
6. **Don't compact mid-task.** Wait for a natural break point.
|
|
112
|
+
|
|
113
|
+
## Workflow Patterns
|
|
114
|
+
|
|
115
|
+
### Research → Index → Search → Test
|
|
116
|
+
1. `content_fetch(url)` — index reference docs
|
|
117
|
+
2. `content_search(query)` — find relevant sections
|
|
118
|
+
3. `sandbox(lang, code)` — test hypotheses
|
|
119
|
+
|
|
120
|
+
### Diagnose → Fix → Verify
|
|
121
|
+
1. `compactor_doctor` — check system health
|
|
122
|
+
2. Fix issues (install runtimes, rebuild index)
|
|
123
|
+
3. `compactor_stats` — verify metrics
|
|
124
|
+
|
|
125
|
+
### Before Complex Work
|
|
126
|
+
1. `compact` — free up context
|
|
127
|
+
2. `content_index` — index relevant files
|
|
128
|
+
3. `session_recall("goals")` — load context
|
|
129
|
+
|
|
130
|
+
### After Long Session
|
|
131
|
+
1. `compactor_stats` — check savings
|
|
132
|
+
2. `compact` — compact if needed
|
|
133
|
+
3. `session_recall(topic)` — verify recall quality
|