@jwitmann/vcc-brain-opencode-v2 2.7.2 → 2.8.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 +188 -23
- package/dist/index.js.map +11 -10
- package/dist/server.js +188 -23
- package/dist/server.js.map +11 -10
- package/dist/tui.js +2 -2
- package/dist/tui.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7406,7 +7406,7 @@ import { Plugin } from "@opencode/plugin";
|
|
|
7406
7406
|
// package.json
|
|
7407
7407
|
var package_default = {
|
|
7408
7408
|
name: "@jwitmann/vcc-brain-opencode-v2",
|
|
7409
|
-
version: "2.
|
|
7409
|
+
version: "2.8.1",
|
|
7410
7410
|
description: "VCC Brain adapter for OpenCode V2.",
|
|
7411
7411
|
license: "BSD-3-Clause",
|
|
7412
7412
|
author: "jwitmann",
|
|
@@ -217460,6 +217460,16 @@ function readOptionNumber(path, block, key, defaultValue) {
|
|
|
217460
217460
|
}
|
|
217461
217461
|
return success2(value);
|
|
217462
217462
|
}
|
|
217463
|
+
function readOptionString(path, block, key, defaultValue) {
|
|
217464
|
+
const value = block[key];
|
|
217465
|
+
if (value === undefined) {
|
|
217466
|
+
return success2(defaultValue);
|
|
217467
|
+
}
|
|
217468
|
+
if (typeof value !== "string") {
|
|
217469
|
+
return failure2({ message: `The "${path}.${key}" option must be a string.` });
|
|
217470
|
+
}
|
|
217471
|
+
return success2(value);
|
|
217472
|
+
}
|
|
217463
217473
|
function readOptionBoolean(path, block, key, defaultValue) {
|
|
217464
217474
|
const value = block[key];
|
|
217465
217475
|
if (value === undefined) {
|
|
@@ -218537,10 +218547,24 @@ function toCompilerNode(message, seq) {
|
|
|
218537
218547
|
if (block !== null)
|
|
218538
218548
|
blocks.push(block);
|
|
218539
218549
|
}
|
|
218550
|
+
if (isTaggedCheckpointBlocks(blocks)) {
|
|
218551
|
+
return {
|
|
218552
|
+
seq,
|
|
218553
|
+
message: { role: "user", content: blocks, source: { kind: "compact-checkpoint" } }
|
|
218554
|
+
};
|
|
218555
|
+
}
|
|
218540
218556
|
return { seq, message: { role: "user", content: blocks } };
|
|
218541
218557
|
}
|
|
218542
218558
|
return null;
|
|
218543
218559
|
}
|
|
218560
|
+
function isTaggedCheckpointBlocks(blocks) {
|
|
218561
|
+
let text = "";
|
|
218562
|
+
for (const block of blocks) {
|
|
218563
|
+
if (block?.type === "text" && typeof block.text === "string")
|
|
218564
|
+
text += block.text;
|
|
218565
|
+
}
|
|
218566
|
+
return text.includes(CHECKPOINT_OPEN_TAG) && text.includes(CHECKPOINT_CLOSE_TAG);
|
|
218567
|
+
}
|
|
218544
218568
|
function pickKeepID(messages, keepMessages) {
|
|
218545
218569
|
const list = Array.isArray(messages) ? messages : [];
|
|
218546
218570
|
const keep = Number.isFinite(keepMessages) && keepMessages > 0 ? Math.max(1, Math.floor(keepMessages)) : DEFAULT_VCC_KEEP_MESSAGES;
|
|
@@ -219327,6 +219351,30 @@ function formatSearchReply(pattern, found) {
|
|
|
219327
219351
|
|
|
219328
219352
|
${found.text}`;
|
|
219329
219353
|
}
|
|
219354
|
+
var FOREIGN_COMPACTION_HEADER_PATTERN = /\[([^\][\n]*-compaction\s+\S[^\][\n]*:[^\][\n]*)\]/;
|
|
219355
|
+
var OWN_COMPACTION_HEADER_PREFIX = "[vcc-compaction ";
|
|
219356
|
+
function findForeignCheckpointHeader(messages) {
|
|
219357
|
+
const list = Array.isArray(messages) ? messages : [];
|
|
219358
|
+
for (const message of list) {
|
|
219359
|
+
const content = message?.content;
|
|
219360
|
+
if (!Array.isArray(content))
|
|
219361
|
+
continue;
|
|
219362
|
+
for (const part of content) {
|
|
219363
|
+
if (part === null || part === undefined || part.type !== "text")
|
|
219364
|
+
continue;
|
|
219365
|
+
const text = part.text;
|
|
219366
|
+
if (typeof text !== "string")
|
|
219367
|
+
continue;
|
|
219368
|
+
const match = FOREIGN_COMPACTION_HEADER_PATTERN.exec(text);
|
|
219369
|
+
if (match === null)
|
|
219370
|
+
continue;
|
|
219371
|
+
const header = `[${match[1] ?? ""}]`;
|
|
219372
|
+
if (!header.startsWith(OWN_COMPACTION_HEADER_PREFIX))
|
|
219373
|
+
return header;
|
|
219374
|
+
}
|
|
219375
|
+
}
|
|
219376
|
+
return null;
|
|
219377
|
+
}
|
|
219330
219378
|
function classifySnapshotStore(read) {
|
|
219331
219379
|
if (!read.ok)
|
|
219332
219380
|
return { status: "failed" };
|
|
@@ -219738,8 +219786,12 @@ function countWords(text, maxWords) {
|
|
|
219738
219786
|
import { join as join11 } from "node:path";
|
|
219739
219787
|
|
|
219740
219788
|
// src/context-config.ts
|
|
219789
|
+
function isFullContextMode(config) {
|
|
219790
|
+
return config.mode === "full";
|
|
219791
|
+
}
|
|
219741
219792
|
var DEFAULT_CONTEXT_MANAGEMENT_CONFIG = {
|
|
219742
219793
|
enabled: false,
|
|
219794
|
+
mode: "full",
|
|
219743
219795
|
ratio: 0.8,
|
|
219744
219796
|
hardCapTokens: 250000,
|
|
219745
219797
|
keepRecentTurns: 3,
|
|
@@ -219767,6 +219819,7 @@ function parseContextManagementBlock(block, base = DEFAULT_CONTEXT_MANAGEMENT_CO
|
|
|
219767
219819
|
}
|
|
219768
219820
|
const path = "vcc-brain.contextManagement";
|
|
219769
219821
|
const enabled = readOptionBoolean(path, block, "enabled", base.enabled);
|
|
219822
|
+
const mode = readOptionString(path, block, "mode", base.mode);
|
|
219770
219823
|
const ratio = readOptionNumber(path, block, "ratio", base.ratio);
|
|
219771
219824
|
const hardCapTokens = readOptionNumber(path, block, "hardCapTokens", base.hardCapTokens);
|
|
219772
219825
|
const keepRecentTurns = readOptionNumber(path, block, "keepRecentTurns", base.keepRecentTurns);
|
|
@@ -219774,6 +219827,13 @@ function parseContextManagementBlock(block, base = DEFAULT_CONTEXT_MANAGEMENT_CO
|
|
|
219774
219827
|
const compactFloorTokens = readOptionNumber(path, block, "compactFloorTokens", base.compactFloorTokens);
|
|
219775
219828
|
if (!enabled.ok)
|
|
219776
219829
|
return enabled;
|
|
219830
|
+
if (!mode.ok)
|
|
219831
|
+
return mode;
|
|
219832
|
+
if (mode.value !== "full" && mode.value !== "vcc") {
|
|
219833
|
+
return failure2({
|
|
219834
|
+
message: `The "${path}.mode" option must be "full" or "vcc".`
|
|
219835
|
+
});
|
|
219836
|
+
}
|
|
219777
219837
|
if (!ratio.ok)
|
|
219778
219838
|
return ratio;
|
|
219779
219839
|
if (!hardCapTokens.ok)
|
|
@@ -219786,6 +219846,7 @@ function parseContextManagementBlock(block, base = DEFAULT_CONTEXT_MANAGEMENT_CO
|
|
|
219786
219846
|
return compactFloorTokens;
|
|
219787
219847
|
return success2({
|
|
219788
219848
|
enabled: enabled.value,
|
|
219849
|
+
mode: mode.value,
|
|
219789
219850
|
ratio: ratio.value,
|
|
219790
219851
|
hardCapTokens: hardCapTokens.value,
|
|
219791
219852
|
keepRecentTurns: keepRecentTurns.value,
|
|
@@ -219802,20 +219863,23 @@ function registerContextHook(context, deps, runtime) {
|
|
|
219802
219863
|
}
|
|
219803
219864
|
const sessionID = event.sessionID;
|
|
219804
219865
|
const config = deps.config;
|
|
219866
|
+
const fullMode = isFullContextMode(config);
|
|
219805
219867
|
await ensureSessionHydrated(deps.stateDirectory, runtime, sessionID);
|
|
219806
219868
|
if (!deps.isBrainAvailable(sessionID)) {
|
|
219807
219869
|
await ensureRefusalReceipt(deps.stateDirectory, runtime, sessionID, deps);
|
|
219808
219870
|
return;
|
|
219809
219871
|
}
|
|
219810
219872
|
const session = sessionRuntime(runtime, sessionID);
|
|
219811
|
-
if (
|
|
219812
|
-
|
|
219813
|
-
|
|
219814
|
-
|
|
219815
|
-
|
|
219816
|
-
|
|
219873
|
+
if (fullMode) {
|
|
219874
|
+
if (isContextStale(deps)) {
|
|
219875
|
+
return;
|
|
219876
|
+
}
|
|
219877
|
+
const remembered = await rememberSnapshot(join11(deps.stateDirectory, "context-snapshot"), sessionID, event.messages, new Date().toISOString(), session.snapshotSeen);
|
|
219878
|
+
if (isContextStale(deps)) {
|
|
219879
|
+
return;
|
|
219880
|
+
}
|
|
219881
|
+
session.snapshotSeen = remembered.seen;
|
|
219817
219882
|
}
|
|
219818
|
-
session.snapshotSeen = remembered.seen;
|
|
219819
219883
|
const estimatedTokens = estimateContextTokens(session.estimator, event.messages);
|
|
219820
219884
|
const windowTokens = await resolveWindowTokens(context, session, event.model);
|
|
219821
219885
|
session.lastEstimate = estimatedTokens;
|
|
@@ -219855,6 +219919,9 @@ function registerContextHook(context, deps, runtime) {
|
|
|
219855
219919
|
if (!exceedsThresholds(estimateAfterTrim, windowTokens ?? 0, config)) {
|
|
219856
219920
|
return;
|
|
219857
219921
|
}
|
|
219922
|
+
if (!fullMode) {
|
|
219923
|
+
return;
|
|
219924
|
+
}
|
|
219858
219925
|
if (shouldSuppressCompactionRequest(session, estimatedTokens, windowTokens ?? 0, Date.now())) {
|
|
219859
219926
|
return;
|
|
219860
219927
|
}
|
|
@@ -220948,6 +221015,42 @@ function readProjectBlock(input, key) {
|
|
|
220948
221015
|
return success2(section);
|
|
220949
221016
|
}
|
|
220950
221017
|
|
|
221018
|
+
// src/provider-detect.ts
|
|
221019
|
+
var EXTERNAL_RECALL_TOOL_NAMES = new Set(["vcc-recall", "vcc-search"]);
|
|
221020
|
+
var EXTERNAL_ENGINE_SEGMENT = "opencode-vcc-port";
|
|
221021
|
+
function detectExternalCompactionProvider(plugins, tools) {
|
|
221022
|
+
const toolList = Array.isArray(tools) ? tools : [];
|
|
221023
|
+
for (const tool of toolList) {
|
|
221024
|
+
if (isRecord(tool) && typeof tool.name === "string" && EXTERNAL_RECALL_TOOL_NAMES.has(tool.name)) {
|
|
221025
|
+
return { kind: "tool", detail: `external compaction tool "${tool.name}" is registered` };
|
|
221026
|
+
}
|
|
221027
|
+
}
|
|
221028
|
+
const pluginList = Array.isArray(plugins) ? plugins : [];
|
|
221029
|
+
for (const plugin of pluginList) {
|
|
221030
|
+
if (!isRecord(plugin))
|
|
221031
|
+
continue;
|
|
221032
|
+
if (typeof plugin.id === "string" && plugin.id === EXTERNAL_ENGINE_SEGMENT) {
|
|
221033
|
+
return { kind: "plugin", detail: `external compaction plugin "${plugin.id}" is active` };
|
|
221034
|
+
}
|
|
221035
|
+
const source = plugin.source;
|
|
221036
|
+
if (isRecord(source) && source.type === "local" && typeof source.path === "string" && source.path.split("/").includes(EXTERNAL_ENGINE_SEGMENT)) {
|
|
221037
|
+
return { kind: "plugin", detail: `external compaction plugin at "${source.path}" is active` };
|
|
221038
|
+
}
|
|
221039
|
+
}
|
|
221040
|
+
return null;
|
|
221041
|
+
}
|
|
221042
|
+
async function findExternalCompactionProvider(context) {
|
|
221043
|
+
try {
|
|
221044
|
+
const pluginList = typeof context.plugin?.list === "function" ? await context.plugin.list() : null;
|
|
221045
|
+
const toolList = typeof context.tool?.list === "function" ? await context.tool.list() : null;
|
|
221046
|
+
const plugins = isRecord(pluginList) && Array.isArray(pluginList.data) ? pluginList.data : [];
|
|
221047
|
+
const tools = Array.isArray(toolList) ? toolList : [];
|
|
221048
|
+
return detectExternalCompactionProvider(plugins, tools);
|
|
221049
|
+
} catch {
|
|
221050
|
+
return null;
|
|
221051
|
+
}
|
|
221052
|
+
}
|
|
221053
|
+
|
|
220951
221054
|
// src/refresh.ts
|
|
220952
221055
|
import { join as join12 } from "node:path";
|
|
220953
221056
|
async function maybeRefreshPreamble(deps, runtime, sessionID, projectDirectory, homeDirectory, cache, messages) {
|
|
@@ -221012,6 +221115,12 @@ async function refreshPreambleContent(deps, runtime, sessionID, projectDirectory
|
|
|
221012
221115
|
import { execFile } from "node:child_process";
|
|
221013
221116
|
import { join as join13 } from "node:path";
|
|
221014
221117
|
var OMISSION_ID_PATTERN = /^omitted-\d+$/;
|
|
221118
|
+
var CONTEXT_MANAGEMENT_TOOL_NAMES = [
|
|
221119
|
+
"vcc-brain-read_omitted",
|
|
221120
|
+
"vcc-brain-prune",
|
|
221121
|
+
"vcc-brain-recall",
|
|
221122
|
+
"vcc-brain-search"
|
|
221123
|
+
];
|
|
221015
221124
|
function isOmissionID(contentID) {
|
|
221016
221125
|
return OMISSION_ID_PATTERN.test(contentID);
|
|
221017
221126
|
}
|
|
@@ -221149,6 +221258,14 @@ async function registerRecallTool(context, deps) {
|
|
|
221149
221258
|
}
|
|
221150
221259
|
const resolved = resolveRecallSelections(classified.messages, input.type, input.id);
|
|
221151
221260
|
if (resolved.errors.length > 0 || resolved.selections.length === 0) {
|
|
221261
|
+
if (input.type === "checkpoint") {
|
|
221262
|
+
const foreign = findForeignCheckpointHeader(classified.messages);
|
|
221263
|
+
if (foreign !== null) {
|
|
221264
|
+
return {
|
|
221265
|
+
content: `This session's checkpoint was compiled by an external compaction engine (${foreign}), ` + "not by VCC Brain instant-compaction, so vcc-brain-recall has no checkpoint ordinals for it. " + "Restore it with the owning engine's recall tool (for the opencode-vcc-port engine: vcc-recall)."
|
|
221266
|
+
};
|
|
221267
|
+
}
|
|
221268
|
+
}
|
|
221152
221269
|
return {
|
|
221153
221270
|
content: resolved.errors.length > 0 ? resolved.errors.join("; ") : "Nothing to recall."
|
|
221154
221271
|
};
|
|
@@ -221394,10 +221511,53 @@ var VccBrainPlugin = Plugin.define({
|
|
|
221394
221511
|
const effectiveRefreshConfig = projectOverride.config.preambleRefresh;
|
|
221395
221512
|
const effectiveBrainUpdatesConfig = projectOverride.config.brainUpdates;
|
|
221396
221513
|
const effectiveContextManagement = projectOverride.config.contextManagement;
|
|
221397
|
-
|
|
221514
|
+
let contextManagementEnabled = parsed.ok && effectiveContextManagement.enabled;
|
|
221515
|
+
if (contextManagementEnabled && isFullContextMode(effectiveContextManagement)) {
|
|
221516
|
+
const external = await findExternalCompactionProvider(context);
|
|
221517
|
+
if (external !== null) {
|
|
221518
|
+
contextManagementEnabled = false;
|
|
221519
|
+
await showToast({
|
|
221520
|
+
title: "VCC Brain",
|
|
221521
|
+
message: `External compaction engine detected (${external.detail}); VCC Brain context management is off — ` + "one compaction/recall provider per session. Preamble, refresh, and brain updates stay on.",
|
|
221522
|
+
variant: "warning"
|
|
221523
|
+
}).catch(() => {
|
|
221524
|
+
return;
|
|
221525
|
+
});
|
|
221526
|
+
}
|
|
221527
|
+
}
|
|
221528
|
+
const standDown = { stoodDown: false };
|
|
221529
|
+
const isActive = () => isCurrent() && !standDown.stoodDown;
|
|
221530
|
+
let providerRecheckDone = false;
|
|
221531
|
+
const maybeStandDownForExternalProvider = async () => {
|
|
221532
|
+
if (!contextManagementEnabled || !isFullContextMode(effectiveContextManagement) || providerRecheckDone || !isCurrent()) {
|
|
221533
|
+
return;
|
|
221534
|
+
}
|
|
221535
|
+
providerRecheckDone = true;
|
|
221536
|
+
const hit = await findExternalCompactionProvider(context);
|
|
221537
|
+
if (hit === null || !isCurrent())
|
|
221538
|
+
return;
|
|
221539
|
+
standDown.stoodDown = true;
|
|
221540
|
+
try {
|
|
221541
|
+
await context.tool.transform((editor) => {
|
|
221542
|
+
for (const name of CONTEXT_MANAGEMENT_TOOL_NAMES)
|
|
221543
|
+
editor.remove(name);
|
|
221544
|
+
});
|
|
221545
|
+
} catch {}
|
|
221546
|
+
await showToast({
|
|
221547
|
+
title: "VCC Brain",
|
|
221548
|
+
message: `External compaction engine detected (${hit.detail}); VCC Brain context management stood down — ` + "use the owning engine's recall/search tools.",
|
|
221549
|
+
variant: "warning"
|
|
221550
|
+
}).catch(() => {
|
|
221551
|
+
return;
|
|
221552
|
+
});
|
|
221553
|
+
};
|
|
221398
221554
|
await registerCommands(context);
|
|
221399
221555
|
const brainAvailable = new Map;
|
|
221400
221556
|
await context.session.hook("context", async (event) => {
|
|
221557
|
+
if (!isCurrent()) {
|
|
221558
|
+
return;
|
|
221559
|
+
}
|
|
221560
|
+
await maybeStandDownForExternalProvider();
|
|
221401
221561
|
if (!isCurrent()) {
|
|
221402
221562
|
return;
|
|
221403
221563
|
}
|
|
@@ -221479,8 +221639,9 @@ var VccBrainPlugin = Plugin.define({
|
|
|
221479
221639
|
};
|
|
221480
221640
|
const controller = new AbortController;
|
|
221481
221641
|
if (contextManagementEnabled) {
|
|
221642
|
+
const fullMode = isFullContextMode(config);
|
|
221482
221643
|
const requestCompaction = (sessionID, cause) => {
|
|
221483
|
-
if (!
|
|
221644
|
+
if (!isActive()) {
|
|
221484
221645
|
return;
|
|
221485
221646
|
}
|
|
221486
221647
|
requestSessionCompaction(context, runtime, sessionID, cause);
|
|
@@ -221491,23 +221652,27 @@ var VccBrainPlugin = Plugin.define({
|
|
|
221491
221652
|
requestCompaction,
|
|
221492
221653
|
isBrainAvailable,
|
|
221493
221654
|
reportReceiptFailure,
|
|
221494
|
-
isCurrent
|
|
221655
|
+
isCurrent: isActive
|
|
221495
221656
|
};
|
|
221496
221657
|
registerContextHook(context, deps, runtime);
|
|
221497
|
-
|
|
221498
|
-
|
|
221499
|
-
|
|
221500
|
-
|
|
221501
|
-
|
|
221502
|
-
|
|
221503
|
-
|
|
221504
|
-
|
|
221505
|
-
|
|
221658
|
+
if (fullMode) {
|
|
221659
|
+
registerCompactionHook(context, {
|
|
221660
|
+
config,
|
|
221661
|
+
stateDirectory,
|
|
221662
|
+
brainPaths: DEFAULT_BRAIN_PATHS,
|
|
221663
|
+
isBrainAvailable,
|
|
221664
|
+
reportReceiptFailure,
|
|
221665
|
+
refreshEnabled: refreshConfig.enabled,
|
|
221666
|
+
isCurrent: isActive
|
|
221667
|
+
}, runtime);
|
|
221668
|
+
}
|
|
221506
221669
|
registerCompletionTrigger(context, deps, runtime, { signal: controller.signal });
|
|
221507
221670
|
await registerReadOmittedTool(context, { stateDirectory });
|
|
221508
221671
|
await registerPruneTool(context, { stateDirectory });
|
|
221509
|
-
|
|
221510
|
-
|
|
221672
|
+
if (fullMode) {
|
|
221673
|
+
await registerRecallTool(context, { stateDirectory });
|
|
221674
|
+
await registerSearchTool(context, { stateDirectory });
|
|
221675
|
+
}
|
|
221511
221676
|
await registerSearchSessionsTool(context, {
|
|
221512
221677
|
projectDirectory: context.location.directory
|
|
221513
221678
|
});
|
|
@@ -221549,4 +221714,4 @@ export {
|
|
|
221549
221714
|
src_default as default
|
|
221550
221715
|
};
|
|
221551
221716
|
|
|
221552
|
-
//# debugId=
|
|
221717
|
+
//# debugId=ED9B918913E4F56E64756E2164756E21
|