pi-rewind-hook 1.7.2 → 1.8.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/install.js CHANGED
@@ -9,7 +9,6 @@ const REPO_URL = "https://raw.githubusercontent.com/nicobailon/pi-rewind-hook/ma
9
9
  const EXT_DIR = path.join(os.homedir(), ".pi", "agent", "extensions", "rewind");
10
10
  const OLD_HOOK_DIR = path.join(os.homedir(), ".pi", "agent", "hooks", "rewind");
11
11
  const SETTINGS_FILE = path.join(os.homedir(), ".pi", "agent", "settings.json");
12
- const EXT_PATH = "~/.pi/agent/extensions/rewind/index.ts";
13
12
 
14
13
  function download(url) {
15
14
  return new Promise((resolve, reject) => {
@@ -38,62 +37,53 @@ async function main() {
38
37
  const extContent = await download(`${REPO_URL}/index.ts`);
39
38
  fs.writeFileSync(path.join(EXT_DIR, "index.ts"), extContent);
40
39
 
40
+ console.log("Downloading package.json...");
41
+ const pkgContent = await download(`${REPO_URL}/package.json`);
42
+ fs.writeFileSync(path.join(EXT_DIR, "package.json"), pkgContent);
43
+
41
44
  console.log("Downloading README.md...");
42
45
  const readmeContent = await download(`${REPO_URL}/README.md`);
43
46
  fs.writeFileSync(path.join(EXT_DIR, "README.md"), readmeContent);
44
47
 
45
- console.log(`\nUpdating settings: ${SETTINGS_FILE}`);
46
-
47
- let settings = {};
48
+ // Migrate old hooks to extensions and clean up legacy settings
48
49
  if (fs.existsSync(SETTINGS_FILE)) {
49
50
  try {
50
- settings = JSON.parse(fs.readFileSync(SETTINGS_FILE, "utf-8"));
51
- } catch (err) {
52
- console.error(`Warning: Could not parse existing settings.json: ${err.message}`);
53
- console.error("Creating new settings file...");
54
- }
55
- }
51
+ let settings = JSON.parse(fs.readFileSync(SETTINGS_FILE, "utf-8"));
52
+ let modified = false;
53
+
54
+ // Remove old hooks key
55
+ if (settings.hooks && Array.isArray(settings.hooks)) {
56
+ delete settings.hooks;
57
+ console.log("\nRemoved old 'hooks' key from settings");
58
+ modified = true;
59
+ }
56
60
 
57
- if (settings.hooks && Array.isArray(settings.hooks) && settings.hooks.length > 0) {
58
- console.log("\nMigrating hooks to extensions...");
59
- if (!Array.isArray(settings.extensions)) {
60
- settings.extensions = [];
61
- }
62
- for (const entry of settings.hooks) {
63
- if (entry.includes("/hooks/rewind")) {
64
- continue;
61
+ // Remove rewind from explicit extensions (auto-discovery handles it now)
62
+ if (Array.isArray(settings.extensions)) {
63
+ const before = settings.extensions.length;
64
+ settings.extensions = settings.extensions.filter(p =>
65
+ !p.includes("/extensions/rewind")
66
+ );
67
+ if (settings.extensions.length < before) {
68
+ console.log("Removed rewind from explicit extensions (auto-discovery handles it)");
69
+ modified = true;
70
+ }
71
+ // Clean up empty extensions array
72
+ if (settings.extensions.length === 0) {
73
+ delete settings.extensions;
74
+ modified = true;
75
+ }
65
76
  }
66
- const newPath = entry.replace("/hooks/", "/extensions/");
67
- if (!settings.extensions.includes(newPath)) {
68
- settings.extensions.push(newPath);
69
- console.log(` Migrated: ${entry} -> ${newPath}`);
77
+
78
+ if (modified) {
79
+ fs.writeFileSync(SETTINGS_FILE, JSON.stringify(settings, null, 2) + "\n");
70
80
  }
81
+ } catch (err) {
82
+ console.error(`Warning: Could not update settings.json: ${err.message}`);
71
83
  }
72
- delete settings.hooks;
73
- console.log("Removed old 'hooks' key from settings");
74
- }
75
-
76
- if (!Array.isArray(settings.extensions)) {
77
- settings.extensions = [];
78
84
  }
79
85
 
80
- const EXT_PATH_ALT = "~/.pi/agent/extensions/rewind";
81
- const hasRewindExt = settings.extensions.some(p =>
82
- p === EXT_PATH || p === EXT_PATH_ALT ||
83
- p.includes("/extensions/rewind/index.ts") ||
84
- p.endsWith("/extensions/rewind")
85
- );
86
-
87
- if (!hasRewindExt) {
88
- settings.extensions.push(EXT_PATH);
89
- console.log(`Added "${EXT_PATH}" to extensions array`);
90
- } else {
91
- console.log("Extension already configured in settings.json");
92
- }
93
-
94
- fs.mkdirSync(path.dirname(SETTINGS_FILE), { recursive: true });
95
- fs.writeFileSync(SETTINGS_FILE, JSON.stringify(settings, null, 2) + "\n");
96
-
86
+ // Clean up old hooks directory
97
87
  if (fs.existsSync(OLD_HOOK_DIR)) {
98
88
  console.log(`\nCleaning up old hooks directory: ${OLD_HOOK_DIR}`);
99
89
  fs.rmSync(OLD_HOOK_DIR, { recursive: true, force: true });
@@ -101,8 +91,8 @@ async function main() {
101
91
  }
102
92
 
103
93
  console.log("\nInstallation complete!");
104
- console.log("\nThe rewind extension will load automatically when you start pi.");
105
- console.log("Use /branch to rewind to a previous checkpoint.");
94
+ console.log("\nThe extension is auto-discovered from ~/.pi/agent/extensions/rewind/");
95
+ console.log("Restart pi to load the extension. Use /branch to rewind to a checkpoint.");
106
96
  }
107
97
 
108
98
  main().catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-rewind-hook",
3
- "version": "1.7.2",
3
+ "version": "1.8.0",
4
4
  "description": "Rewind extension for Pi agent - automatic git checkpoints with file/conversation restore",
5
5
  "bin": {
6
6
  "pi-rewind-hook": "./install.js"
@@ -21,8 +21,12 @@
21
21
  "author": "nicobailon",
22
22
  "license": "MIT",
23
23
  "pi": {
24
- "extensions": [
25
- "./index.ts"
26
- ]
24
+ "extensions": ["./index.ts"]
25
+ },
26
+ "scripts": {
27
+ "test": "npx --yes tsx --tsconfig tsconfig.test.json --test index.test.ts"
28
+ },
29
+ "devDependencies": {
30
+ "@mariozechner/pi-coding-agent": "^0.51.0"
27
31
  }
28
32
  }
@@ -0,0 +1,6 @@
1
+ export function getAgentDir(): string {
2
+ return process.env.PI_CODING_AGENT_DIR ?? "";
3
+ }
4
+
5
+ export type ExtensionAPI = any;
6
+ export type ExtensionContext = any;
@@ -0,0 +1,11 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "baseUrl": ".",
7
+ "paths": {
8
+ "@mariozechner/pi-coding-agent": ["./test-support/pi-coding-agent-shim.ts"]
9
+ }
10
+ }
11
+ }