Skip to content

feat: use compressObservation for tool capture in session transcripts#75

Open
myselfsiddharth wants to merge 2 commits into
supermemoryai:mainfrom
myselfsiddharth:feat/compress-tool-capture
Open

feat: use compressObservation for tool capture in session transcripts#75
myselfsiddharth wants to merge 2 commits into
supermemoryai:mainfrom
myselfsiddharth:feat/compress-tool-capture

Conversation

@myselfsiddharth

@myselfsiddharth myselfsiddharth commented Jul 7, 2026

Copy link
Copy Markdown

Summary

Session auto-capture (summary-hook) formats Claude Code transcripts before saving them to Supermemory. When includeTools is configured, tool activity was previously stored by truncating raw tool result text to 500 characters. That produced noisy, low-signal memories.

This PR wires up the existing compress.js module (which was already in the repo but unused) into transcript-formatter.js. Tool results are now summarized with compressObservation(), using the original tool name and input from the assistant's tool_use block.

Before: raw truncated output

Edit(success): import fs from 'node:fs'...\n[500 chars of file content]

After: semantic summary

Edit(success): Edited lib/stdin.js: "async function readStdin()" → "async function readStdin(timeoutMs)"

Changes

  • Import compressObservation from ./compress in transcript-formatter.js
  • Store { name, input } in toolUseMap instead of just the tool name string
  • Replace MAX_TOOL_RESULT_LENGTH truncation with compressObservation() for tool results
  • Remove dead MAX_TOOL_RESULT_LENGTH constant
  • Drop truncate from module.exports (still used internally; nothing imported it externally)
  • Rebuild plugin/scripts/summary-hook.cjs

No changes to compress.js itself.

Why this matters

Supermemory extracts memories from these transcripts using PERSONAL_ENTITY_CONTEXT. Higher-quality tool summaries give the extraction layer better signal about what the user actually did, especially for Edit, Write, Bash, Read, and Grep turns.

Test plan

  • npx biome check src/lib/transcript-formatter.js passes
  • npm run build succeeds
  • Only summary-hook.cjs bundle changes (the sole consumer of transcript-formatter)
  • Verify auto-capture with includeTools: ["Edit", "Write"] in settings produces compressed tool lines in saved session memory
  • Confirm signal extraction mode (formatSignalEntries) is unaffected (it uses text-only formatting and skips tool results)

Session Details

  • Session: View Session
  • Requested by: Unknown
  • Address comments on this PR. Add (aside) to your comment to have me ignore it.

Wire the existing compress.js helper into transcript-formatter so
auto-captured tool activity is summarized semantically instead of
truncating raw tool output to 500 characters.

Store tool name and input in toolUseMap so compressObservation can
produce concise descriptions (e.g. "Edited stdin.js: ..." instead of
a blob of tool result text). Remove unused MAX_TOOL_RESULT_LENGTH and
drop truncate from public exports.

Rebuild summary-hook.cjs bundle.

@vorflux vorflux Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Reviewed — found 1 issue(s). This PR changes transcript formatting to capture tool results through compressObservation() and updates the generated summary hook bundle. The review focused on correctness and data quality risks in captured session transcripts.

Findings

src/lib/transcript-formatter.js

  1. tool_result formatting now always uses compressObservation(), which can drop meaningful output for unsupported includable tools and misleadingly summarize failed operations without preserving the actual error text.

Verdict

⚠️ Changes requested. The formatter should retain meaningful result/error content for included tools, especially unsupported tool types and failed tool executions, to avoid degrading or misrepresenting captured memories.


Review with Vorflux

);
const status = block.is_error ? 'error' : 'success';
if (resultContent) {
const compressed = compressObservation(toolName, toolEntry.input, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compressObservation() replaces the previous cleaned/truncated tool_result content for every included tool, but it only has meaningful summaries for a subset of documented includable tools and does not reliably preserve failure output. For unsupported tools such as TodoWrite, TaskOutput, AskUserQuestion, or LSP, transcript capture can degrade to generic text like Used <tool>, and failed operations such as Edit, Write, or Read can omit the actual error that explains what happened. Please keep a fallback to the cleaned/truncated block.content when the tool is unsupported or block.is_error is true, or extend compressObservation() so every includable tool and failure path preserves a meaningful result summary.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed It! mb, did not consider that

@vorflux

vorflux Bot commented Jul 7, 2026

Copy link
Copy Markdown

Testing

Functional verification was performed against PR commit ea4b1a2770bb066d1f38786f886940443e4eefb5 in a detached worktree. Build, lint, hook smoke checks, and one-off formatter integration coverage passed; no screenshots or recordings were applicable because this PR has no UI or mobile changes.

Commands run:

git worktree add --detach /tmp/claude-supermemory-pr75 origin/pr-75
cd /tmp/claude-supermemory-pr75
npm ci
npm run clean
npm run build
grep -q 'Edited ' plugin/scripts/summary-hook.cjs
grep -q 'Used ' plugin/scripts/summary-hook.cjs
grep -q 'compressObservation' plugin/scripts/summary-hook.cjs
npm run lint
node /tmp/pr75-formatter-tests.cjs
unset SUPERMEMORY_CC_API_KEY
echo '{}' | node plugin/scripts/context-hook.cjs
printf {session_id:pr75-smoke,transcript_path:%s,cwd:%s}n "$tmptranscript" "$PWD" | node plugin/scripts/summary-hook.cjs

Result:

npm ci: passed; 6 packages installed, 0 vulnerabilities.
npm run clean && npm run build: passed; generated 8 hook bundles including plugin/scripts/summary-hook.cjs.
Bundle marker check: passed; plugin/scripts/summary-hook.cjs contains compressed observation logic.
npm run lint: passed; Checked 28 files in 13ms. No fixes applied.
Formatter integration tests: passed for included tool summaries, raw output suppression, failed Bash markers, missing tool-use mapping, includeTools filtering, and signal extraction.
Hook smoke tests without API key: passed; context-hook.cjs emitted valid SessionStart hook JSON and summary-hook.cjs emitted valid { "continue": true }.
Evidence logs: /var/tmp/testing_responses/44ccd9e0-c0b2-49e5-8de5-212f6a2eaa13/response_pr75-testing.md, /tmp/pr75-full-verification-final.log, /tmp/pr75-formatter-tests.cjs, /tmp/pr75-setup-build-lint.log, /tmp/pr75-formatter-final.log.

Verdict

Passed. The exercised build, lint, formatter, and hook smoke checks completed successfully; the repository still lacks committed regression tests for src/lib/transcript-formatter.js, so coverage was provided by a one-off external script.

Address review feedback on compressObservation integration:

- Fall back to cleaned, truncated tool_result content when
  compressObservation returns a generic "Used <tool>" string
  (unsupported includable tools like TodoWrite, LSP, etc.)
- On failed tools, append the actual error output after the
  compressed summary so captured memories retain failure context

Rebuild summary-hook.cjs bundle.
@vorflux

vorflux Bot commented Jul 7, 2026

Copy link
Copy Markdown

Thanks — confirmed the latest PR head 409c8ab addresses the issue. src/lib/transcript-formatter.js now preserves cleaned/truncated block.content for error results and uses it as a fallback for generic Used <tool> summaries, so the previous data-loss/misleading-error concern is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant