billion-context-omp 0.2.1 → 0.2.2

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 CHANGED
@@ -4508,7 +4508,7 @@ async function statusReport(runtime, ctx) {
4508
4508
  const coveredIds = collectCoveredMessageIds(state);
4509
4509
  const sentTokens = estimateTokens(coreMessages, coveredIds) + systemPromptTokens;
4510
4510
  const turn = runtime.core.processTurn({ messages: coreMessages, state, config, tokenCount: sentTokens });
4511
- const versionStr = "0.2.1" ? `billion-context-omp@${"0.2.1"}` : void 0;
4511
+ const versionStr = "0.2.2" ? `billion-context-omp@${"0.2.2"}` : void 0;
4512
4512
  return buildStatusPanel({
4513
4513
  version: versionStr,
4514
4514
  tokenCount: sessionTokens,
@@ -5051,9 +5051,44 @@ function wireToolGuardrails(pi, runtime) {
5051
5051
  });
5052
5052
  }
5053
5053
 
5054
+ // src/instance-guard.ts
5055
+ import { readFileSync as readFileSync2, writeFileSync } from "fs";
5056
+ import { join as join4 } from "path";
5057
+ var MARKER_FILE = ".billion-context-omp-instance.json";
5058
+ var FRESH_MS = 6e4;
5059
+ function markerPath() {
5060
+ return join4(homeDir(), ".omp", MARKER_FILE);
5061
+ }
5062
+ function readMarker() {
5063
+ try {
5064
+ const raw = JSON.parse(readFileSync2(markerPath(), "utf8"));
5065
+ if (typeof raw?.path === "string" && typeof raw?.ts === "number") return raw;
5066
+ } catch {
5067
+ }
5068
+ return void 0;
5069
+ }
5070
+ function detectDualInstance(selfPath, now = Date.now()) {
5071
+ const m = readMarker();
5072
+ if (!m) return void 0;
5073
+ if (m.path === selfPath) return void 0;
5074
+ if (now - m.ts > FRESH_MS) return void 0;
5075
+ return m;
5076
+ }
5077
+ function stampInstance(selfPath, version, pid = process.pid, now = Date.now()) {
5078
+ try {
5079
+ writeFileSync(markerPath(), JSON.stringify({ path: selfPath, version, pid, ts: now }));
5080
+ } catch {
5081
+ }
5082
+ }
5083
+ function stampAndDetect(selfPath, version, now = Date.now()) {
5084
+ const conflict = detectDualInstance(selfPath, now);
5085
+ stampInstance(selfPath, version, void 0, now);
5086
+ return conflict;
5087
+ }
5088
+
5054
5089
  // src/update.ts
5055
5090
  import { readFile, writeFile as writeFile2, mkdir as mkdir2 } from "fs/promises";
5056
- import { join as join4, dirname as dirname3 } from "path";
5091
+ import { join as join5, dirname as dirname3 } from "path";
5057
5092
  import { fileURLToPath } from "url";
5058
5093
  import { execFile } from "child_process";
5059
5094
  import { CONFIG_DIR_NAME as CONFIG_DIR_NAME3 } from "@oh-my-pi/pi-utils";
@@ -5061,7 +5096,7 @@ var PACKAGE_NAME = "billion-context-omp";
5061
5096
  var REGISTRY_URL = `https://registry.npmjs.org/${PACKAGE_NAME}/latest`;
5062
5097
  var SEMVER_RE = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z-.]+)?$/;
5063
5098
  var CHECK_INTERVAL_MS = 3 * 60 * 1e3;
5064
- var throttleFile = () => join4(homeDir(), CONFIG_DIR_NAME3, ".billion-context-omp-update-check");
5099
+ var throttleFile = () => join5(homeDir(), CONFIG_DIR_NAME3, ".billion-context-omp-update-check");
5065
5100
  var updateInFlight = false;
5066
5101
  function parseVersion(v) {
5067
5102
  return v.replace(/^v/, "").split(".").map((n) => parseInt(n, 10) || 0);
@@ -5111,7 +5146,7 @@ function findNpmRoot(extDir) {
5111
5146
  async function findExtensionDir() {
5112
5147
  let dir = dirname3(fileURLToPath(import.meta.url));
5113
5148
  for (; ; ) {
5114
- const pkg = await readPackageJson(join4(dir, "package.json"));
5149
+ const pkg = await readPackageJson(join5(dir, "package.json"));
5115
5150
  if (pkg?.name === PACKAGE_NAME) return dir;
5116
5151
  const parent = dirname3(dir);
5117
5152
  if (parent === dir) return void 0;
@@ -5181,7 +5216,7 @@ async function checkForUpdate(autoUpdate, notify) {
5181
5216
  const data = await res.json();
5182
5217
  const latest = data.version;
5183
5218
  if (!latest) return;
5184
- const current = runtimeVersion ?? "0.2.1";
5219
+ const current = runtimeVersion ?? "0.2.2";
5185
5220
  const hasUpdate = isNewer(latest, current);
5186
5221
  debug.event("update-check", {
5187
5222
  current,
@@ -5211,12 +5246,12 @@ async function checkForUpdate(autoUpdate, notify) {
5211
5246
  async function getRuntimeVersion() {
5212
5247
  const extDir = await findExtensionDir();
5213
5248
  if (!extDir) return void 0;
5214
- const pkg = await readPackageJson(join4(extDir, "package.json"));
5249
+ const pkg = await readPackageJson(join5(extDir, "package.json"));
5215
5250
  return pkg?.version;
5216
5251
  }
5217
5252
 
5218
5253
  // src/dump.ts
5219
- import { mkdirSync as mkdirSync2, writeFileSync, readdirSync, unlinkSync } from "fs";
5254
+ import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2, readdirSync, unlinkSync } from "fs";
5220
5255
  import * as path2 from "path";
5221
5256
  import { CONFIG_DIR_NAME as CONFIG_DIR_NAME4 } from "@oh-my-pi/pi-utils";
5222
5257
  var counters = {};
@@ -5261,7 +5296,7 @@ function dumpContextMessages(messages, meta) {
5261
5296
  counters[dir] = seq + 1;
5262
5297
  const name = `${String(seq).padStart(4, "0")}.json`;
5263
5298
  const fullPath = path2.join(dir, name);
5264
- writeFileSync(
5299
+ writeFileSync2(
5265
5300
  fullPath,
5266
5301
  JSON.stringify({
5267
5302
  ts: (/* @__PURE__ */ new Date()).toISOString(),
@@ -5345,7 +5380,7 @@ function dumpProviderRequest(payload, meta) {
5345
5380
  const name = `req_${String(seq).padStart(4, "0")}.json`;
5346
5381
  const fullPath = path2.join(dir, name);
5347
5382
  const summary = summarizeProviderPayload(payload);
5348
- writeFileSync(
5383
+ writeFileSync2(
5349
5384
  fullPath,
5350
5385
  JSON.stringify({
5351
5386
  ts: (/* @__PURE__ */ new Date()).toISOString(),
@@ -5370,8 +5405,8 @@ import { CONFIG_DIR_NAME as CONFIG_DIR_NAME5 } from "@oh-my-pi/pi-utils";
5370
5405
  async function loadUserConfig(cwd) {
5371
5406
  const home = homeDir();
5372
5407
  const merged = {};
5373
- for (const base of [join7(home, CONFIG_DIR_NAME5), join7(cwd, CONFIG_DIR_NAME5)]) {
5374
- const file = join7(base, "acp-omp.json");
5408
+ for (const base of [join8(home, CONFIG_DIR_NAME5), join8(cwd, CONFIG_DIR_NAME5)]) {
5409
+ const file = join8(base, "acp-omp.json");
5375
5410
  const allowPrompts = base.startsWith(home);
5376
5411
  try {
5377
5412
  const raw = await fs.readFile(file, "utf8");
@@ -5389,7 +5424,7 @@ async function loadUserConfig(cwd) {
5389
5424
  }
5390
5425
  return merged;
5391
5426
  }
5392
- function join7(...parts) {
5427
+ function join8(...parts) {
5393
5428
  return path3.join(...parts);
5394
5429
  }
5395
5430
  var KNOWN = /* @__PURE__ */ new Set([
@@ -5497,7 +5532,18 @@ function wireCompactionDisable(pi, runtime) {
5497
5532
  function wireSessionLifecycle(pi, runtime) {
5498
5533
  pi.on("session_start", async (_event, ctx) => {
5499
5534
  const sid = ctx.sessionManager.getSessionId();
5500
- logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.2.1" : null });
5535
+ logInfo("session", { event: "start", sid, cwd: ctx.cwd, debug: runtime.adapter.debug ?? null, version: true ? "0.2.2" : null });
5536
+ const selfPath = import.meta.url;
5537
+ const conflict = stampAndDetect(selfPath, true ? "0.2.2" : null);
5538
+ if (conflict) {
5539
+ logWarn("instance", { event: "dual-instance", self: selfPath, other: conflict.path, otherPid: conflict.pid, otherVersion: conflict.version });
5540
+ try {
5541
+ if (ctx.hasUI) {
5542
+ ctx.ui.notify(`\u26A0 billion-context-omp loaded TWICE (also from ${conflict.path}). Two instances corrupt compression state \u2014 remove one (check 'omp plugin list' vs config.yml extensions).`);
5543
+ }
5544
+ } catch {
5545
+ }
5546
+ }
5501
5547
  try {
5502
5548
  const user = await loadUserConfig(ctx.cwd);
5503
5549
  runtime.setAdapter(applyUserConfig(runtime.adapter, user));