@aeondave/pi-persona-mind 0.8.4 → 0.8.5
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/AGENTS.md +2 -1
- package/CHANGELOG.md +6 -0
- package/README.md +7 -11
- package/docs/DESIGN.md +4 -2
- package/package.json +2 -2
- package/src/extension/auto-optimize-session.ts +2 -0
- package/src/extension/auto-optimize.ts +66 -33
- package/src/extension/mind-command.ts +30 -8
package/AGENTS.md
CHANGED
|
@@ -44,7 +44,8 @@ coupled through a versioned local companion handshake to
|
|
|
44
44
|
not a boolean. Existing persona facts are not automatically reassigned. STM/backlog auto-delete after ~48h. Explicit session notes live
|
|
45
45
|
in Pi's native active branch, survive compaction/resume, and stay absent from delegated workers.
|
|
46
46
|
A non-persistent host session reports in-memory storage; forget is a branch-local tombstone.
|
|
47
|
-
-
|
|
47
|
+
- `/mind optimize [project|project-long|persona]` starts one bounded real Persona-hosted LLM review NOW, bypassing automatic dirty/token/cooldown and auto-off gates but not owner, busy, validation or CAS safeguards. It uses the existing worker/prompt/strict JSON/provenance/preview/apply/receipt pipeline, exact current model only, no fallback/tools, and reports bounded coverage/no-op honestly. Shared is refused with a pointer to `/mind optimize inspect shared`; it is excluded from all LLM automatic and explicit writes. `/mind optimize inspect [target]` stays read-only. Do not publish a separate persistent activity row for full optimization; let Persona's normal worker row terminate. Interrupted/stale explicit runs never apply, report across owner change, or arm an automatic retry.
|
|
48
|
+
- Optimization inspect/stage exact replacements/apply a short-lived plan ID remains available through explicit inspect/show/apply commands and the memory tool. Similarity
|
|
48
49
|
is advisory. Compare the original raw store fingerprint under its lock; reject stale/expired
|
|
49
50
|
plans, invalid stores, ownership mixing, provenance overflow and extended STM expiry.
|
|
50
51
|
Lifecycle changes invalidate plans. Automatic semantic review is user-authorized and on by default
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.8.5](https://github.com/AeonDave/pi-persona-mind/releases/tag/v0.8.5) - 2026-10-26
|
|
4
|
+
|
|
5
|
+
- Add `/mind optimize [project|project-long|persona]` for an immediate, bounded review by a visible Persona-hosted worker using the current session model. Changes pass Mind's validation, provenance and compare-and-swap checks; successful writes retain receipts and support guarded undo.
|
|
6
|
+
- Remove the worker row on completion while retaining results in the conversation. Keep reviews bounded, rotate completed windows, and handle busy sessions, cancellation, stale owners and errors safely.
|
|
7
|
+
- **Usage change:** use `/mind optimize inspect [target]` to inspect; `/mind optimize [target]` now starts a review instead.
|
|
8
|
+
|
|
3
9
|
## [0.8.4](https://github.com/AeonDave/pi-persona-mind/releases/tag/v0.8.4) - 2026-10-25
|
|
4
10
|
|
|
5
11
|
- Add durable project memory and scope-preserving promotion; expose project/persona/shared scope
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<h1 align="center">pi-persona-mind</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<img src="https://raw.githubusercontent.com/AeonDave/pi-persona-mind/v0.8.
|
|
4
|
+
<img src="https://raw.githubusercontent.com/AeonDave/pi-persona-mind/v0.8.5/assets/banner.png" alt="pi-persona-mind — durable memory for Pi">
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
[](https://github.com/AeonDave/pi-persona-mind/actions/workflows/test.yml) [](https://www.npmjs.com/package/@aeondave/pi-persona-mind) [](LICENSE)
|
|
@@ -10,7 +10,7 @@ Local memory for [Pi](https://github.com/earendil-works/pi): durable facts, sess
|
|
|
10
10
|
unfinished work. Bounded excerpts enter each turn; the agent can retrieve full entries when needed.
|
|
11
11
|
|
|
12
12
|
Requires a compatible loaded [pi-persona](https://github.com/AeonDave/pi-persona). The current
|
|
13
|
-
release pair is Mind 0.8.
|
|
13
|
+
release pair is Mind 0.8.5 with Persona 1.17.5 or later.
|
|
14
14
|
Stores use local files and Pi's session history, without embeddings, a database or a separate service.
|
|
15
15
|
Automatic consolidation uses a visible Mind worker on your current session model. Memory injection and
|
|
16
16
|
worker review consume normal model tokens. A saved claim is not automatically a verified fact.
|
|
@@ -32,7 +32,7 @@ with no memory capture, writes, injection or reminders.
|
|
|
32
32
|
| Install option | Command |
|
|
33
33
|
|---|---|
|
|
34
34
|
| This project only | `pi install -l npm:@aeondave/pi-persona-mind` |
|
|
35
|
-
| Pin Mind 0.8.
|
|
35
|
+
| Pin Mind 0.8.5 | `pi install npm:@aeondave/pi-persona-mind@0.8.5` |
|
|
36
36
|
| Update the unpinned pair | `pi update npm:@aeondave/pi-persona`<br>`pi update npm:@aeondave/pi-persona-mind` |
|
|
37
37
|
|
|
38
38
|
When switching either extension from a Git install to npm, remove its exact Git source first (use
|
|
@@ -80,7 +80,8 @@ source reference. A result reference is provenance, not permission to read anoth
|
|
|
80
80
|
| `/persona-mind reset` | Clear this project's short-term facts and backlog |
|
|
81
81
|
| `/persona-mind reset workspace` | Same explicit workspace reset |
|
|
82
82
|
| `/persona-mind migrate-persona` | Recover an ambiguous historical persona-data alias |
|
|
83
|
-
| `/persona-mind optimize [project\|project-long\|persona
|
|
83
|
+
| `/persona-mind optimize [project\|project-long\|persona]` | Request one visible Persona-hosted LLM review; defaults to `project` |
|
|
84
|
+
| `/persona-mind optimize inspect [project\|project-long\|persona\|shared]` | Read-only bounded inspection |
|
|
84
85
|
| `/persona-mind optimize show <planId>` | Display an already staged plan |
|
|
85
86
|
| `/persona-mind optimize apply <planId>` | Apply that exact plan if still current |
|
|
86
87
|
| `/persona-mind optimize history [target]` | Review retained before/after receipts; default `project` |
|
|
@@ -117,9 +118,7 @@ The retrieval is deterministic; it does not infer arbitrary synonyms or establis
|
|
|
117
118
|
|
|
118
119
|
## Review and consolidate
|
|
119
120
|
|
|
120
|
-
|
|
121
|
-
The slash command alone is a local inspection, not a hidden model request. The agent evaluates
|
|
122
|
-
the evidence during its normal foreground turn.
|
|
121
|
+
`/mind optimize [project|project-long|persona]` requests one bounded review in the real visible Persona worker; the command returns before inspection and worker admission. It bypasses automatic preference/token/cooldown gates, but refuses busy sessions, overlap and stale owners. It uses the session model and the validated preview/CAS/apply/undo pipeline. Use `/mind optimize inspect [target]` for explicitly read-only inspection. `shared` is excluded from LLM optimization and must be inspected and handled through a manually reviewed workflow.
|
|
123
122
|
|
|
124
123
|
1. `memory {action:"optimize", mode:"inspect", target:"project"}` returns IDs and a fingerprint.
|
|
125
124
|
2. Read full facts, then stage explicit replacements with that fingerprint and
|
|
@@ -147,10 +146,7 @@ Exact deduplication and expiry cleanup already run automatically. Lexical simila
|
|
|
147
146
|
comparisons; it cannot distinguish agreement from contradiction. Age never deletes a durable fact.
|
|
148
147
|
See [research and decisions](docs/MEMORY-RESEARCH.md).
|
|
149
148
|
|
|
150
|
-
|
|
151
|
-
view. The row distinguishes local work, a prepared proposal and a terminal result.
|
|
152
|
-
It does not invent a worker model, tokens or a cancellable agent. Finished rows are bounded and
|
|
153
|
-
remain visible, so a fast local operation does not disappear before it can be read.
|
|
149
|
+
Local inspect/stage/apply activity uses Mind activity rows. Full `/mind optimize` runs appear as ordinary Persona worker rows; the host removes those rows on terminal completion. The full review does not create a separate sticky activity row.
|
|
154
150
|
|
|
155
151
|
Automatic review is on by default. Successful saves/promotions mark project or persona memories
|
|
156
152
|
for review; shared memories are excluded. The first eligible burst can run after the main agent
|
package/docs/DESIGN.md
CHANGED
|
@@ -14,7 +14,7 @@ patch an installed host.
|
|
|
14
14
|
Mind requires a loaded compatible pi-persona through its versioned local companion handshake.
|
|
15
15
|
Missing/incompatible presence leaves tools inactive and suppresses capture, storage/import,
|
|
16
16
|
injection and reminders. A settings file or installed npm package is not proof of an active
|
|
17
|
-
companion. Mind 0.8.
|
|
17
|
+
companion. Mind 0.8.5 requires Persona 1.17.5 or later for these paired contracts. Its optional npm
|
|
18
18
|
peer declares that requirement without auto-installing or activating another extension.
|
|
19
19
|
|
|
20
20
|
The node-only core has no Pi imports. The factory wires native Pi hooks, tools, scope, scheduling
|
|
@@ -109,7 +109,9 @@ An in-memory session is not advertised as restart-durable.
|
|
|
109
109
|
|
|
110
110
|
## Explicit consolidation
|
|
111
111
|
|
|
112
|
-
The
|
|
112
|
+
`/mind optimize [project|project-long|persona]` launches one real visible Persona-hosted LLM review pass using the exact session model and existing worker admission, prompt, strict JSON validation, provenance, preview, CAS apply and durable receipt pipeline. It bypasses automatic dirty/token/cooldown/auto-off gates, but honors the one-worker-per-instance and current owner checks. The command returns after scheduler acceptance, before store inspection or worker admission; the toast says the review was requested and is preparing. Completion is handled in the background and displayed as ordinary Mind result cards, without a separate activity row. A pass is bounded to one selected record window; reports state bounded coverage/no-op and never claim whole-store review. Interrupted/stale work cannot apply, emit stale reports or schedule a manual retry. Shared is explicitly refused for LLM review and points to `/mind optimize inspect shared` plus manual review. Read-only inspection is `/mind optimize inspect [target]`; default optimize target remains project.
|
|
113
|
+
|
|
114
|
+
The manual workflow is inspect → stage exact replacements → apply plan ID. An omitted replacement tag
|
|
113
115
|
list inherits the normalized union from selected sources; an explicit empty list clears tags. Lexical
|
|
114
116
|
rules never approve semantic changes. Learned decay rates, recall counters and age-based LTM deletion
|
|
115
117
|
remain outside the contract.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeondave/pi-persona-mind",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Local memory for Pi with pi-persona — durable project and persona facts, session notes, bounded retrieval, and supervised automatic consolidation.",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"pi": {
|
|
60
|
-
"image": "https://raw.githubusercontent.com/AeonDave/pi-persona-mind/v0.8.
|
|
60
|
+
"image": "https://raw.githubusercontent.com/AeonDave/pi-persona-mind/v0.8.5/assets/banner.png",
|
|
61
61
|
"extensions": [
|
|
62
62
|
"./src/index.ts"
|
|
63
63
|
]
|
|
@@ -40,6 +40,7 @@ export interface AutoOptimizeSession {
|
|
|
40
40
|
memoryAdded(ctx: ExtensionContext, target: AutoOptimizeTarget): void;
|
|
41
41
|
status(): string;
|
|
42
42
|
setEnabled(enabled: boolean): void;
|
|
43
|
+
startExplicit(target: AutoOptimizeTarget): boolean;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export function installAutoOptimize(pi: ExtensionAPI, deps: Dependencies): AutoOptimizeSession {
|
|
@@ -114,5 +115,6 @@ export function installAutoOptimize(pi: ExtensionAPI, deps: Dependencies): AutoO
|
|
|
114
115
|
return { activate, revoke, memoryAdded,
|
|
115
116
|
status: () => boundContext ? scheduler.status() : "inactive · automatic work requires an interactive Persona session",
|
|
116
117
|
setEnabled: (enabled) => scheduler.setEnabled(enabled),
|
|
118
|
+
startExplicit: (target) => scheduler.startExplicit(target),
|
|
117
119
|
};
|
|
118
120
|
}
|
|
@@ -39,7 +39,8 @@ export class AutoOptimizeScheduler {
|
|
|
39
39
|
private generation = 0;
|
|
40
40
|
private disabledGeneration = 0;
|
|
41
41
|
private timer: (() => void) | undefined;
|
|
42
|
-
private
|
|
42
|
+
private timerGeneration = 0;
|
|
43
|
+
private running: { optimizer: Optimizer; cancel?: () => void; retryTarget?: Target; explicit?: boolean } | undefined;
|
|
43
44
|
private work: Promise<void> = Promise.resolve();
|
|
44
45
|
private last = "waiting for new memory";
|
|
45
46
|
|
|
@@ -65,8 +66,8 @@ export class AutoOptimizeScheduler {
|
|
|
65
66
|
}
|
|
66
67
|
stop(): void { this.interrupt(); this.owner = undefined; this.pending.clear(); this.retryTargets.clear(); this.cursors.clear(); this.inputTokens = 0; this.seen.clear(); this.lastAttempt = -Infinity; }
|
|
67
68
|
interrupt(): void {
|
|
68
|
-
this.timer?.(); this.timer = undefined; this.generation++;
|
|
69
|
-
if (this.enabled && this.running?.retryTarget) {
|
|
69
|
+
this.timer?.(); this.timer = undefined; this.timerGeneration++; this.generation++;
|
|
70
|
+
if (this.enabled && !this.running?.explicit && this.running?.retryTarget) {
|
|
70
71
|
this.pending.add(this.running.retryTarget);
|
|
71
72
|
this.retryTargets.add(this.running.retryTarget);
|
|
72
73
|
}
|
|
@@ -105,14 +106,32 @@ export class AutoOptimizeScheduler {
|
|
|
105
106
|
const eligiblePending = [...this.pending].some((target) => this.allows(owner, target) && (this.retryTargets.has(target) || tokenReady));
|
|
106
107
|
if (!eligiblePending) return;
|
|
107
108
|
const generation = this.generation;
|
|
109
|
+
const timerGeneration = ++this.timerGeneration;
|
|
108
110
|
this.timer = this.schedule(() => {
|
|
111
|
+
if (timerGeneration !== this.timerGeneration) return;
|
|
109
112
|
this.timer = undefined;
|
|
110
|
-
if (generation !== this.generation) return;
|
|
113
|
+
if (generation !== this.generation || this.running) return;
|
|
111
114
|
this.work = this.run().catch(() => { this.last = "inspection failed; no automatic retry"; });
|
|
112
115
|
}, Math.max(AUTO_IDLE_MS, this.lastAttempt + AUTO_COOLDOWN_MS - this.now()));
|
|
113
116
|
}
|
|
117
|
+
/** Start one user-requested bounded pass without automatic gates or preference checks. */
|
|
118
|
+
startExplicit(target: Target): boolean {
|
|
119
|
+
const owner = this.owner;
|
|
120
|
+
if (!owner || !this.safeCurrent(owner) || !this.safeIdle(owner) || !this.allows(owner, target) || this.running) return false;
|
|
121
|
+
this.timer?.(); this.timer = undefined; this.timerGeneration++;
|
|
122
|
+
const generation = this.generation;
|
|
123
|
+
this.work = this.run(target, true).catch(() => {
|
|
124
|
+
if (generation !== this.generation || !this.safeCurrent(owner)) return;
|
|
125
|
+
this.last = "explicit review failed; inspect current memory before retrying because apply may have completed";
|
|
126
|
+
try { owner.report("Mind optimization result", `Bounded review failed unexpectedly; ${this.last}.`); } catch { /* owner reporting is best-effort */ }
|
|
127
|
+
}).finally(() => {
|
|
128
|
+
if (generation === this.generation && this.safeCurrent(owner) && this.safeIdle(owner) && this.pending.size) this.settled();
|
|
129
|
+
});
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
114
132
|
join(): Promise<void> { return this.work; }
|
|
115
133
|
private safeCurrent(owner: AutoOptimizeOwner): boolean { try { return this.owner === owner && owner.current(); } catch { return false; } }
|
|
134
|
+
private safeIdle(owner: AutoOptimizeOwner): boolean { try { return owner.idle(); } catch { return false; } }
|
|
116
135
|
private allows(owner: AutoOptimizeOwner, target: Target): boolean { return owner.allowedTargets.includes(target); }
|
|
117
136
|
private remember(owner: AutoOptimizeOwner, target: Target, digest: string, state: AutoAttempt["state"], at: number): void {
|
|
118
137
|
owner.recordAttempt({ digest, target, at, state });
|
|
@@ -120,27 +139,27 @@ export class AutoOptimizeScheduler {
|
|
|
120
139
|
this.seen.add(digest); while (this.seen.size > 64) this.seen.delete(this.seen.values().next().value!);
|
|
121
140
|
}
|
|
122
141
|
}
|
|
123
|
-
private async run(): Promise<void> {
|
|
142
|
+
private async run(explicitTarget?: Target, explicit = false): Promise<void> {
|
|
124
143
|
const owner = this.owner;
|
|
125
|
-
if (!owner || !this.enabled || !this.safeCurrent(owner) || !
|
|
144
|
+
if (!owner || (!explicit && !this.enabled) || !this.safeCurrent(owner) || !this.safeIdle(owner) || this.running) return;
|
|
126
145
|
const generation = this.generation;
|
|
127
146
|
const disabledGeneration = this.disabledGeneration;
|
|
128
|
-
const current = () => generation === this.generation && this.enabled && this.
|
|
129
|
-
const mayRetry = () => this.enabled && this.disabledGeneration === disabledGeneration && this.safeCurrent(owner);
|
|
147
|
+
const current = () => generation === this.generation && (explicit || this.enabled) && this.safeIdle(owner) && this.safeCurrent(owner);
|
|
148
|
+
const mayRetry = () => !explicit && this.enabled && this.disabledGeneration === disabledGeneration && this.safeCurrent(owner);
|
|
130
149
|
const optimizer = owner.optimizer();
|
|
131
|
-
const running: NonNullable<AutoOptimizeScheduler["running"]> = { optimizer };
|
|
150
|
+
const running: NonNullable<AutoOptimizeScheduler["running"]> = { optimizer, explicit };
|
|
132
151
|
let attemptRecorded = false;
|
|
133
152
|
let unsettledTarget: Target | undefined;
|
|
134
153
|
let nextCursor: CoverageCursor | undefined;
|
|
135
154
|
let retryRequiresSettled = false;
|
|
136
155
|
this.running = running;
|
|
137
156
|
try {
|
|
138
|
-
for (const target of [...this.pending]) {
|
|
157
|
+
for (const target of explicit ? [explicitTarget!] : [...this.pending]) {
|
|
139
158
|
if (!this.allows(owner, target)) { this.pending.delete(target); this.retryTargets.delete(target); continue; }
|
|
140
159
|
const retry = this.retryTargets.has(target);
|
|
141
160
|
const tokenReady = this.lastAttempt === -Infinity || this.inputTokens >= AUTO_INPUT_TOKEN_THRESHOLD;
|
|
142
|
-
if (!retry && !tokenReady) continue;
|
|
143
|
-
this.pending.delete(target);
|
|
161
|
+
if (!explicit && !retry && !tokenReady) continue;
|
|
162
|
+
if (!explicit) this.pending.delete(target);
|
|
144
163
|
const cursor = this.cursors.get(target) ?? { offset: 0, withinPage: 0 };
|
|
145
164
|
let inspection: OptimizeInspection | OptimizeFailure;
|
|
146
165
|
let newestInspection: OptimizeInspection | undefined;
|
|
@@ -151,7 +170,8 @@ export class AutoOptimizeScheduler {
|
|
|
151
170
|
if (latest.ok && latest.target === target && latest.fingerprint === inspection.fingerprint) newestInspection = latest;
|
|
152
171
|
else {
|
|
153
172
|
if (mayRetry()) this.pending.add(target);
|
|
154
|
-
this.last = "store changed during bounded inspection; waiting for the next settled event";
|
|
173
|
+
this.last = explicit ? "store changed during bounded inspection; the selected window was not reviewed" : "store changed during bounded inspection; waiting for the next settled event";
|
|
174
|
+
if (explicit && current()) owner.report("Mind optimization result", `Bounded review stopped before worker admission: ${this.last}.`);
|
|
155
175
|
return;
|
|
156
176
|
}
|
|
157
177
|
}
|
|
@@ -162,6 +182,7 @@ export class AutoOptimizeScheduler {
|
|
|
162
182
|
return;
|
|
163
183
|
}
|
|
164
184
|
this.last = "store inspection failed; see /mind doctor";
|
|
185
|
+
if (explicit) owner.report("Mind optimization result", `Bounded review could not inspect this record window: ${this.last}.`);
|
|
165
186
|
continue;
|
|
166
187
|
}
|
|
167
188
|
if (!current()) {
|
|
@@ -170,8 +191,8 @@ export class AutoOptimizeScheduler {
|
|
|
170
191
|
if (mayRetry()) this.pending.add(target);
|
|
171
192
|
return;
|
|
172
193
|
}
|
|
173
|
-
if (!inspection.ok) { this.last = "store inspection refused; see /mind doctor"; continue; }
|
|
174
|
-
if (inspection.target !== target) { this.last = "store inspection returned a different tier; no worker started"; continue; }
|
|
194
|
+
if (!inspection.ok) { this.last = "store inspection refused; see /mind doctor"; if (explicit) owner.report("Mind optimization result", `Bounded review stopped before worker admission: ${this.last}.`); continue; }
|
|
195
|
+
if (inspection.target !== target) { this.last = "store inspection returned a different tier; no worker started"; if (explicit) owner.report("Mind optimization result", `Bounded review stopped before worker admission: ${this.last}.`); continue; }
|
|
175
196
|
const page = selectAutoInputPage(inspection, owner.persona, cursor.withinPage, newestInspection);
|
|
176
197
|
nextCursor = page.pageComplete
|
|
177
198
|
? { offset: inspection.nextOffset ?? 0, withinPage: 0 }
|
|
@@ -181,30 +202,39 @@ export class AutoOptimizeScheduler {
|
|
|
181
202
|
this.cursors.set(target, nextCursor);
|
|
182
203
|
this.retryTargets.delete(target);
|
|
183
204
|
this.last = "no eligible records in this bounded page";
|
|
205
|
+
if (explicit) owner.report("Mind optimization result", `Bounded coverage: no eligible records in the selected window; ${this.last}.`);
|
|
184
206
|
continue;
|
|
185
207
|
}
|
|
186
|
-
if (this.seen.has(input.digest)) {
|
|
208
|
+
if (!explicit && this.seen.has(input.digest)) {
|
|
187
209
|
this.cursors.set(target, nextCursor);
|
|
188
210
|
this.retryTargets.delete(target);
|
|
189
211
|
this.last = "this bounded record set was already reviewed";
|
|
190
212
|
continue;
|
|
191
213
|
}
|
|
192
214
|
const worker = owner.launch(buildAutoPrompt(input));
|
|
193
|
-
if (!worker.ok) {
|
|
215
|
+
if (!worker.ok) {
|
|
216
|
+
if (!explicit) this.pending.add(target);
|
|
217
|
+
this.last = worker.reason;
|
|
218
|
+
if (explicit && current()) owner.report("Mind optimization result", `Bounded review was not admitted: ${worker.reason}. No memory changed.`);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
194
221
|
const attemptAt = this.now();
|
|
195
222
|
running.cancel = worker.cancel;
|
|
196
223
|
running.retryTarget = target;
|
|
197
224
|
this.retryTargets.delete(target);
|
|
198
|
-
this.lastAttempt = attemptAt; this.inputTokens = 0;
|
|
225
|
+
if (!explicit) { this.lastAttempt = attemptAt; this.inputTokens = 0; }
|
|
226
|
+
this.last = "Mind is reviewing memory";
|
|
199
227
|
unsettledTarget = target;
|
|
200
228
|
const settle = (): void => {
|
|
201
|
-
this.remember(owner, target, input.digest, "settled", attemptAt);
|
|
229
|
+
if (!explicit) this.remember(owner, target, input.digest, "settled", attemptAt);
|
|
202
230
|
if (nextCursor) this.cursors.set(target, nextCursor);
|
|
203
231
|
unsettledTarget = undefined;
|
|
204
232
|
};
|
|
205
233
|
try {
|
|
206
|
-
|
|
207
|
-
|
|
234
|
+
if (!explicit) {
|
|
235
|
+
this.remember(owner, target, input.digest, "started", attemptAt);
|
|
236
|
+
attemptRecorded = true;
|
|
237
|
+
}
|
|
208
238
|
} catch {
|
|
209
239
|
try { running.cancel?.(); } catch { /* best-effort stop before apply */ }
|
|
210
240
|
this.last = "attempt could not be saved; worker cancelled before apply";
|
|
@@ -213,22 +243,25 @@ export class AutoOptimizeScheduler {
|
|
|
213
243
|
const result = await worker.completion;
|
|
214
244
|
if (!current()) return;
|
|
215
245
|
if (workerWasStopped(result)) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
246
|
+
if (!explicit) {
|
|
247
|
+
retryRequiresSettled = true;
|
|
248
|
+
this.pending.add(target);
|
|
249
|
+
this.retryTargets.add(target);
|
|
250
|
+
}
|
|
219
251
|
unsettledTarget = undefined;
|
|
220
|
-
this.last = "review interrupted; waiting for the next settled event";
|
|
252
|
+
this.last = explicit ? "explicit review stopped; memory unchanged" : "review interrupted; waiting for the next settled event";
|
|
253
|
+
if (explicit && current()) owner.report("Mind optimization result", this.last);
|
|
221
254
|
return;
|
|
222
255
|
}
|
|
223
|
-
if (!result.ok) { settle(); this.last = "worker failed; memory unchanged"; owner.report("Mind automatic optimization",
|
|
256
|
+
if (!result.ok) { settle(); this.last = "worker failed; memory unchanged"; owner.report(explicit ? "Mind optimization result" : "Mind automatic optimization", `Bounded review · ${this.last}${result.error ? `: ${result.error}` : ""}`); return; }
|
|
224
257
|
const parsed = parseAutoProposal(result.output, input);
|
|
225
|
-
if (!parsed.ok) { settle(); this.last = "proposal refused; memory unchanged"; owner.report("Mind automatic optimization",
|
|
258
|
+
if (!parsed.ok) { settle(); this.last = "proposal refused; memory unchanged"; owner.report(explicit ? "Mind optimization result" : "Mind automatic optimization", `Bounded review · ${this.last}: ${parsed.reason}`); return; }
|
|
226
259
|
const provenance = `Worker ${worker.runId} · ${worker.model} · ${worker.thinking}${result.resultRef ? `\nTerminal report: ${result.resultRef}` : ""}`;
|
|
227
|
-
if (!parsed.operations.length) { settle(); this.last = "bounded review found no safe consolidation in this record set"; owner.report("Mind automatic optimization",
|
|
260
|
+
if (!parsed.operations.length) { settle(); this.last = "bounded review found no safe consolidation in this record set"; owner.report(explicit ? "Mind optimization result" : "Mind automatic optimization", `Bounded coverage: one selected record window; ${this.last}.\n${provenance}`); return; }
|
|
228
261
|
const plan = await optimizer.preview({ target: input.target, fingerprint: input.fingerprint, operations: parsed.operations });
|
|
229
262
|
if (!current()) return;
|
|
230
|
-
if (!plan.ok) { settle(); this.last = "store or proposal changed; nothing applied"; owner.report("Mind automatic optimization",
|
|
231
|
-
owner.report("Mind automatic proposal", `${provenance}\n${formatAutoPlan(plan)}\
|
|
263
|
+
if (!plan.ok) { settle(); this.last = "store or proposal changed; nothing applied"; owner.report(explicit ? "Mind optimization result" : "Mind automatic optimization", `Bounded coverage: one selected record window; ${this.last}: ${plan.reason}\n${provenance}`); return; }
|
|
264
|
+
owner.report(explicit ? "Mind optimization proposal" : "Mind automatic proposal", `${provenance}\n${formatAutoPlan(plan)}\n${explicit ? "Validated apply pending" : "Automatic apply pending"}; it proceeds only while this owner and snapshot remain current.`);
|
|
232
265
|
if (!current()) { optimizer.invalidate(); return; }
|
|
233
266
|
const applied = await optimizer.apply(plan.planId);
|
|
234
267
|
if (!current()) return;
|
|
@@ -238,7 +271,7 @@ export class AutoOptimizeScheduler {
|
|
|
238
271
|
? applied.receiptId ? `\nUndo: /mind optimize undo ${applied.receiptId} ${applied.target}.` : "\nNo durable undo receipt was returned."
|
|
239
272
|
: "";
|
|
240
273
|
const warning = applied.ok && applied.warning ? `\nWarning: ${applied.warning}` : "";
|
|
241
|
-
owner.report("Mind automatic result",
|
|
274
|
+
owner.report(explicit ? "Mind optimization result" : "Mind automatic result", `Bounded coverage: one selected record window; ${this.last}\n${provenance}${receipt}${warning}`);
|
|
242
275
|
return; // One worker per pass; other dirty tiers wait for the input floor and cooldown.
|
|
243
276
|
}
|
|
244
277
|
} finally {
|
|
@@ -251,7 +284,7 @@ export class AutoOptimizeScheduler {
|
|
|
251
284
|
}
|
|
252
285
|
// One actual attempt may leave other dirty tiers pending; they need the input floor
|
|
253
286
|
// and cooldown. Only the same interrupted target bypasses the token floor.
|
|
254
|
-
if (attemptRecorded && this.pending.size > 0 && current() && !retryRequiresSettled) this.settled();
|
|
287
|
+
if (!explicit && attemptRecorded && this.pending.size > 0 && current() && !retryRequiresSettled) this.settled();
|
|
255
288
|
}
|
|
256
289
|
}
|
|
257
290
|
}
|
|
@@ -261,5 +294,5 @@ function workerWasStopped(result: MindWorkerResult): boolean {
|
|
|
261
294
|
}
|
|
262
295
|
|
|
263
296
|
function formatAutoPlan(plan: OptimizePlan): string {
|
|
264
|
-
return `Staged
|
|
297
|
+
return `Staged proposed change · ${plan.beforeCount} entries → ${plan.afterCount}\n${JSON.stringify(plan.changes, null, 2)}`;
|
|
265
298
|
}
|
|
@@ -21,6 +21,8 @@ export type MindCommand =
|
|
|
21
21
|
| { type: "reset" }
|
|
22
22
|
| { type: "migrate-persona" }
|
|
23
23
|
| { type: "session" }
|
|
24
|
+
| { type: "optimize-run"; target: Exclude<MindOptimizeTarget, "shared"> }
|
|
25
|
+
| { type: "optimize-shared-refused" }
|
|
24
26
|
| { type: "optimize-inspect"; target: MindOptimizeTarget }
|
|
25
27
|
| { type: "optimize-show"; planId: string }
|
|
26
28
|
| { type: "optimize-apply"; planId: string }
|
|
@@ -30,7 +32,7 @@ export type MindCommand =
|
|
|
30
32
|
| { type: "invalid"; message: string };
|
|
31
33
|
|
|
32
34
|
const USAGE =
|
|
33
|
-
"usage: /persona-mind [help|doctor|session|reset [workspace]|migrate-persona|optimize [project|project-long|persona|shared]|optimize show <planId>|optimize apply <planId>|optimize history [target]|optimize undo <receiptId> [target]|optimize auto [status|on|off]]";
|
|
35
|
+
"usage: /persona-mind [help|doctor|session|reset [workspace]|migrate-persona|optimize [project|project-long|persona]|optimize inspect [project|project-long|persona|shared]|optimize show <planId>|optimize apply <planId>|optimize history [target]|optimize undo <receiptId> [target]|optimize auto [status|on|off]]";
|
|
34
36
|
|
|
35
37
|
export interface MindCommandDeps {
|
|
36
38
|
agentDir: string;
|
|
@@ -40,7 +42,7 @@ export interface MindCommandDeps {
|
|
|
40
42
|
getSessionMemory(): SessionMemory;
|
|
41
43
|
getOptimizer(ctx: ExtensionContext): MemoryOptimizer;
|
|
42
44
|
activity?(ctx: ExtensionContext): MindActivityRunner | undefined;
|
|
43
|
-
autoOptimize?: { status(): string; setEnabled(enabled: boolean): void };
|
|
45
|
+
autoOptimize?: { status(): string; setEnabled(enabled: boolean): void; startExplicit?(target: Exclude<MindOptimizeTarget, "shared">): boolean };
|
|
44
46
|
isCurrent(ctx: ExtensionContext): boolean;
|
|
45
47
|
ensureLegacyMigrated(ctx: ExtensionContext, includeAmbiguousPersonaAlias?: boolean, awaitCompletion?: boolean): Promise<void>;
|
|
46
48
|
migrationStatus(): string;
|
|
@@ -76,16 +78,33 @@ export function registerMindCommands(pi: ExtensionAPI, deps: MindCommandDeps): v
|
|
|
76
78
|
"/persona-mind session — list notes on this active session branch",
|
|
77
79
|
"/persona-mind reset [workspace] — clear this project's short-term memory and backlog",
|
|
78
80
|
"/persona-mind migrate-persona — explicitly import an ambiguous historical persona alias",
|
|
79
|
-
"/persona-mind optimize [project|project-long|persona
|
|
80
|
-
"
|
|
81
|
+
"/persona-mind optimize [project|project-long|persona] — request one bounded visible Persona-hosted LLM review; project is expiring working memory, project-long is durable repository knowledge",
|
|
82
|
+
"/persona-mind optimize inspect [project|project-long|persona|shared] — read-only inspection; shared changes require a manually reviewed workflow.",
|
|
81
83
|
"/persona-mind optimize show <planId> — inspect exact staged text; /persona-mind optimize apply <planId> commits that plan only",
|
|
82
84
|
"/persona-mind optimize history [target] — inspect bounded durable before/after receipts; /persona-mind optimize undo <receiptId> [target] restores unchanged affected facts (target defaults to project)",
|
|
83
85
|
"/persona-mind optimize auto [status|on|off] — inspect or switch automatic review for this session; off cancels pending work",
|
|
84
|
-
"/mind is an alias.
|
|
86
|
+
"/mind is an alias. Explicit review bypasses automatic gates but not worker/busy/owner safeguards; it reports bounded coverage and applies only validated CAS plans. Automatic review remains idle-gated.",
|
|
85
87
|
].join("\n");
|
|
86
88
|
publish(ctx, deps, "pi-persona-mind help", body, "Command reference is in the expandable card.");
|
|
87
89
|
return;
|
|
88
90
|
}
|
|
91
|
+
if (command.type === "optimize-shared-refused") {
|
|
92
|
+
ctx.ui.notify("Shared memory is excluded from LLM optimization. Use `/mind optimize inspect shared` and a manually reviewed workflow.", "warning");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (command.type === "optimize-run") {
|
|
96
|
+
if (deps.isDelegatedLeg || !deps.autoOptimize?.startExplicit) {
|
|
97
|
+
ctx.ui.notify("Visible Persona-hosted memory review is unavailable in this session.", "warning");
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (!captureSessionOwner(deps, ctx)()) {
|
|
101
|
+
ctx.ui.notify("Memory session owner changed; optimization was not started.", "warning");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!deps.autoOptimize.startExplicit(command.target)) ctx.ui.notify("Mind is busy, already has a review worker active, or its memory owner is unavailable; no review was accepted.", "warning");
|
|
105
|
+
else ctx.ui.notify(`Mind ${command.target} review requested; bounded inspection and worker admission are preparing in the background.`, "info");
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
89
108
|
if (command.type === "optimize-auto") {
|
|
90
109
|
if (!captureSessionOwner(deps, ctx)()) {
|
|
91
110
|
ctx.ui.notify("Memory session owner changed; automatic optimization was not changed.", "warning");
|
|
@@ -318,9 +337,12 @@ export function parseMindCommand(args: string): MindCommand {
|
|
|
318
337
|
if (parts.length === 3 && (parts[2] === "status" || parts[2] === "on" || parts[2] === "off")) return { type: "optimize-auto", action: parts[2] };
|
|
319
338
|
return { type: "invalid", message: USAGE };
|
|
320
339
|
}
|
|
321
|
-
if (parts.length ===
|
|
322
|
-
if (parts
|
|
323
|
-
|
|
340
|
+
if (parts[1] === "inspect" && parts.length === 2) return { type: "optimize-inspect", target: "project" };
|
|
341
|
+
if (parts[1] === "inspect" && parts.length === 3 && isOptimizeTarget(parts[2])) return { type: "optimize-inspect", target: parts[2] };
|
|
342
|
+
if (parts.length === 1) return { type: "optimize-run", target: "project" };
|
|
343
|
+
if (parts.length === 2 && parts[1] === "shared") return { type: "optimize-shared-refused" };
|
|
344
|
+
if (parts.length === 2 && (parts[1] === "project" || parts[1] === "project-long" || parts[1] === "persona")) {
|
|
345
|
+
return { type: "optimize-run", target: parts[1] };
|
|
324
346
|
}
|
|
325
347
|
if (parts.length === 3 && (parts[1] === "show" || parts[1] === "apply") && isPlanId(args.trim().split(/\s+/)[2])) {
|
|
326
348
|
const planId = args.trim().split(/\s+/)[2]!;
|