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/config.js
CHANGED
|
@@ -2,6 +2,7 @@ import { readFileSync, existsSync, mkdirSync, writeFileSync, renameSync } from '
|
|
|
2
2
|
import { homedir } from 'os';
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
import { parse, stringify } from 'yaml';
|
|
5
|
+
import { cleanTurnText } from './content/transcript-sanitizer.js';
|
|
5
6
|
// Config file paths
|
|
6
7
|
const CONFIG_DIR = join(homedir(), '.osborn');
|
|
7
8
|
const CONFIG_FILE = join(CONFIG_DIR, 'config.yaml');
|
|
@@ -452,6 +453,7 @@ export async function listSessions(projectPath) {
|
|
|
452
453
|
projectPath: targetPath,
|
|
453
454
|
timestamp: stats.mtime,
|
|
454
455
|
lastMessage: info.lastMessage,
|
|
456
|
+
title: info.title,
|
|
455
457
|
messageCount: info.messageCount,
|
|
456
458
|
filePath,
|
|
457
459
|
});
|
|
@@ -466,11 +468,74 @@ export async function listSessions(projectPath) {
|
|
|
466
468
|
sessions.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime());
|
|
467
469
|
return sessions;
|
|
468
470
|
}
|
|
469
|
-
|
|
471
|
+
const PREVIEW_LAST_CHARS = 100;
|
|
472
|
+
const PREVIEW_TITLE_CHARS = 120;
|
|
473
|
+
/** User-entry text: string content, or the text parts of an array that is not a tool_result. */
|
|
474
|
+
function previewUserText(content) {
|
|
475
|
+
if (typeof content === 'string')
|
|
476
|
+
return content;
|
|
477
|
+
if (!Array.isArray(content))
|
|
478
|
+
return null;
|
|
479
|
+
if (content[0]?.type === 'tool_result')
|
|
480
|
+
return null;
|
|
481
|
+
const texts = content.filter((p) => p?.type === 'text' && typeof p.text === 'string').map((p) => p.text);
|
|
482
|
+
return texts.length ? texts.join('\n') : null;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Fold one parsed JSONL entry into the preview accumulator. ONE definition shared
|
|
486
|
+
* by the small-file and the head/tail paths (UI#1: the old counter incremented on
|
|
487
|
+
* every user/assistant record, i.e. tool round-trips and split assistant chunks).
|
|
488
|
+
* Text is sanitized by the shared transcript sanitizer BEFORE truncation, so a
|
|
489
|
+
* wrapped turn ([INTERRUPTED] puts the user's words last) still yields its words
|
|
490
|
+
* and a notice-only turn ([favorited], [SYSTEM], ...) is not a title or a turn.
|
|
491
|
+
*/
|
|
492
|
+
function accumulatePreviewEntry(acc, entry) {
|
|
493
|
+
if (!entry || typeof entry !== 'object')
|
|
494
|
+
return;
|
|
495
|
+
if (!acc.firstTs && typeof entry.timestamp === 'string' && entry.timestamp)
|
|
496
|
+
acc.firstTs = entry.timestamp;
|
|
497
|
+
if (entry.type === 'ai-title' && typeof entry.aiTitle === 'string') {
|
|
498
|
+
const t = cleanTurnText(entry.aiTitle, 'assistant');
|
|
499
|
+
if (t)
|
|
500
|
+
acc.aiTitle = t.substring(0, PREVIEW_TITLE_CHARS);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (entry.isMeta)
|
|
504
|
+
return;
|
|
505
|
+
if (entry.type === 'user') {
|
|
506
|
+
const raw = previewUserText(entry.message?.content);
|
|
507
|
+
if (raw === null)
|
|
508
|
+
return;
|
|
509
|
+
const clean = cleanTurnText(raw, 'user');
|
|
510
|
+
if (!clean)
|
|
511
|
+
return;
|
|
512
|
+
acc.count++;
|
|
513
|
+
acc.lastAsstId = undefined;
|
|
514
|
+
if (acc.firstUser === undefined)
|
|
515
|
+
acc.firstUser = clean.substring(0, PREVIEW_TITLE_CHARS);
|
|
516
|
+
acc.lastUser = clean.substring(0, PREVIEW_LAST_CHARS);
|
|
517
|
+
if (typeof entry.timestamp === 'string' && entry.timestamp)
|
|
518
|
+
acc.lastTs = entry.timestamp;
|
|
519
|
+
}
|
|
520
|
+
else if (entry.type === 'assistant') {
|
|
521
|
+
const content = entry.message?.content;
|
|
522
|
+
const hasText = typeof content === 'string'
|
|
523
|
+
? content.trim().length > 0
|
|
524
|
+
: Array.isArray(content) && content.some((p) => p?.type === 'text' && typeof p.text === 'string' && p.text.trim());
|
|
525
|
+
if (!hasText)
|
|
526
|
+
return;
|
|
527
|
+
const id = typeof entry.message?.id === 'string' ? entry.message.id : undefined;
|
|
528
|
+
if (!(id && id === acc.lastAsstId))
|
|
529
|
+
acc.count++;
|
|
530
|
+
acc.lastAsstId = id;
|
|
531
|
+
if (typeof entry.timestamp === 'string' && entry.timestamp)
|
|
532
|
+
acc.lastTs = entry.timestamp;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
/** Parse JSONL text into a preview accumulator. */
|
|
470
536
|
function scanPreviewLines(text, skipFirstPartial) {
|
|
471
537
|
const lines = text.split('\n');
|
|
472
|
-
|
|
473
|
-
let lastUser;
|
|
538
|
+
const acc = { count: 0 };
|
|
474
539
|
// A tail slice usually begins mid-line — drop that fragment so JSON.parse
|
|
475
540
|
// doesn't choke on it (and never counts a half-record).
|
|
476
541
|
for (let i = skipFirstPartial ? 1 : 0; i < lines.length; i++) {
|
|
@@ -478,38 +543,26 @@ function scanPreviewLines(text, skipFirstPartial) {
|
|
|
478
543
|
if (!line)
|
|
479
544
|
continue;
|
|
480
545
|
try {
|
|
481
|
-
|
|
482
|
-
if (entry.type === 'user' || entry.type === 'assistant')
|
|
483
|
-
count++;
|
|
484
|
-
if (entry.type === 'user' && entry.message?.content) {
|
|
485
|
-
const content = entry.message.content;
|
|
486
|
-
if (typeof content === 'string')
|
|
487
|
-
lastUser = content.substring(0, 100);
|
|
488
|
-
else if (Array.isArray(content)) {
|
|
489
|
-
const textPart = content.find((p) => p.type === 'text');
|
|
490
|
-
if (textPart?.text)
|
|
491
|
-
lastUser = textPart.text.substring(0, 100);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
546
|
+
accumulatePreviewEntry(acc, JSON.parse(line));
|
|
494
547
|
}
|
|
495
548
|
catch {
|
|
496
549
|
// skip malformed / partial line
|
|
497
550
|
}
|
|
498
551
|
}
|
|
499
|
-
return
|
|
552
|
+
return acc;
|
|
500
553
|
}
|
|
501
554
|
/**
|
|
502
|
-
* Get a preview of a session (last message
|
|
555
|
+
* Get a preview of a session (title, last message, turn count, first/last activity).
|
|
503
556
|
*
|
|
504
557
|
* PERF (sub-second-connect initiative): this used to stream and JSON.parse the
|
|
505
558
|
* ENTIRE transcript — which meant the dashboard session list read a 155–323MB
|
|
506
559
|
* JSONL end-to-end per cold load (the ~30s dashboard stall measured in the
|
|
507
560
|
* connect video). The preview only needs (a) enough to clear the ">2 messages"
|
|
508
561
|
* gate and (b) the LAST user message. So: small files are read whole (exact);
|
|
509
|
-
* large files read a bounded HEAD (gate + density sample
|
|
510
|
-
* message), turning a hundreds-of-MB parse into
|
|
511
|
-
* estimate for large files — it's display-only
|
|
512
|
-
* large session clears from the head alone.
|
|
562
|
+
* large files read a bounded HEAD (gate + density sample + first turn/title) +
|
|
563
|
+
* TAIL (last user message, last activity), turning a hundreds-of-MB parse into
|
|
564
|
+
* ~192KB. messageCount becomes an estimate for large files — it's display-only
|
|
565
|
+
* and gated on ">2", which any large session clears from the head alone.
|
|
513
566
|
*/
|
|
514
567
|
async function getSessionPreview(filePath, fileSize) {
|
|
515
568
|
const HEAD = 64 * 1024;
|
|
@@ -519,33 +572,26 @@ async function getSessionPreview(filePath, fileSize) {
|
|
|
519
572
|
if (size <= HEAD + TAIL) {
|
|
520
573
|
// Small enough to read whole — exact count + last message (cheap).
|
|
521
574
|
const whole = await new Promise((resolve) => {
|
|
522
|
-
|
|
523
|
-
let lastUser;
|
|
575
|
+
const acc = { count: 0 };
|
|
524
576
|
const rl = readline.createInterface({ input: createReadStream(filePath), crlfDelay: Infinity });
|
|
525
577
|
rl.on('line', (line) => {
|
|
526
578
|
if (!line.trim())
|
|
527
579
|
return;
|
|
528
580
|
try {
|
|
529
|
-
|
|
530
|
-
if (entry.type === 'user' || entry.type === 'assistant')
|
|
531
|
-
count++;
|
|
532
|
-
if (entry.type === 'user' && entry.message?.content) {
|
|
533
|
-
const content = entry.message.content;
|
|
534
|
-
if (typeof content === 'string')
|
|
535
|
-
lastUser = content.substring(0, 100);
|
|
536
|
-
else if (Array.isArray(content)) {
|
|
537
|
-
const textPart = content.find((p) => p.type === 'text');
|
|
538
|
-
if (textPart?.text)
|
|
539
|
-
lastUser = textPart.text.substring(0, 100);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
581
|
+
accumulatePreviewEntry(acc, JSON.parse(line));
|
|
542
582
|
}
|
|
543
583
|
catch { /* skip */ }
|
|
544
584
|
});
|
|
545
|
-
rl.on('close', () => resolve(
|
|
585
|
+
rl.on('close', () => resolve(acc));
|
|
546
586
|
rl.on('error', () => resolve({ count: 0 }));
|
|
547
587
|
});
|
|
548
|
-
return {
|
|
588
|
+
return {
|
|
589
|
+
lastMessage: whole.lastUser,
|
|
590
|
+
title: whole.aiTitle ?? whole.firstUser,
|
|
591
|
+
messageCount: whole.count,
|
|
592
|
+
firstTs: whole.firstTs,
|
|
593
|
+
lastActivityAt: whole.lastTs,
|
|
594
|
+
};
|
|
549
595
|
}
|
|
550
596
|
// Large file: bounded head + tail only.
|
|
551
597
|
const fd = openSync(filePath, 'r');
|
|
@@ -561,7 +607,13 @@ async function getSessionPreview(filePath, fileSize) {
|
|
|
561
607
|
// by head.count alone for any real large session.
|
|
562
608
|
const avg = head.count > 0 ? hn / head.count : hn;
|
|
563
609
|
const messageCount = head.count >= 3 ? Math.max(3, Math.round(size / avg)) : head.count;
|
|
564
|
-
return {
|
|
610
|
+
return {
|
|
611
|
+
lastMessage,
|
|
612
|
+
title: tail.aiTitle ?? head.aiTitle ?? head.firstUser,
|
|
613
|
+
messageCount,
|
|
614
|
+
firstTs: head.firstTs,
|
|
615
|
+
lastActivityAt: tail.lastTs ?? head.lastTs,
|
|
616
|
+
};
|
|
565
617
|
}
|
|
566
618
|
finally {
|
|
567
619
|
closeSync(fd);
|
|
@@ -674,7 +726,9 @@ const SESSION_LIST_TTL_MS = 300_000;
|
|
|
674
726
|
export function invalidateSessionListCache() {
|
|
675
727
|
_sessionListCache = null;
|
|
676
728
|
}
|
|
677
|
-
|
|
729
|
+
// v2: sanitized lastMessage, title, firstTs, lastActivityAt, corrected turn count.
|
|
730
|
+
// A v1 manifest is discarded on load (its previews carry raw wrapper text).
|
|
731
|
+
const SESSION_MANIFEST_VERSION = 2;
|
|
678
732
|
function sessionManifestPath() {
|
|
679
733
|
return join(homedir(), '.claude', 'session-manifest.json');
|
|
680
734
|
}
|
|
@@ -771,13 +825,18 @@ export async function listAllClaudeSessions(limit = 1000, includeSubagents = fal
|
|
|
771
825
|
const hit = manifest.entries[c.filePath];
|
|
772
826
|
if (hit && hit.mtimeMs === c.mtime.getTime() && hit.size === c.size) {
|
|
773
827
|
// Unchanged since last build — reuse cached preview + cwd, skip the read.
|
|
774
|
-
|
|
828
|
+
const preview = {
|
|
829
|
+
lastMessage: hit.lastMessage, title: hit.title, messageCount: hit.messageCount,
|
|
830
|
+
firstTs: hit.firstTs, lastActivityAt: hit.lastActivityAt,
|
|
831
|
+
};
|
|
832
|
+
return { c, preview, cwd: hit.cwd };
|
|
775
833
|
}
|
|
776
834
|
try {
|
|
777
835
|
const [preview, cwd] = await Promise.all([getSessionPreview(c.filePath, c.size), extractCwd(c.filePath)]);
|
|
778
836
|
manifest.entries[c.filePath] = {
|
|
779
837
|
mtimeMs: c.mtime.getTime(), size: c.size,
|
|
780
838
|
lastMessage: preview.lastMessage, messageCount: preview.messageCount, cwd,
|
|
839
|
+
title: preview.title, firstTs: preview.firstTs, lastActivityAt: preview.lastActivityAt,
|
|
781
840
|
};
|
|
782
841
|
manifestDirty = true;
|
|
783
842
|
return { c, preview, cwd };
|
|
@@ -845,7 +904,10 @@ export async function listAllClaudeSessions(limit = 1000, includeSubagents = fal
|
|
|
845
904
|
cwd: slugPath || cwd, // resume routing (file location)
|
|
846
905
|
timestamp: c.mtime,
|
|
847
906
|
lastMessage: preview.lastMessage,
|
|
907
|
+
title: preview.title,
|
|
848
908
|
messageCount: preview.messageCount,
|
|
909
|
+
firstTs: preview.firstTs,
|
|
910
|
+
lastActivityAt: preview.lastActivityAt,
|
|
849
911
|
filePath: c.filePath,
|
|
850
912
|
fileSize: c.size,
|
|
851
913
|
});
|
|
@@ -864,7 +926,7 @@ export async function getSessionSummary(sessionId, projectPath) {
|
|
|
864
926
|
return null;
|
|
865
927
|
// Parse JSONL to extract last messages
|
|
866
928
|
const lastMessages = [];
|
|
867
|
-
|
|
929
|
+
const acc = { count: 0 };
|
|
868
930
|
return new Promise((resolve) => {
|
|
869
931
|
const fileStream = createReadStream(filePath);
|
|
870
932
|
const rl = readline.createInterface({
|
|
@@ -875,24 +937,14 @@ export async function getSessionSummary(sessionId, projectPath) {
|
|
|
875
937
|
if (!line.trim())
|
|
876
938
|
return;
|
|
877
939
|
try {
|
|
940
|
+
// Shared accumulator (L2b): real turns only (no tool round-trips, split
|
|
941
|
+
// assistant messages once) and user text sanitized BEFORE truncation,
|
|
942
|
+
// so notices / injected blocks are neither counted nor summarized.
|
|
878
943
|
const entry = JSON.parse(line);
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
if (entry.type === 'user' && entry.message?.content) {
|
|
884
|
-
const content = entry.message.content;
|
|
885
|
-
let text;
|
|
886
|
-
if (typeof content === 'string') {
|
|
887
|
-
text = content;
|
|
888
|
-
}
|
|
889
|
-
else if (Array.isArray(content)) {
|
|
890
|
-
const textPart = content.find((p) => p.type === 'text');
|
|
891
|
-
text = textPart?.text;
|
|
892
|
-
}
|
|
893
|
-
if (text) {
|
|
894
|
-
lastMessages.push(text.substring(0, 100));
|
|
895
|
-
}
|
|
944
|
+
const before = acc.count;
|
|
945
|
+
accumulatePreviewEntry(acc, entry);
|
|
946
|
+
if (entry?.type === 'user' && acc.count > before && acc.lastUser !== undefined) {
|
|
947
|
+
lastMessages.push(acc.lastUser);
|
|
896
948
|
}
|
|
897
949
|
}
|
|
898
950
|
catch {
|
|
@@ -902,7 +954,7 @@ export async function getSessionSummary(sessionId, projectPath) {
|
|
|
902
954
|
rl.on('close', () => {
|
|
903
955
|
resolve({
|
|
904
956
|
sessionId,
|
|
905
|
-
messageCount,
|
|
957
|
+
messageCount: acc.count,
|
|
906
958
|
lastMessages: lastMessages.slice(-5), // Last 5 user messages
|
|
907
959
|
});
|
|
908
960
|
});
|
|
@@ -950,9 +1002,14 @@ export async function getConversationHistory(sessionId, projectPath, limit = 10)
|
|
|
950
1002
|
for (const line of lines) {
|
|
951
1003
|
try {
|
|
952
1004
|
const msg = JSON.parse(line);
|
|
953
|
-
|
|
1005
|
+
if (msg.isMeta)
|
|
1006
|
+
continue;
|
|
1007
|
+
// Shared sanitizer (L2b): clean BEFORE truncating, and drop rows with
|
|
1008
|
+
// nothing real left (notices, injected blocks, tool_result-only user
|
|
1009
|
+
// rows), so they never take one of the `limit` slots.
|
|
954
1010
|
if (msg.type === 'user' && msg.message?.content) {
|
|
955
|
-
const
|
|
1011
|
+
const raw = previewUserText(msg.message.content);
|
|
1012
|
+
const text = raw === null ? null : cleanTurnText(raw, 'user');
|
|
956
1013
|
if (text) {
|
|
957
1014
|
exchanges.push({
|
|
958
1015
|
role: 'user',
|
|
@@ -960,9 +1017,9 @@ export async function getConversationHistory(sessionId, projectPath, limit = 10)
|
|
|
960
1017
|
});
|
|
961
1018
|
}
|
|
962
1019
|
}
|
|
963
|
-
// Extract assistant messages
|
|
964
1020
|
if (msg.type === 'assistant' && msg.message?.content) {
|
|
965
|
-
const
|
|
1021
|
+
const raw = extractTextContent(msg.message.content);
|
|
1022
|
+
const text = raw === null ? null : cleanTurnText(raw, 'assistant');
|
|
966
1023
|
if (text) {
|
|
967
1024
|
exchanges.push({
|
|
968
1025
|
role: 'assistant',
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* transcript-sanitizer.ts
|
|
3
3
|
* ------------------------------------------------------------------------
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* THE shared transcript sanitizer. Started as the offline sanitizer for the
|
|
5
|
+
* Osborn content pipeline; it is now also the ONE place the live agent cleans
|
|
6
|
+
* pipeline wrapper text before it reaches titles, chat or the dashboard
|
|
7
|
+
* (`cleanTurnText`, used by config.ts getSessionPreview and the
|
|
8
|
+
* pipeline-direct-llm.ts session tail). It reads a saved transcript (session
|
|
9
|
+
* JSONL today; arbitrary text / media later) and emits clean, per-utterance
|
|
10
|
+
* USER-speech records with live credentials masked out. The frontend keeps a
|
|
11
|
+
* display port of the same rules in frontend/src/lib/transcript-clean.ts.
|
|
10
12
|
*
|
|
11
13
|
* It only *references* the live agent's marker formats (read-only) to stay
|
|
12
14
|
* faithful to what the runtime actually writes:
|
|
@@ -136,6 +138,18 @@ export declare function detectSecrets(text: string, opts?: SecretScanOptions): {
|
|
|
136
138
|
* filter on that — every real utterance is included.
|
|
137
139
|
*/
|
|
138
140
|
export declare function sanitizeRecord(raw: RawRecord): SanitizeOutcome;
|
|
141
|
+
/**
|
|
142
|
+
* ONE-CALL cleaner for a single turn's text, used by the live agent data path
|
|
143
|
+
* (session titles / previews, the post-compaction session tail). Composes the
|
|
144
|
+
* injected-block stripper (lens-strip.ts: <session_tail>, <recalled_context>,
|
|
145
|
+
* <system-reminder>, <task-notification>, hook context, compaction summaries,
|
|
146
|
+
* silent-control lines; user turns only) with `sanitizeRecord` ([time:] tags,
|
|
147
|
+
* drop markers, [INTERRUPTED]/[CONTEXT] unwrap, attachments, secret redaction).
|
|
148
|
+
* Returns the cleaned text, or null when nothing the person/assistant actually
|
|
149
|
+
* said remains. Pure. ALWAYS sanitize before truncating: the [INTERRUPTED]
|
|
150
|
+
* template puts the user's words last, past any short preview window.
|
|
151
|
+
*/
|
|
152
|
+
export declare function cleanTurnText(text: string, speaker?: 'user' | 'assistant'): string | null;
|
|
139
153
|
/** Run the core over a record stream and return kept SanitizedRecords. Pure. */
|
|
140
154
|
export declare function sanitizeTranscript(records: Iterable<RawRecord>): SanitizedRecord[];
|
|
141
155
|
/** Like sanitizeTranscript but also returns drop/unwrap/clean counts. Pure. */
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* transcript-sanitizer.ts
|
|
3
3
|
* ------------------------------------------------------------------------
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* THE shared transcript sanitizer. Started as the offline sanitizer for the
|
|
5
|
+
* Osborn content pipeline; it is now also the ONE place the live agent cleans
|
|
6
|
+
* pipeline wrapper text before it reaches titles, chat or the dashboard
|
|
7
|
+
* (`cleanTurnText`, used by config.ts getSessionPreview and the
|
|
8
|
+
* pipeline-direct-llm.ts session tail). It reads a saved transcript (session
|
|
9
|
+
* JSONL today; arbitrary text / media later) and emits clean, per-utterance
|
|
10
|
+
* USER-speech records with live credentials masked out. The frontend keeps a
|
|
11
|
+
* display port of the same rules in frontend/src/lib/transcript-clean.ts.
|
|
10
12
|
*
|
|
11
13
|
* It only *references* the live agent's marker formats (read-only) to stay
|
|
12
14
|
* faithful to what the runtime actually writes:
|
|
@@ -32,6 +34,7 @@
|
|
|
32
34
|
* ================================================================
|
|
33
35
|
*/
|
|
34
36
|
import { readFileSync } from 'node:fs';
|
|
37
|
+
import { stripInjected } from './lens-strip.js';
|
|
35
38
|
/**
|
|
36
39
|
* Order matters. Specific, high-confidence token shapes run FIRST so their KIND
|
|
37
40
|
* label wins; the broad `*_API_KEY=/_SECRET=/_TOKEN=` assignment rule runs LAST
|
|
@@ -217,7 +220,14 @@ const DROP_PREFIXES = [
|
|
|
217
220
|
/^\[EMERGENCY STOP\]/,
|
|
218
221
|
/^\[BACKGROUND_INIT\]/,
|
|
219
222
|
/^\[liked\]/,
|
|
220
|
-
|
|
223
|
+
// Client notices sent as user_text by the frontend (VoiceRoom.tsx), never speech.
|
|
224
|
+
/^\[favorited\]/,
|
|
225
|
+
/^\[welcome-back\]/,
|
|
226
|
+
// Voice-queue injections (index.ts filters these from the echo too).
|
|
227
|
+
/^\[(?:SCRIPT|PROACTIVE|NOTIFICATION)\]/,
|
|
228
|
+
// [SYSTEM], [SYSTEM — SILENT CONTROL MESSAGE …], [SYSTEM: …], [SYSTEM - …];
|
|
229
|
+
// NOT a real message that merely starts with "[SYSTEM design] …".
|
|
230
|
+
/^\[SYSTEM(?:\]|\s*[—:-])/,
|
|
221
231
|
/^\[MEETING —/,
|
|
222
232
|
/^This session is being continued/,
|
|
223
233
|
/^<system-reminder>/,
|
|
@@ -301,10 +311,14 @@ function stripTrailingAttachments(text) {
|
|
|
301
311
|
export function sanitizeRecord(raw) {
|
|
302
312
|
let text = raw.text ?? '';
|
|
303
313
|
let wrapped = false;
|
|
304
|
-
// A. Leading post-compaction session tail (confirmed anchor)
|
|
305
|
-
|
|
306
|
-
//
|
|
307
|
-
|
|
314
|
+
// A+B. Leading post-compaction session tail (confirmed anchor) and leading
|
|
315
|
+
// [time: …] prefix, in either order (the frontend tags typed text before the
|
|
316
|
+
// agent prepends the tail, but older rows can carry the tag first). Repeat
|
|
317
|
+
// until stable.
|
|
318
|
+
for (let prev = ''; prev !== text;) {
|
|
319
|
+
prev = text;
|
|
320
|
+
text = text.replace(SESSION_TAIL_RE, '').replace(TIME_PREFIX_RE, '');
|
|
321
|
+
}
|
|
308
322
|
const lead = text.trimStart();
|
|
309
323
|
// C. Drop markers.
|
|
310
324
|
for (const re of DROP_PREFIXES) {
|
|
@@ -326,6 +340,16 @@ export function sanitizeRecord(raw) {
|
|
|
326
340
|
text = inner;
|
|
327
341
|
wrapped = true;
|
|
328
342
|
}
|
|
343
|
+
// The quoted user words inside a template still carry the frontend's
|
|
344
|
+
// [time: …] tag (typed turns); strip it, then re-check the drop markers
|
|
345
|
+
// (an interrupted [favorited] notice is still a notice).
|
|
346
|
+
if (wrapped) {
|
|
347
|
+
text = text.trimStart().replace(TIME_PREFIX_RE, '');
|
|
348
|
+
for (const re of DROP_PREFIXES) {
|
|
349
|
+
if (re.test(text))
|
|
350
|
+
return { record: null, action: 'drop' };
|
|
351
|
+
}
|
|
352
|
+
}
|
|
329
353
|
// E. Trailing attachments.
|
|
330
354
|
text = stripTrailingAttachments(text);
|
|
331
355
|
// F. Secret redaction (on the final kept text). Assistant records also get
|
|
@@ -341,6 +365,37 @@ export function sanitizeRecord(raw) {
|
|
|
341
365
|
action: wrapped ? 'unwrap' : 'clean',
|
|
342
366
|
};
|
|
343
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* ONE-CALL cleaner for a single turn's text, used by the live agent data path
|
|
370
|
+
* (session titles / previews, the post-compaction session tail). Composes the
|
|
371
|
+
* injected-block stripper (lens-strip.ts: <session_tail>, <recalled_context>,
|
|
372
|
+
* <system-reminder>, <task-notification>, hook context, compaction summaries,
|
|
373
|
+
* silent-control lines; user turns only) with `sanitizeRecord` ([time:] tags,
|
|
374
|
+
* drop markers, [INTERRUPTED]/[CONTEXT] unwrap, attachments, secret redaction).
|
|
375
|
+
* Returns the cleaned text, or null when nothing the person/assistant actually
|
|
376
|
+
* said remains. Pure. ALWAYS sanitize before truncating: the [INTERRUPTED]
|
|
377
|
+
* template puts the user's words last, past any short preview window.
|
|
378
|
+
*/
|
|
379
|
+
export function cleanTurnText(text, speaker = 'user') {
|
|
380
|
+
const raw = typeof text === 'string' ? text : '';
|
|
381
|
+
if (!raw.trim())
|
|
382
|
+
return null;
|
|
383
|
+
let body = raw;
|
|
384
|
+
if (speaker === 'user') {
|
|
385
|
+
// Injected blocks can sit anywhere in a user row (lens-strip tolerates a
|
|
386
|
+
// leading [time:] before a line-start block).
|
|
387
|
+
body = stripInjected(raw, 'user').text;
|
|
388
|
+
if (body === null)
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
const { record } = sanitizeRecord({ text: body, timestamp: '', speaker });
|
|
392
|
+
if (!record)
|
|
393
|
+
return null;
|
|
394
|
+
// A tail stripped mid-text can leave the next template's bare marker behind
|
|
395
|
+
// ("words\n\n[INTERRUPTED]"); it is never the person's words.
|
|
396
|
+
const out = record.text.replace(/\s*\[INTERRUPTED\]\s*$/, '').trim();
|
|
397
|
+
return out || null;
|
|
398
|
+
}
|
|
344
399
|
/** Run the core over a record stream and return kept SanitizedRecords. Pure. */
|
|
345
400
|
export function sanitizeTranscript(records) {
|
|
346
401
|
const out = [];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-sender-auth.ts — who may send data-channel commands, and who may become
|
|
3
|
+
* the controller.
|
|
4
|
+
*
|
|
5
|
+
* Every message on topic 'user-input' is handled by handleDataReceived in
|
|
6
|
+
* index.ts. All of them EXCEPT the read-only queries in READ_ONLY_MESSAGE_TYPES
|
|
7
|
+
* must come from the controlling user participant: the `user-*` identity
|
|
8
|
+
* minted by the frontend /api/token (auth-gated, checks room ownership) that
|
|
9
|
+
* the agent adopted as its voice user. Canvas, bots and other identities are
|
|
10
|
+
* dropped. The gate FAILS CLOSED: a type that is not on the read-only list
|
|
11
|
+
* (including any new type added to index.ts later) requires the controller.
|
|
12
|
+
*
|
|
13
|
+
* Full set of types handleDataReceived handles (2026-11-07):
|
|
14
|
+
* Gated (state-changing or leaks session/process ids):
|
|
15
|
+
* user_text, claude_auth_code, permission_response, list_sessions,
|
|
16
|
+
* resume_session, continue_session, switch_session, session_selected,
|
|
17
|
+
* mcp_toggle, set_agents, skill_add, skill_remove, noise_cancel,
|
|
18
|
+
* gate_send_anyway, stop_dispatch, join_meeting, leave_meeting,
|
|
19
|
+
* mute_participant, start_ide, stop_ide, spawn_background_session,
|
|
20
|
+
* dispatch_background, stop_background_session, list_slots, list_processes,
|
|
21
|
+
* favorite_changed
|
|
22
|
+
* Open (read-only, listed in READ_ONLY_MESSAGE_TYPES):
|
|
23
|
+
* get_current_session, get_session_artifacts, get_plan_file,
|
|
24
|
+
* get_research_artifact, get_mcp_status, get_skills, get_agents, skill_get
|
|
25
|
+
* list_sessions / list_slots / list_processes are read-only but return session
|
|
26
|
+
* and process ids that the gated commands (dispatch_background etc.) take as
|
|
27
|
+
* targets, so they are gated too.
|
|
28
|
+
*
|
|
29
|
+
* Controller binding (canBecomeController): when the machine has an owner
|
|
30
|
+
* (OSBORN_OWNER_USER_ID, baked into machine env by the frontend provisioning),
|
|
31
|
+
* only a participant whose SIGNED token metadata userId equals the owner can
|
|
32
|
+
* become the controller. With no owner configured (single-tenant / local
|
|
33
|
+
* mode) the newest joiner becomes the controller, as before.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Known gated types. Informational and for tests: the gate itself is "not
|
|
37
|
+
* read-only", so types missing from this list are still gated.
|
|
38
|
+
*/
|
|
39
|
+
export declare const CONTROL_MESSAGE_TYPES: ReadonlySet<string>;
|
|
40
|
+
/** Read-only queries any participant may send. Everything else is gated. */
|
|
41
|
+
export declare const READ_ONLY_MESSAGE_TYPES: ReadonlySet<string>;
|
|
42
|
+
/** Identity prefix /api/token gives every user participant. */
|
|
43
|
+
export declare const USER_IDENTITY_PREFIX = "user-";
|
|
44
|
+
/**
|
|
45
|
+
* Identity the agent itself mints (mintAgentToken). The watch gateway joins
|
|
46
|
+
* with it and relays watch Approve/Deny as `permission_response`. Only the
|
|
47
|
+
* agent's own API secret can mint it, so it is trusted for approvals but not
|
|
48
|
+
* for anything else.
|
|
49
|
+
*/
|
|
50
|
+
export declare const AGENT_SELF_IDENTITY = "osborn-agent";
|
|
51
|
+
export interface SenderCheck {
|
|
52
|
+
ok: boolean;
|
|
53
|
+
reason?: string;
|
|
54
|
+
}
|
|
55
|
+
export declare function checkControlSender(type: string, senderIdentity: string | undefined | null, controllingIdentity: string | null): SenderCheck;
|
|
56
|
+
/**
|
|
57
|
+
* May a joining participant become the controller?
|
|
58
|
+
* - Owner configured: only when the participant's token userId matches it.
|
|
59
|
+
* - No owner configured (single-tenant / local): yes (newest joiner wins).
|
|
60
|
+
*/
|
|
61
|
+
export declare function canBecomeController(participantUserId: string | undefined | null, ownerUserId: string | undefined | null): boolean;
|
|
62
|
+
export interface JoinDecision {
|
|
63
|
+
/** Build the voice session for this joiner (index.ts participantConnectedHandler). */
|
|
64
|
+
adoptSession: boolean;
|
|
65
|
+
/** Controlling identity after this join. */
|
|
66
|
+
controller: string | null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* What a non-canvas participant joining the room changes. Pure, so the
|
|
70
|
+
* controller rules are testable without LiveKit.
|
|
71
|
+
* - `user-*` joiner allowed by canBecomeController: gets the session and
|
|
72
|
+
* becomes the controller (newest eligible joiner wins).
|
|
73
|
+
* - `user-*` joiner that is not the owner: ignored entirely.
|
|
74
|
+
* - The agent's own identity (watch gateway): NEVER becomes the controller,
|
|
75
|
+
* so the owner's commands keep working; it can still send
|
|
76
|
+
* permission_response (checkControlSender). It gets the voice session only
|
|
77
|
+
* when it joins with no controller (the opt-in watch voice path that hears
|
|
78
|
+
* the watch mic). When a controller already exists it is NOT adopted: the
|
|
79
|
+
* full session rebuild would tear down the owner's live session and reset
|
|
80
|
+
* currentUserId to '' (the gateway's token has no metadata).
|
|
81
|
+
* - Any other identity: never the controller; gets a session only in
|
|
82
|
+
* single-tenant mode (no owner), matching the old behavior there.
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolveJoin(joinerIdentity: string, joinerUserId: string | undefined | null, ownerUserId: string | undefined | null, currentController: string | null): JoinDecision;
|
|
85
|
+
/**
|
|
86
|
+
* userId from a participant's token metadata (JSON set by /api/token and signed
|
|
87
|
+
* into the JWT). Participants cannot change their own metadata unless the token
|
|
88
|
+
* grants canUpdateOwnMetadata, which /api/token sets to false.
|
|
89
|
+
*/
|
|
90
|
+
export declare function userIdFromMetadata(metadata: string | undefined | null): string | undefined;
|