@aibexhq/aibex-link 0.0.10 → 0.0.11
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 +207 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1051,6 +1051,23 @@ async function collectReport(options) {
|
|
|
1051
1051
|
}
|
|
1052
1052
|
return report;
|
|
1053
1053
|
}
|
|
1054
|
+
function parseLinkHealth(value) {
|
|
1055
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
1056
|
+
const { failures, rolled_back: rolledBack } = value;
|
|
1057
|
+
if (typeof failures !== "number" || !Number.isInteger(failures) || failures < 0) {
|
|
1058
|
+
return void 0;
|
|
1059
|
+
}
|
|
1060
|
+
if (rolledBack === void 0) return { failures };
|
|
1061
|
+
if (typeof rolledBack !== "object" || rolledBack === null) return void 0;
|
|
1062
|
+
const { from, to, at, reason } = rolledBack;
|
|
1063
|
+
if (typeof from !== "string" || typeof to !== "string" || typeof at !== "string" || !Number.isFinite(Date.parse(at)) || typeof reason !== "string") {
|
|
1064
|
+
return void 0;
|
|
1065
|
+
}
|
|
1066
|
+
return {
|
|
1067
|
+
failures,
|
|
1068
|
+
rolled_back: { from, to, at, reason: reason.slice(0, 500) }
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1054
1071
|
function buildHeartbeat(input) {
|
|
1055
1072
|
const machine = describeMachine();
|
|
1056
1073
|
const heartbeat = {
|
|
@@ -1075,6 +1092,7 @@ function buildHeartbeat(input) {
|
|
|
1075
1092
|
if (setup_terminals) heartbeat.setup_terminals = setup_terminals;
|
|
1076
1093
|
if (worktrees) heartbeat.worktrees = worktrees;
|
|
1077
1094
|
if (releases) heartbeat.releases = releases;
|
|
1095
|
+
if (input.linkHealth) heartbeat.link_health = input.linkHealth;
|
|
1078
1096
|
if (input.diagnostics) heartbeat.diagnostics = input.diagnostics;
|
|
1079
1097
|
return heartbeat;
|
|
1080
1098
|
}
|
|
@@ -1844,6 +1862,7 @@ class Poller {
|
|
|
1844
1862
|
linkVersion: this.options.linkVersion,
|
|
1845
1863
|
aibexdVersion: status.aibexdVersion,
|
|
1846
1864
|
selfUpdate: status.selfUpdate,
|
|
1865
|
+
linkHealth: status.linkHealth,
|
|
1847
1866
|
harnesses: typeof this.options.harnesses === "function" ? this.options.harnesses() : this.options.harnesses,
|
|
1848
1867
|
acks,
|
|
1849
1868
|
diagnostics,
|
|
@@ -2437,10 +2456,11 @@ class Relay {
|
|
|
2437
2456
|
const HARNESSES = {
|
|
2438
2457
|
// The input box: a full-width rule, then `❯` and the placeholder. The
|
|
2439
2458
|
// folder trust dialog also starts a line with `❯`, but never under a rule.
|
|
2459
|
+
// Claude Code 2.1.3xx puts a no-break space after `❯`.
|
|
2440
2460
|
claude: {
|
|
2441
2461
|
command: "claude",
|
|
2442
2462
|
args: [],
|
|
2443
|
-
ready: /─{20,}\n❯(?: |$)/mu,
|
|
2463
|
+
ready: /─{20,}\n❯(?:[ \u00A0]|$)/mu,
|
|
2444
2464
|
multiline: "paste"
|
|
2445
2465
|
},
|
|
2446
2466
|
// The composer line `› Ask Codex to do anything`. The update notice, the
|
|
@@ -2512,6 +2532,142 @@ function reportedState(phase, hints) {
|
|
|
2512
2532
|
}
|
|
2513
2533
|
}
|
|
2514
2534
|
}
|
|
2535
|
+
const REPLY_MAX = 16 * 1024;
|
|
2536
|
+
const REPLY_TRUNCATED = "[… earlier output cut]\n";
|
|
2537
|
+
const REPLY_SCROLLBACK = 2e3;
|
|
2538
|
+
const ESCAPES = (
|
|
2539
|
+
// eslint-disable-next-line no-control-regex
|
|
2540
|
+
/\u001B\[[0-?]*[ -/]*[@-~]|\u001B\][^\u0007\u001B]*(?:\u0007|\u001B\\)|\u001B[@-Z\\-_]|[\u0000-\u0008\u000B-\u001F\u007F]/gu
|
|
2541
|
+
);
|
|
2542
|
+
const DRAWING = "─━═│┃║╭╮╰╯┌┐└┘├┤┬┴┼╔╗╚╝╠╣╦╩╬┄┅┈┉╌╍▀▄█▌▐▔▁░▒▓■▪";
|
|
2543
|
+
const DRAWING_ONLY = new RegExp(
|
|
2544
|
+
String.raw`^[\s${DRAWING}\-_=~]*[${DRAWING}][\s${DRAWING}\-_=~]*$`,
|
|
2545
|
+
"u"
|
|
2546
|
+
);
|
|
2547
|
+
const LABELLED_RULE = /^\s*[─━═]{2,}.*[─━═]{3,}\s*$/u;
|
|
2548
|
+
const BOX_SIDES = /^\s*[│┃║]\s?(.*?)\s*[│┃║]\s*$/u;
|
|
2549
|
+
const GUTTER = /^(\s*)([⏺●⎿│┃›❯>→▶•])(?: |$)/u;
|
|
2550
|
+
const CHROME = [
|
|
2551
|
+
/\b(?:esc|ctrl\+c) to (?:interrupt|cancel|stop)\b/iu,
|
|
2552
|
+
/^\s*[⠀-⣿]/u,
|
|
2553
|
+
/^\s*[✻✶✳✢✽✺✹✸✷◐◓◑◒◴◷◶◵]\s/u,
|
|
2554
|
+
/^\s*[·∗*]\s+\S+(?:…|\.\.\.)/u,
|
|
2555
|
+
/\?\s+for shortcuts/iu,
|
|
2556
|
+
/\bshift\+tab to\b/iu,
|
|
2557
|
+
/^\s*⏵⏵/u,
|
|
2558
|
+
/^\s*\d{1,2}:\d{2}(?::\d{2})?\s?(?:[AP]M)?\s*$/iu
|
|
2559
|
+
];
|
|
2560
|
+
const INFORMATION_OPEN = "<aibexd-information>";
|
|
2561
|
+
const INFORMATION_CLOSE = "</aibexd-information>";
|
|
2562
|
+
function stripEscapes(text) {
|
|
2563
|
+
return text.replaceAll(ESCAPES, "").replaceAll(" ", " ");
|
|
2564
|
+
}
|
|
2565
|
+
function withoutGutter(line) {
|
|
2566
|
+
const match = GUTTER.exec(line);
|
|
2567
|
+
const indent = match?.[1] ?? "";
|
|
2568
|
+
if (!match || match[2] === "•" && indent !== "") return line;
|
|
2569
|
+
return indent + " ".repeat(match[0].length - indent.length) + line.slice(match[0].length);
|
|
2570
|
+
}
|
|
2571
|
+
function normalize(text) {
|
|
2572
|
+
return text.split("\n").map((line) => withoutGutter(stripEscapes(line))).join(" ").replaceAll(/\s+/gu, " ").trim();
|
|
2573
|
+
}
|
|
2574
|
+
function undecorate(text) {
|
|
2575
|
+
const kept = [];
|
|
2576
|
+
let inInformation = false;
|
|
2577
|
+
for (const raw of stripEscapes(text).split("\n")) {
|
|
2578
|
+
let line = raw.trimEnd();
|
|
2579
|
+
const sides = BOX_SIDES.exec(line);
|
|
2580
|
+
if (sides) line = sides[1] ?? "";
|
|
2581
|
+
line = withoutGutter(line).trimEnd();
|
|
2582
|
+
const bare = line.trim();
|
|
2583
|
+
if (inInformation) {
|
|
2584
|
+
if (bare.includes(INFORMATION_CLOSE)) inInformation = false;
|
|
2585
|
+
continue;
|
|
2586
|
+
}
|
|
2587
|
+
if (bare.startsWith(INFORMATION_OPEN)) {
|
|
2588
|
+
inInformation = !bare.includes(INFORMATION_CLOSE);
|
|
2589
|
+
continue;
|
|
2590
|
+
}
|
|
2591
|
+
if (bare === "") {
|
|
2592
|
+
kept.push("");
|
|
2593
|
+
continue;
|
|
2594
|
+
}
|
|
2595
|
+
if (DRAWING_ONLY.test(bare) || LABELLED_RULE.test(bare)) continue;
|
|
2596
|
+
if (CHROME.some((pattern) => pattern.test(bare))) continue;
|
|
2597
|
+
kept.push(line);
|
|
2598
|
+
}
|
|
2599
|
+
const lines = [];
|
|
2600
|
+
for (const line of kept) {
|
|
2601
|
+
if (line === "" && (lines.length === 0 || lines.at(-1) === "")) continue;
|
|
2602
|
+
lines.push(line);
|
|
2603
|
+
}
|
|
2604
|
+
while (lines.at(-1) === "") lines.pop();
|
|
2605
|
+
const indents = lines.filter((line) => line !== "").map((line) => /^ */u.exec(line)?.[0].length ?? 0);
|
|
2606
|
+
const indent = indents.length > 0 ? Math.min(...indents) : 0;
|
|
2607
|
+
return lines.map((line) => line.slice(indent)).join("\n");
|
|
2608
|
+
}
|
|
2609
|
+
function inputStart(text, ready) {
|
|
2610
|
+
const flags = ready.flags.includes("g") ? ready.flags : `${ready.flags}g`;
|
|
2611
|
+
let last = -1;
|
|
2612
|
+
for (const match of text.matchAll(new RegExp(ready.source, flags))) {
|
|
2613
|
+
last = match.index;
|
|
2614
|
+
}
|
|
2615
|
+
if (last === -1) return text.length;
|
|
2616
|
+
return text.lastIndexOf("\n", last - 1) + 1;
|
|
2617
|
+
}
|
|
2618
|
+
const PROMPT_PREFIX = /^\S{0,12}[>›❯$%#:→] ?/u;
|
|
2619
|
+
function echoed(line, typed) {
|
|
2620
|
+
const prefix = PROMPT_PREFIX.exec(line);
|
|
2621
|
+
if (!prefix) return line;
|
|
2622
|
+
const rest = line.slice(prefix[0].length);
|
|
2623
|
+
const length = Math.min(rest.length, typed.length);
|
|
2624
|
+
return length > 0 && rest.slice(0, length) === typed.slice(0, length) ? rest : line;
|
|
2625
|
+
}
|
|
2626
|
+
function afterEcho(lines, sent) {
|
|
2627
|
+
const typed = normalize(sent);
|
|
2628
|
+
if (typed === "") return void 0;
|
|
2629
|
+
const shortest = Math.min(typed.length, 8);
|
|
2630
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
2631
|
+
const line = echoed(normalize(lines[index] ?? ""), typed);
|
|
2632
|
+
if (line.length < shortest) continue;
|
|
2633
|
+
const length = Math.min(line.length, typed.length);
|
|
2634
|
+
if (line.slice(0, length) !== typed.slice(0, length)) continue;
|
|
2635
|
+
if (typed.length < 8 && line !== typed) continue;
|
|
2636
|
+
let echo = line;
|
|
2637
|
+
let next = index + 1;
|
|
2638
|
+
while (next < lines.length && echo.length < typed.length) {
|
|
2639
|
+
const more = normalize(lines[next] ?? "");
|
|
2640
|
+
if (more === "") {
|
|
2641
|
+
next += 1;
|
|
2642
|
+
continue;
|
|
2643
|
+
}
|
|
2644
|
+
if (typed.startsWith(`${echo} ${more}`)) echo = `${echo} ${more}`;
|
|
2645
|
+
else if (typed.startsWith(`${echo}${more}`)) echo += more;
|
|
2646
|
+
else break;
|
|
2647
|
+
next += 1;
|
|
2648
|
+
}
|
|
2649
|
+
return next;
|
|
2650
|
+
}
|
|
2651
|
+
return void 0;
|
|
2652
|
+
}
|
|
2653
|
+
const PASTE_PLACEHOLDER = /\[Pasted[^\]]*\]/u;
|
|
2654
|
+
function extractReply(screen, options) {
|
|
2655
|
+
const text = stripEscapes(screen);
|
|
2656
|
+
const above = text.slice(0, inputStart(text, options.ready));
|
|
2657
|
+
const lines = above.split("\n");
|
|
2658
|
+
let start = afterEcho(lines, options.sent);
|
|
2659
|
+
if (start === void 0) {
|
|
2660
|
+
const placeholder = lines.findLastIndex(
|
|
2661
|
+
(line) => PASTE_PLACEHOLDER.test(line)
|
|
2662
|
+
);
|
|
2663
|
+
start = placeholder === -1 ? 0 : placeholder + 1;
|
|
2664
|
+
}
|
|
2665
|
+
const reply = undecorate(lines.slice(start).join("\n"));
|
|
2666
|
+
if (reply.length <= REPLY_MAX) return reply;
|
|
2667
|
+
const tail = reply.slice(reply.length - (REPLY_MAX - REPLY_TRUNCATED.length));
|
|
2668
|
+
const newline = tail.indexOf("\n");
|
|
2669
|
+
return `${REPLY_TRUNCATED}${newline === -1 ? tail : tail.slice(newline + 1)}`;
|
|
2670
|
+
}
|
|
2515
2671
|
const MAX_CHUNK_BYTES = 1024 * 1024;
|
|
2516
2672
|
class Transcript {
|
|
2517
2673
|
constructor(spoolFile, state) {
|
|
@@ -2839,7 +2995,11 @@ class Session {
|
|
|
2839
2995
|
}
|
|
2840
2996
|
case "idle": {
|
|
2841
2997
|
this.busy = false;
|
|
2998
|
+
const was = this.activity;
|
|
2842
2999
|
this.activity = "idle";
|
|
3000
|
+
if (was === "working" && this.phase === "running") {
|
|
3001
|
+
void this.captureReply();
|
|
3002
|
+
}
|
|
2843
3003
|
break;
|
|
2844
3004
|
}
|
|
2845
3005
|
case "title": {
|
|
@@ -2929,6 +3089,7 @@ class Session {
|
|
|
2929
3089
|
});
|
|
2930
3090
|
if (!pressed.ok || !this.live(client)) return;
|
|
2931
3091
|
this.record.queue.shift();
|
|
3092
|
+
this.record.last_sent = text;
|
|
2932
3093
|
const first = !this.record.prompted;
|
|
2933
3094
|
this.record.prompted = true;
|
|
2934
3095
|
this.lastSendAt = this.manager.now();
|
|
@@ -2940,6 +3101,38 @@ class Session {
|
|
|
2940
3101
|
`${this.record.thread_id}: ${first ? "typed the prompt" : "typed a follow-up"} into ${this.record.harness}`
|
|
2941
3102
|
);
|
|
2942
3103
|
}
|
|
3104
|
+
/**
|
|
3105
|
+
* On each move from working to idle: the screen below the last text typed
|
|
3106
|
+
* in, undecorated, as a `reply` event, unless it is empty or the same as
|
|
3107
|
+
* the last reply. A screen without the ready marker (a dialog) waits for
|
|
3108
|
+
* the next idle.
|
|
3109
|
+
*/
|
|
3110
|
+
async captureReply() {
|
|
3111
|
+
const client = this.client;
|
|
3112
|
+
const sent = this.record.last_sent;
|
|
3113
|
+
if (!client || sent === void 0 || this.fenced) return;
|
|
3114
|
+
const snapshot = await client.request({
|
|
3115
|
+
type: "snapshot",
|
|
3116
|
+
terminal: this.record.terminal,
|
|
3117
|
+
lines: REPLY_SCROLLBACK
|
|
3118
|
+
});
|
|
3119
|
+
if (!snapshot.ok || this.client !== client || this.phase !== "running" || this.record.last_sent !== sent || !this.harness.ready.test(String(snapshot.text))) {
|
|
3120
|
+
return;
|
|
3121
|
+
}
|
|
3122
|
+
const text = extractReply(String(snapshot.all ?? snapshot.text), {
|
|
3123
|
+
sent,
|
|
3124
|
+
ready: this.harness.ready
|
|
3125
|
+
});
|
|
3126
|
+
if (text === "") return;
|
|
3127
|
+
const hash = createHash("sha256").update(text).digest("base64url");
|
|
3128
|
+
if (hash === this.record.reply_hash) return;
|
|
3129
|
+
this.record.reply_hash = hash;
|
|
3130
|
+
this.manager.event(this, {
|
|
3131
|
+
type: "reply",
|
|
3132
|
+
text,
|
|
3133
|
+
...text.startsWith(REPLY_TRUNCATED) ? { truncated: true } : {}
|
|
3134
|
+
});
|
|
3135
|
+
}
|
|
2943
3136
|
/** A title becomes a `status` event, at most one per interval, the latest winning. */
|
|
2944
3137
|
setStatus(text) {
|
|
2945
3138
|
const status = text.trim().slice(0, STATUS_MAX);
|
|
@@ -3750,6 +3943,13 @@ function initialSelfUpdate() {
|
|
|
3750
3943
|
}
|
|
3751
3944
|
return { can: true, reason: null };
|
|
3752
3945
|
}
|
|
3946
|
+
function initialLinkHealth() {
|
|
3947
|
+
try {
|
|
3948
|
+
return parseLinkHealth(JSON.parse(process.env.AIBEX_LINK_HEALTH ?? ""));
|
|
3949
|
+
} catch {
|
|
3950
|
+
return void 0;
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3753
3953
|
function main() {
|
|
3754
3954
|
const info = readPackageInfo();
|
|
3755
3955
|
if (process.argv.includes("--self-test")) {
|
|
@@ -3772,7 +3972,8 @@ function main() {
|
|
|
3772
3972
|
let status = {
|
|
3773
3973
|
type: "status",
|
|
3774
3974
|
aibexdVersion: process.env.AIBEX_AIBEXD_VERSION ?? "unknown",
|
|
3775
|
-
selfUpdate: initialSelfUpdate()
|
|
3975
|
+
selfUpdate: initialSelfUpdate(),
|
|
3976
|
+
linkHealth: initialLinkHealth()
|
|
3776
3977
|
};
|
|
3777
3978
|
const identity = readIdentity(hostDirectory);
|
|
3778
3979
|
const paths = linkPaths(hostDirectory);
|
|
@@ -3903,7 +4104,10 @@ function main() {
|
|
|
3903
4104
|
process.on("message", (message) => {
|
|
3904
4105
|
switch (message.type) {
|
|
3905
4106
|
case "status": {
|
|
3906
|
-
status =
|
|
4107
|
+
status = {
|
|
4108
|
+
...message,
|
|
4109
|
+
linkHealth: parseLinkHealth(message.linkHealth) ?? status.linkHealth
|
|
4110
|
+
};
|
|
3907
4111
|
break;
|
|
3908
4112
|
}
|
|
3909
4113
|
case "diagnostics": {
|