ClaudeMods
☰
ZH-CN
● 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.

更多类似作品