Commit graph

4 commits

Author SHA1 Message Date
Himanshu Dongre
ec0139f707 Add Smriti agent skill pack source and renderer
The skill pack is an instruction file installed into an agent host's
project directory so Smriti's workflow lives in the agent's system
context instead of documentation nobody reads. A single versioned
template.md renders for both Claude Code (MCP-primary) and Codex
(CLI-primary) via a pure-function substituter, keeping content in
sync mechanically across targets.

template.md contains 15 sections. The load-bearing one is Section 5,
When NOT to checkpoint, with equal weight to Section 4. Agents are
told explicitly not to checkpoint after every small step, not to
produce end-of-session blobs, not to treat commits as a save button,
not to stack commits on inconsistent state, not to restate existing
state, and not to checkpoint just because the user asked when there
is no real inflection point. A frequency target (2-4 checkpoints per
4-hour session) and a three-question signal test give agents concrete
criteria for every call.

Other sections cover the read-state-first reflex, when to fork, when
to review, when to compare, when to restore, drift detection,
explicit anti-patterns (HANDOFF.md, silent state reads, inconsistent
author_agent, /chat/send), and the phrases the agent should say out
loud so the human watching has an audit trail.

Renderer API (all pure functions): load_template, get_version, render,
install. install is version-aware: refuses to overwrite a destination
whose installed version is >= the template version unless force=True.
Dry-run mode returns the rendered content without writing.

Content-integrity tests parametrized over both targets assert that
every anti-pattern rule, the signal test, the frequency target, and
the drift-detection guidance appear in the rendered output. If a
future template edit drops any of them, tests fail loudly.

22 skill pack tests, all green.
2026-04-12 02:07:47 +05:30
Himanshu Dongre
2258231c30 Add MCP server wrapping all CLI commands as 12 tools
Round 4 validated that the Smriti CLI surface is complete. This is the
next transport: an MCP stdio server that exposes the same operations as
tools inside MCP-aware hosts (Claude Code, Cursor, Windsurf) so agents
can read and write reasoning state natively in their session instead of
shelling out to the `smriti` binary.

The server lives inside the existing CLI package as a sibling to
client.py and main.py. One `pip install -e ./cli` installs both the
`smriti` and `smriti-mcp` console scripts. Architecture is a thin shim:
each tool builds a SmritiClient, calls 1-2 client methods, pipes the
result through an existing formatter, and returns a string. FastMCP
auto-wraps the string into TextContent. Errors raise SmritiToolError
(wrapping SmritiError with HTTP status + structured detail); FastMCP
converts raised exceptions into MCP error responses.

Zero reimplementation of API logic, zero duplicated formatting, zero
changes to client.py, formatters.py, main.py, or the backend.

Twelve tools, 1:1 with the CLI verbs:

  smriti_list_spaces        smriti_state
  smriti_create_space       smriti_list_checkpoints
  smriti_delete_space       smriti_show_checkpoint
  smriti_create_checkpoint  smriti_review_checkpoint
  smriti_delete_checkpoint  smriti_restore
  smriti_fork               smriti_compare

Two deliberate differences from the CLI:

  - No `-y` confirmation flag on destructive tools. The MCP host's
    tool-approval UI is the gate.
  - smriti_create_checkpoint uses the extract path only (no
    --from-json mode) and does NOT auto-capture cwd as project_root.
    MCP servers run in the host's arbitrary working directory, so
    cwd would plant garbage paths. Callers pass project_root
    explicitly when they want it populated.

Testing: 33 unit tests across all 12 tools using a
MagicMock(spec=SmritiClient) fixture in tests/conftest.py. Each tool
has at least one happy path and one error path; the complex ones
(smriti_state, smriti_create_checkpoint, smriti_delete_checkpoint)
have extra tests for their branches (no-checkpoints short-circuit,
dry-run, existing-session, 409-with-dependents formatting,
409-with-non-dict-fallback, empty-content pre-check).

End-to-end stdio protocol smoke verified independently: the
`smriti-mcp` binary responds to `initialize` with protocol version
2025-03-26 and returns all 12 tools on `tools/list`. Ready for
`mcp dev smriti_cli.mcp_server:mcp` Inspector UI exploration or
direct Claude Code connection.

cli/README.md gets a new MCP server section with installation,
example Claude Code config, tool list, and notes on the project_root
and confirmation-gate differences from the CLI.
2026-04-12 00:54:40 +05:30
Himanshu Dongre
e5db6d8116 Add mcp dependency and pytest harness skeleton
First two steps of V3 Build 2 (the MCP server transport):

  - Pin `mcp>=1.27.0,<2.0.0` in cli/pyproject.toml. FastMCP has been
    the high-level API across the entire 1.x line and is what the
    server will use for tool registration. Verified importable as
    `from mcp.server.fastmcp import FastMCP`.
  - Add `[project.optional-dependencies].dev` with pytest>=7.0 and
    `[tool.pytest.ini_options]` so `pip install -e "./cli[dev]"`
    gets the full dev loop. The cli package previously had no tests.
  - Create cli/tests/ with __init__.py, an empty conftest.py (soon
    to host the shared mock_client fixture), and a smoke test that
    just confirms `smriti_cli` imports. Gives us a working `pytest`
    command from the first commit.

The `smriti-mcp` entry point + actual MCP server code land in the
next commit alongside mcp_server.py so every commit leaves the
package in an installable state.
2026-04-12 00:46:34 +05:30
Himanshu Dongre
89b6df16cf Add CLI for agent and programmatic access
Introduce a thin Python CLI that wraps the backend REST API. Seven
commands: space list, space create, state, checkpoint create,
checkpoint show, checkpoint list, checkpoint review. Reads piped
JSON on stdin for checkpoint create, prints a continuation-oriented
markdown brief for state. Supports --json on every command for
structured output.

Fixes a V2 schema drift where the commit response omitted
assumptions and artifacts, so the CLI can read full checkpoints
via the cleaner V2 single-resource endpoints. Updates README,
ARCHITECTURE, and DECISIONS to frame Smriti as a reasoning-state
backend with the chat UI and CLI as two clients of the same core.
2026-04-11 11:10:01 +05:30