Files
rohitg00__agentmemory/tsdown.config.ts
T
Rohit Ghumare 81be407078 address CodeRabbit review on #188
All six findings verified against current code on this branch; all valid.

1. observe.ts firstPrompt (L206-211) — raw.userPrompt is typed as
   optional string but populated from payload.data which is unknown at
   runtime; a non-string truthy value (array, object) would crash at
   .replace(). Guard with typeof === 'string' before sanitizing, and
   skip the update when the trimmed value is empty.

2. replay.ts deriveCrystalAndLessons — generateId('lesson') /
   generateId('crystal') produced fresh IDs on every import, so
   re-importing the same JSONL duplicated lessons and crystals. Switch
   to fingerprintId:
   - lessons keyed by fingerprintId('lesson', content.toLowerCase()) +
     merge on existing (bump reinforcements, append sessionId to
     sourceIds, union tags).
   - crystals keyed by fingerprintId('crystal', sessionId) + preserve
     original createdAt and sourceActionIds when upserting.

3. viewer/index.html crystals filter (L2686-2691) — search haystack
   previously joined raw lesson IDs (lesson_xxx), so lesson text never
   matched. Resolve each ID via state.crystals.lessonMap and include
   resolved content in the haystack; also fold in filesAffected and
   project so the search feels complete.

4. image-quota-cleanup.ts (L56-68) — when getImageRefCount threw, the
   refCount variable stayed at its default 0 and the code happily
   proceeded to deleteImage(). That could delete a still-referenced
   image on any transient KV error. Fail-closed: log and return from
   the withKeyedLock callback on error so deleteImage is never reached
   without a confirmed refCount === 0.

5. types.ts / disk-size-manager.ts — add a StateScope interface that
   maps KV.state scope keys to their value types
   (system:currentDiskSize: number), export StateScopeKey, and have
   disk-size-manager use StateScope[typeof DISK_SIZE_KEY] in kv.get /
   kv.set generics instead of the ad-hoc <number>.

6. tsdown.config.ts + package.json — onnxruntime-node / onnxruntime-web
   are not imported directly; they come in transitively via
   @xenova/transformers. Keep them in tsdown's external array (bundling
   them breaks the relative .node binding paths in dist/) and add both
   to package.json optionalDependencies alongside @xenova/transformers
   so the optional/lazy nature is explicit. Expand the tsdown comment
   to reference the new optionalDependencies entries and name the exact
   src files that lazy-import them.

812/812 tests pass.
2026-04-22 11:53:11 +01:00

78 lines
1.9 KiB
TypeScript

import { defineConfig } from "tsdown";
const hookEntries = [
"src/hooks/session-start.ts",
"src/hooks/prompt-submit.ts",
"src/hooks/pre-tool-use.ts",
"src/hooks/post-tool-use.ts",
"src/hooks/post-tool-failure.ts",
"src/hooks/pre-compact.ts",
"src/hooks/subagent-start.ts",
"src/hooks/subagent-stop.ts",
"src/hooks/notification.ts",
"src/hooks/task-completed.ts",
"src/hooks/stop.ts",
"src/hooks/session-end.ts",
];
const shared = {
format: ["esm"] as const,
target: "node20" as const,
inlineOnly: false as const,
// Keep as node_modules imports. We never import onnxruntime-{node,web}
// directly; they come in transitively through @xenova/transformers, which
// is lazy-loaded from src/providers/embedding/{clip,local}.ts and
// src/state/reranker.ts. Bundling inlines relative paths like
// `../bin/napi-v3/darwin/arm64/onnxruntime_binding.node` that no longer
// resolve from dist/. All three are declared as optionalDependencies in
// package.json so users can install them only when they enable local
// embeddings / CLIP / reranker.
external: [
"@xenova/transformers",
"onnxruntime-node",
"onnxruntime-web",
"@anthropic-ai/claude-agent-sdk",
"@anthropic-ai/sdk",
] as const,
};
export default defineConfig([
{
entry: ["src/index.ts"],
outDir: "dist",
...shared,
dts: true,
clean: true,
sourcemap: true,
banner: { js: "#!/usr/bin/env node" },
},
{
entry: ["src/cli.ts"],
outDir: "dist",
...shared,
clean: false,
sourcemap: false,
},
{
entry: ["src/mcp/standalone.ts"],
outDir: "dist",
...shared,
clean: false,
sourcemap: false,
},
{
entry: hookEntries,
outDir: "dist/hooks",
...shared,
clean: false,
sourcemap: false,
},
{
entry: hookEntries,
outDir: "plugin/scripts",
...shared,
clean: false,
sourcemap: false,
},
]);