osborn 0.9.214 → 0.9.215
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/claude-llm.js +90 -50
- package/package.json +1 -1
package/dist/claude-llm.js
CHANGED
|
@@ -15,7 +15,7 @@ import { getResearchSystemPrompt, getDirectModeResearchPrompt, getGroundingBlock
|
|
|
15
15
|
import { getIndexPath } from './summary-index.js';
|
|
16
16
|
import { openStore, recall, storeExists, updateSessionStore, getStorePath } from './session-store.js';
|
|
17
17
|
import { getEmbedder } from './embedder.js';
|
|
18
|
-
import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
18
|
+
import { existsSync, readdirSync, readFileSync, writeFileSync, mkdirSync, statSync } from 'node:fs';
|
|
19
19
|
import { join, dirname, resolve, basename } from 'node:path';
|
|
20
20
|
import { fileURLToPath } from 'node:url';
|
|
21
21
|
import { homedir } from 'node:os';
|
|
@@ -200,66 +200,105 @@ function loadAllSkills(_workingDir) {
|
|
|
200
200
|
return `<available-skills>\n${[...skillMap.values()].join('\n\n---\n\n')}\n</available-skills>`;
|
|
201
201
|
}
|
|
202
202
|
/**
|
|
203
|
-
* Enumerate the agent's CURRENT skills
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* (
|
|
208
|
-
*
|
|
203
|
+
* Enumerate the agent's CURRENT skills from ~/.claude/skills for injection into
|
|
204
|
+
* the PreCompact instruction — the material the compaction model reads so it
|
|
205
|
+
* refines/merges existing skills instead of re-emitting duplicates.
|
|
206
|
+
*
|
|
207
|
+
* Containment principle (why this is cheap AND complete):
|
|
208
|
+
* - SKILL.md is the canonical knowledge file and is small (~1–15KB each). We
|
|
209
|
+
* inject it IN FULL so the model sees every minute implementation detail and
|
|
210
|
+
* its UPDATE_SECTION edits are never blind. Bodies are emitted up to a total
|
|
211
|
+
* char budget; any overflow skill degrades to headings-only (still enough to
|
|
212
|
+
* dedup / target a section) so a pathological skill count can't blow the turn.
|
|
213
|
+
* - Satellite files in the folder (scripts/tools/reference docs) can be huge and
|
|
214
|
+
* unbounded, so we NEVER inject their contents — only a manifest line
|
|
215
|
+
* (name + size). The model can flag one for update; editing it is deferred to
|
|
216
|
+
* the user or a future tool-equipped merger that reads just that one file.
|
|
209
217
|
*/
|
|
218
|
+
// ~50K tokens of full SKILL.md text — ~5% of the 1M-context summarizer window, so
|
|
219
|
+
// completeness (the user's priority) wins over frugality. 16 defaults already use
|
|
220
|
+
// ~59KB, so a real user's defaults + learned + UI skills need real headroom here.
|
|
221
|
+
// NOTE: skills are walked alphabetically, so once the budget is hit the *late-alphabet*
|
|
222
|
+
// skills degrade to headings-only. A future refinement is to order by session-relevance
|
|
223
|
+
// (skills touched this session first) rather than name, so the overflow is the least
|
|
224
|
+
// relevant skills rather than an alphabetical accident.
|
|
225
|
+
const SKILL_BODY_BUDGET = 200_000;
|
|
226
|
+
function extractSkillDescription(raw) {
|
|
227
|
+
let desc = '';
|
|
228
|
+
const fm = raw.match(/^---\n([\s\S]*?)\n---/);
|
|
229
|
+
if (fm) {
|
|
230
|
+
const m = fm[1].match(/^description:\s*(.+)$/m);
|
|
231
|
+
if (m)
|
|
232
|
+
desc = m[1].trim();
|
|
233
|
+
}
|
|
234
|
+
const body = raw.replace(/^---\n[\s\S]*?\n---\n?/, '');
|
|
235
|
+
if (!desc) {
|
|
236
|
+
const when = body.match(/^\s*WHEN:\s*(.+)$/mi);
|
|
237
|
+
if (when)
|
|
238
|
+
desc = when[1].trim();
|
|
239
|
+
}
|
|
240
|
+
if (!desc) {
|
|
241
|
+
const first = body.split('\n').map(l => l.trim()).find(l => l && !l.startsWith('#'));
|
|
242
|
+
desc = first || '(no description)';
|
|
243
|
+
}
|
|
244
|
+
return desc.length > 200 ? desc.slice(0, 197) + '…' : desc;
|
|
245
|
+
}
|
|
210
246
|
function enumerateSkillsForCompaction() {
|
|
211
247
|
const dir = join(homedir(), '.claude', 'skills');
|
|
212
248
|
if (!existsSync(dir))
|
|
213
249
|
return '';
|
|
214
|
-
const
|
|
250
|
+
const blocks = [];
|
|
251
|
+
let budgetLeft = SKILL_BODY_BUDGET;
|
|
215
252
|
try {
|
|
216
253
|
for (const name of readdirSync(dir).sort()) {
|
|
217
|
-
const
|
|
254
|
+
const folder = join(dir, name);
|
|
255
|
+
const file = join(folder, 'SKILL.md');
|
|
218
256
|
if (!existsSync(file))
|
|
219
257
|
continue;
|
|
220
|
-
let desc = '';
|
|
221
258
|
try {
|
|
222
|
-
const raw = readFileSync(file, 'utf-8');
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
259
|
+
const raw = readFileSync(file, 'utf-8').trim();
|
|
260
|
+
const desc = extractSkillDescription(raw);
|
|
261
|
+
// Manifest of satellite files (name + size), contents NEVER injected.
|
|
262
|
+
let manifest = '';
|
|
263
|
+
try {
|
|
264
|
+
const others = readdirSync(folder)
|
|
265
|
+
.filter(f => f !== 'SKILL.md')
|
|
266
|
+
.map(f => {
|
|
267
|
+
try {
|
|
268
|
+
const st = statSync(join(folder, f));
|
|
269
|
+
const kb = st.isDirectory() ? '(dir)' : `${Math.max(1, Math.round(st.size / 1024))}KB`;
|
|
270
|
+
return `${f} ${kb}`;
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
return f;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
if (others.length)
|
|
277
|
+
manifest = `files (contents NOT shown — flag for update if needed): ${others.join(', ')}\n`;
|
|
228
278
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
279
|
+
catch { /* folder read race — skip manifest */ }
|
|
280
|
+
const header = `########## SKILL: ${name} ##########\ndescription: ${desc}\n${manifest}`;
|
|
281
|
+
if (raw.length <= budgetLeft) {
|
|
282
|
+
budgetLeft -= raw.length;
|
|
283
|
+
blocks.push(`${header}${raw}`);
|
|
234
284
|
}
|
|
235
|
-
|
|
285
|
+
else {
|
|
286
|
+
// Over budget → headings-only fallback (still enough to dedup + target a section).
|
|
236
287
|
const body = raw.replace(/^---\n[\s\S]*?\n---\n?/, '');
|
|
237
|
-
const
|
|
238
|
-
|
|
288
|
+
const headings = (body.match(/^#{2,6}\s+.+$/gm) || [])
|
|
289
|
+
.map(h => h.replace(/^#+\s+/, '').trim());
|
|
290
|
+
blocks.push(`${header}(full body omitted — over injection budget)\nsections: ${headings.join(' | ') || '(none)'}`);
|
|
239
291
|
}
|
|
240
|
-
// Option A: expose the skill's SECTION HEADINGS so the compaction model can
|
|
241
|
-
// target a specific section for a surgical update (via UPDATE_SECTION) rather
|
|
242
|
-
// than re-dumping a whole new skill. The summarizer has no tool access — this
|
|
243
|
-
// is the only way it can "see inside" the file.
|
|
244
|
-
const body = raw.replace(/^---\n[\s\S]*?\n---\n?/, '');
|
|
245
|
-
const headings = (body.match(/^#{2,3}\s+.+$/gm) || [])
|
|
246
|
-
.map(h => h.replace(/^#{2,3}\s+/, '').trim())
|
|
247
|
-
.filter(Boolean);
|
|
248
|
-
if (desc.length > 180)
|
|
249
|
-
desc = desc.slice(0, 177) + '…';
|
|
250
|
-
lines.push(`- ${name}: ${desc}`);
|
|
251
|
-
if (headings.length)
|
|
252
|
-
lines.push(` sections: ${headings.join(' | ')}`);
|
|
253
292
|
}
|
|
254
293
|
catch {
|
|
255
|
-
|
|
294
|
+
blocks.push(`########## SKILL: ${name} ##########\n(unreadable)`);
|
|
256
295
|
}
|
|
257
296
|
}
|
|
258
297
|
}
|
|
259
298
|
catch (err) {
|
|
260
299
|
console.warn('⚠️ enumerateSkillsForCompaction failed:', err instanceof Error ? err.message : err);
|
|
261
300
|
}
|
|
262
|
-
return
|
|
301
|
+
return blocks.join('\n\n');
|
|
263
302
|
}
|
|
264
303
|
// Compaction threshold: Fable 5 runs a 1M context window, so let sessions use
|
|
265
304
|
// all of it before auto-compacting. autoCompactWindow max is 1_000_000; the SDK
|
|
@@ -2174,24 +2213,25 @@ class ClaudeLLMStream extends llm.LLMStream {
|
|
|
2174
2213
|
// proliferated duplicates. We hand it the current skill set + an adversarial,
|
|
2175
2214
|
// self-critical directive to merge/refine rather than create anew.
|
|
2176
2215
|
const existingSkills = enumerateSkillsForCompaction();
|
|
2177
|
-
//
|
|
2216
|
+
// Each skill is delimited by a `########## SKILL: <name> ##########` header.
|
|
2178
2217
|
const skillCount = existingSkills
|
|
2179
|
-
? existingSkills.
|
|
2218
|
+
? (existingSkills.match(/^########## SKILL: /gm) || []).length
|
|
2180
2219
|
: 0;
|
|
2181
2220
|
const criticBlock = existingSkills
|
|
2182
|
-
? `\n\n---\n\n=== EXISTING SKILLS (${skillCount}) ===\n`
|
|
2183
|
-
+ `
|
|
2184
|
-
+
|
|
2185
|
-
+ `
|
|
2186
|
-
+ `
|
|
2221
|
+
? `\n\n---\n\n=== EXISTING SKILLS (${skillCount}) — FULL TEXT ===\n`
|
|
2222
|
+
+ `Below is the COMPLETE current text of each skill the user already has (delimited by `
|
|
2223
|
+
+ `\`########## SKILL: <name> ##########\`). A \`files:\` line lists any satellite files in the `
|
|
2224
|
+
+ `skill folder (scripts/tools/docs) whose CONTENTS are not shown — flag one only if it clearly needs updating.\n`
|
|
2225
|
+
+ `Read these before emitting SKILL_CANDIDATES or BEHAVIORAL_LEARNINGS, and act as an ADVERSARIAL reviewer of your own output:\n`
|
|
2226
|
+
+ `1. If what you learned refines ONE part of an existing skill, do NOT re-emit the whole skill. Emit a `
|
|
2187
2227
|
+ `surgical section update inside SKILL_CANDIDATES using this exact block form (the heading must match a `
|
|
2188
|
-
+
|
|
2228
|
+
+ `\`## \`/\`### \` heading that appears verbatim in that skill's text above):\n`
|
|
2189
2229
|
+ ` --- UPDATE_SECTION: <skill-name> > <exact section heading> ---\n`
|
|
2190
|
-
+ ` <the new markdown that should REPLACE that section's body>\n`
|
|
2230
|
+
+ ` <the new markdown that should REPLACE that section's body — preserve detail already present that is still correct>\n`
|
|
2191
2231
|
+ ` --- END UPDATE_SECTION ---\n`
|
|
2192
|
-
+ `2. If a candidate duplicates or substantially overlaps one
|
|
2232
|
+
+ `2. If a candidate duplicates or substantially overlaps one above but isn't a single-section tweak, `
|
|
2193
2233
|
+ `re-emit it under the EXACT SAME kebab-case name, and only if it needs a substantive update; otherwise omit it.\n`
|
|
2194
|
-
+ `3. Propose a brand-new skill ONLY if nothing
|
|
2234
|
+
+ `3. Propose a brand-new skill ONLY if nothing above covers it, it was CONFIRMED working this session, `
|
|
2195
2235
|
+ `and it generalizes to future sessions on different tasks.\n`
|
|
2196
2236
|
+ `4. Prefer refining/section-updating over proliferating. A small set of sharp, non-overlapping skills is the goal — `
|
|
2197
2237
|
+ `reject your own low-signal or one-off candidates.\n\n`
|