@joe-broadhead/opencode-mem 0.12.5 → 0.13.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 (59) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +1 -0
  3. package/package.json +10 -2
  4. package/src/collector.js +23 -5
  5. package/src/plugins/source-contract/index.js +2 -2
  6. package/src/plugins/source-contract/vendor/PROVENANCE.json +9 -9
  7. package/src/plugins/source-contract/vendor/RELEASE-SHA256SUMS +3 -3
  8. package/src/plugins/source-contract/vendor/RELEASE.json +9 -9
  9. package/src/plugins/source-contract/vendor/SHA256SUMS +36 -29
  10. package/src/plugins/source-contract/vendor/broker-client.js +14 -14
  11. package/src/plugins/source-contract/vendor/chunks/{chunk-JUWIMDGF.js → chunk-6ZSJSJMV.js} +2 -2
  12. package/src/plugins/source-contract/vendor/chunks/{chunk-77MJETEE.js → chunk-A2KM6BYK.js} +13 -13
  13. package/src/plugins/source-contract/vendor/chunks/{chunk-HVBOAYBO.js → chunk-BEU3WWNO.js} +59 -6
  14. package/src/plugins/source-contract/vendor/chunks/{chunk-T4QM7B3S.js → chunk-CUITXC5J.js} +1 -1
  15. package/src/{vendor/source-contract/chunks/chunk-OZMX7VR7.js → plugins/source-contract/vendor/chunks/chunk-EOS4LD6F.js} +1 -1
  16. package/src/plugins/source-contract/vendor/chunks/{chunk-F4K2Y64D.js → chunk-EUDLXWG4.js} +1 -1
  17. package/src/plugins/source-contract/vendor/chunks/{chunk-BOUWB5UP.js → chunk-GDBKZBG7.js} +2 -2
  18. package/src/plugins/source-contract/vendor/chunks/{chunk-EHIOPXPL.js → chunk-HR22TL23.js} +14 -14
  19. package/src/plugins/source-contract/vendor/chunks/{chunk-X6XP7YK2.js → chunk-IGPRJ63D.js} +2 -2
  20. package/src/plugins/source-contract/vendor/chunks/{chunk-XVA6H6OO.js → chunk-IIUWLSGP.js} +2 -2
  21. package/src/plugins/source-contract/vendor/chunks/chunk-ITQZIF2U.js +191 -0
  22. package/src/plugins/source-contract/vendor/chunks/{chunk-IL565TRX.js → chunk-KXQYSM2Z.js} +1 -1
  23. package/src/plugins/source-contract/vendor/chunks/{chunk-YH323FAZ.js → chunk-LJL3EALP.js} +238 -12
  24. package/src/plugins/source-contract/vendor/chunks/{chunk-NUEROZNU.js → chunk-NUBUQFLH.js} +1 -1
  25. package/src/plugins/source-contract/vendor/cursor.js +3 -3
  26. package/src/plugins/source-contract/vendor/descriptor.js +11 -11
  27. package/src/plugins/source-contract/vendor/events.js +22 -4
  28. package/src/plugins/source-contract/vendor/hints.js +33 -0
  29. package/src/plugins/source-contract/vendor/index.js +3 -3
  30. package/src/plugins/source-contract/vendor/params.js +3 -3
  31. package/src/plugins/source-contract/vendor/permission.js +3 -3
  32. package/src/plugins/source-contract/vendor/pick.js +5 -5
  33. package/src/plugins/source-contract/vendor/read.js +14 -14
  34. package/src/plugins/source-contract/vendor/registry.js +4 -4
  35. package/src/plugins/source-contract/vendor/schema.js +14 -10
  36. package/src/plugins/source-contract/vendor/schemas/fact.commitment.json +57 -0
  37. package/src/plugins/source-contract/vendor/schemas/fact.meeting.attended.json +35 -0
  38. package/src/plugins/source-contract/vendor/schemas/fact.person.attribute.json +37 -0
  39. package/src/plugins/source-contract/vendor/schemas/hint.json +41 -0
  40. package/src/plugins/source-contract/vendor/schemas/routine.json +67 -0
  41. package/src/plugins/source-contract/vendor/schemas/sources.json +56 -0
  42. package/src/plugins/source-contract/vendor/schemas.js +16 -11
  43. package/src/plugins/source-contract/vendor/tools-rpc.js +4 -4
  44. package/src/records.js +3 -1
  45. package/src/vendor/source-contract/README.md +10 -8
  46. package/src/vendor/source-contract/VENDOR.json +48 -39
  47. package/src/vendor/source-contract/chunks/{chunk-JUWIMDGF.js → chunk-6ZSJSJMV.js} +2 -2
  48. package/src/vendor/source-contract/chunks/{chunk-T4QM7B3S.js → chunk-CUITXC5J.js} +1 -1
  49. package/src/{plugins/source-contract/vendor/chunks/chunk-OZMX7VR7.js → vendor/source-contract/chunks/chunk-EOS4LD6F.js} +1 -1
  50. package/src/vendor/source-contract/chunks/{chunk-BOUWB5UP.js → chunk-GDBKZBG7.js} +2 -2
  51. package/src/vendor/source-contract/chunks/{chunk-X6XP7YK2.js → chunk-IGPRJ63D.js} +2 -2
  52. package/src/vendor/source-contract/chunks/{chunk-YH323FAZ.js → chunk-LJL3EALP.js} +238 -12
  53. package/src/vendor/source-contract/chunks/{chunk-NUEROZNU.js → chunk-NUBUQFLH.js} +1 -1
  54. package/src/vendor/source-contract/cursor.js +3 -3
  55. package/src/vendor/source-contract/events.js +22 -4
  56. package/src/vendor/source-contract/registry.js +4 -4
  57. package/src/vendor/source-contract/tools-rpc.js +4 -4
  58. package/src/views/contracts.js +1 -3
  59. package/src/views/rpc.js +4 -5
@@ -1,8 +1,8 @@
1
- // @we-the-rebel-alliance/source-contract 0.2.0. Built by scripts/build.mjs; do not edit.
1
+ // @we-the-rebel-alliance/source-contract 0.3.0. Built by scripts/build.mjs; do not edit.
2
2
  import {
3
3
  ACCOUNT_PATTERN,
4
4
  evaluate
5
- } from "./chunk-OZMX7VR7.js";
5
+ } from "./chunk-EOS4LD6F.js";
6
6
 
7
7
  // src/tools-rpc.ts
8
8
  import { randomUUID } from "node:crypto";
@@ -1,8 +1,8 @@
1
- // @we-the-rebel-alliance/source-contract 0.2.0. Built by scripts/build.mjs; do not edit.
1
+ // @we-the-rebel-alliance/source-contract 0.3.0. Built by scripts/build.mjs; do not edit.
2
2
  import {
3
3
  isExtensionOutput,
4
4
  outputValidator
5
- } from "./chunk-BOUWB5UP.js";
5
+ } from "./chunk-GDBKZBG7.js";
6
6
 
7
7
  // src/pick.ts
8
8
  var MAX_PICK_PATHS = 50;
@@ -0,0 +1,191 @@
1
+ // @we-the-rebel-alliance/source-contract 0.3.0. Built by scripts/build.mjs; do not edit.
2
+ import {
3
+ _enum,
4
+ array,
5
+ object,
6
+ string,
7
+ validator
8
+ } from "./chunk-6ZSJSJMV.js";
9
+ import {
10
+ isEventKind
11
+ } from "./chunk-LJL3EALP.js";
12
+
13
+ // src/hints.ts
14
+ var HINT_MAX = 1500;
15
+ var ROUTINE_BODY_MAX = 4e3;
16
+ var HINT_KEYS = ["source", "kinds", "produces"];
17
+ var ROUTINE_KEYS = ["id", "title", "reads", "produces"];
18
+ var FORBIDDEN_HINT_KEYS = ["apply", "stated_by", "space", "budget", "priority"];
19
+ var FORBIDDEN_ROUTINE_KEYS = ["tier", "schedule", "budget", "priority", "apply", "stated_by", "namespace"];
20
+ var PRODUCES_TYPES = ["commitment", "decision", "fact", "preference", "constraint", "person", "project"];
21
+ var PRODUCES_LIST = "commitment, decision, fact, preference, constraint, person or project";
22
+ var SOURCE_ID = /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/;
23
+ var ROUTINE_ID = /^[a-z][a-z0-9-]{0,63}$/;
24
+ var KEY = /^[a-z][a-z0-9_]*$/;
25
+ var producesType = _enum(PRODUCES_TYPES, { error: `must be a type Memory's core extractor finds (${PRODUCES_LIST})` });
26
+ var kind = string().max(64).refine(isEventKind, { error: "must be an event kind, such as meeting or x-<namespace>/<name>" });
27
+ var sourceId = string().max(64).regex(SOURCE_ID, { error: "must be a source id such as granola.meetings" });
28
+ var hintFrontmatter = object({
29
+ source: sourceId.describe("One of the plugin's own source ids."),
30
+ kinds: array(kind, { error: "must be a list such as [meeting]" }).min(1, "must name at least one kind"),
31
+ produces: array(producesType, { error: "must be a list such as [commitment]" }).min(1, "must name at least one type").optional()
32
+ }).strict();
33
+ var routineFrontmatter = object({
34
+ id: string().max(64).regex(ROUTINE_ID, { error: "must be a lowercase word such as meeting-actions" }),
35
+ title: string().min(1).max(200),
36
+ reads: object({
37
+ sources: array(sourceId, { error: "must be a list such as [granola.meetings]" }).min(1, "must name at least one source").describe("The plugin's own sources only."),
38
+ kinds: array(kind, { error: "must be a list such as [meeting]" }).min(1, "must name at least one kind")
39
+ }).strict(),
40
+ produces: array(producesType, { error: "must be a list such as [commitment]" }).min(1, "must name at least one type")
41
+ }).strict();
42
+ var HINT_SCHEMA = validator("hint", hintFrontmatter);
43
+ var ROUTINE_SCHEMA = validator("routine", routineFrontmatter);
44
+ function scalar(raw) {
45
+ const text = raw.trim();
46
+ if (text.startsWith('"') || text.startsWith("'")) {
47
+ const quote = text[0];
48
+ if (text.length < 2 || !text.endsWith(quote)) return { ok: false };
49
+ return { ok: true, value: text.slice(1, -1).replaceAll(`\\${quote}`, quote) };
50
+ }
51
+ if (text.startsWith("[") || text.startsWith("{")) return { ok: false };
52
+ return { ok: true, value: text };
53
+ }
54
+ function splitTop(text) {
55
+ const parts = [];
56
+ let depth = 0;
57
+ let quote = "";
58
+ let start = 0;
59
+ for (let index = 0; index < text.length; index++) {
60
+ const char = text[index];
61
+ if (quote !== "") {
62
+ if (char === quote) quote = "";
63
+ continue;
64
+ }
65
+ if (char === '"' || char === "'") quote = char;
66
+ else if (char === "[" || char === "{") depth++;
67
+ else if (char === "]" || char === "}") depth--;
68
+ else if (char === "," && depth === 0) {
69
+ parts.push(text.slice(start, index));
70
+ start = index + 1;
71
+ }
72
+ }
73
+ parts.push(text.slice(start));
74
+ return parts.map((part) => part.trim()).filter((part) => part !== "");
75
+ }
76
+ function parseValue(raw) {
77
+ const text = raw.trim();
78
+ if (text.startsWith("[") && text.endsWith("]")) {
79
+ const inner = text.slice(1, -1);
80
+ const items = [];
81
+ for (const part of splitTop(inner)) {
82
+ const parsed = scalar(part);
83
+ if (!parsed.ok) return parsed;
84
+ items.push(parsed.value);
85
+ }
86
+ return { ok: true, value: items };
87
+ }
88
+ if (text.startsWith("{") && text.endsWith("}")) {
89
+ const inner = text.slice(1, -1);
90
+ const entries = {};
91
+ for (const part of splitTop(inner)) {
92
+ const colon = part.indexOf(":");
93
+ if (colon <= 0) return { ok: false };
94
+ const key = part.slice(0, colon).trim();
95
+ if (!KEY.test(key)) return { ok: false };
96
+ const parsed = parseValue(part.slice(colon + 1));
97
+ if (!parsed.ok) return parsed;
98
+ entries[key] = parsed.value;
99
+ }
100
+ return { ok: true, value: entries };
101
+ }
102
+ return scalar(text);
103
+ }
104
+ function parseFrontmatter(text, what = "file") {
105
+ const lines = text.replace(/\r\n/g, "\n").split("\n");
106
+ if (lines[0] !== "---") return { ok: false, problems: [`the ${what} must begin with its frontmatter: --- on a line of its own`] };
107
+ const close = lines.findIndex((line, index) => index > 0 && line === "---");
108
+ if (close === -1) return { ok: false, problems: [`the ${what} has no closing --- line for its frontmatter`] };
109
+ const frontmatter = {};
110
+ const problems = [];
111
+ for (const [index, line] of lines.slice(1, close).entries()) {
112
+ const at = index + 2;
113
+ if (line.trim() === "") continue;
114
+ if (/^[\s]/.test(line)) {
115
+ problems.push(`the ${what}'s frontmatter line ${at} is indented: the frontmatter is one key a line`);
116
+ continue;
117
+ }
118
+ const colon = line.indexOf(":");
119
+ const key = colon === -1 ? "" : line.slice(0, colon).trim();
120
+ if (colon <= 0 || !KEY.test(key)) {
121
+ problems.push(`the ${what}'s frontmatter line ${at} is not a key and its value`);
122
+ continue;
123
+ }
124
+ if (Object.hasOwn(frontmatter, key)) {
125
+ problems.push(`the ${what}'s frontmatter line ${at} repeats the key "${key}"`);
126
+ continue;
127
+ }
128
+ const parsed = parseValue(line.slice(colon + 1));
129
+ if (!parsed.ok) {
130
+ problems.push(`the ${what}'s frontmatter line ${at} holds a value this contract does not read`);
131
+ continue;
132
+ }
133
+ frontmatter[key] = parsed.value;
134
+ }
135
+ if (problems.length > 0) return { ok: false, problems };
136
+ return { ok: true, value: { frontmatter, body: lines.slice(close + 1).join("\n").trim() } };
137
+ }
138
+ function keyProblems(frontmatter, known, forbidden, what, why) {
139
+ const problems = [];
140
+ for (const key of Object.keys(frontmatter)) {
141
+ if (known.includes(key)) continue;
142
+ if (forbidden.includes(key)) problems.push(`the ${what} sets "${key}", which a ${what} may not set: ${why}`);
143
+ else problems.push(`the ${what} has the key "${key}", which a ${what} does not have (${known.join(", ")})`);
144
+ }
145
+ return problems;
146
+ }
147
+ var HINT_WHY = "a hint is data, and Memory decides how its text is used";
148
+ var ROUTINE_WHY = "the namespace, the tier, the schedule, the budget, the priority and the apply mode are Memory's";
149
+ function hintProblems(text, options) {
150
+ if (typeof text !== "string") return ["the hint is not text"];
151
+ const problems = [];
152
+ if (text.length > HINT_MAX) problems.push(`the hint is ${text.length} characters, over the ${HINT_MAX} a hint may take`);
153
+ const parsed = parseFrontmatter(text, "hint");
154
+ if (!parsed.ok) return [...problems, ...parsed.problems];
155
+ const keys = keyProblems(parsed.value.frontmatter, HINT_KEYS, FORBIDDEN_HINT_KEYS, "hint", HINT_WHY);
156
+ if (keys.length > 0) return [...problems, ...keys];
157
+ const checked = HINT_SCHEMA.check(parsed.value.frontmatter);
158
+ if (!checked.ok) return [...problems, ...checked.problems];
159
+ if (!options.sources.includes(checked.value.source)) problems.push(`the hint names the source "${checked.value.source}", which is not one of the plugin's own`);
160
+ return problems;
161
+ }
162
+ function routineProblems(text, options) {
163
+ if (typeof text !== "string") return ["the routine is not text"];
164
+ const problems = [];
165
+ const parsed = parseFrontmatter(text, "routine");
166
+ if (!parsed.ok) return parsed.problems;
167
+ if (parsed.value.body.length > ROUTINE_BODY_MAX) problems.push(`the routine's body is ${parsed.value.body.length} characters, over the ${ROUTINE_BODY_MAX} its instructions may take`);
168
+ const keys = keyProblems(parsed.value.frontmatter, ROUTINE_KEYS, FORBIDDEN_ROUTINE_KEYS, "routine", ROUTINE_WHY);
169
+ if (keys.length > 0) return [...problems, ...keys];
170
+ const checked = ROUTINE_SCHEMA.check(parsed.value.frontmatter);
171
+ if (!checked.ok) return [...problems, ...checked.problems];
172
+ for (const source of checked.value.reads.sources) {
173
+ if (!options.sources.includes(source)) problems.push(`the routine reads the source "${source}", which is not one of the plugin's own`);
174
+ }
175
+ return problems;
176
+ }
177
+
178
+ export {
179
+ HINT_MAX,
180
+ ROUTINE_BODY_MAX,
181
+ HINT_KEYS,
182
+ ROUTINE_KEYS,
183
+ FORBIDDEN_HINT_KEYS,
184
+ FORBIDDEN_ROUTINE_KEYS,
185
+ PRODUCES_TYPES,
186
+ HINT_SCHEMA,
187
+ ROUTINE_SCHEMA,
188
+ parseFrontmatter,
189
+ hintProblems,
190
+ routineProblems
191
+ };
@@ -1,4 +1,4 @@
1
- // @we-the-rebel-alliance/source-contract 0.2.0. Built by scripts/build.mjs; do not edit.
1
+ // @we-the-rebel-alliance/source-contract 0.3.0. Built by scripts/build.mjs; do not edit.
2
2
 
3
3
  // src/index.ts
4
4
  var CONTRACT_VERSION = 1;
@@ -1,8 +1,8 @@
1
- // @we-the-rebel-alliance/source-contract 0.2.0. Built by scripts/build.mjs; do not edit.
1
+ // @we-the-rebel-alliance/source-contract 0.3.0. Built by scripts/build.mjs; do not edit.
2
2
  import {
3
3
  MAX_CURSOR_LENGTH,
4
4
  canonicalScope
5
- } from "./chunk-NUEROZNU.js";
5
+ } from "./chunk-NUBUQFLH.js";
6
6
 
7
7
  // src/internal/secrets.ts
8
8
  var PRIVATE_KEY_BLOCK = /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----[\s\S]*?(?:-----END (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----|$)/g;
@@ -152,13 +152,37 @@ var EVENT_LIMITS = {
152
152
  refused: 500,
153
153
  failed: 500,
154
154
  detail: 200,
155
- costUnits: 8
155
+ costUnits: 8,
156
+ /** #45 §1: the identities one actor may carry, and the lengths of each part of one. */
157
+ identities: 10,
158
+ identityBasis: 64,
159
+ /** #45 §2: the metadata one event may carry. */
160
+ replyTo: 512,
161
+ domains: 20,
162
+ domain: 253,
163
+ sections: 20,
164
+ sectionHeading: 300,
165
+ parts: 50,
166
+ partId: 512,
167
+ /** #45 §3: the facts one event may carry, and the lengths of their fields. */
168
+ facts: 20,
169
+ factKey: 200,
170
+ factTitle: 300,
171
+ factAttribute: 120
156
172
  };
157
173
  var PAGE = { default: 100, min: 1, max: 500 };
158
174
  var MAX_PAGE_BYTES = 65536;
159
175
  var MAX_BYTES = { default: 65536, max: 1048576 };
160
176
  var FIRST_RUN_HOURS = 24;
161
177
  var TRUST = "untrusted";
178
+ var ACTOR_KINDS = ["person", "agent", "bot", "service"];
179
+ var ACTOR_ROLES = ["from", "author", "to", "cc", "bcc", "mentioned", "assignee", "creator", "reviewer", "organizer", "attendee", "owner", "speaker", "agent"];
180
+ var AUTHOR_ROLES = ["from", "author"];
181
+ var IDENTITY_STRENGTHS = ["strong", "weak"];
182
+ var AUDIENCES = ["dm", "group", "channel", "email", "public"];
183
+ var FACT_TYPES = ["commitment", "person.attribute", "meeting.attended"];
184
+ var COMMITMENT_STATES = ["open", "done", "cancelled"];
185
+ var ATTENDANCE_RESPONSES = ["accepted", "declined", "tentative", "needs_action"];
162
186
  function ownerShapeProblems(owner, what) {
163
187
  if (!plainObject(owner) || !line(owner["id"], EVENT_LIMITS.ownerId) || !line(owner["label"], EVENT_LIMITS.ownerLabel) || Object.keys(owner).some((key) => key !== "id" && key !== "label" && key !== "verified")) {
164
188
  return [`${what} must be { id, label }, two non-empty lines`];
@@ -299,6 +323,20 @@ function cut(text2, max) {
299
323
  if (end > 0 && code >= 55296 && code <= 56319) end--;
300
324
  return `${text2.slice(0, end)}\u2026`;
301
325
  }
326
+ function stable(value) {
327
+ if (Array.isArray(value)) return value.map(stable);
328
+ if (typeof value === "object" && value !== null) {
329
+ const entries = Object.keys(value).filter((key) => value[key] !== void 0);
330
+ return Object.fromEntries(entries.sort().map((key) => [key, stable(value[key])]));
331
+ }
332
+ return value;
333
+ }
334
+ var HASHED_EVENT_FIELDS = ["reply_to", "audience", "domains", "sections", "parts", "facts"];
335
+ function actorFields(actor) {
336
+ const base = [actor.role, actor.id, actor.name ?? null];
337
+ const extra = stable({ kind: actor.kind, identities: actor.identities, self: actor.self });
338
+ return Object.keys(extra).length === 0 ? base : [...base, extra];
339
+ }
302
340
  function eventHash(event) {
303
341
  const fields = [
304
342
  event.source,
@@ -307,12 +345,16 @@ function eventHash(event) {
307
345
  event.kind,
308
346
  event.occurred_at,
309
347
  event.thread,
310
- event.actors.map((actor) => [actor.role, actor.id, actor.name ?? null]),
348
+ event.actors.map(actorFields),
311
349
  event.title,
312
350
  event.text,
313
351
  event.url,
314
352
  event.labels
315
353
  ];
354
+ for (const key of HASHED_EVENT_FIELDS) {
355
+ const value = event[key];
356
+ if (value !== void 0) fields.push([key, stable(value)]);
357
+ }
316
358
  return `sha256:${createHash("sha256").update(JSON.stringify(fields)).digest("hex")}`;
317
359
  }
318
360
  var clean = (text2) => text2.replaceAll("\0", "");
@@ -329,11 +371,27 @@ function makeEvent(draft) {
329
371
  if (!role || !id || seen.has(key) || actors.length >= EVENT_LIMITS.actors) continue;
330
372
  seen.add(key);
331
373
  const name = actor.name ? cut(oneLine(actor.name), EVENT_LIMITS.actorName) : "";
332
- actors.push(name ? { role, id, name } : { role, id });
374
+ actors.push({
375
+ role,
376
+ id,
377
+ ...name ? { name } : {},
378
+ ...actor.kind === void 0 ? {} : { kind: actor.kind },
379
+ // An empty list says nothing, and is left out so the actor hashes as if it had none.
380
+ ...actor.identities === void 0 || actor.identities.length === 0 ? {} : { identities: [...actor.identities] },
381
+ ...actor.self === void 0 ? {} : { self: actor.self }
382
+ });
333
383
  }
334
384
  const labels = [...new Set((draft.labels ?? []).map((label) => oneLine(label).replace(/\s/g, "-")).filter((label) => label.length > 0 && label.length <= EVENT_LIMITS.label))].slice(0, EVENT_LIMITS.labels);
335
385
  const url = draft.url && /^https:\/\/\S+$/.test(draft.url) && draft.url.length <= EVENT_LIMITS.url ? draft.url : null;
336
386
  const thread = draft.thread ? oneLine(draft.thread) || null : null;
387
+ const replyTo = draft.reply_to ? cut(oneLine(draft.reply_to), EVENT_LIMITS.replyTo) : void 0;
388
+ const domains = draft.domains === void 0 ? void 0 : [...new Set(draft.domains.map((domain) => oneLine(domain).toLowerCase()))].filter((domain) => domain.length > 0);
389
+ const sections = draft.sections?.map((section) => ({ heading: cut(oneLine(section.heading), EVENT_LIMITS.sectionHeading), text: cut(clean(section.text), EVENT_LIMITS.text) })).filter((section) => section.heading.length > 0);
390
+ const parts = draft.parts?.map((part) => {
391
+ const id = cut(oneLine(part.id), EVENT_LIMITS.partId);
392
+ const actor = part.actor === void 0 ? "" : oneLine(part.actor);
393
+ return { id, text: cut(clean(part.text), EVENT_LIMITS.text), ...actor ? { actor } : {} };
394
+ }).filter((part) => part.id.length > 0);
337
395
  const event = {
338
396
  source: draft.source,
339
397
  account: draft.account,
@@ -345,7 +403,13 @@ function makeEvent(draft) {
345
403
  title: cut(oneLine(draft.title ?? ""), EVENT_LIMITS.title),
346
404
  text: cut(clean(draft.text ?? "").trim(), EVENT_LIMITS.text),
347
405
  url,
348
- labels
406
+ labels,
407
+ ...replyTo === void 0 ? {} : { reply_to: replyTo },
408
+ ...draft.audience === void 0 || draft.audience === null ? {} : { audience: draft.audience },
409
+ ...domains === void 0 || domains.length === 0 ? {} : { domains },
410
+ ...sections === void 0 || sections.length === 0 ? {} : { sections },
411
+ ...parts === void 0 || parts.length === 0 ? {} : { parts },
412
+ ...draft.facts === void 0 || draft.facts.length === 0 ? {} : { facts: [...draft.facts] }
349
413
  };
350
414
  return { ...event, hash: eventHash(event) };
351
415
  }
@@ -460,15 +524,168 @@ var SCHEMED = /^[a-z][a-z0-9+.-]*:\S+$/;
460
524
  var HASH = /^sha256:[0-9a-f]{64}$/;
461
525
  var CODE = /^[A-Z][A-Z0-9_]*$/;
462
526
  var UNIT = /^[a-z][a-z0-9_-]*$/;
527
+ var DOMAIN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+$/;
528
+ var DATE = /^\d{4}-\d{2}-\d{2}$/;
529
+ var listOf = (items) => items.length <= 1 ? items.join("") : `${items.slice(0, -1).join(", ")} or ${items.at(-1)}`;
463
530
  var text = (value, max, empty = false) => typeof value === "string" && value.length <= max && (empty || value.length > 0) && !value.includes("\0");
464
531
  var line = (value, max, empty = false) => text(value, max, empty) && !hasControl(value);
465
532
  var isoUtc = (value) => typeof value === "string" && ISO_UTC.test(value) && Number.isFinite(Date.parse(value));
533
+ function actorProblems(actor, at) {
534
+ const problems = [];
535
+ for (const key of Object.keys(actor)) if (!["role", "id", "name", "kind", "identities", "self"].includes(key)) problems.push(`${at} has the field "${key}", which the contract does not define`);
536
+ const role = actor.role;
537
+ const id = actor.id;
538
+ if (!line(role, EVENT_LIMITS.actorRole) || !ROLE.test(role)) problems.push(`${at}.role must be a lowercase word such as from`);
539
+ if (!line(id, EVENT_LIMITS.actorId) || !SCHEMED.test(id)) problems.push(`${at}.id must be a scheme-qualified id such as mailto:someone@example.com`);
540
+ if (actor.name !== void 0 && !line(actor.name, EVENT_LIMITS.actorName)) problems.push(`${at}.name must be one non-empty line of at most ${EVENT_LIMITS.actorName} characters`);
541
+ if (actor.kind !== void 0 && !ACTOR_KINDS.includes(actor.kind)) problems.push(`${at}.kind must be ${listOf(ACTOR_KINDS)}`);
542
+ if (actor.self !== void 0 && typeof actor.self !== "boolean") problems.push(`${at}.self must be true or false`);
543
+ if (actor.identities !== void 0) {
544
+ if (!Array.isArray(actor.identities) || actor.identities.length > EVENT_LIMITS.identities) problems.push(`${at}.identities must be a list of at most ${EVENT_LIMITS.identities}`);
545
+ else {
546
+ const seen = /* @__PURE__ */ new Set();
547
+ for (const [index, identity] of actor.identities.entries()) {
548
+ const here = `${at}.identities[${index}]`;
549
+ if (!plainObject(identity)) {
550
+ problems.push(`${here} is not an object`);
551
+ continue;
552
+ }
553
+ for (const key of Object.keys(identity)) if (!["id", "strength", "basis"].includes(key)) problems.push(`${here} has the field "${key}", which the contract does not define`);
554
+ const own = identity.id;
555
+ if (!line(own, EVENT_LIMITS.actorId) || !SCHEMED.test(own)) problems.push(`${here}.id must be a scheme-qualified id such as mailto:someone@example.com`);
556
+ else if (own === id) problems.push(`${here}.id is the actor's own id: an identity is another id for the same actor`);
557
+ else if (seen.has(own)) problems.push(`${here} repeats an identity`);
558
+ else seen.add(own);
559
+ if (!IDENTITY_STRENGTHS.includes(identity.strength)) problems.push(`${here}.strength must be ${listOf(IDENTITY_STRENGTHS)}`);
560
+ if (!line(identity.basis, EVENT_LIMITS.identityBasis)) {
561
+ problems.push(`${here}.basis must be one line of at most ${EVENT_LIMITS.identityBasis} characters naming the provider field it came from`);
562
+ }
563
+ }
564
+ }
565
+ }
566
+ return problems;
567
+ }
568
+ function targetProblems(e, where) {
569
+ const problems = [];
570
+ if (e.reply_to !== void 0 && !line(e.reply_to, EVENT_LIMITS.replyTo)) {
571
+ problems.push(`${where}.reply_to must be a non-empty id of at most ${EVENT_LIMITS.replyTo} characters`);
572
+ }
573
+ if (e.audience !== void 0 && !AUDIENCES.includes(e.audience)) {
574
+ problems.push(`${where}.audience must be ${listOf(AUDIENCES)}`);
575
+ }
576
+ if (e.domains !== void 0) {
577
+ if (!Array.isArray(e.domains) || e.domains.length > EVENT_LIMITS.domains) problems.push(`${where}.domains must be at most ${EVENT_LIMITS.domains} lowercase domains`);
578
+ else {
579
+ const seen = /* @__PURE__ */ new Set();
580
+ for (const [index, domain] of e.domains.entries()) {
581
+ if (!line(domain, EVENT_LIMITS.domain) || !DOMAIN.test(domain)) problems.push(`${where}.domains[${index}] must be a lowercase domain such as example.com`);
582
+ else if (seen.has(domain)) problems.push(`${where}.domains repeats a domain`);
583
+ else seen.add(domain);
584
+ }
585
+ }
586
+ }
587
+ return problems;
588
+ }
589
+ function partProblems(e, where, actorIds) {
590
+ const problems = [];
591
+ if (e.sections !== void 0) {
592
+ if (!Array.isArray(e.sections) || e.sections.length > EVENT_LIMITS.sections) problems.push(`${where}.sections must be a list of at most ${EVENT_LIMITS.sections}`);
593
+ else {
594
+ for (const [index, section] of e.sections.entries()) {
595
+ const at = `${where}.sections[${index}]`;
596
+ if (!plainObject(section)) {
597
+ problems.push(`${at} is not an object`);
598
+ continue;
599
+ }
600
+ for (const key of Object.keys(section)) if (!["heading", "text"].includes(key)) problems.push(`${at} has the field "${key}", which the contract does not define`);
601
+ if (!line(section.heading, EVENT_LIMITS.sectionHeading)) problems.push(`${at}.heading must be one line of at most ${EVENT_LIMITS.sectionHeading} characters`);
602
+ if (!text(section.text, EVENT_LIMITS.text, true)) problems.push(`${at}.text must be at most ${EVENT_LIMITS.text} characters`);
603
+ }
604
+ }
605
+ }
606
+ if (e.parts !== void 0) {
607
+ if (!Array.isArray(e.parts) || e.parts.length > EVENT_LIMITS.parts) problems.push(`${where}.parts must be a list of at most ${EVENT_LIMITS.parts}`);
608
+ else {
609
+ const seen = /* @__PURE__ */ new Set();
610
+ for (const [index, part] of e.parts.entries()) {
611
+ const at = `${where}.parts[${index}]`;
612
+ if (!plainObject(part)) {
613
+ problems.push(`${at} is not an object`);
614
+ continue;
615
+ }
616
+ for (const key of Object.keys(part)) if (!["id", "text", "actor"].includes(key)) problems.push(`${at} has the field "${key}", which the contract does not define`);
617
+ const id = part.id;
618
+ if (!line(id, EVENT_LIMITS.partId)) problems.push(`${at}.id must be a non-empty id of at most ${EVENT_LIMITS.partId} characters`);
619
+ else if (seen.has(id)) problems.push(`${at}.id repeats a part`);
620
+ else seen.add(id);
621
+ if (!text(part.text, EVENT_LIMITS.text, true)) problems.push(`${at}.text must be at most ${EVENT_LIMITS.text} characters`);
622
+ if (part.actor !== void 0) {
623
+ if (!line(part.actor, EVENT_LIMITS.actorId)) problems.push(`${at}.actor must be an actor id of the same event`);
624
+ else if (!actorIds.has(part.actor)) problems.push(`${at}.actor is not an actor of the same event`);
625
+ }
626
+ }
627
+ }
628
+ }
629
+ return problems;
630
+ }
631
+ function factProblems(fact, actors, where = "fact") {
632
+ if (!plainObject(fact)) return [`${where} is not an object`];
633
+ const type = fact.type;
634
+ if (!FACT_TYPES.includes(type)) return [`${where}.type must be ${listOf(FACT_TYPES)}`];
635
+ const allowed = {
636
+ commitment: ["type", "key", "title", "owner", "counterparty", "due", "state", "url"],
637
+ "person.attribute": ["type", "actor", "org", "team", "role"],
638
+ "meeting.attended": ["type", "actor", "response", "organizer"]
639
+ };
640
+ const problems = [];
641
+ for (const key of Object.keys(fact)) {
642
+ if (!allowed[type].includes(key)) problems.push(`${where} has the field "${key}", which the contract does not define`);
643
+ }
644
+ const reference = (key) => {
645
+ const id = fact[key];
646
+ if (!line(id, EVENT_LIMITS.actorId)) problems.push(`${where}.${key} must be an actor id of the same event`);
647
+ else if (!actors.has(id)) problems.push(`${where}.${key} is not an actor of the same event`);
648
+ };
649
+ if (type === "commitment") {
650
+ if (!line(fact.key, EVENT_LIMITS.factKey)) problems.push(`${where}.key must be a stable id of at most ${EVENT_LIMITS.factKey} characters`);
651
+ if (!line(fact.title, EVENT_LIMITS.factTitle)) problems.push(`${where}.title must be one line of at most ${EVENT_LIMITS.factTitle} characters`);
652
+ reference("owner");
653
+ if (fact.counterparty !== void 0) reference("counterparty");
654
+ if (fact.due !== void 0 && !(typeof fact.due === "string" && DATE.test(fact.due) && Number.isFinite(Date.parse(fact.due)))) problems.push(`${where}.due must be a date such as 2026-11-30`);
655
+ if (!COMMITMENT_STATES.includes(fact.state)) problems.push(`${where}.state must be ${listOf(COMMITMENT_STATES)}`);
656
+ if (fact.url !== void 0 && !(typeof fact.url === "string" && fact.url.length <= EVENT_LIMITS.url && /^https:\/\/\S+$/.test(fact.url))) problems.push(`${where}.url must be an https URL`);
657
+ }
658
+ if (type === "person.attribute") {
659
+ reference("actor");
660
+ if (fact.org === void 0 && fact.team === void 0 && fact.role === void 0) {
661
+ problems.push(`${where} must name org, team or role: a person's attribute comes from structured profile or directory data`);
662
+ }
663
+ for (const key of ["org", "team", "role"]) {
664
+ if (fact[key] !== void 0 && !line(fact[key], EVENT_LIMITS.factAttribute)) {
665
+ problems.push(`${where}.${key} must be one line of at most ${EVENT_LIMITS.factAttribute} characters`);
666
+ }
667
+ }
668
+ }
669
+ if (type === "meeting.attended") {
670
+ reference("actor");
671
+ if (!ATTENDANCE_RESPONSES.includes(fact.response)) problems.push(`${where}.response must be ${listOf(ATTENDANCE_RESPONSES)}`);
672
+ if (typeof fact.organizer !== "boolean") problems.push(`${where}.organizer must be true or false`);
673
+ }
674
+ return problems;
675
+ }
676
+ function factsProblems(e, where, actorIds) {
677
+ if (e.facts === void 0) return [];
678
+ if (!Array.isArray(e.facts) || e.facts.length > EVENT_LIMITS.facts) return [`${where}.facts must be a list of at most ${EVENT_LIMITS.facts}`];
679
+ return e.facts.flatMap((fact, index) => factProblems(fact, actorIds, `${where}.facts[${index}]`));
680
+ }
681
+ var EVENT_KEYS = ["source", "account", "external_id", "kind", "occurred_at", "thread", "actors", "title", "text", "url", "labels", "hash"];
682
+ var EVENT_METADATA_KEYS = ["reply_to", "audience", "domains", "sections", "parts", "facts"];
466
683
  function eventProblems(event, where = "event") {
467
684
  if (!plainObject(event)) return [`${where} is not an object`];
468
685
  const problems = [];
469
- const keys = ["source", "account", "external_id", "kind", "occurred_at", "thread", "actors", "title", "text", "url", "labels", "hash"];
686
+ const keys = [...EVENT_KEYS, ...EVENT_METADATA_KEYS];
470
687
  for (const key of Object.keys(event)) if (!keys.includes(key)) problems.push(`${where} has the field "${key}", which the contract does not define`);
471
- for (const key of keys) if (!Object.hasOwn(event, key)) problems.push(`${where} has no "${key}"`);
688
+ for (const key of EVENT_KEYS) if (!Object.hasOwn(event, key)) problems.push(`${where} has no "${key}"`);
472
689
  const e = event;
473
690
  if (!line(e.source, EVENT_LIMITS.source) || !SOURCE_PATTERN.test(e.source)) problems.push(`${where}.source must be a lowercase name such as gmail`);
474
691
  if (!line(e.account, EVENT_LIMITS.account)) problems.push(`${where}.account must be a non-empty name of at most ${EVENT_LIMITS.account} characters`);
@@ -482,6 +699,7 @@ function eventProblems(event, where = "event") {
482
699
  if (!Array.isArray(e.labels) || e.labels.length > EVENT_LIMITS.labels || e.labels.some((label) => !line(label, EVENT_LIMITS.label) || /\s/.test(label))) {
483
700
  problems.push(`${where}.labels must be at most ${EVENT_LIMITS.labels} labels of at most ${EVENT_LIMITS.label} characters without spaces`);
484
701
  } else if (new Set(e.labels).size !== e.labels.length) problems.push(`${where}.labels repeats a label`);
702
+ const actorIds = /* @__PURE__ */ new Set();
485
703
  if (!Array.isArray(e.actors) || e.actors.length > EVENT_LIMITS.actors) problems.push(`${where}.actors must be a list of at most ${EVENT_LIMITS.actors}`);
486
704
  else {
487
705
  const seen = /* @__PURE__ */ new Set();
@@ -491,15 +709,14 @@ function eventProblems(event, where = "event") {
491
709
  problems.push(`${at} is not an object`);
492
710
  continue;
493
711
  }
494
- for (const key2 of Object.keys(actor)) if (!["role", "id", "name"].includes(key2)) problems.push(`${at} has the field "${key2}", which the contract does not define`);
495
- if (!line(actor.role, EVENT_LIMITS.actorRole) || !ROLE.test(actor.role)) problems.push(`${at}.role must be a lowercase word such as from`);
496
- if (!line(actor.id, EVENT_LIMITS.actorId) || !SCHEMED.test(actor.id)) problems.push(`${at}.id must be a scheme-qualified id such as mailto:someone@example.com`);
497
- if (actor.name !== void 0 && !line(actor.name, EVENT_LIMITS.actorName)) problems.push(`${at}.name must be one non-empty line of at most ${EVENT_LIMITS.actorName} characters`);
712
+ problems.push(...actorProblems(actor, at));
713
+ if (typeof actor.id === "string") actorIds.add(actor.id);
498
714
  const key = `${String(actor.role)}\0${String(actor.id)}`;
499
715
  if (seen.has(key)) problems.push(`${at} repeats an actor`);
500
716
  seen.add(key);
501
717
  }
502
718
  }
719
+ problems.push(...targetProblems(e, where), ...partProblems(e, where, actorIds), ...factsProblems(e, where, actorIds));
503
720
  if (typeof e.hash !== "string" || !HASH.test(e.hash)) problems.push(`${where}.hash must be sha256: and 64 hex digits`);
504
721
  else if (problems.length === 0) {
505
722
  const { hash, ...rest } = e;
@@ -659,6 +876,14 @@ export {
659
876
  MAX_BYTES,
660
877
  FIRST_RUN_HOURS,
661
878
  TRUST,
879
+ ACTOR_KINDS,
880
+ ACTOR_ROLES,
881
+ AUTHOR_ROLES,
882
+ IDENTITY_STRENGTHS,
883
+ AUDIENCES,
884
+ FACT_TYPES,
885
+ COMMITMENT_STATES,
886
+ ATTENDANCE_RESPONSES,
662
887
  REFUSAL_REASONS,
663
888
  REMOVAL_REASONS,
664
889
  GAP_REASONS,
@@ -688,6 +913,7 @@ export {
688
913
  probeResult,
689
914
  probeResultProblems,
690
915
  eventsListResult,
916
+ factProblems,
691
917
  eventProblems,
692
918
  removalProblems,
693
919
  resultProblems
@@ -1,4 +1,4 @@
1
- // @we-the-rebel-alliance/source-contract 0.2.0. Built by scripts/build.mjs; do not edit.
1
+ // @we-the-rebel-alliance/source-contract 0.3.0. Built by scripts/build.mjs; do not edit.
2
2
 
3
3
  // src/cursor.ts
4
4
  import { createHash } from "node:crypto";
@@ -1,4 +1,4 @@
1
- // @we-the-rebel-alliance/source-contract 0.2.0. Built by scripts/build.mjs; do not edit.
1
+ // @we-the-rebel-alliance/source-contract 0.3.0. Built by scripts/build.mjs; do not edit.
2
2
  import {
3
3
  CURSOR_V1,
4
4
  CURSOR_V2,
@@ -10,8 +10,8 @@ import {
10
10
  decodeCursor,
11
11
  encodeBoundCursor,
12
12
  encodeCursor
13
- } from "./chunks/chunk-NUEROZNU.js";
14
- import "./chunks/chunk-T4QM7B3S.js";
13
+ } from "./chunks/chunk-NUBUQFLH.js";
14
+ import "./chunks/chunk-CUITXC5J.js";
15
15
  export {
16
16
  CURSOR_V1,
17
17
  CURSOR_V2,
@@ -1,4 +1,4 @@
1
- // @we-the-rebel-alliance/source-contract 0.2.0. Built by scripts/build.mjs; do not edit.
1
+ // @we-the-rebel-alliance/source-contract 0.3.0. Built by scripts/build.mjs; do not edit.
2
2
  import {
3
3
  DEFAULT_MAX_BYTES,
4
4
  DETAIL_FIELDS,
@@ -10,16 +10,16 @@ import {
10
10
  findSource,
11
11
  maxBytesOf,
12
12
  readInstalledDescriptor
13
- } from "./chunks/chunk-EHIOPXPL.js";
14
- import "./chunks/chunk-HVBOAYBO.js";
15
- import "./chunks/chunk-X6XP7YK2.js";
16
- import "./chunks/chunk-IL565TRX.js";
17
- import "./chunks/chunk-YH323FAZ.js";
18
- import "./chunks/chunk-NUEROZNU.js";
19
- import "./chunks/chunk-OZMX7VR7.js";
20
- import "./chunks/chunk-BOUWB5UP.js";
21
- import "./chunks/chunk-JUWIMDGF.js";
22
- import "./chunks/chunk-T4QM7B3S.js";
13
+ } from "./chunks/chunk-HR22TL23.js";
14
+ import "./chunks/chunk-GDBKZBG7.js";
15
+ import "./chunks/chunk-BEU3WWNO.js";
16
+ import "./chunks/chunk-IGPRJ63D.js";
17
+ import "./chunks/chunk-KXQYSM2Z.js";
18
+ import "./chunks/chunk-6ZSJSJMV.js";
19
+ import "./chunks/chunk-LJL3EALP.js";
20
+ import "./chunks/chunk-NUBUQFLH.js";
21
+ import "./chunks/chunk-EOS4LD6F.js";
22
+ import "./chunks/chunk-CUITXC5J.js";
23
23
  export {
24
24
  DEFAULT_MAX_BYTES,
25
25
  DETAIL_FIELDS,