@alan-ai-hq/agent-manager-linux-arm64 0.1.135 → 0.1.137

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 +565 -231
  2. package/alan-holder.cjs +449 -160
  3. package/package.json +1 -1
package/alan-agent.cjs CHANGED
@@ -20104,7 +20104,12 @@ var init_run_context = __esm({
20104
20104
  prMeta: pullRequestMetaSchema.optional(),
20105
20105
  currentUser: agentUserIdentitySchema.optional(),
20106
20106
  sessionVisibility: external_exports.enum(["private", "team"]).nullable().optional(),
20107
- workflowTools: external_exports.array(workflowToolRefSchema).optional()
20107
+ workflowTools: external_exports.array(workflowToolRefSchema).optional(),
20108
+ availableSkills: external_exports.array(external_exports.object({
20109
+ name: external_exports.string().min(1),
20110
+ description: external_exports.string(),
20111
+ packageDirectory: external_exports.string().min(1)
20112
+ })).max(2e3).optional()
20108
20113
  });
20109
20114
  }
20110
20115
  });
@@ -20358,6 +20363,7 @@ var init_desired_state = __esm({
20358
20363
  /** Omitted by older servers; only an explicit entitlement enables context-search guidance. */
20359
20364
  contextGraphEnabled: external_exports.boolean().optional(),
20360
20365
  cloudEnvironmentId: external_exports.guid().optional(),
20366
+ sandboxId: external_exports.string().min(1).optional(),
20361
20367
  localRepoUrls: external_exports.array(external_exports.string().min(1)).optional()
20362
20368
  // Never here: the provider API key. The holder fetches it per run (RUN_PROVIDER_CREDENTIAL_PATH).
20363
20369
  });
@@ -20379,10 +20385,13 @@ var init_desired_state = __esm({
20379
20385
  function runProviderCredentialPath(runId) {
20380
20386
  return `/public/machines/me/runs/${encodeURIComponent(runId)}/provider-credential`;
20381
20387
  }
20388
+ function runCodexCredentialRefreshPath(runId) {
20389
+ return `${runProviderCredentialPath(runId)}/refresh`;
20390
+ }
20382
20391
  function runAttachmentPath(runId, attachmentId) {
20383
20392
  return `/public/machines/me/runs/${encodeURIComponent(runId)}/attachments/${encodeURIComponent(attachmentId)}`;
20384
20393
  }
20385
- var machineEndpointsSchema, machineCredentialGrantSchema, MACHINE_PATHS, machinePlatformSchema, machineRegisterRequestSchema, machineEnrollRequestSchema, machineRenewRequestSchema, machineRenewReusedSchema, deviceAuthorizationSchema, machineDeviceAuthorizationRequestSchema, machineDeviceTokenRequestSchema, machineDeviceTokenSchema, DEVICE_TOKEN_ERRORS, machineDeviceTokenErrorSchema, DEVICE_SLOW_DOWN_INCREMENT_SECONDS, machineMcpCredentialRequestSchema, machineMcpCredentialSchema, runtimeReleaseSchema, machineSiblingSchema, MACHINE_SIBLINGS_LIMIT, machineSiblingsResponseSchema, runProviderCredentialSchema;
20394
+ var machineEndpointsSchema, machineCredentialGrantSchema, MACHINE_PATHS, machinePlatformSchema, machineRegisterRequestSchema, machineEnrollRequestSchema, machineRenewRequestSchema, machineRenewReusedSchema, deviceAuthorizationSchema, machineDeviceAuthorizationRequestSchema, machineDeviceTokenRequestSchema, machineDeviceTokenSchema, DEVICE_TOKEN_ERRORS, machineDeviceTokenErrorSchema, DEVICE_SLOW_DOWN_INCREMENT_SECONDS, machineMcpCredentialRequestSchema, machineMcpCredentialSchema, runtimeReleaseSchema, machineSiblingSchema, MACHINE_SIBLINGS_LIMIT, machineSiblingsResponseSchema, runCodexCredentialSchema, runCodexCredentialRefreshRequestSchema, runProviderCredentialSchema;
20386
20395
  var init_machine_identity = __esm({
20387
20396
  "../shared/dist/runtime-v2/machine-identity.js"() {
20388
20397
  "use strict";
@@ -20498,9 +20507,20 @@ var init_machine_identity = __esm({
20498
20507
  machineSiblingsResponseSchema = external_exports.object({
20499
20508
  machines: external_exports.array(machineSiblingSchema).max(MACHINE_SIBLINGS_LIMIT)
20500
20509
  });
20510
+ runCodexCredentialSchema = external_exports.object({
20511
+ accessToken: external_exports.string().min(1),
20512
+ chatgptAccountId: external_exports.string().min(1),
20513
+ chatgptPlanType: external_exports.string().nullable()
20514
+ });
20515
+ runCodexCredentialRefreshRequestSchema = external_exports.object({
20516
+ /** sha256 hex of the access token Codex was refused with; a newer stored token is returned instead of rotating. */
20517
+ rejectedAccessTokenSha256: external_exports.string().regex(/^[0-9a-f]{64}$/).optional()
20518
+ });
20501
20519
  runProviderCredentialSchema = external_exports.object({
20502
20520
  /** Environment variables for the agent CLI, e.g. ANTHROPIC_API_KEY; empty when the CLI's own login is used. */
20503
- env: external_exports.record(external_exports.string(), external_exports.string())
20521
+ env: external_exports.record(external_exports.string(), external_exports.string()),
20522
+ /** The team's Codex login for a cloud sandbox; absent where the CLI's own login is used. */
20523
+ codex: runCodexCredentialSchema.optional()
20504
20524
  });
20505
20525
  }
20506
20526
  });
@@ -21358,6 +21378,7 @@ var init_workflow_tools_filter = __esm({
21358
21378
  WORKFLOW_ALWAYS_ALLOWED_BUILTIN_TOOLS = [
21359
21379
  "search_context",
21360
21380
  "create_test_report",
21381
+ "publish_capture",
21361
21382
  "create_plan",
21362
21383
  "create_document_artifact",
21363
21384
  "list_artifacts",
@@ -21839,12 +21860,14 @@ function isExternalMcpServerName(name) {
21839
21860
  function isMcpConfigKey(name) {
21840
21861
  return MCP_CONFIG_KEY.test(name);
21841
21862
  }
21842
- var ALAN_MCP_AUTHORIZATION_ENV, ALAN_RUN_ID_ENV, MCP_CONFIG_KEY;
21863
+ var ALAN_MCP_AUTHORIZATION_ENV, ALAN_RUN_ID_ENV, ALAN_MCP_URL_ENV, ALAN_MCP_CREDENTIAL_FILE_ENV, MCP_CONFIG_KEY;
21843
21864
  var init_mcp_config = __esm({
21844
21865
  "../shared/dist/agent/mcp-config.js"() {
21845
21866
  "use strict";
21846
21867
  ALAN_MCP_AUTHORIZATION_ENV = "ALAN_MCP_AUTHORIZATION";
21847
21868
  ALAN_RUN_ID_ENV = "ALAN_RUN_ID";
21869
+ ALAN_MCP_URL_ENV = "ALAN_MCP_URL";
21870
+ ALAN_MCP_CREDENTIAL_FILE_ENV = "ALAN_MCP_CREDENTIAL_FILE";
21848
21871
  MCP_CONFIG_KEY = /^[A-Za-z0-9_-]+$/;
21849
21872
  }
21850
21873
  });
@@ -24402,11 +24425,20 @@ var init_chunk_DALFHI4B = __esm({
24402
24425
  }
24403
24426
  });
24404
24427
 
24405
- // ../agent-core/dist/chunk-R6R6ORR2.js
24428
+ // ../agent-core/dist/chunk-54ZRJOQP.js
24406
24429
  function specForErrorKind(errorKind) {
24407
24430
  const spec = ERROR_SPECS[errorKind];
24408
24431
  return { message: spec.message, errorKind, recoveryClass: spec.recoveryClass };
24409
24432
  }
24433
+ function withAgentSignIn(classified, harness) {
24434
+ const agent = AGENT_SIGN_IN_BY_HARNESS.get(harness);
24435
+ if (!agent || classified.message !== ERROR_SPECS.not_logged_in.message) return classified;
24436
+ const local = agent.localSignIn ?? "sign in to it";
24437
+ return {
24438
+ ...classified,
24439
+ message: `${agent.name} isn't signed in: for cloud runs connect it in Team settings \u2192 Integrations \u2192 Coding agents; on your computer ${local}; then retry.`
24440
+ };
24441
+ }
24410
24442
  function embeddedJson(text2) {
24411
24443
  const start = text2.indexOf("{");
24412
24444
  if (start === -1) return void 0;
@@ -24565,7 +24597,8 @@ function retryOwnerFor(classified, harnessOwnsRetry, safe) {
24565
24597
  if (!safe) return "none";
24566
24598
  return classified.errorKind === "resume_failed" || classified.errorKind === "history_rejected" ? "alan_resume" : "user_confirmed_fresh_run";
24567
24599
  }
24568
- function createCliProblem(classified, options) {
24600
+ function createCliProblem(observed, options) {
24601
+ const classified = withAgentSignIn(observed, options.harness);
24569
24602
  const automatic = classified.recoveryClass === "auto_recovering";
24570
24603
  const harnessOwnsRetry = options.finality === "observation" && automatic;
24571
24604
  const safe = options.outcomeCertainty === "no_effect" || harnessOwnsRetry;
@@ -24595,9 +24628,9 @@ function createCliProblem(classified, options) {
24595
24628
  ...classified.resetsAt ? { resetsAt: classified.resetsAt } : {}
24596
24629
  });
24597
24630
  }
24598
- var import_crypto2, ERROR_SPECS, AGENT_ERROR_KINDS, STATUS_PREFIX, TEXT_RULES, CODEX_TIMEOUT_MESSAGE, CODEX_EXPIRED_MESSAGE, EPOCH_RESET, WORDED_RESET, COMMAND_NOT_FOUND, CODE_RULES, TEXT_REFINES, STATUS_LEAD, CLI_PROBLEM_CODE_BY_ERROR_KIND, KEY_REJECTION_KINDS;
24599
- var init_chunk_R6R6ORR2 = __esm({
24600
- "../agent-core/dist/chunk-R6R6ORR2.js"() {
24631
+ var import_crypto2, ERROR_SPECS, AGENT_ERROR_KINDS, AGENT_SIGN_IN_BY_HARNESS, STATUS_PREFIX, TEXT_RULES, CODEX_TIMEOUT_MESSAGE, CODEX_EXPIRED_MESSAGE, EPOCH_RESET, WORDED_RESET, COMMAND_NOT_FOUND, CODE_RULES, TEXT_REFINES, STATUS_LEAD, CLI_PROBLEM_CODE_BY_ERROR_KIND, KEY_REJECTION_KINDS;
24632
+ var init_chunk_54ZRJOQP = __esm({
24633
+ "../agent-core/dist/chunk-54ZRJOQP.js"() {
24601
24634
  "use strict";
24602
24635
  init_chunk_YXWJW7I5();
24603
24636
  import_crypto2 = require("crypto");
@@ -24616,7 +24649,7 @@ var init_chunk_R6R6ORR2 = __esm({
24616
24649
  recoveryClass: "user_fixable"
24617
24650
  },
24618
24651
  not_logged_in: {
24619
- message: "Not logged in to the agent CLI on this computer. Sign in to it there (for Claude Code, run `claude` then `/login`), then retry.",
24652
+ message: "The agent CLI isn't signed in: for cloud runs connect it in Team settings \u2192 Integrations \u2192 Coding agents; on your computer sign in to the CLI; then retry.",
24620
24653
  recoveryClass: "user_fixable"
24621
24654
  },
24622
24655
  not_authenticated: {
@@ -24707,6 +24740,19 @@ var init_chunk_R6R6ORR2 = __esm({
24707
24740
  AGENT_ERROR_KINDS = Object.keys(ERROR_SPECS).filter(
24708
24741
  (key) => key in ERROR_SPECS
24709
24742
  );
24743
+ AGENT_SIGN_IN_BY_HARNESS = /* @__PURE__ */ new Map([
24744
+ ["claude_cli", { name: "Claude Code", localSignIn: "run `claude` then `/login`" }],
24745
+ ["codex_app_server", { name: "Codex", localSignIn: "run `codex login`" }],
24746
+ ["codex_exec", { name: "Codex", localSignIn: "run `codex login`" }],
24747
+ ["cursor_agent_cli", { name: "Cursor Agent", localSignIn: "run `cursor-agent login`" }],
24748
+ ["copilot_cli", { name: "GitHub Copilot CLI", localSignIn: "run `copilot` then `/login`" }],
24749
+ ["opencode_serve", { name: "OpenCode", localSignIn: "run `opencode auth login`" }],
24750
+ ["droid_cli", { name: "Droid" }],
24751
+ ["antigravity_cli", { name: "Antigravity" }],
24752
+ ["grok_cli", { name: "Grok CLI" }],
24753
+ ["kimi_cli", { name: "Kimi CLI" }],
24754
+ ["command_code_cli", { name: "Command Code" }]
24755
+ ]);
24710
24756
  STATUS_PREFIX = /\b(?:api error|status|http)[:\s]+(\d{3})\b/i;
24711
24757
  TEXT_RULES = [
24712
24758
  { kind: "auth_expired", pattern: /\bcodex cli connection expired\b|\breconnect openai codex\b/ },
@@ -24847,7 +24893,7 @@ var init_chunk_R6R6ORR2 = __esm({
24847
24893
  }
24848
24894
  });
24849
24895
 
24850
- // ../agent-core/dist/chunk-W3QH4J4A.js
24896
+ // ../agent-core/dist/chunk-YPYC4VBL.js
24851
24897
  function collectStrings(value2, out) {
24852
24898
  if (typeof value2 === "string") out.push(value2);
24853
24899
  else if (Array.isArray(value2)) for (const item of value2) collectStrings(item, out);
@@ -25217,11 +25263,11 @@ function silentStartError(name, timeoutMs) {
25217
25263
  };
25218
25264
  }
25219
25265
  var import_crypto3, import_fs4, import_path3, 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;
25220
- var init_chunk_W3QH4J4A = __esm({
25221
- "../agent-core/dist/chunk-W3QH4J4A.js"() {
25266
+ var init_chunk_YPYC4VBL = __esm({
25267
+ "../agent-core/dist/chunk-YPYC4VBL.js"() {
25222
25268
  "use strict";
25223
25269
  init_chunk_UGRKZTAD();
25224
- init_chunk_R6R6ORR2();
25270
+ init_chunk_54ZRJOQP();
25225
25271
  init_chunk_J4T6L5LX();
25226
25272
  init_chunk_YXWJW7I5();
25227
25273
  import_crypto3 = require("crypto");
@@ -25684,7 +25730,7 @@ var init_chunk_J2KTV5FP = __esm({
25684
25730
  }
25685
25731
  });
25686
25732
 
25687
- // ../agent-core/dist/chunk-6WN2R725.js
25733
+ // ../agent-core/dist/chunk-ITTV3UIM.js
25688
25734
  function truncate(value2, limit) {
25689
25735
  const normalized2 = Array.from(value2, (character) => {
25690
25736
  const code = character.charCodeAt(0);
@@ -25937,9 +25983,41 @@ function teamOverlay(spec) {
25937
25983
  function present(values) {
25938
25984
  return values.filter((value2) => Boolean(value2?.length));
25939
25985
  }
25986
+ function cloudExecutionSection(spec) {
25987
+ if (!spec.sandboxId && !spec.cloudEnvironmentId) return void 0;
25988
+ const lines2 = ["## Cloud execution", "You are executing inside an Alan cloud sandbox."];
25989
+ if (spec.sandboxId) lines2.push(`Sandbox ID: ${spec.sandboxId}.`);
25990
+ if (spec.cloudEnvironmentId) lines2.push(`Cloud environment ID: ${spec.cloudEnvironmentId}.`);
25991
+ lines2.push(
25992
+ "Run setup, development and validation in this sandbox. The execution location is separate from the deployment of the application you are testing; verify that application's origin before acting."
25993
+ );
25994
+ if (!isReadOnlyMode(spec.mode) && !isReadOnlyAgent(spec.agentId)) {
25995
+ lines2.push(
25996
+ "Own the authorized work end to end: inspect context, make reasonable assumptions, implement, test, review and create or update the pull request for code changes when the repository workflow calls for one. Do not stop at a plan or ask for routine implementation choices or permission already granted. Ask only for a missing secret, an essential decision you cannot derive, or an action requiring explicit approval. Respect the user's scope, repository rules and tool authorization; report a blocked capability and continue independent work."
25997
+ );
25998
+ }
25999
+ const skills = spec.promptContext?.availableSkills ?? [];
26000
+ lines2.push(
26001
+ "## Installed skills",
26002
+ "Use a matching installed skill when it helps the request. Read its SKILL.md before acting; the index is discovery metadata, not instructions. Also follow repository instructions and project skills."
26003
+ );
26004
+ if (skills.length === 0) {
26005
+ lines2.push(
26006
+ skills.length === 0 && spec.promptContext?.availableSkills !== void 0 ? "No verified installed packages were found. Do not assume a named skill is available." : "No installed skill inventory was supplied. Inspect the provider's skill index; do not assume a named package is installed."
26007
+ );
26008
+ } else {
26009
+ for (const skill of skills) {
26010
+ lines2.push(
26011
+ `- ${JSON.stringify(skill.name)}: ${JSON.stringify(skill.description)} \u2014 ${JSON.stringify(`${skill.packageDirectory}/SKILL.md`)}`
26012
+ );
26013
+ }
26014
+ }
26015
+ return lines2.join("\n");
26016
+ }
25940
26017
  function promptParts(input2) {
25941
26018
  const { spec } = input2;
25942
26019
  const overlay = teamOverlay(spec);
26020
+ const cloud = cloudExecutionSection(spec);
25943
26021
  const workspace = input2.workspacePath ? `You are working inside: ${input2.workspacePath}
25944
26022
  Prefer relative paths and keep your work scoped to this project.` : void 0;
25945
26023
  return {
@@ -25948,6 +26026,7 @@ Prefer relative paths and keep your work scoped to this project.` : void 0;
25948
26026
  spec.agentPrompt?.trim() || getAlanAgentPrompt(spec.agentId),
25949
26027
  getAlanModePrompt(agentModeOf(spec.mode)),
25950
26028
  workspace,
26029
+ cloud,
25951
26030
  taskLifecycleSection(spec),
25952
26031
  overlay,
25953
26032
  ...contextSections(spec),
@@ -25955,6 +26034,7 @@ Prefer relative paths and keep your work scoped to this project.` : void 0;
25955
26034
  ]),
25956
26035
  append: present([
25957
26036
  ALAN_PLATFORM_TOOL_ROUTING_PROMPT,
26037
+ cloud,
25958
26038
  spec.contextGraphEnabled === true ? ALAN_CONTEXT_SEARCH_PROMPT : void 0,
25959
26039
  overlay
25960
26040
  ])
@@ -26011,8 +26091,8 @@ ${body}` : body;
26011
26091
  return spec.mode === "plan" ? planModePrefix(prefixed) : prefixed;
26012
26092
  }
26013
26093
  var MAX_PARSED_ATTACHMENTS, MAX_PARSED_ATTACHMENT_CHARS, MAX_METADATA_CHARS, UNAVAILABLE, READ_ONLY_MODES, AGENT_MODES;
26014
- var init_chunk_6WN2R725 = __esm({
26015
- "../agent-core/dist/chunk-6WN2R725.js"() {
26094
+ var init_chunk_ITTV3UIM = __esm({
26095
+ "../agent-core/dist/chunk-ITTV3UIM.js"() {
26016
26096
  "use strict";
26017
26097
  init_agent2();
26018
26098
  MAX_PARSED_ATTACHMENTS = 3;
@@ -27279,12 +27359,12 @@ var init_claude = __esm({
27279
27359
  "../agent-core/dist/providers/claude.js"() {
27280
27360
  "use strict";
27281
27361
  init_chunk_DALFHI4B();
27282
- init_chunk_W3QH4J4A();
27362
+ init_chunk_YPYC4VBL();
27283
27363
  init_chunk_UGRKZTAD();
27284
- init_chunk_R6R6ORR2();
27364
+ init_chunk_54ZRJOQP();
27285
27365
  init_chunk_J2KTV5FP();
27286
27366
  init_chunk_J4T6L5LX();
27287
- init_chunk_6WN2R725();
27367
+ init_chunk_ITTV3UIM();
27288
27368
  init_chunk_YXWJW7I5();
27289
27369
  init_effort();
27290
27370
  import_crypto6 = require("crypto");
@@ -29070,11 +29150,12 @@ async function withDeadline(work, clock, ms, what) {
29070
29150
  `codex app-server did not answer ${what} within ${ms} ms`
29071
29151
  );
29072
29152
  }
29073
- async function handshake(session, log) {
29153
+ async function handshake(session, spec, log) {
29154
+ const experimentalApi = spec.externalAuth !== void 0;
29074
29155
  const init = asRecord(
29075
29156
  await session.rpc.request("initialize", {
29076
29157
  clientInfo: CLIENT_INFO,
29077
- capabilities: { experimentalApi: false, requestAttestation: false }
29158
+ capabilities: { experimentalApi, requestAttestation: false }
29078
29159
  })
29079
29160
  );
29080
29161
  const userAgent = asString(init?.userAgent);
@@ -29167,7 +29248,7 @@ function createCodexDriver(options = {}) {
29167
29248
  await started;
29168
29249
  try {
29169
29250
  const opening = (async () => {
29170
- await handshake(session, resolved.log);
29251
+ await handshake(session, spec, resolved.log);
29171
29252
  await preflight(session, spec);
29172
29253
  return openThread(session, spec, resolved.log);
29173
29254
  })();
@@ -30055,12 +30136,12 @@ var init_codex = __esm({
30055
30136
  "../agent-core/dist/providers/codex.js"() {
30056
30137
  "use strict";
30057
30138
  init_chunk_DALFHI4B();
30058
- init_chunk_W3QH4J4A();
30139
+ init_chunk_YPYC4VBL();
30059
30140
  init_chunk_UGRKZTAD();
30060
- init_chunk_R6R6ORR2();
30141
+ init_chunk_54ZRJOQP();
30061
30142
  init_chunk_J2KTV5FP();
30062
30143
  init_chunk_J4T6L5LX();
30063
- init_chunk_6WN2R725();
30144
+ init_chunk_ITTV3UIM();
30064
30145
  init_chunk_YXWJW7I5();
30065
30146
  import_fs6 = require("fs");
30066
30147
  import_path6 = require("path");
@@ -41325,9 +41406,9 @@ var require_tar_stream = __commonJS({
41325
41406
  var init_dist = __esm({
41326
41407
  "../agent-core/dist/index.js"() {
41327
41408
  "use strict";
41328
- init_chunk_W3QH4J4A();
41409
+ init_chunk_YPYC4VBL();
41329
41410
  init_chunk_UGRKZTAD();
41330
- init_chunk_R6R6ORR2();
41411
+ init_chunk_54ZRJOQP();
41331
41412
  init_chunk_J4T6L5LX();
41332
41413
  init_chunk_YXWJW7I5();
41333
41414
  }
@@ -42072,12 +42153,12 @@ var import_promises48, import_path9, import_crypto12, import_promises49, CURSOR_
42072
42153
  var init_acp3 = __esm({
42073
42154
  "../agent-core/dist/providers/acp.js"() {
42074
42155
  "use strict";
42075
- init_chunk_W3QH4J4A();
42156
+ init_chunk_YPYC4VBL();
42076
42157
  init_chunk_UGRKZTAD();
42077
- init_chunk_R6R6ORR2();
42158
+ init_chunk_54ZRJOQP();
42078
42159
  init_chunk_J2KTV5FP();
42079
42160
  init_chunk_J4T6L5LX();
42080
- init_chunk_6WN2R725();
42161
+ init_chunk_ITTV3UIM();
42081
42162
  init_chunk_YXWJW7I5();
42082
42163
  import_promises48 = require("fs/promises");
42083
42164
  import_path9 = require("path");
@@ -42889,7 +42970,7 @@ var init_acp3 = __esm({
42889
42970
  var init_classify = __esm({
42890
42971
  "../agent-core/dist/classify.js"() {
42891
42972
  "use strict";
42892
- init_chunk_R6R6ORR2();
42973
+ init_chunk_54ZRJOQP();
42893
42974
  init_chunk_YXWJW7I5();
42894
42975
  }
42895
42976
  });
@@ -42919,38 +43000,31 @@ function toTurnResult(harness, outcome2, spec, providerSessionId, clock, apiKeyS
42919
43000
  return { outcome: "aborted", ...session };
42920
43001
  case "interrupted":
42921
43002
  return { outcome: "interrupted", message: outcome2.reason, ...session };
42922
- case "failed":
42923
- return {
42924
- outcome: "failed",
42925
- message: outcome2.error.message,
42926
- problem: createCliProblem(outcome2.error, {
42927
- harness,
42928
- phase: "stream",
42929
- finality: "terminal",
42930
- outcomeCertainty: "effect_unknown",
42931
- occurredAt: new Date(clock.now()).toISOString(),
42932
- scope: { runId: spec.runId, conversationId: spec.conversationId },
42933
- apiKeySupplied
42934
- }),
42935
- ...session
42936
- };
43003
+ case "failed": {
43004
+ const problem = createCliProblem(outcome2.error, {
43005
+ harness,
43006
+ phase: "stream",
43007
+ finality: "terminal",
43008
+ outcomeCertainty: "effect_unknown",
43009
+ occurredAt: new Date(clock.now()).toISOString(),
43010
+ scope: { runId: spec.runId, conversationId: spec.conversationId },
43011
+ apiKeySupplied
43012
+ });
43013
+ return { outcome: "failed", message: problem.detail, problem, ...session };
43014
+ }
42937
43015
  }
42938
43016
  }
42939
43017
  function refusalResult(harness, refusal2, spec, clock, apiKeySupplied) {
42940
- const error61 = refusal2.classified ?? specForErrorKind("not_authenticated");
42941
- return {
42942
- outcome: "failed",
42943
- message: error61.message,
42944
- problem: createCliProblem(error61, {
42945
- harness,
42946
- phase: "preflight",
42947
- finality: "terminal",
42948
- outcomeCertainty: "no_effect",
42949
- occurredAt: new Date(clock.now()).toISOString(),
42950
- scope: { runId: spec.runId, conversationId: spec.conversationId },
42951
- apiKeySupplied
42952
- })
42953
- };
43018
+ const problem = createCliProblem(refusal2.classified ?? specForErrorKind("not_authenticated"), {
43019
+ harness,
43020
+ phase: "preflight",
43021
+ finality: "terminal",
43022
+ outcomeCertainty: "no_effect",
43023
+ occurredAt: new Date(clock.now()).toISOString(),
43024
+ scope: { runId: spec.runId, conversationId: spec.conversationId },
43025
+ apiKeySupplied
43026
+ });
43027
+ return { outcome: "failed", message: problem.detail, problem };
42954
43028
  }
42955
43029
  function createPersistentDriver(provider4, options) {
42956
43030
  const { log, clock } = options;
@@ -43783,12 +43857,12 @@ var import_http10, import_crypto13, import_promises50, import_path10, import_pat
43783
43857
  var init_opencode = __esm({
43784
43858
  "../agent-core/dist/providers/opencode.js"() {
43785
43859
  "use strict";
43786
- init_chunk_W3QH4J4A();
43860
+ init_chunk_YPYC4VBL();
43787
43861
  init_chunk_UGRKZTAD();
43788
- init_chunk_R6R6ORR2();
43862
+ init_chunk_54ZRJOQP();
43789
43863
  init_chunk_J2KTV5FP();
43790
43864
  init_chunk_J4T6L5LX();
43791
- init_chunk_6WN2R725();
43865
+ init_chunk_ITTV3UIM();
43792
43866
  init_chunk_YXWJW7I5();
43793
43867
  import_http10 = require("http");
43794
43868
  init_runtime_v2();
@@ -45059,21 +45133,63 @@ var codex_exports = {};
45059
45133
  __export(codex_exports, {
45060
45134
  createCodexHolderDriver: () => createCodexHolderDriver
45061
45135
  });
45136
+ function sha2563(value2) {
45137
+ return (0, import_node_crypto25.createHash)("sha256").update(value2).digest("hex");
45138
+ }
45139
+ function createCodexLogin(broker) {
45140
+ const state = {};
45141
+ return {
45142
+ forTurn: (runId, tokens2) => {
45143
+ state.runId = runId;
45144
+ state.latest = tokens2;
45145
+ },
45146
+ externalAuth: {
45147
+ current: async () => {
45148
+ if (state.latest === void 0) throw new Error("No Codex sign-in for this turn");
45149
+ state.given = state.latest;
45150
+ return state.given;
45151
+ },
45152
+ refresh: async () => {
45153
+ if (broker === void 0 || state.runId === void 0) {
45154
+ throw new Error("Codex sign-in cannot be refreshed on this machine");
45155
+ }
45156
+ const rejected2 = state.given === void 0 ? void 0 : sha2563(state.given.accessToken);
45157
+ const fresh = await broker.refresh(state.runId, rejected2);
45158
+ state.latest = fresh;
45159
+ state.given = fresh;
45160
+ return fresh;
45161
+ }
45162
+ }
45163
+ };
45164
+ }
45165
+ function withLogin(planned, externalAuth, accountId) {
45166
+ return {
45167
+ ...planned,
45168
+ spec: { ...planned.spec, externalAuth },
45169
+ key: JSON.stringify([planned.key, accountId])
45170
+ };
45171
+ }
45062
45172
  function createCodexHolderDriver(options) {
45063
45173
  const clock = options.clock ?? systemClock2;
45064
45174
  const sessions = options.sessions ?? createCodexDriver({ ...options.timings, clock, log: options.log });
45175
+ const login = createCodexLogin(options.codexCredentials);
45065
45176
  return createPersistentDriver(
45066
45177
  {
45067
45178
  harness: "codex_app_server",
45068
45179
  displayName: "Codex app-server",
45069
- plan: (spec, inputs, resumeId, managedMcp) => planCodexSession(spec, {
45070
- command: options.command ?? "codex",
45071
- cwd: spec.projectPath ?? options.defaultCwd,
45072
- cliEnv: options.cliEnvironment,
45073
- providerEnv: inputs.providerEnv,
45074
- ...managedMcp === void 0 ? {} : { managedMcp },
45075
- ...resumeId === void 0 ? {} : { resumeThreadId: resumeId }
45076
- }),
45180
+ plan: (spec, inputs, resumeId, managedMcp) => {
45181
+ const planned = planCodexSession(spec, {
45182
+ command: options.command ?? "codex",
45183
+ cwd: spec.projectPath ?? options.defaultCwd,
45184
+ cliEnv: options.cliEnvironment,
45185
+ providerEnv: inputs.providerEnv,
45186
+ ...managedMcp === void 0 ? {} : { managedMcp },
45187
+ ...resumeId === void 0 ? {} : { resumeThreadId: resumeId }
45188
+ });
45189
+ if (inputs.codex === void 0) return planned;
45190
+ login.forTurn(spec.runId, inputs.codex);
45191
+ return withLogin(planned, login.externalAuth, inputs.codex.chatgptAccountId);
45192
+ },
45077
45193
  canResume: () => true,
45078
45194
  open: async (spec) => {
45079
45195
  const session = await sessions.open(spec);
@@ -45093,9 +45209,11 @@ function createCodexHolderDriver(options) {
45093
45209
  }
45094
45210
  );
45095
45211
  }
45212
+ var import_node_crypto25;
45096
45213
  var init_codex2 = __esm({
45097
45214
  "src/holder/drivers/codex.ts"() {
45098
45215
  "use strict";
45216
+ import_node_crypto25 = require("crypto");
45099
45217
  init_dist();
45100
45218
  init_codex();
45101
45219
  init_persistent();
@@ -45547,12 +45665,12 @@ var import_crypto15, import_promises51, FACTORY_API_VERSION, FACTORY_PROTOCOL_VE
45547
45665
  var init_droid = __esm({
45548
45666
  "../agent-core/dist/providers/droid.js"() {
45549
45667
  "use strict";
45550
- init_chunk_W3QH4J4A();
45668
+ init_chunk_YPYC4VBL();
45551
45669
  init_chunk_UGRKZTAD();
45552
- init_chunk_R6R6ORR2();
45670
+ init_chunk_54ZRJOQP();
45553
45671
  init_chunk_J2KTV5FP();
45554
45672
  init_chunk_J4T6L5LX();
45555
- init_chunk_6WN2R725();
45673
+ init_chunk_ITTV3UIM();
45556
45674
  init_chunk_YXWJW7I5();
45557
45675
  init_runtime_v2();
45558
45676
  import_crypto15 = require("crypto");
@@ -46020,6 +46138,35 @@ var init_opencode2 = __esm({
46020
46138
  });
46021
46139
 
46022
46140
  // ../agent-core/dist/providers/antigravity.js
46141
+ function settingsPath(env) {
46142
+ const home = env.HOME?.trim() || env.USERPROFILE?.trim();
46143
+ return home ? (0, import_path12.resolve)(home, ".gemini", "antigravity-cli", "settings.json") : void 0;
46144
+ }
46145
+ async function readSettings2(path4) {
46146
+ let raw;
46147
+ try {
46148
+ raw = (await (0, import_promises52.readFile)(path4, "utf8")).trim();
46149
+ } catch {
46150
+ return {};
46151
+ }
46152
+ if (!raw) return {};
46153
+ try {
46154
+ const parsed = JSON.parse(raw);
46155
+ return isRecord(parsed) ? parsed : "malformed";
46156
+ } catch {
46157
+ return "malformed";
46158
+ }
46159
+ }
46160
+ async function selectAntigravityApiKeyMode(env) {
46161
+ const path4 = settingsPath(env);
46162
+ if (!env.GEMINI_API_KEY?.trim() || path4 === void 0) return "no_key";
46163
+ const settings2 = await readSettings2(path4);
46164
+ if (settings2 === "malformed") return "malformed";
46165
+ if (settings2.modelProvider === "gemini") return "already_selected";
46166
+ await (0, import_promises52.mkdir)((0, import_path12.dirname)(path4), { recursive: true });
46167
+ await (0, import_promises52.writeFile)(path4, JSON.stringify({ ...settings2, modelProvider: "gemini" }), { mode: 384 });
46168
+ return "selected";
46169
+ }
46023
46170
  function readAntigravityCapabilities(version2, help) {
46024
46171
  const text2 = help.toLowerCase().replace(/\s+/g, " ");
46025
46172
  const structured = /\bstream-json\b/.test(text2) || /\bjsonl\b/.test(text2) || /\bjson\b/.test(text2);
@@ -46060,21 +46207,21 @@ function antigravityArgs(input2, capabilities, prompt) {
46060
46207
  ];
46061
46208
  }
46062
46209
  function workspaceRoot(cwd) {
46063
- for (let current = (0, import_path12.resolve)(cwd); ; current = (0, import_path12.dirname)(current)) {
46064
- if ((0, import_fs8.existsSync)((0, import_path12.join)(current, ".git"))) return current;
46065
- if ((0, import_path12.dirname)(current) === current) return (0, import_path12.resolve)(cwd);
46210
+ for (let current = (0, import_path13.resolve)(cwd); ; current = (0, import_path13.dirname)(current)) {
46211
+ if ((0, import_fs8.existsSync)((0, import_path13.join)(current, ".git"))) return current;
46212
+ if ((0, import_path13.dirname)(current) === current) return (0, import_path13.resolve)(cwd);
46066
46213
  }
46067
46214
  }
46068
46215
  function instructionPaths(cwd) {
46069
46216
  const root = workspaceRoot(cwd);
46070
46217
  const paths = [];
46071
- for (let current = (0, import_path12.resolve)(cwd); ; current = (0, import_path12.dirname)(current)) {
46072
- const path4 = (0, import_path12.join)(current, INSTRUCTIONS_FILE);
46218
+ for (let current = (0, import_path13.resolve)(cwd); ; current = (0, import_path13.dirname)(current)) {
46219
+ const path4 = (0, import_path13.join)(current, INSTRUCTIONS_FILE);
46073
46220
  try {
46074
46221
  if ((0, import_fs8.existsSync)(path4) && (0, import_fs8.statSync)(path4).isFile()) paths.unshift(path4);
46075
46222
  } catch {
46076
46223
  }
46077
- if (current === root || (0, import_path12.dirname)(current) === current) return paths;
46224
+ if (current === root || (0, import_path13.dirname)(current) === current) return paths;
46078
46225
  }
46079
46226
  }
46080
46227
  function antigravityWorkspaceInstructions(cwd, maxChars = MAX_INSTRUCTION_CHARS) {
@@ -46328,7 +46475,7 @@ function normalizeAntigravityFrame(event) {
46328
46475
  }
46329
46476
  function antigravityBrainRoot(env) {
46330
46477
  const home = env.HOME?.trim() || env.USERPROFILE?.trim();
46331
- return home ? (0, import_path13.resolve)(home, ".gemini", "antigravity-cli", "brain") : void 0;
46478
+ return home ? (0, import_path14.resolve)(home, ".gemini", "antigravity-cli", "brain") : void 0;
46332
46479
  }
46333
46480
  function parseEntry(text2) {
46334
46481
  try {
@@ -46366,14 +46513,14 @@ function childTranscriptPath(root, frame) {
46366
46513
  try {
46367
46514
  const url3 = new URL(logUri);
46368
46515
  if (url3.protocol !== "file:") return void 0;
46369
- path4 = (0, import_path13.resolve)((0, import_url3.fileURLToPath)(url3));
46516
+ path4 = (0, import_path14.resolve)((0, import_url3.fileURLToPath)(url3));
46370
46517
  } catch {
46371
46518
  return void 0;
46372
46519
  }
46373
- const fromRoot = (0, import_path13.relative)(root, path4);
46374
- if (!fromRoot || (0, import_path13.isAbsolute)(fromRoot) || fromRoot.split(import_path13.sep).includes("..")) return void 0;
46520
+ const fromRoot = (0, import_path14.relative)(root, path4);
46521
+ if (!fromRoot || (0, import_path14.isAbsolute)(fromRoot) || fromRoot.split(import_path14.sep).includes("..")) return void 0;
46375
46522
  const expected = [conversationId, ...LOG_DIRS, TRANSCRIPT_FILE];
46376
- const segments = fromRoot.split(import_path13.sep);
46523
+ const segments = fromRoot.split(import_path14.sep);
46377
46524
  const matches = segments.length === expected.length && segments.every((segment, index) => segment === expected[index]);
46378
46525
  return matches ? path4 : void 0;
46379
46526
  }
@@ -46551,11 +46698,15 @@ ${output2.stderr}`).join("\n")
46551
46698
  name: "antigravity_cli",
46552
46699
  capabilities,
46553
46700
  open: async (spec) => {
46554
- const found = await capabilities(spec.command, spec.env);
46701
+ const [found, apiKeyMode] = await Promise.all([
46702
+ capabilities(spec.command, spec.env),
46703
+ selectAntigravityApiKeyMode(spec.env).catch(() => "unwritable")
46704
+ ]);
46555
46705
  session.log.info("antigravity.opened", {
46556
46706
  version: found.version,
46557
46707
  structured: found.structuredPrint,
46558
- resumeId: spec.resumeSessionId
46708
+ resumeId: spec.resumeSessionId,
46709
+ apiKeyMode
46559
46710
  });
46560
46711
  return new AntigravitySession(
46561
46712
  provider2(spec, found, options.platform ?? process.platform),
@@ -46612,21 +46763,24 @@ function antigravityTurnInput(run2, context) {
46612
46763
  });
46613
46764
  return { turnId: run2.runId, text: appendImagePathReferences(text2, images) };
46614
46765
  }
46615
- var import_fs8, import_path12, import_path13, import_url3, import_crypto16, NO_ANTIGRAVITY_CAPABILITIES, INSTRUCTIONS_FILE, MAX_INSTRUCTION_CHARS, SHORTENED_NOTE, DIFF_BLOCK_START, DIFF_BLOCK_END, HUNK_HEADER, TRANSCRIPT_FILE, FULL_TRANSCRIPT_FILE, LOG_DIRS, TOOL_RESULT_TYPES, BrainTranscript, AntigravityTranscripts, ANTIGRAVITY_GRAMMAR_NAME, AntigravityGrammar, ignored, HANDLERS, SUCCESSFUL_STATUSES, SESSION_START_TYPES, RESULT_TYPES, SUBAGENT_START_TYPES, RESUME_FORKED, EXITED_WITHOUT_RESULT, AntigravityTurn, DEFAULTS6, AntigravitySession, WINDOWS_LINE_MARGIN;
46766
+ var import_promises52, import_path12, import_fs8, import_path13, import_path14, import_url3, import_crypto16, NO_ANTIGRAVITY_CAPABILITIES, INSTRUCTIONS_FILE, MAX_INSTRUCTION_CHARS, SHORTENED_NOTE, DIFF_BLOCK_START, DIFF_BLOCK_END, HUNK_HEADER, TRANSCRIPT_FILE, FULL_TRANSCRIPT_FILE, LOG_DIRS, TOOL_RESULT_TYPES, BrainTranscript, AntigravityTranscripts, ANTIGRAVITY_GRAMMAR_NAME, AntigravityGrammar, ignored, HANDLERS, SUCCESSFUL_STATUSES, SESSION_START_TYPES, RESULT_TYPES, SUBAGENT_START_TYPES, RESUME_FORKED, EXITED_WITHOUT_RESULT, AntigravityTurn, DEFAULTS6, AntigravitySession, WINDOWS_LINE_MARGIN;
46616
46767
  var init_antigravity = __esm({
46617
46768
  "../agent-core/dist/providers/antigravity.js"() {
46618
46769
  "use strict";
46619
46770
  init_chunk_DALFHI4B();
46620
- init_chunk_W3QH4J4A();
46771
+ init_chunk_YPYC4VBL();
46621
46772
  init_chunk_UGRKZTAD();
46622
- init_chunk_R6R6ORR2();
46773
+ init_chunk_54ZRJOQP();
46623
46774
  init_chunk_J4T6L5LX();
46624
- init_chunk_6WN2R725();
46775
+ init_chunk_ITTV3UIM();
46625
46776
  init_chunk_YXWJW7I5();
46626
- import_fs8 = require("fs");
46777
+ import_promises52 = require("fs/promises");
46627
46778
  import_path12 = require("path");
46628
- init_effort();
46779
+ init_type_guards();
46780
+ import_fs8 = require("fs");
46629
46781
  import_path13 = require("path");
46782
+ init_effort();
46783
+ import_path14 = require("path");
46630
46784
  import_url3 = require("url");
46631
46785
  import_crypto16 = require("crypto");
46632
46786
  init_agent2();
@@ -46666,7 +46820,7 @@ var init_antigravity = __esm({
46666
46820
  #full;
46667
46821
  constructor(path4) {
46668
46822
  this.#cursor = new TranscriptCursor(path4);
46669
- this.#fullPath = (0, import_path13.resolve)((0, import_path13.dirname)(path4), FULL_TRANSCRIPT_FILE);
46823
+ this.#fullPath = (0, import_path14.resolve)((0, import_path14.dirname)(path4), FULL_TRANSCRIPT_FILE);
46670
46824
  }
46671
46825
  skipExisting() {
46672
46826
  this.#cursor.read();
@@ -46714,7 +46868,7 @@ var init_antigravity = __esm({
46714
46868
  /** A conversation this turn did not resume was created by it, so it is read whole. */
46715
46869
  trackParent(conversationId) {
46716
46870
  if (this.#parent?.conversationId === conversationId) return;
46717
- const path4 = (0, import_path13.resolve)(this.#root, conversationId, ...LOG_DIRS, TRANSCRIPT_FILE);
46871
+ const path4 = (0, import_path14.resolve)(this.#root, conversationId, ...LOG_DIRS, TRANSCRIPT_FILE);
46718
46872
  this.#parent = { conversationId, transcript: new BrainTranscript(path4) };
46719
46873
  }
46720
46874
  /** A launcher keeps the first valid transcript it names; later frames change nothing. */
@@ -47119,8 +47273,8 @@ function parseConfig(raw) {
47119
47273
  }
47120
47274
  }
47121
47275
  async function writeCommandCodeProjectMcp(cwd, mcp) {
47122
- const path4 = (0, import_path14.join)(cwd, ".mcp.json");
47123
- const original = await (0, import_promises52.readFile)(path4, "utf8").catch(() => null);
47276
+ const path4 = (0, import_path15.join)(cwd, ".mcp.json");
47277
+ const original = await (0, import_promises53.readFile)(path4, "utf8").catch(() => null);
47124
47278
  const config2 = parseConfig(original);
47125
47279
  const next = {
47126
47280
  ...config2,
@@ -47137,12 +47291,12 @@ async function writeCommandCodeProjectMcp(cwd, mcp) {
47137
47291
  }
47138
47292
  }
47139
47293
  };
47140
- await (0, import_promises52.mkdir)(cwd, { recursive: true });
47141
- await (0, import_promises52.writeFile)(path4, `${JSON.stringify(next, null, 2)}
47294
+ await (0, import_promises53.mkdir)(cwd, { recursive: true });
47295
+ await (0, import_promises53.writeFile)(path4, `${JSON.stringify(next, null, 2)}
47142
47296
  `);
47143
47297
  return async () => {
47144
- if (original === null) await (0, import_promises52.rm)(path4, { force: true });
47145
- else await (0, import_promises52.writeFile)(path4, original);
47298
+ if (original === null) await (0, import_promises53.rm)(path4, { force: true });
47299
+ else await (0, import_promises53.writeFile)(path4, original);
47146
47300
  };
47147
47301
  }
47148
47302
  function commandCodeString(value2) {
@@ -47314,19 +47468,19 @@ function commandCodeTurnInput(run2, context) {
47314
47468
  });
47315
47469
  return { turnId: run2.runId, text: appendImagePathReferences(text2, images) };
47316
47470
  }
47317
- var import_promises52, import_path14, import_crypto17, COMMAND_CODE_GRAMMAR_NAME, SILENT3, CommandCodeGrammar, SHELL_TOOL, STOP_TOOLS, REPORTED_STATUS, SHELL_STATUS, SWEEP_INTERVAL_MS, CommandCodeBackgroundTasks, EXITED_WITHOUT_RESULT2, CommandCodeTurn, COMMAND_CODE_MAX_TURNS, DEFAULTS7, CommandCodeSession;
47471
+ var import_promises53, import_path15, import_crypto17, COMMAND_CODE_GRAMMAR_NAME, SILENT3, CommandCodeGrammar, SHELL_TOOL, STOP_TOOLS, REPORTED_STATUS, SHELL_STATUS, SWEEP_INTERVAL_MS, CommandCodeBackgroundTasks, EXITED_WITHOUT_RESULT2, CommandCodeTurn, COMMAND_CODE_MAX_TURNS, DEFAULTS7, CommandCodeSession;
47318
47472
  var init_command_code = __esm({
47319
47473
  "../agent-core/dist/providers/command-code.js"() {
47320
47474
  "use strict";
47321
- init_chunk_W3QH4J4A();
47475
+ init_chunk_YPYC4VBL();
47322
47476
  init_chunk_UGRKZTAD();
47323
- init_chunk_R6R6ORR2();
47477
+ init_chunk_54ZRJOQP();
47324
47478
  init_chunk_J2KTV5FP();
47325
47479
  init_chunk_J4T6L5LX();
47326
- init_chunk_6WN2R725();
47480
+ init_chunk_ITTV3UIM();
47327
47481
  init_chunk_YXWJW7I5();
47328
- import_promises52 = require("fs/promises");
47329
- import_path14 = require("path");
47482
+ import_promises53 = require("fs/promises");
47483
+ import_path15 = require("path");
47330
47484
  init_agent2();
47331
47485
  init_runtime_v2();
47332
47486
  init_acp();
@@ -51312,7 +51466,7 @@ var require_websocket = __commonJS({
51312
51466
  var http = require("http");
51313
51467
  var net = require("net");
51314
51468
  var tls = require("tls");
51315
- var { randomBytes: randomBytes6, createHash: createHash29 } = require("crypto");
51469
+ var { randomBytes: randomBytes6, createHash: createHash31 } = require("crypto");
51316
51470
  var { Duplex, Readable: Readable2 } = require("stream");
51317
51471
  var { URL: URL2 } = require("url");
51318
51472
  var PerMessageDeflate = require_permessage_deflate();
@@ -51969,7 +52123,7 @@ var require_websocket = __commonJS({
51969
52123
  abortHandshake(websocket, socket, "Invalid Upgrade header");
51970
52124
  return;
51971
52125
  }
51972
- const digest = createHash29("sha1").update(key + GUID).digest("base64");
52126
+ const digest = createHash31("sha1").update(key + GUID).digest("base64");
51973
52127
  if (res.headers["sec-websocket-accept"] !== digest) {
51974
52128
  abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
51975
52129
  return;
@@ -52336,7 +52490,7 @@ var require_websocket_server = __commonJS({
52336
52490
  var EventEmitter = require("events");
52337
52491
  var http = require("http");
52338
52492
  var { Duplex } = require("stream");
52339
- var { createHash: createHash29 } = require("crypto");
52493
+ var { createHash: createHash31 } = require("crypto");
52340
52494
  var extension = require_extension();
52341
52495
  var PerMessageDeflate = require_permessage_deflate();
52342
52496
  var subprotocol = require_subprotocol();
@@ -52633,7 +52787,7 @@ var require_websocket_server = __commonJS({
52633
52787
  );
52634
52788
  }
52635
52789
  if (this._state > RUNNING) return abortHandshake(socket, 503);
52636
- const digest = createHash29("sha1").update(key + GUID).digest("base64");
52790
+ const digest = createHash31("sha1").update(key + GUID).digest("base64");
52637
52791
  const headers = [
52638
52792
  "HTTP/1.1 101 Switching Protocols",
52639
52793
  "Upgrade: websocket",
@@ -52721,7 +52875,7 @@ var require_websocket_server = __commonJS({
52721
52875
  // package.json
52722
52876
  var package_default = {
52723
52877
  name: "@alan-ai-hq/agent-manager",
52724
- version: "0.1.135",
52878
+ version: "0.1.137",
52725
52879
  private: true,
52726
52880
  type: "module",
52727
52881
  description: "Alan machine runtime (alan-agent): identity, link, reconciler, session holders, run log, uploader, local API",
@@ -52770,8 +52924,8 @@ var package_default = {
52770
52924
  };
52771
52925
 
52772
52926
  // src/cli/commands/compat.ts
52773
- var import_node_crypto28 = require("crypto");
52774
- var import_promises63 = require("fs/promises");
52927
+ var import_node_crypto30 = require("crypto");
52928
+ var import_promises65 = require("fs/promises");
52775
52929
  init_runtime_v2();
52776
52930
  init_zod();
52777
52931
 
@@ -53577,6 +53731,13 @@ function createHolderApiClient({
53577
53731
  }
53578
53732
  return runProviderCredentialSchema.parse(jsonBody(response));
53579
53733
  },
53734
+ refreshCodexCredential: async (runId, body, signal) => {
53735
+ const response = await request2("POST", runCodexCredentialRefreshPath(runId), signal, body);
53736
+ if (!isOk(response)) {
53737
+ throw new RuntimeFault("io_failed", `Codex sign-in refresh failed: ${response.status}`);
53738
+ }
53739
+ return runCodexCredentialSchema.parse(jsonBody(response));
53740
+ },
53580
53741
  mintMcpCredential: async (conversationId, signal) => {
53581
53742
  const response = await request2("POST", MACHINE_PATHS.mcpCredential, signal, {
53582
53743
  conversationId
@@ -63093,16 +63254,33 @@ async function scanLocalSkills(home, context, cache2, mode = "incremental") {
63093
63254
  // src/capabilities/skills/store.ts
63094
63255
  var import_promises40 = require("fs/promises");
63095
63256
  var import_node_path42 = require("path");
63257
+
63258
+ // ../shared/dist/node/alan-skill-identity.js
63259
+ var import_node_crypto20 = require("crypto");
63260
+ var ALAN_SKILL_NAMESPACE = "ec71d99b-d207-4ca2-a9eb-3a7bed4a73fd";
63261
+ function uuidV5(name, namespace) {
63262
+ const bytes = (0, import_node_crypto20.createHash)("sha1").update(Buffer.from(namespace.replaceAll("-", ""), "hex")).update(name, "utf8").digest().subarray(0, 16);
63263
+ bytes[6] = bytes[6] & 15 | 80;
63264
+ bytes[8] = bytes[8] & 63 | 128;
63265
+ const hex3 = bytes.toString("hex");
63266
+ return `${hex3.slice(0, 8)}-${hex3.slice(8, 12)}-${hex3.slice(12, 16)}-${hex3.slice(16, 20)}-${hex3.slice(20)}`;
63267
+ }
63268
+ function alanSkillId(slug) {
63269
+ return uuidV5(`alan:${slug}`, ALAN_SKILL_NAMESPACE);
63270
+ }
63271
+
63272
+ // src/capabilities/skills/store.ts
63096
63273
  init_runtime_v2();
63097
63274
  init_zod();
63098
- function skillsLayout(stateDir) {
63275
+ function skillsLayout(stateDir, home) {
63099
63276
  const root = (0, import_node_path42.join)(stateDir, "skills");
63100
63277
  return {
63101
63278
  root,
63102
63279
  installedFile: (0, import_node_path42.join)(root, "installed.json"),
63103
63280
  localFile: (0, import_node_path42.join)(root, "local.json"),
63104
63281
  versionsDir: (0, import_node_path42.join)(root, "versions"),
63105
- tmpDir: (0, import_node_path42.join)(root, "tmp")
63282
+ tmpDir: (0, import_node_path42.join)(root, "tmp"),
63283
+ nativeDir: home === void 0 || home === "" ? null : (0, import_node_path42.join)(home, ".agents", "skills")
63106
63284
  };
63107
63285
  }
63108
63286
  function packageDirectory(layout, versionId) {
@@ -63169,6 +63347,17 @@ async function isIntact(layout, skill) {
63169
63347
  return false;
63170
63348
  }
63171
63349
  }
63350
+ async function resolveNativeBuiltIn(layout, invocation) {
63351
+ const slug = invocation.displayName;
63352
+ if (layout.nativeDir === null || invocation.skillId !== alanSkillId(slug)) return null;
63353
+ const directory = (0, import_node_path42.join)(layout.nativeDir, slug);
63354
+ try {
63355
+ await inspectSkillPackage(directory, { expectedName: slug });
63356
+ return { packageDirectory: directory };
63357
+ } catch {
63358
+ return null;
63359
+ }
63360
+ }
63172
63361
  async function resolveSkillInvocations(layout, invocations) {
63173
63362
  if (invocations.length === 0) return { kind: "resolved", skills: [] };
63174
63363
  const installed = await readInstalledSkills(layout);
@@ -63187,12 +63376,46 @@ async function resolveSkillInvocations(layout, invocations) {
63187
63376
  );
63188
63377
  if (skill !== void 0 && await isIntact(layout, skill)) {
63189
63378
  resolved.push({ packageDirectory: packageDirectory(layout, skill.versionId) });
63190
- } else {
63191
- missing.push(invocation.displayName);
63379
+ continue;
63192
63380
  }
63381
+ const native = await resolveNativeBuiltIn(layout, invocation);
63382
+ if (native === null) missing.push(invocation.displayName);
63383
+ else resolved.push(native);
63193
63384
  }
63194
63385
  return missing.length === 0 ? { kind: "resolved", skills: resolved } : { kind: "missing", names: missing };
63195
63386
  }
63387
+ async function availableSkillIndex(layout) {
63388
+ const found = /* @__PURE__ */ new Map();
63389
+ const candidates2 = [];
63390
+ for (const skill of await readInstalledSkills(layout)) {
63391
+ candidates2.push({
63392
+ directory: packageDirectory(layout, skill.versionId),
63393
+ contentHash: skill.contentHash
63394
+ });
63395
+ }
63396
+ if (layout.nativeDir !== null) {
63397
+ const entries = await (0, import_promises40.readdir)(layout.nativeDir, { withFileTypes: true }).catch(() => []);
63398
+ for (const entry of entries) {
63399
+ if (entry.isDirectory() || entry.isSymbolicLink())
63400
+ candidates2.push({ directory: (0, import_node_path42.join)(layout.nativeDir, entry.name) });
63401
+ }
63402
+ }
63403
+ for (const candidate of candidates2.slice(0, 2e3)) {
63404
+ const skill = await inspectIndexedSkill(candidate.directory, candidate.contentHash);
63405
+ if (skill !== null && !found.has(skill.name)) found.set(skill.name, skill);
63406
+ }
63407
+ return [...found.values()].sort((a, b) => a.name.localeCompare(b.name));
63408
+ }
63409
+ async function inspectIndexedSkill(directory, contentHash) {
63410
+ try {
63411
+ const inspected = await inspectSkillPackage(directory, { expectedName: null });
63412
+ if (contentHash && inspected.contentHash !== contentHash) return null;
63413
+ const { name, description } = inspected.metadata;
63414
+ return { name, description, packageDirectory: directory };
63415
+ } catch {
63416
+ return null;
63417
+ }
63418
+ }
63196
63419
 
63197
63420
  // src/capabilities/skills/local-preview.ts
63198
63421
  var MAX_INLINE_IMAGE_BYTES = 2 * 1024 * 1024;
@@ -63303,7 +63526,7 @@ var import_promises43 = require("fs/promises");
63303
63526
 
63304
63527
  // ../shared/dist/node/skill-bundle.js
63305
63528
  var import_node_buffer2 = require("buffer");
63306
- var import_node_crypto20 = require("crypto");
63529
+ var import_node_crypto21 = require("crypto");
63307
63530
  var import_promises42 = require("fs/promises");
63308
63531
  var import_node_path44 = require("path");
63309
63532
  var import_node_stream = require("stream");
@@ -63442,7 +63665,7 @@ function requireSafeArchivePath(value2) {
63442
63665
  return normalized2;
63443
63666
  }
63444
63667
  function sha2562(bytes) {
63445
- return `sha256:${(0, import_node_crypto20.createHash)("sha256").update(bytes).digest("hex")}`;
63668
+ return `sha256:${(0, import_node_crypto21.createHash)("sha256").update(bytes).digest("hex")}`;
63446
63669
  }
63447
63670
 
63448
63671
  // src/capabilities/skills/local-upload.ts
@@ -63486,14 +63709,14 @@ async function publishLocalSkill(options) {
63486
63709
  }
63487
63710
 
63488
63711
  // src/capabilities/skills/sync.ts
63489
- var import_node_crypto21 = require("crypto");
63712
+ var import_node_crypto22 = require("crypto");
63490
63713
  var import_promises44 = require("fs/promises");
63491
63714
  var import_node_path45 = require("path");
63492
63715
  var SKILL_PREPARE_WAIT_MS = 15e3;
63493
63716
  async function install(layout, source, skill, download, signal) {
63494
63717
  const bytes = await source.download(download.url, signal);
63495
63718
  await (0, import_promises44.mkdir)(layout.tmpDir, { recursive: true, mode: 448 });
63496
- const staging = (0, import_node_path45.join)(layout.tmpDir, (0, import_node_crypto21.randomUUID)());
63719
+ const staging = (0, import_node_path45.join)(layout.tmpDir, (0, import_node_crypto22.randomUUID)());
63497
63720
  await extractSkillBundle(Buffer.from(bytes), staging, {
63498
63721
  expectedArchiveHash: download.archiveHash,
63499
63722
  expectedContentHash: skill.contentHash
@@ -63533,11 +63756,28 @@ async function mapBounded(items, limit, work) {
63533
63756
  await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
63534
63757
  return results;
63535
63758
  }
63536
- async function applyDesired(layout, source, log, present2, response, signal) {
63759
+ function installedRecorder(layout, present2, onRecorded) {
63760
+ const ready = new Map(
63761
+ present2.map((skill) => [skill.skillId, skill])
63762
+ );
63763
+ let chain = Promise.resolve();
63764
+ return {
63765
+ record: (skill) => {
63766
+ ready.set(skill.skillId, skill);
63767
+ const snapshot2 = [...ready.values()];
63768
+ const write = chain.then(() => writeInstalledSkills(layout, snapshot2)).then(onRecorded);
63769
+ chain = write.catch(() => void 0);
63770
+ return write;
63771
+ },
63772
+ settled: () => chain
63773
+ };
63774
+ }
63775
+ async function applyDesired(layout, source, log, present2, response, onRecorded, signal) {
63537
63776
  const held = new Map(present2.map((skill) => [skill.skillId, skill]));
63538
63777
  const downloads = new Map(
63539
63778
  response.downloads.map((download) => [download.skillId, download])
63540
63779
  );
63780
+ const recorder = installedRecorder(layout, present2, onRecorded);
63541
63781
  const installOne = async (skill) => {
63542
63782
  const download = downloads.get(skill.skillId);
63543
63783
  if (download === void 0) {
@@ -63547,6 +63787,7 @@ async function applyDesired(layout, source, log, present2, response, signal) {
63547
63787
  }
63548
63788
  try {
63549
63789
  await install(layout, source, skill, download, signal);
63790
+ await recorder.record(skill);
63550
63791
  return "downloaded";
63551
63792
  } catch (error61) {
63552
63793
  log.warn("skills.install_failed", { skillId: skill.skillId, slug: skill.slug, error: error61 });
@@ -63557,6 +63798,7 @@ async function applyDesired(layout, source, log, present2, response, signal) {
63557
63798
  const installed = response.skills.filter((_, index) => outcomes[index] !== "failed");
63558
63799
  const failed = response.skills.filter((_, index) => outcomes[index] === "failed").map((skill) => skill.slug);
63559
63800
  const downloaded = outcomes.filter((outcome2) => outcome2 === "downloaded").length;
63801
+ await recorder.settled();
63560
63802
  await writeInstalledSkills(layout, installed);
63561
63803
  const removed = await sweep(layout, installed);
63562
63804
  return { installed: installed.length, downloaded, removed, failed };
@@ -63647,14 +63889,14 @@ async function settleLocal(layout, source, log, local, exchange3, response, sign
63647
63889
  const uploads = await uploadRequested(layout, source, log, local, response.uploads ?? [], signal);
63648
63890
  return serverLost || uploads > 0;
63649
63891
  }
63650
- async function syncOnce(layout, source, log, local, signal) {
63892
+ async function syncOnce(layout, source, log, local, onRecorded, signal) {
63651
63893
  let report2 = { installed: 0, downloaded: 0, removed: 0, failed: [] };
63652
63894
  if (local !== null) await loadContext(layout, local);
63653
63895
  for (let exchange3 = 0; exchange3 < MAX_EXCHANGES; exchange3 += 1) {
63654
63896
  const present2 = await intactSkills(layout);
63655
63897
  const pending = local === null ? null : localExchange(local);
63656
63898
  const response = await source.sync(syncRequest(present2, pending), signal);
63657
- report2 = await applyDesired(layout, source, log, present2, response, signal);
63899
+ report2 = await applyDesired(layout, source, log, present2, response, onRecorded, signal);
63658
63900
  if (local === null || pending === null) return report2;
63659
63901
  const again = await settleLocal(layout, source, log, local, pending, response, signal);
63660
63902
  if (!again) return report2;
@@ -63668,7 +63910,7 @@ function aborted2(signal) {
63668
63910
  });
63669
63911
  }
63670
63912
  function openMachineSkills(options) {
63671
- const layout = skillsLayout(options.stateDir);
63913
+ const layout = skillsLayout(options.stateDir, options.local?.home);
63672
63914
  const { source, log } = options;
63673
63915
  const local = options.local === void 0 ? null : {
63674
63916
  options: options.local,
@@ -63684,6 +63926,10 @@ function openMachineSkills(options) {
63684
63926
  const waitMs = options.waitMs ?? SKILL_PREPARE_WAIT_MS;
63685
63927
  const lifetime = new AbortController();
63686
63928
  const flight = {};
63929
+ const recordWatchers = /* @__PURE__ */ new Set();
63930
+ const recorded = () => {
63931
+ for (const watcher of recordWatchers) watcher();
63932
+ };
63687
63933
  const rescans = /* @__PURE__ */ new Set();
63688
63934
  const rescanOnce = async (state) => {
63689
63935
  try {
@@ -63700,7 +63946,7 @@ function openMachineSkills(options) {
63700
63946
  return task;
63701
63947
  };
63702
63948
  const run2 = () => {
63703
- const running = syncOnce(layout, source, log, local, lifetime.signal).then((report2) => {
63949
+ const running = syncOnce(layout, source, log, local, recorded, lifetime.signal).then((report2) => {
63704
63950
  log.info("skills.synced", { ...report2 });
63705
63951
  return report2;
63706
63952
  }).catch((error61) => {
@@ -63741,6 +63987,25 @@ function openMachineSkills(options) {
63741
63987
  if ((await resolveSkillInvocations(layout, named)).kind === "resolved") return;
63742
63988
  }
63743
63989
  };
63990
+ const recordedUntilResolved = (named, until) => new Promise((resolve12) => {
63991
+ const done = () => {
63992
+ recordWatchers.delete(check3);
63993
+ until.removeEventListener("abort", done);
63994
+ resolve12();
63995
+ };
63996
+ const check3 = () => {
63997
+ void resolveSkillInvocations(layout, named).then((resolution) => {
63998
+ if (resolution.kind === "resolved") done();
63999
+ });
64000
+ };
64001
+ if (until.aborted) {
64002
+ resolve12();
64003
+ return;
64004
+ }
64005
+ recordWatchers.add(check3);
64006
+ until.addEventListener("abort", done, { once: true });
64007
+ check3();
64008
+ });
63744
64009
  return {
63745
64010
  sync,
63746
64011
  rescan,
@@ -63748,8 +64013,11 @@ function openMachineSkills(options) {
63748
64013
  const named = invocations ?? [];
63749
64014
  if ((await resolveSkillInvocations(layout, named)).kind === "resolved") return;
63750
64015
  const picksLocal = named.some((invocation) => invocation.kind === "local_skill");
64016
+ const settled2 = new AbortController();
64017
+ const until = AbortSignal.any([signal, AbortSignal.timeout(waitMs), settled2.signal]);
63751
64018
  const settle = picksLocal ? rescanUntilResolved(named) : exchangeUntilResolved(named);
63752
- await Promise.race([settle, aborted2(AbortSignal.any([signal, AbortSignal.timeout(waitMs)]))]);
64019
+ await Promise.race([settle, recordedUntilResolved(named, until), aborted2(until)]);
64020
+ settled2.abort();
63753
64021
  },
63754
64022
  [Symbol.asyncDispose]: async () => {
63755
64023
  lifetime.abort();
@@ -63861,7 +64129,7 @@ async function openApprovedPaths(options) {
63861
64129
  }
63862
64130
 
63863
64131
  // src/capabilities/workspace/locks.ts
63864
- var import_node_crypto22 = require("crypto");
64132
+ var import_node_crypto23 = require("crypto");
63865
64133
  var import_promises46 = require("fs/promises");
63866
64134
  var import_node_path47 = require("path");
63867
64135
  init_zod();
@@ -63878,7 +64146,7 @@ var ownerSchema = external_exports.object({
63878
64146
  since: external_exports.number().int().nonnegative()
63879
64147
  });
63880
64148
  function repositoryLockKey(commonDir, platform3) {
63881
- return (0, import_node_crypto22.createHash)("sha256").update(comparablePath(commonDir, platform3)).digest("hex").slice(0, 32);
64149
+ return (0, import_node_crypto23.createHash)("sha256").update(comparablePath(commonDir, platform3)).digest("hex").slice(0, 32);
63882
64150
  }
63883
64151
  async function readOwner2(path4) {
63884
64152
  let text2;
@@ -63991,7 +64259,7 @@ function openRepositoryLocks(options) {
63991
64259
  },
63992
64260
  tryShared: async (commonDir, runId) => {
63993
64261
  const { key, dir } = await folder(commonDir);
63994
- const file2 = `${RUN_FILE_PREFIX}${(0, import_node_crypto22.createHash)("sha256").update(runId).digest("hex").slice(0, 32)}.json`;
64262
+ const file2 = `${RUN_FILE_PREFIX}${(0, import_node_crypto23.createHash)("sha256").update(runId).digest("hex").slice(0, 32)}.json`;
63995
64263
  const path4 = (0, import_node_path47.join)(dir, file2);
63996
64264
  const owner = await self(runId);
63997
64265
  await writeJsonFileAtomic(path4, owner);
@@ -64898,14 +65166,14 @@ async function sendNativeHookSignal(discoveryPath, hookSignal, signal) {
64898
65166
  }
64899
65167
 
64900
65168
  // src/sessions/index.ts
64901
- var import_node_crypto27 = require("crypto");
64902
- var import_promises61 = require("fs/promises");
65169
+ var import_node_crypto29 = require("crypto");
65170
+ var import_promises63 = require("fs/promises");
64903
65171
  var import_node_os10 = require("os");
64904
65172
  var import_node_path63 = require("path");
64905
65173
  init_runtime_v2();
64906
65174
 
64907
65175
  // src/holder/control-client.ts
64908
- var import_node_crypto23 = require("crypto");
65176
+ var import_node_crypto24 = require("crypto");
64909
65177
  var import_node_net2 = require("net");
64910
65178
  init_runtime_v2();
64911
65179
 
@@ -64975,7 +65243,7 @@ async function connectHolder(endpoint, token, onEvent) {
64975
65243
  });
64976
65244
  const pid = await ready;
64977
65245
  const request2 = (body) => {
64978
- const id = (0, import_node_crypto23.randomUUID)();
65246
+ const id = (0, import_node_crypto24.randomUUID)();
64979
65247
  return new Promise((resolve12, reject) => {
64980
65248
  const timer = AbortSignal.timeout(REQUEST_TIMEOUT_MS7);
64981
65249
  timer.addEventListener("abort", () => {
@@ -65236,8 +65504,33 @@ function createConversationMcpAuthorization(options) {
65236
65504
  };
65237
65505
  }
65238
65506
 
65507
+ // src/holder/mcp-helper-access.ts
65508
+ var import_promises54 = require("fs/promises");
65509
+ function createHelperMcpAccess(options) {
65510
+ return {
65511
+ [Symbol.asyncDispose]: async () => {
65512
+ await (0, import_promises54.rm)(options.credentialPath, { force: true });
65513
+ },
65514
+ url: options.managedMcp.url,
65515
+ authorization: async (signal) => {
65516
+ const authorization = await options.managedMcp.authorization(signal);
65517
+ if (authorization === void 0 || signal.aborted) {
65518
+ await (0, import_promises54.rm)(options.credentialPath, { force: true });
65519
+ return void 0;
65520
+ }
65521
+ const credential = {
65522
+ url: options.managedMcp.url,
65523
+ authorization,
65524
+ conversationId: options.conversationId
65525
+ };
65526
+ await writeJsonFileAtomic(options.credentialPath, credential);
65527
+ return authorization;
65528
+ }
65529
+ };
65530
+ }
65531
+
65239
65532
  // src/holder/run-inputs.ts
65240
- var import_promises53 = require("fs/promises");
65533
+ var import_promises55 = require("fs/promises");
65241
65534
  var import_node_path53 = require("path");
65242
65535
  var NO_RUN_INPUTS = {
65243
65536
  attachments: [],
@@ -65253,16 +65546,16 @@ function safeFilename(filename) {
65253
65546
  async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
65254
65547
  const dir = (0, import_node_path53.join)(tmpDir, "runs", spec.runId);
65255
65548
  const cleanup = async () => {
65256
- await (0, import_promises53.rm)(dir, { recursive: true, force: true });
65549
+ await (0, import_promises55.rm)(dir, { recursive: true, force: true });
65257
65550
  };
65258
65551
  try {
65259
65552
  const credential = await source.fetchProviderCredential(spec.runId, signal);
65260
65553
  const attachments = [];
65261
- if (spec.attachments?.length) await (0, import_promises53.mkdir)(dir, { recursive: true, mode: 448 });
65554
+ if (spec.attachments?.length) await (0, import_promises55.mkdir)(dir, { recursive: true, mode: 448 });
65262
65555
  for (const [index, attachment] of (spec.attachments ?? []).entries()) {
65263
65556
  const bytes = await source.downloadAttachment(spec.runId, attachment.id, signal);
65264
65557
  const path4 = (0, import_node_path53.join)(dir, `${index}-${safeFilename(attachment.filename)}`);
65265
- await (0, import_promises53.writeFile)(path4, bytes, { mode: 384 });
65558
+ await (0, import_promises55.writeFile)(path4, bytes, { mode: 384 });
65266
65559
  attachments.push({
65267
65560
  id: attachment.id,
65268
65561
  kind: attachment.kind,
@@ -65275,7 +65568,13 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
65275
65568
  ...attachment.height === void 0 ? {} : { height: attachment.height }
65276
65569
  });
65277
65570
  }
65278
- return { attachments, providerEnv: credential.env, skills, [Symbol.asyncDispose]: cleanup };
65571
+ return {
65572
+ attachments,
65573
+ providerEnv: credential.env,
65574
+ ...credential.codex === void 0 ? {} : { codex: credential.codex },
65575
+ skills,
65576
+ [Symbol.asyncDispose]: cleanup
65577
+ };
65279
65578
  } catch (error61) {
65280
65579
  await cleanup();
65281
65580
  throw error61;
@@ -65283,7 +65582,7 @@ async function prepareRunInputs(spec, { source, tmpDir, signal, skills = [] }) {
65283
65582
  }
65284
65583
 
65285
65584
  // src/holder/serve.ts
65286
- var import_node_crypto26 = require("crypto");
65585
+ var import_node_crypto28 = require("crypto");
65287
65586
  var import_node_fs21 = require("fs");
65288
65587
  var import_node_net3 = require("net");
65289
65588
  var import_node_path62 = require("path");
@@ -65291,7 +65590,7 @@ init_runtime_v2();
65291
65590
 
65292
65591
  // src/holder/admission.ts
65293
65592
  var import_node_fs18 = require("fs");
65294
- var import_promises57 = require("fs/promises");
65593
+ var import_promises59 = require("fs/promises");
65295
65594
  var import_node_os9 = require("os");
65296
65595
  var import_node_path58 = require("path");
65297
65596
  init_constants();
@@ -65305,7 +65604,7 @@ function resolveAlanDefaultWorkspacePath(homeDirectory = (0, import_node_os8.hom
65305
65604
  }
65306
65605
 
65307
65606
  // src/holder/admission-relocation.ts
65308
- var import_promises54 = require("fs/promises");
65607
+ var import_promises56 = require("fs/promises");
65309
65608
  var import_node_path55 = require("path");
65310
65609
  var MAX_RELOCATION_CANDIDATES = 200;
65311
65610
  var RELOCATION_BUDGET_MS = 2e4;
@@ -65341,7 +65640,7 @@ async function originIdentity(git, path4, signal) {
65341
65640
  }
65342
65641
  async function childDirectories(parent, limit) {
65343
65642
  try {
65344
- const entries = await (0, import_promises54.readdir)(parent, { withFileTypes: true });
65643
+ const entries = await (0, import_promises56.readdir)(parent, { withFileTypes: true });
65345
65644
  return entries.filter((entry) => entry.isDirectory()).slice(0, limit).map((entry) => (0, import_node_path55.join)(parent, entry.name));
65346
65645
  } catch {
65347
65646
  return [];
@@ -65377,8 +65676,8 @@ async function discoverRelocatedWorkspace(search) {
65377
65676
  }
65378
65677
 
65379
65678
  // src/holder/checkout-refresh.ts
65380
- var import_node_crypto24 = require("crypto");
65381
- var import_promises55 = require("fs/promises");
65679
+ var import_node_crypto26 = require("crypto");
65680
+ var import_promises57 = require("fs/promises");
65382
65681
  var import_node_path56 = require("path");
65383
65682
  function short(sha) {
65384
65683
  return sha.slice(0, 12);
@@ -65391,8 +65690,8 @@ function staleLine(path4, snapshot2, tip) {
65391
65690
  }
65392
65691
  async function claimOnce(dir, name) {
65393
65692
  try {
65394
- await (0, import_promises55.mkdir)(dir, { recursive: true, mode: 448 });
65395
- await (await (0, import_promises55.open)((0, import_node_path56.join)(dir, name), "wx")).close();
65693
+ await (0, import_promises57.mkdir)(dir, { recursive: true, mode: 448 });
65694
+ await (await (0, import_promises57.open)((0, import_node_path56.join)(dir, name), "wx")).close();
65396
65695
  return true;
65397
65696
  } catch {
65398
65697
  return false;
@@ -65424,7 +65723,7 @@ async function fastForward(freshness, operationId, deps, signal) {
65424
65723
  async function atFirstLease(freshness, spec, deps, signal) {
65425
65724
  const first = await claimOnce(
65426
65725
  (0, import_node_path56.join)(deps.dir, "leased"),
65427
- (0, import_node_crypto24.createHash)("sha256").update(freshness.path).digest("hex")
65726
+ (0, import_node_crypto26.createHash)("sha256").update(freshness.path).digest("hex")
65428
65727
  );
65429
65728
  switch (freshness.state) {
65430
65729
  case "current":
@@ -65475,7 +65774,7 @@ function createCheckoutRefresh(deps) {
65475
65774
  }
65476
65775
 
65477
65776
  // src/holder/lease.ts
65478
- var import_promises56 = require("fs/promises");
65777
+ var import_promises58 = require("fs/promises");
65479
65778
  var import_node_path57 = require("path");
65480
65779
  var LEASE_CHECK_EVERY_MS = 5e3;
65481
65780
  var MAX_TRANSIENT_FAILURES = 3;
@@ -65490,8 +65789,8 @@ function identityFailure(code, workspacePath) {
65490
65789
  return { code, problemCode: "app.workspace.missing", message: MESSAGES[code], workspacePath };
65491
65790
  }
65492
65791
  async function fileIdentity(path4) {
65493
- const canonical = await (0, import_promises56.realpath)(path4);
65494
- const info = await (0, import_promises56.stat)(canonical, { bigint: true });
65792
+ const canonical = await (0, import_promises58.realpath)(path4);
65793
+ const info = await (0, import_promises58.stat)(canonical, { bigint: true });
65495
65794
  return `${canonical}:${info.dev}:${info.ino}`;
65496
65795
  }
65497
65796
  async function snapshot(git, path4, signal) {
@@ -65510,7 +65809,7 @@ async function snapshot(git, path4, signal) {
65510
65809
  workspace: await fileIdentity(path4),
65511
65810
  repository: await fileIdentity(commonDir),
65512
65811
  worktree: await fileIdentity(gitDir),
65513
- commonDir: await (0, import_promises56.realpath)(commonDir)
65812
+ commonDir: await (0, import_promises58.realpath)(commonDir)
65514
65813
  };
65515
65814
  } catch {
65516
65815
  return null;
@@ -65523,7 +65822,7 @@ async function gitValue(git, path4, args, signal) {
65523
65822
  }
65524
65823
  async function pathExists(path4) {
65525
65824
  try {
65526
- await (0, import_promises56.stat)(path4);
65825
+ await (0, import_promises58.stat)(path4);
65527
65826
  return true;
65528
65827
  } catch (error61) {
65529
65828
  return errnoCode(error61) !== "ENOENT" && errnoCode(error61) !== "ENOTDIR";
@@ -65532,13 +65831,13 @@ async function pathExists(path4) {
65532
65831
  async function hasGitMarker(path4) {
65533
65832
  let directory;
65534
65833
  try {
65535
- directory = await (0, import_promises56.realpath)(path4);
65834
+ directory = await (0, import_promises58.realpath)(path4);
65536
65835
  } catch {
65537
65836
  return true;
65538
65837
  }
65539
65838
  for (; ; ) {
65540
65839
  try {
65541
- await (0, import_promises56.stat)((0, import_node_path57.join)(directory, ".git"));
65840
+ await (0, import_promises58.stat)((0, import_node_path57.join)(directory, ".git"));
65542
65841
  return true;
65543
65842
  } catch (error61) {
65544
65843
  const code = errnoCode(error61);
@@ -65708,7 +66007,7 @@ function volumeRoot(path4) {
65708
66007
  }
65709
66008
  async function exists4(path4) {
65710
66009
  try {
65711
- await (0, import_promises57.stat)(path4);
66010
+ await (0, import_promises59.stat)(path4);
65712
66011
  return true;
65713
66012
  } catch {
65714
66013
  return false;
@@ -65716,10 +66015,10 @@ async function exists4(path4) {
65716
66015
  }
65717
66016
  async function inspectReadiness(path4) {
65718
66017
  try {
65719
- if (!(await (0, import_promises57.stat)(path4)).isDirectory()) {
66018
+ if (!(await (0, import_promises59.stat)(path4)).isDirectory()) {
65720
66019
  return { ready: false, missing: true, message: MESSAGES2.missing };
65721
66020
  }
65722
- await (0, import_promises57.access)(path4, import_node_fs18.constants.R_OK | import_node_fs18.constants.W_OK | import_node_fs18.constants.X_OK);
66021
+ await (0, import_promises59.access)(path4, import_node_fs18.constants.R_OK | import_node_fs18.constants.W_OK | import_node_fs18.constants.X_OK);
65723
66022
  return { ready: true };
65724
66023
  } catch (error61) {
65725
66024
  const code = errnoCode(error61) ?? "";
@@ -65797,8 +66096,8 @@ async function admitDefaultWorkspace(spec, context, skills) {
65797
66096
  const { env } = context;
65798
66097
  const path4 = resolveAlanDefaultWorkspacePath(env.HOME || env.USERPROFILE || (0, import_node_os9.homedir)());
65799
66098
  try {
65800
- await (0, import_promises57.mkdir)(path4, { recursive: true, mode: 448 });
65801
- await (0, import_promises57.access)(path4, import_node_fs18.constants.R_OK | import_node_fs18.constants.W_OK | import_node_fs18.constants.X_OK);
66099
+ await (0, import_promises59.mkdir)(path4, { recursive: true, mode: 448 });
66100
+ await (0, import_promises59.access)(path4, import_node_fs18.constants.R_OK | import_node_fs18.constants.W_OK | import_node_fs18.constants.X_OK);
65802
66101
  return {
65803
66102
  kind: "admitted",
65804
66103
  spec: { ...spec, projectPath: path4 },
@@ -65814,6 +66113,16 @@ async function admitDefaultWorkspace(spec, context, skills) {
65814
66113
  );
65815
66114
  }
65816
66115
  }
66116
+ async function withInstalledCloudSkills(spec, context) {
66117
+ if (!spec.sandboxId && !spec.cloudEnvironmentId || context.skills === void 0) return spec;
66118
+ return {
66119
+ ...spec,
66120
+ promptContext: {
66121
+ ...spec.promptContext,
66122
+ availableSkills: await availableSkillIndex(context.skills)
66123
+ }
66124
+ };
66125
+ }
65817
66126
  async function admitRun(spec, context, signal) {
65818
66127
  const provider4 = await checkProvider(spec, context);
65819
66128
  if (provider4 !== null) return provider4;
@@ -65825,6 +66134,7 @@ async function admitRun(spec, context, signal) {
65825
66134
  );
65826
66135
  }
65827
66136
  const skills = selected.skills;
66137
+ spec = await withInstalledCloudSkills(spec, context);
65828
66138
  const projectPath = spec.projectPath;
65829
66139
  if (projectPath === void 0) {
65830
66140
  return { kind: "admitted", spec, relocated: null, leaseTargets: [], skills };
@@ -65869,7 +66179,10 @@ function createHolderWorkspace(machine, clock, log) {
65869
66179
  env: machine.env,
65870
66180
  git,
65871
66181
  platform: platform3,
65872
- skills: skillsLayout(machine.stateDir),
66182
+ skills: skillsLayout(
66183
+ machine.stateDir,
66184
+ machine.env.HOME || machine.env.USERPROFILE || (0, import_node_os9.homedir)()
66185
+ ),
65873
66186
  approvedRoots: async () => {
65874
66187
  const approved = await openApprovedPaths({
65875
66188
  file: (0, import_node_path58.join)(machine.stateDir, "workspaces.json"),
@@ -65913,7 +66226,7 @@ async function respondToTurn(runningRunId, gate, driver, request2) {
65913
66226
  }
65914
66227
 
65915
66228
  // src/holder/session-facts.ts
65916
- var import_promises58 = require("fs/promises");
66229
+ var import_promises60 = require("fs/promises");
65917
66230
  var CLI_RSS_CACHE_MS = 1e4;
65918
66231
  var LOGIN_PROBLEM_PREFIX = "cli.auth.";
65919
66232
  function isLoginFailure(result) {
@@ -65939,8 +66252,8 @@ function createSessionFacts(options) {
65939
66252
  const path4 = await resolveCommandOnPath(command, env, platform3);
65940
66253
  if (path4 === null) return null;
65941
66254
  try {
65942
- const real = await (0, import_promises58.realpath)(path4);
65943
- const info = await (0, import_promises58.stat)(real);
66255
+ const real = await (0, import_promises60.realpath)(path4);
66256
+ const info = await (0, import_promises60.stat)(real);
65944
66257
  return { command, key: `${real}:${info.ino}:${info.size}:${info.mtimeMs}` };
65945
66258
  } catch {
65946
66259
  return null;
@@ -66027,12 +66340,12 @@ function createSessionFacts(options) {
66027
66340
  init_acp2();
66028
66341
 
66029
66342
  // src/run-log/complete.ts
66030
- var import_node_crypto25 = require("crypto");
66343
+ var import_node_crypto27 = require("crypto");
66031
66344
  var import_node_fs19 = require("fs");
66032
66345
  var import_node_path60 = require("path");
66033
66346
 
66034
66347
  // src/run-log/directory.ts
66035
- var import_promises59 = require("fs/promises");
66348
+ var import_promises61 = require("fs/promises");
66036
66349
  var import_node_path59 = require("path");
66037
66350
  init_runtime_v2();
66038
66351
  init_zod();
@@ -66052,7 +66365,7 @@ function runDirectory(runsDir, runId) {
66052
66365
  }
66053
66366
  async function isRunClaimed(runsDir, runId) {
66054
66367
  try {
66055
- return (await (0, import_promises59.stat)(runDirectory(runsDir, runId).log)).size > 0;
66368
+ return (await (0, import_promises61.stat)(runDirectory(runsDir, runId).log)).size > 0;
66056
66369
  } catch (error61) {
66057
66370
  if (errnoCode(error61) === "ENOENT") return false;
66058
66371
  throw error61;
@@ -66061,7 +66374,7 @@ async function isRunClaimed(runsDir, runId) {
66061
66374
 
66062
66375
  // src/run-log/complete.ts
66063
66376
  function writeLogFile(path4, dir, text2) {
66064
- const temp = (0, import_node_path60.join)(dir, `.log.${(0, import_node_crypto25.randomUUID)()}.tmp`);
66377
+ const temp = (0, import_node_path60.join)(dir, `.log.${(0, import_node_crypto27.randomUUID)()}.tmp`);
66065
66378
  const fd = (0, import_node_fs19.openSync)(temp, "wx", 384);
66066
66379
  try {
66067
66380
  (0, import_node_fs19.writeSync)(fd, text2);
@@ -66090,7 +66403,7 @@ async function writeCompleteRunLog(runsDir, meta3, records) {
66090
66403
  }
66091
66404
 
66092
66405
  // src/run-log/reader.ts
66093
- var import_promises60 = require("fs/promises");
66406
+ var import_promises62 = require("fs/promises");
66094
66407
  init_runtime_v2();
66095
66408
 
66096
66409
  // src/run-log/tail.ts
@@ -66113,7 +66426,7 @@ function firstRecordLength(bytes) {
66113
66426
  return bytes.indexOf(RUN_LOG_RECORD_SEPARATOR) + 1;
66114
66427
  }
66115
66428
  async function openRunLogReader(path4) {
66116
- const handle = await (0, import_promises60.open)(path4, "r");
66429
+ const handle = await (0, import_promises62.open)(path4, "r");
66117
66430
  const readAt = async (position, length) => {
66118
66431
  const buffer = Buffer.alloc(length);
66119
66432
  const { bytesRead } = await handle.read(buffer, 0, length, position);
@@ -66147,7 +66460,7 @@ async function openRunLogReader(path4) {
66147
66460
  };
66148
66461
  }
66149
66462
  async function readLastRecord(path4) {
66150
- const handle = await (0, import_promises60.open)(path4, "r").catch(() => null);
66463
+ const handle = await (0, import_promises62.open)(path4, "r").catch(() => null);
66151
66464
  if (handle === null) return null;
66152
66465
  try {
66153
66466
  const { size } = await handle.stat();
@@ -66493,13 +66806,13 @@ var TASK_UNSUPPORTED = {
66493
66806
  reason: "unsupported",
66494
66807
  message: "This agent cannot stop one background task."
66495
66808
  };
66496
- function sha2563(value2) {
66497
- return (0, import_node_crypto26.createHash)("sha256").update(value2).digest("hex");
66809
+ function sha2564(value2) {
66810
+ return (0, import_node_crypto28.createHash)("sha256").update(value2).digest("hex");
66498
66811
  }
66499
66812
  function tokenMatches(expected, presented) {
66500
- const a = Buffer.from(sha2563(expected), "hex");
66501
- const b = Buffer.from(sha2563(presented), "hex");
66502
- return (0, import_node_crypto26.timingSafeEqual)(a, b);
66813
+ const a = Buffer.from(sha2564(expected), "hex");
66814
+ const b = Buffer.from(sha2564(presented), "hex");
66815
+ return (0, import_node_crypto28.timingSafeEqual)(a, b);
66503
66816
  }
66504
66817
  async function runHolder({
66505
66818
  launch,
@@ -66536,7 +66849,7 @@ async function runHolder({
66536
66849
  startedAt: identity.startedAt,
66537
66850
  ...identity.command === void 0 ? {} : { command: identity.command },
66538
66851
  endpoint: launch.endpoint,
66539
- tokenSha256: sha2563(launch.token),
66852
+ tokenSha256: sha2564(launch.token),
66540
66853
  state: holder.state,
66541
66854
  runId: holder.runId,
66542
66855
  updatedAt: clock.now()
@@ -66807,7 +67120,7 @@ var DEFAULT_MAX_ACTIVE_RUNS = 32;
66807
67120
  var HOLDER_BUSY = "busy";
66808
67121
  async function listIds(dir, schema) {
66809
67122
  const ids = [];
66810
- for (const name of await (0, import_promises61.readdir)(dir).catch(() => [])) {
67123
+ for (const name of await (0, import_promises63.readdir)(dir).catch(() => [])) {
66811
67124
  const parsed = schema.safeParse(name);
66812
67125
  if (parsed.success) ids.push(parsed.data);
66813
67126
  }
@@ -66863,7 +67176,7 @@ async function openSessions(deps) {
66863
67176
  await reapLeftoverEngines(engineRecordsPath(dir), { clock, log, conversationId }).catch(
66864
67177
  (error61) => log.warn("sessions.engine_reap_failed", { conversationId, error: error61 })
66865
67178
  );
66866
- await (0, import_promises61.rm)(dir, { recursive: true, force: true });
67179
+ await (0, import_promises63.rm)(dir, { recursive: true, force: true });
66867
67180
  };
66868
67181
  const retireIfGone = async (conversationId) => {
66869
67182
  const files = sessionFiles(paths, conversationId);
@@ -66951,7 +67264,7 @@ async function openSessions(deps) {
66951
67264
  log.info("sessions.reattached", { conversationId });
66952
67265
  return;
66953
67266
  }
66954
- if (alive) await (0, import_promises61.rm)(files.dir, { recursive: true, force: true });
67267
+ if (alive) await (0, import_promises63.rm)(files.dir, { recursive: true, force: true });
66955
67268
  else await discardSession(conversationId);
66956
67269
  };
66957
67270
  const busyRunIds = async () => {
@@ -66982,8 +67295,8 @@ async function openSessions(deps) {
66982
67295
  protocol: HOLDER_PROTOCOL,
66983
67296
  conversationId,
66984
67297
  machineId: deps.machineId,
66985
- endpoint: ipcEndpoint(paths.sockets, (0, import_node_crypto27.randomUUID)().slice(0, 8)),
66986
- token: (0, import_node_crypto27.randomBytes)(32).toString("hex"),
67298
+ endpoint: ipcEndpoint(paths.sockets, (0, import_node_crypto29.randomUUID)().slice(0, 8)),
67299
+ token: (0, import_node_crypto29.randomBytes)(32).toString("hex"),
66987
67300
  runsDir: paths.runs,
66988
67301
  statusPath: files.status
66989
67302
  };
@@ -67009,7 +67322,7 @@ async function openSessions(deps) {
67009
67322
  const meta3 = await readRunMeta(dir.meta);
67010
67323
  const last = await readLastRecord(dir.log);
67011
67324
  if (meta3 === null || last === null) return null;
67012
- const logged = await (0, import_promises61.stat)(dir.log).catch((error61) => {
67325
+ const logged = await (0, import_promises63.stat)(dir.log).catch((error61) => {
67013
67326
  if (errnoCode(error61) === "ENOENT") return null;
67014
67327
  throw error61;
67015
67328
  });
@@ -67389,7 +67702,7 @@ function takeEnrollmentCodeFromEnv(env = process.env) {
67389
67702
  }
67390
67703
 
67391
67704
  // src/cli/context.ts
67392
- var import_promises62 = require("fs/promises");
67705
+ var import_promises64 = require("fs/promises");
67393
67706
  var import_node_os12 = require("os");
67394
67707
  var import_node_path65 = require("path");
67395
67708
  var DESKTOP_BUNDLE_IDS = {
@@ -67439,7 +67752,7 @@ async function installedServiceSpec(ctx) {
67439
67752
  const spec = serviceSpec(ctx);
67440
67753
  if (ctx.config.host === "app") return spec;
67441
67754
  const layout = installLayout(ctx.config.installDir, ctx.config.profile);
67442
- const installed = await (0, import_promises62.access)(layout.launcher).then(
67755
+ const installed = await (0, import_promises64.access)(layout.launcher).then(
67443
67756
  () => true,
67444
67757
  () => false
67445
67758
  );
@@ -67567,7 +67880,7 @@ var manifestRevisionSchema = external_exports.object({ revision: external_export
67567
67880
  async function manifestRevision(path4) {
67568
67881
  let raw;
67569
67882
  try {
67570
- raw = JSON.parse(await (0, import_promises63.readFile)(path4, "utf8"));
67883
+ raw = JSON.parse(await (0, import_promises65.readFile)(path4, "utf8"));
67571
67884
  } catch (error61) {
67572
67885
  throw new RuntimeFault("invalid_file", `Cannot read the skill manifest at ${path4}`, {
67573
67886
  cause: error61
@@ -67585,7 +67898,7 @@ async function runSkills(argv) {
67585
67898
  case "scan":
67586
67899
  writeJson({
67587
67900
  status: "failed",
67588
- attemptId: (0, import_node_crypto28.randomUUID)(),
67901
+ attemptId: (0, import_node_crypto30.randomUUID)(),
67589
67902
  retainedInventoryRevision: null,
67590
67903
  diagnostics: [
67591
67904
  { code: "RUNTIME_SKILL_SCAN_UNSUPPORTED", message: SKILLS_SYNCED_BY_RUNTIME }
@@ -67601,7 +67914,7 @@ async function runSkills(argv) {
67601
67914
  );
67602
67915
  }
67603
67916
  writeJson({
67604
- attemptId: (0, import_node_crypto28.randomUUID)(),
67917
+ attemptId: (0, import_node_crypto30.randomUUID)(),
67605
67918
  desiredRevision: await manifestRevision(manifest),
67606
67919
  skills: []
67607
67920
  });
@@ -67621,7 +67934,7 @@ async function runSkills(argv) {
67621
67934
  }
67622
67935
 
67623
67936
  // src/cli/commands/doctor.ts
67624
- var import_promises66 = require("fs/promises");
67937
+ var import_promises68 = require("fs/promises");
67625
67938
  var import_node_path69 = require("path");
67626
67939
  init_runtime_v2();
67627
67940
 
@@ -67799,11 +68112,11 @@ async function authorizeDevice(input2) {
67799
68112
  }
67800
68113
 
67801
68114
  // src/identity/enroll.ts
67802
- var import_promises64 = require("fs/promises");
68115
+ var import_promises66 = require("fs/promises");
67803
68116
  init_runtime_v2();
67804
68117
 
67805
68118
  // src/identity/installation.ts
67806
- var import_node_crypto29 = require("crypto");
68119
+ var import_node_crypto31 = require("crypto");
67807
68120
  var import_node_path66 = require("path");
67808
68121
  init_zod();
67809
68122
  var installationFileSchema = external_exports.object({
@@ -67816,7 +68129,7 @@ async function ensureInstallationId(paths) {
67816
68129
  const path4 = installationPath(paths);
67817
68130
  const existing = await readJsonFile(path4, installationFileSchema);
67818
68131
  if (existing.kind === "ok") return existing.value.installationId;
67819
- const created = { installationId: (0, import_node_crypto29.randomUUID)() };
68132
+ const created = { installationId: (0, import_node_crypto31.randomUUID)() };
67820
68133
  await writeJsonFileAtomic(path4, created);
67821
68134
  return created.installationId;
67822
68135
  }
@@ -67903,12 +68216,12 @@ async function enrollFromGrantFile(input2) {
67903
68216
  clock: input2.clock,
67904
68217
  access: input2.access
67905
68218
  });
67906
- await (0, import_promises64.rm)(input2.grantPath, { force: true });
68219
+ await (0, import_promises66.rm)(input2.grantPath, { force: true });
67907
68220
  return machine;
67908
68221
  }
67909
68222
 
67910
68223
  // src/identity/migrate-v1.ts
67911
- var import_promises65 = require("fs/promises");
68224
+ var import_promises67 = require("fs/promises");
67912
68225
  var import_node_path67 = require("path");
67913
68226
  init_runtime_v2();
67914
68227
  init_zod();
@@ -67959,8 +68272,8 @@ async function scrubLegacyInstall(install2) {
67959
68272
  const scrubbed = { ...install2.config, migratedToRuntimeV2: true };
67960
68273
  for (const key of SCRUBBED_KEYS) delete scrubbed[key];
67961
68274
  await writeJsonFileAtomic(`${install2.configPath}.migrated-v1`, scrubbed);
67962
- await (0, import_promises65.rm)(install2.configPath, { force: true });
67963
- await (0, import_promises65.rm)(install2.ownerLeasePath, { force: true });
68275
+ await (0, import_promises67.rm)(install2.configPath, { force: true });
68276
+ await (0, import_promises67.rm)(install2.ownerLeasePath, { force: true });
67964
68277
  }
67965
68278
  async function exchangeCredential(deps) {
67966
68279
  const { config: config2 } = deps.install;
@@ -68369,7 +68682,7 @@ async function probeHolder(dir, conversationId) {
68369
68682
  }
68370
68683
  }
68371
68684
  async function holdersCheck(ctx) {
68372
- const names = await (0, import_promises66.readdir)(ctx.paths.sessions).catch(() => []);
68685
+ const names = await (0, import_promises68.readdir)(ctx.paths.sessions).catch(() => []);
68373
68686
  const holders = (await Promise.all(names.map((name) => probeHolder((0, import_node_path69.join)(ctx.paths.sessions, name), name)))).filter((facts) => facts !== null);
68374
68687
  const dead = holders.filter((holder) => !holder.alive).length;
68375
68688
  return check2(
@@ -68381,7 +68694,7 @@ async function holdersCheck(ctx) {
68381
68694
  }
68382
68695
  async function freeBytesAt(path4) {
68383
68696
  try {
68384
- const stats = await (0, import_promises66.statfs)(path4);
68697
+ const stats = await (0, import_promises68.statfs)(path4);
68385
68698
  return { path: path4, freeBytes: stats.bavail * stats.bsize };
68386
68699
  } catch (error61) {
68387
68700
  const parent = (0, import_node_path69.dirname)(path4);
@@ -68520,7 +68833,7 @@ async function runDoctor(argv, context = cliContext) {
68520
68833
  }
68521
68834
 
68522
68835
  // src/cli/commands/git-credential.ts
68523
- var import_promises67 = require("fs/promises");
68836
+ var import_promises69 = require("fs/promises");
68524
68837
  var import_node_net4 = require("net");
68525
68838
  var MAX_RESPONSE_BYTES = 64 * 1024;
68526
68839
  async function readAll(stream) {
@@ -68630,7 +68943,7 @@ async function configure(argv) {
68630
68943
  }
68631
68944
  async function configureGitGateway(config2, gatewayUrl, signal) {
68632
68945
  const { launcher } = installLayout(config2.installDir, config2.profile);
68633
- const installed = await (0, import_promises67.access)(launcher).then(
68946
+ const installed = await (0, import_promises69.access)(launcher).then(
68634
68947
  () => true,
68635
68948
  () => false
68636
68949
  );
@@ -68658,6 +68971,7 @@ async function runGitCredential(argv) {
68658
68971
 
68659
68972
  // src/cli/commands/hold.ts
68660
68973
  var import_node_path70 = require("path");
68974
+ init_agent2();
68661
68975
  init_runtime_v2();
68662
68976
  async function machineAccess(paths, log, conversationId, transport) {
68663
68977
  const initial = await loadStoredAccess(paths).catch(
@@ -68690,7 +69004,14 @@ async function machineAccess(paths, log, conversationId, transport) {
68690
69004
  return (await api()).fetchProviderCredential(runId, signal);
68691
69005
  }
68692
69006
  };
68693
- return { source, managedMcp };
69007
+ const codexCredentials = {
69008
+ refresh: async (runId, rejectedAccessTokenSha256) => (await api()).refreshCodexCredential(
69009
+ runId,
69010
+ rejectedAccessTokenSha256 === void 0 ? {} : { rejectedAccessTokenSha256 },
69011
+ new AbortController().signal
69012
+ )
69013
+ };
69014
+ return { source, managedMcp, codexCredentials };
68694
69015
  }
68695
69016
  async function runHold(argv) {
68696
69017
  var _stack = [];
@@ -68718,14 +69039,26 @@ async function runHold(argv) {
68718
69039
  );
68719
69040
  const transport = __using(_stack, createHttpTransport());
68720
69041
  const access7 = await machineAccess(paths, log, launch.value.conversationId, transport);
69042
+ const credentialPath = (0, import_node_path70.join)(paths.tmp, "mcp", `${launch.value.conversationId}.json`);
69043
+ const managedMcp = __using(_stack, access7.managedMcp === void 0 ? void 0 : createHelperMcpAccess({
69044
+ managedMcp: access7.managedMcp,
69045
+ conversationId: launch.value.conversationId,
69046
+ credentialPath
69047
+ }), true);
69048
+ const providerEnvironment2 = access7.managedMcp === void 0 ? cliEnvironment : {
69049
+ ...cliEnvironment,
69050
+ [ALAN_MCP_URL_ENV]: access7.managedMcp.url,
69051
+ [ALAN_MCP_CREDENTIAL_FILE_ENV]: credentialPath
69052
+ };
68721
69053
  await runHolder({
68722
69054
  launch: launch.value,
68723
69055
  driver: createProviderDrivers({
68724
- cliEnvironment,
69056
+ cliEnvironment: providerEnvironment2,
68725
69057
  defaultCwd: process.cwd(),
68726
69058
  timings: config2.sessionTimings,
68727
69059
  log,
68728
- ...access7.managedMcp === void 0 ? {} : { managedMcp: access7.managedMcp }
69060
+ ...managedMcp === void 0 ? {} : { managedMcp },
69061
+ codexCredentials: access7.codexCredentials
68729
69062
  }),
68730
69063
  clock: systemClock,
68731
69064
  log,
@@ -68740,7 +69073,8 @@ async function runHold(argv) {
68740
69073
  } catch (_) {
68741
69074
  var _error = _, _hasError = true;
68742
69075
  } finally {
68743
- __callDispose(_stack, _error, _hasError);
69076
+ var _promise2 = __callDispose(_stack, _error, _hasError);
69077
+ _promise2 && await _promise2;
68744
69078
  }
68745
69079
  }
68746
69080
 
@@ -68813,7 +69147,7 @@ async function runHook(argv, overrides = {}) {
68813
69147
  }
68814
69148
 
68815
69149
  // src/cli/commands/ingestion-hooks.ts
68816
- var import_promises68 = require("fs/promises");
69150
+ var import_promises70 = require("fs/promises");
68817
69151
  var CODEX_TRUST_NOTE = "Codex runs new hooks only after you review them: open /hooks in Codex.";
68818
69152
  function isAction(value2) {
68819
69153
  return value2 === "enable" || value2 === "disable" || value2 === "status";
@@ -68836,7 +69170,7 @@ function errorMessage2(error61) {
68836
69170
  return error61 instanceof Error ? error61.message : String(error61);
68837
69171
  }
68838
69172
  async function exists5(path4) {
68839
- return (0, import_promises68.access)(path4).then(
69173
+ return (0, import_promises70.access)(path4).then(
68840
69174
  () => true,
68841
69175
  () => false
68842
69176
  );
@@ -69195,7 +69529,7 @@ async function runToken(argv, signal) {
69195
69529
  }
69196
69530
 
69197
69531
  // src/cli/commands/logout.ts
69198
- var import_promises69 = require("fs/promises");
69532
+ var import_promises71 = require("fs/promises");
69199
69533
  var import_node_path74 = require("path");
69200
69534
  init_runtime_v2();
69201
69535
  var RUNTIME_EXIT_WAIT_MS = 35e3;
@@ -69255,7 +69589,7 @@ async function stopHolder(launch, deps, outcome2) {
69255
69589
  }
69256
69590
  async function stopHeldRuns(ctx, deps, outcome2 = "aborted") {
69257
69591
  const stopped = [];
69258
- for (const name of await (0, import_promises69.readdir)(ctx.paths.sessions).catch(() => [])) {
69592
+ for (const name of await (0, import_promises71.readdir)(ctx.paths.sessions).catch(() => [])) {
69259
69593
  const launch = await readJsonFile(
69260
69594
  (0, import_node_path74.join)(ctx.paths.sessions, name, "launch.json"),
69261
69595
  holderLaunchSchema
@@ -69294,7 +69628,7 @@ async function forgetMachineLocally(ctx) {
69294
69628
  const machine = await readMachineFile(ctx.paths);
69295
69629
  if (machine === null) return;
69296
69630
  await credentialStoreFor(ctx.paths, machine.credentialStore, ctx.access).clear();
69297
- await (0, import_promises69.rm)(ctx.paths.machine, { force: true });
69631
+ await (0, import_promises71.rm)(ctx.paths.machine, { force: true });
69298
69632
  }
69299
69633
  async function runLogout(argv, signal) {
69300
69634
  var _stack = [];
@@ -69382,18 +69716,18 @@ function createRunAppends() {
69382
69716
  }
69383
69717
 
69384
69718
  // src/local-api/server.ts
69385
- var import_node_crypto31 = require("crypto");
69386
- var import_promises70 = require("fs/promises");
69719
+ var import_node_crypto33 = require("crypto");
69720
+ var import_promises72 = require("fs/promises");
69387
69721
  var import_node_http4 = require("http");
69388
69722
  var import_node_path75 = require("path");
69389
69723
 
69390
69724
  // src/local-api/guard.ts
69391
- var import_node_crypto30 = require("crypto");
69725
+ var import_node_crypto32 = require("crypto");
69392
69726
  var ALLOWED = { kind: "allowed" };
69393
69727
  function tokenMatches2(expected, header) {
69394
69728
  if (header === void 0 || !header.startsWith("Bearer ")) return false;
69395
69729
  const presented = Buffer.from(header.slice("Bearer ".length));
69396
- return presented.length === expected.length && (0, import_node_crypto30.timingSafeEqual)(presented, expected);
69730
+ return presented.length === expected.length && (0, import_node_crypto32.timingSafeEqual)(presented, expected);
69397
69731
  }
69398
69732
  function isBrowserReachable(req, allowedHosts) {
69399
69733
  if (req.headers.origin !== void 0 || req.headers.referer !== void 0) return true;
@@ -70038,7 +70372,7 @@ async function serveLocalApi(deps) {
70038
70372
  server.keepAliveTimeout = KEEP_ALIVE_TIMEOUT_MS;
70039
70373
  server.maxConnections = HARD_MAX_CONNECTIONS;
70040
70374
  const port = await listenOnLoopback(server);
70041
- const token = (0, import_node_crypto31.randomBytes)(32).toString("base64url");
70375
+ const token = (0, import_node_crypto33.randomBytes)(32).toString("base64url");
70042
70376
  const guard = createRequestGuard({ token, port, rateLimit: limits.rateLimit, clock });
70043
70377
  const appAttachments = createAppAttachments(clock);
70044
70378
  const routeDeps = {
@@ -70122,7 +70456,7 @@ async function serveLocalApi(deps) {
70122
70456
  await watchedStatus[Symbol.asyncDispose]();
70123
70457
  const current = await readJsonFile(discoveryPath, localApiDiscoverySchema);
70124
70458
  if (current.kind === "ok" && current.value.token === token) {
70125
- await (0, import_promises70.rm)(discoveryPath, { force: true });
70459
+ await (0, import_promises72.rm)(discoveryPath, { force: true });
70126
70460
  }
70127
70461
  await closeServer(server);
70128
70462
  log.info("local_api.closed", {});
@@ -73875,7 +74209,7 @@ function refusalFailure(refusal2) {
73875
74209
  }
73876
74210
 
73877
74211
  // src/link/probe.ts
73878
- var import_promises71 = require("dns/promises");
74212
+ var import_promises73 = require("dns/promises");
73879
74213
  var import_node_net5 = require("net");
73880
74214
  var import_node_tls2 = require("tls");
73881
74215
  var PROBE_TIMEOUT_MS4 = 5e3;
@@ -73911,7 +74245,7 @@ async function connectOnce(url3, clock) {
73911
74245
  }
73912
74246
  async function probeEndpoint(url3, clock) {
73913
74247
  try {
73914
- await (0, import_promises71.lookup)(url3.hostname);
74248
+ await (0, import_promises73.lookup)(url3.hostname);
73915
74249
  } catch (error61) {
73916
74250
  const reason = classifyTransportFailure(error61);
73917
74251
  return reason === "other" ? "dns" : reason;
@@ -74213,9 +74547,9 @@ function planReconcile(desired, held) {
74213
74547
  }
74214
74548
 
74215
74549
  // src/reconciler/desired-sync.ts
74216
- var import_node_crypto32 = require("crypto");
74550
+ var import_node_crypto34 = require("crypto");
74217
74551
  function fingerprintOf(desired) {
74218
- return (0, import_node_crypto32.createHash)("sha256").update(JSON.stringify(desired)).digest("hex");
74552
+ return (0, import_node_crypto34.createHash)("sha256").update(JSON.stringify(desired)).digest("hex");
74219
74553
  }
74220
74554
  var FAILED_READ_RETRY_MS = 3e4;
74221
74555
  function createDesiredSync(deps) {
@@ -74352,7 +74686,7 @@ function createReconciler(host, lifecycle, log, signal) {
74352
74686
  }
74353
74687
 
74354
74688
  // src/uploader/index.ts
74355
- var import_promises72 = require("fs/promises");
74689
+ var import_promises74 = require("fs/promises");
74356
74690
  init_runtime_v2();
74357
74691
  init_zod();
74358
74692
  var RETRY_DELAYS_MS = [250, 500, 1e3, 2e3, 5e3, 1e4, 3e4];
@@ -74493,7 +74827,7 @@ function startUploader({ api, runsDir, clock, log }) {
74493
74827
  active.set(runId, task);
74494
74828
  };
74495
74829
  const sweep2 = async () => {
74496
- for (const name of await (0, import_promises72.readdir)(runsDir).catch(() => [])) {
74830
+ for (const name of await (0, import_promises74.readdir)(runsDir).catch(() => [])) {
74497
74831
  const runId = runIdSchema.safeParse(name);
74498
74832
  if (runId.success) run2(runId.data);
74499
74833
  }
@@ -74503,18 +74837,18 @@ function startUploader({ api, runsDir, clock, log }) {
74503
74837
  const dir = runDirectory(runsDir, runId);
74504
74838
  const progress = await readJsonFile(dir.upload, uploadProgressSchema);
74505
74839
  if (progress.kind !== "ok" || !progress.value.sealed) return false;
74506
- const sealedAt = (await (0, import_promises72.stat)(dir.upload)).mtimeMs;
74840
+ const sealedAt = (await (0, import_promises74.stat)(dir.upload)).mtimeMs;
74507
74841
  if (clock.now() - sealedAt < options.sealedForMs) return false;
74508
74842
  return (await readLastRecord(dir.log))?.update.sessionUpdate === "_alan/run.ended";
74509
74843
  };
74510
74844
  const prune = async (options) => {
74511
74845
  let removed = 0;
74512
- for (const name of await (0, import_promises72.readdir)(runsDir).catch(() => [])) {
74846
+ for (const name of await (0, import_promises74.readdir)(runsDir).catch(() => [])) {
74513
74847
  const runId = runIdSchema.safeParse(name);
74514
74848
  if (!runId.success) continue;
74515
74849
  try {
74516
74850
  if (!await isPrunable(runId.data, options)) continue;
74517
- await (0, import_promises72.rm)(runDirectory(runsDir, runId.data).dir, { recursive: true, force: true });
74851
+ await (0, import_promises74.rm)(runDirectory(runsDir, runId.data).dir, { recursive: true, force: true });
74518
74852
  removed += 1;
74519
74853
  } catch (error61) {
74520
74854
  log.warn("upload.prune_failed", { runId: runId.data, error: error61 });
@@ -75814,17 +76148,17 @@ async function runServiceCommand(argv, ctx = cliContext()) {
75814
76148
  }
75815
76149
 
75816
76150
  // src/cli/commands/upgrade.ts
75817
- var import_promises73 = require("fs/promises");
76151
+ var import_promises75 = require("fs/promises");
75818
76152
  var import_node_path79 = require("path");
75819
76153
  function isNotNewer(version2, installed) {
75820
76154
  return installed !== null && isReleaseVersion(version2) && isReleaseVersion(installed) && compareVersions(version2, installed) <= 0;
75821
76155
  }
75822
76156
  async function installFromSource(source) {
75823
76157
  const { layout, from, ifNewer } = source;
75824
- const isTarball = (await (0, import_promises73.stat)(from)).isFile();
76158
+ const isTarball = (await (0, import_promises75.stat)(from)).isFile();
75825
76159
  const downloads = (0, import_node_path79.join)(layout.root, ".downloads");
75826
- if (isTarball) await (0, import_promises73.mkdir)(downloads, { recursive: true, mode: 448 });
75827
- const scratch = isTarball ? await (0, import_promises73.mkdtemp)((0, import_node_path79.join)(downloads, "upgrade-")) : null;
76160
+ if (isTarball) await (0, import_promises75.mkdir)(downloads, { recursive: true, mode: 448 });
76161
+ const scratch = isTarball ? await (0, import_promises75.mkdtemp)((0, import_node_path79.join)(downloads, "upgrade-")) : null;
75828
76162
  try {
75829
76163
  const sourceDir = scratch === null ? from : await extractPackageTarball(from, scratch);
75830
76164
  const version2 = await readPackageVersion(sourceDir);
@@ -75832,7 +76166,7 @@ async function installFromSource(source) {
75832
76166
  if (ifNewer && isNotNewer(version2, installed)) return { kind: "skipped", version: version2, installed };
75833
76167
  return { kind: "installed", ...await installVersion(layout, sourceDir) };
75834
76168
  } finally {
75835
- if (scratch !== null) await (0, import_promises73.rm)(scratch, { recursive: true, force: true });
76169
+ if (scratch !== null) await (0, import_promises75.rm)(scratch, { recursive: true, force: true });
75836
76170
  }
75837
76171
  }
75838
76172
  async function runUpgrade(argv) {