@commonlyai/cli 0.1.359 → 0.1.361
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/package.json
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { observeSpawn, controlsFromArguments } from '../runtime-observation.js';
|
|
2
|
+
import { descendantsOf, killProcessTree, readProcessTable } from '@commonlyai/seats/process-group';
|
|
3
|
+
import { killStallSurvivors } from '../first-output-watchdog.js';
|
|
2
4
|
/**
|
|
3
5
|
* OpenCode adapter — wraps `opencode run --format json` as a Commonly seat.
|
|
4
6
|
*
|
|
@@ -1028,6 +1030,7 @@ const publicToolFailedError = ({ tool, error }) => {
|
|
|
1028
1030
|
|
|
1029
1031
|
const runOpenCode = ({
|
|
1030
1032
|
cmd, args, cwd, env, timeoutMs, credentials, spawnImpl = childSpawn, onSpawn, controls = {}, onFirstStep,
|
|
1033
|
+
terminationGraceMs = TERMINATION_GRACE_MS,
|
|
1031
1034
|
}) => new Promise((resolve, reject) => {
|
|
1032
1035
|
let proc;
|
|
1033
1036
|
try {
|
|
@@ -1041,10 +1044,26 @@ const runOpenCode = ({
|
|
|
1041
1044
|
let timedOut = false;
|
|
1042
1045
|
let killTimer = null;
|
|
1043
1046
|
const events = makeEventParser();
|
|
1047
|
+
// A timed-out turn is killed as a tree (F257): a child of OpenCode (a
|
|
1048
|
+
// launcher's real binary, an MCP server) that ignores SIGTERM would keep the
|
|
1049
|
+
// turn's stdout open, so close never fired and the turn never settled. The
|
|
1050
|
+
// descendants are snapshotted at SIGTERM, because one whose parent exits is
|
|
1051
|
+
// reparented and no tree walk from the spawn finds it again; any still alive
|
|
1052
|
+
// is SIGKILLed on close and at the grace (as claude.js does). At the grace,
|
|
1053
|
+
// dropping our ends of the pipes bounds the turn even if a holder was missed.
|
|
1054
|
+
let survivors = [];
|
|
1055
|
+
const sweepSurvivors = () => { if (survivors.length) killStallSurvivors(survivors); };
|
|
1044
1056
|
const timer = setTimeout(() => {
|
|
1045
1057
|
timedOut = true;
|
|
1046
|
-
proc.
|
|
1047
|
-
|
|
1058
|
+
const table = Number.isInteger(proc.pid) ? readProcessTable() : null;
|
|
1059
|
+
if (table) survivors = descendantsOf(table, proc.pid);
|
|
1060
|
+
killProcessTree(proc, 'SIGTERM', { table: () => table });
|
|
1061
|
+
killTimer = setTimeout(() => {
|
|
1062
|
+
killProcessTree(proc, 'SIGKILL');
|
|
1063
|
+
sweepSurvivors();
|
|
1064
|
+
proc.stdout?.destroy?.();
|
|
1065
|
+
proc.stderr?.destroy?.();
|
|
1066
|
+
}, terminationGraceMs);
|
|
1048
1067
|
}, timeoutMs);
|
|
1049
1068
|
const clearTimers = () => {
|
|
1050
1069
|
clearTimeout(timer);
|
|
@@ -1073,8 +1092,9 @@ const runOpenCode = ({
|
|
|
1073
1092
|
clearTimers();
|
|
1074
1093
|
reject(err);
|
|
1075
1094
|
});
|
|
1076
|
-
proc.on('close', (code) => {
|
|
1095
|
+
proc.on('close', (code, signal) => {
|
|
1077
1096
|
clearTimers();
|
|
1097
|
+
if (timedOut) sweepSurvivors();
|
|
1078
1098
|
events.flush();
|
|
1079
1099
|
if (stepHookError) return reject(stepHookError);
|
|
1080
1100
|
if (timedOut) return reject(new Error(`opencode timed out after ${timeoutMs}ms`));
|
|
@@ -1086,7 +1106,9 @@ const runOpenCode = ({
|
|
|
1086
1106
|
return reject(err);
|
|
1087
1107
|
}
|
|
1088
1108
|
if (code !== 0) {
|
|
1089
|
-
|
|
1109
|
+
// A signal exit has no code, so without its name a quiet death read as
|
|
1110
|
+
// just "opencode" (F257).
|
|
1111
|
+
const err = adapterFailure(code === null && signal ? `opencode ended on ${signal}` : 'opencode', stderr.trim(), {
|
|
1090
1112
|
credentials, exitCode: code, limit: 500,
|
|
1091
1113
|
});
|
|
1092
1114
|
err.staleSession = !events.turnOutput && STALE_SESSION_PATTERN.test(stderr);
|
|
@@ -1619,6 +1641,7 @@ export default {
|
|
|
1619
1641
|
cwd: ctx.cwd,
|
|
1620
1642
|
env: childEnv,
|
|
1621
1643
|
timeoutMs: ctx.timeoutMs || DEFAULT_TIMEOUT_MS,
|
|
1644
|
+
...(ctx._terminationGraceMs ? { terminationGraceMs: ctx._terminationGraceMs } : {}),
|
|
1622
1645
|
credentials,
|
|
1623
1646
|
spawnImpl, onSpawn: ctx.onSpawn, controls: controlsFromArguments(args.slice(0, -1), { modelFlag: '-m', effortFlag: '--variant', valueFlags: ['-s', '--dir', '--title', '--format'] }),
|
|
1624
1647
|
// CodeRabbit #3487, F460: a public seat's credential stops existing
|
|
@@ -73,7 +73,13 @@ export const publicCodexVersionError = ({ found, required, seat = 'public seat'
|
|
|
73
73
|
// `args` come before `--version`, for a launch that is an interpreter and a
|
|
74
74
|
// script (a Windows npm shim). The interpreter's path says nothing about which
|
|
75
75
|
// script it would run, so that probe is never cached.
|
|
76
|
+
//
|
|
77
|
+
// An entry also ages out after VERSION_CACHE_MAX_AGE_MS. A shim on PATH (asdf,
|
|
78
|
+
// mise, a wrapper script) keeps its mtime while the harness behind it changes,
|
|
79
|
+
// so an upgrade, or a downgrade under a version floor, would otherwise go
|
|
80
|
+
// unseen until the daemon restarted (F262).
|
|
76
81
|
const versionCache = new Map();
|
|
82
|
+
export const VERSION_CACHE_MAX_AGE_MS = 5 * 60 * 1000;
|
|
77
83
|
|
|
78
84
|
const resolveBinary = (binary, env) => {
|
|
79
85
|
const name = String(binary || '');
|
|
@@ -90,17 +96,18 @@ const resolveBinary = (binary, env) => {
|
|
|
90
96
|
|
|
91
97
|
export const probeVersion = async (binary, {
|
|
92
98
|
args = [], env, timeoutMs = 30000, parse, execFileImpl = childProcess.execFile, cache = versionCache,
|
|
99
|
+
now = Date.now,
|
|
93
100
|
} = {}) => {
|
|
94
101
|
const resolved = args.length ? null : resolveBinary(binary, env);
|
|
95
102
|
const key = resolved?.key || null;
|
|
96
103
|
const hit = key ? cache.get(key) : null;
|
|
97
|
-
if (hit && hit.mtimeMs === resolved.mtimeMs) return hit.version;
|
|
104
|
+
if (hit && hit.mtimeMs === resolved.mtimeMs && now() - hit.at < VERSION_CACHE_MAX_AGE_MS) return hit.version;
|
|
98
105
|
const stdout = await new Promise((resolve) => {
|
|
99
106
|
execFileImpl(key || binary, [...args, '--version'], { encoding: 'utf8', env, timeout: timeoutMs }, (error, out) => {
|
|
100
107
|
resolve(error ? null : out);
|
|
101
108
|
});
|
|
102
109
|
});
|
|
103
110
|
const version = stdout === null ? null : parse(stdout);
|
|
104
|
-
if (version && key) cache.set(key, { mtimeMs: resolved.mtimeMs, version });
|
|
111
|
+
if (version && key) cache.set(key, { mtimeMs: resolved.mtimeMs, version, at: now() });
|
|
105
112
|
return version;
|
|
106
113
|
};
|