Skip to content

Commit 8123f81

Browse files
authored
Merge pull request #518 from editor-code-assistant/improve-init-prompt-and-documentation
Improve init prompt and agent documentation
2 parents 874af04 + b084c51 commit 8123f81

4 files changed

Lines changed: 131 additions & 46 deletions

File tree

AGENTS.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
ECA Agent Guide (AGENTS.md)
22

3+
ECA (Editor Code Assistant) is a Clojure server that editors talk to over stdin/stdout JSON-RPC to provide AI coding features (chat, tools, MCP, agents). Shipped as a GraalVM native binary.
4+
5+
- Architecture (request flow: editor → JSON-RPC stdio → `handlers``features``llm_api``llm_providers` → streamed back via `messenger`):
6+
- `src/eca/server.clj` / `src/eca/main.clj`: stdio server entrypoint / CLI interface.
7+
- `src/eca/handlers.clj`: entrypoint for all protocol methods, dispatches to features.
8+
- `src/eca/features/`: high-level capabilities — `chat.clj` (+ `chat/` lifecycle, history, tool-calls), `tools.clj` (+ `tools/` built-in tools: filesystem, shell, git, mcp, task…), `agents.clj`, `skills.clj`, `rules.clj`, `hooks.clj`, `commands.clj`, `context.clj`, `prompt.clj`, `login.clj`, `plugins.clj`.
9+
- `src/eca/llm_api.clj`: façade used by features to call an LLM; vendor adapters in `src/eca/llm_providers/` (anthropic, openai, google, ollama, copilot…).
10+
- `src/eca/db.clj`: in-memory state (sessions, chats, MCP); `src/eca/config.clj`: config resolution from multiple sources.
11+
- `src/eca/messenger.clj`: sends requests/notifications back to the client; `src/eca/remote/`: remote HTTP/SSE server mode.
12+
- `src/eca/nrepl.clj`: starts an nREPL when nrepl/cider-nrepl are on the classpath (i.e. the `bb debug-cli` build; no flag needed) — port is logged to stderr, and you can eval against the live process.
13+
314
- Build (requires Clojure CLI + Babashka):
415
- All-in-one debug CLI (JVM, nREPL): `bb debug-cli`
516
- Production CLI (JVM): `bb prod-cli` | Production JAR: `bb prod-jar`
@@ -9,37 +20,41 @@ ECA Agent Guide (AGENTS.md)
920
- Run all unit tests: `bb test` (same as `clojure -M:test`)
1021
- Run a single unit test namespace: `clojure -M:test --focus eca.main-test`
1122
- Run a single unit test var: `clojure -M:test --focus eca.main-test/parse-opts-test`
12-
- Run all integration tests (requires built `./eca` or `eca.exe`): `bb integration-test`
23+
- Run all integration tests (requires built `./eca` or `eca.exe` at repo root): `bb integration-test`
1324
- Run a single integration test: `bb integration-test --dev --ns integration.chat.mcp-remote-test`
25+
- `--dev` runs the server from source via the `clojure` CLI (no binary build needed); `--list-ns` lists test namespaces; `--proxy` routes via Tinyproxy (must be installed).
26+
- Integration tests use mock LLM/MCP servers (`integration-test/llm_mock`, `mcp_mock`) — no API keys needed.
1427

1528
- Lint/format:
1629
- Lint: `clj-kondo --lint src test dev integration-test`
17-
- Formatting not enforced; follow idiomatic Clojure (`cljfmt` optional).
30+
- Formatting not enforced in CI; follow idiomatic Clojure. `.cljfmt.edn` defines extra indents: `task` and `future*` are `[[:inner 0]]`.
1831

1932
- Namespaces/imports:
2033
- One file per `ns`; always `(set! *warn-on-reflection* true)` near top.
2134
- Group `:require` as: Clojure stdlib, third‑party, then `eca.*`; sort within groups.
2235
- Prefer `:as` aliases; avoid `:refer` except in tests (`clojure.test` and what you use).
2336

2437
- Naming/types/data:
25-
- kebab-case for fns/vars, `eca.<area>[.<subarea>]` for namespaces.
26-
- Use snake/camel case only when mirroring external data keys.
27-
- Prefer immutable maps/vectors/sets; use namespaced keywords for domain data.
28-
- Add type hints only to remove reflection where it shows up.
38+
- Internal Clojure names and domain keys use kebab-case (`chat-id`, `tool-call-id`, `parent-chat-id`).
39+
- Client protocol/config JSON uses camelCase (`initializationOptions`, `toolCall`, `contentReceived`); keep conversions at boundaries (`shared/map->camel-cased-map`, config normalization).
40+
- Provider/MCP payloads mirror vendor specs and may use mixed conventions (`input_tokens`, `function_call`, `inputSchema`); do not “fix” these to Clojure style.
41+
- Hook script stdin uses top-level snake_case for shell ergonomics (`hook_name`, `chat_id`, `db_cache_path`), while nested tool data may keep its original shape.
42+
- - Add type hints only to remove reflection where it shows up.
2943

3044
- Errors/logging/flows:
3145
- Use `ex-info` with data for exceptional paths; return `{:result-code ...}` maps from CLI flows.
32-
- Never `println` for app logs; use `eca.logger/error|warn|info|debug` (stderr-based).
46+
- **stdout is the JSON-RPC channel** — never print to stdout; use `eca.logger/error|warn|info|debug` (stderr-based) for all app logs.
3347
- If a chat-scoped function contains any `logger/...` call, wrap the relevant body in `logger/with-chat-context`. Pass both `chat-id` and the current chat’s `parent-chat-id`.
3448
- Consider wrapping chat-scoped functions that call downstream code known to log, or that start `future*` work whose logs should be attributed to the chat. If there is no downstream logging, `with-chat-context` is unnecessary; instead, consider whether the function should log an important chat lifecycle event.
3549

3650
- Tests:
3751
- Use `clojure.test` + `nubank/matcher-combinators`; keep tests deterministic.
3852
- Put shared test helpers under `test/eca/test_helper.clj`.
53+
- CI runs Linux, macOS, and Windows — use `eca.test-helper/file-path` / `file-uri` for Windows-safe paths in tests.
3954

4055
- General:
41-
- Use java class typing to avoid GraalVM reflection issues
42-
- Avoid adding too many comments, only add essential or when you think is really important to mention something.
56+
- Use concrete Java class type hints when they prevent GraalVM/reflection issues.
57+
- If changing dependency inputs in `deps.edn` or `bb.edn`, run `nix develop --command deps-lock-update`; PR CI fails if this leaves a `deps-lock.json` diff.
4358
- ECA's protocol specification of client <-> server lives in docs/protocol.md
4459
- If changing ECA config structure, remember to update its docs/config.json
45-
- When adding support to a new feature or fixing a existing github issue, add a entry to Unreleased in CHANGELOG.md if not already there as last entry, be really concise (max 180 chars), implementation details not needed, mention the issue number in the end if you know it's related to one.
60+
- When adding support to a new feature or fixing an existing GitHub issue, add a concise Unreleased `CHANGELOG.md` entry (max 180 chars, issue number if known).

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Support provider-level `extraHeaders`, sent on completion and models list requests. #517
6+
- Improve `/init` prompt, `AGENTS.md`, and development docs.
67

78
## 0.144.0
89

docs/development.md

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,49 @@ The ECA codebase follows a pragmatic **layered layout** that separates concerns
1515

1616
### Files overview
1717

18-
Path | Responsibility
19-
-------------------------|-------------------------------------------------------
20-
`bb.edn` | Babashka tasks (e.g. `bb test`, `bb debug-cli`) for local workflows and CI, the main entrypoint for most tasks.
21-
`deps.edn` | Clojure dependency coordinates and aliases used by the JVM build and the native GraalVM image.
22-
`docs/` | Markdown documentation shown at https://eca.dev
23-
`src/eca/config.clj` | Centralized place to get ECA configs from multiple places.
24-
`src/eca/logger.clj` | Logger interface to log to stderr.
25-
`src/eca/shared.clj` | shared utility fns to whole project.
26-
`src/eca/db.clj` | Simple in-memory KV store that backs sessions/MCP, all in-memory state lives here.
27-
`src/eca/llm_api.clj` | Public façade used by features to call an LLM.
28-
`src/eca/llm_providers/` | Vendor adapters (`openai.clj`, `anthropic.clj`, `ollama.clj`).
29-
`src/eca/llm_util.clj` | Token counting, chunking, rate-limit helpers.
30-
`src/eca/features/` | **High-level capabilities exposed to the editor**
31-
├─ `chat.clj` | Streaming chat orchestration & tool-call pipeline.
32-
├─ `prompt.clj` | Prompt templates and variable interpolation.
33-
├─ `index.clj` | Embedding & retrieval-augmented generation helpers.
34-
├─ `rules.clj` | Guards that enforce user-defined project rules.
35-
├─ `tools.clj` | Registry of built-in tool descriptors (run, approve…).
36-
└─ `tools/` | Implementation of side-effectful tools:
37-
──├─ `filesystem.clj` | read/write/edit helpers 
38-
──├─ `shell.clj` | runs user-approved shell commands 
39-
──├─ `mcp.clj` | Multi-Command Plan supervisor 
40-
──└─ `util.clj` | misc helpers shared by tools.
41-
`src/eca/messenger.clj` | To send back to client requests/notifications over stdio.
42-
`src/eca/handlers.clj` | Entrypoint for all features.
43-
`src/eca/server.clj` | stdio **entry point**; wires everything together via `jsonrpc4clj`.
44-
`src/eca/main.clj` | The CLI interface.
45-
`src/eca/nrepl.clj` | Starts an nREPL when `:debug` flag is passed.
18+
Path | Responsibility
19+
----------------------------|-------------------------------------------------------
20+
`bb.edn` | Babashka tasks (e.g. `bb test`, `bb debug-cli`) for local workflows and CI, the main entrypoint for most tasks.
21+
`deps.edn` | Clojure dependency coordinates and aliases used by the JVM build and the native GraalVM image.
22+
`docs/` | Markdown documentation shown at https://eca.dev
23+
`src/eca/main.clj` | The CLI interface (`eca server`, etc.).
24+
`src/eca/server.clj` | stdio **entry point**; wires everything together via `jsonrpc4clj`.
25+
`src/eca/handlers.clj` | Entrypoint for all features; every JSON-RPC request/notification lands here.
26+
`src/eca/messenger.clj` | Protocol to send requests/notifications back to the client (stdio or remote).
27+
`src/eca/db.clj` | In-memory state atom (`db*`); sessions, chats, tool servers — all state lives here.
28+
`src/eca/config.clj` | Centralized place to get ECA configs from multiple places (global, local, env, initializationOptions).
29+
`src/eca/logger.clj` | Logger interface, logs to stderr (stdout is reserved for JSON-RPC).
30+
`src/eca/shared.clj` | Shared utility fns for the whole project.
31+
`src/eca/llm_api.clj` | Public façade used by features to call an LLM.
32+
`src/eca/llm_providers/` | Vendor adapters (`anthropic.clj`, `openai.clj`, `openai_chat.clj`, `google.clj`, `copilot.clj`, `bedrock.clj`, `azure.clj`, `ollama.clj`, `openrouter.clj`, ...).
33+
`src/eca/llm_util.clj` | Streaming/event helpers shared by providers.
34+
`src/eca/features/` | **High-level capabilities exposed to the editor**
35+
├─ `chat.clj` + `chat/` | Streaming chat orchestration & tool-call pipeline (lifecycle, history, tool calls).
36+
├─ `agents.clj` | Agents and subagents (definitions, spawning).
37+
├─ `commands.clj` | Chat commands (`/init`, `/login`, `/context`, custom commands, ...).
38+
├─ `hooks.clj` | User-configured hooks triggered on server events.
39+
├─ `skills.clj` + `skills/` | Skills discovery and loading.
40+
├─ `rules.clj` | User-defined global/project/path-scoped rules.
41+
├─ `context.clj` | Contexts attached to prompts (files, repo map, ...).
42+
├─ `prompt.clj` | System prompt templates and variable interpolation.
43+
├─ `login.clj` | Provider auth flows.
44+
├─ `providers.clj` | Model/provider resolution.
45+
├─ `completion.clj` | Non-chat LLM feature: code completion.
46+
├─ `rewrite.clj` | Non-chat LLM feature: text rewrite.
47+
├─ `index.clj` | Workspace indexing helpers (repo map).
48+
├─ `tools.clj` | Registry of tool servers and built-in tool descriptors, approval logic.
49+
└─ `tools/` | Implementation of built-in tools:
50+
──├─ `filesystem.clj` | read/write/edit/grep helpers
51+
──├─ `shell.clj` | runs user-approved shell commands, background jobs
52+
──├─ `mcp.clj` | MCP (Model Context Protocol) servers integration
53+
──├─ ... | other built-in tools: `git.clj`, `task.clj`, `agent.clj`, `ask_user.clj`, `skill.clj`, ...
54+
──└─ `util.clj` | misc helpers shared by tools.
55+
`src/eca/remote/` | Optional remote HTTP/SSE server exposing chats to non-stdio clients.
56+
`src/eca/nrepl.clj` | Starts an nREPL when built with `bb debug-cli`.
4657

4758
Together these files implement the request flow:
4859

49-
`client/editor``stdin JSON-RPC``handlers``features``llm_api``llm_provider` → results streamed back.
60+
`client/editor``stdin JSON-RPC``handlers``features``llm_api``llm_provider` → results streamed back via `messenger`.
5061

5162
With this map you can usually answer:
5263

@@ -56,11 +67,23 @@ With this map you can usually answer:
5667

5768
### Unit Tests
5869

59-
Run with `bb test` or run test via Clojure REPL. CI will run the same task.
70+
Run with `bb test` or run tests via Clojure REPL. CI runs the same task.
71+
72+
To run a single namespace or test, use kaocha's focus:
73+
74+
```bash
75+
clojure -M:test --focus eca.features.chat-test
76+
```
6077

6178
### Integration Tests
6279

63-
Run with `bb integration-test`, it will use your `eca` binary project root to spawn a server process and communicate with it via JSONRPC, testing the whole eca flow like an editor.
80+
Run with `bb integration-test`, it will use your `eca` binary at project root (build one with `bb debug-cli` or `bb prod-cli`) to spawn a server process and communicate with it via JSONRPC, testing the whole eca flow like an editor. LLM and MCP servers are mocked (`integration-test/llm_mock`, `integration-test/mcp_mock`), so no API keys are needed.
81+
82+
Useful flags (see `bb integration-test -h`):
83+
84+
- `--dev`: run the server from source via the `clojure` CLI instead of a binary.
85+
- `--ns integration.chat.anthropic-test`: run only specific test namespaces (comma-separated); `-l` lists them.
86+
- `--proxy`: route requests through a transient Tinyproxy to verify proxy support.
6487

6588
## Coding
6689

resources/prompts/init.md

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,53 @@
1-
Analyze this codebase and create an AGENTS.md file containing:
2-
1. Build/lint/test commands - especially for running a single test
3-
2. Code style guidelines including imports, formatting, types, naming conventions, error handling, etc.
1+
Analyze this codebase and create or update an AGENTS.md file containing the essential information an AI coding agent needs to work effectively in this repository.
42

5-
The file you create will be given to agentic coding agents (such as yourself) that operate in this repository. Make it about 20 lines long.
3+
Create or update it at the repository root. If {{workspaceRoots}} contains multiple roots, inspect them and ask which root should receive AGENTS.md before writing.
64

7-
If there's already an AGENTS.md, improve it if it's located in {{workspaceRoots}}.
5+
## Step 1: Explore the codebase
6+
7+
Read the actual contents of files like these (skip any that don't exist — this is not an exhaustive list):
8+
9+
- **Manifest/package files**: package.json, deps.edn, project.clj, Cargo.toml, pyproject.toml, go.mod, pom.xml, build.gradle, mix.exs, etc.
10+
- **Build/task runner configs**: Makefile, bb.edn, Justfile, Taskfile.yml, package.json scripts, etc.
11+
- **CI config**: .github/workflows/*, .gitlab-ci.yml, .circleci/, azure-pipelines.yml, etc.
12+
- **Existing AI instructions**: AGENTS.md, CLAUDE.md, .cursor/rules/, .cursorrules, .github/copilot-instructions.md, .windsurfrules, .clinerules, etc.
13+
- **README**, **CONTRIBUTING**, or **DEVELOPERS** docs, etc.
14+
- **Linter/formatter configs**: .clj-kondo/, .eslintrc*, ruff.toml, .golangci.yml, biome.json, .prettierrc, etc.
15+
16+
Do not guess from filenames — read the actual file contents.
17+
18+
From what you read, identify (among other things):
19+
- **Build commands** — especially non-standard ones (wrapper scripts, aliases, specific flags)
20+
- **Test commands** — including how to run a single test (namespace, file, or individual test)
21+
- **Lint/format commands** — exact invocations
22+
- **Project structure** — monorepo, multi-module, or single project; workspace conventions
23+
- **Code style rules that DIFFER from language defaults** — imports, formatting, naming, types, error handling
24+
- **Non-obvious gotchas** — required env vars, setup steps, platform-specific issues
25+
- **Repo conventions** — branch naming, PR/commit style, changelog practices
26+
- **Architectural constraints** — things that constrain how code should be written (e.g., "must work with GraalVM native image", "no reflection")
27+
28+
Do not invent missing conventions. If missing information is essential to avoid misleading instructions, ask targeted questions (via ask_user tool) before writing AGENTS.md. Otherwise omit unknown conventions rather than guessing.
29+
30+
## Step 2: Write AGENTS.md
31+
32+
Write a concise AGENTS.md. Every line must pass this test: **would removing it cause an agent to make mistakes or work less efficiently?** If not, cut it.
33+
34+
Include:
35+
- Non-standard build/test/lint commands (especially single-test invocation)
36+
- Style rules that differ from defaults
37+
- Testing quirks and instructions
38+
- Repo etiquette (branch/PR/commit conventions)
39+
- Required env vars or setup steps
40+
- Non-obvious gotchas or architectural constraints
41+
- Concise architecture notes that are not obvious from filenames: major boundaries, request/data flow, extension points, generated-code areas, or constraints that affect how changes should be made
42+
- Key information from existing AI tool configs — read instructions meant for other AI tools and adapt them for AGENTS.md
43+
44+
Exclude:
45+
- File-by-file structure or component lists (agents can discover these by reading code)
46+
- Standard language conventions agents already know
47+
- Generic advice ("write clean code", "handle errors")
48+
- Information that changes frequently — reference the source file instead
49+
- Detailed tutorials — link to docs instead
50+
51+
Use short sections with bullet points, not paragraphs.
52+
53+
If AGENTS.md already exists in the chosen repository root, read it first. Improve it by filling gaps, removing outdated information, and tightening the language. Preserve what's already correct and useful.

0 commit comments

Comments
 (0)