notesoup 0.56.0 → 0.56.1
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/dist/plugins/pi/marker.d.ts +4 -2
- package/dist/plugins/pi/marker.js +18 -8
- package/dist/plugins/pi/reset/lifecycle.js +6 -0
- package/dist/test/agent-loop.test.js +44 -1
- package/dist/test/marker.test.js +46 -15
- package/docs/architecture.md +1 -1
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/pi/marker.ts +18 -12
- package/plugins/pi/reset/lifecycle.ts +5 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import type { CustomMessageEntryDraft, ExtensionAPI, ExtensionContext, SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
/** Spacing between durable seq breadcrumbs, in projected history seq. */
|
|
3
|
-
export declare const MARKER_INTERVAL =
|
|
3
|
+
export declare const MARKER_INTERVAL = 100;
|
|
4
4
|
/**
|
|
5
5
|
* Stamp the current seq every MARKER_INTERVAL seqs. The marker names the seq it occupies, so a
|
|
6
6
|
* model paging history_list meets a breadcrumb that tells it where it is. Skipped while a reset
|
|
7
7
|
* tail still awaits boot or continuation: a foreign message there would close the repair shape.
|
|
8
8
|
*/
|
|
9
|
+
export declare function buildMarkerDraft(ctx: ExtensionContext, pending?: readonly SessionBoundaryDraft[]): CustomMessageEntryDraft | undefined;
|
|
10
|
+
/** Run-start fallback; active runs append the same draft through the turn-end boundary. */
|
|
9
11
|
export declare function maybeSendMarker(pi: ExtensionAPI, ctx: ExtensionContext): void;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { piSequenceCount } from "../../src/history/pi.js";
|
|
2
|
-
import { BOOT_TYPE, MARKER_TYPE } from "./entries.js";
|
|
2
|
+
import { BOOT_TYPE, MARKER_TYPE, RESET_MARKER_TYPE } from "./entries.js";
|
|
3
3
|
import { nextHistorySeq } from "./history.js";
|
|
4
4
|
import { inspectResetTail } from "./reset/artifacts.js";
|
|
5
5
|
import { markerContent } from "./text.js";
|
|
6
6
|
import { currentReset } from "./window.js";
|
|
7
7
|
/** Spacing between durable seq breadcrumbs, in projected history seq. */
|
|
8
|
-
export const MARKER_INTERVAL =
|
|
8
|
+
export const MARKER_INTERVAL = 100;
|
|
9
9
|
/** Highest seq already anchored by a window boot or marker; 0 before the first. */
|
|
10
|
-
function lastMarkerSeq(ctx) {
|
|
10
|
+
function lastMarkerSeq(ctx, pending) {
|
|
11
11
|
let last = 0;
|
|
12
12
|
let nextSeq = 1;
|
|
13
|
-
for (const entry of ctx.sessionManager.getEntries()) {
|
|
13
|
+
for (const entry of [...ctx.sessionManager.getEntries(), ...pending]) {
|
|
14
14
|
const count = piSequenceCount(entry);
|
|
15
15
|
if (count === 0)
|
|
16
16
|
continue;
|
|
@@ -26,15 +26,25 @@ function lastMarkerSeq(ctx) {
|
|
|
26
26
|
* model paging history_list meets a breadcrumb that tells it where it is. Skipped while a reset
|
|
27
27
|
* tail still awaits boot or continuation: a foreign message there would close the repair shape.
|
|
28
28
|
*/
|
|
29
|
-
export function
|
|
29
|
+
export function buildMarkerDraft(ctx, pending = []) {
|
|
30
|
+
if (pending.some((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE))
|
|
31
|
+
return;
|
|
30
32
|
const reset = currentReset(ctx);
|
|
31
33
|
if (reset) {
|
|
32
34
|
const tail = inspectResetTail(ctx, reset.id, reset.data.windowId);
|
|
33
35
|
if (tail && (!tail.boot || !tail.continuation))
|
|
34
36
|
return;
|
|
35
37
|
}
|
|
36
|
-
const seq = nextHistorySeq(ctx);
|
|
37
|
-
if (seq - lastMarkerSeq(ctx) < MARKER_INTERVAL)
|
|
38
|
+
const seq = nextHistorySeq(ctx, pending);
|
|
39
|
+
if (seq - lastMarkerSeq(ctx, pending) < MARKER_INTERVAL)
|
|
40
|
+
return;
|
|
41
|
+
return { type: "custom_message", customType: MARKER_TYPE, content: markerContent(seq), display: false, details: { seq } };
|
|
42
|
+
}
|
|
43
|
+
/** Run-start fallback; active runs append the same draft through the turn-end boundary. */
|
|
44
|
+
export function maybeSendMarker(pi, ctx) {
|
|
45
|
+
const draft = buildMarkerDraft(ctx);
|
|
46
|
+
if (!draft)
|
|
38
47
|
return;
|
|
39
|
-
|
|
48
|
+
const { type: _type, ...message } = draft;
|
|
49
|
+
pi.sendMessage(message, { triggerTurn: false });
|
|
40
50
|
}
|
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { getCurrentSystemMessage, isContextOverflow, isRecoverableLength } from "@earendil-works/pi-ai";
|
|
3
3
|
import { currentReset, currentWindowId } from "../window.js";
|
|
4
4
|
import { nextHistorySeq } from "../history.js";
|
|
5
|
+
import { buildMarkerDraft } from "../marker.js";
|
|
5
6
|
import { resetBoundaryCommitted } from "./committed.js";
|
|
6
7
|
import { errorMessage } from "../../../src/error-message.js";
|
|
7
8
|
import { carriedInputDrafts, isCarriedInputEntry } from "./artifacts.js";
|
|
@@ -272,6 +273,11 @@ export function registerResetLifecycle(pi, options) {
|
|
|
272
273
|
if (aborted || (event.outcome === "error" && decision.state.request.phase === "none"))
|
|
273
274
|
restoreCommandInputs();
|
|
274
275
|
control = decision.state;
|
|
276
|
+
if (!aborted && event.outcome !== "error" && options.isEnabled()) {
|
|
277
|
+
const marker = buildMarkerDraft(ctx, entries);
|
|
278
|
+
if (marker)
|
|
279
|
+
entries.push(marker);
|
|
280
|
+
}
|
|
275
281
|
return entries.length > 0 ? { entries } : undefined;
|
|
276
282
|
});
|
|
277
283
|
pi.on("agent_before_settle", async (event, ctx) => {
|
|
@@ -6,8 +6,9 @@ import test from "node:test";
|
|
|
6
6
|
import { createAssistantMessageEventStream, getCurrentSystemMessage } from "@earendil-works/pi-ai";
|
|
7
7
|
import { createAgentSession, createCodemodeExtension, DefaultResourceLoader, ModelRuntime, SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import notesoup, { createNotesoup } from "../plugins/pi/extension.js";
|
|
9
|
-
import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, NEXT_WINDOW_PROMPT_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "../plugins/pi/entries.js";
|
|
9
|
+
import { BOOT_TYPE, CARRIED_INPUT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, MANUAL_WIPE_TYPE, MARKER_TYPE, NEXT_WINDOW_PROMPT_TYPE, RESET_MARKER_TYPE, WARNING_TYPE } from "../plugins/pi/entries.js";
|
|
10
10
|
import { historyFromSession } from "../plugins/pi/history.js";
|
|
11
|
+
import { MARKER_INTERVAL } from "../plugins/pi/marker.js";
|
|
11
12
|
import { assertBootHistory } from "./helpers/extension.js";
|
|
12
13
|
import { NOTES_PROTOCOL_OPEN_TAG, WINDOW_IDENTITY_OPEN_TAG } from "../src/boot/text.js";
|
|
13
14
|
import { FORCED_CONTINUATIONS, GUIDANCE_OPEN_TAG, NORMAL_CONTINUATIONS, warningPrompt } from "../src/budget/text.js";
|
|
@@ -235,6 +236,48 @@ function assertFreshRequest(fixture, requestIndex, oldSentinel) {
|
|
|
235
236
|
assert.ok(body.includes(WINDOW_IDENTITY_OPEN_TAG), "the new provider request includes the fresh context-window boot");
|
|
236
237
|
assert.deepEqual(continuationLinesIn(body).length, 1, "the fresh window carries exactly one reset paragraph");
|
|
237
238
|
}
|
|
239
|
+
test("real AgentSession: turn-end markers reach tool continuations and allow one-turn lag when steering crosses the interval", async () => {
|
|
240
|
+
for (const seedCount of [MARKER_INTERVAL - 4, MARKER_INTERVAL - 7]) {
|
|
241
|
+
let starts = 0;
|
|
242
|
+
let fixture;
|
|
243
|
+
fixture = await openFixture({
|
|
244
|
+
compactionEnabled: false,
|
|
245
|
+
hook: (pi, getSession) => {
|
|
246
|
+
pi.on("before_agent_start", () => { starts++; });
|
|
247
|
+
pi.on("tool_call", async () => { await getSession().steer("MARKER_MID_RUN_USER"); });
|
|
248
|
+
},
|
|
249
|
+
script: (request) => request === 1
|
|
250
|
+
? assistant(fixture, [{ type: "toolCall", id: "marker-tool", name: "get_context_remaining", arguments: {} }], "toolUse")
|
|
251
|
+
: assistant(fixture, [{ type: "text", text: "steered input handled" }]),
|
|
252
|
+
});
|
|
253
|
+
try {
|
|
254
|
+
for (let i = 0; i < seedCount; i++)
|
|
255
|
+
fixture.sessionManager.appendMessage(assistant(fixture, [{ type: "text", text: "seed" }]));
|
|
256
|
+
await fixture.session.prompt("MARKER_INITIAL_USER");
|
|
257
|
+
await fixture.session.waitForIdle();
|
|
258
|
+
assert.equal(starts, 1);
|
|
259
|
+
assert.equal(fixture.requests.length, 2, "the marker does not create another model request");
|
|
260
|
+
assert.equal(text(fixture.requests[0]).includes("notesoup:marker"), false);
|
|
261
|
+
assert.equal(text(fixture.requests[1]).includes("notesoup:marker"), seedCount === MARKER_INTERVAL - 4);
|
|
262
|
+
assert.equal(text(fixture.requests[1]).split("MARKER_MID_RUN_USER").length - 1, 1);
|
|
263
|
+
const branch = fixture.sessionManager.getBranch();
|
|
264
|
+
const markers = branch.filter((entry) => entry.type === "custom_message" && entry.customType === MARKER_TYPE);
|
|
265
|
+
assert.equal(markers.length, 1);
|
|
266
|
+
const marker = markers[0];
|
|
267
|
+
const markerIndex = branch.indexOf(marker);
|
|
268
|
+
const userIndex = branch.findIndex((entry) => entry.type === "message" && entry.message.role === "user" && JSON.stringify(entry.message.content).includes("MARKER_MID_RUN_USER"));
|
|
269
|
+
assert.equal(markerIndex < userIndex, seedCount === MARKER_INTERVAL - 4, "a steering-only threshold crossing is marked after its response");
|
|
270
|
+
assert.ok(branch.slice(0, markerIndex).some((entry) => entry.type === "message" && entry.message.role === "toolResult" && entry.message.toolCallId === "marker-tool"));
|
|
271
|
+
const projection = historyFromSession({ sessionManager: fixture.sessionManager });
|
|
272
|
+
const addressed = projection.windows.flatMap((window) => window.items).find((item) => item.text.includes("<notesoup:marker"));
|
|
273
|
+
assert.ok(addressed);
|
|
274
|
+
assert.deepEqual(marker.type === "custom_message" ? marker.details : undefined, { seq: addressed.seq });
|
|
275
|
+
}
|
|
276
|
+
finally {
|
|
277
|
+
fixture.close();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
238
281
|
test("real Pi codemode receives typed notes/history outcomes, including expected errors", async () => {
|
|
239
282
|
let fixture;
|
|
240
283
|
fixture = await openFixture({
|
package/dist/test/marker.test.js
CHANGED
|
@@ -3,8 +3,8 @@ import test from "node:test";
|
|
|
3
3
|
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { BOOT_TYPE, CONTINUATION_TYPE, MARKER_TYPE, RESET_MARKER_TYPE } from "../plugins/pi/entries.js";
|
|
5
5
|
import { nextHistorySeq } from "../plugins/pi/history.js";
|
|
6
|
-
import { MARKER_INTERVAL } from "../plugins/pi/marker.js";
|
|
7
|
-
import { appendText, context, installExtensionTestEnvironment, makeExtension, runCommand, runHandlers, sentOf } from "./helpers/extension.js";
|
|
6
|
+
import { buildMarkerDraft, MARKER_INTERVAL } from "../plugins/pi/marker.js";
|
|
7
|
+
import { appendText, call, commitTurnEndBoundary, context, installExtensionTestEnvironment, makeExtension, runCommand, runHandlers, sentOf } from "./helpers/extension.js";
|
|
8
8
|
const env = installExtensionTestEnvironment("notesoup-marker-test");
|
|
9
9
|
test.beforeEach(env.beforeEach);
|
|
10
10
|
test.afterEach(env.afterEach);
|
|
@@ -13,7 +13,7 @@ function beforeAgentStart(captured, ctx) {
|
|
|
13
13
|
return runHandlers(captured, "before_agent_start", { type: "before_agent_start" }, ctx);
|
|
14
14
|
}
|
|
15
15
|
test("marker stamps its own seq at run start once the interval is reached, never mid-turn", async () => {
|
|
16
|
-
const sessionManager = managerWithMessages(
|
|
16
|
+
const sessionManager = managerWithMessages(99);
|
|
17
17
|
const captured = makeExtension(sessionManager);
|
|
18
18
|
const ctx = context(sessionManager);
|
|
19
19
|
// Mid-run tool turns never inject a standalone marker message.
|
|
@@ -22,32 +22,61 @@ test("marker stamps its own seq at run start once the interval is reached, never
|
|
|
22
22
|
await beforeAgentStart(captured, ctx);
|
|
23
23
|
const sent = sentOf(captured, MARKER_TYPE);
|
|
24
24
|
assert.equal(sent.length, 1);
|
|
25
|
-
assert.deepEqual(sent[0].message.details, { seq:
|
|
25
|
+
assert.deepEqual(sent[0].message.details, { seq: 100 });
|
|
26
26
|
assert.equal(sent[0].message.display, false);
|
|
27
27
|
assert.equal(sent[0].options?.triggerTurn, false);
|
|
28
|
-
assert.equal(sent[0].message.content, '<notesoup:marker seq="
|
|
29
|
-
assert.equal(nextHistorySeq(ctx),
|
|
28
|
+
assert.equal(sent[0].message.content, '<notesoup:marker seq="100" />');
|
|
29
|
+
assert.equal(nextHistorySeq(ctx), 101, "the marker occupies the seq it names");
|
|
30
30
|
// An immediate second run is only one seq later: no new marker.
|
|
31
31
|
await beforeAgentStart(captured, ctx);
|
|
32
32
|
assert.equal(sentOf(captured, MARKER_TYPE).length, 1);
|
|
33
33
|
// The next marker lands one interval after the last.
|
|
34
34
|
appendText(sessionManager, "user", "x");
|
|
35
|
-
for (let i = 0; i <
|
|
35
|
+
for (let i = 0; i < 98; i++)
|
|
36
36
|
appendText(sessionManager, "assistant", "y");
|
|
37
37
|
await beforeAgentStart(captured, ctx);
|
|
38
38
|
const all = sentOf(captured, MARKER_TYPE);
|
|
39
39
|
assert.equal(all.length, 2);
|
|
40
|
-
assert.deepEqual(all[1].message.details, { seq:
|
|
40
|
+
assert.deepEqual(all[1].message.details, { seq: 200 });
|
|
41
|
+
});
|
|
42
|
+
test("turn-end appends a due marker without requesting continuation or duplicating it at run start", async () => {
|
|
43
|
+
const sessionManager = managerWithMessages(99);
|
|
44
|
+
const captured = makeExtension(sessionManager);
|
|
45
|
+
const ctx = context(sessionManager);
|
|
46
|
+
const boundary = await commitTurnEndBoundary(captured, sessionManager, ctx);
|
|
47
|
+
assert.equal(boundary.continue, false);
|
|
48
|
+
assert.deepEqual(boundary.entries, [{ type: "custom_message", customType: MARKER_TYPE, content: '<notesoup:marker seq="100" />', display: false, details: { seq: 100 } }]);
|
|
49
|
+
assert.equal(nextHistorySeq(ctx), 101);
|
|
50
|
+
await beforeAgentStart(captured, ctx);
|
|
51
|
+
assert.equal(sentOf(captured, MARKER_TYPE).length, 0, "the committed turn-end marker already anchored this interval");
|
|
52
|
+
});
|
|
53
|
+
test("marker seq includes incoming boundary drafts, and a drafted reset or boot suppresses another marker", () => {
|
|
54
|
+
const ctx = context(managerWithMessages(98));
|
|
55
|
+
const incoming = [{ type: "custom_message", customType: "other/context", content: "context", display: false }];
|
|
56
|
+
assert.deepEqual(buildMarkerDraft(ctx, incoming)?.details, { seq: 100 });
|
|
57
|
+
assert.equal(buildMarkerDraft(ctx, [{ type: "custom", customType: RESET_MARKER_TYPE, data: { windowId: "pcw:new" } }]), undefined);
|
|
58
|
+
assert.equal(buildMarkerDraft(ctx, [{ type: "custom_message", customType: BOOT_TYPE, content: "boot", display: false }]), undefined);
|
|
59
|
+
});
|
|
60
|
+
test("a due tool reset uses its boot instead of inserting a marker in the reset boundary", async () => {
|
|
61
|
+
const sessionManager = managerWithMessages(99);
|
|
62
|
+
const captured = makeExtension(sessionManager);
|
|
63
|
+
const ctx = context(sessionManager);
|
|
64
|
+
await call(captured, "empty_brain", {}, ctx);
|
|
65
|
+
const boundary = await commitTurnEndBoundary(captured, sessionManager, ctx);
|
|
66
|
+
assert.ok(boundary.entries.some((entry) => entry.type === "custom_message" && entry.customType === BOOT_TYPE));
|
|
67
|
+
assert.equal(boundary.entries.some((entry) => entry.type === "custom_message" && entry.customType === MARKER_TYPE), false);
|
|
68
|
+
await beforeAgentStart(captured, ctx);
|
|
69
|
+
assert.equal(sentOf(captured, MARKER_TYPE).length, 0);
|
|
41
70
|
});
|
|
42
71
|
test("no marker before the interval", async () => {
|
|
43
|
-
const sessionManager = managerWithMessages(
|
|
72
|
+
const sessionManager = managerWithMessages(98);
|
|
44
73
|
const captured = makeExtension(sessionManager);
|
|
45
74
|
await beforeAgentStart(captured, context(sessionManager));
|
|
46
75
|
assert.equal(sentOf(captured, MARKER_TYPE).length, 0);
|
|
47
|
-
assert.equal(MARKER_INTERVAL,
|
|
76
|
+
assert.equal(MARKER_INTERVAL, 100);
|
|
48
77
|
});
|
|
49
78
|
test("a reset tail awaiting repair blocks markers, and boot anchors the new window's interval", async () => {
|
|
50
|
-
const sessionManager = managerWithMessages(
|
|
79
|
+
const sessionManager = managerWithMessages(99);
|
|
51
80
|
const captured = makeExtension(sessionManager);
|
|
52
81
|
const ctx = context(sessionManager);
|
|
53
82
|
// A marker with neither boot nor continuation still expects repair; stay out of its tail.
|
|
@@ -58,23 +87,25 @@ test("a reset tail awaiting repair blocks markers, and boot anchors the new wind
|
|
|
58
87
|
sessionManager.appendCustomMessageEntry(BOOT_TYPE, "boot", false, { windowId: "pcw:test:w1" });
|
|
59
88
|
await beforeAgentStart(captured, ctx);
|
|
60
89
|
assert.equal(sentOf(captured, MARKER_TYPE).length, 0);
|
|
61
|
-
// Once the reset tail is closed, boot (seq
|
|
90
|
+
// Once the reset tail is closed, boot (seq 100) already anchored the window's start seq.
|
|
62
91
|
sessionManager.appendCustomMessageEntry(CONTINUATION_TYPE, "continued", false);
|
|
63
92
|
await beforeAgentStart(captured, ctx);
|
|
64
93
|
assert.equal(sentOf(captured, MARKER_TYPE).length, 0);
|
|
65
|
-
for (let i = 0; i <
|
|
94
|
+
for (let i = 0; i < 98; i++)
|
|
66
95
|
appendText(sessionManager, "assistant", "y");
|
|
67
96
|
await beforeAgentStart(captured, ctx);
|
|
68
97
|
const sent = sentOf(captured, MARKER_TYPE);
|
|
69
98
|
assert.equal(sent.length, 1);
|
|
70
|
-
assert.deepEqual(sent[0].message.details, { seq:
|
|
99
|
+
assert.deepEqual(sent[0].message.details, { seq: 200 });
|
|
71
100
|
});
|
|
72
101
|
test("notesoup off silences the odometer", async () => {
|
|
73
|
-
const sessionManager = managerWithMessages(
|
|
102
|
+
const sessionManager = managerWithMessages(99);
|
|
74
103
|
const captured = makeExtension(sessionManager);
|
|
75
104
|
const ctx = context(sessionManager);
|
|
76
105
|
await runCommand(captured, "notesoup", "off", ctx);
|
|
77
106
|
await beforeAgentStart(captured, ctx);
|
|
107
|
+
const boundary = await commitTurnEndBoundary(captured, sessionManager, ctx);
|
|
108
|
+
assert.equal(boundary.entries.length, 0);
|
|
78
109
|
assert.equal(sentOf(captured, MARKER_TYPE).length, 0);
|
|
79
110
|
});
|
|
80
111
|
function managerWithMessages(count) {
|
package/docs/architecture.md
CHANGED
|
@@ -43,7 +43,7 @@ For the native dsh reset transaction, prompt ordering, capability checks and lim
|
|
|
43
43
|
|
|
44
44
|
## State and persistence
|
|
45
45
|
|
|
46
|
-
`plugins/pi/reset/lifecycle.ts` is the sole `turn_end` composer: it accepts incoming drafts, drains budget-owned guidance/warning drafts, and appends a reset boundary for an explicit tool request or the hard-reserve safety path. Manual and budget close-outs stay armed across note/tool turns and commit from `agent_before_settle` after a successful stop with queued work drained; a manual close-out stops the run while a budget close-out continues in the fresh window. Repeated requests for the same window deduplicate. See [reset lifecycle](reset-lifecycle.md).
|
|
46
|
+
`plugins/pi/reset/lifecycle.ts` is the sole `turn_end` composer: it accepts incoming drafts, drains budget-owned guidance/warning drafts, and appends a reset boundary for an explicit tool request or the hard-reserve safety path. Successful non-reset turns also append a hidden seq marker once at least 100 projected seqs have elapsed since the latest boot or marker, counting incoming boundary drafts; run-start checking remains as a fallback. Markers do not request continuation or split a tool batch. Queued user messages are delivered after this boundary, so a threshold crossed only by such input is marked after its response, not before. A reset's boot anchors its interval instead of adding an old-window marker. Manual and budget close-outs stay armed across note/tool turns and commit from `agent_before_settle` after a successful stop with queued work drained; a manual close-out stops the run while a budget close-out continues in the fresh window. Repeated requests for the same window deduplicate. See [reset lifecycle](reset-lifecycle.md).
|
|
47
47
|
|
|
48
48
|
A new reset is a native empty-summary compaction checkpoint configured to retain none, followed by one `notesoup/reset-marker` custom entry with `{ windowId: string, origin: "normal" | "forced" }`, a hidden `notesoup/boot` whose `details.windowId` matches, and a hidden continuation. The checkpoint is the canonical-history cut; the marker is the durable logical window identity. Raw session entries remain available to history tools. Legacy marker-only branches keep a narrow projection fallback. `plugins/pi/window.ts` owns marker/checkpoint validation, active-branch scan, root/current IDs, and per-window message lookup; `plugins/pi/history.ts` supplies append entries and the active branch to `src/history/pi.ts`, whose structural wire decoder recognizes persisted reset markers; shared `history/history.ts` pairs only decoded, addressed data. The live scan never uses a global entry tail.
|
|
49
49
|
|
package/package.json
CHANGED
package/plugins/pi/marker.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import type { CustomMessageEntryDraft, ExtensionAPI, ExtensionContext, SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { piSequenceCount } from "../../src/history/pi.js";
|
|
3
|
-
import { BOOT_TYPE, MARKER_TYPE } from "./entries.js";
|
|
3
|
+
import { BOOT_TYPE, MARKER_TYPE, RESET_MARKER_TYPE } from "./entries.js";
|
|
4
4
|
import { nextHistorySeq } from "./history.js";
|
|
5
5
|
import { inspectResetTail } from "./reset/artifacts.js";
|
|
6
6
|
import { markerContent } from "./text.js";
|
|
7
7
|
import { currentReset } from "./window.js";
|
|
8
8
|
|
|
9
9
|
/** Spacing between durable seq breadcrumbs, in projected history seq. */
|
|
10
|
-
export const MARKER_INTERVAL =
|
|
10
|
+
export const MARKER_INTERVAL = 100;
|
|
11
11
|
|
|
12
12
|
/** Highest seq already anchored by a window boot or marker; 0 before the first. */
|
|
13
|
-
function lastMarkerSeq(ctx: ExtensionContext): number {
|
|
13
|
+
function lastMarkerSeq(ctx: ExtensionContext, pending: readonly SessionBoundaryDraft[]): number {
|
|
14
14
|
let last = 0;
|
|
15
15
|
let nextSeq = 1;
|
|
16
|
-
for (const entry of ctx.sessionManager.getEntries()) {
|
|
16
|
+
for (const entry of [...ctx.sessionManager.getEntries(), ...pending]) {
|
|
17
17
|
const count = piSequenceCount(entry);
|
|
18
18
|
if (count === 0) continue;
|
|
19
19
|
if (entry.type === "custom_message" && (entry.customType === MARKER_TYPE || entry.customType === BOOT_TYPE)) {
|
|
@@ -29,16 +29,22 @@ function lastMarkerSeq(ctx: ExtensionContext): number {
|
|
|
29
29
|
* model paging history_list meets a breadcrumb that tells it where it is. Skipped while a reset
|
|
30
30
|
* tail still awaits boot or continuation: a foreign message there would close the repair shape.
|
|
31
31
|
*/
|
|
32
|
-
export function
|
|
32
|
+
export function buildMarkerDraft(ctx: ExtensionContext, pending: readonly SessionBoundaryDraft[] = []): CustomMessageEntryDraft | undefined {
|
|
33
|
+
if (pending.some((entry) => entry.type === "custom" && entry.customType === RESET_MARKER_TYPE)) return;
|
|
33
34
|
const reset = currentReset(ctx);
|
|
34
35
|
if (reset) {
|
|
35
36
|
const tail = inspectResetTail(ctx, reset.id, reset.data.windowId);
|
|
36
37
|
if (tail && (!tail.boot || !tail.continuation)) return;
|
|
37
38
|
}
|
|
38
|
-
const seq = nextHistorySeq(ctx);
|
|
39
|
-
if (seq - lastMarkerSeq(ctx) < MARKER_INTERVAL) return;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
const seq = nextHistorySeq(ctx, pending);
|
|
40
|
+
if (seq - lastMarkerSeq(ctx, pending) < MARKER_INTERVAL) return;
|
|
41
|
+
return { type: "custom_message", customType: MARKER_TYPE, content: markerContent(seq), display: false, details: { seq } };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Run-start fallback; active runs append the same draft through the turn-end boundary. */
|
|
45
|
+
export function maybeSendMarker(pi: ExtensionAPI, ctx: ExtensionContext): void {
|
|
46
|
+
const draft = buildMarkerDraft(ctx);
|
|
47
|
+
if (!draft) return;
|
|
48
|
+
const { type: _type, ...message } = draft;
|
|
49
|
+
pi.sendMessage(message, { triggerTurn: false });
|
|
44
50
|
}
|
|
@@ -4,6 +4,7 @@ import { getCurrentSystemMessage, isContextOverflow, isRecoverableLength } from
|
|
|
4
4
|
import type { AgentBeforeSettleEvent, ExtensionAPI, ExtensionContext, SessionBoundaryDraft } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { currentReset, currentWindowId } from "../window.js";
|
|
6
6
|
import { nextHistorySeq } from "../history.js";
|
|
7
|
+
import { buildMarkerDraft } from "../marker.js";
|
|
7
8
|
import { resetBoundaryCommitted } from "./committed.js";
|
|
8
9
|
import type { ResetOrigin } from "../../../src/budget/text.js";
|
|
9
10
|
import { errorMessage } from "../../../src/error-message.js";
|
|
@@ -335,6 +336,10 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
|
|
|
335
336
|
if (decision.effect === "build-boundary") return await resetBoundaryResult(entries, ctx, decision);
|
|
336
337
|
if (aborted || (event.outcome === "error" && decision.state.request.phase === "none")) restoreCommandInputs();
|
|
337
338
|
control = decision.state;
|
|
339
|
+
if (!aborted && event.outcome !== "error" && options.isEnabled()) {
|
|
340
|
+
const marker = buildMarkerDraft(ctx, entries);
|
|
341
|
+
if (marker) entries.push(marker);
|
|
342
|
+
}
|
|
338
343
|
return entries.length > 0 ? { entries } : undefined;
|
|
339
344
|
});
|
|
340
345
|
|