Skip to content

Master PR consolidating previous 11 PRs into one for easy merge - #18

Open
Shifat7 wants to merge 32 commits into
clutchpbcfo:mainfrom
Shifat7:main
Open

Shifat7 wants to merge 32 commits into
clutchpbcfo:mainfrom
Shifat7:main

Conversation

@Shifat7

@Shifat7 Shifat7 commented Aug 23, 2026

Copy link
Copy Markdown

No description provided.

Shifat7 and others added 30 commits August 22, 2026 17:20
Every dispatched request now logs a local prompt-size estimate in the
audit log: total chars, estimated tokens (ceil(chars / 4)), a section
breakdown (relay instructions, conversation, tool results, tool
schemas, payload JSON), retention limits, and forwarded tool counts.
Hyperagent does not report authoritative usage, so figures are labeled
as local estimates everywhere.

New CLI surface:
- hacb cost-report [--last N]: per-request table plus totals/averages
- hacb explain-prompt [--verbose]: section breakdown of the last prompt
- hacb audit --cost [count]: receipts with estimated token columns

Prompt excerpt capture is strictly opt-in via debugPromptExcerpts;
excerpts stay bounded (240 chars) in the private 0600 state directory
and never reach the sanitized audit or gateway logs.
Classify each turn locally into final_answer_only, read_or_search,
edit_code, run_command, debug_failure, or unknown, then forward only
the client tool categories that task type needs. Function schemas are
minimised to argument names, types, and required lists with capped
descriptions unless forwardFullToolSchemas is enabled.

Safety rules enforced by tests: exact tool names preserved, no tools
invented, mid-task conversations keep their tools, unknown turns keep
the full inventory, and disabling enableSmartToolSelection restores
unconditional forwarding. Defaults: on, minimal schemas, 160-char
descriptions.
Add reduceToolOutput() applied to function_call_output and
custom_tool_call_output items during input normalisation: ANSI and
progress noise stripped, successful output capped to its last
meaningful lines, failures keep the first error block plus tail lines,
and search output is capped per file with remainder notes. Reductions
are marked inline; user prose is never reduced.

Defaults: on, 20 successful lines, 80 failure lines, 5 matches/file.
Set enableToolResultReducer false for byte-identical prior behaviour.
Load bounded .hacb/CODEX_STATE-style checkpoints and inject them into
the relay payload ahead of the conversation so long sessions can rely
on cheap repo-local state instead of huge chat history. Only exact
configured filenames inside checkpointDir are read; traversal entries
are ignored; missing files are skipped; content is capped at
maxCheckpointChars with an explicit truncation marker.

Defaults: on, .hacb directory, four standard checkpoint files, 4,000
chars. enableCheckpointMemory false disables all filesystem access.
Add hacb task start/status/stop managing durable named tasks with
their own request, prompt-char, and tool-loop limits. The bridge
reserves from the active task after the daily reservation succeeds;
exhaustion releases the unused daily slot and fails closed with an
explicit operator message. No active task means no per-task
enforcement; daily caps always remain authoritative.

Defaults: 8 requests, 180k prompt chars, warn at 120k chars.
Store completed successful responses by sha256(canonical JSON body)
in the private state directory and replay identical un-keyed requests
locally until the TTL expires (bounded by maxEntries). Errors,
cancellations, and indeterminate dispatches are never stored; explicit
Idempotency-Key flows take precedence and skip the cache entirely.

Disabled by default: enableResponseCache must be explicitly true.
Replay is marked with X-Response-Cache-Replayed and a sanitized
gateway log event.
Accept type:function_calls relay output when enableMultiToolCalls is
true: every call is validated against forwarded function tools and the
whole response fails safely to a final answer on any unavailable name
or when maxToolCallsPerResponse is exceeded. Valid multi-calls render
as multiple Responses function_call items with distinct suffixed
call_ids over SSE and non-streaming output.

Default remains disabled; single-tool behaviour is unchanged.
Collapse the relay header from 21 lines of prose to the mechanical
minimum that survives imperfect relay-agent setup: ownership boundary,
forwarded tool list, four JSON shapes, never-invent-names, and
one-JSON-object rules. Trivial-prompt size drops from 1,978 to 1,370
chars (-31%), applied to every sampling request.

Documented the recommended relay agent setup in README and marked
RELAY_AGENT_PROMPT.md as the durable home for behavioural rules.
Add pickAgentRoute() classifying each request into debug_failure,
large_refactor, planning, tool_selection, or final_answer, and bridge
support for substituting a configured agentRoutes target before
dispatch when enableAgentRouting is true. Route targets resolve via
the standard model resolution rules; unknown targets log
agent_route_fallback and keep the requested model; selected routes
and reasons are recorded in audit receipts.

Disabled by default: no hidden model substitution.
Add runLocalPreprocessor() executing a configured local command with
sanitised request metadata on stdin (requestId, model, toolCount,
inputChars; never prompt content) and honouring an explicit reject
decision as HTTP 400 preprocessor_rejected. Timeouts kill the child;
spawn errors, non-zero exits, and invalid JSON follow the configured
failure mode: fallback allows with a logged reason, fail_closed
returns HTTP 503 preprocessor_failed.

Disabled by default: enableLocalPreprocessor plus an explicit
localPreprocessorCommand are both required.
# Conflicts:
#	src/protocol.mjs
# Conflicts:
#	README.md
#	src/config.mjs
#	test/protocol.test.mjs
# Conflicts:
#	README.md
#	src/config.mjs
#	src/protocol.mjs
#	test/protocol.test.mjs
# Conflicts:
#	README.md
#	src/bridge.mjs
#	src/config.mjs
#	src/protocol.mjs
#	test/protocol.test.mjs
# Conflicts:
#	README.md
#	src/config.mjs
#	test/protocol.test.mjs
# Conflicts:
#	README.md
#	src/bridge.mjs
#	src/config.mjs
#	test/bridge.test.mjs
#	test/protocol.test.mjs
# Conflicts:
#	README.md
#	src/bridge.mjs
#	src/config.mjs
#	test/bridge.test.mjs
# Conflicts:
#	README.md
#	src/bridge.mjs
#	src/config.mjs
#	test/bridge.test.mjs
# Conflicts:
#	README.md
#	src/bridge.mjs
#	src/config.mjs
#	test/bridge.test.mjs
Cut mid-turn tool dumps, scrub Codex plugin chrome, coerce/sanitize relay JSON, and make profile/doctor OpenRouter-aware after local QA.
Keep tool_search MCP discoveries eligible, reserve a bounded other-tool slot, tighten chrome scrub / apply_patch / coercion / doctor key trim, and count the OpenRouter system prompt in budgets.
feat: tighten OpenRouter harness efficiency and relay reliability
OpenRouter often emits apply_patch as a function_call or bare type; Codex only accepts the freeform custom tool, so remap those shapes before rejecting.
gpt-4.1-mini sometimes emits `@@` plus a following `-1,9 +1,31 @@` line; Codex treats that as search context and the patch loops forever.
budget --set was clamped at 100 in both CLI validation and dailyLimit(); allow higher explicit caps (used for OpenRouter harness QA at 500).
Codex freeform apply_patch treats unified ranges (split or joined) as
search context, so rewrite them to a bare @@ marker before Codex sees them.
High-default models like Claude Sonnet reserve ~64k completion tokens
on OpenRouter; without an explicit max_tokens the staging key returns
402 and the bridge surfaces a generic upstream_error.
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