@astralyn/pi 1.4.0 → 1.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 (67) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/bundle/chunks/{chunk-BMTEURL3.js → chunk-FGPSYHTQ.js} +72 -11
  3. package/dist/bundle/chunks/{chunk-TJIPCBZF.js → chunk-HXKY52DF.js} +1 -1
  4. package/dist/bundle/chunks/{virtual-modules-3CTTTQQN.js → virtual-modules-5NSVVTKO.js} +1 -1
  5. package/dist/bundle/cli.js +1 -1
  6. package/dist/bundle/index.js +1 -1
  7. package/dist/bundle/rpc-entry.js +1 -1
  8. package/dist/core/compaction/compaction.d.ts.map +1 -1
  9. package/dist/core/compaction/compaction.js +5 -5
  10. package/dist/core/compaction/compaction.js.map +1 -1
  11. package/dist/core/extensions/index.d.ts +1 -1
  12. package/dist/core/extensions/index.d.ts.map +1 -1
  13. package/dist/core/extensions/index.js.map +1 -1
  14. package/dist/core/extensions/types.d.ts +25 -1
  15. package/dist/core/extensions/types.d.ts.map +1 -1
  16. package/dist/core/extensions/types.js.map +1 -1
  17. package/dist/extensions/cached-compaction/index.d.ts +3 -0
  18. package/dist/extensions/cached-compaction/index.d.ts.map +1 -0
  19. package/dist/extensions/cached-compaction/index.js +91 -0
  20. package/dist/extensions/cached-compaction/index.js.map +1 -0
  21. package/dist/extensions/cached-compaction/render.d.ts +11 -0
  22. package/dist/extensions/cached-compaction/render.d.ts.map +1 -0
  23. package/dist/extensions/cached-compaction/render.js +19 -0
  24. package/dist/extensions/cached-compaction/render.js.map +1 -0
  25. package/dist/extensions/cached-compaction/summary.d.ts +15 -0
  26. package/dist/extensions/cached-compaction/summary.d.ts.map +1 -0
  27. package/dist/extensions/cached-compaction/summary.js +131 -0
  28. package/dist/extensions/cached-compaction/summary.js.map +1 -0
  29. package/dist/extensions/index.d.ts.map +1 -1
  30. package/dist/extensions/index.js +4 -0
  31. package/dist/extensions/index.js.map +1 -1
  32. package/dist/extensions/tool-presentation/index.d.ts +7 -0
  33. package/dist/extensions/tool-presentation/index.d.ts.map +1 -0
  34. package/dist/extensions/tool-presentation/index.js +9 -0
  35. package/dist/extensions/tool-presentation/index.js.map +1 -0
  36. package/dist/index.d.ts +1 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/modes/interactive/components/index.d.ts +1 -1
  40. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  41. package/dist/modes/interactive/components/index.js +1 -1
  42. package/dist/modes/interactive/components/index.js.map +1 -1
  43. package/dist/modes/interactive/components/tool-execution.d.ts +85 -0
  44. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  45. package/dist/modes/interactive/components/tool-execution.js +362 -0
  46. package/dist/modes/interactive/components/tool-execution.js.map +1 -0
  47. package/dist/modes/interactive/interactive-mode.js +1 -1
  48. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  49. package/dist/modes/interactive/tool-view/chat.d.ts +1 -1
  50. package/dist/modes/interactive/tool-view/chat.d.ts.map +1 -1
  51. package/dist/modes/interactive/tool-view/chat.js +2 -3
  52. package/dist/modes/interactive/tool-view/chat.js.map +1 -1
  53. package/dist/modes/interactive/tool-view/shell.d.ts +15 -0
  54. package/dist/modes/interactive/tool-view/shell.d.ts.map +1 -0
  55. package/dist/modes/interactive/tool-view/shell.js +51 -0
  56. package/dist/modes/interactive/tool-view/shell.js.map +1 -0
  57. package/dist/modes/interactive/tool-view/tool-execution.d.ts +10 -79
  58. package/dist/modes/interactive/tool-view/tool-execution.d.ts.map +1 -1
  59. package/dist/modes/interactive/tool-view/tool-execution.js +7 -298
  60. package/dist/modes/interactive/tool-view/tool-execution.js.map +1 -1
  61. package/docs/bundled/extensions/cached-compaction.md +35 -0
  62. package/docs/bundled/tool-presentation.md +9 -7
  63. package/docs/compaction.md +1 -1
  64. package/docs/docs.json +4 -0
  65. package/docs/extensions.md +3 -1
  66. package/npm-shrinkwrap.json +2 -2
  67. package/package.json +1 -1
@@ -0,0 +1,35 @@
1
+ # Cached compaction
2
+
3
+ The bundled `cached-compaction` extension replaces summary generation for manual `/compact` and automatic threshold compaction. Pi still owns the cut point, session persistence, recent-message retention, and context rebuilding.
4
+
5
+ Instead of flattening the older messages into a new summarizer prompt and truncating each tool result, the extension sends the current prepared conversation plus one user message asking for a structured checkpoint. This lets the provider reuse its prompt cache and lets the summary model read the complete tool output that was present in the conversation.
6
+
7
+ Caching is an optimization, not a prerequisite. The extension does not estimate cache expiry or adapt requests to individual providers. A cold cache can make this request more expensive than native compaction, but produces the same kind of checkpoint without a separate provider-specific path.
8
+
9
+ ## Summary boundary
10
+
11
+ The extension uses Pi's `firstKeptEntryId` unchanged. Because the summary model also sees the retained recent messages, its instruction quotes the first retained message as `<kept-start>` and explicitly excludes that message and everything after it from the summary. Repeated opening text is identified by its occurrence counting backward from the end. If no usable text or tool-call boundary exists, native compaction runs instead.
12
+
13
+ The summary keeps Pi's Goal, Constraints & Preferences, Progress, Key Decisions, Next Steps, and Critical Context sections. Optional `/compact [instructions]` focus is appended to the instruction. Read and modified file lists are computed from session operations and previous compaction details rather than generated by the model.
14
+
15
+ ## Fallbacks
16
+
17
+ - Overflow recovery always uses native compaction because the complete context has already exceeded the model window.
18
+ - A missing boundary, request failure, empty summary, tool call, or output-length stop falls back to native compaction.
19
+ - Cancelling the summary cancels that compaction without starting a second native summary request.
20
+ - Branch summarization through `/tree` is unchanged.
21
+
22
+ Native compaction accepts the same native file-list shape in extension-provided compaction details, so alternating between cached and native compaction does not reset file history.
23
+
24
+ ## Result card
25
+
26
+ A successful cached-path compaction adds a persistent display-only card after the summary:
27
+
28
+ ```text
29
+ Cached compaction · manual
30
+ Cache 641.2k/648.8k (98.8%) · output 2.8k · 18.4s
31
+ ```
32
+
33
+ Automatic compaction is labelled `automatic`. The cache figures are the response's actual `cacheRead` divided by `input + cacheRead + cacheWrite`; the card also shows output tokens and elapsed time. It contains no cost estimate and never enters model context. Native fallback adds no card.
34
+
35
+ The extension registers no commands or settings.
@@ -39,23 +39,25 @@ The `Ctrl+B` background hint is not part of a tool row. Once a foreground manage
39
39
 
40
40
  The look is defined in one place, `src/modes/interactive/tool-view/style.ts`: the marker and rail glyphs, their colors, the spacing between blocks, and which tools fold their result. `FramedComponent` in the same file hangs a component's lines off the marker or the rail and derives the gutter width from the glyphs.
41
41
 
42
- `tool-view/tool-execution.ts` owns one call's lifecycle: pending, success and error states, expansion, image placement and Kitty conversion, and renderer disposal. `tool-view/chat.ts` owns the chat container that measures tool blocks for spacing and disposes rows when the chat clears. Extension tools and built-in tools use the same shell, so a third-party tool gets the same dot and rail without any change.
42
+ The upstream `components/tool-execution.ts` owns one call's lifecycle: pending, success and error states, expansion, image placement and Kitty conversion, and renderer disposal. The bundled `tool-presentation` extension attaches a TUI-only shell through the existing tool renderer resolver; `tool-view/shell.ts` maps the visual policy to that shell. The old `tool-view/tool-execution.ts` path is only a compatibility adapter for direct source imports, not a second lifecycle implementation.
43
43
 
44
- Built-in renderers remain responsible for semantic content such as file paths, syntax highlighting, search results, Diff previews, and command output. They return plain components; the shell frames them.
44
+ `tool-view/chat.ts` owns the chat container that measures tool blocks for spacing and disposes rows when the chat clears. It reads each row's gap policy: upstream rows keep one blank line, while the distribution shell uses the compact policy above. Extension tools and built-in tools use the same shell unless they explicitly own a self shell.
45
+
46
+ Built-in renderers remain responsible for semantic content such as file paths, syntax highlighting, search results, Diff previews, and command output. They return plain components; the native component passes them to the shell without wrapping their renderer functions. HTML export uses only those renderers and ignores the TUI shell, so it retains its existing output. Disable `builtin:tool-presentation` (for example with `-builtin:tool-presentation` in extension settings) to use the upstream Box presentation instead.
45
47
 
46
48
  ## Renderer inheritance
47
49
 
48
50
  | Tool definition | Behavior |
49
51
  |---|---|
50
- | No `renderCall`/`renderResult` | Uses the native call and result fallback. |
51
- | Custom renderer with the default shell | Uses the native shell around the custom content. |
52
- | `renderShell: "self"` | Keeps complete ownership of the tool's layout. |
52
+ | No `renderCall`/`renderResult` | Uses the active shell's call and result fallback. |
53
+ | Custom renderer with the default shell | Uses the distribution shell around the custom content, or upstream Box when the extension is disabled. |
54
+ | `renderShell: "self"` | Keeps complete ownership of the tool's layout; no distribution shell is attached. |
53
55
 
54
56
  Built-in tool definitions are also used when an extension overrides only one renderer slot. A custom call renderer can inherit the built-in result renderer, and vice versa. An extension that overrides a built-in tool with its own result renderer controls what that row shows, including when it is collapsed.
55
57
 
56
58
  The inherited Bash result renderer keeps its elapsed time even with a custom call renderer. Call and result renderers share `state`; a renderer that adds a `dispose()` callback must also call the previous callback so both renderers can release their resources.
57
59
 
58
- Renderer failures fall back to native generic output rather than breaking the transcript.
60
+ Renderer failures fall back to the active shell's generic output rather than breaking the transcript; without a distribution shell, the upstream generic fallback is used.
59
61
 
60
62
  ## Generic fallback
61
63
 
@@ -89,7 +91,7 @@ The package does not use:
89
91
 
90
92
  - prototype patching of `ToolExecutionComponent` from an extension;
91
93
  - same-name re-registration to replace built-in tools;
92
- - a global renderer registry exposed through Extension API;
94
+ - a second global renderer registry exposed through Extension API;
93
95
  - a restored `tools-view` extension;
94
96
  - forced decoration of third-party tools that explicitly own their shell;
95
97
  - merging consecutive calls into a collapsed group, or a shell-level progress row.
@@ -17,7 +17,7 @@ Pi has two summarization mechanisms:
17
17
  | Compaction | Context exceeds threshold, or `/compact` | Summarize old messages to free up context |
18
18
  | Branch summarization | `/tree` navigation | Preserve context when switching branches |
19
19
 
20
- Both use the same structured summary format and track file operations cumulatively. Summarization requests disable prompt-cache writes because these one-off prompts are unlikely to be reused.
20
+ Both use the same structured summary format and track file operations cumulatively. Native summarization requests disable prompt-cache writes because these one-off prompts are unlikely to be reused. The bundled [Cached compaction](bundled/extensions/cached-compaction.md) extension instead summarizes the prepared conversation directly for manual and threshold compaction, allowing provider prompt-cache reuse; overflow recovery and failed cached-path attempts retain the native behavior.
21
21
 
22
22
  ## Compaction
23
23
 
package/docs/docs.json CHANGED
@@ -72,6 +72,10 @@
72
72
  "title": "BTW",
73
73
  "path": "bundled/extensions/btw.md"
74
74
  },
75
+ {
76
+ "title": "Cached compaction",
77
+ "path": "bundled/extensions/cached-compaction.md"
78
+ },
75
79
  {
76
80
  "title": "DeepWiki",
77
81
  "path": "bundled/extensions/deepwiki.md"
@@ -2531,7 +2531,7 @@ export default function (pi: ExtensionAPI) {
2531
2531
 
2532
2532
  Tools can provide `renderCall` and `renderResult` for custom TUI display. See [tui.md](tui.md) for the full component API.
2533
2533
 
2534
- By default, tool output is wrapped in Pi's native call/result shell, which owns the status dot, result rail, spacing between consecutive tool rows, and fallback rendering. A defined `renderCall` or `renderResult` must return a `Component`. If a slot renderer is not defined, the shell uses fallback rendering for that slot. Return content without leading padding: the shell trims leading blank result lines and adds no blank line between consecutive tool rows.
2534
+ By default, tool output is wrapped in the active call/result shell, which owns the status dot, result rail, spacing between consecutive tool rows, and fallback rendering. The bundled `tool-presentation` extension supplies the distribution's compact shell; disabling `builtin:tool-presentation` restores the upstream Box shell. A defined `renderCall` or `renderResult` must return a `Component`. If a slot renderer is not defined, the shell uses fallback rendering for that slot. Return content without leading padding: the compact shell trims leading blank result lines and adds no blank line between consecutive single-line tool rows.
2535
2535
 
2536
2536
  Set `renderShell: "self"` when the tool should render its own shell instead of using the native shell. This is useful for tools that need complete control over framing or background behavior, for example large previews that must stay visually stable after the tool settles.
2537
2537
 
@@ -3345,6 +3345,8 @@ A tool that reaches other tools declares which ones a call may reach with `reach
3345
3345
 
3346
3346
  `pi.registerToolRenderer((toolName, next) => renderers)` chooses `renderCall`, `renderResult`, and `renderShell` for calls to any tool, including tools that are not registered yet, such as MCP tools in a resumed session. Resolvers run in extension load order. `next()` returns the remaining resolvers' result or the registered tool's renderers, so `next() ?? mine` supplies a fallback. Interactive transcripts and HTML exports both use these resolvers.
3347
3347
 
3348
+ A resolver can also attach an optional `shell` (`ToolExecutionShell`) for TUI-only framing, fallbacks, and row spacing. The native tool component consumes it after the renderers return their components, so `lastComponent` reuse and renderer ownership are preserved. HTML export ignores `shell`; it never changes tool execution or the model-facing tool declaration. An explicit `renderShell: "self"` always remains tool-owned and is not wrapped by a distribution shell.
3349
+
3348
3350
  ### MCP servers
3349
3351
 
3350
3352
  `pi.registerMcpServer(name, config)` adds an MCP server for the current session. `config` has the shape of an `mcpServers` entry in [`mcp.json`](mcp.md): `command`, `args`, `env`, and `cwd` for stdio servers, `url`, `headers`, and `oauth` for HTTP servers, plus `exposure`, `toolExposure`, `description`, `enabled`, and `timeout`.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@astralyn/pi",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@astralyn/pi",
9
- "version": "1.4.0",
9
+ "version": "1.4.2",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@earendil-works/pi-agent-core": "1.4.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astralyn/pi",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Coding agent CLI with read, bash, edit, write tools and session management",
5
5
  "type": "module",
6
6
  "piConfig": {