@aibexhq/aibex-link 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +363 -117
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { readFileSync, mkdirSync, writeFileSync, chmodSync, renameSync, rmSync, existsSync, readdirSync, statSync, cpSync, mkdtempSync, appendFileSync, openSync, readSync, closeSync, accessSync, constants } from "node:fs";
1
+ import { readFileSync, mkdirSync, writeFileSync, chmodSync, renameSync, rmSync, existsSync, readdirSync, realpathSync, lstatSync, cpSync, statSync, mkdtempSync, appendFileSync, openSync, readSync, closeSync, accessSync, constants } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { randomBytes, createHash, timingSafeEqual } from "node:crypto";
4
4
  import { execFile } from "node:child_process";
@@ -700,6 +700,239 @@ class Access {
700
700
  return { accept: file.accept, integrations: file.integrations };
701
701
  }
702
702
  }
703
+ const GITHUB_HOST = "github.com";
704
+ const REPO_SCAN_MS = 6e4;
705
+ const GITHUB_REMOTE = [
706
+ /^https:\/\/(?:[^@/]+@)?github\.com\/([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/u,
707
+ /^(?:ssh:\/\/)?git@github\.com[:/]([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/u
708
+ ];
709
+ function parseGitHubRemote(url) {
710
+ for (const pattern of GITHUB_REMOTE) {
711
+ const match = pattern.exec(url.trim());
712
+ if (match?.[1] && match[2]) return { owner: match[1], name: match[2] };
713
+ }
714
+ return void 0;
715
+ }
716
+ function git(cwd, args, environment) {
717
+ return new Promise((resolve) => {
718
+ execFile(
719
+ "git",
720
+ ["-C", cwd, ...args],
721
+ environment ? { env: { ...process.env, ...environment } } : {},
722
+ (failure, stdout, stderr) => resolve({
723
+ ok: failure === null,
724
+ stdout: stdout.trim(),
725
+ stderr: stderr.trim()
726
+ })
727
+ );
728
+ });
729
+ }
730
+ function directories(parent) {
731
+ try {
732
+ return readdirSync(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name).toSorted();
733
+ } catch {
734
+ return [];
735
+ }
736
+ }
737
+ async function scanRepos(reposDirectory) {
738
+ const github = path.join(reposDirectory, GITHUB_HOST);
739
+ const candidates = directories(github).flatMap(
740
+ (owner) => directories(path.join(github, owner)).map((name) => path.join(github, owner, name)).filter((directory) => existsSync(path.join(directory, ".git")))
741
+ );
742
+ const found = await Promise.all(
743
+ candidates.map(async (directory) => {
744
+ const origin = await git(directory, [
745
+ "config",
746
+ "--get",
747
+ "remote.origin.url"
748
+ ]);
749
+ const repo = origin.ok ? parseGitHubRemote(origin.stdout) : void 0;
750
+ return repo ? { repo, path: directory } : void 0;
751
+ })
752
+ );
753
+ return found.filter((checkout) => checkout !== void 0);
754
+ }
755
+ class Repos {
756
+ constructor(reposDirectory, now = Date.now) {
757
+ this.reposDirectory = reposDirectory;
758
+ this.now = now;
759
+ }
760
+ scanned = [];
761
+ scannedAt = Number.NEGATIVE_INFINITY;
762
+ async list(options = {}) {
763
+ if (options.fresh || this.now() - this.scannedAt >= REPO_SCAN_MS) {
764
+ this.scanned = await scanRepos(this.reposDirectory);
765
+ this.scannedAt = this.now();
766
+ }
767
+ return this.scanned;
768
+ }
769
+ /** The checkout for a repository, rescanning once when it is not known. */
770
+ async find(repo) {
771
+ const match = (checkouts) => checkouts.find(
772
+ (checkout) => checkout.repo.owner.toLowerCase() === repo.owner.toLowerCase() && checkout.repo.name.toLowerCase() === repo.name.toLowerCase()
773
+ );
774
+ return match(await this.list()) ?? match(await this.list({ fresh: true }));
775
+ }
776
+ }
777
+ const REPO_FILE = ".aibex/repo.json";
778
+ const CARRY_MAX = 20;
779
+ const CARRY_ENTRY_MAX = 200;
780
+ const REPO_FILE_MAX_BYTES = 64 * 1024;
781
+ function carryEntryProblem(entry) {
782
+ if (typeof entry !== "string") return "is not a string";
783
+ if (entry === "") return "is empty";
784
+ if (entry.length > CARRY_ENTRY_MAX)
785
+ return `is longer than ${CARRY_ENTRY_MAX} characters`;
786
+ if (entry.includes("\0") || entry.includes("\\"))
787
+ return "holds a backslash or a NUL";
788
+ if (path.isAbsolute(entry) || path.win32.isAbsolute(entry))
789
+ return "is absolute";
790
+ if (/[*?[]/u.test(entry) || entry.startsWith(":"))
791
+ return 'holds a glob character or starts with ":"';
792
+ const parts = entry.split("/");
793
+ if (parts.some((part) => part === "" || part === "." || part === ".."))
794
+ return 'is not a plain relative path (no "..", ".", "//" or trailing "/")';
795
+ if (parts.some((part) => part.toLowerCase() === ".git"))
796
+ return "is inside .git";
797
+ return void 0;
798
+ }
799
+ function carryList(worktree) {
800
+ const file = path.join(worktree, REPO_FILE);
801
+ let stats;
802
+ try {
803
+ stats = lstatSync(file);
804
+ } catch {
805
+ return { carry: [], problems: [] };
806
+ }
807
+ if (!stats.isFile()) {
808
+ return { carry: [], problems: [`${REPO_FILE} is not a regular file`] };
809
+ }
810
+ if (stats.size > REPO_FILE_MAX_BYTES) {
811
+ return {
812
+ carry: [],
813
+ problems: [`${REPO_FILE} is larger than ${REPO_FILE_MAX_BYTES} bytes`]
814
+ };
815
+ }
816
+ let parsed;
817
+ try {
818
+ parsed = JSON.parse(readFileSync(file, "utf8"));
819
+ } catch {
820
+ return { carry: [], problems: [`${REPO_FILE} is not valid JSON`] };
821
+ }
822
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
823
+ return { carry: [], problems: [`${REPO_FILE} is not a JSON object`] };
824
+ }
825
+ const value = parsed.carry;
826
+ if (value === void 0) return { carry: [], problems: [] };
827
+ if (!Array.isArray(value)) {
828
+ return { carry: [], problems: [`${REPO_FILE}: "carry" is not a list`] };
829
+ }
830
+ const carry = [];
831
+ const problems = [];
832
+ if (value.length > CARRY_MAX) {
833
+ problems.push(
834
+ `${REPO_FILE}: "carry" lists ${value.length} entries; only the first ${CARRY_MAX} are read`
835
+ );
836
+ }
837
+ for (const entry of value.slice(0, CARRY_MAX)) {
838
+ const problem = carryEntryProblem(entry);
839
+ if (problem !== void 0) {
840
+ problems.push(
841
+ `${REPO_FILE}: carry entry ${JSON.stringify(entry)} skipped: it ${problem}`
842
+ );
843
+ } else if (!carry.includes(entry)) {
844
+ carry.push(entry);
845
+ }
846
+ }
847
+ return { carry, problems };
848
+ }
849
+ function inside(parent, child) {
850
+ const relative = path.relative(parent, child);
851
+ return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
852
+ }
853
+ function realAncestor(target) {
854
+ let current = target;
855
+ for (; ; ) {
856
+ try {
857
+ return realpathSync(current);
858
+ } catch {
859
+ const parent = path.dirname(current);
860
+ if (parent === current) return current;
861
+ current = parent;
862
+ }
863
+ }
864
+ }
865
+ async function carryInto(checkout, worktree) {
866
+ const { carry, problems } = carryList(worktree);
867
+ const carried = [];
868
+ let checkoutReal;
869
+ let worktreeReal;
870
+ try {
871
+ checkoutReal = realpathSync(checkout);
872
+ worktreeReal = realpathSync(worktree);
873
+ } catch (error) {
874
+ problems.push(`carry skipped: ${error.message}`);
875
+ return { carried, problems };
876
+ }
877
+ for (const entry of carry) {
878
+ const from = path.join(checkout, entry);
879
+ const to = path.join(worktree, entry);
880
+ const skip = (why) => problems.push(`carry entry ${JSON.stringify(entry)} skipped: ${why}`);
881
+ let source;
882
+ try {
883
+ source = lstatSync(from);
884
+ } catch {
885
+ continue;
886
+ }
887
+ if (source.isSymbolicLink()) {
888
+ skip("it is a symbolic link in the checkout");
889
+ continue;
890
+ }
891
+ if (!source.isFile() && !source.isDirectory()) {
892
+ skip("it is not a file or a directory");
893
+ continue;
894
+ }
895
+ if (!inside(checkoutReal, realpathSync(from))) {
896
+ skip("it leads out of the checkout");
897
+ continue;
898
+ }
899
+ if (existsSync(to) || isLink(to)) continue;
900
+ const tracked = await git(checkout, [
901
+ "--literal-pathspecs",
902
+ "ls-files",
903
+ "--error-unmatch",
904
+ "--",
905
+ entry
906
+ ]);
907
+ if (tracked.ok) continue;
908
+ if (!inside(worktreeReal, realAncestor(path.dirname(to)))) {
909
+ skip("it leads out of the worktree");
910
+ continue;
911
+ }
912
+ try {
913
+ mkdirSync(path.dirname(to), { recursive: true });
914
+ cpSync(from, to, {
915
+ recursive: true,
916
+ filter: (item) => !lstatSync(item).isSymbolicLink()
917
+ });
918
+ carried.push(entry);
919
+ } catch (error) {
920
+ skip(`the copy failed: ${error.message}`);
921
+ }
922
+ }
923
+ return { carried, problems };
924
+ }
925
+ function isLink(file) {
926
+ try {
927
+ return lstatSync(file).isSymbolicLink();
928
+ } catch {
929
+ return false;
930
+ }
931
+ }
932
+ function retiredReposConfigNotice(file) {
933
+ if (!existsSync(file)) return void 0;
934
+ return `${file} is no longer read: nothing is carried into worktrees unless a repository lists it under "carry" in its own ${REPO_FILE}`;
935
+ }
703
936
  const DEFAULT_ALIVE_INTERVAL_MS = 15e3;
704
937
  const DEFAULT_POLL_BACKOFF_INITIAL_MS = 5e3;
705
938
  const DEFAULT_POLL_BACKOFF_MAX_MS = 5 * 6e4;
@@ -988,7 +1221,7 @@ function linkPaths(hostDirectory) {
988
1221
  work: path.join(state, "work"),
989
1222
  scratch: path.join(state, "scratch"),
990
1223
  bin: path.join(state, "bin"),
991
- reposConfig: path.join(state, "repos.json"),
1224
+ retiredReposConfig: path.join(state, "repos.json"),
992
1225
  config: path.join(state, "config.json"),
993
1226
  access: path.join(hostDirectory, "access.json")
994
1227
  };
@@ -998,6 +1231,11 @@ function configuredSlots(paths) {
998
1231
  const slots = value?.slots;
999
1232
  return typeof slots === "number" && Number.isInteger(slots) && slots >= 0 && slots <= 64 ? slots : DEFAULT_SLOTS;
1000
1233
  }
1234
+ function isThreadDirectory(paths, directory) {
1235
+ const resolved = path.resolve(directory);
1236
+ const parent = path.dirname(resolved);
1237
+ return path.basename(resolved) !== "" && (parent === path.resolve(paths.work) || parent === path.resolve(paths.scratch));
1238
+ }
1001
1239
  const HARNESS_COMMANDS = {
1002
1240
  claude: "claude",
1003
1241
  codex: "codex",
@@ -1098,80 +1336,6 @@ function buildHeartbeat(input) {
1098
1336
  if (input.diagnostics) heartbeat.diagnostics = input.diagnostics;
1099
1337
  return heartbeat;
1100
1338
  }
1101
- const GITHUB_HOST = "github.com";
1102
- const REPO_SCAN_MS = 6e4;
1103
- const GITHUB_REMOTE = [
1104
- /^https:\/\/(?:[^@/]+@)?github\.com\/([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/u,
1105
- /^(?:ssh:\/\/)?git@github\.com[:/]([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/u
1106
- ];
1107
- function parseGitHubRemote(url) {
1108
- for (const pattern of GITHUB_REMOTE) {
1109
- const match = pattern.exec(url.trim());
1110
- if (match?.[1] && match[2]) return { owner: match[1], name: match[2] };
1111
- }
1112
- return void 0;
1113
- }
1114
- function git(cwd, args, environment) {
1115
- return new Promise((resolve) => {
1116
- execFile(
1117
- "git",
1118
- ["-C", cwd, ...args],
1119
- environment ? { env: { ...process.env, ...environment } } : {},
1120
- (failure, stdout, stderr) => resolve({
1121
- ok: failure === null,
1122
- stdout: stdout.trim(),
1123
- stderr: stderr.trim()
1124
- })
1125
- );
1126
- });
1127
- }
1128
- function directories(parent) {
1129
- try {
1130
- return readdirSync(parent, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map((entry) => entry.name).toSorted();
1131
- } catch {
1132
- return [];
1133
- }
1134
- }
1135
- async function scanRepos(reposDirectory) {
1136
- const github = path.join(reposDirectory, GITHUB_HOST);
1137
- const candidates = directories(github).flatMap(
1138
- (owner) => directories(path.join(github, owner)).map((name) => path.join(github, owner, name)).filter((directory) => existsSync(path.join(directory, ".git")))
1139
- );
1140
- const found = await Promise.all(
1141
- candidates.map(async (directory) => {
1142
- const origin = await git(directory, [
1143
- "config",
1144
- "--get",
1145
- "remote.origin.url"
1146
- ]);
1147
- const repo = origin.ok ? parseGitHubRemote(origin.stdout) : void 0;
1148
- return repo ? { repo, path: directory } : void 0;
1149
- })
1150
- );
1151
- return found.filter((checkout) => checkout !== void 0);
1152
- }
1153
- class Repos {
1154
- constructor(reposDirectory, now = Date.now) {
1155
- this.reposDirectory = reposDirectory;
1156
- this.now = now;
1157
- }
1158
- scanned = [];
1159
- scannedAt = Number.NEGATIVE_INFINITY;
1160
- async list(options = {}) {
1161
- if (options.fresh || this.now() - this.scannedAt >= REPO_SCAN_MS) {
1162
- this.scanned = await scanRepos(this.reposDirectory);
1163
- this.scannedAt = this.now();
1164
- }
1165
- return this.scanned;
1166
- }
1167
- /** The checkout for a repository, rescanning once when it is not known. */
1168
- async find(repo) {
1169
- const match = (checkouts) => checkouts.find(
1170
- (checkout) => checkout.repo.owner.toLowerCase() === repo.owner.toLowerCase() && checkout.repo.name.toLowerCase() === repo.name.toLowerCase()
1171
- );
1172
- return match(await this.list()) ?? match(await this.list({ fresh: true }));
1173
- }
1174
- }
1175
1339
  const THREAD_ID$1 = /^t_[A-Za-z0-9]{8,64}$/u;
1176
1340
  function prepareScratch(scratch, threadId) {
1177
1341
  if (!THREAD_ID$1.test(threadId))
@@ -1224,15 +1388,6 @@ function removeScratch(scratch, threadId) {
1224
1388
  if (!THREAD_ID$1.test(threadId)) return;
1225
1389
  rmSync(path.join(scratch, threadId), { recursive: true, force: true });
1226
1390
  }
1227
- const DEFAULT_CARRY = [".mcp.json", ".claude/settings.local.json"];
1228
- function carryList(reposConfig) {
1229
- const value = readJson(reposConfig);
1230
- const carry = value?.carry;
1231
- if (!Array.isArray(carry)) return DEFAULT_CARRY;
1232
- return carry.filter(
1233
- (entry) => typeof entry === "string" && entry !== "" && !path.isAbsolute(entry) && !entry.split(/[/\\]/u).includes("..")
1234
- );
1235
- }
1236
1391
  function salvageReference(threadId) {
1237
1392
  return `refs/aibex/salvage/${threadId}`;
1238
1393
  }
@@ -1326,26 +1481,12 @@ async function prepareWorktree(options) {
1326
1481
  };
1327
1482
  }
1328
1483
  }
1329
- const carried = [];
1330
- for (const file of carryList(options.reposConfig)) {
1331
- const from = path.join(checkout, file);
1332
- const to = path.join(worktreePath, file);
1333
- if (!existsSync(from) || existsSync(to)) continue;
1334
- const tracked = await git(checkout, [
1335
- "ls-files",
1336
- "--error-unmatch",
1337
- "--",
1338
- file
1339
- ]);
1340
- if (tracked.ok) continue;
1341
- mkdirSync(path.dirname(to), { recursive: true });
1342
- cpSync(from, to, { recursive: true });
1343
- carried.push(file);
1344
- }
1484
+ const { carried, problems } = await carryInto(checkout, worktreePath);
1345
1485
  return {
1346
1486
  ok: true,
1347
1487
  worktree: { path: worktreePath, branch, base },
1348
1488
  carried,
1489
+ carryProblems: problems,
1349
1490
  ...restored === void 0 ? {} : { restored }
1350
1491
  };
1351
1492
  }
@@ -1411,8 +1552,7 @@ async function isDirty(worktree, carry) {
1411
1552
  }
1412
1553
  return false;
1413
1554
  }
1414
- async function scanWorktrees(work, reposConfig) {
1415
- const carry = carryList(reposConfig);
1555
+ async function scanWorktrees(work) {
1416
1556
  const listings = [];
1417
1557
  for (const threadId of threadDirectories(work)) {
1418
1558
  const directory = path.join(work, threadId);
@@ -1432,7 +1572,7 @@ async function scanWorktrees(work, reposConfig) {
1432
1572
  const head = await git(directory, ["rev-parse", "--verify", "HEAD"]);
1433
1573
  if (head.ok && /^[0-9a-f]{40}$/u.test(head.stdout)) {
1434
1574
  listing.head = head.stdout;
1435
- listing.dirty = await isDirty(directory, carry);
1575
+ listing.dirty = await isDirty(directory, carryList(directory).carry);
1436
1576
  listing.unpushed = await hasUnpushed(directory);
1437
1577
  }
1438
1578
  }
@@ -1545,7 +1685,7 @@ async function releaseWorktree(options) {
1545
1685
  };
1546
1686
  }
1547
1687
  const reference = salvageReference(threadId);
1548
- const carry = carryList(options.reposConfig);
1688
+ const carry = carryList(worktree).carry;
1549
1689
  const dirty = await isDirty(worktree, carry);
1550
1690
  const unpushed = await hasUnpushed(worktree);
1551
1691
  let salvage;
@@ -1711,7 +1851,7 @@ class Reaper {
1711
1851
  const now = this.now();
1712
1852
  if (now - this.scannedAt >= (this.options.scanMs ?? WORKTREE_SCAN_MS)) {
1713
1853
  this.listing = [
1714
- ...await scanWorktrees(this.options.work, this.options.reposConfig),
1854
+ ...await scanWorktrees(this.options.work),
1715
1855
  ...scanScratch(this.options.scratch)
1716
1856
  ];
1717
1857
  this.scannedAt = now;
@@ -1743,7 +1883,6 @@ class Reaper {
1743
1883
  work: this.options.work,
1744
1884
  threadId: command.thread_id,
1745
1885
  epoch: command.epoch,
1746
- reposConfig: this.options.reposConfig,
1747
1886
  checkouts: await this.options.checkouts(),
1748
1887
  sessionListed
1749
1888
  });
@@ -2524,6 +2663,7 @@ class Relay {
2524
2663
  for (const message of queued) event(message);
2525
2664
  }
2526
2665
  }
2666
+ const CLAUDE_TRUST = /^\s*❯ No, exit\s*\n\s*Yes, I trust this folder\s*$/mu;
2527
2667
  const HARNESSES = {
2528
2668
  // The input box: a full-width rule, then `❯` and the placeholder. The
2529
2669
  // folder trust dialog also starts a line with `❯`, but never under a rule.
@@ -2532,7 +2672,21 @@ const HARNESSES = {
2532
2672
  command: "claude",
2533
2673
  args: [],
2534
2674
  ready: /─{20,}\n❯(?:[ \u00A0]|$)/mu,
2535
- multiline: "paste"
2675
+ multiline: "paste",
2676
+ // Claude Code has no flag for an interactive session's folder trust, so
2677
+ // the link answers the dialog. The marker pins the order (`No, exit`
2678
+ // selected, `Yes, I trust this folder` below it), so Down then Enter is
2679
+ // the yes; a dialog drawn any other way does not match and is left alone.
2680
+ trustDialog: { marker: CLAUDE_TRUST, keys: ["Down", "Enter"] },
2681
+ prompts: [
2682
+ // The first-run theme picker comes before the sign-in.
2683
+ {
2684
+ kind: "sign-in",
2685
+ marker: /Choose the text style that looks best with your terminal/u
2686
+ },
2687
+ { kind: "sign-in", marker: /Select login method:/u },
2688
+ { kind: "trust", marker: CLAUDE_TRUST }
2689
+ ]
2536
2690
  },
2537
2691
  // The composer line `› Ask Codex to do anything`. The update notice, the
2538
2692
  // folder trust dialog and sign-in all list numbered choices after `›`.
@@ -2541,16 +2695,50 @@ const HARNESSES = {
2541
2695
  // The update notice waits for a key, so a driven session skips it.
2542
2696
  args: ["-c", "check_for_update_on_startup=false"],
2543
2697
  ready: /^›(?: (?!\d+\. )|$)/mu,
2544
- multiline: "paste"
2698
+ multiline: "paste",
2699
+ // A `projects` table as a `-c` override marks the directory trusted for
2700
+ // this run only; codex writes nothing. The dotted form
2701
+ // (`projects."<dir>".trust_level`) does not take.
2702
+ trustArgs: (directories2) => [
2703
+ "-c",
2704
+ `projects={${directories2.map((directory) => `${tomlString(directory)}={trust_level="trusted"}`).join(",")}}`
2705
+ ],
2706
+ prompts: [
2707
+ { kind: "sign-in", marker: /Sign in with ChatGPT/u },
2708
+ // Only if check_for_update_on_startup=false stops working.
2709
+ { kind: "update", marker: /Update available ·/u },
2710
+ { kind: "trust", marker: /Trust this folder\?/u }
2711
+ ]
2545
2712
  },
2546
2713
  // The input box under a row of `▄`, with `→` and the placeholder.
2547
2714
  cursor: {
2548
2715
  command: "cursor-agent",
2549
2716
  args: [],
2550
2717
  ready: /▄{20,}\n\s*→/u,
2551
- multiline: "paste"
2718
+ multiline: "paste",
2719
+ // "Trust the current workspace without prompting".
2720
+ trustArgs: () => ["--trust"],
2721
+ prompts: [
2722
+ { kind: "sign-in", marker: /Press any key to log in/u },
2723
+ { kind: "trust", marker: /Workspace Trust Required/u }
2724
+ ]
2552
2725
  }
2553
2726
  };
2727
+ const PROMPT_NAMES = {
2728
+ "sign-in": "sign-in",
2729
+ update: "update",
2730
+ trust: "folder trust"
2731
+ };
2732
+ function notReadyStatus(harness, entry, screen) {
2733
+ const prompt = entry.prompts.find(({ marker }) => marker.test(screen));
2734
+ return prompt ? `${harness} is waiting at its ${PROMPT_NAMES[prompt.kind]} prompt; open the terminal` : "harness not ready";
2735
+ }
2736
+ function tomlString(text) {
2737
+ return JSON.stringify(text);
2738
+ }
2739
+ function harnessArguments(entry, directories2, threadDirectory) {
2740
+ return threadDirectory && entry.trustArgs ? [...entry.args, ...entry.trustArgs(directories2)] : [...entry.args];
2741
+ }
2554
2742
  const SETUP_PROGRAMS = {
2555
2743
  shell: void 0,
2556
2744
  claude: "claude",
@@ -3021,6 +3209,14 @@ const DEFAULT_SESSION_TIMINGS = {
3021
3209
  reattachMaxMs: 6e4
3022
3210
  };
3023
3211
  const STATUS_MAX = 200;
3212
+ function trustedPaths(directory) {
3213
+ try {
3214
+ const real = realpathSync(directory);
3215
+ return real === directory ? [directory] : [directory, real];
3216
+ } catch {
3217
+ return [directory];
3218
+ }
3219
+ }
3024
3220
  function newEventId() {
3025
3221
  return `e_${randomBytes(12).toString("base64url")}`;
3026
3222
  }
@@ -3294,13 +3490,20 @@ class Session {
3294
3490
  });
3295
3491
  if (!screen.ok) return;
3296
3492
  const quiet = this.quiet(screen.seq);
3297
- const ready = this.record.prompted || this.harness.ready.test(String(screen.text));
3493
+ const text = String(screen.text);
3494
+ const ready = this.record.prompted || this.harness.ready.test(text);
3495
+ if (quiet && !ready && await this.answerTrust(text)) return;
3298
3496
  if (!quiet || !ready) {
3299
3497
  if (this.phase === "launching" && !this.notReady && this.readySince !== void 0 && this.manager.now() - this.readySince >= this.timings.readyTimeoutMs) {
3300
3498
  this.notReady = true;
3301
- this.setStatus("harness not ready");
3499
+ const status = notReadyStatus(
3500
+ this.record.harness,
3501
+ this.harness,
3502
+ text
3503
+ );
3504
+ this.setStatus(status);
3302
3505
  this.manager.log.line(
3303
- `${this.record.thread_id}: ${this.record.harness} showed no ready marker in ${Math.round(this.timings.readyTimeoutMs / 1e3)}s; nothing typed`
3506
+ `${this.record.thread_id}: ${this.record.harness} showed no ready marker in ${Math.round(this.timings.readyTimeoutMs / 1e3)}s; nothing typed${status === "harness not ready" ? "" : ` (${status})`}`
3304
3507
  );
3305
3508
  }
3306
3509
  return;
@@ -3310,6 +3513,32 @@ class Session {
3310
3513
  this.sending = false;
3311
3514
  }
3312
3515
  }
3516
+ /**
3517
+ * Accepts the harness's folder trust dialog once, as a person would, when
3518
+ * it is on screen and the session runs in a directory the link made for
3519
+ * the thread. Answers whether it pressed the keys. A dialog that shows
3520
+ * again is left alone, so the ready timeout reports it.
3521
+ */
3522
+ async answerTrust(text) {
3523
+ const dialog = this.harness.trustDialog;
3524
+ const client = this.client;
3525
+ const directory = this.record.worktree?.path ?? this.record.scratch;
3526
+ if (!dialog || !client || this.phase !== "launching" || this.record.trust_answered || directory === void 0 || !this.manager.isThreadDirectory(directory) || !dialog.marker.test(text)) {
3527
+ return false;
3528
+ }
3529
+ const pressed = await client.request({
3530
+ type: "press",
3531
+ terminal: this.record.terminal,
3532
+ keys: dialog.keys
3533
+ });
3534
+ if (!pressed.ok || !this.live(client)) return true;
3535
+ this.record.trust_answered = true;
3536
+ this.save();
3537
+ this.manager.log.line(
3538
+ `${this.record.thread_id}: answered ${this.record.harness}'s folder trust for ${directory}`
3539
+ );
3540
+ return true;
3541
+ }
3313
3542
  /** Whether the session may still be typed into by this client. */
3314
3543
  live(client) {
3315
3544
  return this.client === client && (this.phase === "launching" || this.phase === "running");
@@ -3543,6 +3772,10 @@ class Sessions {
3543
3772
  now() {
3544
3773
  return (this.options.now ?? Date.now)();
3545
3774
  }
3775
+ /** Whether `directory` is a thread directory under `<state>/work/` or `<state>/scratch/`. */
3776
+ isThreadDirectory(directory) {
3777
+ return isThreadDirectory(this.options.paths, directory);
3778
+ }
3546
3779
  spoolFile(threadId) {
3547
3780
  return path.join(this.directory, `${threadId}.spool`);
3548
3781
  }
@@ -3721,8 +3954,7 @@ class Sessions {
3721
3954
  checkout: checkout.path,
3722
3955
  workDirectory: this.options.paths.work,
3723
3956
  threadId: record.thread_id,
3724
- baseRef: request.base_ref,
3725
- reposConfig: this.options.paths.reposConfig
3957
+ baseRef: request.base_ref
3726
3958
  });
3727
3959
  if (stale()) return;
3728
3960
  if (!prepared.ok) {
@@ -3731,6 +3963,14 @@ class Sessions {
3731
3963
  }
3732
3964
  record.worktree = prepared.worktree;
3733
3965
  directory = prepared.worktree.path;
3966
+ if (prepared.carried.length > 0) {
3967
+ this.options.log.line(
3968
+ `${record.thread_id}: carried ${prepared.carried.join(", ")} from the checkout`
3969
+ );
3970
+ }
3971
+ for (const problem of prepared.carryProblems) {
3972
+ this.options.log.line(`${record.thread_id}: ${problem}`);
3973
+ }
3734
3974
  if (prepared.restored !== void 0) {
3735
3975
  this.options.log.line(
3736
3976
  `${record.thread_id}: rebuilt its worktree from salvaged work (${prepared.restored})`
@@ -3771,7 +4011,12 @@ class Sessions {
3771
4011
  const created = await client.request({
3772
4012
  type: "create",
3773
4013
  file: resolveProgram(entry.command, searchPath),
3774
- args: entry.args,
4014
+ // Trusting is implicit in a directory the link made for the thread.
4015
+ args: harnessArguments(
4016
+ entry,
4017
+ trustedPaths(directory),
4018
+ this.isThreadDirectory(directory)
4019
+ ),
3775
4020
  cwd: directory,
3776
4021
  env: {
3777
4022
  PATH: searchPath,
@@ -4113,6 +4358,8 @@ function main() {
4113
4358
  const access = new Access(paths.access);
4114
4359
  const repos = new Repos(paths.repos);
4115
4360
  rmSync(path.join(hostDirectory, "activations.json"), { force: true });
4361
+ const retired = retiredReposConfigNotice(paths.retiredReposConfig);
4362
+ if (retired !== void 0) log.line(retired);
4116
4363
  const terminalSocket = process.env.AIBEX_TERMINAL_SOCKET;
4117
4364
  const terminalsDirectory = process.env.AIBEX_TERMINALS_DIR;
4118
4365
  let poller;
@@ -4156,7 +4403,6 @@ function main() {
4156
4403
  reaper = new Reaper({
4157
4404
  work: paths.work,
4158
4405
  scratch: paths.scratch,
4159
- reposConfig: paths.reposConfig,
4160
4406
  checkouts: async () => {
4161
4407
  const checkouts = await repos.list();
4162
4408
  return checkouts.map((checkout) => checkout.path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aibexhq/aibex-link",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "The process aibexd runs to link a machine to an Aibex herd",
5
5
  "homepage": "https://github.com/aibexhq",
6
6
  "bugs": {