aglio-worker 0.101.2 → 0.101.23

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.
Files changed (2) hide show
  1. package/agent.js +132 -26
  2. package/package.json +1 -1
package/agent.js CHANGED
@@ -50183,7 +50183,16 @@ var RUN_STATUSES_FOR_SCHEMA = [
50183
50183
  "cancelled",
50184
50184
  "skipped"
50185
50185
  ];
50186
- var RUN_KINDS = ["planning", "agent", "build", "consult", "review", "workspace_consult", "job"];
50186
+ var RUN_KINDS = [
50187
+ "planning",
50188
+ "agent",
50189
+ "overseer",
50190
+ "build",
50191
+ "consult",
50192
+ "review",
50193
+ "workspace_consult",
50194
+ "job"
50195
+ ];
50187
50196
  var AGENT_DRIVERS = ["pi", "claude", "codex", "cursor", "opencode", "antigravity", "hermes"];
50188
50197
  var QUESTION_TYPES = ["single", "multi", "text"];
50189
50198
  var VERIFICATION_KINDS = ["test_output", "screenshot", "recording", "not_applicable"];
@@ -50206,6 +50215,7 @@ var RUN_TRIGGERS = [
50206
50215
  "review_poll",
50207
50216
  "planning_chat",
50208
50217
  "agent_chat",
50218
+ "auto_mode",
50209
50219
  "followup",
50210
50220
  "workspace_chat",
50211
50221
  "schedule"
@@ -70493,7 +70503,11 @@ var autoModeStateSchema = external_exports.object({
70493
70503
  /** Last tick decision, so the board can say what it checked and skipped. */
70494
70504
  lastTick: autoModeTickSchema.nullable().default(null),
70495
70505
  /** Set when a tick starts, so two triggers cannot plan at once. */
70496
- tickStartedAt: external_exports.string().datetime().nullable().default(null)
70506
+ tickStartedAt: external_exports.string().datetime().nullable().default(null),
70507
+ /** Ticket/PR digest seen by the last overseer wake. New state wakes it again. */
70508
+ overseerSignature: external_exports.string().nullable().default(null),
70509
+ /** When the live overseer last woke, so the board can show it is watching. */
70510
+ lastOverseerAt: external_exports.string().datetime().nullable().default(null)
70497
70511
  });
70498
70512
  var defaultAutoModeState = {
70499
70513
  paused: false,
@@ -70502,7 +70516,9 @@ var defaultAutoModeState = {
70502
70516
  consecutiveFailures: 0,
70503
70517
  lastPlannerRunAt: null,
70504
70518
  lastTick: null,
70505
- tickStartedAt: null
70519
+ tickStartedAt: null,
70520
+ overseerSignature: null,
70521
+ lastOverseerAt: null
70506
70522
  };
70507
70523
  var autoModeSettingsSchema = external_exports.object({
70508
70524
  enabled: external_exports.boolean().default(false),
@@ -86005,7 +86021,23 @@ async function runRemoteCardJob(deps) {
86005
86021
  } catch (error63) {
86006
86022
  return { state: "failed", error: `Could not load run context: ${errorText2(error63)}` };
86007
86023
  }
86008
- const claim3 = await deps.api.claimRun?.(lease).catch(() => "started") ?? "started";
86024
+ let claim3 = "started";
86025
+ if (deps.api.claimRun) {
86026
+ let lastError = null;
86027
+ for (let attempt = 1; attempt <= 3; attempt += 1) {
86028
+ try {
86029
+ claim3 = await deps.api.claimRun(lease);
86030
+ lastError = null;
86031
+ break;
86032
+ } catch (error63) {
86033
+ lastError = error63;
86034
+ if (attempt < 3) await new Promise((resolve7) => setTimeout(resolve7, attempt * 1e3));
86035
+ }
86036
+ }
86037
+ if (lastError) {
86038
+ return { state: "failed", error: `Could not claim run: ${errorText2(lastError)}` };
86039
+ }
86040
+ }
86009
86041
  if (claim3 === "waiting") {
86010
86042
  write("[aglio] waiting for a free run slot\n");
86011
86043
  return { state: "succeeded", error: null };
@@ -86066,8 +86098,35 @@ async function runRemoteCardJob(deps) {
86066
86098
  log: (message) => deps.log?.(message)
86067
86099
  });
86068
86100
  const repoPaths = await cloneRepos();
86069
- const restoredSessionId = await restoreRunContext(repoPaths, context);
86070
- if (restoredSessionId && !context.run.sessionId) context.run.sessionId = restoredSessionId;
86101
+ const repoStartHeads = await Promise.all(
86102
+ repoPaths.map(async (target) => {
86103
+ const targetRun = containerPath(runRoot, workspace, target);
86104
+ return gitOutput(["-C", targetRun, "rev-parse", "HEAD"]).then((value) => value.trim()).catch(() => "");
86105
+ })
86106
+ );
86107
+ const restore = await restoreRunContext(repoPaths, context);
86108
+ if (!context.run.sessionId && restore.sessionId && restore.driver === context.agent.driver && restore.agentConfigId === context.agent.id) {
86109
+ context.run.sessionId = restore.sessionId;
86110
+ }
86111
+ const expectedResume = Boolean(context.run.sessionId);
86112
+ let sessionResumeStatus = "fresh";
86113
+ let sessionResumeReason = null;
86114
+ if (expectedResume) {
86115
+ const resumed = context.run.restoreContextArtifactId ? restore.restored : true;
86116
+ if (resumed) {
86117
+ sessionResumeStatus = "resumed";
86118
+ const resumePrompt = context.run.resumePrompt?.trim();
86119
+ if (resumePrompt) context.prompt = resumePrompt;
86120
+ } else {
86121
+ sessionResumeStatus = "restarted";
86122
+ sessionResumeReason = "The inherited session snapshot could not be restored, so this run started a fresh session.";
86123
+ context.run.sessionId = null;
86124
+ }
86125
+ } else if (context.run.restoreContextArtifactId) {
86126
+ sessionResumeStatus = "restarted";
86127
+ sessionResumeReason = "The inherited context has no resumable session for this agent, so this run started a fresh session.";
86128
+ }
86129
+ await status({ sessionResumeStatus, sessionResumeReason });
86071
86130
  if (context.run.kind === "workspace_consult") {
86072
86131
  await rm3(gitConfigPath, { force: true }).catch(() => void 0);
86073
86132
  }
@@ -86091,7 +86150,7 @@ async function runRemoteCardJob(deps) {
86091
86150
  systemPromptAppend: context.systemPromptAppend
86092
86151
  });
86093
86152
  const exit = await runAgent(command, env);
86094
- await uploadRunContext(repoPaths, context, exit.sessionId).catch((error63) => {
86153
+ await uploadRunContext(repoPaths, context, exit.sessionId, repoStartHeads).catch((error63) => {
86095
86154
  write(`[aglio] context snapshot failed: ${errorText2(error63)}
86096
86155
  `);
86097
86156
  });
@@ -86454,8 +86513,8 @@ async function runRemoteCardJob(deps) {
86454
86513
  if (driver === "hermes") return ["sessions"];
86455
86514
  return [];
86456
86515
  }
86457
- async function uploadRunContext(repoPaths, current, sessionId) {
86458
- if (!current.card || current.run.kind === "workspace_consult") return;
86516
+ async function uploadRunContext(repoPaths, current, sessionId, baseHeads) {
86517
+ if (!current.card && current.run.kind !== "workspace_consult") return;
86459
86518
  const staging = join5(workspace, ".aglio", "context");
86460
86519
  const archivePath = join5(workspace, ".aglio", `run-context-${current.run.id}.tar.gz`);
86461
86520
  await rm3(staging, { recursive: true, force: true }).catch(() => void 0);
@@ -86465,6 +86524,7 @@ async function runRemoteCardJob(deps) {
86465
86524
  version: 1,
86466
86525
  runId: current.run.id,
86467
86526
  driver: current.agent.driver,
86527
+ agentConfigId: current.agent.id,
86468
86528
  sessionId: sessionId ?? current.run.sessionId,
86469
86529
  sessionDirs: [],
86470
86530
  repos: [],
@@ -86475,7 +86535,7 @@ async function runRemoteCardJob(deps) {
86475
86535
  if (!repo) continue;
86476
86536
  const targetRun = containerPath(runRoot, workspace, target);
86477
86537
  const base = repo.baseBranch || "main";
86478
- const baseRef = (await runGit(workspace, ["-C", targetRun, "rev-parse", "--verify", `origin/${base}`])).code === 0 ? `origin/${base}` : base;
86538
+ const baseRef = baseHeads[index3] || ((await runGit(workspace, ["-C", targetRun, "rev-parse", "--verify", `origin/${base}`])).code === 0 ? `origin/${base}` : base);
86479
86539
  const patchRel = `repo-${index3}.patch`;
86480
86540
  const patchPath = join5(staging, patchRel);
86481
86541
  const indexFile = join5(staging, `index-${index3}`);
@@ -86563,7 +86623,9 @@ async function runRemoteCardJob(deps) {
86563
86623
  }
86564
86624
  async function restoreRunContext(repoPaths, current) {
86565
86625
  const artifactId = current.run.restoreContextArtifactId;
86566
- if (!artifactId) return null;
86626
+ if (!artifactId) {
86627
+ return { sessionId: null, restored: false, driver: null, agentConfigId: null };
86628
+ }
86567
86629
  const restoreDir = join5(workspace, ".aglio", "context-restore");
86568
86630
  const archivePath = join5(restoreDir, "context.tar.gz");
86569
86631
  await rm3(restoreDir, { recursive: true, force: true }).catch(() => void 0);
@@ -86574,7 +86636,7 @@ async function runRemoteCardJob(deps) {
86574
86636
  } catch (error63) {
86575
86637
  write(`[aglio] context restore download failed: ${errorText2(error63)}
86576
86638
  `);
86577
- return null;
86639
+ return { sessionId: null, restored: false, driver: null, agentConfigId: null };
86578
86640
  }
86579
86641
  await writeFile(archivePath, data);
86580
86642
  const unpacked = await deps.runCommand({
@@ -86586,12 +86648,12 @@ async function runRemoteCardJob(deps) {
86586
86648
  });
86587
86649
  if (unpacked !== 0) {
86588
86650
  write("[aglio] context restore unpack failed\n");
86589
- return null;
86651
+ return { sessionId: null, restored: false, driver: null, agentConfigId: null };
86590
86652
  }
86591
86653
  const manifest = await readFile2(join5(restoreDir, "manifest.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
86592
86654
  if (!manifest) {
86593
86655
  write("[aglio] context restore manifest missing\n");
86594
- return null;
86656
+ return { sessionId: null, restored: false, driver: null, agentConfigId: null };
86595
86657
  }
86596
86658
  for (const [index3, repo] of (manifest.repos ?? []).entries()) {
86597
86659
  if (!repo.patch) continue;
@@ -86614,6 +86676,7 @@ async function runRemoteCardJob(deps) {
86614
86676
  }
86615
86677
  }
86616
86678
  }
86679
+ let restoredSessions = 0;
86617
86680
  for (const session of manifest.sessionDirs ?? []) {
86618
86681
  if (!session.path || !session.archive) continue;
86619
86682
  const target = resolve4(toolDir, session.path);
@@ -86627,11 +86690,19 @@ async function runRemoteCardJob(deps) {
86627
86690
  signal: deps.signal,
86628
86691
  onOutput: () => void 0
86629
86692
  });
86630
- if (restored === 0) write(`[aglio] restored session ${session.path}
86693
+ if (restored === 0) {
86694
+ restoredSessions += 1;
86695
+ write(`[aglio] restored session ${session.path}
86631
86696
  `);
86697
+ }
86632
86698
  }
86633
86699
  await rm3(restoreDir, { recursive: true, force: true }).catch(() => void 0);
86634
- return manifest.sessionId ?? null;
86700
+ return {
86701
+ sessionId: manifest.sessionId ?? null,
86702
+ restored: restoredSessions > 0,
86703
+ driver: manifest.driver ?? null,
86704
+ agentConfigId: manifest.agentConfigId ?? null
86705
+ };
86635
86706
  }
86636
86707
  async function gitOutput(args) {
86637
86708
  let output2 = "";
@@ -86692,7 +86763,8 @@ async function runRemoteCardJob(deps) {
86692
86763
  let consumeQueue = Promise.resolve();
86693
86764
  const isPlanning = context.run.kind === "planning";
86694
86765
  const isAgent = context.run.kind === "agent";
86695
- const isChat = isPlanning || isAgent;
86766
+ const isOverseer = context.run.kind === "overseer";
86767
+ const isChat = isPlanning || isAgent || isOverseer;
86696
86768
  const isConsult = context.run.kind === "workspace_consult";
86697
86769
  const emitLive = async (events) => {
86698
86770
  if (events.length === 0) return;
@@ -99861,10 +99933,10 @@ function createServerForRun(run) {
99861
99933
  server.registerTool(
99862
99934
  "card_get",
99863
99935
  {
99864
- description: "Read the current card, subtickets, comments, work log, linked PRs and feedback.",
99865
- inputSchema: {}
99936
+ description: "Read a card with subtickets, comments, work log, linked PRs, recent runs and feedback. Auto mode overseer may pass cardId or cardNumber to read any ticket in its goal.",
99937
+ inputSchema: { cardId: external_exports.string().optional(), cardNumber: external_exports.number().int().positive().optional() }
99866
99938
  },
99867
- async () => forward("card_get", {})
99939
+ async (input2) => forward("card_get", input2)
99868
99940
  );
99869
99941
  server.registerTool(
99870
99942
  "repo_list",
@@ -99874,28 +99946,40 @@ function createServerForRun(run) {
99874
99946
  server.registerTool(
99875
99947
  "pr_get",
99876
99948
  {
99877
- description: "Read linked pull requests, or one PR with reviews, comments and checks.",
99878
- inputSchema: { repoId: external_exports.string().optional(), number: external_exports.number().int().optional() }
99949
+ description: "Read linked pull requests, or one PR with reviews, comments and checks. The overseer may pass cardId or cardNumber to read a goal ticket's PRs.",
99950
+ inputSchema: {
99951
+ repoId: external_exports.string().optional(),
99952
+ number: external_exports.number().int().optional(),
99953
+ cardId: external_exports.string().optional(),
99954
+ cardNumber: external_exports.number().int().positive().optional()
99955
+ }
99879
99956
  },
99880
99957
  async (input2) => forward("pr_get", input2)
99881
99958
  );
99882
99959
  server.registerTool(
99883
99960
  "comment_add",
99884
99961
  {
99885
- description: "Post a comment on the card. Pass parentCommentId to answer inside a thread; a consult started from a comment replies there by default.",
99886
- inputSchema: { body: external_exports.string().min(1).max(2e4), parentCommentId: external_exports.string().optional() }
99962
+ description: "Post a comment on the card. Pass parentCommentId to answer inside a thread; a consult started from a comment replies there by default. The overseer may pass cardId or cardNumber to comment on a goal ticket.",
99963
+ inputSchema: {
99964
+ body: external_exports.string().min(1).max(2e4),
99965
+ parentCommentId: external_exports.string().optional(),
99966
+ cardId: external_exports.string().optional(),
99967
+ cardNumber: external_exports.number().int().positive().optional()
99968
+ }
99887
99969
  },
99888
99970
  async (input2) => forward("comment_add", input2)
99889
99971
  );
99890
99972
  server.registerTool(
99891
99973
  "worklog_add",
99892
99974
  {
99893
- description: "Add a short work log entry. Keep summaries to one or two short sentences.",
99975
+ description: "Add a short work log entry. Keep summaries to one or two short sentences. The overseer may pass cardId or cardNumber to log on a goal ticket.",
99894
99976
  inputSchema: {
99895
99977
  type: external_exports.enum(WORK_LOG_TYPES),
99896
99978
  summary: external_exports.string().min(1).max(400),
99897
99979
  details: external_exports.string().max(2e4).optional(),
99898
- artifactIds: external_exports.array(external_exports.string()).optional()
99980
+ artifactIds: external_exports.array(external_exports.string()).optional(),
99981
+ cardId: external_exports.string().optional(),
99982
+ cardNumber: external_exports.number().int().positive().optional()
99899
99983
  }
99900
99984
  },
99901
99985
  async (input2) => forward("worklog_add", input2)
@@ -100116,6 +100200,28 @@ function createServerForRun(run) {
100116
100200
  return forward("pr_open", input2);
100117
100201
  }
100118
100202
  );
100203
+ server.registerTool(
100204
+ "pr_merge",
100205
+ {
100206
+ description: "Auto mode overseer only. Merge the green pull request of one goal ticket and move the ticket to Done. Refuses while checks are pending or failed, or when the PR touches PLAN.md or a rejected file.",
100207
+ inputSchema: {
100208
+ cardId: external_exports.string().optional(),
100209
+ cardNumber: external_exports.number().int().positive().optional()
100210
+ }
100211
+ },
100212
+ async (input2) => forward("pr_merge", input2)
100213
+ );
100214
+ server.registerTool(
100215
+ "card_retry",
100216
+ {
100217
+ description: "Auto mode overseer only. Retry the latest failed or cancelled run of one goal ticket, with the same agent and prompt.",
100218
+ inputSchema: {
100219
+ cardId: external_exports.string().optional(),
100220
+ cardNumber: external_exports.number().int().positive().optional()
100221
+ }
100222
+ },
100223
+ async (input2) => forward("card_retry", input2)
100224
+ );
100119
100225
  return server;
100120
100226
  }
100121
100227
  function createRemoteMcpHost(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aglio-worker",
3
- "version": "0.101.2",
3
+ "version": "0.101.23",
4
4
  "description": "Host machine agent for Aglio: claims jobs over the API and starts aglio-runner containers.",
5
5
  "type": "module",
6
6
  "bin": {