opencode-copilot-delegate 0.12.1 → 0.13.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 +19 -1
- package/README.md +16 -16
- package/dist/index.js +20666 -14568
- package/dist/lib/normalize-tool-arg-schemas.d.ts +1 -1
- package/dist/lib/process-global.d.ts +18 -0
- package/dist/lib/tool.d.ts +25 -0
- package/dist/runtime/plugin-singleton.d.ts +60 -36
- package/dist/runtime/rpc-paths.d.ts +6 -0
- package/dist/runtime/rpc-port-sweep.d.ts +38 -0
- package/dist/runtime/rpc-server.d.ts +10 -0
- package/dist/tools/cancel.d.ts +3 -9
- package/dist/tools/delegate.d.ts +8 -19
- package/dist/tools/output.d.ts +5 -13
- package/dist/tools/resume.d.ts +13 -15
- package/dist/tui/index.js +2818 -10922
- package/dist/tui/status-dialogs.d.ts +17 -0
- package/dist/tui/status-format.d.ts +10 -0
- package/package.json +17 -13
- package/src/tui/index.tsx +11 -42
- package/src/tui/rpc-client.ts +5 -13
- package/src/tui/status-dialogs.tsx +243 -0
- package/src/tui/{components/row.tsx → status-format.ts} +10 -6
- package/dist/tui/__tests__/confirm-card.test.d.ts +0 -2
- package/dist/tui/__tests__/index.test.d.ts +0 -1
- package/dist/tui/__tests__/modal-list.test.d.ts +0 -1
- package/dist/tui/__tests__/rpc-client.test.d.ts +0 -1
- package/dist/tui/components/confirm-card.d.ts +0 -12
- package/dist/tui/components/modal-list.d.ts +0 -16
- package/dist/tui/components/row.d.ts +0 -6
- package/src/tui/__tests__/confirm-card.test.tsx +0 -516
- package/src/tui/__tests__/index.test.ts +0 -561
- package/src/tui/__tests__/modal-list.test.tsx +0 -518
- package/src/tui/__tests__/rpc-client.test.ts +0 -507
- package/src/tui/components/confirm-card.tsx +0 -252
- package/src/tui/components/modal-list.tsx +0 -232
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process-wide state shared by every module instance of this plugin.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode can evaluate the plugin module more than once in one process: once
|
|
5
|
+
* per config source, and (since #530 item 2) once per workspace directory. A
|
|
6
|
+
* module-level `new Map()` therefore exists once per module instance, not once
|
|
7
|
+
* per process. State that must be process-wide lives on `globalThis` under a
|
|
8
|
+
* `Symbol.for` key, so every instance resolves the same object. Examples are
|
|
9
|
+
* the task registry the RPC server lists, the PID-ledger write lock, and the
|
|
10
|
+
* per-session in-flight counters.
|
|
11
|
+
*
|
|
12
|
+
* Keys are versioned (`.v1`). If a stored shape changes incompatibly, bump
|
|
13
|
+
* the version so two plugin versions loaded in one process don't share state.
|
|
14
|
+
*/
|
|
15
|
+
/** Return the process-wide value for `name`, creating it with `init` once. */
|
|
16
|
+
export declare function processGlobal<T>(name: string, init: () => T): T;
|
|
17
|
+
/** Test-only: forget a process-wide slot so the next access re-creates it. */
|
|
18
|
+
export declare function _resetProcessGlobal(name: string): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ToolContext, ToolResult } from '@opencode-ai/plugin/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Host-free replacement for `tool()` from `@opencode-ai/plugin/tool`.
|
|
5
|
+
*
|
|
6
|
+
* The V1 host's `tool()` is an identity function with `tool.schema = z`.
|
|
7
|
+
* Importing it at runtime makes `dist/index.js` depend on
|
|
8
|
+
* `@opencode-ai/plugin`, so the plugin can't load on a host that doesn't
|
|
9
|
+
* provide that package, such as an OpenCode V2 install (see
|
|
10
|
+
* docs/plans/2026-11-20-002-feat-opencode-v2-dual-host-plan.md, R3).
|
|
11
|
+
*
|
|
12
|
+
* This module keeps the same shape. It uses the plugin's own bundled zod
|
|
13
|
+
* (>= 4.2, so V2 can consume the schemas directly as Standard Schema) and
|
|
14
|
+
* imports only types from the host package. Argument descriptions still
|
|
15
|
+
* reach V1 hosts below 1.15.1 through `normalizeToolArgSchemas`.
|
|
16
|
+
*/
|
|
17
|
+
export type ToolDefinition<Args extends z.ZodRawShape = z.ZodRawShape> = {
|
|
18
|
+
description: string;
|
|
19
|
+
args: Args;
|
|
20
|
+
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<ToolResult>;
|
|
21
|
+
};
|
|
22
|
+
export declare function tool<Args extends z.ZodRawShape>(input: ToolDefinition<Args>): ToolDefinition<Args>;
|
|
23
|
+
export declare namespace tool {
|
|
24
|
+
export { z as schema };
|
|
25
|
+
}
|
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Register-once guards for the plugin factory.
|
|
3
3
|
*
|
|
4
|
-
* OpenCode invokes the plugin factory more than once per process
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* same process.
|
|
4
|
+
* OpenCode invokes the plugin factory more than once per process: once per
|
|
5
|
+
* config source that lists the plugin (for example a user-level
|
|
6
|
+
* `~/.config/opencode/opencode.json` AND a project-level `opencode.json`),
|
|
7
|
+
* and once per workspace directory the server opens. Each invocation may
|
|
8
|
+
* evaluate the plugin module fresh, so module-local variables reset between
|
|
9
|
+
* calls. The guard state therefore lives on `globalThis` to persist across
|
|
10
|
+
* module instances within the same process.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
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.
|
|
12
|
+
* Two guards with different scopes:
|
|
21
13
|
*
|
|
22
|
-
*
|
|
14
|
+
* - {@link initProcessOnce} runs process-wide setup (orphan reaping, the RPC
|
|
15
|
+
* server and its port file) exactly once per process, whatever the
|
|
16
|
+
* directory.
|
|
17
|
+
* - {@link plugInOnce} hands out real hooks once per `key` (the workspace
|
|
18
|
+
* directory). A second invocation for the same key gets `{}`; a different
|
|
19
|
+
* key gets its own real hooks. This partially supersedes R6 of the
|
|
20
|
+
* 2026-05-11 singleton decision, which returned `{}` to every invocation
|
|
21
|
+
* after the first. That starved later workspaces of tools (#530 item 2).
|
|
22
|
+
*
|
|
23
|
+
* For a given key, the first invocation runs `doInit` and caches its promise
|
|
24
|
+
* on `globalThis`; the caller receives `{ isFirst: true, hooks }`. Every
|
|
25
|
+
* later invocation for that key in the same PID skips `doInit`, awaits the
|
|
26
|
+
* cached promise (so sticky rejections still propagate), fires `onDuplicate`
|
|
27
|
+
* once, and receives `{ isFirst: false, hooks: {} as T }`. Across PIDs the
|
|
28
|
+
* guard is treated as absent and init runs fresh. `globalThis` is
|
|
29
|
+
* per-process, but the explicit PID check is a defensive belt-and-suspenders
|
|
30
|
+
* against any state-leakage edge case.
|
|
31
|
+
*
|
|
32
|
+
* **Why empty hooks on duplicate invocations.**
|
|
23
33
|
* that returns the same hooks reference to both invocations does not
|
|
24
34
|
* deduplicate host-side tool registration: OpenCode iterates each plugin
|
|
25
35
|
* source's returned hook surface and registers every tool entry it finds,
|
|
@@ -55,22 +65,30 @@
|
|
|
55
65
|
* harmless because the second run produces the same registrations as the
|
|
56
66
|
* first.
|
|
57
67
|
*
|
|
58
|
-
* This plugin's
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* (
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
68
|
+
* This plugin's process setup is not idempotent. The RPC server binds an
|
|
69
|
+
* ephemeral port and writes a port file with a fresh bearer token to a
|
|
70
|
+
* well-known path. A second server in the same process would not collide on
|
|
71
|
+
* the port (it is port 0, so the OS picks a new one). It would overwrite the
|
|
72
|
+
* port file, though, so the TUI would discover only the second server and its
|
|
73
|
+
* token, and lose sight of tasks the first one serves. Orphan reaping must
|
|
74
|
+
* also run once, before any task is spawned. {@link initProcessOnce} is the
|
|
75
|
+
* guard for that process-wide work. Per-directory tool hooks are cheap and
|
|
76
|
+
* safe to build once per workspace. The paired `wireRpcServerCleanup` helper
|
|
77
|
+
* in `src/lib/rpc-cleanup.ts` enforces the matching invariant on shutdown:
|
|
78
|
+
* the server closes exactly once.
|
|
67
79
|
*/
|
|
68
80
|
export interface PlugInOnceOptions<T> {
|
|
69
|
-
/**
|
|
81
|
+
/** Per-key hook construction; runs at most once per key per process. */
|
|
70
82
|
doInit: () => Promise<T>;
|
|
71
83
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
84
|
+
* Guard key. Use the workspace directory so each workspace gets its own
|
|
85
|
+
* hooks while repeat invocations for one workspace get `{}`. Defaults to a
|
|
86
|
+
* single shared key (the pre-#530 one-hooks-per-process behavior).
|
|
87
|
+
*/
|
|
88
|
+
key?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Called exactly once on the first duplicate invocation for a key in the
|
|
91
|
+
* same process. Subsequent duplicates are silent. Receives the same `pid`
|
|
74
92
|
* value the guard used for its identity check (so test overrides flow
|
|
75
93
|
* through faithfully). Implementations must not throw; fire-and-forget
|
|
76
94
|
* side effects (logging, metrics) are expected. Synchronous exceptions
|
|
@@ -97,13 +115,19 @@ export interface PlugInOnceResult<T> {
|
|
|
97
115
|
hooks: T;
|
|
98
116
|
}
|
|
99
117
|
/**
|
|
100
|
-
* Run `doInit` at most once per process; on duplicate invocations
|
|
101
|
-
* to empty hooks so the OpenCode host does not
|
|
102
|
-
* hooks under dual-source configurations.
|
|
118
|
+
* Run `doInit` at most once per `key` per process; on duplicate invocations
|
|
119
|
+
* for the same key resolve to empty hooks so the OpenCode host does not
|
|
120
|
+
* double-register tools and hooks under dual-source configurations.
|
|
121
|
+
*/
|
|
122
|
+
export declare function plugInOnce<T>({ doInit, key, onDuplicate, pid, }: PlugInOnceOptions<T>): Promise<PlugInOnceResult<T>>;
|
|
123
|
+
/**
|
|
124
|
+
* Run process-wide setup at most once per process, across every module
|
|
125
|
+
* instance and workspace directory, and share its promise with every caller.
|
|
126
|
+
* A rejected init is sticky, like {@link plugInOnce}.
|
|
103
127
|
*/
|
|
104
|
-
export declare function
|
|
128
|
+
export declare function initProcessOnce<T>(doInit: () => Promise<T>, pid?: number): Promise<T>;
|
|
105
129
|
/**
|
|
106
|
-
* Test-only: clear
|
|
107
|
-
*
|
|
130
|
+
* Test-only: clear both guards so the next invocation re-runs process setup
|
|
131
|
+
* and hook construction. Must not be called in production code paths.
|
|
108
132
|
*/
|
|
109
133
|
export declare function _resetPluginSingleton(): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared by the RPC server and the TUI client so both resolve the same
|
|
3
|
+
* `server-port.json` location. Node-only; `rpc-contract.ts` stays zod-only.
|
|
4
|
+
*/
|
|
5
|
+
export declare function defaultPortFileBaseDir(): string;
|
|
6
|
+
export declare function defaultSessionDiscriminator(): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Best-effort sweep of port files left behind by exited hosts.
|
|
3
|
+
*
|
|
4
|
+
* `close()` only runs on `beforeExit`/SIGTERM, so a host that dies any other
|
|
5
|
+
* way (SIGKILL, crash, torn-down worker) leaves `<base>/<discriminator>/
|
|
6
|
+
* server-port.json` behind. When the discriminator is the PID it is never
|
|
7
|
+
* revisited, so the files accumulate forever. This sweep removes sibling
|
|
8
|
+
* files that are provably stale and otherwise fails closed.
|
|
9
|
+
*
|
|
10
|
+
* The sweep is discriminator-agnostic: it never assumes what a directory name
|
|
11
|
+
* means beyond "all digits may be a PID", and it identifies the writer from
|
|
12
|
+
* the `pid` recorded in the file. Token values are never logged or retained.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_PORT_FILE_GRACE_MS: number;
|
|
15
|
+
export declare const DEFAULT_PORT_SWEEP_MAX_ENTRIES = 256;
|
|
16
|
+
export type PortFileSweepOptions = {
|
|
17
|
+
baseDir: string;
|
|
18
|
+
/** Directory name of the running server. It is never touched. */
|
|
19
|
+
currentDiscriminator: string;
|
|
20
|
+
now?: () => number;
|
|
21
|
+
/** Minimum file age (mtime) before removal. Default 10 minutes. */
|
|
22
|
+
graceMs?: number;
|
|
23
|
+
/** Max directory entries examined per sweep. Default 256. */
|
|
24
|
+
maxEntries?: number;
|
|
25
|
+
/** PID liveness probe. Default: `process.kill(pid, 0)`. */
|
|
26
|
+
isPidAlive?: (pid: number) => boolean;
|
|
27
|
+
};
|
|
28
|
+
export type PortFileSweepResult = {
|
|
29
|
+
scanned: number;
|
|
30
|
+
removed: number;
|
|
31
|
+
kept: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Remove stale `server-port.json` files (and their emptied directories) from
|
|
35
|
+
* sibling discriminator directories. Never throws; any per-entry error leaves
|
|
36
|
+
* that entry untouched.
|
|
37
|
+
*/
|
|
38
|
+
export declare function sweepStalePortFiles(options: PortFileSweepOptions): Promise<PortFileSweepResult>;
|
|
@@ -2,6 +2,7 @@ import type { AddressInfo } from 'node:net';
|
|
|
2
2
|
import type { CancelTaskResult } from './cancel-helper';
|
|
3
3
|
import type { TaskStatus } from './envelope';
|
|
4
4
|
import type { ParsedEvent } from './jsonl-parser';
|
|
5
|
+
import { type PortFileSweepOptions, type PortFileSweepResult } from './rpc-port-sweep';
|
|
5
6
|
type RpcTaskRecord = {
|
|
6
7
|
taskId: string;
|
|
7
8
|
status: TaskStatus;
|
|
@@ -20,10 +21,19 @@ export type StartRpcServerOptions = {
|
|
|
20
21
|
portFileBaseDir?: string;
|
|
21
22
|
sessionDiscriminator?: string;
|
|
22
23
|
now?: () => number;
|
|
24
|
+
/**
|
|
25
|
+
* Receives a count-only summary when the background sweep removed stale
|
|
26
|
+
* port files. Never receives paths or token values.
|
|
27
|
+
*/
|
|
28
|
+
log?: (message: string) => void;
|
|
29
|
+
/** Test seams for the stale port-file sweep. */
|
|
30
|
+
sweep?: Pick<PortFileSweepOptions, 'graceMs' | 'maxEntries' | 'isPidAlive' | 'now'>;
|
|
23
31
|
};
|
|
24
32
|
export type StartedRpcServer = {
|
|
25
33
|
port: number;
|
|
26
34
|
token: string;
|
|
35
|
+
/** Settles when the background stale-file sweep finishes. Never rejects. */
|
|
36
|
+
staleSweep: Promise<PortFileSweepResult>;
|
|
27
37
|
close(): Promise<void>;
|
|
28
38
|
};
|
|
29
39
|
export declare function isMissingPathError(error: unknown): boolean;
|
package/dist/tools/cancel.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export declare function createCancelTool(): {
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
};
|
|
1
|
+
export declare function createCancelTool(): import("../lib/tool").ToolDefinition<{
|
|
2
|
+
task_id: import("zod").ZodString;
|
|
3
|
+
}>;
|
package/dist/tools/delegate.d.ts
CHANGED
|
@@ -5,23 +5,12 @@ type DelegateToolOptions = {
|
|
|
5
5
|
directory: string;
|
|
6
6
|
pidFilePath?: string;
|
|
7
7
|
};
|
|
8
|
-
export declare function createDelegateTool(options: DelegateToolOptions): {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
deny_tool: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
17
|
-
};
|
|
18
|
-
execute(args: {
|
|
19
|
-
prompt: string;
|
|
20
|
-
agent?: string | undefined;
|
|
21
|
-
model?: string | undefined;
|
|
22
|
-
add_dir?: string[] | undefined;
|
|
23
|
-
allow_tool?: string[] | undefined;
|
|
24
|
-
deny_tool?: string[] | undefined;
|
|
25
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
26
|
-
};
|
|
8
|
+
export declare function createDelegateTool(options: DelegateToolOptions): import("../lib/tool").ToolDefinition<{
|
|
9
|
+
prompt: import("zod").ZodString;
|
|
10
|
+
agent: import("zod").ZodOptional<import("zod").ZodString>;
|
|
11
|
+
model: import("zod").ZodOptional<import("zod").ZodString>;
|
|
12
|
+
add_dir: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
13
|
+
allow_tool: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
14
|
+
deny_tool: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
15
|
+
}>;
|
|
27
16
|
export {};
|
package/dist/tools/output.d.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
export declare function createOutputTool(): {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
};
|
|
1
|
+
export declare function createOutputTool(): import("../lib/tool").ToolDefinition<{
|
|
2
|
+
task_id: import("zod").ZodString;
|
|
3
|
+
block: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
4
|
+
timeout_ms: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
5
|
+
}>;
|
package/dist/tools/resume.d.ts
CHANGED
|
@@ -32,6 +32,12 @@ export type LaunchResumeOptions = {
|
|
|
32
32
|
addDirs?: string[];
|
|
33
33
|
configDir?: string;
|
|
34
34
|
pidFilePath?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Fast-fail probe window for name/prefix targets. Defaults to
|
|
37
|
+
* `NAME_TARGET_FAILURE_WINDOW_MS`; injectable so tests can decide the race
|
|
38
|
+
* with the subprocess exit instead of a wall-clock timer.
|
|
39
|
+
*/
|
|
40
|
+
failureWindowMs?: number;
|
|
35
41
|
};
|
|
36
42
|
export type LaunchResumeResult = {
|
|
37
43
|
task_id: string;
|
|
@@ -43,20 +49,12 @@ type ResumeToolOptions = {
|
|
|
43
49
|
client: PluginInput['client'];
|
|
44
50
|
directory: string;
|
|
45
51
|
pidFilePath?: string;
|
|
52
|
+
failureWindowMs?: number;
|
|
46
53
|
};
|
|
47
|
-
export declare function createResumeTool(options: ResumeToolOptions): {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
config_dir: import("zod").ZodOptional<import("zod").ZodString>;
|
|
54
|
-
};
|
|
55
|
-
execute(args: {
|
|
56
|
-
target_id: string;
|
|
57
|
-
cwd?: string | undefined;
|
|
58
|
-
add_dir?: string[] | undefined;
|
|
59
|
-
config_dir?: string | undefined;
|
|
60
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
61
|
-
};
|
|
54
|
+
export declare function createResumeTool(options: ResumeToolOptions): import("../lib/tool").ToolDefinition<{
|
|
55
|
+
target_id: import("zod").ZodString;
|
|
56
|
+
cwd: import("zod").ZodOptional<import("zod").ZodString>;
|
|
57
|
+
add_dir: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
58
|
+
config_dir: import("zod").ZodOptional<import("zod").ZodString>;
|
|
59
|
+
}>;
|
|
62
60
|
export {};
|