Skip to content

Scripts

The pipeline is a collection of small, single-purpose scripts under scripts/. Each one owns a narrow job — a phase transition, a model invocation, a state write — and the orchestrator wires them together. This page catalogs the ones you will reach for most often, grouped by function.

Source of truth

This page summarizes the catalog for public reference. The authoritative, always-current version lives in the private repo at docs/scripts-reference.md. For the complete list, run ls scripts/.

Pipeline core

ScriptWhat it does
orchestrate.shHandles phase transitions and global pipeline state. Writes to state/STATE.json (active phase, active agent, locks). Invoked by every phase command. Not to be confused with the per-issue state/pipeline/<issue>.json.
run.jsSecure proxy for executing bash scripts inside the Claude Code sandbox. Fixes the fd mismatch on Windows/WSL by spawning bash with correct pipes, and kills stalled scripts after JKZ_STALL_TIMEOUT_MS. Always prefer this over bash script.sh.
json-helper.jsReads and writes per-issue state fields (state/pipeline/<issue>.json) without racing on concurrent writes.
worktree.shCreates, manages, and cleans up the per-issue Git worktree (../jkz-worktree-<issue>), isolated from the main repo. Tracks stages via .jkz-checkpoint.
Terminal window
node scripts/run.js orchestrate.sh transition <phase> --issue <N>
node scripts/run.js resolve-wrapper.sh --role judge --pr 42
node scripts/json-helper.js set <field> <value> state/pipeline/<issue>.json

Model wrappers

ScriptWhat it does
resolve-wrapper.shEntry point for invoking any external agent. Cascade: JKZ_<ROLE>_ENDPOINTapi-wrapper.sh, then JKZ_API_ENDPOINTapi-wrapper.sh, then the native model CLI.
codex-wrapper.shWrapper for the Codex CLI. Per-role session memory, Accumulated Patterns extraction, 5-minute stall detection, rate-limit retry with exit 75.
gemini-wrapper.shWrapper for the Gemini CLI. Streaming JSONL, multi-format parsing, exponential rate-limit retry, format fallback.
api-wrapper.shWrapper for OpenAI-compatible endpoints. Used when JKZ_<ROLE>_ENDPOINT or JKZ_API_ENDPOINT are set.
resolve-provider-fallback.shResolves the fallback provider when a wrapper exits 75 (rate limit). Defaults: auditor/lens → sonnet; curator/inspector/judge/sentinel → opus.
parse-gemini-stream.jsNormalizes Gemini CLI output to a unified {response, session_id, tokens, format} shape. Used internally by gemini-wrapper.sh.

Validators

ScriptWhat it does
scripts/validators/run.jsPre-validated checks runner. Receives the diff via stdin, returns { checks, skipped }. Output is injected as === PRE-VALIDATED CHECKS === into Judge and Sentinel prompts. Full reference → Validators.
scripts/validators/config.jsonRule configuration: enabled, severity (fail/warn), type (diff-safe/worktree-required). Toggle rules without touching code.

Infrastructure and monitoring

ScriptWhat it does
health-check.shFull system health check: CLI versions, auth, MCP servers, tests, npm audit, stale worktrees, service status. --fix updates outdated CLIs; --deep adds auth, MCP, and notifications.
circuit-breaker.jsProtects the pipeline from downed services. States: closedopen (after 3 consecutive failures) → half_openclosed. State in state/circuit/<service>.json.
telegram-bot.jsMonitoring and remote-control bot: 11 health checks every 10 min, task discovery every 30 min, inline commands. Requires JKZ_NOTIFY_BACKEND=telegram.
monitoring-checks.jsThe 9 async checks behind the monitoring loop (agent idle, CI status, stale worktrees, rate limits, SLO compliance, groupthink, and more).
slo-check.jsEvaluates pipelines against the 4 SLOs in scripts/slos.json over a 30-day window.

Pipeline utilities

ScriptWhat it does
loop-guard.jsDetects duplicate Doctor fix attempts via SHA256 (exact) and Jaccard similarity (≥80% near-duplicate). Advisory — injects a warning, does not block.
resume-diagnose.jsDiagnoses pipeline interruptions (crash, fail, blocked, running, stopped, completed) and determines the resume point. Releases expired locks.
postmortem-generate.jsGenerates a postmortem when the pipeline reaches jkz:blocked: event timeline, failure patterns, 5-whys template.
pipeline-cost-report.jsBuilds a cost table by phase/role/iteration from tokens._runs[] in pipeline state, priced via scripts/pricing.json.
pipeline-notify.shSends phase-transition notifications. Respects JKZ_NOTIFY_FORCE_DISABLE=1 for tests.
step-gate.jsDAG of dependencies between pipeline steps. Commands call begin/complete to track progress and guard crash recovery.
classify-issue.jsHybrid issue complexity classifier (LLM primary via Haiku, deterministic fallback). Outputs complexity, confidence, recommended_pipeline, reasoning, signals.
agent-kind.jsCentralized kind classification per role: creative, adversarial, validator, utility.

Memory and patterns

ScriptWhat it does
memory-store.jsSQLite client for the patterns system (state/memory.db). Operations: insert, reinforce-patterns, increment-ignore, decay.
memory-curate.jsCLI for Claude Code memory files. Actions: status, review, promote, classify.
format-patterns.jsFormats patterns from SQLite for prompt injection. Budget-controlled: 800 tokens adversarial, 500 constructive.

GitHub integration

ScriptWhat it does
adr-extract.jsReads the jkz:adr-json signal from the Architect’s deliberation and generates MADR documents in docs/decisions/.
resolve-cr-threads.shResolves CodeRabbit threads in bulk. Use only for VALID/OUT_OF_SCOPE threads — it does not verify a reply was posted.
minimize-old-comments.shMinimizes outdated comments from previous iterations of the same role on a PR. Invoked automatically by wrappers.
pin-status-comment.shPins status comments on issues (REST API with GraphQL fallback). Auto-unpins the previous pin.
check-merge-gate.shVerifies the 4 layers of the merge gate before allowing a merge.
post-merge.shPost-merge cleanup: removes the worktree, clears phase labels, archives deliberations.
project-sync.shSyncs the issue to a GitHub Projects board on phase transitions. Requires JKZ_PROJECT_NUMBER. Optional.

Observability

ScriptWhat it does
langfuse-trace.jsFire-and-forget LangFuse client (zero deps, native fetch, fail-silent). Maps pipeline run → Session, phase+iteration → Trace, agent invocation → Generation, verdict → Score. Flag: LANGFUSE_ENABLED=true.
analyze-deliberations.jsDeliberation analytics: agreement rates, tokens per role, patterns. Backs /jkz:insights.
threat-model.jsGenerates state/threat-model.json (STRIDE) when the issue carries security labels or keywords.

Installation

ScriptWhat it does
install.shFull system installation.
install-service.shInstalls the Telegram bot as a service (launchd/PM2).
add-project.shRegisters a project in jkz.
jkz-install.shInstalls jkz in plugin mode in another project.
jkz-update.shUpdates jkz to the latest version.
jkz-uninstall.shUninstalls jkz.
  • Validators — the pre-validated checks runner in detail.
  • Glossary — definitions for the terms used above.
  • CLI / commands — the /jkz:* commands that orchestrate these scripts.