@zeph-to/cli 1.16.0 → 1.18.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/README.md +33 -12
- package/dist/check-update.js +1 -1
- package/dist/cli.js +8 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -2
- package/dist/crypto.d.ts +2 -1
- package/dist/crypto.d.ts.map +1 -1
- package/dist/crypto.js +7 -1
- package/dist/gate.d.ts +1 -0
- package/dist/gate.d.ts.map +1 -1
- package/dist/gate.js +36 -5
- package/dist/listener.d.ts +10 -0
- package/dist/listener.d.ts.map +1 -1
- package/dist/listener.js +54 -3
- package/dist/remote-agents.d.ts.map +1 -1
- package/dist/remote-agents.js +32 -10
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/zeph-core.generated.d.ts +3 -3
- package/dist/zeph-core.generated.d.ts.map +1 -1
- package/dist/zeph-core.generated.js +3 -3
- package/dist/zeph-hook.d.ts.map +1 -1
- package/dist/zeph-hook.js +31 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,13 +5,23 @@
|
|
|
5
5
|
[](https://nodejs.org)
|
|
6
6
|
[](./LICENSE)
|
|
7
7
|
|
|
8
|
-
Push notification SDK + CLI for [Zeph](https://zeph.to)
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
Push notification SDK + CLI for [Zeph](https://zeph.to) — the terminal
|
|
9
|
+
side of the round trip: your agent works, hits a decision, and asks your
|
|
10
|
+
phone; you tap a button (or type a reply), and the answer lands back in
|
|
11
|
+
the live session so the agent keeps going.
|
|
11
12
|
|
|
12
13
|
- `ZephHook` SDK — native `fetch`, no runtime deps. Send/list/dismiss pushes.
|
|
13
|
-
- `zeph` CLI —
|
|
14
|
-
|
|
14
|
+
- `zeph` CLI — one-command setup for 8 AI agents, push sending, and an
|
|
15
|
+
optional resident listener that **drives Claude Code / Codex / Gemini
|
|
16
|
+
sessions from your phone** by injecting messages into named tmux
|
|
17
|
+
sessions.
|
|
18
|
+
|
|
19
|
+
Part of the Zeph toolchain:
|
|
20
|
+
[`@zeph-to/mcp-server`](https://github.com/zeph-to/mcp-server) (the MCP
|
|
21
|
+
tools your agent calls, e.g. `zeph_ask`) ·
|
|
22
|
+
[`zeph-to/plugin`](https://github.com/zeph-to/plugin) (Claude Code plugin
|
|
23
|
+
bundling hooks + MCP + rules) · the [Zeph app](https://zeph.to) on your
|
|
24
|
+
phone.
|
|
15
25
|
|
|
16
26
|
## Installation
|
|
17
27
|
|
|
@@ -49,6 +59,11 @@ npx @zeph-to/cli install --key ak_... --hook hook_...
|
|
|
49
59
|
Either way it saves to `~/.zeph/config.json`. All Zeph tools (CLI, MCP
|
|
50
60
|
server, plugin hooks, listener) read this file.
|
|
51
61
|
|
|
62
|
+
On a fresh machine `install` alone is enough: with no `--key` and no
|
|
63
|
+
saved config it opens the same browser login automatically (headless
|
|
64
|
+
boxes fall back to manual key entry). Pass `--only claude,cursor,…` to
|
|
65
|
+
skip the interactive agent picker.
|
|
66
|
+
|
|
52
67
|
To **send** notifications:
|
|
53
68
|
|
|
54
69
|
```bash
|
|
@@ -63,8 +78,8 @@ To **drive a Claude Code / Codex / Gemini session from your phone**, see
|
|
|
63
78
|
> Send messages from your phone *into* a live Claude Code / Codex /
|
|
64
79
|
> Gemini session — even after a `zeph_ask` polling window has expired.
|
|
65
80
|
|
|
66
|
-
The MCP tools `zeph_ask` / `zeph_prompt` / `zeph_input`
|
|
67
|
-
|
|
81
|
+
The MCP tools `zeph_ask` / `zeph_prompt` / `zeph_input` wait on a fixed
|
|
82
|
+
timeout (120–600 s). Once that window closes the
|
|
68
83
|
session becomes unaddressable from the phone, even though it's still
|
|
69
84
|
running. The `zeph listener` daemon fixes this by keeping a persistent
|
|
70
85
|
WebSocket open to Zeph and injecting matching messages into a *named*
|
|
@@ -293,7 +308,7 @@ zeph notify --title "Hello" --json
|
|
|
293
308
|
| Command | Description |
|
|
294
309
|
|---------|-------------|
|
|
295
310
|
| `login` | Browser sign-in: auto-fetch API key + hook into `~/.zeph/config.json` over a localhost loopback (`--web-url`, `--timeout`). No copy-paste |
|
|
296
|
-
| `install` | One-command setup: detect agents, save config, install rules + hooks + MCP |
|
|
311
|
+
| `install` (alias: `setup`) | One-command setup: detect agents, save config, install rules + hooks + MCP. No saved config → opens browser login automatically. `--only claude,cursor,…` skips the picker |
|
|
297
312
|
| `uninstall` | Remove Zeph from all detected agents (`--dry-run`, `--purge`) |
|
|
298
313
|
| `verify` | Check installation health across detected agents (`--ping` for a live API call) |
|
|
299
314
|
| `check-update` | Check whether a newer Zeph version is on npm |
|
|
@@ -314,6 +329,10 @@ zeph notify --title "Hello" --json
|
|
|
314
329
|
| `--type <type>` | Push type: `note`, `link`, `file`, `hook` |
|
|
315
330
|
| `--priority <p>` | Priority: `low`, `normal`, `high`, `urgent` |
|
|
316
331
|
| `--device <id>` | Target device ID |
|
|
332
|
+
| `--session <id>` | AI session ID so the push threads into that session's chat (or `ZEPH_SESSION_ID` env) |
|
|
333
|
+
| `--auto` | Apply the push gate before sending — honors the `/zeph-quiet` / `/zeph-loud` push-mode dial; gated-out exits silently with code 0 |
|
|
334
|
+
| `--marker <m>` | Push Signal marker for `--auto`: `skip`, `push`, `high` |
|
|
335
|
+
| `--tools <n>`, `--nonreadonly <n>` | Turn tool counts feeding `--auto`'s heuristic (defaults assume real work) |
|
|
317
336
|
|
|
318
337
|
The defaults are tuned for hook-driven invocations (e.g. Stop hooks
|
|
319
338
|
calling `zeph notify --title "Task done"` without a body) — you'll see
|
|
@@ -326,6 +345,7 @@ which project + branch finished without writing per-IDE wrappers. Pass
|
|
|
326
345
|
|------|-------------|
|
|
327
346
|
| `--ws-url <url>` | WebSocket endpoint (or set `ZEPH_WS_URL` env, or `wsUrl` in `~/.zeph/config.json`) |
|
|
328
347
|
| `--key <api-key>` | API key (or set `ZEPH_API_KEY` env) |
|
|
348
|
+
| `--base-url <url>` | REST API base URL (or set `ZEPH_BASE_URL` env, or `baseUrl` in `~/.zeph/config.json`) |
|
|
329
349
|
|
|
330
350
|
The listener reconnects with exponential backoff + jitter (1 s → 30 s
|
|
331
351
|
cap). Heartbeat is ping every 25 s with a 10 s pong timeout. On an
|
|
@@ -454,11 +474,12 @@ try {
|
|
|
454
474
|
|-------|-------------------|
|
|
455
475
|
| Claude Code | Plugin (hooks + MCP server) |
|
|
456
476
|
| Cursor | MCP server + stop hook + rules |
|
|
457
|
-
| Windsurf | MCP server + response hook |
|
|
477
|
+
| Windsurf | MCP server + response hook + rules |
|
|
458
478
|
| Gemini CLI | MCP server + AfterAgent hook |
|
|
459
|
-
| Codex CLI | Stop hook |
|
|
460
|
-
| Copilot CLI | Session end hook |
|
|
461
|
-
| Cline | Rules file |
|
|
479
|
+
| Codex CLI | Stop hook + rules |
|
|
480
|
+
| Copilot CLI | Session end hook + rules |
|
|
481
|
+
| Cline | Rules file (`~/.cline/rules/zeph.md`) |
|
|
482
|
+
| Aider | Conventions file + `read:` directive in `~/.aider.conf.yml` |
|
|
462
483
|
|
|
463
484
|
For remote-control via `zeph listener` the per-agent setup is the same
|
|
464
485
|
across CC/Codex/Gemini — the wrapper just spawns them in a named tmux
|
package/dist/check-update.js
CHANGED
|
@@ -49,7 +49,7 @@ const handleCheckUpdate = async (args) => {
|
|
|
49
49
|
}
|
|
50
50
|
if (isJson) {
|
|
51
51
|
console.log(JSON.stringify({ results }, null, 2));
|
|
52
|
-
return
|
|
52
|
+
return 0;
|
|
53
53
|
}
|
|
54
54
|
console.log('\n Zeph — update check\n');
|
|
55
55
|
let anyOutdated = false;
|
package/dist/cli.js
CHANGED
|
@@ -229,7 +229,10 @@ const handleList = async (args) => {
|
|
|
229
229
|
if (!hook)
|
|
230
230
|
return 3;
|
|
231
231
|
try {
|
|
232
|
-
|
|
232
|
+
// Clamp to the documented 1-20 range; a non-numeric value falls back to
|
|
233
|
+
// the server default instead of sending limit=NaN in the query string.
|
|
234
|
+
const rawLimit = args.limit ? Number(args.limit) : NaN;
|
|
235
|
+
const limit = Number.isFinite(rawLimit) ? Math.min(20, Math.max(1, Math.floor(rawLimit))) : undefined;
|
|
233
236
|
const result = await hook.list({
|
|
234
237
|
limit,
|
|
235
238
|
type: args.type,
|
|
@@ -387,4 +390,7 @@ const main = async () => {
|
|
|
387
390
|
return 1;
|
|
388
391
|
}
|
|
389
392
|
};
|
|
390
|
-
main().then((code) => process.exit(code))
|
|
393
|
+
main().then((code) => process.exit(code), (err) => {
|
|
394
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
395
|
+
process.exit(1);
|
|
396
|
+
});
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,QAA2B,CAAC;AACnD,eAAO,MAAM,WAAW,QAAkC,CAAC;AAE3D,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAGlD,CAAC;AAMF,eAAO,MAAM,oBAAoB,+EAAgF,CAAC;AAElH,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,QAAO,MAMnC,CAAC;AAEF,eAAO,MAAM,UAAU,QAAO,UAM7B,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,QAAQ,UAAU,KAAG,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,QAA2B,CAAC;AACnD,eAAO,MAAM,WAAW,QAAkC,CAAC;AAE3D,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAGlD,CAAC;AAMF,eAAO,MAAM,oBAAoB,+EAAgF,CAAC;AAElH,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,QAAO,MAMnC,CAAC;AAEF,eAAO,MAAM,UAAU,QAAO,UAM7B,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,QAAQ,UAAU,KAAG,IAM/C,CAAC;AAEF,eAAO,MAAM,OAAO,QAOhB,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -36,8 +36,11 @@ const loadConfig = () => {
|
|
|
36
36
|
};
|
|
37
37
|
exports.loadConfig = loadConfig;
|
|
38
38
|
const saveConfig = (config) => {
|
|
39
|
-
(0, fs_1.mkdirSync)(exports.CONFIG_DIR, { recursive: true });
|
|
40
|
-
(0, fs_1.writeFileSync)(exports.CONFIG_FILE, JSON.stringify(config, null, 2) + '\n');
|
|
39
|
+
(0, fs_1.mkdirSync)(exports.CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
40
|
+
(0, fs_1.writeFileSync)(exports.CONFIG_FILE, JSON.stringify(config, null, 2) + '\n', { mode: 0o600 });
|
|
41
|
+
// `mode` only applies on creation — tighten pre-existing installs too,
|
|
42
|
+
// since this file holds the API key.
|
|
43
|
+
(0, fs_1.chmodSync)(exports.CONFIG_FILE, 0o600);
|
|
41
44
|
};
|
|
42
45
|
exports.saveConfig = saveConfig;
|
|
43
46
|
exports.VERSION = (() => {
|
package/dist/crypto.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Device-shared encryption for Hook SDK — self-contained ECDH P-256 +
|
|
3
3
|
* AES-256-GCM. Mirrors @zeph/crypto API but bundled inline (no external
|
|
4
|
-
* dependency). Uses Web Crypto API
|
|
4
|
+
* dependency). Uses Web Crypto API via node:crypto webcrypto — Node.js 18+
|
|
5
|
+
* (the `crypto` global only exists unflagged from Node 19, so we import it).
|
|
5
6
|
*
|
|
6
7
|
* Threat model honesty (do not call this "E2E" without a footnote):
|
|
7
8
|
*
|
package/dist/crypto.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAiKH;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,SAAS,MAAM,EAAE,UAAU,MAAM,KAAG,OAAO,CAAC,MAAM,CAsE5E,CAAC;AA2CF,eAAO,MAAM,UAAU,QAAO,aAAa,GAAG,IAAqB,CAAC;AACpE,eAAO,MAAM,YAAY,QAAO,MAAM,GAAG,IAA+B,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,EACtD,uBAAuB,MAAM,KAC5B,OAAO,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,IAAI,CAAC;CACnB,CAeA,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GACjC,OAAO;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,KACrD,OAAO,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,IAAI,CAAC;CACnB,CAaA,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,EACf,uBAAuB,MAAM,KAC5B,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CASlE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,MAAM,KACd,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAQlE,CAAC"}
|
package/dist/crypto.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Device-shared encryption for Hook SDK — self-contained ECDH P-256 +
|
|
4
4
|
* AES-256-GCM. Mirrors @zeph/crypto API but bundled inline (no external
|
|
5
|
-
* dependency). Uses Web Crypto API
|
|
5
|
+
* dependency). Uses Web Crypto API via node:crypto webcrypto — Node.js 18+
|
|
6
|
+
* (the `crypto` global only exists unflagged from Node 19, so we import it).
|
|
6
7
|
*
|
|
7
8
|
* Threat model honesty (do not call this "E2E" without a footnote):
|
|
8
9
|
*
|
|
@@ -33,6 +34,11 @@ exports.encryptFileForSelf = exports.encryptFileForRecipient = exports.encryptPu
|
|
|
33
34
|
const fs_1 = require("fs");
|
|
34
35
|
const os_1 = require("os");
|
|
35
36
|
const path_1 = require("path");
|
|
37
|
+
const node_crypto_1 = require("node:crypto");
|
|
38
|
+
// Node 18 has no `crypto` global (unflagged only from 19.0.0) — resolve the
|
|
39
|
+
// Web Crypto implementation explicitly so encryption works on the declared
|
|
40
|
+
// minimum runtime instead of silently falling back to plaintext.
|
|
41
|
+
const crypto = node_crypto_1.webcrypto;
|
|
36
42
|
// ─── Base64 helpers ───
|
|
37
43
|
const toBase64 = (buffer) => {
|
|
38
44
|
const bytes = new Uint8Array(buffer);
|
package/dist/gate.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare const GATE_DEFAULTS: {
|
|
|
28
28
|
export declare const normalizeMarker: (raw: string | undefined) => GateMarker;
|
|
29
29
|
export declare const normalizePushMode: (raw: string | undefined) => GatePushMode;
|
|
30
30
|
export declare const decidePush: (input: GateInput) => GateVerdict;
|
|
31
|
+
export declare const stateDir: () => string;
|
|
31
32
|
export declare const projectHash: (dir: string) => string | null;
|
|
32
33
|
/** True when the user ran /zeph-mute for this project. */
|
|
33
34
|
export declare const isMuted: (dir: string) => boolean;
|
package/dist/gate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gate.d.ts","sourceRoot":"","sources":["../src/gate.ts"],"names":[],"mappings":"AAwBA,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAC3D,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEvD,MAAM,WAAW,SAAS;IACxB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,gBAAgB,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,YAAY,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC;CAC7B;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;CAIhB,CAAC;AAEX,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,GAAG,SAAS,KAAG,UACS,CAAC;AAEpE,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,GAAG,SAAS,KAAG,YACR,CAAC;AAErD,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,KAAG,WAW7C,CAAC;AAeF,eAAO,MAAM,QAAQ,QAAO,MACoD,CAAC;AAmBjF,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,IAOlD,CAAC;AAEF,0DAA0D;AAC1D,eAAO,MAAM,OAAO,GAAI,KAAK,MAAM,KAAG,OAGrC,CAAC;AAEF,oFAAoF;AACpF,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,YAU1C,CAAC"}
|
package/dist/gate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readPushMode = exports.isMuted = exports.projectHash = exports.decidePush = exports.normalizePushMode = exports.normalizeMarker = exports.GATE_DEFAULTS = void 0;
|
|
3
|
+
exports.readPushMode = exports.isMuted = exports.projectHash = exports.stateDir = exports.decidePush = exports.normalizePushMode = exports.normalizeMarker = exports.GATE_DEFAULTS = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Push-gate decision — the portable half of the Zeph Stop-hook logic.
|
|
6
6
|
*
|
|
@@ -22,6 +22,8 @@ exports.readPushMode = exports.isMuted = exports.projectHash = exports.decidePus
|
|
|
22
22
|
*/
|
|
23
23
|
const child_process_1 = require("child_process");
|
|
24
24
|
const fs_1 = require("fs");
|
|
25
|
+
const os_1 = require("os");
|
|
26
|
+
const path_1 = require("path");
|
|
25
27
|
/**
|
|
26
28
|
* "Assume real work" defaults for hooks that can't supply turn facts
|
|
27
29
|
* (most non-Claude agents pass no counts): in normal mode the push still
|
|
@@ -54,9 +56,35 @@ const decidePush = (input) => {
|
|
|
54
56
|
exports.decidePush = decidePush;
|
|
55
57
|
// ── Per-project gate state (mute + push-mode dial) ───────────────
|
|
56
58
|
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
+
// State lives under ${XDG_STATE_HOME:-~/.local/state}/zeph — a per-user
|
|
60
|
+
// directory. It used to live at predictable names in world-writable /tmp,
|
|
61
|
+
// where any local user could pre-create a victim's mute file (and sticky
|
|
62
|
+
// /tmp makes that file un-deletable by the victim). Legacy /tmp files are
|
|
63
|
+
// still honored during the migration window, but only when owned by the
|
|
64
|
+
// current user, which neutralizes planted files.
|
|
65
|
+
//
|
|
66
|
+
// The plugin's bash hooks key these files off `cksum` of the project dir;
|
|
67
|
+
// shelling out to the same `cksum` here (instead of a pure-TS CRC)
|
|
59
68
|
// guarantees hash parity with every already-written file.
|
|
69
|
+
const stateDir = () => (0, path_1.join)(process.env.XDG_STATE_HOME || (0, path_1.join)((0, os_1.homedir)(), '.local', 'state'), 'zeph');
|
|
70
|
+
exports.stateDir = stateDir;
|
|
71
|
+
const ownedByCurrentUser = (path) => {
|
|
72
|
+
try {
|
|
73
|
+
const st = (0, fs_1.statSync)(path);
|
|
74
|
+
return typeof process.getuid !== 'function' || st.uid === process.getuid();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
/** Resolve a state file: current location first, then user-owned legacy /tmp. */
|
|
81
|
+
const findStateFile = (kind, hash) => {
|
|
82
|
+
const current = (0, path_1.join)((0, exports.stateDir)(), `${kind}-${hash}`);
|
|
83
|
+
if ((0, fs_1.existsSync)(current))
|
|
84
|
+
return current;
|
|
85
|
+
const legacy = `/tmp/zeph-${kind}-${hash}`;
|
|
86
|
+
return ownedByCurrentUser(legacy) ? legacy : null;
|
|
87
|
+
};
|
|
60
88
|
const projectHash = (dir) => {
|
|
61
89
|
try {
|
|
62
90
|
const raw = (0, child_process_1.execFileSync)('cksum', { input: dir, encoding: 'utf-8' });
|
|
@@ -70,7 +98,7 @@ exports.projectHash = projectHash;
|
|
|
70
98
|
/** True when the user ran /zeph-mute for this project. */
|
|
71
99
|
const isMuted = (dir) => {
|
|
72
100
|
const hash = (0, exports.projectHash)(dir);
|
|
73
|
-
return hash !== null && (
|
|
101
|
+
return hash !== null && findStateFile('muted', hash) !== null;
|
|
74
102
|
};
|
|
75
103
|
exports.isMuted = isMuted;
|
|
76
104
|
/** The user's session push-mode dial (/zeph-quiet | /zeph-loud), default normal. */
|
|
@@ -78,8 +106,11 @@ const readPushMode = (dir) => {
|
|
|
78
106
|
const hash = (0, exports.projectHash)(dir);
|
|
79
107
|
if (!hash)
|
|
80
108
|
return 'normal';
|
|
109
|
+
const file = findStateFile('pushmode', hash);
|
|
110
|
+
if (!file)
|
|
111
|
+
return 'normal';
|
|
81
112
|
try {
|
|
82
|
-
return (0, exports.normalizePushMode)((0, fs_1.readFileSync)(
|
|
113
|
+
return (0, exports.normalizePushMode)((0, fs_1.readFileSync)(file, 'utf-8').replace(/\s+/g, ''));
|
|
83
114
|
}
|
|
84
115
|
catch {
|
|
85
116
|
return 'normal';
|
package/dist/listener.d.ts
CHANGED
|
@@ -207,7 +207,17 @@ interface HandlePushDeps {
|
|
|
207
207
|
now?: () => number;
|
|
208
208
|
/** Injectable for tests; defaults to the REST-backed downloader. */
|
|
209
209
|
downloadAttachments?: (pushId: string, files: PushFileAttachment[]) => Promise<string[]>;
|
|
210
|
+
/** Pane cwd lookup for the remote-origin marker (ADR-0002). */
|
|
211
|
+
paneCwd?: (session: string) => string | null;
|
|
210
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Record a successful phone→pane text injection so the plugin's
|
|
215
|
+
* UserPromptSubmit hook can flag the matching prompt as remote-originated
|
|
216
|
+
* and enter sticky REMOTE mode (ADR-0002). One file per project dir,
|
|
217
|
+
* overwritten on every inject; the hook consumes it on an exact-text match.
|
|
218
|
+
* Best-effort: a write failure must never fail the injection itself.
|
|
219
|
+
*/
|
|
220
|
+
export declare const writeRemoteMarker: (paneCwd: string, text: string, now?: () => number) => boolean;
|
|
211
221
|
export declare const setAttachmentContext: (ctx: {
|
|
212
222
|
apiKey: string;
|
|
213
223
|
baseUrl: string;
|
package/dist/listener.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../src/listener.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;
|
|
1
|
+
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../src/listener.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAUH,OAAO,EAA2B,KAAK,SAAS,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACzG,OAAO,EAAiD,KAAK,UAAU,EAA4C,MAAM,kBAAkB,CAAC;AA4B5I,UAAU,YAAY;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAYD,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAAC,MAAM,CAA+B,CAAC;AAenF,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,EAAE,MAAK,MAAmB,KAAG,OAgB1E,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,KAAG,MAAM,GAAG,IAO7D,CAAC;AAiCF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,EAAE,KAAG,MAA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CAAA;CAAE,KAAG,IAE/E,CAAC;AA2FF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GACtB,MAAK,MAAmB,EACxB,MAAK,MAAwB,EAC7B,MAAK,MAA0B,KAChC,MAaF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GACnB,MAAM,QAAQ,EACd,OAAM,cAAmB,KAC1B,OAAO,CAAC,OAAO,CAkCjB,CAAC;AAcF,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,MAIhD,CAAC;AAWF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAM,MAAmB,KAAG,MAGnE,CAAC;AA8PF,eAAO,MAAM,cAAc,GAAU,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,KAAG,OAAO,CAAC,MAAM,CA+H3F,CAAC"}
|
package/dist/listener.js
CHANGED
|
@@ -25,7 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.handleListener = exports.computeListenerDeviceId = exports.computeBackoff = exports.handlePush = exports.gcAttachments = exports.setAttachmentContext = exports.collectSessions = exports.collectSessionsVerbose = exports.handleScreenRequest = exports.collectWatchHits = exports.resetPatternWatches = exports.setPatternWatches = exports.deriveSessionState = exports.resetSessionStates = exports.detectRemoteAgent = exports.parseSessionName = exports.invalidateTmuxSocketCache = exports.resolveKeys = exports.paneCurrentCommand = exports.checkRateLimit = exports.AUTH_FAILURE_CODES = void 0;
|
|
28
|
+
exports.handleListener = exports.computeListenerDeviceId = exports.computeBackoff = exports.handlePush = exports.gcAttachments = exports.setAttachmentContext = exports.writeRemoteMarker = exports.collectSessions = exports.collectSessionsVerbose = exports.handleScreenRequest = exports.collectWatchHits = exports.resetPatternWatches = exports.setPatternWatches = exports.deriveSessionState = exports.resetSessionStates = exports.detectRemoteAgent = exports.parseSessionName = exports.invalidateTmuxSocketCache = exports.resolveKeys = exports.paneCurrentCommand = exports.checkRateLimit = exports.AUTH_FAILURE_CODES = void 0;
|
|
29
29
|
const child_process_1 = require("child_process");
|
|
30
30
|
const crypto_1 = require("crypto");
|
|
31
31
|
const fs_1 = require("fs");
|
|
@@ -33,6 +33,7 @@ const os_1 = require("os");
|
|
|
33
33
|
const path_1 = require("path");
|
|
34
34
|
const ws_1 = __importDefault(require("ws"));
|
|
35
35
|
const config_js_1 = require("./config.js");
|
|
36
|
+
const gate_js_1 = require("./gate.js");
|
|
36
37
|
const remote_agents_js_1 = require("./remote-agents.js");
|
|
37
38
|
const agent_state_js_1 = require("./agent-state.js");
|
|
38
39
|
const agent_rules_fetch_js_1 = require("./agent-rules-fetch.js");
|
|
@@ -772,6 +773,34 @@ const passesInjectGuards = (session, deps) => {
|
|
|
772
773
|
}
|
|
773
774
|
return true;
|
|
774
775
|
};
|
|
776
|
+
/**
|
|
777
|
+
* Record a successful phone→pane text injection so the plugin's
|
|
778
|
+
* UserPromptSubmit hook can flag the matching prompt as remote-originated
|
|
779
|
+
* and enter sticky REMOTE mode (ADR-0002). One file per project dir,
|
|
780
|
+
* overwritten on every inject; the hook consumes it on an exact-text match.
|
|
781
|
+
* Best-effort: a write failure must never fail the injection itself.
|
|
782
|
+
*/
|
|
783
|
+
const writeRemoteMarker = (paneCwd, text, now = Date.now) => {
|
|
784
|
+
const hash = (0, gate_js_1.projectHash)(paneCwd);
|
|
785
|
+
if (!hash)
|
|
786
|
+
return false;
|
|
787
|
+
try {
|
|
788
|
+
(0, fs_1.mkdirSync)((0, gate_js_1.stateDir)(), { recursive: true, mode: 0o700 });
|
|
789
|
+
// Explicit ASCII-only trim, NOT String.trim() — trim() also strips
|
|
790
|
+
// Unicode whitespace (U+00A0 etc.) that the hook's bash-side trim
|
|
791
|
+
// keeps. Both sides must strip the exact same bytes: the hook
|
|
792
|
+
// (zeph-remote.sh) trims $' \t\r\n\f\v' and nothing else.
|
|
793
|
+
const trimmed = text.replace(/^[ \t\r\n\f\v]+|[ \t\r\n\f\v]+$/g, '');
|
|
794
|
+
const digest = (0, crypto_1.createHash)('sha256').update(trimmed).digest('hex');
|
|
795
|
+
(0, fs_1.writeFileSync)((0, path_1.join)((0, gate_js_1.stateDir)(), `remote-${hash}`), `${Math.floor(now() / 1000)} ${digest}\n`);
|
|
796
|
+
return true;
|
|
797
|
+
}
|
|
798
|
+
catch {
|
|
799
|
+
return false;
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
exports.writeRemoteMarker = writeRemoteMarker;
|
|
803
|
+
const defaultPaneCwd = (session) => readPaneInfo(session).currentPath;
|
|
775
804
|
const tryInject = (session, text, deps) => {
|
|
776
805
|
if (!text) {
|
|
777
806
|
log(`! ${session}: empty text — drop`);
|
|
@@ -782,6 +811,11 @@ const tryInject = (session, text, deps) => {
|
|
|
782
811
|
const ok = (deps.inject ?? injectKeys)(session, text);
|
|
783
812
|
const preview = text.length > 60 ? text.slice(0, 60) + '…' : text;
|
|
784
813
|
log(`${ok ? '→' : '✗'} ${session}: ${preview}`);
|
|
814
|
+
if (ok) {
|
|
815
|
+
const cwd = (deps.paneCwd ?? defaultPaneCwd)(session);
|
|
816
|
+
if (cwd)
|
|
817
|
+
(0, exports.writeRemoteMarker)(cwd, text);
|
|
818
|
+
}
|
|
785
819
|
return ok;
|
|
786
820
|
};
|
|
787
821
|
/** Key-event sibling of tryInject: same pane/shell/rate guards, but sends
|
|
@@ -990,11 +1024,16 @@ exports.computeListenerDeviceId = computeListenerDeviceId;
|
|
|
990
1024
|
*/
|
|
991
1025
|
const streamSession = (wsUrl, apiKey) => {
|
|
992
1026
|
let ws = null;
|
|
1027
|
+
let opened = false;
|
|
993
1028
|
const done = new Promise((resolve) => {
|
|
994
1029
|
// deviceId + listenerNickname let the backend attach the connection
|
|
995
1030
|
// to a DeviceRecord (auto-created on first connect for apiKey auth).
|
|
996
1031
|
// Without these the `listener.sessions` reports are silently dropped
|
|
997
1032
|
// server-side and the phone's picker stays empty.
|
|
1033
|
+
// KNOWN TRADEOFF: apiKey rides the query string, so it can land in
|
|
1034
|
+
// API Gateway access logs. The $connect route can't read custom
|
|
1035
|
+
// headers from every WS client; moving to first-message auth needs a
|
|
1036
|
+
// server-side change (tracked upstream).
|
|
998
1037
|
const deviceId = (0, exports.computeListenerDeviceId)();
|
|
999
1038
|
const nickname = (0, os_1.hostname)() || 'listener';
|
|
1000
1039
|
const params = new URLSearchParams({
|
|
@@ -1099,6 +1138,7 @@ const streamSession = (wsUrl, apiKey) => {
|
|
|
1099
1138
|
clearTimeout(connectTimer);
|
|
1100
1139
|
connectTimer = null;
|
|
1101
1140
|
}
|
|
1141
|
+
opened = true;
|
|
1102
1142
|
lastRoundTripAt = Date.now();
|
|
1103
1143
|
log('connected');
|
|
1104
1144
|
// Initial inventory so the phone's picker has something to
|
|
@@ -1183,7 +1223,7 @@ const streamSession = (wsUrl, apiKey) => {
|
|
|
1183
1223
|
});
|
|
1184
1224
|
sock.on('close', (code, reasonBuf) => {
|
|
1185
1225
|
cleanup();
|
|
1186
|
-
resolve({ closeCode: code, reason: reasonBuf?.toString('utf-8') ?? '' });
|
|
1226
|
+
resolve({ closeCode: code, reason: reasonBuf?.toString('utf-8') ?? '', connected: opened });
|
|
1187
1227
|
});
|
|
1188
1228
|
});
|
|
1189
1229
|
return {
|
|
@@ -1312,6 +1352,11 @@ const handleListener = async (args) => {
|
|
|
1312
1352
|
rulesTimer.unref();
|
|
1313
1353
|
let shuttingDown = false;
|
|
1314
1354
|
let activeHandle = null;
|
|
1355
|
+
// Resolved by stop() so the reconnect backoff sleep below can be
|
|
1356
|
+
// interrupted — otherwise a SIGINT during the (up to 30s) backoff waits
|
|
1357
|
+
// out the full delay before the loop notices shuttingDown.
|
|
1358
|
+
let notifyStop = () => undefined;
|
|
1359
|
+
const stopped = new Promise((resolve) => { notifyStop = resolve; });
|
|
1315
1360
|
const stop = (sig) => {
|
|
1316
1361
|
if (shuttingDown)
|
|
1317
1362
|
return;
|
|
@@ -1320,6 +1365,7 @@ const handleListener = async (args) => {
|
|
|
1320
1365
|
// Force-close any open WS so the streamSession promise resolves
|
|
1321
1366
|
// immediately instead of waiting for the server to drop us.
|
|
1322
1367
|
activeHandle?.terminate();
|
|
1368
|
+
notifyStop();
|
|
1323
1369
|
};
|
|
1324
1370
|
process.on('SIGINT', () => stop('SIGINT'));
|
|
1325
1371
|
process.on('SIGTERM', () => stop('SIGTERM'));
|
|
@@ -1335,9 +1381,14 @@ const handleListener = async (args) => {
|
|
|
1335
1381
|
}
|
|
1336
1382
|
if (shuttingDown)
|
|
1337
1383
|
break;
|
|
1384
|
+
// A session that actually connected resets the backoff — otherwise a
|
|
1385
|
+
// long-lived daemon on a flaky link ratchets up to the 30s ceiling
|
|
1386
|
+
// permanently, even when every reconnect succeeds instantly.
|
|
1387
|
+
if (result.connected)
|
|
1388
|
+
attempt = 0;
|
|
1338
1389
|
const delay = (0, exports.computeBackoff)(attempt);
|
|
1339
1390
|
log(`disconnected (code=${result.closeCode}) — reconnect in ${Math.round(delay / 1000)}s`);
|
|
1340
|
-
await sleep(delay);
|
|
1391
|
+
await Promise.race([sleep(delay), stopped]);
|
|
1341
1392
|
attempt = Math.min(attempt + 1, 10);
|
|
1342
1393
|
}
|
|
1343
1394
|
removeListenerPid();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-agents.d.ts","sourceRoot":"","sources":["../src/remote-agents.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,WAAW;IACxB,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,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eAAO,MAAM,0BAA0B,GACnC,SAAS,MAAM,EACf,SAAS,MAAM,GAAG,IAAI,EACtB,OAAM,cAAmB,KAC1B,MAAM,GAAG,IAOX,CAAC;AAIF,QAAA,MAAM,kBAAkB;;;;;;;;;;;;;;;;EAwBmB,CAAC;AAE5C,uFAAuF;AACvF,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,8FAA8F;AAC9F,MAAM,MAAM,qBAAqB,GAAG,WAAW,GAAG;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC;AAEtE,eAAO,MAAM,aAAa,EAAE,SAAS,qBAAqB,EAAuB,CAAC;AAElF,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,KAAG,qBAAqB,GAAG,SAClB,CAAC;AAE3D,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,KAAG,qBAAqB,GAAG,SAG9E,CAAC"}
|
package/dist/remote-agents.js
CHANGED
|
@@ -112,15 +112,25 @@ const readPidSessionRecords = () => {
|
|
|
112
112
|
return []; // dir absent (older CC) — caller falls back to mtime
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
115
|
+
// One `ps` spawn and one ~/.claude/sessions scan per report cycle, not per
|
|
116
|
+
// tmux session: the resolver runs for every session every 5s, and each call
|
|
117
|
+
// paid a full process-table spawn plus a directory scan on the daemon's hot
|
|
118
|
+
// path. A TTL just under the report interval lets all sessions in one cycle
|
|
119
|
+
// share a single snapshot while still refreshing every cycle. The parsed
|
|
120
|
+
// child-adjacency map is what's cached (not the raw table) so N sessions
|
|
121
|
+
// share one parse and differ only in the per-root BFS.
|
|
122
|
+
const SNAPSHOT_TTL_MS = 4_000;
|
|
123
|
+
const ttlMemo = (ttlMs, compute) => {
|
|
124
|
+
let snap = null;
|
|
125
|
+
return () => {
|
|
126
|
+
const now = Date.now();
|
|
127
|
+
if (snap && snap.expiresAt > now)
|
|
128
|
+
return snap.value;
|
|
129
|
+
snap = { value: compute(), expiresAt: now + ttlMs };
|
|
130
|
+
return snap.value;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
const parseChildren = (table) => {
|
|
124
134
|
const children = new Map();
|
|
125
135
|
for (const line of table.split('\n')) {
|
|
126
136
|
const m = line.trim().match(/^(\d+)\s+(\d+)$/);
|
|
@@ -131,6 +141,18 @@ const collectDescendantPids = (rootPid, psOutput) => {
|
|
|
131
141
|
list.push(pid);
|
|
132
142
|
children.set(ppid, list);
|
|
133
143
|
}
|
|
144
|
+
return children;
|
|
145
|
+
};
|
|
146
|
+
const readPsChildren = ttlMemo(SNAPSHOT_TTL_MS, () => {
|
|
147
|
+
const r = (0, child_process_1.spawnSync)('ps', ['-axo', 'pid=,ppid='], { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] });
|
|
148
|
+
return r.status === 0 ? parseChildren(r.stdout ?? '') : null;
|
|
149
|
+
});
|
|
150
|
+
const cachedPidSessionRecords = ttlMemo(SNAPSHOT_TTL_MS, readPidSessionRecords);
|
|
151
|
+
/** pid set of `rootPid` + all descendants, from one `ps` snapshot. */
|
|
152
|
+
const collectDescendantPids = (rootPid, psOutput) => {
|
|
153
|
+
const children = psOutput !== undefined ? parseChildren(psOutput) : readPsChildren();
|
|
154
|
+
if (children === null)
|
|
155
|
+
return new Set([rootPid]);
|
|
134
156
|
const found = new Set([rootPid]);
|
|
135
157
|
const queue = [rootPid];
|
|
136
158
|
while (queue.length > 0) {
|
|
@@ -150,7 +172,7 @@ const collectDescendantPids = (rootPid, psOutput) => {
|
|
|
150
172
|
* to the mtime heuristic.
|
|
151
173
|
*/
|
|
152
174
|
const detectClaudeSessionIdByPid = (panePid, paneCwd, deps = {}) => {
|
|
153
|
-
const records = deps.records ??
|
|
175
|
+
const records = deps.records ?? cachedPidSessionRecords();
|
|
154
176
|
if (records.length === 0)
|
|
155
177
|
return null;
|
|
156
178
|
const descendants = deps.descendants ?? collectDescendantPids(panePid);
|
package/dist/types.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export interface NotifyPayload {
|
|
|
11
11
|
priority?: 'low' | 'normal' | 'high' | 'urgent';
|
|
12
12
|
targetDeviceId?: string;
|
|
13
13
|
sessionId?: string;
|
|
14
|
+
/** Stable agent-session grouping so a hook/notify joins the agent chat:
|
|
15
|
+
* the listener device (per-host) + tmux session name. Auto-filled by
|
|
16
|
+
* ZephHook.notify when running inside a tmux agent session. */
|
|
17
|
+
agentDeviceId?: string;
|
|
18
|
+
agentSessionName?: string;
|
|
14
19
|
}
|
|
15
20
|
export interface NotifyResult {
|
|
16
21
|
pushId: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACzC,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAA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;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** sha256 over the plugin manifest + extracted rule text at generation time. */
|
|
2
|
-
export declare const ZEPH_CORE_SOURCE_HASH = "
|
|
2
|
+
export declare const ZEPH_CORE_SOURCE_HASH = "24f467b2379d45cefeabdde0b8864aea274382b931c548544ff20b341bef52c6";
|
|
3
3
|
/** Shared rule core for agents with a Stop-equivalent hook (Cursor, Windsurf, Gemini, Codex, Copilot). */
|
|
4
|
-
export declare const ZEPH_CORE_HOOK_DRIVEN = "### When zeph_ask is MANDATORY\n\n3. **NEVER end a response with a plain-text question.** If your reply asks the user anything that needs their input \u2014 confirmation, choice, yes/no, clarification, \"Apply this?\", \"Proceed?\", \"Which option?\" \u2014 the FINAL tool call MUST be `zeph_ask`. A \"?\" written in your reply is invisible to a user on their phone. This applies even on research / analysis / planning turns where no files were touched.\n\n Anti-pattern (wrong):\n ```\n \"...build/commit on hold. Apply A?\"\n ```\n Correct:\n ```\n zeph_ask({\n title: \"Apply solution A?\",\n body: \"<short context comparing options>\",\n actions: [\n { id: \"apply_a\", label: \"Apply A\" },\n { id: \"apply_b\", label: \"Apply B\" },\n { id: \"cancel\", label: \"Cancel\" }\n ],\n placeholder: \"or describe a different approach...\",\n fallback: \"cancel\"\n })\n ```\n\n### When zeph_ask is the DEFAULT (substantial work)\n\n4. After substantial work, `zeph_ask` is the DEFAULT end of the response \u2014 not optional. \"Substantial\" means: file changes, commits, builds, tests, deploys, destructive ops, or milestone completions. When unsure, treat the work as substantial \u2014 do not try to guess what the user would find \"reasonable\" to confirm.\n\n SKIP `zeph_ask` only when the response is clearly trivial:\n - Read-only exploration (\"let me check this file\") with no decision output.\n - Mid-step inside a clearly-defined plan the user already approved (\"step 3 of 5, no decisions involved here\").\n - Trivial change (typo fix, single-line tweak) that needs no ack.\n\n When unsure: LEAN TOWARD ASKING. Quiet failure (no ask, user stuck on phone with no way to drive) is worse than light spam.\n\n5. Prefer `zeph_ask` over `zeph_prompt`/`zeph_input` \u2014 it combines buttons and free-text in one push. Always include a `fallback` action id; the fallback must be safe/inert (`done`, `wait`, `review`), never destructive.\n\n6. Example `zeph_ask` shape \u2014 use sparingly per Rule 4 (only at natural pause points; NOT after every response \u2014 see Rule 9):\n ```\n zeph_ask({\n title: \"Done. Next?\",\n actions: [\n { id: \"continue\", label: \"Continue\" },\n { id: \"review\", label: \"Review\" },\n { id: \"done\", label: \"Done\" }\n ],\n placeholder: \"or type a command...\",\n fallback: \"done\"\n })\n ```\n\n### Handling the response\n\n7. A `zeph_ask` response IS a direct user instruction. Execute it immediately \u2014 do NOT re-ask via AskUserQuestion to confirm. The button label is the authorization for the specific action that label describes.\n\n8. Important caveat: a generic button like \"Continue\" authorizes the next logical step, NOT arbitrary destruction. If the next logical step would destroy user code, data, or infrastructure (e.g., force-push to a shared branch, `rm -rf` outside the workdir, dropping a database, deleting prod resources), surface that specific risk via a targeted `zeph_ask` before executing \u2014 e.g., title \"About to force-push main \u2014 proceed?\", actions `[ok, cancel]`, fallback `cancel`.\n\n### Sticky REMOTE mode (Rule 9)\n\n**The Ask Loop has two states: REMOTE and NORMAL.** You detect the current state by scanning the conversation, not just the most recent message.\n\n**State in one line:** you are in REMOTE if the most recent `zeph_ask`
|
|
4
|
+
export declare const ZEPH_CORE_HOOK_DRIVEN = "### When zeph_ask is MANDATORY\n\n3. **NEVER end a response with a plain-text question.** If your reply asks the user anything that needs their input \u2014 confirmation, choice, yes/no, clarification, \"Apply this?\", \"Proceed?\", \"Which option?\" \u2014 the FINAL tool call MUST be `zeph_ask`. A \"?\" written in your reply is invisible to a user on their phone. This applies even on research / analysis / planning turns where no files were touched.\n\n Anti-pattern (wrong):\n ```\n \"...build/commit on hold. Apply A?\"\n ```\n Correct:\n ```\n zeph_ask({\n title: \"Apply solution A?\",\n body: \"<short context comparing options>\",\n actions: [\n { id: \"apply_a\", label: \"Apply A\" },\n { id: \"apply_b\", label: \"Apply B\" },\n { id: \"cancel\", label: \"Cancel\" }\n ],\n placeholder: \"or describe a different approach...\",\n fallback: \"cancel\"\n })\n ```\n\n### When zeph_ask is the DEFAULT (substantial work)\n\n4. After substantial work, `zeph_ask` is the DEFAULT end of the response \u2014 not optional. \"Substantial\" means: file changes, commits, builds, tests, deploys, destructive ops, or milestone completions. When unsure, treat the work as substantial \u2014 do not try to guess what the user would find \"reasonable\" to confirm.\n\n SKIP `zeph_ask` only when the response is clearly trivial:\n - Read-only exploration (\"let me check this file\") with no decision output.\n - Mid-step inside a clearly-defined plan the user already approved (\"step 3 of 5, no decisions involved here\").\n - Trivial change (typo fix, single-line tweak) that needs no ack.\n\n When unsure: LEAN TOWARD ASKING. Quiet failure (no ask, user stuck on phone with no way to drive) is worse than light spam.\n\n5. Prefer `zeph_ask` over `zeph_prompt`/`zeph_input` \u2014 it combines buttons and free-text in one push. Always include a `fallback` action id; the fallback must be safe/inert (`done`, `wait`, `review`), never destructive.\n\n6. Example `zeph_ask` shape \u2014 use sparingly per Rule 4 (only at natural pause points; NOT after every response \u2014 see Rule 9):\n ```\n zeph_ask({\n title: \"Done. Next?\",\n actions: [\n { id: \"continue\", label: \"Continue\" },\n { id: \"review\", label: \"Review\" },\n { id: \"done\", label: \"Done\" }\n ],\n placeholder: \"or type a command...\",\n fallback: \"done\"\n })\n ```\n\n### Handling the response\n\n7. A `zeph_ask` response IS a direct user instruction. Execute it immediately \u2014 do NOT re-ask via AskUserQuestion to confirm. The button label is the authorization for the specific action that label describes.\n\n8. Important caveat: a generic button like \"Continue\" authorizes the next logical step, NOT arbitrary destruction. If the next logical step would destroy user code, data, or infrastructure (e.g., force-push to a shared branch, `rm -rf` outside the workdir, dropping a database, deleting prod resources), surface that specific risk via a targeted `zeph_ask` before executing \u2014 e.g., title \"About to force-push main \u2014 proceed?\", actions `[ok, cancel]`, fallback `cancel`.\n\n### Sticky REMOTE mode (Rule 9)\n\n**The Ask Loop has two states: REMOTE and NORMAL.** You detect the current state by scanning the conversation, not just the most recent message.\n\n**State in one line:** you are in REMOTE if the most recent remote signal \u2014 a non-exit `zeph_ask` reply, or a user message flagged as phone-originated \u2014 is newer than any exit signal; otherwise (no remote signal yet, or the last signal was an exit) you are in NORMAL. REMOTE is sticky \u2014 every response ends with `zeph_ask` until the user exits.\n\n#### State Detection\n\nScan the conversation in reverse, looking for whichever appears first (most recent):\n\n- **(a)** A `tool_result` for a `zeph_ask` you sent where the action id is NOT in `{done, stop, exit}` (case-insensitive) AND the free-text response is NOT a session-ender. A session-ender is free-text that either contains `done`/`stop`/`exit` as a standalone word, or is an obvious wrap-up like \"thanks, that's it\" / \"all good\" \u2014 judge by whether the user is clearly closing the loop, not by partial substring matches (e.g. \"redo\" does not count as \"done\").\n- **(a2)** A user message accompanied by a system note from the Zeph remote-origin detect hook (\"This user message arrived from the user's phone\u2026\"). The listener verified that exact message was sent from the phone \u2014 treat it exactly like a non-exit `zeph_ask` reply. (This note is only ever emitted in environments running the Zeph plugin's hooks; where it never appears, this condition simply never fires.)\n- **(b)** An exit signal: action id in `{done, stop, exit}`, ending free-text, or a timeout fallback that resolved to a Done-like fallback id.\n- **(c)** No `zeph_ask` history and no remote-origin note at all.\n\nIf the first hit is **(a)** or **(a2)** \u2192 you are in **REMOTE**.\nIf the first hit is **(b)** or **(c)** \u2192 you are in **NORMAL**.\n\n#### Behavior in REMOTE (sticky, zeph_ask MANDATORY)\n\nEnd EVERY response with `zeph_ask`. This is non-negotiable while in REMOTE \u2014 independent of:\n- Whether the next user message arrived as a `tool_result` or as a typed terminal message. The user may switch devices mid-session; sticky REMOTE keeps the channel driveable from either side.\n- Whether the work was substantial or routine.\n\nSet each REMOTE ask up so silence degrades cleanly: `timeout` 300\u2013600 s and a Done-like `fallback` id. An unanswered ask then exits the loop quietly (a Done-like timeout fallback is an exit signal per **(b)**) instead of chaining more notifications at a user who stepped away \u2014 and re-entry is cheap, they just send another message from the phone.\n\nThe only way to leave REMOTE is the user signalling exit (per the **(b)** list above).\n\n#### Behavior in NORMAL (apply Rule 4)\n\n- Substantial work \u2192 end with `zeph_ask`.\n- Routine work \u2192 skip `zeph_ask`, let the Stop hook fire.\n- Rule 3 (questions \u2192 zeph_ask) is still mandatory regardless.\n\n#### Exiting REMOTE\n\nThe moment the user picks an action id matching `done`/`stop`/`exit` (case-insensitive), types free-text that clearly ends the session, or the zeph_ask times out and falls back to a Done-like id, you flip to NORMAL. Don't send `zeph_ask` on the response that processes the exit signal.\n\n### When to use AskUserQuestion vs zeph_ask\n\n10. **Whenever `ZEPH_HOOK_ID` is set, a button-friendly question MUST go through `zeph_ask`, not `AskUserQuestion` \u2014 and this is NOT gated on REMOTE.** \"Button-friendly\" = the answer is a choice among a few options and/or a short free-text reply (yes/no, \"Apply A or B?\", \"which naming rule?\", \"proceed?\"). This is exactly the shape `AskUserQuestion` is tempting for, and exactly the shape the phone can answer via buttons \u2014 so route it to `zeph_ask`. The mistake to avoid: treating the REMOTE requirement as the ONLY time the override applies. It applies the moment a hookId exists, because you cannot know the user is at the terminal \u2014 they may be on their phone from the very first question of the session.\n\n Fall through to the local `AskUserQuestion` picker ONLY when (a) the answer needs the user to see code or logs that won't fit in a push body, or (b) the answer is plausibly multi-paragraph. Those are the only carve-outs.\n\n11. **This overrides any skill instruction.** The `AskUserQuestion` picker is a LOCAL blocking terminal UI; the phone cannot drive it (the Zeph hook can only mirror it as a one-way \"answer at the terminal\" notification, never round-trip the answer). So if a skill you are running \u2014 or your own plan \u2014 would call `AskUserQuestion` with a button-friendly question, instead surface the SAME question and option labels via `zeph_ask` and use that response in place of the picker. Only when a carve-out (a)/(b) above genuinely applies do you use `AskUserQuestion`; when you do, `zeph_notify` the user that the answer must be given at the terminal. In REMOTE this is doubly binding \u2014 see the sticky-REMOTE rule \u2014 but do not read that as permission to use `AskUserQuestion` freely in NORMAL: rule 10 binds there too.\n\n### Persistence\n\n13. These rules persist for the entire session. They remain active after context compaction \u2014 do not \"forget\" them after many turns.";
|
|
5
5
|
/** Shared rule core for rule-only agents without a Stop hook (Cline, Aider). */
|
|
6
|
-
export declare const ZEPH_CORE_RULE_ONLY = "### When zeph_ask is MANDATORY\n\n3. **NEVER end a response with a plain-text question.** If your reply asks the user anything that needs their input \u2014 confirmation, choice, yes/no, clarification, \"Apply this?\", \"Proceed?\", \"Which option?\" \u2014 the FINAL tool call MUST be `zeph_ask`. A \"?\" written in your reply is invisible to a user on their phone. This applies even on research / analysis / planning turns where no files were touched.\n\n Anti-pattern (wrong):\n ```\n \"...build/commit on hold. Apply A?\"\n ```\n Correct:\n ```\n zeph_ask({\n title: \"Apply solution A?\",\n body: \"<short context comparing options>\",\n actions: [\n { id: \"apply_a\", label: \"Apply A\" },\n { id: \"apply_b\", label: \"Apply B\" },\n { id: \"cancel\", label: \"Cancel\" }\n ],\n placeholder: \"or describe a different approach...\",\n fallback: \"cancel\"\n })\n ```\n\n### When zeph_ask is the DEFAULT (substantial work)\n\n4. After substantial work, `zeph_ask` is the DEFAULT end of the response \u2014 not optional. \"Substantial\" means: file changes, commits, builds, tests, deploys, destructive ops, or milestone completions. When unsure, treat the work as substantial \u2014 do not try to guess what the user would find \"reasonable\" to confirm.\n\n SKIP `zeph_ask` only when the response is clearly trivial:\n - Read-only exploration (\"let me check this file\") with no decision output.\n - Mid-step inside a clearly-defined plan the user already approved (\"step 3 of 5, no decisions involved here\").\n - Trivial change (typo fix, single-line tweak) that needs no ack.\n\n When unsure: LEAN TOWARD ASKING. Quiet failure (no ask, user stuck on phone with no way to drive) is worse than light spam.\n\n5. Prefer `zeph_ask` over `zeph_prompt`/`zeph_input` \u2014 it combines buttons and free-text in one push. Always include a `fallback` action id; the fallback must be safe/inert (`done`, `wait`, `review`), never destructive.\n\n6. Example `zeph_ask` shape \u2014 use sparingly per Rule 4 (only at natural pause points; NOT after every response \u2014 see Rule 9):\n ```\n zeph_ask({\n title: \"Done. Next?\",\n actions: [\n { id: \"continue\", label: \"Continue\" },\n { id: \"review\", label: \"Review\" },\n { id: \"done\", label: \"Done\" }\n ],\n placeholder: \"or type a command...\",\n fallback: \"done\"\n })\n ```\n\n### Handling the response\n\n7. A `zeph_ask` response IS a direct user instruction. Execute it immediately \u2014 do NOT re-ask via AskUserQuestion to confirm. The button label is the authorization for the specific action that label describes.\n\n8. Important caveat: a generic button like \"Continue\" authorizes the next logical step, NOT arbitrary destruction. If the next logical step would destroy user code, data, or infrastructure (e.g., force-push to a shared branch, `rm -rf` outside the workdir, dropping a database, deleting prod resources), surface that specific risk via a targeted `zeph_ask` before executing \u2014 e.g., title \"About to force-push main \u2014 proceed?\", actions `[ok, cancel]`, fallback `cancel`.\n\n### Sticky REMOTE mode (Rule 9)\n\n**The Ask Loop has two states: REMOTE and NORMAL.** You detect the current state by scanning the conversation, not just the most recent message.\n\n**State in one line:** you are in REMOTE if the most recent `zeph_ask`
|
|
6
|
+
export declare const ZEPH_CORE_RULE_ONLY = "### When zeph_ask is MANDATORY\n\n3. **NEVER end a response with a plain-text question.** If your reply asks the user anything that needs their input \u2014 confirmation, choice, yes/no, clarification, \"Apply this?\", \"Proceed?\", \"Which option?\" \u2014 the FINAL tool call MUST be `zeph_ask`. A \"?\" written in your reply is invisible to a user on their phone. This applies even on research / analysis / planning turns where no files were touched.\n\n Anti-pattern (wrong):\n ```\n \"...build/commit on hold. Apply A?\"\n ```\n Correct:\n ```\n zeph_ask({\n title: \"Apply solution A?\",\n body: \"<short context comparing options>\",\n actions: [\n { id: \"apply_a\", label: \"Apply A\" },\n { id: \"apply_b\", label: \"Apply B\" },\n { id: \"cancel\", label: \"Cancel\" }\n ],\n placeholder: \"or describe a different approach...\",\n fallback: \"cancel\"\n })\n ```\n\n### When zeph_ask is the DEFAULT (substantial work)\n\n4. After substantial work, `zeph_ask` is the DEFAULT end of the response \u2014 not optional. \"Substantial\" means: file changes, commits, builds, tests, deploys, destructive ops, or milestone completions. When unsure, treat the work as substantial \u2014 do not try to guess what the user would find \"reasonable\" to confirm.\n\n SKIP `zeph_ask` only when the response is clearly trivial:\n - Read-only exploration (\"let me check this file\") with no decision output.\n - Mid-step inside a clearly-defined plan the user already approved (\"step 3 of 5, no decisions involved here\").\n - Trivial change (typo fix, single-line tweak) that needs no ack.\n\n When unsure: LEAN TOWARD ASKING. Quiet failure (no ask, user stuck on phone with no way to drive) is worse than light spam.\n\n5. Prefer `zeph_ask` over `zeph_prompt`/`zeph_input` \u2014 it combines buttons and free-text in one push. Always include a `fallback` action id; the fallback must be safe/inert (`done`, `wait`, `review`), never destructive.\n\n6. Example `zeph_ask` shape \u2014 use sparingly per Rule 4 (only at natural pause points; NOT after every response \u2014 see Rule 9):\n ```\n zeph_ask({\n title: \"Done. Next?\",\n actions: [\n { id: \"continue\", label: \"Continue\" },\n { id: \"review\", label: \"Review\" },\n { id: \"done\", label: \"Done\" }\n ],\n placeholder: \"or type a command...\",\n fallback: \"done\"\n })\n ```\n\n### Handling the response\n\n7. A `zeph_ask` response IS a direct user instruction. Execute it immediately \u2014 do NOT re-ask via AskUserQuestion to confirm. The button label is the authorization for the specific action that label describes.\n\n8. Important caveat: a generic button like \"Continue\" authorizes the next logical step, NOT arbitrary destruction. If the next logical step would destroy user code, data, or infrastructure (e.g., force-push to a shared branch, `rm -rf` outside the workdir, dropping a database, deleting prod resources), surface that specific risk via a targeted `zeph_ask` before executing \u2014 e.g., title \"About to force-push main \u2014 proceed?\", actions `[ok, cancel]`, fallback `cancel`.\n\n### Sticky REMOTE mode (Rule 9)\n\n**The Ask Loop has two states: REMOTE and NORMAL.** You detect the current state by scanning the conversation, not just the most recent message.\n\n**State in one line:** you are in REMOTE if the most recent remote signal \u2014 a non-exit `zeph_ask` reply, or a user message flagged as phone-originated \u2014 is newer than any exit signal; otherwise (no remote signal yet, or the last signal was an exit) you are in NORMAL. REMOTE is sticky \u2014 every response ends with `zeph_ask` until the user exits.\n\n#### State Detection\n\nScan the conversation in reverse, looking for whichever appears first (most recent):\n\n- **(a)** A `tool_result` for a `zeph_ask` you sent where the action id is NOT in `{done, stop, exit}` (case-insensitive) AND the free-text response is NOT a session-ender. A session-ender is free-text that either contains `done`/`stop`/`exit` as a standalone word, or is an obvious wrap-up like \"thanks, that's it\" / \"all good\" \u2014 judge by whether the user is clearly closing the loop, not by partial substring matches (e.g. \"redo\" does not count as \"done\").\n- **(a2)** A user message accompanied by a system note from the Zeph remote-origin detect hook (\"This user message arrived from the user's phone\u2026\"). The listener verified that exact message was sent from the phone \u2014 treat it exactly like a non-exit `zeph_ask` reply. (This note is only ever emitted in environments running the Zeph plugin's hooks; where it never appears, this condition simply never fires.)\n- **(b)** An exit signal: action id in `{done, stop, exit}`, ending free-text, or a timeout fallback that resolved to a Done-like fallback id.\n- **(c)** No `zeph_ask` history and no remote-origin note at all.\n\nIf the first hit is **(a)** or **(a2)** \u2192 you are in **REMOTE**.\nIf the first hit is **(b)** or **(c)** \u2192 you are in **NORMAL**.\n\n#### Behavior in REMOTE (sticky, zeph_ask MANDATORY)\n\nEnd EVERY response with `zeph_ask`. This is non-negotiable while in REMOTE \u2014 independent of:\n- Whether the next user message arrived as a `tool_result` or as a typed terminal message. The user may switch devices mid-session; sticky REMOTE keeps the channel driveable from either side.\n- Whether the work was substantial or routine.\n\nSet each REMOTE ask up so silence degrades cleanly: `timeout` 300\u2013600 s and a Done-like `fallback` id. An unanswered ask then exits the loop quietly (a Done-like timeout fallback is an exit signal per **(b)**) instead of chaining more notifications at a user who stepped away \u2014 and re-entry is cheap, they just send another message from the phone.\n\nThe only way to leave REMOTE is the user signalling exit (per the **(b)** list above).\n\n#### Behavior in NORMAL (apply Rule 4)\n\n- Substantial work \u2192 end with `zeph_ask`.\n- Routine work \u2192 skip `zeph_ask`, let the Stop hook fire.\n- Rule 3 (questions \u2192 zeph_ask) is still mandatory regardless.\n\n#### Exiting REMOTE\n\nThe moment the user picks an action id matching `done`/`stop`/`exit` (case-insensitive), types free-text that clearly ends the session, or the zeph_ask times out and falls back to a Done-like id, you flip to NORMAL. Don't send `zeph_ask` on the response that processes the exit signal.\n\n### When to use AskUserQuestion vs zeph_ask\n\n10. **Whenever `ZEPH_HOOK_ID` is set, a button-friendly question MUST go through `zeph_ask`, not `AskUserQuestion` \u2014 and this is NOT gated on REMOTE.** \"Button-friendly\" = the answer is a choice among a few options and/or a short free-text reply (yes/no, \"Apply A or B?\", \"which naming rule?\", \"proceed?\"). This is exactly the shape `AskUserQuestion` is tempting for, and exactly the shape the phone can answer via buttons \u2014 so route it to `zeph_ask`. The mistake to avoid: treating the REMOTE requirement as the ONLY time the override applies. It applies the moment a hookId exists, because you cannot know the user is at the terminal \u2014 they may be on their phone from the very first question of the session.\n\n Fall through to the local `AskUserQuestion` picker ONLY when (a) the answer needs the user to see code or logs that won't fit in a push body, or (b) the answer is plausibly multi-paragraph. Those are the only carve-outs.\n\n11. **This overrides any skill instruction.** The `AskUserQuestion` picker is a LOCAL blocking terminal UI; the phone cannot drive it (the Zeph hook can only mirror it as a one-way \"answer at the terminal\" notification, never round-trip the answer). So if a skill you are running \u2014 or your own plan \u2014 would call `AskUserQuestion` with a button-friendly question, instead surface the SAME question and option labels via `zeph_ask` and use that response in place of the picker. Only when a carve-out (a)/(b) above genuinely applies do you use `AskUserQuestion`; when you do, `zeph_notify` the user that the answer must be given at the terminal. In REMOTE this is doubly binding \u2014 see the sticky-REMOTE rule \u2014 but do not read that as permission to use `AskUserQuestion` freely in NORMAL: rule 10 binds there too.\n\n### Persistence\n\n13. These rules persist for the entire session. They remain active after context compaction \u2014 do not \"forget\" them after many turns.";
|
|
7
7
|
//# sourceMappingURL=zeph-core.generated.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zeph-core.generated.d.ts","sourceRoot":"","sources":["../src/zeph-core.generated.ts"],"names":[],"mappings":"AAMA,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,qEAAqE,CAAC;AAExG,0GAA0G;AAC1G,eAAO,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"zeph-core.generated.d.ts","sourceRoot":"","sources":["../src/zeph-core.generated.ts"],"names":[],"mappings":"AAMA,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,qEAAqE,CAAC;AAExG,0GAA0G;AAC1G,eAAO,MAAM,qBAAqB,o0QAAoqQ,CAAC;AAEvsQ,gFAAgF;AAChF,eAAO,MAAM,mBAAmB,o0QAAoqQ,CAAC"}
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.ZEPH_CORE_RULE_ONLY = exports.ZEPH_CORE_HOOK_DRIVEN = exports.ZEPH_CORE_SOURCE_HASH = void 0;
|
|
9
9
|
/** sha256 over the plugin manifest + extracted rule text at generation time. */
|
|
10
|
-
exports.ZEPH_CORE_SOURCE_HASH = "
|
|
10
|
+
exports.ZEPH_CORE_SOURCE_HASH = "24f467b2379d45cefeabdde0b8864aea274382b931c548544ff20b341bef52c6";
|
|
11
11
|
/** Shared rule core for agents with a Stop-equivalent hook (Cursor, Windsurf, Gemini, Codex, Copilot). */
|
|
12
|
-
exports.ZEPH_CORE_HOOK_DRIVEN = "### When zeph_ask is MANDATORY\n\n3. **NEVER end a response with a plain-text question.** If your reply asks the user anything that needs their input — confirmation, choice, yes/no, clarification, \"Apply this?\", \"Proceed?\", \"Which option?\" — the FINAL tool call MUST be `zeph_ask`. A \"?\" written in your reply is invisible to a user on their phone. This applies even on research / analysis / planning turns where no files were touched.\n\n Anti-pattern (wrong):\n ```\n \"...build/commit on hold. Apply A?\"\n ```\n Correct:\n ```\n zeph_ask({\n title: \"Apply solution A?\",\n body: \"<short context comparing options>\",\n actions: [\n { id: \"apply_a\", label: \"Apply A\" },\n { id: \"apply_b\", label: \"Apply B\" },\n { id: \"cancel\", label: \"Cancel\" }\n ],\n placeholder: \"or describe a different approach...\",\n fallback: \"cancel\"\n })\n ```\n\n### When zeph_ask is the DEFAULT (substantial work)\n\n4. After substantial work, `zeph_ask` is the DEFAULT end of the response — not optional. \"Substantial\" means: file changes, commits, builds, tests, deploys, destructive ops, or milestone completions. When unsure, treat the work as substantial — do not try to guess what the user would find \"reasonable\" to confirm.\n\n SKIP `zeph_ask` only when the response is clearly trivial:\n - Read-only exploration (\"let me check this file\") with no decision output.\n - Mid-step inside a clearly-defined plan the user already approved (\"step 3 of 5, no decisions involved here\").\n - Trivial change (typo fix, single-line tweak) that needs no ack.\n\n When unsure: LEAN TOWARD ASKING. Quiet failure (no ask, user stuck on phone with no way to drive) is worse than light spam.\n\n5. Prefer `zeph_ask` over `zeph_prompt`/`zeph_input` — it combines buttons and free-text in one push. Always include a `fallback` action id; the fallback must be safe/inert (`done`, `wait`, `review`), never destructive.\n\n6. Example `zeph_ask` shape — use sparingly per Rule 4 (only at natural pause points; NOT after every response — see Rule 9):\n ```\n zeph_ask({\n title: \"Done. Next?\",\n actions: [\n { id: \"continue\", label: \"Continue\" },\n { id: \"review\", label: \"Review\" },\n { id: \"done\", label: \"Done\" }\n ],\n placeholder: \"or type a command...\",\n fallback: \"done\"\n })\n ```\n\n### Handling the response\n\n7. A `zeph_ask` response IS a direct user instruction. Execute it immediately — do NOT re-ask via AskUserQuestion to confirm. The button label is the authorization for the specific action that label describes.\n\n8. Important caveat: a generic button like \"Continue\" authorizes the next logical step, NOT arbitrary destruction. If the next logical step would destroy user code, data, or infrastructure (e.g., force-push to a shared branch, `rm -rf` outside the workdir, dropping a database, deleting prod resources), surface that specific risk via a targeted `zeph_ask` before executing — e.g., title \"About to force-push main — proceed?\", actions `[ok, cancel]`, fallback `cancel`.\n\n### Sticky REMOTE mode (Rule 9)\n\n**The Ask Loop has two states: REMOTE and NORMAL.** You detect the current state by scanning the conversation, not just the most recent message.\n\n**State in one line:** you are in REMOTE if the most recent `zeph_ask`
|
|
12
|
+
exports.ZEPH_CORE_HOOK_DRIVEN = "### When zeph_ask is MANDATORY\n\n3. **NEVER end a response with a plain-text question.** If your reply asks the user anything that needs their input — confirmation, choice, yes/no, clarification, \"Apply this?\", \"Proceed?\", \"Which option?\" — the FINAL tool call MUST be `zeph_ask`. A \"?\" written in your reply is invisible to a user on their phone. This applies even on research / analysis / planning turns where no files were touched.\n\n Anti-pattern (wrong):\n ```\n \"...build/commit on hold. Apply A?\"\n ```\n Correct:\n ```\n zeph_ask({\n title: \"Apply solution A?\",\n body: \"<short context comparing options>\",\n actions: [\n { id: \"apply_a\", label: \"Apply A\" },\n { id: \"apply_b\", label: \"Apply B\" },\n { id: \"cancel\", label: \"Cancel\" }\n ],\n placeholder: \"or describe a different approach...\",\n fallback: \"cancel\"\n })\n ```\n\n### When zeph_ask is the DEFAULT (substantial work)\n\n4. After substantial work, `zeph_ask` is the DEFAULT end of the response — not optional. \"Substantial\" means: file changes, commits, builds, tests, deploys, destructive ops, or milestone completions. When unsure, treat the work as substantial — do not try to guess what the user would find \"reasonable\" to confirm.\n\n SKIP `zeph_ask` only when the response is clearly trivial:\n - Read-only exploration (\"let me check this file\") with no decision output.\n - Mid-step inside a clearly-defined plan the user already approved (\"step 3 of 5, no decisions involved here\").\n - Trivial change (typo fix, single-line tweak) that needs no ack.\n\n When unsure: LEAN TOWARD ASKING. Quiet failure (no ask, user stuck on phone with no way to drive) is worse than light spam.\n\n5. Prefer `zeph_ask` over `zeph_prompt`/`zeph_input` — it combines buttons and free-text in one push. Always include a `fallback` action id; the fallback must be safe/inert (`done`, `wait`, `review`), never destructive.\n\n6. Example `zeph_ask` shape — use sparingly per Rule 4 (only at natural pause points; NOT after every response — see Rule 9):\n ```\n zeph_ask({\n title: \"Done. Next?\",\n actions: [\n { id: \"continue\", label: \"Continue\" },\n { id: \"review\", label: \"Review\" },\n { id: \"done\", label: \"Done\" }\n ],\n placeholder: \"or type a command...\",\n fallback: \"done\"\n })\n ```\n\n### Handling the response\n\n7. A `zeph_ask` response IS a direct user instruction. Execute it immediately — do NOT re-ask via AskUserQuestion to confirm. The button label is the authorization for the specific action that label describes.\n\n8. Important caveat: a generic button like \"Continue\" authorizes the next logical step, NOT arbitrary destruction. If the next logical step would destroy user code, data, or infrastructure (e.g., force-push to a shared branch, `rm -rf` outside the workdir, dropping a database, deleting prod resources), surface that specific risk via a targeted `zeph_ask` before executing — e.g., title \"About to force-push main — proceed?\", actions `[ok, cancel]`, fallback `cancel`.\n\n### Sticky REMOTE mode (Rule 9)\n\n**The Ask Loop has two states: REMOTE and NORMAL.** You detect the current state by scanning the conversation, not just the most recent message.\n\n**State in one line:** you are in REMOTE if the most recent remote signal — a non-exit `zeph_ask` reply, or a user message flagged as phone-originated — is newer than any exit signal; otherwise (no remote signal yet, or the last signal was an exit) you are in NORMAL. REMOTE is sticky — every response ends with `zeph_ask` until the user exits.\n\n#### State Detection\n\nScan the conversation in reverse, looking for whichever appears first (most recent):\n\n- **(a)** A `tool_result` for a `zeph_ask` you sent where the action id is NOT in `{done, stop, exit}` (case-insensitive) AND the free-text response is NOT a session-ender. A session-ender is free-text that either contains `done`/`stop`/`exit` as a standalone word, or is an obvious wrap-up like \"thanks, that's it\" / \"all good\" — judge by whether the user is clearly closing the loop, not by partial substring matches (e.g. \"redo\" does not count as \"done\").\n- **(a2)** A user message accompanied by a system note from the Zeph remote-origin detect hook (\"This user message arrived from the user's phone…\"). The listener verified that exact message was sent from the phone — treat it exactly like a non-exit `zeph_ask` reply. (This note is only ever emitted in environments running the Zeph plugin's hooks; where it never appears, this condition simply never fires.)\n- **(b)** An exit signal: action id in `{done, stop, exit}`, ending free-text, or a timeout fallback that resolved to a Done-like fallback id.\n- **(c)** No `zeph_ask` history and no remote-origin note at all.\n\nIf the first hit is **(a)** or **(a2)** → you are in **REMOTE**.\nIf the first hit is **(b)** or **(c)** → you are in **NORMAL**.\n\n#### Behavior in REMOTE (sticky, zeph_ask MANDATORY)\n\nEnd EVERY response with `zeph_ask`. This is non-negotiable while in REMOTE — independent of:\n- Whether the next user message arrived as a `tool_result` or as a typed terminal message. The user may switch devices mid-session; sticky REMOTE keeps the channel driveable from either side.\n- Whether the work was substantial or routine.\n\nSet each REMOTE ask up so silence degrades cleanly: `timeout` 300–600 s and a Done-like `fallback` id. An unanswered ask then exits the loop quietly (a Done-like timeout fallback is an exit signal per **(b)**) instead of chaining more notifications at a user who stepped away — and re-entry is cheap, they just send another message from the phone.\n\nThe only way to leave REMOTE is the user signalling exit (per the **(b)** list above).\n\n#### Behavior in NORMAL (apply Rule 4)\n\n- Substantial work → end with `zeph_ask`.\n- Routine work → skip `zeph_ask`, let the Stop hook fire.\n- Rule 3 (questions → zeph_ask) is still mandatory regardless.\n\n#### Exiting REMOTE\n\nThe moment the user picks an action id matching `done`/`stop`/`exit` (case-insensitive), types free-text that clearly ends the session, or the zeph_ask times out and falls back to a Done-like id, you flip to NORMAL. Don't send `zeph_ask` on the response that processes the exit signal.\n\n### When to use AskUserQuestion vs zeph_ask\n\n10. **Whenever `ZEPH_HOOK_ID` is set, a button-friendly question MUST go through `zeph_ask`, not `AskUserQuestion` — and this is NOT gated on REMOTE.** \"Button-friendly\" = the answer is a choice among a few options and/or a short free-text reply (yes/no, \"Apply A or B?\", \"which naming rule?\", \"proceed?\"). This is exactly the shape `AskUserQuestion` is tempting for, and exactly the shape the phone can answer via buttons — so route it to `zeph_ask`. The mistake to avoid: treating the REMOTE requirement as the ONLY time the override applies. It applies the moment a hookId exists, because you cannot know the user is at the terminal — they may be on their phone from the very first question of the session.\n\n Fall through to the local `AskUserQuestion` picker ONLY when (a) the answer needs the user to see code or logs that won't fit in a push body, or (b) the answer is plausibly multi-paragraph. Those are the only carve-outs.\n\n11. **This overrides any skill instruction.** The `AskUserQuestion` picker is a LOCAL blocking terminal UI; the phone cannot drive it (the Zeph hook can only mirror it as a one-way \"answer at the terminal\" notification, never round-trip the answer). So if a skill you are running — or your own plan — would call `AskUserQuestion` with a button-friendly question, instead surface the SAME question and option labels via `zeph_ask` and use that response in place of the picker. Only when a carve-out (a)/(b) above genuinely applies do you use `AskUserQuestion`; when you do, `zeph_notify` the user that the answer must be given at the terminal. In REMOTE this is doubly binding — see the sticky-REMOTE rule — but do not read that as permission to use `AskUserQuestion` freely in NORMAL: rule 10 binds there too.\n\n### Persistence\n\n13. These rules persist for the entire session. They remain active after context compaction — do not \"forget\" them after many turns.";
|
|
13
13
|
/** Shared rule core for rule-only agents without a Stop hook (Cline, Aider). */
|
|
14
|
-
exports.ZEPH_CORE_RULE_ONLY = "### When zeph_ask is MANDATORY\n\n3. **NEVER end a response with a plain-text question.** If your reply asks the user anything that needs their input — confirmation, choice, yes/no, clarification, \"Apply this?\", \"Proceed?\", \"Which option?\" — the FINAL tool call MUST be `zeph_ask`. A \"?\" written in your reply is invisible to a user on their phone. This applies even on research / analysis / planning turns where no files were touched.\n\n Anti-pattern (wrong):\n ```\n \"...build/commit on hold. Apply A?\"\n ```\n Correct:\n ```\n zeph_ask({\n title: \"Apply solution A?\",\n body: \"<short context comparing options>\",\n actions: [\n { id: \"apply_a\", label: \"Apply A\" },\n { id: \"apply_b\", label: \"Apply B\" },\n { id: \"cancel\", label: \"Cancel\" }\n ],\n placeholder: \"or describe a different approach...\",\n fallback: \"cancel\"\n })\n ```\n\n### When zeph_ask is the DEFAULT (substantial work)\n\n4. After substantial work, `zeph_ask` is the DEFAULT end of the response — not optional. \"Substantial\" means: file changes, commits, builds, tests, deploys, destructive ops, or milestone completions. When unsure, treat the work as substantial — do not try to guess what the user would find \"reasonable\" to confirm.\n\n SKIP `zeph_ask` only when the response is clearly trivial:\n - Read-only exploration (\"let me check this file\") with no decision output.\n - Mid-step inside a clearly-defined plan the user already approved (\"step 3 of 5, no decisions involved here\").\n - Trivial change (typo fix, single-line tweak) that needs no ack.\n\n When unsure: LEAN TOWARD ASKING. Quiet failure (no ask, user stuck on phone with no way to drive) is worse than light spam.\n\n5. Prefer `zeph_ask` over `zeph_prompt`/`zeph_input` — it combines buttons and free-text in one push. Always include a `fallback` action id; the fallback must be safe/inert (`done`, `wait`, `review`), never destructive.\n\n6. Example `zeph_ask` shape — use sparingly per Rule 4 (only at natural pause points; NOT after every response — see Rule 9):\n ```\n zeph_ask({\n title: \"Done. Next?\",\n actions: [\n { id: \"continue\", label: \"Continue\" },\n { id: \"review\", label: \"Review\" },\n { id: \"done\", label: \"Done\" }\n ],\n placeholder: \"or type a command...\",\n fallback: \"done\"\n })\n ```\n\n### Handling the response\n\n7. A `zeph_ask` response IS a direct user instruction. Execute it immediately — do NOT re-ask via AskUserQuestion to confirm. The button label is the authorization for the specific action that label describes.\n\n8. Important caveat: a generic button like \"Continue\" authorizes the next logical step, NOT arbitrary destruction. If the next logical step would destroy user code, data, or infrastructure (e.g., force-push to a shared branch, `rm -rf` outside the workdir, dropping a database, deleting prod resources), surface that specific risk via a targeted `zeph_ask` before executing — e.g., title \"About to force-push main — proceed?\", actions `[ok, cancel]`, fallback `cancel`.\n\n### Sticky REMOTE mode (Rule 9)\n\n**The Ask Loop has two states: REMOTE and NORMAL.** You detect the current state by scanning the conversation, not just the most recent message.\n\n**State in one line:** you are in REMOTE if the most recent `zeph_ask`
|
|
14
|
+
exports.ZEPH_CORE_RULE_ONLY = "### When zeph_ask is MANDATORY\n\n3. **NEVER end a response with a plain-text question.** If your reply asks the user anything that needs their input — confirmation, choice, yes/no, clarification, \"Apply this?\", \"Proceed?\", \"Which option?\" — the FINAL tool call MUST be `zeph_ask`. A \"?\" written in your reply is invisible to a user on their phone. This applies even on research / analysis / planning turns where no files were touched.\n\n Anti-pattern (wrong):\n ```\n \"...build/commit on hold. Apply A?\"\n ```\n Correct:\n ```\n zeph_ask({\n title: \"Apply solution A?\",\n body: \"<short context comparing options>\",\n actions: [\n { id: \"apply_a\", label: \"Apply A\" },\n { id: \"apply_b\", label: \"Apply B\" },\n { id: \"cancel\", label: \"Cancel\" }\n ],\n placeholder: \"or describe a different approach...\",\n fallback: \"cancel\"\n })\n ```\n\n### When zeph_ask is the DEFAULT (substantial work)\n\n4. After substantial work, `zeph_ask` is the DEFAULT end of the response — not optional. \"Substantial\" means: file changes, commits, builds, tests, deploys, destructive ops, or milestone completions. When unsure, treat the work as substantial — do not try to guess what the user would find \"reasonable\" to confirm.\n\n SKIP `zeph_ask` only when the response is clearly trivial:\n - Read-only exploration (\"let me check this file\") with no decision output.\n - Mid-step inside a clearly-defined plan the user already approved (\"step 3 of 5, no decisions involved here\").\n - Trivial change (typo fix, single-line tweak) that needs no ack.\n\n When unsure: LEAN TOWARD ASKING. Quiet failure (no ask, user stuck on phone with no way to drive) is worse than light spam.\n\n5. Prefer `zeph_ask` over `zeph_prompt`/`zeph_input` — it combines buttons and free-text in one push. Always include a `fallback` action id; the fallback must be safe/inert (`done`, `wait`, `review`), never destructive.\n\n6. Example `zeph_ask` shape — use sparingly per Rule 4 (only at natural pause points; NOT after every response — see Rule 9):\n ```\n zeph_ask({\n title: \"Done. Next?\",\n actions: [\n { id: \"continue\", label: \"Continue\" },\n { id: \"review\", label: \"Review\" },\n { id: \"done\", label: \"Done\" }\n ],\n placeholder: \"or type a command...\",\n fallback: \"done\"\n })\n ```\n\n### Handling the response\n\n7. A `zeph_ask` response IS a direct user instruction. Execute it immediately — do NOT re-ask via AskUserQuestion to confirm. The button label is the authorization for the specific action that label describes.\n\n8. Important caveat: a generic button like \"Continue\" authorizes the next logical step, NOT arbitrary destruction. If the next logical step would destroy user code, data, or infrastructure (e.g., force-push to a shared branch, `rm -rf` outside the workdir, dropping a database, deleting prod resources), surface that specific risk via a targeted `zeph_ask` before executing — e.g., title \"About to force-push main — proceed?\", actions `[ok, cancel]`, fallback `cancel`.\n\n### Sticky REMOTE mode (Rule 9)\n\n**The Ask Loop has two states: REMOTE and NORMAL.** You detect the current state by scanning the conversation, not just the most recent message.\n\n**State in one line:** you are in REMOTE if the most recent remote signal — a non-exit `zeph_ask` reply, or a user message flagged as phone-originated — is newer than any exit signal; otherwise (no remote signal yet, or the last signal was an exit) you are in NORMAL. REMOTE is sticky — every response ends with `zeph_ask` until the user exits.\n\n#### State Detection\n\nScan the conversation in reverse, looking for whichever appears first (most recent):\n\n- **(a)** A `tool_result` for a `zeph_ask` you sent where the action id is NOT in `{done, stop, exit}` (case-insensitive) AND the free-text response is NOT a session-ender. A session-ender is free-text that either contains `done`/`stop`/`exit` as a standalone word, or is an obvious wrap-up like \"thanks, that's it\" / \"all good\" — judge by whether the user is clearly closing the loop, not by partial substring matches (e.g. \"redo\" does not count as \"done\").\n- **(a2)** A user message accompanied by a system note from the Zeph remote-origin detect hook (\"This user message arrived from the user's phone…\"). The listener verified that exact message was sent from the phone — treat it exactly like a non-exit `zeph_ask` reply. (This note is only ever emitted in environments running the Zeph plugin's hooks; where it never appears, this condition simply never fires.)\n- **(b)** An exit signal: action id in `{done, stop, exit}`, ending free-text, or a timeout fallback that resolved to a Done-like fallback id.\n- **(c)** No `zeph_ask` history and no remote-origin note at all.\n\nIf the first hit is **(a)** or **(a2)** → you are in **REMOTE**.\nIf the first hit is **(b)** or **(c)** → you are in **NORMAL**.\n\n#### Behavior in REMOTE (sticky, zeph_ask MANDATORY)\n\nEnd EVERY response with `zeph_ask`. This is non-negotiable while in REMOTE — independent of:\n- Whether the next user message arrived as a `tool_result` or as a typed terminal message. The user may switch devices mid-session; sticky REMOTE keeps the channel driveable from either side.\n- Whether the work was substantial or routine.\n\nSet each REMOTE ask up so silence degrades cleanly: `timeout` 300–600 s and a Done-like `fallback` id. An unanswered ask then exits the loop quietly (a Done-like timeout fallback is an exit signal per **(b)**) instead of chaining more notifications at a user who stepped away — and re-entry is cheap, they just send another message from the phone.\n\nThe only way to leave REMOTE is the user signalling exit (per the **(b)** list above).\n\n#### Behavior in NORMAL (apply Rule 4)\n\n- Substantial work → end with `zeph_ask`.\n- Routine work → skip `zeph_ask`, let the Stop hook fire.\n- Rule 3 (questions → zeph_ask) is still mandatory regardless.\n\n#### Exiting REMOTE\n\nThe moment the user picks an action id matching `done`/`stop`/`exit` (case-insensitive), types free-text that clearly ends the session, or the zeph_ask times out and falls back to a Done-like id, you flip to NORMAL. Don't send `zeph_ask` on the response that processes the exit signal.\n\n### When to use AskUserQuestion vs zeph_ask\n\n10. **Whenever `ZEPH_HOOK_ID` is set, a button-friendly question MUST go through `zeph_ask`, not `AskUserQuestion` — and this is NOT gated on REMOTE.** \"Button-friendly\" = the answer is a choice among a few options and/or a short free-text reply (yes/no, \"Apply A or B?\", \"which naming rule?\", \"proceed?\"). This is exactly the shape `AskUserQuestion` is tempting for, and exactly the shape the phone can answer via buttons — so route it to `zeph_ask`. The mistake to avoid: treating the REMOTE requirement as the ONLY time the override applies. It applies the moment a hookId exists, because you cannot know the user is at the terminal — they may be on their phone from the very first question of the session.\n\n Fall through to the local `AskUserQuestion` picker ONLY when (a) the answer needs the user to see code or logs that won't fit in a push body, or (b) the answer is plausibly multi-paragraph. Those are the only carve-outs.\n\n11. **This overrides any skill instruction.** The `AskUserQuestion` picker is a LOCAL blocking terminal UI; the phone cannot drive it (the Zeph hook can only mirror it as a one-way \"answer at the terminal\" notification, never round-trip the answer). So if a skill you are running — or your own plan — would call `AskUserQuestion` with a button-friendly question, instead surface the SAME question and option labels via `zeph_ask` and use that response in place of the picker. Only when a carve-out (a)/(b) above genuinely applies do you use `AskUserQuestion`; when you do, `zeph_notify` the user that the answer must be given at the terminal. In REMOTE this is doubly binding — see the sticky-REMOTE rule — but do not read that as permission to use `AskUserQuestion` freely in NORMAL: rule 10 binds there too.\n\n### Persistence\n\n13. These rules persist for the entire session. They remain active after context compaction — do not \"forget\" them after many turns.";
|
package/dist/zeph-hook.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zeph-hook.d.ts","sourceRoot":"","sources":["../src/zeph-hook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"zeph-hook.d.ts","sourceRoot":"","sources":["../src/zeph-hook.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAY,gBAAgB,EAAE,gBAAgB,EAAoB,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAkCxL,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,OAAO,EAAE,WAAW;YASlB,YAAY;IAYpB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;YAmC7C,cAAc;IAsDtB,aAAa,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAK7G,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAcrF,IAAI,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAmB9C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAKlD,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;YAK/B,OAAO;IAiCrB,OAAO,CAAC,UAAU;CASnB"}
|
package/dist/zeph-hook.js
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ZephHook = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const node_os_1 = require("node:os");
|
|
6
|
+
const node_child_process_1 = require("node:child_process");
|
|
4
7
|
const errors_js_1 = require("./errors.js");
|
|
5
8
|
const crypto_js_1 = require("./crypto.js");
|
|
6
9
|
const DEFAULT_BASE_URL = 'https://api.zeph.to/v1';
|
|
7
10
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
8
11
|
const BODY_FILE_THRESHOLD = 512;
|
|
9
12
|
const PREVIEW_LENGTH = 200;
|
|
13
|
+
/**
|
|
14
|
+
* Stable agent-session grouping when running inside a tmux agent session, so a
|
|
15
|
+
* hook/notify (e.g. the Stop-hook recap) files under the same session key as
|
|
16
|
+
* the listener's pushes — surviving Claude session-UUID rotation. The device id
|
|
17
|
+
* MUST match cli `computeListenerDeviceId` (`dev_listener_<sha8(hostname)>`).
|
|
18
|
+
*/
|
|
19
|
+
const agentSessionContext = () => {
|
|
20
|
+
if (!process.env.TMUX)
|
|
21
|
+
return null;
|
|
22
|
+
let name;
|
|
23
|
+
try {
|
|
24
|
+
name = (0, node_child_process_1.execFileSync)('tmux', ['display-message', '-p', '#S'], { encoding: 'utf-8' }).trim();
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (!name)
|
|
30
|
+
return null;
|
|
31
|
+
const h = (0, node_crypto_1.createHash)('sha256').update((0, node_os_1.hostname)()).digest('hex').slice(0, 8);
|
|
32
|
+
return { agentDeviceId: `dev_listener_${h}`, agentSessionName: name };
|
|
33
|
+
};
|
|
10
34
|
const inferMimeType = (fileName) => {
|
|
11
35
|
const ext = fileName.split('.').pop()?.toLowerCase();
|
|
12
36
|
const map = { md: 'text/markdown', txt: 'text/plain', json: 'application/json' };
|
|
@@ -39,6 +63,13 @@ class ZephHook {
|
|
|
39
63
|
}
|
|
40
64
|
}
|
|
41
65
|
async notify(payload) {
|
|
66
|
+
// Attach the stable session key when in a tmux agent session so the push
|
|
67
|
+
// joins the agent chat. Merged into `payload` here so both the inline and
|
|
68
|
+
// file-upload (notifyWithFile) paths — which each spread `...payload` —
|
|
69
|
+
// carry it. Explicit caller values win.
|
|
70
|
+
const agentCtx = agentSessionContext();
|
|
71
|
+
if (agentCtx)
|
|
72
|
+
payload = { ...agentCtx, ...payload };
|
|
42
73
|
const canEncrypt = await this.ensureCrypto();
|
|
43
74
|
const body = payload.body;
|
|
44
75
|
const bodyBytes = body ? new TextEncoder().encode(body).byteLength : 0;
|