@agntk/agent-harness 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-framework-K4GUIICH.js → agent-framework-CMFC3VJM.js} +8 -8
- package/dist/{auto-processor-OLE45UI3.js → auto-processor-SDAJF67T.js} +3 -3
- package/dist/{chunk-XTBKL5BI.js → chunk-2ENYRENZ.js} +2 -2
- package/dist/{chunk-UPLBF4RZ.js → chunk-2UVWCTAY.js} +2 -2
- package/dist/{chunk-4CWAGBNS.js → chunk-4TQQZILG.js} +73 -3
- package/dist/chunk-4TQQZILG.js.map +1 -0
- package/dist/{chunk-A7BJPQQ6.js → chunk-5O5OGOOQ.js} +2 -2
- package/dist/{chunk-UWQTZMNI.js → chunk-7GZ4D6V6.js} +2 -2
- package/dist/{chunk-FLZU44SV.js → chunk-AN6Y4MDD.js} +6 -6
- package/dist/{chunk-4FDUOGSZ.js → chunk-D7AWV24Z.js} +3 -3
- package/dist/{chunk-CHJ5GNZC.js → chunk-EC42HQQH.js} +2 -2
- package/dist/{chunk-274RV3YO.js → chunk-GX2RCSFJ.js} +3 -3
- package/dist/{chunk-GJNNR2RA.js → chunk-M6PDMK2O.js} +3 -3
- package/dist/{chunk-GUJTBGVS.js → chunk-MSO7DKBK.js} +99 -188
- package/dist/chunk-MSO7DKBK.js.map +1 -0
- package/dist/{chunk-CSL3ERUI.js → chunk-NBEAK63K.js} +3 -3
- package/dist/{chunk-DA7IKHC4.js → chunk-NOJW5KG2.js} +2 -2
- package/dist/{chunk-M7NXUK55.js → chunk-NVC2WY4K.js} +2 -2
- package/dist/{chunk-YIJY5DBV.js → chunk-P74KXHA4.js} +4 -4
- package/dist/{chunk-YUFNYN2H.js → chunk-PTQ37NRI.js} +4 -4
- package/dist/{chunk-KFX54TQM.js → chunk-RPBC2QOA.js} +73 -3
- package/dist/chunk-RPBC2QOA.js.map +1 -0
- package/dist/{chunk-RY3ZFII7.js → chunk-SEHAQTBO.js} +6 -6
- package/dist/{chunk-MPZ3BPUI.js → chunk-UMXPOYZR.js} +4 -4
- package/dist/{chunk-W4T7PGI2.js → chunk-UXCHAS3Z.js} +4 -4
- package/dist/chunk-XVFVTDE6.js +98 -0
- package/dist/chunk-XVFVTDE6.js.map +1 -0
- package/dist/cli/index.js +105 -104
- package/dist/cli/index.js.map +1 -1
- package/dist/{config-WVMRUOCA.js → config-2O6S2YJO.js} +3 -3
- package/dist/config-LLQZYN2Q.js +11 -0
- package/dist/{context-loader-3ORBPMHJ.js → context-loader-XCZ5EXNG.js} +4 -4
- package/dist/{conversation-QDEIDQPH.js → conversation-OPLE23IM.js} +6 -6
- package/dist/{delegate-VJCJLYEK.js → delegate-ZJCIADNN.js} +7 -7
- package/dist/{export-6GCYHEHQ.js → export-2HEAAOUF.js} +3 -3
- package/dist/{graph-YUIPOSOO.js → graph-5MKRTC3J.js} +4 -4
- package/dist/harness-ABKZWP47.js +11 -0
- package/dist/{harness-WE4SLCML.js → harness-XSBQBY7T.js} +8 -8
- package/dist/index.d.ts +22 -0
- package/dist/index.js +90 -6
- package/dist/index.js.map +1 -1
- package/dist/{indexer-LONANRRM.js → indexer-YKSGUVYT.js} +4 -4
- package/dist/{instinct-learner-SRM72DHF.js → instinct-learner-CWVMLUWX.js} +5 -5
- package/dist/{intake-4M3HNU43.js → intake-M5NRR6QR.js} +5 -5
- package/dist/{intelligence-HJOCA4SJ.js → intelligence-UW4TCOC7.js} +10 -10
- package/dist/{journal-WANJL3MI.js → journal-KN265YLU.js} +5 -5
- package/dist/{loader-C3TKIKZR.js → loader-BOCVXVCH.js} +3 -3
- package/dist/{mcp-installer-6O2XXD3V.js → mcp-installer-KV3XZRRF.js} +3 -3
- package/dist/{primitive-registry-I6VTIR4W.js → primitive-registry-HOJMUFBT.js} +3 -3
- package/dist/{rule-engine-YGQ3RYZM.js → rule-engine-I4AFQSSR.js} +3 -3
- package/dist/{scaffold-A3VRRCBV.js → scaffold-ZY4XWINP.js} +4 -4
- package/dist/{scheduler-XHHIVHRI.js → scheduler-TYOQKO4C.js} +11 -11
- package/dist/{search-V3W5JMJG.js → search-4IYM525O.js} +3 -3
- package/dist/{semantic-search-2DTOO5UX.js → semantic-search-G624D6CI.js} +3 -3
- package/dist/{serve-DTQ3HENY.js → serve-QFUZWOU3.js} +9 -9
- package/dist/{telemetry-UC6PBXC7.js → telemetry-MVDNGJEC.js} +4 -4
- package/dist/{tool-executor-MJ7IG7PQ.js → tool-executor-KEYQLO4M.js} +5 -5
- package/dist/{tools-DZ4KETET.js → tools-EB3BHRRF.js} +4 -4
- package/dist/{types-EW7AIB3R.js → types-NYKB2DN3.js} +2 -2
- package/dist/{types-WGDLSPO6.js → types-VRSXU4AM.js} +2 -2
- package/dist/{universal-installer-AAXXYM5A.js → universal-installer-7MFCJUW7.js} +91 -6
- package/dist/universal-installer-7MFCJUW7.js.map +1 -0
- package/dist/{validator-7WXMDIHH.js → validator-LZXBFEPV.js} +8 -8
- package/dist/{verification-gate-FYXUX6LH.js → verification-gate-ALSJVKSW.js} +3 -3
- package/dist/{watcher-ISJC7YKL.js → watcher-CSHVDOCM.js} +5 -5
- package/dist/{web-server-DD7ZOP46.js → web-server-7NGOTK7J.js} +8 -8
- package/dist/web-server-7NGOTK7J.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-4CWAGBNS.js.map +0 -1
- package/dist/chunk-GUJTBGVS.js.map +0 -1
- package/dist/chunk-KFX54TQM.js.map +0 -1
- package/dist/harness-LCHA3DWP.js +0 -10
- package/dist/universal-installer-AAXXYM5A.js.map +0 -1
- /package/dist/{agent-framework-K4GUIICH.js.map → agent-framework-CMFC3VJM.js.map} +0 -0
- /package/dist/{auto-processor-OLE45UI3.js.map → auto-processor-SDAJF67T.js.map} +0 -0
- /package/dist/{chunk-XTBKL5BI.js.map → chunk-2ENYRENZ.js.map} +0 -0
- /package/dist/{chunk-UPLBF4RZ.js.map → chunk-2UVWCTAY.js.map} +0 -0
- /package/dist/{chunk-A7BJPQQ6.js.map → chunk-5O5OGOOQ.js.map} +0 -0
- /package/dist/{chunk-UWQTZMNI.js.map → chunk-7GZ4D6V6.js.map} +0 -0
- /package/dist/{chunk-FLZU44SV.js.map → chunk-AN6Y4MDD.js.map} +0 -0
- /package/dist/{chunk-4FDUOGSZ.js.map → chunk-D7AWV24Z.js.map} +0 -0
- /package/dist/{chunk-CHJ5GNZC.js.map → chunk-EC42HQQH.js.map} +0 -0
- /package/dist/{chunk-274RV3YO.js.map → chunk-GX2RCSFJ.js.map} +0 -0
- /package/dist/{chunk-GJNNR2RA.js.map → chunk-M6PDMK2O.js.map} +0 -0
- /package/dist/{chunk-CSL3ERUI.js.map → chunk-NBEAK63K.js.map} +0 -0
- /package/dist/{chunk-DA7IKHC4.js.map → chunk-NOJW5KG2.js.map} +0 -0
- /package/dist/{chunk-M7NXUK55.js.map → chunk-NVC2WY4K.js.map} +0 -0
- /package/dist/{chunk-YIJY5DBV.js.map → chunk-P74KXHA4.js.map} +0 -0
- /package/dist/{chunk-YUFNYN2H.js.map → chunk-PTQ37NRI.js.map} +0 -0
- /package/dist/{chunk-RY3ZFII7.js.map → chunk-SEHAQTBO.js.map} +0 -0
- /package/dist/{chunk-MPZ3BPUI.js.map → chunk-UMXPOYZR.js.map} +0 -0
- /package/dist/{chunk-W4T7PGI2.js.map → chunk-UXCHAS3Z.js.map} +0 -0
- /package/dist/{config-WVMRUOCA.js.map → config-2O6S2YJO.js.map} +0 -0
- /package/dist/{context-loader-3ORBPMHJ.js.map → config-LLQZYN2Q.js.map} +0 -0
- /package/dist/{conversation-QDEIDQPH.js.map → context-loader-XCZ5EXNG.js.map} +0 -0
- /package/dist/{delegate-VJCJLYEK.js.map → conversation-OPLE23IM.js.map} +0 -0
- /package/dist/{graph-YUIPOSOO.js.map → delegate-ZJCIADNN.js.map} +0 -0
- /package/dist/{export-6GCYHEHQ.js.map → export-2HEAAOUF.js.map} +0 -0
- /package/dist/{harness-LCHA3DWP.js.map → graph-5MKRTC3J.js.map} +0 -0
- /package/dist/{harness-WE4SLCML.js.map → harness-ABKZWP47.js.map} +0 -0
- /package/dist/{indexer-LONANRRM.js.map → harness-XSBQBY7T.js.map} +0 -0
- /package/dist/{instinct-learner-SRM72DHF.js.map → indexer-YKSGUVYT.js.map} +0 -0
- /package/dist/{intake-4M3HNU43.js.map → instinct-learner-CWVMLUWX.js.map} +0 -0
- /package/dist/{journal-WANJL3MI.js.map → intake-M5NRR6QR.js.map} +0 -0
- /package/dist/{intelligence-HJOCA4SJ.js.map → intelligence-UW4TCOC7.js.map} +0 -0
- /package/dist/{loader-C3TKIKZR.js.map → journal-KN265YLU.js.map} +0 -0
- /package/dist/{telemetry-UC6PBXC7.js.map → loader-BOCVXVCH.js.map} +0 -0
- /package/dist/{mcp-installer-6O2XXD3V.js.map → mcp-installer-KV3XZRRF.js.map} +0 -0
- /package/dist/{primitive-registry-I6VTIR4W.js.map → primitive-registry-HOJMUFBT.js.map} +0 -0
- /package/dist/{rule-engine-YGQ3RYZM.js.map → rule-engine-I4AFQSSR.js.map} +0 -0
- /package/dist/{scaffold-A3VRRCBV.js.map → scaffold-ZY4XWINP.js.map} +0 -0
- /package/dist/{scheduler-XHHIVHRI.js.map → scheduler-TYOQKO4C.js.map} +0 -0
- /package/dist/{search-V3W5JMJG.js.map → search-4IYM525O.js.map} +0 -0
- /package/dist/{semantic-search-2DTOO5UX.js.map → semantic-search-G624D6CI.js.map} +0 -0
- /package/dist/{serve-DTQ3HENY.js.map → serve-QFUZWOU3.js.map} +0 -0
- /package/dist/{tool-executor-MJ7IG7PQ.js.map → telemetry-MVDNGJEC.js.map} +0 -0
- /package/dist/{tools-DZ4KETET.js.map → tool-executor-KEYQLO4M.js.map} +0 -0
- /package/dist/{types-EW7AIB3R.js.map → tools-EB3BHRRF.js.map} +0 -0
- /package/dist/{types-WGDLSPO6.js.map → types-NYKB2DN3.js.map} +0 -0
- /package/dist/{validator-7WXMDIHH.js.map → types-VRSXU4AM.js.map} +0 -0
- /package/dist/{web-server-DD7ZOP46.js.map → validator-LZXBFEPV.js.map} +0 -0
- /package/dist/{verification-gate-FYXUX6LH.js.map → verification-gate-ALSJVKSW.js.map} +0 -0
- /package/dist/{watcher-ISJC7YKL.js.map → watcher-CSHVDOCM.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime/universal-installer.ts"],"sourcesContent":["import { existsSync, readFileSync, writeFileSync, mkdirSync, copyFileSync } from 'fs';\nimport { join, basename, extname } from 'path';\nimport { tmpdir } from 'os';\nimport { createRequire } from 'module';\nimport matter from 'gray-matter';\nimport { parse as parseYaml } from 'yaml';\nimport { fixCapability, installCapability, downloadCapability } from './intake.js';\nimport { autoProcessFile } from './auto-processor.js';\nimport { discoverSources, loadAllSources } from './sources.js';\nimport type { Source, SourceDiscoveryResult } from './sources.js';\nimport { log } from '../core/logger.js';\n\n// ─── Provenance ──────────────────────────────────────────────────────────────\n\n/**\n * Read the harness's own package.json version for the `installed_by` field.\n *\n * Has to handle three possible runtime layouts because tsup bundles flat:\n * - Dev/test: src/runtime/universal-installer.ts → ../../package.json\n * - Built bin: dist/cli/index.js → ../../package.json\n * - Built lib: dist/<bundle>.js → ../package.json\n *\n * Walks up one directory at a time, requires `package.json`, and returns\n * the version of the FIRST one whose name is `@agntk/agent-harness`. Stops\n * after a few levels so a broken environment never causes an infinite loop.\n * Returns \"unknown\" on any failure so an install never blocks on this.\n */\nfunction getHarnessVersion(): string {\n try {\n const require = createRequire(import.meta.url);\n const candidates = [\n '../package.json',\n '../../package.json',\n '../../../package.json',\n ];\n for (const candidate of candidates) {\n try {\n const pkg = require(candidate) as { name?: string; version?: string };\n if (pkg.name === '@agntk/agent-harness' && pkg.version) {\n return pkg.version;\n }\n } catch {\n // Candidate didn't resolve — try the next one.\n }\n }\n return 'unknown';\n } catch {\n return 'unknown';\n }\n}\n\n/**\n * Resolve a commit SHA for a GitHub raw URL by calling the GitHub Contents API.\n *\n * Input URL shape:\n * https://raw.githubusercontent.com/{owner}/{repo}/{ref}/{path}\n * where {ref} is either a 40-char commit SHA or a branch/tag name.\n *\n * Returns the SHA (either the one already in the URL, or the one resolved from\n * a branch name via the Contents API). Returns `null` on any failure — network\n * error, timeout, 404, non-github host, unparseable URL — so the install can\n * proceed without source_commit.\n */\nasync function resolveGithubCommitSha(url: string): Promise<string | null> {\n // Only handle raw.githubusercontent.com URLs\n const match = url.match(\n /^https?:\\/\\/raw\\.githubusercontent\\.com\\/([^/]+)\\/([^/]+)\\/([^/]+)\\/(.+)$/,\n );\n if (!match) return null;\n const [, owner, repo, ref, path] = match;\n\n // If ref is already a 40-char hex SHA, just return it\n if (/^[0-9a-f]{40}$/i.test(ref)) return ref;\n\n // Otherwise resolve via the Contents API\n const apiUrl = `https://api.github.com/repos/${owner}/${repo}/contents/${path}?ref=${ref}`;\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), 5000);\n try {\n const response = await fetch(apiUrl, {\n signal: controller.signal,\n headers: { 'Accept': 'application/vnd.github+json' },\n });\n if (!response.ok) return null;\n const data = (await response.json()) as { sha?: string };\n if (typeof data.sha === 'string' && /^[0-9a-f]{40}$/i.test(data.sha)) {\n return data.sha;\n }\n return null;\n } catch {\n return null;\n } finally {\n clearTimeout(timeout);\n }\n}\n\n// ─── License Detection (Level 2 of task 12.14) ──────────────────────────────\n\n/**\n * Result of license detection. `spdxId` is one of:\n * - A standard SPDX identifier (\"MIT\", \"Apache-2.0\", etc.)\n * - \"PROPRIETARY\" — text says \"all rights reserved\" or no permission grant\n * - \"UNKNOWN\" — no LICENSE file found, or text doesn't match any pattern\n */\nexport interface LicenseInfo {\n /** SPDX id, \"PROPRIETARY\", or \"UNKNOWN\" */\n spdxId: string;\n /** First copyright line found in the LICENSE text, if any */\n copyright?: string;\n /** URL to the license file the detector actually found, if any */\n licenseSource?: string;\n}\n\n/** Sibling LICENSE filenames to probe in the same directory as the installed file. */\nconst SIBLING_LICENSE_NAMES = [\n 'LICENSE',\n 'LICENSE.txt',\n 'LICENSE.md',\n 'COPYING',\n 'COPYING.txt',\n] as const;\n\n/**\n * Classify a LICENSE file's body text into an SPDX id, \"PROPRIETARY\", or \"UNKNOWN\".\n * Substring-based detection — not a full parser. Good enough for the common cases\n * (MIT, Apache-2.0, BSD, ISC, GPL, MPL, CC) and the proprietary \"all rights reserved\"\n * pattern that bit us in v0.1.0.\n */\nfunction classifyLicenseText(text: string): string {\n const lower = text.toLowerCase();\n // PROPRIETARY check first — overrides any false-positive substring match below.\n if (lower.includes('all rights reserved')) {\n return 'PROPRIETARY';\n }\n // Then SPDX-by-substring. Order matters: check more-specific patterns first\n // (e.g. AGPL before GPL, LGPL before GPL).\n if (lower.includes('mit license')) return 'MIT';\n if (lower.includes('apache license, version 2.0') || lower.includes('apache-2.0'))\n return 'Apache-2.0';\n if (lower.includes('mozilla public license version 2.0') || lower.includes('mpl-2.0'))\n return 'MPL-2.0';\n if (lower.includes('gnu affero general public license')) return 'AGPL-3.0';\n if (lower.includes('gnu lesser general public license')) {\n if (lower.includes('version 3')) return 'LGPL-3.0';\n if (lower.includes('version 2')) return 'LGPL-2.1';\n }\n if (lower.includes('gnu general public license')) {\n if (lower.includes('version 3')) return 'GPL-3.0';\n if (lower.includes('version 2')) return 'GPL-2.0';\n }\n if (lower.includes('isc license')) return 'ISC';\n if (lower.includes('cc0 1.0 universal') || lower.includes('cc0-1.0')) return 'CC0-1.0';\n if (lower.includes('creative commons attribution-sharealike 4.0')) return 'CC-BY-SA-4.0';\n if (lower.includes('creative commons attribution 4.0') || lower.includes('cc-by-4.0'))\n return 'CC-BY-4.0';\n if (\n lower.includes('redistribution and use in source and binary forms') &&\n lower.includes('neither the name of')\n ) {\n return 'BSD-3-Clause';\n }\n if (lower.includes('redistribution and use in source and binary forms')) {\n return 'BSD-2-Clause';\n }\n if (lower.includes('this is free and unencumbered software released into the public domain')) {\n return 'Unlicense';\n }\n return 'UNKNOWN';\n}\n\n/**\n * Extract the first `Copyright (c) YEAR ...` line from a license body.\n * Returns the trimmed line, or undefined if no copyright line is found.\n */\nfunction extractCopyright(text: string): string | undefined {\n // Match lines starting with \"©\" or \"Copyright\" (any case) and containing a\n // 4-digit year. The leading \"©\" can be followed immediately by space/digit\n // (it's a non-word char so we don't put a \\b after it). \"Copyright\" can be\n // followed by anything as long as a year appears later in the line.\n const lines = text.split(/\\r?\\n/);\n for (const line of lines) {\n const trimmed = line.trim();\n if (/^©\\s*\\d{4}/.test(trimmed) || /^copyright\\b.*\\d{4}/i.test(trimmed)) {\n return trimmed;\n }\n }\n return undefined;\n}\n\n/**\n * Try to fetch a single sibling LICENSE file next to the installed file.\n * Returns the body text on success, null on any failure (404, network, timeout).\n */\nasync function fetchSiblingLicense(\n siblingUrl: string,\n): Promise<string | null> {\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), 5000);\n try {\n const response = await fetch(siblingUrl, { signal: controller.signal });\n if (!response.ok) return null;\n return await response.text();\n } catch {\n return null;\n } finally {\n clearTimeout(timeout);\n }\n}\n\n/**\n * Try to fetch the repo-root LICENSE via the GitHub License API.\n * Returns the SPDX id, html_url, and (when available) the decoded body text\n * so the caller can extract a copyright line. Null on any failure.\n *\n * The API response shape:\n * {\n * license: { spdx_id: \"MIT\" },\n * html_url: \"https://github.com/owner/repo/blob/main/LICENSE\",\n * content: \"<base64>\",\n * encoding: \"base64\"\n * }\n *\n * https://docs.github.com/en/rest/licenses/licenses#get-the-license-for-a-repository\n */\nasync function fetchGithubRepoLicense(\n owner: string,\n repo: string,\n): Promise<{ spdxId: string; htmlUrl: string; body?: string } | null> {\n const apiUrl = `https://api.github.com/repos/${owner}/${repo}/license`;\n const controller = new AbortController();\n const timeout = setTimeout(() => controller.abort(), 5000);\n try {\n const response = await fetch(apiUrl, {\n signal: controller.signal,\n headers: { 'Accept': 'application/vnd.github+json' },\n });\n if (!response.ok) return null;\n const data = (await response.json()) as {\n license?: { spdx_id?: string };\n html_url?: string;\n content?: string;\n encoding?: string;\n };\n const spdxId = data.license?.spdx_id;\n if (!spdxId || spdxId === 'NOASSERTION') return null;\n\n // Decode the base64-encoded body so the caller can extract copyright.\n // Tolerant of failures — if decoding throws, just omit the body.\n let body: string | undefined;\n if (data.content && data.encoding === 'base64') {\n try {\n body = Buffer.from(data.content, 'base64').toString('utf-8');\n } catch {\n body = undefined;\n }\n }\n\n return { spdxId, htmlUrl: data.html_url ?? '', body };\n } catch {\n return null;\n } finally {\n clearTimeout(timeout);\n }\n}\n\n/**\n * Detect the license of a file at a given URL.\n *\n * Lookup order, strictest finding wins:\n * 1. Per-file LICENSE sibling in the same directory as the file.\n * Catches the v0.1.0 case where each anthropics/skills/<skill>/\n * directory contained its own proprietary LICENSE.txt.\n * 2. Repository root LICENSE via the GitHub License API. Returns SPDX id.\n * 3. Caller falls back to the source file's own frontmatter (handled in\n * recordProvenance, not here).\n *\n * Strictness rule: PROPRIETARY > UNKNOWN > permissive SPDX. If a per-file\n * LICENSE says \"All rights reserved\" we never look at the repo root —\n * proprietary always wins.\n *\n * Non-github URLs return immediately with `{ spdxId: 'UNKNOWN' }` since we\n * have no way to look up a license. The caller can still use frontmatter.\n *\n * @param sourceUrl The URL the user passed to `harness install`\n * @returns LicenseInfo. Always returns an object — never throws or returns null.\n */\nexport async function detectLicense(sourceUrl: string): Promise<LicenseInfo> {\n // Only github raw URLs have a structure we can probe.\n const match = sourceUrl.match(\n /^https?:\\/\\/raw\\.githubusercontent\\.com\\/([^/]+)\\/([^/]+)\\/([^/]+)\\/(.+)$/,\n );\n if (!match) {\n return { spdxId: 'UNKNOWN' };\n }\n const [, owner, repo, ref, path] = match;\n\n // 1. Per-file LICENSE sibling — split path into dir, then probe each filename.\n const lastSlash = path.lastIndexOf('/');\n const dir = lastSlash >= 0 ? path.slice(0, lastSlash) : '';\n const dirPrefix = dir ? `${dir}/` : '';\n\n for (const siblingName of SIBLING_LICENSE_NAMES) {\n const siblingUrl = `https://raw.githubusercontent.com/${owner}/${repo}/${ref}/${dirPrefix}${siblingName}`;\n const text = await fetchSiblingLicense(siblingUrl);\n if (text) {\n const spdxId = classifyLicenseText(text);\n const copyright = extractCopyright(text);\n return { spdxId, copyright, licenseSource: siblingUrl };\n }\n }\n\n // 2. Repository root LICENSE via the GitHub License API. The API returns\n // the SPDX id directly, plus a base64-encoded body we can use to extract\n // a copyright line.\n const repoLicense = await fetchGithubRepoLicense(owner, repo);\n if (repoLicense) {\n const copyright = repoLicense.body\n ? extractCopyright(repoLicense.body)\n : undefined;\n return {\n spdxId: repoLicense.spdxId,\n copyright,\n licenseSource: repoLicense.htmlUrl || undefined,\n };\n }\n\n return { spdxId: 'UNKNOWN' };\n}\n\n/**\n * Inject provenance and license fields into a normalized markdown file's\n * frontmatter.\n *\n * Provenance rules (Level 1 of task 12.14):\n * - `source` and `source_commit` are preserved if already present (idempotent)\n * - `installed_at` and `installed_by` are always updated to reflect the most\n * recent install action\n * - `source_commit` is only written when a SHA could be resolved\n *\n * License rules (Level 2 of task 12.14):\n * - `license`, `copyright`, `license_source` are preserved if already present\n * in the source file's frontmatter (idempotent — author intent wins)\n * - Otherwise detected via detectLicense() and merged in\n * - License detection NEVER blocks the install. Failures result in\n * `license: UNKNOWN` rather than an error.\n *\n * @param content Normalized markdown content with existing frontmatter\n * @param originalSource The exact URL the user passed to `harness install`\n * @returns The content with provenance + license fields merged into frontmatter\n */\nexport async function recordProvenance(\n content: string,\n originalSource: string,\n): Promise<string> {\n let parsed: ReturnType<typeof matter>;\n try {\n parsed = matter(content);\n } catch {\n return content;\n }\n\n const data = parsed.data as Record<string, unknown>;\n\n // Preserve existing source — idempotency rule\n if (!data.source) {\n data.source = originalSource;\n }\n\n // Preserve existing source_commit; only resolve if missing AND URL is github raw\n if (!data.source_commit) {\n const sha = await resolveGithubCommitSha(originalSource);\n if (sha) {\n data.source_commit = sha;\n }\n }\n\n // License detection (Level 2). Idempotent: don't overwrite author-set fields.\n // Only run detection if at least one license-related field is missing — saves\n // the network calls when re-installing files that already carry their license.\n if (!data.license || !data.copyright || !data.license_source) {\n const license = await detectLicense(originalSource);\n if (!data.license) {\n data.license = license.spdxId;\n }\n if (!data.copyright && license.copyright) {\n data.copyright = license.copyright;\n }\n if (!data.license_source && license.licenseSource) {\n data.license_source = license.licenseSource;\n }\n }\n\n // Always update these to reflect the most recent install\n data.installed_at = new Date().toISOString();\n data.installed_by = `agent-harness@${getHarnessVersion()}`;\n\n return matter.stringify(parsed.content, data);\n}\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\n/** Detected source format of a file to be installed. */\nexport type SourceFormat =\n | 'harness' // Already harness convention (frontmatter + L0/L1)\n | 'claude-skill' // Claude Code SKILL.md (plain markdown, no frontmatter)\n | 'faf-yaml' // .faf YAML format\n | 'raw-markdown' // Plain markdown with no harness structure\n | 'bash-hook' // Bash/shell script (hook or workflow)\n | 'mcp-config' // MCP server configuration (JSON/YAML)\n | 'unknown';\n\n/** Result of format detection. */\nexport interface FormatDetection {\n /** Detected format */\n format: SourceFormat;\n /** Inferred primitive type (skill, agent, rule, etc.) */\n primitiveType: string | null;\n /** Confidence score (0-1) */\n confidence: number;\n /** Reasons for the detection */\n reasons: string[];\n}\n\n/** Result of a universal install operation. */\nexport interface UniversalInstallResult {\n /** Whether installation succeeded */\n installed: boolean;\n /** Source reference that was resolved */\n source: string;\n /** Detected format */\n format: FormatDetection;\n /** Path where the file was installed */\n destination: string;\n /** Fixes applied during normalization */\n fixes: string[];\n /** Errors encountered */\n errors: string[];\n /** Suggested dependencies to install */\n suggestedDependencies: string[];\n}\n\n/** Options for the universal installer. */\nexport interface UniversalInstallOptions {\n /** Override the detected primitive type (skill, rule, agent, etc.) */\n type?: string;\n /** Override the generated ID */\n id?: string;\n /** Force install even if validation has warnings */\n force?: boolean;\n /** Skip auto-fix (frontmatter, L0/L1 generation) */\n skipFix?: boolean;\n /** Additional tags to add */\n tags?: string[];\n /**\n * Override the license policy for THIS install only. Pass an SPDX id like\n * \"MIT\" or \"Apache-2.0\" — the installer will treat the file as if its\n * license were the override and skip the policy check entirely. Use only\n * when you have written permission for the content. (Level 3 of 12.14.)\n */\n forceLicense?: string;\n}\n\n/**\n * License policy enforcement decision (Level 3 of task 12.14).\n *\n * Returned by `evaluateLicensePolicy()` to tell the installer what to do\n * about a detected license. The installer turns this into a console warning,\n * an interactive prompt, or an error result depending on the action.\n */\nexport interface LicensePolicyDecision {\n /** What the installer should do — block aborts, prompt asks, warn logs, allow continues */\n action: 'allow' | 'warn' | 'prompt' | 'block';\n /** Human-readable reason — used in warning text and block error messages */\n reason: string;\n /** The SPDX id (or PROPRIETARY/UNKNOWN) the policy was evaluated against */\n spdxId: string;\n}\n\n/**\n * Decide what to do about a detected license, given the user's `install:`\n * config policy. Pure function — never makes decisions on its own, never\n * prompts. The caller (universalInstall) handles UI side effects.\n *\n * Logic:\n * - If `forceLicense` is set, always return `allow` (with the override SPDX id)\n * - If the SPDX id is PROPRIETARY → use `on_proprietary` setting\n * - If the SPDX id is in `allowed_licenses` → `allow`\n * - Otherwise (UNKNOWN, GPL, anything not on the list) → use `on_unknown_license`\n */\nexport function evaluateLicensePolicy(\n detected: LicenseInfo,\n policy: {\n allowed_licenses: readonly string[];\n on_unknown_license: 'allow' | 'warn' | 'prompt' | 'block';\n on_proprietary: 'allow' | 'warn' | 'prompt' | 'block';\n },\n forceLicense?: string,\n): LicensePolicyDecision {\n // Force override — caller asserted permission. Skip the check entirely.\n if (forceLicense) {\n return {\n action: 'allow',\n reason: `forced license override: ${forceLicense}`,\n spdxId: forceLicense,\n };\n }\n\n const spdxId = detected.spdxId;\n\n if (spdxId === 'PROPRIETARY') {\n return {\n action: policy.on_proprietary,\n reason: detected.licenseSource\n ? `proprietary content per ${detected.licenseSource}`\n : 'proprietary content (license text says \"all rights reserved\")',\n spdxId,\n };\n }\n\n if (policy.allowed_licenses.includes(spdxId)) {\n return {\n action: 'allow',\n reason: `${spdxId} is in allowed_licenses`,\n spdxId,\n };\n }\n\n // Either UNKNOWN or a non-permissive SPDX id (GPL, AGPL, etc.) the user\n // didn't add to their allowed list.\n return {\n action: policy.on_unknown_license,\n reason:\n spdxId === 'UNKNOWN'\n ? 'no LICENSE file found in source repo (per-file, repo root, or frontmatter)'\n : `${spdxId} is not in your allowed_licenses (config.yaml install.allowed_licenses)`,\n spdxId,\n };\n}\n\n// ─── Constants ───────────────────────────────────────────────────────────────\n\nconst VALID_TYPES = ['rule', 'instinct', 'skill', 'playbook', 'workflow', 'tool', 'agent'];\n\nconst TYPE_DIRS: Record<string, string> = {\n rule: 'rules',\n instinct: 'instincts',\n skill: 'skills',\n playbook: 'playbooks',\n workflow: 'workflows',\n tool: 'tools',\n agent: 'agents',\n};\n\n// ─── Format Detection ────────────────────────────────────────────────────────\n\n/**\n * Detect the format of a file based on its content and extension.\n *\n * Detection heuristics:\n * - Has `---` frontmatter with `id:` + `status:` → harness convention\n * - Has `---` frontmatter but missing harness fields → raw-markdown\n * - `.faf` or `.yaml`/`.yml` with `type:` + `content:` keys → faf-yaml\n * - `.sh`/`.bash` or starts with `#!/` → bash-hook\n * - JSON/YAML with `mcpServers` or `servers` → mcp-config\n * - Plain markdown with no frontmatter → claude-skill or raw-markdown\n */\nexport function detectFormat(content: string, filename: string): FormatDetection {\n const ext = extname(filename).toLowerCase();\n const reasons: string[] = [];\n let format: SourceFormat = 'unknown';\n let primitiveType: string | null = null;\n let confidence = 0;\n\n // Check for bash/shell scripts\n if (ext === '.sh' || ext === '.bash' || content.trimStart().startsWith('#!/')) {\n format = 'bash-hook';\n primitiveType = 'workflow';\n confidence = 0.9;\n reasons.push('Shell script detected (shebang or .sh extension)');\n\n // Hooks are typically short scripts with specific patterns\n if (content.includes('hook') || content.includes('pre-commit') || content.includes('post-')) {\n primitiveType = 'workflow';\n reasons.push('Hook pattern detected in content');\n }\n\n return { format, primitiveType, confidence, reasons };\n }\n\n // Check for JSON/YAML MCP configs\n if (ext === '.json') {\n try {\n const parsed = JSON.parse(content) as Record<string, unknown>;\n if (parsed.mcpServers || parsed.servers || parsed.command || parsed.args) {\n format = 'mcp-config';\n primitiveType = 'tool';\n confidence = 0.9;\n reasons.push('MCP configuration JSON detected');\n return { format, primitiveType, confidence, reasons };\n }\n } catch {\n // Not valid JSON, continue\n }\n }\n\n // Check for .faf YAML format\n if (ext === '.faf' || ext === '.yaml' || ext === '.yml') {\n try {\n const parsed = parseYaml(content) as Record<string, unknown>;\n if (parsed.type && parsed.content) {\n format = 'faf-yaml';\n primitiveType = inferTypeFromFafType(String(parsed.type));\n confidence = 0.9;\n reasons.push(`.faf YAML format with type: ${parsed.type}`);\n return { format, primitiveType, confidence, reasons };\n }\n // YAML with mcpServers\n if (parsed.mcpServers || parsed.servers) {\n format = 'mcp-config';\n primitiveType = 'tool';\n confidence = 0.85;\n reasons.push('MCP configuration YAML detected');\n return { format, primitiveType, confidence, reasons };\n }\n } catch {\n // Not valid YAML, continue\n }\n }\n\n // Check for markdown content\n if (ext === '.md' || ext === '' || !ext) {\n // Try to parse frontmatter\n try {\n const parsed = matter(content);\n const data = parsed.data as Record<string, unknown>;\n\n if (data.id && data.status) {\n // Has harness-style frontmatter\n format = 'harness';\n confidence = 0.95;\n reasons.push('Harness frontmatter detected (id + status fields)');\n\n // Detect type from tags\n const tags = Array.isArray(data.tags)\n ? (data.tags as string[]).map((t) => String(t).toLowerCase())\n : [];\n for (const type of VALID_TYPES) {\n if (tags.includes(type)) {\n primitiveType = type;\n break;\n }\n }\n\n return { format, primitiveType, confidence, reasons };\n }\n\n if (Object.keys(data).length > 0) {\n // Has some frontmatter but not harness convention\n format = 'raw-markdown';\n confidence = 0.7;\n reasons.push('Markdown with non-harness frontmatter');\n }\n } catch {\n // No frontmatter or parse error\n }\n\n // Check for Claude Code SKILL.md patterns\n if (format === 'unknown' || format === 'raw-markdown') {\n const isClaudeSkill = detectClaudeSkillPattern(content, filename);\n if (isClaudeSkill) {\n format = 'claude-skill';\n primitiveType = 'skill';\n confidence = 0.8;\n reasons.push('Claude Code SKILL.md pattern detected');\n return { format, primitiveType, confidence, reasons };\n }\n }\n\n // Plain markdown — infer type from content\n if (format === 'unknown') {\n format = 'raw-markdown';\n confidence = 0.5;\n reasons.push('Plain markdown without frontmatter');\n }\n\n // Try to infer type from content/filename\n if (!primitiveType) {\n primitiveType = inferTypeFromContent(content, filename);\n if (primitiveType) {\n reasons.push(`Type inferred from content/filename: ${primitiveType}`);\n }\n }\n\n return { format, primitiveType, confidence, reasons };\n }\n\n return { format, primitiveType, confidence, reasons };\n}\n\n// ─── Format Normalization ────────────────────────────────────────────────────\n\n/**\n * Normalize content from any detected format to harness convention.\n * Returns the normalized markdown content ready for writing.\n */\nexport function normalizeToHarness(\n content: string,\n filename: string,\n detection: FormatDetection,\n options?: UniversalInstallOptions,\n): { content: string; filename: string; fixes: string[] } {\n const fixes: string[] = [];\n const type = options?.type ?? detection.primitiveType;\n\n switch (detection.format) {\n case 'harness':\n // Already in harness format — just pass through\n return { content, filename, fixes: ['Already in harness format'] };\n\n case 'claude-skill':\n return normalizeClaudeSkill(content, filename, type, options, fixes);\n\n case 'faf-yaml':\n return normalizeFafYaml(content, filename, type, options, fixes);\n\n case 'raw-markdown':\n return normalizeRawMarkdown(content, filename, type, options, fixes);\n\n case 'bash-hook':\n return normalizeBashHook(content, filename, type, options, fixes);\n\n case 'mcp-config':\n return normalizeMcpConfig(content, filename, options, fixes);\n\n default:\n return normalizeRawMarkdown(content, filename, type, options, fixes);\n }\n}\n\n/**\n * Convert Claude Code SKILL.md to harness convention.\n * Claude skills are plain markdown — add frontmatter + L0/L1.\n */\nfunction normalizeClaudeSkill(\n content: string,\n filename: string,\n type: string | null,\n options: UniversalInstallOptions | undefined,\n fixes: string[],\n): { content: string; filename: string; fixes: string[] } {\n const id = options?.id ?? deriveId(filename);\n const primitiveType = type ?? 'skill';\n const tags = [primitiveType, ...(options?.tags ?? [])];\n\n // Extract first heading as title\n const headingMatch = content.match(/^#\\s+(.+)$/m);\n const title = headingMatch ? headingMatch[1].trim() : id;\n\n const frontmatter: Record<string, unknown> = {\n id,\n created: new Date().toISOString().split('T')[0],\n author: 'human',\n status: 'active',\n tags,\n };\n\n // Generate L0 from title/first heading\n const l0 = title.length > 120 ? title.slice(0, 117) + '...' : title;\n\n // Generate L1 from first paragraph\n const paragraphs = content.split(/\\n{2,}/).filter((p) => {\n const trimmed = p.trim();\n return trimmed.length > 0 && !trimmed.startsWith('#') && !trimmed.startsWith('<!--');\n });\n const l1 = paragraphs.length > 0\n ? paragraphs[0].replace(/\\n/g, ' ').trim().slice(0, 300)\n : '';\n\n let body = `<!-- L0: ${l0} -->\\n`;\n if (l1) {\n body += `<!-- L1: ${l1} -->\\n`;\n }\n body += '\\n' + content;\n\n const result = matter.stringify(body, frontmatter);\n fixes.push('Added harness frontmatter (id, status, tags)');\n fixes.push(`Generated L0 from heading: \"${l0}\"`);\n if (l1) fixes.push('Generated L1 from first paragraph');\n\n const outFilename = ensureMdExtension(filename);\n return { content: result, filename: outFilename, fixes };\n}\n\n/**\n * Convert .faf YAML format to harness markdown.\n */\nfunction normalizeFafYaml(\n content: string,\n filename: string,\n type: string | null,\n options: UniversalInstallOptions | undefined,\n fixes: string[],\n): { content: string; filename: string; fixes: string[] } {\n let parsed: Record<string, unknown>;\n try {\n parsed = parseYaml(content) as Record<string, unknown>;\n } catch {\n fixes.push('Failed to parse YAML — treating as raw markdown');\n return normalizeRawMarkdown(content, filename, type, options, fixes);\n }\n\n const id = options?.id ?? String(parsed.id ?? deriveId(filename));\n const fafType = String(parsed.type ?? 'skill');\n const primitiveType = type ?? inferTypeFromFafType(fafType) ?? 'skill';\n const title = String(parsed.title ?? parsed.name ?? id);\n const description = String(parsed.description ?? '');\n const fafContent = String(parsed.content ?? '');\n const fafTags = Array.isArray(parsed.tags)\n ? (parsed.tags as string[]).map(String)\n : [];\n\n const tags = [primitiveType, ...fafTags, ...(options?.tags ?? [])];\n\n const frontmatter: Record<string, unknown> = {\n id,\n created: new Date().toISOString().split('T')[0],\n author: 'human',\n status: 'active',\n tags: [...new Set(tags)],\n };\n\n const l0 = title.length > 120 ? title.slice(0, 117) + '...' : title;\n const l1 = description.length > 300 ? description.slice(0, 297) + '...' : description;\n\n let body = `<!-- L0: ${l0} -->\\n`;\n if (l1) body += `<!-- L1: ${l1} -->\\n`;\n body += `\\n# ${title}\\n\\n`;\n if (description) body += `${description}\\n\\n`;\n if (fafContent) body += fafContent + '\\n';\n\n const result = matter.stringify(body, frontmatter);\n fixes.push('Converted .faf YAML to harness markdown');\n fixes.push(`Added frontmatter (id: ${id}, type: ${primitiveType})`);\n\n const outFilename = deriveId(filename) + '.md';\n return { content: result, filename: outFilename, fixes };\n}\n\n/**\n * Normalize raw markdown (no frontmatter or non-harness frontmatter).\n */\nfunction normalizeRawMarkdown(\n content: string,\n filename: string,\n type: string | null,\n options: UniversalInstallOptions | undefined,\n fixes: string[],\n): { content: string; filename: string; fixes: string[] } {\n const id = options?.id ?? deriveId(filename);\n const primitiveType = type ?? 'skill';\n const tags = [primitiveType, ...(options?.tags ?? [])];\n\n // Try to preserve any existing frontmatter\n let parsed: ReturnType<typeof matter>;\n try {\n parsed = matter(content);\n } catch {\n parsed = { data: {}, content, orig: '', excerpt: '', language: '', matter: '', stringify: () => '' } as ReturnType<typeof matter>;\n }\n\n const data = parsed.data as Record<string, unknown>;\n\n // Set required harness fields — options override existing values\n if (options?.id || !data.id) {\n data.id = id;\n fixes.push(`Set id: \"${id}\"`);\n }\n if (!data.status) {\n data.status = 'active';\n fixes.push('Added status: \"active\"');\n }\n if (!data.created) {\n data.created = new Date().toISOString().split('T')[0];\n fixes.push('Added created date');\n }\n if (!data.author || !['human', 'agent', 'infrastructure'].includes(String(data.author))) {\n data.author = 'human';\n fixes.push('Added author: \"human\"');\n }\n if (!Array.isArray(data.tags) || data.tags.length === 0) {\n data.tags = [...new Set(tags)];\n fixes.push(`Added tags: [${(data.tags as string[]).join(', ')}]`);\n }\n\n let body = parsed.content;\n\n // Add L0 if missing\n const l0Regex = /<!--\\s*L0:\\s*(.*?)\\s*-->/;\n if (!l0Regex.test(body)) {\n const headingMatch = body.match(/^#\\s+(.+)$/m);\n const firstLine = body.split('\\n').find((line) => line.trim().length > 0);\n const summary = headingMatch ? headingMatch[1].trim() : (firstLine?.trim() ?? id);\n const l0 = summary.length > 120 ? summary.slice(0, 117) + '...' : summary;\n body = `<!-- L0: ${l0} -->\\n${body}`;\n fixes.push(`Generated L0: \"${l0}\"`);\n }\n\n // Add L1 if missing\n const l1Regex = /<!--\\s*L1:\\s*([\\s\\S]*?)\\s*-->/;\n if (!l1Regex.test(body)) {\n const paragraphs = body.split(/\\n{2,}/).filter((p) => {\n const trimmed = p.trim();\n return trimmed.length > 0 && !trimmed.startsWith('<!--') && !trimmed.startsWith('#');\n });\n if (paragraphs.length > 0) {\n const para = paragraphs[0].replace(/\\n/g, ' ').trim();\n const l1 = para.length > 300 ? para.slice(0, 297) + '...' : para;\n const l0Pos = body.indexOf('-->');\n if (l0Pos !== -1) {\n const insertPos = l0Pos + 3;\n body = body.slice(0, insertPos) + `\\n<!-- L1: ${l1} -->` + body.slice(insertPos);\n } else {\n body = `<!-- L1: ${l1} -->\\n${body}`;\n }\n fixes.push('Generated L1 from first paragraph');\n }\n }\n\n const result = matter.stringify(body, data);\n const outFilename = ensureMdExtension(filename);\n return { content: result, filename: outFilename, fixes };\n}\n\n/**\n * Wrap a bash hook script in harness markdown.\n */\nfunction normalizeBashHook(\n content: string,\n filename: string,\n type: string | null,\n options: UniversalInstallOptions | undefined,\n fixes: string[],\n): { content: string; filename: string; fixes: string[] } {\n const id = options?.id ?? deriveId(filename);\n const primitiveType = type ?? 'workflow';\n const tags = [primitiveType, 'hook', ...(options?.tags ?? [])];\n\n // Extract description from comments at top of script\n const commentLines = content.split('\\n')\n .filter((line) => line.startsWith('#') && !line.startsWith('#!'))\n .map((line) => line.replace(/^#\\s?/, '').trim())\n .filter((line) => line.length > 0);\n\n const description = commentLines.length > 0\n ? commentLines.slice(0, 3).join(' ')\n : `Bash hook: ${id}`;\n\n const frontmatter: Record<string, unknown> = {\n id,\n created: new Date().toISOString().split('T')[0],\n author: 'human',\n status: 'active',\n tags: [...new Set(tags)],\n };\n\n const l0 = description.length > 120 ? description.slice(0, 117) + '...' : description;\n\n let body = `<!-- L0: ${l0} -->\\n\\n`;\n body += `# ${id}\\n\\n`;\n body += `${description}\\n\\n`;\n body += '```bash\\n';\n body += content;\n if (!content.endsWith('\\n')) body += '\\n';\n body += '```\\n';\n\n const result = matter.stringify(body, frontmatter);\n fixes.push('Wrapped bash script in harness markdown');\n fixes.push(`Added frontmatter (id: ${id}, type: ${primitiveType})`);\n\n const outFilename = deriveId(filename) + '.md';\n return { content: result, filename: outFilename, fixes };\n}\n\n/**\n * Convert an MCP config to harness tool documentation.\n */\nfunction normalizeMcpConfig(\n content: string,\n filename: string,\n options: UniversalInstallOptions | undefined,\n fixes: string[],\n): { content: string; filename: string; fixes: string[] } {\n const id = options?.id ?? deriveId(filename);\n const tags = ['tool', 'mcp', ...(options?.tags ?? [])];\n\n // Try to parse config\n let config: Record<string, unknown> = {};\n const ext = extname(filename).toLowerCase();\n try {\n if (ext === '.json') {\n config = JSON.parse(content) as Record<string, unknown>;\n } else {\n config = parseYaml(content) as Record<string, unknown>;\n }\n } catch {\n fixes.push('Failed to parse MCP config');\n }\n\n const serverName = String(config.name ?? config.command ?? id);\n const description = String(config.description ?? `MCP server: ${serverName}`);\n\n const frontmatter: Record<string, unknown> = {\n id,\n created: new Date().toISOString().split('T')[0],\n author: 'human',\n status: 'active',\n tags: [...new Set(tags)],\n };\n\n const l0 = description.length > 120 ? description.slice(0, 117) + '...' : description;\n\n let body = `<!-- L0: ${l0} -->\\n\\n`;\n body += `# MCP Server: ${serverName}\\n\\n`;\n body += `${description}\\n\\n`;\n body += '## Configuration\\n\\n';\n body += '```json\\n';\n body += JSON.stringify(config, null, 2);\n body += '\\n```\\n';\n\n const result = matter.stringify(body, frontmatter);\n fixes.push('Converted MCP config to harness tool documentation');\n fixes.push(`Added frontmatter (id: ${id})`);\n\n const outFilename = deriveId(filename) + '.md';\n return { content: result, filename: outFilename, fixes };\n}\n\n// ─── Source Resolution ───────────────────────────────────────────────────────\n\n/**\n * Resolve a source reference to a local file path.\n *\n * Supports:\n * - Local file paths (absolute or relative)\n * - HTTPS URLs (GitHub raw, any markdown URL)\n * - Source query (searches registered sources)\n *\n * @returns Path to a local file (downloaded if remote)\n */\nexport async function resolveSource(\n source: string,\n harnessDir: string,\n): Promise<{ localPath: string; originalSource: string; error?: string }> {\n // Case 1: Local file path\n if (existsSync(source)) {\n return { localPath: source, originalSource: source };\n }\n\n // Case 2: URL\n if (source.startsWith('https://') || source.startsWith('http://')) {\n // Convert GitHub URL to raw if needed\n const rawUrl = convertToRawUrl(source);\n const result = await downloadCapability(rawUrl);\n if (result.downloaded) {\n return { localPath: result.localPath, originalSource: source };\n }\n return { localPath: '', originalSource: source, error: result.error };\n }\n\n // Case 3: Source registry lookup — search known sources\n const results = discoverSources(harnessDir, source, { maxResults: 1 });\n if (results.length > 0) {\n const hit = results[0];\n // If the source is a GitHub source, construct a raw URL\n if (hit.source.type === 'github') {\n const rawUrl = convertToRawUrl(hit.url);\n const result = await downloadCapability(rawUrl);\n if (result.downloaded) {\n return { localPath: result.localPath, originalSource: source };\n }\n return { localPath: '', originalSource: source, error: result.error };\n }\n return { localPath: '', originalSource: source, error: `Source \"${hit.source.name}\" is type \"${hit.source.type}\" — direct install not yet supported for this type` };\n }\n\n return { localPath: '', originalSource: source, error: `Could not resolve \"${source}\" — not a local file, URL, or known source` };\n}\n\n// ─── Main Install Function ───────────────────────────────────────────────────\n\n/**\n * Universal install: resolve → detect → normalize → fix → install.\n *\n * Accepts a local path, URL, or search query. Detects the format,\n * normalizes to harness convention, applies auto-fixes, and installs\n * to the correct directory.\n *\n * @param harnessDir - Harness directory\n * @param source - File path, URL, or name to install\n * @param options - Installation options\n * @returns Install result with status, fixes, errors, dependency hints\n */\nexport async function universalInstall(\n harnessDir: string,\n source: string,\n options?: UniversalInstallOptions,\n): Promise<UniversalInstallResult> {\n const result: UniversalInstallResult = {\n installed: false,\n source,\n format: { format: 'unknown', primitiveType: null, confidence: 0, reasons: [] },\n destination: '',\n fixes: [],\n errors: [],\n suggestedDependencies: [],\n };\n\n // Step 1: Resolve source to local file\n const resolved = await resolveSource(source, harnessDir);\n if (resolved.error || !resolved.localPath) {\n result.errors.push(resolved.error ?? 'Failed to resolve source');\n return result;\n }\n\n // Step 2: Read content\n let content: string;\n try {\n content = readFileSync(resolved.localPath, 'utf-8');\n } catch (err) {\n result.errors.push(`Failed to read file: ${err instanceof Error ? err.message : String(err)}`);\n return result;\n }\n\n if (content.trim().length === 0) {\n result.errors.push('File is empty');\n return result;\n }\n\n // Step 3: Detect format\n const filename = basename(resolved.localPath);\n const detection = detectFormat(content, filename);\n result.format = detection;\n\n // Step 4: Normalize to harness convention\n const normalized = normalizeToHarness(content, filename, detection, options);\n result.fixes.push(...normalized.fixes);\n\n // Step 4b: Record provenance for URL installs so every installed file is\n // traceable back to its source. Local-path installs are skipped — the path\n // on disk is not a stable identifier.\n let finalContent = normalized.content;\n if (source.startsWith('http://') || source.startsWith('https://')) {\n finalContent = await recordProvenance(finalContent, source);\n result.fixes.push('Recorded provenance (source, installed_at, installed_by)');\n\n // Step 4c: License policy enforcement (Level 3 of task 12.14).\n // The license fields are now in the frontmatter from recordProvenance.\n // Re-parse them, evaluate against the user's `install:` config policy,\n // and either continue, warn, prompt, or block based on the decision.\n //\n // Loaded inline so universalInstall stays decoupled from CLI lifecycle.\n // Failures to load config fall back to safe defaults — never crash.\n try {\n const { loadConfig } = await import('../core/config.js');\n const config = loadConfig(harnessDir);\n const installPolicy = config.install;\n const parsed = matter(finalContent);\n const detected: LicenseInfo = {\n spdxId: typeof parsed.data.license === 'string' ? parsed.data.license : 'UNKNOWN',\n copyright: typeof parsed.data.copyright === 'string' ? parsed.data.copyright : undefined,\n licenseSource:\n typeof parsed.data.license_source === 'string' ? parsed.data.license_source : undefined,\n };\n\n const decision = evaluateLicensePolicy(detected, installPolicy, options?.forceLicense);\n\n if (decision.action === 'block') {\n result.errors.push(\n `License policy blocked install: ${decision.reason}` +\n (detected.licenseSource ? ` (${detected.licenseSource})` : '') +\n `. To override, re-run with --force-license <SPDX> if you have written permission.`,\n );\n return result;\n }\n\n if (decision.action === 'warn') {\n log.warn(\n `[install] license policy warning: ${decision.reason}. ` +\n `Installing anyway (set install.on_unknown_license: block in config.yaml to refuse).`,\n );\n result.fixes.push(`License policy: warned (${decision.spdxId})`);\n }\n\n if (decision.action === 'prompt') {\n // Prompt only on TTY. In non-TTY (CI, piped input), default to BLOCK\n // — safer than silently installing unknown content in automation.\n if (process.stdin.isTTY && process.stdout.isTTY) {\n const readline = await import('readline');\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n const question = `\\n ⚠ License policy: ${decision.reason}\\n ${\n detected.licenseSource ? `License source: ${detected.licenseSource}\\n ` : ''\n }Install anyway? [y/N] `;\n const answer = await new Promise<string>((res) => rl.question(question, res));\n rl.close();\n if (!/^y(es)?$/i.test(answer.trim())) {\n result.errors.push('License policy prompt declined by user');\n return result;\n }\n result.fixes.push(`License policy: prompted, user accepted (${decision.spdxId})`);\n } else {\n result.errors.push(\n `License policy requires interactive confirmation (${decision.reason}) ` +\n `but stdin/stdout is not a TTY. Re-run interactively, or pass ` +\n `--force-license <SPDX> if you have written permission.`,\n );\n return result;\n }\n }\n\n // 'allow' falls through silently.\n if (decision.action === 'allow' && options?.forceLicense) {\n result.fixes.push(`License policy: forced to ${decision.spdxId}`);\n }\n } catch (err) {\n // Config load failure should not block install. Log for visibility.\n log.warn(\n `[install] license policy check skipped: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n }\n\n // Step 5: Write normalized content to temp file for installation\n const tempDir = join(tmpdir(), 'harness-install');\n mkdirSync(tempDir, { recursive: true });\n const tempPath = join(tempDir, normalized.filename);\n writeFileSync(tempPath, finalContent, 'utf-8');\n\n // Step 6: Apply auto-fix if not skipped\n if (!options?.skipFix) {\n const fixResult = fixCapability(tempPath);\n result.fixes.push(...fixResult.fixes_applied);\n\n if (!fixResult.valid && !options?.force) {\n result.errors.push(...fixResult.errors);\n return result;\n }\n }\n\n // Step 7: Install via existing pipeline\n const installResult = installCapability(harnessDir, tempPath);\n result.installed = installResult.installed;\n result.destination = installResult.destination;\n\n if (!installResult.installed) {\n result.errors.push(...installResult.evalResult.errors);\n // If force mode, try direct copy\n if (options?.force && detection.primitiveType) {\n const targetDir = join(harnessDir, TYPE_DIRS[detection.primitiveType] ?? 'skills');\n if (!existsSync(targetDir)) mkdirSync(targetDir, { recursive: true });\n const dest = join(targetDir, normalized.filename);\n copyFileSync(tempPath, dest);\n result.installed = true;\n result.destination = dest;\n result.fixes.push('Force-installed despite validation errors');\n }\n }\n\n // Step 8: Scan for dependency hints\n result.suggestedDependencies = extractDependencyHints(normalized.content);\n\n return result;\n}\n\n/**\n * Install from a URL (convenience wrapper).\n */\nexport async function installFromUrl(\n harnessDir: string,\n url: string,\n options?: UniversalInstallOptions,\n): Promise<UniversalInstallResult> {\n return universalInstall(harnessDir, url, options);\n}\n\n/**\n * Install from a local file path (convenience wrapper).\n */\nexport async function installFromFile(\n harnessDir: string,\n filePath: string,\n options?: UniversalInstallOptions,\n): Promise<UniversalInstallResult> {\n return universalInstall(harnessDir, filePath, options);\n}\n\n// ─── Helpers ─────────────────────────────────────────────────────────────────\n\nfunction deriveId(filename: string): string {\n const base = basename(filename).replace(/\\.(md|faf|yaml|yml|json|sh|bash)$/i, '');\n return base.replace(/[^a-z0-9-]/gi, '-').toLowerCase();\n}\n\nfunction ensureMdExtension(filename: string): string {\n if (filename.endsWith('.md')) return filename;\n return deriveId(filename) + '.md';\n}\n\n/**\n * Convert a GitHub URL to its raw content URL.\n *\n * Handles:\n * - github.com/owner/repo/blob/branch/path → raw.githubusercontent.com/owner/repo/branch/path\n * - Already raw.githubusercontent.com URLs → pass through\n * - Other URLs → pass through\n */\nexport function convertToRawUrl(url: string): string {\n // Already raw\n if (url.includes('raw.githubusercontent.com')) return url;\n\n // GitHub blob URL → raw\n const blobMatch = url.match(\n /^https?:\\/\\/github\\.com\\/([^/]+)\\/([^/]+)\\/blob\\/(.+)$/,\n );\n if (blobMatch) {\n const [, owner, repo, rest] = blobMatch;\n return `https://raw.githubusercontent.com/${owner}/${repo}/${rest}`;\n }\n\n return url;\n}\n\n/**\n * Detect if content matches Claude Code SKILL.md patterns.\n * Claude skills are plain markdown with specific structural patterns.\n */\nfunction detectClaudeSkillPattern(content: string, filename: string): boolean {\n const nameLower = filename.toLowerCase();\n\n // Filename patterns\n if (nameLower === 'skill.md' || nameLower.endsWith('-skill.md') || nameLower.endsWith('_skill.md')) {\n return true;\n }\n\n // Content patterns common in Claude Code skills\n const patterns = [\n /^#\\s+.+skill/im,\n /instructions?\\s+for\\s+/i,\n /when\\s+(the\\s+)?user\\s+(asks?|wants?|needs?|requests?)/i,\n /you\\s+(should|must|will)\\s+/i,\n ];\n\n let matches = 0;\n for (const pattern of patterns) {\n if (pattern.test(content)) matches++;\n }\n\n // Need at least 2 pattern matches to classify as Claude skill\n // (plain markdown + instructional tone)\n return matches >= 2 && !content.startsWith('---');\n}\n\nfunction inferTypeFromFafType(fafType: string): string | null {\n const typeMap: Record<string, string> = {\n skill: 'skill',\n agent: 'agent',\n rule: 'rule',\n playbook: 'playbook',\n workflow: 'workflow',\n tool: 'tool',\n instinct: 'instinct',\n hook: 'workflow',\n template: 'skill',\n plugin: 'skill',\n };\n\n return typeMap[fafType.toLowerCase()] ?? null;\n}\n\nfunction inferTypeFromContent(content: string, filename: string): string | null {\n const lower = content.toLowerCase();\n const nameLower = filename.toLowerCase();\n\n // From filename\n if (nameLower.includes('rule')) return 'rule';\n if (nameLower.includes('agent')) return 'agent';\n if (nameLower.includes('playbook')) return 'playbook';\n if (nameLower.includes('workflow')) return 'workflow';\n if (nameLower.includes('instinct')) return 'instinct';\n if (nameLower.includes('tool')) return 'tool';\n if (nameLower.includes('skill')) return 'skill';\n\n // From content patterns\n if (lower.includes('# rule:') || lower.includes('## rules')) return 'rule';\n if (lower.includes('# agent:') || lower.includes('## agent')) return 'agent';\n if (lower.includes('# playbook:') || lower.includes('## playbook')) return 'playbook';\n if (lower.includes('# skill:') || lower.includes('## skill')) return 'skill';\n if (lower.includes('# workflow:') || lower.includes('## workflow')) return 'workflow';\n if (lower.includes('# tool:') || lower.includes('## tool')) return 'tool';\n\n // Default for markdown without clear type\n return null;\n}\n\n/**\n * Extract dependency hints from content.\n * Looks for references to tools, skills, or other primitives.\n */\nfunction extractDependencyHints(content: string): string[] {\n const hints: string[] = [];\n const seen = new Set<string>();\n\n // Look for \"requires:\" or \"depends:\" in frontmatter\n try {\n const parsed = matter(content);\n const data = parsed.data as Record<string, unknown>;\n if (Array.isArray(data.requires)) {\n for (const dep of data.requires as string[]) {\n if (!seen.has(dep)) {\n hints.push(dep);\n seen.add(dep);\n }\n }\n }\n if (Array.isArray(data.depends)) {\n for (const dep of data.depends as string[]) {\n if (!seen.has(dep)) {\n hints.push(dep);\n seen.add(dep);\n }\n }\n }\n if (Array.isArray(data.related)) {\n for (const dep of data.related as string[]) {\n if (!seen.has(dep)) {\n hints.push(dep);\n seen.add(dep);\n }\n }\n }\n } catch {\n // Ignore parse errors\n }\n\n return hints;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,cAAc,eAAe,WAAW,oBAAoB;AACjF,SAAS,MAAM,UAAU,eAAe;AACxC,SAAS,cAAc;AACvB,SAAS,qBAAqB;AAC9B,OAAO,YAAY;AACnB,SAAS,SAAS,iBAAiB;AAsBnC,SAAS,oBAA4B;AACnC,MAAI;AACF,UAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,UAAM,aAAa;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,eAAW,aAAa,YAAY;AAClC,UAAI;AACF,cAAM,MAAMA,SAAQ,SAAS;AAC7B,YAAI,IAAI,SAAS,0BAA0B,IAAI,SAAS;AACtD,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AS,OAAO,OAAO;AAC7B,UAAM,OAAO,OAAO;AACpB,QAAI,MAAM,QAAQ,KAAK,QAAQ,GAAG;AAChC,iBAAW,OAAO,KAAK,UAAsB;AAC3C,YAAI,CAAC,KAAK,IAAI,GAAG,GAAG;AAClB,gBAAM,KAAK,GAAG;AACd,eAAK,IAAI,GAAG;AAAA,QACd;AAAA,MACF;AAAA,IACF;AACA,QAAI,MAAM,QAAQ,KAAK,OAAO,GAAG;AAC/B,iBAAW,OAAO,KAAK,SAAqB;AAC1C,YAAI,CAAC,KAAK,IAAI,GAAG,GAAG;AAClB,gBAAM,KAAK,GAAG;AACd,eAAK,IAAI,GAAG;AAAA,QACd;AAAA,MACF;AAAA,IACF;AACA,QAAI,MAAM,QAAQ,KAAK,OAAO,GAAG;AAC/B,iBAAW,OAAO,KAAK,SAAqB;AAC1C,YAAI,CAAC,KAAK,IAAI,GAAG,GAAG;AAClB,gBAAM,KAAK,GAAG;AACd,eAAK,IAAI,GAAG;AAAA,QACd;AAAA,MACF;AAAA,IACF;AAAA,EACF,QAAQ;AAAA,EAER;AAEA,SAAO;AACT;","names":["require"]}
|
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
import {
|
|
4
4
|
doctorHarness,
|
|
5
5
|
validateHarness
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-AN6Y4MDD.js";
|
|
7
|
+
import "./chunk-UXCHAS3Z.js";
|
|
8
8
|
import "./chunk-5H34JPMB.js";
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-D7AWV24Z.js";
|
|
10
|
+
import "./chunk-7GZ4D6V6.js";
|
|
11
11
|
import "./chunk-UDZIS2AQ.js";
|
|
12
12
|
import "./chunk-Z2PUCXTZ.js";
|
|
13
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-2UVWCTAY.js";
|
|
14
14
|
import "./chunk-BSKDOFRT.js";
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
15
|
+
import "./chunk-EC42HQQH.js";
|
|
16
|
+
import "./chunk-4TQQZILG.js";
|
|
17
17
|
import "./chunk-ZZJOFKAT.js";
|
|
18
18
|
export {
|
|
19
19
|
doctorHarness,
|
|
20
20
|
validateHarness
|
|
21
21
|
};
|
|
22
|
-
//# sourceMappingURL=validator-
|
|
22
|
+
//# sourceMappingURL=validator-LZXBFEPV.js.map
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
loadDirectory
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-2UVWCTAY.js";
|
|
6
|
+
import "./chunk-4TQQZILG.js";
|
|
7
7
|
import "./chunk-ZZJOFKAT.js";
|
|
8
8
|
|
|
9
9
|
// src/runtime/verification-gate.ts
|
|
@@ -243,4 +243,4 @@ export {
|
|
|
243
243
|
getGatesForPlaybook,
|
|
244
244
|
loadGates
|
|
245
245
|
};
|
|
246
|
-
//# sourceMappingURL=verification-gate-
|
|
246
|
+
//# sourceMappingURL=verification-gate-ALSJVKSW.js.map
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
writeIndexFile
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-D7AWV24Z.js";
|
|
6
6
|
import {
|
|
7
7
|
autoProcessFile
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-NVC2WY4K.js";
|
|
9
|
+
import "./chunk-2UVWCTAY.js";
|
|
10
10
|
import {
|
|
11
11
|
log
|
|
12
12
|
} from "./chunk-BSKDOFRT.js";
|
|
13
13
|
import {
|
|
14
14
|
CORE_PRIMITIVE_DIRS
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-4TQQZILG.js";
|
|
16
16
|
import "./chunk-ZZJOFKAT.js";
|
|
17
17
|
|
|
18
18
|
// src/runtime/watcher.ts
|
|
@@ -106,4 +106,4 @@ function createWatcher(options) {
|
|
|
106
106
|
export {
|
|
107
107
|
createWatcher
|
|
108
108
|
};
|
|
109
|
-
//# sourceMappingURL=watcher-
|
|
109
|
+
//# sourceMappingURL=watcher-CSHVDOCM.js.map
|
|
@@ -3,26 +3,26 @@
|
|
|
3
3
|
import {
|
|
4
4
|
createWebApp,
|
|
5
5
|
startWebServer
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-SEHAQTBO.js";
|
|
7
|
+
import "./chunk-5O5OGOOQ.js";
|
|
8
8
|
import "./chunk-6EMOEYGU.js";
|
|
9
9
|
import "./chunk-GNUSHD2Y.js";
|
|
10
10
|
import "./chunk-5H34JPMB.js";
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-UMXPOYZR.js";
|
|
12
|
+
import "./chunk-7GZ4D6V6.js";
|
|
13
13
|
import "./chunk-UDZIS2AQ.js";
|
|
14
14
|
import "./chunk-DTTXPHFW.js";
|
|
15
15
|
import "./chunk-Z2PUCXTZ.js";
|
|
16
16
|
import "./chunk-TAT6JU3X.js";
|
|
17
17
|
import "./chunk-JKMGYWXB.js";
|
|
18
|
-
import "./chunk-
|
|
18
|
+
import "./chunk-2UVWCTAY.js";
|
|
19
19
|
import "./chunk-BSKDOFRT.js";
|
|
20
20
|
import "./chunk-IZ6UZ3ZL.js";
|
|
21
|
-
import "./chunk-
|
|
22
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-EC42HQQH.js";
|
|
22
|
+
import "./chunk-4TQQZILG.js";
|
|
23
23
|
import "./chunk-ZZJOFKAT.js";
|
|
24
24
|
export {
|
|
25
25
|
createWebApp,
|
|
26
26
|
startWebServer
|
|
27
27
|
};
|
|
28
|
-
//# sourceMappingURL=web-server-
|
|
28
|
+
//# sourceMappingURL=web-server-7NGOTK7J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/types.ts"],"sourcesContent":["import { z } from 'zod';\n\n// --- Frontmatter ---\nexport const FrontmatterSchema = z.object({\n id: z.string(),\n tags: z.array(z.string()).default([]),\n created: z.string().optional(),\n updated: z.string().optional(),\n author: z.enum(['human', 'agent', 'infrastructure']).default('human'),\n status: z.enum(['active', 'archived', 'deprecated', 'draft']).default('active'),\n related: z.array(z.string()).default([]),\n schedule: z.string().optional(),\n with: z.string().optional(),\n channel: z.string().optional(),\n duration_minutes: z.number().optional(),\n max_retries: z.number().int().nonnegative().optional(),\n retry_delay_ms: z.number().int().positive().optional(),\n});\n\nexport type Frontmatter = z.infer<typeof FrontmatterSchema>;\n\n// --- Primitive Document ---\nexport interface HarnessDocument {\n path: string;\n frontmatter: Frontmatter;\n l0: string;\n l1: string;\n body: string;\n raw: string;\n}\n\n// --- Primitive Types ---\nexport type PrimitiveType =\n | 'rule'\n | 'instinct'\n | 'skill'\n | 'playbook'\n | 'workflow'\n | 'tool'\n | 'agent'\n | 'session'\n | 'journal';\n\nexport interface Primitive {\n type: PrimitiveType;\n doc: HarnessDocument;\n}\n\n// --- Config ---\nexport const HarnessConfigSchema = z.object({\n agent: z.object({\n name: z.string().min(1),\n version: z.string().default('0.1.0'),\n }).passthrough(),\n model: z.object({\n provider: z.string().default('openrouter'),\n id: z.string().min(1),\n max_tokens: z.number().int().positive().default(200000),\n max_retries: z.number().int().nonnegative().default(2),\n timeout_ms: z.number().int().positive().optional(),\n /** Cheap model for auto-generating summaries, tags, frontmatter (e.g. 'google/gemini-flash-1.5') */\n summary_model: z.string().optional(),\n /** Fast model for validation, checks, and quick decisions (e.g. 'google/gemini-flash-1.5') */\n fast_model: z.string().optional(),\n }).passthrough(),\n runtime: z.object({\n scratchpad_budget: z.number().int().nonnegative().default(10000),\n /** Reserved: cron expression for periodic heartbeat check (not yet implemented) */\n heartbeat: z.string().optional(),\n /** Reserved: cron expression for daily summary generation (not yet implemented) */\n daily_summary: z.string().optional(),\n /** Auto-process primitives on save: generate frontmatter, L0/L1 summaries (default: true) */\n auto_process: z.boolean().default(true),\n quiet_hours: z.object({\n start: z.number().int().min(0).max(23).default(23),\n end: z.number().int().min(0).max(23).default(6),\n }).passthrough().default({ start: 23, end: 6 }),\n timezone: z.string().default('America/New_York'),\n }).passthrough(),\n memory: z.object({\n session_retention_days: z.number().int().positive().default(7),\n journal_retention_days: z.number().int().positive().default(365),\n }).passthrough(),\n channels: z.object({\n primary: z.string().default('cli'),\n }).passthrough(),\n extensions: z.object({\n directories: z.array(z.string()).default([]),\n }).passthrough().default({ directories: [] }),\n rate_limits: z.object({\n /** Max LLM calls per minute (default: unlimited) */\n per_minute: z.number().int().positive().optional(),\n /** Max LLM calls per hour (default: unlimited) */\n per_hour: z.number().int().positive().optional(),\n /** Max LLM calls per day (default: unlimited) */\n per_day: z.number().int().positive().optional(),\n }).passthrough().default({}),\n budget: z.object({\n /** Max daily spend in USD (default: unlimited) */\n daily_limit_usd: z.number().positive().optional(),\n /** Max monthly spend in USD (default: unlimited) */\n monthly_limit_usd: z.number().positive().optional(),\n /** Block runs when budget exceeded (default: true) */\n enforce: z.boolean().default(true),\n }).passthrough().default({ enforce: true }),\n mcp: z.object({\n /** MCP server definitions keyed by server name */\n servers: z.record(z.string(), z.object({\n /** Transport type: 'stdio' for local processes, 'http' for remote, 'sse' for SSE */\n transport: z.enum(['stdio', 'http', 'sse']),\n /** Command to spawn (stdio transport only) */\n command: z.string().optional(),\n /** Command arguments (stdio transport only) */\n args: z.array(z.string()).optional(),\n /** Environment variables for the spawned process (stdio transport only) */\n env: z.record(z.string(), z.string()).optional(),\n /** Working directory for the spawned process (stdio transport only) */\n cwd: z.string().optional(),\n /** URL endpoint (http/sse transport only) */\n url: z.string().optional(),\n /** Additional HTTP headers (http/sse transport only) */\n headers: z.record(z.string(), z.string()).optional(),\n /** Whether this server is enabled (default: true) */\n enabled: z.boolean().default(true),\n }).passthrough()).default({}),\n }).passthrough().default({ servers: {} }),\n /** Intelligence & continuous learning config */\n intelligence: z.object({\n /** Auto-run journal synthesis on a cron schedule (default: off). Set to cron string e.g. \"0 22 * * *\" or true for default \"0 22 * * *\". */\n auto_journal: z.union([z.boolean(), z.string()]).default(false),\n /** Auto-run instinct learning after journal synthesis (default: off) */\n auto_learn: z.boolean().default(false),\n }).passthrough().default({ auto_journal: false, auto_learn: false }),\n /** Proactive execution config (scheduler rate-limiting) */\n proactive: z.object({\n /** Enable proactive scheduled workflows (default: false) */\n enabled: z.boolean().default(false),\n /** Max proactive workflow executions per hour (default: 5) */\n max_per_hour: z.number().int().positive().default(5),\n /** Cooldown in minutes between proactive runs of the same workflow (default: 30) */\n cooldown_minutes: z.number().int().nonnegative().default(30),\n /** Override quiet hours for proactive execution (start/end hours, inherits runtime.quiet_hours if not set) */\n quiet_hours: z.object({\n start: z.number().int().min(0).max(23).optional(),\n end: z.number().int().min(0).max(23).optional(),\n }).passthrough().optional(),\n }).passthrough().default({ enabled: false, max_per_hour: 5, cooldown_minutes: 30 }),\n /** Primitive bundle registries for search/install */\n registries: z.array(z.object({\n /** Registry URL (HTTPS endpoint) */\n url: z.string().url(),\n /** Optional display name */\n name: z.string().optional(),\n /** Optional auth token for private registries */\n token: z.string().optional(),\n }).passthrough()).default([]),\n}).passthrough();\n\nexport type HarnessConfig = z.infer<typeof HarnessConfigSchema>;\n\nexport const CONFIG_DEFAULTS: HarnessConfig = {\n agent: { name: 'agent', version: '0.1.0' },\n model: { provider: 'openrouter', id: 'anthropic/claude-sonnet-4', max_tokens: 200000, max_retries: 2 },\n runtime: {\n scratchpad_budget: 10000,\n auto_process: true,\n quiet_hours: { start: 23, end: 6 },\n timezone: 'America/New_York',\n },\n memory: { session_retention_days: 7, journal_retention_days: 365 },\n channels: { primary: 'cli' },\n extensions: { directories: [] },\n rate_limits: {},\n budget: { enforce: true },\n intelligence: { auto_journal: false, auto_learn: false },\n proactive: { enabled: false, max_per_hour: 5, cooldown_minutes: 30 },\n mcp: { servers: {} },\n registries: [],\n};\n\nexport const CORE_PRIMITIVE_DIRS = ['rules', 'instincts', 'skills', 'playbooks', 'workflows', 'tools', 'agents'] as const;\n\nexport function getPrimitiveDirs(config?: HarnessConfig): string[] {\n const dirs: string[] = [...CORE_PRIMITIVE_DIRS];\n if (config?.extensions?.directories) {\n for (const dir of config.extensions.directories) {\n if (!dirs.includes(dir)) {\n dirs.push(dir);\n }\n }\n }\n return dirs;\n}\n\n// --- Agent State ---\nexport interface AgentState {\n mode: string;\n goals: string[];\n active_workflows: string[];\n last_interaction: string;\n unfinished_business: string[];\n}\n\n// --- Context Budget ---\nexport interface ContextBudget {\n max_tokens: number;\n used_tokens: number;\n remaining: number;\n loaded_files: string[];\n}\n\n// --- Utility Types ---\nexport type DeepPartial<T> = {\n [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];\n};\n\n// --- Lifecycle Hooks ---\nexport interface HarnessHooks {\n /** Called after boot completes (context loaded, state ready) */\n onBoot?: (context: { agent: HarnessAgent; config: HarnessConfig; state: AgentState }) => void | Promise<void>;\n /** Called after each session completes (run or stream) */\n onSessionEnd?: (context: { agent: HarnessAgent; sessionId: string; prompt: string; result: AgentRunResult }) => void | Promise<void>;\n /** Called when an error occurs during run/stream */\n onError?: (context: { agent: HarnessAgent; error: Error; prompt?: string }) => void | Promise<void>;\n /** Called when agent state changes (boot, shutdown, after run) */\n onStateChange?: (context: { agent: HarnessAgent; previous: string; current: string }) => void | Promise<void>;\n /** Called before shutdown completes */\n onShutdown?: (context: { agent: HarnessAgent; state: AgentState }) => void | Promise<void>;\n}\n\n// --- Tool Executor Config (inline to avoid circular deps) ---\nexport interface ToolExecutorOptions {\n /** Maximum tool calls per run (default: 5) */\n maxToolCalls?: number;\n /** Timeout per tool call in ms (default: 30000) */\n toolTimeoutMs?: number;\n /** Whether to allow HTTP tool execution (default: true) */\n allowHttpExecution?: boolean;\n}\n\n// --- Agent Options (programmatic API) ---\nexport interface CreateHarnessOptions {\n dir: string;\n /** Model ID override (e.g., \"claude-sonnet-4-20250514\" or \"gpt-4o\") */\n model?: string;\n /** Provider override (e.g., \"anthropic\", \"openai\", \"openrouter\") */\n provider?: string;\n apiKey?: string;\n config?: DeepPartial<HarnessConfig>;\n /** Lifecycle hooks for agent events */\n hooks?: HarnessHooks;\n /** Tool execution configuration */\n toolExecutor?: ToolExecutorOptions;\n}\n\n/** Record of a single tool call made during a run */\nexport interface ToolCallInfo {\n toolName: string;\n args: Record<string, unknown>;\n result: unknown;\n}\n\n// --- Agent Interface ---\nexport interface AgentRunResult {\n text: string;\n usage: { inputTokens: number; outputTokens: number; totalTokens: number };\n session_id: string;\n steps: number;\n /** Tool calls made during the run (empty array if none) */\n toolCalls: ToolCallInfo[];\n}\n\nexport interface AgentStreamResult {\n /** Async iterable of text chunks — consume with for-await */\n textStream: AsyncIterable<string>;\n /** Resolves after the stream is fully consumed with session metadata */\n result: Promise<AgentRunResult>;\n}\n\nexport interface HarnessAgent {\n name: string;\n config: HarnessConfig;\n boot(): Promise<void>;\n run(prompt: string): Promise<AgentRunResult>;\n stream(prompt: string): AgentStreamResult;\n shutdown(): Promise<void>;\n getSystemPrompt(): string;\n getState(): AgentState;\n}\n\n// --- Index Entry ---\nexport interface IndexEntry {\n id: string;\n path: string;\n tags: string[];\n l0: string;\n created: string;\n status: string;\n}\n"],"mappings":";;;;AAAA,SAAS,SAAS;AAGX,IAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,IAAI,EAAE,OAAO;AAAA,EACb,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,CAAC;AAAA,EACpC,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,SAAS,gBAAgB,CAAC,EAAE,QAAQ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