Skip to content

feat(core,cli): M3c-ext — http/prompt hooks + if-field + apiKeyHelper refresh + auto-compact#12

Merged
oratis merged 1 commit into
mainfrom
feat/m3c-ext-hooks-autocompact
May 28, 2026
Merged

feat(core,cli): M3c-ext — http/prompt hooks + if-field + apiKeyHelper refresh + auto-compact#12
oratis merged 1 commit into
mainfrom
feat/m3c-ext-hooks-autocompact

Conversation

@oratis

@oratis oratis commented May 28, 2026

Copy link
Copy Markdown
Owner

Summary

3 new hook handler types (http / prompt / mcp_tool+agent stubs) + if field permission-syntax filter + allowedHttpHookUrls whitelist 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:feature

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

… 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>
@oratis oratis merged commit 7ee0d49 into main May 28, 2026
2 checks passed
@oratis oratis deleted the feat/m3c-ext-hooks-autocompact branch May 28, 2026 04:37
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