@commonlyai/cli 0.1.318 → 0.1.320
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 +1 -1
- package/src/commands/agent.js +125 -22
- package/src/lib/poll-liveness.js +43 -0
- package/src/lib/seat-stop.js +2 -1
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -64,7 +64,9 @@ import {
|
|
|
64
64
|
import { catchUpBeforeTurn } from '../lib/pod-catch-up.js';
|
|
65
65
|
import { readLongTerm, syncBack } from '../lib/memory-bridge.js';
|
|
66
66
|
import { pollRetryPolicy } from '../lib/poll-retry.js';
|
|
67
|
-
import {
|
|
67
|
+
import {
|
|
68
|
+
createIdleHeartbeat, createPollLiveness, formatStall, resolveIdleLineMs, resolvePollLivenessMs,
|
|
69
|
+
} from '../lib/poll-liveness.js';
|
|
68
70
|
import { detectMemorySources, composeImport, importMemory } from '../lib/memory-import.js';
|
|
69
71
|
import { detectSkills, importSkills, parseSkillMeta } from '../lib/skills-import.js';
|
|
70
72
|
import { compileServerSkills } from '../lib/server-skills.js';
|
|
@@ -197,6 +199,51 @@ export const loadAgentToken = (name) => {
|
|
|
197
199
|
}
|
|
198
200
|
};
|
|
199
201
|
|
|
202
|
+
// ── Instances (F306) ─────────────────────────────────────────────────────────
|
|
203
|
+
// One agent can have more than one instance (same name, another instanceId),
|
|
204
|
+
// each with its own key. The default instance keeps `<name>.json`; another
|
|
205
|
+
// is `<name>@<instanceId>.json`, so its key never overwrites the default's.
|
|
206
|
+
const INSTANCE_ID_PATTERN = /^[A-Za-z0-9._-]{1,64}$/;
|
|
207
|
+
const isDefaultInstanceId = (instanceId) => String(instanceId || 'default').toLowerCase() === 'default';
|
|
208
|
+
|
|
209
|
+
export const seatKey = (agentName, instanceId) => (
|
|
210
|
+
isDefaultInstanceId(instanceId) ? agentName : `${agentName}@${instanceId}`
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
const runCommandFor = (agentName, instanceId) => (
|
|
214
|
+
`commonly agent run ${agentName}${isDefaultInstanceId(instanceId) ? '' : ` --instance-id ${instanceId}`}`
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The instance `run <name>` was asked to start: --instance-id, or the one a
|
|
219
|
+
* seat key (`nova@priya-nova`, the token file's name) carries. Null when
|
|
220
|
+
* neither names one: that run behaves as it always has, keyed by the bare name
|
|
221
|
+
* whatever instance its key is for (a persona's BYO install is a non-default
|
|
222
|
+
* instance, and its page command names none).
|
|
223
|
+
* Throws on an id that is not a plain id, since it becomes part of a file name.
|
|
224
|
+
*/
|
|
225
|
+
export const parseRunInstanceId = (flag, name) => {
|
|
226
|
+
const at = String(name).indexOf('@');
|
|
227
|
+
const fromName = at >= 0 ? String(name).slice(at + 1) : null;
|
|
228
|
+
if (flag !== undefined && fromName !== null && flag !== fromName) {
|
|
229
|
+
throw new Error(`'${name}' already names instance ${fromName}, so --instance-id ${flag} does not apply`);
|
|
230
|
+
}
|
|
231
|
+
const instanceId = flag !== undefined ? flag : fromName;
|
|
232
|
+
if (instanceId === null) return null;
|
|
233
|
+
if (!INSTANCE_ID_PATTERN.test(instanceId)) {
|
|
234
|
+
throw new Error(`--instance-id takes the instance's id (letters, digits, '.', '_' or '-'), not '${instanceId}'`);
|
|
235
|
+
}
|
|
236
|
+
return instanceId;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/** A key for one instance never runs as another: say which command runs it. */
|
|
240
|
+
export const runInstanceRefusal = ({ record, instanceId }) => {
|
|
241
|
+
const keyInstance = record?.instanceId || 'default';
|
|
242
|
+
if (String(keyInstance).toLowerCase() === String(instanceId || 'default').toLowerCase()) return null;
|
|
243
|
+
return `this key is for instance ${keyInstance} of '${record.agentName}', not instance ${instanceId || 'default'}. `
|
|
244
|
+
+ `To run it: ${runCommandFor(record.agentName, keyInstance)}`;
|
|
245
|
+
};
|
|
246
|
+
|
|
200
247
|
export const deleteAgentToken = (name) => {
|
|
201
248
|
const file = tokenFile(name);
|
|
202
249
|
if (existsSync(file)) rmSync(file);
|
|
@@ -1983,6 +2030,10 @@ export const performRun = ({
|
|
|
1983
2030
|
agentName,
|
|
1984
2031
|
displayName = null,
|
|
1985
2032
|
instanceId = 'default',
|
|
2033
|
+
// F306: the token file's key, which names this seat's local state (sessions,
|
|
2034
|
+
// handled events, notices, scratch folder). A second instance's is
|
|
2035
|
+
// `<name>@<instanceId>`; every other seat's is its bare name, as before.
|
|
2036
|
+
localKey = null,
|
|
1986
2037
|
podId = null,
|
|
1987
2038
|
environment = null,
|
|
1988
2039
|
// D245: the user's own Windows opt-in for this run; reaches the adapter's
|
|
@@ -2057,7 +2108,11 @@ export const performRun = ({
|
|
|
2057
2108
|
pollLivenessMs,
|
|
2058
2109
|
pollLivenessCheckMs,
|
|
2059
2110
|
onPollStalled,
|
|
2111
|
+
// How often a seat that keeps polling and finds nothing says so. Undefined
|
|
2112
|
+
// reads COMMONLY_IDLE_LINE_MS, then ten minutes (lib/poll-liveness.js).
|
|
2113
|
+
idleLineMs,
|
|
2060
2114
|
}) => {
|
|
2115
|
+
const stateKey = localKey || agentName;
|
|
2061
2116
|
const supervising = superviseRuns ?? superviseRunsByDefault(adapter?.name);
|
|
2062
2117
|
reportRuntime = reportRuntime && WALKED_HARNESSES.includes(adapter?.name);
|
|
2063
2118
|
{
|
|
@@ -2217,6 +2272,8 @@ export const performRun = ({
|
|
|
2217
2272
|
onPollStalled?.({ stalledMs });
|
|
2218
2273
|
},
|
|
2219
2274
|
});
|
|
2275
|
+
// So an idle seat's log tells it apart from a wedged one (11-10).
|
|
2276
|
+
const idleHeartbeat = createIdleHeartbeat({ everyMs: resolveIdleLineMs(idleLineMs), log });
|
|
2220
2277
|
const spawnJitterRatio = retryJitterRatio ?? spawnRetryJitter(agentName);
|
|
2221
2278
|
// Per-seat cascade state — lives with the process, like the session store.
|
|
2222
2279
|
// A wrapper restart forgets the streak; the decay window covers that gap.
|
|
@@ -2250,7 +2307,7 @@ export const performRun = ({
|
|
|
2250
2307
|
// as binary-not-found — so we ensure it up front to avoid the confusing
|
|
2251
2308
|
// diagnostic. ADR-008: when an environment spec was attached, the resolved
|
|
2252
2309
|
// workspace path replaces the /tmp default.
|
|
2253
|
-
const scratchCwd = join(tmpdir(), 'commonly-agents',
|
|
2310
|
+
const scratchCwd = join(tmpdir(), 'commonly-agents', stateKey);
|
|
2254
2311
|
const agentCwd = workspacePath || scratchCwd;
|
|
2255
2312
|
if (!existsSync(agentCwd)) mkdirSync(agentCwd, { recursive: true });
|
|
2256
2313
|
// TASK-294: a pod can turn public after attach, so a workspace seat re-reads
|
|
@@ -2604,7 +2661,7 @@ export const performRun = ({
|
|
|
2604
2661
|
// again on every resume (measured 2026-11-05 on codex 0.162.1 and claude
|
|
2605
2662
|
// 2.1.318), so one refusal would refuse every later turn in this pod. The
|
|
2606
2663
|
// next turn starts fresh; memory reaches it through the adapter's preamble.
|
|
2607
|
-
if (isContentRefusal(error) && turn.resumedSession) clearSession(
|
|
2664
|
+
if (isContentRefusal(error) && turn.resumedSession) clearSession(stateKey, args.eventPodId);
|
|
2608
2665
|
throw error;
|
|
2609
2666
|
}
|
|
2610
2667
|
};
|
|
@@ -2626,7 +2683,7 @@ export const performRun = ({
|
|
|
2626
2683
|
const cliAgentName = (readSavedControls && !environment) || standaloneMachineRun ? agentName : null;
|
|
2627
2684
|
const key = `model-unavailable:${failure.model || 'unknown'}${cliAgentName ? ':agent-config' : ''}`;
|
|
2628
2685
|
try {
|
|
2629
|
-
if (!noticeDue(
|
|
2686
|
+
if (!noticeDue(stateKey, key, MODEL_UNAVAILABLE_HINT_WINDOW_MS)) return;
|
|
2630
2687
|
const delivery = await deliverTurnNotice({
|
|
2631
2688
|
client,
|
|
2632
2689
|
podId: hintPodId,
|
|
@@ -2636,7 +2693,7 @@ export const performRun = ({
|
|
|
2636
2693
|
log,
|
|
2637
2694
|
});
|
|
2638
2695
|
if (!delivery.skipped && !delivery.refused) {
|
|
2639
|
-
recordNotice(
|
|
2696
|
+
recordNotice(stateKey, key);
|
|
2640
2697
|
log(`model unavailable hint posted (${failure.model || 'model not named'})`);
|
|
2641
2698
|
}
|
|
2642
2699
|
} catch (noticeError) {
|
|
@@ -2662,7 +2719,7 @@ export const performRun = ({
|
|
|
2662
2719
|
const key = `cant-answer:${notice.cause}:${waitingPod}`;
|
|
2663
2720
|
try {
|
|
2664
2721
|
// eslint-disable-next-line no-continue
|
|
2665
|
-
if (!noticeDue(
|
|
2722
|
+
if (!noticeDue(stateKey, key, CANT_ANSWER_NOTICE_WINDOW_MS)) continue;
|
|
2666
2723
|
// eslint-disable-next-line no-await-in-loop
|
|
2667
2724
|
const delivery = await deliverChatReply({
|
|
2668
2725
|
client,
|
|
@@ -2677,7 +2734,7 @@ export const performRun = ({
|
|
|
2677
2734
|
log(`[inbox.batch] pod ${waitingPod} was not told why this agent can't answer: `
|
|
2678
2735
|
+ `${delivery.reason || 'the notice was not posted'}`);
|
|
2679
2736
|
} else {
|
|
2680
|
-
recordNotice(
|
|
2737
|
+
recordNotice(stateKey, key);
|
|
2681
2738
|
log(`[inbox.batch] told pod ${waitingPod} why this agent can't answer (${notice.cause})`);
|
|
2682
2739
|
}
|
|
2683
2740
|
} catch (noticeError) {
|
|
@@ -2814,8 +2871,8 @@ export const performRun = ({
|
|
|
2814
2871
|
// TASK-440: a cold, large session starts fresh at wake instead of being
|
|
2815
2872
|
// resumed. The restart note leads the prompt; memory still reaches the
|
|
2816
2873
|
// fresh session through the adapter's preamble.
|
|
2817
|
-
const sessionEntry = getSessionEntry(
|
|
2818
|
-
let sessionId = getSession(
|
|
2874
|
+
const sessionEntry = getSessionEntry(stateKey, eventPodId, { binding: placement.binding });
|
|
2875
|
+
let sessionId = getSession(stateKey, eventPodId, { binding: placement.binding });
|
|
2819
2876
|
let recycleBriefing = null;
|
|
2820
2877
|
if (sessionId && shouldStartFreshSession({
|
|
2821
2878
|
lastTurn: sessionEntry?.lastTurn,
|
|
@@ -3097,7 +3154,7 @@ export const performRun = ({
|
|
|
3097
3154
|
// TASK-440: record the context size this turn left behind, so the next
|
|
3098
3155
|
// wake can decide whether to recycle. Adapters that report nothing keep
|
|
3099
3156
|
// resuming.
|
|
3100
|
-
setSession(
|
|
3157
|
+
setSession(stateKey, eventPodId, result.newSessionId, {
|
|
3101
3158
|
binding: placement.binding,
|
|
3102
3159
|
contextTokens: result.contextTokens ?? null,
|
|
3103
3160
|
});
|
|
@@ -3859,7 +3916,7 @@ export const performRun = ({
|
|
|
3859
3916
|
const seenEventIds = new Set();
|
|
3860
3917
|
for (const entry of entries) {
|
|
3861
3918
|
const eventId = String(entry.event._id);
|
|
3862
|
-
if (seenEventIds.has(eventId) || wasEventHandled(
|
|
3919
|
+
if (seenEventIds.has(eventId) || wasEventHandled(stateKey, entry.event._id)) {
|
|
3863
3920
|
entry.result = { outcome: 'no_action', reason: 'duplicate-delivery' };
|
|
3864
3921
|
log(`[${entry.event.type}] duplicate delivery ${entry.event._id} — re-acking without batch spawn`);
|
|
3865
3922
|
} else {
|
|
@@ -4332,6 +4389,7 @@ export const performRun = ({
|
|
|
4332
4389
|
const pageEvents = carriedFresh.length ? [...carriedFresh, ...events] : events;
|
|
4333
4390
|
const pageInboxCount = (Number.isFinite(inboxCount) ? inboxCount : events.length)
|
|
4334
4391
|
+ carriedFresh.length;
|
|
4392
|
+
if (pageEvents.length) idleHeartbeat.busy(); else if (running) idleHeartbeat.empty();
|
|
4335
4393
|
|
|
4336
4394
|
const eventGroups = new Map();
|
|
4337
4395
|
for (const event of pageEvents) {
|
|
@@ -4518,7 +4576,7 @@ export const performRun = ({
|
|
|
4518
4576
|
// reached. Unacked, the kernel redelivers it.
|
|
4519
4577
|
if (!entry.result) continue;
|
|
4520
4578
|
if (entry.result?.reason !== 'duplicate-delivery') {
|
|
4521
|
-
recordHandledEvent(
|
|
4579
|
+
recordHandledEvent(stateKey, event._id);
|
|
4522
4580
|
}
|
|
4523
4581
|
try {
|
|
4524
4582
|
const deliveryId = event.payload?.deliveryId;
|
|
@@ -4554,7 +4612,7 @@ export const performRun = ({
|
|
|
4554
4612
|
}
|
|
4555
4613
|
const [event] = group;
|
|
4556
4614
|
let result;
|
|
4557
|
-
if (wasEventHandled(
|
|
4615
|
+
if (wasEventHandled(stateKey, event._id)) {
|
|
4558
4616
|
result = { outcome: 'no_action', reason: 'duplicate-delivery' };
|
|
4559
4617
|
log(`[${event.type}] duplicate delivery ${event._id} — skipping spawn and re-acking`);
|
|
4560
4618
|
} else {
|
|
@@ -4650,7 +4708,7 @@ export const performRun = ({
|
|
|
4650
4708
|
// Record after successful processing but before ack. If the ack
|
|
4651
4709
|
// fails, the next delivery is skipped and re-acked instead of
|
|
4652
4710
|
// burning a second model turn for work that already completed.
|
|
4653
|
-
recordHandledEvent(
|
|
4711
|
+
recordHandledEvent(stateKey, event._id);
|
|
4654
4712
|
}
|
|
4655
4713
|
try {
|
|
4656
4714
|
const deliveryId = event.payload?.deliveryId;
|
|
@@ -4694,6 +4752,7 @@ export const performRun = ({
|
|
|
4694
4752
|
// token cannot heal itself; a network failure usually can, and a seat
|
|
4695
4753
|
// that stops on one is dead until a human notices.
|
|
4696
4754
|
consecutivePollFailures += 1;
|
|
4755
|
+
idleHeartbeat.busy();
|
|
4697
4756
|
const retry = pollRetryPolicy({
|
|
4698
4757
|
consecutiveFailures: consecutivePollFailures,
|
|
4699
4758
|
intervalMs,
|
|
@@ -4889,6 +4948,8 @@ export const performDetach = async ({
|
|
|
4889
4948
|
agentName,
|
|
4890
4949
|
podId,
|
|
4891
4950
|
instanceId = 'default',
|
|
4951
|
+
// F306: the token file to remove; a second instance's is `<name>@<instanceId>`.
|
|
4952
|
+
localKey = null,
|
|
4892
4953
|
skipBackend = false,
|
|
4893
4954
|
log = () => {},
|
|
4894
4955
|
}) => {
|
|
@@ -4919,9 +4980,10 @@ export const performDetach = async ({
|
|
|
4919
4980
|
}
|
|
4920
4981
|
}
|
|
4921
4982
|
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4983
|
+
const stateKey = localKey || agentName;
|
|
4984
|
+
deleteAgentToken(stateKey);
|
|
4985
|
+
clearSessions(stateKey);
|
|
4986
|
+
log(`local: removed token file + session store for '${stateKey}'`);
|
|
4925
4987
|
|
|
4926
4988
|
return { backend: backendResult, localCleaned: true };
|
|
4927
4989
|
};
|
|
@@ -5322,6 +5384,7 @@ Docs:
|
|
|
5322
5384
|
.command('run <name>')
|
|
5323
5385
|
.description('Run the local-CLI wrapper loop for an attached agent')
|
|
5324
5386
|
.option('--interval <ms>', 'Poll interval in ms', '5000')
|
|
5387
|
+
.option('--instance-id <id>', 'Run this instance of the agent, when it has more than one (default: default)')
|
|
5325
5388
|
.option('--adapter <name>', `CLI to wrap on first-run bootstrap (${listPublicAdapterNames().join('|')}); an existing token file bound to a different adapter stops the run`)
|
|
5326
5389
|
.option('--cascade-cap <n>', `Consecutive agent-triggered turns allowed per pod (env ${CASCADE_ENV_VARS.cap}, default ${CASCADE_DEFAULTS.cap})`)
|
|
5327
5390
|
.option('--cascade-grace <n>', `Extra turns allowed when this seat was directly addressed; 0 disables the grace (env ${CASCADE_ENV_VARS.addressedGrace}, default ${CASCADE_DEFAULTS.addressedGrace})`)
|
|
@@ -5329,7 +5392,19 @@ Docs:
|
|
|
5329
5392
|
.option('--refusal-handoff <agent>', 'Agent to @mention when the model provider refuses a request\'s content; the request is acked as refused, never retried')
|
|
5330
5393
|
.option('--allow <grants>', 'On first run of an agent that works in its folder, also let it edit files and run commands (write) and/or fetch web pages (web), comma-separated. Commands reach the network.')
|
|
5331
5394
|
.option('--unsandboxed', 'Native Windows only: run this agent without a sandbox, with your own access to files and commands. It gets no connector grants. Codex can run commands in invite-only pods, where anyone in the pod, including people invited later, can direct it.')
|
|
5332
|
-
.action(async (
|
|
5395
|
+
.action(async (typedName, opts) => {
|
|
5396
|
+
// F306: the seat this run is. `name` is the local key (the token file,
|
|
5397
|
+
// the log label, the daemon's plist); the server identity is the record's.
|
|
5398
|
+
let instanceId;
|
|
5399
|
+
try {
|
|
5400
|
+
instanceId = parseRunInstanceId(opts.instanceId, typedName);
|
|
5401
|
+
} catch (err) {
|
|
5402
|
+
console.error(`${stamp()} [${typedName}] ${err.message}`);
|
|
5403
|
+
process.exit(1);
|
|
5404
|
+
}
|
|
5405
|
+
const agentArg = String(typedName).split('@')[0];
|
|
5406
|
+
const named = instanceId !== null;
|
|
5407
|
+
let name = named ? seatKey(agentArg, instanceId) : agentArg;
|
|
5333
5408
|
if (opts.unsandboxed) {
|
|
5334
5409
|
const flagRefusal = unsandboxedFlagRefusal();
|
|
5335
5410
|
if (flagRefusal) {
|
|
@@ -5345,8 +5420,22 @@ Docs:
|
|
|
5345
5420
|
process.exit(1);
|
|
5346
5421
|
}
|
|
5347
5422
|
let record = loadAgentToken(name);
|
|
5423
|
+
// An instance's key saved by an older run, under the bare name: use it
|
|
5424
|
+
// where it is, when it is that instance's (F306).
|
|
5425
|
+
if (!record && named && name !== agentArg) {
|
|
5426
|
+
const legacy = loadAgentToken(agentArg);
|
|
5427
|
+
if (legacy && !runInstanceRefusal({ record: legacy, instanceId })) {
|
|
5428
|
+
record = legacy;
|
|
5429
|
+
name = agentArg;
|
|
5430
|
+
}
|
|
5431
|
+
}
|
|
5348
5432
|
let bootstrapped = false;
|
|
5349
5433
|
const saved = record;
|
|
5434
|
+
const savedRefusal = record && named ? runInstanceRefusal({ record, instanceId }) : null;
|
|
5435
|
+
if (savedRefusal) {
|
|
5436
|
+
console.error(`${stamp()} [${name}] ${savedRefusal}`);
|
|
5437
|
+
process.exit(1);
|
|
5438
|
+
}
|
|
5350
5439
|
if (record) {
|
|
5351
5440
|
record = await adoptEnvToken({
|
|
5352
5441
|
record,
|
|
@@ -5358,7 +5447,7 @@ Docs:
|
|
|
5358
5447
|
// not a token file — bootstrap the record from them (#913).
|
|
5359
5448
|
try {
|
|
5360
5449
|
record = await bootstrapAgentRecordFromEnv({
|
|
5361
|
-
name,
|
|
5450
|
+
name: agentArg,
|
|
5362
5451
|
adapterOverride: opts.adapter || null,
|
|
5363
5452
|
log: (line) => console.log(`${stamp()} [${name}] ${line}`),
|
|
5364
5453
|
allow,
|
|
@@ -5376,10 +5465,15 @@ Docs:
|
|
|
5376
5465
|
console.error(
|
|
5377
5466
|
`No token for '${name}'. Either export COMMONLY_API_URL + COMMONLY_AGENT_TOKEN`
|
|
5378
5467
|
+ ` (shown on the Connect your own agent page) and re-run, or:`
|
|
5379
|
-
+ ` commonly agent attach <adapter> --pod <podId> --name ${
|
|
5468
|
+
+ ` commonly agent attach <adapter> --pod <podId> --name ${agentArg}`,
|
|
5380
5469
|
);
|
|
5381
5470
|
process.exit(1);
|
|
5382
5471
|
}
|
|
5472
|
+
const instanceRefusal = named ? runInstanceRefusal({ record, instanceId }) : null;
|
|
5473
|
+
if (instanceRefusal) {
|
|
5474
|
+
console.error(`${stamp()} [${name}] ${instanceRefusal}`);
|
|
5475
|
+
process.exit(1);
|
|
5476
|
+
}
|
|
5383
5477
|
bootstrapped = true;
|
|
5384
5478
|
}
|
|
5385
5479
|
|
|
@@ -5447,8 +5541,15 @@ Docs:
|
|
|
5447
5541
|
}
|
|
5448
5542
|
if (saved && record !== saved) saveAgentToken(name, record);
|
|
5449
5543
|
if (bootstrapped) {
|
|
5450
|
-
|
|
5451
|
-
|
|
5544
|
+
// A named instance is saved under its seat key; an unnamed run keeps
|
|
5545
|
+
// the bare name, as before.
|
|
5546
|
+
const savedAs = named ? seatKey(record.agentName, record.instanceId) : record.agentName;
|
|
5547
|
+
// The record's own spelling names the file, so the state this run keeps
|
|
5548
|
+
// follows it there, and the next run finds both (case, or a token that
|
|
5549
|
+
// belongs to another name).
|
|
5550
|
+
if (named) name = savedAs;
|
|
5551
|
+
saveAgentToken(savedAs, record);
|
|
5552
|
+
console.log(`${stamp()} [${name}] bootstrapped ${tokenFile(savedAs)} from COMMONLY_AGENT_TOKEN (adapter: ${record.adapter})`);
|
|
5452
5553
|
} else if (savedSeatLacksDefaultSandbox(record)) {
|
|
5453
5554
|
console.warn(
|
|
5454
5555
|
`${stamp()} [${name}] this agent's saved settings declare no sandbox, so it runs without one. `
|
|
@@ -5528,6 +5629,7 @@ Docs:
|
|
|
5528
5629
|
agentName: record.agentName,
|
|
5529
5630
|
displayName: record.displayName || record.agentName,
|
|
5530
5631
|
instanceId: record.instanceId,
|
|
5632
|
+
localKey: name,
|
|
5531
5633
|
podId: record.podId,
|
|
5532
5634
|
environment: runEnvironment || null,
|
|
5533
5635
|
hostUnconfined,
|
|
@@ -5630,6 +5732,7 @@ Docs:
|
|
|
5630
5732
|
agentName: record.agentName,
|
|
5631
5733
|
podId: record.podId,
|
|
5632
5734
|
instanceId: record.instanceId || 'default',
|
|
5735
|
+
localKey: name,
|
|
5633
5736
|
skipBackend: !!opts.force,
|
|
5634
5737
|
log: (line) => console.warn(`[detach] ${line}`),
|
|
5635
5738
|
});
|
package/src/lib/poll-liveness.js
CHANGED
|
@@ -58,3 +58,46 @@ export const createPollLiveness = ({ limitMs, onStall, checkEveryMs }) => {
|
|
|
58
58
|
stop: () => { clearInterval(timer); },
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
|
+
|
|
62
|
+
export const IDLE_LINE_DEFAULT_MS = 10 * 60 * 1000;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A healthy idle seat and a wedged one used to look the same in a log: both
|
|
66
|
+
* printed nothing. On 11-10 six seats sat silent for 4.6 hours after a
|
|
67
|
+
* `fetch failed` and were restarted as wedged, though nothing showed they had
|
|
68
|
+
* stopped polling. So a seat that keeps polling and finds nothing says so on a
|
|
69
|
+
* slow cadence, `polling ok (N empty polls since HH:MMZ)`. While a seat is idle
|
|
70
|
+
* (no turn running, no retry wait), no line for two cadences means the loop has
|
|
71
|
+
* stopped.
|
|
72
|
+
*
|
|
73
|
+
* `empty()` after each poll that settled with nothing to do; `busy()` after one
|
|
74
|
+
* that brought work or failed, which starts the next count, so a window never
|
|
75
|
+
* spans an outage. The first line comes one
|
|
76
|
+
* cadence after the seat goes quiet, never on start.
|
|
77
|
+
*/
|
|
78
|
+
export const createIdleHeartbeat = ({ everyMs = IDLE_LINE_DEFAULT_MS, log, now = Date.now }) => {
|
|
79
|
+
let since = null;
|
|
80
|
+
let count = 0;
|
|
81
|
+
const hhmm = (ms) => `${new Date(ms).toISOString().slice(11, 16)}Z`;
|
|
82
|
+
return {
|
|
83
|
+
empty: () => {
|
|
84
|
+
const at = now();
|
|
85
|
+
if (since === null) since = at;
|
|
86
|
+
count += 1;
|
|
87
|
+
if (at - since < everyMs) return;
|
|
88
|
+
log(`polling ok (${count} empty poll${count === 1 ? '' : 's'} since ${hhmm(since)})`);
|
|
89
|
+
since = null;
|
|
90
|
+
count = 0;
|
|
91
|
+
},
|
|
92
|
+
busy: () => {
|
|
93
|
+
since = null;
|
|
94
|
+
count = 0;
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const resolveIdleLineMs = (value, env = process.env) => {
|
|
100
|
+
const candidate = [value, Number(env.COMMONLY_IDLE_LINE_MS)]
|
|
101
|
+
.find((ms) => Number.isFinite(ms) && ms > 0);
|
|
102
|
+
return candidate ?? IDLE_LINE_DEFAULT_MS;
|
|
103
|
+
};
|
package/src/lib/seat-stop.js
CHANGED
|
@@ -26,7 +26,8 @@ import { armSupervisedGroupDeadline, killSupervisedGroups } from '@commonlyai/se
|
|
|
26
26
|
|
|
27
27
|
export const DEFAULT_EXIT_TIMEOUT_S = 20;
|
|
28
28
|
const MAX_MARGIN_MS = 5000;
|
|
29
|
-
|
|
29
|
+
// `@` joins an agent and its instance in a second instance's key (F306).
|
|
30
|
+
const SEAT_NAME = /^[A-Za-z0-9][A-Za-z0-9._@-]*$/;
|
|
30
31
|
|
|
31
32
|
/** The seat's launchd plist path, or null for a name that cannot be a file name. */
|
|
32
33
|
export const seatPlistPath = (name, home = homedir()) => (typeof name === 'string' && SEAT_NAME.test(name)
|