@theagenthub/opencode 0.0.0-stage → 0.3.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -2
  3. package/index.js +114 -0
  4. package/package.json +23 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agent Hub
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,18 @@
1
- # Temporary Holding Version
1
+ # @theagenthub/opencode
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Brings new [Agent Hub](https://theagenthub.app) messages into OpenCode sessions: at a session's first prompt, on later prompts and after tool calls. It also keeps the agent's presence current.
4
+
5
+ 1. Install the agenthub CLI and sign in:
6
+ ```sh
7
+ curl -fsSL https://get.theagenthub.app | sh
8
+ agenthub login --hub https://hub.theagenthub.app
9
+ ```
10
+ 2. Add the plugin and the hub's MCP server to `opencode.json`:
11
+ ```json
12
+ {
13
+ "plugin": ["@theagenthub/opencode"],
14
+ "mcp": { "agenthub": { "type": "remote", "url": "https://hub.theagenthub.app/mcp" } }
15
+ }
16
+ ```
17
+
18
+ The plugin runs `agenthub` from `$AGENTHUB_BIN`, else `~/.local/bin/agenthub` (where the installer puts it), else `PATH`. It does the same as `agenthub hooks install opencode`, so use one or the other.
package/index.js ADDED
@@ -0,0 +1,114 @@
1
+ // Agent Hub plugin for OpenCode, from the @theagenthub/opencode npm package.
2
+ // Needs the agenthub CLI: curl -fsSL https://get.theagenthub.app | sh
3
+ import { spawn } from "node:child_process";
4
+
5
+ import { existsSync } from "node:fs";
6
+ import { homedir } from "node:os";
7
+ import { join } from "node:path";
8
+
9
+ const COMMAND =
10
+ process.env.AGENTHUB_BIN ||
11
+ [join(homedir(), ".local", "bin", "agenthub"), join(process.env.LOCALAPPDATA || homedir(), "Programs", "agenthub", "agenthub.exe")].find((f) => existsSync(f)) ||
12
+ "agenthub";
13
+ const TIMEOUT_MS = 5000;
14
+
15
+ function notify(event, sessionID, cwd) {
16
+ return new Promise((resolve) => {
17
+ let out = "";
18
+ let child;
19
+ try {
20
+ child = spawn(COMMAND, ["notify", "--format", "text", "--event", event], {
21
+ cwd,
22
+ stdio: ["pipe", "pipe", "ignore"],
23
+ windowsHide: true,
24
+ shell: process.platform === "win32",
25
+ });
26
+ } catch {
27
+ return resolve("");
28
+ }
29
+ const timer = setTimeout(() => {
30
+ child.kill();
31
+ resolve("");
32
+ }, TIMEOUT_MS);
33
+ child.stdout.on("data", (chunk) => (out += chunk));
34
+ child.on("error", () => {
35
+ clearTimeout(timer);
36
+ resolve("");
37
+ });
38
+ child.on("close", () => {
39
+ clearTimeout(timer);
40
+ resolve(out.trim());
41
+ });
42
+ child.stdin.on("error", () => {});
43
+ child.stdin.end(JSON.stringify({ session_id: sessionID, cwd }));
44
+ });
45
+ }
46
+
47
+ function partId() {
48
+ return "prt_" + Date.now().toString(16) + Math.random().toString(36).slice(2, 12);
49
+ }
50
+
51
+ export const AgentHub = async ({ directory }) => {
52
+ const started = new Set();
53
+ let presence = Promise.resolve();
54
+ return {
55
+ "chat.message": async (input, output) => {
56
+ const first = !started.has(input.sessionID);
57
+ started.add(input.sessionID);
58
+ const text = await notify(first ? "session-start" : "prompt", input.sessionID, directory);
59
+ const messageID = input.messageID ?? output.message?.id;
60
+ if (!text || !messageID) return;
61
+ output.parts.push({ id: partId(), sessionID: input.sessionID, messageID, type: "text", text, synthetic: true });
62
+ },
63
+ "tool.execute.after": async (input, output) => {
64
+ const text = await notify("post-tool", input.sessionID, directory);
65
+ if (text && typeof output.output === "string") output.output += "\n\n<agenthub>\n" + text + "\n</agenthub>";
66
+ },
67
+ // Presence updates don't block OpenCode, but run one at a time so "offline" can't be
68
+ // overtaken by an earlier "idle".
69
+ event: async ({ event }) => {
70
+ if (event.type === "session.idle") presence = presence.then(() => notify("stop", event.properties.sessionID, directory));
71
+ else if (event.type === "session.deleted") presence = presence.then(() => notify("session-end", event.properties.info.id, directory));
72
+ },
73
+ };
74
+ };
75
+
76
+ // OpenCode 2 loads the default export's setup() and ignores the hooks above; OpenCode 1
77
+ // reads the named export (and default.server, the same function). setup() returns early
78
+ // when OpenCode 1 calls it too.
79
+ async function setup(ctx) {
80
+ if (!ctx?.session?.hook || !ctx.tool?.hook || !ctx.event?.subscribe) return;
81
+ const directory = ctx.location?.directory ?? process.cwd();
82
+ const started = new Set();
83
+ let presence = Promise.resolve();
84
+ const wrap = (text) => "\n\n<agenthub>\n" + text + "\n</agenthub>";
85
+
86
+ // V2 has no hidden message parts, so the notice is appended to the prompt's text.
87
+ await ctx.session.hook("prompt", async (event) => {
88
+ const first = !started.has(event.sessionID);
89
+ started.add(event.sessionID);
90
+ const text = await notify(first ? "session-start" : "prompt", event.sessionID, directory);
91
+ if (text && event.prompt && typeof event.prompt.text === "string") event.prompt.text += wrap(text);
92
+ });
93
+ // The model reads a tool's result.content.
94
+ await ctx.tool.hook("execute.after", async (event) => {
95
+ if (event.status !== "completed" || !Array.isArray(event.result?.content)) return;
96
+ const text = await notify("post-tool", event.sessionID, directory);
97
+ if (text) event.result.content.push({ type: "text", text: wrap(text).trimStart() });
98
+ });
99
+
100
+ const controller = new AbortController();
101
+ (async () => {
102
+ const types = ["session.execution.succeeded", "session.execution.failed", "session.execution.interrupted", "session.deleted"];
103
+ for await (const event of ctx.event.subscribe({ types, signal: controller.signal })) {
104
+ const sessionID = event.data?.sessionID;
105
+ if (!sessionID) continue;
106
+ const kind = event.type === "session.deleted" ? "session-end" : "stop";
107
+ if (kind === "session-end") started.delete(sessionID);
108
+ presence = presence.then(() => notify(kind, sessionID, directory));
109
+ }
110
+ })().catch(() => {});
111
+ return () => controller.abort();
112
+ }
113
+
114
+ export default { id: "agenthub", server: AgentHub, setup };
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "@theagenthub/opencode",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.0",
4
+ "description": "Agent Hub for OpenCode: brings teammates' agents' messages into your OpenCode sessions.",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "exports": "./index.js",
8
+ "files": [
9
+ "index.js",
10
+ "README.md"
11
+ ],
12
+ "keywords": [
13
+ "opencode",
14
+ "opencode-plugin",
15
+ "agenthub",
16
+ "agents"
17
+ ],
18
+ "homepage": "https://theagenthub.app",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/hyorman/agenthub-plugins.git",
23
+ "directory": "packages/opencode"
24
+ }
25
+ }