Skip to content

Commit 3e7f8b6

Browse files
author
StackMemory Bot (CLI)
committed
docs(sdk): add README, .npmignore, repo metadata for npm publish
SDK ready for npm publish at 17.9 kB.
1 parent 53c3146 commit 3e7f8b6

3 files changed

Lines changed: 135 additions & 1 deletion

File tree

packages/sdk/.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src/
2+
**/__tests__/
3+
**/*.test.ts
4+
tsconfig.json
5+
.tsbuildinfo
6+
node_modules/

packages/sdk/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# @stackmemoryai/sdk
2+
3+
TypeScript SDK for [StackMemory](https://github.com/stackmemoryai/stackmemory) — content cache, skill packs, and provenance tracking for AI agent workflows.
4+
5+
## Install
6+
7+
```bash
8+
npm install @stackmemoryai/sdk
9+
```
10+
11+
## Quick Start
12+
13+
```ts
14+
import { StackMemory } from '@stackmemoryai/sdk';
15+
16+
const sm = new StackMemory();
17+
18+
// Content-hash token cache — dedup LLM context
19+
sm.cache.put('function add(a, b) { return a + b; }', 'file:math.ts');
20+
const result = sm.cache.lookup('function add(a, b) { return a + b; }');
21+
console.log(result.hit); // true
22+
console.log(result.tokensSaved); // ~11
23+
24+
// Skill packs — versioned agent bundles
25+
sm.packs.install({
26+
manifest: {
27+
name: 'coding/typescript-react',
28+
version: '1.0.0',
29+
description: 'TypeScript + React patterns',
30+
author: 'stackmemory',
31+
license: 'MIT',
32+
},
33+
instructions: 'Use functional components with hooks...',
34+
});
35+
const packs = sm.packs.list();
36+
const found = sm.packs.search('typescript');
37+
38+
// Provenance — trace events with source lineage
39+
sm.provenance.record({
40+
timestamp: new Date().toISOString(),
41+
traceId: 'trace-001',
42+
sessionId: 'sess-001',
43+
tenantId: 'team-alpha',
44+
actor: { host: 'claude-code', agent: 'sdk', user: 'dev' },
45+
operation: 'query',
46+
inputs: { q: 'auth middleware' },
47+
outputs: { result: '3 files found' },
48+
tokensIn: 150,
49+
tokensOut: 80,
50+
costUsd: 0.002,
51+
provenance: {
52+
sources: [{ system: 'github', externalId: 'PR-42', fetchedAt: new Date().toISOString() }],
53+
derivation: [],
54+
confidence: 0.85,
55+
},
56+
});
57+
58+
// Decision confidence scoring
59+
const score = sm.scoreConfidence('we decided to use SQLite for local storage');
60+
console.log(score); // { confidence: 0.3, classification: 'discard', signals: { triggerPhrases: ['we decided'] } }
61+
62+
sm.close();
63+
```
64+
65+
## API
66+
67+
### `new StackMemory(config?)`
68+
69+
| Option | Type | Default | Description |
70+
|--------|------|---------|-------------|
71+
| `dataDir` | `string` | `~/.stackmemory` | Directory for SQLite databases |
72+
| `logLevel` | `'debug' \| 'info' \| 'warn' \| 'error' \| 'silent'` | `'warn'` | Log verbosity |
73+
74+
### `sm.cache` — Content Cache
75+
76+
| Method | Description |
77+
|--------|-------------|
78+
| `put(content, source?, metadata?)` | Cache content, returns `CacheEntry` |
79+
| `lookup(content, source?)` | Check cache, returns `CacheLookupResult` with `hit` and `tokensSaved` |
80+
| `getStats()` | Aggregate stats: entries, tokens cached/saved, hit rate, top sources |
81+
| `evict(olderThan?)` | Remove old entries, returns count removed |
82+
| `clear()` | Remove all entries |
83+
84+
### `sm.packs` — Skill Pack Registry
85+
86+
| Method | Description |
87+
|--------|-------------|
88+
| `install(pack, source?)` | Install a skill pack (upserts on name match) |
89+
| `uninstall(name)` | Remove a pack |
90+
| `get(name)` | Get pack by name (e.g. `"coding/typescript-react"`) |
91+
| `list(opts?)` | List packs, optionally filter by `namespace` or `runtime` |
92+
| `search(query)` | Full-text search across name, description, instructions |
93+
| `getByTool(toolName)` | Find the pack that provides a specific MCP tool |
94+
95+
### `sm.provenance` — Provenance Store
96+
97+
| Method | Description |
98+
|--------|-------------|
99+
| `record(event)` | Persist a `TraceEvent` |
100+
| `get(traceId)` | Retrieve by trace ID |
101+
| `query(opts?)` | Filter by `sessionId`, `tenantId`, `operation`, `since`, `limit` |
102+
| `supersede(traceId, supersededBy)` | Mark a trace as superseded |
103+
| `getLineage(traceId)` | Follow `parentTraceId` chain to root |
104+
| `getStats(tenantId?)` | Aggregate: total events, tokens, cost, avg confidence |
105+
106+
### `sm.scoreConfidence(text, context?)`
107+
108+
Score text for decision confidence. Returns `{ confidence, signals, classification }`.
109+
110+
### Standalone exports
111+
112+
```ts
113+
import { scoreConfidence, estimateTokens, hashContent } from '@stackmemoryai/sdk';
114+
import { parsePackYaml, loadPackFromDir } from '@stackmemoryai/sdk';
115+
```
116+
117+
## License
118+
119+
MIT

packages/sdk/package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,14 @@
4141
"ai",
4242
"llm"
4343
],
44-
"license": "MIT"
44+
"license": "MIT",
45+
"repository": {
46+
"type": "git",
47+
"url": "https://github.com/stackmemoryai/stackmemory.git",
48+
"directory": "packages/sdk"
49+
},
50+
"homepage": "https://github.com/stackmemoryai/stackmemory/tree/main/packages/sdk#readme",
51+
"engines": {
52+
"node": ">=20.0.0"
53+
}
4554
}

0 commit comments

Comments
 (0)