typescript

235 files

loom-sprint-scaffoldsource

Ack Gate

/** * H3.1 — Ack Gate: wrap every tool result with obs_hash; enforce that the * NEXT assistant turn begins with `<ack …

TS94 lines2,810 bytes
loom-sprint-scaffoldtest

Ack Gate.Test

/** * Tests for ack-gate (H3.1). * * Proves: * - wrapResult produces deterministic hex hash from tool result * - ch…

TS162 lines5,577 bytes
codemode-gatewaysource

Ai

import type { Env } from "../types"; /** * AI namespace tools — powered by Workers AI binding. * * Uses `env.AI.run(…

TS125 lines4,276 bytes
pi-cyberneticsource

Analyze Batches

import { Agent } from "@earendil-works/pi-agent-core"; import { getModel } from "@earendil-works/pi-ai"; import { Type }…

TS139 lines5,068 bytes
loom-sprint-scaffoldsource

Approve Skills

#!/usr/bin/env bun /** * Approval CLI for skill proposals. * * This is OPERATOR TOOLING — a bun script, NOT workerd c…

TS233 lines7,435 bytes
loom-buildertest

Artifact Contract.Test

/** * Artifact Contract Tests for run.ts dispatch paths. * * Proves that run.ts enforces the Dispatch Artifact Contra…

TS200 lines7,726 bytes
loom-builder-soltest

Artifact Contract.Test

/** * Artifact Contract Tests for run.ts dispatch paths. * * Proves that run.ts enforces the Dispatch Artifact Contra…

TS200 lines7,726 bytes
codemode-gatewaysource

Artifacts

import type { Env } from "../types"; /** * Artifacts namespace tools — R2 bucket for binary artifacts. * * Provides …

TS36 lines992 bytes
codemode-gatewaysource

Browser

import type { Env } from "../types"; /** * Browser namespace tools — powered by Browser Rendering quick actions. * *…

TS195 lines6,781 bytes
loom-sprint-scaffoldsource

Budget Governor

/** * H3.6 — Budget Governor: hard caps B_tokens / B_calls / B_wallclock_ms from * the envelope. Breach → graceful sus…

TS142 lines3,640 bytes
loom-sprint-scaffoldtest

Budget Governor.Test

/** * Tests for budget-governor (H3.6). * * Proves: * - all 3 hard cap types (calls, tokens, wallclock) are enforced…

TS190 lines6,388 bytes
codemode-gatewaysource

Cf

/** * Cloudflare REST API client types and the typed error surfaced to sandbox * code when the API returns `success:fa…

TS58 lines1,628 bytes
loom-sprint-scaffoldtest

Chaos Scenarios

/** * Shared chaos scenario runners used by both chaos.test.ts and * no-silent-failure.test.ts. Lives outside *.test.t…

TS76 lines2,999 bytes
loom-sprint-scaffoldtest

Chaos.Test

/** * Chaos Tests — fault injection, one scenario per test. * * Five scenarios: * 1. dropped-tool-result — ack gat…

TS253 lines10,016 bytes
loom-sprint-scaffoldsource

Checkpoint

/** * H1.1 + H1.4 — The alarm-tick sequence: assemble current GoalState, * evaluate active stage done-criteria predica…

TS299 lines9,633 bytes
loom-sprint-scaffoldtest

Checkpoint.Test

/** * Tests for CheckpointEngine (H1.1 + H1.4). * * Proves: * - scripted fake stage results drive fail_streak to EXA…

TS386 lines13,178 bytes
codemode-gatewaysource

Client

import type { CfEnvelope, CfError, Env } from "../types"; import { CloudflareApiError } from "../types"; /** * Host-si…

TS176 lines5,471 bytes
loom-sprint-scaffoldtest

Codegen

/** * Golden goal: codegen — multi-stage code-generation goal. * * All stages pass done-criteria; the goal completes …

TS82 lines2,789 bytes
loom-sprint-scaffoldsource

Compactor

/** * H4.5 — Compactor: summarize raw working context into semantic MemoryRecords. * * compactStage(goal_id, stage_id…

TS208 lines6,662 bytes
loom-sprint-scaffoldtest

Compactor.Test

/** * Compactor tests (H4.5). * * Proves: * - Compactor output records all validate against memory-record.schema.j…

TS178 lines6,156 bytes
loom-sprint-scaffoldsource

Conf Monitor

/** * H3.5 — Confidence Monitor: every assistant turn must include conf ∈ [0,1] * (schema-enforced; extract from a tra…

TS108 lines3,011 bytes
loom-sprint-scaffoldtest

Conf Monitor.Test

/** * Tests for conf-monitor (H3.5). * * Proves: * - extractConf finds trailing JSON line `{"conf": 0.8}` in assista…

TS159 lines5,452 bytes
pi-cyberneticsource

Confidence Calibrator

/** P5 — Brier-score confidence calibration over (stated confidence, outcome) pairs. */ import type { Escalation } from…

TS59 lines1,723 bytes
pi-cyberneticsource

Config

/** Harness configuration — one section per loop. */ import type { ToolExecutionMode } from "@earendil-works/pi-agent-c…

TS129 lines4,146 bytes
pi-cyberneticsource

Consolidation

/** * Offline consolidation: Hippocampus -> Neocortex. * * This engine is intentionally not called from transformCont…

TS78 lines2,583 bytes
pi-cybernetictest

Consolidation.Test

import { describe, expect, test } from "bun:test"; import { ConsolidationEngine } from "../src/engines/consolidation.ts"…

TS31 lines1,388 bytes
loom-sprint-scaffoldsource

Context Assembler

/** * H4.1 — Context Assembler. * * assembleContext({scope, goal_id, query, token_budget}): * 1. Query SemanticIndex…

TS229 lines8,047 bytes
loom-sprint-scaffoldtest

Context Assembler.Test

/** * ContextAssembler tests (H4.1). * * Proves: * - Budget NEVER exceeded: table-driven over budgets {0, tiny, ex…

TS245 lines8,542 bytes
loom-sprint-scaffoldsource

Contracts

/** * TypeScript mirrors of the 5 LOOM contracts (src/contracts/*.schema.json). * The JSON Schemas are the source of t…

TS241 lines6,845 bytes
loom-sprint-scaffoldtest

Contracts.Test

import { describe, expect, test } from "bun:test"; import { parseContract, checkContract, isContractName } from "../src/…

TS81 lines3,573 bytes
pi-cyberneticsource

Cybernetic Harness

/** * ADR-001 — Concentric Wrapper. One pi-agent Agent instance, four regulatory * layers attached through its hook su…

TS231 lines9,352 bytes
loom-sprint-scaffoldtest

Data Pipeline

/** * Golden goal: data_pipeline — destructive step requires approval token (mint → verify path). * * Stages: * 1.…

TS138 lines4,961 bytes
loom-sprint-scaffoldsource

Dataset Emitter

/** * H5.6 — Dataset Emitter. * * Exports (failure_pattern, root_cause_signature, successful_intervention) * tuples …

TS185 lines6,010 bytes
loom-sprint-scaffoldtest

Dataset Emitter.Test

/** * Tests for H5.6 — Dataset Emitter. * * Proves: * - extractDatasetTuples extracts (failure_pattern, root_cause…

TS245 lines8,772 bytes
codemode-gatewaysource

Db

import type { Env } from "../types"; /** * `db` namespace tools — generic SQL over the bound D1 database `env.DB`. * …

TS148 lines5,353 bytes
loom-sprint-scaffoldsource

Decomposer

/** * H1.3 — Decompose a goal spec into a sequence of StageSpec[] via a single * model call. Each StageSpec is validat…

TS230 lines8,248 bytes
loom-sprint-scaffoldtest

Decomposer.Test

/** * Tests for decomposer (H1.3). * * Proves: * - rejects non-machine-evaluable done_criteria with the specific vio…

TS182 lines6,299 bytes
pi-cyberneticsource

Desideratum Gate

/** * ADR-004 — D1→D2→D3 enforced at runtime. Failed prerequisites put dependent * modules into degraded passthrough m…

TS59 lines1,580 bytes
loom-buildersource

Dispatch Archive

/** * dispatch-archive — THE single source of truth for the Dispatch Artifact Contract. * * Contract (see /home/mikes…

TS172 lines6,371 bytes
loom-builder-solsource

Dispatch Archive

/** * dispatch-archive — THE single source of truth for the Dispatch Artifact Contract. * * Contract (see /home/mikes…

TS172 lines6,375 bytes
loom-buildertest

Dispatch Archive.Test

/** * Structural proof of the Dispatch Artifact Contract across paths. * Asserts: on BOTH normal completion AND a SIGT…

TS87 lines3,621 bytes
loom-builder-soltest

Dispatch Archive.Test

/** * Structural proof of the Dispatch Artifact Contract across paths. * Asserts: on BOTH normal completion AND a SIGT…

TS87 lines3,621 bytes
pi-cyberneticsource

Dispatch Scanner

import { Agent } from "@earendil-works/pi-agent-core"; import { getModel } from "@earendil-works/pi-ai"; import { Type }…

TS114 lines3,693 bytes
pi-cyberneticsource

Dispatch Scanner V2

import { Agent } from "@earendil-works/pi-agent-core"; import { getModel } from "@earendil-works/pi-ai"; import { Type }…

TS99 lines3,846 bytes
pi-cyberneticsource

Dispatch Scanner V3

import { Agent } from "@earendil-works/pi-agent-core"; import { getModel } from "@earendil-works/pi-ai"; import { Type }…

TS99 lines3,833 bytes
loom-sprint-scaffoldsource

Dlq Escalator

/** * H2.4 — DLQ Escalator. * * Converts a dead letter into a Loop 1 escalation: * - builds typed escalation payload…

TS94 lines3,061 bytes
loom-sprint-scaffoldtest

Dlq Escalator.Test

/** * Tests for DlqEscalator (H2.4). * * Proves: * - DLQ letter → escalation POST with correct payload (goal_id, sta…

TS151 lines5,483 bytes
loom-sprint-scaffoldsource

Do

import { drizzle } from "drizzle-orm/d1"; import { goals } from "../db/schema"; import { parseContract } from "../lib/va…

TS435 lines16,278 bytes
pi-cyberneticsource

Drift Detector

/** P3 — semantic drift between execution trajectory and original spec. */ import type { Escalation } from "../types/in…

TS43 lines1,258 bytes
loom-sprint-scaffoldsource

Drift Sentinel

/** * H1.6 — Drift Sentinel: embed last N stage summaries, compare cosine distance * against the original_spec embeddi…

TS137 lines4,012 bytes
loom-sprint-scaffoldtest

Drift Sentinel.Test

/** * Tests for DriftSentinel (H1.6). * * Proves: * - single spike does NOT raise sustained drift * - sustained div…

TS146 lines4,522 bytes
loom-sprint-scaffoldsource

Drizzle.Config

import type { Config } from "drizzle-kit"; /** * Drizzle is the typed query layer over D1 (src/db/schema.ts). * Migra…

TS16 lines550 bytes
pi-cybernetictest

Enforcement.Test

/** * Unit tests for the enforcement bridge: classifySkill, buildArtifact, emitArtifact. * Tests deterministic mapping…

TS247 lines8,996 bytes
pi-cyberneticsource

Entropy Monitor

/** P6 — channel capacity tracking: context utilization, query/source entropy. */ import { estimateTokens, extractText,…

TS49 lines1,457 bytes
loom-sprint-scaffoldsource

Entropy Monitors

/** * H5.4 — Entropy Monitors. * * Queries entropy H(q) (dispatch outcome entropy) and H(s) (source/variety_class * …

TS177 lines5,757 bytes
loom-sprint-scaffoldtest

Entropy Monitors.Test

/** * Tests for H5.4 — Entropy Monitors. * * Proves: * - Shannon entropy computed correctly with natural log (hand…

TS191 lines6,905 bytes
codemode-gatewaysource

Env

/** * Worker environment bindings for codemode-gateway. * * `LOADER` is the `worker_loaders` binding used by `Dynamic…

TS57 lines2,396 bytes
loom-sprint-scaffoldsource

Env

import type { DispatchEnvelope } from "./contracts"; /** Worker bindings — must match wrangler.jsonc exactly. */ export…

TS13 lines339 bytes
loom-sprint-scaffoldsource

Envelope Compiler

/** * H2.2 + H2.3 — Envelope Compiler. * * compile(stage, mode, opts): DispatchEnvelope * - Tool allowlist: only the…

TS130 lines4,998 bytes
loom-sprint-scaffoldtest

Envelope Compiler.Test

/** * Tests for EnvelopeCompiler (H2.2 + H2.3). * * Proves: * - compiled envelope validates against dispatch-envelop…

TS262 lines10,508 bytes
pi-cyberneticsource

Episodic Store

/** Episodic memory — raw traces with deterministic term-overlap retrieval. */ import type { InteractionTrace } from ".…

TS51 lines1,621 bytes
loom-sprint-scaffoldsource

Errors

/** Typed error hierarchy — never throw bare Error, never swallow. */ export abstract class LoomError extends Error { …

TS67 lines2,492 bytes
loom-sprint-scaffoldsource

Escalation Ledger

/** * H1.4 — Escalation ledger for per-stage fail_streak persistence and * escalation records. Append-only records are…

TS115 lines3,562 bytes
loom-sprint-scaffoldtest

Escalation Ledger.Test

/** * Tests for EscalationLedger (H1.4). * * Proves: * - fail_streak increment/reset * - escalation records append-…

TS110 lines3,728 bytes
codemode-gatewaysource

Execute

/** * HTTP request/response contracts for `POST /execute`. * * These are the gateway's own wire types and are intenti…

TS36 lines1,268 bytes
loom-sprint-scaffoldsource

Execution

/** * Execution harness types — Loop 3: model client, monitors, stage result. * All new execution types go here; barre…

TS119 lines4,106 bytes
loom-buildersource

Exit Matrix

/** * Exit-code retry matrix — maps process outcomes to verdicts. * * Bug fixed: executor exit -1 previously could re…

TS71 lines2,575 bytes
loom-builder-solsource

Exit Matrix

/** * Exit-code retry matrix — maps process outcomes to verdicts. * * Bug fixed: executor exit -1 previously could re…

TS71 lines2,575 bytes
loom-buildertest

Exit Matrix.Test

import { describe, test, expect } from "bun:test"; import { exitToVerdict, isRetryable, canBeDone, retryBackoffMs } from…

TS154 lines5,568 bytes
loom-builder-soltest

Exit Matrix.Test

import { describe, test, expect } from "bun:test"; import { exitToVerdict, isRetryable, canBeDone, retryBackoffMs } from…

TS154 lines5,568 bytes
pi-cyberneticsource

Exporter

/** * exporter.ts — emits enforcement artifacts to a file-based queue. * * Callable from MetaEngine.consolidateLesson…

TS108 lines3,453 bytes
loom-sprint-scaffoldsource

Failure Clusterer

/** * H5.1 — Failure Clusterer. * * Groups trace failures by (tool, normalized error signature, variety_class). * Er…

TS181 lines6,193 bytes
loom-sprint-scaffoldtest

Failure Clusterer.Test

/** * Tests for H5.1 — Failure Clusterer. * * Proves: * - normalizeErrorSignature strips ids, paths, numbers deter…

TS200 lines7,278 bytes
loom-sprint-scaffoldtest

Fakes

/** * Shared fake implementations for LOOM E2E tests. * * Consolidates patterns from: * tests/orchestrator/checkpo…

TS384 lines13,629 bytes
pi-cybernetictest

Fixtures

/** Shared deterministic test fixtures — mock the LLM, never the hooks. */ import { createAssistantMessageEventStream }…

TS128 lines3,508 bytes
loom-sprint-scaffoldtest

Fixtures

/** * Synthetic trace corpus for Loop 5 synthesis tests. * ~50 enriched trace events covering failures, successes, rep…

TS264 lines11,826 bytes
loom-buildersource

Gate Analyzer

/** * gate-analyzer — preflight gate complexity review. * * Runs on EVERY dispatch after spec lint, before the execut…

TS573 lines18,277 bytes
loom-builder-solsource

Gate Analyzer

/** * gate-analyzer — preflight gate complexity review. * * Runs on EVERY dispatch after spec lint, before the execut…

TS571 lines18,199 bytes
loom-buildertest

Gate Analyzer.Test

import { describe, expect, test, mock, beforeEach } from "bun:test"; import type { DispatchSpec, ValidationCmd, GateAnal…

TS546 lines19,035 bytes
loom-builder-soltest

Gate Analyzer.Test

import { describe, expect, test, mock, beforeEach } from "bun:test"; import type { DispatchSpec, ValidationCmd, GateAnal…

TS546 lines19,035 bytes
loom-buildersource

Gate Escalation

/** * gate-escalation — consecutive-failure tracking and diagnostic interrogation. * * When the same validation gate …

TS295 lines9,472 bytes
loom-builder-solsource

Gate Escalation

/** * gate-escalation — consecutive-failure tracking and diagnostic interrogation. * * When the same validation gate …

TS295 lines9,472 bytes
loom-buildertest

Gate Escalation.Test

import { describe, expect, test } from "bun:test"; import { GateEscalationTracker, buildDiagnosticPrompt, parseDia…

TS373 lines15,237 bytes
loom-builder-soltest

Gate Escalation.Test

import { describe, expect, test } from "bun:test"; import { GateEscalationTracker, buildDiagnosticPrompt, parseDia…

TS373 lines15,237 bytes
pi-cyberneticsource

Gate Integrity

/** * gate-integrity.ts — Layer 1 runtime enforcement (A13 / N15 / N16). * * Verifies a spec's pinned gate reference …

TS137 lines5,182 bytes
loom-buildersource

Gate Integrity

/** * gate-integrity.ts — Layer 1 runtime enforcement (A13 / N15 / N16). * * Verifies a spec's pinned gate reference …

TS137 lines5,182 bytes
loom-builder-solsource

Gate Integrity

/** * gate-integrity.ts — Layer 1 runtime enforcement (A13 / N15 / N16). * * Verifies a spec's pinned gate reference …

TS137 lines5,182 bytes
loom-buildersource

Gate Packs

import { existsSync, readFileSync, statSync } from "node:fs"; import { join, resolve } from "node:path"; import type { V…

TS126 lines4,537 bytes
loom-builder-solsource

Gate Packs

import { existsSync, readFileSync, statSync } from "node:fs"; import { join, resolve } from "node:path"; import type { V…

TS126 lines4,537 bytes
loom-buildertest

Gate Packs.Test

import { describe, test, expect } from "bun:test"; import { loadGatePack, resolvePackValidation, staleDigestGuard,…

TS101 lines3,739 bytes
loom-builder-soltest

Gate Packs.Test

import { describe, test, expect } from "bun:test"; import { loadGatePack, resolvePackValidation, staleDigestGuard,…

TS101 lines3,739 bytes
loom-buildersource

Gates

import { createHash } from "node:crypto"; import { GateHaltError, type HaltReason, type ValidationCmd } from "./types.js…

TS174 lines6,717 bytes
loom-builder-solsource

Gates

import { createHash } from "node:crypto"; import { GateHaltError, type HaltReason, type ValidationCmd } from "./types.js…

TS174 lines6,717 bytes
loom-buildertest

Gates.Test

import { describe, expect, test } from "bun:test"; import { BudgetGovernor, LoopDetector, actionHash, canonicalJ…

TS175 lines6,688 bytes
loom-builder-soltest

Gates.Test

import { describe, expect, test } from "bun:test"; import { BudgetGovernor, LoopDetector, actionHash, canonicalJ…

TS175 lines6,688 bytes
pi-cyberneticsource

Gear Shifter

/** * Loop 4 — GearShifter. Deterministic memory router (ADR-005..009). * Preserves the MemoryEngine hook surface whil…

TS313 lines12,599 bytes
pi-cybernetictest

Gear Shifter.Test

import { describe, expect, test } from "bun:test"; import type { AgentMessage } from "@earendil-works/pi-agent-core"; im…

TS42 lines1,852 bytes
pi-cyberneticsource

Goal State

/** Loop 1 — goal homeostasis types (P3). */ export type GoalItemStatus = "pending" | "active" | "complete" | "failed";…

TS60 lines1,669 bytes
loom-sprint-scaffoldtest

Golden Runner

/** * E2E Golden Runner — in-process composition root for LOOM integration tests. * * Wires Loop 1 (CheckpointEngine,…

TS423 lines15,811 bytes
loom-sprint-scaffoldtest

Golden.Test

/** * E2E Golden Goal Tests. * * Runs all three golden goals end-to-end through all LOOM loops. * Each asserts: * …

TS50 lines2,037 bytes
loom-sprint-scaffoldsource

Harness

/** * H3 — Harness: runStage(envelope, modelCaller, deps): Promise<StageResult> * composing all monitors around the to…

TS357 lines13,236 bytes
pi-cybernetictest

Harness.Test

/** * End-to-end: real Agent, real hooks, mock LLM (scripted streamFn). * Verifies the concentric wrapper against pi-a…

TS218 lines8,984 bytes
loom-sprint-scaffoldtest

Harness.Test

/** * Integration tests for harness (runStage). * * Proves every StageTermination kind is reachable: * DONE | GATE_R…

TS612 lines20,705 bytes
loom-sprint-scaffoldtest

Helpers

/** * Test helpers for memory module tests. * * Provides: * - FakeD1: in-memory SQLite (bun:sqlite) implementing D…

TS324 lines10,577 bytes
loom-sprint-scaffoldsource

Hmac

/** * HMAC utilities shared by Loop 1 (token-mint) and Loop 3 (reversibility-gate). * WebCrypto only — workerd-compati…

TS77 lines2,257 bytes
loom-sprint-scaffoldsource

Ids

/** * Identity + hashing primitives shared by every loop. * Web Crypto only — identical behavior on workerd and Bun (H…

TS58 lines2,060 bytes
loom-sprint-scaffoldtest

Ids.Test

import { describe, expect, test } from "bun:test"; import { actionHash, canonicalJSON, dispatchId, newEventId, newGoalId…

TS47 lines1,923 bytes
loom-buildersource

Import Lesson

/** * import-lesson.ts — reads enforcement artifacts from pi-cybernetic's file-based * queue and applies them to loom-…

TS456 lines14,814 bytes
loom-builder-solsource

Import Lesson

/** * import-lesson.ts — reads enforcement artifacts from pi-cybernetic's file-based * queue and applies them to loom-…

TS456 lines14,814 bytes
loom-buildertest

Import Lesson.Test

/** * Tests for import-lesson.ts — the bridge from pi-cybernetic enforcement * artifacts to loom-builder's gate govern…

TS343 lines11,737 bytes
loom-builder-soltest

Import Lesson.Test

/** * Tests for import-lesson.ts — the bridge from pi-cybernetic enforcement * artifacts to loom-builder's gate govern…

TS343 lines11,737 bytes
pi-cyberneticsource

Index

export * from "./types/index.ts"; export * from "./monitors/index.ts"; export * from "./storage/index.ts"; export * from…

TS8 lines246 bytes
pi-cyberneticsource

Index

/** * Enforcement artifact types — the bridge from pi-cybernetic Loop-5 lessons to * loom-builder gate enforcement art…

TS167 lines5,861 bytes
pi-cyberneticsource

Index

export * from "./goal-state.ts"; export * from "./metrics.ts"; export * from "./tool-registry.ts"; export * from "./memo…

TS7 lines188 bytes
pi-cyberneticsource

Index

export * from "./cybernetic-harness.ts"; export * from "./desideratum-gate.ts"; export * from "./ladders.ts";

TS4 lines110 bytes
pi-cyberneticsource

Index

export * from "./episodic-store.ts"; export * from "./semantic-store.ts"; export * from "./procedural-store.ts"; export …

TS5 lines151 bytes
pi-cyberneticsource

Index

export * from "./management.ts"; export * from "./strategic.ts"; export * from "./memory.ts"; export * from "./gear-shif…

TS7 lines192 bytes
pi-cyberneticsource

Index

export * from "./loop-detector.ts"; export * from "./confidence-calibrator.ts"; export * from "./drift-detector.ts"; exp…

TS5 lines155 bytes
loom-buildersource

Index

console.log("Hello via Bun!");

TS1 lines30 bytes
loom-builder-solsource

Index

console.log("Hello via Bun!");

TS1 lines30 bytes
codemode-gatewaysource

Index

import { DynamicWorkerExecutor } from "@cloudflare/codemode"; import type { Env, ErrorResponse, ExecuteRequest, …

TS326 lines12,271 bytes
codemode-gatewaysource

Index

/** * Barrel export for gateway-local types. */ export type { Env } from "./env"; export type { ExecuteRequest, Ex…

TS31 lines556 bytes
loom-sprint-scaffoldtest

Index

/** Barrel for golden goal scripts. */ export { script as codegenScript, assert as assertCodegen } from "./codegen"; ex…

TS6 lines299 bytes
loom-sprint-scaffoldsource

Index

import { drizzle } from "drizzle-orm/d1"; import { dispatches, traceEvents } from "./db/schema"; import { checkContract,…

TS269 lines10,644 bytes
loom-sprint-scaffoldsource

Index

/** * Loop 5 — Synthesis batch glue. * * Thin scheduled() handler that wires injectables from the worker's Env * int…

TS294 lines9,742 bytes
loom-sprint-scaffoldsource

Index

/** * Loop 2 dispatcher — thin worker-side barrel + concrete wire-ups. * * All logic lives in src/dispatcher/core/ (p…

TS120 lines4,364 bytes
loom-sprint-scaffoldsource

Index

/** * Loop 4 — Memory Service: thin worker shell. * * Factory: pick VectorizeIndex when env.SEMANTIC binding present,…

TS259 lines8,844 bytes
loom-sprint-scaffoldsource

Index

/** Barrel — import all LOOM types from "@/types" or relative "../types". */ export * from "./contracts"; export * from …

TS8 lines241 bytes
loom-sprint-scaffoldsource

Index

/** * Barrel — all core orchestration classes and types. */ export { type PredicateEvaluation, evaluatePredicate, eva…

TS11 lines727 bytes
loom-sprint-scaffoldtest

Isolation.Test

/** * Isolation test for src/synthesis/. * * Enforces at the grep level: * 1. No import from src/orchestrator/, sr…

TS132 lines4,331 bytes
pi-cyberneticsource

Ladders

/** * Model escalation ladders — P2 variety expansion. * A ladder is an ordered list of rungs with strictly increasing…

TS61 lines1,995 bytes
pi-cyberneticsource

Live Run

/** * Live-wire smoke run: real opencode-go model through the full 5-loop harness. * * set -a && source /home/mikes…

TS92 lines3,596 bytes
loom-sprint-scaffoldsource

Logger

/** * Structured logger. The single sanctioned sink for log output — * bare console.log in logic paths is a lint-level…

TS37 lines1,354 bytes
pi-cyberneticsource

Loop Detector

/** P5 — action-sequence loop detection over a sliding window. */ import type { Escalation } from "../types/index.ts"; …

TS100 lines3,235 bytes
loom-sprint-scaffoldsource

Loop Detector

/** * H3.2 — Loop Detector: actionHash(tool, args) via src/lib/ids.ts; * ring buffer W=10; ≥3 identical in window → HA…

TS96 lines2,531 bytes
loom-sprint-scaffoldtest

Loop Detector.Test

/** * Tests for loop-detector (H3.2). * * Proves: * - the identical action halts at exactly the 3rd occurrence (not …

TS152 lines5,256 bytes
pi-cyberneticsource

Management

/** * Loop 2 — ManagementEngine. Variety allocator + feedback enforcer (P1, P2, P4). * Attaches via beforeToolCall (di…

TS371 lines14,227 bytes
pi-cybernetictest

Management.Test

import { describe, expect, test } from "bun:test"; import { ManagementEngine } from "../src/engines/management.ts"; impo…

TS325 lines14,039 bytes
pi-cyberneticsource

Memory

/** Loop 4 — three-level memory hierarchy types (P6). */ export interface InteractionTrace { id: string; kind: "too…

TS80 lines1,558 bytes
pi-cyberneticsource

Memory

/** * Loop 4 — MemoryEngine. Channel-capacity manager (P6). * Attaches via transformContext (entropy gate) and convert…

TS186 lines7,712 bytes
loom-sprint-scaffoldsource

Memory

/** * Memory service types — Loop 4. * * Injectables: BlobStore, SemanticIndex, Clock, TokenCounter. * D1DatabaseLik…

TS138 lines4,025 bytes
pi-cybernetictest

Memory.Test

import { describe, expect, test } from "bun:test"; import type { AgentMessage } from "@earendil-works/pi-agent-core"; im…

TS111 lines4,808 bytes
pi-cyberneticsource

Messages

/** * ADR-003 — inter-loop communication as custom AgentMessage types via * declaration merging. Carried in the transc…

TS96 lines2,425 bytes
pi-cyberneticsource

Meta

/** * Loop 5 — MetaEngine. Second-order regulator (P5): watches the regulators, * extracts failure patterns, revises c…

TS315 lines12,010 bytes
pi-cybernetictest

Meta.Test

import { describe, expect, test } from "bun:test"; import { ManagementEngine } from "../src/engines/management.ts"; impo…

TS124 lines5,119 bytes
pi-cyberneticsource

Metrics

/** Cross-loop metric, escalation, and meta-learning types. */ export type LoopId = "strategic" | "management" | "execu…

TS73 lines1,903 bytes
loom-sprint-scaffoldsource

Mode Registry

/** * H2.1 — D1-backed mode registry. * * selectMode(variety_class) picks the mode with highest success rate for that…

TS87 lines3,002 bytes
loom-sprint-scaffoldtest

Mode Registry.Test

/** * Tests for ModeRegistry (H2.1). * * Proves: * - unknown variety_class → highest-capability mode + variety_defic…

TS198 lines6,916 bytes
loom-sprint-scaffoldsource

Model Client

/** * H3.0 — Fetch-based Anthropic Messages API client. * workerd-compatible: plain fetch, NO node SDK, no node:* impo…

TS93 lines2,958 bytes
loom-sprint-scaffoldtest

Model Client.Test

/** * Tests for model-client (H3.0). * * Proves: * - createAnthropicModelCaller returns a callable ModelCaller * - …

TS349 lines10,934 bytes
loom-buildersource

Model Router

import { existsSync, readFileSync } from "node:fs"; import { resolve } from "node:path"; import type { DispatchSpec, Mod…

TS69 lines2,315 bytes
loom-builder-solsource

Model Router

import { existsSync, readFileSync } from "node:fs"; import { resolve } from "node:path"; import type { DispatchSpec, Mod…

TS69 lines2,315 bytes
loom-buildertest

Model Router.Test

import { describe, expect, test } from "bun:test"; import { PreFlightError } from "./preflight.js"; import { routeModelF…

TS44 lines1,653 bytes
loom-builder-soltest

Model Router.Test

import { describe, expect, test } from "bun:test"; import { PreFlightError } from "./preflight.js"; import { routeModelF…

TS44 lines1,653 bytes
pi-cybernetictest

Monitors.Test

import { describe, expect, test } from "bun:test"; import { LoopDetector } from "../src/monitors/loop-detector.ts"; impo…

TS97 lines3,898 bytes
loom-sprint-scaffoldtest

No Silent Failure.Test

/** * No-Silent-Failure Invariant Walk. * * For EVERY terminated (non-DONE) stage across all golden runs + chaos runs…

TS249 lines9,793 bytes
loom-buildersource

Outcome

import type { DispatchOutcome } from "./types.js"; export type DispatchStatus = DispatchOutcome["status"]; export func…

TS27 lines894 bytes
loom-builder-solsource

Outcome

import type { DispatchOutcome } from "./types.js"; export type DispatchStatus = DispatchOutcome["status"]; export func…

TS27 lines894 bytes
loom-buildertest

Outcome.Test

import { describe, expect, test } from "bun:test"; import { normalizeMaxReformulations, settleStatusAfterValidation, val…

TS35 lines1,452 bytes
loom-builder-soltest

Outcome.Test

import { describe, expect, test } from "bun:test"; import { normalizeMaxReformulations, settleStatusAfterValidation, val…

TS35 lines1,452 bytes
loom-sprint-scaffoldsource

Parity Check

#!/usr/bin/env bun /** * Parity Check — byte-stable decision log for LOOM monitor decision path. * * Replays a script…

TS170 lines6,075 bytes
codemode-gatewaysource

Parse

/** * Parse-don't-validate helpers for tool argument parsing. * * Each helper throws a plain `Error` with a `"<tool>:…

TS103 lines2,885 bytes
pi-cyberneticsource

Performance Log

/** Loop 5 raw data — structured event log for pattern analysis. */ export interface ToolExecutionRecord { toolName: …

TS68 lines1,718 bytes
loom-buildersource

Pi Executable

import { existsSync } from "node:fs"; export interface PiExecutableCheck { ok: boolean; path: string; reason: str…

TS27 lines861 bytes
loom-builder-solsource

Pi Executable

import { existsSync } from "node:fs"; export interface PiExecutableCheck { ok: boolean; path: string; reason: str…

TS27 lines861 bytes
loom-buildertest

Pi Executable.Test

import { afterEach, describe, expect, test } from "bun:test"; import { mkdtempSync, rmSync, writeFileSync } from "node:f…

TS33 lines1,072 bytes
loom-builder-soltest

Pi Executable.Test

import { afterEach, describe, expect, test } from "bun:test"; import { mkdtempSync, rmSync, writeFileSync } from "node:f…

TS33 lines1,072 bytes
loom-sprint-scaffoldsource

Pointer Hierarchy

/** * H4.4 — Pointer Hierarchy. * * topic → summary → episodic_ref (R2 key). * * memoryExpand(record_id): resolve e…

TS119 lines3,691 bytes
loom-sprint-scaffoldtest

Pointer Hierarchy.Test

/** * PointerHierarchy tests (H4.4). * * Proves: * - memory_expand round-trips: put full text in fake BlobStore → …

TS188 lines6,753 bytes
loom-sprint-scaffoldsource

Predicates

/** * H1.1 — Predicate evaluators for the six machine-evaluable predicate kinds. * * Each takes a Predicate spec + an…

TS109 lines3,011 bytes
loom-sprint-scaffoldtest

Predicates.Test

/** * Tests for predicate evaluators (H1.1). * All six kinds: pass + fail cases each. * Injects a scripted PredicateR…

TS120 lines5,367 bytes
loom-buildersource

Preflight

import { readFileSync } from "node:fs"; import { globSync } from "glob"; import { resolve, relative } from "node:path"; …

TS183 lines6,119 bytes
loom-builder-solsource

Preflight

import { readFileSync } from "node:fs"; import { globSync } from "glob"; import { resolve, relative } from "node:path"; …

TS183 lines6,119 bytes
loom-sprint-scaffoldsource

Preflight

/** * H3.7 — Preflight: before any recoverable|destructive action, scan a provided * list of staged file contents for …

TS84 lines2,426 bytes
loom-buildersource

Preflight Cli

/** * Pre-flight CLI: estimate tokens for a spec and exit non-zero if too large. * Usage: bun run src/preflight-cli.ts…

TS42 lines1,436 bytes
loom-builder-solsource

Preflight Cli

/** * Pre-flight CLI: estimate tokens for a spec and exit non-zero if too large. * Usage: bun run src/preflight-cli.ts…

TS42 lines1,436 bytes
loom-buildertest

Preflight.Test

/** * Tests for token-cliff gate: pre-flight estimate, runtime ceiling, chain awareness. */ import { describe, test, e…

TS173 lines5,539 bytes
loom-builder-soltest

Preflight.Test

/** * Tests for token-cliff gate: pre-flight estimate, runtime ceiling, chain awareness. */ import { describe, test, e…

TS173 lines5,539 bytes
loom-sprint-scaffoldtest

Preflight.Test

/** * Tests for preflight (H3.7). * * Proves: * - clean files (no markers) pass * - every marker (TODO, FIXME, <<<<…

TS133 lines4,732 bytes
loom-sprint-scaffoldsource

Probe Planner

/** * H2.5 — Probe Planner. * * For stages with variety_class === "api_integration" AND no management-scope * behavi…

TS129 lines4,290 bytes
loom-sprint-scaffoldtest

Probe Planner.Test

/** * Tests for ProbePlanner (H2.5). * * Proves: * - api_integration + no behavior model → probe prepended (recovera…

TS197 lines7,246 bytes
pi-cyberneticsource

Procedural Store

/** Procedural memory — verified skills + working memory (active hypotheses). */ import type { ActiveHypothesis, Eviden…

TS78 lines2,391 bytes
loom-sprint-scaffoldsource

Promotion Engine

/** * H4.2 — Promotion Engine. * * episodic → semantic: when a pattern recurs across ≥ m_promote distinct traces. * …

TS198 lines6,260 bytes
loom-sprint-scaffoldtest

Promotion Engine.Test

/** * PromotionEngine tests (H4.2). * * Proves: * - Promotion fires at EXACTLY m_promote distinct traces (not m-1;…

TS212 lines9,720 bytes
loom-buildersource

Purpose

import type { DispatchSpec } from "./types.js"; export const PURPOSE_HEADER = "## PURPOSE (INVARIANT — restated verbati…

TS12 lines418 bytes
loom-builder-solsource

Purpose

import type { DispatchSpec } from "./types.js"; export const PURPOSE_HEADER = "## PURPOSE (INVARIANT — restated verbati…

TS12 lines418 bytes
loom-buildertest

Purpose.Test

import { describe, expect, test } from "bun:test"; import { injectPurpose, purposeBlock } from "./purpose.js"; describe…

TS21 lines824 bytes
loom-builder-soltest

Purpose.Test

import { describe, expect, test } from "bun:test"; import { injectPurpose, purposeBlock } from "./purpose.js"; describe…

TS21 lines824 bytes
codemode-gatewaysource

Registry

import { DynamicWorkerExecutor, type ResolvedProvider } from "@cloudflare/codemode"; import type { Env, ToolDef, T…

TS893 lines31,420 bytes
codemode-gatewaysource

Registry

import type { Env } from "./env"; /** * Tool registry types. The registry (`src/registry.ts`) is the single source * …

TS99 lines3,131 bytes
loom-sprint-scaffoldsource

Registry Seed

/** * Seed data for the mode_registry D1 table. * * Three modes covering the spec's default model set, with typed see…

TS146 lines4,376 bytes
loom-sprint-scaffoldsource

Registry Updater

/** * H5.3 — Registry Updater. * * Recomputes mode_registry success_n / fail_n / avg_cost_tokens per * (mode, variet…

TS153 lines4,797 bytes
loom-sprint-scaffoldtest

Registry Updater.Test

/** * Tests for H5.3 — Registry Updater. * * Proves: * - computeModeStats groups correctly by (model, harnessProfi…

TS208 lines7,132 bytes
loom-sprint-scaffoldsource

Reinjector

/** * H3.4 — Reinjector: normalize observations. Truncate to per-tool obs_cap_tokens * from the envelope; store full t…

TS98 lines2,802 bytes
loom-sprint-scaffoldtest

Reinjector.Test

/** * Tests for reinjector (H3.4). * * Proves: * - normalizeObservation truncates content exceeding obs_cap_tokens …

TS167 lines5,612 bytes
loom-sprint-scaffoldsource

Report

/** * Synthesis Report Assembler. * * Orchestrates all Loop 5 monitors (H5.1–H5.6) into a single SynthesisReport: * …

TS227 lines7,181 bytes
loom-sprint-scaffoldtest

Report.Test

/** * Integration test for the full synthesis report pipeline. * * Proves: * - Synthetic trace corpus → determinis…

TS184 lines6,142 bytes
loom-sprint-scaffoldtest

Research

/** * Golden goal: research — mid-goal failing stage drives fail_streak to m=3 → REFORMULATE → recovers → completes. *…

TS152 lines5,484 bytes
loom-sprint-scaffoldsource

Retry

import { RetryExhaustedError } from "../types/errors"; /** * Exponential backoff with FULL jitter (HC-6): delay = rand…

TS45 lines1,583 bytes
loom-sprint-scaffoldtest

Retry.Test

import { describe, expect, test } from "bun:test"; import { withRetry } from "../src/lib/retry"; import { RetryExhausted…

TS66 lines2,287 bytes
loom-sprint-scaffoldsource

Reversibility Gate

/** * H3.3 — Reversibility Gate: every tool call checked against the envelope * allowlist. Each allowlist entry has re…

TS136 lines3,886 bytes
loom-sprint-scaffoldtest

Reversibility Gate.Test

/** * Tests for reversibility-gate (H3.3). * * Proves: * - allowlist lookup accepts allowed tools and denies unknown…

TS203 lines6,855 bytes
loom-sprint-scaffoldsource

Revision Governor

/** * H5.5 — Revision Governor. * * Hard caps on skill proposals per window (tunable, default 5). * Tunable-paramete…

TS109 lines3,687 bytes
loom-sprint-scaffoldtest

Revision Governor.Test

/** * Tests for H5.5 — Revision Governor. * * Proves: * - Caps proposals at maxSkillProposals (default 5) * - N…

TS170 lines5,880 bytes
loom-buildersource

Run

/** * loom-builder — homeostatic dispatch harness. * Runs one DispatchSpec: agent loop (pi-coding-agent SDK) under har…

TS536 lines23,234 bytes
loom-builder-solsource

Run

/** * loom-builder — homeostatic dispatch harness. * Runs one DispatchSpec: agent loop (pi-coding-agent SDK) under har…

TS532 lines23,100 bytes
loom-sprint-scaffoldsource

Schema

import { sqliteTable, text, integer, index } from "drizzle-orm/sqlite-core"; /** * 7-table D1 schema — mirrors LOOM-SP…

TS108 lines3,990 bytes
loom-sprint-scaffoldsource

Scope Wall

/** * H4.3 — Scope Wall. * * All reads/writes carry a required scope. Default read path filters to the * caller's sc…

TS117 lines3,264 bytes
loom-sprint-scaffoldtest

Scope Wall.Test

/** * ScopeWall tests (H4.3). * * Proves: * - Same-scope read works (constructor requires scope) * - Cross-scop…

TS266 lines8,984 bytes
codemode-gatewaysource

Scrape

import type { Env } from "../types"; /** * `scrape` namespace tools — convenience persistence over the bound D1 * dat…

TS178 lines5,517 bytes
loom-sprint-scaffoldsource

Semantic Index

/** * H4.6 — SemanticIndex: search abstraction with two implementations. * * VectorizeIndex — wraps Cloudflare Vecto…

TS161 lines5,866 bytes
loom-sprint-scaffoldtest

Semantic Index.Test

/** * SemanticIndex contract test suite. * * Shared tests run against BOTH Fts5Index (with fake D1/SQLite) and * Vec…

TS238 lines9,598 bytes
pi-cyberneticsource

Semantic Store

/** Semantic memory — compressed summaries + entity-relation tuples, with promotion. */ import type { CompressedSummary…

TS51 lines1,626 bytes
loom-sprint-scaffoldsource

Skill Proposer

/** * H5.2 — Skill Proposer. * * Detects recurring successful sub-sequences across ≥ N distinct goals * (tunable, de…

TS239 lines7,685 bytes
loom-sprint-scaffoldtest

Skill Proposer.Test

/** * Tests for H5.2 — Skill Proposer. * * Proves: * - extractSuccessfulSequences groups tool calls by dispatch *…

TS206 lines7,692 bytes
codemode-gatewaysource

Snippet

/** * Snippet store types. A snippet is a saved, named sandbox script — the * gateway's "procedural memory". Stored as…

TS37 lines1,245 bytes
loom-buildersource

Spec Lint

/** * Spec-schema lint — validates DispatchSpec at preflight before dispatch. * * Checks: * - Unknown top-level keys…

TS234 lines7,585 bytes
loom-builder-solsource

Spec Lint

/** * Spec-schema lint — validates DispatchSpec at preflight before dispatch. * * Checks: * - Unknown top-level keys…

TS234 lines7,585 bytes
codemode-gatewaysource

Store

import { normalizeCode } from "@cloudflare/codemode"; import type { Env, Snippet, SnippetSummary } from "../types"; /**…

TS137 lines4,804 bytes
pi-cyberneticsource

Strategic

/** * Loop 1 — StrategicEngine. Homeostatic regulator over Ω_goal (P3, P5). * * pi-agent-core 0.79 exposes `shouldSto…

TS387 lines13,868 bytes
pi-cybernetictest

Strategic.Test

import { describe, expect, test } from "bun:test"; import type { AgentMessage } from "@earendil-works/pi-agent-core"; im…

TS174 lines7,912 bytes
loom-sprint-scaffoldsource

Synthesis

/** * Loop 5 synthesis types — report shapes, interfaces, contract-style types. * * All Loop 5 outputs are typed here…

TS177 lines5,430 bytes
loom-sprint-scaffoldsource

Token Mint

/** * H1.5 — HMAC single-use, stage-scoped, TTL'd approval tokens for destructive * actions. WebCrypto only. * * Tok…

TS208 lines6,815 bytes
loom-sprint-scaffoldtest

Token Mint.Test

/** * Tests for TokenMint (H1.5). * * Proves: * - mint → Loop 3 verify passes (round-trip) * - expired tokens fail …

TS180 lines5,795 bytes
pi-cyberneticsource

Tool Registry

/** Loop 2 — variety + reversibility registries (P2, P4). */ export type Reversibility = "read" | "recoverable" | "dest…

TS50 lines1,294 bytes
codemode-gatewaysource

Tools

import type { CfEnvelope, CfError, D1Database, Env, KvNamespace } from "../types"; import { CloudflareApiError } from ".…

TS187 lines6,099 bytes
loom-buildersource

Trace

import { appendFileSync, mkdirSync } from "node:fs"; import { dirname } from "node:path"; import type { TraceEvent } fro…

TS20 lines806 bytes
loom-builder-solsource

Trace

import { appendFileSync, mkdirSync } from "node:fs"; import { dirname } from "node:path"; import type { TraceEvent } fro…

TS20 lines806 bytes
loom-buildersource

Types

/** Contract types for loom-builder dispatches. */ export interface ModelRef { provider: string; id: string; } exp…

TS186 lines6,050 bytes
loom-builder-solsource

Types

/** Contract types for loom-builder dispatches. */ export interface ModelRef { provider: string; id: string; } exp…

TS186 lines6,050 bytes
loom-sprint-scaffoldsource

Types

/** * Injectable interfaces for the Loop 2 dispatcher core. * * Every dependency is an interface so tests inject fake…

TS100 lines3,297 bytes
loom-sprint-scaffoldsource

Types

/** * Injectable interfaces for LOOM Loop 1 orchestration core. * Every dependency is an interface so tests can inject…

TS101 lines3,889 bytes
pi-cyberneticsource

Util

/** Deterministic shared helpers — no LLM reasoning, no randomness beyond ids. */ let idCounter = 0; export function n…

TS99 lines3,339 bytes
codemode-gatewaysource

Util

/** * Implementations for the `util` namespace: `util.echo(x)`, `util.now()`, * `util.rand()`. Contains only trivial, …

TS25 lines1,065 bytes
loom-sprint-scaffoldsource

Validate

import { Ajv, type ValidateFunction } from "ajv"; import addFormats from "ajv-formats"; import { ContractViolationError …

TS67 lines2,858 bytes