@pi-unipi/unipi 2.4.0 → 2.4.2

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 (99) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/package.json +26 -22
  3. package/packages/ask-user/package.json +2 -2
  4. package/packages/autocomplete/package.json +4 -2
  5. package/packages/btw/package.json +2 -2
  6. package/packages/cocoindex/package.json +2 -2
  7. package/packages/cocoindex/tools.ts +0 -8
  8. package/packages/compactor/README.md +18 -22
  9. package/packages/compactor/package.json +3 -3
  10. package/packages/compactor/src/compaction/auto-trigger.ts +0 -0
  11. package/packages/compactor/src/compaction/build-sections.ts +2 -2
  12. package/packages/compactor/src/compaction/format.ts +1 -1
  13. package/packages/compactor/src/config/presets.ts +19 -30
  14. package/packages/compactor/src/config/schema.ts +0 -0
  15. package/packages/compactor/src/index.ts +39 -56
  16. package/packages/compactor/src/session/resume-inject.ts +27 -0
  17. package/packages/compactor/src/tools/ctx-batch-execute.ts +4 -2
  18. package/packages/compactor/src/tools/ctx-execute-file.ts +4 -2
  19. package/packages/compactor/src/tools/ctx-execute.ts +4 -2
  20. package/packages/compactor/src/tools/register.ts +22 -4
  21. package/packages/compactor/src/tui/settings-overlay.ts +9 -22
  22. package/packages/compactor/src/types.ts +24 -2
  23. package/packages/core/events.ts +13 -13
  24. package/packages/core/package.json +3 -2
  25. package/packages/footer/README.md +2 -2
  26. package/packages/footer/package.json +3 -3
  27. package/packages/footer/src/events.ts +0 -10
  28. package/packages/footer/src/segments/core.ts +0 -9
  29. package/packages/image/package.json +2 -2
  30. package/packages/info-screen/core-groups.ts +0 -14
  31. package/packages/info-screen/package.json +2 -2
  32. package/packages/input-shortcuts/package.json +2 -2
  33. package/packages/kanboard/commands.ts +0 -1
  34. package/packages/kanboard/package.json +2 -2
  35. package/packages/mcp/package.json +2 -2
  36. package/packages/memory/package.json +3 -3
  37. package/packages/memory/storage.ts +0 -18
  38. package/packages/memory/tools.ts +0 -1
  39. package/packages/milestone/hooks.ts +9 -15
  40. package/packages/milestone/package.json +2 -2
  41. package/packages/notify/README.md +2 -0
  42. package/packages/notify/events.ts +23 -13
  43. package/packages/notify/package.json +2 -2
  44. package/packages/notify/tools.ts +17 -8
  45. package/packages/notify/types.ts +5 -1
  46. package/packages/ralph/index.ts +10 -5
  47. package/packages/ralph/package.json +3 -3
  48. package/packages/ralph/ralph-loop.ts +10 -0
  49. package/packages/subagents/README.md +3 -1
  50. package/packages/subagents/package.json +10 -6
  51. package/packages/subagents/src/agent-manager.ts +46 -11
  52. package/packages/subagents/src/core-compat.ts +38 -0
  53. package/packages/subagents/src/global.d.ts +7 -0
  54. package/packages/subagents/src/index.ts +6 -3
  55. package/packages/subagents/src/widget.ts +0 -7
  56. package/packages/unipi/bundled.js +371 -438
  57. package/packages/updater/package.json +4 -3
  58. package/packages/utility/README.md +1 -1
  59. package/packages/utility/package.json +7 -4
  60. package/packages/utility/src/commands.ts +2 -10
  61. package/packages/utility/src/diff/theme.ts +0 -3
  62. package/packages/utility/src/tui/name-badge.ts +0 -9
  63. package/packages/web-api/package.json +2 -2
  64. package/packages/web-api/src/engine/extract.ts +0 -26
  65. package/packages/web-api/src/tools.ts +0 -13
  66. package/packages/workflow/commands.ts +13 -1
  67. package/packages/workflow/index.ts +12 -1
  68. package/packages/workflow/lifecycle.ts +43 -0
  69. package/packages/workflow/package.json +3 -2
  70. package/packages/autocomplete/index.ts +0 -7
  71. package/packages/autocomplete/src/__tests__/command-registry.audit.test.ts +0 -120
  72. package/packages/autocomplete/src/__tests__/provider.sorting.test.ts +0 -423
  73. package/packages/compactor/src/compaction/recall-scope.ts +0 -32
  74. package/packages/compactor/src/compaction/sections.ts +0 -15
  75. package/packages/compactor/src/display/bash-display.ts +0 -28
  76. package/packages/compactor/src/display/diff-presentation.ts +0 -25
  77. package/packages/compactor/src/display/pending-diff-preview.ts +0 -51
  78. package/packages/compactor/src/display/user-message-box.ts +0 -16
  79. package/packages/compactor/src/session/analytics.ts +0 -205
  80. package/packages/image/index.ts +0 -1
  81. package/packages/input-shortcuts/index.ts +0 -5
  82. package/packages/input-shortcuts/src/status.ts +0 -35
  83. package/packages/kanboard/tui/kanboard-overlay.ts +0 -300
  84. package/packages/mcp/index.ts +0 -1
  85. package/packages/memory/search.ts +0 -134
  86. package/packages/milestone/coexist.ts +0 -114
  87. package/packages/notify/src/__tests__/ask-user-prompt-message.test.ts +0 -159
  88. package/packages/notify/src/__tests__/event-bus.test.ts +0 -119
  89. package/packages/notify/src/__tests__/permission-prompt-message.test.ts +0 -172
  90. package/packages/subagents/src/__tests__/badge-generation.test.ts +0 -315
  91. package/packages/subagents/src/__tests__/config.test.ts +0 -240
  92. package/packages/subagents/src/__tests__/esc-propagation.test.ts +0 -162
  93. package/packages/subagents/src/__tests__/file-lock.test.ts +0 -244
  94. package/packages/subagents/src/__tests__/shutdown-stale-ctx.test.ts +0 -185
  95. package/packages/subagents/src/__tests__/workflow-integration.test.ts +0 -334
  96. package/packages/subagents/src/prompts.ts +0 -39
  97. package/packages/utility/index.ts +0 -1
  98. package/packages/web-api/src/tui/progress.ts +0 -168
  99. package/packages/web-api/src/tui/result.ts +0 -173
package/CHANGELOG.md CHANGED
@@ -6,6 +6,49 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.4.2] — 2026-08-13
10
+
11
+ This release closes the unreachable-code and misleading-contract audit across runtime behavior, package artifacts, and integration events.
12
+
13
+ ### Added
14
+
15
+ - **Release contracts:** added package-entry, production-graph, all-tarball manifest, standalone Subagents import, and isolated Utility dependency checks.
16
+ - **Workflow lifecycle events:** workflow commands now emit one start/end pair around their agent run; Milestone synchronizes on completion while retaining shutdown fallback.
17
+ - **Compactor event delivery:** successful compactions now emit the documented completion event, and Ralph emits iteration completion only after a real advance.
18
+
19
+ ### Changed
20
+
21
+ - **Compactor configuration is now truthful.** Session continuity and sandbox off modes are enforced; language allowlists and output limits are active. Unsupported FTS5, display, and pipeline controls are hidden/deprecated rather than presented as working features.
22
+ - **Subagents honors type enablement.** JSON and custom-agent frontmatter disables are enforced before records or queue entries are created.
23
+ - **Notification priority is effective.** Explicit low/normal/high requests map to Gotify 2/5/8 and ntfy 2/3/5; omission preserves configured platform priorities.
24
+ - **Standalone Subagents ships built ESM.** The package now prebuilds verified `dist` JavaScript/declarations, publishes no tests or raw source, and exposes a standalone Pi extension entry.
25
+ - **Utility declares its real dependencies.** Direct Shiki usage is backed by `shiki`, and Pi TUI is declared as a host-shared peer.
26
+ - **Package roots and manifests were tightened.** Meaningful Footer/Updater barrels are canonical, redundant wrappers are gone, and root/workspace tarballs exclude tests while retaining every declared main.
27
+
28
+ ### Fixed
29
+
30
+ - **Compactor resume context reaches the model once.** The hidden one-shot snapshot no longer gets consumed and discarded, and the system prompt remains prefix-cache stable.
31
+ - **Compactor sandbox policy is enforced.** Disabled tools are not registered, disallowed languages are rejected, and configured output limits reach shared executors.
32
+ - **`/unipi:status` responds immediately and truthfully.** Removed the dead request broadcast and guaranteed 500 ms wait; the command now points to live info and diagnostics surfaces.
33
+ - **Footer event wiring no longer waits on stale stats events.** Live Compactor segments continue reading session state directly.
34
+ - **Standalone package resolution works in strict installs.** Subagents imports by package name, and Utility resolves Shiki and Pi TUI from its installed package root.
35
+
36
+ ### Removed
37
+
38
+ - Nine compiler-proven private declarations with no reads or callers.
39
+ - Fourteen source modules absent from the production graph, after preserving active `SectionData` and `RuntimeStats` type contracts.
40
+ - Permanently-zero Compactor indexed-byte accounting and unused package-root pass-through wrappers.
41
+
42
+ ### Known issue
43
+
44
+ - The rank-2 LLM summarization provider still returns placeholder text. Its resolution is intentionally deferred pending the broader Wigolo/web-fetch architecture decision.
45
+
46
+ ## [2.4.1] — 2026-08-13
47
+
48
+ ### Fixed
49
+
50
+ - **`ralph`: loop status no longer invalidates the DeepSeek prefix cache.** The `before_agent_start` hook appended `[RALPH LOOP - name - Iteration N]` to the system prompt on every turn; because the iteration number changes each turn, this mutated the request prefix on every turn of a Ralph loop, forcing a full DeepSeek prefix-cache miss (~60K tokens re-billed at uncached price) per turn. The loop status now rides a hidden tail message (`unipi-ralph-loop-reminder`) so the cacheable prefix (system prompt + prior history) stays byte-stable across turns. The model still sees the loop name, iteration, and instructions.
51
+
9
52
  ## [2.4.0] — 2026-08-09
10
53
 
11
54
  Image generation no longer requires an OpenRouter account, and `image_generate` can now edit an existing image.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/unipi",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "All-in-one extension suite for Pi coding agent",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -41,7 +41,11 @@
41
41
  "packages/*/SKILL.md",
42
42
  "packages/*/skills/**/*",
43
43
  "packages/*/README.md",
44
- "packages/unipi/bundled.js"
44
+ "packages/unipi/bundled.js",
45
+ "!packages/**/__tests__/**",
46
+ "!packages/**/tests/**",
47
+ "!packages/**/*.test.ts",
48
+ "!packages/**/*.spec.ts"
45
49
  ],
46
50
  "pi": {
47
51
  "extensions": [
@@ -71,26 +75,26 @@
71
75
  "typebox": "^1.1.38"
72
76
  },
73
77
  "dependencies": {
74
- "@pi-unipi/ask-user": "2.4.0",
75
- "@pi-unipi/btw": "2.4.0",
76
- "@pi-unipi/compactor": "2.4.0",
77
- "@pi-unipi/notify": "2.4.0",
78
- "@pi-unipi/command-enchantment": "2.4.0",
79
- "@pi-unipi/core": "2.4.0",
80
- "@pi-unipi/info-screen": "2.4.0",
81
- "@pi-unipi/mcp": "2.4.0",
82
- "@pi-unipi/memory": "2.4.0",
83
- "@pi-unipi/ralph": "2.4.0",
84
- "@pi-unipi/subagents": "2.4.0",
85
- "@pi-unipi/utility": "2.4.0",
86
- "@pi-unipi/milestone": "2.4.0",
87
- "@pi-unipi/kanboard": "2.4.0",
88
- "@pi-unipi/web-api": "2.4.0",
89
- "@pi-unipi/workflow": "2.4.0",
90
- "@pi-unipi/footer": "2.4.0",
91
- "@pi-unipi/updater": "2.4.0",
92
- "@pi-unipi/input-shortcuts": "2.4.0",
93
- "@pi-unipi/cocoindex": "2.4.0"
78
+ "@pi-unipi/ask-user": "2.4.1",
79
+ "@pi-unipi/btw": "2.4.1",
80
+ "@pi-unipi/compactor": "2.4.1",
81
+ "@pi-unipi/notify": "2.4.1",
82
+ "@pi-unipi/command-enchantment": "2.4.1",
83
+ "@pi-unipi/core": "2.4.1",
84
+ "@pi-unipi/info-screen": "2.4.1",
85
+ "@pi-unipi/mcp": "2.4.1",
86
+ "@pi-unipi/memory": "2.4.1",
87
+ "@pi-unipi/ralph": "2.4.2",
88
+ "@pi-unipi/subagents": "2.4.1",
89
+ "@pi-unipi/utility": "2.4.1",
90
+ "@pi-unipi/milestone": "2.4.1",
91
+ "@pi-unipi/kanboard": "2.4.1",
92
+ "@pi-unipi/web-api": "2.4.1",
93
+ "@pi-unipi/workflow": "2.4.1",
94
+ "@pi-unipi/footer": "2.4.1",
95
+ "@pi-unipi/updater": "2.4.1",
96
+ "@pi-unipi/input-shortcuts": "2.4.1",
97
+ "@pi-unipi/cocoindex": "2.4.1"
94
98
  },
95
99
  "devDependencies": {
96
100
  "@earendil-works/pi-agent-core": "^0.80.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/ask-user",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Structured user input tool for Pi coding agent — single-select, multi-select, freeform",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -40,7 +40,7 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@pi-unipi/core": "2.4.0"
43
+ "@pi-unipi/core": "2.4.1"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@earendil-works/pi-coding-agent": "^0.80.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/command-enchantment",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Enhanced TUI autocomplete for /unipi:* commands — colored, sorted, and grouped by package",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -24,7 +24,9 @@
24
24
  ],
25
25
  "files": [
26
26
  "src/**/*.ts",
27
- "README.md"
27
+ "README.md",
28
+ "!src/__tests__/**",
29
+ "!src/**/*.test.ts"
28
30
  ],
29
31
  "peerDependencies": {
30
32
  "@earendil-works/pi-coding-agent": "^0.80.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/btw",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "A pi extension for parallel side conversations with /unipi:btw — part of the Unipi suite",
5
5
  "type": "module",
6
6
  "main": "extensions/btw.ts",
@@ -37,7 +37,7 @@
37
37
  "@earendil-works/pi-tui": "^0.80.0"
38
38
  },
39
39
  "dependencies": {
40
- "@pi-unipi/core": "2.4.0"
40
+ "@pi-unipi/core": "2.4.1"
41
41
  },
42
42
  "pi": {
43
43
  "extensions": [],
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/cocoindex",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "CocoIndex integration for Pi — AST-aware content indexing, semantic vector search, and incremental pipeline management",
5
5
  "type": "module",
6
6
  "main": "index.ts",
@@ -25,7 +25,7 @@
25
25
  "typebox": "^1.1.38"
26
26
  },
27
27
  "dependencies": {
28
- "@pi-unipi/core": "2.4.0"
28
+ "@pi-unipi/core": "2.4.1"
29
29
  },
30
30
  "optionalDependencies": {
31
31
  "@lancedb/lancedb": "^0.21.0"
@@ -35,14 +35,6 @@ function textResult(text: string, details?: Record<string, unknown>): any {
35
35
  };
36
36
  }
37
37
 
38
- function jsonResult(data: unknown, label?: string): any {
39
- const text = label ? `${label}:\n${JSON.stringify(data, null, 2)}` : JSON.stringify(data, null, 2);
40
- return {
41
- content: [{ type: "text", text }],
42
- details: data as Record<string, unknown>,
43
- };
44
- }
45
-
46
38
  // ─────────────────────────────────────────────────────────
47
39
  // Registration
48
40
  // ─────────────────────────────────────────────────────────
@@ -72,14 +72,14 @@ Keyboard:
72
72
 
73
73
  ### Presets tab
74
74
 
75
- Presets are profiles that set strategies, pipeline switches, sandbox mode, and display mode.
75
+ Presets are profiles that set strategies, the implemented Auto Injection pipeline behavior, and sandbox mode.
76
76
 
77
77
  | Preset | Intended use | Important effects |
78
78
  |---|---|---|
79
- | `precise` | Code-heavy work, minimal waste | Full compaction sections, safe-only sandbox, opencode display, Pipeline: `ttlCache` + `mmapPragma` on. |
80
- | `balanced` | Daily/default profile | Compact transcript, balanced display, FTS mode auto, sandbox all, Pipeline: all six switches on. |
81
- | `thorough` | Debug/audit sessions | Full transcript, verbose display, sandbox all, Pipeline: all six switches on. |
82
- | `lean` | Quick fixes or short sessions | Brief/minimal compaction sections, no sandbox, no session continuity, Pipeline: all off. |
79
+ | `precise` | Code-heavy work, minimal waste | Full compaction sections, sandbox enabled, Auto Injection off. |
80
+ | `balanced` | Daily/default profile | Compact transcript, sandbox enabled, Auto Injection on. |
81
+ | `thorough` | Debug/audit sessions | Full transcript, sandbox enabled, Auto Injection on. |
82
+ | `lean` | Quick fixes or short sessions | Brief/minimal compaction sections, no sandbox, no session continuity, Auto Injection off. |
83
83
 
84
84
  The **Project Override** row controls where settings are saved:
85
85
 
@@ -99,11 +99,10 @@ These settings control what is extracted into compaction summaries or how relate
99
99
  | `Outstanding Context` | `full`, `critical-only`, `off` | Keeps blockers, TODOs, pending decisions, and follow-ups. |
100
100
  | `User Preferences` | `all`, `recent-only`, `off` | Preserves user preferences learned during the session. |
101
101
  | `Brief Transcript` | `full`, `compact`, `minimal`, `off` | Keeps a rolling recent transcript after the structured sections. |
102
- | `Session Continuity` | `full`, `essential-only`, `off` | Controls XML-style resume snapshots that help the next turn continue after compaction. |
103
- | `Sandbox Execution` | `all`, `safe-only`, `off` | Controls agent-facing sandbox availability/intent. Safe-only is intended for less risky execution. |
104
- | `Tool Display` | `opencode`, `balanced`, `verbose`, `custom` | Controls built-in tool output rendering style and diff display behavior. |
102
+ | `Session Continuity` | `full`, `off` | Controls XML-style resume snapshots. Off prevents snapshot creation and injection; Pi’s normal compaction summary still remains. |
103
+ | `Sandbox Execution` | `all`, `off` | Controls sandbox tool registration. Changes require a session reload. Allowed languages and output limit are enforced from config. |
105
104
 
106
- Config-only legacy field: `fts5Index` remains in the schema for compatibility, but project indexing has moved to `@pi-unipi/cocoindex`.
105
+ Config-only legacy field: `fts5Index` remains in the schema for compatibility, but project indexing has moved to `@pi-unipi/cocoindex`. It is hidden from Compactor settings and presets. Legacy `sessionContinuity.mode: "essential-only"`, `eventCategories`, and `sandboxExecution.mode: "safe-only"` values remain loadable; essential-only behaves as full and safe-only behaves as enabled/all until explicit filtering/security policies are designed. Legacy `toolDisplay` and `showTruncationHints` fields also remain loadable but are deprecated and ignored; their profile names were never mapped to runtime renderer modes. Narrow-terminal diff clamping remains active as independent safety behavior.
107
106
 
108
107
  ### Auto tab
109
108
 
@@ -133,20 +132,15 @@ Example config:
133
132
 
134
133
  ### Pipeline tab
135
134
 
136
- Pipeline switches are low-level feature flags used by presets and advanced users.
135
+ The Pipeline tab exposes only behavior implemented by the current runtime.
137
136
 
138
137
  | Setting | Preset behavior | Current effect |
139
138
  |---|---|---|
140
- | `TTL Cache` | On in `precise`, `balanced`, `thorough`; off in `lean` | Reserved/compatibility switch for cache behavior. Search has an internal cache, but this toggle is not currently required for it. |
141
- | `Auto Injection` | On in `balanced`, `thorough`; off in `precise`, `lean` | Active. Adds behavioral/session state to the resume snapshot after compaction. |
142
- | `MMap Pragma` | On in `precise`, `balanced`, `thorough`; off in `lean` | Reserved/compatibility switch for SQLite mmap tuning. |
143
- | `Proximity Reranking` | On in `balanced`, `thorough`; off in `precise`, `lean` | Reserved/compatibility switch for future recall/search ranking. |
144
- | `Timeline Sort` | On in `balanced`, `thorough`; off in `precise`, `lean` | Reserved/compatibility switch for future chronological recall sorting. |
145
- | `Progressive Throttling` | On in `balanced`, `thorough`; off in `precise`, `lean` | Reserved/compatibility switch for future large-project throttling. |
139
+ | `Auto Injection` | On in `balanced`, `thorough`; off in `precise`, `lean` | Adds behavioral/session state to the one-shot resume context after compaction. |
146
140
 
147
- If all Pipeline values stay `off` after choosing a preset, that means the running version is not applying preset pipeline values correctly. Choose a preset, press **Enter** to save, and verify you are on a version containing the preset pipeline fix.
141
+ Deprecated config-only compatibility fields are still accepted so existing files load without migration failures, but they are ignored and no longer controlled or advertised by presets: `ttlCache`, `mmapPragma`, `proximityReranking`, `timelineSort`, and `progressiveThrottling`.
148
142
 
149
- Config-only pipeline field:
143
+ Other config-only pipeline field:
150
144
 
151
145
  | Field | Meaning |
152
146
  |---|---|
@@ -289,10 +283,12 @@ Practical interpretation:
289
283
 
290
284
  That means preset application is not updating `config.pipeline`. The intended behavior is:
291
285
 
292
- - `precise`: `ttlCache` + `mmapPragma` on.
293
- - `balanced`: all six pipeline switches on.
294
- - `thorough`: all six pipeline switches on.
295
- - `lean`: all pipeline switches off.
286
+ - `precise`: Auto Injection off.
287
+ - `balanced`: Auto Injection on.
288
+ - `thorough`: Auto Injection on.
289
+ - `lean`: Auto Injection off.
290
+
291
+ The five deprecated compatibility fields remain off in every preset.
296
292
 
297
293
  Make sure you are running a version with the preset pipeline fix, select the preset, and press **Enter** to save.
298
294
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-unipi/compactor",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Context engine for Pi — zero-LLM compaction, session continuity, sandbox execution, and tool display optimization",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -34,8 +34,8 @@
34
34
  "access": "public"
35
35
  },
36
36
  "dependencies": {
37
- "@pi-unipi/core": "2.4.0",
38
- "@pi-unipi/info-screen": "2.4.0",
37
+ "@pi-unipi/core": "2.4.1",
38
+ "@pi-unipi/info-screen": "2.4.1",
39
39
  "@earendil-works/pi-agent-core": "^0.80.0"
40
40
  },
41
41
  "peerDependencies": {
File without changes
@@ -9,8 +9,8 @@ import { extractFiles } from "./extract/files.js";
9
9
  import { extractPreferences, dedupPreferencesAgainstGoals } from "./extract/preferences.js";
10
10
  import { extractCommits, formatCommits } from "./extract/commits.js";
11
11
  import { buildBriefSections, sectionsToTranscript, stringifyBrief } from "./brief.js";
12
- import type { SectionData } from "./sections.js";
13
- export type { SectionData } from "./sections.js";
12
+ import type { SectionData } from "../types.js";
13
+ export type { SectionData } from "../types.js";
14
14
 
15
15
  const BLOCKER_RE =
16
16
  /\b(fail(ed|s|ure|ing)?|broken|cannot|can't|won't work|does not work|doesn't work|still (broken|failing|wrong)|blocked|blocker|not (fixed|resolved|working)|crash(es|ed|ing)?)\b/i;
@@ -2,7 +2,7 @@
2
2
  * Stage 5: Format — Render sections with separators
3
3
  */
4
4
 
5
- import type { SectionData } from "./sections.js";
5
+ import type { SectionData } from "../types.js";
6
6
 
7
7
  const section = (title: string, items: string[]): string => {
8
8
  if (items.length === 0) return "";
@@ -12,13 +12,11 @@ const pipeline = (overrides: Partial<CompactorConfig["pipeline"]> = {}): Compact
12
12
  customNoisePatterns: [...(overrides.customNoisePatterns ?? DEFAULT_COMPACTOR_CONFIG.pipeline.customNoisePatterns)],
13
13
  });
14
14
 
15
- const pipelineAllOn = (): CompactorConfig["pipeline"] => pipeline({
16
- ttlCache: true,
15
+ // Auto Injection is the only preset-controlled pipeline feature with a runtime
16
+ // implementation. The other persisted fields are retained as ignored legacy
17
+ // compatibility data, but presets must not advertise or enable them.
18
+ const pipelineWithAutoInjection = (): CompactorConfig["pipeline"] => pipeline({
17
19
  autoInjection: true,
18
- proximityReranking: true,
19
- timelineSort: true,
20
- progressiveThrottling: true,
21
- mmapPragma: true,
22
20
  });
23
21
 
24
22
  const preset = (
@@ -33,30 +31,29 @@ const preset = (
33
31
  userPreferences: { ...DEFAULT_COMPACTOR_CONFIG.userPreferences, ...(overrides.userPreferences ?? {}) },
34
32
  briefTranscript: { ...DEFAULT_COMPACTOR_CONFIG.briefTranscript, ...(overrides.briefTranscript ?? {}) },
35
33
  sessionContinuity: { ...DEFAULT_COMPACTOR_CONFIG.sessionContinuity, ...(overrides.sessionContinuity ?? {}) },
36
- fts5Index: { ...DEFAULT_COMPACTOR_CONFIG.fts5Index, ...(overrides.fts5Index ?? {}) },
34
+ // Legacy compatibility data only; presets never advertise or alter it.
35
+ fts5Index: { ...DEFAULT_COMPACTOR_CONFIG.fts5Index },
37
36
  sandboxExecution: { ...DEFAULT_COMPACTOR_CONFIG.sandboxExecution, ...(overrides.sandboxExecution ?? {}) },
38
- toolDisplay: { ...DEFAULT_COMPACTOR_CONFIG.toolDisplay, ...(overrides.toolDisplay ?? {}) },
37
+ // Legacy compatibility data only; presets never advertise or alter it.
38
+ toolDisplay: { ...DEFAULT_COMPACTOR_CONFIG.toolDisplay },
39
39
  pipeline: pipeline(overrides.pipeline),
40
40
  autoCompaction: { ...DEFAULT_COMPACTOR_CONFIG.autoCompaction, ...(overrides.autoCompaction ?? {}) },
41
41
  });
42
42
 
43
- // Pipeline feature defaults per preset:
44
- // precise: ttlCache+mmap on, rest off
45
- // balanced: all on
46
- // thorough: all on
47
- // lean: all off
43
+ // Active pipeline behavior per preset:
44
+ // precise/lean: auto-injection off
45
+ // balanced/thorough: auto-injection on
46
+ // Reserved compatibility fields remain at their inert defaults in all presets.
48
47
 
49
48
  export const PRESET_CONFIGS: Record<CompactorPreset, CompactorConfig> = {
50
49
  // New preset names
51
50
  precise: preset({
52
- pipeline: pipeline({ ttlCache: true, mmapPragma: true }),
53
- sandboxExecution: { ...DEFAULT_COMPACTOR_CONFIG.sandboxExecution, mode: "safe-only" },
54
- toolDisplay: { ...DEFAULT_COMPACTOR_CONFIG.toolDisplay, mode: "opencode" },
51
+ pipeline: pipeline(),
52
+ sandboxExecution: { ...DEFAULT_COMPACTOR_CONFIG.sandboxExecution, mode: "all" },
55
53
  }),
56
54
  thorough: preset({
57
- pipeline: pipelineAllOn(),
55
+ pipeline: pipelineWithAutoInjection(),
58
56
  briefTranscript: { ...DEFAULT_COMPACTOR_CONFIG.briefTranscript, mode: "full" },
59
- toolDisplay: { ...DEFAULT_COMPACTOR_CONFIG.toolDisplay, mode: "verbose" },
60
57
  }),
61
58
  lean: preset({
62
59
  pipeline: pipeline(),
@@ -67,27 +64,21 @@ export const PRESET_CONFIGS: Record<CompactorPreset, CompactorConfig> = {
67
64
  userPreferences: { ...DEFAULT_COMPACTOR_CONFIG.userPreferences, enabled: false, mode: "off" },
68
65
  briefTranscript: { ...DEFAULT_COMPACTOR_CONFIG.briefTranscript, enabled: true, mode: "minimal" },
69
66
  sessionContinuity: { ...DEFAULT_COMPACTOR_CONFIG.sessionContinuity, enabled: false, mode: "off" },
70
- fts5Index: { ...DEFAULT_COMPACTOR_CONFIG.fts5Index, enabled: false, mode: "off" },
71
67
  sandboxExecution: { ...DEFAULT_COMPACTOR_CONFIG.sandboxExecution, enabled: false, mode: "off" },
72
- toolDisplay: { ...DEFAULT_COMPACTOR_CONFIG.toolDisplay, enabled: true, mode: "opencode" },
73
68
  }),
74
69
  balanced: preset({
75
- pipeline: pipelineAllOn(),
70
+ pipeline: pipelineWithAutoInjection(),
76
71
  briefTranscript: { ...DEFAULT_COMPACTOR_CONFIG.briefTranscript, mode: "compact" },
77
- toolDisplay: { ...DEFAULT_COMPACTOR_CONFIG.toolDisplay, mode: "balanced" },
78
- fts5Index: { ...DEFAULT_COMPACTOR_CONFIG.fts5Index, mode: "auto" },
79
72
  }),
80
73
 
81
74
  // Backward-compat aliases — map old names to new
82
75
  opencode: preset({
83
- pipeline: pipeline({ ttlCache: true, mmapPragma: true }),
84
- sandboxExecution: { ...DEFAULT_COMPACTOR_CONFIG.sandboxExecution, mode: "safe-only" },
85
- toolDisplay: { ...DEFAULT_COMPACTOR_CONFIG.toolDisplay, mode: "opencode" },
76
+ pipeline: pipeline(),
77
+ sandboxExecution: { ...DEFAULT_COMPACTOR_CONFIG.sandboxExecution, mode: "all" },
86
78
  }),
87
79
  verbose: preset({
88
- pipeline: pipelineAllOn(),
80
+ pipeline: pipelineWithAutoInjection(),
89
81
  briefTranscript: { ...DEFAULT_COMPACTOR_CONFIG.briefTranscript, mode: "full" },
90
- toolDisplay: { ...DEFAULT_COMPACTOR_CONFIG.toolDisplay, mode: "verbose" },
91
82
  }),
92
83
  minimal: preset({
93
84
  pipeline: pipeline(),
@@ -98,9 +89,7 @@ export const PRESET_CONFIGS: Record<CompactorPreset, CompactorConfig> = {
98
89
  userPreferences: { ...DEFAULT_COMPACTOR_CONFIG.userPreferences, enabled: false, mode: "off" },
99
90
  briefTranscript: { ...DEFAULT_COMPACTOR_CONFIG.briefTranscript, enabled: true, mode: "minimal" },
100
91
  sessionContinuity: { ...DEFAULT_COMPACTOR_CONFIG.sessionContinuity, enabled: false, mode: "off" },
101
- fts5Index: { ...DEFAULT_COMPACTOR_CONFIG.fts5Index, enabled: false, mode: "off" },
102
92
  sandboxExecution: { ...DEFAULT_COMPACTOR_CONFIG.sandboxExecution, enabled: false, mode: "off" },
103
- toolDisplay: { ...DEFAULT_COMPACTOR_CONFIG.toolDisplay, enabled: true, mode: "opencode" },
104
93
  }),
105
94
  custom: structuredClone(DEFAULT_COMPACTOR_CONFIG),
106
95
  };
File without changes
@@ -15,15 +15,14 @@ import {
15
15
  } from "./compaction/auto-trigger.js";
16
16
  import { SessionDB, getWorktreeSuffix } from "./session/db.js";
17
17
  import { extractEventsFromToolResult } from "./session/extract.js";
18
- import { injectResumeSnapshot } from "./session/resume-inject.js";
18
+ import { buildResumeContextMessage, isSessionContinuityEnabled } from "./session/resume-inject.js";
19
19
  import { PolyglotExecutor } from "./executor/executor.js";
20
20
  import { registerCommands } from "./commands/index.js";
21
21
  import { registerCompactorTools } from "./tools/register.js";
22
22
  import { normalizeMessages } from "./compaction/normalize.js";
23
23
  import { filterNoise } from "./compaction/filter-noise.js";
24
24
  import { recallBlocksFromContext } from "./session/recall-blocks.js";
25
- import type { NormalizedBlock, CompactorStrategyConfig, RuntimeCounters } from "./types.js";
26
- import type { RuntimeStats } from "./session/analytics.js";
25
+ import type { NormalizedBlock, CompactorStrategyConfig, RuntimeCounters, RuntimeStats } from "./types.js";
27
26
 
28
27
  /** Debug logger — only logs when config.debug === true */
29
28
  function createDebugLogger(getConfig: () => { debug: boolean }) {
@@ -63,11 +62,6 @@ function isSandboxTool(name: string): boolean {
63
62
  return name === "bash" || name === "Bash";
64
63
  }
65
64
 
66
- /** Check if a tool is an index tool (content goes to FTS5, not context). Future-proofing. */
67
- function isIndexTool(_name: string): boolean {
68
- return false;
69
- }
70
-
71
65
  export default function compactorExtension(pi: ExtensionAPI): void {
72
66
  let sessionDB: SessionDB | null = null;
73
67
  let executor: PolyglotExecutor | null = null;
@@ -86,7 +80,6 @@ export default function compactorExtension(pi: ExtensionAPI): void {
86
80
 
87
81
  const runtimeStats: RuntimeStats = {
88
82
  bytesReturned: {},
89
- bytesIndexed: 0,
90
83
  bytesSandboxed: 0,
91
84
  calls: {},
92
85
  sessionStart: Date.now(),
@@ -114,7 +107,7 @@ export default function compactorExtension(pi: ExtensionAPI): void {
114
107
  sessionDB = null;
115
108
  }
116
109
 
117
- executor = new PolyglotExecutor();
110
+ executor = null;
118
111
  };
119
112
 
120
113
  // Register compaction hooks with lazy deps — sessionDB/sessionId may not be
@@ -156,7 +149,6 @@ export default function compactorExtension(pi: ExtensionAPI): void {
156
149
 
157
150
  // Reset runtime stats for new session
158
151
  runtimeStats.bytesReturned = {};
159
- runtimeStats.bytesIndexed = 0;
160
152
  runtimeStats.bytesSandboxed = 0;
161
153
  runtimeStats.calls = {};
162
154
  runtimeStats.sessionStart = Date.now();
@@ -168,11 +160,19 @@ export default function compactorExtension(pi: ExtensionAPI): void {
168
160
 
169
161
  // Register all compactor tools with Pi (deps now have live sessionDB)
170
162
  if (sessionDB) {
163
+ const sandboxEnabled = config.sandboxExecution.enabled && config.sandboxExecution.mode !== "off";
164
+ executor = sandboxEnabled
165
+ ? new PolyglotExecutor({ hardCapBytes: config.sandboxExecution.outputLimit, projectRoot: projectDir })
166
+ : null;
171
167
  registerCompactorTools(pi, {
172
168
  sessionDB,
173
169
  getSessionId: () => currentSessionId,
174
170
  getBlocks: () => cachedBlocks,
175
171
  getCounters,
172
+ sandbox: executor ? {
173
+ executor,
174
+ allowedLanguages: config.sandboxExecution.allowedLanguages,
175
+ } : undefined,
176
176
  });
177
177
  }
178
178
 
@@ -277,25 +277,11 @@ export default function compactorExtension(pi: ExtensionAPI): void {
277
277
  // Non-fatal: recall will work on empty blocks
278
278
  }
279
279
 
280
- if (sessionDB) {
281
- const snapshot = await injectResumeSnapshot(sessionDB, currentSessionId);
282
- debug("resume_snapshot", { injected: !!snapshot });
283
-
284
- // Auto-injection on compact: inject behavioral state after compaction
285
- if (snapshot && sessionDB) {
286
- try {
287
- const { buildAutoInjection } = await import("./session/auto-inject.js");
288
- const events = sessionDB.getEvents(currentSessionId, { limit: 100 });
289
- const autoInjection = buildAutoInjection(events);
290
- if (autoInjection) {
291
- debug("auto_injection", { tokens: autoInjection.tokens, length: autoInjection.text.length });
292
- // Note: auto-injection is included in the resume snapshot context
293
- // The model receives it as part of the session state restoration
294
- }
295
- } catch (err) {
296
- debug("auto_injection_error", { error: String(err) });
297
- }
298
- }
280
+ const continuityEnabled = isSessionContinuityEnabled(config);
281
+ if (sessionDB && continuityEnabled) {
282
+ const resumeContext = await buildResumeContextMessage(sessionDB, currentSessionId);
283
+ debug("resume_snapshot", { injected: !!resumeContext });
284
+ return resumeContext;
299
285
  }
300
286
  });
301
287
 
@@ -358,7 +344,8 @@ export default function compactorExtension(pi: ExtensionAPI): void {
358
344
  });
359
345
 
360
346
  pi.on("session_before_compact", async (event, _ctx) => {
361
- if (sessionDB) {
347
+ const continuityEnabled = isSessionContinuityEnabled(config);
348
+ if (sessionDB && continuityEnabled) {
362
349
  // Use closure currentSessionId — Pi's session_before_compact event
363
350
  // does not include sessionId at the top level.
364
351
  const sessionId = currentSessionId;
@@ -386,14 +373,21 @@ export default function compactorExtension(pi: ExtensionAPI): void {
386
373
  const compactionEntry = (event as any).compactionEntry;
387
374
  const tokensBefore = compactionEntry?.tokensBefore ?? 0;
388
375
 
376
+ let summarized = 0;
377
+ let kept = 0;
378
+ let tokensSaved = 0;
379
+
389
380
  if (tokensBefore > 0) {
390
381
  // Use actual token count from Pi's compactionEntry.
391
382
  // Compaction typically keeps ~10-15% of original context.
392
383
  const charsBefore = tokensBefore * 4;
393
- const tokensAfter = (event as any).tokensAfter ?? Math.round(tokensBefore * 0.12);
384
+ const tokensAfter = Math.round(tokensBefore * 0.12);
385
+ kept = tokensAfter;
386
+ tokensSaved = tokensBefore - tokensAfter;
394
387
  const charsKept = tokensAfter * 4;
395
388
  const messagesSummarized = Math.max(1, Math.round(tokensBefore / 500));
396
- counters.totalTokensCompacted += tokensBefore - tokensAfter;
389
+ summarized = messagesSummarized;
390
+ counters.totalTokensCompacted += tokensSaved;
397
391
  sessionDB.addCompactionStats(sessionId, charsBefore, charsKept, messagesSummarized);
398
392
  } else {
399
393
  // tokensBefore unavailable — use session event count as a rough heuristic.
@@ -407,13 +401,24 @@ export default function compactorExtension(pi: ExtensionAPI): void {
407
401
  const estTokensAfter = Math.round(estTokensBefore * 0.12);
408
402
  const charsBefore = estTokensBefore * 4;
409
403
  const charsKept = estTokensAfter * 4;
410
- counters.totalTokensCompacted += estTokensBefore - estTokensAfter;
404
+ summarized = eventCount;
405
+ kept = estTokensAfter;
406
+ tokensSaved = estTokensBefore - estTokensAfter;
407
+ counters.totalTokensCompacted += tokensSaved;
411
408
  sessionDB.addCompactionStats(sessionId, charsBefore, charsKept, eventCount);
412
409
  }
413
410
  } catch {
414
411
  // Non-fatal: heuristic estimation failed
415
412
  }
416
413
  }
414
+ const totalEstimated = tokensSaved + kept;
415
+ emitEvent(pi, UNIPI_EVENTS.COMPACTOR_COMPACTED, {
416
+ sessionId,
417
+ summarized,
418
+ kept,
419
+ tokensSaved,
420
+ compressionRatio: kept > 0 ? `${Math.round(totalEstimated / kept)}:1` : "0:1",
421
+ });
417
422
  debug("session_compact", { sessionId, tokensBefore, hasCompactionEntry: !!compactionEntry });
418
423
  }
419
424
  });
@@ -531,34 +536,12 @@ export default function compactorExtension(pi: ExtensionAPI): void {
531
536
  if (isSandboxTool(tName)) {
532
537
  runtimeStats.bytesSandboxed += responseBytes;
533
538
  }
534
- if (isIndexTool(tName)) {
535
- runtimeStats.bytesIndexed += responseBytes;
536
- }
537
539
  }
538
540
  } catch {
539
541
  // Non-blocking: byte tracking errors silently skipped
540
542
  }
541
543
 
542
- // Apply display overrides for built-in tools
543
544
  const toolName = (event as any).toolName ?? "";
544
- const td = config.toolDisplay;
545
- const toolConfig = {
546
- readOutputMode: td?.mode as any,
547
- searchOutputMode: td?.mode as any,
548
- bashOutputMode: td?.mode as any,
549
- previewLines: 20,
550
- bashCollapsedLines: 5,
551
- showTruncationHints: true,
552
- };
553
- try {
554
- const { applyToolDisplayOverride } = await import("./display/tool-overrides.js");
555
- const override = applyToolDisplayOverride(toolName, event as any, toolConfig);
556
- if (override !== undefined) {
557
- return override as any;
558
- }
559
- } catch {
560
- // Non-fatal: display override failed
561
- }
562
545
 
563
546
  // Width-safe diff truncation for edit/write tool results.
564
547
  // Pi's renderDiff() does not truncate lines to terminal width,