@zeph-to/cli 1.15.2 → 1.16.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.
|
@@ -8,6 +8,13 @@ export declare const RULES_REFRESH_INTERVAL_MS: number;
|
|
|
8
8
|
* back to bundled rules.
|
|
9
9
|
*/
|
|
10
10
|
export declare const validateManifest: (value: unknown) => DetectionManifest | null;
|
|
11
|
+
/**
|
|
12
|
+
* Segment-wise numeric compare of dotted date versions
|
|
13
|
+
* ("2026.07.04.3"). Plain string compare fails on ".10" vs ".9";
|
|
14
|
+
* non-numeric segments compare as equal so a malformed version can
|
|
15
|
+
* never crash the refresh path.
|
|
16
|
+
*/
|
|
17
|
+
export declare const compareManifestVersions: (a: string, b: string) => number;
|
|
11
18
|
export type ManifestSource = 'remote' | 'cache' | 'bundled';
|
|
12
19
|
export declare const getActiveManifest: () => DetectionManifest;
|
|
13
20
|
export declare const getActiveManifestSource: () => ManifestSource;
|
|
@@ -21,7 +28,7 @@ export declare const loadManifestFromCache: () => ManifestSource;
|
|
|
21
28
|
export declare const rulesUrl: () => string;
|
|
22
29
|
export interface RefreshResult {
|
|
23
30
|
source: ManifestSource;
|
|
24
|
-
/** 'updated' | 'not-modified' | 'invalid' | 'error' — for verbose logs. */
|
|
31
|
+
/** 'updated' | 'not-modified' | 'stale-ignored' | 'invalid' | 'error' — for verbose logs. */
|
|
25
32
|
outcome: string;
|
|
26
33
|
version?: string;
|
|
27
34
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-rules-fetch.d.ts","sourceRoot":"","sources":["../src/agent-rules-fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-rules-fetch.d.ts","sourceRoot":"","sources":["../src/agent-rules-fetch.ts"],"names":[],"mappings":"AAuBA,OAAO,EAEH,KAAK,iBAAiB,EACzB,MAAM,kBAAkB,CAAC;AAG1B,eAAO,MAAM,gBAAgB,QAAuC,CAAC;AACrE,eAAO,MAAM,yBAAyB,QAAqB,CAAC;AA6C5D;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,OAAO,KAAG,iBAAiB,GAAG,IAWrE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,MAU9D,CAAC;AAIF,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;AAK5D,eAAO,MAAM,iBAAiB,QAAO,iBAAmC,CAAC;AACzE,eAAO,MAAM,uBAAuB,QAAO,cAA8B,CAAC;AAS1E,iBAAiB;AACjB,eAAO,MAAM,mBAAmB,QAAO,IAEtC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAAO,cAWxC,CAAC;AAWF,eAAO,MAAM,QAAQ,QAAO,MAK3B,CAAC;AAEF,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,cAAc,CAAC;IACvB,6FAA6F;IAC7F,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAU,YAAW,OAAO,KAAa,KAAG,OAAO,CAAC,aAAa,CA4C5F,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.refreshManifest = exports.rulesUrl = exports.loadManifestFromCache = exports.resetActiveManifest = exports.getActiveManifestSource = exports.getActiveManifest = exports.validateManifest = exports.RULES_REFRESH_INTERVAL_MS = exports.RULES_CACHE_FILE = void 0;
|
|
3
|
+
exports.refreshManifest = exports.rulesUrl = exports.loadManifestFromCache = exports.resetActiveManifest = exports.getActiveManifestSource = exports.getActiveManifest = exports.compareManifestVersions = exports.validateManifest = exports.RULES_REFRESH_INTERVAL_MS = exports.RULES_CACHE_FILE = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* OTA delivery for agent detection rules (SPEC-AGENT-AWARENESS §S7).
|
|
6
6
|
*
|
|
@@ -12,6 +12,14 @@ exports.refreshManifest = exports.rulesUrl = exports.loadManifestFromCache = exp
|
|
|
12
12
|
* hostile payload can never leave the listener without rules, and
|
|
13
13
|
* `disabledRuleIds` in a fetched manifest acts as a same-day
|
|
14
14
|
* kill-switch for a misfiring rule (no release, no restart).
|
|
15
|
+
*
|
|
16
|
+
* Version precedence: a fetched/cached manifest only activates when
|
|
17
|
+
* its version is >= the bundled one. npm publishes land in minutes
|
|
18
|
+
* while the server manifest ships with a full deploy, so a fresh cli
|
|
19
|
+
* routinely carries NEWER rules than the endpoint — without the gate,
|
|
20
|
+
* the older remote manifest would shadow every bundled rule fix until
|
|
21
|
+
* the server caught up. Server-side rollback still works: the server
|
|
22
|
+
* bumps the version even when reverting rule content.
|
|
15
23
|
*/
|
|
16
24
|
const fs_1 = require("fs");
|
|
17
25
|
const path_1 = require("path");
|
|
@@ -90,6 +98,26 @@ const validateManifest = (value) => {
|
|
|
90
98
|
return value;
|
|
91
99
|
};
|
|
92
100
|
exports.validateManifest = validateManifest;
|
|
101
|
+
/**
|
|
102
|
+
* Segment-wise numeric compare of dotted date versions
|
|
103
|
+
* ("2026.07.04.3"). Plain string compare fails on ".10" vs ".9";
|
|
104
|
+
* non-numeric segments compare as equal so a malformed version can
|
|
105
|
+
* never crash the refresh path.
|
|
106
|
+
*/
|
|
107
|
+
const compareManifestVersions = (a, b) => {
|
|
108
|
+
const as = a.split('.').map(Number);
|
|
109
|
+
const bs = b.split('.').map(Number);
|
|
110
|
+
const len = Math.max(as.length, bs.length);
|
|
111
|
+
for (let i = 0; i < len; i++) {
|
|
112
|
+
const d = (as[i] ?? 0) - (bs[i] ?? 0);
|
|
113
|
+
if (Number.isNaN(d))
|
|
114
|
+
continue;
|
|
115
|
+
if (d !== 0)
|
|
116
|
+
return d < 0 ? -1 : 1;
|
|
117
|
+
}
|
|
118
|
+
return 0;
|
|
119
|
+
};
|
|
120
|
+
exports.compareManifestVersions = compareManifestVersions;
|
|
93
121
|
let activeManifest = agent_rules_default_js_1.DEFAULT_MANIFEST;
|
|
94
122
|
let activeSource = 'bundled';
|
|
95
123
|
const getActiveManifest = () => activeManifest;
|
|
@@ -115,7 +143,7 @@ const loadManifestFromCache = () => {
|
|
|
115
143
|
try {
|
|
116
144
|
const cache = JSON.parse((0, fs_1.readFileSync)(exports.RULES_CACHE_FILE, 'utf-8'));
|
|
117
145
|
const manifest = (0, exports.validateManifest)(cache.manifest);
|
|
118
|
-
if (manifest) {
|
|
146
|
+
if (manifest && (0, exports.compareManifestVersions)(manifest.version, agent_rules_default_js_1.DEFAULT_MANIFEST.version) >= 0) {
|
|
119
147
|
activateManifest(manifest, 'cache');
|
|
120
148
|
}
|
|
121
149
|
}
|
|
@@ -180,6 +208,12 @@ const refreshManifest = async (fetchImpl = fetch) => {
|
|
|
180
208
|
// Cache write failure is non-fatal: the manifest still
|
|
181
209
|
// activates for this process lifetime.
|
|
182
210
|
}
|
|
211
|
+
if ((0, exports.compareManifestVersions)(manifest.version, agent_rules_default_js_1.DEFAULT_MANIFEST.version) < 0) {
|
|
212
|
+
// Endpoint hasn't caught up to this build's bundled rules.
|
|
213
|
+
// Cache is still written above (the ETag stops refetch churn)
|
|
214
|
+
// but startup applies the same gate, so bundled stays active.
|
|
215
|
+
return { source: activeSource, outcome: 'stale-ignored', version: manifest.version };
|
|
216
|
+
}
|
|
183
217
|
activateManifest(manifest, 'remote');
|
|
184
218
|
return { source: 'remote', outcome: 'updated', version: manifest.version };
|
|
185
219
|
}
|
package/dist/listener.d.ts
CHANGED
|
@@ -45,6 +45,13 @@ export declare const AUTH_FAILURE_CODES: ReadonlySet<number>;
|
|
|
45
45
|
export declare const checkRateLimit: (session: string, now?: number) => boolean;
|
|
46
46
|
/** Read the foreground command in the named tmux session's active pane. */
|
|
47
47
|
export declare const paneCurrentCommand: (session: string) => string | null;
|
|
48
|
+
/**
|
|
49
|
+
* Translate a phone-supplied key list to tmux tokens. Returns null if ANY
|
|
50
|
+
* key is unknown — a partial injection (some keys land, one is dropped)
|
|
51
|
+
* leaves the pane in a worse mid-state than none, so the whole batch is
|
|
52
|
+
* rejected.
|
|
53
|
+
*/
|
|
54
|
+
export declare const resolveKeys: (keys: string[]) => string[] | null;
|
|
48
55
|
/**
|
|
49
56
|
* Mark the cached socket as no longer trustworthy — call this when a
|
|
50
57
|
* tmux command fails against the cached path. The next findTmuxSocket()
|
|
@@ -186,12 +193,16 @@ interface PushItem {
|
|
|
186
193
|
isEncrypted?: boolean;
|
|
187
194
|
/** Set when type='agent.command' — tmux session name to inject into. */
|
|
188
195
|
agentSessionName?: string;
|
|
196
|
+
/** Named keys (Esc/arrows/Enter) to inject instead of body text —
|
|
197
|
+
* drives full-screen modals the phone can't escape with text. */
|
|
198
|
+
keys?: string[];
|
|
189
199
|
/** Optional image/file attachments (agent.command only, plaintext). */
|
|
190
200
|
files?: PushFileAttachment[];
|
|
191
201
|
}
|
|
192
202
|
interface HandlePushDeps {
|
|
193
203
|
paneCommand?: (session: string) => string | null;
|
|
194
204
|
inject?: (session: string, text: string) => boolean;
|
|
205
|
+
sendKeys?: (session: string, tokens: string[]) => boolean;
|
|
195
206
|
rateLimit?: (session: string) => boolean;
|
|
196
207
|
now?: () => number;
|
|
197
208
|
/** Injectable for tests; defaults to the REST-backed downloader. */
|
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;AASH,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,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,kBAAkB,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAC5F;AAwDD,eAAO,MAAM,oBAAoB,GAAI,KAAK;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,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;AASF;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,GAAI,OAAM,MAAmB,KAAG,MAGnE,CAAC;AAwPF,eAAO,MAAM,cAAc,GAAU,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,KAAG,OAAO,CAAC,MAAM,CAoH3F,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.paneCurrentCommand = exports.checkRateLimit = exports.AUTH_FAILURE_CODES = void 0;
|
|
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;
|
|
29
29
|
const child_process_1 = require("child_process");
|
|
30
30
|
const crypto_1 = require("crypto");
|
|
31
31
|
const fs_1 = require("fs");
|
|
@@ -120,6 +120,45 @@ const injectKeys = (session, text) => {
|
|
|
120
120
|
const b = (0, child_process_1.spawnSync)('tmux', tmuxArgs(['send-keys', '-t', session, 'Enter']), { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
121
121
|
return b.status === 0;
|
|
122
122
|
};
|
|
123
|
+
// Named keys the phone may inject to drive a full-screen Claude Code pane
|
|
124
|
+
// (a `/usage` modal captures text input — only a real Escape/arrow gets out).
|
|
125
|
+
// Maps a lowercase wire name to the exact tmux key token. Whitelist-ONLY:
|
|
126
|
+
// anything outside this map is refused so a compromised sender can't smuggle
|
|
127
|
+
// `C-c`, `M-x`, or a shell command through send-keys' key-name syntax.
|
|
128
|
+
const ALLOWED_KEYS = {
|
|
129
|
+
escape: 'Escape',
|
|
130
|
+
up: 'Up',
|
|
131
|
+
down: 'Down',
|
|
132
|
+
left: 'Left',
|
|
133
|
+
right: 'Right',
|
|
134
|
+
enter: 'Enter',
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* Translate a phone-supplied key list to tmux tokens. Returns null if ANY
|
|
138
|
+
* key is unknown — a partial injection (some keys land, one is dropped)
|
|
139
|
+
* leaves the pane in a worse mid-state than none, so the whole batch is
|
|
140
|
+
* rejected.
|
|
141
|
+
*/
|
|
142
|
+
const resolveKeys = (keys) => {
|
|
143
|
+
const out = [];
|
|
144
|
+
for (const k of keys) {
|
|
145
|
+
const token = ALLOWED_KEYS[k.toLowerCase().trim()];
|
|
146
|
+
if (!token)
|
|
147
|
+
return null;
|
|
148
|
+
out.push(token);
|
|
149
|
+
}
|
|
150
|
+
return out.length ? out : null;
|
|
151
|
+
};
|
|
152
|
+
exports.resolveKeys = resolveKeys;
|
|
153
|
+
/**
|
|
154
|
+
* Send named keys as keys (NOT `-l`), so tmux interprets Escape/Up/Enter as
|
|
155
|
+
* key presses rather than literal text. One send-keys call carries the
|
|
156
|
+
* whole sequence in order.
|
|
157
|
+
*/
|
|
158
|
+
const injectNamedKeys = (session, tokens) => {
|
|
159
|
+
const r = (0, child_process_1.spawnSync)('tmux', tmuxArgs(['send-keys', '-t', session, ...tokens]), { stdio: ['ignore', 'ignore', 'pipe'] });
|
|
160
|
+
return r.status === 0;
|
|
161
|
+
};
|
|
123
162
|
const stamp = () => new Date().toISOString().slice(11, 19);
|
|
124
163
|
const log = (msg) => console.log(`[${stamp()}] ${msg}`);
|
|
125
164
|
// ─── tmux socket discovery ──────────────────────────────────────────
|
|
@@ -717,11 +756,7 @@ exports.collectSessions = collectSessions;
|
|
|
717
756
|
* the structured `agent.command` push type and the legacy `@<session>`
|
|
718
757
|
* prefix path route through here so the defense layers can't diverge.
|
|
719
758
|
*/
|
|
720
|
-
const
|
|
721
|
-
if (!text) {
|
|
722
|
-
log(`! ${session}: empty text — drop`);
|
|
723
|
-
return false;
|
|
724
|
-
}
|
|
759
|
+
const passesInjectGuards = (session, deps) => {
|
|
725
760
|
const cmd = (deps.paneCommand ?? exports.paneCurrentCommand)(session);
|
|
726
761
|
if (cmd === null) {
|
|
727
762
|
log(`! ${session}: no such tmux session — drop`);
|
|
@@ -731,16 +766,33 @@ const tryInject = (session, text, deps) => {
|
|
|
731
766
|
log(`! ${session}: pane is at shell (${cmd}) — refusing (would be RCE)`);
|
|
732
767
|
return false;
|
|
733
768
|
}
|
|
734
|
-
|
|
735
|
-
if (!allowed) {
|
|
769
|
+
if (!(deps.rateLimit ?? exports.checkRateLimit)(session)) {
|
|
736
770
|
log(`! ${session}: rate-limited — drop`);
|
|
737
771
|
return false;
|
|
738
772
|
}
|
|
773
|
+
return true;
|
|
774
|
+
};
|
|
775
|
+
const tryInject = (session, text, deps) => {
|
|
776
|
+
if (!text) {
|
|
777
|
+
log(`! ${session}: empty text — drop`);
|
|
778
|
+
return false;
|
|
779
|
+
}
|
|
780
|
+
if (!passesInjectGuards(session, deps))
|
|
781
|
+
return false;
|
|
739
782
|
const ok = (deps.inject ?? injectKeys)(session, text);
|
|
740
783
|
const preview = text.length > 60 ? text.slice(0, 60) + '…' : text;
|
|
741
784
|
log(`${ok ? '→' : '✗'} ${session}: ${preview}`);
|
|
742
785
|
return ok;
|
|
743
786
|
};
|
|
787
|
+
/** Key-event sibling of tryInject: same pane/shell/rate guards, but sends
|
|
788
|
+
* named keys instead of literal text + Enter. */
|
|
789
|
+
const tryInjectKeys = (session, tokens, deps) => {
|
|
790
|
+
if (!passesInjectGuards(session, deps))
|
|
791
|
+
return false;
|
|
792
|
+
const ok = (deps.sendKeys ?? injectNamedKeys)(session, tokens);
|
|
793
|
+
log(`${ok ? '⌨' : '✗'} ${session}: [${tokens.join(' ')}]`);
|
|
794
|
+
return ok;
|
|
795
|
+
};
|
|
744
796
|
// ─── Attachment download (agent.command files[]) ────────────────────
|
|
745
797
|
const ATTACHMENTS_DIR = (0, path_1.join)((0, os_1.homedir)(), '.zeph', 'attachments');
|
|
746
798
|
const DEFAULT_API_BASE = 'https://api.zeph.to/v1';
|
|
@@ -876,6 +928,17 @@ const handlePush = async (push, deps = {}) => {
|
|
|
876
928
|
}
|
|
877
929
|
if (push.type !== 'agent.command' || !push.agentSessionName)
|
|
878
930
|
return false;
|
|
931
|
+
// Key event (Esc / arrows / Enter) — no body, no attachments. Lets the
|
|
932
|
+
// phone escape a full-screen modal (e.g. after `/usage`) that swallows
|
|
933
|
+
// text input.
|
|
934
|
+
if (push.keys?.length) {
|
|
935
|
+
const tokens = (0, exports.resolveKeys)(push.keys);
|
|
936
|
+
if (!tokens) {
|
|
937
|
+
log(`! ${push.agentSessionName}: unknown key(s) [${push.keys.join(' ')}] — drop`);
|
|
938
|
+
return false;
|
|
939
|
+
}
|
|
940
|
+
return tryInjectKeys(push.agentSessionName, tokens, deps);
|
|
941
|
+
}
|
|
879
942
|
// Download any attachments BEFORE injecting so the agent can read the
|
|
880
943
|
// local paths immediately. A download-phase failure is isolated: the
|
|
881
944
|
// body text still injects so the command itself isn't blocked.
|