ks-cookbook
CLAUDE.md9 starsChanged 7 months agoMITView on GitHub
Before editing anything, read the cursor rules that mirror ks-backend's clean-code convention: ks-cookbook is a uv workspace of 32 flagship agent demos plus a set of lightweight recipes that sit on top of Knowledge Stack. Every flagship uses the same pattern: connect to knowledgestack-mcp (stdio), enumerate a corpus folder, read chunks, produce structured output with real [chunk:<uuid>] citations, and write a file artifact (.md / .docx / .xlsx). The ksapi dependency resolves from PyPI (ksapi>=0.1.0). No sibling checkout of ks-backend…
- Reads credentials
In this repository3 other files it gives its agents.
- .cursor/rules/flagship_author.mdcCursor rule
- .cursor/rules/python_clean_code.mdcCursor rule
- .cursor/rules/recipe_author.mdcCursor rule
The file
We split this CLAUDE.md into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 7
Before editing anything, read the cursor rules that mirror ks-backend's clean-code convention:
- Very specific: line 21
All targets assume .env with KS_API_KEY + (OPENAI_API_KEY or ANTHROPIC_API_KEY).
- Distinctive: line 38
Run a flagship directly (bypasses Makefile defaults):
≈ “Common” is an estimate: at least 1 in 5 of the 28,633 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Style rules (load these first)
Before editing anything, read the cursor rules that mirror ks-backend's clean-code convention:
.cursor/rules/python_clean_code.mdc— SRP, function-size limits, forbidden smells, the four prompt invariants..cursor/rules/flagship_author.mdc— file layout, README template, agent wiring, schema shape, Makefile entry, PR checklist for flagships..cursor/rules/recipe_author.mdc— ≤100-LOC cap, frontmatter, shared session helper, smoke-test bar.
What this repo is
ks-cookbook is a uv workspace of 32 flagship agent demos plus a set of lightweight recipes that sit on top of Knowledge Stack. Every flagship uses the same pattern: connect to knowledgestack-mcp (stdio), enumerate a corpus folder, read chunks, produce structured output with real [chunk:<uuid>] citations, and write a file artifact (.md / .docx / .xlsx).
The ksapi dependency resolves from PyPI (ksapi>=0.1.0). No sibling checkout of ks-backend is required. If you want to develop against the local generated SDK instead, add a [tool.uv.sources] override pointing at ../ks-backend/codegen/ks-backend-python in your own working copy — don't commit it.
Commands
All targets assume .env with KS_API_KEY + (OPENAI_API_KEY or ANTHROPIC_API_KEY).
make setup # uv sync --all-packages + check-env
make install-dev # setup + install pre-commit hooks
make lint # ruff check . (line-length 100, ignores E501/UP042)
make fix # ruff check . --fix (imports, unused, etc.)
make format # ruff format .
make test # reminder — MCP server tests live in the ks-mcp repo
make help # list every demo target
make demo-<name> # run a single flagship (e.g. demo-credit-memo)
make recipe NAME=<dir> ARGS='...' # run a recipe from recipes/<dir>/recipe.py
make clean # delete generated sample outputs from every flagshipMCP server tests live in https://github.com/knowledgestack/ks-mcp — ks-cookbook no longer ships the server source.
Run a flagship directly (bypasses Makefile defaults):
uv run --package ks-cookbook-<slug> ks-cookbook-<slug> --helpmake check-env is a dependency of every demo target — it fails fast if KS_API_KEY or an LLM key is missing.
Architecture
Workspace layout
pyproject.tomlat the root defines the uv workspace. Every flagship is a member; each has its ownpyproject.toml,src/<module>/, and[project.scripts]entrypoint (ks-cookbook-<slug>).flagships/<name>/src/<module>/— each flagship follows the same four-file shape:__main__.py(CLI),agent.py(prompt + MCP wiring),schema.py(pydantic output contract),sample_inputs/.recipes/— short (<100 LOC) single-file patterns.recipes/_shared/mcp_client.pyexposesks_mcp_session(); recipes use it rather than constructingMCPServerStdioby hand.- The MCP server (
knowledgestack-mcp) lives in knowledgestack/ks-mcp. The Python SDK (ksapi) lives in knowledgestack/ks-sdk-python; the TypeScript SDK (@knowledge-stack/ksapi) lives in knowledgestack/ks-sdk-ts. Central docs are in knowledgestack/ks-docs (Mintlify → docs.knowledgestack.ai). The cookbook consumes the MCP server viauvxand the Python SDK from PyPI.
Flagship runtime flow
- CLI parses args; resolves
KS_MCP_COMMAND(defaults to.venv/bin/ks-mcp) andKS_MCP_ARGS. - Agent spawns
MCPServerStdiowithKS_API_KEY+KS_BASE_URLin env. - System prompt hard-codes the MCP workflow:
list_contents(folder_id=<corpus>)→read(path_part_id=<uuid>)→ emit structured output whoseCitation.chunk_idvalues are copied verbatim from[chunk:<uuid>]markers inreadoutput. agent.run()returns a pydantic model;__main__.pyrenders it to.md/.docx/.xlsxin the repo root.
The corpus_folder_id is always threaded as a per-demo env var (e.g. CORPUS_FOLDER_ID, LEGAL_CORPUS_FOLDER_ID, AUDIT_CORPUS_FOLDER_ID) with a seeded default in the Makefile — overriding it points the same agent at a different tenant folder.
MCP tool surface (read-only, v1)
search_knowledge, search_keyword, read, read_around, list_contents, find, get_info, view_chunk_image, get_organization_info, get_current_datetime. Writes are intentionally not exposed. Don't add a second MCP server — the KS-only contract is enforced on contribution.
Contribution rules that affect code changes
From CONTRIBUTING.md, enforced by CI:
- Recipes ≤100 LOC; anything larger belongs under
flagships/. - Grounding is mandatory — every recipe/flagship must call at least one MCP tool; no ungrounded LLM output.
- Citations must be visible — inline
[chunk:<uuid>]tags fromreadoutput, or an explicitcitationsfield in the schema. - Defaults must just work — the default seeded policies corpus is
ab926019-ac7a-579f-bfda-6c52a13c5f41. Recipes run with no flags. - To scaffold:
cp -r flagships/_template flagships/<name>(orrecipes/_template recipes/<name>), then add the member to the rootpyproject.tomlworkspace list and ademo-<name>target to the Makefile.
Gotchas
ksapiresolves from PyPI. If you need to test against an unreleased SDK, temporarily add a[tool.uv.sources]override in a local-only edit topyproject.toml— do not commit it.chunk_idUUIDs must come fromreadoutput markers, not be synthesized — multiple system prompts repeat this and CI-style reviewers will reject fabricated citations.make testonly runs the MCP package tests; flagships are not unit-tested (non-deterministic LLM output). Use--helpas a smoke test.- Generated artifacts (
credit-memo.md,filled.xlsx,brief.docx, etc.) are intentionally checked into the repo root as reference outputs.make cleanremoves them.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

