@tbrandenburg/opencode-a2a-lite 0.3.3 → 0.4.1
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 +13 -1
- package/dist/package.json +1 -1
- package/dist/src/acp-client.js +17 -2
- package/dist/src/activity.js +23 -0
- package/dist/src/cli-options.js +3 -1
- package/dist/src/cli.js +4 -1
- package/dist/src/executor.js +47 -3
- package/dist/src/server.js +13 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ launcher still use Linux-specific tooling.
|
|
|
88
88
|
## Usage
|
|
89
89
|
|
|
90
90
|
```text
|
|
91
|
-
opencode-a2a-lite --workspace <path> [--port <0..65535>]
|
|
91
|
+
opencode-a2a-lite --workspace <path> [--port <0..65535>] [--publish-activity]
|
|
92
92
|
opencode-a2a-lite --help | --version
|
|
93
93
|
```
|
|
94
94
|
|
|
@@ -126,6 +126,18 @@ reusing the ACP session for that context.
|
|
|
126
126
|
- Permission requests are rejected/canceled, not silently approved.
|
|
127
127
|
- A failed task names the failing phase (for example `ACP session creation failed`); the
|
|
128
128
|
underlying OpenCode diagnostic is never published. A bridge failure is permanent until restart.
|
|
129
|
+
- Every task's metadata carries `opencode.sessionId` and `opencode.stopReason` (after a session
|
|
130
|
+
exists). The session id is the key for finding the full transcript in OpenCode itself.
|
|
131
|
+
- `--publish-activity` (off by default) adds an `activity` artifact of data parts: tool call id,
|
|
132
|
+
title, kind and status, plus the model's reasoning text as `{"thought": "..."}` when OpenCode
|
|
133
|
+
emits it. Tool inputs and outputs are never published. Titles and reasoning may reveal paths,
|
|
134
|
+
commands or workspace data, so enable it only for clients you trust. The Agent Card then
|
|
135
|
+
declares the `urn:opencode-a2a-lite:activity:v1` extension. Reasoning appears only for models
|
|
136
|
+
and effort settings that emit it (for example Claude Haiku 5.5 with `effort=high`).
|
|
137
|
+
- The gateway never approves permission requests. A turn stopped by a rejection ends `canceled`
|
|
138
|
+
with the message "Permission request rejected" and `opencode.permissionDenied: "true"` in the
|
|
139
|
+
task metadata; a client cancellation carries neither. Permissions that OpenCode's own configuration
|
|
140
|
+
allows are never asked, so they are never rejected.
|
|
129
141
|
- Defaults: 30-second startup/session allocation, 120-second prompt, 5-second
|
|
130
142
|
cancellation and 5-second ACP shutdown. Failure retires the unhealthy bridge.
|
|
131
143
|
- Streaming sends stable artifact IDs and ordered append events. Task states are
|
package/dist/package.json
CHANGED
package/dist/src/acp-client.js
CHANGED
|
@@ -3,6 +3,7 @@ import { isAbsolute } from "node:path";
|
|
|
3
3
|
import { Readable, Writable } from "node:stream";
|
|
4
4
|
import * as acp from "@agentclientprotocol/sdk";
|
|
5
5
|
import manifest from "../package.json" with { type: "json" };
|
|
6
|
+
import { activityOf } from "./activity.js";
|
|
6
7
|
import { BridgeError } from "./bridge-error.js";
|
|
7
8
|
import { supportedOpenCode } from "./opencode-version.js";
|
|
8
9
|
import { StartupError } from "./startup-error.js";
|
|
@@ -128,6 +129,7 @@ export function createAcpBridge(options) {
|
|
|
128
129
|
turn.cancelled ||
|
|
129
130
|
request.params.sessionId !== turn.sessionId)
|
|
130
131
|
return { outcome: { outcome: "cancelled" } };
|
|
132
|
+
turn.denied = true;
|
|
131
133
|
const reject = request.params.options.find((option) => option.kind === "reject_once" || option.kind === "reject_always");
|
|
132
134
|
return {
|
|
133
135
|
outcome: reject
|
|
@@ -145,6 +147,16 @@ export function createAcpBridge(options) {
|
|
|
145
147
|
if (notification.params._meta?.["opencode/child-session"] !== undefined ||
|
|
146
148
|
update._meta?.["opencode/child-session"] !== undefined)
|
|
147
149
|
return;
|
|
150
|
+
const activity = activityOf(update);
|
|
151
|
+
if (activity) {
|
|
152
|
+
try {
|
|
153
|
+
turn.onActivity?.(activity);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
fail("ACP activity callback failed");
|
|
157
|
+
}
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
148
160
|
if (update.sessionUpdate !== "agent_message_chunk" || update.content.type !== "text")
|
|
149
161
|
return;
|
|
150
162
|
if (update.content._meta?.["opencode/child-session"] !== undefined)
|
|
@@ -184,13 +196,15 @@ export function createAcpBridge(options) {
|
|
|
184
196
|
sessions.add(response.sessionId);
|
|
185
197
|
return response;
|
|
186
198
|
}
|
|
187
|
-
async function prompt(sessionId, text, onText) {
|
|
199
|
+
async function prompt(sessionId, text, onText, onActivity) {
|
|
188
200
|
const current = requireConnection(sessionId);
|
|
189
201
|
if (turn)
|
|
190
202
|
throw new Error("ACP prompt in progress");
|
|
191
203
|
const active = {
|
|
192
204
|
sessionId,
|
|
193
205
|
onText,
|
|
206
|
+
onActivity,
|
|
207
|
+
denied: false,
|
|
194
208
|
cancelled: false,
|
|
195
209
|
settled: false,
|
|
196
210
|
cancellation: undefined,
|
|
@@ -202,7 +216,8 @@ export function createAcpBridge(options) {
|
|
|
202
216
|
prompt: [{ type: "text", text }],
|
|
203
217
|
}), promptTimeout, "prompt");
|
|
204
218
|
try {
|
|
205
|
-
|
|
219
|
+
const response = await active.completion;
|
|
220
|
+
return active.denied ? { ...response, permissionDenied: true } : response;
|
|
206
221
|
}
|
|
207
222
|
finally {
|
|
208
223
|
active.settled = true;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function thoughtOf(update) {
|
|
2
|
+
if (update.sessionUpdate !== "agent_thought_chunk")
|
|
3
|
+
return;
|
|
4
|
+
if (update.content.type !== "text" || !update.content.text)
|
|
5
|
+
return;
|
|
6
|
+
if (update.content._meta?.["opencode/child-session"] !== undefined)
|
|
7
|
+
return;
|
|
8
|
+
return { thought: update.content.text };
|
|
9
|
+
}
|
|
10
|
+
function toolOf(update) {
|
|
11
|
+
if (update.sessionUpdate !== "tool_call" && update.sessionUpdate !== "tool_call_update")
|
|
12
|
+
return;
|
|
13
|
+
return {
|
|
14
|
+
toolCallId: update.toolCallId,
|
|
15
|
+
...(update.title ? { title: update.title } : {}),
|
|
16
|
+
...(update.kind ? { kind: update.kind } : {}),
|
|
17
|
+
...(update.status ? { status: update.status } : {}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
// Tool inputs and outputs never leave the bridge: only identifying fields and thought text do.
|
|
21
|
+
export function activityOf(update) {
|
|
22
|
+
return thoughtOf(update) ?? toolOf(update);
|
|
23
|
+
}
|
package/dist/src/cli-options.js
CHANGED
|
@@ -17,10 +17,12 @@ export function parseOptions(args, env) {
|
|
|
17
17
|
server: {
|
|
18
18
|
workspace,
|
|
19
19
|
port: parsePort(flags.get("--port") ?? env.A2A_PORT),
|
|
20
|
+
...(flags.has("--publish-activity") ? { executor: { activity: true } } : {}),
|
|
20
21
|
...(identity === undefined ? {} : { identity }),
|
|
21
22
|
},
|
|
22
23
|
};
|
|
23
24
|
}
|
|
25
|
+
const VALUELESS = new Set(["--help", "--version", "--publish-activity"]);
|
|
24
26
|
function parseFlags(args) {
|
|
25
27
|
const flags = new Map();
|
|
26
28
|
for (let index = 0; index < args.length; index += 1) {
|
|
@@ -28,7 +30,7 @@ function parseFlags(args) {
|
|
|
28
30
|
const flag = token === "-h" ? "--help" : token === "-v" ? "--version" : token;
|
|
29
31
|
if (flag === undefined || flags.has(flag))
|
|
30
32
|
throw new StartupError("arguments");
|
|
31
|
-
if (flag
|
|
33
|
+
if (VALUELESS.has(flag)) {
|
|
32
34
|
flags.set(flag, "");
|
|
33
35
|
continue;
|
|
34
36
|
}
|
package/dist/src/cli.js
CHANGED
|
@@ -5,13 +5,16 @@ import { reportStartupError } from "./startup-error.js";
|
|
|
5
5
|
async function main() {
|
|
6
6
|
const options = parseOptions(process.argv.slice(2), process.env);
|
|
7
7
|
if (options.action === "help") {
|
|
8
|
-
console.log(`Usage: opencode-a2a-lite --workspace <path> [--port <0..65535>]
|
|
8
|
+
console.log(`Usage: opencode-a2a-lite --workspace <path> [--port <0..65535>] [--publish-activity]
|
|
9
9
|
|
|
10
10
|
Start the foreground, unauthenticated A2A gateway.
|
|
11
11
|
Linux or macOS (experimental), Bun 1.4.4, stable OpenCode 2.2.7 or newer on PATH, and configured provider required.
|
|
12
12
|
|
|
13
13
|
--workspace <path> Explicitly trust this directory; relative paths are resolved.
|
|
14
14
|
--port <0..65535> Port (default 41241; 0 selects a free port).
|
|
15
|
+
--publish-activity Also publish an "activity" artifact with tool call ids, titles, kinds and
|
|
16
|
+
statuses (no inputs or outputs) and the model's reasoning text.
|
|
17
|
+
May reveal paths, commands or workspace data.
|
|
15
18
|
--help, -h Show help without starting OpenCode.
|
|
16
19
|
--version, -v Print package version without starting OpenCode.
|
|
17
20
|
|
package/dist/src/executor.js
CHANGED
|
@@ -4,6 +4,15 @@ import { TaskNotCancelableError } from "@a2a-js/sdk/errors";
|
|
|
4
4
|
import { AgentEvent, } from "@a2a-js/sdk/server";
|
|
5
5
|
import { BridgeError } from "./bridge-error.js";
|
|
6
6
|
export const EXPLICIT_CONTEXT = "opencode.explicitContext";
|
|
7
|
+
export const ACTIVITY_EXTENSION = "urn:opencode-a2a-lite:activity:v1";
|
|
8
|
+
function dataPart(value) {
|
|
9
|
+
return {
|
|
10
|
+
content: { $case: "data", value },
|
|
11
|
+
mediaType: "application/json",
|
|
12
|
+
filename: "",
|
|
13
|
+
metadata: undefined,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
7
16
|
function textPart(text) {
|
|
8
17
|
return {
|
|
9
18
|
content: { $case: "text", value: text },
|
|
@@ -22,7 +31,10 @@ export function createAgentExecutor(bridge, options = {}) {
|
|
|
22
31
|
const taskId = ctx.taskId;
|
|
23
32
|
const contextId = ctx.contextId;
|
|
24
33
|
const artifactId = randomUUID();
|
|
34
|
+
const activityId = randomUUID();
|
|
35
|
+
const meta = {};
|
|
25
36
|
let emitted = false;
|
|
37
|
+
let activityEmitted = false;
|
|
26
38
|
let terminal = false;
|
|
27
39
|
function status(state, text) {
|
|
28
40
|
bus.publish(AgentEvent.statusUpdate({
|
|
@@ -44,7 +56,7 @@ export function createAgentExecutor(bridge, options = {}) {
|
|
|
44
56
|
}
|
|
45
57
|
: undefined,
|
|
46
58
|
},
|
|
47
|
-
metadata: undefined,
|
|
59
|
+
metadata: Object.keys(meta).length ? { ...meta } : undefined,
|
|
48
60
|
}));
|
|
49
61
|
}
|
|
50
62
|
function chunk(text, lastChunk = false) {
|
|
@@ -65,10 +77,31 @@ export function createAgentExecutor(bridge, options = {}) {
|
|
|
65
77
|
}));
|
|
66
78
|
emitted = true;
|
|
67
79
|
}
|
|
80
|
+
function activity(entry) {
|
|
81
|
+
const lastChunk = entry === undefined;
|
|
82
|
+
bus.publish(AgentEvent.artifactUpdate({
|
|
83
|
+
taskId,
|
|
84
|
+
contextId,
|
|
85
|
+
artifact: {
|
|
86
|
+
artifactId: activityId,
|
|
87
|
+
name: "activity",
|
|
88
|
+
description: "Tool call summaries and reasoning text",
|
|
89
|
+
parts: [entry ? dataPart(entry) : textPart("")],
|
|
90
|
+
metadata: undefined,
|
|
91
|
+
extensions: [ACTIVITY_EXTENSION],
|
|
92
|
+
},
|
|
93
|
+
append: activityEmitted,
|
|
94
|
+
lastChunk,
|
|
95
|
+
metadata: undefined,
|
|
96
|
+
}));
|
|
97
|
+
activityEmitted = true;
|
|
98
|
+
}
|
|
68
99
|
function finish(state, text) {
|
|
69
100
|
terminal = true;
|
|
70
101
|
if (emitted)
|
|
71
102
|
chunk("", true);
|
|
103
|
+
if (activityEmitted)
|
|
104
|
+
activity();
|
|
72
105
|
status(state, text);
|
|
73
106
|
}
|
|
74
107
|
bus.publish(AgentEvent.task(ctx.task ?? {
|
|
@@ -124,17 +157,28 @@ export function createAgentExecutor(bridge, options = {}) {
|
|
|
124
157
|
try {
|
|
125
158
|
const sessionId = existing ?? (await bridge.newSession()).sessionId;
|
|
126
159
|
record.sessionId = sessionId;
|
|
160
|
+
meta["opencode.sessionId"] = sessionId;
|
|
127
161
|
sessions.set(contextId, sessionId);
|
|
128
162
|
const response = await bridge.prompt(sessionId, text, (value) => {
|
|
129
163
|
if (!terminal && value)
|
|
130
164
|
chunk(value);
|
|
131
|
-
}
|
|
165
|
+
}, options.activity
|
|
166
|
+
? (entry) => {
|
|
167
|
+
if (!terminal)
|
|
168
|
+
activity(entry);
|
|
169
|
+
}
|
|
170
|
+
: undefined);
|
|
171
|
+
meta["opencode.stopReason"] = response.stopReason;
|
|
172
|
+
if (response.permissionDenied)
|
|
173
|
+
meta["opencode.permissionDenied"] = "true";
|
|
132
174
|
if (response.stopReason === "end_turn") {
|
|
133
175
|
finish(TaskState.TASK_STATE_COMPLETED);
|
|
134
176
|
return;
|
|
135
177
|
}
|
|
136
178
|
if (response.stopReason === "cancelled") {
|
|
137
|
-
finish(TaskState.TASK_STATE_CANCELED
|
|
179
|
+
finish(TaskState.TASK_STATE_CANCELED, response.permissionDenied && !record.cancellation
|
|
180
|
+
? "Permission request rejected; the gateway never approves tool permissions"
|
|
181
|
+
: undefined);
|
|
138
182
|
return;
|
|
139
183
|
}
|
|
140
184
|
sessions.delete(contextId);
|
package/dist/src/server.js
CHANGED
|
@@ -7,7 +7,7 @@ import manifest from "../package.json" with { type: "json" };
|
|
|
7
7
|
import { A2A_PROTOCOL_VERSION, AGENT_CARD_PATH } from "@a2a-js/sdk";
|
|
8
8
|
import { agentCardHandler, jsonRpcHandler, UserBuilder } from "@a2a-js/sdk/server/express";
|
|
9
9
|
import { createAcpBridge } from "./acp-client.js";
|
|
10
|
-
import { createAgentExecutor, EXPLICIT_CONTEXT } from "./executor.js";
|
|
10
|
+
import { ACTIVITY_EXTENSION, createAgentExecutor, EXPLICIT_CONTEXT, } from "./executor.js";
|
|
11
11
|
import { createRequestHandler } from "./request-handler.js";
|
|
12
12
|
import { parseOptions } from "./cli-options.js";
|
|
13
13
|
import { reportStartupError, StartupError } from "./startup-error.js";
|
|
@@ -104,7 +104,16 @@ export function createGateway(options) {
|
|
|
104
104
|
streaming: true,
|
|
105
105
|
pushNotifications: false,
|
|
106
106
|
extendedAgentCard: false,
|
|
107
|
-
extensions:
|
|
107
|
+
extensions: options.executor?.activity
|
|
108
|
+
? [
|
|
109
|
+
{
|
|
110
|
+
uri: ACTIVITY_EXTENSION,
|
|
111
|
+
description: "Adds an optional 'activity' artifact of tool call ids, titles, kinds, statuses and reasoning text.",
|
|
112
|
+
required: false,
|
|
113
|
+
params: undefined,
|
|
114
|
+
},
|
|
115
|
+
]
|
|
116
|
+
: [],
|
|
108
117
|
},
|
|
109
118
|
securitySchemes: {},
|
|
110
119
|
securityRequirements: [],
|
|
@@ -191,6 +200,8 @@ export async function launchGateway(options) {
|
|
|
191
200
|
const cardUrl = new URL(".well-known/agent-card.json", ready.url).href;
|
|
192
201
|
status("ready", `gateway · ${ready.url}`);
|
|
193
202
|
status("workspace", options.workspace);
|
|
203
|
+
if (options.executor?.activity)
|
|
204
|
+
status("activity", "tool calls and reasoning text are published; they may reveal paths, commands or workspace data");
|
|
194
205
|
status("agent card", cardUrl);
|
|
195
206
|
status("connect", `a2a send -a ${ready.url} "Reply with a short greeting." --stream`);
|
|
196
207
|
status("stop", "press Ctrl-C to stop the gateway");
|