Files
rohitg00__agentmemory/package.json
T
Rohit Ghumare 281e10ca8c fix: stop burning Claude tokens on every PostToolUse hook (#138) (#140)
* fix: stop burning Claude tokens on every PostToolUse hook (#138)

mem::observe was firing mem::compress unconditionally on every
PostToolUse hook, which called Claude via the user's ANTHROPIC_API_KEY
to compress each raw observation into a structured summary. On an
active coding session (50-200 tool calls/hour) this silently burned
hundreds of thousands of Claude API tokens within minutes. Reported
by @olcor1 on a fresh Docker install — his token allocation was gone
in 20 minutes.

Make per-observation LLM compression opt-in.

- New env var AGENTMEMORY_AUTO_COMPRESS, default `false`. When false,
  observe.ts builds a zero-LLM synthetic CompressedObservation from
  raw tool I/O (title from toolName, narrative from truncated
  input/output, files extracted from file_path/pattern/etc., type
  inferred from camelCase-normalized tool name) and stores + indexes
  it. Recall and BM25 search still work.
- New src/functions/compress-synthetic.ts with buildSyntheticCompression().
- src/functions/observe.ts gates the compress trigger on the flag and
  writes the synthetic observation + stream events when disabled.
- Startup banner now logs "Auto-compress: OFF (default, #138)" or a
  loud warning when opt-in is on, so the mode is never silent.
- Regression test: test/auto-compress.test.ts covers the default path
  (no mem::compress fired), explicit opt-in, tool-name-to-type
  mapping, file-path extraction, narrative truncation, and the
  post_tool_failure→error mapping.

Bumps to 0.8.8 (main package + shim). 707 tests pass.

**Migration**: users who were relying on LLM-generated summaries set
AGENTMEMORY_AUTO_COMPRESS=true in ~/.agentmemory/.env and restart.
Existing compressed observations on disk are untouched.

* review: address CodeRabbit findings on #140

- compress-synthetic.ts:92 — use the fallback toolName for inferType
  so both title and type derive from the same resolved value
- test/auto-compress.test.ts — vi.resetModules() in beforeEach to
  prevent cached observe.js from seeing stale env var state between
  the default, opt-in, and explicit-off test cases
2026-04-14 15:42:17 +01:00

78 lines
2.0 KiB
JSON

{
"name": "@agentmemory/agentmemory",
"version": "0.8.8",
"description": "Persistent memory for AI coding agents, powered by iii-engine's three primitives",
"type": "module",
"main": "dist/index.mjs",
"types": "dist/index.d.mts",
"exports": {
".": {
"types": "./dist/index.d.mts",
"import": "./dist/index.mjs"
},
"./dist/standalone.mjs": "./dist/standalone.mjs",
"./package.json": "./package.json"
},
"bin": {
"agentmemory": "dist/cli.mjs"
},
"scripts": {
"build": "tsdown && (cp iii-config.yaml dist/ 2>/dev/null || true) && (cp iii-config.docker.yaml dist/ 2>/dev/null || true) && (cp docker-compose.yml dist/ 2>/dev/null || true) && mkdir -p dist/viewer && cp src/viewer/index.html dist/viewer/",
"dev": "tsx src/index.ts",
"start": "node dist/cli.mjs",
"migrate": "node dist/functions/migrate.js",
"test": "vitest run --exclude test/integration.test.ts",
"test:watch": "vitest --exclude test/integration.test.ts",
"test:integration": "vitest run test/integration.test.ts",
"test:all": "vitest run"
},
"keywords": [
"ai",
"agent",
"memory",
"persistent",
"iii-engine",
"claude-code",
"coding-agent",
"context",
"observation"
],
"files": [
"dist/",
"plugin/",
"iii-config.yaml",
"iii-config.docker.yaml",
"docker-compose.yml",
"LICENSE",
"README.md",
"AGENTS.md"
],
"author": "Rohit Ghumare <ghumare64@gmail.com>",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/rohitg00/agentmemory"
},
"dependencies": {
"@anthropic-ai/claude-agent-sdk": "^0.2.56",
"@anthropic-ai/sdk": "^0.39.0",
"@clack/prompts": "^1.2.0",
"dotenv": "^16.4.7",
"iii-sdk": "^0.3.0",
"zod": "^4.0.0"
},
"optionalDependencies": {
"@xenova/transformers": "^2.17.2"
},
"devDependencies": {
"@types/node": "^22.0.0",
"tsdown": "^0.20.3",
"tsx": "^4.19.0",
"typescript": "^5.7.0",
"vitest": "^3.0.0"
},
"engines": {
"node": ">=20.0.0"
}
}