feat(core,cli): M3c-ext — http/prompt hooks + if-field + apiKeyHelper refresh + auto-compact#12
Merged
Merged
Conversation
… refresh + auto-compact
What ships
----------
- hooks/dispatcher.ts:
· 3 new handler types beyond `command`:
- http: POST JSON to URL, response.text → stdout, status >=400 → exitCode
- prompt: synthesizes additionalContext JSON output (no exec)
- mcp_tool / agent: stubs with informative stderr (paired with M5+)
· `if` field — permission-rule syntax filter, runs before handler exec
· allowedHttpHookUrls — whitelist enforced for http handlers
· matchRule imported from config/permissions.js (no circular dep since
permissions doesn't import hooks)
- credentials/index.ts:
· ApiKeyHelperRefresher class — 5min TTL cache + invalidate() for 401
recovery + DEEPCODE_API_KEY_HELPER_TTL_MS env var override
- agent.ts:
· runAgent now accepts `autoCompact: { contextWindow, threshold, ... }`
· After each turn, if cumulative tokens > threshold, runs compact() and
replaces history mid-loop. Summarizer tokens counted in totalUsage.
· Compaction failure is non-fatal — agent continues with full history.
- apps/cli/src/repl.ts:
· Wires settings.allowedHttpHookUrls into HookDispatcher
· Sets autoCompact = { contextWindow: 128000, threshold: 0.8 } by default
Tests (9 new, 297 total)
------------------------
- hooks: http POST roundtrip (uses node:http local server) +
allowedHttpHookUrls reject + prompt handler additionalContext +
mcp_tool/agent stub + if-field permission-syntax filter
- credentials: ApiKeyHelperRefresher cache-hit + refresh + invalidate +
DEEPCODE_API_KEY_HELPER_TTL_MS env-var TTL override
Verified
--------
pnpm typecheck → green
pnpm test → 297 passed / 7 skipped / 0 failed
pnpm format:check → conformant
What's NOT in this PR
---------------------
- mcp_tool / agent hook handlers (paired with M5 plugin sandbox + M4 sub-agent
dispatch — wire when those land)
- httpHookAllowedEnvVars (M5+ — needed for sandboxed plugins)
- /init multi-phase (still M3c-rest)
- auto classifier mode (still M3c-rest)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
3 new hook handler types (http / prompt / mcp_tool+agent stubs) +
iffield permission-syntax filter +allowedHttpHookUrlswhitelist enforcement +ApiKeyHelperRefresher(TTL cache + 401 invalidate) + auto-compact trigger in agent loop after each turn.9 new tests, 297 total, 0 failed.
Release notes
release-notes:featureCo-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com