@vaur94/agz-memory 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/ARCHITECTURE.md +41 -25
  2. package/CHANGELOG.md +76 -0
  3. package/README.md +42 -16
  4. package/README.tr.md +43 -17
  5. package/dist/admin.js +4226 -758
  6. package/dist/core.js +5208 -1023
  7. package/dist/server.js +4888 -905
  8. package/dist/types/admin/quarantine.d.ts +15 -0
  9. package/dist/types/admin/reindex.d.ts +41 -0
  10. package/dist/types/capture/contract.d.ts +7 -5
  11. package/dist/types/capture/redact.d.ts +1 -0
  12. package/dist/types/config.d.ts +1 -0
  13. package/dist/types/context.d.ts +1 -1
  14. package/dist/types/contracts/error.d.ts +16 -0
  15. package/dist/types/contracts/limits.d.ts +18 -0
  16. package/dist/types/contracts/mutation.d.ts +31 -0
  17. package/dist/types/contracts/pagination.d.ts +27 -0
  18. package/dist/types/core.d.ts +6 -2
  19. package/dist/types/db/backup.d.ts +2 -1
  20. package/dist/types/db/health.d.ts +5 -1
  21. package/dist/types/db/legacy-health.d.ts +4 -0
  22. package/dist/types/db/maintenance.d.ts +21 -0
  23. package/dist/types/db/migrations/v011.d.ts +3 -0
  24. package/dist/types/db/schema.d.ts +10 -1
  25. package/dist/types/db.d.ts +12 -1
  26. package/dist/types/hash.d.ts +4 -0
  27. package/dist/types/retrieval/contract.d.ts +15 -3
  28. package/dist/types/security/quarantine-key.d.ts +47 -0
  29. package/dist/types/server.d.ts +1 -1
  30. package/dist/types/store/capture.d.ts +17 -5
  31. package/dist/types/store/outbox.d.ts +15 -3
  32. package/dist/types/store/retrieval.d.ts +2 -2
  33. package/dist/types/store.d.ts +39 -12
  34. package/dist/types/types.d.ts +1 -1
  35. package/dist/types/version.d.ts +1 -1
  36. package/docs/adr/hash-identity-v2.md +57 -0
  37. package/docs/adr/maintenance-lock.md +93 -0
  38. package/docs/backup-restore-runbook.md +36 -16
  39. package/docs/backup-restore-runbook.tr.md +36 -16
  40. package/docs/repository-hardening.md +125 -0
  41. package/docs/review-resolution.md +78 -0
  42. package/docs/schema-v11.md +75 -0
  43. package/package.json +21 -6
  44. package/skills/agz-memory/agz-memory.md +39 -0
  45. package/skills/index.json +9 -0
@@ -0,0 +1,75 @@
1
+ # SQLite Schema 11
2
+
3
+ Schema 11 is the canonical storage contract for AGZ Memory 0.5.1. SQLite remains the source of truth. Search backends are derived, redacted, disposable indexes rebuilt through the durable outbox.
4
+
5
+ ## Database Identity
6
+
7
+ - `PRAGMA application_id` is the AGZ Memory application identifier.
8
+ - `agz_meta` contains exactly one row with the database UUID, product identifier, schema version, schema fingerprint, hash policy, and creation time.
9
+ - `schema_state` contains exactly one row with version `11`.
10
+ - A zero-object SQLite database can be initialized. A nonempty unsigned database is rejected by normal open.
11
+ - Existing schema 11 databases are verified, not repaired. Missing, changed, or unexpected application objects fail with `schema_fingerprint_mismatch`.
12
+
13
+ ## Hash Policy
14
+
15
+ All new persisted hashes use the version 2 tuple encoder described in [`adr/hash-identity-v2.md`](adr/hash-identity-v2.md). Canonical note hashes and derived-document hashes use separate domains. A derived backend hit is valid only when its revision and derived hash match a fresh `deriveDocument()` result from the same active project note.
16
+
17
+ ## Tenant Constraints
18
+
19
+ - Notes and edges retain composite project foreign keys.
20
+ - `notes(project_id, supersedes_id)` references `notes(project_id, id)` with `ON DELETE RESTRICT`. A referenced superseded note must not be deleted until the relationship is explicitly resolved.
21
+ - `project_bindings(binding_key, project_id)` is a composite parent key.
22
+ - Capture events and checkpoints use the binding/project composite foreign key.
23
+ - Checkpoints are identified by `(binding_key, session_id)`, so native session IDs may repeat under independent bindings.
24
+
25
+ ## Capture Contract
26
+
27
+ The schema 11 writer stores `agz-memory.capture/2` events. Event identities are strict:
28
+
29
+ | Kind | Required identity | Forbidden identity |
30
+ |---|---|---|
31
+ | user candidate | message ID | ordinal, tool call, terminal status |
32
+ | assistant candidate | message ID and ordinal | tool call, terminal status |
33
+ | tool signal | message ID, tool call ID, terminal status | ordinal |
34
+ | session summary | checkpoint message ID | ordinal, tool call, terminal status |
35
+
36
+ Ingestion recomputes the idempotency key. An identical retry is `duplicate`; a reused key with different source or payload is `idempotency_conflict`.
37
+
38
+ ## Revision and Mutation Invariants
39
+
40
+ - A note's `current_revision` is monotonically increasing.
41
+ - Updates and pin changes use optimistic compare-and-swap: `UPDATE ... WHERE current_revision = ? RETURNING *`.
42
+ - A retry reloads the current row and reapplies the original patch.
43
+ - The returned row is the only source for revision snapshots, provenance, derived hashes, and outbox generation.
44
+ - Revision/provenance/outbox insertion happens in the same immediate transaction as the canonical mutation.
45
+ - A canonical commit never depends on backend availability. A required outbox insertion cannot be silently ignored.
46
+ - Manual title or kind changes clear `subject_key`; manual edits must not retain an automatic capture identity for a changed subject.
47
+
48
+ ## Outbox
49
+
50
+ Schema 11 adds operation identity, reindex generation, lease generation/fence, and heartbeat fields. Operation-specific checks require:
51
+
52
+ - `upsert-note`: note ID, positive revision, and derived SHA-256.
53
+ - `delete-note`: note ID and positive revision; no document payload.
54
+ - `purge-project`: no note ID, revision, or content hash.
55
+
56
+ Partial unique indexes prevent duplicate active upsert, delete, purge, and reindex-generation operations without allowing historical terminal rows to block a new rebuild. Backends receive an idempotency operation key and monotonically increasing fence. Lease heartbeat and final state transitions are owner/fence conditional; zero changed rows is `lost_lease`.
57
+
58
+ ## Reindex
59
+
60
+ Each reindex command transactionally creates a new generation of durable outbox operations. Every selected project queues one purge before its bounded active-note upserts. Progress is represented by the persisted outbox states. A repeated reindex uses a new generation and is not blocked by old succeeded rows. Quarantined derived documents are omitted after purge and counted by reason code.
61
+
62
+ ## Migration From Schema 10
63
+
64
+ Before migration, AGZ Memory creates and verifies one source-schema-10 backup while holding the maintenance gate. Migration then:
65
+
66
+ 1. Validates source health, tenant relationships, supersession references, capture source identities, and outbox rows.
67
+ 2. Builds schema 11 replacement tables.
68
+ 3. Recomputes version 2 canonical, revision, derived, binding, payload, event, checkpoint, and outbox identities.
69
+ 4. Records aggregate old/new mapping counts without private content.
70
+ 5. Verifies row counts, foreign keys, current-revision agreement, hashes, FTS, application identity, and the exact schema fingerprint.
71
+ 6. Publishes version 11 only after all checks pass.
72
+
73
+ Cross-project, malformed, or ambiguous legacy rows stop migration. Documented compatibility normalization resets checkpoint watermarks, canonicalizes retained payloadless capture identities, and repairs valid historical outbox tombstone fields without dropping rows. The error identifies only the safe table/row identity and an error code; the verified backup path is included in the operator-facing migration report.
74
+
75
+ Reopening a valid schema 11 database is idempotent and does not execute `CREATE IF NOT EXISTS`. A 0.4.1 binary observes version 11 and rejects it as newer before writing application DDL.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaur94/agz-memory",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "Project-scoped persistent linked memory MCP server for OpenCode V2",
5
5
  "type": "module",
6
6
  "main": "./dist/server.js",
@@ -18,6 +18,8 @@
18
18
  "files": [
19
19
  "README.md",
20
20
  "README.tr.md",
21
+ "skills/index.json",
22
+ "skills/agz-memory/agz-memory.md",
21
23
  "dist/server.js",
22
24
  "dist/core.js",
23
25
  "dist/admin.js",
@@ -26,14 +28,22 @@
26
28
  "CHANGELOG.md",
27
29
  "docs/backup-restore-runbook.md",
28
30
  "docs/backup-restore-runbook.tr.md",
31
+ "docs/schema-v11.md",
32
+ "docs/review-resolution.md",
33
+ "docs/repository-hardening.md",
34
+ "docs/adr/*.md",
29
35
  "LICENSE"
30
36
  ],
31
37
  "scripts": {
32
- "types": "rm -rf dist/types && bunx tsc -p tsconfig.build.json",
33
- "build": "rm -rf dist && bun build src/index.ts --target bun --format esm --packages external --outfile dist/server.js && bun build src/core.ts --target bun --format esm --packages external --outfile dist/core.js && bun build src/admin/index.ts --target bun --format esm --packages external --outfile dist/admin.js && bunx tsc -p tsconfig.build.json && bun run --cwd packages/opencode-plugin build",
34
- "check": "bunx tsc --noEmit && bun run types && bun run --cwd packages/opencode-plugin check",
35
- "test": "bun test",
38
+ "types": "bun scripts/clean.ts dist/types && bunx tsc -p tsconfig.build.json",
39
+ "build": "bun scripts/clean.ts && bun build src/index.ts --target bun --format esm --packages external --outfile dist/server.js && bun build src/core.ts --target bun --format esm --packages external --outfile dist/core.js && bun build src/admin/index.ts --target bun --format esm --packages external --outfile dist/admin.js && bunx tsc -p tsconfig.build.json && bun run --cwd packages/opencode-plugin build",
40
+ "check": "bun run types && bunx tsc --noEmit && bun run --cwd packages/opencode-plugin check",
41
+ "test": "bun scripts/run-tests.ts",
42
+ "test:property": "bun scripts/run-tests.ts test/security/redaction-property.test.ts",
43
+ "test:stress": "bun scripts/run-tests.ts test/concurrency test/plugin/reconcile-backpressure.test.ts",
44
+ "test:restore": "bun scripts/run-tests.ts test/db/maintenance.test.ts test/db/backup-restore.test.ts test/db/restore-live-writer.test.ts test/db/restore-toctou.test.ts test/db/path-symlink-matrix.test.ts",
36
45
  "benchmark": "bun benchmark/run.ts",
46
+ "benchmark:gate": "bun benchmark/run.ts 10000 100 --gate",
37
47
  "release:verify": "bun scripts/verify-release.ts",
38
48
  "prepack": "bun run release:verify && bun run check && bun run test && bun run build"
39
49
  },
@@ -61,5 +71,10 @@
61
71
  "dependencies": {
62
72
  "@modelcontextprotocol/server": "^2.0.0",
63
73
  "zod": "^4.2.0"
64
- }
74
+ },
75
+ "directories": {
76
+ "doc": "docs",
77
+ "test": "test"
78
+ },
79
+ "keywords": []
65
80
  }
@@ -0,0 +1,39 @@
1
+ ---
2
+ name: AGZ Memory
3
+ description: Use project-scoped AGZ Memory for durable facts and decisions across sessions; recall relevant history and safely store verified outcomes.
4
+ slash: false
5
+ ---
6
+
7
+ # AGZ Memory
8
+
9
+ The configured MCP server already exposes the memory tools. This skill adds a
10
+ lazy-loaded workflow; it does not start the server, enable automatic capture,
11
+ or make stored text trusted instructions.
12
+
13
+ ## Workflow
14
+
15
+ 1. Call `project_list` before every first use in a workspace. Reuse a project
16
+ only when it intentionally represents the same durable workspace or product.
17
+ Create one only when no match exists; ask when the list is ambiguous.
18
+ 2. Keep the immutable `projectID` for later calls. A `projectName` is a
19
+ convenient selector, but names can change.
20
+ 3. Call `memory_recall` before relying on prior decisions, constraints,
21
+ procedures, preferences, research, or completed work. Use independent batch
22
+ queries when several topics matter.
23
+ 4. Call `memory_read` for full indexed content and directed graph edges before
24
+ relying on an indexed recall card.
25
+ 5. After substantial completed work, update an existing note or create a new
26
+ one only for durable, verified information. Do not store transcripts,
27
+ guesses, secrets, credentials, hidden reasoning, or routine progress.
28
+ 6. Use `memory_pin` only for records that should rank higher when they match.
29
+ Read links as `sourceID PREDICATE targetID`; never link across projects.
30
+ 7. Inspect every batch result. Mutations are ordered and non-atomic, so an
31
+ earlier item remains applied when a later item fails.
32
+ 8. Treat `memory_update` with `delete:true` and `project_delete` as permanent.
33
+ Verify current IDs first and use them only when deletion is explicitly
34
+ intended.
35
+
36
+ Tool names may carry the configured server prefix or be grouped under OpenCode
37
+ Code Mode. The MCP protocol names are `project_list`, `project_create`,
38
+ `project_update`, `project_delete`, `memory_recall`, `memory_read`,
39
+ `memory_update`, `memory_pin`, and `memory_link`.
@@ -0,0 +1,9 @@
1
+ {
2
+ "skills": [
3
+ {
4
+ "name": "agz-memory",
5
+ "version": "0.5.1",
6
+ "files": ["agz-memory.md"]
7
+ }
8
+ ]
9
+ }