pi-goal-list-loop-audit 0.40.1 → 0.41.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/CHANGELOG.md +27 -0
- package/README.md +3 -1
- package/docs/INDEX.md +1 -1
- package/docs/RECOVERY.md +16 -0
- package/docs/RUNTIME-INVENTORY.md +9 -9
- package/docs/SETTINGS.md +3 -1
- package/extensions/completion-summary.ts +59 -15
- package/extensions/decision-auto-select.ts +252 -0
- package/extensions/goal-commands.ts +162 -41
- package/extensions/goal-continuation.ts +31 -1
- package/extensions/goal-heartbeat.ts +105 -1
- package/extensions/goal-loop-core.ts +6 -0
- package/extensions/goal-loop-display.ts +14 -0
- package/extensions/goal-settings.ts +29 -0
- package/extensions/human-handoff.ts +6 -4
- package/extensions/loops/goal-activation.ts +24 -2
- package/extensions/loops/goal-orchestrator.ts +7 -0
- package/extensions/loops/goal-settings-ui.ts +24 -0
- package/extensions/loops/goal-tools.ts +1 -1
- package/extensions/loops/goal-ui.ts +4 -0
- package/extensions/loops/goal.ts +6 -2
- package/extensions/settings-menu.ts +9 -0
- package/extensions/summary-renderer.ts +9 -1
- package/package.json +1 -1
- package/prompts/goal-loop-continuation.md +1 -1
- package/schemas/goal.schema.json +1 -0
- package/scripts/summary-readability-capture.ts +4 -0
|
@@ -21,6 +21,13 @@ import type { ExtensionContext, ExtensionAPI } from "@earendil-works/pi-coding-a
|
|
|
21
21
|
import { renderAgentsPanel, tailChildTranscript, TRANSCRIPT_HEADER_SCAN_MAX_BYTES } from "./goal-agents-panel.js";
|
|
22
22
|
|
|
23
23
|
import { state, replaceState } from "./goal-state.js";
|
|
24
|
+
import {
|
|
25
|
+
decisionAutoSelectCandidate,
|
|
26
|
+
decisionAutoSelectAdoptable,
|
|
27
|
+
decisionAutoSelectCountdownMs,
|
|
28
|
+
decisionOptionText,
|
|
29
|
+
resolveDecisionAutoSelectMinutes,
|
|
30
|
+
} from "./decision-auto-select.js";
|
|
24
31
|
import {
|
|
25
32
|
DEFAULT_TOKEN_LIMIT, DEFAULT_COMPACTION_TOKEN_THRESHOLD, Goal, ListItem, Status, appendLedger, archiveDir, archivedGoalPath, auditVerdictLabel, sanitizeProviderDisplayText,
|
|
26
33
|
computeListDepthFromLedger, clearQueueItemFiles, deleteQueueItemFile, deleteQueueItemFileResult, extractVerificationContract, stripTweakProceduralTail, formatAuditLog, formatGoalAuditHistory, formatMainModelRecoveryStatus, queueItemSidecarCount, countTrailingDisapprovals,
|
|
@@ -957,6 +964,147 @@ function pendingDecision(): Goal | null {
|
|
|
957
964
|
return g && g.status === "paused" && g.pauseKind === "decision" && g.pauseOptions && g.pauseOptions.length > 0 ? g : null;
|
|
958
965
|
}
|
|
959
966
|
|
|
967
|
+
/** Act on ONE decision option — shared by the picker and the auto-select
|
|
968
|
+
* clock so the two surfaces can never disagree about what a pick means.
|
|
969
|
+
*
|
|
970
|
+
* Executable options (`Label (/goal resume)`) RUN the command; a placeholder
|
|
971
|
+
* (`…<arg>`) or prose option is steered to the agent and the work resumes.
|
|
972
|
+
* Returns false when the decision could not be delivered (work stays paused).
|
|
973
|
+
* Reserved options (cancel/accept/tweak/pause/stop) are NOT refused here —
|
|
974
|
+
* the picker may dispatch them as the operator's own hand; the auto-select
|
|
975
|
+
* clock refuses them BEFORE it reaches this function
|
|
976
|
+
* (decision-auto-select.ts owns that classification). */
|
|
977
|
+
async function actOnDecisionOption(
|
|
978
|
+
g: Goal,
|
|
979
|
+
label: string,
|
|
980
|
+
ctx: ExtensionContext,
|
|
981
|
+
): Promise<boolean> {
|
|
982
|
+
// v0.29.3: the wipe escape — "… (/glla wipe)" options run the wipe
|
|
983
|
+
// (which Confirms on its own — destructive actions keep their gate).
|
|
984
|
+
if (/\(\/glla wipe\)\s*$/.test(label)) {
|
|
985
|
+
await cmdGllaWipe(ctx);
|
|
986
|
+
return true;
|
|
987
|
+
}
|
|
988
|
+
// Executable options — "Label (/goal cancel)" — RUN the command.
|
|
989
|
+
// Placeholder commands (…/<arg>) fall through to the message path.
|
|
990
|
+
const cmdMatch = label.match(/\((\/goal|\/list|\/loop) ([a-z]+)\)\s*$/);
|
|
991
|
+
if (cmdMatch && !label.includes("…") && !label.includes("<")) {
|
|
992
|
+
const group = (cmdMatch[1] ?? "").replace(/^\//, "");
|
|
993
|
+
const verb = cmdMatch[2];
|
|
994
|
+
// v0.39.55: the interactive tweak editor is executable from the picker —
|
|
995
|
+
// bare tweak pre-fills the current text and its own Confirm gate applies.
|
|
996
|
+
// This is the recovery path for truncated proposals: the picker offers
|
|
997
|
+
// it instead of a broken copy-paste command.
|
|
998
|
+
if ((group === "goal" || group === "list") && verb === "tweak") { await cmdTweak("", ctx, group === "list" ? "list" : "goal"); return true; }
|
|
999
|
+
if (group === "goal" && verb === "resume") await cmdResume(ctx);
|
|
1000
|
+
else if (group === "goal" && verb === "cancel") await cmdCancel(ctx);
|
|
1001
|
+
else if (group === "goal" && verb === "accept") await cmdAcceptWithFollowups(ctx);
|
|
1002
|
+
else if (group === "goal" && verb === "pause") await cmdPause(ctx);
|
|
1003
|
+
else if (group === "list" && ["resume", "cancel", "pause", "next", "clear"].includes(verb!)) await cmdList(verb!, ctx);
|
|
1004
|
+
else if (group === "loop" && verb === "stop") await cmdLoop("stop", ctx);
|
|
1005
|
+
else if (group === "loop" && verb === "resume") await cmdLoop("resume", ctx);
|
|
1006
|
+
else if (group === "loop" && ["cancel", "pause", "finish"].includes(verb!)) await cmdLoop(verb!, ctx);
|
|
1007
|
+
else {
|
|
1008
|
+
if (!safeSteerUser(ctx, `Decision for the paused goal "${displaySlice(g.objective, 240)}": ${sanitizeDisplayText(label)} — continue on this path.`)) {
|
|
1009
|
+
ctx.ui.notify("Decision could not be delivered — work stays paused. /goal decide to retry.", "warning");
|
|
1010
|
+
return false;
|
|
1011
|
+
}
|
|
1012
|
+
await cmdResume(ctx);
|
|
1013
|
+
}
|
|
1014
|
+
return true;
|
|
1015
|
+
}
|
|
1016
|
+
// Content choice — deliver to the agent, then resume.
|
|
1017
|
+
if (!safeSteerUser(ctx, `Decision for the paused goal "${displaySlice(g.objective, 240)}": ${sanitizeDisplayText(label)} — continue on this path.`)) {
|
|
1018
|
+
ctx.ui.notify("Decision could not be delivered — work stays paused. /goal decide to retry.", "warning");
|
|
1019
|
+
return false;
|
|
1020
|
+
}
|
|
1021
|
+
await cmdResume(ctx);
|
|
1022
|
+
return true;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* Adopt the RECOMMENDED option because the operator's configured delay
|
|
1027
|
+
* (`decisionAutoSelectMinutes`) elapsed with nobody there. This is the ONE
|
|
1028
|
+
* adoption path — the picker's countdown expiry and the heartbeat backstop
|
|
1029
|
+
* both call it, so the ledger, the assumption log, and the eligibility rule
|
|
1030
|
+
* cannot drift between them.
|
|
1031
|
+
*
|
|
1032
|
+
* SAFETY: nothing is adopted unless the option classifies as continue-work.
|
|
1033
|
+
* A reserved answer (cancel/accept/tweak/pause/stop/clear/wipe), a `/glla`
|
|
1034
|
+
* settings task, or a contract amendment keeps the pause parked and says so
|
|
1035
|
+
* ONCE per episode — an absent agent must not end or rewrite the work on the
|
|
1036
|
+
* operator's behalf.
|
|
1037
|
+
*
|
|
1038
|
+
* Returns "adopted" | "refused" | "stale" (the decision changed under us).
|
|
1039
|
+
* A refused delivery ("the answer could not be carried") is also "refused":
|
|
1040
|
+
* the pause stays parked and the failure is ledgered rather than retried
|
|
1041
|
+
* forever against a host that cannot send.
|
|
1042
|
+
*/
|
|
1043
|
+
export async function adoptRecommendedDecision(
|
|
1044
|
+
g: Goal,
|
|
1045
|
+
ctx: ExtensionContext,
|
|
1046
|
+
minutes?: number,
|
|
1047
|
+
): Promise<"adopted" | "refused" | "stale"> {
|
|
1048
|
+
if (pendingDecision() !== g) return "stale";
|
|
1049
|
+
const candidate = decisionAutoSelectCandidate(g);
|
|
1050
|
+
if (!candidate) return "refused";
|
|
1051
|
+
if (!candidate.verdict.adoptable) {
|
|
1052
|
+
// Announce it ONCE per episode instead of on every heartbeat tick.
|
|
1053
|
+
const tail = readLedgerTail(ctx.cwd, 200);
|
|
1054
|
+
const alreadySaid = tail.some((record) => record.type === "decision_auto_select_refused"
|
|
1055
|
+
&& (record.value as { goalId?: string } | undefined)?.goalId === g.id);
|
|
1056
|
+
if (!alreadySaid) {
|
|
1057
|
+
appendLedger(ctx.cwd, "decision_auto_select_refused", { goalId: g.id, option: candidate.option.slice(0, 200), reason: candidate.verdict.reason });
|
|
1058
|
+
ctx.ui.notify(`Decision auto-select declined — ${candidate.verdict.reason}. The question stays parked for you: ${activeGoalSurfaceCommand("decide")}.`, "info");
|
|
1059
|
+
}
|
|
1060
|
+
return "refused";
|
|
1061
|
+
}
|
|
1062
|
+
// The assumption log entry is what the agent must carry into its recap; it
|
|
1063
|
+
// has the same shape the mid-run decision default uses.
|
|
1064
|
+
const entry = {
|
|
1065
|
+
at: new Date().toISOString(),
|
|
1066
|
+
reason: (g.pauseReason ?? "decision pause").slice(0, 300),
|
|
1067
|
+
chosen: decisionOptionText(candidate.option).slice(0, 300),
|
|
1068
|
+
options: (g.pauseOptions ?? []).map((option) => decisionOptionText(option).slice(0, 200)).slice(0, 10),
|
|
1069
|
+
};
|
|
1070
|
+
if (!updateGoal({ autoDefaultLog: [...(g.autoDefaultLog ?? []), entry].slice(-20) }, ctx)) return "refused";
|
|
1071
|
+
const waitedMs = g.pauseDecidedAt ? Date.now() - Date.parse(g.pauseDecidedAt) : undefined;
|
|
1072
|
+
const details = {
|
|
1073
|
+
goalId: g.id,
|
|
1074
|
+
minutes,
|
|
1075
|
+
shape: candidate.verdict.shape,
|
|
1076
|
+
optionIndex: candidate.index,
|
|
1077
|
+
chosen: entry.chosen,
|
|
1078
|
+
...(waitedMs !== undefined && Number.isFinite(waitedMs) ? { waitedMs } : {}),
|
|
1079
|
+
};
|
|
1080
|
+
const delivered = await actOnDecisionOption(g, candidate.option, ctx);
|
|
1081
|
+
// The adoption row claims the WORK MOVED, so it is written only after the
|
|
1082
|
+
// answer actually landed. A refused delivery (a stale handle, an
|
|
1083
|
+
// undeliverable steer) keeps the pause parked and records the failure instead
|
|
1084
|
+
// — reporting "adopted" over a still-parked goal is the exact dishonesty the
|
|
1085
|
+
// paused-is-safe invariant exists to prevent.
|
|
1086
|
+
if (!delivered) {
|
|
1087
|
+
appendLedger(ctx.cwd, "decision_auto_select_delivery_failed", { ...details, reason: "the answer could not be delivered" });
|
|
1088
|
+
return "refused";
|
|
1089
|
+
}
|
|
1090
|
+
appendLedger(ctx.cwd, "decision_auto_select_adopted", details);
|
|
1091
|
+
ctx.ui.notify(`Decision auto-selected after ${minutes ?? "?"}m without an answer — option ${candidate.index}: ${entry.chosen}. It is expected in the completion recap as an assumption; ${activeGoalSurfaceCommand("cancel")} still stops the work.`, "info");
|
|
1092
|
+
return "adopted";
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
/** Adopt the recommended decision for the goal's OWN current pause — the
|
|
1096
|
+
* heartbeat's entry point (it has no captured Goal handle). Returns "stale"
|
|
1097
|
+
* when the pause moved on, so a caller never adopts a different question. */
|
|
1098
|
+
export async function adoptRecommendedDecisionNow(
|
|
1099
|
+
ctx: ExtensionContext,
|
|
1100
|
+
minutes: number,
|
|
1101
|
+
): Promise<"adopted" | "refused" | "stale"> {
|
|
1102
|
+
const g = pendingDecision();
|
|
1103
|
+
if (!g) return "stale";
|
|
1104
|
+
return adoptRecommendedDecision(g, ctx, minutes);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
|
|
960
1108
|
/** Open the decision picker for the current decision pause. Returns true
|
|
961
1109
|
* when a picker was shown (false → caller notifies "no pending decision"). */
|
|
962
1110
|
async function showDecisionPrompt(ctx: ExtensionContext): Promise<boolean> {
|
|
@@ -967,8 +1115,18 @@ async function showDecisionPrompt(ctx: ExtensionContext): Promise<boolean> {
|
|
|
967
1115
|
try {
|
|
968
1116
|
const title = `Decision needed — ${displaySlice(g.objective, 72)}${g.pauseReason ? ` · ${displaySlice(sanitizeProviderDisplayText(g.pauseReason), 80)}` : ""}`;
|
|
969
1117
|
const options = g.pauseOptions!.map((o, i) => (g.pauseRecommended === i + 1 ? `${o} (recommended)` : o));
|
|
970
|
-
const
|
|
971
|
-
|
|
1118
|
+
const minutes = loadSettings(ctx.cwd).decisionAutoSelectMinutes;
|
|
1119
|
+
const countdownMs = decisionAutoSelectCountdownMs(g, minutes, Date.now());
|
|
1120
|
+
const pick = await ctx.ui.select(title, options, countdownMs === undefined ? undefined : { timeout: countdownMs });
|
|
1121
|
+
if (!pick) {
|
|
1122
|
+
// Escape and a host timeout both resolve undefined. A pick-less close is
|
|
1123
|
+
// only an ADOPTION when the durable clock says the delay elapsed — a
|
|
1124
|
+
// deliberate Escape before the deadline leaves the pause for the card.
|
|
1125
|
+
if (pendingDecision() === g && decisionAutoSelectAdoptable(g, minutes, Date.now())) {
|
|
1126
|
+
await adoptRecommendedDecision(g, ctx, resolveDecisionAutoSelectMinutes(minutes));
|
|
1127
|
+
}
|
|
1128
|
+
return true; // The widget card remains the fallback
|
|
1129
|
+
}
|
|
972
1130
|
if (warnIfStaleAtEntry(ctx, "/goal decide selection")) return true;
|
|
973
1131
|
if (pendingDecision() !== g) {
|
|
974
1132
|
ctx.ui.notify("Decision changed while the picker was open — selection was not applied. /goal decide shows the current choice.", "info");
|
|
@@ -1004,45 +1162,7 @@ async function showDecisionPrompt(ctx: ExtensionContext): Promise<boolean> {
|
|
|
1004
1162
|
return true;
|
|
1005
1163
|
}
|
|
1006
1164
|
const label = g.pauseOptions![idx] ?? pick.replace(/ {2}\(recommended\)$/, "");
|
|
1007
|
-
|
|
1008
|
-
// (which Confirms on its own — destructive actions keep their gate).
|
|
1009
|
-
if (/\(\/glla wipe\)\s*$/.test(label)) {
|
|
1010
|
-
await cmdGllaWipe(ctx);
|
|
1011
|
-
return true;
|
|
1012
|
-
}
|
|
1013
|
-
// Executable options — "Label (/goal cancel)" — RUN the command.
|
|
1014
|
-
// Placeholder commands (…/<arg>) fall through to the message path.
|
|
1015
|
-
const cmdMatch = label.match(/\(\/(goal|list|loop) ([a-z]+)\)\s*$/);
|
|
1016
|
-
if (cmdMatch && !label.includes("…") && !label.includes("<")) {
|
|
1017
|
-
const [, group, verb] = cmdMatch;
|
|
1018
|
-
// v0.39.55: the interactive tweak editor is executable from the picker —
|
|
1019
|
-
// bare tweak pre-fills the current text and its own Confirm gate applies.
|
|
1020
|
-
// This is the recovery path for truncated proposals: the picker offers
|
|
1021
|
-
// it instead of a broken copy-paste command.
|
|
1022
|
-
if ((group === "goal" || group === "list") && verb === "tweak") { await cmdTweak("", ctx, group === "list" ? "list" : "goal"); return true; }
|
|
1023
|
-
if (group === "goal" && verb === "resume") await cmdResume(ctx);
|
|
1024
|
-
else if (group === "goal" && verb === "cancel") await cmdCancel(ctx);
|
|
1025
|
-
else if (group === "goal" && verb === "accept") await cmdAcceptWithFollowups(ctx);
|
|
1026
|
-
else if (group === "goal" && verb === "pause") await cmdPause(ctx);
|
|
1027
|
-
else if (group === "list" && ["resume", "cancel", "pause", "next", "clear"].includes(verb!)) await cmdList(verb!, ctx);
|
|
1028
|
-
else if (group === "loop" && verb === "stop") await cmdLoop("stop", ctx);
|
|
1029
|
-
else if (group === "loop" && verb === "resume") await cmdLoop("resume", ctx);
|
|
1030
|
-
else if (group === "loop" && ["cancel", "pause", "finish"].includes(verb!)) await cmdLoop(verb!, ctx);
|
|
1031
|
-
else {
|
|
1032
|
-
if (!safeSteerUser(ctx, `Decision for the paused goal "${displaySlice(g.objective, 240)}": ${sanitizeDisplayText(label)} — continue on this path.`)) {
|
|
1033
|
-
ctx.ui.notify("Decision could not be delivered — work stays paused. /goal decide to retry.", "warning");
|
|
1034
|
-
return true;
|
|
1035
|
-
}
|
|
1036
|
-
await cmdResume(ctx);
|
|
1037
|
-
}
|
|
1038
|
-
return true;
|
|
1039
|
-
}
|
|
1040
|
-
// Content choice — deliver to the agent, then resume.
|
|
1041
|
-
if (!safeSteerUser(ctx, `Decision for the paused goal "${displaySlice(g.objective, 240)}": ${sanitizeDisplayText(label)} — continue on this path.`)) {
|
|
1042
|
-
ctx.ui.notify("Decision could not be delivered — work stays paused. /goal decide to retry.", "warning");
|
|
1043
|
-
return true;
|
|
1044
|
-
}
|
|
1045
|
-
await cmdResume(ctx);
|
|
1165
|
+
await actOnDecisionOption(g, label, ctx);
|
|
1046
1166
|
return true;
|
|
1047
1167
|
} finally {
|
|
1048
1168
|
decisionPromptOpen = false;
|
|
@@ -3799,6 +3919,7 @@ async function cmdSettings(args: string, ctx: ExtensionContext): Promise<void> {
|
|
|
3799
3919
|
fmt("auditCapHard", "auditCapHard"),
|
|
3800
3920
|
fmt("mechanicalLoadScale", "mechanicalLoadScale"),
|
|
3801
3921
|
fmt("decisionPauseBudget", "decisionPauseBudget"),
|
|
3922
|
+
fmt("decisionAutoSelectMinutes", "decisionAutoSelectMinutes (unset = off; recommended continue-work only)"),
|
|
3802
3923
|
fmt("auditFeedbackChars", "auditFeedbackChars"),
|
|
3803
3924
|
fmt("aggressiveMode", "aggressiveMode"),
|
|
3804
3925
|
fmt("stuckMaxInterventions", "stuckMaxInterventions"),
|
|
@@ -326,6 +326,31 @@ let continuationInitialFullSentFor: string | null = null;
|
|
|
326
326
|
export function resetContinuationInitialSend(): void {
|
|
327
327
|
continuationInitialFullSentFor = null;
|
|
328
328
|
deliveredAuditFingerprints.clear();
|
|
329
|
+
deliveredPendingTasks.clear();
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Field 2026-11-18: per-goal hash of the auditor TODO list already delivered
|
|
333
|
+
* in a full brief. `pendingTasks` forced a full ~28 KB send on EVERY rework
|
|
334
|
+
* turn: in the local record 160 of 258 recent full sends carried an unchanged
|
|
335
|
+
* TODO list the model had already been given. A new or edited list still goes
|
|
336
|
+
* full; an unchanged one rides the marker like any other steady-state turn. */
|
|
337
|
+
const deliveredPendingTasks = new Map<string, string>();
|
|
338
|
+
function pendingTasksFingerprint(tasks: readonly string[] | undefined): string | undefined {
|
|
339
|
+
if (!tasks || tasks.length === 0) return undefined;
|
|
340
|
+
return createHash("sha256").update(JSON.stringify(tasks), "utf8").digest("hex").slice(0, 16);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** A compaction may summarize away the full brief that carried the audit
|
|
344
|
+
* report and the TODO list, so the next send must teach them again. Cheaper
|
|
345
|
+
* than the alternative: one full send per compaction during rework instead of
|
|
346
|
+
* one per turn. */
|
|
347
|
+
export function forgetDeliveredReworkContext(): void {
|
|
348
|
+
deliveredAuditFingerprints.clear();
|
|
349
|
+
deliveredPendingTasks.clear();
|
|
350
|
+
}
|
|
351
|
+
export function __testOnlyRecordDeliveredPendingTasks(goalId: string, tasks: readonly string[] | undefined): void {
|
|
352
|
+
const fp = pendingTasksFingerprint(tasks);
|
|
353
|
+
if (fp) deliveredPendingTasks.set(goalId, fp); else deliveredPendingTasks.delete(goalId);
|
|
329
354
|
}
|
|
330
355
|
export function __testOnlyRecordDeliveredAudit(goalId: string, fp: AuditEvidenceFingerprint | undefined): void {
|
|
331
356
|
if (fp) deliveredAuditFingerprints.set(goalId, fp); else deliveredAuditFingerprints.delete(goalId);
|
|
@@ -1579,7 +1604,8 @@ export function buildMarkerContent(goalId: string): string {
|
|
|
1579
1604
|
export function needsFullContinuation(goal: Goal): boolean {
|
|
1580
1605
|
if (goal.repairTarget) return true;
|
|
1581
1606
|
if (goal.autoResumedAt) return true;
|
|
1582
|
-
if (!auditorSurfaceSuppressed(goal.id) && goal.pendingTasks && goal.pendingTasks.length > 0
|
|
1607
|
+
if (!auditorSurfaceSuppressed(goal.id) && goal.pendingTasks && goal.pendingTasks.length > 0
|
|
1608
|
+
&& pendingTasksFingerprint(goal.pendingTasks) !== deliveredPendingTasks.get(goal.id)) return true;
|
|
1583
1609
|
const lastAudit = goal.auditHistory?.[goal.auditHistory.length - 1];
|
|
1584
1610
|
if (lastAudit && lastAudit.report && !auditorSurfaceSuppressed(goal.id)) {
|
|
1585
1611
|
const fp = auditEvidenceFingerprint(lastAudit);
|
|
@@ -1779,6 +1805,10 @@ export function sendContinuation(goalId: string): void {
|
|
|
1779
1805
|
continuationInitialFullSentFor = goalId;
|
|
1780
1806
|
const fp = auditEvidenceFingerprint(goalForSend.auditHistory?.[goalForSend.auditHistory.length - 1]);
|
|
1781
1807
|
if (fp) deliveredAuditFingerprints.set(goalId, fp);
|
|
1808
|
+
// The TODO list rides the full brief only while the auditor surface is
|
|
1809
|
+
// shown; a suppressed surface delivered nothing, so record nothing.
|
|
1810
|
+
const tasksFp = auditorSurfaceSuppressed(goalId) ? undefined : pendingTasksFingerprint(goalForSend.pendingTasks);
|
|
1811
|
+
if (tasksFp) deliveredPendingTasks.set(goalId, tasksFp); else deliveredPendingTasks.delete(goalId);
|
|
1782
1812
|
}
|
|
1783
1813
|
continuationRearmStreak = 0; continuationRearmSince = 0; // v0.28.5 (E3): an accepted dispatch clears the storm
|
|
1784
1814
|
appendLedger(ctx.cwd, "goal_continuation_sent", { goalId, attemptId: attempt.id, generation: attempt.generation, kind, payloadChars: content.length, ...(busyBypass ? { busyBypass: true } : {}) });
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
type Goal,
|
|
35
35
|
} from "./goal-loop-core.js";
|
|
36
36
|
import { loadSettings } from "./goal-settings.js";
|
|
37
|
+
import { decisionAutoSelectDue as decisionAutoSelectDueNow, resolveDecisionAutoSelectMinutes } from "./decision-auto-select.js";
|
|
37
38
|
import { isCompactionInFlightSince, classifyMainModelFailure, isEagerRetryFailure, type MainModelFailureKind } from "./main-model-recovery.js";
|
|
38
39
|
import {
|
|
39
40
|
HEARTBEAT_STALL_MS,
|
|
@@ -124,6 +125,11 @@ export interface HeartbeatDeps {
|
|
|
124
125
|
continuationUnansweredThrottleMs: number;
|
|
125
126
|
/** Abort and durably park the owner of a confirmed zero-stream turn. */
|
|
126
127
|
abortZombieRun(ctx: ExtensionContext, generation: number, goalId: string | undefined, lastStreamActivityAt: number): boolean;
|
|
128
|
+
/** v0.39.x (the stuck-question clock): adopt the RECOMMENDED continue-work
|
|
129
|
+
* option of a decision pause whose configured delay elapsed. Injected from
|
|
130
|
+
* goal.ts (goal-commands owns the pause actions, so the adoption path lives
|
|
131
|
+
* beside the picker — the heartbeat must stay acyclic). */
|
|
132
|
+
adoptRecommendedDecision(ctx: ExtensionContext, minutes: number): Promise<"adopted" | "refused" | "stale">;
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
let flags: HeartbeatFlags;
|
|
@@ -150,6 +156,7 @@ let goalNoun: HeartbeatDeps["goalNoun"];
|
|
|
150
156
|
let continuationUnansweredMs: HeartbeatDeps["continuationUnansweredMs"];
|
|
151
157
|
let continuationUnansweredThrottleMs: HeartbeatDeps["continuationUnansweredThrottleMs"];
|
|
152
158
|
let abortZombieRun: HeartbeatDeps["abortZombieRun"];
|
|
159
|
+
let adoptRecommendedDecision: HeartbeatDeps["adoptRecommendedDecision"];
|
|
153
160
|
|
|
154
161
|
export function createGoalHeartbeat(flagsArg: HeartbeatFlags, d: HeartbeatDeps): void {
|
|
155
162
|
flags = flagsArg;
|
|
@@ -174,6 +181,7 @@ export function createGoalHeartbeat(flagsArg: HeartbeatFlags, d: HeartbeatDeps):
|
|
|
174
181
|
continuationUnansweredMs = d.continuationUnansweredMs;
|
|
175
182
|
continuationUnansweredThrottleMs = d.continuationUnansweredThrottleMs;
|
|
176
183
|
abortZombieRun = d.abortZombieRun;
|
|
184
|
+
adoptRecommendedDecision = d.adoptRecommendedDecision;
|
|
177
185
|
}
|
|
178
186
|
|
|
179
187
|
// ----------------------------------------------------------------------------
|
|
@@ -261,6 +269,92 @@ const WAIT_OVERDUE_GRACE_MS = 90 * 1_000;
|
|
|
261
269
|
* rewrites pauseResumeAt when it re-parks, which re-arms the key. */
|
|
262
270
|
let lastOverdueWaitKey = "";
|
|
263
271
|
|
|
272
|
+
// ---------------------------------------------------------------------------
|
|
273
|
+
// v0.39.x — the STUCK-QUESTION clock (operator: "auto select recommended
|
|
274
|
+
// answer after a longer delay so we don't get stuck in case we are thrown an
|
|
275
|
+
// odd question").
|
|
276
|
+
//
|
|
277
|
+
// A decision pause has no clock: it waits for a human forever. The opt-in
|
|
278
|
+
// setting `decisionAutoSelectMinutes` gives it one, and this backstop is the
|
|
279
|
+
// surface-independent half — the picker countdown covers the dialog case, and
|
|
280
|
+
// this covers every case where no dialog ever opened (headless rigs, the
|
|
281
|
+
// popup setting turned off, an Escape, a restart mid-question).
|
|
282
|
+
//
|
|
283
|
+
// The eligibility rule is NOT here: adoptRecommendedDecision (goal-commands,
|
|
284
|
+
// injected through HeartbeatDeps) refuses anything that is not a continue-work
|
|
285
|
+
// answer. This module only decides WHEN the clock is due.
|
|
286
|
+
//
|
|
287
|
+
// One adoption per (goalId:pauseDecidedAt) pair. A REFUSED answer is latched
|
|
288
|
+
// (nothing to do until the operator acts); a failed adoption is left
|
|
289
|
+
// UNLATCHED so the next tick retries — same question, same clock, and the
|
|
290
|
+
// paused-is-safe invariant is untouched because nothing was resumed.
|
|
291
|
+
let lastDecisionAutoSelectKey = "";
|
|
292
|
+
let decisionAutoSelectInFlight = false;
|
|
293
|
+
/** The `decision_auto_select_due` ledger fence, separate from the adoption
|
|
294
|
+
* latch: a FAILED adoption is retried (no latch), but the "your clock expired"
|
|
295
|
+
* row must not be re-written on every retry tick. Re-armed by a new episode. */
|
|
296
|
+
let lastDecisionAutoSelectDueKey = "";
|
|
297
|
+
|
|
298
|
+
/** The cwd the last healthy heartbeat observed — settings live there. */
|
|
299
|
+
function heartbeatCwd(): string | undefined {
|
|
300
|
+
try {
|
|
301
|
+
return flags.lastCtx?.cwd || undefined;
|
|
302
|
+
} catch {
|
|
303
|
+
return undefined; // a disposed host throws on ANY property access
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Minutes when the delay is armed AND has actually elapsed, else undefined. */
|
|
308
|
+
function decisionAutoSelectWaitMinutes(): number | undefined {
|
|
309
|
+
const goal = state.goal;
|
|
310
|
+
if (!goal || goal.status !== "paused" || goal.pauseKind !== "decision") return undefined;
|
|
311
|
+
const cwd = heartbeatCwd();
|
|
312
|
+
if (!cwd) return undefined;
|
|
313
|
+
const minutes = resolveDecisionAutoSelectMinutes(loadSettings(cwd).decisionAutoSelectMinutes);
|
|
314
|
+
if (minutes === undefined) return undefined;
|
|
315
|
+
if (supervisorPaused(state)) return undefined;
|
|
316
|
+
if (!decisionAutoSelectDueNow(goal, minutes, Date.now())) return undefined;
|
|
317
|
+
const key = `${goal.id}:${goal.pauseDecidedAt ?? goal.updatedAt}`;
|
|
318
|
+
if (key === lastDecisionAutoSelectKey) return undefined;
|
|
319
|
+
return minutes;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function decisionAutoSelectBackstop(ctx: ExtensionContext, minutes: number): void {
|
|
323
|
+
// A stale/handed-off handle cannot carry the resume the adoption performs:
|
|
324
|
+
// the pause would be consumed with nothing scheduled (exactly the
|
|
325
|
+
// paused-is-safe violation the overdue-wait backstop documents above).
|
|
326
|
+
if (flags.sessionHandoffPending || flags.staleTerminalDone || flags.extensionApiStale) return;
|
|
327
|
+
if (mainModelRecoveryActive()) return;
|
|
328
|
+
if (decisionAutoSelectInFlight) return;
|
|
329
|
+
const goal = state.goal;
|
|
330
|
+
if (!goal || goal.status !== "paused" || goal.pauseKind !== "decision") return;
|
|
331
|
+
const key = `${goal.id}:${goal.pauseDecidedAt ?? goal.updatedAt}`;
|
|
332
|
+
if (lastDecisionAutoSelectDueKey !== key) {
|
|
333
|
+
lastDecisionAutoSelectDueKey = key;
|
|
334
|
+
appendLedger(ctx.cwd, "decision_auto_select_due", {
|
|
335
|
+
goalId: goal.id,
|
|
336
|
+
minutes,
|
|
337
|
+
...(goal.pauseDecidedAt ? { waitedMs: Date.now() - Date.parse(goal.pauseDecidedAt) } : {}),
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
decisionAutoSelectInFlight = true;
|
|
341
|
+
void adoptRecommendedDecision(ctx, minutes)
|
|
342
|
+
.then((outcome) => {
|
|
343
|
+
// "refused"/"stale" are answers, not transient failures: the question
|
|
344
|
+
// keeps its own clock state and the operator still owns it — latch, or
|
|
345
|
+
// the tick would re-announce the same refusal forever.
|
|
346
|
+
if (outcome !== "adopted") lastDecisionAutoSelectKey = key;
|
|
347
|
+
})
|
|
348
|
+
.catch(() => { /* retry on the next tick — the pause is unchanged */ })
|
|
349
|
+
.finally(() => { decisionAutoSelectInFlight = false; });
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function __testOnlyResetDecisionAutoSelect(): void {
|
|
353
|
+
lastDecisionAutoSelectKey = "";
|
|
354
|
+
lastDecisionAutoSelectDueKey = "";
|
|
355
|
+
decisionAutoSelectInFlight = false;
|
|
356
|
+
}
|
|
357
|
+
|
|
264
358
|
function overdueWaitDue(): boolean {
|
|
265
359
|
const goal = state.goal;
|
|
266
360
|
if (!goal || goal.status !== "paused" || goal.pauseKind !== "wait") return false;
|
|
@@ -1379,7 +1473,11 @@ function heartbeatTick(): void {
|
|
|
1379
1473
|
&& state.goal.pendingCompletion?.phase === "recovery-pending";
|
|
1380
1474
|
// v0.35.28 (issue #16): a lapsed wait-pause is host-bound work too — the
|
|
1381
1475
|
// heartbeat owns its durable due-time backstop (see overdueWaitBackstop).
|
|
1382
|
-
|
|
1476
|
+
// Evaluated ONCE per tick: the gate needs it to decide whether this tick has
|
|
1477
|
+
// any host-bound work at all, and the backstop below reuses the same reading
|
|
1478
|
+
// (a second loadSettings on every tick would be waste, not correctness).
|
|
1479
|
+
const autoSelectMinutes = decisionAutoSelectWaitMinutes();
|
|
1480
|
+
if (overdueWaitDue() || autoSelectMinutes !== undefined) {
|
|
1383
1481
|
// fall through: the backstop below needs a heartbeat opportunity
|
|
1384
1482
|
} else if (state.goal?.status !== "active"
|
|
1385
1483
|
&& state.goal?.status !== "auditing"
|
|
@@ -1562,6 +1660,12 @@ function heartbeatTick(): void {
|
|
|
1562
1660
|
return;
|
|
1563
1661
|
}
|
|
1564
1662
|
overdueWaitBackstop(ctx);
|
|
1663
|
+
// The stuck-question clock (opt-in `decisionAutoSelectMinutes`), read by the
|
|
1664
|
+
// gate at the top of this tick. Same "is there a live host to carry the
|
|
1665
|
+
// resume" boundary the overdue backstop documents; the eligibility rule
|
|
1666
|
+
// inside the injected adoption refuses anything that is not a
|
|
1667
|
+
// continue-work answer.
|
|
1668
|
+
if (autoSelectMinutes !== undefined) decisionAutoSelectBackstop(ctx, autoSelectMinutes);
|
|
1565
1669
|
let idle = false;
|
|
1566
1670
|
let pending = false;
|
|
1567
1671
|
try {
|
|
@@ -1145,6 +1145,12 @@ export interface Goal {
|
|
|
1145
1145
|
pauseOptions?: string[];
|
|
1146
1146
|
/** v0.28.22: 1-based index into pauseOptions the agent recommends. */
|
|
1147
1147
|
pauseRecommended?: number;
|
|
1148
|
+
/** v0.39.x: ISO time the current pause EPISODE began — stamped by every
|
|
1149
|
+
* pause write that lands fresh pause fields, so the auto-select clock
|
|
1150
|
+
* (`decisionAutoSelectMinutes`) measures the real waiting time instead of
|
|
1151
|
+
* `updatedAt` (which later touches bump). Absent on legacy records; readers
|
|
1152
|
+
* fall back to `updatedAt`, which the pause write itself stamped. */
|
|
1153
|
+
pauseDecidedAt?: string;
|
|
1148
1154
|
/** Concrete consent proposal; acceptance must match this base before writing. */
|
|
1149
1155
|
pauseContractAmendment?: { baseContract: string; baseRevision: number; amendment: ContractAmendment };
|
|
1150
1156
|
/** v0.38.69 (Antigravity port): mid-run decision-pause accounting — every
|
|
@@ -261,6 +261,12 @@ export interface WidgetExtras {
|
|
|
261
261
|
auditorProgressSignals?: boolean;
|
|
262
262
|
/** Compact live audit HUD; detailed history remains in /goal status. */
|
|
263
263
|
compactAuditCard?: boolean;
|
|
264
|
+
/** v0.39.x (the stuck-question clock): when `decisionAutoSelectMinutes` is
|
|
265
|
+
* armed and the recommended option may be adopted, the ONE line that says
|
|
266
|
+
* so ("auto-answers with option N in Xm unless you decide first"). Resolved
|
|
267
|
+
* at render contact by the caller — this module keeps zero runtime imports,
|
|
268
|
+
* so the classification lives in decision-auto-select.ts. */
|
|
269
|
+
decisionAutoSelectLine?: string;
|
|
264
270
|
/** Physical widget height budget; bounded independently from terminal width. */
|
|
265
271
|
maxWidgetLines?: number;
|
|
266
272
|
/** Effective global main-model backup order for truthful recovery HUDs. */
|
|
@@ -3491,6 +3497,14 @@ function goalLines(g: Goal, state: State, audit: AuditDisplayProgress | null | u
|
|
|
3491
3497
|
lines.push(`│ ${paint(theme, rec ? "accent" : "dim", text)}`);
|
|
3492
3498
|
});
|
|
3493
3499
|
if (decisionOptions.length > 6) lines.push(`│ ${paint(theme, "dim", `… and ${decisionOptions.length - 6} more`)}`);
|
|
3500
|
+
// v0.39.x: the stuck-question clock — say plainly that this question
|
|
3501
|
+
// will answer itself, so nobody is surprised by an adoption. Absent
|
|
3502
|
+
// when the clock is off or the recommendation may not be adopted.
|
|
3503
|
+
if (extras?.decisionAutoSelectLine) {
|
|
3504
|
+
wrap(extras.decisionAutoSelectLine, budget, 2).forEach((w) => {
|
|
3505
|
+
lines.push(`│ ${paint(theme, "dim", w)}`);
|
|
3506
|
+
});
|
|
3507
|
+
}
|
|
3494
3508
|
// Close the options block; the history helper reopens it when deferred
|
|
3495
3509
|
// rows follow.
|
|
3496
3510
|
const lastOpt = lines[lines.length - 1];
|
|
@@ -54,6 +54,9 @@ import {
|
|
|
54
54
|
DEFAULT_ZOMBIE_RETRY_MAX_ATTEMPTS,
|
|
55
55
|
MAX_ZOMBIE_RETRY_ATTEMPTS,
|
|
56
56
|
} from "./goal-loop-backoff.js";
|
|
57
|
+
// Upper bound for decisionAutoSelectMinutes — the modules stay acyclic
|
|
58
|
+
// (decision-auto-select imports only the Goal type).
|
|
59
|
+
import { DECISION_AUTO_SELECT_MAX_MINUTES } from "./decision-auto-select.js";
|
|
57
60
|
|
|
58
61
|
/** v0.38.104: the one thinking ladder. normalizeLoadedSettings prunes every
|
|
59
62
|
* level-bearing setting against this list — the per-agent override map and the
|
|
@@ -252,6 +255,17 @@ export interface Settings {
|
|
|
252
255
|
* unclassified human decisions require classification, and authorized
|
|
253
256
|
* mechanical/reversible work continues without a decision. */
|
|
254
257
|
decisionPauseBudget?: number;
|
|
258
|
+
/** The stuck-question clock: minutes a decision pause may sit before its
|
|
259
|
+
* RECOMMENDED continue-work answer is adopted automatically. Unset (the
|
|
260
|
+
* default) = never — the pause waits for you indefinitely. Only a
|
|
261
|
+
* continue-work recommendation (`/goal resume`, `/list resume`, `/list next`,
|
|
262
|
+
* `/loop resume`, or content the picker steers to the agent) may be adopted;
|
|
263
|
+
* cancel/accept/tweak/pause/stop/clear/wipe/contract-amendment options never
|
|
264
|
+
* are, because those end or rewrite the work rather than unstick it. Both the
|
|
265
|
+
* `/goal decide` picker countdown and the heartbeat backstop honour it. Global
|
|
266
|
+
* only: one answer for how long YOU stay away is machine policy, not a project
|
|
267
|
+
* artifact. */
|
|
268
|
+
decisionAutoSelectMinutes?: number;
|
|
255
269
|
/** v0.28.14: what happens to stale carryover (paused goal, waiting list,
|
|
256
270
|
* held loop from before this session) when NEW work activates.
|
|
257
271
|
* pause (default) = leave it + ONE summary; clear = drop it all honestly;
|
|
@@ -387,6 +401,11 @@ export const GLOBAL_ONLY_KEYS: ReadonlySet<keyof Settings> = new Set([
|
|
|
387
401
|
"mainModelPrimaryProbeMinutes",
|
|
388
402
|
"hourlyRetryProbe",
|
|
389
403
|
"autoResume",
|
|
404
|
+
// v0.39.x: how long the OPERATOR stays away before a decision takes its own
|
|
405
|
+
// recommended answer is machine policy about a person, not a property of one
|
|
406
|
+
// repository — a project copy could silently adopt a recommendation in one
|
|
407
|
+
// tree and wait forever in the next.
|
|
408
|
+
"decisionAutoSelectMinutes",
|
|
390
409
|
"drafterModel",
|
|
391
410
|
"drafterThinkingLevel",
|
|
392
411
|
"drafterModelFallbacks",
|
|
@@ -822,6 +841,15 @@ export function normalizeLoadedSettings(settings: Settings): Settings {
|
|
|
822
841
|
}
|
|
823
842
|
if (typeof settings.decisionPopup !== "boolean") delete settings.decisionPopup;
|
|
824
843
|
if (settings.decisionPauseBudget !== undefined && (!Number.isInteger(settings.decisionPauseBudget) || settings.decisionPauseBudget < 0)) delete settings.decisionPauseBudget;
|
|
844
|
+
// 0 is meaningful for the budget (relentless from the first) but NOT for the
|
|
845
|
+
// auto-select clock: 0 minutes would adopt a recommendation before anyone
|
|
846
|
+
// could read it, so a sub-1 or out-of-range value clears to "off".
|
|
847
|
+
if (settings.decisionAutoSelectMinutes !== undefined
|
|
848
|
+
&& (!Number.isInteger(settings.decisionAutoSelectMinutes)
|
|
849
|
+
|| settings.decisionAutoSelectMinutes < 1
|
|
850
|
+
|| settings.decisionAutoSelectMinutes > DECISION_AUTO_SELECT_MAX_MINUTES)) {
|
|
851
|
+
delete settings.decisionAutoSelectMinutes;
|
|
852
|
+
}
|
|
825
853
|
if (typeof settings.aggressiveMode !== "boolean") delete settings.aggressiveMode;
|
|
826
854
|
if (typeof settings.autoResume !== "boolean") delete settings.autoResume;
|
|
827
855
|
if (typeof settings.autoAcceptDrafts !== "boolean") delete settings.autoAcceptDrafts;
|
|
@@ -1122,6 +1150,7 @@ export const SETTINGS_KEYS: Array<keyof Settings> = [
|
|
|
1122
1150
|
"autoResume",
|
|
1123
1151
|
"decisionPopup",
|
|
1124
1152
|
"decisionPauseBudget",
|
|
1153
|
+
"decisionAutoSelectMinutes",
|
|
1125
1154
|
"carryover",
|
|
1126
1155
|
"autoAcceptDrafts",
|
|
1127
1156
|
"versionDisplay",
|
|
@@ -10,7 +10,7 @@ import { CARD_SECTION, LEGACY_CARD_SECTIONS, cardSectionName } from "./card-sect
|
|
|
10
10
|
* one finding group per work area, the real gate rows, the follow-ups and the
|
|
11
11
|
* one next step — instead of asking the agent to write a compact recap and
|
|
12
12
|
* then relying on the renderer to rescue its shape. */
|
|
13
|
-
export const HUMAN_HANDOFF_GUIDANCE = `HUMAN HANDOFF: Write for the person using the project, not for an audit log. Say what changed or what is preventing progress in one or two plain sentences. Name the user's next action separately, or say no action is needed. Do not put investigation history, file inventories, tool counts, model names, hashes or verifier mechanics into the human explanation. Keep evidence in verificationSummary/gateRows (completion) or interruption.evidence (pause). Preserve real limitations; never claim an unobserved result. COMPLETION REPORT: Outcome is the lede — one or two plain sentences on the result, because the card uses its first clause as the headline and the rest as the prose lede. Group the work by area with findingGroups (subsystem, screen, or phase), each finding written as \`<user-visible outcome> — <concrete evidence>\` with a repo-relative path:line where one exists. Add gateRows for the commands you actually ran, with their real counts in notes: the report always shows them, and status is derived from those notes, never claimed. Put limitations in Unresolved, deliberately deferred scope in leftOut, and one concrete follow-up in Next (extra actions belong in findingGroups or leftOut, not a second Next). Finding groups are detailed supporting material, not an excuse to repeat the whole report. For pause_goal keep reason to the unmet prerequisite and use suggestedAction for concrete steps, the relevant document or exact command; a resume command alone does not resolve a blocker. For waits explain the condition, not the scheduler, and do not promise completion at the next check.`;
|
|
13
|
+
export const HUMAN_HANDOFF_GUIDANCE = `HUMAN HANDOFF: Write for the person using the project, not for an audit log. Say what changed or what is preventing progress in one or two plain sentences. Name the user's next action separately, or say no action is needed. Do not put investigation history, file inventories, tool counts, model names, hashes or verifier mechanics into the human explanation. Keep evidence in verificationSummary/gateRows (completion) or interruption.evidence (pause). Preserve real limitations; never claim an unobserved result. COMPLETION REPORT: Summarize the whole objective, including work completed before audit rework, rather than only the last fix or test run. Lead with the concrete result and why it matters to the user. For example, write "Overlapping saves now keep the latest confirmed edit. You can switch panels without losing changes" rather than "Implemented persistence improvements". Explain significant behavior changes and decisions in ordinary language; file paths support the explanation rather than replace it. Scale detail to the work: a small fix needs a short paragraph and verification, while a broad objective needs a few meaningful work areas. Do not invent sections or follow-up work to fill the template. Outcome is the lede — one or two plain sentences on the result, because the card uses its first clause as the headline and the rest as the prose lede. Group the work by area with findingGroups (subsystem, screen, or phase), each finding written as \`<user-visible outcome> — <concrete evidence>\` with a repo-relative path:line where one exists. Add gateRows for the commands you actually ran, with their real counts in notes: the report always shows them, and status is derived from those notes, never claimed. Put limitations in Unresolved, deliberately deferred scope in leftOut, and one concrete follow-up in Next (extra actions belong in findingGroups or leftOut, not a second Next). Finding groups are detailed supporting material, not an excuse to repeat the whole report. For pause_goal keep reason to the unmet prerequisite and use suggestedAction for concrete steps, the relevant document or exact command; a resume command alone does not resolve a blocker. For waits explain the condition, not the scheduler, and do not promise completion at the next check.`;
|
|
14
14
|
|
|
15
15
|
/** A visibly abbreviated projection, never a semantic rewrite. Callers must
|
|
16
16
|
* offer expansion or a durable record whenever this omits source content. */
|
|
@@ -58,15 +58,17 @@ export function compactHumanSummary(content: string): { content: string; omitted
|
|
|
58
58
|
const sectionName = cardSectionName(heading);
|
|
59
59
|
if (sectionName) {
|
|
60
60
|
section = sectionName;
|
|
61
|
+
// Each work area gets its own allowance. A global counter let a busy
|
|
62
|
+
// first area erase every result from the rest of the objective.
|
|
63
|
+
if (section === CARD_SECTION.whatChanged) findings = 0;
|
|
61
64
|
result.push(line);
|
|
62
65
|
continue;
|
|
63
66
|
}
|
|
64
67
|
const isChangeArea = /^#{2,4}\s+What changed\s*\u00b7/i.test(line) || /^\*\*What changed\s*\u00b7/i.test(line);
|
|
65
68
|
if (section === CARD_SECTION.summary && line.trim()) {
|
|
66
69
|
if (/^#{2,4}\s|^\*\*.*\*\*$/.test(line) || ++summaryLines > 2) { omitted = true; continue; }
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
result.push(preview);
|
|
70
|
+
// Keep the opening explanation intact; wrapping belongs to the TUI.
|
|
71
|
+
result.push(line);
|
|
70
72
|
continue;
|
|
71
73
|
}
|
|
72
74
|
if (section === CARD_SECTION.whatChanged || section === LEGACY_CARD_SECTIONS[0]) {
|
|
@@ -190,6 +190,7 @@ import {
|
|
|
190
190
|
setContinuationRearmSince,
|
|
191
191
|
resetContinuationDispatchState,
|
|
192
192
|
resetContinuationInitialSend,
|
|
193
|
+
forgetDeliveredReworkContext,
|
|
193
194
|
noteUserMessageForDispatch,
|
|
194
195
|
sendTerminalCompletionNotice,
|
|
195
196
|
type ContinuationFlags,
|
|
@@ -591,6 +592,13 @@ let lengthExhaustionEpisodes = 0;
|
|
|
591
592
|
// fingerprint — first occurrence lands, identical repeats are silent, and
|
|
592
593
|
// any value change (or generation bump) re-arms.
|
|
593
594
|
let lastPayloadEvictionFingerprint = "";
|
|
595
|
+
// Field 2026-11-18: the same rule for error-turn hygiene. The `context` hook
|
|
596
|
+
// runs once per provider request, so a host retrying against a dead provider
|
|
597
|
+
// re-projected the identical failed turn every ~10-30s: 1,114 of 2,231 events
|
|
598
|
+
// in one active ledger were byte-identical `context_hygiene_dropped` lines.
|
|
599
|
+
// First occurrence lands; repeats are counted and ride the next change.
|
|
600
|
+
let lastContextHygieneFingerprint = "";
|
|
601
|
+
let suppressedContextHygieneRepeats = 0;
|
|
594
602
|
/** A manual resume starts a fresh relentless cycle: a user pause between
|
|
595
603
|
an episode-1 wedge and the next one must not make that wedge park one
|
|
596
604
|
cycle early. */
|
|
@@ -1676,6 +1684,9 @@ export function registerGoalRuntime(pi: ExtensionAPI, ownership: ProcessOwnerBou
|
|
|
1676
1684
|
if (!isSupervising()) return;
|
|
1677
1685
|
clearBoundaryCompactionAttempt(ctx);
|
|
1678
1686
|
appendLedger(ctx.cwd, "session_compact", {});
|
|
1687
|
+
// The compacted history may no longer hold the audit report or the TODO
|
|
1688
|
+
// list, so the next send re-teaches them in a full brief.
|
|
1689
|
+
forgetDeliveredReworkContext();
|
|
1679
1690
|
// v0.28.24: a compaction is LEGITIMATE busy time — reset the send-rearm
|
|
1680
1691
|
// storm streaks (π-web nearly escalated a "send-retry storm" pause during
|
|
1681
1692
|
// a 3.5-minute compact) and open the post-compaction stall grace.
|
|
@@ -4130,13 +4141,24 @@ async function handleHotLengthExhaustion(
|
|
|
4130
4141
|
if (projection.evicted.length === 0 && hygiene.dropped.length === 0 && checkpointProjection.removedPayloads === 0) return {};
|
|
4131
4142
|
try {
|
|
4132
4143
|
if (hygiene.dropped.length > 0) {
|
|
4133
|
-
|
|
4144
|
+
const hygieneValue = {
|
|
4134
4145
|
dropped: hygiene.dropped.length,
|
|
4135
4146
|
droppedDispatchPayloads: hygiene.dropped.filter(turn => turn.triggerMessageIndex !== undefined).length,
|
|
4136
4147
|
kept: hygiene.kept,
|
|
4137
4148
|
lastError: hygiene.dropped[hygiene.dropped.length - 1]?.errorMessage?.slice(0, 160),
|
|
4138
4149
|
generation: sessionGeneration,
|
|
4139
|
-
}
|
|
4150
|
+
};
|
|
4151
|
+
const hygieneFingerprint = `${ctx.cwd}\u0000${JSON.stringify(hygieneValue)}`;
|
|
4152
|
+
if (hygieneFingerprint !== lastContextHygieneFingerprint) {
|
|
4153
|
+
lastContextHygieneFingerprint = hygieneFingerprint;
|
|
4154
|
+
appendLedger(ctx.cwd, "context_hygiene_dropped", {
|
|
4155
|
+
...hygieneValue,
|
|
4156
|
+
...(suppressedContextHygieneRepeats > 0 ? { suppressedRepeats: suppressedContextHygieneRepeats } : {}),
|
|
4157
|
+
});
|
|
4158
|
+
suppressedContextHygieneRepeats = 0;
|
|
4159
|
+
} else {
|
|
4160
|
+
suppressedContextHygieneRepeats++;
|
|
4161
|
+
}
|
|
4140
4162
|
}
|
|
4141
4163
|
if (projection.evicted.length > 0) {
|
|
4142
4164
|
const evictionFingerprint = `${sessionGeneration}:${projection.evicted.length}:${projection.totalImageBytes - projection.remainingImageBytes}:${projection.remainingImageBytes}:${projection.remainingImageCount}`;
|