@jwitmann/vcc-brain-opencode-v2 2.9.1 → 2.10.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/dist/server.js CHANGED
@@ -7409,7 +7409,7 @@ import { Plugin } from "@opencode/plugin";
7409
7409
  // package.json
7410
7410
  var package_default = {
7411
7411
  name: "@jwitmann/vcc-brain-opencode-v2",
7412
- version: "2.9.1",
7412
+ version: "2.10.0",
7413
7413
  description: "VCC Brain adapter for OpenCode V2.",
7414
7414
  license: "BSD-3-Clause",
7415
7415
  author: "jwitmann",
@@ -216793,6 +216793,14 @@ function evaluateBrainUpdateActivity(state, fingerprint, completedCalls, thresho
216793
216793
  };
216794
216794
  return { state: next, completedSinceBaseline: sinceBaseline, crossed };
216795
216795
  }
216796
+ function brainUpdateReminderText(toolCallThreshold) {
216797
+ return `<vcc-brain-brain-update-reminder>
216798
+ You have completed ${toolCallThreshold} tool calls without a Brain change.
216799
+ Before continuing, record any durable decisions, contracts, or lessons in the
216800
+ appropriate Brain partition. Do not write transient task progress or restate
216801
+ implementation. If nothing durable has emerged, make no Brain edits.
216802
+ </vcc-brain-brain-update-reminder>`;
216803
+ }
216796
216804
  function isHelperTool(part) {
216797
216805
  return part.namespace === "vcc-brain" || part.namespace === "operator";
216798
216806
  }
@@ -217496,15 +217504,7 @@ async function maybeAppendBrainUpdateReminder(deps, runtime, sessionID, messages
217496
217504
  await appendReceipt(join9(deps.stateDirectory, "context-log"), sessionID, receipt);
217497
217505
  return `${content}
217498
217506
 
217499
- ${brainUpdateReminder(deps.config.toolCallThreshold)}`;
217500
- }
217501
- function brainUpdateReminder(toolCallThreshold) {
217502
- return `<vcc-brain-brain-update-reminder>
217503
- You have completed ${toolCallThreshold} tool calls without a Brain change.
217504
- Before continuing, record any durable decisions, contracts, or lessons in the
217505
- appropriate Brain partition. Do not write transient task progress or restate
217506
- implementation. If nothing durable has emerged, make no Brain edits.
217507
- </vcc-brain-brain-update-reminder>`;
217507
+ ${brainUpdateReminderText(deps.config.toolCallThreshold)}`;
217508
217508
  }
217509
217509
 
217510
217510
  // src/utils.ts
@@ -217550,16 +217550,6 @@ function readOptionNumber(path, block, key, defaultValue) {
217550
217550
  }
217551
217551
  return success2(value);
217552
217552
  }
217553
- function readOptionString(path, block, key, defaultValue) {
217554
- const value = block[key];
217555
- if (value === undefined) {
217556
- return success2(defaultValue);
217557
- }
217558
- if (typeof value !== "string") {
217559
- return failure2({ message: `The "${path}.${key}" option must be a string.` });
217560
- }
217561
- return success2(value);
217562
- }
217563
217553
  function readOptionBoolean(path, block, key, defaultValue) {
217564
217554
  const value = block[key];
217565
217555
  if (value === undefined) {
@@ -219099,6 +219089,23 @@ ${JSON.stringify(event.data ?? null)}`;
219099
219089
  text
219100
219090
  };
219101
219091
  }
219092
+ function dropPhantomSeqZeroHits(out) {
219093
+ const hits = out.hits.filter((hit) => hit.seq !== 0);
219094
+ const dropped = out.hits.length - hits.length;
219095
+ const totalMatches = out.totalMatches - dropped;
219096
+ const omitted = Math.max(0, totalMatches - hits.length);
219097
+ const lines = [
219098
+ `[search "${out.pattern}": ${totalMatches} matching event(s)]`,
219099
+ ...hits.map((hit) => hit.text),
219100
+ ...omitted > 0 ? [`[${omitted} more matching event(s) omitted — narrow the pattern or use recall]`] : [],
219101
+ ...out.truncated ? ["[search budget exhausted; some hits were cut]"] : []
219102
+ ];
219103
+ if (hits.length > 0)
219104
+ lines.push("[use recall with a (seq N) pointer to restore any hit's full original content]");
219105
+ return { ...out, totalMatches, hits, omitted, text: lines.join(`
219106
+
219107
+ `) };
219108
+ }
219102
219109
 
219103
219110
  // src/compaction-snapshot.ts
219104
219111
  var SNAPSHOT_VERSION = 1;
@@ -219413,27 +219420,7 @@ function searchSnapshot(messages, patternSource, config = {}) {
219413
219420
  }
219414
219421
  };
219415
219422
  const out = searchSession(paddedSession, patternSource, { maxSearchHits, maxRecallTokens });
219416
- const hits = out.hits.filter((hit) => hit.seq !== 0);
219417
- const dropped = out.hits.length - hits.length;
219418
- const totalMatches = out.totalMatches - dropped;
219419
- const omitted = Math.max(0, totalMatches - hits.length);
219420
- const lines = [
219421
- `[search "${out.pattern}": ${totalMatches} matching event(s)]`,
219422
- ...hits.map((hit) => hit.text),
219423
- ...omitted > 0 ? [`[${omitted} more matching event(s) omitted — narrow the pattern or use recall]`] : [],
219424
- ...out.truncated ? ["[search budget exhausted; some hits were cut]"] : []
219425
- ];
219426
- if (hits.length > 0)
219427
- lines.push("[use recall with a (seq N) pointer to restore any hit's full original content]");
219428
- return {
219429
- ...out,
219430
- totalMatches,
219431
- hits,
219432
- omitted,
219433
- text: lines.join(`
219434
-
219435
- `)
219436
- };
219423
+ return dropPhantomSeqZeroHits(out);
219437
219424
  }
219438
219425
  function formatRecallReply(type, id, recalled) {
219439
219426
  const label = `**vcc-brain-recall ${type} ${id}** (${recalled.seqs.length} event(s), ${recalled.tokens} tokens` + `${recalled.missing > 0 ? `, ${recalled.missing} missing` : ""}` + `${recalled.truncated ? ", budget-truncated" : ""})`;
@@ -219911,12 +219898,8 @@ function countWords(text, maxWords) {
219911
219898
  import { join as join12 } from "node:path";
219912
219899
 
219913
219900
  // src/context-config.ts
219914
- function isFullContextMode(config) {
219915
- return config.mode === "full";
219916
- }
219917
219901
  var DEFAULT_CONTEXT_MANAGEMENT_CONFIG = {
219918
219902
  enabled: false,
219919
- mode: "full",
219920
219903
  ratio: 0.8,
219921
219904
  hardCapTokens: 250000,
219922
219905
  keepRecentTurns: 3,
@@ -219944,7 +219927,6 @@ function parseContextManagementBlock(block, base = DEFAULT_CONTEXT_MANAGEMENT_CO
219944
219927
  }
219945
219928
  const path = "vcc-brain.contextManagement";
219946
219929
  const enabled = readOptionBoolean(path, block, "enabled", base.enabled);
219947
- const mode = readOptionString(path, block, "mode", base.mode);
219948
219930
  const ratio = readOptionNumber(path, block, "ratio", base.ratio);
219949
219931
  const hardCapTokens = readOptionNumber(path, block, "hardCapTokens", base.hardCapTokens);
219950
219932
  const keepRecentTurns = readOptionNumber(path, block, "keepRecentTurns", base.keepRecentTurns);
@@ -219952,13 +219934,6 @@ function parseContextManagementBlock(block, base = DEFAULT_CONTEXT_MANAGEMENT_CO
219952
219934
  const compactFloorTokens = readOptionNumber(path, block, "compactFloorTokens", base.compactFloorTokens);
219953
219935
  if (!enabled.ok)
219954
219936
  return enabled;
219955
- if (!mode.ok)
219956
- return mode;
219957
- if (mode.value !== "full" && mode.value !== "vcc") {
219958
- return failure2({
219959
- message: `The "${path}.mode" option must be "full" or "vcc".`
219960
- });
219961
- }
219962
219937
  if (!ratio.ok)
219963
219938
  return ratio;
219964
219939
  if (!hardCapTokens.ok)
@@ -219971,7 +219946,6 @@ function parseContextManagementBlock(block, base = DEFAULT_CONTEXT_MANAGEMENT_CO
219971
219946
  return compactFloorTokens;
219972
219947
  return success2({
219973
219948
  enabled: enabled.value,
219974
- mode: mode.value,
219975
219949
  ratio: ratio.value,
219976
219950
  hardCapTokens: hardCapTokens.value,
219977
219951
  keepRecentTurns: keepRecentTurns.value,
@@ -219988,23 +219962,20 @@ function registerContextHook(context, deps, runtime) {
219988
219962
  }
219989
219963
  const sessionID = event.sessionID;
219990
219964
  const config = deps.config;
219991
- const fullMode = isFullContextMode(config);
219992
219965
  await ensureSessionHydrated(deps.stateDirectory, runtime, sessionID);
219993
219966
  if (!deps.isBrainAvailable(sessionID)) {
219994
219967
  await ensureRefusalReceipt(deps.stateDirectory, runtime, sessionID, deps);
219995
219968
  return;
219996
219969
  }
219997
219970
  const session = sessionRuntime(runtime, sessionID);
219998
- if (fullMode) {
219999
- if (isContextStale(deps)) {
220000
- return;
220001
- }
220002
- const remembered = await rememberSnapshot(join12(deps.stateDirectory, "context-snapshot"), sessionID, event.messages, new Date().toISOString(), session.snapshotSeen);
220003
- if (isContextStale(deps)) {
220004
- return;
220005
- }
220006
- session.snapshotSeen = remembered.seen;
219971
+ if (isContextStale(deps)) {
219972
+ return;
219973
+ }
219974
+ const remembered = await rememberSnapshot(join12(deps.stateDirectory, "context-snapshot"), sessionID, event.messages, new Date().toISOString(), session.snapshotSeen);
219975
+ if (isContextStale(deps)) {
219976
+ return;
220007
219977
  }
219978
+ session.snapshotSeen = remembered.seen;
220008
219979
  const estimatedTokens = estimateContextTokens(session.estimator, event.messages);
220009
219980
  const windowTokens = await resolveWindowTokens(context, session, event.model);
220010
219981
  session.lastEstimate = estimatedTokens;
@@ -221272,8 +221243,62 @@ async function refreshPreambleContent(deps, runtime, sessionID, projectDirectory
221272
221243
  }
221273
221244
 
221274
221245
  // src/tool.ts
221275
- import { execFile } from "node:child_process";
221276
221246
  import { join as join14 } from "node:path";
221247
+
221248
+ // ../core/src/helper-binary.ts
221249
+ import { execFile } from "node:child_process";
221250
+ var HELPER_BIN = "vcc-brain-helper";
221251
+ var HELPER_TIMEOUT_MS = 60000;
221252
+ var HELPER_MAX_BUFFER_BYTES = 4 * 1024 * 1024;
221253
+ function asAbortSignal(value) {
221254
+ if (typeof value !== "object" || value === null) {
221255
+ return;
221256
+ }
221257
+ const candidate = value;
221258
+ return typeof candidate.aborted === "boolean" && typeof candidate.addEventListener === "function" ? value : undefined;
221259
+ }
221260
+ function isBufferOverflow(error) {
221261
+ if (typeof error !== "object" || error === null || !("code" in error)) {
221262
+ return false;
221263
+ }
221264
+ const code = error.code;
221265
+ return code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER" || code === "ENOBUFS";
221266
+ }
221267
+ function runHelperBinary(argument_, options) {
221268
+ const bin = process.env.VCC_BRAIN_HELPER_BIN ?? HELPER_BIN;
221269
+ const signal = asAbortSignal(options?.signal);
221270
+ if (signal?.aborted === true) {
221271
+ return Promise.resolve({ exitCode: -1, output: "Helper call cancelled.", cancelled: true });
221272
+ }
221273
+ return new Promise((resolve) => {
221274
+ execFile(bin, [...argument_], { timeout: HELPER_TIMEOUT_MS, maxBuffer: HELPER_MAX_BUFFER_BYTES, signal }, (error, stdout, stderr) => {
221275
+ if (error !== null && (signal?.aborted === true || error.name === "AbortError")) {
221276
+ resolve({ exitCode: -1, output: "Helper call cancelled.", cancelled: true });
221277
+ return;
221278
+ }
221279
+ if (error === null) {
221280
+ resolve({ exitCode: 0, output: stdout, cancelled: false });
221281
+ return;
221282
+ }
221283
+ if (isBufferOverflow(error)) {
221284
+ resolve({
221285
+ exitCode: typeof error.code === "number" ? error.code : 2,
221286
+ output: `Helper output exceeded ${HELPER_MAX_BUFFER_BYTES} bytes and was discarded. ` + "Narrow the request (query keywords, recall --seq/--from-seq) and retry.",
221287
+ cancelled: false
221288
+ });
221289
+ return;
221290
+ }
221291
+ const exitCode = typeof error.code === "number" ? error.code : 2;
221292
+ if (exitCode !== 0 && stderr !== "") {
221293
+ resolve({ exitCode, output: stderr, cancelled: false });
221294
+ return;
221295
+ }
221296
+ resolve({ exitCode, output: stdout !== "" ? stdout : error.message, cancelled: false });
221297
+ });
221298
+ });
221299
+ }
221300
+
221301
+ // src/tool.ts
221277
221302
  var OMISSION_ID_PATTERN = /^omitted-\d+$/;
221278
221303
  var CONTEXT_MANAGEMENT_TOOL_NAMES = [
221279
221304
  "vcc-brain-read_omitted",
@@ -221480,30 +221505,12 @@ async function registerSearchTool(context, deps) {
221480
221505
  });
221481
221506
  });
221482
221507
  }
221483
- var HELPER_BIN = "vcc-brain-helper";
221484
- var HELPER_TIMEOUT_MS = 60000;
221485
- function runHelperBinary(argument_) {
221486
- return new Promise((resolve) => {
221487
- execFile(HELPER_BIN, [...argument_], { timeout: HELPER_TIMEOUT_MS }, (error, stdout, stderr) => {
221488
- if (error === null) {
221489
- resolve({ exitCode: 0, output: stdout });
221490
- return;
221491
- }
221492
- const exitCode = typeof error.code === "number" ? error.code : 2;
221493
- if (exitCode !== 0 && stderr !== "") {
221494
- resolve({ exitCode, output: stderr });
221495
- return;
221496
- }
221497
- resolve({ exitCode, output: stdout !== "" ? stdout : error.message });
221498
- });
221499
- });
221500
- }
221501
221508
  async function registerSearchSessionsTool(context, deps) {
221502
221509
  await context.tool.transform((editor) => {
221503
221510
  editor.add({
221504
221511
  name: "vcc-brain-search-sessions",
221505
221512
  options: { codemode: false },
221506
- description: "Search OTHER sessions (cross-session recall) for keywords, scoped to this project plus mutual peers. " + "Returns matching turns with stored session ids (like opencode:ses_... or dsh:<uuid>); " + "call vcc-brain-recall-session to restore a session's full turns. " + "Use vcc-brain-search (not this tool) for the current conversation. " + "OpenCode results require one `vcc-brain-helper recall-cross index` run on this machine first.",
221513
+ description: "Search OTHER sessions (cross-session recall) for keywords, scoped to this project plus mutual peers. " + "Returns matching turns with stored session ids (like opencode:ses_..., dsh:<uuid>, or pi:<id>); " + "call vcc-brain-recall-session to restore a session's full turns. " + "Use vcc-brain-search (not this tool) for the current conversation. " + "OpenCode results require one `vcc-brain-helper recall-cross index` run on this machine first.",
221507
221514
  input: {
221508
221515
  type: "object",
221509
221516
  properties: {
@@ -221514,7 +221521,7 @@ async function registerSearchSessionsTool(context, deps) {
221514
221521
  harness: {
221515
221522
  type: "string",
221516
221523
  description: "Limit results to one harness.",
221517
- enum: ["dsh", "opencode", "all"]
221524
+ enum: ["dsh", "opencode", "pi", "all"]
221518
221525
  }
221519
221526
  },
221520
221527
  required: ["keywords"]
@@ -221536,14 +221543,14 @@ async function registerSearchSessionsTool(context, deps) {
221536
221543
  deps.projectDirectory
221537
221544
  ];
221538
221545
  if (input.harness !== undefined && input.harness !== "") {
221539
- if (input.harness !== "dsh" && input.harness !== "opencode" && input.harness !== "all") {
221540
- return { content: "Invalid input: harness must be one of dsh, opencode, all." };
221546
+ if (input.harness !== "dsh" && input.harness !== "opencode" && input.harness !== "pi" && input.harness !== "all") {
221547
+ return { content: "Invalid input: harness must be one of dsh, opencode, pi, all." };
221541
221548
  }
221542
221549
  invocation.push("--harness", input.harness);
221543
221550
  }
221544
221551
  invocation.push(...words);
221545
221552
  try {
221546
- const result = await runHelperBinary(invocation);
221553
+ const result = await runHelperBinary(invocation, null);
221547
221554
  return { content: result.output };
221548
221555
  } catch {
221549
221556
  return { content: "Could not run the recall index. Is vcc-brain-helper installed?" };
@@ -221557,13 +221564,13 @@ async function registerRecallSessionTool(context) {
221557
221564
  editor.add({
221558
221565
  name: "vcc-brain-recall-session",
221559
221566
  options: { codemode: false },
221560
- description: "Restore the full turns of one indexed past session by its stored session id " + "(like opencode:ses_... or dsh:<uuid>), optionally a single turn by sequence number. " + "Use vcc-brain-recall (not this tool) for the current conversation.",
221567
+ description: "Restore the full turns of one indexed past session by its stored session id " + "(like opencode:ses_..., dsh:<uuid>, or pi:<id>), optionally a single turn by sequence number. " + "Use vcc-brain-recall (not this tool) for the current conversation.",
221561
221568
  input: {
221562
221569
  type: "object",
221563
221570
  properties: {
221564
221571
  sessionId: {
221565
221572
  type: "string",
221566
- description: "Stored session id, like opencode:ses_... or dsh:<uuid>."
221573
+ description: "Stored session id, like opencode:ses_..., dsh:<uuid>, or pi:<id>."
221567
221574
  },
221568
221575
  seq: {
221569
221576
  type: "string",
@@ -221591,7 +221598,7 @@ async function registerRecallSessionTool(context) {
221591
221598
  invocation.push("--seq", sequence);
221592
221599
  }
221593
221600
  try {
221594
- const result = await runHelperBinary(invocation);
221601
+ const result = await runHelperBinary(invocation, null);
221595
221602
  return { content: result.output };
221596
221603
  } catch {
221597
221604
  return { content: "Could not run the recall index. Is vcc-brain-helper installed?" };
@@ -221772,7 +221779,7 @@ var VccBrainPlugin = Plugin.define({
221772
221779
  const effectiveBrainUpdatesConfig = projectOverride.config.brainUpdates;
221773
221780
  const effectiveContextManagement = projectOverride.config.contextManagement;
221774
221781
  let contextManagementEnabled = parsed.ok && effectiveContextManagement.enabled;
221775
- if (contextManagementEnabled && isFullContextMode(effectiveContextManagement)) {
221782
+ if (contextManagementEnabled) {
221776
221783
  const external = await findExternalCompactionProvider(context);
221777
221784
  if (external !== null) {
221778
221785
  contextManagementEnabled = false;
@@ -221789,7 +221796,7 @@ var VccBrainPlugin = Plugin.define({
221789
221796
  const isActive = () => isCurrent() && !standDown.stoodDown;
221790
221797
  let providerRecheckDone = false;
221791
221798
  const maybeStandDownForExternalProvider = async () => {
221792
- if (!contextManagementEnabled || !isFullContextMode(effectiveContextManagement) || providerRecheckDone || !isCurrent()) {
221799
+ if (!contextManagementEnabled || providerRecheckDone || !isCurrent()) {
221793
221800
  return;
221794
221801
  }
221795
221802
  providerRecheckDone = true;
@@ -221900,7 +221907,6 @@ var VccBrainPlugin = Plugin.define({
221900
221907
  };
221901
221908
  const controller = new AbortController;
221902
221909
  if (contextManagementEnabled) {
221903
- const fullMode = isFullContextMode(config);
221904
221910
  const requestCompaction = (sessionID, cause) => {
221905
221911
  if (!isActive()) {
221906
221912
  return;
@@ -221916,28 +221922,24 @@ var VccBrainPlugin = Plugin.define({
221916
221922
  isCurrent: isActive
221917
221923
  };
221918
221924
  registerContextHook(context, deps, runtime);
221919
- if (fullMode) {
221920
- registerCompactionHook(context, {
221921
- config,
221922
- stateDirectory,
221923
- brainPaths: DEFAULT_BRAIN_PATHS,
221924
- isBrainAvailable,
221925
- reportReceiptFailure,
221926
- refreshEnabled: refreshConfig.enabled,
221927
- isCurrent: isActive,
221928
- onAnchorWritten: (sessionID) => {
221929
- cache.delete(sessionID);
221930
- }
221931
- }, runtime);
221932
- }
221925
+ registerCompactionHook(context, {
221926
+ config,
221927
+ stateDirectory,
221928
+ brainPaths: DEFAULT_BRAIN_PATHS,
221929
+ isBrainAvailable,
221930
+ reportReceiptFailure,
221931
+ refreshEnabled: refreshConfig.enabled,
221932
+ isCurrent: isActive,
221933
+ onAnchorWritten: (sessionID) => {
221934
+ cache.delete(sessionID);
221935
+ }
221936
+ }, runtime);
221933
221937
  registerCompletionTrigger(context, deps, runtime, { signal: controller.signal });
221934
221938
  await registerReadOmittedTool(context, { stateDirectory });
221935
221939
  await registerPruneTool(context, { stateDirectory });
221936
- if (fullMode) {
221937
- await registerRecallTool(context, { stateDirectory });
221938
- await registerSearchTool(context, { stateDirectory });
221939
- await registerAnchorTool(context, { stateDirectory, runtime });
221940
- }
221940
+ await registerRecallTool(context, { stateDirectory });
221941
+ await registerSearchTool(context, { stateDirectory });
221942
+ await registerAnchorTool(context, { stateDirectory, runtime });
221941
221943
  await registerSearchSessionsTool(context, {
221942
221944
  projectDirectory: context.location.directory
221943
221945
  });
@@ -221979,4 +221981,4 @@ export {
221979
221981
  src_default as default
221980
221982
  };
221981
221983
 
221982
- //# debugId=F31F250955F03E0F64756E2164756E21
221984
+ //# debugId=991AE20D1ACF66DE64756E2164756E21