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
@@ -18,25 +18,231 @@ export const TREE_COMMAND = `I=$(mktemp -u) && { GIT_INDEX_FILE=$I git read-tree
18
18
  // Run in the repo root after a CLEAN or REFACTORED verdict.
19
19
  export const SIGNOFF_COMMAND = `T=$(sh -c '${TREE_COMMAND}') && echo "$T" > "$(git rev-parse --git-dir)/${MARKER_FILE}"`;
20
20
  export function stewardMode(env = process.env) {
21
- const m = (env.OSBORN_STEWARD_MODE || 'advise').toLowerCase();
22
- return m === 'block' || m === 'off' ? m : 'advise';
21
+ const m = (env.OSBORN_STEWARD_MODE || 'block').toLowerCase();
22
+ return m === 'advise' || m === 'off' ? m : 'block';
23
23
  }
24
- // Only a command in command position counts: not `grep "git push"` or `echo "... git commit"`.
25
- const AT = String.raw `(?:^|[;&|(\n]\s*)`;
26
- const GIT_OPTS = String.raw `(?:\s+-[Cc]\s+\S+)*`;
27
- /** The git action a shell command performs, and the directory it runs in (a leading `cd X &&` or `git -C X`). */
28
- export function gitAction(cmd, cwd) {
29
- const action = new RegExp(`${AT}gh\\s+pr\\s+create\\b`).test(cmd) ? 'pr'
30
- : new RegExp(`${AT}git${GIT_OPTS}\\s+push\\b`).test(cmd) ? 'push'
31
- : new RegExp(`${AT}git${GIT_OPTS}\\s+commit\\b`).test(cmd) ? 'commit'
32
- : null;
33
- if (!action)
34
- return null;
35
- const cd = cmd.match(/^\s*cd\s+("[^"]+"|'[^']+'|\S+)\s*&&/);
36
- const gitC = cmd.match(/\bgit\s+-C\s+("[^"]+"|'[^']+'|\S+)/);
37
- const raw = (gitC?.[1] ?? cd?.[1])?.replace(/^["']|["']$/g, '');
38
- const dir = raw ? (isAbsolute(raw) ? raw : resolve(cwd, raw.replace(/^~(?=\/|$)/, process.env.HOME || '~'))) : cwd;
39
- return { action, dir };
24
+ // Words that can precede a command: keywords, wrappers, and wrappers' options.
25
+ const PREFIX = new Set(['sudo', 'command', 'exec', 'env', 'nohup', 'time', 'builtin', 'nice', 'xargs', 'timeout', 'setsid', 'stdbuf', 'doas', 'ionice',
26
+ 'then', 'do', 'else', 'elif', 'if', 'while', 'until', '!', '{', '}']);
27
+ // Options that take a value, per wrapper.
28
+ const TAKES_ARG = {
29
+ sudo: new Set(['-u', '-g', '-h', '-p', '-U', '-C', '-D', '-r', '-t', '-T']),
30
+ timeout: new Set(['-s', '-k', '--signal', '--kill-after']),
31
+ nice: new Set(['-n', '--adjustment']),
32
+ xargs: new Set(['-a', '-d', '-E', '-I', '-L', '-n', '-P', '-s', '--arg-file', '--delimiter', '--eof', '--max-lines', '--max-procs', '--max-args', '--max-chars']),
33
+ time: new Set(['-f', '-o', '--format', '--output']),
34
+ env: new Set(['-u', '--unset', '-C', '--chdir', '-S', '--split-string']),
35
+ exec: new Set(['-a']),
36
+ stdbuf: new Set(['-i', '-o', '-e']),
37
+ doas: new Set(['-u', '-C']),
38
+ ionice: new Set(['-c', '-n', '-p', '-P', '-u', '--class', '--classdata']),
39
+ };
40
+ const SHELLS = new Set(['sh', 'bash', 'zsh', 'dash']);
41
+ export function gitActions(cmd, cwd) {
42
+ return scan(cmd, cwd).hits;
43
+ }
44
+ /** gitActions' worker: also returns the directory the shell is left in, so a
45
+ * `cd` inside `eval`'s argument carries over to the commands after it. */
46
+ function scan(cmd, cwd) {
47
+ const hits = [];
48
+ const home = process.env.HOME || '~';
49
+ const resolveDir = (base, raw) => {
50
+ if (raw === undefined)
51
+ return home; // bare `cd`
52
+ if (raw === '')
53
+ return base; // `cd ""` leaves the shell where it is
54
+ // `-` is $OLDPWD, and a variable or command substitution is expanded by the
55
+ // shell, not here — resolving one literally would invent `<cwd>/$HOME/x`.
56
+ if (raw === '-' || /[$`]/.test(raw))
57
+ return null;
58
+ const p = raw.replace(/^~(?=\/|$)/, home);
59
+ if (isAbsolute(p))
60
+ return p;
61
+ return base === null ? null : resolve(base, p);
62
+ };
63
+ let dir = cwd;
64
+ let segDir = cwd; // dir at the start of the current simple command, for subshell revert
65
+ const stack = [];
66
+ let words = [], word = '', inWord = false, quote = null, inBacktick = false;
67
+ const endWord = () => { if (inWord)
68
+ words.push(word); word = ''; inWord = false; };
69
+ const endCommand = () => {
70
+ endWord();
71
+ let w = words;
72
+ words = [];
73
+ let wrapper = '';
74
+ while (w.length) {
75
+ if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(w[0]))
76
+ w = w.slice(1);
77
+ else if (PREFIX.has(w[0])) {
78
+ wrapper = w[0];
79
+ w = w.slice(1);
80
+ }
81
+ else if (wrapper === 'env' && /^(-S|--split-string)/.test(w[0])) { // env -S runs its string as a command
82
+ const rest = w[0].includes('=') ? [w[0].split('=').slice(1).join('='), ...w.slice(1)] : w[0].length > 2 && w[0].startsWith('-S') ? [w[0].slice(2), ...w.slice(1)] : w.slice(1);
83
+ hits.push(...scan(rest.join(' '), dir).hits); // env execs: a cd inside cannot outlive it
84
+ return;
85
+ }
86
+ else if (wrapper && w[0].startsWith('-'))
87
+ w = w.slice(!w[0].includes('=') && TAKES_ARG[wrapper]?.has(w[0]) ? 2 : 1);
88
+ else if (wrapper === 'timeout' && /^\d+(\.\d+)?[smhd]?$/.test(w[0]))
89
+ w = w.slice(1); // timeout's duration
90
+ else
91
+ break;
92
+ }
93
+ if (!w.length)
94
+ return;
95
+ // eval runs its arguments as a command in THIS shell, so a `cd` among them
96
+ // persists — whether it arrived bare (`eval cd sub`) or quoted (`eval 'cd sub'`).
97
+ if (w[0] === 'eval') {
98
+ const sub = scan(w.slice(1).join(' '), dir);
99
+ hits.push(...sub.hits);
100
+ dir = sub.dir ?? dir; // an unknowable cd inside eval must not blank what follows
101
+ return;
102
+ }
103
+ const name = w[0].split('/').pop();
104
+ // `cd` takes options before the operand, so the operand is not always w[1]:
105
+ // `cd -- sub` used to be read as a directory literally named "--".
106
+ // (`pushd` is deliberately NOT tracked: without modelling `popd` too, a
107
+ // `pushd sub; popd` pair would leave the tracked dir in sub, which is more
108
+ // wrong than not following it at all.)
109
+ if (name === 'cd') {
110
+ // Skip options (-L -P -e -@, zsh's -q -s, ...) to reach the operand; `--`
111
+ // ends them. `-` alone is not an option, it is $OLDPWD.
112
+ let j = 1;
113
+ while (j < w.length && w[j].startsWith('-') && w[j] !== '-')
114
+ if (w[j++] === '--')
115
+ break;
116
+ dir = resolveDir(dir, w[j]);
117
+ return;
118
+ }
119
+ // A shell's -c can carry other flags with it (`sh -ec`, `bash -lc`,
120
+ // `bash -o pipefail -c`); its command runs in a subshell, so no cd escapes.
121
+ if (SHELLS.has(name)) {
122
+ for (let i = 1; i < w.length; i++) {
123
+ if (w[i] === '-o' || w[i] === '+o') {
124
+ i++;
125
+ continue;
126
+ }
127
+ if (/^-[a-zA-Z]*c$/.test(w[i])) {
128
+ const arg = w[i + 1] === '--' ? w[i + 2] : w[i + 1];
129
+ if (arg)
130
+ hits.push(...scan(arg, dir).hits);
131
+ return;
132
+ }
133
+ if (!w[i].startsWith('-'))
134
+ return;
135
+ }
136
+ return;
137
+ }
138
+ if (name === 'gh') {
139
+ const rest = w.slice(1).filter((x, j, a) => !x.startsWith('-') && !['--repo', '-R', '--hostname'].includes(a[j - 1]));
140
+ if (rest[0] === 'pr' && rest[1] === 'create')
141
+ hits.push({ action: 'pr', dir });
142
+ return;
143
+ }
144
+ if (name !== 'git')
145
+ return;
146
+ let gdir = dir, i = 1;
147
+ while (i < w.length && w[i].startsWith('-')) {
148
+ if (w[i] === '-C') {
149
+ gdir = resolveDir(gdir, w[i + 1]);
150
+ i += 2;
151
+ }
152
+ else if (w[i] === '-c' || w[i] === '--git-dir' || w[i] === '--work-tree' || w[i] === '--namespace')
153
+ i += 2;
154
+ else
155
+ i += 1;
156
+ }
157
+ if (w[i] === 'commit' || w[i] === 'push')
158
+ hits.push({ action: w[i], dir: gdir });
159
+ };
160
+ for (let k = 0; k < cmd.length; k++) {
161
+ const c = cmd[k];
162
+ // Heredoc: its body is data, not commands. Skip to the line holding only the delimiter.
163
+ if (!quote && c === '<' && cmd[k + 1] === '<' && cmd[k + 2] !== '<') {
164
+ const m = cmd.slice(k).match(/^<<-?\s*(['"]?)([A-Za-z0-9_]+)\1/);
165
+ if (m) {
166
+ const nl = cmd.indexOf('\n', k);
167
+ const head = nl < 0 ? cmd.slice(k + m[0].length) : cmd.slice(k + m[0].length, nl);
168
+ const close = nl < 0 ? -1 : cmd.slice(nl + 1).search(new RegExp(`^\\s*${m[2]}\\s*$`, 'm'));
169
+ cmd = cmd.slice(0, k) + head + '\n' + (close < 0 ? '' : cmd.slice(nl + 1 + close).replace(/^[^\n]*\n?/, ''));
170
+ k -= 1;
171
+ continue;
172
+ }
173
+ }
174
+ if (quote) {
175
+ if (c === quote)
176
+ quote = null;
177
+ else if (c === '\\' && quote === '"')
178
+ word += cmd[++k] ?? '';
179
+ else
180
+ word += c;
181
+ continue;
182
+ }
183
+ if (c === '"' || c === "'") {
184
+ quote = c;
185
+ inWord = true;
186
+ continue;
187
+ }
188
+ if (c === '\\') {
189
+ word += cmd[++k] ?? '';
190
+ inWord = true;
191
+ continue;
192
+ }
193
+ if (c === ';' || c === '\n') {
194
+ endCommand();
195
+ segDir = dir;
196
+ continue;
197
+ }
198
+ // `&&` / `||` continue in this shell; a bare `|` (pipeline element) or `&`
199
+ // (background job) runs its command in a SUBSHELL, so its `cd` dies with it.
200
+ if (c === '&' || c === '|') {
201
+ // Not a separator at all inside a redirection: `>&2`, `2>&1`, `&>log`.
202
+ if (c === '&' && (word.endsWith('>') || cmd[k + 1] === '>')) {
203
+ word += c;
204
+ inWord = true;
205
+ continue;
206
+ }
207
+ const chained = cmd[k + 1] === c;
208
+ endCommand();
209
+ if (chained)
210
+ k++;
211
+ else
212
+ dir = segDir;
213
+ segDir = dir;
214
+ continue;
215
+ }
216
+ // A substitution splits the token stream here, so the word it belongs to is
217
+ // only half-read. Feed it a `$` so resolveDir reads it as unresolvable —
218
+ // otherwise `cd `pwd`` ends a BARE `cd` and resolves it to $HOME, and
219
+ // `cd `echo child`` would check the parent repo's marker for a child commit.
220
+ if (c === '(' || (c === '`' && !inBacktick)) {
221
+ word += '$';
222
+ inWord = true;
223
+ endCommand();
224
+ stack.push(dir);
225
+ if (c === '`')
226
+ inBacktick = true;
227
+ continue;
228
+ }
229
+ if (c === ')' || c === '`') {
230
+ endCommand();
231
+ dir = stack.pop() ?? dir;
232
+ segDir = dir;
233
+ if (c === '`')
234
+ inBacktick = false;
235
+ continue;
236
+ }
237
+ if (c === ' ' || c === '\t') {
238
+ endWord();
239
+ continue;
240
+ }
241
+ word += c;
242
+ inWord = true;
243
+ }
244
+ endCommand();
245
+ return { hits, dir };
40
246
  }
41
247
  const git = async (dir, args) => (await run('git', args, { cwd: dir })).stdout.trim();
42
248
  const workingTree = async (dir) => (await run('sh', ['-c', TREE_COMMAND], { cwd: dir })).stdout.trim();
@@ -52,24 +258,42 @@ async function signedFor(dir, action, marker) {
52
258
  const trackedClean = await run('git', ['diff', '--quiet', 'HEAD'], { cwd: dir }).then(() => true, () => false);
53
259
  return trackedClean && (await workingTree(dir)) === marker;
54
260
  }
55
- /** Check a Bash command against the steward sign-off. Never throws: an unreadable repo is allowed. */
261
+ /** Check a Bash command against the steward sign-off: every git action in it, most restrictive wins. */
56
262
  export async function stewardGate(cmd, cwd, mode = stewardMode()) {
57
263
  if (mode === 'off')
58
264
  return { decision: 'allow' };
59
- const hit = gitAction(cmd, cwd);
60
- if (!hit || !existsSync(hit.dir))
61
- return { decision: 'allow' };
62
- try {
63
- const markerPath = join(await git(hit.dir, ['rev-parse', '--absolute-git-dir']), MARKER_FILE);
64
- const marker = existsSync(markerPath) ? (await readFile(markerPath, 'utf8')).trim() : '';
65
- if (marker && await signedFor(hit.dir, hit.action, marker))
66
- return { decision: 'allow' };
265
+ let unsigned = null, failed = null;
266
+ for (const hit of gitActions(cmd, cwd)) {
267
+ // An unknown directory (`cd $VAR`, `cd -`) or one the command has not created
268
+ // yet is skipped, as before: there is no repo to read, and nothing the agent
269
+ // could do about a complaint. `git worktree add w && cd w && git commit` is
270
+ // the ordinary case, not an evasion.
271
+ if (hit.dir === null || !existsSync(hit.dir))
272
+ continue;
273
+ let gitDir;
274
+ try {
275
+ gitDir = await git(hit.dir, ['rev-parse', '--absolute-git-dir']);
276
+ }
277
+ catch {
278
+ continue;
279
+ } // not a repo
280
+ try {
281
+ const markerPath = join(gitDir, MARKER_FILE);
282
+ const marker = existsSync(markerPath) ? (await readFile(markerPath, 'utf8')).trim() : '';
283
+ if (!marker || !await signedFor(hit.dir, hit.action, marker)) {
284
+ unsigned = unsigned ?? hit.action;
285
+ }
286
+ }
287
+ catch (e) {
288
+ failed = e.message.split('\n')[0].slice(0, 160);
289
+ console.log(`[steward-gate] could not check ${hit.action} in ${hit.dir}: ${failed}`);
290
+ }
67
291
  }
68
- catch {
292
+ if (!unsigned && !failed)
69
293
  return { decision: 'allow' };
70
- }
71
- const what = hit.action === 'pr' ? 'opening this PR' : `this ${hit.action}`;
72
- const message = `The steward has not signed off on the code in ${what}: run the \`steward\` agent on the change first ` +
73
- `(it records its sign-off for this exact content; any later edit needs a new sign-off).`;
294
+ const message = unsigned
295
+ ? `The steward has not signed off on the code in ${unsigned === 'pr' ? 'opening this PR' : `this ${unsigned}`}: run the \`steward\` agent on the change first ` +
296
+ `(it records its sign-off for this exact content; any later edit needs a new sign-off).`
297
+ : `The steward sign-off could not be checked (${failed}).`;
74
298
  return mode === 'block' ? { decision: 'deny', message } : { decision: 'advise', message };
75
299
  }
@@ -0,0 +1,23 @@
1
+ export type StewardVerdictKind = 'CLEAN' | 'REFACTORED' | 'BLOCK';
2
+ export interface StewardVerdict {
3
+ verdict: StewardVerdictKind;
4
+ summary: string;
5
+ /** BLOCK only: the decision a human has to make. */
6
+ decision?: string;
7
+ rootCause?: string;
8
+ netNew: string[];
9
+ removed: string[];
10
+ lines?: string;
11
+ history: string[];
12
+ /** The full return, so the card can show the whole record. */
13
+ raw: string;
14
+ /** ISO time the steward returned. */
15
+ at: string;
16
+ }
17
+ /** Parse a steward return. Null when the text carries no VERDICT line. */
18
+ export declare function parseStewardVerdict(text: string, at?: string): StewardVerdict | null;
19
+ /** Sidecar path: next to session.db and compactions.jsonl. */
20
+ export declare function getStewardLogPath(sessionId: string, workingDir: string): string;
21
+ export declare function appendStewardVerdict(sessionId: string, workingDir: string, v: StewardVerdict): void;
22
+ /** Every recorded verdict for a session, file order. Missing file or torn lines are skipped. */
23
+ export declare function readStewardVerdicts(sessionId: string, workingDir: string): StewardVerdict[];
@@ -0,0 +1,97 @@
1
+ // Steward verdict card (#221, #224): the steward's return text (agent/src/prompts/steward.md,
2
+ // "What to return") parsed into the fields the chat card shows, and kept in a sidecar next to
3
+ // compactions.jsonl so a reload rebuilds the card where it happened.
4
+ import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'fs';
5
+ import { dirname, join } from 'path';
6
+ import { getStorePath } from './session-store.js';
7
+ const LABELS = {
8
+ 'VERDICT': 'verdict', 'REUSE MAP': 'reuse', 'INVENTORY': 'reuse', 'DUPLICATES': 'reuse', 'BEHAVIOUR': 'regressions', 'NET-NEW': 'netNew', 'REMOVED': 'removed',
9
+ 'REGRESSION MAP': 'regressions', 'IMPACT': 'regressions', 'LINES': 'lines', 'HISTORY': 'history', 'ROOT CAUSE': 'rootCause',
10
+ 'DECISION': 'decision', 'HUMAN DECISION': 'decision', 'DECISION NEEDED': 'decision',
11
+ };
12
+ // A label line, tolerant of markdown: "- **VERDICT:** ...", "## HISTORY", "ROOT CAUSE — ...".
13
+ const LABEL_RE = new RegExp(`^[\\s>#*_\\-•]*(${Object.keys(LABELS).sort((a, b) => b.length - a.length).join('|')})[*_\\s]*(?::|—|–|$)[*_\\s]*(.*)$`, 'i');
14
+ const strip = (s) => s.replace(/^[\s>*_\-•]+|[\s*_]+$/g, '').replace(/\*\*/g, '').trim();
15
+ const isNone = (s) => /^(none|n\/a|nothing)\b\.?$/i.test(s);
16
+ /** Parse a steward return. Null when the text carries no VERDICT line. */
17
+ export function parseStewardVerdict(text, at = new Date().toISOString()) {
18
+ const sections = {};
19
+ const loose = [];
20
+ let current = null;
21
+ for (const line of String(text ?? '').split('\n')) {
22
+ const m = line.match(LABEL_RE);
23
+ if (m) {
24
+ current = LABELS[m[1].toUpperCase().replace(/\s+/g, ' ')];
25
+ (sections[current] ??= []);
26
+ const rest = strip(m[2]);
27
+ if (rest)
28
+ sections[current].push(rest);
29
+ continue;
30
+ }
31
+ const s = strip(line);
32
+ if (!s)
33
+ continue;
34
+ if (current)
35
+ sections[current].push(s);
36
+ else
37
+ loose.push(s);
38
+ }
39
+ const head = (sections.verdict ?? []).join(' ');
40
+ const vm = head.match(/^(CLEAN|REFACTORED|BLOCK)\b[\s—–:\-|]*(.*)$/i);
41
+ if (!vm)
42
+ return null;
43
+ const verdict = vm[1].toUpperCase();
44
+ // Every line is an entry; a single line holding several is split on ";".
45
+ const entries = (k) => {
46
+ const ls = sections[k] ?? [];
47
+ const out = (ls.length === 1 ? ls[0].split(/;\s+/) : ls).map(strip).filter(Boolean);
48
+ // Bounded, so a long return cannot overflow the data-channel packet on reload.
49
+ return out.length === 1 && isNone(out[0]) ? [] : out.slice(0, 20).map((e) => e.slice(0, 300));
50
+ };
51
+ // REUSE MAP and IMPACT stay in `raw` only; a NET-NEW entry inside the reuse map is lifted out.
52
+ const netNew = entries('netNew');
53
+ for (const e of entries('reuse')) {
54
+ if (/NET-NEW/i.test(e))
55
+ netNew.push(e.replace(/\s*(?:→|->|\|)?\s*NET-NEW\s*:?\s*/i, ' — ').replace(/^ — /, ''));
56
+ }
57
+ const joined = (k) => (sections[k] ?? []).join(' ').trim() || undefined;
58
+ // "For BLOCK, name the decision": a labelled DECISION line, else the free text that follows.
59
+ const decision = verdict === 'BLOCK' ? joined('decision') ?? (loose.join(' ') || undefined) : undefined;
60
+ return {
61
+ verdict,
62
+ summary: strip(vm[2]),
63
+ ...(decision ? { decision } : {}),
64
+ ...(joined('rootCause') ? { rootCause: joined('rootCause') } : {}),
65
+ netNew,
66
+ removed: entries('removed'),
67
+ ...(joined('lines') ? { lines: joined('lines') } : {}),
68
+ history: entries('history'),
69
+ raw: String(text).trim().slice(0, 6000),
70
+ at,
71
+ };
72
+ }
73
+ /** Sidecar path: next to session.db and compactions.jsonl. */
74
+ export function getStewardLogPath(sessionId, workingDir) {
75
+ return join(dirname(getStorePath(sessionId, workingDir)), 'steward.jsonl');
76
+ }
77
+ export function appendStewardVerdict(sessionId, workingDir, v) {
78
+ const p = getStewardLogPath(sessionId, workingDir);
79
+ mkdirSync(dirname(p), { recursive: true });
80
+ appendFileSync(p, JSON.stringify(v) + '\n', 'utf-8');
81
+ }
82
+ /** Every recorded verdict for a session, file order. Missing file or torn lines are skipped. */
83
+ export function readStewardVerdicts(sessionId, workingDir) {
84
+ const p = getStewardLogPath(sessionId, workingDir);
85
+ if (!existsSync(p))
86
+ return [];
87
+ const out = [];
88
+ for (const line of readFileSync(p, 'utf-8').split('\n')) {
89
+ try {
90
+ const o = JSON.parse(line);
91
+ if (o && typeof o.verdict === 'string' && typeof o.at === 'string')
92
+ out.push(o);
93
+ }
94
+ catch { /* blank or torn line */ }
95
+ }
96
+ return out;
97
+ }
@@ -0,0 +1 @@
1
+ export declare const STOPWORDS: ReadonlySet<string>;
@@ -0,0 +1,6 @@
1
+ // English stopwords for term matching, shared by the content lens (transcripts) and the
2
+ // store catalog's recommendations. No imports, so either can use it without pulling the other in.
3
+ export const STOPWORDS = new Set(('the and for that this with you your are was were have has had not but just like what when then them they there ' +
4
+ 'their about from into would could should will can its so also well even still want need ' +
5
+ 'here more some only very much make made does did doing done been being which where while because since each ' +
6
+ 'other than over our out all any one two who how why way get got see say said now back').split(/\s+/));
@@ -0,0 +1,106 @@
1
+ import { type Role } from './agent-store.js';
2
+ type EntryKind = 'agent' | 'skill';
3
+ type Trust = 'anthropic' | 'community';
4
+ interface CatalogSource {
5
+ id: string;
6
+ label: string;
7
+ repo: string;
8
+ trust: Trust;
9
+ /** Path patterns: group 1 is the plugin (if any), the match is the entry. */
10
+ skill: RegExp;
11
+ agent?: RegExp;
12
+ }
13
+ export declare const SOURCES: CatalogSource[];
14
+ export interface CatalogEntry {
15
+ id: string;
16
+ source: string;
17
+ kind: EntryKind;
18
+ name: string;
19
+ description: string;
20
+ tools: string[];
21
+ model?: string;
22
+ files: string[];
23
+ repo: string;
24
+ path: string;
25
+ sha: string;
26
+ rev: string;
27
+ license: string;
28
+ /** Files that can run (scripts/ or a script extension), shown before install. */
29
+ scripts: string[];
30
+ trust: Trust;
31
+ plugin?: string;
32
+ category?: string;
33
+ }
34
+ export interface Snapshot {
35
+ sha: string;
36
+ paths: string[];
37
+ }
38
+ type Reader = (path: string) => Promise<string | null>;
39
+ /** Turns a repo snapshot into catalog entries (pure apart from `read`). Returns the bodies too. */
40
+ export declare function normaliseSource(src: CatalogSource, snap: Snapshot, read: Reader): Promise<{
41
+ entries: CatalogEntry[];
42
+ bodies: Record<string, string>;
43
+ failed: number;
44
+ tooLarge: number;
45
+ }>;
46
+ export declare class TooLarge extends Error {
47
+ }
48
+ interface SourceCache {
49
+ source: string;
50
+ repo: string;
51
+ sha: string;
52
+ fetchedAt: number;
53
+ entries: CatalogEntry[];
54
+ bodies: Record<string, string>;
55
+ error?: string;
56
+ note?: string;
57
+ }
58
+ export declare function loadCatalog(ids: string[] | null, opts?: {
59
+ refresh?: boolean;
60
+ dir?: string;
61
+ }): Promise<SourceCache[]>;
62
+ export declare function findEntry(id: string, opts?: {
63
+ dir?: string;
64
+ }): Promise<{
65
+ entry: CatalogEntry;
66
+ body: string;
67
+ } | null>;
68
+ export declare const PROVENANCE_FILE = ".store-provenance.json";
69
+ /** A file path inside a skill: relative, no '..', no hidden segments, no backslashes. */
70
+ export declare function safeRelPath(rel: string): boolean;
71
+ /** Copies a catalog skill into skillsDir/<name>/ at its pinned sha, with a provenance file. */
72
+ export declare function installSkill(entry: CatalogEntry, skillsDir: string, coreSkills: Set<string>, fetchFile?: (path: string) => Promise<Buffer | null>): Promise<{
73
+ ok: true;
74
+ name: string;
75
+ } | {
76
+ error: string;
77
+ }>;
78
+ export declare function skillProvenance(skillsDir: string, folder: string): {
79
+ source: string;
80
+ repo: string;
81
+ sha: string;
82
+ } | undefined;
83
+ /** A user_agents draft for a catalog agent; the frontend saves it. Its role starts from its tools (draftRole). */
84
+ export declare function agentDraft(entry: CatalogEntry, body: string): {
85
+ name: string;
86
+ description: string;
87
+ prompt: string;
88
+ model: string;
89
+ tools: string[];
90
+ role: Role;
91
+ forked_from: string;
92
+ };
93
+ /** Ids of the entries already installed: a skill by its folder, an agent by a row installed from the same file. */
94
+ export declare function installedIds(entries: CatalogEntry[], skillFolders: Set<string>, agentOrigins: string[]): Set<string>;
95
+ interface Signal {
96
+ text: string;
97
+ reason: string;
98
+ }
99
+ interface Recommendation {
100
+ id: string;
101
+ score: number;
102
+ reason: string;
103
+ }
104
+ /** Ranks entries against what the user does (installed skills, agents, recent session titles); installed ids are left out. */
105
+ export declare function recommend(entries: CatalogEntry[], signals: Signal[], installed: Set<string>, limit?: number): Recommendation[];
106
+ export {};