@gitroll/tacitt-cli 0.3.0 → 0.4.1

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.
@@ -1,6 +1,6 @@
1
- import { Bn as validatePlan, Cn as sessionNonce, Dn as entityDictionaryVersion, En as cleanupImplementationVersion, Fn as frameRecords, Gn as detectStatic, H as codePointLength, Hn as defaultLimits, Ht as ApplicationError, In as retainedMainTextNodes, Jn as jsonSpans, Jt as reviewFamilies, Ln as validateProfile, Nn as nativeText, On as nativeParserVersion, Pn as transformRecords, Qt as sourceSnapshotId, Sn as createReplacementKey, Tn as parseNativeRecord, Un as recordPointerLimits, V as bDigest, Wn as resolveLimits, Wt as safeCode, Xn as createEntityMatcher, Xt as sourceKey, Yn as agentContextLocation, an as withMandatoryCustomTerms, c as textDigest, cn as mainReviewRole, dn as renderNative, fn as createSessionPreparation, gn as createDetectionSummary, in as nativeSourceIdentitySchema, ir as isProcessingCode, j as bDuplicateShift, jn as nativeField, k as bBindingCap, kn as redactionImplementationVersion, ln as reviewRoles, nr as ProcessingError, o as reviewDigest, on as processNativeRecord, pn as bindInspection, qt as familySelected, rr as fail$1, sn as projectNativeReviewInput, tr as defaultDetectionLimits, un as createSentenceContext, vn as walkNativeFields, wn as projectNativeRecord, x as createBAnalysisUnits, zn as buildPlan } from "./locate-U3-nkird.mjs";
1
+ import { Bn as validatePlan, Cn as sessionNonce, Dn as entityDictionaryVersion, En as cleanupImplementationVersion, Fn as frameRecords, Gn as detectStatic, H as codePointLength, Hn as defaultLimits, Ht as ApplicationError, In as retainedMainTextNodes, Jn as jsonSpans, Jt as reviewFamilies, Ln as validateProfile, Mn as nativeItems, Nn as nativeText, On as nativeParserVersion, Pn as transformRecords, Qt as sourceSnapshotId, Sn as createReplacementKey, Tn as parseNativeRecord, Un as recordPointerLimits, V as bDigest, Wn as resolveLimits, Wt as safeCode, Xn as createEntityMatcher, Xt as sourceKey, Yn as agentContextLocation, an as withMandatoryCustomTerms, c as textDigest, cn as mainReviewRole, dn as renderNative, fn as createSessionPreparation, gn as createDetectionSummary, in as nativeSourceIdentitySchema, ir as isProcessingCode, j as bDuplicateShift, jn as nativeField, k as bBindingCap, kn as redactionImplementationVersion, ln as reviewRoles, nr as ProcessingError, o as reviewDigest, on as processNativeRecord, pn as bindInspection, qt as familySelected, rr as fail$1, sn as projectNativeReviewInput, tr as defaultDetectionLimits, un as createSentenceContext, vn as walkNativeFields, wn as projectNativeRecord, x as createBAnalysisUnits, zn as buildPlan } from "./locate-U3-nkird.mjs";
2
2
  import { t as createZstdFrameCheck } from "./frame-waS5FnN5.mjs";
3
- import { Bn as bWordBounded, F as withSourceEvidence, I as agentSetupKey, In as bContainment, Ln as bExceptionRanges, Nt as metadataProcessingVersion, P as sourceIdentityEvidence, gr as resolveSourceSelection, ii as approvedTreatmentSchema, it as defaultAgentSetupInclusion, li as staticCatalogRef, ni as sourceChangePolicy, rt as classifyAgentSetup } from "./src-B4R5XMEP.mjs";
3
+ import { An as bContainment, Dt as metadataProcessingVersion, F as withSourceEvidence, I as agentSetupKey, Mr as agentSourceSchema, P as sourceIdentityEvidence, Pn as bWordBounded, ai as sourceChangePolicy, fi as staticCatalogRef, it as defaultAgentSetupInclusion, jn as bExceptionRanges, jr as agentSourcePathSegment, rt as classifyAgentSetup, si as approvedTreatmentSchema, ur as resolveSourceSelection } from "./src-DSDRF7i6.mjs";
4
4
  import { constants } from "node:fs";
5
5
  import { link, lstat, mkdir, open, readFile, readdir, realpath, rm, rmdir, stat, unlink } from "node:fs/promises";
6
6
  import { execFile, fork, spawn } from "node:child_process";
@@ -16,6 +16,7 @@ import "node:perf_hooks";
16
16
  import { availableParallelism, platform, tmpdir, totalmem } from "node:os";
17
17
  import { pipeline } from "node:stream/promises";
18
18
  import { constants as constants$1, createZstdDecompress } from "node:zlib";
19
+ import { parse } from "@decimalturn/toml-patch";
19
20
  //#region packages/file-privacy/src/windows/descriptor.ts
20
21
  const system = "S-1-5-18";
21
22
  const administrators = "S-1-5-32-544";
@@ -831,9 +832,9 @@ const readMetadata = async (entry, signal, maximumBytes = metadataLimitBytes) =>
831
832
  };
832
833
  //#endregion
833
834
  //#region packages/artifact/src/manifest/fields.ts
834
- const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
835
- const record = (value) => {
836
- if (!isRecord$1(value)) return fail("ARTIFACT_INVALID_MANIFEST");
835
+ const isRecord$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
836
+ const record$1 = (value) => {
837
+ if (!isRecord$2(value)) return fail("ARTIFACT_INVALID_MANIFEST");
837
838
  return value;
838
839
  };
839
840
  const string = (value) => {
@@ -860,7 +861,7 @@ const keys = (value, expected) => {
860
861
  //#endregion
861
862
  //#region packages/artifact/src/manifest/parse.ts
862
863
  const parseCounts = (value) => {
863
- const item = record(value);
864
+ const item = record$1(value);
864
865
  keys(item, [
865
866
  "workspaces",
866
867
  "sessions",
@@ -1086,7 +1087,7 @@ const nativeId = (value) => {
1086
1087
  };
1087
1088
  const nullableId = (value) => value === null ? null : nativeId(value);
1088
1089
  const parsePosition = (value) => {
1089
- const item = record(value);
1090
+ const item = record$1(value);
1090
1091
  keys(item, ["kind", "value"]);
1091
1092
  const kind = item["kind"];
1092
1093
  if (kind === "unknown" && item["value"] === null) return {
@@ -1115,7 +1116,7 @@ const parsePosition = (value) => {
1115
1116
  return fail("ARTIFACT_INVALID_MANIFEST");
1116
1117
  };
1117
1118
  const parseFork = (value) => {
1118
- const item = record(value);
1119
+ const item = record$1(value);
1119
1120
  keys(item, ["parentSessionId", "position"]);
1120
1121
  return {
1121
1122
  parentSessionId: nativeId(item["parentSessionId"]),
@@ -1124,7 +1125,7 @@ const parseFork = (value) => {
1124
1125
  };
1125
1126
  /** Relationships are explicit native metadata; names never determine roles. */
1126
1127
  const parseNativeIdentity = (value) => {
1127
- const item = record(value);
1128
+ const item = record$1(value);
1128
1129
  keys(item, [
1129
1130
  "role",
1130
1131
  "sessionId",
@@ -1143,7 +1144,7 @@ const parseNativeIdentity = (value) => {
1143
1144
  };
1144
1145
  };
1145
1146
  const parseNativeRelation = (value) => {
1146
- const item = record(value);
1147
+ const item = record$1(value);
1147
1148
  const kind = item["kind"];
1148
1149
  if (kind === "call" || kind === "result") {
1149
1150
  keys(item, ["kind", "callId"]);
@@ -1428,7 +1429,7 @@ function parseWorkspaceConfiguration(input, expectedDigest) {
1428
1429
  /** The talent-platform `challengeIdSchema`; an identifier outside it would fail the upload. */
1429
1430
  const challengeIdPattern = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/;
1430
1431
  const markerLimitBytes = 4096;
1431
- const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1432
+ const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1432
1433
  const isAbsent = (error) => error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR");
1433
1434
  /** One fixed line; never the path, the file content or the native error message. */
1434
1435
  function ignored(code) {
@@ -1481,7 +1482,7 @@ async function readChallengeId(workspacePath, signal) {
1481
1482
  } catch {
1482
1483
  return ignored("CHALLENGE_MARKER_INVALID");
1483
1484
  }
1484
- if (!isRecord(marker)) return ignored("CHALLENGE_MARKER_INVALID");
1485
+ if (!isRecord$1(marker)) return ignored("CHALLENGE_MARKER_INVALID");
1485
1486
  const challengeId = marker["challengeId"];
1486
1487
  return marker["version"] === 1 && typeof challengeId === "string" && challengeIdPattern.test(challengeId) ? challengeId : ignored("CHALLENGE_MARKER_INVALID");
1487
1488
  }
@@ -1490,7 +1491,7 @@ async function readChallengeId(workspacePath, signal) {
1490
1491
  const uuid$3 = /^[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12}$/;
1491
1492
  const digest$6 = /^[a-f0-9]{64}$/;
1492
1493
  function parseConfiguredWork(value) {
1493
- const item = record(value);
1494
+ const item = record$1(value);
1494
1495
  keys(item, [
1495
1496
  "id",
1496
1497
  "metadataPath",
@@ -1506,7 +1507,7 @@ function parseConfiguredWork(value) {
1506
1507
  };
1507
1508
  }
1508
1509
  function parseConfiguredSourceWorkspace(value) {
1509
- const item = record(value);
1510
+ const item = record$1(value);
1510
1511
  keys(item, [
1511
1512
  "id",
1512
1513
  "metadataPath",
@@ -1526,7 +1527,7 @@ function parseConfiguredSourceWorkspace(value) {
1526
1527
  };
1527
1528
  }
1528
1529
  function parseConfiguredWorkMetadata(value) {
1529
- const item = record(value);
1530
+ const item = record$1(value);
1530
1531
  keys(item, [
1531
1532
  "version",
1532
1533
  "id",
@@ -1545,7 +1546,7 @@ function parseConfiguredWorkMetadata(value) {
1545
1546
  }
1546
1547
  /** Physical hashes are never synthesized from a logical Work identity. */
1547
1548
  function validateConfiguredSourceMetadata(value, expected) {
1548
- const item = record(value);
1549
+ const item = record$1(value);
1549
1550
  keys(item, [
1550
1551
  "version",
1551
1552
  "title",
@@ -1576,7 +1577,7 @@ function digestString(value) {
1576
1577
  return result;
1577
1578
  }
1578
1579
  function parseConfiguredEntry(value) {
1579
- const item = record(value);
1580
+ const item = record$1(value);
1580
1581
  keys(item, [
1581
1582
  "entryPath",
1582
1583
  "kind",
@@ -1597,7 +1598,7 @@ function parseConfiguredEntry(value) {
1597
1598
  };
1598
1599
  }
1599
1600
  function parseConfiguredPart(value) {
1600
- const item = record(value);
1601
+ const item = record$1(value);
1601
1602
  keys(item, [
1602
1603
  "id",
1603
1604
  "sourceId",
@@ -1609,7 +1610,7 @@ function parseConfiguredPart(value) {
1609
1610
  "retainedRecordCount",
1610
1611
  "equivalence"
1611
1612
  ]);
1612
- const source = record(item["source"]);
1613
+ const source = record$1(item["source"]);
1613
1614
  keys(source, [
1614
1615
  "representation",
1615
1616
  "byteLength",
@@ -1634,7 +1635,7 @@ function parseConfiguredPart(value) {
1634
1635
  };
1635
1636
  }
1636
1637
  function session$1(value) {
1637
- const item = record(value);
1638
+ const item = record$1(value);
1638
1639
  keys(item, [
1639
1640
  "id",
1640
1641
  "workspaceId",
@@ -1657,7 +1658,7 @@ function session$1(value) {
1657
1658
  };
1658
1659
  }
1659
1660
  function exclusion$1(value) {
1660
- const item = record(value);
1661
+ const item = record$1(value);
1661
1662
  keys(item, [
1662
1663
  "sessionId",
1663
1664
  "sourceId",
@@ -1672,7 +1673,7 @@ function exclusion$1(value) {
1672
1673
  };
1673
1674
  }
1674
1675
  function parseConfiguredManifest(text) {
1675
- const item = record(strictJson(text, manifestLimitBytes, manifestNodeLimit));
1676
+ const item = record$1(strictJson(text, manifestLimitBytes, manifestNodeLimit));
1676
1677
  keys(item, [
1677
1678
  "format",
1678
1679
  "formatVersion",
@@ -1699,11 +1700,11 @@ function parseConfiguredManifest(text) {
1699
1700
  ]);
1700
1701
  const challengeId = item["challengeId"] === void 0 ? null : string(item["challengeId"]);
1701
1702
  if (challengeId !== null && !challengeIdPattern.test(challengeId)) fail("ARTIFACT_INVALID_MANIFEST");
1702
- const producer = record(item["producer"]);
1703
+ const producer = record$1(item["producer"]);
1703
1704
  keys(producer, ["name", "version"]);
1704
- const adapters = record(item["adapterVersions"]);
1705
+ const adapters = record$1(item["adapterVersions"]);
1705
1706
  keys(adapters, ["claude", "codex"]);
1706
- const setup = record(item["agentSetup"]);
1707
+ const setup = record$1(item["agentSetup"]);
1707
1708
  keys(setup, ["version", "files"]);
1708
1709
  const configurationDigest = digestString(item["configurationDigest"]);
1709
1710
  return {
@@ -1730,7 +1731,7 @@ function parseConfiguredManifest(text) {
1730
1731
  configurationDigest,
1731
1732
  configuration: parseWorkspaceConfiguration(item["configuration"], configurationDigest),
1732
1733
  sourceScope: array(item["sourceScope"], (value) => {
1733
- const source = record(value);
1734
+ const source = record$1(value);
1734
1735
  keys(source, ["sessionId", "sourceId"]);
1735
1736
  return {
1736
1737
  sessionId: string(source["sessionId"]),
@@ -1742,7 +1743,7 @@ function parseConfiguredManifest(text) {
1742
1743
  agentSetup: {
1743
1744
  version: literal(setup["version"], 1),
1744
1745
  files: array(setup["files"], (value) => {
1745
- const file = record(value);
1746
+ const file = record$1(value);
1746
1747
  keys(file, [
1747
1748
  "id",
1748
1749
  "category",
@@ -1858,7 +1859,7 @@ const digestPattern = /^[a-f0-9]{64}$/;
1858
1859
  const sessionIdPattern = /^s[0-9]{6}$/;
1859
1860
  const sourceIdPattern = /^src[0-9]{6}$/;
1860
1861
  function description(value) {
1861
- const item = record(value);
1862
+ const item = record$1(value);
1862
1863
  const kind = item["kind"];
1863
1864
  const representation = item["representation"];
1864
1865
  if (kind !== "data" && kind !== "facts" && kind !== "metadata" && kind !== "agent-setup" || representation !== "json" && representation !== "jsonl" && representation !== "jsonl.zst") return fail("ARTIFACT_INVALID_MANIFEST");
@@ -1874,16 +1875,16 @@ function description(value) {
1874
1875
  };
1875
1876
  }
1876
1877
  function checkWorkspaceManifest(text, entries, bundleId, expectedPathHash, summary) {
1877
- const manifest = record(strictJson(text, manifestLimitBytes, manifestNodeLimit));
1878
+ const manifest = record$1(strictJson(text, manifestLimitBytes, manifestNodeLimit));
1878
1879
  const treatment = manifest["contentTreatment"];
1879
1880
  const configured = treatment === "configured";
1880
1881
  const configuredManifest = configured ? parseConfiguredManifest(text) : null;
1881
1882
  if (configuredManifest) validateConfiguredManifest(configuredManifest);
1882
- const sourceWorkspaces = configuredManifest?.sourceWorkspaces ?? [record(manifest["workspace"])];
1883
+ const sourceWorkspaces = configuredManifest?.sourceWorkspaces ?? [record$1(manifest["workspace"])];
1883
1884
  const workspaceIds = new Set(sourceWorkspaces.map((workspace) => string(workspace["id"])));
1884
1885
  if (literal(manifest["format"], "sess-pilot-workspace-bundle") !== "sess-pilot-workspace-bundle" || manifest["formatVersion"] !== (configured ? 5 : 3) || string(manifest["bundleId"]) !== bundleId || summary.bundleId !== bundleId || treatment !== "original" && treatment !== "legacy-plan" && treatment !== "configured") fail("ARTIFACT_INVALID_MANIFEST");
1885
1886
  if (!configured) {
1886
- const workspace = record(manifest["workspace"]);
1887
+ const workspace = record$1(manifest["workspace"]);
1887
1888
  keys(workspace, [
1888
1889
  "id",
1889
1890
  "metadataPath",
@@ -1893,7 +1894,7 @@ function checkWorkspaceManifest(text, entries, bundleId, expectedPathHash, summa
1893
1894
  if (workspace["id"] !== "w000001" || pathHash !== null && !digestPattern.test(pathHash) || pathHash !== expectedPathHash || workspace["metadataPath"] !== "workspace/metadata.json") fail("ARTIFACT_INVALID_MANIFEST");
1894
1895
  } else if ((sourceWorkspaces.length === 1 ? sourceWorkspaces[0]?.["pathHash"] : null) !== expectedPathHash) fail("ARTIFACT_INVALID_MANIFEST");
1895
1896
  const counts = parseCounts(manifest["counts"]);
1896
- const sessions = array(manifest["sessions"], record);
1897
+ const sessions = array(manifest["sessions"], record$1);
1897
1898
  if (counts.workspaces !== sourceWorkspaces.length || sessions.length === 0 || sessions.length !== summary.sessions.length || !countsEqual(counts, summary.counts)) fail("ARTIFACT_INVALID_MANIFEST");
1898
1899
  const descriptions = /* @__PURE__ */ new Map();
1899
1900
  for (const item of array(manifest["entries"], description)) {
@@ -1912,10 +1913,10 @@ function checkWorkspaceManifest(text, entries, bundleId, expectedPathHash, summa
1912
1913
  for (const workspace of configuredManifest.sourceWorkspaces) requireEntry(workspace.metadataPath, "metadata", "json");
1913
1914
  } else requireEntry("workspace/metadata.json", "metadata", "json");
1914
1915
  if (configured) {
1915
- const setup = record(manifest["agentSetup"]);
1916
+ const setup = record$1(manifest["agentSetup"]);
1916
1917
  keys(setup, ["version", "files"]);
1917
1918
  if (setup["version"] !== 1) fail("ARTIFACT_INVALID_MANIFEST");
1918
- for (const [index, value] of array(setup["files"], record).entries()) {
1919
+ for (const [index, value] of array(setup["files"], record$1).entries()) {
1919
1920
  keys(value, [
1920
1921
  "id",
1921
1922
  "category",
@@ -1952,7 +1953,7 @@ function checkWorkspaceManifest(text, entries, bundleId, expectedPathHash, summa
1952
1953
  if (rawSession["metadataPath"] !== metadataPath) fail("ARTIFACT_INVALID_MANIFEST");
1953
1954
  requireEntry(metadataPath, "metadata", "json");
1954
1955
  }
1955
- const sessionParts = array(rawSession["parts"], record);
1956
+ const sessionParts = array(rawSession["parts"], record$1);
1956
1957
  if (sessionParts.length === 0 || sessionParts.length !== expected.sources.length) fail("ARTIFACT_INVALID_MANIFEST");
1957
1958
  for (const [partIndex, part] of sessionParts.entries()) {
1958
1959
  const source = expected.sources[partIndex] ?? fail("ARTIFACT_INVALID_MANIFEST");
@@ -1962,7 +1963,7 @@ function checkWorkspaceManifest(text, entries, bundleId, expectedPathHash, summa
1962
1963
  admitted.set(sourceId, id);
1963
1964
  if (configured) {
1964
1965
  if (source.native === null || !isDeepStrictEqual(parseNativeIdentity(part["native"]), source.native)) fail("ARTIFACT_INVALID_MANIFEST");
1965
- const sourceFacts = record(part["source"]);
1966
+ const sourceFacts = record$1(part["source"]);
1966
1967
  sourceBytes += integer(sourceFacts["byteLength"]);
1967
1968
  const data = `sessions/${id}/parts/${partId}.jsonl`;
1968
1969
  const facts = `sessions/${id}/facts/${partId}.jsonl`;
@@ -1977,21 +1978,21 @@ function checkWorkspaceManifest(text, entries, bundleId, expectedPathHash, summa
1977
1978
  const data = `sessions/${id}/parts/${partId}.${representation}`;
1978
1979
  if (part["entryPath"] !== data) fail("ARTIFACT_INVALID_MANIFEST");
1979
1980
  requireEntry(data, "data", representation);
1980
- sourceBytes += part["source"] === void 0 ? integer(part["byteLength"]) : integer(record(part["source"])["byteLength"]);
1981
+ sourceBytes += part["source"] === void 0 ? integer(part["byteLength"]) : integer(record$1(part["source"])["byteLength"]);
1981
1982
  }
1982
1983
  parts++;
1983
1984
  }
1984
1985
  }
1985
1986
  if (parts !== counts.parts || sourceBytes !== counts.sourceBytes || referenced.size !== descriptions.size) fail("ARTIFACT_INVALID_MANIFEST");
1986
1987
  const scope = /* @__PURE__ */ new Map();
1987
- for (const item of array(manifest["sourceScope"], record)) {
1988
+ for (const item of array(manifest["sourceScope"], record$1)) {
1988
1989
  const sourceId = string(item["sourceId"]);
1989
1990
  const sessionId = string(item["sessionId"]);
1990
1991
  if (!sourceIdPattern.test(sourceId) || !sessionIdPattern.test(sessionId) || scope.has(sourceId)) fail("ARTIFACT_INVALID_MANIFEST");
1991
1992
  scope.set(sourceId, sessionId);
1992
1993
  }
1993
1994
  const excluded = /* @__PURE__ */ new Set();
1994
- for (const item of array(manifest["exclusions"], record)) {
1995
+ for (const item of array(manifest["exclusions"], record$1)) {
1995
1996
  const sourceId = string(item["sourceId"]);
1996
1997
  if (scope.get(sourceId) !== item["sessionId"] || excluded.has(sourceId)) fail("ARTIFACT_INVALID_MANIFEST");
1997
1998
  excluded.add(sourceId);
@@ -2065,7 +2066,7 @@ async function checkWrittenWorkspaceBundle(path, identity, expectedManifestText,
2065
2066
  //#endregion
2066
2067
  //#region packages/artifact/src/collection/companion.ts
2067
2068
  function companionManifest(primaryText, primary, entries) {
2068
- const manifest = record(strictJson(primaryText, manifestLimitBytes, manifestNodeLimit));
2069
+ const manifest = record$1(strictJson(primaryText, manifestLimitBytes, manifestNodeLimit));
2069
2070
  if (manifest["formatVersion"] !== 5 || manifest["companionVersion"] !== 3 || manifest["contentTreatment"] !== "configured") return fail("ARTIFACT_INVALID_MANIFEST");
2070
2071
  return JSON.stringify({
2071
2072
  format: "sess-pilot-workspace-companion",
@@ -2080,7 +2081,7 @@ function companionManifest(primaryText, primary, entries) {
2080
2081
  });
2081
2082
  }
2082
2083
  function checkCompanionManifest(text, entries, primaryText, primary) {
2083
- const value = record(strictJson(text, manifestLimitBytes, manifestNodeLimit));
2084
+ const value = record$1(strictJson(text, manifestLimitBytes, manifestNodeLimit));
2084
2085
  keys(value, [
2085
2086
  "format",
2086
2087
  "formatVersion",
@@ -2092,12 +2093,12 @@ function checkCompanionManifest(text, entries, primaryText, primary) {
2092
2093
  literal(value["format"], "sess-pilot-workspace-companion");
2093
2094
  literal(value["formatVersion"], 1);
2094
2095
  literal(value["companionVersion"], 3);
2095
- const descriptions = array(value["entries"], record);
2096
- const expected = record(strictJson(companionManifest(primaryText, primary, descriptions), manifestLimitBytes, manifestNodeLimit));
2096
+ const descriptions = array(value["entries"], record$1);
2097
+ const expected = record$1(strictJson(companionManifest(primaryText, primary, descriptions), manifestLimitBytes, manifestNodeLimit));
2097
2098
  if (!isDeepStrictEqual(value, expected)) fail("ARTIFACT_INVALID_MANIFEST");
2098
2099
  const paths = /* @__PURE__ */ new Set();
2099
- const primaryManifest = record(strictJson(primaryText, manifestLimitBytes, manifestNodeLimit));
2100
- const parts = array(primaryManifest["sessions"], record).flatMap((session) => array(session["parts"], record));
2100
+ const primaryManifest = record$1(strictJson(primaryText, manifestLimitBytes, manifestNodeLimit));
2101
+ const parts = array(primaryManifest["sessions"], record$1).flatMap((session) => array(session["parts"], record$1));
2101
2102
  for (const part of parts) {
2102
2103
  const path = string(part["factsPath"]);
2103
2104
  if (paths.has(path)) fail("ARTIFACT_INVALID_MANIFEST");
@@ -2221,7 +2222,7 @@ const roles = [
2221
2222
  ];
2222
2223
  const parseRole = (value) => roles.find((role) => role === value) ?? fail("ARTIFACT_INVALID_MANIFEST");
2223
2224
  const parseBody = (value) => {
2224
- const item = record(value);
2225
+ const item = record$1(value);
2225
2226
  keys(item, [
2226
2227
  "bodyId",
2227
2228
  "fieldId",
@@ -2271,7 +2272,7 @@ function sampleLocations(bodies, fields, locations) {
2271
2272
  return synthetic;
2272
2273
  }
2273
2274
  const measured$1 = (value, parse) => {
2274
- const item = record(value);
2275
+ const item = record$1(value);
2275
2276
  const state = item["state"];
2276
2277
  keys(item, [
2277
2278
  "state",
@@ -2295,8 +2296,8 @@ const measured$1 = (value, parse) => {
2295
2296
  };
2296
2297
  return fail("ARTIFACT_INVALID_MANIFEST");
2297
2298
  };
2298
- const patch$1 = (value) => {
2299
- const item = record(value);
2299
+ const patch$2 = (value) => {
2300
+ const item = record$1(value);
2300
2301
  keys(item, [
2301
2302
  "grammarVersion",
2302
2303
  "basis",
@@ -2315,7 +2316,7 @@ const patch$1 = (value) => {
2315
2316
  };
2316
2317
  };
2317
2318
  const parseFacts = (value) => {
2318
- const item = record(value);
2319
+ const item = record$1(value);
2319
2320
  const optional = [
2320
2321
  "decodedUtf8Bytes",
2321
2322
  "logicalLines",
@@ -2338,7 +2339,7 @@ const parseFacts = (value) => {
2338
2339
  extractorVersion: literal(item["extractorVersion"], "native-retention-v1"),
2339
2340
  ...Object.hasOwn(item, "decodedUtf8Bytes") ? { decodedUtf8Bytes: measured$1(item["decodedUtf8Bytes"], integer) } : {},
2340
2341
  ...Object.hasOwn(item, "logicalLines") ? { logicalLines: measured$1(item["logicalLines"], integer) } : {},
2341
- ...Object.hasOwn(item, "patchDelta") ? { patchDelta: measured$1(item["patchDelta"], patch$1) } : {}
2342
+ ...Object.hasOwn(item, "patchDelta") ? { patchDelta: measured$1(item["patchDelta"], patch$2) } : {}
2342
2343
  };
2343
2344
  };
2344
2345
  /** IDs address original nodes, never mutable output positions. */
@@ -2643,7 +2644,7 @@ async function verifyConfiguredPart(part, entries, descriptions, signal) {
2643
2644
  //#region packages/artifact/src/read/configured/workspace.ts
2644
2645
  /** Public primary facts are parsed independently; no source file is opened. */
2645
2646
  function workspaceSummary(text) {
2646
- const manifest = record(parseConfiguredManifest(text));
2647
+ const manifest = record$1(parseConfiguredManifest(text));
2647
2648
  if (manifest["contentTreatment"] !== "configured" || manifest["formatVersion"] !== 5 || manifest["companionVersion"] !== 3) return fail("ARTIFACT_INVALID_MANIFEST");
2648
2649
  return {
2649
2650
  format: "sess-pilot-workspace-summary",
@@ -2651,7 +2652,7 @@ function workspaceSummary(text) {
2651
2652
  bundleId: string(manifest["bundleId"]),
2652
2653
  counts: parseCounts(manifest["counts"]),
2653
2654
  sessions: array(manifest["sessions"], (value) => {
2654
- const session = record(value);
2655
+ const session = record$1(value);
2655
2656
  const harness = session["harness"];
2656
2657
  if (harness !== "claude" && harness !== "codex") return fail("ARTIFACT_INVALID_MANIFEST");
2657
2658
  return {
@@ -2681,7 +2682,7 @@ async function readPrimaryMetadata(primaryEntries, primaryText, signal, only) {
2681
2682
  if (description.representation !== "jsonl" && (!only || only.has(description.entryPath))) {
2682
2683
  const text = await readMetadata(entry, signal);
2683
2684
  if (createHash("sha256").update(text).digest("hex") !== description.sha256) fail("ARTIFACT_INVALID_ARCHIVE");
2684
- const metadata = record(strictJson(text, metadataLimitBytes));
2685
+ const metadata = record$1(strictJson(text, metadataLimitBytes));
2685
2686
  if (description.entryPath === manifest.work.metadataPath) {
2686
2687
  if (parseConfiguredWorkMetadata(metadata).id !== manifest.work.id) fail("ARTIFACT_INVALID_MANIFEST");
2687
2688
  }
@@ -2690,7 +2691,7 @@ async function readPrimaryMetadata(primaryEntries, primaryText, signal, only) {
2690
2691
  if (description.entryPath.startsWith("sessions/")) {
2691
2692
  keys(metadata, ["version", "session"]);
2692
2693
  if (metadata["version"] !== 3) fail("ARTIFACT_INVALID_MANIFEST");
2693
- const session = record(metadata["session"]);
2694
+ const session = record$1(metadata["session"]);
2694
2695
  keys(session, [
2695
2696
  "id",
2696
2697
  "harness",
@@ -2715,11 +2716,11 @@ async function readPrimaryMetadata(primaryEntries, primaryText, signal, only) {
2715
2716
  async function readConfiguredWorkspacePair(primaryEntries, primaryText, companionEntries, companionText, primary, signal, only) {
2716
2717
  const { summary } = await readPrimaryMetadata(primaryEntries, primaryText, signal, only);
2717
2718
  checkCompanionManifest(companionText, companionEntries, primaryText, primary);
2718
- const manifest = record(strictJson(primaryText, manifestLimitBytes, manifestNodeLimit));
2719
- const companion = record(strictJson(companionText, manifestLimitBytes, manifestNodeLimit));
2719
+ const manifest = record$1(strictJson(primaryText, manifestLimitBytes, manifestNodeLimit));
2720
+ const companion = record$1(strictJson(companionText, manifestLimitBytes, manifestNodeLimit));
2720
2721
  const descriptions = new Map([...array(manifest["entries"], parseConfiguredEntry), ...array(companion["entries"], parseConfiguredEntry)].map((entry) => [entry.entryPath, entry]));
2721
2722
  const entries = new Map([...primaryEntries, ...[...companionEntries].filter(([path]) => path !== "manifest.json")]);
2722
- for (const session of array(manifest["sessions"], record)) for (const part of array(session["parts"], parseConfiguredPart)) if (!only || only.has(part.dataPath)) await verifyConfiguredPart(part, entries, descriptions, signal);
2723
+ for (const session of array(manifest["sessions"], record$1)) for (const part of array(session["parts"], parseConfiguredPart)) if (!only || only.has(part.dataPath)) await verifyConfiguredPart(part, entries, descriptions, signal);
2723
2724
  return summary;
2724
2725
  }
2725
2726
  //#endregion
@@ -3226,21 +3227,23 @@ async function inspectInput(input, part, adapter, signal, overrides, complete =
3226
3227
  const inspector = adapter.source(part);
3227
3228
  const limits = resolveLimits(overrides);
3228
3229
  let records = 0;
3230
+ let identityRecords = 0;
3229
3231
  let readingRecords = true;
3230
3232
  const cleanup = createCleanup();
3231
3233
  try {
3232
3234
  for await (const text of frameRecords(input.chunks, "jsonl", limits.maxRecordBytes, signal)) {
3233
3235
  const root = parseNativeRecord(text, limits, signal);
3234
3236
  inspector.inspect(root);
3235
- observe?.(root);
3236
3237
  const native = inspector.current();
3238
+ observe?.(root, native);
3237
3239
  if (!complete && native.role !== "unknown" && native.sessionId !== null) {
3238
3240
  const identity = inspector.finish();
3239
3241
  checkNativeEvidence(part, identity);
3240
3242
  return identity;
3241
3243
  }
3242
3244
  records += 1;
3243
- if (!complete && records >= 256) break;
3245
+ if (adapter.identityRecord?.(root) !== false) identityRecords += 1;
3246
+ if (!complete && identityRecords >= 256) break;
3244
3247
  }
3245
3248
  readingRecords = false;
3246
3249
  if (complete) await (input.finish ?? fail("ARTIFACT_PROCESSING_FAILED"))();
@@ -3271,20 +3274,24 @@ async function inspectCompleteCapturedSourceIdentity(part, captured, adapter, si
3271
3274
  return inspectInput(await openCapturedConfiguredSource(part, captured, signal), part, adapter, signal, overrides, true, observe);
3272
3275
  }
3273
3276
  /**
3274
- * First launch named by the frozen capture, the same first-known value admission observes;
3275
- * undefined when no record names one or the adapter has no launch port.
3277
+ * Launch on the first identity-bearing record that names a launch, matching admission. Later per-record launch
3278
+ * metadata cannot redefine session admission; absent launch retains legacy behavior.
3276
3279
  */
3277
3280
  async function capturedLaunch(part, captured, adapter, signal, overrides) {
3278
3281
  const launch = adapter.launch;
3279
3282
  if (!launch) return void 0;
3283
+ const inspector = adapter.source(part);
3280
3284
  const limits = resolveLimits(overrides);
3281
3285
  const input = await openCapturedConfiguredSource(part, captured, signal);
3282
3286
  let records = 0;
3283
3287
  const cleanup = createCleanup();
3284
3288
  try {
3285
3289
  for await (const text of frameRecords(input.chunks, "jsonl", limits.maxRecordBytes, signal)) {
3286
- const value = launch(parseNativeRecord(text, limits, signal));
3287
- if (value !== void 0) return value;
3290
+ const root = parseNativeRecord(text, limits, signal);
3291
+ inspector.inspect(root);
3292
+ const identity = inspector.current();
3293
+ const value = launch(root);
3294
+ if (identity.sessionId !== null && adapter.identityRecord?.(root) !== false && value !== void 0) return value;
3288
3295
  records += 1;
3289
3296
  }
3290
3297
  return;
@@ -3973,11 +3980,11 @@ function configuredSelection(selection, treatment) {
3973
3980
  if (modes !== void 0 && !object(modes)) return fail("ARTIFACT_INVALID_APPROVAL");
3974
3981
  const guardians = new Set(selection.diagnostics.filter((diagnostic) => diagnostic.code === "guardian-excluded").map((diagnostic) => diagnostic.nodeId));
3975
3982
  if (cleanup.ref.id === "native-evidence") {
3976
- if (selection.omitRecord && guardians.has(void 0)) return selection;
3983
+ if (selection.omitRecord && (guardians.has(void 0) || selection.diagnostics.some((item) => item.code === "unsupported-native-shape"))) return selection;
3977
3984
  return {
3978
3985
  diagnostics: selection.diagnostics,
3979
3986
  edits: selection.edits.map((edit) => {
3980
- if (guardians.has(edit.nodeId)) return edit;
3987
+ if (guardians.has(edit.nodeId) || edit.alwaysApply && edit.role === "derived") return edit;
3981
3988
  const { replacement: _replacement, retainAs: _retainAs, replacementOrigin, replacementSourceRanges: _replacementSourceRanges, replacementTargetRanges: _replacementTargetRanges, ...original } = edit;
3982
3989
  return {
3983
3990
  ...original,
@@ -4729,6 +4736,277 @@ function createInspectionProcessor(processing) {
4729
4736
  } };
4730
4737
  }
4731
4738
  //#endregion
4739
+ //#region packages/artifact/src/agent-sources/model.ts
4740
+ function isRecord(value) {
4741
+ return value !== null && typeof value === "object" && !Array.isArray(value);
4742
+ }
4743
+ function record(value) {
4744
+ return isRecord(value) ? value : {};
4745
+ }
4746
+ function publicName(value) {
4747
+ return typeof value === "string" && /^[a-zA-Z0-9][a-zA-Z0-9_.:-]{0,199}$/.test(value);
4748
+ }
4749
+ function repository(value) {
4750
+ if (typeof value !== "string") return false;
4751
+ const segments = value.split("/");
4752
+ return segments.length === 2 && segments.every((part) => part.length <= 100 && agentSourcePathSegment(part));
4753
+ }
4754
+ function repoPath(value) {
4755
+ return value.length <= 500 && value.split("/").every(agentSourcePathSegment);
4756
+ }
4757
+ //#endregion
4758
+ //#region packages/artifact/src/agent-sources/mcp.ts
4759
+ /** Only direct npx invocation has npm provenance; never preserve its arguments. */
4760
+ function npmPackage(value) {
4761
+ const entry = record(value);
4762
+ if (entry["command"] !== "npx" || entry["url"] !== void 0 || entry["type"] !== void 0 && entry["type"] !== "stdio") return void 0;
4763
+ const args = entry["args"];
4764
+ if (!Array.isArray(args) || !args.every((arg) => typeof arg === "string")) return void 0;
4765
+ if (args.some((arg) => /registry|userconfig/i.test(arg)) || Object.keys(record(entry["env"])).some((key) => /registry|userconfig/i.test(key))) return void 0;
4766
+ let position = 0;
4767
+ while (args[position] === "-y" || args[position] === "--yes" || args[position] === "--no") position++;
4768
+ const candidate = args[position];
4769
+ if (candidate === void 0) return void 0;
4770
+ const name = /^((?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*)(?:@[a-zA-Z0-9][a-zA-Z0-9._~^*-]*)?$/.exec(candidate)?.[1];
4771
+ return name !== void 0 && name.length <= 214 ? name : void 0;
4772
+ }
4773
+ function mcpCandidates(value, names) {
4774
+ const output = [];
4775
+ for (const [name, entry] of Object.entries(record(value)).slice(0, 500)) {
4776
+ if (!publicName(name) || !names.has(name)) continue;
4777
+ const packageName = npmPackage(entry);
4778
+ if (packageName) output.push({
4779
+ kind: "mcp",
4780
+ name,
4781
+ source: {
4782
+ type: "npm",
4783
+ package: packageName
4784
+ }
4785
+ });
4786
+ }
4787
+ return output;
4788
+ }
4789
+ //#endregion
4790
+ //#region packages/artifact/src/agent-sources/read.ts
4791
+ /** Optional enrichment treats missing, malformed and unreadable config as omissions. */
4792
+ async function readText(path) {
4793
+ try {
4794
+ const file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK);
4795
+ try {
4796
+ const info = await file.stat();
4797
+ if (!info.isFile() || info.size > 1048576) return void 0;
4798
+ const buffer = Buffer.alloc(1048577);
4799
+ const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
4800
+ return bytesRead <= 1048576 ? buffer.subarray(0, bytesRead).toString("utf8") : void 0;
4801
+ } finally {
4802
+ await file.close();
4803
+ }
4804
+ } catch {
4805
+ return;
4806
+ }
4807
+ }
4808
+ async function readJson(path) {
4809
+ const text = await readText(path);
4810
+ if (text === void 0) return void 0;
4811
+ try {
4812
+ return JSON.parse(text);
4813
+ } catch {
4814
+ return;
4815
+ }
4816
+ }
4817
+ //#endregion
4818
+ //#region packages/artifact/src/agent-sources/plugins.ts
4819
+ async function skillsAt(root) {
4820
+ try {
4821
+ const entries = await readdir(join(root, "skills"), { withFileTypes: true });
4822
+ const result = [];
4823
+ for (const entry of entries.slice(0, 500)) {
4824
+ if (!entry.isDirectory() || !repoPath(entry.name)) continue;
4825
+ const path = `skills/${entry.name}/SKILL.md`;
4826
+ const text = await readText(join(root, path));
4827
+ const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(text ?? "")?.[1];
4828
+ const name = /^name:\s*["']?([a-zA-Z0-9][a-zA-Z0-9_.:-]*)["']?\s*$/m.exec(frontmatter ?? "")?.[1];
4829
+ if (name && publicName(name)) result.push({
4830
+ name,
4831
+ path
4832
+ });
4833
+ }
4834
+ return result;
4835
+ } catch {
4836
+ return [];
4837
+ }
4838
+ }
4839
+ async function pluginCandidates(home, workspacePath, skills, mcps) {
4840
+ const base = join(home, ".claude", "plugins");
4841
+ const installed = record(record(await readJson(join(base, "installed_plugins.json")))["plugins"]);
4842
+ const marketplaces = record(await readJson(join(base, "known_marketplaces.json")));
4843
+ const personalAndProject = new Set((await Promise.all([skillsAt(join(home, ".claude")), skillsAt(join(workspacePath, ".claude"))])).flat().map((skill) => skill.name));
4844
+ const definitions = /* @__PURE__ */ new Map();
4845
+ const bareCandidates = /* @__PURE__ */ new Set();
4846
+ const output = [];
4847
+ for (const [key, entries] of Object.entries(installed).slice(0, 128)) {
4848
+ const [plugin, marketplace, extra] = key.split("@");
4849
+ if (!plugin || !marketplace || extra !== void 0 || !publicName(plugin)) continue;
4850
+ const market = record(marketplaces[marketplace]);
4851
+ const marketSource = record(market["source"]);
4852
+ const location = market["installLocation"];
4853
+ const catalog = typeof location === "string" ? record(await readJson(join(location, ".claude-plugin", "marketplace.json")))["plugins"] : void 0;
4854
+ const catalogEntry = Array.isArray(catalog) ? catalog.find((item) => record(item)["name"] === plugin) : void 0;
4855
+ const descriptor = record(catalogEntry);
4856
+ const source = record(descriptor["source"]);
4857
+ const relativeSource = descriptor["source"];
4858
+ const prefix = typeof relativeSource === "string" && relativeSource.startsWith("./") && repoPath(relativeSource.slice(2)) ? relativeSource.slice(2) : void 0;
4859
+ const repo = source["source"] === "github" ? source["repo"] : catalogEntry !== void 0 && (relativeSource === void 0 || prefix !== void 0) && (marketSource["source"] === void 0 || marketSource["source"] === "github") ? marketSource["repo"] : void 0;
4860
+ if (!Array.isArray(entries)) continue;
4861
+ const rank = (value) => {
4862
+ const entry = record(value);
4863
+ const scope = entry["scope"];
4864
+ if (scope === "local" || scope === "project") {
4865
+ const projectPath = entry["projectPath"];
4866
+ if (typeof projectPath !== "string" || resolve(projectPath) !== resolve(workspacePath)) return -1;
4867
+ return scope === "local" ? 3 : 2;
4868
+ }
4869
+ return scope === void 0 || scope === "user" ? 1 : -1;
4870
+ };
4871
+ const selected = entries.slice(0, 8).filter((entry) => rank(entry) >= 0).sort((left, right) => rank(right) - rank(left)).slice(0, 1);
4872
+ for (const raw of selected) {
4873
+ const entry = record(raw);
4874
+ const root = entry["installPath"];
4875
+ if (typeof root !== "string") continue;
4876
+ const pluginMcp = record(await readJson(join(root, ".mcp.json")));
4877
+ const servers = record(pluginMcp["mcpServers"] ?? pluginMcp);
4878
+ output.push(...mcpCandidates(servers, mcps));
4879
+ for (const [server, configuration] of Object.entries(servers).slice(0, 500)) {
4880
+ const alias = `plugin_${plugin}_${server}`;
4881
+ if (mcps.has(alias)) output.push(...mcpCandidates({ [alias]: configuration }, mcps));
4882
+ }
4883
+ const directSource = record(entry["source"]);
4884
+ const candidateRepo = directSource["source"] === "github" ? directSource["repo"] : entry["source"] === void 0 ? repo : void 0;
4885
+ const installedSkills = await skillsAt(root);
4886
+ for (const skill of installedSkills) {
4887
+ const owners = definitions.get(skill.name) ?? /* @__PURE__ */ new Set();
4888
+ owners.add(key);
4889
+ definitions.set(skill.name, owners);
4890
+ }
4891
+ if (!repository(candidateRepo)) continue;
4892
+ const commit = entry["gitCommitSha"];
4893
+ for (const skill of installedSkills) for (const name of [`${plugin}:${skill.name}`, skill.name]) {
4894
+ if (!skills.has(name)) continue;
4895
+ const path = directSource["source"] === "github" || source["source"] === "github" ? skill.path : prefix ? `${prefix}/${skill.path}` : void 0;
4896
+ const candidate = {
4897
+ kind: "skill",
4898
+ name,
4899
+ source: {
4900
+ type: "github",
4901
+ repo: candidateRepo,
4902
+ ...path === void 0 ? {} : { path },
4903
+ ...typeof commit === "string" && /^[a-fA-F0-9]{40}$/.test(commit) ? { commit } : {}
4904
+ }
4905
+ };
4906
+ output.push(candidate);
4907
+ if (name === skill.name) bareCandidates.add(candidate);
4908
+ }
4909
+ }
4910
+ }
4911
+ return output.filter((item) => !bareCandidates.has(item) || definitions.get(item.name)?.size === 1 && !personalAndProject.has(item.name)).slice(0, 500);
4912
+ }
4913
+ //#endregion
4914
+ //#region packages/artifact/src/agent-sources/index.ts
4915
+ /** Collection-time candidates stay local until anonymous upload-time admission. */
4916
+ async function collectAgentSourceCandidates(options) {
4917
+ const skills = new Set(options.skills.slice(0, 500));
4918
+ const mcps = new Set(options.mcps.slice(0, 500));
4919
+ if (skills.size === 0 && mcps.size === 0) return [];
4920
+ const output = [];
4921
+ if (options.harness !== "codex") {
4922
+ const user = record(await readJson(join(options.userHome, ".claude.json")));
4923
+ const project = record(await readJson(join(options.workspacePath, ".mcp.json")));
4924
+ const local = record(record(user["projects"])[options.workspacePath]);
4925
+ const servers = {
4926
+ ...record(user["mcpServers"]),
4927
+ ...record(project["mcpServers"]),
4928
+ ...record(local["mcpServers"])
4929
+ };
4930
+ const plugins = await pluginCandidates(options.userHome, options.workspacePath, skills, mcps);
4931
+ output.push(...plugins.filter((item) => item.kind !== "mcp" || !(item.name in servers)));
4932
+ output.push(...mcpCandidates(servers, mcps));
4933
+ }
4934
+ const toml = options.harness === "claude" ? void 0 : await readText(join(options.userHome, ".codex", "config.toml"));
4935
+ if (toml !== void 0) try {
4936
+ output.push(...mcpCandidates(record(parse(toml))["mcp_servers"], mcps));
4937
+ } catch {}
4938
+ const customRegistry = (await Promise.all([readText(join(options.workspacePath, ".npmrc")), readText(join(options.userHome, ".npmrc"))])).some((text) => text?.split(/\r?\n/u).some((line) => /^\s*(?:@[^:=\s]+:)?registry\s*=/iu.test(line)));
4939
+ const privateTerms = [basename(options.userHome), ...options.customTerms ?? []].map((term) => term.normalize("NFC").toLowerCase()).filter(Boolean);
4940
+ const admitted = output.filter((item) => !(customRegistry && item.source.type === "npm") && ![item.name, ...item.source.type === "github" ? [item.source.repo, item.source.path ?? ""] : [item.source.package]].some((value) => privateTerms.some((term) => value.normalize("NFC").toLowerCase().includes(term))));
4941
+ return [...new Map(admitted.map((item) => [`${item.kind}:${item.name}`, item])).values()].slice(0, 500);
4942
+ }
4943
+ //#endregion
4944
+ //#region packages/artifact/src/configured/session/agent-sources.ts
4945
+ /** Recognized call positions only: arbitrary prose and tool results never establish usage. */
4946
+ function createAgentSourceCollector(harness) {
4947
+ const skills = /* @__PURE__ */ new Set();
4948
+ const mcps = /* @__PURE__ */ new Set();
4949
+ const add = (set, name) => {
4950
+ if (name && set.size < 500 && /^[A-Za-z0-9_][A-Za-z0-9_.:-]{0,199}$/u.test(name)) set.add(name);
4951
+ };
4952
+ const mcp = (name) => {
4953
+ if (!name?.startsWith("mcp__")) return;
4954
+ const server = name.slice(5).split("__")[0];
4955
+ if (server && /^[A-Za-z0-9_-]+$/u.test(server)) add(mcps, server);
4956
+ };
4957
+ return {
4958
+ add(root) {
4959
+ const type = nativeText(nativeField(root, "type"));
4960
+ if (harness === "claude" && type === "assistant") {
4961
+ const message = nativeField(root, "message");
4962
+ const role = nativeText(nativeField(message, "role"));
4963
+ if (role !== void 0 && role !== "assistant") return;
4964
+ for (const item of nativeItems(nativeField(message, "content"))) {
4965
+ if (nativeText(nativeField(item, "type")) !== "tool_use") continue;
4966
+ const name = nativeText(nativeField(item, "name"));
4967
+ if (name === "Skill") add(skills, nativeText(nativeField(nativeField(item, "input"), "skill")));
4968
+ else mcp(name);
4969
+ }
4970
+ }
4971
+ if (harness === "codex") {
4972
+ const payload = nativeField(root, "payload");
4973
+ const payloadType = nativeText(nativeField(payload, "type"));
4974
+ if (type === "response_item" && payloadType === "function_call") {
4975
+ mcp(nativeText(nativeField(payload, "name")));
4976
+ mcp(nativeText(nativeField(payload, "namespace")));
4977
+ }
4978
+ if (type === "event_msg" && payloadType === "mcp_tool_call_begin") add(mcps, nativeText(nativeField(nativeField(payload, "invocation"), "server")));
4979
+ }
4980
+ },
4981
+ names: () => ({
4982
+ skills: [...skills],
4983
+ mcps: [...mcps]
4984
+ })
4985
+ };
4986
+ }
4987
+ async function collectSessionAgentSources(request, names) {
4988
+ const userHome = request.processing.environment.userHome;
4989
+ if (!userHome || !request.workspace.path || names.skills.length === 0 && names.mcps.length === 0) return [];
4990
+ try {
4991
+ const candidates = await collectAgentSourceCandidates({
4992
+ userHome,
4993
+ harness: request.session.harness,
4994
+ customTerms: request.processing.customTerms?.terms ?? [],
4995
+ workspacePath: request.workspace.path,
4996
+ ...names
4997
+ });
4998
+ const items = [];
4999
+ for (const candidate of candidates) {
5000
+ const parsed = agentSourceSchema.safeParse(candidate);
5001
+ if (parsed.success) items.push(parsed.data);
5002
+ }
5003
+ return items.slice(0, 500);
5004
+ } catch {
5005
+ console.error("AGENT_SOURCES_COLLECTION_UNAVAILABLE");
5006
+ return [];
5007
+ }
5008
+ }
5009
+ //#endregion
4732
5010
  //#region packages/artifact/src/configured/masks/text.ts
4733
5011
  /** Generated title input is local metadata, not an asserted location inside a captured native row. */
4734
5012
  function titleMasks(input, output) {
@@ -4928,8 +5206,12 @@ async function prepareConfiguredSession(request) {
4928
5206
  const metadata = metadataRoot(request, owner.limits);
4929
5207
  const gitIdentity = await prepareGit(request, owner.signal, owner.preparation);
4930
5208
  const agentSetup = request.collectAgentSetup ? createAgentSetupCollector(request) : void 0;
5209
+ const agentSources = request.collectAgentSetup ? createAgentSourceCollector(request.session.harness) : void 0;
4931
5210
  let images = 0;
4932
- const snapshots = await prepareSources(request, owner, metadata, agentSetup?.add, (count) => {
5211
+ const snapshots = await prepareSources(request, owner, metadata, (root) => {
5212
+ agentSetup?.add(root);
5213
+ agentSources?.add(root);
5214
+ }, (count) => {
4933
5215
  images += count;
4934
5216
  });
4935
5217
  owner.seal();
@@ -4996,6 +5278,7 @@ async function prepareConfiguredSession(request) {
4996
5278
  ...processedMetadata.masks === void 0 ? {} : { metadataMasks: processedMetadata.masks },
4997
5279
  sources: Object.freeze(sources),
4998
5280
  agentSetup: Object.freeze(setup),
5281
+ ...agentSources ? { agentSources: await collectSessionAgentSources(request, agentSources.names()) } : {},
4999
5282
  images
5000
5283
  });
5001
5284
  await owner.close();
@@ -5019,10 +5302,10 @@ async function prepareConfiguredSession(request) {
5019
5302
  //#region packages/artifact/src/collection/producer/session-metadata.ts
5020
5303
  /** Validate the session-only shape already projected before configured processing. */
5021
5304
  function sessionMetadata(metadata) {
5022
- const root = record(strictJson(metadata, metadataLimitBytes));
5305
+ const root = record$1(strictJson(metadata, metadataLimitBytes));
5023
5306
  keys(root, ["version", "session"]);
5024
5307
  literal(root["version"], 3);
5025
- const session = record(root["session"]);
5308
+ const session = record$1(root["session"]);
5026
5309
  const compact = JSON.stringify({
5027
5310
  version: 3,
5028
5311
  session
@@ -5629,7 +5912,7 @@ function boundedHash(value) {
5629
5912
  return result;
5630
5913
  }
5631
5914
  function parseIdentityMap(value) {
5632
- const input = record(value);
5915
+ const input = record$1(value);
5633
5916
  keys(input, [
5634
5917
  "format",
5635
5918
  "formatVersion",
@@ -5638,7 +5921,7 @@ function parseIdentityMap(value) {
5638
5921
  ]);
5639
5922
  const bundleId = string(input["bundleId"]);
5640
5923
  validBundleId(bundleId);
5641
- const workspace = record(input["workspace"]);
5924
+ const workspace = record$1(input["workspace"]);
5642
5925
  keys(workspace, [
5643
5926
  "path",
5644
5927
  "pathHash",
@@ -5652,7 +5935,7 @@ function parseIdentityMap(value) {
5652
5935
  if (!Array.isArray(rawRemotes)) return fail("ARTIFACT_INVALID_MANIFEST");
5653
5936
  if (rawRemotes.length > maximumRemotes) fail("ARTIFACT_METADATA_LIMIT");
5654
5937
  const remotes = rawRemotes.map((entry) => {
5655
- const remote = record(entry);
5938
+ const remote = record$1(entry);
5656
5939
  keys(remote, ["url", "hash"]);
5657
5940
  return {
5658
5941
  url: boundedLocator(remote["url"]),
@@ -6359,7 +6642,7 @@ const pointer$3 = (value) => {
6359
6642
  return text;
6360
6643
  };
6361
6644
  const range$2 = (value) => {
6362
- const v = record(value);
6645
+ const v = record$1(value);
6363
6646
  keys(v, ["start", "end"]);
6364
6647
  const start = integer(v["start"]), end = integer(v["end"]);
6365
6648
  if (end <= start) fail("ARTIFACT_INVALID_MANIFEST");
@@ -6385,7 +6668,7 @@ function rowRanges(value, fields) {
6385
6668
  });
6386
6669
  }
6387
6670
  function mask(value) {
6388
- const v = record(value);
6671
+ const v = record$1(value);
6389
6672
  keys(v, [
6390
6673
  "inputRange",
6391
6674
  "outputRange",
@@ -6394,9 +6677,9 @@ function mask(value) {
6394
6677
  "node",
6395
6678
  "ruleId"
6396
6679
  ]);
6397
- const node = record(v["node"]);
6680
+ const node = record$1(v["node"]);
6398
6681
  keys(node, ["id", "version"]);
6399
- const output = record(v["outputRange"]);
6682
+ const output = record$1(v["outputRange"]);
6400
6683
  keys(output, ["start", "end"]);
6401
6684
  const start = integer(output["start"]), end = integer(output["end"]);
6402
6685
  const replacement = string(v["replacement"]);
@@ -6417,7 +6700,7 @@ function mask(value) {
6417
6700
  };
6418
6701
  }
6419
6702
  function field(value) {
6420
- const v = record(value);
6703
+ const v = record$1(value);
6421
6704
  keys(v, [
6422
6705
  "pointer",
6423
6706
  "cleanedPointer",
@@ -6460,7 +6743,7 @@ function field(value) {
6460
6743
  return result;
6461
6744
  }
6462
6745
  function parsePrivateReviewRow(text) {
6463
- const v = record(strictJson(text, 67108864));
6746
+ const v = record$1(strictJson(text, 67108864));
6464
6747
  keys(v, [
6465
6748
  "entryPath",
6466
6749
  "recordIndex",
@@ -6486,7 +6769,7 @@ function parsePrivateReviewRow(text) {
6486
6769
  };
6487
6770
  }
6488
6771
  function parsePrivateReviewManifest(text, entries, primary) {
6489
- const v = record(strictJson(text, manifestLimitBytes, manifestNodeLimit));
6772
+ const v = record$1(strictJson(text, manifestLimitBytes, manifestNodeLimit));
6490
6773
  keys(v, [
6491
6774
  "format",
6492
6775
  "version",
@@ -6496,11 +6779,11 @@ function parsePrivateReviewManifest(text, entries, primary) {
6496
6779
  "entries",
6497
6780
  "rows"
6498
6781
  ]);
6499
- const bound = record(v["primary"]);
6782
+ const bound = record$1(v["primary"]);
6500
6783
  keys(bound, ["sha256", "archiveBytes"]);
6501
6784
  if (v["bundleId"] !== primary.manifest.bundleId || v["workId"] !== primary.manifest.work.id || bound["sha256"] !== primary.sha256 || bound["archiveBytes"] !== primary.archiveBytes) fail("ARTIFACT_PROCESSING_MISMATCH");
6502
6785
  const descriptions = array(v["entries"], (value) => {
6503
- const e = record(value);
6786
+ const e = record$1(value);
6504
6787
  keys(e, [
6505
6788
  "entryPath",
6506
6789
  "kind",
@@ -7727,7 +8010,7 @@ function createMaskContexts() {
7727
8010
  /** Resolves a stored context of the next row read; a reference must name an earlier one. */
7728
8011
  read(row, inputSha256, value) {
7729
8012
  enter(row);
7730
- const data = record(value);
8013
+ const data = record$1(value);
7731
8014
  const start = integer(data["start"]);
7732
8015
  if (!Object.hasOwn(data, "text")) {
7733
8016
  keys(data, ["start", "end"]);
@@ -7755,7 +8038,7 @@ const hash$3 = (value) => {
7755
8038
  return text;
7756
8039
  };
7757
8040
  const range$1 = (value) => {
7758
- const data = record(value);
8041
+ const data = record$1(value);
7759
8042
  keys(data, ["start", "end"]);
7760
8043
  const start = integer(data["start"]);
7761
8044
  const end = integer(data["end"]);
@@ -7772,7 +8055,7 @@ const pointer$2 = (value) => {
7772
8055
  };
7773
8056
  /** Parses one row in ledger order; `contexts` resolves context references (ADR 0084). */
7774
8057
  function parsePrivateMaskRow(text, contexts) {
7775
- const row = record(strictJson(text, 33554432));
8058
+ const row = record$1(strictJson(text, 33554432));
7776
8059
  keys(row, [
7777
8060
  "entryPath",
7778
8061
  "recordIndex",
@@ -7781,7 +8064,7 @@ function parsePrivateMaskRow(text, contexts) {
7781
8064
  "archiveSessionId",
7782
8065
  "mask"
7783
8066
  ]);
7784
- const item = record(row["mask"]);
8067
+ const item = record$1(row["mask"]);
7785
8068
  keys(item, [
7786
8069
  "inputRange",
7787
8070
  "outputRange",
@@ -7798,7 +8081,7 @@ function parsePrivateMaskRow(text, contexts) {
7798
8081
  "outputSha256",
7799
8082
  "context"
7800
8083
  ]);
7801
- const node = record(item["node"]);
8084
+ const node = record$1(item["node"]);
7802
8085
  keys(node, ["id", "version"]);
7803
8086
  const entryPath = string(row["entryPath"]);
7804
8087
  const recordIndex = integer(row["recordIndex"]);
@@ -7843,7 +8126,7 @@ function parsePrivateMaskRow(text, contexts) {
7843
8126
  };
7844
8127
  }
7845
8128
  function parsePrivateMaskManifest(text, entries, primary) {
7846
- const data = record(strictJson(text, manifestLimitBytes, manifestNodeLimit));
8129
+ const data = record$1(strictJson(text, manifestLimitBytes, manifestNodeLimit));
7847
8130
  keys(data, [
7848
8131
  "format",
7849
8132
  "version",
@@ -7854,11 +8137,11 @@ function parsePrivateMaskManifest(text, entries, primary) {
7854
8137
  "entries",
7855
8138
  "rows"
7856
8139
  ]);
7857
- const binding = record(data["primary"]);
8140
+ const binding = record$1(data["primary"]);
7858
8141
  keys(binding, ["sha256", "archiveBytes"]);
7859
8142
  if (data["bundleId"] !== primary.manifest.bundleId || data["workId"] !== primary.manifest.work.id || binding["sha256"] !== primary.sha256 || binding["archiveBytes"] !== primary.archiveBytes) return fail("ARTIFACT_PROCESSING_MISMATCH");
7860
8143
  const descriptions = array(data["entries"], (value) => {
7861
- const entry = record(value);
8144
+ const entry = record$1(value);
7862
8145
  keys(entry, [
7863
8146
  "entryPath",
7864
8147
  "kind",
@@ -7925,7 +8208,7 @@ function maskHash(value) {
7925
8208
  return text;
7926
8209
  }
7927
8210
  function maskRange(value) {
7928
- const data = record(value);
8211
+ const data = record$1(value);
7929
8212
  keys(data, ["start", "end"]);
7930
8213
  const result = {
7931
8214
  start: integer(data["start"]),
@@ -7940,7 +8223,7 @@ function pointer$1(value) {
7940
8223
  return text;
7941
8224
  }
7942
8225
  function semantic(value, scope, contexts) {
7943
- const data = record(value);
8226
+ const data = record$1(value);
7944
8227
  keys(data, [
7945
8228
  "pointer",
7946
8229
  "inputSha256",
@@ -7967,7 +8250,7 @@ function semantic(value, scope, contexts) {
7967
8250
  }
7968
8251
  /** Parses one row in ledger order; `contexts` resolves static context references (ADR 0084). */
7969
8252
  function parseFinalMaskRow(text, contexts) {
7970
- const data = record(strictJson(text, 33554432));
8253
+ const data = record$1(strictJson(text, 33554432));
7971
8254
  keys(data, [
7972
8255
  "entryPath",
7973
8256
  "recordIndex",
@@ -7982,7 +8265,7 @@ function parseFinalMaskRow(text, contexts) {
7982
8265
  const subject = data["subject"];
7983
8266
  if (subject !== "key" && subject !== "value") return fail("ARTIFACT_INVALID_MANIFEST");
7984
8267
  const contributors = array(data["contributors"], (value) => {
7985
- const item = record(value);
8268
+ const item = record$1(value);
7986
8269
  keys(item, [
7987
8270
  "id",
7988
8271
  "kind",
@@ -8031,7 +8314,7 @@ function parseFinalMaskRow(text, contexts) {
8031
8314
  //#endregion
8032
8315
  //#region packages/artifact/src/configured/masks/final/manifest.ts
8033
8316
  function categories(value) {
8034
- const item = record(value);
8317
+ const item = record$1(value);
8035
8318
  keys(item, [
8036
8319
  "identity",
8037
8320
  "credentials",
@@ -8046,7 +8329,7 @@ function categories(value) {
8046
8329
  };
8047
8330
  }
8048
8331
  function maskSummary(value) {
8049
- const data = record(value);
8332
+ const data = record$1(value);
8050
8333
  keys(data, [
8051
8334
  "occurrences",
8052
8335
  "contributors",
@@ -8064,7 +8347,7 @@ function maskSummariesEqual(a, b) {
8064
8347
  return a.occurrences === b.occurrences && a.contributors === b.contributors && a.categories.identity === b.categories.identity && a.categories.credentials === b.categories.credentials && a.categories.internal === b.categories.internal && a.categories.private === b.categories.private;
8065
8348
  }
8066
8349
  function parseFinalMaskManifest(text, entries, primary) {
8067
- const data = record(strictJson(text, manifestLimitBytes, manifestNodeLimit));
8350
+ const data = record$1(strictJson(text, manifestLimitBytes, manifestNodeLimit));
8068
8351
  keys(data, [
8069
8352
  "format",
8070
8353
  "version",
@@ -8078,13 +8361,13 @@ function parseFinalMaskManifest(text, entries, primary) {
8078
8361
  "entries",
8079
8362
  "summary"
8080
8363
  ]);
8081
- const binding = record(data["primary"]);
8364
+ const binding = record$1(data["primary"]);
8082
8365
  keys(binding, ["sha256", "archiveBytes"]);
8083
8366
  if (data["bundleId"] !== primary.manifest.bundleId || data["workId"] !== primary.manifest.work.id || binding["sha256"] !== primary.sha256 || binding["archiveBytes"] !== primary.archiveBytes) fail("ARTIFACT_PROCESSING_MISMATCH");
8084
8367
  const expected = new Set(primary.manifest.entries.map((entry) => `${entry.entryPath}.masks.jsonl`));
8085
8368
  let total = emptyMaskSummary();
8086
8369
  const descriptions = array(data["entries"], (value) => {
8087
- const row = record(value);
8370
+ const row = record$1(value);
8088
8371
  keys(row, [
8089
8372
  "entryPath",
8090
8373
  "kind",
@@ -8950,7 +9233,7 @@ async function rewriteConfiguredOutput(request, handle, signal = new AbortContro
8950
9233
  archiveBytes: primaryResult.archiveBytes
8951
9234
  };
8952
9235
  const finalMaskLedger = await masks?.finish(changed, finalPrimary, { rows: request.shards === void 0 });
8953
- const companionValue = record(strictJson(companion.manifestText, manifestLimitBytes, manifestNodeLimit));
9236
+ const companionValue = record$1(strictJson(companion.manifestText, manifestLimitBytes, manifestNodeLimit));
8954
9237
  const companionEntries = [];
8955
9238
  for (const description of array(companionValue["entries"], parseConfiguredEntry)) {
8956
9239
  const entry = companion.entries.get(description.entryPath) ?? fail("ARTIFACT_INVALID_ARCHIVE");
@@ -10304,7 +10587,7 @@ function validateCollectionIndex(index) {
10304
10587
  const maximumCollectionIndexBytes = 16777216;
10305
10588
  const maximumCollectionNodes = 1e6;
10306
10589
  function source(value) {
10307
- const item = record(value);
10590
+ const item = record$1(value);
10308
10591
  keys(item, [
10309
10592
  "sourceId",
10310
10593
  "sourceOrdinal",
@@ -10317,7 +10600,7 @@ function source(value) {
10317
10600
  };
10318
10601
  }
10319
10602
  function session(value) {
10320
- const item = record(value);
10603
+ const item = record$1(value);
10321
10604
  keys(item, [
10322
10605
  "sessionId",
10323
10606
  "scopeOrdinal",
@@ -10338,7 +10621,7 @@ function session(value) {
10338
10621
  };
10339
10622
  }
10340
10623
  function parseCollectionWorkspaceSummary(value) {
10341
- const item = record(value);
10624
+ const item = record$1(value);
10342
10625
  keys(item, [
10343
10626
  "format",
10344
10627
  "formatVersion",
@@ -10355,7 +10638,7 @@ function parseCollectionWorkspaceSummary(value) {
10355
10638
  };
10356
10639
  }
10357
10640
  function parseCompanionDescriptor(value) {
10358
- const item = record(value);
10641
+ const item = record$1(value);
10359
10642
  keys(item, [
10360
10643
  "path",
10361
10644
  "archiveBytes",
@@ -10368,7 +10651,7 @@ function parseCompanionDescriptor(value) {
10368
10651
  };
10369
10652
  }
10370
10653
  function bundle(value) {
10371
- const item = record(value);
10654
+ const item = record$1(value);
10372
10655
  keys(item, [
10373
10656
  "workspaceSlot",
10374
10657
  "workspaceVersion",
@@ -10403,7 +10686,7 @@ function bundle(value) {
10403
10686
  };
10404
10687
  }
10405
10688
  function sourceScope(value) {
10406
- const item = record(value);
10689
+ const item = record$1(value);
10407
10690
  keys(item, ["applicationSessionId", "sourceId"]);
10408
10691
  return {
10409
10692
  applicationSessionId: string(item["applicationSessionId"]),
@@ -10411,7 +10694,7 @@ function sourceScope(value) {
10411
10694
  };
10412
10695
  }
10413
10696
  function exclusion(value) {
10414
- const item = record(value);
10697
+ const item = record$1(value);
10415
10698
  keys(item, [
10416
10699
  "applicationSessionId",
10417
10700
  "sourceId",
@@ -10426,7 +10709,7 @@ function exclusion(value) {
10426
10709
  };
10427
10710
  }
10428
10711
  function sessionBinding(value) {
10429
- const item = record(value);
10712
+ const item = record$1(value);
10430
10713
  keys(item, [
10431
10714
  "applicationSessionId",
10432
10715
  "bundleId",
@@ -10441,7 +10724,7 @@ function sessionBinding(value) {
10441
10724
  };
10442
10725
  }
10443
10726
  function sourceBinding(value) {
10444
- const item = record(value);
10727
+ const item = record$1(value);
10445
10728
  keys(item, [
10446
10729
  "applicationSessionId",
10447
10730
  "sourceId",
@@ -10467,7 +10750,7 @@ function parseCollectionIndex(text) {
10467
10750
  if (error instanceof Error && error.message === "ARTIFACT_METADATA_LIMIT") fail("ARTIFACT_INDEX_LIMIT", { cause: error });
10468
10751
  throw error;
10469
10752
  }
10470
- const item = record(value);
10753
+ const item = record$1(value);
10471
10754
  keys(item, [
10472
10755
  "format",
10473
10756
  "formatVersion",
@@ -10563,7 +10846,7 @@ function measured(value, copy) {
10563
10846
  reasonCode: value.reasonCode
10564
10847
  };
10565
10848
  }
10566
- function patch(value) {
10849
+ function patch$1(value) {
10567
10850
  return {
10568
10851
  grammarVersion: value.grammarVersion,
10569
10852
  basis: value.basis,
@@ -10582,7 +10865,7 @@ function fact(value) {
10582
10865
  extractorVersion: value.extractorVersion,
10583
10866
  ...value.decodedUtf8Bytes === void 0 ? {} : { decodedUtf8Bytes: measured(value.decodedUtf8Bytes, (number) => number) },
10584
10867
  ...value.logicalLines === void 0 ? {} : { logicalLines: measured(value.logicalLines, (number) => number) },
10585
- ...value.patchDelta === void 0 ? {} : { patchDelta: measured(value.patchDelta, patch) }
10868
+ ...value.patchDelta === void 0 ? {} : { patchDelta: measured(value.patchDelta, patch$1) }
10586
10869
  };
10587
10870
  }
10588
10871
  function relation(value) {
@@ -10710,7 +10993,7 @@ function pointer(value) {
10710
10993
  return result;
10711
10994
  }
10712
10995
  function parseInputField(value) {
10713
- const v = record(value);
10996
+ const v = record$1(value);
10714
10997
  keys(v, [
10715
10998
  "fieldId",
10716
10999
  "sourceFieldId",
@@ -10732,13 +11015,13 @@ function parseInputField(value) {
10732
11015
  if (scalarKind !== void 0 && scalarKind !== "literal" && scalarKind !== "structure" && scalarKind !== "container") return fail("ARTIFACT_INVALID_MANIFEST");
10733
11016
  const text = string(v["text"]), fieldHash = digest(v["fieldHash"]);
10734
11017
  if (!text.length || hash$1(text) !== fieldHash) fail("ARTIFACT_PROCESSING_MISMATCH");
10735
- const c = v["cleanedRange"] === void 0 ? void 0 : record(v["cleanedRange"]);
11018
+ const c = v["cleanedRange"] === void 0 ? void 0 : record$1(v["cleanedRange"]);
10736
11019
  if (c) keys(c, ["start", "end"]);
10737
11020
  const cleanedRange = c ? {
10738
11021
  start: integer(c["start"]),
10739
11022
  end: integer(c["end"])
10740
11023
  } : void 0;
10741
- const r = v["originalRange"] === void 0 ? void 0 : record(v["originalRange"]);
11024
+ const r = v["originalRange"] === void 0 ? void 0 : record$1(v["originalRange"]);
10742
11025
  if (r) keys(r, ["start", "end"]);
10743
11026
  const range = r ? {
10744
11027
  start: integer(r["start"]),
@@ -11108,6 +11391,7 @@ async function runConfiguredSessionJob(job, processing, signal, onSourceProgress
11108
11391
  parts,
11109
11392
  entries,
11110
11393
  agentSetup: completed.agentSetup,
11394
+ ...completed.agentSources === void 0 ? {} : { agentSources: completed.agentSources },
11111
11395
  images: completed.images
11112
11396
  };
11113
11397
  } catch (error) {
@@ -12748,10 +13032,11 @@ async function admitConfiguredSources(approval, processing, signal, hooks, isola
12748
13032
  const adapter = processing.adapters[session.harness];
12749
13033
  const launch = adapter.launch;
12750
13034
  let launchKnown = false;
12751
- const observe = launch && ((root) => {
12752
- if (launchKnown) return;
13035
+ const observe = launch && ((root, identity) => {
13036
+ if (launchKnown || identity.sessionId === null || adapter.identityRecord?.(root) === false) return;
12753
13037
  const value = launch(root);
12754
- launchKnown = value !== void 0;
13038
+ if (value === void 0) return;
13039
+ launchKnown = true;
12755
13040
  if (value === "interactive") interactive.add(id);
12756
13041
  if (value === "automation" && assessedOnly.has(session.id)) automated.add(id);
12757
13042
  });
@@ -15316,6 +15601,7 @@ async function runConfiguredScanJob(job, processing, signal, onSourceProgress, o
15316
15601
  requireCurrentCleanup(job.cleanup);
15317
15602
  const owner = createOwner(request);
15318
15603
  const buffered = [];
15604
+ const toleratedDrift = /* @__PURE__ */ new Map();
15319
15605
  const verified = /* @__PURE__ */ new Map();
15320
15606
  let bufferedUtf16 = 0, mainRecords = 0, emptyEligible = true;
15321
15607
  try {
@@ -15337,6 +15623,12 @@ async function runConfiguredScanJob(job, processing, signal, onSourceProgress, o
15337
15623
  const inspector = adapter.source(source.source);
15338
15624
  const input = await owner.open(source);
15339
15625
  let ordinal = 0;
15626
+ let identitySeen = false;
15627
+ const tolerate = (shape) => {
15628
+ const counts = toleratedDrift.get(source.id) ?? {};
15629
+ counts[shape] = (counts[shape] ?? 0) + 1;
15630
+ toleratedDrift.set(source.id, counts);
15631
+ };
15340
15632
  let reading = true;
15341
15633
  try {
15342
15634
  for await (const record of roots(input, owner.limits, owner.signal)) {
@@ -15346,7 +15638,15 @@ async function runConfiguredScanJob(job, processing, signal, onSourceProgress, o
15346
15638
  const original = retain(root);
15347
15639
  const annotations = adapter.annotations(root, nativeOptions, original);
15348
15640
  prepareOriginals(root, original, annotations, owner.preparation, owner.limits, owner.signal);
15349
- if (adapter.mainProseComplete?.(root, original) !== true || adapter.launch?.(root) === "automation") fail("ARTIFACT_PROCESSING_UNSUPPORTED");
15641
+ if (adapter.mainProseComplete?.(root, original, tolerate) !== true) fail("ARTIFACT_PROCESSING_UNSUPPORTED");
15642
+ const native = inspector.current();
15643
+ const launch = adapter.launch?.(root);
15644
+ const identityRecord = native.sessionId !== null && adapter.identityRecord?.(root) !== false && launch !== void 0;
15645
+ if (launch === "automation") {
15646
+ if (!identitySeen && identityRecord) fail("ARTIFACT_PROCESSING_UNSUPPORTED");
15647
+ tolerate("launch");
15648
+ }
15649
+ identitySeen ||= identityRecord;
15350
15650
  const id = recordId(source.id, capture.facts, ordinal);
15351
15651
  const projection = projectNativeReviewInput({
15352
15652
  root,
@@ -15467,8 +15767,18 @@ async function runConfiguredScanJob(job, processing, signal, onSourceProgress, o
15467
15767
  input: {
15468
15768
  ...metadataRow,
15469
15769
  file: await fields.finish()
15470
- }
15770
+ },
15771
+ toleratedDrift: [...toleratedDrift].map(([sourceId, driftCounts]) => ({
15772
+ sourceId,
15773
+ count: Object.values(driftCounts).reduce((sum, count) => sum + count, 0),
15774
+ driftCounts
15775
+ }))
15471
15776
  };
15777
+ for (const { sourceId, driftCounts } of result.toleratedDrift ?? []) processing.onAnomaly?.({
15778
+ code: "tolerated-harness-drift",
15779
+ sourceId,
15780
+ driftCounts
15781
+ });
15472
15782
  success = true;
15473
15783
  return result;
15474
15784
  } finally {
@@ -15588,6 +15898,17 @@ async function scanPreparedSession(production, sessionId, directory, hooks, canc
15588
15898
  const capture = captures.find((row) => row.partId === source.source.id);
15589
15899
  if (capture && JSON.stringify(actual.facts) !== JSON.stringify(capture.facts)) fail("ARTIFACT_SOURCE_CHANGED");
15590
15900
  }
15901
+ const drift = settled.toleratedDrift ?? [];
15902
+ if (parallel && parallel.size > 1) for (const { sourceId, driftCounts } of drift) production.processing.onAnomaly?.({
15903
+ code: "tolerated-harness-drift",
15904
+ sourceId,
15905
+ driftCounts
15906
+ });
15907
+ hooks.onTiming?.({
15908
+ scope: "preparation",
15909
+ phases: {},
15910
+ volumes: { scanToleratedDrift: drift.reduce((sum, row) => sum + row.count, 0) }
15911
+ });
15591
15912
  return settled;
15592
15913
  } catch (error) {
15593
15914
  const id = error instanceof SessionWorkerError ? error.sourceId : recordSourceId(error);
@@ -15613,7 +15934,7 @@ function hash(value) {
15613
15934
  return text;
15614
15935
  }
15615
15936
  function range(value) {
15616
- const v = record(value);
15937
+ const v = record$1(value);
15617
15938
  keys(v, ["start", "end"]);
15618
15939
  const start = integer(v["start"]), end = integer(v["end"]);
15619
15940
  if (end <= start) fail("ARTIFACT_PROCESSING_MISMATCH");
@@ -15634,7 +15955,7 @@ function rowIdentity(v, input) {
15634
15955
  };
15635
15956
  }
15636
15957
  function parseSessionScanRow(value, input) {
15637
- const v = record(value);
15958
+ const v = record$1(value);
15638
15959
  keys(v, [
15639
15960
  "sourceId",
15640
15961
  "ordinal",
@@ -15644,7 +15965,7 @@ function parseSessionScanRow(value, input) {
15644
15965
  const { sourceId, ordinal, id, source } = rowIdentity(v, input);
15645
15966
  const ids = /* @__PURE__ */ new Set();
15646
15967
  const fields = array(v["fields"], (item) => {
15647
- const { sessionId, sourceId: fieldSource, ordinal: fieldOrdinal, recordId: fieldRecord, protectedRanges, ...plain } = record(item);
15968
+ const { sessionId, sourceId: fieldSource, ordinal: fieldOrdinal, recordId: fieldRecord, protectedRanges, ...plain } = record$1(item);
15648
15969
  const field = parseInputField(plain);
15649
15970
  if (!source || source.native.role !== "main" || sessionId !== input.sessionId || fieldSource !== sourceId || fieldOrdinal !== ordinal || fieldRecord !== id || field.role === "tool-output" || field.scalarKind !== void 0 || ids.has(field.fieldId) || !field.sourceFieldId.startsWith(`${id}-f`)) fail("ARTIFACT_PROCESSING_MISMATCH");
15650
15971
  const node = field.sourceFieldId.slice(`${id}-f`.length);
@@ -15671,20 +15992,20 @@ function parseSessionScanRow(value, input) {
15671
15992
  };
15672
15993
  }
15673
15994
  function scanFile(value) {
15674
- const file = record(value);
15995
+ const file = record$1(value);
15675
15996
  keys(file, [
15676
15997
  "path",
15677
15998
  "identity",
15678
15999
  "sha256",
15679
16000
  "byteLength"
15680
16001
  ]);
15681
- const identity = record(file["identity"]);
16002
+ const identity = record$1(file["identity"]);
15682
16003
  keys(identity, ["dev", "ino"]);
15683
16004
  if (!string(file["path"]) || !string(identity["dev"]) || !string(identity["ino"]) || integer(file["byteLength"]) > maximumPartBytes) fail("ARTIFACT_PROCESSING_MISMATCH");
15684
16005
  hash(file["sha256"]);
15685
16006
  }
15686
16007
  function validateSessionScanInput(input) {
15687
- keys(record(input), [
16008
+ keys(record$1(input), [
15688
16009
  "version",
15689
16010
  "sessionId",
15690
16011
  "emptyReviewVerified",
@@ -15701,7 +16022,7 @@ function validateSessionScanInput(input) {
15701
16022
  integer(input.fieldCount);
15702
16023
  integer(input.inputUtf16);
15703
16024
  const sources = /* @__PURE__ */ new Set(), parts = /* @__PURE__ */ new Set();
15704
- for (const item of array(input.sources, record)) {
16025
+ for (const item of array(input.sources, record$1)) {
15705
16026
  keys(item, [
15706
16027
  "sourceId",
15707
16028
  "sourcePartId",
@@ -15712,7 +16033,7 @@ function validateSessionScanInput(input) {
15712
16033
  if (!id || !part || sources.has(id) || parts.has(part) || !nativeSourceIdentitySchema.safeParse(item["native"]).success) fail("ARTIFACT_PROCESSING_MISMATCH");
15713
16034
  sources.add(id);
15714
16035
  parts.add(part);
15715
- const facts = record(item["facts"]);
16036
+ const facts = record$1(item["facts"]);
15716
16037
  keys(facts, [
15717
16038
  "representation",
15718
16039
  "byteLength",
@@ -15748,7 +16069,7 @@ async function* scan(handle, input, signal) {
15748
16069
  const ordinals = /* @__PURE__ */ new Map();
15749
16070
  for await (const value of frames(handle, input.file, signal)) {
15750
16071
  if (footer) fail("ARTIFACT_PROCESSING_MISMATCH");
15751
- if (record(value)["kind"] === "session-scan-footer") {
16072
+ if (record$1(value)["kind"] === "session-scan-footer") {
15752
16073
  const { file: _file, ...descriptor } = input;
15753
16074
  if (!isDeepStrictEqual(value, {
15754
16075
  kind: "session-scan-footer",
@@ -16174,7 +16495,7 @@ function createWorkPieces() {
16174
16495
  const occurrences = /* @__PURE__ */ new Map();
16175
16496
  for (const { field, row } of fields) for (const spec of cut(fieldOutline(field), repeated)) {
16176
16497
  if (taken.has(spec.id)) continue;
16177
- const text = field.text.slice(spec.utf16Start, spec.utf16End);
16498
+ const text = Buffer.from(field.text.slice(spec.utf16Start, spec.utf16End), "utf16le").toString("utf16le");
16178
16499
  if (spec.key) {
16179
16500
  texts.set(spec.key, text);
16180
16501
  occurrences.set(spec.key, (occurrences.get(spec.key) ?? 0) + 1);