diff --git a/README.md b/README.md index 730e2f9..cc90a24 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,16 @@ with path-stored fields: the pinned mdbase-ts and Rust CLI reject the starter until `sources.json` moves to engines that implement them. See [`mdbase.daily-note` 1.0.0](contracts/mdbase.daily-note/1.0.0.md). +The `mdbase.memory` pack defines memories that AI assistants share: one record +per thing to remember, indexed by a kebab-case `name`, a one-line `description` +and a `kind` (`user`, `feedback`, `project` or `reference`), with the memory +itself in the Markdown body. Assistants recall by listing the index and reading +only the bodies that matter, and update a memory on the same subject rather than +adding a duplicate. The **Memory** starter stores the name in the file name, +`Memories/.md`, with `collection.path.fields`, and puts the rules +assistants need into its description and field descriptions, which they read +before any body. See [`mdbase.memory` 1.0.0](contracts/mdbase.memory/1.0.0.md). + The `tasknotes.task` pack is the canonical application-provisioned TaskNotes contract bundle. TaskNotes clients embed the published provision byte-for-byte and pin its catalog digest so independently deployed clients cannot drift onto diff --git a/contracts/mdbase.memory/1.0.0.md b/contracts/mdbase.memory/1.0.0.md new file mode 100644 index 0000000..b3479c0 --- /dev/null +++ b/contracts/mdbase.memory/1.0.0.md @@ -0,0 +1,73 @@ +--- +kind: mdbase.contract +contract_type: record +id: mdbase.memory +version: 1.0.0 +name: Memory +description: One thing an AI assistant should remember about the person it works for, shared by every assistant that reaches the collection. +record_schema: + dialect: json-schema-2020-12 + ref: ../../schemas/mdbase.memory/1.0.0.schema.json +--- + +# Memory + +A record exposed through `mdbase.memory` holds one thing an assistant should +remember about the person it works for: who they are, how they want +assistants to work, what they are working on, or where to find something. +Several assistants, such as Claude, ChatGPT and Codex, read and write the same +memories, so what one learns the others can use. + +The Markdown body is the memory itself. The contract's fields are the index an +assistant reads before deciding which bodies to open. + +## Fields + +- `name` identifies the memory: a short kebab-case slug such as + `prefers-metric-units`. It is the memory's identity, never its path or file + name. An implementing type may store it in the path. +- `description` is one line, specific enough that an assistant can tell from + it alone whether the memory matters to the conversation at hand. +- `kind` is one of: + - `user`: who the person is, such as their role, expertise or circumstances; + - `feedback`: how they want assistants to work, including corrections and + approaches they confirmed; + - `project`: ongoing work, goals, decisions and dates not recorded elsewhere; + - `reference`: where to find things, such as documents, dashboards or + other collections. +- `by`, when present, names the assistant that saved or last changed the + memory, such as `Claude`. It is a display hint, not an identity or + authority. + +## One memory per name + +A collection should hold at most one memory per `name` across all types that +implement this contract. An application that finds several records with the +same name MUST report the duplicate and MUST NOT silently merge them or pick +one to change. Implementing types may declare `collection.unique` on their +name field so the engine reports duplicates within the type. + +## Recalling + +An assistant recalls by listing memories with only `name`, `description` and +`kind`, then reading the bodies of the few that matter to the conversation. +It does not read every body up front. + +## Saving + +Before saving, an assistant looks for an existing memory on the same subject +and updates it rather than adding another. One memory holds one subject. A +`feedback` or `project` body states the fact, then a line beginning `Why:` and +a line beginning `How to apply:`. Dates are written as absolute dates, never +as "yesterday" or "next week". Memories link to related memories as +`[[name]]`. + +A memory never holds passwords, keys, tokens or other secrets. + +## Forgetting + +Forgetting a memory deletes its record. Applications that show memories to +the person should let them read, correct and forget each one. + +This artifact is passive. Implementing it grants no authority to read, create, +or modify any record. diff --git a/dist/artifacts/contracts/mdbase.memory/1.0.0.md b/dist/artifacts/contracts/mdbase.memory/1.0.0.md new file mode 100644 index 0000000..b3479c0 --- /dev/null +++ b/dist/artifacts/contracts/mdbase.memory/1.0.0.md @@ -0,0 +1,73 @@ +--- +kind: mdbase.contract +contract_type: record +id: mdbase.memory +version: 1.0.0 +name: Memory +description: One thing an AI assistant should remember about the person it works for, shared by every assistant that reaches the collection. +record_schema: + dialect: json-schema-2020-12 + ref: ../../schemas/mdbase.memory/1.0.0.schema.json +--- + +# Memory + +A record exposed through `mdbase.memory` holds one thing an assistant should +remember about the person it works for: who they are, how they want +assistants to work, what they are working on, or where to find something. +Several assistants, such as Claude, ChatGPT and Codex, read and write the same +memories, so what one learns the others can use. + +The Markdown body is the memory itself. The contract's fields are the index an +assistant reads before deciding which bodies to open. + +## Fields + +- `name` identifies the memory: a short kebab-case slug such as + `prefers-metric-units`. It is the memory's identity, never its path or file + name. An implementing type may store it in the path. +- `description` is one line, specific enough that an assistant can tell from + it alone whether the memory matters to the conversation at hand. +- `kind` is one of: + - `user`: who the person is, such as their role, expertise or circumstances; + - `feedback`: how they want assistants to work, including corrections and + approaches they confirmed; + - `project`: ongoing work, goals, decisions and dates not recorded elsewhere; + - `reference`: where to find things, such as documents, dashboards or + other collections. +- `by`, when present, names the assistant that saved or last changed the + memory, such as `Claude`. It is a display hint, not an identity or + authority. + +## One memory per name + +A collection should hold at most one memory per `name` across all types that +implement this contract. An application that finds several records with the +same name MUST report the duplicate and MUST NOT silently merge them or pick +one to change. Implementing types may declare `collection.unique` on their +name field so the engine reports duplicates within the type. + +## Recalling + +An assistant recalls by listing memories with only `name`, `description` and +`kind`, then reading the bodies of the few that matter to the conversation. +It does not read every body up front. + +## Saving + +Before saving, an assistant looks for an existing memory on the same subject +and updates it rather than adding another. One memory holds one subject. A +`feedback` or `project` body states the fact, then a line beginning `Why:` and +a line beginning `How to apply:`. Dates are written as absolute dates, never +as "yesterday" or "next week". Memories link to related memories as +`[[name]]`. + +A memory never holds passwords, keys, tokens or other secrets. + +## Forgetting + +Forgetting a memory deletes its record. Applications that show memories to +the person should let them read, correct and forget each one. + +This artifact is passive. Implementing it grants no authority to read, create, +or modify any record. diff --git a/dist/artifacts/schemas/mdbase.memory/1.0.0.schema.json b/dist/artifacts/schemas/mdbase.memory/1.0.0.schema.json new file mode 100644 index 0000000..fcb8de2 --- /dev/null +++ b/dist/artifacts/schemas/mdbase.memory/1.0.0.schema.json @@ -0,0 +1,42 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://mdbase.dev/contracts/schemas/mdbase.memory/1.0.0.schema.json", + "title": "Memory", + "description": "One thing an AI assistant should remember about the person it works for. The Markdown body is the memory itself.", + "type": "object", + "required": [ + "name", + "description", + "kind" + ], + "properties": { + "name": { + "type": "string", + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$", + "maxLength": 80, + "description": "Short kebab-case identifier for the memory, unique in the collection." + }, + "description": { + "type": "string", + "minLength": 1, + "maxLength": 200, + "description": "One line saying what the memory is about, specific enough to decide from it alone whether to read it." + }, + "kind": { + "enum": [ + "user", + "feedback", + "project", + "reference" + ], + "description": "user: who the person is. feedback: how they want assistants to work. project: ongoing work, goals and dates. reference: where to find things." + }, + "by": { + "type": "string", + "minLength": 1, + "maxLength": 80, + "description": "The assistant that saved or last changed the memory, such as Claude, ChatGPT or Codex." + } + }, + "additionalProperties": false +} diff --git a/dist/artifacts/types/memory/1.md b/dist/artifacts/types/memory/1.md new file mode 100644 index 0000000..d183eba --- /dev/null +++ b/dist/artifacts/types/memory/1.md @@ -0,0 +1,90 @@ +--- +kind: mdbase.type +name: memory +version: 1 +description: 'Something an AI assistant should remember about the person it works for, one per note in Memories/. To recall, list only name, description and kind, then read the few that matter. Update an existing memory rather than adding a duplicate. Never store passwords, keys or other secrets.' +match: + path_glob: 'Memories/*.md' +schema: + dialect: json-schema-2020-12 + value: + $schema: https://json-schema.org/draft/2020-12/schema + title: Memory + description: One thing to remember, written in the note's body. The name is stored in the file name. + type: object + required: + - name + - description + - kind + properties: + name: + type: string + pattern: '^[a-z0-9]+(-[a-z0-9]+)*$' + maxLength: 80 + description: Short kebab-case identifier, such as prefers-metric-units. It is the file name (Memories/prefers-metric-units.md), so changing it renames the note. + description: + type: string + minLength: 1 + maxLength: 200 + description: One line saying what this memory is about, specific enough to decide from it alone whether to read the note. + kind: + enum: + - user + - feedback + - project + - reference + description: 'user: who the person is. feedback: how they want assistants to work, including corrections and confirmed approaches. project: ongoing work, goals and dates not recorded elsewhere. reference: where to find things. For feedback and project memories, the body states the fact, then a "Why:" line and a "How to apply:" line. Write dates as absolute dates.' + by: + type: string + minLength: 1 + maxLength: 80 + description: The assistant that saved or last changed this memory, such as Claude, ChatGPT or Codex. + additionalProperties: true +collection: + path: + pattern: 'Memories/{name}.md' + fields: + - name + unique: + - field: name + scope: type + display: + name_field: description + icon: brain +implements: + - contract: mdbase.memory + version: 1.0.0 + fields: + name: name + description: description + kind: kind + by: by +--- + +# Memory + +One thing an assistant should remember about you, at `Memories/.md`. +The note's body is the memory; its frontmatter is the index assistants read +first. + +```markdown +--- +description: Prefers metric units and 24-hour times in every answer +kind: feedback +by: Claude +--- +Use kilometres, kilograms, Celsius and 24-hour times. + +Why: they find imperial units and am/pm slow to read. +How to apply: convert any figures a source gives in other units. +``` + +Assistants that reach this collection through mdbase recall by listing each +memory's name, description and kind, then reading the few that matter. When +they learn something worth keeping, they update the memory on that subject or +add a new one. You can read, correct or delete any memory here yourself. + +This type belongs to your collection once installed. Apps find memories +through the `mdbase.memory` contract, not through this folder, so you can move +them by changing both `match.path_glob` and `collection.path.pattern`, or add +fields of your own. diff --git a/dist/catalog.json b/dist/catalog.json index 590e630..50e13dd 100644 --- a/dist/catalog.json +++ b/dist/catalog.json @@ -59,6 +59,16 @@ "artifact": "./artifacts/contracts/mdbase.daily-note/1.0.0.md", "standards": [] }, + { + "id": "mdbase.memory", + "version": "1.0.0", + "name": "Memory", + "description": "One thing an AI assistant should remember about the person it works for, shared by every assistant that reaches the collection.", + "contract_type": "record", + "digest": "sha256:09d16184787c403222d33ff0449569f664e3d12bd83c5368e2de1adbae93a52f", + "artifact": "./artifacts/contracts/mdbase.memory/1.0.0.md", + "standards": [] + }, { "id": "mdbase.person", "version": "1.0.0", @@ -744,6 +754,44 @@ ] } }, + { + "id": "mdbase.memory", + "version": "1.0.0", + "name": "Memories", + "description": "The mdbase.memory contract and an editable Memory type that AI assistants share.", + "digest": "sha256:c6453eaeea05efef616ad4282e131ad933535c9a1cb1df6fa0859e36541df2cd", + "provision": "./packs/mdbase.memory/1.0.0.json", + "provides": [ + { + "id": "mdbase.memory", + "version": "1.0.0", + "digest": "sha256:0db69a68f706a216c3cf133af84dd600928c3637d49d51b707b499ddb7407bd6" + } + ], + "resource_count": 3, + "display": { + "name": "Memories", + "summary": "Keep what your AI assistants remember about you in one place that Claude, ChatGPT and others all read and update.", + "category": "other", + "audience": "general", + "icon": "brain", + "badges": [ + "Shared AI memory" + ] + }, + "installation": { + "visibility": "default", + "recommendation": "optional", + "primary_type": "memory", + "caution": "Requires an mdbase engine with path-stored fields (mdbase 0.3.0-rc.6). Older engines reject the Memory type, which keeps each memory's name in its file name.", + "types": [ + { + "name": "memory", + "label": "Memory" + } + ] + } + }, { "id": "mdbase.runtime.standard", "version": "0.2.0", diff --git a/dist/packs/mdbase.memory/1.0.0.json b/dist/packs/mdbase.memory/1.0.0.json new file mode 100644 index 0000000..a7c326d --- /dev/null +++ b/dist/packs/mdbase.memory/1.0.0.json @@ -0,0 +1,53 @@ +{ + "manifest": { + "kind": "mdbase.type-pack", + "id": "mdbase.memory", + "version": "1.0.0", + "name": "Memories", + "description": "The mdbase.memory contract and an editable Memory type that AI assistants share.", + "resources": [ + { + "kind": "schema", + "mode": "managed", + "source": "schemas/mdbase.memory/1.0.0.schema.json", + "target": "schemas/mdbase.memory/1.0.0.schema.json", + "digest": "sha256:0bd047f3bed5016aaddcfdd82ff6afabe3c6e45f77a6722e039b693b547c9038" + }, + { + "kind": "contract", + "mode": "managed", + "source": "contracts/mdbase.memory/1.0.0.md", + "target": "_contracts/mdbase.memory/1.0.0.md", + "digest": "sha256:09d16184787c403222d33ff0449569f664e3d12bd83c5368e2de1adbae93a52f" + }, + { + "kind": "type", + "mode": "seed", + "source": "types/memory/1.md", + "target": "_types/memory.md", + "digest": "sha256:29578f3826f9e5d20a54246ccb2a8ac8e7e3bfda72358721c319188f40cddee9" + } + ] + }, + "resources": [ + { + "source": "schemas/mdbase.memory/1.0.0.schema.json", + "document": "{\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n \"$id\": \"https://mdbase.dev/contracts/schemas/mdbase.memory/1.0.0.schema.json\",\n \"title\": \"Memory\",\n \"description\": \"One thing an AI assistant should remember about the person it works for. The Markdown body is the memory itself.\",\n \"type\": \"object\",\n \"required\": [\n \"name\",\n \"description\",\n \"kind\"\n ],\n \"properties\": {\n \"name\": {\n \"type\": \"string\",\n \"pattern\": \"^[a-z0-9]+(-[a-z0-9]+)*$\",\n \"maxLength\": 80,\n \"description\": \"Short kebab-case identifier for the memory, unique in the collection.\"\n },\n \"description\": {\n \"type\": \"string\",\n \"minLength\": 1,\n \"maxLength\": 200,\n \"description\": \"One line saying what the memory is about, specific enough to decide from it alone whether to read it.\"\n },\n \"kind\": {\n \"enum\": [\n \"user\",\n \"feedback\",\n \"project\",\n \"reference\"\n ],\n \"description\": \"user: who the person is. feedback: how they want assistants to work. project: ongoing work, goals and dates. reference: where to find things.\"\n },\n \"by\": {\n \"type\": \"string\",\n \"minLength\": 1,\n \"maxLength\": 80,\n \"description\": \"The assistant that saved or last changed the memory, such as Claude, ChatGPT or Codex.\"\n }\n },\n \"additionalProperties\": false\n}\n" + }, + { + "source": "contracts/mdbase.memory/1.0.0.md", + "document": "---\nkind: mdbase.contract\ncontract_type: record\nid: mdbase.memory\nversion: 1.0.0\nname: Memory\ndescription: One thing an AI assistant should remember about the person it works for, shared by every assistant that reaches the collection.\nrecord_schema:\n dialect: json-schema-2020-12\n ref: ../../schemas/mdbase.memory/1.0.0.schema.json\n---\n\n# Memory\n\nA record exposed through `mdbase.memory` holds one thing an assistant should\nremember about the person it works for: who they are, how they want\nassistants to work, what they are working on, or where to find something.\nSeveral assistants, such as Claude, ChatGPT and Codex, read and write the same\nmemories, so what one learns the others can use.\n\nThe Markdown body is the memory itself. The contract's fields are the index an\nassistant reads before deciding which bodies to open.\n\n## Fields\n\n- `name` identifies the memory: a short kebab-case slug such as\n `prefers-metric-units`. It is the memory's identity, never its path or file\n name. An implementing type may store it in the path.\n- `description` is one line, specific enough that an assistant can tell from\n it alone whether the memory matters to the conversation at hand.\n- `kind` is one of:\n - `user`: who the person is, such as their role, expertise or circumstances;\n - `feedback`: how they want assistants to work, including corrections and\n approaches they confirmed;\n - `project`: ongoing work, goals, decisions and dates not recorded elsewhere;\n - `reference`: where to find things, such as documents, dashboards or\n other collections.\n- `by`, when present, names the assistant that saved or last changed the\n memory, such as `Claude`. It is a display hint, not an identity or\n authority.\n\n## One memory per name\n\nA collection should hold at most one memory per `name` across all types that\nimplement this contract. An application that finds several records with the\nsame name MUST report the duplicate and MUST NOT silently merge them or pick\none to change. Implementing types may declare `collection.unique` on their\nname field so the engine reports duplicates within the type.\n\n## Recalling\n\nAn assistant recalls by listing memories with only `name`, `description` and\n`kind`, then reading the bodies of the few that matter to the conversation.\nIt does not read every body up front.\n\n## Saving\n\nBefore saving, an assistant looks for an existing memory on the same subject\nand updates it rather than adding another. One memory holds one subject. A\n`feedback` or `project` body states the fact, then a line beginning `Why:` and\na line beginning `How to apply:`. Dates are written as absolute dates, never\nas \"yesterday\" or \"next week\". Memories link to related memories as\n`[[name]]`.\n\nA memory never holds passwords, keys, tokens or other secrets.\n\n## Forgetting\n\nForgetting a memory deletes its record. Applications that show memories to\nthe person should let them read, correct and forget each one.\n\nThis artifact is passive. Implementing it grants no authority to read, create,\nor modify any record.\n" + }, + { + "source": "types/memory/1.md", + "document": "---\nkind: mdbase.type\nname: memory\nversion: 1\ndescription: 'Something an AI assistant should remember about the person it works for, one per note in Memories/. To recall, list only name, description and kind, then read the few that matter. Update an existing memory rather than adding a duplicate. Never store passwords, keys or other secrets.'\nmatch:\n path_glob: 'Memories/*.md'\nschema:\n dialect: json-schema-2020-12\n value:\n $schema: https://json-schema.org/draft/2020-12/schema\n title: Memory\n description: One thing to remember, written in the note's body. The name is stored in the file name.\n type: object\n required:\n - name\n - description\n - kind\n properties:\n name:\n type: string\n pattern: '^[a-z0-9]+(-[a-z0-9]+)*$'\n maxLength: 80\n description: Short kebab-case identifier, such as prefers-metric-units. It is the file name (Memories/prefers-metric-units.md), so changing it renames the note.\n description:\n type: string\n minLength: 1\n maxLength: 200\n description: One line saying what this memory is about, specific enough to decide from it alone whether to read the note.\n kind:\n enum:\n - user\n - feedback\n - project\n - reference\n description: 'user: who the person is. feedback: how they want assistants to work, including corrections and confirmed approaches. project: ongoing work, goals and dates not recorded elsewhere. reference: where to find things. For feedback and project memories, the body states the fact, then a \"Why:\" line and a \"How to apply:\" line. Write dates as absolute dates.'\n by:\n type: string\n minLength: 1\n maxLength: 80\n description: The assistant that saved or last changed this memory, such as Claude, ChatGPT or Codex.\n additionalProperties: true\ncollection:\n path:\n pattern: 'Memories/{name}.md'\n fields:\n - name\n unique:\n - field: name\n scope: type\n display:\n name_field: description\n icon: brain\nimplements:\n - contract: mdbase.memory\n version: 1.0.0\n fields:\n name: name\n description: description\n kind: kind\n by: by\n---\n\n# Memory\n\nOne thing an assistant should remember about you, at `Memories/.md`.\nThe note's body is the memory; its frontmatter is the index assistants read\nfirst.\n\n```markdown\n---\ndescription: Prefers metric units and 24-hour times in every answer\nkind: feedback\nby: Claude\n---\nUse kilometres, kilograms, Celsius and 24-hour times.\n\nWhy: they find imperial units and am/pm slow to read.\nHow to apply: convert any figures a source gives in other units.\n```\n\nAssistants that reach this collection through mdbase recall by listing each\nmemory's name, description and kind, then reading the few that matter. When\nthey learn something worth keeping, they update the memory on that subject or\nadd a new one. You can read, correct or delete any memory here yourself.\n\nThis type belongs to your collection once installed. Apps find memories\nthrough the `mdbase.memory` contract, not through this folder, so you can move\nthem by changing both `match.path_glob` and `collection.path.pattern`, or add\nfields of your own.\n" + } + ], + "provides": [ + { + "id": "mdbase.memory", + "version": "1.0.0", + "digest": "sha256:0db69a68f706a216c3cf133af84dd600928c3637d49d51b707b499ddb7407bd6" + } + ] +} diff --git a/dist/schemas/mdbase.memory/1.0.0.schema.json b/dist/schemas/mdbase.memory/1.0.0.schema.json new file mode 100644 index 0000000..fcb8de2 --- /dev/null +++ b/dist/schemas/mdbase.memory/1.0.0.schema.json @@ -0,0 +1,42 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://mdbase.dev/contracts/schemas/mdbase.memory/1.0.0.schema.json", + "title": "Memory", + "description": "One thing an AI assistant should remember about the person it works for. The Markdown body is the memory itself.", + "type": "object", + "required": [ + "name", + "description", + "kind" + ], + "properties": { + "name": { + "type": "string", + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$", + "maxLength": 80, + "description": "Short kebab-case identifier for the memory, unique in the collection." + }, + "description": { + "type": "string", + "minLength": 1, + "maxLength": 200, + "description": "One line saying what the memory is about, specific enough to decide from it alone whether to read it." + }, + "kind": { + "enum": [ + "user", + "feedback", + "project", + "reference" + ], + "description": "user: who the person is. feedback: how they want assistants to work. project: ongoing work, goals and dates. reference: where to find things." + }, + "by": { + "type": "string", + "minLength": 1, + "maxLength": 80, + "description": "The assistant that saved or last changed the memory, such as Claude, ChatGPT or Codex." + } + }, + "additionalProperties": false +} diff --git a/package.json b/package.json index 3f3e2dc..5f26f73 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "node scripts/build.mjs", "expand:type": "node scripts/expand-type.mjs", "verify": "node scripts/verify.mjs", - "test": "node --test scripts/schema-expansion.test.mjs scripts/person-contract.test.mjs scripts/comment-contract.test.mjs scripts/daily-note-contract.test.mjs scripts/starter-type-keys.test.mjs && npm run build && npm run verify && node --test scripts/seed-baselines.test.mjs scripts/contract-retention.test.mjs scripts/seed-upgrade.test.mjs scripts/person-pack.test.mjs scripts/tasknotes-upgrade.test.mjs scripts/tasknotes-plugin-collections.test.mjs" + "test": "node --test scripts/schema-expansion.test.mjs scripts/person-contract.test.mjs scripts/comment-contract.test.mjs scripts/daily-note-contract.test.mjs scripts/memory-contract.test.mjs scripts/starter-type-keys.test.mjs && npm run build && npm run verify && node --test scripts/seed-baselines.test.mjs scripts/contract-retention.test.mjs scripts/seed-upgrade.test.mjs scripts/person-pack.test.mjs scripts/tasknotes-upgrade.test.mjs scripts/tasknotes-plugin-collections.test.mjs" }, "dependencies": { "ajv": "^8.20.0", diff --git a/packs/mdbase.memory/1.0.0.pack.yaml b/packs/mdbase.memory/1.0.0.pack.yaml new file mode 100644 index 0000000..07936b6 --- /dev/null +++ b/packs/mdbase.memory/1.0.0.pack.yaml @@ -0,0 +1,34 @@ +kind: mdbase.catalog-pack +id: mdbase.memory +version: 1.0.0 +name: Memories +description: The mdbase.memory contract and an editable Memory type that AI assistants share. +display: + name: Memories + summary: Keep what your AI assistants remember about you in one place that Claude, ChatGPT and others all read and update. + category: other + audience: general + icon: brain + badges: + - Shared AI memory +installation: + visibility: default + recommendation: optional + primary_type: memory + caution: Requires an mdbase engine with path-stored fields (mdbase 0.3.0-rc.6). Older engines reject the Memory type, which keeps each memory's name in its file name. +provides: + - id: mdbase.memory + version: 1.0.0 +resources: + - kind: schema + mode: managed + source: schemas/mdbase.memory/1.0.0.schema.json + target: schemas/mdbase.memory/1.0.0.schema.json + - kind: contract + mode: managed + source: contracts/mdbase.memory/1.0.0.md + target: _contracts/mdbase.memory/1.0.0.md + - kind: type + mode: seed + source: types/memory/1.md + target: _types/memory.md diff --git a/schemas/mdbase.memory/1.0.0.schema.json b/schemas/mdbase.memory/1.0.0.schema.json new file mode 100644 index 0000000..fcb8de2 --- /dev/null +++ b/schemas/mdbase.memory/1.0.0.schema.json @@ -0,0 +1,42 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://mdbase.dev/contracts/schemas/mdbase.memory/1.0.0.schema.json", + "title": "Memory", + "description": "One thing an AI assistant should remember about the person it works for. The Markdown body is the memory itself.", + "type": "object", + "required": [ + "name", + "description", + "kind" + ], + "properties": { + "name": { + "type": "string", + "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$", + "maxLength": 80, + "description": "Short kebab-case identifier for the memory, unique in the collection." + }, + "description": { + "type": "string", + "minLength": 1, + "maxLength": 200, + "description": "One line saying what the memory is about, specific enough to decide from it alone whether to read it." + }, + "kind": { + "enum": [ + "user", + "feedback", + "project", + "reference" + ], + "description": "user: who the person is. feedback: how they want assistants to work. project: ongoing work, goals and dates. reference: where to find things." + }, + "by": { + "type": "string", + "minLength": 1, + "maxLength": 80, + "description": "The assistant that saved or last changed the memory, such as Claude, ChatGPT or Codex." + } + }, + "additionalProperties": false +} diff --git a/scripts/memory-contract.test.mjs b/scripts/memory-contract.test.mjs new file mode 100644 index 0000000..2c40429 --- /dev/null +++ b/scripts/memory-contract.test.mjs @@ -0,0 +1,78 @@ +import assert from "node:assert/strict"; +import { readFile } from "node:fs/promises"; +import test from "node:test"; +import Ajv2020 from "ajv/dist/2020.js"; +import addFormats from "ajv-formats"; +import matter from "gray-matter"; + +const root = new URL("../", import.meta.url); +const contractSchema = JSON.parse(await readFile(new URL( + "schemas/mdbase.memory/1.0.0.schema.json", root, +), "utf8")); +const starter = matter(await readFile(new URL("types/memory/1.md", root), "utf8")).data; +const ajv = new Ajv2020({ allErrors: true, strict: true }); +addFormats(ajv); +const validateContract = ajv.compile(contractSchema); +const validateStarter = ajv.compile(starter.schema.value); +const memory = { name: "prefers-metric-units", description: "Prefers metric units and 24-hour times", kind: "feedback" }; + +test("a memory is a kebab-case name, a one-line description and a kind", () => { + for (const validate of [validateContract, validateStarter]) { + assert.equal(validate(memory), true, ajv.errorsText(validate.errors)); + assert.equal(validate({ ...memory, by: "Claude" }), true, ajv.errorsText(validate.errors)); + for (const kind of ["user", "feedback", "project", "reference"]) { + assert.equal(validate({ ...memory, kind }), true, kind); + } + for (const key of ["name", "description", "kind"]) { + const { [key]: _omitted, ...rest } = memory; + assert.equal(validate(rest), false, `accepted a memory without ${key}`); + } + for (const name of ["Prefers metric", "prefers_metric", "-metric", "metric-", "metric--units", "a".repeat(81)]) { + assert.equal(validate({ ...memory, name }), false, `accepted name ${JSON.stringify(name)}`); + } + for (const description of ["", "x".repeat(201)]) { + assert.equal(validate({ ...memory, description }), false, `accepted a ${description.length}-character description`); + } + assert.equal(validate({ ...memory, kind: "preference" }), false); + assert.equal(validate({ ...memory, by: "" }), false); + } +}); + +test("the contract view is only the index; the starter keeps the note's other fields", () => { + assert.equal(validateContract({ ...memory, tags: ["home"] }), false); + assert.equal(validateStarter({ ...memory, tags: ["home"] }), true); +}); + +test("the starter stores the name in the path and maps every contract field", () => { + const { path, unique, display } = starter.collection; + assert.deepEqual(path, { pattern: "Memories/{name}.md", fields: ["name"] }); + assert.deepEqual(unique, [{ field: "name", scope: "type" }]); + assert.equal(display.name_field, "description"); + assert.deepEqual(starter.implements, [{ + contract: "mdbase.memory", + version: "1.0.0", + fields: { name: "name", description: "description", kind: "kind", by: "by" }, + }]); + assert.deepEqual(Object.keys(starter.implements[0].fields).sort(), Object.keys(contractSchema.properties).sort()); +}); + +test("the starter's index carries the rules an assistant reads before any body", () => { + // Assistants see a type's description and field descriptions when they + // describe a collection, not the type document's body. + assert.match(starter.description, /list only name, description and kind/); + assert.match(starter.description, /Update an existing memory rather than adding a duplicate/); + assert.match(starter.description, /Never store passwords, keys or other secrets/); + assert.match(starter.schema.value.properties.kind.description, /"Why:" line and a "How to apply:" line/); + assert.match(starter.schema.value.properties.kind.description, /absolute dates/); +}); + +test("the starter matches notes in its pattern's folder only", () => { + const glob = starter.match.path_glob; + const folder = path => path.slice(0, path.lastIndexOf("/") + 1); + assert.equal(folder(glob), folder(starter.collection.path.pattern)); + const pattern = new RegExp(`^${glob.replace(/[.]/g, "\\.").replace(/\*/g, "[^/]*")}$`); + assert.match("Memories/prefers-metric-units.md", pattern); + for (const path of ["prefers-metric-units.md", "Memories/archive/old.md", "Notes/prefers-metric-units.md"]) { + assert.doesNotMatch(path, pattern); + } +}); diff --git a/scripts/starter-type-keys.test.mjs b/scripts/starter-type-keys.test.mjs index 39b2ba6..3d9aa3b 100644 --- a/scripts/starter-type-keys.test.mjs +++ b/scripts/starter-type-keys.test.mjs @@ -13,7 +13,7 @@ const runtimeTypes = [ "action-attempt", "capability-grant", "checkpoint", "dead-letter", "diagnostic", "policy", "provider-registration", "run", "timer", "workflow" ].map((slug) => `types/mdbase-runtime/v2/${slug}.md`); -for (const source of ["types/person/3.md", "types/comment/2.md", "types/view/2.md", "types/daily-note/1.md", ...runtimeTypes]) { +for (const source of ["types/person/3.md", "types/comment/2.md", "types/view/2.md", "types/daily-note/1.md", "types/memory/1.md", ...runtimeTypes]) { test(`${source} leaves the type key to the collection`, async () => { const type = matter(await readFile(new URL(source, root), "utf8")).data; const schema = type.schema.value; diff --git a/types/memory/1.md b/types/memory/1.md new file mode 100644 index 0000000..d183eba --- /dev/null +++ b/types/memory/1.md @@ -0,0 +1,90 @@ +--- +kind: mdbase.type +name: memory +version: 1 +description: 'Something an AI assistant should remember about the person it works for, one per note in Memories/. To recall, list only name, description and kind, then read the few that matter. Update an existing memory rather than adding a duplicate. Never store passwords, keys or other secrets.' +match: + path_glob: 'Memories/*.md' +schema: + dialect: json-schema-2020-12 + value: + $schema: https://json-schema.org/draft/2020-12/schema + title: Memory + description: One thing to remember, written in the note's body. The name is stored in the file name. + type: object + required: + - name + - description + - kind + properties: + name: + type: string + pattern: '^[a-z0-9]+(-[a-z0-9]+)*$' + maxLength: 80 + description: Short kebab-case identifier, such as prefers-metric-units. It is the file name (Memories/prefers-metric-units.md), so changing it renames the note. + description: + type: string + minLength: 1 + maxLength: 200 + description: One line saying what this memory is about, specific enough to decide from it alone whether to read the note. + kind: + enum: + - user + - feedback + - project + - reference + description: 'user: who the person is. feedback: how they want assistants to work, including corrections and confirmed approaches. project: ongoing work, goals and dates not recorded elsewhere. reference: where to find things. For feedback and project memories, the body states the fact, then a "Why:" line and a "How to apply:" line. Write dates as absolute dates.' + by: + type: string + minLength: 1 + maxLength: 80 + description: The assistant that saved or last changed this memory, such as Claude, ChatGPT or Codex. + additionalProperties: true +collection: + path: + pattern: 'Memories/{name}.md' + fields: + - name + unique: + - field: name + scope: type + display: + name_field: description + icon: brain +implements: + - contract: mdbase.memory + version: 1.0.0 + fields: + name: name + description: description + kind: kind + by: by +--- + +# Memory + +One thing an assistant should remember about you, at `Memories/.md`. +The note's body is the memory; its frontmatter is the index assistants read +first. + +```markdown +--- +description: Prefers metric units and 24-hour times in every answer +kind: feedback +by: Claude +--- +Use kilometres, kilograms, Celsius and 24-hour times. + +Why: they find imperial units and am/pm slow to read. +How to apply: convert any figures a source gives in other units. +``` + +Assistants that reach this collection through mdbase recall by listing each +memory's name, description and kind, then reading the few that matter. When +they learn something worth keeping, they update the memory on that subject or +add a new one. You can read, correct or delete any memory here yourself. + +This type belongs to your collection once installed. Apps find memories +through the `mdbase.memory` contract, not through this folder, so you can move +them by changing both `match.path_glob` and `collection.path.pattern`, or add +fields of your own.