aglio-worker 0.98.0 → 0.101.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.
Files changed (2) hide show
  1. package/agent.js +211 -116
  2. package/package.json +1 -1
package/agent.js CHANGED
@@ -50183,11 +50183,11 @@ var RUN_STATUSES_FOR_SCHEMA = [
50183
50183
  "cancelled",
50184
50184
  "skipped"
50185
50185
  ];
50186
- var RUN_KINDS = ["planning", "build", "consult", "review", "workspace_consult", "job"];
50187
- var AGENT_DRIVERS = ["pi", "claude", "codex", "gemini", "cursor", "opencode", "antigravity", "hermes"];
50186
+ var RUN_KINDS = ["planning", "agent", "build", "consult", "review", "workspace_consult", "job"];
50187
+ var AGENT_DRIVERS = ["pi", "claude", "codex", "cursor", "opencode", "antigravity", "hermes"];
50188
50188
  var QUESTION_TYPES = ["single", "multi", "text"];
50189
50189
  var VERIFICATION_KINDS = ["test_output", "screenshot", "recording", "not_applicable"];
50190
- var ARTIFACT_KINDS = ["image", "log", "file", "recording", "canvas"];
50190
+ var ARTIFACT_KINDS = ["image", "log", "file", "recording", "canvas", "context"];
50191
50191
  var WORK_LOG_TYPES = [
50192
50192
  "summary",
50193
50193
  "decision",
@@ -50205,6 +50205,7 @@ var RUN_TRIGGERS = [
50205
50205
  "mention",
50206
50206
  "review_poll",
50207
50207
  "planning_chat",
50208
+ "agent_chat",
50208
50209
  "followup",
50209
50210
  "workspace_chat",
50210
50211
  "schedule"
@@ -71166,27 +71167,10 @@ var PROVIDERS = [
71166
71167
  {
71167
71168
  id: "google",
71168
71169
  label: "Google Gemini",
71169
- drivers: ["gemini", "pi", "hermes"],
71170
+ drivers: ["pi", "hermes"],
71170
71171
  models: ["gemini-2.5-pro", "gemini-2.5-flash", "gemini-2.0-flash"],
71171
71172
  connection: { baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai" },
71172
- authOptions: [
71173
- apiKey("GEMINI_API_KEY", ["gemini", "pi", "hermes"]),
71174
- sessionBundle(
71175
- ".gemini/oauth_creds.json",
71176
- "Sign in with the Google account that has a Gemini subscription.",
71177
- ["gemini"],
71178
- [
71179
- {
71180
- id: "google",
71181
- label: "Google account",
71182
- command: ["gemini", "--skip-trust"],
71183
- env: { NO_BROWSER: "true", GOOGLE_GENAI_USE_GCA: "true" },
71184
- kickoff: "hi\r",
71185
- code: true
71186
- }
71187
- ]
71188
- )
71189
- ]
71173
+ authOptions: [apiKey("GEMINI_API_KEY", ["pi", "hermes"])]
71190
71174
  },
71191
71175
  {
71192
71176
  id: "cursor",
@@ -71616,7 +71600,7 @@ var MAX_INVITE_EXPIRY_DAYS = 90;
71616
71600
  // ../../packages/shared/src/image-upload-quality.ts
71617
71601
  var IMAGE_UPLOAD_QUALITY_LEVELS = ["lowest", "low", "medium", "high"];
71618
71602
  var imageUploadQualitySchema = external_exports.enum(IMAGE_UPLOAD_QUALITY_LEVELS);
71619
- var DEFAULT_IMAGE_UPLOAD_QUALITY = "lowest";
71603
+ var DEFAULT_IMAGE_UPLOAD_QUALITY = "medium";
71620
71604
 
71621
71605
  // ../../packages/shared/src/workspace-settings.ts
71622
71606
  var WORKSPACE_SETTINGS_DEFAULTS = {
@@ -71624,7 +71608,7 @@ var WORKSPACE_SETTINGS_DEFAULTS = {
71624
71608
  defaultAgentConfigId: null,
71625
71609
  /** 0 means keep artifacts forever. */
71626
71610
  artifactRetentionDays: 0,
71627
- /** Uploaded pictures are always re-encoded. Lowest keeps the free recipe. */
71611
+ /** Uploaded pictures are always re-encoded. Everyone starts at Medium. */
71628
71612
  imageUploadQuality: DEFAULT_IMAGE_UPLOAD_QUALITY,
71629
71613
  /** The shared workspace consultant is opt-out. Disabled hides every entry point. */
71630
71614
  consultantEnabled: true,
@@ -73281,7 +73265,7 @@ function driverThinkingArgs(driver, thinking) {
73281
73265
  function hermesProvider(provider) {
73282
73266
  const normalized = provider.toLowerCase();
73283
73267
  if (normalized === "openai") return "openai-api";
73284
- if (normalized === "google" || normalized === "gemini") return "gemini";
73268
+ if (normalized === "google") return "gemini";
73285
73269
  return normalized;
73286
73270
  }
73287
73271
  function buildDriverCommand(input2) {
@@ -73343,26 +73327,6 @@ function buildDriverCommand(input2) {
73343
73327
  args2.push(prompt);
73344
73328
  return args2;
73345
73329
  }
73346
- if (input2.driver === "gemini") {
73347
- const args2 = [
73348
- "gemini",
73349
- "-p",
73350
- prompt,
73351
- "-m",
73352
- input2.model,
73353
- "--output-format",
73354
- "stream-json",
73355
- "--yolo",
73356
- "--skip-trust"
73357
- ];
73358
- if (input2.resume && input2.sessionId) {
73359
- args2.push("--resume", input2.sessionId);
73360
- } else if (input2.sessionId) {
73361
- args2.push("--session-id", input2.sessionId);
73362
- }
73363
- if (input2.workingDirectory) args2.push("--include-directories", input2.workingDirectory);
73364
- return args2;
73365
- }
73366
73330
  if (input2.driver === "cursor") {
73367
73331
  const args2 = [
73368
73332
  "cursor-agent",
@@ -73577,23 +73541,11 @@ function driverSetupCommands(driver, url2, extraServers = []) {
73577
73541
  }
73578
73542
  return [["bash", "-lc", parts.join("; ")]];
73579
73543
  }
73580
- if (driver === "gemini") {
73581
- const parts = [
73582
- `gemini mcp remove aglio >/dev/null 2>&1 || true; gemini mcp add aglio ${url2} --transport http --header "Authorization: Bearer $AGLIO_MCP_TOKEN" --trust --scope user`
73583
- ];
73584
- for (const server of extraServers) {
73585
- const headers = server.headers.map((header) => `--header ${shellQuote(`${header.name}: ${header.value}`)}`).join(" ");
73586
- parts.push(
73587
- `gemini mcp remove ${server.name} >/dev/null 2>&1 || true; gemini mcp add ${server.name} ${shellQuote(server.url)} --transport http ${headers} --trust --scope user`
73588
- );
73589
- }
73590
- return [["bash", "-lc", parts.join("; ")]];
73591
- }
73592
73544
  return [];
73593
73545
  }
73594
73546
  function providerEnv(provider, apiKey2) {
73595
73547
  const normalized = provider.toLowerCase();
73596
- if (normalized === "google" || normalized === "gemini") {
73548
+ if (normalized === "google") {
73597
73549
  return { GEMINI_API_KEY: apiKey2, GOOGLE_API_KEY: apiKey2 };
73598
73550
  }
73599
73551
  if (normalized === "antigravity") return { GEMINI_API_KEY: apiKey2 };
@@ -73892,60 +73844,6 @@ function parseCursorLine(raw) {
73892
73844
  }
73893
73845
  return { type, at: at3 };
73894
73846
  }
73895
- function parseGeminiLine(raw) {
73896
- const type = String(raw.type ?? "");
73897
- const at3 = timestampOf(raw.timestamp);
73898
- if (type === "init") {
73899
- return { type, sessionId: raw.session_id ? String(raw.session_id) : void 0, at: at3 };
73900
- }
73901
- if (type === "message") {
73902
- const role = String(raw.role ?? "");
73903
- if (role !== "assistant") return { type, at: at3 };
73904
- const text = typeof raw.content === "string" ? raw.content : void 0;
73905
- return { type, assistantText: text || void 0, assistantDelta: raw.delta === true, at: at3 };
73906
- }
73907
- if (type === "tool_use") {
73908
- return {
73909
- type,
73910
- toolName: typeof raw.tool_name === "string" ? raw.tool_name : "tool",
73911
- toolArgs: raw.parameters,
73912
- toolCallId: typeof raw.tool_id === "string" ? raw.tool_id : void 0,
73913
- toolStart: true,
73914
- toolPartial: false,
73915
- at: at3
73916
- };
73917
- }
73918
- if (type === "result") {
73919
- const stats = asRecord(raw.stats);
73920
- const status = String(raw.status ?? "");
73921
- const error63 = asRecord(raw.error);
73922
- const number4 = (value) => {
73923
- const parsed = Number(value);
73924
- return Number.isFinite(parsed) && parsed > 0 ? parsed : void 0;
73925
- };
73926
- const input2 = number4(stats?.input_tokens);
73927
- const output2 = number4(stats?.output_tokens);
73928
- const cacheRead = number4(stats?.cached);
73929
- return {
73930
- type,
73931
- sessionId: raw.session_id ? String(raw.session_id) : void 0,
73932
- error: status === "error" ? typeof error63?.message === "string" ? error63.message : "Gemini run ended with an error" : void 0,
73933
- usage: input2 || output2 || cacheRead ? { input: input2, output: output2, cacheRead } : void 0,
73934
- done: true,
73935
- final: status === "success",
73936
- at: at3
73937
- };
73938
- }
73939
- if (type === "error") {
73940
- if (String(raw.severity ?? "error") !== "error") return { type, at: at3 };
73941
- return {
73942
- type,
73943
- error: typeof raw.message === "string" ? raw.message : "Gemini run ended with an error",
73944
- at: at3
73945
- };
73946
- }
73947
- return { type, at: at3 };
73948
- }
73949
73847
  function codexTool(item) {
73950
73848
  const itemType = String(item.type ?? "");
73951
73849
  const names = {
@@ -74301,7 +74199,6 @@ function parseDriverLine(driver, line) {
74301
74199
  if (driver === "pi") return parsePiLine(raw);
74302
74200
  if (driver === "claude") return parseClaudeLine(raw);
74303
74201
  if (driver === "cursor") return parseCursorLine(raw);
74304
- if (driver === "gemini") return parseGeminiLine(raw);
74305
74202
  if (driver === "codex") return parseCodexLine(raw);
74306
74203
  if (driver === "opencode") return parseOpencodeLine(raw);
74307
74204
  if (driver === "antigravity") return parseAntigravityLine(raw);
@@ -86169,6 +86066,8 @@ async function runRemoteCardJob(deps) {
86169
86066
  log: (message) => deps.log?.(message)
86170
86067
  });
86171
86068
  const repoPaths = await cloneRepos();
86069
+ const restoredSessionId = await restoreRunContext(repoPaths, context);
86070
+ if (restoredSessionId && !context.run.sessionId) context.run.sessionId = restoredSessionId;
86172
86071
  if (context.run.kind === "workspace_consult") {
86173
86072
  await rm3(gitConfigPath, { force: true }).catch(() => void 0);
86174
86073
  }
@@ -86192,6 +86091,10 @@ async function runRemoteCardJob(deps) {
86192
86091
  systemPromptAppend: context.systemPromptAppend
86193
86092
  });
86194
86093
  const exit = await runAgent(command, env);
86094
+ await uploadRunContext(repoPaths, context, exit.sessionId).catch((error63) => {
86095
+ write(`[aglio] context snapshot failed: ${errorText2(error63)}
86096
+ `);
86097
+ });
86195
86098
  if (deps.cancelled()) return { state: "cancelled", error: "Cancelled from the board" };
86196
86099
  await status({ finalMessage: exit.finalMessage });
86197
86100
  if (exit.error) return { state: "failed", error: exit.error };
@@ -86541,6 +86444,195 @@ async function runRemoteCardJob(deps) {
86541
86444
  }
86542
86445
  }
86543
86446
  }
86447
+ function sessionDirsForDriver(driver) {
86448
+ if (driver === "pi") return ["sessions"];
86449
+ if (driver === "claude") return ["projects"];
86450
+ if (driver === "codex") return ["home/.codex/sessions"];
86451
+ if (driver === "cursor") return ["home/.cursor/chats"];
86452
+ if (driver === "opencode") return ["home/.local/share/opencode/storage"];
86453
+ if (driver === "antigravity") return ["home/.gemini/tmp"];
86454
+ if (driver === "hermes") return ["sessions"];
86455
+ return [];
86456
+ }
86457
+ async function uploadRunContext(repoPaths, current, sessionId) {
86458
+ if (!current.card || current.run.kind === "workspace_consult") return;
86459
+ const staging = join5(workspace, ".aglio", "context");
86460
+ const archivePath = join5(workspace, ".aglio", `run-context-${current.run.id}.tar.gz`);
86461
+ await rm3(staging, { recursive: true, force: true }).catch(() => void 0);
86462
+ await rm3(archivePath, { force: true }).catch(() => void 0);
86463
+ await mkdir2(staging, { recursive: true });
86464
+ const manifest = {
86465
+ version: 1,
86466
+ runId: current.run.id,
86467
+ driver: current.agent.driver,
86468
+ sessionId: sessionId ?? current.run.sessionId,
86469
+ sessionDirs: [],
86470
+ repos: [],
86471
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
86472
+ };
86473
+ for (const [index3, target] of repoPaths.entries()) {
86474
+ const repo = current.repos[index3];
86475
+ if (!repo) continue;
86476
+ const targetRun = containerPath(runRoot, workspace, target);
86477
+ const base = repo.baseBranch || "main";
86478
+ const baseRef = (await runGit(workspace, ["-C", targetRun, "rev-parse", "--verify", `origin/${base}`])).code === 0 ? `origin/${base}` : base;
86479
+ const patchRel = `repo-${index3}.patch`;
86480
+ const patchPath = join5(staging, patchRel);
86481
+ const indexFile = join5(staging, `index-${index3}`);
86482
+ const indexFileRun = containerPath(runRoot, workspace, indexFile);
86483
+ const patchPathRun = containerPath(runRoot, workspace, patchPath);
86484
+ const command = [
86485
+ `GIT_INDEX_FILE=${shellArg2(indexFileRun)} git -C ${shellArg2(targetRun)} read-tree ${shellArg2(baseRef)}`,
86486
+ `GIT_INDEX_FILE=${shellArg2(indexFileRun)} git -C ${shellArg2(targetRun)} add -A`,
86487
+ `GIT_INDEX_FILE=${shellArg2(indexFileRun)} git -C ${shellArg2(targetRun)} diff --cached --binary ${shellArg2(baseRef)} > ${shellArg2(patchPathRun)}`
86488
+ ].join(" && ");
86489
+ const code = await deps.runCommand({
86490
+ command,
86491
+ cwd: workspace,
86492
+ env: { GIT_TERMINAL_PROMPT: "0" },
86493
+ signal: deps.signal,
86494
+ onOutput: () => void 0
86495
+ });
86496
+ if (code === 0) {
86497
+ manifest.repos.push({ name: repo.name, baseBranch: base, patch: patchRel });
86498
+ } else {
86499
+ write(`[aglio] context patch skipped for ${repo.name}
86500
+ `);
86501
+ }
86502
+ }
86503
+ for (const [index3, relative6] of sessionDirsForDriver(current.agent.driver).entries()) {
86504
+ const source = join5(toolDir, relative6);
86505
+ const info = await stat3(source).catch(() => null);
86506
+ if (!info?.isDirectory()) continue;
86507
+ const archiveName = `session-${index3}`;
86508
+ await mkdir2(join5(staging, archiveName), { recursive: true });
86509
+ const copied = await deps.runCommand({
86510
+ command: `cp -a ${shellArg2(`${containerPath(runRoot, workspace, source)}/.`)} ${shellArg2(`${containerPath(runRoot, workspace, join5(staging, archiveName))}/`)}`,
86511
+ cwd: workspace,
86512
+ env: {},
86513
+ signal: deps.signal,
86514
+ onOutput: () => void 0
86515
+ });
86516
+ if (copied === 0) manifest.sessionDirs.push({ path: relative6, archive: archiveName });
86517
+ }
86518
+ await writeFile(join5(staging, "manifest.json"), JSON.stringify(manifest, null, 2), "utf8");
86519
+ const tarArgs = [
86520
+ "-czf",
86521
+ containerPath(runRoot, workspace, archivePath),
86522
+ "-C",
86523
+ containerPath(runRoot, workspace, staging),
86524
+ "manifest.json"
86525
+ ];
86526
+ for (const repo of manifest.repos) tarArgs.push(repo.patch);
86527
+ for (const session of manifest.sessionDirs) tarArgs.push(session.archive);
86528
+ const tarCode = await deps.runCommand({
86529
+ command: ["tar", ...tarArgs].map(shellArg2).join(" "),
86530
+ cwd: workspace,
86531
+ env: {},
86532
+ signal: deps.signal,
86533
+ onOutput: () => void 0
86534
+ });
86535
+ if (tarCode !== 0) {
86536
+ write("[aglio] context archive failed\n");
86537
+ return;
86538
+ }
86539
+ const data = await readFile2(archivePath).catch(() => null);
86540
+ if (!data?.length) return;
86541
+ if (data.length > 10 * 1024 * 1024) {
86542
+ write("[aglio] context archive exceeds 10MB, skipped\n");
86543
+ return;
86544
+ }
86545
+ try {
86546
+ const artifactId = await deps.jobApi.uploadArtifact({
86547
+ ...lease,
86548
+ name: `run-context-${current.run.id}.tar.gz`,
86549
+ label: `Run context ${current.run.id.slice(0, 8)}`,
86550
+ mime: "application/gzip",
86551
+ data,
86552
+ kind: "context"
86553
+ });
86554
+ if (artifactId) write(`[aglio] context snapshot uploaded (${data.length} bytes)
86555
+ `);
86556
+ } catch (error63) {
86557
+ write(`[aglio] context snapshot upload failed: ${errorText2(error63)}
86558
+ `);
86559
+ } finally {
86560
+ await rm3(staging, { recursive: true, force: true }).catch(() => void 0);
86561
+ await rm3(archivePath, { force: true }).catch(() => void 0);
86562
+ }
86563
+ }
86564
+ async function restoreRunContext(repoPaths, current) {
86565
+ const artifactId = current.run.restoreContextArtifactId;
86566
+ if (!artifactId) return null;
86567
+ const restoreDir = join5(workspace, ".aglio", "context-restore");
86568
+ const archivePath = join5(restoreDir, "context.tar.gz");
86569
+ await rm3(restoreDir, { recursive: true, force: true }).catch(() => void 0);
86570
+ await mkdir2(restoreDir, { recursive: true });
86571
+ let data;
86572
+ try {
86573
+ data = await deps.api.fetchAttachment({ ...lease, artifactId });
86574
+ } catch (error63) {
86575
+ write(`[aglio] context restore download failed: ${errorText2(error63)}
86576
+ `);
86577
+ return null;
86578
+ }
86579
+ await writeFile(archivePath, data);
86580
+ const unpacked = await deps.runCommand({
86581
+ command: `tar -xzf ${shellArg2(containerPath(runRoot, workspace, archivePath))} -C ${shellArg2(containerPath(runRoot, workspace, restoreDir))}`,
86582
+ cwd: workspace,
86583
+ env: {},
86584
+ signal: deps.signal,
86585
+ onOutput: () => void 0
86586
+ });
86587
+ if (unpacked !== 0) {
86588
+ write("[aglio] context restore unpack failed\n");
86589
+ return null;
86590
+ }
86591
+ const manifest = await readFile2(join5(restoreDir, "manifest.json"), "utf8").then((text) => JSON.parse(text)).catch(() => null);
86592
+ if (!manifest) {
86593
+ write("[aglio] context restore manifest missing\n");
86594
+ return null;
86595
+ }
86596
+ for (const [index3, repo] of (manifest.repos ?? []).entries()) {
86597
+ if (!repo.patch) continue;
86598
+ const target = repoPaths[index3];
86599
+ const repoConfig = current.repos[index3];
86600
+ if (!target || !repoConfig) continue;
86601
+ const targetRun = containerPath(runRoot, workspace, target);
86602
+ const patchPath = resolve4(restoreDir, repo.patch);
86603
+ if (!patchPath.startsWith(resolve4(restoreDir))) continue;
86604
+ const patchPathRun = containerPath(runRoot, workspace, patchPath);
86605
+ const apply = await runGit(workspace, ["-C", targetRun, "apply", "--binary", "--3way", "--whitespace=nowarn", patchPathRun]);
86606
+ if (apply.code !== 0) {
86607
+ const reverse = await runGit(workspace, ["-C", targetRun, "apply", "--reverse", "--check", "--binary", patchPathRun]);
86608
+ if (reverse.code === 0) {
86609
+ write(`[aglio] context patch already present in ${repoConfig.name}
86610
+ `);
86611
+ } else {
86612
+ write(`[aglio] context patch did not apply in ${repoConfig.name}
86613
+ `);
86614
+ }
86615
+ }
86616
+ }
86617
+ for (const session of manifest.sessionDirs ?? []) {
86618
+ if (!session.path || !session.archive) continue;
86619
+ const target = resolve4(toolDir, session.path);
86620
+ if (!target.startsWith(resolve4(toolDir))) continue;
86621
+ await rm3(target, { recursive: true, force: true }).catch(() => void 0);
86622
+ await mkdir2(target, { recursive: true });
86623
+ const restored = await deps.runCommand({
86624
+ command: `tar -xzf ${shellArg2(containerPath(runRoot, workspace, archivePath))} -C ${shellArg2(containerPath(runRoot, workspace, target))} --strip-components=1 ${shellArg2(session.archive)}`,
86625
+ cwd: workspace,
86626
+ env: {},
86627
+ signal: deps.signal,
86628
+ onOutput: () => void 0
86629
+ });
86630
+ if (restored === 0) write(`[aglio] restored session ${session.path}
86631
+ `);
86632
+ }
86633
+ await rm3(restoreDir, { recursive: true, force: true }).catch(() => void 0);
86634
+ return manifest.sessionId ?? null;
86635
+ }
86544
86636
  async function gitOutput(args) {
86545
86637
  let output2 = "";
86546
86638
  const code = await deps.runCommand({
@@ -86599,6 +86691,8 @@ async function runRemoteCardJob(deps) {
86599
86691
  const lastToolUpdateAt = /* @__PURE__ */ new Map();
86600
86692
  let consumeQueue = Promise.resolve();
86601
86693
  const isPlanning = context.run.kind === "planning";
86694
+ const isAgent = context.run.kind === "agent";
86695
+ const isChat = isPlanning || isAgent;
86602
86696
  const isConsult = context.run.kind === "workspace_consult";
86603
86697
  const emitLive = async (events) => {
86604
86698
  if (events.length === 0) return;
@@ -86607,9 +86701,9 @@ async function runRemoteCardJob(deps) {
86607
86701
  });
86608
86702
  };
86609
86703
  const appendChat = async (text, kind = "text", toolName, toolArgs) => {
86610
- if (!isPlanning && !isConsult) return;
86704
+ if (!isChat && !isConsult) return;
86611
86705
  try {
86612
- const messageId = await (isPlanning ? deps.api.appendPlanningMessage : deps.api.appendConsultMessage)({
86706
+ const messageId = await (isChat ? deps.api.appendPlanningMessage : deps.api.appendConsultMessage)({
86613
86707
  ...lease,
86614
86708
  messageId: kind === "text" ? chatMessageId : null,
86615
86709
  text,
@@ -87480,7 +87574,8 @@ function jobApi(config2, fetchImpl, signal) {
87480
87574
  "x-aglio-lease-id": input2.leaseId,
87481
87575
  "x-aglio-name": encodeURIComponent(input2.name),
87482
87576
  "x-aglio-label": input2.label,
87483
- "x-aglio-mime": input2.mime
87577
+ "x-aglio-mime": input2.mime,
87578
+ ...input2.kind ? { "x-aglio-kind": input2.kind } : {}
87484
87579
  },
87485
87580
  body: input2.data,
87486
87581
  signal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aglio-worker",
3
- "version": "0.98.0",
3
+ "version": "0.101.2",
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": {