Sheet index — the whole set

  1. 00Home首页
  2. 01About关于
    1. 01 About me
    2. 01.1 Hobbies
  3. 02Projects项目
    1. 02 All projects
    2. 02.1 The 3D studio
    3. 02.2 ZERO CORE
    4. 02.3 i-Share
    5. 02.4 MV pipeline
    6. 02.5 Cleaning System
  4. 03MV worksMV 作品
    1. 03 Music videos
    2. 03.1 Arcade
  5. 04Workshop工坊
    1. 04.1 Studio
    2. 04.2 Tools
  6. 05Resume简历
  7. 06Contact联系
EN 中
Enter the room

02.2 — projects — zero-core

02.2Case file/projects/zero-core/

rev.
976ae73
date
2026-11-21

sheet 02 of 06

ZERO CORE

The private hub behind my AI agent workflow

role
Solo
context
A private hub that keeps the rules my Claude Code sessions follow
scope
Rules, tests and a review agent around my own work
result
95 problems raised in its first 41 reviews · 130 tests

Dependencies

  • Cloudflare Workers
  • D1
  • Access
  • TypeScript
  • Claude API
  • Claude Code hooks

Changelog

  • the rules my Claude Code sessions follow live in one place and are handed to every session
  • an independent review agent reads the change report when the work is done
  • 130 automated tests, run before every deploy
FIG 01 How it works, in 3D and on the real panel: a rule's round trip from the hook to the review agent and back, told by Zero. The panel shows demo data.
01

The problem

I work with Claude Code every day. I want its sessions to follow the same rules every time, and I want to see what they did. A rule that lives only in my head, or in one file I forget to update, reaches only the sessions I remember to mention it to.

02

The design

Four parts, drawn in FIG 02.

AccessClaude Codesessionhook(on my PC)Cloudflare Workerbehind AccessD1databasereview agent(fresh context)panel · 8 regions+ Zeroinject rulesstop a breachsync usagefile reportsETag · 304rulesproposalsreportsusageto-dosproposalsevery diffapprove →next session's rules123456
  1. Claude Code session — where I work; when it learns something it proposes a rule change.
  2. Hook, on my PC — four jobs: inject the rules that apply at the start (within a size budget); stop a tool call that breaks a hard rule; sync usage; file a change report after each change.
  3. Cloudflare Worker, behind Access — the service the hook and the panel talk to.
  4. D1 — keeps the rules, proposals, reports, usage and to-dos.
  5. Review agent — reads the diff of every change report in a fresh context.
  6. Panel — eight regions, and Zero, a read-only assistant. I approve proposals here; an approved one becomes the next session's rules.
FIG 02 How the parts talk. The blue line is the data path; the dashed line is the loop that turns an approval into the next session's rules.

A hook on my PC. A Claude Code hook runs inside every session. At the start it injects the rules that apply, within a size budget so they never crowd out the work. During the session it stops a tool call that breaks a hard rule, such as committing a secret or adding a tracking script. It syncs usage, and after each change it files a change report.

A Worker and a database. A Cloudflare Worker with a D1 database, behind Cloudflare Access, keeps the rules, proposals, reports, usage and to-dos. The diff in every change report goes to a review agent that starts in a fresh context, so it has not seen the thinking that produced the change.

Back to me. When Claude learns something, it proposes a rule change. I approve it in the panel, and an approved proposal becomes part of the rules the next session is given. The panel has eight regions and a read-only assistant, Zero, that answers questions about the rules and cannot change them.

The panel's home with every text replaced by grey bars: a row of region tabs along the top, then a sheet of paper with groups of rows that are waiting.
FIG 03 The home: an inbox of what waits for me. Text replaced by bars; the data is private.
The panel's rule search with every text replaced by grey bars.
FIG 04 Rule search. Text replaced by bars; the data is private.
The panel's talk panel for the assistant with every text replaced by grey bars.
FIG 05 The assistant's talk panel. Text replaced by bars; the data is private.
03

The code

Four short pieces quoted from its source, cut with // … where I left lines out. The file is named above each.

hook/handlers.ts
export async function preToolUse(input: HookInput, deps: Deps): Promise<HookOutput> {  const cache = await deps.readCache();  if (!cache || !input.tool_name) return {};  const snap = cache.snapshot;  const call = { tool: input.tool_name, input: input.tool_input ?? {} };  const verdict = evaluate(activeGuards(snap, input.cwd), call);  // …  const deny: { g: ActiveGuard; detail: string }[] = verdict.deny.map((g) => ({ g, detail: '' }));  // …  const at = now();  if (deny.length) {    const first = deny[0]!;    // …    return {      hookSpecificOutput: {        hookEventName: 'PreToolUse',        permissionDecision: 'deny',        permissionDecisionReason: `Blocked by the owner's hard rule in ZERO CORE: ${describe(first.g)}.${first.detail} Do not try another way around it; tell the owner what you were about to do and ask.`,      },      systemMessage: `ZERO CORE blocked ${input.tool_name}: ${first.g.rule.text}${first.detail}`,    };  }  // …}
FIG 06 The hook's guard. Before a tool call runs it is checked against my hard rules; on a breach the hook records the block and denies the call, and tells the session not to look for another way round.
worker/api.ts
/** The answer with an ETag (a hash of its body): a request that already holds exactly this gets 304 and no body.    Cache-Control stays no-store (index.ts), so nothing along the way keeps it; the panel itself remembers the tag. */export async function etagged(req: Request, data: unknown): Promise<Response> {  const text = JSON.stringify(data);  const sum = new Uint8Array(await crypto.subtle.digest('SHA-1', new TextEncoder().encode(text)));  const tag = `"${[...sum].map((x) => x.toString(16).padStart(2, '0')).join('')}"`;  const held = req.headers.get('If-None-Match');  if (held && held.split(',').some((t) => t.trim().replace(/^W\//, '') === tag)) return new Response(null, { status: 304, headers: { ETag: tag } });  return new Response(text, { headers: { 'Content-Type': 'application/json; charset=utf-8', ETag: tag } });}
FIG 07 The panel's state answer carries an ETag, a hash of its body, so a poll that already holds it gets a 304 and no body. This is the 122 KB to 0.3 KB.
shared/pet-stream.ts
export type PetEvent =  | { t: 'start'; id: number }  | { t: 'tool'; name: string }  | { t: 'text'; d: string }  | { t: 'ping' }  | { t: 'done'; reply: PetTalkReply | PetDeeperReply }  | { t: 'error'; message: string };// …/** One event as a line. */export const encodeEvent = (ev: PetEvent): string => `${JSON.stringify(ev)}\n`;// …export function parseEvent(line: string): PetEvent | null {  let v: unknown;  try { v = JSON.parse(line); } catch { return null; }  if (!v || typeof v !== 'object') return null;  const o = v as Record<string, unknown>;  switch (o.t) {    case 'start': return typeof o.id === 'number' ? { t: 'start', id: o.id } : null;    case 'tool': return typeof o.name === 'string' ? { t: 'tool', name: o.name } : null;    case 'text': return typeof o.d === 'string' ? { t: 'text', d: o.d } : null;    case 'ping': return { t: 'ping' };    case 'done': return o.reply && typeof o.reply === 'object' ? { t: 'done', reply: o.reply as PetTalkReply | PetDeeperReply } : null;    case 'error': return { t: 'error', message: typeof o.message === 'string' ? o.message : 'something went wrong on the server' };    default: return null;  }}
FIG 08 The talk's event protocol: the Worker writes one JSON object per line, and the parser skips any type it does not know, so a newer Worker can add events without breaking an older panel.
worker/reports.ts
/** The review: the diff zc sends is read by a fresh-context reviewer and dropped; the verdict is kept. zc may    instead say why it sends none (`skip`). A report already reviewed is not reviewed again. */export async function reviewReport(env: Env, id: string, b: Body): Promise<{ verdict: Verdict; review: Review | null; note: string | null }> {  const db = env.DB;  const row = await db.prepare('SELECT * FROM reports WHERE id = ?').bind(id).first<Record<string, unknown>>();  if (!row) throw new HttpError(404, 'no such report');  const r = reportRow(row);  if (r.verdict !== 'pending' && r.verdict !== 'skipped') return { verdict: r.verdict, review: r.review, note: r.review_note };  const skip = text(b, 'skip', 300);  const diff = typeof b.diff === 'string' ? b.diff : '';  if (diff.length > DIFF_LIMIT + 4000) bad(`diff: at most ${DIFF_LIMIT} characters (zc cuts it down)`);  let verdict: Verdict = 'skipped';  let review: Review | null = null;  let note: string | null = skip;  let model: string | null = null;  let usage: { input_tokens: number; output_tokens: number } | null = null;  if (!skip) {    if (!diff.trim()) note = 'no changes to read';    else {      const out = await reviewDiff(env, { title: r.title, points: r.points, files: r.files }, diff);      if ('error' in out) note = `not reviewed: ${out.error}`;      else { verdict = out.verdict; review = out.review; note = null; model = REVIEW_MODEL; usage = out.usage; }    }  }  // …  return { verdict, review, note };}
FIG 09 How a change report reaches the reviewer: the diff arrives with the report, is read in a fresh context and dropped, and only the verdict is kept. A report already reviewed is not reviewed twice.
04

What the review agent caught

Of the first 45 change reports filed, from 29 October to 2 November 2026, the review agent read 41 (4 were skipped) and raised 95 problems or concerns. I did not track how many of them I fixed, so I give no number for that. Three it found, and what I changed:

  • The 30-second refresh pulled a scrolled block index back to the open block on every redraw. The open block is now brought into view only when it changes.
  • Re-sending a session's usage without a title wiped the title already stored. A row sent again now keeps the stored title.
  • After a failed save of a hard rule, Retry re-armed the confirmation instead of saving. A retried save now saves.
05

How it is tested

130 unit tests, run with node --test. On 3 Nov 2026, when I wrote this, npm test printed 130 passing and 0 failing. Each change report's diff is also sent to a review agent that reads it in a fresh context.

06

Numbers

  • 122 KB → 0.3 KB for an unchanged 30-second poll, by answering with an ETag and a 304 instead of the whole response
  • 130 tests, 8 panel regions