Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/installer-targets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ describe('Installer targets — partial-state idempotency', () => {
expect(body).toContain('model:\n default: qwen-3.7');
expect(body).toContain('mcp_servers:\n other:\n command: other');
expect(body).toContain(' codegraph:\n command: codegraph');
expect(body).toContain(' - hermes-cli');
expect(body).toContain(' - mcp-codegraph');
expect(body).toContain(' - hermes-cli');
expect(body).toContain(' - mcp-codegraph');
expect(body).toContain(' discord:\n - hermes-discord');

const second = hermes.install('global', { autoAllow: true });
Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions src/installer/targets/hermes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Detect sibling keys that have inline YAML values

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 like removeCodeGraphMcpServer()/upsertCodeGraphMcpServer() and upsertCodeGraphToolset() 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 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle quoted and numeric sibling YAML keys

The new boundary check in childRange() assumes sibling keys must match [A-Za-z_][A-Za-z0-9_-]*, but YAML allows keys like 'x.y': and 1st:. In files that use those valid key forms under mcp_servers or platform_toolsets, range detection runs past the actual sibling boundary, so install/uninstall can splice through unrelated sections instead of only the target child block.

Useful? React with 👍 / 👎.

end = i;
break;
}
Expand Down Expand Up @@ -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');
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down