osborn 0.9.291 → 0.9.293
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 +5 -4
- package/.claude/skills/browser-apply/candidate.example.env +4 -1
- package/.claude/skills/browser-apply/fill.mjs +13 -2
- package/.claude/skills/meetings/SKILL.md +26 -7
- package/.env.example +6 -0
- package/dist/agent-store.d.ts +6 -0
- package/dist/agent-store.js +36 -6
- package/dist/approval-policy.d.ts +99 -0
- package/dist/approval-policy.js +196 -0
- package/dist/claude-llm.d.ts +3 -2
- package/dist/claude-llm.js +49 -19
- package/dist/config.d.ts +12 -16
- package/dist/config.js +80 -22
- package/dist/content/compaction-lens-worker.d.ts +5 -0
- package/dist/content/compaction-lens-worker.js +78 -7
- package/dist/content/content-llm.d.ts +14 -3
- package/dist/content/content-llm.js +33 -142
- package/dist/content/lens-db.d.ts +16 -5
- package/dist/content/lens-db.js +58 -11
- package/dist/content/lens-ingest.d.ts +1 -0
- package/dist/content/lens-ingest.js +1 -1
- package/dist/content/lens-launch.d.ts +42 -1
- package/dist/content/lens-launch.js +202 -40
- package/dist/content/lens-library-digest.d.ts +85 -0
- package/dist/content/lens-library-digest.js +305 -0
- package/dist/content/lens-library-index.d.ts +14 -3
- package/dist/content/lens-library-index.js +35 -8
- package/dist/content/lens-library-select.d.ts +1 -1
- package/dist/content/lens-library-select.js +1 -1
- package/dist/content/lens-library-sweep.d.ts +36 -0
- package/dist/content/lens-library-sweep.js +331 -0
- package/dist/content/lens-library.d.ts +29 -0
- package/dist/content/lens-library.js +130 -20
- package/dist/content/lens-model.d.ts +4 -0
- package/dist/content/lens-model.js +5 -0
- package/dist/content/lens-paths.d.ts +72 -0
- package/dist/content/lens-paths.js +248 -5
- package/dist/content/period-run.js +2 -2
- package/dist/content/secret-rules.d.ts +51 -0
- package/dist/content/secret-rules.js +185 -0
- package/dist/content/transcript-sanitizer.d.ts +1 -41
- package/dist/content/transcript-sanitizer.js +4 -171
- package/dist/data-sender-auth.d.ts +43 -6
- package/dist/data-sender-auth.js +61 -45
- package/dist/env-keys.d.ts +10 -2
- package/dist/env-keys.js +26 -5
- package/dist/index.js +499 -106
- package/dist/phone-code.d.ts +76 -0
- package/dist/phone-code.js +124 -0
- package/dist/phone-voice-actions.d.ts +132 -0
- package/dist/phone-voice-actions.js +223 -0
- package/dist/pipeline-direct-llm.d.ts +7 -1
- package/dist/pipeline-direct-llm.js +12 -1
- package/dist/prompts/library-digest.md +11 -0
- package/dist/prompts.js +2 -2
- package/dist/pushover.d.ts +2 -1
- package/dist/pushover.js +7 -6
- package/dist/risk-tier.d.ts +14 -0
- package/dist/risk-tier.js +140 -0
- package/dist/session-store.d.ts +1 -0
- package/dist/session-store.js +3 -2
- package/dist/session-switch.d.ts +22 -7
- package/dist/session-switch.js +58 -24
- package/dist/steward-verdict.d.ts +16 -3
- package/dist/steward-verdict.js +37 -18
- package/dist/watch-gateway.js +3 -1
- package/package.json +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.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ interface AckPayload {
|
|
|
40
40
|
}
|
|
41
41
|
/** An approval push went out and is still waiting for its answer. */
|
|
42
42
|
export declare const phonePushPending: () => boolean;
|
|
43
|
-
export declare function setWatchResultHandler(fn: (allow: boolean, toolName: string) => void): void;
|
|
43
|
+
export declare function setWatchResultHandler(fn: (allow: boolean, toolName: string, requestId?: string) => void): void;
|
|
44
44
|
/** The frontend this agent links to and accepts store writes from (OSBORN_FRONTEND_URL, default the live site). */
|
|
45
45
|
export declare const osbornFrontendUrl: () => string;
|
|
46
46
|
export declare function pushoverConfig(): PushoverConfig | null;
|
|
@@ -73,6 +73,7 @@ export declare function notifyPhone(message: string): Promise<boolean>;
|
|
|
73
73
|
export declare function armPermissionPush(opts: {
|
|
74
74
|
toolName: string;
|
|
75
75
|
description: string;
|
|
76
|
+
requestId?: string;
|
|
76
77
|
}): Promise<void>;
|
|
77
78
|
/**
|
|
78
79
|
* Landing for the frontend ack route. Returns true when a pending push was
|
package/dist/pushover.js
CHANGED
|
@@ -36,7 +36,7 @@ const EXPIRY_GRACE_MS = 5_000;
|
|
|
36
36
|
const pending = new Map();
|
|
37
37
|
/** An approval push went out and is still waiting for its answer. */
|
|
38
38
|
export const phonePushPending = () => [...pending.values()].some(p => !p.settled);
|
|
39
|
-
/** Registered by index.ts: resolves the
|
|
39
|
+
/** Registered by index.ts: resolves the permission request the push was armed for. */
|
|
40
40
|
let resultHandler = null;
|
|
41
41
|
export function setWatchResultHandler(fn) {
|
|
42
42
|
resultHandler = fn;
|
|
@@ -154,6 +154,7 @@ export async function armPermissionPush(opts) {
|
|
|
154
154
|
receipt: '',
|
|
155
155
|
toolName: opts.toolName,
|
|
156
156
|
description: opts.description,
|
|
157
|
+
requestId: opts.requestId,
|
|
157
158
|
expiresAt: now + EXPIRE_S * 1000,
|
|
158
159
|
settled: false,
|
|
159
160
|
};
|
|
@@ -228,7 +229,7 @@ export function handleWatchAck(qid, receipt, allow = true) {
|
|
|
228
229
|
clearTimeout(record.expiryTimer);
|
|
229
230
|
pending.delete(qid);
|
|
230
231
|
console.log(`⌚️ Watch bridge: ACKED → ${allow ? 'approve' : 'deny'} ${record.toolName}`);
|
|
231
|
-
resultHandler?.(allow, record.toolName);
|
|
232
|
+
resultHandler?.(allow, record.toolName, record.requestId);
|
|
232
233
|
return true;
|
|
233
234
|
}
|
|
234
235
|
/**
|
|
@@ -246,7 +247,7 @@ async function settleExpired(record) {
|
|
|
246
247
|
record.settled = true;
|
|
247
248
|
pending.delete(record.qid);
|
|
248
249
|
console.log(`⌚️ Watch bridge: unacknowledged at expiry → deny ${record.toolName}`);
|
|
249
|
-
resultHandler?.(false, record.toolName);
|
|
250
|
+
resultHandler?.(false, record.toolName, record.requestId);
|
|
250
251
|
return;
|
|
251
252
|
}
|
|
252
253
|
try {
|
|
@@ -257,11 +258,11 @@ async function settleExpired(record) {
|
|
|
257
258
|
if (body.acknowledged === 1) {
|
|
258
259
|
// Acked but the callback never reached us — recover as approve.
|
|
259
260
|
console.log(`⌚️ Watch bridge: expiry poll found late ack → approve ${record.toolName}`);
|
|
260
|
-
resultHandler?.(true, record.toolName);
|
|
261
|
+
resultHandler?.(true, record.toolName, record.requestId);
|
|
261
262
|
}
|
|
262
263
|
else {
|
|
263
264
|
console.log(`⌚️ Watch bridge: unacknowledged at expiry → deny ${record.toolName}`);
|
|
264
|
-
resultHandler?.(false, record.toolName);
|
|
265
|
+
resultHandler?.(false, record.toolName, record.requestId);
|
|
265
266
|
// Cancel remaining emergency retries so the wrist stops buzzing.
|
|
266
267
|
void fetch(`${PUSH_API}/receipts/${record.receipt}/cancel.json`, {
|
|
267
268
|
method: 'POST',
|
|
@@ -274,6 +275,6 @@ async function settleExpired(record) {
|
|
|
274
275
|
console.log('⌚️ Watch bridge: receipts poll failed:', e instanceof Error ? e.message : e);
|
|
275
276
|
record.settled = true;
|
|
276
277
|
pending.delete(record.qid);
|
|
277
|
-
resultHandler?.(false, record.toolName);
|
|
278
|
+
resultHandler?.(false, record.toolName, record.requestId);
|
|
278
279
|
}
|
|
279
280
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type RiskTier = 'low' | 'high';
|
|
2
|
+
export declare function isInWorkspace(rawPath: unknown, root?: string): boolean;
|
|
3
|
+
export declare function isSensitivePath(rawPath: unknown): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* A cwd too broad to trust writes under: the filesystem root or the user's
|
|
6
|
+
* home folder (its dotfiles, ssh keys and shell profile all sit "inside" it).
|
|
7
|
+
*/
|
|
8
|
+
export declare function isBroadRoot(root: string | undefined, home?: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Derive the risk tier for a tool request from the data in the permission_request
|
|
11
|
+
* payload. Pure — no React, no I/O. Conservative by construction: anything not
|
|
12
|
+
* provably LOW is HIGH.
|
|
13
|
+
*/
|
|
14
|
+
export declare function classifyRisk(toolName: string, input?: Record<string, unknown> | null, workspaceRoot?: string): RiskTier;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Risk classifier for the "Auto-review" approval mode (#364).
|
|
2
|
+
//
|
|
3
|
+
// The one copy: the agent applies the approval mode itself (approval-policy.ts,
|
|
4
|
+
// index.ts `permission_request`), for the browser and phone calls alike, so the
|
|
5
|
+
// browser no longer classifies. The tier is derived from the tool name + its
|
|
6
|
+
// target, and kept deliberately conservative: when in doubt, it is HIGH (never
|
|
7
|
+
// auto-approved).
|
|
8
|
+
//
|
|
9
|
+
// LOW → read-only tools, or file writes/edits whose target stays inside the
|
|
10
|
+
// workspace. These auto-approve in 'auto-review' mode.
|
|
11
|
+
// HIGH → everything else: destructive deletes, shell/Bash side effects,
|
|
12
|
+
// network/exfil (WebFetch/WebSearch, incl. the "copy scope doc + POST
|
|
13
|
+
// it" shape), out-of-workspace writes, sub-agent spawns, MCP calls, and
|
|
14
|
+
// any unknown tool. NEVER auto-approved — always waits for a human.
|
|
15
|
+
//
|
|
16
|
+
// This classifier ONLY decides the auto-answer to a permission request. It never
|
|
17
|
+
// relaxes the canUseTool / PreToolUse gate: a tool the agent denies stays denied,
|
|
18
|
+
// and DENY always wins.
|
|
19
|
+
import { homedir } from 'node:os';
|
|
20
|
+
// Default workspace root; the agent passes the session's working directory.
|
|
21
|
+
const WORKSPACE_ROOT = '/workspace';
|
|
22
|
+
// Tools that only read — they never mutate the filesystem, run a shell, or touch
|
|
23
|
+
// the network. LOW only for an in-workspace, non-sensitive target.
|
|
24
|
+
const READ_ONLY_TOOLS = new Set([
|
|
25
|
+
'Read',
|
|
26
|
+
'Grep',
|
|
27
|
+
'Glob',
|
|
28
|
+
'LS',
|
|
29
|
+
'NotebookRead',
|
|
30
|
+
]);
|
|
31
|
+
// File-mutating tools that are LOW *only* when their target stays in-workspace.
|
|
32
|
+
const WORKSPACE_WRITE_TOOLS = new Set([
|
|
33
|
+
'Write',
|
|
34
|
+
'Edit',
|
|
35
|
+
'MultiEdit',
|
|
36
|
+
'NotebookEdit',
|
|
37
|
+
]);
|
|
38
|
+
// Pull the filesystem target out of a tool input, whichever field it uses.
|
|
39
|
+
function targetPath(input) {
|
|
40
|
+
if (!input)
|
|
41
|
+
return undefined;
|
|
42
|
+
return input.file_path ?? input.notebook_path ?? input.path;
|
|
43
|
+
}
|
|
44
|
+
// True only when the path is unambiguously inside the workspace. Relative paths
|
|
45
|
+
// resolve against the agent's cwd (the workspace) and count as in-workspace;
|
|
46
|
+
// absolute paths must live under `root`. Anything with a `..` segment, a
|
|
47
|
+
// URL scheme, or a home-relative `~` is rejected so it can never escape.
|
|
48
|
+
export function isInWorkspace(rawPath, root = WORKSPACE_ROOT) {
|
|
49
|
+
const base = root.length > 1 ? root.replace(/\/+$/, '') : root;
|
|
50
|
+
if (typeof rawPath !== 'string')
|
|
51
|
+
return false;
|
|
52
|
+
const p = rawPath.trim();
|
|
53
|
+
if (p.length === 0)
|
|
54
|
+
return false;
|
|
55
|
+
// Any traversal segment can climb out of the workspace — refuse outright.
|
|
56
|
+
if (p.split(/[\\/]/).some((seg) => seg === '..'))
|
|
57
|
+
return false;
|
|
58
|
+
// URL schemes (http://, file://, …) and home-relative paths are not workspace paths.
|
|
59
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(p) || p.startsWith('~'))
|
|
60
|
+
return false;
|
|
61
|
+
// Relative path → resolves against cwd (the workspace).
|
|
62
|
+
if (!p.startsWith('/'))
|
|
63
|
+
return true;
|
|
64
|
+
// Absolute path → must be the workspace root or a descendant of it.
|
|
65
|
+
// A root of "/" (or none) would make every path in-workspace: never.
|
|
66
|
+
if (!base.startsWith('/') || base === '/')
|
|
67
|
+
return false;
|
|
68
|
+
return p === base || p.startsWith(base + '/');
|
|
69
|
+
}
|
|
70
|
+
// File names that steer agents, builds, CI or deploys, or look like secrets.
|
|
71
|
+
const SENSITIVE_NAMES = [
|
|
72
|
+
/settings|hook/i, // settings and hook files
|
|
73
|
+
/^(?:claude|claude\.local|agents)\.md$/i, // agent instructions, at any depth
|
|
74
|
+
/^package\.json$/i, // scripts run on install/build
|
|
75
|
+
/(?:^|[-.])lock(?:\.json|\.ya?ml|b)?$|\.lock$|^go\.sum$/i, // lockfiles
|
|
76
|
+
/^(?:makefile|gnumakefile|justfile|rakefile|jenkinsfile|procfile)$/i,
|
|
77
|
+
/^dockerfile(?:\..+)?$|^docker-compose[\w.-]*\.ya?ml$|^compose\.ya?ml$/i,
|
|
78
|
+
/\.(?:sh|bash|zsh|fish|ps1|bat|cmd)$/i, // shell scripts
|
|
79
|
+
/^(?:azure-pipelines|bitbucket-pipelines|codemagic|cloudbuild|buildspec|appveyor)\.ya?ml$/i, // CI
|
|
80
|
+
/^(?:fly|railway|nixpacks|netlify|vercel)\.(?:toml|json)$/i, // deploy configs
|
|
81
|
+
/\.(?:pem|key|p12|pfx|jks|keystore)$/i, /^id_(?:rsa|dsa|ecdsa|ed25519)/i, /credential/i, /secret/i,
|
|
82
|
+
// Files a build, install or test run executes or reads as config.
|
|
83
|
+
/^(?:setup\.py|setup\.cfg|pyproject\.toml|conftest\.py|pipfile|pipfile\.lock|cargo\.toml|build\.rs|gemfile|go\.mod)$/i,
|
|
84
|
+
/^requirements[\w.-]*\.txt$/i, /\.gemspec$/i,
|
|
85
|
+
/\.config\.(?:js|ts|mjs|cjs|mts|cts|json)$/i, // vite/next/jest/eslint/… configs
|
|
86
|
+
/^tsconfig[\w.-]*\.json$/i,
|
|
87
|
+
// Build systems and task runners.
|
|
88
|
+
/^cmakelists\.txt$/i, /\.gradle|^gradle(?:w|\.properties)$/i, /^pom\.xml$/i, /^(?:tox|pytest)\.ini$/i, /^noxfile\.py$/i,
|
|
89
|
+
/^(?:turbo|nx)\.json$/i, /^taskfile(?:\.dist)?\.ya?ml$/i, /^flake\.nix$/i, /^meson\.build$/i,
|
|
90
|
+
/^(?:build|build\.bazel|workspace|workspace\.bazel|module\.bazel)$/i,
|
|
91
|
+
];
|
|
92
|
+
// Paths that change how tools, the agent, builds or the repo behave, or hold
|
|
93
|
+
// secrets: any dot segment (.git, .claude, .husky, .github, .gitlab-ci.yml,
|
|
94
|
+
// .env*, .babelrc, .githooks, .npmrc …), anything under node_modules, a hooks
|
|
95
|
+
// folder, and the SENSITIVE_NAMES above. Never LOW, even inside the workspace.
|
|
96
|
+
export function isSensitivePath(rawPath) {
|
|
97
|
+
if (typeof rawPath !== 'string')
|
|
98
|
+
return true;
|
|
99
|
+
const segs = rawPath.trim().split(/[\\/]+/).filter((s) => s && s !== '.');
|
|
100
|
+
if (segs.some((s) => s.startsWith('.') || /^hooks?$/i.test(s) || s === 'node_modules'))
|
|
101
|
+
return true;
|
|
102
|
+
const base = segs[segs.length - 1] || '';
|
|
103
|
+
return SENSITIVE_NAMES.some((re) => re.test(base));
|
|
104
|
+
}
|
|
105
|
+
// Grep/Glob search the workspace (cwd) when they are given no path.
|
|
106
|
+
const DEFAULTS_TO_CWD = new Set(['Grep', 'Glob']);
|
|
107
|
+
/**
|
|
108
|
+
* A cwd too broad to trust writes under: the filesystem root or the user's
|
|
109
|
+
* home folder (its dotfiles, ssh keys and shell profile all sit "inside" it).
|
|
110
|
+
*/
|
|
111
|
+
export function isBroadRoot(root, home = homedir()) {
|
|
112
|
+
if (!root)
|
|
113
|
+
return true;
|
|
114
|
+
const norm = (p) => (p.length > 1 ? p.replace(/\/+$/, '') : p);
|
|
115
|
+
const r = norm(root);
|
|
116
|
+
return r === '/' || r === '' || (!!home && r === norm(home));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Derive the risk tier for a tool request from the data in the permission_request
|
|
120
|
+
* payload. Pure — no React, no I/O. Conservative by construction: anything not
|
|
121
|
+
* provably LOW is HIGH.
|
|
122
|
+
*/
|
|
123
|
+
export function classifyRisk(toolName, input, workspaceRoot) {
|
|
124
|
+
if (!toolName || typeof toolName !== 'string')
|
|
125
|
+
return 'high';
|
|
126
|
+
// LOW needs an in-workspace (session cwd), non-sensitive target.
|
|
127
|
+
if (READ_ONLY_TOOLS.has(toolName) || WORKSPACE_WRITE_TOOLS.has(toolName)) {
|
|
128
|
+
// A home-folder or "/" cwd: no write is low risk.
|
|
129
|
+
if (WORKSPACE_WRITE_TOOLS.has(toolName) && workspaceRoot !== undefined && isBroadRoot(workspaceRoot))
|
|
130
|
+
return 'high';
|
|
131
|
+
const target = targetPath(input);
|
|
132
|
+
if (target === undefined && DEFAULTS_TO_CWD.has(toolName))
|
|
133
|
+
return 'low';
|
|
134
|
+
return isInWorkspace(target, workspaceRoot) && !isSensitivePath(target) ? 'low' : 'high';
|
|
135
|
+
}
|
|
136
|
+
// Bash/KillShell (shell side effects), WebFetch/WebSearch (network/exfil),
|
|
137
|
+
// Task (spawns an agent that can do anything), MCP tools (mcp__*), and every
|
|
138
|
+
// unknown tool fall through to HIGH — never auto-approved.
|
|
139
|
+
return 'high';
|
|
140
|
+
}
|
package/dist/session-store.d.ts
CHANGED
|
@@ -75,6 +75,7 @@ export declare function openStore(dbPath: string, opts?: {
|
|
|
75
75
|
export declare function updateSessionStore(sessionId: string, workingDir: string, opts?: {
|
|
76
76
|
embed?: Embedder;
|
|
77
77
|
onProgress?: (msg: string) => void;
|
|
78
|
+
mainOnly?: boolean;
|
|
78
79
|
}): Promise<StoreStats>;
|
|
79
80
|
export interface RecallOpts {
|
|
80
81
|
mode?: 'hybrid' | 'keyword' | 'vector';
|
package/dist/session-store.js
CHANGED
|
@@ -386,11 +386,12 @@ export async function updateSessionStore(sessionId, workingDir, opts) {
|
|
|
386
386
|
const sources = [];
|
|
387
387
|
if (existsSync(paths.conversation))
|
|
388
388
|
sources.push({ source: 'main', path: paths.conversation });
|
|
389
|
-
|
|
389
|
+
// mainOnly skips sub-agent discovery, which parses the whole main JSONL.
|
|
390
|
+
for (const f of opts?.mainOnly ? [] : paths.subagents) {
|
|
390
391
|
const key = basename(f, '.jsonl').replace('agent-', '').substring(0, 8);
|
|
391
392
|
sources.push({ source: `agent-${key}`, path: f });
|
|
392
393
|
}
|
|
393
|
-
for (const a of getSessionSubAgents(sessionId, workingDir)) {
|
|
394
|
+
for (const a of opts?.mainOnly ? [] : getSessionSubAgents(sessionId, workingDir)) {
|
|
394
395
|
if (!a.agentFileExists)
|
|
395
396
|
continue;
|
|
396
397
|
const src = `agent-${a.agentId.substring(0, 8)}`;
|
package/dist/session-switch.d.ts
CHANGED
|
@@ -80,6 +80,10 @@ export interface SessionCwdDeps {
|
|
|
80
80
|
exists: (sessionId: string, cwd: string) => boolean;
|
|
81
81
|
/** Find ONE session's project dir (scanSlugCwd), or null. */
|
|
82
82
|
lookupCwd: (sessionId: string) => Promise<string | null | undefined>;
|
|
83
|
+
/** extractCwd of the session's JSONL under `cwd`'s slug: the cwd it records. */
|
|
84
|
+
recordedCwd?: (sessionId: string, cwd: string) => Promise<string | null | undefined>;
|
|
85
|
+
/** existsSync: a colliding candidate only loses to a recorded dir that exists. */
|
|
86
|
+
dirExists?: (path: string) => boolean;
|
|
83
87
|
}
|
|
84
88
|
/**
|
|
85
89
|
* The project directory a session's JSONL resolves under (what `--resume`
|
|
@@ -139,13 +143,12 @@ export declare function createSwitchGuard(): {
|
|
|
139
143
|
};
|
|
140
144
|
/**
|
|
141
145
|
* Find a session's project dir by scanning ~/.claude/projects/<slug>/<id>.jsonl
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
* only looks at the slug.
|
|
146
|
+
* (slugs sorted, `-subagents` skipped like the session list). The cwd the JSONL
|
|
147
|
+
* records wins when it encodes to the slug it sits in: the slug decode is lossy
|
|
148
|
+
* (`/w/my-app` decodes to `/w/my/app`), so a decoded path that disagrees with
|
|
149
|
+
* it is another project (#181). The decode is only used when the recorded cwd
|
|
150
|
+
* belongs elsewhere (an imported session) or is missing. Only paths that EXIST
|
|
151
|
+
* are returned — the switch executor never creates directories for them.
|
|
149
152
|
*/
|
|
150
153
|
export declare function scanSlugCwd(sessionId: string, projectsDir: string, fsx: {
|
|
151
154
|
readdir: (dir: string) => string[];
|
|
@@ -155,3 +158,15 @@ export declare function scanSlugCwd(sessionId: string, projectsDir: string, fsx:
|
|
|
155
158
|
/** extractCwd(filePath) from config.ts: the cwd the JSONL itself records. */
|
|
156
159
|
readCwd: (filePath: string) => Promise<string | null | undefined>;
|
|
157
160
|
}): Promise<string | null>;
|
|
161
|
+
/**
|
|
162
|
+
* Connect-time working dir (#183): the resolved session dir, else the client's
|
|
163
|
+
* hint when it exists, else the default. A missing hint is created only for a
|
|
164
|
+
* NEW chat (no session id, e.g. "New project") and only when it is a plausible
|
|
165
|
+
* path on this machine: absolute, no `.`/`..` segments, parent already there.
|
|
166
|
+
* A hint for a session that did not resolve is stale (a shared link, another
|
|
167
|
+
* machine, a deleted project) and is never created.
|
|
168
|
+
*/
|
|
169
|
+
export declare function connectWorkingDir(resolved: string | null | undefined, hint: string | null | undefined, sessionId: string | null | undefined, fallback: string, dirExists: (path: string) => boolean): {
|
|
170
|
+
dir: string;
|
|
171
|
+
create: boolean;
|
|
172
|
+
};
|
package/dist/session-switch.js
CHANGED
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
* background until its current turn finishes — it is never aborted. So a busy
|
|
18
18
|
* session is never 'close'd here; it is 'background'.
|
|
19
19
|
*/
|
|
20
|
+
import { dirname, isAbsolute } from 'node:path';
|
|
21
|
+
import { projectPathToSlug } from './session-access.js';
|
|
20
22
|
const norm = (v) => (typeof v === 'string' && v.length > 0 ? v : null);
|
|
21
23
|
export function decideNextSession(state) {
|
|
22
24
|
const liveId = norm(state.liveSessionId);
|
|
@@ -75,8 +77,19 @@ export async function resolveSessionCwd(sessionId, hint, currentDir, deps) {
|
|
|
75
77
|
if (!sessionId)
|
|
76
78
|
return null;
|
|
77
79
|
for (const c of [hint, currentDir]) {
|
|
78
|
-
if (c
|
|
80
|
+
if (!c || !deps.exists(sessionId, c))
|
|
81
|
+
continue;
|
|
82
|
+
let rec = null;
|
|
83
|
+
try {
|
|
84
|
+
rec = await deps.recordedCwd?.(sessionId, c);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
rec = null;
|
|
88
|
+
}
|
|
89
|
+
const collides = !!rec && rec !== c && projectPathToSlug(rec) === projectPathToSlug(c);
|
|
90
|
+
if (!collides || !deps.dirExists?.(rec))
|
|
79
91
|
return c;
|
|
92
|
+
break;
|
|
80
93
|
}
|
|
81
94
|
let c = null;
|
|
82
95
|
try {
|
|
@@ -159,13 +172,12 @@ export function createSwitchGuard() {
|
|
|
159
172
|
}
|
|
160
173
|
/**
|
|
161
174
|
* Find a session's project dir by scanning ~/.claude/projects/<slug>/<id>.jsonl
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* only looks at the slug.
|
|
175
|
+
* (slugs sorted, `-subagents` skipped like the session list). The cwd the JSONL
|
|
176
|
+
* records wins when it encodes to the slug it sits in: the slug decode is lossy
|
|
177
|
+
* (`/w/my-app` decodes to `/w/my/app`), so a decoded path that disagrees with
|
|
178
|
+
* it is another project (#181). The decode is only used when the recorded cwd
|
|
179
|
+
* belongs elsewhere (an imported session) or is missing. Only paths that EXIST
|
|
180
|
+
* are returned — the switch executor never creates directories for them.
|
|
169
181
|
*/
|
|
170
182
|
export async function scanSlugCwd(sessionId, projectsDir, fsx) {
|
|
171
183
|
if (!sessionId || !fsx.exists(projectsDir))
|
|
@@ -177,24 +189,46 @@ export async function scanSlugCwd(sessionId, projectsDir, fsx) {
|
|
|
177
189
|
catch {
|
|
178
190
|
return null;
|
|
179
191
|
}
|
|
180
|
-
let
|
|
181
|
-
for (const slug of slugs) {
|
|
192
|
+
let decoded = null;
|
|
193
|
+
for (const slug of slugs.filter((s) => !s.endsWith('-subagents')).sort()) {
|
|
182
194
|
const filePath = `${projectsDir}/${slug}/${sessionId}.jsonl`;
|
|
183
195
|
if (!fsx.exists(filePath))
|
|
184
196
|
continue;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
let recorded = null;
|
|
198
|
+
try {
|
|
199
|
+
recorded = await fsx.readCwd(filePath);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
recorded = null;
|
|
203
|
+
}
|
|
204
|
+
if (recorded && projectPathToSlug(recorded) === slug) {
|
|
205
|
+
if (fsx.exists(recorded))
|
|
206
|
+
return recorded;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const guess = fsx.decodeSlug(slug);
|
|
210
|
+
if (!decoded && guess && guess !== '/')
|
|
211
|
+
decoded = guess;
|
|
199
212
|
}
|
|
213
|
+
return decoded;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Connect-time working dir (#183): the resolved session dir, else the client's
|
|
217
|
+
* hint when it exists, else the default. A missing hint is created only for a
|
|
218
|
+
* NEW chat (no session id, e.g. "New project") and only when it is a plausible
|
|
219
|
+
* path on this machine: absolute, no `.`/`..` segments, parent already there.
|
|
220
|
+
* A hint for a session that did not resolve is stale (a shared link, another
|
|
221
|
+
* machine, a deleted project) and is never created.
|
|
222
|
+
*/
|
|
223
|
+
export function connectWorkingDir(resolved, hint, sessionId, fallback, dirExists) {
|
|
224
|
+
if (resolved && dirExists(resolved))
|
|
225
|
+
return { dir: resolved, create: false };
|
|
226
|
+
if (hint && dirExists(hint))
|
|
227
|
+
return { dir: hint, create: false };
|
|
228
|
+
const plausible = !!hint && isAbsolute(hint) && !hint.includes('\0')
|
|
229
|
+
&& !hint.split('/').some((seg) => seg === '.' || seg === '..')
|
|
230
|
+
&& dirExists(dirname(hint));
|
|
231
|
+
if (hint && !sessionId && plausible)
|
|
232
|
+
return { dir: hint, create: true };
|
|
233
|
+
return { dir: fallback, create: false };
|
|
200
234
|
}
|
|
@@ -9,15 +9,28 @@ export interface StewardVerdict {
|
|
|
9
9
|
removed: string[];
|
|
10
10
|
lines?: string;
|
|
11
11
|
history: string[];
|
|
12
|
+
/** IMPACT: each changed symbol → its usages → verdict, then SIBLINGS. */
|
|
13
|
+
impact?: string[];
|
|
12
14
|
/** The full return, so the card can show the whole record. */
|
|
13
15
|
raw: string;
|
|
14
16
|
/** ISO time the steward returned. */
|
|
15
17
|
at: string;
|
|
16
18
|
}
|
|
19
|
+
/** The sign-off gate advised on or refused a commit / push / PR (#254). Kept in the same sidecar. */
|
|
20
|
+
export interface StewardGateRecord {
|
|
21
|
+
gate: 'advise' | 'deny';
|
|
22
|
+
message: string;
|
|
23
|
+
at: string;
|
|
24
|
+
}
|
|
25
|
+
export type StewardRecord = StewardVerdict | StewardGateRecord;
|
|
17
26
|
/** Parse a steward return. Null when the text carries no VERDICT line. */
|
|
18
27
|
export declare function parseStewardVerdict(text: string, at?: string): StewardVerdict | null;
|
|
28
|
+
/** The `prior_messages` push: the last `n` verdicts and the last `n` gate events (so gates never crowd the
|
|
29
|
+
* verdicts out), file order, without `raw` and `impact` so it stays under the packet limit.
|
|
30
|
+
* `/session-messages` serves the full records. */
|
|
31
|
+
export declare function stewardPushRecords(records: StewardRecord[], n?: number): StewardRecord[];
|
|
19
32
|
/** Sidecar path: next to session.db and compactions.jsonl. */
|
|
20
33
|
export declare function getStewardLogPath(sessionId: string, workingDir: string): string;
|
|
21
|
-
export declare function
|
|
22
|
-
/** Every recorded verdict for a session, file order. Missing file or torn lines are skipped. */
|
|
23
|
-
export declare function
|
|
34
|
+
export declare function appendStewardRecord(sessionId: string, workingDir: string, v: StewardRecord): void;
|
|
35
|
+
/** Every recorded verdict and gate event for a session, file order. Missing file or torn lines are skipped. */
|
|
36
|
+
export declare function readStewardRecords(sessionId: string, workingDir: string): StewardRecord[];
|
package/dist/steward-verdict.js
CHANGED
|
@@ -6,22 +6,32 @@ import { dirname, join } from 'path';
|
|
|
6
6
|
import { getStorePath } from './session-store.js';
|
|
7
7
|
const LABELS = {
|
|
8
8
|
'VERDICT': 'verdict', 'REUSE MAP': 'reuse', 'INVENTORY': 'reuse', 'DUPLICATES': 'reuse', 'BEHAVIOUR': 'regressions', 'NET-NEW': 'netNew', 'REMOVED': 'removed',
|
|
9
|
-
'REGRESSION MAP': 'regressions', 'IMPACT': '
|
|
9
|
+
'REGRESSION MAP': 'regressions', 'IMPACT': 'impact', 'CHALLENGED': 'regressions', 'TESTS': 'regressions',
|
|
10
|
+
'SETTLED': 'regressions', 'STEPS': 'regressions', 'LINES': 'lines', 'HISTORY': 'history', 'ROOT CAUSE': 'rootCause',
|
|
10
11
|
'DECISION': 'decision', 'HUMAN DECISION': 'decision', 'DECISION NEEDED': 'decision',
|
|
11
12
|
};
|
|
12
13
|
// A label line, tolerant of markdown: "- **VERDICT:** ...", "## HISTORY", "ROOT CAUSE — ...".
|
|
13
14
|
const LABEL_RE = new RegExp(`^[\\s>#*_\\-•]*(${Object.keys(LABELS).sort((a, b) => b.length - a.length).join('|')})[*_\\s]*(?::|—|–|$)[*_\\s]*(.*)$`, 'i');
|
|
14
15
|
const strip = (s) => s.replace(/^[\s>*_\-•]+|[\s*_]+$/g, '').replace(/\*\*/g, '').trim();
|
|
15
16
|
const isNone = (s) => /^(none|n\/a|nothing)\b\.?$/i.test(s);
|
|
17
|
+
// Labels the template puts after HISTORY: only these may end it from a bullet line, so a
|
|
18
|
+
// "- IMPACT: …" or "- coupled: …" bullet inside HISTORY stays history (#259).
|
|
19
|
+
const AFTER_HISTORY = new Set(['CHALLENGED', 'SETTLED', 'STEPS', 'ROOT CAUSE', 'DECISION', 'HUMAN DECISION', 'DECISION NEEDED']);
|
|
20
|
+
const BULLET_RE = /^\s*(?:[-•*]\s|>)/;
|
|
21
|
+
// Bounds, so a long return cannot overflow the data-channel packet on reload.
|
|
22
|
+
const MAX_ENTRIES = 20, MAX_ENTRY = 300, MAX_TEXT = 1000, MAX_RAW = 6000;
|
|
23
|
+
const cap = (s, n) => (s.length > n ? s.slice(0, n) + '… [truncated]' : s);
|
|
16
24
|
/** Parse a steward return. Null when the text carries no VERDICT line. */
|
|
17
25
|
export function parseStewardVerdict(text, at = new Date().toISOString()) {
|
|
18
26
|
const sections = {};
|
|
19
27
|
const loose = [];
|
|
20
28
|
let current = null;
|
|
21
|
-
|
|
29
|
+
// Model-written text: CRLF or lone CR line endings are normalised, or no label would match (#250).
|
|
30
|
+
for (const line of String(text ?? '').split(/\r\n?|\n/)) {
|
|
22
31
|
const m = line.match(LABEL_RE);
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
const label = m ? m[1].toUpperCase().replace(/\s+/g, ' ') : '';
|
|
33
|
+
if (m && !(current === 'history' && BULLET_RE.test(line) && !AFTER_HISTORY.has(label))) {
|
|
34
|
+
current = LABELS[label];
|
|
25
35
|
(sections[current] ??= []);
|
|
26
36
|
const rest = strip(m[2]);
|
|
27
37
|
if (rest)
|
|
@@ -45,42 +55,51 @@ export function parseStewardVerdict(text, at = new Date().toISOString()) {
|
|
|
45
55
|
const entries = (k) => {
|
|
46
56
|
const ls = sections[k] ?? [];
|
|
47
57
|
const out = (ls.length === 1 ? ls[0].split(/;\s+/) : ls).map(strip).filter(Boolean);
|
|
48
|
-
|
|
49
|
-
return out.length === 1 && isNone(out[0]) ? [] : out.slice(0, 20).map((e) => e.slice(0, 300));
|
|
58
|
+
return out.length === 1 && isNone(out[0]) ? [] : out.map((e) => e.slice(0, MAX_ENTRY));
|
|
50
59
|
};
|
|
51
|
-
|
|
60
|
+
const bounded = (k) => entries(k).slice(0, MAX_ENTRIES);
|
|
61
|
+
// REUSE MAP stays in `raw` only; a NET-NEW entry inside the reuse map is lifted out, then capped.
|
|
52
62
|
const netNew = entries('netNew');
|
|
53
63
|
for (const e of entries('reuse')) {
|
|
54
64
|
if (/NET-NEW/i.test(e))
|
|
55
65
|
netNew.push(e.replace(/\s*(?:→|->|\|)?\s*NET-NEW\s*:?\s*/i, ' — ').replace(/^ — /, ''));
|
|
56
66
|
}
|
|
57
|
-
const joined = (k) => (sections[k] ?? []).join(' ').trim() || undefined;
|
|
67
|
+
const joined = (k) => cap((sections[k] ?? []).join(' ').trim(), MAX_TEXT) || undefined;
|
|
68
|
+
const impact = bounded('impact');
|
|
58
69
|
// "For BLOCK, name the decision": a labelled DECISION line, else the free text that follows.
|
|
59
70
|
const decision = verdict === 'BLOCK' ? joined('decision') ?? (loose.join(' ') || undefined) : undefined;
|
|
60
71
|
return {
|
|
61
72
|
verdict,
|
|
62
|
-
summary: strip(vm[2]),
|
|
63
|
-
...(decision ? { decision } : {}),
|
|
73
|
+
summary: cap(strip(vm[2]), MAX_TEXT),
|
|
74
|
+
...(decision ? { decision: cap(decision, MAX_TEXT) } : {}),
|
|
64
75
|
...(joined('rootCause') ? { rootCause: joined('rootCause') } : {}),
|
|
65
|
-
netNew,
|
|
66
|
-
removed:
|
|
76
|
+
netNew: netNew.slice(0, MAX_ENTRIES),
|
|
77
|
+
removed: bounded('removed'),
|
|
67
78
|
...(joined('lines') ? { lines: joined('lines') } : {}),
|
|
68
|
-
history:
|
|
69
|
-
|
|
79
|
+
history: bounded('history'),
|
|
80
|
+
...(impact.length ? { impact } : {}),
|
|
81
|
+
raw: cap(String(text).trim(), MAX_RAW),
|
|
70
82
|
at,
|
|
71
83
|
};
|
|
72
84
|
}
|
|
85
|
+
/** The `prior_messages` push: the last `n` verdicts and the last `n` gate events (so gates never crowd the
|
|
86
|
+
* verdicts out), file order, without `raw` and `impact` so it stays under the packet limit.
|
|
87
|
+
* `/session-messages` serves the full records. */
|
|
88
|
+
export function stewardPushRecords(records, n = 10) {
|
|
89
|
+
const keep = new Set([...records.filter((r) => 'verdict' in r).slice(-n), ...records.filter((r) => 'gate' in r).slice(-n)]);
|
|
90
|
+
return records.filter((r) => keep.has(r)).map((r) => ('verdict' in r ? { ...r, raw: undefined, impact: undefined } : r));
|
|
91
|
+
}
|
|
73
92
|
/** Sidecar path: next to session.db and compactions.jsonl. */
|
|
74
93
|
export function getStewardLogPath(sessionId, workingDir) {
|
|
75
94
|
return join(dirname(getStorePath(sessionId, workingDir)), 'steward.jsonl');
|
|
76
95
|
}
|
|
77
|
-
export function
|
|
96
|
+
export function appendStewardRecord(sessionId, workingDir, v) {
|
|
78
97
|
const p = getStewardLogPath(sessionId, workingDir);
|
|
79
98
|
mkdirSync(dirname(p), { recursive: true });
|
|
80
99
|
appendFileSync(p, JSON.stringify(v) + '\n', 'utf-8');
|
|
81
100
|
}
|
|
82
|
-
/** Every recorded verdict for a session, file order. Missing file or torn lines are skipped. */
|
|
83
|
-
export function
|
|
101
|
+
/** Every recorded verdict and gate event for a session, file order. Missing file or torn lines are skipped. */
|
|
102
|
+
export function readStewardRecords(sessionId, workingDir) {
|
|
84
103
|
const p = getStewardLogPath(sessionId, workingDir);
|
|
85
104
|
if (!existsSync(p))
|
|
86
105
|
return [];
|
|
@@ -88,7 +107,7 @@ export function readStewardVerdicts(sessionId, workingDir) {
|
|
|
88
107
|
for (const line of readFileSync(p, 'utf-8').split('\n')) {
|
|
89
108
|
try {
|
|
90
109
|
const o = JSON.parse(line);
|
|
91
|
-
if (o && typeof o.verdict === 'string' && typeof o.at === 'string')
|
|
110
|
+
if (o && (typeof o.verdict === 'string' || typeof o.gate === 'string') && typeof o.at === 'string')
|
|
92
111
|
out.push(o);
|
|
93
112
|
}
|
|
94
113
|
catch { /* blank or torn line */ }
|
package/dist/watch-gateway.js
CHANGED
|
@@ -80,6 +80,8 @@ export function startWatchGateway(opts) {
|
|
|
80
80
|
response: msg.allow ? 'allow' : 'deny',
|
|
81
81
|
source: 'watch',
|
|
82
82
|
qid: msg.qid,
|
|
83
|
+
// The question's qid is the agent's requestId: the answer settles only that request.
|
|
84
|
+
requestId: msg.qid,
|
|
83
85
|
});
|
|
84
86
|
void session.room.localParticipant
|
|
85
87
|
?.publishData(new TextEncoder().encode(payload), { reliable: true })
|
|
@@ -133,7 +135,7 @@ export function startWatchGateway(opts) {
|
|
|
133
135
|
// The watch shows a yes/no sheet for blocking questions.
|
|
134
136
|
wsSendJson(ws, {
|
|
135
137
|
type: 'question',
|
|
136
|
-
qid: parsed.toolUseId ?? parsed.toolName ?? 'perm',
|
|
138
|
+
qid: parsed.requestId ?? parsed.toolUseId ?? parsed.toolName ?? 'perm',
|
|
137
139
|
text: parsed.description ?? `Use ${parsed.toolName}?`,
|
|
138
140
|
});
|
|
139
141
|
}
|
package/package.json
CHANGED
package/dist/bridge-llm.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bridge LLM Module - Creates LLM instances for pipelined voice sessions
|
|
3
|
-
*
|
|
4
|
-
* In pipelined mode, we use a separate LLM (Gemini or GPT-4o) as the
|
|
5
|
-
* "conversation manager" that handles voice I/O and routes to Claude Code.
|
|
6
|
-
*/
|
|
7
|
-
import * as google from '@livekit/agents-plugin-google';
|
|
8
|
-
import * as openai from '@livekit/agents-plugin-openai';
|
|
9
|
-
export interface BridgeLLMConfig {
|
|
10
|
-
provider: 'gemini-pro' | 'gemini-flash' | 'gpt-4o' | 'gpt-4o-mini';
|
|
11
|
-
model?: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Create Bridge LLM instance for pipelined voice sessions
|
|
15
|
-
*
|
|
16
|
-
* Options:
|
|
17
|
-
* - gemini-pro: Gemini 2.5 Pro (smart, good reasoning)
|
|
18
|
-
* - gemini-flash: Gemini 2.0 Flash (faster, cheaper)
|
|
19
|
-
* - gpt-4o: GPT-4o (alternative if OpenAI preferred)
|
|
20
|
-
* - gpt-4o-mini: GPT-4o Mini (faster, cheaper)
|
|
21
|
-
*/
|
|
22
|
-
export declare function createBridgeLLM(config: BridgeLLMConfig): google.LLM | openai.LLM;
|