capman 0.4.1 → 0.4.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/README.md CHANGED
@@ -32,21 +32,21 @@ User query → match capability → resolve via API or nav → structured result
32
32
 
33
33
  ## Quick Start
34
34
 
35
- **1. Create your manifest config**
35
+ **1. Generate your manifest — three ways:**
36
36
 
37
37
  ```bash
38
- npx capman init
39
- ```
38
+ # From an OpenAPI/Swagger spec (fastest, no API key needed)
39
+ npx capman generate --from openapi.json
40
+ npx capman generate --from https://api.your-app.com/openapi.json
40
41
 
41
- Edit `capman.config.js` to define your app's capabilities.
42
+ # AI-assisted describe your app in plain English
43
+ npx capman generate --ai
42
44
 
43
- **2. Generate the manifest**
44
-
45
- ```bash
46
- npx capman generate
45
+ # Manual edit capman.config.js yourself
46
+ npx capman init
47
47
  ```
48
48
 
49
- **3. Use the engine in your AI agent**
49
+ **2. Use the engine in your AI agent**
50
50
 
51
51
  ```typescript
52
52
  import { CapmanEngine, readManifest } from 'capman'
@@ -66,7 +66,7 @@ console.log(result.resolvedVia) // 'keyword' | 'llm' | 'cache'
66
66
  console.log(result.trace.reasoning) // ['Matched "check_product_availability" with 100% confidence', ...]
67
67
  ```
68
68
 
69
- **4. See it live**
69
+ **3. See it live**
70
70
 
71
71
  ```bash
72
72
  npx capman demo
@@ -74,6 +74,61 @@ npx capman demo
74
74
 
75
75
  ---
76
76
 
77
+ ## Manifest Generation
78
+
79
+ capman gives you three ways to create your manifest — pick based on what you have:
80
+
81
+ ### From OpenAPI / Swagger spec
82
+
83
+ If your backend has an OpenAPI spec (most do), capman reads it and generates a complete manifest automatically. No LLM needed, no API key, works offline.
84
+
85
+ ```bash
86
+ npx capman generate --from openapi.json
87
+ npx capman generate --from https://api.your-app.com/openapi.json
88
+ ```
89
+
90
+ What it does automatically:
91
+ - Converts every endpoint into a capability with correct ID, name, and description
92
+ - Extracts path params, query params, and request body fields
93
+ - Infers privacy scope from security schemes — bearer token → `user_owned`, admin tags → `admin`, no auth → `public`
94
+ - Generates natural language examples from the operation summary
95
+ - Writes a ready `capman.config.js` for you to review and adjust
96
+
97
+ ```
98
+ ✓ Parsed 19 capabilities from spec
99
+ ✓ Config written to capman.config.js
100
+ ✓ Manifest written to manifest.json
101
+ ```
102
+
103
+ ### AI-assisted generation
104
+
105
+ No OpenAPI spec? Describe your app in plain English and capman uses an LLM to generate a full manifest.
106
+
107
+ ```bash
108
+ npx capman generate --ai
109
+ ```
110
+
111
+ ```
112
+ Describe your app and its main capabilities:
113
+ > A SaaS CRM. Users can create contacts, log calls, view pipeline
114
+ stages. Admins can manage teams and billing.
115
+
116
+ Using anthropic to generate manifest...
117
+ ✓ 6 capabilities generated
118
+ ```
119
+
120
+ Requires one of: `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, or `OPENROUTER_API_KEY` in your environment.
121
+
122
+ ### Manual
123
+
124
+ For full control, start from a starter config and define capabilities yourself:
125
+
126
+ ```bash
127
+ npx capman init
128
+ ```
129
+
130
+ ---
131
+
77
132
  ## Execution Trace
78
133
 
79
134
  Every `engine.ask()` call returns a full execution trace — so you always know why the AI did what it did.
@@ -112,19 +167,6 @@ Debug any query from the CLI:
112
167
  npx capman run "check availability for blue jacket" --debug
113
168
  ```
114
169
 
115
- ```
116
- ✓ Matched: check_product_availability
117
- Intent: retrieval
118
- Confidence: 100%
119
- Resolver: api
120
- Params: product=blue-jacket
121
-
122
- ── All candidates:
123
- ✓ check_product_availability: 100%
124
- ○ get_order_status: 12%
125
- ○ navigate_to_screen: 0%
126
- ```
127
-
128
170
  ---
129
171
 
130
172
  ## Matching Modes
@@ -171,29 +213,15 @@ import { CapmanEngine, FileCache, FileLearningStore } from 'capman'
171
213
 
172
214
  const engine = new CapmanEngine({
173
215
  manifest,
174
- // Default: MemoryCache (fast, resets on restart)
175
- // For persistence across restarts:
176
216
  cache: new FileCache('.capman/cache.json'),
177
217
  learning: new FileLearningStore('.capman/learning.json'),
178
218
  })
179
219
 
180
- // After real usage, see what's happening
181
220
  const stats = await engine.getStats()
182
- console.log(stats)
183
- // {
184
- // totalQueries: 142,
185
- // llmQueries: 18,
186
- // cacheHits: 67,
187
- // outOfScope: 3,
188
- // index: { 'availability': { 'check_product_availability': 34 }, ... }
189
- // }
221
+ // { totalQueries: 142, llmQueries: 18, cacheHits: 67, outOfScope: 3 }
190
222
 
191
223
  const top = await engine.getTopCapabilities(3)
192
- // [
193
- // { id: 'check_product_availability', hits: 58 },
194
- // { id: 'navigate_to_screen', hits: 41 },
195
- // { id: 'get_order_status', hits: 28 },
196
- // ]
224
+ // [{ id: 'check_product_availability', hits: 58 }, ...]
197
225
  ```
198
226
 
199
227
  ---
@@ -212,77 +240,29 @@ const engine = new CapmanEngine({
212
240
  userId: 'user-123', // auto-injected into session params
213
241
  },
214
242
  })
215
-
216
- // user_owned capabilities require auth — blocked without it
217
- // admin capabilities require role: 'admin' — blocked for regular users
218
- // session params like {user_id} are auto-replaced from auth.userId
219
243
  ```
220
244
 
221
245
  ---
222
246
 
223
247
  ## Resolver Hardening
224
248
 
225
- Configure retries and timeouts per call:
226
-
227
249
  ```typescript
228
250
  const result = await engine.ask('show my orders', {
229
- retries: 2, // retry failed requests (default: 0)
230
- timeoutMs: 3000, // abort after 3 seconds (default: 5000)
251
+ retries: 2,
252
+ timeoutMs: 3000,
231
253
  })
232
254
  ```
233
255
 
234
256
  ---
235
257
 
236
- ## Capability Config
237
-
238
- Each capability in `capman.config.js`:
239
-
240
- ```javascript
241
- module.exports = {
242
- app: 'your-app',
243
- baseUrl: 'https://api.your-app.com',
244
- capabilities: [
245
- {
246
- id: 'check_product_availability',
247
- name: 'Check product availability',
248
- description: 'Check stock and pricing for a product by name or ID.',
249
- examples: [
250
- 'Is the blue jacket available?',
251
- 'Check availability for product 42',
252
- 'Do you have size M in stock?',
253
- ],
254
- params: [
255
- {
256
- name: 'product',
257
- description: 'Product name or ID',
258
- required: true,
259
- source: 'user_query', // extracted from the query
260
- },
261
- ],
262
- returns: ['stock', 'price', 'variants'],
263
- resolver: {
264
- type: 'api', // 'api' | 'nav' | 'hybrid'
265
- endpoints: [
266
- { method: 'GET', path: '/products/{product}/availability' },
267
- ],
268
- },
269
- privacy: {
270
- level: 'public', // 'public' | 'user_owned' | 'admin'
271
- note: 'No auth required',
272
- },
273
- },
274
- ],
275
- }
276
- ```
277
-
278
- ---
279
-
280
258
  ## CLI Commands
281
259
 
282
260
  | Command | What it does |
283
261
  |---|---|
284
262
  | `capman init` | Create a starter `capman.config.js` |
285
- | `capman generate` | Generate `manifest.json` from config |
263
+ | `capman generate` | Generate manifest from `capman.config.js` |
264
+ | `capman generate --from <path\|url>` | Generate from OpenAPI/Swagger spec |
265
+ | `capman generate --ai` | Generate manifest using AI |
286
266
  | `capman validate` | Validate your manifest for errors |
287
267
  | `capman inspect` | Print all capabilities in the manifest |
288
268
  | `capman run "query"` | Run a query against your manifest |
@@ -326,20 +306,19 @@ module.exports = {
326
306
 
327
307
  **Works well:**
328
308
  - Structured data retrieval via APIs
329
- - Navigating to known app screens
330
- - Multi-endpoint aggregation
309
+ - Auto-generating manifests from OpenAPI specs
331
310
  - Privacy enforcement per capability
332
- - Caching repeated queries
333
311
  - Full execution tracing and debugging
312
+ - Caching repeated queries
334
313
 
335
314
  **Current limits:**
336
315
  - Real-time infra status (is the server down?)
337
316
  - UI-only state with no API backing
338
317
  - Very ambiguous queries — use `mode: 'accurate'` with an LLM
339
- - Cross-app orchestration (planned)
318
+ - Multi-instance deployments need Redis adapter (planned for v0.5)
340
319
 
341
320
  ---
342
321
 
343
322
  ## License
344
323
 
345
- MIT — [github.com/Hobbydefiningdoctory/capman](https://github.com/Hobbydefiningdoctory/capman)
324
+ MIT — [github.com/Hobbydefiningdoctory/capman]