ClaudeMods
☰
ZH-TW
● 0 人在線上 · 瀏覽 0 次
贊助提交作品
GitHub 儲存庫 · 發布者 pablontiv

a4s-context-expert

由 Jev 引導的 Claude Code 確定性壓縮:以 TypeSafe Jev 評分的保留/截斷/捨棄轉錄取代原生摘要,並在 Jev 判定時機合適時自動壓縮。

pablontiv@pablontiv

pablontiv/a4s/tree/main/packages/context-expert/adapters/claude

已翻譯

關於這個 mod

a4s-context-expert(Claude Code plugin)

由 Jev 引導的 Claude Code 確定性壓縮。它用 TypeSafe Jev 評分的 保留 / 截斷 / 捨棄 轉錄,取代 Claude 原生的 /compact 摘要,並在上下文視窗跨過門檻後自動壓縮——這是 Pi 的 pi-context-expert 在 Claude 上的對應實作,使用 trigger.mode: "auto"。

這個資料夾是自包含的市集外掛。它內含一份與主機無關的核心副本(core/),由 scripts/sync-core.mjs 維持與標準 packages/context-expert/core/ 的位元組完全一致,並由 claude-bundle-parity 測試錨定,因為市集只會安裝這個資料夾。

它會做什麼

  • session.compact ——在即時轉錄上執行共用核心。Jev 會為每個工具呼叫/結果評分;低於保留門檻的項目會被捨棄(呼叫)或截斷(結果),第一則訊息和最近的 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 要求的 token 預算。 | | 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 below minReductionRatio, or anything fails, it falls back to the native summary via next(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 chooses compact. triggerMode controls what then happens: auto compacts, hint only suggests /compact, off disables it. This is the Claude analog of pi-context-expert's trigger.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.

更多類似作品