<!-- WHYCODE:START -->
# WhyCode — verified context for AI-assisted development

## Connection
- Server: http://127.0.0.1:8100
- Project: codeledger (id: codeledger)
- Mode: solo
- Client: Cline (no client-side hooks — session lifecycle runs on the server)

## Before editing any file
Call `context.before_edit` with the file path and the current content. The response returns any relevant decisions, active conflicts on that file, and import constraints. Honor the returned decisions — they are architectural constraints.

## Before making architectural changes
Call `decision.create` with:
- `title` — imperative, under 72 characters
- `description` — the *why*, not the *what*
- `tags` — short labels, e.g. `["auth", "security"]`
- `files_affected` — files that will change as a result

## To understand why code exists
Call `provenance.reverse` with the file path and entity name. The response includes the originating decision, change event, and CI verification status.

## To check codebase health
Call `drift.check` — returns any architectural violations. Call `harness.score` after `session.end` for a quality summary.

## Session lifecycle (managed on the server)
Your first tool call that includes `cwd`, `agent_name`, and `project_id` opens or resumes a session and injects a context block in the response under `session_context`. Sessions auto-close after 30 minutes of inactivity (configurable in `whycode.toml`). Call `session.end` explicitly when a logical unit of work is finished; if it returns `completed_with_warnings` with an `unlinked_files` list, either record a `decision.create` for each or re-run with `force: true` and an `override_reason`.

Always pass `project_id="codeledger"` in tool calls.

## Core tools
- `session.start` — open a coding session
- `session.end` — close session, run harness, check density
- `context.get_relevant` — semantic search over all decisions
- `context.get_for_file` — decisions governing a specific file
- `context.before_edit` — file context + conflict + drift check
- `decision.create` — record an architectural decision
- `decision.list` — list all decisions for this project
- `provenance.reverse` — why does this function exist?
- `provenance.forward` — what code did this decision produce?
- `drift.check` — check for architectural violations
- `harness.score` — quality scores for a session
- `rollback.plan` — impact analysis before reverting a decision
<!-- WHYCODE:END -->
