@tbrandenburg/opencode-a2a-lite 0.3.3 → 0.4.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 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,12 @@ 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 with only tool
132
+ call id, title, kind and status; tool inputs, outputs and reasoning are never published. Titles
133
+ may reveal paths or commands, so enable it only for clients you trust. The Agent Card then
134
+ declares the `urn:opencode-a2a-lite:activity:v1` extension.
129
135
  - Defaults: 30-second startup/session allocation, 120-second prompt, 5-second
130
136
  cancellation and 5-second ACP shutdown. Failure retires the unhealthy bridge.
131
137
  - Streaming sends stable artifact IDs and ordered append events. Task states are
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbrandenburg/opencode-a2a-lite",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "description": "OpenCode ACP to A2A gateway for trusted workspaces",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -6,6 +6,17 @@ import manifest from "../package.json" with { type: "json" };
6
6
  import { BridgeError } from "./bridge-error.js";
7
7
  import { supportedOpenCode } from "./opencode-version.js";
8
8
  import { StartupError } from "./startup-error.js";
9
+ // Only identifying fields are forwarded; tool inputs and outputs never leave the bridge.
10
+ function toolActivity(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
+ }
9
20
  export function createAcpBridge(options) {
10
21
  if (!isAbsolute(options.cwd))
11
22
  throw new Error("ACP workspace must be absolute");
@@ -145,6 +156,16 @@ export function createAcpBridge(options) {
145
156
  if (notification.params._meta?.["opencode/child-session"] !== undefined ||
146
157
  update._meta?.["opencode/child-session"] !== undefined)
147
158
  return;
159
+ const activity = toolActivity(update);
160
+ if (activity) {
161
+ try {
162
+ turn.onActivity?.(activity);
163
+ }
164
+ catch {
165
+ fail("ACP activity callback failed");
166
+ }
167
+ return;
168
+ }
148
169
  if (update.sessionUpdate !== "agent_message_chunk" || update.content.type !== "text")
149
170
  return;
150
171
  if (update.content._meta?.["opencode/child-session"] !== undefined)
@@ -184,13 +205,14 @@ export function createAcpBridge(options) {
184
205
  sessions.add(response.sessionId);
185
206
  return response;
186
207
  }
187
- async function prompt(sessionId, text, onText) {
208
+ async function prompt(sessionId, text, onText, onActivity) {
188
209
  const current = requireConnection(sessionId);
189
210
  if (turn)
190
211
  throw new Error("ACP prompt in progress");
191
212
  const active = {
192
213
  sessionId,
193
214
  onText,
215
+ onActivity,
194
216
  cancelled: false,
195
217
  settled: false,
196
218
  cancellation: undefined,
@@ -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 === "--help" || flag === "--version") {
33
+ if (VALUELESS.has(flag)) {
32
34
  flags.set(flag, "");
33
35
  continue;
34
36
  }
package/dist/src/cli.js CHANGED
@@ -5,13 +5,15 @@ 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). Titles may reveal paths or commands.
15
17
  --help, -h Show help without starting OpenCode.
16
18
  --version, -v Print package version without starting OpenCode.
17
19
 
@@ -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 activity summary",
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,11 +157,18 @@ 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;
132
172
  if (response.stopReason === "end_turn") {
133
173
  finish(TaskState.TASK_STATE_COMPLETED);
134
174
  return;
@@ -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 and statuses.",
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 call titles are published; they may reveal paths or commands");
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");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbrandenburg/opencode-a2a-lite",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "description": "OpenCode ACP to A2A gateway for trusted workspaces",
5
5
  "license": "MIT",
6
6
  "repository": {