@agntk/agent-harness 0.1.1 → 0.1.3

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/index.js CHANGED
@@ -12444,8 +12444,79 @@ function inferContentType(filePath, sourceContentTypes) {
12444
12444
  import { existsSync as existsSync32, readFileSync as readFileSync25, writeFileSync as writeFileSync18, mkdirSync as mkdirSync16, copyFileSync as copyFileSync2 } from "fs";
12445
12445
  import { join as join32, basename as basename9, extname } from "path";
12446
12446
  import { tmpdir as tmpdir2 } from "os";
12447
+ import { createRequire } from "module";
12447
12448
  import matter4 from "gray-matter";
12448
12449
  import { parse as parseYaml3 } from "yaml";
12450
+ function getHarnessVersion() {
12451
+ try {
12452
+ const require2 = createRequire(import.meta.url);
12453
+ const candidates = [
12454
+ "../package.json",
12455
+ "../../package.json",
12456
+ "../../../package.json"
12457
+ ];
12458
+ for (const candidate of candidates) {
12459
+ try {
12460
+ const pkg = require2(candidate);
12461
+ if (pkg.name === "@agntk/agent-harness" && pkg.version) {
12462
+ return pkg.version;
12463
+ }
12464
+ } catch {
12465
+ }
12466
+ }
12467
+ return "unknown";
12468
+ } catch {
12469
+ return "unknown";
12470
+ }
12471
+ }
12472
+ async function resolveGithubCommitSha(url) {
12473
+ const match2 = url.match(
12474
+ /^https?:\/\/raw\.githubusercontent\.com\/([^/]+)\/([^/]+)\/([^/]+)\/(.+)$/
12475
+ );
12476
+ if (!match2) return null;
12477
+ const [, owner, repo, ref, path] = match2;
12478
+ if (/^[0-9a-f]{40}$/i.test(ref)) return ref;
12479
+ const apiUrl = `https://api.github.com/repos/${owner}/${repo}/contents/${path}?ref=${ref}`;
12480
+ const controller = new AbortController();
12481
+ const timeout = setTimeout(() => controller.abort(), 5e3);
12482
+ try {
12483
+ const response = await fetch(apiUrl, {
12484
+ signal: controller.signal,
12485
+ headers: { "Accept": "application/vnd.github+json" }
12486
+ });
12487
+ if (!response.ok) return null;
12488
+ const data = await response.json();
12489
+ if (typeof data.sha === "string" && /^[0-9a-f]{40}$/i.test(data.sha)) {
12490
+ return data.sha;
12491
+ }
12492
+ return null;
12493
+ } catch {
12494
+ return null;
12495
+ } finally {
12496
+ clearTimeout(timeout);
12497
+ }
12498
+ }
12499
+ async function recordProvenance(content, originalSource) {
12500
+ let parsed;
12501
+ try {
12502
+ parsed = matter4(content);
12503
+ } catch {
12504
+ return content;
12505
+ }
12506
+ const data = parsed.data;
12507
+ if (!data.source) {
12508
+ data.source = originalSource;
12509
+ }
12510
+ if (!data.source_commit) {
12511
+ const sha = await resolveGithubCommitSha(originalSource);
12512
+ if (sha) {
12513
+ data.source_commit = sha;
12514
+ }
12515
+ }
12516
+ data.installed_at = (/* @__PURE__ */ new Date()).toISOString();
12517
+ data.installed_by = `agent-harness@${getHarnessVersion()}`;
12518
+ return matter4.stringify(parsed.content, data);
12519
+ }
12449
12520
  var VALID_TYPES2 = ["rule", "instinct", "skill", "playbook", "workflow", "tool", "agent"];
12450
12521
  var TYPE_DIRS2 = {
12451
12522
  rule: "rules",
@@ -12852,10 +12923,15 @@ async function universalInstall(harnessDir, source, options) {
12852
12923
  result.format = detection;
12853
12924
  const normalized = normalizeToHarness(content, filename, detection, options);
12854
12925
  result.fixes.push(...normalized.fixes);
12926
+ let finalContent = normalized.content;
12927
+ if (source.startsWith("http://") || source.startsWith("https://")) {
12928
+ finalContent = await recordProvenance(finalContent, source);
12929
+ result.fixes.push("Recorded provenance (source, installed_at, installed_by)");
12930
+ }
12855
12931
  const tempDir = join32(tmpdir2(), "harness-install");
12856
12932
  mkdirSync16(tempDir, { recursive: true });
12857
12933
  const tempPath = join32(tempDir, normalized.filename);
12858
- writeFileSync18(tempPath, normalized.content, "utf-8");
12934
+ writeFileSync18(tempPath, finalContent, "utf-8");
12859
12935
  if (!options?.skipFix) {
12860
12936
  const fixResult = fixCapability(tempPath);
12861
12937
  result.fixes.push(...fixResult.fixes_applied);