@commonlyai/cli 0.1.301 → 0.1.303
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 +66 -5
- package/src/lib/model-unavailable.js +20 -4
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -857,6 +857,7 @@ const findOwnPost = (messages, earlierIds) => {
|
|
|
857
857
|
author: m.username || 'unknown',
|
|
858
858
|
basis: serverKnowsSelf ? 'self' : 'legacy-any-bot',
|
|
859
859
|
threadRootId: m.thread_root_id ?? null,
|
|
860
|
+
content: typeof m.content === 'string' ? m.content : '',
|
|
860
861
|
};
|
|
861
862
|
}
|
|
862
863
|
}
|
|
@@ -1840,6 +1841,28 @@ const FINAL_TEXT_ANSWERS_A_PERSON = 'Your final text is posted to the pod unless
|
|
|
1840
1841
|
+ 'Use NO_REPLY alone only after you posted your answer through a tool, with no summary. '
|
|
1841
1842
|
+ FAILURE_IN_PLAIN_WORDS;
|
|
1842
1843
|
|
|
1844
|
+
// F335: a turn that posted through a tool and then failed is retried with the
|
|
1845
|
+
// same prompt, often in a fresh session, so nothing tells the retry its answer
|
|
1846
|
+
// is already up. It names that post, so the retry adds what's missing or stays
|
|
1847
|
+
// silent instead of answering the person a second time. A batch's attempt can't
|
|
1848
|
+
// say which item its post answered, so in a batch the line says so.
|
|
1849
|
+
const EARLIER_ATTEMPT_EXCERPT = 300;
|
|
1850
|
+
export const earlierAttemptPosted = (part, { batch = false } = {}) => {
|
|
1851
|
+
const text = String(part?.content || '').replace(/\s+/g, ' ').trim();
|
|
1852
|
+
const cut = text.length > EARLIER_ATTEMPT_EXCERPT;
|
|
1853
|
+
const excerpt = cut ? `${text.slice(0, EARLIER_ATTEMPT_EXCERPT)}…` : text;
|
|
1854
|
+
return `[An earlier attempt at ${batch ? 'this batch' : 'this item'} failed after it posted in this pod (message ${part.id})`
|
|
1855
|
+
+ `${excerpt ? `, beginning ${JSON.stringify(excerpt)}` : ''}. That post is already there: don't post it again. `
|
|
1856
|
+
+ (batch ? 'It may answer this item or another one here. ' : '')
|
|
1857
|
+
+ (cut ? 'Read that message in full before you decide. ' : '')
|
|
1858
|
+
+ 'Add only what this item still lacks, then checkpoint. '
|
|
1859
|
+
+ (batch
|
|
1860
|
+
? 'If it already answers this item, checkpoint this item and go on to the others here; '
|
|
1861
|
+
+ 'end with NO_REPLY only once every item is handled.]'
|
|
1862
|
+
: 'If it already answers this item, checkpoint it and end with NO_REPLY. '
|
|
1863
|
+
+ 'An acknowledgement such as "on it" does not answer it.]');
|
|
1864
|
+
};
|
|
1865
|
+
|
|
1843
1866
|
export const answersAPerson = (entry) => (
|
|
1844
1867
|
entry?.trigger === 'human' && ADDRESSED_EVENT_TYPES.has(entry.event?.type) && !entry.peerFrame
|
|
1845
1868
|
&& !entry.event.payload?.adjacentReply && !entry.event.payload?.welcomeWake
|
|
@@ -2044,6 +2067,9 @@ export const performRun = ({
|
|
|
2044
2067
|
// saved on the server before each turn. Off for daemon seats, whose daemon
|
|
2045
2068
|
// projects the same values into `environment`.
|
|
2046
2069
|
readSavedControls = false,
|
|
2070
|
+
// A machine-bound record started by hand, without its daemon: nothing
|
|
2071
|
+
// projects Settings into it, so only `agent config` changes its model.
|
|
2072
|
+
standaloneMachineRun = false,
|
|
2047
2073
|
// F150: a seat with no daemon reads its live grant brokers before each turn.
|
|
2048
2074
|
// Off for daemon seats, whose daemon merges /assigned's into the record.
|
|
2049
2075
|
readGrantBrokers = false,
|
|
@@ -2559,12 +2585,17 @@ export const performRun = ({
|
|
|
2559
2585
|
}
|
|
2560
2586
|
}
|
|
2561
2587
|
|
|
2588
|
+
// A private item (an agent.ask.response turn may post a pod update) is
|
|
2589
|
+
// retried here, not in a batch, so it hears what its attempt posted here
|
|
2590
|
+
// too. A comment is answered in its thread, so it is not.
|
|
2591
|
+
const earlierPart = isCommentWake(event) ? null : heldRetryParts.get(String(event._id));
|
|
2592
|
+
const earlierLine = earlierPart ? `\n\n${earlierAttemptPosted(earlierPart)}` : '';
|
|
2562
2593
|
let turnResult;
|
|
2563
2594
|
try {
|
|
2564
2595
|
turnResult = await runTurn({
|
|
2565
2596
|
event,
|
|
2566
2597
|
eventPodId,
|
|
2567
|
-
prompt: peerFrame ? `${peerFrame}\n\n
|
|
2598
|
+
prompt: `${peerFrame ? `${peerFrame}\n\n` : ''}${prompt}${earlierLine}`,
|
|
2568
2599
|
preSpawnIds,
|
|
2569
2600
|
snapshotMessages,
|
|
2570
2601
|
claimKeeper,
|
|
@@ -2621,13 +2652,19 @@ export const performRun = ({
|
|
|
2621
2652
|
const postModelUnavailableHint = async (error, hintPodId, configuredModel) => {
|
|
2622
2653
|
const failure = modelUnavailableFailure(error, { fallbackModel: configuredModel });
|
|
2623
2654
|
if (!failure || !hintPodId) return;
|
|
2624
|
-
|
|
2655
|
+
// A listener seat with no saved environment ignores Settings (see the
|
|
2656
|
+
// "has no saved environment" notice above), and so does a machine-bound
|
|
2657
|
+
// run with no daemon, so both get the command. Each instruction keeps its
|
|
2658
|
+
// own hour: a seat restarted with an environment hears the Settings line
|
|
2659
|
+
// even if the command line went out just before.
|
|
2660
|
+
const cliAgentName = (readSavedControls && !environment) || standaloneMachineRun ? agentName : null;
|
|
2661
|
+
const key = `model-unavailable:${failure.model || 'unknown'}${cliAgentName ? ':agent-config' : ''}`;
|
|
2625
2662
|
try {
|
|
2626
2663
|
if (!noticeDue(agentName, key, MODEL_UNAVAILABLE_HINT_WINDOW_MS)) return;
|
|
2627
2664
|
const delivery = await deliverTurnNotice({
|
|
2628
2665
|
client,
|
|
2629
2666
|
podId: hintPodId,
|
|
2630
|
-
text: modelUnavailableHint(failure.model),
|
|
2667
|
+
text: modelUnavailableHint(failure.model, { cliAgentName }),
|
|
2631
2668
|
limit: chatCharLimit,
|
|
2632
2669
|
maxChunks: maxChatChunks,
|
|
2633
2670
|
log,
|
|
@@ -2700,7 +2737,10 @@ export const performRun = ({
|
|
|
2700
2737
|
if (!failedTurn?.preSpawnIds || wrapperSpokeInTurn) return;
|
|
2701
2738
|
const tail = await failedTurn.snapshotMessages(50);
|
|
2702
2739
|
const ownPost = tail && newestOwnPostSince(tail, failedTurn.preSpawnIds);
|
|
2703
|
-
|
|
2740
|
+
// `solo`: the attempt carried only this item, so its post can only be this
|
|
2741
|
+
// item's. A batch's post may answer any item in it.
|
|
2742
|
+
const solo = failedEvents.length === 1;
|
|
2743
|
+
if (ownPost) failedEvents.forEach((event) => heldRetryParts.set(String(event._id), { ...ownPost, solo }));
|
|
2704
2744
|
};
|
|
2705
2745
|
|
|
2706
2746
|
const noticeCutOff = async (lostEvents, { released = [], part = null } = {}) => {
|
|
@@ -3417,13 +3457,20 @@ export const performRun = ({
|
|
|
3417
3457
|
const body = entry.prompt || '[No usable prompt was delivered for this item.]';
|
|
3418
3458
|
const personLine = answersAPerson(entry) ? `\n${PERSON_ADDRESSED}` : '';
|
|
3419
3459
|
const channelLine = answersInChannel(entry) ? `\n${ANSWER_IN_CHANNEL}` : '';
|
|
3460
|
+
// A peer's item is read-only, and a comment is answered in its thread, not
|
|
3461
|
+
// by a pod post: neither is told to stop at what the attempt posted.
|
|
3462
|
+
const earlierPart = entry.readOnly || isCommentWake(entry.event)
|
|
3463
|
+
? null : heldRetryParts.get(String(entry.event._id));
|
|
3464
|
+
const earlierLine = earlierPart
|
|
3465
|
+
? `\n${earlierAttemptPosted(earlierPart, { batch: shownEntries.length > 1 })}`
|
|
3466
|
+
: '';
|
|
3420
3467
|
const deliveryId = entry.event.payload?.deliveryId;
|
|
3421
3468
|
const checkpoint = typeof deliveryId === 'string' && deliveryId
|
|
3422
3469
|
? `\n[After ${answersAPerson(entry) ? 'all of your answer is posted through a tool' : 'completed tool-side work or intentional NO_REPLY'} for only this item, call commonly_checkpoint_event(${JSON.stringify({
|
|
3423
3470
|
eventId: String(entry.event._id), deliveryId,
|
|
3424
3471
|
})}). Checkpoint metadata is private runtime data; never post it in chat.]`
|
|
3425
3472
|
: '';
|
|
3426
|
-
return `${prefix}\n${claimContext}${body}${personLine}${channelLine}${checkpoint}`;
|
|
3473
|
+
return `${prefix}\n${claimContext}${body}${personLine}${channelLine}${earlierLine}${checkpoint}`;
|
|
3427
3474
|
});
|
|
3428
3475
|
const rollup = wakeEntries.find((entry) => entry.event.payload?.digestRollup)?.event.payload?.digestRollup;
|
|
3429
3476
|
const digestEvents = digestEntries.map((entry) => entry.event);
|
|
@@ -4175,6 +4222,15 @@ export const performRun = ({
|
|
|
4175
4222
|
// An item left without a result (a failure during isolation)
|
|
4176
4223
|
// releases with no outcome, for redelivery, as a thrown turn does.
|
|
4177
4224
|
const release = claimReleaseFor(entry.event, entry.result || turnResult);
|
|
4225
|
+
// A retry that chose NO_REPLY because its single-item attempt already
|
|
4226
|
+
// posted the answer answered the person, so it closes, never handed
|
|
4227
|
+
// to another listener. A retry that printed nothing chose nothing,
|
|
4228
|
+
// and a batch's post may be another item's: both still decline, so a
|
|
4229
|
+
// batch whose post answered every item can be handed on (a known
|
|
4230
|
+
// limit; telling which item a post answered needs a signal we lack).
|
|
4231
|
+
if (release.outcome === 'declined' && actionEntries.length === 1
|
|
4232
|
+
&& (entry.result || turnResult)?.reason !== EMPTY_OUTPUT
|
|
4233
|
+
&& heldRetryParts.get(String(entry.event._id))?.solo) release.outcome = 'completed';
|
|
4178
4234
|
await entry.claimKeeper.release(release.outcome, {
|
|
4179
4235
|
reason: release.reason, status: release.status,
|
|
4180
4236
|
});
|
|
@@ -4563,6 +4619,10 @@ export const performRun = ({
|
|
|
4563
4619
|
// Carried to the retry like a failed batch: the event is claimed,
|
|
4564
4620
|
// so the next poll would not return it.
|
|
4565
4621
|
tickUnsettled.push(...claimedAfter(groupIndex));
|
|
4622
|
+
// Only this event's own turn: a throw before its spawn leaves an
|
|
4623
|
+
// earlier turn's arguments, possibly another pod's, in failedTurn.
|
|
4624
|
+
// eslint-disable-next-line no-await-in-loop
|
|
4625
|
+
if (failedTurn?.event === event) await noteFailedTurnPart([event]);
|
|
4566
4626
|
// eslint-disable-next-line no-await-in-loop
|
|
4567
4627
|
const hold = await holdForRetry([event], untriedAfter(groupIndex));
|
|
4568
4628
|
keepHeldLeases(retry.delayMs);
|
|
@@ -5519,6 +5579,7 @@ Docs:
|
|
|
5519
5579
|
machineId: record.machineId, agentName: record.agentName, instanceId: record.instanceId }),
|
|
5520
5580
|
reportRuntime: Boolean(record.machineId || process.env.COMMONLY_MANAGED_RUNNER === '1'),
|
|
5521
5581
|
readSavedControls: !record.machineId && process.env.COMMONLY_MANAGED_RUNNER !== '1',
|
|
5582
|
+
standaloneMachineRun: Boolean(record.machineId) && process.env.COMMONLY_MANAGED_RUNNER !== '1',
|
|
5522
5583
|
readGrantBrokers: !record.machineId && process.env.COMMONLY_MANAGED_RUNNER !== '1',
|
|
5523
5584
|
spawnCredentialTtlSeconds: resolveSpawnTtlSeconds(process.env),
|
|
5524
5585
|
refusalHandoff: opts.refusalHandoff || null,
|
|
@@ -131,7 +131,23 @@ export const modelUnavailableFailure = (error, { fallbackModel = null } = {}) =>
|
|
|
131
131
|
return { model: safeModelName(fallbackModel) };
|
|
132
132
|
};
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
const CLI_AGENT_NAME_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/i;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The one line posted in the pod. The model is set in the agent's Settings,
|
|
138
|
+
* under the "How it runs" section, which starts collapsed (F354: a walk missed
|
|
139
|
+
* it). `cliAgentName` is for a `commonly agent run` seat whose record has no
|
|
140
|
+
* saved environment: Settings doesn't reach that seat until `agent config`
|
|
141
|
+
* writes one, so the line names that command instead. A name that can't be
|
|
142
|
+
* printed safely becomes `<name>`: Settings still wouldn't reach that seat.
|
|
143
|
+
*/
|
|
144
|
+
export const modelUnavailableHint = (model, { cliAgentName = null } = {}) => {
|
|
145
|
+
const what = model
|
|
146
|
+
? `The model provider says ${model} isn't available for this agent.`
|
|
147
|
+
: "The model provider says this agent's model isn't available.";
|
|
148
|
+
if (typeof cliAgentName !== 'string' || !cliAgentName) {
|
|
149
|
+
return `${what} To change it, open the agent's Settings, then How it runs, then Model.`;
|
|
150
|
+
}
|
|
151
|
+
const name = CLI_AGENT_NAME_RE.test(cliAgentName) ? cliAgentName : '<name>';
|
|
152
|
+
return `${what} To change it, run commonly agent config ${name} --model <model> on the computer it runs on, then restart commonly agent run ${name}.`;
|
|
153
|
+
};
|