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/CHANGELOG.md +26 -14
- package/README.md +127 -109
- package/banner.png +0 -0
- package/index.test.ts +602 -0
- package/index.ts +1205 -449
- package/install.js +37 -47
- package/package.json +8 -4
- package/test-support/pi-coding-agent-shim.ts +6 -0
- package/tsconfig.test.json +11 -0
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
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
67
|
-
if (
|
|
68
|
-
|
|
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
|
-
|
|
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
|
|
105
|
-
console.log("Use /branch to rewind to a
|
|
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.
|
|
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
|
-
|
|
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
|
}
|