@code-yeongyu/senpi 2026.9.4-2 → 2026.9.4-3
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/CHANGELOG.md +23 -0
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +31 -41
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/credential-pool/state-store.d.ts +1 -0
- package/dist/core/credential-pool/state-store.d.ts.map +1 -1
- package/dist/core/credential-pool/state-store.js +22 -2
- package/dist/core/credential-pool/state-store.js.map +1 -1
- package/dist/core/extensions/builtin/goal/store.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/store.js +8 -20
- package/dist/core/extensions/builtin/goal/store.js.map +1 -1
- package/dist/core/extensions/builtin/hooks/trust-storage.d.ts.map +1 -1
- package/dist/core/extensions/builtin/hooks/trust-storage.js +3 -1
- package/dist/core/extensions/builtin/hooks/trust-storage.js.map +1 -1
- package/dist/core/extensions/builtin/imagegen/auth.d.ts.map +1 -1
- package/dist/core/extensions/builtin/imagegen/auth.js +10 -2
- package/dist/core/extensions/builtin/imagegen/auth.js.map +1 -1
- package/dist/core/extensions/builtin/loop/store.d.ts +8 -6
- package/dist/core/extensions/builtin/loop/store.d.ts.map +1 -1
- package/dist/core/extensions/builtin/loop/store.js +54 -88
- package/dist/core/extensions/builtin/loop/store.js.map +1 -1
- package/dist/core/extensions/builtin/monitor-state-event.d.ts +2 -0
- package/dist/core/extensions/builtin/monitor-state-event.d.ts.map +1 -1
- package/dist/core/extensions/builtin/monitor-state-event.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.js +181 -3
- package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/manager.d.ts +10 -0
- package/dist/core/extensions/builtin/terminal/manager.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/manager.js +21 -0
- package/dist/core/extensions/builtin/terminal/manager.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/manifest-lease.d.ts +24 -0
- package/dist/core/extensions/builtin/terminal/manifest-lease.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/manifest-lease.js +105 -0
- package/dist/core/extensions/builtin/terminal/manifest-lease.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts +13 -2
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.js +24 -2
- package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/restore.d.ts +43 -0
- package/dist/core/extensions/builtin/terminal/restore.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/restore.js +149 -0
- package/dist/core/extensions/builtin/terminal/restore.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/terminal-manifest.d.ts +110 -0
- package/dist/core/extensions/builtin/terminal/terminal-manifest.d.ts.map +1 -0
- package/dist/core/extensions/builtin/terminal/terminal-manifest.js +158 -0
- package/dist/core/extensions/builtin/terminal/terminal-manifest.js.map +1 -0
- package/dist/core/extensions/builtin/terminal/tools/bash-input.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-input.js +3 -2
- package/dist/core/extensions/builtin/terminal/tools/bash-input.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-output.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-output.js +5 -4
- package/dist/core/extensions/builtin/terminal/tools/bash-output.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-resize.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-resize.js +3 -2
- package/dist/core/extensions/builtin/terminal/tools/bash-resize.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts +8 -0
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.js +10 -0
- package/dist/core/extensions/builtin/terminal/tools/context.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/kill-bash.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/kill-bash.js +5 -4
- package/dist/core/extensions/builtin/terminal/tools/kill-bash.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts +4 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.js +58 -14
- package/dist/core/extensions/builtin/terminal/tools/monitor.js.map +1 -1
- package/dist/core/extensions/builtin/tool-search/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/tool-search/index.js +1 -1
- package/dist/core/extensions/builtin/tool-search/index.js.map +1 -1
- package/dist/core/extensions/builtin/tool-search/native-search.d.ts +9 -4
- package/dist/core/extensions/builtin/tool-search/native-search.d.ts.map +1 -1
- package/dist/core/extensions/builtin/tool-search/native-search.js +11 -6
- package/dist/core/extensions/builtin/tool-search/native-search.js.map +1 -1
- package/dist/core/extensions/builtin/tool-search/native-support.d.ts +13 -0
- package/dist/core/extensions/builtin/tool-search/native-support.d.ts.map +1 -0
- package/dist/core/extensions/builtin/tool-search/native-support.js +45 -0
- package/dist/core/extensions/builtin/tool-search/native-support.js.map +1 -0
- package/dist/core/lockfile-policy.d.ts +11 -0
- package/dist/core/lockfile-policy.d.ts.map +1 -1
- package/dist/core/lockfile-policy.js +19 -0
- package/dist/core/lockfile-policy.js.map +1 -1
- package/dist/core/session-sidecar-store.d.ts +62 -0
- package/dist/core/session-sidecar-store.d.ts.map +1 -0
- package/dist/core/session-sidecar-store.js +149 -0
- package/dist/core/session-sidecar-store.js.map +1 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +11 -15
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/modes/app-server/daemon/process.d.ts +33 -3
- package/dist/modes/app-server/daemon/process.d.ts.map +1 -1
- package/dist/modes/app-server/daemon/process.js +57 -6
- package/dist/modes/app-server/daemon/process.js.map +1 -1
- package/dist/modes/app-server/daemon.js +9 -1
- package/dist/modes/app-server/daemon.js.map +1 -1
- package/dist/modes/rpc/host-ensure.d.ts +2 -0
- package/dist/modes/rpc/host-ensure.d.ts.map +1 -1
- package/dist/modes/rpc/host-ensure.js +77 -18
- package/dist/modes/rpc/host-ensure.js.map +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +14 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +5 -5
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js +4 -4
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +7 -7
|
@@ -18,6 +18,8 @@ export interface CreatedTerminalSession {
|
|
|
18
18
|
export declare class TerminalManager {
|
|
19
19
|
private readonly registry;
|
|
20
20
|
private readonly runtimes;
|
|
21
|
+
/** Stable "mon_" identities bound to runtime session ids; survives PTY exit, then drops on session prune or teardown. */
|
|
22
|
+
private readonly monitorIds;
|
|
21
23
|
private readonly scrollback?;
|
|
22
24
|
private readonly maxSessions;
|
|
23
25
|
private readonly exited;
|
|
@@ -30,6 +32,14 @@ export declare class TerminalManager {
|
|
|
30
32
|
create(command: string, options: TerminalSessionOptions): Promise<CreatedTerminalSession>;
|
|
31
33
|
/** Look up a live-or-exited session, refreshing its LRU timestamp. */
|
|
32
34
|
get(id: string): TerminalRuntimeSession | null;
|
|
35
|
+
/** Bind a stable "mon_" id to its runtime session id; a later restore re-binds the same id. */
|
|
36
|
+
bindMonitorId(monitorId: string, sessionId: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Resolve a "mon_" monitor id to its current runtime "bash_N" (or "watch_N"), passing a
|
|
39
|
+
* runtime id through unchanged; undefined when neither resolves. Bindings intentionally
|
|
40
|
+
* outlive PTY exit for a final output read, then drop when the session is pruned or torn down.
|
|
41
|
+
*/
|
|
42
|
+
resolveId(idOrMonitorId: string): string | undefined;
|
|
33
43
|
list(): {
|
|
34
44
|
id: string;
|
|
35
45
|
runtime: TerminalRuntimeSession;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,4BAA4B,EAE5B,KAAK,sBAAsB,EAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAA+B,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAG3F,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAEtE,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,sBAAsB,CAAC;CACzC;AAED;;;;;GAKG;AACH,qBAAa,eAAe;IAC3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmC;IAC5D,OAAO,CAAC,QAAQ,CAAC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B,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,4BAA4B,CAErF"}
|
|
@@ -11,6 +11,8 @@ export { SessionRegistryCapacityError } from "@earendil-works/pi-pty";
|
|
|
11
11
|
export class TerminalManager {
|
|
12
12
|
constructor(options = {}) {
|
|
13
13
|
this.runtimes = new Map();
|
|
14
|
+
/** Stable "mon_" identities bound to runtime session ids; survives PTY exit, then drops on session prune or teardown. */
|
|
15
|
+
this.monitorIds = new Map();
|
|
14
16
|
this.exited = new Set();
|
|
15
17
|
this.reservations = 0;
|
|
16
18
|
this.maxSessions = options.maxSessions ?? DEFAULT_MAX_SESSIONS;
|
|
@@ -69,6 +71,20 @@ export class TerminalManager {
|
|
|
69
71
|
return null;
|
|
70
72
|
return this.runtimes.get(id) ?? null;
|
|
71
73
|
}
|
|
74
|
+
/** Bind a stable "mon_" id to its runtime session id; a later restore re-binds the same id. */
|
|
75
|
+
bindMonitorId(monitorId, sessionId) {
|
|
76
|
+
this.monitorIds.set(monitorId, sessionId);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Resolve a "mon_" monitor id to its current runtime "bash_N" (or "watch_N"), passing a
|
|
80
|
+
* runtime id through unchanged; undefined when neither resolves. Bindings intentionally
|
|
81
|
+
* outlive PTY exit for a final output read, then drop when the session is pruned or torn down.
|
|
82
|
+
*/
|
|
83
|
+
resolveId(idOrMonitorId) {
|
|
84
|
+
if (idOrMonitorId.startsWith("mon_"))
|
|
85
|
+
return this.monitorIds.get(idOrMonitorId);
|
|
86
|
+
return this.registry.get(idOrMonitorId) ? idOrMonitorId : undefined;
|
|
87
|
+
}
|
|
72
88
|
list() {
|
|
73
89
|
const result = [];
|
|
74
90
|
for (const entry of this.registry.list()) {
|
|
@@ -91,6 +107,7 @@ export class TerminalManager {
|
|
|
91
107
|
runtime.dispose();
|
|
92
108
|
this.runtimes.clear();
|
|
93
109
|
this.exited.clear();
|
|
110
|
+
this.monitorIds.clear();
|
|
94
111
|
}
|
|
95
112
|
/** Dispose runtime wrappers whose registry entry was pruned (capacity/LRU eviction). */
|
|
96
113
|
reconcileRuntimes() {
|
|
@@ -101,6 +118,10 @@ export class TerminalManager {
|
|
|
101
118
|
runtime.dispose();
|
|
102
119
|
this.runtimes.delete(id);
|
|
103
120
|
this.exited.delete(id);
|
|
121
|
+
for (const [monitorId, sessionId] of this.monitorIds) {
|
|
122
|
+
if (sessionId === id)
|
|
123
|
+
this.monitorIds.delete(monitorId);
|
|
124
|
+
}
|
|
104
125
|
}
|
|
105
126
|
}
|
|
106
127
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,4BAA4B,GAG5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAA+B,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAYtE;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAQ3B,YAAY,UAAkC,EAAE;QAN/B,aAAQ,GAAG,IAAI,GAAG,EAAkC,CAAC;QAGrD,WAAM,GAAG,IAAI,GAAG,EAAU,CAAC;QACpC,iBAAY,GAAG,CAAC,CAAC;QAGxB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,oBAAoB,CAAC;QAC/D,IAAI,CAAC,QAAQ,GAAG,IAAI,eAAe,CAAkB,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QACxF,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACtC,CAAC;IAED,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,UAAU;QACb,IAAI,CAAC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;QAC7C,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,gEAAgE;IAChE,KAAK,CAAC,QAAQ;QACb,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAC/B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;YAAE,OAAO,CAAC,OAAO,EAAE,CAAC;QAChE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,wFAAwF;IAChF,iBAAiB;QACxB,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;QACvE,KAAK,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC3C,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,SAAS;YAC9B,OAAO,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACzB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACxB,CAAC;IACF,CAAC;CACD;AAED,MAAM,UAAU,eAAe,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,4BAA4B,CAAC;AACtD,CAAC","sourcesContent":["import {\n\tSessionRegistry,\n\tSessionRegistryCapacityError,\n\ttype TerminalSession,\n\ttype TerminalSessionOptions,\n} from \"@earendil-works/pi-pty\";\nimport { type TerminalRuntimeOptions, TerminalRuntimeSession } from \"./runtime-session.ts\";\nimport { DEFAULT_MAX_SESSIONS } from \"./shared.ts\";\n\nexport { SessionRegistryCapacityError } from \"@earendil-works/pi-pty\";\n\nexport interface TerminalManagerOptions {\n\treadonly maxSessions?: number;\n\treadonly scrollback?: number;\n}\n\nexport interface CreatedTerminalSession {\n\treadonly id: string;\n\treadonly runtime: TerminalRuntimeSession;\n}\n\n/**\n * Owns the live terminal sessions for one agent session. Delegates id allocation,\n * capacity caps, LRU-exited pruning, and tree-kill teardown to the pi-pty\n * {@link SessionRegistry}, while keeping the richer {@link TerminalRuntimeSession}\n * wrappers (screen model + output buffer) in lock-step.\n */\nexport class TerminalManager {\n\tprivate readonly registry: SessionRegistry<TerminalSession>;\n\tprivate readonly runtimes = new Map<string, TerminalRuntimeSession>();\n\tprivate readonly scrollback?: number;\n\tprivate readonly maxSessions: number;\n\tprivate readonly exited = new Set<string>();\n\tprivate reservations = 0;\n\n\tconstructor(options: TerminalManagerOptions = {}) {\n\t\tthis.maxSessions = options.maxSessions ?? DEFAULT_MAX_SESSIONS;\n\t\tthis.registry = new SessionRegistry<TerminalSession>({ maxSessions: this.maxSessions });\n\t\tthis.scrollback = options.scrollback;\n\t}\n\n\tget size(): number {\n\t\treturn this.runtimes.size;\n\t}\n\n\tget activeSize(): number {\n\t\tthis.reconcileRuntimes();\n\t\treturn this.runtimes.size - this.exited.size + this.reservations;\n\t}\n\n\treserve(): (() => void) | null {\n\t\tthis.reconcileRuntimes();\n\t\tif (this.runtimes.size - this.exited.size + this.reservations >= this.maxSessions) return null;\n\t\tthis.reservations += 1;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tthis.reservations -= 1;\n\t\t};\n\t}\n\n\t/** Spawn a new terminal session and register it under an allocated `bash_N` id. */\n\tasync create(command: string, options: TerminalSessionOptions): Promise<CreatedTerminalSession> {\n\t\tconst release = this.reserve();\n\t\tif (!release) throw new SessionRegistryCapacityError(this.maxSessions);\n\t\tconst runtimeOptions: TerminalRuntimeOptions = { ...options, scrollback: this.scrollback };\n\t\tconst runtime = new TerminalRuntimeSession(command, runtimeOptions);\n\t\tlet entry: { id: string };\n\t\ttry {\n\t\t\tentry = await this.registry.create({ command, session: runtime.session });\n\t\t} catch (error) {\n\t\t\trelease();\n\t\t\truntime.dispose();\n\t\t\truntime.session.kill();\n\t\t\tthrow error;\n\t\t}\n\t\tthis.runtimes.set(entry.id, runtime);\n\t\truntime.session.onExit(() => {\n\t\t\tthis.exited.add(entry.id);\n\t\t});\n\t\trelease();\n\t\tthis.reconcileRuntimes();\n\t\treturn { id: entry.id, runtime };\n\t}\n\n\t/** Look up a live-or-exited session, refreshing its LRU timestamp. */\n\tget(id: string): TerminalRuntimeSession | null {\n\t\tconst entry = this.registry.get(id);\n\t\tif (!entry) return null;\n\t\treturn this.runtimes.get(id) ?? null;\n\t}\n\n\tlist(): { id: string; runtime: TerminalRuntimeSession }[] {\n\t\tconst result: { id: string; runtime: TerminalRuntimeSession }[] = [];\n\t\tfor (const entry of this.registry.list()) {\n\t\t\tconst runtime = this.runtimes.get(entry.id);\n\t\t\tif (runtime) result.push({ id: entry.id, runtime });\n\t\t}\n\t\treturn result;\n\t}\n\n\t/** Tree-kill one session; the exited entry is kept for a final output read until swept. */\n\tasync stop(id: string): Promise<boolean> {\n\t\tconst stopped = await this.registry.stop(id);\n\t\tthis.reconcileRuntimes();\n\t\treturn stopped;\n\t}\n\n\t/** Tree-kill every session and dispose all runtime wrappers. */\n\tasync teardown(): Promise<void> {\n\t\tawait this.registry.teardown();\n\t\tfor (const runtime of this.runtimes.values()) runtime.dispose();\n\t\tthis.runtimes.clear();\n\t\tthis.exited.clear();\n\t}\n\n\t/** Dispose runtime wrappers whose registry entry was pruned (capacity/LRU eviction). */\n\tprivate reconcileRuntimes(): void {\n\t\tconst liveIds = new Set(this.registry.list().map((entry) => entry.id));\n\t\tfor (const [id, runtime] of this.runtimes) {\n\t\t\tif (liveIds.has(id)) continue;\n\t\t\truntime.dispose();\n\t\t\tthis.runtimes.delete(id);\n\t\t\tthis.exited.delete(id);\n\t\t}\n\t}\n}\n\nexport function isCapacityError(error: unknown): error is SessionRegistryCapacityError {\n\treturn error instanceof SessionRegistryCapacityError;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,4BAA4B,GAG5B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAA+B,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAYtE;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAU3B,YAAY,UAAkC,EAAE;QAR/B,aAAQ,GAAG,IAAI,GAAG,EAAkC,CAAC;QACtE,yHAAyH;QACxG,eAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QAGvC,WAAM,GAAG,IAAI,GAAG,EAAU,CAAC;QACpC,iBAAY,GAAG,CAAC,CAAC;QAGxB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,oBAAoB,CAAC;QAC/D,IAAI,CAAC,QAAQ,GAAG,IAAI,eAAe,CAAkB,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QACxF,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACtC,CAAC;IAED,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,IAAI,UAAU;QACb,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC;IAClE,CAAC;IAED,OAAO;QACN,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,GAAG,IAAI,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,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YACzD,CAAC;QACF,CAAC;IACF,CAAC;CACD;AAED,MAAM,UAAU,eAAe,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,4BAA4B,CAAC;AACtD,CAAC","sourcesContent":["import {\n\tSessionRegistry,\n\tSessionRegistryCapacityError,\n\ttype TerminalSession,\n\ttype TerminalSessionOptions,\n} from \"@earendil-works/pi-pty\";\nimport { type TerminalRuntimeOptions, TerminalRuntimeSession } from \"./runtime-session.ts\";\nimport { DEFAULT_MAX_SESSIONS } from \"./shared.ts\";\n\nexport { SessionRegistryCapacityError } from \"@earendil-works/pi-pty\";\n\nexport interface TerminalManagerOptions {\n\treadonly maxSessions?: number;\n\treadonly scrollback?: number;\n}\n\nexport interface CreatedTerminalSession {\n\treadonly id: string;\n\treadonly runtime: TerminalRuntimeSession;\n}\n\n/**\n * Owns the live terminal sessions for one agent session. Delegates id allocation,\n * capacity caps, LRU-exited pruning, and tree-kill teardown to the pi-pty\n * {@link SessionRegistry}, while keeping the richer {@link TerminalRuntimeSession}\n * wrappers (screen model + output buffer) in lock-step.\n */\nexport class TerminalManager {\n\tprivate readonly registry: SessionRegistry<TerminalSession>;\n\tprivate readonly runtimes = new Map<string, TerminalRuntimeSession>();\n\t/** Stable \"mon_\" identities bound to runtime session ids; survives PTY exit, then drops on session prune or teardown. */\n\tprivate readonly monitorIds = new Map<string, string>();\n\tprivate readonly scrollback?: number;\n\tprivate readonly maxSessions: number;\n\tprivate readonly exited = new Set<string>();\n\tprivate reservations = 0;\n\n\tconstructor(options: TerminalManagerOptions = {}) {\n\t\tthis.maxSessions = options.maxSessions ?? DEFAULT_MAX_SESSIONS;\n\t\tthis.registry = new SessionRegistry<TerminalSession>({ maxSessions: this.maxSessions });\n\t\tthis.scrollback = options.scrollback;\n\t}\n\n\tget size(): number {\n\t\treturn this.runtimes.size;\n\t}\n\n\tget activeSize(): number {\n\t\tthis.reconcileRuntimes();\n\t\treturn this.runtimes.size - this.exited.size + this.reservations;\n\t}\n\n\treserve(): (() => void) | null {\n\t\tthis.reconcileRuntimes();\n\t\tif (this.runtimes.size - this.exited.size + this.reservations >= this.maxSessions) return null;\n\t\tthis.reservations += 1;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tthis.reservations -= 1;\n\t\t};\n\t}\n\n\t/** Spawn a new terminal session and register it under an allocated `bash_N` id. */\n\tasync create(command: string, options: TerminalSessionOptions): Promise<CreatedTerminalSession> {\n\t\tconst release = this.reserve();\n\t\tif (!release) throw new SessionRegistryCapacityError(this.maxSessions);\n\t\tconst runtimeOptions: TerminalRuntimeOptions = { ...options, scrollback: this.scrollback };\n\t\tconst runtime = new TerminalRuntimeSession(command, runtimeOptions);\n\t\tlet entry: { id: string };\n\t\ttry {\n\t\t\tentry = await this.registry.create({ command, session: runtime.session });\n\t\t} catch (error) {\n\t\t\trelease();\n\t\t\truntime.dispose();\n\t\t\truntime.session.kill();\n\t\t\tthrow error;\n\t\t}\n\t\tthis.runtimes.set(entry.id, runtime);\n\t\truntime.session.onExit(() => {\n\t\t\tthis.exited.add(entry.id);\n\t\t});\n\t\trelease();\n\t\tthis.reconcileRuntimes();\n\t\treturn { id: entry.id, runtime };\n\t}\n\n\t/** Look up a live-or-exited session, refreshing its LRU timestamp. */\n\tget(id: string): TerminalRuntimeSession | null {\n\t\tconst entry = this.registry.get(id);\n\t\tif (!entry) return null;\n\t\treturn this.runtimes.get(id) ?? null;\n\t}\n\n\t/** Bind a stable \"mon_\" id to its runtime session id; a later restore re-binds the same id. */\n\tbindMonitorId(monitorId: string, sessionId: string): void {\n\t\tthis.monitorIds.set(monitorId, sessionId);\n\t}\n\n\t/**\n\t * Resolve a \"mon_\" monitor id to its current runtime \"bash_N\" (or \"watch_N\"), passing a\n\t * runtime id through unchanged; undefined when neither resolves. Bindings intentionally\n\t * outlive PTY exit for a final output read, then drop when the session is pruned or torn down.\n\t */\n\tresolveId(idOrMonitorId: string): string | undefined {\n\t\tif (idOrMonitorId.startsWith(\"mon_\")) return this.monitorIds.get(idOrMonitorId);\n\t\treturn this.registry.get(idOrMonitorId) ? idOrMonitorId : undefined;\n\t}\n\n\tlist(): { id: string; runtime: TerminalRuntimeSession }[] {\n\t\tconst result: { id: string; runtime: TerminalRuntimeSession }[] = [];\n\t\tfor (const entry of this.registry.list()) {\n\t\t\tconst runtime = this.runtimes.get(entry.id);\n\t\t\tif (runtime) result.push({ id: entry.id, runtime });\n\t\t}\n\t\treturn result;\n\t}\n\n\t/** Tree-kill one session; the exited entry is kept for a final output read until swept. */\n\tasync stop(id: string): Promise<boolean> {\n\t\tconst stopped = await this.registry.stop(id);\n\t\tthis.reconcileRuntimes();\n\t\treturn stopped;\n\t}\n\n\t/** Tree-kill every session and dispose all runtime wrappers. */\n\tasync teardown(): Promise<void> {\n\t\tawait this.registry.teardown();\n\t\tfor (const runtime of this.runtimes.values()) runtime.dispose();\n\t\tthis.runtimes.clear();\n\t\tthis.exited.clear();\n\t\tthis.monitorIds.clear();\n\t}\n\n\t/** Dispose runtime wrappers whose registry entry was pruned (capacity/LRU eviction). */\n\tprivate reconcileRuntimes(): void {\n\t\tconst liveIds = new Set(this.registry.list().map((entry) => entry.id));\n\t\tfor (const [id, runtime] of this.runtimes) {\n\t\t\tif (liveIds.has(id)) continue;\n\t\t\truntime.dispose();\n\t\t\tthis.runtimes.delete(id);\n\t\t\tthis.exited.delete(id);\n\t\t\tfor (const [monitorId, sessionId] of this.monitorIds) {\n\t\t\t\tif (sessionId === id) this.monitorIds.delete(monitorId);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function isCapacityError(error: unknown): error is SessionRegistryCapacityError {\n\treturn error instanceof SessionRegistryCapacityError;\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type AcquireTerminalLeaseOptions = {
|
|
2
|
+
dir: string;
|
|
3
|
+
encodedSessionId: string;
|
|
4
|
+
pid?: number;
|
|
5
|
+
now?: () => number;
|
|
6
|
+
isProcessAlive?: (pid: number) => boolean;
|
|
7
|
+
};
|
|
8
|
+
export type AcquireTerminalLeaseResult = {
|
|
9
|
+
acquired: true;
|
|
10
|
+
path: string;
|
|
11
|
+
pid: number;
|
|
12
|
+
} | {
|
|
13
|
+
acquired: false;
|
|
14
|
+
holder: {
|
|
15
|
+
pid: number;
|
|
16
|
+
startedAtMs: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export declare function acquireTerminalLease(options: AcquireTerminalLeaseOptions): Promise<AcquireTerminalLeaseResult>;
|
|
20
|
+
export declare function releaseTerminalLease(handle: {
|
|
21
|
+
path: string;
|
|
22
|
+
pid: number;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
//# sourceMappingURL=manifest-lease.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest-lease.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/manifest-lease.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,2BAA2B,GAAG;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,0BAA0B,GACnC;IAAE,QAAQ,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC7C;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC;AA2FrE,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAMpH;AAED,wBAAsB,oBAAoB,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAK/F"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { mkdir, open, readFile, unlink } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
function errorCode(error) {
|
|
4
|
+
if (typeof error === "object" && error !== null && "code" in error && typeof error.code === "string") {
|
|
5
|
+
return error.code;
|
|
6
|
+
}
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
function probeAlive(pid, probe) {
|
|
10
|
+
try {
|
|
11
|
+
if (probe)
|
|
12
|
+
return probe(pid);
|
|
13
|
+
process.kill(pid, 0);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
const code = errorCode(error);
|
|
18
|
+
if (code === "EPERM")
|
|
19
|
+
return true;
|
|
20
|
+
if (code === "ESRCH")
|
|
21
|
+
return false;
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function readLease(path) {
|
|
26
|
+
let raw;
|
|
27
|
+
try {
|
|
28
|
+
raw = await readFile(path, "utf8");
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (errorCode(error) === "ENOENT")
|
|
32
|
+
return "missing";
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(raw);
|
|
37
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
38
|
+
return "unparseable";
|
|
39
|
+
const pid = parsed.pid;
|
|
40
|
+
const startedAtMs = parsed.startedAtMs;
|
|
41
|
+
if (typeof pid !== "number" ||
|
|
42
|
+
!Number.isFinite(pid) ||
|
|
43
|
+
typeof startedAtMs !== "number" ||
|
|
44
|
+
!Number.isFinite(startedAtMs)) {
|
|
45
|
+
return "unparseable";
|
|
46
|
+
}
|
|
47
|
+
return { pid, startedAtMs };
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return "unparseable";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function exclusiveCreate(path, record) {
|
|
54
|
+
const file = await open(path, "wx");
|
|
55
|
+
try {
|
|
56
|
+
await file.writeFile(JSON.stringify(record), "utf8");
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
await file.close();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function unlinkIfPresent(path) {
|
|
63
|
+
try {
|
|
64
|
+
await unlink(path);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (errorCode(error) !== "ENOENT")
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function tryAcquire(path, record, isProcessAlive, retry) {
|
|
72
|
+
try {
|
|
73
|
+
await exclusiveCreate(path, record);
|
|
74
|
+
return { acquired: true, path, pid: record.pid };
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (errorCode(error) !== "EEXIST")
|
|
78
|
+
throw error;
|
|
79
|
+
const existing = await readLease(path);
|
|
80
|
+
const reclaimable = existing === "missing" || existing === "unparseable" || !probeAlive(existing.pid, isProcessAlive);
|
|
81
|
+
if (reclaimable && retry) {
|
|
82
|
+
await unlinkIfPresent(path);
|
|
83
|
+
return tryAcquire(path, record, isProcessAlive, false);
|
|
84
|
+
}
|
|
85
|
+
if (existing === "missing" || existing === "unparseable")
|
|
86
|
+
throw error;
|
|
87
|
+
return { acquired: false, holder: existing };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export async function acquireTerminalLease(options) {
|
|
91
|
+
const pid = options.pid ?? process.pid;
|
|
92
|
+
const startedAtMs = (options.now ?? Date.now)();
|
|
93
|
+
const path = join(options.dir, `${options.encodedSessionId}.lease`);
|
|
94
|
+
await mkdir(options.dir, { recursive: true });
|
|
95
|
+
return tryAcquire(path, { pid, startedAtMs }, options.isProcessAlive, true);
|
|
96
|
+
}
|
|
97
|
+
export async function releaseTerminalLease(handle) {
|
|
98
|
+
const existing = await readLease(handle.path);
|
|
99
|
+
if (existing === "missing" || existing === "unparseable")
|
|
100
|
+
return;
|
|
101
|
+
if (existing.pid !== handle.pid)
|
|
102
|
+
return;
|
|
103
|
+
await unlinkIfPresent(handle.path);
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=manifest-lease.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest-lease.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/manifest-lease.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAgBjC,SAAS,SAAS,CAAC,KAAc;IAChC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACtG,OAAO,KAAK,CAAC,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,SAAS,UAAU,CAAC,GAAW,EAAE,KAAgC;IAChE,IAAI,CAAC;QACJ,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,IAAI,KAAK,OAAO;YAAE,OAAO,IAAI,CAAC;QAClC,IAAI,IAAI,KAAK,OA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AAK,UAAU,oBAAoB,CAAC,OAAoC;IAC9E,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IACvC,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAChD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,gBAAgB,QAAQ,CAAC,CAAC;IACpE,MAAM,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,OAAO,UAAU,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;AAC7E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAAqC;IAC/E,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC9C,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,aAAa;QAAE,OAAO;IACjE,IAAI,QAAQ,CAAC,GAAG,KAAK,MAAM,CAAC,GAAG;QAAE,OAAO;IACxC,MAAM,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import { mkdir, open, readFile, unlink } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nexport type AcquireTerminalLeaseOptions = {\n\tdir: string;\n\tencodedSessionId: string;\n\tpid?: number;\n\tnow?: () => number;\n\tisProcessAlive?: (pid: number) => boolean;\n};\n\nexport type AcquireTerminalLeaseResult =\n\t| { acquired: true; path: string; pid: number }\n\t| { acquired: false; holder: { pid: number; startedAtMs: number } };\n\ntype LeaseRecord = { pid: number; startedAtMs: number };\n\nfunction errorCode(error: unknown): string | undefined {\n\tif (typeof error === \"object\" && error !== null && \"code\" in error && typeof error.code === \"string\") {\n\t\treturn error.code;\n\t}\n\treturn undefined;\n}\n\nfunction probeAlive(pid: number, probe?: (pid: number) => boolean): boolean {\n\ttry {\n\t\tif (probe) return probe(pid);\n\t\tprocess.kill(pid, 0);\n\t\treturn true;\n\t} catch (error) {\n\t\tconst code = errorCode(error);\n\t\tif (code === \"EPERM\") return true;\n\t\tif (code === \"ESRCH\") return false;\n\t\tthrow error;\n\t}\n}\n\nasync function readLease(path: string): Promise<LeaseRecord | \"missing\" | \"unparseable\"> {\n\tlet raw: string;\n\ttry {\n\t\traw = await readFile(path, \"utf8\");\n\t} catch (error) {\n\t\tif (errorCode(error) === \"ENOENT\") return \"missing\";\n\t\tthrow error;\n\t}\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(raw);\n\t\tif (typeof parsed !== \"object\" || parsed === null) return \"unparseable\";\n\t\tconst pid = (parsed as { pid?: unknown }).pid;\n\t\tconst startedAtMs = (parsed as { startedAtMs?: unknown }).startedAtMs;\n\t\tif (\n\t\t\ttypeof pid !== \"number\" ||\n\t\t\t!Number.isFinite(pid) ||\n\t\t\ttypeof startedAtMs !== \"number\" ||\n\t\t\t!Number.isFinite(startedAtMs)\n\t\t) {\n\t\t\treturn \"unparseable\";\n\t\t}\n\t\treturn { pid, startedAtMs };\n\t} catch {\n\t\treturn \"unparseable\";\n\t}\n}\n\nasync function exclusiveCreate(path: string, record: LeaseRecord): Promise<void> {\n\tconst file = await open(path, \"wx\");\n\ttry {\n\t\tawait file.writeFile(JSON.stringify(record), \"utf8\");\n\t} finally {\n\t\tawait file.close();\n\t}\n}\n\nasync function unlinkIfPresent(path: string): Promise<void> {\n\ttry {\n\t\tawait unlink(path);\n\t} catch (error) {\n\t\tif (errorCode(error) !== \"ENOENT\") throw error;\n\t}\n}\n\nasync function tryAcquire(\n\tpath: string,\n\trecord: LeaseRecord,\n\tisProcessAlive: ((pid: number) => boolean) | undefined,\n\tretry: boolean,\n): Promise<AcquireTerminalLeaseResult> {\n\ttry {\n\t\tawait exclusiveCreate(path, record);\n\t\treturn { acquired: true, path, pid: record.pid };\n\t} catch (error) {\n\t\tif (errorCode(error) !== \"EEXIST\") throw error;\n\t\tconst existing = await readLease(path);\n\t\tconst reclaimable =\n\t\t\texisting === \"missing\" || existing === \"unparseable\" || !probeAlive(existing.pid, isProcessAlive);\n\t\tif (reclaimable && retry) {\n\t\t\tawait unlinkIfPresent(path);\n\t\t\treturn tryAcquire(path, record, isProcessAlive, false);\n\t\t}\n\t\tif (existing === \"missing\" || existing === \"unparseable\") throw error;\n\t\treturn { acquired: false, holder: existing };\n\t}\n}\n\nexport async function acquireTerminalLease(options: AcquireTerminalLeaseOptions): Promise<AcquireTerminalLeaseResult> {\n\tconst pid = options.pid ?? process.pid;\n\tconst startedAtMs = (options.now ?? Date.now)();\n\tconst path = join(options.dir, `${options.encodedSessionId}.lease`);\n\tawait mkdir(options.dir, { recursive: true });\n\treturn tryAcquire(path, { pid, startedAtMs }, options.isProcessAlive, true);\n}\n\nexport async function releaseTerminalLease(handle: { path: string; pid: number }): Promise<void> {\n\tconst existing = await readLease(handle.path);\n\tif (existing === \"missing\" || existing === \"unparseable\") return;\n\tif (existing.pid !== handle.pid) return;\n\tawait unlinkIfPresent(handle.path);\n}\n"]}
|
|
@@ -17,8 +17,12 @@ export interface MonitorResumeResult {
|
|
|
17
17
|
readonly id: string;
|
|
18
18
|
readonly mutedDropped: number;
|
|
19
19
|
}
|
|
20
|
+
/** Allocate a stable monitor identity: "mon_" + 16 Crockford base-32 chars (80 random bits). */
|
|
21
|
+
export declare function allocateMonitorId(): string;
|
|
20
22
|
export interface MonitorSnapshotEntry {
|
|
21
23
|
readonly id: string;
|
|
24
|
+
/** Stable "mon_" identity carried alongside the runtime id; always set on live snapshots. */
|
|
25
|
+
readonly monitorId?: string;
|
|
22
26
|
readonly description: string;
|
|
23
27
|
readonly paused: boolean;
|
|
24
28
|
/** Epoch milliseconds when the watch registered; feeds the footer's live elapsed label. */
|
|
@@ -33,6 +37,8 @@ export interface MonitorRegistryOptions {
|
|
|
33
37
|
export interface RegisterFileMonitorOptions {
|
|
34
38
|
readonly description: string;
|
|
35
39
|
readonly path: string;
|
|
40
|
+
/** Caller-supplied stable identity so a restore can re-bind the same "mon_" id. */
|
|
41
|
+
readonly monitorId?: string;
|
|
36
42
|
readonly event: "create" | "modify";
|
|
37
43
|
readonly timeoutMs: number;
|
|
38
44
|
readonly cwd: string;
|
|
@@ -40,6 +46,8 @@ export interface RegisterFileMonitorOptions {
|
|
|
40
46
|
}
|
|
41
47
|
export interface RegisterMonitorOptions {
|
|
42
48
|
readonly id: string;
|
|
49
|
+
/** Caller-supplied stable identity so a restore can re-bind the same "mon_" id. */
|
|
50
|
+
readonly monitorId?: string;
|
|
43
51
|
readonly description: string;
|
|
44
52
|
readonly runtime: TerminalRuntimeSession;
|
|
45
53
|
readonly filter?: RegExp;
|
|
@@ -53,10 +61,13 @@ export declare class MonitorRegistry {
|
|
|
53
61
|
#private;
|
|
54
62
|
constructor(emit: (event: MonitorEvent) => void, options?: MonitorRegistryOptions);
|
|
55
63
|
snapshot(): readonly MonitorSnapshotEntry[];
|
|
56
|
-
registerFile(options: RegisterFileMonitorOptions): Promise<
|
|
64
|
+
registerFile(options: RegisterFileMonitorOptions): Promise<{
|
|
65
|
+
id: string;
|
|
66
|
+
monitorId: string;
|
|
67
|
+
}>;
|
|
57
68
|
stopFile(id: string): Promise<boolean>;
|
|
58
69
|
stopAllFiles(): Promise<number>;
|
|
59
|
-
register(options: RegisterMonitorOptions):
|
|
70
|
+
register(options: RegisterMonitorOptions): string;
|
|
60
71
|
pause(ids: readonly string[]): string[];
|
|
61
72
|
pauseAll(): string[];
|
|
62
73
|
resume(ids?: readonly string[]): MonitorResumeResult[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitor-registry.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/terminal/monitor-registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,sBAAsB,EAAE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ACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB;AAsDD;;;;GAIG;AACH,qBAAa,eAAe;;gBAYf,IAAI,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAMjF,QAAQ,IAAI,SAAS,oBAAoB,EAAE;IAUrC,YAAY,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAiL7F,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOtC,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IA2HrC,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM;IA4BjD,KAAK,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE;IAYvC,QAAQ,IAAI,MAAM,EAAE;IAIpB,MAAM,CAAC,GAAG,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,mBAAmB,EAAE;IAgBtD,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAIhC,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,kBAAkB;IAQrC,OAAO,IAAI,IAAI;CA8Hf"}
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
2
|
import { watch } from "node:fs";
|
|
3
3
|
import { access, lstat, open, realpath, stat } from "node:fs/promises";
|
|
4
4
|
import { basename, dirname, join, resolve } from "node:path";
|
|
5
5
|
import { describeExit } from "./tools/spawn.js";
|
|
6
|
+
const MONITOR_ID_ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
7
|
+
/** Allocate a stable monitor identity: "mon_" + 16 Crockford base-32 chars (80 random bits). */
|
|
8
|
+
export function allocateMonitorId() {
|
|
9
|
+
let id = "mon_";
|
|
10
|
+
let buffer = 0;
|
|
11
|
+
let bits = 0;
|
|
12
|
+
for (const byte of randomBytes(10)) {
|
|
13
|
+
buffer = (buffer << 8) | byte;
|
|
14
|
+
bits += 8;
|
|
15
|
+
while (bits >= 5) {
|
|
16
|
+
bits -= 5;
|
|
17
|
+
id += MONITOR_ID_ALPHABET[(buffer >> bits) & 31];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return id;
|
|
21
|
+
}
|
|
6
22
|
/**
|
|
7
23
|
* Tracks active monitor sessions alongside the terminal manager's existing bash-id registry.
|
|
8
24
|
* Output is deliberately retained only by TerminalRuntimeSession's bounded history; this
|
|
@@ -27,6 +43,7 @@ export class MonitorRegistry {
|
|
|
27
43
|
snapshot() {
|
|
28
44
|
return [...this.#records.values(), ...this.#files.values()].map((record) => ({
|
|
29
45
|
id: record.id,
|
|
46
|
+
monitorId: record.monitorId,
|
|
30
47
|
description: record.description,
|
|
31
48
|
paused: record.paused,
|
|
32
49
|
startedAtMs: record.startedAtMs,
|
|
@@ -181,6 +198,8 @@ export class MonitorRegistry {
|
|
|
181
198
|
}
|
|
182
199
|
const record = {
|
|
183
200
|
id,
|
|
201
|
+
monitorId: options.monitorId ?? allocateMonitorId(),
|
|
202
|
+
sessionId: id,
|
|
184
203
|
description: options.description,
|
|
185
204
|
startedAtMs: Date.now(),
|
|
186
205
|
path,
|
|
@@ -217,7 +236,7 @@ export class MonitorRegistry {
|
|
|
217
236
|
throw new Error(registrationError ?? "Cannot create file monitor: monitor registry is disposed.");
|
|
218
237
|
}
|
|
219
238
|
this.#notifyChange();
|
|
220
|
-
return id;
|
|
239
|
+
return { id, monitorId: record.monitorId };
|
|
221
240
|
}
|
|
222
241
|
async stopFile(id) {
|
|
223
242
|
const record = this.#files.get(id);
|
|
@@ -360,6 +379,8 @@ export class MonitorRegistry {
|
|
|
360
379
|
register(options) {
|
|
361
380
|
const record = {
|
|
362
381
|
id: options.id,
|
|
382
|
+
monitorId: options.monitorId ?? allocateMonitorId(),
|
|
383
|
+
sessionId: options.id,
|
|
363
384
|
description: options.description,
|
|
364
385
|
startedAtMs: Date.now(),
|
|
365
386
|
runtime: options.runtime,
|
|
@@ -380,6 +401,7 @@ export class MonitorRegistry {
|
|
|
380
401
|
record.unsubscribeExit = record.runtime.session.onExit(() => this.#settle(record));
|
|
381
402
|
if (record.runtime.exited)
|
|
382
403
|
this.#settle(record);
|
|
404
|
+
return record.monitorId;
|
|
383
405
|
}
|
|
384
406
|
pause(ids) {
|
|
385
407
|
const paused = [];
|