Instructions for AI coding agents working on the primkit codebase, and pointers for agents using primkit as a tool.
One-time setup after cloning:
bash scripts/install-hooks.shThis installs a pre-commit hook that runs make docs-check before each commit,
preventing you from committing stale documentation.
See the Agent Reference for structured command tables, JSON output schemas, decision trees, and error handling patterns for all four primitives (taskprim, stateprim, knowledgeprim, queueprim).
For knowledgeprim usage strategy (entity types, relationships, search modes, discovery workflows), see the knowledgeprim Guide.
make build # Build bin/taskprim, bin/stateprim, bin/knowledgeprim, bin/queueprim
make test # Run all tests across all modules, race detector
make lint # go vet on all modules
make fmt # gofmt -s -w on all modules
make tidy # go mod tidy on all modulesSingle module:
cd taskprim && go test -v -race -count=1 ./...
cd stateprim && go test -v -race -count=1 ./...
cd knowledgeprim && go test -v -race -count=1 ./...
cd queueprim && go test -v -race -count=1 ./...
cd primkit && go test -v -race -count=1 ./...- Go 1.26+
- Pure Go SQLite (
modernc.org/sqlite) — no CGo - CLI:
github.com/spf13/cobra - Config:
gopkg.in/yaml.v3+ env var overrides - IDs:
github.com/matoous/go-nanoid/v2 - Tests:
github.com/stretchr/testify - MCP:
github.com/mark3labs/mcp-go
primkit/
├── primkit/ # Shared library (config, db, auth, server, mcp, replicate)
├── taskprim/ # Task management primitive
├── stateprim/ # State persistence primitive
├── knowledgeprim/ # Knowledge graph primitive
├── queueprim/ # Work queue primitive
├── go.work # Go workspace (5 modules)
└── Makefile # Build targets
Each primitive follows identical internal layout:
<primitive>/
├── cmd/<primitive>/ # main.go entrypoint
└── internal/
├── model/ # Domain structs, validation, state machine
├── store/ # Store interface + SQLite implementation
├── cli/ # Cobra commands (one file per command)
├── api/ # HTTP API handler
└── mcpserver/ # MCP tool registrations
knowledgeprim additionally has internal/embed/ for the embedding provider abstraction. queueprim's store runs a background sweeper goroutine (in serve/mcp modes) that releases claimed jobs whose visibility timeout has expired.
- Standard Go conventions:
gofmt,go vet - Each CLI command in its own file (
add.go,search.go,capture.go) - Command pattern: parse flags -> call store -> format output
- Tests use
testify/assertandtestify/require - All tests use in-memory SQLite (
db.OpenInMemory()) — no disk I/O, no cleanup - No global state — store is injected via
cobra.Commandcontext
1. bash scripts/new-prim.sh <name>
2. Implement commands in <name>/internal/cli/
3. make all # fails until everything is wired correctly
4. Update README.md, llms.txt, REPOS.md manuallyThe scaffold script registers the new prim in go.work, Makefile, scripts/docgen.sh,
and docs/agent-reference.md. make check-registration validates all registrations
are in place.
- Branch from
main - Clear, imperative commit messages:
add restore command,fix duplicate encoding - One logical change per commit
make testmust pass before committingmake buildmust compile cleanly
- Run
make testafter any code change - Add tests for new functionality (use in-memory SQLite)
- Follow the existing command pattern (parse flags -> store -> format)
- Keep store interfaces as the boundary — CLI, API, MCP never depend on each other
- Adding new dependencies to go.mod
- Changing the store interface (affects CLI, API, and MCP consumers)
- Modifying database migrations (affects existing user data)
- Changing CLI flag names or defaults (breaks existing scripts)
- Modify files outside the primitive you're working on without explicit instruction
- Skip tests or use
--shortflag - Add CGo dependencies (breaks cross-compilation)
- Commit database files, config.yaml, or .env files
- Force push to main
The docs/agent-reference.md command tables are auto-generated from each primitive's Cobra command tree. Hand-written sections (schemas, idempotency tables, decision trees) are preserved — only the content between anchor comments is replaced.
make docs # Regenerate docs/agent-reference.md
make docs-check # Check that docs are up to date (used in CI)- Each primitive has a
cmd/docgen/main.gothat walks its Cobra command tree and emits JSON metadata to stdout. primkit/cmd/docupdater/main.goreads the JSON files and rewrites the anchored sections indocs/agent-reference.md.scripts/docgen.shorchestrates both steps.
Each prim's Commands table is wrapped in HTML comment anchors:
<!-- docgen:start:<primname>:commands -->
| Command | Synopsis | Flags |
...
<!-- docgen:end:<primname>:commands -->
Do not edit content inside these anchors manually — it will be overwritten by the next make docs run.
Run make docs after any change to:
- CLI flags (adding, removing, or renaming flags)
- Adding or removing commands
- Changing command
Usestrings orShortdescriptions - Adding
MarkFlagRequiredto a command
CI runs make docs-check on every pull request and will fail if the docs are out of date.