Dispatch System
31 files
Types
/** Contract types for loom-builder dispatches. */ export interface ModelRef { provider: string; id: string; } exp…
Gate Packs
import { existsSync, readFileSync, statSync } from "node:fs"; import { join, resolve } from "node:path"; import type { V…
Gate Integrity
/** * gate-integrity.ts — Layer 1 runtime enforcement (A13 / N15 / N16). * * Verifies a spec's pinned gate reference …
Gate Analyzer
/** * gate-analyzer — preflight gate complexity review. * * Runs on EVERY dispatch after spec lint, before the execut…
Purpose.Test
import { describe, expect, test } from "bun:test"; import { injectPurpose, purposeBlock } from "./purpose.js"; describe…
Dispatch Archive.Test
/** * Structural proof of the Dispatch Artifact Contract across paths. * Asserts: on BOTH normal completion AND a SIGT…
Pi Executable
import { existsSync } from "node:fs"; export interface PiExecutableCheck { ok: boolean; path: string; reason: str…
Model Router
import { existsSync, readFileSync } from "node:fs"; import { resolve } from "node:path"; import type { DispatchSpec, Mod…
Spec Lint
/** * Spec-schema lint — validates DispatchSpec at preflight before dispatch. * * Checks: * - Unknown top-level keys…
Preflight Cli
/** * Pre-flight CLI: estimate tokens for a spec and exit non-zero if too large. * Usage: bun run src/preflight-cli.ts…
Preflight
import { readFileSync } from "node:fs"; import { globSync } from "glob"; import { resolve, relative } from "node:path"; …
Pi Executable.Test
import { afterEach, describe, expect, test } from "bun:test"; import { mkdtempSync, rmSync, writeFileSync } from "node:f…
Outcome
import type { DispatchOutcome } from "./types.js"; export type DispatchStatus = DispatchOutcome["status"]; export func…
Run
/** * loom-builder — homeostatic dispatch harness. * Runs one DispatchSpec: agent loop (pi-coding-agent SDK) under har…
Exit Matrix
/** * Exit-code retry matrix — maps process outcomes to verdicts. * * Bug fixed: executor exit -1 previously could re…
Import Lesson
/** * import-lesson.ts — reads enforcement artifacts from pi-cybernetic's file-based * queue and applies them to loom-…
Dispatch Archive
/** * dispatch-archive — THE single source of truth for the Dispatch Artifact Contract. * * Contract (see /home/mikes…
Gate Escalation
/** * gate-escalation — consecutive-failure tracking and diagnostic interrogation. * * When the same validation gate …
Gates
import { createHash } from "node:crypto"; import { GateHaltError, type HaltReason, type ValidationCmd } from "./types.js…
Gate Escalation.Test
import { describe, expect, test } from "bun:test"; import { GateEscalationTracker, buildDiagnosticPrompt, parseDia…
Preflight.Test
/** * Tests for token-cliff gate: pre-flight estimate, runtime ceiling, chain awareness. */ import { describe, test, e…
Purpose
import type { DispatchSpec } from "./types.js"; export const PURPOSE_HEADER = "## PURPOSE (INVARIANT — restated verbati…
Import Lesson.Test
/** * Tests for import-lesson.ts — the bridge from pi-cybernetic enforcement * artifacts to loom-builder's gate govern…
Gate Analyzer.Test
import { describe, expect, test, mock, beforeEach } from "bun:test"; import type { DispatchSpec, ValidationCmd, GateAnal…
Model Router.Test
import { describe, expect, test } from "bun:test"; import { PreFlightError } from "./preflight.js"; import { routeModelF…
Exit Matrix.Test
import { describe, test, expect } from "bun:test"; import { exitToVerdict, isRetryable, canBeDone, retryBackoffMs } from…
Outcome.Test
import { describe, expect, test } from "bun:test"; import { normalizeMaxReformulations, settleStatusAfterValidation, val…
Artifact Contract.Test
/** * Artifact Contract Tests for run.ts dispatch paths. * * Proves that run.ts enforces the Dispatch Artifact Contra…
Trace
import { appendFileSync, mkdirSync } from "node:fs"; import { dirname } from "node:path"; import type { TraceEvent } fro…
Gates.Test
import { describe, expect, test } from "bun:test"; import { BudgetGovernor, LoopDetector, actionHash, canonicalJ…