@getmarrow/sdk 3.7.0 → 3.7.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.
Files changed (2) hide show
  1. package/README.md +48 -422
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -5,284 +5,8 @@
5
5
  ![npm](https://img.shields.io/npm/v/@getmarrow/sdk)
6
6
  ![npm](https://img.shields.io/npm/dw/@getmarrow/sdk)
7
7
  ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@getmarrow/sdk)
8
- ![GitHub](https://img.shields.io/github/license/MajinBuu0x9/marrow-sdk)
9
- ![TypeScript](https://img.shields.io/badge/TypeScript-5.3%2B-blue)
10
- ![Node.js](https://img.shields.io/badge/Node.js-18%2B-green)
11
8
 
12
- Most agents still work like this:
13
- - they plan something
14
- - they do something
15
- - they forget what happened
16
- - then they repeat the same mistake next session
17
-
18
- That's fine for a toy. It's a problem for anything real.
19
-
20
- `@getmarrow/sdk` gives your agent a memory that compounds. It lets you log intent before meaningful work, pull back useful decision intelligence, and commit the outcome afterward so the next run starts smarter instead of blank.
21
-
22
- **Marrow turns agent memory from a passive log into an operating loop.**
23
-
24
- ---
25
-
26
- ## Improvement Since Onboarding
27
-
28
- Every dashboard and digest call now returns an `improvement` block comparing your agents' current performance against their day-1 baseline, captured automatically when an account reaches 7 days of activity or 20 decisions, whichever comes first.
29
-
30
- ```typescript
31
- const dash = await marrow.dashboard();
32
- if (dash.improvement.status === 'active') {
33
- console.log(`Agents are ${Math.abs(dash.improvement.time_to_success_seconds.delta_pct)}% ${
34
- dash.improvement.time_to_success_seconds.delta_pct < 0 ? 'faster' : 'slower'
35
- } since onboarding (${dash.improvement.days_since_baseline} days ago).`);
36
- }
37
- ```
38
-
39
- Four measured deltas: `attempts_per_success`, `time_to_success_seconds`, `drift_rate`, `success_rate`, each with `baseline`, `current`, and `delta_pct`.
40
-
41
- **No heuristics, no estimates.** The baseline is a frozen snapshot of your agents' own first week. Everything is computed from real decision data. Token-usage savings estimates remain on the enterprise roadmap.
42
-
43
- ---
44
-
45
- ## What's New in v3.6.0
46
-
47
- ### Agent-Narrated Marrow Contribution
48
-
49
- Marrow now tells the agent exactly what it contributed to each decision, so the agent can surface that contribution to the user in plain English — no dashboard required.
50
-
51
- - `think()` returns `marrow_contributed` describing intelligence Marrow surfaced (warnings consulted, hive patterns, similar decisions, workflow templates, loop detection, collective insight).
52
- - `commit()` returns `marrow_contributed` with concrete signals (pattern reused, warning avoided, workflow step).
53
- - `endSession()` returns `session_summary` aggregating Marrow's contribution across the session, with a one-line `narrative` for the agent to surface.
54
-
55
- Each object has `has_signal: boolean` — agent narrates when true, stays quiet when false. The MCP `marrow-always-on` system prompt instructs agents on tone and timing.
56
-
57
- ```typescript
58
- const result = await marrow.think({ action: 'deploy auth refactor', type: 'implementation' });
59
- if (result.marrow_contributed?.has_signal) {
60
- // Agent can mention: "Pulling 12 similar patterns from the hive..."
61
- // Or: "Marrow flagged this approach failed 4× last week..."
62
- }
63
- ```
64
-
65
- Counts and booleans only — no decision content, no PII echoed back.
66
-
67
- ---
68
-
69
- ## Agent-Narrated Milestones
70
-
71
- `commit()` returns a `narrative` field. When a milestone fires (first commit, baseline capture, decision #100/500/1000/5000, or a meaningful weekly recap), the backend returns a human-readable string the agent can relay to the user. Otherwise returns null.
72
-
73
- Example:
74
-
75
- ```typescript
76
- const result = await marrow.commit({ success: true, outcome: 'Deploy succeeded' });
77
- if (result.narrative) { console.log('Marrow:', result.narrative); }
78
- ```
79
-
80
- Narratives are pure aggregated metrics, no user data, no decision content. No heuristics.
81
-
82
- ---
83
-
84
- ## Passive Mode
85
-
86
- Three patterns for auto-logging agent decisions — pick what fits your runtime.
87
-
88
- ### Per-function: wrap(meta, fn)
89
-
90
- ```typescript
91
- await marrow.wrap(
92
- { action: 'deploy release', type: 'process', external: true },
93
- () => deploy()
94
- );
95
- ```
96
-
97
- ### Per-object: autoWrap(client)
98
-
99
- ```typescript
100
- const wrappedAgent = marrow.autoWrap(myAgent, {
101
- actionPrefix: 'claims-agent: ',
102
- exclude: ['getConfig', 'toJSON'],
103
- type: 'process',
104
- });
105
-
106
- await wrappedAgent.deploy();
107
- ```
108
-
109
- ### Per-fetch: wrapFetch(fetch)
110
-
111
- ```typescript
112
- const wrappedFetch = marrow.wrapFetch(fetch);
113
- await wrappedFetch('https://api.example.com/deploy?token=secret', {
114
- method: 'POST',
115
- });
116
- ```
117
-
118
- Pairs with `@getmarrow/mcp@3.2.0` PostToolUse hooks. MCP users get passive via hooks, SDK users get it via `autoWrap`. See `PASSIVE-MODE.md` in the marketing docs for the full pitch story.
119
-
120
- ---
121
-
122
- ## Operator Dashboard
123
-
124
- One call returns everything an operator needs to see — account health, top failures, workflow status, recent activity, and Marrow's impact.
125
-
126
- ```typescript
127
- const dash = await marrow.dashboard();
128
- // dash.health.overall_score, dash.top_failures, dash.impact.saves_this_week, ...
129
- ```
130
-
131
- ## Weekly Digest
132
-
133
- Periodic summary with success rate trend vs previous period.
134
-
135
- ```typescript
136
- const digest = await marrow.digest('7d');
137
- // digest.summary, digest.success_rate.direction, digest.saves.count, ...
138
- ```
139
-
140
- ## Session Management
141
-
142
- ### Explicit Session End
143
-
144
- Gracefully close a session and optionally auto-commit any open decision — prevents orphaned decisions.
145
-
146
- ```typescript
147
- await marrow.endSession(true); // true = auto-commit any open decision
148
- ```
149
-
150
- ## Auto-Workflow Detection
151
-
152
- When Marrow detects a recurring decision sequence (5+ occurrences), it surfaces it in `orient()` as a suggestion. Accept it to convert the pattern into an enforced workflow.
153
-
154
- ```typescript
155
- await marrow.acceptDetectedWorkflow(detectedId);
156
- ```
157
-
158
- ## Intelligence Fields in think() Response
159
-
160
- - `onboarding_hint` — contextual tip for new accounts (first 50 decisions)
161
- - `intelligence.collective` — anonymized insights aggregated from all Marrow accounts (k-anonymity ≥5)
162
- - `intelligence.team_context` — recent decisions from other sessions in the same account
163
-
164
- ---
165
-
166
- ## Velocity Metrics
167
-
168
- Dashboard and digest now include three measured velocity metrics so operators can see how agents get better over time:
169
-
170
- - `attempts_per_success` — average number of decisions an agent makes before landing a success
171
- - `time_to_success_seconds` — median seconds from `think()` to successful `commit()`
172
- - `drift_rate` — % of decisions that didn't link to a known pattern (lower = more reuse, less rediscovery)
173
-
174
- Each metric reports `{current, previous, delta_pct, direction}` so trends are visible at a glance.
175
-
176
- ```typescript
177
- const dash = await marrow.dashboard();
178
- console.log(dash.velocity.attempts_per_success.direction); // 'improving'
179
- console.log(dash.velocity.time_to_success_seconds.current); // 47
180
- ```
181
-
182
- All metrics are computed from real decision data, no estimates, no heuristics. Token-usage savings are on the enterprise roadmap.
183
-
184
- ## Available Templates
185
-
186
- 24 pre-built workflow templates across 8 industries. Browse via `listTemplates()` and install with `installTemplate(slug)`.
187
-
188
- - **Insurance (4):** `claims-triage`, `fraud-review`, `underwriting-decision`, `complaint-escalation`
189
- - **Healthcare (4):** `patient-triage`, `clinical-documentation`, `prior-authorization`, `coding-audit`
190
- - **E-commerce (3):** `order-fulfillment`, `refund-approval`, `return-processing`
191
- - **Legal (3):** `contract-review`, `case-triage`, `document-discovery`
192
- - **SaaS (6):** `code-review-deploy`, `incident-response`, `feature-rollout`, `ticket-triage`, `escalation-flow`, `lead-qualify`
193
- - **Fintech (2):** `etl-pipeline`, `approval-flow`
194
- - **Media (1):** `content-publish`
195
- - **Enterprise (1):** `change-management`
196
-
197
- Full catalog with descriptions and step-by-step details: [getmarrow.ai/docs#template-marketplace](https://getmarrow.ai/docs/#template-marketplace)
198
-
199
- ```typescript
200
- const templates = await marrow.listTemplates({ industry: 'insurance' });
201
- const workflow = await marrow.installTemplate('claims-triage');
202
- ```
203
-
204
- ## Active Intelligence — Marrow Intervenes Before Mistakes
205
-
206
- ### Auto-Warn on Orient
207
- When you call `orient({autoWarn: true})`, Marrow scans your recent decisions and warns you BEFORE you start a task that recently failed:
208
-
209
- ```typescript
210
- const result = await marrow.orient({
211
- task: "Fix authentication error",
212
- autoWarn: true
213
- });
214
-
215
- // Returns warnings like:
216
- // "⚠️ HIGH: This task type failed 4x with approach='retry-without-fix'.
217
- // Try approach='apply-patch-first' (89% success rate)"
218
- ```
219
-
220
- ### Loop Detection on Think
221
- When you call `think({checkLoop: true})`, Marrow detects if you're about to retry a failed approach and interrupts:
222
-
223
- ```typescript
224
- const decision = await marrow.think({
225
- action: "Retry auth with method='internal'",
226
- checkLoop: true
227
- });
228
-
229
- // Returns loop warnings:
230
- // "🚨 LOOP DETECTED: You're retrying a failed approach.
231
- // Previous failure: 'retry-without-fix' approach not supported.
232
- // Suggested: Use 'apply-patch-first' approach instead."
233
- ```
234
-
235
- ### Rate Limiting
236
- - `orient`: 30 requests/minute per account
237
- - `think`: 60 requests/minute per account
238
- - Automatic 429 responses when limit exceeded
239
-
240
- ### Enhanced PII Protection
241
- - Automatic stripping of emails, phone numbers, API keys from all responses
242
- - Applied to `recentLessons`, `warnings`, and `outcome` fields
243
- - Deep object stripping for complex data structures
244
-
245
- ---
246
-
247
- ## The Problem
248
-
249
- Without durable decision memory:
250
- - agents repeat bad calls
251
- - successful patterns get lost
252
- - work gets marked "done" without outcome context
253
- - external actions happen with no structured trail
254
- - every new session wastes time rediscovering what already failed
255
-
256
- A bigger context window doesn't solve this.
257
- You need a system that remembers:
258
- - what the agent was trying to do
259
- - what it actually did
260
- - whether it worked
261
- - what pattern that should teach the next attempt
262
-
263
- ---
264
-
265
- ## The Solution
266
-
267
- Marrow gives you a simple SDK for decision memory and loop discipline.
268
-
269
- With `@getmarrow/sdk`, your agent can:
270
- - **orient** at session start
271
- - **think** before meaningful action
272
- - **check** whether the loop is still open
273
- - **wrap** important actions so intent and outcome stay connected
274
- - **commit** the result back into memory
275
-
276
- That gives you a usable operating loop:
277
-
278
- ```text
279
- orient -> think -> act -> check -> commit
280
- ```
281
-
282
- Not just memory for memory's sake —
283
- memory that improves execution.
284
-
285
- The value compounds with use. Each decision your agent logs makes the hive smarter — failure rates drop, patterns emerge, and the next session starts with real intelligence instead of a blank slate.
9
+ `@getmarrow/sdk` gives your agent a memory that compounds. Log intent, pull back decision intelligence, commit outcomes — every session starts smarter.
286
10
 
287
11
  ---
288
12
 
@@ -292,174 +16,76 @@ The value compounds with use. Each decision your agent logs makes the hive smart
292
16
  npm install @getmarrow/sdk
293
17
  ```
294
18
 
295
- Get your API key at [getmarrow.ai](https://getmarrow.ai)
296
-
297
- ---
298
-
299
19
  ## Quick Start
300
20
 
301
21
  ```typescript
302
- import { createMarrowClient } from '@getmarrow/sdk';
303
-
304
- const marrow = createMarrowClient(process.env.MARROW_API_KEY!);
305
-
306
- await marrow.orient();
307
- await marrow.think({ action: 'deploy to production', type: 'deployment' });
308
- await deployToProduction();
309
- await marrow.commit({ success: true, outcome: 'Deployed v2.8.0 — 0 errors' });
310
- ```
311
-
312
- ---
313
-
314
- ## Zero-Ceremony Mode
315
-
316
- The simplest integration — one call handles everything:
317
-
318
- ```typescript
319
- import { marrowFromEnv } from '@getmarrow/sdk';
22
+ import { MarrowClient } from '@getmarrow/sdk';
320
23
 
321
- const marrow = marrowFromEnv(); // reads MARROW_API_KEY, defaults to auto mode
24
+ const marrow = new MarrowClient({ apiKey: 'mrw_...' });
322
25
 
323
- await marrow.run('deploy to production', async () => {
324
- await deployToProduction();
26
+ // Before a task get intelligence
27
+ const { decisionId, intelligence } = await marrow.think({
28
+ action: 'deploy new feature',
29
+ type: 'implementation'
325
30
  });
326
- // orient + think + commit fire automatically
327
- ```
328
-
329
- ---
330
-
331
- ## How It Works
31
+ // intelligence.warnings tasks that failed before
32
+ // intelligence.similar → what worked for other agents
332
33
 
333
- ### 1. Orient
334
- Start the session with context from prior decisions.
335
-
336
- ```typescript
337
- await marrow.orient();
34
+ // After a task — commit outcome
35
+ await marrow.commit({ success: true, outcome: 'deployed successfully' });
338
36
  ```
339
37
 
340
- This gives the agent a cleaner starting point instead of acting cold.
38
+ ## Core Methods
39
+
40
+ | Method | Description |
41
+ |--------|-------------|
42
+ | `orient()` | Session-start warnings — avoid known failures |
43
+ | `think()` | Log intent + get hive intelligence |
44
+ | `commit()` | Record outcome — closes the decision loop |
45
+ | `run()` | Zero-ceremony: orient → think → commit |
46
+ | `auto()` | Fire-and-forget background logging |
341
47
 
342
- ### 2. Think
343
- Log intent before meaningful work.
48
+ ### 🆕 v3.7.1 — Multi-API-Key Management
344
49
 
345
50
  ```typescript
346
- const decision = await marrow.think({
347
- action: 'Deploy auth refactor to staging',
348
- type: 'implementation',
349
- });
51
+ const key = await marrow.createApiKey({ name: 'Prod Agent', key_type: 'live' });
52
+ const keys = await marrow.listApiKeys();
53
+ await marrow.rotateApiKey(keyId);
54
+ await marrow.revokeApiKey(keyId);
55
+ const audit = await marrow.getKeyAudit({ limit: 20 });
350
56
  ```
351
57
 
352
- Now the work has a decision trail and Marrow can return relevant intelligence.
58
+ ### Key Management Methods
353
59
 
354
- ### 3. Act
355
- Do the actual work.
60
+ | Method | Description |
61
+ |--------|-------------|
62
+ | `createApiKey()` | Create scoped API keys |
63
+ | `listApiKeys()` | List all keys (masked) |
64
+ | `getApiKey()` | Key details + usage stats |
65
+ | `rotateApiKey()` | Atomically rotate a key |
66
+ | `revokeApiKey()` | Permanently revoke |
67
+ | `getKeyAudit()` | Paginated audit log |
356
68
 
357
- For low-friction usage, wrap the action directly:
69
+ ## Passive Mode Zero Code
358
70
 
359
71
  ```typescript
360
- await marrow.wrap(
361
- {
362
- action: 'Call deployment API',
363
- type: 'implementation',
364
- external: true,
365
- result: 'Staging deploy succeeded',
366
- },
367
- async () => deployToStaging()
368
- );
72
+ const wrappedAgent = marrow.autoWrap(myAgent);
73
+ await wrappedAgent.deploy(); // auto-logged!
369
74
  ```
370
75
 
371
- ### 4. Commit
372
- Close the loop with the outcome.
76
+ ## Operator Dashboard
373
77
 
374
78
  ```typescript
375
- await marrow.commit({
376
- success: true,
377
- outcome: 'Staging deploy succeeded, running smoke tests',
378
- });
79
+ const dashboard = await marrow.dashboard();
80
+ // { health, top_failures, workflows, saves, velocity, improvement }
379
81
  ```
380
82
 
381
- ---
382
-
383
- ## API Reference
384
-
385
- ### Core Methods
386
-
387
- #### `orient(taskType?)`
388
- Call at session start. Returns failure warnings from your history.
389
-
390
- #### `think(params)`
391
- Log intent before acting. Returns pattern intelligence and recommendations.
392
-
393
- #### `commit(params)`
394
- Log the outcome after acting. Closes the decision loop.
395
-
396
- #### `run(description, fn, options?)`
397
- Zero-ceremony wrapper. Handles orient → think → commit automatically.
398
-
399
- #### `wrap(meta, fn)`
400
- Wrap any action to auto-log intent and outcome.
401
-
402
- ### Memory Methods
403
-
404
- #### `listMemories(params?)`
405
- List memories with optional filters (status, query, limit, agentId).
406
-
407
- #### `getMemory(id)`
408
- Get a single memory by ID.
409
-
410
- #### `updateMemory(id, patch)`
411
- Update memory text, tags, or metadata.
412
-
413
- #### `deleteMemory(id, meta?)`
414
- Soft delete a memory.
415
-
416
- #### `markOutdated(id, meta?)`
417
- Mark a memory as outdated.
418
-
419
- #### `supersedeMemory(id, replacement)`
420
- Atomically replace a memory with a new version.
421
-
422
- #### `shareMemory(id, options)`
423
- Share a memory with specific agents.
424
-
425
- #### `exportMemories(options?)`
426
- Export memories to JSON or CSV.
427
-
428
- #### `importMemories(options)`
429
- Import memories with merge (dedup) or replace mode.
430
-
431
- #### `retrieveMemories(query, params?)`
432
- Full-text search with filters (from, to, tags, source, status, shared).
433
-
434
- ### Query Methods
435
-
436
- #### `ask(query)`
437
- Query the collective hive in plain English.
438
-
439
- #### `quickStatus()`
440
- Check health and memory status.
441
-
442
- #### `analytics()`
443
- Get agent health score and trends.
444
-
445
- ---
446
-
447
- ## Environment Variables
448
-
449
- | Variable | Required | Description |
450
- |----------|----------|-------------|
451
- | `MARROW_API_KEY` | Yes | Your API key from getmarrow.ai |
452
- | `MARROW_BASE_URL` | No | Custom API URL (default: `https://api.getmarrow.ai`). Must use HTTPS. |
453
- | `MARROW_SESSION_ID` | No | Session identifier for multi-agent setups |
454
-
455
- ---
456
-
457
- ## License
458
-
459
- MIT
460
-
461
- ---
83
+ ## Full Documentation
462
84
 
463
- ## Related Packages
85
+ 📖 **Complete API reference, metrics, features, and examples:**
86
+ **[https://getmarrow.ai/docs](https://getmarrow.ai/docs)**
464
87
 
465
- - **[@getmarrow/mcp](https://www.npmjs.com/package/@getmarrow/mcp)** — MCP server for Claude Code, Claude Desktop, and other MCP-compatible clients. Provides the same memory features through the Model Context Protocol. Includes one-command agent setup for automatic Marrow usage.
88
+ - [Auto-Logging](https://getmarrow.ai/docs/#auto-logging)
89
+ - [Metrics & Intelligence](https://getmarrow.ai/docs/#metrics-intelligence)
90
+ - [API Key Management](https://getmarrow.ai/docs/#api-key-management)
91
+ - [API Reference](https://getmarrow.ai/docs/#api-reference)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getmarrow/sdk",
3
- "version": "3.7.0",
3
+ "version": "3.7.2",
4
4
  "description": "Your go-to memory provider for all agents, for any AI model.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -44,4 +44,4 @@
44
44
  "@types/node": "^25.5.2",
45
45
  "typescript": "^5.3.3"
46
46
  }
47
- }
47
+ }