Cotton code
824 lines · 23.8 KB · JSONRaw
{  "pair": "memory and projects",  "rust": "crates/cotton-tools/src/mcp/handlers/records_2/memory.rs, handlers/projects",  "worker": "apps/business/src/mcp/tools/memory.ts",  "cases": [    {      "name": "recall with and without a project",      "seed": [        {          "kind": "project",          "id": "00000000-0000-4000-8000-000000000001",          "data": {            "slug": "widgets",            "name": "Widgets",            "repos": [],            "status": "active"          }        },        {          "kind": "memory",          "id": "00000000-0000-4000-8000-000000000011",          "data": {            "slug": "tea-first",            "title": "Tea comes before coffee.",            "body": "",            "status": "active",            "visibility": "private",            "origin_kind": "user"          }        },        {          "kind": "memory",          "id": "00000000-0000-4000-8000-000000000012",          "data": {            "slug": "ship-friday",            "title": "Ship on Fridays only after a walk.",            "body": "",            "status": "active",            "visibility": "private",            "origin_kind": "user"          },          "at": "2026-01-02T00:00:00.000Z"        },        {          "kind": "project_link",          "id": "00000000-0000-4000-8000-000000000101",          "data": {            "project": "00000000-0000-4000-8000-000000000001",            "record_kind": "memory",            "record_id": "00000000-0000-4000-8000-000000000011",            "applied_by": "user",            "pinned": false,            "position": 2000          }        },        {          "kind": "project_link",          "id": "00000000-0000-4000-8000-000000000102",          "data": {            "project": "00000000-0000-4000-8000-000000000001",            "record_kind": "memory",            "record_id": "00000000-0000-4000-8000-000000000012",            "applied_by": "user",            "pinned": false,            "position": 1000          }        }      ],      "steps": [        {          "tool": "recall",          "args": {},          "expect": {            "answer": {              "memories": [                {                  "id": "00000000-0000-4000-8000-000000000012",                  "slug": "ship-friday",                  "title": "Ship on Fridays only after a walk.",                  "projects": [                    {                      "slug": "widgets",                      "pinned": false,                      "position": 1000                    }                  ],                  "status": "active",                  "originKind": "user",                  "originLabel": null,                  "machine": null,                  "source": null,                  "supersededBy": null,                  "archivedAt": null,                  "createdAt": "<instant>",                  "updatedAt": "<instant>"                },                {                  "id": "00000000-0000-4000-8000-000000000011",                  "slug": "tea-first",                  "title": "Tea comes before coffee.",                  "projects": [                    {                      "slug": "widgets",                      "pinned": false,                      "position": 2000                    }                  ],                  "status": "active",                  "originKind": "user",                  "originLabel": null,                  "machine": null,                  "source": null,                  "supersededBy": null,                  "archivedAt": null,                  "createdAt": "<instant>",                  "updatedAt": "<instant>"                }              ]            }          }        },        {          "tool": "recall",          "args": {            "project": "widgets"          },          "expect": {            "answer": {              "memories": [                {                  "id": "00000000-0000-4000-8000-000000000012",                  "slug": "ship-friday",                  "title": "Ship on Fridays only after a walk.",                  "projects": [                    {                      "slug": "widgets",                      "pinned": false,                      "position": 1000                    }                  ],                  "status": "active",                  "originKind": "user",                  "originLabel": null,                  "machine": null,                  "source": null,                  "supersededBy": null,                  "archivedAt": null,                  "createdAt": "<instant>",                  "updatedAt": "<instant>"                },                {                  "id": "00000000-0000-4000-8000-000000000011",                  "slug": "tea-first",                  "title": "Tea comes before coffee.",                  "projects": [                    {                      "slug": "widgets",                      "pinned": false,                      "position": 2000                    }                  ],                  "status": "active",                  "originKind": "user",                  "originLabel": null,                  "machine": null,                  "source": null,                  "supersededBy": null,                  "archivedAt": null,                  "createdAt": "<instant>",                  "updatedAt": "<instant>"                }              ]            }          }        },        {          "tool": "recall",          "args": {            "q": "coffee"          },          "expect": {            "answer": {              "memories": [                {                  "id": "00000000-0000-4000-8000-000000000011",                  "slug": "tea-first",                  "title": "Tea comes before coffee.",                  "projects": [                    {                      "slug": "widgets",                      "pinned": false,                      "position": 2000                    }                  ],                  "status": "active",                  "originKind": "user",                  "originLabel": null,                  "machine": null,                  "source": null,                  "supersededBy": null,                  "archivedAt": null,                  "createdAt": "<instant>",                  "updatedAt": "<instant>"                }              ]            }          }        },        {          "tool": "recall",          "args": {            "flavour": "x"          },          "expect": {            "refusal": "unknown recall argument: flavour"          }        },        {          "tool": "recall",          "args": {            "status": "sleeping"          },          "expect": {            "refusal": "status must be one of active, archived, all"          }        },        {          "tool": "recall",          "args": {            "project": "nope"          },          "expect": {            "refusal": "unknown project \"nope\" — projects are: widgets"          }        }      ]    },    {      "name": "remember refusals",      "seed": [        {          "kind": "project",          "id": "00000000-0000-4000-8000-000000000001",          "data": {            "slug": "widgets",            "name": "Widgets",            "repos": [],            "status": "active"          }        }      ],      "steps": [        {          "tool": "remember",          "args": {            "project": "widgets"          },          "expect": {            "refusal": "title is required"          }        },        {          "tool": "remember",          "args": {            "project": "widgets",            "title": "A sentence.",            "body": "more"          },          "expect": {            "refusal": "body was retired — the sentence IS the memory (≤280 chars). A long thought is several thoughts: split it into separate entries. Genuinely long source material (an interview, a spec) becomes a note, and the memory links to it with source: note:<id>."          }        },        {          "tool": "remember",          "args": {            "project": "widgets",            "title": "A sentence.",            "kind": "fact"          },          "expect": {            "refusal": "kind and layer were retired — memory is flat: the sentence IS the entry, and there is no category to file it under. Send the sentence alone. And technical knowledge still never goes in memory: if a future change can make it false, it lives in the repository — write it as a guard or a note beside the code that can invalidate it."          }        },        {          "tool": "remember",          "args": {            "project": "widgets",            "title": "A sentence.",            "slug": "Not Kebab"          },          "expect": {            "refusal": "slug must be kebab-case, ≤64 chars"          }        },        {          "tool": "remember",          "args": {            "project": "widgets",            "title": "A sentence.",            "decision": {              "action": "merge"            }          },          "expect": {            "refusal": "decision.action must be one of add, update, supersede, noop"          }        },        {          "tool": "remember",          "args": {            "project": "widgets",            "title": "A sentence.",            "owner": true          },          "expect": {            "refusal": "owner: true is an entry with no project — the Owner section of every brief; pass project or owner, not both"          }        },        {          "tool": "remember",          "args": {            "project": "nope",            "title": "A sentence."          },          "expect": {            "refusal": "unknown project \"nope\" — projects are: widgets"          }        }      ]    },    {      "name": "memory_update and memory_archive",      "seed": [        {          "kind": "project",          "id": "00000000-0000-4000-8000-000000000001",          "data": {            "slug": "widgets",            "name": "Widgets",            "repos": [],            "status": "active"          }        },        {          "kind": "memory",          "id": "00000000-0000-4000-8000-000000000011",          "data": {            "slug": "tea-first",            "title": "Tea comes before coffee.",            "body": "",            "status": "active",            "visibility": "private",            "origin_kind": "user"          }        },        {          "kind": "project_link",          "id": "00000000-0000-4000-8000-000000000101",          "data": {            "project": "00000000-0000-4000-8000-000000000001",            "record_kind": "memory",            "record_id": "00000000-0000-4000-8000-000000000011",            "applied_by": "user",            "pinned": false,            "position": 1000          }        }      ],      "steps": [        {          "tool": "memory_update",          "args": {            "slug": "tea-first",            "title": "Tea always comes before coffee."          },          "expect": {            "answer": {              "updated": true,              "slug": "tea-first",              "note": "the prior state is version-snapshotted"            }          }        },        {          "tool": "memory_update",          "args": {            "slug": "tea-first",            "project": "widgets",            "pinned": true          },          "expect": {            "answer": {              "updated": true,              "slug": "tea-first",              "note": "pinned in widgets — the arrangement is that project's; nothing else changed"            }          }        },        {          "tool": "memory_update",          "args": {            "slug": "tea-first"          },          "expect": {            "refusal": "send at least one field to change"          }        },        {          "tool": "memory_update",          "args": {            "slug": "tea-first",            "pinned": true          },          "expect": {            "refusal": "pinned is per project — pass project to say which of the entry's projects pins it"          }        },        {          "tool": "memory_update",          "args": {            "slug": "nobody",            "title": "x"          },          "expect": {            "refusal": "no memory entry with slug \"nobody\""          }        },        {          "tool": "memory_archive",          "args": {            "slug": "tea-first"          },          "expect": {            "answer": {              "archived": true,              "slug": "tea-first"            }          }        },        {          "tool": "recall",          "args": {            "status": "archived"          },          "expect": {            "answer": {              "memories": [                {                  "id": "00000000-0000-4000-8000-000000000011",                  "slug": "tea-first",                  "title": "Tea always comes before coffee.",                  "projects": [                    {                      "slug": "widgets",                      "pinned": true,                      "position": 1000                    }                  ],                  "status": "archived",                  "originKind": "user",                  "originLabel": null,                  "machine": null,                  "source": null,                  "supersededBy": null,                  "archivedAt": "<instant>",                  "createdAt": "<instant>",                  "updatedAt": "<instant>"                }              ]            }          }        }      ]    }  ],  "differs": [    {      "name": "list_projects and link_to_project",      "why": "A memory linked at the tail of a project with no links sits at position 1024 on the phone and 1000 on the Worker.",      "seed": [        {          "kind": "project",          "id": "00000000-0000-4000-8000-000000000001",          "data": {            "slug": "widgets",            "name": "Widgets",            "repos": [              "https://git.example.test/acme/widgets.git"            ],            "status": "active"          }        },        {          "kind": "project",          "id": "00000000-0000-4000-8000-000000000002",          "data": {            "slug": "gadgets",            "name": "Gadgets",            "repos": [],            "status": "active"          },          "at": "2026-01-02T00:00:00.000Z"        },        {          "kind": "memory",          "id": "00000000-0000-4000-8000-000000000011",          "data": {            "slug": "tea-first",            "title": "Tea comes before coffee.",            "body": "",            "status": "active",            "visibility": "private",            "origin_kind": "user"          }        },        {          "kind": "project_link",          "id": "00000000-0000-4000-8000-000000000101",          "data": {            "project": "00000000-0000-4000-8000-000000000001",            "record_kind": "memory",            "record_id": "00000000-0000-4000-8000-000000000011",            "applied_by": "user",            "pinned": false,            "position": 1000          }        }      ],      "steps": [        {          "tool": "list_projects",          "args": {},          "expect": {            "answer": {              "projects": [                {                  "slug": "widgets",                  "name": "Widgets",                  "repos": [                    "https://git.example.test/acme/widgets.git"                  ],                  "status": "active",                  "linked": {                    "memory": 1                  }                },                {                  "slug": "gadgets",                  "name": "Gadgets",                  "repos": [],                  "status": "active",                  "linked": {}                }              ]            }          }        },        {          "tool": "link_to_project",          "args": {            "project": "gadgets",            "records": [              {                "kind": "memory",                "id": "00000000-0000-4000-8000-000000000011"              }            ]          },          "expect": {            "answer": {              "project": "gadgets",              "records": [                {                  "kind": "memory",                  "id": "00000000-0000-4000-8000-000000000011",                  "title": "Tea comes before coffee.",                  "linked": true                }              ]            }          }        },        {          "tool": "recall",          "args": {            "project": "gadgets"          },          "rust": {            "answer": {              "memories": [                {                  "id": "00000000-0000-4000-8000-000000000011",                  "slug": "tea-first",                  "title": "Tea comes before coffee.",                  "projects": [                    {                      "slug": "gadgets",                      "pinned": false,                      "position": 1024                    },                    {                      "slug": "widgets",                      "pinned": false,                      "position": 1000                    }                  ],                  "status": "active",                  "originKind": "user",                  "originLabel": null,                  "machine": null,                  "source": null,                  "supersededBy": null,                  "archivedAt": null,                  "createdAt": "<instant>",                  "updatedAt": "<instant>"                }              ]            }          },          "worker": {            "answer": {              "memories": [                {                  "id": "00000000-0000-4000-8000-000000000011",                  "slug": "tea-first",                  "title": "Tea comes before coffee.",                  "projects": [                    {                      "slug": "gadgets",                      "pinned": false,                      "position": 1000                    },                    {                      "slug": "widgets",                      "pinned": false,                      "position": 1000                    }                  ],                  "status": "active",                  "originKind": "user",                  "originLabel": null,                  "machine": null,                  "source": null,                  "supersededBy": null,                  "archivedAt": null,                  "createdAt": "<instant>",                  "updatedAt": "<instant>"                }              ]            }          }        },        {          "tool": "link_to_project",          "args": {            "project": "gadgets",            "records": []          },          "expect": {            "refusal": "records must be a non-empty array of { kind, id }"          }        },        {          "tool": "link_to_project",          "args": {            "records": [              {                "kind": "memory",                "id": "00000000-0000-4000-8000-000000000011"              }            ]          },          "expect": {            "refusal": "project is required — the project's slug, from list_projects"          }        },        {          "tool": "link_to_project",          "args": {            "project": "gadgets",            "records": [              {                "kind": "recipe",                "id": "00000000-0000-4000-8000-000000000011"              }            ]          },          "rust": {            "refusal": "kind must be one of thread, email_thread, person, note, journal, todo, event, document, transaction, photo, video, memory, call, album, secret, repository"          },          "worker": {            "refusal": "kind must be one of thread, email_thread, person, note, journal, todo, event, document, photo, video, memory, call, album, secret"          }        },        {          "tool": "link_to_project",          "args": {            "project": "gadgets",            "records": [              {                "kind": "memory",                "id": "00000000-0000-4000-8000-000000000999"              }            ]          },          "expect": {            "refusal": "no memory with id 00000000-0000-4000-8000-000000000999 — nothing was linked; check the ids and call again"          }        }      ]    },    {      "name": "remember adds, then answers noop for the same sentence",      "seed": [        {          "kind": "project",          "id": "00000000-0000-4000-8000-000000000001",          "data": {            "slug": "widgets",            "name": "Widgets",            "repos": [],            "status": "active"          }        }      ],      "steps": [        {          "tool": "remember",          "args": {            "project": "widgets",            "title": "The kettle is descaled every Sunday."          },          "expect": {            "answer": {              "action": "add",              "slug": "the-kettle-is-descaled-every-sunday",              "project": "widgets",              "status": "active",              "note": "live in the next briefing"            }          }        },        {          "tool": "remember",          "args": {            "project": "widgets",            "title": "The kettle is descaled every Sunday."          },          "expect": {            "answer": {              "action": "noop",              "existing": {                "slug": "the-kettle-is-descaled-every-sunday",                "title": "The kettle is descaled every Sunday."              },              "note": "an entry already says this — nothing written; memory_update it if the wording should change"            }          }        },        {          "tool": "recall",          "args": {            "project": "widgets"          },          "rust": {            "answer": {              "memories": [                {                  "id": "<id1>",                  "slug": "the-kettle-is-descaled-every-sunday",                  "title": "The kettle is descaled every Sunday.",                  "projects": [                    {                      "slug": "widgets",                      "pinned": false,                      "position": 1000                    }                  ],                  "status": "active",                  "originKind": "agent",                  "originLabel": "Claude",                  "machine": null,                  "source": null,                  "supersededBy": null,                  "archivedAt": null,                  "createdAt": "<instant>",                  "updatedAt": "<instant>"                }              ]            }          },          "worker": {            "answer": {              "memories": [                {                  "id": "<id1>",                  "slug": "the-kettle-is-descaled-every-sunday",                  "title": "The kettle is descaled every Sunday.",                  "projects": [                    {                      "slug": "widgets",                      "pinned": false,                      "position": 1000                    }                  ],                  "status": "active",                  "originKind": "agent",                  "originLabel": "Claude",                  "machine": null,                  "source": null,                  "supersededBy": null,                  "archivedAt": null,                  "createdAt": "<instant>",                  "updatedAt": "<instant>",                  "unreviewed": true                }              ]            }          }        }      ]    }  ]}