opencode-copilot-delegate 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/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/discovery/agents.d.ts +10 -0
- package/dist/discovery/description.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +9917 -0
- package/dist/lib/ansi.d.ts +1 -0
- package/dist/lib/kill-tree.d.ts +1 -0
- package/dist/runtime/envelope.d.ts +58 -0
- package/dist/runtime/jsonl-parser.d.ts +24 -0
- package/dist/runtime/notify.d.ts +63 -0
- package/dist/runtime/subprocess.d.ts +23 -0
- package/dist/runtime/task-registry.d.ts +22 -0
- package/dist/tools/cancel.d.ts +9 -0
- package/dist/tools/delegate.d.ts +26 -0
- package/dist/tools/output.d.ts +13 -0
- package/package.json +65 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function stripAnsi(text: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function killProcessTree(pid: number): Promise<void>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Envelope builder for Copilot delegation results.
|
|
3
|
+
*
|
|
4
|
+
* Folds ParsedEvent[] into the structured output envelope returned by
|
|
5
|
+
* `copilot_output`. Every field is optional-safe — missing data degrades
|
|
6
|
+
* gracefully rather than erroring.
|
|
7
|
+
*/
|
|
8
|
+
import type { ParsedEvent } from './jsonl-parser';
|
|
9
|
+
/** Status of a delegated Copilot task. */
|
|
10
|
+
export type TaskStatus = 'running' | 'complete' | 'failed' | 'cancelled';
|
|
11
|
+
/** Summary of a single tool call made during the Copilot session. */
|
|
12
|
+
export type ToolCallSummary = {
|
|
13
|
+
name: string;
|
|
14
|
+
toolCallId: string;
|
|
15
|
+
success?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/** Token/usage information from the Copilot session. */
|
|
18
|
+
export type TokenUsage = {
|
|
19
|
+
premiumRequests?: number;
|
|
20
|
+
totalApiDurationMs?: number;
|
|
21
|
+
sessionDurationMs?: number;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
/** Input for building the output envelope. */
|
|
25
|
+
export type EnvelopeInput = {
|
|
26
|
+
taskId: string;
|
|
27
|
+
events: ParsedEvent[];
|
|
28
|
+
status: TaskStatus;
|
|
29
|
+
startedAt: number;
|
|
30
|
+
endedAt?: number;
|
|
31
|
+
exitCode?: number;
|
|
32
|
+
agentName?: string;
|
|
33
|
+
modelName?: string;
|
|
34
|
+
errorText?: string;
|
|
35
|
+
timedOut?: boolean;
|
|
36
|
+
};
|
|
37
|
+
/** The structured result envelope returned by `copilot_output`. */
|
|
38
|
+
export type OutputEnvelope = {
|
|
39
|
+
task_id: string;
|
|
40
|
+
status: TaskStatus;
|
|
41
|
+
exit_code?: number;
|
|
42
|
+
agent?: string;
|
|
43
|
+
model?: string;
|
|
44
|
+
duration_ms: number;
|
|
45
|
+
tokens?: TokenUsage;
|
|
46
|
+
final_message?: string;
|
|
47
|
+
tool_calls_summary?: ToolCallSummary[];
|
|
48
|
+
error?: string;
|
|
49
|
+
timed_out?: boolean;
|
|
50
|
+
events_count: number;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Build the structured output envelope from parsed events and task metadata.
|
|
54
|
+
*
|
|
55
|
+
* Every field degrades gracefully — missing events, empty arrays, and absent
|
|
56
|
+
* usage data produce undefined fields rather than errors.
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildEnvelope(input: EnvelopeInput): OutputEnvelope;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copilot CLI JSONL event parser.
|
|
3
|
+
*
|
|
4
|
+
* Parses individual JSONL lines from `copilot --output-format json` stdout
|
|
5
|
+
* into normalized ParsedEvent objects. Defensive: never throws on malformed
|
|
6
|
+
* input — returns type "unknown" instead.
|
|
7
|
+
*/
|
|
8
|
+
/** Normalized event types relevant to the output envelope. */
|
|
9
|
+
export type ParsedEventType = 'message' | 'tool_use' | 'tool_result' | 'usage' | 'error' | 'unknown';
|
|
10
|
+
/** A parsed and normalized JSONL event. */
|
|
11
|
+
export type ParsedEvent = {
|
|
12
|
+
/** Normalized event type for envelope construction. */
|
|
13
|
+
type: ParsedEventType;
|
|
14
|
+
/** Extracted payload fields relevant to this event type. */
|
|
15
|
+
data: Record<string, unknown>;
|
|
16
|
+
/** Original raw parsed JSON object (empty object if parse failed). */
|
|
17
|
+
raw: Record<string, unknown>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Parse a single JSONL line into a normalized ParsedEvent.
|
|
21
|
+
*
|
|
22
|
+
* Never throws. Malformed input returns `{ type: 'unknown', data: {}, raw: {} }`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseJsonlLine(line: string): ParsedEvent;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Notification injection for Copilot delegation completions.
|
|
3
|
+
*
|
|
4
|
+
* Injects `<system-reminder>` messages into the parent OpenCode session
|
|
5
|
+
* when a delegated Copilot subprocess completes. Uses `noReply` semantics
|
|
6
|
+
* mirroring OMO's per-parent-session in-flight counter pattern.
|
|
7
|
+
*
|
|
8
|
+
* Correctness invariant: decrement the in-flight counter synchronously
|
|
9
|
+
* (before any await) to prevent concurrent completions from both reading
|
|
10
|
+
* the same counter value and both setting noReply: false.
|
|
11
|
+
*/
|
|
12
|
+
import type { TaskStatus } from './envelope';
|
|
13
|
+
/** Minimal client interface for notification injection. */
|
|
14
|
+
export type NotifyClient = {
|
|
15
|
+
session: {
|
|
16
|
+
prompt: (opts: {
|
|
17
|
+
path: {
|
|
18
|
+
id: string;
|
|
19
|
+
};
|
|
20
|
+
body: {
|
|
21
|
+
noReply: boolean;
|
|
22
|
+
parts: Array<{
|
|
23
|
+
type: 'text';
|
|
24
|
+
text: string;
|
|
25
|
+
synthetic: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
};
|
|
28
|
+
}) => Promise<unknown>;
|
|
29
|
+
};
|
|
30
|
+
tui: {
|
|
31
|
+
showToast: (opts: {
|
|
32
|
+
body: {
|
|
33
|
+
message: string;
|
|
34
|
+
variant: 'info' | 'success' | 'warning' | 'error';
|
|
35
|
+
};
|
|
36
|
+
}) => unknown;
|
|
37
|
+
};
|
|
38
|
+
app: {
|
|
39
|
+
log: (...args: unknown[]) => void;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/** Task information needed for building the notification. */
|
|
43
|
+
export type NotifyTaskInfo = {
|
|
44
|
+
taskId: string;
|
|
45
|
+
parentSessionID: string;
|
|
46
|
+
status: TaskStatus;
|
|
47
|
+
agentName?: string;
|
|
48
|
+
modelName?: string;
|
|
49
|
+
startedAt: number;
|
|
50
|
+
exitCode?: number;
|
|
51
|
+
};
|
|
52
|
+
/** Increment the in-flight counter for a parent session. */
|
|
53
|
+
export declare function incrementInFlight(parentSessionID: string): void;
|
|
54
|
+
/** Reset all counters (for testing only). */
|
|
55
|
+
export declare function resetInFlightCounters(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Notify the parent session that a Copilot delegation has completed.
|
|
58
|
+
*
|
|
59
|
+
* Decrements the in-flight counter synchronously, then injects the
|
|
60
|
+
* notification via client.session.prompt with correct noReply semantics.
|
|
61
|
+
* Never throws — logs and swallows prompt/toast errors.
|
|
62
|
+
*/
|
|
63
|
+
export declare function notifyCompletion(client: NotifyClient, task: NotifyTaskInfo): Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ChildProcess } from 'node:child_process';
|
|
2
|
+
import type { TaskStatus } from './envelope';
|
|
3
|
+
import { type ParsedEvent } from './jsonl-parser';
|
|
4
|
+
type SpawnCopilotOptions = {
|
|
5
|
+
cwd: string;
|
|
6
|
+
env?: Record<string, string>;
|
|
7
|
+
};
|
|
8
|
+
export type SpawnCopilotResult = {
|
|
9
|
+
taskId: string;
|
|
10
|
+
pid: number;
|
|
11
|
+
events: ParsedEvent[];
|
|
12
|
+
completionPromise: Promise<void>;
|
|
13
|
+
abortController: AbortController;
|
|
14
|
+
child: ChildProcess;
|
|
15
|
+
status: TaskStatus;
|
|
16
|
+
exitCode?: number;
|
|
17
|
+
endedAt?: number;
|
|
18
|
+
stdoutLineBuffer: string;
|
|
19
|
+
finalMessage?: string;
|
|
20
|
+
errorText?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function spawnCopilot(args: string[], opts: SpawnCopilotOptions): SpawnCopilotResult;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SpawnCopilotResult } from './subprocess';
|
|
2
|
+
export type TaskState = SpawnCopilotResult & {
|
|
3
|
+
parentSessionID: string;
|
|
4
|
+
startedAt: number;
|
|
5
|
+
args: string[];
|
|
6
|
+
cwd: string;
|
|
7
|
+
agentName?: string;
|
|
8
|
+
modelName?: string;
|
|
9
|
+
};
|
|
10
|
+
export type CreateTaskInput = Omit<SpawnCopilotResult, 'taskId'> & {
|
|
11
|
+
parentSessionID: string;
|
|
12
|
+
startedAt: number;
|
|
13
|
+
args: string[];
|
|
14
|
+
cwd: string;
|
|
15
|
+
agentName?: string;
|
|
16
|
+
modelName?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function createTask(input: CreateTaskInput, taskId?: string): TaskState;
|
|
19
|
+
export declare function getTask(taskId: string): TaskState | undefined;
|
|
20
|
+
export declare function getAllTasks(): TaskState[];
|
|
21
|
+
export declare function deleteTask(taskId: string): boolean;
|
|
22
|
+
export declare function cleanupAll(): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function createCancelTool(): {
|
|
2
|
+
description: string;
|
|
3
|
+
args: {
|
|
4
|
+
task_id: import("zod").ZodString;
|
|
5
|
+
};
|
|
6
|
+
execute(args: {
|
|
7
|
+
task_id: string;
|
|
8
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PluginInput } from '@opencode-ai/plugin';
|
|
2
|
+
type DelegateToolOptions = {
|
|
3
|
+
client: PluginInput['client'];
|
|
4
|
+
description: string;
|
|
5
|
+
directory: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function createDelegateTool(options: DelegateToolOptions): {
|
|
8
|
+
description: string;
|
|
9
|
+
args: {
|
|
10
|
+
prompt: import("zod").ZodString;
|
|
11
|
+
agent: import("zod").ZodOptional<import("zod").ZodString>;
|
|
12
|
+
model: import("zod").ZodOptional<import("zod").ZodString>;
|
|
13
|
+
add_dir: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
14
|
+
allow_tool: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
15
|
+
deny_tool: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
16
|
+
};
|
|
17
|
+
execute(args: {
|
|
18
|
+
prompt: string;
|
|
19
|
+
agent?: string | undefined;
|
|
20
|
+
model?: string | undefined;
|
|
21
|
+
add_dir?: string[] | undefined;
|
|
22
|
+
allow_tool?: string[] | undefined;
|
|
23
|
+
deny_tool?: string[] | undefined;
|
|
24
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function createOutputTool(): {
|
|
2
|
+
description: string;
|
|
3
|
+
args: {
|
|
4
|
+
task_id: import("zod").ZodString;
|
|
5
|
+
block: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
6
|
+
timeout_ms: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
7
|
+
};
|
|
8
|
+
execute(args: {
|
|
9
|
+
task_id: string;
|
|
10
|
+
block?: boolean | undefined;
|
|
11
|
+
timeout_ms?: number | undefined;
|
|
12
|
+
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
13
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "opencode-copilot-delegate",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "OpenCode plugin that delegates tasks to GitHub Copilot CLI as background subprocesses",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md",
|
|
11
|
+
"LICENSE",
|
|
12
|
+
"CHANGELOG.md"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"opencode",
|
|
16
|
+
"opencode-plugin",
|
|
17
|
+
"copilot",
|
|
18
|
+
"github-copilot",
|
|
19
|
+
"agent",
|
|
20
|
+
"delegation"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "Marcus R. Brown <git@mrbro.dev> (https://mrbro.dev)",
|
|
24
|
+
"homepage": "https://github.com/marcusrbrown/opencode-copilot-delegate",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/marcusrbrown/opencode-copilot-delegate.git"
|
|
28
|
+
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/marcusrbrown/opencode-copilot-delegate/issues"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=24"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@opencode-ai/plugin": ">=1.14.0",
|
|
37
|
+
"@opencode-ai/sdk": ">=1.14.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@biomejs/biome": "^2.4.13",
|
|
41
|
+
"@changesets/cli": "^2.31.0",
|
|
42
|
+
"@opencode-ai/plugin": "^1.14.19",
|
|
43
|
+
"@opencode-ai/sdk": "^1.14.19",
|
|
44
|
+
"@types/bun": "^1.2.0",
|
|
45
|
+
"@types/node": "^24.0.0",
|
|
46
|
+
"rimraf": "^6.0.1",
|
|
47
|
+
"typescript": "^6.0.3"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"clean": "rimraf dist",
|
|
51
|
+
"build": "bun run clean && bun build src/index.ts --outdir dist --target bun --external @opencode-ai/plugin --external @opencode-ai/sdk && tsc --emitDeclarationOnly --noEmit false",
|
|
52
|
+
"typecheck": "tsc --noEmit",
|
|
53
|
+
"test": "bun test",
|
|
54
|
+
"test:unit": "bun test tests/*.test.ts",
|
|
55
|
+
"test:integration": "bun test tests/integration/",
|
|
56
|
+
"lint": "biome check .",
|
|
57
|
+
"fix": "biome check . --write",
|
|
58
|
+
"prepublishOnly": "bun run build",
|
|
59
|
+
"version-changesets": "changeset version && bun install --lockfile-only",
|
|
60
|
+
"publish-changesets": "bun run build && changeset publish"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"fkill": "10.0.3"
|
|
64
|
+
}
|
|
65
|
+
}
|