diff --git a/README.md b/README.md index 48ba13a..5e05b51 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,17 @@ Disable counting: CD_USAGE_ENABLED=0 ``` +Disable the primer by itself, leaving counting and guide seeding in place: + +```bash +CD_PRIMER=0 +``` + +The primer is fixed cost paid on every session, and whether it earns that cost +is a question about your workload rather than a claim this project can settle +for you. This switch is what makes it answerable: run the same tasks with it on +and off, and compare. + ## Project guide seeding On the first session inside a Git repository, the plugin creates an empty guide diff --git a/README.zh-CN.md b/README.zh-CN.md index d45dc12..2eb168a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -144,6 +144,16 @@ bash plugins/coding-discipline/hooks/skills-count.sh CD_USAGE_ENABLED=0 ``` +只关闭纪律总纲,保留计数和引导文档生成: + +```bash +CD_PRIMER=0 +``` + +总纲是每个 session 都要付的固定开销。它值不值这个开销,取决于你自己的工作 +负载,不是本项目单方面能替你下结论的事。这个开关的意义就在于让它可被回答: +同样一批任务,开和关各跑一遍,比较结果。 + ## 自动生成项目引导文档 第一次在 Git 仓库中开启 session 时,如果目标文件不存在,插件会创建一份 diff --git a/plugins/coding-discipline/hooks/session-start-skills b/plugins/coding-discipline/hooks/session-start-skills index ea7af2f..fe09384 100755 --- a/plugins/coding-discipline/hooks/session-start-skills +++ b/plugins/coding-discipline/hooks/session-start-skills @@ -66,6 +66,14 @@ seed_agent_doc() { } seed_agent_doc || true +# The primer is the one piece worth isolating: it is fixed cost paid on every +# session, and whether it earns that cost can only be measured by turning it off +# on its own. Counting and seeding already ran above, so this changes nothing but +# the injected text. +case "${CD_PRIMER:-1}" in + 0|false|False|FALSE|no|No|NO|off|Off|OFF) exit 0 ;; +esac + # Cursor uses additional_context; Copilot/SDK uses top-level additionalContext; # Claude Code, Codex, and the default path use # hookSpecificOutput.additionalContext. diff --git a/tests/test-hooks.sh b/tests/test-hooks.sh index ea146b6..05217db 100755 --- a/tests/test-hooks.sh +++ b/tests/test-hooks.sh @@ -174,4 +174,31 @@ case "$output" in *'Skill tool'*) fail 'a non-primary host received Claude Code wording' ;; esac +# The primer can be switched off on its own. Measuring what those characters buy +# means changing that one variable and nothing else, so usage counting and guide +# seeding have to survive the opt-out. +repo_primer_off="${TMP_ROOT}/repo-primer-off" +make_repo "$repo_primer_off" +output="$({ + cd "$repo_primer_off" + CD_PRIMER=0 CD_USAGE_LOG="${TMP_ROOT}/usage-primer-off.jsonl" "$HOOK" claude-code +})" +[ -z "$output" ] || fail 'CD_PRIMER=0 still emitted a primer payload' +[ -f "${repo_primer_off}/CLAUDE.md" ] || fail 'CD_PRIMER=0 also suppressed guide seeding' +grep -q '"platform":"claude-code"' "${TMP_ROOT}/usage-primer-off.jsonl" \ + || fail 'CD_PRIMER=0 also suppressed usage counting' + +# Leaving it unset keeps the current behavior. +repo_primer_on="${TMP_ROOT}/repo-primer-on" +make_repo "$repo_primer_on" +output="$({ + cd "$repo_primer_on" + CD_USAGE_ENABLED=0 "$HOOK" claude-code +})" +printf '%s\n' "$output" | assert_json_output +case "$output" in + *'Skill discipline'*) ;; + *) fail 'the default path stopped injecting the primer' ;; +esac + printf 'hook behavior tests passed\n'