@agnishc/edb-system-prompt-watch 0.14.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 +5 -0
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/package.json +43 -0
- package/src/index.ts +25 -0
- package/src/state.ts +82 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agnish Chakraborty
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @agnishc/edb-system-prompt-watch
|
|
2
|
+
|
|
3
|
+
A Pi CLI extension that alerts when Pi's bundled default system prompt source changes.
|
|
4
|
+
|
|
5
|
+
This is for setups where you use your own `SYSTEM.md`, but still want to know when Pi's upstream default prompt changed so you can manually review and merge any useful updates.
|
|
6
|
+
|
|
7
|
+
## Behavior
|
|
8
|
+
|
|
9
|
+
On Pi startup, the extension:
|
|
10
|
+
|
|
11
|
+
1. Reads the installed `@earendil-works/pi-coding-agent` package version
|
|
12
|
+
2. Hashes the installed `dist/core/system-prompt.js`
|
|
13
|
+
3. Compares it with the last startup hash stored in `~/.pi/agent/state/system-prompt-watch.json`
|
|
14
|
+
4. Shows a warning if the bundled default system prompt source changed
|
|
15
|
+
5. Stores the current hash as the new baseline
|
|
16
|
+
|
|
17
|
+
First run is silent and only stores the baseline.
|
|
18
|
+
|
|
19
|
+
The extension does not fetch anything from the network and does not modify your custom prompt.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pi install npm:@agnishc/edb-system-prompt-watch
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
[MIT](LICENSE) © Agnish Chakraborty
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agnishc/edb-system-prompt-watch",
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "Pi extension: alert when Pi's bundled default system prompt changes",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi-extension",
|
|
8
|
+
"edb",
|
|
9
|
+
"system-prompt"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "Agnish Chakraborty",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/agnishcc/pi-extention-monorepo.git",
|
|
17
|
+
"directory": "packages/edb-system-prompt-watch"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/agnishcc/pi-extention-monorepo/tree/main/packages/edb-system-prompt-watch#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/agnishcc/pi-extention-monorepo/issues"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "vitest run"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"src",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE",
|
|
33
|
+
"CHANGELOG.md"
|
|
34
|
+
],
|
|
35
|
+
"pi": {
|
|
36
|
+
"extensions": [
|
|
37
|
+
"./src/index.ts"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { checkPromptSource } from "./state";
|
|
3
|
+
|
|
4
|
+
export default function systemPromptWatchExtension(pi: ExtensionAPI): void {
|
|
5
|
+
pi.on("session_start", async (event, ctx) => {
|
|
6
|
+
if (event.reason !== "startup") return;
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
const result = await checkPromptSource();
|
|
10
|
+
if (!result.changed) return;
|
|
11
|
+
|
|
12
|
+
const previousVersion = result.previous?.lastSeenPiVersion ?? "unknown";
|
|
13
|
+
const currentVersion = result.snapshot.piVersion;
|
|
14
|
+
const versionText =
|
|
15
|
+
previousVersion === currentVersion ? currentVersion : `${previousVersion} → ${currentVersion}`;
|
|
16
|
+
|
|
17
|
+
ctx.ui.notify(
|
|
18
|
+
`Pi default system prompt changed (${versionText}). Review your custom SYSTEM.md against the bundled default prompt.`,
|
|
19
|
+
"warning",
|
|
20
|
+
);
|
|
21
|
+
} catch (error: unknown) {
|
|
22
|
+
console.error("[edb-system-prompt-watch] Failed to check Pi default system prompt:", error);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
package/src/state.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { getAgentDir, VERSION } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
|
|
7
|
+
export interface PromptWatchState {
|
|
8
|
+
lastSeenPromptSourceHash?: string;
|
|
9
|
+
lastSeenPiVersion?: string;
|
|
10
|
+
lastSeenPromptSourcePath?: string;
|
|
11
|
+
lastCheckedAt?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface PromptSourceSnapshot {
|
|
15
|
+
piVersion: string;
|
|
16
|
+
promptSourcePath: string;
|
|
17
|
+
promptSourceHash: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PromptWatchResult {
|
|
21
|
+
changed: boolean;
|
|
22
|
+
firstRun: boolean;
|
|
23
|
+
previous?: PromptWatchState;
|
|
24
|
+
snapshot: PromptSourceSnapshot;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function hashText(text: string): string {
|
|
28
|
+
return createHash("sha256").update(text).digest("hex");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getStatePath(): string {
|
|
32
|
+
return join(getAgentDir(), "state", "system-prompt-watch.json");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function readState(statePath = getStatePath()): PromptWatchState | undefined {
|
|
36
|
+
if (!existsSync(statePath)) return undefined;
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
return JSON.parse(readFileSync(statePath, "utf8")) as PromptWatchState;
|
|
40
|
+
} catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function writeState(state: PromptWatchState, statePath = getStatePath()): void {
|
|
46
|
+
mkdirSync(dirname(statePath), { recursive: true });
|
|
47
|
+
writeFileSync(statePath, `${JSON.stringify(state, null, "\t")}\n`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function getPromptSourceSnapshot(): Promise<PromptSourceSnapshot> {
|
|
51
|
+
const packageEntryUrl = await import.meta.resolve("@earendil-works/pi-coding-agent");
|
|
52
|
+
const packageEntry = fileURLToPath(packageEntryUrl);
|
|
53
|
+
const packageRoot = dirname(dirname(packageEntry));
|
|
54
|
+
const promptSourcePath = join(packageRoot, "dist", "core", "system-prompt.js");
|
|
55
|
+
const promptSource = readFileSync(promptSourcePath, "utf8");
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
piVersion: VERSION,
|
|
59
|
+
promptSourcePath,
|
|
60
|
+
promptSourceHash: hashText(promptSource),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function checkPromptSource(previous = readState()): Promise<PromptWatchResult> {
|
|
65
|
+
const snapshot = await getPromptSourceSnapshot();
|
|
66
|
+
const firstRun = !previous?.lastSeenPromptSourceHash;
|
|
67
|
+
const changed = !firstRun && previous.lastSeenPromptSourceHash !== snapshot.promptSourceHash;
|
|
68
|
+
|
|
69
|
+
writeState({
|
|
70
|
+
lastSeenPromptSourceHash: snapshot.promptSourceHash,
|
|
71
|
+
lastSeenPiVersion: snapshot.piVersion,
|
|
72
|
+
lastSeenPromptSourcePath: snapshot.promptSourcePath,
|
|
73
|
+
lastCheckedAt: new Date().toISOString(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
changed,
|
|
78
|
+
firstRun,
|
|
79
|
+
previous,
|
|
80
|
+
snapshot,
|
|
81
|
+
};
|
|
82
|
+
}
|