superbee 0.4.3-pre.21 → 0.4.3-pre.23

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.
@@ -924,25 +924,25 @@ var require_pairs = __commonJS({
924
924
  var _toString = Object.prototype.toString;
925
925
  function resolveYamlPairs(data) {
926
926
  if (data === null) return true;
927
- var index2, length, pair, keys, result, object = data;
927
+ var index2, length, pair, keys2, result, object = data;
928
928
  result = new Array(object.length);
929
929
  for (index2 = 0, length = object.length; index2 < length; index2 += 1) {
930
930
  pair = object[index2];
931
931
  if (_toString.call(pair) !== "[object Object]") return false;
932
- keys = Object.keys(pair);
933
- if (keys.length !== 1) return false;
934
- result[index2] = [keys[0], pair[keys[0]]];
932
+ keys2 = Object.keys(pair);
933
+ if (keys2.length !== 1) return false;
934
+ result[index2] = [keys2[0], pair[keys2[0]]];
935
935
  }
936
936
  return true;
937
937
  }
938
938
  function constructYamlPairs(data) {
939
939
  if (data === null) return [];
940
- var index2, length, pair, keys, result, object = data;
940
+ var index2, length, pair, keys2, result, object = data;
941
941
  result = new Array(object.length);
942
942
  for (index2 = 0, length = object.length; index2 < length; index2 += 1) {
943
943
  pair = object[index2];
944
- keys = Object.keys(pair);
945
- result[index2] = [keys[0], pair[keys[0]]];
944
+ keys2 = Object.keys(pair);
945
+ result[index2] = [keys2[0], pair[keys2[0]]];
946
946
  }
947
947
  return result;
948
948
  }
@@ -2349,12 +2349,12 @@ var require_dumper = __commonJS({
2349
2349
  "OFF"
2350
2350
  ];
2351
2351
  function compileStyleMap(schema, map) {
2352
- var result, keys, index2, length, tag, style, type;
2352
+ var result, keys2, index2, length, tag, style, type;
2353
2353
  if (map === null) return {};
2354
2354
  result = {};
2355
- keys = Object.keys(map);
2356
- for (index2 = 0, length = keys.length; index2 < length; index2 += 1) {
2357
- tag = keys[index2];
2355
+ keys2 = Object.keys(map);
2356
+ for (index2 = 0, length = keys2.length; index2 < length; index2 += 1) {
2357
+ tag = keys2[index2];
2358
2358
  style = String(map[tag]);
2359
2359
  if (tag.slice(0, 2) === "!!") {
2360
2360
  tag = "tag:yaml.org,2002:" + tag.slice(2);
@@ -30726,15 +30726,15 @@ var require_react_jsx_runtime_development = __commonJS({
30726
30726
  else validateChildKeys(children);
30727
30727
  if (hasOwnProperty2.call(config, "key")) {
30728
30728
  children = getComponentNameFromType(type);
30729
- var keys = Object.keys(config).filter(function(k) {
30729
+ var keys2 = Object.keys(config).filter(function(k) {
30730
30730
  return "key" !== k;
30731
30731
  });
30732
- isStaticChildren = 0 < keys.length ? "{key: someKey, " + keys.join(": ..., ") + ": ...}" : "{key: someKey}";
30733
- didWarnAboutKeySpread[children + isStaticChildren] || (keys = 0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}", console.error(
30732
+ isStaticChildren = 0 < keys2.length ? "{key: someKey, " + keys2.join(": ..., ") + ": ...}" : "{key: someKey}";
30733
+ didWarnAboutKeySpread[children + isStaticChildren] || (keys2 = 0 < keys2.length ? "{" + keys2.join(": ..., ") + ": ...}" : "{}", console.error(
30734
30734
  'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',
30735
30735
  isStaticChildren,
30736
30736
  children,
30737
- keys,
30737
+ keys2,
30738
30738
  children
30739
30739
  ), didWarnAboutKeySpread[children + isStaticChildren] = true);
30740
30740
  }
@@ -30828,7 +30828,38 @@ import path5 from "node:path";
30828
30828
  // ../core/src/backend.ts
30829
30829
  import path3 from "node:path";
30830
30830
 
30831
- // ../core/src/frontmatter.ts
30831
+ // ../core/src/errors.ts
30832
+ var InvalidInputError = class extends Error {
30833
+ constructor(message) {
30834
+ super(message);
30835
+ this.name = "InvalidInputError";
30836
+ }
30837
+ };
30838
+ var FilesystemIdentityAliasError = class extends InvalidInputError {
30839
+ rel;
30840
+ segment;
30841
+ constructor(rel, segment) {
30842
+ super(
30843
+ `Path '${rel}' does not match the exact spelling of an existing filesystem entry at segment '${segment}'; ids that differ only by case or Unicode normalization cannot share one file.`
30844
+ );
30845
+ this.name = "FilesystemIdentityAliasError";
30846
+ this.rel = rel;
30847
+ this.segment = segment;
30848
+ }
30849
+ };
30850
+ var ConcurrentReplacementError = class extends Error {
30851
+ rel;
30852
+ /** Optional bounded backoff hint for a transient host condition; ordinary observation races use zero. */
30853
+ retryAfterMs;
30854
+ constructor(rel, attempts, retryAfterMs = 0) {
30855
+ super(`Path '${rel}' could not be bound to one stable entry during ${attempts} filesystem attempt(s); retry.`);
30856
+ this.name = "ConcurrentReplacementError";
30857
+ this.rel = rel;
30858
+ this.retryAfterMs = retryAfterMs;
30859
+ }
30860
+ };
30861
+
30862
+ // ../core/src/portable-frontmatter.ts
30832
30863
  var import_js_yaml = __toESM(require_js_yaml2(), 1);
30833
30864
 
30834
30865
  // ../core/src/frontmatter-contract.ts
@@ -30876,112 +30907,23 @@ function splitLeadingFrontmatter(raw, context) {
30876
30907
  throw new MalformedDocumentError(context, new Error("unterminated YAML frontmatter delimiter"));
30877
30908
  }
30878
30909
 
30879
- // ../core/src/frontmatter.ts
30880
- var YAML_TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp";
30881
- function requireYamlTimestampType() {
30882
- const type = import_js_yaml.default.DEFAULT_SAFE_SCHEMA.implicit.find(
30883
- (candidate) => candidate.tag === YAML_TIMESTAMP_TAG
30884
- );
30885
- if (!type) throw new Error("js-yaml safe schema is missing its timestamp type");
30886
- return type;
30887
- }
30888
- var yamlTimestampType = requireYamlTimestampType();
30889
- var stringTimestampType = new import_js_yaml.default.Type(YAML_TIMESTAMP_TAG, {
30890
- kind: "scalar",
30891
- resolve: (value) => yamlTimestampType.resolve(value),
30892
- construct: (value) => value
30893
- });
30894
- var losslessDateSchema = new import_js_yaml.default.Schema({
30895
- include: [import_js_yaml.default.DEFAULT_SAFE_SCHEMA],
30896
- implicit: [stringTimestampType]
30897
- });
30898
- var yamlEngine = {
30899
- parse(input) {
30900
- return import_js_yaml.default.safeLoad(input, { schema: losslessDateSchema }) ?? {};
30901
- }
30902
- };
30903
- function normalizeFrontmatter(data, okfVersion) {
30904
- const out = { ...data };
30905
- if (okfVersion === "0.2") return out;
30906
- const value = out.timestamp;
30907
- if (value instanceof Date) {
30908
- out.timestamp = value.toISOString();
30909
- } else if (typeof value === "number" && Number.isFinite(value)) {
30910
- out.timestamp = new Date(value).toISOString();
30911
- } else if (typeof value === "string" && yamlTimestampType.resolve(value)) {
30912
- const parsed = yamlTimestampType.construct(value);
30913
- if (parsed instanceof Date) out.timestamp = parsed.toISOString();
30914
- }
30915
- return out;
30916
- }
30917
- function parseMarkdown(raw, context, options = {}) {
30910
+ // ../core/src/portable-frontmatter.ts
30911
+ function parseLeadingFrontmatter(raw, context) {
30918
30912
  const split = splitLeadingFrontmatter(raw, context);
30919
- if (!("yamlSource" in split)) return { frontmatter: {}, body: split.body };
30920
- return { frontmatter: parseFrontmatter(split.yamlSource, context, options), body: split.body };
30921
- }
30922
- function parseFrontmatter(source, context, options = {}) {
30923
- let parsed;
30913
+ if (!("yamlSource" in split)) return {};
30924
30914
  try {
30925
- parsed = yamlEngine.parse(source);
30926
- } catch (err) {
30927
- throw new MalformedDocumentError(context, err);
30915
+ const parsed = import_js_yaml.default.safeLoad(split.yamlSource);
30916
+ if (parsed === void 0 || parsed === null) return {};
30917
+ if (typeof parsed !== "object" || Array.isArray(parsed)) {
30918
+ throw new TypeError("YAML frontmatter must be a mapping");
30919
+ }
30920
+ return parsed;
30921
+ } catch (error) {
30922
+ if (error instanceof MalformedDocumentError) throw error;
30923
+ throw new MalformedDocumentError(context, error);
30928
30924
  }
30929
- return normalizeFrontmatter(parsed, options.okfVersion);
30930
- }
30931
- function stringifyFrontmatter(data) {
30932
- return import_js_yaml.default.safeDump(data).trim();
30933
- }
30934
- function normalizeDocumentBodyForStorage(body) {
30935
- return body.endsWith("\n") ? body : `${body}
30936
- `;
30937
- }
30938
- function stringifyWithData(data, body) {
30939
- return stringifyWithSerializedFrontmatter(stringifyFrontmatter(data), body);
30940
- }
30941
- function stringifyWithSerializedFrontmatter(dumped, body) {
30942
- const content3 = body ?? "";
30943
- const newline = (value) => value.endsWith("\n") ? value : `${value}
30944
- `;
30945
- if (dumped === "{}") return normalizeDocumentBodyForStorage(content3);
30946
- return `---
30947
- ${newline(dumped)}---
30948
- ${normalizeDocumentBodyForStorage(content3)}`;
30949
- }
30950
- function stringifyDoc(frontmatter2, body) {
30951
- return stringifyWithData(frontmatter2, body);
30952
30925
  }
30953
30926
 
30954
- // ../core/src/errors.ts
30955
- var InvalidInputError = class extends Error {
30956
- constructor(message) {
30957
- super(message);
30958
- this.name = "InvalidInputError";
30959
- }
30960
- };
30961
- var FilesystemIdentityAliasError = class extends InvalidInputError {
30962
- rel;
30963
- segment;
30964
- constructor(rel, segment) {
30965
- super(
30966
- `Path '${rel}' does not match the exact spelling of an existing filesystem entry at segment '${segment}'; ids that differ only by case or Unicode normalization cannot share one file.`
30967
- );
30968
- this.name = "FilesystemIdentityAliasError";
30969
- this.rel = rel;
30970
- this.segment = segment;
30971
- }
30972
- };
30973
- var ConcurrentReplacementError = class extends Error {
30974
- rel;
30975
- /** Optional bounded backoff hint for a transient host condition; ordinary observation races use zero. */
30976
- retryAfterMs;
30977
- constructor(rel, attempts, retryAfterMs = 0) {
30978
- super(`Path '${rel}' could not be bound to one stable entry during ${attempts} filesystem attempt(s); retry.`);
30979
- this.name = "ConcurrentReplacementError";
30980
- this.rel = rel;
30981
- this.retryAfterMs = retryAfterMs;
30982
- }
30983
- };
30984
-
30985
30927
  // ../core/src/paths.ts
30986
30928
  var RESERVED_FILENAMES = ["index.md", "log.md"];
30987
30929
  function compareStorageKeys(a, b) {
@@ -31058,6 +31000,357 @@ function assertSafeReservedDir(dir) {
31058
31000
  if (dir !== "") assertPortablePath(dir, "Reserved-file directory");
31059
31001
  }
31060
31002
 
31003
+ // ../core/src/sha256.ts
31004
+ var K = new Uint32Array([
31005
+ 1116352408,
31006
+ 1899447441,
31007
+ 3049323471,
31008
+ 3921009573,
31009
+ 961987163,
31010
+ 1508970993,
31011
+ 2453635748,
31012
+ 2870763221,
31013
+ 3624381080,
31014
+ 310598401,
31015
+ 607225278,
31016
+ 1426881987,
31017
+ 1925078388,
31018
+ 2162078206,
31019
+ 2614888103,
31020
+ 3248222580,
31021
+ 3835390401,
31022
+ 4022224774,
31023
+ 264347078,
31024
+ 604807628,
31025
+ 770255983,
31026
+ 1249150122,
31027
+ 1555081692,
31028
+ 1996064986,
31029
+ 2554220882,
31030
+ 2821834349,
31031
+ 2952996808,
31032
+ 3210313671,
31033
+ 3336571891,
31034
+ 3584528711,
31035
+ 113926993,
31036
+ 338241895,
31037
+ 666307205,
31038
+ 773529912,
31039
+ 1294757372,
31040
+ 1396182291,
31041
+ 1695183700,
31042
+ 1986661051,
31043
+ 2177026350,
31044
+ 2456956037,
31045
+ 2730485921,
31046
+ 2820302411,
31047
+ 3259730800,
31048
+ 3345764771,
31049
+ 3516065817,
31050
+ 3600352804,
31051
+ 4094571909,
31052
+ 275423344,
31053
+ 430227734,
31054
+ 506948616,
31055
+ 659060556,
31056
+ 883997877,
31057
+ 958139571,
31058
+ 1322822218,
31059
+ 1537002063,
31060
+ 1747873779,
31061
+ 1955562222,
31062
+ 2024104815,
31063
+ 2227730452,
31064
+ 2361852424,
31065
+ 2428436474,
31066
+ 2756734187,
31067
+ 3204031479,
31068
+ 3329325298
31069
+ ]);
31070
+ var INITIAL_STATE = new Uint32Array([
31071
+ 1779033703,
31072
+ 3144134277,
31073
+ 1013904242,
31074
+ 2773480762,
31075
+ 1359893119,
31076
+ 2600822924,
31077
+ 528734635,
31078
+ 1541459225
31079
+ ]);
31080
+ var encoder = new TextEncoder();
31081
+ function rotr(value, bits) {
31082
+ return value >>> bits | value << 32 - bits;
31083
+ }
31084
+ function compress(h, w, view, offset) {
31085
+ for (let i = 0; i < 16; i++) {
31086
+ w[i] = view.getUint32(offset + i * 4);
31087
+ }
31088
+ for (let i = 16; i < 64; i++) {
31089
+ const w15 = w[i - 15];
31090
+ const w2 = w[i - 2];
31091
+ const s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ w15 >>> 3;
31092
+ const s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ w2 >>> 10;
31093
+ w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
31094
+ }
31095
+ let a = h[0];
31096
+ let b = h[1];
31097
+ let c = h[2];
31098
+ let d = h[3];
31099
+ let e = h[4];
31100
+ let f = h[5];
31101
+ let g = h[6];
31102
+ let hh = h[7];
31103
+ for (let i = 0; i < 64; i++) {
31104
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
31105
+ const ch = e & f ^ ~e & g;
31106
+ const t1 = hh + S1 + ch + K[i] + w[i] >>> 0;
31107
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
31108
+ const maj = a & b ^ a & c ^ b & c;
31109
+ const t2 = S0 + maj >>> 0;
31110
+ hh = g;
31111
+ g = f;
31112
+ f = e;
31113
+ e = d + t1 >>> 0;
31114
+ d = c;
31115
+ c = b;
31116
+ b = a;
31117
+ a = t1 + t2 >>> 0;
31118
+ }
31119
+ h[0] = h[0] + a >>> 0;
31120
+ h[1] = h[1] + b >>> 0;
31121
+ h[2] = h[2] + c >>> 0;
31122
+ h[3] = h[3] + d >>> 0;
31123
+ h[4] = h[4] + e >>> 0;
31124
+ h[5] = h[5] + f >>> 0;
31125
+ h[6] = h[6] + g >>> 0;
31126
+ h[7] = h[7] + hh >>> 0;
31127
+ }
31128
+ function sha256HexOfBytes(bytes) {
31129
+ const h = new Uint32Array(INITIAL_STATE);
31130
+ const w = new Uint32Array(64);
31131
+ const length = bytes.byteLength;
31132
+ const view = new DataView(bytes.buffer, bytes.byteOffset, length);
31133
+ const fullBlocks = length >>> 6;
31134
+ for (let block = 0; block < fullBlocks; block++) {
31135
+ compress(h, w, view, block * 64);
31136
+ }
31137
+ const remaining = length - fullBlocks * 64;
31138
+ const tail = new Uint8Array(remaining + 1 + 8 > 64 ? 128 : 64);
31139
+ tail.set(bytes.subarray(fullBlocks * 64));
31140
+ tail[remaining] = 128;
31141
+ const tailView = new DataView(tail.buffer);
31142
+ const bitLengthHigh = Math.floor(length / 536870912);
31143
+ const bitLengthLow = length << 3 >>> 0;
31144
+ tailView.setUint32(tail.length - 8, bitLengthHigh);
31145
+ tailView.setUint32(tail.length - 4, bitLengthLow);
31146
+ for (let offset = 0; offset < tail.length; offset += 64) {
31147
+ compress(h, w, tailView, offset);
31148
+ }
31149
+ let hex = "";
31150
+ for (let i = 0; i < 8; i++) {
31151
+ hex += h[i].toString(16).padStart(8, "0");
31152
+ }
31153
+ return hex;
31154
+ }
31155
+ function sha256HexOfUtf8(input) {
31156
+ return sha256HexOfBytes(encoder.encode(input));
31157
+ }
31158
+
31159
+ // ../core/src/inventory-guard.ts
31160
+ var INVENTORY_GUARD_DOMAIN = "cooperating-local-writers-v1";
31161
+ var InventoryGuardUnsupported = class extends Error {
31162
+ written = false;
31163
+ reason;
31164
+ constructor(reason) {
31165
+ super(`Inventory guard unsupported: ${reason}`);
31166
+ this.name = "InventoryGuardUnsupported";
31167
+ this.reason = reason;
31168
+ }
31169
+ };
31170
+ var InventoryGuardConflict = class extends Error {
31171
+ written = false;
31172
+ reason;
31173
+ constructor(reason) {
31174
+ super(`Inventory guard premise changed: ${reason}`);
31175
+ this.name = "InventoryGuardConflict";
31176
+ this.reason = reason;
31177
+ }
31178
+ };
31179
+ var capabilityOwners = /* @__PURE__ */ new WeakMap();
31180
+ function bindInventoryGuard(owner, guard) {
31181
+ capabilityOwners.set(guard, owner);
31182
+ return guard;
31183
+ }
31184
+ function assertInventoryGuardBound(count) {
31185
+ if (count > 1e4) throw new InventoryGuardUnsupported("inventory_document_bound");
31186
+ }
31187
+ function copyData(value, active = /* @__PURE__ */ new Set(), budget = { nodes: 1e5 }) {
31188
+ if (--budget.nodes < 0) throw new InvalidInputError("Inventory guard input exceeds its data bound.");
31189
+ if (value === null || typeof value === "string" || typeof value === "boolean") return value;
31190
+ if (typeof value === "number" && Number.isFinite(value)) return value;
31191
+ if (typeof value !== "object") throw new InvalidInputError("Inventory guard accepts finite plain data only.");
31192
+ if (active.has(value)) throw new InvalidInputError("Inventory guard input is cyclic.");
31193
+ const array = Array.isArray(value);
31194
+ if (Object.getPrototypeOf(value) !== (array ? Array.prototype : Object.prototype) && Object.getPrototypeOf(value) !== null) {
31195
+ throw new InvalidInputError("Inventory guard accepts plain objects and arrays only.");
31196
+ }
31197
+ active.add(value);
31198
+ const result = array ? [] : /* @__PURE__ */ Object.create(null);
31199
+ if (array && Object.keys(value).length !== value.length) throw new InvalidInputError("Inventory guard input cannot carry sparse arrays or extra keys.");
31200
+ for (const key of Reflect.ownKeys(value)) {
31201
+ if (array && key === "length") continue;
31202
+ if (array && (typeof key !== "string" || !/^(0|[1-9][0-9]*)$/.test(key))) throw new InvalidInputError("Inventory guard arrays require indexed data only.");
31203
+ if (typeof key !== "string") throw new InvalidInputError("Inventory guard input cannot carry symbol keys.");
31204
+ const property = Object.getOwnPropertyDescriptor(value, key);
31205
+ if (!property.enumerable || !("value" in property)) throw new InvalidInputError("Inventory guard input cannot carry accessors or hidden data.");
31206
+ Object.defineProperty(result, key, { value: copyData(property.value, active, budget), enumerable: true, configurable: true, writable: true });
31207
+ }
31208
+ if (array && result.length !== value.length) throw new InvalidInputError("Inventory guard input cannot carry sparse arrays.");
31209
+ active.delete(value);
31210
+ return result;
31211
+ }
31212
+ function record(value) {
31213
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new InvalidInputError("Inventory guard expected an object.");
31214
+ return value;
31215
+ }
31216
+ function keys(value, allowed) {
31217
+ if (Object.keys(value).some((key) => !allowed.includes(key))) throw new InvalidInputError("Inventory guard input has unsupported fields.");
31218
+ }
31219
+ function version(value) {
31220
+ if (typeof value !== "string" || !/^sha256:[0-9a-f]{64}$/.test(value)) throw new InvalidInputError("Inventory guard requires exact content versions.");
31221
+ }
31222
+ function captureInventoryGuardRequest(input) {
31223
+ const data = record(copyData(input));
31224
+ keys(data, ["target", "domain", "inventory", "id", "expectedVersion", "doc", "options"]);
31225
+ const target = record(data.target);
31226
+ keys(target, ["contract", "domain", "adapter", "store", "root_version", "edition"]);
31227
+ if (target.contract !== "inventory-guard/v1" || target.domain !== INVENTORY_GUARD_DOMAIN || data.domain !== INVENTORY_GUARD_DOMAIN) {
31228
+ throw new InventoryGuardUnsupported("domain_or_contract");
31229
+ }
31230
+ if (!["memory", "filesystem"].includes(String(target.adapter)) || typeof target.store !== "string" || target.store.length === 0 || !["0.1", "0.2"].includes(String(target.edition))) throw new InvalidInputError("Invalid inventory guard target.");
31231
+ version(target.root_version);
31232
+ if (typeof data.id !== "string") throw new InvalidInputError("Inventory guard requires a target id.");
31233
+ assertSafeConceptId(data.id);
31234
+ if (isReservedFile(pathFromConceptId(data.id))) throw new InvalidInputError("Inventory guard target must be a concept.");
31235
+ version(data.expectedVersion);
31236
+ if (!Array.isArray(data.inventory)) throw new InvalidInputError("Inventory guard requires a complete inventory.");
31237
+ assertInventoryGuardBound(data.inventory.length);
31238
+ let previous3;
31239
+ for (const raw of data.inventory) {
31240
+ const row = record(raw);
31241
+ keys(row, ["id", "version"]);
31242
+ if (typeof row.id !== "string") throw new InvalidInputError("Inventory guard inventory id is invalid.");
31243
+ assertSafeConceptId(row.id);
31244
+ if (isReservedFile(pathFromConceptId(row.id)) || previous3 !== void 0 && compareStorageKeys(previous3, row.id) >= 0) throw new InvalidInputError("Inventory guard inventory must be sorted, unique concepts.");
31245
+ version(row.version);
31246
+ previous3 = row.id;
31247
+ }
31248
+ if (!data.inventory.some((row) => row.id === data.id && row.version === data.expectedVersion)) throw new InvalidInputError("Inventory guard target/version is missing from inventory.");
31249
+ const doc = record(data.doc);
31250
+ keys(doc, ["id", "frontmatter", "body"]);
31251
+ if (doc.id !== data.id || typeof doc.body !== "string") throw new InvalidInputError("Inventory guard candidate identity/body is invalid.");
31252
+ record(doc.frontmatter);
31253
+ if (data.options !== void 0) {
31254
+ const options = record(data.options);
31255
+ keys(options, ["actor", "agent"]);
31256
+ if (Object.values(options).some((value) => typeof value !== "string")) throw new InvalidInputError("Inventory guard attribution must be strings.");
31257
+ }
31258
+ return data;
31259
+ }
31260
+ function guardEdition(content3) {
31261
+ if (content3 === null) throw new InventoryGuardUnsupported("root_metadata_absent");
31262
+ const edition = parseLeadingFrontmatter(content3, "index.md").okf_version;
31263
+ if (edition !== "0.1" && edition !== "0.2") throw new InventoryGuardUnsupported("root_edition_unestablished");
31264
+ return edition;
31265
+ }
31266
+ function compareInventoryPremises(expected, current, inventory) {
31267
+ if (expected.target.adapter !== current.adapter || expected.target.store !== current.store) throw new InventoryGuardConflict("identity");
31268
+ if (expected.target.edition !== current.edition) throw new InventoryGuardConflict("edition");
31269
+ if (expected.target.root_version !== current.root_version) throw new InventoryGuardConflict("root_metadata");
31270
+ if (expected.inventory.length !== inventory.length || expected.inventory.some((row, index2) => row.id !== inventory[index2]?.id)) throw new InventoryGuardConflict("membership");
31271
+ if (expected.inventory.some((row, index2) => row.version !== inventory[index2].version)) throw new InventoryGuardConflict("version");
31272
+ if (!inventory.some((row) => row.id === expected.id && row.version === expected.expectedVersion)) throw new InventoryGuardConflict("target_version");
31273
+ }
31274
+ function inventoryDigest(inventory) {
31275
+ return `sha256:${sha256HexOfUtf8(JSON.stringify(inventory.map((row) => [row.id, row.version])))}`;
31276
+ }
31277
+
31278
+ // ../core/src/frontmatter.ts
31279
+ var import_js_yaml2 = __toESM(require_js_yaml2(), 1);
31280
+ var YAML_TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp";
31281
+ function requireYamlTimestampType() {
31282
+ const type = import_js_yaml2.default.DEFAULT_SAFE_SCHEMA.implicit.find(
31283
+ (candidate) => candidate.tag === YAML_TIMESTAMP_TAG
31284
+ );
31285
+ if (!type) throw new Error("js-yaml safe schema is missing its timestamp type");
31286
+ return type;
31287
+ }
31288
+ var yamlTimestampType = requireYamlTimestampType();
31289
+ var stringTimestampType = new import_js_yaml2.default.Type(YAML_TIMESTAMP_TAG, {
31290
+ kind: "scalar",
31291
+ resolve: (value) => yamlTimestampType.resolve(value),
31292
+ construct: (value) => value
31293
+ });
31294
+ var losslessDateSchema = new import_js_yaml2.default.Schema({
31295
+ include: [import_js_yaml2.default.DEFAULT_SAFE_SCHEMA],
31296
+ implicit: [stringTimestampType]
31297
+ });
31298
+ var yamlEngine = {
31299
+ parse(input) {
31300
+ return import_js_yaml2.default.safeLoad(input, { schema: losslessDateSchema }) ?? {};
31301
+ }
31302
+ };
31303
+ function normalizeFrontmatter(data, okfVersion) {
31304
+ const out = { ...data };
31305
+ if (okfVersion === "0.2") return out;
31306
+ const value = out.timestamp;
31307
+ if (value instanceof Date) {
31308
+ out.timestamp = value.toISOString();
31309
+ } else if (typeof value === "number" && Number.isFinite(value)) {
31310
+ out.timestamp = new Date(value).toISOString();
31311
+ } else if (typeof value === "string" && yamlTimestampType.resolve(value)) {
31312
+ const parsed = yamlTimestampType.construct(value);
31313
+ if (parsed instanceof Date) out.timestamp = parsed.toISOString();
31314
+ }
31315
+ return out;
31316
+ }
31317
+ function parseMarkdown(raw, context, options = {}) {
31318
+ const split = splitLeadingFrontmatter(raw, context);
31319
+ if (!("yamlSource" in split)) return { frontmatter: {}, body: split.body };
31320
+ return { frontmatter: parseFrontmatter(split.yamlSource, context, options), body: split.body };
31321
+ }
31322
+ function parseFrontmatter(source, context, options = {}) {
31323
+ let parsed;
31324
+ try {
31325
+ parsed = yamlEngine.parse(source);
31326
+ } catch (err) {
31327
+ throw new MalformedDocumentError(context, err);
31328
+ }
31329
+ return normalizeFrontmatter(parsed, options.okfVersion);
31330
+ }
31331
+ function stringifyFrontmatter(data) {
31332
+ return import_js_yaml2.default.safeDump(data).trim();
31333
+ }
31334
+ function normalizeDocumentBodyForStorage(body) {
31335
+ return body.endsWith("\n") ? body : `${body}
31336
+ `;
31337
+ }
31338
+ function stringifyWithData(data, body) {
31339
+ return stringifyWithSerializedFrontmatter(stringifyFrontmatter(data), body);
31340
+ }
31341
+ function stringifyWithSerializedFrontmatter(dumped, body) {
31342
+ const content3 = body ?? "";
31343
+ const newline = (value) => value.endsWith("\n") ? value : `${value}
31344
+ `;
31345
+ if (dumped === "{}") return normalizeDocumentBodyForStorage(content3);
31346
+ return `---
31347
+ ${newline(dumped)}---
31348
+ ${normalizeDocumentBodyForStorage(content3)}`;
31349
+ }
31350
+ function stringifyDoc(frontmatter2, body) {
31351
+ return stringifyWithData(frontmatter2, body);
31352
+ }
31353
+
31061
31354
  // ../core/src/links.ts
31062
31355
  function normalizeSegments(segments) {
31063
31356
  const out = [];
@@ -31381,12 +31674,25 @@ function parseTimestamp(ts, okfVersion) {
31381
31674
  return Number.isNaN(ms) ? null : ms;
31382
31675
  }
31383
31676
 
31677
+ // ../core/src/okf-authored-values.ts
31678
+ function isOkfRecord(value) {
31679
+ if (value === null || typeof value !== "object") return false;
31680
+ const prototype = Object.getPrototypeOf(value);
31681
+ return prototype === Object.prototype || prototype === null;
31682
+ }
31683
+
31384
31684
  // ../core/src/okf-lifecycle.ts
31385
31685
  var OKF_LIFECYCLE_STATUSES = Object.freeze(["draft", "stable", "deprecated"]);
31386
31686
  function isOkfLifecycleStatus(value) {
31387
31687
  return typeof value === "string" && OKF_LIFECYCLE_STATUSES.includes(value);
31388
31688
  }
31389
31689
 
31690
+ // ../core/src/okf-standard-fields.ts
31691
+ var OKF_STANDARD_FIELD_NAMES = ["type", "title", "description", "resource", "tags", "status", "sources", "generated", "verified", "stale_after", "usage_window", "runtime", "computation", "parameters", "executor", "attester", "okf_version"];
31692
+ function isOkfStandardField(field) {
31693
+ return OKF_STANDARD_FIELD_NAMES.includes(field);
31694
+ }
31695
+
31390
31696
  // ../core/src/mutation-attribution.ts
31391
31697
  var SUPERBEE_UPDATED_BY_FIELD = "superbee_updated_by";
31392
31698
  function nonEmptyString(value) {
@@ -31396,24 +31702,6 @@ function mutationActorFromFrontmatter(frontmatter2) {
31396
31702
  return nonEmptyString(frontmatter2[SUPERBEE_UPDATED_BY_FIELD]) ?? nonEmptyString(frontmatter2.updated_by) ?? nonEmptyString(frontmatter2.actor);
31397
31703
  }
31398
31704
 
31399
- // ../core/src/portable-frontmatter.ts
31400
- var import_js_yaml2 = __toESM(require_js_yaml2(), 1);
31401
- function parseLeadingFrontmatter(raw, context) {
31402
- const split = splitLeadingFrontmatter(raw, context);
31403
- if (!("yamlSource" in split)) return {};
31404
- try {
31405
- const parsed = import_js_yaml2.default.safeLoad(split.yamlSource);
31406
- if (parsed === void 0 || parsed === null) return {};
31407
- if (typeof parsed !== "object" || Array.isArray(parsed)) {
31408
- throw new TypeError("YAML frontmatter must be a mapping");
31409
- }
31410
- return parsed;
31411
- } catch (error) {
31412
- if (error instanceof MalformedDocumentError) throw error;
31413
- throw new MalformedDocumentError(context, error);
31414
- }
31415
- }
31416
-
31417
31705
  // ../core/src/query-filter.ts
31418
31706
  function matchesFilter(doc, filter) {
31419
31707
  if (filter.prefix && !doc.id.startsWith(filter.prefix)) return false;
@@ -31519,10 +31807,10 @@ async function queryHeads(backend, filter = {}, options = {}) {
31519
31807
  rows.sort((a, b) => a.id.localeCompare(b.id));
31520
31808
  return rows;
31521
31809
  }
31522
- return (await scanMatching(backend, filter, options.onSkip)).map(({ doc, version }) => ({
31810
+ return (await scanMatching(backend, filter, options.onSkip)).map(({ doc, version: version2 }) => ({
31523
31811
  id: doc.id,
31524
31812
  frontmatter: doc.frontmatter,
31525
- version
31813
+ version: version2
31526
31814
  }));
31527
31815
  }
31528
31816
  function normalizeEdgeSelector(raw) {
@@ -31634,13 +31922,13 @@ function snapshotHostPolicy(input, seen = /* @__PURE__ */ new WeakMap()) {
31634
31922
  if (existing) return existing;
31635
31923
  const result = Array.isArray(input) ? [] : {};
31636
31924
  seen.set(input, result);
31637
- const keys = /* @__PURE__ */ new Set();
31925
+ const keys2 = /* @__PURE__ */ new Set();
31638
31926
  for (let owner = input; owner && owner !== Object.prototype && owner !== Array.prototype; owner = Object.getPrototypeOf(owner)) {
31639
31927
  for (const key of Reflect.ownKeys(owner)) {
31640
- if (key !== "constructor" && !(Array.isArray(input) && key === "length")) keys.add(key);
31928
+ if (key !== "constructor" && !(Array.isArray(input) && key === "length")) keys2.add(key);
31641
31929
  }
31642
31930
  }
31643
- for (const key of keys) {
31931
+ for (const key of keys2) {
31644
31932
  const value = input[key];
31645
31933
  Object.defineProperty(result, key, {
31646
31934
  value: typeof value === "function" ? value.bind(result) : value && typeof value === "object" ? snapshotHostPolicy(value, seen) : value,
@@ -31765,14 +32053,14 @@ async function readOwnerRecord(lockPath) {
31765
32053
  }
31766
32054
  async function resolveOwnerRecord(lockPath, started, waitMs, pollMs) {
31767
32055
  while (true) {
31768
- const record = await readOwnerRecord(lockPath);
31769
- if (record.state !== "unreadable" || Date.now() - started >= waitMs) return record;
32056
+ const record2 = await readOwnerRecord(lockPath);
32057
+ if (record2.state !== "unreadable" || Date.now() - started >= waitMs) return record2;
31770
32058
  await delay(pollMs);
31771
32059
  }
31772
32060
  }
31773
32061
  async function readOwner(lockPath) {
31774
- const record = await readOwnerRecord(lockPath);
31775
- return record.state === "record" ? record.owner : null;
32062
+ const record2 = await readOwnerRecord(lockPath);
32063
+ return record2.state === "record" ? record2.owner : null;
31776
32064
  }
31777
32065
  function processExists(pid) {
31778
32066
  try {
@@ -31967,12 +32255,12 @@ async function claimLockPath(lockPath, owner, waitMs, pollMs, policy) {
31967
32255
  }
31968
32256
  async function rollBackOwnClaim(lockPath, owner, claimed, waitMs, pollMs, policy) {
31969
32257
  const started = Date.now();
31970
- const record = await resolveOwnerRecord(lockPath, started, waitMs, pollMs);
31971
- if (record.state === "record") {
31972
- if (record.owner.token === owner.token) await removeReleasedLock(lockPath, owner, started, waitMs, pollMs, policy);
32258
+ const record2 = await resolveOwnerRecord(lockPath, started, waitMs, pollMs);
32259
+ if (record2.state === "record") {
32260
+ if (record2.owner.token === owner.token) await removeReleasedLock(lockPath, owner, started, waitMs, pollMs, policy);
31973
32261
  return;
31974
32262
  }
31975
- if (record.state === "unreadable" || !await isClaimedDirectory(lockPath, claimed)) return;
32263
+ if (record2.state === "unreadable" || !await isClaimedDirectory(lockPath, claimed)) return;
31976
32264
  const remnant = releasedLockRemnantPath(lockPath, owner);
31977
32265
  await fs.rename(lockPath, remnant);
31978
32266
  await fs.rm(remnant, { recursive: true, force: true });
@@ -32135,12 +32423,62 @@ async function existingAnchor(resolved) {
32135
32423
  candidate = parent;
32136
32424
  }
32137
32425
  }
32138
- async function identityKey(root, rel) {
32139
- const foldedRel = relSegments(rel).map(foldSegment).join("/");
32426
+ async function foldedPhysicalRoot(root) {
32140
32427
  const { anchor, tail } = await existingAnchor(path2.resolve(root));
32141
32428
  const anchorSegments = anchor.split(path2.sep).filter((segment, index2) => index2 === 0 || segment !== "");
32142
- const foldedRoot = [...anchorSegments, ...tail].map(foldSegment).join("/");
32143
- return createHash2("sha256").update(`superbee-identity/v1\0${foldedRoot}\0${foldedRel}`).digest("hex");
32429
+ return [...anchorSegments, ...tail].map(foldSegment).join("/");
32430
+ }
32431
+ async function identityKey(root, rel) {
32432
+ const foldedRel = relSegments(rel).map(foldSegment).join("/");
32433
+ return createHash2("sha256").update(`superbee-identity/v1\0${await foldedPhysicalRoot(root)}\0${foldedRel}`).digest("hex");
32434
+ }
32435
+ async function filesystemRootMutationKey(root) {
32436
+ return createHash2("sha256").update(`superbee-root-mutation/v1\0${await foldedPhysicalRoot(root)}`).digest("hex");
32437
+ }
32438
+ async function filesystemRootWitness(port, root) {
32439
+ const physical = await fs2.realpath(root);
32440
+ const witnesses = [];
32441
+ let current = physical;
32442
+ for (; ; ) {
32443
+ const witness = await port.probe(current);
32444
+ if (!witness || witness.kind !== "directory") throw new InvalidInputError("Inventory guard root identity is unavailable.");
32445
+ witnesses.push([current, witness.dev, witness.ino]);
32446
+ const parent = path2.dirname(current);
32447
+ if (parent === current) break;
32448
+ current = parent;
32449
+ }
32450
+ return createHash2("sha256").update(JSON.stringify(witnesses)).digest("hex");
32451
+ }
32452
+ var rootMutationQueues = /* @__PURE__ */ new Map();
32453
+ function createFilesystemMutationCoordinator(_port, root, hostPolicy) {
32454
+ const policy = captureFilesystemHostPolicy(hostPolicy);
32455
+ let lockRoot;
32456
+ const namespace = () => lockRoot ??= filesystemMutationLockRoot(root, policy);
32457
+ return Object.freeze({
32458
+ namespace,
32459
+ async run(body) {
32460
+ const key = await filesystemRootMutationKey(root);
32461
+ const lockRoot2 = namespace();
32462
+ const queueKey = `${lockRoot2}:${key}`;
32463
+ const previous3 = rootMutationQueues.get(queueKey) ?? Promise.resolve();
32464
+ const run = previous3.then(async () => {
32465
+ const release = await acquireFilesystemIdentityLock(key, root, { portableRoot: root, lockRoot: lockRoot2, hostPolicy: policy });
32466
+ try {
32467
+ return await body();
32468
+ } finally {
32469
+ await release();
32470
+ }
32471
+ });
32472
+ const settled = run.then(() => {
32473
+ }, () => {
32474
+ });
32475
+ rootMutationQueues.set(queueKey, settled);
32476
+ void settled.then(() => {
32477
+ if (rootMutationQueues.get(queueKey) === settled) rootMutationQueues.delete(queueKey);
32478
+ });
32479
+ return run;
32480
+ }
32481
+ });
32144
32482
  }
32145
32483
  function sameWitness(a, b) {
32146
32484
  return a.dev === b.dev && a.ino === b.ino;
@@ -32674,162 +33012,6 @@ function createNodeFilesystemIdentityPort(hostPolicy) {
32674
33012
  });
32675
33013
  }
32676
33014
 
32677
- // ../core/src/sha256.ts
32678
- var K = new Uint32Array([
32679
- 1116352408,
32680
- 1899447441,
32681
- 3049323471,
32682
- 3921009573,
32683
- 961987163,
32684
- 1508970993,
32685
- 2453635748,
32686
- 2870763221,
32687
- 3624381080,
32688
- 310598401,
32689
- 607225278,
32690
- 1426881987,
32691
- 1925078388,
32692
- 2162078206,
32693
- 2614888103,
32694
- 3248222580,
32695
- 3835390401,
32696
- 4022224774,
32697
- 264347078,
32698
- 604807628,
32699
- 770255983,
32700
- 1249150122,
32701
- 1555081692,
32702
- 1996064986,
32703
- 2554220882,
32704
- 2821834349,
32705
- 2952996808,
32706
- 3210313671,
32707
- 3336571891,
32708
- 3584528711,
32709
- 113926993,
32710
- 338241895,
32711
- 666307205,
32712
- 773529912,
32713
- 1294757372,
32714
- 1396182291,
32715
- 1695183700,
32716
- 1986661051,
32717
- 2177026350,
32718
- 2456956037,
32719
- 2730485921,
32720
- 2820302411,
32721
- 3259730800,
32722
- 3345764771,
32723
- 3516065817,
32724
- 3600352804,
32725
- 4094571909,
32726
- 275423344,
32727
- 430227734,
32728
- 506948616,
32729
- 659060556,
32730
- 883997877,
32731
- 958139571,
32732
- 1322822218,
32733
- 1537002063,
32734
- 1747873779,
32735
- 1955562222,
32736
- 2024104815,
32737
- 2227730452,
32738
- 2361852424,
32739
- 2428436474,
32740
- 2756734187,
32741
- 3204031479,
32742
- 3329325298
32743
- ]);
32744
- var INITIAL_STATE = new Uint32Array([
32745
- 1779033703,
32746
- 3144134277,
32747
- 1013904242,
32748
- 2773480762,
32749
- 1359893119,
32750
- 2600822924,
32751
- 528734635,
32752
- 1541459225
32753
- ]);
32754
- var encoder = new TextEncoder();
32755
- function rotr(value, bits) {
32756
- return value >>> bits | value << 32 - bits;
32757
- }
32758
- function compress(h, w, view, offset) {
32759
- for (let i = 0; i < 16; i++) {
32760
- w[i] = view.getUint32(offset + i * 4);
32761
- }
32762
- for (let i = 16; i < 64; i++) {
32763
- const w15 = w[i - 15];
32764
- const w2 = w[i - 2];
32765
- const s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ w15 >>> 3;
32766
- const s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ w2 >>> 10;
32767
- w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
32768
- }
32769
- let a = h[0];
32770
- let b = h[1];
32771
- let c = h[2];
32772
- let d = h[3];
32773
- let e = h[4];
32774
- let f = h[5];
32775
- let g = h[6];
32776
- let hh = h[7];
32777
- for (let i = 0; i < 64; i++) {
32778
- const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
32779
- const ch = e & f ^ ~e & g;
32780
- const t1 = hh + S1 + ch + K[i] + w[i] >>> 0;
32781
- const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
32782
- const maj = a & b ^ a & c ^ b & c;
32783
- const t2 = S0 + maj >>> 0;
32784
- hh = g;
32785
- g = f;
32786
- f = e;
32787
- e = d + t1 >>> 0;
32788
- d = c;
32789
- c = b;
32790
- b = a;
32791
- a = t1 + t2 >>> 0;
32792
- }
32793
- h[0] = h[0] + a >>> 0;
32794
- h[1] = h[1] + b >>> 0;
32795
- h[2] = h[2] + c >>> 0;
32796
- h[3] = h[3] + d >>> 0;
32797
- h[4] = h[4] + e >>> 0;
32798
- h[5] = h[5] + f >>> 0;
32799
- h[6] = h[6] + g >>> 0;
32800
- h[7] = h[7] + hh >>> 0;
32801
- }
32802
- function sha256HexOfBytes(bytes) {
32803
- const h = new Uint32Array(INITIAL_STATE);
32804
- const w = new Uint32Array(64);
32805
- const length = bytes.byteLength;
32806
- const view = new DataView(bytes.buffer, bytes.byteOffset, length);
32807
- const fullBlocks = length >>> 6;
32808
- for (let block = 0; block < fullBlocks; block++) {
32809
- compress(h, w, view, block * 64);
32810
- }
32811
- const remaining = length - fullBlocks * 64;
32812
- const tail = new Uint8Array(remaining + 1 + 8 > 64 ? 128 : 64);
32813
- tail.set(bytes.subarray(fullBlocks * 64));
32814
- tail[remaining] = 128;
32815
- const tailView = new DataView(tail.buffer);
32816
- const bitLengthHigh = Math.floor(length / 536870912);
32817
- const bitLengthLow = length << 3 >>> 0;
32818
- tailView.setUint32(tail.length - 8, bitLengthHigh);
32819
- tailView.setUint32(tail.length - 4, bitLengthLow);
32820
- for (let offset = 0; offset < tail.length; offset += 64) {
32821
- compress(h, w, tailView, offset);
32822
- }
32823
- let hex = "";
32824
- for (let i = 0; i < 8; i++) {
32825
- hex += h[i].toString(16).padStart(8, "0");
32826
- }
32827
- return hex;
32828
- }
32829
- function sha256HexOfUtf8(input) {
32830
- return sha256HexOfBytes(encoder.encode(input));
32831
- }
32832
-
32833
33015
  // ../core/src/versioning.ts
32834
33016
  function sha256Hex(input) {
32835
33017
  return sha256HexOfUtf8(input);
@@ -32889,6 +33071,66 @@ function reservedPath(dir, name) {
32889
33071
  var FilesystemBackend = class _FilesystemBackend {
32890
33072
  #root;
32891
33073
  #port;
33074
+ #coordinator;
33075
+ /** The coordinator is private: no transaction callback or held-root capability escapes. */
33076
+ #withRootMutation(body) {
33077
+ return this.#coordinator.run(body);
33078
+ }
33079
+ #mutateExact(rel, body) {
33080
+ return this.#withRootMutation(() => mutateExact(this.#port, this.#root, rel, body));
33081
+ }
33082
+ #assertInventoryGuard() {
33083
+ if (Object.getPrototypeOf(this) !== _FilesystemBackend.prototype || ["read", "readMany", "list", "write", "delete", "writeReserved", "writeBlob", "deleteBlob", "readReserved"].some((name) => this[name] !== _FilesystemBackend.prototype[name])) {
33084
+ throw new InventoryGuardUnsupported("unqualified_filesystem_override");
33085
+ }
33086
+ }
33087
+ get inventoryGuard() {
33088
+ this.#assertInventoryGuard();
33089
+ return bindInventoryGuard(this, {
33090
+ observeTarget: () => this.#withRootMutation(() => {
33091
+ this.#assertInventoryGuard();
33092
+ return this.#guardTarget();
33093
+ }),
33094
+ compareInventoryAndWrite: async (input) => {
33095
+ const request = captureInventoryGuardRequest(input);
33096
+ const raw = stringifyDoc(request.doc.frontmatter, request.doc.body);
33097
+ return this.#withRootMutation(async () => {
33098
+ this.#assertInventoryGuard();
33099
+ const target = await this.#guardTarget();
33100
+ const inventory = [];
33101
+ const ids = await this.list();
33102
+ assertInventoryGuardBound(ids.length);
33103
+ const deadline = performance.now() + 5e3;
33104
+ for (const id of ids) {
33105
+ if (performance.now() > deadline) throw new InventoryGuardUnsupported("inventory_scan_time_bound");
33106
+ const raw2 = await readRawFilesystemDocument(this, id);
33107
+ parseMarkdown(new TextDecoder("utf-8", { fatal: true }).decode(raw2.bytes), pathFromConceptId(id), { okfVersion: target.edition });
33108
+ inventory.push({ id, version: raw2.version });
33109
+ }
33110
+ if (performance.now() > deadline) throw new InventoryGuardUnsupported("inventory_scan_time_bound");
33111
+ compareInventoryPremises(request, target, inventory);
33112
+ const version2 = await mutateExact(this.#port, this.#root, pathFromConceptId(request.id), async (leaf) => {
33113
+ compareInventoryPremises(request, await this.#guardTarget(), inventory);
33114
+ const bytes = await leaf.current();
33115
+ if (bytes === null || versionOfBytes(bytes.toString("utf8")) !== request.expectedVersion) throw new InventoryGuardConflict("target_version");
33116
+ await leaf.replace(Buffer.from(raw, "utf8"));
33117
+ return versionOfBytes(raw);
33118
+ });
33119
+ return { version: version2, target, inventory_digest: inventoryDigest(inventory) };
33120
+ });
33121
+ }
33122
+ });
33123
+ }
33124
+ async #guardTarget() {
33125
+ const witness = await filesystemRootWitness(this.#port, this.#root);
33126
+ const metadata = await readRawFilesystemReserved(this, "", "index.md");
33127
+ const content3 = metadata === null ? null : new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(metadata.bytes);
33128
+ const edition = guardEdition(content3);
33129
+ const after = await filesystemRootWitness(this.#port, this.#root);
33130
+ if (witness !== after) throw new InventoryGuardConflict("identity");
33131
+ const store = versionOfBytes(`${await filesystemRootMutationKey(this.#root)}:${this.#coordinator.namespace()}:${witness}`);
33132
+ return { contract: "inventory-guard/v1", domain: INVENTORY_GUARD_DOMAIN, adapter: "filesystem", store, edition, root_version: blobVersion(metadata.bytes) };
33133
+ }
32892
33134
  /**
32893
33135
  * The root is resolved once here: a relative root would otherwise re-resolve against the
32894
33136
  * process's current directory on every operation, so a later `chdir` would silently move the
@@ -32897,6 +33139,7 @@ var FilesystemBackend = class _FilesystemBackend {
32897
33139
  constructor(root, options = {}) {
32898
33140
  this.#port = createNodeFilesystemIdentityPort(options.hostPolicy);
32899
33141
  this.#root = path3.resolve(root);
33142
+ this.#coordinator = createFilesystemMutationCoordinator(this.#port, this.#root, options.hostPolicy);
32900
33143
  publicationContexts.set(this, { root: this.#root, port: this.#port });
32901
33144
  }
32902
33145
  async read(id) {
@@ -32941,7 +33184,7 @@ var FilesystemBackend = class _FilesystemBackend {
32941
33184
  assertSafeConceptId(id);
32942
33185
  const raw = stringifyDoc(doc.frontmatter, doc.body ?? "");
32943
33186
  const rel = pathFromConceptId(id);
32944
- return mutateExact(this.#port, this.#root, rel, async (target) => {
33187
+ return this.#mutateExact(rel, async (target) => {
32945
33188
  if (options.expectedVersion !== void 0) {
32946
33189
  const bytes = await target.current();
32947
33190
  const current = bytes === null ? null : versionOfBytes(bytes.toString("utf8"));
@@ -32955,7 +33198,7 @@ var FilesystemBackend = class _FilesystemBackend {
32955
33198
  }
32956
33199
  async delete(id, options = {}) {
32957
33200
  assertSafeConceptId(id);
32958
- return mutateExact(this.#port, this.#root, pathFromConceptId(id), async (target) => {
33201
+ return this.#mutateExact(pathFromConceptId(id), async (target) => {
32959
33202
  const bytes = await target.current();
32960
33203
  if (bytes === null) return false;
32961
33204
  const current = versionOfBytes(bytes.toString("utf8"));
@@ -33019,7 +33262,7 @@ var FilesystemBackend = class _FilesystemBackend {
33019
33262
  assertSafeReservedDir(dir);
33020
33263
  assertSafeReservedFilename(name);
33021
33264
  const rel = reservedPath(dir, name);
33022
- return mutateExact(this.#port, this.#root, rel, async (target) => {
33265
+ return this.#mutateExact(rel, async (target) => {
33023
33266
  if (options.expectedVersion !== void 0) {
33024
33267
  const bytes = await target.current();
33025
33268
  const current = bytes === null ? null : versionOfBytes(bytes.toString("utf8"));
@@ -33041,7 +33284,7 @@ var FilesystemBackend = class _FilesystemBackend {
33041
33284
  }
33042
33285
  async writeBlob(key, bytes, _contentType, options = {}) {
33043
33286
  assertSafeBlobKey(key);
33044
- return mutateExact(this.#port, this.#root, key, async (target) => {
33287
+ return this.#mutateExact(key, async (target) => {
33045
33288
  if (options.expectedVersion !== void 0) {
33046
33289
  const existing = await target.current();
33047
33290
  const current = existing === null ? null : blobVersion(existing);
@@ -33055,7 +33298,7 @@ var FilesystemBackend = class _FilesystemBackend {
33055
33298
  }
33056
33299
  async deleteBlob(key, options = {}) {
33057
33300
  assertSafeBlobKey(key);
33058
- return mutateExact(this.#port, this.#root, key, async (target) => {
33301
+ return this.#mutateExact(key, async (target) => {
33059
33302
  const existing = await target.current();
33060
33303
  if (existing === null) return false;
33061
33304
  const current = blobVersion(existing);
@@ -33073,8 +33316,8 @@ var FilesystemBackend = class _FilesystemBackend {
33073
33316
  }
33074
33317
  async listBlobs(prefix) {
33075
33318
  const files = await walkFiles(this.#port, this.#root, (name) => !name.toLowerCase().endsWith(".md"));
33076
- const keys = files.map(toPosix);
33077
- const filtered = prefix ? keys.filter((k) => k.startsWith(prefix)) : keys;
33319
+ const keys2 = files.map(toPosix);
33320
+ const filtered = prefix ? keys2.filter((k) => k.startsWith(prefix)) : keys2;
33078
33321
  filtered.sort(compareStorageKeys);
33079
33322
  return filtered;
33080
33323
  }
@@ -33181,6 +33424,86 @@ async function queryEdges2(bundle, filter = {}, options = {}) {
33181
33424
  // ../core/src/bundle.ts
33182
33425
  setDefaultBackendFactory((root) => new FilesystemBackend(root));
33183
33426
 
33427
+ // ../core/src/managed-document-metadata.ts
33428
+ var MANAGED_DOCUMENT_METADATA_FIELDS = /* @__PURE__ */ new Set([
33429
+ "generated",
33430
+ "verified",
33431
+ "superbee_updated_by",
33432
+ "actor",
33433
+ "timestamp"
33434
+ ]);
33435
+ function isManagedDocumentMetadataField(field) {
33436
+ return MANAGED_DOCUMENT_METADATA_FIELDS.has(field);
33437
+ }
33438
+
33439
+ // ../core/src/kind-deprecation.ts
33440
+ var problem = (field, message) => ({
33441
+ code: "KIND_DEPRECATION_INVALID",
33442
+ field,
33443
+ message: `${field}: ${message}`,
33444
+ severity: "warning"
33445
+ });
33446
+ function parseKindDeprecation(raw, kind2, reserved, claimFields) {
33447
+ const result = { fields: [], values: {}, links: [] };
33448
+ const problems = [];
33449
+ const fail2 = (field, message) => {
33450
+ problems.push(problem(field, message));
33451
+ };
33452
+ const names = (value, path6) => {
33453
+ if (!Array.isArray(value) || value.some((v) => typeof v !== "string" || !v.trim() || v !== v.trim())) {
33454
+ fail2(path6, "expected a list of nonempty exact names");
33455
+ return [];
33456
+ }
33457
+ return [...new Set(value)];
33458
+ };
33459
+ const protectedField = (field) => reserved.includes(field) || isOkfStandardField(field) || isManagedDocumentMetadataField(field) || claimFields.includes(field);
33460
+ if (!isOkfRecord(raw)) fail2("deprecated", "expected a map of fields, values and links");
33461
+ else {
33462
+ for (const key of Object.keys(raw)) if (!["fields", "values", "links"].includes(key)) fail2(`deprecated.${key}`, "unknown policy coordinate");
33463
+ if (Object.hasOwn(raw, "fields")) result.fields = names(raw.fields, "deprecated.fields");
33464
+ for (const field of result.fields) {
33465
+ if (!kind2.fields.optional.includes(field) || kind2.fields.required.includes(field) || protectedField(field)) {
33466
+ fail2(`deprecated.fields.${field}`, "only an optional, nonstandard, nonreserved, nonclaim field can be deprecated");
33467
+ }
33468
+ }
33469
+ if (Object.hasOwn(raw, "values")) {
33470
+ if (!isOkfRecord(raw.values)) fail2("deprecated.values", "expected a field-to-values map");
33471
+ else for (const [field, value] of Object.entries(raw.values)) {
33472
+ const path6 = `deprecated.values.${field}`;
33473
+ const values = Array.isArray(value) && value.every((v) => ["string", "number", "boolean"].includes(typeof v)) ? [...new Set(value.map(String))] : void 0;
33474
+ if (!values || values.some((v) => !v.trim())) {
33475
+ fail2(path6, "expected a list of enum members");
33476
+ continue;
33477
+ }
33478
+ Object.defineProperty(result.values, field, { value: values, enumerable: true, writable: true, configurable: true });
33479
+ const allowed = Object.hasOwn(kind2.fields.values, field) ? kind2.fields.values[field] : void 0;
33480
+ if (protectedField(field) || ![...kind2.fields.required, ...kind2.fields.optional].includes(field) || !allowed || values.some((v) => !allowed.includes(v)) || kind2.fields.types?.[field] === "https-url-list") {
33481
+ fail2(path6, "expected members of a declared, nonstandard, nonclaim vocabulary");
33482
+ }
33483
+ const terminal = Object.hasOwn(kind2.fields.terminal, field) ? kind2.fields.terminal[field] : [];
33484
+ if (values.some((v) => terminal.includes(v))) fail2(path6, "terminal members require a separate migration");
33485
+ if (kind2.fields.required.includes(field) && allowed && !allowed.some((v) => !values.includes(v))) fail2(path6, "a required field must retain an active member");
33486
+ }
33487
+ }
33488
+ if (Object.hasOwn(raw, "links")) result.links = names(raw.links, "deprecated.links");
33489
+ for (const label of result.links) if (!kind2.links || !Object.hasOwn(kind2.links, label)) fail2(`deprecated.links.${label}`, "expected an existing outbound label");
33490
+ }
33491
+ if (problems.length) {
33492
+ result.problems = problems;
33493
+ result.raw = structuredClone(raw);
33494
+ }
33495
+ return result;
33496
+ }
33497
+ function kindDeprecationProblems(kind2, registry) {
33498
+ const problems = [...kind2.deprecated?.problems ?? []];
33499
+ for (const label of kind2.deprecated?.links ?? []) {
33500
+ if ([...registry?.kinds.values() ?? [kind2]].some((k) => k.expectsInbound && Object.hasOwn(k.expectsInbound, label))) {
33501
+ problems.push(problem(`deprecated.links.${label}`, "the admitted registry still declares an inbound expectation for this label"));
33502
+ }
33503
+ }
33504
+ return problems;
33505
+ }
33506
+
33184
33507
  // ../core/src/kinds.ts
33185
33508
  var CONVENTIONS_PREFIX = "conventions/";
33186
33509
  var CONVENTION_TYPE = "Convention";
@@ -33244,6 +33567,7 @@ function buildKindRegistry(docs, initialWarnings = [], options = {}) {
33244
33567
  }
33245
33568
  accepted.set(kind2.governs, kind2);
33246
33569
  }
33570
+ for (const kind2 of accepted.values()) warnings.push(...kindDeprecationProblems(kind2, { kinds: accepted, warnings: [] }).filter((w) => !warnings.includes(w)));
33247
33571
  const kinds = /* @__PURE__ */ new Map();
33248
33572
  for (const kind2 of [...accepted.values()].sort(compareReadingOrder)) kinds.set(kind2.governs, kind2);
33249
33573
  return { kinds, warnings };
@@ -33257,9 +33581,9 @@ function compareReadingOrder(a, b) {
33257
33581
  var PROGRESS_STATUS_FIELD = "progress_status";
33258
33582
  var SUPERBEE_PROGRESS_STATUS_FIELD = "superbee_progress_status";
33259
33583
  function progressStatusStorageField(okfVersion) {
33260
- const version = okfVersion?.trim() || "0.1";
33261
- if (version === "0.1") return "status";
33262
- if (version === "0.2") return SUPERBEE_PROGRESS_STATUS_FIELD;
33584
+ const version2 = okfVersion?.trim() || "0.1";
33585
+ if (version2 === "0.1") return "status";
33586
+ if (version2 === "0.2") return SUPERBEE_PROGRESS_STATUS_FIELD;
33263
33587
  return void 0;
33264
33588
  }
33265
33589
  function declaresField(kind2, field) {
@@ -33282,6 +33606,19 @@ function resolveKindFieldCoordinate(okfVersion, kind2, field) {
33282
33606
  if (field === PROGRESS_STATUS_FIELD && progress) return progress;
33283
33607
  return void 0;
33284
33608
  }
33609
+ function claimCoordinates(okfVersion, kind2) {
33610
+ if (!kind2.claim) return void 0;
33611
+ const resolve = (field) => field === void 0 ? void 0 : resolveKindFieldCoordinate(okfVersion, kind2, field)?.storageField;
33612
+ const ownerField = resolve(kind2.claim.ownerField);
33613
+ const stateField = resolve(kind2.claim.stateField);
33614
+ const fields = [...new Set([ownerField, stateField].filter((f) => f !== void 0))];
33615
+ if (fields.length === 0) return void 0;
33616
+ return {
33617
+ ...ownerField !== void 0 ? { ownerField } : {},
33618
+ ...stateField !== void 0 ? { stateField } : {},
33619
+ fields
33620
+ };
33621
+ }
33285
33622
  function readKindField(okfVersion, kind2, frontmatter2, field) {
33286
33623
  const coordinate = resolveKindFieldCoordinate(okfVersion, kind2, field);
33287
33624
  return coordinate ? frontmatter2[coordinate.storageField] : void 0;
@@ -33302,11 +33639,11 @@ function isPlainObject(value) {
33302
33639
  const prototype = Object.getPrototypeOf(value);
33303
33640
  return prototype === Object.prototype || prototype === null;
33304
33641
  }
33305
- function hasOwn(record, key) {
33306
- return Object.prototype.hasOwnProperty.call(record, key);
33642
+ function hasOwn(record2, key) {
33643
+ return Object.prototype.hasOwnProperty.call(record2, key);
33307
33644
  }
33308
- function setOwn(record, key, value) {
33309
- Object.defineProperty(record, key, { value, enumerable: true, configurable: true, writable: true });
33645
+ function setOwn(record2, key, value) {
33646
+ Object.defineProperty(record2, key, { value, enumerable: true, configurable: true, writable: true });
33310
33647
  }
33311
33648
  function isScalar(value) {
33312
33649
  return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
@@ -33798,6 +34135,10 @@ function parseConventionDoc(doc, options = {}) {
33798
34135
  if (browseCollapsed !== void 0) kind2.browseCollapsed = browseCollapsed;
33799
34136
  if (order !== void 0) kind2.order = order;
33800
34137
  if (claim !== void 0) kind2.claim = claim;
34138
+ if (Object.hasOwn(fm, "deprecated")) {
34139
+ kind2.deprecated = parseKindDeprecation(fm.deprecated, kind2, RESERVED_KIND_FIELD_NAMES, claimCoordinates(options.okfVersion, kind2)?.fields ?? []);
34140
+ warnings.push(...kind2.deprecated.problems ?? []);
34141
+ }
33801
34142
  return {
33802
34143
  ok: true,
33803
34144
  kind: kind2,
@@ -43558,8 +43899,8 @@ var BridgeService = class {
43558
43899
  if (!after) return this.reload(launchId, "the View changed while its subscription was polled");
43559
43900
  const changes = [];
43560
43901
  const removed = [];
43561
- for (const [id, version] of next) {
43562
- if (subscription.baseline.get(id) !== version) changes.push({ id, version });
43902
+ for (const [id, version2] of next) {
43903
+ if (subscription.baseline.get(id) !== version2) changes.push({ id, version: version2 });
43563
43904
  }
43564
43905
  for (const id of subscription.baseline.keys()) {
43565
43906
  if (!next.has(id)) removed.push(id);
@@ -44214,7 +44555,7 @@ function buildSnapshot(first) {
44214
44555
  blobs.sort((a, b) => a.key.localeCompare(b.key));
44215
44556
  const blobsByKey = new Map(blobs.map((row) => [row.key, row]));
44216
44557
  const views = [];
44217
- for (const { doc, version } of parsedDocs.values()) {
44558
+ for (const { doc, version: version2 } of parsedDocs.values()) {
44218
44559
  if (doc.frontmatter.type !== "View") continue;
44219
44560
  const registration = parseRegistration(doc.id, doc.frontmatter);
44220
44561
  if (!registration) {
@@ -44243,7 +44584,7 @@ function buildSnapshot(first) {
44243
44584
  const presentation = doc.frontmatter.presentation;
44244
44585
  views.push({
44245
44586
  id: registration.id,
44246
- registrationVersion: version,
44587
+ registrationVersion: version2,
44247
44588
  title: typeof doc.frontmatter.title === "string" && doc.frontmatter.title.trim() ? doc.frontmatter.title.trim() : registration.id,
44248
44589
  ...typeof doc.frontmatter.description === "string" ? { description: doc.frontmatter.description } : {},
44249
44590
  ...presentation === "workspace" || presentation === "inline" || presentation === "adaptive" ? { presentation } : {},