walkie-cli 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +67 -2
- package/bin/walkie.mjs +9 -0
- package/dist/actions.js +95 -0
- package/dist/adapters.js +75 -0
- package/dist/channel.js +129 -0
- package/dist/cli.js +384 -0
- package/dist/config.js +108 -0
- package/dist/feed.js +20 -0
- package/dist/install.js +86 -0
- package/dist/join.js +89 -0
- package/dist/listen.js +129 -0
- package/dist/pair.js +71 -0
- package/dist/rendezvous.js +44 -0
- package/dist/report.js +57 -0
- package/dist/running.js +51 -0
- package/dist/sse.js +79 -0
- package/dist/webhook-server.js +102 -0
- package/package.json +52 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Niko Kalpakian
|
|
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,68 @@
|
|
|
1
|
-
#
|
|
1
|
+
# walkie-cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The recipient side of [Walkie Talkie](https://github.com/nkalpakian/Walkie Talkie): a channel you manage from your phone that your coding-agent sessions and machines subscribe to. Zero runtime dependencies, Node 20+.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx -y walkie-cli join http://192.168.1.20:8787 7E4VZZ # code from the app: Recipients → Add
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
One command: redeems the code for a token, saves it under `~/.config/walkie/`, detects Claude Code or Cursor in the current directory and installs the hooks. Manual alternative:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
export WALKIE_URL=https://channel.example.com
|
|
13
|
+
export WALKIE_TOKEN=wt_… # from the recipient screen in the app
|
|
14
|
+
npx -y walkie-cli status
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Coding agents
|
|
18
|
+
|
|
19
|
+
| Harness | Command | What it does |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| Claude Code | `npx -y walkie-cli install claude` | Adds `SessionStart` (full feed) and `UserPromptSubmit` (deltas only) command hooks to `.claude/settings.json` (`--global` for `~/.claude`). |
|
|
22
|
+
| Claude Code, live push | `npx -y walkie-cli install channel` then `claude --dangerously-load-development-channels server:walkie` | Registers a stdio MCP server in `.mcp.json` that pushes posts into the running session as channel events (research preview). |
|
|
23
|
+
| Cursor | `npx -y walkie-cli install cursor` | Adds a `beforeSubmitPrompt` hook that refreshes an always-apply rule at `.cursor/rules/walkie.mdc`. |
|
|
24
|
+
| Codex, Copilot, Gemini CLI, anything reading `AGENTS.md` | `npx -y walkie-cli install agents-md` then `npx -y walkie-cli agents-md` | Maintains a managed block in `AGENTS.md`; run from a start hook, alias or cron. |
|
|
25
|
+
|
|
26
|
+
Hooks fail open: on any error they print nothing and exit 0, so a down server never blocks an agent.
|
|
27
|
+
|
|
28
|
+
## Any machine or server
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Long-running recipient: holds a stream, resumes after restarts, acknowledges posts.
|
|
32
|
+
npx -y walkie-cli listen --name build-box \
|
|
33
|
+
--dir ./walkie-inbox \
|
|
34
|
+
--exec 'notify-send Walkie Talkie "$WALKIE_POST_TITLE"' \
|
|
35
|
+
--forward http://localhost:3000/channel \
|
|
36
|
+
--ndjson
|
|
37
|
+
|
|
38
|
+
# Verified inbound endpoint for a webhook recipient.
|
|
39
|
+
WALKIE_WEBHOOK_SECRET=whsec_… npx -y walkie-cli webhook-server --port 8790 --path /hook --dir ./walkie-inbox
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Actions can be combined. `--exec` receives the event JSON on stdin and `WALKIE_EVENT`, `WALKIE_POST_ID`, `WALKIE_POST_TITLE`, `WALKIE_POST_PRIORITY`, `WALKIE_POST_TAGS`, `WALKIE_BULLETIN`, `WALKIE_REPLAY` in the environment. A failed action leaves the stream cursor in place so the post is replayed on reconnect, and makes `webhook-server` return 500 so the relay retries.
|
|
43
|
+
|
|
44
|
+
## Back to the person
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npx -y walkie-cli report "Tests fail on ARM, see screenshot" --kind evidence --file shot.png --file test.log
|
|
48
|
+
npx -y walkie-cli report "Which DB first?" --kind question
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Shows up in the app with previews; the person's reply arrives as a post addressed only to this recipient. Session id comes from `WALKIE_SESSION_ID`, `CLAUDE_CODE_SESSION_ID` or the hostname.
|
|
52
|
+
|
|
53
|
+
## Credentials
|
|
54
|
+
|
|
55
|
+
First complete source wins: `--url`/`--token` flags, `WALKIE_URL`/`WALKIE_TOKEN`, a `.walkie.json` found walking up from the working directory (`{"url": "…", "tokenEnv": "WALKIE_TOKEN"}` so repos never commit tokens), then `~/.config/walkie/config.json` written by `walkie login --url … --token …`.
|
|
56
|
+
|
|
57
|
+
## All commands
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
claude [--delta] cursor agents-md [--file F] channel
|
|
61
|
+
listen [--name N] [--initial] [--no-ack] <actions>
|
|
62
|
+
webhook-server --port P [--path /hook] [--secret whsec_…]... [--insecure] <actions>
|
|
63
|
+
report "<message>" [--kind evidence|question|status] [--file F]... [--post ID] [--session S]
|
|
64
|
+
print [--json] status install <claude|cursor|agents-md|channel> [--global]
|
|
65
|
+
login --url U --token T
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
MIT
|
package/bin/walkie.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { main } from "../dist/cli.js";
|
|
3
|
+
main(process.argv.slice(2)).then(
|
|
4
|
+
(code) => process.exit(code ?? 0),
|
|
5
|
+
(err) => {
|
|
6
|
+
process.stderr.write(`walkie: ${err?.message ?? err}\n`);
|
|
7
|
+
process.exit(0); // hooks must never break the agent
|
|
8
|
+
},
|
|
9
|
+
);
|
package/dist/actions.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a recipient does with a post once it arrives. Shared by `listen`
|
|
3
|
+
* (SSE), `webhook-server` (inbound POST) and `channel` (Claude Code).
|
|
4
|
+
*
|
|
5
|
+
* Any machine can be a recipient: the actions are deliberately primitive so
|
|
6
|
+
* they compose with whatever is already on the box (cron, systemd, a shell
|
|
7
|
+
* script, a local service).
|
|
8
|
+
*/
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { existsSync } from "node:fs";
|
|
13
|
+
import { writeAgentsMd, writeCursorRule } from "./adapters.js";
|
|
14
|
+
export function eventEnv(ev) {
|
|
15
|
+
return {
|
|
16
|
+
WALKIE_EVENT: ev.type,
|
|
17
|
+
WALKIE_EVENT_ID: ev.id,
|
|
18
|
+
WALKIE_BULLETIN: ev.bulletin.slug,
|
|
19
|
+
WALKIE_POST_ID: ev.post?.id ?? "",
|
|
20
|
+
WALKIE_POST_TITLE: ev.post?.title ?? "",
|
|
21
|
+
WALKIE_POST_PRIORITY: ev.post?.priority ?? "",
|
|
22
|
+
WALKIE_POST_TAGS: ev.post?.tags.join(",") ?? "",
|
|
23
|
+
WALKIE_REPLAY: ev.replay ? "1" : "0",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const safe = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 80);
|
|
27
|
+
/** Runs every configured action. Throws if any action fails so callers can skip the ack. */
|
|
28
|
+
export async function runActions(ev, opts) {
|
|
29
|
+
const log = opts.log ?? (() => { });
|
|
30
|
+
const failures = [];
|
|
31
|
+
if (opts.ndjson)
|
|
32
|
+
process.stdout.write(JSON.stringify(ev) + "\n");
|
|
33
|
+
if (opts.dir) {
|
|
34
|
+
try {
|
|
35
|
+
mkdirSync(opts.dir, { recursive: true });
|
|
36
|
+
const stamp = ev.receivedAt.replace(/[:.]/g, "-");
|
|
37
|
+
const base = join(opts.dir, `${stamp}-${safe(ev.post?.id ?? ev.id)}`);
|
|
38
|
+
writeFileSync(`${base}.json`, JSON.stringify(ev, null, 2) + "\n");
|
|
39
|
+
if (ev.markdown)
|
|
40
|
+
writeFileSync(`${base}.md`, ev.markdown);
|
|
41
|
+
log(`wrote ${base}.{json,md}`);
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
failures.push(`dir: ${e instanceof Error ? e.message : String(e)}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (opts.forward) {
|
|
48
|
+
try {
|
|
49
|
+
const res = await (opts.fetchImpl ?? fetch)(opts.forward, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: { "content-type": "application/json", "x-walkie-event": ev.type },
|
|
52
|
+
body: JSON.stringify(ev),
|
|
53
|
+
});
|
|
54
|
+
if (!res.ok)
|
|
55
|
+
failures.push(`forward: HTTP ${res.status}`);
|
|
56
|
+
else
|
|
57
|
+
log(`forwarded to ${opts.forward} (${res.status})`);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
failures.push(`forward: ${e instanceof Error ? e.message : String(e)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (opts.files && opts.refresh) {
|
|
64
|
+
try {
|
|
65
|
+
const feed = await opts.refresh();
|
|
66
|
+
const wrote = [];
|
|
67
|
+
if (existsSync(join(opts.files, ".cursor")))
|
|
68
|
+
wrote.push(writeCursorRule(opts.files, feed));
|
|
69
|
+
const agents = join(opts.files, "AGENTS.md");
|
|
70
|
+
if (existsSync(agents))
|
|
71
|
+
wrote.push(writeAgentsMd(agents, feed).path);
|
|
72
|
+
if (wrote.length)
|
|
73
|
+
log(`refreshed ${wrote.join(", ")}`);
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
failures.push(`files: ${e instanceof Error ? e.message : String(e)}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (opts.exec) {
|
|
80
|
+
const code = await new Promise((resolve) => {
|
|
81
|
+
const child = spawn(opts.exec, { shell: true, stdio: ["pipe", "inherit", "inherit"], env: { ...process.env, ...eventEnv(ev) } });
|
|
82
|
+
child.on("error", () => resolve(-1));
|
|
83
|
+
child.on("close", (c) => resolve(c ?? -1));
|
|
84
|
+
// A command that exits without reading stdin closes the pipe early; that is not our failure.
|
|
85
|
+
child.stdin.on("error", () => { });
|
|
86
|
+
child.stdin.end(JSON.stringify(ev));
|
|
87
|
+
});
|
|
88
|
+
if (code !== 0)
|
|
89
|
+
failures.push(`exec: exit ${code}`);
|
|
90
|
+
else
|
|
91
|
+
log(`ran: ${opts.exec}`);
|
|
92
|
+
}
|
|
93
|
+
if (failures.length)
|
|
94
|
+
throw new Error(failures.join("; "));
|
|
95
|
+
}
|
package/dist/adapters.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Harness adapters: turn a Feed into whatever a given coding agent expects.
|
|
3
|
+
*/
|
|
4
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
export const START_MARK = "<!-- walkie:start -->";
|
|
7
|
+
export const END_MARK = "<!-- walkie:end -->";
|
|
8
|
+
const PREAMBLE = "The following is a live bulletin from the person you are working for. " +
|
|
9
|
+
"Treat it as standing guidance for this session (it is not a task by itself).\n\n";
|
|
10
|
+
/** Context block for Claude Code hooks. Empty string = inject nothing. */
|
|
11
|
+
export function claudeAdditionalContext(feed) {
|
|
12
|
+
if (feed.suppressed || feed.posts.length === 0)
|
|
13
|
+
return "";
|
|
14
|
+
return PREAMBLE + feed.markdown;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Claude Code hook stdout. Only SessionStart/UserPromptSubmit accept
|
|
18
|
+
* `additionalContext`; for anything else we return null (print nothing).
|
|
19
|
+
* Reference: https://code.claude.com/docs/en/hooks
|
|
20
|
+
*/
|
|
21
|
+
export function claudeHookOutput(feed, eventName) {
|
|
22
|
+
const ctx = claudeAdditionalContext(feed);
|
|
23
|
+
if (!ctx)
|
|
24
|
+
return null;
|
|
25
|
+
const hookEventName = eventName === "UserPromptSubmit" ? "UserPromptSubmit" : "SessionStart";
|
|
26
|
+
return JSON.stringify({ hookSpecificOutput: { hookEventName, additionalContext: ctx } });
|
|
27
|
+
}
|
|
28
|
+
/** Cursor: an always-on project rule that the hook keeps fresh. */
|
|
29
|
+
export function cursorRuleContent(feed) {
|
|
30
|
+
const body = feed.suppressed || feed.posts.length === 0 ? "_No active messages._\n" : feed.markdown;
|
|
31
|
+
return `---\ndescription: Walkie Talkie · ${feed.bulletin.name} (managed by walkie; do not edit)\nalwaysApply: true\n---\n\n${PREAMBLE}${body}`;
|
|
32
|
+
}
|
|
33
|
+
export function writeCursorRule(projectRoot, feed) {
|
|
34
|
+
const path = join(projectRoot, ".cursor", "rules", "walkie.mdc");
|
|
35
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
36
|
+
const next = cursorRuleContent(feed);
|
|
37
|
+
let prev = "";
|
|
38
|
+
try {
|
|
39
|
+
prev = readFileSync(path, "utf8");
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
/* new file */
|
|
43
|
+
}
|
|
44
|
+
if (prev !== next)
|
|
45
|
+
writeFileSync(path, next);
|
|
46
|
+
return path;
|
|
47
|
+
}
|
|
48
|
+
/** Replace (or append) the managed block in an AGENTS.md-style file. */
|
|
49
|
+
export function upsertManagedBlock(existing, inner) {
|
|
50
|
+
const block = `${START_MARK}\n${inner.trimEnd()}\n${END_MARK}`;
|
|
51
|
+
const start = existing.indexOf(START_MARK);
|
|
52
|
+
const end = existing.indexOf(END_MARK);
|
|
53
|
+
if (start !== -1 && end !== -1 && end > start) {
|
|
54
|
+
return existing.slice(0, start) + block + existing.slice(end + END_MARK.length);
|
|
55
|
+
}
|
|
56
|
+
const sep = existing.length === 0 ? "" : existing.endsWith("\n\n") ? "" : existing.endsWith("\n") ? "\n" : "\n\n";
|
|
57
|
+
return existing + sep + block + "\n";
|
|
58
|
+
}
|
|
59
|
+
export function agentsMdBlock(feed) {
|
|
60
|
+
const body = feed.suppressed || feed.posts.length === 0 ? "_No active bulletin posts._" : feed.markdown.trimEnd();
|
|
61
|
+
return `<!-- Managed by walkie. Edits inside this block are overwritten. -->\n${PREAMBLE}${body}`;
|
|
62
|
+
}
|
|
63
|
+
export function writeAgentsMd(file, feed) {
|
|
64
|
+
let prev = "";
|
|
65
|
+
try {
|
|
66
|
+
prev = readFileSync(file, "utf8");
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
/* new file */
|
|
70
|
+
}
|
|
71
|
+
const next = upsertManagedBlock(prev, agentsMdBlock(feed));
|
|
72
|
+
if (next !== prev)
|
|
73
|
+
writeFileSync(file, next);
|
|
74
|
+
return { path: file, changed: next !== prev };
|
|
75
|
+
}
|
package/dist/channel.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `walkie channel`: a stdio MCP server that pushes bulletin posts
|
|
3
|
+
* into a RUNNING Claude Code session through the Channels feature.
|
|
4
|
+
*
|
|
5
|
+
* Contract (research preview; see https://code.claude.com/docs/en/channels-reference):
|
|
6
|
+
* - declare `capabilities.experimental["claude/channel"] = {}` on initialize
|
|
7
|
+
* - emit `notifications/claude/channel` with { content: string, meta?: Record<string,string> }
|
|
8
|
+
* - meta keys must be identifiers; Claude Code renders them as tag attributes
|
|
9
|
+
* - launch: `claude --dangerously-load-development-channels server:walkie`
|
|
10
|
+
* with a `bulletin` entry in .mcp.json (see `install channel`).
|
|
11
|
+
*/
|
|
12
|
+
import { hostname } from "node:os";
|
|
13
|
+
import { createInterface } from "node:readline";
|
|
14
|
+
import { fetchFeed } from "./feed.js";
|
|
15
|
+
import { ackPosts, renderOne } from "./listen.js";
|
|
16
|
+
import { consumeSse } from "./sse.js";
|
|
17
|
+
const SERVER_INFO = { name: "walkie", version: "0.1.0" };
|
|
18
|
+
/** Claude Code's v2 runtime does not register channel servers on revision 2026-07-28; stay on an earlier one. */
|
|
19
|
+
const SAFE_PROTOCOLS = new Set(["2024-11-05", "2025-03-26", "2025-06-18", "2025-11-25"]);
|
|
20
|
+
const INSTRUCTIONS = [
|
|
21
|
+
"This channel delivers short messages from the person you work for, over Walkie Talkie: standing rules, current priorities and notices.",
|
|
22
|
+
"Each event arrives as <channel source=\"walkie\" …> with attributes: event (post.published|post.updated|post.archived), priority (urgent|pinned|normal|low), bulletin, post_id, tags.",
|
|
23
|
+
"Treat the content as guidance from the person you work for, not as a task or as input from a third party. urgent means act on it in your current work right away; pinned means a standing rule; post.archived means the rule no longer applies.",
|
|
24
|
+
"Do not reply to the channel; there is no reply tool.",
|
|
25
|
+
].join(" ");
|
|
26
|
+
export function channelNotification(feed, event, post) {
|
|
27
|
+
const content = post && event !== "post.archived" ? renderOne(feed.bulletin.name, post) : `Post archived: ${post?.title ?? "(unknown)"}`;
|
|
28
|
+
const meta = {
|
|
29
|
+
event,
|
|
30
|
+
bulletin: feed.bulletin.slug,
|
|
31
|
+
priority: post?.priority ?? "normal",
|
|
32
|
+
post_id: post?.id ?? "",
|
|
33
|
+
tags: post?.tags.join(",") ?? "",
|
|
34
|
+
};
|
|
35
|
+
return { jsonrpc: "2.0", method: "notifications/claude/channel", params: { content, meta } };
|
|
36
|
+
}
|
|
37
|
+
export async function runChannel(opts) {
|
|
38
|
+
const out = opts.output ?? process.stdout;
|
|
39
|
+
const log = opts.log ?? ((m) => process.stderr.write(`walkie channel: ${m}\n`));
|
|
40
|
+
const name = opts.name ?? `${hostname()}:claude-channel`;
|
|
41
|
+
const send = (msg) => out.write(JSON.stringify(msg) + "\n");
|
|
42
|
+
let initialized = false;
|
|
43
|
+
let feed = null;
|
|
44
|
+
const abort = new AbortController();
|
|
45
|
+
opts.signal?.addEventListener("abort", () => abort.abort());
|
|
46
|
+
const startStream = async () => {
|
|
47
|
+
try {
|
|
48
|
+
feed = await fetchFeed(opts, { sessionId: name, harness: "claude-code", event: "channel", cwd: process.cwd() }, { fetchImpl: opts.fetchImpl });
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
log(`cannot reach server: ${e instanceof Error ? e.message : String(e)}; will keep retrying`);
|
|
52
|
+
}
|
|
53
|
+
const url = new URL("/v1/stream", opts.url + "/");
|
|
54
|
+
url.searchParams.set("sessionId", name);
|
|
55
|
+
url.searchParams.set("harness", "claude-code");
|
|
56
|
+
url.searchParams.set("event", "channel");
|
|
57
|
+
await consumeSse({
|
|
58
|
+
url: url.toString(),
|
|
59
|
+
headers: { authorization: `Bearer ${opts.token}` },
|
|
60
|
+
signal: abort.signal,
|
|
61
|
+
fetchImpl: opts.fetchImpl,
|
|
62
|
+
onStatus: log,
|
|
63
|
+
onEvent: async (ev) => {
|
|
64
|
+
if (!ev.event.startsWith("post."))
|
|
65
|
+
return;
|
|
66
|
+
let payload;
|
|
67
|
+
try {
|
|
68
|
+
payload = JSON.parse(ev.data);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!feed)
|
|
74
|
+
feed = { bulletin: { id: "", slug: "walkie", name: "Walkie Talkie", description: "" } };
|
|
75
|
+
send(channelNotification(feed, ev.event, payload.post));
|
|
76
|
+
if ((opts.ack ?? true) && payload.post && ev.event !== "post.archived")
|
|
77
|
+
await ackPosts(opts, [payload.post.id], name);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
const rl = createInterface({ input: opts.input ?? process.stdin, crlfDelay: Infinity });
|
|
82
|
+
rl.on("close", () => abort.abort());
|
|
83
|
+
for await (const line of rl) {
|
|
84
|
+
if (!line.trim())
|
|
85
|
+
continue;
|
|
86
|
+
let msg;
|
|
87
|
+
try {
|
|
88
|
+
msg = JSON.parse(line);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (msg.method === "initialize") {
|
|
94
|
+
const requested = String(msg.params?.protocolVersion ?? "2025-06-18");
|
|
95
|
+
send({
|
|
96
|
+
jsonrpc: "2.0",
|
|
97
|
+
id: msg.id ?? null,
|
|
98
|
+
result: {
|
|
99
|
+
protocolVersion: SAFE_PROTOCOLS.has(requested) ? requested : "2025-06-18",
|
|
100
|
+
capabilities: { experimental: { "claude/channel": {} } },
|
|
101
|
+
serverInfo: SERVER_INFO,
|
|
102
|
+
instructions: INSTRUCTIONS,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else if (msg.method === "notifications/initialized") {
|
|
107
|
+
if (!initialized) {
|
|
108
|
+
initialized = true;
|
|
109
|
+
void startStream();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (msg.method === "ping") {
|
|
113
|
+
send({ jsonrpc: "2.0", id: msg.id ?? null, result: {} });
|
|
114
|
+
}
|
|
115
|
+
else if (msg.method === "tools/list") {
|
|
116
|
+
send({ jsonrpc: "2.0", id: msg.id ?? null, result: { tools: [] } });
|
|
117
|
+
}
|
|
118
|
+
else if (msg.method === "resources/list") {
|
|
119
|
+
send({ jsonrpc: "2.0", id: msg.id ?? null, result: { resources: [] } });
|
|
120
|
+
}
|
|
121
|
+
else if (msg.method === "prompts/list") {
|
|
122
|
+
send({ jsonrpc: "2.0", id: msg.id ?? null, result: { prompts: [] } });
|
|
123
|
+
}
|
|
124
|
+
else if (msg.id !== undefined && msg.method) {
|
|
125
|
+
send({ jsonrpc: "2.0", id: msg.id, error: { code: -32601, message: `method not found: ${msg.method}` } });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
abort.abort();
|
|
129
|
+
}
|