opencode-apex 0.3.0 → 0.5.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 +60 -0
- package/README.md +5 -1
- package/core/config.ts +2 -0
- package/core/daemon-client.ts +157 -0
- package/daemon/main.ts +688 -0
- package/daemon/shared.ts +119 -0
- package/daemon/webhooks.ts +165 -0
- package/docs/CONFIG.md +2 -1
- package/docs/ENDPOINTS.md +64 -0
- package/endpoints.ts +221 -0
- package/index.ts +9 -1
- package/opencode-apex.jsonc +3 -1
- package/package.json +9 -4
- package/skills/apex-callbacks/SKILL.md +3 -2
- package/skills/apex-callbacks/references/reachability.md +3 -1
- package/skills/apex-endpoints/SKILL.md +114 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-apex",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Modular plugin for OpenCode V2 (>= 2.1): secret redaction, RPC callbacks/webhooks/watchers that wake agents, tools.run, AI permission advisor, guard meta-permissions, temp-directory access
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Modular plugin for OpenCode V2 (>= 2.1): secret redaction, RPC callbacks/webhooks/watchers that wake agents, OpenTunnel endpoints + verified webhooks (cross-platform daemon), tools.run, AI permission advisor, guard meta-permissions, temp-directory access",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Antonio Orizondo Leyva",
|
|
7
7
|
"repository": {
|
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
"automation",
|
|
26
26
|
"permissions",
|
|
27
27
|
"cdp",
|
|
28
|
-
"browser"
|
|
28
|
+
"browser",
|
|
29
|
+
"opentunnel",
|
|
30
|
+
"tunnel"
|
|
29
31
|
],
|
|
30
32
|
"engines": {
|
|
31
33
|
"opencode": ">=2.1.0"
|
|
@@ -36,6 +38,8 @@
|
|
|
36
38
|
"index.ts",
|
|
37
39
|
"redact.ts",
|
|
38
40
|
"events.ts",
|
|
41
|
+
"daemon",
|
|
42
|
+
"endpoints.ts",
|
|
39
43
|
"advisor.ts",
|
|
40
44
|
"guard.ts",
|
|
41
45
|
"browser.ts",
|
|
@@ -50,6 +54,7 @@
|
|
|
50
54
|
"dependencies": {
|
|
51
55
|
"@opencode/plugin": "^2.1.1",
|
|
52
56
|
"@opencode/plugin-browser": "^2.1.1",
|
|
57
|
+
"@opentunnel/client": "^0.7.0",
|
|
53
58
|
"jsonc-parser": "^3.3.1",
|
|
54
59
|
"ws": "^8.22.0",
|
|
55
60
|
"zod": "^3.24.0"
|
|
@@ -59,7 +64,7 @@
|
|
|
59
64
|
"bun-types": "^1.1.0"
|
|
60
65
|
},
|
|
61
66
|
"scripts": {
|
|
62
|
-
"test": "bun test/events.test.ts && bun test/guard.test.ts && bun test/process-context.test.ts && bun test/temp-access.test.ts",
|
|
67
|
+
"test": "bun test/events.test.ts && bun test/guard.test.ts && bun test/process-context.test.ts && bun test/temp-access.test.ts && bun test/endpoints.test.ts",
|
|
63
68
|
"typecheck": "tsc --noEmit -p .",
|
|
64
69
|
"check:install": "node scripts/check-install.mjs",
|
|
65
70
|
"prepublishOnly": "npm test && npm run typecheck && npm run check:install"
|
|
@@ -101,7 +101,7 @@ Patterns, the source catalog (WebSocket, SSE, IMAP, polling, queues…), state a
|
|
|
101
101
|
- A relay that **connects out** to the source can run on a laptop behind NAT next to OpenCode. Examples: WebSocket, SSE, long-poll, IMAP IDLE, polling an API, consuming a queue. This is the default: prefer it whenever the service offers it.
|
|
102
102
|
- A **webhook** means the service connects **in**. A relay on `127.0.0.1` or a home PC behind NAT **cannot be reached from the Internet** unless you add one of these:
|
|
103
103
|
1. the service's outbound mode (Slack Socket Mode, Discord Gateway, Telegram `getUpdates`, Gmail via Pub/Sub pull);
|
|
104
|
-
2.
|
|
104
|
+
2. **`apex_webhook`**, the shortest path: a public OpenTunnel URL that checks the GitHub, Stripe or Slack signature, a generic HMAC or a token, then calls `events.ingest` locally. You write no relay code. Use **`apex_tunnel`** to publish a relay of your own (skill **`apex-endpoints`**). Without apex: `opentunnel route add <relay port>`, Cloudflare Tunnel, Tailscale Funnel or ngrok;
|
|
105
105
|
3. a reverse SSH connection to a VPS;
|
|
106
106
|
4. a small public receiver that stores events while the local relay pulls them (store-and-forward, which survives the PC being off).
|
|
107
107
|
- OpenCode listens on loopback. Run the relay **on the same machine** and expose **the relay**, with its own token, never the OpenCode server: the URL and password of the server give full control of OpenCode. Third-party webhooks (GitHub, Stripe…) always go to a relay.
|
|
@@ -140,7 +140,7 @@ A relay must:
|
|
|
140
140
|
- keep logs;
|
|
141
141
|
- read secrets from `0600` files, never from the unit or command line.
|
|
142
142
|
|
|
143
|
-
Run it as the **same user** as OpenCode, so it can read the password record. A watcher needs a scheduler instead of a supervisor. Ready-made units for systemd (Linux), launchd (macOS), Task Scheduler and NSSM/WinSW (Windows), Docker and pm2 are in **`references/run-anywhere.md`**.
|
|
143
|
+
Run it as the **same user** as OpenCode, so it can read the password record. A watcher needs a scheduler instead of a supervisor. Ready-made units for systemd (Linux), launchd (macOS), Task Scheduler and NSSM/WinSW (Windows), Docker and pm2 are in **`references/run-anywhere.md`**. If the only job is turning a third-party webhook into an event, `apex_webhook` needs no program at all.
|
|
144
144
|
|
|
145
145
|
## Before you call it done
|
|
146
146
|
|
|
@@ -178,3 +178,4 @@ All of them: `POST <baseUrl>/api/rpc/apex/<method>?location[directory]=<project>
|
|
|
178
178
|
| `references/reachability.md` | Webhooks or senders on other machines: outbound modes, OpenTunnel and OpenCode remote access, Cloudflare/Tailscale/ngrok tunnels, reverse SSH, store-and-forward, signature checks |
|
|
179
179
|
| `references/run-anywhere.md` | Keeping a relay or watcher alive on Linux, macOS, Windows, Docker, pm2, and removing it |
|
|
180
180
|
| `references/examples.md` | Copyable code: sh watcher, Python SSE relay, Node webhook relay, PowerShell ingest, n8n recipe, `tools.run` calls |
|
|
181
|
+
| skill `apex-endpoints` | `apex_webhook` / `apex_tunnel` / `apex_daemon`: verified webhooks without a relay, public URLs for your own service |
|
|
@@ -35,7 +35,9 @@ Look for it before reaching for a tunnel:
|
|
|
35
35
|
|
|
36
36
|
The tunnel client connects **out** to the provider. The provider gives you a public HTTPS URL that forwards to a local port. Point it at **the relay's port**, never at the OpenCode server.
|
|
37
37
|
|
|
38
|
-
**OpenTunnel (first choice)**: by Anomaly, the makers of OpenCode. No account. TLS ends on your machine, so the relay server cannot read the traffic.
|
|
38
|
+
**OpenTunnel (first choice)**: by Anomaly, the makers of OpenCode. No account. TLS ends on your machine, so the relay server cannot read the traffic.
|
|
39
|
+
|
|
40
|
+
**With apex you do not need the CLI.** `apex_tunnel({action:"open", port})` publishes a port. `apex_webhook` gives a verified webhook URL with no relay code. Both work on Linux, macOS and Windows, live in the apex daemon and accept a TTL (skill `apex-endpoints`). The CLI below is for machines without apex. It ships prebuilt for Linux and macOS.
|
|
39
41
|
- Install: `curl -fsSL https://opentunnel.xyz/install | sh`, `brew install anomalyco/tap/opentunnel`, or `npm install -g opentunnel`.
|
|
40
42
|
- Publish the relay:
|
|
41
43
|
```sh
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apex-endpoints
|
|
3
|
+
description: Expose things to the Internet with opencode-apex, on any OS, without a tunnel CLI. Use it when the agent must receive a webhook (GitHub, Stripe, Slack, n8n, any HMAC or token sender) that wakes an agent, or publish a local port (a service, API or demo you started) on a public HTTPS URL, temporary or permanent. Tools apex_webhook, apex_tunnel and apex_daemon, through OpenTunnel (the makers of OpenCode) and the apex daemon.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Public endpoints (apex daemon + OpenTunnel)
|
|
7
|
+
|
|
8
|
+
## The model
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
Internet ──HTTPS──▶ OpenTunnel ──▶ apex daemon (one per user, outside OpenCode)
|
|
12
|
+
<route>.<id>.opentunnel.xyz ├─ webhook: verify signature → events.ingest (local) → subscription → agent
|
|
13
|
+
└─ route → any local port (your service)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- **The apex daemon** keeps routes and webhooks alive. It is one process per user, launched by the plugin with OpenCode's own binary.
|
|
17
|
+
- It survives the 60-minute plugin unload and OpenCode restarts.
|
|
18
|
+
- It works with any init system and on Windows.
|
|
19
|
+
- It starts on the first tool call. With nothing left to keep, it exits after 10 minutes.
|
|
20
|
+
- After a reboot, it comes back when apex loads in any project.
|
|
21
|
+
- **OpenTunnel:** the daemon adds its **own routes** to this device's tunnel, the same one OpenCode remote access uses. TLS ends on this machine. New routes are cheap; new tunnels are limited to about 30 per hour per IP.
|
|
22
|
+
- **Every entry** belongs to this project. It is either **temporary** (`ttlMinutes`) or **permanent** (no TTL). The daemon removes temporary ones on time, even with OpenCode closed.
|
|
23
|
+
|
|
24
|
+
## Pick the tool
|
|
25
|
+
|
|
26
|
+
| You need | Use |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| A service (GitHub, Stripe, Slack, n8n, a form…) must call in and wake an agent | **`apex_webhook`**: no code at all |
|
|
29
|
+
| A port you started (your API, microservice, dev server, demo) on a public URL | **`apex_tunnel`** |
|
|
30
|
+
| A sender **you control** on another machine must call OpenCode's RPC itself | Not this skill: OpenCode remote access (skill `apex-callbacks`, Step 3) |
|
|
31
|
+
|
|
32
|
+
Prefer a source's **outbound** mode (WebSocket, polling…) when it has one. Nothing is exposed then (skill `apex-callbacks`).
|
|
33
|
+
|
|
34
|
+
## Webhooks: `apex_webhook`
|
|
35
|
+
|
|
36
|
+
1. **Subscribe first** with `apex_subscribe`, so the first event lands somewhere:
|
|
37
|
+
- filter on `source` (and `type`);
|
|
38
|
+
- in the template, say the payload is third-party data.
|
|
39
|
+
2. **Create:**
|
|
40
|
+
```jsonc
|
|
41
|
+
apex_webhook({ "action": "create", "name": "gh-acme-api", "provider": "github", "ttlMinutes": 0 })
|
|
42
|
+
// → { url, secretFile, secretShell: "cat '<file>'", source: "github", route, next }
|
|
43
|
+
```
|
|
44
|
+
- `provider`:
|
|
45
|
+
- `github`: `X-Hub-Signature-256`.
|
|
46
|
+
- `stripe`: `Stripe-Signature`, with a 5-minute replay window. Pass its `whsec_…` as `secret`.
|
|
47
|
+
- `slack`: signing secret, with a 5-minute replay window. Pass it as `secret`. The `url_verification` challenge is answered for you.
|
|
48
|
+
- `hmac`: HMAC-SHA256 of the raw body, hex or base64, in `header` (default `X-Signature`). A `sha256=` prefix is accepted.
|
|
49
|
+
- `token`: `Authorization: Bearer`, `X-Apex-Token` or `?token=`. For senders that cannot sign (n8n, curl, IFTTT).
|
|
50
|
+
- Without `secret`, a random one is generated. **It is never returned**: you get only `secretFile` (`0600`).
|
|
51
|
+
- Configure the sender by reading the file at run time, for example:
|
|
52
|
+
`gh api repos/OWNER/REPO/hooks -f config[url]=<url> -f config[secret]="$(cat '<secretFile>')" -f config[content_type]=json -f 'events[]=pull_request'`.
|
|
53
|
+
Never paste the secret in the chat.
|
|
54
|
+
3. **What the agent receives:**
|
|
55
|
+
- `source`: the provider, or your `source`.
|
|
56
|
+
- `type`, by provider:
|
|
57
|
+
- GitHub: `pull_request.opened`.
|
|
58
|
+
- Stripe: `invoice.paid`.
|
|
59
|
+
- Slack: the event type.
|
|
60
|
+
- hmac and token: `X-Event-Type`, else `payload.type`.
|
|
61
|
+
- `eventID`: `<name>:<delivery id>`. A redelivery is not delivered twice.
|
|
62
|
+
- `payload`: the parsed body plus `_webhook: {name, provider, headers}`. Signatures and tokens are left out of `headers`.
|
|
63
|
+
4. **What the sender gets back:**
|
|
64
|
+
- `202`: verified and delivered.
|
|
65
|
+
- `401`: bad or missing signature. Nothing is delivered.
|
|
66
|
+
- `503`: OpenCode is down. Stripe and Slack retry; GitHub shows it under "Recent deliveries".
|
|
67
|
+
5. **Check:** `apex_webhook({action:"list"})` shows `stats`: `ok` / `rejected` / `failed`, and `lastError`. Send one real test delivery and watch the agent wake up.
|
|
68
|
+
|
|
69
|
+
## Ports: `apex_tunnel`
|
|
70
|
+
|
|
71
|
+
```jsonc
|
|
72
|
+
apex_tunnel({ "action": "open", "port": 5173, "ttlMinutes": 30 }) // → { id, route, url }
|
|
73
|
+
apex_tunnel({ "action": "open", "port": 3000, "name": "demo" }) // https://demo.<id>.opentunnel.xyz, permanent
|
|
74
|
+
apex_tunnel({ "action": "list" }) · apex_tunnel({ "action": "close", "id": "<id or route>" })
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
- Routes are random by default: 16 hex characters that never appear in certificate logs. Use `name` only when a readable URL matters.
|
|
78
|
+
- `proxyProtocol: "v2"` sends the visitor's IP to the app. Only use it if the app expects a PROXY header.
|
|
79
|
+
- The OpenCode server port is refused: that is what remote access is for.
|
|
80
|
+
|
|
81
|
+
**Your own microservice behind a route:**
|
|
82
|
+
- **Listen on `127.0.0.1`.** The tunnel reaches loopback, and binding to `0.0.0.0` also exposes it to the LAN.
|
|
83
|
+
- **Authenticate every request.** Behind the tunnel, every request comes from `127.0.0.1` with a `Host` the visitor chose, so "is it local?" checks are worthless. A random route is not authentication either.
|
|
84
|
+
- **To wake agents,** call `events.ingest` (`apex_callback_endpoint`, read the password from its file on every call). If it only needs to turn a third-party call into an event, use `apex_webhook` instead and write no service at all.
|
|
85
|
+
- **The tunnel route does not keep the process alive.** Run it so it survives the session (skill `apex-callbacks`, `references/run-anywhere.md`). Keep the route's lifetime matched to the process: a TTL for temporary ones, closing the route when you stop the service.
|
|
86
|
+
|
|
87
|
+
## Temporary or permanent
|
|
88
|
+
|
|
89
|
+
- **Temporary:** always set `ttlMinutes` for tests, demos, one-off callbacks (an OAuth redirect, a payment test) and anything "for now". The daemon removes the entry on time; a webhook also loses its URL and secret file.
|
|
90
|
+
- **Permanent:** omit `ttlMinutes` only when the user wants it to stay. Tell them how to remove it (`delete`, `close`).
|
|
91
|
+
- The URL stays the same while the device tunnel exists.
|
|
92
|
+
|
|
93
|
+
## When it is not reachable
|
|
94
|
+
|
|
95
|
+
`apex_daemon({action:"status"})` returns `tunnel.state` and the `log` file:
|
|
96
|
+
- `connected`: everything is fine.
|
|
97
|
+
- `provisioning`: the device's first tunnel. The certificate takes about 1 minute; then `url` appears in `list`.
|
|
98
|
+
- `reconnecting`: the network dropped. It retries on its own.
|
|
99
|
+
- `error`: read `lastError`.
|
|
100
|
+
|
|
101
|
+
Proxy and network settings:
|
|
102
|
+
- A corporate proxy or custom CA: the daemon honours `HTTPS_PROXY` / `NO_PROXY` and `OPENTUNNEL_CA_CERT`. SOCKS is not supported.
|
|
103
|
+
- A self-hosted OpenTunnel server: set `OPENTUNNEL_API` in OpenCode's environment.
|
|
104
|
+
- After changing any of these, run `apex_daemon({action:"stop"})` so it restarts with them.
|
|
105
|
+
|
|
106
|
+
## Before you call it done
|
|
107
|
+
|
|
108
|
+
1. Send one real request through the public `url`: an actual delivery for a webhook, `curl -i <url>` with credentials for a service.
|
|
109
|
+
2. Send a **bad** request and check it is refused: a wrong signature or token gets `401`.
|
|
110
|
+
3. Tell the user:
|
|
111
|
+
- the URL and what it reaches;
|
|
112
|
+
- temporary (until when) or permanent;
|
|
113
|
+
- how to remove it;
|
|
114
|
+
- the subscription id, if any.
|