Externalize emitted-artifact templates and the CLI command table into data files - #100
Merged
Merged
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| preserves local edits. | ||
| """ | ||
| _SCAFFOLD_DATA_DIR = package_data_dir("chock.scaffold", "data") | ||
| _GITATTRIBUTES_TEMPLATE = _SCAFFOLD_DATA_DIR.joinpath("gitattributes.txt").read_text(encoding="utf-8") |
Every emitted-artifact template written in a language other than Python
(YAML, shell, PowerShell, and the vendored-runtime Python-source fragments)
moves out of Python string literals into template files under each
package's own data/ directory, loaded via importlib.resources and rendered
with __TOKEN__ + str.replace instead of .format() -- so each template file
is valid in its own language as committed and CI lints it that way
(shellcheck, actionlint).
Covers: compile/emitters/{ci,git_hook,in_agent}.py, hooks/installers.py,
scaffold/{install_ci,templates,agents_md}.py, gate/runtime_bundle.py.
Emitted bytes are unchanged, proven by the existing emitter-stability
goldens, this repo's own `chock sync --check`, and new token round-trip
tests. New package-data and PyInstaller coverage tests guard every new
data/ directory.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Signed-off-by: Claude <noreply@anthropic.com>
Compact hard-rule entry beside code_comments, mirroring the owner standard (plan/coding-standards.md, externalize-dont-hardcode): non-Python text and vendor facts live in data/template files read by code, token placeholders swapped by str.replace, template files linted as their own language, package-data and frozen-binary coverage tested, error messages stay beside their raising condition, behaviour stays code. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
The COMMANDS table (name -> module path, help/alias text) is a table of facts, not code: it moves to data/commands.json (grouped everyday/ authoring/aliases, preserving order), read once at import time to build EVERYDAY/AUTHORING/ALIASES/COMMANDS. Lazy-import (_module_main/_module_fn) behaviour is unchanged. `chock --help` output is byte-identical (golden in tests/fixtures/cli_help_golden.txt); a new test asserts every module path in the table imports and exposes its entry point. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Claude <noreply@anthropic.com>
open-coder-ai
force-pushed
the
w48/emitter-templates-to-data
branch
from
September 2, 2026 02:13
dcb59f2 to
71c89ea
Compare
open-coder-ai
marked this pull request as ready for review
September 2, 2026 02:24
5 tasks
Owner
Author
|
The CodeQL finding on Generated by Claude Code |
open-coder-ai
added a commit
that referenced
this pull request
Sep 2, 2026
…-rename-and-bridge-marker Follow-up to #100: fix CodeQL finding, externalize the bridge marker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Applies the owner's "externalize, don't hardcode" standard (
plan/coding-standards.md§2) toevery emitted-artifact template that was previously a Python string literal. Three fronts, one
PR (per brief
plan/spine-a/briefs/w48-chock-templates-to-data.md):Templates out of Python source, into a single
src/chock/data/templates/tree (thebrief's suggested path), read via
chock.resources.template_text/render_templateandrendered with
__TOKEN__+str.replace(never.format()), so each template file is validin its own language as committed:
compile/emitters/ci.py(CI-gate step YAML),git_hook.py(git-hook shim, bash)compile/emitters/in_agent.py(bash + PowerShell one-liners)hooks/installers.py(dispatcher + two wrapper scripts, sh)scaffold/install_ci.py(scaffolded CI workflow YAML),templates.py(three config-filescaffolds),
agents_md.py(pointer block)scaffold/skills_bridge.py(the bridge-directory marker body)gate/runtime_bundle.py(vendored-runtime Python-source fragments, as.py.tmpl)Out of scope by owner decision: error/diagnostic message strings (stay beside the condition
that raises them) and plugin posture prose (
plugin/posture.pyand per-store descriptions —C1/C3 derive those).
AGENTS.md gains a compact
externalized_texthard rule recording the standard, besidecode_comments.cli.py'sCOMMANDStable becomes data. The name → (module, help/alias) table moves todata/commands.json(grouped, order preserved), read once at import time; lazy-import(
_module_main/_module_fn) behaviour is unchanged.Proof of byte-identical output
tests/test_template_data.py: every template renders, every__TOKEN__round-trips betweenfile and renderer (no orphan, no missing), Python
.tmplfragments parse, ownership markerssurvive.
tests/test_emitter_stability.py(existing goldens) and the runtime-bundle goldens passunchanged.
chock sync, then.chock/,.claude/,.cursor/,.github/hooks/compared byte-for-byte betweenthis repo's pre-change state (
25d9e96) and this branch, pluschock plugin build --format allandchock marketplace build(all three vendor trees) compared the same way — zerobytes differ anywhere (
gate-events.jsonlexcluded, as specified).chock --helpoutput is byte-identical, golden-pinned (tests/fixtures/cli_help.txt); everymodule path in
commands.jsonimports and exposes its entry point(
tests/test_cli_commands.py).Package-data / frozen-binary coverage
pyproject.toml:"chock" = ["data/*.json", "data/templates/**/*"].tests/test_wheel_install.py: the built wheel ships every file underdata/templates/(verified directly against a real wheel build).
packaging/chock.spec's existingcollect_data_files("chock")needed no changes — verifieddirectly (not assumed) that it already reaches every file under
data/templates/; the CIbinary smoke greps the rendered pointer block to prove a frozen-binary template read.
CI linting of templates
New
template-lintjob:shellcheck(via theshellcheck-pyPyPI wheel, hash-pinned like everyother tool in this repo) on the shell templates,
actionlint(viaactionlint-py) on thecomplete scaffolded CI workflow template — not the ci-gate step fragment, since actionlint needs
a complete workflow; the fragment is unit-tested instead.
Note on how this PR came together
This PR's first three commits continue a predecessor session's branch
(
feat/w48-templates-to-data, corrected into my spawn via an orchestrator amendment after I'dalready built an independent, differently-structured implementation of the same brief). I
verified the predecessor's work critically rather than trusting it — reran the full test suite,
chock check,chock sync --check, ruff, the acceptance suite, a real wheel build, a realPyInstaller build/collection check, and the full C2 artifact diff myself from scratch — before
building on it. The one issue I found and fixed on top (last commit): CodeQL flagged
_GITATTRIBUTES_TEMPLATEas an unused global (its leading underscore reads as module-private,but it's genuinely consumed from
scaffold/init.py); renamed to match its two siblings in thesame file, which already use no underscore for the identical cross-module usage.
Definition of done
chock check→ 0 errors, 0 warnings, 0 infoschock check --only matrixpasses (no behavior change)chock sync --repo . --checkcleanchock check --only verifycleanpytest -qgreen (1047 passed, 1 skipped, pre-existing)pytest acceptance/ -c acceptance/pytest.ini --rootdir=acceptancegreen (packaging touched)ruff check .andruff format --check .cleanClaims
templates are stored, not what is emitted or installed;
INSTALLED_SURFACESand thecoverage table are unaffected.
🤖 Generated with Claude Code