@aibexhq/aibex-link 0.0.13 → 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.
- package/dist/index.js +111 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1231,6 +1231,11 @@ function configuredSlots(paths) {
|
|
|
1231
1231
|
const slots = value?.slots;
|
|
1232
1232
|
return typeof slots === "number" && Number.isInteger(slots) && slots >= 0 && slots <= 64 ? slots : DEFAULT_SLOTS;
|
|
1233
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
|
+
}
|
|
1234
1239
|
const HARNESS_COMMANDS = {
|
|
1235
1240
|
claude: "claude",
|
|
1236
1241
|
codex: "codex",
|
|
@@ -2658,6 +2663,7 @@ class Relay {
|
|
|
2658
2663
|
for (const message of queued) event(message);
|
|
2659
2664
|
}
|
|
2660
2665
|
}
|
|
2666
|
+
const CLAUDE_TRUST = /^\s*❯ No, exit\s*\n\s*Yes, I trust this folder\s*$/mu;
|
|
2661
2667
|
const HARNESSES = {
|
|
2662
2668
|
// The input box: a full-width rule, then `❯` and the placeholder. The
|
|
2663
2669
|
// folder trust dialog also starts a line with `❯`, but never under a rule.
|
|
@@ -2666,7 +2672,21 @@ const HARNESSES = {
|
|
|
2666
2672
|
command: "claude",
|
|
2667
2673
|
args: [],
|
|
2668
2674
|
ready: /─{20,}\n❯(?:[ \u00A0]|$)/mu,
|
|
2669
|
-
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
|
+
]
|
|
2670
2690
|
},
|
|
2671
2691
|
// The composer line `› Ask Codex to do anything`. The update notice, the
|
|
2672
2692
|
// folder trust dialog and sign-in all list numbered choices after `›`.
|
|
@@ -2675,16 +2695,50 @@ const HARNESSES = {
|
|
|
2675
2695
|
// The update notice waits for a key, so a driven session skips it.
|
|
2676
2696
|
args: ["-c", "check_for_update_on_startup=false"],
|
|
2677
2697
|
ready: /^›(?: (?!\d+\. )|$)/mu,
|
|
2678
|
-
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
|
+
]
|
|
2679
2712
|
},
|
|
2680
2713
|
// The input box under a row of `▄`, with `→` and the placeholder.
|
|
2681
2714
|
cursor: {
|
|
2682
2715
|
command: "cursor-agent",
|
|
2683
2716
|
args: [],
|
|
2684
2717
|
ready: /▄{20,}\n\s*→/u,
|
|
2685
|
-
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
|
+
]
|
|
2686
2725
|
}
|
|
2687
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
|
+
}
|
|
2688
2742
|
const SETUP_PROGRAMS = {
|
|
2689
2743
|
shell: void 0,
|
|
2690
2744
|
claude: "claude",
|
|
@@ -3155,6 +3209,14 @@ const DEFAULT_SESSION_TIMINGS = {
|
|
|
3155
3209
|
reattachMaxMs: 6e4
|
|
3156
3210
|
};
|
|
3157
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
|
+
}
|
|
3158
3220
|
function newEventId() {
|
|
3159
3221
|
return `e_${randomBytes(12).toString("base64url")}`;
|
|
3160
3222
|
}
|
|
@@ -3428,13 +3490,20 @@ class Session {
|
|
|
3428
3490
|
});
|
|
3429
3491
|
if (!screen.ok) return;
|
|
3430
3492
|
const quiet = this.quiet(screen.seq);
|
|
3431
|
-
const
|
|
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;
|
|
3432
3496
|
if (!quiet || !ready) {
|
|
3433
3497
|
if (this.phase === "launching" && !this.notReady && this.readySince !== void 0 && this.manager.now() - this.readySince >= this.timings.readyTimeoutMs) {
|
|
3434
3498
|
this.notReady = true;
|
|
3435
|
-
|
|
3499
|
+
const status = notReadyStatus(
|
|
3500
|
+
this.record.harness,
|
|
3501
|
+
this.harness,
|
|
3502
|
+
text
|
|
3503
|
+
);
|
|
3504
|
+
this.setStatus(status);
|
|
3436
3505
|
this.manager.log.line(
|
|
3437
|
-
`${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})`}`
|
|
3438
3507
|
);
|
|
3439
3508
|
}
|
|
3440
3509
|
return;
|
|
@@ -3444,6 +3513,32 @@ class Session {
|
|
|
3444
3513
|
this.sending = false;
|
|
3445
3514
|
}
|
|
3446
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
|
+
}
|
|
3447
3542
|
/** Whether the session may still be typed into by this client. */
|
|
3448
3543
|
live(client) {
|
|
3449
3544
|
return this.client === client && (this.phase === "launching" || this.phase === "running");
|
|
@@ -3677,6 +3772,10 @@ class Sessions {
|
|
|
3677
3772
|
now() {
|
|
3678
3773
|
return (this.options.now ?? Date.now)();
|
|
3679
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
|
+
}
|
|
3680
3779
|
spoolFile(threadId) {
|
|
3681
3780
|
return path.join(this.directory, `${threadId}.spool`);
|
|
3682
3781
|
}
|
|
@@ -3912,7 +4011,12 @@ class Sessions {
|
|
|
3912
4011
|
const created = await client.request({
|
|
3913
4012
|
type: "create",
|
|
3914
4013
|
file: resolveProgram(entry.command, searchPath),
|
|
3915
|
-
|
|
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
|
+
),
|
|
3916
4020
|
cwd: directory,
|
|
3917
4021
|
env: {
|
|
3918
4022
|
PATH: searchPath,
|