@lune_99/pi-compaction 0.1.0 → 0.2.0

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/CHANGELOG.md CHANGED
@@ -5,6 +5,30 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.2.0] - 2026-11-28
9
+
10
+ ### Added
11
+
12
+ - **Parallel classifier requests.** Set how many fragments the tool-history review classifies at once (1–16, default 2) in the Compaction settings. Raise it to finish long reviews sooner; a rate-limited request still cancels the compaction. Embedded hosts pass the value as `jev.concurrency`.
13
+
14
+ ### Changed
15
+
16
+ - **Review result in the transcript**: The review result is now a saved `Tool review` entry next to Pi's compaction summary instead of a status notification, which Pi removed when the checkpoint committed. The entry shows disjoint removal counts and the summary-input size; Ctrl+O adds the classifier, reviewed and protected calls, and the split between per-result truncation and classifier drops. One row above the editor shows request progress while the review and summary run and disappears when the compaction ends, so nothing stays pinned. Drops inside fully removed calls no longer inflate the fragment count. Because the entry follows the checkpoint, an immediate second `/compact` reports Pi's "Nothing to compact" instead of "Already compacted".
17
+ - **Reviewed `codemode` results**: A result that ran nested tools is now a review candidate when its nested record is complete, every nested call succeeded and every nested tool is in **Deletable tools**; otherwise it stays protected with a specific reason. Pi lists file operations before the review, so `readFiles`, `modifiedFiles` and the summary's file lists can still name files that only a removed call touched, as for removed `read` calls.
18
+ - **Classifier selection copy.** The classifier field now describes what the classifier rates, and its automatic choice reads **Automatic · first available classifier**. The unavailable-classifier guidance matches Subagents and points to `/lune-core-settings → Compaction → Classifier model`; behavior is unchanged.
19
+ - **Native summary behavior on Pi 1.6.0.** Summary requests use the selected model’s output limit. Custom `/compact` instructions apply to both summaries when Pi splits a turn.
20
+ - **Core 0.2 dependency.** Require `@lune_99/pi-lune-extensions-core@^0.2.1`. The earlier `^0.1.0` range excluded Core 0.2, so an installation kept Core 0.1.0 beside the newer Core that other Lune packages load.
21
+
22
+ ### Fixed
23
+
24
+ - **Retry interrupted classifier requests.** Retry temporary connection failures, including `fetch failed` and `UND_ERR_SOCKET`, up to twice with cancellable backoff at the configured parallelism. Quota and billing failures bypass retries; non-retryable errors and exhausted retries still cancel compaction.
25
+
26
+ - **Pi 1.5 SDK compatibility.** Define the settings schema directly with TypeBox so SDK consumers and local checks do not depend on Pi's legacy import mapping. Existing settings values, defaults and storage stay unchanged.
27
+
28
+ - **Pi package discovery.** Add the `pi-package`, `pi`, and `pi-coding-agent` npm keywords. The discovery keyword makes the package eligible for the official Pi package gallery once published.
29
+
30
+ ## [0.1.0] - 2026-10-16
31
+
8
32
  ### Added
9
33
 
10
34
  - **Follow session model**: Add a default summary-model choice that inherits the current session model and effort at the start of each compaction. Selecting a separate model retains independent thinking-level configuration.
package/README.md CHANGED
@@ -28,8 +28,8 @@ Lune compaction is on by default. Run `/compact` as usual, or let Pi compact aut
28
28
 
29
29
  - **Gives summaries their own model.** Follow the session model and effort, or select a separate summary model with an independent thinking level.
30
30
  - **Works with native compaction.** Manual, threshold and overflow compaction keep Pi's handling of previous summaries, split turns and file operations.
31
- - **Reviews tool output before summarizing.** An optional classifier judges which result fragments are no longer useful. You choose the confidence threshold and which tools may lose their whole call.
32
- - **Shows what was removed.** A review notice reports the classifier, calls checked, edits and the change in summary-input size.
31
+ - **Reviews tool output before summarizing.** An optional classifier judges which result fragments are no longer useful. You choose the confidence threshold and which tools may lose their whole call. `codemode` results are reviewed too when every nested call finished, succeeded and used a permitted tool.
32
+ - **Shows what was removed.** A `Tool review` entry next to the compaction summary reports removals and the change in summary-input size; expand it for the classifier, reviewed and protected calls, and how much came from the per-result truncation cap and how much from the classifier.
33
33
  - **Keeps configuration close.** Pick models and review options in the Compaction settings panel, with global defaults and project overrides.
34
34
  - **Reports failures explicitly.** A failed summary or classification cancels the operation; cancelled or stale work cannot write a checkpoint.
35
35
 
@@ -43,17 +43,19 @@ Open:
43
43
 
44
44
  Choose **Follow session model** to use the current model and effort. Selecting a separate **Compaction model** makes **Compaction thinking level** independent.
45
45
 
46
- **Jev preprocessing** is off by default. Enable it to review tool history, then choose a Pi classifier, set **Drop confidence** and select **Deletable tools**. A whole call is removed only when its tool is permitted and every result fragment meets the threshold. Summary models and classifiers come from Pi's configured providers.
46
+ **Jev preprocessing** is off by default. Enable it to review tool history, then choose a Pi classifier, set **Drop confidence** and select **Deletable tools**. A whole call is removed only when its tool is permitted and every result fragment meets the threshold. A call that ran other tools, such as `codemode`, also needs a complete nested record in which every call succeeded and every tool is permitted; otherwise it stays in the summary input unchanged. Summary models and classifiers come from Pi's configured providers.
47
+
48
+ **Parallel classifier requests** sets how many fragments the classifier reviews at once, from 1 to 16 (default 2). A higher value finishes the review sooner on long tool histories. Each fragment retries temporary transport failures up to twice, after 500 ms and 1 second, within the configured parallelism. Cancellation interrupts the retry delay; a non-retryable error or exhausted retries cancel the compaction, so stay below your provider's rate limit.
47
49
 
48
50
  `Ctrl+G` switches global/project scope; `Ctrl+R` removes the selected override. Changes apply to the next compaction.
49
51
 
50
52
  ## Tool-history review
51
53
 
52
- An example review notice:
54
+ An example review entry, collapsed and expanded:
53
55
 
54
- ![Lune Compaction review notice](docs/compaction-review.png)
56
+ ![Lune Compaction review entry](docs/compaction-review.png)
55
57
 
56
- The notice reports the size of the messages entering the summary in characters. Review changes that input; the on-disk tool transcript stays intact.
58
+ While the classifier and summary run, one row above the editor shows progress; it disappears when the compaction ends. The result is saved as a transcript entry at the point of the compaction, after the retained messages; in the live session that is directly above Pi's compaction summary. It scrolls away with the conversation and is still there after a reload. Press `Ctrl+O` to expand it, as with tool output. Sizes are the characters of the messages entering the summary: `truncation` is what the 8,000-character cap on each tool result removed, and `classifier` is what the classifier's decisions removed after that. Review changes only that input; the on-disk tool transcript stays intact.
57
59
 
58
60
  ## Development
59
61
 
Binary file
@@ -1,9 +1,12 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="946.4399999999999" height="108.8" viewBox="0 0 946.4399999999999 108.8" font-family="Menlo, FiraCode Nerd Font Mono, monospace" font-size="14" xml:space="preserve" role="img" aria-label="pi — an illustrative tool-review notice">
2
- <title>pi — an illustrative tool-review notice</title>
3
- <rect width="946.4399999999999" height="108.8" rx="10" fill="#181a1b"/>
4
- <rect width="946.4399999999999" height="34" rx="10" fill="#768186" opacity="0.25"/>
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="701.97" height="167" viewBox="0 0 701.97 167" font-family="Menlo, FiraCode Nerd Font Mono, monospace" font-size="14" xml:space="preserve" role="img" aria-label="pi — an illustrative tool-review entry, collapsed and expanded">
2
+ <title>pi — an illustrative tool-review entry, collapsed and expanded</title>
3
+ <rect width="701.97" height="167" rx="10" fill="#181a1b"/>
4
+ <rect width="701.97" height="34" rx="10" fill="#768186" opacity="0.25"/>
5
5
  <circle cx="24" cy="17" r="5" fill="#ff5f57"/><circle cx="42" cy="17" r="5" fill="#febc2e"/><circle cx="60" cy="17" r="5" fill="#28c840"/>
6
- <text x="80" y="22" fill="#9da5a9" font-size="13">pi — an illustrative tool-review notice</text>
7
- <text x="18.00" y="65.97" fill="#dee0e1" textLength="8.43" lengthAdjust="spacingAndGlyphs"> </text><text x="26.43" y="65.97" fill="#7e888e" textLength="902.01" lengthAdjust="spacingAndGlyphs">◇ Tool review · example/classifier · 12 calls checked: 3 calls deleted · 1 result fragment deleted · </text>
8
- <text x="18.00" y="85.37" fill="#dee0e1" textLength="8.43" lengthAdjust="spacingAndGlyphs"> </text><text x="26.43" y="85.37" fill="#7e888e" textLength="118.02" lengthAdjust="spacingAndGlyphs">48k→31k (-35%)</text><text x="144.45" y="85.37" fill="#dee0e1" textLength="783.99" lengthAdjust="spacingAndGlyphs"> </text>
6
+ <text x="80" y="22" fill="#9da5a9" font-size="13">pi — an illustrative tool-review entry, collapsed and expanded</text>
7
+ <text x="18.00" y="65.97" fill="#dee0e1" textLength="8.43" lengthAdjust="spacingAndGlyphs"> </text><text x="26.43" y="65.97" fill="#a798d7" textLength="8.43" lengthAdjust="spacingAndGlyphs">◇</text><text x="34.86" y="65.97" fill="#dee0e1" textLength="101.16" lengthAdjust="spacingAndGlyphs"> Tool review</text><text x="136.02" y="65.97" fill="#9da5a9" textLength="25.29" lengthAdjust="spacingAndGlyphs"> · </text><text x="161.31" y="65.97" fill="#dee0e1" textLength="67.44" lengthAdjust="spacingAndGlyphs">−3 calls</text><text x="228.75" y="65.97" fill="#9da5a9" textLength="25.29" lengthAdjust="spacingAndGlyphs"> · </text><text x="254.04" y="65.97" fill="#dee0e1" textLength="92.73" lengthAdjust="spacingAndGlyphs">−1 fragment</text><text x="346.77" y="65.97" fill="#9da5a9" textLength="25.29" lengthAdjust="spacingAndGlyphs"> · </text><text x="372.06" y="65.97" fill="#dee0e1" textLength="75.87" lengthAdjust="spacingAndGlyphs">48k → 31k</text>
8
+
9
+ <text x="18.00" y="104.77" fill="#dee0e1" textLength="8.43" lengthAdjust="spacingAndGlyphs"> </text><text x="26.43" y="104.77" fill="#a798d7" textLength="8.43" lengthAdjust="spacingAndGlyphs">◇</text><text x="34.86" y="104.77" fill="#dee0e1" textLength="101.16" lengthAdjust="spacingAndGlyphs"> Tool review</text><text x="136.02" y="104.77" fill="#9da5a9" textLength="25.29" lengthAdjust="spacingAndGlyphs"> · </text><text x="161.31" y="104.77" fill="#9da5a9" textLength="151.74" lengthAdjust="spacingAndGlyphs">example/classifier</text>
10
+ <text x="18.00" y="124.17" fill="#dee0e1" textLength="25.29" lengthAdjust="spacingAndGlyphs"> </text><text x="43.29" y="124.17" fill="#9da5a9" textLength="67.44" lengthAdjust="spacingAndGlyphs">15 calls</text><text x="110.73" y="124.17" fill="#9da5a9" textLength="25.29" lengthAdjust="spacingAndGlyphs"> · </text><text x="136.02" y="124.17" fill="#9da5a9" textLength="92.73" lengthAdjust="spacingAndGlyphs">12 reviewed</text><text x="228.75" y="124.17" fill="#9da5a9" textLength="25.29" lengthAdjust="spacingAndGlyphs"> · </text><text x="254.04" y="124.17" fill="#9da5a9" textLength="92.73" lengthAdjust="spacingAndGlyphs">3 protected</text><text x="346.77" y="124.17" fill="#dee0e1" textLength="8.43" lengthAdjust="spacingAndGlyphs"> </text><text x="355.20" y="124.17" fill="#9da5a9" textLength="328.77" lengthAdjust="spacingAndGlyphs">(1 recent · 1 not permitted · 1 nested)</text>
11
+ <text x="18.00" y="143.57" fill="#dee0e1" textLength="92.73" lengthAdjust="spacingAndGlyphs"> −3 calls</text><text x="110.73" y="143.57" fill="#9da5a9" textLength="25.29" lengthAdjust="spacingAndGlyphs"> · </text><text x="136.02" y="143.57" fill="#dee0e1" textLength="92.73" lengthAdjust="spacingAndGlyphs">−1 fragment</text><text x="228.75" y="143.57" fill="#9da5a9" textLength="25.29" lengthAdjust="spacingAndGlyphs"> · </text><text x="254.04" y="143.57" fill="#dee0e1" textLength="75.87" lengthAdjust="spacingAndGlyphs">48k → 31k</text><text x="329.91" y="143.57" fill="#9da5a9" textLength="25.29" lengthAdjust="spacingAndGlyphs"> · </text><text x="355.20" y="143.57" fill="#9da5a9" textLength="118.02" lengthAdjust="spacingAndGlyphs">truncation −9k</text><text x="473.22" y="143.57" fill="#9da5a9" textLength="25.29" lengthAdjust="spacingAndGlyphs"> · </text><text x="498.51" y="143.57" fill="#9da5a9" textLength="118.02" lengthAdjust="spacingAndGlyphs">classifier −8k</text>
9
12
  </svg>
Binary file
@@ -1,6 +1,6 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="929.5799999999999" height="399.79999999999995" viewBox="0 0 929.5799999999999 399.79999999999995" font-family="Menlo, FiraCode Nerd Font Mono, monospace" font-size="14" xml:space="preserve" role="img" aria-label="pi — choose how your next compaction runs">
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="929.5799999999999" height="419.2" viewBox="0 0 929.5799999999999 419.2" font-family="Menlo, FiraCode Nerd Font Mono, monospace" font-size="14" xml:space="preserve" role="img" aria-label="pi — choose how your next compaction runs">
2
2
  <title>pi — choose how your next compaction runs</title>
3
- <rect width="929.5799999999999" height="399.79999999999995" rx="10" fill="#181a1b"/>
3
+ <rect width="929.5799999999999" height="419.2" rx="10" fill="#181a1b"/>
4
4
  <rect width="929.5799999999999" height="34" rx="10" fill="#768186" opacity="0.25"/>
5
5
  <circle cx="24" cy="17" r="5" fill="#ff5f57"/><circle cx="42" cy="17" r="5" fill="#febc2e"/><circle cx="60" cy="17" r="5" fill="#28c840"/>
6
6
  <text x="80" y="22" fill="#9da5a9" font-size="13">pi — choose how your next compaction runs</text>
@@ -12,13 +12,14 @@
12
12
  <text x="18.00" y="162.97" fill="#dee0e1" textLength="151.74" lengthAdjust="spacingAndGlyphs"> Compaction model</text><text x="169.74" y="162.97" fill="#9da5a9" textLength="303.48" lengthAdjust="spacingAndGlyphs"> Follow session model</text>
13
13
  <text x="18.00" y="182.37" fill="#dee0e1" textLength="227.61" lengthAdjust="spacingAndGlyphs"> Compaction thinking level</text><text x="245.61" y="182.37" fill="#9da5a9" textLength="311.91" lengthAdjust="spacingAndGlyphs"> Follow session effort · medium</text>
14
14
  <text x="18.00" y="201.77" fill="#dee0e1" textLength="160.17" lengthAdjust="spacingAndGlyphs"> Jev preprocessing</text><text x="178.17" y="201.77" fill="#9da5a9" textLength="151.74" lengthAdjust="spacingAndGlyphs"> off</text>
15
- <text x="18.00" y="221.17" fill="#dee0e1" textLength="151.74" lengthAdjust="spacingAndGlyphs"> Classifier model</text><text x="169.74" y="221.17" fill="#9da5a9" textLength="438.36" lengthAdjust="spacingAndGlyphs"> Automatic · available Pi classifiers</text>
16
- <text x="18.00" y="240.57" fill="#dee0e1" textLength="143.31" lengthAdjust="spacingAndGlyphs"> Drop confidence</text><text x="161.31" y="240.57" fill="#9da5a9" textLength="168.60" lengthAdjust="spacingAndGlyphs"> 0.7</text>
17
- <text x="18.00" y="259.97" fill="#dee0e1" textLength="160.17" lengthAdjust="spacingAndGlyphs"> Deletable tools →</text><text x="178.17" y="259.97" fill="#9da5a9" textLength="210.75" lengthAdjust="spacingAndGlyphs"> 9 selected</text>
15
+ <text x="18.00" y="221.17" fill="#dee0e1" textLength="151.74" lengthAdjust="spacingAndGlyphs"> Classifier model</text><text x="169.74" y="221.17" fill="#9da5a9" textLength="455.22" lengthAdjust="spacingAndGlyphs"> Automatic · first available classifier</text>
16
+ <text x="18.00" y="240.57" fill="#dee0e1" textLength="252.90" lengthAdjust="spacingAndGlyphs"> Parallel classifier requests</text><text x="270.90" y="240.57" fill="#9da5a9" textLength="42.15" lengthAdjust="spacingAndGlyphs"> 2</text>
17
+ <text x="18.00" y="259.97" fill="#dee0e1" textLength="143.31" lengthAdjust="spacingAndGlyphs"> Drop confidence</text><text x="161.31" y="259.97" fill="#9da5a9" textLength="168.60" lengthAdjust="spacingAndGlyphs"> 0.7</text>
18
+ <text x="18.00" y="279.37" fill="#dee0e1" textLength="160.17" lengthAdjust="spacingAndGlyphs"> Deletable tools →</text><text x="178.17" y="279.37" fill="#9da5a9" textLength="210.75" lengthAdjust="spacingAndGlyphs"> 9 selected</text>
18
19
 
19
- <text x="18.00" y="298.77" fill="#9da5a9" textLength="893.58" lengthAdjust="spacingAndGlyphs">Enabled by default. Follow the session model and effort, or select a separate summary model. Changes apply</text>
20
- <text x="18.00" y="318.17" fill="#9da5a9" textLength="185.46" lengthAdjust="spacingAndGlyphs">on the next operation.</text>
21
- <text x="18.00" y="337.57" fill="#7e888e" textLength="893.58" lengthAdjust="spacingAndGlyphs">──────────────────────────────────────────────────────────────────────────────────────────────────────────</text>
22
- <text x="18.00" y="356.97" fill="#7e888e" textLength="876.72" lengthAdjust="spacingAndGlyphs">↑↓ select · Enter change · Tab section · Ctrl+G scope · Ctrl+S reload section · Ctrl+R reset · Esc close</text>
23
- <text x="18.00" y="376.37" fill="#7e888e" textLength="893.58" lengthAdjust="spacingAndGlyphs">──────────────────────────────────────────────────────────────────────────────────────────────────────────</text>
20
+ <text x="18.00" y="318.17" fill="#9da5a9" textLength="893.58" lengthAdjust="spacingAndGlyphs">Enabled by default. Follow the session model and effort, or select a separate summary model. Changes apply</text>
21
+ <text x="18.00" y="337.57" fill="#9da5a9" textLength="185.46" lengthAdjust="spacingAndGlyphs">on the next operation.</text>
22
+ <text x="18.00" y="356.97" fill="#7e888e" textLength="893.58" lengthAdjust="spacingAndGlyphs">──────────────────────────────────────────────────────────────────────────────────────────────────────────</text>
23
+ <text x="18.00" y="376.37" fill="#7e888e" textLength="876.72" lengthAdjust="spacingAndGlyphs">↑↓ select · Enter change · Tab section · Ctrl+G scope · Ctrl+S reload section · Ctrl+R reset · Esc close</text>
24
+ <text x="18.00" y="395.77" fill="#7e888e" textLength="893.58" lengthAdjust="spacingAndGlyphs">──────────────────────────────────────────────────────────────────────────────────────────────────────────</text>
24
25
  </svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lune_99/pi-compaction",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Model-selectable native Pi compaction with classifier-reviewed tool history",
5
5
  "type": "module",
6
6
  "files": [
@@ -22,22 +22,31 @@
22
22
  "engines": {
23
23
  "node": ">=22.19.0"
24
24
  },
25
+ "keywords": [
26
+ "pi-package",
27
+ "pi",
28
+ "pi-coding-agent"
29
+ ],
25
30
  "license": "MIT",
26
31
  "author": "Nouvelle-Lune",
27
32
  "peerDependencies": {
28
33
  "@earendil-works/pi-agent-core": ">=1.0.4",
29
34
  "@earendil-works/pi-ai": ">=1.0.4",
30
- "@earendil-works/pi-coding-agent": ">=1.0.4"
35
+ "@earendil-works/pi-coding-agent": ">=1.0.4",
36
+ "@earendil-works/pi-tui": ">=1.0.4",
37
+ "typebox": ">=1.3.27"
31
38
  },
32
39
  "devDependencies": {
33
- "@earendil-works/pi-agent-core": "1.3.0",
34
- "@earendil-works/pi-ai": "1.3.0",
35
- "@earendil-works/pi-coding-agent": "1.3.0",
40
+ "@earendil-works/pi-agent-core": "1.6.0",
41
+ "@earendil-works/pi-ai": "1.6.0",
42
+ "@earendil-works/pi-coding-agent": "1.6.0",
43
+ "@earendil-works/pi-tui": "1.6.0",
36
44
  "@types/node": "^22.20.2",
45
+ "typebox": "1.3.27",
37
46
  "typescript": "5.9.3"
38
47
  },
39
48
  "dependencies": {
40
- "@lune_99/pi-lune-extensions-core": "^0.1.0"
49
+ "@lune_99/pi-lune-extensions-core": "^0.2.1"
41
50
  },
42
51
  "pi": {
43
52
  "extensions": [
@@ -12,8 +12,8 @@ import { validateOptions, type ConfigurationProvider } from "./options.ts";
12
12
  import { resolveClassifier } from "./tool-review/classification.ts";
13
13
  import {
14
14
  checkpointRecord,
15
- formatReviewNotice,
16
15
  reviewToolHistory,
16
+ type ToolReviewProgress,
17
17
  type ToolReviewReport,
18
18
  } from "./tool-review/review.ts";
19
19
 
@@ -46,6 +46,30 @@ export interface CompactionRun {
46
46
  summary?: string;
47
47
  }
48
48
 
49
+ /** What a presentation layer sees of a reviewed run; the report is shared, not copied. */
50
+ export interface CompactionRunUpdate {
51
+ readonly runId: number;
52
+ readonly stage: CompactionStage;
53
+ /** `provider/id`, known once the classifier is resolved. */
54
+ readonly reviewModel?: string;
55
+ readonly candidateTools?: number;
56
+ readonly protectedTools?: number;
57
+ readonly completedBatches: number;
58
+ readonly totalBatches: number;
59
+ readonly jev?: Readonly<ToolReviewReport>;
60
+ readonly error?: string;
61
+ }
62
+
63
+ /** Receives every visible change of a reviewed run, and `undefined` when its notice no longer applies. */
64
+ export type CompactionRunListener = (
65
+ update: CompactionRunUpdate | undefined,
66
+ ctx: ExtensionContext,
67
+ ) => void;
68
+
69
+ export interface CompactionControllerOptions {
70
+ readonly onRunChange?: CompactionRunListener;
71
+ }
72
+
49
73
  /** Route summaries through Pi's registry and reject any split response that did not finish normally. */
50
74
  export function createSummaryStream(
51
75
  ctx: ExtensionContext,
@@ -85,19 +109,29 @@ export class CompactionController {
85
109
  private run: CompactionRun | undefined;
86
110
  private readonly unregister: (() => void)[] = [];
87
111
  private readonly getConfiguration: ConfigurationProvider;
112
+ private readonly onRunChange: CompactionRunListener | undefined;
88
113
 
89
- constructor(pi: ExtensionAPI, getConfiguration: ConfigurationProvider) {
114
+ constructor(
115
+ pi: ExtensionAPI,
116
+ getConfiguration: ConfigurationProvider,
117
+ options: CompactionControllerOptions = {},
118
+ ) {
90
119
  this.getConfiguration = getConfiguration;
120
+ this.onRunChange = options.onRunChange;
121
+ const retire = (ctx: ExtensionContext): void => {
122
+ this.invalidate();
123
+ this.publish(ctx, undefined);
124
+ };
91
125
  this.unregister.push(
92
126
  pi.on("session_before_compact", (event, ctx) => this.beforeCompact(event, ctx)),
93
- pi.on("session_start", () => {
94
- this.invalidate();
127
+ pi.on("session_start", (_event, ctx) => {
128
+ retire(ctx);
95
129
  this.run = undefined;
96
130
  }),
97
- pi.on("session_shutdown", () => this.invalidate()),
98
- pi.on("session_before_switch", () => this.invalidate()),
99
- pi.on("session_before_fork", () => this.invalidate()),
100
- pi.on("session_before_tree", () => this.invalidate()),
131
+ pi.on("session_shutdown", (_event, ctx) => retire(ctx)),
132
+ pi.on("session_before_switch", (_event, ctx) => retire(ctx)),
133
+ pi.on("session_before_fork", (_event, ctx) => retire(ctx)),
134
+ pi.on("session_before_tree", (_event, ctx) => retire(ctx)),
101
135
  pi.on("session_compact", (event, ctx) => {
102
136
  const run = this.awaitingCommit(ctx);
103
137
  if (!run) return;
@@ -117,6 +151,7 @@ export class CompactionController {
117
151
  run.stage = "complete";
118
152
  }
119
153
  run.finishedAt = Date.now();
154
+ if (run.jev) this.publish(ctx, run);
120
155
  }),
121
156
  pi.on("session_compact_failed", (event, ctx) => {
122
157
  const run = this.awaitingCommit(ctx);
@@ -129,6 +164,7 @@ export class CompactionController {
129
164
  );
130
165
  this.report(ctx, run.error);
131
166
  }
167
+ if (run.jev) this.publish(ctx, run);
132
168
  }),
133
169
  );
134
170
  }
@@ -158,6 +194,31 @@ export class CompactionController {
158
194
  }
159
195
  }
160
196
 
197
+ private publish(
198
+ ctx: ExtensionContext,
199
+ run: CompactionRun | undefined,
200
+ progress?: { readonly reviewModel: string; readonly review?: ToolReviewProgress },
201
+ ): void {
202
+ if (!this.onRunChange) return;
203
+ const update: CompactionRunUpdate | undefined = run && {
204
+ runId: run.id,
205
+ stage: run.stage,
206
+ reviewModel: run.jev?.model ?? progress?.reviewModel,
207
+ candidateTools: run.jev?.candidateTools ?? progress?.review?.candidateTools,
208
+ protectedTools: run.jev?.protectedTools.length ?? progress?.review?.protectedTools,
209
+ completedBatches: run.completedBatches,
210
+ totalBatches: run.totalBatches,
211
+ jev: run.jev,
212
+ error: run.error?.message,
213
+ };
214
+ try {
215
+ this.onRunChange(update, ctx);
216
+ } catch (listenerError) {
217
+ // Presentation must never fail or retry a compaction.
218
+ console.warn("[pi-compaction] Run listener failed", listenerError);
219
+ }
220
+ }
221
+
161
222
  private report(ctx: ExtensionContext, error: Error): void {
162
223
  // Error reporting must not turn a cancel result into a swallowed hook exception.
163
224
  console.error("[pi-compaction]", error);
@@ -193,6 +254,7 @@ export class CompactionController {
193
254
  };
194
255
  const previousRun = this.run;
195
256
  this.run = run;
257
+ let reviewing = false;
196
258
  const signal = AbortSignal.any([event.signal, cancel.signal]);
197
259
  const assertActive = (): void => {
198
260
  signal.throwIfAborted();
@@ -215,6 +277,7 @@ export class CompactionController {
215
277
  if (configuration === null) {
216
278
  // Disabling interception is a configured mode, never a response to failure.
217
279
  this.run = previousRun;
280
+ this.publish(ctx, undefined);
218
281
  return {};
219
282
  }
220
283
  validateOptions(configuration);
@@ -232,34 +295,38 @@ export class CompactionController {
232
295
  // Native compact reads preparation without mutating it; only the review replaces these message arrays.
233
296
  const preparation = { ...event.preparation };
234
297
  if (configuration.jev.enabled) {
298
+ reviewing = true;
299
+ this.publish(ctx, run);
300
+ const classifier = await resolveClassifier(configuration.jev.model, ctx, signal);
301
+ assertActive();
302
+ const reviewModel = `${classifier.provider}/${classifier.id}`;
303
+ this.publish(ctx, run, { reviewModel });
235
304
  const reviewed = await reviewToolHistory(
236
305
  event,
237
306
  ctx,
238
307
  configuration.policy,
239
- await resolveClassifier(configuration.jev.model, ctx, signal),
308
+ classifier,
309
+ configuration.jev.concurrency,
240
310
  signal,
241
311
  (update) => {
242
312
  assertActive();
243
313
  run.stage = update.stage;
244
314
  run.completedBatches = update.completedBatches;
245
315
  run.totalBatches = update.totalBatches;
316
+ this.publish(ctx, run, { reviewModel, review: update });
246
317
  },
247
318
  );
248
319
  assertActive();
249
320
  preparation.messagesToSummarize = reviewed.messagesToSummarize;
250
321
  preparation.turnPrefixMessages = reviewed.turnPrefixMessages;
251
322
  run.jev = reviewed.report;
252
- if (ctx.hasUI) {
253
- try {
254
- const theme = ctx.ui.theme;
255
- ctx.ui.notify(theme.fg("dim", formatReviewNotice(reviewed.report)), "info");
256
- } catch (notificationError) {
257
- console.warn("[pi-compaction] Notification failed", notificationError);
258
- }
259
- }
323
+ } else {
324
+ // A notice from an earlier review would describe a checkpoint this run replaces.
325
+ this.publish(ctx, undefined);
260
326
  }
261
327
  assertActive();
262
328
  run.stage = "summarizing";
329
+ if (run.jev) this.publish(ctx, run);
263
330
  const result = await compact(
264
331
  preparation,
265
332
  model,
@@ -301,6 +368,8 @@ export class CompactionController {
301
368
  run.error = failure;
302
369
  this.report(ctx, failure);
303
370
  }
371
+ // A retired session already cleared its notice; its context must not draw a new one.
372
+ if (reviewing && generation === this.generation) this.publish(ctx, run);
304
373
  return { cancel: true };
305
374
  } finally {
306
375
  if (this.active === cancel) this.active = undefined;
package/src/extension.ts CHANGED
@@ -5,6 +5,7 @@ import { ResourceScope } from "@lune_99/pi-lune-extensions-core/resources";
5
5
  import { CompactionController } from "./compaction-controller.ts";
6
6
  import { resolveCompactionSettings } from "./settings/schema.ts";
7
7
  import { compactionSettings, createCompactionPanel } from "./settings/section.ts";
8
+ import { createReviewNotice } from "./ui/review-notice.ts";
8
9
 
9
10
  export async function installConfiguredCompaction(pi: ExtensionAPI) {
10
11
  const resources = new ResourceScope();
@@ -18,16 +19,21 @@ export async function installConfiguredCompaction(pi: ExtensionAPI) {
18
19
  ),
19
20
  );
20
21
  const controller = resources.use(
21
- new CompactionController(pi, async (ctx) => {
22
- const view = await settings.view(ctx);
23
- return resolveCompactionSettings(view.snapshot(), ctx);
24
- }),
22
+ new CompactionController(
23
+ pi,
24
+ async (ctx) => {
25
+ const view = await settings.view(ctx);
26
+ return resolveCompactionSettings(view.snapshot(), ctx);
27
+ },
28
+ { onRunChange: createReviewNotice(pi) },
29
+ ),
25
30
  );
26
31
  return { controller, dispose: () => resources.dispose() };
27
32
  } catch (error) {
28
33
  try {
29
34
  await resources.dispose();
30
35
  } catch (cleanupError) {
36
+ // eslint-disable-next-line preserve-caught-error -- AggregateError.errors retains both failures.
31
37
  throw new AggregateError([error, cleanupError], "Compaction setup and cleanup failed");
32
38
  }
33
39
  throw error;
package/src/index.ts CHANGED
@@ -1,13 +1,16 @@
1
1
  import type { ExtensionAPI, ExtensionFactory } from "@earendil-works/pi-coding-agent";
2
2
  import { CompactionController } from "./compaction-controller.ts";
3
3
  import type { ConfigurationProvider } from "./options.ts";
4
+ import { createReviewNotice } from "./ui/review-notice.ts";
4
5
 
5
6
  export type {
6
7
  CompactionController,
7
8
  CompactionRun,
9
+ CompactionRunListener,
10
+ CompactionRunUpdate,
8
11
  CompactionStage,
9
12
  } from "./compaction-controller.ts";
10
- export { DEFAULT_COMPACTION_POLICY } from "./options.ts";
13
+ export { DEFAULT_CLASSIFIER_CONCURRENCY, DEFAULT_COMPACTION_POLICY } from "./options.ts";
11
14
  export type {
12
15
  CompactionOptions,
13
16
  CompactionPolicy,
@@ -21,7 +24,7 @@ export function installCompaction(
21
24
  pi: ExtensionAPI,
22
25
  getConfiguration: ConfigurationProvider,
23
26
  ): CompactionController {
24
- return new CompactionController(pi, getConfiguration);
27
+ return new CompactionController(pi, getConfiguration, { onRunChange: createReviewNotice(pi) });
25
28
  }
26
29
 
27
30
  /** Embedded consumers own configuration; the standalone Pi entry uses Core settings. */
package/src/options.ts CHANGED
@@ -11,7 +11,12 @@ export interface CompactionPolicy {
11
11
  /** A null model selects the first available Pi classifier at run time. */
12
12
  export type JevOptions =
13
13
  | { readonly enabled: false }
14
- | { readonly enabled: true; readonly model: ModelReference | null };
14
+ | {
15
+ readonly enabled: true;
16
+ readonly model: ModelReference | null;
17
+ /** Classifier requests in flight at once during a review. */
18
+ readonly concurrency: number;
19
+ };
15
20
 
16
21
  export interface CompactionOptions {
17
22
  readonly summaryModel: ModelReference;
@@ -40,6 +45,10 @@ export const DEFAULT_COMPACTION_POLICY: CompactionPolicy = Object.freeze({
40
45
  ]),
41
46
  });
42
47
 
48
+ export const DEFAULT_CLASSIFIER_CONCURRENCY = 2;
49
+ // A terminal request failure cancels the review, so the cap bounds rate-limit failures.
50
+ export const MAX_CLASSIFIER_CONCURRENCY = 16;
51
+
43
52
  /** Embedded providers bypass settings schema validation, so every operation rechecks its options. */
44
53
  export function validateOptions(options: CompactionOptions): void {
45
54
  const identity = options.summaryModel;
@@ -66,4 +75,14 @@ export function validateOptions(options: CompactionOptions): void {
66
75
  ) {
67
76
  throw new Error("Classifier reference must contain a provider and model id");
68
77
  }
78
+ if (
79
+ options.jev.enabled &&
80
+ (!Number.isSafeInteger(options.jev.concurrency) ||
81
+ options.jev.concurrency < 1 ||
82
+ options.jev.concurrency > MAX_CLASSIFIER_CONCURRENCY)
83
+ ) {
84
+ throw new Error(
85
+ `Classifier concurrency must be an integer from 1 to ${MAX_CLASSIFIER_CONCURRENCY}`,
86
+ );
87
+ }
69
88
  }
@@ -1,7 +1,13 @@
1
- import { Type, StringEnum, type Static } from "@earendil-works/pi-ai";
1
+ import { Type, type Static } from "typebox";
2
2
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
3
3
  import type { SettingsView, DeepReadonly } from "@lune_99/pi-lune-extensions-core/settings";
4
- import { DEFAULT_COMPACTION_POLICY, validateOptions, type CompactionOptions } from "../options.ts";
4
+ import {
5
+ DEFAULT_CLASSIFIER_CONCURRENCY,
6
+ DEFAULT_COMPACTION_POLICY,
7
+ MAX_CLASSIFIER_CONCURRENCY,
8
+ validateOptions,
9
+ type CompactionOptions,
10
+ } from "../options.ts";
5
11
 
6
12
  export const SETTINGS_ID = "pi-compaction";
7
13
 
@@ -21,12 +27,17 @@ export const compactionSchema = Type.Object(
21
27
  {
22
28
  enabled: Type.Boolean({ default: true }),
23
29
  summaryModel: modelReference(),
24
- summaryThinkingLevel: StringEnum(
30
+ summaryThinkingLevel: Type.Enum(
25
31
  ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const,
26
- { default: "off" },
32
+ { type: "string", default: "off" },
27
33
  ),
28
34
  jevEnabled: Type.Boolean({ default: false }),
29
35
  classifier: modelReference(),
36
+ classifierConcurrency: Type.Integer({
37
+ minimum: 1,
38
+ maximum: MAX_CLASSIFIER_CONCURRENCY,
39
+ default: DEFAULT_CLASSIFIER_CONCURRENCY,
40
+ }),
30
41
  policy: Type.Object(
31
42
  {
32
43
  deleteThreshold: Type.Number({ minimum: 0, maximum: 1 }),
@@ -61,7 +72,11 @@ export function resolveCompactionSettings(
61
72
  : (session?.thinkingLevel ?? "off"),
62
73
  policy: { ...settings.policy, deletableTools: [...settings.policy.deletableTools] },
63
74
  jev: settings.jevEnabled
64
- ? { enabled: true, model: settings.classifier }
75
+ ? {
76
+ enabled: true,
77
+ model: settings.classifier,
78
+ concurrency: settings.classifierConcurrency,
79
+ }
65
80
  : { enabled: false },
66
81
  };
67
82
  validateOptions(options);
@@ -8,6 +8,7 @@ import {
8
8
  type SettingsChoiceSource,
9
9
  } from "@lune_99/pi-lune-extensions-core/panel";
10
10
  import { createDefinedSettingsSection } from "@lune_99/pi-lune-extensions-core/panel/host";
11
+ import { MAX_CLASSIFIER_CONCURRENCY } from "../options.ts";
11
12
  import { compactionSchema, SETTINGS_ID, type CompactionSettingsView } from "./schema.ts";
12
13
 
13
14
  export const summaryModelChoices: SettingsChoiceSource<ModelReference | null> = modelChoices({
@@ -27,10 +28,10 @@ export const classifierChoices: SettingsChoiceSource<ModelReference | null> = mo
27
28
  specialChoices: (_context, entries) => [
28
29
  {
29
30
  value: null,
30
- label: "Automatic",
31
+ label: "Automatic · first available classifier",
31
32
  description: entries.length
32
33
  ? `Use the first available Pi classifier at runtime (${entries[0]!.provider}/${entries[0]!.id} currently).`
33
- : "No classifier is available. Configure a provider in Pi with /login or environment credentials, then press Ctrl+R to refresh.",
34
+ : "No classifier is available. Configure a classifier provider in Pi with /login or its environment credentials, then press Ctrl+R to refresh.",
34
35
  },
35
36
  ],
36
37
  });
@@ -94,12 +95,19 @@ export function createCompactionPanel(getTools: ExtensionAPI["getAllTools"]) {
94
95
  }),
95
96
  field("classifier", {
96
97
  label: "Classifier model",
98
+ description:
99
+ "The Pi classifier that rates each permitted tool output fragment. Automatic " +
100
+ "uses the first available one.",
97
101
  formatValue: (value) =>
98
102
  value
99
103
  ? `${value.provider}/${value.id}`
100
- : "Automatic · available Pi classifiers",
104
+ : "Automatic · first available classifier",
101
105
  choiceSource: classifierChoices,
102
106
  }),
107
+ field("classifierConcurrency", {
108
+ label: "Parallel classifier requests",
109
+ description: `How many fragments the classifier reviews at once (1–${MAX_CLASSIFIER_CONCURRENCY}). Higher values finish the review sooner but reach provider rate limits faster; a rejected request cancels the compaction.`,
110
+ }),
103
111
  field(["policy", "deleteThreshold"], {
104
112
  label: "Drop confidence",
105
113
  description:
@@ -204,9 +204,20 @@ export function indexTools(
204
204
  reasons.push("non-text-result");
205
205
  if (!policy.deletableTools.includes(call.name)) reasons.push("tool-not-deletable");
206
206
  const nested = result.message.nestedCalls;
207
- // Permission for the outer name cannot authorize nested or unrecorded operations.
208
- if (nested && (!nested.complete || nested.calls.length > 0))
209
- reasons.push("nested-calls");
207
+ // Pi records calls made by nested tools too, so each recorded name needs its own permission.
208
+ if (nested) {
209
+ // An incomplete record can hide calls or arguments past Pi's recording limits.
210
+ if (!nested.complete) reasons.push("incomplete-nested-calls");
211
+ if (
212
+ nested.calls.some(
213
+ (nestedCall) => !policy.deletableTools.includes(nestedCall.name),
214
+ )
215
+ )
216
+ reasons.push("nested-tool-not-deletable");
217
+ // A failed or unfinished nested call means the outer result may not describe what ran.
218
+ if (nested.calls.some((nestedCall) => nestedCall.status !== "ok"))
219
+ reasons.push("nested-call-failed");
220
+ }
210
221
  }
211
222
  if (reasons.length > 0) {
212
223
  protectedTools.push({ id, reasons });