add_decision
Record architecture choices, trade-offs, and deprecations as markdown files to persist key decisions in the repo's .ai-memory/decisions/ directory.
Instructions
Record a non-trivial decision made while working in this repo
(architecture choice, trade-off, deprecation, etc.) as a markdown file
under .ai-memory/decisions/.
Args: title: one-line headline of the decision. body: full markdown explanation — context, options considered, reasoning, who/when.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | ||
| body | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/repo_memory/store.py:228-240 (handler)Core handler function that creates a decision markdown file under `.ai-memory/decisions/`. Takes root path, title, and optional body. Generates a filename from date+slug, avoids clobbering by appending -2/-3 etc., writes the markdown content, and returns the path.
def add_decision(root: Path, title: str, body: str = "") -> Path: init(root) date = datetime.now(timezone.utc).strftime("%Y-%m-%d") name = f"{date}-{_slug(title)}.md" path = _memdir(root) / DECISIONS_DIR / name # Avoid clobber on same day, same slug n = 1 while path.exists(): n += 1 path = _memdir(root) / DECISIONS_DIR / f"{date}-{_slug(title)}-{n}.md" content = f"# {title.strip()}\n\n_Decided: {_now()}_\n\n{body.strip()}\n" path.write_text(content, encoding="utf-8") return path - src/repo_memory/mcp_server.py:67-79 (schema)MCP tool wrapper for add_decision. Defines the tool signature: title (str, required) and body (str, optional). Calls store.add_decision and returns a string confirming the written path. Decorated with @mcp.tool() to register with MCP.
@mcp.tool() def add_decision(title: str, body: str = "") -> str: """Record a non-trivial decision made while working in this repo (architecture choice, trade-off, deprecation, etc.) as a markdown file under `.ai-memory/decisions/`. Args: title: one-line headline of the decision. body: full markdown explanation — context, options considered, reasoning, who/when. """ path = store.add_decision(_REPO_ROOT, title, body) return f"wrote {path.relative_to(_REPO_ROOT)}" - src/repo_memory/mcp_server.py:67-67 (registration)The @mcp.tool() decorator on the add_decision function registers it as an MCP tool named 'add_decision'.
@mcp.tool() - src/repo_memory/cli.py:58-61 (registration)CLI sub-command registration for 'add-decision' using argparse. Defines the title positional argument and optional --body argument.
p_add_dec = sub.add_parser("add-decision", help="Add a decision document.") _add_root_arg(p_add_dec) p_add_dec.add_argument("title") p_add_dec.add_argument("--body", default="", help="Decision body (Markdown).") - src/repo_memory/store.py:223-225 (helper)Helper function _slug() that converts a title string to a filesystem-safe slug (max 60 chars), used by add_decision to construct the filename.
def _slug(text: str) -> str: s = re.sub(r"[^a-zA-Z0-9]+", "-", text.lower()).strip("-") return s[:60] or "decision"