@codemem/opencode-plugin 0.49.0-beta.7 → 0.49.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.
|
@@ -117,7 +117,7 @@ export const probeCliCandidate = async ({ path, nodePath, expectedVersion, boots
|
|
|
117
117
|
try {
|
|
118
118
|
const candidate = readCandidate(location.manifestPath, { nodePath, expectedVersion, executable: location.executable });
|
|
119
119
|
const result = await executeFile(candidate.command, [...candidate.args, "--version"], {
|
|
120
|
-
timeout: remaining, maxBuffer: MAX_OUTPUT_BYTES, killSignal: "SIGKILL",
|
|
120
|
+
timeout: remaining, maxBuffer: MAX_OUTPUT_BYTES, killSignal: "SIGKILL", windowsHide: true,
|
|
121
121
|
});
|
|
122
122
|
if (result.stdout.trim() === candidate.version && isCachedCliCurrent(candidate)) return candidate;
|
|
123
123
|
} catch { /* An unusable candidate must not select an unverified command. */ }
|
|
@@ -128,7 +128,7 @@ export const probeCliCandidate = async ({ path, nodePath, expectedVersion, boots
|
|
|
128
128
|
const runProbe = async ({ command, args, cwd, env, timeout, execute, expectedVersion }) => {
|
|
129
129
|
try {
|
|
130
130
|
const result = await execute(command, args, {
|
|
131
|
-
cwd, env, timeout, maxBuffer: MAX_OUTPUT_BYTES, killSignal: "SIGKILL",
|
|
131
|
+
cwd, env, timeout, maxBuffer: MAX_OUTPUT_BYTES, killSignal: "SIGKILL", windowsHide: true,
|
|
132
132
|
});
|
|
133
133
|
const candidate = JSON.parse(result.stdout);
|
|
134
134
|
if (!candidate || !isAbsolute(candidate.command) || candidate.args?.length !== 1
|
|
@@ -118,7 +118,9 @@ export const runChildCommand = (cmd, options = {}, defaults = {}) => {
|
|
|
118
118
|
resolve({ exitCode: null, stdout: "", stderr: "aborted", aborted: true });
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
|
-
const proc = nodeSpawn(command, args, {
|
|
121
|
+
const proc = nodeSpawn(command, args, {
|
|
122
|
+
cwd, env, stdio: ["pipe", "pipe", "pipe"], windowsHide: true,
|
|
123
|
+
});
|
|
122
124
|
const output = collectOutput(proc);
|
|
123
125
|
const stdinFailure = writeStdin(proc, stdinText);
|
|
124
126
|
if (stdinFailure) {
|
package/.opencode/lib/compat.js
CHANGED
|
@@ -90,13 +90,22 @@ export const parseBackendUpdatePolicy = (value) => {
|
|
|
90
90
|
return "notify";
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
+
// Same result as /@[^/]+$/.test(value) without the regex, which backtracks
|
|
94
|
+
// quadratically on long "@" runs: some "@" in the last path segment must be
|
|
95
|
+
// followed by at least one character.
|
|
96
|
+
const endsWithRefSuffix = (value) => {
|
|
97
|
+
const refStart = value.indexOf("@", value.lastIndexOf("/") + 1);
|
|
98
|
+
return refStart !== -1 && refStart < value.length - 1;
|
|
99
|
+
};
|
|
100
|
+
|
|
93
101
|
const isPinnedGitSource = (runnerFrom) => {
|
|
94
102
|
const source = String(runnerFrom || "").trim();
|
|
95
103
|
if (!source) return false;
|
|
96
104
|
if (!(source.startsWith("git+") || source.includes(".git"))) {
|
|
97
105
|
return false;
|
|
98
106
|
}
|
|
99
|
-
const
|
|
107
|
+
const queryStart = source.search(/[?#]/);
|
|
108
|
+
const withoutQuery = queryStart === -1 ? source : source.slice(0, queryStart);
|
|
100
109
|
if (withoutQuery.includes(".git@")) {
|
|
101
110
|
return true;
|
|
102
111
|
}
|
|
@@ -110,9 +119,9 @@ const isPinnedGitSource = (runnerFrom) => {
|
|
|
110
119
|
if (path.includes(".git@")) {
|
|
111
120
|
return true;
|
|
112
121
|
}
|
|
113
|
-
return
|
|
122
|
+
return endsWithRefSuffix(path);
|
|
114
123
|
} catch {
|
|
115
|
-
return
|
|
124
|
+
return endsWithRefSuffix(withoutQuery);
|
|
116
125
|
}
|
|
117
126
|
};
|
|
118
127
|
|
|
@@ -92,6 +92,7 @@ const createDeliveryState = (options) => ({
|
|
|
92
92
|
lastStatusCheckAt: 0,
|
|
93
93
|
latestViewerFailure: null,
|
|
94
94
|
lastToastAtBySession: new Map(),
|
|
95
|
+
identityMismatch: false,
|
|
95
96
|
options,
|
|
96
97
|
retainedPayloads: new WeakSet(),
|
|
97
98
|
spoolDirectory: resolveSpoolDirectory(options.spoolHome),
|
|
@@ -344,6 +345,29 @@ const armViewerBackoff = (state, error, timing) => {
|
|
|
344
345
|
return viewerFailure;
|
|
345
346
|
};
|
|
346
347
|
|
|
348
|
+
const isIdentityMismatchFailure = (error) =>
|
|
349
|
+
error?.rawEventFailure?.cause === "viewer_identity_mismatch";
|
|
350
|
+
|
|
351
|
+
const pauseForIdentityMismatch = async (state) => {
|
|
352
|
+
if (state.identityMismatch) return;
|
|
353
|
+
state.identityMismatch = true;
|
|
354
|
+
if (!state.options.isActive()) return;
|
|
355
|
+
const message = "codemem capture delivery paused: viewer identity mismatch; align CODEMEM_* settings, then restart the viewer and OpenCode to resume saved events";
|
|
356
|
+
const diagnostic = `raw_events.delivery.paused code=viewer_identity_mismatch category=identity ${message}`;
|
|
357
|
+
try {
|
|
358
|
+
await persistSafeSpoolDiagnostic(state, diagnostic);
|
|
359
|
+
} catch {
|
|
360
|
+
// The host warning still explains recovery when the default log is unavailable.
|
|
361
|
+
}
|
|
362
|
+
await bestEffortHostLog(state, {
|
|
363
|
+
service: "codemem",
|
|
364
|
+
level: "error",
|
|
365
|
+
message,
|
|
366
|
+
extra: { category: "identity", code: "viewer_identity_mismatch" },
|
|
367
|
+
});
|
|
368
|
+
await bestEffortNotify(state, { message, variant: "error" });
|
|
369
|
+
};
|
|
370
|
+
|
|
347
371
|
const warnRejectedEntry = async (state, { rejection, outcome, sessionID }) => {
|
|
348
372
|
const messages = {
|
|
349
373
|
retained: "codemem retained a rejected raw event; inspect it with codemem diagnostics capture list-rejected",
|
|
@@ -386,6 +410,24 @@ const retainRejectedEntry = async (state, { eventId, rejection, sessionID, paylo
|
|
|
386
410
|
}
|
|
387
411
|
};
|
|
388
412
|
|
|
413
|
+
const handleDrainFailure = async (state, entry, error, startedAt) => {
|
|
414
|
+
if (isIdentityMismatchFailure(error)) {
|
|
415
|
+
await pauseForIdentityMismatch(state);
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
if (error?.rawEventTerminalRejection) {
|
|
419
|
+
await retainRejectedEntry(state, { eventId: entry.eventId, rejection: error.rawEventTerminalRejection });
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
await state.options.logLine("raw_events.spool.drain_deferred category=fallback");
|
|
423
|
+
const status = error?.rawEventFailure?.status;
|
|
424
|
+
if (!Number.isInteger(status) || status >= 500 || status === 409) {
|
|
425
|
+
armViewerBackoff(state, error, { stage: "post", startedAt });
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
return true;
|
|
429
|
+
};
|
|
430
|
+
|
|
389
431
|
const drainLoadedEntries = async (state, loaded) => {
|
|
390
432
|
if (loaded.corruptCount > 0) {
|
|
391
433
|
await state.options.logLine(`raw_events.spool.corrupt_retained count=${loaded.corruptCount}`);
|
|
@@ -394,21 +436,14 @@ const drainLoadedEntries = async (state, loaded) => {
|
|
|
394
436
|
state.spoolCorruptionNoted = false;
|
|
395
437
|
}
|
|
396
438
|
for (const entry of loaded.entries) {
|
|
439
|
+
if (state.identityMismatch) break;
|
|
397
440
|
const viewerStartedAt = Date.now();
|
|
398
441
|
try {
|
|
399
442
|
await postToViewer(state, entry.envelope);
|
|
400
443
|
await removeFromSpool(state, { eventId: entry.eventId });
|
|
401
444
|
} catch (error) {
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
continue;
|
|
405
|
-
}
|
|
406
|
-
await state.options.logLine("raw_events.spool.drain_deferred category=fallback");
|
|
407
|
-
const status = error?.rawEventFailure?.status;
|
|
408
|
-
if (!Number.isInteger(status) || status >= 500 || status === 409) {
|
|
409
|
-
armViewerBackoff(state, error, { stage: "post", startedAt: viewerStartedAt });
|
|
410
|
-
break;
|
|
411
|
-
}
|
|
445
|
+
const canContinue = await handleDrainFailure(state, entry, error, viewerStartedAt);
|
|
446
|
+
if (!canContinue) break;
|
|
412
447
|
}
|
|
413
448
|
}
|
|
414
449
|
};
|
|
@@ -420,6 +455,7 @@ const runSpoolDrain = async (state) => {
|
|
|
420
455
|
|
|
421
456
|
const drainSpool = (state) => {
|
|
422
457
|
if (!state.options.enabled) return Promise.resolve();
|
|
458
|
+
if (state.identityMismatch) return Promise.resolve();
|
|
423
459
|
if (Date.now() < state.streamUnavailableUntil) return Promise.resolve();
|
|
424
460
|
const existingDrain = rawEventSpoolDrainsInFlight.get(state.spoolDirectory);
|
|
425
461
|
if (existingDrain) return existingDrain;
|
|
@@ -533,28 +569,40 @@ const postToViewer = async (state, body) => {
|
|
|
533
569
|
cause: "http_status",
|
|
534
570
|
status: response.status,
|
|
535
571
|
};
|
|
572
|
+
if (response.status === 409 && responseBody?.error?.code === "viewer_identity_mismatch") {
|
|
573
|
+
error.rawEventFailure.cause = "viewer_identity_mismatch";
|
|
574
|
+
}
|
|
536
575
|
throw error;
|
|
537
576
|
};
|
|
538
577
|
|
|
578
|
+
const persistRejectedDelivery = async (state, input, rejection) => {
|
|
579
|
+
const durable = await persistForRetry(state, input);
|
|
580
|
+
if (durable) {
|
|
581
|
+
const canonical = input.payload && typeof input.payload === "object"
|
|
582
|
+
? state.envelopes.get(input.payload) : null;
|
|
583
|
+
// A size rejection proves only the posted copy was too large. Retry changed saved bytes first.
|
|
584
|
+
if (rejection.status === 413
|
|
585
|
+
&& canonical && canonical.serialized !== input.serialized) return durable;
|
|
586
|
+
await retainRejectedEntry(state, {
|
|
587
|
+
eventId: input.body.event_id,
|
|
588
|
+
rejection,
|
|
589
|
+
sessionID: input.sessionID,
|
|
590
|
+
payload: input.payload,
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
return durable;
|
|
594
|
+
};
|
|
595
|
+
|
|
539
596
|
const handleViewerFailure = async (state, input, error, timing) => {
|
|
597
|
+
if (isIdentityMismatchFailure(error)) {
|
|
598
|
+
await pauseForIdentityMismatch(state);
|
|
599
|
+
return persistForRetry(state, input);
|
|
600
|
+
}
|
|
540
601
|
if (error?.rawEventTerminalRejection) {
|
|
541
|
-
|
|
542
|
-
if (durable) {
|
|
543
|
-
const canonical = input.payload && typeof input.payload === "object"
|
|
544
|
-
? state.envelopes.get(input.payload) : null;
|
|
545
|
-
// A size rejection proves only the posted copy was too large. Retry changed saved bytes first.
|
|
546
|
-
if (error.rawEventTerminalRejection.status === 413
|
|
547
|
-
&& canonical && canonical.serialized !== input.serialized) return durable;
|
|
548
|
-
await retainRejectedEntry(state, {
|
|
549
|
-
eventId: input.body.event_id,
|
|
550
|
-
rejection: error.rawEventTerminalRejection,
|
|
551
|
-
sessionID: input.sessionID,
|
|
552
|
-
payload: input.payload,
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
return durable;
|
|
602
|
+
return persistRejectedDelivery(state, input, error.rawEventTerminalRejection);
|
|
556
603
|
}
|
|
557
604
|
if (!state.options.isActive()) return persistForRetry(state, input);
|
|
605
|
+
if (state.identityMismatch) return persistForRetry(state, input);
|
|
558
606
|
const category = error?.rawEventFailureCategory || "connection";
|
|
559
607
|
const viewerFailure = armViewerBackoff(state, error, timing);
|
|
560
608
|
await state.options.logLine(
|
|
@@ -584,11 +632,13 @@ const deliver = async (state, { sessionID, type, payload }) => {
|
|
|
584
632
|
const envelope = cachedEnvelope(state, sessionID, type, payload, now);
|
|
585
633
|
const input = { ...envelope, payload, sessionID };
|
|
586
634
|
if (!state.options.isActive()) return persistForRetry(state, input);
|
|
635
|
+
if (state.identityMismatch) return persistForRetry(state, input);
|
|
587
636
|
if (now < state.streamUnavailableUntil) return deliverDuringBackoff(state, input);
|
|
588
637
|
const viewerStartedAt = Date.now();
|
|
589
638
|
let viewerStage = "status";
|
|
590
639
|
try {
|
|
591
640
|
await checkViewerAvailability(state, now);
|
|
641
|
+
if (state.identityMismatch) return persistForRetry(state, input);
|
|
592
642
|
viewerStage = "post";
|
|
593
643
|
await postToViewer(state, envelope.body);
|
|
594
644
|
state.streamUnavailableUntil = 0;
|
package/.opencode/lib/runtime.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execSync, spawn as nodeSpawn } from "node:child_process";
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
4
|
import { appendFile, mkdir } from "node:fs/promises";
|
|
5
5
|
import { homedir } from "node:os";
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
|
|
39
39
|
const TRUTHY_VALUES = ["1", "true", "yes"];
|
|
40
40
|
const DISABLED_VALUES = ["0", "false", "off"];
|
|
41
|
-
const PINNED_BACKEND_VERSION = "0.49.
|
|
41
|
+
const PINNED_BACKEND_VERSION = "0.49.1";
|
|
42
42
|
const COMPAT_CHECK_DELAY_MS = 1500;
|
|
43
43
|
const COMPAT_CHECK_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
44
44
|
const MAX_UPDATE_STATUS_BYTES = 16 * 1024;
|
|
@@ -2218,6 +2218,7 @@ const detectRunner = ({ cwd, envRunner }) => {
|
|
|
2218
2218
|
// catch below falls back to npx. Without this, stderr leaks to the
|
|
2219
2219
|
// terminal on every OpenCode startup for npx-only installs.
|
|
2220
2220
|
stdio: ["ignore", "pipe", "ignore"],
|
|
2221
|
+
windowsHide: true,
|
|
2221
2222
|
}).trim();
|
|
2222
2223
|
// Use a newer global CLI only when it remains on the plugin's release
|
|
2223
2224
|
// channel. This prevents both channel crossing and fallback to an older pin
|
|
@@ -2555,12 +2556,7 @@ export const createCodememRuntime = async ({ location, host, hostGeneration = nu
|
|
|
2555
2556
|
let rawEventDeliveryCount = 0;
|
|
2556
2557
|
let flushDeliveryTail = Promise.resolve();
|
|
2557
2558
|
let promptPackTransportUnavailableUntil = 0;
|
|
2558
|
-
const nextEventId = () =>
|
|
2559
|
-
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
2560
|
-
return crypto.randomUUID();
|
|
2561
|
-
}
|
|
2562
|
-
return `${Date.now()}-${Math.random()}`;
|
|
2563
|
-
};
|
|
2559
|
+
const nextEventId = () => randomUUID();
|
|
2564
2560
|
|
|
2565
2561
|
const buildViewerCliArgs = createViewerCliArgs({ viewerHost, viewerPort, viewerDbPath, viewerConfigPath });
|
|
2566
2562
|
|
|
@@ -2904,7 +2900,7 @@ export const createCodememRuntime = async ({ location, host, hostGeneration = nu
|
|
|
2904
2900
|
cwd,
|
|
2905
2901
|
env: process.env,
|
|
2906
2902
|
detached: true,
|
|
2907
|
-
stdio: "ignore",
|
|
2903
|
+
stdio: "ignore", windowsHide: true,
|
|
2908
2904
|
});
|
|
2909
2905
|
child.once("spawn", () => {
|
|
2910
2906
|
viewerStarted = true;
|
|
@@ -3885,7 +3881,7 @@ export const createCodememRuntime = async ({ location, host, hostGeneration = nu
|
|
|
3885
3881
|
encoding: "utf-8",
|
|
3886
3882
|
// Suppress "fatal: not a git repository" when the working directory is
|
|
3887
3883
|
// not a git repo. The catch below leaves version as "unknown".
|
|
3888
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
3884
|
+
stdio: ["ignore", "pipe", "ignore"], windowsHide: true,
|
|
3889
3885
|
}).trim();
|
|
3890
3886
|
} catch {
|
|
3891
3887
|
// Ignore - version will remain 'unknown'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codemem/opencode-plugin",
|
|
3
|
-
"version": "0.49.
|
|
3
|
+
"version": "0.49.1",
|
|
4
4
|
"description": "CodeMem plugin for OpenCode",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@babel/parser": "8.1.0",
|
|
43
43
|
"@opencode/cli": "2.0.24",
|
|
44
44
|
"@types/node": "^24.12.4",
|
|
45
|
-
"codemem": "^0.49.
|
|
45
|
+
"codemem": "^0.49.1",
|
|
46
46
|
"vitest": "^4.1.11"
|
|
47
47
|
},
|
|
48
48
|
"repository": {
|