@hcflabs/pi-notes 3.2.4 → 3.3.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/README.md +9 -5
- package/extensions/notes.ts +33 -8
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ pi install npm:@hcflabs/pi-notes
|
|
|
12
12
|
|
|
13
13
|
## Use
|
|
14
14
|
|
|
15
|
-
Run `/note Verify the migration rollback.` in a Git worktree. The reminder appears immediately and in later sessions.
|
|
15
|
+
Run `/note Verify the migration rollback.` in a Git worktree or any other directory. The reminder appears immediately and in later sessions.
|
|
16
16
|
|
|
17
17
|
These commands and the widget are for people.
|
|
18
18
|
|
|
@@ -23,16 +23,20 @@ These commands and the widget are for people.
|
|
|
23
23
|
| `/note-clear` | command | Clear worktree notes. |
|
|
24
24
|
| Notes widget | ui | Show worktree notes. |
|
|
25
25
|
|
|
26
|
-
Each worktree has separate notes. The TUI numbers notes and limits each to two lines. Other modes show plain text without that limit. Empty widgets stay hidden.
|
|
26
|
+
Each worktree has separate notes. Outside a Git repository, for example in a parent directory that holds many repositories, the notes belong to the real path of the working directory. A subdirectory of that directory has its own notes. The TUI numbers notes and limits each to two lines. Other modes show plain text without that limit. Empty widgets stay hidden.
|
|
27
27
|
|
|
28
28
|
## State and storage
|
|
29
29
|
|
|
30
|
-
Commands save notes to `~/.pi/agent/config/pi-notes/<worktree-sha256>.json`.
|
|
30
|
+
Commands save notes to `~/.pi/agent/config/pi-notes/<worktree-sha256>.json`. Outside a Git repository, the hash is of the real path of the working directory.
|
|
31
31
|
|
|
32
|
-
Session start and note changes silently delete stale files for removed repositories and
|
|
32
|
+
Session start and note changes silently delete stale files for removed repositories, worktrees, and directories.
|
|
33
|
+
|
|
34
|
+
If a directory with notes becomes a Git repository, the old notes do not apply to it. The widget shows `Worktree notes belong to an old worktree; run /note-clear to reset.`
|
|
33
35
|
|
|
34
36
|
## Limits and recovery
|
|
35
37
|
|
|
36
|
-
Each worktree holds at most four notes. `/note` trims surrounding whitespace and replaces whitespace sequences with one space. It rejects remaining control characters with `Notes cannot contain terminal control characters.`
|
|
38
|
+
Each worktree or directory holds at most four notes. `/note` trims surrounding whitespace and replaces whitespace sequences with one space. It rejects remaining control characters with `Notes cannot contain terminal control characters.`
|
|
37
39
|
|
|
38
40
|
The extension validates files as untrusted data. Malformed files stay unchanged and block changes for their worktree. Fix the file or reset it with `/note-clear`.
|
|
41
|
+
|
|
42
|
+
Git failures other than "not a Git repository" are errors. Examples are a Git timeout, a missing `git` program, and a bare repository. The commands show the error and change no file. The widget stays empty.
|
package/extensions/notes.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type ExtensionContext,
|
|
8
8
|
} from "@earendil-works/pi-coding-agent";
|
|
9
9
|
import { extensionConfigDir, writePrivateTextFileAtomically } from "@hcflabs/pi-config-store";
|
|
10
|
+
import { gitTopLevel } from "@hcflabs/pi-repo";
|
|
10
11
|
import { truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
11
12
|
|
|
12
13
|
const MAX_NOTES = 4;
|
|
@@ -81,13 +82,23 @@ function setNotesWidget(ctx: ExtensionContext, notes: string[]): void {
|
|
|
81
82
|
}));
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Read the identity of the Git worktree that contains `cwd`.
|
|
87
|
+
* Return `undefined` when `cwd` is outside a Git repository.
|
|
88
|
+
* Other Git failures throw, for example a timeout, a missing Git program, or a bare repository.
|
|
89
|
+
*/
|
|
90
|
+
async function gitWorktree(pi: ExtensionAPI, cwd: string): Promise<WorktreeIdentity | undefined> {
|
|
85
91
|
const result = await pi.exec(
|
|
86
92
|
"git",
|
|
87
93
|
["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-common-dir", "--git-dir"],
|
|
88
94
|
{ cwd },
|
|
89
95
|
);
|
|
90
|
-
if (result.
|
|
96
|
+
if (result.killed) throw new Error(`git did not finish in ${cwd}`);
|
|
97
|
+
if (result.code !== 0) {
|
|
98
|
+
// gitTopLevel decides without Git messages, so the answer does not depend on the Git locale.
|
|
99
|
+
if (await gitTopLevel(cwd) === undefined) return undefined;
|
|
100
|
+
throw new Error(`git rev-parse failed in ${cwd} with exit ${result.code}`);
|
|
101
|
+
}
|
|
91
102
|
const [worktree, repository, gitDir, ...extra] = result.stdout.trim().split(/\r?\n/);
|
|
92
103
|
if (!worktree || !repository || !gitDir || extra.length) throw new Error("git returned an invalid worktree identity");
|
|
93
104
|
const [canonicalWorktree, canonicalRepository, canonicalGitDir] = await Promise.all([
|
|
@@ -103,6 +114,18 @@ async function resolveWorktree(pi: ExtensionAPI, cwd: string): Promise<WorktreeI
|
|
|
103
114
|
};
|
|
104
115
|
}
|
|
105
116
|
|
|
117
|
+
/** Outside a Git repository, the real path of the directory names the notes. The three paths are equal. */
|
|
118
|
+
async function directoryIdentity(cwd: string): Promise<WorktreeIdentity> {
|
|
119
|
+
const directory = await realpath(cwd);
|
|
120
|
+
return { worktree: directory, repository: directory, gitDir: directory, generation: await worktreeGeneration(directory) };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const isDirectoryIdentity = ({ worktree, repository, gitDir }: WorktreeIdentity) => worktree === repository && repository === gitDir;
|
|
124
|
+
|
|
125
|
+
async function resolveWorktree(pi: ExtensionAPI, cwd: string): Promise<WorktreeIdentity> {
|
|
126
|
+
return await gitWorktree(pi, cwd) ?? await directoryIdentity(cwd);
|
|
127
|
+
}
|
|
128
|
+
|
|
106
129
|
async function loadNotes(identity: WorktreeIdentity): Promise<{ notes: string[]; message?: string }> {
|
|
107
130
|
let raw: string;
|
|
108
131
|
try {
|
|
@@ -186,13 +209,15 @@ async function pruneStale(pi: ExtensionAPI): Promise<void> {
|
|
|
186
209
|
if (code === "ENOENT" || code === "ENOTDIR") stale = true;
|
|
187
210
|
else continue;
|
|
188
211
|
}
|
|
189
|
-
|
|
190
|
-
|
|
212
|
+
// A directory record has no Git identity to compare. If the directory becomes a repository, /note-clear resets it.
|
|
213
|
+
if (!stale && !isDirectoryIdentity(record)) {
|
|
214
|
+
let current: WorktreeIdentity | undefined;
|
|
191
215
|
try {
|
|
192
|
-
current = await
|
|
216
|
+
current = await gitWorktree(pi, record.worktree);
|
|
193
217
|
} catch {
|
|
194
218
|
continue;
|
|
195
219
|
}
|
|
220
|
+
if (!current) continue;
|
|
196
221
|
const { notes, ...identity } = record;
|
|
197
222
|
stale = !isDeepStrictEqual(current, identity);
|
|
198
223
|
}
|
|
@@ -215,7 +240,7 @@ export default function notesExtension(pi: ExtensionAPI): void {
|
|
|
215
240
|
});
|
|
216
241
|
|
|
217
242
|
pi.registerCommand("note", {
|
|
218
|
-
description: `Add a note to this Git worktree (max ${MAX_NOTES})`,
|
|
243
|
+
description: `Add a note to this Git worktree or directory (max ${MAX_NOTES})`,
|
|
219
244
|
handler: async (args, ctx) => {
|
|
220
245
|
const text = args.replace(/\s+/g, " ").trim();
|
|
221
246
|
if (!text) {
|
|
@@ -240,7 +265,7 @@ export default function notesExtension(pi: ExtensionAPI): void {
|
|
|
240
265
|
});
|
|
241
266
|
|
|
242
267
|
pi.registerCommand("note-rm", {
|
|
243
|
-
description: "Remove a note from this Git worktree",
|
|
268
|
+
description: "Remove a note from this Git worktree or directory",
|
|
244
269
|
handler: async (args, ctx) => {
|
|
245
270
|
if (args.trim()) {
|
|
246
271
|
ctx.ui.notify("Usage: /note-rm", "warning");
|
|
@@ -270,7 +295,7 @@ export default function notesExtension(pi: ExtensionAPI): void {
|
|
|
270
295
|
});
|
|
271
296
|
|
|
272
297
|
pi.registerCommand("note-clear", {
|
|
273
|
-
description: "Clear notes for this Git worktree",
|
|
298
|
+
description: "Clear notes for this Git worktree or directory",
|
|
274
299
|
handler: async (args, ctx) => {
|
|
275
300
|
if (args.trim()) {
|
|
276
301
|
ctx.ui.notify("Usage: /note-clear", "warning");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hcflabs/pi-notes",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Persistent notes in a Pi widget, managed with /note commands.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"pack:check": "npm pack --dry-run"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@earendil-works/pi-coding-agent": "^1.
|
|
29
|
-
"@earendil-works/pi-tui": "^1.
|
|
28
|
+
"@earendil-works/pi-coding-agent": "^1.6.0",
|
|
29
|
+
"@earendil-works/pi-tui": "^1.6.0"
|
|
30
30
|
},
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
@@ -46,10 +46,11 @@
|
|
|
46
46
|
"image": "https://raw.githubusercontent.com/hcflabs/pi-harness/main/extensions/pi-notes/example.png"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@hcflabs/pi-config-store": "^4.0.0"
|
|
49
|
+
"@hcflabs/pi-config-store": "^4.0.0",
|
|
50
|
+
"@hcflabs/pi-repo": "^0.1.0"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
53
|
-
"@earendil-works/pi-tui": "1.
|
|
53
|
+
"@earendil-works/pi-coding-agent": "1.6.0",
|
|
54
|
+
"@earendil-works/pi-tui": "1.6.0"
|
|
54
55
|
}
|
|
55
56
|
}
|