opencode-copilot-delegate 0.10.1 → 0.11.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 +16 -0
- package/dist/index.js +21 -16
- package/dist/runtime/plugin-singleton.d.ts +51 -20
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# opencode-copilot-delegate
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 31dfb28: Fix host-side double registration of `copilot_delegate`, `copilot_output`, and `copilot_cancel` when the plugin is listed in both a user-level and project-level `opencode.json`.
|
|
8
|
+
|
|
9
|
+
Previously, the per-process register-once guard returned the cached real hooks to every duplicate factory invocation in the same PID. The OpenCode host iterates each plugin source's returned hook surface and registers every tool entry it finds, even when two sources return the same JS reference. That meant each tool appeared twice in the LLM-visible tool catalog under dual-source configurations.
|
|
10
|
+
|
|
11
|
+
The guard now returns empty hooks (`{}`) on duplicate invocations so the host has nothing to register a second time. The first invocation still runs `doInit` once and receives the real hooks; subsequent invocations in the same PID receive `{}` and emit a one-time warning. Heavy initialization (agent discovery, orphan reaping, RPC server startup) still runs at most once per process.
|
|
12
|
+
|
|
13
|
+
Single-source configurations are unaffected.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- e019e86: Stabilize the cancel-process-tree test against CI runner load by polling `process.kill(pid, 0)` with a 2s deadline instead of asserting synchronously. Test-only change; no plugin behavior or consumer surface affected.
|
|
18
|
+
|
|
3
19
|
## 0.10.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -9881,7 +9881,8 @@ async function plugInOnce({
|
|
|
9881
9881
|
onDuplicate?.(currentPid);
|
|
9882
9882
|
} catch {}
|
|
9883
9883
|
}
|
|
9884
|
-
|
|
9884
|
+
await existing.hooksPromise;
|
|
9885
|
+
return { isFirst: false, hooks: {} };
|
|
9885
9886
|
}
|
|
9886
9887
|
const hooksPromise = doInit();
|
|
9887
9888
|
g[SINGLETON_KEY] = {
|
|
@@ -9890,7 +9891,8 @@ async function plugInOnce({
|
|
|
9890
9891
|
hooksPromise,
|
|
9891
9892
|
warned: false
|
|
9892
9893
|
};
|
|
9893
|
-
|
|
9894
|
+
const hooks = await hooksPromise;
|
|
9895
|
+
return { isFirst: true, hooks };
|
|
9894
9896
|
}
|
|
9895
9897
|
|
|
9896
9898
|
// src/runtime/rpc-server.ts
|
|
@@ -24478,20 +24480,23 @@ async function initializePlugin(input) {
|
|
|
24478
24480
|
}
|
|
24479
24481
|
};
|
|
24480
24482
|
}
|
|
24481
|
-
var CopilotDelegate = async (input) =>
|
|
24482
|
-
|
|
24483
|
-
|
|
24484
|
-
|
|
24485
|
-
|
|
24486
|
-
|
|
24487
|
-
|
|
24488
|
-
|
|
24489
|
-
|
|
24490
|
-
|
|
24491
|
-
|
|
24492
|
-
|
|
24493
|
-
|
|
24494
|
-
}
|
|
24483
|
+
var CopilotDelegate = async (input) => {
|
|
24484
|
+
const result = await plugInOnce({
|
|
24485
|
+
doInit: () => initializePlugin(input),
|
|
24486
|
+
onDuplicate: (pid) => {
|
|
24487
|
+
const message = `[copilot-delegate] duplicate factory invocation in same process (pid=${pid}); returning empty hooks so the host does not double-register tools. Multiple opencode.json sources may list this plugin.`;
|
|
24488
|
+
console.warn(message);
|
|
24489
|
+
input.client.app.log({
|
|
24490
|
+
body: {
|
|
24491
|
+
service: "copilot-delegate",
|
|
24492
|
+
level: "warn",
|
|
24493
|
+
message
|
|
24494
|
+
}
|
|
24495
|
+
}).catch(() => {});
|
|
24496
|
+
}
|
|
24497
|
+
});
|
|
24498
|
+
return result.hooks;
|
|
24499
|
+
};
|
|
24495
24500
|
var src_default = CopilotDelegate;
|
|
24496
24501
|
export {
|
|
24497
24502
|
wireRpcServerCleanup,
|
|
@@ -1,35 +1,49 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Per-process
|
|
2
|
+
* Per-process register-once guard for the plugin factory.
|
|
3
3
|
*
|
|
4
4
|
* OpenCode invokes the plugin factory more than once per process when the
|
|
5
5
|
* same plugin is referenced by multiple config sources (for example a
|
|
6
6
|
* user-level `~/.config/opencode/opencode.json` AND a project-level
|
|
7
7
|
* `opencode.json`). Each invocation evaluates the plugin module fresh —
|
|
8
|
-
* module-local variables reset between calls — so the
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* module-local variables reset between calls — so the guard state must
|
|
9
|
+
* live on `globalThis` to persist across module instances within the
|
|
10
|
+
* same process.
|
|
11
11
|
*
|
|
12
|
-
* On the first invocation
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
12
|
+
* On the first invocation `doInit` runs and the resulting hooks promise
|
|
13
|
+
* is cached on `globalThis`; the caller receives `{ isFirst: true, hooks }`.
|
|
14
|
+
* On every subsequent invocation in the same PID `doInit` is skipped, the
|
|
15
|
+
* cached promise is awaited (so sticky rejections still propagate),
|
|
16
|
+
* `onDuplicate` fires exactly once, and the caller receives
|
|
17
|
+
* `{ isFirst: false, hooks: {} as T }`. Across PIDs the guard is treated
|
|
18
|
+
* as absent and init runs fresh — `globalThis` is per-process, but the
|
|
19
|
+
* explicit PID check adds defensive belt-and-suspenders against any
|
|
20
|
+
* state-leakage edge case.
|
|
21
|
+
*
|
|
22
|
+
* **Why empty hooks on duplicate invocations.** A whole-hooks singleton
|
|
23
|
+
* that returns the same hooks reference to both invocations does not
|
|
24
|
+
* deduplicate host-side tool registration: OpenCode iterates each plugin
|
|
25
|
+
* source's returned hook surface and registers every tool entry it finds,
|
|
26
|
+
* even when two sources return the same JS reference. Returning `{}` from
|
|
27
|
+
* the duplicate path is the only shape that prevents host-side double
|
|
28
|
+
* registration of `copilot_delegate`, `copilot_output`, and
|
|
29
|
+
* `copilot_cancel`. Verified empirically against
|
|
30
|
+
* `client.tool.list({...})`: under whole-hooks reuse a dual-source config
|
|
31
|
+
* lists each tool twice; under empty-hooks-on-duplicate it lists each
|
|
32
|
+
* tool once.
|
|
19
33
|
*
|
|
20
34
|
* The cached value is the init Promise rather than the resolved value so
|
|
21
35
|
* a second invocation that arrives while the first is still awaiting
|
|
22
36
|
* `mkdir` / `reapOrphans` converges on the same init result instead of
|
|
23
37
|
* starting a parallel init.
|
|
24
38
|
*
|
|
25
|
-
* **Known limitation — rejected init is
|
|
39
|
+
* **Known limitation — rejected init is sticky.** If `doInit()` rejects,
|
|
26
40
|
* the rejected promise is stored on `globalThis` and every subsequent
|
|
27
|
-
* invocation in the same PID
|
|
41
|
+
* invocation in the same PID surfaces the same rejection without
|
|
28
42
|
* retrying init. This is intentional: re-running heavy init on every
|
|
29
|
-
* call would defeat the
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
43
|
+
* call would defeat the guard's purpose. Recovery requires a process
|
|
44
|
+
* restart. OpenCode currently surfaces a failed plugin factory as a
|
|
45
|
+
* startup error rather than retrying within the process, so this matches
|
|
46
|
+
* the upstream contract.
|
|
33
47
|
*/
|
|
34
48
|
export interface PlugInOnceOptions<T> {
|
|
35
49
|
/** Heavy init work that should run at most once per process. */
|
|
@@ -47,10 +61,27 @@ export interface PlugInOnceOptions<T> {
|
|
|
47
61
|
pid?: number;
|
|
48
62
|
}
|
|
49
63
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
64
|
+
* Result envelope for `plugInOnce(...)`.
|
|
65
|
+
*
|
|
66
|
+
* - `isFirst: true` — caller should return `hooks` (the real hooks from
|
|
67
|
+
* `doInit`) to OpenCode.
|
|
68
|
+
* - `isFirst: false` — caller MUST return `hooks` (which is an empty `{}`)
|
|
69
|
+
* so the host loader does not register tools or hooks twice.
|
|
70
|
+
*
|
|
71
|
+
* Callers that just `return result.hooks` do the right thing in both
|
|
72
|
+
* cases without needing to inspect `isFirst` — the empty object is what
|
|
73
|
+
* the host should register on the duplicate source.
|
|
74
|
+
*/
|
|
75
|
+
export interface PlugInOnceResult<T> {
|
|
76
|
+
isFirst: boolean;
|
|
77
|
+
hooks: T;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Run `doInit` at most once per process; on duplicate invocations resolve
|
|
81
|
+
* to empty hooks so the OpenCode host does not double-register tools and
|
|
82
|
+
* hooks under dual-source configurations.
|
|
52
83
|
*/
|
|
53
|
-
export declare function plugInOnce<T>({ doInit, onDuplicate, pid, }: PlugInOnceOptions<T>): Promise<T
|
|
84
|
+
export declare function plugInOnce<T>({ doInit, onDuplicate, pid, }: PlugInOnceOptions<T>): Promise<PlugInOnceResult<T>>;
|
|
54
85
|
/**
|
|
55
86
|
* Test-only: clear the singleton state so the next invocation re-runs
|
|
56
87
|
* init. Must not be called in production code paths.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-copilot-delegate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "OpenCode plugin that delegates tasks to GitHub Copilot CLI as background subprocesses",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"@opencode-ai/plugin": ">=1.14.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@biomejs/biome": "2.4.
|
|
58
|
+
"@biomejs/biome": "2.4.14",
|
|
59
59
|
"@changesets/cli": "2.31.0",
|
|
60
|
-
"@opencode-ai/plugin": "1.14.
|
|
60
|
+
"@opencode-ai/plugin": "1.14.31",
|
|
61
61
|
"@types/bun": "1.3.13",
|
|
62
62
|
"@types/node": "24.12.2",
|
|
63
63
|
"rimraf": "6.1.3",
|
|
@@ -78,10 +78,10 @@
|
|
|
78
78
|
"publish-changesets": "bun run build && changeset publish"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@opentui/core": "0.1
|
|
82
|
-
"@opentui/solid": "0.1
|
|
81
|
+
"@opentui/core": "0.2.1",
|
|
82
|
+
"@opentui/solid": "0.2.1",
|
|
83
83
|
"fkill": "10.0.3",
|
|
84
|
-
"solid-js": "1.9.
|
|
84
|
+
"solid-js": "1.9.12",
|
|
85
85
|
"zod": "^4.3.0"
|
|
86
86
|
},
|
|
87
87
|
"overrides": {
|