diff --git a/package-lock.json b/package-lock.json index 840d188..c68bf42 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "taskbound", "version": "0.2.3", "license": "MIT", + "dependencies": { + "agent-gov-core": "github:Conalh/agent-gov-core#v0.1.2" + }, "bin": { "taskbound": "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 16022bb..8710a43 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 {