@factory/cli 0.1.0 → 0.1.2-dev.7

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  A hybrid command-line interface that runs **either**:
4
4
 
5
5
  1. **Interactive TUI** – a full-screen React/Ink terminal app
6
- 2. **Headless commands** – traditional `factory headless <command>` sub-commands powered by Commander
6
+ 2. **Headless commands** – traditional `droid headless <command>` sub-commands powered by Commander
7
7
 
8
8
  The entry-point (`src/index.ts`) detects how it was invoked and chooses the right mode automatically.
9
9
 
@@ -55,7 +55,15 @@ The `start`/`debug` scripts use **tsx** so you can edit TypeScript and restart i
55
55
  npm start
56
56
  ```
57
57
 
58
- Youll see a colourful Ink interface; quit with `Ctrl-C`.
58
+ You'll see a colourful Ink interface; quit with `Ctrl-C`.
59
+
60
+ ### Running in VSCode
61
+
62
+ Factory CLI can also be run inside VSCode using the Factory extension:
63
+
64
+ 1. First, install the Factory VSCode extension (see [VSCode Extension README](../factory-vscode-extension/README.md) for installation instructions)
65
+ 2. Click the **Run Factory** button (🤖) in the editor toolbar to launch Factory CLI in a dedicated terminal
66
+ 3. The extension provides full VSCode context (open files, selections, diagnostics) to Factory via MCP
59
67
 
60
68
  ### Headless Commands
61
69
 
@@ -79,12 +87,12 @@ The extra `--` after `npm start` passes subsequent flags to the CLI.
79
87
 
80
88
  ## 4 · Development vs Production
81
89
 
82
- | Phase | Command(s) | Result |
83
- | ----------- | ------------------------------------ | ------------------------------------------------ |
84
- | **Dev** | `npm start` / `npm run debug` | Runs from TS sources with tsx, fast reload. |
85
- | **Build** | `npm run build` | Compiles TS → `dist/`. |
86
- | **Bundle** | `npm run bundle` (calls `build`) | Generates single executable `bundle/factory.js`. |
87
- | **Publish** | `npm publish` (bundled in `prepare`) | Users install `factory` binary from npm. |
90
+ | Phase | Command(s) | Result |
91
+ | ----------- | ------------------------------------ | ---------------------------------------------- |
92
+ | **Dev** | `npm start` / `npm run debug` | Runs from TS sources with tsx, fast reload. |
93
+ | **Build** | `npm run build` | Compiles TS → `dist/`. |
94
+ | **Bundle** | `npm run bundle` (calls `build`) | Generates single executable `bundle/droid.js`. |
95
+ | **Publish** | `npm publish` (bundled in `prepare`) | Users install `droid` binary from npm. |
88
96
 
89
97
  During CI the `prepare` script produces the bundle automatically.
90
98
 
@@ -96,25 +104,25 @@ During CI the `prepare` script produces the bundle automatically.
96
104
 
97
105
  ```bash
98
106
  # Show authentication status
99
- factory headless status
107
+ droid headless status
100
108
 
101
109
  # Authenticate (opens browser)
102
- factory headless login
110
+ droid headless login
103
111
 
104
112
  # Talk to Droid
105
- factory headless droid "Hello" --session-id dOLpXUI8ux6YdZrg3kCs
113
+ droid headless droid "Hello" --session-id dOLpXUI8ux6YdZrg3kCs
106
114
  ```
107
115
 
108
116
  ### Interactive example
109
117
 
110
118
  ```bash
111
119
  # Simply run with no args
112
- factory
120
+ droid
113
121
  ```
114
122
 
115
123
  ---
116
124
 
117
- ## 6 · Testing the Production **`factory`** Command
125
+ ## 6 · Testing the Production **`droid`** Command
118
126
 
119
127
  Sometimes you need to test the **exact binary** users will get from `npm
120
128
  install -g factory-cli`.
@@ -124,23 +132,23 @@ Follow this workflow:
124
132
  # 1. Build optimised bundle (also compiles TS → JS)
125
133
  npm run bundle
126
134
 
127
- # 2. Link globally so `factory` is on your PATH
135
+ # 2. Link globally so `droid` is on your PATH
128
136
  npm link
129
137
 
130
138
  # 3. Use it anywhere
131
- factory --help
132
- factory headless status
133
- factory headless droid "Hello" --session-id <sessionId>
139
+ droid --help
140
+ droid headless status
141
+ droid headless droid "Hello" --session-id <sessionId>
134
142
 
135
143
  # 4. (Optional) Un-link when finished
136
144
  npm unlink -g factory-cli
137
145
  ```
138
146
 
139
- | Situation | Command to use |
140
- | --------------------------- | ----------------------------------------------------------- |
141
- | Fast iteration / TypeScript | `npm start -- <args>` |
142
- | Debug with inspector | `npm run debug -- <args>` |
143
- | Validate production bundle | `npm run bundle && npm link` then `factory headless <args>` |
147
+ | Situation | Command to use |
148
+ | --------------------------- | --------------------------------------------------------- |
149
+ | Fast iteration / TypeScript | `npm start -- <args>` |
150
+ | Debug with inspector | `npm run debug -- <args>` |
151
+ | Validate production bundle | `npm run bundle && npm link` then `droid headless <args>` |
144
152
 
145
153
  ℹ️ _Tip:_ The extra `--` after `npm start` or `npm run debug` passes the
146
154
  remaining flags **directly to the CLI**.
@@ -155,15 +163,113 @@ The package is `"type": "module"`; all runtime imports use `.js` extensions even
155
163
 
156
164
  ## 8 · Troubleshooting
157
165
 
158
- | Problem | Fix |
159
- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
160
- | `EACCES` when running `factory` | Ensure the bundle is executable (`chmod +x bundle/factory.js`). `npm run bundle` handles this automatically. |
161
- | `module not found` after rename | Run `npm run clean && npm run bundle` to rebuild from scratch. |
162
- | Global command still points to old code | Run `npm unlink -g factory-cli && npm link` to refresh the symlink. |
166
+ | Problem | Fix |
167
+ | --------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
168
+ | `EACCES` when running `droid` | Ensure the bundle is executable (`chmod +x bundle/droid.js`). `npm run bundle` handles this automatically. |
169
+ | `module not found` after rename | Run `npm run clean && npm run bundle` to rebuild from scratch. |
170
+ | Global command still points to old code | Run `npm unlink -g factory-cli && npm link` to refresh the symlink. |
171
+
172
+ ---
173
+
174
+ ## 9 · Logging
175
+
176
+ Factory CLI has two different logging behaviors depending on the execution mode:
177
+
178
+ ### Interactive Mode Logging
179
+
180
+ When running in **interactive TUI mode** (`droid` with no arguments), all logging output is redirected to files to avoid interfering with the clean React/Ink interface:
181
+
182
+ - **Log Directory**: `~/.factory/logs/`
183
+ - **Log Files**: `droid-log-<timestamp>.log` (e.g., `droid-log-2025-01-15T10-30-45-123Z.log`)
184
+ - **Content**: All `logInfo`, `logException`, and `logWarn` calls are written to the timestamped log file
185
+ - **Format**: `[timestamp] LEVEL: message | Context: {...}`
186
+
187
+ **Example log file location:**
188
+
189
+ ```bash
190
+ ~/.factory/logs/droid-log-2025-01-15T10-30-45-123Z.log
191
+ ```
192
+
193
+ **Example log entry:**
194
+
195
+ ```
196
+ [2025-01-15T10:30:45.123Z] INFO: User started interactive session
197
+ [2025-01-15T10:30:47.456Z] ERROR: Failed to initialize MCP client: Connection refused | Context: {"retry": 1}
198
+ ```
199
+
200
+ ### Headless Mode Logging
201
+
202
+ When running **headless commands** (`droid headless <command>`), logging follows standard console output patterns:
203
+
204
+ - **Log Output**: Directly to stdout/stderr using the standard `@factory/logging` package
205
+ - **Integration**: Works with existing telemetry, Sentry, and monitoring systems
206
+ - **Format**: Standard Factory logging format with metadata support
207
+
208
+ ### Accessing Logs
209
+
210
+ **Interactive Mode Logs:**
211
+
212
+ ```bash
213
+ # View the most recent log file
214
+ ls -la ~/.factory/logs/
215
+
216
+ # Tail the logs in real-time (find the most recent file)
217
+ tail -f ~/.factory/logs/droid-log-*.log
218
+
219
+ # View logs from a specific session
220
+ cat ~/.factory/logs/droid-log-2025-01-15T10-30-45-123Z.log
221
+ ```
222
+
223
+ **Headless Mode Logs:**
224
+
225
+ ```bash
226
+ # Logs appear directly in terminal output
227
+ droid headless droid "test message" --session-id abc123
228
+
229
+ # Redirect to file if needed
230
+ droid headless droid "test" --session-id abc123 2>&1 | tee my-session.log
231
+ ```
232
+
233
+ ### Log Cleanup
234
+
235
+ Interactive mode creates a new log file for each session. To manage disk space:
236
+
237
+ ```bash
238
+ # Remove logs older than 7 days
239
+ find ~/.factory/logs -name "droid-log-*.log" -mtime +7 -delete
240
+
241
+ # View total log directory size
242
+ du -sh ~/.factory/logs
243
+ ```
244
+
245
+ ---
246
+
247
+ ## 10 · Tool Registry & Executors Design
248
+
249
+ ### 🔄 What Changed
250
+
251
+ **After:** Dynamic mapping automatically discovers tools from TUI registry
252
+
253
+ ```javascript
254
+ // Tools are automatically discovered from TUI registry
255
+ const toolMapping = buildToolMapping();
256
+ ```
257
+
258
+ ### 🛠 How to Add New Tools
259
+
260
+ 1. **Create executor** in `src/tools/executors/client/` (implement `ClientToolExecutor`)
261
+ 2. **Register in TUI registry** in `src/tools/tui.ts`:
262
+ ```javascript
263
+ getTUIToolRegistry().register({
264
+ tool: myNewCliTool, // from @factory/droid-core/tools/definitions
265
+ executorFactory: () => new MyNewExecutor(),
266
+ });
267
+ ```
268
+ 3. **That's it!** Tool is automatically available in `executeTool()` using its `llmId`
163
269
 
164
270
  ---
165
271
 
166
- ## 9 · Contributing
272
+ ## 11 · Contributing
167
273
 
168
274
  1. `pnpm install` (or `npm install`) at repo root
169
275
  2. `cd apps/factory-cli`