agent-lyceum 0.42.1 → 0.42.2
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/dist/adapters/claude.js +2 -1
- package/dist/run-session.js +46 -4
- package/dist/run-store.d.ts +5 -0
- package/dist/run-store.js +1 -0
- package/dist/scaffold.js +1 -1
- package/package.json +1 -1
package/dist/adapters/claude.js
CHANGED
|
@@ -92,8 +92,9 @@ export function buildClaudeInvocation(raw) {
|
|
|
92
92
|
args.push("--model", agent.model);
|
|
93
93
|
if (agent.effort)
|
|
94
94
|
args.push("--effort", agent.effort);
|
|
95
|
+
// Fork so this attempt writes a copy. The stored id stays the transcript from before the attempt; a failure discards the copy.
|
|
95
96
|
if (input.sessionId)
|
|
96
|
-
args.push("--resume", input.sessionId);
|
|
97
|
+
args.push("--resume", input.sessionId, "--fork-session");
|
|
97
98
|
for (const d of [...new Set(addDirs)])
|
|
98
99
|
args.push("--add-dir", d);
|
|
99
100
|
return {
|
package/dist/run-session.js
CHANGED
|
@@ -43,6 +43,35 @@ function readIndex(file) {
|
|
|
43
43
|
}
|
|
44
44
|
/** The `state.sessions` key of the session an agent runs in on candidate `c`: a backup has a session of its own. */
|
|
45
45
|
const sessionKeyOf = (agent, c) => (c.primary ? agent.name : `${agent.name}@${c.key}`);
|
|
46
|
+
/** A backup's key is `name@runtime/model`; the primary's key is the agent name. */
|
|
47
|
+
const ownsSessionKey = (agent, key) => key === agent || key.startsWith(`${agent}@`);
|
|
48
|
+
/** Stable identity of the mail this wake is handling, so a saved session can be matched to that mail only. */
|
|
49
|
+
const mailTag = (ids) => [...ids].sort().join("\n");
|
|
50
|
+
/** Drop this agent's stored sessions. A new mail must not resume another mail's transcript. */
|
|
51
|
+
function dropAgentSessions(state, agent) {
|
|
52
|
+
for (const key of Object.keys(state.sessions)) {
|
|
53
|
+
if (!ownsSessionKey(agent, key))
|
|
54
|
+
continue;
|
|
55
|
+
delete state.sessions[key];
|
|
56
|
+
if (state.session_mail)
|
|
57
|
+
delete state.session_mail[key];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Keep only sessions saved for `tag` (this mail). Anything else is another mail's transcript:
|
|
62
|
+
* a redo must not load it, and a retry must not fall back to it.
|
|
63
|
+
*/
|
|
64
|
+
function retainSessionsForMail(state, agent, tag) {
|
|
65
|
+
for (const key of Object.keys(state.sessions)) {
|
|
66
|
+
if (!ownsSessionKey(agent, key))
|
|
67
|
+
continue;
|
|
68
|
+
if (state.session_mail?.[key] === tag && state.sessions[key])
|
|
69
|
+
continue;
|
|
70
|
+
delete state.sessions[key];
|
|
71
|
+
if (state.session_mail)
|
|
72
|
+
delete state.session_mail[key];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
46
75
|
/** Why `key` is cooling down, for a message. */
|
|
47
76
|
const cooldownKind = (cd, key) => cd.toJSON()[key]?.kind ?? "unknown";
|
|
48
77
|
/** `runtime/model`, or the runtime alone for its default model. */
|
|
@@ -590,6 +619,16 @@ export class RunSession {
|
|
|
590
619
|
};
|
|
591
620
|
// Without a fallback chain (one candidate) the loop, its output and its records are exactly those of plain retries (spec 20.2 decision 11).
|
|
592
621
|
// A lead's `tier` (spec 24.5.3): only for an agent with a ladder, and only a valid value counts.
|
|
622
|
+
const messageIds = unread.map((m) => m.meta.id);
|
|
623
|
+
const tag = mailTag(messageIds);
|
|
624
|
+
// A new mail drops every stored transcript. A redo keeps only a session saved for this same mail.
|
|
625
|
+
if (agent.resume) {
|
|
626
|
+
const opening = priorFailedAttempts(runDir, agent.name, messageIds, "wake");
|
|
627
|
+
if (opening.prior.length > 0)
|
|
628
|
+
retainSessionsForMail(state, agent.name, tag);
|
|
629
|
+
else
|
|
630
|
+
dropAgentSessions(state, agent.name);
|
|
631
|
+
}
|
|
593
632
|
const tier = agent.tiers && agent.tiers.length >= 2 ? wakeTier(unread.map((m) => m.meta.tier)) : undefined;
|
|
594
633
|
const all = candidatesFor(agent, tier && agent.tiers ? modelForTier(agent.tiers, tier) : undefined);
|
|
595
634
|
const chain = all.length > 1;
|
|
@@ -664,11 +703,12 @@ export class RunSession {
|
|
|
664
703
|
const started = Date.now();
|
|
665
704
|
const att = beginAttempt(runDir, claim.id);
|
|
666
705
|
// Looked up again for every call: a retry sees what the attempt before it just set aside.
|
|
667
|
-
const redo = this.redoContext(agent.name,
|
|
668
|
-
const userPrompt = redoUserPrompt(base.userPrompt, { attempt, error: ctx.previous?.error, prior: redo.prior, drafts: redo.drafts, taskMemory: agent.memory.task });
|
|
706
|
+
const redo = this.redoContext(agent.name, messageIds, att.id, attempt);
|
|
669
707
|
const retryN = chain ? ctx.candidateAttempt : attempt;
|
|
670
708
|
say(`[round ${roundsLabel(state.rounds, state.max_rounds)}] waking ${agent.name} (${chain ? modelLabel(c) : agent.runtime}${c.tiered ? `, tier ${tier}` : ""})${retryN ? ` — retry ${retryN}` : ""}`);
|
|
671
|
-
|
|
709
|
+
// Retry and redo load the session stored before this attempt. A new mail stored nothing (it was dropped above).
|
|
710
|
+
const sessionId = agent.resume && (attempt > 0 || redo.prior.length > 0) ? state.sessions[sessionKey] : undefined;
|
|
711
|
+
const userPrompt = redoUserPrompt(base.userPrompt, { attempt, error: ctx.previous?.error, prior: redo.prior, drafts: redo.drafts, taskMemory: agent.memory.task });
|
|
672
712
|
const handling = unread.map((m) => ({ from: m.meta.from, type: m.meta.type, subject: m.meta.subject, brief: briefOf(m.body), digest: digestOf(m.meta.type, m.body) }));
|
|
673
713
|
// What the panel shows for the message being worked on is uncut; the wake record below keeps the short digest.
|
|
674
714
|
const activeHandling = unread.map((m, i) => ({ ...handling[i], digest: digestOf(m.meta.type, m.body, true) }));
|
|
@@ -688,8 +728,10 @@ export class RunSession {
|
|
|
688
728
|
timedOut: false,
|
|
689
729
|
error: e.message,
|
|
690
730
|
}));
|
|
691
|
-
if (result.sessionId && agent.resume)
|
|
731
|
+
if (result.ok && result.sessionId && agent.resume) {
|
|
692
732
|
state.sessions[sessionKey] = result.sessionId;
|
|
733
|
+
state.session_mail = { ...state.session_mail, [sessionKey]: tag };
|
|
734
|
+
}
|
|
693
735
|
if (result.outputTokens)
|
|
694
736
|
state.output_tokens += result.outputTokens;
|
|
695
737
|
state.cache_read_tokens += result.cacheReadTokens ?? 0;
|
package/dist/run-store.d.ts
CHANGED
|
@@ -143,6 +143,11 @@ export interface RunState {
|
|
|
143
143
|
/** The pull request the dispatcher opened for this run (when the lead asked for one and it worked). */
|
|
144
144
|
pr_url?: string;
|
|
145
145
|
sessions: Record<string, string>;
|
|
146
|
+
/**
|
|
147
|
+
* Which mail each `sessions` entry belongs to (`mailTag` of the message ids).
|
|
148
|
+
* Absent on runs saved before a session was tied to its mail. A redo resumes an entry only when this matches.
|
|
149
|
+
*/
|
|
150
|
+
session_mail?: Record<string, string>;
|
|
146
151
|
output_tokens: number;
|
|
147
152
|
/** Run totals of the wakes' prompt-cache input tokens (0 for runs before this was recorded, and for codex). */
|
|
148
153
|
cache_read_tokens: number;
|
package/dist/run-store.js
CHANGED
|
@@ -58,6 +58,7 @@ const WireState = z
|
|
|
58
58
|
notes: z.array(z.string()).optional(),
|
|
59
59
|
ask_rejections: z.record(z.string(), nonNeg).optional(),
|
|
60
60
|
sessions: z.record(z.string(), z.string()).optional(),
|
|
61
|
+
session_mail: z.record(z.string(), z.string()).optional(),
|
|
61
62
|
output_tokens: nonNeg.optional(),
|
|
62
63
|
cache_read_tokens: nonNeg.optional(),
|
|
63
64
|
cache_write_tokens: nonNeg.optional(),
|
package/dist/scaffold.js
CHANGED
|
@@ -105,7 +105,7 @@ dispatcher:
|
|
|
105
105
|
agents:
|
|
106
106
|
# Fields not set here are inherited from the global team.yaml.
|
|
107
107
|
lead:
|
|
108
|
-
resume: true #
|
|
108
|
+
resume: true # retry and redo of the same mail may resume its session; a new mail starts fresh
|
|
109
109
|
can_message: all
|
|
110
110
|
can_edit_agent_md: true
|
|
111
111
|
fe-member:
|