@blueshed/joined 0.3.0 → 0.3.2

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 (109) hide show
  1. package/.claude/skills/joined/reference.md +57 -18
  2. package/docs/design.md +93 -38
  3. package/docs/introduction.md +9 -9
  4. package/docs/light-and-shadow.svg +1 -0
  5. package/docs/links-and-trust.svg +1 -0
  6. package/docs/stories-to-code.svg +2 -1
  7. package/docs/wire-op.svg +1 -0
  8. package/examples/app.css +9 -0
  9. package/examples/cafe/cafe.css +87 -69
  10. package/examples/cafe/generated/staff.elements.ts +7 -2
  11. package/examples/cafe/generated/staff.rules.ts +3 -0
  12. package/examples/cafe/generated/supplies.rules.ts +5 -0
  13. package/examples/cafe/kitchen.css +11 -19
  14. package/examples/cafe/kitchen.ts +6 -2
  15. package/examples/cafe/migrations/002-guard-supplies.ts +15 -0
  16. package/examples/cafe/order.html +2 -1
  17. package/examples/cafe/order.ts +1 -1
  18. package/examples/cafe/staff.json +5 -0
  19. package/examples/cafe/stories.jsonl +4 -2
  20. package/examples/cafe/supplies.html +1 -0
  21. package/examples/cafe/supplies.ts +45 -28
  22. package/examples/cafe/till.ts +14 -10
  23. package/examples/cafe/views.ts +7 -5
  24. package/examples/chart/arches.ts +5 -3
  25. package/examples/chart/chart.css +7 -2
  26. package/examples/desk/desk.css +6 -10
  27. package/examples/desk/generated/elements.ts +1 -1
  28. package/examples/desk/index.html +1 -1
  29. package/examples/desk/lanes.css +21 -19
  30. package/examples/desk/stories.jsonl +1 -1
  31. package/examples/desk/tally.css +1 -1
  32. package/examples/docs.ts +7 -4
  33. package/examples/index.html +16 -7
  34. package/examples/notes/generated/queries.ts +8 -2
  35. package/examples/notes/index.html +1 -1
  36. package/examples/notes/stories.jsonl +3 -0
  37. package/examples/page.ts +9 -2
  38. package/examples/people/links.ts +7 -9
  39. package/examples/people/people.css +1 -1
  40. package/examples/people/view.ts +1 -1
  41. package/examples/trip/generated/elements.ts +1 -1
  42. package/examples/trip/stays.css +1 -1
  43. package/examples/trip/stays.ts +1 -1
  44. package/examples/trips/generated/elements.ts +1 -1
  45. package/examples/trips/trips.css +24 -23
  46. package/examples/welcome.css +41 -33
  47. package/package.json +1 -1
  48. package/src/attachment.ts +17 -2
  49. package/src/board.css +2 -1
  50. package/src/board.ts +4 -4
  51. package/src/cli.ts +14 -2
  52. package/src/compile.ts +255 -77
  53. package/src/definitions.ts +62 -14
  54. package/src/demo.css +2 -5
  55. package/src/draft.ts +10 -4
  56. package/src/drawer.ts +30 -4
  57. package/src/engine.ts +14 -5
  58. package/src/fields.ts +88 -15
  59. package/src/file-value.ts +12 -2
  60. package/src/files.ts +113 -35
  61. package/src/icon-names.ts +4 -0
  62. package/src/keep.ts +16 -3
  63. package/src/map.css +23 -16
  64. package/src/map.ts +3 -3
  65. package/src/mcp.ts +24 -3
  66. package/src/members/group.ts +41 -17
  67. package/src/members/keys.ts +3 -3
  68. package/src/members/panel.css +17 -18
  69. package/src/members/panel.ts +9 -2
  70. package/src/migrate.ts +58 -21
  71. package/src/migrations/005-change-kept.ts +7 -0
  72. package/src/month.css +6 -2
  73. package/src/month.ts +5 -5
  74. package/src/ops.ts +40 -1
  75. package/src/page.css +3 -2
  76. package/src/page.ts +64 -16
  77. package/src/parts.css +178 -86
  78. package/src/parts.ts +60 -20
  79. package/src/plane.css +9 -4
  80. package/src/plane.ts +4 -2
  81. package/src/reading.css +1 -5
  82. package/src/rows.css +2 -21
  83. package/src/rows.ts +123 -39
  84. package/src/server.ts +157 -30
  85. package/src/sheet.ts +4 -2
  86. package/src/slots.css +0 -4
  87. package/src/specs.ts +1 -1
  88. package/src/starter.ts +15 -1
  89. package/src/store.ts +40 -18
  90. package/src/surface.ts +7 -2
  91. package/src/time.ts +2 -0
  92. package/src/timeline.ts +14 -5
  93. package/src/together.ts +15 -17
  94. package/src/tokens.css +12 -3
  95. package/src/tokens.json +38 -7
  96. package/src/tool.ts +6 -7
  97. package/src/upkeep.ts +31 -4
  98. package/src/views.css +8 -9
  99. package/src/views.ts +23 -6
  100. package/src/week.css +1 -2
  101. package/src/week.ts +11 -7
  102. package/src/write.ts +130 -15
  103. package/starter/CHANGELOG.md +8 -0
  104. package/starter/CLAUDE.md +7 -1
  105. package/starter/bunfig +2 -1
  106. package/starter/githooks/pre-commit +13 -0
  107. package/starter/prettierignore +1 -0
  108. package/starter/tests/records.test.ts +40 -0
  109. package/starter/todo.jsonl +0 -0
package/src/write.ts CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  type Store,
23
23
  } from "./store.ts";
24
24
  import { named, type Part } from "./together.ts";
25
+ import { wallIn } from "./time.ts";
25
26
  import { admits, guestRole, levelled } from "./visitors.ts";
26
27
 
27
28
  /** A way to read any document as it is now: whole, or as a member sees it (owns). */
@@ -31,7 +32,8 @@ export type Read = (doc: string, member?: number) => Doc;
31
32
  export type Rules = StoreRules & {
32
33
  anonymous?: boolean;
33
34
  derived?: readonly string[];
34
- holds?(d: Doc, touched: Record<string, number[]>): string | null;
35
+ /** What its definitions hold among each collection's rows (`d`, by collection), each the write touched. */
36
+ holds?(d: Record<string, unknown>, touched: Record<string, number[]>): string | null;
35
37
  /** What its lists hold as a write leaves them (definitions' within and apart), asked on SQLite: Postgres's triggers
36
38
  * hold them, at the write's end (the store's settle). */
37
39
  listsHold?(d: Doc, touched: Record<string, number[]>): string | null;
@@ -59,6 +61,9 @@ export type Rules = StoreRules & {
59
61
  reads?: readonly string[];
60
62
  /** Who may hold it at all (definitions' where), each a role: null, anyone. */
61
63
  mayHold?: readonly string[] | null;
64
+ /** Each link whose every id names one who holds a role: that role, and the words another is refused in (definitions'
65
+ * links, holds). */
66
+ names?: Record<string, readonly [(m: number, read: Read, doc: string) => boolean, string]>;
62
67
  type?: "static" | "read-only" | "shared";
63
68
  };
64
69
  /** An app's own rules for a write (its trust.ts), which no story can say: why it's refused, or null. Asked
@@ -85,6 +90,11 @@ class Missing {
85
90
  ) {}
86
91
  }
87
92
 
93
+ /** A write kept while away that's made already, and the version it made. */
94
+ export class Made {
95
+ constructor(readonly version: number) {}
96
+ }
97
+
88
98
  /** How many rounds of reactions a write may set off before it's refused as never settling. */
89
99
  const ROUNDS = 10;
90
100
 
@@ -186,7 +196,23 @@ export function writes({
186
196
  * root's code at a level (src/visitors.ts), who may do what its level may alone, or the root's own by an item's
187
197
  * code, where a guest may do nothing. */
188
198
  const anyoneIs = (doc: string, member: number | null) =>
189
- member !== null || (open && (!byCode(doc) || (!levelled(rulesOf(doc)) && !rootKind(doc))));
199
+ member !== null || (open && (byCode(doc) ? !levelled(rulesOf(doc)) && !rootKind(doc) : !held(doc)));
200
+ /** Whether a page holds a document that isn't a kind by an item's code (`order?code=…`): its guest, who may do
201
+ * what a guest may, never what any member may. */
202
+ const held = (doc: string) => {
203
+ const { params } = docParts(doc);
204
+ return Object.values(rulesOf(doc).guests ?? {}).some((code) => params[code] !== undefined);
205
+ };
206
+ /** Whether the code a page holds a document by names one of its items: a made-up code holds nothing. */
207
+ const itsCode = (doc: string) => {
208
+ const { base, params } = docParts(doc),
209
+ whole = read(base);
210
+ return Object.entries(rulesOf(doc).guests ?? {}).some(
211
+ ([coll, code]) =>
212
+ params[code] !== undefined &&
213
+ ((whole[coll] ?? []) as Record<string, unknown>[]).some((i) => i[code] === params[code]),
214
+ );
215
+ };
190
216
 
191
217
  /** Why a write does what no story does (an op of a form no path has, or one no story grants), or what the
192
218
  * writer's roles may not; null if neither. `roles` null: the server's own write, or nobody's on an open group,
@@ -380,6 +406,47 @@ export function writes({
380
406
  }
381
407
  return null;
382
408
  }
409
+ /** Why a write names someone in a link who doesn't hold the role it names only holders of (definitions' links,
410
+ * holds: a supply's supplier, a seller), or null: each id it gives the field, as an item's or the field's own. */
411
+ function namedIn(doc: string, ops: Op[]) {
412
+ const r = rulesOf(doc);
413
+ if (!r.names) return null;
414
+ for (const o of ops) {
415
+ if (o.op === "remove") continue;
416
+ const { field } = parts(o.path);
417
+ // a field given its value, or an item given whole (an add, a replace)
418
+ const given: [string, unknown][] = field !== undefined ? [[field, o.value]] : Object.entries(o.value ?? {});
419
+ for (const [f, v] of given) {
420
+ const [is, refused] = r.names[f] ?? [];
421
+ if (is && [v ?? []].flat().some((id) => typeof id === "number" && !is(id, read, doc))) return refused!;
422
+ }
423
+ }
424
+ return null;
425
+ }
426
+ /** Why a write links to what the document it's written to doesn't hold (a comment on another board's post, which
427
+ * nobody there could see, nor then remove the post), or null: each id it gives a link to one of the document's own
428
+ * collections is of an item in it, as the write leaves it (so one it adds is): in a kind, its instance's; held by an
429
+ * item's code, what the code holds. Its words, the table's. */
430
+ function beyond(doc: string, applied: Op[], member: number) {
431
+ const r = rulesOf(doc),
432
+ guest = byCode(doc) || held(doc);
433
+ let holds: Doc | undefined;
434
+ for (const o of applied) {
435
+ if (o.op === "remove") continue;
436
+ const { coll, field, link } = parts(o.path),
437
+ value = link !== undefined && /^[a-z]/.test(link) ? { [link]: o.value } : o.value,
438
+ item = field === undefined ? value : { [field]: value };
439
+ for (const [f, to] of Object.entries(r.collections[coll]?.links ?? {})) {
440
+ // (an object's field, terms.item)
441
+ const v = f.split(".").reduce<any>((at, k) => at?.[k], item);
442
+ if (v == null || !(to in r.collections)) continue;
443
+ const items = ((holds ??= guest ? view(doc, member) : read(docParts(doc).base))[to] ?? []) as { id: number }[];
444
+ if ([v].flat().some((id) => !items.some((i) => i.id === id)))
445
+ return `${f} links only to ${to} the ${r.doc} document holds`;
446
+ }
447
+ }
448
+ return null;
449
+ }
383
450
  /** Why a write gives or takes another's id in a list that's each member's own (definitions' mine), or null: an id
384
451
  * added or taken, a list replaced or removed whole (the ids that changes), or an item added with one. */
385
452
  function othersIn(doc: string, ops: Op[], member: number) {
@@ -427,13 +494,27 @@ export function writes({
427
494
  btoa(String.fromCharCode(...crypto.getRandomValues(new Uint8Array(9))))
428
495
  .replace(/\+/g, "-")
429
496
  .replace(/\//g, "_");
430
- /** A write's adds with the fields the server fills, where they don't give them: "now" is the instant, "random" a code
431
- * no one can guess, "me" its writer (`by`); and those
497
+ /** Now, on the clock of the zone a wall clock is on (the first said of its collection's clock: the item's own, its
498
+ * kind's root's, the document's own), or refused: there's none to say it on. */
499
+ function wallNow(doc: string, coll: string, f: string, value: Record<string, unknown>) {
500
+ const r = rulesOf(doc);
501
+ const zone = r.collections[coll]!.clock!.map(
502
+ (c) => (c === "item" ? value : c === "root" ? rootItem(r, doc, read) : read(doc))?.zone,
503
+ ).find((z) => z !== undefined);
504
+ if (zone === undefined) throw new Refused(`${f} is now on its zone's clock, and no zone is said`);
505
+ try {
506
+ return wallIn(zone as string);
507
+ } catch {
508
+ throw new Refused(`${f} is now on its zone's clock, and ${zone} isn't a time zone`);
509
+ }
510
+ }
511
+ /** A write's adds with the fields the server fills, where they don't give them: "now" is the instant (a wall clock,
512
+ * where the field is one), "random" a code no one can guess, "me" its writer (`by`); and those
432
513
  * copied from what a link points at, as it is now (none, where it points at nothing: the table refuses that). */
433
514
  function fill(doc: string, ops: Op[], by: number | null) {
434
515
  return ops.map((o) => {
435
516
  const { coll, key, field } = parts(o.path);
436
- const { fills, copies } = rulesOf(doc).collections[coll] ?? {};
517
+ const { fills, copies, fields } = rulesOf(doc).collections[coll] ?? {};
437
518
  if (copies && o.op === "add" && key === "-" && field === undefined) {
438
519
  const from = (read(copies.at)[copies.to] as Record<string, unknown>[]).find(
439
520
  (i) => i.id === o.value?.[copies.from],
@@ -448,7 +529,15 @@ export function writes({
448
529
  ...Object.fromEntries(
449
530
  Object.entries(fills).map(([f, v]) => [
450
531
  f,
451
- v === "now" ? now : v === "random" ? random() : v === "me" ? by : v,
532
+ v === "now"
533
+ ? fields![f] === "date-time"
534
+ ? wallNow(doc, coll, f, o.value ?? {})
535
+ : now
536
+ : v === "random"
537
+ ? random()
538
+ : v === "me"
539
+ ? by
540
+ : v,
452
541
  ]),
453
542
  ),
454
543
  ...o.value,
@@ -505,7 +594,9 @@ export function writes({
505
594
  : byCode(doc) && !admits(r, guestOf(doc, r.kind!.root, undefined))
506
595
  )
507
596
  return "No access";
508
- const guest = byCode(doc) || Object.values(r.guests ?? {}).some((code) => params[code] !== undefined);
597
+ // an item's code that names none of its items: No access, as a kind's is
598
+ if (!k && !byCode(doc) && held(doc) && !itsCode(doc)) return "No access";
599
+ const guest = byCode(doc) || held(doc);
509
600
  if (member === null && !open && !r.anonymous && !guest) return "sign in with your link first";
510
601
  if (r.mayHold && !guest && !(member !== null && r.rolesOf!(member, read, doc).some((x) => r.mayHold!.includes(x))))
511
602
  return "No access";
@@ -551,6 +642,7 @@ export function writes({
551
642
  anyoneIs(doc, who?.member ?? null),
552
643
  undoing,
553
644
  ) ??
645
+ namedIn(doc, ops) ??
554
646
  // of a kind, what its root item's settings say of a write the grants allow (a frozen board, one held for approval)
555
647
  settled(
556
648
  r,
@@ -563,10 +655,17 @@ export function writes({
563
655
  if (ruled) throw new Refused(ruled);
564
656
  // a code it makes new, the server's (whatever the page gave), before it's kept
565
657
  ops = renewed(doc, ops);
566
- if (groupless(doc, who)) return { ops };
567
- const write = await group(docParts(doc).base, ops);
658
+ const write = groupless(doc, who) ? { ops } : await group(docParts(doc).base, ops);
568
659
  if ("refused" in write) throw new Refused(write.refused);
569
- return write;
660
+ // of a kind's instance, or held by an item's code, it links to nothing another holds: asked of it as made, before
661
+ // it's kept
662
+ if (!r.kind && !byCode(doc) && !held(doc)) return write;
663
+ const within = async (applied: Op[]) => {
664
+ const why = await settle(() => beyond(doc, applied, who?.member ?? 0));
665
+ if (why) throw new Refused(why);
666
+ if ("within" in write) await write.within?.(applied);
667
+ };
668
+ return { ops: write.ops, within };
570
669
  }
571
670
 
572
671
  /** A write and what follows from it (each app's reactions, round after round until none writes), in one
@@ -574,22 +673,29 @@ export function writes({
574
673
  * turn, named by the adds before it. Its changes, the first the document written first's; each part's own (`parts`);
575
674
  * what's told to each part of a document the pages hold (`held`); and the ops as its parts made them. `asked`: a
576
675
  * page's write, each part asked its rules first, in the transaction; `undoes`, the version the write puts back, if
577
- * it's an undo. */
676
+ * it's an undo; `kept`, the id a page gave a write it kept while away, kept with the first part's change (whose
677
+ * version is the write's). */
578
678
  async function land(
579
679
  writes: Part[],
580
680
  by: number | null,
581
681
  via: string | null,
582
682
  {
583
683
  undoes,
684
+ kept,
584
685
  asked,
585
686
  held,
586
687
  }: {
587
688
  undoes?: number;
689
+ kept?: string;
588
690
  asked?: (doc: string, ops: Op[], why?: string) => Promise<{ ops: Op[]; within?: (applied: Op[]) => unknown }>;
589
691
  held: Held;
590
692
  },
591
693
  ) {
592
694
  return store.db.transaction(async () => {
695
+ // one a page kept while away, made already: looked for as it's made, in the same transaction, so two sent at
696
+ // once (two tabs, two servers) make it once
697
+ const made = kept === undefined ? undefined : await store.keptAs(kept);
698
+ if (made !== undefined) throw new Made(made);
593
699
  // what each person holding a part of a document saw of it, before
594
700
  const before = await settle(() => new Map(held.views.map((v) => [v.topic, view(v.doc, v.member)])));
595
701
  const changes: Change[] = [],
@@ -603,16 +709,20 @@ export function writes({
603
709
  v: string | null,
604
710
  w?: (applied: Op[]) => unknown,
605
711
  u?: number,
712
+ k?: string,
606
713
  ) => {
607
714
  // (an undo puts back what was, filled as it was then: a field cleared since stays clear)
608
715
  const gone = await settle(() => withGone(d, o));
609
716
  const filled = u === undefined ? await settle(() => fill(d, gone, b)) : gone;
610
- const made = await store.write(d, filled, b, v, w, { undoes: u });
717
+ const made = await store.write(d, filled, b, v, w, { undoes: u, kept: k });
611
718
  // what the definitions hold of it (unique, noOverlap), once the write is done: refused whole if not
612
719
  const r = rulesOf(d),
613
720
  touched = touchedBy(made.applied);
721
+ // (unique and noOverlap among every row of a collection's table, not only those its where holds)
722
+ const all: Record<string, Awaited<ReturnType<Store["rowsOf"]>>> = {};
723
+ if (r.holds) for (const c of Object.keys(touched)) all[c] = await store.rowsOf(d, c);
614
724
  const held = await settle(
615
- () => r.holds?.(read(d), touched) ?? (store.db.dialect === "sqlite" ? r.listsHold?.(read(d), touched) : null),
725
+ () => r.holds?.(all, touched) ?? (store.db.dialect === "sqlite" ? r.listsHold?.(read(d), touched) : null),
616
726
  );
617
727
  if (held) throw new Refused(held);
618
728
  for (const [name, r] of Object.entries(made.rows)) (rows[name] ??= []).push(...r);
@@ -629,10 +739,15 @@ export function writes({
629
739
  // each part named as the write names it (src/together.ts), and landed in turn
630
740
  const adds: { coll: string; id: number }[] = [];
631
741
  for (const part of writes) {
632
- const w = named(part, adds, (name) => rules[name]?.kind?.root);
742
+ const w = named(
743
+ part,
744
+ adds,
745
+ (name) => rules[name]?.kind?.root,
746
+ (name) => rules[name]?.collections,
747
+ );
633
748
  // a page's write is asked first, here: refused, none of it lands
634
749
  const { ops, within } = (await asked?.(w.doc, w.ops, w.why)) ?? { ops: w.ops };
635
- const made = await one(docParts(w.doc).base, ops, by, via, within, undoes);
750
+ const made = await one(docParts(w.doc).base, ops, by, via, within, undoes, own.length ? undefined : kept);
636
751
  applied.push(...made.applied);
637
752
  own.push(made.changes[0]!);
638
753
  next.push(...made.changes);
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ Where this app has been, newest first, a line in its entry as each change lands; what's open is in `todo.jsonl`.
4
+
5
+ ## [Unreleased]
6
+
7
+ - **Begun from `bun create joined`**: hello, the joined skill, the scripts, and the record (this, `todo.jsonl`, and
8
+ `.githooks/pre-commit`, which refuses a commit that carries neither).
package/starter/CLAUDE.md CHANGED
@@ -14,6 +14,8 @@ only the section of its `reference.md` your task needs. joined's own files (`src
14
14
  - `apps/members.json`, once an app has members: the group's seed, its people by id and name (§11 of the skill).
15
15
  - `tests/`: each app's stories told (`joined/stories`), its page's in a browser (`hello-page.test.ts`), and
16
16
  anything else of the app's own.
17
+ - The record: `CHANGELOG.md` (where this app has been) and `todo.jsonl` (what's open, a JSON object a line, each
18
+ with its number, `n`).
17
19
  - What the pages change is kept in `.data/` (`JOINED_DATA`); `.env` holds `ROOT_TOKEN` once an app has members.
18
20
 
19
21
  ## Rules
@@ -31,7 +33,11 @@ only the section of its `reference.md` your task needs. joined's own files (`src
31
33
  - **Look at a change in the page** (`bun run dev`) before calling it done. `dev` runs a demo on this machine: an
32
34
  app's home page carries `<joined-demo>` (`import "joined/demo"`), a line to be anyone in the group, the BDFL first,
33
35
  so looking as Nora always has a way back. The live site is never a demo.
36
+ - **The record.** Every commit stages `CHANGELOG.md` or `todo.jsonl` beside its change (`.githooks/pre-commit`
37
+ refuses one without; `bun install` wires it): a small fix is a line in the entry it belongs to. Every "Not yet" in
38
+ the CHANGELOG names its todo (`todo 4`), each part of it (`tests/records.test.ts`). When later work makes an entry
39
+ untrue, a new entry says so, and the old one stands. Never `--no-verify`.
34
40
  - **The gate**, before a commit: `bun check` (the types: a link to one member may be none, once they've left),
35
- `bun fmt --check` (`bun fmt` formats; never what the compiler writes) and `bun test`.
41
+ `bun fmt --check` (`bun fmt` to format; what the compiler writes is left alone, `.prettierignore`) and `bun test`.
36
42
  - **joined is upgraded by `bun run upgrade [version]`:** it moves the version, refreshes the skill and
37
43
  compiles again.
package/starter/bunfig CHANGED
@@ -1,4 +1,5 @@
1
1
  [fmt]
2
- # bun fmt: every file but what the compiler writes (.prettierignore), as joined has it
2
+ # bun fmt: every file but what the compiler writes (.prettierignore), held by bun fmt --check in the gate
3
3
  printWidth = 120
4
+ # a document's code is shown as it is: a story is one line
4
5
  embeddedLanguageFormatting = "off"
@@ -0,0 +1,13 @@
1
+ #!/bin/sh
2
+ # Every commit carries its record (CLAUDE.md, "The record"): CHANGELOG.md, where this app has been, or todo.jsonl,
3
+ # what's open, staged beside the change. A small fix is a line added to the entry it belongs to.
4
+ staged=$(git diff --cached --name-only)
5
+ [ -z "$staged" ] && exit 0
6
+ if echo "$staged" | grep -qx -e CHANGELOG.md -e todo.jsonl; then
7
+ # and what it says holds: each "Not yet" names its todo (quick: the record's test alone)
8
+ bun test tests/records.test.ts >/dev/null 2>&1 && exit 0
9
+ echo "Refused: the record doesn't hold. Run: bun test tests/records.test.ts" >&2
10
+ exit 1
11
+ fi
12
+ echo "Refused: a commit carries its record. Stage CHANGELOG.md (a line in the entry the change belongs to) or todo.jsonl beside it." >&2
13
+ exit 1
@@ -1,3 +1,4 @@
1
+ # what the compiler writes: bun run compile reads it back, so bun fmt leaves it as it is
1
2
  apps/*/generated/
2
3
  apps/*/migrations/
3
4
  # joined's skill, refreshed by bun run upgrade: left as it comes
@@ -0,0 +1,40 @@
1
+ // The record (CLAUDE.md): CHANGELOG.md says where this app has been, todo.jsonl what's open, a JSON object a line,
2
+ // each with its number, `n`. Every "Not yet" in the CHANGELOG names the todo that holds it (`todo 4`, or `#4`), each
3
+ // of its parts (split by ";") one, and every todo it names is there; and this checkout's commits pass through
4
+ // .githooks/pre-commit, which refuses a commit without its record.
5
+
6
+ import { expect, test } from "bun:test";
7
+ import { existsSync } from "node:fs";
8
+ import { resolve } from "node:path";
9
+
10
+ const root = `${import.meta.dir}/..`;
11
+ const todos = new Set(
12
+ (await Bun.file(`${root}/todo.jsonl`).text())
13
+ .split("\n")
14
+ .filter(Boolean)
15
+ .map((l) => (JSON.parse(l) as { n: number }).n),
16
+ );
17
+ const entries = (await Bun.file(`${root}/CHANGELOG.md`).text()).split(/\n(?=- )/).map((e) => e.replace(/\s+/g, " "));
18
+ /** A todo named: `todo 4`, or `#4`. */
19
+ const TODO = /(?:todo |#)(\d+)\b/g;
20
+
21
+ test("every Not yet in the CHANGELOG names its todo", () => {
22
+ const untracked: string[] = [];
23
+ for (const e of entries)
24
+ for (const m of e.matchAll(/Not yet(?:, [^:.]{0,40}:|:)?\s([^]*?)(?=\. [A-Z*]|\.$|$)/g))
25
+ for (const part of m[1]!.split(";"))
26
+ if (!new RegExp(TODO.source).test(part)) untracked.push(`${e.slice(2, 60)}…: Not yet${part}`);
27
+ expect(untracked).toEqual([]);
28
+ });
29
+
30
+ test("every todo the CHANGELOG names is in todo.jsonl", () => {
31
+ const named = entries.flatMap((e) => [...e.matchAll(TODO)].map((m) => Number(m[1])));
32
+ expect(named.filter((n) => !todos.has(n))).toEqual([]);
33
+ });
34
+
35
+ test("commits here pass through the record's hook", async () => {
36
+ if (!existsSync(`${root}/.git`)) return;
37
+ // (said as it's wired, or whole, as a worktree's tools write it)
38
+ const path = (await Bun.$`git -C ${root} config core.hooksPath`.nothrow().text()).trim();
39
+ expect(resolve(root, path), "run `bun install` (its prepare wires .githooks)").toBe(resolve(root, ".githooks"));
40
+ });
File without changes