@grackle-ai/runtime-sdk 0.82.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/async-queue.d.ts +13 -0
- package/dist/async-queue.d.ts.map +1 -0
- package/dist/async-queue.js +48 -0
- package/dist/async-queue.js.map +1 -0
- package/dist/base-runtime.d.ts +30 -0
- package/dist/base-runtime.d.ts.map +1 -0
- package/dist/base-runtime.js +23 -0
- package/dist/base-runtime.js.map +1 -0
- package/dist/base-session.d.ts +104 -0
- package/dist/base-session.d.ts.map +1 -0
- package/dist/base-session.js +198 -0
- package/dist/base-session.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +10 -0
- package/dist/logger.js.map +1 -0
- package/dist/runtime-installer.d.ts +43 -0
- package/dist/runtime-installer.d.ts.map +1 -0
- package/dist/runtime-installer.js +275 -0
- package/dist/runtime-installer.js.map +1 -0
- package/dist/runtime-utils.d.ts +97 -0
- package/dist/runtime-utils.d.ts.map +1 -0
- package/dist/runtime-utils.js +291 -0
- package/dist/runtime-utils.js.map +1 -0
- package/dist/runtime.d.ts +63 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +2 -0
- package/dist/runtime.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/worktree.d.ts +30 -0
- package/dist/worktree.d.ts.map +1 -0
- package/dist/worktree.js +115 -0
- package/dist/worktree.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** A simple async queue that implements `AsyncIterable`, allowing consumers to `for await` over pushed items. */
|
|
2
|
+
export declare class AsyncQueue<T> {
|
|
3
|
+
private queue;
|
|
4
|
+
private waiters;
|
|
5
|
+
private closed;
|
|
6
|
+
push(item: T): void;
|
|
7
|
+
shift(): Promise<T | undefined>;
|
|
8
|
+
/** Remove and return all items currently buffered in the queue. */
|
|
9
|
+
drain(): T[];
|
|
10
|
+
close(): void;
|
|
11
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=async-queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-queue.d.ts","sourceRoot":"","sources":["../src/async-queue.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,qBAAa,UAAU,CAAC,CAAC;IACvB,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,OAAO,CAA6C;IAC5D,OAAO,CAAC,MAAM,CAAkB;IAEzB,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAUb,KAAK,IAAI,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAU5C,mEAAmE;IAC5D,KAAK,IAAI,CAAC,EAAE;IAIZ,KAAK,IAAI,IAAI;IAQN,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,qBAAqB,CAAC,CAAC,CAAC;CAQjE"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** A simple async queue that implements `AsyncIterable`, allowing consumers to `for await` over pushed items. */
|
|
2
|
+
export class AsyncQueue {
|
|
3
|
+
queue = [];
|
|
4
|
+
waiters = [];
|
|
5
|
+
closed = false;
|
|
6
|
+
push(item) {
|
|
7
|
+
if (this.closed)
|
|
8
|
+
return;
|
|
9
|
+
if (this.waiters.length > 0) {
|
|
10
|
+
const waiter = this.waiters.shift();
|
|
11
|
+
waiter(item);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
this.queue.push(item);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async shift() {
|
|
18
|
+
if (this.queue.length > 0) {
|
|
19
|
+
return this.queue.shift();
|
|
20
|
+
}
|
|
21
|
+
if (this.closed)
|
|
22
|
+
return undefined;
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
this.waiters.push(resolve);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** Remove and return all items currently buffered in the queue. */
|
|
28
|
+
drain() {
|
|
29
|
+
return this.queue.splice(0);
|
|
30
|
+
}
|
|
31
|
+
close() {
|
|
32
|
+
this.closed = true;
|
|
33
|
+
for (const waiter of this.waiters) {
|
|
34
|
+
waiter(undefined);
|
|
35
|
+
}
|
|
36
|
+
this.waiters.length = 0;
|
|
37
|
+
}
|
|
38
|
+
async *[Symbol.asyncIterator]() {
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- closed changes asynchronously via close()
|
|
40
|
+
while (true) {
|
|
41
|
+
const item = await this.shift();
|
|
42
|
+
if (item === undefined)
|
|
43
|
+
return;
|
|
44
|
+
yield item;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=async-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-queue.js","sourceRoot":"","sources":["../src/async-queue.ts"],"names":[],"mappings":"AAAA,iHAAiH;AACjH,MAAM,OAAO,UAAU;IACb,KAAK,GAAQ,EAAE,CAAC;IAChB,OAAO,GAA0C,EAAE,CAAC;IACpD,MAAM,GAAY,KAAK,CAAC;IAEzB,IAAI,CAAC,IAAO;QACjB,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACxB,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAG,CAAC;YACrC,MAAM,CAAC,IAAI,CAAC,CAAC;QACf,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QAC5B,CAAC;QACD,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO,SAAS,CAAC;QAClC,OAAO,IAAI,OAAO,CAAgB,CAAC,OAAO,EAAE,EAAE;YAC5C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,mEAAmE;IAC5D,KAAK;QACV,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,MAAM,CAAC,SAAS,CAAC,CAAC;QACpB,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QAClC,oHAAoH;QACpH,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YAChC,IAAI,IAAI,KAAK,SAAS;gBAAE,OAAO;YAC/B,MAAM,IAAI,CAAC;QACb,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AgentRuntime, AgentSession, SpawnOptions, ResumeOptions } from "./runtime.js";
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class for agent runtimes that share the spawn/resume pattern.
|
|
4
|
+
*
|
|
5
|
+
* Subclasses implement `createSession()` to construct the runtime-specific session.
|
|
6
|
+
* The `spawn()` and `resume()` methods delegate to `createSession()` with the
|
|
7
|
+
* appropriate parameters.
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class BaseAgentRuntime implements AgentRuntime {
|
|
10
|
+
abstract name: string;
|
|
11
|
+
/**
|
|
12
|
+
* Prompt text used when resuming a session. Defaults to `""`.
|
|
13
|
+
* CopilotRuntime overrides to `"(resumed)"` since the Copilot SDK requires a non-empty prompt.
|
|
14
|
+
*/
|
|
15
|
+
protected resumePrompt: string;
|
|
16
|
+
/**
|
|
17
|
+
* Create a runtime-specific agent session.
|
|
18
|
+
*
|
|
19
|
+
* Called by both `spawn()` and `resume()` with the appropriate parameters.
|
|
20
|
+
*/
|
|
21
|
+
protected abstract createSession(id: string, prompt: string, model: string, maxTurns: number, resumeSessionId?: string, branch?: string, workingDirectory?: string, systemContext?: string, mcpServers?: Record<string, unknown>, hooks?: Record<string, unknown>, mcpBroker?: {
|
|
22
|
+
url: string;
|
|
23
|
+
token: string;
|
|
24
|
+
}, useWorktrees?: boolean): AgentSession;
|
|
25
|
+
/** Create and start a new agent session. */
|
|
26
|
+
spawn(opts: SpawnOptions): AgentSession;
|
|
27
|
+
/** Resume a previously suspended session. */
|
|
28
|
+
resume(opts: ResumeOptions): AgentSession;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=base-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-runtime.d.ts","sourceRoot":"","sources":["../src/base-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE5F;;;;;;GAMG;AACH,8BAAsB,gBAAiB,YAAW,YAAY;IAC5D,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,SAAS,CAAC,YAAY,EAAE,MAAM,CAAM;IAEpC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,CAC9B,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,eAAe,CAAC,EAAE,MAAM,EACxB,MAAM,CAAC,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,MAAM,EACzB,aAAa,CAAC,EAAE,MAAM,EACtB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAC1C,YAAY,CAAC,EAAE,OAAO,GACrB,YAAY;IAEf,4CAA4C;IACrC,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY;IAiB9C,6CAA6C;IACtC,MAAM,CAAC,IAAI,EAAE,aAAa,GAAG,YAAY;CASjD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract base class for agent runtimes that share the spawn/resume pattern.
|
|
3
|
+
*
|
|
4
|
+
* Subclasses implement `createSession()` to construct the runtime-specific session.
|
|
5
|
+
* The `spawn()` and `resume()` methods delegate to `createSession()` with the
|
|
6
|
+
* appropriate parameters.
|
|
7
|
+
*/
|
|
8
|
+
export class BaseAgentRuntime {
|
|
9
|
+
/**
|
|
10
|
+
* Prompt text used when resuming a session. Defaults to `""`.
|
|
11
|
+
* CopilotRuntime overrides to `"(resumed)"` since the Copilot SDK requires a non-empty prompt.
|
|
12
|
+
*/
|
|
13
|
+
resumePrompt = "";
|
|
14
|
+
/** Create and start a new agent session. */
|
|
15
|
+
spawn(opts) {
|
|
16
|
+
return this.createSession(opts.sessionId, opts.prompt, opts.model, opts.maxTurns, undefined, opts.branch, opts.workingDirectory, opts.systemContext, opts.mcpServers, opts.hooks, opts.mcpBroker, opts.useWorktrees);
|
|
17
|
+
}
|
|
18
|
+
/** Resume a previously suspended session. */
|
|
19
|
+
resume(opts) {
|
|
20
|
+
return this.createSession(opts.sessionId, this.resumePrompt, "", 0, opts.runtimeSessionId);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=base-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-runtime.js","sourceRoot":"","sources":["../src/base-runtime.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,OAAgB,gBAAgB;IAGpC;;;OAGG;IACO,YAAY,GAAW,EAAE,CAAC;IAsBpC,4CAA4C;IACrC,KAAK,CAAC,IAAkB;QAC7B,OAAO,IAAI,CAAC,aAAa,CACvB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,QAAQ,EACb,SAAS,EACT,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,gBAAgB,EACrB,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,YAAY,CAClB,CAAC;IACJ,CAAC;IAED,6CAA6C;IACtC,MAAM,CAAC,IAAmB;QAC/B,OAAO,IAAI,CAAC,aAAa,CACvB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,YAAY,EACjB,EAAE,EACF,CAAC,EACD,IAAI,CAAC,gBAAgB,CACtB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { AgentSession, AgentEvent } from "./runtime.js";
|
|
2
|
+
import type { SessionStatus } from "@grackle-ai/common";
|
|
3
|
+
import { AsyncQueue } from "./async-queue.js";
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for agent sessions that use the eventQueue + waiting_input lifecycle.
|
|
6
|
+
*
|
|
7
|
+
* Provides the shared session lifecycle:
|
|
8
|
+
* - `stream()` yields an initial system message, drives `runSession()` in the background,
|
|
9
|
+
* and yields events from the queue.
|
|
10
|
+
* - `runSession()` calls `setupSdk()`, handles resume vs initial query, transitions to waiting_input,
|
|
11
|
+
* then starts the input processing loop.
|
|
12
|
+
* - `sendInput()` enqueues input for sequential processing by the input loop.
|
|
13
|
+
* - `processInputLoop()` dequeues inputs and calls `executeFollowUp()` one at a time,
|
|
14
|
+
* preventing concurrent follow-ups across all runtimes.
|
|
15
|
+
* - `kill()` aborts active work, closes the input queue, releases resources, and closes the event queue.
|
|
16
|
+
*
|
|
17
|
+
* Subclasses implement the SDK-specific abstract methods.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class BaseAgentSession implements AgentSession {
|
|
20
|
+
id: string;
|
|
21
|
+
abstract runtimeName: string;
|
|
22
|
+
runtimeSessionId: string;
|
|
23
|
+
status: SessionStatus;
|
|
24
|
+
protected readonly eventQueue: AsyncQueue<AgentEvent>;
|
|
25
|
+
private readonly inputQueue;
|
|
26
|
+
protected killed: boolean;
|
|
27
|
+
protected readonly prompt: string;
|
|
28
|
+
protected readonly model: string;
|
|
29
|
+
protected readonly maxTurns: number;
|
|
30
|
+
protected readonly resumeSessionId?: string;
|
|
31
|
+
protected readonly branch?: string;
|
|
32
|
+
protected readonly workingDirectory?: string;
|
|
33
|
+
protected readonly useWorktrees: boolean;
|
|
34
|
+
protected readonly systemContext?: string;
|
|
35
|
+
protected readonly mcpServers?: Record<string, unknown>;
|
|
36
|
+
protected readonly hooks?: Record<string, unknown>;
|
|
37
|
+
protected readonly mcpBroker?: {
|
|
38
|
+
url: string;
|
|
39
|
+
token: string;
|
|
40
|
+
};
|
|
41
|
+
/** Human-readable display name for system messages (e.g. "Claude Code", "Codex"). */
|
|
42
|
+
protected abstract readonly runtimeDisplayName: string;
|
|
43
|
+
/** Error message displayed when the initial query returns zero messages. */
|
|
44
|
+
protected abstract readonly noMessagesError: string;
|
|
45
|
+
constructor(id: string, prompt: string, model: string, maxTurns: number, resumeSessionId?: string, branch?: string, workingDirectory?: string, systemContext?: string, mcpServers?: Record<string, unknown>, hooks?: Record<string, unknown>, mcpBroker?: {
|
|
46
|
+
url: string;
|
|
47
|
+
token: string;
|
|
48
|
+
}, useWorktrees?: boolean);
|
|
49
|
+
/**
|
|
50
|
+
* Initialize the SDK (import libraries, create instances, resolve worktree).
|
|
51
|
+
* Called once at the start of `runSession()`, before resume checks or initial query.
|
|
52
|
+
*/
|
|
53
|
+
protected abstract setupSdk(): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Perform resume-specific setup (e.g. resume thread, emit system message).
|
|
56
|
+
* Called only when `resumeSessionId` is set.
|
|
57
|
+
*/
|
|
58
|
+
protected abstract setupForResume(): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Run the initial query with the given prompt.
|
|
61
|
+
* Should consume the SDK stream/query and push events to `eventQueue`.
|
|
62
|
+
* Returns the number of meaningful messages processed.
|
|
63
|
+
*/
|
|
64
|
+
protected abstract runInitialQuery(prompt: string): Promise<number>;
|
|
65
|
+
/**
|
|
66
|
+
* Execute a follow-up input on the existing session.
|
|
67
|
+
* Should consume the SDK stream/query and push events to `eventQueue`.
|
|
68
|
+
* Resolves when the follow-up is complete.
|
|
69
|
+
*/
|
|
70
|
+
protected abstract executeFollowUp(text: string): Promise<void>;
|
|
71
|
+
/** Check whether the session is ready to accept follow-up input via `sendInput()`. */
|
|
72
|
+
protected abstract canAcceptInput(): boolean;
|
|
73
|
+
/** Abort the currently active stream or query. */
|
|
74
|
+
protected abstract abortActive(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Release SDK resources for garbage collection.
|
|
77
|
+
* Called on kill and on fatal error. Default is a no-op.
|
|
78
|
+
*/
|
|
79
|
+
protected releaseResources(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Build the initial prompt by combining system context with the user prompt.
|
|
82
|
+
* Subclasses that inject system context via SDK-native mechanisms should
|
|
83
|
+
* override this to return just `this.prompt`.
|
|
84
|
+
*/
|
|
85
|
+
protected buildInitialPrompt(): string;
|
|
86
|
+
stream(): AsyncIterable<AgentEvent>;
|
|
87
|
+
/** Core session logic: setup SDK, handle resume or initial query, transition to waiting_input. */
|
|
88
|
+
private runSession;
|
|
89
|
+
/** Queue follow-up input for sequential processing by the input loop. */
|
|
90
|
+
sendInput(text: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Background loop that dequeues input and calls `executeFollowUp()` sequentially.
|
|
93
|
+
* Started after the initial query (or resume setup) completes. Owns the eventQueue
|
|
94
|
+
* lifecycle — closes it when the loop exits.
|
|
95
|
+
*/
|
|
96
|
+
private processInputLoop;
|
|
97
|
+
/** Fire-and-forget launch of the input processing loop. */
|
|
98
|
+
private startInputLoop;
|
|
99
|
+
/** Forcefully terminate the session. Emits a final status event with the given reason. */
|
|
100
|
+
kill(reason?: string): void;
|
|
101
|
+
/** Drain any buffered events that were not yet consumed by the stream. */
|
|
102
|
+
drainBufferedEvents(): AgentEvent[];
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=base-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-session.d.ts","sourceRoot":"","sources":["../src/base-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C;;;;;;;;;;;;;;GAcG;AACH,8BAAsB,gBAAiB,YAAW,YAAY;IACrD,EAAE,EAAE,MAAM,CAAC;IAClB,SAAgB,WAAW,EAAE,MAAM,CAAC;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,aAAa,CAA0B;IAEtD,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,CAAgC;IACrF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgD;IAC3E,SAAS,CAAC,MAAM,EAAE,OAAO,CAAS;IAClC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,C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CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAC1C,YAAY,CAAC,EAAE,OAAO;IAmBxB;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAE5C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAElD;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAEnE;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAE/D,sFAAsF;IACtF,SAAS,CAAC,QAAQ,CAAC,cAAc,IAAI,OAAO;IAE5C,kDAAkD;IAClD,SAAS,CAAC,QAAQ,CAAC,WAAW,IAAI,IAAI;IAEtC;;;OAGG;IACH,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAIlC;;;;OAIG;IACH,SAAS,CAAC,kBAAkB,IAAI,MAAM;IAQxB,MAAM,IAAI,aAAa,CAAC,UAAU,CAAC;IAmBjD,kGAAkG;YACpF,UAAU;IA4CxB,yEAAyE;IAClE,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAOpC;;;;OAIG;YACW,gBAAgB;IA6B9B,2DAA2D;IAC3D,OAAO,CAAC,cAAc;IAatB,0FAA0F;IACnF,IAAI,CAAC,MAAM,GAAE,MAAiB,GAAG,IAAI;IAmB5C,0EAA0E;IACnE,mBAAmB,IAAI,UAAU,EAAE;CAG3C"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { SESSION_STATUS } from "@grackle-ai/common";
|
|
2
|
+
import { AsyncQueue } from "./async-queue.js";
|
|
3
|
+
import { logger } from "./logger.js";
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for agent sessions that use the eventQueue + waiting_input lifecycle.
|
|
6
|
+
*
|
|
7
|
+
* Provides the shared session lifecycle:
|
|
8
|
+
* - `stream()` yields an initial system message, drives `runSession()` in the background,
|
|
9
|
+
* and yields events from the queue.
|
|
10
|
+
* - `runSession()` calls `setupSdk()`, handles resume vs initial query, transitions to waiting_input,
|
|
11
|
+
* then starts the input processing loop.
|
|
12
|
+
* - `sendInput()` enqueues input for sequential processing by the input loop.
|
|
13
|
+
* - `processInputLoop()` dequeues inputs and calls `executeFollowUp()` one at a time,
|
|
14
|
+
* preventing concurrent follow-ups across all runtimes.
|
|
15
|
+
* - `kill()` aborts active work, closes the input queue, releases resources, and closes the event queue.
|
|
16
|
+
*
|
|
17
|
+
* Subclasses implement the SDK-specific abstract methods.
|
|
18
|
+
*/
|
|
19
|
+
export class BaseAgentSession {
|
|
20
|
+
id;
|
|
21
|
+
runtimeSessionId;
|
|
22
|
+
status = SESSION_STATUS.RUNNING;
|
|
23
|
+
eventQueue = new AsyncQueue();
|
|
24
|
+
inputQueue = new AsyncQueue();
|
|
25
|
+
killed = false;
|
|
26
|
+
prompt;
|
|
27
|
+
model;
|
|
28
|
+
maxTurns;
|
|
29
|
+
resumeSessionId;
|
|
30
|
+
branch;
|
|
31
|
+
workingDirectory;
|
|
32
|
+
useWorktrees;
|
|
33
|
+
systemContext;
|
|
34
|
+
mcpServers;
|
|
35
|
+
hooks;
|
|
36
|
+
mcpBroker;
|
|
37
|
+
constructor(id, prompt, model, maxTurns, resumeSessionId, branch, workingDirectory, systemContext, mcpServers, hooks, mcpBroker, useWorktrees) {
|
|
38
|
+
this.id = id;
|
|
39
|
+
this.prompt = prompt;
|
|
40
|
+
this.model = model;
|
|
41
|
+
this.maxTurns = maxTurns;
|
|
42
|
+
this.resumeSessionId = resumeSessionId;
|
|
43
|
+
this.branch = branch;
|
|
44
|
+
this.workingDirectory = workingDirectory;
|
|
45
|
+
this.useWorktrees = useWorktrees ?? true;
|
|
46
|
+
this.systemContext = systemContext;
|
|
47
|
+
this.mcpServers = mcpServers;
|
|
48
|
+
this.hooks = hooks;
|
|
49
|
+
this.mcpBroker = mcpBroker;
|
|
50
|
+
this.runtimeSessionId = resumeSessionId || "";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Release SDK resources for garbage collection.
|
|
54
|
+
* Called on kill and on fatal error. Default is a no-op.
|
|
55
|
+
*/
|
|
56
|
+
releaseResources() {
|
|
57
|
+
// Default: no-op. Override in subclasses that hold SDK references.
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build the initial prompt by combining system context with the user prompt.
|
|
61
|
+
* Subclasses that inject system context via SDK-native mechanisms should
|
|
62
|
+
* override this to return just `this.prompt`.
|
|
63
|
+
*/
|
|
64
|
+
buildInitialPrompt() {
|
|
65
|
+
return this.systemContext
|
|
66
|
+
? `${this.systemContext}\n\n---\n\n${this.prompt}`
|
|
67
|
+
: this.prompt;
|
|
68
|
+
}
|
|
69
|
+
// ─── Shared lifecycle implementation ──────────────────────
|
|
70
|
+
async *stream() {
|
|
71
|
+
const ts = () => new Date().toISOString();
|
|
72
|
+
yield { type: "system", timestamp: ts(), content: `Starting ${this.runtimeDisplayName} runtime...` };
|
|
73
|
+
// Drive the session in the background; events are pushed to the queue
|
|
74
|
+
// and yielded from this generator.
|
|
75
|
+
this.runSession().catch((err) => {
|
|
76
|
+
this.eventQueue.push({ type: "error", timestamp: ts(), content: String(err) });
|
|
77
|
+
this.eventQueue.push({ type: "status", timestamp: ts(), content: "failed" });
|
|
78
|
+
this.status = SESSION_STATUS.STOPPED;
|
|
79
|
+
this.eventQueue.close();
|
|
80
|
+
});
|
|
81
|
+
for await (const event of this.eventQueue) {
|
|
82
|
+
yield event;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Core session logic: setup SDK, handle resume or initial query, transition to waiting_input. */
|
|
86
|
+
async runSession() {
|
|
87
|
+
const ts = () => new Date().toISOString();
|
|
88
|
+
try {
|
|
89
|
+
await this.setupSdk();
|
|
90
|
+
// For resumed sessions, perform resume-specific setup and wait for input.
|
|
91
|
+
if (this.resumeSessionId) {
|
|
92
|
+
await this.setupForResume();
|
|
93
|
+
this.status = SESSION_STATUS.IDLE;
|
|
94
|
+
this.eventQueue.push({ type: "status", timestamp: ts(), content: "waiting_input" });
|
|
95
|
+
this.startInputLoop();
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
// Build final prompt with system context
|
|
99
|
+
const finalPrompt = this.buildInitialPrompt();
|
|
100
|
+
const messageCount = await this.runInitialQuery(finalPrompt);
|
|
101
|
+
if (this.killed) {
|
|
102
|
+
this.releaseResources();
|
|
103
|
+
this.eventQueue.close();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (messageCount === 0) {
|
|
107
|
+
this.eventQueue.push({ type: "error", timestamp: ts(), content: this.noMessagesError });
|
|
108
|
+
}
|
|
109
|
+
// Session is idle — ready for follow-up input via sendInput().
|
|
110
|
+
// The input loop owns the eventQueue lifecycle from this point.
|
|
111
|
+
this.status = SESSION_STATUS.IDLE;
|
|
112
|
+
this.eventQueue.push({ type: "status", timestamp: ts(), content: "waiting_input" });
|
|
113
|
+
this.startInputLoop();
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
this.status = SESSION_STATUS.STOPPED;
|
|
117
|
+
this.eventQueue.push({ type: "error", timestamp: ts(), content: String(err) });
|
|
118
|
+
this.eventQueue.push({ type: "status", timestamp: ts(), content: "failed" });
|
|
119
|
+
this.releaseResources();
|
|
120
|
+
this.eventQueue.close();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** Queue follow-up input for sequential processing by the input loop. */
|
|
124
|
+
sendInput(text) {
|
|
125
|
+
if (this.killed || !this.canAcceptInput()) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.inputQueue.push(text);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Background loop that dequeues input and calls `executeFollowUp()` sequentially.
|
|
132
|
+
* Started after the initial query (or resume setup) completes. Owns the eventQueue
|
|
133
|
+
* lifecycle — closes it when the loop exits.
|
|
134
|
+
*/
|
|
135
|
+
async processInputLoop() {
|
|
136
|
+
const ts = () => new Date().toISOString();
|
|
137
|
+
for await (const text of this.inputQueue) {
|
|
138
|
+
if (this.killed) {
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
this.status = SESSION_STATUS.RUNNING;
|
|
142
|
+
this.eventQueue.push({ type: "status", timestamp: ts(), content: "running" });
|
|
143
|
+
try {
|
|
144
|
+
await this.executeFollowUp(text);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
logger.warn({ err }, `Failed to process follow-up input in ${this.runtimeDisplayName} session`);
|
|
148
|
+
this.eventQueue.push({ type: "error", timestamp: ts(), content: String(err) });
|
|
149
|
+
}
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- killed changes asynchronously via kill()
|
|
151
|
+
if (this.killed) {
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
this.status = SESSION_STATUS.IDLE;
|
|
155
|
+
this.eventQueue.push({ type: "status", timestamp: ts(), content: "waiting_input" });
|
|
156
|
+
}
|
|
157
|
+
// Loop exited — queue closed (kill) or drained.
|
|
158
|
+
this.releaseResources();
|
|
159
|
+
this.eventQueue.close();
|
|
160
|
+
}
|
|
161
|
+
/** Fire-and-forget launch of the input processing loop. */
|
|
162
|
+
startInputLoop() {
|
|
163
|
+
this.processInputLoop().catch((err) => {
|
|
164
|
+
const ts = new Date().toISOString();
|
|
165
|
+
logger.error({ err }, `Input loop crashed in ${this.runtimeDisplayName} session`);
|
|
166
|
+
this.status = SESSION_STATUS.STOPPED;
|
|
167
|
+
this.eventQueue.push({ type: "error", timestamp: ts, content: String(err) });
|
|
168
|
+
this.eventQueue.push({ type: "status", timestamp: ts, content: "failed" });
|
|
169
|
+
this.inputQueue.close();
|
|
170
|
+
this.releaseResources();
|
|
171
|
+
this.eventQueue.close();
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/** Forcefully terminate the session. Emits a final status event with the given reason. */
|
|
175
|
+
kill(reason = "killed") {
|
|
176
|
+
this.killed = true;
|
|
177
|
+
this.status = SESSION_STATUS.STOPPED;
|
|
178
|
+
this.abortActive();
|
|
179
|
+
this.inputQueue.close();
|
|
180
|
+
// Emit a final status event BEFORE closing the queue so the server receives it.
|
|
181
|
+
this.eventQueue.push({
|
|
182
|
+
type: "status",
|
|
183
|
+
timestamp: new Date().toISOString(),
|
|
184
|
+
content: reason,
|
|
185
|
+
});
|
|
186
|
+
// releaseResources() and eventQueue.close() are also called by processInputLoop()
|
|
187
|
+
// when it exits, but we call them here too for the case where kill() is called
|
|
188
|
+
// before the input loop starts (e.g. during the initial query).
|
|
189
|
+
// Both are idempotent — safe to call multiple times.
|
|
190
|
+
this.releaseResources();
|
|
191
|
+
this.eventQueue.close();
|
|
192
|
+
}
|
|
193
|
+
/** Drain any buffered events that were not yet consumed by the stream. */
|
|
194
|
+
drainBufferedEvents() {
|
|
195
|
+
return this.eventQueue.drain();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=base-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-session.js","sourceRoot":"","sources":["../src/base-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAgB,gBAAgB;IAC7B,EAAE,CAAS;IAEX,gBAAgB,CAAS;IACzB,MAAM,GAAkB,cAAc,CAAC,OAAO,CAAC;IAEnC,UAAU,GAA2B,IAAI,UAAU,EAAc,CAAC;IACpE,UAAU,GAAuB,IAAI,UAAU,EAAU,CAAC;IACjE,MAAM,GAAY,KAAK,CAAC;IACf,MAAM,C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nF,IAAI,CAAC,SAAiB,QAAQ;QACnC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC;QACrC,IAAI,CAAC,WAAW,EAAE,CAAC;QACnB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,gFAAgF;QAChF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACnB,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,OAAO,EAAE,MAAM;SAChB,CAAC,CAAC;QACH,kFAAkF;QAClF,+EAA+E;QAC/E,gEAAgE;QAChE,qDAAqD;QACrD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED,0EAA0E;IACnE,mBAAmB;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IACjC,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type { AgentEvent, SpawnOptions, ResumeOptions, AgentSession, AgentRuntime } from "./runtime.js";
|
|
2
|
+
export { BaseAgentRuntime } from "./base-runtime.js";
|
|
3
|
+
export { BaseAgentSession } from "./base-session.js";
|
|
4
|
+
export { resolveWorkingDirectory, findGitRepoPath, convertMcpServers, resolveMcpServers, NODE_GIT_REPOSITORY, NODE_WORKSPACE_LOCATOR, } from "./runtime-utils.js";
|
|
5
|
+
export type { GitRepository, WorkspaceLocator, ResolveWorkingDirectoryOptions, ResolvedMcpConfig, BrokerConfig, } from "./runtime-utils.js";
|
|
6
|
+
export { AsyncQueue } from "./async-queue.js";
|
|
7
|
+
export { ensureWorktree, removeWorktree, worktreeDir, sanitizeBranch, } from "./worktree.js";
|
|
8
|
+
export type { GitExecutor, WorktreeFileSystem, WorktreeResult } from "./worktree.js";
|
|
9
|
+
export { ensureRuntimeInstalled, importFromRuntime, getRuntimeBinDirectory, isDevMode, } from "./runtime-installer.js";
|
|
10
|
+
export type { RuntimeInstallOptions } from "./runtime-installer.js";
|
|
11
|
+
export { logger } from "./logger.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,8BAA8B,EAC9B,iBAAiB,EACjB,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,cAAc,EACd,WAAW,EACX,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,EACtB,SAAS,GACV,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { BaseAgentRuntime } from "./base-runtime.js";
|
|
2
|
+
export { BaseAgentSession } from "./base-session.js";
|
|
3
|
+
export { resolveWorkingDirectory, findGitRepoPath, convertMcpServers, resolveMcpServers, NODE_GIT_REPOSITORY, NODE_WORKSPACE_LOCATOR, } from "./runtime-utils.js";
|
|
4
|
+
export { AsyncQueue } from "./async-queue.js";
|
|
5
|
+
export { ensureWorktree, removeWorktree, worktreeDir, sanitizeBranch, } from "./worktree.js";
|
|
6
|
+
export { ensureRuntimeInstalled, importFromRuntime, getRuntimeBinDirectory, isDevMode, } from "./runtime-installer.js";
|
|
7
|
+
export { logger } from "./logger.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC;AAQ5B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EACL,cAAc,EACd,cAAc,EACd,WAAW,EACX,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,sBAAsB,EACtB,SAAS,GACV,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAa,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AAEzC,uDAAuD;AACvD,eAAO,MAAM,MAAM,EAAE,MAMnB,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import pino from "pino";
|
|
2
|
+
/** Application logger for Grackle runtime packages. */
|
|
3
|
+
export const logger = pino({
|
|
4
|
+
name: "grackle-runtime",
|
|
5
|
+
level: process.env.LOG_LEVEL || "info",
|
|
6
|
+
transport: process.env.NODE_ENV !== "production"
|
|
7
|
+
? { target: "pino/file", options: { destination: 1 } }
|
|
8
|
+
: undefined,
|
|
9
|
+
});
|
|
10
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,IAAqB,MAAM,MAAM,CAAC;AAEzC,uDAAuD;AACvD,MAAM,CAAC,MAAM,MAAM,GAAW,IAAI,CAAC;IACjC,IAAI,EAAE,iBAAiB;IACvB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM;IACtC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QAC9C,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE;QACtD,CAAC,CAAC,SAAS;CACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Optional callbacks for install progress. */
|
|
2
|
+
export interface RuntimeInstallOptions {
|
|
3
|
+
/** Callback for system-level events (e.g. "Installing claude-code runtime..."). */
|
|
4
|
+
eventCallback?: (message: string) => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Check if PowerLine is running from a monorepo source checkout.
|
|
8
|
+
* Looks for `rush.json` relative to PowerLine's compiled location
|
|
9
|
+
* (packages/powerline/dist → 3 levels up).
|
|
10
|
+
*/
|
|
11
|
+
export declare function isDevMode(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Ensure that the npm packages for a runtime are installed in an isolated
|
|
14
|
+
* directory under `~/.grackle/runtimes/<name>/`.
|
|
15
|
+
*
|
|
16
|
+
* **Fast path**: if the persisted manifest matches the current PowerLine
|
|
17
|
+
* version and package specs, returns immediately (one `readFileSync`).
|
|
18
|
+
*
|
|
19
|
+
* **Dev mode**: returns empty string immediately — Rush already resolves
|
|
20
|
+
* all packages via the monorepo's node_modules.
|
|
21
|
+
*
|
|
22
|
+
* @returns The absolute path to the runtime's install directory.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ensureRuntimeInstalled(runtimeName: string, options?: RuntimeInstallOptions): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Dynamically import a module from an isolated runtime directory.
|
|
27
|
+
*
|
|
28
|
+
* In dev mode, falls back to standard `import()` since Rush handles resolution.
|
|
29
|
+
*
|
|
30
|
+
* @param runtimeName - Runtime identifier (e.g. "claude-code")
|
|
31
|
+
* @param packageName - npm package name to import (e.g. `\@anthropic-ai/claude-agent-sdk`)
|
|
32
|
+
* @returns The imported module
|
|
33
|
+
*/
|
|
34
|
+
export declare function importFromRuntime<T>(runtimeName: string, packageName: string): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the path to the `.bin` directory inside a runtime's node_modules.
|
|
37
|
+
* Used to add runtime-specific CLI binaries to PATH when spawning agent subprocesses.
|
|
38
|
+
*
|
|
39
|
+
* @param runtimeName - Runtime identifier (e.g. "codex-acp")
|
|
40
|
+
* @returns Absolute path to `~/.grackle/runtimes/<name>/node_modules/.bin`
|
|
41
|
+
*/
|
|
42
|
+
export declare function getRuntimeBinDirectory(runtimeName: string): string;
|
|
43
|
+
//# sourceMappingURL=runtime-installer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-installer.d.ts","sourceRoot":"","sources":["../src/runtime-installer.ts"],"names":[],"mappings":"AA4BA,+CAA+C;AAC/C,MAAM,WAAW,qBAAqB;IACpC,mFAAmF;IACnF,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C;AAID;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,CAGnC;AAmDD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,MAAM,CAAC,CA6CjB;AAED;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CA8D/F;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CASlE"}
|