@cotal-ai/orca 0.11.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/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @cotal-ai/orca
2
+
3
+ The Orca integration: a thin driver over the public `orca` CLI plus a self-registering
4
+ `orca` `Runtime` provider. Importing it registers the runtime with the core `Registry`, so
5
+ the manager can spawn agents into native Orca terminals.
6
+
7
+ **Tier:** `extensions/`. Depends on [`@cotal-ai/core`](../../packages/core); self-registers on
8
+ import.
9
+
10
+ ## What it does
11
+
12
+ - Resolves the launch `cwd` to the enclosing Orca worktree with `orca worktree current --json`,
13
+ then targets that stable worktree id for terminal creation.
14
+ - Runs the agent from the exact launch `cwd`, even though Orca terminals are attached to the
15
+ worktree.
16
+ - Keeps Cotal launch env and credentials out of the Orca command line by writing a private Node
17
+ launcher script, passing only `exec '<node>' '<script>'` to Orca, and deleting the launcher after it loads.
18
+ - Forces Orca CLI lifecycle calls to the local runtime by removing ambient remote-runtime selectors.
19
+ - Uses Orca terminal handles for status, interrupt, and close. Watching is native: switch to the
20
+ Orca tab rather than `cotal attach`.
21
+ - Contributes a `Runtime` only, not a `TerminalLayout` provider for setup layouts.
22
+
23
+ Orca must open terminals with a POSIX-compatible shell that supports `exec` and single-quoted
24
+ arguments. Driver calls are synchronous because Cotal's `Runtime` lifecycle contract is synchronous;
25
+ short probe caches batch status checks and repeated launches from the same cwd.
26
+
27
+ ## Usage
28
+
29
+ Install it into the published CLI:
30
+
31
+ ```bash
32
+ cotal ext add @cotal-ai/orca
33
+ cotal supervise --runtime orca
34
+ ```
35
+
36
+ Library composition roots can still import it explicitly:
37
+
38
+ ```ts
39
+ import "@cotal-ai/orca"; // self-registers
40
+ ```
41
+
42
+ The runtime can also be selected with `runtime: orca` in a mesh manifest.
43
+
44
+ ## Testing
45
+
46
+ `pnpm smoke:orca:live` exercises the driver and runtime directly. `pnpm smoke:orca-e2e:live`
47
+ runs the complete operator journey against live Orca and Claude Code: install this package with
48
+ `cotal ext`, launch a `runtime: orca` manifest, observe the agent through `cotal ps`, then shut down
49
+ and remove the extension.
@@ -0,0 +1,58 @@
1
+ export interface OrcaWorktree {
2
+ id: string;
3
+ path: string;
4
+ displayName?: string;
5
+ }
6
+ export interface OrcaTerminal {
7
+ handle: string;
8
+ ptyId?: string;
9
+ title?: string;
10
+ connected?: boolean;
11
+ writable?: boolean;
12
+ }
13
+ interface OrcaEnvelope<T> {
14
+ ok?: boolean;
15
+ result?: T;
16
+ error?: {
17
+ code?: string;
18
+ message?: string;
19
+ };
20
+ }
21
+ interface TerminalResult {
22
+ terminal?: OrcaTerminal;
23
+ handle?: string;
24
+ }
25
+ export declare class OrcaCliError extends Error {
26
+ readonly code: string;
27
+ constructor(code: string, message: string);
28
+ }
29
+ /** Orca terminals are a local runtime boundary. Never let ambient remote-runtime selectors
30
+ * redirect manager lifecycle calls to another Orca environment. */
31
+ export declare function localCliEnv(env?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
32
+ /** True when an Orca runtime is reachable through the public CLI. */
33
+ export declare function available(): boolean;
34
+ /** Resolve the Orca worktree that encloses `cwd`. Uses `current` first because it is the documented
35
+ * cwd-aware selector, then falls back to exact `path:` checks up the parent chain. */
36
+ export declare function resolveWorktree(cwd: string): OrcaWorktree;
37
+ export declare function createTerminal(opts: {
38
+ worktreeId: string;
39
+ title: string;
40
+ command: string;
41
+ }): OrcaTerminal;
42
+ export declare function showTerminal(handle: string): OrcaEnvelope<TerminalResult>;
43
+ /** Resolve the current handle for a terminal. Orca handles are runtime-scoped, while ptyId stays
44
+ * stable across handle rotation. */
45
+ export declare function currentTerminal(terminal: Pick<OrcaTerminal, "handle" | "ptyId">): OrcaTerminal | undefined;
46
+ export declare function terminalAlive(terminal: Pick<OrcaTerminal, "handle" | "ptyId">): boolean;
47
+ export declare function sendTerminal(handle: string, opts?: {
48
+ text?: string;
49
+ enter?: boolean;
50
+ interrupt?: boolean;
51
+ }): void;
52
+ export declare function closeTerminal(handle: string): boolean;
53
+ /** Close by stable identity. If the handle rotates between resolution and close, refresh by ptyId
54
+ * and retry once instead of treating a stale handle as a successful stop. */
55
+ export declare function closeManagedTerminal(terminal: Pick<OrcaTerminal, "handle" | "ptyId">): void;
56
+ export declare function terminals(): OrcaTerminal[];
57
+ export {};
58
+ //# sourceMappingURL=driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,UAAU,YAAY,CAAC,CAAC;IACtB,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C;AAMD,UAAU,cAAc;IACtB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAaD,qBAAa,YAAa,SAAQ,KAAK;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAGnD;AAMD;mEACmE;AACnE,wBAAgB,WAAW,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAAC,UAAU,CAMnF;AAuFD,qEAAqE;AACrE,wBAAgB,SAAS,IAAI,OAAO,CAYnC;AAED;uFACuF;AACvF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CA0BzD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,YAAY,CAgBzG;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,CAAC,cAAc,CAAC,CAEzE;AAED;oCACoC;AACpC,wBAAgB,eAAe,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,YAAY,GAAG,SAAS,CAiB1G;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,OAAO,CAQvF;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,IAAI,CAOrH;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAYrD;AAED;6EAC6E;AAC7E,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,IAAI,CAM3F;AAED,wBAAgB,SAAS,IAAI,YAAY,EAAE,CAE1C"}
package/dist/driver.js ADDED
@@ -0,0 +1,255 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { existsSync, realpathSync, statSync } from "node:fs";
3
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
4
+ const MAX_BUFFER = 16 * 1024 * 1024;
5
+ const PROBE_CACHE_MS = 250;
6
+ const MAX_WORKTREE_PARENT_PROBES = 12;
7
+ export class OrcaCliError extends Error {
8
+ code;
9
+ constructor(code, message) {
10
+ super(message);
11
+ this.code = code;
12
+ }
13
+ }
14
+ let selectedBin;
15
+ let availableCache;
16
+ let terminalCache;
17
+ /** Orca terminals are a local runtime boundary. Never let ambient remote-runtime selectors
18
+ * redirect manager lifecycle calls to another Orca environment. */
19
+ export function localCliEnv(env = process.env) {
20
+ const clean = { ...env };
21
+ for (const key of Object.keys(clean)) {
22
+ if (key.toUpperCase() === "ORCA_PAIRING_CODE" || key.toUpperCase() === "ORCA_ENVIRONMENT")
23
+ delete clean[key];
24
+ }
25
+ return clean;
26
+ }
27
+ function candidates() {
28
+ const explicit = process.env.COTAL_ORCA_BIN?.trim();
29
+ if (explicit)
30
+ return [explicit];
31
+ return process.platform === "linux" ? ["orca-ide", "orca"] : ["orca", "orca-ide"];
32
+ }
33
+ function errorText(err) {
34
+ const e = err;
35
+ const stderr = Buffer.isBuffer(e.stderr) ? e.stderr.toString("utf8") : e.stderr;
36
+ const stdout = Buffer.isBuffer(e.stdout) ? e.stdout.toString("utf8") : e.stdout;
37
+ return (stderr?.trim() || stdout?.trim() || e.message || String(err)).replace(/\s+/g, " ");
38
+ }
39
+ function execOrca(args, opts = {}) {
40
+ const tried = [];
41
+ const explicit = !!process.env.COTAL_ORCA_BIN?.trim();
42
+ const bins = !explicit && selectedBin ? [selectedBin] : candidates();
43
+ for (const bin of bins) {
44
+ tried.push(bin);
45
+ try {
46
+ const out = execFileSync(bin, args, {
47
+ cwd: opts.cwd,
48
+ env: localCliEnv(),
49
+ encoding: "utf8",
50
+ stdio: ["ignore", "pipe", "pipe"],
51
+ maxBuffer: MAX_BUFFER,
52
+ });
53
+ if (!explicit)
54
+ selectedBin = bin;
55
+ return out;
56
+ }
57
+ catch (err) {
58
+ const e = err;
59
+ if (!selectedBin && e.code === "ENOENT" && bin !== bins[bins.length - 1])
60
+ continue;
61
+ const stdout = Buffer.isBuffer(e.stdout) ? e.stdout.toString("utf8") : e.stdout;
62
+ // Orca reports command failures as a JSON envelope on stdout and exits nonzero.
63
+ // Preserve that envelope so request-level code can handle expected errors by code.
64
+ if (typeof stdout === "string" && stdout.trim()) {
65
+ try {
66
+ const envelope = JSON.parse(stdout);
67
+ if (envelope.ok === false) {
68
+ if (!explicit)
69
+ selectedBin = bin;
70
+ return stdout;
71
+ }
72
+ }
73
+ catch {
74
+ /* fall through to the CLI diagnostic below */
75
+ }
76
+ }
77
+ throw new Error(`orca ${args.join(" ")} failed via ${bin} (exit ${e.status ?? "unknown"}): ${errorText(err)}`);
78
+ }
79
+ }
80
+ throw new Error(`orca CLI not found (tried ${tried.join(", ")}); install/register Orca CLI or set COTAL_ORCA_BIN`);
81
+ }
82
+ function parseEnvelope(stdout, args) {
83
+ try {
84
+ return JSON.parse(stdout);
85
+ }
86
+ catch (e) {
87
+ throw new Error(`orca ${args.join(" ")} returned non-JSON output: ${e.message}`);
88
+ }
89
+ }
90
+ function request(args, opts = {}) {
91
+ return parseEnvelope(execOrca(args, opts), args);
92
+ }
93
+ function requireOk(args, opts = {}) {
94
+ const r = request(args, opts);
95
+ if (r.ok === false) {
96
+ const code = r.error?.code ?? "unknown_error";
97
+ const msg = r.error?.message ?? r.error?.code ?? "unknown Orca error";
98
+ throw new OrcaCliError(code, `orca ${args.join(" ")} failed: ${msg}`);
99
+ }
100
+ if (r.result === undefined)
101
+ throw new Error(`orca ${args.join(" ")} returned no result`);
102
+ return r.result;
103
+ }
104
+ function isUnder(parent, child) {
105
+ const rel = relative(parent, child);
106
+ return rel === "" || (!!rel && !rel.startsWith("..") && !isAbsolute(rel));
107
+ }
108
+ function assertDir(path) {
109
+ if (!existsSync(path))
110
+ throw new Error(`orca runtime: cwd does not exist: ${path}`);
111
+ if (!statSync(path).isDirectory())
112
+ throw new Error(`orca runtime: cwd is not a directory: ${path}`);
113
+ }
114
+ /** True when an Orca runtime is reachable through the public CLI. */
115
+ export function available() {
116
+ const cacheable = !process.env.COTAL_ORCA_BIN?.trim();
117
+ if (cacheable && availableCache && Date.now() - availableCache.at < PROBE_CACHE_MS)
118
+ return availableCache.value;
119
+ try {
120
+ const r = request(["status", "--json"]);
121
+ const value = r.ok === true && r.result?.runtime?.reachable === true;
122
+ if (cacheable)
123
+ availableCache = { at: Date.now(), value };
124
+ return value;
125
+ }
126
+ catch {
127
+ if (cacheable)
128
+ availableCache = { at: Date.now(), value: false };
129
+ return false;
130
+ }
131
+ }
132
+ /** Resolve the Orca worktree that encloses `cwd`. Uses `current` first because it is the documented
133
+ * cwd-aware selector, then falls back to exact `path:` checks up the parent chain. */
134
+ export function resolveWorktree(cwd) {
135
+ const requested = resolve(cwd);
136
+ assertDir(requested);
137
+ const abs = realpathSync(requested);
138
+ const current = request(["worktree", "current", "--json"], { cwd: abs });
139
+ if (current.ok !== false && current.result?.worktree?.id && current.result.worktree.path) {
140
+ const wt = current.result.worktree;
141
+ if (isUnder(realpathSync(wt.path), abs))
142
+ return wt;
143
+ }
144
+ let probes = 0;
145
+ for (let dir = abs; probes < MAX_WORKTREE_PARENT_PROBES; probes++) {
146
+ const shown = request(["worktree", "show", "--worktree", `path:${dir}`, "--json"]);
147
+ if (shown.ok !== false && shown.result?.worktree?.id && shown.result.worktree.path) {
148
+ const wt = shown.result.worktree;
149
+ if (isUnder(realpathSync(wt.path), abs))
150
+ return wt;
151
+ }
152
+ if (shown.ok === false && shown.error?.code && shown.error.code !== "selector_not_found") {
153
+ throw new Error(`orca worktree lookup failed for ${dir}: ${shown.error.message ?? shown.error.code}`);
154
+ }
155
+ const parent = dirname(dir);
156
+ if (parent === dir)
157
+ break;
158
+ dir = parent;
159
+ }
160
+ throw new Error(`orca runtime: ${abs} is not inside an Orca-managed worktree; open/register that project in Orca first`);
161
+ }
162
+ export function createTerminal(opts) {
163
+ const result = requireOk([
164
+ "terminal",
165
+ "create",
166
+ "--worktree",
167
+ `id:${opts.worktreeId}`,
168
+ "--title",
169
+ opts.title,
170
+ "--command",
171
+ opts.command,
172
+ "--json",
173
+ ]);
174
+ const terminal = result.terminal ?? (result.handle ? { handle: result.handle } : undefined);
175
+ if (!terminal?.handle)
176
+ throw new Error("orca terminal create returned no terminal handle");
177
+ terminalCache = undefined;
178
+ return terminal;
179
+ }
180
+ export function showTerminal(handle) {
181
+ return request(["terminal", "show", "--terminal", handle, "--json"]);
182
+ }
183
+ /** Resolve the current handle for a terminal. Orca handles are runtime-scoped, while ptyId stays
184
+ * stable across handle rotation. */
185
+ export function currentTerminal(terminal) {
186
+ if (!terminalCache || Date.now() - terminalCache.at >= PROBE_CACHE_MS) {
187
+ const listed = requireOk(["terminal", "list", "--json"]).terminals ?? [];
188
+ terminalCache = { at: Date.now(), terminals: listed };
189
+ }
190
+ const listed = terminal.ptyId
191
+ ? terminalCache.terminals.find((candidate) => candidate.ptyId === terminal.ptyId)
192
+ : terminalCache.terminals.find((candidate) => candidate.handle === terminal.handle);
193
+ if (listed)
194
+ return { ...terminal, ...listed };
195
+ const shown = showTerminal(terminal.handle);
196
+ if (shown.ok === false) {
197
+ const code = shown.error?.code ?? "";
198
+ if (/not_found|stale|closed/i.test(code))
199
+ return undefined;
200
+ throw new OrcaCliError(code, `orca terminal show failed: ${shown.error?.message ?? code}`);
201
+ }
202
+ return shown.result?.terminal ?? terminal;
203
+ }
204
+ export function terminalAlive(terminal) {
205
+ try {
206
+ const current = currentTerminal(terminal);
207
+ return current ? current.connected !== false : false;
208
+ }
209
+ catch {
210
+ // Status drives teardown. An unreachable CLI is not positive evidence that the agent exited.
211
+ return true;
212
+ }
213
+ }
214
+ export function sendTerminal(handle, opts = {}) {
215
+ const args = ["terminal", "send", "--terminal", handle];
216
+ if (opts.text !== undefined)
217
+ args.push("--text", opts.text);
218
+ if (opts.enter)
219
+ args.push("--enter");
220
+ if (opts.interrupt)
221
+ args.push("--interrupt");
222
+ args.push("--json");
223
+ requireOk(args);
224
+ }
225
+ export function closeTerminal(handle) {
226
+ try {
227
+ const r = request(["terminal", "close", "--terminal", handle, "--json"]);
228
+ if (r.ok === false) {
229
+ const code = r.error?.code ?? "";
230
+ if (/not_found|stale|closed/i.test(code))
231
+ return false;
232
+ throw new Error(`orca terminal close failed for ${handle}: ${r.error?.message ?? code}`);
233
+ }
234
+ return true;
235
+ }
236
+ finally {
237
+ terminalCache = undefined;
238
+ }
239
+ }
240
+ /** Close by stable identity. If the handle rotates between resolution and close, refresh by ptyId
241
+ * and retry once instead of treating a stale handle as a successful stop. */
242
+ export function closeManagedTerminal(terminal) {
243
+ const current = currentTerminal(terminal);
244
+ if (!current)
245
+ return;
246
+ if (closeTerminal(current.handle) || !current.ptyId)
247
+ return;
248
+ const rotated = currentTerminal(current);
249
+ if (rotated && rotated.handle !== current.handle)
250
+ closeTerminal(rotated.handle);
251
+ }
252
+ export function terminals() {
253
+ return requireOk(["terminal", "list", "--json"]).terminals ?? [];
254
+ }
255
+ //# sourceMappingURL=driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.js","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnE,MAAM,UAAU,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AACpC,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,0BAA0B,GAAG,EAAE,CAAC;AA0CtC,MAAM,OAAO,YAAa,SAAQ,KAAK;IAChB;IAArB,YAAqB,IAAY,EAAE,OAAe;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QADI,SAAI,GAAJ,IAAI,CAAQ;IAEjC,CAAC;CACF;AAED,IAAI,WAA+B,CAAC;AACpC,IAAI,cAA0D,CAAC;AAC/D,IAAI,aAAoE,CAAC;AAEzE;mEACmE;AACnE,MAAM,UAAU,WA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,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAClF,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,SAAS,CAAqB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC;AACvF,CAAC"}
@@ -0,0 +1,6 @@
1
+ /** @cotal-ai/orca — the Orca integration: a thin driver over the public Orca CLI plus a
2
+ * self-registering `orca` Runtime provider. Importing the package registers it with the core
3
+ * Registry, so the manager can spawn agents into the Orca worktree matching each launch cwd. */
4
+ export * as orca from "./driver.js";
5
+ export { OrcaRuntime, orcaRuntimeProvider } from "./runtime.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;iGAEiG;AACjG,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ /** @cotal-ai/orca — the Orca integration: a thin driver over the public Orca CLI plus a
2
+ * self-registering `orca` Runtime provider. Importing the package registers it with the core
3
+ * Registry, so the manager can spawn agents into the Orca worktree matching each launch cwd. */
4
+ export * as orca from "./driver.js";
5
+ export { OrcaRuntime, orcaRuntimeProvider } from "./runtime.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;iGAEiG;AACjG,OAAO,KAAK,IAAI,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type AgentHandle, type LaunchSpec, type Runtime, type RuntimeProvider } from "@cotal-ai/core";
2
+ export interface PrivateLauncher {
3
+ command: string;
4
+ dir: string;
5
+ script: string;
6
+ }
7
+ export declare function privateLauncher(spec: LaunchSpec, cwd: string): PrivateLauncher;
8
+ /** Spawns each managed agent into an Orca terminal in the Orca worktree enclosing the launch cwd. */
9
+ export declare class OrcaRuntime implements Runtime {
10
+ #private;
11
+ readonly kind: "orca";
12
+ spawn(name: string, spec: LaunchSpec, cwd: string): AgentHandle;
13
+ }
14
+ /** Self-registering runtime provider — `import "@cotal-ai/orca"` makes the manager's `orca`
15
+ * runtime available without the manager depending on this package. */
16
+ export declare const orcaRuntimeProvider: RuntimeProvider;
17
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAexB,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB;AAqBD,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,eAAe,CAQ9E;AAsBD,qGAAqG;AACrG,qBAAa,WAAY,YAAW,OAAO;;IACzC,QAAQ,CAAC,IAAI,EAAG,MAAM,CAAU;IAShC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW;CAoFhE;AAED;uEACuE;AACvE,eAAO,MAAM,mBAAmB,EAAE,eAKjC,CAAC"}
@@ -0,0 +1,167 @@
1
+ import { mkdtempSync, realpathSync, rmSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { tmpdir } from "node:os";
4
+ import { hardenPrivate, registry, writeSecretFile, } from "@cotal-ai/core";
5
+ import * as orca from "./driver.js";
6
+ const GRACE_MS = 2_000;
7
+ const CONFIRM_INTERVAL_MS = 1_000;
8
+ const MAX_CONFIRMS = 5;
9
+ const MAX_WORKTREE_CACHE = 32;
10
+ function shellQuote(s) {
11
+ return `'${s.replace(/'/g, "'\\''")}'`;
12
+ }
13
+ function launcherSource(payload) {
14
+ return `import { spawn } from "node:child_process";\n` +
15
+ `import { rmSync } from "node:fs";\n` +
16
+ `const launch = ${JSON.stringify(payload)};\n` +
17
+ `try { rmSync(new URL(".", import.meta.url), { recursive: true, force: true }); } catch {}\n` +
18
+ `process.chdir(launch.cwd);\n` +
19
+ `const child = spawn(launch.command, launch.args, { env: launch.env, stdio: "inherit", windowsHide: false });\n` +
20
+ `let exiting = false;\n` +
21
+ `const forward = (signal) => { if (!exiting && child.pid) child.kill(signal); };\n` +
22
+ `process.on("SIGINT", () => forward("SIGINT"));\n` +
23
+ `process.on("SIGTERM", () => forward("SIGTERM"));\n` +
24
+ `child.on("error", (err) => { console.error("[cotal-orca-launch] " + launch.command + ": " + err.message); process.exit(127); });\n` +
25
+ `child.on("exit", (code, signal) => { exiting = true; if (signal) process.exit(128); process.exit(code ?? 0); });\n`;
26
+ }
27
+ export function privateLauncher(spec, cwd) {
28
+ const dir = mkdtempSync(join(tmpdir(), "cotal-orca-"));
29
+ hardenPrivate(dir, "dir");
30
+ const script = join(dir, "launch.mjs");
31
+ writeSecretFile(script, launcherSource({ cwd, command: spec.command, args: spec.args, env: spec.env ?? {} }));
32
+ // Orca types --command into an interactive shell. exec makes terminal connectivity track
33
+ // launcher lifetime, while single-quote escaping prevents shell interpolation in temp paths.
34
+ return { command: `exec ${shellQuote(process.execPath)} ${shellQuote(script)}`, dir, script };
35
+ }
36
+ function cleanupLauncher(launcher) {
37
+ try {
38
+ rmSync(launcher.dir, { recursive: true, force: true });
39
+ }
40
+ catch {
41
+ /* the launcher also removes itself after loading */
42
+ }
43
+ }
44
+ function scheduleConfirm(handle) {
45
+ for (let i = 1; i <= MAX_CONFIRMS; i++) {
46
+ setTimeout(() => {
47
+ try {
48
+ orca.sendTerminal(handle(), { enter: true });
49
+ }
50
+ catch {
51
+ /* terminal may already be gone */
52
+ }
53
+ }, i * CONFIRM_INTERVAL_MS);
54
+ }
55
+ }
56
+ /** Spawns each managed agent into an Orca terminal in the Orca worktree enclosing the launch cwd. */
57
+ export class OrcaRuntime {
58
+ kind = "orca";
59
+ #worktrees = new Map();
60
+ #cacheWorktree(cwd, worktree) {
61
+ this.#worktrees.delete(cwd);
62
+ this.#worktrees.set(cwd, worktree);
63
+ if (this.#worktrees.size > MAX_WORKTREE_CACHE)
64
+ this.#worktrees.delete(this.#worktrees.keys().next().value);
65
+ }
66
+ spawn(name, spec, cwd) {
67
+ if (!/^[A-Za-z0-9_.-]+$/.test(name))
68
+ throw new Error(`orca runtime: unsafe agent name ${JSON.stringify(name)} (allowed: letters, digits, _ . -)`);
69
+ if (!orca.available())
70
+ throw new Error("orca runtime: Orca CLI/runtime is not reachable (run `orca status --json`)");
71
+ const cwdKey = realpathSync(cwd);
72
+ let worktree = this.#worktrees.get(cwdKey);
73
+ const cachedWorktree = !!worktree;
74
+ if (!worktree) {
75
+ worktree = orca.resolveWorktree(cwd);
76
+ this.#cacheWorktree(cwdKey, worktree);
77
+ }
78
+ const title = `cotal-${name}`;
79
+ const launcher = privateLauncher(spec, cwd);
80
+ let terminal;
81
+ try {
82
+ terminal = orca.createTerminal({ worktreeId: worktree.id, title, command: launcher.command });
83
+ }
84
+ catch (err) {
85
+ if (cachedWorktree && err instanceof orca.OrcaCliError && /selector_not_found|worktree.*not_found/i.test(err.code)) {
86
+ this.#worktrees.delete(cwdKey);
87
+ worktree = orca.resolveWorktree(cwd);
88
+ this.#cacheWorktree(cwdKey, worktree);
89
+ try {
90
+ terminal = orca.createTerminal({ worktreeId: worktree.id, title, command: launcher.command });
91
+ }
92
+ catch (retryErr) {
93
+ cleanupLauncher(launcher);
94
+ throw retryErr;
95
+ }
96
+ }
97
+ else {
98
+ cleanupLauncher(launcher);
99
+ throw err;
100
+ }
101
+ }
102
+ const current = () => {
103
+ terminal = orca.currentTerminal(terminal) ?? terminal;
104
+ return terminal;
105
+ };
106
+ if (spec.confirm)
107
+ scheduleConfirm(() => current().handle);
108
+ return {
109
+ name,
110
+ kind: "orca",
111
+ status: () => (orca.terminalAlive(terminal) ? "running" : "exited"),
112
+ stop: (opts) => {
113
+ if (opts?.graceful === false) {
114
+ try {
115
+ orca.closeManagedTerminal(terminal);
116
+ }
117
+ finally {
118
+ cleanupLauncher(launcher);
119
+ }
120
+ return;
121
+ }
122
+ try {
123
+ orca.sendTerminal(current().handle, { text: "/exit", enter: true });
124
+ }
125
+ catch {
126
+ /* still ensure it closes below */
127
+ }
128
+ setTimeout(() => {
129
+ try {
130
+ orca.closeManagedTerminal(terminal);
131
+ }
132
+ catch (err) {
133
+ console.error(`orca runtime: failed to close terminal for "${name}":`, err);
134
+ }
135
+ finally {
136
+ cleanupLauncher(launcher);
137
+ }
138
+ }, GRACE_MS);
139
+ },
140
+ interrupt: () => {
141
+ try {
142
+ orca.sendTerminal(current().handle, { interrupt: true });
143
+ }
144
+ catch (err) {
145
+ if (err instanceof orca.OrcaCliError && /not_found|stale|closed|not_writable/i.test(err.code))
146
+ return;
147
+ throw err;
148
+ }
149
+ },
150
+ attach: () => {
151
+ throw new Error(`orca runtime: watch this agent in Orca terminal ${current().handle}` +
152
+ `${worktree.displayName ? ` (${worktree.displayName})` : ""}; ` +
153
+ `run \`orca terminal switch --terminal ${terminal.handle}\` to focus it`);
154
+ },
155
+ };
156
+ }
157
+ }
158
+ /** Self-registering runtime provider — `import "@cotal-ai/orca"` makes the manager's `orca`
159
+ * runtime available without the manager depending on this package. */
160
+ export const orcaRuntimeProvider = {
161
+ kind: "runtime",
162
+ name: "orca",
163
+ available: () => orca.available(),
164
+ create: () => new OrcaRuntime(),
165
+ };
166
+ registry.register(orcaRuntimeProvider);
167
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot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AAC,MAAM,gBAAgB,CAC3E,CAAC;YACJ,CAAC;SACF,CAAC;IACJ,CAAC;CACF;AAED;uEACuE;AACvE,MAAM,CAAC,MAAM,mBAAmB,GAAoB;IAClD,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE;IACjC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,WAAW,EAAE;CAChC,CAAC;AAEF,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@cotal-ai/orca",
3
+ "description": "Cotal Orca integration: an Orca Runtime provider for spawning agents into the right Orca worktree.",
4
+ "version": "0.11.1",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/Cotal-AI/Cotal.git",
9
+ "directory": "extensions/orca"
10
+ },
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "scripts": {
21
+ "typecheck": "tsc -p tsconfig.json --noEmit",
22
+ "build": "tsc -p tsconfig.json",
23
+ "prepublishOnly": "pnpm run build"
24
+ },
25
+ "peerDependencies": {
26
+ "@cotal-ai/core": "*"
27
+ },
28
+ "devDependencies": {
29
+ "@cotal-ai/core": "workspace:*",
30
+ "tsx": "^4.22.4"
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "publishConfig": {
36
+ "access": "public"
37
+ }
38
+ }