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.
Files changed (38) hide show
  1. package/dist/agent-store.d.ts +164 -0
  2. package/dist/agent-store.js +302 -0
  3. package/dist/claude-llm.d.ts +7 -8
  4. package/dist/claude-llm.js +75 -171
  5. package/dist/content/compaction-lens-worker.js +2 -1
  6. package/dist/content/content-run.js +9 -9
  7. package/dist/content/lens-clip-window.js +7 -6
  8. package/dist/content/lens-launch.d.ts +11 -0
  9. package/dist/content/lens-launch.js +11 -0
  10. package/dist/content/lens-library-select.d.ts +7 -5
  11. package/dist/content/lens-library-select.js +7 -6
  12. package/dist/content/lens-library.d.ts +7 -1
  13. package/dist/content/lens-library.js +29 -6
  14. package/dist/data-sender-auth.d.ts +3 -2
  15. package/dist/data-sender-auth.js +10 -3
  16. package/dist/index.js +376 -190
  17. package/dist/pipeline-direct-llm.d.ts +1 -1
  18. package/dist/pipeline-direct-llm.js +1 -1
  19. package/dist/prompts/chain-after-planner.md +1 -0
  20. package/dist/prompts/chain-after-researcher.md +1 -0
  21. package/dist/prompts/chain-after-writer.md +1 -0
  22. package/dist/prompts/direct-mode-research.md +2 -2
  23. package/dist/prompts/steward.md +131 -0
  24. package/dist/prompts.d.ts +6 -0
  25. package/dist/prompts.js +18 -1
  26. package/dist/pushover.d.ts +7 -0
  27. package/dist/pushover.js +45 -42
  28. package/dist/steward-gate.d.ts +6 -5
  29. package/dist/steward-gate.js +256 -32
  30. package/dist/steward-verdict.d.ts +23 -0
  31. package/dist/steward-verdict.js +97 -0
  32. package/dist/stopwords.d.ts +1 -0
  33. package/dist/stopwords.js +6 -0
  34. package/dist/store-catalog.d.ts +106 -0
  35. package/dist/store-catalog.js +356 -0
  36. package/dist/store-name.d.ts +1 -0
  37. package/dist/store-name.js +7 -0
  38. package/package.json +1 -1
@@ -0,0 +1,356 @@
1
+ // Store catalog: skills and named agents from trusted GitHub repos, read live
2
+ // through the agent (the frontend never calls GitHub), cached on disk for an
3
+ // hour, pinned at the commit they were read at. MCP servers, hooks, bin and
4
+ // monitors are out of scope: entries that need MCP are skipped.
5
+ import { execFile } from 'node:child_process';
6
+ import { createHash } from 'node:crypto';
7
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, rmSync, mkdtempSync } from 'node:fs';
8
+ import { homedir, tmpdir } from 'node:os';
9
+ import { dirname, join, resolve, sep, posix } from 'node:path';
10
+ import { promisify } from 'node:util';
11
+ import MiniSearch from 'minisearch';
12
+ import { STOPWORDS } from './stopwords.js';
13
+ import { storeName, draftRole, isAgentModel, parseFrontMatter, catalogOrigin, unpinnedOrigin, AGENT_LIMITS } from './agent-store.js';
14
+ const run = promisify(execFile);
15
+ export const SOURCES = [
16
+ { id: 'anthropic-skills', label: 'Anthropic skills', repo: 'anthropics/skills', trust: 'anthropic', skill: /^skills\/[^/]+\/SKILL\.md$/ },
17
+ {
18
+ id: 'anthropic-plugins', label: 'Anthropic plugins', repo: 'anthropics/claude-plugins-official', trust: 'anthropic',
19
+ skill: /^plugins\/([^/]+)\/skills\/[^/]+\/SKILL\.md$/, agent: /^plugins\/([^/]+)\/agents\/[^/]+\.md$/,
20
+ },
21
+ {
22
+ id: 'wshobson-agents', label: 'wshobson/agents', repo: 'wshobson/agents', trust: 'community',
23
+ skill: /^plugins\/([^/]+)\/skills\/[^/]+\/SKILL\.md$/, agent: /^plugins\/([^/]+)\/agents\/[^/]+\.md$/,
24
+ },
25
+ ];
26
+ // ── Parsing ──────────────────────────────────────────────────────────────────
27
+ const str = (v) => (Array.isArray(v) ? v.join(', ') : String(v ?? '')).trim();
28
+ const list = (v) => (Array.isArray(v) ? v : String(v ?? '').split(',')).map((t) => String(t).trim()).filter(Boolean);
29
+ const SCRIPT_EXT = /\.(py|sh|bash|zsh|js|mjs|cjs|ts|rb|pl|ps1|php)$/i;
30
+ const isHidden = (rel) => rel.split('/').some((s) => s.startsWith('.'));
31
+ function detectLicense(text) {
32
+ if (!text)
33
+ return undefined;
34
+ const head = text.slice(0, 600);
35
+ if (/MIT License/i.test(head))
36
+ return 'MIT';
37
+ if (/Apache License/i.test(head))
38
+ return 'Apache-2.0';
39
+ if (/BSD/i.test(head))
40
+ return 'BSD';
41
+ return 'See LICENSE';
42
+ }
43
+ async function mapLimit(items, n, fn) {
44
+ const out = new Array(items.length);
45
+ let i = 0;
46
+ await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => {
47
+ while (i < items.length) {
48
+ const k = i++;
49
+ out[k] = await fn(items[k]);
50
+ }
51
+ }));
52
+ return out;
53
+ }
54
+ /** Turns a repo snapshot into catalog entries (pure apart from `read`). Returns the bodies too. */
55
+ export async function normaliseSource(src, snap, read) {
56
+ let failed = 0, tooLarge = 0;
57
+ const paths = snap.paths;
58
+ const repoLicense = detectLicense(await read(paths.find((p) => /^LICEN[CS]E(\.md|\.txt)?$/i.test(p)) || 'LICENSE').catch(() => null));
59
+ const market = {};
60
+ try {
61
+ const mp = JSON.parse((await read('.claude-plugin/marketplace.json')) || '{}');
62
+ for (const p of Array.isArray(mp.plugins) ? mp.plugins : [])
63
+ if (p?.name)
64
+ market[String(p.name)] = { category: p.category ? String(p.category) : undefined };
65
+ }
66
+ catch { /* marketplace metadata is optional */ }
67
+ const hits = paths.flatMap((p) => {
68
+ const s = src.skill.exec(p);
69
+ if (s)
70
+ return [{ kind: "skill", file: p, plugin: s[1] }];
71
+ const a = src.agent?.exec(p);
72
+ return a ? [{ kind: "agent", file: p, plugin: a[1] }] : [];
73
+ });
74
+ const bodies = {};
75
+ const entries = (await mapLimit(hits, 8, async (h) => {
76
+ const md = await read(h.file).catch((e) => { if (e instanceof TooLarge)
77
+ tooLarge++;
78
+ else
79
+ failed++; return null; });
80
+ if (!md)
81
+ return null;
82
+ const { meta, body } = parseFrontMatter(md);
83
+ const dir = h.kind === 'skill' ? posix.dirname(h.file) : h.file;
84
+ const files = h.kind === 'skill'
85
+ ? paths.filter((p) => p.startsWith(dir + '/')).map((p) => p.slice(dir.length + 1)).filter((r) => !isHidden(r))
86
+ : [posix.basename(h.file)];
87
+ const tools = list(meta.tools ?? meta['allowed-tools']);
88
+ // Out of scope: anything that needs an MCP server.
89
+ if (tools.some((t) => /^mcp__/.test(t)) || paths.some((p) => p.startsWith(dir + '/') && posix.basename(p) === '.mcp.json'))
90
+ return null;
91
+ const name = storeName(str(meta.name) || (h.kind === 'skill' ? posix.basename(dir) : posix.basename(h.file, '.md')));
92
+ if (!name)
93
+ return null;
94
+ const ownLicense = str(meta.license);
95
+ const id = `${src.id}:${dir}`;
96
+ bodies[id] = h.kind === 'agent' ? body.trim() : md;
97
+ return {
98
+ id, source: src.id, kind: h.kind, name,
99
+ description: str(meta.description).slice(0, 600),
100
+ tools, ...(str(meta.model) ? { model: str(meta.model) } : {}),
101
+ files, repo: src.repo, path: dir, sha: snap.sha,
102
+ rev: createHash('sha256').update(md).update('\0' + files.join('\n')).digest('hex').slice(0, 16),
103
+ license: ownLicense ? (/LICENSE/i.test(ownLicense) ? 'See LICENSE.txt' : ownLicense.slice(0, 40)) : (files.some((f) => /^LICEN[CS]E/i.test(f)) ? 'See LICENSE.txt' : repoLicense || 'Unknown'),
104
+ scripts: files.filter((f) => f.startsWith('scripts/') || SCRIPT_EXT.test(f)),
105
+ trust: src.trust,
106
+ ...(h.plugin ? { plugin: h.plugin, ...(market[h.plugin]?.category ? { category: market[h.plugin].category } : {}) } : {}),
107
+ };
108
+ })).filter((e) => !!e);
109
+ return { entries, bodies, failed, tooLarge };
110
+ }
111
+ // ── Fetching ─────────────────────────────────────────────────────────────────
112
+ const GH_API = 'https://api.github.com';
113
+ const GH_RAW = 'https://raw.githubusercontent.com';
114
+ const ghHeaders = () => ({
115
+ 'User-Agent': 'osborn-store',
116
+ ...(process.env.GITHUB_TOKEN ? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } : {}),
117
+ });
118
+ async function snapshotViaApi(repo) {
119
+ const c = await fetch(`${GH_API}/repos/${repo}/commits/HEAD`, { headers: { ...ghHeaders(), Accept: 'application/vnd.github.sha' }, signal: AbortSignal.timeout(15000) });
120
+ if (!c.ok)
121
+ throw new Error(`commit lookup ${c.status}`);
122
+ const sha = (await c.text()).trim();
123
+ if (!/^[0-9a-f]{40}$/.test(sha))
124
+ throw new Error('bad commit sha');
125
+ const t = await fetch(`${GH_API}/repos/${repo}/git/trees/${sha}?recursive=1`, { headers: { ...ghHeaders(), Accept: 'application/vnd.github+json' }, signal: AbortSignal.timeout(20000) });
126
+ if (!t.ok)
127
+ throw new Error(`tree ${t.status}`);
128
+ const tree = await t.json();
129
+ if (tree.truncated)
130
+ throw new Error('tree listing truncated'); // a partial listing would cache as complete; git lists it all
131
+ return { sha, paths: (tree.tree || []).filter((n) => n.type === 'blob').map((n) => n.path) };
132
+ }
133
+ /** Fallback when the API is rate-limited or blocked: a blobless depth-1 clone, file names only. */
134
+ async function snapshotViaGit(repo) {
135
+ const d = mkdtempSync(join(tmpdir(), 'osborn-store-'));
136
+ try {
137
+ await run('git', ['clone', '-q', '--depth', '1', '--filter=blob:none', '--no-checkout', `https://github.com/${repo}`, d], { timeout: 60000 });
138
+ const sha = (await run('git', ['-C', d, 'rev-parse', 'HEAD'])).stdout.trim();
139
+ const ls = (await run('git', ['-C', d, 'ls-tree', '-r', '--name-only', 'HEAD'], { maxBuffer: 32 * 1024 * 1024 })).stdout;
140
+ return { sha, paths: ls.split('\n').filter(Boolean) };
141
+ }
142
+ finally {
143
+ rmSync(d, { recursive: true, force: true });
144
+ }
145
+ }
146
+ async function snapshot(repo) {
147
+ try {
148
+ return await snapshotViaApi(repo);
149
+ }
150
+ catch (e) {
151
+ console.log(`[store] ${repo}: API listing failed (${e instanceof Error ? e.message : e}); trying git`);
152
+ return snapshotViaGit(repo);
153
+ }
154
+ }
155
+ const MAX_FILE_BYTES = 2 * 1024 * 1024;
156
+ export class TooLarge extends Error {
157
+ }
158
+ async function rawBytes(repo, sha, path) {
159
+ const r = await fetch(`${GH_RAW}/${repo}/${sha}/${path.split('/').map(encodeURIComponent).join('/')}`, { signal: AbortSignal.timeout(20000) });
160
+ if (r.status === 404)
161
+ return null;
162
+ if (!r.ok)
163
+ throw new Error(`raw ${r.status}`); // rate limit / outage: a failure, not a missing file
164
+ const buf = Buffer.from(await r.arrayBuffer());
165
+ if (buf.length > MAX_FILE_BYTES)
166
+ throw new TooLarge(`${path} is larger than ${MAX_FILE_BYTES >> 20} MB`); // never read as a missing file
167
+ return buf;
168
+ }
169
+ const rawReader = (repo, sha) => async (p) => (await rawBytes(repo, sha, p))?.toString('utf-8') ?? null;
170
+ // ── Cache ────────────────────────────────────────────────────────────────────
171
+ const TTL_MS = 60 * 60 * 1000;
172
+ const cacheDir = () => join(homedir(), '.osborn', 'store-cache');
173
+ const inflight = new Map();
174
+ async function loadSource(src, opts = {}) {
175
+ const file = join(opts.dir || cacheDir(), `${src.id}.v3.json`); // v3: entries carry rev
176
+ let cached = null;
177
+ try {
178
+ cached = JSON.parse(readFileSync(file, 'utf-8'));
179
+ }
180
+ catch { /* none yet */ }
181
+ if (cached && !opts.refresh && Date.now() - cached.fetchedAt < TTL_MS)
182
+ return cached;
183
+ if (inflight.has(src.id))
184
+ return inflight.get(src.id);
185
+ const p = (async () => {
186
+ try {
187
+ const snap = await snapshot(src.repo);
188
+ const { entries, bodies, failed, tooLarge } = await normaliseSource(src, snap, rawReader(src.repo, snap.sha));
189
+ // Oversize entries are left out on purpose; the source says so rather than looking complete.
190
+ const fresh = { source: src.id, repo: src.repo, sha: snap.sha, fetchedAt: Date.now(), entries, bodies, ...(tooLarge ? { note: `${tooLarge} entr${tooLarge === 1 ? 'y is' : 'ies are'} over ${MAX_FILE_BYTES >> 20} MB and not listed` } : {}) };
191
+ // Some files could not be read: never cache a partial catalog over a good one.
192
+ if (failed) {
193
+ const error = `${failed} file(s) could not be read from GitHub`;
194
+ console.warn(`[store] ${src.id}: ${error}`);
195
+ return { ...(cached ?? fresh), error };
196
+ }
197
+ mkdirSync(dirname(file), { recursive: true });
198
+ writeFileSync(file + '.tmp', JSON.stringify(fresh));
199
+ renameSync(file + '.tmp', file);
200
+ return fresh;
201
+ }
202
+ catch (e) {
203
+ const error = e instanceof Error ? e.message : String(e);
204
+ console.warn(`[store] ${src.id}: ${error}`);
205
+ // A stale catalog beats none.
206
+ return cached ? { ...cached, error } : { source: src.id, repo: src.repo, sha: '', fetchedAt: 0, entries: [], bodies: {}, error };
207
+ }
208
+ finally {
209
+ inflight.delete(src.id);
210
+ }
211
+ })();
212
+ inflight.set(src.id, p);
213
+ return p;
214
+ }
215
+ export async function loadCatalog(ids, opts = {}) {
216
+ return Promise.all(SOURCES.filter((s) => !ids || ids.includes(s.id)).map((s) => loadSource(s, opts)));
217
+ }
218
+ export async function findEntry(id, opts = {}) {
219
+ const src = SOURCES.find((s) => id.startsWith(s.id + ':'));
220
+ if (!src)
221
+ return null;
222
+ const c = await loadSource(src, opts);
223
+ const entry = c.entries.find((e) => e.id === id);
224
+ return entry ? { entry, body: c.bodies[id] || '' } : null;
225
+ }
226
+ // ── Install ──────────────────────────────────────────────────────────────────
227
+ export const PROVENANCE_FILE = '.store-provenance.json';
228
+ const MAX_SKILL_BYTES = 10 * 1024 * 1024;
229
+ const MAX_SKILL_FILES = 300;
230
+ /** A file path inside a skill: relative, no '..', no hidden segments, no backslashes. */
231
+ export function safeRelPath(rel) {
232
+ if (!rel || rel.includes('\\') || rel.includes('\0') || posix.isAbsolute(rel))
233
+ return false;
234
+ const parts = rel.split('/');
235
+ return parts.every((p) => p && p !== '.' && p !== '..' && !p.startsWith('.'));
236
+ }
237
+ /** Copies a catalog skill into skillsDir/<name>/ at its pinned sha, with a provenance file. */
238
+ export async function installSkill(entry, skillsDir, coreSkills, fetchFile = (p) => rawBytes(entry.repo, entry.sha, p)) {
239
+ if (entry.kind !== 'skill')
240
+ return { error: 'not a skill' };
241
+ const name = storeName(entry.name);
242
+ if (!name)
243
+ return { error: 'invalid skill name' };
244
+ if (coreSkills.has(name))
245
+ return { error: `${name} is a built-in skill name — fork the built-in instead` };
246
+ const dst = join(skillsDir, name);
247
+ if (existsSync(dst))
248
+ return { error: `a skill named ${name} is already installed` };
249
+ if (!entry.files.includes('SKILL.md'))
250
+ return { error: 'skill has no SKILL.md' };
251
+ if (entry.files.length > MAX_SKILL_FILES)
252
+ return { error: `skill has too many files (${entry.files.length})` };
253
+ for (const f of entry.files) {
254
+ if (!safeRelPath(f) || !resolve(dst, f).startsWith(resolve(dst) + sep))
255
+ return { error: `refused unsafe path: ${f}` };
256
+ }
257
+ mkdirSync(skillsDir, { recursive: true });
258
+ const tmp = mkdtempSync(join(skillsDir, `.installing-${name}-`));
259
+ try {
260
+ let total = 0;
261
+ for (const f of entry.files) {
262
+ let buf;
263
+ try {
264
+ buf = await fetchFile(`${entry.path}/${f}`);
265
+ }
266
+ catch (e) {
267
+ if (e instanceof TooLarge)
268
+ return { error: e.message };
269
+ throw e;
270
+ }
271
+ if (!buf)
272
+ return { error: `could not fetch ${f}` };
273
+ total += buf.length;
274
+ if (total > MAX_SKILL_BYTES)
275
+ return { error: 'skill is larger than 10 MB' };
276
+ const out = join(tmp, f);
277
+ mkdirSync(dirname(out), { recursive: true });
278
+ writeFileSync(out, buf);
279
+ }
280
+ writeFileSync(join(tmp, PROVENANCE_FILE), JSON.stringify({
281
+ source: entry.source, repo: entry.repo, sha: entry.sha, path: entry.path, license: entry.license,
282
+ files: entry.files, scripts: entry.scripts, installedAt: new Date().toISOString(),
283
+ }, null, 2));
284
+ renameSync(tmp, dst);
285
+ return { ok: true, name };
286
+ }
287
+ finally {
288
+ rmSync(tmp, { recursive: true, force: true });
289
+ }
290
+ }
291
+ export function skillProvenance(skillsDir, folder) {
292
+ try {
293
+ const p = JSON.parse(readFileSync(join(skillsDir, folder, PROVENANCE_FILE), 'utf-8'));
294
+ return p?.source && p?.sha ? { source: String(p.source), repo: String(p.repo), sha: String(p.sha) } : undefined;
295
+ }
296
+ catch {
297
+ return undefined;
298
+ }
299
+ }
300
+ /** A user_agents draft for a catalog agent; the frontend saves it. Its role starts from its tools (draftRole). */
301
+ export function agentDraft(entry, body) {
302
+ const tools = entry.tools.filter((t) => !/^mcp__/.test(t));
303
+ const model = isAgentModel(entry.model) ? entry.model : 'inherit';
304
+ return {
305
+ name: storeName(entry.name).slice(0, AGENT_LIMITS.name),
306
+ description: (entry.description || entry.name).slice(0, AGENT_LIMITS.description),
307
+ prompt: body, // never cut: /store/install refuses one over AGENT_LIMITS.prompt
308
+ model, tools, role: draftRole(tools),
309
+ forked_from: catalogOrigin(entry),
310
+ };
311
+ }
312
+ /** Ids of the entries already installed: a skill by its folder, an agent by a row installed from the same file. */
313
+ export function installedIds(entries, skillFolders, agentOrigins) {
314
+ const origins = new Set(agentOrigins.map(unpinnedOrigin));
315
+ return new Set(entries.filter((e) => (e.kind === 'skill' ? skillFolders.has(e.name) : origins.has(unpinnedOrigin(catalogOrigin(e))))).map((e) => e.id));
316
+ }
317
+ // Stopwords: the shared English list plus words every catalog entry shares. The transcript
318
+ // fillers the content lens adds (work, time, look, good, thing…) stay searchable here: in a
319
+ // skill or agent description they name what it does ("time tracking", "look up").
320
+ const STOP = new Set([...STOPWORDS, 'use', 'agent', 'skill', 'skills', 'agents', 'using', 'used', 'user', 'users', 'help', 'let', 'please', 'new']);
321
+ const processTerm = (t) => { const w = t.toLowerCase(); return w.length < 3 || STOP.has(w) || /^\d+$/.test(w) ? null : w; };
322
+ /** Ranks entries against what the user does (installed skills, agents, recent session titles); installed ids are left out. */
323
+ export function recommend(entries, signals, installed, limit = 8) {
324
+ const pool = entries.filter((e) => !installed.has(e.id));
325
+ if (!pool.length || !signals.length)
326
+ return [];
327
+ const ms = new MiniSearch({
328
+ fields: ['name', 'description', 'plugin', 'category'],
329
+ storeFields: ['id'],
330
+ processTerm,
331
+ searchOptions: { boost: { name: 3, plugin: 2, category: 1.5 }, prefix: true, combineWith: 'OR' },
332
+ });
333
+ ms.addAll(pool);
334
+ const acc = new Map();
335
+ for (const s of signals) {
336
+ const hits = ms.search(s.text.replace(/[-_/]/g, ' ')).slice(0, 20);
337
+ const top = hits[0]?.score || 1;
338
+ for (const h of hits) {
339
+ const v = h.score / top; // each signal counts at most 1 per entry, so a long title cannot dominate
340
+ const a = acc.get(h.id) || { score: 0, best: 0, reason: '' };
341
+ a.score += v;
342
+ if (v > a.best) {
343
+ a.best = v;
344
+ a.reason = s.reason;
345
+ }
346
+ acc.set(h.id, a);
347
+ }
348
+ }
349
+ const nameOf = new Map(pool.map((e) => [e.id, e.name]));
350
+ const seen = new Set(); // the same agent ships in several plugins: show it once
351
+ return [...acc.entries()].map(([id, a]) => ({ id, score: Math.round(a.score * 100) / 100, reason: a.reason }))
352
+ .sort((x, y) => y.score - x.score || x.id.localeCompare(y.id))
353
+ .filter((r) => { const n = nameOf.get(r.id); if (seen.has(n))
354
+ return false; seen.add(n); return true; })
355
+ .slice(0, limit);
356
+ }
@@ -0,0 +1 @@
1
+ export declare const storeName: (raw: unknown) => string;
@@ -0,0 +1,7 @@
1
+ // The name a user agent or skill is stored under. Dependency-free so the frontend's
2
+ // copy (frontend/src/lib/agent-name.ts agentName) can be tested against it.
3
+ // A name with no letter or digit ('---') is no name: ''.
4
+ export const storeName = (raw) => {
5
+ const n = String(raw ?? '').trim().toLowerCase().replace(/[^a-z0-9-]/g, '-');
6
+ return /[a-z0-9]/.test(n) ? n : '';
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "osborn",
3
- "version": "0.9.280",
3
+ "version": "0.9.282",
4
4
  "description": "Voice AI coding assistant - local agent that connects to Osborn frontend",
5
5
  "type": "module",
6
6
  "bin": {