@adhd/agent-mcp 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +236 -0
- package/CHANGELOG.md +115 -0
- package/LICENSE +21 -0
- package/README.md +201 -0
- package/docs/architecture-and-security.md +405 -0
- package/docs/marketing/.catalog/capabilities.md +143 -0
- package/docs/marketing/.catalog/consumer.md +111 -0
- package/docs/marketing/.catalog/distribution.md +223 -0
- package/docs/marketing/.catalog/doc-conformance.md +237 -0
- package/docs/marketing/.catalog/doc-ops.md +98 -0
- package/docs/marketing/.catalog/metrics.md +119 -0
- package/docs/marketing/.catalog/required-tooling.md +224 -0
- package/docs/marketing/.catalog/review.md +164 -0
- package/docs/provider-call-audit.md +254 -0
- package/llms.txt +133 -0
- package/package.json +31 -50
- package/src/__tests__/integration/harness.d.ts +871 -39
- package/src/__tests__/integration/harness.d.ts.map +1 -1
- package/src/__tests__/integration/harness.js +93 -87
- package/src/__tests__/integration/harness.js.map +1 -1
- package/src/__tests__/integration/scripted-provider.d.ts +1 -2
- package/src/__tests__/integration/scripted-provider.d.ts.map +1 -1
- package/src/__tests__/integration/scripted-provider.js +1 -3
- package/src/__tests__/integration/scripted-provider.js.map +1 -1
- package/src/config.d.ts +6 -69
- package/src/config.d.ts.map +1 -1
- package/src/config.js +1 -50
- package/src/config.js.map +1 -1
- package/src/db/client.d.ts +1516 -2
- package/src/db/client.d.ts.map +1 -1
- package/src/db/client.js +4 -2
- package/src/db/client.js.map +1 -1
- package/src/db/migrate-runner.d.ts +0 -28
- package/src/db/migrate-runner.d.ts.map +1 -1
- package/src/db/migrate-runner.js +0 -24
- package/src/db/migrate-runner.js.map +1 -1
- package/src/db/migrate.d.ts +0 -7
- package/src/db/migrate.d.ts.map +1 -1
- package/src/db/migrate.js +0 -7
- package/src/db/migrate.js.map +1 -1
- package/src/db/schema.d.ts +0 -1260
- package/src/db/schema.d.ts.map +1 -1
- package/src/db/schema.js +2 -179
- package/src/db/schema.js.map +1 -1
- package/src/index.d.ts +4 -27
- package/src/index.d.ts.map +1 -1
- package/src/index.js +43 -114
- package/src/index.js.map +1 -1
- package/src/logger.d.ts +0 -8
- package/src/logger.d.ts.map +1 -1
- package/src/logger.js +1 -12
- package/src/logger.js.map +1 -1
- package/src/scripts/agent-mcp-tail.d.ts +3 -0
- package/src/scripts/agent-mcp-tail.d.ts.map +1 -0
- package/src/scripts/agent-mcp-tail.js +227 -0
- package/src/scripts/agent-mcp-tail.js.map +1 -0
- package/src/server.d.ts +13 -34
- package/src/server.d.ts.map +1 -1
- package/src/server.js +234 -326
- package/src/server.js.map +1 -1
- package/src/store/agent-store.d.ts +3 -16
- package/src/store/agent-store.d.ts.map +1 -1
- package/src/store/agent-store.js +38 -41
- package/src/store/agent-store.js.map +1 -1
- package/src/streaming/chat-gateway.d.ts +17 -0
- package/src/streaming/chat-gateway.d.ts.map +1 -0
- package/src/streaming/chat-gateway.js +336 -0
- package/src/streaming/chat-gateway.js.map +1 -0
- package/src/streaming/event-bus.d.ts +4 -0
- package/src/streaming/event-bus.d.ts.map +1 -1
- package/src/streaming/event-bus.js +14 -1
- package/src/streaming/event-bus.js.map +1 -1
- package/src/streaming/sse-server.d.ts +3 -14
- package/src/streaming/sse-server.d.ts.map +1 -1
- package/src/streaming/sse-server.js +37 -37
- package/src/streaming/sse-server.js.map +1 -1
- package/src/utils/load-env.d.ts +0 -14
- package/src/utils/load-env.d.ts.map +1 -1
- package/src/utils/load-env.js +0 -18
- package/src/utils/load-env.js.map +1 -1
- package/drizzle/0000_nifty_sasquatch.sql +0 -55
- package/drizzle/0001_task_usage.sql +0 -16
- package/drizzle/0002_lumpy_silver_centurion.sql +0 -2
- package/drizzle/0003_nifty_shriek.sql +0 -2
- package/drizzle/0004_brief_shocker.sql +0 -4
- package/drizzle/0005_clear_lenny_balinger.sql +0 -25
- package/drizzle/0006_composed_prompts_cache.sql +0 -24
- package/drizzle/meta/0000_snapshot.json +0 -387
- package/drizzle/meta/0001_snapshot.json +0 -495
- package/drizzle/meta/0002_snapshot.json +0 -509
- package/drizzle/meta/0003_snapshot.json +0 -523
- package/drizzle/meta/0004_snapshot.json +0 -551
- package/drizzle/meta/0005_snapshot.json +0 -545
- package/drizzle/meta/0006_snapshot.json +0 -651
- package/drizzle/meta/_journal.json +0 -55
- package/src/clients/http-client.d.ts +0 -24
- package/src/clients/http-client.d.ts.map +0 -1
- package/src/clients/http-client.js +0 -98
- package/src/clients/http-client.js.map +0 -1
- package/src/clients/in-process.d.ts +0 -27
- package/src/clients/in-process.d.ts.map +0 -1
- package/src/clients/in-process.js +0 -37
- package/src/clients/in-process.js.map +0 -1
- package/src/clients/index.d.ts +0 -7
- package/src/clients/index.d.ts.map +0 -1
- package/src/clients/index.js +0 -5
- package/src/clients/index.js.map +0 -1
- package/src/clients/registry.d.ts +0 -54
- package/src/clients/registry.d.ts.map +0 -1
- package/src/clients/registry.js +0 -164
- package/src/clients/registry.js.map +0 -1
- package/src/clients/stdio-client.d.ts +0 -16
- package/src/clients/stdio-client.d.ts.map +0 -1
- package/src/clients/stdio-client.js +0 -97
- package/src/clients/stdio-client.js.map +0 -1
- package/src/clients/tool-naming.d.ts +0 -44
- package/src/clients/tool-naming.d.ts.map +0 -1
- package/src/clients/tool-naming.js +0 -65
- package/src/clients/tool-naming.js.map +0 -1
- package/src/clients/types.d.ts +0 -18
- package/src/clients/types.d.ts.map +0 -1
- package/src/clients/types.js +0 -2
- package/src/clients/types.js.map +0 -1
- package/src/engine/dag-engine.d.ts +0 -62
- package/src/engine/dag-engine.d.ts.map +0 -1
- package/src/engine/dag-engine.js +0 -158
- package/src/engine/dag-engine.js.map +0 -1
- package/src/engine/hooks.d.ts +0 -24
- package/src/engine/hooks.d.ts.map +0 -1
- package/src/engine/hooks.js +0 -50
- package/src/engine/hooks.js.map +0 -1
- package/src/engine/orchestrator.d.ts +0 -40
- package/src/engine/orchestrator.d.ts.map +0 -1
- package/src/engine/orchestrator.js +0 -507
- package/src/engine/orchestrator.js.map +0 -1
- package/src/engine/policy.d.ts +0 -66
- package/src/engine/policy.d.ts.map +0 -1
- package/src/engine/policy.js +0 -112
- package/src/engine/policy.js.map +0 -1
- package/src/engine/prompt-resolver.d.ts +0 -89
- package/src/engine/prompt-resolver.d.ts.map +0 -1
- package/src/engine/prompt-resolver.js +0 -96
- package/src/engine/prompt-resolver.js.map +0 -1
- package/src/engine/queue.d.ts +0 -29
- package/src/engine/queue.d.ts.map +0 -1
- package/src/engine/queue.js +0 -56
- package/src/engine/queue.js.map +0 -1
- package/src/plugins/index.d.ts +0 -2
- package/src/plugins/index.d.ts.map +0 -1
- package/src/plugins/index.js +0 -2
- package/src/plugins/index.js.map +0 -1
- package/src/plugins/loader.d.ts +0 -65
- package/src/plugins/loader.d.ts.map +0 -1
- package/src/plugins/loader.js +0 -222
- package/src/plugins/loader.js.map +0 -1
- package/src/plugins/usage-plugin.d.ts +0 -27
- package/src/plugins/usage-plugin.d.ts.map +0 -1
- package/src/plugins/usage-plugin.js +0 -148
- package/src/plugins/usage-plugin.js.map +0 -1
- package/src/providers/anthropic.d.ts +0 -13
- package/src/providers/anthropic.d.ts.map +0 -1
- package/src/providers/anthropic.js +0 -260
- package/src/providers/anthropic.js.map +0 -1
- package/src/providers/claudecli.d.ts +0 -153
- package/src/providers/claudecli.d.ts.map +0 -1
- package/src/providers/claudecli.js +0 -510
- package/src/providers/claudecli.js.map +0 -1
- package/src/providers/factory.d.ts +0 -10
- package/src/providers/factory.d.ts.map +0 -1
- package/src/providers/factory.js +0 -24
- package/src/providers/factory.js.map +0 -1
- package/src/providers/index.d.ts +0 -6
- package/src/providers/index.d.ts.map +0 -1
- package/src/providers/index.js +0 -5
- package/src/providers/index.js.map +0 -1
- package/src/providers/openai.d.ts +0 -14
- package/src/providers/openai.d.ts.map +0 -1
- package/src/providers/openai.js +0 -162
- package/src/providers/openai.js.map +0 -1
- package/src/providers/types.d.ts +0 -36
- package/src/providers/types.d.ts.map +0 -1
- package/src/providers/types.js +0 -2
- package/src/providers/types.js.map +0 -1
- package/src/store/composed-prompt-store.d.ts +0 -24
- package/src/store/composed-prompt-store.d.ts.map +0 -1
- package/src/store/composed-prompt-store.js +0 -75
- package/src/store/composed-prompt-store.js.map +0 -1
- package/src/store/index.d.ts +0 -5
- package/src/store/index.d.ts.map +0 -1
- package/src/store/index.js +0 -5
- package/src/store/index.js.map +0 -1
- package/src/store/session-store.d.ts +0 -45
- package/src/store/session-store.d.ts.map +0 -1
- package/src/store/session-store.js +0 -197
- package/src/store/session-store.js.map +0 -1
- package/src/store/task-store.d.ts +0 -55
- package/src/store/task-store.d.ts.map +0 -1
- package/src/store/task-store.js +0 -186
- package/src/store/task-store.js.map +0 -1
- package/src/tools/agent-crud.d.ts +0 -15
- package/src/tools/agent-crud.d.ts.map +0 -1
- package/src/tools/agent-crud.js +0 -32
- package/src/tools/agent-crud.js.map +0 -1
- package/src/tools/session.d.ts +0 -33
- package/src/tools/session.d.ts.map +0 -1
- package/src/tools/session.js +0 -73
- package/src/tools/session.js.map +0 -1
- package/src/tools/task.d.ts +0 -86
- package/src/tools/task.d.ts.map +0 -1
- package/src/tools/task.js +0 -406
- package/src/tools/task.js.map +0 -1
- package/src/tools/usage.d.ts +0 -60
- package/src/tools/usage.d.ts.map +0 -1
- package/src/tools/usage.js +0 -174
- package/src/tools/usage.js.map +0 -1
- package/src/types/agent.d.ts +0 -2
- package/src/types/agent.d.ts.map +0 -1
- package/src/types/agent.js +0 -3
- package/src/types/agent.js.map +0 -1
- package/src/types/execution.d.ts +0 -2
- package/src/types/execution.d.ts.map +0 -1
- package/src/types/execution.js +0 -3
- package/src/types/execution.js.map +0 -1
- package/src/types/index.d.ts +0 -2
- package/src/types/index.d.ts.map +0 -1
- package/src/types/index.js +0 -2
- package/src/types/index.js.map +0 -1
- package/src/types/mcp.d.ts +0 -2
- package/src/types/mcp.d.ts.map +0 -1
- package/src/types/mcp.js +0 -3
- package/src/types/mcp.js.map +0 -1
- package/src/types/message.d.ts +0 -2
- package/src/types/message.d.ts.map +0 -1
- package/src/types/message.js +0 -3
- package/src/types/message.js.map +0 -1
- package/src/types/session.d.ts +0 -2
- package/src/types/session.d.ts.map +0 -1
- package/src/types/session.js +0 -3
- package/src/types/session.js.map +0 -1
- package/src/types/task.d.ts +0 -2
- package/src/types/task.d.ts.map +0 -1
- package/src/types/task.js +0 -3
- package/src/types/task.js.map +0 -1
- package/src/utils/ids.d.ts +0 -2
- package/src/utils/ids.d.ts.map +0 -1
- package/src/utils/ids.js +0 -5
- package/src/utils/ids.js.map +0 -1
- package/src/utils/logger.d.ts +0 -2
- package/src/utils/logger.d.ts.map +0 -1
- package/src/utils/logger.js +0 -5
- package/src/utils/logger.js.map +0 -1
- package/src/utils/timestamps.d.ts +0 -2
- package/src/utils/timestamps.d.ts.map +0 -1
- package/src/utils/timestamps.js +0 -4
- package/src/utils/timestamps.js.map +0 -1
- package/src/validation/agent.d.ts +0 -400
- package/src/validation/agent.d.ts.map +0 -1
- package/src/validation/agent.js +0 -251
- package/src/validation/agent.js.map +0 -1
- package/src/validation/agents.d.ts +0 -2
- package/src/validation/agents.d.ts.map +0 -1
- package/src/validation/agents.js +0 -3
- package/src/validation/agents.js.map +0 -1
- package/src/validation/errors.d.ts +0 -32
- package/src/validation/errors.d.ts.map +0 -1
- package/src/validation/errors.js +0 -42
- package/src/validation/errors.js.map +0 -1
- package/src/validation/execution.d.ts +0 -86
- package/src/validation/execution.d.ts.map +0 -1
- package/src/validation/execution.js +0 -28
- package/src/validation/execution.js.map +0 -1
- package/src/validation/index.d.ts +0 -9
- package/src/validation/index.d.ts.map +0 -1
- package/src/validation/index.js +0 -9
- package/src/validation/index.js.map +0 -1
- package/src/validation/mcp.d.ts +0 -42
- package/src/validation/mcp.d.ts.map +0 -1
- package/src/validation/mcp.js +0 -28
- package/src/validation/mcp.js.map +0 -1
- package/src/validation/message.d.ts +0 -43
- package/src/validation/message.d.ts.map +0 -1
- package/src/validation/message.js +0 -23
- package/src/validation/message.js.map +0 -1
- package/src/validation/session.d.ts +0 -49
- package/src/validation/session.d.ts.map +0 -1
- package/src/validation/session.js +0 -34
- package/src/validation/session.js.map +0 -1
- package/src/validation/task.d.ts +0 -146
- package/src/validation/task.d.ts.map +0 -1
- package/src/validation/task.js +0 -95
- package/src/validation/task.js.map +0 -1
- package/src/validation/tasks.d.ts +0 -2
- package/src/validation/tasks.d.ts.map +0 -1
- package/src/validation/tasks.js +0 -3
- package/src/validation/tasks.js.map +0 -1
- package/src/validation/usage.d.ts +0 -89
- package/src/validation/usage.d.ts.map +0 -1
- package/src/validation/usage.js +0 -98
- package/src/validation/usage.js.map +0 -1
package/AGENTS.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# AGENTS.md — LLM-Guiding Documentation
|
|
2
|
+
|
|
3
|
+
This document is written for LLM/agent consumption. It contains only factual, non-marketing claims about @adhd/agent-mcp. All statements are grounded in code or configuration, not speculation.
|
|
4
|
+
|
|
5
|
+
## What This Package Is (Fact-Based)
|
|
6
|
+
|
|
7
|
+
`@adhd/agent-mcp` is an MCP (Model Context Protocol) server. When run, it:
|
|
8
|
+
|
|
9
|
+
1. Accepts JSON-RPC method calls from MCP clients over stdio
|
|
10
|
+
2. Manages a local SQLite database at `~/.adhd/agent-mcp/` (configurable)
|
|
11
|
+
3. Accepts calls to create agents, send messages, and retrieve results
|
|
12
|
+
4. Calls external model providers (OpenAI, Anthropic, DeepSeek, Gemini) via their APIs
|
|
13
|
+
5. Enforces runtime policies (token limits, tool allowlists, delegation depth)
|
|
14
|
+
6. Returns results and execution traces to the MCP client
|
|
15
|
+
|
|
16
|
+
## Shipped Status (as of 2.0.2)
|
|
17
|
+
|
|
18
|
+
All features listed below are shipped and tested.
|
|
19
|
+
|
|
20
|
+
### Protocol: MCP Tools
|
|
21
|
+
|
|
22
|
+
The server exposes these MCP tools:
|
|
23
|
+
|
|
24
|
+
| Tool | Signature | Purpose |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| `agent` | `(agentName: string) -> {session}` | Instantiate a session for a named agent |
|
|
27
|
+
| `agent_create` | `(name: string, config: object) -> {agentId}` | Create a named agent with provider, model, policy, tool allowlist |
|
|
28
|
+
| `agent_read` | `(name: string) -> {config}` | Fetch agent config by name |
|
|
29
|
+
| `agent_update` | `(name: string, config: object) -> {version}` | Update agent config; existing sessions isolated from change |
|
|
30
|
+
| `agent_delete` | `(name: string, force?: bool) -> {}` | Unregister agent and cascade-delete all sessions (as of 2.0.2) |
|
|
31
|
+
| `agent_list` | `() -> {agents: [...]}` | List all registered agents |
|
|
32
|
+
| `task` | `(agentName: string, prompt: string) -> {taskId, status}` | Run a prompt against a session and execute tool-call loop until completion |
|
|
33
|
+
| `result` | `(taskId: string) -> {status, result, usage}` | Retrieve task result and execution usage |
|
|
34
|
+
| `task_list` | `(filter?: object) -> {tasks: [...]}` | List tasks (filter by sessionId, status, agentName) |
|
|
35
|
+
| `task_cancel` | `(taskId: string) -> {}` | Cancel a running or pending task |
|
|
36
|
+
| `task_resume` | `(taskId: string, resumeInput: string) -> {}` | Resume a HITL-suspended task with user input |
|
|
37
|
+
| `session_list` | `(filter?: object) -> {sessions: [...]}` | List sessions (filter by agentName, status) |
|
|
38
|
+
| `session_close` | `(sessionId: string) -> {}` | Close a session; marks final state |
|
|
39
|
+
| `session_clear` | `(sessionId: string) -> {}` | Delete message history for a session (preserves agent snapshot) |
|
|
40
|
+
| `usage_query` | `(filter?: object, groupBy?: string) -> {usage: [...]}` | Query task usage across multiple tasks (grouped by agent, model, provider) |
|
|
41
|
+
| `guide` | `() -> {workflows, providers, errors}` | Built-in help: 5 workflows, provider table, error codes |
|
|
42
|
+
|
|
43
|
+
### Configuration: Environment Variables
|
|
44
|
+
|
|
45
|
+
These env vars must be set before starting the server:
|
|
46
|
+
|
|
47
|
+
| Variable | Type | Example | Required |
|
|
48
|
+
|---|---|---|---|
|
|
49
|
+
| `ADHD_AGENT_PROVIDER` | string | `anthropic` | Yes |
|
|
50
|
+
| `ADHD_AGENT_MODEL` | string | `claude-opus-4-1` | Yes |
|
|
51
|
+
| `ADHD_AGENT_CONTEXT_LIMIT` | number | `0` (default, disabled) | No |
|
|
52
|
+
| `ANTHROPIC_API_KEY` | string | (credential) | If provider=anthropic |
|
|
53
|
+
| `OPENAI_API_KEY` | string | (credential) | If provider=openai |
|
|
54
|
+
| `DEEPSEEK_API_KEY` | string | (credential) | If provider=deepseek |
|
|
55
|
+
| `GOOGLE_API_KEY` | string | (credential) | If provider=gemini |
|
|
56
|
+
|
|
57
|
+
### Database
|
|
58
|
+
|
|
59
|
+
- **Location:** `~/.adhd/agent-mcp/agent-mcp.db` (SQLite, configurable via `ADHD_AGENT_DB_PATH`)
|
|
60
|
+
- **Tables:** `agents`, `sessions`, `messages`, `task_usage`, `migrations`
|
|
61
|
+
- **Persistence:** All agents, conversations, and usage records persist across server restarts
|
|
62
|
+
- **Migration:** `npm run db:migrate` (drizzle-kit auto-applied on server start as of 2.0.2)
|
|
63
|
+
|
|
64
|
+
### Providers (Supported Models)
|
|
65
|
+
|
|
66
|
+
Tested and working:
|
|
67
|
+
|
|
68
|
+
| Provider | Models | Notes |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| Anthropic | claude-opus-4-1, claude-sonnet-4 | Full JSON-schema tool support; cache-aware usage reporting |
|
|
71
|
+
| OpenAI | gpt-4-turbo, gpt-4o, gpt-4o-mini | Full JSON-schema tool support; cache-aware usage reporting (2.0.2+) |
|
|
72
|
+
| DeepSeek | deepseek-v4-flash, deepseek-v4-pro | Full JSON-schema tool support; cache-aware usage reporting (2.0.2+) |
|
|
73
|
+
| Gemini | gemini-2.5-pro, gemini-2.5-flash | Function-calling support; cache-aware usage reporting (2.0.2+) |
|
|
74
|
+
|
|
75
|
+
### Token Accounting (2.0.2 Changes)
|
|
76
|
+
|
|
77
|
+
**New fields in `task_usage` response:**
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"inputTokens": 715316, // cumulative across all model calls
|
|
82
|
+
"peakContextTokens": 43187, // max prompt size in any single call (NEW 2.0.2)
|
|
83
|
+
"cacheReadTokens": 525056, // cache-hit tokens (provider-dependent; 2.0.2+)
|
|
84
|
+
"uncachedInputTokens": 190260, // full-price tokens (provider-dependent; 2.0.2+)
|
|
85
|
+
"cacheCreationTokens": 0, // Anthropic cache-write surcharge, if any (2.0.2+)
|
|
86
|
+
"reasoningTokens": 2101, // inference tokens from reasoning-capable models (2.0.2+)
|
|
87
|
+
"outputTokens": 7370 // generation tokens
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Breaking change:** Code that interpreted `inputTokens` as "max context size" must now use `peakContextTokens` for that purpose.
|
|
92
|
+
|
|
93
|
+
### Context Management (2.0.2 Changes)
|
|
94
|
+
|
|
95
|
+
**Default behavior:** `ADHD_AGENT_CONTEXT_LIMIT=0` (disabled). No automatic message eviction.
|
|
96
|
+
|
|
97
|
+
**If limit is enabled** (limit > 0):
|
|
98
|
+
- Messages are kept append-only until the provider's actual `prompt_tokens` approaches the limit
|
|
99
|
+
- When triggered, the **middle** of the conversation is collapsed into a synthetic summary message, exactly once
|
|
100
|
+
- The leading prefix (system + early context) is never mutated; this preserves provider-side prefix caching
|
|
101
|
+
|
|
102
|
+
**Prior behavior (2.0.0-2.0.1):** Evicted from the front on every threshold crossing, destroying cache hits (measured: 3.3x cost inflation).
|
|
103
|
+
|
|
104
|
+
### Tool Advertisement (2.0.2 Changes)
|
|
105
|
+
|
|
106
|
+
**Default:** Full JSON-Schema function-calling for all non-claudecli providers.
|
|
107
|
+
|
|
108
|
+
**Alternative:** Set `toolAdvertisement: 'names'` on agent creation to use name-only tools (with prose descriptions in system message).
|
|
109
|
+
|
|
110
|
+
**Prior behavior (2.0.0-2.0.1):** Silently defaulted to name-only for all non-claudecli agents, breaking provider-side tool-call validation.
|
|
111
|
+
|
|
112
|
+
### Delegation (Agent → Child Agent)
|
|
113
|
+
|
|
114
|
+
An agent can delegate to child agents by calling the `task` tool targeting another agent (when allowed by parent policy). Child agents:
|
|
115
|
+
- Have reduced token/cost budgets
|
|
116
|
+
- Have restricted tool and filesystem access (subset of parent)
|
|
117
|
+
- Cannot delegate further if `maxDelegationDepth` is reached
|
|
118
|
+
- Are supervised by the same SQLite database and policy engine
|
|
119
|
+
|
|
120
|
+
## Known Limitations (as of 2.0.2)
|
|
121
|
+
|
|
122
|
+
| Limitation | Status | Impact |
|
|
123
|
+
|---|---|---|
|
|
124
|
+
| No OS-level sandboxing | By design | Filesystem/network enforcement is policy-based, not OS-based |
|
|
125
|
+
| No external security audit | Incomplete | Treat as experimental/research-grade |
|
|
126
|
+
| Single-user isolation | By design | All MCP clients share the same agent database and access all agents |
|
|
127
|
+
| Prompt injection not mitigated | By design | Tool filtering is guidance; creative prompts may bypass it |
|
|
128
|
+
| Experimental state recovery | Partial | Assume data loss on ungraceful shutdown |
|
|
129
|
+
| No multi-provider per-agent | By design | One provider per agent; agent-mcp server-wide provider is the default |
|
|
130
|
+
| No agent-specific timeouts | Not implemented | Uses server-wide `maxToolLoops` only |
|
|
131
|
+
|
|
132
|
+
## Roadmap Items (Not Shipped)
|
|
133
|
+
|
|
134
|
+
These are not yet implemented:
|
|
135
|
+
|
|
136
|
+
- Per-agent provider selection (currently server-wide)
|
|
137
|
+
- per-agent-specific request timeouts (independent of maxToolLoops)
|
|
138
|
+
- Runtime budget monitoring API (only stored after task completion)
|
|
139
|
+
- Agent state snapshots / recovery on host crash
|
|
140
|
+
- Multi-user isolation (per-API-key access control)
|
|
141
|
+
- OS-level sandboxing (container, seccomp, pledge/unveil)
|
|
142
|
+
- External security audit and compliance matrix
|
|
143
|
+
|
|
144
|
+
Do not document these as shipped features.
|
|
145
|
+
|
|
146
|
+
## Dependencies
|
|
147
|
+
|
|
148
|
+
### Runtime (Required)
|
|
149
|
+
|
|
150
|
+
- `@adhd/agent-engine-orchestrator` — orchestration engine
|
|
151
|
+
- `@adhd/agent-store-runtime` — state persistence
|
|
152
|
+
- `@modelcontextprotocol/sdk` — MCP protocol implementation
|
|
153
|
+
- `drizzle-orm`, `better-sqlite3` — database access
|
|
154
|
+
- `pino` — logging
|
|
155
|
+
- `zod` — validation
|
|
156
|
+
|
|
157
|
+
### Build/Test
|
|
158
|
+
|
|
159
|
+
- TypeScript, Vite, ESLint (standard monorepo tooling)
|
|
160
|
+
|
|
161
|
+
## Database Migrations
|
|
162
|
+
|
|
163
|
+
As of 2.0.2, two migrations are required:
|
|
164
|
+
|
|
165
|
+
- **0008:** Adds `peak_context_tokens`, `peak_context_at`, and cache/reasoning fields to `task_usage` table
|
|
166
|
+
- **0009:** Restores `sessions.agent_name → agents.name ON DELETE CASCADE` foreign-key constraint
|
|
167
|
+
|
|
168
|
+
Migration is auto-applied on server start.
|
|
169
|
+
|
|
170
|
+
## Example Usage (Fact-Based)
|
|
171
|
+
|
|
172
|
+
When an MCP client sends:
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"jsonrpc": "2.0",
|
|
177
|
+
"id": 1,
|
|
178
|
+
"method": "agent_create",
|
|
179
|
+
"params": {
|
|
180
|
+
"name": "research-agent",
|
|
181
|
+
"config": {
|
|
182
|
+
"provider": "anthropic",
|
|
183
|
+
"model": "claude-opus-4-1",
|
|
184
|
+
"tools": {
|
|
185
|
+
"allow": ["filesystem__read_text_file", "filesystem__read_dir"]
|
|
186
|
+
},
|
|
187
|
+
"filesystem": {
|
|
188
|
+
"read": ["/Users/me/code"]
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The server:
|
|
196
|
+
1. Validates `config` against the schema
|
|
197
|
+
2. Checks the env-name guard (any `provider.env` keys must be `ADHD_AGENT_` prefixed; NEW in 2.0.2)
|
|
198
|
+
3. Creates a row in the `agents` table
|
|
199
|
+
4. Returns `{agentId: "research-agent"}`
|
|
200
|
+
|
|
201
|
+
When the client sends:
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"jsonrpc": "2.0",
|
|
206
|
+
"id": 2,
|
|
207
|
+
"method": "task",
|
|
208
|
+
"params": {
|
|
209
|
+
"agentName": "research-agent",
|
|
210
|
+
"prompt": "Find all TypeScript files in /Users/me/code"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The server:
|
|
216
|
+
1. Fetches the agent config and prior session history
|
|
217
|
+
2. Constructs a message list: `[system_prompt, prior_messages..., new_user_message]`
|
|
218
|
+
3. Calls `provider.chat({model: "claude-opus-4-1", messages, tools})`
|
|
219
|
+
4. If the model returns tool calls, executes them (respecting the `allow` filter)
|
|
220
|
+
5. Appends tool results and repeats (up to 50 loops)
|
|
221
|
+
6. When the model stops tool-calling, records the task in `task_usage` with token counts
|
|
222
|
+
7. Returns `{taskId, status, result, usage}`
|
|
223
|
+
|
|
224
|
+
All data persists in SQLite; the client can later call `result(taskId)` to retrieve the task's result or `usage_query()` to retrieve token usage.
|
|
225
|
+
|
|
226
|
+
## Verifiable Claims
|
|
227
|
+
|
|
228
|
+
Every claim in this document is tied to:
|
|
229
|
+
|
|
230
|
+
- **Code:** Method exists in `src/` and is called by the MCP transport layer
|
|
231
|
+
- **Tests:** Behavior is tested in `src/__tests__/`
|
|
232
|
+
- **Database:** Schema fields exist and are persisted
|
|
233
|
+
- **BACKLOG:** Bugs and fixes are logged with receipts (BUG-ORCH-003 through BUG-ORCH-014)
|
|
234
|
+
- **Research docs:** `docs/ideas/` contain wire-trace evidence for 2.0.2 changes
|
|
235
|
+
|
|
236
|
+
Do not present this document as aspirational. All features are currently shipped.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.0.2] - 2026-07-11
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
#### Cache-preserving context management (BUG-ORCH-008)
|
|
13
|
+
|
|
14
|
+
Fixes a critical regression where the context limiter destroyed provider prefix caching, causing 3-4x cost inflation.
|
|
15
|
+
|
|
16
|
+
**Problem:** When `ADHD_AGENT_CONTEXT_LIMIT > 0`, the `windowMessages` function dropped the oldest conversation messages to stay under the token limit. This mutated the message prefix, which all four major providers (Anthropic, OpenAI, DeepSeek, Gemini) use for efficient caching. Prefix caches provide up to 90% token cost reduction on stateless chat APIs; destroying the prefix on every trim forced full-price re-billing of the entire surviving history.
|
|
17
|
+
|
|
18
|
+
Measured on wire (DeepSeek v4-flash, 24 model calls):
|
|
19
|
+
- With prefix intact: 93-100% cache hit rate
|
|
20
|
+
- Calls where prefix was trimmed: 5-6% cache hit rate
|
|
21
|
+
- Full-price tokens wasted by 4 trim events: 154,224 tokens (81% of all full-price input in the run)
|
|
22
|
+
- Net cost inflation: ~3.15x–3.3x
|
|
23
|
+
|
|
24
|
+
**Fix:** Replaced with append-only message history. Context enforcement now:
|
|
25
|
+
1. Monitors the provider's exact `prompt_tokens` from each response (no more local estimation)
|
|
26
|
+
2. Only acts when approaching the model's real context ceiling (e.g., 90% of 1M for deepseek-v4-flash)
|
|
27
|
+
3. When action is needed, collapses middle messages into a single synthetic summary exactly once, preserving the prefix
|
|
28
|
+
|
|
29
|
+
**Breaking change:** `ADHD_AGENT_CONTEXT_LIMIT` now defaults to `0` (disabled). The previous hardcoded 30,000-token default is removed. Users should either:
|
|
30
|
+
- Keep the limit disabled (0) and rely on provider ceilings
|
|
31
|
+
- Implement input-capping at the source (limit individual tool-result sizes) instead of evicting from the conversation
|
|
32
|
+
- Set a per-model override if an operator-enforced cost cap is needed
|
|
33
|
+
|
|
34
|
+
**Related docs:** `docs/ideas/context-and-cache-strategy.md` in the monorepo contains the complete analysis, wire captures, and design rationale.
|
|
35
|
+
|
|
36
|
+
#### Provider-neutral token accounting (BUG-ORCH-009, BUG-ORCH-010)
|
|
37
|
+
|
|
38
|
+
Fixes a critical gap where cache-hit/miss tokens were dropped for OpenAI-compatible providers, and peak-context-size was never tracked.
|
|
39
|
+
|
|
40
|
+
**Problem:**
|
|
41
|
+
- `inputTokens` is computed differently per provider: Anthropic excludes cached tokens, but OpenAI, DeepSeek, and Gemini include them. This silently broke cross-provider cost aggregation.
|
|
42
|
+
- No field tracked the peak prompt size in a single call; only cumulative sum existed. This made it impossible to distinguish "many small calls" (fix: fewer calls, preserve cache) from "one huge call" (fix: cap that input).
|
|
43
|
+
- DeepSeek and Anthropic responses carry cache-hit/miss breakdown, but the shipped OpenAI provider dropped these fields entirely on the wire.
|
|
44
|
+
|
|
45
|
+
**Fix:**
|
|
46
|
+
- New normalized usage fields (per-call and in task summary):
|
|
47
|
+
- `uncachedInputTokens` — tokens billed at full rate (cache-miss rate for DeepSeek; input minus cached for Anthropic)
|
|
48
|
+
- `cacheReadTokens` — tokens billed at cache-hit rate (cache-hit for DeepSeek; cache_read for Anthropic)
|
|
49
|
+
- `cacheCreationTokens` — Anthropic cache-creation surcharge (undefined for DeepSeek/OpenAI, which don't charge writes separately)
|
|
50
|
+
- `reasoningTokens` — inference tokens when the provider reports them
|
|
51
|
+
- `peakContextTokens` — maximum prompt size in any single call (new, tracked per-task via `MAX()`, not sum)
|
|
52
|
+
|
|
53
|
+
- Task usage report now surfaces cache-hit rate and peak context alongside cumulative totals
|
|
54
|
+
- Provider mappings for OpenAI now capture `prompt_cache_hit_tokens` / `prompt_cache_miss_tokens` / `reasoning_tokens` from DeepSeek and reasoning-capable models
|
|
55
|
+
|
|
56
|
+
**Database migration:** `0008` adds:
|
|
57
|
+
- `task_usage.peak_context_tokens` (integer)
|
|
58
|
+
- `task_usage.peak_context_at` (integer — the 1-based model-call number that hit the peak)
|
|
59
|
+
|
|
60
|
+
**Breaking change:** Code reading `task_usage.inputTokens` must distinguish:
|
|
61
|
+
- `cumulativeBilledInputTokens` (what `inputTokens` was; cumulative sum across all calls)
|
|
62
|
+
- `peakContextTokens` (new; max single-call prompt size; the relevant metric for window limits)
|
|
63
|
+
|
|
64
|
+
#### Create-time environment-variable guard restored (BUG-ORCH-011)
|
|
65
|
+
|
|
66
|
+
Fixes a security regression where arbitrary host environment variables could be injected into agent provider credentials.
|
|
67
|
+
|
|
68
|
+
**Problem:** The `agent_create` and `agent_update` schemas had an `envNameGuard` validation rule that enforced `ADHD_AGENT_` prefix on all provider environment variable names. During refactoring to TypeScript, this was extracted into a factory function but never wired into the schemas, silently allowing injection of variables like `AWS_SECRET_ACCESS_KEY`, `GITHUB_TOKEN`, etc.
|
|
69
|
+
|
|
70
|
+
**Fix:** Re-wired `buildEnvNameGuard()` into both `agentCreateInputSchema` and `agentUpdateInputSchema`.
|
|
71
|
+
|
|
72
|
+
**Impact:** Existing agents with non-`ADHD_AGENT_` prefixed environment variables will fail validation on next update. These agents must be recreated with compliant env names.
|
|
73
|
+
|
|
74
|
+
#### Sessions→agents foreign-key cascade restored (BUG-ORCH-012)
|
|
75
|
+
|
|
76
|
+
Fixes a data-integrity regression where deleting an agent orphaned all its sessions and messages.
|
|
77
|
+
|
|
78
|
+
**Problem:** Migration `0007_smart_callisto.sql` restructured the schema, moving `agents` table from `agent-mcp` to `agent-store-runtime`. Drizzle's auto-generated migration silently dropped the `sessions.agent_name → agents.name ON DELETE CASCADE` foreign-key constraint. This meant `agent_delete` would delete the agent row but leave all sessions and messages orphaned, making them impossible to clean up without manual SQL.
|
|
79
|
+
|
|
80
|
+
**Fix:** Migration `0009_restore_fk_cascade.sql` restores the cascade constraint.
|
|
81
|
+
|
|
82
|
+
**Impact:** Existing orphaned sessions remain in the database (backward-compatible; no data is deleted). All future agent deletions will cascade correctly. Consider manual cleanup of orphaned sessions from prior 2.0.0/2.0.1 deletions if space is a concern.
|
|
83
|
+
|
|
84
|
+
#### Default tool advertisement restored to full JSON schemas (BUG-ORCH-013)
|
|
85
|
+
|
|
86
|
+
Fixes a silent breaking change where agents lost structured tool-call validation.
|
|
87
|
+
|
|
88
|
+
**Problem:** A new `toolAdvertisement` configuration field was added, defaulting to `'names'` (name + prose description only) for all non-claudecli providers. This was a silent wire-format change: every agent created under 2.0.0/2.0.1 without an explicit `toolAdvertisement` value lost full JSON-Schema function-calling definitions, replacing them with a prose-doc block in the system message. This affects provider-side validation and model-side tool-call accuracy.
|
|
89
|
+
|
|
90
|
+
**Fix:** Restored full JSON-Schema as the default for `toolAdvertisement`. Name-only mode remains available via explicit `toolAdvertisement: 'names'` on agent creation.
|
|
91
|
+
|
|
92
|
+
**Impact:** Agents created under 2.0.0/2.0.1 without explicit `toolAdvertisement` setting will now see full schemas in their next task. No migration needed; the change applies on next run.
|
|
93
|
+
|
|
94
|
+
#### Plugin global-config back-compat (BUG-ORCH-014)
|
|
95
|
+
|
|
96
|
+
Fixes a silent breaking change where existing global plugin configs stopped loading.
|
|
97
|
+
|
|
98
|
+
**Problem:** The plugin-loader's `findConfigFile()` function was updated to check `~/.adhd/agent-mcp/config.json` (new preferred location) but silently dropped the fallback to `~/.agent-mcp/config.json` (legacy location). Users with existing configs at the old path would get zero plugins loaded, with no warning.
|
|
99
|
+
|
|
100
|
+
**Fix:** Restored the fallback chain:
|
|
101
|
+
1. `~/.adhd/agent-mcp/config.json` (new preferred)
|
|
102
|
+
2. `./.adhd/agent-mcp/config.json` (project-local)
|
|
103
|
+
3. `~/.agent-mcp/config.json` (legacy, now explicitly supported)
|
|
104
|
+
|
|
105
|
+
**Impact:** Existing global configs at `~/.agent-mcp/config.json` will load again. No migration needed.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## [2.0.1] - (prior release)
|
|
110
|
+
|
|
111
|
+
Refer to commit history for 2.0.1 changes.
|
|
112
|
+
|
|
113
|
+
## [2.0.0] - (prior release)
|
|
114
|
+
|
|
115
|
+
Initial TypeScript rewrite of the agent-mcp runtime.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pseudosky
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# @adhd/agent-mcp
|
|
2
|
+
|
|
3
|
+
An MCP (Model Context Protocol) server exposing a bounded, supervised agent runtime. This package serves as the public protocol interface to the agent framework, enabling MCP clients to create, monitor, and control child agents running within enforced resource and permission boundaries.
|
|
4
|
+
|
|
5
|
+
## What is this?
|
|
6
|
+
|
|
7
|
+
`@adhd/agent-mcp` is an MCP server that:
|
|
8
|
+
|
|
9
|
+
- **Runs agents as stateful processes** — each agent maintains conversation history, executes tools, and interacts with model providers (OpenAI, Anthropic, DeepSeek, Gemini)
|
|
10
|
+
- **Enforces runtime policies** — maximum delegation depth, token/cost budgets, filesystem scope, network allowlist, tool deny/allow filters
|
|
11
|
+
- **Persists state locally** — SQLite-backed storage for agents, sessions, messages, and execution traces
|
|
12
|
+
- **Exposes a tool-call interface** — MCP clients call tools like `agent_create`, `task`, `result`, `task_cancel` to interact with the runtime
|
|
13
|
+
- **Supports multi-turn delegation** — parent agents can spawn child agents with subset-of-parent permissions
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
### Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install -g @adhd/agent-mcp
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Run as an MCP server
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
agent-mcp
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This starts a JSON-RPC server over stdio. Configure in your MCP host (e.g., Claude's `claude_desktop_config.json`):
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"mcpServers": {
|
|
34
|
+
"agent-mcp": {
|
|
35
|
+
"command": "agent-mcp",
|
|
36
|
+
"env": {
|
|
37
|
+
"ADHD_AGENT_PROVIDER": "anthropic",
|
|
38
|
+
"ADHD_AGENT_MODEL": "claude-opus-4-1",
|
|
39
|
+
"ADHD_AGENT_CONTEXT_LIMIT": "0"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Common environment variables
|
|
47
|
+
|
|
48
|
+
| Variable | Default | Purpose |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| `ADHD_AGENT_PROVIDER` | `anthropic` | LLM provider: `anthropic`, `openai`, `deepseek`, `gemini` |
|
|
51
|
+
| `ADHD_AGENT_MODEL` | `claude-opus-4-1` | Model identifier for the provider |
|
|
52
|
+
| `ADHD_AGENT_CONTEXT_LIMIT` | `0` | Max context size in tokens; 0 = no limit (enforce only at provider ceiling) |
|
|
53
|
+
| `ADHD_AGENT_MAX_TOOL_LOOPS` | `50` | Max tool-call iterations per task |
|
|
54
|
+
| `ADHD_AGENT_MAX_DEPTH` | `3` | Max delegation depth (agent → child → grandchild) |
|
|
55
|
+
| `ANTHROPIC_API_KEY` | (required) | Anthropic API credential if using Anthropic provider |
|
|
56
|
+
| `OPENAI_API_KEY` | (required) | OpenAI API credential if using OpenAI provider |
|
|
57
|
+
|
|
58
|
+
### Example: Create and run an agent task (via MCP client)
|
|
59
|
+
|
|
60
|
+
When connected to `agent-mcp` via MCP, call tools in sequence:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
// 1. Register an agent
|
|
64
|
+
{
|
|
65
|
+
"jsonrpc": "2.0",
|
|
66
|
+
"id": 1,
|
|
67
|
+
"method": "agent_create",
|
|
68
|
+
"params": {
|
|
69
|
+
"name": "my-agent",
|
|
70
|
+
"config": {
|
|
71
|
+
"provider": "anthropic",
|
|
72
|
+
"model": "claude-opus-4-1",
|
|
73
|
+
"tools": { "allow": ["file_read", "code_execute"] },
|
|
74
|
+
"filesystem": { "read": ["/Users/me/project"] }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Returns: {"agentId": "my-agent"}
|
|
79
|
+
|
|
80
|
+
// 2. Run a task against the agent
|
|
81
|
+
{
|
|
82
|
+
"jsonrpc": "2.0",
|
|
83
|
+
"id": 2,
|
|
84
|
+
"method": "task",
|
|
85
|
+
"params": {
|
|
86
|
+
"agentName": "my-agent",
|
|
87
|
+
"prompt": "Analyze the TypeScript code in /Users/me/project and list the 3 most critical issues"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Returns: {"taskId": "task-abc123", "status": "running"}
|
|
91
|
+
|
|
92
|
+
// 3. Poll for result
|
|
93
|
+
{
|
|
94
|
+
"jsonrpc": "2.0",
|
|
95
|
+
"id": 3,
|
|
96
|
+
"method": "result",
|
|
97
|
+
"params": { "taskId": "task-abc123" }
|
|
98
|
+
}
|
|
99
|
+
// Returns: {
|
|
100
|
+
// "taskId": "task-abc123",
|
|
101
|
+
// "status": "completed",
|
|
102
|
+
// "result": "Found 3 issues:\n1. Unhandled promise rejection...",
|
|
103
|
+
// "usage": {
|
|
104
|
+
// "inputTokens": 15234,
|
|
105
|
+
// "peakContextTokens": 8500,
|
|
106
|
+
// "cacheReadTokens": 12000,
|
|
107
|
+
// "uncachedInputTokens": 3234,
|
|
108
|
+
// "outputTokens": 412
|
|
109
|
+
// }
|
|
110
|
+
// }
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
See the source repository's `examples/` directory for end-to-end client libraries (Node.js, Python).
|
|
114
|
+
|
|
115
|
+
## 2.0.2 Release Notes
|
|
116
|
+
|
|
117
|
+
This release fixes six critical regressions from 2.0.0/2.0.1 related to context management, token accounting, security guards, and configuration discovery:
|
|
118
|
+
|
|
119
|
+
### Cache-preserving context management
|
|
120
|
+
|
|
121
|
+
**Issue:** The context limiter dropped oldest messages on every call, mutating the prefix that providers use for caching. This destroyed prefix cache hits (from ~93-100% to ~5-6%) and inflated token spend by ~3.3x on affected tasks.
|
|
122
|
+
|
|
123
|
+
**Fix:** Replaced with append-only history that only summarizes the middle when the real context (from the provider's own `prompt_tokens`) approaches the model's actual window. `ADHD_AGENT_CONTEXT_LIMIT` now defaults to `0` (disabled), and the hardcoded 30,000-token default is gone.
|
|
124
|
+
|
|
125
|
+
**Impact:** Users with active context limits should re-evaluate whether they still need them, or switch to input-capping strategies (limiting individual tool-result sizes) instead.
|
|
126
|
+
|
|
127
|
+
### Provider-neutral token accounting
|
|
128
|
+
|
|
129
|
+
**Issue:** `inputTokens` meant different things on different providers (Anthropic excludes cached tokens; others include them), making cross-provider cost aggregation impossible. Peak-context-size tracking didn't exist anywhere.
|
|
130
|
+
|
|
131
|
+
**Fix:** New normalized usage fields:
|
|
132
|
+
- `uncachedInputTokens` — full-price tokens this call
|
|
133
|
+
- `cacheReadTokens` — discounted cache-hit tokens
|
|
134
|
+
- `cacheCreationTokens` — Anthropic cache-write surcharge (Anthropic only)
|
|
135
|
+
- `reasoningTokens` — inference tokens (when provider reports them)
|
|
136
|
+
- `peakContextTokens` — max prompt size across all calls in the task (distinct from cumulative `inputTokens`)
|
|
137
|
+
|
|
138
|
+
**Impact:** Callers must update code that reads `inputTokens` to distinguish between `cumulativeBilledInputTokens` (what was `inputTokens` before) and `peakContextTokens` (new, for "am I close to the window?" checks). Database migration 0008 adds the new columns.
|
|
139
|
+
|
|
140
|
+
### Create-time environment-variable guard restored
|
|
141
|
+
|
|
142
|
+
**Issue:** The env-name allowlist guard (`ADHD_AGENT_` prefix requirement) was refactored but never wired up, allowing arbitrary host environment variables (like `AWS_SECRET_ACCESS_KEY`) to be injected into agent credentials at creation time.
|
|
143
|
+
|
|
144
|
+
**Fix:** Restored validation so `agent_create` and `agent_update` reject any provider environment variable not prefixed `ADHD_AGENT_`.
|
|
145
|
+
|
|
146
|
+
**Impact:** Existing agents with non-compliant env names will need to be recreated with correct names.
|
|
147
|
+
|
|
148
|
+
### Sessions→agents foreign-key cascade restored
|
|
149
|
+
|
|
150
|
+
**Issue:** Database migration 0007 (schema restructuring) silently dropped the `sessions.agent_name → agents.name ON DELETE CASCADE` foreign key, causing `agent_delete` to orphan session and message history forever.
|
|
151
|
+
|
|
152
|
+
**Fix:** Database migration 0009 restores the cascade constraint.
|
|
153
|
+
|
|
154
|
+
**Impact:** Requires migration 0009. Old orphaned sessions remain in the database (manual cleanup may be needed); all future deletes will cascade correctly.
|
|
155
|
+
|
|
156
|
+
### Default tool advertisement restored to full JSON schemas
|
|
157
|
+
|
|
158
|
+
**Issue:** Tool advertisement mode silently switched from full JSON-Schema function-calling (2.0.1 default) to name-only (with prose doc in system message), affecting every non-claudecli agent post-upgrade with no migration or changelog note.
|
|
159
|
+
|
|
160
|
+
**Fix:** Restored full JSON-Schema as default. Name-only mode remains available via `toolAdvertisement: 'names'` on agent creation.
|
|
161
|
+
|
|
162
|
+
**Impact:** Wire format changes for any agent created under 2.0.0/2.0.1 without an explicit `toolAdvertisement` setting. Existing agents should see restored tool-definition accuracy.
|
|
163
|
+
|
|
164
|
+
### Plugin global-config back-compat
|
|
165
|
+
|
|
166
|
+
**Issue:** Plugin loader stopped checking `~/.agent-mcp/config.json` (the legacy path), breaking users with existing global plugin configurations.
|
|
167
|
+
|
|
168
|
+
**Fix:** Restored fallback to legacy path. Loader now checks (in order):
|
|
169
|
+
1. `~/.adhd/agent-mcp/config.json` (new preferred path)
|
|
170
|
+
2. `./.adhd/agent-mcp/config.json` (project-local override)
|
|
171
|
+
3. `~/.agent-mcp/config.json` (legacy fallback)
|
|
172
|
+
|
|
173
|
+
**Impact:** Existing configs at the legacy path will load again. No action required.
|
|
174
|
+
|
|
175
|
+
## Architecture & Security
|
|
176
|
+
|
|
177
|
+
See [docs/architecture-and-security.md](./docs/architecture-and-security.md) for details on:
|
|
178
|
+
- System boundaries and process model
|
|
179
|
+
- Provider abstraction and state persistence
|
|
180
|
+
- Permission inheritance and trust boundaries
|
|
181
|
+
- Filesystem and network access controls
|
|
182
|
+
- Failure recovery and cancellation semantics
|
|
183
|
+
- Known limitations and security assumptions
|
|
184
|
+
|
|
185
|
+
## Limitations
|
|
186
|
+
|
|
187
|
+
- **No OS-level sandboxing** — filesystem/network access is enforced by policy, not by OS isolation. A malicious or compromised agent can still access the host if the policy permits.
|
|
188
|
+
- **No external audit** — this is research-grade software. Security evaluation by an external auditor is incomplete.
|
|
189
|
+
- **Prompt-level controls only** — tool-use filtering can be bypassed by prompt injection; it is not a security boundary.
|
|
190
|
+
- **Single-user only** — no multi-user isolation; all agents share the same SQLite database.
|
|
191
|
+
- **Experimental recovery** — agent state recovery after host crash is partially implemented; assume data loss on unexpected termination.
|
|
192
|
+
|
|
193
|
+
## Support
|
|
194
|
+
|
|
195
|
+
- **Issues:** Report bugs at the monorepo issue tracker
|
|
196
|
+
- **Security:** See SECURITY.md for responsible disclosure
|
|
197
|
+
- **Documentation:** Full architecture docs in `docs/`
|
|
198
|
+
|
|
199
|
+
## License
|
|
200
|
+
|
|
201
|
+
See LICENSE file in this directory.
|