@getmarrow/sdk 3.7.3 → 3.7.5

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 +441 -66
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -5,8 +5,310 @@
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)
8
11
 
9
- `@getmarrow/sdk` gives your agent a memory that compounds. Log intent, pull back decision intelligence, commit outcomes — every session starts smarter.
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.7.0
46
+
47
+ ### Multi-API-Key Management
48
+
49
+ Manage API keys for your entire fleet of agents directly from your code:
50
+
51
+ - `createApiKey()` — Create named, scoped API keys (`live`/`test`)
52
+ - `listApiKeys()` — List all keys with masked display
53
+ - `getApiKey()` — Get key details and usage stats
54
+ - `revokeApiKey()` — Permanently revoke a key
55
+ - `rotateApiKey()` — Atomically rotate (revoke + create new)
56
+ - `getKeyAudit()` — Paginated audit log for key operations
57
+
58
+ ```typescript
59
+ const key = await marrow.createApiKey({
60
+ name: 'Production Agent',
61
+ key_type: 'live',
62
+ scopes: ['decisions:write', 'memories:read']
63
+ });
64
+ // { id, key: 'mrw_live_...', name, scopes, ... }
65
+ // ⚠️ Full key shown once — store it securely
66
+
67
+ const keys = await marrow.listApiKeys();
68
+ // [{ name, key: 'mrw_live_abc1...d4ef', key_type, status, ... }]
69
+ ```
70
+
71
+ ---
72
+
73
+ ### Previous: v3.6.0 — Agent-Narrated Marrow Contribution
74
+
75
+ 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.
76
+
77
+ - `think()` returns `marrow_contributed` describing intelligence Marrow surfaced (warnings consulted, hive patterns, similar decisions, workflow templates, loop detection, collective insight).
78
+ - `commit()` returns `marrow_contributed` with concrete signals (pattern reused, warning avoided, workflow step).
79
+ - `endSession()` returns `session_summary` aggregating Marrow's contribution across the session, with a one-line `narrative` for the agent to surface.
80
+
81
+ 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.
82
+
83
+ ```typescript
84
+ const result = await marrow.think({ action: 'deploy auth refactor', type: 'implementation' });
85
+ if (result.marrow_contributed?.has_signal) {
86
+ // Agent can mention: "Pulling 12 similar patterns from the hive..."
87
+ // Or: "Marrow flagged this approach failed 4× last week..."
88
+ }
89
+ ```
90
+
91
+ Counts and booleans only — no decision content, no PII echoed back.
92
+
93
+ ---
94
+
95
+ ## Agent-Narrated Milestones
96
+
97
+ `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.
98
+
99
+ Example:
100
+
101
+ ```typescript
102
+ const result = await marrow.commit({ success: true, outcome: 'Deploy succeeded' });
103
+ if (result.narrative) { console.log('Marrow:', result.narrative); }
104
+ ```
105
+
106
+ Narratives are pure aggregated metrics, no user data, no decision content. No heuristics.
107
+
108
+ ---
109
+
110
+ ## Passive Mode
111
+
112
+ Three patterns for auto-logging agent decisions — pick what fits your runtime.
113
+
114
+ ### Per-function: wrap(meta, fn)
115
+
116
+ ```typescript
117
+ await marrow.wrap(
118
+ { action: 'deploy release', type: 'process', external: true },
119
+ () => deploy()
120
+ );
121
+ ```
122
+
123
+ ### Per-object: autoWrap(client)
124
+
125
+ ```typescript
126
+ const wrappedAgent = marrow.autoWrap(myAgent, {
127
+ actionPrefix: 'claims-agent: ',
128
+ exclude: ['getConfig', 'toJSON'],
129
+ type: 'process',
130
+ });
131
+
132
+ await wrappedAgent.deploy();
133
+ ```
134
+
135
+ ### Per-fetch: wrapFetch(fetch)
136
+
137
+ ```typescript
138
+ const wrappedFetch = marrow.wrapFetch(fetch);
139
+ await wrappedFetch('https://api.example.com/deploy?token=secret', {
140
+ method: 'POST',
141
+ });
142
+ ```
143
+
144
+ 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.
145
+
146
+ ---
147
+
148
+ ## Operator Dashboard
149
+
150
+ One call returns everything an operator needs to see — account health, top failures, workflow status, recent activity, and Marrow's impact.
151
+
152
+ ```typescript
153
+ const dash = await marrow.dashboard();
154
+ // dash.health.overall_score, dash.top_failures, dash.impact.saves_this_week, ...
155
+ ```
156
+
157
+ ## Weekly Digest
158
+
159
+ Periodic summary with success rate trend vs previous period.
160
+
161
+ ```typescript
162
+ const digest = await marrow.digest('7d');
163
+ // digest.summary, digest.success_rate.direction, digest.saves.count, ...
164
+ ```
165
+
166
+ ## Session Management
167
+
168
+ ### Explicit Session End
169
+
170
+ Gracefully close a session and optionally auto-commit any open decision — prevents orphaned decisions.
171
+
172
+ ```typescript
173
+ await marrow.endSession(true); // true = auto-commit any open decision
174
+ ```
175
+
176
+ ## Auto-Workflow Detection
177
+
178
+ 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.
179
+
180
+ ```typescript
181
+ await marrow.acceptDetectedWorkflow(detectedId);
182
+ ```
183
+
184
+ ## Intelligence Fields in think() Response
185
+
186
+ - `onboarding_hint` — contextual tip for new accounts (first 50 decisions)
187
+ - `intelligence.collective` — anonymized insights aggregated from all Marrow accounts (k-anonymity ≥5)
188
+ - `intelligence.team_context` — recent decisions from other sessions in the same account
189
+
190
+ ---
191
+
192
+ ## Velocity Metrics
193
+
194
+ Dashboard and digest now include three measured velocity metrics so operators can see how agents get better over time:
195
+
196
+ - `attempts_per_success` — average number of decisions an agent makes before landing a success
197
+ - `time_to_success_seconds` — median seconds from `think()` to successful `commit()`
198
+ - `drift_rate` — % of decisions that didn't link to a known pattern (lower = more reuse, less rediscovery)
199
+
200
+ Each metric reports `{current, previous, delta_pct, direction}` so trends are visible at a glance.
201
+
202
+ ```typescript
203
+ const dash = await marrow.dashboard();
204
+ console.log(dash.velocity.attempts_per_success.direction); // 'improving'
205
+ console.log(dash.velocity.time_to_success_seconds.current); // 47
206
+ ```
207
+
208
+ All metrics are computed from real decision data, no estimates, no heuristics. Token-usage savings are on the enterprise roadmap.
209
+
210
+ ## Available Templates
211
+
212
+ 24 pre-built workflow templates across 8 industries. Browse via `listTemplates()` and install with `installTemplate(slug)`.
213
+
214
+ - **Insurance (4):** `claims-triage`, `fraud-review`, `underwriting-decision`, `complaint-escalation`
215
+ - **Healthcare (4):** `patient-triage`, `clinical-documentation`, `prior-authorization`, `coding-audit`
216
+ - **E-commerce (3):** `order-fulfillment`, `refund-approval`, `return-processing`
217
+ - **Legal (3):** `contract-review`, `case-triage`, `document-discovery`
218
+ - **SaaS (6):** `code-review-deploy`, `incident-response`, `feature-rollout`, `ticket-triage`, `escalation-flow`, `lead-qualify`
219
+ - **Fintech (2):** `etl-pipeline`, `approval-flow`
220
+ - **Media (1):** `content-publish`
221
+ - **Enterprise (1):** `change-management`
222
+
223
+ Full catalog with descriptions and step-by-step details: [getmarrow.ai/docs#template-marketplace](https://getmarrow.ai/docs/#template-marketplace)
224
+
225
+ ```typescript
226
+ const templates = await marrow.listTemplates({ industry: 'insurance' });
227
+ const workflow = await marrow.installTemplate('claims-triage');
228
+ ```
229
+
230
+ ## Active Intelligence — Marrow Intervenes Before Mistakes
231
+
232
+ ### Auto-Warn on Orient
233
+ When you call `orient({autoWarn: true})`, Marrow scans your recent decisions and warns you BEFORE you start a task that recently failed:
234
+
235
+ ```typescript
236
+ const result = await marrow.orient({
237
+ task: "Fix authentication error",
238
+ autoWarn: true
239
+ });
240
+
241
+ // Returns warnings like:
242
+ // "⚠️ HIGH: This task type failed 4x with approach='retry-without-fix'.
243
+ // Try approach='apply-patch-first' (89% success rate)"
244
+ ```
245
+
246
+ ### Loop Detection on Think
247
+ When you call `think({checkLoop: true})`, Marrow detects if you're about to retry a failed approach and interrupts:
248
+
249
+ ```typescript
250
+ const decision = await marrow.think({
251
+ action: "Retry auth with method='internal'",
252
+ checkLoop: true
253
+ });
254
+
255
+ // Returns loop warnings:
256
+ // "🚨 LOOP DETECTED: You're retrying a failed approach.
257
+ // Previous failure: 'retry-without-fix' approach not supported.
258
+ // Suggested: Use 'apply-patch-first' approach instead."
259
+ ```
260
+
261
+ ### Rate Limiting
262
+ - `orient`: 30 requests/minute per account
263
+ - `think`: 60 requests/minute per account
264
+ - Automatic 429 responses when limit exceeded
265
+
266
+ ### Enhanced PII Protection
267
+ - Automatic stripping of emails, phone numbers, API keys from all responses
268
+ - Applied to `recentLessons`, `warnings`, and `outcome` fields
269
+ - Deep object stripping for complex data structures
270
+
271
+ ---
272
+
273
+ ## The Problem
274
+
275
+ Without durable decision memory:
276
+ - agents repeat bad calls
277
+ - successful patterns get lost
278
+ - work gets marked "done" without outcome context
279
+ - external actions happen with no structured trail
280
+ - every new session wastes time rediscovering what already failed
281
+
282
+ A bigger context window doesn't solve this.
283
+ You need a system that remembers:
284
+ - what the agent was trying to do
285
+ - what it actually did
286
+ - whether it worked
287
+ - what pattern that should teach the next attempt
288
+
289
+ ---
290
+
291
+ ## The Solution
292
+
293
+ Marrow gives you a simple SDK for decision memory and loop discipline.
294
+
295
+ With `@getmarrow/sdk`, your agent can:
296
+ - **orient** at session start
297
+ - **think** before meaningful action
298
+ - **check** whether the loop is still open
299
+ - **wrap** important actions so intent and outcome stay connected
300
+ - **commit** the result back into memory
301
+
302
+ That gives you a usable operating loop:
303
+
304
+ ```text
305
+ orient -> think -> act -> check -> commit
306
+ ```
307
+
308
+ Not just memory for memory's sake —
309
+ memory that improves execution.
310
+
311
+ 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.
10
312
 
11
313
  ---
12
314
 
@@ -16,96 +318,169 @@
16
318
  npm install @getmarrow/sdk
17
319
  ```
18
320
 
321
+ Get your API key at [getmarrow.ai](https://getmarrow.ai)
322
+
323
+ ---
324
+
19
325
  ## Quick Start
20
326
 
21
327
  ```typescript
22
- import { MarrowClient } from '@getmarrow/sdk';
328
+ import { createMarrowClient } from '@getmarrow/sdk';
23
329
 
24
- const marrow = new MarrowClient({ apiKey: 'mrw_...' });
330
+ const marrow = createMarrowClient(process.env.MARROW_API_KEY!);
25
331
 
26
- // Before a task — get intelligence
27
- const { decisionId, intelligence } = await marrow.think({
28
- action: 'deploy new feature',
29
- type: 'implementation'
30
- });
31
- // intelligence.warnings → tasks that failed before
32
- // intelligence.similar → what worked for other agents
332
+ await marrow.orient();
333
+ await marrow.think({ action: 'deploy to production', type: 'deployment' });
334
+ await deployToProduction();
335
+ await marrow.commit({ success: true, outcome: 'Deployed v2.8.0 — 0 errors' });
336
+ ```
33
337
 
34
- // After a task — commit outcome
35
- await marrow.commit({ success: true, outcome: 'deployed successfully' });
338
+ ---
339
+
340
+ ## Zero-Ceremony Mode
341
+
342
+ The simplest integration — one call handles everything:
343
+
344
+ ```typescript
345
+ import { marrowFromEnv } from '@getmarrow/sdk';
346
+
347
+ const marrow = marrowFromEnv(); // reads MARROW_API_KEY, defaults to auto mode
348
+
349
+ await marrow.run('deploy to production', async () => {
350
+ await deployToProduction();
351
+ });
352
+ // orient + think + commit fire automatically
36
353
  ```
37
354
 
38
- ## Core Methods
355
+ ---
39
356
 
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 |
357
+ ## How It Works
47
358
 
48
- ### 🆕 v3.7.1 — Multi-API-Key Management
359
+ ### 1. Orient
360
+ Start the session with context from prior decisions.
49
361
 
50
362
  ```typescript
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 });
363
+ await marrow.orient();
364
+ ```
365
+
366
+ This gives the agent a cleaner starting point instead of acting cold.
367
+
368
+ ### 2. Think
369
+ Log intent before meaningful work.
370
+
371
+ ```typescript
372
+ const decision = await marrow.think({
373
+ action: 'Deploy auth refactor to staging',
374
+ type: 'implementation',
375
+ });
56
376
  ```
57
377
 
58
- ### Key Management Methods
378
+ Now the work has a decision trail and Marrow can return relevant intelligence.
59
379
 
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 |
380
+ ### 3. Act
381
+ Do the actual work.
68
382
 
69
- ## Passive Mode Zero Code
383
+ For low-friction usage, wrap the action directly:
70
384
 
71
385
  ```typescript
72
- const wrappedAgent = marrow.autoWrap(myAgent);
73
- await wrappedAgent.deploy(); // auto-logged!
386
+ await marrow.wrap(
387
+ {
388
+ action: 'Call deployment API',
389
+ type: 'implementation',
390
+ external: true,
391
+ result: 'Staging deploy succeeded',
392
+ },
393
+ async () => deployToStaging()
394
+ );
74
395
  ```
75
396
 
76
- ## Operator Dashboard
397
+ ### 4. Commit
398
+ Close the loop with the outcome.
77
399
 
78
400
  ```typescript
79
- const dashboard = await marrow.dashboard();
80
- // { health, top_failures, workflows, saves, velocity, improvement }
401
+ await marrow.commit({
402
+ success: true,
403
+ outcome: 'Staging deploy succeeded, running smoke tests',
404
+ });
81
405
  ```
82
406
 
83
- ## Full Feature Marketplace
407
+ ---
408
+
409
+ ## API Reference
410
+
411
+ ### Core Methods
412
+
413
+ #### `orient(taskType?)`
414
+ Call at session start. Returns failure warnings from your history.
415
+
416
+ #### `think(params)`
417
+ Log intent before acting. Returns pattern intelligence and recommendations.
418
+
419
+ #### `commit(params)`
420
+ Log the outcome after acting. Closes the decision loop.
84
421
 
85
- | Category | Features |
86
- |----------|----------|
87
- | 🔁 **Decision Loop** | orient → think → commit with auto-logging |
88
- | 🔐 **Multi-API-Keys** | Create, list, rotate, revoke scoped keys for fleets |
89
- | 🧠 **Persistent Memory** | List, search, update, share, export, import (14 tools) |
90
- | 📊 **Operator Dashboard** | Health, top failures, workflow status, velocity metrics |
91
- | 📈 **Velocity Tracking** | Attempts/success, time-to-success, drift rate, improvement delta |
92
- | 🌐 **Collective Intelligence** | Cross-account anonymous patterns, plain-English query |
93
- | 🔄 **Enforced Workflows** | 24 templates across 8 industries, step-by-step with audit |
94
- | ⚡ **Passive Mode** | autoWrap + wrapFetch — zero code auto-logging |
95
- | 🛡️ **PII Protection** | Auto-strip emails, phones, keys from all responses |
96
- | 🗄️ **Fleet Operations** | Agent registry, multi-user orgs, RBAC, SSE streaming |
97
- | 📋 **Session Management** | Open/close with summaries, pattern reuse tracking |
98
- | 🔗 **Causal Graphs** | Decision chaining — "What happened after this deploy?" |
99
- | 📬 **Auto-Email** | First-decision welcome, 7-day recap, milestone notifications |
100
- | 🔒 **Rate Limiting** | Per-endpoint, per-key, per-IP with tiered limits |
101
- | 📜 **Audit Trail** | Immutable key operation logs with IP and timestamp |
422
+ #### `run(description, fn, options?)`
423
+ Zero-ceremony wrapper. Handles orient → think → commit automatically.
102
424
 
103
- ## Full Documentation
425
+ #### `wrap(meta, fn)`
426
+ Wrap any action to auto-log intent and outcome.
427
+
428
+ **📖 Full API reference with request/response examples:**
429
+ **[getmarrow.ai/docs/#api-reference](https://getmarrow.ai/docs/#api-reference)**
430
+
431
+ ### Memory Methods
432
+
433
+ #### `listMemories(params?)`
434
+ List memories with optional filters (status, query, limit, agentId).
435
+
436
+ #### `getMemory(id)`
437
+ Get a single memory by ID.
438
+
439
+ #### `updateMemory(id, patch)`
440
+ Update memory text, tags, or metadata.
441
+
442
+ #### `deleteMemory(id, meta?)`
443
+ Soft delete a memory.
444
+
445
+ #### `markOutdated(id, meta?)`
446
+ Mark a memory as outdated.
447
+
448
+ #### `supersedeMemory(id, replacement)`
449
+ Atomically replace a memory with a new version.
450
+
451
+ #### `shareMemory(id, options)`
452
+ Share a memory with specific agents.
453
+
454
+ #### `exportMemories(options?)`
455
+ Export memories to JSON or CSV.
456
+
457
+ #### `importMemories(options)`
458
+ Import memories with merge (dedup) or replace mode.
459
+
460
+ #### `retrieveMemories(query, params?)`
461
+ Full-text search with filters.
462
+
463
+ **📖 All memory, query, and operator endpoints:**
464
+ **[getmarrow.ai/docs/#api-reference](https://getmarrow.ai/docs/#api-reference)**
465
+
466
+ ---
467
+
468
+ ## Environment Variables
469
+
470
+ | Variable | Required | Description |
471
+ |----------|----------|-------------|
472
+ | `MARROW_API_KEY` | Yes | Your API key from getmarrow.ai |
473
+ | `MARROW_BASE_URL` | No | Custom API URL (default: `https://api.getmarrow.ai`). Must use HTTPS. |
474
+ | `MARROW_SESSION_ID` | No | Session identifier for multi-agent setups |
475
+
476
+ ---
477
+
478
+ ## License
479
+
480
+ MIT
481
+
482
+ ---
104
483
 
105
- 📖 **Complete API reference, metrics, features, and examples:**
106
- **[https://getmarrow.ai/docs](https://getmarrow.ai/docs)**
484
+ ## Related Packages
107
485
 
108
- - [Auto-Logging](https://getmarrow.ai/docs/#auto-logging)
109
- - [Metrics & Intelligence](https://getmarrow.ai/docs/#metrics-intelligence)
110
- - [API Key Management](https://getmarrow.ai/docs/#api-key-management)
111
- - [API Reference](https://getmarrow.ai/docs/#api-reference)
486
+ - **[@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getmarrow/sdk",
3
- "version": "3.7.3",
3
+ "version": "3.7.5",
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",