passcontrol 1.7.2 → 1.8.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/cli/tool-gate.mjs CHANGED
@@ -27,6 +27,7 @@
27
27
  // page: tool name, decision, rule number and wait. Never the command, path or URL.
28
28
  import { underTaint } from "./injection-hold.mjs";
29
29
  import { evaluateToolRules, parseToolRules } from "./tool-rules.mjs";
30
+ import { evaluateMissionTools, toolItemKey } from "./mission-tools.mjs";
30
31
 
31
32
  /** The wait ends this long before Claude Code would give up on the hook. */
32
33
  export const HOOK_MARGIN_S = 30;
@@ -86,8 +87,9 @@ export function createToolGate({ askOwner, onDecision = () => {}, now = () => Da
86
87
  * The rules from the latest trusted /self read, or null.
87
88
  * @param {number | null} hookTimeoutS What the hook's URL says it waits; null when it does not say.
88
89
  * @param {"off" | "clear" | "tainted" | "unknown"} injection
90
+ * @param {"off" | "clear" | "held"} memory idea 13: unresolved memory arrivals hold the same tools
89
91
  */
90
- async function decide(input, rulesEntry, hookTimeoutS, injection = "off") {
92
+ async function decide(input, rulesEntry, hookTimeoutS, injection = "off", memory = "off") {
91
93
  if (input?.hook_event_name !== "PreToolUse") return {};
92
94
  if (needsRefresh || refreshing) {
93
95
  if (!refreshing) {
@@ -114,10 +116,13 @@ export function createToolGate({ askOwner, onDecision = () => {}, now = () => Da
114
116
  }
115
117
 
116
118
  const original = evaluateToolRules(parsed, input);
117
- const hit = injection === "tainted" ? underTaint(original, input.tool_name) : original;
119
+ const hit = injection === "tainted" || memory === "held" ? underTaint(original, input.tool_name) : original;
118
120
  const escalated = hit.reason === "injection_taint";
119
121
  // `/self` says only that the agent is tainted, not why: a tell, or output not fully checked (1.7.1).
120
- const guardText = "This tool was held by the injection guard: something the agent recently read looked like a prompt injection, or could not be fully checked.";
122
+ const guardText =
123
+ injection !== "tainted" && memory === "held"
124
+ ? "This tool was held by memory custody: the agent's memory files have entries waiting for the owner's review (they arrived with no custody record, or were written while outside content was in its context)."
125
+ : "This tool was held by the injection guard: something the agent recently read looked like a prompt injection, or could not be fully checked.";
121
126
  let warning = {};
122
127
  if (injection === "unknown" && (injectionWarnedAt === null || now() - injectionWarnedAt >= WARN_EVERY_MS)) {
123
128
  injectionWarnedAt = now();
@@ -129,6 +134,43 @@ export function createToolGate({ askOwner, onDecision = () => {}, now = () => Da
129
134
  try { onHold({ tool: String(input.tool_name ?? "").slice(0, 128), outcome }); } catch {}
130
135
  }
131
136
  }
137
+ // Idea 11: the agent's mission, local-tool section. A GUARD RAIL, not a boundary
138
+ // (cli/mission-tools.mjs says why). Only adds friction where the rules above are
139
+ // not already stricter: a deny stays a deny, an ask_owner still asks the owner.
140
+ // Outside an enforcing mission the call holds through Claude Code's own prompt;
141
+ // shadow mode records what it would have held and changes nothing.
142
+ const mission = rulesEntry?.mission;
143
+ if (mission && (hit.effect === null || hit.effect === "ask") && !escalated) {
144
+ // Mission-only (R11-01): between missions nothing is standing authority, so every
145
+ // tool the rules do not already decide holds here, as the gateway holds services.
146
+ if (mission.only === true && mission.state === "none") {
147
+ record(input, "mission_outside", null, 0);
148
+ return withWarning(
149
+ verdict(
150
+ "ask",
151
+ "PassControl: this agent works only on missions, and none is in force. Confirm it here if you meant it; a mission is approved by the owner. This check is a guard rail on this machine, not a boundary."
152
+ )
153
+ );
154
+ }
155
+ if (mission.state === "ok" && Array.isArray(mission.tools)) {
156
+ const judged = evaluateMissionTools(mission.tools, input);
157
+ if (judged.state === "outside" && mission.mode === "enforce") {
158
+ record(input, "mission_outside", null, 0);
159
+ const what = judged.missing.map((item) => toolItemKey(item)).join(", ");
160
+ return withWarning(
161
+ verdict(
162
+ "ask",
163
+ `PassControl: this is outside this agent's mission (${short(what)}). Confirm it here if you meant it; widening the mission itself needs the owner. This check is a guard rail on this machine, not a boundary.`
164
+ )
165
+ );
166
+ }
167
+ if (judged.state === "outside") record(input, "mission_would_hold", null, 0);
168
+ } else if (mission.state === "unknown" && (warnedAt === null || now() - warnedAt >= WARN_EVERY_MS)) {
169
+ warnedAt = now();
170
+ warning = { ...warning, systemMessage: "PassControl could not read this agent's mission yet, so this goes ahead. The gateway still enforces it for models and services." };
171
+ }
172
+ }
173
+
132
174
  const ruleIndex = escalated ? null : hit.ruleIndex;
133
175
  if (hit.effect === null) return withWarning({});
134
176
  const rule = escalated ? "injection guard" : `rule ${hit.ruleIndex + 1}`;
@@ -0,0 +1,20 @@
1
+ export interface DecoyCandidates {
2
+ candidates: string[];
3
+ truncated: boolean;
4
+ }
5
+ export const TRIPWIRE_SCAN_LIMITS: Readonly<{
6
+ maxCandidates: number;
7
+ maxDepth: number;
8
+ streamWindow: number;
9
+ streamTail: number;
10
+ seam: number;
11
+ }>;
12
+ /** A credential header's value, plus its decoded HTTP Basic credentials when it is Basic auth. */
13
+ export function credentialHeaderTexts(raw: unknown): string[];
14
+ export function findDecoyCandidates(text: string): DecoyCandidates;
15
+ export function candidatesInJson(value: unknown): DecoyCandidates & { gaps: ("depth_limit" | "candidate_limit")[] };
16
+ export function createStreamCandidateFinder(): {
17
+ push(fragment: string): void;
18
+ finish(): DecoyCandidates;
19
+ retained(): number;
20
+ };
@@ -0,0 +1,279 @@
1
+ // Tripwire decoy candidates (idea 12; research/idea-12-tripwire/).
2
+ //
3
+ // Shared by the gateway (lib/tripwire/*, edge runtime) and the local sidecar, so it is
4
+ // plain JavaScript with no Node built-ins and no hashing: the caller hashes each
5
+ // candidate and asks its registry. A candidate is NOT a finding. Only an exact digest
6
+ // match against a registered decoy is, so a false candidate costs one lookup and can
7
+ // never raise a Seen on its own. That is why this file errs towards proposing too much:
8
+ // no word boundaries (junk glued to a decoy must not hide it), and every decoding layer
9
+ // the design claims is tried.
10
+ //
11
+ // Forms covered (research/idea-12-tripwire/RESULTS.md, S2): plain; JSON \u escapes;
12
+ // percent-encoding; base64 (standard and url-safe, any byte alignment, line-wrapped); hex
13
+ // (either case); one of the first two layers around one of the last two; a decoy split across
14
+ // two ADJACENT string leaves of one JSON body; a decoy split across stream chunks.
15
+ // Forms NOT covered are listed there as accepted limits (compression, encryption,
16
+ // line-wrapped base64, any transformation the agent invents, splits across requests).
17
+ //
18
+ // Linear time: one indexOf pass per signature per layer, and each hit inspects a
19
+ // fixed-size window. Bounded output: at most `maxCandidates` unique candidates, and a
20
+ // truncation is reported, never silently dropped.
21
+
22
+ const PREFIX = "pc_agent_";
23
+ const SECRET_LENGTH = 43;
24
+ const DECOY_LENGTH = PREFIX.length + SECRET_LENGTH; // 52
25
+ const SECRET_CHAR = /^[A-Za-z0-9_-]$/;
26
+
27
+ export const TRIPWIRE_SCAN_LIMITS = Object.freeze({
28
+ maxCandidates: 512,
29
+ maxDepth: 64,
30
+ // Longer than the longest single-decoy encoding this file reads: \u-escaped is 6
31
+ // characters a byte (312), percent-encoded base64 of a decoy is ~216.
32
+ streamWindow: 4096,
33
+ streamTail: 640,
34
+ // Characters of each adjacent leaf joined to find a decoy split across two leaves.
35
+ seam: 640,
36
+ });
37
+
38
+ const B64_STD = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
39
+ const B64_URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
40
+ const B64_VALUE = new Map();
41
+ for (let i = 0; i < 64; i++) {
42
+ B64_VALUE.set(B64_STD[i], i);
43
+ B64_VALUE.set(B64_URL[i], i);
44
+ }
45
+
46
+ function encodeBase64(bytes, alphabet) {
47
+ let out = "";
48
+ for (let i = 0; i + 2 < bytes.length; i += 3) {
49
+ const n = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
50
+ out += alphabet[(n >> 18) & 63] + alphabet[(n >> 12) & 63] + alphabet[(n >> 6) & 63] + alphabet[n & 63];
51
+ }
52
+ return out; // whole groups only: the trailing partial group depends on what follows
53
+ }
54
+
55
+ // For each byte alignment k (bytes of the 3-byte group before the prefix), the base64
56
+ // characters of the prefix that do not depend on its neighbours, and how many
57
+ // characters into the group they start.
58
+ const PREFIX_BYTES = Array.from(PREFIX, (c) => c.charCodeAt(0));
59
+ const B64_SIGNATURES = [];
60
+ for (const alphabet of [B64_STD, B64_URL]) {
61
+ for (let k = 0; k < 3; k++) {
62
+ const enc = encodeBase64([...new Array(k).fill(0), ...PREFIX_BYTES], alphabet);
63
+ const skip = k === 0 ? 0 : k + 1; // chars touched by the k leading bytes
64
+ const signature = enc.slice(skip);
65
+ if (!B64_SIGNATURES.some((s) => s.signature === signature)) B64_SIGNATURES.push({ signature, k, skip });
66
+ }
67
+ }
68
+ const HEX_SIGNATURE = Array.from(PREFIX, (c) => c.charCodeAt(0).toString(16).padStart(2, "0")).join("");
69
+
70
+ function isSecret(text, start) {
71
+ if (start + SECRET_LENGTH > text.length) return false;
72
+ for (let i = start; i < start + SECRET_LENGTH; i++) {
73
+ if (!SECRET_CHAR.test(text[i])) return false;
74
+ }
75
+ return true;
76
+ }
77
+
78
+ /** Collects unique candidates up to the cap. */
79
+ class Sink {
80
+ constructor(limit = TRIPWIRE_SCAN_LIMITS.maxCandidates) {
81
+ this.limit = limit;
82
+ this.set = new Set();
83
+ this.truncated = false;
84
+ }
85
+ add(candidate) {
86
+ if (this.set.has(candidate)) return;
87
+ if (this.set.size >= this.limit) {
88
+ this.truncated = true;
89
+ return;
90
+ }
91
+ this.set.add(candidate);
92
+ }
93
+ }
94
+
95
+ function scanPlain(text, sink) {
96
+ for (let at = text.indexOf(PREFIX); at !== -1; at = text.indexOf(PREFIX, at + 1)) {
97
+ const start = at + PREFIX.length;
98
+ if (isSecret(text, start)) sink.add(text.slice(at, start + SECRET_LENGTH));
99
+ }
100
+ }
101
+
102
+ function decodeBase64Window(text, from, chars) {
103
+ const bytes = [];
104
+ let acc = 0;
105
+ let bits = 0;
106
+ for (let i = from; i < from + chars && i < text.length; i++) {
107
+ const v = B64_VALUE.get(text[i]);
108
+ if (v === undefined) break;
109
+ acc = (acc << 6) | v;
110
+ bits += 6;
111
+ if (bits >= 8) {
112
+ bits -= 8;
113
+ bytes.push((acc >> bits) & 0xff);
114
+ }
115
+ }
116
+ return String.fromCharCode(...bytes);
117
+ }
118
+
119
+ function scanBase64(text, sink) {
120
+ // A decoy needs the k leading bytes plus 52: ceil((k + 52) / 3) groups.
121
+ for (const { signature, k, skip } of B64_SIGNATURES) {
122
+ for (let at = text.indexOf(signature); at !== -1; at = text.indexOf(signature, at + 1)) {
123
+ const groupStart = at - skip;
124
+ if (groupStart < 0) continue;
125
+ const chars = Math.ceil((k + DECOY_LENGTH) / 3) * 4;
126
+ const decoded = decodeBase64Window(text, groupStart, chars);
127
+ const value = decoded.slice(k, k + DECOY_LENGTH);
128
+ if (value.startsWith(PREFIX) && isSecret(value, PREFIX.length)) sink.add(value);
129
+ }
130
+ }
131
+ }
132
+
133
+ function scanHex(text, sink) {
134
+ const lower = text.toLowerCase();
135
+ for (let at = lower.indexOf(HEX_SIGNATURE); at !== -1; at = lower.indexOf(HEX_SIGNATURE, at + 1)) {
136
+ if (at + DECOY_LENGTH * 2 > lower.length) continue;
137
+ let value = "";
138
+ for (let i = 0; i < DECOY_LENGTH; i++) {
139
+ const pair = lower.slice(at + i * 2, at + i * 2 + 2);
140
+ if (!/^[0-9a-f]{2}$/.test(pair)) break;
141
+ value += String.fromCharCode(parseInt(pair, 16));
142
+ }
143
+ if (value.length === DECOY_LENGTH && isSecret(value, PREFIX.length)) sink.add(value);
144
+ }
145
+ }
146
+
147
+ function unescapeJson(text) {
148
+ if (!text.includes("\\")) return null;
149
+ // Any number of backslashes before the u: JSON inside a JSON string escapes the escape
150
+ // (`\\u0070`), and that is how a nested tool result arrives (S2 suite, red team R3-07).
151
+ const out = text.replace(/\\+u([0-9a-fA-F]{4})/g, (_, h) => String.fromCharCode(parseInt(h, 16))).replace(/\\+\//g, "/");
152
+ return out === text ? null : out;
153
+ }
154
+
155
+ function decodePercent(text) {
156
+ if (!text.includes("%")) return null;
157
+ const out = text.replace(/%([0-9a-fA-F]{2})/g, (_, h) => String.fromCharCode(parseInt(h, 16)));
158
+ return out === text ? null : out;
159
+ }
160
+
161
+ function scanLayers(text, sink) {
162
+ const layers = [text];
163
+ // Line-wrapped base64 or hex (MIME's 76 columns, `base64` without -w0, PEM-style): the
164
+ // same text with line breaks removed. Red team R1-06.
165
+ if (text.includes("\n") || text.includes("\r")) {
166
+ const unwrapped = text.replace(/[\r\n]+/g, "");
167
+ if (unwrapped !== text) layers.push(unwrapped);
168
+ }
169
+ const json = unescapeJson(text);
170
+ if (json !== null) layers.push(json);
171
+ const percent = decodePercent(text);
172
+ if (percent !== null) layers.push(percent);
173
+ for (const layer of layers) {
174
+ scanPlain(layer, sink);
175
+ scanBase64(layer, sink);
176
+ scanHex(layer, sink);
177
+ }
178
+ }
179
+
180
+ /** Candidates in one string. Never throws on a string. */
181
+ /**
182
+ * A credential header's value, plus what its HTTP Basic credentials decode to, when it is
183
+ * Basic auth (curl -u, git credential helpers; red team R2-01/02). The gateway and the
184
+ * sidecar both read headers through this, so the two cannot disagree (review R12-10).
185
+ * Standard or URL-safe base64; anything that is not base64 adds nothing.
186
+ */
187
+ export function credentialHeaderTexts(raw) {
188
+ if (typeof raw !== "string") return [];
189
+ const texts = [raw];
190
+ const basic = /^\s*basic\s+([A-Za-z0-9+/=_-]{1,4096})\s*$/i.exec(raw);
191
+ if (basic) {
192
+ try {
193
+ texts.push(atob(basic[1].replace(/-/g, "+").replace(/_/g, "/")));
194
+ } catch {
195
+ // Not base64: nothing more to read.
196
+ }
197
+ }
198
+ return texts;
199
+ }
200
+
201
+ export function findDecoyCandidates(text) {
202
+ const sink = new Sink();
203
+ if (typeof text === "string" && text.length > 0) scanLayers(text, sink);
204
+ return { candidates: [...sink.set], truncated: sink.truncated };
205
+ }
206
+
207
+ /**
208
+ * Candidates in a parsed JSON value: every string leaf (base64 media included, because
209
+ * a text document travels as base64), plus the seam between each pair of adjacent
210
+ * leaves, so a decoy cut across two messages is still read whole.
211
+ */
212
+ export function candidatesInJson(value) {
213
+ const sink = new Sink();
214
+ const gaps = new Set();
215
+ let previous = "";
216
+ const seam = TRIPWIRE_SCAN_LIMITS.seam;
217
+ const pending = [[value, 0]];
218
+ const visited = new WeakSet();
219
+ const leaf = (text) => {
220
+ scanLayers(text, sink);
221
+ if (previous) scanLayers(previous.slice(-seam) + text.slice(0, seam), sink);
222
+ previous = text;
223
+ };
224
+ while (pending.length) {
225
+ const [node, depth] = pending.pop();
226
+ if (typeof node === "string") {
227
+ leaf(node);
228
+ continue;
229
+ }
230
+ if (node === null || typeof node !== "object") continue;
231
+ if (depth >= TRIPWIRE_SCAN_LIMITS.maxDepth) {
232
+ gaps.add("depth_limit");
233
+ continue;
234
+ }
235
+ if (visited.has(node)) continue;
236
+ visited.add(node);
237
+ // Object keys too: a decoy can be a key. Pushed in reverse so leaves come out in order.
238
+ const entries = Array.isArray(node) ? node.map((v) => [null, v]) : Object.entries(node);
239
+ for (let i = entries.length - 1; i >= 0; i--) {
240
+ const [key, child] = entries[i];
241
+ pending.push([child, depth + 1]);
242
+ if (key !== null && key.length >= PREFIX.length) pending.push([key, depth + 1]);
243
+ }
244
+ }
245
+ if (sink.truncated) gaps.add("candidate_limit");
246
+ return { candidates: [...sink.set], truncated: sink.truncated, gaps: [...gaps] };
247
+ }
248
+
249
+ /**
250
+ * For text that arrives in fragments (a streamed answer, a chunked body): a bounded
251
+ * window scanned as it grows, keeping a tail longer than any encoded decoy.
252
+ */
253
+ export function createStreamCandidateFinder() {
254
+ const { streamWindow, streamTail } = TRIPWIRE_SCAN_LIMITS;
255
+ const sink = new Sink();
256
+ let window = "";
257
+ return {
258
+ push(fragment) {
259
+ if (typeof fragment !== "string" || fragment.length === 0) return;
260
+ for (let at = 0; at < fragment.length; ) {
261
+ const room = streamWindow - window.length;
262
+ window += fragment.slice(at, at + room);
263
+ at += room;
264
+ if (window.length >= streamWindow) {
265
+ scanLayers(window, sink);
266
+ window = window.slice(-streamTail);
267
+ }
268
+ }
269
+ },
270
+ finish() {
271
+ scanLayers(window, sink);
272
+ window = "";
273
+ return { candidates: [...sink.set], truncated: sink.truncated };
274
+ },
275
+ retained() {
276
+ return window.length;
277
+ },
278
+ };
279
+ }
@@ -0,0 +1,10 @@
1
+ export const TRIPWIRE_PATH: string;
2
+ export const TRIPWIRE_SOURCE: string;
3
+ export const HEARTBEAT_MS: number;
4
+ export function decoyInHeaders(headers: Record<string, unknown>, digests: Set<string>, isCredentialHeader: (name: string) => boolean): string | null;
5
+ export function decoysInHook(input: unknown, digests: Set<string>): string[];
6
+ export function createTripwireReporter(input: { send(body: unknown): Promise<{ status: number }>; now?: () => number }): {
7
+ used(digest: string, tools?: string[]): Promise<{ status: number }>;
8
+ seen(digests: string[]): Promise<{ status: number }>;
9
+ heartbeat(): Promise<{ status: number }>;
10
+ };
@@ -0,0 +1,84 @@
1
+ // The sidecar's tripwire checks (idea 12). Local, digest-only: the sidecar reads the
2
+ // manifest `configure tripwires` wrote (digests, never decoys), so nothing it sends can
3
+ // carry a decoy, and nothing it holds is one.
4
+ //
5
+ // * Used: a request the sidecar relays carries a planted decoy in a credential header.
6
+ // The sidecar strips credentials before forwarding (that is its job), so this is the
7
+ // only place such a decoy can be seen. The request is refused locally with the same 401
8
+ // an unknown key gets, and reported; the gateway stops the decoy's agent and this one.
9
+ // * Seen: a planted decoy appears in tool output a PostToolBatch/PostToolUse hook hands
10
+ // the model (subscription mode, where the gateway never sees model traffic).
11
+ // * Heartbeat: the scan is running, at most once per HEARTBEAT_MS (coverage, not safety).
12
+ import { createHash } from "node:crypto";
13
+ import { candidatesInJson, credentialHeaderTexts } from "./tripwire-scan.mjs";
14
+
15
+ export const TRIPWIRE_PATH = "/api/v1/tripwire";
16
+ export const TRIPWIRE_SOURCE = "passcontrol-sidecar";
17
+ export const HEARTBEAT_MS = 10 * 60 * 1000;
18
+ const DECOY = /pc_agent_[A-Za-z0-9_-]{43}/g;
19
+
20
+ const digest = (value) => createHash("sha256").update(value, "utf8").digest("base64url");
21
+
22
+ /** The planted digest a credential-bearing header carries, or null. */
23
+ export function decoyInHeaders(headers, digests, isCredentialHeader) {
24
+ if (!digests || digests.size === 0) return null;
25
+ for (const [name, raw] of Object.entries(headers ?? {})) {
26
+ if (!isCredentialHeader(name)) continue;
27
+ const values = Array.isArray(raw) ? raw : [raw];
28
+ for (const value of values) {
29
+ // Basic auth is decoded first: `pc_agent_` is not visible in its base64 (R12-10).
30
+ for (const text of credentialHeaderTexts(value)) {
31
+ if (!text.includes("pc_agent_")) continue;
32
+ for (const m of text.matchAll(DECOY)) {
33
+ const d = digest(m[0]);
34
+ if (digests.has(d)) return d;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ return null;
40
+ }
41
+
42
+ /** Planted digests that appear in the tool output of a hook input. Never throws. */
43
+ export function decoysInHook(input, digests) {
44
+ try {
45
+ if (!digests || digests.size === 0) return [];
46
+ let outputs = [];
47
+ if (input?.hook_event_name === "PostToolBatch" && Array.isArray(input.tool_calls)) outputs = input.tool_calls.map((c) => c?.tool_response);
48
+ else if (input?.hook_event_name === "PostToolUse") outputs = [input.tool_response ?? input.tool_output ?? input.output];
49
+ else return [];
50
+ const hits = new Set();
51
+ for (const c of candidatesInJson(outputs).candidates) {
52
+ const d = digest(c);
53
+ if (digests.has(d)) hits.add(d);
54
+ }
55
+ return [...hits];
56
+ } catch {
57
+ return [];
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Sends reports through the sidecar's authenticated path. `send(body)` posts JSON to
63
+ * TRIPWIRE_PATH with the sidecar's visa and returns { status }. `used` is awaited so the
64
+ * stop has happened (or is known to have failed) before the relayed request is answered.
65
+ */
66
+ export function createTripwireReporter({ send, now = Date.now }) {
67
+ let lastBeat = 0;
68
+ const post = async (reports) => {
69
+ try {
70
+ return await send({ source: TRIPWIRE_SOURCE, reports });
71
+ } catch {
72
+ return { status: 0 };
73
+ }
74
+ };
75
+ return {
76
+ used: (digestValue, tools = []) => post([{ kind: "used", digest: digestValue, tools: tools.slice(-5) }]),
77
+ seen: (digests) => (digests.length ? post(digests.slice(0, 20).map((d) => ({ kind: "seen", digest: d }))) : Promise.resolve({ status: 204 })),
78
+ heartbeat: () => {
79
+ if (now() - lastBeat < HEARTBEAT_MS) return Promise.resolve({ status: 204 });
80
+ lastBeat = now();
81
+ return post([{ kind: "heartbeat" }]);
82
+ },
83
+ };
84
+ }
@@ -0,0 +1,21 @@
1
+ export const TRIPWIRE_PLACEMENTS: Record<"state_backup" | "anthropic_pair", { rel(slug: string): string; content(decoy: string, origin?: string): string }>;
2
+ export const DEFAULT_TRIPWIRE_PLACEMENTS: string[];
3
+ export function tripwirePlacementChoices(): string;
4
+ export function generateDecoy(): string;
5
+ export function decoyDigest(decoy: string): string;
6
+ export function tripwireManifestPath(env?: Record<string, string | undefined>): string;
7
+ export function readTripwireManifest(file?: string): { version: number; agents: Record<string, { placements: { placement: string; path: string; digest: string; plantedAt: string }[] }> };
8
+ export function plantedDigests(file?: string): Set<string>;
9
+ export function slugOf(agentId: string): string;
10
+ export function enclosingRepo(dir: string): string | null;
11
+ export function checkTarget(home: string, rel: string, ownDigest: string | undefined): string;
12
+ export function plantTripwires(input: {
13
+ home?: string;
14
+ agentId: string;
15
+ origin: string;
16
+ placements?: string[];
17
+ register(decoys: { placement: string; digest: string }[], replace: boolean): Promise<unknown>;
18
+ manifestFile?: string;
19
+ dryRun?: boolean;
20
+ }): Promise<{ planted: { placement: string; path: string }[]; rotated?: boolean; dryRun?: boolean }>;
21
+ export function removeTripwires(input: { agentId: string; retire(): Promise<unknown>; manifestFile?: string }): Promise<{ removed: string[]; kept: string[] }>;