@commonlyai/cli 0.1.338 → 0.1.340
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
package/src/commands/agent.js
CHANGED
|
@@ -152,6 +152,7 @@ import {
|
|
|
152
152
|
cantAnswerNotice,
|
|
153
153
|
claudeSignedOutResult,
|
|
154
154
|
isClaudeSignedOut,
|
|
155
|
+
spawnFailureReason,
|
|
155
156
|
} from '../lib/turn-failure-notice.js';
|
|
156
157
|
import {
|
|
157
158
|
ADDRESSED_EVENT_TYPES,
|
|
@@ -3130,6 +3131,8 @@ export const performRun = ({
|
|
|
3130
3131
|
// D245 item 4: how long the runtime ran, for the reply receipt.
|
|
3131
3132
|
let spawnDurationMs;
|
|
3132
3133
|
let observedSpawn = false;
|
|
3134
|
+
// What a failed spawn threw, read only for its fixed reason code (F370 #11).
|
|
3135
|
+
let spawnFailure = null;
|
|
3133
3136
|
let commitAttribution = null;
|
|
3134
3137
|
try {
|
|
3135
3138
|
// The local CLI is a wrapper for a Commonly seat, so its Git commits
|
|
@@ -3213,6 +3216,7 @@ export const performRun = ({
|
|
|
3213
3216
|
try {
|
|
3214
3217
|
result = await turn.run(adapter, spawnPrompt, spawnCtx);
|
|
3215
3218
|
} catch (spawnError) {
|
|
3219
|
+
spawnFailure = spawnError;
|
|
3216
3220
|
await postModelUnavailableHint(spawnError, eventPodId, seatEnvironment?.model);
|
|
3217
3221
|
throw spawnError;
|
|
3218
3222
|
}
|
|
@@ -3223,13 +3227,19 @@ export const performRun = ({
|
|
|
3223
3227
|
// failure would be. With one, the turn delivered, and a retry would post twice.
|
|
3224
3228
|
if (result?.failure) {
|
|
3225
3229
|
const postSpawn = preSpawnIds ? await snapshotMessages() : null;
|
|
3226
|
-
if (!(postSpawn && findOwnPost(postSpawn, preSpawnIds)))
|
|
3230
|
+
if (!(postSpawn && findOwnPost(postSpawn, preSpawnIds))) {
|
|
3231
|
+
spawnFailure = result.failure;
|
|
3232
|
+
throw result.failure;
|
|
3233
|
+
}
|
|
3227
3234
|
log(`[${event.type}] the turn failed after a post of its own, so it is not retried: ${result.failure.message}`);
|
|
3228
3235
|
}
|
|
3229
3236
|
spawnCompleted = true;
|
|
3230
3237
|
} finally {
|
|
3231
3238
|
try {
|
|
3232
|
-
if (reportRuntime)
|
|
3239
|
+
if (reportRuntime) {
|
|
3240
|
+
await runtimeReporter.settled(observedSpawn ? spawnCompleted ? 'completed' : 'failed' : null,
|
|
3241
|
+
observedSpawn && !spawnCompleted ? spawnFailureReason(spawnFailure) : null);
|
|
3242
|
+
}
|
|
3233
3243
|
commitAttribution?.cleanup();
|
|
3234
3244
|
} finally {
|
|
3235
3245
|
if (spawnCompleted && skillMount) {
|
package/src/commands/daemon.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { collectRuntimeInventory } from '../lib/runtime-inventory.js';
|
|
1
|
+
import { collectRuntimeInventory, createInventoryCache } from '../lib/runtime-inventory.js';
|
|
2
2
|
/**
|
|
3
3
|
* commonly daemon <subcommand>
|
|
4
4
|
*
|
|
@@ -740,8 +740,7 @@ Examples:
|
|
|
740
740
|
// exit parks it on macOS; systemd honors 77 directly.
|
|
741
741
|
process.exitCode = saved || process.platform !== 'darwin' ? 77 : 0;
|
|
742
742
|
};
|
|
743
|
-
|
|
744
|
-
let inventoryCheckedAt = 0;
|
|
743
|
+
const runtimeInventory = createInventoryCache((harnesses) => collectRuntimeInventory(getAdapter, undefined, harnesses));
|
|
745
744
|
supervisor = createDaemonSupervisor({
|
|
746
745
|
record,
|
|
747
746
|
client,
|
|
@@ -767,13 +766,7 @@ Examples:
|
|
|
767
766
|
loadToken: loadAgentToken,
|
|
768
767
|
saveToken: saveAgentToken,
|
|
769
768
|
machineReport: daemonMachineReport,
|
|
770
|
-
runtimeInventory
|
|
771
|
-
if (!cachedInventory || Date.now() - inventoryCheckedAt > 300_000) {
|
|
772
|
-
cachedInventory = await collectRuntimeInventory(getAdapter);
|
|
773
|
-
inventoryCheckedAt = Date.now();
|
|
774
|
-
}
|
|
775
|
-
return cachedInventory;
|
|
776
|
-
},
|
|
769
|
+
runtimeInventory,
|
|
777
770
|
resolveAdapter: (runtime) => resolveAdapterForRuntime(runtime),
|
|
778
771
|
log: stampLog,
|
|
779
772
|
persistState: (seats) => saveDaemonState({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Probe only the walked adapter's version command. Never enumerate workspace
|
|
2
2
|
// extensions to discover models: a model picker must not execute project code.
|
|
3
3
|
export const WALKED_HARNESSES = ['claude', 'codex', 'opencode', 'hermes', 'dsh'];
|
|
4
|
-
export const collectRuntimeInventory = async (getAdapter, capabilities) => Promise.all(
|
|
4
|
+
export const collectRuntimeInventory = async (getAdapter, capabilities, harnesses = WALKED_HARNESSES) => Promise.all(harnesses.map(async (harness) => {
|
|
5
5
|
const adapter = getAdapter(harness);
|
|
6
6
|
let detected = null;
|
|
7
7
|
try { detected = await adapter?.detect(); } catch { /* unavailable */ }
|
|
@@ -10,3 +10,40 @@ export const collectRuntimeInventory = async (getAdapter, capabilities) => Promi
|
|
|
10
10
|
return { harness, installed: Boolean(detected), version: detected?.version || null,
|
|
11
11
|
models: choices.models, efforts: choices.efforts };
|
|
12
12
|
}));
|
|
13
|
+
|
|
14
|
+
// The daemon's inventory, refreshed in full every five minutes. A harness it
|
|
15
|
+
// didn't find is probed again sooner, so one installed while the BYO page is
|
|
16
|
+
// open shows up within a heartbeat or two, without a reload (F370 #8).
|
|
17
|
+
// Probes are synchronous: a binary that isn't there fails at once, but one
|
|
18
|
+
// that's there and hangs on --version blocks the daemon for its timeout. A
|
|
19
|
+
// re-probe slower than INVENTORY_SLOW_MS waits for the full refresh instead.
|
|
20
|
+
export const INVENTORY_FULL_MS = 300_000;
|
|
21
|
+
export const INVENTORY_MISSING_MS = 25_000;
|
|
22
|
+
export const INVENTORY_SLOW_MS = 1_000;
|
|
23
|
+
export const createInventoryCache = (collect, { now = Date.now } = {}) => {
|
|
24
|
+
let cached;
|
|
25
|
+
let fullAt = 0;
|
|
26
|
+
let missingAt = 0;
|
|
27
|
+
let slow = new Set();
|
|
28
|
+
return async () => {
|
|
29
|
+
const at = now();
|
|
30
|
+
if (!cached || at - fullAt > INVENTORY_FULL_MS) {
|
|
31
|
+
cached = await collect(WALKED_HARNESSES);
|
|
32
|
+
fullAt = at;
|
|
33
|
+
missingAt = at;
|
|
34
|
+
slow = new Set();
|
|
35
|
+
return cached;
|
|
36
|
+
}
|
|
37
|
+
const missing = cached.filter((row) => !row.installed && !slow.has(row.harness)).map((row) => row.harness);
|
|
38
|
+
if (missing.length && at - missingAt > INVENTORY_MISSING_MS) {
|
|
39
|
+
missingAt = at;
|
|
40
|
+
for (const harness of missing) {
|
|
41
|
+
const started = now();
|
|
42
|
+
const [fresh] = await collect([harness]);
|
|
43
|
+
if (now() - started > INVENTORY_SLOW_MS) slow.add(harness);
|
|
44
|
+
if (fresh) cached = cached.map((row) => (row.harness === harness ? fresh : row));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return cached;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -22,6 +22,16 @@ export const createRuntimeReporter = ({ client, harness, detect }) => {
|
|
|
22
22
|
}).catch(() => {});
|
|
23
23
|
return queue;
|
|
24
24
|
},
|
|
25
|
-
|
|
25
|
+
// A failed spawn carries its reason code (F370 #11). A backend from before
|
|
26
|
+
// the field refuses the whole report with a 400, so it's sent once more
|
|
27
|
+
// without the reason, and the outcome still lands.
|
|
28
|
+
settled: (outcome = null, reason = null) => {
|
|
29
|
+
const body = { event: 'settled', ...(outcome ? { outcome } : {}) };
|
|
30
|
+
if (!(outcome === 'failed' && reason)) return send(body);
|
|
31
|
+
queue = queue.then(() => client.post('/api/agents/runtime/observation', { ...body, reason })
|
|
32
|
+
.catch((error) => (error?.status === 400 ? client.post('/api/agents/runtime/observation', body) : undefined)))
|
|
33
|
+
.catch(() => {});
|
|
34
|
+
return queue;
|
|
35
|
+
},
|
|
26
36
|
};
|
|
27
37
|
};
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
import { PUBLIC_MCP_NOT_READY_CODE, PUBLIC_TOOL_FAILED_CODE } from './public-tool-error.js';
|
|
19
19
|
import { PUBLIC_CODEX_VERSION_CODE } from './adapters/tested-version.js';
|
|
20
20
|
import { classifySpawnFailure, GATEWAY_BUDGET_RE, SPAWN_FAILURE_CLASS } from './spawn-retry.js';
|
|
21
|
+
import { modelUnavailableFailure } from './model-unavailable.js';
|
|
21
22
|
|
|
22
23
|
/** How long one cause stays posted in a pod before the seat may post it again. */
|
|
23
24
|
export const CANT_ANSWER_NOTICE_WINDOW_MS = 60 * 60 * 1000;
|
|
@@ -139,6 +140,24 @@ export const cantAnswerNotice = (error) => {
|
|
|
139
140
|
return null;
|
|
140
141
|
};
|
|
141
142
|
|
|
143
|
+
// F370 rough spot #11: Settings said "spawn failed" and nothing more; the cause
|
|
144
|
+
// was only in the seat's log. The runner reports one of these fixed codes with
|
|
145
|
+
// a failed outcome, never the error text. The server stores the code alone.
|
|
146
|
+
export const SPAWN_FAILURE_REASONS = [
|
|
147
|
+
'claude-signed-out', 'login', 'wont-start', 'out-of-allowance', 'tools-unavailable', 'codex-version', 'model-unavailable',
|
|
148
|
+
];
|
|
149
|
+
// A shell's "found but can't run it" exit, on the adapter's own exit line.
|
|
150
|
+
const NOT_EXECUTABLE_EXIT = /^\w+ exited(?: with code)? 126\b/;
|
|
151
|
+
|
|
152
|
+
/** The failed spawn's reason code, or null when no known cause matches. */
|
|
153
|
+
export const spawnFailureReason = (error) => {
|
|
154
|
+
if (!error) return null;
|
|
155
|
+
if (modelUnavailableFailure(error)) return 'model-unavailable';
|
|
156
|
+
const cause = cantAnswerNotice(error)?.cause;
|
|
157
|
+
if (SPAWN_FAILURE_REASONS.includes(cause)) return cause;
|
|
158
|
+
return NOT_EXECUTABLE_EXIT.test(String(error.message ?? '')) ? 'wont-start' : null;
|
|
159
|
+
};
|
|
160
|
+
|
|
142
161
|
/**
|
|
143
162
|
* A turn that failed because Claude Code is signed out on this computer (F436).
|
|
144
163
|
* It is a setup fault, not an outage: retrying cannot fix it, and holding the
|