pi-rebrief 0.0.0-stage → 0.0.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.
Potentially problematic release.
This version of pi-rebrief might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/README.md +45 -2
- package/index.ts +155 -0
- package/package.json +47 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ariel Sakin
|
|
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
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pi-rebrief
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://snyk.io/test/github/asakin/pi-rebrief)
|
|
4
|
+
|
|
5
|
+
A [Pi](https://pi.dev) extension that adds a `/rebrief` command. It reloads only the
|
|
6
|
+
project context files, including `AGENTS.md` and `CLAUDE.md`, into a running session, and
|
|
7
|
+
tells you which files changed. It loads them with the same function Pi uses, so it picks up
|
|
8
|
+
whatever files your Pi version discovers.
|
|
9
|
+
|
|
10
|
+
Pi's own `/reload` also re-reads context files, but along with everything else: settings,
|
|
11
|
+
extensions, MCP servers, skills and themes. `/rebrief` leaves all of that running.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pi install npm:pi-rebrief
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then run `/reload` in an active session, or try it for a single session without installing:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pi -e npm:pi-rebrief
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
Edit a context file, then run:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
/rebrief
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The next turn sees the new instructions, and so does every turn after it. `/rebrief` reports
|
|
34
|
+
what it found, for example:
|
|
35
|
+
|
|
36
|
+
- `Reloaded context files: changed AGENTS.md, added sub/AGENTS.md.`
|
|
37
|
+
- `Context files unchanged (2 context files).`
|
|
38
|
+
|
|
39
|
+
If Pi was started with `--no-context-files`, `/rebrief` does nothing.
|
|
40
|
+
|
|
41
|
+
Pair it with `/tree` to rewind a couple of turns, tighten an instruction in `AGENTS.md`,
|
|
42
|
+
run `/rebrief`, and continue from before the derail.
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT
|
package/index.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionCommandContext,
|
|
4
|
+
} from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { getAgentDir, loadProjectContextFiles } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { isAbsolute, relative, sep } from "node:path";
|
|
8
|
+
|
|
9
|
+
export interface ContextFile {
|
|
10
|
+
path: string;
|
|
11
|
+
content: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface RebriefDeps {
|
|
15
|
+
getAgentDir?: () => string;
|
|
16
|
+
loadProjectContextFiles?: (options: { cwd: string; agentDir: string }) => ContextFile[];
|
|
17
|
+
contextFilesDisabled?: () => boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Check if Pi was started with --no-context-files (-nc); extensions can't read built-in flags
|
|
21
|
+
export function contextFilesDisabledByArgv(argv: readonly string[]): boolean {
|
|
22
|
+
return argv.includes("--no-context-files") || argv.includes("-nc");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Check if two sets of context files are the same
|
|
26
|
+
export function sameContextFiles(a: readonly ContextFile[], b: readonly ContextFile[]): boolean {
|
|
27
|
+
if (a.length !== b.length) return false;
|
|
28
|
+
for (let i = 0; i < a.length; i++) {
|
|
29
|
+
const left = a[i]!;
|
|
30
|
+
const right = b[i]!;
|
|
31
|
+
if (left.path !== right.path || left.content !== right.content) return false;
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Show a path relative to cwd when inside it, else home-relative, else absolute
|
|
37
|
+
function displayPath(path: string, cwd: string, home: string): string {
|
|
38
|
+
const rel = relative(cwd, path);
|
|
39
|
+
if (rel && !rel.startsWith("..") && !isAbsolute(rel)) return rel;
|
|
40
|
+
if (home && path.startsWith(home + sep)) return `~${path.slice(home.length)}`;
|
|
41
|
+
return path;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const MAX_LISTED = 3;
|
|
45
|
+
|
|
46
|
+
// Summarize which context files changed, were added, or were removed
|
|
47
|
+
export function describeChanges(
|
|
48
|
+
previous: readonly ContextFile[],
|
|
49
|
+
fresh: readonly ContextFile[],
|
|
50
|
+
cwd: string,
|
|
51
|
+
home: string = homedir(),
|
|
52
|
+
): string {
|
|
53
|
+
const before = new Map(previous.map((file) => [file.path, file.content]));
|
|
54
|
+
const after = new Set(fresh.map((file) => file.path));
|
|
55
|
+
const entries: string[] = [];
|
|
56
|
+
for (const file of fresh) {
|
|
57
|
+
const old = before.get(file.path);
|
|
58
|
+
if (old === undefined) entries.push(`added ${displayPath(file.path, cwd, home)}`);
|
|
59
|
+
else if (old !== file.content) entries.push(`changed ${displayPath(file.path, cwd, home)}`);
|
|
60
|
+
}
|
|
61
|
+
for (const file of previous) {
|
|
62
|
+
if (!after.has(file.path)) entries.push(`removed ${displayPath(file.path, cwd, home)}`);
|
|
63
|
+
}
|
|
64
|
+
if (entries.length === 0) return "order changed";
|
|
65
|
+
|
|
66
|
+
// "changed a, b" instead of "changed a, changed b"
|
|
67
|
+
const merged: string[] = [];
|
|
68
|
+
let lastVerb = "";
|
|
69
|
+
for (const entry of entries.slice(0, MAX_LISTED)) {
|
|
70
|
+
const [verb] = entry.split(" ", 1);
|
|
71
|
+
merged.push(verb === lastVerb ? entry.slice(verb!.length + 1) : entry);
|
|
72
|
+
lastVerb = verb!;
|
|
73
|
+
}
|
|
74
|
+
const more = entries.length - MAX_LISTED;
|
|
75
|
+
return more > 0 ? `${merged.join(", ")}, and ${more} more` : merged.join(", ");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Format the number of context files into a human-readable string
|
|
79
|
+
function fileCountLabel(count: number): string {
|
|
80
|
+
return `${count} context file${count === 1 ? "" : "s"}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Clone the context files
|
|
84
|
+
function cloneContextFiles(files: readonly ContextFile[]): ContextFile[] {
|
|
85
|
+
return files.map((file) => ({ path: file.path, content: file.content }));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Create the rebrief extension
|
|
89
|
+
export function createRebriefExtension(deps: RebriefDeps = {}) {
|
|
90
|
+
const resolveAgentDir = deps.getAgentDir ?? getAgentDir;
|
|
91
|
+
const loadContextFiles = deps.loadProjectContextFiles ?? loadProjectContextFiles;
|
|
92
|
+
const contextFilesDisabled = deps.contextFilesDisabled ?? (() => contextFilesDisabledByArgv(process.argv));
|
|
93
|
+
|
|
94
|
+
return function piRebrief(pi: ExtensionAPI) {
|
|
95
|
+
let rebriefed: { cwd: string; files: ContextFile[] } | undefined;
|
|
96
|
+
|
|
97
|
+
pi.on("session_start", () => {
|
|
98
|
+
rebriefed = undefined;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
pi.registerCommand("rebrief", {
|
|
102
|
+
description: "Reload only context files (lighter than /reload)",
|
|
103
|
+
handler: async (_args: string, ctx: ExtensionCommandContext) => {
|
|
104
|
+
if (contextFilesDisabled()) {
|
|
105
|
+
if (ctx.hasUI) {
|
|
106
|
+
ctx.ui.notify("Context files are disabled (--no-context-files) — nothing to rebrief.", "warning");
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let freshFiles: ContextFile[];
|
|
112
|
+
try {
|
|
113
|
+
freshFiles = loadContextFiles({
|
|
114
|
+
cwd: ctx.cwd,
|
|
115
|
+
agentDir: resolveAgentDir(),
|
|
116
|
+
});
|
|
117
|
+
} catch (err) {
|
|
118
|
+
if (ctx.hasUI) {
|
|
119
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
120
|
+
ctx.ui.notify(`Failed to reload context files: ${detail}`, "error");
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const baseOptions = ctx.getSystemPromptOptions?.();
|
|
126
|
+
const previousFiles =
|
|
127
|
+
rebriefed?.cwd === ctx.cwd
|
|
128
|
+
? rebriefed.files
|
|
129
|
+
: (baseOptions?.contextFiles ?? []);
|
|
130
|
+
const changed = !sameContextFiles(previousFiles, freshFiles);
|
|
131
|
+
|
|
132
|
+
rebriefed = { cwd: ctx.cwd, files: cloneContextFiles(freshFiles) };
|
|
133
|
+
if (baseOptions) {
|
|
134
|
+
baseOptions.contextFiles = cloneContextFiles(freshFiles);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!ctx.hasUI) return;
|
|
138
|
+
|
|
139
|
+
if (!changed) {
|
|
140
|
+
ctx.ui.notify(`Context files unchanged (${fileCountLabel(freshFiles.length)}).`, "info");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
ctx.ui.notify(`Reloaded context files: ${describeChanges(previousFiles, freshFiles, ctx.cwd)}.`, "info");
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
pi.on("before_agent_start", async (event) => {
|
|
149
|
+
if (!rebriefed || rebriefed.cwd !== event.systemPromptOptions.cwd) return;
|
|
150
|
+
event.systemPromptOptions.contextFiles = cloneContextFiles(rebriefed.files);
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export default createRebriefExtension();
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-rebrief",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Reload only the project context files, including AGENTS.md and CLAUDE.md, into a running Pi session: no extension restart or MCP reconnect like /reload, plus a report of what changed.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"pi-package",
|
|
8
|
+
"pi-extension",
|
|
9
|
+
"pi-coding-agent",
|
|
10
|
+
"pi",
|
|
11
|
+
"agents-md",
|
|
12
|
+
"claude-md",
|
|
13
|
+
"context-files",
|
|
14
|
+
"reload",
|
|
15
|
+
"system-prompt"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "Ariel Sakin <asakin@gmail.com>",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/asakin/pi-rebrief.git"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/asakin/pi-rebrief#readme",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/asakin/pi-rebrief/issues"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"index.ts",
|
|
29
|
+
"README.md",
|
|
30
|
+
"LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"pi": {
|
|
33
|
+
"extensions": [
|
|
34
|
+
"./index.ts"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"check": "tsc --noEmit",
|
|
39
|
+
"test": "node --test"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@earendil-works/pi-coding-agent": "^1.0.0",
|
|
46
|
+
"@types/node": ">=22.0.0",
|
|
47
|
+
"typescript": ">=5.0.0"
|
|
48
|
+
}
|
|
49
|
+
}
|