user-management-system-v2-implementation
User management system v2 — implementation direction
This file translates user-management-system-v2.md into an implementation plan for coding assistants and contributors.
Use this as an execution guide: what to build, where to build it, in what order, and how to validate completion.
Scope and non-scope
In scope
- Node-first identity (
nodeId) with generated 10-word phrase (passw) flow. - Removal of email-required auth paths from primary user workflow.
- Shared node derivation/validation implementation in main codebase (CLI + SDK + server).
- Node-owned agent records and runtime ownership checks.
- Merkle/stable-key shape updates to encode node hierarchy.
Out of scope (for initial v2 cut)
- Legacy-mode dual auth support unless explicitly requested.
- New social/reputation/payment features not required by identity migration.
- New UI polish beyond required auth/flow changes.
Primary references
- Product/contract note:
docs/notes/user-management-system-v2.md - Derivation/validation behavior source:
/Users/williamsisaac/Documents/play-tools/node-validation.md - Occupancy policy context:
docs/notes/occupant-model-and-interaction-policy.md
Guiding implementation rules
- One shared node-crypto implementation must be used by CLI, SDK, and server.
- No plaintext persistence of phrase material on server.
- All privileged agent-node actions must require
mainNodeId + passw + agentNodeId. - Merkle identity hierarchy changes are required, not optional.
- Backward-incompatible changes must be explicit in docs and tests.
Target module map
New shared modules (recommended)
packages/sdk/src/lib/node-identity.ts(or shared internal package)- Derive node id from credential material using v2-compatible method.
- Validate node id against source material.
- Expose stable API for CLI/SDK/server.
packages/web-ui/src/server/node-identity.ts- Server-side wrappers around the same derivation/validation primitives.
- Phrase verification helper (slow hash verification).
Server changes
packages/web-ui/src/server/auth-store.ts- Remove email-keyed flows from primary auth path.
- Add node record creation/loading helpers.
- Add phrase verification by
nodeId.
packages/web-ui/src/server/agent-play/agent-repository.ts- Replace/augment
userIdownership with requirednodeId. - Update record types and methods accordingly.
- Replace/augment
packages/web-ui/src/server/agent-play/redis-agent-repository.ts- Redis schema migration to node-owned records.
- Ensure lookup/indexing by node where needed.
packages/web-ui/src/server/agent-play/in-memory-agent-repository.ts- Keep behavior parity with Redis repository for tests.
packages/web-ui/src/server/agent-play/play-world.tsaddPlayerownership check: agent must belong to authenticated main node.- Agent-node admin actions require tuple checks when applicable.
packages/web-ui/src/app/api/*- Replace email-era auth endpoints with node bootstrap/auth endpoints.
- Update
playersregistration payload requirements. - Ensure route-level tuple validation for admin operations.
SDK changes
packages/sdk/src/lib/remote-play-world.ts- Support credential-file path or loaded node-auth object.
- Send node-auth payload shape required by server.
packages/sdk/src/public-types.ts- Replace/add auth-relevant public types with node-first semantics.
packages/sdk/examples/*- Replace API-key/email assumptions with node-passw + nodeId flow.
CLI changes
packages/cli/src/cli.ts- Add command to generate node identity material:
- 10-word phrase
- derived node id
- print credential file content (view once only with warnings that loosing this means looseing access to their node and all their agent nodes)
- tell them to keep this safe in a file and this can be used to login and recover their account later
- Remove old email/API-key command UX from default path.
- Add command to generate node identity material:
Player-chain / Merkle changes
packages/web-ui/src/server/agent-play/player-chain/index.ts- Update stable key derivation to include node hierarchy (for agent leaves).
- Keep deterministic ordering and notify behavior.
packages/sdk/src/lib/player-chain-merge.ts- Keep parse/merge compatibility with new stable key shape.
packages/web-ui/src/server/agent-play/read-player-chain-node.ts- Ensure node-scoped key lookup works for incremental sync fetches.
Recommended rollout sequence
- Implement shared node derivation/validation module with test vectors.
- Add CLI node bootstrap command and local credential file schema.
- Add server node records + phrase verification paths.
- Migrate repository ownership from
userIdtonodeId. - Update API routes for node-first auth payloads.
- Update SDK auth inputs and runtime registration payload.
- Update player-chain key shape for node hierarchy.
- Update docs and examples.
- Run migration tests and end-to-end sync verification.
Do not merge partial ownership migrations without full route and runtime checks.
Data migration strategy
Required migration outputs
- Existing account records mapped to
nodeId. - Existing agents assigned to
nodeId. - Any legacy lookup keys updated or dual-read during migration window.
- Run
npm run migrate:v2:node-authagainst Redis before enabling strict route checks.
Suggested migration phases
- Prepare
- Add new fields/keys and dual-write.
- Backfill
- Populate node ids for existing users and agent records.
- Cutover
- Switch read/auth ownership checks to
nodeId.
- Switch read/auth ownership checks to
- Cleanup
- Remove email-era/legacy ownership paths.
Test plan (must-have)
Unit tests
- Node id derivation deterministic parity against play-tools vectors.
- Phrase verification success/failure cases.
- Repository ownership checks by
nodeId. - Stable key generation under node-qualified shape.
Integration tests
- CLI bootstrap -> file write -> SDK load -> addPlayer success.
- Wrong phrase, right node id -> denied.
- Right phrase, wrong agent node -> denied.
- Correct main node + passw + agent node -> allowed.
Sync tests
- Merkle root changes when node-scoped ownership changes.
playerChainNotifyrefs remain valid and merge converges for all clients.- SDK and web-ui both converge from same fanout stream.
Security tests
- No plaintext phrase appears in server persistence.
- Timing-safe phrase verification path (where applicable).
- Route-level checks reject incomplete auth tuple payloads.
Acceptance criteria
Implementation is complete only when all are true:
- Users can bootstrap with generated 10-word phrase and receive
nodeId. - SDK/CLI/server share the same node derivation+validation behavior.
- Email is not required for v2 primary flow.
- Agent ownership is enforced by
nodeId. - Merkle/player-chain shape reflects node hierarchy.
- Full workspace tests pass and docs reference v2 flow.
Coding-assistant execution notes
- Prefer small, test-first slices.
- Keep compatibility decisions explicit in code and docs.
- Update tests before changing behavior where possible.
- If migration risk is high, gate with feature flag and document default.