pi-rtk-optimizer 0.5.2 → 0.5.4

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
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.4] - 2026-04-22
11
+
12
+ ### Fixed
13
+ - Respected `PI_CODING_AGENT_DIR` when resolving the global extension config directory and preserved exact skill reads under the configured global Pi skills path.
14
+
15
+ ### Changed
16
+ - Updated README installation/configuration guidance and the settings modal description to document configurable global Pi paths.
17
+ - Removed session-switch lifecycle reinitialization from the extension runtime.
18
+ - Updated `@mariozechner/pi-coding-agent` and `@mariozechner/pi-tui` peer dependencies to ^0.68.1.
19
+
20
+ ## [0.5.3] - 2026-04-01
21
+
22
+ ### Changed
23
+ - Updated README.md with new background image source URL
24
+ - Aligned npm keywords for better package discoverability
25
+ - Added Related Pi Extensions cross-linking section to README
26
+
10
27
  ## [0.5.2] - 2026-04-01
11
28
 
12
29
  ### Changed
package/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  > RTK command rewriting and tool output compaction extension for the Pi coding agent.
4
4
 
5
- ![background](https://raw.githubusercontent.com/MasuRii/pi-rtk-optimizer/main/asset/pi-rtk-optimizer-background.png)
5
+ <img width="1360" height="752" alt="image" src="https://github.com/user-attachments/assets/f4536889-62ec-429a-984e-dc0de9f1f709" />
6
+
6
7
 
7
8
  **pi-rtk-optimizer** automatically rewrites `bash` tool commands to their `rtk` equivalents and compacts noisy tool output (`bash`, `read`, `grep`) to reduce context window usage while preserving actionable information for the AI agent.
8
9
 
@@ -58,8 +59,8 @@ Multi-stage pipeline to reduce token consumption:
58
59
 
59
60
  Place this folder in one of the following locations:
60
61
 
61
- ```
62
- ~/.pi/agent/extensions/pi-rtk-optimizer # Global (all projects)
62
+ ```text
63
+ ~/.pi/agent/extensions/pi-rtk-optimizer # Global default (when PI_CODING_AGENT_DIR is unset)
63
64
  .pi/extensions/pi-rtk-optimizer # Project-specific
64
65
  ```
65
66
 
@@ -106,8 +107,9 @@ Use arrow keys to navigate settings, Enter to cycle values, and Escape to close.
106
107
 
107
108
  Configuration is stored at:
108
109
 
109
- ```
110
- ~/.pi/agent/extensions/pi-rtk-optimizer/config.json
110
+ ```text
111
+ Default global path: ~/.pi/agent/extensions/pi-rtk-optimizer/config.json
112
+ Actual global path: $PI_CODING_AGENT_DIR/extensions/pi-rtk-optimizer/config.json when PI_CODING_AGENT_DIR is set
111
113
  ```
112
114
 
113
115
  A starter template is included at `config/config.example.json`.
@@ -287,6 +289,13 @@ Inspired by:
287
289
  - [mcowger/pi-rtk](https://github.com/mcowger/pi-rtk)
288
290
  - [rtk-ai/rtk](https://github.com/rtk-ai/rtk)
289
291
 
292
+ ## Related Pi Extensions
293
+
294
+ - [pi-tool-display](https://github.com/MasuRii/pi-tool-display) — Compact tool rendering and diff visualization
295
+ - [pi-permission-system](https://github.com/MasuRii/pi-permission-system) — Permission enforcement for tool and command access
296
+ - [pi-smart-voice-notify](https://github.com/MasuRii/pi-smart-voice-notify) — Multi-channel TTS and sound notifications
297
+ - [pi-image-tools](https://github.com/MasuRii/pi-image-tools) — Image attachment and inline preview
298
+
290
299
  ## License
291
300
 
292
301
  [MIT](LICENSE) © MasuRii
package/package.json CHANGED
@@ -1,60 +1,64 @@
1
- {
2
- "name": "pi-rtk-optimizer",
3
- "version": "0.5.2",
4
- "description": "Pi extension that optimizes RTK command rewriting and tool output compaction for the coding agent.",
5
- "type": "module",
6
- "main": "./index.ts",
7
- "exports": {
8
- ".": "./index.ts"
9
- },
10
- "files": [
11
- "index.ts",
12
- "src",
13
- "config/config.example.json",
14
- "README.md",
15
- "CHANGELOG.md",
16
- "LICENSE"
17
- ],
18
- "scripts": {
19
- "build": "npx --yes -p typescript@5.7.3 tsc -p tsconfig.json --noCheck",
20
- "lint": "npm run build",
21
- "typecheck": "npx --yes -p typescript@5.7.3 tsc -p tsconfig.json",
22
- "test": "bun ./src/output-compactor-test.ts && bun ./src/command-rewriter-test.ts && bun ./src/runtime-guard-test.ts && bun ./src/additional-coverage-test.ts && bun ./src/config-modal-test.ts && bun ./src/index-test.ts",
23
- "check": "npm run lint && npm run typecheck && npm run test",
24
- "build:check": "bunx esbuild ./index.ts --bundle --platform=node --format=esm --outfile=./.pi-rtk-optimizer-check.mjs --external:@mariozechner/pi-coding-agent --external:@mariozechner/pi-tui && bun -e \"import { unlinkSync } from 'node:fs'; unlinkSync('./.pi-rtk-optimizer-check.mjs');\""
25
- },
26
- "keywords": [
27
- "pi-package",
28
- "pi",
29
- "pi-extension",
30
- "rtk",
31
- "token-optimization",
32
- "tool-compaction",
33
- "coding-agent"
34
- ],
35
- "author": "MasuRii",
36
- "license": "MIT",
37
- "repository": {
38
- "type": "git",
39
- "url": "git+https://github.com/MasuRii/pi-rtk-optimizer.git"
40
- },
41
- "bugs": {
42
- "url": "https://github.com/MasuRii/pi-rtk-optimizer/issues"
43
- },
44
- "homepage": "https://github.com/MasuRii/pi-rtk-optimizer#readme",
45
- "engines": {
46
- "node": ">=20"
47
- },
48
- "publishConfig": {
49
- "access": "public"
50
- },
51
- "pi": {
52
- "extensions": [
53
- "./index.ts"
54
- ]
55
- },
56
- "peerDependencies": {
57
- "@mariozechner/pi-coding-agent": "^0.64.0",
58
- "@mariozechner/pi-tui": "^0.64.0"
59
- }
60
- }
1
+ {
2
+ "name": "pi-rtk-optimizer",
3
+ "version": "0.5.4",
4
+ "description": "Pi extension that optimizes RTK command rewriting and tool output compaction for the coding agent.",
5
+ "type": "module",
6
+ "main": "./index.ts",
7
+ "exports": {
8
+ ".": "./index.ts"
9
+ },
10
+ "files": [
11
+ "index.ts",
12
+ "src",
13
+ "config/config.example.json",
14
+ "README.md",
15
+ "CHANGELOG.md",
16
+ "LICENSE"
17
+ ],
18
+ "scripts": {
19
+ "build": "npx --yes -p typescript@5.7.3 tsc -p tsconfig.json --noCheck",
20
+ "lint": "npm run build",
21
+ "typecheck": "npx --yes -p typescript@5.7.3 tsc -p tsconfig.json",
22
+ "test": "bun ./src/output-compactor-test.ts && bun ./src/command-rewriter-test.ts && bun ./src/runtime-guard-test.ts && bun ./src/additional-coverage-test.ts && bun ./src/config-modal-test.ts && bun ./src/index-test.ts",
23
+ "check": "npm run lint && npm run typecheck && npm run test",
24
+ "build:check": "bunx esbuild ./index.ts --bundle --platform=node --format=esm --outfile=./.pi-rtk-optimizer-check.mjs --external:@mariozechner/pi-coding-agent --external:@mariozechner/pi-tui && bun -e \"import { unlinkSync } from 'node:fs'; unlinkSync('./.pi-rtk-optimizer-check.mjs');\""
25
+ },
26
+ "keywords": [
27
+ "pi-package",
28
+ "pi",
29
+ "pi-extension",
30
+ "pi-coding-agent",
31
+ "coding-agent",
32
+ "rtk",
33
+ "token-optimization",
34
+ "tool-compaction",
35
+ "output-compaction",
36
+ "command-rewrite",
37
+ "optimization"
38
+ ],
39
+ "author": "MasuRii",
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/MasuRii/pi-rtk-optimizer.git"
44
+ },
45
+ "bugs": {
46
+ "url": "https://github.com/MasuRii/pi-rtk-optimizer/issues"
47
+ },
48
+ "homepage": "https://github.com/MasuRii/pi-rtk-optimizer#readme",
49
+ "engines": {
50
+ "node": ">=20"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ },
55
+ "pi": {
56
+ "extensions": [
57
+ "./index.ts"
58
+ ]
59
+ },
60
+ "peerDependencies": {
61
+ "@mariozechner/pi-coding-agent": "^0.68.1",
62
+ "@mariozechner/pi-tui": "^0.68.1"
63
+ }
64
+ }
@@ -1,13 +1,20 @@
1
1
  import assert from "node:assert/strict";
2
+ import { mock } from "bun:test";
2
3
  import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
3
4
 
4
- import {
5
+ const MOCK_AGENT_DIR = "C:/tmp/.pi/agent";
6
+
7
+ mock.module("@mariozechner/pi-coding-agent", () => ({
8
+ getAgentDir: () => MOCK_AGENT_DIR,
9
+ }));
10
+
11
+ const {
5
12
  ensureConfigExists,
6
13
  getRtkIntegrationConfigPath,
7
14
  loadRtkIntegrationConfig,
8
15
  normalizeRtkIntegrationConfig,
9
16
  saveRtkIntegrationConfig,
10
- } from "./config-store.ts";
17
+ } = await import("./config-store.ts");
11
18
  import { clearOutputMetrics, getOutputMetricsSummary, trackOutputSavings } from "./output-metrics.ts";
12
19
  import { runTest } from "./test-helpers.ts";
13
20
  import { matchesCommandPatterns, normalizeCommandForDetection } from "./techniques/command-detection.ts";
@@ -143,7 +143,7 @@ function buildSettingItems(config: RtkIntegrationConfig): SettingItem[] {
143
143
  {
144
144
  id: "outputPreserveExactSkillReads",
145
145
  label: "Preserve exact skill reads",
146
- description: "If on, read results under ~/.pi/agent/skills, ~/.agents/skills, .pi/skills, and ancestor .agents/skills skip read compaction",
146
+ description: "If on, read results under the global Pi skills directory (default: ~/.pi/agent/skills, respects PI_CODING_AGENT_DIR), ~/.agents/skills, .pi/skills, and ancestor .agents/skills skip read compaction",
147
147
  currentValue: toOnOff(config.outputCompaction.preserveExactSkillReads),
148
148
  values: ON_OFF,
149
149
  },
package/src/constants.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { homedir } from "node:os";
2
- import { join } from "node:path";
3
-
4
- export const EXTENSION_NAME = "pi-rtk-optimizer";
5
- export const CONFIG_DIR = join(homedir(), ".pi", "agent", "extensions", EXTENSION_NAME);
6
- export const CONFIG_PATH = join(CONFIG_DIR, "config.json");
1
+ import { getAgentDir } from "@mariozechner/pi-coding-agent";
2
+ import { join } from "node:path";
3
+
4
+ export const EXTENSION_NAME = "pi-rtk-optimizer";
5
+ export const CONFIG_DIR = join(getAgentDir(), "extensions", EXTENSION_NAME);
6
+ export const CONFIG_PATH = join(CONFIG_DIR, "config.json");
package/src/index-test.ts CHANGED
@@ -4,6 +4,7 @@ import { mock } from "bun:test";
4
4
  import { runTest } from "./test-helpers.ts";
5
5
 
6
6
  mock.module("@mariozechner/pi-coding-agent", () => ({
7
+ getAgentDir: () => "/tmp/.pi/agent",
7
8
  getSettingsListTheme: () => ({}),
8
9
  isToolCallEventType: (toolName: string, event: Record<string, unknown>) => event.toolName === toolName,
9
10
  }));
package/src/index.ts CHANGED
@@ -262,14 +262,6 @@ export default function rtkIntegrationExtension(pi: ExtensionAPI): void {
262
262
  maybeWarnRtkMissing(ctx);
263
263
  });
264
264
 
265
- pi.on("session_switch", async (_event, ctx) => {
266
- warnedMessages.reset();
267
- suggestionNotices.reset();
268
- clearTrackedBashCommands();
269
- missingRtkWarningShown = false;
270
- await refreshConfig(ctx);
271
- maybeWarnRtkMissing(ctx);
272
- });
273
265
 
274
266
  pi.on("agent_end", async () => {
275
267
  clearTrackedBashCommands();
@@ -1,10 +1,17 @@
1
1
  import assert from "node:assert/strict";
2
- import { homedir } from "node:os";
2
+ import { mock } from "bun:test";
3
3
  import { join } from "node:path";
4
4
 
5
- import { compactToolResult } from "./output-compactor.ts";
6
5
  import { cloneDefaultConfig, runTest } from "./test-helpers.ts";
7
6
 
7
+ const MOCK_AGENT_DIR = "C:/tmp/.pi/agent";
8
+
9
+ mock.module("@mariozechner/pi-coding-agent", () => ({
10
+ getAgentDir: () => MOCK_AGENT_DIR,
11
+ }));
12
+
13
+ const { compactToolResult } = await import("./output-compactor.ts");
14
+
8
15
  function buildReadContent(lineCount: number): string {
9
16
  const lines: string[] = [];
10
17
  for (let index = 0; index < lineCount; index += 1) {
@@ -216,7 +223,7 @@ runTest("skill reads stay exact when preserveExactSkillReads is enabled for user
216
223
  const result = compactToolResult(
217
224
  {
218
225
  toolName: "read",
219
- input: { path: join(homedir(), ".pi", "agent", "skills", "example", "SKILL.md") },
226
+ input: { path: join(MOCK_AGENT_DIR, "skills", "example", "SKILL.md") },
220
227
  content: [{ type: "text", text: content }],
221
228
  },
222
229
  config,
@@ -1,3 +1,4 @@
1
+ import { getAgentDir } from "@mariozechner/pi-coding-agent";
1
2
  import { homedir } from "node:os";
2
3
  import { dirname, join, resolve, sep } from "node:path";
3
4
  import {
@@ -60,7 +61,7 @@ const LOSSY_TECHNIQUE_PREFIXES = [
60
61
 
61
62
  const READ_EXACT_OUTPUT_LINE_THRESHOLD = 80;
62
63
  const READ_COMPACTION_BANNER_PREFIX = "[RTK compacted output:";
63
- const USER_SKILL_ROOTS = [join(homedir(), ".pi", "agent", "skills"), join(homedir(), ".agents", "skills")];
64
+ const USER_SKILL_ROOTS = [join(getAgentDir(), "skills"), join(homedir(), ".agents", "skills")];
64
65
 
65
66
  function normalizePathForComparison(path: string): string {
66
67
  return process.platform === "win32" ? path.toLowerCase() : path;
@@ -89,6 +89,7 @@ declare module "@mariozechner/pi-coding-agent" {
89
89
  getFgAnsi?(name: string): string;
90
90
  }
91
91
 
92
+ export function getAgentDir(): string;
92
93
  export function getSettingsListTheme(): unknown;
93
94
 
94
95
  export interface ExtensionAPI {