@commonlyai/cli 0.1.263 → 0.1.264
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/node_modules/@commonlyai/seats/src/upstream-refusal.js +34 -0
- package/package.json +1 -1
- package/src/commands/agent.js +42 -1
- package/src/lib/adapters/claude.js +24 -0
- package/src/lib/adapters/opencode.js +488 -9
- package/src/lib/adapters/pi.js +2 -2
- package/src/lib/default-environment.js +6 -4
- package/src/lib/grant-broker-guard.js +8 -3
- package/src/lib/model-unavailable.js +134 -0
- package/src/lib/sandbox/bwrap.js +10 -3
- package/src/lib/sandbox/seatbelt.js +19 -0
- package/src/lib/sandbox/workspace-pin.js +158 -0
- package/src/lib/session-store.js +43 -1
- package/src/lib/workspace-trust.js +2 -2
|
@@ -327,12 +327,46 @@ export const scrubAdapterFailure = (text, { credentials = [], limit = MAX_REFUSA
|
|
|
327
327
|
* spawn-retry.js). The message still names the status so a human log says the
|
|
328
328
|
* same thing as the classifier's decision.
|
|
329
329
|
*/
|
|
330
|
+
/**
|
|
331
|
+
* The provider's own error code (`error.code`, then a top-level `code`), read
|
|
332
|
+
* from the body a tail carries: the structured body after a status, else the
|
|
333
|
+
* one JSON object embedded in prose (`unexpected status 404 Not Found: {…}`).
|
|
334
|
+
* It is a keep-list of one more named field, and narrower than the message:
|
|
335
|
+
* only a short identifier is kept, and one that echoes a credential this spawn
|
|
336
|
+
* was handed is dropped. Null when there is none (F178: the keep-list reduced
|
|
337
|
+
* `{"code":"model_not_found"}` to its message, so the code was lost).
|
|
338
|
+
*/
|
|
339
|
+
const PROVIDER_CODE_RE = /^[A-Za-z][\w.-]{0,63}$/;
|
|
340
|
+
export const providerCodeFrom = (text, { credentials = [] } = {}) => {
|
|
341
|
+
const raw = String(text ?? '');
|
|
342
|
+
const { body } = readStatusAndBody(raw.trim());
|
|
343
|
+
const candidates = [body];
|
|
344
|
+
const start = raw.indexOf('{');
|
|
345
|
+
const end = raw.lastIndexOf('}');
|
|
346
|
+
if (start >= 0 && end > start) candidates.push(raw.slice(start, end + 1));
|
|
347
|
+
for (const candidate of candidates) {
|
|
348
|
+
let parsed;
|
|
349
|
+
try {
|
|
350
|
+
parsed = JSON.parse(candidate);
|
|
351
|
+
} catch {
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) continue;
|
|
355
|
+
const code = parsed.error?.code ?? parsed.code;
|
|
356
|
+
if (typeof code !== 'string' || !PROVIDER_CODE_RE.test(code)) return null;
|
|
357
|
+
return redactKnownCredentials(code, credentials) === code ? code : null;
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
};
|
|
361
|
+
|
|
330
362
|
export const adapterFailure = (label, text, { credentials = [], exitCode = null, limit } = {}) => {
|
|
331
363
|
const { status, detail } = scrubAdapterFailure(text, { credentials, limit });
|
|
332
364
|
const code = exitCode === null ? '' : ` exited with code ${exitCode}`;
|
|
333
365
|
const named = status === null ? '' : ` (upstream ${status})`;
|
|
334
366
|
const error = new Error(`${label}${code}${named}${detail ? `: ${detail}` : ''}`);
|
|
335
367
|
if (status !== null) error.status = status;
|
|
368
|
+
const providerCode = providerCodeFrom(text, { credentials });
|
|
369
|
+
if (providerCode !== null) error.providerCode = providerCode;
|
|
336
370
|
return error;
|
|
337
371
|
};
|
|
338
372
|
|
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -45,7 +45,14 @@ import {
|
|
|
45
45
|
clearSessions,
|
|
46
46
|
wasEventHandled,
|
|
47
47
|
recordHandledEvent,
|
|
48
|
+
noticeDue,
|
|
49
|
+
recordNotice,
|
|
48
50
|
} from '../lib/session-store.js';
|
|
51
|
+
import {
|
|
52
|
+
MODEL_UNAVAILABLE_HINT_WINDOW_MS,
|
|
53
|
+
modelUnavailableFailure,
|
|
54
|
+
modelUnavailableHint,
|
|
55
|
+
} from '../lib/model-unavailable.js';
|
|
49
56
|
import {
|
|
50
57
|
buildRecycleBriefing,
|
|
51
58
|
idleMinutesSince,
|
|
@@ -2268,6 +2275,35 @@ export const performRun = ({
|
|
|
2268
2275
|
}
|
|
2269
2276
|
};
|
|
2270
2277
|
|
|
2278
|
+
// F178: a provider that will not run this seat's model fails every turn the
|
|
2279
|
+
// same way, and until now only the seat log said so. Post one plain line in
|
|
2280
|
+
// the pod naming the model and where to change it, at most once per model
|
|
2281
|
+
// per seat per hour (persisted, so a restart does not re-post). The failure
|
|
2282
|
+
// itself is rethrown by the caller unchanged, so retry and ack behave as
|
|
2283
|
+
// before. A notice that fails to post is logged and tried on a later turn.
|
|
2284
|
+
const postModelUnavailableHint = async (error, hintPodId, configuredModel) => {
|
|
2285
|
+
const failure = modelUnavailableFailure(error, { fallbackModel: configuredModel });
|
|
2286
|
+
if (!failure || !hintPodId) return;
|
|
2287
|
+
const key = `model-unavailable:${failure.model || 'unknown'}`;
|
|
2288
|
+
try {
|
|
2289
|
+
if (!noticeDue(agentName, key, MODEL_UNAVAILABLE_HINT_WINDOW_MS)) return;
|
|
2290
|
+
const delivery = await deliverChatReply({
|
|
2291
|
+
client,
|
|
2292
|
+
podId: hintPodId,
|
|
2293
|
+
text: modelUnavailableHint(failure.model),
|
|
2294
|
+
limit: chatCharLimit,
|
|
2295
|
+
maxChunks: maxChatChunks,
|
|
2296
|
+
log,
|
|
2297
|
+
});
|
|
2298
|
+
if (!delivery.skipped && !delivery.refused) {
|
|
2299
|
+
recordNotice(agentName, key);
|
|
2300
|
+
log(`model unavailable hint posted (${failure.model || 'model not named'})`);
|
|
2301
|
+
}
|
|
2302
|
+
} catch (noticeError) {
|
|
2303
|
+
log(`model unavailable hint could not be posted: ${noticeError.message}`);
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
|
|
2271
2307
|
const runTurnBody = async ({
|
|
2272
2308
|
event, eventPodId, prompt, preSpawnIds, snapshotMessages, claimKeeper, trigger, turn,
|
|
2273
2309
|
}) => {
|
|
@@ -2544,7 +2580,12 @@ export const performRun = ({
|
|
|
2544
2580
|
// Supervised or plain, a failure is thrown exactly as the adapter's own
|
|
2545
2581
|
// would be, so the run loop's classification and retry apply unchanged.
|
|
2546
2582
|
const spawnStartedAt = Date.now();
|
|
2547
|
-
|
|
2583
|
+
try {
|
|
2584
|
+
result = await turn.run(adapter, spawnPrompt, spawnCtx);
|
|
2585
|
+
} catch (spawnError) {
|
|
2586
|
+
await postModelUnavailableHint(spawnError, eventPodId, seatEnvironment?.model);
|
|
2587
|
+
throw spawnError;
|
|
2588
|
+
}
|
|
2548
2589
|
spawnDurationMs = Date.now() - spawnStartedAt;
|
|
2549
2590
|
spawnCompleted = true;
|
|
2550
2591
|
} finally {
|
|
@@ -85,6 +85,7 @@ import {
|
|
|
85
85
|
normalizeSandboxTrust,
|
|
86
86
|
} from '../environment.js';
|
|
87
87
|
import { detectBwrap, wrapArgvWithBwrap } from '../sandbox/bwrap.js';
|
|
88
|
+
import { holdWorkspaceRealpath, workspacePinDir } from '../sandbox/workspace-pin.js';
|
|
88
89
|
import { PUBLIC_SANDBOX_MODES, resolvePublicSandboxMode } from '../sandbox/mode.js';
|
|
89
90
|
import { UNSANDBOXED_FLAG } from '../sandbox/host-check.js';
|
|
90
91
|
import {
|
|
@@ -1458,6 +1459,10 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1458
1459
|
// link refuses the turn (fail-closed). A workspace seat's folder is the
|
|
1459
1460
|
// operator's own choice, which may be a link, and keeps following it.
|
|
1460
1461
|
pinWorkspace: sandboxTrust === 'public',
|
|
1462
|
+
// F200: a workspace seat's folder is held to the realpath recorded on
|
|
1463
|
+
// its first turn, and that record is never writable from the jail.
|
|
1464
|
+
expectedWorkspaceRealpath: ctx.workspaceRealpath || null,
|
|
1465
|
+
denyWritePaths: ctx.workspacePinDirs || [],
|
|
1461
1466
|
executablePath: claudeBin,
|
|
1462
1467
|
statePath: ctx.publicClaudeState.statePath,
|
|
1463
1468
|
mcpConfigDir: ctx.mcpConfigDir,
|
|
@@ -1524,6 +1529,10 @@ const prepareArgv = async (innerArgv, ctx) => {
|
|
|
1524
1529
|
const { statePath } = ctx.publicClaudeState;
|
|
1525
1530
|
const wrapped = wrapArgvWithBwrap([claudeBin, ...innerArgv], env, {
|
|
1526
1531
|
workspacePath: ctx.cwd,
|
|
1532
|
+
// F200: bwrap resolves a bind source when the jail starts, after the
|
|
1533
|
+
// check, so the checked realpath is the source, mounted at the path the
|
|
1534
|
+
// seat was given.
|
|
1535
|
+
workspaceSource: ctx.workspaceRealpath || ctx.cwd,
|
|
1527
1536
|
workspaceReadOnly: !grants.includes('write'),
|
|
1528
1537
|
readOnlyWorkspaceEntries: ['.git'],
|
|
1529
1538
|
homePath: statePath,
|
|
@@ -1720,6 +1729,14 @@ export default {
|
|
|
1720
1729
|
&& resolvePublicSandboxMode(ctx.environment?.sandbox) === 'bwrap';
|
|
1721
1730
|
const workspaceBwrapSandbox = jailed && ctx.environment?.sandbox?.trust === 'workspace'
|
|
1722
1731
|
&& resolvePublicSandboxMode(ctx.environment?.sandbox) === 'bwrap';
|
|
1732
|
+
// F200: a jailed workspace seat's folder must still resolve where it did
|
|
1733
|
+
// on the seat's first turn, or a link the seat left in its place would
|
|
1734
|
+
// carry this turn's grant elsewhere. The record sits beside the seat's
|
|
1735
|
+
// state folder, the one bwrapClaudeStatePath names for both jails.
|
|
1736
|
+
const heldWorkspace = ctx.environment?.sandbox?.trust === 'workspace' && Boolean(ctx.cwd)
|
|
1737
|
+
&& (publicNativeSandbox || workspaceBwrapSandbox);
|
|
1738
|
+
const workspacePinDirs = heldWorkspace ? [workspacePinDir(bwrapClaudeStatePath(ctx))] : [];
|
|
1739
|
+
let workspaceRealpath = null;
|
|
1723
1740
|
// The proxy's address and per-turn token, never the host's key.
|
|
1724
1741
|
const withProvider = (env) => {
|
|
1725
1742
|
if (providerProxy) {
|
|
@@ -1733,6 +1750,11 @@ export default {
|
|
|
1733
1750
|
...spawnCredentials(spawnContext), providerProxy?.token,
|
|
1734
1751
|
].filter(Boolean);
|
|
1735
1752
|
try {
|
|
1753
|
+
// Checked (and recorded, the first time) before the state is prepared
|
|
1754
|
+
// or anything is spawned.
|
|
1755
|
+
if (heldWorkspace) {
|
|
1756
|
+
workspaceRealpath = await holdWorkspaceRealpath({ cwd: ctx.cwd, statePath: bwrapClaudeStatePath(ctx) });
|
|
1757
|
+
}
|
|
1736
1758
|
// Trust is normalized at entry (legacy `internal` reads as public). The
|
|
1737
1759
|
// MCP policy follows trust alone, whatever confines the seat: a public
|
|
1738
1760
|
// bwrap seat needs a host-prepared build exactly as a Seatbelt one does
|
|
@@ -1854,6 +1876,8 @@ export default {
|
|
|
1854
1876
|
publicClaudeState,
|
|
1855
1877
|
publicSkillArgs,
|
|
1856
1878
|
providerProxyPort: proxyPort(providerProxy),
|
|
1879
|
+
workspaceRealpath,
|
|
1880
|
+
workspacePinDirs,
|
|
1857
1881
|
claudeEnv,
|
|
1858
1882
|
};
|
|
1859
1883
|
const { cmd, args, env, childHome } = await prepareArgv(baseArgs, spawnCtx);
|