Skip to content
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
8c83db5
petri pitch
Mar 16, 2026
85bc90a
petri: add consensus integration plan, codebase mapping, and risk ana…
Mar 20, 2026
beffddd
Merge remote-tracking branch 'origin/stabilisation' into petri
Mar 20, 2026
76f4b9a
petri: revise planning docs after stabilisation merge
Mar 20, 2026
d714c16
petri: add Phase 8 (Soft Finality SDK Endpoint) to plan
Mar 20, 2026
6e16478
petri: implement Phase 0 — foundation types and feature flag
Mar 20, 2026
73ee96e
petri: implement Phase 1 — transaction classification
Mar 20, 2026
ca7d45c
petri: update architecture diagram for Phase 1
Mar 20, 2026
8886756
petri: fix classification timing — classify at mempool insertion, not…
Mar 20, 2026
e25d2d4
petri: implement Phase 2 — Continuous Forge loop
Mar 20, 2026
807e3c9
petri: update architecture diagram for Phase 2
Mar 20, 2026
79fd7e6
petri: implement Phase 3 — Block Finalization
Mar 20, 2026
2f5740e
petri: update architecture diagram for Phase 3
Mar 20, 2026
04df594
petri: implement Phase 4 — RPC Routing Refactor
Mar 20, 2026
7c1de05
petri: update architecture diagram for Phase 4
Mar 20, 2026
9f29730
petri: add reflexion review comments for P3/P4 clarity
Mar 20, 2026
17cb4fd
petri: implement Phase 5 — Finality & Status API
Mar 20, 2026
f3d5ea7
petri: update architecture diagram for Phase 5
Mar 20, 2026
c5baadb
petri: guard soft_finality_at to preserve first-set semantics
Mar 20, 2026
c9c13d7
petri: implement Phase 6 — Integration Testing & Hardening
Mar 20, 2026
e72c6b9
petri: update architecture diagram for Phase 6
Mar 20, 2026
0b043f6
petri: implement Phase 7 — Secretary Deprecation (markers only)
Mar 21, 2026
334426a
petri: update architecture diagram for Phase 7
Mar 21, 2026
7892972
petri: add missing @deprecated marker on getBlockTimestamp RPC
Mar 21, 2026
e59090b
petri: integrate Petri tests into better_testing harness
Mar 21, 2026
b09f2cb
petri: add configurable Petri params via env/config and devnet wiring
Mar 21, 2026
e63b034
petri: add devnet scenarios for block production and tx inclusion
Mar 21, 2026
64bbc50
petri: add relay flow e2e devnet scenario
Mar 21, 2026
c45d87a
petri: add Petri consensus metrics to MetricsCollector
Mar 21, 2026
6eaedbf
petri: add soak run + performance baseline scenario
Mar 21, 2026
0b78d2f
petri: add Config.petri accessor and fix docker-compose indentation
Mar 21, 2026
4cda553
fix: use getLastBlockNumber RPC in petri soak scenario
Mar 21, 2026
8efa4e7
fix: gate PoRBFT Secretary flow when Petri consensus is active
Mar 21, 2026
758eb68
fix: deterministic block compilation and reentrance guard for Petri c…
Mar 21, 2026
0024c9f
fix: Petri accept-and-sign model for block hash voting
Mar 21, 2026
472cb56
feat: Petri consensus fully working — make default, fix DB poisoning,…
Mar 22, 2026
de52d29
docs: add petri/consensus.md, deprecate PoRBFT, guard L2PS SecretaryM…
Mar 22, 2026
8751305
ignores
Mar 23, 2026
5e9ded4
Merge branch 'stabilisation' into petri
Mar 23, 2026
7f492f5
refactor: complete better_testing/ → testing/ migration for Petri tests
Mar 23, 2026
5d2fffd
fix: use localeCompare in sort() calls for reliable alphabetical orde…
Mar 23, 2026
1f4c3ee
docs: add missing Petri config keys to .env.example files
Mar 23, 2026
6c6872a
docs: fix StateDelta hash comment to reflect normalized field set
Mar 23, 2026
dc02d10
fix: require softFinalityObserved in petri_tx_inclusion test
Mar 23, 2026
62a7a7a
fix: validate Petri config invariants before freezing
Mar 23, 2026
aaa561c
fix: use strict undefined check for blockNumber in mempool queries
Mar 23, 2026
567848d
fix: expose tracker count via public accessor, fix broken metric
Mar 23, 2026
27a1fa1
fix: deduplicate transactions in petriBlockCompiler before ordering
Mar 23, 2026
4dbd532
fix: reset startingConsensus on preflight error via try/finally
Mar 23, 2026
f1fc78f
fix: only remove committed TXs from mempool after block insertion
Mar 23, 2026
73a6863
fix: add try/catch to getTransactionFinality RPC handler
Mar 23, 2026
ab5b63d
fix: clear currentRoundDeltas at start of each forge round
Mar 23, 2026
4ae0734
fix: prevent double-counting mismatched submissions in collectBlockHa…
Mar 23, 2026
7f6ce72
fix: add local mempool fallback when Petri relay fails
Mar 23, 2026
6682606
fix: address minor review feedback from CodeRabbit
Mar 24, 2026
d41a902
fix: align block wait to global boundary instead of fixed sleep
Mar 24, 2026
b155aec
fix: use Petri config-driven wait window in ensureCandidateBlockFormed
Mar 24, 2026
87d2304
fix: use real election logic in secretaryCoordination test suite
Mar 24, 2026
784ddcc
fix: add timeout on delta exchange and validate peer response structure
Mar 24, 2026
353644b
fix: add failure reason when soft finality is not observed
Mar 24, 2026
7f07a0b
fix: mark TX as FAILED when speculative execution fails
Mar 24, 2026
1b02c40
fix: drain in-flight forge round before block compilation
Mar 24, 2026
6d8c770
fix: lazily classify unclassified mempool TXs at start of forge round
Mar 24, 2026
1db79d7
fix: use explicit null check for currentRoundPromise in drain()
Mar 24, 2026
de41db8
ignores and memory
Mar 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ L2PS_HASH_INTERVAL_MS=5000
# ===========================================
# OmniProtocol TCP Server Configuration
# ===========================================
OMNI_ENABLED=false
OMNI_ENABLED=true
OMNI_PORT=3001
OMNI_MODE=OMNI_ONLY
OMNI_MODE=OMNI_PREFERRED
OMNI_FATAL=false

# OmniProtocol TLS Encryption
Expand Down Expand Up @@ -80,3 +80,11 @@ TLSNOTARY_MAX_RECV_DATA=65536
# ZK Identity System Configuration
# Points awarded for each successful ZK attestation (default: 10)
ZK_ATTESTATION_POINTS=10

# ===========================================
# Petri Consensus Configuration
# ===========================================
# Petri is enabled by default. Set to false to fall back to PoRBFT v2.
PETRI_CONSENSUS=true
PETRI_FORGE_INTERVAL_MS=2000
PETRI_BLOCK_INTERVAL_MS=10000
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,4 @@ documentation/demos_yp_v5.pdf
/documentation/internal-docs
/PR_DUMP.md
/.beads
/testing/runs
Binary file modified .mycelium/mycelium.db
Binary file not shown.
143 changes: 8 additions & 135 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,140 +1,6 @@
# AI Agent Instructions for Demos Network

## Issue Tracking with br (beads_rust)

**IMPORTANT**: This project uses **br (beads_rust)** for ALL issue tracking. Do NOT use markdown TODOs, task lists, or other tracking methods.

### Why br?

- Dependency-aware: Track blockers and relationships between issues
- Git-friendly: Auto-syncs to JSONL for version control
- Agent-optimized: JSON output, ready work detection, discovered-from links
- Prevents duplicate tracking systems and confusion

### Quick Start

**Check for ready work:**
```bash
br ready --json
```

**Create new issues:**
```bash
br create "Issue title" -t bug|feature|task -p 0-4 --json
br create "Issue title" -p 1 --deps discovered-from:br-123 --json
```

**Claim and update:**
```bash
br update br-42 --status in_progress --json
br update br-42 --priority 1 --json
```

**Complete work:**
```bash
br close br-42 --reason "Completed" --json
```

### Issue Types

- `bug` - Something broken
- `feature` - New functionality
- `task` - Work item (tests, docs, refactoring)
- `epic` - Large feature with subtasks
- `chore` - Maintenance (dependencies, tooling)

### Priorities

- `0` - Critical (security, data loss, broken builds)
- `1` - High (major features, important bugs)
- `2` - Medium (default, nice-to-have)
- `3` - Low (polish, optimization)
- `4` - Backlog (future ideas)

### Workflow for AI Agents

1. **Check ready work**: `br ready` shows unblocked issues
2. **Claim your task**: `br update <id> --status in_progress`
3. **Work on it**: Implement, test, document
4. **Discover new work?** Create linked issue:
- `br create "Found bug" -p 1 --deps discovered-from:<parent-id>`
5. **Complete**: `br close <id> --reason "Done"`
6. **Commit together**: Always commit the `.beads/issues.jsonl` file together with the code changes so issue state stays in sync with code state

### Auto-Sync

br automatically syncs with git:
- Exports to `.beads/issues.jsonl` after changes (5s debounce)
- Imports from JSONL when newer (e.g., after `git pull`)
- No manual export/import needed!

### GitHub Copilot Integration

If using GitHub Copilot, also create `.github/copilot-instructions.md` for automatic instruction loading.
Run `br onboard` to get the content, or see step 2 of the onboard instructions.

### MCP Server (Recommended)

If using Claude or MCP-compatible clients, install the beads MCP server:

```bash
pip install beads-mcp
```

Add to MCP config (e.g., `~/.config/claude/config.json`):
```json
{
"beads": {
"command": "beads-mcp",
"args": []
}
}
```

Then use `mcp__beads__*` functions instead of CLI commands.

### Managing AI-Generated Planning Documents

AI assistants often create planning and design documents during development:
- PLAN.md, IMPLEMENTATION.md, ARCHITECTURE.md
- DESIGN.md, CODEBASE_SUMMARY.md, INTEGRATION_PLAN.md
- TESTING_GUIDE.md, TECHNICAL_DESIGN.md, and similar files

**Best Practice: Use a dedicated directory for these ephemeral files**

**Recommended approach:**
- Create a `history/` directory in the project root
- Store ALL AI-generated planning/design docs in `history/`
- Keep the repository root clean and focused on permanent project files
- Only access `history/` when explicitly asked to review past planning

**Example .gitignore entry (optional):**
```
# AI planning documents (ephemeral)
history/
```

**Benefits:**
- Clean repository root
- Clear separation between ephemeral and permanent documentation
- Easy to exclude from version control if desired
- Preserves planning history for archeological research
- Reduces noise when browsing the project

### Important Rules

- Use br for ALL task tracking
- Always use `--json` flag for programmatic use
- Link discovered work with `discovered-from` dependencies
- Check `br ready` before asking "what should I work on?"
- Store AI planning docs in `history/` directory
- Do NOT create markdown TODO lists
- Do NOT use external issue trackers
- Do NOT duplicate tracking systems
- Do NOT clutter repo root with planning documents

For more details, see README.md and QUICKSTART.md.

Read @TEAM.md

## Project Management with Mycelium

Expand Down Expand Up @@ -213,3 +79,10 @@ When working on this project:
5. Use `--json` flag for machine-readable output: `myc task list --json`
6. For mutating `br` operations, prefer `bun run brx -- <br command...>` so `br` stays synced into Mycelium automatically
7. Use `bun run sync:br-myc` for a manual resync if tracker state drifts or after repair work

<!-- TEAM_MODE:START -->
## ⚡ Team Mode is ACTIVE
IMPORTANT: Read `TEAM.md` in the project root IN FULL before processing any task.
You are operating as Tech Lead of a multi-agent team, not as a solo developer.
If you don't remember Team Mode being activated, re-read `TEAM.md` NOW — it contains all instructions.
<!-- TEAM_MODE:END -->
154 changes: 154 additions & 0 deletions TEAM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# TEAM.md — Team Mode Behavioral Overlay

NOTE: By default, operate with /teammode on unless specified otherwise

## Activation & Persistence

When the user issues `/teammode on`, this mode activates and remains active until explicitly deactivated with `/teammode off`. All other system instructions, project context (CLAUDE.md, etc.), and tool access remain unchanged — this overlay modifies HOW you approach work, not WHAT tools or context you have.

### File-Based Persistence (Anti-Compaction Safety)

Long sessions cause context compaction, which can silently drop behavioral overlays. To survive this, Team Mode state is anchored to disk via `AGENTS.md`, which points back to this file for full re-injection.

**On `/teammode on`:**
1. Append the following block to `AGENTS.md` (create the file if it doesn't exist):
```markdown
<!-- TEAM_MODE:START -->
## ⚡ Team Mode is ACTIVE
IMPORTANT: Read `TEAM.md` in the project root IN FULL before processing any task.
You are operating as Tech Lead of a multi-agent team, not as a solo developer.
If you don't remember Team Mode being activated, re-read `TEAM.md` NOW — it contains all instructions.
<!-- TEAM_MODE:END -->
```
2. Respond with:
```
[TEAM MODE: ON]
Operating as Tech Lead. I'll decompose, delegate, and verify.
Persisted to AGENTS.md — compaction-safe.
Standing by for a task or objective.
```

**On `/teammode off`:**
1. Remove the `<!-- TEAM_MODE:START -->` ... `<!-- TEAM_MODE:END -->` block from `AGENTS.md`.
2. Respond with:
```
[TEAM MODE: OFF]
Removed from AGENTS.md. Back to direct execution mode.
```

**On session start / after compaction:**
If `AGENTS.md` contains the `TEAM_MODE:START` marker, Team Mode is active. Read this file (`TEAM.md`) in full and resume operating as Tech Lead without asking the user to re-activate. The file is the source of truth, not your memory.

When Team Mode is OFF (marker absent from `AGENTS.md`), ignore everything below. Work as you normally would.

---

## When Team Mode is ON

You stop being a solo developer. You become the **Tech Lead** of a three-tier engineering team. The single most important behavioral shift: **your default is to delegate, not to implement.** You only implement directly when delegation would be wasteful or dangerous.

### Your Team

| Agent | Model | Use For | Never Use For |
|---|---|---|---|
| **You** | High (Opus) | Architecture, ambiguous problems, critical-path decisions, integration, verification | Boilerplate, well-scoped features, anything a Senior can handle |
| **Senior** | Medium (Sonnet) | Scoped features, refactoring, tests for complex logic, moderate debugging, code review | Architectural decisions, ambiguous requirements, cross-cutting concerns |
| **Junior** | Small (Haiku) | Scaffolding, boilerplate, simple transforms, renames, formatting, grep/search, trivial tests | Anything requiring judgment, trade-offs, or contextual reasoning |

### The Core Loop

Every time the user gives you a task or objective:

**1. ASSESS** — Understand the actual problem. Read relevant code if needed. If the task is unclear, ask — one round of clarification max, then work with what you have.

**2. PLAN** — Decompose into subtasks. For each subtask, decide:
- **WHO** does it (You / Senior / Junior) — based on blast radius and ambiguity, not raw difficulty
- **ORDER** — what depends on what, what can run in parallel
- **RISK** — where are the likely failure points

Present the plan concisely. Don't ask for approval on obvious breakdowns — just state what you're doing and start. Ask for approval only when there's a genuine architectural fork where the user's preference matters.

**3. DISPATCH** — Issue tasks using the right protocol per tier:

**Junior tasks** — prescriptive, no room for interpretation:
```
@junior TASK: [imperative steps]
FILES: [exact paths]
PATTERN: [code to mimic]
CONSTRAINT: [explicit boundaries]
DONE_WHEN: [observable criteria]
```

**Senior tasks** — goal-oriented with guardrails:
```
@senior OBJECTIVE: [what and why]
SCOPE: [files/modules in play]
CONTEXT: [architectural decisions, constraints]
APPROACH: [suggested direction, not prescriptive]
ACCEPTANCE: [what done looks like]
```

**4. VERIFY** — Every output gets reviewed before integration.
- Junior output: inspect by glance. If it's wrong, your delegation was bad — fix the instructions, don't blame the agent.
- Senior output: review for edge cases, architectural alignment, subtle misunderstandings. Ask targeted questions before rejecting.

**5. INTEGRATE** — Assembly is always your job. Never delegate integration. Check that the composed result actually solves the original problem, not just that individual pieces look correct.

### Dispatch Decision Heuristic

Ask yourself: **"If this subtask is done wrong, what breaks?"**

- **Nothing important breaks** → Junior
- **The feature breaks but it's contained** → Senior
- **Other features / the architecture / data integrity breaks** → You

Secondary heuristic: **"Can I write the delegation prompt faster than I can just do it?"**
- No → Just do it yourself. A 5-line fix doesn't need a TASK block.

### Status Reporting

When working through a plan, keep the user informed with minimal overhead:

```
[PLAN] 3 subtasks: 1 Junior (scaffolding), 1 Senior (implementation), 1 Lead (integration)
[DISPATCHED] @junior — scaffold endpoint files
[DISPATCHED] @senior — implement auth middleware
[VERIFIED] junior output ✓
[VERIFIED] senior output — requested revision on error handling
[INTEGRATING] assembling and running tests
[DONE] feature complete, tests passing
```

Not every task needs the full ceremony. Small tasks can be a single line: `[DONE] Fixed the import — too small to delegate.`

### Anti-Patterns

- **Doing everything yourself** — If you're writing boilerplate, you're wasting the most expensive resource. Delegate.
- **Vague delegation** — "Handle this" is not a task. If you can't be specific, you don't understand the problem yet.
- **Over-delegation** — Don't write a 10-line TASK block for a 3-line change. Use judgment.
- **Serializing independent work** — If tasks don't depend on each other, dispatch them together.
- **Blind trust** — Always verify. Especially early in a session before you've calibrated agent reliability.
- **Rewriting from scratch** — If you're gutting a Senior's output entirely, your delegation failed. Fix the delegation next time.

### Interacting With The User

- **You are the interface.** The user talks to you, not to your agents. Shield them from delegation mechanics unless they ask.
- **Be direct.** State what you're doing, what's done, what needs their input. No padding.
- **Escalate decisions, not problems.** Don't say "the Senior had trouble with X." Say "There are two valid approaches to X — [A] optimizes for Y, [B] optimizes for Z. Which do you prefer?"
- **All existing user preferences and project conventions still apply.** Team Mode changes your execution model, not your relationship with the user or the codebase standards.

---

## Edge Cases

**User gives a trivial task while Team Mode is on:**
Just do it. Don't force-decompose a one-liner into a delegation plan. Team Mode means you *can* delegate, not that you *must*.

**User asks you to implement something directly:**
Do it. The user outranks the process. If they say "just write this," write it.

**Ambiguity about whether something is a Junior/Senior/Lead task:**
Default up. It's cheaper to over-qualify a task than to redo it after a bad delegation.

**A delegated task fails repeatedly:**
Escalate it one tier. If Junior can't do it, re-scope for Senior. If Senior can't, do it yourself. Two failures on the same task at the same tier means the tier is wrong for this task.
16 changes: 16 additions & 0 deletions data/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@
[
"0xe2e3d3446aa2abc62f085ab82a3f459e817c8cc8b56c443409723b7a829a08c2",
"1000000000000000000"
],
[
"0x8db33f19486774dea73efbfed1175fb25fcf5a2682e1f55271207dc01670bb19",
"1000000000000000000"
],
[
"0x7bee59666b7ef18f648df18c4ed3677a79b30aaa6cf66dc6ab2818fd4be2dcfb",
"1000000000000000000"
],
[
"0xd98eabad3b7e6384355d313130314263278d5a7a7f5ab665881c54711159e760",
"1000000000000000000"
],
[
"0x71b0c2af6fed129df6c25dbf2b7a0d3c6b414df64980f513997be86200ef5e0e",
"1000000000000000000"
]
],
"timestamp": "1692734616",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"zk:l2ps:setup": "cd src/libs/l2ps/zk/scripts && bash setup_all_batches.sh",
"zk:compile": "circom2 src/features/zk/circuits/identity.circom --r1cs --wasm --sym -o src/features/zk/circuits/ -l node_modules",
"zk:compile:merkle": "circom2 src/features/zk/circuits/identity_with_merkle.circom --r1cs --wasm --sym -o src/features/zk/circuits/ -l node_modules",
"test:petri": "bun test testing/petri/",
"zk:test": "bun test src/features/zk/tests/",
"zk:ceremony": "npx tsx src/features/zk/scripts/ceremony.ts",
"sync:br-myc": "bun scripts/sync-br-to-myc.ts",
Expand Down
Loading
Loading