KilimcininKorOglu/claude-code-mods/tree/main/plugins/config-parse
config-parse
解析编辑或写入触及的每个 JSON、YAML、TOML 或 .env 文件,立即记录解析错误,而不是在下一次构建时记录,并在稍后的编辑修复该错误时再次说明。
关于这个 mod
配置解析
package.json 中缺少的逗号或 YAML 文件中的错误缩进在创建时不会产生任何费用;您会在下一次构建或服务拒绝启动时发现,通常与导致它的编辑相距甚远。该 mod 在编辑或写入触及每个 JSON、YAML、TOML 或 .env 文件后立即解析它,并当场告诉模型有关解析错误的信息。
它的作用
/config-parse on or off, the mode, and the files that do not parse
/config-parse on | off on by default
/config-parse mode note note only; the default
/config-parse mode deny a commit, a push and a merge also stop while a file does not parse
Q。每次编辑或写入引擎运行后,它都会查看路径。解析 .json、.jsonc、.yml、.yaml、.toml、.env 或 .env.<name> 文件;所有其他文件都保持原样。他们自己的工具读取为带有注释的 JSON 的文件(.jsonc、tsconfig*.json、jsconfig*.json、.vscode/*.json、devcontainer.json)可能包含 // 和 /* */ 注释和尾随逗号。所有其他 JSON 文件都会被严格解析。
2。 JSON 由 mod 本身解析。逐行读取 .env 文件:非空、非注释、非 KEY=value(前面有 export 即可)的行是查找结果及其行号。
3。 YAML 和 TOML 由 python3(带有安全加载程序的 yaml.load_all 和 tomllib.load)解析,文件路径作为 one argv 项传递。读取 --- 流的每个文档,并接受 !Ref 或 !vault 等应用程序标记,因为两者都是有效的 YAML。如果 python 或模块丢失,则会话会跳过该类型,并且 one 行会告诉您。
4。未解析的文件将进入 two 通道。该模型会收到一个 context 注释,命名该文件和错误。您会在 侧边栏 流中看到一个红色条目(首先是文件,然后是错误,解析器名称的位置(例如 line 2 或 (line 3, column 5),为黄色)),或者在侧边栏关闭时出现转录行。该文件是相对于会话启动的 git 存储库或存储库外部的会话目录显示的。该根目录会在会话启动时读取一次,因为 Bash cd 会移动会话自己的目录。
5。当稍后的编辑再次解析相同的文件时,常设条目将被清除,并显示一条绿线。该行仅适用于您,因为模型本身修复了文件。当发现的文件被删除时,它会在下一个测量中以相同的方式关闭,即 <file> is gone, and its parse error with it。存在但无法读取的文件会保留其发现结果。
6。它从不否认编辑。文件先写入,后读取。
7。在每个主循环结束时再次测量模型未关闭的结果,剩下的任何内容都会到达模型,如 one 在下一个提示中注释:
config-parse: 1 file(s) still do not parse: package.json. Fix them.
即每回合 one 音符,而不是每提示 one。如果没有它,结果就会在编辑时被说一次,然后就坐在窗格中,而模型却忘记了它。您没有读到任何新内容,因为窗格已经显示了相同的发现。
8。在 deny 模式下,当文件不解析时,它还会停止 git commit、git push 和 git merge。在停止 one 之前,它会再次解析每个打开的文件,因此一旦模型修复了它们,该命令就会自行执行。 git commit 只回答它自己的文件:mod 读取索引 (git diff --cached --name-only -z) 并在没有打开的文件时让提交运行,one 行告诉您还有多少个打开的文件。 config-parse: 1 file(s) still do not parse: package.json. Fix them.
Q 和 merge 没有可供读取的索引,因此每个发现都很重要。没有绕过:--dry-run、--help 和 -h 通过,但损坏文件的真正提交等待修复。 note 模式是默认模式,不会停止任何操作。
在实时检查中,用尾随逗号破坏的 JSON 文件得到了注释 (Property name must be a string literal),用 a: 1: 2 破坏的 YAML 文件得到了 python 错误,而 a: 1 的下一个写入则用 parses as YAML again 结束了发现。
命令
/config-parse on or off, the mode, and the files that do not parse
/config-parse on | off on by default
/config-parse mode note note only; the default
/config-parse mode deny a commit, a push and a merge also stop while a file does not parse
安装
claude plugin marketplace add KilimcininKorOglu/claude-code-mods
claude plugin install config-parse@kilimcininkoroglu-mods
函数钩子是抢先体验的。 Claude Code 2.1.288 以及后来默认加载它们,所以没有什么可以打开的。
安装后
1。使用 PyYAML 安装 python3 以进行 YAML 检查 (python3 -m pip install pyyaml)。 TOML 只需要 python 3.11 或更新版本。如果没有它们,那些 two 类型将被跳过; JSON 和 .env 仍然有效。
2。重新启动Claude Code。
它可以达到什么
在 Claude Code 2.1.283 上使用 claude plugin validate 进行验证:
❯ ./register.ts hooks: session.start, command.run{command=config-parse}, tool.call{tool=Edit}, tool.call{tool=Write}, turn.complete, prompt.submit, tool.call{tool=Bash}
❯ ./register.ts calls: $.command.register, $.fs.exists (via isGone), $.fs.read (via fileText), $.process.run (via pythonCheck, shownRootOf, stagedPaths), $.session.cwd, $.sidebar.clear (via closeOne), $.sidebar.set (via toPerson), $.store.get (via readSettings), $.store.set (via runCommand, setMode), $.ui.log
到达 L2:它读取文件并运行进程。
1. Reads: the path of each Edit and Write, the command of each Bash call, and the text of the edited JSON and .env files, and each open file again at the turn's end
2. Runs: python3 -c, by argv, on YAML and TOML files; git rev-parse --show-toplevel once at the session's start, to name files against the repository root; and git rev-parse --show-toplevel plus git diff --cached --name-only -z at a commit in deny mode
3. Sends: the file name and the parse error to the model, and one more note with the next prompt while a finding stands; nothing leaves the machine
4. Persists: the on/off setting and the mode in $.store
5. Hostile input: the path comes from the tool call and reaches python as one argv item, never through a shell; the python program is fixed text and reads sys.argv[1]
限制
- 检查在写入后运行,因此损坏的文件一直存在,直到下一次编辑修复它为止。任何编辑都不会被拒绝;在
deny模式下只有提交、推送和合并停止。 deny模式没有旁路。当无法修复问题时,可以使用/config-parse mode note关闭门。- git 命令通过包装器、别名或脚本运行,当
git commit|push|merge通过大门时,mod 无法读取这些命令。 git commit -a、-am和--之后带有路径规范的提交不会缩小到索引,因为它们提交索引尚未保存的文件。每一个公开的发现都很重要。- 在命令运行之前读取索引。文件在读取和运行之间发生变化的提交是根据读取时索引所保存的内容来衡量的。
- 仅检查
.env线的形状。错误的值、缺少的引号或重复的键都不是结果。 - Mod 不知道其名称下带有注释的 JSON 文件是带有注释的 JSON(项目 1 列表之外的
.json名称)被报告为损坏,因为该名称被严格读取。- YAML和TOML需要python3;在没有它的机器上,这些文件永远不会被检查。 - 在“编辑和写入”之外进行的编辑(例如由 Bash
sed进行的编辑)不会被看到。
发展
make install # eslint, typescript-eslint, typescript
make lint # complexity limit 10, the build fails above it
make typecheck # needs .claude/types/ from /plugin-types
make validate
make test # claude plugin test
安装
请先查看作者 README 确认 marketplace 和插件名称;命令可能随仓库结构改变。
claude plugin marketplace add KilimcininKorOglu/claude-code-mods claude plugin install config-parse
原文 / README
config-parse
A missing comma in package.json or a bad indent in a YAML file costs nothing at the moment it is made; you find out at the next build, or when a service refuses to start, often far from the edit that caused it. This mod parses every JSON, YAML, TOML or .env file right after an Edit or Write touches it, and tells the model about a parse error on the spot.
What it does
-
After each Edit or Write the engine ran, it looks at the path. A
.json,.jsonc,.yml,.yaml,.toml,.envor.env.<name>file is parsed; every other file is left alone. Files their own tool reads as JSON with comments (.jsonc,tsconfig*.json,jsconfig*.json,.vscode/*.json,devcontainer.json) may hold//and/* */comments and trailing commas. Every other JSON file is parsed strictly. -
JSON is parsed by the mod itself. A
.envfile is read line by line: a line that is not empty, not a comment and notKEY=value(anexportin front is fine) is the finding, with its line number. -
YAML and TOML are parsed by
python3(yaml.load_allwith a safe loader, andtomllib.load), with the file path passed as one argv item. Every document of a---stream is read, and application tags such as!Refor!vaultare accepted, because both are valid YAML. If python or the module is missing, that kind is skipped for the session and one line tells you. -
A file that does not parse goes to two channels. The model gets a
contextnote naming the file and the error. You get a red entry in the sidebar stream (the file first, then the error, with the position the parser names, such asline 2or(line 3, column 5), in yellow), or a transcript line when the sidebar is closed. The file is shown relative to the git repository the session started in, or to the session's directory outside a repository. That root is read once at the session's start, because a Bashcdmoves the session's own directory. -
When a later edit makes the same file parse again, the standing entry is cleared and a green line says so. That line goes to you only, because the model fixed the file itself. A file deleted while its finding stands closes the same way at the next measure, with
<file> is gone, and its parse error with it. A file that is there but cannot be read keeps its finding. -
It never denies an edit. The file is written first, then read.
-
A finding the model did not close is measured again at the end of each main-loop turn, and whatever is left reaches the model as one note with your next prompt:
config-parse: 1 file(s) still do not parse: package.json. Fix them.That is one note per turn, not one per prompt. Without it the finding would be said once, at the edit, and then sit in the pane while the model forgot about it. You read nothing new, because the pane already shows the same finding.
-
In
denymode it also stopsgit commit,git pushandgit mergewhile a file does not parse. Before stopping one it parses every open file again, so the command goes through by itself once the model fixed them. Agit commitanswers for its own files alone: the mod reads the index (git diff --cached --name-only -z) and lets the commit run when it holds none of the open files, with one line telling you how many still stand. Apushand amergehave no index to read, so every finding counts there. There is no bypass:--dry-run,--helpand-hpass, but a real commit of a broken file waits for the fix.notemode is the default and stops nothing.
In the live check a JSON file broken with a trailing comma got the note (Property name must be a string literal), a YAML file broken with a: 1: 2 got the python error, and the next Write of a: 1 closed the finding with parses as YAML again.
Command
/config-parse on or off, the mode, and the files that do not parse
/config-parse on | off on by default
/config-parse mode note note only; the default
/config-parse mode deny a commit, a push and a merge also stop while a file does not parse
Install
claude plugin marketplace add KilimcininKorOglu/claude-code-mods
claude plugin install config-parse@kilimcininkoroglu-mods
Function hooks are early access. Claude Code 2.1.288 and later load them by default, so there is nothing to switch on.
After installing
- Install
python3with PyYAML for the YAML check (python3 -m pip install pyyaml). TOML only needs python 3.11 or newer. Without them those two kinds are skipped; JSON and.envstill work. - Restart Claude Code.
What it can reach
Validated with claude plugin validate on Claude Code 2.1.283:
❯ ./register.ts hooks: session.start, command.run{command=config-parse}, tool.call{tool=Edit}, tool.call{tool=Write}, turn.complete, prompt.submit, tool.call{tool=Bash}
❯ ./register.ts calls: $.command.register, $.fs.exists (via isGone), $.fs.read (via fileText), $.process.run (via pythonCheck, shownRootOf, stagedPaths), $.session.cwd, $.sidebar.clear (via closeOne), $.sidebar.set (via toPerson), $.store.get (via readSettings), $.store.set (via runCommand, setMode), $.ui.log
Reach L2: it reads files and runs a process.
1. Reads: the path of each Edit and Write, the command of each Bash call, and the text of the edited JSON and .env files, and each open file again at the turn's end
2. Runs: python3 -c, by argv, on YAML and TOML files; git rev-parse --show-toplevel once at the session's start, to name files against the repository root; and git rev-parse --show-toplevel plus git diff --cached --name-only -z at a commit in deny mode
3. Sends: the file name and the parse error to the model, and one more note with the next prompt while a finding stands; nothing leaves the machine
4. Persists: the on/off setting and the mode in $.store
5. Hostile input: the path comes from the tool call and reaches python as one argv item, never through a shell; the python program is fixed text and reads sys.argv[1]
Limits
- The check runs after the write, so a broken file exists until the next edit fixes it. No edit is ever denied; in
denymode only a commit, a push and a merge stop. - The
denymode has no bypass. When a finding cannot be fixed, you turn the gate off with/config-parse mode note. - A git command run through a wrapper, an alias or a script that the mod cannot read as
git commit|push|mergepasses the gate. - A
git commit -a, a-amand a commit with a pathspec after--are not narrowed to the index, because they commit files the index does not hold yet. Every open finding counts for those. - The index is read before the command runs. A commit whose files change between that read and the run is measured against what the index held at the read.
- A
.envline is checked for its shape only. A wrong value, a missing quote or a duplicate key is not a finding. - A JSON file with comments under a name the mod does not know as JSON with comments (a
.jsonname outside the list in item 1) is reported as broken, because that name is read strictly. - YAML and TOML need
python3; on a machine without it those files are never checked. - An edit made outside Edit and Write, for example by a Bash
sed, is not seen.
Development
make install # eslint, typescript-eslint, typescript
make lint # complexity limit 10, the build fails above it
make typecheck # needs .claude/types/ from /plugin-types
make validate
make test # claude plugin test
