aegis-bridge 2.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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +244 -0
  3. package/dashboard/dist/assets/index-CijFoeRu.css +32 -0
  4. package/dashboard/dist/assets/index-QtT4j0ht.js +262 -0
  5. package/dashboard/dist/index.html +14 -0
  6. package/dist/auth.d.ts +76 -0
  7. package/dist/auth.js +219 -0
  8. package/dist/channels/index.d.ts +8 -0
  9. package/dist/channels/index.js +9 -0
  10. package/dist/channels/manager.d.ts +39 -0
  11. package/dist/channels/manager.js +101 -0
  12. package/dist/channels/telegram-style.d.ts +118 -0
  13. package/dist/channels/telegram-style.js +203 -0
  14. package/dist/channels/telegram.d.ts +76 -0
  15. package/dist/channels/telegram.js +1396 -0
  16. package/dist/channels/types.d.ts +77 -0
  17. package/dist/channels/types.js +9 -0
  18. package/dist/channels/webhook.d.ts +58 -0
  19. package/dist/channels/webhook.js +162 -0
  20. package/dist/cli.d.ts +8 -0
  21. package/dist/cli.js +223 -0
  22. package/dist/config.d.ts +60 -0
  23. package/dist/config.js +188 -0
  24. package/dist/dashboard/assets/index-CijFoeRu.css +32 -0
  25. package/dist/dashboard/assets/index-QtT4j0ht.js +262 -0
  26. package/dist/dashboard/index.html +14 -0
  27. package/dist/events.d.ts +86 -0
  28. package/dist/events.js +258 -0
  29. package/dist/hook-settings.d.ts +67 -0
  30. package/dist/hook-settings.js +138 -0
  31. package/dist/hook.d.ts +18 -0
  32. package/dist/hook.js +199 -0
  33. package/dist/hooks.d.ts +32 -0
  34. package/dist/hooks.js +279 -0
  35. package/dist/jsonl-watcher.d.ts +57 -0
  36. package/dist/jsonl-watcher.js +159 -0
  37. package/dist/mcp-server.d.ts +60 -0
  38. package/dist/mcp-server.js +788 -0
  39. package/dist/metrics.d.ts +104 -0
  40. package/dist/metrics.js +226 -0
  41. package/dist/monitor.d.ts +84 -0
  42. package/dist/monitor.js +553 -0
  43. package/dist/permission-guard.d.ts +51 -0
  44. package/dist/permission-guard.js +197 -0
  45. package/dist/pipeline.d.ts +84 -0
  46. package/dist/pipeline.js +218 -0
  47. package/dist/screenshot.d.ts +26 -0
  48. package/dist/screenshot.js +57 -0
  49. package/dist/server.d.ts +10 -0
  50. package/dist/server.js +1577 -0
  51. package/dist/session.d.ts +297 -0
  52. package/dist/session.js +1275 -0
  53. package/dist/sse-limiter.d.ts +47 -0
  54. package/dist/sse-limiter.js +62 -0
  55. package/dist/sse-writer.d.ts +31 -0
  56. package/dist/sse-writer.js +95 -0
  57. package/dist/ssrf.d.ts +57 -0
  58. package/dist/ssrf.js +169 -0
  59. package/dist/swarm-monitor.d.ts +114 -0
  60. package/dist/swarm-monitor.js +267 -0
  61. package/dist/terminal-parser.d.ts +16 -0
  62. package/dist/terminal-parser.js +343 -0
  63. package/dist/tmux.d.ts +161 -0
  64. package/dist/tmux.js +725 -0
  65. package/dist/transcript.d.ts +47 -0
  66. package/dist/transcript.js +244 -0
  67. package/dist/validation.d.ts +222 -0
  68. package/dist/validation.js +268 -0
  69. package/dist/ws-terminal.d.ts +32 -0
  70. package/dist/ws-terminal.js +297 -0
  71. package/package.json +71 -0
package/dist/tmux.d.ts ADDED
@@ -0,0 +1,161 @@
1
+ /**
2
+ * tmux.ts — Low-level tmux interaction layer.
3
+ *
4
+ * Wraps tmux CLI commands to manage windows inside a named session.
5
+ * Port of CCBot's tmux_manager.py to TypeScript.
6
+ */
7
+ /** Thrown when a tmux command exceeds its timeout. */
8
+ export declare class TmuxTimeoutError extends Error {
9
+ constructor(args: string[], timeoutMs: number);
10
+ }
11
+ export interface TmuxWindow {
12
+ windowId: string;
13
+ windowName: string;
14
+ cwd: string;
15
+ paneCommand: string;
16
+ }
17
+ export declare class TmuxManager {
18
+ private sessionName;
19
+ /** tmux socket name (-L flag). Isolates sessions from other tmux instances. */
20
+ readonly socketName: string;
21
+ /** #357: Cache for window existence checks — avoids repeated tmux CLI calls. */
22
+ private windowExistsCache;
23
+ private static readonly WINDOW_CACHE_TTL_MS;
24
+ constructor(sessionName?: string, socketName?: string);
25
+ /** Promise-chain queue that serializes all tmux CLI calls to prevent race conditions. */
26
+ private queue;
27
+ /** #403: Counter of in-flight createWindow calls — direct methods must queue when > 0. */
28
+ private _creatingCount;
29
+ /** #357: Short-lived cache for window existence checks to reduce CLI calls. */
30
+ private windowCache;
31
+ /** Run `fn` sequentially after all previously-queued operations complete. */
32
+ private serialize;
33
+ /** Run a tmux command and return stdout (serialized through the queue).
34
+ * Issue #66: All tmux commands have a timeout to prevent hangs.
35
+ * A single hung tmux command would otherwise block the entire Aegis server.
36
+ */
37
+ private tmux;
38
+ private tmuxInternal;
39
+ /** Ensure our tmux session exists and is healthy.
40
+ * Issue #7: After prolonged uptime, tmux session may exist but be degraded.
41
+ * We verify by listing windows — if that fails, recreate the session.
42
+ */
43
+ ensureSession(): Promise<void>;
44
+ /** #403: Internal version that calls tmuxInternal directly (safe inside serialize). */
45
+ private ensureSessionInternal;
46
+ /** List all windows (excluding the placeholder _bridge_main). */
47
+ listWindows(): Promise<TmuxWindow[]>;
48
+ /** Create a new window, start claude, return window info.
49
+ * Issue #7: Retries up to 3x on failure, with tmux session health check between retries.
50
+ */
51
+ createWindow(opts: {
52
+ workDir: string;
53
+ windowName: string;
54
+ claudeCommand?: string;
55
+ resumeSessionId?: string;
56
+ env?: Record<string, string>;
57
+ permissionMode?: string;
58
+ /** Path to a CC settings JSON file (via --settings flag). */
59
+ settingsFile?: string;
60
+ /** @deprecated Use permissionMode instead. Maps true→bypassPermissions, false→default. */
61
+ autoApprove?: boolean;
62
+ }): Promise<{
63
+ windowId: string;
64
+ windowName: string;
65
+ freshSessionId?: string;
66
+ }>;
67
+ /**
68
+ * Archive old Claude session files so interactive mode starts fresh.
69
+ *
70
+ * Claude CLI computes a project hash from the workDir path:
71
+ * /home/user/projects/foo → -home-user-projects-foo
72
+ * and stores sessions at ~/.claude/projects/<hash>/*.jsonl.
73
+ *
74
+ * In interactive mode, Claude always auto-resumes the latest .jsonl file.
75
+ * There is no CLI flag to disable this. The only reliable way to force a
76
+ * fresh session is to move existing .jsonl files out of the way.
77
+ *
78
+ * Files are moved to an `_archived/` subfolder (not deleted), so they can
79
+ * be recovered if needed.
80
+ */
81
+ private archiveStaleSessionFiles;
82
+ /** Issue #23: Set env vars securely without exposing values in tmux pane.
83
+ * Writes vars to a temp file, sources it, then deletes it.
84
+ * Values never appear in terminal scrollback or capture-pane output.
85
+ */
86
+ private setEnvSecure;
87
+ /** P1 fix: Check if a window exists. Returns true if window is in the session.
88
+ * #357: Uses a short-lived cache to avoid repeated tmux CLI calls. */
89
+ windowExists(windowId: string): Promise<boolean>;
90
+ /** Issue #69: Get the PID of the first pane in a window. Returns null on error. */
91
+ listPanePid(windowId: string): Promise<number | null>;
92
+ /** Issue #69: Check if a PID is alive using kill -0. */
93
+ isPidAlive(pid: number): boolean;
94
+ /** Get detailed window info for health checks.
95
+ * Issue #2: Returns window existence, pane command, and whether Claude is running.
96
+ */
97
+ getWindowHealth(windowId: string): Promise<{
98
+ windowExists: boolean;
99
+ paneCommand: string | null;
100
+ claudeRunning: boolean;
101
+ }>;
102
+ /** Send text to a window's active pane. */
103
+ sendKeys(windowId: string, text: string, enter?: boolean): Promise<void>;
104
+ /** Check if a pane state indicates CC has received input (non-idle). */
105
+ private isActiveState;
106
+ /** Verify that a message was delivered to Claude Code.
107
+ * Issue #1 v2: Compares pre-send and post-send pane state to detect delivery.
108
+ *
109
+ * Strategy:
110
+ * 1. If CC transitioned from idle → active state → confirmed
111
+ * 2. If CC is in any active state (working, permission, etc.) → confirmed
112
+ * 3. If sent text (prefix) is visible in the pane → confirmed
113
+ * 4. If CC is still idle with no trace of input → NOT confirmed
114
+ * 5. Unknown state → benefit of the doubt (confirmed)
115
+ *
116
+ * The `preSendState` parameter enables state-change detection to avoid
117
+ * false negatives during transitional moments.
118
+ */
119
+ verifyDelivery(windowId: string, sentText: string, preSendState?: string): Promise<boolean>;
120
+ /** Send text and verify delivery with retry.
121
+ * Issue #1 v2: Captures pre-send state and only re-sends if pane is still idle.
122
+ * Prevents duplicate prompt delivery that plagued v1.
123
+ */
124
+ sendKeysVerified(windowId: string, text: string, maxAttempts?: number): Promise<{
125
+ delivered: boolean;
126
+ attempts: number;
127
+ }>;
128
+ /** Send a special key (Escape, C-c, etc.) */
129
+ sendSpecialKey(windowId: string, key: string): Promise<void>;
130
+ /** Capture the visible pane content.
131
+ * Issue #89 L23: Strips DCS passthrough sequences (ESC P ... ESC \\)
132
+ * that can leak through tmux's capture-pane into the output.
133
+ */
134
+ capturePane(windowId: string): Promise<string>;
135
+ /** Capture pane content WITHOUT going through the serialize queue.
136
+ * Used for critical-path operations (e.g., sendInitialPrompt) that should
137
+ * not be delayed by monitor polls. The queue is for preventing race conditions
138
+ * in monitor/concurrent reads, but sendInitialPrompt is the ONLY writer at
139
+ * session creation time.
140
+ * #403: During window creation (_creatingCount > 0), queues behind serialize
141
+ * to avoid racing with the creation sequence.
142
+ */
143
+ capturePaneDirect(windowId: string): Promise<string>;
144
+ private capturePaneDirectInternal;
145
+ /** Send keys WITHOUT going through the serialize queue.
146
+ * Used for critical-path operations (e.g., sendInitialPrompt).
147
+ * Simplified version: sends literal text + Enter (no ! command mode handling).
148
+ * #403: During window creation (_creatingCount > 0), queues behind serialize
149
+ * to avoid racing with the creation sequence.
150
+ */
151
+ sendKeysDirect(windowId: string, text: string, enter?: boolean): Promise<void>;
152
+ private sendKeysDirectInternal;
153
+ /** Resize a window's pane to the given dimensions. */
154
+ resizePane(windowId: string, cols: number, rows: number): Promise<void>;
155
+ /** Kill a window. */
156
+ killWindow(windowId: string): Promise<void>;
157
+ /** Kill the entire tmux session. Used for cleanup on shutdown. */
158
+ killSession(sessionName?: string): Promise<void>;
159
+ /** #357: Poll until condition returns true or timeout elapses. */
160
+ private pollUntil;
161
+ }