Files
juliusbrussee__cavekit/tests/router.test.cjs
T
Claude 499205d2e0 Add autonomous runtime layer — hooks, orchestration engine, router, budgets
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
2026-04-17 18:46:00 +00:00

57 lines
1.8 KiB
JavaScript

"use strict";
const assert = require("assert");
const { scoreTask, tierForScore, pickModel, presetModel, clampTier, ROLE_BASELINES } =
require("../scripts/cavekit-router.cjs");
function score_axes_additive() {
const s = scoreTask({ files: 3, type: "feature", judgment: "medium", cross_component: 1, novelty: "rare" });
// files:3→1, type:feature→2, judgment:medium→2, cross:1, novelty:rare→1 = 7
assert.strictEqual(s, 7);
}
function tier_bands() {
assert.strictEqual(tierForScore(0), "haiku");
assert.strictEqual(tierForScore(6), "haiku");
assert.strictEqual(tierForScore(7), "sonnet");
assert.strictEqual(tierForScore(13), "sonnet");
assert.strictEqual(tierForScore(14), "opus");
}
function role_baseline_clamps() {
// complexity role must be haiku always.
const t = pickModel("ck:complexity", 18);
assert.strictEqual(t, "haiku");
// architect floor is sonnet.
const t2 = pickModel("ck:architect", 0);
assert.strictEqual(t2, "sonnet");
}
function budget_pressure_demotes() {
const t = pickModel("ck:task-builder", 14, { budget_pressure: 0.95 });
assert.strictEqual(t, "haiku");
const t2 = pickModel("ck:task-builder", 14, { budget_pressure: 0.75 });
assert.strictEqual(t2, "sonnet");
}
function preset_matrix() {
assert.strictEqual(presetModel("expensive", "execution"), "opus");
assert.strictEqual(presetModel("quality", "exploration"), "sonnet");
assert.strictEqual(presetModel("balanced", "execution"), "sonnet");
assert.strictEqual(presetModel("fast", "reasoning"), "sonnet");
}
function clamp_respects_band() {
const band = ROLE_BASELINES["ck:task-builder"];
assert.strictEqual(clampTier("opus", band), "opus");
assert.strictEqual(clampTier("haiku", band), "haiku");
}
module.exports = {
score_axes_additive,
tier_bands,
role_baseline_clamps,
budget_pressure_demotes,
preset_matrix,
clamp_respects_band,
};