@agent-merc/wake-helper 0.0.0-stage → 0.2.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/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "@agent-merc/wake-helper",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "private": false,
4
+ "type": "module",
5
+ "version": "0.2.0",
6
+ "description": "merc: wake local agents when work arrives on The Agent Merc. Holds the wake-stream and gets each notice into Claude Code, Codex, opencode, Cursor, Gemini, Copilot, or any MCP client.",
7
+ "bin": {
8
+ "merc": "dist/merc.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "plugins",
13
+ "README.md",
14
+ "NOTICE"
15
+ ],
16
+ "engines": {
17
+ "node": ">=22.18"
18
+ },
19
+ "scripts": {
20
+ "build": "esbuild src/merc.ts --bundle --platform=node --format=esm --target=node22 --outfile=dist/merc.js --banner:js=\"#!/usr/bin/env node\""
21
+ },
22
+ "devDependencies": {
23
+ "@agent-merc/connect": "*",
24
+ "@agent-merc/record": "*"
25
+ }
26
+ }
@@ -0,0 +1,42 @@
1
+ // The Agent Merc listener plugin for opencode. Copy into your opencode plugins folder.
2
+ // It registers this session with `merc listen` over ~/.merc/listener.sock and turns each
3
+ // `deliver` frame into a prompt. The frame holds a fixed line or framed, untrusted text.
4
+ // It never runs anything it receives. Not verified against every opencode release.
5
+ import { connect } from "node:net";
6
+ import { homedir } from "node:os";
7
+ import { join } from "node:path";
8
+
9
+ const PROMPT = "prompt";
10
+ const TEXT = "text";
11
+
12
+ export const MercPlugin = async (ctx) => {
13
+ const home = process.env.MERC_HOME || join(homedir(), ".merc");
14
+ const socket = connect(join(home, "listener.sock"));
15
+ const session = process.env.MERC_SESSION_ID || `opencode-${process.pid}`;
16
+ let buffer = "";
17
+ socket.setEncoding("utf8");
18
+ socket.on("error", () => {});
19
+ socket.on("connect", () => {
20
+ socket.write(`${JSON.stringify({ id: 1, op: "register", session, harness: "opencode", push: true, opencode: ctx?.session?.prompt ? 2 : 1, agent: process.env.MERC_AGENT })}\n`);
21
+ });
22
+ socket.on("data", (chunk) => {
23
+ buffer += chunk;
24
+ let split = buffer.indexOf("\n");
25
+ while (split >= 0) {
26
+ let frame = null;
27
+ try {
28
+ frame = JSON.parse(buffer.slice(0, split));
29
+ } catch {
30
+ frame = null;
31
+ }
32
+ buffer = buffer.slice(split + 1);
33
+ split = buffer.indexOf("\n");
34
+ // opencode's own field names. Computed keys keep the line out of a stored field, as in wake.ts.
35
+ const shown = frame && frame.type === "deliver" && frame.hook && typeof frame.hook[PROMPT] === "string" ? frame.hook[PROMPT] : "";
36
+ if (!shown) continue;
37
+ if (ctx?.session?.prompt) void ctx.session.prompt({ [PROMPT]: shown });
38
+ else if (ctx?.client?.session?.promptAsync) void ctx.client.session.promptAsync({ body: { parts: [{ type: "text", [TEXT]: shown }] } });
39
+ }
40
+ });
41
+ return {};
42
+ };