ai-battery 0.2.0 → 0.2.2
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/README.md +30 -14
- package/bin/ai-battery-macos-rail.applescript +227 -0
- package/bin/ai-battery-macos-status.applescript +5 -12
- package/bin/ai-battery-run +701 -31
- package/bin/ai-battery-tmux.js +17 -0
- package/bin/terminal-compositor.js +111 -0
- package/docs/REFERENCE.md +23 -3
- package/docs/RELEASING.md +30 -7
- package/docs/WINDOWS-TERMINAL-SHARED-BAR.md +74 -0
- package/docs/hud-preview.svg +75 -20
- package/docs/terminal-vertical-preview.svg +73 -0
- package/lib/cli.js +1148 -240
- package/lib/core/atomic-rename.js +18 -0
- package/lib/core/cli-help.js +57 -12
- package/lib/core/cli-messages.js +45 -1
- package/lib/core/cli-output.js +277 -72
- package/lib/core/cli-wrappers.js +410 -0
- package/lib/core/config-editor.js +194 -29
- package/lib/core/display-config.js +45 -0
- package/lib/core/integration-files.js +32 -3
- package/lib/core/shared-bar.js +603 -0
- package/lib/core/statusline-git.js +179 -15
- package/lib/core/terminal.js +25 -7
- package/lib/core/tmux-status.js +172 -0
- package/lib/core/uninstall.js +20 -7
- package/lib/core/usage-store.js +85 -0
- package/lib/hud/launcher.js +32 -33
- package/lib/platforms/linux/gnome-extension/extension.js +7 -6
- package/lib/platforms/linux/hud.js +157 -42
- package/lib/platforms/linux/panel.js +16 -3
- package/lib/platforms/linux/rail.js +412 -0
- package/lib/platforms/macos/hud.js +152 -44
- package/lib/platforms/process-scanner.js +77 -29
- package/lib/platforms/windows/autostart-cleanup.js +1 -1
- package/lib/platforms/windows/codex-runner.js +178 -21
- package/lib/platforms/windows/hud/controls.ps1 +65 -15
- package/lib/platforms/windows/hud/main.ps1 +715 -54
- package/lib/platforms/windows/hud/rendering.ps1 +1284 -2
- package/lib/platforms/windows/hud/snapshot.ps1 +26 -46
- package/lib/platforms/windows/hud-launcher.js +234 -81
- package/lib/platforms/windows/shared-bar-platform.js +972 -0
- package/lib/platforms/windows/terminal-compositor.js +210 -25
- package/lib/platforms/windows/wt-bar.js +729 -0
- package/lib/platforms/windows/wt-fragment.js +665 -0
- package/lib/platforms/windows/wt-keybinding.js +300 -0
- package/lib/providers/antigravity.js +155 -8
- package/package.json +6 -2
- package/vendor/PaneContext.cs +875 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { cleanupPaneAiSession, isPaneSharedBarActive, paneUsageDecision, readConfiguredBarPosition, readConfiguredSidebarWidth } from "./shared-bar-platform.js";
|
|
3
4
|
import { spawn, spawnSync } from "node:child_process";
|
|
4
5
|
import fs from "node:fs";
|
|
5
6
|
import os from "node:os";
|
|
@@ -118,7 +119,7 @@ function inferProvider(command) {
|
|
|
118
119
|
const names = command.map((part) => path.basename(part).toLowerCase());
|
|
119
120
|
if (names.some((name) => name.includes("codex")) || joined.includes("@openai/codex")) return "codex";
|
|
120
121
|
if (names.some((name) => name.includes("claude")) || joined.includes("@anthropic-ai/claude-code")) return "claude";
|
|
121
|
-
if (names.some(name => /^(?:
|
|
122
|
+
if (names.some(name => /^agy(?:\.(?:exe|cmd|js|mjs|cjs))?$/.test(name))) return "antigravity";
|
|
122
123
|
return "all";
|
|
123
124
|
}
|
|
124
125
|
|
|
@@ -385,6 +386,9 @@ class StatusLine {
|
|
|
385
386
|
this.lastReading = "";
|
|
386
387
|
this.fetchFailures = 0;
|
|
387
388
|
this.command = options.command;
|
|
389
|
+
this.maxWidthOverride = Number.isFinite(Number(options.maxWidth)) && Number(options.maxWidth) > 0
|
|
390
|
+
? Math.floor(Number(options.maxWidth))
|
|
391
|
+
: null;
|
|
388
392
|
this.fetchTimeoutMs = options.fetchTimeoutMs ?? statusCommandTimeoutMs();
|
|
389
393
|
this.onRefresh = null;
|
|
390
394
|
this.resize();
|
|
@@ -416,7 +420,7 @@ class StatusLine {
|
|
|
416
420
|
clearTimeout(this.retryTimer);
|
|
417
421
|
this.retryTimer = null;
|
|
418
422
|
this.nextFetch = now + (this.args.interval * 1000);
|
|
419
|
-
const maxWidth = Math.max(20, this.cols - columnGuard());
|
|
423
|
+
const maxWidth = this.maxWidthOverride ?? Math.max(20, this.cols - columnGuard());
|
|
420
424
|
const command = this.command ?? batteryCommand(this.args, this.activeProvider, maxWidth);
|
|
421
425
|
const child = spawn(command[0], command.slice(1), {
|
|
422
426
|
stdio: ["ignore", "pipe", "ignore"],
|
|
@@ -673,6 +677,66 @@ function compositorWindowsPty(release = os.release()) {
|
|
|
673
677
|
};
|
|
674
678
|
}
|
|
675
679
|
|
|
680
|
+
const BENIGN_PTY_ERROR_CODES = new Set([
|
|
681
|
+
"EPIPE",
|
|
682
|
+
"EOF",
|
|
683
|
+
"ECONNRESET",
|
|
684
|
+
"EIO",
|
|
685
|
+
"EBADF",
|
|
686
|
+
"ENOTCONN",
|
|
687
|
+
"ERR_STREAM_DESTROYED",
|
|
688
|
+
"ERR_STREAM_WRITE_AFTER_END"
|
|
689
|
+
]);
|
|
690
|
+
|
|
691
|
+
function isBenignPtyError(error) {
|
|
692
|
+
const code = String(error?.code || "").toUpperCase();
|
|
693
|
+
if (BENIGN_PTY_ERROR_CODES.has(code)) return true;
|
|
694
|
+
const message = String(error?.message || "");
|
|
695
|
+
return /\b(?:EPIPE|EOF|ECONNRESET|EIO|EBADF|write after end|stream was destroyed)\b/i.test(message);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function attachPtyErrorGuards(term) {
|
|
699
|
+
if (!term || typeof term !== "object") return;
|
|
700
|
+
const onSocketError = (stage) => (error) => {
|
|
701
|
+
if (isBenignPtyError(error)) {
|
|
702
|
+
debugLog(`pty:${stage}-closed`, { code: error?.code || "", message: error?.message || "" });
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
debugLog(`pty:${stage}-error`, { code: error?.code || "", message: error?.message || "" });
|
|
706
|
+
};
|
|
707
|
+
// node-pty's WindowsTerminal never attaches an 'error' listener to _agent.inSocket,
|
|
708
|
+
// so any write racing with child exit (e.g. a trailing VT reply or keypress) crashes
|
|
709
|
+
// Node.js with an unhandled 'error' event (write EPIPE).
|
|
710
|
+
const inSocket = term?._agent?.inSocket;
|
|
711
|
+
if (typeof inSocket?.on === "function") {
|
|
712
|
+
inSocket.on("error", onSocketError("in-socket"));
|
|
713
|
+
}
|
|
714
|
+
const outSocket = term?._agent?.outSocket || term?._socket;
|
|
715
|
+
if (outSocket && outSocket !== inSocket && typeof outSocket.on === "function") {
|
|
716
|
+
outSocket.on("error", onSocketError("out-socket"));
|
|
717
|
+
}
|
|
718
|
+
if (typeof term.on === "function") {
|
|
719
|
+
term.on("error", onSocketError("term"));
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
function safeWritePty(term, data, exited = false) {
|
|
724
|
+
if (!term || exited || !data) return false;
|
|
725
|
+
const inSocket = term?._agent?.inSocket;
|
|
726
|
+
if (inSocket && (inSocket.destroyed || inSocket.writableEnded || inSocket.writable === false)) {
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
try {
|
|
730
|
+
term.write(data);
|
|
731
|
+
return true;
|
|
732
|
+
} catch (error) {
|
|
733
|
+
if (!isBenignPtyError(error)) {
|
|
734
|
+
debugLog("pty:write-error", { code: error?.code || "", message: error?.message || "" });
|
|
735
|
+
}
|
|
736
|
+
return false;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
676
740
|
function configureWindowsPtyInput(term) {
|
|
677
741
|
// node-pty 1.1 opens ConPTY's input pipe as a net.Socket. A nonblocking
|
|
678
742
|
// Windows pipe write can return EAGAIN and destroy that socket. Match the
|
|
@@ -681,6 +745,7 @@ function configureWindowsPtyInput(term) {
|
|
|
681
745
|
if (typeof handle?.setBlocking !== "function") throw new Error("ConPTY input pipe cannot be configured safely");
|
|
682
746
|
const result = handle.setBlocking(true);
|
|
683
747
|
if (result !== 0) throw new Error(`ConPTY blocking input configuration failed: ${result}`);
|
|
748
|
+
attachPtyErrorGuards(term);
|
|
684
749
|
}
|
|
685
750
|
|
|
686
751
|
async function runFullscreenCompositor(args, activeProvider) {
|
|
@@ -700,12 +765,31 @@ async function runFullscreenCompositor(args, activeProvider) {
|
|
|
700
765
|
}
|
|
701
766
|
|
|
702
767
|
const size = termSize();
|
|
703
|
-
const
|
|
768
|
+
const initialDecision = paneUsageDecision(activeProvider || "codex", {
|
|
769
|
+
ownerPid: process.pid,
|
|
770
|
+
cols: size.cols,
|
|
771
|
+
rows: size.rows
|
|
772
|
+
});
|
|
773
|
+
const statusVisible = Boolean(initialDecision.showUsage) && !initialDecision.attaching;
|
|
774
|
+
const statusPosition = readConfiguredBarPosition(process.env);
|
|
775
|
+
const sidebarWidth = readConfiguredSidebarWidth(process.env);
|
|
776
|
+
const isSidePosition = statusPosition === "left" || statusPosition === "right";
|
|
777
|
+
const effectiveArgs = isSidePosition
|
|
778
|
+
? { ...args, barWidth: String(Math.max(4, Math.min(Number(args.barWidth) || 10, sidebarWidth - 6))) }
|
|
779
|
+
: args;
|
|
704
780
|
const childCommand = activeProvider === "codex"
|
|
705
781
|
? [...args.command, "-c", "tui.fullscreen_transcript=true"] : args.command;
|
|
706
782
|
const command = windowsCommand(childCommand);
|
|
707
|
-
const
|
|
783
|
+
const initialHorizontalMaxWidth = (!isSidePosition && initialDecision.barSlice?.total > size.cols)
|
|
784
|
+
? Math.max(20, initialDecision.barSlice.total - columnGuard())
|
|
785
|
+
: null;
|
|
786
|
+
const status = new StatusLine(
|
|
787
|
+
effectiveArgs,
|
|
788
|
+
activeProvider,
|
|
789
|
+
isSidePosition ? { maxWidth: 240 } : (initialHorizontalMaxWidth ? { maxWidth: initialHorizontalMaxWidth } : {})
|
|
790
|
+
);
|
|
708
791
|
let term;
|
|
792
|
+
let termExited = false;
|
|
709
793
|
let compositor;
|
|
710
794
|
const pendingReplies = [];
|
|
711
795
|
|
|
@@ -713,11 +797,15 @@ async function runFullscreenCompositor(args, activeProvider) {
|
|
|
713
797
|
compositor = new HeadlessTerminalCompositor({
|
|
714
798
|
columns: size.cols,
|
|
715
799
|
rows: size.rows,
|
|
800
|
+
statusVisible,
|
|
801
|
+
statusPosition,
|
|
802
|
+
sidebarWidth,
|
|
803
|
+
statusSlice: initialDecision.barSlice || null,
|
|
716
804
|
frameIntervalMs: compositorFrameIntervalMs(),
|
|
717
805
|
windowsMode: false,
|
|
718
806
|
windowsPty: compositorWindowsPty(),
|
|
719
807
|
onReply: (data) => {
|
|
720
|
-
if (term) term
|
|
808
|
+
if (term) safeWritePty(term, data, termExited);
|
|
721
809
|
else pendingReplies.push(data);
|
|
722
810
|
},
|
|
723
811
|
onTitle: (title) => {
|
|
@@ -728,14 +816,15 @@ async function runFullscreenCompositor(args, activeProvider) {
|
|
|
728
816
|
|
|
729
817
|
term = pty.spawn(command.file, command.args, {
|
|
730
818
|
name: "xterm-256color",
|
|
731
|
-
cols:
|
|
732
|
-
rows: childRows,
|
|
819
|
+
cols: compositor.childColumns,
|
|
820
|
+
rows: compositor.childRows,
|
|
733
821
|
cwd: process.cwd(),
|
|
734
822
|
env: {
|
|
735
823
|
...process.env,
|
|
736
824
|
TERM: process.env.TERM || "xterm-256color",
|
|
737
825
|
COLORTERM: process.env.COLORTERM || "truecolor",
|
|
738
|
-
AI_BATTERY_ACTIVE_LAYOUT: "composite"
|
|
826
|
+
AI_BATTERY_ACTIVE_LAYOUT: "composite",
|
|
827
|
+
...(activeProvider === "claude" || activeProvider === "antigravity" ? { AI_BATTERY_EXTERNAL_BAR: "1" } : {})
|
|
739
828
|
},
|
|
740
829
|
encoding: null,
|
|
741
830
|
useConpty: true,
|
|
@@ -746,6 +835,7 @@ async function runFullscreenCompositor(args, activeProvider) {
|
|
|
746
835
|
} catch (error) {
|
|
747
836
|
try { term?.kill?.(); } catch {}
|
|
748
837
|
await compositor?.dispose?.().catch(() => {});
|
|
838
|
+
cleanupPaneAiSession(activeProvider || "codex", { ownerPid: process.pid });
|
|
749
839
|
debugLog("fullscreen:error", { stage: "spawn", error: error.message, command });
|
|
750
840
|
return null;
|
|
751
841
|
}
|
|
@@ -812,14 +902,17 @@ async function runFullscreenCompositor(args, activeProvider) {
|
|
|
812
902
|
};
|
|
813
903
|
});
|
|
814
904
|
const exitDisposable = term.onExit(({ exitCode, signal }) => {
|
|
905
|
+
termExited = true;
|
|
815
906
|
debugLog("fullscreen:exit", { exitCode, signal });
|
|
816
907
|
settleExit({ exitCode, signal });
|
|
817
908
|
});
|
|
818
|
-
for (const reply of pendingReplies.splice(0)) term
|
|
909
|
+
for (const reply of pendingReplies.splice(0)) safeWritePty(term, reply, termExited);
|
|
819
910
|
|
|
820
911
|
debugLog("fullscreen:start", {
|
|
821
912
|
size,
|
|
822
|
-
|
|
913
|
+
childColumns: compositor.childColumns,
|
|
914
|
+
childRows: compositor.childRows,
|
|
915
|
+
statusPosition,
|
|
823
916
|
command,
|
|
824
917
|
conptyMode: rowptyConptyMode(),
|
|
825
918
|
bundled: compositorUsesBundledConpty(),
|
|
@@ -830,25 +923,41 @@ async function runFullscreenCompositor(args, activeProvider) {
|
|
|
830
923
|
const stdinWasPaused = process.stdin.isPaused?.() ?? false;
|
|
831
924
|
const onInput = (data) => compositor.input(data);
|
|
832
925
|
let refreshTimer = null;
|
|
926
|
+
let initialRefreshTimer = null;
|
|
927
|
+
let leaseWatchTimer = null;
|
|
833
928
|
let resizePollTimer = null;
|
|
929
|
+
let lastDecision = initialDecision;
|
|
930
|
+
let resizeDebounceTimer = null;
|
|
931
|
+
let onPostResize = null;
|
|
834
932
|
let lastSize = size;
|
|
835
|
-
const
|
|
933
|
+
const applyResize = () => {
|
|
836
934
|
try {
|
|
837
935
|
const next = termSize();
|
|
838
936
|
if (next.cols === lastSize.cols && next.rows === lastSize.rows) return;
|
|
839
937
|
lastSize = next;
|
|
840
|
-
const nextChildRows = Math.max(1, next.rows - 1);
|
|
841
|
-
debugLog("fullscreen:resize", { size: next, childRows: nextChildRows });
|
|
842
938
|
compositor.resize(next.cols, next.rows).catch((error) => {
|
|
843
939
|
debugLog("fullscreen:error", { stage: "screen-resize", error: error.message });
|
|
844
940
|
});
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
941
|
+
debugLog("fullscreen:resize", { size: next, childColumns: compositor.childColumns, childRows: compositor.childRows });
|
|
942
|
+
if (!termExited) {
|
|
943
|
+
try { term.resize(compositor.childColumns, compositor.childRows); } catch {}
|
|
944
|
+
}
|
|
945
|
+
if (typeof onPostResize === "function") onPostResize();
|
|
946
|
+
if (compositor.statusVisible) {
|
|
947
|
+
status.resize();
|
|
948
|
+
status.kickRefresh(true);
|
|
949
|
+
}
|
|
848
950
|
} catch (error) {
|
|
849
951
|
debugLog("fullscreen:error", { stage: "resize", error: error.message });
|
|
850
952
|
}
|
|
851
953
|
};
|
|
954
|
+
const onResize = () => {
|
|
955
|
+
if (resizeDebounceTimer) clearTimeout(resizeDebounceTimer);
|
|
956
|
+
resizeDebounceTimer = setTimeout(() => {
|
|
957
|
+
resizeDebounceTimer = null;
|
|
958
|
+
applyResize();
|
|
959
|
+
}, 50);
|
|
960
|
+
};
|
|
852
961
|
|
|
853
962
|
const emergencyRestore = () => {
|
|
854
963
|
try {
|
|
@@ -877,12 +986,16 @@ async function runFullscreenCompositor(args, activeProvider) {
|
|
|
877
986
|
if (cleaned) return;
|
|
878
987
|
cleaned = true;
|
|
879
988
|
if (refreshTimer) clearInterval(refreshTimer);
|
|
989
|
+
if (initialRefreshTimer) clearTimeout(initialRefreshTimer);
|
|
990
|
+
if (leaseWatchTimer) clearInterval(leaseWatchTimer);
|
|
880
991
|
if (resizePollTimer) clearInterval(resizePollTimer);
|
|
992
|
+
if (resizeDebounceTimer) clearTimeout(resizeDebounceTimer);
|
|
881
993
|
process.stdout.off("resize", onResize);
|
|
882
994
|
process.stdin.off("data", onInput);
|
|
883
995
|
process.stdin.setRawMode?.(oldRaw);
|
|
884
996
|
if (stdinWasPaused) process.stdin.pause();
|
|
885
997
|
status.dispose();
|
|
998
|
+
cleanupPaneAiSession(activeProvider || "codex", { ownerPid: process.pid });
|
|
886
999
|
await waitForOutputDrain();
|
|
887
1000
|
outputDisposable?.dispose?.();
|
|
888
1001
|
exitDisposable?.dispose?.();
|
|
@@ -902,12 +1015,51 @@ async function runFullscreenCompositor(args, activeProvider) {
|
|
|
902
1015
|
compositor.start();
|
|
903
1016
|
await compositor.setStatusText("AI Battery starting...");
|
|
904
1017
|
status.onRefresh = () => compositor.setStatusText(status.text);
|
|
905
|
-
|
|
1018
|
+
const refreshStatus = () => {
|
|
1019
|
+
const decision = paneUsageDecision(activeProvider || "codex", {
|
|
1020
|
+
ownerPid: process.pid,
|
|
1021
|
+
cols: lastSize.cols,
|
|
1022
|
+
rows: lastSize.rows
|
|
1023
|
+
});
|
|
1024
|
+
lastDecision = decision;
|
|
1025
|
+
const visible = Boolean(decision.showUsage) && !decision.attaching;
|
|
1026
|
+
if (visible !== compositor.statusVisible) {
|
|
1027
|
+
compositor.setStatusVisible(visible).catch(error => debugLog("status:visibility-error", { error: error.message }));
|
|
1028
|
+
if (!termExited) {
|
|
1029
|
+
try { term.resize(compositor.childColumns, compositor.childRows); } catch {}
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
const nextSlice = visible ? (decision.barSlice || null) : null;
|
|
1033
|
+
if (!isSidePosition) {
|
|
1034
|
+
status.maxWidthOverride = nextSlice && nextSlice.total > lastSize.cols
|
|
1035
|
+
? Math.max(20, nextSlice.total - columnGuard())
|
|
1036
|
+
: null;
|
|
1037
|
+
}
|
|
1038
|
+
compositor.setStatusSlice(nextSlice).catch(error => debugLog("status:slice-error", { error: error.message }));
|
|
1039
|
+
if (visible) status.kickRefresh(false);
|
|
1040
|
+
};
|
|
1041
|
+
const watchSharedLease = () => {
|
|
1042
|
+
if (!lastDecision?.root || !lastDecision?.context?.tab) return;
|
|
1043
|
+
try {
|
|
1044
|
+
const sharedActive = isPaneSharedBarActive(lastDecision, { includePendingAttach: true });
|
|
1045
|
+
const shouldHide = Boolean(sharedActive);
|
|
1046
|
+
if (shouldHide === compositor.statusVisible) {
|
|
1047
|
+
refreshStatus();
|
|
1048
|
+
}
|
|
1049
|
+
} catch {}
|
|
1050
|
+
};
|
|
1051
|
+
onPostResize = refreshStatus;
|
|
1052
|
+
if (statusVisible) status.kickRefresh(true);
|
|
906
1053
|
process.stdin.setRawMode?.(true);
|
|
907
1054
|
process.stdin.resume();
|
|
908
1055
|
process.stdin.on("data", onInput);
|
|
1056
|
+
initialRefreshTimer = setTimeout(() => {
|
|
1057
|
+
initialRefreshTimer = null;
|
|
1058
|
+
refreshStatus();
|
|
1059
|
+
}, 300);
|
|
1060
|
+
leaseWatchTimer = setInterval(watchSharedLease, 150);
|
|
909
1061
|
refreshTimer = setInterval(
|
|
910
|
-
|
|
1062
|
+
refreshStatus,
|
|
911
1063
|
Math.max(500, Math.floor(args.interval * 1000))
|
|
912
1064
|
);
|
|
913
1065
|
process.stdout.on("resize", onResize);
|
|
@@ -1094,11 +1246,13 @@ async function runConPty(args, activeProvider) {
|
|
|
1094
1246
|
cwd: process.cwd(),
|
|
1095
1247
|
env: process.env
|
|
1096
1248
|
});
|
|
1249
|
+
attachPtyErrorGuards(term);
|
|
1250
|
+
let termExited = false;
|
|
1097
1251
|
|
|
1098
1252
|
const oldRaw = process.stdin.isRaw;
|
|
1099
1253
|
process.stdin.setRawMode?.(true);
|
|
1100
1254
|
process.stdin.resume();
|
|
1101
|
-
const onInput = (data) => term
|
|
1255
|
+
const onInput = (data) => safeWritePty(term, normalizeConPtyInput(data), termExited);
|
|
1102
1256
|
process.stdin.on("data", onInput);
|
|
1103
1257
|
|
|
1104
1258
|
let drawTimer = null;
|
|
@@ -1120,7 +1274,9 @@ async function runConPty(args, activeProvider) {
|
|
|
1120
1274
|
const repaintTimer = setInterval(() => status.paint(true), conPtyRepaintIntervalMs());
|
|
1121
1275
|
const onResize = () => {
|
|
1122
1276
|
status.resize(true);
|
|
1123
|
-
|
|
1277
|
+
if (!termExited) {
|
|
1278
|
+
try { term.resize(status.cols, Math.max(1, status.rows - 1)); } catch {}
|
|
1279
|
+
}
|
|
1124
1280
|
scheduleDraw(true, 0);
|
|
1125
1281
|
scheduleRepaintBurst(status, timers);
|
|
1126
1282
|
};
|
|
@@ -1141,6 +1297,7 @@ async function runConPty(args, activeProvider) {
|
|
|
1141
1297
|
scheduleDraw(false);
|
|
1142
1298
|
});
|
|
1143
1299
|
term.onExit(({ exitCode }) => {
|
|
1300
|
+
termExited = true;
|
|
1144
1301
|
debugLog("conpty:exit", { exitCode });
|
|
1145
1302
|
clearConPtyTimers();
|
|
1146
1303
|
process.stdout.off("resize", onResize);
|
|
@@ -1365,7 +1522,7 @@ async function main() {
|
|
|
1365
1522
|
} else if (["composite", "auto"].includes(args.layout)) {
|
|
1366
1523
|
exitCode = await runFullscreenCompositor(args, activeProvider);
|
|
1367
1524
|
if (exitCode === null) {
|
|
1368
|
-
console.error(cliText("ai-battery-run-win: compositor unavailable;
|
|
1525
|
+
console.error(cliText("ai-battery-run-win: compositor unavailable; launching command directly.", "ai-battery-run-win: compositor를 사용할 수 없어 명령을 직접 실행합니다."));
|
|
1369
1526
|
exitCode = process.stdin.isTTY && process.stdout.isTTY ? await runNativeFullscreen(args) : await runPlain(args);
|
|
1370
1527
|
}
|
|
1371
1528
|
} else if (args.layout === "inline") {
|
|
@@ -256,6 +256,37 @@ function Resize-HudToContent {
|
|
|
256
256
|
Sync-HitFormBounds
|
|
257
257
|
return
|
|
258
258
|
}
|
|
259
|
+
if ($script:hudHorizontalPanel) {
|
|
260
|
+
if ($script:hudCustomLayout -eq "rail") {
|
|
261
|
+
$railSize = Measure-VerticalRailHudSize $script:latestHudTexts
|
|
262
|
+
$desiredWidth = $railSize.Width
|
|
263
|
+
$desiredHeight = $railSize.Height
|
|
264
|
+
} else {
|
|
265
|
+
$desiredWidth = Measure-HorizontalBrandHudWidth $script:latestHudTexts $font
|
|
266
|
+
$desiredHeight = Scale-HudValue 34
|
|
267
|
+
}
|
|
268
|
+
if (($form.Width -ne $desiredWidth) -or ($form.Height -ne $desiredHeight)) {
|
|
269
|
+
$form.Size = [System.Drawing.Size]::new($desiredWidth, $desiredHeight)
|
|
270
|
+
if (-not $script:resizeDrag) {
|
|
271
|
+
$newX = if ($script:hudAnchorX -eq "right") { $oldRight - $form.Width } else { $form.Left }
|
|
272
|
+
$newY = if ($script:hudAnchorY -eq "bottom") { $oldBottom - $form.Height } else { $form.Top }
|
|
273
|
+
if ($script:positionSaveReady -and (Get-Command Get-OnScreenPoint -ErrorAction SilentlyContinue)) {
|
|
274
|
+
$form.Location = Get-OnScreenPoint ([int]$newX) ([int]$newY) ([int]$form.Width) ([int]$form.Height)
|
|
275
|
+
} else {
|
|
276
|
+
$form.Location = [System.Drawing.Point]::new([int]$newX, [int]$newY)
|
|
277
|
+
}
|
|
278
|
+
Sync-HitFormBounds
|
|
279
|
+
Save-HudPositionIfReady
|
|
280
|
+
} else {
|
|
281
|
+
Sync-HitFormBounds
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if ($script:horizontalPaintPanel) { $script:horizontalPaintPanel.Invalidate() }
|
|
285
|
+
if ($script:detailPopupForm -and -not $script:detailPopupForm.IsDisposed -and $script:detailPopupForm.Visible) {
|
|
286
|
+
Update-HorizontalDetailPopupBounds
|
|
287
|
+
}
|
|
288
|
+
return
|
|
289
|
+
}
|
|
259
290
|
$contentWidth = 0
|
|
260
291
|
foreach ($name in $script:hudVisibleProviders) {
|
|
261
292
|
$contentWidth = [math]::Max($contentWidth, (Get-HudControlsWidth $script:hudProviderRows[$name].Controls))
|
|
@@ -273,18 +304,28 @@ function Resize-HudToContent {
|
|
|
273
304
|
|
|
274
305
|
if (([math]::Abs($form.Width - $desiredWidth) -gt 1) -or ($form.Height -ne $desiredHeight)) {
|
|
275
306
|
$form.Size = [System.Drawing.Size]::new($desiredWidth, $desiredHeight)
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
307
|
+
if (-not $script:resizeDrag) {
|
|
308
|
+
$newX = if ($script:hudAnchorX -eq "right") { $oldRight - $form.Width } else { $form.Left }
|
|
309
|
+
$newY = if ($script:hudAnchorY -eq "bottom") { $oldBottom - $form.Height } else { $form.Top }
|
|
310
|
+
if ($script:positionSaveReady -and (Get-Command Get-OnScreenPoint -ErrorAction SilentlyContinue)) {
|
|
311
|
+
$form.Location = Get-OnScreenPoint ([int]$newX) ([int]$newY) ([int]$form.Width) ([int]$form.Height)
|
|
312
|
+
} else {
|
|
313
|
+
$form.Location = [System.Drawing.Point]::new([int]$newX, [int]$newY)
|
|
314
|
+
}
|
|
315
|
+
Sync-HitFormBounds
|
|
316
|
+
Save-HudPositionIfReady
|
|
317
|
+
} else {
|
|
318
|
+
Sync-HitFormBounds
|
|
319
|
+
}
|
|
281
320
|
}
|
|
282
321
|
}
|
|
283
322
|
|
|
284
323
|
function Show-HudMessage([string]$Message) {
|
|
285
|
-
$key = "message:$Message|$script:hudScale|$script:hudDarkText"
|
|
324
|
+
$key = "message:$Message|$script:hudScale|$script:hudDarkText|$script:hudContrastBackdrop|$script:hudCodexIconMode|$script:hudHorizontalPanel"
|
|
286
325
|
if ($script:hudVisualKey -eq $key) { return }
|
|
287
326
|
$script:hudVisualKey = $null
|
|
327
|
+
$script:latestHudTexts = $null
|
|
328
|
+
$script:hudHorizontalMessage = $Message
|
|
288
329
|
$codexPrefixLabel.Text = $Message
|
|
289
330
|
$codexPrefixLabel.ForeColor = Get-HudMutedTextColor
|
|
290
331
|
$codexPrefixLabel.Width = (Get-LabelTextWidth $codexPrefixLabel) + (Scale-HudValue 1)
|
|
@@ -329,6 +370,12 @@ function Update-HudFromSnapshot($Snapshot) {
|
|
|
329
370
|
|
|
330
371
|
try {
|
|
331
372
|
$texts = ConvertTo-HudTexts $Snapshot
|
|
373
|
+
if ($texts.Rows.Count -eq 0) {
|
|
374
|
+
Show-HudMessage "No providers enabled"
|
|
375
|
+
Invalidate-DockedTuiIfChanged $Snapshot
|
|
376
|
+
Update-HudVisibilityForFullscreen
|
|
377
|
+
return
|
|
378
|
+
}
|
|
332
379
|
# Timestamps and fetch metadata do not affect the frame. Keep polling and
|
|
333
380
|
# caching fresh snapshots, but leave an identical screen untouched.
|
|
334
381
|
$visualRows = @($texts.Rows | ForEach-Object {
|
|
@@ -336,13 +383,14 @@ function Update-HudFromSnapshot($Snapshot) {
|
|
|
336
383
|
Running = $_.Parts.Running; Color = $_.Parts.TextColor.ToArgb();
|
|
337
384
|
Reset = $_.Parts.ResetValue; Week = $_.Parts.WeekValue; Extra = $_.Parts.ExtraText }
|
|
338
385
|
})
|
|
339
|
-
$key = (@{ Rows = $visualRows; Scale = $script:hudScale; DarkText = $script:hudDarkText } | ConvertTo-Json -Depth 5 -Compress)
|
|
386
|
+
$key = (@{ Rows = $visualRows; Scale = $script:hudScale; DarkText = $script:hudDarkText; Backdrop = [bool]$script:hudContrastBackdrop; CodexIcon = [string]$script:hudCodexIconMode; Layout = $script:hudCustomLayout } | ConvertTo-Json -Depth 5 -Compress)
|
|
340
387
|
if ($script:hudVisualKey -eq $key) {
|
|
341
388
|
Invalidate-DockedTuiIfChanged $Snapshot
|
|
342
389
|
Update-HudVisibilityForFullscreen
|
|
343
390
|
return
|
|
344
391
|
}
|
|
345
392
|
$script:hudVisualKey = $null
|
|
393
|
+
$script:latestHudTexts = $texts
|
|
346
394
|
$script:codexRowVisible = [bool]$texts.CodexVisible
|
|
347
395
|
$script:claudeRowVisible = [bool]$texts.ClaudeVisible
|
|
348
396
|
$script:hudVisibleProviders = @($texts.Rows | ForEach-Object { $_.Provider })
|
|
@@ -396,16 +444,15 @@ function Invoke-HudPump {
|
|
|
396
444
|
Write-HudSnapshot $merged
|
|
397
445
|
Update-HudFromSnapshot $merged
|
|
398
446
|
|
|
399
|
-
$missingWeekly = @($merged.results | Where-Object { $_.ok -and $null -ne $_.percentRemaining -and $null -eq $_.secondary })
|
|
400
|
-
if ($missingWeekly.Count -gt 0 -and $script:weeklyRetryCount -lt 6) {
|
|
401
|
-
$script:weeklyRetryCount += 1
|
|
402
|
-
Start-SnapshotFetch
|
|
403
|
-
return
|
|
404
|
-
}
|
|
405
|
-
$script:weeklyRetryCount = 0
|
|
406
447
|
return
|
|
407
448
|
}
|
|
408
449
|
|
|
450
|
+
$current = Get-CurrentHudSnapshot $script:latestSnapshot
|
|
451
|
+
if ($current -and -not [object]::ReferenceEquals($current, $script:latestSnapshot)) {
|
|
452
|
+
$script:latestSnapshot = $current
|
|
453
|
+
Update-HudFromSnapshot $current
|
|
454
|
+
}
|
|
455
|
+
|
|
409
456
|
if (-not $script:fetchPowerShell -and
|
|
410
457
|
([datetime]::UtcNow - $script:lastFetchStartUtc).TotalSeconds -ge [math]::Max(1, $Interval)) {
|
|
411
458
|
Start-SnapshotFetch
|
|
@@ -428,4 +475,7 @@ $topMostTimer.add_Tick({
|
|
|
428
475
|
})
|
|
429
476
|
$menuAutoHideTimer = New-Object System.Windows.Forms.Timer
|
|
430
477
|
$menuAutoHideTimer.Interval = 50
|
|
431
|
-
$menuAutoHideTimer.add_Tick({
|
|
478
|
+
$menuAutoHideTimer.add_Tick({
|
|
479
|
+
Update-HudMenuAutoHide
|
|
480
|
+
Update-DetailPopupAutoHide
|
|
481
|
+
})
|