aglio-worker 0.115.0 → 0.115.7

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 +75 -21
  2. package/package.json +1 -1
package/agent.js CHANGED
@@ -71988,8 +71988,8 @@ var CARD_LABEL_COLORS = [
71988
71988
  var CARD_LABEL_COLOR_KEYS = CARD_LABEL_COLORS.map((color) => color.key);
71989
71989
  var DEFAULT_CARD_LABEL_COLOR = "green";
71990
71990
  var CARD_LABEL_NAME_MAX = 40;
71991
- var FALLBACK_COLOR = CARD_LABEL_COLORS[0];
71992
- var cardLabelColorSchema = external_exports.enum(CARD_LABEL_COLOR_KEYS);
71991
+ var HEX_COLOR2 = /^#[0-9a-f]{6}$/;
71992
+ var cardLabelColorSchema = external_exports.union([external_exports.enum(CARD_LABEL_COLOR_KEYS), external_exports.string().trim().toLowerCase().regex(HEX_COLOR2)]).default(DEFAULT_CARD_LABEL_COLOR);
71993
71993
  var cardLabelInputSchema = external_exports.object({
71994
71994
  name: external_exports.string().trim().max(CARD_LABEL_NAME_MAX).default(""),
71995
71995
  color: cardLabelColorSchema.default(DEFAULT_CARD_LABEL_COLOR)
@@ -72756,6 +72756,24 @@ async function pullOnce(client, image, platform2) {
72756
72756
  });
72757
72757
  await readPullStream(stream);
72758
72758
  }
72759
+ function abortable(work, signal) {
72760
+ if (!signal) return work;
72761
+ if (signal.aborted) return Promise.reject(new Error("Runner image pull cancelled"));
72762
+ return new Promise((resolve7, reject) => {
72763
+ const onAbort = () => reject(new Error("Runner image pull cancelled"));
72764
+ signal.addEventListener("abort", onAbort, { once: true });
72765
+ work.then(
72766
+ (value) => {
72767
+ signal.removeEventListener("abort", onAbort);
72768
+ resolve7(value);
72769
+ },
72770
+ (error63) => {
72771
+ signal.removeEventListener("abort", onAbort);
72772
+ reject(error63);
72773
+ }
72774
+ );
72775
+ });
72776
+ }
72759
72777
  async function pullDockerImage(client, image, options = {}) {
72760
72778
  if (!isRegistryImage(image)) {
72761
72779
  throw new Error(
@@ -72763,7 +72781,7 @@ async function pullDockerImage(client, image, options = {}) {
72763
72781
  );
72764
72782
  }
72765
72783
  const existing = inFlight.get(image);
72766
- if (existing) return existing;
72784
+ if (existing) return abortable(existing, options.signal);
72767
72785
  const pull = (async () => {
72768
72786
  try {
72769
72787
  await pullOnce(client, image);
@@ -72778,11 +72796,10 @@ async function pullDockerImage(client, image, options = {}) {
72778
72796
  }
72779
72797
  })();
72780
72798
  inFlight.set(image, pull);
72781
- try {
72782
- await pull;
72783
- } finally {
72784
- inFlight.delete(image);
72785
- }
72799
+ void pull.finally(() => {
72800
+ if (inFlight.get(image) === pull) inFlight.delete(image);
72801
+ }).catch(() => void 0);
72802
+ await abortable(pull, options.signal);
72786
72803
  }
72787
72804
  async function ensureDockerImage(input2) {
72788
72805
  try {
@@ -72797,8 +72814,12 @@ async function ensureDockerImage(input2) {
72797
72814
  }
72798
72815
  input2.log?.("runner image missing, pulling", { image: input2.image });
72799
72816
  try {
72800
- await pullDockerImage(input2.client, input2.image, { log: input2.log });
72817
+ await pullDockerImage(input2.client, input2.image, {
72818
+ log: input2.log,
72819
+ signal: input2.signal
72820
+ });
72801
72821
  } catch (error63) {
72822
+ if (input2.signal?.aborted) throw error63;
72802
72823
  const reason = error63 instanceof Error ? error63.message : String(error63);
72803
72824
  throw new Error(
72804
72825
  `Runner image ${input2.image} not found and could not be pulled: ${reason}. Check registry access or docker login, then retry: docker pull ${input2.image}`
@@ -72930,9 +72951,12 @@ var RUNNER_CACHE_ENTRIES = [
72930
72951
  { id: "composer", containerPath: "/root/.cache/composer", description: "Composer package cache" },
72931
72952
  { id: "maven", containerPath: "/root/.m2/repository", description: "Maven local repository" },
72932
72953
  { id: "gradle", containerPath: "/root/.gradle/caches", description: "Gradle dependency cache" },
72933
- // Only the .deb archive, not /var/lib/apt/lists: package lists are locked per
72934
- // directory, and two concurrent jobs sharing that lock would make one fail.
72935
- { id: "apt", containerPath: "/var/cache/apt/archives", description: "apt .deb download cache" }
72954
+ // Browser builds are directory-per-revision, so two jobs running different
72955
+ // Playwright versions on this host never write the same files.
72956
+ { id: "playwright", containerPath: "/root/.cache/ms-playwright", description: "Playwright browser builds" }
72957
+ // apt is not cached: its archive lock file sits inside the directory, so two
72958
+ // concurrent jobs sharing it fail with "Could not get lock", and a killed
72959
+ // job leaves the lock behind for the next one.
72936
72960
  ];
72937
72961
  var RUNNER_CACHE_VOLUME_PREFIX = "aglio-runner-cache-";
72938
72962
  function runnerCacheEnabled(env = process.env) {
@@ -73039,7 +73063,13 @@ function remoteDockerClient(socketPath) {
73039
73063
  }
73040
73064
  async function createDockerJobExecutor(input2) {
73041
73065
  const client = input2.client ?? remoteDockerClient(input2.socketPath ?? "/var/run/docker.sock");
73042
- await ensureDockerImage({ client, image: input2.image, log: input2.log });
73066
+ await ensureDockerImage({
73067
+ client,
73068
+ image: input2.image,
73069
+ signal: input2.signal,
73070
+ log: input2.log
73071
+ });
73072
+ if (input2.signal?.aborted) throw new Error("Job cancelled before the runner container started");
73043
73073
  const { hostPath } = mapDockerWorkspace({
73044
73074
  workspaceRoot: input2.workspaceRoot,
73045
73075
  hostWorkspaceRoot: input2.hostWorkspaceRoot,
@@ -73883,8 +73913,12 @@ async function executeRemoteJob(job, deps) {
73883
73913
  const leaseAbort = new AbortController();
73884
73914
  const leaseTimer = setInterval(
73885
73915
  () => {
73916
+ if (cancelRequested || leaseLost) {
73917
+ clearInterval(leaseTimer);
73918
+ return;
73919
+ }
73886
73920
  void deps.api.heartbeatLease({ jobId: job.id, leaseId: job.lease.id, token: job.lease.token }).then((result) => {
73887
- if (result && result.cancelled) {
73921
+ if (result && result.cancelled && !cancelRequested) {
73888
73922
  cancelRequested = true;
73889
73923
  leaseAbort.abort();
73890
73924
  log("cancel requested", { jobId: job.id });
@@ -73932,7 +73966,7 @@ ${job.instructions.trim()}
73932
73966
  }
73933
73967
  if (deps.createExecutor) {
73934
73968
  try {
73935
- executor = await deps.createExecutor({ job, workspace });
73969
+ executor = await deps.createExecutor({ job, workspace, signal: leaseAbort.signal });
73936
73970
  } catch (error63) {
73937
73971
  write(`[aglio] executor failed: ${errorText(error63)}
73938
73972
  `);
@@ -74006,6 +74040,10 @@ $ ${step.command}
74006
74040
  if (error63 instanceof JobLeaseLostError || leaseLost) {
74007
74041
  throw new JobLeaseLostError(errorText(error63));
74008
74042
  }
74043
+ if (cancelRequested) {
74044
+ await finish(deps, job, "cancelled", "Cancelled from the board").catch(() => void 0);
74045
+ return "cancelled";
74046
+ }
74009
74047
  if (error63 instanceof JobAbortedError || deps.signal?.aborted) throw new JobAbortedError();
74010
74048
  await finish(deps, job, "failed", errorText(error63)).catch(() => void 0);
74011
74049
  return "failed";
@@ -74240,7 +74278,7 @@ function buildDriverCommand(input2) {
74240
74278
  if (input2.tools && input2.tools.length > 0) args.push("--tools", input2.tools.join(","));
74241
74279
  if (input2.systemPromptAppend) args.push("--append-system-prompt", input2.systemPromptAppend);
74242
74280
  if (input2.resume && input2.sessionId) {
74243
- args.push("--session", input2.sessionId);
74281
+ args.push("--fork", input2.sessionId);
74244
74282
  } else if (input2.sessionId) {
74245
74283
  args.push("--session-id", input2.sessionId);
74246
74284
  }
@@ -87618,7 +87656,7 @@ async function runRemoteCardJob(deps) {
87618
87656
  deps.log?.("run events update failed", { error: errorText2(eventError) });
87619
87657
  });
87620
87658
  };
87621
- const appendChat = async (text, kind = "text", toolName, toolArgs) => {
87659
+ const appendChat = async (text, kind = "text", toolName, toolArgs, replace = false) => {
87622
87660
  if (!isChat && !isConsult) return;
87623
87661
  try {
87624
87662
  const messageId = await (isChat ? deps.api.appendPlanningMessage : deps.api.appendConsultMessage)({
@@ -87627,7 +87665,8 @@ async function runRemoteCardJob(deps) {
87627
87665
  text,
87628
87666
  kind,
87629
87667
  toolName: toolName ?? null,
87630
- toolArgs: toolArgs ?? null
87668
+ toolArgs: toolArgs ?? null,
87669
+ replace
87631
87670
  });
87632
87671
  if (kind === "text") chatMessageId = messageId;
87633
87672
  } catch (chatError) {
@@ -87720,7 +87759,9 @@ async function runRemoteCardJob(deps) {
87720
87759
  if (parsed.assistantText) {
87721
87760
  await flushThinking(true);
87722
87761
  const text = parsed.assistantText;
87723
- const duplicateFinal = Boolean(messageText && text && messageText.endsWith(text));
87762
+ const duplicateFinal = Boolean(
87763
+ messageText && text && (parsed.messageEnd || messageText.endsWith(text))
87764
+ );
87724
87765
  if (!duplicateFinal) {
87725
87766
  if (parsed.assistantDelta) {
87726
87767
  messageText += text;
@@ -87737,6 +87778,9 @@ async function runRemoteCardJob(deps) {
87737
87778
  if (parsed.messageEnd) {
87738
87779
  await flushAssistant(true);
87739
87780
  await flushThinking(true);
87781
+ if (chatMessageId && messageText && text && text !== messageText) {
87782
+ await appendChat(text, "text", null, null, true);
87783
+ }
87740
87784
  finalMessage = text || messageText;
87741
87785
  messageText = "";
87742
87786
  thinkingText = "";
@@ -87859,6 +87903,14 @@ async function runRemoteCardJob(deps) {
87859
87903
  usage: usagePatch
87860
87904
  });
87861
87905
  }
87906
+ if ((isChat || isConsult) && !error63 && !assistantTextSeen && !finalMessage) {
87907
+ return complete({
87908
+ error: stderr.trim().slice(-2e3) || "Agent exited without a reply",
87909
+ sessionId,
87910
+ finalMessage,
87911
+ usage: usagePatch
87912
+ });
87913
+ }
87862
87914
  return complete({ error: null, sessionId, finalMessage, usage: usagePatch });
87863
87915
  }
87864
87916
  }
@@ -88402,7 +88454,8 @@ async function appendRunMessage(config2, fetchImpl, signal, input2, _channel) {
88402
88454
  text: input2.text,
88403
88455
  kind: input2.kind ?? "text",
88404
88456
  toolName: input2.toolName ?? null,
88405
- toolArgs: input2.toolArgs ?? null
88457
+ toolArgs: input2.toolArgs ?? null,
88458
+ replace: input2.replace === true
88406
88459
  }),
88407
88460
  signal
88408
88461
  }
@@ -101963,11 +102016,12 @@ async function main() {
101963
102016
  signal: controller.signal,
101964
102017
  mcpHost: mcpHost ?? void 0,
101965
102018
  runRoot: (workspace) => mode === "docker" ? "/workspace" : workspace,
101966
- createExecutor: mode === "docker" ? ({ job, workspace }) => createDockerJobExecutor({
102019
+ createExecutor: mode === "docker" ? ({ job, workspace, signal }) => createDockerJobExecutor({
101967
102020
  jobId: job.id,
101968
102021
  workspace,
101969
102022
  workspaceRoot,
101970
102023
  hostWorkspaceRoot,
102024
+ signal,
101971
102025
  image: job.runnerImage ?? resolveRunnerImage({
101972
102026
  requiredLabels: job.requiredLabels,
101973
102027
  images: runnerImages,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aglio-worker",
3
- "version": "0.115.0",
3
+ "version": "0.115.7",
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": {