@codemem/core 0.41.0 → 0.42.0

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.
Files changed (53) hide show
  1. package/dist/api-types.d.ts +14 -0
  2. package/dist/api-types.d.ts.map +1 -1
  3. package/dist/claude-hooks.d.ts +12 -4
  4. package/dist/claude-hooks.d.ts.map +1 -1
  5. package/dist/codex-hooks.d.ts +7 -3
  6. package/dist/codex-hooks.d.ts.map +1 -1
  7. package/dist/coordinator-actions.d.ts.map +1 -1
  8. package/dist/{coordinator-api-Bxw5Q3py.js → coordinator-api-SeLosPIq.js} +489 -459
  9. package/dist/coordinator-api-SeLosPIq.js.map +1 -0
  10. package/dist/coordinator-api.d.ts.map +1 -1
  11. package/dist/db.d.ts +2 -0
  12. package/dist/db.d.ts.map +1 -1
  13. package/dist/device-identity-binding.d.ts +50 -0
  14. package/dist/device-identity-binding.d.ts.map +1 -0
  15. package/dist/device-identity-inventory.d.ts +72 -0
  16. package/dist/device-identity-inventory.d.ts.map +1 -0
  17. package/dist/hook-transcript.d.ts +25 -0
  18. package/dist/hook-transcript.d.ts.map +1 -0
  19. package/dist/identity-target.d.ts +16 -0
  20. package/dist/identity-target.d.ts.map +1 -0
  21. package/dist/index.d.ts +17 -7
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +8601 -7482
  24. package/dist/index.js.map +1 -1
  25. package/dist/internal/cloudflare-coordinator.js +149 -149
  26. package/dist/project-invite-identity.d.ts +2 -0
  27. package/dist/project-invite-identity.d.ts.map +1 -1
  28. package/dist/prompt-transport.d.ts +36 -0
  29. package/dist/prompt-transport.d.ts.map +1 -0
  30. package/dist/raw-event-flush.d.ts +1 -0
  31. package/dist/raw-event-flush.d.ts.map +1 -1
  32. package/dist/raw-event-ingest.d.ts +19 -0
  33. package/dist/raw-event-ingest.d.ts.map +1 -0
  34. package/dist/raw-event-sweeper.d.ts +6 -1
  35. package/dist/raw-event-sweeper.d.ts.map +1 -1
  36. package/dist/schema-bootstrap.d.ts +9 -0
  37. package/dist/schema-bootstrap.d.ts.map +1 -1
  38. package/dist/schema.d.ts +817 -0
  39. package/dist/schema.d.ts.map +1 -1
  40. package/dist/share-operation.d.ts.map +1 -1
  41. package/dist/store.d.ts +1 -1
  42. package/dist/store.d.ts.map +1 -1
  43. package/dist/sync-auth.d.ts +62 -2
  44. package/dist/sync-auth.d.ts.map +1 -1
  45. package/dist/sync-bootstrap.d.ts +2 -0
  46. package/dist/sync-bootstrap.d.ts.map +1 -1
  47. package/dist/sync-http-client.d.ts +1 -0
  48. package/dist/sync-http-client.d.ts.map +1 -1
  49. package/dist/sync-pass.d.ts.map +1 -1
  50. package/dist/test-schema.generated.d.ts +1 -1
  51. package/dist/test-schema.generated.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/dist/coordinator-api-Bxw5Q3py.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { B as e, D as t, H as n, I as r, L as i, R as a, U as o, V as s, W as c, j as l, k as u, n as d, t as f, w as p, z as m } from "../coordinator-api-Bxw5Q3py.js";
1
+ import { B as e, D as t, G as n, H as r, K as i, R as a, U as o, V as s, W as c, j as l, k as u, n as d, t as f, w as p, z as m } from "../coordinator-api-SeLosPIq.js";
2
2
  //#region src/d1-coordinator-store.ts
3
3
  function h(e) {
4
4
  if (e == null) throw Error("expected row");
@@ -143,7 +143,7 @@ async function A(e) {
143
143
  }
144
144
  async function j(e) {
145
145
  if (e.invite_kind === "team_member") {
146
- if (!e.policy_team_id || !r(e.assigned_identity_id) || !e.reviewed_preview_digest) throw Error("invite_invalid");
146
+ if (!e.policy_team_id || !a(e.assigned_identity_id) || !e.reviewed_preview_digest) throw Error("invite_invalid");
147
147
  let t = await u(e.reviewed_intent_json, {
148
148
  target: {
149
149
  kind: "team_member",
@@ -234,16 +234,16 @@ function L(e, t, n) {
234
234
  if (!r || !i) throw Error("scopeId and deviceId are required.");
235
235
  let a = k(e.coordinatorId), o = k(e.groupId);
236
236
  if (a && a !== t?.coordinator_id) throw Error("membership coordinatorId must match the scope coordinatorId.");
237
- if (o && o !== t?.group_id) throw new m("scope_group_mismatch");
238
- let s = e.membershipEpoch == null ? null : M(e.membershipEpoch), c = t?.membership_epoch ?? 0;
239
- if (s != null && s < c) throw Error("membershipEpoch must not be lower than the scope membershipEpoch.");
240
- if (s != null && n && s < (n.status === "revoked" ? n.membership_epoch + 1 : n.membership_epoch)) throw Error("membershipEpoch must not move backwards.");
241
- let l = s ?? (n ? Math.max(c, n.membership_epoch + +(n.status === "revoked")) : c);
237
+ if (o && o !== t?.group_id) throw new s("scope_group_mismatch");
238
+ let c = e.membershipEpoch == null ? null : M(e.membershipEpoch), l = t?.membership_epoch ?? 0;
239
+ if (c != null && c < l) throw Error("membershipEpoch must not be lower than the scope membershipEpoch.");
240
+ if (c != null && n && c < (n.status === "revoked" ? n.membership_epoch + 1 : n.membership_epoch)) throw Error("membershipEpoch must not move backwards.");
241
+ let u = c ?? (n ? Math.max(l, n.membership_epoch + +(n.status === "revoked")) : l);
242
242
  return {
243
243
  scopeId: r,
244
244
  deviceId: i,
245
245
  role: k(e.role) ?? "member",
246
- membershipEpoch: l,
246
+ membershipEpoch: u,
247
247
  coordinatorId: t?.coordinator_id ?? null,
248
248
  groupId: t?.group_id ?? null,
249
249
  manifestIssuerDeviceId: k(e.manifestIssuerDeviceId) ?? t?.manifest_issuer_device_id ?? null,
@@ -364,32 +364,32 @@ var Y = class {
364
364
  await this.db.prepare("DELETE FROM request_nonces WHERE created_at < ?").bind(e).run();
365
365
  }
366
366
  async createInvite(e) {
367
- let t = b(), n = C(12), r = C(24), a = await w(r), o = i(e.expiresAt), s = await this.getGroup(e.groupId), c = String(e.operationId ?? "").trim() || null, l = String(e.reviewedProjectSetDigest ?? "").trim() || null, u = await A(e), d = u.inviteKind === "team_member" ? `identity:${C(18)}` : null;
368
- if (!!c != !!l) throw Error("operationId and reviewedProjectSetDigest must be provided together.");
369
- let f = async () => {
370
- if (!c) return null;
371
- let t = await q(this.db.prepare(`SELECT ${T} FROM coordinator_invites WHERE operation_id = ?`).bind(c));
367
+ let t = b(), n = C(12), r = C(24), i = await w(r), a = m(e.expiresAt), o = await this.getGroup(e.groupId), s = String(e.operationId ?? "").trim() || null, c = String(e.reviewedProjectSetDigest ?? "").trim() || null, l = await A(e), u = l.inviteKind === "team_member" ? `identity:${C(18)}` : null;
368
+ if (!!s != !!c) throw Error("operationId and reviewedProjectSetDigest must be provided together.");
369
+ let d = async () => {
370
+ if (!s) return null;
371
+ let t = await q(this.db.prepare(`SELECT ${T} FROM coordinator_invites WHERE operation_id = ?`).bind(s));
372
372
  if (!t) return null;
373
373
  if (t.consumed_at) throw Error("invite_already_bound");
374
- if (t.group_id !== e.groupId || t.policy !== e.policy || t.invite_kind !== u.inviteKind || t.reviewed_project_set_digest !== l || t.inviter_actor_id !== (String(e.inviterActorId ?? "").trim() || null) || t.inviter_display_name !== (String(e.inviterDisplayName ?? "").trim() || null) || t.inviter_device_id !== (String(e.inviterDeviceId ?? "").trim() || null) || t.pending_person_id !== (String(e.pendingPersonId ?? "").trim() || null) || t.project_summaries_json !== (e.projectSummaries ? JSON.stringify(e.projectSummaries) : null) || t.project_intent_json !== (e.projectIntent ? JSON.stringify(e.projectIntent) : null) || t.policy_team_id !== u.policyTeamId || t.target_identity_id !== u.targetIdentityId || t.reviewed_preview_digest !== u.reviewedPreviewDigest || t.reviewed_intent_json !== u.reviewedIntentJson) throw Error("invite_operation_intent_conflict");
374
+ if (t.group_id !== e.groupId || t.policy !== e.policy || t.invite_kind !== l.inviteKind || t.reviewed_project_set_digest !== c || t.inviter_actor_id !== (String(e.inviterActorId ?? "").trim() || null) || t.inviter_display_name !== (String(e.inviterDisplayName ?? "").trim() || null) || t.inviter_device_id !== (String(e.inviterDeviceId ?? "").trim() || null) || t.pending_person_id !== (String(e.pendingPersonId ?? "").trim() || null) || t.project_summaries_json !== (e.projectSummaries ? JSON.stringify(e.projectSummaries) : null) || t.project_intent_json !== (e.projectIntent ? JSON.stringify(e.projectIntent) : null) || t.policy_team_id !== l.policyTeamId || t.target_identity_id !== l.targetIdentityId || t.reviewed_preview_digest !== l.reviewedPreviewDigest || t.reviewed_intent_json !== l.reviewedIntentJson) throw Error("invite_operation_intent_conflict");
375
375
  return h(t);
376
- }, p = async (n) => {
376
+ }, f = async (n) => {
377
377
  if (!n.revoked_at && n.expires_at > t) return n;
378
- await J(this.db.prepare("UPDATE coordinator_invites\n SET token = ?, token_digest = ?, expires_at = ?, created_at = ?, created_by = ?,\n team_name_snapshot = ?, revoked_at = NULL\n WHERE operation_id = ? AND token = ?\n AND (revoked_at IS NOT NULL OR expires_at <= ?)").bind(r, a, o, t, e.createdBy ?? null, s?.display_name ?? null, c, n.token, t));
379
- let i = await f();
380
- if (!i) throw Error("invite_operation_reissue_failed");
381
- return i;
378
+ await J(this.db.prepare("UPDATE coordinator_invites\n SET token = ?, token_digest = ?, expires_at = ?, created_at = ?, created_by = ?,\n team_name_snapshot = ?, revoked_at = NULL\n WHERE operation_id = ? AND token = ?\n AND (revoked_at IS NOT NULL OR expires_at <= ?)").bind(r, i, a, t, e.createdBy ?? null, o?.display_name ?? null, s, n.token, t));
379
+ let c = await d();
380
+ if (!c) throw Error("invite_operation_reissue_failed");
381
+ return c;
382
382
  };
383
- if (c) {
384
- let e = await f();
385
- if (e) return await p(e);
383
+ if (s) {
384
+ let e = await d();
385
+ if (e) return await f(e);
386
386
  }
387
387
  try {
388
- await this.db.prepare("INSERT INTO coordinator_invites(\n invite_id, group_id, token, policy, expires_at, created_at, created_by,\n team_name_snapshot, revoked_at, operation_id, reviewed_project_set_digest,\n token_digest, inviter_actor_id, inviter_display_name, inviter_device_id,\n pending_person_id, project_summaries_json, project_intent_json, trust_state,\n invite_kind, policy_team_id, target_identity_id, assigned_identity_id,\n reviewed_preview_digest, reviewed_intent_json\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").bind(n, e.groupId, r, e.policy, o, t, e.createdBy ?? null, s?.display_name ?? null, c, l, a, String(e.inviterActorId ?? "").trim() || null, String(e.inviterDisplayName ?? "").trim() || null, String(e.inviterDeviceId ?? "").trim() || null, String(e.pendingPersonId ?? "").trim() || null, e.projectSummaries ? JSON.stringify(e.projectSummaries) : null, e.projectIntent ? JSON.stringify(e.projectIntent) : null, c ? "pending" : null, u.inviteKind, u.policyTeamId, u.targetIdentityId, d, u.reviewedPreviewDigest, u.reviewedIntentJson).run();
388
+ await this.db.prepare("INSERT INTO coordinator_invites(\n invite_id, group_id, token, policy, expires_at, created_at, created_by,\n team_name_snapshot, revoked_at, operation_id, reviewed_project_set_digest,\n token_digest, inviter_actor_id, inviter_display_name, inviter_device_id,\n pending_person_id, project_summaries_json, project_intent_json, trust_state,\n invite_kind, policy_team_id, target_identity_id, assigned_identity_id,\n reviewed_preview_digest, reviewed_intent_json\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").bind(n, e.groupId, r, e.policy, a, t, e.createdBy ?? null, o?.display_name ?? null, s, c, i, String(e.inviterActorId ?? "").trim() || null, String(e.inviterDisplayName ?? "").trim() || null, String(e.inviterDeviceId ?? "").trim() || null, String(e.pendingPersonId ?? "").trim() || null, e.projectSummaries ? JSON.stringify(e.projectSummaries) : null, e.projectIntent ? JSON.stringify(e.projectIntent) : null, s ? "pending" : null, l.inviteKind, l.policyTeamId, l.targetIdentityId, u, l.reviewedPreviewDigest, l.reviewedIntentJson).run();
389
389
  } catch (e) {
390
- if (c) {
391
- let e = await f();
392
- if (e) return await p(e);
390
+ if (s) {
391
+ let e = await d();
392
+ if (e) return await f(e);
393
393
  }
394
394
  throw e;
395
395
  }
@@ -413,69 +413,69 @@ var Y = class {
413
413
  let n = await j(t);
414
414
  if (!n) return null;
415
415
  if (t.revoked_at) throw Error("invite_invalid");
416
- if (!t.consumed_at && new Date(t.expires_at) <= new Date(i(e.now))) throw Error("invite_expired");
416
+ if (!t.consumed_at && new Date(t.expires_at) <= new Date(m(e.now))) throw Error("invite_expired");
417
417
  let r = await this.getGroup(t.group_id);
418
418
  if (!r) throw Error("group_not_found");
419
419
  if (r.archived_at) throw Error("group_archived");
420
420
  return n;
421
421
  }
422
- async consumeRecipientInvite(e) {
423
- let t = i(e.now), n = e.recipientDisplayName ?? null, r = e.deviceDisplayName ?? null;
424
- if (!e.identityId || !e.deviceId || !e.publicKey || !e.fingerprint || e.identityId !== e.identityId.trim() || e.deviceId !== e.deviceId.trim() || e.identityId.length > 256 || e.deviceId.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e.identityId) || /[\p{Cc}\p{Cf}]/u.test(e.deviceId)) throw Error("invite_identity_conflict");
425
- let o = await w(e.token), s = await this.getInviteByTokenForInspection(e.token), c = s ? await j(s) : null;
426
- if (!s || !c || c.kind !== e.inviteKind || s.revoked_at) throw Error("invite_invalid");
427
- let l = await this.getGroup(s.group_id);
428
- if (!l) throw Error("group_not_found");
429
- if (l.archived_at) throw Error("group_archived");
430
- if (!s.consumed_at && new Date(s.expires_at) <= new Date(t)) throw Error("invite_expired");
431
- if (p(e.publicKey) !== e.fingerprint) throw Error("fingerprint_mismatch");
432
- let u = a(c);
433
- if (u !== e.identityId) throw Error("invite_identity_conflict");
434
- let d = s.bound_device_id === e.deviceId && s.bound_public_key === e.publicKey && s.bound_fingerprint === e.fingerprint;
435
- if (s.consumed_at && !d) throw Error("invite_already_bound");
436
- if (s.consumed_at && s.recipient_actor_id !== u) throw Error("invite_identity_conflict");
437
- let f = await q(this.db.prepare(`SELECT ${E}
438
- FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(s.group_id, e.deviceId));
439
- if (f && (f.public_key !== e.publicKey || f.fingerprint !== e.fingerprint || f.identity_id !== null && f.identity_id !== u)) throw Error("invite_identity_conflict");
440
- let m = 0, h = C(12);
441
- if (!s.consumed_at) {
422
+ async consumeRecipientInvite(t) {
423
+ let n = m(t.now), r = t.recipientDisplayName ?? null, i = t.deviceDisplayName ?? null;
424
+ if (!t.identityId || !t.deviceId || !t.publicKey || !t.fingerprint || t.identityId !== t.identityId.trim() || t.deviceId !== t.deviceId.trim() || t.identityId.length > 256 || t.deviceId.length > 256 || /[\p{Cc}\p{Cf}]/u.test(t.identityId) || /[\p{Cc}\p{Cf}]/u.test(t.deviceId)) throw Error("invite_identity_conflict");
425
+ let a = await w(t.token), o = await this.getInviteByTokenForInspection(t.token), s = o ? await j(o) : null;
426
+ if (!o || !s || s.kind !== t.inviteKind || o.revoked_at) throw Error("invite_invalid");
427
+ let c = await this.getGroup(o.group_id);
428
+ if (!c) throw Error("group_not_found");
429
+ if (c.archived_at) throw Error("group_archived");
430
+ if (!o.consumed_at && new Date(o.expires_at) <= new Date(n)) throw Error("invite_expired");
431
+ if (p(t.publicKey) !== t.fingerprint) throw Error("fingerprint_mismatch");
432
+ let l = e(s);
433
+ if (l !== t.identityId) throw Error("invite_identity_conflict");
434
+ let u = o.bound_device_id === t.deviceId && o.bound_public_key === t.publicKey && o.bound_fingerprint === t.fingerprint;
435
+ if (o.consumed_at && !u) throw Error("invite_already_bound");
436
+ if (o.consumed_at && o.recipient_actor_id !== l) throw Error("invite_identity_conflict");
437
+ let d = await q(this.db.prepare(`SELECT ${E}
438
+ FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(o.group_id, t.deviceId));
439
+ if (d && (d.public_key !== t.publicKey || d.fingerprint !== t.fingerprint || d.identity_id !== null && d.identity_id !== l)) throw Error("invite_identity_conflict");
440
+ let f = 0, h = C(12);
441
+ if (!o.consumed_at) {
442
442
  if (!this.db.batch) throw Error("D1 batch support is required for atomic invite consume.");
443
- m = W((await this.db.batch([
444
- this.db.prepare("UPDATE coordinator_invites SET token = ?, consumed_at = ?, bound_device_id = ?,\n bound_public_key = ?, bound_fingerprint = ?, recipient_actor_id = ?,\n recipient_display_name = ?, recipient_device_display_name = ?\n WHERE (token_digest = ? OR token = ?) AND consumed_at IS NULL\n AND revoked_at IS NULL AND expires_at > ? AND invite_kind = ?\n AND reviewed_intent_json = ? AND reviewed_preview_digest = ?\n AND ((invite_kind = 'team_member' AND assigned_identity_id = ?)\n OR (invite_kind = 'add_device' AND target_identity_id = ?))\n AND NOT EXISTS (\n SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id AND e.device_id = ?\n AND (e.public_key <> ? OR e.fingerprint <> ?\n OR (e.identity_id IS NOT NULL AND e.identity_id <> ?))\n )\n AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id\n AND g.archived_at IS NULL)").bind(`consumed:${s.invite_id}`, t, e.deviceId, e.publicKey, e.fingerprint, u, n, r, o, e.token, t, e.inviteKind, s.reviewed_intent_json, s.reviewed_preview_digest, u, u, e.deviceId, e.publicKey, e.fingerprint, u),
445
- this.db.prepare("INSERT INTO enrolled_devices(\n group_id, device_id, public_key, fingerprint, identity_id, display_name, enabled, created_at\n ) SELECT i.group_id, i.bound_device_id, i.bound_public_key, i.bound_fingerprint,\n i.recipient_actor_id, i.recipient_device_display_name, 1, ? FROM coordinator_invites i\n JOIN groups g ON g.group_id = i.group_id AND g.archived_at IS NULL\n WHERE (i.token_digest = ? OR i.token = ?) AND i.bound_device_id = ?\n AND i.bound_public_key = ? AND i.bound_fingerprint = ?\n AND i.recipient_actor_id = ?\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n identity_id = COALESCE(enrolled_devices.identity_id, excluded.identity_id),\n display_name = COALESCE(enrolled_devices.display_name, excluded.display_name),\n enabled = 1\n WHERE enrolled_devices.identity_id IS NULL\n OR enrolled_devices.identity_id = excluded.identity_id").bind(t, o, e.token, e.deviceId, e.publicKey, e.fingerprint, u),
446
- this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE (token_digest = ? OR token = ?) AND invite_kind = 'add_device'\n AND bootstrap_grant_id IS NULL AND inviter_device_id IS NOT NULL\n AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(h, o, e.token, t),
447
- this.db.prepare("INSERT OR IGNORE INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at,\n created_at, created_by, revoked_at\n ) SELECT i.bootstrap_grant_id, i.group_id, i.inviter_device_id, i.bound_device_id,\n i.expires_at, ?, i.recipient_actor_id, NULL FROM coordinator_invites i\n JOIN enrolled_devices e ON e.group_id = i.group_id\n AND e.device_id = i.inviter_device_id AND e.enabled = 1\n WHERE (i.token_digest = ? OR i.token = ?) AND i.invite_kind = 'add_device'\n AND i.bootstrap_grant_id IS NOT NULL AND i.bound_device_id = ?").bind(t, o, e.token, e.deviceId)
443
+ f = W((await this.db.batch([
444
+ this.db.prepare("UPDATE coordinator_invites SET token = ?, consumed_at = ?, bound_device_id = ?,\n bound_public_key = ?, bound_fingerprint = ?, recipient_actor_id = ?,\n recipient_display_name = ?, recipient_device_display_name = ?\n WHERE (token_digest = ? OR token = ?) AND consumed_at IS NULL\n AND revoked_at IS NULL AND expires_at > ? AND invite_kind = ?\n AND reviewed_intent_json = ? AND reviewed_preview_digest = ?\n AND ((invite_kind = 'team_member' AND assigned_identity_id = ?)\n OR (invite_kind = 'add_device' AND target_identity_id = ?))\n AND NOT EXISTS (\n SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id AND e.device_id = ?\n AND (e.public_key <> ? OR e.fingerprint <> ?\n OR (e.identity_id IS NOT NULL AND e.identity_id <> ?))\n )\n AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id\n AND g.archived_at IS NULL)").bind(`consumed:${o.invite_id}`, n, t.deviceId, t.publicKey, t.fingerprint, l, r, i, a, t.token, n, t.inviteKind, o.reviewed_intent_json, o.reviewed_preview_digest, l, l, t.deviceId, t.publicKey, t.fingerprint, l),
445
+ this.db.prepare("INSERT INTO enrolled_devices(\n group_id, device_id, public_key, fingerprint, identity_id, display_name, enabled, created_at\n ) SELECT i.group_id, i.bound_device_id, i.bound_public_key, i.bound_fingerprint,\n i.recipient_actor_id, i.recipient_device_display_name, 1, ? FROM coordinator_invites i\n JOIN groups g ON g.group_id = i.group_id AND g.archived_at IS NULL\n WHERE (i.token_digest = ? OR i.token = ?) AND i.bound_device_id = ?\n AND i.bound_public_key = ? AND i.bound_fingerprint = ?\n AND i.recipient_actor_id = ?\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n identity_id = COALESCE(enrolled_devices.identity_id, excluded.identity_id),\n display_name = COALESCE(enrolled_devices.display_name, excluded.display_name),\n enabled = 1\n WHERE enrolled_devices.identity_id IS NULL\n OR enrolled_devices.identity_id = excluded.identity_id").bind(n, a, t.token, t.deviceId, t.publicKey, t.fingerprint, l),
446
+ this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE (token_digest = ? OR token = ?) AND invite_kind = 'add_device'\n AND bootstrap_grant_id IS NULL AND inviter_device_id IS NOT NULL\n AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(h, a, t.token, n),
447
+ this.db.prepare("INSERT OR IGNORE INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at,\n created_at, created_by, revoked_at\n ) SELECT i.bootstrap_grant_id, i.group_id, i.inviter_device_id, i.bound_device_id,\n i.expires_at, ?, i.recipient_actor_id, NULL FROM coordinator_invites i\n JOIN enrolled_devices e ON e.group_id = i.group_id\n AND e.device_id = i.inviter_device_id AND e.enabled = 1\n WHERE (i.token_digest = ? OR i.token = ?) AND i.invite_kind = 'add_device'\n AND i.bootstrap_grant_id IS NOT NULL AND i.bound_device_id = ?").bind(n, a, t.token, t.deviceId)
448
448
  ]))[0]);
449
449
  }
450
- let g = await this.getGroup(s.group_id);
450
+ let g = await this.getGroup(o.group_id);
451
451
  if (!g) throw Error("group_not_found");
452
452
  if (g.archived_at) throw Error("group_archived");
453
453
  let _ = await q(this.db.prepare(`SELECT ${E}
454
- FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(s.group_id, e.deviceId));
455
- if (_ && (_.public_key !== e.publicKey || _.fingerprint !== e.fingerprint || _.identity_id !== null && _.identity_id !== u)) throw Error("invite_identity_conflict");
456
- let v = await this.getInviteByTokenForInspection(e.token);
457
- if (!v || v.revoked_at || !v.consumed_at && new Date(v.expires_at) <= new Date(t)) throw Error("invite_invalid");
454
+ FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(o.group_id, t.deviceId));
455
+ if (_ && (_.public_key !== t.publicKey || _.fingerprint !== t.fingerprint || _.identity_id !== null && _.identity_id !== l)) throw Error("invite_identity_conflict");
456
+ let v = await this.getInviteByTokenForInspection(t.token);
457
+ if (!v || v.revoked_at || !v.consumed_at && new Date(v.expires_at) <= new Date(n)) throw Error("invite_invalid");
458
458
  let y = await j(v);
459
- if (!y || y.kind !== e.inviteKind) throw Error("invite_invalid");
460
- if (a(y) !== u) throw Error("invite_identity_conflict");
461
- if (v.bound_device_id !== e.deviceId || v.bound_public_key !== e.publicKey || v.bound_fingerprint !== e.fingerprint) throw Error("invite_already_bound");
462
- if (v.recipient_actor_id !== u) throw Error("invite_identity_conflict");
463
- await this.db.prepare("UPDATE enrolled_devices SET identity_id = ?\n WHERE group_id = ? AND device_id = ? AND identity_id IS NULL\n AND public_key = ? AND fingerprint = ?").bind(u, v.group_id, e.deviceId, e.publicKey, e.fingerprint).run();
464
- let b = await this.getEnrollment(v.group_id, e.deviceId);
459
+ if (!y || y.kind !== t.inviteKind) throw Error("invite_invalid");
460
+ if (e(y) !== l) throw Error("invite_identity_conflict");
461
+ if (v.bound_device_id !== t.deviceId || v.bound_public_key !== t.publicKey || v.bound_fingerprint !== t.fingerprint) throw Error("invite_already_bound");
462
+ if (v.recipient_actor_id !== l) throw Error("invite_identity_conflict");
463
+ await this.db.prepare("UPDATE enrolled_devices SET identity_id = ?\n WHERE group_id = ? AND device_id = ? AND identity_id IS NULL\n AND public_key = ? AND fingerprint = ?").bind(l, v.group_id, t.deviceId, t.publicKey, t.fingerprint).run();
464
+ let b = await this.getEnrollment(v.group_id, t.deviceId);
465
465
  if (!b) throw Error("invite_acceptance_incomplete");
466
- if (b.public_key !== e.publicKey || b.fingerprint !== e.fingerprint || b.identity_id !== u) throw Error("invite_identity_conflict");
466
+ if (b.public_key !== t.publicKey || b.fingerprint !== t.fingerprint || b.identity_id !== l) throw Error("invite_identity_conflict");
467
467
  let x = v;
468
- if (y.kind === "add_device" && v.inviter_device_id && !v.bootstrap_grant_id && new Date(v.expires_at) > new Date(t)) {
468
+ if (y.kind === "add_device" && v.inviter_device_id && !v.bootstrap_grant_id && new Date(v.expires_at) > new Date(n)) {
469
469
  if (!this.db.batch) throw Error("D1 batch support is required for atomic bootstrap grant recovery.");
470
- let n = C(12);
471
- await this.db.batch([this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE invite_id = ? AND invite_kind = 'add_device'\n AND bootstrap_grant_id IS NULL AND inviter_device_id IS NOT NULL\n AND bound_device_id = ? AND recipient_actor_id = ? AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(n, v.invite_id, e.deviceId, u, t), this.db.prepare("INSERT OR IGNORE INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at,\n created_at, created_by, revoked_at\n ) SELECT i.bootstrap_grant_id, i.group_id, i.inviter_device_id, i.bound_device_id,\n i.expires_at, ?, i.recipient_actor_id, NULL FROM coordinator_invites i\n JOIN enrolled_devices e ON e.group_id = i.group_id\n AND e.device_id = i.inviter_device_id AND e.enabled = 1\n WHERE i.invite_id = ? AND i.invite_kind = 'add_device'\n AND i.bootstrap_grant_id IS NOT NULL AND i.bound_device_id = ?").bind(t, v.invite_id, e.deviceId)]);
472
- let r = await this.getInviteByTokenForInspection(e.token);
470
+ let e = C(12);
471
+ await this.db.batch([this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE invite_id = ? AND invite_kind = 'add_device'\n AND bootstrap_grant_id IS NULL AND inviter_device_id IS NOT NULL\n AND bound_device_id = ? AND recipient_actor_id = ? AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e\n WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(e, v.invite_id, t.deviceId, l, n), this.db.prepare("INSERT OR IGNORE INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at,\n created_at, created_by, revoked_at\n ) SELECT i.bootstrap_grant_id, i.group_id, i.inviter_device_id, i.bound_device_id,\n i.expires_at, ?, i.recipient_actor_id, NULL FROM coordinator_invites i\n JOIN enrolled_devices e ON e.group_id = i.group_id\n AND e.device_id = i.inviter_device_id AND e.enabled = 1\n WHERE i.invite_id = ? AND i.invite_kind = 'add_device'\n AND i.bootstrap_grant_id IS NOT NULL AND i.bound_device_id = ?").bind(n, v.invite_id, t.deviceId)]);
472
+ let r = await this.getInviteByTokenForInspection(t.token);
473
473
  if (!r) throw Error("invite_invalid");
474
474
  x = r;
475
475
  }
476
476
  let S = x.bootstrap_grant_id ? await this.getBootstrapGrant(x.bootstrap_grant_id) : null;
477
477
  return {
478
- status: m === 1 ? "accepted" : "existing",
478
+ status: f === 1 ? "accepted" : "existing",
479
479
  invite: x,
480
480
  reviewed_intent: y.reviewed_intent,
481
481
  bootstrap_grant: S
@@ -483,42 +483,42 @@ var Y = class {
483
483
  }
484
484
  async consumeProjectInvite(e) {
485
485
  if (!this.db.batch) throw Error("D1 batch support is required for atomic invite consume.");
486
- let t = i(e.now), n = await w(e.token), r = await this.getInviteByTokenForInspection(e.token);
486
+ let t = m(e.now), n = await w(e.token), r = await this.getInviteByTokenForInspection(e.token);
487
487
  if (!r?.operation_id || !r.project_intent_json || r.revoked_at) throw Error("invite_invalid");
488
- let a = await this.getGroup(r.group_id);
489
- if (!a) throw Error("group_not_found");
490
- if (a.archived_at) throw Error("group_archived");
488
+ let i = await this.getGroup(r.group_id);
489
+ if (!i) throw Error("group_not_found");
490
+ if (i.archived_at) throw Error("group_archived");
491
491
  if (r.operation_id !== e.operationId) throw Error("invite_invalid");
492
492
  if (p(e.publicKey) !== e.fingerprint) throw Error("fingerprint_mismatch");
493
493
  if (!r.consumed_at && new Date(r.expires_at) <= new Date(t)) throw Error("invite_expired");
494
- let o = r.bound_device_id === e.deviceId && r.bound_public_key === e.publicKey && r.bound_fingerprint === e.fingerprint;
495
- if (r.consumed_at && !o) throw Error("invite_already_bound");
494
+ let a = r.bound_device_id === e.deviceId && r.bound_public_key === e.publicKey && r.bound_fingerprint === e.fingerprint;
495
+ if (r.consumed_at && !a) throw Error("invite_already_bound");
496
496
  if (r.consumed_at && (r.recipient_actor_id !== e.recipientActorId || r.recipient_display_name !== e.recipientDisplayName || r.recipient_device_display_name !== e.deviceDisplayName)) throw Error("invite_identity_conflict");
497
- let s = await q(this.db.prepare(`SELECT ${E}
497
+ let o = await q(this.db.prepare(`SELECT ${E}
498
498
  FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(r.group_id, e.deviceId));
499
- if (s && (s.public_key !== e.publicKey || s.fingerprint !== e.fingerprint || s.identity_id != null && s.identity_id !== e.recipientActorId)) throw Error("invite_identity_conflict");
500
- let c = C(12), l = W((await this.db.batch([
499
+ if (o && (o.public_key !== e.publicKey || o.fingerprint !== e.fingerprint || o.identity_id != null && o.identity_id !== e.recipientActorId)) throw Error("invite_identity_conflict");
500
+ let s = C(12), c = W((await this.db.batch([
501
501
  this.db.prepare("UPDATE coordinator_invites SET token = ?, consumed_at = ?, bound_device_id = ?,\n bound_public_key = ?, bound_fingerprint = ?, recipient_actor_id = ?,\n recipient_display_name = ?, recipient_device_display_name = ?,\n trust_state = 'pending_inviter_device'\n WHERE (token_digest = ? OR token = ?) AND consumed_at IS NULL\n AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id\n AND g.archived_at IS NULL)").bind(`consumed:${r.invite_id}`, t, e.deviceId, e.publicKey, e.fingerprint, e.recipientActorId, e.recipientDisplayName, e.deviceDisplayName, n, e.token),
502
502
  this.db.prepare("INSERT INTO enrolled_devices(\n group_id, device_id, public_key, fingerprint, identity_id, display_name, enabled, created_at\n ) SELECT i.group_id, i.bound_device_id, i.bound_public_key, i.bound_fingerprint,\n i.recipient_actor_id, i.recipient_device_display_name, 1, ? FROM coordinator_invites i\n JOIN groups g ON g.group_id = i.group_id AND g.archived_at IS NULL\n WHERE (i.token_digest = ? OR i.token = ?) AND i.bound_device_id = ? AND ? = 1\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n identity_id = COALESCE(enrolled_devices.identity_id, excluded.identity_id),\n display_name = excluded.display_name, enabled = 1\n WHERE enrolled_devices.identity_id IS NULL\n OR enrolled_devices.identity_id = excluded.identity_id").bind(t, n, e.token, e.deviceId, +!r.consumed_at),
503
- this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE (token_digest = ? OR token = ?) AND bootstrap_grant_id IS NULL\n AND bound_device_id = ?\n AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id\n AND g.archived_at IS NULL)\n AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(c, n, e.token, e.deviceId, t),
503
+ this.db.prepare("UPDATE coordinator_invites SET bootstrap_grant_id = ?,\n trust_state = 'bootstrap_grant_created'\n WHERE (token_digest = ? OR token = ?) AND bootstrap_grant_id IS NULL\n AND bound_device_id = ?\n AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id\n AND g.archived_at IS NULL)\n AND expires_at > ?\n AND EXISTS (SELECT 1 FROM enrolled_devices e WHERE e.group_id = coordinator_invites.group_id\n AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)").bind(s, n, e.token, e.deviceId, t),
504
504
  this.db.prepare("INSERT OR IGNORE INTO coordinator_bootstrap_grants(\n grant_id, group_id, seed_device_id, worker_device_id, expires_at, created_at,\n created_by, revoked_at\n ) SELECT i.bootstrap_grant_id, i.group_id, i.inviter_device_id, i.bound_device_id,\n i.expires_at, ?, i.inviter_actor_id, NULL FROM coordinator_invites i\n JOIN groups g ON g.group_id = i.group_id AND g.archived_at IS NULL\n JOIN enrolled_devices e ON e.group_id = i.group_id AND e.device_id = i.inviter_device_id\n WHERE (i.token_digest = ? OR i.token = ?) AND i.bootstrap_grant_id IS NOT NULL\n AND i.bound_device_id = ? AND e.enabled = 1").bind(t, n, e.token, e.deviceId)
505
- ]))[0]) === 1, u = await this.getGroup(r.group_id);
506
- if (!u) throw Error("group_not_found");
507
- if (u.archived_at) throw Error("group_archived");
508
- let d = await this.getInviteByTokenForInspection(e.token);
509
- if (!d) throw Error("invite_invalid");
510
- if (d.bound_device_id !== e.deviceId || d.bound_public_key !== e.publicKey || d.bound_fingerprint !== e.fingerprint) throw Error("invite_already_bound");
511
- if (d.recipient_actor_id !== e.recipientActorId || d.recipient_display_name !== e.recipientDisplayName || d.recipient_device_display_name !== e.deviceDisplayName) throw Error("invite_identity_conflict");
512
- l || await this.db.prepare("UPDATE enrolled_devices SET identity_id = ?\n WHERE group_id = ? AND device_id = ? AND identity_id IS NULL AND enabled = 1\n AND public_key = ? AND fingerprint = ?").bind(e.recipientActorId, d.group_id, e.deviceId, e.publicKey, e.fingerprint).run();
513
- let f = await this.getEnrollment(d.group_id, e.deviceId);
514
- if (!f) throw Error("invite_acceptance_incomplete");
515
- if (f.identity_id !== e.recipientActorId) throw Error("invite_identity_conflict");
516
- let m = d.inviter_device_id ? await this.getEnrollment(d.group_id, d.inviter_device_id) : null, h = d.bootstrap_grant_id ? await this.getBootstrapGrant(d.bootstrap_grant_id) : null;
505
+ ]))[0]) === 1, l = await this.getGroup(r.group_id);
506
+ if (!l) throw Error("group_not_found");
507
+ if (l.archived_at) throw Error("group_archived");
508
+ let u = await this.getInviteByTokenForInspection(e.token);
509
+ if (!u) throw Error("invite_invalid");
510
+ if (u.bound_device_id !== e.deviceId || u.bound_public_key !== e.publicKey || u.bound_fingerprint !== e.fingerprint) throw Error("invite_already_bound");
511
+ if (u.recipient_actor_id !== e.recipientActorId || u.recipient_display_name !== e.recipientDisplayName || u.recipient_device_display_name !== e.deviceDisplayName) throw Error("invite_identity_conflict");
512
+ c || await this.db.prepare("UPDATE enrolled_devices SET identity_id = ?\n WHERE group_id = ? AND device_id = ? AND identity_id IS NULL AND enabled = 1\n AND public_key = ? AND fingerprint = ?").bind(e.recipientActorId, u.group_id, e.deviceId, e.publicKey, e.fingerprint).run();
513
+ let d = await this.getEnrollment(u.group_id, e.deviceId);
514
+ if (!d) throw Error("invite_acceptance_incomplete");
515
+ if (d.identity_id !== e.recipientActorId) throw Error("invite_identity_conflict");
516
+ let f = u.inviter_device_id ? await this.getEnrollment(u.group_id, u.inviter_device_id) : null, h = u.bootstrap_grant_id ? await this.getBootstrapGrant(u.bootstrap_grant_id) : null;
517
517
  return {
518
- status: l ? "accepted" : "existing",
519
- invite: d,
520
- enrollment: f,
521
- seed_enrollment: m,
518
+ status: c ? "accepted" : "existing",
519
+ invite: u,
520
+ enrollment: d,
521
+ seed_enrollment: f,
522
522
  bootstrap_grant: h
523
523
  };
524
524
  }
@@ -651,71 +651,71 @@ var Y = class {
651
651
  ORDER BY coordinator_id ASC, group_id ASC, scope_id ASC`);
652
652
  return (await K(n.length ? s.bind(...n) : s)).map((e) => h(e));
653
653
  }
654
- async grantScopeMembership(t) {
655
- let r = o(t.effectId), i = s(t), a = await B(this.db, r);
656
- if (a) return e(a, "grant", i), n(a);
657
- let c = k(t.scopeId), l = k(t.deviceId), u = c ? await this.getScope(c) : null;
658
- if (!u) throw new m("scope_not_found");
659
- if (u.status !== "active") throw new m("scope_inactive");
660
- let d = c && l ? await this.getScopeMembership(c, l) : null, f = L(t, u, d);
661
- if (f.groupId && !await this.getEnrollment(f.groupId, f.deviceId)) throw new m("device_not_enrolled");
662
- let p = b();
654
+ async grantScopeMembership(e) {
655
+ let t = n(e.effectId), i = o(e), a = await B(this.db, t);
656
+ if (a) return r(a, "grant", i), c(a);
657
+ let l = k(e.scopeId), u = k(e.deviceId), d = l ? await this.getScope(l) : null;
658
+ if (!d) throw new s("scope_not_found");
659
+ if (d.status !== "active") throw new s("scope_inactive");
660
+ let f = l && u ? await this.getScopeMembership(l, u) : null, p = L(e, d, f);
661
+ if (p.groupId && !await this.getEnrollment(p.groupId, p.deviceId)) throw new s("device_not_enrolled");
662
+ let m = b();
663
663
  await U(this.db, [
664
- this.db.prepare("INSERT INTO coordinator_scope_memberships(\n scope_id, device_id, role, status, membership_epoch, coordinator_id, group_id,\n manifest_issuer_device_id, manifest_hash, signed_manifest_json, updated_at\n ) SELECT ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?\n WHERE NOT EXISTS (\n SELECT 1 FROM coordinator_scope_membership_effect_receipts WHERE effect_id = ?\n )\n ON CONFLICT(scope_id, device_id) DO UPDATE SET\n role = excluded.role,\n status = 'active',\n membership_epoch = excluded.membership_epoch,\n coordinator_id = excluded.coordinator_id,\n group_id = excluded.group_id,\n manifest_issuer_device_id = excluded.manifest_issuer_device_id,\n manifest_hash = excluded.manifest_hash,\n signed_manifest_json = excluded.signed_manifest_json,\n updated_at = excluded.updated_at\n WHERE excluded.membership_epoch > coordinator_scope_memberships.membership_epoch\n OR (\n excluded.membership_epoch = coordinator_scope_memberships.membership_epoch\n AND coordinator_scope_memberships.status != 'revoked'\n )").bind(f.scopeId, f.deviceId, f.role, f.membershipEpoch, f.coordinatorId, f.groupId, f.manifestIssuerDeviceId, f.manifestHash, f.signedManifestJson, p, r),
664
+ this.db.prepare("INSERT INTO coordinator_scope_memberships(\n scope_id, device_id, role, status, membership_epoch, coordinator_id, group_id,\n manifest_issuer_device_id, manifest_hash, signed_manifest_json, updated_at\n ) SELECT ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?\n WHERE NOT EXISTS (\n SELECT 1 FROM coordinator_scope_membership_effect_receipts WHERE effect_id = ?\n )\n ON CONFLICT(scope_id, device_id) DO UPDATE SET\n role = excluded.role,\n status = 'active',\n membership_epoch = excluded.membership_epoch,\n coordinator_id = excluded.coordinator_id,\n group_id = excluded.group_id,\n manifest_issuer_device_id = excluded.manifest_issuer_device_id,\n manifest_hash = excluded.manifest_hash,\n signed_manifest_json = excluded.signed_manifest_json,\n updated_at = excluded.updated_at\n WHERE excluded.membership_epoch > coordinator_scope_memberships.membership_epoch\n OR (\n excluded.membership_epoch = coordinator_scope_memberships.membership_epoch\n AND coordinator_scope_memberships.status != 'revoked'\n )").bind(p.scopeId, p.deviceId, p.role, p.membershipEpoch, p.coordinatorId, p.groupId, p.manifestIssuerDeviceId, p.manifestHash, p.signedManifestJson, m, t),
665
665
  V(this.db, {
666
- effectId: r,
666
+ effectId: t,
667
667
  requestJson: i,
668
- scopeId: f.scopeId,
669
- deviceId: f.deviceId,
670
- createdAt: p
668
+ scopeId: p.scopeId,
669
+ deviceId: p.deviceId,
670
+ createdAt: m
671
671
  }),
672
672
  z(this.db, {
673
- effectId: r,
673
+ effectId: t,
674
674
  requestJson: i,
675
675
  action: "grant",
676
- previous: d,
677
- scopeId: f.scopeId,
678
- deviceId: f.deviceId,
676
+ previous: f,
677
+ scopeId: p.scopeId,
678
+ deviceId: p.deviceId,
679
679
  status: "active",
680
- membershipEpoch: f.membershipEpoch,
681
- updatedAt: p,
682
- actorType: f.actorType,
683
- actorId: f.actorId,
684
- createdAt: p
680
+ membershipEpoch: p.membershipEpoch,
681
+ updatedAt: m,
682
+ actorType: p.actorType,
683
+ actorId: p.actorId,
684
+ createdAt: m
685
685
  })
686
686
  ]);
687
- let h = await B(this.db, r);
687
+ let h = await B(this.db, t);
688
688
  if (!h) throw Error("scope membership grant was not applied.");
689
- return e(h, "grant", i), n(h);
690
- }
691
- async revokeScopeMembership(t) {
692
- let n = k(t.scopeId), r = k(t.deviceId);
693
- if (!n || !r) throw Error("scopeId and deviceId are required.");
694
- let i = o(t.effectId), a = c(t), s = await B(this.db, i);
695
- if (s) return e(s, "revoke", a), s.outcome_applied === 1;
696
- let l = t.membershipEpoch == null ? null : M(t.membershipEpoch), u = k(t.groupId), d = u ? await this.getScope(n) : null;
697
- if (u && u !== d?.group_id) throw new m("scope_group_mismatch");
698
- let f = await this.getScopeMembership(n, r);
699
- if (l != null && f && l <= f.membership_epoch) throw Error("membershipEpoch must increase on revoke.");
700
- let p = b(), h = l ?? (f?.membership_epoch ?? -1) + 1, g = this.db.prepare("UPDATE coordinator_scope_memberships\n SET status = 'revoked',\n membership_epoch = CASE WHEN ? IS NULL THEN membership_epoch + 1 ELSE ? END,\n manifest_hash = COALESCE(?, manifest_hash),\n signed_manifest_json = COALESCE(?, signed_manifest_json),\n updated_at = ?\n WHERE scope_id = ? AND device_id = ? AND membership_epoch = ? AND status = ?\n AND NOT EXISTS (\n SELECT 1 FROM coordinator_scope_membership_effect_receipts WHERE effect_id = ?\n )").bind(l, l, k(t.manifestHash), k(t.signedManifestJson), p, n, r, f?.membership_epoch ?? -1, f?.status ?? "", i), _ = H(this.db, {
701
- effectId: i,
702
- requestJson: a,
703
- scopeId: n,
704
- deviceId: r,
705
- createdAt: p
689
+ return r(h, "grant", i), c(h);
690
+ }
691
+ async revokeScopeMembership(e) {
692
+ let t = k(e.scopeId), a = k(e.deviceId);
693
+ if (!t || !a) throw Error("scopeId and deviceId are required.");
694
+ let o = n(e.effectId), c = i(e), l = await B(this.db, o);
695
+ if (l) return r(l, "revoke", c), l.outcome_applied === 1;
696
+ let u = e.membershipEpoch == null ? null : M(e.membershipEpoch), d = k(e.groupId), f = d ? await this.getScope(t) : null;
697
+ if (d && d !== f?.group_id) throw new s("scope_group_mismatch");
698
+ let p = await this.getScopeMembership(t, a);
699
+ if (u != null && p && u <= p.membership_epoch) throw Error("membershipEpoch must increase on revoke.");
700
+ let m = b(), h = u ?? (p?.membership_epoch ?? -1) + 1, g = this.db.prepare("UPDATE coordinator_scope_memberships\n SET status = 'revoked',\n membership_epoch = CASE WHEN ? IS NULL THEN membership_epoch + 1 ELSE ? END,\n manifest_hash = COALESCE(?, manifest_hash),\n signed_manifest_json = COALESCE(?, signed_manifest_json),\n updated_at = ?\n WHERE scope_id = ? AND device_id = ? AND membership_epoch = ? AND status = ?\n AND NOT EXISTS (\n SELECT 1 FROM coordinator_scope_membership_effect_receipts WHERE effect_id = ?\n )").bind(u, u, k(e.manifestHash), k(e.signedManifestJson), m, t, a, p?.membership_epoch ?? -1, p?.status ?? "", o), _ = H(this.db, {
701
+ effectId: o,
702
+ requestJson: c,
703
+ scopeId: t,
704
+ deviceId: a,
705
+ createdAt: m
706
706
  }), v = z(this.db, {
707
- effectId: i,
708
- requestJson: a,
707
+ effectId: o,
708
+ requestJson: c,
709
709
  action: "revoke",
710
- previous: f,
711
- scopeId: n,
712
- deviceId: r,
710
+ previous: p,
711
+ scopeId: t,
712
+ deviceId: a,
713
713
  status: "revoked",
714
714
  membershipEpoch: h,
715
- updatedAt: p,
716
- actorType: k(t.actorType),
717
- actorId: k(t.actorId),
718
- createdAt: p
715
+ updatedAt: m,
716
+ actorType: k(e.actorType),
717
+ actorId: k(e.actorId),
718
+ createdAt: m
719
719
  });
720
720
  try {
721
721
  await U(this.db, [
@@ -724,13 +724,13 @@ var Y = class {
724
724
  v
725
725
  ]);
726
726
  } catch (e) {
727
- let t = await this.getScopeMembership(n, r);
728
- if (f && (!t || t.membership_epoch !== f.membership_epoch || t.status !== f.status)) return !1;
727
+ let n = await this.getScopeMembership(t, a);
728
+ if (p && (!n || n.membership_epoch !== p.membership_epoch || n.status !== p.status)) return !1;
729
729
  throw e;
730
730
  }
731
- let y = await B(this.db, i);
731
+ let y = await B(this.db, o);
732
732
  if (!y) throw Error("scope membership revoke receipt was not persisted.");
733
- return e(y, "revoke", a), y.outcome_applied === 1;
733
+ return r(y, "revoke", c), y.outcome_applied === 1;
734
734
  }
735
735
  async listScopeMemberships(e, t = !1) {
736
736
  let n = k(e);
@@ -3,6 +3,8 @@ export interface ProjectInviteSummary {
3
3
  existing_memory_count: number;
4
4
  }
5
5
  export declare function normalizeIdentityDisplayName(value: string, field: string): string;
6
+ export declare function isHumanPresentationName(value: unknown): boolean;
7
+ export declare function normalizeHumanPresentationName(value: string, field: string): string;
6
8
  export declare function normalizeDeviceNameHint(value: string | null | undefined): string | null;
7
9
  export declare function friendlyDeviceName(input: {
8
10
  explicitName?: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"project-invite-identity.d.ts","sourceRoot":"","sources":["../src/project-invite-identity.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,qBAAqB,EAAE,MAAM,CAAC;CAC9B;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAUjF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAIvF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACzC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,GAAG,MAAM,CAST;AAED,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,EAAE,CAoBtF"}
1
+ {"version":3,"file":"project-invite-identity.d.ts","sourceRoot":"","sources":["../src/project-invite-identity.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,oBAAoB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,qBAAqB,EAAE,MAAM,CAAC;CAC9B;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAUjF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAe/D;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAInF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAIvF;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACzC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,GAAG,MAAM,CAmBT;AAED,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,EAAE,CAoBtF"}
@@ -0,0 +1,36 @@
1
+ export interface PromptTransportProtocolRange {
2
+ minSupportedProtocolVersion: number;
3
+ protocolVersion: number;
4
+ }
5
+ /** Current prompt-transport protocol range implemented by this release. */
6
+ export declare const PROMPT_TRANSPORT_PROTOCOL_RANGE: {
7
+ readonly minSupportedProtocolVersion: 1;
8
+ readonly protocolVersion: 1;
9
+ };
10
+ export type PromptTransportDisposition = "fallback" | "local_fallback" | "terminal";
11
+ export type PromptTransportFailure = {
12
+ kind: "profile_absent" | "profile_malformed" | "protocol_range_mismatch" | "network_unavailable" | "network_timeout" | "network_reset" | "viewer_restart" | "malformed_response";
13
+ } | {
14
+ kind: "database_mismatch" | "runtime_identity_mismatch";
15
+ } | {
16
+ kind: "invalid_request";
17
+ compatibleProfile: boolean;
18
+ } | {
19
+ kind: "policy_failure" | "authorization_failure";
20
+ } | {
21
+ kind: "viewer_contract_unsupported";
22
+ compatibleProfile: boolean;
23
+ };
24
+ /**
25
+ * Normalize a current/minimum pair into a closed supported range.
26
+ *
27
+ * A missing minimum is interpreted as an older single-version profile. Any
28
+ * explicitly malformed minimum remains invalid instead of being silently
29
+ * widened.
30
+ */
31
+ export declare function normalizePromptTransportProtocolRange(protocolVersion: unknown, minSupportedProtocolVersion?: unknown): PromptTransportProtocolRange | null;
32
+ /** Return true when two closed protocol-version ranges overlap. */
33
+ export declare function arePromptTransportProtocolRangesCompatible(left: PromptTransportProtocolRange, right: PromptTransportProtocolRange): boolean;
34
+ /** Classify whether a prompt transport failure may use local compatibility fallback. */
35
+ export declare function classifyPromptTransportFailure(failure: PromptTransportFailure): PromptTransportDisposition;
36
+ //# sourceMappingURL=prompt-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-transport.d.ts","sourceRoot":"","sources":["../src/prompt-transport.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,4BAA4B;IAC5C,2BAA2B,EAAE,MAAM,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC;CACxB;AAED,2EAA2E;AAC3E,eAAO,MAAM,+BAA+B;;;CAGK,CAAC;AAElD,MAAM,MAAM,0BAA0B,GAAG,UAAU,GAAG,gBAAgB,GAAG,UAAU,CAAC;AAEpF,MAAM,MAAM,sBAAsB,GAC/B;IACA,IAAI,EACD,gBAAgB,GAChB,mBAAmB,GACnB,yBAAyB,GACzB,qBAAqB,GACrB,iBAAiB,GACjB,eAAe,GACf,gBAAgB,GAChB,oBAAoB,CAAC;CACvB,GACD;IAAE,IAAI,EAAE,mBAAmB,GAAG,2BAA2B,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,iBAAiB,EAAE,OAAO,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,gBAAgB,GAAG,uBAAuB,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,6BAA6B,CAAC;IAAC,iBAAiB,EAAE,OAAO,CAAA;CAAE,CAAC;AAMvE;;;;;;GAMG;AACH,wBAAgB,qCAAqC,CACpD,eAAe,EAAE,OAAO,EACxB,2BAA2B,CAAC,EAAE,OAAO,GACnC,4BAA4B,GAAG,IAAI,CASrC;AAED,mEAAmE;AACnE,wBAAgB,0CAA0C,CACzD,IAAI,EAAE,4BAA4B,EAClC,KAAK,EAAE,4BAA4B,GACjC,OAAO,CAKT;AAED,wFAAwF;AACxF,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,sBAAsB,GAC7B,0BAA0B,CAe5B"}
@@ -24,6 +24,7 @@ export interface FlushRawEventsOptions {
24
24
  project?: string | null;
25
25
  startedAt?: string | null;
26
26
  maxEvents?: number | null;
27
+ throughEventSeq?: number | null;
27
28
  }
28
29
  /**
29
30
  * Flush raw events for a single session through the ingest pipeline.
@@ -1 +1 @@
1
- {"version":3,"file":"raw-event-flush.d.ts","sourceRoot":"","sources":["../src/raw-event-flush.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,sBAAsB,CAAC;AAElE,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAyD9C;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,cAAc,CA2FrF;AA0CD,MAAM,WAAW,qBAAqB;IACrC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CACnC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,aAAa,EACzB,IAAI,EAAE,qBAAqB,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CAyIpD"}
1
+ {"version":3,"file":"raw-event-flush.d.ts","sourceRoot":"","sources":["../src/raw-event-flush.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,KAAK,aAAa,EAAU,MAAM,sBAAsB,CAAC;AAElE,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAyD9C;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,cAAc,CA2FrF;AA0CD,MAAM,WAAW,qBAAqB;IACrC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CACnC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,aAAa,EACzB,IAAI,EAAE,qBAAqB,GACzB,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CA+IpD"}
@@ -0,0 +1,19 @@
1
+ import type { Database } from "./db.js";
2
+ export interface RawEventIngestStore {
3
+ db: Database;
4
+ }
5
+ export interface RawEventIngestSession {
6
+ source: string;
7
+ streamId: string;
8
+ }
9
+ export interface RawEventIngestResult {
10
+ inserted: number;
11
+ skipped: number;
12
+ received: number;
13
+ sessions: RawEventIngestSession[];
14
+ }
15
+ export declare class RawEventIngestValidationError extends Error {
16
+ constructor(message: string);
17
+ }
18
+ export declare function ingestRawEvents(store: RawEventIngestStore, request: object): RawEventIngestResult;
19
+ //# sourceMappingURL=raw-event-ingest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw-event-ingest.d.ts","sourceRoot":"","sources":["../src/raw-event-ingest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAcxC,MAAM,WAAW,mBAAmB;IACnC,EAAE,EAAE,QAAQ,CAAC;CACb;AAED,MAAM,WAAW,qBAAqB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,qBAAqB,EAAE,CAAC;CAClC;AAuBD,qBAAa,6BAA8B,SAAQ,KAAK;gBAC3C,OAAO,EAAE,MAAM;CAI3B;AA0VD,wBAAgB,eAAe,CAAC,KAAK,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,GAAG,oBAAoB,CAoCjG"}
@@ -21,12 +21,14 @@ export declare class RawEventSweeper {
21
21
  private store;
22
22
  private ingestOpts;
23
23
  private active;
24
+ private stopping;
24
25
  private running;
25
26
  private currentTick;
26
27
  private wakeHandle;
27
28
  private loopHandle;
28
29
  private autoFlushTimers;
29
- private sessionFlushing;
30
+ private sessionFlushPromises;
31
+ private sessionBoundaryWaiters;
30
32
  private autoFlushPending;
31
33
  private autoFlushPromises;
32
34
  private authBackoffUntil;
@@ -77,6 +79,9 @@ export declare class RawEventSweeper {
77
79
  * Mirrors Python's RawEventAutoFlusher.note_activity() behavior.
78
80
  */
79
81
  nudge(opencodeSessionId: string, source?: string): void;
82
+ /** Flush one session immediately through the event visible at this boundary. */
83
+ flushBoundary(opencodeSessionId: string, source?: string): Promise<void>;
84
+ private acquireSessionFlush;
80
85
  private trackAutoFlush;
81
86
  private scheduleAutoFlush;
82
87
  private flushNow;
@@ -1 +1 @@
1
- {"version":3,"file":"raw-event-sweeper.d.ts","sourceRoot":"","sources":["../src/raw-event-sweeper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA4B9C,qBAAa,eAAe;IAC3B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,eAAe,CAAoD;IAC3E,OAAO,CAAC,eAAe,CAAqB;IAC5C,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,iBAAiB,CAA4B;IACrD,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,eAAe,CAAS;gBAEpB,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa;IASzD,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,eAAe;IAYvB;;;OAGG;IACH,gBAAgB,IAAI,IAAI;IAMxB;;OAEG;IACH,iBAAiB,IAAI;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;IAU5D;;;;;;OAMG;IACH,KAAK,IAAI,IAAI;IAOb;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB3B;;;OAGG;IACH,mBAAmB,IAAI,IAAI;IAI3B;;;OAGG;IACH,KAAK,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,SAAa,GAAG,IAAI;IA0B3D,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,iBAAiB;YAqBX,QAAQ;IAwCtB,4DAA4D;IAC5D,OAAO,CAAC,YAAY;IAYpB,iDAAiD;YACnC,OAAO;IAgBrB,OAAO,CAAC,IAAI;IAmBZ;;;;;;;;OAQG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAkG3B"}
1
+ {"version":3,"file":"raw-event-sweeper.d.ts","sourceRoot":"","sources":["../src/raw-event-sweeper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA4B9C,qBAAa,eAAe;IAC3B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAA8B;IACjD,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,UAAU,CAA8C;IAChE,OAAO,CAAC,eAAe,CAAoD;IAC3E,OAAO,CAAC,oBAAoB,CAAoC;IAChE,OAAO,CAAC,sBAAsB,CAA6B;IAC3D,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,iBAAiB,CAA4B;IACrD,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,eAAe,CAAS;gBAEpB,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa;IASzD,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,UAAU;IAmBlB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,eAAe;IAYvB;;;OAGG;IACH,gBAAgB,IAAI,IAAI;IAMxB;;OAEG;IACH,iBAAiB,IAAI;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE;IAU5D;;;;;;OAMG;IACH,KAAK,IAAI,IAAI;IAQb;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB3B;;;OAGG;IACH,mBAAmB,IAAI,IAAI;IAI3B;;;OAGG;IACH,KAAK,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,SAAa,GAAG,IAAI;IA2B3D,gFAAgF;IAC1E,aAAa,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,SAAa,GAAG,OAAO,CAAC,IAAI,CAAC;YAqBpE,mBAAmB;IAwCjC,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,iBAAiB;YAsBX,QAAQ;IA6DtB,4DAA4D;IAC5D,OAAO,CAAC,YAAY;IAYpB,iDAAiD;YACnC,OAAO;IAgBrB,OAAO,CAAC,IAAI;IAmBZ;;;;;;;;OAQG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAkG3B"}
@@ -11,6 +11,15 @@ import type { Database } from "./db.js";
11
11
  */
12
12
  export declare function ensureVectorSchema(db: Database): void;
13
13
  export declare function bootstrapSchema(db: Database): void;
14
+ /** Add sticky direct-peer signature state without requiring a schema-version bump. */
15
+ export declare function ensureSyncPeerDirectSignatureVersionColumn(db: Database): void;
16
+ /**
17
+ * Keep signature downgrade protection outside deletable peer trust rows.
18
+ *
19
+ * The copy is advancing-only so this repair can run on every open, including
20
+ * databases whose compatibility marker was written before this table existed.
21
+ */
22
+ export declare function ensureSyncPeerSignatureStateSchema(db: Database): void;
14
23
  /** Add the local-only retrieval ledger to an already initialized database. */
15
24
  export declare function ensureRetrievalLedgerSchema(db: Database): void;
16
25
  /**