1jehuang / 1jehuang/jcode

Feature: allow post_tool hook to transform tool output (not gate-only)

Open
#1,241 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

autonomous: no enhancement triage: needs-decision
Dominant language
Rust
Stars
19.9k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
30

Description

Motivation

docs/HOOKS.md documents pre_tool as a gate (exit 0/2). post_tool currently fires for telemetry but cannot modify the tool result returned to the model. This blocks a large class of context-hygiene automations:

  • Auto-invoking mcp__headroom__headroom_compress on any tool output above a byte/line threshold.
  • Redacting secrets that leaked into command output.
  • Truncating or summarizing verbose logs before they enter context.

Today the AGENTS.md "compress outputs > 2 KB" rule is prose-only. Users cannot enforce it mechanically, so per-session compression coverage is near zero even when the Headroom MCP is configured.

Proposed contract

  • post_tool hook may print a JSON envelope on stdout, e.g. {"replace_output": "..."} or {"replace_output_ref": "hr_<hash>"}.
  • Exit 0 with no stdout = pass-through (current behavior).
  • Exit non-zero = fail-open with warning (matches current fail-open semantics).
  • Add post_tool_timeout_ms mirroring pre_tool_timeout_ms.

Alternatives considered

  • Doing it in pre_tool — impossible, output does not exist yet.
  • Client-side hook in the harness — jcode is the harness.
  • MCP proxy layer — would need to intercept every tool call type, not just MCP.

Related: ~/.jcode/preferred-tools.md already tells the model to compress big outputs, but nothing enforces it. Version: v0.84.0.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading docs/HOOKS.md and tracing the existing pre_tool hook and pre_tool_timeout_ms handling. Confirm the post_tool path can parse the proposed JSON envelope, preserve pass-through and fail-open behavior, and support a matching timeout; done means transformed output reaches the model without breaking existing telemetry.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.