v0.3.0-rc.1: live skill registry + fast advisor scaffold

Roots out the v0.2.x failure mode: Pi-extracted lessons routinely named
hallucinated skill ids (relocate.surface, choose.safe.surface,
survive.shelter, gather.visible_log, …). All 47 Pi-lessons in the live DB
had applied_count=0 because normalisePreferSkill couldn't find them.

Fix:
1. runtime/skill-registry.js — single source of truth derived from
   skills/index.js. Exports listSkillIds, isRegistered, and a
   prompt-ready block (skillRegistryPrompt) grouped by namespace.
2. Pi prompts (coach/postmortem, coach/reflect) embed the live registry
   with a "USE ONLY THESE, never invent" instruction. Lessons are
   filtered at write-time too — anything not in the registry and not a
   known mode name gets dropped.
3. coach/advice.js — normalisePreferSkill now returns null for unknown
   ids, hardening consult() against any hallucinations that slip
   through. Warn-logged for visibility.

Also lays the LLM substrate for the rest of v0.3.0:

- runtime/llm/provider.js — OpenAI-compatible chat client. Configured
  via PEPA_FAST_LLM_{BASE_URL,API_KEY,MODEL,TIMEOUT_MS}. Safe no-op
  unless API_KEY is set. Supports JSON-mode.
- runtime/coach/fast-advisor.js — tactical advisor tier (scaffold).
  Exposes advise() that asks the fast LLM what to do RIGHT NOW when
  the reflex is wedged/stuck. Rejects hallucinated skill ids using the
  registry. Rate-limited 6/h, 30s cooldown. Not auto-triggered yet —
  wired into reflex in rc.3 (awareness layer).

Tests: 279 green (+24 vs rc.3): 5 registry, 9 provider, 10 advisor.

See dev/v0.3.0/PLAN.md for the full iteration design (manifesto needs
ladder, event-driven awareness, skill pre-emption) and STATUS.md for
shipped/pending tracking.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 17:39:43 +03:00
co-authored by Claude Opus 4.7
parent 865aae1213
commit fcfa2277ba
13 changed files with 1113 additions and 20 deletions
+68
View File
@@ -0,0 +1,68 @@
// Single source of truth for "what skill ids are real" — exported separately
// from skills/index.js so coach/advice.js, coach/postmortem.js, coach/reflect.js,
// and coach/fast-advisor.js can all consult the SAME live registry without
// circular imports through runSkill.
//
// Why this exists: in v0.2.x Pi (the LLM coach) routinely fabricated
// skill ids that never existed — "relocate.surface", "choose.safe.surface",
// "survive.shelter", "gather.visible_log". Of 47 Pi-extracted lessons,
// 0 were ever applied because normalisePreferSkill() couldn't map them
// to anything real. The fix is two-pronged: (a) hand Pi the real registry
// in its system prompt so it doesn't have to guess; (b) reject anything
// not in the registry at the consult() boundary.
import { listSkills } from "./skills/index.js";
let _cache = null;
function rebuild() {
const all = listSkills();
const byId = new Map();
const byNamespace = new Map();
for (const s of all) {
byId.set(s.id, s);
const ns = s.id.split(".")[0] || "misc";
if (!byNamespace.has(ns)) byNamespace.set(ns, []);
byNamespace.get(ns).push(s);
}
_cache = { all, byId, byNamespace };
return _cache;
}
function get() { return _cache ?? rebuild(); }
export function listSkillIds() {
return Array.from(get().byId.keys());
}
export function isRegistered(id) {
if (!id || typeof id !== "string") return false;
return get().byId.has(id);
}
export function describeSkill(id) {
return get().byId.get(id) ?? null;
}
// Human-readable block to drop into LLM system prompts. Groups by
// namespace, lists "id — title (timeoutMs)". Capped at ~2KB to stay
// well within the model's instruction window.
export function skillRegistryPrompt({ limit = 2000 } = {}) {
const { byNamespace } = get();
const namespaces = Array.from(byNamespace.keys()).sort();
const lines = ["Valid skill ids (USE ONLY THESE for avoid_skill / prefer_skill):"];
for (const ns of namespaces) {
const skills = byNamespace.get(ns).sort((a, b) => a.id.localeCompare(b.id));
lines.push(` ${ns}:`);
for (const s of skills) {
lines.push(` - ${s.id}${s.title ?? s.id}`);
}
}
lines.push("");
lines.push("If no listed skill fits, set the field to null. NEVER invent new ids.");
const text = lines.join("\n");
return text.length > limit ? text.slice(0, limit - 4) + "\n..." : text;
}
// For tests / hot-reload scenarios.
export function _resetForTest() { _cache = null; }