mirror of
https://github.com/JuliusBrussee/cavekit.git
synced 2026-09-14 16:32:40 +08:00
499205d2e0
Introduces the machinery that turns /ck:make into a hands-off autonomous
loop without changing the Hunt methodology. Nothing in existing commands,
skills, or agents breaks; the new layer is additive and opt-in.
New runtime (scripts/):
- cavekit-tools.cjs — state machine, lock with heartbeat, token ledger,
task registry, routing, capability discovery, backprop directive,
status-block dashboard. Zero runtime deps.
- cavekit-router.cjs — five-axis task scoring mapped to haiku/sonnet/opus
tiers with role baselines and budget-pressure demotion.
New hook system (hooks/):
- stop-hook.sh — Stop-event driver; reads .cavekit/state, routes the next
prompt, returns {decision:"block",reason:...} to keep the session going
until <promise>CAVEKIT_COMPLETE</promise> is emitted or a budget trips.
- token-monitor.sh — per-task budget (80% warn, 100% halt).
- tool-cache.js / tool-cache-store.js — 120s TTL cache for read-only tools.
- test-output-filter.js — condense test output around failure lines.
- auto-backprop.js — write flag file on test failure; stop-hook prepends
a backpropagation directive on the next iteration.
- progress-tracker.js — zero-stdout snapshot for /ck:watch.
- hooks.json — registers all of the above (Stop + PreToolUse + PostToolUse).
New skills (skills/):
- karpathy-guardrails — four behavioral rules (think-before-code, simplicity,
surgical, goal-driven) enforced by reviewer and task-builder.
- caveman-internal — three intensity modes (lite/full/ultra) for
machine-to-machine artifacts, with budget-pressure auto-selection and a
verbose-regeneration fallback. Separate from the user-facing /caveman skill.
- backpropagation — six-step bug-to-kit trace; auto-triggered by the
auto-backprop hook or manually via /ck:backprop.
- complexity-detection — five-axis scoring rubric; depth mapping
(0-6 quick / 7-13 standard / 14+ thorough).
- autonomous-loop — end-to-end loop reference (state files, sentinels,
lock protocol, debugging).
- capability-discovery — MCP + plugin + CLI detection, writes
.cavekit/capabilities.json.
- graphify-integration — optional knowledge-graph queries; degrades to grep
when graphify-out/graph.json is absent.
New commands (commands/):
- /ck:watch — live dashboard.
- /ck:resume — recover from crash, lock conflict, or interrupt.
- /ck:backprop — manual entry to the backpropagation skill.
- /ck:review-branch — two-pass (kit + code) branch review, optional Codex.
- /ck:setup-tools — run capability discovery and summarize.
New agents (agents/):
- complexity — haiku-only classifier, returns JSON score.
- verifier — goal-backward verification with stub detection.
- researcher — multi-source research brief with citations.
Templates (templates/):
- state.md, config.json, task-status.json, spec-kit.md — seed files that
commands copy into .cavekit/ or context/ on init.
Config (scripts/bp-config.sh):
- Adds session_budget, max_iterations, task_budget_{quick,standard,thorough},
auto_backprop, tool_cache(+_ttl_ms), test_filter, progress_tracker,
parallelism_max_{agents,per_repo}, model_routing, graphify_enabled.
- Extends caveman_phases validator to accept review and verify.
Plugin manifest (.claude-plugin/):
- plugin.json + marketplace.json for the marketplace discovery path.
Existing root plugin.json bumped to 2.1.0; install.sh version strings
bumped to match.
Tests (tests/):
- 34 zero-dep Node.js tests covering frontmatter round-trip, state
merging, lock acquire/heartbeat/steal/release, per-task + session
budget, task registry with dependency ordering, routing sentinels,
router tier bands, preset matrix, and deep-merged config loading.
- Runner: `node tests/run-tests.cjs`.
No changes to existing /ck:sketch, /ck:map, /ck:make, /ck:check, or any
existing skill/agent — this commit strictly adds the runtime layer beneath
them.
https://claude.ai/code/session_018edLvsv8JE9947oFiBXyHS
75 lines
2.3 KiB
JavaScript
75 lines
2.3 KiB
JavaScript
"use strict";
|
|
const assert = require("assert");
|
|
const path = require("path");
|
|
const {
|
|
setupLoop, routeDecision, initTaskRegistry, markTaskComplete,
|
|
readLedger, writeState, teardownLoop,
|
|
} = require("../scripts/cavekit-tools.cjs");
|
|
const { cavekitDir, rmrf } = require("./helpers.cjs");
|
|
|
|
const sample = [
|
|
{ id: "T-001", title: "First", tier: 1, depends_on: [] },
|
|
{ id: "T-002", title: "Second", tier: 2, depends_on: ["T-001"] },
|
|
];
|
|
|
|
function route_returns_next_task_prompt() {
|
|
const ck = cavekitDir("route-next");
|
|
setupLoop(ck, { maxIterations: 10 });
|
|
initTaskRegistry(ck, sample);
|
|
const out = routeDecision(ck);
|
|
assert.ok(out.includes("T-001"));
|
|
assert.ok(out.includes("Wave"));
|
|
rmrf(path.dirname(ck));
|
|
}
|
|
|
|
function route_returns_done_sentinel_when_empty() {
|
|
const ck = cavekitDir("route-done");
|
|
setupLoop(ck, { maxIterations: 10 });
|
|
initTaskRegistry(ck, sample);
|
|
markTaskComplete(ck, "T-001");
|
|
markTaskComplete(ck, "T-002");
|
|
const out = routeDecision(ck);
|
|
assert.strictEqual(out, "CAVEKIT_LOOP_DONE");
|
|
rmrf(path.dirname(ck));
|
|
}
|
|
|
|
function route_returns_max_iterations_sentinel() {
|
|
const ck = cavekitDir("route-max");
|
|
setupLoop(ck, { maxIterations: 0 });
|
|
initTaskRegistry(ck, sample);
|
|
const out = routeDecision(ck);
|
|
assert.strictEqual(out, "CAVEKIT_MAX_ITERATIONS");
|
|
rmrf(path.dirname(ck));
|
|
}
|
|
|
|
function route_returns_budget_exhausted_sentinel() {
|
|
const ck = cavekitDir("route-budget");
|
|
setupLoop(ck, { maxIterations: 10 });
|
|
initTaskRegistry(ck, sample);
|
|
// Manually exhaust session.
|
|
const led = readLedger(ck);
|
|
led.session_used = led.session_budget + 1;
|
|
const fs = require("fs");
|
|
fs.writeFileSync(path.join(ck, "token-ledger.json"), JSON.stringify(led));
|
|
const out = routeDecision(ck);
|
|
assert.strictEqual(out, "CAVEKIT_BUDGET_EXHAUSTED");
|
|
rmrf(path.dirname(ck));
|
|
}
|
|
|
|
function teardown_clears_loop_and_lock() {
|
|
const ck = cavekitDir("route-tear");
|
|
setupLoop(ck, { maxIterations: 10 });
|
|
teardownLoop(ck);
|
|
const fs = require("fs");
|
|
assert.strictEqual(fs.existsSync(path.join(ck, ".loop.json")), false);
|
|
rmrf(path.dirname(ck));
|
|
}
|
|
|
|
module.exports = {
|
|
route_returns_next_task_prompt,
|
|
route_returns_done_sentinel_when_empty,
|
|
route_returns_max_iterations_sentinel,
|
|
route_returns_budget_exhausted_sentinel,
|
|
teardown_clears_loop_and_lock,
|
|
};
|