aglio-worker 0.101.0 → 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 +137 -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", "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"];
@@ -50205,6 +50214,8 @@ var RUN_TRIGGERS = [
50205
50214
  "mention",
50206
50215
  "review_poll",
50207
50216
  "planning_chat",
50217
+ "agent_chat",
50218
+ "auto_mode",
50208
50219
  "followup",
50209
50220
  "workspace_chat",
50210
50221
  "schedule"
@@ -70492,7 +70503,11 @@ var autoModeStateSchema = external_exports.object({
70492
70503
  /** Last tick decision, so the board can say what it checked and skipped. */
70493
70504
  lastTick: autoModeTickSchema.nullable().default(null),
70494
70505
  /** Set when a tick starts, so two triggers cannot plan at once. */
70495
- 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)
70496
70511
  });
70497
70512
  var defaultAutoModeState = {
70498
70513
  paused: false,
@@ -70501,7 +70516,9 @@ var defaultAutoModeState = {
70501
70516
  consecutiveFailures: 0,
70502
70517
  lastPlannerRunAt: null,
70503
70518
  lastTick: null,
70504
- tickStartedAt: null
70519
+ tickStartedAt: null,
70520
+ overseerSignature: null,
70521
+ lastOverseerAt: null
70505
70522
  };
70506
70523
  var autoModeSettingsSchema = external_exports.object({
70507
70524
  enabled: external_exports.boolean().default(false),
@@ -86004,7 +86021,23 @@ async function runRemoteCardJob(deps) {
86004
86021
  } catch (error63) {
86005
86022
  return { state: "failed", error: `Could not load run context: ${errorText2(error63)}` };
86006
86023
  }
86007
- 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
+ }
86008
86041
  if (claim3 === "waiting") {
86009
86042
  write("[aglio] waiting for a free run slot\n");
86010
86043
  return { state: "succeeded", error: null };
@@ -86065,7 +86098,35 @@ async function runRemoteCardJob(deps) {
86065
86098
  log: (message) => deps.log?.(message)
86066
86099
  });
86067
86100
  const repoPaths = await cloneRepos();
86068
- await restoreRunContext(repoPaths, context);
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 });
86069
86130
  if (context.run.kind === "workspace_consult") {
86070
86131
  await rm3(gitConfigPath, { force: true }).catch(() => void 0);
86071
86132
  }
@@ -86089,7 +86150,7 @@ async function runRemoteCardJob(deps) {
86089
86150
  systemPromptAppend: context.systemPromptAppend
86090
86151
  });
86091
86152
  const exit = await runAgent(command, env);
86092
- await uploadRunContext(repoPaths, context).catch((error63) => {
86153
+ await uploadRunContext(repoPaths, context, exit.sessionId, repoStartHeads).catch((error63) => {
86093
86154
  write(`[aglio] context snapshot failed: ${errorText2(error63)}
86094
86155
  `);
86095
86156
  });
@@ -86452,8 +86513,8 @@ async function runRemoteCardJob(deps) {
86452
86513
  if (driver === "hermes") return ["sessions"];
86453
86514
  return [];
86454
86515
  }
86455
- async function uploadRunContext(repoPaths, current) {
86456
- 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;
86457
86518
  const staging = join5(workspace, ".aglio", "context");
86458
86519
  const archivePath = join5(workspace, ".aglio", `run-context-${current.run.id}.tar.gz`);
86459
86520
  await rm3(staging, { recursive: true, force: true }).catch(() => void 0);
@@ -86463,7 +86524,8 @@ async function runRemoteCardJob(deps) {
86463
86524
  version: 1,
86464
86525
  runId: current.run.id,
86465
86526
  driver: current.agent.driver,
86466
- sessionId: current.run.sessionId,
86527
+ agentConfigId: current.agent.id,
86528
+ sessionId: sessionId ?? current.run.sessionId,
86467
86529
  sessionDirs: [],
86468
86530
  repos: [],
86469
86531
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
@@ -86473,7 +86535,7 @@ async function runRemoteCardJob(deps) {
86473
86535
  if (!repo) continue;
86474
86536
  const targetRun = containerPath(runRoot, workspace, target);
86475
86537
  const base = repo.baseBranch || "main";
86476
- 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);
86477
86539
  const patchRel = `repo-${index3}.patch`;
86478
86540
  const patchPath = join5(staging, patchRel);
86479
86541
  const indexFile = join5(staging, `index-${index3}`);
@@ -86561,7 +86623,9 @@ async function runRemoteCardJob(deps) {
86561
86623
  }
86562
86624
  async function restoreRunContext(repoPaths, current) {
86563
86625
  const artifactId = current.run.restoreContextArtifactId;
86564
- if (!artifactId) return;
86626
+ if (!artifactId) {
86627
+ return { sessionId: null, restored: false, driver: null, agentConfigId: null };
86628
+ }
86565
86629
  const restoreDir = join5(workspace, ".aglio", "context-restore");
86566
86630
  const archivePath = join5(restoreDir, "context.tar.gz");
86567
86631
  await rm3(restoreDir, { recursive: true, force: true }).catch(() => void 0);
@@ -86572,7 +86636,7 @@ async function runRemoteCardJob(deps) {
86572
86636
  } catch (error63) {
86573
86637
  write(`[aglio] context restore download failed: ${errorText2(error63)}
86574
86638
  `);
86575
- return;
86639
+ return { sessionId: null, restored: false, driver: null, agentConfigId: null };
86576
86640
  }
86577
86641
  await writeFile(archivePath, data);
86578
86642
  const unpacked = await deps.runCommand({
@@ -86584,12 +86648,12 @@ async function runRemoteCardJob(deps) {
86584
86648
  });
86585
86649
  if (unpacked !== 0) {
86586
86650
  write("[aglio] context restore unpack failed\n");
86587
- return;
86651
+ return { sessionId: null, restored: false, driver: null, agentConfigId: null };
86588
86652
  }
86589
86653
  const manifest = await readFile2(join5(restoreDir, "manifest.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
86590
86654
  if (!manifest) {
86591
86655
  write("[aglio] context restore manifest missing\n");
86592
- return;
86656
+ return { sessionId: null, restored: false, driver: null, agentConfigId: null };
86593
86657
  }
86594
86658
  for (const [index3, repo] of (manifest.repos ?? []).entries()) {
86595
86659
  if (!repo.patch) continue;
@@ -86612,6 +86676,7 @@ async function runRemoteCardJob(deps) {
86612
86676
  }
86613
86677
  }
86614
86678
  }
86679
+ let restoredSessions = 0;
86615
86680
  for (const session of manifest.sessionDirs ?? []) {
86616
86681
  if (!session.path || !session.archive) continue;
86617
86682
  const target = resolve4(toolDir, session.path);
@@ -86625,10 +86690,19 @@ async function runRemoteCardJob(deps) {
86625
86690
  signal: deps.signal,
86626
86691
  onOutput: () => void 0
86627
86692
  });
86628
- if (restored === 0) write(`[aglio] restored session ${session.path}
86693
+ if (restored === 0) {
86694
+ restoredSessions += 1;
86695
+ write(`[aglio] restored session ${session.path}
86629
86696
  `);
86697
+ }
86630
86698
  }
86631
86699
  await rm3(restoreDir, { recursive: true, force: true }).catch(() => void 0);
86700
+ return {
86701
+ sessionId: manifest.sessionId ?? null,
86702
+ restored: restoredSessions > 0,
86703
+ driver: manifest.driver ?? null,
86704
+ agentConfigId: manifest.agentConfigId ?? null
86705
+ };
86632
86706
  }
86633
86707
  async function gitOutput(args) {
86634
86708
  let output2 = "";
@@ -86688,6 +86762,9 @@ async function runRemoteCardJob(deps) {
86688
86762
  const lastToolUpdateAt = /* @__PURE__ */ new Map();
86689
86763
  let consumeQueue = Promise.resolve();
86690
86764
  const isPlanning = context.run.kind === "planning";
86765
+ const isAgent = context.run.kind === "agent";
86766
+ const isOverseer = context.run.kind === "overseer";
86767
+ const isChat = isPlanning || isAgent || isOverseer;
86691
86768
  const isConsult = context.run.kind === "workspace_consult";
86692
86769
  const emitLive = async (events) => {
86693
86770
  if (events.length === 0) return;
@@ -86696,9 +86773,9 @@ async function runRemoteCardJob(deps) {
86696
86773
  });
86697
86774
  };
86698
86775
  const appendChat = async (text, kind = "text", toolName, toolArgs) => {
86699
- if (!isPlanning && !isConsult) return;
86776
+ if (!isChat && !isConsult) return;
86700
86777
  try {
86701
- const messageId = await (isPlanning ? deps.api.appendPlanningMessage : deps.api.appendConsultMessage)({
86778
+ const messageId = await (isChat ? deps.api.appendPlanningMessage : deps.api.appendConsultMessage)({
86702
86779
  ...lease,
86703
86780
  messageId: kind === "text" ? chatMessageId : null,
86704
86781
  text,
@@ -99856,10 +99933,10 @@ function createServerForRun(run) {
99856
99933
  server.registerTool(
99857
99934
  "card_get",
99858
99935
  {
99859
- description: "Read the current card, subtickets, comments, work log, linked PRs and feedback.",
99860
- 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() }
99861
99938
  },
99862
- async () => forward("card_get", {})
99939
+ async (input2) => forward("card_get", input2)
99863
99940
  );
99864
99941
  server.registerTool(
99865
99942
  "repo_list",
@@ -99869,28 +99946,40 @@ function createServerForRun(run) {
99869
99946
  server.registerTool(
99870
99947
  "pr_get",
99871
99948
  {
99872
- description: "Read linked pull requests, or one PR with reviews, comments and checks.",
99873
- 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
+ }
99874
99956
  },
99875
99957
  async (input2) => forward("pr_get", input2)
99876
99958
  );
99877
99959
  server.registerTool(
99878
99960
  "comment_add",
99879
99961
  {
99880
- description: "Post a comment on the card. Pass parentCommentId to answer inside a thread; a consult started from a comment replies there by default.",
99881
- 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
+ }
99882
99969
  },
99883
99970
  async (input2) => forward("comment_add", input2)
99884
99971
  );
99885
99972
  server.registerTool(
99886
99973
  "worklog_add",
99887
99974
  {
99888
- 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.",
99889
99976
  inputSchema: {
99890
99977
  type: external_exports.enum(WORK_LOG_TYPES),
99891
99978
  summary: external_exports.string().min(1).max(400),
99892
99979
  details: external_exports.string().max(2e4).optional(),
99893
- 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()
99894
99983
  }
99895
99984
  },
99896
99985
  async (input2) => forward("worklog_add", input2)
@@ -100111,6 +100200,28 @@ function createServerForRun(run) {
100111
100200
  return forward("pr_open", input2);
100112
100201
  }
100113
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
+ );
100114
100225
  return server;
100115
100226
  }
100116
100227
  function createRemoteMcpHost(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aglio-worker",
3
- "version": "0.101.0",
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": {