@jwitmann/vcc-brain-opencode-v2 2.8.1 → 2.9.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/index.js +431 -166
- package/dist/index.js.map +22 -18
- package/dist/server.js +431 -166
- package/dist/server.js.map +22 -18
- package/dist/tui.js +2 -2
- package/dist/tui.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6995,6 +6995,9 @@ function getErrorMessage(error) {
|
|
|
6995
6995
|
function isRecord(value) {
|
|
6996
6996
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6997
6997
|
}
|
|
6998
|
+
function isStringArray(value) {
|
|
6999
|
+
return Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
7000
|
+
}
|
|
6998
7001
|
function readString(value, key) {
|
|
6999
7002
|
const field = value[key];
|
|
7000
7003
|
return typeof field === "string" ? field : null;
|
|
@@ -7406,7 +7409,7 @@ import { Plugin } from "@opencode/plugin";
|
|
|
7406
7409
|
// package.json
|
|
7407
7410
|
var package_default = {
|
|
7408
7411
|
name: "@jwitmann/vcc-brain-opencode-v2",
|
|
7409
|
-
version: "2.
|
|
7412
|
+
version: "2.9.1",
|
|
7410
7413
|
description: "VCC Brain adapter for OpenCode V2.",
|
|
7411
7414
|
license: "BSD-3-Clause",
|
|
7412
7415
|
author: "jwitmann",
|
|
@@ -217179,7 +217182,7 @@ async function collectIndexFiles(directory, paths) {
|
|
|
217179
217182
|
}
|
|
217180
217183
|
|
|
217181
217184
|
// src/brain-updates.ts
|
|
217182
|
-
import { join as
|
|
217185
|
+
import { join as join9 } from "node:path";
|
|
217183
217186
|
|
|
217184
217187
|
// ../core/src/context/triggers.ts
|
|
217185
217188
|
var EMPTY_TRIGGER_STATE = { fired: {} };
|
|
@@ -217232,8 +217235,88 @@ function recordFired(state, kind, estimatedTokens) {
|
|
|
217232
217235
|
return { fired: { ...state.fired, [kind]: estimatedTokens } };
|
|
217233
217236
|
}
|
|
217234
217237
|
|
|
217235
|
-
// src/
|
|
217238
|
+
// ../core/src/context/session-slot.ts
|
|
217239
|
+
import { mkdir as mkdir3, readFile as readFile4, rename, rm, writeFile as writeFile2 } from "node:fs/promises";
|
|
217236
217240
|
import { join as join7 } from "node:path";
|
|
217241
|
+
function slotPath(stateDirectory, slot, sessionID) {
|
|
217242
|
+
return join7(stateDirectory, slot, `${sessionID}.json`);
|
|
217243
|
+
}
|
|
217244
|
+
async function slotSet(stateDirectory, slot, sessionID, value) {
|
|
217245
|
+
if (!isSafePathSegment(sessionID)) {
|
|
217246
|
+
return failure({ kind: "unsafe-session-id", sessionID });
|
|
217247
|
+
}
|
|
217248
|
+
try {
|
|
217249
|
+
await mkdir3(join7(stateDirectory, slot), { recursive: true });
|
|
217250
|
+
const target = slotPath(stateDirectory, slot, sessionID);
|
|
217251
|
+
const staging = `${target}.${process.pid}.tmp`;
|
|
217252
|
+
await writeFile2(staging, JSON.stringify(value), "utf8");
|
|
217253
|
+
await rename(staging, target);
|
|
217254
|
+
return success(null);
|
|
217255
|
+
} catch (error) {
|
|
217256
|
+
return failure({ kind: "write-failed", reason: getErrorMessage(error) });
|
|
217257
|
+
}
|
|
217258
|
+
}
|
|
217259
|
+
async function slotGet(stateDirectory, slot, sessionID, guard) {
|
|
217260
|
+
if (!isSafePathSegment(sessionID)) {
|
|
217261
|
+
return failure({ kind: "unsafe-session-id", sessionID });
|
|
217262
|
+
}
|
|
217263
|
+
let raw;
|
|
217264
|
+
try {
|
|
217265
|
+
raw = await readFile4(slotPath(stateDirectory, slot, sessionID), "utf8");
|
|
217266
|
+
} catch {
|
|
217267
|
+
return success(null);
|
|
217268
|
+
}
|
|
217269
|
+
let parsed;
|
|
217270
|
+
try {
|
|
217271
|
+
parsed = JSON.parse(raw);
|
|
217272
|
+
} catch {
|
|
217273
|
+
return success(null);
|
|
217274
|
+
}
|
|
217275
|
+
if (!guard(parsed)) {
|
|
217276
|
+
return success(null);
|
|
217277
|
+
}
|
|
217278
|
+
return success(parsed);
|
|
217279
|
+
}
|
|
217280
|
+
async function slotClear(stateDirectory, slot, sessionID) {
|
|
217281
|
+
if (!isSafePathSegment(sessionID)) {
|
|
217282
|
+
return failure({ kind: "unsafe-session-id", sessionID });
|
|
217283
|
+
}
|
|
217284
|
+
try {
|
|
217285
|
+
await rm(slotPath(stateDirectory, slot, sessionID), { force: true });
|
|
217286
|
+
return success(null);
|
|
217287
|
+
} catch (error) {
|
|
217288
|
+
return failure({ kind: "clear-failed", reason: getErrorMessage(error) });
|
|
217289
|
+
}
|
|
217290
|
+
}
|
|
217291
|
+
|
|
217292
|
+
// ../core/src/context/failure-backoff.ts
|
|
217293
|
+
var FAILURE_BACKOFF_VERSION = 1;
|
|
217294
|
+
var FAILURE_BACKOFF_SLOT = "context-failure-backoff";
|
|
217295
|
+
function isFailureBackoffRecord(value) {
|
|
217296
|
+
if (!isRecord(value)) {
|
|
217297
|
+
return false;
|
|
217298
|
+
}
|
|
217299
|
+
return value.version === FAILURE_BACKOFF_VERSION && typeof value.session_id === "string" && typeof value.at === "number" && typeof value.estimate === "number";
|
|
217300
|
+
}
|
|
217301
|
+
async function failureBackoffSet(stateDirectory, record) {
|
|
217302
|
+
return slotSet(stateDirectory, FAILURE_BACKOFF_SLOT, record.session_id, record);
|
|
217303
|
+
}
|
|
217304
|
+
async function failureBackoffGet(stateDirectory, sessionID) {
|
|
217305
|
+
const stored = await slotGet(stateDirectory, FAILURE_BACKOFF_SLOT, sessionID, isFailureBackoffRecord);
|
|
217306
|
+
if (!stored.ok) {
|
|
217307
|
+
return stored;
|
|
217308
|
+
}
|
|
217309
|
+
if (stored.value !== null && stored.value.session_id !== sessionID) {
|
|
217310
|
+
return success(null);
|
|
217311
|
+
}
|
|
217312
|
+
return stored;
|
|
217313
|
+
}
|
|
217314
|
+
async function failureBackoffClear(stateDirectory, sessionID) {
|
|
217315
|
+
return slotClear(stateDirectory, FAILURE_BACKOFF_SLOT, sessionID);
|
|
217316
|
+
}
|
|
217317
|
+
|
|
217318
|
+
// src/runtime.ts
|
|
217319
|
+
import { join as join8 } from "node:path";
|
|
217237
217320
|
var PENDING_CAUSE_TTL_MS = 10 * 60 * 1000;
|
|
217238
217321
|
var FAILED_COMPACTION_COOLDOWN_MS = 10 * 60 * 1000;
|
|
217239
217322
|
function shouldSuppressCompactionRequest(session, estimatedTokens, windowTokens, now) {
|
|
@@ -217255,7 +217338,8 @@ function createContextRuntime() {
|
|
|
217255
217338
|
refusals: new Set,
|
|
217256
217339
|
reportedReceiptFailures: new Set,
|
|
217257
217340
|
hydrated: new Set,
|
|
217258
|
-
pendingCauses: new Map
|
|
217341
|
+
pendingCauses: new Map,
|
|
217342
|
+
pendingAnchors: new Map
|
|
217259
217343
|
};
|
|
217260
217344
|
}
|
|
217261
217345
|
var SHARED_RUNTIME_KEY = "__vccBrainContextRuntime";
|
|
@@ -217335,7 +217419,7 @@ async function ensureSessionHydrated(stateDirectory, runtime, sessionID) {
|
|
|
217335
217419
|
if (runtime.hydrated.has(sessionID)) {
|
|
217336
217420
|
return;
|
|
217337
217421
|
}
|
|
217338
|
-
const receipts = await readReceipts(
|
|
217422
|
+
const receipts = await readReceipts(join8(stateDirectory, "context-log"), sessionID);
|
|
217339
217423
|
if (!receipts.ok) {
|
|
217340
217424
|
return;
|
|
217341
217425
|
}
|
|
@@ -217351,6 +217435,12 @@ async function ensureSessionHydrated(stateDirectory, runtime, sessionID) {
|
|
|
217351
217435
|
}
|
|
217352
217436
|
}
|
|
217353
217437
|
session.triggerState = { fired: { ...fired, ...session.triggerState.fired } };
|
|
217438
|
+
if (session.lastCompactionFailure === null) {
|
|
217439
|
+
const backoff = await failureBackoffGet(stateDirectory, sessionID);
|
|
217440
|
+
if (backoff.ok && backoff.value !== null) {
|
|
217441
|
+
session.lastCompactionFailure = { at: backoff.value.at, estimate: backoff.value.estimate };
|
|
217442
|
+
}
|
|
217443
|
+
}
|
|
217354
217444
|
runtime.hydrated.add(sessionID);
|
|
217355
217445
|
}
|
|
217356
217446
|
async function ensureRefusalReceipt(stateDirectory, runtime, sessionID, deps) {
|
|
@@ -217358,7 +217448,7 @@ async function ensureRefusalReceipt(stateDirectory, runtime, sessionID, deps) {
|
|
|
217358
217448
|
return;
|
|
217359
217449
|
}
|
|
217360
217450
|
runtime.refusals.add(sessionID);
|
|
217361
|
-
const written = await appendReceipt(
|
|
217451
|
+
const written = await appendReceipt(join8(stateDirectory, "context-log"), sessionID, {
|
|
217362
217452
|
kind: "refusal",
|
|
217363
217453
|
at: new Date().toISOString(),
|
|
217364
217454
|
reason: "brain-unavailable"
|
|
@@ -217403,7 +217493,7 @@ async function maybeAppendBrainUpdateReminder(deps, runtime, sessionID, messages
|
|
|
217403
217493
|
threshold: deps.config.toolCallThreshold,
|
|
217404
217494
|
completedSinceBaseline: decision.completedSinceBaseline
|
|
217405
217495
|
};
|
|
217406
|
-
await appendReceipt(
|
|
217496
|
+
await appendReceipt(join9(deps.stateDirectory, "context-log"), sessionID, receipt);
|
|
217407
217497
|
return `${content}
|
|
217408
217498
|
|
|
217409
217499
|
${brainUpdateReminder(deps.config.toolCallThreshold)}`;
|
|
@@ -217576,13 +217666,18 @@ Use Helper output as working context. Do not reproduce it wholesale or reimpleme
|
|
|
217576
217666
|
}
|
|
217577
217667
|
|
|
217578
217668
|
// ../core/src/context/compaction.ts
|
|
217579
|
-
var DEFAULT_RECOVERY_RULE = `Tool
|
|
217669
|
+
var DEFAULT_RECOVERY_RULE = `Tool output omission notices (content IDs) are the only recoverable
|
|
217580
217670
|
` + ` handles for trimmed content. Keep every omission notice verbatim in the
|
|
217581
217671
|
` + ` summary; the agent recovers payloads through the vcc-brain-read_omitted
|
|
217582
217672
|
` + " tool.";
|
|
217583
217673
|
function buildCompactionPrompt(input) {
|
|
217584
217674
|
const paths = input.brainPaths.map((path) => `- ${path}`).join(`
|
|
217585
217675
|
`);
|
|
217676
|
+
const anchorRule = input.anchorView === null ? "" : `- The session carries a verbatim task-anchor block below. Reproduce
|
|
217677
|
+
it byte-identical at the top of the summary, before any other text.
|
|
217678
|
+
It is machine-written orientation state, not prose to compress:
|
|
217679
|
+
${input.anchorView}
|
|
217680
|
+
`;
|
|
217586
217681
|
return `<compaction-instructions>
|
|
217587
217682
|
You are compacting the conversation history for a VCC Brain session.
|
|
217588
217683
|
Produce a summary that lets the next session continue the work without the
|
|
@@ -217597,7 +217692,7 @@ The summary must preserve, in order of importance:
|
|
|
217597
217692
|
|
|
217598
217693
|
Rules:
|
|
217599
217694
|
- ${input.recoveryRule ?? DEFAULT_RECOVERY_RULE}
|
|
217600
|
-
- Durable knowledge lives in the Brain partitions. Reference these paths
|
|
217695
|
+
${anchorRule}- Durable knowledge lives in the Brain partitions. Reference these paths
|
|
217601
217696
|
instead of inlining their content:
|
|
217602
217697
|
${paths}
|
|
217603
217698
|
- Before summarizing, ensure any spec or decision that exists only in this
|
|
@@ -217607,7 +217702,7 @@ ${paths}
|
|
|
217607
217702
|
}
|
|
217608
217703
|
|
|
217609
217704
|
// src/compaction.ts
|
|
217610
|
-
import { join as
|
|
217705
|
+
import { join as join11 } from "node:path";
|
|
217611
217706
|
|
|
217612
217707
|
// ../core/src/context/compiler.ts
|
|
217613
217708
|
var TOKEN_RE = /[a-zA-Z]+|[0-9]+|[^\sa-zA-Z0-9]|\s+/g;
|
|
@@ -218606,8 +218701,8 @@ function compileCompaction(messages, config, keepMessages, requestTokens) {
|
|
|
218606
218701
|
}
|
|
218607
218702
|
|
|
218608
218703
|
// src/compaction-snapshot.ts
|
|
218609
|
-
import { mkdir as
|
|
218610
|
-
import { join as
|
|
218704
|
+
import { mkdir as mkdir4, readFile as readFile5, rename as rename2, writeFile as writeFile3 } from "node:fs/promises";
|
|
218705
|
+
import { join as join10 } from "node:path";
|
|
218611
218706
|
|
|
218612
218707
|
// ../core/src/context/session-compat.ts
|
|
218613
218708
|
var warnSink = null;
|
|
@@ -219142,7 +219237,7 @@ async function rememberSnapshot(root, sessionID, messages, at, prev) {
|
|
|
219142
219237
|
}
|
|
219143
219238
|
}
|
|
219144
219239
|
function snapshotPath(root, sessionID) {
|
|
219145
|
-
return
|
|
219240
|
+
return join10(root, `${sessionID}.json`);
|
|
219146
219241
|
}
|
|
219147
219242
|
async function writeCompactionSnapshot(root, sessionID, messages, at) {
|
|
219148
219243
|
const path = snapshotPath(root, sessionID);
|
|
@@ -219151,11 +219246,11 @@ async function writeCompactionSnapshot(root, sessionID, messages, at) {
|
|
|
219151
219246
|
}
|
|
219152
219247
|
const envelope = { ...buildSnapshot(messages), writtenAt: at };
|
|
219153
219248
|
try {
|
|
219154
|
-
await
|
|
219249
|
+
await mkdir4(root, { recursive: true });
|
|
219155
219250
|
const tmp = `${path}.tmp`;
|
|
219156
|
-
await
|
|
219251
|
+
await writeFile3(tmp, `${JSON.stringify(envelope)}
|
|
219157
219252
|
`, "utf8");
|
|
219158
|
-
await
|
|
219253
|
+
await rename2(tmp, path);
|
|
219159
219254
|
} catch (cause) {
|
|
219160
219255
|
return failure({ path, cause });
|
|
219161
219256
|
}
|
|
@@ -219168,7 +219263,7 @@ async function readCompactionSnapshot(root, sessionID) {
|
|
|
219168
219263
|
}
|
|
219169
219264
|
let raw;
|
|
219170
219265
|
try {
|
|
219171
|
-
raw = await
|
|
219266
|
+
raw = await readFile5(path, "utf8");
|
|
219172
219267
|
} catch (cause) {
|
|
219173
219268
|
if (isRecord(cause) && cause.code === "ENOENT")
|
|
219174
219269
|
return success(null);
|
|
@@ -219385,6 +219480,125 @@ function classifySnapshotStore(read) {
|
|
|
219385
219480
|
return { status: "ready", messages };
|
|
219386
219481
|
}
|
|
219387
219482
|
|
|
219483
|
+
// ../core/src/context/anchor.ts
|
|
219484
|
+
var ANCHOR_VERSION = 1;
|
|
219485
|
+
var ANCHOR_SLOT = "context-anchor";
|
|
219486
|
+
function isAnchorRecord(value) {
|
|
219487
|
+
if (!isRecord(value)) {
|
|
219488
|
+
return false;
|
|
219489
|
+
}
|
|
219490
|
+
const checklist = value.checklist;
|
|
219491
|
+
const workingTree = value.working_tree;
|
|
219492
|
+
const midThrough = value.mid_through;
|
|
219493
|
+
if (!isRecord(checklist)) {
|
|
219494
|
+
return false;
|
|
219495
|
+
}
|
|
219496
|
+
const done = checklist.done;
|
|
219497
|
+
const next = checklist.next;
|
|
219498
|
+
const current = checklist.current;
|
|
219499
|
+
return value.version === ANCHOR_VERSION && typeof value.session_id === "string" && typeof value.task_id === "string" && typeof value.written_at === "string" && isStringArray(value.plan_paths) && isStringArray(done) && isStringArray(next) && (current === null || typeof current === "string") && (workingTree === null || isStringArray(workingTree)) && (midThrough === null || typeof midThrough === "string");
|
|
219500
|
+
}
|
|
219501
|
+
async function anchorSet(stateDirectory, record) {
|
|
219502
|
+
return slotSet(stateDirectory, ANCHOR_SLOT, record.session_id, record);
|
|
219503
|
+
}
|
|
219504
|
+
async function anchorGet(stateDirectory, sessionID) {
|
|
219505
|
+
const stored = await slotGet(stateDirectory, ANCHOR_SLOT, sessionID, isAnchorRecord);
|
|
219506
|
+
if (!stored.ok) {
|
|
219507
|
+
return stored;
|
|
219508
|
+
}
|
|
219509
|
+
if (stored.value !== null && stored.value.session_id !== sessionID) {
|
|
219510
|
+
return success(null);
|
|
219511
|
+
}
|
|
219512
|
+
return stored;
|
|
219513
|
+
}
|
|
219514
|
+
async function anchorClear(stateDirectory, sessionID) {
|
|
219515
|
+
return slotClear(stateDirectory, ANCHOR_SLOT, sessionID);
|
|
219516
|
+
}
|
|
219517
|
+
function sanitizeAnchorLine(value) {
|
|
219518
|
+
return value.replace(/[\r\n]+/g, " ");
|
|
219519
|
+
}
|
|
219520
|
+
function renderAnchorView(record) {
|
|
219521
|
+
const lines = [
|
|
219522
|
+
"<task-anchor>",
|
|
219523
|
+
`task: ${sanitizeAnchorLine(record.task_id)}`,
|
|
219524
|
+
`written: ${sanitizeAnchorLine(record.written_at)}`
|
|
219525
|
+
];
|
|
219526
|
+
for (const plan of record.plan_paths) {
|
|
219527
|
+
lines.push(`plan: ${sanitizeAnchorLine(plan)}`);
|
|
219528
|
+
}
|
|
219529
|
+
for (const done of record.checklist.done) {
|
|
219530
|
+
lines.push(`done: ${sanitizeAnchorLine(done)}`);
|
|
219531
|
+
}
|
|
219532
|
+
if (record.checklist.current !== null) {
|
|
219533
|
+
lines.push(`current: ${sanitizeAnchorLine(record.checklist.current)}`);
|
|
219534
|
+
}
|
|
219535
|
+
for (const next of record.checklist.next) {
|
|
219536
|
+
lines.push(`next: ${sanitizeAnchorLine(next)}`);
|
|
219537
|
+
}
|
|
219538
|
+
if (record.working_tree !== null) {
|
|
219539
|
+
for (const entry of record.working_tree) {
|
|
219540
|
+
lines.push(`tree: ${sanitizeAnchorLine(entry)}`);
|
|
219541
|
+
}
|
|
219542
|
+
}
|
|
219543
|
+
if (record.mid_through !== null) {
|
|
219544
|
+
lines.push(`mid-through: ${sanitizeAnchorLine(record.mid_through)}`);
|
|
219545
|
+
}
|
|
219546
|
+
lines.push("</task-anchor>");
|
|
219547
|
+
return lines.join(`
|
|
219548
|
+
`);
|
|
219549
|
+
}
|
|
219550
|
+
function renderAnchorResumeSection(record) {
|
|
219551
|
+
const lines = [
|
|
219552
|
+
"",
|
|
219553
|
+
"## Task Anchor",
|
|
219554
|
+
"",
|
|
219555
|
+
"A compaction cut through live task state. Re-read these plan files before acting:"
|
|
219556
|
+
];
|
|
219557
|
+
for (const plan of record.plan_paths) {
|
|
219558
|
+
lines.push(`- ${sanitizeAnchorLine(plan)}`);
|
|
219559
|
+
}
|
|
219560
|
+
if (record.checklist.current !== null) {
|
|
219561
|
+
lines.push(`Current: ${sanitizeAnchorLine(record.checklist.current)}.`);
|
|
219562
|
+
}
|
|
219563
|
+
return lines.join(`
|
|
219564
|
+
`);
|
|
219565
|
+
}
|
|
219566
|
+
|
|
219567
|
+
// src/anchor.ts
|
|
219568
|
+
function stageAnchor(runtime, sessionID, fields) {
|
|
219569
|
+
runtime.pendingAnchors.set(sessionID, fields);
|
|
219570
|
+
}
|
|
219571
|
+
async function consumeStagedAnchor(stateDirectory, runtime, sessionID, deps, now) {
|
|
219572
|
+
const staged = runtime.pendingAnchors.get(sessionID);
|
|
219573
|
+
if (staged === undefined) {
|
|
219574
|
+
return null;
|
|
219575
|
+
}
|
|
219576
|
+
const record = {
|
|
219577
|
+
version: ANCHOR_VERSION,
|
|
219578
|
+
session_id: sessionID,
|
|
219579
|
+
task_id: staged.task_id,
|
|
219580
|
+
written_at: now,
|
|
219581
|
+
plan_paths: staged.plan_paths,
|
|
219582
|
+
checklist: staged.checklist,
|
|
219583
|
+
working_tree: staged.working_tree,
|
|
219584
|
+
mid_through: staged.mid_through
|
|
219585
|
+
};
|
|
219586
|
+
const written = await anchorSet(stateDirectory, record);
|
|
219587
|
+
if (!written.ok) {
|
|
219588
|
+
reportReceiptFailureOnce(runtime, deps, sessionID, "compact");
|
|
219589
|
+
return null;
|
|
219590
|
+
}
|
|
219591
|
+
runtime.pendingAnchors.delete(sessionID);
|
|
219592
|
+
return renderAnchorView(record);
|
|
219593
|
+
}
|
|
219594
|
+
async function loadSessionAnchor(stateDirectory, sessionID) {
|
|
219595
|
+
const read = await anchorGet(stateDirectory, sessionID);
|
|
219596
|
+
if (!read.ok) {
|
|
219597
|
+
return null;
|
|
219598
|
+
}
|
|
219599
|
+
return read.value;
|
|
219600
|
+
}
|
|
219601
|
+
|
|
219388
219602
|
// src/compaction.ts
|
|
219389
219603
|
function registerCompactionHook(context, deps, runtime) {
|
|
219390
219604
|
context.session.hook("compaction", async (event) => {
|
|
@@ -219402,6 +219616,10 @@ function registerCompactionHook(context, deps, runtime) {
|
|
|
219402
219616
|
}
|
|
219403
219617
|
const session = sessionRuntime(runtime, sessionID);
|
|
219404
219618
|
session.lastCompactionFailure = null;
|
|
219619
|
+
const backoffCleared = await failureBackoffClear(deps.stateDirectory, sessionID);
|
|
219620
|
+
if (!backoffCleared.ok) {
|
|
219621
|
+
reportReceiptFailureOnce(runtime, deps, sessionID, "compact");
|
|
219622
|
+
}
|
|
219405
219623
|
if (deps.refreshEnabled) {
|
|
219406
219624
|
session.preambleRefreshPending = true;
|
|
219407
219625
|
}
|
|
@@ -219409,6 +219627,13 @@ function registerCompactionHook(context, deps, runtime) {
|
|
|
219409
219627
|
const pending = runtime.pendingCauses.get(sessionID);
|
|
219410
219628
|
const cause = pending !== undefined && Date.now() - pending.at <= PENDING_CAUSE_TTL_MS ? pending.cause : "manual";
|
|
219411
219629
|
runtime.pendingCauses.delete(sessionID);
|
|
219630
|
+
const anchorView = await consumeStagedAnchor(deps.stateDirectory, runtime, sessionID, deps, new Date().toISOString());
|
|
219631
|
+
if (isContextStale(deps)) {
|
|
219632
|
+
return;
|
|
219633
|
+
}
|
|
219634
|
+
if (anchorView !== null && deps.onAnchorWritten !== null) {
|
|
219635
|
+
deps.onAnchorWritten(sessionID);
|
|
219636
|
+
}
|
|
219412
219637
|
const vcc = compileCompaction(event.messages, resolveVccCompilerConfig(), DEFAULT_VCC_KEEP_MESSAGES, Math.max(0, estimatedTokens));
|
|
219413
219638
|
const receipt = vcc === undefined ? {
|
|
219414
219639
|
kind: "compact",
|
|
@@ -219430,17 +219655,21 @@ function registerCompactionHook(context, deps, runtime) {
|
|
|
219430
219655
|
} else {
|
|
219431
219656
|
event.system.push({
|
|
219432
219657
|
type: "text",
|
|
219433
|
-
text: buildCompactionPrompt({
|
|
219658
|
+
text: buildCompactionPrompt({
|
|
219659
|
+
brainPaths: deps.brainPaths,
|
|
219660
|
+
recoveryRule: null,
|
|
219661
|
+
anchorView
|
|
219662
|
+
})
|
|
219434
219663
|
});
|
|
219435
219664
|
}
|
|
219436
|
-
const written = await appendReceipt(
|
|
219665
|
+
const written = await appendReceipt(join11(deps.stateDirectory, "context-log"), sessionID, receipt);
|
|
219437
219666
|
if (!written.ok) {
|
|
219438
219667
|
reportReceiptFailureOnce(runtime, deps, sessionID, "compact");
|
|
219439
219668
|
}
|
|
219440
219669
|
if (isContextStale(deps)) {
|
|
219441
219670
|
return;
|
|
219442
219671
|
}
|
|
219443
|
-
const remembered = await rememberSnapshot(
|
|
219672
|
+
const remembered = await rememberSnapshot(join11(deps.stateDirectory, "context-snapshot"), sessionID, event.messages, new Date().toISOString(), session.snapshotSeen);
|
|
219444
219673
|
if (isContextStale(deps)) {
|
|
219445
219674
|
return;
|
|
219446
219675
|
}
|
|
@@ -219457,21 +219686,11 @@ Output Length: ${length} characters
|
|
|
219457
219686
|
Content ID: ${contentID}
|
|
219458
219687
|
</tool-output-omission-notice>`;
|
|
219459
219688
|
}
|
|
219460
|
-
function inputOmissionNotice(description, length, contentID) {
|
|
219461
|
-
return `<tool-input-omission-notice>
|
|
219462
|
-
${description}
|
|
219463
|
-
|
|
219464
|
-
Omitted Length: ${length} characters
|
|
219465
|
-
Content ID: ${contentID}
|
|
219466
|
-
</tool-input-omission-notice>`;
|
|
219467
|
-
}
|
|
219468
219689
|
|
|
219469
219690
|
// ../core/src/context/trim.ts
|
|
219470
219691
|
var DEFAULT_OUTPUT_DESCRIPTION = "Output omitted due to a compaction operation.";
|
|
219471
219692
|
var DEFAULT_LIMIT = { words: 128, chars: 1024 };
|
|
219472
219693
|
var TASK_OUTPUT_LIMIT = { words: 512, chars: 4096 };
|
|
219473
|
-
var BASH_COMMAND_CHAR_LIMIT = 1024;
|
|
219474
|
-
var BASH_HEAD_CHAR_LIMIT = 512;
|
|
219475
219694
|
function planTrimBatched(messages, options) {
|
|
219476
219695
|
const turns = computeTurns(messages);
|
|
219477
219696
|
removeTrailingAssistantlessTurn(turns);
|
|
@@ -219492,22 +219711,14 @@ function planTrimBatched(messages, options) {
|
|
|
219492
219711
|
if (call.resultMessageIndex === null || call.resultIsError) {
|
|
219493
219712
|
continue;
|
|
219494
219713
|
}
|
|
219495
|
-
const input = planInputOmission(call);
|
|
219496
219714
|
const output = planOutputOmission(call);
|
|
219497
|
-
if (
|
|
219498
|
-
omissions.push({ call,
|
|
219715
|
+
if (output !== null) {
|
|
219716
|
+
omissions.push({ call, output });
|
|
219499
219717
|
}
|
|
219500
219718
|
}
|
|
219501
219719
|
const requests = [];
|
|
219502
219720
|
for (const omission of omissions) {
|
|
219503
|
-
if (omission.
|
|
219504
|
-
requests.push({
|
|
219505
|
-
key: omission.input.key,
|
|
219506
|
-
content: omission.input.content,
|
|
219507
|
-
tokens: omission.input.tokens
|
|
219508
|
-
});
|
|
219509
|
-
}
|
|
219510
|
-
if (omission.output !== null && omission.output.kind === "stored") {
|
|
219721
|
+
if (omission.output.kind === "stored") {
|
|
219511
219722
|
requests.push({
|
|
219512
219723
|
key: omission.output.key,
|
|
219513
219724
|
content: omission.output.content,
|
|
@@ -219592,43 +219803,23 @@ function contentAt(messages, location) {
|
|
|
219592
219803
|
}
|
|
219593
219804
|
function buildTrimPlan(messages, omissions, ids) {
|
|
219594
219805
|
const replacements = [];
|
|
219595
|
-
for (const { call,
|
|
219596
|
-
let inputNotice = null;
|
|
219597
|
-
if (input !== null) {
|
|
219598
|
-
const contentID = ids.get(input.key) ?? null;
|
|
219599
|
-
if (contentID !== null) {
|
|
219600
|
-
replacements.push({
|
|
219601
|
-
messageIndex: call.messageIndex,
|
|
219602
|
-
partIndex: call.partIndex,
|
|
219603
|
-
part: input.part(contentID)
|
|
219604
|
-
});
|
|
219605
|
-
inputNotice = input.outputNotice(contentID);
|
|
219606
|
-
}
|
|
219607
|
-
}
|
|
219806
|
+
for (const { call, output } of omissions) {
|
|
219608
219807
|
if (call.resultMessageIndex === null || call.resultPartIndex === null) {
|
|
219609
219808
|
continue;
|
|
219610
219809
|
}
|
|
219611
219810
|
const originalOutput = stringifyToolContent(call.resultValue);
|
|
219612
219811
|
let nextOutput = originalOutput;
|
|
219613
219812
|
let replaced = false;
|
|
219614
|
-
if (output
|
|
219615
|
-
|
|
219616
|
-
|
|
219813
|
+
if (output.kind === "direct") {
|
|
219814
|
+
nextOutput = output.text;
|
|
219815
|
+
replaced = true;
|
|
219816
|
+
} else {
|
|
219817
|
+
const contentID = ids.get(output.key) ?? null;
|
|
219818
|
+
if (contentID !== null) {
|
|
219819
|
+
nextOutput = output.text(contentID);
|
|
219617
219820
|
replaced = true;
|
|
219618
|
-
} else {
|
|
219619
|
-
const contentID = ids.get(output.key) ?? null;
|
|
219620
|
-
if (contentID !== null) {
|
|
219621
|
-
nextOutput = output.text(contentID);
|
|
219622
|
-
replaced = true;
|
|
219623
|
-
}
|
|
219624
219821
|
}
|
|
219625
219822
|
}
|
|
219626
|
-
if (inputNotice !== null) {
|
|
219627
|
-
nextOutput = `${inputNotice}
|
|
219628
|
-
|
|
219629
|
-
${nextOutput}`;
|
|
219630
|
-
replaced = true;
|
|
219631
|
-
}
|
|
219632
219823
|
if (replaced) {
|
|
219633
219824
|
replacements.push({
|
|
219634
219825
|
messageIndex: call.resultMessageIndex,
|
|
@@ -219645,72 +219836,6 @@ ${nextOutput}`;
|
|
|
219645
219836
|
}
|
|
219646
219837
|
return { replacements };
|
|
219647
219838
|
}
|
|
219648
|
-
function planInputOmission(call) {
|
|
219649
|
-
if (!isRecord(call.input)) {
|
|
219650
|
-
return null;
|
|
219651
|
-
}
|
|
219652
|
-
const input = call.input;
|
|
219653
|
-
const originalPart = { type: "tool-call", id: call.callID, name: call.toolName, input };
|
|
219654
|
-
if (call.toolName === "write") {
|
|
219655
|
-
const content = readString(input, "content");
|
|
219656
|
-
if (content !== null && exceeds(content, DEFAULT_LIMIT)) {
|
|
219657
|
-
return {
|
|
219658
|
-
key: `${call.callID}:input`,
|
|
219659
|
-
content,
|
|
219660
|
-
tokens: countTextTokens(content),
|
|
219661
|
-
part: () => ({ ...originalPart, input: { ...input, content: "[Omitted]" } }),
|
|
219662
|
-
outputNotice: (contentID) => inputOmissionNotice("File write contents omitted due to a compaction operation. If necessary, reread file to see current contents.", content.length, contentID)
|
|
219663
|
-
};
|
|
219664
|
-
}
|
|
219665
|
-
}
|
|
219666
|
-
if (call.toolName === "apply_patch") {
|
|
219667
|
-
const content = readString(input, "patchText");
|
|
219668
|
-
if (content !== null && exceeds(content, DEFAULT_LIMIT)) {
|
|
219669
|
-
return {
|
|
219670
|
-
key: `${call.callID}:input`,
|
|
219671
|
-
content,
|
|
219672
|
-
tokens: countTextTokens(content),
|
|
219673
|
-
part: () => ({ ...originalPart, input: { ...input, patchText: "[Omitted]" } }),
|
|
219674
|
-
outputNotice: (contentID) => inputOmissionNotice("Patch text omitted due to compaction operation. If necessary, reread files to see current contents.", content.length, contentID)
|
|
219675
|
-
};
|
|
219676
|
-
}
|
|
219677
|
-
}
|
|
219678
|
-
if (call.toolName === "bash") {
|
|
219679
|
-
const content = readString(input, "command");
|
|
219680
|
-
if (content !== null && content.length > BASH_COMMAND_CHAR_LIMIT) {
|
|
219681
|
-
const truncated = `${content.slice(0, BASH_HEAD_CHAR_LIMIT)}
|
|
219682
|
-
[REST OF COMMAND TRUNCATED]`;
|
|
219683
|
-
return {
|
|
219684
|
-
key: `${call.callID}:input`,
|
|
219685
|
-
content,
|
|
219686
|
-
tokens: countTextTokens(content),
|
|
219687
|
-
part: () => ({ ...originalPart, input: { ...input, command: truncated } }),
|
|
219688
|
-
outputNotice: (contentID) => inputOmissionNotice("Bash command truncated due to compaction operation.", content.length, contentID)
|
|
219689
|
-
};
|
|
219690
|
-
}
|
|
219691
|
-
}
|
|
219692
|
-
if (call.toolName === "edit") {
|
|
219693
|
-
const oldString = readString(input, "oldString");
|
|
219694
|
-
const newString = readString(input, "newString");
|
|
219695
|
-
if (oldString !== null && newString !== null) {
|
|
219696
|
-
const combined = `${oldString}
|
|
219697
|
-
${newString}`;
|
|
219698
|
-
if (exceeds(combined, DEFAULT_LIMIT)) {
|
|
219699
|
-
return {
|
|
219700
|
-
key: `${call.callID}:input`,
|
|
219701
|
-
content: combined,
|
|
219702
|
-
tokens: countTextTokens(combined),
|
|
219703
|
-
part: () => ({
|
|
219704
|
-
...originalPart,
|
|
219705
|
-
input: { ...input, oldString: "[Omitted]", newString: "[Omitted]" }
|
|
219706
|
-
}),
|
|
219707
|
-
outputNotice: (contentID) => inputOmissionNotice("File edit oldString and newString omitted due to compaction operation. If necessary, reread file to see current contents.", combined.length, contentID)
|
|
219708
|
-
};
|
|
219709
|
-
}
|
|
219710
|
-
}
|
|
219711
|
-
}
|
|
219712
|
-
return null;
|
|
219713
|
-
}
|
|
219714
219839
|
function planOutputOmission(call) {
|
|
219715
219840
|
const output = stringifyToolContent(call.resultValue);
|
|
219716
219841
|
if (call.toolName === "question") {
|
|
@@ -219783,7 +219908,7 @@ function countWords(text, maxWords) {
|
|
|
219783
219908
|
}
|
|
219784
219909
|
|
|
219785
219910
|
// src/context.ts
|
|
219786
|
-
import { join as
|
|
219911
|
+
import { join as join12 } from "node:path";
|
|
219787
219912
|
|
|
219788
219913
|
// src/context-config.ts
|
|
219789
219914
|
function isFullContextMode(config) {
|
|
@@ -219874,7 +219999,7 @@ function registerContextHook(context, deps, runtime) {
|
|
|
219874
219999
|
if (isContextStale(deps)) {
|
|
219875
220000
|
return;
|
|
219876
220001
|
}
|
|
219877
|
-
const remembered = await rememberSnapshot(
|
|
220002
|
+
const remembered = await rememberSnapshot(join12(deps.stateDirectory, "context-snapshot"), sessionID, event.messages, new Date().toISOString(), session.snapshotSeen);
|
|
219878
220003
|
if (isContextStale(deps)) {
|
|
219879
220004
|
return;
|
|
219880
220005
|
}
|
|
@@ -219911,7 +220036,7 @@ function registerContextHook(context, deps, runtime) {
|
|
|
219911
220036
|
removed: trimResult.removedTokens,
|
|
219912
220037
|
omissions: trimResult.omissionCount
|
|
219913
220038
|
};
|
|
219914
|
-
const written = await appendReceipt(
|
|
220039
|
+
const written = await appendReceipt(join12(deps.stateDirectory, "context-log"), sessionID, receipt);
|
|
219915
220040
|
if (!written.ok) {
|
|
219916
220041
|
reportReceiptFailureOnce(runtime, deps, sessionID, "trim");
|
|
219917
220042
|
}
|
|
@@ -219919,9 +220044,6 @@ function registerContextHook(context, deps, runtime) {
|
|
|
219919
220044
|
if (!exceedsThresholds(estimateAfterTrim, windowTokens ?? 0, config)) {
|
|
219920
220045
|
return;
|
|
219921
220046
|
}
|
|
219922
|
-
if (!fullMode) {
|
|
219923
|
-
return;
|
|
219924
|
-
}
|
|
219925
220047
|
if (shouldSuppressCompactionRequest(session, estimatedTokens, windowTokens ?? 0, Date.now())) {
|
|
219926
220048
|
return;
|
|
219927
220049
|
}
|
|
@@ -219930,7 +220052,7 @@ function registerContextHook(context, deps, runtime) {
|
|
|
219930
220052
|
}
|
|
219931
220053
|
async function trimRequest(sessionID, messages, deps) {
|
|
219932
220054
|
const batch = planTrimBatched(messages, { keepRecentTurns: deps.config.keepRecentTurns });
|
|
219933
|
-
const omittedRoot =
|
|
220055
|
+
const omittedRoot = join12(deps.stateDirectory, "omitted");
|
|
219934
220056
|
const stored = await storeOmissions(omittedRoot, sessionID, batch.requests);
|
|
219935
220057
|
const ids = stored.ok ? stored.value.ids : new Map;
|
|
219936
220058
|
const fresh = stored.ok ? stored.value.stored : new Set;
|
|
@@ -220018,9 +220140,9 @@ async function dispatchEvent(raw, deps, runtime) {
|
|
|
220018
220140
|
} else if (event.type === STEP_ENDED) {
|
|
220019
220141
|
handleStepEnded(event.sessionID, event.tokens, deps, runtime);
|
|
220020
220142
|
} else if (event.type === COMPACTION_FAILED) {
|
|
220021
|
-
handleCompactionFailed(event.sessionID, runtime);
|
|
220143
|
+
await handleCompactionFailed(event.sessionID, deps, runtime);
|
|
220022
220144
|
} else if (event.type === COMPACTION_ENDED) {
|
|
220023
|
-
handleCompactionEnded(event.sessionID, runtime);
|
|
220145
|
+
await handleCompactionEnded(event.sessionID, deps, runtime);
|
|
220024
220146
|
}
|
|
220025
220147
|
}
|
|
220026
220148
|
async function handleExecutionSucceeded(sessionID, deps, runtime) {
|
|
@@ -220057,7 +220179,7 @@ function handleStepEnded(sessionID, tokens, deps, runtime) {
|
|
|
220057
220179
|
session.lastStepTokens = tokens;
|
|
220058
220180
|
session.estimator = anchorEstimator(tokens, session.lastMessageCount);
|
|
220059
220181
|
}
|
|
220060
|
-
function handleCompactionFailed(sessionID, runtime) {
|
|
220182
|
+
async function handleCompactionFailed(sessionID, deps, runtime) {
|
|
220061
220183
|
if (sessionID === undefined) {
|
|
220062
220184
|
return;
|
|
220063
220185
|
}
|
|
@@ -220065,13 +220187,34 @@ function handleCompactionFailed(sessionID, runtime) {
|
|
|
220065
220187
|
if (session.lastEstimate === null) {
|
|
220066
220188
|
return;
|
|
220067
220189
|
}
|
|
220068
|
-
|
|
220190
|
+
const at = Date.now();
|
|
220191
|
+
const estimate = session.lastEstimate;
|
|
220192
|
+
const written = await failureBackoffSet(deps.stateDirectory, {
|
|
220193
|
+
version: FAILURE_BACKOFF_VERSION,
|
|
220194
|
+
session_id: sessionID,
|
|
220195
|
+
at,
|
|
220196
|
+
estimate
|
|
220197
|
+
});
|
|
220198
|
+
if (isContextStale(deps)) {
|
|
220199
|
+
return;
|
|
220200
|
+
}
|
|
220201
|
+
session.lastCompactionFailure = { at, estimate };
|
|
220202
|
+
if (!written.ok) {
|
|
220203
|
+
reportReceiptFailureOnce(runtime, deps, sessionID, "compact");
|
|
220204
|
+
}
|
|
220069
220205
|
}
|
|
220070
|
-
function handleCompactionEnded(sessionID, runtime) {
|
|
220206
|
+
async function handleCompactionEnded(sessionID, deps, runtime) {
|
|
220071
220207
|
if (sessionID === undefined) {
|
|
220072
220208
|
return;
|
|
220073
220209
|
}
|
|
220210
|
+
const cleared = await failureBackoffClear(deps.stateDirectory, sessionID);
|
|
220211
|
+
if (isContextStale(deps)) {
|
|
220212
|
+
return;
|
|
220213
|
+
}
|
|
220074
220214
|
sessionRuntime(runtime, sessionID).lastCompactionFailure = null;
|
|
220215
|
+
if (!cleared.ok) {
|
|
220216
|
+
reportReceiptFailureOnce(runtime, deps, sessionID, "compact");
|
|
220217
|
+
}
|
|
220075
220218
|
}
|
|
220076
220219
|
function requestSessionCompaction(context, runtime, sessionID, cause) {
|
|
220077
220220
|
const session = context.session;
|
|
@@ -220500,6 +220643,7 @@ var PREAMBLE_TENETS = `<vcc-brain-tenets version="1.1">
|
|
|
220500
220643
|
- **Your context is ephemeral.** You WILL forget everything after the user starts a new conversation. Proactively persist durable decisions, specs, guides, and lessons in the right place now if they should survive the next session.
|
|
220501
220644
|
- **Keep documents lean.** Do not restate the code. Record contracts, invariants, and decisions the code cannot own. Do not create paragraphs for minor tweaks. Keep documents cohesive, but well scoped; when a document becomes unfocused: split.
|
|
220502
220645
|
- **Proactively update your brain.** When durable truth changes, rewrite its canonical home in the present tense (specs, knowledge, plans → delete/convert when done, product vision). No edit sprawl. Update naturally; state what is true now.
|
|
220646
|
+
- **Resume orientation first.** After a compaction, the session task anchor (plan paths, checklist position) outranks the summary for what to do next: re-read the anchored plan files before acting.
|
|
220503
220647
|
</important>
|
|
220504
220648
|
|
|
220505
220649
|
**You must remember these tenets and apply them while you work.**
|
|
@@ -220651,6 +220795,7 @@ var PREAMBLE_TENETS2 = `<vcc-brain-tenets version="2.0">
|
|
|
220651
220795
|
- **Documents are truth and knowledge.** Read matching documents before every task. Update when details changes. Explore progressively. Do not default to reading everything.
|
|
220652
220796
|
- **Persist durable, reusable knowledge.** Your context is ephemeral. You WILL forget everything after this session ends. Proactively maintain essential context: specs, decisions, guides, rules, findings, etc. in their canonical homes. Do not record task-local guidance or findings with no future usefulness. Permanent rules or definitely useful findings may be recorded in appropriate locations. If uncertain about long-term value, ask user whether to record.
|
|
220653
220797
|
- **Keep memory current and lean.** Update changed contracts, resolve completed plans, and remove obsolete content without duplicating explanations or restating implementation. Outside of essential context or overviews, do not summarize or restate the code. Do not record paragraphs for minor tweaks. No edit sprawl; one home. Update naturally; state what is true now; no mentioning historical detail unless useful.
|
|
220798
|
+
- **Resume orientation first.** After a compaction, the session task anchor (plan paths, checklist position) outranks the summary for what to do next: re-read the anchored plan files before acting.
|
|
220654
220799
|
</important>
|
|
220655
220800
|
|
|
220656
220801
|
**You must remember these tenets and apply them while you work.**
|
|
@@ -220907,15 +221052,15 @@ async function loadPreamble(options) {
|
|
|
220907
221052
|
const cached = options.cache.get(options.sessionID);
|
|
220908
221053
|
if (cached !== undefined)
|
|
220909
221054
|
return cached;
|
|
220910
|
-
const pending = readPreamble(options.projectDirectory, options.homeDirectory);
|
|
221055
|
+
const pending = readPreamble(options.projectDirectory, options.homeDirectory, options.stateDirectory, options.sessionID);
|
|
220911
221056
|
options.cache.set(options.sessionID, pending);
|
|
220912
221057
|
return pending;
|
|
220913
221058
|
}
|
|
220914
|
-
async function readPreamble(projectDirectory, homeDirectory) {
|
|
221059
|
+
async function readPreamble(projectDirectory, homeDirectory, stateDirectory, sessionID) {
|
|
220915
221060
|
try {
|
|
220916
221061
|
const snapshotPromise = loadMemorySnapshot(projectDirectory, homeDirectory, true);
|
|
220917
221062
|
const roots = await resolveBrainRoots(projectDirectory, homeDirectory);
|
|
220918
|
-
|
|
221063
|
+
const rendered = renderPreamble(await snapshotPromise, {
|
|
220919
221064
|
shared: roots.sharedDisplay,
|
|
220920
221065
|
private: roots.privateDisplay,
|
|
220921
221066
|
user: roots.userDisplay,
|
|
@@ -220924,14 +221069,23 @@ async function readPreamble(projectDirectory, homeDirectory) {
|
|
|
220924
221069
|
shared: roots.sharedLegacyAlsoExists,
|
|
220925
221070
|
user: roots.userLegacyAlsoExists
|
|
220926
221071
|
}
|
|
220927
|
-
})
|
|
221072
|
+
});
|
|
221073
|
+
const anchor = await loadSessionAnchor(stateDirectory, sessionID);
|
|
221074
|
+
if (anchor === null || !rendered.loaded) {
|
|
221075
|
+
return success2(rendered);
|
|
221076
|
+
}
|
|
221077
|
+
return success2({
|
|
221078
|
+
...rendered,
|
|
221079
|
+
content: `${rendered.content}
|
|
221080
|
+
${renderAnchorResumeSection(anchor)}`
|
|
221081
|
+
});
|
|
220928
221082
|
} catch (cause) {
|
|
220929
221083
|
return failure2({ message: "VCC Brain failed to create the session preamble.", cause });
|
|
220930
221084
|
}
|
|
220931
221085
|
}
|
|
220932
221086
|
|
|
220933
221087
|
// src/project-config.ts
|
|
220934
|
-
import { readFile as
|
|
221088
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
220935
221089
|
|
|
220936
221090
|
// src/refresh-config.ts
|
|
220937
221091
|
var DEFAULT_PREAMBLE_REFRESH_CONFIG = {
|
|
@@ -220959,7 +221113,7 @@ function parsePreambleRefreshBlock(block, base = DEFAULT_PREAMBLE_REFRESH_CONFIG
|
|
|
220959
221113
|
async function resolveProjectConfig(projectDirectory, base) {
|
|
220960
221114
|
for (const candidate of projectConfigPaths(projectDirectory)) {
|
|
220961
221115
|
try {
|
|
220962
|
-
const text = await
|
|
221116
|
+
const text = await readFile6(candidate, "utf8");
|
|
220963
221117
|
let raw;
|
|
220964
221118
|
try {
|
|
220965
221119
|
raw = JSON.parse(text);
|
|
@@ -221052,7 +221206,7 @@ async function findExternalCompactionProvider(context) {
|
|
|
221052
221206
|
}
|
|
221053
221207
|
|
|
221054
221208
|
// src/refresh.ts
|
|
221055
|
-
import { join as
|
|
221209
|
+
import { join as join13 } from "node:path";
|
|
221056
221210
|
async function maybeRefreshPreamble(deps, runtime, sessionID, projectDirectory, homeDirectory, cache, messages) {
|
|
221057
221211
|
const idle = { refreshed: false, failed: false };
|
|
221058
221212
|
if (!deps.config.enabled || isContextStale(deps) || !deps.isBrainAvailable(sessionID)) {
|
|
@@ -221083,7 +221237,13 @@ async function maybeRefreshPreamble(deps, runtime, sessionID, projectDirectory,
|
|
|
221083
221237
|
}
|
|
221084
221238
|
}
|
|
221085
221239
|
cache.delete(sessionID);
|
|
221086
|
-
const rendered = await loadPreamble({
|
|
221240
|
+
const rendered = await loadPreamble({
|
|
221241
|
+
sessionID,
|
|
221242
|
+
projectDirectory,
|
|
221243
|
+
homeDirectory,
|
|
221244
|
+
stateDirectory: deps.stateDirectory,
|
|
221245
|
+
cache
|
|
221246
|
+
});
|
|
221087
221247
|
if (!rendered.ok || !rendered.value.loaded) {
|
|
221088
221248
|
cache.delete(sessionID);
|
|
221089
221249
|
return { refreshed: false, failed: true };
|
|
@@ -221094,7 +221254,7 @@ async function maybeRefreshPreamble(deps, runtime, sessionID, projectDirectory,
|
|
|
221094
221254
|
reason: postCompaction ? "post-compaction" : "brain-changed",
|
|
221095
221255
|
at: new Date().toISOString()
|
|
221096
221256
|
};
|
|
221097
|
-
await appendReceipt(
|
|
221257
|
+
await appendReceipt(join13(deps.stateDirectory, "context-log"), sessionID, receipt);
|
|
221098
221258
|
return { refreshed: true, content: rendered.value.content };
|
|
221099
221259
|
}
|
|
221100
221260
|
async function refreshPreambleContent(deps, runtime, sessionID, projectDirectory, homeDirectory, cache, messages, cachedContent) {
|
|
@@ -221113,13 +221273,14 @@ async function refreshPreambleContent(deps, runtime, sessionID, projectDirectory
|
|
|
221113
221273
|
|
|
221114
221274
|
// src/tool.ts
|
|
221115
221275
|
import { execFile } from "node:child_process";
|
|
221116
|
-
import { join as
|
|
221276
|
+
import { join as join14 } from "node:path";
|
|
221117
221277
|
var OMISSION_ID_PATTERN = /^omitted-\d+$/;
|
|
221118
221278
|
var CONTEXT_MANAGEMENT_TOOL_NAMES = [
|
|
221119
221279
|
"vcc-brain-read_omitted",
|
|
221120
221280
|
"vcc-brain-prune",
|
|
221121
221281
|
"vcc-brain-recall",
|
|
221122
|
-
"vcc-brain-search"
|
|
221282
|
+
"vcc-brain-search",
|
|
221283
|
+
"vcc-brain-anchor"
|
|
221123
221284
|
];
|
|
221124
221285
|
function isOmissionID(contentID) {
|
|
221125
221286
|
return OMISSION_ID_PATTERN.test(contentID);
|
|
@@ -221129,7 +221290,7 @@ async function registerReadOmittedTool(context, deps) {
|
|
|
221129
221290
|
editor.add({
|
|
221130
221291
|
name: "vcc-brain-read_omitted",
|
|
221131
221292
|
options: { codemode: false },
|
|
221132
|
-
description: "Read original tool
|
|
221293
|
+
description: "Read original tool output content omitted by VCC Brain trimming or compaction. " + "This reads the snapshot of previously executed tool I/O; contents should be expected " + "to be stale. Only use it when stale content is strictly required and similar " + "information cannot be obtained via new tool calls.",
|
|
221133
221294
|
input: {
|
|
221134
221295
|
type: "object",
|
|
221135
221296
|
properties: {
|
|
@@ -221151,7 +221312,7 @@ async function registerReadOmittedTool(context, deps) {
|
|
|
221151
221312
|
if (!isOmissionID(contentID)) {
|
|
221152
221313
|
return { content: `Invalid content ID: ${contentID}.` };
|
|
221153
221314
|
}
|
|
221154
|
-
const stored = await readOmission(
|
|
221315
|
+
const stored = await readOmission(join14(deps.stateDirectory, "omitted"), toolContext.sessionID, contentID);
|
|
221155
221316
|
if (!stored.ok) {
|
|
221156
221317
|
return { content: `Could not read omitted content for Content ID: ${contentID}.` };
|
|
221157
221318
|
}
|
|
@@ -221167,7 +221328,7 @@ async function registerPruneTool(context, deps) {
|
|
|
221167
221328
|
editor.add({
|
|
221168
221329
|
name: "vcc-brain-prune",
|
|
221169
221330
|
options: { codemode: false },
|
|
221170
|
-
description: "Prune the current session's omitted tool
|
|
221331
|
+
description: "Prune the current session's omitted tool output store " + "by age, count, and size. Recover pruned payloads first if they are " + "still needed: pruning deletes the files vcc-brain-read_omitted serves.",
|
|
221171
221332
|
input: {
|
|
221172
221333
|
type: "object",
|
|
221173
221334
|
properties: {
|
|
@@ -221187,7 +221348,7 @@ async function registerPruneTool(context, deps) {
|
|
|
221187
221348
|
},
|
|
221188
221349
|
execute: async (input, toolContext) => {
|
|
221189
221350
|
const options = asPruneOptions(input);
|
|
221190
|
-
const pruned = await pruneOmissions(
|
|
221351
|
+
const pruned = await pruneOmissions(join14(deps.stateDirectory, "omitted"), toolContext.sessionID, {
|
|
221191
221352
|
maxAgeMs: options.maxAgeDays * 24 * 60 * 60 * 1000,
|
|
221192
221353
|
maxPayloads: options.maxPayloads,
|
|
221193
221354
|
maxBytes: options.maxBytes
|
|
@@ -221246,7 +221407,7 @@ async function registerRecallTool(context, deps) {
|
|
|
221246
221407
|
if (typeof input.id !== "string" || input.id.trim() === "") {
|
|
221247
221408
|
return { content: "Missing required input: id." };
|
|
221248
221409
|
}
|
|
221249
|
-
const read = await readCompactionSnapshot(
|
|
221410
|
+
const read = await readCompactionSnapshot(join14(deps.stateDirectory, "context-snapshot"), toolContext.sessionID);
|
|
221250
221411
|
const classified = classifySnapshotStore(read);
|
|
221251
221412
|
if (classified.status === "failed") {
|
|
221252
221413
|
return { content: "Could not read compaction snapshot for this session." };
|
|
@@ -221296,7 +221457,7 @@ async function registerSearchTool(context, deps) {
|
|
|
221296
221457
|
if (!isRecord(input) || typeof input.pattern !== "string" || input.pattern.trim() === "") {
|
|
221297
221458
|
return { content: "Missing required input: pattern." };
|
|
221298
221459
|
}
|
|
221299
|
-
const read = await readCompactionSnapshot(
|
|
221460
|
+
const read = await readCompactionSnapshot(join14(deps.stateDirectory, "context-snapshot"), toolContext.sessionID);
|
|
221300
221461
|
const classified = classifySnapshotStore(read);
|
|
221301
221462
|
if (classified.status === "failed") {
|
|
221302
221463
|
return { content: "Could not read compaction snapshot for this session." };
|
|
@@ -221439,6 +221600,105 @@ async function registerRecallSessionTool(context) {
|
|
|
221439
221600
|
});
|
|
221440
221601
|
});
|
|
221441
221602
|
}
|
|
221603
|
+
async function registerAnchorTool(context, deps) {
|
|
221604
|
+
await context.tool.transform((editor) => {
|
|
221605
|
+
editor.add({
|
|
221606
|
+
name: "vcc-brain-anchor",
|
|
221607
|
+
options: { codemode: false },
|
|
221608
|
+
description: "Stage or clear the session task anchor: orientation state that survives " + "compaction deterministically. Action stage records plan paths and checklist " + "position for the next compaction; action clear removes the record on task completion.",
|
|
221609
|
+
input: {
|
|
221610
|
+
type: "object",
|
|
221611
|
+
properties: {
|
|
221612
|
+
action: {
|
|
221613
|
+
type: "string",
|
|
221614
|
+
description: 'Either "stage" or "clear".'
|
|
221615
|
+
},
|
|
221616
|
+
task_id: {
|
|
221617
|
+
type: "string",
|
|
221618
|
+
description: "Task identifier, e.g. a plan path (stage only)."
|
|
221619
|
+
},
|
|
221620
|
+
plan_paths: {
|
|
221621
|
+
type: "array",
|
|
221622
|
+
items: { type: "string" },
|
|
221623
|
+
description: "Plan files to re-read at resume (stage only)."
|
|
221624
|
+
},
|
|
221625
|
+
done: {
|
|
221626
|
+
type: "array",
|
|
221627
|
+
items: { type: "string" },
|
|
221628
|
+
description: "Completed checklist entries (stage only)."
|
|
221629
|
+
},
|
|
221630
|
+
current: {
|
|
221631
|
+
type: "string",
|
|
221632
|
+
description: "Current checklist entry, or null (stage only)."
|
|
221633
|
+
},
|
|
221634
|
+
next: {
|
|
221635
|
+
type: "array",
|
|
221636
|
+
items: { type: "string" },
|
|
221637
|
+
description: "Upcoming checklist entries (stage only)."
|
|
221638
|
+
},
|
|
221639
|
+
working_tree: {
|
|
221640
|
+
type: "array",
|
|
221641
|
+
items: { type: "string" },
|
|
221642
|
+
description: "Working-tree sketch lines, or null (stage only)."
|
|
221643
|
+
},
|
|
221644
|
+
mid_through: {
|
|
221645
|
+
type: "string",
|
|
221646
|
+
description: "One-line mid-through note, or null (stage only)."
|
|
221647
|
+
}
|
|
221648
|
+
},
|
|
221649
|
+
required: ["action"]
|
|
221650
|
+
},
|
|
221651
|
+
execute: async (input, toolContext) => {
|
|
221652
|
+
if (!isRecord(input) || input.action !== "stage" && input.action !== "clear") {
|
|
221653
|
+
return { content: 'Missing or invalid input: action must be "stage" or "clear".' };
|
|
221654
|
+
}
|
|
221655
|
+
if (input.action === "clear") {
|
|
221656
|
+
const cleared = await anchorClear(deps.stateDirectory, toolContext.sessionID);
|
|
221657
|
+
if (!cleared.ok) {
|
|
221658
|
+
return { content: "Could not clear the task anchor for this session." };
|
|
221659
|
+
}
|
|
221660
|
+
return { content: "Task anchor cleared." };
|
|
221661
|
+
}
|
|
221662
|
+
if (typeof input.task_id !== "string" || input.task_id.trim() === "") {
|
|
221663
|
+
return { content: "Missing required input: task_id." };
|
|
221664
|
+
}
|
|
221665
|
+
if (!isStringArray(input.plan_paths)) {
|
|
221666
|
+
return { content: "Missing required input: plan_paths must be an array of strings." };
|
|
221667
|
+
}
|
|
221668
|
+
const doneRaw = input.done === undefined ? [] : input.done;
|
|
221669
|
+
const nextRaw = input.next === undefined ? [] : input.next;
|
|
221670
|
+
if (!isStringArray(doneRaw) || !isStringArray(nextRaw)) {
|
|
221671
|
+
return { content: "Invalid input: done and next must be arrays of strings." };
|
|
221672
|
+
}
|
|
221673
|
+
const done = doneRaw;
|
|
221674
|
+
const next = nextRaw;
|
|
221675
|
+
const currentRaw = input.current === undefined || input.current === null ? null : input.current;
|
|
221676
|
+
if (currentRaw !== null && typeof currentRaw !== "string") {
|
|
221677
|
+
return { content: "Invalid input: current must be a string or null." };
|
|
221678
|
+
}
|
|
221679
|
+
const current = currentRaw;
|
|
221680
|
+
const workingTreeRaw = input.working_tree === undefined || input.working_tree === null ? null : input.working_tree;
|
|
221681
|
+
if (workingTreeRaw !== null && !isStringArray(workingTreeRaw)) {
|
|
221682
|
+
return { content: "Invalid input: working_tree must be an array of strings or null." };
|
|
221683
|
+
}
|
|
221684
|
+
const workingTree = workingTreeRaw;
|
|
221685
|
+
const midThroughRaw = input.mid_through === undefined || input.mid_through === null ? null : input.mid_through;
|
|
221686
|
+
if (midThroughRaw !== null && typeof midThroughRaw !== "string") {
|
|
221687
|
+
return { content: "Invalid input: mid_through must be a string or null." };
|
|
221688
|
+
}
|
|
221689
|
+
const midThrough = midThroughRaw;
|
|
221690
|
+
stageAnchor(deps.runtime, toolContext.sessionID, {
|
|
221691
|
+
task_id: input.task_id,
|
|
221692
|
+
plan_paths: input.plan_paths,
|
|
221693
|
+
checklist: { done, current, next },
|
|
221694
|
+
working_tree: workingTree,
|
|
221695
|
+
mid_through: midThrough
|
|
221696
|
+
});
|
|
221697
|
+
return { content: "Task anchor staged for the next compaction." };
|
|
221698
|
+
}
|
|
221699
|
+
});
|
|
221700
|
+
});
|
|
221701
|
+
}
|
|
221442
221702
|
|
|
221443
221703
|
// src/index.ts
|
|
221444
221704
|
var setupGeneration = 0;
|
|
@@ -221565,6 +221825,7 @@ var VccBrainPlugin = Plugin.define({
|
|
|
221565
221825
|
sessionID: event.sessionID,
|
|
221566
221826
|
projectDirectory: context.location.directory,
|
|
221567
221827
|
homeDirectory: homedir(),
|
|
221828
|
+
stateDirectory: resolveStateDirectory(homedir()),
|
|
221568
221829
|
cache
|
|
221569
221830
|
});
|
|
221570
221831
|
brainAvailable.set(event.sessionID, result.ok ? result.value.loaded && result.value.initialized : false);
|
|
@@ -221663,7 +221924,10 @@ var VccBrainPlugin = Plugin.define({
|
|
|
221663
221924
|
isBrainAvailable,
|
|
221664
221925
|
reportReceiptFailure,
|
|
221665
221926
|
refreshEnabled: refreshConfig.enabled,
|
|
221666
|
-
isCurrent: isActive
|
|
221927
|
+
isCurrent: isActive,
|
|
221928
|
+
onAnchorWritten: (sessionID) => {
|
|
221929
|
+
cache.delete(sessionID);
|
|
221930
|
+
}
|
|
221667
221931
|
}, runtime);
|
|
221668
221932
|
}
|
|
221669
221933
|
registerCompletionTrigger(context, deps, runtime, { signal: controller.signal });
|
|
@@ -221672,6 +221936,7 @@ var VccBrainPlugin = Plugin.define({
|
|
|
221672
221936
|
if (fullMode) {
|
|
221673
221937
|
await registerRecallTool(context, { stateDirectory });
|
|
221674
221938
|
await registerSearchTool(context, { stateDirectory });
|
|
221939
|
+
await registerAnchorTool(context, { stateDirectory, runtime });
|
|
221675
221940
|
}
|
|
221676
221941
|
await registerSearchSessionsTool(context, {
|
|
221677
221942
|
projectDirectory: context.location.directory
|
|
@@ -221714,4 +221979,4 @@ export {
|
|
|
221714
221979
|
src_default as default
|
|
221715
221980
|
};
|
|
221716
221981
|
|
|
221717
|
-
//# debugId=
|
|
221982
|
+
//# debugId=C6752D1D4CECD5A764756E2164756E21
|