feat(runtime): v0.1.0 — adopt Voyager critic + Mindcraft modes/library/lint
Five concrete patterns from Voyager and Mindcraft, applied in our shape
without abandoning the git-as-evolution-substrate that makes pepa
distinct. Plus a first multi-agent surface so two bots from the same
repo can share intent.
1. runtime/critic.js (Voyager critic.txt)
- Spawns `pi -p` with a JSON-only critic prompt before a proposal is
written. {reasoning, success, critique}.
- success=true short-circuits the proposal (bot recovered between
detector tripping and now), saving Pi tokens on false positives.
- critique is spliced into the proposal body via attachCritique() so
the downstream auto-patcher has a sharp spec.
- Graceful: pi missing / timeout / unparseable JSON → proposal still
filed without the critic block.
2. scripts/lint-patch.js (Mindcraft coder._lintCode)
- Pre-flight gate between Pi commit and npm test: node --check, dynamic
import (catches missing named exports), regex extraction of
runSkill("id") calls cross-checked against the live registry.
- Cheaper than npm test, fails fast with a clear reason.
3. runtime/stuck-incident.renderActionTemplate (Voyager action_template.txt)
- All proposal bodies now follow the same fixed-section layout: Task /
Last result / Execution error / State / Metrics / Journal /
Scenarios / Critique / Fix / Edit scope / Forbidden.
4. runtime/skill-library.js (Mindcraft skill_library.getRelevantSkillDocs)
- Word-overlap ranking (Mindcraft's offline fallback) — zero deps,
deterministic. auto-patch.js injects top-3 similar skills into the
Pi prompt as "look at these patterns".
5. runtime/modes.js (Mindcraft modes.js)
- Declarative {name, interrupts, on, active, update(ctx)} chain that
runs BEFORE the curriculum each tick.
- Ships self_preservation (low HP → eat/flee), hunger (food<14 → eat),
night_shelter (night + bed in hand → sleep). Cleaner than ad-hoc
lastFleeAttempt cooldowns in reflex.js.
6. runtime/social/conversation.js + cmd:conv-say/conv-recent/conv-list
- File-JSONL topic channel so two bots from the same repo (different
usernames, different host dirs under state/) can append turns and
read peers. Skeleton — multi-agent collaboration on top later.
Differentiator preserved: every Pi-written skill still lands on main via
auto-patch.js (real git branch + smoke gate + cherry-pick). Voyager
keeps skills in a Chroma JSON, Mindcraft keeps them in RAM — pepa keeps
them as versioned source code reviewable in `git log`.
package.json: 0.0.1 → 0.1.0. 174/174 tests pass. README + AGENTS updated.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+134
-82
@@ -4,6 +4,13 @@
|
||||
// the reflex loop hasn't crashed, but a single reason code (e.g.
|
||||
// no_food_source, planner_empty) keeps coming back tick after tick.
|
||||
//
|
||||
// Before a proposal is filed, an optional critic pass (runtime/critic.js,
|
||||
// adapted from Voyager) gets one Pi roundtrip to judge whether the bot
|
||||
// actually failed. critic.success=true short-circuits the proposal (the
|
||||
// bot has already recovered between the detector tripping and now);
|
||||
// critic.success=false embeds the critique in the proposal body so the
|
||||
// downstream auto-patcher has a sharp spec instead of raw metrics.
|
||||
//
|
||||
// When the same reason persists past STUCK_THRESHOLD_MS we build a
|
||||
// proposal body summarising the situation, including:
|
||||
// - the no-progress reason
|
||||
@@ -112,52 +119,22 @@ export function createStuckIncidentDetector({ thresholdMs = STUCK_THRESHOLD_MS,
|
||||
).join("\n")
|
||||
: "_(no scenario memory recorded yet)_";
|
||||
|
||||
const body = [
|
||||
`# Stuck on \`${reason}\``,
|
||||
"",
|
||||
`The runtime has reported the same no-progress reason for >${Math.round(thresholdMs / 60000)} min without a productive action.`,
|
||||
"",
|
||||
"## Current state",
|
||||
"",
|
||||
"```json",
|
||||
JSON.stringify(slim, null, 2),
|
||||
"```",
|
||||
"",
|
||||
"## Last action result",
|
||||
"",
|
||||
lastResult
|
||||
? `\`${lastResult.label}\` → ${lastResult.code ?? (lastResult.ok ? "ok" : "fail")}${lastResult.detail ? ` (${JSON.stringify(lastResult.detail).slice(0, 200)})` : ""}`
|
||||
: "_(none recorded)_",
|
||||
"",
|
||||
"## Skill metrics so far (this process lifetime)",
|
||||
"",
|
||||
metricsLine,
|
||||
"",
|
||||
"## World journal (what we have discovered so far)",
|
||||
"",
|
||||
journalLine,
|
||||
"",
|
||||
"## Recent scenario memory (last attempts, what worked / failed in similar situations)",
|
||||
"",
|
||||
scenarioLines,
|
||||
"",
|
||||
"## Suggested fix",
|
||||
"",
|
||||
suggested
|
||||
const body = renderActionTemplate({
|
||||
title: `Stuck on \`${reason}\``,
|
||||
lede: `The runtime has reported the same no-progress reason for >${Math.round(thresholdMs / 60000)} min without a productive action.`,
|
||||
task: milestone?.title ?? "(no active milestone)",
|
||||
suggestedSkill: suggested,
|
||||
lastResult,
|
||||
executionError: lastResult?.detail ?? null,
|
||||
state: slim,
|
||||
metrics: metricsLine,
|
||||
journal: journalLine,
|
||||
scenarioTail: scenarioLines,
|
||||
editScope,
|
||||
fixGuidance: suggested
|
||||
? `Improve \`${suggested}\` so the bot can clear the \`${reason}\` blocker, OR teach a NEW skill that handles this kind of situation if no single edit fixes it. Touch only the listed files (the test files under runtime/**/*.test.js are auto-allowed). Use the scenario-memory entries above to avoid re-introducing patterns that already failed.`
|
||||
: `The curriculum has no suggested skill for this state. Either teach the curriculum a new milestone OR add a recovery skill that turns this reason code into a productive action. The scenario memory above shows what's been tried.`,
|
||||
"",
|
||||
"## Edit scope (auto-patch must obey this)",
|
||||
"",
|
||||
editScope.map((p) => `- ${p}`).join("\n"),
|
||||
"",
|
||||
"## Forbidden",
|
||||
"",
|
||||
"- Don't touch `.env`, `state/`, `extensions/`, `tui/` unless the scope above includes them.",
|
||||
"- Don't add new npm dependencies.",
|
||||
"- Don't change git history (no `--amend`, no `git reset --hard`).",
|
||||
"",
|
||||
].join("\n");
|
||||
});
|
||||
|
||||
return {
|
||||
fire: true,
|
||||
@@ -191,44 +168,20 @@ export function createStuckIncidentDetector({ thresholdMs = STUCK_THRESHOLD_MS,
|
||||
).join("\n")
|
||||
: "_(no scenario memory)_";
|
||||
|
||||
const body = [
|
||||
`# Wedged — escape-pit cannot extract the bot`,
|
||||
"",
|
||||
`The bot has produced ${WEDGED_FIRE_AT}+ "wedged-jump / escape-pit / blind" completions in a row.`,
|
||||
"In-world it stands still; the existing escape primitives are not enough.",
|
||||
"",
|
||||
"## Current state",
|
||||
"```json",
|
||||
JSON.stringify(slim, null, 2),
|
||||
"```",
|
||||
"",
|
||||
"## Last action result",
|
||||
lastResult
|
||||
? `\`${lastResult.label}\` → ${lastResult.code ?? (lastResult.ok ? "ok" : "fail")} ${lastResult.detail ? `(${JSON.stringify(lastResult.detail).slice(0, 200)})` : ""}`
|
||||
: "_(none)_",
|
||||
"",
|
||||
"## Skill metrics",
|
||||
metricsLine,
|
||||
"",
|
||||
"## World journal byKind",
|
||||
journalLine,
|
||||
"",
|
||||
"## Recent scenario memory (last attempts)",
|
||||
scenarioLines,
|
||||
"",
|
||||
"## Suggested fix",
|
||||
"",
|
||||
"Either improve `escapePit()` in `runtime/actions.js` (e.g. dig forward + down + side, not only up) OR add a NEW skill `recovery.tunnel-out` that breaks the bot out of a 1×1 hole by digging a 3-block tunnel in the most-free cardinal. Add tests under `runtime/skills/`.",
|
||||
"",
|
||||
"## Edit scope",
|
||||
"- runtime/actions.js",
|
||||
"- runtime/skills/",
|
||||
"- runtime/reflex.js",
|
||||
"",
|
||||
"## Forbidden",
|
||||
"- Don't touch `.env`, `state/`, `extensions/`, `tui/`, `package.json`.",
|
||||
"- Don't add new npm dependencies.",
|
||||
].join("\n");
|
||||
const body = renderActionTemplate({
|
||||
title: "Wedged — escape-pit cannot extract the bot",
|
||||
lede: `The bot has produced ${WEDGED_FIRE_AT}+ "wedged-jump / escape-pit / blind" completions in a row. In-world it stands still; the existing escape primitives are not enough.`,
|
||||
task: "free the bot from its current 1×1 wedge",
|
||||
suggestedSkill: "recovery.tunnel-out",
|
||||
lastResult,
|
||||
executionError: lastResult?.detail ?? null,
|
||||
state: slim,
|
||||
metrics: metricsLine,
|
||||
journal: journalLine,
|
||||
scenarioTail: scenarioLines,
|
||||
editScope: ["runtime/actions.js", "runtime/skills/", "runtime/reflex.js"],
|
||||
fixGuidance: "Either improve `escapePit()` in `runtime/actions.js` (e.g. dig forward + down + side, not only up) OR add a NEW skill `recovery.tunnel-out` that breaks the bot out of a 1×1 hole by digging a 3-block tunnel in the most-free cardinal. Add tests under `runtime/skills/`.",
|
||||
});
|
||||
|
||||
return {
|
||||
fire: true,
|
||||
@@ -241,3 +194,102 @@ export function createStuckIncidentDetector({ thresholdMs = STUCK_THRESHOLD_MS,
|
||||
|
||||
return { check, checkWedged, noteResult, reset };
|
||||
}
|
||||
|
||||
// Render a proposal body in the Voyager action_template.txt schema —
|
||||
// Task / Last action / Execution error / Current state / Metrics /
|
||||
// World journal / Scenario memory / Edit scope / Suggested fix /
|
||||
// Forbidden. The fixed section order trains Pi to scan a familiar
|
||||
// layout instead of re-parsing ad-hoc Markdown each time.
|
||||
export function renderActionTemplate({
|
||||
title,
|
||||
lede,
|
||||
task,
|
||||
suggestedSkill,
|
||||
lastResult,
|
||||
executionError,
|
||||
state,
|
||||
metrics,
|
||||
journal,
|
||||
scenarioTail,
|
||||
editScope,
|
||||
fixGuidance,
|
||||
}) {
|
||||
const lastResultLine = lastResult
|
||||
? `\`${lastResult.label}\` → ${lastResult.code ?? (lastResult.ok ? "ok" : "fail")}${lastResult.detail ? ` (${JSON.stringify(lastResult.detail).slice(0, 200)})` : ""}`
|
||||
: "_(none recorded)_";
|
||||
const errLine = executionError
|
||||
? (typeof executionError === "string" ? executionError : JSON.stringify(executionError)).slice(0, 300)
|
||||
: "_(none)_";
|
||||
return [
|
||||
`# ${title}`,
|
||||
"",
|
||||
lede,
|
||||
"",
|
||||
"## Task",
|
||||
"",
|
||||
`- **goal**: ${task}`,
|
||||
`- **suggested skill**: ${suggestedSkill ? `\`${suggestedSkill}\`` : "_(none — propose one)_"}`,
|
||||
"",
|
||||
"## Last action result",
|
||||
"",
|
||||
lastResultLine,
|
||||
"",
|
||||
"## Execution error",
|
||||
"",
|
||||
errLine,
|
||||
"",
|
||||
"## Current state",
|
||||
"",
|
||||
"```json",
|
||||
JSON.stringify(state, null, 2),
|
||||
"```",
|
||||
"",
|
||||
"## Skill metrics (this process lifetime)",
|
||||
"",
|
||||
metrics,
|
||||
"",
|
||||
"## World journal (what we have discovered so far)",
|
||||
"",
|
||||
journal,
|
||||
"",
|
||||
"## Scenario memory (last attempts in similar situations)",
|
||||
"",
|
||||
scenarioTail,
|
||||
"",
|
||||
"## Suggested fix",
|
||||
"",
|
||||
fixGuidance,
|
||||
"",
|
||||
"## Edit scope (auto-patch must obey this)",
|
||||
"",
|
||||
(editScope || []).map((p) => `- ${p}`).join("\n"),
|
||||
"",
|
||||
"## Forbidden",
|
||||
"",
|
||||
"- Don't touch `.env`, `state/`, `extensions/`, `tui/` unless the scope above includes them.",
|
||||
"- Don't add new npm dependencies.",
|
||||
"- Don't change git history (no `--amend`, no `git reset --hard`).",
|
||||
"",
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
// Splice a Voyager-style critic block into a proposal body. Inserted just
|
||||
// before the "## Suggested fix" header so Pi sees the critic's surgical
|
||||
// hint before its own guidance.
|
||||
export function attachCritique(body, critique) {
|
||||
if (!critique) return body;
|
||||
const block = [
|
||||
"## Critic (Pi pre-flight judgement)",
|
||||
"",
|
||||
`- **reasoning**: ${critique.reasoning || "(none)"}`,
|
||||
`- **success-already**: ${critique.success}`,
|
||||
`- **critique**: ${critique.critique || "(none)"}`,
|
||||
critique.durationMs != null ? `- _critic took ${critique.durationMs}ms_` : null,
|
||||
"",
|
||||
].filter(Boolean).join("\n");
|
||||
const marker = "## Suggested fix";
|
||||
const idx = body.indexOf(marker);
|
||||
if (idx < 0) return `${body}\n\n${block}`;
|
||||
return `${body.slice(0, idx)}${block}\n${body.slice(idx)}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user