Skip to content

Migrate JSONC reader + line locators to agent-gov-core@v0.1.1#40

Merged
Conalh merged 1 commit into
mainfrom
migrate-jsonc-locators-to-agent-gov-core
May 22, 2026
Merged

Migrate JSONC reader + line locators to agent-gov-core@v0.1.1#40
Conalh merged 1 commit into
mainfrom
migrate-jsonc-locators-to-agent-gov-core

Conversation

@Conalh
Copy link
Copy Markdown
Owner

@Conalh Conalh commented May 22, 2026

Summary

  • Replaces local stripJsonComments, stripTrailingCommas, lineOfJsonKey, and lineOfJsonStringValue with the shared primitives from agent-gov-core@v0.1.1.
  • Mirrors the same migration ScopeTrail did in Pin ScopeTrail v0.1.10 #35.
  • Net change: −238 / +33 lines. src/discovery.ts shrinks from 207 to 91 lines and stops duplicating logic that now lives in one place.

What stays local

  • Async readJsonObjectWithSource wrapper with ENOENT → empty-object semantics (PolicyMesh runs against repos that haven't adopted these surfaces yet).
  • JsonParseError = { message, line } shape — parsers/* and errors.ts depend on it. line is still derived from SyntaxError's position N.

Action-time install

action.yml now npm ci --omit=dev --no-audit --no-funds before invoking the bundled CLI, so the new agent-gov-core runtime import resolves. Same change ScopeTrail made. The workflow.test.mjs assertion is loosened from "no npm ci" to "no npm run build" — dist/ is still committed.

Test plan

  • npm test — all 38 tests pass locally against the migrated reader
  • CI green on this PR
  • Self-dogfood workflow still passes (PolicyMesh workflow self-dogfoods the action test was untouched)

🤖 Generated with Claude Code

Replaces local copies of stripJsonComments, stripTrailingCommas,
lineOfJsonKey, and lineOfJsonStringValue with the shared primitives.
This is the same migration ScopeTrail PR #35 did — PolicyMesh's
discovery.ts now delegates parsing/location logic to agent-gov-core
and keeps only PolicyMesh-specific behavior:
  - async wrapper with ENOENT → empty object (PolicyMesh runs against
    repos that haven't adopted these surfaces yet)
  - JsonParseError = { message, line } shape that the parsers/* layer
    depends on (line is derived from SyntaxError 'position N')

The action now `npm ci --omit=dev` so runtime imports resolve at
action invocation time — same change ScopeTrail made. Loosened the
workflow.test.mjs assertion from "no npm ci" to "no npm run build";
dist/ is still committed and consumers still skip the TypeScript
compile.

All 38 existing tests pass against the migrated reader.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@Conalh Conalh merged commit 8b9a639 into main May 22, 2026
4 checks passed
@Conalh Conalh deleted the migrate-jsonc-locators-to-agent-gov-core branch May 22, 2026 14:07
Conalh added a commit that referenced this pull request May 22, 2026
Closes the false-positive class flagged in the PolicyMesh audit:
two surfaces that differ only in cosmetically neutral ways
(`npx -y <pkg>` vs `npx <pkg>`, `.cmd` vs unsuffixed, flag
reordering) were being reported as high-severity command mismatches.

What changed
- McpServer gains a `canonicalIdentity: string` field, computed by
  agent-gov-core@v0.1.2's normalizeMcpCommand from (command, args,
  url). Both the JSON and Codex TOML parsers populate it.
- `detectMcpCommandMismatch` now groups by `canonicalIdentity` instead
  of the raw joined `command` string. The human-readable command list
  in the finding message still uses `command` so the finding stays
  actionable.
- Env is deliberately omitted from `canonicalIdentity`. Env drift has
  its own detector (mcp_env_mismatch); including env here would have
  surfaced two findings for what users perceive as one issue (and
  broke the mcp-env-value-mismatch fixture test).

Regression test pinned
`mcp-command-neutral-flag-equivalence` fixture: root MCP runs
`npx -y @modelcontextprotocol/server-github@1.2.3`, Cursor runs the
same without `-y`. Before this change the audit emitted a
high-severity mcp_command_mismatch finding; after it emits none. Test
'CLI does not flag mcp_command_mismatch on neutral -y flag drift
between surfaces' asserts the post-fix behavior — it fails on the
pre-fix engine, passes here.

39 PolicyMesh tests pass. Stacked on #40 (JSONC migration); merge
that one first.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Conalh added a commit that referenced this pull request May 22, 2026
Closes the false-positive class flagged in the PolicyMesh audit:
two surfaces that differ only in cosmetically neutral ways
(`npx -y <pkg>` vs `npx <pkg>`, `.cmd` vs unsuffixed, flag
reordering) were being reported as high-severity command mismatches.

What changed
- McpServer gains a `canonicalIdentity: string` field, computed by
  agent-gov-core@v0.1.2's normalizeMcpCommand from (command, args,
  url). Both the JSON and Codex TOML parsers populate it.
- `detectMcpCommandMismatch` now groups by `canonicalIdentity` instead
  of the raw joined `command` string. The human-readable command list
  in the finding message still uses `command` so the finding stays
  actionable.
- Env is deliberately omitted from `canonicalIdentity`. Env drift has
  its own detector (mcp_env_mismatch); including env here would have
  surfaced two findings for what users perceive as one issue (and
  broke the mcp-env-value-mismatch fixture test).

Regression test pinned
`mcp-command-neutral-flag-equivalence` fixture: root MCP runs
`npx -y @modelcontextprotocol/server-github@1.2.3`, Cursor runs the
same without `-y`. Before this change the audit emitted a
high-severity mcp_command_mismatch finding; after it emits none. Test
'CLI does not flag mcp_command_mismatch on neutral -y flag drift
between surfaces' asserts the post-fix behavior — it fails on the
pre-fix engine, passes here.

39 PolicyMesh tests pass. Stacked on #40 (JSONC migration); merge
that one first.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant