拓冰建站拓冰建站
首页 / 资讯中心 / 正文

Caveman Native Core 详解:一份 560 Token 的 Agent 编码策略如何被编译、预算约束与多宿主分发

Caveman Native Core 详解一份 560 Token 的 Agent 编码策略如何被编译、预算约束与多宿主分发【免费下载链接】caveman why use many token when few token do trick — Claude Code skill that cuts 65% of tokens by talking like caveman项目地址: https://gitcode.com/GitHub_Trending/caveman1/caveman本文以 skills/native-core.md 为主体逐段解读这份 Caveman 项目中的原生核心Native Core工程策略——它是一份以极简 token 预算560 token 上限编写的强制性默认编码准则在 Claude Code、Codex、Gemini、Hermes、OpenCode、Aider 等宿主 Agent 中作为系统级默认策略生效。读完后你能完整理解这份策略的五级决策阶梯、安全豁免边界与最小证明纪律以及它在 skills/registry.json、skills/compile.mjs 中如何被校验、编译并分发给各宿主含 token 预算的硬性闸门与任务类型到技能的 fail-closed 选择机制。Native Core 是什么一份最高优先级默认值Native Core 是整个 Caveman 技能体系中最底层的一份工程策略文本全文仅 16 行英文指令却是所有native 交付技能的强制底座。它的定位可以从 skills/registry.json 的native_pack元数据中直接确认{ native_pack: { id: caveman-local, version: 2.2.0, protocol: 1, core_source: native-core.md, core_prompt_token_budget: 560, targets: [claude, codex, hermes, gemini, opencode, aider] } }其中三个字段定义了 Core 的身份core_source指向唯一的权威来源文件skills/native-core.md且 skills/compile.mjs 明确禁止该字段包含路径分隔符防止指向仓库其他位置core_prompt_token_budget: 560是 token 预算上限targets枚举了六个宿主。编译产物中 Core 被标记为mandatory: true见 skills/generated/claude/pack.json 的core.mandatory字段意味着它不是可选项——宿主注入任务技能时Core 必须先行在场。Native Core 与 Caveman 的其他技能如caveman输出压缩、caveman-explore只读探索等 CLI 交付技能是两套并行的交付通道前者走delivery: [cli]经agent-skills.generated.ts进入 CLI后者走delivery: [native]经 native pack 进入各 Agent 宿主的钩子系统。本文聚焦后者且只以 native-core.md 的内容为核心。策略全文16 行文本的逐段解读下面给出 skills/native-core.md 的完整原文与编译产物 skills/generated/claude/pack.json 中core.instructions逐字节一致可交叉验证Build simplest complete system. Trace behavior and invariants before editing. System, user, and repository instructions outrank this default. Consider in order; accept first with correctness and architectural fit without distortion: 1. Required behavior already exists: reuse it or change nothing. 2. Responsible layer, type, helper, or pattern owns it: extend there. 3. Standard library, native platform, browser, database, runtime, or installed dependency owns it: use it. 4. Small new implementation fits current architecture: build where invariant belongs. 5. Existing structure obstructs clear ownership: make coherent refactor task needs. Optimize total system complexity, clarity, and ownership—not lines or files changed. Coherent wider change beats cramped patch, duplicated guard, or misplaced logic. Reuse fitting abstractions; do not contort code to avoid abstraction. Prefer consolidation. Fix root cause. Avoid speculative features and extension points, single-implementation interfaces, configuration for fixed values, premature services, and imagined scaffolding. Dependency or public surface is valid for correct design or lower lifecycle cost; explain material tradeoff. Simplicity never removes trust-boundary validation, authorization, security,>const coreEstimatedTokens Math.ceil(Buffer.byteLength(nativeCore) / 3); if (coreEstimatedTokens nativePackMeta.core_prompt_token_budget) { die(native Core exceeds conservative token estimate: ${coreEstimatedTokens} ${nativePackMeta.core_prompt_token_budget}); }估算基础是ceil(utf8_bytes / 3)即 3 字节 ≈ 1 token 的保守换算编译产物中该口径被显式记录为estimate_basis: ceil_utf8_bytes_divided_by_3。当前 skills/native-core.md 全文约 1668 字节估算约 556 token低于 560 的预算上限skills/generated/claude/pack.json 中estimated_tokens: 556与prompt_token_budget: 560可以查证。一旦有人修改 Core 文本使其超出预算die()会直接让编译失败——这是 fail-closed 设计预算超支的 Core 绝不会被分发。加载期闸门在 Go 侧的 proxy/internal/nativepack/pack.go。native pack 的 JSON 被//go:embed内嵌进二进制pack.govalidate在Load()的sync.Once内对运行时副本做同构校验if !pack.Core.Mandatory || pack.Core.Instructions || pack.Core.EstimatedTokens pack.Core.PromptTokenBudget { return errors.New(native pack: invalid Core budget or instructions) }即 Core 必须为强制项、指令非空、且估算 token 不超预算——与编译期完全相同的三条约束在运行时再验一遍。测试用例 proxy/internal/nativepack/pack_test.go 固化了这组不变量。这种双闸门的意义在于即使有人绕过编译直接手改生成的 JSON生成文件头部都标有GENERATED ... DO NOT EDIT运行时也会拒绝加载。对 Agent 策略这类每次会话都进上下文的内容token 预算就是硬成本治理必须到可执行的程度。编译与多宿主分发从单一 Markdown 到六个宿主的钩子skills/compile.mjs 是整个 native 交付链的单一入口其流程为校验registry.json→ 读取 Core 与每个 native 技能的 SKILL.md 正文 → 通过 skills-verbs 门技能不得引用不存在的 CLI 命令/MCP 工具/SDK 调用见 compile.mjs→ 输出四路产物。与 Native Core 相关的产物路径如下产物路径消费方TypeScript 嵌入packages/cli/src/native-pack.generated.tsCLINATIVE_PACK/NATIVE_CORE/NATIVE_SKILL_INSTRUCTIONS常量Go 内嵌 JSONproxy/internal/nativepack/native-pack.generated.json本地代理//go:embed各宿主 packskills/generated/claude/pack.json、skills/generated/codex/pack.json 等六个目录各宿主 Agent 的安装/注入流程编译产物中Core 与任务技能被组装为caveman.native-pack.v1schemacompile.mjs其中core块携带source、mandatory、prompt_token_budget、estimated_tokens、estimate_basis与完整指令文本。真正的多宿主差异体现在targets的激活钩子映射上。skills/compile.mjs 为每个宿主硬编码了 Core 与任务技能各自的注入时机编译结果以 skills/generated/claude/pack.json 为准宿主Core 注入点任务技能注入点claudeSessionStartUserPromptSubmitcodexdeveloper_instructionsSessionStartUserPromptSubmithermespre_llm_callpre_llm_callgeminiBeforeAgentBeforeAgentopencodeexperimental.chat.system.transformchat.messageaiderread_only_conventionsnative_repository_map_authoritative从这张映射可以看出 Core 的分发策略在每个宿主中Core 都选择会话最早、最贴近系统提示层的位置注入SessionStart、developer_instructions、pre_llm_call 等确保它在任何任务技能之前进入上下文而任务技能则在用户提交提示时按分类结果注入。Aider 的注入方式最为特殊——从 packages/cli/src/index.ts 可以看到Aider 的 Core 文本被包在一个带标记的块中写入其约定文件const AIDER_NATIVE_CORE_MARKER !-- caveman:native-aider-core --; // ... return ${AIDER_NATIVE_CORE_MARKER}\n${NATIVE_CORE}\n\nHost limits: Aider repository map remains authoritative. ...;该标记同时用于回读时判断当前文件中的 Core 是否由 Caveman 拥有index.ts避免覆盖用户对约定文件的自行修改。另外 CLI 还暴露了think.core配置开关index.ts 的提示文本给出了caveman tools config set think.core off的用法允许用户在静态启用的 Core 上整体开/关且提示start new session to clear delivered context——即已注入的上下文需要新会话才会清除。这印证了 Core 的定位它是默认开启的策略基线用户可以显式退出。Native Core 与六个任务技能分类、优先级与 fail-closed 选择Native Core 从不单独行动它与六个delivery: [native]的任务技能组成完整策略包。这六个技能都在 skills/registry.json 中登记其元数据被编译进各宿主 pack示例见 skills/generated/claude/pack.json 的skills数组技能 idtask_type字节预算进入条件停止条件关键护栏guardrailsinvestigate-firstinvestigation900cause is ambiguous原因或确切阻塞点有证据支撑no_edit_before_credible_hypothesis; diagnosis_does_not_authorize_fixlean-buildfeature900task adds product behavior聚焦的验收证明通过core_architecture_first_simplicity; preserve_correctness_controls; justify_material_tradeoffsmigrationmigration950任务改变持久化或公开形态请求的迁移阶段通过且无隐式收缩preserve_rollback; preserve_data; verify_compatibilitysafe-refactorrefactor900请求结构变更但不改变行为前后证明一致preserve_behavior; keep_intermediate_states_testablesurgical-patchbugfix850任务修正错误行为故障已修复且回归证明通过avoid_unrelated_cleanup; preserve_surrounding_behaviorverify-and-stopverification850任务要求证明或完成度验证验收证明完整no_unrequested_product_edit; report_unavailable_proof_exactly每个 native 技能元数据都要求activation: classified即注入前提是宿主先对任务做了分类compile.mjs 对非 classified 激活直接拒绝见 skills/compile.mjs并且指令正文的字节数不得超过prompt_byte_budgetskills/compile.mjs。Core 与技能之间是明确的分层lean-build的指令开篇即写Native Cores architecture-first simplicity remains mandatory护栏里也把core_architecture_first_simplicity放在第一位——Core 是基线技能是基线之上的任务特化。运行时如何选择技能proxy/internal/nativepack/pack.go 的Select(taskType)按 task_type 匹配并在多个候选中取最高precedence当前六个技能均为 100因为编译期要求同一 task_type 下的冲突对必须互报 conflicts 且 precedence 不同——目前每个 task_type 只有唯一属主约束为未来扩展预留。关键是它的 fail-closed 行为无法匹配的 task_type 返回(Skill{}, false)调用方落回 Core。这一点被测试固化if _, ok : Select(review); ok { t.Fatal(unowned task type must fail closed to Core) }proxy/internal/nativepack/pack_test.go。也就是说分类失败时系统不会注入任何技能、也不会报错阻塞而是只有 Core 在场——Core 因此必须自身构成一份完整可执行的策略这正是它 16 行内覆盖决策、优化、安全与验收四个维度而不依赖任何技能的原因。对 Agent 行为的实际约束一条可验证的因果链把以上证据串起来Native Core 在 Caveman 中的完整因果链是单一来源skills/native-core.md 是唯一权威文本skills/registry.json 的core_source字段指认它编译器拒绝其他来源路径校验compile.mjs。预算闸门编译期按ceil(bytes/3)估算并与 560 对比超限即编译失败运行时 Go 侧再验一遍pack.go。编译分发Core 文本连同六个任务技能、目标钩子映射一起被编译进 CLI 的 TypeScript 嵌入、Go 的 embed JSON 与六个宿主的 pack.jsonCLI 与代理都不手抄提示词skills/compile.mjs 文件头注释。运行时注入按各宿主的激活钩子在会话最早期注入 Core任务技能按 classified 分类注入未分类的任务 fail-closed 落回 Core。策略内容五级阶梯压低写新代码的优先级反投机清单约束抽象膨胀安全豁免段保住十一类工程控制最小证明条款定义验收与汇报边界。从源码结构看这套设计把希望 Agent 怎么写代码从一个模糊的价值观问题转化成了三个可机械验证的契约token 预算不超数字比较、schema 与冲突规则成立validate、预算与行为测试通过pack_test.go。策略文本本身只允许在预算内演化任何扩写都必须先通过编译闸门。相关路径索引策略权威来源skills/native-core.md登记与预算元数据skills/registry.json编译器校验 产物生成skills/compile.mjs各宿主编译产物skills/generated/claude/pack.json、skills/generated/codex/pack.json、skills/generated/gemini/pack.json、skills/generated/hermes/pack.json、skills/generated/opencode/pack.json、skills/generated/aider/pack.jsonCLI 侧嵌入与注入packages/cli/src/native-pack.generated.ts、packages/cli/src/index.tsAider 标记块见 L7026 附近代理侧加载与选择proxy/internal/nativepack/pack.go、proxy/internal/nativepack/pack_test.go、proxy/internal/nativepack/native-pack.generated.json【免费下载链接】caveman why use many token when few token do trick — Claude Code skill that cuts 65% of tokens by talking like caveman项目地址: https://gitcode.com/GitHub_Trending/caveman1/caveman创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
分享:

看完干货,该让你的企业上线了

免费需求沟通 · 48 小时内出具建站方案 · 河南本地可上门