AI & Systems
Mar 2026·8 min read

Local-First Context Engineering: How NodeNet, LCDD, and Iritoken Cut AI Agent Token Waste by 79%

A deep dive into managing agent blast radius, AST-ranked context budgeting, version-governed specification contracts with LCDD, and replay-safe telemetry.

LEP
Lelianto Eko PradanaAI & Full Stack Engineer · Indonesia

#Introduction

Autonomous coding agents (Cline, Roo, Cursor, OpenCraft, Claude Code) are fundamentally limited by context quality, not model size. Dumping whole repositories or naive fuzzy-search dumps into an LLM context window causes three acute failure modes:

  1. Context Rot: The model loses focus on the core task as irrelevant files dilute attention.
  2. Economic Waste: Sending 30,000+ tokens on every turn quickly multiplies API costs into hundreds of dollars per day.
  3. Architectural Drift: Agents make localized syntax fixes that silently violate team invariants (e.g. leaking secrets, skipping CSRF checks, or breaking SSR hydration).

To solve this, I designed a local-first engineering pipeline composed of three specialized open-source tools: NodeNet, LCDD, and Iritoken, observed by AgentifAI and audited by ai.log.


#1. Mapping Blast Radius Before Agent Execution (NodeNet)

Rather than letting an agent blind-search files with grep, NodeNet builds an explainable local dependency graph by parsing Abstract Syntax Trees (ASTs) of TypeScript and JavaScript projects.

When an agent is assigned a task (e.g. updating portfolio-client.tsx), NodeNet calculates the shortest path and blast radius:

code
[ Modified Target: portfolio-client.tsx ]
   ├── Direct Dependents: app/page.tsx, app/archive/page.tsx
   ├── Core Dependency: app/firebase.ts (Security Boundary)
   └── Blast Radius: LOW · Required Reviewer: @lelianto

By exposing this structural intelligence via the Model Context Protocol (MCP), the agent immediately understands what *cannot* be broken and which files actually matter.


#2. Enforcing Living System Contracts (LCDD)

Documentation in wikis or README files decays the moment code changes. Living Context-Driven Development (LCDD) treats specifications as executable YAML contracts placed directly in .lcdd/contracts/:

yaml
# .lcdd/contracts/security.yaml
name: privacy.anonymous-telemetry-sha256
invariants:
  - id: zero-raw-ip-storage
    rule: "No visitor IP or raw identifier may be written to Firestore."
    enforcement: static-ast-check
  - id: sha256-hash-salt
    rule: "Visitor IDs must be hashed with crypto.subtle.digest('SHA-256')."

Before the agent proposes a git commit or writes a file, npx @lcdd/cli validate --strict verifies that no invariants have been breached. If an agent tries to log raw session credentials, the operation is blocked pre-commit with clear remediation steps.


#3. Deterministic Token Pruning & Semantic Caching (Iritoken)

Once NodeNet identifies relevant files and LCDD supplies the architectural contracts, Iritoken assembles the final prompt payload:

  1. Symbol Skeletonization: Implementation bodies of secondary files are stripped, preserving only typed interfaces and exported function signatures.
  2. Stable Prefix Ordering: Contracts and static types are ordered first to maximize LLM KV-cache hits (up to 94.6% cache reuse across iterative turns).
  3. Hard Budget Bounds: The payload is deterministically packed to fit within user-specified limits (e.g. 6,000 tokens).
typescript
import { assembleContextBudget } from "iritoken";

const context = await assembleContextBudget({
  targetTokens: 6000,
  seedFiles: ["app/portfolio-client.tsx"],
  strategy: "ast-rank",
  contracts: ["specs/security.lcdd.yaml"],
});

console.log(context.stats);
// => { rawTokens: 28450, budgetTokens: 5860, reduction: "79.4%", cacheHits: 4 }

#4. Replay-Safe Observability (AgentifAI + ai.log)

Every tool call and LLM round-trip emits OpenTelemetry spans via AgentifAI: - Tracking token consumption per tool execution. - Measuring sub-second latency across local MCP servers. - Enabling deterministic replay: if an agent fails on step 4, developers can replay from step 3 locally without re-paying the API provider for steps 1 and 2.

Meanwhile, ai.log maintains an append-only JSONL ledger on the developer's local machine, attesting which files were read, which commands were executed, and verifying hash integrity with SHA-256.


#5. Architectural Takeaways

  • Never rely on the model for code geography: Use AST static analysis to guide agent attention.
  • Context is code: Version, test, and enforce your architectural contracts in CI.
  • Local-first keeps control: Developer credentials and source code stay on-device, only compacted task context reaches the LLM.