osborn 0.9.280 → 0.9.282
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/dist/agent-store.d.ts +164 -0
- package/dist/agent-store.js +302 -0
- package/dist/claude-llm.d.ts +7 -8
- package/dist/claude-llm.js +75 -171
- package/dist/content/compaction-lens-worker.js +2 -1
- package/dist/content/content-run.js +9 -9
- package/dist/content/lens-clip-window.js +7 -6
- package/dist/content/lens-launch.d.ts +11 -0
- package/dist/content/lens-launch.js +11 -0
- package/dist/content/lens-library-select.d.ts +7 -5
- package/dist/content/lens-library-select.js +7 -6
- package/dist/content/lens-library.d.ts +7 -1
- package/dist/content/lens-library.js +29 -6
- package/dist/data-sender-auth.d.ts +3 -2
- package/dist/data-sender-auth.js +10 -3
- package/dist/index.js +376 -190
- package/dist/pipeline-direct-llm.d.ts +1 -1
- package/dist/pipeline-direct-llm.js +1 -1
- package/dist/prompts/chain-after-planner.md +1 -0
- package/dist/prompts/chain-after-researcher.md +1 -0
- package/dist/prompts/chain-after-writer.md +1 -0
- package/dist/prompts/direct-mode-research.md +2 -2
- package/dist/prompts/steward.md +131 -0
- package/dist/prompts.d.ts +6 -0
- package/dist/prompts.js +18 -1
- package/dist/pushover.d.ts +7 -0
- package/dist/pushover.js +45 -42
- package/dist/steward-gate.d.ts +6 -5
- package/dist/steward-gate.js +256 -32
- package/dist/steward-verdict.d.ts +23 -0
- package/dist/steward-verdict.js +97 -0
- package/dist/stopwords.d.ts +1 -0
- package/dist/stopwords.js +6 -0
- package/dist/store-catalog.d.ts +106 -0
- package/dist/store-catalog.js +356 -0
- package/dist/store-name.d.ts +1 -0
- package/dist/store-name.js +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { storeName } from './store-name.js';
|
|
2
|
+
export { storeName };
|
|
3
|
+
export interface AgentDef {
|
|
4
|
+
description: string;
|
|
5
|
+
prompt: string;
|
|
6
|
+
tools?: string[];
|
|
7
|
+
model?: string;
|
|
8
|
+
grounded?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** The built-in agents (claude-llm.ts NAMED_AGENTS): each holds the role of its own name. */
|
|
11
|
+
export type CoreAgents = Record<string, {
|
|
12
|
+
description: string;
|
|
13
|
+
prompt: string;
|
|
14
|
+
tools?: readonly string[];
|
|
15
|
+
model?: string;
|
|
16
|
+
grounded?: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
export interface AgentListing {
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
model?: string;
|
|
22
|
+
tools?: string[];
|
|
23
|
+
core: boolean;
|
|
24
|
+
prompt?: string;
|
|
25
|
+
/** A user agent's origin, for people: the built-in it was forked from, or 'owner/repo @sha7' for a catalog install. */
|
|
26
|
+
origin?: string;
|
|
27
|
+
role: Role;
|
|
28
|
+
/** The role's one-liner (for a built-in agent, its card text) and icon key. */
|
|
29
|
+
summary: string;
|
|
30
|
+
icon: string;
|
|
31
|
+
behaviours: string[];
|
|
32
|
+
}
|
|
33
|
+
/** 'workspace': session workspace only. 'anywhere': any path, through the
|
|
34
|
+
* permission dialog. Extension rule: only matching files (fail closed). */
|
|
35
|
+
export type WriteRule = 'workspace' | 'anywhere' | {
|
|
36
|
+
extensions: RegExp;
|
|
37
|
+
label: string;
|
|
38
|
+
matchBasename?: boolean;
|
|
39
|
+
};
|
|
40
|
+
export declare const ROLE_NAMES: readonly ["reader", "researcher", "reasoner", "planner", "writer", "tester", "steward", "reviewer"];
|
|
41
|
+
export type Role = typeof ROLE_NAMES[number];
|
|
42
|
+
interface RoleSpec {
|
|
43
|
+
/** One line for people: the card text of the built-in agent of this role, and the role picker's hint. */
|
|
44
|
+
summary: string;
|
|
45
|
+
/** Icon key; the frontend maps it to a glyph. */
|
|
46
|
+
icon: string;
|
|
47
|
+
write: WriteRule;
|
|
48
|
+
/** A built-in agent of this role writes into .claude/skills/<name>/ without a dialog. */
|
|
49
|
+
skillInstall?: boolean;
|
|
50
|
+
/** Its first edit of an existing file each turn is held once with a history reminder; its writes show in the live trace. */
|
|
51
|
+
historyFirst?: boolean;
|
|
52
|
+
/** Its final message is parsed into a steward verdict card. */
|
|
53
|
+
verdict?: boolean;
|
|
54
|
+
/** Verifier chain: who runs after it. The text pushed to the orchestrator when it
|
|
55
|
+
* finishes is a prompt: prompts/chain-after-<role>.md (getChainReminder). */
|
|
56
|
+
chain?: Role[];
|
|
57
|
+
}
|
|
58
|
+
export declare const ROLES: Record<Role, RoleSpec>;
|
|
59
|
+
/** Tools that edit files: the write gate covers each of them, and a catalog draft with one is a writer. */
|
|
60
|
+
export declare const EDIT_TOOLS: ReadonlySet<string>;
|
|
61
|
+
/** The role a catalog agent's draft starts with: a writer if it can edit, else a reader.
|
|
62
|
+
* It is saved on the row, so the owner sees it and can change it. Never applied to saved rows. */
|
|
63
|
+
export declare const draftRole: (tools?: string[] | null) => Role;
|
|
64
|
+
/** The role of a built-in agent (null for any other name). Own keys only. */
|
|
65
|
+
export declare const coreRole: (name: unknown, core: CoreAgents) => Role | null;
|
|
66
|
+
/** The acting agent's role (null = the main orchestrator, or an agent we do not know). */
|
|
67
|
+
export declare function roleOf(agentType: unknown, userRoles: Record<string, Role> | undefined, core: CoreAgents): Role | null;
|
|
68
|
+
/** Skill folders are written without a dialog only by a BUILT-IN agent whose role installs skills. */
|
|
69
|
+
export declare const installsSkillsSilently: (role: Role | null, isCore: boolean) => boolean;
|
|
70
|
+
export declare const AGENT_MODELS: readonly ["inherit", "sonnet", "opus", "haiku", "fable"];
|
|
71
|
+
export declare const isAgentModel: (m: unknown) => m is string;
|
|
72
|
+
export declare const AGENT_LIMITS: {
|
|
73
|
+
readonly name: 40;
|
|
74
|
+
readonly description: 500;
|
|
75
|
+
readonly prompt: 20000;
|
|
76
|
+
};
|
|
77
|
+
/** Roles, chains and the editor's rules for the store (served by /agents and agents_status). */
|
|
78
|
+
export declare const describeRoles: () => {
|
|
79
|
+
roles: {
|
|
80
|
+
role: "reader" | "researcher" | "reasoner" | "planner" | "writer" | "tester" | "steward" | "reviewer";
|
|
81
|
+
summary: string;
|
|
82
|
+
icon: string;
|
|
83
|
+
behaviours: string[];
|
|
84
|
+
}[];
|
|
85
|
+
chains: ("reader" | "researcher" | "reasoner" | "planner" | "writer" | "tester" | "steward" | "reviewer")[][];
|
|
86
|
+
models: readonly ["inherit", "sonnet", "opus", "haiku", "fable"];
|
|
87
|
+
limits: {
|
|
88
|
+
readonly name: 40;
|
|
89
|
+
readonly description: 500;
|
|
90
|
+
readonly prompt: 20000;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
export declare const catalogOrigin: (e: {
|
|
94
|
+
source: string;
|
|
95
|
+
repo: string;
|
|
96
|
+
sha: string;
|
|
97
|
+
path: string;
|
|
98
|
+
}) => string;
|
|
99
|
+
/** The same catalog file at any commit. */
|
|
100
|
+
export declare const unpinnedOrigin: (origin: string) => string;
|
|
101
|
+
/** Validates user_agents rows. Disabled rows are skipped; every other dropped
|
|
102
|
+
* row is reported with its reason (a core name: core agents cannot be overridden). */
|
|
103
|
+
export declare function parseUserAgents(rows: unknown, core: CoreAgents): {
|
|
104
|
+
agents: Record<string, AgentDef>;
|
|
105
|
+
roles: Record<string, Role>;
|
|
106
|
+
origins: Record<string, string>;
|
|
107
|
+
dropped: {
|
|
108
|
+
name: string;
|
|
109
|
+
reason: string;
|
|
110
|
+
}[];
|
|
111
|
+
};
|
|
112
|
+
/** Effective agent set: every core agent, plus user agents whose names are free. */
|
|
113
|
+
export declare function mergeAgents<T>(core: Record<string, T>, user: Record<string, T> | null | undefined): Record<string, T>;
|
|
114
|
+
/** UI listing; withPrompts adds the core prompts (GET /agents only, never the data channel). */
|
|
115
|
+
export declare function describeAgents(core: CoreAgents, user: Record<string, AgentDef> | null | undefined, roles?: Record<string, Role>, withPrompts?: boolean, origins?: Record<string, string>): AgentListing[];
|
|
116
|
+
/** Browser origins allowed to make store writes on a machine with no sync token: a local
|
|
117
|
+
* page, voice-native.com, or the frontend the agent is configured with. No Origin = not a
|
|
118
|
+
* browser cross-site request. Also decides which origin the write routes' CORS echoes. */
|
|
119
|
+
export declare function storeWriteOriginAllowed(origin: string | undefined, frontendUrl: string): boolean;
|
|
120
|
+
/** Refusal for a store request, or null. With a token, unauthorized() has already checked it;
|
|
121
|
+
* without one, only this machine's own pages may use the store (reads carry the core prompts
|
|
122
|
+
* and the user's skills), never a public or tunnelled address, and every write must be JSON
|
|
123
|
+
* (no other site's form or text/plain POST). */
|
|
124
|
+
export declare function storeWriteRefusal(r: {
|
|
125
|
+
hasToken: boolean;
|
|
126
|
+
publicDeploy: boolean;
|
|
127
|
+
forwarded: boolean;
|
|
128
|
+
host?: string;
|
|
129
|
+
remote?: string;
|
|
130
|
+
origin?: string;
|
|
131
|
+
contentType?: string;
|
|
132
|
+
frontendUrl: string;
|
|
133
|
+
read?: boolean;
|
|
134
|
+
}): {
|
|
135
|
+
status: number;
|
|
136
|
+
error: string;
|
|
137
|
+
} | null;
|
|
138
|
+
/** YAML front matter + body. Front matter YAML rejects (an unquoted ': ' is common in
|
|
139
|
+
* descriptions) falls back to its top-level `key: value` lines. */
|
|
140
|
+
export declare function parseFrontMatter(md: string): {
|
|
141
|
+
meta: Record<string, unknown>;
|
|
142
|
+
body: string;
|
|
143
|
+
};
|
|
144
|
+
/** Folder names of the skills shipped with the package. */
|
|
145
|
+
export declare function coreSkillNames(pkgSkillsDir: string): Set<string>;
|
|
146
|
+
export declare function skillForkedFrom(skillsDir: string, folder: string): string | undefined;
|
|
147
|
+
type SkillResult = {
|
|
148
|
+
ok: true;
|
|
149
|
+
} | {
|
|
150
|
+
error: string;
|
|
151
|
+
};
|
|
152
|
+
export declare function readUserSkill(skillsDir: string, name: unknown): {
|
|
153
|
+
name: string;
|
|
154
|
+
content: string;
|
|
155
|
+
} | {
|
|
156
|
+
error: string;
|
|
157
|
+
};
|
|
158
|
+
/** Writes a skill the user sent. A built-in name installs the packaged copy instead of the
|
|
159
|
+
* sent body (it lists as built in, so it must be the shipped one; the Browser Screen Recorder
|
|
160
|
+
* seed updates itself from the served copy); an installed built-in is never overwritten. */
|
|
161
|
+
export declare function addUserSkill(skillsDir: string, pkgSkillsDir: string, name: unknown, content: unknown): SkillResult;
|
|
162
|
+
/** Copies a core skill folder to a new user-owned name (front matter `name` renamed). */
|
|
163
|
+
export declare function forkSkill(skillsDir: string, pkgSkillsDir: string, from: unknown, to: unknown): SkillResult;
|
|
164
|
+
export declare function removeUserSkill(skillsDir: string, pkgSkillsDir: string, name: unknown): SkillResult;
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
// Agent & skill store rules. Built-in (core) agents and shipped skills are
|
|
2
|
+
// maintained by Voice Native: users can view and fork them, never override,
|
|
3
|
+
// edit or remove them. A fork is a user-owned copy under a new name.
|
|
4
|
+
// The frontend reads every rule it shows (roles, models, limits) from here
|
|
5
|
+
// through /agents and agents_status; it keeps no copy.
|
|
6
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync, cpSync, rmSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { parse as parseYaml } from 'yaml';
|
|
9
|
+
import { storeName } from './store-name.js';
|
|
10
|
+
export { storeName };
|
|
11
|
+
export const ROLE_NAMES = ['reader', 'researcher', 'reasoner', 'planner', 'writer', 'tester', 'steward', 'reviewer'];
|
|
12
|
+
const isRole = (r) => typeof r === 'string' && ROLE_NAMES.includes(r);
|
|
13
|
+
export const ROLES = {
|
|
14
|
+
reader: { summary: 'Reads and reports. Writes notes in the session workspace only.', icon: 'robot', write: 'workspace' },
|
|
15
|
+
researcher: {
|
|
16
|
+
summary: 'Digs through your code and the web to gather facts; a reasoner checks them before they are used.',
|
|
17
|
+
icon: 'search', write: 'workspace', chain: ['reasoner'],
|
|
18
|
+
},
|
|
19
|
+
reasoner: { summary: 'Thinks through hard problems, writes plans and gates research. Writes notes in the session workspace only.', icon: 'brain', write: 'workspace' },
|
|
20
|
+
planner: {
|
|
21
|
+
summary: 'Breaks a task into ordered steps; the steward checks the plan for things that already exist.',
|
|
22
|
+
icon: 'list', write: 'workspace', chain: ['steward', 'writer'],
|
|
23
|
+
},
|
|
24
|
+
writer: {
|
|
25
|
+
summary: 'Makes the code changes (each write goes through your permission settings); its work is tested, stewarded and reviewed.',
|
|
26
|
+
icon: 'pen', write: 'anywhere', skillInstall: true, historyFirst: true, chain: ['tester', 'steward', 'reviewer'],
|
|
27
|
+
},
|
|
28
|
+
tester: { summary: 'Writes and runs tests to check the work holds up. May write test files only.', icon: 'test', write: { extensions: /\.(test|spec)\.[jt]sx?$/, label: 'test', matchBasename: true } },
|
|
29
|
+
steward: {
|
|
30
|
+
summary: 'Keeps the code lean: reuses what exists and makes sure a change breaks nothing that depends on it.',
|
|
31
|
+
icon: 'shield', write: 'anywhere', // refactors the writer's diff in place
|
|
32
|
+
verdict: true,
|
|
33
|
+
},
|
|
34
|
+
reviewer: { summary: 'Reviews the final diff for problems before it ships. May write documentation files only.', icon: 'eye', write: { extensions: /\.(md|markdown|mdx|txt|rst|adoc)$/i, label: 'documentation' } },
|
|
35
|
+
};
|
|
36
|
+
/** Tools that edit files: the write gate covers each of them, and a catalog draft with one is a writer. */
|
|
37
|
+
export const EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit']);
|
|
38
|
+
/** The role a catalog agent's draft starts with: a writer if it can edit, else a reader.
|
|
39
|
+
* It is saved on the row, so the owner sees it and can change it. Never applied to saved rows. */
|
|
40
|
+
export const draftRole = (tools) => (tools || []).some((t) => EDIT_TOOLS.has(String(t).trim())) ? 'writer' : 'reader';
|
|
41
|
+
/** The role of a built-in agent (null for any other name). Own keys only. */
|
|
42
|
+
export const coreRole = (name, core) => typeof name === 'string' && Object.hasOwn(core, name) && isRole(name) ? name : null;
|
|
43
|
+
/** Role of a saved user agent: the one set on it, else its built-in parent's, else reader (never inferred). */
|
|
44
|
+
const resolveRole = (a, core) => isRole(a.role) ? a.role : coreRole(a.forkedFrom, core) ?? 'reader';
|
|
45
|
+
/** The acting agent's role (null = the main orchestrator, or an agent we do not know). */
|
|
46
|
+
export function roleOf(agentType, userRoles, core) {
|
|
47
|
+
if (typeof agentType !== 'string' || !agentType)
|
|
48
|
+
return null;
|
|
49
|
+
return userRoles && Object.hasOwn(userRoles, agentType) ? userRoles[agentType] : coreRole(agentType, core);
|
|
50
|
+
}
|
|
51
|
+
/** Skill folders are written without a dialog only by a BUILT-IN agent whose role installs skills. */
|
|
52
|
+
export const installsSkillsSilently = (role, isCore) => !!(role && isCore && ROLES[role].skillInstall);
|
|
53
|
+
/** What a role unlocks, in plain words for the store. */
|
|
54
|
+
function roleBehaviours(role, isCore) {
|
|
55
|
+
const r = ROLES[role];
|
|
56
|
+
const out = [];
|
|
57
|
+
if (r.write === 'workspace')
|
|
58
|
+
out.push('Writes only in the session workspace');
|
|
59
|
+
else if (r.write === 'anywhere')
|
|
60
|
+
out.push('Can edit files anywhere, through your permission settings');
|
|
61
|
+
else
|
|
62
|
+
out.push(`Can write ${r.write.label} files only`);
|
|
63
|
+
if (installsSkillsSilently(role, isCore))
|
|
64
|
+
out.push('Installs skills without asking for each file');
|
|
65
|
+
if (r.historyFirst)
|
|
66
|
+
out.push("Checks a file's history before its first edit");
|
|
67
|
+
if (r.verdict)
|
|
68
|
+
out.push('Its verdict shows as a card in chat');
|
|
69
|
+
if (r.chain)
|
|
70
|
+
out.push(`When it finishes: ${r.chain.join(' → ')}`);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
// ── Definitions shared with the frontend and the user_agents SQL checks ───────
|
|
74
|
+
// (migrations 004/015/016/018; agent/tests/user-agents-migrations.test.ts keeps them equal)
|
|
75
|
+
export const AGENT_MODELS = ['inherit', 'sonnet', 'opus', 'haiku', 'fable'];
|
|
76
|
+
export const isAgentModel = (m) => typeof m === 'string' && (AGENT_MODELS.includes(m) || /^claude-/.test(m));
|
|
77
|
+
export const AGENT_LIMITS = { name: 40, description: 500, prompt: 20000 };
|
|
78
|
+
/** Roles, chains and the editor's rules for the store (served by /agents and agents_status). */
|
|
79
|
+
export const describeRoles = () => ({
|
|
80
|
+
roles: ROLE_NAMES.map((role) => ({ role, summary: ROLES[role].summary, icon: ROLES[role].icon, behaviours: roleBehaviours(role, false) })),
|
|
81
|
+
chains: ROLE_NAMES.filter((r) => ROLES[r].chain).map((r) => [r, ...ROLES[r].chain]),
|
|
82
|
+
models: AGENT_MODELS,
|
|
83
|
+
limits: AGENT_LIMITS,
|
|
84
|
+
});
|
|
85
|
+
// ── Catalog origins: forked_from of an agent installed from a store catalog ────
|
|
86
|
+
// '<source>:<owner>/<repo>@<sha>/<path>' (user_agents check, migration 016).
|
|
87
|
+
export const catalogOrigin = (e) => `${e.source}:${e.repo}@${e.sha}/${e.path}`;
|
|
88
|
+
/** The same catalog file at any commit. */
|
|
89
|
+
export const unpinnedOrigin = (origin) => origin.replace(/@[0-9a-f]{7,40}\//, '/');
|
|
90
|
+
/** Where a user agent came from, for people: its built-in parent's name, or 'owner/repo @sha7'. */
|
|
91
|
+
const originLabel = (forkedFrom, core) => {
|
|
92
|
+
if (coreRole(forkedFrom, core))
|
|
93
|
+
return forkedFrom;
|
|
94
|
+
const m = /^[^:]+:([^@]+)@([0-9a-f]{7})[0-9a-f]*\//.exec(forkedFrom);
|
|
95
|
+
return m ? `${m[1]} @${m[2]}` : undefined;
|
|
96
|
+
};
|
|
97
|
+
/** Validates user_agents rows. Disabled rows are skipped; every other dropped
|
|
98
|
+
* row is reported with its reason (a core name: core agents cannot be overridden). */
|
|
99
|
+
export function parseUserAgents(rows, core) {
|
|
100
|
+
const agents = {};
|
|
101
|
+
const roles = {};
|
|
102
|
+
const origins = {};
|
|
103
|
+
const dropped = [];
|
|
104
|
+
for (const r of Array.isArray(rows) ? rows : []) {
|
|
105
|
+
const name = storeName(r?.name);
|
|
106
|
+
const description = String(r?.description || '').trim();
|
|
107
|
+
const prompt = String(r?.prompt || '').trim();
|
|
108
|
+
if (r?.enabled === false)
|
|
109
|
+
continue;
|
|
110
|
+
const reason = !name ? 'no name'
|
|
111
|
+
: Object.hasOwn(core, name) ? 'is a core agent (fork it under a new name)'
|
|
112
|
+
: name.length > AGENT_LIMITS.name ? `name longer than ${AGENT_LIMITS.name}`
|
|
113
|
+
: !description ? 'no description'
|
|
114
|
+
: description.length > AGENT_LIMITS.description ? `description longer than ${AGENT_LIMITS.description}`
|
|
115
|
+
: !prompt ? 'no prompt'
|
|
116
|
+
: prompt.length > AGENT_LIMITS.prompt ? `prompt longer than ${AGENT_LIMITS.prompt}`
|
|
117
|
+
: '';
|
|
118
|
+
if (reason) {
|
|
119
|
+
dropped.push({ name: name || '(unnamed)', reason });
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const rawFrom = String(r.forkedFrom ?? r.forked_from ?? '').trim();
|
|
123
|
+
const origin = originLabel(rawFrom, core);
|
|
124
|
+
if (origin)
|
|
125
|
+
origins[name] = origin;
|
|
126
|
+
// Only a built-in parent matters to the role and grounding; a catalog origin names none.
|
|
127
|
+
const from = storeName(rawFrom);
|
|
128
|
+
roles[name] = resolveRole({ role: r.role, forkedFrom: from }, core);
|
|
129
|
+
const listed = Array.isArray(r.tools) ? r.tools.map((t) => String(t).trim()).filter(Boolean) : []; // ' Edit ' is Edit
|
|
130
|
+
const tools = listed.length ? listed : undefined;
|
|
131
|
+
agents[name] = {
|
|
132
|
+
description,
|
|
133
|
+
prompt,
|
|
134
|
+
...(tools ? { tools } : {}),
|
|
135
|
+
...(isAgentModel(r.model) ? { model: r.model } : {}),
|
|
136
|
+
// A fork of a grounded built-in reads the session recall store like its parent (claude-llm applyGrounding).
|
|
137
|
+
...(coreRole(from, core) && core[from].grounded ? { grounded: true } : {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return { agents, roles, origins, dropped };
|
|
141
|
+
}
|
|
142
|
+
/** Effective agent set: every core agent, plus user agents whose names are free. */
|
|
143
|
+
export function mergeAgents(core, user) {
|
|
144
|
+
const out = { ...core };
|
|
145
|
+
for (const [name, a] of Object.entries(user || {}))
|
|
146
|
+
if (!Object.hasOwn(core, name))
|
|
147
|
+
out[name] = a;
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
/** UI listing; withPrompts adds the core prompts (GET /agents only, never the data channel). */
|
|
151
|
+
export function describeAgents(core, user, roles = {}, withPrompts = false, origins = {}) {
|
|
152
|
+
return Object.entries(mergeAgents(core, user)).map(([name, a]) => {
|
|
153
|
+
const isCore = Object.hasOwn(core, name);
|
|
154
|
+
const role = roleOf(name, roles, core) ?? 'reader';
|
|
155
|
+
return {
|
|
156
|
+
name, description: a.description, model: a.model, tools: a.tools ? [...a.tools] : undefined, core: isCore, role,
|
|
157
|
+
summary: ROLES[role].summary, icon: ROLES[role].icon, behaviours: roleBehaviours(role, isCore),
|
|
158
|
+
...(isCore && withPrompts ? { prompt: a.prompt } : {}),
|
|
159
|
+
...(!isCore && Object.hasOwn(origins, name) ? { origin: origins[name] } : {}),
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
// ── Who may change the machine's skills (skills add/fork/remove, catalog install) ──
|
|
164
|
+
const LOOPBACK_HOST = /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/;
|
|
165
|
+
const LOOPBACK_ADDR = /^(127\.|::1$|::ffff:127\.)/;
|
|
166
|
+
/** Browser origins allowed to make store writes on a machine with no sync token: a local
|
|
167
|
+
* page, voice-native.com, or the frontend the agent is configured with. No Origin = not a
|
|
168
|
+
* browser cross-site request. Also decides which origin the write routes' CORS echoes. */
|
|
169
|
+
export function storeWriteOriginAllowed(origin, frontendUrl) {
|
|
170
|
+
if (!origin)
|
|
171
|
+
return true;
|
|
172
|
+
let u;
|
|
173
|
+
try {
|
|
174
|
+
u = new URL(origin);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
let configured = '';
|
|
180
|
+
try {
|
|
181
|
+
configured = new URL(frontendUrl).origin;
|
|
182
|
+
}
|
|
183
|
+
catch { /* none configured */ }
|
|
184
|
+
return LOOPBACK_HOST.test(u.host) || /^https:\/\/(www\.)?voice-native\.com$/.test(u.origin) || u.origin === configured;
|
|
185
|
+
}
|
|
186
|
+
/** Refusal for a store request, or null. With a token, unauthorized() has already checked it;
|
|
187
|
+
* without one, only this machine's own pages may use the store (reads carry the core prompts
|
|
188
|
+
* and the user's skills), never a public or tunnelled address, and every write must be JSON
|
|
189
|
+
* (no other site's form or text/plain POST). */
|
|
190
|
+
export function storeWriteRefusal(r) {
|
|
191
|
+
if (!r.hasToken) {
|
|
192
|
+
if (r.publicDeploy || r.forwarded || !LOOPBACK_HOST.test(r.host || ''))
|
|
193
|
+
return { status: 403, error: 'this machine is reachable from outside: set OSBORN_SYNC_TOKEN to use the store' };
|
|
194
|
+
if (!LOOPBACK_ADDR.test(r.remote || ''))
|
|
195
|
+
return { status: 403, error: 'the store needs the sync token or a request from this machine' };
|
|
196
|
+
if (!storeWriteOriginAllowed(r.origin, r.frontendUrl))
|
|
197
|
+
return { status: 403, error: 'the store is refused from this site' };
|
|
198
|
+
}
|
|
199
|
+
if (!r.read && !/^application\/json\b/i.test(r.contentType || ''))
|
|
200
|
+
return { status: 415, error: 'send JSON (Content-Type: application/json)' };
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
// ── SKILL.md and agent .md front matter ───────────────────────────────────────
|
|
204
|
+
const FRONT_MATTER = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
205
|
+
/** YAML front matter + body. Front matter YAML rejects (an unquoted ': ' is common in
|
|
206
|
+
* descriptions) falls back to its top-level `key: value` lines. */
|
|
207
|
+
export function parseFrontMatter(md) {
|
|
208
|
+
const m = FRONT_MATTER.exec(md);
|
|
209
|
+
if (!m)
|
|
210
|
+
return { meta: {}, body: md };
|
|
211
|
+
let meta = {};
|
|
212
|
+
try {
|
|
213
|
+
const y = parseYaml(m[1]);
|
|
214
|
+
if (y && typeof y === 'object' && !Array.isArray(y))
|
|
215
|
+
meta = y;
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
for (const line of m[1].split(/\r?\n/)) {
|
|
219
|
+
const kv = /^([A-Za-z0-9_-]+):[ \t]*(.+)$/.exec(line);
|
|
220
|
+
if (kv)
|
|
221
|
+
meta[kv[1]] = kv[2].trim().replace(/^(['"])(.*)\1$/, '$2');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (const [k, v] of Object.entries(meta))
|
|
225
|
+
if (typeof v === 'string')
|
|
226
|
+
meta[k] = v.trim();
|
|
227
|
+
return { meta, body: md.slice(m[0].length) };
|
|
228
|
+
}
|
|
229
|
+
// ── Skills ───────────────────────────────────────────────────────────────────
|
|
230
|
+
/** Folder names of the skills shipped with the package. */
|
|
231
|
+
export function coreSkillNames(pkgSkillsDir) {
|
|
232
|
+
try {
|
|
233
|
+
return new Set(readdirSync(pkgSkillsDir).filter((n) => existsSync(join(pkgSkillsDir, n, 'SKILL.md'))));
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return new Set();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const FORK_MARKER = '.forked-from';
|
|
240
|
+
export function skillForkedFrom(skillsDir, folder) {
|
|
241
|
+
try {
|
|
242
|
+
return readFileSync(join(skillsDir, folder, FORK_MARKER), 'utf-8').trim() || undefined;
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
export function readUserSkill(skillsDir, name) {
|
|
249
|
+
const folder = storeName(name);
|
|
250
|
+
const p = join(skillsDir, folder, 'SKILL.md');
|
|
251
|
+
return folder && existsSync(p) ? { name: folder, content: readFileSync(p, 'utf-8') } : { error: 'skill not found' };
|
|
252
|
+
}
|
|
253
|
+
/** Writes a skill the user sent. A built-in name installs the packaged copy instead of the
|
|
254
|
+
* sent body (it lists as built in, so it must be the shipped one; the Browser Screen Recorder
|
|
255
|
+
* seed updates itself from the served copy); an installed built-in is never overwritten. */
|
|
256
|
+
export function addUserSkill(skillsDir, pkgSkillsDir, name, content) {
|
|
257
|
+
const folder = storeName(name);
|
|
258
|
+
const md = String(content ?? '').trim();
|
|
259
|
+
if (!folder || !md)
|
|
260
|
+
return { error: 'Name and content are required' };
|
|
261
|
+
const dir = join(skillsDir, folder);
|
|
262
|
+
if (coreSkillNames(pkgSkillsDir).has(folder)) {
|
|
263
|
+
if (existsSync(join(dir, 'SKILL.md')))
|
|
264
|
+
return { error: `${folder} is a built-in skill — fork it under a new name` };
|
|
265
|
+
cpSync(join(pkgSkillsDir, folder), dir, { recursive: true });
|
|
266
|
+
return { ok: true };
|
|
267
|
+
}
|
|
268
|
+
mkdirSync(dir, { recursive: true });
|
|
269
|
+
writeFileSync(join(dir, 'SKILL.md'), md, 'utf-8');
|
|
270
|
+
return { ok: true };
|
|
271
|
+
}
|
|
272
|
+
/** Copies a core skill folder to a new user-owned name (front matter `name` renamed). */
|
|
273
|
+
export function forkSkill(skillsDir, pkgSkillsDir, from, to) {
|
|
274
|
+
const core = coreSkillNames(pkgSkillsDir);
|
|
275
|
+
const src = storeName(from), dst = storeName(to);
|
|
276
|
+
if (!core.has(src))
|
|
277
|
+
return { error: 'only built-in skills can be forked' };
|
|
278
|
+
if (!dst || core.has(dst))
|
|
279
|
+
return { error: 'choose a new name that is not a built-in skill' };
|
|
280
|
+
const dstDir = join(skillsDir, dst);
|
|
281
|
+
if (existsSync(dstDir))
|
|
282
|
+
return { error: `a skill named ${dst} already exists` };
|
|
283
|
+
const srcDir = existsSync(join(skillsDir, src, 'SKILL.md')) ? join(skillsDir, src) : join(pkgSkillsDir, src);
|
|
284
|
+
cpSync(srcDir, dstDir, { recursive: true });
|
|
285
|
+
const md = join(dstDir, 'SKILL.md');
|
|
286
|
+
const text = readFileSync(md, 'utf-8');
|
|
287
|
+
const fm = FRONT_MATTER.exec(text);
|
|
288
|
+
const named = (block) => /^name:.*$/m.test(block) ? block.replace(/^name:.*$/m, `name: ${dst}`) : block.replace(/^---\r?\n/, `---\nname: ${dst}\n`);
|
|
289
|
+
writeFileSync(md, fm ? named(fm[0]) + text.slice(fm[0].length) : `---\nname: ${dst}\n---\n${text}`, 'utf-8');
|
|
290
|
+
writeFileSync(join(dstDir, FORK_MARKER), src, 'utf-8');
|
|
291
|
+
return { ok: true };
|
|
292
|
+
}
|
|
293
|
+
export function removeUserSkill(skillsDir, pkgSkillsDir, name) {
|
|
294
|
+
const folder = storeName(name);
|
|
295
|
+
if (coreSkillNames(pkgSkillsDir).has(folder))
|
|
296
|
+
return { error: 'built-in skills cannot be removed' };
|
|
297
|
+
const dir = join(skillsDir, folder);
|
|
298
|
+
if (!folder || !existsSync(dir))
|
|
299
|
+
return { error: 'skill not found' };
|
|
300
|
+
rmSync(dir, { recursive: true, force: true });
|
|
301
|
+
return { ok: true };
|
|
302
|
+
}
|
package/dist/claude-llm.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { llm, type APIConnectOptions } from '@livekit/agents';
|
|
10
10
|
import { query, type Options, type McpServerConfig } from '@anthropic-ai/claude-agent-sdk';
|
|
11
11
|
import { EventEmitter } from 'events';
|
|
12
|
+
import { type Role } from './agent-store.js';
|
|
12
13
|
export interface ClaudeLLMOptions {
|
|
13
14
|
workingDirectory?: string;
|
|
14
15
|
sessionBaseDir?: string;
|
|
@@ -43,6 +44,8 @@ export interface ClaudeLLMOptions {
|
|
|
43
44
|
tools?: string[];
|
|
44
45
|
model?: string;
|
|
45
46
|
}>;
|
|
47
|
+
/** Role of each non-core agent (agent-store.ts); core agents fall back to their own. */
|
|
48
|
+
agentRoles?: Record<string, Role>;
|
|
46
49
|
/** Test seam: replaces the SDK `query()` for the persistent session (cold start
|
|
47
50
|
* + primeResume). Production never sets it. */
|
|
48
51
|
queryFn?: typeof query;
|
|
@@ -130,21 +133,17 @@ export declare function applyTurbo(agents: Record<string, any>, turbo: boolean):
|
|
|
130
133
|
*/
|
|
131
134
|
export declare function applyGrounding(agents: Record<string, any>, sessionId: string | null, workingDir: string | undefined): Record<string, any>;
|
|
132
135
|
/**
|
|
133
|
-
* Decide a Write/Edit/MultiEdit for the acting agent (null = main
|
|
134
|
-
*
|
|
136
|
+
* Decide a Write/Edit/MultiEdit for the acting agent's role (null = main
|
|
137
|
+
* orchestrator or an unknown agent). Returns:
|
|
135
138
|
* 'allow' → fall through (→ canUseTool workspace auto-approve, or {}).
|
|
136
139
|
* 'defer' → PreToolUse 'ask' (canUseTool decides).
|
|
137
140
|
* 'deny' → hard block with reason.
|
|
138
141
|
*/
|
|
139
|
-
export declare function decideWrite(
|
|
142
|
+
export declare function decideWrite(role: Role | null, filePath: string): {
|
|
140
143
|
decision: 'allow' | 'defer' | 'deny';
|
|
141
144
|
reason?: string;
|
|
142
145
|
};
|
|
143
146
|
export declare const SILENT_VERIFY_PREFIX: string;
|
|
144
|
-
export declare const VERIFIER_CHAIN: Record<string, {
|
|
145
|
-
parallelAtStart?: string[];
|
|
146
|
-
afterReminder?: string;
|
|
147
|
-
}>;
|
|
148
147
|
export declare class ClaudeLLM extends llm.LLM {
|
|
149
148
|
#private;
|
|
150
149
|
/** True when the live subprocess predates the latest auth-backend change. */
|
|
@@ -204,7 +203,7 @@ export declare class ClaudeLLM extends llm.LLM {
|
|
|
204
203
|
* start (session start/resume/switch) — a live subprocess keeps the agents
|
|
205
204
|
* it was created with.
|
|
206
205
|
*/
|
|
207
|
-
setAgents(agents: ClaudeLLMOptions['agents']): void;
|
|
206
|
+
setAgents(agents: ClaudeLLMOptions['agents'], roles?: Record<string, Role>): void;
|
|
208
207
|
/**
|
|
209
208
|
* Enable/disable Turbo mode. When on, the main model and every sub-agent
|
|
210
209
|
* spawn on FAST_MODEL. Takes effect at the next query cold start.
|