pablontiv/a4s/tree/main/packages/context-expert/adapters/claude
a4s-context-expert
Jev が導く Claude Code の決定論的コンパクション。TypeSafe Jev が採点した keep/truncate/drop のトランスクリプトでネイティブ要約を置き換え、Jev が適切と判断した時点で自動コンパクションします。
この mod について
a4s-context-expert(Claude Code plugin)
Jev が導く Claude Code の決定論的コンパクションです。Claude のネイティブ /compact 要約を、TypeSafe Jev が採点する keep / truncate / drop トランスクリプトに置き換え、コンテキストウィンドウがしきい値を超えると自動でコンパクションします。Pi の pi-context-expert に相当する Claude 版で、trigger.mode: "auto" を使います。
このディレクトリは自己完結したマーケットプレイスプラグインです。ホストに依存しないコアのコピー(core/)を同梱し、scripts/sync-core.mjs によって正規の packages/context-expert/core/ とバイト単位で同一に保ち、claude-bundle-parity テストで固定しています。マーケットプレイスがインストールするのはこのディレクトリだけだからです。
できること
session.compact——ライブトランスクリプトに共有コアを実行します。Jev は各ツール呼び出し/結果を採点し、keep しきい値未満の項目を削除(呼び出し)または切り詰め(結果)します。最初のメッセージと最新の N 件はピン留めされ、再構築したメッセージ配列がネイティブ要約を置き換えます。推定削減率がminReductionRatio未満、または何かが失敗した場合は、next(event)でネイティブ要約にフォールバックします。失敗によってセッションが悪化することはありません。turn.complete——Jev が決める自動コンパクションのトリガーです。固定した割合ではコンパクションしません。ローカルの下限(minimumContextRatio)を超え、クールダウンが明けて資格情報も利用できる場合、テキストを含まない状態を Jev に渡して今が理想的なタイミングかを尋ね、Jev がcompactを選んだ場合だけ実行します。triggerModeはその後の動作を制御します。autoはコンパクション、hintは/compactの提案だけ、offは無効化です。pi-context-expertのtrigger.modeに相当する Claude 版です。
資格情報
TypeSafe Jev キーは、プラグインの apiKey userConfig、TYPESAFE_API_KEY、プラグイン設定の env、最後に Pi のネイティブ資格情報プロバイダー(~/.pi/agent/auth.json → typesafe.key)の順で解決されます。これは A4S の作業方式が認める(do_work.credentials)取得元です。キーはプロセス内でのみ読み取られ、ログ出力、ディスクへの書き込み、別の場所へのコピーは行いません。
インストール(A4S マーケットプレイスから)
claude plugin marketplace add pablontiv/a4s
claude plugin install a4s-context-expert@a4s
チェックアウトから直接読み込むこともできます。
claude --plugin-dir packages/context-expert/adapters/claude
設定(userConfig)
| キー | デフォルト | 意味 |
| --- | --- | --- |
| triggerMode | auto | auto(Jev が判断してからコンパクション)、hint(/compact を提案)、または off。 |
| minimumContextRatio | 0.5 | コンテキストウィンドウの充填率(0..1)。これ未満ではトリガーは Jev に尋ねません。 |
| minReductionRatio | 0.25 | 履歴を置き換えるための最小推定削減率。これ未満ならネイティブ要約を使います。 |
| keepThreshold | 0.5 | ツール呼び出し/結果を保持するための Jev の最小確率。 |
| preserveRecentMessages | 6 | コンパクションから保持してピン留めする最新メッセージ数。 |
| maxStateTokens / maxRequestTokens | 25000 / 30000 | Jev リクエストのトークン予算。 |
| truncateHeadChars | 300 | 切り詰めたツール結果に残す文字数。 |
| model | jev-latest | TypeSafe Jev モデル。 |
| apiKey | — | TypeSafe キーの上書き(機密)。それ以外は上記の順で解決します。 |
自動コンパクションのトリガーをオフにするには、triggerMode を off に設定します。
fast-jev-compaction(MIT)を元にしています。NOTICE を参照してください。
インストール
まず作者の README で marketplace とプラグイン名を確認してください。コマンドはリポジトリの構成によって変わる場合があります。
claude plugin marketplace add pablontiv/a4s claude plugin install a4s-context-expert
原文 / README
a4s-context-expert (Claude Code plugin)
Jev-guided deterministic compaction for Claude Code. It replaces Claude's
native /compact summary with a keep / truncate / drop transcript scored by
TypeSafe Jev, and auto-compacts once the context window crosses a threshold —
the Claude analog of Pi's pi-context-expert with trigger.mode: "auto".
This directory is the self-contained marketplace plugin. It bundles its own copy
of the host-neutral core (core/), kept byte-identical to the canonical
packages/context-expert/core/ by scripts/sync-core.mjs and anchored by the
claude-bundle-parity test, because the marketplace installs only this
directory.
What it does
session.compact— runs the shared core over the live transcript. Jev scores each tool call/result; items below the keep threshold are dropped (calls) or truncated (results), the first message and the most recent N are pinned, and the rebuilt message array replaces the native summary. If the estimated reduction is belowminReductionRatio, or anything fails, it falls back to the native summary vianext(event)— a failure never degrades the session.turn.complete— the Jev-decided auto-compact trigger. It does not compact at a fixed percentage. Past a local floor (minimumContextRatio), and subject to a cooldown and an available credential, it asks Jev — with a text-free state — whether now is the ideal moment to compact, and acts only when Jev choosescompact.triggerModecontrols what then happens:autocompacts,hintonly suggests/compact,offdisables it. This is the Claude analog ofpi-context-expert'strigger.mode.
Credentials
The TypeSafe Jev key resolves, in order, from the plugin apiKey userConfig,
then TYPESAFE_API_KEY, then the plugin settings env, and finally Pi's
native credential provider (~/.pi/agent/auth.json → typesafe.key) — the
source the A4S way-of-working sanctions (do_work.credentials). The key is read
in-process only; it is never logged, written to disk, or copied elsewhere.
Install (from the A4S marketplace)
claude plugin marketplace add pablontiv/a4s
claude plugin install a4s-context-expert@a4s
Or load it directly from a checkout:
claude --plugin-dir packages/context-expert/adapters/claude
Configuration (userConfig)
| Key | Default | Meaning |
| --- | --- | --- |
| triggerMode | auto | auto (Jev decides, then compacts), hint (suggest /compact), or off. |
| minimumContextRatio | 0.5 | Context-window fill (0..1) below which the trigger never asks Jev. |
| minReductionRatio | 0.25 | Minimum estimated reduction to replace history; below it, native summary. |
| keepThreshold | 0.5 | Minimum Jev probability to keep a tool call/result. |
| preserveRecentMessages | 6 | Newest messages pinned from compaction. |
| maxStateTokens / maxRequestTokens | 25000 / 30000 | Jev request token budgets. |
| truncateHeadChars | 300 | Characters of a truncated tool result kept. |
| model | jev-latest | TypeSafe Jev model. |
| apiKey | — | TypeSafe key override (sensitive); otherwise resolved as above. |
To turn the auto-compact trigger off, set triggerMode to off.
Derived from fast-jev-compaction
(MIT) — see NOTICE.
