From 0607dd83098637c455839aeb48e5cfa52c6075ad Mon Sep 17 00:00:00 2001 From: davidrobertson Date: Sun, 1 Nov 2026 16:34:57 -0500 Subject: [PATCH] fix: port upstream capture and import safety fixes Adapt upstream import preflight, structured redaction, identifier boundaries, and hook event identities while preserving fork runtime and storage behavior. Co-authored-by: Dmitrii Zhukov Co-authored-by: Rohit Ghumare <48523873+rohitg00@users.noreply.github.com> --- AGENTS.md | 4 +- README.md | 6 +- READMEs/README.ar-SA.md | 6 +- READMEs/README.bn-BD.md | 6 +- READMEs/README.cs-CZ.md | 6 +- READMEs/README.da-DK.md | 6 +- READMEs/README.de-DE.md | 6 +- READMEs/README.el-GR.md | 6 +- READMEs/README.es-ES.md | 6 +- READMEs/README.fi-FI.md | 6 +- READMEs/README.fr-FR.md | 6 +- READMEs/README.he-IL.md | 6 +- READMEs/README.hi-IN.md | 6 +- READMEs/README.hu-HU.md | 6 +- READMEs/README.id-ID.md | 6 +- READMEs/README.it-IT.md | 6 +- READMEs/README.ja-JP.md | 6 +- READMEs/README.ko-KR.md | 6 +- READMEs/README.nb-NO.md | 6 +- READMEs/README.nl-NL.md | 6 +- READMEs/README.pl-PL.md | 6 +- READMEs/README.pt-BR.md | 6 +- READMEs/README.pt-PT.md | 6 +- READMEs/README.ro-RO.md | 6 +- READMEs/README.ru-RU.md | 6 +- READMEs/README.sv-SE.md | 6 +- READMEs/README.th-TH.md | 6 +- READMEs/README.tl-PH.md | 6 +- READMEs/README.tr-TR.md | 6 +- READMEs/README.uk-UA.md | 6 +- READMEs/README.ur-PK.md | 6 +- READMEs/README.vi-VN.md | 6 +- READMEs/README.zh-CN.md | 6 +- READMEs/README.zh-TW.md | 6 +- assets/tags/light/stat-tests.svg | 4 +- assets/tags/stat-tests.svg | 4 +- .../reliability/2026-11-01-upstream-review.md | 55 +++++ plugin/scripts/_capture.mjs | 40 +++- plugin/scripts/notification.mjs | 10 +- plugin/scripts/subagent-start.mjs | 2 +- plugin/scripts/subagent-stop.mjs | 8 +- plugin/scripts/task-completed.mjs | 2 +- scripts/docs-sync.state.json | 2 +- src/capture/spool.ts | 14 +- src/functions/export-import.ts | 47 +++- src/functions/observe.ts | 14 +- src/functions/privacy.ts | 32 ++- src/hooks/notification.ts | 30 +-- src/hooks/subagent-start.ts | 4 +- src/hooks/subagent-stop.ts | 29 +-- src/hooks/task-completed.ts | 4 +- test/capture-redaction.test.ts | 207 +++++++++++++++++ test/export-import.test.ts | 134 +++++++++++ test/hook-event-ids.test.ts | 210 ++++++++++++++++++ test/privacy.test.ts | 73 +++++- 55 files changed, 932 insertions(+), 195 deletions(-) create mode 100644 docs/reliability/2026-11-01-upstream-review.md create mode 100644 test/capture-redaction.test.ts create mode 100644 test/hook-event-ids.test.ts diff --git a/AGENTS.md b/AGENTS.md index a07b67533a..5de6bd9516 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -101,7 +101,7 @@ Hook scripts in `src/hooks/` are standalone Node.js scripts (no iii-sdk import). ## Testing -- Before every commit run, in order: `npm run build`, `npm run skills:gen`, `npm run docs:sync`, `npm run skills:check`, `npm test` (2,600+ tests). Commit anything the generators changed. CI runs the same build, skills check and tests. +- Before every commit run, in order: `npm run build`, `npm run skills:gen`, `npm run docs:sync`, `npm run skills:check`, `npm test` (2,800+ tests). Commit anything the generators changed. CI runs the same build, skills check and tests. - Before any npm publish: `npm run release:gate` must pass. It installs the packed tarballs into a clean home and runs capture, recovery, restart, export/import, MCP and status checks against the installed CLI (see CONTRIBUTING.md, Release process) - Mock pattern: `vi.mock("iii-sdk")` with mock `sdk.trigger`, `kv.get/set/list` - Test files go in `test/` with `.test.ts` extension @@ -114,4 +114,4 @@ Hook scripts in `src/hooks/` are standalone Node.js scripts (no iii-sdk import). - 6 MCP resources, 3 MCP prompts - 12 hooks, 17 skills - 312+ iii functions -- 2,600+ tests +- 2,800+ tests diff --git a/README.md b/README.md index 72e285ae2c..cd95d1646a 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1446,7 +1446,7 @@ fi | Prometheus / Grafana | iii OTEL + health monitor | | Custom plugin systems | `iii worker add ` | -**225 source files · ~54,000 LOC · 2,600+ tests · 312 functions · 66 KV scopes**, all on three primitives. No `agentmemory plugin install`. The plugin system is iii itself. +**225 source files · ~54,000 LOC · 2,800+ tests · 312 functions · 66 KV scopes**, all on three primitives. No `agentmemory plugin install`. The plugin system is iii itself. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ar-SA.md b/READMEs/README.ar-SA.md index ae107e1b53..dc3a9a4c2f 100644 --- a/READMEs/README.ar-SA.md +++ b/READMEs/README.ar-SA.md @@ -73,7 +73,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1439,7 +1439,7 @@ fi | Prometheus / Grafana | OTEL في iii + مراقب الحالة الصحية | | أنظمة إضافات مخصصة | `iii worker add ` | -**225 ملف مصدري · ~54,000 سطر برمجي · 2,600+ اختبار · 312 دالة · 66 نطاق KV**، كل ذلك على ثلاث بنى أساسية. لا يوجد أمر `agentmemory plugin install`. نظام الإضافات هو iii نفسه. +**225 ملف مصدري · ~54,000 سطر برمجي · 2,800+ اختبار · 312 دالة · 66 نطاق KV**، كل ذلك على ثلاث بنى أساسية. لا يوجد أمر `agentmemory plugin install`. نظام الإضافات هو iii نفسه. --- @@ -1863,7 +1863,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.bn-BD.md b/READMEs/README.bn-BD.md index decacdc164..787f56851c 100644 --- a/READMEs/README.bn-BD.md +++ b/READMEs/README.bn-BD.md @@ -71,7 +71,7 @@ 54 MCP টুল 12 অটো হুক 0 এক্সটার্নাল ডিবি - 2,600+ টেস্ট পাস + 2,800+ টেস্ট পাস

@@ -1437,7 +1437,7 @@ fi | Prometheus / Grafana | iii OTEL + হেলথ মনিটর | | কাস্টম প্লাগইন সিস্টেম | `iii worker add ` | -**225 সোর্স ফাইল · ~54,000 LOC · 2,600+ টেস্ট · 312 ফাংশন · 66 KV স্কোপ**, সবকিছু তিনটি প্রিমিটিভের উপর। কোনো `agentmemory plugin install` নেই। প্লাগইন সিস্টেমটাই iii নিজে। +**225 সোর্স ফাইল · ~54,000 LOC · 2,800+ টেস্ট · 312 ফাংশন · 66 KV স্কোপ**, সবকিছু তিনটি প্রিমিটিভের উপর। কোনো `agentmemory plugin install` নেই। প্লাগইন সিস্টেমটাই iii নিজে। --- @@ -1861,7 +1861,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.cs-CZ.md b/READMEs/README.cs-CZ.md index 2c89bc5cbd..dcced82d2a 100644 --- a/READMEs/README.cs-CZ.md +++ b/READMEs/README.cs-CZ.md @@ -71,7 +71,7 @@ 54 MCP nástrojů 12 automatických hooks 0 externích databází - 2,600+ testů úspěšně proběhlo + 2,800+ testů úspěšně proběhlo

@@ -1446,7 +1446,7 @@ fi | Prometheus / Grafana | iii OTEL + health monitor | | Vlastní systémy pluginů | `iii worker add ` | -**225 zdrojových souborů · ~54,000 řádků kódu · 2,600+ testů · 312 funkcí · 66 KV scopes**, vše na třech primitivech. Žádné `agentmemory plugin install`. Systém pluginů je samo iii. +**225 zdrojových souborů · ~54,000 řádků kódu · 2,800+ testů · 312 funkcí · 66 KV scopes**, vše na třech primitivech. Žádné `agentmemory plugin install`. Systém pluginů je samo iii. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.da-DK.md b/READMEs/README.da-DK.md index 4ddeedad2c..a528100018 100644 --- a/READMEs/README.da-DK.md +++ b/READMEs/README.da-DK.md @@ -71,7 +71,7 @@ 54 MCP-værktøjer 12 automatiske hooks 0 eksterne databaser - 2,600+ beståede tests + 2,800+ beståede tests

@@ -1436,7 +1436,7 @@ fi | Prometheus / Grafana | iii OTEL + health monitor | | Custom plugin-systemer | `iii worker add ` | -**225 kildefiler · ~54,000 LOC · 2,600+ tests · 312 funktioner · 66 KV-scopes**, alt på tre primitiver. Intet `agentmemory plugin install`. Plugin-systemet er iii selv. +**225 kildefiler · ~54,000 LOC · 2,800+ tests · 312 funktioner · 66 KV-scopes**, alt på tre primitiver. Intet `agentmemory plugin install`. Plugin-systemet er iii selv. --- @@ -1860,7 +1860,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.de-DE.md b/READMEs/README.de-DE.md index 34793535bd..02273d4fff 100644 --- a/READMEs/README.de-DE.md +++ b/READMEs/README.de-DE.md @@ -71,7 +71,7 @@ 54 MCP-Tools 12 Auto-Hooks 0 externe DBs - 2,600+ bestandene Tests + 2,800+ bestandene Tests

@@ -1446,7 +1446,7 @@ fi | Prometheus / Grafana | iii OTEL + Health-Monitor | | Eigene Plugin-Systeme | `iii worker add ` | -**225 Quelldateien · ~54,000 LOC · 2,600+ Tests · 312 Funktionen · 66 KV-Scopes**, alles auf drei Primitiven. Kein `agentmemory plugin install`. Das Plugin-System ist iii selbst. +**225 Quelldateien · ~54,000 LOC · 2,800+ Tests · 312 Funktionen · 66 KV-Scopes**, alles auf drei Primitiven. Kein `agentmemory plugin install`. Das Plugin-System ist iii selbst. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.el-GR.md b/READMEs/README.el-GR.md index b6b169e323..a3a3d8de07 100644 --- a/READMEs/README.el-GR.md +++ b/READMEs/README.el-GR.md @@ -71,7 +71,7 @@ 54 εργαλεία MCP 12 αυτόματα hooks 0 εξωτερικές βάσεις δεδομένων - 2,600+ επιτυχημένες δοκιμές + 2,800+ επιτυχημένες δοκιμές

@@ -1438,7 +1438,7 @@ fi | Prometheus / Grafana | iii OTEL + monitor υγείας | | Προσαρμοσμένα συστήματα plugin | `iii worker add ` | -**225 αρχεία πηγαίου κώδικα · ~54,000 LOC · 2,600+ δοκιμές · 312 functions · 66 KV scopes**, όλα πάνω σε τρία primitives. Δεν υπάρχει `agentmemory plugin install`. Το σύστημα plugin είναι το ίδιο το iii. +**225 αρχεία πηγαίου κώδικα · ~54,000 LOC · 2,800+ δοκιμές · 312 functions · 66 KV scopes**, όλα πάνω σε τρία primitives. Δεν υπάρχει `agentmemory plugin install`. Το σύστημα plugin είναι το ίδιο το iii. --- @@ -1862,7 +1862,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.es-ES.md b/READMEs/README.es-ES.md index 0a1ac997fd..59a163c5ef 100644 --- a/READMEs/README.es-ES.md +++ b/READMEs/README.es-ES.md @@ -71,7 +71,7 @@ 54 tools MCP 12 hooks automáticos 0 bases de datos externas - 2,600+ tests superados + 2,800+ tests superados

@@ -1446,7 +1446,7 @@ fi | Prometheus / Grafana | iii OTEL + monitor de salud | | Sistemas de plugins propios | `iii worker add ` | -**225 ficheros de código · ~54,000 LOC · 2,600+ tests · 312 funciones · 66 scopes KV**, todo sobre tres primitivos. No hay `agentmemory plugin install`. El sistema de plugins es iii mismo. +**225 ficheros de código · ~54,000 LOC · 2,800+ tests · 312 funciones · 66 scopes KV**, todo sobre tres primitivos. No hay `agentmemory plugin install`. El sistema de plugins es iii mismo. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.fi-FI.md b/READMEs/README.fi-FI.md index 45f9227a39..964fbe3119 100644 --- a/READMEs/README.fi-FI.md +++ b/READMEs/README.fi-FI.md @@ -71,7 +71,7 @@ 54 MCP-työkalua 12 automaattista hookia 0 ulkoista tietokantaa - 2,600+ testiä läpäisty + 2,800+ testiä läpäisty

@@ -1446,7 +1446,7 @@ fi | Prometheus / Grafana | iii OTEL + terveysmonitori | | Mukautetut plugin-järjestelmät | `iii worker add ` | -**225 lähdetiedostoa · ~54,000 LOC · 2,600+ testiä · 312 funktiota · 66 KV-scopea**, kaikki kolmen primitiivin päällä. Ei `agentmemory plugin install` -komentoa. Plugin-järjestelmä on iii itse. +**225 lähdetiedostoa · ~54,000 LOC · 2,800+ testiä · 312 funktiota · 66 KV-scopea**, kaikki kolmen primitiivin päällä. Ei `agentmemory plugin install` -komentoa. Plugin-järjestelmä on iii itse. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.fr-FR.md b/READMEs/README.fr-FR.md index b621587a96..8db27f238a 100644 --- a/READMEs/README.fr-FR.md +++ b/READMEs/README.fr-FR.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1448,7 +1448,7 @@ fi | Prometheus / Grafana | iii OTEL + moniteur de santé | | Systèmes de plugins custom | `iii worker add ` | -**225 fichiers sources · ~54,000 LOC · 2,600+ tests · 312 fonctions · 66 scopes KV**, tout sur trois primitives. Pas de `agentmemory plugin install`. Le système de plugins, c'est iii lui-même. +**225 fichiers sources · ~54,000 LOC · 2,800+ tests · 312 fonctions · 66 scopes KV**, tout sur trois primitives. Pas de `agentmemory plugin install`. Le système de plugins, c'est iii lui-même. --- @@ -1872,7 +1872,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.he-IL.md b/READMEs/README.he-IL.md index cbfcc48b0d..f6067cf14a 100644 --- a/READMEs/README.he-IL.md +++ b/READMEs/README.he-IL.md @@ -73,7 +73,7 @@ 54 כלי MCP 12 hooks אוטומטיים 0 מסדי נתונים חיצוניים - 2,600+ בדיקות עוברות + 2,800+ בדיקות עוברות

@@ -1439,7 +1439,7 @@ fi | Prometheus / Grafana | iii OTEL + מוניטור health | | מערכות plugin מותאמות אישית | `iii worker add ` | -**225 קבצי מקור · ~54,000 LOC · 2,600+ בדיקות · 312 פונקציות · 66 תחומי KV**, הכול על שלושה primitives. אין `agentmemory plugin install`. מערכת ה-plugin היא iii עצמו. +**225 קבצי מקור · ~54,000 LOC · 2,800+ בדיקות · 312 פונקציות · 66 תחומי KV**, הכול על שלושה primitives. אין `agentmemory plugin install`. מערכת ה-plugin היא iii עצמו. --- @@ -1863,7 +1863,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.hi-IN.md b/READMEs/README.hi-IN.md index 0a20e6f298..3960e04d5c 100644 --- a/READMEs/README.hi-IN.md +++ b/READMEs/README.hi-IN.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1449,7 +1449,7 @@ fi | Prometheus / Grafana | iii OTEL + health monitor | | Custom plugin systems | `iii worker add ` | -**225 source files · ~54,000 LOC · 2,600+ tests · 312 functions · 66 KV scopes**, सब कुछ तीन primitives पर। कोई `agentmemory plugin install` नहीं। Plugin system iii स्वयं है। +**225 source files · ~54,000 LOC · 2,800+ tests · 312 functions · 66 KV scopes**, सब कुछ तीन primitives पर। कोई `agentmemory plugin install` नहीं। Plugin system iii स्वयं है। --- @@ -1873,7 +1873,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.hu-HU.md b/READMEs/README.hu-HU.md index 40bb3780f8..0d340a625a 100644 --- a/READMEs/README.hu-HU.md +++ b/READMEs/README.hu-HU.md @@ -71,7 +71,7 @@ 54 MCP eszköz 12 automatikus hook 0 külső adatbázis - 2,600+ sikeres teszt + 2,800+ sikeres teszt

@@ -1446,7 +1446,7 @@ A `/agentmemory/export` emellett elfogadja a `?maxSessions=`-t és a `?offset=`- | Prometheus / Grafana | iii OTEL + egészségfigyelő | | Egyéni plugin-rendszerek | `iii worker add ` | -**225 forrásfájl · ~54,000 LOC · 2,600+ teszt · 312 funkció · 66 KV-hatókör**, mindez három primitíven. Nincs `agentmemory plugin install`. A plugin-rendszer maga az iii. +**225 forrásfájl · ~54,000 LOC · 2,800+ teszt · 312 funkció · 66 KV-hatókör**, mindez három primitíven. Nincs `agentmemory plugin install`. A plugin-rendszer maga az iii. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.id-ID.md b/READMEs/README.id-ID.md index 88ef7560e5..efa3c2719a 100644 --- a/READMEs/README.id-ID.md +++ b/READMEs/README.id-ID.md @@ -71,7 +71,7 @@ 54 tool MCP 12 hook otomatis 0 DB eksternal - 2,600+ pengujian lolos + 2,800+ pengujian lolos

@@ -1447,7 +1447,7 @@ fi | Prometheus / Grafana | iii OTEL + health monitor | | Sistem plugin custom | `iii worker add ` | -**225 file sumber · ~54,000 LOC · 2,600+ pengujian · 312 fungsi · 66 scope KV**, semua di atas tiga primitif. Tidak ada `agentmemory plugin install`. Sistem plugin-nya adalah iii itu sendiri. +**225 file sumber · ~54,000 LOC · 2,800+ pengujian · 312 fungsi · 66 scope KV**, semua di atas tiga primitif. Tidak ada `agentmemory plugin install`. Sistem plugin-nya adalah iii itu sendiri. --- @@ -1871,7 +1871,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.it-IT.md b/READMEs/README.it-IT.md index 270db8966a..d85db03518 100644 --- a/READMEs/README.it-IT.md +++ b/READMEs/README.it-IT.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1446,7 +1446,7 @@ fi | Prometheus / Grafana | iii OTEL + monitor di salute | | Sistemi di plugin personalizzati | `iii worker add ` | -**225 file sorgente · ~54,000 righe di codice · 2,600+ test · 312 funzioni · 66 scope KV**, tutto su tre primitive. Nessun `agentmemory plugin install`. Il sistema di plugin è iii stesso. +**225 file sorgente · ~54,000 righe di codice · 2,800+ test · 312 funzioni · 66 scope KV**, tutto su tre primitive. Nessun `agentmemory plugin install`. Il sistema di plugin è iii stesso. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ja-JP.md b/READMEs/README.ja-JP.md index 6aa9d54f74..d6f74636fc 100644 --- a/READMEs/README.ja-JP.md +++ b/READMEs/README.ja-JP.md @@ -71,7 +71,7 @@ 54 MCP ツール 12 自動 hooks 外部 DB 0 個 - 2,600+ 件のテストが成功 + 2,800+ 件のテストが成功

@@ -1445,7 +1445,7 @@ fi | Prometheus / Grafana | iii OTEL + ヘルスモニタ | | カスタムプラグインシステム | `iii worker add ` | -**225 ソースファイル · ~54,000 LOC · 2,600+ テスト · 312 functions · 66 KV スコープ** — すべて 3 つのプリミティブの上に。`agentmemory plugin install` はありません。プラグインシステムは iii そのものです。 +**225 ソースファイル · ~54,000 LOC · 2,800+ テスト · 312 functions · 66 KV スコープ** — すべて 3 つのプリミティブの上に。`agentmemory plugin install` はありません。プラグインシステムは iii そのものです。 --- @@ -1869,7 +1869,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ko-KR.md b/READMEs/README.ko-KR.md index e005768950..43aa8d1c8e 100644 --- a/READMEs/README.ko-KR.md +++ b/READMEs/README.ko-KR.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1446,7 +1446,7 @@ fi | Prometheus / Grafana | iii OTEL + health 모니터 | | 커스텀 플러그인 시스템 | `iii worker add ` | -**소스 파일 225개 · LOC ~54,000줄 · 테스트 2,600+개 · 함수 312개 · KV 스코프 66개**, 모두 세 가지 프리미티브 위에서 동작합니다. `agentmemory plugin install` 같은 것은 없습니다. 플러그인 시스템은 곧 iii 자체입니다. +**소스 파일 225개 · LOC ~54,000줄 · 테스트 2,800+개 · 함수 312개 · KV 스코프 66개**, 모두 세 가지 프리미티브 위에서 동작합니다. `agentmemory plugin install` 같은 것은 없습니다. 플러그인 시스템은 곧 iii 자체입니다. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.nb-NO.md b/READMEs/README.nb-NO.md index 334ba7c453..55b3235cec 100644 --- a/READMEs/README.nb-NO.md +++ b/READMEs/README.nb-NO.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1447,7 +1447,7 @@ fi | Prometheus / Grafana | iii OTEL + helseovervåker | | Egendefinerte plugin-systemer | `iii worker add ` | -**225 kildefiler · ~54,000 LOC · 2,600+ tester · 312 funksjoner · 66 KV-scopes**, alt på tre primitiver. Ingen `agentmemory plugin install`. Plugin-systemet er iii selv. +**225 kildefiler · ~54,000 LOC · 2,800+ tester · 312 funksjoner · 66 KV-scopes**, alt på tre primitiver. Ingen `agentmemory plugin install`. Plugin-systemet er iii selv. --- @@ -1871,7 +1871,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.nl-NL.md b/READMEs/README.nl-NL.md index a8a61a2471..2ce6ae947d 100644 --- a/READMEs/README.nl-NL.md +++ b/READMEs/README.nl-NL.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1446,7 +1446,7 @@ fi | Prometheus / Grafana | iii OTEL + health monitor | | Custom plugin-systemen | `iii worker add ` | -**225 bronbestanden · ~54,000 LOC · 2,600+ tests · 312 functies · 66 KV-scopes**, allemaal op drie primitieven. Geen `agentmemory plugin install`. Het pluginsysteem is iii zelf. +**225 bronbestanden · ~54,000 LOC · 2,800+ tests · 312 functies · 66 KV-scopes**, allemaal op drie primitieven. Geen `agentmemory plugin install`. Het pluginsysteem is iii zelf. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.pl-PL.md b/READMEs/README.pl-PL.md index ae1648952b..5845653e97 100644 --- a/READMEs/README.pl-PL.md +++ b/READMEs/README.pl-PL.md @@ -71,7 +71,7 @@ 54 narzędzia MCP 12 automatycznych hooków 0 zewnętrznych baz danych - 2,600+ zaliczonych testów + 2,800+ zaliczonych testów

@@ -1446,7 +1446,7 @@ fi | Prometheus / Grafana | iii OTEL + monitor stanu | | Niestandardowe systemy pluginów | `iii worker add ` | -**225 plików źródłowych · ~54,000 LOC · 2,600+ testów · 312 funkcji · 66 zakresów KV**, wszystko na trzech prymitywach. Nie ma `agentmemory plugin install`. Systemem pluginów jest sam iii. +**225 plików źródłowych · ~54,000 LOC · 2,800+ testów · 312 funkcji · 66 zakresów KV**, wszystko na trzech prymitywach. Nie ma `agentmemory plugin install`. Systemem pluginów jest sam iii. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.pt-BR.md b/READMEs/README.pt-BR.md index 78f0d899e5..f70020b97b 100644 --- a/READMEs/README.pt-BR.md +++ b/READMEs/README.pt-BR.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1447,7 +1447,7 @@ fi | Prometheus / Grafana | iii OTEL + monitor de saúde | | Sistemas de plugin customizados | `iii worker add ` | -**225 arquivos de código · ~54,000 LOC · 2,600+ testes · 312 funções · 66 escopos KV**, tudo em cima de três primitivos. Sem `agentmemory plugin install`. O sistema de plugins é o próprio iii. +**225 arquivos de código · ~54,000 LOC · 2,800+ testes · 312 funções · 66 escopos KV**, tudo em cima de três primitivos. Sem `agentmemory plugin install`. O sistema de plugins é o próprio iii. --- @@ -1871,7 +1871,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.pt-PT.md b/READMEs/README.pt-PT.md index c858b4a073..12fd2548f4 100644 --- a/READMEs/README.pt-PT.md +++ b/READMEs/README.pt-PT.md @@ -71,7 +71,7 @@ 54 ferramentas MCP 12 hooks automáticos 0 bases de dados externas - 2,600+ testes aprovados + 2,800+ testes aprovados

@@ -1446,7 +1446,7 @@ O `/agentmemory/export` também aceita `?maxSessions=` e `?offset=` para dividir | Prometheus / Grafana | iii OTEL + monitor de saúde | | Sistemas de plugins personalizados | `iii worker add ` | -**225 ficheiros de código-fonte · ~54,000 LOC · 2,600+ testes · 312 funções · 66 âmbitos de KV**, tudo sobre três primitivos. Sem `agentmemory plugin install`. O sistema de plugins é o próprio iii. +**225 ficheiros de código-fonte · ~54,000 LOC · 2,800+ testes · 312 funções · 66 âmbitos de KV**, tudo sobre três primitivos. Sem `agentmemory plugin install`. O sistema de plugins é o próprio iii. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ro-RO.md b/READMEs/README.ro-RO.md index 4582afcea6..cd2477b339 100644 --- a/READMEs/README.ro-RO.md +++ b/READMEs/README.ro-RO.md @@ -71,7 +71,7 @@ 54 de instrumente MCP 12 hook-uri automate 0 baze de date externe - 2,600+ teste trecute + 2,800+ teste trecute

@@ -1430,7 +1430,7 @@ fi | Prometheus / Grafana | iii OTEL + monitor de sănătate | | Sisteme de plugin-uri personalizate | `iii worker add ` | -**225 fișiere sursă · ~54,000 LOC · 2,600+ teste · 312 funcții · 66 domenii KV**, toate pe trei primitive. Niciun `agentmemory plugin install`. Sistemul de plugin-uri este chiar iii. +**225 fișiere sursă · ~54,000 LOC · 2,800+ teste · 312 funcții · 66 domenii KV**, toate pe trei primitive. Niciun `agentmemory plugin install`. Sistemul de plugin-uri este chiar iii. --- @@ -1854,7 +1854,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ru-RU.md b/READMEs/README.ru-RU.md index 22d7188106..7ca6e7a032 100644 --- a/READMEs/README.ru-RU.md +++ b/READMEs/README.ru-RU.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1446,7 +1446,7 @@ fi | Prometheus / Grafana | iii OTEL + монитор состояния | | Самописные плагинные системы | `iii worker add ` | -**225 исходных файлов · ~54,000 LOC · 2,600+ тестов · 312 функция · 66 KV-scope'ов**, всё на трёх примитивах. Никакого `agentmemory plugin install`. Плагинная система — это сам iii. +**225 исходных файлов · ~54,000 LOC · 2,800+ тестов · 312 функция · 66 KV-scope'ов**, всё на трёх примитивах. Никакого `agentmemory plugin install`. Плагинная система — это сам iii. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.sv-SE.md b/READMEs/README.sv-SE.md index 1ee7fbd048..fe171159ce 100644 --- a/READMEs/README.sv-SE.md +++ b/READMEs/README.sv-SE.md @@ -71,7 +71,7 @@ 54 MCP-verktyg 12 automatiska hooks 0 externa databaser - 2,600+ godkända tester + 2,800+ godkända tester

@@ -1437,7 +1437,7 @@ fi | Prometheus / Grafana | iii OTEL + hälsoövervakare | | Anpassade pluginsystem | `iii worker add ` | -**225 källkodsfiler · ~54,000 LOC · 2,600+ tester · 312 funktioner · 66 KV-scopes**, allt på tre primitiv. Inget `agentmemory plugin install`. Pluginsystemet är iii självt. +**225 källkodsfiler · ~54,000 LOC · 2,800+ tester · 312 funktioner · 66 KV-scopes**, allt på tre primitiv. Inget `agentmemory plugin install`. Pluginsystemet är iii självt. --- @@ -1861,7 +1861,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.th-TH.md b/READMEs/README.th-TH.md index d64a5f00c9..b2758963a4 100644 --- a/READMEs/README.th-TH.md +++ b/READMEs/README.th-TH.md @@ -71,7 +71,7 @@ 54 เครื่องมือ MCP 12 hook อัตโนมัติ ไม่ต้องพึ่ง external DB เลย - ผ่านการทดสอบ 2,600+ รายการ + ผ่านการทดสอบ 2,800+ รายการ

@@ -1444,7 +1444,7 @@ fi | Prometheus / Grafana | iii OTEL + health monitor | | Custom plugin systems | `iii worker add ` | -**225 source file · ~54,000 LOC · 2,600+ การทดสอบ · 312 function · 66 KV scope** ทั้งหมดอยู่บน primitive สามตัว ไม่มี `agentmemory plugin install` ระบบ plugin ก็คือ iii เองนั่นแหละ +**225 source file · ~54,000 LOC · 2,800+ การทดสอบ · 312 function · 66 KV scope** ทั้งหมดอยู่บน primitive สามตัว ไม่มี `agentmemory plugin install` ระบบ plugin ก็คือ iii เองนั่นแหละ --- @@ -1868,7 +1868,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.tl-PH.md b/READMEs/README.tl-PH.md index 6f08a9c3b2..dd2002c7fd 100644 --- a/READMEs/README.tl-PH.md +++ b/READMEs/README.tl-PH.md @@ -71,7 +71,7 @@ 54 MCP tool 12 awtomatikong hook 0 panlabas na DB - 2,600+ pumapasang test + 2,800+ pumapasang test

@@ -1446,7 +1446,7 @@ Tinatanggap din ng `/agentmemory/export` ang `?maxSessions=` at `?offset=` para | Prometheus / Grafana | iii OTEL + health monitor | | Custom na plugin system | `iii worker add ` | -**225 na source file · ~54,000 LOC · 2,600+ na test · 312 na function · 66 na KV scope**, lahat sa tatlong primitive. Walang `agentmemory plugin install`. Ang plugin system mismo ay ang iii. +**225 na source file · ~54,000 LOC · 2,800+ na test · 312 na function · 66 na KV scope**, lahat sa tatlong primitive. Walang `agentmemory plugin install`. Ang plugin system mismo ay ang iii. --- @@ -1870,7 +1870,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.tr-TR.md b/READMEs/README.tr-TR.md index c14c913a4e..d63800b318 100644 --- a/READMEs/README.tr-TR.md +++ b/READMEs/README.tr-TR.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1437,7 +1437,7 @@ fi | Prometheus / Grafana | iii OTEL + health monitor | | Custom eklenti sistemleri | `iii worker add ` | -**225 kaynak dosya · ~54,000 LOC · 2,600+ test · 312 fonksiyon · 66 KV scope**, hepsi üç primitif üzerinde. `agentmemory plugin install` yok. Eklenti sistemi, iii'nin kendisidir. +**225 kaynak dosya · ~54,000 LOC · 2,800+ test · 312 fonksiyon · 66 KV scope**, hepsi üç primitif üzerinde. `agentmemory plugin install` yok. Eklenti sistemi, iii'nin kendisidir. --- @@ -1861,7 +1861,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.uk-UA.md b/READMEs/README.uk-UA.md index df7b118ce6..03931035e9 100644 --- a/READMEs/README.uk-UA.md +++ b/READMEs/README.uk-UA.md @@ -71,7 +71,7 @@ 54 інструменти MCP 12 автоматичних хуків 0 зовнішніх БД - 2,600+ тестів пройдено + 2,800+ тестів пройдено

@@ -1447,7 +1447,7 @@ fi | Prometheus / Grafana | iii OTEL + монітор стану здоров'я | | Власні системи плагінів | `iii worker add ` | -**225 вихідних файлів · ~54,000 LOC · 2,600+ тестів · 312 функцій · 66 KV-скоупів**, усе на трьох примітивах. Жодного `agentmemory plugin install`. Система плагінів — це сам iii. +**225 вихідних файлів · ~54,000 LOC · 2,800+ тестів · 312 функцій · 66 KV-скоупів**, усе на трьох примітивах. Жодного `agentmemory plugin install`. Система плагінів — це сам iii. --- @@ -1871,7 +1871,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.ur-PK.md b/READMEs/README.ur-PK.md index 9fd55e9fa1..5fbc628b97 100644 --- a/READMEs/README.ur-PK.md +++ b/READMEs/README.ur-PK.md @@ -73,7 +73,7 @@ 54 MCP ٹولز 12 خودکار ہکس 0 خارجی ڈیٹابیسز - 2,600+ ٹیسٹس پاس ہو رہے ہیں + 2,800+ ٹیسٹس پاس ہو رہے ہیں

@@ -1432,7 +1432,7 @@ fi | Prometheus / Grafana | iii OTEL + health monitor | | کسٹم plugin سسٹمز | `iii worker add ` | -**225 سورس فائلز · ~54,000 لائنز کوڈ · 2,600+ ٹیسٹس · 312 فنکشنز · 66 KV اسکوپس**، سب تین primitives پر۔ کوئی `agentmemory plugin install` نہیں۔ plugin سسٹم خود iii ہی ہے۔ +**225 سورس فائلز · ~54,000 لائنز کوڈ · 2,800+ ٹیسٹس · 312 فنکشنز · 66 KV اسکوپس**، سب تین primitives پر۔ کوئی `agentmemory plugin install` نہیں۔ plugin سسٹم خود iii ہی ہے۔ --- @@ -1854,7 +1854,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.vi-VN.md b/READMEs/README.vi-VN.md index ce5d3d0017..f84285f5fa 100644 --- a/READMEs/README.vi-VN.md +++ b/READMEs/README.vi-VN.md @@ -71,7 +71,7 @@ 54 MCP tools 12 auto hooks 0 external DBs - 2,600+ tests passing + 2,800+ tests passing

@@ -1437,7 +1437,7 @@ fi | Prometheus / Grafana | iii OTEL + health monitor | | Hệ thống plugin tùy chỉnh | `iii worker add ` | -**225 file source · ~54,000 LOC · 2,600+ test · 312 function · 66 KV scope**, tất cả trên ba primitive. Không có `agentmemory plugin install`. Hệ thống plugin chính là iii. +**225 file source · ~54,000 LOC · 2,800+ test · 312 function · 66 KV scope**, tất cả trên ba primitive. Không có `agentmemory plugin install`. Hệ thống plugin chính là iii. --- @@ -1861,7 +1861,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.zh-CN.md b/READMEs/README.zh-CN.md index e0eb97c89b..6666d4b597 100644 --- a/READMEs/README.zh-CN.md +++ b/READMEs/README.zh-CN.md @@ -71,7 +71,7 @@ 54 个 MCP 工具 12 个自动 hooks 0 个外部数据库 - 2,600+ 项测试通过 + 2,800+ 项测试通过

@@ -1444,7 +1444,7 @@ fi | Prometheus / Grafana | iii OTEL + 健康监控 | | Custom plugin systems | `iii worker add ` | -**225 个源文件 · ~54,000 行代码 · 2,600+ 个测试 · 312 个函数 · 66 个 KV 作用域**,全部基于三种原语。没有 `agentmemory plugin install`。插件系统就是 iii 本身。 +**225 个源文件 · ~54,000 行代码 · 2,800+ 个测试 · 312 个函数 · 66 个 KV 作用域**,全部基于三种原语。没有 `agentmemory plugin install`。插件系统就是 iii 本身。 --- @@ -1868,7 +1868,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/READMEs/README.zh-TW.md b/READMEs/README.zh-TW.md index 45b6585f9f..e8c1e4db4f 100644 --- a/READMEs/README.zh-TW.md +++ b/READMEs/README.zh-TW.md @@ -71,7 +71,7 @@ 54 個 MCP 工具 12 個自動 hooks 0 個外部資料庫 - 2,600+ 測試通過 + 2,800+ 測試通過

@@ -1430,7 +1430,7 @@ fi | Prometheus / Grafana | iii OTEL + 健康監控 | | 自訂外掛系統 | `iii worker add ` | -**225 個原始檔 · ~54,000 行程式碼 · 2,600+ 測試 · 312 個函式 · 66 個 KV 範圍**,全部基於三種原語。沒有 `agentmemory plugin install`。外掛系統就是 iii 本身。 +**225 個原始檔 · ~54,000 行程式碼 · 2,800+ 測試 · 312 個函式 · 66 個 KV 範圍**,全部基於三種原語。沒有 `agentmemory plugin install`。外掛系統就是 iii 本身。 --- @@ -1854,7 +1854,7 @@ curl -X POST http://localhost:3111/agentmemory/graph/compact -H "Content-Type: a ```bash npm run dev # Hot reload npm run build # Production build -npm test # 2,600+ tests +npm test # 2,800+ tests npm run test:integration # API tests (requires running services) ``` diff --git a/assets/tags/light/stat-tests.svg b/assets/tags/light/stat-tests.svg index 4dfe9de336..5b4ee4167f 100644 --- a/assets/tags/light/stat-tests.svg +++ b/assets/tags/light/stat-tests.svg @@ -1,5 +1,5 @@ - + - 2600+ + 2800+ TESTS PASSING diff --git a/assets/tags/stat-tests.svg b/assets/tags/stat-tests.svg index b704fbe706..b65aceffb1 100644 --- a/assets/tags/stat-tests.svg +++ b/assets/tags/stat-tests.svg @@ -1,5 +1,5 @@ - + - 2600+ + 2800+ TESTS PASSING diff --git a/docs/reliability/2026-11-01-upstream-review.md b/docs/reliability/2026-11-01-upstream-review.md new file mode 100644 index 0000000000..9a03e69493 --- /dev/null +++ b/docs/reliability/2026-11-01-upstream-review.md @@ -0,0 +1,55 @@ +# AgentMemory upstream comparison + +Keep the fork for now. Port the independent safety fixes first, then evaluate a return to upstream in a separate migration exercise. + +This review compares [the fork at 823df5d](https://github.com/davidrobertson/agentmemory/commit/823df5dad042d35b78aa9332de1e3597ac7d32d6) with [official upstream at c6c476d](https://github.com/rohitg00/agentmemory/commit/c6c476d2905926727fa5848a134d7a3b38a7fa98). GitHub identifies `rohitg00/agentmemory` as the parent of `davidrobertson/agentmemory`. The fork has 44 commits absent from upstream, and upstream has 65 absent from the fork. Both revisions use Apache-2.0 and have identical `LICENSE` files. + +## Why retain the fork + +Several fork behaviors remain distinct at these revisions. + +- `src/functions/file-index.ts` uses `selectSessions` to reject partial or null session rows before filtering and applying the history cap. Upstream still sorts raw rows. Fork PR #11 fixed a real file-history failure. +- `src/functions/context.ts` includes selected durable memories in automatic context. Upstream has improved explicit durable-memory search and expansion, but its context path loads slots, profiles, and lessons without this collection. +- `src/hooks/_env.ts` hydrates hook settings from the environment file. The fork also gates pre-compact context explicitly and retains captures when worker routes return 404 during restarts. +- The fork has deliberate bounded graph writes, sharded graph indexes, and serialized viewer refreshes. Upstream also has side indexes, but its generation-scoped graph design differs. These paths need behavioral parity checks before replacement. + +Upstream commit [36bdbe9](https://github.com/rohitg00/agentmemory/commit/36bdbe9) moves the engine and SDK from iii 0.22.1 to 0.25.0. It changes CLI lifecycle management to Worker Compose and moves viewer live updates to authenticated SSE. Its upgrade guide requires stopping the old runtime and preserving its data and credentials. This is an operational migration, not a routine dependency bump. + +Upstream commit [857cf1b](https://github.com/rohitg00/agentmemory/commit/857cf1b) also introduces generation-scoped graph indexes and an explicit legacy scan. Upstream documents that initial discovery is unbounded. Graph retrieval reports `needs-migration` until an operator runs `graph-index migrate --allow-legacy-scan`. The review did not establish compatibility with the fork's sharded canonical graph records. + +Keeping the fork has a cost. The two histories now differ across retrieval, capture, graph storage, and lifecycle management. Selective ports will need adaptation and regression tests. The preferred long-term direction is upstream once the remaining fork guarantees are either accepted upstream or demonstrated equivalent with an isolated installed-runtime test. + +## First ports + +| Upstream change | Decision | Reason | +| --- | --- | --- | +| [1c99508](https://github.com/rohitg00/agentmemory/commit/1c99508), import preflight | Port | Optional section shapes, keyed rows, and access-log limits must fail before a replace import deletes existing state. Preserve the fork's source budgets and graph representation. | +| [35813c5](https://github.com/rohitg00/agentmemory/commit/35813c5), identifier redaction boundaries | Port | Preserve ordinary identifiers containing key-like substrings while still redacting credentials. | +| [ea2f629](https://github.com/rohitg00/agentmemory/commit/ea2f629), structured redaction | Port capture paths | Scrubbing serialized JSON can break parsing. The fork's spool fallback then returns the original body. Recursively scrub values and collision-safe property names after JSON normalization. The unrelated vector-recovery gate edit is outside this port. | +| [72e1266](https://github.com/rohitg00/agentmemory/commit/72e1266), hook event identities | Port | Upstream reports shared prompt IDs across Claude hook events. Tests reproduce collisions for distinct subagents, tasks, and notification content. Preserve retry deduplication; identical notifications from one agent in one prompt still share an ID. | + +The existing import payload, structured JSON capture body, and `ObserveBody` event payload remain the organizing data structures. These ports reuse upstream's settled behavior and the fork's boundaries. They do not introduce a new runtime architecture. + +## Remaining upstream changes + +The other commits fall into these groups. Deferral means the change is valuable but is outside the first safety port. + +| Group and examples | Decision | Reason | +| --- | --- | --- | +| Durable search, project scoping, bounded retrieval, and token budgets, including 5a0db22, 9caace6, 9d70369, da91cc0, 6a182c4 | Evaluate next | Upstream improves linked-session scope checks, graph scores, and large-result handling. Adapt these to the fork's durable ranking, automatic context selection, and side indexes. | +| Write ordering, graph consistency, compression recovery, vector recovery, session finalization, and reflection, including a5e036c, 062159c, d9a20da, 7bf9c53, df3d4a8, 6a2b35a | Separate reliability work | These touch shared state, recovery checkpoints, or background processing. They need focused concurrency and recovery evidence. | +| Worker Compose, SSE, graph migrations, deployment changes, engine startup, diagnostics, and 0.9.31 release preparation | Separate migration | Validate installed capture, recall, hooks, auth, graph reads, restart recovery, and viewer behavior on isolated synthetic state before any deployment. | +| Linked-worktree projects and Claude transcript backfill, e37c6a7 and 0b3515d | Defer | Worktree canonicalization changes future project names without moving historical records. Transcript capture needs the fork's bounded shutdown and spool tests. | +| Hermes and OpenClaw hardening, c17874a | Separate integration review | Newer scoped credentials and profile isolation must retain custom data-directory behavior. | +| Local MCP fallback notices, 5f44085 | Defer | Adapt notices while preserving the fork's fail-closed configured-server behavior. | +| MCP stdout routing, e6d5136 | Skip the logging change | The fork already protects MCP stdout by sending all routine logs to stderr. Upstream also changes non-error logging outside MCP to stdout; this port leaves the fork's logging policy intact. | +| Exact MCP shim version, c554973 | Already covered | The fork's shim already pins its runtime release. | +| Cursor, Cline, Devin, dsh, pi and Oh My Pi integrations; skills-only Codex packaging | Defer optional integrations | These do not resolve the first safety issues. The skills-only Codex ZIP is an additional package flavor, not a reason to remove the fork's existing MCP packaging. | +| Import session limits and JSONL idempotence, export pagination, action pagination, facet cleanup, provider reporting and warnings | Follow-on correctness review | Useful independent fixes, but each needs its own boundary and compatibility checks. | +| Documentation, website, benchmark presentation, release publication and provenance | Defer to release or documentation work | Preserve review focus. No package publication is part of this PR. | + +## Verification boundary + +The regression tests exercise rejected imports against seeded in-memory state, structured capture and local spool files, and hook subprocess requests to isolated test servers. Generated plugin scripts must match source hooks. The repository's build, skill generation, documentation synchronization, skill checks, and test suite are required before commit. + +This PR does not verify an iii 0.25 migration or install a new runtime. The existing service, memory data, repository settings, and release versions remain outside the execution scope. diff --git a/plugin/scripts/_capture.mjs b/plugin/scripts/_capture.mjs index 07ac049ebd..8b062674ac 100644 --- a/plugin/scripts/_capture.mjs +++ b/plugin/scripts/_capture.mjs @@ -256,9 +256,9 @@ const PRIVATE_TAG_RE = /[\s\S]*?<\/private>/gi; const SECRET_PATTERN_SOURCES = [ /(?:api[_-]?key|secret|token|password|credential|auth)[\s]*[=:]\s*["']?[A-Za-z0-9_\-/.+]{20,}["']?/gi, /Bearer\s+[A-Za-z0-9._\-+/=]{20,}/gi, - /sk-proj-[A-Za-z0-9\-_]{20,}/g, - /(?:sk|pk|rk|ak)-[A-Za-z0-9][A-Za-z0-9\-_]{19,}/g, - /sk-ant-[A-Za-z0-9\-_]{20,}/g, + /(? scrubRecord(item, options)); + if (value !== null && typeof value === "object") { + const proto = Object.getPrototypeOf(value); + if (proto !== Object.prototype && proto !== null) return value; + const entries = Object.entries(value).map(([key, item]) => [options.scrubKeys ? stripPrivateData(key) : key, item]); + const reserved = new Set(entries.map(([key]) => key)); + const used = /* @__PURE__ */ new Set(); + return Object.fromEntries(entries.map(([key, item]) => { + let unique = key; + if (used.has(unique)) { + let suffix = 2; + do + unique = `${key}_${suffix++}`; + while (reserved.has(unique) || used.has(unique)); + } + used.add(unique); + return [unique, scrubRecord(item, options)]; + })); + } + return value; +} //#endregion //#region src/capture/spool.ts const DEFAULT_MAX_BYTES = 5 * 1024 * 1024; @@ -426,13 +449,6 @@ function fileSize(path) { return 0; } } -function sanitizeBody(body) { - try { - return JSON.parse(stripPrivateData(JSON.stringify(body))); - } catch { - return body; - } -} function withoutImage(body) { const data = body["data"]; if (!data || typeof data !== "object" || Array.isArray(data)) return body; @@ -518,7 +534,7 @@ function appendSpool(url, eventId, body, reason, options = {}) { spooledAt: (/* @__PURE__ */ new Date()).toISOString(), reason, attempts: options.attempts ?? 0, - body: sanitizeBody(body) + body: scrubRecord(JSON.parse(JSON.stringify(body)), { scrubKeys: true }) }; let line = JSON.stringify(record) + "\n"; if (Buffer.byteLength(line) > policy.maxRecordBytes) { @@ -618,7 +634,7 @@ function retainSent(url, eventId, body, mark, options = {}) { spooledAt: new Date(now).toISOString(), reason: "sent", attempts: 0, - body: sanitizeBody(body), + body: scrubRecord(JSON.parse(JSON.stringify(body)), { scrubKeys: true }), bootId: mark.bootId }; let line = JSON.stringify(record) + "\n"; diff --git a/plugin/scripts/notification.mjs b/plugin/scripts/notification.mjs index 74f659df5b..292a3e9f19 100755 --- a/plugin/scripts/notification.mjs +++ b/plugin/scripts/notification.mjs @@ -99,7 +99,8 @@ async function main() { ].find((v) => typeof v === "string" && v.length > 0); const sessionId = typeof rawSessionId === "string" ? rawSessionId : "unknown"; const cwd = hookCwd(data) || process.cwd(); - captureObservation(withEventId({ + const promptId = [data.prompt_id, data.promptId].find((v) => typeof v === "string" && v.length > 0); + const body = { hookType: "notification", sessionId, project: resolveProject(cwd), @@ -110,7 +111,12 @@ async function main() { title: data.title, message: data.message } - }, data), OBSERVE_TIMEOUT_MS); + }; + captureObservation(withEventId(body, {}, { + ...body.data, + prompt_id: promptId, + agent_id: data.agent_id + }, { stable: promptId !== void 0 }), OBSERVE_TIMEOUT_MS); setTimeout(() => process.exit(0), EXIT_CAP_MS).unref(); } main().catch(() => process.exit(0)); diff --git a/plugin/scripts/subagent-start.mjs b/plugin/scripts/subagent-start.mjs index 187f241d0c..976cb51376 100755 --- a/plugin/scripts/subagent-start.mjs +++ b/plugin/scripts/subagent-start.mjs @@ -104,7 +104,7 @@ async function main() { agent_id: agentId, agent_type: agentType } - }, data), OBSERVE_TIMEOUT_MS); + }, {}, void 0, { stable: Boolean(data.agent_id) }), OBSERVE_TIMEOUT_MS); setTimeout(() => process.exit(0), EXIT_CAP_MS).unref(); } main().catch(() => process.exit(0)); diff --git a/plugin/scripts/subagent-stop.mjs b/plugin/scripts/subagent-stop.mjs index 917890d0f1..4101ed98f7 100755 --- a/plugin/scripts/subagent-stop.mjs +++ b/plugin/scripts/subagent-stop.mjs @@ -95,7 +95,7 @@ async function main() { const agentType = data.agent_type || data.agentDisplayName || data.agentName; const lastMsg = typeof data.last_assistant_message === "string" ? data.last_assistant_message.slice(0, 4e3) : ""; const cwd = hookCwd(data) || process.cwd(); - captureObservation(withEventId({ + const body = { hookType: "subagent_stop", sessionId, project: resolveProject(cwd), @@ -106,7 +106,11 @@ async function main() { agent_type: agentType, last_message: lastMsg } - }, data), OBSERVE_TIMEOUT_MS); + }; + captureObservation(withEventId(body, {}, { + ...body.data, + stop_hook_active: data.stop_hook_active === true + }, { stable: Boolean(data.agent_id) }), OBSERVE_TIMEOUT_MS); setTimeout(() => process.exit(0), EXIT_CAP_MS).unref(); } main().catch(() => process.exit(0)); diff --git a/plugin/scripts/task-completed.mjs b/plugin/scripts/task-completed.mjs index 149131cc3c..95d6329c91 100755 --- a/plugin/scripts/task-completed.mjs +++ b/plugin/scripts/task-completed.mjs @@ -105,7 +105,7 @@ async function main() { teammate_name: data.teammate_name, team_name: data.team_name } - }, data), OBSERVE_TIMEOUT_MS); + }, {}, void 0, { stable: Boolean(data.task_id) }), OBSERVE_TIMEOUT_MS); setTimeout(() => process.exit(0), EXIT_CAP_MS).unref(); } main().catch(() => process.exit(0)); diff --git a/scripts/docs-sync.state.json b/scripts/docs-sync.state.json index 9e6bf41473..0f1231975b 100644 --- a/scripts/docs-sync.state.json +++ b/scripts/docs-sync.state.json @@ -20,7 +20,7 @@ "12" ], "tests": [ - "2600+" + "2800+" ], "functions": [ "312" diff --git a/src/capture/spool.ts b/src/capture/spool.ts index 5b71b4a82a..4c9a66bc27 100644 --- a/src/capture/spool.ts +++ b/src/capture/spool.ts @@ -16,7 +16,7 @@ import { } from "node:fs"; import { join, resolve } from "node:path"; import { resolveDataDir } from "../cli-data-dir.js"; -import { stripPrivateData } from "../functions/privacy.js"; +import { scrubRecord } from "../functions/privacy.js"; export interface SpoolRecord { v: 1; @@ -239,14 +239,6 @@ function fileSize(path: string): number { } } -function sanitizeBody(body: Record): Record { - try { - return JSON.parse(stripPrivateData(JSON.stringify(body))) as Record; - } catch { - return body; - } -} - function withoutImage(body: Record): Record { const data = body["data"]; if (!data || typeof data !== "object" || Array.isArray(data)) return body; @@ -334,7 +326,7 @@ export function appendSpool( spooledAt: new Date().toISOString(), reason, attempts: options.attempts ?? 0, - body: sanitizeBody(body), + body: scrubRecord(JSON.parse(JSON.stringify(body)), { scrubKeys: true }), }; let line = JSON.stringify(record) + "\n"; if (Buffer.byteLength(line) > policy.maxRecordBytes) { @@ -441,7 +433,7 @@ export function retainSent( spooledAt: new Date(now).toISOString(), reason: "sent", attempts: 0, - body: sanitizeBody(body), + body: scrubRecord(JSON.parse(JSON.stringify(body)), { scrubKeys: true }), bootId: mark.bootId, }; let line = JSON.stringify(record) + "\n"; diff --git a/src/functions/export-import.ts b/src/functions/export-import.ts index ef0110a8c5..75f97c090d 100644 --- a/src/functions/export-import.ts +++ b/src/functions/export-import.ts @@ -70,7 +70,7 @@ async function runChunked( const EXPORT_OVERSIZE_HINT = "narrow the range with ?maxSessions / ?offset, or export fewer collections; the non-session collections (memories, graph, semantic, actions, lessons, ...) are not yet paginated"; -const EXPORT_COLLECTIONS: ReadonlyArray = [ +const EXPORT_COLLECTIONS = [ ["graphNodes", KV.graphNodes], ["graphEdges", KV.graphEdges], ["semanticMemories", KV.semantic], @@ -87,7 +87,7 @@ const EXPORT_COLLECTIONS: ReadonlyArray = [ ["signals", KV.signals], ["checkpoints", KV.checkpoints], ["accessLogs", KV.accessLog], -]; +] satisfies ReadonlyArray; export class ExportBudget { bytes = 0; @@ -286,8 +286,15 @@ export function registerExportImportFunction(sdk: IIIClient, kv: StateKV): void }; } + const invalidRowIndex = (rows: readonly unknown[], key: string) => + rows.findIndex((row) => { + const id: unknown = row !== null && typeof row === "object" && !Array.isArray(row) + ? Reflect.get(row, key) + : undefined; + return typeof id !== "string" || id.length === 0; + }); let totalObservations = 0; - for (const [, obs] of Object.entries(importData.observations)) { + for (const [sessionId, obs] of Object.entries(importData.observations)) { if (!Array.isArray(obs)) { return { success: false, error: "observation values must be arrays" }; } @@ -297,6 +304,10 @@ export function registerExportImportFunction(sdk: IIIClient, kv: StateKV): void error: `Too many observations per session (max ${MAX_OBS_PER_SESSION})`, }; } + const index = invalidRowIndex(obs, "id"); + if (index >= 0) { + return { success: false, error: `observations.${sessionId}[${index}] must be an object with a string id` }; + } totalObservations += obs.length; } if (totalObservations > MAX_TOTAL_OBSERVATIONS) { @@ -306,6 +317,27 @@ export function registerExportImportFunction(sdk: IIIClient, kv: StateKV): void }; } + const rowKeys: Partial> = { + summaries: "sessionId", profiles: "project", accessLogs: "memoryId", + }; + for (const section of ["sessions", "memories", "summaries", "profiles", ...EXPORT_COLLECTIONS.map(([field]) => field)] as const) { + const rows = importData[section]; + if (rows !== undefined && !Array.isArray(rows)) { + return { success: false, error: `${section} must be an array` }; + } + const key = rowKeys[section] ?? "id"; + const index = invalidRowIndex(rows ?? [], key); + if (index >= 0) { + return { success: false, error: `${section}[${index}] must be an object with a string ${key}` }; + } + } + if ((importData.accessLogs?.length ?? 0) > MAX_ACCESS_LOGS) { + return { + success: false, + error: `Too many access logs (max ${MAX_ACCESS_LOGS})`, + }; + } + const stats = { sessions: 0, observations: 0, @@ -673,15 +705,6 @@ export function registerExportImportFunction(sdk: IIIClient, kv: StateKV): void }); } if (importData.accessLogs) { - if (!Array.isArray(importData.accessLogs)) { - return { success: false, error: "accessLogs must be an array" }; - } - if (importData.accessLogs.length > MAX_ACCESS_LOGS) { - return { - success: false, - error: `Too many access logs (max ${MAX_ACCESS_LOGS})`, - }; - } const memoryIds = new Set( importData.memories.map((m) => m.id), ); diff --git a/src/functions/observe.ts b/src/functions/observe.ts index 237fd2c719..72379829cf 100644 --- a/src/functions/observe.ts +++ b/src/functions/observe.ts @@ -7,7 +7,7 @@ import { StateKV } from "../state/kv.js"; import { trackViewerStreamItem, pruneViewerStreamIfDue } from "../state/viewer-stream.js"; import { addSessionToProjectIndex } from "../state/session-index.js"; import { indexObservationSession } from "../state/obs-index.js"; -import { stripPrivateData } from "./privacy.js"; +import { scrubRecord } from "./privacy.js"; import { DedupMap, recordDedupSkip } from "./dedup.js"; import { withKeyedLock } from "../state/keyed-mutex.js"; import { isAutoCompressEnabled } from "../config.js"; @@ -120,14 +120,10 @@ export function registerObserveFunction( } } - let sanitizedRaw: unknown = payload.data; - try { - const jsonStr = JSON.stringify(payload.data); - const sanitized = stripPrivateData(jsonStr); - sanitizedRaw = JSON.parse(sanitized); - } catch { - sanitizedRaw = stripPrivateData(String(payload.data)); - } + const serializedData = JSON.stringify(payload.data); + const sanitizedRaw = serializedData === undefined + ? undefined + : scrubRecord(JSON.parse(serializedData), { scrubKeys: true }); let originChannel: Origin["channel"] = "agent"; if (payload.hookType === "prompt_submit") originChannel = "user"; diff --git a/src/functions/privacy.ts b/src/functions/privacy.ts index 538453e9a9..d20cb79254 100644 --- a/src/functions/privacy.ts +++ b/src/functions/privacy.ts @@ -5,9 +5,9 @@ const PRIVATE_TAG_RE = /[\s\S]*?<\/private>/gi; const SECRET_PATTERN_SOURCES = [ /(?:api[_-]?key|secret|token|password|credential|auth)[\s]*[=:]\s*["']?[A-Za-z0-9_\-/.+]{20,}["']?/gi, /Bearer\s+[A-Za-z0-9._\-+/=]{20,}/gi, - /sk-proj-[A-Za-z0-9\-_]{20,}/g, - /(?:sk|pk|rk|ak)-[A-Za-z0-9][A-Za-z0-9\-_]{19,}/g, - /sk-ant-[A-Za-z0-9\-_]{20,}/g, + /(?(value: T): T { +export function scrubRecord(value: T, options: { scrubKeys?: boolean } = {}): T { if (typeof value === "string") return stripPrivateData(value) as T; - if (Array.isArray(value)) return value.map((item) => scrubRecord(item)) as T; + if (Array.isArray(value)) return value.map((item) => scrubRecord(item, options)) as T; if (value !== null && typeof value === "object") { const proto = Object.getPrototypeOf(value); if (proto !== Object.prototype && proto !== null) return value; - const out: Record = {}; - for (const [key, item] of Object.entries(value as Record)) { - out[key] = scrubRecord(item); - } - return out as T; + const entries = Object.entries(value as Record).map(([key, item]) => [ + options.scrubKeys ? stripPrivateData(key) : key, + item, + ] as const); + const reserved = new Set(entries.map(([key]) => key)); + const used = new Set(); + return Object.fromEntries( + entries.map(([key, item]) => { + let unique = key; + if (used.has(unique)) { + let suffix = 2; + do { unique = `${key}_${suffix++}`; } while (reserved.has(unique) || used.has(unique)); + } + used.add(unique); + return [unique, scrubRecord(item, options)]; + }), + ) as T; } return value; } diff --git a/src/hooks/notification.ts b/src/hooks/notification.ts index 53f53d5721..3101df4563 100644 --- a/src/hooks/notification.ts +++ b/src/hooks/notification.ts @@ -38,21 +38,25 @@ async function main() { const cwd = hookCwd(data) || process.cwd(); + const promptId = [data.prompt_id, data.promptId].find((v) => typeof v === "string" && v.length > 0); + const body = { + hookType: "notification", + sessionId, + project: resolveProject(cwd), + cwd, + timestamp: new Date().toISOString(), + data: { + notification_type: notificationType, + title: data.title, + message: data.message, + }, + }; void captureObservation( withEventId( - { - hookType: "notification", - sessionId, - project: resolveProject(cwd), - cwd, - timestamp: new Date().toISOString(), - data: { - notification_type: notificationType, - title: data.title, - message: data.message, - }, - }, - data, + body, + {}, + { ...body.data, prompt_id: promptId, agent_id: data.agent_id }, + { stable: promptId !== undefined }, ), OBSERVE_TIMEOUT_MS, ); diff --git a/src/hooks/subagent-start.ts b/src/hooks/subagent-start.ts index f94b8956b0..028f5714d7 100644 --- a/src/hooks/subagent-start.ts +++ b/src/hooks/subagent-start.ts @@ -50,7 +50,9 @@ async function main() { agent_type: agentType, }, }, - data, + {}, + undefined, + { stable: Boolean(data.agent_id) }, ), OBSERVE_TIMEOUT_MS, ); diff --git a/src/hooks/subagent-stop.ts b/src/hooks/subagent-stop.ts index e2ac8d4000..6181142b5f 100644 --- a/src/hooks/subagent-stop.ts +++ b/src/hooks/subagent-stop.ts @@ -39,21 +39,24 @@ async function main() { const cwd = hookCwd(data) || process.cwd(); + const body = { + hookType: "subagent_stop", + sessionId, + project: resolveProject(cwd), + cwd, + timestamp: new Date().toISOString(), + data: { + agent_id: agentId, + agent_type: agentType, + last_message: lastMsg, + }, + }; void captureObservation( withEventId( - { - hookType: "subagent_stop", - sessionId, - project: resolveProject(cwd), - cwd, - timestamp: new Date().toISOString(), - data: { - agent_id: agentId, - agent_type: agentType, - last_message: lastMsg, - }, - }, - data, + body, + {}, + { ...body.data, stop_hook_active: data.stop_hook_active === true }, + { stable: Boolean(data.agent_id) }, ), OBSERVE_TIMEOUT_MS, ); diff --git a/src/hooks/task-completed.ts b/src/hooks/task-completed.ts index 1c4534f76a..6eca89577f 100644 --- a/src/hooks/task-completed.ts +++ b/src/hooks/task-completed.ts @@ -51,7 +51,9 @@ async function main() { team_name: data.team_name, }, }, - data, + {}, + undefined, + { stable: Boolean(data.task_id) }, ), OBSERVE_TIMEOUT_MS, ); diff --git a/test/capture-redaction.test.ts b/test/capture-redaction.test.ts new file mode 100644 index 0000000000..73c05545a7 --- /dev/null +++ b/test/capture-redaction.test.ts @@ -0,0 +1,207 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { mkdtempSync, readFileSync, readdirSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { appendSpool, retainSent, type SpoolRecord } from "../src/capture/spool.js"; +import { registerObserveFunction } from "../src/functions/observe.js"; +import { KV } from "../src/state/schema.js"; +import { getSearchIndex, setEmbeddingProvider, setVectorIndex } from "../src/functions/search.js"; +import type { CompressedObservation, RawObservation } from "../src/types.js"; +import { mockKV, mockSdk } from "./helpers/mocks.js"; + +vi.mock("../src/logger.js", () => ({ + logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() }, +})); + +const SECRET = "abcdefghijklmnopqrstuvwxyz"; +const PRIVATE_TEXT = "private capture details"; +const NORMAL = { count: 3, ok: true, empty: null, text: "quoted \"text\" and a \\ path\nnext line" }; +class SerializedToolOutput { + toJSON(key: string) { + return { key, [`sk-${SECRET}`]: `password=${SECRET}`, ["__proto__"]: { note: `${PRIVATE_TEXT}` } }; + } +} + +const CASES = [ + { + name: "colliding redacted property names", + data: { nested: [{ [`sk-${SECRET}`]: "first", [`pk-${SECRET}`]: "second", "[REDACTED_SECRET]_2": "ordinary" }] }, + expected: { nested: [{ "[REDACTED_SECRET]": "first", "[REDACTED_SECRET]_3": "second", "[REDACTED_SECRET]_2": "ordinary" }] }, + }, + { + name: "nested URL objects and dates", + data: { tool_name: "Read", tool_input: [{ url: new URL(`https://user:${SECRET}@example.test/path`) }], tool_output: new Date("2026-10-16T00:00:00.000Z") }, + expected: { tool_name: "Read", tool_input: [{ url: "https://[REDACTED_SECRET]@example.test/path" }], tool_output: "2026-10-16T00:00:00.000Z" }, + }, + { + name: "custom JSON representations and boxed strings", + data: { tool_name: "Read", tool_input: new String(`api_key=${SECRET}`), tool_output: new SerializedToolOutput() }, + expected: { tool_name: "Read", tool_input: "[REDACTED_SECRET]", tool_output: { key: "tool_output", "[REDACTED_SECRET]": "[REDACTED_SECRET]", ["__proto__"]: { note: "[REDACTED]" } } }, + }, + { + name: "plain objects with custom JSON representations", + data: { toJSON() { return { tool_name: "Read", tool_output: `api_key=${SECRET}` }; } }, + expected: { tool_name: "Read", tool_output: "[REDACTED_SECRET]" }, + }, + { + name: "undefined payloads", + data: undefined, + expected: undefined, + }, + { + name: "a secret assignment at the end of a string", + data: { tool_name: "Bash", tool_input: { command: "printenv" }, tool_output: `api_key=${SECRET}` }, + expected: { tool_name: "Bash", tool_input: { command: "printenv" }, tool_output: "[REDACTED_SECRET]" }, + }, + { + name: "quoted secrets and private blocks in nested objects and arrays", + data: { + tool_name: "Bash", + tool_input: { command: `password="${SECRET}"`, options: NORMAL }, + tool_output: [ + { message: `before ${PRIVATE_TEXT}\n\"quoted\" after` }, + [`token='${SECRET}'`, "ordinary result", 7, false, null], + ], + }, + expected: { + tool_name: "Bash", + tool_input: { command: "[REDACTED_SECRET]", options: NORMAL }, + tool_output: [ + { message: "before [REDACTED] after" }, + ["[REDACTED_SECRET]", "ordinary result", 7, false, null], + ], + }, + }, + { + name: "an array payload", + data: [`api_key=${SECRET}`, { note: `${PRIVATE_TEXT}`, ...NORMAL }], + expected: ["[REDACTED_SECRET]", { note: "[REDACTED]", ...NORMAL }], + }, + { + name: "ordinary JSON data", + data: { tool_name: "Read", tool_input: { file_path: "src/main.ts" }, tool_output: NORMAL }, + expected: { tool_name: "Read", tool_input: { file_path: "src/main.ts" }, tool_output: NORMAL }, + }, + { + name: "secrets in nested object property names", + data: { + [`sk-${SECRET}`]: "label", + tool_name: "Read", + tool_input: [{ [`${PRIVATE_TEXT}`]: { [`api_key=${SECRET}`]: NORMAL } }], + tool_output: "ordinary result", + }, + expected: { + "[REDACTED_SECRET]": "label", + tool_name: "Read", + tool_input: [{ "[REDACTED]": { "[REDACTED_SECRET]": NORMAL } }], + tool_output: "ordinary result", + }, + }, + { + name: "an own __proto__ JSON field", + data: { tool_name: "Read", tool_input: { ["__proto__"]: { note: `api_key=${SECRET}` } }, tool_output: NORMAL }, + expected: { tool_name: "Read", tool_input: { ["__proto__"]: { note: "[REDACTED_SECRET]" } }, tool_output: NORMAL }, + }, +]; + +function payload(data: unknown) { + return { + hookType: "post_tool_use" as const, + sessionId: "ses_capture_redaction", + project: "redaction-test", + cwd: "/work/redaction-test", + timestamp: "2026-10-16T00:00:00.000Z", + data, + }; +} + +function expectClean(value: unknown): void { + const text = JSON.stringify(value); + expect(text).not.toContain(SECRET); + expect(text).not.toContain(PRIVATE_TEXT); +} + +describe.each(["pending", "retained"] as const)("%s capture spool redaction", (mode) => { + let dir: string; + + beforeEach(() => { + dir = mkdtempSync(join(tmpdir(), "am-capture-redaction-")); + }); + + afterEach(() => { + rmSync(dir, { recursive: true, force: true }); + }); + + it.each(CASES)("preserves structure while scrubbing $name", ({ data, expected }) => { + const body = payload(data); + const before = JSON.stringify(body); + const url = "http://localhost:4811"; + const eventId = "evc_redaction000001"; + if (mode === "pending") { + expect(appendSpool(url, eventId, body, "unreachable", { dir }).spooled).toBe(true); + } else { + expect(retainSent(url, eventId, body, { bootId: "redactionboot001", durableAfterMs: 60_000 }, { dir })).toBe(true); + } + const files = readdirSync(dir).filter((file) => file.endsWith(".jsonl")); + expect(files).toHaveLength(1); + const text = readFileSync(join(dir, files[0]!), "utf-8"); + expectClean(text); + const record = JSON.parse(text.trim()) as SpoolRecord; + expect(record.body).toEqual(JSON.parse(JSON.stringify({ ...payload(expected) }))); + expect(record.eventId).toBe(eventId); + expect(JSON.stringify(body)).toBe(before); + }); +}); + +describe.each(["raw", "synthetic"] as const)("%s observation redaction", (mode) => { + beforeEach(() => { + vi.stubEnv("AGENTMEMORY_AUTO_COMPRESS", mode === "raw" ? "true" : "false"); + getSearchIndex().clear(); + setVectorIndex(null); + setEmbeddingProvider(null); + }); + + afterEach(() => { + vi.unstubAllEnvs(); + }); + + it.each(CASES)("preserves structure while scrubbing $name", async ({ data, expected }) => { + const sdk = mockSdk({ looseTrigger: true }); + const kv = mockKV(); + const stream = vi.fn(async (_data: unknown) => null); + const compress = vi.fn(async (_data: unknown) => null); + sdk.registerFunction("stream::send", stream); + sdk.registerFunction("mem::compress", compress); + registerObserveFunction(sdk as never, kv as never); + const input = payload(data); + const before = JSON.stringify(input); + + const result = await sdk.trigger({ function_id: "mem::observe", payload: input }) as { observationId: string }; + + expect(result.observationId).toBeTruthy(); + const stored = await kv.get(KV.observations(input.sessionId), result.observationId); + const streamed = (stream.mock.calls[0]![0] as { data: { observation: RawObservation } }).data.observation; + expect(streamed.raw).toEqual(expected); + expect(stored).not.toBeNull(); + expect(stored && "raw" in stored).toBe(mode === "raw"); + if (stored && "raw" in stored) { + expect(stored.raw).toEqual(expected); + expect(stored.toolName).toBe(streamed.toolName); + expect(stored.toolInput).toEqual(streamed.toolInput); + expect(stored.toolOutput).toEqual(streamed.toolOutput); + } else if (stored) { + expect(stored.source?.toolName).toBe(streamed.toolName); + expect(stored.source?.toolInput).toEqual(streamed.toolInput); + expect(stored.source?.toolOutput).toEqual(streamed.toolOutput); + if (!streamed.toolName) expect(stored.source?.payload).toEqual(expected); + } + expectClean(stored); + expectClean(streamed); + if (mode === "raw") { + expect(compress).toHaveBeenCalledWith({ observationId: result.observationId, sessionId: input.sessionId, raw: streamed }); + } else { + expect(compress).not.toHaveBeenCalled(); + } + expect(JSON.stringify(input)).toBe(before); + }); +}); diff --git a/test/export-import.test.ts b/test/export-import.test.ts index 8dfe5fbb40..88d3143968 100644 --- a/test/export-import.test.ts +++ b/test/export-import.test.ts @@ -7,6 +7,7 @@ vi.mock("../src/logger.js", () => ({ import { registerExportImportFunction } from "../src/functions/export-import.js"; import { VERSION } from "../src/version.js"; import { getSearchIndex } from "../src/functions/search.js"; +import { KV } from "../src/state/schema.js"; import type { Session, CompressedObservation, @@ -18,6 +19,7 @@ import type { function mockKV() { const store = new Map>(); return { + snapshot: () => structuredClone(store), get: async (scope: string, key: string): Promise => { return (store.get(scope)?.get(key) as T) ?? null; }, @@ -103,6 +105,74 @@ const testSummary: SessionSummary = { observationCount: 1, }; +const optionalImportSections = [ + ["profiles", KV.profiles, "project"], + ["graphNodes", KV.graphNodes, "id"], + ["graphEdges", KV.graphEdges, "id"], + ["semanticMemories", KV.semantic, "id"], + ["proceduralMemories", KV.procedural, "id"], + ["actions", KV.actions, "id"], + ["actionEdges", KV.actionEdges, "id"], + ["routines", KV.routines, "id"], + ["signals", KV.signals, "id"], + ["checkpoints", KV.checkpoints, "id"], + ["sentinels", KV.sentinels, "id"], + ["sketches", KV.sketches, "id"], + ["crystals", KV.crystals, "id"], + ["facets", KV.facets, "id"], + ["lessons", KV.lessons, "id"], + ["insights", KV.insights, "id"], + ["accessLogs", KV.accessLog, "memoryId"], +] as const; + +const importRowKeys = [ + ["sessions", "id"], + ["memories", "id"], + ["summaries", "sessionId"], + ...optionalImportSections.map(([section, , key]) => [section, key]), + ["observations", "id"], +] as const; + +const malformedSections = [ + ...optionalImportSections.map(([section]) => ({ section, shape: "null", value: null })), + { section: "lessons", shape: "an object", value: {} }, + { section: "profiles", shape: "a string", value: "oops" }, + { section: "accessLogs", shape: "a string", value: "oops" }, + { section: "graphNodes", shape: "false", value: false }, +]; + +const malformedRows = [ + ...importRowKeys.map(([section, key]) => ({ section, key, shape: "without its key", value: {} })), + ...[ + ["lessons", "id"], + ["summaries", "sessionId"], + ["profiles", "project"], + ["accessLogs", "memoryId"], + ].flatMap(([section, key]) => [ + { section, key, shape: "null", value: null }, + { section, key, shape: "with an empty key", value: { [key]: "" } }, + { section, key, shape: "with a numeric key", value: { [key]: 1 } }, + ]), + { section: "facets", key: "id", shape: "null", value: null }, + { section: "memories", key: "id", shape: "null", value: null }, +]; + +const sectionPreflightCases = [ + ...malformedSections.map((testCase) => ({ ...testCase, strategy: "replace" })), + ...["merge", "skip"].flatMap((strategy) => [ + { section: "lessons", shape: "null", value: null, strategy }, + { section: "accessLogs", shape: "a string", value: "oops", strategy }, + ]), +]; + +const rowPreflightCases = [ + ...malformedRows.map((testCase) => ({ ...testCase, strategy: "replace" })), + ...["merge", "skip"].flatMap((strategy) => [ + { section: "profiles", key: "project", shape: "without its key", value: {}, strategy }, + { section: "observations", key: "id", shape: "null", value: null, strategy }, + ]), +]; + describe("Export/Import Functions", () => { let sdk: ReturnType; let kv: ReturnType; @@ -260,6 +330,70 @@ describe("Export/Import Functions", () => { expect(oldSession).toBeNull(); }); + describe("import preflight", () => { + let incoming: ExportData; + + beforeEach(async () => { + for (const [section, scope, key] of optionalImportSections) { + await kv.set(scope, `existing-${section}`, { [key]: `existing-${section}` }); + } + incoming = { + version: VERSION, + exportedAt: "2026-11-01T00:00:00Z", + sessions: [{ ...testSession, id: "ses_incoming" }], + observations: { + ses_incoming: [{ ...testObs, id: "obs_incoming", sessionId: "ses_incoming" }], + }, + memories: [{ ...testMemory, id: "mem_incoming" }], + summaries: [{ ...testSummary, sessionId: "ses_incoming" }], + }; + }); + + it.each(sectionPreflightCases)("$strategy rejects $section as $shape before any writes", async ({ section, value, strategy }) => { + const before = kv.snapshot(); + const result = await sdk.trigger("mem::import", { + exportData: { ...incoming, [section]: value }, + strategy, + }).catch((error: unknown) => error); + + expect.soft(result).toMatchObject({ success: false, error: `${section} must be an array` }); + expect(kv.snapshot()).toEqual(before); + }); + + it.each(rowPreflightCases)("$strategy rejects a $section row $shape before any writes", async ({ section, key, value, strategy }) => { + const before = kv.snapshot(); + const rows = [{ id: "valid", sessionId: "valid", project: "valid", memoryId: "valid" }, value]; + const result = await sdk.trigger("mem::import", { + exportData: { + ...incoming, + [section]: section === "observations" ? { ses_incoming: rows } : rows, + }, + strategy, + }).catch((error: unknown) => error); + + const location = section === "observations" ? "observations.ses_incoming" : section; + expect.soft(result).toMatchObject({ + success: false, + error: `${location}[1] must be an object with a string ${key}`, + }); + expect(kv.snapshot()).toEqual(before); + }); + + it.each(["replace", "merge", "skip"])("%s rejects access logs above the cap before any writes", async (strategy) => { + const before = kv.snapshot(); + const result = await sdk.trigger("mem::import", { + exportData: { + ...incoming, + accessLogs: Array.from({ length: 50_001 }, () => ({ memoryId: "mem_incoming" })), + }, + strategy, + }); + + expect.soft(result).toMatchObject({ success: false, error: "Too many access logs (max 50000)" }); + expect(kv.snapshot()).toEqual(before); + }); + }); + it("export then import round-trip preserves data", async () => { const exported = (await sdk.trigger("mem::export", {})) as ExportData; diff --git a/test/hook-event-ids.test.ts b/test/hook-event-ids.test.ts new file mode 100644 index 0000000000..5e3cde9c86 --- /dev/null +++ b/test/hook-event-ids.test.ts @@ -0,0 +1,210 @@ +import { describe, it, expect, vi, beforeAll, afterAll } from "vitest"; +import { spawn } from "node:child_process"; +import { createServer, type Server } from "node:http"; +import { mkdtempSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { mockKV, mockSdk } from "./helpers/mocks.js"; +import { KV } from "../src/state/schema.js"; + +vi.mock("../src/logger.js", () => ({ + logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() }, +})); + +const HOOKS_DIR = join(import.meta.dirname, "..", "plugin", "scripts"); +const SESSION = "ses_hook_ids"; + +const turn = { + session_id: SESSION, + prompt_id: "6f1c2a4e-0b7d-4c22-9e83-5a4b3c2d1e0f", + transcript_path: `/home/u/.claude/projects/p/${SESSION}.jsonl`, + cwd: "/work/hook-ids", +}; + +function subagentStop(agentId: string, message: string, extra: Record = {}) { + return { + ...turn, + hook_event_name: "SubagentStop", + stop_hook_active: false, + agent_id: agentId, + agent_type: "Explore", + agent_transcript_path: `/home/u/.claude/projects/p/${SESSION}/subagents/agent-${agentId}.jsonl`, + last_assistant_message: message, + ...extra, + }; +} + +function subagentStart(agentId: string) { + return { ...turn, hook_event_name: "SubagentStart", agent_id: agentId, agent_type: "Explore" }; +} + +function taskCompleted(taskId: string, subject: string) { + return { ...turn, hook_event_name: "TaskCompleted", task_id: taskId, task_subject: subject }; +} + +function permissionPrompt(message: string) { + return { ...turn, hook_event_name: "Notification", notification_type: "permission_prompt", title: "Permission needed", message }; +} + +describe("hook event ids for distinct events under one prompt", () => { + let server: Server; + let received: Array>; + let env: Record; + + beforeAll(async () => { + received = []; + server = createServer((req, res) => { + let raw = ""; + req.on("data", (c) => (raw += c)); + req.on("end", () => { + try { + received.push(JSON.parse(raw)); + } catch {} + res.writeHead(201, { "content-type": "application/json" }); + res.end(JSON.stringify({ status: "accepted" })); + }); + }); + await new Promise((resolve) => server.listen(0, "127.0.0.1", () => resolve())); + const addr = server.address(); + const port = typeof addr === "object" && addr ? addr.port : 0; + const home = mkdtempSync(join(tmpdir(), "am-hook-ids-")); + env = { + PATH: process.env["PATH"] ?? "", + HOME: home, + AGENTMEMORY_URL: `http://127.0.0.1:${port}`, + AGENTMEMORY_CAPTURE_SPOOL_DIR: join(home, "spool"), + }; + }); + + afterAll(async () => { + await new Promise((resolve) => server.close(() => resolve())); + }); + + async function send(script: string, payload: Record): Promise> { + const before = received.length; + await new Promise((resolve, reject) => { + const child = spawn(process.execPath, [join(HOOKS_DIR, script)], { env, stdio: ["pipe", "ignore", "ignore"] }); + child.on("error", reject); + child.on("close", () => resolve()); + child.stdin.end(JSON.stringify(payload)); + }); + expect(received).toHaveLength(before + 1); + return received[received.length - 1]!; + } + + it("gives two subagents that stop in the same prompt different ids", async () => { + const a = await send("subagent-stop.mjs", subagentStop("a1c4e7f0b2d5a8c13", "Done")); + const b = await send("subagent-stop.mjs", subagentStop("b9d2f5a8c1e4b7d06", "Done")); + expect(a.eventId).not.toBe(b.eventId); + }); + + it("gives two subagents that start in the same prompt different ids", async () => { + const a = await send("subagent-start.mjs", subagentStart("a1c4e7f0b2d5a8c13")); + const b = await send("subagent-start.mjs", subagentStart("b9d2f5a8c1e4b7d06")); + expect(a.eventId).not.toBe(b.eventId); + }); + + it("gives two tasks completed in the same prompt different ids", async () => { + const a = await send("task-completed.mjs", taskCompleted("task-001", "Add the endpoint")); + const b = await send("task-completed.mjs", taskCompleted("task-002", "Add the endpoint")); + expect(a.eventId).not.toBe(b.eventId); + }); + + it("gives two permission prompts in the same prompt different ids", async () => { + const a = await send("notification.mjs", permissionPrompt("Claude needs your permission to use Bash")); + const b = await send("notification.mjs", permissionPrompt("Claude needs your permission to use Edit")); + expect(a.eventId).not.toBe(b.eventId); + }); + + it("gives the same permission prompt from two subagents different ids", async () => { + const message = "Claude needs your permission to use Bash"; + const a = await send("notification.mjs", { ...permissionPrompt(message), agent_id: "a1c4e7f0b2d5a8c13" }); + const b = await send("notification.mjs", { ...permissionPrompt(message), agent_id: "b9d2f5a8c1e4b7d06" }); + expect(a.eventId).not.toBe(b.eventId); + }); + + it("gives the same permission prompt in two prompts different ids", async () => { + const message = "Claude needs your permission to use Bash"; + const a = await send("notification.mjs", permissionPrompt(message)); + const b = await send("notification.mjs", { ...permissionPrompt(message), prompt_id: "9d3e5b7a-1c2f-4e6a-8b0d-2f4a6c8e0b1d" }); + expect(a.eventId).not.toBe(b.eventId); + }); + + it("keeps permission prompts apart when the host sends no prompt id", async () => { + const { prompt_id: _omit, ...payload } = permissionPrompt("Claude needs your permission to use Bash"); + const a = await send("notification.mjs", payload); + const b = await send("notification.mjs", payload); + expect(a.eventId).not.toBe(b.eventId); + }); + + it("keeps one id when the same subagent, task or permission event is delivered twice", async () => { + for (const [script, payload] of [ + ["subagent-stop.mjs", subagentStop("c3e6a9d2f5b8c1e47", "Done")], + ["subagent-start.mjs", subagentStart("c3e6a9d2f5b8c1e47")], + ["task-completed.mjs", taskCompleted("task-003", "Write the migration")], + ["notification.mjs", permissionPrompt("Claude needs your permission to use Write")], + ] as const) { + const first = await send(script, payload); + const again = await send(script, payload); + expect(again.eventId).toBe(first.eventId); + } + }); + + it("keeps subagents without a host agent id apart even when their reports match", async () => { + const payload = { sessionId: SESSION, cwd: turn.cwd, agentName: "explore", last_assistant_message: "Done" }; + const a = await send("subagent-stop.mjs", payload); + const b = await send("subagent-stop.mjs", payload); + expect(a.eventId).not.toBe(b.eventId); + }); + + it("keeps subagent starts and tasks without a host id apart", async () => { + for (const [script, payload] of [ + ["subagent-start.mjs", { sessionId: SESSION, cwd: turn.cwd, agentName: "explore" }], + ["task-completed.mjs", { sessionId: SESSION, cwd: turn.cwd, task_subject: "Write the migration" }], + ] as const) { + const a = await send(script, payload); + const b = await send(script, payload); + expect(a.eventId, script).not.toBe(b.eventId); + } + }); + + it("gives a subagent that stops again after a blocking stop hook a new id", async () => { + const first = await send("subagent-stop.mjs", subagentStop("d4f7b0e3a6c9d2f58", "Draft ready")); + const final = await send( + "subagent-stop.mjs", + subagentStop("d4f7b0e3a6c9d2f58", "Draft ready, tests added", { stop_hook_active: true }), + ); + expect(final.eventId).not.toBe(first.eventId); + }); + + it("gives a subagent that stops again with the same reply after a blocking stop hook a new id", async () => { + const first = await send("subagent-stop.mjs", subagentStop("a7c0e3b6d9f2a5c81", "Draft ready")); + const again = await send( + "subagent-stop.mjs", + subagentStop("a7c0e3b6d9f2a5c81", "Draft ready", { stop_hook_active: true }), + ); + expect(again.eventId).not.toBe(first.eventId); + }); + + it("stores both subagent reports when the server dedups by event id", async () => { + const a = await send("subagent-stop.mjs", subagentStop("e5a8c1f4b7d0e3a69", "Report A")); + const b = await send("subagent-stop.mjs", subagentStop("f6b9d2a5c8e1f4b70", "Report B")); + const retry = await send("subagent-stop.mjs", subagentStop("e5a8c1f4b7d0e3a69", "Report A")); + + vi.resetModules(); + const kv = mockKV(); + const { registerObserveFunction } = await import("../src/functions/observe.js"); + const { registerCaptureFunctions } = await import("../src/functions/capture.js"); + const { DedupMap } = await import("../src/functions/dedup.js"); + const sdk = mockSdk({ looseTrigger: true }); + registerObserveFunction(sdk as never, kv as never, new DedupMap()); + registerCaptureFunctions(sdk as never, kv as never, {}); + const capture = ({ eventId, ...payload }: Record) => + sdk.trigger("mem::capture", { payload, eventId }) as Promise>; + + expect(await capture(a)).toMatchObject({ status: "accepted" }); + expect(await capture(b)).toMatchObject({ status: "accepted" }); + expect(await capture(retry)).toMatchObject({ status: "duplicate" }); + expect(kv.store.get(KV.observations(SESSION))?.size).toBe(2); + }); +}); diff --git a/test/privacy.test.ts b/test/privacy.test.ts index 450e209111..8277045b02 100644 --- a/test/privacy.test.ts +++ b/test/privacy.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from "vitest"; -import { stripPrivateData } from "../src/functions/privacy.js"; +import { scrubRecord, stripPrivateData } from "../src/functions/privacy.js"; describe("stripPrivateData", () => { it("strips private tags", () => { @@ -104,4 +104,75 @@ describe("stripPrivateData", () => { expect(stripPrivateData(input)).toBe("[REDACTED_SECRET]"); expect(stripPrivateData(input)).toBe("[REDACTED_SECRET]"); }); + + it.each([ + "task-runner-that-does-something-long", + "bookmark-this-long-reference-identifier", + "break-this-long-background-operation", + "task-proj-abcdefghijklmnopqrstuvwxyz", + "task-ant-abcdefghijklmnopqrstuvwxyz", + "prefix_pk-abcdefghijklmnopqrstuvwxyz", + "42rk-abcdefghijklmnopqrstuvwxyz", + "éak-abcdefghijklmnopqrstuvwxyz", + "漢sk-abcdefghijklmnopqrstuvwxyz", + "e\u0301sk-abcdefghijklmnopqrstuvwxyz", + ])("preserves key-like suffixes inside identifiers: %s", (identifier) => { + expect(stripPrivateData(identifier)).toBe(identifier); + }); + + it.each(["sk", "pk", "rk", "ak", "sk-proj", "sk-ant"])( + "still redacts standalone %s keys at punctuation and whitespace boundaries", + (prefix) => { + const key = `${prefix}-abcdefghijklmnopqrstuvwxyz`; + for (const [before, after] of [["", ""], ["'", "'"], ['"', '"'], ["(", ")"], ["/", "."], ["\n", "\t"], ["🔑", "!"]]) { + expect(stripPrivateData(`${before}${key}${after}`)).toBe(`${before}[REDACTED_SECRET]${after}`); + } + }, + ); + + it("preserves identifiers while redacting adjacent keys on repeated passes", () => { + const input = '{"task":"task-runner-that-does-something-long","key":"sk-abcdefghijklmnopqrstuvwxyz"}'; + const expected = '{"task":"task-runner-that-does-something-long","key":"[REDACTED_SECRET]"}'; + expect(stripPrivateData(input)).toBe(expected); + expect(stripPrivateData(input)).toBe(expected); + expect(stripPrivateData(expected)).toBe(expected); + }); +}); + +describe("scrubRecord property names", () => { + const secret = "sk-abcdefghijklmnopqrstuvwxyz"; + + it("leaves property names unchanged by default", () => { + expect(scrubRecord({ [secret]: secret })).toEqual({ [secret]: "[REDACTED_SECRET]" }); + }); + + it("optionally scrubs property names recursively without changing the input", () => { + const input = { nested: [{ [secret]: { note: secret, count: 3, ok: true, empty: null } }] }; + const before = structuredClone(input); + expect(scrubRecord(input, { scrubKeys: true })).toEqual({ + nested: [{ "[REDACTED_SECRET]": { note: "[REDACTED_SECRET]", count: 3, ok: true, empty: null } }], + }); + expect(input).toEqual(before); + }); + + it.each([false, true])("preserves own __proto__ fields with scrubKeys=%s", (scrubKeys) => { + const input = { ["__proto__"]: { note: secret }, constructor: "ordinary value" }; + const output = scrubRecord(input, { scrubKeys }); + expect(Object.getPrototypeOf(output)).toBe(Object.prototype); + expect(Object.hasOwn(output, "__proto__")).toBe(true); + expect(output).toEqual({ ["__proto__"]: { note: "[REDACTED_SECRET]" }, constructor: "ordinary value" }); + expect(input["__proto__"].note).toBe(secret); + }); + + it("preserves both values when scrubbed property names collide", () => { + expect(scrubRecord({ [secret]: "first", "[REDACTED_SECRET]": "last" }, { scrubKeys: true })) + .toEqual({ "[REDACTED_SECRET]": "first", "[REDACTED_SECRET]_2": "last" }); + }); + + it("avoids existing names when allocating collision suffixes", () => { + const input = { [secret]: "first", "pk-abcdefghijklmnopqrstuvwxyz": "second", "[REDACTED_SECRET]_2": "ordinary" }; + const output = scrubRecord(input, { scrubKeys: true }); + expect(output).toEqual({ "[REDACTED_SECRET]": "first", "[REDACTED_SECRET]_3": "second", "[REDACTED_SECRET]_2": "ordinary" }); + expect(scrubRecord(output, { scrubKeys: true })).toEqual(output); + }); });