@composable-os/cli 0.1.0-beta.7 → 0.1.0-beta.8

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.
@@ -3,11 +3,11 @@ import {
3
3
  fetchKit,
4
4
  lineDiff,
5
5
  loadClientProduct
6
- } from "./chunk-VL62IMBN.js";
6
+ } from "./chunk-KOKYDJ7Z.js";
7
7
  import {
8
8
  CliError,
9
9
  str
10
- } from "./chunk-Y7PQ7NIL.js";
10
+ } from "./chunk-G3ORKXVP.js";
11
11
  import "./chunk-ZRWF6QZS.js";
12
12
  import "./chunk-2ABSVMGB.js";
13
13
  import "./chunk-6UWRT4VM.js";
@@ -1056,7 +1056,7 @@ async function ext(argv, deps) {
1056
1056
  }
1057
1057
  async function client(argv, deps) {
1058
1058
  if (argv[0] === "generate" && !argv.includes("--out")) {
1059
- const repo = await import("./client-repo-G55G4OLV.js");
1059
+ const repo = await import("./client-repo-ZVZ6KW5S.js");
1060
1060
  const parsed = parseArgs(["client", ...argv.slice(1)]);
1061
1061
  const dir = str(parsed.flags, "dir") ?? process.cwd();
1062
1062
  if (repo.isClientRepo(dir)) {
@@ -1070,7 +1070,7 @@ async function client(argv, deps) {
1070
1070
  }
1071
1071
  }
1072
1072
  try {
1073
- const { runClient } = await import("./cli-XHC6QBQW.js");
1073
+ const { runClient } = await import("./cli-DTMGNDXN.js");
1074
1074
  return await runClient(argv, deps.io);
1075
1075
  } catch (error) {
1076
1076
  if (error.code === "ERR_MODULE_NOT_FOUND") {
@@ -1133,8 +1133,8 @@ async function runCli(argv, input) {
1133
1133
  deps.io.out(HELP);
1134
1134
  return argv.length ? 0 : 2;
1135
1135
  }
1136
- const repo = await import("./client-repo-G55G4OLV.js");
1137
- const blocks = await import("./blocks-HVTAQ5W2.js");
1136
+ const repo = await import("./client-repo-ZVZ6KW5S.js");
1137
+ const blocks = await import("./blocks-DEELKGDC.js");
1138
1138
  const commands = {
1139
1139
  install,
1140
1140
  // In a client repo (its product.ts is a client product), `cos upgrade` moves the repo to a
@@ -7,7 +7,7 @@ import {
7
7
  str,
8
8
  upgrade,
9
9
  verified
10
- } from "./chunk-Y7PQ7NIL.js";
10
+ } from "./chunk-G3ORKXVP.js";
11
11
  import {
12
12
  CloudflareClient,
13
13
  assetHash,
@@ -413,8 +413,8 @@ function appClients(product) {
413
413
  return out;
414
414
  }
415
415
  async function generateClients(root, product, kit, io) {
416
- const { releaseContract, renderClient } = await import("./src-SSVOBH6L.js");
417
- const { loadExtension } = await import("./cli-XHC6QBQW.js");
416
+ const { releaseContract, renderClient } = await import("./src-G6OF5SKW.js");
417
+ const { loadExtension } = await import("./cli-DTMGNDXN.js");
418
418
  const perAudience = ["customer", "public", "staff"].map((audience) => {
419
419
  const bytes = kit.get(`${KIT.contract}${audience}.json`);
420
420
  if (!bytes) throw new CliError(`The release's client kit has no ${audience} contract.`);
@@ -431,7 +431,7 @@ async function generateClients(root, product, kit, io) {
431
431
  }
432
432
  const roles = product.mobile?.roles ?? [];
433
433
  if (roles.length && product.mobile) {
434
- const { renderRoleClient } = await import("./src-SSVOBH6L.js");
434
+ const { renderRoleClient } = await import("./src-G6OF5SKW.js");
435
435
  const rolesFile = kit.get(`${KIT.contract}roles.json`);
436
436
  if (!rolesFile) {
437
437
  throw new CliError(
@@ -12,7 +12,7 @@ import {
12
12
  STATEMENTS_CALIBRATED,
13
13
  coreRegistry,
14
14
  toolOperation
15
- } from "./chunk-BEKL3CA2.js";
15
+ } from "./chunk-XDDBLYKW.js";
16
16
  import {
17
17
  AUDIENCES,
18
18
  JOB_CHANGE_CALIBRATED,
@@ -20,7 +20,7 @@ import {
20
20
  audiencesOf,
21
21
  choice,
22
22
  forPacks
23
- } from "./chunk-MINQ46RU.js";
23
+ } from "./chunk-LTQDLCP7.js";
24
24
  import {
25
25
  external_exports,
26
26
  toManifest
@@ -16236,6 +16236,7 @@ var personOperations = [
16236
16236
  ];
16237
16237
 
16238
16238
  export {
16239
+ valuesEqual,
16239
16240
  diffRecords,
16240
16241
  errorForLog,
16241
16242
  AUDIENCES,
@@ -220,12 +220,13 @@ import {
220
220
  unknownObject,
221
221
  updateVisible,
222
222
  validateConditions,
223
+ valuesEqual,
223
224
  vectorId,
224
225
  visibleObject,
225
226
  visibleSource,
226
227
  visibleTable,
227
228
  zonedTime
228
- } from "./chunk-MINQ46RU.js";
229
+ } from "./chunk-LTQDLCP7.js";
229
230
  import {
230
231
  CHANNELS,
231
232
  compareVersions,
@@ -3422,6 +3423,13 @@ async function invokeOnce(op, rawInput, ctx, attempt) {
3422
3423
  grantedPermissions: ctx.grantedPermissions,
3423
3424
  permissionGrants: packRole ? [] : grants,
3424
3425
  reason: ctx.reason,
3426
+ ...ctx.approval ? {
3427
+ approval: {
3428
+ actionId: ctx.approval.actionId,
3429
+ approvedBy: ctx.approval.approvedBy,
3430
+ preview: ctx.approval.preview
3431
+ }
3432
+ } : {},
3425
3433
  write: (...statements2) => {
3426
3434
  writes.push(...statements2);
3427
3435
  },
@@ -8688,6 +8696,289 @@ var APPROVAL_INTENT_CALIBRATED = {
8688
8696
  }
8689
8697
  };
8690
8698
 
8699
+ // ../core/src/records/media.ts
8700
+ var MEDIA_WIDTHS = [320, 640, 960, 1280, 1920];
8701
+ var MEDIA_PREFIX = "media/";
8702
+ var u16be = (b, at) => (b[at] ?? 0) << 8 | (b[at + 1] ?? 0);
8703
+ var u16le = (b, at) => (b[at] ?? 0) | (b[at + 1] ?? 0) << 8;
8704
+ var u24le = (b, at) => u16le(b, at) | (b[at + 2] ?? 0) << 16;
8705
+ var u32be = (b, at) => u16be(b, at) * 65536 + u16be(b, at + 2);
8706
+ var ascii = (bytes, at, text4) => [...text4].every((c, i) => bytes[at + i] === c.charCodeAt(0));
8707
+ function mediaDimensions(bytes, type) {
8708
+ const none = { width: null, height: null };
8709
+ try {
8710
+ switch (type) {
8711
+ case "image/png":
8712
+ return { width: u32be(bytes, 16), height: u32be(bytes, 20) };
8713
+ case "image/gif":
8714
+ return { width: u16le(bytes, 6), height: u16le(bytes, 8) };
8715
+ case "image/webp": {
8716
+ if (ascii(bytes, 12, "VP8X")) {
8717
+ return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
8718
+ }
8719
+ if (ascii(bytes, 12, "VP8L")) {
8720
+ const b0 = bytes[21] ?? 0;
8721
+ const b1 = bytes[22] ?? 0;
8722
+ const b2 = bytes[23] ?? 0;
8723
+ const b3 = bytes[24] ?? 0;
8724
+ return {
8725
+ width: 1 + ((b1 & 63) << 8 | b0),
8726
+ height: 1 + ((b3 & 15) << 10 | b2 << 2 | (b1 & 192) >> 6)
8727
+ };
8728
+ }
8729
+ if (ascii(bytes, 12, "VP8 ")) {
8730
+ return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
8731
+ }
8732
+ return none;
8733
+ }
8734
+ case "image/jpeg": {
8735
+ let at = 2;
8736
+ while (at + 9 < bytes.length) {
8737
+ if (bytes[at] !== 255) return none;
8738
+ const marker = bytes[at + 1] ?? 0;
8739
+ const length = u16be(bytes, at + 2);
8740
+ const frame = marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204;
8741
+ if (frame) return { height: u16be(bytes, at + 5), width: u16be(bytes, at + 7) };
8742
+ if (length < 2) return none;
8743
+ at += 2 + length;
8744
+ }
8745
+ return none;
8746
+ }
8747
+ default:
8748
+ return none;
8749
+ }
8750
+ } catch {
8751
+ return none;
8752
+ }
8753
+ }
8754
+ function servedWidth(asked) {
8755
+ if (asked === null || !Number.isFinite(asked) || asked <= 0) return null;
8756
+ return MEDIA_WIDTHS.find((w) => w >= asked) ?? MEDIA_WIDTHS[MEDIA_WIDTHS.length - 1] ?? null;
8757
+ }
8758
+ function mediaUsesOf(object, content) {
8759
+ const uses = /* @__PURE__ */ new Map();
8760
+ for (const field of object.fields) {
8761
+ if (!Object.hasOwn(content, field.name)) continue;
8762
+ const schema = documentSchemaOf({
8763
+ type: field.fieldType,
8764
+ schema: field.options?.document?.schema
8765
+ });
8766
+ const value = content[field.name];
8767
+ if (!schema || value === null || value === void 0) continue;
8768
+ for (const ref2 of documentRefs(schema, value)) {
8769
+ if (ref2.to !== RICH_TEXT_MEDIA_OBJECT) continue;
8770
+ uses.set(`${ref2.id}|${field.name}`, { media: ref2.id, field: field.name });
8771
+ }
8772
+ }
8773
+ return [...uses.values()];
8774
+ }
8775
+
8776
+ // ../core/src/records/publish.ts
8777
+ var PUBLISH_OPERATIONS = /* @__PURE__ */ new Set([
8778
+ "record.publish",
8779
+ "record.schedulePublish",
8780
+ "record.unpublish",
8781
+ "record.cancelSchedule"
8782
+ ]);
8783
+ var ALWAYS_REVIEWED_PUBLISHERS = [
8784
+ "assistant",
8785
+ "mcp",
8786
+ "automation",
8787
+ "extension"
8788
+ ];
8789
+ var DRAFT_KEY = "draftFingerprint";
8790
+ function publisherOf(ctx) {
8791
+ return ctx.approval ? { user: ctx.approval.approvedBy, requestedBy: ctx.user.id, requestedVia: ctx.actor } : { user: ctx.user.id, requestedBy: null, requestedVia: null };
8792
+ }
8793
+ async function draftFingerprint(object, record) {
8794
+ const content = object.publishable.content.map((f) => [f, record.values[f] ?? null]);
8795
+ const digest = await crypto.subtle.digest(
8796
+ "SHA-256",
8797
+ new TextEncoder().encode(JSON.stringify(content))
8798
+ );
8799
+ return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
8800
+ }
8801
+ function assertAskedFor(ctx, object, id2, now) {
8802
+ if (!ctx.approval) return;
8803
+ const asked = ctx.approval.preview.find(
8804
+ (p) => p.object === object && p.id === id2 && DRAFT_KEY in p.diff
8805
+ )?.diff;
8806
+ const changed = asked ? Object.keys(now).find((key) => key in asked && !valuesEqual(asked[key]?.before, now[key])) : DRAFT_KEY;
8807
+ if (changed) {
8808
+ throw new ConflictError(
8809
+ `The ${object} ${id2} changed after this publish was asked for (${changed}), so what would go live is not what was approved. Ask for the publish again.`,
8810
+ { object, id: id2, field: changed, reason: "changed_since_request" }
8811
+ );
8812
+ }
8813
+ }
8814
+ var SUMMARY_CHARS = 280;
8815
+ function documentWords(value, out2 = []) {
8816
+ if (Array.isArray(value)) {
8817
+ for (const item of value) documentWords(item, out2);
8818
+ } else if (value && typeof value === "object") {
8819
+ for (const [key, v] of Object.entries(value)) {
8820
+ if (key === "text" && typeof v === "string") out2.push(v);
8821
+ else documentWords(v, out2);
8822
+ }
8823
+ }
8824
+ return out2;
8825
+ }
8826
+ function summaryOf(value) {
8827
+ if (value === null || value === void 0) return null;
8828
+ const cut = (text4) => text4.length > SUMMARY_CHARS ? `${text4.slice(0, SUMMARY_CHARS).trimEnd()}\u2026` : text4;
8829
+ if (typeof value === "string") return cut(value);
8830
+ if (typeof value !== "object") return value;
8831
+ const words = documentWords(value).join(" ").replace(/\s+/g, " ").trim();
8832
+ return words ? cut(words) : `(${documentBytes(value)} bytes)`;
8833
+ }
8834
+ function publishDiff(object, live, working, fingerprint, extra) {
8835
+ const diff = { ...extra };
8836
+ for (const field of object.publishable.content) {
8837
+ const before = live ? live[field] ?? null : null;
8838
+ const after = working.values[field] ?? null;
8839
+ if (valuesEqual(before, after)) continue;
8840
+ const b = summaryOf(before);
8841
+ let a = summaryOf(after);
8842
+ if (valuesEqual(b, a)) a = `${String(a)} (changed further on)`;
8843
+ diff[field] = { before: b, after: a };
8844
+ }
8845
+ diff[DRAFT_KEY] = { before: fingerprint, after: fingerprint };
8846
+ return diff;
8847
+ }
8848
+ async function liveContent(ctx, object, id2) {
8849
+ const row = await ctx.db.selectFrom("core_publish_version").select(["version", "content"]).where("object_type", "=", object).where("record_id", "=", id2).where("current", "=", 1).executeTakeFirst();
8850
+ return row ? { version: Number(row.version), content: JSON.parse(row.content) } : null;
8851
+ }
8852
+ var VERSION_MAX_BYTES = 1048576;
8853
+ var empty = (value) => value === void 0 || value === null || value === "";
8854
+ function snapshotOf(object, record, at) {
8855
+ const { content: fields, slug: slug2, date } = object.publishable;
8856
+ if (slug2 && empty(record.values[slug2])) {
8857
+ throw new ValidationError(`${object.label} needs an address (${slug2}) to be published`, {
8858
+ field: slug2,
8859
+ reason: "slug_required"
8860
+ });
8861
+ }
8862
+ const content = Object.fromEntries(
8863
+ fields.map((f) => [f, record.values[f] ?? null])
8864
+ );
8865
+ const fill = {};
8866
+ if (date && empty(content[date])) {
8867
+ const type = object.fields.find((f) => f.name === date)?.type;
8868
+ fill[date] = type === "date" ? at.slice(0, 10) : at;
8869
+ content[date] = fill[date];
8870
+ }
8871
+ const bytes = documentBytes(content);
8872
+ if (bytes > VERSION_MAX_BYTES) {
8873
+ throw new ValidationError(
8874
+ `The content is ${bytes} bytes; a version holds at most ${VERSION_MAX_BYTES}`,
8875
+ { bytes, max: VERSION_MAX_BYTES }
8876
+ );
8877
+ }
8878
+ return { content, bytes, fill };
8879
+ }
8880
+ async function nextVersion(ctx, object, id2) {
8881
+ const latest = await sql`
8882
+ SELECT max(version) AS version FROM core_publish_version
8883
+ WHERE object_type = ${object} AND record_id = ${id2}
8884
+ `.execute(ctx.db);
8885
+ return Number(latest.rows[0]?.version ?? 0) + 1;
8886
+ }
8887
+ function publishWrites(definition, id2, version, snapshot4, by) {
8888
+ const object = definition.name;
8889
+ const content = typeof snapshot4.content === "string" ? snapshot4.content : JSON.stringify(snapshot4.content);
8890
+ const values = typeof snapshot4.content === "string" ? JSON.parse(snapshot4.content) : snapshot4.content;
8891
+ return [
8892
+ // The media the new current version references (ADR 0444): what the public may be served.
8893
+ ...publishedMediaWrites(object, id2, mediaUsesOf(definition, values)),
8894
+ CompiledQuery.raw(
8895
+ "UPDATE core_publish_version SET current = 0 WHERE object_type = ? AND record_id = ? AND current = 1",
8896
+ [object, id2]
8897
+ ),
8898
+ CompiledQuery.raw(
8899
+ "INSERT INTO core_publish_version (object_type, record_id, version, content, bytes, current, published_at, published_by, note, requested_by, requested_via) VALUES (?, ?, ?, ?, ?, 1, ?, ?, ?, ?, ?)",
8900
+ [
8901
+ object,
8902
+ id2,
8903
+ version,
8904
+ content,
8905
+ snapshot4.bytes,
8906
+ by.at,
8907
+ by.user,
8908
+ by.note,
8909
+ by.requestedBy ?? null,
8910
+ by.requestedVia ?? null
8911
+ ]
8912
+ ),
8913
+ clearScheduleWrite(object, id2)
8914
+ ];
8915
+ }
8916
+ function unpublishWrites(object, id2) {
8917
+ return [
8918
+ ...publishedMediaWrites(object, id2, []),
8919
+ CompiledQuery.raw(
8920
+ "UPDATE core_publish_version SET current = 0 WHERE object_type = ? AND record_id = ? AND current = 1",
8921
+ [object, id2]
8922
+ ),
8923
+ clearScheduleWrite(object, id2)
8924
+ ];
8925
+ }
8926
+ function publishedMediaWrites(object, id2, uses) {
8927
+ return [
8928
+ CompiledQuery.raw("DELETE FROM core_published_media WHERE object_type = ? AND record_id = ?", [
8929
+ object,
8930
+ id2
8931
+ ]),
8932
+ ...uses.map(
8933
+ (use) => CompiledQuery.raw(
8934
+ "INSERT OR IGNORE INTO core_published_media (media_id, object_type, record_id, field) VALUES (?, ?, ?, ?)",
8935
+ [use.media, object, id2, use.field]
8936
+ )
8937
+ )
8938
+ ];
8939
+ }
8940
+ function scheduleWrite(object, id2, at, snapshot4, by) {
8941
+ return CompiledQuery.raw(
8942
+ "INSERT INTO core_publish_schedule (object_type, record_id, publish_at, content, bytes, note, scheduled_by, scheduled_at, requested_by, requested_via) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (object_type, record_id) DO UPDATE SET publish_at = excluded.publish_at, content = excluded.content, bytes = excluded.bytes, note = excluded.note, scheduled_by = excluded.scheduled_by, scheduled_at = excluded.scheduled_at, requested_by = excluded.requested_by, requested_via = excluded.requested_via",
8943
+ [
8944
+ object,
8945
+ id2,
8946
+ at,
8947
+ JSON.stringify(snapshot4.content),
8948
+ snapshot4.bytes,
8949
+ by.note,
8950
+ by.user,
8951
+ by.now,
8952
+ by.requestedBy,
8953
+ by.requestedVia
8954
+ ]
8955
+ );
8956
+ }
8957
+ function clearScheduleWrite(object, id2) {
8958
+ return CompiledQuery.raw(
8959
+ "DELETE FROM core_publish_schedule WHERE object_type = ? AND record_id = ?",
8960
+ [object, id2]
8961
+ );
8962
+ }
8963
+ async function scheduleOf(ctx, object, id2) {
8964
+ return await ctx.db.selectFrom("core_publish_schedule").select([
8965
+ "publish_at",
8966
+ "scheduled_by",
8967
+ "note",
8968
+ "bytes",
8969
+ "content",
8970
+ "requested_by",
8971
+ "requested_via"
8972
+ ]).where("object_type", "=", object).where("record_id", "=", id2).executeTakeFirst() ?? null;
8973
+ }
8974
+ async function currentVersion(ctx, object, id2) {
8975
+ const row = await ctx.db.selectFrom("core_publish_version").select("version").where("object_type", "=", object).where("record_id", "=", id2).where("current", "=", 1).executeTakeFirst();
8976
+ return row ? Number(row.version) : null;
8977
+ }
8978
+ async function dueSchedules(ctx, now, limit) {
8979
+ return ctx.db.selectFrom("core_publish_schedule").selectAll().where("publish_at", "<=", now).orderBy("publish_at").orderBy("object_type").orderBy("record_id").limit(limit).execute();
8980
+ }
8981
+
8691
8982
  // ../core/src/operations/approval.ts
8692
8983
  var changeSetId = external_exports.string().startsWith("chs_").max(64).describe("Change set id (chs_\u2026)");
8693
8984
  var actionId = external_exports.string().startsWith("pac_").max(64).describe("Pending action id (pac_\u2026)");
@@ -9331,6 +9622,21 @@ async function approveActions(ctx, input, how) {
9331
9622
  });
9332
9623
  }
9333
9624
  }
9625
+ const publish = targets.find((t) => PUBLISH_OPERATIONS.has(t.operation));
9626
+ if (publish) {
9627
+ if (ctx.actor !== "human") {
9628
+ throw new ForbiddenError("A publish is approved by a person, never by an AI actor", {
9629
+ actionId: publish.id,
9630
+ actor: ctx.actor
9631
+ });
9632
+ }
9633
+ if (!holdsPermission(ctx.user, ctx.permissionGrants, "records:publish")) {
9634
+ throw new ForbiddenError(
9635
+ "Approving a publish needs the publish permission (records:publish)",
9636
+ { actionId: publish.id, permission: "records:publish" }
9637
+ );
9638
+ }
9639
+ }
9334
9640
  const targetIds = new Set(targets.map((t) => t.id));
9335
9641
  const depIds = [...new Set(targets.flatMap((t) => parse(t.depends_on, [])))];
9336
9642
  const deps = await loadActions(ctx.db, { ids: depIds.filter((d) => !targetIds.has(d)) });
@@ -11638,7 +11944,7 @@ function slugFields(object) {
11638
11944
  (f) => f.fieldType === "slug" && f.extension !== void 0 && f.extension === object.extension && fieldStorage(object.name, f.name)?.own === true
11639
11945
  );
11640
11946
  }
11641
- var empty = (value) => value === void 0 || value === null || value === "";
11947
+ var empty2 = (value) => value === void 0 || value === null || value === "";
11642
11948
  function columnOf(object, field) {
11643
11949
  const column3 = fieldStorage(object.name, field.name)?.column;
11644
11950
  if (!column3) throw new Error(`${object.name}.${field.name} has no column`);
@@ -11674,7 +11980,7 @@ async function slugsForCreate(ctx, object, values) {
11674
11980
  const out2 = { ...values };
11675
11981
  for (const field of fields) {
11676
11982
  const given = out2[field.name];
11677
- if (empty(given)) {
11983
+ if (empty2(given)) {
11678
11984
  const title = object.titleField ? out2[object.titleField] : void 0;
11679
11985
  const local = object.name.split(".").pop() ?? "record";
11680
11986
  const base2 = slugify(typeof title === "string" ? title : "") || slugify(local) || "record";
@@ -11687,7 +11993,7 @@ async function slugsForCreate(ctx, object, values) {
11687
11993
  }
11688
11994
  async function assertSlugsFree(ctx, object, id2, values) {
11689
11995
  for (const field of slugFields(object)) {
11690
- if (!Object.hasOwn(values, field.name) || empty(values[field.name])) continue;
11996
+ if (!Object.hasOwn(values, field.name) || empty2(values[field.name])) continue;
11691
11997
  await assertFree(ctx, object, field, values[field.name], id2);
11692
11998
  }
11693
11999
  }
@@ -20519,83 +20825,6 @@ var meOperations = [
20519
20825
  meDeleteAccount
20520
20826
  ];
20521
20827
 
20522
- // ../core/src/records/media.ts
20523
- var MEDIA_WIDTHS = [320, 640, 960, 1280, 1920];
20524
- var MEDIA_PREFIX = "media/";
20525
- var u16be = (b, at) => (b[at] ?? 0) << 8 | (b[at + 1] ?? 0);
20526
- var u16le = (b, at) => (b[at] ?? 0) | (b[at + 1] ?? 0) << 8;
20527
- var u24le = (b, at) => u16le(b, at) | (b[at + 2] ?? 0) << 16;
20528
- var u32be = (b, at) => u16be(b, at) * 65536 + u16be(b, at + 2);
20529
- var ascii = (bytes, at, text4) => [...text4].every((c, i) => bytes[at + i] === c.charCodeAt(0));
20530
- function mediaDimensions(bytes, type) {
20531
- const none = { width: null, height: null };
20532
- try {
20533
- switch (type) {
20534
- case "image/png":
20535
- return { width: u32be(bytes, 16), height: u32be(bytes, 20) };
20536
- case "image/gif":
20537
- return { width: u16le(bytes, 6), height: u16le(bytes, 8) };
20538
- case "image/webp": {
20539
- if (ascii(bytes, 12, "VP8X")) {
20540
- return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
20541
- }
20542
- if (ascii(bytes, 12, "VP8L")) {
20543
- const b0 = bytes[21] ?? 0;
20544
- const b1 = bytes[22] ?? 0;
20545
- const b2 = bytes[23] ?? 0;
20546
- const b3 = bytes[24] ?? 0;
20547
- return {
20548
- width: 1 + ((b1 & 63) << 8 | b0),
20549
- height: 1 + ((b3 & 15) << 10 | b2 << 2 | (b1 & 192) >> 6)
20550
- };
20551
- }
20552
- if (ascii(bytes, 12, "VP8 ")) {
20553
- return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
20554
- }
20555
- return none;
20556
- }
20557
- case "image/jpeg": {
20558
- let at = 2;
20559
- while (at + 9 < bytes.length) {
20560
- if (bytes[at] !== 255) return none;
20561
- const marker = bytes[at + 1] ?? 0;
20562
- const length = u16be(bytes, at + 2);
20563
- const frame = marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204;
20564
- if (frame) return { height: u16be(bytes, at + 5), width: u16be(bytes, at + 7) };
20565
- if (length < 2) return none;
20566
- at += 2 + length;
20567
- }
20568
- return none;
20569
- }
20570
- default:
20571
- return none;
20572
- }
20573
- } catch {
20574
- return none;
20575
- }
20576
- }
20577
- function servedWidth(asked) {
20578
- if (asked === null || !Number.isFinite(asked) || asked <= 0) return null;
20579
- return MEDIA_WIDTHS.find((w) => w >= asked) ?? MEDIA_WIDTHS[MEDIA_WIDTHS.length - 1] ?? null;
20580
- }
20581
- function mediaUsesOf(object, content) {
20582
- const uses = /* @__PURE__ */ new Map();
20583
- for (const field of object.fields) {
20584
- if (!Object.hasOwn(content, field.name)) continue;
20585
- const schema = documentSchemaOf({
20586
- type: field.fieldType,
20587
- schema: field.options?.document?.schema
20588
- });
20589
- const value = content[field.name];
20590
- if (!schema || value === null || value === void 0) continue;
20591
- for (const ref2 of documentRefs(schema, value)) {
20592
- if (ref2.to !== RICH_TEXT_MEDIA_OBJECT) continue;
20593
- uses.set(`${ref2.id}|${field.name}`, { media: ref2.id, field: field.name });
20594
- }
20595
- }
20596
- return [...uses.values()];
20597
- }
20598
-
20599
20828
  // ../core/src/operations/media.ts
20600
20829
  var mediaId = external_exports.string().min(1).max(64).describe("A media item's id");
20601
20830
  var mediaOut = external_exports.object({
@@ -23065,7 +23294,7 @@ async function resolveBuyer(ctx, address2) {
23065
23294
  }
23066
23295
  const creator = await creatorFor(ctx.db, email);
23067
23296
  if (!creator) throw new ConfigError("There is no admin to create the buyer's Person for");
23068
- const { personCreate } = await import("./person-AZFEPZOE.js");
23297
+ const { personCreate } = await import("./person-WMWRF2HV.js");
23069
23298
  const asCreator = Object.create(ctx, {
23070
23299
  user: { value: creator },
23071
23300
  actor: { value: "automation" },
@@ -24584,107 +24813,6 @@ var recordImport = defineOperation({
24584
24813
  });
24585
24814
  var recordImportOperations = [recordImport];
24586
24815
 
24587
- // ../core/src/records/publish.ts
24588
- var VERSION_MAX_BYTES = 1048576;
24589
- var empty2 = (value) => value === void 0 || value === null || value === "";
24590
- function snapshotOf(object, record, at) {
24591
- const { content: fields, slug: slug2, date } = object.publishable;
24592
- if (slug2 && empty2(record.values[slug2])) {
24593
- throw new ValidationError(`${object.label} needs an address (${slug2}) to be published`, {
24594
- field: slug2,
24595
- reason: "slug_required"
24596
- });
24597
- }
24598
- const content = Object.fromEntries(
24599
- fields.map((f) => [f, record.values[f] ?? null])
24600
- );
24601
- const fill = {};
24602
- if (date && empty2(content[date])) {
24603
- const type = object.fields.find((f) => f.name === date)?.type;
24604
- fill[date] = type === "date" ? at.slice(0, 10) : at;
24605
- content[date] = fill[date];
24606
- }
24607
- const bytes = documentBytes(content);
24608
- if (bytes > VERSION_MAX_BYTES) {
24609
- throw new ValidationError(
24610
- `The content is ${bytes} bytes; a version holds at most ${VERSION_MAX_BYTES}`,
24611
- { bytes, max: VERSION_MAX_BYTES }
24612
- );
24613
- }
24614
- return { content, bytes, fill };
24615
- }
24616
- async function nextVersion(ctx, object, id2) {
24617
- const latest = await sql`
24618
- SELECT max(version) AS version FROM core_publish_version
24619
- WHERE object_type = ${object} AND record_id = ${id2}
24620
- `.execute(ctx.db);
24621
- return Number(latest.rows[0]?.version ?? 0) + 1;
24622
- }
24623
- function publishWrites(definition, id2, version, snapshot4, by) {
24624
- const object = definition.name;
24625
- const content = typeof snapshot4.content === "string" ? snapshot4.content : JSON.stringify(snapshot4.content);
24626
- const values = typeof snapshot4.content === "string" ? JSON.parse(snapshot4.content) : snapshot4.content;
24627
- return [
24628
- // The media the new current version references (ADR 0444): what the public may be served.
24629
- ...publishedMediaWrites(object, id2, mediaUsesOf(definition, values)),
24630
- CompiledQuery.raw(
24631
- "UPDATE core_publish_version SET current = 0 WHERE object_type = ? AND record_id = ? AND current = 1",
24632
- [object, id2]
24633
- ),
24634
- CompiledQuery.raw(
24635
- "INSERT INTO core_publish_version (object_type, record_id, version, content, bytes, current, published_at, published_by, note) VALUES (?, ?, ?, ?, ?, 1, ?, ?, ?)",
24636
- [object, id2, version, content, snapshot4.bytes, by.at, by.user, by.note]
24637
- ),
24638
- clearScheduleWrite(object, id2)
24639
- ];
24640
- }
24641
- function unpublishWrites(object, id2) {
24642
- return [
24643
- ...publishedMediaWrites(object, id2, []),
24644
- CompiledQuery.raw(
24645
- "UPDATE core_publish_version SET current = 0 WHERE object_type = ? AND record_id = ? AND current = 1",
24646
- [object, id2]
24647
- ),
24648
- clearScheduleWrite(object, id2)
24649
- ];
24650
- }
24651
- function publishedMediaWrites(object, id2, uses) {
24652
- return [
24653
- CompiledQuery.raw("DELETE FROM core_published_media WHERE object_type = ? AND record_id = ?", [
24654
- object,
24655
- id2
24656
- ]),
24657
- ...uses.map(
24658
- (use) => CompiledQuery.raw(
24659
- "INSERT OR IGNORE INTO core_published_media (media_id, object_type, record_id, field) VALUES (?, ?, ?, ?)",
24660
- [use.media, object, id2, use.field]
24661
- )
24662
- )
24663
- ];
24664
- }
24665
- function scheduleWrite(object, id2, at, snapshot4, by) {
24666
- return CompiledQuery.raw(
24667
- "INSERT INTO core_publish_schedule (object_type, record_id, publish_at, content, bytes, note, scheduled_by, scheduled_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT (object_type, record_id) DO UPDATE SET publish_at = excluded.publish_at, content = excluded.content, bytes = excluded.bytes, note = excluded.note, scheduled_by = excluded.scheduled_by, scheduled_at = excluded.scheduled_at",
24668
- [object, id2, at, JSON.stringify(snapshot4.content), snapshot4.bytes, by.note, by.user, by.now]
24669
- );
24670
- }
24671
- function clearScheduleWrite(object, id2) {
24672
- return CompiledQuery.raw(
24673
- "DELETE FROM core_publish_schedule WHERE object_type = ? AND record_id = ?",
24674
- [object, id2]
24675
- );
24676
- }
24677
- async function scheduleOf(ctx, object, id2) {
24678
- return await ctx.db.selectFrom("core_publish_schedule").select(["publish_at", "scheduled_by", "note", "bytes", "content"]).where("object_type", "=", object).where("record_id", "=", id2).executeTakeFirst() ?? null;
24679
- }
24680
- async function currentVersion(ctx, object, id2) {
24681
- const row = await ctx.db.selectFrom("core_publish_version").select("version").where("object_type", "=", object).where("record_id", "=", id2).where("current", "=", 1).executeTakeFirst();
24682
- return row ? Number(row.version) : null;
24683
- }
24684
- async function dueSchedules(ctx, now, limit) {
24685
- return ctx.db.selectFrom("core_publish_schedule").selectAll().where("publish_at", "<=", now).orderBy("publish_at").orderBy("object_type").orderBy("record_id").limit(limit).execute();
24686
- }
24687
-
24688
24816
  // ../core/src/operations/record-versions.ts
24689
24817
  var objectName7 = external_exports.string().min(1).max(80).regex(/^[a-z][a-z0-9]*\.[a-z][a-z0-9]*$/).describe("An extension object (`<extension>.<object>`, see schema.objects)");
24690
24818
  var recordId3 = external_exports.string().min(1).max(64).describe("Record id");
@@ -24693,10 +24821,13 @@ var versionSummary = external_exports.object({
24693
24821
  version: external_exports.number().int(),
24694
24822
  current: external_exports.boolean().describe("The version readers are given"),
24695
24823
  publishedAt: external_exports.string(),
24696
- publishedBy: external_exports.string().nullable().describe("The staff user who published it"),
24824
+ publishedBy: external_exports.string().nullable().describe("The person who published it: for an approved request, the approver"),
24825
+ requestedBy: external_exports.string().nullable().describe("For an approved request: the staff user the AI actor asked for"),
24826
+ requestedVia: external_exports.string().nullable().describe("For an approved request: the actor that asked (assistant, mcp, ...)"),
24697
24827
  note: external_exports.string().nullable(),
24698
24828
  bytes: external_exports.number().int()
24699
24829
  });
24830
+ var ASKS = "A person with the publish permission does it at once. An AI assistant, MCP client, automation or extension may call it too: then it never happens at once, under any approval policy. It waits for a person with the publish permission to approve it (the result says it is pending), and is refused on approval if the record changed since it was asked for. The account it acts for must hold the publish permission to ask.";
24700
24831
  function requirePublishable(name) {
24701
24832
  const object = requireExtensionObject(name);
24702
24833
  if (!object.publishable) {
@@ -24711,17 +24842,28 @@ async function requireRecord(ctx, object, id2) {
24711
24842
  if (!record) throw new NotFoundError(object.name, id2);
24712
24843
  return record;
24713
24844
  }
24714
- var summaryOf = (row) => ({
24845
+ function refuseOverPending(ctx, object, id2) {
24846
+ const pending = ctx.simulation?.record(object.name, id2);
24847
+ if (pending) {
24848
+ throw new ValidationError(
24849
+ `This ${object.label.toLowerCase()} has changes still waiting for a person's approval (${pending.actionId}). Ask for the publish once they are approved or rejected.`,
24850
+ { reason: "pending_changes", actionId: pending.actionId }
24851
+ );
24852
+ }
24853
+ }
24854
+ var summaryOf2 = (row) => ({
24715
24855
  version: Number(row.version),
24716
24856
  current: Number(row.current) === 1,
24717
24857
  publishedAt: row.published_at,
24718
24858
  publishedBy: row.published_by,
24859
+ requestedBy: row.requested_by,
24860
+ requestedVia: row.requested_via,
24719
24861
  note: row.note,
24720
24862
  bytes: Number(row.bytes)
24721
24863
  });
24722
24864
  var recordPublish = defineOperation({
24723
24865
  name: "record.publish",
24724
- description: "Publish a record of a publishable object (see schema.objects): its content fields as they are now become its next version, and the version readers are given. Editing the record afterwards changes no version until it is published again; what follows a version (a program's assignments) keeps the one it pinned. Only a person with the publish permission can do this, never an AI assistant: draft the changes and ask a person to publish. Returns the new version.",
24866
+ description: `Publish a record of a publishable object (see schema.objects): its content fields as they are now become its next version, and the version readers are given. Editing the record afterwards changes no version until it is published again; what follows a version (a program's assignments) keeps the one it pinned. ${ASKS} Returns the new version.`,
24725
24867
  input: external_exports.object({
24726
24868
  object: objectName7,
24727
24869
  id: recordId3,
@@ -24730,37 +24872,50 @@ var recordPublish = defineOperation({
24730
24872
  output: versionSummary,
24731
24873
  permission: "records:publish",
24732
24874
  risk: "write",
24733
- actors: ["human"],
24734
- mcp: { expose: false },
24875
+ alwaysReview: ALWAYS_REVIEWED_PUBLISHERS,
24876
+ mcp: { title: "Publish a record (a person approves an AI's request)" },
24735
24877
  async handler(input, ctx) {
24736
24878
  const object = requirePublishable(input.object);
24879
+ refuseOverPending(ctx, object, input.id);
24737
24880
  const record = await requireRecord(ctx, object, input.id);
24881
+ const fingerprint = await draftFingerprint(object, record);
24882
+ const live = await liveContent(ctx, object.name, input.id);
24883
+ const before = {
24884
+ publishedVersion: live?.version ?? null,
24885
+ publishAt: record.values.publishAt ?? null
24886
+ };
24887
+ assertAskedFor(ctx, object.name, input.id, { ...before, [DRAFT_KEY]: fingerprint });
24738
24888
  const snapshot4 = snapshotOf(object, record, ctx.now);
24739
- if (Object.keys(snapshot4.fill).length) await updateRecord(ctx, object, input.id, snapshot4.fill);
24740
24889
  const version = await nextVersion(ctx, object.name, input.id);
24890
+ if (Object.keys(snapshot4.fill).length) await updateRecord(ctx, object, input.id, snapshot4.fill);
24891
+ ctx.recordChange({
24892
+ object: object.name,
24893
+ id: input.id,
24894
+ action: "update",
24895
+ before: { ...before, [DRAFT_KEY]: fingerprint },
24896
+ diff: publishDiff(object, live?.content ?? null, record, fingerprint, {
24897
+ publishedVersion: { before: before.publishedVersion, after: version },
24898
+ ...before.publishAt === null ? {} : { publishAt: { before: before.publishAt, after: null } }
24899
+ })
24900
+ });
24741
24901
  const note = input.note ?? null;
24902
+ const by = publisherOf(ctx);
24742
24903
  ctx.write(
24743
24904
  ...publishWrites(object, input.id, version, snapshot4, {
24744
24905
  at: ctx.now,
24745
- user: ctx.user.id,
24746
- note
24906
+ user: by.user,
24907
+ note,
24908
+ requestedBy: by.requestedBy,
24909
+ requestedVia: by.requestedVia
24747
24910
  })
24748
24911
  );
24749
- ctx.recordChange({
24750
- object: object.name,
24751
- id: input.id,
24752
- action: "update",
24753
- before: {
24754
- publishedVersion: record.values.publishedVersion ?? null,
24755
- publishAt: record.values.publishAt ?? null
24756
- },
24757
- after: { publishedVersion: version, publishAt: null }
24758
- });
24759
24912
  return {
24760
24913
  version,
24761
24914
  current: true,
24762
24915
  publishedAt: ctx.now,
24763
- publishedBy: ctx.user.id,
24916
+ publishedBy: by.user,
24917
+ requestedBy: by.requestedBy,
24918
+ requestedVia: by.requestedVia,
24764
24919
  note,
24765
24920
  bytes: snapshot4.bytes
24766
24921
  };
@@ -24770,13 +24925,15 @@ var SCHEDULE_MAX_DAYS = 366;
24770
24925
  var PUBLISH_DUE_BATCH = 20;
24771
24926
  var scheduleSummary = external_exports.object({
24772
24927
  publishAt: external_exports.string().describe("When it goes live (ISO-8601 UTC)"),
24773
- scheduledBy: external_exports.string(),
24928
+ scheduledBy: external_exports.string().describe("The person: for an approved request, the approver"),
24929
+ requestedBy: external_exports.string().nullable().describe("For an approved request: who the AI asked for"),
24930
+ requestedVia: external_exports.string().nullable().describe("For an approved request: the actor that asked"),
24774
24931
  note: external_exports.string().nullable(),
24775
24932
  bytes: external_exports.number().int()
24776
24933
  });
24777
24934
  var recordSchedulePublish = defineOperation({
24778
24935
  name: "record.schedulePublish",
24779
- description: "Schedule a record of a publishable object to be published at a time: its content fields as they are now are what goes live then (a later edit waits for the next publish). Replaces any earlier schedule; publishing now or unpublishing drops it. Only a person with the publish permission can do this, never an AI assistant. Returns the schedule.",
24936
+ description: `Schedule a record of a publishable object to be published at a time: its content fields as they are now are what goes live then (a later edit waits for the next publish). Replaces any earlier schedule; publishing now or unpublishing drops it. ${ASKS} Returns the schedule.`,
24780
24937
  input: external_exports.object({
24781
24938
  object: objectName7,
24782
24939
  id: recordId3,
@@ -24786,8 +24943,8 @@ var recordSchedulePublish = defineOperation({
24786
24943
  output: scheduleSummary,
24787
24944
  permission: "records:publish",
24788
24945
  risk: "write",
24789
- actors: ["human"],
24790
- mcp: { expose: false },
24946
+ alwaysReview: ALWAYS_REVIEWED_PUBLISHERS,
24947
+ mcp: { title: "Schedule a publish (a person approves an AI's request)" },
24791
24948
  async handler(input, ctx) {
24792
24949
  const object = requirePublishable(input.object);
24793
24950
  const at = new Date(input.at);
@@ -24802,37 +24959,54 @@ var recordSchedulePublish = defineOperation({
24802
24959
  field: "at"
24803
24960
  });
24804
24961
  }
24962
+ refuseOverPending(ctx, object, input.id);
24805
24963
  const record = await requireRecord(ctx, object, input.id);
24964
+ const fingerprint = await draftFingerprint(object, record);
24965
+ const live = await liveContent(ctx, object.name, input.id);
24966
+ const before = record.values.publishAt ?? null;
24967
+ assertAskedFor(ctx, object.name, input.id, { publishAt: before, [DRAFT_KEY]: fingerprint });
24806
24968
  const publishAt = at.toISOString();
24807
24969
  const snapshot4 = snapshotOf(object, record, publishAt);
24808
24970
  if (Object.keys(snapshot4.fill).length) await updateRecord(ctx, object, input.id, snapshot4.fill);
24971
+ ctx.recordChange({
24972
+ object: object.name,
24973
+ id: input.id,
24974
+ action: "update",
24975
+ before: { publishAt: before, [DRAFT_KEY]: fingerprint },
24976
+ diff: publishDiff(object, live?.content ?? null, record, fingerprint, {
24977
+ publishAt: { before, after: publishAt }
24978
+ })
24979
+ });
24809
24980
  const note = input.note ?? null;
24981
+ const by = publisherOf(ctx);
24810
24982
  ctx.write(
24811
24983
  scheduleWrite(object.name, input.id, publishAt, snapshot4, {
24812
24984
  now: ctx.now,
24813
- user: ctx.user.id,
24814
- note
24985
+ user: by.user,
24986
+ note,
24987
+ requestedBy: by.requestedBy,
24988
+ requestedVia: by.requestedVia
24815
24989
  })
24816
24990
  );
24817
- ctx.recordChange({
24818
- object: object.name,
24819
- id: input.id,
24820
- action: "update",
24821
- before: { publishAt: record.values.publishAt ?? null },
24822
- after: { publishAt }
24823
- });
24824
- return { publishAt, scheduledBy: ctx.user.id, note, bytes: snapshot4.bytes };
24991
+ return {
24992
+ publishAt,
24993
+ scheduledBy: by.user,
24994
+ requestedBy: by.requestedBy,
24995
+ requestedVia: by.requestedVia,
24996
+ note,
24997
+ bytes: snapshot4.bytes
24998
+ };
24825
24999
  }
24826
25000
  });
24827
25001
  var recordCancelSchedule = defineOperation({
24828
25002
  name: "record.cancelSchedule",
24829
- description: "Drop the scheduled publish of a record of a publishable object. What is live stays live. Not found when nothing is scheduled.",
25003
+ description: `Drop the scheduled publish of a record of a publishable object. What is live stays live. Not found when nothing is scheduled. ${ASKS}`,
24830
25004
  input: external_exports.object({ object: objectName7, id: recordId3 }),
24831
25005
  output: external_exports.object({ cancelled: external_exports.string().describe("The time it was scheduled for") }),
24832
25006
  permission: "records:publish",
24833
25007
  risk: "write",
24834
- actors: ["human"],
24835
- mcp: { expose: false },
25008
+ alwaysReview: ALWAYS_REVIEWED_PUBLISHERS,
25009
+ mcp: { title: "Cancel a scheduled publish (a person approves an AI's request)" },
24836
25010
  async handler(input, ctx) {
24837
25011
  const object = requirePublishable(input.object);
24838
25012
  await requireRecord(ctx, object, input.id);
@@ -24851,13 +25025,13 @@ var recordCancelSchedule = defineOperation({
24851
25025
  });
24852
25026
  var recordUnpublish = defineOperation({
24853
25027
  name: "record.unpublish",
24854
- description: "Unpublish a record of a publishable object: the public no longer reads it (it answers as a record that does not exist) and any scheduled publish is dropped. Its versions are kept and it can be published again. Only a person with the publish permission can do this.",
25028
+ description: `Unpublish a record of a publishable object: the public no longer reads it (it answers as a record that does not exist) and any scheduled publish is dropped. Its versions are kept and it can be published again. ${ASKS}`,
24855
25029
  input: external_exports.object({ object: objectName7, id: recordId3 }),
24856
25030
  output: external_exports.object({ unpublished: external_exports.number().int().describe("The version that was live") }),
24857
25031
  permission: "records:publish",
24858
25032
  risk: "write",
24859
- actors: ["human"],
24860
- mcp: { expose: false },
25033
+ alwaysReview: ALWAYS_REVIEWED_PUBLISHERS,
25034
+ mcp: { title: "Unpublish a record (a person approves an AI's request)" },
24861
25035
  async handler(input, ctx) {
24862
25036
  const object = requirePublishable(input.object);
24863
25037
  const record = await requireRecord(ctx, object, input.id);
@@ -24893,7 +25067,8 @@ var recordPublishDue = defineOperation({
24893
25067
  }),
24894
25068
  permission: "records:write",
24895
25069
  risk: "write",
24896
- // Only what a person scheduled is published here: no input names a record or its content.
25070
+ // Only what a person scheduled (or approved scheduling) is published here: no input names a
25071
+ // record or its content.
24897
25072
  actors: ["automation"],
24898
25073
  mcp: { expose: false },
24899
25074
  auditSummary: (output) => ({ count: output.published.length, dropped: output.dropped }),
@@ -24913,7 +25088,9 @@ var recordPublishDue = defineOperation({
24913
25088
  ...publishWrites(object, due.record_id, version, due, {
24914
25089
  at: ctx.now,
24915
25090
  user: due.scheduled_by,
24916
- note: due.note
25091
+ note: due.note,
25092
+ requestedBy: due.requested_by,
25093
+ requestedVia: due.requested_via
24917
25094
  })
24918
25095
  );
24919
25096
  ctx.recordChange({
@@ -24933,7 +25110,7 @@ var recordPublishDue = defineOperation({
24933
25110
  });
24934
25111
  var recordVersions = defineOperation({
24935
25112
  name: "record.versions",
24936
- description: "The published versions of a record of a publishable object, newest first: number, when, who, the note, size, and which one is current (what readers are given). Read one with record.version. Read-only.",
25113
+ description: "The published versions of a record of a publishable object, newest first: number, when, who published it (for an approved request, the approver, and who asked, and how), the note, size, and which one is current (what readers are given). Read one with record.version. Read-only.",
24937
25114
  input: external_exports.object({
24938
25115
  object: objectName7,
24939
25116
  id: recordId3,
@@ -24947,11 +25124,12 @@ var recordVersions = defineOperation({
24947
25124
  const object = requirePublishable(input.object);
24948
25125
  await requireRecord(ctx, object, input.id);
24949
25126
  const rows = await sql`
24950
- SELECT version, current, bytes, published_at, published_by, note FROM core_publish_version
25127
+ SELECT version, current, bytes, published_at, published_by, requested_by, requested_via, note
25128
+ FROM core_publish_version
24951
25129
  WHERE object_type = ${object.name} AND record_id = ${input.id}
24952
25130
  ORDER BY version DESC LIMIT ${input.limit}
24953
25131
  `.execute(ctx.db);
24954
- return { items: rows.rows.map(summaryOf) };
25132
+ return { items: rows.rows.map(summaryOf2) };
24955
25133
  }
24956
25134
  });
24957
25135
  var recordVersion = defineOperation({
@@ -24971,7 +25149,7 @@ var recordVersion = defineOperation({
24971
25149
  await requireRecord(ctx, object, input.id);
24972
25150
  const row = await readVersion(ctx, object.name, input.id, input.version);
24973
25151
  return {
24974
- ...summaryOf(row),
25152
+ ...summaryOf2(row),
24975
25153
  values: JSON.parse(row.content ?? "{}")
24976
25154
  };
24977
25155
  }
@@ -24979,7 +25157,8 @@ var recordVersion = defineOperation({
24979
25157
  async function readVersion(ctx, object, id2, version) {
24980
25158
  const which = version === void 0 ? sql`current = 1` : sql`version = ${version}`;
24981
25159
  const rows = await sql`
24982
- SELECT version, current, content, bytes, published_at, published_by, note
25160
+ SELECT version, current, content, bytes, published_at, published_by, requested_by,
25161
+ requested_via, note
24983
25162
  FROM core_publish_version WHERE object_type = ${object} AND record_id = ${id2} AND ${which}
24984
25163
  `.execute(ctx.db);
24985
25164
  const row = rows.rows[0];
@@ -2,9 +2,9 @@
2
2
  import {
3
3
  productContract,
4
4
  renderClient
5
- } from "./chunk-2P4AZTFL.js";
6
- import "./chunk-BEKL3CA2.js";
7
- import "./chunk-MINQ46RU.js";
5
+ } from "./chunk-KTXGEXTY.js";
6
+ import "./chunk-XDDBLYKW.js";
7
+ import "./chunk-LTQDLCP7.js";
8
8
  import "./chunk-ZRWF6QZS.js";
9
9
  import "./chunk-6UWRT4VM.js";
10
10
  import "./chunk-MAXLUQKB.js";
package/dist/cli.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  Redactor,
8
8
  runCli,
9
9
  terminalIo
10
- } from "./chunk-Y7PQ7NIL.js";
10
+ } from "./chunk-G3ORKXVP.js";
11
11
  import "./chunk-ZRWF6QZS.js";
12
12
  import "./chunk-2ABSVMGB.js";
13
13
  import "./chunk-6UWRT4VM.js";
@@ -22,8 +22,8 @@ import {
22
22
  upgradeRepo,
23
23
  withEnvBinding,
24
24
  withTsExtensions
25
- } from "./chunk-VL62IMBN.js";
26
- import "./chunk-Y7PQ7NIL.js";
25
+ } from "./chunk-KOKYDJ7Z.js";
26
+ import "./chunk-G3ORKXVP.js";
27
27
  import "./chunk-ZRWF6QZS.js";
28
28
  import "./chunk-2ABSVMGB.js";
29
29
  import "./chunk-6UWRT4VM.js";
package/dist/create.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  Redactor,
8
8
  runCli,
9
9
  terminalIo
10
- } from "./chunk-Y7PQ7NIL.js";
10
+ } from "./chunk-G3ORKXVP.js";
11
11
  import "./chunk-ZRWF6QZS.js";
12
12
  import "./chunk-2ABSVMGB.js";
13
13
  import "./chunk-6UWRT4VM.js";
@@ -6,8 +6,8 @@ import {
6
6
  invoke,
7
7
  invokeByName,
8
8
  listOperations
9
- } from "./chunk-BEKL3CA2.js";
10
- import "./chunk-MINQ46RU.js";
9
+ } from "./chunk-XDDBLYKW.js";
10
+ import "./chunk-LTQDLCP7.js";
11
11
  import "./chunk-ZRWF6QZS.js";
12
12
  import "./chunk-6UWRT4VM.js";
13
13
  import "./chunk-MAXLUQKB.js";
@@ -22,7 +22,7 @@ import {
22
22
  phoneInputSchema,
23
23
  socialProfileSchema,
24
24
  updatePerson
25
- } from "./chunk-MINQ46RU.js";
25
+ } from "./chunk-LTQDLCP7.js";
26
26
  import "./chunk-6UWRT4VM.js";
27
27
  import {
28
28
  TRASH_RETENTION_DAYS
@@ -0,0 +1,20 @@
1
+ -- An AI actor asks for a publish (ADR 0480, stage 28 criterion 12): its request waits for a
2
+ -- person, and the version history says who asked and who approved.
3
+ --
4
+ -- A version published by approving a request keeps the person who approved it in `published_by`
5
+ -- (or `scheduled_by`), and the request beside it: `requested_by`, the staff user the AI actor
6
+ -- acted for, and `requested_via`, the actor (assistant, mcp, automation, extension). A person's
7
+ -- own publish leaves both empty. A scheduled publish carries them to the version the minute cron
8
+ -- publishes. Only packages/core/src/records/publish.ts writes either table.
9
+ ALTER TABLE core_publish_version ADD COLUMN requested_by TEXT;
10
+ ALTER TABLE core_publish_version ADD COLUMN requested_via TEXT
11
+ CHECK (requested_via IS NULL OR requested_via IN ('human', 'assistant', 'mcp', 'automation', 'extension'));
12
+ ALTER TABLE core_publish_schedule ADD COLUMN requested_by TEXT;
13
+ ALTER TABLE core_publish_schedule ADD COLUMN requested_via TEXT
14
+ CHECK (requested_via IS NULL OR requested_via IN ('human', 'assistant', 'mcp', 'automation', 'extension'));
15
+
16
+ DROP VIEW rec_publish_version;
17
+ CREATE VIEW rec_publish_version AS
18
+ SELECT object_type, record_id, version, current, bytes, published_at, published_by, note,
19
+ requested_by, requested_via
20
+ FROM core_publish_version;
@@ -8,9 +8,9 @@ import {
8
8
  renderEntry,
9
9
  renderRoleClient,
10
10
  schemaToTs
11
- } from "./chunk-2P4AZTFL.js";
12
- import "./chunk-BEKL3CA2.js";
13
- import "./chunk-MINQ46RU.js";
11
+ } from "./chunk-KTXGEXTY.js";
12
+ import "./chunk-XDDBLYKW.js";
13
+ import "./chunk-LTQDLCP7.js";
14
14
  import "./chunk-ZRWF6QZS.js";
15
15
  import "./chunk-6UWRT4VM.js";
16
16
  import "./chunk-MAXLUQKB.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@composable-os/cli",
3
- "version": "0.1.0-beta.7",
3
+ "version": "0.1.0-beta.8",
4
4
  "license": "FSL-1.1-ALv2",
5
5
  "type": "module",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  "dependencies": {
30
30
  "esbuild": "0.28.2",
31
31
  "typescript": "6.0.3",
32
- "@composable-os/sdk": "0.1.0-beta.7",
32
+ "@composable-os/sdk": "0.1.0-beta.8",
33
33
  "zod": "4.6.7"
34
34
  }
35
35
  }