@omnicross/cli-launcher 0.1.0 → 0.1.1

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.d.cts CHANGED
@@ -1,110 +1,12 @@
1
+ import { ProcessSupervisor } from './types.cjs';
2
+ export { ManagedRun, ManagedRunStdin, RunExit, RunRecord, RunRegistry, RunState, SpawnChildInput, SpawnInput, SpawnPtyInput, TerminationReason } from './types.cjs';
1
3
  import { ChildProcess } from 'node:child_process';
4
+ export { PtyAdapterHandle } from './pty-adapter.cjs';
2
5
  import { ProviderConfigSource, UsageRecorderImport } from '@omnicross/core';
3
6
  import { ApiKeyPoolService } from '@omnicross/core/completion/ApiKeyPoolService';
4
7
  import { SubscriptionAuthProfile } from '@omnicross/core/pipeline/SubscriptionAuthSource';
5
8
  import { RouteAuthMode } from '@omnicross/core/provider-proxy';
6
9
 
7
- /**
8
- * Process Supervisor types.
9
- *
10
- * Defines all interfaces for subprocess lifecycle management:
11
- * spawn inputs, run records, exit results, and module contracts.
12
- *
13
- * @module types
14
- */
15
- type RunState = 'starting' | 'running' | 'exiting' | 'exited';
16
- type TerminationReason = 'manual-cancel' | 'overall-timeout' | 'no-output-timeout' | 'spawn-error' | 'signal' | 'exit';
17
- interface SpawnBaseInput {
18
- runId?: string;
19
- sessionId: string;
20
- backendId: string;
21
- scopeKey?: string;
22
- replaceExistingScope?: boolean;
23
- cwd?: string;
24
- env?: Record<string, string>;
25
- timeoutMs?: number;
26
- noOutputTimeoutMs?: number;
27
- captureOutput?: boolean;
28
- onStdout?: (chunk: string) => void;
29
- onStderr?: (chunk: string) => void;
30
- }
31
- interface SpawnChildInput extends SpawnBaseInput {
32
- mode: 'child';
33
- argv: string[];
34
- windowsVerbatimArguments?: boolean;
35
- input?: string;
36
- stdinMode?: 'inherit' | 'pipe-open' | 'pipe-closed';
37
- }
38
- interface SpawnPtyInput extends SpawnBaseInput {
39
- mode: 'pty';
40
- /** Shell executable (defaults: powershell.exe on Windows, /bin/bash on Unix). */
41
- shell?: string;
42
- /** Arguments passed to the shell. */
43
- args?: string[];
44
- /** Terminal columns (default: 120). */
45
- cols?: number;
46
- /** Terminal rows (default: 30). */
47
- rows?: number;
48
- }
49
- /** Spawn input union — child-process or PTY mode. */
50
- type SpawnInput = SpawnChildInput | SpawnPtyInput;
51
- interface RunRecord {
52
- runId: string;
53
- sessionId: string;
54
- backendId: string;
55
- scopeKey?: string;
56
- pid?: number;
57
- startedAtMs: number;
58
- lastOutputAtMs: number;
59
- createdAtMs: number;
60
- updatedAtMs: number;
61
- state: RunState;
62
- terminationReason?: TerminationReason;
63
- exitCode?: number | null;
64
- exitSignal?: string | null;
65
- }
66
- interface RunExit {
67
- reason: TerminationReason;
68
- exitCode: number | null;
69
- exitSignal: string | null;
70
- durationMs: number;
71
- stdout: string;
72
- stderr: string;
73
- timedOut: boolean;
74
- noOutputTimedOut: boolean;
75
- }
76
- interface ManagedRunStdin {
77
- write(data: string): void;
78
- end(): void;
79
- destroy(): void;
80
- }
81
- interface ManagedRun {
82
- runId: string;
83
- pid?: number;
84
- startedAtMs: number;
85
- stdin?: ManagedRunStdin;
86
- wait: () => Promise<RunExit>;
87
- cancel: (reason?: TerminationReason) => void;
88
- }
89
- interface ProcessSupervisor {
90
- spawn(input: SpawnInput): ManagedRun;
91
- cancel(runId: string, reason?: TerminationReason): void;
92
- cancelScope(scopeKey: string, reason?: TerminationReason): void;
93
- getRecord(runId: string): RunRecord | undefined;
94
- /** Resize the PTY terminal. No-op for non-PTY runs. */
95
- resizePty(runId: string, cols: number, rows: number): boolean;
96
- }
97
- interface RunRegistry {
98
- add(record: RunRecord): void;
99
- get(runId: string): RunRecord | undefined;
100
- list(): RunRecord[];
101
- listByScope(scopeKey: string): RunRecord[];
102
- updateState(runId: string, state: RunState, patch?: Partial<RunRecord>): void;
103
- touchOutput(runId: string): void;
104
- finalize(runId: string, reason: TerminationReason, exitCode?: number | null, exitSignal?: string | null): void;
105
- delete(runId: string): void;
106
- }
107
-
108
10
  /**
109
11
  * child_process spawn adapter.
110
12
  *
@@ -128,36 +30,6 @@ interface ChildAdapterHandle {
128
30
  dispose: () => void;
129
31
  }
130
32
 
131
- /**
132
- * PTY Adapter — wraps node-pty into the same handle shape
133
- * used by child-adapter, so ProcessSupervisor can manage
134
- * both child_process and PTY sessions uniformly.
135
- *
136
- * node-pty is lazily loaded — the import only happens when
137
- * a PTY spawn is actually requested.
138
- *
139
- * @module pty-adapter
140
- */
141
-
142
- interface PtyAdapterHandle {
143
- pid: number | undefined;
144
- onStdout(cb: (data: string) => void): void;
145
- onStderr(cb: (data: string) => void): void;
146
- stdin: {
147
- write(data: string): void;
148
- end(): void;
149
- destroy(): void;
150
- };
151
- write(data: string): void;
152
- resize(cols: number, rows: number): void;
153
- wait(): Promise<{
154
- code: number | null;
155
- signal: string | null;
156
- }>;
157
- kill(signal?: string): void;
158
- dispose(): void;
159
- }
160
-
161
33
  /**
162
34
  * Per-CLI launch-config builders for the GENUINELY-NEW interceptable backends
163
35
  * (qwen / copilot / opencode) — the OpenAI-Chat-Completions analogue of
@@ -465,4 +337,4 @@ declare function buildCodexLaunchConfig(inputs: CodexLaunchConfigInputs): Promis
465
337
 
466
338
  declare function getProcessSupervisor(): ProcessSupervisor;
467
339
 
468
- export { CHAT_PROXY_BASE_PATH, CLAUDE_PROXY_API_KEY_SENTINEL, CODEX_PROXY_BASE_PATH, CODEX_PROXY_PROVIDER_NAME, type ChatCliBackendId, type ChatCliLaunchConfig, type ChatCliLaunchConfigInputs, type ChildAdapterHandle, type ClaudeCliLaunchConfigInputs, type CodexLaunchConfig, type CodexLaunchConfigInputs, type GeminiCliLaunchConfigInputs, type ManagedRun, type ManagedRunStdin, OPENCODE_PROXY_PROVIDER_ID, OPENCODE_PROXY_TOKEN_ENV, type ProcessSupervisor, type PtyAdapterHandle, type RunExit, type RunRecord, type RunRegistry, type RunState, type SpawnChildInput, type SpawnInput, type SpawnPtyInput, type TerminationReason, buildChatCliLaunchConfig, buildClaudeCliLaunchConfig, buildCodexConfigOverrides, buildCodexLaunchConfig, buildGeminiCliLaunchConfig, getProcessSupervisor };
340
+ export { CHAT_PROXY_BASE_PATH, CLAUDE_PROXY_API_KEY_SENTINEL, CODEX_PROXY_BASE_PATH, CODEX_PROXY_PROVIDER_NAME, type ChatCliBackendId, type ChatCliLaunchConfig, type ChatCliLaunchConfigInputs, type ChildAdapterHandle, type ClaudeCliLaunchConfigInputs, type CodexLaunchConfig, type CodexLaunchConfigInputs, type GeminiCliLaunchConfigInputs, OPENCODE_PROXY_PROVIDER_ID, OPENCODE_PROXY_TOKEN_ENV, ProcessSupervisor, buildChatCliLaunchConfig, buildClaudeCliLaunchConfig, buildCodexConfigOverrides, buildCodexLaunchConfig, buildGeminiCliLaunchConfig, getProcessSupervisor };
package/dist/index.d.ts CHANGED
@@ -1,110 +1,12 @@
1
+ import { ProcessSupervisor } from './types.js';
2
+ export { ManagedRun, ManagedRunStdin, RunExit, RunRecord, RunRegistry, RunState, SpawnChildInput, SpawnInput, SpawnPtyInput, TerminationReason } from './types.js';
1
3
  import { ChildProcess } from 'node:child_process';
4
+ export { PtyAdapterHandle } from './pty-adapter.js';
2
5
  import { ProviderConfigSource, UsageRecorderImport } from '@omnicross/core';
3
6
  import { ApiKeyPoolService } from '@omnicross/core/completion/ApiKeyPoolService';
4
7
  import { SubscriptionAuthProfile } from '@omnicross/core/pipeline/SubscriptionAuthSource';
5
8
  import { RouteAuthMode } from '@omnicross/core/provider-proxy';
6
9
 
7
- /**
8
- * Process Supervisor types.
9
- *
10
- * Defines all interfaces for subprocess lifecycle management:
11
- * spawn inputs, run records, exit results, and module contracts.
12
- *
13
- * @module types
14
- */
15
- type RunState = 'starting' | 'running' | 'exiting' | 'exited';
16
- type TerminationReason = 'manual-cancel' | 'overall-timeout' | 'no-output-timeout' | 'spawn-error' | 'signal' | 'exit';
17
- interface SpawnBaseInput {
18
- runId?: string;
19
- sessionId: string;
20
- backendId: string;
21
- scopeKey?: string;
22
- replaceExistingScope?: boolean;
23
- cwd?: string;
24
- env?: Record<string, string>;
25
- timeoutMs?: number;
26
- noOutputTimeoutMs?: number;
27
- captureOutput?: boolean;
28
- onStdout?: (chunk: string) => void;
29
- onStderr?: (chunk: string) => void;
30
- }
31
- interface SpawnChildInput extends SpawnBaseInput {
32
- mode: 'child';
33
- argv: string[];
34
- windowsVerbatimArguments?: boolean;
35
- input?: string;
36
- stdinMode?: 'inherit' | 'pipe-open' | 'pipe-closed';
37
- }
38
- interface SpawnPtyInput extends SpawnBaseInput {
39
- mode: 'pty';
40
- /** Shell executable (defaults: powershell.exe on Windows, /bin/bash on Unix). */
41
- shell?: string;
42
- /** Arguments passed to the shell. */
43
- args?: string[];
44
- /** Terminal columns (default: 120). */
45
- cols?: number;
46
- /** Terminal rows (default: 30). */
47
- rows?: number;
48
- }
49
- /** Spawn input union — child-process or PTY mode. */
50
- type SpawnInput = SpawnChildInput | SpawnPtyInput;
51
- interface RunRecord {
52
- runId: string;
53
- sessionId: string;
54
- backendId: string;
55
- scopeKey?: string;
56
- pid?: number;
57
- startedAtMs: number;
58
- lastOutputAtMs: number;
59
- createdAtMs: number;
60
- updatedAtMs: number;
61
- state: RunState;
62
- terminationReason?: TerminationReason;
63
- exitCode?: number | null;
64
- exitSignal?: string | null;
65
- }
66
- interface RunExit {
67
- reason: TerminationReason;
68
- exitCode: number | null;
69
- exitSignal: string | null;
70
- durationMs: number;
71
- stdout: string;
72
- stderr: string;
73
- timedOut: boolean;
74
- noOutputTimedOut: boolean;
75
- }
76
- interface ManagedRunStdin {
77
- write(data: string): void;
78
- end(): void;
79
- destroy(): void;
80
- }
81
- interface ManagedRun {
82
- runId: string;
83
- pid?: number;
84
- startedAtMs: number;
85
- stdin?: ManagedRunStdin;
86
- wait: () => Promise<RunExit>;
87
- cancel: (reason?: TerminationReason) => void;
88
- }
89
- interface ProcessSupervisor {
90
- spawn(input: SpawnInput): ManagedRun;
91
- cancel(runId: string, reason?: TerminationReason): void;
92
- cancelScope(scopeKey: string, reason?: TerminationReason): void;
93
- getRecord(runId: string): RunRecord | undefined;
94
- /** Resize the PTY terminal. No-op for non-PTY runs. */
95
- resizePty(runId: string, cols: number, rows: number): boolean;
96
- }
97
- interface RunRegistry {
98
- add(record: RunRecord): void;
99
- get(runId: string): RunRecord | undefined;
100
- list(): RunRecord[];
101
- listByScope(scopeKey: string): RunRecord[];
102
- updateState(runId: string, state: RunState, patch?: Partial<RunRecord>): void;
103
- touchOutput(runId: string): void;
104
- finalize(runId: string, reason: TerminationReason, exitCode?: number | null, exitSignal?: string | null): void;
105
- delete(runId: string): void;
106
- }
107
-
108
10
  /**
109
11
  * child_process spawn adapter.
110
12
  *
@@ -128,36 +30,6 @@ interface ChildAdapterHandle {
128
30
  dispose: () => void;
129
31
  }
130
32
 
131
- /**
132
- * PTY Adapter — wraps node-pty into the same handle shape
133
- * used by child-adapter, so ProcessSupervisor can manage
134
- * both child_process and PTY sessions uniformly.
135
- *
136
- * node-pty is lazily loaded — the import only happens when
137
- * a PTY spawn is actually requested.
138
- *
139
- * @module pty-adapter
140
- */
141
-
142
- interface PtyAdapterHandle {
143
- pid: number | undefined;
144
- onStdout(cb: (data: string) => void): void;
145
- onStderr(cb: (data: string) => void): void;
146
- stdin: {
147
- write(data: string): void;
148
- end(): void;
149
- destroy(): void;
150
- };
151
- write(data: string): void;
152
- resize(cols: number, rows: number): void;
153
- wait(): Promise<{
154
- code: number | null;
155
- signal: string | null;
156
- }>;
157
- kill(signal?: string): void;
158
- dispose(): void;
159
- }
160
-
161
33
  /**
162
34
  * Per-CLI launch-config builders for the GENUINELY-NEW interceptable backends
163
35
  * (qwen / copilot / opencode) — the OpenAI-Chat-Completions analogue of
@@ -465,4 +337,4 @@ declare function buildCodexLaunchConfig(inputs: CodexLaunchConfigInputs): Promis
465
337
 
466
338
  declare function getProcessSupervisor(): ProcessSupervisor;
467
339
 
468
- export { CHAT_PROXY_BASE_PATH, CLAUDE_PROXY_API_KEY_SENTINEL, CODEX_PROXY_BASE_PATH, CODEX_PROXY_PROVIDER_NAME, type ChatCliBackendId, type ChatCliLaunchConfig, type ChatCliLaunchConfigInputs, type ChildAdapterHandle, type ClaudeCliLaunchConfigInputs, type CodexLaunchConfig, type CodexLaunchConfigInputs, type GeminiCliLaunchConfigInputs, type ManagedRun, type ManagedRunStdin, OPENCODE_PROXY_PROVIDER_ID, OPENCODE_PROXY_TOKEN_ENV, type ProcessSupervisor, type PtyAdapterHandle, type RunExit, type RunRecord, type RunRegistry, type RunState, type SpawnChildInput, type SpawnInput, type SpawnPtyInput, type TerminationReason, buildChatCliLaunchConfig, buildClaudeCliLaunchConfig, buildCodexConfigOverrides, buildCodexLaunchConfig, buildGeminiCliLaunchConfig, getProcessSupervisor };
340
+ export { CHAT_PROXY_BASE_PATH, CLAUDE_PROXY_API_KEY_SENTINEL, CODEX_PROXY_BASE_PATH, CODEX_PROXY_PROVIDER_NAME, type ChatCliBackendId, type ChatCliLaunchConfig, type ChatCliLaunchConfigInputs, type ChildAdapterHandle, type ClaudeCliLaunchConfigInputs, type CodexLaunchConfig, type CodexLaunchConfigInputs, type GeminiCliLaunchConfigInputs, OPENCODE_PROXY_PROVIDER_ID, OPENCODE_PROXY_TOKEN_ENV, ProcessSupervisor, buildChatCliLaunchConfig, buildClaudeCliLaunchConfig, buildCodexConfigOverrides, buildCodexLaunchConfig, buildGeminiCliLaunchConfig, getProcessSupervisor };
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/pty-adapter.ts
21
+ var pty_adapter_exports = {};
22
+ __export(pty_adapter_exports, {
23
+ buildPtyEnv: () => buildPtyEnv,
24
+ createPtyAdapter: () => createPtyAdapter
25
+ });
26
+ module.exports = __toCommonJS(pty_adapter_exports);
27
+ function buildPtyEnv(overlay) {
28
+ return overlay ? { ...process.env, ...overlay } : { ...process.env };
29
+ }
30
+ function createPtyAdapter(input) {
31
+ const nodePty = require("node-pty");
32
+ const shell = input.shell ?? (process.platform === "win32" ? "powershell.exe" : "/bin/bash");
33
+ const pty = nodePty.spawn(shell, input.args ?? [], {
34
+ name: "xterm-256color",
35
+ cols: input.cols ?? 120,
36
+ rows: input.rows ?? 30,
37
+ cwd: input.cwd,
38
+ env: buildPtyEnv(input.env)
39
+ });
40
+ const stdoutListeners = [];
41
+ const stderrListeners = [];
42
+ const dataDisposable = pty.onData((data) => {
43
+ for (const cb of stdoutListeners) cb(data);
44
+ });
45
+ let exitResolve = null;
46
+ const exitPromise = new Promise((resolve) => {
47
+ exitResolve = resolve;
48
+ });
49
+ const exitDisposable = pty.onExit(({ exitCode, signal }) => {
50
+ exitResolve?.({ code: exitCode, signal: signal != null ? String(signal) : null });
51
+ });
52
+ let disposed = false;
53
+ return {
54
+ pid: pty.pid,
55
+ onStdout(cb) {
56
+ stdoutListeners.push(cb);
57
+ },
58
+ onStderr(cb) {
59
+ stderrListeners.push(cb);
60
+ },
61
+ stdin: {
62
+ write(data) {
63
+ if (!disposed) pty.write(data);
64
+ },
65
+ end() {
66
+ if (!disposed) pty.write("");
67
+ },
68
+ destroy() {
69
+ }
70
+ },
71
+ write(data) {
72
+ if (!disposed) pty.write(data);
73
+ },
74
+ resize(cols, rows) {
75
+ if (!disposed) pty.resize(cols, rows);
76
+ },
77
+ wait() {
78
+ return exitPromise;
79
+ },
80
+ kill(signal) {
81
+ if (disposed) return;
82
+ try {
83
+ pty.kill(signal);
84
+ } catch {
85
+ }
86
+ },
87
+ dispose() {
88
+ if (disposed) return;
89
+ disposed = true;
90
+ dataDisposable.dispose();
91
+ exitDisposable.dispose();
92
+ try {
93
+ pty.kill();
94
+ } catch {
95
+ }
96
+ }
97
+ };
98
+ }
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ buildPtyEnv,
102
+ createPtyAdapter
103
+ });
@@ -0,0 +1,50 @@
1
+ import { SpawnPtyInput } from './types.cjs';
2
+
3
+ /**
4
+ * PTY Adapter — wraps node-pty into the same handle shape
5
+ * used by child-adapter, so ProcessSupervisor can manage
6
+ * both child_process and PTY sessions uniformly.
7
+ *
8
+ * node-pty is lazily loaded — the import only happens when
9
+ * a PTY spawn is actually requested.
10
+ *
11
+ * @module pty-adapter
12
+ */
13
+
14
+ interface PtyAdapterHandle {
15
+ pid: number | undefined;
16
+ onStdout(cb: (data: string) => void): void;
17
+ onStderr(cb: (data: string) => void): void;
18
+ stdin: {
19
+ write(data: string): void;
20
+ end(): void;
21
+ destroy(): void;
22
+ };
23
+ write(data: string): void;
24
+ resize(cols: number, rows: number): void;
25
+ wait(): Promise<{
26
+ code: number | null;
27
+ signal: string | null;
28
+ }>;
29
+ kill(signal?: string): void;
30
+ dispose(): void;
31
+ }
32
+ /**
33
+ * Build the env object passed to node-pty.spawn.
34
+ *
35
+ * Inherits `process.env` as base so the PTY shell sees PATH/HOME/APPDATA
36
+ * and any directories the host has injected at runtime — notably the bin
37
+ * dirs of portable-installed Node/uv/git. Without this, PTY-mode CLI backends
38
+ * (Claude Code, Codex, Gemini-CLI) silently fail to find host-managed tools
39
+ * because the underlying shell only sees the system-level PATH from the
40
+ * Windows registry / Unix dotfiles, not the augmented `process.env.PATH`.
41
+ *
42
+ * Mirrors the merge already performed in `child-adapter.ts:37`.
43
+ *
44
+ * Exported for direct unit testing — the adapter itself depends on the
45
+ * native `node-pty` module which is awkward to mock from a unit test.
46
+ */
47
+ declare function buildPtyEnv(overlay: Record<string, string> | undefined): Record<string, string>;
48
+ declare function createPtyAdapter(input: SpawnPtyInput): PtyAdapterHandle;
49
+
50
+ export { type PtyAdapterHandle, buildPtyEnv, createPtyAdapter };
@@ -0,0 +1,50 @@
1
+ import { SpawnPtyInput } from './types.js';
2
+
3
+ /**
4
+ * PTY Adapter — wraps node-pty into the same handle shape
5
+ * used by child-adapter, so ProcessSupervisor can manage
6
+ * both child_process and PTY sessions uniformly.
7
+ *
8
+ * node-pty is lazily loaded — the import only happens when
9
+ * a PTY spawn is actually requested.
10
+ *
11
+ * @module pty-adapter
12
+ */
13
+
14
+ interface PtyAdapterHandle {
15
+ pid: number | undefined;
16
+ onStdout(cb: (data: string) => void): void;
17
+ onStderr(cb: (data: string) => void): void;
18
+ stdin: {
19
+ write(data: string): void;
20
+ end(): void;
21
+ destroy(): void;
22
+ };
23
+ write(data: string): void;
24
+ resize(cols: number, rows: number): void;
25
+ wait(): Promise<{
26
+ code: number | null;
27
+ signal: string | null;
28
+ }>;
29
+ kill(signal?: string): void;
30
+ dispose(): void;
31
+ }
32
+ /**
33
+ * Build the env object passed to node-pty.spawn.
34
+ *
35
+ * Inherits `process.env` as base so the PTY shell sees PATH/HOME/APPDATA
36
+ * and any directories the host has injected at runtime — notably the bin
37
+ * dirs of portable-installed Node/uv/git. Without this, PTY-mode CLI backends
38
+ * (Claude Code, Codex, Gemini-CLI) silently fail to find host-managed tools
39
+ * because the underlying shell only sees the system-level PATH from the
40
+ * Windows registry / Unix dotfiles, not the augmented `process.env.PATH`.
41
+ *
42
+ * Mirrors the merge already performed in `child-adapter.ts:37`.
43
+ *
44
+ * Exported for direct unit testing — the adapter itself depends on the
45
+ * native `node-pty` module which is awkward to mock from a unit test.
46
+ */
47
+ declare function buildPtyEnv(overlay: Record<string, string> | undefined): Record<string, string>;
48
+ declare function createPtyAdapter(input: SpawnPtyInput): PtyAdapterHandle;
49
+
50
+ export { type PtyAdapterHandle, buildPtyEnv, createPtyAdapter };
@@ -0,0 +1,84 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
8
+ // src/pty-adapter.ts
9
+ function buildPtyEnv(overlay) {
10
+ return overlay ? { ...process.env, ...overlay } : { ...process.env };
11
+ }
12
+ function createPtyAdapter(input) {
13
+ const nodePty = __require("node-pty");
14
+ const shell = input.shell ?? (process.platform === "win32" ? "powershell.exe" : "/bin/bash");
15
+ const pty = nodePty.spawn(shell, input.args ?? [], {
16
+ name: "xterm-256color",
17
+ cols: input.cols ?? 120,
18
+ rows: input.rows ?? 30,
19
+ cwd: input.cwd,
20
+ env: buildPtyEnv(input.env)
21
+ });
22
+ const stdoutListeners = [];
23
+ const stderrListeners = [];
24
+ const dataDisposable = pty.onData((data) => {
25
+ for (const cb of stdoutListeners) cb(data);
26
+ });
27
+ let exitResolve = null;
28
+ const exitPromise = new Promise((resolve) => {
29
+ exitResolve = resolve;
30
+ });
31
+ const exitDisposable = pty.onExit(({ exitCode, signal }) => {
32
+ exitResolve?.({ code: exitCode, signal: signal != null ? String(signal) : null });
33
+ });
34
+ let disposed = false;
35
+ return {
36
+ pid: pty.pid,
37
+ onStdout(cb) {
38
+ stdoutListeners.push(cb);
39
+ },
40
+ onStderr(cb) {
41
+ stderrListeners.push(cb);
42
+ },
43
+ stdin: {
44
+ write(data) {
45
+ if (!disposed) pty.write(data);
46
+ },
47
+ end() {
48
+ if (!disposed) pty.write("");
49
+ },
50
+ destroy() {
51
+ }
52
+ },
53
+ write(data) {
54
+ if (!disposed) pty.write(data);
55
+ },
56
+ resize(cols, rows) {
57
+ if (!disposed) pty.resize(cols, rows);
58
+ },
59
+ wait() {
60
+ return exitPromise;
61
+ },
62
+ kill(signal) {
63
+ if (disposed) return;
64
+ try {
65
+ pty.kill(signal);
66
+ } catch {
67
+ }
68
+ },
69
+ dispose() {
70
+ if (disposed) return;
71
+ disposed = true;
72
+ dataDisposable.dispose();
73
+ exitDisposable.dispose();
74
+ try {
75
+ pty.kill();
76
+ } catch {
77
+ }
78
+ }
79
+ };
80
+ }
81
+ export {
82
+ buildPtyEnv,
83
+ createPtyAdapter
84
+ };
package/dist/types.cjs ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/types.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Process Supervisor types.
3
+ *
4
+ * Defines all interfaces for subprocess lifecycle management:
5
+ * spawn inputs, run records, exit results, and module contracts.
6
+ *
7
+ * @module types
8
+ */
9
+ type RunState = 'starting' | 'running' | 'exiting' | 'exited';
10
+ type TerminationReason = 'manual-cancel' | 'overall-timeout' | 'no-output-timeout' | 'spawn-error' | 'signal' | 'exit';
11
+ interface SpawnBaseInput {
12
+ runId?: string;
13
+ sessionId: string;
14
+ backendId: string;
15
+ scopeKey?: string;
16
+ replaceExistingScope?: boolean;
17
+ cwd?: string;
18
+ env?: Record<string, string>;
19
+ timeoutMs?: number;
20
+ noOutputTimeoutMs?: number;
21
+ captureOutput?: boolean;
22
+ onStdout?: (chunk: string) => void;
23
+ onStderr?: (chunk: string) => void;
24
+ }
25
+ interface SpawnChildInput extends SpawnBaseInput {
26
+ mode: 'child';
27
+ argv: string[];
28
+ windowsVerbatimArguments?: boolean;
29
+ input?: string;
30
+ stdinMode?: 'inherit' | 'pipe-open' | 'pipe-closed';
31
+ }
32
+ interface SpawnPtyInput extends SpawnBaseInput {
33
+ mode: 'pty';
34
+ /** Shell executable (defaults: powershell.exe on Windows, /bin/bash on Unix). */
35
+ shell?: string;
36
+ /** Arguments passed to the shell. */
37
+ args?: string[];
38
+ /** Terminal columns (default: 120). */
39
+ cols?: number;
40
+ /** Terminal rows (default: 30). */
41
+ rows?: number;
42
+ }
43
+ /** Spawn input union — child-process or PTY mode. */
44
+ type SpawnInput = SpawnChildInput | SpawnPtyInput;
45
+ interface RunRecord {
46
+ runId: string;
47
+ sessionId: string;
48
+ backendId: string;
49
+ scopeKey?: string;
50
+ pid?: number;
51
+ startedAtMs: number;
52
+ lastOutputAtMs: number;
53
+ createdAtMs: number;
54
+ updatedAtMs: number;
55
+ state: RunState;
56
+ terminationReason?: TerminationReason;
57
+ exitCode?: number | null;
58
+ exitSignal?: string | null;
59
+ }
60
+ interface RunExit {
61
+ reason: TerminationReason;
62
+ exitCode: number | null;
63
+ exitSignal: string | null;
64
+ durationMs: number;
65
+ stdout: string;
66
+ stderr: string;
67
+ timedOut: boolean;
68
+ noOutputTimedOut: boolean;
69
+ }
70
+ interface ManagedRunStdin {
71
+ write(data: string): void;
72
+ end(): void;
73
+ destroy(): void;
74
+ }
75
+ interface ManagedRun {
76
+ runId: string;
77
+ pid?: number;
78
+ startedAtMs: number;
79
+ stdin?: ManagedRunStdin;
80
+ wait: () => Promise<RunExit>;
81
+ cancel: (reason?: TerminationReason) => void;
82
+ }
83
+ interface ProcessSupervisor {
84
+ spawn(input: SpawnInput): ManagedRun;
85
+ cancel(runId: string, reason?: TerminationReason): void;
86
+ cancelScope(scopeKey: string, reason?: TerminationReason): void;
87
+ getRecord(runId: string): RunRecord | undefined;
88
+ /** Resize the PTY terminal. No-op for non-PTY runs. */
89
+ resizePty(runId: string, cols: number, rows: number): boolean;
90
+ }
91
+ interface RunRegistry {
92
+ add(record: RunRecord): void;
93
+ get(runId: string): RunRecord | undefined;
94
+ list(): RunRecord[];
95
+ listByScope(scopeKey: string): RunRecord[];
96
+ updateState(runId: string, state: RunState, patch?: Partial<RunRecord>): void;
97
+ touchOutput(runId: string): void;
98
+ finalize(runId: string, reason: TerminationReason, exitCode?: number | null, exitSignal?: string | null): void;
99
+ delete(runId: string): void;
100
+ }
101
+
102
+ export type { ManagedRun, ManagedRunStdin, ProcessSupervisor, RunExit, RunRecord, RunRegistry, RunState, SpawnBaseInput, SpawnChildInput, SpawnInput, SpawnPtyInput, TerminationReason };
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Process Supervisor types.
3
+ *
4
+ * Defines all interfaces for subprocess lifecycle management:
5
+ * spawn inputs, run records, exit results, and module contracts.
6
+ *
7
+ * @module types
8
+ */
9
+ type RunState = 'starting' | 'running' | 'exiting' | 'exited';
10
+ type TerminationReason = 'manual-cancel' | 'overall-timeout' | 'no-output-timeout' | 'spawn-error' | 'signal' | 'exit';
11
+ interface SpawnBaseInput {
12
+ runId?: string;
13
+ sessionId: string;
14
+ backendId: string;
15
+ scopeKey?: string;
16
+ replaceExistingScope?: boolean;
17
+ cwd?: string;
18
+ env?: Record<string, string>;
19
+ timeoutMs?: number;
20
+ noOutputTimeoutMs?: number;
21
+ captureOutput?: boolean;
22
+ onStdout?: (chunk: string) => void;
23
+ onStderr?: (chunk: string) => void;
24
+ }
25
+ interface SpawnChildInput extends SpawnBaseInput {
26
+ mode: 'child';
27
+ argv: string[];
28
+ windowsVerbatimArguments?: boolean;
29
+ input?: string;
30
+ stdinMode?: 'inherit' | 'pipe-open' | 'pipe-closed';
31
+ }
32
+ interface SpawnPtyInput extends SpawnBaseInput {
33
+ mode: 'pty';
34
+ /** Shell executable (defaults: powershell.exe on Windows, /bin/bash on Unix). */
35
+ shell?: string;
36
+ /** Arguments passed to the shell. */
37
+ args?: string[];
38
+ /** Terminal columns (default: 120). */
39
+ cols?: number;
40
+ /** Terminal rows (default: 30). */
41
+ rows?: number;
42
+ }
43
+ /** Spawn input union — child-process or PTY mode. */
44
+ type SpawnInput = SpawnChildInput | SpawnPtyInput;
45
+ interface RunRecord {
46
+ runId: string;
47
+ sessionId: string;
48
+ backendId: string;
49
+ scopeKey?: string;
50
+ pid?: number;
51
+ startedAtMs: number;
52
+ lastOutputAtMs: number;
53
+ createdAtMs: number;
54
+ updatedAtMs: number;
55
+ state: RunState;
56
+ terminationReason?: TerminationReason;
57
+ exitCode?: number | null;
58
+ exitSignal?: string | null;
59
+ }
60
+ interface RunExit {
61
+ reason: TerminationReason;
62
+ exitCode: number | null;
63
+ exitSignal: string | null;
64
+ durationMs: number;
65
+ stdout: string;
66
+ stderr: string;
67
+ timedOut: boolean;
68
+ noOutputTimedOut: boolean;
69
+ }
70
+ interface ManagedRunStdin {
71
+ write(data: string): void;
72
+ end(): void;
73
+ destroy(): void;
74
+ }
75
+ interface ManagedRun {
76
+ runId: string;
77
+ pid?: number;
78
+ startedAtMs: number;
79
+ stdin?: ManagedRunStdin;
80
+ wait: () => Promise<RunExit>;
81
+ cancel: (reason?: TerminationReason) => void;
82
+ }
83
+ interface ProcessSupervisor {
84
+ spawn(input: SpawnInput): ManagedRun;
85
+ cancel(runId: string, reason?: TerminationReason): void;
86
+ cancelScope(scopeKey: string, reason?: TerminationReason): void;
87
+ getRecord(runId: string): RunRecord | undefined;
88
+ /** Resize the PTY terminal. No-op for non-PTY runs. */
89
+ resizePty(runId: string, cols: number, rows: number): boolean;
90
+ }
91
+ interface RunRegistry {
92
+ add(record: RunRecord): void;
93
+ get(runId: string): RunRecord | undefined;
94
+ list(): RunRecord[];
95
+ listByScope(scopeKey: string): RunRecord[];
96
+ updateState(runId: string, state: RunState, patch?: Partial<RunRecord>): void;
97
+ touchOutput(runId: string): void;
98
+ finalize(runId: string, reason: TerminationReason, exitCode?: number | null, exitSignal?: string | null): void;
99
+ delete(runId: string): void;
100
+ }
101
+
102
+ export type { ManagedRun, ManagedRunStdin, ProcessSupervisor, RunExit, RunRecord, RunRegistry, RunState, SpawnBaseInput, SpawnChildInput, SpawnInput, SpawnPtyInput, TerminationReason };
package/dist/types.js ADDED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnicross/cli-launcher",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Omnicross CLI-launcher — the ProcessSupervisor subprocess-lifecycle mechanism + per-CLI proxy-env wiring.",
5
5
  "license": "MIT",
6
6
  "author": "Sayo (https://github.com/Dumoedss)",