@formlm/cli 0.1.3 → 0.2.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.
Files changed (43) hide show
  1. package/README.md +231 -77
  2. package/dist/commands/connect.d.ts +3 -0
  3. package/dist/commands/connect.d.ts.map +1 -0
  4. package/dist/commands/connect.js +555 -0
  5. package/dist/commands/connect.js.map +1 -0
  6. package/dist/commands/expert.d.ts +3 -0
  7. package/dist/commands/expert.d.ts.map +1 -0
  8. package/dist/commands/expert.js +123 -0
  9. package/dist/commands/expert.js.map +1 -0
  10. package/dist/commands/field.js +3 -3
  11. package/dist/commands/field.js.map +1 -1
  12. package/dist/commands/report.d.ts +3 -0
  13. package/dist/commands/report.d.ts.map +1 -0
  14. package/dist/commands/report.js +507 -0
  15. package/dist/commands/report.js.map +1 -0
  16. package/dist/commands/scale.d.ts +3 -0
  17. package/dist/commands/scale.d.ts.map +1 -0
  18. package/dist/commands/scale.js +289 -0
  19. package/dist/commands/scale.js.map +1 -0
  20. package/dist/commands/share.js +1 -1
  21. package/dist/commands/share.js.map +1 -1
  22. package/dist/commands/skill.d.ts +15 -0
  23. package/dist/commands/skill.d.ts.map +1 -0
  24. package/dist/commands/skill.js +31 -0
  25. package/dist/commands/skill.js.map +1 -0
  26. package/dist/commands/smart.d.ts +16 -0
  27. package/dist/commands/smart.d.ts.map +1 -0
  28. package/dist/commands/smart.js +81 -0
  29. package/dist/commands/smart.js.map +1 -0
  30. package/dist/commands/snapshot.d.ts +13 -0
  31. package/dist/commands/snapshot.d.ts.map +1 -0
  32. package/dist/commands/snapshot.js +61 -0
  33. package/dist/commands/snapshot.js.map +1 -0
  34. package/dist/exec.d.ts +8 -2
  35. package/dist/exec.d.ts.map +1 -1
  36. package/dist/exec.js +28 -2
  37. package/dist/exec.js.map +1 -1
  38. package/dist/index.js +23 -8
  39. package/dist/index.js.map +1 -1
  40. package/dist/mcp.d.ts.map +1 -1
  41. package/dist/mcp.js +441 -272
  42. package/dist/mcp.js.map +1 -1
  43. package/package.json +1 -1
package/README.md CHANGED
@@ -20,13 +20,43 @@ With `formlm-cli`, you can control FormLM directly from your terminal or plug it
20
20
 
21
21
  ---
22
22
 
23
- ## Features
23
+ ## What's New in v0.2.0
24
24
 
25
- - **Dual-mode**: run as a terminal CLI *or* as an MCP Server for AI Agents
26
- - **20 built-in tools** covering full Auth / App / Field / Share lifecycle
27
- - **Multi-profile support** — manage multiple accounts or environments
28
- - **Token auth** — simple and secure, stored locally with 600 permissions
29
- - **MCP-ready** — plug into Claude Desktop, Cursor, or any MCP-compatible client out of the box
25
+ The MCP architecture has been completely redesigned from the ground up:
26
+
27
+ - **34 flat tools → 9 layered tools + 6 knowledge resources**
28
+ - **Intelligence Layer**: `formlm_create` / `formlm_modify` wrap the server-side AssessAgent/BuilderAgent pipeline
29
+ - **Chat-only Risk Confirmation**: `formlm_confirm` executes medium/high-risk `formlm_modify` plans after user approval — no web UI needed
30
+ - **Domain Knowledge**: 6 MCP resources expose SKILL.md files directly to AI agents
31
+ - **State Awareness**: `formlm_snapshot` aggregates all module states in one call
32
+ - **P0 Constraints**: Embedded directly in command descriptions — AI sees them every time
33
+
34
+ ### Architecture
35
+
36
+ ```
37
+ ┌─────────────────────────────────────────────────────────┐
38
+ │ AI Agent (any MCP Client: Claude / Cursor / │
39
+ │ Codex CLI / Windsurf / Cline / ...) │
40
+ ├─────────────────────────────────────────────────────────┤
41
+ │ Tier 0: auth_login, auth_status │
42
+ │ Tier 1: formlm_plan, formlm_create, │
43
+ │ formlm_modify, formlm_confirm ← Smart Pipeline │
44
+ │ Tier 2: formlm_snapshot, formlm_skill ← State + Knowledge│
45
+ │ Tier 3: formlm_exec ← Direct Commands │
46
+ ├─────────────────────────────────────────────────────────┤
47
+ │ Resources: formlm://skills/{form,scale,connect, │
48
+ │ report,expert,share} │
49
+ ├─────────────────────────────────────────────────────────┤
50
+ │ formlm-cli MCP Server │
51
+ ├─────────────────────────────────────────────────────────┤
52
+ │ FormLM Server (McpV1Api) │
53
+ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
54
+ │ │AssessAgent│ │BuilderAgent│ │CliService│ │SKILL.md │ │
55
+ │ │ (Plan+ │ │ (Think+ │ │ (picocli │ │ (domain │ │
56
+ │ │ Execute) │ │ Reflect)│ │ dispatch)│ │ rules) │ │
57
+ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
58
+ └─────────────────────────────────────────────────────────┘
59
+ ```
30
60
 
31
61
  ---
32
62
 
@@ -38,7 +68,7 @@ npm install -g @formlm/cli
38
68
 
39
69
  Requires Node.js ≥ 18.
40
70
 
41
- For a detailed step-by-step guide (including MCP setup for Claude / Cursor), see **[INSTALL.md](INSTALL.md)**.
71
+ For a detailed step-by-step guide (including MCP setup for Claude Desktop / Cursor / Codex CLI / Windsurf / Cline), see **[INSTALL.md](INSTALL.md)**.
42
72
 
43
73
  ---
44
74
 
@@ -52,42 +82,94 @@ formlm-cli auth login
52
82
  formlm-cli auth login --token <your-token>
53
83
  ```
54
84
 
55
- > You can also get your token from [formlm.me](https://formlm.me): open DevTools → Application → Cookies → copy the `Authorization` value.
56
-
57
- ### 2. Use the CLI
85
+ ### 2. Smart Pipeline (AI-recommended)
58
86
 
59
87
  ```bash
60
- # List all apps
61
- formlm-cli app list
88
+ # Preview the plan before executing (optional, for user review)
89
+ formlm-cli smart plan --input "Create a workplace stress assessment with 10 questions, 3 dimensions"
62
90
 
63
- # Create a new app
64
- formlm-cli app create --name "Customer Survey" --description "2024 annual survey"
91
+ # Generate a complete assessment app from natural language
92
+ formlm-cli smart create --input "Create a workplace stress assessment with 10 questions, 3 dimensions, and detailed score interpretations"
65
93
 
66
- # Add a field
67
- formlm-cli field add --app <appId> --id q1 --name "Your Name" --type input --required
94
+ # Modify an existing app
95
+ formlm-cli smart modify --app <appId> --input "Add a new dimension for workplace social support"
68
96
 
69
- # Add a radio field with scores
70
- formlm-cli field add --app <appId> --id s1 --type radio --options "Satisfied:3,Neutral:2,Unsatisfied:1"
97
+ # If the change is medium/high risk, smart modify returns a plan preview instead of executing.
98
+ # Show the plan to the user, then confirm and execute it (no web UI needed):
99
+ formlm-cli smart confirm --app <appId> --plan-json '<the exact "plan" JSON returned above>'
100
+ ```
71
101
 
72
- # Publish the form
73
- formlm-cli share publish --app <appId>
102
+ ### 3. Direct Commands (for fine-grained control)
74
103
 
75
- # Get the shareable URL
76
- formlm-cli share url --app <appId>
104
+ ```bash
105
+ # Get a snapshot of all module states
106
+ formlm-cli snapshot --app <appId>
107
+
108
+ # Read a skill document before constructing commands
109
+ formlm-cli skill form
110
+ formlm-cli skill scale
111
+
112
+ # Scale commands
113
+ formlm-cli scale query --app <appId>
114
+ formlm-cli scale add --app <appId> --id stress --name "Stress Level" --format sum --kbText "..."
115
+ formlm-cli scale keys add --app <appId> --scale stress --fields q1,q2,q3
116
+ formlm-cli scale data add --app <appId> --scale stress --ranges "0-10:Low,11-20:Moderate,21-30:High"
117
+
118
+ # Report commands
119
+ formlm-cli report query --app <appId>
120
+ formlm-cli report page add --app <appId> --name "Summary" --layout grid
121
+ formlm-cli report widget add --app <appId> --page <pageId> --type chart --chartType bar --name "Score Chart"
122
+
123
+ # Expert commands
124
+ formlm-cli expert query --app <appId>
125
+ formlm-cli expert config --app <appId> --enableChat true
77
126
  ```
78
127
 
79
- ### 3. Use as MCP Server
128
+ ### 4. Use as MCP Server
80
129
 
81
130
  ```bash
82
131
  formlm-cli mcp
83
132
  ```
84
133
 
85
- This starts the MCP Server (stdio transport), ready for AI Agents to connect.
134
+ This starts the MCP Server (stdio transport) with 9 tools + 6 resources, ready for AI Agents to connect.
86
135
 
87
136
  ---
88
137
 
89
138
  ## Command Reference
90
139
 
140
+ ### Smart Pipeline (AI-recommended)
141
+
142
+ ```bash
143
+ # Generate a complete app from natural language
144
+ formlm-cli smart create --input "..." [--plan-type assessment] [--style "温暖亲切"] [--question-count 10-15]
145
+
146
+ # Modify an existing app
147
+ formlm-cli smart modify --app <appId> --input "..."
148
+
149
+ # Confirm and execute a medium/high risk plan returned by smart modify (skips Think/Plan, no web UI needed)
150
+ formlm-cli smart confirm --app <appId> --plan-json '<exact plan JSON from smart modify>'
151
+ ```
152
+
153
+ ### Snapshot
154
+
155
+ ```bash
156
+ # Get all module states in one call
157
+ formlm-cli snapshot --app <appId>
158
+ formlm-cli snapshot --app <appId> --module scale # Only scale module
159
+ ```
160
+
161
+ ### Skill Documents
162
+
163
+ ```bash
164
+ # Get SKILL.md domain knowledge (P0/P1/P2 constraints, command templates)
165
+ formlm-cli skill form # Form field rules
166
+ formlm-cli skill scale # Scale dimension rules
167
+ formlm-cli skill connect # Page styling rules
168
+ formlm-cli skill report # Report layout rules
169
+ formlm-cli skill expert # Expert interpretation rules
170
+ formlm-cli skill share # Share/publish rules
171
+ ```
172
+
91
173
  ### Auth
92
174
 
93
175
  ```bash
@@ -111,9 +193,9 @@ formlm-cli --profile work app list # Use a profile for one command
111
193
  ```bash
112
194
  formlm-cli app list
113
195
  formlm-cli app create --name "My Form" --description "..."
114
- formlm-cli app get --app <appId>
115
196
  formlm-cli app update --app <appId> --name "New Name" --theme blue
116
- formlm-cli app delete --app <appId>
197
+ formlm-cli app remove --app <appId> # Delete an app (irreversible)
198
+ formlm-cli app urls --app <appId> # Get fill-in / editor / data URLs
117
199
  ```
118
200
 
119
201
  ### Field
@@ -123,83 +205,155 @@ formlm-cli field schema # All supported
123
205
  formlm-cli field config --type radio # Configurable props for a type
124
206
  formlm-cli field list --app <appId>
125
207
  formlm-cli field find --app <appId> --id q1 # Get a single field
126
- formlm-cli field find --app <appId> --filter "name" # Search fields by keyword
127
208
  formlm-cli field add --app <appId> --id q1 --name "Name" --type input --required
128
- formlm-cli field add --app <appId> --id n1 --type scale --min 1 --max 10
129
209
  formlm-cli field update --app <appId> --id q1 --title "Your Full Name"
130
210
  formlm-cli field remove --app <appId> --id q1
131
211
  formlm-cli field set-property --app <appId> --id q1 --property options.0.score --value 5
132
212
  ```
133
213
 
134
- ### Share
214
+ ### Scale (Dimensions & Scoring)
135
215
 
136
216
  ```bash
137
- formlm-cli share publish --app <appId> # Publish (each respondent can submit once; unlimited respondents)
138
- formlm-cli share unpublish --app <appId> # Unpublish
139
- formlm-cli share query --app <appId> # Check publish status
140
- formlm-cli share url --app <appId> # Get the shareable URL
217
+ formlm-cli scale query --app <appId> # List all dimensions
218
+ formlm-cli scale find --app <appId> --id <scaleId> # Find a dimension
219
+ formlm-cli scale add --app <appId> --id stress --name "Stress" --format sum --kbText "..."
220
+ formlm-cli scale update --app <appId> --id stress --name "Stress Level"
221
+ formlm-cli scale set --app <appId> --id stress --direction negative
222
+ formlm-cli scale remove --app <appId> --id stress
223
+ formlm-cli scale clear --app <appId>
224
+ formlm-cli scale config --app <appId> --enable-single true
225
+
226
+ # Associate fields with a dimension
227
+ formlm-cli scale keys add --app <appId> --scale stress --fields q1,q2,q3 [--polarities "q3:negative"]
228
+ formlm-cli scale keys remove --app <appId> --scale stress --fields q1
229
+ formlm-cli scale keys list --app <appId> --scale stress
230
+ formlm-cli scale keys set --app <appId> --scale stress --fields q3 --negScore true
231
+
232
+ # Configure score ranges
233
+ formlm-cli scale data add --app <appId> --scale stress --ranges "0-10:Low,11-20:High"
234
+ formlm-cli scale data update --app <appId> --scale stress --id <dataId> --value "Moderate"
235
+ formlm-cli scale data remove --app <appId> --scale stress --id <dataId>
236
+ formlm-cli scale data list --app <appId> --scale stress
237
+ formlm-cli scale data clear --app <appId> --scale stress
141
238
  ```
142
239
 
143
- ---
240
+ ### Connect (Page Styling & Visual Design)
144
241
 
145
- ## MCP Integration
242
+ ```bash
243
+ formlm-cli connect query --app <appId> [--type cover|main|final] [--filter <keyword>] --md
244
+ formlm-cli connect find --app <appId> --filter <keyword>
245
+ formlm-cli connect types [--category cover|main|final] --verbose
246
+ formlm-cli connect config --category cover --format rich-text
247
+
248
+ # Cover page management
249
+ formlm-cli connect cover-page add --app <appId> --id cover_main --name "Welcome" --format text --value "<h1>Hello</h1>"
250
+ formlm-cli connect cover-page update --app <appId> --id cover_main --name "New Title"
251
+ formlm-cli connect cover-page find --app <appId> [--id cover_main]
252
+ formlm-cli connect cover-page remove --app <appId> [--id cover_main]
253
+
254
+ # Final page management
255
+ formlm-cli connect final-page add --app <appId> --id final_report --name "Thank You" --enable-report true
256
+ formlm-cli connect final-page update --app <appId> --id final_report --name "Done"
257
+ formlm-cli connect final-page find --app <appId> [--id final_report]
258
+ formlm-cli connect final-page remove --app <appId> [--id final_report]
259
+
260
+ # Main page management
261
+ formlm-cli connect main-page set --app <appId> --format card
262
+ formlm-cli connect main-page set --app <appId> --field X1 --description "<p>Context</p>"
263
+
264
+ # Visual style
265
+ formlm-cli connect style set --app <appId> --type cover --bg "#f3f3fe" --fg "#ffffff" --font "#01105c"
266
+ formlm-cli connect style query --app <appId> --type cover
267
+ formlm-cli connect style apply --app <appId> --look "deep blue tech, frosted glass cards" [--theme Minimal] [--layout flat]
268
+ formlm-cli connect style apply-all --app <appId> --look "light warm Japanese style" [--theme Minimal] [--layout flat]
269
+ formlm-cli connect style move --app <appId> --id <pageId> --direction up
270
+ ```
271
+
272
+ ### Report (Pages & Widgets)
146
273
 
147
- ### Claude Desktop
274
+ ```bash
275
+ formlm-cli report query --app <appId> # List all report pages
276
+ formlm-cli report find --app <appId> --filter <keyword> # Find report widget
277
+ formlm-cli report update --app <appId> --page <pageId> --name "New Name"
278
+
279
+ # Page management
280
+ formlm-cli report page add --app <appId> --name "Summary" --layout grid
281
+ formlm-cli report page update --app <appId> --id <pageId> --name "Overview"
282
+ formlm-cli report page remove --app <appId> --id <pageId>
283
+
284
+ # Widget management
285
+ formlm-cli report widget list --app <appId> --page <pageId>
286
+ formlm-cli report widget find --app <appId> --filter <keyword>
287
+ formlm-cli report widget set --app <appId> --id <widgetId> --value "{{TotalScore}}"
288
+ formlm-cli report widget add --app <appId> --page <pageId> --type chart --chartType bar --name "Score Chart"
289
+ formlm-cli report widget update --app <appId> --id <widgetId> --name "Updated Chart"
290
+ formlm-cli report widget remove --app <appId> --id <widgetId>
291
+ formlm-cli report widget types --category chart
292
+ formlm-cli report widget config --type chart --prop chartType
293
+
294
+ # Logic rules
295
+ formlm-cli report logic add --app <appId> --page <pageId> --condition "score>20" --action show
296
+ formlm-cli report logic list --app <appId> --page <pageId>
297
+ formlm-cli report logic remove --app <appId> --id <logicId>
298
+ ```
148
299
 
149
- Add to your `claude_desktop_config.json`:
300
+ ### Expert (AI Interpretation)
150
301
 
151
- ```json
152
- {
153
- "mcpServers": {
154
- "formlm": {
155
- "command": "formlm-cli",
156
- "args": ["mcp"]
157
- }
158
- }
159
- }
302
+ ```bash
303
+ formlm-cli expert query --app <appId> # Query expert config
304
+ formlm-cli expert find --app <appId> # Find expert details
305
+ formlm-cli expert config --app <appId> --enableChat true # Full configuration
306
+ formlm-cli expert set --app <appId> --key model --value gpt-4
307
+ formlm-cli expert avatar --app <appId> --name "Dr. AI" --avatar <url>
308
+ formlm-cli expert remove --app <appId>
309
+ formlm-cli expert chat --app <appId> --message "Explain my score"
160
310
  ```
161
311
 
162
- > **No token? No problem.** If you omit `FORMLM_TOKEN`, the AI will prompt you to authenticate via the `auth_login` tool — just provide your token or email + password directly in the chat.
312
+ ### Share
163
313
 
164
- ### Cursor / VS Code
314
+ ```bash
315
+ formlm-cli share publish --app <appId> # Publish (each respondent can submit once; unlimited respondents)
316
+ formlm-cli share unpublish --app <appId> # Unpublish
317
+ formlm-cli share query --app <appId> # Check publish status
318
+ formlm-cli share url --app <appId> # Get the shareable URL
319
+ ```
165
320
 
166
- Add the same block to `.cursor/mcp.json`.
321
+ ---
167
322
 
168
- ### Let your AI Agent install it
323
+ ## MCP Integration
169
324
 
170
- Paste this into any AI chat:
325
+ FormLM CLI works as a standard MCP Server over stdio and plugs into **any MCP-compatible AI platform** — Claude Desktop, Cursor, Codex CLI, Windsurf, Cline, etc.
171
326
 
172
- ```
173
- Help me install FormLM CLI from https://github.com/formlm/cli,
174
- then run: formlm-cli auth login
175
- ```
327
+ > **⚠️ macOS/Linux users:** desktop AI clients often launch the MCP server without your full terminal PATH, which can cause `command not found` errors. See **[INSTALL.md → Step 4](INSTALL.md#step-4--connect-to-an-ai-agent-mcp-mode)** for the `env.PATH` fix, per-platform config file locations (including Codex CLI's TOML format), and the full setup guide.
328
+
329
+ > **No token? No problem.** If you omit `FORMLM_TOKEN`, the AI will prompt you to authenticate via the `auth_login` tool — just provide your email + password (or token) directly in the chat.
176
330
 
177
331
  ---
178
332
 
179
- ## Available MCP Tools (20)
333
+ ## Available MCP Tools (9)
180
334
 
181
- | Category | Tool | Description |
335
+ | Tier | Tool | Description |
182
336
  |---|---|---|
183
- | Auth | `auth_login` | Login with token or email + password |
184
- | Auth | `auth_status` | Check current login status |
185
- | App | `app_list` | List all apps |
186
- | App | `app_create` | Create a new app |
187
- | App | `app_get` | Get app details |
188
- | App | `app_update` | Update app name / description / theme |
189
- | App | `app_delete` | Delete an app |
190
- | Field | `field_schema` | List all supported field types |
191
- | Field | `field_config` | Get configurable properties for a field type |
192
- | Field | `field_list` | List all fields in an app |
193
- | Field | `field_find` | Get a single field by ID or keyword |
194
- | Field | `field_add` | Add a new field |
195
- | Field | `field_update` | Update a field |
196
- | Field | `field_remove` | Remove a field |
197
- | Field | `field_move` | Move a field to a specific position |
198
- | Field | `field_set_property` | Fine-grained field property update |
199
- | Share | `share_publish` | Publish the form (each respondent can submit once; unlimited respondents) |
200
- | Share | `share_unpublish` | Unpublish the form |
201
- | Share | `share_query` | Query publish status |
202
- | Share | `share_url` | Get the form fill-in URL |
337
+ | 0 | `auth_login` | Login with token or email + password |
338
+ | 0 | `auth_status` | Check current login status |
339
+ | 1 | `formlm_plan` | Preview execution plan without executing (for user review before create) |
340
+ | 1 | `formlm_create` | Generate a complete app from natural language (AssessAgent pipeline) |
341
+ | 1 | `formlm_modify` | Modify an existing app via natural language (BuilderAgent pipeline) |
342
+ | 1 | `formlm_confirm` | Confirm and execute a medium/high risk plan returned by `formlm_modify` — no web UI needed |
343
+ | 2 | `formlm_snapshot` | Get aggregated state of all modules (form/scale/connect/report/expert/share) |
344
+ | 2 | `formlm_skill` | Fetch SKILL.md domain knowledge for a skill module |
345
+ | 3 | `formlm_exec` | Execute any whitelisted CLI command directly |
346
+
347
+ ## Available MCP Resources (6)
348
+
349
+ | Resource URI | Description |
350
+ |---|---|
351
+ | `formlm://skills/form` | Form field SKILL.md — P0 constraints, field types, scoring rules |
352
+ | `formlm://skills/scale` | Scale dimension SKILL.md — range rules, polarity, direction |
353
+ | `formlm://skills/connect` | Connect page SKILL.md — theme modes, layout formats |
354
+ | `formlm://skills/report` | Report layout SKILL.md — widget types, variables, logic |
355
+ | `formlm://skills/expert` | Expert interpretation SKILL.md — AI config, chat rules |
356
+ | `formlm://skills/share` | Share/publish SKILL.md — access types, idempotency |
203
357
 
204
358
  ---
205
359
 
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare function registerConnectCommand(parent: Command): void;
3
+ //# sourceMappingURL=connect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/commands/connect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAsd5D"}