-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(hermes): preserve YAML list indentation (2-space flush style) #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,7 +177,15 @@ function childRange(lines: string[], parent: LineRange, child: string): LineRang | |
| for (let i = start + 1; i < parent.end; i++) { | ||
| const line = lines[i] ?? ''; | ||
| if (line.trim() === '') continue; | ||
| if (/^ \S/.test(line)) { | ||
| // YAML allows both: | ||
| // cli: | ||
| // - file | ||
| // and: | ||
| // cli: | ||
| // - file | ||
| // A line beginning with " -" is still part of the current child, not | ||
| // the next platform key. Only a sibling mapping key ends this child. | ||
| if (/^ [A-Za-z_][A-Za-z0-9_-]*:\s*(?:#.*)?$/.test(line)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new boundary check in Useful? React with 👍 / 👎. |
||
| end = i; | ||
| break; | ||
| } | ||
|
|
@@ -248,6 +256,14 @@ function removeCodeGraphMcpServer(content: string): string { | |
| return joinLines(lines); | ||
| } | ||
|
|
||
| function listItemIndent(lines: string[], range: LineRange, fallback: string): string { | ||
| for (const line of lines.slice(range.start + 1, range.end)) { | ||
| const match = /^(\s*)-\s+/.exec(line); | ||
| if (match) return match[1] ?? fallback; | ||
| } | ||
| return fallback; | ||
| } | ||
|
|
||
| function upsertCodeGraphToolset(content: string): string { | ||
| const lines = splitLines(content); | ||
| const parent = topLevelRange(lines, 'platform_toolsets'); | ||
|
|
@@ -261,7 +277,7 @@ function upsertCodeGraphToolset(content: string): string { | |
| } | ||
|
|
||
| if (!cli) { | ||
| lines.splice(parent.end, 0, ' cli:', ' - hermes-cli', ' - mcp-codegraph'); | ||
| lines.splice(parent.end, 0, ' cli:', ' - hermes-cli', ' - mcp-codegraph'); | ||
| return joinLines(lines); | ||
| } | ||
|
|
||
|
|
@@ -270,7 +286,8 @@ function upsertCodeGraphToolset(content: string): string { | |
| .some((line) => line.trim() === '- mcp-codegraph'); | ||
| if (hasEntry) return joinLines(lines); | ||
|
|
||
| lines.splice(cli.end, 0, ' - mcp-codegraph'); | ||
| const indent = listItemIndent(lines, cli, ' '); | ||
| lines.splice(cli.end, 0, `${indent}- mcp-codegraph`); | ||
| return joinLines(lines); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new sibling-boundary regex only matches lines like
" key:"and ignores valid siblings such as" other: { ... }"or" discord: [ ... ]". In those configs,childRange()no longer stops at the next sibling, so calls likeremoveCodeGraphMcpServer()/upsertCodeGraphMcpServer()andupsertCodeGraphToolset()can treat subsequent sibling entries as part of the current block, leading to accidental deletion or malformed insertion when rewriting the file.Useful? React with 👍 / 👎.