osborn 0.9.271 → 0.9.275
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-auth.d.ts +85 -6
- package/dist/claude-auth.js +202 -22
- package/dist/claude-llm.d.ts +13 -0
- package/dist/claude-llm.js +171 -25
- 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 +158 -0
- package/dist/duck.d.ts +8 -0
- package/dist/duck.js +59 -0
- package/dist/env-keys.js +11 -0
- package/dist/index.js +493 -97
- package/dist/lib/safe-artifact-path.d.ts +17 -0
- package/dist/lib/safe-artifact-path.js +129 -0
- package/dist/meeting-addressing.d.ts +176 -0
- package/dist/meeting-addressing.js +288 -0
- package/dist/pipeline-direct-llm.d.ts +52 -1
- package/dist/pipeline-direct-llm.js +206 -61
- 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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type ArtifactRoot = 'osb' | 'osbornSessions' | 'osbornResearch' | 'plans';
|
|
2
|
+
/**
|
|
3
|
+
* Default root set for the session-workspace read + write gates. Mirrors the
|
|
4
|
+
* roots the old substring checks intended: the per-session `/osb/` workspace
|
|
5
|
+
* plus the two legacy `.osborn/` locations. (`plans` is opt-in — only the plan
|
|
6
|
+
* read handler allows it.)
|
|
7
|
+
*/
|
|
8
|
+
export declare const WORKSPACE_ROOTS: ArtifactRoot[];
|
|
9
|
+
/**
|
|
10
|
+
* True iff `filePath` resolves to a location strictly inside one of the
|
|
11
|
+
* `allowed` roots. Rejects null bytes, `..` traversal and absolute escapes
|
|
12
|
+
* implicitly via the resolve()+canonicalize()+prefix test — never a substring.
|
|
13
|
+
*
|
|
14
|
+
* @param filePath caller-supplied path (may be relative or not-yet-existing)
|
|
15
|
+
* @param allowed which roots to accept (defaults to the workspace roots)
|
|
16
|
+
*/
|
|
17
|
+
export declare function isSafeArtifactPath(filePath: string, allowed?: ArtifactRoot[]): boolean;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Robust path validation for the artifact read gate and the write /
|
|
3
|
+
* auto-approve permission gates.
|
|
4
|
+
*
|
|
5
|
+
* ── Why this exists ─────────────────────────────────────────────────────────
|
|
6
|
+
* The pre-existing gates tested membership with a SUBSTRING check, e.g.
|
|
7
|
+
* filePath.includes('/osb/')
|
|
8
|
+
* filePath.includes('.osborn/sessions/')
|
|
9
|
+
* filePath.includes('.osborn/research/')
|
|
10
|
+
* filePath.includes('.claude/plans/')
|
|
11
|
+
* A substring test is trivially defeated by `..` traversal: a path like
|
|
12
|
+
* /workspace/osb/../../../etc/passwd
|
|
13
|
+
* /tmp/osb/../../etc/passwd
|
|
14
|
+
* contains the literal substring "/osb/" yet RESOLVES to a file outside the
|
|
15
|
+
* workspace. The `get_research_artifact` / `get_plan_file` data-channel
|
|
16
|
+
* handlers are read-only and un-gated by owner/controller, so ANY room
|
|
17
|
+
* participant could use them to read + exfiltrate arbitrary files off the
|
|
18
|
+
* machine. The same weak test also gated write auto-approval, so a traversal
|
|
19
|
+
* path could widen which writes got approved without a prompt.
|
|
20
|
+
*
|
|
21
|
+
* ── The fix ─────────────────────────────────────────────────────────────────
|
|
22
|
+
* 1. resolve() the path — collapses `..`/`.` and makes it absolute.
|
|
23
|
+
* 2. Canonicalize symlinks on the deepest EXISTING ancestor (defeats a
|
|
24
|
+
* symlinked parent dir used to escape a root) while still accepting a
|
|
25
|
+
* not-yet-existing leaf (needed by the write/auto-approve gates, where the
|
|
26
|
+
* target file is about to be created).
|
|
27
|
+
* 3. Require the result to sit INSIDE an allowed root as a true path PREFIX
|
|
28
|
+
* (`resolved === root || resolved.startsWith(root + sep)`) — never a
|
|
29
|
+
* substring. `..`, absolute escapes and null bytes are rejected.
|
|
30
|
+
*/
|
|
31
|
+
import { realpathSync } from 'node:fs';
|
|
32
|
+
import { resolve, join, sep, dirname, basename, relative } from 'node:path';
|
|
33
|
+
import { homedir } from 'node:os';
|
|
34
|
+
/**
|
|
35
|
+
* Default root set for the session-workspace read + write gates. Mirrors the
|
|
36
|
+
* roots the old substring checks intended: the per-session `/osb/` workspace
|
|
37
|
+
* plus the two legacy `.osborn/` locations. (`plans` is opt-in — only the plan
|
|
38
|
+
* read handler allows it.)
|
|
39
|
+
*/
|
|
40
|
+
export const WORKSPACE_ROOTS = ['osb', 'osbornSessions', 'osbornResearch'];
|
|
41
|
+
function claudeConfigDir() {
|
|
42
|
+
return process.env.CLAUDE_CONFIG_DIR || join(homedir(), '.claude');
|
|
43
|
+
}
|
|
44
|
+
function osbornHomeDir() {
|
|
45
|
+
// Matches how the rest of the agent locates ~/.osborn (homedir, with an
|
|
46
|
+
// OSBORN_HOME override). The legacy `.osborn/sessions|research` roots live
|
|
47
|
+
// here; no active code writes to them, but we honor the location for parity.
|
|
48
|
+
return (process.env.OSBORN_HOME || '').trim() || join(homedir(), '.osborn');
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Canonicalize an already-absolute path. realpath the deepest existing
|
|
52
|
+
* ancestor (so a symlinked parent dir cannot be used to escape a root), then
|
|
53
|
+
* re-append the trailing not-yet-existing segments verbatim. Those trailing
|
|
54
|
+
* segments came out of resolve(), so they contain no `..` or `.` to re-open a
|
|
55
|
+
* traversal. On total failure returns the input unchanged (still absolute).
|
|
56
|
+
*/
|
|
57
|
+
function canonicalize(absPath) {
|
|
58
|
+
let cur = absPath;
|
|
59
|
+
const suffix = [];
|
|
60
|
+
// Bounded loop — dirname() strictly converges to the filesystem root.
|
|
61
|
+
for (let i = 0; i < 4096; i++) {
|
|
62
|
+
try {
|
|
63
|
+
const real = realpathSync(cur);
|
|
64
|
+
return suffix.length ? join(real, ...suffix) : real;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
const parent = dirname(cur);
|
|
68
|
+
if (parent === cur)
|
|
69
|
+
return absPath; // reached root, nothing resolved
|
|
70
|
+
suffix.unshift(basename(cur));
|
|
71
|
+
cur = parent;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return absPath;
|
|
75
|
+
}
|
|
76
|
+
/** True iff `resolved` (already canonical) is inside the canonicalized `root`. */
|
|
77
|
+
function isInside(resolved, root) {
|
|
78
|
+
const r = canonicalize(resolve(root));
|
|
79
|
+
return resolved === r || resolved.startsWith(r + sep);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* True iff `filePath` resolves to a location strictly inside one of the
|
|
83
|
+
* `allowed` roots. Rejects null bytes, `..` traversal and absolute escapes
|
|
84
|
+
* implicitly via the resolve()+canonicalize()+prefix test — never a substring.
|
|
85
|
+
*
|
|
86
|
+
* @param filePath caller-supplied path (may be relative or not-yet-existing)
|
|
87
|
+
* @param allowed which roots to accept (defaults to the workspace roots)
|
|
88
|
+
*/
|
|
89
|
+
export function isSafeArtifactPath(filePath, allowed = WORKSPACE_ROOTS) {
|
|
90
|
+
if (!filePath || typeof filePath !== 'string')
|
|
91
|
+
return false;
|
|
92
|
+
if (filePath.includes('\0'))
|
|
93
|
+
return false; // null byte — reject outright
|
|
94
|
+
let resolved;
|
|
95
|
+
try {
|
|
96
|
+
resolved = canonicalize(resolve(filePath));
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
for (const root of allowed) {
|
|
102
|
+
if (root === 'osb') {
|
|
103
|
+
// ~/.claude/projects/<slug>/osb/<sessionId>/... (and the session-sharing
|
|
104
|
+
// index layout ~/.claude/projects/osb/<slug>/...). Require containment
|
|
105
|
+
// under ~/.claude/projects AND a real `osb` path COMPONENT — a `..` that
|
|
106
|
+
// climbed out of projects fails the prefix test; `osb` as a substring of
|
|
107
|
+
// some other name (e.g. `osbornish`) is not a component and fails too.
|
|
108
|
+
const projectsRoot = canonicalize(resolve(join(claudeConfigDir(), 'projects')));
|
|
109
|
+
if (resolved === projectsRoot || resolved.startsWith(projectsRoot + sep)) {
|
|
110
|
+
const rel = relative(projectsRoot, resolved);
|
|
111
|
+
if (rel && !rel.startsWith('..') && rel.split(sep).includes('osb'))
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else if (root === 'osbornSessions') {
|
|
116
|
+
if (isInside(resolved, join(osbornHomeDir(), 'sessions')))
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
else if (root === 'osbornResearch') {
|
|
120
|
+
if (isInside(resolved, join(osbornHomeDir(), 'research')))
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
else if (root === 'plans') {
|
|
124
|
+
if (isInside(resolved, join(claudeConfigDir(), 'plans')))
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meeting multi-participant addressing + mute — scaffolding (OFF by default).
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS
|
|
5
|
+
* The comm-layer design (docs: Tier-1 router / Tier-2 workers) and the meeting
|
|
6
|
+
* copilot both want a way, in a multi-speaker room, to (a) address a SPECIFIC
|
|
7
|
+
* named agent ("@researcher, dig into X") rather than just "the bot", and
|
|
8
|
+
* (b) mute a noisy participant so their utterances never reach the LLM. The
|
|
9
|
+
* live meeting path today only does fuzzy single-name matching for "Osborn" and
|
|
10
|
+
* a global interactive/observer latch (see index.ts recall.on('transcript')).
|
|
11
|
+
* There is no per-agent routing and no per-participant mute. This module is the
|
|
12
|
+
* smallest, fully-additive first step toward that runtime.
|
|
13
|
+
*
|
|
14
|
+
* SAFETY CONTRACT
|
|
15
|
+
* - OFF BY DEFAULT. The singleton's `enabled` getter reads
|
|
16
|
+
* OSBORN_MEETING_ADDRESSING lazily; unless it is exactly 'on'/'1'/'true',
|
|
17
|
+
* processUtterance() is a pure pass-through: it never drops, never rewrites,
|
|
18
|
+
* never routes. With the flag unset there is ZERO behavior change.
|
|
19
|
+
* - PURE CORE. parseAddressing / parseMuteCommand / resolveAgent / buildRoster
|
|
20
|
+
* are pure functions with no I/O, so the regression suite can pin them without
|
|
21
|
+
* a network or a live meeting.
|
|
22
|
+
* - NO SIDE EFFECTS ON IMPORT. Only a class, some functions, and one singleton
|
|
23
|
+
* with no timers and no env reads at module load.
|
|
24
|
+
*
|
|
25
|
+
* WHAT IS REAL vs SCAFFOLD
|
|
26
|
+
* - REAL: the addressing parser, the mute command parser, the MuteRegistry, the
|
|
27
|
+
* flag gate, and the combined processUtterance() verdict object.
|
|
28
|
+
* - SCAFFOLD / NOT WIRED: the verdict's `target` does not yet route the turn to
|
|
29
|
+
* that Tier-2 worker (that needs the SDK-queue feed described in
|
|
30
|
+
* docs/multiagent-runtime-plan.md). Today the meeting handler only logs the
|
|
31
|
+
* verdict behind the flag and honours `drop` for muted speakers.
|
|
32
|
+
*/
|
|
33
|
+
/** A target that can be addressed in a meeting: the orchestrator or a worker. */
|
|
34
|
+
export interface MeetingAgentDef {
|
|
35
|
+
/** Canonical id used for routing, e.g. 'researcher' or 'osborn'. */
|
|
36
|
+
id: string;
|
|
37
|
+
/** Human label for logs/UI, e.g. 'Researcher'. */
|
|
38
|
+
label: string;
|
|
39
|
+
/** Lowercase tokens (without '@') that resolve to this id. */
|
|
40
|
+
aliases: string[];
|
|
41
|
+
}
|
|
42
|
+
export type MeetingRoster = MeetingAgentDef[];
|
|
43
|
+
/**
|
|
44
|
+
* Default addressable names. 'osborn' is the orchestrator (the main agent /
|
|
45
|
+
* the bot itself); the rest mirror the built-in NAMED_AGENTS worker roster in
|
|
46
|
+
* claude-llm.ts. Kept as a plain list (not an import of NAMED_AGENTS) to avoid
|
|
47
|
+
* coupling this leaf module to the LLM module — the runtime can override at
|
|
48
|
+
* startup via setRoster(Object.keys(NAMED_AGENTS)).
|
|
49
|
+
*/
|
|
50
|
+
export declare const DEFAULT_AGENT_NAMES: readonly ["osborn", "researcher", "reasoner", "writer", "planner", "reviewer", "tester"];
|
|
51
|
+
/** The orchestrator's canonical id — the main agent / "the bot" itself. An
|
|
52
|
+
* utterance addressed to it is NOT routed to a Tier-2 worker (the orchestrator
|
|
53
|
+
* already IS the turn's handler); only a NON-orchestrator target is routable. */
|
|
54
|
+
export declare const ORCHESTRATOR_ID = "osborn";
|
|
55
|
+
/**
|
|
56
|
+
* Whether an addressing target should be routed to a specific Tier-2 worker.
|
|
57
|
+
* True only for a concrete, non-orchestrator target. Pure — the single source
|
|
58
|
+
* of the Phase-C routing decision, shared by the meeting handler and the tests
|
|
59
|
+
* so the "@researcher routes, @osborn does not" rule is pinned without a live
|
|
60
|
+
* meeting. Fail-safe: null / undefined / the orchestrator id all return false.
|
|
61
|
+
*/
|
|
62
|
+
export declare function isRoutableTarget(target: string | null | undefined): boolean;
|
|
63
|
+
/** Build a roster from a list of agent ids. Aliases default to the id plus a
|
|
64
|
+
* couple of forgiving variants (hyphen/space collapsed). Extra aliases let the
|
|
65
|
+
* caller add room-specific nicknames. Pure. */
|
|
66
|
+
export declare function buildRoster(names?: readonly string[], extraAliases?: Record<string, string[]>): MeetingRoster;
|
|
67
|
+
/** Resolve a single token (with or without a leading '@') to a canonical agent
|
|
68
|
+
* id, or null if nothing in the roster matches. Case-insensitive. Pure. */
|
|
69
|
+
export declare function resolveAgent(token: string, roster: MeetingRoster): string | null;
|
|
70
|
+
export interface AddressingResult {
|
|
71
|
+
/** Canonical agent id addressed, or null if the turn addresses no one specific. */
|
|
72
|
+
target: string | null;
|
|
73
|
+
/** The utterance with the matched addressing token removed (whitespace tidied).
|
|
74
|
+
* Equals the input when there was no match. NEVER a paraphrase — only the
|
|
75
|
+
* single addressing token is stripped. */
|
|
76
|
+
cleanedText: string;
|
|
77
|
+
/** The raw token that matched (for logging), e.g. '@researcher'. */
|
|
78
|
+
token?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Parse @-addressing out of an utterance. Resolution order:
|
|
82
|
+
* 1. The first '@mention' whose token resolves in the roster.
|
|
83
|
+
* 2. Otherwise a leading "<alias>," / "<alias>:" address, only if the alias
|
|
84
|
+
* resolves in the roster (so plain sentences like "So, let's..." are NOT
|
|
85
|
+
* treated as addressing).
|
|
86
|
+
* Returns the resolved target (or null) and the utterance with just that one
|
|
87
|
+
* addressing token removed. Pure — no state, no I/O.
|
|
88
|
+
*/
|
|
89
|
+
export declare function parseAddressing(text: string, roster: MeetingRoster): AddressingResult;
|
|
90
|
+
export interface MuteCommand {
|
|
91
|
+
action: 'mute' | 'unmute' | null;
|
|
92
|
+
/** Lowercased participant name, '*' for everyone, or null when none parsed. */
|
|
93
|
+
who: string | null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Parse an explicit mute/unmute command from an utterance. Conservative: the
|
|
97
|
+
* command must LEAD the utterance (after an optional "please"/"can you" lead)
|
|
98
|
+
* and name a target, so ordinary sentences that merely contain the word "mute"
|
|
99
|
+
* mid-speech don't trigger it. Pure. Returns { action: null, who: null } when
|
|
100
|
+
* nothing matches.
|
|
101
|
+
*/
|
|
102
|
+
export declare function parseMuteCommand(text: string): MuteCommand;
|
|
103
|
+
/** Case-insensitive set of muted participant names, plus a global mute-all flag. */
|
|
104
|
+
export declare class MuteRegistry {
|
|
105
|
+
#private;
|
|
106
|
+
mute(who: string): void;
|
|
107
|
+
unmute(who: string): void;
|
|
108
|
+
isMuted(name: string): boolean;
|
|
109
|
+
list(): string[];
|
|
110
|
+
clear(): void;
|
|
111
|
+
}
|
|
112
|
+
export interface UtteranceVerdict {
|
|
113
|
+
/** Whether the addressing/mute layer was active (flag on) for this utterance. */
|
|
114
|
+
gated: boolean;
|
|
115
|
+
/** True when the speaker is muted and the utterance should NOT reach the LLM. */
|
|
116
|
+
drop: boolean;
|
|
117
|
+
/** Canonical agent id the utterance addresses, or null. */
|
|
118
|
+
target: string | null;
|
|
119
|
+
/** Utterance with any addressing token stripped (verbatim otherwise). */
|
|
120
|
+
cleanedText: string;
|
|
121
|
+
/** Set when this utterance was itself a mute/unmute command that was applied. */
|
|
122
|
+
muteChanged?: {
|
|
123
|
+
action: 'mute' | 'unmute';
|
|
124
|
+
who: string;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Singleton meeting-addressing layer. One per agent process (one meeting at a
|
|
129
|
+
* time per machine), mirroring the noiseGate singleton pattern. Stateful only
|
|
130
|
+
* in the MuteRegistry and the (overridable) roster.
|
|
131
|
+
*/
|
|
132
|
+
declare class MeetingAddressing {
|
|
133
|
+
#private;
|
|
134
|
+
readonly mutes: MuteRegistry;
|
|
135
|
+
/** OFF unless OSBORN_MEETING_ADDRESSING is on/1/true. Read lazily so ops can
|
|
136
|
+
* flip it at runtime without a republish (same discipline as noiseGate). */
|
|
137
|
+
get enabled(): boolean;
|
|
138
|
+
get roster(): MeetingRoster;
|
|
139
|
+
/** Canonical ids of the addressable roster (for emitting to the frontend). */
|
|
140
|
+
get rosterIds(): string[];
|
|
141
|
+
/**
|
|
142
|
+
* Apply an out-of-band mute/unmute control (e.g. a `mute_participant` message
|
|
143
|
+
* from the frontend) to the registry. Normalizes the name the same way voice
|
|
144
|
+
* commands do (lowercase/trim; everyone|everybody|all → '*') and returns the
|
|
145
|
+
* applied change for emission, or null when nothing valid was given. Pure of
|
|
146
|
+
* I/O — only mutates the registry — so the control path is testable without a
|
|
147
|
+
* live room or the data channel.
|
|
148
|
+
*/
|
|
149
|
+
applyMuteControl(action: 'mute' | 'unmute', who: string): {
|
|
150
|
+
action: 'mute' | 'unmute';
|
|
151
|
+
who: string;
|
|
152
|
+
} | null;
|
|
153
|
+
/** Snapshot of the addressing/mute layer for the frontend meeting_state msg. */
|
|
154
|
+
state(): {
|
|
155
|
+
enabled: boolean;
|
|
156
|
+
roster: string[];
|
|
157
|
+
muted: string[];
|
|
158
|
+
};
|
|
159
|
+
/** Override the addressable roster, e.g. from Object.keys(NAMED_AGENTS) at
|
|
160
|
+
* startup, or from per-user named agents. */
|
|
161
|
+
setRoster(names: readonly string[], extraAliases?: Record<string, string[]>): void;
|
|
162
|
+
/** Reset per-meeting state (call on leave_meeting / session switch). */
|
|
163
|
+
reset(): void;
|
|
164
|
+
/**
|
|
165
|
+
* The combined per-utterance verdict. PURE PASS-THROUGH when disabled:
|
|
166
|
+
* returns the input verbatim with drop=false, target=null. When enabled it
|
|
167
|
+
* (1) applies any mute/unmute command FIRST (so a muted speaker can still
|
|
168
|
+
* unmute themselves), (2) decides drop from the mute registry, and
|
|
169
|
+
* (3) parses @-addressing. It NEVER paraphrases — cleanedText only ever has a
|
|
170
|
+
* single addressing token removed.
|
|
171
|
+
*/
|
|
172
|
+
processUtterance(speaker: string, text: string): UtteranceVerdict;
|
|
173
|
+
}
|
|
174
|
+
/** Process-wide singleton (no side effects on import). */
|
|
175
|
+
export declare const meetingAddressing: MeetingAddressing;
|
|
176
|
+
export {};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Meeting multi-participant addressing + mute — scaffolding (OFF by default).
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS
|
|
5
|
+
* The comm-layer design (docs: Tier-1 router / Tier-2 workers) and the meeting
|
|
6
|
+
* copilot both want a way, in a multi-speaker room, to (a) address a SPECIFIC
|
|
7
|
+
* named agent ("@researcher, dig into X") rather than just "the bot", and
|
|
8
|
+
* (b) mute a noisy participant so their utterances never reach the LLM. The
|
|
9
|
+
* live meeting path today only does fuzzy single-name matching for "Osborn" and
|
|
10
|
+
* a global interactive/observer latch (see index.ts recall.on('transcript')).
|
|
11
|
+
* There is no per-agent routing and no per-participant mute. This module is the
|
|
12
|
+
* smallest, fully-additive first step toward that runtime.
|
|
13
|
+
*
|
|
14
|
+
* SAFETY CONTRACT
|
|
15
|
+
* - OFF BY DEFAULT. The singleton's `enabled` getter reads
|
|
16
|
+
* OSBORN_MEETING_ADDRESSING lazily; unless it is exactly 'on'/'1'/'true',
|
|
17
|
+
* processUtterance() is a pure pass-through: it never drops, never rewrites,
|
|
18
|
+
* never routes. With the flag unset there is ZERO behavior change.
|
|
19
|
+
* - PURE CORE. parseAddressing / parseMuteCommand / resolveAgent / buildRoster
|
|
20
|
+
* are pure functions with no I/O, so the regression suite can pin them without
|
|
21
|
+
* a network or a live meeting.
|
|
22
|
+
* - NO SIDE EFFECTS ON IMPORT. Only a class, some functions, and one singleton
|
|
23
|
+
* with no timers and no env reads at module load.
|
|
24
|
+
*
|
|
25
|
+
* WHAT IS REAL vs SCAFFOLD
|
|
26
|
+
* - REAL: the addressing parser, the mute command parser, the MuteRegistry, the
|
|
27
|
+
* flag gate, and the combined processUtterance() verdict object.
|
|
28
|
+
* - SCAFFOLD / NOT WIRED: the verdict's `target` does not yet route the turn to
|
|
29
|
+
* that Tier-2 worker (that needs the SDK-queue feed described in
|
|
30
|
+
* docs/multiagent-runtime-plan.md). Today the meeting handler only logs the
|
|
31
|
+
* verdict behind the flag and honours `drop` for muted speakers.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* Default addressable names. 'osborn' is the orchestrator (the main agent /
|
|
35
|
+
* the bot itself); the rest mirror the built-in NAMED_AGENTS worker roster in
|
|
36
|
+
* claude-llm.ts. Kept as a plain list (not an import of NAMED_AGENTS) to avoid
|
|
37
|
+
* coupling this leaf module to the LLM module — the runtime can override at
|
|
38
|
+
* startup via setRoster(Object.keys(NAMED_AGENTS)).
|
|
39
|
+
*/
|
|
40
|
+
export const DEFAULT_AGENT_NAMES = [
|
|
41
|
+
'osborn',
|
|
42
|
+
'researcher',
|
|
43
|
+
'reasoner',
|
|
44
|
+
'writer',
|
|
45
|
+
'planner',
|
|
46
|
+
'reviewer',
|
|
47
|
+
'tester',
|
|
48
|
+
];
|
|
49
|
+
/** The orchestrator's canonical id — the main agent / "the bot" itself. An
|
|
50
|
+
* utterance addressed to it is NOT routed to a Tier-2 worker (the orchestrator
|
|
51
|
+
* already IS the turn's handler); only a NON-orchestrator target is routable. */
|
|
52
|
+
export const ORCHESTRATOR_ID = 'osborn';
|
|
53
|
+
/**
|
|
54
|
+
* Whether an addressing target should be routed to a specific Tier-2 worker.
|
|
55
|
+
* True only for a concrete, non-orchestrator target. Pure — the single source
|
|
56
|
+
* of the Phase-C routing decision, shared by the meeting handler and the tests
|
|
57
|
+
* so the "@researcher routes, @osborn does not" rule is pinned without a live
|
|
58
|
+
* meeting. Fail-safe: null / undefined / the orchestrator id all return false.
|
|
59
|
+
*/
|
|
60
|
+
export function isRoutableTarget(target) {
|
|
61
|
+
const t = String(target || '').trim().toLowerCase();
|
|
62
|
+
return !!t && t !== ORCHESTRATOR_ID;
|
|
63
|
+
}
|
|
64
|
+
/** Build a roster from a list of agent ids. Aliases default to the id plus a
|
|
65
|
+
* couple of forgiving variants (hyphen/space collapsed). Extra aliases let the
|
|
66
|
+
* caller add room-specific nicknames. Pure. */
|
|
67
|
+
export function buildRoster(names = DEFAULT_AGENT_NAMES, extraAliases = {}) {
|
|
68
|
+
const seen = new Set();
|
|
69
|
+
const roster = [];
|
|
70
|
+
for (const raw of names) {
|
|
71
|
+
const id = String(raw || '').trim().toLowerCase();
|
|
72
|
+
if (!id || seen.has(id))
|
|
73
|
+
continue;
|
|
74
|
+
seen.add(id);
|
|
75
|
+
const aliases = new Set([id, id.replace(/[-_\s]+/g, '')]);
|
|
76
|
+
for (const a of extraAliases[id] || []) {
|
|
77
|
+
const t = String(a || '').trim().toLowerCase();
|
|
78
|
+
if (t)
|
|
79
|
+
aliases.add(t);
|
|
80
|
+
}
|
|
81
|
+
roster.push({ id, label: id.charAt(0).toUpperCase() + id.slice(1), aliases: [...aliases] });
|
|
82
|
+
}
|
|
83
|
+
return roster;
|
|
84
|
+
}
|
|
85
|
+
/** Resolve a single token (with or without a leading '@') to a canonical agent
|
|
86
|
+
* id, or null if nothing in the roster matches. Case-insensitive. Pure. */
|
|
87
|
+
export function resolveAgent(token, roster) {
|
|
88
|
+
const t = String(token || '').trim().toLowerCase().replace(/^@+/, '').replace(/[^a-z0-9_-]/g, '');
|
|
89
|
+
if (!t)
|
|
90
|
+
return null;
|
|
91
|
+
for (const a of roster)
|
|
92
|
+
if (a.id === t || a.aliases.includes(t))
|
|
93
|
+
return a.id;
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
// '@name' mention anywhere in the utterance. The capture excludes the '@'.
|
|
97
|
+
const MENTION_RE = /@([a-z0-9][a-z0-9_-]*)/i;
|
|
98
|
+
// Leading direct address: "researcher, ..." or "researcher: ..." at the start.
|
|
99
|
+
const LEADING_RE = /^\s*([a-z][a-z0-9_-]*)\s*[,:]\s+/i;
|
|
100
|
+
/**
|
|
101
|
+
* Parse @-addressing out of an utterance. Resolution order:
|
|
102
|
+
* 1. The first '@mention' whose token resolves in the roster.
|
|
103
|
+
* 2. Otherwise a leading "<alias>," / "<alias>:" address, only if the alias
|
|
104
|
+
* resolves in the roster (so plain sentences like "So, let's..." are NOT
|
|
105
|
+
* treated as addressing).
|
|
106
|
+
* Returns the resolved target (or null) and the utterance with just that one
|
|
107
|
+
* addressing token removed. Pure — no state, no I/O.
|
|
108
|
+
*/
|
|
109
|
+
export function parseAddressing(text, roster) {
|
|
110
|
+
const input = String(text ?? '');
|
|
111
|
+
if (!input.trim())
|
|
112
|
+
return { target: null, cleanedText: input };
|
|
113
|
+
const m = input.match(MENTION_RE);
|
|
114
|
+
if (m) {
|
|
115
|
+
const target = resolveAgent(m[1], roster);
|
|
116
|
+
if (target) {
|
|
117
|
+
const token = m[0];
|
|
118
|
+
const cleanedText = input.replace(token, ' ').replace(/\s{2,}/g, ' ').trim();
|
|
119
|
+
return { target, cleanedText, token };
|
|
120
|
+
}
|
|
121
|
+
// An '@token' that is NOT a known agent is left untouched (could be a handle,
|
|
122
|
+
// an email fragment, etc.) — fall through to the leading-address check.
|
|
123
|
+
}
|
|
124
|
+
const lead = input.match(LEADING_RE);
|
|
125
|
+
if (lead) {
|
|
126
|
+
const target = resolveAgent(lead[1], roster);
|
|
127
|
+
if (target) {
|
|
128
|
+
const token = lead[0];
|
|
129
|
+
const cleanedText = input.slice(token.length).trim();
|
|
130
|
+
return { target, cleanedText, token: lead[1] };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return { target: null, cleanedText: input };
|
|
134
|
+
}
|
|
135
|
+
// "mute <name>" / "unmute <name>" / "mute everyone|all|me", optionally with a
|
|
136
|
+
// short polite lead ("please mute Daniel"). The <name> is 1-2 words.
|
|
137
|
+
const MUTE_RE = /^(?:(?:can|could|would) you\s+|please\s+)?(mute|unmute)\s+(everyone|everybody|all|me|[a-z][a-z0-9'._-]*(?:\s+[a-z][a-z0-9'._-]*)?)\s*$/i;
|
|
138
|
+
/**
|
|
139
|
+
* Parse an explicit mute/unmute command from an utterance. Conservative: the
|
|
140
|
+
* command must LEAD the utterance (after an optional "please"/"can you" lead)
|
|
141
|
+
* and name a target, so ordinary sentences that merely contain the word "mute"
|
|
142
|
+
* mid-speech don't trigger it. Pure. Returns { action: null, who: null } when
|
|
143
|
+
* nothing matches.
|
|
144
|
+
*/
|
|
145
|
+
export function parseMuteCommand(text) {
|
|
146
|
+
const t = String(text ?? '').trim().replace(/\s+(please|now|thanks)\.?\s*$/i, '');
|
|
147
|
+
const m = t.match(MUTE_RE);
|
|
148
|
+
if (!m)
|
|
149
|
+
return { action: null, who: null };
|
|
150
|
+
const action = m[1].toLowerCase();
|
|
151
|
+
const rawWho = m[2].trim().toLowerCase();
|
|
152
|
+
const who = /^(everyone|everybody|all)$/.test(rawWho) ? '*' : rawWho.replace(/[.,!?]+$/, '');
|
|
153
|
+
return { action, who: who || null };
|
|
154
|
+
}
|
|
155
|
+
/** Case-insensitive set of muted participant names, plus a global mute-all flag. */
|
|
156
|
+
export class MuteRegistry {
|
|
157
|
+
#muted = new Set();
|
|
158
|
+
#all = false;
|
|
159
|
+
mute(who) {
|
|
160
|
+
const w = String(who || '').trim().toLowerCase();
|
|
161
|
+
if (!w)
|
|
162
|
+
return;
|
|
163
|
+
if (w === '*') {
|
|
164
|
+
this.#all = true;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
this.#muted.add(w);
|
|
168
|
+
}
|
|
169
|
+
unmute(who) {
|
|
170
|
+
const w = String(who || '').trim().toLowerCase();
|
|
171
|
+
if (!w)
|
|
172
|
+
return;
|
|
173
|
+
if (w === '*') {
|
|
174
|
+
this.#all = false;
|
|
175
|
+
this.#muted.clear();
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this.#muted.delete(w);
|
|
179
|
+
}
|
|
180
|
+
isMuted(name) {
|
|
181
|
+
const n = String(name || '').trim().toLowerCase();
|
|
182
|
+
if (!n)
|
|
183
|
+
return false;
|
|
184
|
+
if (this.#muted.has(n))
|
|
185
|
+
return true;
|
|
186
|
+
// mute-all applies to everyone EXCEPT names explicitly carved out is not a
|
|
187
|
+
// feature yet; '*' simply mutes all participants.
|
|
188
|
+
return this.#all;
|
|
189
|
+
}
|
|
190
|
+
list() {
|
|
191
|
+
return this.#all ? ['*', ...[...this.#muted].sort()] : [...this.#muted].sort();
|
|
192
|
+
}
|
|
193
|
+
clear() {
|
|
194
|
+
this.#muted.clear();
|
|
195
|
+
this.#all = false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Singleton meeting-addressing layer. One per agent process (one meeting at a
|
|
200
|
+
* time per machine), mirroring the noiseGate singleton pattern. Stateful only
|
|
201
|
+
* in the MuteRegistry and the (overridable) roster.
|
|
202
|
+
*/
|
|
203
|
+
class MeetingAddressing {
|
|
204
|
+
#roster = buildRoster();
|
|
205
|
+
mutes = new MuteRegistry();
|
|
206
|
+
/** OFF unless OSBORN_MEETING_ADDRESSING is on/1/true. Read lazily so ops can
|
|
207
|
+
* flip it at runtime without a republish (same discipline as noiseGate). */
|
|
208
|
+
get enabled() {
|
|
209
|
+
const v = String(process.env.OSBORN_MEETING_ADDRESSING || '').trim().toLowerCase();
|
|
210
|
+
return v === 'on' || v === '1' || v === 'true';
|
|
211
|
+
}
|
|
212
|
+
get roster() {
|
|
213
|
+
return this.#roster;
|
|
214
|
+
}
|
|
215
|
+
/** Canonical ids of the addressable roster (for emitting to the frontend). */
|
|
216
|
+
get rosterIds() {
|
|
217
|
+
return this.#roster.map((a) => a.id);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Apply an out-of-band mute/unmute control (e.g. a `mute_participant` message
|
|
221
|
+
* from the frontend) to the registry. Normalizes the name the same way voice
|
|
222
|
+
* commands do (lowercase/trim; everyone|everybody|all → '*') and returns the
|
|
223
|
+
* applied change for emission, or null when nothing valid was given. Pure of
|
|
224
|
+
* I/O — only mutates the registry — so the control path is testable without a
|
|
225
|
+
* live room or the data channel.
|
|
226
|
+
*/
|
|
227
|
+
applyMuteControl(action, who) {
|
|
228
|
+
const raw = String(who || '').trim().toLowerCase();
|
|
229
|
+
if (!raw)
|
|
230
|
+
return null;
|
|
231
|
+
const target = /^(everyone|everybody|all)$/.test(raw) ? '*' : raw;
|
|
232
|
+
if (action === 'mute')
|
|
233
|
+
this.mutes.mute(target);
|
|
234
|
+
else
|
|
235
|
+
this.mutes.unmute(target);
|
|
236
|
+
return { action, who: target };
|
|
237
|
+
}
|
|
238
|
+
/** Snapshot of the addressing/mute layer for the frontend meeting_state msg. */
|
|
239
|
+
state() {
|
|
240
|
+
return { enabled: this.enabled, roster: this.rosterIds, muted: this.mutes.list() };
|
|
241
|
+
}
|
|
242
|
+
/** Override the addressable roster, e.g. from Object.keys(NAMED_AGENTS) at
|
|
243
|
+
* startup, or from per-user named agents. */
|
|
244
|
+
setRoster(names, extraAliases) {
|
|
245
|
+
this.#roster = buildRoster(names, extraAliases);
|
|
246
|
+
}
|
|
247
|
+
/** Reset per-meeting state (call on leave_meeting / session switch). */
|
|
248
|
+
reset() {
|
|
249
|
+
this.mutes.clear();
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* The combined per-utterance verdict. PURE PASS-THROUGH when disabled:
|
|
253
|
+
* returns the input verbatim with drop=false, target=null. When enabled it
|
|
254
|
+
* (1) applies any mute/unmute command FIRST (so a muted speaker can still
|
|
255
|
+
* unmute themselves), (2) decides drop from the mute registry, and
|
|
256
|
+
* (3) parses @-addressing. It NEVER paraphrases — cleanedText only ever has a
|
|
257
|
+
* single addressing token removed.
|
|
258
|
+
*/
|
|
259
|
+
processUtterance(speaker, text) {
|
|
260
|
+
if (!this.enabled) {
|
|
261
|
+
return { gated: false, drop: false, target: null, cleanedText: String(text ?? '') };
|
|
262
|
+
}
|
|
263
|
+
let muteChanged;
|
|
264
|
+
const cmd = parseMuteCommand(text);
|
|
265
|
+
if (cmd.action && cmd.who) {
|
|
266
|
+
// "mute me" / "unmute me" resolve to the current speaker.
|
|
267
|
+
const who = cmd.who === 'me' ? String(speaker || '').trim().toLowerCase() : cmd.who;
|
|
268
|
+
if (who) {
|
|
269
|
+
if (cmd.action === 'mute')
|
|
270
|
+
this.mutes.mute(who);
|
|
271
|
+
else
|
|
272
|
+
this.mutes.unmute(who);
|
|
273
|
+
muteChanged = { action: cmd.action, who };
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const drop = this.mutes.isMuted(speaker);
|
|
277
|
+
const addr = parseAddressing(text, this.#roster);
|
|
278
|
+
return {
|
|
279
|
+
gated: true,
|
|
280
|
+
drop,
|
|
281
|
+
target: addr.target,
|
|
282
|
+
cleanedText: addr.cleanedText,
|
|
283
|
+
...(muteChanged ? { muteChanged } : {}),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/** Process-wide singleton (no side effects on import). */
|
|
288
|
+
export const meetingAddressing = new MeetingAddressing();
|