agent-working-memory 0.8.6 → 0.8.8
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 +46 -2
- package/dist/adapters/common.d.ts.map +1 -1
- package/dist/adapters/common.js +13 -0
- package/dist/adapters/common.js.map +1 -1
- package/dist/api/routes.js +8 -8
- package/dist/cli/migrate.js +29 -29
- package/dist/cli.js +105 -105
- package/dist/coordination/circuit-breaker.js +23 -23
- package/dist/core/lite-compress.d.ts +26 -0
- package/dist/core/lite-compress.d.ts.map +1 -0
- package/dist/core/lite-compress.js +105 -0
- package/dist/core/lite-compress.js.map +1 -0
- package/dist/mcp.d.ts +5 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +138 -84
- package/dist/mcp.js.map +1 -1
- package/dist/storage/pglite-schema.js +143 -143
- package/dist/storage/pglite.js +138 -138
- package/package.json +4 -3
- package/src/adapters/common.ts +13 -0
- package/src/api/index.ts +3 -3
- package/src/api/routes.ts +1 -1
- package/src/cli/migrate.ts +307 -307
- package/src/cli.ts +1 -1
- package/src/coordination/circuit-breaker.ts +83 -83
- package/src/coordination/failure-modes.ts +50 -50
- package/src/core/decay.ts +63 -63
- package/src/core/embeddings.ts +110 -110
- package/src/core/index.ts +5 -5
- package/src/core/lite-compress.ts +129 -0
- package/src/core/logger.ts +36 -36
- package/src/core/ml-worker-entry.ts +194 -194
- package/src/core/ml-worker.ts +281 -281
- package/src/core/query-expander.ts +122 -122
- package/src/core/reranker.ts +119 -119
- package/src/engine/confidence.ts +120 -120
- package/src/engine/connections.ts +162 -162
- package/src/engine/consolidation-scheduler.ts +242 -242
- package/src/engine/eval.ts +102 -102
- package/src/engine/eviction.ts +101 -101
- package/src/engine/index.ts +8 -8
- package/src/engine/retraction.ts +366 -366
- package/src/engine/staging.ts +74 -74
- package/src/mcp.ts +70 -4
- package/src/storage/factory.ts +147 -147
- package/src/storage/index.ts +3 -3
- package/src/storage/pglite-schema.ts +166 -166
- package/src/storage/pglite.ts +1363 -1363
- package/src/storage/store.ts +80 -80
- package/src/types/agent.ts +67 -67
- package/src/types/checkpoint.ts +46 -46
- package/src/types/eval.ts +100 -100
- package/src/types/index.ts +6 -6
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ npm install -g agent-working-memory
|
|
|
29
29
|
awm setup --global
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
Restart Claude Code. That's it —
|
|
32
|
+
Restart Claude Code. That's it — 16 memory tools appear automatically.
|
|
33
33
|
|
|
34
34
|
### Upgrading
|
|
35
35
|
|
|
@@ -142,7 +142,7 @@ All evals are reproducible. See [Testing & Evaluation](#testing--evaluation).
|
|
|
142
142
|
|
|
143
143
|
## Features
|
|
144
144
|
|
|
145
|
-
### Memory Tools (
|
|
145
|
+
### Memory Tools (16)
|
|
146
146
|
|
|
147
147
|
| Tool | Purpose |
|
|
148
148
|
|------|---------|
|
|
@@ -160,6 +160,8 @@ All evals are reproducible. See [Testing & Evaluation](#testing--evaluation).
|
|
|
160
160
|
| `memory_task_next` | Get the highest-priority actionable task |
|
|
161
161
|
| `memory_task_begin` | Start a task — auto-checkpoints and recalls context |
|
|
162
162
|
| `memory_task_end` | End a task — writes summary and checkpoints |
|
|
163
|
+
| `compress_output` | Encode a structured tool output as TOON — ~50-65% fewer tokens, lossless, output-only |
|
|
164
|
+
| `retrieve_original` | Get the verbatim source back for a `compress_output` ref |
|
|
163
165
|
|
|
164
166
|
### Separate Memory Pools
|
|
165
167
|
|
|
@@ -657,6 +659,47 @@ callers keep working without modification. Full validation at the milestone:
|
|
|
657
659
|
|
|
658
660
|
See [CHANGELOG.md](CHANGELOG.md) for full details.
|
|
659
661
|
|
|
662
|
+
## Integrations
|
|
663
|
+
|
|
664
|
+
AWM is a standard MCP server, so it plugs into any MCP-capable agent host with
|
|
665
|
+
**no adapter code** — the same server Claude Code uses. Point two hosts at the
|
|
666
|
+
same `AWM_DB_PATH` (with a shared `AWM_AGENT_ID`/`AWM_WORKSPACE`) and they share
|
|
667
|
+
one cognitive memory.
|
|
668
|
+
|
|
669
|
+
### Hermes Agent (Nous Research)
|
|
670
|
+
|
|
671
|
+
1. Make AWM available where Hermes runs (e.g. a derived Docker image — the
|
|
672
|
+
Hermes image already bundles Node):
|
|
673
|
+
|
|
674
|
+
```dockerfile
|
|
675
|
+
FROM hermes-agent:local
|
|
676
|
+
USER root
|
|
677
|
+
RUN npm install -g agent-working-memory@latest
|
|
678
|
+
ENV HF_HOME=/opt/data/.cache/huggingface
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
2. Register it in `~/.hermes/config.yaml`:
|
|
682
|
+
|
|
683
|
+
```yaml
|
|
684
|
+
mcp_servers:
|
|
685
|
+
awm:
|
|
686
|
+
command: node
|
|
687
|
+
args: ["/usr/local/lib/node_modules/agent-working-memory/dist/mcp.js"]
|
|
688
|
+
env:
|
|
689
|
+
AWM_AGENT_ID: hermes
|
|
690
|
+
AWM_DB_PATH: /opt/data/awm/hermes.db # on a persistent volume
|
|
691
|
+
HF_HOME: /opt/data/.cache/huggingface
|
|
692
|
+
timeout: 600 # first call downloads the embedder
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
3. AWM's tools appear to the agent as `mcp_awm_memory_write`,
|
|
696
|
+
`mcp_awm_memory_recall`, etc. Works with any Hermes model provider
|
|
697
|
+
(verified on Anthropic and Azure `gpt-5-4-mini`).
|
|
698
|
+
|
|
699
|
+
Full recipe — model-provider examples, the Azure GPT-5.x `/openai/v1` note, and
|
|
700
|
+
gotchas (incl. the Windows CRLF/s6 clone fix) — is in
|
|
701
|
+
[docs/integrations/hermes.md](docs/integrations/hermes.md).
|
|
702
|
+
|
|
660
703
|
## Project Status
|
|
661
704
|
|
|
662
705
|
AWM is in active development (v0.8.5). The core memory pipeline, consolidation
|
|
@@ -665,6 +708,7 @@ daily in production coding workflows.
|
|
|
665
708
|
|
|
666
709
|
- Core retrieval and consolidation: **stable**
|
|
667
710
|
- MCP tools and Claude Code integration: **stable**
|
|
711
|
+
- Other MCP hosts (e.g. [Hermes Agent](docs/integrations/hermes.md)): **supported** — AWM drops in as an MCP memory server with no adapter code
|
|
668
712
|
- Multi-agent coordination: **stable** (v0.8.1 hardening)
|
|
669
713
|
- Task management: **stable**
|
|
670
714
|
- Hook sidecar and auto-checkpoint: **stable**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/adapters/common.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK/C,gEAAgE;AAChE,wBAAgB,kBAAkB,IAAI,MAAM,CAG3C;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAOnF;AAED,8CAA8C;AAC9C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAUxD;AAED,8DAA8D;AAC9D,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,OAAO,GACjB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,GAAG;IACpD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAkBA;AAED,uDAAuD;AACvD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,YAAY,CA6Bf;AAED,sBAAsB;AACtB,wBAAgB,OAAO,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Y,CA6Bf;AAED,sBAAsB;AACtB,wBAAgB,OAAO,IAAI,MAAM,CAEhC;AAID;;;GAGG;AACH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GACrD,MAAM,CA8CR;AAED,eAAO,MAAM,uBAAuB,QA8SvB,CAAC"}
|
package/dist/adapters/common.js
CHANGED
|
@@ -395,6 +395,19 @@ memory_write(
|
|
|
395
395
|
- AWM is shared across all agents in real time. When any agent writes or supersedes a
|
|
396
396
|
memory, every other agent can recall it immediately.
|
|
397
397
|
|
|
398
|
+
### Output compression (token efficiency, output-only)
|
|
399
|
+
When a tool returns a LARGE STRUCTURED result you need to keep in context — a JSON
|
|
400
|
+
array of records, query rows, a log dump, an API response — pass it through
|
|
401
|
+
\`compress_output\` first. It re-encodes the data as TOON (a compact, lossless,
|
|
402
|
+
schema-aware tabular form of JSON), cutting ~50-65% of the tokens at no
|
|
403
|
+
comprehension cost. This is output-only: it never changes the data or your memories.
|
|
404
|
+
- Use it on big STRUCTURED outputs, not on prose. Prose is returned unchanged —
|
|
405
|
+
for trimming memory prose, use recall \`granularity: 'compact'\` instead.
|
|
406
|
+
- It returns a \`ref\`; call \`retrieve_original(ref)\` if you later need the exact
|
|
407
|
+
verbatim source (e.g. to hand it to another tool unchanged).
|
|
408
|
+
- Don't bother for small outputs — it only compresses when the saving is worthwhile
|
|
409
|
+
and falls back to plain JSON if TOON wouldn't reproduce the data exactly.
|
|
410
|
+
|
|
398
411
|
### Backend (SQLite vs PGlite, 0.8.x)
|
|
399
412
|
AWM ships two storage backends. The installer picks SQLite by default; both
|
|
400
413
|
are functionally equivalent for cognitive workloads, but differ in operational
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["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AAK,uDAAuD,CAAC;AACzE,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8StC,CAAC,SAAS,EAAE,CAAC"}
|
package/dist/api/routes.js
CHANGED
|
@@ -655,9 +655,9 @@ export function registerRoutes(app, deps) {
|
|
|
655
655
|
return reply.code(501).send({ error: 'export endpoint requires the SQLite backend' });
|
|
656
656
|
}
|
|
657
657
|
const db = store.getDb();
|
|
658
|
-
let engramSql = `SELECT id, agent_id, concept, content, confidence, salience, access_count,
|
|
659
|
-
last_accessed, created_at, salience_features, reason_codes, stage, ttl,
|
|
660
|
-
retracted, retracted_by, retracted_at, tags
|
|
658
|
+
let engramSql = `SELECT id, agent_id, concept, content, confidence, salience, access_count,
|
|
659
|
+
last_accessed, created_at, salience_features, reason_codes, stage, ttl,
|
|
660
|
+
retracted, retracted_by, retracted_at, tags
|
|
661
661
|
FROM engrams`;
|
|
662
662
|
const conditions = [];
|
|
663
663
|
const params = [];
|
|
@@ -675,7 +675,7 @@ export function registerRoutes(app, deps) {
|
|
|
675
675
|
engramSql += ' ORDER BY created_at ASC';
|
|
676
676
|
const engrams = db.prepare(engramSql).all(...params);
|
|
677
677
|
const engramIds = new Set(engrams.map(e => e.id));
|
|
678
|
-
const allAssocs = db.prepare(`SELECT id, from_engram_id, to_engram_id, weight, confidence, type, activation_count, created_at, last_activated
|
|
678
|
+
const allAssocs = db.prepare(`SELECT id, from_engram_id, to_engram_id, weight, confidence, type, activation_count, created_at, last_activated
|
|
679
679
|
FROM associations`).all();
|
|
680
680
|
const associations = allAssocs.filter(a => engramIds.has(a.from_engram_id) && engramIds.has(a.to_engram_id));
|
|
681
681
|
return reply.send({
|
|
@@ -694,15 +694,15 @@ export function registerRoutes(app, deps) {
|
|
|
694
694
|
const base = {
|
|
695
695
|
status: 'ok',
|
|
696
696
|
timestamp: new Date().toISOString(),
|
|
697
|
-
version: '0.8.
|
|
697
|
+
version: '0.8.8',
|
|
698
698
|
coordination: coordEnabled,
|
|
699
699
|
};
|
|
700
700
|
if (coordEnabled && typeof deps.store.getDb === 'function') {
|
|
701
701
|
try {
|
|
702
702
|
const db = deps.store.getDb();
|
|
703
|
-
const stats = db.prepare(`SELECT
|
|
704
|
-
(SELECT COUNT(*) FROM coord_agents WHERE status != 'dead') AS agents_alive,
|
|
705
|
-
(SELECT COUNT(*) FROM coord_assignments WHERE status = 'pending') AS pending_tasks,
|
|
703
|
+
const stats = db.prepare(`SELECT
|
|
704
|
+
(SELECT COUNT(*) FROM coord_agents WHERE status != 'dead') AS agents_alive,
|
|
705
|
+
(SELECT COUNT(*) FROM coord_assignments WHERE status = 'pending') AS pending_tasks,
|
|
706
706
|
(SELECT COUNT(*) FROM coord_locks) AS active_locks`).get();
|
|
707
707
|
Object.assign(base, stats);
|
|
708
708
|
}
|
package/dist/cli/migrate.js
CHANGED
|
@@ -72,17 +72,17 @@ export async function migrate(opts) {
|
|
|
72
72
|
const embedding = r.embedding
|
|
73
73
|
? vectorLiteral(Array.from(bufferToFloat32Array(r.embedding)))
|
|
74
74
|
: null;
|
|
75
|
-
await dst.query(`INSERT INTO engrams (
|
|
76
|
-
id, agent_id, concept, content, embedding, embedding_model,
|
|
77
|
-
confidence, salience, access_count, last_accessed, created_at,
|
|
78
|
-
salience_features, reason_codes, stage, ttl,
|
|
79
|
-
retracted, retracted_by, retracted_at, tags, memory_type,
|
|
80
|
-
memory_class, superseded_by, supersedes, episode_id,
|
|
81
|
-
task_status, task_priority, blocked_by, sequence, references_json
|
|
82
|
-
) VALUES (
|
|
83
|
-
$1, $2, $3, $4, $5::vector, $6, $7, $8, $9, $10, $11,
|
|
84
|
-
$12, $13, $14, $15, $16, $17, $18, $19, $20,
|
|
85
|
-
$21, $22, $23, $24, $25, $26, $27, $28, $29
|
|
75
|
+
await dst.query(`INSERT INTO engrams (
|
|
76
|
+
id, agent_id, concept, content, embedding, embedding_model,
|
|
77
|
+
confidence, salience, access_count, last_accessed, created_at,
|
|
78
|
+
salience_features, reason_codes, stage, ttl,
|
|
79
|
+
retracted, retracted_by, retracted_at, tags, memory_type,
|
|
80
|
+
memory_class, superseded_by, supersedes, episode_id,
|
|
81
|
+
task_status, task_priority, blocked_by, sequence, references_json
|
|
82
|
+
) VALUES (
|
|
83
|
+
$1, $2, $3, $4, $5::vector, $6, $7, $8, $9, $10, $11,
|
|
84
|
+
$12, $13, $14, $15, $16, $17, $18, $19, $20,
|
|
85
|
+
$21, $22, $23, $24, $25, $26, $27, $28, $29
|
|
86
86
|
)`, [
|
|
87
87
|
r.id, r.agent_id, r.concept, r.content, embedding, r.embedding_model,
|
|
88
88
|
r.confidence, r.salience, r.access_count, r.last_accessed, r.created_at,
|
|
@@ -112,9 +112,9 @@ export async function migrate(opts) {
|
|
|
112
112
|
for (let i = 0; i < assocRows.length; i += batchSize) {
|
|
113
113
|
const batch = assocRows.slice(i, i + batchSize);
|
|
114
114
|
for (const r of batch) {
|
|
115
|
-
await dst.query(`INSERT INTO associations (
|
|
116
|
-
id, from_engram_id, to_engram_id, weight, confidence, type,
|
|
117
|
-
activation_count, created_at, last_activated
|
|
115
|
+
await dst.query(`INSERT INTO associations (
|
|
116
|
+
id, from_engram_id, to_engram_id, weight, confidence, type,
|
|
117
|
+
activation_count, created_at, last_activated
|
|
118
118
|
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)`, [
|
|
119
119
|
r.id, r.from_engram_id, r.to_engram_id, r.weight, r.confidence,
|
|
120
120
|
r.type ?? 'hebbian', r.activation_count ?? 0,
|
|
@@ -133,7 +133,7 @@ export async function migrate(opts) {
|
|
|
133
133
|
console.log(`agents: ${agentRows.length} rows`);
|
|
134
134
|
if (dst && agentRows.length > 0) {
|
|
135
135
|
for (const r of agentRows) {
|
|
136
|
-
await dst.query(`INSERT INTO agents (id, name, created_at, config) VALUES ($1,$2,$3,$4)
|
|
136
|
+
await dst.query(`INSERT INTO agents (id, name, created_at, config) VALUES ($1,$2,$3,$4)
|
|
137
137
|
ON CONFLICT (id) DO NOTHING`, [r.id, r.name, r.created_at, r.config ?? '{}']);
|
|
138
138
|
stats.agents++;
|
|
139
139
|
}
|
|
@@ -148,8 +148,8 @@ export async function migrate(opts) {
|
|
|
148
148
|
if (dst && aeRows.length > 0) {
|
|
149
149
|
for (let i = 0; i < aeRows.length; i += batchSize) {
|
|
150
150
|
for (const r of aeRows.slice(i, i + batchSize)) {
|
|
151
|
-
await dst.query(`INSERT INTO activation_events
|
|
152
|
-
(id, agent_id, timestamp, context, results_returned, top_score, latency_ms, engram_ids)
|
|
151
|
+
await dst.query(`INSERT INTO activation_events
|
|
152
|
+
(id, agent_id, timestamp, context, results_returned, top_score, latency_ms, engram_ids)
|
|
153
153
|
VALUES ($1,$2,$3,$4,$5,$6,$7,$8)`, [r.id, r.agent_id, r.timestamp, r.context, r.results_returned,
|
|
154
154
|
r.top_score, r.latency_ms, r.engram_ids ?? '[]']);
|
|
155
155
|
stats.activationEvents++;
|
|
@@ -165,7 +165,7 @@ export async function migrate(opts) {
|
|
|
165
165
|
console.log(`staging_events: ${seRows.length} rows`);
|
|
166
166
|
if (dst && seRows.length > 0) {
|
|
167
167
|
for (const r of seRows) {
|
|
168
|
-
await dst.query(`INSERT INTO staging_events (engram_id, agent_id, action, resonance_score, timestamp, age_ms)
|
|
168
|
+
await dst.query(`INSERT INTO staging_events (engram_id, agent_id, action, resonance_score, timestamp, age_ms)
|
|
169
169
|
VALUES ($1,$2,$3,$4,$5,$6)`, [r.engram_id, r.agent_id, r.action, r.resonance_score, r.timestamp, r.age_ms]);
|
|
170
170
|
stats.stagingEvents++;
|
|
171
171
|
}
|
|
@@ -179,8 +179,8 @@ export async function migrate(opts) {
|
|
|
179
179
|
console.log(`retrieval_feedback: ${rfRows.length} rows`);
|
|
180
180
|
if (dst && rfRows.length > 0) {
|
|
181
181
|
for (const r of rfRows) {
|
|
182
|
-
await dst.query(`INSERT INTO retrieval_feedback
|
|
183
|
-
(id, activation_event_id, engram_id, useful, context, timestamp)
|
|
182
|
+
await dst.query(`INSERT INTO retrieval_feedback
|
|
183
|
+
(id, activation_event_id, engram_id, useful, context, timestamp)
|
|
184
184
|
VALUES ($1,$2,$3,$4,$5,$6)`, [r.id, r.activation_event_id, r.engram_id, intToBool(r.useful), r.context, r.timestamp]);
|
|
185
185
|
stats.retrievalFeedback++;
|
|
186
186
|
}
|
|
@@ -199,8 +199,8 @@ export async function migrate(opts) {
|
|
|
199
199
|
const embedding = r.embedding
|
|
200
200
|
? vectorLiteral(Array.from(bufferToFloat32Array(r.embedding)))
|
|
201
201
|
: null;
|
|
202
|
-
await dst.query(`INSERT INTO episodes
|
|
203
|
-
(id, agent_id, label, embedding, engram_count, start_time, end_time, created_at)
|
|
202
|
+
await dst.query(`INSERT INTO episodes
|
|
203
|
+
(id, agent_id, label, embedding, engram_count, start_time, end_time, created_at)
|
|
204
204
|
VALUES ($1,$2,$3,$4::vector,$5,$6,$7,$8)`, [r.id, r.agent_id, r.label, embedding, r.engram_count ?? 0,
|
|
205
205
|
r.start_time, r.end_time, r.created_at]);
|
|
206
206
|
stats.episodes++;
|
|
@@ -221,13 +221,13 @@ export async function migrate(opts) {
|
|
|
221
221
|
console.log(`conscious_state: ${csRows.length} rows`);
|
|
222
222
|
if (dst && csRows.length > 0) {
|
|
223
223
|
for (const r of csRows) {
|
|
224
|
-
await dst.query(`INSERT INTO conscious_state (
|
|
225
|
-
agent_id, last_write_id, last_recall_context, last_recall_ids,
|
|
226
|
-
last_activity_at, write_count_since_consolidation,
|
|
227
|
-
recall_count_since_consolidation, execution_state, checkpoint_at,
|
|
228
|
-
last_consolidation_at, last_mini_consolidation_at,
|
|
229
|
-
consolidation_cycle_count, updated_at
|
|
230
|
-
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)
|
|
224
|
+
await dst.query(`INSERT INTO conscious_state (
|
|
225
|
+
agent_id, last_write_id, last_recall_context, last_recall_ids,
|
|
226
|
+
last_activity_at, write_count_since_consolidation,
|
|
227
|
+
recall_count_since_consolidation, execution_state, checkpoint_at,
|
|
228
|
+
last_consolidation_at, last_mini_consolidation_at,
|
|
229
|
+
consolidation_cycle_count, updated_at
|
|
230
|
+
) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)
|
|
231
231
|
ON CONFLICT (agent_id) DO NOTHING`, [
|
|
232
232
|
r.agent_id, r.last_write_id, r.last_recall_context,
|
|
233
233
|
r.last_recall_ids ?? '[]', r.last_activity_at,
|
package/dist/cli.js
CHANGED
|
@@ -38,46 +38,46 @@ catch { /* No .env file */ }
|
|
|
38
38
|
const args = process.argv.slice(2);
|
|
39
39
|
const command = args[0];
|
|
40
40
|
function printUsage() {
|
|
41
|
-
console.log(`
|
|
42
|
-
AgentWorkingMemory — Cognitive memory for AI agents
|
|
43
|
-
|
|
44
|
-
Usage:
|
|
45
|
-
awm setup [target] [options] Configure AWM for an AI CLI
|
|
46
|
-
awm doctor [target|--all] Validate AWM integrations
|
|
47
|
-
awm mcp Start MCP server (stdio)
|
|
48
|
-
awm serve [--port <port>] Start HTTP API server
|
|
49
|
-
awm health [--port <port>] Check server health
|
|
50
|
-
awm export --db <path> [--agent <id>] [--output <file>] [--active-only]
|
|
51
|
-
Export memories to JSON
|
|
52
|
-
awm import <file> --db <path> [--remap-agent <id>] [--dedupe] [--dry-run]
|
|
53
|
-
Import memories from JSON
|
|
54
|
-
awm merge --target <db> --source <db> [--source ...]
|
|
55
|
-
[--remap uuid=name] [--remap-all-uuids <name>]
|
|
56
|
-
[--dedupe] [--dry-run] Merge multiple memory DBs
|
|
57
|
-
awm migrate --from <sqlite.db> --to <pglite-dir> [--dry-run] [--verbose]
|
|
58
|
-
Migrate SQLite DB to PGlite
|
|
59
|
-
|
|
60
|
-
Setup targets:
|
|
61
|
-
claude-code (default) .mcp.json + CLAUDE.md + hooks
|
|
62
|
-
codex ~/.codex/config.toml + AGENTS.md
|
|
63
|
-
cursor .cursor/mcp.json + .cursorrules
|
|
64
|
-
http Connection info for HTTP API
|
|
65
|
-
|
|
66
|
-
Setup options:
|
|
67
|
-
--global Use global scope (recommended for claude-code)
|
|
68
|
-
--agent-id <id> Agent identifier (default: project name)
|
|
69
|
-
--db-path <path> Database path (default: <awm>/data/memory.db)
|
|
70
|
-
--no-instructions Skip instruction file (CLAUDE.md, AGENTS.md, etc.)
|
|
71
|
-
--no-claude-md Alias for --no-instructions
|
|
72
|
-
--no-hooks Skip hook installation
|
|
73
|
-
--hook-port PORT Sidecar port for hooks (default: 8401)
|
|
74
|
-
|
|
75
|
-
Examples:
|
|
76
|
-
awm setup --global Claude Code, global (recommended)
|
|
77
|
-
awm setup codex Codex CLI
|
|
78
|
-
awm setup cursor Cursor IDE
|
|
79
|
-
awm setup http Generic HTTP integration
|
|
80
|
-
awm doctor --all Check all configured targets
|
|
41
|
+
console.log(`
|
|
42
|
+
AgentWorkingMemory — Cognitive memory for AI agents
|
|
43
|
+
|
|
44
|
+
Usage:
|
|
45
|
+
awm setup [target] [options] Configure AWM for an AI CLI
|
|
46
|
+
awm doctor [target|--all] Validate AWM integrations
|
|
47
|
+
awm mcp Start MCP server (stdio)
|
|
48
|
+
awm serve [--port <port>] Start HTTP API server
|
|
49
|
+
awm health [--port <port>] Check server health
|
|
50
|
+
awm export --db <path> [--agent <id>] [--output <file>] [--active-only]
|
|
51
|
+
Export memories to JSON
|
|
52
|
+
awm import <file> --db <path> [--remap-agent <id>] [--dedupe] [--dry-run]
|
|
53
|
+
Import memories from JSON
|
|
54
|
+
awm merge --target <db> --source <db> [--source ...]
|
|
55
|
+
[--remap uuid=name] [--remap-all-uuids <name>]
|
|
56
|
+
[--dedupe] [--dry-run] Merge multiple memory DBs
|
|
57
|
+
awm migrate --from <sqlite.db> --to <pglite-dir> [--dry-run] [--verbose]
|
|
58
|
+
Migrate SQLite DB to PGlite
|
|
59
|
+
|
|
60
|
+
Setup targets:
|
|
61
|
+
claude-code (default) .mcp.json + CLAUDE.md + hooks
|
|
62
|
+
codex ~/.codex/config.toml + AGENTS.md
|
|
63
|
+
cursor .cursor/mcp.json + .cursorrules
|
|
64
|
+
http Connection info for HTTP API
|
|
65
|
+
|
|
66
|
+
Setup options:
|
|
67
|
+
--global Use global scope (recommended for claude-code)
|
|
68
|
+
--agent-id <id> Agent identifier (default: project name)
|
|
69
|
+
--db-path <path> Database path (default: <awm>/data/memory.db)
|
|
70
|
+
--no-instructions Skip instruction file (CLAUDE.md, AGENTS.md, etc.)
|
|
71
|
+
--no-claude-md Alias for --no-instructions
|
|
72
|
+
--no-hooks Skip hook installation
|
|
73
|
+
--hook-port PORT Sidecar port for hooks (default: 8401)
|
|
74
|
+
|
|
75
|
+
Examples:
|
|
76
|
+
awm setup --global Claude Code, global (recommended)
|
|
77
|
+
awm setup codex Codex CLI
|
|
78
|
+
awm setup cursor Cursor IDE
|
|
79
|
+
awm setup http Generic HTTP integration
|
|
80
|
+
awm doctor --all Check all configured targets
|
|
81
81
|
`.trim());
|
|
82
82
|
}
|
|
83
83
|
// ─── SETUP ──────────────────────────────────────
|
|
@@ -135,18 +135,18 @@ async function setup() {
|
|
|
135
135
|
const configAction = adapter.writeMcpConfig(ctx);
|
|
136
136
|
const instructionsAction = adapter.writeInstructions(ctx, skipInstructions);
|
|
137
137
|
const hooksAction = adapter.writeHooks(ctx, skipHooks);
|
|
138
|
-
console.log(`
|
|
139
|
-
AWM configured for ${adapter.name}${isGlobal ? ' (global)' : ''}
|
|
140
|
-
|
|
141
|
-
Agent ID: ${ctx.agentId}
|
|
142
|
-
DB path: ${ctx.dbPath}
|
|
143
|
-
${configAction}
|
|
144
|
-
${instructionsAction}
|
|
145
|
-
${hooksAction}
|
|
146
|
-
|
|
147
|
-
Next steps:
|
|
148
|
-
1. Restart ${adapter.name} to pick up the MCP server
|
|
149
|
-
2. Memory tools will appear automatically${adapter.id === 'codex' ? ' (verify with /mcp)' : ''}
|
|
138
|
+
console.log(`
|
|
139
|
+
AWM configured for ${adapter.name}${isGlobal ? ' (global)' : ''}
|
|
140
|
+
|
|
141
|
+
Agent ID: ${ctx.agentId}
|
|
142
|
+
DB path: ${ctx.dbPath}
|
|
143
|
+
${configAction}
|
|
144
|
+
${instructionsAction}
|
|
145
|
+
${hooksAction}
|
|
146
|
+
|
|
147
|
+
Next steps:
|
|
148
|
+
1. Restart ${adapter.name} to pick up the MCP server
|
|
149
|
+
2. Memory tools will appear automatically${adapter.id === 'codex' ? ' (verify with /mcp)' : ''}
|
|
150
150
|
`.trim());
|
|
151
151
|
}
|
|
152
152
|
// ─── DOCTOR ──────────────────────────────────────
|
|
@@ -309,7 +309,7 @@ async function exportMemories() {
|
|
|
309
309
|
// Collect unique agents
|
|
310
310
|
const agents = [...new Set(memories.map((m) => m.agent_id))];
|
|
311
311
|
const exportData = {
|
|
312
|
-
version: '0.8.
|
|
312
|
+
version: '0.8.8',
|
|
313
313
|
exported_at: new Date().toISOString(),
|
|
314
314
|
source_db: dbPath,
|
|
315
315
|
agent_filter: agentFilter,
|
|
@@ -374,23 +374,23 @@ async function importMemories() {
|
|
|
374
374
|
const Database = (await import('better-sqlite3')).default;
|
|
375
375
|
const db = new Database(dbPath);
|
|
376
376
|
// Ensure tables exist in target
|
|
377
|
-
db.exec(`
|
|
378
|
-
CREATE TABLE IF NOT EXISTS engrams (
|
|
379
|
-
id TEXT PRIMARY KEY, agent_id TEXT NOT NULL, concept TEXT NOT NULL, content TEXT NOT NULL,
|
|
380
|
-
embedding BLOB, confidence REAL NOT NULL DEFAULT 0.5, salience REAL NOT NULL DEFAULT 0.5,
|
|
381
|
-
access_count INTEGER NOT NULL DEFAULT 0, last_accessed TEXT NOT NULL, created_at TEXT NOT NULL,
|
|
382
|
-
salience_features TEXT NOT NULL DEFAULT '{}', reason_codes TEXT NOT NULL DEFAULT '[]',
|
|
383
|
-
stage TEXT NOT NULL DEFAULT 'active', ttl INTEGER, retracted INTEGER NOT NULL DEFAULT 0,
|
|
384
|
-
retracted_by TEXT, retracted_at TEXT, tags TEXT NOT NULL DEFAULT '[]',
|
|
385
|
-
episode_id TEXT, task_status TEXT, task_priority TEXT, blocked_by TEXT,
|
|
386
|
-
memory_class TEXT NOT NULL DEFAULT 'working', superseded_by TEXT, supersedes TEXT
|
|
387
|
-
);
|
|
388
|
-
CREATE TABLE IF NOT EXISTS associations (
|
|
389
|
-
id TEXT PRIMARY KEY, from_engram_id TEXT NOT NULL, to_engram_id TEXT NOT NULL,
|
|
390
|
-
weight REAL NOT NULL DEFAULT 0.1, confidence REAL NOT NULL DEFAULT 0.5,
|
|
391
|
-
type TEXT NOT NULL DEFAULT 'hebbian', activation_count INTEGER NOT NULL DEFAULT 0,
|
|
392
|
-
created_at TEXT NOT NULL, last_activated TEXT
|
|
393
|
-
);
|
|
377
|
+
db.exec(`
|
|
378
|
+
CREATE TABLE IF NOT EXISTS engrams (
|
|
379
|
+
id TEXT PRIMARY KEY, agent_id TEXT NOT NULL, concept TEXT NOT NULL, content TEXT NOT NULL,
|
|
380
|
+
embedding BLOB, confidence REAL NOT NULL DEFAULT 0.5, salience REAL NOT NULL DEFAULT 0.5,
|
|
381
|
+
access_count INTEGER NOT NULL DEFAULT 0, last_accessed TEXT NOT NULL, created_at TEXT NOT NULL,
|
|
382
|
+
salience_features TEXT NOT NULL DEFAULT '{}', reason_codes TEXT NOT NULL DEFAULT '[]',
|
|
383
|
+
stage TEXT NOT NULL DEFAULT 'active', ttl INTEGER, retracted INTEGER NOT NULL DEFAULT 0,
|
|
384
|
+
retracted_by TEXT, retracted_at TEXT, tags TEXT NOT NULL DEFAULT '[]',
|
|
385
|
+
episode_id TEXT, task_status TEXT, task_priority TEXT, blocked_by TEXT,
|
|
386
|
+
memory_class TEXT NOT NULL DEFAULT 'working', superseded_by TEXT, supersedes TEXT
|
|
387
|
+
);
|
|
388
|
+
CREATE TABLE IF NOT EXISTS associations (
|
|
389
|
+
id TEXT PRIMARY KEY, from_engram_id TEXT NOT NULL, to_engram_id TEXT NOT NULL,
|
|
390
|
+
weight REAL NOT NULL DEFAULT 0.1, confidence REAL NOT NULL DEFAULT 0.5,
|
|
391
|
+
type TEXT NOT NULL DEFAULT 'hebbian', activation_count INTEGER NOT NULL DEFAULT 0,
|
|
392
|
+
created_at TEXT NOT NULL, last_activated TEXT
|
|
393
|
+
);
|
|
394
394
|
`);
|
|
395
395
|
// Build dedup set if needed
|
|
396
396
|
const existingHashes = new Set();
|
|
@@ -405,15 +405,15 @@ async function importMemories() {
|
|
|
405
405
|
let imported = 0;
|
|
406
406
|
let skippedDupes = 0;
|
|
407
407
|
let skippedRetracted = 0;
|
|
408
|
-
const insertMem = db.prepare(`
|
|
409
|
-
INSERT INTO engrams (id, agent_id, concept, content, confidence, salience,
|
|
410
|
-
access_count, last_accessed, created_at, stage, tags, memory_class,
|
|
411
|
-
episode_id, task_status, task_priority, supersedes, superseded_by, retracted)
|
|
412
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
408
|
+
const insertMem = db.prepare(`
|
|
409
|
+
INSERT INTO engrams (id, agent_id, concept, content, confidence, salience,
|
|
410
|
+
access_count, last_accessed, created_at, stage, tags, memory_class,
|
|
411
|
+
episode_id, task_status, task_priority, supersedes, superseded_by, retracted)
|
|
412
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
413
413
|
`);
|
|
414
|
-
const insertAssoc = db.prepare(`
|
|
415
|
-
INSERT INTO associations (id, from_engram_id, to_engram_id, weight, type, activation_count, created_at)
|
|
416
|
-
VALUES (?, ?, ?, ?, ?, ?, datetime('now'))
|
|
414
|
+
const insertAssoc = db.prepare(`
|
|
415
|
+
INSERT INTO associations (id, from_engram_id, to_engram_id, weight, type, activation_count, created_at)
|
|
416
|
+
VALUES (?, ?, ?, ?, ?, ?, datetime('now'))
|
|
417
417
|
`);
|
|
418
418
|
const importTx = db.transaction(() => {
|
|
419
419
|
// Import memories
|
|
@@ -516,21 +516,21 @@ async function mergeMemories() {
|
|
|
516
516
|
targetDb.pragma('journal_mode = WAL');
|
|
517
517
|
targetDb.pragma('foreign_keys = ON');
|
|
518
518
|
// Ensure tables exist in target
|
|
519
|
-
targetDb.exec(`
|
|
520
|
-
CREATE TABLE IF NOT EXISTS engrams (
|
|
521
|
-
id TEXT PRIMARY KEY, agent_id TEXT NOT NULL, concept TEXT NOT NULL, content TEXT NOT NULL,
|
|
522
|
-
embedding BLOB, confidence REAL NOT NULL DEFAULT 0.5, salience REAL NOT NULL DEFAULT 0.5,
|
|
523
|
-
access_count INTEGER NOT NULL DEFAULT 0, last_accessed TEXT NOT NULL, created_at TEXT NOT NULL,
|
|
524
|
-
salience_features TEXT NOT NULL DEFAULT '{}', reason_codes TEXT NOT NULL DEFAULT '[]',
|
|
525
|
-
stage TEXT NOT NULL DEFAULT 'active', ttl INTEGER, retracted INTEGER NOT NULL DEFAULT 0,
|
|
526
|
-
retracted_by TEXT, retracted_at TEXT, tags TEXT NOT NULL DEFAULT '[]'
|
|
527
|
-
);
|
|
528
|
-
CREATE TABLE IF NOT EXISTS associations (
|
|
529
|
-
id TEXT PRIMARY KEY, from_engram_id TEXT NOT NULL, to_engram_id TEXT NOT NULL,
|
|
530
|
-
weight REAL NOT NULL DEFAULT 0.1, confidence REAL NOT NULL DEFAULT 0.5,
|
|
531
|
-
type TEXT NOT NULL DEFAULT 'hebbian', activation_count INTEGER NOT NULL DEFAULT 0,
|
|
532
|
-
created_at TEXT NOT NULL, last_activated TEXT NOT NULL
|
|
533
|
-
);
|
|
519
|
+
targetDb.exec(`
|
|
520
|
+
CREATE TABLE IF NOT EXISTS engrams (
|
|
521
|
+
id TEXT PRIMARY KEY, agent_id TEXT NOT NULL, concept TEXT NOT NULL, content TEXT NOT NULL,
|
|
522
|
+
embedding BLOB, confidence REAL NOT NULL DEFAULT 0.5, salience REAL NOT NULL DEFAULT 0.5,
|
|
523
|
+
access_count INTEGER NOT NULL DEFAULT 0, last_accessed TEXT NOT NULL, created_at TEXT NOT NULL,
|
|
524
|
+
salience_features TEXT NOT NULL DEFAULT '{}', reason_codes TEXT NOT NULL DEFAULT '[]',
|
|
525
|
+
stage TEXT NOT NULL DEFAULT 'active', ttl INTEGER, retracted INTEGER NOT NULL DEFAULT 0,
|
|
526
|
+
retracted_by TEXT, retracted_at TEXT, tags TEXT NOT NULL DEFAULT '[]'
|
|
527
|
+
);
|
|
528
|
+
CREATE TABLE IF NOT EXISTS associations (
|
|
529
|
+
id TEXT PRIMARY KEY, from_engram_id TEXT NOT NULL, to_engram_id TEXT NOT NULL,
|
|
530
|
+
weight REAL NOT NULL DEFAULT 0.1, confidence REAL NOT NULL DEFAULT 0.5,
|
|
531
|
+
type TEXT NOT NULL DEFAULT 'hebbian', activation_count INTEGER NOT NULL DEFAULT 0,
|
|
532
|
+
created_at TEXT NOT NULL, last_activated TEXT NOT NULL
|
|
533
|
+
);
|
|
534
534
|
`);
|
|
535
535
|
// Build dedupe hash set from existing target memories
|
|
536
536
|
const existingHashes = new Set();
|
|
@@ -540,16 +540,16 @@ async function mergeMemories() {
|
|
|
540
540
|
existingHashes.add(contentHash(row.concept, row.content));
|
|
541
541
|
console.log(`Target has ${existingHashes.size} unique memories (for dedupe)\n`);
|
|
542
542
|
}
|
|
543
|
-
const insertEngram = targetDb.prepare(`
|
|
544
|
-
INSERT OR IGNORE INTO engrams (id, agent_id, concept, content, confidence, salience, access_count,
|
|
545
|
-
last_accessed, created_at, salience_features, reason_codes, stage, ttl,
|
|
546
|
-
retracted, retracted_by, retracted_at, tags)
|
|
547
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
543
|
+
const insertEngram = targetDb.prepare(`
|
|
544
|
+
INSERT OR IGNORE INTO engrams (id, agent_id, concept, content, confidence, salience, access_count,
|
|
545
|
+
last_accessed, created_at, salience_features, reason_codes, stage, ttl,
|
|
546
|
+
retracted, retracted_by, retracted_at, tags)
|
|
547
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
548
548
|
`);
|
|
549
|
-
const insertAssoc = targetDb.prepare(`
|
|
550
|
-
INSERT OR IGNORE INTO associations (id, from_engram_id, to_engram_id, weight, confidence, type,
|
|
551
|
-
activation_count, created_at, last_activated)
|
|
552
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
549
|
+
const insertAssoc = targetDb.prepare(`
|
|
550
|
+
INSERT OR IGNORE INTO associations (id, from_engram_id, to_engram_id, weight, confidence, type,
|
|
551
|
+
activation_count, created_at, last_activated)
|
|
552
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
553
553
|
`);
|
|
554
554
|
let totalMemories = 0, totalAssociations = 0, totalSkipped = 0;
|
|
555
555
|
for (const sourcePath of sources) {
|
|
@@ -558,10 +558,10 @@ async function mergeMemories() {
|
|
|
558
558
|
continue;
|
|
559
559
|
}
|
|
560
560
|
const sourceDb = new Database(sourcePath, { readonly: true });
|
|
561
|
-
const engrams = sourceDb.prepare(`SELECT id, agent_id, concept, content, confidence, salience, access_count,
|
|
562
|
-
last_accessed, created_at, salience_features, reason_codes, stage, ttl,
|
|
561
|
+
const engrams = sourceDb.prepare(`SELECT id, agent_id, concept, content, confidence, salience, access_count,
|
|
562
|
+
last_accessed, created_at, salience_features, reason_codes, stage, ttl,
|
|
563
563
|
retracted, retracted_by, retracted_at, tags FROM engrams`).all();
|
|
564
|
-
const assocs = sourceDb.prepare(`SELECT id, from_engram_id, to_engram_id, weight, confidence, type,
|
|
564
|
+
const assocs = sourceDb.prepare(`SELECT id, from_engram_id, to_engram_id, weight, confidence, type,
|
|
565
565
|
activation_count, created_at, last_activated FROM associations`).all();
|
|
566
566
|
const idMap = new Map();
|
|
567
567
|
const skippedIds = new Set();
|
|
@@ -14,33 +14,33 @@ const FAILURE_THRESHOLD = 5;
|
|
|
14
14
|
const HALF_OPEN_DELAY_MS = 30_000;
|
|
15
15
|
/** Record a worker failure. Opens the circuit when consecutive failures hit the threshold. */
|
|
16
16
|
export function recordFailure(db, agentId) {
|
|
17
|
-
db.prepare(`
|
|
18
|
-
INSERT INTO coord_circuit_state (agent_id, consecutive_failures, last_transition_at)
|
|
19
|
-
VALUES (?, 1, datetime('now'))
|
|
20
|
-
ON CONFLICT(agent_id) DO UPDATE SET
|
|
21
|
-
consecutive_failures = consecutive_failures + 1,
|
|
22
|
-
state = CASE
|
|
23
|
-
WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} THEN 'open'
|
|
24
|
-
ELSE state
|
|
25
|
-
END,
|
|
26
|
-
opened_at = CASE
|
|
27
|
-
WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} AND (state != 'open' OR opened_at IS NULL)
|
|
28
|
-
THEN datetime('now')
|
|
29
|
-
ELSE opened_at
|
|
30
|
-
END,
|
|
31
|
-
last_transition_at = datetime('now')
|
|
17
|
+
db.prepare(`
|
|
18
|
+
INSERT INTO coord_circuit_state (agent_id, consecutive_failures, last_transition_at)
|
|
19
|
+
VALUES (?, 1, datetime('now'))
|
|
20
|
+
ON CONFLICT(agent_id) DO UPDATE SET
|
|
21
|
+
consecutive_failures = consecutive_failures + 1,
|
|
22
|
+
state = CASE
|
|
23
|
+
WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} THEN 'open'
|
|
24
|
+
ELSE state
|
|
25
|
+
END,
|
|
26
|
+
opened_at = CASE
|
|
27
|
+
WHEN consecutive_failures + 1 >= ${FAILURE_THRESHOLD} AND (state != 'open' OR opened_at IS NULL)
|
|
28
|
+
THEN datetime('now')
|
|
29
|
+
ELSE opened_at
|
|
30
|
+
END,
|
|
31
|
+
last_transition_at = datetime('now')
|
|
32
32
|
`).run(agentId);
|
|
33
33
|
}
|
|
34
34
|
/** Record a worker success. Resets to closed regardless of prior state. */
|
|
35
35
|
export function recordSuccess(db, agentId) {
|
|
36
|
-
db.prepare(`
|
|
37
|
-
INSERT INTO coord_circuit_state (agent_id, state, consecutive_failures, last_transition_at)
|
|
38
|
-
VALUES (?, 'closed', 0, datetime('now'))
|
|
39
|
-
ON CONFLICT(agent_id) DO UPDATE SET
|
|
40
|
-
state = 'closed',
|
|
41
|
-
consecutive_failures = 0,
|
|
42
|
-
opened_at = NULL,
|
|
43
|
-
last_transition_at = datetime('now')
|
|
36
|
+
db.prepare(`
|
|
37
|
+
INSERT INTO coord_circuit_state (agent_id, state, consecutive_failures, last_transition_at)
|
|
38
|
+
VALUES (?, 'closed', 0, datetime('now'))
|
|
39
|
+
ON CONFLICT(agent_id) DO UPDATE SET
|
|
40
|
+
state = 'closed',
|
|
41
|
+
consecutive_failures = 0,
|
|
42
|
+
opened_at = NULL,
|
|
43
|
+
last_transition_at = datetime('now')
|
|
44
44
|
`).run(agentId);
|
|
45
45
|
}
|
|
46
46
|
/**
|