Skip to content

feat(swarm): migration 070 — nodes table for cryptographic identity (#75)#79

Merged
Dewinator merged 2 commits into
mainfrom
agent/issue-75-2026-04-27T18-49-06-604Z
Apr 27, 2026
Merged

feat(swarm): migration 070 — nodes table for cryptographic identity (#75)#79
Dewinator merged 2 commits into
mainfrom
agent/issue-75-2026-04-27T18-49-06-604Z

Conversation

@Dewinator
Copy link
Copy Markdown
Owner

Closes #75. Second step of the Swarm Foundation Plan v1 — the cryptographic identity row that every later swarm phase depends on.

Summary

  • New migration supabase/migrations/070_node_identity.sql creates nodes (node_id PK, pubkey BYTEA, display_name, is_self, created_at). Schema-only — no DROP, no DELETE, no data backfill.
  • Partial unique index nodes_only_one_self ON nodes ((1)) WHERE is_self enforces "at most one row may carry is_self=true".
  • Sibling TS contract test mcp-server/src/__tests__/migration-070-node-identity.test.ts pins the canonical SQL (column types, defaults, partial predicate) so any drift fails before the migration ever hits a real database.

Research summary

  • Issue Swarm Phase 0: SWARM_SPEC.md — wire-format spec for the decentralized mycelium swarm #74 (Phase 0, docs/SWARM_SPEC.md) is closedNodeAdvertisement is the canonical wire format this row backs, so no dependency note needed.
  • Recent migration style (055, 061, 066) uses uppercase SQL keywords, TIMESTAMPTZ, BYTEA, BOOLEAN. Adopted.
  • Tests live in mcp-server/src/__tests__/ and run via npm test (tsc && node --test). There is no pre-existing tests/sql/ directory — the existing pattern is TS contract pins (e.g. affect-recalled-event-type.test.ts). The test for migration 070 follows that pattern: read the raw SQL file, normalise whitespace + case, assert the structural contracts via regex. We cannot RUN the migration from tests (autonomy loop is forbidden from executing migrations — Reed runs them by hand after merge), so static contract pins are the right tool.

What this does NOT do

  • Does NOT execute the migration. The file is committed only; Reed runs it manually.
  • Does NOT include the keypair-generation script or the ~/.mycelium/node.key writer — that is Phase 1b (separate issue).
  • Does NOT implement the node_identity_get MCP tool — also Phase 1b.
  • Does NOT implement signature services — Phase 2.
  • Does NOT touch any other migration file or any CI/CD configuration.

Constitution affirmation

Pillar 1 — Decentralized, networked AI / Souveränität. This is the touched pillar, and this PR strengthens it: the table schema deliberately stores only the public key and the derived node_id. The private key is excluded from the database by design and lives in a chmod-600 file at ~/.mycelium/node.key (documented in the migration header). A DB compromise alone cannot yield the secret. No other pillar (Reproduction, Swarm Intelligence, Microtransactions, Experts in the Swarm, Cyber Security) is weakened — Cyber Security is reinforced by the same separation.

Test plan

  • cd mcp-server && npm test passes (259 tests; 9 of them new for migration 070).
  • After merge, Reed runs cd scripts && bash migrate.sh (or applies 070_node_identity.sql directly) and confirms:
    • \d nodes shows columns node_id text PK, pubkey bytea NOT NULL, display_name text, is_self boolean NOT NULL DEFAULT false, created_at timestamptz NOT NULL DEFAULT now().
    • \di nodes_only_one_self shows the partial unique index with WHERE is_self.
    • INSERT INTO nodes (node_id, pubkey, is_self) VALUES ('x', '\x00', true); succeeds; a second INSERT INTO nodes (node_id, pubkey, is_self) VALUES ('y', '\x01', true); fails with a unique-violation on nodes_only_one_self.

🤖 Generated with Claude Code

Dewinator and others added 2 commits April 27, 2026 20:36
Spec-only first phase of the Mycelium Swarm Foundation Plan v1. Defines
spec versioning, JCS (RFC 8785) over Ed25519 for signatures, the four
wire types (Lesson, HubAnchor, NodeAdvertisement, TrustEdge), four
HTTP/JSON endpoints, and uniform rejection rules. No code, no migrations.

Restates the three unverletzlichen Designprinzipien (Souveränität,
Generalisierung-vor-Sharing, Diversität) at the top so all later phases
implement against the same contract and the same constraints.

Closes the Phase-0 deliverable of issue #74.
)

Swarm Phase 1a: schema-only migration that creates the `nodes` table
holding this mycelium node's public key and node_id (multihash of the
pubkey), plus any peers we will later learn about. The PRIVATE key is
deliberately NOT a column — it lives outside the database in a
chmod-600 file at ~/.mycelium/node.key (Verfassung pillar 1,
Souveränität).

Includes a partial UNIQUE index `nodes_only_one_self ON nodes ((1))
WHERE is_self` that enforces "at most one row may carry is_self=true",
and a sibling TS contract test (`migration-070-node-identity.test.ts`)
that pins the canonical SQL: column types, defaults, and the partial
predicate. The test reads the raw SQL — it does not run the migration.

Out of scope: keypair-generation script and the `node_identity_get`
MCP tool (both phase 1b, separate issue); signature service (phase 2).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Dewinator Dewinator added the agent-opened Opened by the autonomy loop label Apr 27, 2026
@Dewinator Dewinator merged commit d21cfa3 into main Apr 27, 2026
@Dewinator Dewinator deleted the agent/issue-75-2026-04-27T18-49-06-604Z branch April 27, 2026 20:19
Dewinator added a commit that referenced this pull request Apr 29, 2026
Updates the stale "spec-only" header (phases 0–3 have all merged via
PRs #79/#81/#82/#85/#89/#91/#92) and pins each phase to its issue +
merged commit so a reader can tell at a glance which sections are wired
on `main` vs. still paper.

Phases 4–9 are deliberately listed as "_not yet issued_" — the project's
current priority is *Gehirn perfektionieren* per CLAUDE.md § Roadmap
(Reed 2026-04-26), and the wire contract is frozen at v1.0 so an
independent implementer can build a phase-3-equivalent peer today.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Dewinator added a commit that referenced this pull request Apr 29, 2026
The cryptographic foundation of the swarm (SWARM_SPEC v1, Ed25519
signing, JCS canonicalization, wire-validator, .well-known discovery,
peer/signed-record storage — PRs #78,#79,#81,#82,#85,#89,#91,#92) was
landing on main while the README/MANIFESTO still claimed
"pairing/swarm/federation deferred". This commit fixes that mismatch.

README (EN+DE):
- new "Swarm — federation in flight" section with merged-PR table
  and a "what is next" subsection pointing to the swarm label
- Roadmap rewritten: phase 4-5 from "deferred" to "Phase 1 shipped"
- existing /.well-known/mycelium-node block folded into the new section
- promo video as a clickable poster near the top, served from a
  v0.4-swarm-phase-1 GitHub release asset (14 MB H.264 1080p)

MANIFESTO (EN+DE):
- "What is built today" split into brain core + Swarm Phase 1
- aspirational Tailscale+mTLS / mutual-pairing claims removed; those
  pieces remain on archive/swarm-deferred as historical reference
- "What is not built yet" sharpened to the social layer (verification,
  reputation, banishment-by-consensus, Sybil resistance) plus
  micro-transactions

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-opened Opened by the autonomy loop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swarm Phase 1a: migration 070 — node_identity table (file only, do NOT run)

1 participant