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/dist/cli.js
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { claudeHookOutput, writeAgentsMd, writeCursorRule, } from "./adapters.js";
|
|
4
|
+
import { PROJECT_FILE, readSessionState, resolveConfig, writeSessionState, writeUserConfig, } from "./config.js";
|
|
5
|
+
import { runChannel } from "./channel.js";
|
|
6
|
+
import { fetchFeed } from "./feed.js";
|
|
7
|
+
import { installAgentsMd, installChannel, installClaude, installCursor } from "./install.js";
|
|
8
|
+
import { ackPosts, listen } from "./listen.js";
|
|
9
|
+
import { join, normalizeCode, parseJoinArgs } from "./join.js";
|
|
10
|
+
import { resolveServer } from "./rendezvous.js";
|
|
11
|
+
import { machineName, newScanCode, pairLink, renderQr, waitForApproval } from "./pair.js";
|
|
12
|
+
import { sendReport } from "./report.js";
|
|
13
|
+
import { detectRunning, liveSessionNotes } from "./running.js";
|
|
14
|
+
import { createWebhookServer } from "./webhook-server.js";
|
|
15
|
+
const HELP = `walkie — Walkie Talkie for your coding agents: pull messages in, send reports back
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
Pair this machine (one command; code comes from the app)
|
|
19
|
+
Pair this machine: show a QR code, scan it with your phone's camera, tap Pair
|
|
20
|
+
walkie pair [--name N] [--harness H] [--no-install] [--global]
|
|
21
|
+
|
|
22
|
+
Pair with a code typed from the app instead
|
|
23
|
+
walkie join <code> [--name N] [--harness H] [--no-install] [--global]
|
|
24
|
+
walkie join <server-url> <code> (always works; needed for servers without a public HTTPS address)
|
|
25
|
+
|
|
26
|
+
Already have sessions open?
|
|
27
|
+
walkie sync Write the feed into .cursor/rules and AGENTS.md now, and say what each running
|
|
28
|
+
session needs (Cursor/Codex: nothing; Claude Code: type /hooks once)
|
|
29
|
+
|
|
30
|
+
Coding agents (pull on the agent's own events)
|
|
31
|
+
walkie claude [--delta] Claude Code hook (reads hook JSON on stdin)
|
|
32
|
+
walkie cursor Cursor hook: refreshes .cursor/rules/walkie.mdc
|
|
33
|
+
walkie agents-md [--file F] Rewrite the managed block in AGENTS.md
|
|
34
|
+
walkie channel Claude Code channel: push posts into a running session (stdio MCP)
|
|
35
|
+
|
|
36
|
+
Any machine or server (long-running recipients)
|
|
37
|
+
walkie listen [--name N] [--initial] [--no-ack] <actions>
|
|
38
|
+
Hold an SSE stream, resume after restarts, run actions per post
|
|
39
|
+
actions also: --files <projectRoot> keep .cursor/rules/walkie.mdc and AGENTS.md fresh for open sessions
|
|
40
|
+
walkie webhook-server --port P [--path /hook] [--secret whsec_…] <actions>
|
|
41
|
+
Verified inbound webhook endpoint that runs actions per post
|
|
42
|
+
actions: --exec "<cmd>" --dir <inbox> --forward <url> --ndjson (combine freely)
|
|
43
|
+
|
|
44
|
+
Back to the person (from any session or machine)
|
|
45
|
+
walkie report "<message>" [--file shot.png]... [--kind evidence|question|status] [--post ID]
|
|
46
|
+
Send evidence, a question or a status with attachments; shown in the app
|
|
47
|
+
|
|
48
|
+
Everything else
|
|
49
|
+
walkie print [--json] Print the feed (markdown or JSON)
|
|
50
|
+
walkie status Show resolved config and a feed summary
|
|
51
|
+
walkie install <claude|cursor|agents-md|channel> [--global]
|
|
52
|
+
walkie login --url U --token T Save credentials to ~/.config/walkie/config.json
|
|
53
|
+
|
|
54
|
+
Credentials (first complete source wins):
|
|
55
|
+
--url/--token flags · WALKIE_URL/WALKIE_TOKEN env · ${PROJECT_FILE} (url + tokenEnv) · user config
|
|
56
|
+
|
|
57
|
+
Hooks never fail the agent: on any error they print nothing and exit 0.
|
|
58
|
+
`;
|
|
59
|
+
async function readStdinJson(timeoutMs = 300) {
|
|
60
|
+
if (process.stdin.isTTY)
|
|
61
|
+
return {};
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
let data = "";
|
|
64
|
+
const done = () => {
|
|
65
|
+
try {
|
|
66
|
+
resolve(data.trim() ? JSON.parse(data) : {});
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
resolve({});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const t = setTimeout(done, timeoutMs);
|
|
73
|
+
process.stdin.setEncoding("utf8");
|
|
74
|
+
process.stdin.on("data", (c) => (data += c));
|
|
75
|
+
process.stdin.on("end", () => {
|
|
76
|
+
clearTimeout(t);
|
|
77
|
+
done();
|
|
78
|
+
});
|
|
79
|
+
process.stdin.on("error", () => {
|
|
80
|
+
clearTimeout(t);
|
|
81
|
+
done();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const out = (s) => process.stdout.write(s.endsWith("\n") ? s : s + "\n");
|
|
86
|
+
const err = (s) => process.stderr.write(`walkie: ${s}\n`);
|
|
87
|
+
export async function main(argv) {
|
|
88
|
+
const { values, positionals } = parseArgs({
|
|
89
|
+
args: argv,
|
|
90
|
+
allowPositionals: true,
|
|
91
|
+
options: {
|
|
92
|
+
delta: { type: "boolean", default: false },
|
|
93
|
+
json: { type: "boolean", default: false },
|
|
94
|
+
global: { type: "boolean", default: false },
|
|
95
|
+
file: { type: "string", multiple: true },
|
|
96
|
+
url: { type: "string" },
|
|
97
|
+
token: { type: "string" },
|
|
98
|
+
cwd: { type: "string" },
|
|
99
|
+
name: { type: "string" },
|
|
100
|
+
exec: { type: "string" },
|
|
101
|
+
dir: { type: "string" },
|
|
102
|
+
forward: { type: "string" },
|
|
103
|
+
files: { type: "string" },
|
|
104
|
+
ndjson: { type: "boolean", default: false },
|
|
105
|
+
initial: { type: "boolean", default: false },
|
|
106
|
+
"no-ack": { type: "boolean", default: false },
|
|
107
|
+
port: { type: "string" },
|
|
108
|
+
host: { type: "string" },
|
|
109
|
+
path: { type: "string" },
|
|
110
|
+
secret: { type: "string", multiple: true },
|
|
111
|
+
kind: { type: "string" },
|
|
112
|
+
harness: { type: "string" },
|
|
113
|
+
"no-install": { type: "boolean", default: false },
|
|
114
|
+
post: { type: "string" },
|
|
115
|
+
session: { type: "string" },
|
|
116
|
+
insecure: { type: "boolean", default: false },
|
|
117
|
+
help: { type: "boolean", short: "h", default: false },
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
let [cmd, arg] = positionals;
|
|
121
|
+
// `npx walkie-cli` on a machine that has never been paired: that is what the person is here to do.
|
|
122
|
+
if (!cmd && !values.help && process.stdout.isTTY && !resolveConfig({ cwd: values.cwd ?? process.cwd() }))
|
|
123
|
+
cmd = "pair";
|
|
124
|
+
if (values.help || !cmd) {
|
|
125
|
+
out(HELP);
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
const cwd = values.cwd ?? process.cwd();
|
|
129
|
+
if (cmd === "pair") {
|
|
130
|
+
const code = newScanCode();
|
|
131
|
+
const name = values.name ?? machineName();
|
|
132
|
+
out("");
|
|
133
|
+
out(await renderQr(pairLink(code, name)));
|
|
134
|
+
out(" Point your phone's camera at this code, then tap Pair in Walkie Talkie.");
|
|
135
|
+
out(" Waiting for your phone… (Ctrl-C to cancel)");
|
|
136
|
+
try {
|
|
137
|
+
const serverUrl = await waitForApproval(code, process.env);
|
|
138
|
+
out(` approved. connecting to ${serverUrl}`);
|
|
139
|
+
const r = await join(serverUrl, code, { cwd, name, harness: values.harness, install: !values["no-install"], global: values.global, log: (m) => out(` ${m}`) });
|
|
140
|
+
out(` paired with "${r.bulletin.name}". Messages you send from your phone now reach agent sessions on this machine.`);
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
err(e instanceof Error ? e.message : String(e));
|
|
145
|
+
return 1;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// -- commands that do not need credentials ------------------------------
|
|
149
|
+
if (cmd === "join") {
|
|
150
|
+
const parsed = parseJoinArgs(positionals.slice(1));
|
|
151
|
+
if (!parsed) {
|
|
152
|
+
err("usage: walkie join <code> (or: join <server-url> <code>, or: join <server-url>/join/<code>)");
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
let serverUrl = parsed.url;
|
|
157
|
+
if (!serverUrl) {
|
|
158
|
+
serverUrl = await resolveServer(normalizeCode(parsed.code), process.env);
|
|
159
|
+
// Say where this machine is about to be connected before it happens.
|
|
160
|
+
out(`found your server: ${serverUrl}`);
|
|
161
|
+
}
|
|
162
|
+
const r = await join(serverUrl, parsed.code, {
|
|
163
|
+
cwd,
|
|
164
|
+
name: values.name,
|
|
165
|
+
harness: values.harness,
|
|
166
|
+
install: !values["no-install"],
|
|
167
|
+
global: values.global,
|
|
168
|
+
log: (m) => out(m),
|
|
169
|
+
});
|
|
170
|
+
// Sessions that are already open: write the file-based surfaces now and say what else is needed.
|
|
171
|
+
try {
|
|
172
|
+
const feed = await fetchFeed({ url: r.serverUrl || serverUrl, token: r.token }, { cwd, event: "sync", harness: r.subscriber ? undefined : undefined });
|
|
173
|
+
const wrote = [];
|
|
174
|
+
if (existsSync(`${cwd}/.cursor`))
|
|
175
|
+
wrote.push(writeCursorRule(cwd, feed));
|
|
176
|
+
if (existsSync(`${cwd}/AGENTS.md`))
|
|
177
|
+
wrote.push(writeAgentsMd(`${cwd}/AGENTS.md`, feed).path);
|
|
178
|
+
for (const w of wrote)
|
|
179
|
+
out(`wrote ${w}`);
|
|
180
|
+
for (const n of liveSessionNotes(detectRunning(), { claude: r.installed.some((f) => f.includes(".claude")), cursorRule: wrote.some((w) => w.includes(".cursor")), agentsMd: wrote.some((w) => w.endsWith("AGENTS.md")) }))
|
|
181
|
+
out(`- ${n}`);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
/* non-fatal: join already succeeded */
|
|
185
|
+
}
|
|
186
|
+
out(`done. test with: walkie status${r.installed.length ? "" : " (no hooks installed; use `walkie install <claude|cursor|agents-md|channel>` or `walkie listen`)"}`);
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
err(e instanceof Error ? e.message : String(e));
|
|
191
|
+
return 1;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (cmd === "install") {
|
|
195
|
+
if (arg === "claude")
|
|
196
|
+
out(`wrote ${installClaude({ projectRoot: cwd, global: values.global })}`);
|
|
197
|
+
else if (arg === "cursor")
|
|
198
|
+
out(`wrote ${installCursor({ projectRoot: cwd })}`);
|
|
199
|
+
else if (arg === "agents-md")
|
|
200
|
+
out(`wrote ${installAgentsMd({ projectRoot: cwd, file: values.file?.[0] })}`);
|
|
201
|
+
else if (arg === "channel") {
|
|
202
|
+
const r = installChannel({ projectRoot: cwd });
|
|
203
|
+
out(`wrote ${r.path}`);
|
|
204
|
+
out(`launch Claude Code with: ${r.launch}`);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
err(`unknown install target "${arg ?? ""}" (claude | cursor | agents-md)`);
|
|
208
|
+
return 1;
|
|
209
|
+
}
|
|
210
|
+
out(`next: set WALKIE_URL/WALKIE_TOKEN, or run \`walkie login --url … --token …\``);
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
if (cmd === "webhook-server") {
|
|
214
|
+
const secrets = [...(values.secret ?? []), ...(process.env.WALKIE_WEBHOOK_SECRET ? [process.env.WALKIE_WEBHOOK_SECRET] : [])];
|
|
215
|
+
if (secrets.length === 0 && !values.insecure) {
|
|
216
|
+
err("webhook-server needs --secret whsec_… (or WALKIE_WEBHOOK_SECRET), or --insecure for local tests");
|
|
217
|
+
return 1;
|
|
218
|
+
}
|
|
219
|
+
const port = Number(values.port ?? 8790);
|
|
220
|
+
const server = createWebhookServer({
|
|
221
|
+
port,
|
|
222
|
+
host: values.host,
|
|
223
|
+
path: values.path ?? "/",
|
|
224
|
+
secrets,
|
|
225
|
+
insecure: values.insecure,
|
|
226
|
+
exec: values.exec,
|
|
227
|
+
dir: values.dir,
|
|
228
|
+
forward: values.forward,
|
|
229
|
+
ndjson: values.ndjson,
|
|
230
|
+
log: (m) => err(m),
|
|
231
|
+
});
|
|
232
|
+
await new Promise((resolve) => server.listen(port, values.host ?? "0.0.0.0", resolve));
|
|
233
|
+
err(`listening on http://${values.host ?? "0.0.0.0"}:${port}${values.path ?? "/"} (${secrets.length} secret${secrets.length === 1 ? "" : "s"}${values.insecure ? ", INSECURE" : ""})`);
|
|
234
|
+
await new Promise((resolve) => {
|
|
235
|
+
process.on("SIGINT", () => server.close(() => resolve()));
|
|
236
|
+
process.on("SIGTERM", () => server.close(() => resolve()));
|
|
237
|
+
});
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
if (cmd === "login") {
|
|
241
|
+
if (!values.url || !values.token) {
|
|
242
|
+
err("login needs --url and --token");
|
|
243
|
+
return 1;
|
|
244
|
+
}
|
|
245
|
+
out(`saved ${writeUserConfig({ url: values.url, token: values.token })}`);
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
// -- everything else needs a feed ---------------------------------------
|
|
249
|
+
const cfg = resolveConfig({ cwd, url: values.url, token: values.token });
|
|
250
|
+
if (!cfg) {
|
|
251
|
+
err(`no credentials found (WALKIE_URL/WALKIE_TOKEN, ${PROJECT_FILE}, or \`walkie login\`)`);
|
|
252
|
+
return cmd === "status" || cmd === "print" ? 1 : 0; // hooks fail open
|
|
253
|
+
}
|
|
254
|
+
if (cmd === "listen") {
|
|
255
|
+
const ac = new AbortController();
|
|
256
|
+
process.on("SIGINT", () => ac.abort());
|
|
257
|
+
process.on("SIGTERM", () => ac.abort());
|
|
258
|
+
await listen({
|
|
259
|
+
...cfg,
|
|
260
|
+
name: values.name,
|
|
261
|
+
initial: values.initial,
|
|
262
|
+
ack: !values["no-ack"],
|
|
263
|
+
exec: values.exec,
|
|
264
|
+
dir: values.dir,
|
|
265
|
+
forward: values.forward,
|
|
266
|
+
files: values.files,
|
|
267
|
+
ndjson: values.ndjson,
|
|
268
|
+
signal: ac.signal,
|
|
269
|
+
});
|
|
270
|
+
return 0;
|
|
271
|
+
}
|
|
272
|
+
if (cmd === "sync") {
|
|
273
|
+
let feed;
|
|
274
|
+
try {
|
|
275
|
+
feed = await fetchFeed(cfg, { sessionId: process.env.CLAUDE_CODE_SESSION_ID, harness: undefined, cwd, event: "sync" });
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
err(e instanceof Error ? e.message : String(e));
|
|
279
|
+
return 1;
|
|
280
|
+
}
|
|
281
|
+
const wrote = [];
|
|
282
|
+
if (existsSync(`${cwd}/.cursor`))
|
|
283
|
+
wrote.push(writeCursorRule(cwd, feed));
|
|
284
|
+
if (existsSync(`${cwd}/AGENTS.md`))
|
|
285
|
+
wrote.push(writeAgentsMd(`${cwd}/AGENTS.md`, feed).path);
|
|
286
|
+
out(`${feed.bulletin.name}: ${feed.posts.length} post${feed.posts.length === 1 ? "" : "s"} served to "${feed.subscriber.name}"${feed.suppressed ? ` (suppressed: ${feed.suppressedReason})` : ""}`);
|
|
287
|
+
for (const w of wrote)
|
|
288
|
+
out(`wrote ${w}`);
|
|
289
|
+
const running = detectRunning();
|
|
290
|
+
const claudeInstalled = existsSync(`${cwd}/.claude/settings.json`) && readFileSync(`${cwd}/.claude/settings.json`, "utf8").includes("walkie-cli");
|
|
291
|
+
for (const n of liveSessionNotes(running, { claude: claudeInstalled, cursorRule: wrote.some((w) => w.includes(".cursor")), agentsMd: wrote.some((w) => w.endsWith("AGENTS.md")) }))
|
|
292
|
+
out(`- ${n}`);
|
|
293
|
+
return 0;
|
|
294
|
+
}
|
|
295
|
+
if (cmd === "channel") {
|
|
296
|
+
await runChannel({ ...cfg, name: values.name, ack: !values["no-ack"] });
|
|
297
|
+
return 0;
|
|
298
|
+
}
|
|
299
|
+
if (cmd === "report") {
|
|
300
|
+
const message = positionals.slice(1).join(" ").trim();
|
|
301
|
+
if (!message) {
|
|
302
|
+
err('report needs a message: walkie report "what happened" --file shot.png');
|
|
303
|
+
return 1;
|
|
304
|
+
}
|
|
305
|
+
const kind = values.kind;
|
|
306
|
+
if (kind && !["evidence", "question", "status"].includes(kind)) {
|
|
307
|
+
err("--kind must be evidence, question or status");
|
|
308
|
+
return 1;
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
const r = await sendReport({ ...cfg, message, kind, files: values.file ?? [], postId: values.post, sessionId: values.session });
|
|
312
|
+
out(`sent report ${r.id}${r.attachments.length ? ` with ${r.attachments.length} file(s)` : ""}`);
|
|
313
|
+
return 0;
|
|
314
|
+
}
|
|
315
|
+
catch (e) {
|
|
316
|
+
err(e instanceof Error ? e.message : String(e));
|
|
317
|
+
return 1;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const stdin = cmd === "claude" || cmd === "cursor" ? await readStdinJson() : {};
|
|
321
|
+
const sessionId = stdin.session_id ?? stdin.conversation_id ?? process.env.WALKIE_SESSION_ID;
|
|
322
|
+
const eventName = stdin.hook_event_name ?? (cmd === "cursor" ? "beforeSubmitPrompt" : cmd === "claude" ? "SessionStart" : cmd);
|
|
323
|
+
const harness = cmd === "claude" ? "claude-code" : cmd === "cursor" ? "cursor" : cmd === "agents-md" ? "other" : undefined;
|
|
324
|
+
let since;
|
|
325
|
+
if (values.delta && sessionId)
|
|
326
|
+
since = readSessionState(sessionId)?.lastPulledAt;
|
|
327
|
+
let feed;
|
|
328
|
+
try {
|
|
329
|
+
feed = await fetchFeed(cfg, {
|
|
330
|
+
sessionId,
|
|
331
|
+
harness,
|
|
332
|
+
cwd: stdin.cwd ?? cwd,
|
|
333
|
+
event: eventName,
|
|
334
|
+
since,
|
|
335
|
+
pinned: values.delta ? "changed" : "always",
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
catch (e) {
|
|
339
|
+
err(e instanceof Error ? e.message : String(e));
|
|
340
|
+
return cmd === "status" || cmd === "print" ? 1 : 0; // hooks fail open
|
|
341
|
+
}
|
|
342
|
+
if (sessionId)
|
|
343
|
+
writeSessionState(sessionId, { lastPulledAt: feed.generatedAt });
|
|
344
|
+
switch (cmd) {
|
|
345
|
+
case "claude": {
|
|
346
|
+
const output = claudeHookOutput(feed, eventName);
|
|
347
|
+
if (output) {
|
|
348
|
+
out(output);
|
|
349
|
+
// The posts are now in the session's context: acknowledge them so the
|
|
350
|
+
// app can show "read by". Best effort, never blocks the hook.
|
|
351
|
+
await ackPosts({ ...cfg, fetchImpl: undefined }, feed.posts.map((p) => p.id), sessionId);
|
|
352
|
+
}
|
|
353
|
+
return 0;
|
|
354
|
+
}
|
|
355
|
+
case "cursor": {
|
|
356
|
+
const projectRoot = stdin.workspace_roots?.[0] ?? stdin.cwd ?? cwd;
|
|
357
|
+
writeCursorRule(projectRoot, feed);
|
|
358
|
+
out(JSON.stringify({ continue: true }));
|
|
359
|
+
return 0;
|
|
360
|
+
}
|
|
361
|
+
case "agents-md": {
|
|
362
|
+
const file = values.file?.[0] ?? `${cwd}/AGENTS.md`;
|
|
363
|
+
const r = writeAgentsMd(file, feed);
|
|
364
|
+
out(`${r.changed ? "updated" : "unchanged"} ${r.path}`);
|
|
365
|
+
return 0;
|
|
366
|
+
}
|
|
367
|
+
case "print": {
|
|
368
|
+
out(values.json ? JSON.stringify(feed, null, 2) : feed.markdown || `(suppressed: ${feed.suppressedReason})`);
|
|
369
|
+
return 0;
|
|
370
|
+
}
|
|
371
|
+
case "status": {
|
|
372
|
+
out(`server: ${cfg.url}`);
|
|
373
|
+
out(`config: ${cfg.source}`);
|
|
374
|
+
out(`channel: ${feed.bulletin.name} (${feed.bulletin.slug})`);
|
|
375
|
+
out(`subscriber: ${feed.subscriber.name}${feed.subscriber.muted ? " (muted)" : ""}`);
|
|
376
|
+
out(`posts: ${feed.posts.length} served, ${feed.truncated} omitted by budget${feed.suppressed ? `, suppressed (${feed.suppressedReason})` : ""}`);
|
|
377
|
+
return 0;
|
|
378
|
+
}
|
|
379
|
+
default:
|
|
380
|
+
err(`unknown command "${cmd}"`);
|
|
381
|
+
out(HELP);
|
|
382
|
+
return 1;
|
|
383
|
+
}
|
|
384
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
export const PROJECT_FILE = ".walkie.json";
|
|
5
|
+
/** Pre-rename project file, still honoured. */
|
|
6
|
+
export const LEGACY_PROJECT_FILE = ".bulletin.json";
|
|
7
|
+
export function userConfigPath(env = process.env) {
|
|
8
|
+
const base = env.XDG_CONFIG_HOME || join(env.HOME || homedir(), ".config");
|
|
9
|
+
const current = join(base, "walkie", "config.json");
|
|
10
|
+
const legacy = join(base, "bulletin", "config.json");
|
|
11
|
+
return !existsSync(current) && existsSync(legacy) ? legacy : current;
|
|
12
|
+
}
|
|
13
|
+
/** BULLETIN_* variables from before the rename still work; WALKIE_* wins when both are set. */
|
|
14
|
+
export function withLegacyEnv(env) {
|
|
15
|
+
const out = { ...env };
|
|
16
|
+
for (const [k, v] of Object.entries(env)) {
|
|
17
|
+
if (k.startsWith("BULLETIN_") && v !== undefined) {
|
|
18
|
+
const nk = "WALKIE_" + k.slice("BULLETIN_".length);
|
|
19
|
+
if (out[nk] === undefined)
|
|
20
|
+
out[nk] = v;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
export function stateDir(env = process.env) {
|
|
26
|
+
const base = env.XDG_CACHE_HOME || join(env.HOME || homedir(), ".cache");
|
|
27
|
+
return join(base, "walkie");
|
|
28
|
+
}
|
|
29
|
+
function readJson(path) {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/** Walk up from `cwd` looking for a project config file. */
|
|
38
|
+
export function findProjectConfig(cwd) {
|
|
39
|
+
let dir = resolve(cwd);
|
|
40
|
+
for (let i = 0; i < 40; i++) {
|
|
41
|
+
for (const candidate of [join(dir, PROJECT_FILE), join(dir, LEGACY_PROJECT_FILE)]) {
|
|
42
|
+
if (existsSync(candidate)) {
|
|
43
|
+
const data = readJson(candidate);
|
|
44
|
+
if (data)
|
|
45
|
+
return { path: candidate, data };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const parent = dirname(dir);
|
|
49
|
+
if (parent === dir)
|
|
50
|
+
break;
|
|
51
|
+
dir = parent;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Resolution order (first complete wins):
|
|
57
|
+
* 1. CLI flags (--url/--token)
|
|
58
|
+
* 2. env WALKIE_URL / WALKIE_TOKEN
|
|
59
|
+
* 3. <project>/.walkie.json (url + tokenEnv|token), searched upwards from cwd
|
|
60
|
+
* 4. ~/.config/walkie/config.json
|
|
61
|
+
*/
|
|
62
|
+
export function resolveConfig(opts) {
|
|
63
|
+
const env = withLegacyEnv(opts.env ?? process.env);
|
|
64
|
+
let url = opts.url ?? env.WALKIE_URL ?? "";
|
|
65
|
+
let token = opts.token ?? env.WALKIE_TOKEN ?? "";
|
|
66
|
+
const sources = [];
|
|
67
|
+
if (opts.url || opts.token)
|
|
68
|
+
sources.push("flags");
|
|
69
|
+
if (env.WALKIE_URL || env.WALKIE_TOKEN)
|
|
70
|
+
sources.push("env");
|
|
71
|
+
if (!url || !token) {
|
|
72
|
+
const project = findProjectConfig(opts.cwd);
|
|
73
|
+
if (project) {
|
|
74
|
+
url ||= project.data.url ?? "";
|
|
75
|
+
token ||= (project.data.tokenEnv ? env[project.data.tokenEnv] : project.data.token) ?? "";
|
|
76
|
+
sources.push(project.path);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!url || !token) {
|
|
80
|
+
const user = readJson(userConfigPath(env));
|
|
81
|
+
if (user) {
|
|
82
|
+
url ||= user.url ?? "";
|
|
83
|
+
token ||= (user.tokenEnv ? env[user.tokenEnv] : user.token) ?? "";
|
|
84
|
+
sources.push(userConfigPath(env));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (!url || !token)
|
|
88
|
+
return null;
|
|
89
|
+
return { url: url.replace(/\/+$/, ""), token, source: sources.join(" → ") };
|
|
90
|
+
}
|
|
91
|
+
export function writeUserConfig(data, env = process.env) {
|
|
92
|
+
const path = userConfigPath(env);
|
|
93
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
94
|
+
writeFileSync(path, JSON.stringify(data, null, 2) + "\n", { mode: 0o600 });
|
|
95
|
+
return path;
|
|
96
|
+
}
|
|
97
|
+
function sessionStatePath(sessionId, env) {
|
|
98
|
+
const safe = sessionId.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 120);
|
|
99
|
+
return join(stateDir(env), "sessions", `${safe}.json`);
|
|
100
|
+
}
|
|
101
|
+
export function readSessionState(sessionId, env) {
|
|
102
|
+
return readJson(sessionStatePath(sessionId, env));
|
|
103
|
+
}
|
|
104
|
+
export function writeSessionState(sessionId, state, env) {
|
|
105
|
+
const path = sessionStatePath(sessionId, env);
|
|
106
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
107
|
+
writeFileSync(path, JSON.stringify(state));
|
|
108
|
+
}
|
package/dist/feed.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export async function fetchFeed(cfg, params, opts = {}) {
|
|
2
|
+
const u = new URL("/v1/feed", cfg.url + "/");
|
|
3
|
+
for (const [k, v] of Object.entries(params))
|
|
4
|
+
if (v)
|
|
5
|
+
u.searchParams.set(k, String(v));
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
const t = setTimeout(() => controller.abort(), opts.timeoutMs ?? 5000);
|
|
8
|
+
try {
|
|
9
|
+
const res = await (opts.fetchImpl ?? fetch)(u, {
|
|
10
|
+
headers: { authorization: `Bearer ${cfg.token}`, accept: "application/json", "user-agent": "walkie-cli/0.1" },
|
|
11
|
+
signal: controller.signal,
|
|
12
|
+
});
|
|
13
|
+
if (!res.ok)
|
|
14
|
+
throw new Error(`feed request failed: HTTP ${res.status}`);
|
|
15
|
+
return (await res.json());
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
clearTimeout(t);
|
|
19
|
+
}
|
|
20
|
+
}
|
package/dist/install.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `walkie install <harness>`: wire the hook into a project (or user)
|
|
3
|
+
* configuration. Idempotent: re-running updates the managed entries only.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { END_MARK, START_MARK } from "./adapters.js";
|
|
9
|
+
const COMMAND = "npx -y walkie-cli";
|
|
10
|
+
function readJsonFile(path) {
|
|
11
|
+
if (!existsSync(path))
|
|
12
|
+
return {};
|
|
13
|
+
const raw = readFileSync(path, "utf8").trim();
|
|
14
|
+
return raw ? JSON.parse(raw) : {};
|
|
15
|
+
}
|
|
16
|
+
function writeJsonFile(path, data) {
|
|
17
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
18
|
+
writeFileSync(path, JSON.stringify(data, null, 2) + "\n");
|
|
19
|
+
}
|
|
20
|
+
const isOurs = (h) => typeof h?.command === "string" && h.command.includes("walkie-cli");
|
|
21
|
+
/**
|
|
22
|
+
* Claude Code: `.claude/settings.json` (project) or `~/.claude/settings.json`.
|
|
23
|
+
* Adds a SessionStart hook (full feed) and a UserPromptSubmit hook (delta).
|
|
24
|
+
*/
|
|
25
|
+
export function installClaude(opts) {
|
|
26
|
+
const path = opts.global
|
|
27
|
+
? join(opts.home ?? homedir(), ".claude", "settings.json")
|
|
28
|
+
: join(opts.projectRoot, ".claude", "settings.json");
|
|
29
|
+
const settings = readJsonFile(path);
|
|
30
|
+
settings.hooks ??= {};
|
|
31
|
+
const upsert = (event, matcher, command, timeout) => {
|
|
32
|
+
const groups = Array.isArray(settings.hooks[event]) ? settings.hooks[event] : [];
|
|
33
|
+
// Strip previously-managed entries.
|
|
34
|
+
for (const g of groups)
|
|
35
|
+
if (Array.isArray(g.hooks))
|
|
36
|
+
g.hooks = g.hooks.filter((h) => !isOurs(h));
|
|
37
|
+
const cleaned = groups.filter((g) => Array.isArray(g.hooks) && g.hooks.length > 0);
|
|
38
|
+
const entry = { hooks: [{ type: "command", command, timeout }] };
|
|
39
|
+
if (matcher)
|
|
40
|
+
entry.matcher = matcher;
|
|
41
|
+
cleaned.push(entry);
|
|
42
|
+
settings.hooks[event] = cleaned;
|
|
43
|
+
};
|
|
44
|
+
upsert("SessionStart", "startup|resume|clear|compact", `${COMMAND} claude`, 15);
|
|
45
|
+
upsert("UserPromptSubmit", undefined, `${COMMAND} claude --delta`, 10);
|
|
46
|
+
writeJsonFile(path, settings);
|
|
47
|
+
return path;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Cursor: `.cursor/hooks.json` with a beforeSubmitPrompt hook that refreshes
|
|
51
|
+
* `.cursor/rules/walkie.mdc`. Also seeds the rule file so the first prompt
|
|
52
|
+
* already has context.
|
|
53
|
+
*/
|
|
54
|
+
export function installCursor(opts) {
|
|
55
|
+
const path = join(opts.projectRoot, ".cursor", "hooks.json");
|
|
56
|
+
const cfg = readJsonFile(path);
|
|
57
|
+
cfg.version ??= 1;
|
|
58
|
+
cfg.hooks ??= {};
|
|
59
|
+
const list = Array.isArray(cfg.hooks.beforeSubmitPrompt) ? cfg.hooks.beforeSubmitPrompt : [];
|
|
60
|
+
cfg.hooks.beforeSubmitPrompt = [...list.filter((h) => !isOurs(h)), { command: `${COMMAND} cursor` }];
|
|
61
|
+
writeJsonFile(path, cfg);
|
|
62
|
+
return path;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Claude Code channel: register the stdio MCP server in `.mcp.json`. The user
|
|
66
|
+
* then launches `claude --dangerously-load-development-channels server:walkie`
|
|
67
|
+
* (channels are a research preview; custom servers need that flag).
|
|
68
|
+
*/
|
|
69
|
+
export function installChannel(opts) {
|
|
70
|
+
const path = join(opts.projectRoot, ".mcp.json");
|
|
71
|
+
const cfg = readJsonFile(path);
|
|
72
|
+
cfg.mcpServers ??= {};
|
|
73
|
+
cfg.mcpServers.walkie = { command: "npx", args: ["-y", "walkie-cli", "channel"] };
|
|
74
|
+
writeJsonFile(path, cfg);
|
|
75
|
+
return { path, launch: "claude --dangerously-load-development-channels server:walkie" };
|
|
76
|
+
}
|
|
77
|
+
/** AGENTS.md (Codex, Copilot, Gemini CLI, ...): add the managed block markers. */
|
|
78
|
+
export function installAgentsMd(opts) {
|
|
79
|
+
const path = join(opts.projectRoot, opts.file ?? "AGENTS.md");
|
|
80
|
+
const prev = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
81
|
+
if (!prev.includes(START_MARK)) {
|
|
82
|
+
const sep = prev.length === 0 ? "" : prev.endsWith("\n") ? "\n" : "\n\n";
|
|
83
|
+
writeFileSync(path, `${prev}${sep}${START_MARK}\n_Run \`${COMMAND} agents-md\` to populate._\n${END_MARK}\n`);
|
|
84
|
+
}
|
|
85
|
+
return path;
|
|
86
|
+
}
|