osborn 0.9.271 → 0.9.274
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/.claude/skills/browser-apply/SKILL.md +82 -30
- package/.claude/skills/browser-apply/candidate.example.env +16 -0
- package/.claude/skills/browser-apply/fill.mjs +294 -0
- package/Dockerfile +1 -1
- package/dist/claude-llm.d.ts +3 -0
- package/dist/claude-llm.js +100 -17
- package/dist/compaction-log.d.ts +67 -0
- package/dist/compaction-log.js +195 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.js +122 -65
- package/dist/content/transcript-sanitizer.d.ts +20 -6
- package/dist/content/transcript-sanitizer.js +66 -11
- package/dist/data-sender-auth.d.ts +90 -0
- package/dist/data-sender-auth.js +157 -0
- package/dist/env-keys.js +11 -0
- package/dist/index.js +411 -92
- package/dist/meeting-addressing.d.ts +176 -0
- package/dist/meeting-addressing.js +288 -0
- package/dist/pipeline-direct-llm.d.ts +27 -0
- package/dist/pipeline-direct-llm.js +117 -37
- package/dist/prompts/direct-mode-fallback.md +1 -1
- package/dist/prompts/direct-mode-research.md +2 -2
- package/dist/prompts.d.ts +1 -1
- package/dist/prompts.js +3 -3
- package/dist/pushover.d.ts +77 -0
- package/dist/pushover.js +276 -0
- package/dist/recall-client.js +21 -2
- package/dist/session-store.d.ts +15 -5
- package/dist/session-store.js +37 -10
- package/dist/transcript-wiring.d.ts +121 -0
- package/dist/transcript-wiring.js +252 -0
- package/dist/voice-io.d.ts +0 -9
- package/dist/voice-io.js +5 -19
- package/dist/watch-gateway.d.ts +38 -0
- package/dist/watch-gateway.js +205 -0
- package/package.json +1 -1
- package/scripts/review.ts +1 -1
- package/dist/bridge-llm.d.ts +0 -22
- package/dist/bridge-llm.js +0 -39
- package/dist/codex-handler.d.ts +0 -38
- package/dist/codex-handler.js +0 -83
- package/dist/codex-llm.d.ts +0 -40
- package/dist/codex-llm.js +0 -144
- package/dist/fast-brain.d.ts +0 -176
- package/dist/fast-brain.js +0 -1887
- package/dist/index-3-2-26-legacy.d.ts +0 -1
- package/dist/index-3-2-26-legacy.js +0 -2233
- package/dist/leagcyprompts2.d.ts +0 -0
- package/dist/leagcyprompts2.js +0 -573
- package/dist/prompts-2-25-26.d.ts +0 -0
- package/dist/prompts-2-25-26.js +0 -518
- package/dist/prompts-3-2-26.d.ts +0 -78
- package/dist/prompts-3-2-26.js +0 -1319
- package/dist/summary-index.d.ts +0 -90
- package/dist/summary-index.js +0 -585
package/dist/pushover.js
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pushover.ts — Track 1 watch bridge (yes/no on the wrist via Pushover).
|
|
3
|
+
*
|
|
4
|
+
* When the agent hits a blocking permission request and nobody answers in the
|
|
5
|
+
* web UI, this module fires an emergency (priority-2) Pushover notification.
|
|
6
|
+
* Pushover mirrors notifications to the Apple Watch, so a single tap on the
|
|
7
|
+
* wrist acknowledges it; Pushover then requests our callback URL (the
|
|
8
|
+
* frontend's /api/watch/ack/<token> route), which verifies the HMAC and POSTs
|
|
9
|
+
* back to this machine's /watch/ack endpoint — resolving the pending
|
|
10
|
+
* permission as ALLOW. If the push goes unacknowledged for the full expiry
|
|
11
|
+
* window, a receipts-API poll settles it as DENY and cancels further retries.
|
|
12
|
+
*
|
|
13
|
+
* Settled semantics (mobile plan, 2026-10-24): ack = yes · expiry = no.
|
|
14
|
+
*
|
|
15
|
+
* Env (all optional — the bridge is dormant unless a provider is configured):
|
|
16
|
+
* PUSHOVER_TOKEN app token from pushover.net ($5 one-time)
|
|
17
|
+
* PUSHOVER_USER_KEY user (or group) key to push to
|
|
18
|
+
* NTFY_URL ntfy server base (https://ntfy.sh or self-hosted)
|
|
19
|
+
* NTFY_TOPIC topic to publish permission asks to (Approve/Deny buttons)
|
|
20
|
+
* NTFY_TOKEN optional access token for protected ntfy topics
|
|
21
|
+
* WATCH_ACK_SECRET HMAC secret, shared with the frontend ack route
|
|
22
|
+
* OSBORN_PUBLIC_URL this machine's public base URL — embedded in the signed
|
|
23
|
+
* token so the frontend route knows where to forward
|
|
24
|
+
* OSBORN_FRONTEND_URL (existing) callback host, default www.voice-native.com
|
|
25
|
+
*/
|
|
26
|
+
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
27
|
+
const PUSH_API = 'https://api.pushover.net/1';
|
|
28
|
+
const ACK_PATH = '/api/watch/ack';
|
|
29
|
+
// Emergency-push tuning (seconds): re-buzz every 30s for up to 10 minutes.
|
|
30
|
+
const RETRY_S = 30;
|
|
31
|
+
const EXPIRE_S = 600;
|
|
32
|
+
// Grace past expiry before the receipts poll decides (clock skew + delivery).
|
|
33
|
+
const EXPIRY_GRACE_MS = 5_000;
|
|
34
|
+
/** Pending pushes by qid. The permission system is single-slot, so in practice
|
|
35
|
+
* this holds at most one live record — a Map keeps ack matching O(1) anyway. */
|
|
36
|
+
const pending = new Map();
|
|
37
|
+
/** Registered by index.ts: resolves the currently-pending permission. */
|
|
38
|
+
let resultHandler = null;
|
|
39
|
+
export function setWatchResultHandler(fn) {
|
|
40
|
+
resultHandler = fn;
|
|
41
|
+
}
|
|
42
|
+
export function pushoverConfig() {
|
|
43
|
+
const token = process.env.PUSHOVER_TOKEN;
|
|
44
|
+
const userKey = process.env.PUSHOVER_USER_KEY;
|
|
45
|
+
const secret = process.env.WATCH_ACK_SECRET;
|
|
46
|
+
const publicUrl = (process.env.OSBORN_PUBLIC_URL || '').replace(/\/+$/, '');
|
|
47
|
+
const frontendUrl = (process.env.OSBORN_FRONTEND_URL || 'https://www.voice-native.com').replace(/\/+$/, '');
|
|
48
|
+
if (!token || !userKey || !secret || !publicUrl)
|
|
49
|
+
return null;
|
|
50
|
+
return { token, userKey, secret, publicUrl, frontendUrl };
|
|
51
|
+
}
|
|
52
|
+
export function isWatchBridgeEnabled() {
|
|
53
|
+
return pushoverConfig() !== null || ntfyConfig() !== null;
|
|
54
|
+
}
|
|
55
|
+
// --- token helpers ---------------------------------------------------------
|
|
56
|
+
const b64url = (buf) => Buffer.from(buf).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
57
|
+
const b64urlParse = (s) => Buffer.from(s.replace(/-/g, '+').replace(/_/g, '/'), 'base64');
|
|
58
|
+
function hmac(secret, data) {
|
|
59
|
+
return b64url(createHmac('sha256', secret).update(data).digest());
|
|
60
|
+
}
|
|
61
|
+
export function signAckToken(payload, secret) {
|
|
62
|
+
const body = b64url(JSON.stringify(payload));
|
|
63
|
+
return `${body}.${hmac(secret, body)}`;
|
|
64
|
+
}
|
|
65
|
+
export function verifyAckToken(qid, secret) {
|
|
66
|
+
const dot = qid.lastIndexOf('.');
|
|
67
|
+
if (dot <= 0)
|
|
68
|
+
return null;
|
|
69
|
+
const body = qid.slice(0, dot);
|
|
70
|
+
const sig = qid.slice(dot + 1);
|
|
71
|
+
const expected = hmac(secret, body);
|
|
72
|
+
const a = Buffer.from(sig);
|
|
73
|
+
const b = Buffer.from(expected);
|
|
74
|
+
if (a.length !== b.length || !timingSafeEqual(a, b))
|
|
75
|
+
return null;
|
|
76
|
+
try {
|
|
77
|
+
const payload = JSON.parse(b64urlParse(body).toString('utf-8'));
|
|
78
|
+
if (typeof payload.a !== 'string' || typeof payload.n !== 'string')
|
|
79
|
+
return null;
|
|
80
|
+
return payload;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export function ntfyConfig() {
|
|
87
|
+
const url = (process.env.NTFY_URL || '').replace(/\/+$/, '');
|
|
88
|
+
const topic = process.env.NTFY_TOPIC;
|
|
89
|
+
if (!url || !topic)
|
|
90
|
+
return null;
|
|
91
|
+
return { url, topic, token: process.env.NTFY_TOKEN || undefined };
|
|
92
|
+
}
|
|
93
|
+
export function isNtfyEnabled() {
|
|
94
|
+
return ntfyConfig() !== null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Mirror a blocking permission request to the wrist. Fire-and-forget: any
|
|
98
|
+
* failure (network, Pushover 4xx, missing env) just logs — the web UI remains
|
|
99
|
+
* the source of truth and the request still waits for it.
|
|
100
|
+
*/
|
|
101
|
+
export async function armPermissionPush(opts) {
|
|
102
|
+
const cfg = pushoverConfig();
|
|
103
|
+
const ntfy = ntfyConfig();
|
|
104
|
+
if (!cfg && !ntfy)
|
|
105
|
+
return;
|
|
106
|
+
// Single-slot guard: never stack pushes (the SDK won't fire a second
|
|
107
|
+
// permission until the first resolves, but be defensive).
|
|
108
|
+
for (const p of pending.values()) {
|
|
109
|
+
if (!p.settled) {
|
|
110
|
+
console.log(`⌚️ Watch bridge: push already pending (${p.toolName}), not arming another`);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const secret = process.env.WATCH_ACK_SECRET || '';
|
|
115
|
+
const publicUrl = (process.env.OSBORN_PUBLIC_URL || '').replace(/\/+$/, '');
|
|
116
|
+
const frontendUrl = (process.env.OSBORN_FRONTEND_URL || 'https://www.voice-native.com').replace(/\/+$/, '');
|
|
117
|
+
if (!secret || !publicUrl)
|
|
118
|
+
return;
|
|
119
|
+
const now = Date.now();
|
|
120
|
+
const qid = signAckToken({ n: randomBytes(12).toString('hex'), a: publicUrl, t: now, e: now + EXPIRE_S * 1000 }, secret);
|
|
121
|
+
// One record serves both providers: whichever ack lands first settles it.
|
|
122
|
+
const record = {
|
|
123
|
+
qid,
|
|
124
|
+
receipt: '',
|
|
125
|
+
toolName: opts.toolName,
|
|
126
|
+
description: opts.description,
|
|
127
|
+
expiresAt: now + EXPIRE_S * 1000,
|
|
128
|
+
settled: false,
|
|
129
|
+
};
|
|
130
|
+
if (cfg) {
|
|
131
|
+
try {
|
|
132
|
+
const res = await fetch(`${PUSH_API}/messages.json`, {
|
|
133
|
+
method: 'POST',
|
|
134
|
+
body: new URLSearchParams({
|
|
135
|
+
token: cfg.token,
|
|
136
|
+
user: cfg.userKey,
|
|
137
|
+
title: 'Voice Native',
|
|
138
|
+
message: `${opts.description}\n\nTap to approve · ignore to deny`.slice(0, 1000),
|
|
139
|
+
priority: '2',
|
|
140
|
+
retry: String(RETRY_S),
|
|
141
|
+
expire: String(EXPIRE_S),
|
|
142
|
+
callback: `${frontendUrl}${ACK_PATH}/${qid}`,
|
|
143
|
+
}),
|
|
144
|
+
});
|
|
145
|
+
const body = (await res.json().catch(() => ({})));
|
|
146
|
+
if (!res.ok || !body.receipt) {
|
|
147
|
+
console.log(`⌚️ Watch bridge: pushover rejected (${res.status})`, body.errors || '');
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
record.receipt = body.receipt;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
console.log('⌚️ Watch bridge: pushover send failed:', e instanceof Error ? e.message : e);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (ntfy) {
|
|
158
|
+
// Approve/Deny buttons hit the SAME signed ack route with ?ans=1|0.
|
|
159
|
+
try {
|
|
160
|
+
const res = await fetch(ntfy.url, {
|
|
161
|
+
method: 'POST',
|
|
162
|
+
headers: {
|
|
163
|
+
'Content-Type': 'application/json',
|
|
164
|
+
...(ntfy.token ? { Authorization: `Bearer ${ntfy.token}` } : {}),
|
|
165
|
+
},
|
|
166
|
+
body: JSON.stringify({
|
|
167
|
+
topic: ntfy.topic,
|
|
168
|
+
title: 'Voice Native',
|
|
169
|
+
message: opts.description.slice(0, 1000),
|
|
170
|
+
priority: 4,
|
|
171
|
+
tags: ['computer'],
|
|
172
|
+
click: `${frontendUrl}/dashboard`,
|
|
173
|
+
actions: [
|
|
174
|
+
{
|
|
175
|
+
action: 'http',
|
|
176
|
+
label: 'Approve',
|
|
177
|
+
method: 'GET',
|
|
178
|
+
url: `${frontendUrl}${ACK_PATH}/${qid}?ans=1`,
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
action: 'http',
|
|
182
|
+
label: 'Deny',
|
|
183
|
+
method: 'GET',
|
|
184
|
+
url: `${frontendUrl}${ACK_PATH}/${qid}?ans=0`,
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
}),
|
|
188
|
+
});
|
|
189
|
+
if (!res.ok)
|
|
190
|
+
console.log(`⌚️ Watch bridge: ntfy rejected (${res.status})`);
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
console.log('⌚️ Watch bridge: ntfy send failed:', e instanceof Error ? e.message : e);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (!record.receipt && !ntfy)
|
|
197
|
+
return; // nothing actually sent
|
|
198
|
+
record.expiryTimer = setTimeout(() => void settleExpired(record), EXPIRE_S * 1000 + EXPIRY_GRACE_MS);
|
|
199
|
+
pending.set(qid, record);
|
|
200
|
+
console.log(`⌚️ Watch bridge: armed for ${opts.toolName} (pushover=${cfg ? 'on' : 'off'} ntfy=${ntfy ? 'on' : 'off'}, expires in ${EXPIRE_S}s)`);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Landing for the frontend ack route. Returns true when a pending push was
|
|
204
|
+
* settled. `allow` defaults to true (Pushover ack semantics = approve); the
|
|
205
|
+
* ntfy Deny button passes false explicitly. Idempotent: a replayed callback
|
|
206
|
+
* or a late ack after another path answered just returns false.
|
|
207
|
+
*/
|
|
208
|
+
export function handleWatchAck(qid, receipt, allow = true) {
|
|
209
|
+
const secret = process.env.WATCH_ACK_SECRET;
|
|
210
|
+
if (!secret)
|
|
211
|
+
return false;
|
|
212
|
+
if (!verifyAckToken(qid, secret)) {
|
|
213
|
+
console.log('⌚️ Watch bridge: ack token failed HMAC verification');
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
const record = pending.get(qid);
|
|
217
|
+
if (!record || record.settled)
|
|
218
|
+
return false;
|
|
219
|
+
if (receipt && record.receipt && receipt !== record.receipt) {
|
|
220
|
+
console.log('⌚️ Watch bridge: receipt mismatch — ignoring ack');
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
record.settled = true;
|
|
224
|
+
if (record.expiryTimer)
|
|
225
|
+
clearTimeout(record.expiryTimer);
|
|
226
|
+
pending.delete(qid);
|
|
227
|
+
console.log(`⌚️ Watch bridge: ACKED → ${allow ? 'approve' : 'deny'} ${record.toolName}`);
|
|
228
|
+
resultHandler?.(allow, record.toolName);
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Expiry path: if Pushover says the notification was never acknowledged,
|
|
233
|
+
* settle as deny and cancel further retries (stops the watch buzzing). If it
|
|
234
|
+
* WAS acknowledged but our callback never landed (delivery hiccup), recover
|
|
235
|
+
* by treating it as approve. ntfy-only records (no receipt) just settle deny.
|
|
236
|
+
*/
|
|
237
|
+
async function settleExpired(record) {
|
|
238
|
+
if (record.settled)
|
|
239
|
+
return;
|
|
240
|
+
const cfg = pushoverConfig();
|
|
241
|
+
// ntfy-only, or pushover send failed earlier: no receipts API — deny.
|
|
242
|
+
if (!cfg || !record.receipt) {
|
|
243
|
+
record.settled = true;
|
|
244
|
+
pending.delete(record.qid);
|
|
245
|
+
console.log(`⌚️ Watch bridge: unacknowledged at expiry → deny ${record.toolName}`);
|
|
246
|
+
resultHandler?.(false, record.toolName);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
const res = await fetch(`${PUSH_API}/receipts/${record.receipt}.json?token=${encodeURIComponent(cfg.token)}`);
|
|
251
|
+
const body = (await res.json().catch(() => ({})));
|
|
252
|
+
record.settled = true;
|
|
253
|
+
pending.delete(record.qid);
|
|
254
|
+
if (body.acknowledged === 1) {
|
|
255
|
+
// Acked but the callback never reached us — recover as approve.
|
|
256
|
+
console.log(`⌚️ Watch bridge: expiry poll found late ack → approve ${record.toolName}`);
|
|
257
|
+
resultHandler?.(true, record.toolName);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
console.log(`⌚️ Watch bridge: unacknowledged at expiry → deny ${record.toolName}`);
|
|
261
|
+
resultHandler?.(false, record.toolName);
|
|
262
|
+
// Cancel remaining emergency retries so the wrist stops buzzing.
|
|
263
|
+
void fetch(`${PUSH_API}/receipts/${record.receipt}/cancel.json`, {
|
|
264
|
+
method: 'POST',
|
|
265
|
+
body: new URLSearchParams({ token: cfg.token }),
|
|
266
|
+
}).catch(() => { });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
catch (e) {
|
|
270
|
+
// Poll failed — settle deny; the record is dropped either way.
|
|
271
|
+
console.log('⌚️ Watch bridge: receipts poll failed:', e instanceof Error ? e.message : e);
|
|
272
|
+
record.settled = true;
|
|
273
|
+
pending.delete(record.qid);
|
|
274
|
+
resultHandler?.(false, record.toolName);
|
|
275
|
+
}
|
|
276
|
+
}
|
package/dist/recall-client.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
2
|
const RECALL_REGION = process.env.RECALL_REGION ?? 'us-west-2';
|
|
3
3
|
const RECALL_BASE_URL = `https://${RECALL_REGION}.recall.ai/api/v1`;
|
|
4
|
+
const RECALL_REGION_EXPLICIT = !!process.env.RECALL_REGION;
|
|
5
|
+
// Recall API keys are REGION-SCOPED. A key present but pointed at the wrong
|
|
6
|
+
// region makes EVERY call (join / output_audio / transcript) 401 — and it used
|
|
7
|
+
// to fail silently (no base-URL log, generic error), which is why the meeting
|
|
8
|
+
// bot looked "half-wired". Log the resolved base URL once so the target region
|
|
9
|
+
// is visible, and turn 401/403 into a loud, actionable message.
|
|
10
|
+
let recallBaseLogged = false;
|
|
11
|
+
function logRecallBaseOnce() {
|
|
12
|
+
if (recallBaseLogged)
|
|
13
|
+
return;
|
|
14
|
+
recallBaseLogged = true;
|
|
15
|
+
console.log(`🎥 Recall base URL: ${RECALL_BASE_URL}${RECALL_REGION_EXPLICIT ? '' : ' (RECALL_REGION unset → defaulted us-west-2; set it if your key is in another region)'}`);
|
|
16
|
+
}
|
|
17
|
+
function recallRegionHint(status) {
|
|
18
|
+
if (status !== 401 && status !== 403)
|
|
19
|
+
return '';
|
|
20
|
+
return ` — Recall API keys are region-scoped; RECALL_REGION=${RECALL_REGION}${RECALL_REGION_EXPLICIT ? '' : ' (DEFAULTED, not set)'} may not match your account's region. Set RECALL_REGION to your account's region and roll the machine.`;
|
|
21
|
+
}
|
|
4
22
|
export class RecallClient extends EventEmitter {
|
|
5
23
|
#apiKey;
|
|
6
24
|
#activeBots = new Map(); // botId → sessionId
|
|
@@ -66,6 +84,7 @@ export class RecallClient extends EventEmitter {
|
|
|
66
84
|
// We DO keep `recording_config.transcript.provider.recallai_streaming` so
|
|
67
85
|
// Recall actually transcribes the meeting — the REST endpoint we poll
|
|
68
86
|
// requires this to be configured, otherwise transcripts are empty.
|
|
87
|
+
logRecallBaseOnce();
|
|
69
88
|
const res = await fetch(`${RECALL_BASE_URL}/bot`, {
|
|
70
89
|
method: 'POST',
|
|
71
90
|
headers: {
|
|
@@ -91,7 +110,7 @@ export class RecallClient extends EventEmitter {
|
|
|
91
110
|
});
|
|
92
111
|
if (!res.ok) {
|
|
93
112
|
const err = await res.text();
|
|
94
|
-
throw new Error(`Recall.ai join failed: ${res.status} ${err}`);
|
|
113
|
+
throw new Error(`Recall.ai join failed: ${res.status} ${err.slice(0, 200)}${recallRegionHint(res.status)}`);
|
|
95
114
|
}
|
|
96
115
|
const bot = (await res.json());
|
|
97
116
|
console.log(`🤖 Recall.ai bot joined meeting: ${bot.id} (polling-only, no audio pipeline)`);
|
|
@@ -160,7 +179,7 @@ export class RecallClient extends EventEmitter {
|
|
|
160
179
|
});
|
|
161
180
|
if (!res.ok) {
|
|
162
181
|
const e = await res.text().catch(() => '');
|
|
163
|
-
console.warn(`⚠️ Recall output_audio ${res.status}: ${e.slice(0, 160)}`);
|
|
182
|
+
console.warn(`⚠️ Recall output_audio ${res.status}: ${e.slice(0, 160)}${recallRegionHint(res.status)}`);
|
|
164
183
|
return false;
|
|
165
184
|
}
|
|
166
185
|
return true;
|
package/dist/session-store.d.ts
CHANGED
|
@@ -89,10 +89,20 @@ export interface RecallOpts {
|
|
|
89
89
|
*/
|
|
90
90
|
export declare function recall(db: Database.Database, query: string, opts?: RecallOpts): Promise<RecallHit[]>;
|
|
91
91
|
/**
|
|
92
|
-
* Return the most recent N content rows
|
|
93
|
-
*
|
|
94
|
-
*
|
|
92
|
+
* Return the most recent N content rows, newest first, as RecallHit-shaped objects.
|
|
93
|
+
* Powers fast-brain's "recent entries" path and the session tail. Encapsulates
|
|
94
|
+
* decompress so callers never touch the blob/compression.
|
|
95
95
|
* `msgTypes` optionally filters by msg_type IN SQL — so callers that only want
|
|
96
|
-
* user/assistant rows don't decompress rows they'd discard.
|
|
96
|
+
* user/assistant rows don't decompress rows they'd discard. `opts.sources`
|
|
97
|
+
* optionally restricts to given sources (e.g. ['main'] = the session's own JSONL,
|
|
98
|
+
* no sub-agent rows).
|
|
99
|
+
*
|
|
100
|
+
* Recency is by record TIMESTAMP (ts DESC), not insertion id: a backfill/reindex
|
|
101
|
+
* or a resume can insert older rows after newer ones, and "newest by id" then
|
|
102
|
+
* surfaced weeks-old turns (UI#16). id DESC breaks ties; rows with no ts sort
|
|
103
|
+
* last (SQLite NULLs are smallest). idx_content_ts(ts, id) serves the order. The ordering runs in a blob-free subquery so only the N kept rows
|
|
104
|
+
* carry their blob through the sort.
|
|
97
105
|
*/
|
|
98
|
-
export declare function recentRows(db: Database.Database, count: number, msgTypes?: string[]
|
|
106
|
+
export declare function recentRows(db: Database.Database, count: number, msgTypes?: string[], opts?: {
|
|
107
|
+
sources?: string[];
|
|
108
|
+
}): RecallHit[];
|
package/dist/session-store.js
CHANGED
|
@@ -134,6 +134,7 @@ export function openStore(dbPath, opts) {
|
|
|
134
134
|
);
|
|
135
135
|
CREATE INDEX IF NOT EXISTS idx_content_source ON content(source);
|
|
136
136
|
CREATE INDEX IF NOT EXISTS idx_content_type ON content(msg_type);
|
|
137
|
+
CREATE INDEX IF NOT EXISTS idx_content_ts ON content(ts, id);
|
|
137
138
|
|
|
138
139
|
CREATE VIRTUAL TABLE IF NOT EXISTS fts USING fts5(text, content='');
|
|
139
140
|
|
|
@@ -181,6 +182,14 @@ function extractRecords(raw) {
|
|
|
181
182
|
// ── user (regular text OR tool_result wrapper) ──
|
|
182
183
|
if (type === 'user') {
|
|
183
184
|
const content = raw.message?.content;
|
|
185
|
+
// Plain-string content (CLI-typed prompts, SDK string-prompt turns, imported
|
|
186
|
+
// sessions) is a real user turn too; it used to be silently skipped, so those
|
|
187
|
+
// turns were missing from /session-messages and prior_messages (UI#11).
|
|
188
|
+
// Existing stores pick these up on their next rebuild (STORE_VERSION unchanged:
|
|
189
|
+
// a bump would wipe and re-embed every store).
|
|
190
|
+
if (typeof content === 'string') {
|
|
191
|
+
return content.trim() ? [{ msgType: 'user', model: null, toolName: null, text: content }] : [];
|
|
192
|
+
}
|
|
184
193
|
if (!Array.isArray(content))
|
|
185
194
|
return [];
|
|
186
195
|
if (content[0]?.type === 'tool_result') {
|
|
@@ -582,19 +591,37 @@ export async function recall(db, query, opts) {
|
|
|
582
591
|
return hits;
|
|
583
592
|
}
|
|
584
593
|
/**
|
|
585
|
-
* Return the most recent N content rows
|
|
586
|
-
*
|
|
587
|
-
*
|
|
594
|
+
* Return the most recent N content rows, newest first, as RecallHit-shaped objects.
|
|
595
|
+
* Powers fast-brain's "recent entries" path and the session tail. Encapsulates
|
|
596
|
+
* decompress so callers never touch the blob/compression.
|
|
588
597
|
* `msgTypes` optionally filters by msg_type IN SQL — so callers that only want
|
|
589
|
-
* user/assistant rows don't decompress rows they'd discard.
|
|
598
|
+
* user/assistant rows don't decompress rows they'd discard. `opts.sources`
|
|
599
|
+
* optionally restricts to given sources (e.g. ['main'] = the session's own JSONL,
|
|
600
|
+
* no sub-agent rows).
|
|
601
|
+
*
|
|
602
|
+
* Recency is by record TIMESTAMP (ts DESC), not insertion id: a backfill/reindex
|
|
603
|
+
* or a resume can insert older rows after newer ones, and "newest by id" then
|
|
604
|
+
* surfaced weeks-old turns (UI#16). id DESC breaks ties; rows with no ts sort
|
|
605
|
+
* last (SQLite NULLs are smallest). idx_content_ts(ts, id) serves the order. The ordering runs in a blob-free subquery so only the N kept rows
|
|
606
|
+
* carry their blob through the sort.
|
|
590
607
|
*/
|
|
591
|
-
export function recentRows(db, count, msgTypes) {
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
608
|
+
export function recentRows(db, count, msgTypes, opts) {
|
|
609
|
+
const where = [];
|
|
610
|
+
const params = [];
|
|
611
|
+
if (msgTypes && msgTypes.length) {
|
|
612
|
+
where.push(`msg_type IN (${msgTypes.map(() => '?').join(', ')})`);
|
|
613
|
+
params.push(...msgTypes);
|
|
614
|
+
}
|
|
615
|
+
if (opts?.sources && opts.sources.length) {
|
|
616
|
+
where.push(`source IN (${opts.sources.map(() => '?').join(', ')})`);
|
|
617
|
+
params.push(...opts.sources);
|
|
618
|
+
}
|
|
619
|
+
const filter = where.length ? `WHERE ${where.join(' AND ')}` : '';
|
|
620
|
+
params.push(Math.max(1, count));
|
|
621
|
+
const order = `ORDER BY ts DESC, id DESC`;
|
|
596
622
|
const rows = db.prepare(`SELECT id, source, line_num, byte_offset, ts, msg_type, model, git_branch, cwd, tool_name, blob
|
|
597
|
-
FROM content ${filter}
|
|
623
|
+
FROM content WHERE id IN (SELECT id FROM content ${filter} ${order} LIMIT ?)
|
|
624
|
+
${order}`).all(...params);
|
|
598
625
|
return rows.map((row) => ({
|
|
599
626
|
id: row.id,
|
|
600
627
|
source: row.source,
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export interface SessionListSource {
|
|
2
|
+
sessionId: string;
|
|
3
|
+
projectSlug: string;
|
|
4
|
+
projectPath: string;
|
|
5
|
+
cwd: string;
|
|
6
|
+
timestamp: Date;
|
|
7
|
+
lastMessage?: string;
|
|
8
|
+
title?: string;
|
|
9
|
+
messageCount: number;
|
|
10
|
+
firstTs?: string;
|
|
11
|
+
lastActivityAt?: string;
|
|
12
|
+
fileSize?: number;
|
|
13
|
+
}
|
|
14
|
+
/** The preview fields the dashboard / session browser receive per session. */
|
|
15
|
+
export declare function sessionListEntry(s: SessionListSource): {
|
|
16
|
+
sessionId: string;
|
|
17
|
+
projectSlug: string;
|
|
18
|
+
projectPath: string;
|
|
19
|
+
cwd: string;
|
|
20
|
+
timestamp: string;
|
|
21
|
+
lastMessage: string;
|
|
22
|
+
title: string;
|
|
23
|
+
messageCount: number;
|
|
24
|
+
firstTs: string;
|
|
25
|
+
lastActivityAt: string;
|
|
26
|
+
fileSize: number;
|
|
27
|
+
};
|
|
28
|
+
export interface HistoryRow {
|
|
29
|
+
msgType: string;
|
|
30
|
+
text: string;
|
|
31
|
+
ts?: string | null;
|
|
32
|
+
}
|
|
33
|
+
export interface HistoryMessage {
|
|
34
|
+
role: 'user' | 'assistant';
|
|
35
|
+
content: string;
|
|
36
|
+
ts: string | null;
|
|
37
|
+
}
|
|
38
|
+
/** Upper bound on rows read while topping up a page (sanitizer drops). */
|
|
39
|
+
export declare const HISTORY_MAX_FETCH = 2000;
|
|
40
|
+
/**
|
|
41
|
+
* Read up to `limit` clean messages, chronological. `fetchRows(n)` returns the
|
|
42
|
+
* newest `n` rows NEWEST-FIRST (recentRows' contract). Each row is sanitized
|
|
43
|
+
* with cleanTurnText first, then truncated to `maxChars`; dropped rows (pure
|
|
44
|
+
* notices, injected blocks, [SYSTEM] lines) are replaced by fetching more,
|
|
45
|
+
* starting at 3x and doubling, until the page is full, the store is exhausted
|
|
46
|
+
* (fewer rows than asked), or HISTORY_MAX_FETCH is reached.
|
|
47
|
+
*/
|
|
48
|
+
export declare function cleanHistoryRows(fetchRows: (n: number) => HistoryRow[], limit: number, maxChars: number): HistoryMessage[];
|
|
49
|
+
/**
|
|
50
|
+
* Echo-only guard: an injected open tag with no matching close after it is cut,
|
|
51
|
+
* together with everything after it to the end of the string. The shared
|
|
52
|
+
* sanitizer deliberately keeps an inline unterminated tag (a person can say
|
|
53
|
+
* "the <system-reminder> tag is noisy"), so this lives here, not in
|
|
54
|
+
* cleanTurnText: the echo is shown to everyone in the room and must never carry
|
|
55
|
+
* a half-injected block. Closed blocks are left for cleanTurnText.
|
|
56
|
+
*/
|
|
57
|
+
export declare function cutUnclosedInjected(text: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* The text to echo as `user_transcript`, or null to send nothing. Runs the
|
|
60
|
+
* shared sanitizer (drops [time:] tags, <session_tail>, [favorited] /
|
|
61
|
+
* [welcome-back] / [SCRIPT] / [PROACTIVE] / [NOTIFICATION] / [SYSTEM] notices,
|
|
62
|
+
* unwraps [INTERRUPTED]/[CONTEXT]), then the echo's own noise filters.
|
|
63
|
+
*/
|
|
64
|
+
export declare function userEchoText(raw: string, attachments?: string): string | null;
|
|
65
|
+
export interface TypedEcho {
|
|
66
|
+
/** The frontend's id for the optimistic bubble, when it sent one. */
|
|
67
|
+
clientMsgId?: string;
|
|
68
|
+
/** Attachment blocks the agent appended to the typed text ('' = none). */
|
|
69
|
+
attachments: string;
|
|
70
|
+
}
|
|
71
|
+
/** Valid clientMsgId or undefined (string, 1..200 chars). */
|
|
72
|
+
export declare function validClientMsgId(v: unknown): string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Remembers typed messages (user_text) by their raw content so the session's
|
|
75
|
+
* echo of the same item (conversation_item_added → user_transcript) can carry
|
|
76
|
+
* the frontend's clientMsgId and keep its attachment blocks (the sanitizer
|
|
77
|
+
* strips trailing [File:]/[Image:] blocks, which the chat renders). Matches on
|
|
78
|
+
* the exact raw text first, then on the sanitized text. Entries expire after
|
|
79
|
+
* `ttlMs`; at most `max` are kept.
|
|
80
|
+
*/
|
|
81
|
+
export declare class TypedEchoTracker {
|
|
82
|
+
#private;
|
|
83
|
+
private ttlMs;
|
|
84
|
+
private max;
|
|
85
|
+
constructor(ttlMs?: number, max?: number);
|
|
86
|
+
register(rawContent: string, clientMsgId: unknown, attachments?: string, now?: number): void;
|
|
87
|
+
/** Consume and return the typed-message info for this echoed text, if any. */
|
|
88
|
+
take(rawEcho: string, now?: number): TypedEcho | undefined;
|
|
89
|
+
clear(): void;
|
|
90
|
+
get size(): number;
|
|
91
|
+
}
|
|
92
|
+
export interface FavoriteChange {
|
|
93
|
+
filePath: string;
|
|
94
|
+
fileName: string;
|
|
95
|
+
favorited: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** Validate a favorite_changed payload; null when unusable. */
|
|
98
|
+
export declare function parseFavoriteChanged(data: any): FavoriteChange | null;
|
|
99
|
+
/**
|
|
100
|
+
* Backward compatibility: an older frontend sends the favorite as
|
|
101
|
+
* `user_text` "[time: …] [favorited] The user favorited the file NAME."
|
|
102
|
+
* Returns the change when `content` is exactly that notice, else null.
|
|
103
|
+
*/
|
|
104
|
+
export declare function parseLegacyFavoriteNotice(content: string): FavoriteChange | null;
|
|
105
|
+
/**
|
|
106
|
+
* Pending client notices for the agent, delivered as hidden context on the next
|
|
107
|
+
* real user turn (never as a user turn). Keyed by file path so a favorite then
|
|
108
|
+
* an unfavorite of the same file cancels out. The drained block is a
|
|
109
|
+
* <system-reminder>, which the shared sanitizer (lens-strip) removes from
|
|
110
|
+
* history, titles and echoes while keeping the user's own words.
|
|
111
|
+
*/
|
|
112
|
+
export declare class ClientNoteQueue {
|
|
113
|
+
#private;
|
|
114
|
+
private max;
|
|
115
|
+
constructor(max?: number);
|
|
116
|
+
favoriteChanged(raw: FavoriteChange): void;
|
|
117
|
+
get size(): number;
|
|
118
|
+
clear(): void;
|
|
119
|
+
/** Return the pending notes as one hidden-context block and clear them; '' when none. */
|
|
120
|
+
drain(): string;
|
|
121
|
+
}
|