instantping 0.1.0 → 0.1.1
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/README.md +7 -1
- package/ccn.mjs +157 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,10 +43,16 @@ A popup process left running in the background is killed when the hook process e
|
|
|
43
43
|
## One-command install
|
|
44
44
|
The guide's single command installs Node.js if missing (winget on Windows, Homebrew on Mac), saves `ccn.mjs`, runs `setup`, and in a real terminal waits for you to subscribe your phone before sending a test (`setup` skips the wait when there is no terminal).
|
|
45
45
|
|
|
46
|
+
## Phone settings (InstantPing app)
|
|
47
|
+
With the phone app the user chooses, in the app, and the relay follows it: minimum task time ("Quiet for short tasks"), pause, quiet hours (own time zone, "waiting" may still pass), which pings (done / waiting), language, details (project + closing sentence; off by default), and the sound per ping type (Android channels `done` and `waiting`). Two of them the computer must follow itself, so the relay returns them with every event and the hook caches them in `relayPrefs` in `~/.ccn.json`: `delay` (wait N seconds first; the ping is dropped if the user sent a new prompt or Claude finished meanwhile, done by a detached `ccn delayed` process) and `detail`/`lang`. A setting made in the app wins over the same one in `~/.ccn.json`. Ceiling: clicking "Allow" on a permission prompt at the computer does not cancel a delayed "waiting" ping, because no hook fires for it.
|
|
48
|
+
|
|
46
49
|
## Settings (~/.ccn.json)
|
|
50
|
+
Change them with `node ccn.mjs config <key> <value>` (for example `config minSeconds 30`), or with `npx instantping config ...` from the npm package. `config` alone shows the current values.
|
|
47
51
|
- `minSeconds` (default 15): "klaar" only for tasks longer than this. A `UserPromptSubmit` hook records when a task starts. `0` = every task.
|
|
48
52
|
- `phoneDetail` (default false): popup shows project + Claude's closing sentence; the phone push stays generic unless this is true.
|
|
49
|
-
- `desktop` (default true), `ignore` (default `[".claude-mem"]`).
|
|
53
|
+
- `desktop` (default true), `sound` (popup sound, default true), `delay` (seconds, default 0), `lang` (`en` default, `nl`, `es`, `fr`, `de`, `pt`, `ko`, `ja`), `name` (shown in phone pings; for several computers; `setup` asks for it, and a name set in the app wins), `ignore` (default `[".claude-mem"]`).
|
|
54
|
+
- Mute one project: `ccn mute <folder name>` (`mute .` = this folder, `unmute <name>`, `mute` lists). A muted name matches a whole folder name, not part of one.
|
|
55
|
+
- `ccn config` shows everything, including what the phone has set.
|
|
50
56
|
- Skipped automatically: subagent notifications (`agent_id`), `stop_hook_active` loops, the "waiting for your input" idle reminder.
|
|
51
57
|
- Mute: empty file `~/.ccn-muted`, or `CCN_DISABLE=1` for one shell.
|
|
52
58
|
|
package/ccn.mjs
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
// node ccn.mjs install add the hooks to ~/.claude/settings.json (backup made)
|
|
9
9
|
// node ccn.mjs uninstall remove them again
|
|
10
10
|
// node ccn.mjs pair link this computer to the phone app (Pro relay): shows a code, type it in the app
|
|
11
|
+
// node ccn.mjs config show or change settings, e.g. config minSeconds 30 (also: delay, lang, name, sound, desktop, phoneDetail)
|
|
12
|
+
// node ccn.mjs mute mute a project by folder name (mute <name>, mute . for this folder, unmute <name>)
|
|
11
13
|
// node ccn.mjs hook what the hooks run (reads Claude's JSON on stdin)
|
|
12
14
|
import fs from "node:fs";
|
|
13
15
|
import os from "node:os";
|
|
@@ -38,15 +40,26 @@ export function closing(text = "") {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
// Pure: hook payload -> message. rich = project name + Claude's closing sentence, for the popup on this computer.
|
|
41
|
-
// The phone push stays generic unless
|
|
42
|
-
|
|
43
|
+
// The phone push stays generic unless details are on (set in the app, or "phoneDetail": true here), because its text travels through our relay.
|
|
44
|
+
const TEXT = {
|
|
45
|
+
en: { done: ["Claude is done", "Waiting for your next instruction."], waiting: ["Claude is waiting", "Claude needs you."] },
|
|
46
|
+
nl: { done: ["Claude is klaar", "Wacht op je volgende instructie."], waiting: ["Claude wacht op jou", "Claude heeft je nodig."] },
|
|
47
|
+
es: { done: ["Claude ha terminado", "Esperando tu siguiente instrucción."], waiting: ["Claude está esperando", "Claude te necesita."] },
|
|
48
|
+
fr: { done: ["Claude a terminé", "En attente de votre prochaine instruction."], waiting: ["Claude attend", "Claude a besoin de vous."] },
|
|
49
|
+
de: { done: ["Claude ist fertig", "Wartet auf deine nächste Anweisung."], waiting: ["Claude wartet", "Claude braucht dich."] },
|
|
50
|
+
pt: { done: ["Claude terminou", "Aguardando sua próxima instrução."], waiting: ["Claude está esperando", "Claude precisa de você."] },
|
|
51
|
+
ko: { done: ["Claude가 작업을 마쳤어요", "다음 지시를 기다리고 있어요."], waiting: ["Claude가 기다리고 있어요", "Claude에게 당신이 필요해요."] },
|
|
52
|
+
ja: { done: ["Claudeが完了しました", "次の指示をお待ちしています。"], waiting: ["Claudeが待っています", "Claudeはあなたを必要としています。"] },
|
|
53
|
+
};
|
|
54
|
+
export function format(p, rich = false, lang = "en", name = "") {
|
|
43
55
|
const project = p.cwd ? path.basename(p.cwd) : "";
|
|
44
|
-
const where = rich
|
|
56
|
+
const where = (rich ? [name, project] : []).filter(Boolean).map((x) => x + " · ").join("");
|
|
57
|
+
const T = Object.hasOwn(TEXT, lang) ? TEXT[lang] : TEXT.en;
|
|
45
58
|
if (p.hook_event_name === "Stop") {
|
|
46
59
|
const sentence = rich ? closing(p.last_assistant_message) : "";
|
|
47
|
-
return { title: `${where}
|
|
60
|
+
return { title: `${where}${T.done[0]}`, body: sentence || T.done[1], priority: 3, tags: "white_check_mark" };
|
|
48
61
|
}
|
|
49
|
-
return { title: `${where}
|
|
62
|
+
return { title: `${where}${T.waiting[0]}`, body: p.message || T.waiting[1], priority: 4, tags: "bell" };
|
|
50
63
|
}
|
|
51
64
|
|
|
52
65
|
// Muted on purpose: the file ~/.ccn-muted exists, or CCN_DISABLE is set (to anything but empty, 0 or false) in this shell.
|
|
@@ -75,10 +88,34 @@ const marker = (id) => path.join(TASKS, String(id || "anon").replace(/[^A-Za-z0-
|
|
|
75
88
|
function recordStart(id) { try { fs.mkdirSync(TASKS, { recursive: true }); fs.writeFileSync(marker(id), String(Date.now())); } catch { /* best effort */ } }
|
|
76
89
|
function startedAt(id) { try { return Number(fs.readFileSync(marker(id), "utf8")) || null; } catch { return null; } }
|
|
77
90
|
|
|
91
|
+
// Settings a user may change with `ccn config <key> <value>`. Everything else in ~/.ccn.json is internal.
|
|
92
|
+
// A setting chosen in the phone app wins over the same one here (the computer caches it in relayPrefs).
|
|
93
|
+
const SETTING_TYPES = { minSeconds: "number", delay: "number", phoneDetail: "boolean", desktop: "boolean", sound: "boolean", lang: ["en", "nl", "es", "fr", "de", "pt", "ko", "ja"], name: "string" };
|
|
94
|
+
const MAX = { minSeconds: 3600, delay: 600 };
|
|
95
|
+
export function parseSetting(key, raw) {
|
|
96
|
+
const type = SETTING_TYPES[key];
|
|
97
|
+
if (!type) throw new Error(`unknown setting "${key}". Use: ${Object.keys(SETTING_TYPES).join(", ")}`);
|
|
98
|
+
const s = String(raw ?? "").trim();
|
|
99
|
+
if (type === "number") {
|
|
100
|
+
const n = Number(s);
|
|
101
|
+
if (s === "" || !Number.isFinite(n) || n < 0 || n > MAX[key]) throw new Error(`${key} needs a number of seconds from 0 to ${MAX[key]}`);
|
|
102
|
+
return n;
|
|
103
|
+
}
|
|
104
|
+
if (type === "string") { if (s.length > 40) throw new Error(`${key} is at most 40 characters`); return s; } // empty = clear
|
|
105
|
+
if (Array.isArray(type)) { if (!type.includes(s)) throw new Error(`${key} must be one of: ${type.join(", ")}`); return s; }
|
|
106
|
+
if (/^(true|on|yes)$/i.test(s)) return true;
|
|
107
|
+
if (/^(false|off|no)$/i.test(s)) return false;
|
|
108
|
+
throw new Error(`${key} needs on or off`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const act = (id) => path.join(TASKS, "act-" + String(id || "anon").replace(/[^A-Za-z0-9._-]/g, "") + ".txt");
|
|
112
|
+
function touch(id) { const t = Date.now(); try { fs.mkdirSync(TASKS, { recursive: true }); fs.writeFileSync(act(id), String(t)); } catch { /* best effort */ } return t; }
|
|
113
|
+
const lastActivity = (id) => { try { return Number(fs.readFileSync(act(id), "utf8")) || 0; } catch { return 0; } };
|
|
114
|
+
|
|
78
115
|
// Background sessions are not you waiting. claude-mem runs a hidden Claude session that ends a "turn" every few
|
|
79
116
|
// seconds; its Stop hook would notify you all day. Skip any session whose folder contains one of these fragments.
|
|
80
117
|
export function ignored(p, patterns = [".claude-mem"]) {
|
|
81
|
-
const cwd = (p.cwd || "").split("\\").join("/");
|
|
118
|
+
const cwd = (p.cwd || "").split("\\").join("/") + "/"; // trailing slash: a muted "/name/" also matches a cwd that ends in name
|
|
82
119
|
return patterns.some((x) => cwd.includes(x.split("\\").join("/")));
|
|
83
120
|
}
|
|
84
121
|
|
|
@@ -105,7 +142,7 @@ async function push(conf, m) {
|
|
|
105
142
|
// Desktop popup on this computer. No dependencies: PowerShell toast (Windows), osascript (macOS), notify-send (Linux).
|
|
106
143
|
// Text goes through env vars, never into the command line, so quotes in Claude's message cannot break it.
|
|
107
144
|
function desktop(m) {
|
|
108
|
-
const env = { ...process.env, CCN_T: m.title, CCN_B: m.body };
|
|
145
|
+
const env = { ...process.env, CCN_T: m.title, CCN_B: m.body, CCN_S: m.silent ? "1" : "" };
|
|
109
146
|
let cmd, args;
|
|
110
147
|
if (process.platform === "win32") {
|
|
111
148
|
// Own sender name "Claude Notifier", registered per user (HKCU, no admin). Toasts sent as "Windows PowerShell"
|
|
@@ -122,13 +159,14 @@ function desktop(m) {
|
|
|
122
159
|
"$t = $x.GetElementsByTagName('text')",
|
|
123
160
|
"[void]$t.Item(0).AppendChild($x.CreateTextNode($env:CCN_T))",
|
|
124
161
|
"[void]$t.Item(1).AppendChild($x.CreateTextNode($env:CCN_B))",
|
|
162
|
+
"if ($env:CCN_S -eq '1') { $a = $x.CreateElement('audio'); $a.SetAttribute('silent','true'); [void]$x.DocumentElement.AppendChild($a) }",
|
|
125
163
|
"[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($id).Show([Windows.UI.Notifications.ToastNotification]::new($x))",
|
|
126
164
|
// Show() hands the toast to Windows asynchronously; leaving at once can drop it, so linger briefly.
|
|
127
165
|
"Start-Sleep -Seconds 3",
|
|
128
166
|
].join("; ")];
|
|
129
167
|
} else if (process.platform === "darwin") {
|
|
130
168
|
cmd = "osascript";
|
|
131
|
-
args = ["-e", 'display notification (system attribute "CCN_B") with title (system attribute "CCN_T")'];
|
|
169
|
+
args = ["-e", 'display notification (system attribute "CCN_B") with title (system attribute "CCN_T")' + (m.silent ? "" : ' sound name "Glass"')];
|
|
132
170
|
} else {
|
|
133
171
|
cmd = "notify-send";
|
|
134
172
|
args = [m.title, m.body];
|
|
@@ -145,14 +183,44 @@ function desktop(m) {
|
|
|
145
183
|
}
|
|
146
184
|
|
|
147
185
|
// Pro relay: push through our own relay to the phone app (conf.relay = base URL, conf.relayKey = this computer's key).
|
|
148
|
-
|
|
186
|
+
// The relay applies the phone's own settings (pause, quiet hours, minimum task time...) and answers with the ones this computer must follow itself.
|
|
187
|
+
async function pushRelay(conf, kind, m, seconds, rich) {
|
|
149
188
|
const r = await fetch(`${conf.relay}/v1/events`, {
|
|
150
189
|
method: "POST",
|
|
151
190
|
headers: { authorization: "Bearer " + conf.relayKey, "content-type": "application/json" },
|
|
152
|
-
body: JSON.stringify({ kind, title: m.title, body: m.body }),
|
|
191
|
+
body: JSON.stringify({ kind, title: m.title, body: m.body, seconds, minSeconds: conf.minSeconds ?? 15, rich, computer: conf.name || undefined }),
|
|
153
192
|
signal: AbortSignal.timeout(8000),
|
|
154
193
|
});
|
|
155
194
|
if (!r.ok) throw new Error(`relay ${r.status}`);
|
|
195
|
+
const { prefs } = await r.json().catch(() => ({}));
|
|
196
|
+
if (prefs && JSON.stringify(prefs) !== JSON.stringify(conf.relayPrefs ?? {})) cachePrefs(prefs);
|
|
197
|
+
}
|
|
198
|
+
function cachePrefs(prefs) {
|
|
199
|
+
try { const c = load() ?? {}; c.relayPrefs = prefs; fs.writeFileSync(CONF, JSON.stringify(c, null, 2), { mode: 0o600 }); } catch { /* best effort */ }
|
|
200
|
+
}
|
|
201
|
+
async function phoneSettings(conf) {
|
|
202
|
+
try {
|
|
203
|
+
const r = await fetch(`${conf.relay}/v1/prefs`, { method: "POST", headers: { authorization: "Bearer " + conf.relayKey, "content-type": "application/json" }, body: "{}", signal: AbortSignal.timeout(5000) });
|
|
204
|
+
return r.ok ? await r.json() : null;
|
|
205
|
+
} catch { return null; }
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Popup + phone for one event. short = shorter than our minSeconds: then only the relay hears about it, because the phone may want it.
|
|
209
|
+
async function route(conf, p, secs, short) {
|
|
210
|
+
const prefs = conf.relayPrefs ?? {};
|
|
211
|
+
const lang = prefs.lang ?? conf.lang ?? "en";
|
|
212
|
+
const detail = prefs.detail ?? conf.phoneDetail === true; // phone setting wins; details are opt-in
|
|
213
|
+
const local = { ...format(p, true, lang), silent: conf.sound === false };
|
|
214
|
+
const phone = detail ? format(p, true, lang, conf.name) : format(p, false, lang);
|
|
215
|
+
await Promise.allSettled([
|
|
216
|
+
!short && conf.desktop !== false && (conf.detach === false ? desktop(local) : detach(local)),
|
|
217
|
+
!short && conf.topic && push(conf, phone),
|
|
218
|
+
conf.relayKey && pushRelay(conf, p.hook_event_name === "Stop" ? "done" : "waiting", phone, secs, detail),
|
|
219
|
+
]);
|
|
220
|
+
}
|
|
221
|
+
// Same, but after N seconds, and only if you did not act in the meantime (new prompt, or Claude finished). Runs in its own process.
|
|
222
|
+
function later(j) {
|
|
223
|
+
try { spawn(process.execPath, [SELF, "delayed"], { env: { ...process.env, CCN_DELAYED: JSON.stringify(j) }, detached: true, stdio: "ignore", windowsHide: true }).unref(); } catch { /* best effort */ }
|
|
156
224
|
}
|
|
157
225
|
|
|
158
226
|
// Pairing: ask the relay for a code, show it, wait until the phone app has claimed it, store the key.
|
|
@@ -193,6 +261,13 @@ function showTopic(conf) {
|
|
|
193
261
|
console.log(`\n${bar}\n YOUR TOPIC. Type it in the ntfy app EXACTLY like this:\n\n ${conf.topic}\n\n This is NOT a name you choose. This computer was given this exact\n name, and your phone must use the same one, letter for letter.\n${copied ? " It is already copied. On this computer you can paste it with Ctrl+V.\n" : ""}${bar}\n`);
|
|
194
262
|
}
|
|
195
263
|
|
|
264
|
+
// Ask one line in a real terminal; empty answer = def. No terminal: def is not used, nothing is asked.
|
|
265
|
+
function askLine(msg) {
|
|
266
|
+
if (!process.stdin.isTTY) return Promise.resolve(null);
|
|
267
|
+
process.stdout.write(msg);
|
|
268
|
+
return new Promise((r) => process.stdin.once("data", (d) => { process.stdin.pause(); r(String(d).trim()); }));
|
|
269
|
+
}
|
|
270
|
+
|
|
196
271
|
// Wait for Enter in a real terminal; do nothing when there is none (scripts, tests, hooks).
|
|
197
272
|
function pause(msg) {
|
|
198
273
|
if (!process.stdin.isTTY) return Promise.resolve();
|
|
@@ -206,6 +281,13 @@ if (isMain) {
|
|
|
206
281
|
if (cmd === "setup" && PKG) {
|
|
207
282
|
// Customer flow (npx instantping setup): hooks + pairing with the phone app. No ntfy.
|
|
208
283
|
const r = spawnSync(process.execPath, [SELF, "install"], { stdio: "inherit" }); if (r.status) process.exit(r.status);
|
|
284
|
+
// A name tells your computers apart in the app and in the pings. Only sent if you accept or type one.
|
|
285
|
+
const conf0 = load() ?? {};
|
|
286
|
+
if (conf0.name === undefined) {
|
|
287
|
+
const host = os.hostname();
|
|
288
|
+
const a = await askLine(`\nName this computer, so you can tell your pings apart (Enter = "${host}", - = no name): `);
|
|
289
|
+
if (a !== null && a !== "-") fs.writeFileSync(CONF, JSON.stringify({ ...conf0, name: (a || host).slice(0, 40) }, null, 2), { mode: 0o600 });
|
|
290
|
+
}
|
|
209
291
|
console.log("\nOpen the InstantPing app on your phone; it asks for the code below.");
|
|
210
292
|
await pair(load()?.relay || DEFAULT_RELAY);
|
|
211
293
|
console.log("All set. Close Claude Code and open it again, so it loads the new hooks.");
|
|
@@ -225,7 +307,7 @@ if (isMain) {
|
|
|
225
307
|
if (conf?.topic) showTopic(conf); else console.log("No topic yet. Run: node ccn.mjs init");
|
|
226
308
|
} else if (cmd === "test") {
|
|
227
309
|
const conf = load() ?? {};
|
|
228
|
-
const m = { title: "
|
|
310
|
+
const m = { title: "InstantPing works", body: "Test notification.", priority: 3, tags: "tada" };
|
|
229
311
|
const [, phone] = await Promise.allSettled([conf.desktop !== false && desktop(m), conf.topic && push(conf, m)]);
|
|
230
312
|
if (phone.status === "rejected") { console.error("Phone push failed: " + phone.reason.message + " (check your internet connection)"); process.exit(1); }
|
|
231
313
|
console.log(conf.topic ? "Sent: popup on this computer + push to your phone." : "Popup sent. No phone topic yet: run init to add phone push.");
|
|
@@ -248,6 +330,56 @@ if (isMain) {
|
|
|
248
330
|
} else if (cmd === "pair") {
|
|
249
331
|
const relay = process.argv[3] || load()?.relay || DEFAULT_RELAY;
|
|
250
332
|
await pair(relay.replace(/\/$/, ""));
|
|
333
|
+
} else if (cmd === "config") {
|
|
334
|
+
// node ccn.mjs config show settings
|
|
335
|
+
// node ccn.mjs config minSeconds 30 only announce tasks longer than 30 s (0 = every task)
|
|
336
|
+
const [key, value] = process.argv.slice(3);
|
|
337
|
+
let conf = load() ?? {};
|
|
338
|
+
if (key) {
|
|
339
|
+
try { const v = parseSetting(key, value); if (v === "") delete conf[key]; else conf[key] = v; } catch (e) { console.error(e.message); process.exit(1); }
|
|
340
|
+
fs.writeFileSync(CONF, JSON.stringify(conf, null, 2));
|
|
341
|
+
}
|
|
342
|
+
const on = (v, d = true) => ((v ?? d) ? "on" : "off");
|
|
343
|
+
console.log(`This computer (${CONF}):
|
|
344
|
+
minSeconds ${conf.minSeconds ?? 15}${conf.minSeconds === undefined ? " (default)" : ""} only tasks longer than this get a "done" ping; 0 = every task
|
|
345
|
+
delay ${conf.delay ?? 0} wait this many seconds first; no ping if you act in the meantime
|
|
346
|
+
lang ${conf.lang ?? "en"} en, nl, es, fr, de, pt, ko or ja
|
|
347
|
+
name ${conf.name || "(none)"} shown in phone pings, for people with several computers
|
|
348
|
+
desktop ${on(conf.desktop)} popup on this computer
|
|
349
|
+
sound ${on(conf.sound)} popup sound
|
|
350
|
+
phoneDetail ${on(conf.phoneDetail, false)} project name and Claude's last sentence on the phone
|
|
351
|
+
muted ${(conf.ignore ?? [".claude-mem"]).join(", ") || "(none)"} change with: mute <folder name>`);
|
|
352
|
+
if (conf.relayKey) {
|
|
353
|
+
const ph = await phoneSettings(conf);
|
|
354
|
+
if (ph) {
|
|
355
|
+
cachePrefs(ph.prefs);
|
|
356
|
+
const s = ph.settings, q = s.quiet;
|
|
357
|
+
console.log(`Phone (set in the app, wins over the above):
|
|
358
|
+
minSeconds ${s.minSeconds ?? "(not set)"}, delay ${s.delay}, lang ${s.lang}, details ${on(s.detail)}
|
|
359
|
+
pings: done ${on(s.kinds.done)}, waiting ${on(s.kinds.waiting)}
|
|
360
|
+
quiet hours ${q.enabled ? `${q.from}-${q.to} (${q.tz})${q.waitingPasses ? ", waiting still pings" : ""}` : "off"}
|
|
361
|
+
${s.pausedUntil > Date.now() ? "paused until " + new Date(s.pausedUntil).toLocaleString() : "not paused"}`);
|
|
362
|
+
} else console.log("(Could not reach the relay to read the phone settings.)");
|
|
363
|
+
}
|
|
364
|
+
} else if (cmd === "mute" || cmd === "unmute") {
|
|
365
|
+
// node ccn.mjs mute my-project | mute . (this folder) | unmute my-project | mute (list)
|
|
366
|
+
const conf = load() ?? {};
|
|
367
|
+
let list = conf.ignore ?? [".claude-mem"];
|
|
368
|
+
let name = process.argv[3];
|
|
369
|
+
if (name === ".") name = path.basename(process.cwd());
|
|
370
|
+
if (name) {
|
|
371
|
+
const frag = "/" + path.basename(name) + "/";
|
|
372
|
+
list = cmd === "mute" ? [...new Set([...list, frag])] : list.filter((x) => x !== frag);
|
|
373
|
+
conf.ignore = list;
|
|
374
|
+
fs.writeFileSync(CONF, JSON.stringify(conf, null, 2));
|
|
375
|
+
}
|
|
376
|
+
console.log("Muted projects: " + (list.join(", ") || "(none)"));
|
|
377
|
+
} else if (cmd === "delayed") {
|
|
378
|
+
try {
|
|
379
|
+
const j = JSON.parse(process.env.CCN_DELAYED || "{}");
|
|
380
|
+
await new Promise((r) => setTimeout(r, j.delay * 1000));
|
|
381
|
+
if (lastActivity(j.p.session_id) <= j.at && !disabled()) await route(load() ?? {}, j.p, j.secs, j.short);
|
|
382
|
+
} catch { /* ignore */ }
|
|
251
383
|
} else if (cmd === "popup") {
|
|
252
384
|
try { await desktop(JSON.parse(process.env.CCN_POPUP || "{}")); } catch { /* ignore */ }
|
|
253
385
|
} else if (cmd === "hook") {
|
|
@@ -257,17 +389,23 @@ if (isMain) {
|
|
|
257
389
|
const conf = load() ?? {};
|
|
258
390
|
const p = JSON.parse(fs.readFileSync(0, "utf8") || "{}");
|
|
259
391
|
if (!disabled()) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
392
|
+
const now = Date.now();
|
|
393
|
+
if (p.hook_event_name === "UserPromptSubmit") { recordStart(p.session_id); touch(p.session_id); }
|
|
394
|
+
else {
|
|
395
|
+
const at = p.hook_event_name === "Stop" ? touch(p.session_id) : now; // a finished task counts as activity: it cancels an older delayed "waiting" ping
|
|
396
|
+
const st = startedAt(p.session_id);
|
|
397
|
+
if (!skipReason(p, { ...conf, minSeconds: 0 }, now, st) && !throttled(p)) {
|
|
398
|
+
// Everything but the duration check passed. A short task still goes to the relay (the phone may want it); popup and ntfy follow our minSeconds.
|
|
399
|
+
const secs = st == null ? undefined : Math.round((now - st) / 1000);
|
|
400
|
+
const short = skipReason(p, conf, now, st) !== null;
|
|
401
|
+
const delay = conf.relayPrefs?.delay ?? conf.delay ?? 0;
|
|
402
|
+
if (delay > 0) later({ delay, at, secs, short, p: { hook_event_name: p.hook_event_name, session_id: p.session_id, cwd: p.cwd, message: p.message, last_assistant_message: clamp(String(p.last_assistant_message ?? ""), 600) } });
|
|
403
|
+
else await route(conf, p, secs, short);
|
|
404
|
+
}
|
|
267
405
|
}
|
|
268
406
|
}
|
|
269
407
|
} catch { /* ignore */ }
|
|
270
408
|
} else {
|
|
271
|
-
console.log("usage: node ccn.mjs setup|init|topic|test|install|uninstall|pair|hook");
|
|
409
|
+
console.log("usage: node ccn.mjs setup|init|topic|test|install|uninstall|pair|config|mute|unmute|hook");
|
|
272
410
|
}
|
|
273
411
|
}
|