droid-mode 0.0.1 → 0.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "droid-mode",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Progressive Code-Mode MCP integration for Factory.ai Droid - access MCP tools without context bloat",
5
5
  "type": "module",
6
6
  "main": "dist/cli.js",
@@ -0,0 +1,166 @@
1
+ # Droid Mode
2
+
3
+ Progressive Code-Mode MCP integration for Factory Droid. Access MCP tools without loading them into context.
4
+
5
+ ## Installation
6
+
7
+ ### Option A — Project skill (recommended for teams)
8
+
9
+ Copy this directory to `<repo>/.factory/skills/droid-mode/`
10
+
11
+ ```bash
12
+ ./.factory/skills/droid-mode/bin/dm --help
13
+ ```
14
+
15
+ ### Option B — User skill (personal)
16
+
17
+ Copy to `~/.factory/skills/droid-mode/`
18
+
19
+ ```bash
20
+ ~/.factory/skills/droid-mode/bin/dm --help
21
+ ```
22
+
23
+ ### Option C — npx (scaffolding)
24
+
25
+ ```bash
26
+ npx droid-mode init
27
+ ```
28
+
29
+ ---
30
+
31
+ ## MCP Server Configuration
32
+
33
+ This skill connects to MCP servers configured in:
34
+
35
+ - Project: `.factory/mcp.json`
36
+ - User: `~/.factory/mcp.json` (overrides project)
37
+
38
+ ### Recommended Setup
39
+
40
+ Keep MCP servers `disabled: true` so they don't bloat Droid's context:
41
+
42
+ ```json
43
+ {
44
+ "mcpServers": {
45
+ "context-repo": {
46
+ "type": "stdio",
47
+ "command": "npx",
48
+ "args": ["-y", "context-repo-mcp"],
49
+ "disabled": true
50
+ }
51
+ }
52
+ }
53
+ ```
54
+
55
+ This is the **entire point** of droid-mode: access MCP servers without context bloat.
56
+
57
+ ### CLI Overrides
58
+
59
+ For CI or quick experiments:
60
+
61
+ - `--http-url <url>` with optional `--headers-json '{"Authorization":"Bearer ..."}'`
62
+ - `--stdio-command <cmd>` with optional `--stdio-args "a,b,c"` and `--env-json '{"KEY":"VALUE"}'`
63
+
64
+ ---
65
+
66
+ ## Progressive Disclosure Model
67
+
68
+ | Level | Command | Purpose |
69
+ |-------|---------|---------|
70
+ | 1 | `dm servers` | Discover available MCP servers |
71
+ | 2 | `dm index --server X` | List tools on a server |
72
+ | 3 | `dm hydrate tool1 tool2 --server X` | Get full schemas |
73
+ | 4 | `dm run --server X ...` | Execute workflow |
74
+
75
+ ---
76
+
77
+ ## Commands
78
+
79
+ ### `dm servers` — List available MCP servers
80
+
81
+ ```bash
82
+ dm servers
83
+ ```
84
+
85
+ Shows all servers from `mcp.json`. Servers with `disabled: true` show as "disabled (good!)".
86
+
87
+ ### `dm doctor` — Sanity check
88
+
89
+ ```bash
90
+ dm doctor --server contextrepo
91
+ ```
92
+
93
+ Checks: finds `mcp.json`, resolves server, attempts `initialize` + `tools/list`.
94
+
95
+ ### `dm index` — List tools (compact)
96
+
97
+ ```bash
98
+ dm index --server contextrepo
99
+ dm index --server contextrepo --json
100
+ ```
101
+
102
+ Outputs a compact table (name + description + required params).
103
+
104
+ ### `dm search` — Find tools by keyword
105
+
106
+ ```bash
107
+ dm search "semantic search over docs" --limit 8 --server contextrepo
108
+ ```
109
+
110
+ Searches the cached index.
111
+
112
+ ### `dm hydrate` — Get full schemas
113
+
114
+ ```bash
115
+ dm hydrate search_documents get_document --server contextrepo
116
+ ```
117
+
118
+ Writes to `.factory/droid-mode/hydrated/<server>/<timestamp>/`:
119
+ - `tools.json` — full tool definitions
120
+ - `types.d.ts` — TypeScript types
121
+ - `toolmap.json` — safe JS identifiers → tool names
122
+
123
+ ### `dm run` — Execute workflow
124
+
125
+ ```bash
126
+ dm run --server contextrepo --tools search_documents,get_document --workflow workflow.js
127
+ ```
128
+
129
+ Example workflow:
130
+
131
+ ```js
132
+ workflow = async () => {
133
+ const docs = await t.searchDocuments({ query: "Droid Mode PRD", limit: 5 })
134
+ const full = await Promise.all(docs.results.map(d => t.getDocument({ id: d.id })))
135
+ return { count: full.length, ids: full.map(x => x.id) }
136
+ }
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Output & Audit Artifacts
142
+
143
+ All artifacts written to `.factory/droid-mode/`:
144
+
145
+ | Path | Contents |
146
+ |------|----------|
147
+ | `cache/<server>/tools.json` | Cached tool inventory |
148
+ | `hydrated/<server>/<ts>/` | Schema bundles |
149
+ | `runs/<server>/<ts>/run.json` | Workflow result + trace |
150
+
151
+ ---
152
+
153
+ ## Security Posture
154
+
155
+ - Credentials remain in `mcp.json` env/headers, not in prompts
156
+ - Workflow sandbox blocks `require`, `import`, `process`, `fetch`
157
+ - Network access mediated through MCP server only
158
+ - Every tool call traced (name, args hash, duration, error flag)
159
+
160
+ Optional: Add a **PreToolUse hook** to block direct `mcp__*` calls. See `examples/hooks/`.
161
+
162
+ ---
163
+
164
+ ## Design Philosophy
165
+
166
+ Treat MCP as infrastructure. Treat Skills as capability boundaries. Treat code as a reasoning amplifier — not as authority.
@@ -1,237 +1,97 @@
1
1
  ---
2
2
  name: droid-mode
3
- description: Progressive CodeMode MCP integration for Factory Droid. Discover tools incrementally, hydrate schemas on demand, and run procedural workflows that call MCP tools outside the LLM loop.
3
+ description: Progressive Code-Mode MCP integration for Factory Droid. Discover tools incrementally, hydrate schemas on demand, and run procedural workflows that call MCP tools outside the LLM loop.
4
4
  ---
5
5
 
6
- # Droid Mode (Progressive Code‑Mode MCP Skill)
6
+ # Droid Mode
7
7
 
8
- This skill implements the **PRD “Droid Mode”** pattern: treat MCP as backend infrastructure and use **local scripts** to perform **progressive tool discovery + schema hydration + procedural orchestration**.
8
+ Access MCP tools **without loading them into context**. Progressive discovery schema hydration procedural execution.
9
9
 
10
- Instead of injecting a full MCP tool inventory into the model context, Droid uses these scripts to:
10
+ ## When to Use
11
11
 
12
- 1. **Index** tools (compact list)
13
- 2. **Search** tools (narrow candidates)
14
- 3. **Hydrate** schemas (only for selected tools)
15
- 4. **Run** a procedural workflow that calls MCP tools **outside** the LLM loop
16
-
17
- Everything is **auditable**: caches, hydrated schemas, and workflow traces are written to `.factory/droid-mode/` (project) or `~/.factory/droid-mode/` (fallback).
18
-
19
- ---
20
-
21
- ## When to use this skill
22
-
23
- Use this skill when you want any of the following:
24
-
25
- - MCP servers with **many tools**, or rapidly changing inventories
26
- - **Token efficiency** (avoid dumping schemas into prompt context)
27
- - **Procedural** workflows (filter/join/iterate locally between tool calls)
12
+ - MCP servers with **many tools** (avoid context bloat)
13
+ - **Token efficiency** (don't dump schemas into prompts)
14
+ - **Procedural workflows** (filter/join/iterate between tool calls)
28
15
  - **Auditability** (explicit scripts + saved artifacts)
29
16
 
30
- ---
31
-
32
- ## Installation
33
-
34
- ### Option A — Project skill (recommended for teams)
35
-
36
- Copy this directory to:
37
-
38
- - `<repo>/.factory/skills/droid-mode/`
39
-
40
- Then call it from the repo root:
41
-
42
- ```bash
43
- ./.factory/skills/droid-mode/bin/dm --help
44
- ```
45
-
46
- ### Option B — User skill (personal)
47
-
48
- Copy to:
49
-
50
- - `~/.factory/skills/droid-mode/`
51
-
52
- Then call it via absolute path:
53
-
54
- ```bash
55
- ~/.factory/skills/droid-mode/bin/dm --help
56
- ```
57
-
58
- ---
59
-
60
- ## MCP server configuration
61
-
62
- This skill can connect to an MCP server in two ways:
63
-
64
- 1. **Auto-detect from Droid’s `mcp.json`** (preferred)
65
- - Project: `.factory/mcp.json`
66
- - User: `~/.factory/mcp.json` (overrides project server entries)
67
-
68
- 2. **Explicit CLI flags** (useful in CI or quick experiments)
69
-
70
- Supported overrides:
71
- - `--http-url <url>` with optional `--headers-json '{"Authorization":"Bearer ..."}'`
72
- - `--stdio-command <cmd>` with optional `--stdio-args "a,b,c"` and `--env-json '{"KEY":"VALUE"}'`
73
-
74
- ### Recommended: configure ContextRepo as a stdio MCP server
75
-
76
- If you use ContextRepo, the common approach is to run its MCP server locally (stdio) and let it talk to ContextRepo’s API using an API key.
77
-
78
- Example (user-level config is preferred for secrets):
79
-
80
- ```bash
81
- droid mcp add contextrepo "npx -y context-repo-mcp" --env CONTEXTREPO_API_KEY=YOUR_KEY
82
- ```
83
-
84
- Notes:
85
- - This skill intentionally **does not print** env values.
86
- - It will also recognize `CONTEXT_REPO_API_KEY` and `CONTEXTREPO_TOKEN` if present.
87
-
88
- ---
89
-
90
- ## Progressive Disclosure Model
91
-
92
- Droid-mode implements a four-level progressive disclosure model:
17
+ ## Commands
93
18
 
94
19
  | Level | Command | Purpose |
95
20
  |-------|---------|---------|
96
21
  | 1 | `dm servers` | Discover available MCP servers |
97
- | 2 | `dm index --server X` | List tools on a server |
98
- | 3 | `dm hydrate tool1 tool2 --server X` | Get full schemas |
99
- | 4 | `dm run --server X ...` | Execute workflow |
100
-
101
- ### Working with "Disabled" Servers
22
+ | 2 | `dm index --server X` | List tools (name, description, required params) |
23
+ | 3 | `dm hydrate tool1 tool2 --server X` | Get full schemas + TypeScript types |
24
+ | 4 | `dm run --workflow file.js --tools a,b --server X` | Execute procedural workflow |
102
25
 
103
- Servers marked `disabled: true` in `mcp.json` are **fully available** to droid-mode. In fact, this is the recommended configuration:
26
+ All commands accept `--server <name>`. If only one server exists, it's auto-selected.
104
27
 
105
- - `disabled: true` tells Droid: "Don't load this server's tools into context"
106
- - droid-mode connects directly, bypassing context injection
107
- - Result: Token-efficient, on-demand MCP access
108
-
109
- ```json
110
- // ~/.factory/mcp.json - Recommended setup
111
- {
112
- "mcpServers": {
113
- "context-repo": {
114
- "type": "stdio",
115
- "command": "npx",
116
- "args": ["-y", "context-repo-mcp"],
117
- "disabled": true
118
- }
119
- }
120
- }
121
- ```
122
-
123
- This is the **entire point** of droid-mode: access MCP servers without bloating the context window.
124
-
125
- ---
126
-
127
- ## Commands
128
-
129
- > All commands accept `--server <name>` to pick an MCP server from `mcp.json`.
130
- > If only one server is configured, it's auto-selected. Otherwise, use `dm servers` to discover available servers.
131
-
132
- ### 0) List servers (discover available MCP servers)
133
-
134
- ```bash
135
- ./.factory/skills/droid-mode/bin/dm servers
136
- ```
137
-
138
- Lists all MCP servers configured in `mcp.json` (both project and user level).
139
- Servers with `disabled: true` are shown as "disabled (good!)" since they won't bloat Droid's context.
140
-
141
- ### 1) Doctor (sanity check)
142
-
143
- ```bash
144
- ./.factory/skills/droid-mode/bin/dm doctor --server contextrepo
145
- ```
146
-
147
- Checks:
148
- - Finds `mcp.json`
149
- - Resolves the server entry (user overrides project)
150
- - Attempts `initialize` + `tools/list` (unless `--no-connect`)
151
-
152
- ### 2) Index tools (compact list)
153
-
154
- ```bash
155
- ./.factory/skills/droid-mode/bin/dm index --server contextrepo
156
- ```
157
-
158
- Outputs a compact table (name + short description).
159
- Use `--json` to return structured output.
28
+ ## Key Insight
160
29
 
161
- ### 3) Search tools (narrow candidate set)
162
-
163
- ```bash
164
- ./.factory/skills/droid-mode/bin/dm search "semantic search over docs" --limit 8 --server contextrepo
165
- ```
166
-
167
- This searches the cached index, refreshing if missing or stale.
168
-
169
- ### 4) Hydrate tool schemas (small subset)
170
-
171
- ```bash
172
- ./.factory/skills/droid-mode/bin/dm hydrate search_documents get_document --server contextrepo
173
- ```
30
+ Servers with `disabled: true` in `mcp.json` are **fully available** to droid-mode:
174
31
 
175
- Writes an “hydration bundle” to:
176
-
177
- - `.factory/droid-mode/hydrated/<server>/<timestamp>/`
178
-
179
- Contents:
180
- - `tools.json` (full tool definitions for the subset)
181
- - `types.d.ts` (best-effort TS types for inputs/outputs)
182
- - `toolmap.json` (safe JS identifiers → tool names)
183
-
184
- ### 5) Run a procedural workflow (“code-mode”)
32
+ - `disabled: true` = "don't inject tools into Droid's context"
33
+ - droid-mode connects directly, bypassing context injection
34
+ - Result: token-efficient, on-demand MCP access
185
35
 
186
- Create a workflow file that defines `workflow = async () => { ... }`.
36
+ This is the entire point of the skill.
187
37
 
188
- Example:
38
+ ## Workflow Example
189
39
 
190
40
  ```js
191
41
  // workflow.js
192
42
  workflow = async () => {
193
- const docs = await t.searchDocuments({ query: "Droid Mode PRD", limit: 5 })
194
- const full = await Promise.all(docs.results.map(d => t.getDocument({ id: d.id })))
195
- return { count: full.length, ids: full.map(x => x.id) }
43
+ const docs = await t.searchDocuments({ query: "PRD", limit: 5 })
44
+ return docs.results.map(d => d.id)
196
45
  }
197
46
  ```
198
47
 
199
- Run it:
200
-
201
48
  ```bash
202
- ./.factory/skills/droid-mode/bin/dm run --server contextrepo --tools search_documents,get_document --workflow workflow.js
49
+ dm run --server contextrepo --tools search_documents --workflow workflow.js
203
50
  ```
204
51
 
205
- The runner:
206
- - Hydrates only the requested tools
207
- - Executes your workflow in a restricted JS sandbox (no imports/require/fetch)
208
- - Emits a JSON result + an execution trace
52
+ ## Verification
209
53
 
210
- ---
54
+ After using droid-mode, verify:
211
55
 
212
- ## Output & audit artifacts
56
+ - [ ] `dm doctor --server X` passes (connection works)
57
+ - [ ] Artifacts exist in `.factory/droid-mode/` (cache, hydrated, runs)
58
+ - [ ] Workflow trace shows no errors (`runs/<server>/<ts>/run.json`)
213
59
 
214
- Artifacts are written under `.factory/droid-mode/` (project) when possible:
60
+ ## Success Criteria
215
61
 
216
- - `cache/<server>/tools.json` cached tool inventory
217
- - `hydrated/<server>/<timestamp>/...` — schema bundles
218
- - `runs/<server>/<timestamp>/run.json` — workflow result + trace
62
+ The skill completes successfully when:
219
63
 
220
- ---
64
+ - Tool discovery returned results (`dm index` shows tools)
65
+ - Hydrated schemas are valid (`types.d.ts` generated)
66
+ - Workflow executed without sandbox errors (trace shows `error: false`)
221
67
 
222
- ## Security posture (practical guardrails)
68
+ ## Fallbacks
223
69
 
224
- This skill is designed so that:
70
+ | Issue | Resolution |
71
+ |-------|------------|
72
+ | Server not found | Run `dm servers` to list available servers |
73
+ | Connection timeout | Check `mcp.json` config, run `dm doctor` |
74
+ | Tool not found | Run `dm index --server X` to refresh cache |
75
+ | Workflow sandbox error | Check for disallowed `require`/`import`/`fetch` |
225
76
 
226
- - Credentials remain in `mcp.json` env/headers (or your OS keyring), not in prompts.
227
- - The workflow sandbox does **not** expose `require`, `import`, `process`, or `fetch`.
228
- - Network access for workflows is mediated through the MCP server only.
229
- - Every tool call is traced (tool name, args hash, duration, and error flag).
77
+ ## Never Do
230
78
 
231
- Optional: You can add a **PreToolUse hook** to block direct `mcp__*` tool calls and force use of this skill. See `examples/hooks/`.
79
+ - Don't hardcode credentials in workflows (use `mcp.json` env)
80
+ - Don't skip `--server` flag when multiple servers exist
81
+ - Don't use `fetch`/`require`/`import` in workflow files (sandbox blocks them)
232
82
 
233
- ---
83
+ ## Artifacts
84
+
85
+ All outputs written to `.factory/droid-mode/`:
86
+
87
+ - `cache/<server>/tools.json` — tool inventory
88
+ - `hydrated/<server>/<ts>/` — schemas + types
89
+ - `runs/<server>/<ts>/run.json` — execution trace
234
90
 
235
- ## Design philosophy (north star)
91
+ ## Supporting Files
236
92
 
237
- Treat MCP as infrastructure. Treat Skills as capability boundaries. Treat code as a reasoning amplifier not as authority.
93
+ - `bin/dm`CLI entry point
94
+ - `lib/` — implementation modules
95
+ - `examples/workflows/` — sample workflow files
96
+ - `examples/hooks/` — PreToolUse hook examples
97
+ - `README.md` — full documentation