@commonlyai/cli 0.1.118 → 0.1.119
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
|
@@ -51,6 +51,8 @@ import { detectBwrap, wrapArgvWithBwrap } from '../sandbox/bwrap.js';
|
|
|
51
51
|
import { wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
|
|
52
52
|
import { resolvePublicSandboxMode } from '../sandbox/mode.js';
|
|
53
53
|
import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js';
|
|
54
|
+
import { isShippedCommonlyMcpCommand } from '../declared-mcp-guard.js';
|
|
55
|
+
import { isAnswerableToolError } from '../public-tool-error.js';
|
|
54
56
|
|
|
55
57
|
const DEFAULT_TIMEOUT_MS = 15 * 60 * 1000;
|
|
56
58
|
const TERMINATION_GRACE_MS = 5000;
|
|
@@ -297,6 +299,9 @@ const makeEventParser = () => {
|
|
|
297
299
|
let text = '';
|
|
298
300
|
let usage = null;
|
|
299
301
|
let errorMessage = null;
|
|
302
|
+
// Every tool call that came back as an error, for the public-seat check in
|
|
303
|
+
// spawn (publicToolFailure).
|
|
304
|
+
const toolErrors = [];
|
|
300
305
|
const consumeLine = (line) => {
|
|
301
306
|
if (!line.trim()) return;
|
|
302
307
|
try {
|
|
@@ -306,6 +311,12 @@ const makeEventParser = () => {
|
|
|
306
311
|
text += event.part.text;
|
|
307
312
|
} else if (event.type === 'step_finish' && event.part?.tokens) {
|
|
308
313
|
usage = event.part.tokens;
|
|
314
|
+
} else if (event.type === 'tool_use' && event.part?.state?.status === 'error') {
|
|
315
|
+
const { error } = event.part.state;
|
|
316
|
+
toolErrors.push({
|
|
317
|
+
tool: String(event.part.tool || ''),
|
|
318
|
+
error: typeof error === 'string' ? error : JSON.stringify(error ?? ''),
|
|
319
|
+
});
|
|
309
320
|
} else if (event.type === 'error') {
|
|
310
321
|
errorMessage = event.error?.data?.message || event.error?.message || 'OpenCode turn failed';
|
|
311
322
|
}
|
|
@@ -332,9 +343,50 @@ const makeEventParser = () => {
|
|
|
332
343
|
get text() { return text; },
|
|
333
344
|
get usage() { return usage; },
|
|
334
345
|
get errorMessage() { return errorMessage; },
|
|
346
|
+
get toolErrors() { return toolErrors; },
|
|
335
347
|
};
|
|
336
348
|
};
|
|
337
349
|
|
|
350
|
+
// A public seat must never show a stranger its own plumbing. When a Commonly
|
|
351
|
+
// tool can't reach the API, the model is left narrating the failure, and the
|
|
352
|
+
// run loop posted that narration: on 2026-10-21 a canary of Commonly HQ's
|
|
353
|
+
// support seat (this adapter, its prompt, an unreachable API) told the asker
|
|
354
|
+
// "every Commonly tool call (`list_pods`, `list_artifacts`) is returning
|
|
355
|
+
// `fetch failed`", and an instruction to answer NO_REPLY in that case held in
|
|
356
|
+
// only 1 of 3 turns. So the turn is withheld here instead: nothing is posted,
|
|
357
|
+
// and the run loop keeps the event unacked for its retry.
|
|
358
|
+
//
|
|
359
|
+
// OpenCode names an MCP tool `<server>_<tool>`, and a failed call reports
|
|
360
|
+
// `state.status: 'error'` with the message in `state.error` (measured on
|
|
361
|
+
// OpenCode 1.19.0). Only tools of the declared Commonly server count. Of
|
|
362
|
+
// those, only the errors `isAnswerableToolError` names (an API refusal the
|
|
363
|
+
// person can be told about, or a schema mistake the model fixes) leave the
|
|
364
|
+
// turn to be posted; any other failure withholds it. This adapter-level check
|
|
365
|
+
// stays beside the adapter-agnostic readiness witness (TASK-256): it sees the
|
|
366
|
+
// runtime's own view of each call, and the witness sees a server that never
|
|
367
|
+
// started, so each catches what the other cannot.
|
|
368
|
+
export const PUBLIC_TOOL_FAILED_CODE = 'public_tool_failed';
|
|
369
|
+
|
|
370
|
+
export const publicToolFailure = (toolErrors, mcpServers) => {
|
|
371
|
+
const prefixes = (Array.isArray(mcpServers) ? mcpServers : [])
|
|
372
|
+
.filter((server) => server?.name && isShippedCommonlyMcpCommand(server.command))
|
|
373
|
+
.map((server) => `${server.name}_`);
|
|
374
|
+
if (!prefixes.length) return null;
|
|
375
|
+
return (toolErrors || []).find(({ tool, error }) => (
|
|
376
|
+
prefixes.some((prefix) => tool.startsWith(prefix)) && !isAnswerableToolError(error)
|
|
377
|
+
)) || null;
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const publicToolFailedError = ({ tool, error }) => {
|
|
381
|
+
const reason = String(error).replace(/\s+/g, ' ').slice(0, 160) || '(empty error)';
|
|
382
|
+
const failure = new Error(
|
|
383
|
+
`public seat withheld this turn's reply: Commonly tool ${tool} failed in a way the model must not narrate `
|
|
384
|
+
+ `(${reason}), so nothing was posted and the event stays unacked for retry`,
|
|
385
|
+
);
|
|
386
|
+
failure.code = PUBLIC_TOOL_FAILED_CODE;
|
|
387
|
+
return failure;
|
|
388
|
+
};
|
|
389
|
+
|
|
338
390
|
const runOpenCode = ({ cmd, args, cwd, env, timeoutMs, credentials, spawnImpl = childSpawn }) => new Promise((resolve, reject) => {
|
|
339
391
|
let proc;
|
|
340
392
|
try {
|
|
@@ -376,7 +428,9 @@ const runOpenCode = ({ cmd, args, cwd, env, timeoutMs, credentials, spawnImpl =
|
|
|
376
428
|
credentials, exitCode: code, limit: 500,
|
|
377
429
|
}));
|
|
378
430
|
}
|
|
379
|
-
resolve({
|
|
431
|
+
resolve({
|
|
432
|
+
sessionId: events.sessionId, text: events.text, usage: events.usage, toolErrors: events.toolErrors,
|
|
433
|
+
});
|
|
380
434
|
});
|
|
381
435
|
});
|
|
382
436
|
|
|
@@ -783,6 +837,10 @@ export default {
|
|
|
783
837
|
credentials,
|
|
784
838
|
spawnImpl: ctx._spawnImpl,
|
|
785
839
|
});
|
|
840
|
+
if (isPublic) {
|
|
841
|
+
const failure = publicToolFailure(result.toolErrors, ctx.environment?.mcp);
|
|
842
|
+
if (failure) throw publicToolFailedError(failure);
|
|
843
|
+
}
|
|
786
844
|
return {
|
|
787
845
|
text: result.text.trim(),
|
|
788
846
|
newSessionId: result.sessionId || ctx.sessionId || null,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which failed Commonly tool calls a public seat's model may answer in plain
|
|
3
|
+
* words. Everything else withholds the turn (#2374, Vera 79595, Wren 79596).
|
|
4
|
+
*
|
|
5
|
+
* The rule is inverted on purpose. Matching known connection failures let an
|
|
6
|
+
* API 5xx through: the shipped MCP turns a non-2xx into a tool error carrying
|
|
7
|
+
* the status, and during a rollout the ingress answers 503 while the socket
|
|
8
|
+
* connects, so the model narrated the outage to a stranger. A list of failures
|
|
9
|
+
* fails open on the next one nobody listed; a list of answers fails closed.
|
|
10
|
+
*
|
|
11
|
+
* The answerable ones:
|
|
12
|
+
* - an API refusal the person can be told about: 400, 403, 404, 409, 410, 413
|
|
13
|
+
* or 422. 401 is NOT among them: a seat whose token the API rejects is
|
|
14
|
+
* broken plumbing, and every later call fails the same way.
|
|
15
|
+
* - the runtime's own schema check, which the model fixes on its next call.
|
|
16
|
+
* OpenCode 1.19.0 words it "The <tool> tool was called with invalid
|
|
17
|
+
* arguments: …" (ToolInvalidArgumentsError, read from the shipped binary).
|
|
18
|
+
*
|
|
19
|
+
* Everything else withholds: a 5xx, 401, 429 or any other status; a tool error
|
|
20
|
+
* with no status (the shipped MCP's network, timeout and token failures); an
|
|
21
|
+
* MCP transport error ("MCP error -32000: Connection closed"); an empty error;
|
|
22
|
+
* and any text this module does not recognise.
|
|
23
|
+
*
|
|
24
|
+
* How the status arrives: the shipped MCP answers a failed call with
|
|
25
|
+
* `isError: true` and one text part, `JSON.stringify({ status, body, message })`
|
|
26
|
+
* for an HTTP error or `{ message }` otherwise (commonly-mcp/src/tools.js,
|
|
27
|
+
* `err`). OpenCode throws that text as the tool's error, so the event's
|
|
28
|
+
* `state.error` is the JSON (measured on the 2026-10-21 canary).
|
|
29
|
+
*
|
|
30
|
+
* The TASK-256 readiness witness uses this same predicate, so the two
|
|
31
|
+
* witnesses cannot disagree about what counts as a failure.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export const ANSWERABLE_API_STATUSES = new Set([400, 403, 404, 409, 410, 413, 422]);
|
|
35
|
+
|
|
36
|
+
const INVALID_ARGUMENTS_RE = /^The \S+ tool was called with invalid arguments: /;
|
|
37
|
+
|
|
38
|
+
const parsePayload = (text) => {
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(text);
|
|
41
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Whether a failed tool call's error text is one the model may answer. */
|
|
48
|
+
export const isAnswerableToolError = (error) => {
|
|
49
|
+
const text = typeof error === 'string' ? error.trim() : '';
|
|
50
|
+
if (!text) return false;
|
|
51
|
+
if (INVALID_ARGUMENTS_RE.test(text)) return true;
|
|
52
|
+
const payload = parsePayload(text);
|
|
53
|
+
return Boolean(payload && Number.isInteger(payload.status) && ANSWERABLE_API_STATUSES.has(payload.status));
|
|
54
|
+
};
|