@robhowley/pi-remembrancer 0.5.1 → 0.6.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.
Files changed (29) hide show
  1. package/README.md +58 -17
  2. package/extensions/remembrancer/capture-artifacts.ts +211 -0
  3. package/extensions/remembrancer/capture-handoff.ts +712 -0
  4. package/extensions/remembrancer/capture-jobs.ts +111 -0
  5. package/extensions/remembrancer/capture-matches.ts +145 -0
  6. package/extensions/remembrancer/capture-notices.ts +51 -0
  7. package/extensions/remembrancer/capture-publication-lock.mjs +37 -0
  8. package/extensions/remembrancer/capture-review.ts +84 -12
  9. package/extensions/remembrancer/capture-sizing.ts +63 -0
  10. package/extensions/remembrancer/capture-submission.ts +289 -0
  11. package/extensions/remembrancer/capture-worker-bootstrap.mjs +53 -0
  12. package/extensions/remembrancer/capture-worker.ts +336 -0
  13. package/extensions/remembrancer/capture.ts +259 -135
  14. package/extensions/remembrancer/checkpoints.ts +603 -116
  15. package/extensions/remembrancer/config.ts +31 -1
  16. package/extensions/remembrancer/evidence.ts +318 -74
  17. package/extensions/remembrancer/index.ts +260 -14
  18. package/extensions/remembrancer/private-sqlite.mjs +17 -0
  19. package/extensions/remembrancer/proposal-read.ts +223 -9
  20. package/extensions/remembrancer/proposal-ui.ts +597 -191
  21. package/extensions/remembrancer/proposals.ts +44 -9
  22. package/extensions/remembrancer/review-findings.ts +178 -0
  23. package/extensions/remembrancer/review-pages.ts +58 -16
  24. package/extensions/remembrancer/review-plan.ts +27 -0
  25. package/extensions/remembrancer/reviewer-budget.ts +53 -0
  26. package/extensions/remembrancer/reviewer.ts +166 -30
  27. package/extensions/remembrancer/taskwarrior.ts +95 -14
  28. package/package.json +5 -4
  29. package/skills/remembrancer/SKILL.md +35 -19
package/README.md CHANGED
@@ -57,7 +57,7 @@ You can also invoke the skill directly:
57
57
 
58
58
  ## Automatic TODO suggestions
59
59
 
60
- Save task suggestions when you leave a session, without asking for a review each time. Capture never changes your Taskwarrior tasks; you approve suggestions later in [Saved proposals](#saved-proposals).
60
+ Save task suggestions when you leave an interactive session. Capture never changes Taskwarrior; you approve suggestions later in [Saved proposals](#saved-proposals).
61
61
 
62
62
  Capture is off by default. To enable it, add this to Pi's global settings file, normally `~/.pi/agent/settings.json`:
63
63
 
@@ -65,12 +65,47 @@ Capture is off by default. To enable it, add this to Pi's global settings file,
65
65
  { "pi-remembrancer": { "autoCapture": true } }
66
66
  ```
67
67
 
68
+ ### Capture controls
69
+
70
+ With automatic capture enabled, run `/remembrancer capture now` to review this session in the background.
71
+
72
+ Available even when automatic capture or the extension is disabled:
73
+
74
+ | Command | Use |
75
+ | ------------------------------------------- | ---------------------------------------------------------------------------- |
76
+ | `/remembrancer capture status` | See job IDs, attempts used/remaining, failures, retry times and blockers. |
77
+ | `/remembrancer capture pause` | Pause queued reviews and cancel running ones. Cancellation may take time. |
78
+ | `/remembrancer capture resume` | Resume paused work without resetting attempts or retry delays. |
79
+ | `/remembrancer capture retry <full-job-id>` | Confirm two fresh attempts for one stopped job in Pi's interactive terminal. |
80
+
81
+ - Turning capture off prevents new jobs. Use **pause** to stop queued or running reviews.
82
+ - Pause survives restarts; new evidence may still queue.
83
+ - For **retry**, copy the full job ID from status.
84
+ - Retry does not unpause capture or skip earlier jobs from that session.
85
+
86
+ **Attempt limits:**
87
+
88
+ - Each job gets **two attempts**, up to five minutes each.
89
+ - Temporary failures wait at least **60 seconds** before retrying; permanent or unknown failures stop.
90
+ - Restarting Pi does not reset used attempts.
91
+ - Delayed retries wait until Pi is running.
92
+
68
93
  ### What to expect
69
94
 
70
- - **When:** your interactive session ends.
71
- - **Scope:** the session you're leaving, but only messages that haven't yet been reviewed.
72
- - **Model:** your session's selected model
73
- - **Result:** proposals and review progress are saved together. Open `/remembrancer proposals` to review them.
95
+ - **When:** you leave an interactive session.
96
+ - **Scope:** unreviewed messages from that session.
97
+ - **Model:** your session's selected model.
98
+ - **Result:** suggestions waiting in `/remembrancer proposals`.
99
+
100
+ Check suggestions before approving them; automatic review can miss tasks or suggest duplicates.
101
+
102
+ Branch aliases and growing draft/task details stay host-side and can be read in bounded pages. Dense messages can return several observation pages before their text range is acknowledged. Discovery pages fit both input and candidate-ID response capacity. Task and saved-proposal discovery includes current fields, effective drafts and saved evidence, not just labels. Large identity values retain exact handles and remain uncertain candidates; plausible or uncertain matches get exact detail, rather than reading every full detail for every obligation.
103
+
104
+ Automatic capture reads one validated Taskwarrior snapshot per attempt, including completed tasks. This private export is limited to 16 MiB; public task commands retain their 1 MiB output limit. Exceeding either limit fails explicitly rather than silently dropping rows.
105
+
106
+ Saved applying/uncertain proposals remain verify-only during capture too. Capture cannot revise them or create a replacement pending suggestion. It can acknowledge a no-op only when the live task proves both the saved operation and the new intent are already satisfied; otherwise the whole attempt fails without saving suggestions or coverage, including unrelated findings in that attempt.
107
+
108
+ All eligible ranges, findings and final dispositions must be processed before the existing atomic save. A failed pass, insufficient model context, cancellation or timeout saves no suggestions or review coverage. The five-minute limit covers the whole attempt, not each call. Splitting does not guarantee that every review can finish within that limit.
74
109
 
75
110
  ## Saved proposals
76
111
 
@@ -82,18 +117,24 @@ Review the suggestions saved by automatic capture in Pi's interactive terminal:
82
117
 
83
118
  At startup, a reminder such as `3 task proposals · /remembrancer proposals` shows how many pending items await review.
84
119
 
85
- Select an item to see its proposed changes, current task, explanation, and saved quotes.
120
+ The queue opens with all proposals collapsed. Expand one to review the proposed changes, target task, explanation, evidence count, and a shortened supporting quote. Source shows full saved quotes in pages; transcript context is optional.
121
+
122
+ | Key | Action |
123
+ | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
124
+ | ↑ / ↓ | Move focus, collapsing the previous proposal and resetting detail scroll. |
125
+ | Enter | Expand or collapse the focused proposal, without changing tasks. |
126
+ | Page Up / Page Down | Scroll the review body; controls stay fixed. |
127
+ | `Ctrl+A` | Collapsed: open review only. Expanded pending: approve and apply. Expanded applying/uncertain: verify only, never replay writes. |
128
+ | `e` | Edit a pending proposal's validated JSON draft. Save refreshes review; cancel keeps the previous draft. The editor owns input until return. |
129
+ | `d` | Dismiss only a pending proposal, leaving tasks unchanged. Shown in both collapsed and expanded views when available. |
130
+ | `s` | Open paged Source. ← / → pages quotes; ↑ / ↓ selects references. Saved quotes remain available without transcript context. Return restores review. |
131
+ | `i` | Inspect the saved proposal and edited draft without changing it. |
132
+ | `h` | Open read-only History of decided proposals. ↑ / ↓ selects; Enter inspects the saved proposal/result. No replay or undo. |
133
+ | Esc | Leave nested inspection, Source, or History first, then collapse review, then close the collapsed queue. |
134
+
135
+ Only explicit per-item approval authorizes task writes. There is no read-every-line or scroll-to-end approval gate. Changed previews require renewed approval. Feedback distinguishes applied, already satisfied, dismissed (task unchanged), and unresolved results. Missing targets, errors, and applying/uncertain items remain visible until a decided result is established.
86
136
 
87
- | Key | Action |
88
- | ------------------- | ---------------------------------------------------------------------- |
89
- | ↑ / ↓ | Select a proposal from the preview. |
90
- | Page Up / Page Down | Scroll details. |
91
- | `Ctrl+A` | Approve and apply the displayed proposal. |
92
- | `e` | Edit and save a pending proposal's JSON draft, without changing tasks. |
93
- | `d` | Dismiss a pending proposal. |
94
- | `s` | View surrounding source context. |
95
- | `h` | View the saved proposal and revision history. |
96
- | Esc | Return from Source/History to the preview, then close. |
137
+ If the terminal is too small to show review content and controls safely, the overlay asks you to resize and prevents application until enough space is restored.
97
138
 
98
139
  ## Track task blockers
99
140
 
@@ -107,7 +148,7 @@ Skip this setup if you do not need waiting conditions; other task operations wor
107
148
 
108
149
  ## Settings
109
150
 
110
- Remembrancer is enabled by default. Turn off remembrancer at any time by adding this to Pi's global settings file, normally `~/.pi/agent/settings.json`:
151
+ Manual Remembrancer features are enabled by default; automatic capture remains opt-in. Disable foreground features and new capture jobs in Pi's global settings file, normally `~/.pi/agent/settings.json` (accepted jobs still run within their persisted allowance unless paused):
111
152
 
112
153
  ```json
113
154
  { "pi-remembrancer": { "disabled": true } }
@@ -0,0 +1,211 @@
1
+ import {
2
+ chmodSync,
3
+ closeSync,
4
+ constants,
5
+ fstatSync,
6
+ lstatSync,
7
+ mkdtempSync,
8
+ openSync,
9
+ readFileSync,
10
+ readSync,
11
+ rmdirSync,
12
+ unlinkSync,
13
+ writeFileSync,
14
+ } from 'node:fs';
15
+ import { tmpdir } from 'node:os';
16
+ import { join } from 'node:path';
17
+ import { fileURLToPath } from 'node:url';
18
+ import { CaptureReview, type PreparedCapturePage } from './capture-review.js';
19
+ import { REVIEW_RESPONSE_MAX_BYTES } from './review-pages.js';
20
+
21
+ export const REMEMBRANCER_SKILL_PATH = fileURLToPath(
22
+ new URL('../../skills/remembrancer/SKILL.md', import.meta.url),
23
+ );
24
+
25
+ export type CaptureArtifactRead = Readonly<{
26
+ text: string;
27
+ /** Host only, after the reviewer accepts this complete text and its budget. */
28
+ accept(): void;
29
+ }>;
30
+
31
+ /** One attempt's generated evidence. The installed skill is read directly, never owned here. */
32
+ export class CaptureArtifacts {
33
+ readonly reviewPath: string;
34
+ readonly skillPath = REMEMBRANCER_SKILL_PATH;
35
+ readonly pageCount: number;
36
+ private readonly directory: string;
37
+ private directoryIdentity: { dev: number; ino: number } | undefined;
38
+ private readonly pages: PreparedCapturePage[];
39
+ private readonly bytes: Buffer;
40
+ private fd: number | undefined;
41
+ private fileCreated = false;
42
+ private closed = false;
43
+ private skillDelivered = false;
44
+
45
+ constructor(private readonly review: CaptureReview) {
46
+ // Missing/unreadable or oversized installed guidance prevents startup. Do not retain it.
47
+ this.readSkill();
48
+ this.pages = [...review.preparePages()];
49
+ this.pageCount = this.pages.length;
50
+ this.bytes = Buffer.from(this.pages.map((page) => page.text + '\n').join(''), 'utf8');
51
+ this.directory = mkdtempSync(join(tmpdir(), 'remembrancer-review-'));
52
+ this.reviewPath = join(this.directory, 'review.jsonl');
53
+ try {
54
+ this.directoryIdentity = lstatSync(this.directory);
55
+ chmodSync(this.directory, 0o700);
56
+ this.fd = openSync(
57
+ this.reviewPath,
58
+ constants.O_CREAT | constants.O_EXCL | constants.O_RDWR | constants.O_NOFOLLOW,
59
+ 0o600,
60
+ );
61
+ this.fileCreated = true;
62
+ if (!fstatSync(this.fd).isFile()) throw new Error('Capture evidence is not a regular file.');
63
+ writeFileSync(this.fd, this.bytes);
64
+ this.assertGenerated();
65
+ } catch (error) {
66
+ try {
67
+ this.dispose();
68
+ } catch (cleanup) {
69
+ throw new AggregateError(
70
+ [error, cleanup],
71
+ 'Capture artifact preparation and cleanup failed.',
72
+ );
73
+ }
74
+ throw error;
75
+ }
76
+ }
77
+
78
+ /** Exact paths only. Evidence pages are zero-based, next-in-order or accepted-page rereads. */
79
+ read(path: string, page = 0): CaptureArtifactRead {
80
+ this.assertOpen();
81
+ if (!Number.isSafeInteger(page) || page < 0) throw new Error('Invalid capture artifact page.');
82
+ if (path === this.skillPath) {
83
+ if (page !== 0) throw new Error('Read the complete installed skill as page zero.');
84
+ const text = this.readSkill();
85
+ return Object.freeze({
86
+ text,
87
+ accept: () => {
88
+ this.assertOpen();
89
+ this.skillDelivered = true;
90
+ },
91
+ });
92
+ }
93
+ if (path !== this.reviewPath) throw new Error('Path is not an allowed capture artifact.');
94
+ this.assertSkillDelivered();
95
+ const prepared = this.pages[page];
96
+ if (!prepared) throw new Error('Invalid capture evidence page.');
97
+ prepared.assertReadable();
98
+ this.assertGenerated();
99
+ return Object.freeze({
100
+ text: prepared.text,
101
+ accept: () => {
102
+ this.assertOpen();
103
+ this.assertGenerated();
104
+ prepared.accept();
105
+ },
106
+ });
107
+ }
108
+
109
+ assertDelivered(): void {
110
+ this.assertOpen();
111
+ this.assertSkillDelivered();
112
+ this.readSkill();
113
+ this.assertGenerated();
114
+ this.review.assertEvidenceDelivered();
115
+ }
116
+
117
+ /** Always attempt every cleanup operation. A failure must prevent publication. */
118
+ dispose(): void {
119
+ this.closed = true;
120
+ const errors: unknown[] = [];
121
+ if (this.fd !== undefined) {
122
+ try {
123
+ closeSync(this.fd);
124
+ this.fd = undefined;
125
+ } catch (error) {
126
+ errors.push(error);
127
+ }
128
+ }
129
+ // Do not recursively remove anything, and never traverse a replaced attempt directory.
130
+ try {
131
+ const directory = lstatSync(this.directory);
132
+ if (
133
+ !directory.isDirectory() ||
134
+ (this.directoryIdentity &&
135
+ (directory.dev !== this.directoryIdentity.dev ||
136
+ directory.ino !== this.directoryIdentity.ino))
137
+ )
138
+ throw new Error('Capture artifact directory changed before cleanup.');
139
+ if (this.fileCreated) {
140
+ try {
141
+ unlinkSync(this.reviewPath);
142
+ this.fileCreated = false;
143
+ } catch (error) {
144
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') errors.push(error);
145
+ }
146
+ }
147
+ try {
148
+ rmdirSync(this.directory);
149
+ } catch (error) {
150
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') errors.push(error);
151
+ }
152
+ } catch (error) {
153
+ if ((error as NodeJS.ErrnoException).code !== 'ENOENT') errors.push(error);
154
+ }
155
+ if (errors.length) throw new AggregateError(errors, 'Capture artifact cleanup failed.');
156
+ }
157
+
158
+ private assertOpen(): void {
159
+ if (this.closed) throw new Error('Capture artifacts are closed.');
160
+ }
161
+
162
+ /** Guard every other reviewer-facing lookup with this, not only evidence reads. */
163
+ assertSkillDelivered(): void {
164
+ this.assertOpen();
165
+ if (!this.skillDelivered)
166
+ throw new Error('Read and accept the complete installed skill first.');
167
+ }
168
+
169
+ private readSkill(): string {
170
+ const text = readFileSync(this.skillPath, 'utf8');
171
+ if (Buffer.byteLength(text, 'utf8') > REVIEW_RESPONSE_MAX_BYTES)
172
+ throw new Error('The complete installed skill exceeds the capture read limit.');
173
+ return text;
174
+ }
175
+
176
+ private assertGenerated(): void {
177
+ this.assertOpen();
178
+ if (this.fd === undefined) throw new Error('Capture evidence descriptor is closed.');
179
+ const directory = lstatSync(this.directory);
180
+ const file = lstatSync(this.reviewPath);
181
+ const retained = fstatSync(this.fd);
182
+ if (
183
+ !this.directoryIdentity ||
184
+ !directory.isDirectory() ||
185
+ directory.dev !== this.directoryIdentity.dev ||
186
+ directory.ino !== this.directoryIdentity.ino ||
187
+ !file.isFile() ||
188
+ !retained.isFile() ||
189
+ file.dev !== retained.dev ||
190
+ file.ino !== retained.ino ||
191
+ retained.size !== this.bytes.length
192
+ )
193
+ throw new Error('Capture evidence file changed.');
194
+ const chunk = Buffer.alloc(Math.min(64 * 1024, this.bytes.length));
195
+ let offset = 0;
196
+ while (offset < this.bytes.length) {
197
+ const count = readSync(
198
+ this.fd,
199
+ chunk,
200
+ 0,
201
+ Math.min(chunk.length, this.bytes.length - offset),
202
+ offset,
203
+ );
204
+ if (!count || !chunk.subarray(0, count).equals(this.bytes.subarray(offset, offset + count)))
205
+ throw new Error('Capture evidence bytes changed.');
206
+ offset += count;
207
+ }
208
+ if (fstatSync(this.fd).size !== this.bytes.length)
209
+ throw new Error('Capture evidence file changed.');
210
+ }
211
+ }