osborn 0.9.279 → 0.9.281
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 +162 -0
- package/dist/agent-store.js +300 -0
- package/dist/claude-llm.d.ts +13 -8
- package/dist/claude-llm.js +89 -73
- 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 +6 -3
- package/dist/index.js +241 -158
- package/dist/meeting-addressing.d.ts +1 -1
- package/dist/meeting-addressing.js +1 -0
- 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 +5 -4
- package/dist/prompts/steward.md +131 -0
- package/dist/prompts.d.ts +6 -0
- package/dist/prompts.js +20 -3
- package/dist/pushover.d.ts +2 -0
- package/dist/pushover.js +4 -2
- package/dist/steward-gate.d.ts +18 -0
- package/dist/steward-gate.js +299 -0
- 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 +101 -0
- package/dist/store-catalog.js +336 -0
- package/dist/store-name.d.ts +1 -0
- package/dist/store-name.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
// Steward sign-off gate (#218). The steward agent records the tree it approved;
|
|
2
|
+
// a commit, push or PR whose tree differs is reported (advise) or refused (block).
|
|
3
|
+
// The marker is a git TREE id, so it covers the content, not a commit sha that
|
|
4
|
+
// does not exist yet when the steward runs (it runs before the commit).
|
|
5
|
+
// Scope: the Osborn agent's own sessions. This repo's dev tooling has its own
|
|
6
|
+
// pre-PR gate (.claude/hooks/pre-pr-gate.py); the two do not share a marker.
|
|
7
|
+
import { execFile } from 'node:child_process';
|
|
8
|
+
import { existsSync } from 'node:fs';
|
|
9
|
+
import { readFile } from 'node:fs/promises';
|
|
10
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
11
|
+
import { promisify } from 'node:util';
|
|
12
|
+
const run = promisify(execFile);
|
|
13
|
+
export const MARKER_FILE = 'osborn-steward';
|
|
14
|
+
// Tree of the working tree (tracked + untracked, .gitignore respected), built in a
|
|
15
|
+
// throwaway index so the real index is left alone. Works in a repo with no commits.
|
|
16
|
+
export const TREE_COMMAND = `I=$(mktemp -u) && { GIT_INDEX_FILE=$I git read-tree HEAD 2>/dev/null || GIT_INDEX_FILE=$I git read-tree --empty; } && ` +
|
|
17
|
+
`GIT_INDEX_FILE=$I git add -A && GIT_INDEX_FILE=$I git write-tree; S=$?; rm -f "$I"; exit $S`;
|
|
18
|
+
// Run in the repo root after a CLEAN or REFACTORED verdict.
|
|
19
|
+
export const SIGNOFF_COMMAND = `T=$(sh -c '${TREE_COMMAND}') && echo "$T" > "$(git rev-parse --git-dir)/${MARKER_FILE}"`;
|
|
20
|
+
export function stewardMode(env = process.env) {
|
|
21
|
+
const m = (env.OSBORN_STEWARD_MODE || 'block').toLowerCase();
|
|
22
|
+
return m === 'advise' || m === 'off' ? m : 'block';
|
|
23
|
+
}
|
|
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 };
|
|
246
|
+
}
|
|
247
|
+
const git = async (dir, args) => (await run('git', args, { cwd: dir })).stdout.trim();
|
|
248
|
+
const workingTree = async (dir) => (await run('sh', ['-c', TREE_COMMAND], { cwd: dir })).stdout.trim();
|
|
249
|
+
/** Is the content this action ships the content the steward signed off? */
|
|
250
|
+
async function signedFor(dir, action, marker) {
|
|
251
|
+
// A commit ships the working tree (`git add -A && git commit` is checked before the add runs).
|
|
252
|
+
if (action === 'commit')
|
|
253
|
+
return (await workingTree(dir)) === marker;
|
|
254
|
+
// Push / PR ship HEAD: signed if HEAD is exactly the signed tree, or nothing tracked
|
|
255
|
+
// changed since and the working tree still matches (untracked leftovers allowed).
|
|
256
|
+
if ((await git(dir, ['rev-parse', 'HEAD^{tree}'])) === marker)
|
|
257
|
+
return true;
|
|
258
|
+
const trackedClean = await run('git', ['diff', '--quiet', 'HEAD'], { cwd: dir }).then(() => true, () => false);
|
|
259
|
+
return trackedClean && (await workingTree(dir)) === marker;
|
|
260
|
+
}
|
|
261
|
+
/** Check a Bash command against the steward sign-off: every git action in it, most restrictive wins. */
|
|
262
|
+
export async function stewardGate(cmd, cwd, mode = stewardMode()) {
|
|
263
|
+
if (mode === 'off')
|
|
264
|
+
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
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (!unsigned && !failed)
|
|
293
|
+
return { decision: 'allow' };
|
|
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}).`;
|
|
298
|
+
return mode === 'block' ? { decision: 'deny', message } : { decision: 'advise', message };
|
|
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,101 @@
|
|
|
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
|
+
license: string;
|
|
27
|
+
/** Files that can run (scripts/ or a script extension), shown before install. */
|
|
28
|
+
scripts: string[];
|
|
29
|
+
trust: Trust;
|
|
30
|
+
plugin?: string;
|
|
31
|
+
category?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Snapshot {
|
|
34
|
+
sha: string;
|
|
35
|
+
paths: string[];
|
|
36
|
+
}
|
|
37
|
+
type Reader = (path: string) => Promise<string | null>;
|
|
38
|
+
/** Turns a repo snapshot into catalog entries (pure apart from `read`). Returns the bodies too. */
|
|
39
|
+
export declare function normaliseSource(src: CatalogSource, snap: Snapshot, read: Reader): Promise<{
|
|
40
|
+
entries: CatalogEntry[];
|
|
41
|
+
bodies: Record<string, string>;
|
|
42
|
+
failed: number;
|
|
43
|
+
}>;
|
|
44
|
+
interface SourceCache {
|
|
45
|
+
source: string;
|
|
46
|
+
repo: string;
|
|
47
|
+
sha: string;
|
|
48
|
+
fetchedAt: number;
|
|
49
|
+
entries: CatalogEntry[];
|
|
50
|
+
bodies: Record<string, string>;
|
|
51
|
+
error?: string;
|
|
52
|
+
}
|
|
53
|
+
export declare function loadCatalog(ids: string[] | null, opts?: {
|
|
54
|
+
refresh?: boolean;
|
|
55
|
+
dir?: string;
|
|
56
|
+
}): Promise<SourceCache[]>;
|
|
57
|
+
export declare function findEntry(id: string, opts?: {
|
|
58
|
+
dir?: string;
|
|
59
|
+
}): Promise<{
|
|
60
|
+
entry: CatalogEntry;
|
|
61
|
+
body: string;
|
|
62
|
+
} | null>;
|
|
63
|
+
export declare const PROVENANCE_FILE = ".store-provenance.json";
|
|
64
|
+
/** A file path inside a skill: relative, no '..', no hidden segments, no backslashes. */
|
|
65
|
+
export declare function safeRelPath(rel: string): boolean;
|
|
66
|
+
/** Copies a catalog skill into skillsDir/<name>/ at its pinned sha, with a provenance file. */
|
|
67
|
+
export declare function installSkill(entry: CatalogEntry, skillsDir: string, coreSkills: Set<string>, fetchFile?: (path: string) => Promise<Buffer | null>): Promise<{
|
|
68
|
+
ok: true;
|
|
69
|
+
name: string;
|
|
70
|
+
} | {
|
|
71
|
+
error: string;
|
|
72
|
+
}>;
|
|
73
|
+
export declare function skillProvenance(skillsDir: string, folder: string): {
|
|
74
|
+
source: string;
|
|
75
|
+
repo: string;
|
|
76
|
+
sha: string;
|
|
77
|
+
} | undefined;
|
|
78
|
+
/** A user_agents draft for a catalog agent; the frontend saves it. Its role starts from its tools (draftRole). */
|
|
79
|
+
export declare function agentDraft(entry: CatalogEntry, body: string): {
|
|
80
|
+
name: string;
|
|
81
|
+
description: string;
|
|
82
|
+
prompt: string;
|
|
83
|
+
model: string;
|
|
84
|
+
tools: string[];
|
|
85
|
+
role: Role;
|
|
86
|
+
forked_from: string;
|
|
87
|
+
};
|
|
88
|
+
/** Ids of the entries already installed: a skill by its folder, an agent by a row installed from the same file. */
|
|
89
|
+
export declare function installedIds(entries: CatalogEntry[], skillFolders: Set<string>, agentOrigins: string[]): Set<string>;
|
|
90
|
+
interface Signal {
|
|
91
|
+
text: string;
|
|
92
|
+
reason: string;
|
|
93
|
+
}
|
|
94
|
+
interface Recommendation {
|
|
95
|
+
id: string;
|
|
96
|
+
score: number;
|
|
97
|
+
reason: string;
|
|
98
|
+
}
|
|
99
|
+
/** Ranks entries against what the user does (installed skills, agents, recent session titles); installed ids are left out. */
|
|
100
|
+
export declare function recommend(entries: CatalogEntry[], signals: Signal[], installed: Set<string>, limit?: number): Recommendation[];
|
|
101
|
+
export {};
|