@getmarrow/sdk 3.7.1 → 3.7.3

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 +66 -446
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -5,310 +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.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.
9
+ `@getmarrow/sdk` gives your agent a memory that compounds. Log intent, pull back decision intelligence, commit outcomes — every session starts smarter.
312
10
 
313
11
  ---
314
12
 
@@ -318,174 +16,96 @@ The value compounds with use. Each decision your agent logs makes the hive smart
318
16
  npm install @getmarrow/sdk
319
17
  ```
320
18
 
321
- Get your API key at [getmarrow.ai](https://getmarrow.ai)
322
-
323
- ---
324
-
325
19
  ## Quick Start
326
20
 
327
21
  ```typescript
328
- import { createMarrowClient } from '@getmarrow/sdk';
329
-
330
- const marrow = createMarrowClient(process.env.MARROW_API_KEY!);
22
+ import { MarrowClient } from '@getmarrow/sdk';
331
23
 
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
- ```
337
-
338
- ---
24
+ const marrow = new MarrowClient({ apiKey: 'mrw_...' });
339
25
 
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();
26
+ // Before a task — get intelligence
27
+ const { decisionId, intelligence } = await marrow.think({
28
+ action: 'deploy new feature',
29
+ type: 'implementation'
351
30
  });
352
- // orient + think + commit fire automatically
353
- ```
31
+ // intelligence.warnings tasks that failed before
32
+ // intelligence.similar → what worked for other agents
354
33
 
355
- ---
356
-
357
- ## How It Works
358
-
359
- ### 1. Orient
360
- Start the session with context from prior decisions.
361
-
362
- ```typescript
363
- await marrow.orient();
34
+ // After a task — commit outcome
35
+ await marrow.commit({ success: true, outcome: 'deployed successfully' });
364
36
  ```
365
37
 
366
- 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 |
367
47
 
368
- ### 2. Think
369
- Log intent before meaningful work.
48
+ ### 🆕 v3.7.1 — Multi-API-Key Management
370
49
 
371
50
  ```typescript
372
- const decision = await marrow.think({
373
- action: 'Deploy auth refactor to staging',
374
- type: 'implementation',
375
- });
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 });
376
56
  ```
377
57
 
378
- Now the work has a decision trail and Marrow can return relevant intelligence.
58
+ ### Key Management Methods
379
59
 
380
- ### 3. Act
381
- 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 |
382
68
 
383
- For low-friction usage, wrap the action directly:
69
+ ## Passive Mode Zero Code
384
70
 
385
71
  ```typescript
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
- );
72
+ const wrappedAgent = marrow.autoWrap(myAgent);
73
+ await wrappedAgent.deploy(); // auto-logged!
395
74
  ```
396
75
 
397
- ### 4. Commit
398
- Close the loop with the outcome.
76
+ ## Operator Dashboard
399
77
 
400
78
  ```typescript
401
- await marrow.commit({
402
- success: true,
403
- outcome: 'Staging deploy succeeded, running smoke tests',
404
- });
79
+ const dashboard = await marrow.dashboard();
80
+ // { health, top_failures, workflows, saves, velocity, improvement }
405
81
  ```
406
82
 
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.
421
-
422
- #### `run(description, fn, options?)`
423
- Zero-ceremony wrapper. Handles orient → think → commit automatically.
424
-
425
- #### `wrap(meta, fn)`
426
- Wrap any action to auto-log intent and outcome.
83
+ ## Full Feature Marketplace
427
84
 
428
- ### Memory Methods
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 |
429
102
 
430
- #### `listMemories(params?)`
431
- List memories with optional filters (status, query, limit, agentId).
432
-
433
- #### `getMemory(id)`
434
- Get a single memory by ID.
435
-
436
- #### `updateMemory(id, patch)`
437
- Update memory text, tags, or metadata.
438
-
439
- #### `deleteMemory(id, meta?)`
440
- Soft delete a memory.
441
-
442
- #### `markOutdated(id, meta?)`
443
- Mark a memory as outdated.
444
-
445
- #### `supersedeMemory(id, replacement)`
446
- Atomically replace a memory with a new version.
447
-
448
- #### `shareMemory(id, options)`
449
- Share a memory with specific agents.
450
-
451
- #### `exportMemories(options?)`
452
- Export memories to JSON or CSV.
453
-
454
- #### `importMemories(options)`
455
- Import memories with merge (dedup) or replace mode.
456
-
457
- #### `retrieveMemories(query, params?)`
458
- Full-text search with filters (from, to, tags, source, status, shared).
459
-
460
- ### Query Methods
461
-
462
- #### `ask(query)`
463
- Query the collective hive in plain English.
464
-
465
- #### `quickStatus()`
466
- Check health and memory status.
467
-
468
- #### `analytics()`
469
- Get agent health score and trends.
470
-
471
- ---
472
-
473
- ## Environment Variables
474
-
475
- | Variable | Required | Description |
476
- |----------|----------|-------------|
477
- | `MARROW_API_KEY` | Yes | Your API key from getmarrow.ai |
478
- | `MARROW_BASE_URL` | No | Custom API URL (default: `https://api.getmarrow.ai`). Must use HTTPS. |
479
- | `MARROW_SESSION_ID` | No | Session identifier for multi-agent setups |
480
-
481
- ---
482
-
483
- ## License
484
-
485
- MIT
486
-
487
- ---
103
+ ## Full Documentation
488
104
 
489
- ## Related Packages
105
+ 📖 **Complete API reference, metrics, features, and examples:**
106
+ **[https://getmarrow.ai/docs](https://getmarrow.ai/docs)**
490
107
 
491
- - **[@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.
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getmarrow/sdk",
3
- "version": "3.7.1",
3
+ "version": "3.7.3",
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",