From f9cf040cb410ffa277491f11ce473f25a259abbf Mon Sep 17 00:00:00 2001 From: Conal <33135619+Conalh@users.noreply.github.com> Date: Fri, 22 May 2026 09:01:27 -0700 Subject: [PATCH] Migrate line locators to agent-gov-core@v0.1.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirrors the TaskBound #24 and PolicyMesh #40 pattern: replaces the local lineOfJsonKey / lineOfJsonStringValue regex implementations with delegation to agent-gov-core, keeping a thin wrapper that translates core's '0 means not-found' convention back to undefined for the existing call sites. readJsonObjectWithSource stays local (CapabilityEcho's package.json files are real JSON, not JSONC — no need for the core JSONC reader). Pure refactor — no kind-string changes, no behavior changes, 64/64 tests still passing on existing assertions. --- dist/discovery.js | 17 +++++------------ package-lock.json | 11 +++++++++++ package.json | 3 +++ src/discovery.ts | 22 ++++++++-------------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/dist/discovery.js b/dist/discovery.js index e955155..3e5de81 100644 --- a/dist/discovery.js +++ b/dist/discovery.js @@ -1,5 +1,6 @@ import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; +import { lineOfJsonKey as coreLineOfJsonKey, lineOfJsonStringValue as coreLineOfJsonStringValue, } from 'agent-gov-core'; export async function readJsonObject(path) { return (await readJsonObjectWithSource(path)).json; } @@ -23,20 +24,12 @@ export function isRecord(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); } export function lineOfJsonKey(text, key) { - const keyPattern = new RegExp(`"${escapeRegExp(key)}"\\s*:`); - return lineOfPattern(text, keyPattern); + const line = coreLineOfJsonKey(text, key); + return line === 0 ? undefined : line; } export function lineOfJsonStringValue(text, value) { - const encoded = JSON.stringify(value); - return lineOfPattern(text, new RegExp(escapeRegExp(encoded))); -} -function lineOfPattern(text, pattern) { - const lines = text.split(/\r?\n/); - const index = lines.findIndex((line) => pattern.test(line)); - return index === -1 ? undefined : index + 1; -} -function escapeRegExp(value) { - return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + const line = coreLineOfJsonStringValue(text, value); + return line === 0 ? undefined : line; } function isNodeError(error) { return error instanceof Error && 'code' in error; diff --git a/package-lock.json b/package-lock.json index 8f02023..f89a697 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "capabilityecho", "version": "0.1.0", "license": "MIT", + "dependencies": { + "agent-gov-core": "github:Conalh/agent-gov-core#v0.1.2" + }, "bin": { "capabilityecho": "dist/index.js" }, @@ -26,6 +29,14 @@ "undici-types": "~7.16.0" } }, + "node_modules/agent-gov-core": { + "version": "0.1.2", + "resolved": "git+ssh://git@github.com/Conalh/agent-gov-core.git#db05618adbd84a503df9b475c49ad86ff161c62e", + "license": "MIT", + "engines": { + "node": ">=20" + } + }, "node_modules/typescript": { "version": "5.9.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", diff --git a/package.json b/package.json index b50efd1..e84632a 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,9 @@ "build": "tsc -p tsconfig.json", "test": "node --test test/*.test.mjs" }, + "dependencies": { + "agent-gov-core": "github:Conalh/agent-gov-core#v0.1.2" + }, "devDependencies": { "@types/node": "^24.0.0", "typescript": "^5.9.3" diff --git a/src/discovery.ts b/src/discovery.ts index ebe6114..473bbbc 100644 --- a/src/discovery.ts +++ b/src/discovery.ts @@ -1,5 +1,9 @@ import { readFile } from 'node:fs/promises'; import { join } from 'node:path'; +import { + lineOfJsonKey as coreLineOfJsonKey, + lineOfJsonStringValue as coreLineOfJsonStringValue, +} from 'agent-gov-core'; export async function readJsonObject(path: string): Promise> { return (await readJsonObjectWithSource(path)).json; @@ -33,23 +37,13 @@ export function isRecord(value: unknown): value is Record { } export function lineOfJsonKey(text: string, key: string): number | undefined { - const keyPattern = new RegExp(`"${escapeRegExp(key)}"\\s*:`); - return lineOfPattern(text, keyPattern); + const line = coreLineOfJsonKey(text, key); + return line === 0 ? undefined : line; } export function lineOfJsonStringValue(text: string, value: string): number | undefined { - const encoded = JSON.stringify(value); - return lineOfPattern(text, new RegExp(escapeRegExp(encoded))); -} - -function lineOfPattern(text: string, pattern: RegExp): number | undefined { - const lines = text.split(/\r?\n/); - const index = lines.findIndex((line) => pattern.test(line)); - return index === -1 ? undefined : index + 1; -} - -function escapeRegExp(value: string): string { - return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + const line = coreLineOfJsonStringValue(text, value); + return line === 0 ? undefined : line; } function isNodeError(error: unknown): error is NodeJS.ErrnoException {