feat(core): add applies_to field for layered sticky-rules foundation#1102
feat(core): add applies_to field for layered sticky-rules foundation#1102kunickiaj wants to merge 1 commit into
Conversation
Adds explicit applicability scope (user/org/toolchain/project) as a first-class column on memory_items, distinct from scope_id (sharing domain). Foundation for a layered sticky-rules pack band that fights long-context attention dilution by re-emitting standing rules every pack. - Schema: applies_to TEXT NOT NULL DEFAULT 'project' with a CHECK constraint, applies_to_key TEXT (org/toolchain discriminator), composite index idx_memory_items_applies_to. - Validation: new applicability module exposes validateApplicability (strict write path — rejects unknown layers, enforces key contract) and normalizeApplicability (lenient read path — unknown layers degrade to 'project' for downgrade safety on inbound peer payloads). - Replication: recordReplicationOp, buildPayloadFromMemoryRow, parseMemoryPayload, applyReplicationOps (insert + update), and the bootstrap snapshot apply path all carry the new fields. CHECK constraint catches any payload that escapes normalization. - Tests: 6 db migration tests (column existence, default, index composition + EXPLAIN QUERY PLAN, CHECK rejection, idempotency, raw insert default), 15 applicability validator tests, 3 replication round-trip tests (carry, future-layer downgrade, missing-field default). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Scrapping the layered sticky-rules feature stack. The manual user-pinning premise — "user finds a memory in the feed and clicks a dropdown to broaden its scope" — is friction nobody will reach for. The valuable sticky rules ("use fish shell", "no praise filler") are not memories users would find and pin; they are recurring patterns the observer should infer, and the canonical homes for them already exist ( Salvaging the one pre-existing bug surfaced during this work as a focused standalone PR: the silent |

Description
Adds explicit applicability scope (user/org/toolchain/project) as a first-class column on
memory_items, distinct fromscope_id(sharing domain). Foundation for a layered sticky-rules pack band that fights long-context attention dilution by re-emitting standing rules every pack.applies_to TEXT NOT NULL DEFAULT 'project'with aCHECKconstraint,applies_to_key TEXT(org/toolchain discriminator), composite indexidx_memory_items_applies_to.applicabilitymodule exposesvalidateApplicability(strict write path — rejects unknown layers, enforces key contract) andnormalizeApplicability(lenient read path — unknown layers degrade toprojectfor downgrade safety on inbound peer payloads).recordReplicationOp,buildPayloadFromMemoryRow,parseMemoryPayload,applyReplicationOps(insert + update branches), and the bootstrap snapshot apply path all carry the new fields. The CHECK constraint catches any payload that escapes normalization.This is the first PR in a stacked feature. Follow-on PRs add viewer-side promotion UI and the layered pack band.
Type of Change
Testing
pnpm run tsc,pnpm run lint,pnpm run test) — workspace 1951/1951EXPLAIN QUERY PLANconfirms the composite index is used by the layered-band query; pre-commit reviews caught the SQLCHECKconstraint and replication apply-path wiring before merge.Checklist
pnpm run lintpasses for touched files)