Skip to content

feat(kp3): Implement Unified Cognitive Memory Architecture API#26

Open
marklubin wants to merge 1 commit intomainfrom
feat/cognitive-memory-api
Open

feat(kp3): Implement Unified Cognitive Memory Architecture API#26
marklubin wants to merge 1 commit intomainfrom
feat/cognitive-memory-api

Conversation

@marklubin
Copy link
Owner

Summary

Implements the Unified Cognitive Memory Architecture API as designed in docs/unified-cognitive-memory-architecture.md:

Foundation tier (Refs & Derivations):

  • GET/PUT/DELETE /refs/{ref_name:path} with optimistic locking (version-based conflict detection)
  • GET /refs/{ref_name:path}/history - version history tracking
  • GET /refs - list refs with prefix filter
  • GET /passages/{id}/sources - derivation provenance
  • GET /passages/{id}/derived - derived passages

Cognitive tier (Frames & Cognition):

  • POST /frames - create cognitive frame
  • GET /frames/{name}, GET /frames - get/list frames
  • POST /frames/{name}/fork - fork frame for experimentation
  • POST /frames/{name}/activate - activate frame
  • POST /frames/{name}/resolve - resolve to frozen snapshot
  • POST /cognition/increment - atomic state transitions with optimistic locking

New files:

  • schemas.py: Pydantic models for all API endpoints
  • cognitive_router.py: FastAPI router for cognitive endpoints
  • frames.py: Frame service implementation
  • cognition.py: Cognition increment service with optimistic locking, idempotency, and rollback

Test plan

  • 16 E2E tests covering scenarios A-T from design document
  • HTTP API tests for all new endpoints
  • Tests run against testcontainers Postgres with pgvector
  • All tests passing (uv run pytest tests/test_cognitive_e2e.py)

To run tests locally:

cd kp3
DOCKER_HOST=unix:///run/user/$(id -u)/podman/podman.sock uv run pytest tests/test_cognitive_e2e.py -v

🤖 Generated with Claude Code

Implements the cognitive memory API as designed in
docs/unified-cognitive-memory-architecture.md:

Foundation tier (Refs & Derivations):
- GET/PUT/DELETE /refs/{ref_name:path} with optimistic locking
- GET /refs/{ref_name:path}/history - version history
- GET /refs - list refs with prefix filter
- GET /passages/{id}/sources - derivation sources
- GET /passages/{id}/derived - derived passages

Cognitive tier (Frames & Cognition):
- POST /frames - create cognitive frame
- GET /frames/{name} - get frame
- GET /frames - list frames
- POST /frames/{name}/fork - fork frame
- POST /frames/{name}/activate - activate frame
- POST /frames/{name}/resolve - resolve to frozen snapshot
- POST /cognition/increment - atomic state transitions

New files:
- schemas.py: Pydantic models for all API endpoints
- cognitive_router.py: FastAPI router for cognitive endpoints
- frames.py: Frame service implementation
- cognition.py: Cognition increment service with optimistic locking

E2E test coverage:
- Scenarios A-T from the design document
- HTTP API tests for all new endpoints
- 16 tests passing against testcontainers Postgres

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant