@autohq/cli 0.1.418 → 0.1.420

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.
package/dist/index.js CHANGED
@@ -1159,8 +1159,8 @@ var init_regexes = __esm({
1159
1159
  _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
1160
1160
  ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
1161
1161
  ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
1162
- mac = (delimiter) => {
1163
- const escapedDelim = escapeRegex(delimiter ?? ":");
1162
+ mac = (delimiter2) => {
1163
+ const escapedDelim = escapeRegex(delimiter2 ?? ":");
1164
1164
  return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
1165
1165
  };
1166
1166
  cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
@@ -17966,7 +17966,7 @@ var init_secrets = __esm({
17966
17966
  });
17967
17967
 
17968
17968
  // ../../packages/schemas/src/session-bindings.ts
17969
- var BINDING_TARGET_TYPES, TRIGGER_BINDING_TARGET_TYPES, SESSION_BINDING_SOURCES, SESSION_BINDING_STATUSES, SESSION_BINDING_RELEASE_POLICIES, SESSION_BINDING_CONTINUITIES, SESSION_BINDING_RELEASED_BY, BINDING_TRANSITION_CAUSES, BindingTargetTypeSchema, TriggerBindingTargetTypeSchema, SessionBindingSourceSchema, SessionBindingStatusSchema, SessionBindingReleasePolicySchema, SessionBindingContinuitySchema, SessionBindingReleasedBySchema, BindingTransitionCauseSchema, BindingTargetSchema, BINDING_AUTO_BIND_VALUES, BindingAutoBindSchema, AUTO_BIND_LEGAL_TARGETS;
17969
+ var BINDING_TARGET_TYPES, TRIGGER_BINDING_TARGET_TYPES, OBSERVED_TARGET_EVENT_KEYS, SESSION_BINDING_SOURCES, SESSION_BINDING_STATUSES, SESSION_BINDING_RELEASE_POLICIES, SESSION_BINDING_CONTINUITIES, SESSION_BINDING_RELEASED_BY, BINDING_TRANSITION_CAUSES, BindingTargetTypeSchema, TriggerBindingTargetTypeSchema, SessionBindingSourceSchema, SessionBindingStatusSchema, SessionBindingReleasePolicySchema, SessionBindingContinuitySchema, SessionBindingReleasedBySchema, BindingTransitionCauseSchema, BindingTargetSchema, BINDING_AUTO_BIND_VALUES, BindingAutoBindSchema, AUTO_BIND_LEGAL_TARGETS;
17970
17970
  var init_session_bindings = __esm({
17971
17971
  "../../packages/schemas/src/session-bindings.ts"() {
17972
17972
  "use strict";
@@ -17989,6 +17989,11 @@ var init_session_bindings = __esm({
17989
17989
  "linear.issue",
17990
17990
  "auto.session"
17991
17991
  ];
17992
+ OBSERVED_TARGET_EVENT_KEYS = [
17993
+ "auto.session.binding.bound",
17994
+ "auto.session.binding.updated",
17995
+ "auto.session.binding.unbound"
17996
+ ];
17992
17997
  SESSION_BINDING_SOURCES = [
17993
17998
  "trigger_spawn",
17994
17999
  "agent_tool",
@@ -18011,6 +18016,7 @@ var init_session_bindings = __esm({
18011
18016
  "manual_update",
18012
18017
  "attributed_event",
18013
18018
  "mention",
18019
+ "observed_binding_event",
18014
18020
  "session_spawn",
18015
18021
  "trigger_spawn",
18016
18022
  "chat_send",
@@ -18248,7 +18254,7 @@ function normalizeLegacyHeartbeatTickWorkflowInput(input) {
18248
18254
  agentResourceId: sessionResourceId
18249
18255
  };
18250
18256
  }
18251
- var CANONICAL_ROUTE_BY_KINDS, LEGACY_ROUTE_BY_KINDS, CanonicalRouteBySchema, LegacyRouteBySchema, RouteBySchema, TRIGGER_ON_UNMATCHED_POLICIES, OnUnmatchedSchema, SpawnBindSchema, TriggerReleaseSchema, CanonicalTriggerRoutingSchema, LegacySingletonRouteBySchema, LegacySingletonDeliverRoutingSchema, LegacyOwnedArtifactDeliverRoutingSchema, LegacyDeliverOrSpawnRoutingSchema, TriggerRoutingSchema, SourceEventRequestSchema, EventRoutingWorkflowInputSchema, HeartbeatTickWorkflowInputSchema, GithubPullRequestMergeabilityWorkflowInputSchema, GithubPullRequestMergeabilityWorkflowResultSchema, EventRoutingTriggerResultSchema;
18257
+ var CANONICAL_ROUTE_BY_KINDS, LEGACY_ROUTE_BY_KINDS, CanonicalRouteBySchema, LegacyRouteBySchema, RouteBySchema, TRIGGER_ON_UNMATCHED_POLICIES, OnUnmatchedSchema, SpawnBindSchema, TriggerReleaseSchema, ObservedTargetActionSchema, CanonicalTriggerRoutingSchema, LegacySingletonRouteBySchema, LegacySingletonDeliverRoutingSchema, LegacyOwnedArtifactDeliverRoutingSchema, LegacyDeliverOrSpawnRoutingSchema, TriggerRoutingSchema, SourceEventRequestSchema, EventRoutingWorkflowInputSchema, HeartbeatTickWorkflowInputSchema, GithubPullRequestMergeabilityWorkflowInputSchema, GithubPullRequestMergeabilityWorkflowResultSchema, EventRoutingTriggerResultSchema;
18252
18258
  var init_trigger_router = __esm({
18253
18259
  "../../packages/schemas/src/trigger-router.ts"() {
18254
18260
  "use strict";
@@ -18308,6 +18314,17 @@ var init_trigger_router = __esm({
18308
18314
  external_exports.literal(true).transform(() => ({ context: null })),
18309
18315
  external_exports.object({ context: JsonObjectSchema.nullable().default(null) }).strict()
18310
18316
  ]);
18317
+ ObservedTargetActionSchema = external_exports.discriminatedUnion("action", [
18318
+ external_exports.object({
18319
+ action: external_exports.literal("bind"),
18320
+ context: JsonObjectSchema.nullable().default(null),
18321
+ eventContext: JsonObjectSchema.nullable().default(null)
18322
+ }).strict(),
18323
+ external_exports.object({
18324
+ action: external_exports.literal("unbind"),
18325
+ eventContext: JsonObjectSchema.nullable().default(null)
18326
+ }).strict()
18327
+ ]);
18311
18328
  CanonicalTriggerRoutingSchema = external_exports.discriminatedUnion("kind", [
18312
18329
  external_exports.object({
18313
18330
  kind: external_exports.literal("spawn"),
@@ -18336,7 +18353,17 @@ var init_trigger_router = __esm({
18336
18353
  // routing completes. No-op when no active binding exists. `agent.singleton`
18337
18354
  // is rejected at apply time (singleton slots are pool-membership state
18338
18355
  // owned by the reconciler).
18339
- release: TriggerReleaseSchema.default(false)
18356
+ release: TriggerReleaseSchema.default(false),
18357
+ // Observed-target lifecycle action: after the router delivers a matching
18358
+ // binding-transition event to the observer session this trigger's
18359
+ // `auto.session` target resolved, the platform binds or unbinds that
18360
+ // session to/from the target carried by the observed event. Apply-time
18361
+ // validation restricts this to `target: auto.session` triggers on the
18362
+ // `auto.session.binding.bound|updated|unbound` event keys; the target type
18363
+ // is authorized at runtime against the observer agent's own bindable
18364
+ // targets. Distinct from `release` above, which releases this route's own
18365
+ // `auto.session` observation binding.
18366
+ observedTarget: ObservedTargetActionSchema.optional()
18340
18367
  })
18341
18368
  ]);
18342
18369
  LegacySingletonRouteBySchema = external_exports.object({
@@ -18749,6 +18776,28 @@ function validateTriggerReleaseConfig(spec, context) {
18749
18776
  }
18750
18777
  }
18751
18778
  }
18779
+ function validateTriggerObservedTargetConfig(spec, context) {
18780
+ const legalEvents = new Set(OBSERVED_TARGET_EVENT_KEYS);
18781
+ for (const [index, trigger] of spec.triggers.entries()) {
18782
+ if (trigger.routing.kind !== "bind" || !trigger.routing.observedTarget) {
18783
+ continue;
18784
+ }
18785
+ if (trigger.routing.target !== "auto.session") {
18786
+ context.addIssue({
18787
+ code: external_exports.ZodIssueCode.custom,
18788
+ path: ["triggers", index, "routing", "observedTarget"],
18789
+ message: "`observedTarget` requires `target: auto.session`: only the observed child-session relationship may drive an observed-target action"
18790
+ });
18791
+ }
18792
+ if (!trigger.event || !legalEvents.has(trigger.event)) {
18793
+ context.addIssue({
18794
+ code: external_exports.ZodIssueCode.custom,
18795
+ path: ["triggers", index, "routing", "observedTarget"],
18796
+ message: `\`observedTarget\` requires an \`event\` in [${OBSERVED_TARGET_EVENT_KEYS.join(", ")}]: the binding lifecycle transitions are the events that carry the target to act on`
18797
+ });
18798
+ }
18799
+ }
18800
+ }
18752
18801
  function validateTriggerChecks(trigger, context, eventKeys) {
18753
18802
  const checks = trigger.checks ?? [];
18754
18803
  if (checks.length === 0) {
@@ -19118,6 +19167,7 @@ var init_agents = __esm({
19118
19167
  validateConcurrencyConfig(spec, context);
19119
19168
  validateBindingsConfig(spec, context);
19120
19169
  validateTriggerReleaseConfig(spec, context);
19170
+ validateTriggerObservedTargetConfig(spec, context);
19121
19171
  });
19122
19172
  AgentStatusSchema = external_exports.object({
19123
19173
  runCount: external_exports.number().int().nonnegative().default(0),
@@ -36173,15 +36223,15 @@ async function* readSseEvents(body) {
36173
36223
  break;
36174
36224
  }
36175
36225
  buffer += decoder.decode(value, { stream: true });
36176
- let delimiter = buffer.indexOf("\n\n");
36177
- while (delimiter !== -1) {
36178
- const rawEvent = buffer.slice(0, delimiter);
36179
- buffer = buffer.slice(delimiter + 2);
36226
+ let delimiter2 = buffer.indexOf("\n\n");
36227
+ while (delimiter2 !== -1) {
36228
+ const rawEvent = buffer.slice(0, delimiter2);
36229
+ buffer = buffer.slice(delimiter2 + 2);
36180
36230
  const event2 = parseSseEvent(rawEvent);
36181
36231
  if (event2) {
36182
36232
  yield event2;
36183
36233
  }
36184
- delimiter = buffer.indexOf("\n\n");
36234
+ delimiter2 = buffer.indexOf("\n\n");
36185
36235
  }
36186
36236
  }
36187
36237
  buffer += decoder.decode();
@@ -38670,7 +38720,7 @@ var init_package = __esm({
38670
38720
  "package.json"() {
38671
38721
  package_default = {
38672
38722
  name: "@autohq/cli",
38673
- version: "0.1.418",
38723
+ version: "0.1.420",
38674
38724
  license: "SEE LICENSE IN README.md",
38675
38725
  publishConfig: {
38676
38726
  access: "public"
@@ -38735,13 +38785,13 @@ var init_version = __esm({
38735
38785
  });
38736
38786
 
38737
38787
  // src/commands/agents/authoring.ts
38738
- import { readFileSync as readFileSync4, readdirSync as readdirSync2, statSync } from "fs";
38788
+ import { readFileSync as readFileSync6, readdirSync as readdirSync2, statSync as statSync2 } from "fs";
38739
38789
  import {
38740
38790
  basename as basename2,
38741
- dirname as dirname5,
38791
+ dirname as dirname7,
38742
38792
  extname,
38743
38793
  isAbsolute,
38744
- join as join5,
38794
+ join as join6,
38745
38795
  resolve
38746
38796
  } from "path";
38747
38797
  import { parseAllDocuments as parseYamlDocuments, stringify } from "yaml";
@@ -38793,8 +38843,8 @@ function renderAgentExplain(result) {
38793
38843
  return lines.join("\n");
38794
38844
  }
38795
38845
  function readLocalAgentAuthoringStatuses(input) {
38796
- const agentsDirectory = join5(
38797
- input?.directory ?? join5(process.cwd(), ".auto"),
38846
+ const agentsDirectory = join6(
38847
+ input?.directory ?? join6(process.cwd(), ".auto"),
38798
38848
  "agents"
38799
38849
  );
38800
38850
  const paths = agentAuthoringFiles(agentsDirectory);
@@ -38833,7 +38883,7 @@ function agentAuthoringFiles(directory) {
38833
38883
  }
38834
38884
  const files = [];
38835
38885
  for (const entry of entries) {
38836
- const path2 = join5(directory, entry.name);
38886
+ const path2 = join6(directory, entry.name);
38837
38887
  if (entry.isDirectory()) {
38838
38888
  files.push(...agentAuthoringFiles(path2));
38839
38889
  continue;
@@ -38853,12 +38903,12 @@ function resolveAgentAuthoringPath(input) {
38853
38903
  if (isAgentFile(candidate)) {
38854
38904
  return candidate;
38855
38905
  }
38856
- const agentsDirectory = join5(
38857
- input.directory ?? join5(process.cwd(), ".auto"),
38906
+ const agentsDirectory = join6(
38907
+ input.directory ?? join6(process.cwd(), ".auto"),
38858
38908
  "agents"
38859
38909
  );
38860
38910
  for (const extension of AGENT_FILE_EXTENSIONS) {
38861
- const path2 = join5(agentsDirectory, `${input.agent}${extension}`);
38911
+ const path2 = join6(agentsDirectory, `${input.agent}${extension}`);
38862
38912
  if (isAgentFile(path2)) {
38863
38913
  return path2;
38864
38914
  }
@@ -38916,7 +38966,7 @@ function readSingleDocument(path2) {
38916
38966
  return documents[0];
38917
38967
  }
38918
38968
  function readDocuments(path2) {
38919
- const source = readFileSync4(path2, "utf8");
38969
+ const source = readFileSync6(path2, "utf8");
38920
38970
  const documents = parseYamlDocuments(source);
38921
38971
  const parseError = documents.flatMap((document) => document.errors).at(0);
38922
38972
  if (parseError) {
@@ -38941,7 +38991,7 @@ function resolveImportPath(importPath, importerPath) {
38941
38991
  if (isAbsolute(importPath) || /^[A-Za-z]+:\/\//.test(importPath)) {
38942
38992
  throw new Error(`Agent import must be a relative path: ${importPath}`);
38943
38993
  }
38944
- const resolved = resolve(dirname5(importerPath), importPath);
38994
+ const resolved = resolve(dirname7(importerPath), importPath);
38945
38995
  if (!isAgentFile(resolved)) {
38946
38996
  throw new Error(
38947
38997
  `Agent import not found: ${importPath} from ${importerPath}`
@@ -39116,7 +39166,7 @@ function resolveFileBackedString(value, input) {
39116
39166
  `Invalid agent authoring file ${input.path}: ${input.field}.file must be a relative path`
39117
39167
  );
39118
39168
  }
39119
- return readFileSync4(resolve(dirname5(input.path), filePath), "utf8");
39169
+ return readFileSync6(resolve(dirname7(input.path), filePath), "utf8");
39120
39170
  }
39121
39171
  function removalDirectives(document, path2) {
39122
39172
  const raw = isRecord(document.remove) ? document.remove : {};
@@ -39267,7 +39317,7 @@ function importedEdgeCount(graph) {
39267
39317
  }
39268
39318
  function isAgentFile(path2) {
39269
39319
  try {
39270
- return statSync(path2).isFile();
39320
+ return statSync2(path2).isFile();
39271
39321
  } catch {
39272
39322
  return false;
39273
39323
  }
@@ -41625,18 +41675,18 @@ var init_project_apply_files2 = __esm({
41625
41675
 
41626
41676
  // src/commands/apply/files.ts
41627
41677
  import {
41628
- existsSync as existsSync4,
41629
- readFileSync as readFileSync5,
41678
+ existsSync as existsSync6,
41679
+ readFileSync as readFileSync7,
41630
41680
  readdirSync as readdirSync3,
41631
- realpathSync,
41632
- statSync as statSync2
41681
+ realpathSync as realpathSync2,
41682
+ statSync as statSync3
41633
41683
  } from "fs";
41634
41684
  import {
41635
41685
  basename as basename3,
41636
- dirname as dirname6,
41686
+ dirname as dirname8,
41637
41687
  extname as extname3,
41638
41688
  isAbsolute as isAbsolute2,
41639
- join as join7,
41689
+ join as join8,
41640
41690
  relative,
41641
41691
  resolve as resolve2
41642
41692
  } from "path";
@@ -41667,7 +41717,7 @@ function readProjectApplyBundleInput(options) {
41667
41717
  }
41668
41718
  };
41669
41719
  }
41670
- const directory = resolve2(options.directory ?? join7(process.cwd(), ".auto"));
41720
+ const directory = resolve2(options.directory ?? join8(process.cwd(), ".auto"));
41671
41721
  const projectRoot = applyProjectRoot(directory);
41672
41722
  const files = withManagedTemplateFiles(sourceFiles(directory, projectRoot));
41673
41723
  const resourceRoot = sourcePathRelative(projectRoot, directory);
@@ -41704,7 +41754,7 @@ function sourceFiles(root, projectRoot) {
41704
41754
  return [];
41705
41755
  }
41706
41756
  return entries.flatMap((entry) => {
41707
- const path2 = join7(root, entry.name);
41757
+ const path2 = join8(root, entry.name);
41708
41758
  if (entry.isDirectory()) {
41709
41759
  return sourceFiles(path2, projectRoot);
41710
41760
  }
@@ -41717,7 +41767,7 @@ function sourceFiles(root, projectRoot) {
41717
41767
  function sourceFile(path2, projectRoot) {
41718
41768
  return {
41719
41769
  path: sourcePathRelative(projectRoot, path2),
41720
- contentBase64: readFileSync5(path2).toString("base64")
41770
+ contentBase64: readFileSync7(path2).toString("base64")
41721
41771
  };
41722
41772
  }
41723
41773
  function applyBundle(files) {
@@ -41758,24 +41808,24 @@ function filesystemAssetReader(projectRoot) {
41758
41808
  }
41759
41809
  return {
41760
41810
  path: path2,
41761
- bytes: readFileSync5(path2)
41811
+ bytes: readFileSync7(path2)
41762
41812
  };
41763
41813
  };
41764
41814
  }
41765
41815
  function applyProjectRoot(directory) {
41766
41816
  const resolved = resolve2(directory);
41767
- return basename3(resolved) === ".auto" ? dirname6(resolved) : resolved;
41817
+ return basename3(resolved) === ".auto" ? dirname8(resolved) : resolved;
41768
41818
  }
41769
41819
  function applyFileProjectRoot(file2) {
41770
- let dir = dirname6(resolve2(file2));
41820
+ let dir = dirname8(resolve2(file2));
41771
41821
  while (true) {
41772
41822
  if (basename3(dir) === ".auto") {
41773
- return dirname6(dir);
41823
+ return dirname8(dir);
41774
41824
  }
41775
41825
  if (directoryHasAutoRoot(dir)) {
41776
41826
  return dir;
41777
41827
  }
41778
- const parent = dirname6(dir);
41828
+ const parent = dirname8(dir);
41779
41829
  if (parent === dir) {
41780
41830
  return process.cwd();
41781
41831
  }
@@ -41784,14 +41834,14 @@ function applyFileProjectRoot(file2) {
41784
41834
  }
41785
41835
  function applyFileSourceRoot(file2, projectRoot) {
41786
41836
  const autoRoot = resolve2(projectRoot, ".auto");
41787
- return file2 === autoRoot || isInside(file2, autoRoot) ? autoRoot : dirname6(file2);
41837
+ return file2 === autoRoot || isInside(file2, autoRoot) ? autoRoot : dirname8(file2);
41788
41838
  }
41789
41839
  function directoryHasAutoRoot(directory) {
41790
41840
  const autoRoot = resolve2(directory, ".auto");
41791
- if (!existsSync4(autoRoot)) {
41841
+ if (!existsSync6(autoRoot)) {
41792
41842
  return false;
41793
41843
  }
41794
- return statSync2(autoRoot).isDirectory();
41844
+ return statSync3(autoRoot).isDirectory();
41795
41845
  }
41796
41846
  function displayResourceRoot(directory) {
41797
41847
  return basename3(directory) === ".auto" ? ".auto" : directory;
@@ -41814,11 +41864,11 @@ function validateAgentAvatarAsset(input) {
41814
41864
  `Invalid identity avatar asset for "${input.resourceName}": asset path must be under .auto/assets`
41815
41865
  );
41816
41866
  }
41817
- const projectRoot = realpathSync(input.projectRoot);
41867
+ const projectRoot = realpathSync2(input.projectRoot);
41818
41868
  const assetPath = resolve2(projectRoot, input.asset);
41819
41869
  let assetsRoot;
41820
41870
  try {
41821
- assetsRoot = realpathSync(resolve2(projectRoot, ".auto", "assets"));
41871
+ assetsRoot = realpathSync2(resolve2(projectRoot, ".auto", "assets"));
41822
41872
  } catch {
41823
41873
  if (input.allowMissing) {
41824
41874
  return null;
@@ -41830,8 +41880,8 @@ function validateAgentAvatarAsset(input) {
41830
41880
  let resolvedAssetPath;
41831
41881
  let stat;
41832
41882
  try {
41833
- resolvedAssetPath = realpathSync(assetPath);
41834
- stat = statSync2(resolvedAssetPath);
41883
+ resolvedAssetPath = realpathSync2(assetPath);
41884
+ stat = statSync3(resolvedAssetPath);
41835
41885
  } catch {
41836
41886
  if (input.allowMissing) {
41837
41887
  return null;
@@ -42396,14 +42446,14 @@ var init_resources3 = __esm({
42396
42446
  // src/commands/edit/actions.ts
42397
42447
  import { spawn as spawn3 } from "child_process";
42398
42448
  import {
42399
- mkdirSync as mkdirSync5,
42400
- mkdtempSync as mkdtempSync2,
42401
- readFileSync as readFileSync6,
42402
- rmSync as rmSync2,
42403
- writeFileSync as writeFileSync6
42449
+ mkdirSync as mkdirSync6,
42450
+ mkdtempSync as mkdtempSync3,
42451
+ readFileSync as readFileSync8,
42452
+ rmSync as rmSync3,
42453
+ writeFileSync as writeFileSync8
42404
42454
  } from "fs";
42405
- import { tmpdir as tmpdir2 } from "os";
42406
- import { join as join8 } from "path";
42455
+ import { tmpdir as tmpdir3 } from "os";
42456
+ import { join as join9 } from "path";
42407
42457
  import { parseAllDocuments as parseYamlDocuments3, stringify as stringify4 } from "yaml";
42408
42458
  async function editResource(input) {
42409
42459
  const reference = parseProjectResourceReference(input.resource);
@@ -42423,15 +42473,15 @@ async function editResource(input) {
42423
42473
  const document = editableAgentFacade(current);
42424
42474
  const source = `${stringify4(document).trimEnd()}
42425
42475
  `;
42426
- const tempRoot = mkdtempSync2(join8(tmpdir2(), "auto-edit-"));
42427
- const agentsDir = join8(tempRoot, ".auto", "agents");
42428
- mkdirSync5(agentsDir, { recursive: true });
42429
- const filePath = join8(agentsDir, `${reference.name}.yaml`);
42430
- writeFileSync6(filePath, source, "utf8");
42476
+ const tempRoot = mkdtempSync3(join9(tmpdir3(), "auto-edit-"));
42477
+ const agentsDir = join9(tempRoot, ".auto", "agents");
42478
+ mkdirSync6(agentsDir, { recursive: true });
42479
+ const filePath = join9(agentsDir, `${reference.name}.yaml`);
42480
+ writeFileSync8(filePath, source, "utf8");
42431
42481
  let removeTempFile = false;
42432
42482
  try {
42433
42483
  await runEditor(editor, filePath);
42434
- const editedSource = readFileSync6(filePath, "utf8");
42484
+ const editedSource = readFileSync8(filePath, "utf8");
42435
42485
  if (editedSource === source) {
42436
42486
  input.writeOutput("No changes; skipped apply.");
42437
42487
  removeTempFile = true;
@@ -42458,7 +42508,7 @@ async function editResource(input) {
42458
42508
  Edited file retained at ${filePath}`);
42459
42509
  } finally {
42460
42510
  if (removeTempFile) {
42461
- rmSync2(tempRoot, { recursive: true, force: true });
42511
+ rmSync3(tempRoot, { recursive: true, force: true });
42462
42512
  }
42463
42513
  }
42464
42514
  }
@@ -42497,7 +42547,7 @@ async function runEditor(editor, filePath) {
42497
42547
  });
42498
42548
  }
42499
42549
  function assertEditedResourceIdentity(filePath, expected) {
42500
- const source = readFileSync6(filePath, "utf8");
42550
+ const source = readFileSync8(filePath, "utf8");
42501
42551
  let parsedDocuments;
42502
42552
  try {
42503
42553
  parsedDocuments = parseYamlDocuments3(source);
@@ -47986,8 +48036,8 @@ __export(launcher_exports, {
47986
48036
  launch: () => launch
47987
48037
  });
47988
48038
  import { spawnSync } from "child_process";
47989
- import { existsSync as existsSync6 } from "fs";
47990
- import { dirname as dirname7, resolve as resolve3 } from "path";
48039
+ import { existsSync as existsSync8 } from "fs";
48040
+ import { dirname as dirname9, resolve as resolve3 } from "path";
47991
48041
  import { fileURLToPath } from "url";
47992
48042
  import {
47993
48043
  QueryClient,
@@ -48167,7 +48217,7 @@ function resolveSplashVersion() {
48167
48217
  return resolveLatestReleaseVersionFromCheckout() ?? cliVersion;
48168
48218
  }
48169
48219
  function resolveLatestReleaseVersionFromCheckout() {
48170
- const repoRoot = findRepoRoot(dirname7(fileURLToPath(import.meta.url)));
48220
+ const repoRoot = findRepoRoot(dirname9(fileURLToPath(import.meta.url)));
48171
48221
  if (!repoRoot) {
48172
48222
  return null;
48173
48223
  }
@@ -48184,10 +48234,10 @@ function resolveLatestReleaseVersionFromCheckout() {
48184
48234
  function findRepoRoot(startDirectory) {
48185
48235
  let directory = startDirectory;
48186
48236
  while (true) {
48187
- if (existsSync6(resolve3(directory, ".git")) && existsSync6(resolve3(directory, "apps/cli/package.json"))) {
48237
+ if (existsSync8(resolve3(directory, ".git")) && existsSync8(resolve3(directory, "apps/cli/package.json"))) {
48188
48238
  return directory;
48189
48239
  }
48190
- const parent = dirname7(directory);
48240
+ const parent = dirname9(directory);
48191
48241
  if (parent === directory) {
48192
48242
  return null;
48193
48243
  }
@@ -51999,6 +52049,233 @@ function uiChunk(chunk) {
51999
52049
  };
52000
52050
  }
52001
52051
 
52052
+ // src/commands/agent-bridge/harness/claude-code/read-state.ts
52053
+ import {
52054
+ existsSync as existsSync2,
52055
+ mkdirSync as mkdirSync3,
52056
+ readFileSync as readFileSync3,
52057
+ statSync,
52058
+ writeFileSync as writeFileSync3
52059
+ } from "fs";
52060
+ import { dirname as dirname4 } from "path";
52061
+
52062
+ // src/commands/agent-bridge/harness/claude-code/resume-store.ts
52063
+ import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
52064
+ import { dirname as dirname3 } from "path";
52065
+ var AGENT_BRIDGE_RUNTIME_DIR = "/tmp/auto-bridge-runtime";
52066
+ var CLAUDE_SESSION_RESUME_PATH = `${AGENT_BRIDGE_RUNTIME_DIR}/claude-session-id`;
52067
+ function fileClaudeSessionResumeStore(path2 = CLAUDE_SESSION_RESUME_PATH) {
52068
+ return {
52069
+ read(sessionId) {
52070
+ if (!existsSync(path2)) {
52071
+ return null;
52072
+ }
52073
+ const record2 = parseResumeRecord(readFileSync2(path2, "utf8"));
52074
+ if (!record2 || record2.sessionId !== sessionId) {
52075
+ return null;
52076
+ }
52077
+ return record2.agentId;
52078
+ },
52079
+ write(record2) {
52080
+ mkdirSync2(dirname3(path2), { recursive: true });
52081
+ writeFileSync2(path2, `${JSON.stringify(record2)}
52082
+ `, "utf8");
52083
+ }
52084
+ };
52085
+ }
52086
+ function parseResumeRecord(raw) {
52087
+ try {
52088
+ const value = JSON.parse(raw);
52089
+ if (value !== null && typeof value === "object" && "sessionId" in value && "agentId" in value && typeof value.sessionId === "string" && typeof value.agentId === "string" && value.agentId.length > 0) {
52090
+ return { sessionId: value.sessionId, agentId: value.agentId };
52091
+ }
52092
+ return null;
52093
+ } catch {
52094
+ return null;
52095
+ }
52096
+ }
52097
+
52098
+ // src/commands/agent-bridge/harness/claude-code/read-state.ts
52099
+ var CLAUDE_READ_STATE_PATH = `${AGENT_BRIDGE_RUNTIME_DIR}/claude-read-state`;
52100
+ var CLAUDE_READ_STATE_MAX_ENTRIES = 256;
52101
+ var ClaudeReadStateTracker = class {
52102
+ constructor(store) {
52103
+ this.store = store;
52104
+ }
52105
+ store;
52106
+ // Most-recently-observed entries last (Map preserves insertion order, and
52107
+ // touches re-insert), so eviction drops the stalest observation first.
52108
+ entriesByPath = /* @__PURE__ */ new Map();
52109
+ // tool_use ids of in-flight file-tool calls, mapped to the file they target.
52110
+ // Cleared at each turn's terminal result so interrupted calls cannot leak.
52111
+ pendingFileToolUses = /* @__PURE__ */ new Map();
52112
+ loadedForSessionId = null;
52113
+ // Feed every live SDK message through here. Successful Read/Write/Edit
52114
+ // results commit a path+mtime observation; everything else is ignored.
52115
+ observe(sessionId, message) {
52116
+ this.ensureLoaded(sessionId);
52117
+ if (message.type === "result") {
52118
+ this.pendingFileToolUses.clear();
52119
+ return;
52120
+ }
52121
+ if (message.type === "assistant" && message.parent_tool_use_id === null) {
52122
+ for (const block of contentBlocks(message.message.content)) {
52123
+ const use = fileToolUse(block);
52124
+ if (use) {
52125
+ this.pendingFileToolUses.set(use.toolUseId, use.path);
52126
+ }
52127
+ }
52128
+ return;
52129
+ }
52130
+ if (message.type !== "user" || message.parent_tool_use_id !== null) {
52131
+ return;
52132
+ }
52133
+ if ("isReplay" in message && message.isReplay === true) {
52134
+ return;
52135
+ }
52136
+ for (const block of contentBlocks(message.message.content)) {
52137
+ if (block.type !== "tool_result") {
52138
+ continue;
52139
+ }
52140
+ const toolUseId = typeof block.tool_use_id === "string" ? block.tool_use_id : null;
52141
+ if (toolUseId === null) {
52142
+ continue;
52143
+ }
52144
+ const path2 = this.pendingFileToolUses.get(toolUseId);
52145
+ this.pendingFileToolUses.delete(toolUseId);
52146
+ if (path2 !== void 0 && block.is_error !== true) {
52147
+ this.commit(sessionId, path2);
52148
+ }
52149
+ }
52150
+ }
52151
+ // The seeds to replay into a fresh CLI process, stalest observation first so
52152
+ // the most recent reads survive any CLI-side eviction.
52153
+ seeds(sessionId) {
52154
+ this.ensureLoaded(sessionId);
52155
+ return [...this.entriesByPath].map(([path2, mtime]) => ({ path: path2, mtime }));
52156
+ }
52157
+ // A conversation-lineage break: the next CLI session starts with no prior
52158
+ // context, so nothing the model "remembers reading" exists anymore.
52159
+ clear(sessionId) {
52160
+ this.ensureLoaded(sessionId);
52161
+ if (this.entriesByPath.size === 0) {
52162
+ return;
52163
+ }
52164
+ this.entriesByPath.clear();
52165
+ this.persist(sessionId);
52166
+ }
52167
+ ensureLoaded(sessionId) {
52168
+ if (this.loadedForSessionId === sessionId) {
52169
+ return;
52170
+ }
52171
+ this.loadedForSessionId = sessionId;
52172
+ this.entriesByPath.clear();
52173
+ this.pendingFileToolUses.clear();
52174
+ for (const entry of this.store.read(sessionId) ?? []) {
52175
+ this.entriesByPath.set(entry.path, entry.mtime);
52176
+ }
52177
+ }
52178
+ commit(sessionId, path2) {
52179
+ let mtime;
52180
+ try {
52181
+ mtime = Math.floor(statSync(path2).mtimeMs);
52182
+ } catch {
52183
+ if (this.entriesByPath.delete(path2)) {
52184
+ this.persist(sessionId);
52185
+ }
52186
+ return;
52187
+ }
52188
+ this.entriesByPath.delete(path2);
52189
+ this.entriesByPath.set(path2, mtime);
52190
+ while (this.entriesByPath.size > CLAUDE_READ_STATE_MAX_ENTRIES) {
52191
+ const oldest = this.entriesByPath.keys().next().value;
52192
+ if (oldest === void 0) {
52193
+ break;
52194
+ }
52195
+ this.entriesByPath.delete(oldest);
52196
+ }
52197
+ this.persist(sessionId);
52198
+ }
52199
+ persist(sessionId) {
52200
+ this.store.write({ sessionId, entries: this.seeds(sessionId) });
52201
+ }
52202
+ };
52203
+ function fileClaudeReadStateStore(path2 = CLAUDE_READ_STATE_PATH) {
52204
+ return {
52205
+ read(sessionId) {
52206
+ if (!existsSync2(path2)) {
52207
+ return null;
52208
+ }
52209
+ const record2 = parseReadStateRecord(readFileSync3(path2, "utf8"));
52210
+ if (!record2 || record2.sessionId !== sessionId) {
52211
+ return null;
52212
+ }
52213
+ return record2.entries;
52214
+ },
52215
+ write(record2) {
52216
+ mkdirSync3(dirname4(path2), { recursive: true });
52217
+ writeFileSync3(path2, `${JSON.stringify(record2)}
52218
+ `, "utf8");
52219
+ }
52220
+ };
52221
+ }
52222
+ function fileToolUse(block) {
52223
+ if (block.type !== "tool_use" || typeof block.id !== "string") {
52224
+ return null;
52225
+ }
52226
+ const input = block.input;
52227
+ if (typeof input !== "object" || input === null) {
52228
+ return null;
52229
+ }
52230
+ const filePath = input.file_path;
52231
+ if (typeof filePath !== "string" || filePath.length === 0) {
52232
+ return null;
52233
+ }
52234
+ switch (block.name) {
52235
+ case "Read": {
52236
+ const { offset, limit } = input;
52237
+ if (offset !== void 0 || limit !== void 0) {
52238
+ return null;
52239
+ }
52240
+ return { toolUseId: block.id, path: filePath };
52241
+ }
52242
+ case "Write":
52243
+ case "Edit":
52244
+ return { toolUseId: block.id, path: filePath };
52245
+ default:
52246
+ return null;
52247
+ }
52248
+ }
52249
+ function contentBlocks(content) {
52250
+ if (!Array.isArray(content)) {
52251
+ return [];
52252
+ }
52253
+ return content.filter(
52254
+ (block) => typeof block === "object" && block !== null
52255
+ );
52256
+ }
52257
+ function parseReadStateRecord(raw) {
52258
+ try {
52259
+ const value = JSON.parse(raw);
52260
+ if (value === null || typeof value !== "object" || !("sessionId" in value) || !("entries" in value) || typeof value.sessionId !== "string" || !Array.isArray(value.entries)) {
52261
+ return null;
52262
+ }
52263
+ const entries = [];
52264
+ for (const entry of value.entries) {
52265
+ if (entry === null || typeof entry !== "object" || typeof entry.path !== "string" || typeof entry.mtime !== "number") {
52266
+ return null;
52267
+ }
52268
+ entries.push({
52269
+ path: entry.path,
52270
+ mtime: entry.mtime
52271
+ });
52272
+ }
52273
+ return { sessionId: value.sessionId, entries };
52274
+ } catch {
52275
+ return null;
52276
+ }
52277
+ }
52278
+
52002
52279
  // src/commands/agent-bridge/harness/claude-code/session.ts
52003
52280
  import {
52004
52281
  startup as startupClaudeAgent
@@ -52198,6 +52475,7 @@ var CLAUDE_INTERRUPT_SETTLE_TIMEOUT_MS = 1e4;
52198
52475
  var CLAUDE_INTERRUPT_ACK_TIMEOUT_MS = 1e4;
52199
52476
  var CLAUDE_MCP_REGISTRATION_TIMEOUT_MS = 3e3;
52200
52477
  var CLAUDE_MCP_REGISTRATION_POLL_INTERVAL_MS = 100;
52478
+ var CLAUDE_READ_STATE_SEED_FAILURE_LIMIT = 3;
52201
52479
  var CLAUDE_STARTUP_PROFILE_HOOK_EVENTS = [
52202
52480
  "Setup",
52203
52481
  "SessionStart",
@@ -52414,6 +52692,32 @@ var ClaudeAgentBridgeSessionImpl = class {
52414
52692
  }
52415
52693
  );
52416
52694
  }
52695
+ async seedReadState(seeds) {
52696
+ if (seeds.length === 0 || this.state.kind !== "running") {
52697
+ return;
52698
+ }
52699
+ const query = this.state.query;
52700
+ const startedAt = Date.now();
52701
+ let seeded = 0;
52702
+ let failed = 0;
52703
+ for (const seed of seeds) {
52704
+ try {
52705
+ await query.seedReadState(seed.path, seed.mtime);
52706
+ seeded += 1;
52707
+ } catch (error51) {
52708
+ failed += 1;
52709
+ this.input.writeOutput?.(
52710
+ `agent_bridge_claude_read_state_seed_failed path=${seed.path} error=${error51 instanceof Error ? error51.message : String(error51)}`
52711
+ );
52712
+ if (failed >= CLAUDE_READ_STATE_SEED_FAILURE_LIMIT) {
52713
+ break;
52714
+ }
52715
+ }
52716
+ }
52717
+ this.input.writeOutput?.(
52718
+ `agent_bridge_claude_read_state_seeded seeded=${seeded} total=${seeds.length} duration_ms=${Date.now() - startedAt}`
52719
+ );
52720
+ }
52417
52721
  close() {
52418
52722
  const previousState = this.state;
52419
52723
  if (previousState.kind === "closed") {
@@ -52475,6 +52779,7 @@ var ClaudeAgentBridgeSessionImpl = class {
52475
52779
  this.input.writeOutput?.(
52476
52780
  `agent_bridge_claude_resume_fallback session_id=${resume}`
52477
52781
  );
52782
+ this.input.onResumeFallback?.();
52478
52783
  this.state = { kind: "idle" };
52479
52784
  return this.startSdkSession();
52480
52785
  }
@@ -53079,7 +53384,7 @@ function isClaudeAgentTurnResult(message) {
53079
53384
  }
53080
53385
  function toolUseIds(message) {
53081
53386
  if (message.type === "assistant") {
53082
- return contentBlocks(message.message.content).flatMap(
53387
+ return contentBlocks2(message.message.content).flatMap(
53083
53388
  (block2) => block2.type === "tool_use" && typeof block2.id === "string" ? [block2.id] : []
53084
53389
  );
53085
53390
  }
@@ -53097,11 +53402,11 @@ function toolResultIds(message) {
53097
53402
  if (message.type !== "user") {
53098
53403
  return [];
53099
53404
  }
53100
- return contentBlocks(message.message.content).flatMap(
53405
+ return contentBlocks2(message.message.content).flatMap(
53101
53406
  (block) => block.type === "tool_result" && typeof block.tool_use_id === "string" ? [block.tool_use_id] : []
53102
53407
  );
53103
53408
  }
53104
- function contentBlocks(content) {
53409
+ function contentBlocks2(content) {
53105
53410
  if (!Array.isArray(content)) {
53106
53411
  return [];
53107
53412
  }
@@ -53110,42 +53415,6 @@ function contentBlocks(content) {
53110
53415
  );
53111
53416
  }
53112
53417
 
53113
- // src/commands/agent-bridge/harness/claude-code/resume-store.ts
53114
- import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
53115
- import { dirname as dirname3 } from "path";
53116
- var AGENT_BRIDGE_RUNTIME_DIR = "/tmp/auto-bridge-runtime";
53117
- var CLAUDE_SESSION_RESUME_PATH = `${AGENT_BRIDGE_RUNTIME_DIR}/claude-session-id`;
53118
- function fileClaudeSessionResumeStore(path2 = CLAUDE_SESSION_RESUME_PATH) {
53119
- return {
53120
- read(sessionId) {
53121
- if (!existsSync(path2)) {
53122
- return null;
53123
- }
53124
- const record2 = parseResumeRecord(readFileSync2(path2, "utf8"));
53125
- if (!record2 || record2.sessionId !== sessionId) {
53126
- return null;
53127
- }
53128
- return record2.agentId;
53129
- },
53130
- write(record2) {
53131
- mkdirSync2(dirname3(path2), { recursive: true });
53132
- writeFileSync2(path2, `${JSON.stringify(record2)}
53133
- `, "utf8");
53134
- }
53135
- };
53136
- }
53137
- function parseResumeRecord(raw) {
53138
- try {
53139
- const value = JSON.parse(raw);
53140
- if (value !== null && typeof value === "object" && "sessionId" in value && "agentId" in value && typeof value.sessionId === "string" && typeof value.agentId === "string" && value.agentId.length > 0) {
53141
- return { sessionId: value.sessionId, agentId: value.agentId };
53142
- }
53143
- return null;
53144
- } catch {
53145
- return null;
53146
- }
53147
- }
53148
-
53149
53418
  // src/commands/agent-bridge/harness/claude-code/index.ts
53150
53419
  function createClaudeCodeCommandHandler(input) {
53151
53420
  return new ClaudeCodeCommandHandler(input);
@@ -53155,6 +53424,7 @@ var ClaudeCodeCommandHandler = class {
53155
53424
  this.input = input;
53156
53425
  this.claudeConfig = input.claude;
53157
53426
  this.outputBuffer = new AgentBridgeOutputBuffer(input);
53427
+ this.readState = input.readState ? new ClaudeReadStateTracker(input.readState) : null;
53158
53428
  }
53159
53429
  input;
53160
53430
  context = null;
@@ -53176,6 +53446,7 @@ var ClaudeCodeCommandHandler = class {
53176
53446
  pendingQuestions = /* @__PURE__ */ new Map();
53177
53447
  outputBuffer;
53178
53448
  projector = new ClaudeCodeProjector();
53449
+ readState;
53179
53450
  livenessTicker = null;
53180
53451
  // -----------------------------------------------------------------------------
53181
53452
  // Lifecycle (public API)
@@ -53552,6 +53823,7 @@ var ClaudeCodeCommandHandler = class {
53552
53823
  return;
53553
53824
  }
53554
53825
  this.persistAgentId(activeContext, message);
53826
+ this.trackReadState(activeContext, message);
53555
53827
  let projections;
53556
53828
  try {
53557
53829
  projections = this.projector.project(message);
@@ -53615,6 +53887,31 @@ var ClaudeCodeCommandHandler = class {
53615
53887
  );
53616
53888
  }
53617
53889
  }
53890
+ // Observes file-tool results into the read-state tracker and replays the
53891
+ // tracked seeds whenever a fresh CLI cache appears: a new process's `init`
53892
+ // (runtime restart, selection change, CLI-internal fork — all resume the
53893
+ // conversation but start with an empty readFileState) and compaction
53894
+ // boundaries (which can evict prior reads). Seeding is fire-and-forget:
53895
+ // a failed seed degrades to today's behavior, a fresh Read before writing.
53896
+ trackReadState(activeContext, message) {
53897
+ const tracker = this.readState;
53898
+ if (!tracker) {
53899
+ return;
53900
+ }
53901
+ if (message.type === "system" && (message.subtype === "init" || message.subtype === "compact_boundary")) {
53902
+ const seeds = tracker.seeds(activeContext.sessionId);
53903
+ if (seeds.length === 0) {
53904
+ return;
53905
+ }
53906
+ this.agentSession?.seedReadState(seeds).catch((error51) => {
53907
+ this.input.writeOutput?.(
53908
+ `agent_bridge_claude_read_state_seed_failed error=${error51 instanceof Error ? error51.message : String(error51)}`
53909
+ );
53910
+ });
53911
+ return;
53912
+ }
53913
+ tracker.observe(activeContext.sessionId, message);
53914
+ }
53618
53915
  storedResumeAgentId() {
53619
53916
  const store = this.input.sessionResume;
53620
53917
  const activeContext = this.context;
@@ -53644,10 +53941,18 @@ var ClaudeCodeCommandHandler = class {
53644
53941
  "Cannot restart Claude Code for a model/effort selection change without a session id to resume"
53645
53942
  );
53646
53943
  }
53944
+ if (!resumeAgentId && this.context) {
53945
+ this.readState?.clear(this.context.sessionId);
53946
+ }
53647
53947
  const session = claudeAgentBridgeRuntime.start({
53648
53948
  claude: this.claudeConfig,
53649
53949
  resumeAgentId,
53650
53950
  ...resumeRequired ? { allowResumeFallback: false } : {},
53951
+ onResumeFallback: () => {
53952
+ if (this.context) {
53953
+ this.readState?.clear(this.context.sessionId);
53954
+ }
53955
+ },
53651
53956
  canUseTool: this.canUseTool,
53652
53957
  onMessage: (message, meta3) => this.handleAgentMessage(message, meta3),
53653
53958
  onError: (error51) => this.handleAgentError(error51),
@@ -54064,25 +54369,25 @@ function normalizeChunk(chunk) {
54064
54369
  }
54065
54370
 
54066
54371
  // src/commands/agent-bridge/harness/codex/resume-store.ts
54067
- import { existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
54068
- import { dirname as dirname4 } from "path";
54372
+ import { existsSync as existsSync3, mkdirSync as mkdirSync4, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "fs";
54373
+ import { dirname as dirname5 } from "path";
54069
54374
  var AGENT_BRIDGE_RUNTIME_DIR2 = "/tmp/auto-bridge-runtime";
54070
54375
  var CODEX_THREAD_RESUME_PATH = `${AGENT_BRIDGE_RUNTIME_DIR2}/codex-thread-id`;
54071
54376
  function fileCodexThreadResumeStore(path2 = CODEX_THREAD_RESUME_PATH) {
54072
54377
  return {
54073
54378
  read(sessionId) {
54074
- if (!existsSync2(path2)) {
54379
+ if (!existsSync3(path2)) {
54075
54380
  return null;
54076
54381
  }
54077
- const record2 = parseResumeRecord2(readFileSync3(path2, "utf8"));
54382
+ const record2 = parseResumeRecord2(readFileSync4(path2, "utf8"));
54078
54383
  if (!record2 || record2.sessionId !== sessionId) {
54079
54384
  return null;
54080
54385
  }
54081
54386
  return record2.threadId;
54082
54387
  },
54083
54388
  write(record2) {
54084
- mkdirSync3(dirname4(path2), { recursive: true });
54085
- writeFileSync3(path2, `${JSON.stringify(record2)}
54389
+ mkdirSync4(dirname5(path2), { recursive: true });
54390
+ writeFileSync4(path2, `${JSON.stringify(record2)}
54086
54391
  `, "utf8");
54087
54392
  }
54088
54393
  };
@@ -54102,8 +54407,26 @@ function parseResumeRecord2(raw) {
54102
54407
  // src/commands/agent-bridge/harness/codex/session.ts
54103
54408
  init_src();
54104
54409
  import { spawn as spawn2 } from "child_process";
54105
- import { mkdirSync as mkdirSync4, writeFileSync as writeFileSync4 } from "fs";
54106
- import { join as join4 } from "path";
54410
+ import { mkdirSync as mkdirSync5, writeFileSync as writeFileSync6 } from "fs";
54411
+ import { join as join5 } from "path";
54412
+
54413
+ // src/commands/agent-bridge/harness/codex/edit-capability.ts
54414
+ import { execFileSync } from "child_process";
54415
+ import {
54416
+ constants,
54417
+ accessSync,
54418
+ existsSync as existsSync4,
54419
+ lstatSync,
54420
+ mkdtempSync,
54421
+ readFileSync as readFileSync5,
54422
+ realpathSync,
54423
+ rmSync as rmSync2,
54424
+ symlinkSync,
54425
+ unlinkSync,
54426
+ writeFileSync as writeFileSync5
54427
+ } from "fs";
54428
+ import { tmpdir } from "os";
54429
+ import { delimiter, dirname as dirname6, join as join4 } from "path";
54107
54430
 
54108
54431
  // src/commands/agent-bridge/harness/codex/options.ts
54109
54432
  import { join as join3 } from "path";
@@ -54245,6 +54568,172 @@ function tomlString(value) {
54245
54568
  return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
54246
54569
  }
54247
54570
 
54571
+ // src/commands/agent-bridge/harness/codex/edit-capability.ts
54572
+ var CODEX_APPLY_PATCH_ALIAS = "apply_patch";
54573
+ var CODEX_EDIT_PROBE = {
54574
+ fileName: "probe.txt",
54575
+ before: "codex-edit-probe\n",
54576
+ after: "codex-edit-probe-ok\n",
54577
+ patch: [
54578
+ "*** Begin Patch",
54579
+ "*** Update File: probe.txt",
54580
+ "@@",
54581
+ "-codex-edit-probe",
54582
+ "+codex-edit-probe-ok",
54583
+ "*** End Patch"
54584
+ ].join("\n")
54585
+ };
54586
+ var PROBE_TIMEOUT_MS = 15e3;
54587
+ var MAX_EVIDENCE_LENGTH = 300;
54588
+ var CODEX_PLATFORM_VENDOR_TARGETS = {
54589
+ linux: {
54590
+ x64: "x86_64-unknown-linux-musl",
54591
+ arm64: "aarch64-unknown-linux-musl"
54592
+ },
54593
+ darwin: {
54594
+ x64: "x86_64-apple-darwin",
54595
+ arm64: "aarch64-apple-darwin"
54596
+ }
54597
+ };
54598
+ function ensureCodexEditCapability(input) {
54599
+ if (input.command !== CODEX_EXECUTABLE_PATH) {
54600
+ input.writeOutput?.(
54601
+ "agent_bridge_codex_edit_capability status=skipped reason=command_override"
54602
+ );
54603
+ return;
54604
+ }
54605
+ const startedAt = Date.now();
54606
+ const layout = runStep(input, "resolve", () => resolveCodexVendorLayout());
54607
+ const status = runStep(
54608
+ input,
54609
+ "provision",
54610
+ () => provisionApplyPatchAlias(layout)
54611
+ );
54612
+ const alias = join4(layout.codexPathDir, CODEX_APPLY_PATCH_ALIAS);
54613
+ runStep(input, "verify", () => verifyApplyPatchAlias(alias));
54614
+ input.writeOutput?.(
54615
+ `agent_bridge_codex_edit_capability status=${status} alias=${alias} duration_ms=${Date.now() - startedAt}`
54616
+ );
54617
+ }
54618
+ function codexEditFallthroughMarker(item) {
54619
+ if (item.type !== "commandExecution" || item.exitCode !== 127) {
54620
+ return null;
54621
+ }
54622
+ const output = item.aggregatedOutput ?? "";
54623
+ if (!/apply_patch: (command )?not found/.test(output)) {
54624
+ return null;
54625
+ }
54626
+ return `agent_bridge_codex_edit_fallthrough item_id=${item.id} exit_code=127`;
54627
+ }
54628
+ function resolveCodexVendorLayout() {
54629
+ const wrapper = whichOnPath(CODEX_EXECUTABLE_PATH);
54630
+ if (!wrapper) {
54631
+ throw new Error("codex executable not found on PATH");
54632
+ }
54633
+ const target = CODEX_PLATFORM_VENDOR_TARGETS[process.platform]?.[process.arch];
54634
+ if (!target) {
54635
+ throw new Error(
54636
+ `unsupported platform for codex vendor layout: ${process.platform}/${process.arch}`
54637
+ );
54638
+ }
54639
+ const packageRoot = join4(dirname6(realpathSync(wrapper)), "..");
54640
+ const platformPackage = `@openai/codex-${platformPackageSuffix()}`;
54641
+ const candidates = [
54642
+ join4(packageRoot, "node_modules", platformPackage, "vendor", target),
54643
+ join4(packageRoot, "vendor", target)
54644
+ ];
54645
+ for (const vendorDir of candidates) {
54646
+ const binary = join4(vendorDir, "bin", "codex");
54647
+ const codexPathDir = join4(vendorDir, "codex-path");
54648
+ if (existsSync4(binary) && existsSync4(codexPathDir)) {
54649
+ return { binary, codexPathDir };
54650
+ }
54651
+ }
54652
+ throw new Error(
54653
+ `codex vendor layout not found (wrapper=${wrapper} candidates=${candidates.join(",")})`
54654
+ );
54655
+ }
54656
+ function platformPackageSuffix() {
54657
+ const os = process.platform === "darwin" ? "darwin" : "linux";
54658
+ return `${os}-${process.arch}`;
54659
+ }
54660
+ function whichOnPath(command) {
54661
+ for (const dir of (process.env.PATH ?? "").split(delimiter)) {
54662
+ if (!dir) {
54663
+ continue;
54664
+ }
54665
+ const candidate = join4(dir, command);
54666
+ try {
54667
+ accessSync(candidate, constants.X_OK);
54668
+ return candidate;
54669
+ } catch {
54670
+ }
54671
+ }
54672
+ return null;
54673
+ }
54674
+ function provisionApplyPatchAlias(layout) {
54675
+ const alias = join4(layout.codexPathDir, CODEX_APPLY_PATCH_ALIAS);
54676
+ if (aliasResolvesToBinary(alias, layout.binary)) {
54677
+ return "present";
54678
+ }
54679
+ if (lstatExists(alias)) {
54680
+ unlinkSync(alias);
54681
+ }
54682
+ symlinkSync(layout.binary, alias);
54683
+ return "provisioned";
54684
+ }
54685
+ function aliasResolvesToBinary(alias, binary) {
54686
+ try {
54687
+ return realpathSync(alias) === realpathSync(binary);
54688
+ } catch {
54689
+ return false;
54690
+ }
54691
+ }
54692
+ function lstatExists(path2) {
54693
+ try {
54694
+ lstatSync(path2);
54695
+ return true;
54696
+ } catch {
54697
+ return false;
54698
+ }
54699
+ }
54700
+ function verifyApplyPatchAlias(alias) {
54701
+ const scratch = mkdtempSync(join4(tmpdir(), "codex-edit-probe-"));
54702
+ try {
54703
+ const probeFile = join4(scratch, CODEX_EDIT_PROBE.fileName);
54704
+ writeFileSync5(probeFile, CODEX_EDIT_PROBE.before);
54705
+ execFileSync(alias, [CODEX_EDIT_PROBE.patch], {
54706
+ cwd: scratch,
54707
+ stdio: ["ignore", "pipe", "pipe"],
54708
+ timeout: PROBE_TIMEOUT_MS
54709
+ });
54710
+ const applied = readFileSync5(probeFile, "utf8");
54711
+ if (applied !== CODEX_EDIT_PROBE.after) {
54712
+ throw new Error("probe patch did not apply the expected content");
54713
+ }
54714
+ } finally {
54715
+ rmSync2(scratch, { recursive: true, force: true });
54716
+ }
54717
+ }
54718
+ function runStep(input, step, action) {
54719
+ try {
54720
+ return action();
54721
+ } catch (error51) {
54722
+ const detail = boundedEvidence(error51);
54723
+ input.writeOutput?.(
54724
+ `agent_bridge_codex_edit_capability status=failed step=${step} error=${detail}`
54725
+ );
54726
+ throw new Error(
54727
+ `Codex edit capability unavailable at ${step}: ${detail}. Codex 0.141.0 declares no apply_patch tool; without the codex-path alias, exec invocations the interceptor does not recognize fail with command-not-found (codex-runtime-tool-loss-diagnostics).`
54728
+ );
54729
+ }
54730
+ }
54731
+ function boundedEvidence(error51) {
54732
+ const message = error51 instanceof Error ? error51.message : String(error51);
54733
+ const flattened = message.replace(/\s+/g, " ").trim();
54734
+ return flattened.length > MAX_EVIDENCE_LENGTH ? `${flattened.slice(0, MAX_EVIDENCE_LENGTH)}\u2026` : flattened;
54735
+ }
54736
+
54248
54737
  // src/commands/agent-bridge/harness/codex/turn-retry.ts
54249
54738
  var MAX_CODEX_TURN_RETRY_ATTEMPTS = 3;
54250
54739
  var MAX_CODEX_TURN_RETRY_TOTAL_DELAY_MS = 3e4;
@@ -54478,12 +54967,16 @@ var CodexAgentBridgeSessionImpl = class {
54478
54967
  }
54479
54968
  async start() {
54480
54969
  const options = codexLaunchOptions(this.input.codex);
54481
- mkdirSync4(options.codexHome, { recursive: true });
54482
- writeFileSync4(join4(options.codexHome, "config.toml"), options.configToml);
54970
+ mkdirSync5(options.codexHome, { recursive: true });
54971
+ writeFileSync6(join5(options.codexHome, "config.toml"), options.configToml);
54483
54972
  const startedAt = Date.now();
54484
54973
  this.input.writeOutput?.(
54485
54974
  `agent_bridge_codex_startup_started codex_home=${options.codexHome}`
54486
54975
  );
54976
+ ensureCodexEditCapability({
54977
+ command: options.command,
54978
+ ...this.input.writeOutput ? { writeOutput: this.input.writeOutput } : {}
54979
+ });
54487
54980
  const proc = spawn2(options.command, options.args, {
54488
54981
  env: options.env,
54489
54982
  stdio: ["pipe", "pipe", "pipe"]
@@ -54883,12 +55376,17 @@ var CodexAgentBridgeSessionImpl = class {
54883
55376
  this.pendingToolItemIds.add(notification.item.id);
54884
55377
  }
54885
55378
  return;
54886
- case "itemCompleted":
55379
+ case "itemCompleted": {
55380
+ const fallthrough = codexEditFallthroughMarker(notification.item);
55381
+ if (fallthrough) {
55382
+ this.input.writeOutput?.(fallthrough);
55383
+ }
54887
55384
  this.pendingToolItemIds.delete(notification.item.id);
54888
55385
  if (this.pendingToolItemIds.size === 0) {
54889
55386
  this.resolveSettlement();
54890
55387
  }
54891
55388
  return;
55389
+ }
54892
55390
  default:
54893
55391
  return;
54894
55392
  }
@@ -55373,6 +55871,7 @@ function createHarnessCommandHandler(input) {
55373
55871
  return createClaudeCodeCommandHandler({
55374
55872
  ...base,
55375
55873
  claude,
55874
+ readState: fileClaudeReadStateStore(),
55376
55875
  sessionResume: fileClaudeSessionResumeStore()
55377
55876
  });
55378
55877
  }
@@ -55672,9 +56171,9 @@ function statusAgents(input) {
55672
56171
  // src/commands/agents/connect.ts
55673
56172
  init_resources2();
55674
56173
  init_browser();
55675
- import { existsSync as existsSync3, mkdtempSync, writeFileSync as writeFileSync5 } from "fs";
55676
- import { homedir as homedir3, tmpdir } from "os";
55677
- import { join as join6 } from "path";
56174
+ import { existsSync as existsSync5, mkdtempSync as mkdtempSync2, writeFileSync as writeFileSync7 } from "fs";
56175
+ import { homedir as homedir3, tmpdir as tmpdir2 } from "os";
56176
+ import { join as join7 } from "path";
55678
56177
 
55679
56178
  // src/lib/stdio/secret.ts
55680
56179
  async function questionSecret(context, prompt) {
@@ -55865,7 +56364,7 @@ async function promptForIconUploads(input, options) {
55865
56364
  }
55866
56365
  }
55867
56366
  function stagedLocationLabel(stagedPath) {
55868
- return stagedPath.startsWith(`${join6(homedir3(), "Downloads")}/`) ? "Downloads" : "the printed path";
56367
+ return stagedPath.startsWith(`${join7(homedir3(), "Downloads")}/`) ? "Downloads" : "the printed path";
55869
56368
  }
55870
56369
  async function stageAvatarImage(input) {
55871
56370
  try {
@@ -55877,10 +56376,10 @@ async function stageAvatarImage(input) {
55877
56376
  }
55878
56377
  const contentType = response.headers.get("content-type") ?? "";
55879
56378
  const extension = contentType.includes("jpeg") ? ".jpg" : ".png";
55880
- const downloads = join6(homedir3(), "Downloads");
55881
- const directory = existsSync3(downloads) ? downloads : mkdtempSync(join6(tmpdir(), "auto-avatar-"));
55882
- const path2 = join6(directory, `${input.agent}-avatar${extension}`);
55883
- writeFileSync5(path2, Buffer.from(await response.arrayBuffer()));
56379
+ const downloads = join7(homedir3(), "Downloads");
56380
+ const directory = existsSync5(downloads) ? downloads : mkdtempSync2(join7(tmpdir2(), "auto-avatar-"));
56381
+ const path2 = join7(directory, `${input.agent}-avatar${extension}`);
56382
+ writeFileSync7(path2, Buffer.from(await response.arrayBuffer()));
55884
56383
  return path2;
55885
56384
  } catch {
55886
56385
  return void 0;
@@ -57379,19 +57878,19 @@ init_src();
57379
57878
  // src/commands/logs/actions.ts
57380
57879
  import {
57381
57880
  closeSync,
57382
- existsSync as existsSync5,
57881
+ existsSync as existsSync7,
57383
57882
  openSync,
57384
- readFileSync as readFileSync7,
57883
+ readFileSync as readFileSync9,
57385
57884
  readSync,
57386
- statSync as statSync3
57885
+ statSync as statSync4
57387
57886
  } from "fs";
57388
57887
  var DEFAULT_POLL_INTERVAL_MS = 1e3;
57389
57888
  async function tailRuntimeLog(input) {
57390
- if (!existsSync5(input.path)) {
57889
+ if (!existsSync7(input.path)) {
57391
57890
  input.writeError(`No runtime log at ${input.path}`);
57392
57891
  return;
57393
57892
  }
57394
- const content = readFileSync7(input.path, "utf8");
57893
+ const content = readFileSync9(input.path, "utf8");
57395
57894
  for (const line of selectLastLines(content, input.lines)) {
57396
57895
  input.writeOutput(line);
57397
57896
  }
@@ -57418,7 +57917,7 @@ async function followRuntimeLog(input) {
57418
57917
  }
57419
57918
  let size;
57420
57919
  try {
57421
- size = statSync3(input.path).size;
57920
+ size = statSync4(input.path).size;
57422
57921
  } catch {
57423
57922
  continue;
57424
57923
  }
@@ -60503,7 +61002,7 @@ function createProgram(options = {}) {
60503
61002
  }
60504
61003
 
60505
61004
  // src/lib/entrypoint.ts
60506
- import { realpathSync as realpathSync2 } from "fs";
61005
+ import { realpathSync as realpathSync3 } from "fs";
60507
61006
  import { pathToFileURL } from "url";
60508
61007
  function isCliEntrypoint(input) {
60509
61008
  if (input.entrypoint.kind === "missing") {
@@ -60511,7 +61010,7 @@ function isCliEntrypoint(input) {
60511
61010
  }
60512
61011
  let resolvedEntrypoint;
60513
61012
  try {
60514
- resolvedEntrypoint = realpathSync2(input.entrypoint.path);
61013
+ resolvedEntrypoint = realpathSync3(input.entrypoint.path);
60515
61014
  } catch {
60516
61015
  return false;
60517
61016
  }