@adamchanadam/agent-handoff-kit 0.3.42 → 0.3.43

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.
@@ -38,13 +38,13 @@ export function validateOfficialOriginCatalog(catalog) {
38
38
  }
39
39
  if (entry.canonicalSha256 !== content.canonicalSha256) {
40
40
  throw new Error(`official origin catalog canonical hash mismatch: ${version} ${targetRel}`);
41
- }
42
- referenced.add(entry.contentId);
43
- }
44
- for (const targetRel of Object.keys(release.managedSegments ?? {})) {
45
- getArtifactBoundManagedSegment({ version, targetRel, catalog });
46
- }
47
- }
41
+ }
42
+ referenced.add(entry.contentId);
43
+ }
44
+ for (const targetRel of Object.keys(release.managedSegments ?? {})) {
45
+ getArtifactBoundManagedSegment({ version, targetRel, catalog });
46
+ }
47
+ }
48
48
 
49
49
  for (const [contentId, content] of Object.entries(catalog.contents)) {
50
50
  if (contentId !== sha256(`${content.targetRel}\0${content.text}`)) {
@@ -58,31 +58,31 @@ export function validateOfficialOriginCatalog(catalog) {
58
58
  return true;
59
59
  }
60
60
 
61
- export function identifyOfficialOrigin({ targetRel, text, bytes = null, catalog }) {
62
- assertCatalogShape(catalog);
63
- const sourceText = String(text);
64
- const rawBytes = bytes == null ? Buffer.from(sourceText, "utf8") : Buffer.from(bytes);
65
- const rawSha256 = createHash("sha256").update(rawBytes).digest("hex");
66
- const normalizedSha256 = sha256(normalizeNewlines(sourceText));
67
- const canonicalSha256 = sha256(canonicalizeOfficialText(targetRel, sourceText));
68
- const rawExactVersions = [];
69
- const exactVersions = [];
70
- const canonicalVersions = [];
61
+ export function identifyOfficialOrigin({ targetRel, text, bytes = null, catalog }) {
62
+ assertCatalogShape(catalog);
63
+ const sourceText = String(text);
64
+ const rawBytes = bytes == null ? Buffer.from(sourceText, "utf8") : Buffer.from(bytes);
65
+ const rawSha256 = createHash("sha256").update(rawBytes).digest("hex");
66
+ const normalizedSha256 = sha256(normalizeNewlines(sourceText));
67
+ const canonicalSha256 = sha256(canonicalizeOfficialText(targetRel, sourceText));
68
+ const rawExactVersions = [];
69
+ const exactVersions = [];
70
+ const canonicalVersions = [];
71
71
 
72
72
  for (const [version, release] of Object.entries(catalog.releases)) {
73
73
  const entry = release.manifest[targetRel];
74
74
  if (!entry || entry.state !== "present") continue;
75
- if (entry.rawSha256 === rawSha256) rawExactVersions.push(version);
76
- if (entry.normalizedSha256 === normalizedSha256) exactVersions.push(version);
75
+ if (entry.rawSha256 === rawSha256) rawExactVersions.push(version);
76
+ if (entry.normalizedSha256 === normalizedSha256) exactVersions.push(version);
77
77
  else if (entry.canonicalSha256 === canonicalSha256) canonicalVersions.push(version);
78
78
  }
79
79
 
80
80
  return {
81
- targetRel,
82
- rawSha256,
83
- rawExact: rawExactVersions.length > 0,
84
- rawExactVersions,
85
- normalizedSha256,
81
+ targetRel,
82
+ rawSha256,
83
+ rawExact: rawExactVersions.length > 0,
84
+ rawExactVersions,
85
+ normalizedSha256,
86
86
  canonicalSha256,
87
87
  exact: exactVersions.length > 0,
88
88
  exactVersions,
@@ -90,7 +90,7 @@ export function identifyOfficialOrigin({ targetRel, text, bytes = null, catalog
90
90
  };
91
91
  }
92
92
 
93
- export function getOfficialBaseline({ version, targetRel, catalog, root = null }) {
93
+ export function getOfficialBaseline({ version, targetRel, catalog, root = null }) {
94
94
  assertCatalogShape(catalog);
95
95
  const release = catalog.releases[stripVersionPrefix(version)];
96
96
  if (!release) return null;
@@ -109,46 +109,46 @@ export function getOfficialBaseline({ version, targetRel, catalog, root = null }
109
109
  normalizedSha256: entry.normalizedSha256,
110
110
  canonicalSha256: entry.canonicalSha256
111
111
  };
112
- }
113
-
114
- // A managed segment is deliberately narrower than a whole-file catalog
115
- // identity. It exists only when the release is tied to an npm artifact and
116
- // its raw source plus transformed core bytes are recorded in this catalog.
117
- // Markers, filenames, headings, and language never grant this authority.
118
- export function getArtifactBoundManagedSegment({ version, targetRel, catalog }) {
119
- assertCatalogShape(catalog);
120
- const normalizedVersion = stripVersionPrefix(version);
121
- const release = catalog.releases[normalizedVersion];
122
- const segment = release?.managedSegments?.[targetRel];
123
- if (!segment) return null;
124
- const npm = release.source?.npm;
125
- if (!npm || typeof npm.spec !== "string" || !/^[a-f0-9]{40}$/.test(npm.shasum)
126
- || typeof npm.integrity !== "string" || !npm.integrity.startsWith("sha512-")) {
127
- throw new Error(`official origin catalog managed segment has no artifact identity: ${normalizedVersion} ${targetRel}`);
128
- }
129
- if (!segment || typeof segment !== "object" || Array.isArray(segment)
130
- || segment.sourceRel !== "runtime-core/AGENTS.core.md"
131
- || segment.transform?.kind !== "utf8-trim-wrapped-managed-core"
132
- || typeof segment.transform.beginMarker !== "string" || !segment.transform.beginMarker
133
- || typeof segment.transform.endMarker !== "string" || !segment.transform.endMarker
134
- || !validSegmentByteIdentity(segment.artifactSource)
135
- || !validSegmentByteIdentity(segment.transform.core)) {
136
- throw new Error(`official origin catalog managed segment is invalid: ${normalizedVersion} ${targetRel}`);
137
- }
138
- return Object.freeze({
139
- version: normalizedVersion,
140
- targetRel,
141
- sourceRel: segment.sourceRel,
142
- artifact: Object.freeze({ spec: npm.spec, shasum: npm.shasum, integrity: npm.integrity }),
143
- artifactSource: Object.freeze({ ...segment.artifactSource }),
144
- transform: Object.freeze({
145
- kind: segment.transform.kind,
146
- beginMarker: segment.transform.beginMarker,
147
- endMarker: segment.transform.endMarker,
148
- core: Object.freeze({ ...segment.transform.core })
149
- })
150
- });
151
- }
112
+ }
113
+
114
+ // A managed segment is deliberately narrower than a whole-file catalog
115
+ // identity. It exists only when the release is tied to an npm artifact and
116
+ // its raw source plus transformed core bytes are recorded in this catalog.
117
+ // Markers, filenames, headings, and language never grant this authority.
118
+ export function getArtifactBoundManagedSegment({ version, targetRel, catalog }) {
119
+ assertCatalogShape(catalog);
120
+ const normalizedVersion = stripVersionPrefix(version);
121
+ const release = catalog.releases[normalizedVersion];
122
+ const segment = release?.managedSegments?.[targetRel];
123
+ if (!segment) return null;
124
+ const npm = release.source?.npm;
125
+ if (!npm || typeof npm.spec !== "string" || !/^[a-f0-9]{40}$/.test(npm.shasum)
126
+ || typeof npm.integrity !== "string" || !npm.integrity.startsWith("sha512-")) {
127
+ throw new Error(`official origin catalog managed segment has no artifact identity: ${normalizedVersion} ${targetRel}`);
128
+ }
129
+ if (!segment || typeof segment !== "object" || Array.isArray(segment)
130
+ || segment.sourceRel !== "runtime-core/AGENTS.core.md"
131
+ || segment.transform?.kind !== "utf8-trim-wrapped-managed-core"
132
+ || typeof segment.transform.beginMarker !== "string" || !segment.transform.beginMarker
133
+ || typeof segment.transform.endMarker !== "string" || !segment.transform.endMarker
134
+ || !validSegmentByteIdentity(segment.artifactSource)
135
+ || !validSegmentByteIdentity(segment.transform.core)) {
136
+ throw new Error(`official origin catalog managed segment is invalid: ${normalizedVersion} ${targetRel}`);
137
+ }
138
+ return Object.freeze({
139
+ version: normalizedVersion,
140
+ targetRel,
141
+ sourceRel: segment.sourceRel,
142
+ artifact: Object.freeze({ spec: npm.spec, shasum: npm.shasum, integrity: npm.integrity }),
143
+ artifactSource: Object.freeze({ ...segment.artifactSource }),
144
+ transform: Object.freeze({
145
+ kind: segment.transform.kind,
146
+ beginMarker: segment.transform.beginMarker,
147
+ endMarker: segment.transform.endMarker,
148
+ core: Object.freeze({ ...segment.transform.core })
149
+ })
150
+ });
151
+ }
152
152
 
153
153
  export function normalizeNewlines(text) {
154
154
  return String(text).replace(/\r\n?/g, "\n");
@@ -228,15 +228,15 @@ function materializeHandoffOpeningRoot(text, root) {
228
228
  return `${before}${opening}${text.slice(fenceEnd)}`;
229
229
  }
230
230
 
231
- function stripVersionPrefix(version) {
232
- return String(version ?? "").replace(/^v/, "");
233
- }
234
-
235
- function validSegmentByteIdentity(value) {
236
- return Boolean(value && typeof value === "object" && !Array.isArray(value)
237
- && /^[a-f0-9]{64}$/.test(value.sha256)
238
- && Number.isInteger(value.bytes) && value.bytes >= 0);
239
- }
231
+ function stripVersionPrefix(version) {
232
+ return String(version ?? "").replace(/^v/, "");
233
+ }
234
+
235
+ function validSegmentByteIdentity(value) {
236
+ return Boolean(value && typeof value === "object" && !Array.isArray(value)
237
+ && /^[a-f0-9]{64}$/.test(value.sha256)
238
+ && Number.isInteger(value.bytes) && value.bytes >= 0);
239
+ }
240
240
 
241
241
  function assertCatalogShape(catalog) {
242
242
  if (!catalog || catalog.schemaVersion !== OFFICIAL_ORIGIN_CATALOG_SCHEMA) {