@alan-ai-hq/agent-manager-linux-arm64 0.1.157 → 0.1.159

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 (3) hide show
  1. package/alan-agent.cjs +421 -191
  2. package/alan-holder.cjs +377 -188
  3. package/package.json +1 -1
package/alan-holder.cjs CHANGED
@@ -23279,6 +23279,7 @@ If a needed tool is not exposed, use the host's tool-discovery mechanism once wh
23279
23279
  Whatever the intent, check your draft before sending: three or more numbers being compared, several items sharing the same attributes, a sequence, or two or more options means it should be visual. Stay in plain text for one-line facts, yes/no answers, clarifying questions, conversation, and short summaries of code you just changed. Lead with one sentence, show one visual (two at most), then stop; the visual carries the detail, so do not repeat it in prose.
23280
23280
  - Examples of plain questions with visual answers: "Which queue should the importer use, BullMQ or SQS?" \u2192 a one-line recommendation, then \`\`\`openui Tabs with a KeyValue of cost, latency and ops effort per option and a Callout with the pick. "Why did last night's deploy fail?" \u2192 a one-sentence cause, then Steps with the failed step and its detail, then Code with the error. "How's the test suite doing?" \u2192 a row of Stat (passed, failed, flaky) and a line \`\`\`chart of failures per day.
23281
23281
  - \`\`\`mermaid renders in chat, documents, plans and artifacts too; \`\`\`openui renders only in your replies in the Alan chat. In Slack or Teams messages, commit messages, pull request bodies and files, use plain Markdown instead.
23282
+ - When you compose a plan, test report, review or document to save as an Alan artifact, use the \`alan-artifact\` skill for its structure and any HTML or interactive block, and \`alan-diagrams\` for its Mermaid diagrams.
23282
23283
  - \`\`\`chart renders in chat, documents, plans and artifacts, and is **strict JSON, nothing else**:
23283
23284
  \`\`\`chart
23284
23285
  { "type": "bar", "title": "Quarterly Revenue", "data": [{ "name": "Q1", "revenue": 4000 }, { "name": "Q2", "revenue": 3000 }] }
@@ -23325,7 +23326,7 @@ Team
23325
23326
  - When a user asks to create a Skill, default to a team-owned Alan platform Skill through \`alan-skill-authoring\`, whether this session runs locally or in a cloud sandbox. Use a repository or filesystem Skill only when the user explicitly requests that scope. Do not infer repository scope from the current checkout or from a procedure that mentions repository files. If repeated work suggests a reusable Skill, offer the platform Skill and its evidence; do not publish it without the approval required by the authoring workflow.
23326
23327
  - Own mistakes. Wrong ID, jumped too fast \u2014 say so and fix it.
23327
23328
  - When writing code, work like a senior engineer: understand the existing design and conventions, make the smallest coherent change that solves the request, and keep related logic together. Reuse an existing abstraction when it fits; remove duplication that the change would otherwise introduce, but do not refactor unrelated code or add speculative abstractions. Keep names, types, error handling, and tests clear enough for the next engineer to maintain. Review the diff for accidental changes before calling the work done.
23328
- - Write for a human reader. Task, subtask and epic descriptions, documents, artifacts and comments are read by people in the app, not parsed by agents. Lead with the outcome in one sentence, then short sections with headings and bullet lists. Spell out internal shorthand, and keep commit hashes, IDs and migration numbers out of sentences \u2014 put them in a trailing "References" list when they matter.
23329
+ - Write for a human reader. Task, subtask and epic descriptions, documents, artifacts and comments are read by people in the app, not parsed by agents. Lead with the outcome in one sentence, then short sections with headings and bullet lists when there is enough to organise. Size it to what is actually known: a task written from someone's request restates that request and never adds repro steps, causes, verification or acceptance criteria nobody stated. Spell out internal shorthand, and keep commit hashes, IDs and migration numbers out of sentences \u2014 put them in a trailing "References" list when they matter.
23329
23330
  ${ALAN_VISUAL_PROMPT}
23330
23331
  - Images you generate or edit appear in the chat automatically, the way ChatGPT shows them. Do not link, embed, or print the generated file's path afterwards, and do not announce "Generated:" or "Edited image:" \u2014 at most one short sentence about the result. Mention a path only when the user asked for the file to be saved into the project.
23331
23332
 
@@ -25201,6 +25202,13 @@ var init_read = __esm({
25201
25202
  }
25202
25203
  });
25203
25204
 
25205
+ // ../shared/dist/agent/acp/session-activity.js
25206
+ var init_session_activity = __esm({
25207
+ "../shared/dist/agent/acp/session-activity.js"() {
25208
+ "use strict";
25209
+ }
25210
+ });
25211
+
25204
25212
  // ../shared/dist/agent/acp/transcript-byte-decoder.js
25205
25213
  var init_transcript_byte_decoder = __esm({
25206
25214
  "../shared/dist/agent/acp/transcript-byte-decoder.js"() {
@@ -25232,6 +25240,7 @@ var init_acp = __esm({
25232
25240
  init_types3();
25233
25241
  init_read();
25234
25242
  init_reduce();
25243
+ init_session_activity();
25235
25244
  init_transcript_byte_decoder();
25236
25245
  init_transcript_fold();
25237
25246
  init_transcript_http();
@@ -26104,7 +26113,7 @@ var init_chunk_ZCTKXKYY = __esm({
26104
26113
  }
26105
26114
  });
26106
26115
 
26107
- // ../agent-core/dist/chunk-ILZBXGVI.js
26116
+ // ../agent-core/dist/chunk-FYZKVT3E.js
26108
26117
  function detectImageMimeType(buffer) {
26109
26118
  if (buffer.length >= 8 && buffer.subarray(0, 8).equals(PNG_SIGNATURE)) return "image/png";
26110
26119
  if (buffer.length >= 3 && buffer[0] === 255 && buffer[1] === 216 && buffer[2] === 255) {
@@ -26201,21 +26210,38 @@ function imageDimensions(buffer, mimeType) {
26201
26210
  if (mimeType === "image/jpeg") return jpegDimensions(buffer);
26202
26211
  return { width: null, height: null };
26203
26212
  }
26204
- function readMediaFiles(candidates2, cwd, mimeByExt, maxBytes) {
26213
+ function readMediaFiles(query) {
26205
26214
  const seen = /* @__PURE__ */ new Set();
26206
26215
  const files = [];
26207
- for (const candidate of candidates2) {
26208
- const path = normalizePath(candidate, cwd);
26216
+ for (const candidate of query.candidates) {
26217
+ const path = normalizePath(candidate, query.cwd);
26209
26218
  if (!path || seen.has(path) || !(0, import_fs5.existsSync)(path)) continue;
26210
26219
  seen.add(path);
26211
- const mimeType = mimeByExt[(0, import_path4.extname)(path).toLowerCase()];
26220
+ const mimeType = query.mimeByExt[(0, import_path4.extname)(path).toLowerCase()];
26212
26221
  if (!mimeType) continue;
26213
26222
  const stat15 = (0, import_fs5.statSync)(path);
26214
- if (!stat15.isFile() || stat15.size <= 0 || stat15.size > maxBytes) continue;
26223
+ if (!stat15.isFile() || stat15.size <= 0 || stat15.size > query.maxBytes) continue;
26224
+ if (stat15.mtimeMs < query.writtenSince && !query.named.has(path)) continue;
26215
26225
  files.push({ path, mimeType, buffer: (0, import_fs5.readFileSync)(path) });
26216
26226
  }
26217
26227
  return files;
26218
26228
  }
26229
+ function isCaptureTool(tool) {
26230
+ return isBrowserScreenshotToolName(tool.name) || isBrowserRecordingToolName(tool.name);
26231
+ }
26232
+ function runsCaptureCommand(tool) {
26233
+ return someString(tool.input, (text2) => AGENT_BROWSER_CAPTURE_COMMAND.test(text2));
26234
+ }
26235
+ function capturePaths(tool, content, extensions, cwd) {
26236
+ const values = isCaptureTool(tool) ? contentStrings(content, tool.input) : runsCaptureCommand(tool) ? contentStrings("", tool.input) : [];
26237
+ return pathCandidates(values, extensions).flatMap((candidate) => {
26238
+ const path = normalizePath(candidate, cwd);
26239
+ return path ? [path] : [];
26240
+ });
26241
+ }
26242
+ function base64Length(bytes) {
26243
+ return Math.ceil(bytes / 3) * 4;
26244
+ }
26219
26245
  function resultText(update) {
26220
26246
  const only2 = isJsonRecord(update._meta) ? update._meta[TOOL_RESULT_ONLY_META] : void 0;
26221
26247
  if (typeof only2 === "string") return only2;
@@ -26506,9 +26532,9 @@ function silentStartError(name, timeoutMs) {
26506
26532
  message: `${name} printed nothing for ${seconds}s after it started and was stopped. Send your message again.`
26507
26533
  };
26508
26534
  }
26509
- var import_crypto4, import_fs5, import_path4, PNG_SIGNATURE, IMAGE_MIME_BY_EXT, VIDEO_MIME_BY_EXT, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, MAX_IMAGE_BYTES, MAX_VIDEO_BYTES, AGENT_BROWSER_MENTION, LocalMediaReader, SessionOpenRefusal, JsonRpcError, ACP_PROTOCOL_VERSION, ACP_ERROR, STDERR_TAIL_LINES, RESULT_EXIT_GRACE_MS, PerTurnSession;
26510
- var init_chunk_ILZBXGVI = __esm({
26511
- "../agent-core/dist/chunk-ILZBXGVI.js"() {
26535
+ var import_crypto4, import_fs5, import_path4, PNG_SIGNATURE, IMAGE_MIME_BY_EXT, VIDEO_MIME_BY_EXT, IMAGE_EXTENSIONS, VIDEO_EXTENSIONS, MAX_IMAGE_BYTES, MAX_VIDEO_BYTES, MAX_TURN_MEDIA_DATA_CHARS, MTIME_SLACK_MS, AGENT_BROWSER_MENTION, AGENT_BROWSER_CAPTURE_COMMAND, LocalMediaReader, SessionOpenRefusal, JsonRpcError, ACP_PROTOCOL_VERSION, ACP_ERROR, STDERR_TAIL_LINES, RESULT_EXIT_GRACE_MS, PerTurnSession;
26536
+ var init_chunk_FYZKVT3E = __esm({
26537
+ "../agent-core/dist/chunk-FYZKVT3E.js"() {
26512
26538
  "use strict";
26513
26539
  init_chunk_OUEMTEUX();
26514
26540
  init_chunk_ZCTKXKYY();
@@ -26536,12 +26562,16 @@ var init_chunk_ILZBXGVI = __esm({
26536
26562
  VIDEO_EXTENSIONS = "mp4|webm|mov";
26537
26563
  MAX_IMAGE_BYTES = 20 * 1024 * 1024;
26538
26564
  MAX_VIDEO_BYTES = 100 * 1024 * 1024;
26565
+ MAX_TURN_MEDIA_DATA_CHARS = 8 * 1024 * 1024;
26566
+ MTIME_SLACK_MS = 2e3;
26539
26567
  AGENT_BROWSER_MENTION = /agent[-_]browser/i;
26568
+ AGENT_BROWSER_CAPTURE_COMMAND = /(?:^|[\s/])agent[-_]browser(?:@[^\s;&|]+)?(?:\s[^\n;&|]*?)?\s(?:screenshot|record)(?=\s|$)/im;
26540
26569
  LocalMediaReader = class {
26541
26570
  #cwd;
26542
26571
  #clock;
26543
26572
  #tools = /* @__PURE__ */ new Map();
26544
26573
  #pathHints = /* @__PURE__ */ new Set();
26574
+ #mediaDataChars = 0;
26545
26575
  constructor(cwd, clock) {
26546
26576
  this.#cwd = cwd;
26547
26577
  this.#clock = clock;
@@ -26566,7 +26596,11 @@ var init_chunk_ILZBXGVI = __esm({
26566
26596
  /** A recording names its output file when it starts; the stop's result may not repeat it. */
26567
26597
  #announce(toolCallId, name, input2) {
26568
26598
  const known = this.#tools.get(toolCallId);
26569
- const tool = { name: name ?? known?.name ?? "", input: input2 ?? known?.input };
26599
+ const tool = {
26600
+ name: name ?? known?.name ?? "",
26601
+ input: input2 ?? known?.input,
26602
+ startedAt: known?.startedAt ?? this.#clock.now()
26603
+ };
26570
26604
  this.#tools.set(toolCallId, tool);
26571
26605
  if (!isAgentBrowserMedia(tool, "", "video")) return;
26572
26606
  const cwd = toolCwd(this.#cwd, tool.input);
@@ -26575,13 +26609,30 @@ var init_chunk_ILZBXGVI = __esm({
26575
26609
  if (path) this.#pathHints.add(path);
26576
26610
  }
26577
26611
  }
26578
- #payloadFields(file2, toolId) {
26612
+ /** Media written before the call started is old, unless its capture command named it. */
26613
+ #toolFiles(tool, content, extensions, limits) {
26614
+ const cwd = toolCwd(this.#cwd, tool.input);
26615
+ return readMediaFiles({
26616
+ ...limits,
26617
+ candidates: [
26618
+ ...pathCandidates(contentStrings(content, tool.input), extensions),
26619
+ ...this.#pathHints
26620
+ ],
26621
+ cwd,
26622
+ writtenSince: tool.startedAt - MTIME_SLACK_MS,
26623
+ named: /* @__PURE__ */ new Set([...capturePaths(tool, content, extensions, cwd), ...this.#pathHints])
26624
+ });
26625
+ }
26626
+ #payloadFields(file2, toolId, explicit) {
26627
+ const dataChars = base64Length(file2.buffer.length);
26628
+ const inline = explicit || this.#mediaDataChars + dataChars <= MAX_TURN_MEDIA_DATA_CHARS;
26629
+ if (inline) this.#mediaDataChars += dataChars;
26579
26630
  return {
26580
26631
  id: (0, import_crypto4.randomUUID)(),
26581
26632
  filename: (0, import_path4.basename)(file2.path),
26582
26633
  mimeType: file2.mimeType,
26583
26634
  size: file2.buffer.length,
26584
- data: file2.buffer.toString("base64"),
26635
+ ...inline ? { data: file2.buffer.toString("base64") } : { inlineDataOmitted: true },
26585
26636
  sourcePath: file2.path,
26586
26637
  sourceHash: (0, import_crypto4.createHash)("sha256").update(file2.buffer).digest("hex"),
26587
26638
  toolId,
@@ -26590,15 +26641,14 @@ var init_chunk_ILZBXGVI = __esm({
26590
26641
  }
26591
26642
  #generatedImages(toolId, tool, content) {
26592
26643
  if (!isGeneratedImageToolName(tool.name)) return [];
26593
- const candidates2 = [
26594
- ...pathCandidates(contentStrings(content, tool.input), IMAGE_EXTENSIONS),
26595
- ...this.#pathHints
26596
- ];
26597
- const cwd = toolCwd(this.#cwd, tool.input);
26598
- return readMediaFiles(candidates2, cwd, IMAGE_MIME_BY_EXT, MAX_IMAGE_BYTES).map((file2) => {
26644
+ const files = this.#toolFiles(tool, content, IMAGE_EXTENSIONS, {
26645
+ mimeByExt: IMAGE_MIME_BY_EXT,
26646
+ maxBytes: MAX_IMAGE_BYTES
26647
+ });
26648
+ return files.map((file2) => {
26599
26649
  const image = {
26600
26650
  type: "generated_image",
26601
- ...this.#payloadFields(file2, toolId),
26651
+ ...this.#payloadFields(file2, toolId, true),
26602
26652
  ...imageDimensions(file2.buffer, file2.mimeType)
26603
26653
  };
26604
26654
  return { sessionUpdate: "_alan/generated_image", image };
@@ -26608,25 +26658,19 @@ var init_chunk_ILZBXGVI = __esm({
26608
26658
  const isVideo = isAgentBrowserMedia(tool, content, "video");
26609
26659
  if (!isVideo && !isAgentBrowserMedia(tool, content, "image")) return [];
26610
26660
  const kind = isVideo ? "video" : "image";
26611
- const candidates2 = [
26612
- ...pathCandidates(
26613
- contentStrings(content, tool.input),
26614
- isVideo ? VIDEO_EXTENSIONS : IMAGE_EXTENSIONS
26615
- ),
26616
- ...this.#pathHints
26617
- ];
26618
- const files = readMediaFiles(
26619
- candidates2,
26620
- toolCwd(this.#cwd, tool.input),
26621
- isVideo ? VIDEO_MIME_BY_EXT : IMAGE_MIME_BY_EXT,
26622
- isVideo ? MAX_VIDEO_BYTES : MAX_IMAGE_BYTES
26661
+ const explicit = isCaptureTool(tool) || runsCaptureCommand(tool);
26662
+ const files = this.#toolFiles(
26663
+ tool,
26664
+ content,
26665
+ isVideo ? VIDEO_EXTENSIONS : IMAGE_EXTENSIONS,
26666
+ isVideo ? { mimeByExt: VIDEO_MIME_BY_EXT, maxBytes: MAX_VIDEO_BYTES } : { mimeByExt: IMAGE_MIME_BY_EXT, maxBytes: MAX_IMAGE_BYTES }
26623
26667
  );
26624
26668
  return files.map((file2) => {
26625
26669
  this.#pathHints.delete(file2.path);
26626
26670
  const media = {
26627
26671
  type: "session_media",
26628
26672
  kind,
26629
- ...this.#payloadFields(file2, toolId),
26673
+ ...this.#payloadFields(file2, toolId, explicit),
26630
26674
  ...kind === "image" ? imageDimensions(file2.buffer, file2.mimeType) : {}
26631
26675
  };
26632
26676
  return { sessionUpdate: "_alan/session_media", media };
@@ -26858,128 +26902,6 @@ var init_chunk_ILZBXGVI = __esm({
26858
26902
  }
26859
26903
  });
26860
26904
 
26861
- // ../agent-core/dist/chunk-J2KTV5FP.js
26862
- function selectExternalMcpServers(spec) {
26863
- const isWorkflow = Boolean(spec.workflowId || spec.workflowExecutionId);
26864
- const filter = isWorkflow ? createWorkflowToolsFilter(spec.workflowTools) : null;
26865
- if (filter && !filter.hasFilter) return {};
26866
- const selected = {};
26867
- for (const [name, server] of Object.entries(spec.externalMcpServers ?? {})) {
26868
- if (!isExternalMcpServerName(name)) continue;
26869
- if (filter && !filter.isMcpServerAllowed(name)) continue;
26870
- selected[name] = server;
26871
- }
26872
- return selected;
26873
- }
26874
- function headerEnvName(server, header) {
26875
- const fingerprint = (0, import_crypto5.createHash)("sha256").update(`${server}\0${header}`).digest("hex").slice(0, 12);
26876
- return `ALAN_MCP_HEADER_${fingerprint.toUpperCase()}`;
26877
- }
26878
- function deliverRemote(name, server, env) {
26879
- const headerEnv = {};
26880
- for (const [header, value] of Object.entries(server.headers ?? {})) {
26881
- if (!isMcpConfigKey(header)) continue;
26882
- const variable = headerEnvName(name, header);
26883
- env[variable] = value;
26884
- headerEnv[header] = variable;
26885
- }
26886
- return {
26887
- type: server.type === "sse" ? "sse" : "http",
26888
- url: server.url,
26889
- ...Object.keys(headerEnv).length ? { headerEnv } : {}
26890
- };
26891
- }
26892
- function deliverStdio(server, cliEnv, delivery) {
26893
- const envKeys = [];
26894
- for (const [key, value] of Object.entries(server.env ?? {})) {
26895
- if (!isMcpConfigKey(key)) continue;
26896
- if (key in cliEnv || key in delivery.env && delivery.env[key] !== value) {
26897
- delivery.skippedEnvKeys.push(key);
26898
- continue;
26899
- }
26900
- delivery.env[key] = value;
26901
- envKeys.push(key);
26902
- }
26903
- return {
26904
- type: "stdio",
26905
- command: server.command,
26906
- ...server.args?.length ? { args: server.args } : {},
26907
- ...envKeys.length ? { envKeys } : {}
26908
- };
26909
- }
26910
- function planExternalMcpDelivery(spec, cliEnv) {
26911
- const delivery = { servers: {}, env: {}, skippedEnvKeys: [] };
26912
- for (const [name, server] of Object.entries(selectExternalMcpServers(spec))) {
26913
- const { url: url2, command } = server;
26914
- if (url2 && server.type !== "stdio") {
26915
- delivery.servers[name] = deliverRemote(name, { ...server, url: url2 }, delivery.env);
26916
- } else if (command) {
26917
- delivery.servers[name] = deliverStdio({ ...server, command }, cliEnv, delivery);
26918
- }
26919
- }
26920
- return delivery;
26921
- }
26922
- function envReference(name) {
26923
- return `\${${name}}`;
26924
- }
26925
- function managedMcpHeaders(identity) {
26926
- if (identity.scope === "run") {
26927
- return {
26928
- Authorization: envReference(ALAN_MCP_AUTHORIZATION_ENV),
26929
- [MANAGED_MCP_RUN_HEADER]: envReference(ALAN_RUN_ID_ENV)
26930
- };
26931
- }
26932
- return {
26933
- ...identity.authorization === void 0 ? {} : { Authorization: identity.authorization },
26934
- [MANAGED_MCP_CONVERSATION_HEADER]: identity.conversationId
26935
- };
26936
- }
26937
- function credentialDigest(authorization) {
26938
- if (authorization === void 0) return void 0;
26939
- return (0, import_crypto6.createHash)("sha256").update(authorization).digest("hex").slice(0, 16);
26940
- }
26941
- function canonicalizeManagedMcpServerName(serverName) {
26942
- return RUN_SCOPED_SERVER.test(serverName) ? MANAGED_MCP_SERVER_NAME : serverName;
26943
- }
26944
- function canonicalizeManagedMcpToolName(toolName) {
26945
- const namespaced = NAMESPACED_RUN_TOOL.exec(toolName);
26946
- if (namespaced) return `mcp__${MANAGED_MCP_SERVER_NAME}__${namespaced[2]}`;
26947
- const flattened = FLATTENED_RUN_TOOL.exec(toolName);
26948
- return flattened ? `mcp__${MANAGED_MCP_SERVER_NAME}__${flattened[1]}` : toolName;
26949
- }
26950
- async function writeSecretFile(name, contents) {
26951
- const dir = await (0, import_promises14.mkdtemp)((0, import_path5.join)((0, import_os2.tmpdir)(), "alan-mcp-"));
26952
- const path = (0, import_path5.join)(dir, name);
26953
- const remove = async () => {
26954
- await (0, import_promises14.rm)(dir, { recursive: true, force: true });
26955
- };
26956
- try {
26957
- await (0, import_promises14.writeFile)(path, contents, { mode: 384, flag: "wx" });
26958
- } catch (error62) {
26959
- await remove();
26960
- throw error62;
26961
- }
26962
- return { path, remove, [Symbol.asyncDispose]: remove };
26963
- }
26964
- var import_crypto5, import_crypto6, import_promises14, import_os2, import_path5, MANAGED_MCP_SERVER_NAME, RUN_SCOPED_SERVER, NAMESPACED_RUN_TOOL, FLATTENED_RUN_TOOL;
26965
- var init_chunk_J2KTV5FP = __esm({
26966
- "../agent-core/dist/chunk-J2KTV5FP.js"() {
26967
- "use strict";
26968
- import_crypto5 = require("crypto");
26969
- init_agent2();
26970
- import_crypto6 = require("crypto");
26971
- init_agent2();
26972
- init_runtime_v2();
26973
- import_promises14 = require("fs/promises");
26974
- import_os2 = require("os");
26975
- import_path5 = require("path");
26976
- MANAGED_MCP_SERVER_NAME = "alan";
26977
- RUN_SCOPED_SERVER = /^alan-run-[a-f0-9]{16}$/;
26978
- NAMESPACED_RUN_TOOL = /^mcp__(alan-run-[a-f0-9]{16})__(.+)$/;
26979
- FLATTENED_RUN_TOOL = /^alan-run-[a-f0-9]{16}_(.+)$/;
26980
- }
26981
- });
26982
-
26983
26905
  // ../agent-core/dist/chunk-DLVRNIY5.js
26984
26906
  function repositories(input2, context) {
26985
26907
  const problems = new Map(input2.problems.map((problem) => [problem.path, problem]));
@@ -27790,6 +27712,131 @@ var init_chunk_DLVRNIY5 = __esm({
27790
27712
  }
27791
27713
  });
27792
27714
 
27715
+ // ../agent-core/dist/chunk-OSECDZA5.js
27716
+ function selectExternalMcpServers(spec) {
27717
+ const isWorkflow = Boolean(spec.workflowId || spec.workflowExecutionId);
27718
+ const filter = isWorkflow ? createWorkflowToolsFilter(spec.workflowTools) : null;
27719
+ if (filter && !filter.hasFilter) return {};
27720
+ const selected = {};
27721
+ for (const [name, server] of Object.entries(spec.externalMcpServers ?? {})) {
27722
+ if (!isExternalMcpServerName(name)) continue;
27723
+ if (filter && !filter.isMcpServerAllowed(name)) continue;
27724
+ selected[name] = server;
27725
+ }
27726
+ return selected;
27727
+ }
27728
+ function headerEnvName(server, header) {
27729
+ const fingerprint = (0, import_crypto5.createHash)("sha256").update(`${server}\0${header}`).digest("hex").slice(0, 12);
27730
+ return `ALAN_MCP_HEADER_${fingerprint.toUpperCase()}`;
27731
+ }
27732
+ function deliverRemote(name, server, env) {
27733
+ const headerEnv = {};
27734
+ for (const [header, value] of Object.entries(server.headers ?? {})) {
27735
+ if (!isMcpConfigKey(header)) continue;
27736
+ const variable = headerEnvName(name, header);
27737
+ env[variable] = value;
27738
+ headerEnv[header] = variable;
27739
+ }
27740
+ return {
27741
+ type: server.type === "sse" ? "sse" : "http",
27742
+ url: server.url,
27743
+ ...Object.keys(headerEnv).length ? { headerEnv } : {}
27744
+ };
27745
+ }
27746
+ function deliverStdio(server, cliEnv, delivery) {
27747
+ const envKeys = [];
27748
+ for (const [key, value] of Object.entries(server.env ?? {})) {
27749
+ if (!isMcpConfigKey(key)) continue;
27750
+ if (key in cliEnv || key in delivery.env && delivery.env[key] !== value) {
27751
+ delivery.skippedEnvKeys.push(key);
27752
+ continue;
27753
+ }
27754
+ delivery.env[key] = value;
27755
+ envKeys.push(key);
27756
+ }
27757
+ return {
27758
+ type: "stdio",
27759
+ command: server.command,
27760
+ ...server.args?.length ? { args: server.args } : {},
27761
+ ...envKeys.length ? { envKeys } : {}
27762
+ };
27763
+ }
27764
+ function planExternalMcpDelivery(spec, cliEnv) {
27765
+ const delivery = { servers: {}, env: {}, skippedEnvKeys: [] };
27766
+ for (const [name, server] of Object.entries(selectExternalMcpServers(spec))) {
27767
+ const { url: url2, command } = server;
27768
+ if (url2 && server.type !== "stdio") {
27769
+ delivery.servers[name] = deliverRemote(name, { ...server, url: url2 }, delivery.env);
27770
+ } else if (command) {
27771
+ delivery.servers[name] = deliverStdio({ ...server, command }, cliEnv, delivery);
27772
+ }
27773
+ }
27774
+ return delivery;
27775
+ }
27776
+ function envReference(name) {
27777
+ return `\${${name}}`;
27778
+ }
27779
+ function managedMcpHeaders(identity) {
27780
+ if (identity.scope === "run") {
27781
+ return {
27782
+ Authorization: envReference(ALAN_MCP_AUTHORIZATION_ENV),
27783
+ [MANAGED_MCP_RUN_HEADER]: envReference(ALAN_RUN_ID_ENV)
27784
+ };
27785
+ }
27786
+ return {
27787
+ ...identity.authorization === void 0 ? {} : { Authorization: identity.authorization },
27788
+ [MANAGED_MCP_CONVERSATION_HEADER]: identity.conversationId
27789
+ };
27790
+ }
27791
+ function credentialDigest(authorization) {
27792
+ if (authorization === void 0) return void 0;
27793
+ return (0, import_crypto6.createHash)("sha256").update(authorization).digest("hex").slice(0, 16);
27794
+ }
27795
+ function canonicalizeManagedMcpServerName(serverName) {
27796
+ return RUN_SCOPED_SERVER.test(serverName) ? MANAGED_MCP_SERVER_NAME : serverName;
27797
+ }
27798
+ function canonicalizeManagedMcpToolName(toolName) {
27799
+ const namespaced = NAMESPACED_RUN_TOOL.exec(toolName);
27800
+ if (namespaced) return `mcp__${MANAGED_MCP_SERVER_NAME}__${namespaced[2]}`;
27801
+ const flattened = FLATTENED_RUN_TOOL.exec(toolName);
27802
+ return flattened ? `mcp__${MANAGED_MCP_SERVER_NAME}__${flattened[1]}` : toolName;
27803
+ }
27804
+ async function writeSecretFile(name, contents) {
27805
+ const dir = await (0, import_promises14.mkdtemp)((0, import_path5.join)((0, import_os2.tmpdir)(), "alan-mcp-"));
27806
+ const path = (0, import_path5.join)(dir, name);
27807
+ const remove = async () => {
27808
+ await (0, import_promises14.rm)(dir, { recursive: true, force: true });
27809
+ };
27810
+ try {
27811
+ await (0, import_promises14.writeFile)(path, contents, { mode: 384, flag: "wx" });
27812
+ } catch (error62) {
27813
+ await remove();
27814
+ throw error62;
27815
+ }
27816
+ return { path, remove, [Symbol.asyncDispose]: remove };
27817
+ }
27818
+ var import_crypto5, import_crypto6, import_promises14, import_os2, import_path5, OPENCODE_CODE_MODE_ENV, OPENCODE_CODE_MODE_TOOL, CODE_MODE_CALLS_META, MANAGED_MCP_SERVER_NAME, RUN_SCOPED_SERVER, NAMESPACED_RUN_TOOL, FLATTENED_RUN_TOOL;
27819
+ var init_chunk_OSECDZA5 = __esm({
27820
+ "../agent-core/dist/chunk-OSECDZA5.js"() {
27821
+ "use strict";
27822
+ import_crypto5 = require("crypto");
27823
+ init_agent2();
27824
+ import_crypto6 = require("crypto");
27825
+ init_agent2();
27826
+ init_runtime_v2();
27827
+ import_promises14 = require("fs/promises");
27828
+ import_os2 = require("os");
27829
+ import_path5 = require("path");
27830
+ OPENCODE_CODE_MODE_ENV = "OPENCODE_EXPERIMENTAL_CODE_MODE";
27831
+ OPENCODE_CODE_MODE_TOOL = "execute";
27832
+ CODE_MODE_CALLS_META = "alanToolCalls";
27833
+ MANAGED_MCP_SERVER_NAME = "alan";
27834
+ RUN_SCOPED_SERVER = /^alan-run-[a-f0-9]{16}$/;
27835
+ NAMESPACED_RUN_TOOL = /^mcp__(alan-run-[a-f0-9]{16})__(.+)$/;
27836
+ FLATTENED_RUN_TOOL = /^alan-run-[a-f0-9]{16}_(.+)$/;
27837
+ }
27838
+ });
27839
+
27793
27840
  // ../agent-core/dist/providers/claude.js
27794
27841
  function trimmed(value) {
27795
27842
  const text2 = value?.trim();
@@ -27821,16 +27868,16 @@ function externalServerConfig(server) {
27821
27868
  };
27822
27869
  }
27823
27870
  function claudeMcpConfig(mcp) {
27824
- const mcpServers = /* @__PURE__ */ Object.create(null);
27871
+ const mcpServers2 = /* @__PURE__ */ Object.create(null);
27825
27872
  for (const [name, server] of Object.entries(mcp.externalServers ?? {})) {
27826
- mcpServers[name] = externalServerConfig(server);
27873
+ mcpServers2[name] = externalServerConfig(server);
27827
27874
  }
27828
- mcpServers.alan = {
27875
+ mcpServers2.alan = {
27829
27876
  type: "http",
27830
27877
  url: mcp.alanMcpUrl,
27831
27878
  headers: managedMcpHeaders(mcp.identity)
27832
27879
  };
27833
- return { mcpServers };
27880
+ return { mcpServers: mcpServers2 };
27834
27881
  }
27835
27882
  function carriesCredential(mcp) {
27836
27883
  return mcp.identity.scope === "conversation" && mcp.identity.authorization !== void 0;
@@ -28055,11 +28102,27 @@ function parseStreamEvent(event, state) {
28055
28102
  function stringList(value) {
28056
28103
  return asArray(value).map((item) => asString(item)).filter(Boolean);
28057
28104
  }
28105
+ function mcpServers(value) {
28106
+ const servers = [];
28107
+ for (const item of asArray(value)) {
28108
+ const record2 = asRecord(item);
28109
+ const name = asString(record2?.name);
28110
+ if (!record2 || !name) continue;
28111
+ const source = asString(record2.source);
28112
+ servers.push({
28113
+ name,
28114
+ status: CLAUDE_MCP_STATUS[asString(record2.status)] ?? "unknown",
28115
+ ...source ? { source } : {}
28116
+ });
28117
+ }
28118
+ return servers;
28119
+ }
28058
28120
  function initUpdates(event, state) {
28059
28121
  const model = asString(event.model);
28060
28122
  if (model) state.model = model;
28061
28123
  const tools = stringList(event.tools);
28062
28124
  const slashCommands = stringList(event.slash_commands);
28125
+ const servers = mcpServers(event.mcp_servers);
28063
28126
  return [
28064
28127
  {
28065
28128
  sessionUpdate: "_alan/log",
@@ -28073,7 +28136,8 @@ function initUpdates(event, state) {
28073
28136
  ...tools.length > 0 ? { [TOOLS_META]: tools } : {},
28074
28137
  ...slashCommands.length > 0 ? { [SLASH_COMMANDS_META]: slashCommands } : {}
28075
28138
  }
28076
- }
28139
+ },
28140
+ ...servers.length > 0 ? [{ sessionUpdate: "_alan/mcp_servers", servers }] : []
28077
28141
  ];
28078
28142
  }
28079
28143
  function thinkingTokens(event) {
@@ -28833,17 +28897,17 @@ async function claudeTurnInput(run, context) {
28833
28897
  );
28834
28898
  return { turnId: run.runId, text: text2, ...encoded.length ? { images: encoded } : {} };
28835
28899
  }
28836
- var import_crypto7, import_fs6, import_path6, import_crypto8, import_promises15, EDIT_TOOLS, ThoughtBlocks, UNDERSTOOD_SYSTEM_SUBTYPES, RATE_LIMIT_WARN_AT, CLAUDE_GRAMMAR_NAME, SUBAGENT_TOOL_NAMES, controlResponseSchema, STOPPED_STATUSES, TaskRecords, TERMINAL_BACKGROUND_STATUSES, NON_TERMINAL_BACKGROUND_STATUSES, ASYNC_LAUNCH_ACK, BackgroundTasks, FAILED_STATUSES, STOPPED_BY_USER_TEXT, ClaudeTurn, STDERR_TAIL_LINES2, MAX_EARLY_LINES, UNSUPPORTED_STOP, OUTPUT_CLOSED_REASON, ClaudeSession, DEFAULTS, READ_ONLY_DISALLOWED_TOOLS, DEFAULT_MCP_TIMEOUT_MS;
28900
+ var import_crypto7, import_fs6, import_path6, import_crypto8, import_promises15, EDIT_TOOLS, ThoughtBlocks, UNDERSTOOD_SYSTEM_SUBTYPES, CLAUDE_MCP_STATUS, RATE_LIMIT_WARN_AT, CLAUDE_GRAMMAR_NAME, SUBAGENT_TOOL_NAMES, controlResponseSchema, STOPPED_STATUSES, TaskRecords, TERMINAL_BACKGROUND_STATUSES, NON_TERMINAL_BACKGROUND_STATUSES, ASYNC_LAUNCH_ACK, BackgroundTasks, FAILED_STATUSES, STOPPED_BY_USER_TEXT, ClaudeTurn, STDERR_TAIL_LINES2, MAX_EARLY_LINES, UNSUPPORTED_STOP, OUTPUT_CLOSED_REASON, ClaudeSession, DEFAULTS, READ_ONLY_DISALLOWED_TOOLS, DEFAULT_MCP_TIMEOUT_MS;
28837
28901
  var init_claude = __esm({
28838
28902
  "../agent-core/dist/providers/claude.js"() {
28839
28903
  "use strict";
28840
28904
  init_chunk_D4TIXPWZ();
28841
- init_chunk_ILZBXGVI();
28905
+ init_chunk_FYZKVT3E();
28842
28906
  init_chunk_OUEMTEUX();
28843
28907
  init_chunk_ZCTKXKYY();
28844
- init_chunk_J2KTV5FP();
28845
28908
  init_chunk_6VWVDJ2A();
28846
28909
  init_chunk_DLVRNIY5();
28910
+ init_chunk_OSECDZA5();
28847
28911
  init_chunk_YXWJW7I5();
28848
28912
  init_effort();
28849
28913
  import_crypto7 = require("crypto");
@@ -28902,6 +28966,13 @@ var init_claude = __esm({
28902
28966
  "status",
28903
28967
  "commands_changed"
28904
28968
  ]);
28969
+ CLAUDE_MCP_STATUS = {
28970
+ connected: "connected",
28971
+ pending: "starting",
28972
+ "needs-auth": "needs_auth",
28973
+ failed: "failed",
28974
+ disabled: "disabled"
28975
+ };
28905
28976
  RATE_LIMIT_WARN_AT = 0.8;
28906
28977
  CLAUDE_GRAMMAR_NAME = "claude_cli";
28907
28978
  SUBAGENT_TOOL_NAMES = /* @__PURE__ */ new Set(["agent", "task"]);
@@ -31045,17 +31116,17 @@ function codexTurnInput(run, context) {
31045
31116
  ...images.length ? { imagePaths: images.map((image) => image.path) } : {}
31046
31117
  };
31047
31118
  }
31048
- var import_fs7, import_path7, import_crypto9, import_crypto10, import_crypto11, import_crypto12, TokenRefresher, MCP_STARTUP_TIMEOUT_SEC, FIELD_TYPES, YES_NO, ACCEPT_DECLINE, MAX_INLINE_GENERATED_IMAGE_BYTES, PNG_SIGNATURE2, JPEG_NON_FRAME_MARKERS, IMAGE_GEN_CALL, PROMPT_LITERAL, RELOCATE_EVERY_MS, CodexImageGenerationFold, CodexRolloutImages, CodexRateLimits, USER_INPUT_METHOD, PERMISSIONS_METHOD, ELICITATION_METHOD, COMMAND_OR_FILE, LEGACY, DECISIONS, COORDINATION_TOOLS, SETTLED_AGENT, STATUS, CHANGE_OPERATIONS, SILENT_ON_START, IGNORED_ITEMS, PLAN_STATUS, WORKER_LIFECYCLE, INFO_KINDS, SILENT, CodexTurn, STDERR_TAIL_LINES3, MAX_BETWEEN_UPDATES, UNSUPPORTED_REQUEST, DECLINED_ELICITATION, IMAGE_CATCH_UP_MS, IMAGE_POLL_MS, CodexSession, CODEX_MIN_VERSION, CODEX_REQUIREMENT, CODEX_TESTED_LINE, DEFAULTS2, CLIENT_INFO, STATUS2, EXITED_WITHOUT_RESPONSE, CodexExecTurn, DEFAULTS22, CodexExecSession;
31119
+ var import_fs7, import_path7, import_crypto9, import_crypto10, import_crypto11, import_crypto12, TokenRefresher, MCP_STARTUP_TIMEOUT_SEC, FIELD_TYPES, YES_NO, ACCEPT_DECLINE, MAX_INLINE_GENERATED_IMAGE_BYTES, PNG_SIGNATURE2, JPEG_NON_FRAME_MARKERS, IMAGE_GEN_CALL, PROMPT_LITERAL, RELOCATE_EVERY_MS, CodexImageGenerationFold, CodexRolloutImages, CodexRateLimits, USER_INPUT_METHOD, PERMISSIONS_METHOD, ELICITATION_METHOD, COMMAND_OR_FILE, LEGACY, DECISIONS, COORDINATION_TOOLS, SETTLED_AGENT, STATUS, CHANGE_OPERATIONS, SILENT_ON_START, IGNORED_ITEMS, PLAN_STATUS, CODEX_MCP_STATUS, WORKER_LIFECYCLE, INFO_KINDS, SILENT, CodexTurn, STDERR_TAIL_LINES3, MAX_BETWEEN_UPDATES, UNSUPPORTED_REQUEST, DECLINED_ELICITATION, IMAGE_CATCH_UP_MS, IMAGE_POLL_MS, CodexSession, CODEX_MIN_VERSION, CODEX_REQUIREMENT, CODEX_TESTED_LINE, DEFAULTS2, CLIENT_INFO, STATUS2, EXITED_WITHOUT_RESPONSE, CodexExecTurn, DEFAULTS22, CodexExecSession;
31049
31120
  var init_codex = __esm({
31050
31121
  "../agent-core/dist/providers/codex.js"() {
31051
31122
  "use strict";
31052
31123
  init_chunk_D4TIXPWZ();
31053
- init_chunk_ILZBXGVI();
31124
+ init_chunk_FYZKVT3E();
31054
31125
  init_chunk_OUEMTEUX();
31055
31126
  init_chunk_ZCTKXKYY();
31056
- init_chunk_J2KTV5FP();
31057
31127
  init_chunk_6VWVDJ2A();
31058
31128
  init_chunk_DLVRNIY5();
31129
+ init_chunk_OSECDZA5();
31059
31130
  init_chunk_YXWJW7I5();
31060
31131
  import_fs7 = require("fs");
31061
31132
  import_path7 = require("path");
@@ -31338,6 +31409,12 @@ var init_codex = __esm({
31338
31409
  ["inProgress", "in_progress"],
31339
31410
  ["completed", "completed"]
31340
31411
  ]);
31412
+ CODEX_MCP_STATUS = {
31413
+ starting: "starting",
31414
+ ready: "connected",
31415
+ failed: "failed",
31416
+ cancelled: "failed"
31417
+ };
31341
31418
  WORKER_LIFECYCLE = /* @__PURE__ */ new Set([
31342
31419
  "turn/started",
31343
31420
  "turn/completed",
@@ -31489,20 +31566,29 @@ var init_codex = __esm({
31489
31566
  )
31490
31567
  ];
31491
31568
  }
31569
+ #mcpStatus(params) {
31570
+ const name = asString(params.name);
31571
+ if (!name) return [];
31572
+ const reported = asString(params.status);
31573
+ const reason = asString(params.error) || asString(params.failureReason);
31574
+ const status = CODEX_MCP_STATUS[reported] ?? "unknown";
31575
+ const listed = {
31576
+ sessionUpdate: "_alan/mcp_servers",
31577
+ servers: [{ name, status, ...status === "failed" && reason ? { error: reason } : {} }]
31578
+ };
31579
+ if (reported !== "failed") return [listed];
31580
+ return [listed, ...this.#mcpFailure(name, reason)];
31581
+ }
31492
31582
  /**
31493
31583
  * Only Alan's own MCP server failing matters in the chat: its tools are gone for the session.
31494
31584
  * The user's other servers (and their logins) belong to their Codex setup, not to Alan.
31495
31585
  */
31496
- #mcpStatus(params) {
31497
- if (asString(params.status) !== "failed") return [];
31498
- const name = asString(params.name);
31586
+ #mcpFailure(name, reason) {
31499
31587
  if (canonicalizeManagedMcpServerName(name) !== MANAGED_MCP_SERVER_NAME) {
31500
- const reason2 = asString(params.error) || asString(params.failureReason);
31501
31588
  return [
31502
- logUpdate("codex/mcp", `MCP server ${name} failed to start${reason2 ? `: ${reason2}` : "."}`)
31589
+ logUpdate("codex/mcp", `MCP server ${name} failed to start${reason ? `: ${reason}` : "."}`)
31503
31590
  ];
31504
31591
  }
31505
- const reason = asString(params.error) || asString(params.failureReason);
31506
31592
  const key = `mcp_server_failed\0${reason}`;
31507
31593
  if (this.#memory.shownWarnings.has(key)) return [];
31508
31594
  this.#memory.shownWarnings.add(key);
@@ -32328,6 +32414,47 @@ const PROVIDER_ID = ${JSON.stringify(ALAN_CODE_ENGINE_PROVIDER_ID)};
32328
32414
  const INCLUDED_RESULTS = 8;
32329
32415
  const MAX_AUTO_RETRIES = 2;
32330
32416
  const MAX_AUTO_RETRY_WAIT_MS = 10_000;
32417
+ const CODE_MODE_TOOL = ${JSON.stringify(OPENCODE_CODE_MODE_TOOL)};
32418
+ const CODE_MODE_CALLS_META = ${JSON.stringify(CODE_MODE_CALLS_META)};
32419
+ const MAX_CHILD_OUTPUT_CHARS = 64 * 1024;
32420
+ const MAX_OPEN_SCRIPTS = 64;
32421
+ const scriptCalls = new Map();
32422
+
32423
+ function mcpResultText(result) {
32424
+ return result.content
32425
+ .flatMap(function (item) {
32426
+ if (item && item.type === "text") return [item.text];
32427
+ if (item && item.type === "resource" && item.resource && item.resource.text) return [item.resource.text];
32428
+ return [];
32429
+ })
32430
+ .join("\\n\\n");
32431
+ }
32432
+
32433
+ function openScript(callID) {
32434
+ if (scriptCalls.size >= MAX_OPEN_SCRIPTS) scriptCalls.delete(scriptCalls.keys().next().value);
32435
+ scriptCalls.set(callID, []);
32436
+ }
32437
+
32438
+ // Code mode names each MCP call "<script callID>/<n>" and hands the hook the raw MCP result.
32439
+ function recordScriptCall(input, result) {
32440
+ const callID = String(input.callID || "");
32441
+ const slash = callID.lastIndexOf("/");
32442
+ const calls = slash > 0 ? scriptCalls.get(callID.slice(0, slash)) : undefined;
32443
+ if (!calls || !result || !Array.isArray(result.content)) return;
32444
+ calls.push({
32445
+ callId: callID,
32446
+ tool: input.tool,
32447
+ input: input.args,
32448
+ output: mcpResultText(result).slice(0, MAX_CHILD_OUTPUT_CHARS),
32449
+ });
32450
+ }
32451
+
32452
+ function closeScript(callID, output) {
32453
+ const calls = scriptCalls.get(callID);
32454
+ scriptCalls.delete(callID);
32455
+ if (!calls || calls.length === 0 || !output || typeof output !== "object") return;
32456
+ output.metadata = Object.assign({}, output.metadata, { [CODE_MODE_CALLS_META]: calls });
32457
+ }
32331
32458
 
32332
32459
  function truncate(text, max) {
32333
32460
  const trimmed = String(text == null ? "" : text).trim();
@@ -32435,6 +32562,13 @@ export const AlanEnginePlugin = async () => ({
32435
32562
  output.headers["x-alan-operation-key"] = Date.now() + "-" + crypto.randomUUID();
32436
32563
  }
32437
32564
  },
32565
+ "tool.execute.before": async (input) => {
32566
+ if (input.tool === CODE_MODE_TOOL) openScript(input.callID);
32567
+ },
32568
+ "tool.execute.after": async (input, output) => {
32569
+ if (input.tool === CODE_MODE_TOOL) closeScript(input.callID, output);
32570
+ else recordScriptCall(input, output);
32571
+ },
32438
32572
  tool: {
32439
32573
  web_search: {
32440
32574
  description: "web_search: Search the public web via Alan's Parallel proxy. Use when you do not already have a URL. Follow up with webfetch on the best result(s).",
@@ -32468,6 +32602,7 @@ function bearerToken(authorization) {
32468
32602
  function alanCodeEngineEnv(input2) {
32469
32603
  return {
32470
32604
  ...alanCodeEngineDirectories(input2.engineRoot),
32605
+ [OPENCODE_CODE_MODE_ENV]: "true",
32471
32606
  [ALAN_CODE_API_KEY_ENV]: input2.apiKey,
32472
32607
  [ALAN_CODE_CONVERSATION_ID_ENV]: input2.conversationId
32473
32608
  };
@@ -32511,6 +32646,7 @@ var import_http3, import_https, import_fs8, import_path8, import_crypto13, impor
32511
32646
  var init_alan_code = __esm({
32512
32647
  "../agent-core/dist/providers/alan-code.js"() {
32513
32648
  "use strict";
32649
+ init_chunk_OSECDZA5();
32514
32650
  init_chunk_YXWJW7I5();
32515
32651
  import_http3 = require("http");
32516
32652
  import_https = require("https");
@@ -32553,10 +32689,15 @@ var init_alan_code = __esm({
32553
32689
  emptyTurn: "Alan Code ended the turn without producing any output. Try again or pick another model."
32554
32690
  };
32555
32691
  WINDOWS_RUNNABLE_EXTENSION = /\.(exe|com|cmd|bat)$/i;
32556
- ALAN_CODE_ENGINE_PLUGIN_VERSION = 2;
32692
+ ALAN_CODE_ENGINE_PLUGIN_VERSION = 3;
32557
32693
  ALAN_CODE_TOOL_NAMING_PROMPT = `## Alan tool names
32558
32694
 
32559
- This engine exposes Alan MCP tools with an \`alan_\` prefix. Where these instructions name an Alan tool, call its prefixed form: \`search_context\` is \`alan_search_context\`, \`search_code_context\` is \`alan_search_code_context\`, and \`find_records\` is \`alan_find_records\`.`;
32695
+ Alan's MCP tools are not separate tools in this engine. Call them inside an \`execute\` script under the \`alan\` namespace: \`search_context\` is \`tools.alan.search_context({ ... })\`, \`search_code_context\` is \`tools.alan.search_code_context({ ... })\`, and \`find_records\` is \`tools.alan.find_records({ ... })\`.
32696
+
32697
+ - Before the first call to a tool whose signature is not shown in the \`execute\` description, read it with \`tools.$codemode.search({ query: "<tool name>" })\` and pass exactly its fields.
32698
+ - Alan tools return JSON as text: \`JSON.parse\` a result before reading its fields or passing it to \`Object.keys\`.
32699
+ - Look up IDs in one script, then make the writes in the next, so a failed lookup never leaves half the writes done.
32700
+ - Pass an \`idempotencyKey\` naming each change (for example \`create-task:<title>\`) on every write that accepts one. If a script fails, check what it already created before running it again, and run only the writes that are missing.`;
32560
32701
  }
32561
32702
  });
32562
32703
 
@@ -39891,7 +40032,7 @@ var require_dist = __commonJS({
39891
40032
  var init_dist = __esm({
39892
40033
  "../agent-core/dist/index.js"() {
39893
40034
  "use strict";
39894
- init_chunk_ILZBXGVI();
40035
+ init_chunk_FYZKVT3E();
39895
40036
  init_chunk_OUEMTEUX();
39896
40037
  init_chunk_ZCTKXKYY();
39897
40038
  init_chunk_6VWVDJ2A();
@@ -40638,12 +40779,12 @@ var import_promises24, import_path10, import_crypto14, import_promises25, CURSOR
40638
40779
  var init_acp3 = __esm({
40639
40780
  "../agent-core/dist/providers/acp.js"() {
40640
40781
  "use strict";
40641
- init_chunk_ILZBXGVI();
40782
+ init_chunk_FYZKVT3E();
40642
40783
  init_chunk_OUEMTEUX();
40643
40784
  init_chunk_ZCTKXKYY();
40644
- init_chunk_J2KTV5FP();
40645
40785
  init_chunk_6VWVDJ2A();
40646
40786
  init_chunk_DLVRNIY5();
40787
+ init_chunk_OSECDZA5();
40647
40788
  init_chunk_YXWJW7I5();
40648
40789
  import_promises24 = require("fs/promises");
40649
40790
  import_path10 = require("path");
@@ -41901,7 +42042,8 @@ var init_persistent = __esm({
41901
42042
  "user_message",
41902
42043
  "user_message_chunk",
41903
42044
  "_alan/log",
41904
- "_alan/thinking_tokens"
42045
+ "_alan/thinking_tokens",
42046
+ "_alan/mcp_servers"
41905
42047
  ]);
41906
42048
  FIRST_OUTPUT_TIMEOUT_MS = 3e5;
41907
42049
  }
@@ -42144,6 +42286,21 @@ function classifyOpenCodeError(error62, fallback) {
42144
42286
  }
42145
42287
  return classifyCliError(message || fallback);
42146
42288
  }
42289
+ function readChildCall(value) {
42290
+ const record2 = asRecord(value);
42291
+ const callId = asString(record2?.callId);
42292
+ const tool = asString(record2?.tool);
42293
+ if (!record2 || !callId || !tool) return void 0;
42294
+ return { callId, tool, input: record2.input, output: asString(record2.output) };
42295
+ }
42296
+ function readCodeModeChildCalls(metadata) {
42297
+ return asArray(asRecord(metadata)?.[CODE_MODE_CALLS_META]).flatMap(
42298
+ (entry) => {
42299
+ const call = readChildCall(entry);
42300
+ return call ? [call] : [];
42301
+ }
42302
+ );
42303
+ }
42147
42304
  function withParent(updates, parentToolCallId) {
42148
42305
  if (!parentToolCallId) return updates;
42149
42306
  return updates.map(
@@ -42234,6 +42391,24 @@ function toolContent(tool, toolState) {
42234
42391
  const editing = tool.status === "in_progress" && (tool.name === "edit" || tool.name === "write");
42235
42392
  return editing && path ? [fileChangeContent({ path, operation: "modify", hunks: [] })] : void 0;
42236
42393
  }
42394
+ function codeModeChildUpdates(tool, metadata) {
42395
+ if (tool.name !== OPENCODE_CODE_MODE_TOOL || tool.status !== "completed") return [];
42396
+ return readCodeModeChildCalls(metadata).map((call) => {
42397
+ const name = canonicalizeManagedMcpToolName(call.tool);
42398
+ const content = outputContent(call.output);
42399
+ return {
42400
+ sessionUpdate: "tool_call_update",
42401
+ toolCallId: call.callId,
42402
+ name,
42403
+ title: name,
42404
+ kind: toolKindFor(name),
42405
+ status: "completed",
42406
+ ...call.input !== void 0 ? { rawInput: call.input } : {},
42407
+ ...content ? { content } : {},
42408
+ ...call.output ? { rawOutput: call.output } : {}
42409
+ };
42410
+ });
42411
+ }
42237
42412
  function createOpenCodeSessionMemory() {
42238
42413
  return { userMessageIds: /* @__PURE__ */ new Set() };
42239
42414
  }
@@ -42572,12 +42747,12 @@ var import_crypto15, import_http4, import_crypto16, import_promises26, import_pa
42572
42747
  var init_opencode = __esm({
42573
42748
  "../agent-core/dist/providers/opencode.js"() {
42574
42749
  "use strict";
42575
- init_chunk_ILZBXGVI();
42750
+ init_chunk_FYZKVT3E();
42576
42751
  init_chunk_OUEMTEUX();
42577
42752
  init_chunk_ZCTKXKYY();
42578
- init_chunk_J2KTV5FP();
42579
42753
  init_chunk_6VWVDJ2A();
42580
42754
  init_chunk_DLVRNIY5();
42755
+ init_chunk_OSECDZA5();
42581
42756
  init_chunk_YXWJW7I5();
42582
42757
  import_crypto15 = require("crypto");
42583
42758
  import_http4 = require("http");
@@ -43103,6 +43278,7 @@ var init_opencode = __esm({
43103
43278
  }
43104
43279
  ];
43105
43280
  updates.push(...this.#plan(toolCallId, tool.name, toolState));
43281
+ updates.push(...codeModeChildUpdates(tool, toolState?.metadata));
43106
43282
  if (tool.status === "failed" && (tool.isTask || PERMISSION_DENIED.test(tool.errorMessage))) {
43107
43283
  updates.push(
43108
43284
  noticeUpdate("error", "tool_failed", tool.errorMessage || "OpenCode tool call failed.")
@@ -44622,12 +44798,12 @@ var import_crypto18, import_promises27, FACTORY_API_VERSION, FACTORY_PROTOCOL_VE
44622
44798
  var init_droid = __esm({
44623
44799
  "../agent-core/dist/providers/droid.js"() {
44624
44800
  "use strict";
44625
- init_chunk_ILZBXGVI();
44801
+ init_chunk_FYZKVT3E();
44626
44802
  init_chunk_OUEMTEUX();
44627
44803
  init_chunk_ZCTKXKYY();
44628
- init_chunk_J2KTV5FP();
44629
44804
  init_chunk_6VWVDJ2A();
44630
44805
  init_chunk_DLVRNIY5();
44806
+ init_chunk_OSECDZA5();
44631
44807
  init_chunk_YXWJW7I5();
44632
44808
  init_runtime_v2();
44633
44809
  import_crypto18 = require("crypto");
@@ -45732,7 +45908,7 @@ var init_antigravity = __esm({
45732
45908
  "../agent-core/dist/providers/antigravity.js"() {
45733
45909
  "use strict";
45734
45910
  init_chunk_D4TIXPWZ();
45735
- init_chunk_ILZBXGVI();
45911
+ init_chunk_FYZKVT3E();
45736
45912
  init_chunk_OUEMTEUX();
45737
45913
  init_chunk_ZCTKXKYY();
45738
45914
  init_chunk_6VWVDJ2A();
@@ -46436,12 +46612,12 @@ var import_promises29, import_path16, import_crypto20, COMMAND_CODE_GRAMMAR_NAME
46436
46612
  var init_command_code = __esm({
46437
46613
  "../agent-core/dist/providers/command-code.js"() {
46438
46614
  "use strict";
46439
- init_chunk_ILZBXGVI();
46615
+ init_chunk_FYZKVT3E();
46440
46616
  init_chunk_OUEMTEUX();
46441
46617
  init_chunk_ZCTKXKYY();
46442
- init_chunk_J2KTV5FP();
46443
46618
  init_chunk_6VWVDJ2A();
46444
46619
  init_chunk_DLVRNIY5();
46620
+ init_chunk_OSECDZA5();
46445
46621
  init_chunk_YXWJW7I5();
46446
46622
  import_promises29 = require("fs/promises");
46447
46623
  import_path16 = require("path");
@@ -50686,7 +50862,19 @@ async function runHolder({
50686
50862
  ...machine?.platform === void 0 ? {} : { platform: machine.platform }
50687
50863
  });
50688
50864
  const observed = facts.observe(driver);
50689
- const writeStatus = () => writeJsonFileAtomic(launch.statusPath, {
50865
+ let statusWrites = Promise.resolve();
50866
+ const writeStatus = () => {
50867
+ const next = statusWrites.then(() => writeStatusNow());
50868
+ statusWrites = next.catch(
50869
+ (error62) => log.warn("holder.status_write_failed", { error: error62 })
50870
+ );
50871
+ return next;
50872
+ };
50873
+ const queueStatus = () => {
50874
+ writeStatus().catch(() => {
50875
+ });
50876
+ };
50877
+ const writeStatusNow = () => writeJsonFileAtomic(launch.statusPath, {
50690
50878
  protocol: HOLDER_PROTOCOL,
50691
50879
  conversationId: launch.conversationId,
50692
50880
  pid: identity.pid,
@@ -50705,7 +50893,7 @@ async function runHolder({
50705
50893
  holder.state = "idle";
50706
50894
  holder.runId = null;
50707
50895
  holder.turn = null;
50708
- void writeStatus();
50896
+ queueStatus();
50709
50897
  };
50710
50898
  const startTurn = (id, spec, client) => {
50711
50899
  if (holder.runId === spec.runId) {
@@ -50749,7 +50937,7 @@ async function runHolder({
50749
50937
  return;
50750
50938
  }
50751
50939
  writeMessage(client, { type: "ack", id });
50752
- void writeStatus();
50940
+ queueStatus();
50753
50941
  runClaimedTurn(spec, claimed, context, turn.signal).then((outcome2) => broadcast({ type: "turn_ended", runId: spec.runId, outcome: outcome2 })).catch((error62) => log.error("holder.turn_crashed", { runId: spec.runId, error: error62 })).finally(settle2);
50754
50942
  },
50755
50943
  (error62) => {
@@ -50887,6 +51075,7 @@ async function runHolder({
50887
51075
  await driver.suspend?.().catch((error62) => log.warn("holder.driver_suspend_failed", { error: error62 }));
50888
51076
  for (const client of holder.clients) client.end();
50889
51077
  await new Promise((resolve8) => server.close(() => resolve8()));
51078
+ await statusWrites;
50890
51079
  (0, import_node_fs11.rmSync)(launch.statusPath, { force: true });
50891
51080
  log.info("holder.suspended", { conversationId: launch.conversationId });
50892
51081
  } catch (_) {