@rovecode-labs/sdk 0.1.0

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,53 @@
1
+ # @rovecode-labs/sdk
2
+
3
+ Embed the [rovecode](https://github.com/9Code-Labs/rovecode-community) coding-agent harness in your
4
+ own Bun/TypeScript process — sessions, streamed prompts, background subagent tasks, and the live
5
+ agent tree. **One client = one engine**: the SDK boots the same runtime the CLI boots (no second
6
+ loop), so everything the CLI can do, your process can do.
7
+
8
+ ```bash
9
+ bun add @rovecode-labs/sdk
10
+ ```
11
+
12
+ ```ts
13
+ import { createClient, mockStream } from "@rovecode-labs/sdk";
14
+
15
+ const rc = await createClient({ cwd: process.cwd() }); // resolves your configured provider
16
+ const session = await rc.session.create();
17
+
18
+ for await (const ev of session.prompt("fix the failing test in src/auth.ts")) {
19
+ if (ev.type === "agent_tree_update") renderTree(ev.tree); // live subagent tree
20
+ if (ev.type === "run_end") console.log(ev.status);
21
+ }
22
+
23
+ await rc.close();
24
+ ```
25
+
26
+ ## Surface
27
+
28
+ - `createClient({ cwd?, stream?, yolo?, approval? })` → `Promise<RovecodeClient>`
29
+ - `rc.session.create({ id? })` / `rc.session.list()`
30
+ - `session.prompt(goal, { signal? })` → async generator of `SdkEvent` (every `RunEvent` of the run
31
+ plus `agent_tree_update` frames synthesized from the task registry)
32
+ - `rc.task.start(sessionId, { agent?, goal, label?, isolated? })` · `list` · `wait` · `cancel`
33
+ - `rc.agent.tree(sessionId)` — the current parent→children task tree
34
+ - `rc.events.subscribe(fn)` — client-level tap of everything
35
+ - `mockStream({ turns })` — scripted provider for tests: no keys, no network
36
+
37
+ ## Testing
38
+
39
+ ```ts
40
+ import { createClient, mockStream, textTurn } from "@rovecode-labs/sdk";
41
+
42
+ const rc = await createClient({ cwd: tmp, stream: mockStream({ turns: [textTurn("done")] }) });
43
+ ```
44
+
45
+ ## Notes
46
+
47
+ - Requires **Bun ≥ 1.3.14** (the harness is Bun-native).
48
+ - Runs fully local: provider keys come from your normal rovecode config (`rovecode connect`).
49
+ - For a hosted/headless setup, run `rovecode serve` (the same repo) and drive it over HTTP —
50
+ a first-party `remote` transport on these exact types is on the roadmap.
51
+ - 0.x surface: expect evolution, pinned by contract tests upstream.
52
+
53
+ AGPL-3.0-only · 9Code Labs
@@ -0,0 +1,97 @@
1
+ /** @rovecode-labs/sdk — public type surface.
2
+ * The runtime types (RunEvent, TaskInfo…) live in the rovecode source tree; here they are
3
+ * structural aliases so the SDK is usable without the AGPL source checkout. Shapes are
4
+ * pinned by test/unit/sdk-client.test.ts in rovecode-community. */
5
+
6
+ export type TaskId = string;
7
+ export type TaskStatus = "queued" | "running" | "done" | "failed" | "cancelled";
8
+
9
+ /** The agent loop's event union (run_start, turn_start, tool_call_*, turn_end, run_end, …). */
10
+ export type RunEvent = { type: string; [key: string]: unknown };
11
+ export type StreamFn = (...args: never[]) => unknown;
12
+ export type ApprovalFn = (req: unknown) => Promise<unknown> | unknown;
13
+
14
+ export interface AgentNode {
15
+ id: TaskId;
16
+ parent: TaskId | null;
17
+ label: string;
18
+ agent: string;
19
+ goal: string;
20
+ status: TaskStatus;
21
+ depth: number;
22
+ isolated: boolean;
23
+ createdAt: number;
24
+ startedAt?: number;
25
+ finishedAt?: number;
26
+ summary?: string;
27
+ error?: string;
28
+ }
29
+
30
+ export type SdkEvent = RunEvent | { type: "agent_tree_update"; sessionId: string; tree: AgentNode[] };
31
+
32
+ export interface ClientOptions {
33
+ /** project root; default process.cwd() */
34
+ cwd?: string;
35
+ /** inject a provider stream (mockStream for tests); null = offline, omitted = resolve from config */
36
+ stream?: StreamFn | null;
37
+ /** pre-approve everything (deny rules still hold) */
38
+ yolo?: boolean;
39
+ /** approval callback; omitted = policy-only like the headless server */
40
+ approval?: ApprovalFn;
41
+ }
42
+
43
+ export interface SessionHandle {
44
+ readonly id: string;
45
+ prompt(goal: string, opts?: { signal?: AbortSignal }): AsyncGenerator<SdkEvent, void>;
46
+ }
47
+
48
+ export interface SessionSummary {
49
+ id: string;
50
+ [key: string]: unknown;
51
+ }
52
+
53
+ export interface TaskInfo {
54
+ id: TaskId;
55
+ label: string;
56
+ agent: string;
57
+ goal: string;
58
+ status: TaskStatus;
59
+ depth: number;
60
+ parent?: TaskId;
61
+ [key: string]: unknown;
62
+ }
63
+
64
+ export interface WaitOptions {
65
+ timeoutMs?: number;
66
+ }
67
+
68
+ export interface RovecodeClient {
69
+ readonly cwd: string;
70
+ session: {
71
+ create(opts?: { id?: string }): Promise<SessionHandle>;
72
+ list(): SessionSummary[];
73
+ };
74
+ task: {
75
+ start(sessionId: string, req: { agent?: string; goal: string; label?: string; isolated?: boolean }):
76
+ { ok: true; id: TaskId } | { ok: false; reason: string };
77
+ list(sessionId: string): TaskInfo[];
78
+ wait(sessionId: string, id: TaskId, opts?: WaitOptions): Promise<TaskInfo | undefined>;
79
+ cancel(sessionId: string, id: TaskId): boolean;
80
+ };
81
+ agent: { tree(sessionId: string): AgentNode[] };
82
+ events: { subscribe(fn: (e: SdkEvent) => void): () => void };
83
+ close(): Promise<void>;
84
+ }
85
+
86
+ /** tasks.ts TaskInfo → AgentNode (parent edge: StartOptions.caller). */
87
+ export declare function agentTree(tasks: TaskInfo[]): AgentNode[];
88
+
89
+ /** One client = one engine. Boots the same runtime the CLI boots; close() releases it. */
90
+ export declare function createClient(opts?: ClientOptions): Promise<RovecodeClient>;
91
+
92
+ /** Scripted provider stream for tests — no keys, no network. */
93
+ export declare function mockStream(script: { turns: unknown[] }): StreamFn;
94
+
95
+ /** Turn builders for mockStream scripts. */
96
+ export declare function textTurn(text: string): unknown;
97
+ export declare function toolTurn(calls: unknown[], opts?: { text?: string }): unknown;