@commonlyai/cli 0.1.158 → 0.1.160
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
|
@@ -1206,6 +1206,9 @@ export const performRun = ({
|
|
|
1206
1206
|
setTimeoutImpl = setTimeout,
|
|
1207
1207
|
setIntervalImpl = setInterval,
|
|
1208
1208
|
clearIntervalImpl = clearInterval,
|
|
1209
|
+
setDeadlineTimeoutImpl = setTimeout,
|
|
1210
|
+
clearDeadlineTimeoutImpl = clearTimeout,
|
|
1211
|
+
turnTimeoutMs,
|
|
1209
1212
|
retryJitterRatio,
|
|
1210
1213
|
claimLeaseSeconds = 90,
|
|
1211
1214
|
// Undefined means "not overridden" — resolveCascadeSettings falls back to
|
|
@@ -1235,6 +1238,9 @@ export const performRun = ({
|
|
|
1235
1238
|
if (environment?.provider !== undefined && !adapter?.supportsProvider) {
|
|
1236
1239
|
throw new Error('environment.provider requires a provider-capable adapter');
|
|
1237
1240
|
}
|
|
1241
|
+
const requestedTurnTimeout = Number(turnTimeoutMs ?? process.env.COMMONLY_AGENT_RUN_TIMEOUT_MS);
|
|
1242
|
+
const effectiveTurnTimeoutMs = Number.isFinite(requestedTurnTimeout) && requestedTurnTimeout > 0
|
|
1243
|
+
? Math.min(requestedTurnTimeout, 2_147_483_647) : 15 * 60 * 1000;
|
|
1238
1244
|
const client = createClient({ instance: instanceUrl, token });
|
|
1239
1245
|
const handoffAgent = sanitizeHandoffAgent(refusalHandoff);
|
|
1240
1246
|
if (refusalHandoff && !handoffAgent) {
|
|
@@ -1742,6 +1748,7 @@ export const performRun = ({
|
|
|
1742
1748
|
});
|
|
1743
1749
|
}
|
|
1744
1750
|
result = await adapter.spawn(frameDecisionForkRule(promptForSpawn), {
|
|
1751
|
+
timeoutMs: effectiveTurnTimeoutMs,
|
|
1745
1752
|
sessionId,
|
|
1746
1753
|
cwd: agentCwd,
|
|
1747
1754
|
env: commitAttribution?.env || process.env,
|
|
@@ -2076,7 +2083,13 @@ export const performRun = ({
|
|
|
2076
2083
|
+ '[This item is read-only context: a peer won its binding claim. Do not act on it.]\n'
|
|
2077
2084
|
: (entry.peerFrame ? `${entry.peerFrame}\n` : '');
|
|
2078
2085
|
const body = entry.prompt || '[No usable prompt was delivered for this item.]';
|
|
2079
|
-
|
|
2086
|
+
const deliveryId = entry.event.payload?.deliveryId;
|
|
2087
|
+
const checkpoint = typeof deliveryId === 'string' && deliveryId
|
|
2088
|
+
? `\n[After completed tool-side work or intentional NO_REPLY for only this item, call commonly_checkpoint_event(${JSON.stringify({
|
|
2089
|
+
eventId: String(entry.event._id), deliveryId,
|
|
2090
|
+
})}). Checkpoint metadata is private runtime data; never post it in chat.]`
|
|
2091
|
+
: '';
|
|
2092
|
+
return `${prefix}\n${claimContext}${body}${checkpoint}`;
|
|
2080
2093
|
});
|
|
2081
2094
|
const rollup = wakeEntries.find((entry) => entry.event.payload?.digestRollup)?.event.payload?.digestRollup;
|
|
2082
2095
|
const digestFrame = formatDigestFrame(digestEntries.map((entry) => entry.event), rollup);
|
|
@@ -2084,6 +2097,11 @@ export const performRun = ({
|
|
|
2084
2097
|
return [
|
|
2085
2098
|
`[Inbox batch: ${inboxCount} new event${inboxCount === 1 ? '' : 's'} in this pod. `
|
|
2086
2099
|
+ 'This is one turn: read the included items together, then decide what needs YOU.]',
|
|
2100
|
+
'After tool-side work is committed (including any reply posted through a tool), or an intentional NO_REPLY, checkpoint that item with its supplied IDs. '
|
|
2101
|
+
+ 'Release any held message claim first with the correct completed/declined outcome. '
|
|
2102
|
+
+ 'Do not checkpoint a reply you are holding for final CLI output: the wrapper must post it before acknowledging that item. '
|
|
2103
|
+
+ 'Never checkpoint unfinished work. Only a successful checkpoint prevents replay after timeout. '
|
|
2104
|
+
+ 'If the tool is unavailable, continue normally; completion will acknowledge the batch.',
|
|
2087
2105
|
...bodies,
|
|
2088
2106
|
...(digestFrame ? [digestFrame] : []),
|
|
2089
2107
|
...(omitted > 0
|
|
@@ -2170,7 +2188,7 @@ export const performRun = ({
|
|
|
2170
2188
|
let heldGreeting = [];
|
|
2171
2189
|
let greetingHoldSpent = false;
|
|
2172
2190
|
|
|
2173
|
-
const
|
|
2191
|
+
const handleEventBatch = async (events, inboxCount = events.length) => {
|
|
2174
2192
|
const eventPodId = events[0]?.podId || podId;
|
|
2175
2193
|
if (!eventPodId || events.some((event) => (event.podId || podId) !== eventPodId)) {
|
|
2176
2194
|
throw new Error('Inbox batch crossed pod boundaries; refusing to mix private pod context');
|
|
@@ -2427,6 +2445,44 @@ export const performRun = ({
|
|
|
2427
2445
|
}
|
|
2428
2446
|
};
|
|
2429
2447
|
|
|
2448
|
+
const processEventBatch = async (events, inboxCount = events.length) => {
|
|
2449
|
+
const deliveries = events.filter((event) => typeof event.payload?.deliveryId === 'string' && event.payload.deliveryId)
|
|
2450
|
+
.map((event) => ({ eventId: String(event._id), deliveryId: event.payload.deliveryId }));
|
|
2451
|
+
let renewing = false;
|
|
2452
|
+
let renewalStopped = false;
|
|
2453
|
+
const renew = async () => {
|
|
2454
|
+
if (renewalStopped || renewing || deliveries.length === 0) return;
|
|
2455
|
+
renewing = true;
|
|
2456
|
+
try {
|
|
2457
|
+
for (let offset = 0; offset < deliveries.length && !renewalStopped; offset += 50) {
|
|
2458
|
+
await client.post('/api/agents/runtime/events/renew', {
|
|
2459
|
+
events: deliveries.slice(offset, offset + 50),
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2462
|
+
} catch (error) {
|
|
2463
|
+
// An older server may lack this route. Never reinterpret a failed
|
|
2464
|
+
// renewal as an ack: stale checkpoint nonces still fail closed.
|
|
2465
|
+
log(`[inbox.batch] delivery renewal failed: ${error.message}`);
|
|
2466
|
+
} finally { renewing = false; }
|
|
2467
|
+
};
|
|
2468
|
+
const timer = deliveries.length ? setIntervalImpl(renew, 60_000) : null;
|
|
2469
|
+
const stopRenewal = () => {
|
|
2470
|
+
renewalStopped = true;
|
|
2471
|
+
if (timer !== null) clearIntervalImpl(timer);
|
|
2472
|
+
};
|
|
2473
|
+
// Independent of adapter settlement: SIGTERM can be ignored, so awaiting
|
|
2474
|
+
// spawn in finally is not a bound on the event's delivery lease.
|
|
2475
|
+
const deadlineTimer = deliveries.length ? setDeadlineTimeoutImpl(() => {
|
|
2476
|
+
stopRenewal();
|
|
2477
|
+
log('[inbox.batch] turn deadline reached; delivery renewal stopped for GC recovery');
|
|
2478
|
+
}, effectiveTurnTimeoutMs) : null;
|
|
2479
|
+
try { return await handleEventBatch(events, inboxCount); }
|
|
2480
|
+
finally {
|
|
2481
|
+
stopRenewal();
|
|
2482
|
+
if (deadlineTimer !== null) clearDeadlineTimeoutImpl(deadlineTimer);
|
|
2483
|
+
}
|
|
2484
|
+
};
|
|
2485
|
+
|
|
2430
2486
|
const tick = async () => {
|
|
2431
2487
|
if (!running) return;
|
|
2432
2488
|
let nextPollDelayMs = intervalMs;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep the provider key available to pi's per-call auth resolver, but out of
|
|
3
|
+
* shells started by its model bash tool and by manual ! / !! commands.
|
|
4
|
+
* This limits environment inheritance; pi itself is not an OS sandbox.
|
|
5
|
+
*/
|
|
6
|
+
import { createBashTool, createLocalBashOperations } from '@earendil-works/pi-coding-agent';
|
|
7
|
+
|
|
8
|
+
export default function commonlyShellEnvironment(pi) {
|
|
9
|
+
const providerKey = process.env.COMMONLY_PI_PROVIDER_KEY_ENV;
|
|
10
|
+
if (!providerKey) throw new Error('pi adapter: missing provider key environment name');
|
|
11
|
+
const excluded = new Set([
|
|
12
|
+
providerKey, 'COMMONLY_LITELLM_KEY', 'COMMONLY_PI_PROVIDER_KEY_ENV',
|
|
13
|
+
].map((key) => key.toUpperCase()));
|
|
14
|
+
const cleanEnv = (env) => {
|
|
15
|
+
const clean = { ...env };
|
|
16
|
+
// Windows environment lookup ignores case; spreading it loses that behavior.
|
|
17
|
+
for (const key of Object.keys(clean)) {
|
|
18
|
+
if (excluded.has(key.toUpperCase())) delete clean[key];
|
|
19
|
+
}
|
|
20
|
+
return clean;
|
|
21
|
+
};
|
|
22
|
+
const spawnHook = (context) => ({ ...context, env: cleanEnv(context.env) });
|
|
23
|
+
const bash = createBashTool(process.cwd(), { spawnHook });
|
|
24
|
+
pi.registerTool({
|
|
25
|
+
...bash,
|
|
26
|
+
execute(id, params, signal, onUpdate, ctx) {
|
|
27
|
+
return createBashTool(ctx.cwd, { spawnHook }).execute(id, params, signal, onUpdate, ctx);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const local = createLocalBashOperations();
|
|
31
|
+
pi.on('user_bash', () => ({
|
|
32
|
+
operations: {
|
|
33
|
+
exec(command, cwd, options) {
|
|
34
|
+
return local.exec(command, cwd, {
|
|
35
|
+
...options,
|
|
36
|
+
env: cleanEnv(options.env ?? process.env),
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
}
|
package/src/lib/adapters/pi.js
CHANGED
|
@@ -72,6 +72,7 @@ const THINKING = { none: 'off', off: 'off', minimal: 'minimal', low: 'low', medi
|
|
|
72
72
|
export const thinkingFor = (effort) => (effort ? THINKING[String(effort).toLowerCase()] || null : null);
|
|
73
73
|
|
|
74
74
|
const BRIDGE_PATH = join(dirname(fileURLToPath(import.meta.url)), 'pi-commonly-mcp.mjs');
|
|
75
|
+
const SHELL_ENV_PATH = join(dirname(fileURLToPath(import.meta.url)), 'pi-shell-env.mjs');
|
|
75
76
|
|
|
76
77
|
// Same substitution contract as claude.js / codex.js: ${COMMONLY_*}
|
|
77
78
|
// placeholders in the declared MCP env are the wrapper's per-(agent, pod)
|
|
@@ -457,6 +458,9 @@ export default {
|
|
|
457
458
|
...baseEnv,
|
|
458
459
|
PI_CODING_AGENT_DIR: agentDir,
|
|
459
460
|
PI_SKIP_VERSION_CHECK: '1',
|
|
461
|
+
// A variable NAME, never its value. The always-loaded extension uses
|
|
462
|
+
// this to scrub custom provider keys as well as the default LiteLLM key.
|
|
463
|
+
COMMONLY_PI_PROVIDER_KEY_ENV: provider.apiKeyEnv,
|
|
460
464
|
};
|
|
461
465
|
// `baseEnv` is normally the process environment, which carries the
|
|
462
466
|
// bootstrap export. Nothing below this process needs the value: the bridge
|
|
@@ -472,6 +476,8 @@ export default {
|
|
|
472
476
|
prompt: fullPrompt, provider: provider.name, model, thinking, sessionId, isResume, sessionDir,
|
|
473
477
|
bridge: servers.length ? (ctx._bridgePath || BRIDGE_PATH) : null,
|
|
474
478
|
});
|
|
479
|
+
// Shell isolation must not depend on whether this turn declares MCP.
|
|
480
|
+
args.splice(args.length - 1, 0, '-e', SHELL_ENV_PATH);
|
|
475
481
|
|
|
476
482
|
const reply = await runPi({
|
|
477
483
|
args,
|