Files
ely-eye/ely-eye-mcp/internal/mcpserver/write_tools.go
T
ZacharyZhang-NY dc9cfb5a30 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.
2026-10-09 07:13:11 -04:00

96 lines
4.3 KiB
Go

package mcpserver
import (
"context"
"errors"
"github.com/ZacharyZhang-NY/ely-eye/ely-eye-mcp/internal/domain"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
type RememberInput struct {
Text string `json:"text" jsonschema:"the statement to remember, kept verbatim"`
Scenario string `json:"scenario,omitempty" jsonschema:"optional context label such as home or work"`
Session string `json:"session_id,omitempty" jsonschema:"the conversation this belongs to; working_set reloads a session in order"`
EventTime string `json:"event_time,omitempty" jsonschema:"when it was true, ISO 8601 with offset, e.g. 2026-05-01T12:00:00+08:00"`
EventTimePrecision string `json:"event_time_precision,omitempty" jsonschema:"instant, minute, hour, day, month, or year; required with event_time"`
RetentionUntil string `json:"retention_until,omitempty" jsonschema:"ISO 8601 with offset; the memory stops being retrievable after this"`
}
type SupersedeInput struct {
AtomID string `json:"atom_id" jsonschema:"exact Evidence Atom id being replaced"`
Text string `json:"text" jsonschema:"the newer statement, kept verbatim"`
Scenario string `json:"scenario,omitempty" jsonschema:"optional context label such as home or work"`
Session string `json:"session_id,omitempty" jsonschema:"the conversation this belongs to; working_set reloads a session in order"`
EventTime string `json:"event_time,omitempty" jsonschema:"when the new statement became true, ISO 8601 with offset"`
EventTimePrecision string `json:"event_time_precision,omitempty" jsonschema:"instant, minute, hour, day, month, or year; required with event_time"`
}
type ForgetInput struct {
AtomID string `json:"atom_id,omitempty" jsonschema:"exact Evidence Atom id to forget"`
SourceID string `json:"source_id,omitempty" jsonschema:"exact source id to forget, removing every atom of that source"`
Reason string `json:"reason,omitempty" jsonschema:"why this memory is gone"`
}
type RememberOutput struct {
Atom domain.Memory `json:"atom"`
}
type ForgetOutput struct {
Report domain.ForgetReport `json:"report"`
}
func (s *Server) registerWriteTools(server *mcp.Server) {
mcp.AddTool(server, &mcp.Tool{
Name: "remember",
Title: "Remember",
Description: "Store a new memory. The Ely-Eye server stamps the holder, origin and ingestion time, so a caller cannot claim to be somebody else.",
}, s.rememberTool)
mcp.AddTool(server, &mcp.Tool{
Name: "supersede_memory",
Title: "Supersede a memory",
Description: "Replace a memory with a newer statement. The old one stops being retrievable but keeps its record, so the timeline stays readable.",
}, s.supersedeTool)
mcp.AddTool(server, &mcp.Tool{
Name: "forget_memory",
Title: "Forget a memory",
Description: "Delete a memory by atom_id or source_id and drop the derived indexes that would keep surfacing it.",
}, s.forgetTool)
}
func (s *Server) rememberTool(ctx context.Context, _ *mcp.CallToolRequest, input RememberInput) (*mcp.CallToolResult, RememberOutput, error) {
if input.Text == "" {
return nil, RememberOutput{}, errors.New("text is required")
}
var atom domain.Memory
if err := s.api.Post(ctx, "/api/memory", input, &atom); err != nil {
return nil, RememberOutput{}, err
}
return nil, RememberOutput{Atom: atom}, nil
}
func (s *Server) supersedeTool(ctx context.Context, _ *mcp.CallToolRequest, input SupersedeInput) (*mcp.CallToolResult, RememberOutput, error) {
if input.AtomID == "" {
return nil, RememberOutput{}, errors.New("atom_id is required")
}
if input.Text == "" {
return nil, RememberOutput{}, errors.New("text is required")
}
var atom domain.Memory
if err := s.api.Post(ctx, "/api/memory/supersede", input, &atom); err != nil {
return nil, RememberOutput{}, err
}
return nil, RememberOutput{Atom: atom}, nil
}
func (s *Server) forgetTool(ctx context.Context, _ *mcp.CallToolRequest, input ForgetInput) (*mcp.CallToolResult, ForgetOutput, error) {
if (input.AtomID == "") == (input.SourceID == "") {
return nil, ForgetOutput{}, errors.New("forget takes exactly one of atom_id or source_id")
}
var report domain.ForgetReport
if err := s.api.Post(ctx, "/api/memory/forget", input, &report); err != nil {
return nil, ForgetOutput{}, err
}
return nil, ForgetOutput{Report: report}, nil
}