Repository navigation
fix(types): AbsorbConfig type surface — optional value fields + ResolvedAbsorbConfig - #503
ranxianglei wants to merge 1 commit into
Conversation
…e fields + ResolvedAbsorbConfig (#502) The declared surface demanded all five AbsorbConfig fields while both the kernel (resolveAbsorbConfig, defaultConfig spread merges) and consumers tolerate absence per field. Make toolName/minToolTokens/contextThresholdPct/excludeTools optional (enabled stays required as the activation toggle, matching ImageCompressionConfig precedent), add ResolvedAbsorbConfig = Required<AbsorbConfig> for entry points consuming resolved configs (EvaluateCrushInput.absorb, DEFAULT_ABSORB_CONFIG, resolveAbsorbConfig return), and make validateConfig undefined-tolerant like the imageCompression checks. prompt_cache_key wire type intentionally unchanged (issue facet 2, option 1).
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)In your adapter project: npm install acp-kernel@pr-503Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf acp-kernel-pr503.tgz
npm install ./packageThis comment is automatically updated on each push. |
[bot] 🏷 PR #503 独立 review 完成(拉分支核对代码 + 独立确认 CI + 本地定向复验)。 核对过程
结构化七问
测试有效性:3 个新回归测试是真测试——断言精确解析值(4000 / 0 / [] / ABSORB_TOOL_NAME)而非恒真式,分别钉住 partial→defaults 解析、逐字段 override 合并、validateConfig「接受 partial / 拒绝显式坏值(-1 / 2 / "")」边界;若字段回退必填或 resolve 合并被破坏都能抓住。小缺口(不拦): 一项发现(非阻断): 判定:可合并(CI 全绿 + 代码核对通过 + 无意回归未发现 + diff 干净;按仓库规则由人工 merge)。 |
Closes #502
What changed
Facet 1 (main):
AbsorbConfig's declared surface was stricter than actual usage — all five fields were required, while both the kernel (resolveAbsorbConfig/defaultConfigspread merges, src/absorb.ts:42-44, src/config.ts:70-72) and consumers tolerate absence per field. Reproduced on v0.0.100 master:defaultConfig(200000, { absorb: { enabled: true } })fails with TS2739 although it is runtime-valid.src/types.ts:toolName/minToolTokens/contextThresholdPct/excludeToolsnow optional;enabledstays required as the activation toggle (matches theImageCompressionConfigprecedent; the issue allows either). Field docs carry the defaults.src/types.ts: new exportResolvedAbsorbConfig = Required<AbsorbConfig>— the fully-populated shaperesolveAbsorbConfig/defaultConfigproduce.DEFAULT_ABSORB_CONFIG, theresolveAbsorbConfigreturn,EvaluateCrushInput.absorb, and internalisAcpOrConfiguredToolnow use it, so entry points consuming a resolved config cannot silently accept partials after the loosening (they would compare againstundefined).src/config.ts:validateConfigabsorb checks treatundefinedas "default applies" (same pattern as theimageCompressionchecks directly below); explicitly invalid values are still rejected with identical messages.tests/absorb.test.ts: three regression tests (partial→defaults resolution, per-field override merge, validation accepts partials but rejects explicit bad values).The issue's secondary ask — "export a default-merge function consistent with resolveAbsorbSettings" — is already satisfied by the kernel itself:
resolveAbsorbConfig+DEFAULT_ABSORB_CONFIGare exported fromacp-kernelin current master (src/absorb.ts, re-exported via index.ts). No new function needed; the remaining gap was purely the required-fields surface.Facet 2 (
prompt_cache_key): no change, per the issue's own recommendation ① — keepstring(follows the OpenAI spec; non-string wire values are client anomalies, and the consumer-side defense at billion-context src/session-id.ts:214-222 is already in the right place).Behavior changes (disclosed)
AbsorbConfigliterals now typecheck; existing full literals unaffected. New type export is purely additive.validateConfig: an enabled absorb block missingtoolNameused to be reported as"absorb.toolName must be a non-empty string when enabled"(only reachable via JS/cast callers, since absence was unrepresentable under the old types); it now passes because the default"absorb"applies. Explicit empty string""is still rejected. Old → new: missing = error → missing = OK (default fills in); explicit bad values unchanged. Reason: absence is merged over defaults everywhere in the kernel, so flagging it as invalid was a false positive.EvaluateCrushInput.absorb(public input interface): now requires the resolved shape (ResolvedAbsorbConfig). Callers passing fully-populated configs (all current call sites, incl. bili) are unaffected; partials that previously slipped through with undefined comparisons now fail at compile time.No runtime-default, prompt-text, wire-byte, token-count, or pipeline-ordering changes. No new config keys or env vars.
Verification (local, targeted)
defaultConfig(200000, { absorb: { enabled: true } })— before: TS2739 (4 missing props); after: clean.npm run typecheck,npm run format:check,npm run build— green; builtdist/types.d.tsshows the optional fields +ResolvedAbsorbConfigalias.node --import tsx --test tests/absorb.test.ts tests/crush.test.ts tests/sync-config.test.ts— 80/80 pass. Full suite deferred to CI.