Give memories a working tier, a long-term tier, and a record of what disagrees
A memory used to have one state: present. A session could not be reloaded
without searching, nothing separated what a person said today from what the
store ingested a year ago, and two statements that disagree about a number
were both handed to the reader as if the store believed both.
Schema v10. Atoms gain session_id, importance, recall_count, last_recalled_at
and archived_at; two tables arrive beside them — consolidations (one watermark
per holder+scenario lane) and conflicts (a pair, the term they disagree on,
both values, and whether anyone has settled it). v_atoms_current now also
hides archived rows, and apply() drops the view before rebuilding it because
CREATE VIEW IF NOT EXISTS would keep the old body and ignore the archive.
Working memory is a read, not a store: `working <holder> <session>` returns
what that session recorded, in order, with no search involved. Consolidation
rolls a lane's new memories into one standing summary and moves the watermark
to the newest memory actually rolled up — not to the clock of the pass, which
made a second pass count the same memories twice. The archive rule is stated
in the command that runs it (recorded before N days, never returned by a
search, importance at or under a floor) rather than hidden in a decay formula
nobody measured; --dry-run names the victims first.
A conflict is recorded when a new memory repeats a label with a different
number in the same holder's same scenario. Retrieval drops the older side
while the conflict is open and both sides answer again once it is settled:
settling is not superseding, and a word-only disagreement is left alone
because a reworded sentence would fire on every paraphrase. Numbers are keyed
to both the memory's subject and the nearest preceding label, measured: the
two thermostat sentences share only their subject, so a nearest-word-only rule
found nothing.
Search now counts the memories it handed back, which is the only use estimate
the store has, and the archive rule reads it. The dense index applies the same
currency rules as the view, so an archived memory cannot stay findable through
one leg while the other hides it.
Two reads over HTTP (working, conflicts) and two tools over MCP
(working_set, memory_conflicts); curation stays with the operator because an
agent should not decide what its own past is worth. remember and supersede
carry a session id; importance does not cross MCP, because recall_count is
observed and importance is stated.
Gates: 366 passed; ruff clean; mypy 24 errors in 9 files, the recorded 9cb46c1
baseline, net 0; pyright 0 on the touched files; go build/vet/test and gofmt
clean; mcp_write_smoke PASS.
This commit is contained in:
1 parent
4c6af87fe0
commit
dc9cfb5a30
30 files changed
+1814
-229
No files matched your search
@@ -106,3 +106,55 @@ def test_the_cli_answers_in_json_a_machine_can_read(db: Database) -> None:
|
||||
result = runner.invoke(app, ["remember", "钥匙在玄关抽屉", "--holder", "wife"])
|
||||
assert result.exit_code == 0
|
||||
assert json.loads(result.output)["text"] == "钥匙在玄关抽屉"
|
||||
|
||||
|
||||
def test_working_lists_one_session_in_the_order_it_was_recorded(db: Database) -> None:
|
||||
first = run("remember", "烤箱要除垢", "--session", "cooking")
|
||||
second = run("remember", "面粉在储物架第二层", "--session", "cooking")
|
||||
run("remember", "周报周五交")
|
||||
|
||||
working = run("working", "husband", "cooking")
|
||||
|
||||
assert [atom["atom_id"] for atom in working] == [first["atom_id"], second["atom_id"]]
|
||||
|
||||
|
||||
def test_working_refuses_to_guess_which_session_is_working(db: Database) -> None:
|
||||
result = runner.invoke(app, ["working", "husband", ""])
|
||||
assert result.exit_code != 0
|
||||
assert "a working set needs a session" in str(result.exception)
|
||||
|
||||
|
||||
def test_consolidate_rolls_a_lane_up_once_and_then_says_nothing_new(db: Database) -> None:
|
||||
run("remember", "烤箱要除垢", "--scenario", "home")
|
||||
record = run("consolidate", "--scenario", "home", "--holder", "husband")
|
||||
assert record["atom_count"] == 1 and record["rollup_atom_id"]
|
||||
|
||||
result = runner.invoke(app, ["consolidate", "--scenario", "home", "--holder", "husband"])
|
||||
assert result.exit_code == 0
|
||||
assert result.output.strip() == "nothing new to roll up"
|
||||
|
||||
|
||||
def test_the_archive_can_be_read_before_it_moves_anything(db: Database) -> None:
|
||||
atom = run("remember", "前租户的 wifi 密码")
|
||||
|
||||
preview = run("archive", "--older-than-days", "0", "--dry-run")
|
||||
assert preview["dry_run"] is True and preview["atom_ids"] == [atom["atom_id"]]
|
||||
assert run("archived") == []
|
||||
|
||||
moved = run("archive", "--older-than-days", "0")
|
||||
assert moved["dry_run"] is False and moved["atom_ids"] == [atom["atom_id"]]
|
||||
assert [row["atom_id"] for row in run("archived")] == [atom["atom_id"]]
|
||||
assert run("memory-restore", atom["atom_id"]) == {"restored": 1}
|
||||
assert run("archived") == []
|
||||
|
||||
|
||||
def test_the_cli_shows_and_settles_a_disagreement(db: Database) -> None:
|
||||
run("remember", "恒温器放在书房,设定 22 度", "--scenario", "home")
|
||||
run("remember", "恒温器调到 24 度", "--scenario", "home")
|
||||
|
||||
listed = run("conflicts", "--holder", "husband")
|
||||
assert len(listed) == 1
|
||||
assert listed[0]["older_value"] == "22" and listed[0]["newer_value"] == "24"
|
||||
|
||||
assert run("resolve-conflicts", str(listed[0]["conflict_id"])) == {"resolved": 1}
|
||||
assert run("conflicts", "--holder", "husband") == []
|
||||
Reference in new issue
Block a user