slateboard 0.1.0 → 0.1.1

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 (115) hide show
  1. package/README.md +33 -192
  2. package/dist/arch-3JZTL2DJ.js +1842 -0
  3. package/dist/bin.js +35 -11
  4. package/dist/{chunk-WXM4BB4D.js → chunk-4PKRRMRZ.js} +1340 -868
  5. package/dist/{chunk-FMO5B2KJ.js → chunk-4TPC7U6A.js} +5 -5
  6. package/dist/{chunk-SQHGMBUM.js → chunk-ANFNDJZO.js} +3 -2
  7. package/dist/{chunk-ONZFKR4I.js → chunk-PJ5WOZB3.js} +171 -21
  8. package/dist/{chunk-BWNUX4FT.js → chunk-V3PED2Z5.js} +4 -4
  9. package/dist/{client-JHI2EG6J.js → client-5B46626J.js} +2 -2
  10. package/dist/{commands-ONES545N.js → commands-6UA3YOD4.js} +1 -1
  11. package/dist/{doctor-H5Y5L2JZ.js → doctor-ZTQFKV32.js} +2 -2
  12. package/dist/{lifecycle-ZB5HEO5P.js → lifecycle-IZH4RJK5.js} +4 -4
  13. package/dist/{service-command-26BPMBK3.js → service-command-GKRIZCBL.js} +5 -5
  14. package/dist/{src-QZIVUACM.js → src-BDZFYUYY.js} +12 -2
  15. package/dist/{src-YVFB3ZLM.js → src-YO7L7J26.js} +13 -1
  16. package/dist/ui/assets/abnfDiagram-XWFEHMT6-DAC8TnbO.js +1 -0
  17. package/dist/ui/assets/architecture-WOLXFQ4H-X8k0-LVf.js +1 -0
  18. package/dist/ui/assets/architectureDiagram-CSQXQB3N-CVoxvA0s.js +36 -0
  19. package/dist/ui/assets/blockDiagram-BEDRHYPZ-DGf5VAwB.js +140 -0
  20. package/dist/ui/assets/bpmnIcons-APHXDYXF-C0jbCElo.js +1 -0
  21. package/dist/ui/assets/c4Diagram-M2UUVUY5-PB5quCOl.js +38 -0
  22. package/dist/ui/assets/chunk-2Q5K7J3B-C1jixKkw.js +1 -0
  23. package/dist/ui/assets/chunk-3GCGMST5-RRiusQp9.js +1 -0
  24. package/dist/ui/assets/chunk-5VM5RSS4-ZNzvKenW.js +15 -0
  25. package/dist/ui/assets/chunk-7U7NFRK5-CSOOpKZT.js +88 -0
  26. package/dist/ui/assets/chunk-CNRTWJTD-DJuDnaYn.js +1 -0
  27. package/dist/ui/assets/chunk-D5HYT7QG-imLQxbAy.js +1 -0
  28. package/dist/ui/assets/chunk-DUW6YSOI-Dgx8z5s3.js +1 -0
  29. package/dist/ui/assets/chunk-DZSZGQHW-BCXsfFfT.js +1 -0
  30. package/dist/ui/assets/chunk-EBZ3SEQC-CdDips7b.js +2 -0
  31. package/dist/ui/assets/chunk-F3AE6A5H-DTVcMSk7.js +1 -0
  32. package/dist/ui/assets/chunk-FGVZ23HU-BEVs0fgA.js +213 -0
  33. package/dist/ui/assets/chunk-GZTWQ64R-CKGVWw4I.js +62 -0
  34. package/dist/ui/assets/chunk-J5ZVWO5B-oDCd-gWO.js +1 -0
  35. package/dist/ui/assets/chunk-JWPE2WC7-DVXcaiue.js +1 -0
  36. package/dist/ui/assets/chunk-KTR4FSNJ-DSr3q0Xy.js +1 -0
  37. package/dist/ui/assets/chunk-MDAHDJXZ-YMIkXJ0O.js +10 -0
  38. package/dist/ui/assets/chunk-MPYPSXSE-C-CxVwa7.js +1 -0
  39. package/dist/ui/assets/chunk-ND7LMLKX-lfusdDHU.js +72 -0
  40. package/dist/ui/assets/chunk-NGNAAXSQ-DqoPQk1a.js +136 -0
  41. package/dist/ui/assets/chunk-OWCVCYLK-4-W-ynqW.js +2 -0
  42. package/dist/ui/assets/chunk-QDWOWVBQ-Du0KmhW4.js +129 -0
  43. package/dist/ui/assets/chunk-T47YP6PS-CKli33QU.js +1 -0
  44. package/dist/ui/assets/chunk-XXDRQBXY-DSL17ZTh.js +1 -0
  45. package/dist/ui/assets/chunk-Y2CYZVJY-DsF7k-Jl.js +1 -0
  46. package/dist/ui/assets/classDiagram-v2-KXABOMEV-CYc2BZ2y.js +217 -0
  47. package/dist/ui/assets/cose-bilkent-JH36ORCC-81nUs0at.js +1 -0
  48. package/dist/ui/assets/cynefin-EF2NZ3EQ-Clvwy422.js +1 -0
  49. package/dist/ui/assets/cynefinDiagram-NJNITYFG-CsgTQqAC.js +62 -0
  50. package/dist/ui/assets/cytoscape.esm-BPveszXl.js +321 -0
  51. package/dist/ui/assets/d3-scale-lXtN6-Od.js +1 -0
  52. package/dist/ui/assets/d3-selection-BFzs9NTX.js +1 -0
  53. package/dist/ui/assets/dagre-KIHZ2IZ3--BpWd3hW.js +4 -0
  54. package/dist/ui/assets/diagram-7YQZDPLS-Dp_m-C1a.js +41 -0
  55. package/dist/ui/assets/diagram-QBROCOUO-Bt-Lp7vq.js +200 -0
  56. package/dist/ui/assets/diagram-RJJCUUZO-DLsG2Tej.js +30 -0
  57. package/dist/ui/assets/diagram-WERXNKYE-D31SLp70.js +24 -0
  58. package/dist/ui/assets/diagram-YHHI257C-CVMeUILe.js +3 -0
  59. package/dist/ui/assets/diagram-YR4HJLHV-Bz9qvIhJ.js +24 -0
  60. package/dist/ui/assets/dist-YCovsM_S.js +1 -0
  61. package/dist/ui/assets/ebnfDiagram-N527522P-_FIZSf8P.js +1 -0
  62. package/dist/ui/assets/elk-O5DQBFGD-BK3qD3UW.js +27 -0
  63. package/dist/ui/assets/erDiagram-K3K3BIDK-Dmpdi5Ob.js +99 -0
  64. package/dist/ui/assets/eventmodeling-K75KTNOO-Dt-51L4s.js +1 -0
  65. package/dist/ui/assets/flowDiagram-Z6JWZHQI-Cn2ZVzvO.js +1 -0
  66. package/dist/ui/assets/ganttDiagram-3PRQTZWP-BaZof7eT.js +292 -0
  67. package/dist/ui/assets/gitGraph-VSP46ZUC-ezyaB0jQ.js +1 -0
  68. package/dist/ui/assets/gitGraphDiagram-VXDFKS5L-DRNdClPw.js +106 -0
  69. package/dist/ui/assets/graphlib-DS17s2tU.js +1 -0
  70. package/dist/ui/assets/grid-E2QIVN74--djCUwdI.js +1 -0
  71. package/dist/ui/assets/index-Bly281F6.css +1 -0
  72. package/dist/ui/assets/index-CXK8WmR8.js +45 -0
  73. package/dist/ui/assets/info-OHQRW6UA-DsFXrFWI.js +1 -0
  74. package/dist/ui/assets/infoDiagram-EZ3ZOAHP-e8qx3eqc.js +2 -0
  75. package/dist/ui/assets/ishikawaDiagram-S3EKX5GW-CuKExPKN.js +70 -0
  76. package/dist/ui/assets/journeyDiagram-POQNLL5X-D0GE8iji.js +139 -0
  77. package/dist/ui/assets/kanban-definition-BH5XI6FM-NL5dOF_0.js +89 -0
  78. package/dist/ui/assets/katex-BXIx1Jgr.js +257 -0
  79. package/dist/ui/assets/mermaid-parser.core-0pE4JCc_.js +7 -0
  80. package/dist/ui/assets/mermaid.core-BVgUieVU.js +44 -0
  81. package/dist/ui/assets/mindmap-definition-WVAN44T4-BLTtjuVH.js +98 -0
  82. package/dist/ui/assets/packet-JDAUHWVQ-C-7DeilZ.js +1 -0
  83. package/dist/ui/assets/pegDiagram-D4NLKWP3-F2SSXiqv.js +1 -0
  84. package/dist/ui/assets/pie-XZMESJXO-B4BkiWTy.js +1 -0
  85. package/dist/ui/assets/pieDiagram-36ENHN4W-BB5uEdtB.js +39 -0
  86. package/dist/ui/assets/quadrantDiagram-ZQUDMS73-B5iPooYO.js +7 -0
  87. package/dist/ui/assets/radar-ABXABTNO-Dx3jkQdr.js +1 -0
  88. package/dist/ui/assets/railroad-I3PHUGI6-BSh47OT_.js +1 -0
  89. package/dist/ui/assets/railroad-abnf-LNEFI6M7-BWFvDxOj.js +1 -0
  90. package/dist/ui/assets/railroad-ebnf-DWYD2UWJ-GBoLzumA.js +1 -0
  91. package/dist/ui/assets/railroad-peg-JR7BVNR7-DByw5Orh.js +1 -0
  92. package/dist/ui/assets/railroadDiagram-JIZHGYPL--ptGd2NR.js +1 -0
  93. package/dist/ui/assets/render-VIF2ZAQL-CzNp-J42.js +2 -0
  94. package/dist/ui/assets/requirementDiagram-AXW2TVFA-DBh9Dt63.js +84 -0
  95. package/dist/ui/assets/rough.esm-Dy-Kn_BL.js +1 -0
  96. package/dist/ui/assets/sankeyDiagram-FBCJTAIF-CjJtGyu8.js +40 -0
  97. package/dist/ui/assets/sequenceDiagram-3LA2ROMG-BzeMVuzG.js +169 -0
  98. package/dist/ui/assets/sizeCapture-2Q2CQKSF-DSY_W0YL.js +1 -0
  99. package/dist/ui/assets/stateDiagram-v2-ATKHQDJO-DYavre2v.js +291 -0
  100. package/dist/ui/assets/swimlanes-YQL5WMAO-CUTCsfPM.js +1 -0
  101. package/dist/ui/assets/swimlanesDiagram-UCCPES4V-B7bXxKVr.js +8 -0
  102. package/dist/ui/assets/timeline-definition-7Z437IG3-HWrtH0QT.js +120 -0
  103. package/dist/ui/assets/treeView-D4JQ5SDB-B5lbyI_M.js +1 -0
  104. package/dist/ui/assets/treemap-SAJKECNS-Ckfi-DGc.js +1 -0
  105. package/dist/ui/assets/usecaseDiagram-RDK6N6HP-BuKN2NAW.js +328 -0
  106. package/dist/ui/assets/vennDiagram-SHRQU5PJ-s2gljkjP.js +34 -0
  107. package/dist/ui/assets/wardley-7MLQ67FV-CjAqYBcP.js +1 -0
  108. package/dist/ui/assets/wardleyDiagram-F3OXNVQS-Ba_SoMTx.js +78 -0
  109. package/dist/ui/assets/xychartDiagram-GDYJKCDI-FsxUUoqL.js +7 -0
  110. package/dist/ui/index.html +2 -2
  111. package/dist/{upgrade-FND3UBJR.js → upgrade-2CI4OVTY.js} +15 -15
  112. package/migrations/0006_arch_auto.sql +8 -0
  113. package/package.json +1 -1
  114. package/dist/ui/assets/index-4WzXlYHs.css +0 -1
  115. package/dist/ui/assets/index-ZKfByx7Q.js +0 -42
@@ -85,17 +85,17 @@ var require_visit = __commonJS({
85
85
  visit.BREAK = BREAK;
86
86
  visit.SKIP = SKIP;
87
87
  visit.REMOVE = REMOVE;
88
- function visit_(key, node, visitor, path9) {
89
- const ctrl = callVisitor(key, node, visitor, path9);
88
+ function visit_(key, node, visitor, path11) {
89
+ const ctrl = callVisitor(key, node, visitor, path11);
90
90
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
91
- replaceNode(key, path9, ctrl);
92
- return visit_(key, ctrl, visitor, path9);
91
+ replaceNode(key, path11, ctrl);
92
+ return visit_(key, ctrl, visitor, path11);
93
93
  }
94
94
  if (typeof ctrl !== "symbol") {
95
95
  if (identity.isCollection(node)) {
96
- path9 = Object.freeze(path9.concat(node));
96
+ path11 = Object.freeze(path11.concat(node));
97
97
  for (let i = 0; i < node.items.length; ++i) {
98
- const ci = visit_(i, node.items[i], visitor, path9);
98
+ const ci = visit_(i, node.items[i], visitor, path11);
99
99
  if (typeof ci === "number")
100
100
  i = ci - 1;
101
101
  else if (ci === BREAK)
@@ -106,13 +106,13 @@ var require_visit = __commonJS({
106
106
  }
107
107
  }
108
108
  } else if (identity.isPair(node)) {
109
- path9 = Object.freeze(path9.concat(node));
110
- const ck = visit_("key", node.key, visitor, path9);
109
+ path11 = Object.freeze(path11.concat(node));
110
+ const ck = visit_("key", node.key, visitor, path11);
111
111
  if (ck === BREAK)
112
112
  return BREAK;
113
113
  else if (ck === REMOVE)
114
114
  node.key = null;
115
- const cv = visit_("value", node.value, visitor, path9);
115
+ const cv = visit_("value", node.value, visitor, path11);
116
116
  if (cv === BREAK)
117
117
  return BREAK;
118
118
  else if (cv === REMOVE)
@@ -133,17 +133,17 @@ var require_visit = __commonJS({
133
133
  visitAsync.BREAK = BREAK;
134
134
  visitAsync.SKIP = SKIP;
135
135
  visitAsync.REMOVE = REMOVE;
136
- async function visitAsync_(key, node, visitor, path9) {
137
- const ctrl = await callVisitor(key, node, visitor, path9);
136
+ async function visitAsync_(key, node, visitor, path11) {
137
+ const ctrl = await callVisitor(key, node, visitor, path11);
138
138
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
139
- replaceNode(key, path9, ctrl);
140
- return visitAsync_(key, ctrl, visitor, path9);
139
+ replaceNode(key, path11, ctrl);
140
+ return visitAsync_(key, ctrl, visitor, path11);
141
141
  }
142
142
  if (typeof ctrl !== "symbol") {
143
143
  if (identity.isCollection(node)) {
144
- path9 = Object.freeze(path9.concat(node));
144
+ path11 = Object.freeze(path11.concat(node));
145
145
  for (let i = 0; i < node.items.length; ++i) {
146
- const ci = await visitAsync_(i, node.items[i], visitor, path9);
146
+ const ci = await visitAsync_(i, node.items[i], visitor, path11);
147
147
  if (typeof ci === "number")
148
148
  i = ci - 1;
149
149
  else if (ci === BREAK)
@@ -154,13 +154,13 @@ var require_visit = __commonJS({
154
154
  }
155
155
  }
156
156
  } else if (identity.isPair(node)) {
157
- path9 = Object.freeze(path9.concat(node));
158
- const ck = await visitAsync_("key", node.key, visitor, path9);
157
+ path11 = Object.freeze(path11.concat(node));
158
+ const ck = await visitAsync_("key", node.key, visitor, path11);
159
159
  if (ck === BREAK)
160
160
  return BREAK;
161
161
  else if (ck === REMOVE)
162
162
  node.key = null;
163
- const cv = await visitAsync_("value", node.value, visitor, path9);
163
+ const cv = await visitAsync_("value", node.value, visitor, path11);
164
164
  if (cv === BREAK)
165
165
  return BREAK;
166
166
  else if (cv === REMOVE)
@@ -187,23 +187,23 @@ var require_visit = __commonJS({
187
187
  }
188
188
  return visitor;
189
189
  }
190
- function callVisitor(key, node, visitor, path9) {
190
+ function callVisitor(key, node, visitor, path11) {
191
191
  if (typeof visitor === "function")
192
- return visitor(key, node, path9);
192
+ return visitor(key, node, path11);
193
193
  if (identity.isMap(node))
194
- return visitor.Map?.(key, node, path9);
194
+ return visitor.Map?.(key, node, path11);
195
195
  if (identity.isSeq(node))
196
- return visitor.Seq?.(key, node, path9);
196
+ return visitor.Seq?.(key, node, path11);
197
197
  if (identity.isPair(node))
198
- return visitor.Pair?.(key, node, path9);
198
+ return visitor.Pair?.(key, node, path11);
199
199
  if (identity.isScalar(node))
200
- return visitor.Scalar?.(key, node, path9);
200
+ return visitor.Scalar?.(key, node, path11);
201
201
  if (identity.isAlias(node))
202
- return visitor.Alias?.(key, node, path9);
202
+ return visitor.Alias?.(key, node, path11);
203
203
  return void 0;
204
204
  }
205
- function replaceNode(key, path9, node) {
206
- const parent = path9[path9.length - 1];
205
+ function replaceNode(key, path11, node) {
206
+ const parent = path11[path11.length - 1];
207
207
  if (identity.isCollection(parent)) {
208
208
  parent.items[key] = node;
209
209
  } else if (identity.isPair(parent)) {
@@ -815,10 +815,10 @@ var require_Collection = __commonJS({
815
815
  var createNode = require_createNode();
816
816
  var identity = require_identity();
817
817
  var Node = require_Node();
818
- function collectionFromPath(schema, path9, value) {
818
+ function collectionFromPath(schema, path11, value) {
819
819
  let v = value;
820
- for (let i = path9.length - 1; i >= 0; --i) {
821
- const k = path9[i];
820
+ for (let i = path11.length - 1; i >= 0; --i) {
821
+ const k = path11[i];
822
822
  if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
823
823
  const a = [];
824
824
  a[k] = v;
@@ -837,7 +837,7 @@ var require_Collection = __commonJS({
837
837
  sourceObjects: /* @__PURE__ */ new Map()
838
838
  });
839
839
  }
840
- var isEmptyPath = (path9) => path9 == null || typeof path9 === "object" && !!path9[Symbol.iterator]().next().done;
840
+ var isEmptyPath = (path11) => path11 == null || typeof path11 === "object" && !!path11[Symbol.iterator]().next().done;
841
841
  var Collection = class extends Node.NodeBase {
842
842
  constructor(type, schema) {
843
843
  super(type);
@@ -867,11 +867,11 @@ var require_Collection = __commonJS({
867
867
  * be a Pair instance or a `{ key, value }` object, which may not have a key
868
868
  * that already exists in the map.
869
869
  */
870
- addIn(path9, value) {
871
- if (isEmptyPath(path9))
870
+ addIn(path11, value) {
871
+ if (isEmptyPath(path11))
872
872
  this.add(value);
873
873
  else {
874
- const [key, ...rest] = path9;
874
+ const [key, ...rest] = path11;
875
875
  const node = this.get(key, true);
876
876
  if (identity.isCollection(node))
877
877
  node.addIn(rest, value);
@@ -885,8 +885,8 @@ var require_Collection = __commonJS({
885
885
  * Removes a value from the collection.
886
886
  * @returns `true` if the item was found and removed.
887
887
  */
888
- deleteIn(path9) {
889
- const [key, ...rest] = path9;
888
+ deleteIn(path11) {
889
+ const [key, ...rest] = path11;
890
890
  if (rest.length === 0)
891
891
  return this.delete(key);
892
892
  const node = this.get(key, true);
@@ -900,8 +900,8 @@ var require_Collection = __commonJS({
900
900
  * scalar values from their surrounding node; to disable set `keepScalar` to
901
901
  * `true` (collections are always returned intact).
902
902
  */
903
- getIn(path9, keepScalar) {
904
- const [key, ...rest] = path9;
903
+ getIn(path11, keepScalar) {
904
+ const [key, ...rest] = path11;
905
905
  const node = this.get(key, true);
906
906
  if (rest.length === 0)
907
907
  return !keepScalar && identity.isScalar(node) ? node.value : node;
@@ -919,8 +919,8 @@ var require_Collection = __commonJS({
919
919
  /**
920
920
  * Checks if the collection includes a value with the key `key`.
921
921
  */
922
- hasIn(path9) {
923
- const [key, ...rest] = path9;
922
+ hasIn(path11) {
923
+ const [key, ...rest] = path11;
924
924
  if (rest.length === 0)
925
925
  return this.has(key);
926
926
  const node = this.get(key, true);
@@ -930,8 +930,8 @@ var require_Collection = __commonJS({
930
930
  * Sets a value in this collection. For `!!set`, `value` needs to be a
931
931
  * boolean to add/remove the item from the set.
932
932
  */
933
- setIn(path9, value) {
934
- const [key, ...rest] = path9;
933
+ setIn(path11, value) {
934
+ const [key, ...rest] = path11;
935
935
  if (rest.length === 0) {
936
936
  this.set(key, value);
937
937
  } else {
@@ -3446,9 +3446,9 @@ var require_Document = __commonJS({
3446
3446
  this.contents.add(value);
3447
3447
  }
3448
3448
  /** Adds a value to the document. */
3449
- addIn(path9, value) {
3449
+ addIn(path11, value) {
3450
3450
  if (assertCollection(this.contents))
3451
- this.contents.addIn(path9, value);
3451
+ this.contents.addIn(path11, value);
3452
3452
  }
3453
3453
  /**
3454
3454
  * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
@@ -3523,14 +3523,14 @@ var require_Document = __commonJS({
3523
3523
  * Removes a value from the document.
3524
3524
  * @returns `true` if the item was found and removed.
3525
3525
  */
3526
- deleteIn(path9) {
3527
- if (Collection.isEmptyPath(path9)) {
3526
+ deleteIn(path11) {
3527
+ if (Collection.isEmptyPath(path11)) {
3528
3528
  if (this.contents == null)
3529
3529
  return false;
3530
3530
  this.contents = null;
3531
3531
  return true;
3532
3532
  }
3533
- return assertCollection(this.contents) ? this.contents.deleteIn(path9) : false;
3533
+ return assertCollection(this.contents) ? this.contents.deleteIn(path11) : false;
3534
3534
  }
3535
3535
  /**
3536
3536
  * Returns item at `key`, or `undefined` if not found. By default unwraps
@@ -3545,10 +3545,10 @@ var require_Document = __commonJS({
3545
3545
  * scalar values from their surrounding node; to disable set `keepScalar` to
3546
3546
  * `true` (collections are always returned intact).
3547
3547
  */
3548
- getIn(path9, keepScalar) {
3549
- if (Collection.isEmptyPath(path9))
3548
+ getIn(path11, keepScalar) {
3549
+ if (Collection.isEmptyPath(path11))
3550
3550
  return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
3551
- return identity.isCollection(this.contents) ? this.contents.getIn(path9, keepScalar) : void 0;
3551
+ return identity.isCollection(this.contents) ? this.contents.getIn(path11, keepScalar) : void 0;
3552
3552
  }
3553
3553
  /**
3554
3554
  * Checks if the document includes a value with the key `key`.
@@ -3559,10 +3559,10 @@ var require_Document = __commonJS({
3559
3559
  /**
3560
3560
  * Checks if the document includes a value at `path`.
3561
3561
  */
3562
- hasIn(path9) {
3563
- if (Collection.isEmptyPath(path9))
3562
+ hasIn(path11) {
3563
+ if (Collection.isEmptyPath(path11))
3564
3564
  return this.contents !== void 0;
3565
- return identity.isCollection(this.contents) ? this.contents.hasIn(path9) : false;
3565
+ return identity.isCollection(this.contents) ? this.contents.hasIn(path11) : false;
3566
3566
  }
3567
3567
  /**
3568
3568
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -3579,13 +3579,13 @@ var require_Document = __commonJS({
3579
3579
  * Sets a value in this document. For `!!set`, `value` needs to be a
3580
3580
  * boolean to add/remove the item from the set.
3581
3581
  */
3582
- setIn(path9, value) {
3583
- if (Collection.isEmptyPath(path9)) {
3582
+ setIn(path11, value) {
3583
+ if (Collection.isEmptyPath(path11)) {
3584
3584
  this.contents = value;
3585
3585
  } else if (this.contents == null) {
3586
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path9), value);
3586
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path11), value);
3587
3587
  } else if (assertCollection(this.contents)) {
3588
- this.contents.setIn(path9, value);
3588
+ this.contents.setIn(path11, value);
3589
3589
  }
3590
3590
  }
3591
3591
  /**
@@ -5546,9 +5546,9 @@ var require_cst_visit = __commonJS({
5546
5546
  visit.BREAK = BREAK;
5547
5547
  visit.SKIP = SKIP;
5548
5548
  visit.REMOVE = REMOVE;
5549
- visit.itemAtPath = (cst, path9) => {
5549
+ visit.itemAtPath = (cst, path11) => {
5550
5550
  let item = cst;
5551
- for (const [field, index] of path9) {
5551
+ for (const [field, index] of path11) {
5552
5552
  const tok = item?.[field];
5553
5553
  if (tok && "items" in tok) {
5554
5554
  item = tok.items[index];
@@ -5557,23 +5557,23 @@ var require_cst_visit = __commonJS({
5557
5557
  }
5558
5558
  return item;
5559
5559
  };
5560
- visit.parentCollection = (cst, path9) => {
5561
- const parent = visit.itemAtPath(cst, path9.slice(0, -1));
5562
- const field = path9[path9.length - 1][0];
5560
+ visit.parentCollection = (cst, path11) => {
5561
+ const parent = visit.itemAtPath(cst, path11.slice(0, -1));
5562
+ const field = path11[path11.length - 1][0];
5563
5563
  const coll = parent?.[field];
5564
5564
  if (coll && "items" in coll)
5565
5565
  return coll;
5566
5566
  throw new Error("Parent collection not found");
5567
5567
  };
5568
- function _visit(path9, item, visitor) {
5569
- let ctrl = visitor(item, path9);
5568
+ function _visit(path11, item, visitor) {
5569
+ let ctrl = visitor(item, path11);
5570
5570
  if (typeof ctrl === "symbol")
5571
5571
  return ctrl;
5572
5572
  for (const field of ["key", "value"]) {
5573
5573
  const token = item[field];
5574
5574
  if (token && "items" in token) {
5575
5575
  for (let i = 0; i < token.items.length; ++i) {
5576
- const ci = _visit(Object.freeze(path9.concat([[field, i]])), token.items[i], visitor);
5576
+ const ci = _visit(Object.freeze(path11.concat([[field, i]])), token.items[i], visitor);
5577
5577
  if (typeof ci === "number")
5578
5578
  i = ci - 1;
5579
5579
  else if (ci === BREAK)
@@ -5584,10 +5584,10 @@ var require_cst_visit = __commonJS({
5584
5584
  }
5585
5585
  }
5586
5586
  if (typeof ctrl === "function" && field === "key")
5587
- ctrl = ctrl(item, path9);
5587
+ ctrl = ctrl(item, path11);
5588
5588
  }
5589
5589
  }
5590
- return typeof ctrl === "function" ? ctrl(item, path9) : ctrl;
5590
+ return typeof ctrl === "function" ? ctrl(item, path11) : ctrl;
5591
5591
  }
5592
5592
  exports.visit = visit;
5593
5593
  }
@@ -7480,6 +7480,8 @@ var projectUpdateSchema = external_exports.object({
7480
7480
  gitTransitions: external_exports.boolean().optional(),
7481
7481
  /** A path inside the project for the roadmap file, or null to stop keeping it. */
7482
7482
  roadmapFile: external_exports.string().trim().min(1).max(500).nullable().optional(),
7483
+ /** Keep docs/architecture current: regenerate it when HEAD moves (and once when turned on). */
7484
+ archAuto: external_exports.boolean().optional(),
7483
7485
  description: external_exports.string().max(1e4).nullable().optional(),
7484
7486
  milestones: external_exports.array(milestoneSchema).optional(),
7485
7487
  remap: external_exports.record(external_exports.string(), milestoneSchema.nullable()).optional()
@@ -7769,6 +7771,286 @@ var Store = class _Store {
7769
7771
  }
7770
7772
  };
7771
7773
 
7774
+ // ../core/src/services/arch-auto.ts
7775
+ import { existsSync as existsSync4 } from "node:fs";
7776
+
7777
+ // ../core/src/git.ts
7778
+ import fs from "node:fs";
7779
+ import path3 from "node:path";
7780
+ var loaded;
7781
+ var lib = () => loaded ??= import("./isomorphic-git-BZUKICXS.js").then((m) => "log" in m ? m : m.default);
7782
+ var GIT_CACHE_TTL_MS = 15e3;
7783
+ var DEFAULT_COMMIT_SCAN = 500;
7784
+ var MAX_COMMIT_SCAN = 5e3;
7785
+ var SHORT = 7;
7786
+ var cache = /* @__PURE__ */ new Map();
7787
+ function clearGitCache() {
7788
+ cache.clear();
7789
+ diffs.clear();
7790
+ }
7791
+ function isDir(p) {
7792
+ try {
7793
+ return fs.statSync(p).isDirectory();
7794
+ } catch {
7795
+ return false;
7796
+ }
7797
+ }
7798
+ function isFile(p) {
7799
+ try {
7800
+ return fs.statSync(p).isFile();
7801
+ } catch {
7802
+ return false;
7803
+ }
7804
+ }
7805
+ function valid(repo) {
7806
+ return isFile(path3.join(repo.headDir, "HEAD")) && isDir(path3.join(repo.gitdir, "objects")) ? repo : null;
7807
+ }
7808
+ function fromGitFile(dotgit) {
7809
+ const match = /^gitdir:\s*(.+?)\s*$/m.exec(fs.readFileSync(dotgit, "utf8"));
7810
+ if (!match?.[1]) return null;
7811
+ const headDir = path3.resolve(path3.dirname(dotgit), match[1]);
7812
+ const commondir = path3.join(headDir, "commondir");
7813
+ const gitdir = isFile(commondir) ? path3.resolve(headDir, fs.readFileSync(commondir, "utf8").trim()) : headDir;
7814
+ return valid({ gitdir, headDir });
7815
+ }
7816
+ function currentBranch(repoPath) {
7817
+ const repo = locateRepo(repoPath);
7818
+ if (!repo) return null;
7819
+ try {
7820
+ const head = fs.readFileSync(path3.join(repo.headDir, "HEAD"), "utf8").trim();
7821
+ return /^ref: refs\/heads\/(.+)$/.exec(head)?.[1] ?? null;
7822
+ } catch {
7823
+ return null;
7824
+ }
7825
+ }
7826
+ async function defaultBranchShas(repoPath, limit = DEFAULT_COMMIT_SCAN) {
7827
+ const repo = locateRepo(repoPath);
7828
+ if (!repo) return /* @__PURE__ */ new Set();
7829
+ const git = await lib();
7830
+ for (const ref of ["refs/remotes/origin/HEAD", "refs/heads/main", "refs/heads/master"]) {
7831
+ try {
7832
+ const oid = await git.resolveRef({ fs, gitdir: repo.gitdir, ref });
7833
+ const log = await git.log({ fs, gitdir: repo.gitdir, ref: oid, depth: Math.min(limit, MAX_COMMIT_SCAN) });
7834
+ return new Set(log.map((c) => c.oid));
7835
+ } catch {
7836
+ }
7837
+ }
7838
+ return /* @__PURE__ */ new Set();
7839
+ }
7840
+ function keyFromBranch(branch) {
7841
+ return branch && /^slate\/([A-Za-z]{2,5}-\d{1,9})(?:-|$)/.exec(branch)?.[1]?.toUpperCase() || null;
7842
+ }
7843
+ function locateRepo(repoPath) {
7844
+ try {
7845
+ const start = path3.resolve(repoPath);
7846
+ if (!isDir(start)) return null;
7847
+ if (isFile(path3.join(start, "HEAD")) && isDir(path3.join(start, "refs"))) {
7848
+ const bare = valid({ gitdir: start, headDir: start });
7849
+ if (bare) return bare;
7850
+ }
7851
+ for (let dir = start; ; dir = path3.dirname(dir)) {
7852
+ const dotgit = path3.join(dir, ".git");
7853
+ let stat;
7854
+ try {
7855
+ stat = fs.statSync(dotgit);
7856
+ } catch {
7857
+ stat = void 0;
7858
+ }
7859
+ if (stat?.isDirectory()) return valid({ gitdir: dotgit, headDir: dotgit });
7860
+ if (stat?.isFile()) return fromGitFile(dotgit);
7861
+ if (path3.dirname(dir) === dir) return null;
7862
+ }
7863
+ } catch {
7864
+ return null;
7865
+ }
7866
+ }
7867
+ async function headOf(repo) {
7868
+ let head;
7869
+ try {
7870
+ head = fs.readFileSync(path3.join(repo.headDir, "HEAD"), "utf8").trim();
7871
+ } catch {
7872
+ return null;
7873
+ }
7874
+ const symbolic = /^ref:\s*(\S+)$/.exec(head);
7875
+ if (!symbolic) return /^[0-9a-f]{40}([0-9a-f]{24})?$/.test(head) ? head : null;
7876
+ const git = await lib();
7877
+ return git.resolveRef({ fs, gitdir: repo.gitdir, ref: symbolic[1] }).catch(() => null);
7878
+ }
7879
+ async function headCommit(repoPath) {
7880
+ const repo = locateRepo(repoPath);
7881
+ return repo ? headOf(repo) : null;
7882
+ }
7883
+ async function entryFor(repo) {
7884
+ const head = await headOf(repo);
7885
+ if (!head) return null;
7886
+ const now = Date.now();
7887
+ const existing = cache.get(repo.gitdir);
7888
+ if (existing && existing.head === head && now - existing.at < GIT_CACHE_TTL_MS) return existing;
7889
+ const entry = { head, at: now, walks: /* @__PURE__ */ new Map(), shas: /* @__PURE__ */ new Map() };
7890
+ cache.set(repo.gitdir, entry);
7891
+ return entry;
7892
+ }
7893
+ function info(sha2, message, author, timestamp) {
7894
+ return {
7895
+ sha: sha2,
7896
+ shortSha: sha2.slice(0, SHORT),
7897
+ subject: message.split("\n", 1)[0].trim(),
7898
+ author,
7899
+ date: new Date(timestamp * 1e3).toISOString()
7900
+ };
7901
+ }
7902
+ async function resolveCommit(repoPath, sha2) {
7903
+ const wanted = sha2.trim().toLowerCase();
7904
+ if (!/^[0-9a-f]{4,64}$/.test(wanted)) return null;
7905
+ const repo = locateRepo(repoPath);
7906
+ if (!repo) return null;
7907
+ const entry = await entryFor(repo);
7908
+ const lookup = async () => {
7909
+ const git = await lib();
7910
+ try {
7911
+ const oid = wanted.length >= 40 ? wanted : await git.expandOid({ fs, gitdir: repo.gitdir, oid: wanted });
7912
+ const { commit } = await git.readCommit({ fs, gitdir: repo.gitdir, oid });
7913
+ return info(oid, commit.message, commit.author.name, commit.author.timestamp);
7914
+ } catch {
7915
+ return null;
7916
+ }
7917
+ };
7918
+ if (!entry) return lookup();
7919
+ let pending = entry.shas.get(wanted);
7920
+ if (!pending) {
7921
+ pending = lookup();
7922
+ entry.shas.set(wanted, pending);
7923
+ }
7924
+ return pending;
7925
+ }
7926
+ async function walk(repo, entry, limit) {
7927
+ let pending = entry.walks.get(limit);
7928
+ if (!pending) {
7929
+ pending = lib().then(
7930
+ (git) => git.log({ fs, gitdir: repo.gitdir, ref: entry.head, depth: limit }).then((log) => log.map((c) => ({ sha: c.oid, message: c.commit.message, author: c.commit.author.name, timestamp: c.commit.author.timestamp }))).catch(() => [])
7931
+ );
7932
+ entry.walks.set(limit, pending);
7933
+ }
7934
+ return pending;
7935
+ }
7936
+ async function ignoreChecker(dir) {
7937
+ const git = await lib();
7938
+ let workTree = path3.resolve(dir);
7939
+ for (let d = workTree; ; d = path3.dirname(d)) {
7940
+ if (fs.existsSync(path3.join(d, ".git"))) {
7941
+ workTree = d;
7942
+ break;
7943
+ }
7944
+ if (path3.dirname(d) === d) break;
7945
+ }
7946
+ const gitdir = locateRepo(workTree)?.gitdir ?? path3.join(workTree, ".git");
7947
+ const prefix = path3.relative(workTree, path3.resolve(dir)).split(path3.sep).join("/");
7948
+ return (rel, isDirectory) => {
7949
+ const filepath = (prefix ? `${prefix}/${rel}` : rel) + (isDirectory ? "/" : "");
7950
+ return git.isIgnored({ fs, dir: workTree, gitdir, filepath }).catch(() => false);
7951
+ };
7952
+ }
7953
+ var TOKEN = /[A-Za-z0-9_-]+/g;
7954
+ var KEY_TOKEN = /^[A-Za-z]{2,5}-\d{1,9}$/;
7955
+ async function findCommitsMentioning(repoPath, ids, options = {}) {
7956
+ const wanted = new Set(ids.filter((id) => id.length > 0));
7957
+ if (wanted.size === 0) return [];
7958
+ const limit = Math.max(1, Math.min(MAX_COMMIT_SCAN, Math.floor(options.limit ?? DEFAULT_COMMIT_SCAN)));
7959
+ const repo = locateRepo(repoPath);
7960
+ if (!repo) return [];
7961
+ const entry = await entryFor(repo);
7962
+ if (!entry) return [];
7963
+ const out = [];
7964
+ for (const c of await walk(repo, entry, limit)) {
7965
+ const mentioned = new Set(
7966
+ (c.message.match(TOKEN) ?? []).map((token) => wanted.has(token) ? token : KEY_TOKEN.test(token) && wanted.has(token.toUpperCase()) ? token.toUpperCase() : null)
7967
+ );
7968
+ mentioned.delete(null);
7969
+ for (const id of mentioned) out.push({ itemId: id, ...info(c.sha, c.message, c.author, c.timestamp) });
7970
+ }
7971
+ return out;
7972
+ }
7973
+ var MAX_CHANGED_FILES = 2e3;
7974
+ var MAX_DIFFS = 2e4;
7975
+ var diffs = /* @__PURE__ */ new Map();
7976
+ function workTreeOf(repoPath) {
7977
+ try {
7978
+ for (let dir = path3.resolve(repoPath); ; dir = path3.dirname(dir)) {
7979
+ if (fs.existsSync(path3.join(dir, ".git"))) return dir;
7980
+ if (path3.dirname(dir) === dir) return null;
7981
+ }
7982
+ } catch {
7983
+ return null;
7984
+ }
7985
+ }
7986
+ async function diffCommit(git, gitdir, sha2, max, cache2) {
7987
+ let parent;
7988
+ try {
7989
+ const { commit } = await git.readCommit({ fs, gitdir, oid: sha2, cache: cache2 });
7990
+ parent = commit.parent[0];
7991
+ } catch {
7992
+ return null;
7993
+ }
7994
+ const files = [];
7995
+ let truncated = false;
7996
+ const trees = parent ? [git.TREE({ ref: parent }), git.TREE({ ref: sha2 })] : [git.TREE({ ref: sha2 })];
7997
+ try {
7998
+ await git.walk({
7999
+ fs,
8000
+ gitdir,
8001
+ cache: cache2,
8002
+ trees,
8003
+ // One child at a time, so a commit past the cap stops reading trees at once.
8004
+ iterate: async (walk2, children) => {
8005
+ const out = [];
8006
+ for (const child of children) {
8007
+ if (truncated) break;
8008
+ out.push(await walk2(child));
8009
+ }
8010
+ return out;
8011
+ },
8012
+ map: async (filepath, entries) => {
8013
+ if (filepath === ".") return true;
8014
+ const [a, b] = parent ? entries : [null, entries[0] ?? null];
8015
+ if (a && b && await a.oid() === await b.oid()) return null;
8016
+ const types = await Promise.all([a?.type(), b?.type()]);
8017
+ if (types.some((t) => t === "blob" || t === "commit")) {
8018
+ if (files.length >= max) {
8019
+ truncated = true;
8020
+ return null;
8021
+ }
8022
+ files.push(filepath);
8023
+ }
8024
+ return types.includes("tree") ? true : null;
8025
+ },
8026
+ reduce: async () => void 0
8027
+ });
8028
+ } catch {
8029
+ return null;
8030
+ }
8031
+ return { files: files.sort(), truncated };
8032
+ }
8033
+ async function changedFiles(repoPath, shas, max = MAX_CHANGED_FILES) {
8034
+ const out = /* @__PURE__ */ new Map();
8035
+ const repo = locateRepo(repoPath);
8036
+ if (!repo || shas.length === 0) return out;
8037
+ const git = await lib();
8038
+ const cache2 = {};
8039
+ for (const sha2 of new Set(shas)) {
8040
+ const key = `${repo.gitdir}\0${sha2}\0${max}`;
8041
+ let pending = diffs.get(key);
8042
+ if (!pending) {
8043
+ pending = /^[0-9a-f]{40}([0-9a-f]{24})?$/.test(sha2) ? diffCommit(git, repo.gitdir, sha2, max, cache2) : Promise.resolve(null);
8044
+ diffs.set(key, pending);
8045
+ while (diffs.size > MAX_DIFFS) diffs.delete(diffs.keys().next().value);
8046
+ }
8047
+ const found = await pending;
8048
+ if (found) out.set(sha2, found);
8049
+ else diffs.delete(key);
8050
+ }
8051
+ return out;
8052
+ }
8053
+
7772
8054
  // ../../node_modules/.pnpm/fractional-indexing@4.0.0/node_modules/fractional-indexing/src/index.js
7773
8055
  var BASE_62_DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
7774
8056
  var BASE_52_DIGITS = BASE_62_DIGITS.slice(10);
@@ -8206,867 +8488,882 @@ function isUniqueViolation(err, column) {
8206
8488
  return err instanceof Error && /UNIQUE constraint failed/.test(err.message) && err.message.includes(column);
8207
8489
  }
8208
8490
 
8209
- // ../core/src/services/board-format.ts
8210
- var import_yaml = __toESM(require_dist(), 1);
8211
- var BOARD_FORMAT_VERSION = 1;
8212
- var PRIORITY = ["", "low", "medium", "high"];
8213
- var REF_LINE = /^- (file|url|commit|pr) (.*)$/;
8214
- var ITEM_LINE = /^- \[([ xX])\] (.*)$/;
8215
- var ITEM_ANCHOR = /\s*<!--\s*slate\s+id:(\S+)\s+rev:(\d+)\s*-->\s*$/;
8216
- var DETAILS_OPEN = /^ {2}<details>\s*(<summary>.*<\/summary>)?\s*$/;
8217
- var DETAILS_CLOSE = " </details>";
8218
- var DATE = /^\d{4}-\d{2}-\d{2}$/;
8219
- function code(value) {
8220
- const longest = Math.max(0, ...(value.match(/`+/g) ?? []).map((run) => run.length));
8221
- const fence = "`".repeat(longest + 1);
8222
- const pad = longest > 0 || value.startsWith("`") || value.endsWith("`") ? " " : "";
8223
- return `${fence}${pad}${value}${pad}${fence}`;
8224
- }
8225
- function oneLine(text) {
8226
- return text.replace(/\s*\n\s*/g, " ");
8227
- }
8228
- function tag(value) {
8229
- return /^[^\s`#·,]+$/.test(value) ? `#${value}` : `#${code(value)}`;
8491
+ // ../core/src/services/rows.ts
8492
+ import { existsSync as existsSync3 } from "node:fs";
8493
+ var ITEM_SELECT = "SELECT i.*, p.key AS project_key FROM items i JOIN projects p ON p.id = i.project_id";
8494
+ function toWorkspace(row) {
8495
+ return {
8496
+ id: row.id,
8497
+ name: row.name,
8498
+ rootPath: row.root_path,
8499
+ createdAt: row.created_at,
8500
+ updatedAt: row.updated_at,
8501
+ missing: !existsSync3(row.root_path)
8502
+ };
8230
8503
  }
8231
- var YAML_RESERVED = /^(true|false|null|yes|no|on|off|y|n|~)$/i;
8232
- function scalar(value) {
8233
- if (/^[A-Za-z][A-Za-z0-9 ._/()+-]*$/.test(value) && !value.endsWith(" ") && !YAML_RESERVED.test(value)) return value;
8234
- return JSON.stringify(value);
8504
+ function toProject(row) {
8505
+ return {
8506
+ id: row.id,
8507
+ key: row.key,
8508
+ gitTransitions: row.git_transitions === 1,
8509
+ roadmapFile: row.roadmap_file,
8510
+ archAuto: row.arch_auto === 1,
8511
+ archRun: row.arch_head && row.arch_at && row.arch_state ? { state: row.arch_state, head: row.arch_head, at: row.arch_at, reason: row.arch_error } : null,
8512
+ workspaceId: row.workspace_id,
8513
+ name: row.name,
8514
+ path: row.path,
8515
+ description: row.description,
8516
+ milestones: JSON.parse(row.milestones),
8517
+ archived: row.archived === 1,
8518
+ createdAt: row.created_at,
8519
+ updatedAt: row.updated_at,
8520
+ missing: !existsSync3(row.path)
8521
+ };
8235
8522
  }
8236
- function frontmatter(board) {
8237
- const out = ["---", `slate: ${BOARD_FORMAT_VERSION}`, `project: ${scalar(board.name)}`];
8238
- if (board.description) out.push(`description: ${scalar(board.description)}`);
8239
- out.push("columns:");
8240
- for (const c of board.columns) {
8241
- out.push(` - { key: ${scalar(c.key)}, label: ${scalar(c.label)}, kind: ${c.kind}${c.isDefault ? ", default: true" : ""} }`);
8242
- }
8243
- out.push(`milestones: [${board.milestones.map(scalar).join(", ")}]`, "---");
8244
- return out;
8523
+ function toStatus(row) {
8524
+ return { key: row.key, label: row.label, position: row.position, kind: row.kind, isDefault: row.is_default === 1 };
8245
8525
  }
8246
- function metaLine(item, order, done) {
8247
- const byBoardOrder = (ids) => [...ids].sort((a, b) => (order.get(a) ?? Infinity) - (order.get(b) ?? Infinity) || (a < b ? -1 : a > b ? 1 : 0));
8248
- const parts = [];
8249
- if (item.milestone) parts.push(code(item.milestone));
8250
- if (item.priority > 0) parts.push(PRIORITY[item.priority]);
8251
- if (item.tags.length > 0) parts.push(item.tags.map(tag).join(" "));
8252
- if (item.links.blockedBy.length > 0) parts.push(`blocked by ${byBoardOrder(item.links.blockedBy.map((l) => l.id)).map(code).join(", ")}`);
8253
- if (item.links.relates.length > 0) parts.push(`relates ${byBoardOrder(item.links.relates.map((l) => l.id)).map(code).join(", ")}`);
8254
- if (done && item.completedAt) parts.push(`done ${item.completedAt.slice(0, 10)}`);
8255
- return parts.length > 0 ? parts.join(" \xB7 ") : null;
8526
+ function toItem(row) {
8527
+ return {
8528
+ id: row.id,
8529
+ key: itemKey(row.project_key ?? null, row.number),
8530
+ projectId: row.project_id,
8531
+ title: row.title,
8532
+ details: row.details,
8533
+ status: row.status,
8534
+ sortKey: row.sort_key,
8535
+ milestone: row.milestone,
8536
+ priority: row.priority,
8537
+ tags: JSON.parse(row.tags),
8538
+ revision: row.revision,
8539
+ createdAt: row.created_at,
8540
+ updatedAt: row.updated_at,
8541
+ completedAt: row.completed_at,
8542
+ claim: claimOf(row)
8543
+ };
8256
8544
  }
8257
- function itemBlock(item, order, done) {
8258
- const out = [`- [${done ? "x" : " "}] ${code(item.id)} ${oneLine(item.title)} <!-- slate id:${item.id} rev:${item.revision} -->`];
8259
- const meta2 = metaLine(item, order, done);
8260
- if (meta2) out.push(` - ${meta2}`);
8261
- for (const ref of item.refs) out.push(` - ${ref.type} ${code(ref.target)}${ref.label ? ` \u2014 ${oneLine(ref.label)}` : ""}`);
8262
- if (item.details) {
8263
- out.push(" <details><summary>Details</summary>", "");
8264
- for (const line of item.details.split("\n")) out.push(line === "" ? "" : ` ${line}`);
8265
- out.push("", DETAILS_CLOSE);
8266
- }
8267
- return out;
8545
+ function claimOf(row, now = (/* @__PURE__ */ new Date()).toISOString()) {
8546
+ return row.claimed_by && row.claimed_until && row.claimed_until > now ? { by: row.claimed_by, until: row.claimed_until } : null;
8268
8547
  }
8269
- function renderBoard(board) {
8270
- const order = /* @__PURE__ */ new Map();
8271
- for (const column of board.columns) for (const item of board.items.get(column.key) ?? []) order.set(item.id, order.size);
8272
- const out = [...frontmatter(board), "", `# ${oneLine(board.name)}`];
8273
- if (board.description) out.push("", ...board.description.trim().split("\n").map((l) => l ? `> ${l}` : ">"));
8274
- for (const column of board.columns) {
8275
- out.push("", `## ${column.label}`);
8276
- for (const item of board.items.get(column.key) ?? []) out.push("", ...itemBlock(item, order, column.kind === "done"));
8277
- }
8278
- return `${out.join("\n")}
8279
- `;
8548
+ function toRef(row) {
8549
+ return { id: row.id, itemId: row.item_id, type: row.type, target: row.target, label: row.label, createdAt: row.created_at };
8280
8550
  }
8281
- function fail(line, message) {
8282
- throw invalid(`line ${line}: ${message}`, { line });
8551
+ function workspaceRow(store, id) {
8552
+ const row = store.db.prepare("SELECT * FROM workspaces WHERE id = ?").get(id);
8553
+ if (!row) throw notFound("workspace", id);
8554
+ return row;
8283
8555
  }
8284
- var frontmatterSchema = external_exports.object({
8285
- slate: external_exports.literal(BOARD_FORMAT_VERSION, { error: `unsupported board format version; this slate reads version ${BOARD_FORMAT_VERSION}` }),
8286
- project: external_exports.string().optional(),
8287
- description: external_exports.string().nullable().optional(),
8288
- columns: external_exports.array(
8289
- external_exports.object({
8290
- key: statusKeySchema,
8291
- label: external_exports.string().trim().min(1).max(100),
8292
- kind: statusKindSchema,
8293
- default: external_exports.boolean().optional()
8294
- })
8295
- ).min(1),
8296
- milestones: external_exports.array(milestoneSchema).optional()
8297
- });
8298
- function readCodeSpan(s, i) {
8299
- let n = 0;
8300
- while (s[i + n] === "`") n++;
8301
- if (n === 0) return null;
8302
- const fence = "`".repeat(n);
8303
- let j = i + n;
8304
- for (; ; ) {
8305
- const close = s.indexOf(fence, j);
8306
- if (close < 0) return null;
8307
- if (s[close + n] === "`" || s[close - 1] === "`") {
8308
- j = close + n;
8309
- while (s[j] === "`") j++;
8310
- continue;
8311
- }
8312
- let value = s.slice(i + n, close);
8313
- if (value.length > 1 && value.startsWith(" ") && value.endsWith(" ") && value.trim() !== "") value = value.slice(1, -1);
8314
- return { value, end: close + n };
8315
- }
8556
+ function projectRow(store, id) {
8557
+ const row = store.db.prepare("SELECT * FROM projects WHERE id = ?").get(id);
8558
+ if (!row) throw notFound("project", id);
8559
+ return row;
8316
8560
  }
8317
- function splitMeta(s) {
8318
- const parts = [];
8319
- let start = 0;
8320
- let i = 0;
8321
- while (i < s.length) {
8322
- if (s[i] === "`") {
8323
- const span = readCodeSpan(s, i);
8324
- if (span) {
8325
- i = span.end;
8326
- continue;
8327
- }
8328
- }
8329
- if (s.startsWith(" \xB7 ", i)) {
8330
- parts.push(s.slice(start, i));
8331
- i += 3;
8332
- start = i;
8333
- continue;
8334
- }
8335
- i++;
8336
- }
8337
- parts.push(s.slice(start));
8338
- return parts.map((p) => p.trim()).filter((p) => p !== "");
8561
+ function itemRow(store, ref) {
8562
+ const id = resolveItemId(store, ref);
8563
+ const row = store.db.prepare(`${ITEM_SELECT} WHERE i.id = ?`).get(id);
8564
+ if (!row) throw notFound("item", id);
8565
+ return row;
8339
8566
  }
8340
- function wholeCodeSpan(s) {
8341
- const span = readCodeSpan(s, 0);
8342
- return span && span.end === s.length ? span.value : null;
8567
+ function refRow(store, id) {
8568
+ const row = store.db.prepare("SELECT * FROM refs WHERE id = ?").get(id);
8569
+ if (!row) throw notFound("ref", id);
8570
+ return row;
8343
8571
  }
8344
- function idList(s, line) {
8345
- return s.split(",").map((part) => {
8346
- const raw = part.trim();
8347
- const id = wholeCodeSpan(raw) ?? raw;
8348
- if (!/^[A-Za-z0-9_-]+$/.test(id)) fail(line, `'${raw}' is not an item id`);
8349
- return id;
8350
- });
8572
+ function hasOwnStatuses(store, projectId) {
8573
+ return store.db.prepare("SELECT 1 FROM statuses WHERE scope_type = 'project' AND scope_id = ? LIMIT 1").get(projectId) !== void 0;
8351
8574
  }
8352
- function tagList(s, line) {
8353
- const tags = [];
8354
- let i = 0;
8355
- while (i < s.length) {
8356
- if (s[i] === " ") {
8357
- i++;
8358
- continue;
8359
- }
8360
- if (s[i] !== "#") fail(line, `expected a #tag, found '${s.slice(i)}'`);
8361
- i++;
8362
- const span = s[i] === "`" ? readCodeSpan(s, i) : null;
8363
- if (span) {
8364
- tags.push(span.value);
8365
- i = span.end;
8366
- continue;
8367
- }
8368
- const end = s.indexOf(" ", i) < 0 ? s.length : s.indexOf(" ", i);
8369
- const value = s.slice(i, end);
8370
- if (!value) fail(line, "empty #tag");
8371
- tags.push(value);
8372
- i = end;
8373
- }
8374
- return tags;
8575
+ function scopeStatuses(store, scopeType, scopeId) {
8576
+ const rows = store.db.prepare("SELECT key, label, position, kind, is_default FROM statuses WHERE scope_type = ? AND scope_id = ? ORDER BY position").all(scopeType, scopeId);
8577
+ return rows.map(toStatus);
8375
8578
  }
8376
- function applyMeta(item, text, line) {
8377
- for (const part of splitMeta(text)) {
8378
- const milestone = wholeCodeSpan(part);
8379
- if (milestone !== null) {
8380
- if (item.milestone !== null) fail(line, "an item has one milestone");
8381
- item.milestone = milestone;
8382
- } else if (PRIORITY.includes(part) && part !== "") {
8383
- item.priority = PRIORITY.indexOf(part);
8384
- } else if (part.startsWith("#")) {
8385
- item.tags.push(...tagList(part, line));
8386
- } else if (part.startsWith("blocked by ")) {
8387
- item.blockedBy.push(...idList(part.slice("blocked by ".length), line));
8388
- } else if (part.startsWith("relates ")) {
8389
- item.relates.push(...idList(part.slice("relates ".length), line));
8390
- } else if (part.startsWith("done ") && DATE.test(part.slice(5))) {
8391
- item.completedOn = part.slice(5);
8392
- } else {
8393
- fail(line, `unknown metadata '${part}'; expected \`milestone\`, low|medium|high, #tags, 'blocked by', 'relates' or 'done YYYY-MM-DD'`);
8394
- }
8579
+ function effectiveStatuses(store, projectId) {
8580
+ const own = scopeStatuses(store, "project", projectId);
8581
+ if (own.length > 0) return own;
8582
+ return scopeStatuses(store, "workspace", projectRow(store, projectId).workspace_id);
8583
+ }
8584
+ function requireStatus(statuses, key) {
8585
+ const status = statuses.find((s) => s.key === key);
8586
+ if (!status) {
8587
+ throw new SlateError("invalid_argument", `unknown status '${key}'`, { valid: statuses.map((s) => s.key) });
8395
8588
  }
8589
+ return status;
8396
8590
  }
8397
- function parseRef(type, rest, line) {
8398
- const span = readCodeSpan(rest, 0);
8399
- if (!span) fail(line, `a ${type} ref's target is a code span, for example: - ${type} \`target\``);
8400
- const label = rest.slice(span.end).trim().replace(/^(—|--|-)\s*/, "").trim();
8401
- return { type: refTypeSchema.parse(type), target: span.value, label: label || null };
8591
+ function isBlocked(store, itemId) {
8592
+ return store.db.prepare(
8593
+ `SELECT 1 FROM item_links l JOIN items b ON b.id = l.from_id
8594
+ WHERE l.to_id = ? AND l.kind = 'blocks' AND b.completed_at IS NULL LIMIT 1`
8595
+ ).get(itemId) !== void 0;
8402
8596
  }
8403
- function parseFrontmatter(lines) {
8404
- if (lines[0] !== "---") fail(1, "a board file starts with '---' frontmatter");
8405
- const close = lines.indexOf("---", 1);
8406
- if (close < 0) fail(1, "the frontmatter is not closed with '---'");
8407
- let raw;
8408
- try {
8409
- raw = (0, import_yaml.parse)(lines.slice(1, close).join("\n"));
8410
- } catch (err) {
8411
- fail(2, `frontmatter is not valid YAML: ${err.message.split("\n")[0]}`);
8597
+
8598
+ // ../core/src/services/arch-auto.ts
8599
+ function createArchAutoService(ctx) {
8600
+ const { store } = ctx;
8601
+ const db = store.db;
8602
+ function enabled() {
8603
+ return db.prepare("SELECT id FROM projects WHERE arch_auto = 1 AND archived = 0 ORDER BY name").all().map((r) => r.id);
8604
+ }
8605
+ async function due(projectId) {
8606
+ const row = projectRow(store, parse(idSchema, projectId));
8607
+ if (row.arch_auto !== 1 || row.archived === 1 || !existsSync4(row.path)) return null;
8608
+ const head = await headCommit(row.path);
8609
+ return head && head !== row.arch_head ? head : null;
8610
+ }
8611
+ function record(projectId, head, result, since) {
8612
+ const row = projectRow(store, parse(idSchema, projectId));
8613
+ if (row.arch_auto !== 1 || row.arch_head !== since) return false;
8614
+ db.prepare("UPDATE projects SET arch_head = ?, arch_at = ?, arch_state = ?, arch_error = ? WHERE id = ?").run(head, ctx.now(), result.state, result.reason, projectId);
8615
+ ctx.emit("project.updated", { workspaceId: row.workspace_id, projectId, id: projectId });
8616
+ return true;
8412
8617
  }
8413
- const result = frontmatterSchema.safeParse(raw);
8414
- if (!result.success) {
8415
- const issue = result.error.issues[0];
8416
- fail(1, `frontmatter ${issue.path.join(".") || "root"}: ${issue.message}`);
8618
+ function lastHead(projectId) {
8619
+ return projectRow(store, parse(idSchema, projectId)).arch_head;
8417
8620
  }
8418
- return { meta: result.data, next: close + 1 };
8419
- }
8420
- function parseBoard(text) {
8421
- const lines = text.replace(/\r\n/g, "\n").split("\n");
8422
- const { meta: meta2, next } = parseFrontmatter(lines);
8423
- const columns = meta2.columns.map((c) => ({ key: c.key, label: c.label, kind: c.kind, isDefault: c.default === true }));
8424
- if (new Set(columns.map((c) => c.key)).size !== columns.length) fail(1, "column keys must be unique");
8425
- if (new Set(columns.map((c) => c.label)).size !== columns.length) fail(1, "column labels must be unique");
8426
- if (columns.filter((c) => c.isDefault).length !== 1) fail(1, "exactly one column must be 'default: true'");
8427
- const byLabel = new Map(columns.map((c) => [c.label, c]));
8428
- const sections = [];
8429
- const seenIds = /* @__PURE__ */ new Map();
8430
- let section = null;
8431
- let item = null;
8432
- for (let i = next; i < lines.length; i++) {
8433
- const text2 = lines[i];
8434
- const lineNo = i + 1;
8435
- if (text2.trim() === "") continue;
8436
- if (text2.startsWith("## ")) {
8437
- const label = text2.slice(3).trim();
8438
- const column = byLabel.get(label);
8439
- if (!column) fail(lineNo, `'${label}' is not a column in the frontmatter (${columns.map((c) => c.label).join(", ")})`);
8440
- if (sections.some((s) => s.column.key === column.key)) fail(lineNo, `column '${label}' appears twice`);
8441
- section = { line: lineNo, column, items: [] };
8442
- sections.push(section);
8443
- item = null;
8444
- continue;
8445
- }
8446
- const itemMatch = ITEM_LINE.exec(text2);
8447
- if (itemMatch) {
8448
- if (!section) fail(lineNo, "an item must be under a '## Column' heading");
8449
- let rest = itemMatch[2];
8450
- let id = null;
8451
- let revision = null;
8452
- const anchor = ITEM_ANCHOR.exec(rest);
8453
- if (anchor) {
8454
- id = anchor[1];
8455
- revision = Number(anchor[2]);
8456
- rest = rest.slice(0, anchor.index);
8457
- if (seenIds.has(id)) fail(lineNo, `item ${id} also appears on line ${seenIds.get(id)}`);
8458
- seenIds.set(id, lineNo);
8459
- const shown = `${code(id)} `;
8460
- if (rest.startsWith(shown)) rest = rest.slice(shown.length);
8461
- }
8462
- const title = rest.trim();
8463
- if (!title) fail(lineNo, "an item needs a title");
8464
- item = {
8465
- line: lineNo,
8466
- id,
8467
- revision,
8468
- checked: itemMatch[1] !== " ",
8469
- title,
8470
- details: null,
8471
- milestone: null,
8472
- priority: 0,
8473
- tags: [],
8474
- blockedBy: [],
8475
- relates: [],
8476
- refs: [],
8477
- completedOn: null
8478
- };
8479
- section.items.push(item);
8480
- continue;
8481
- }
8482
- if (!text2.startsWith(" ")) {
8483
- if (/^[-*+] /.test(text2)) fail(lineNo, "not an item line; items look like '- [ ] Title'");
8484
- continue;
8485
- }
8486
- if (!item) fail(lineNo, "indented line outside an item");
8487
- if (DETAILS_OPEN.test(text2)) {
8488
- let end = i + 1;
8489
- while (end < lines.length && (lines[end] === "" || lines[end].startsWith(" "))) end++;
8490
- let close = -1;
8491
- for (let j = end - 1; j > i; j--) {
8492
- if (lines[j] === DETAILS_CLOSE) {
8493
- close = j;
8494
- break;
8495
- }
8496
- }
8497
- if (close < 0) fail(lineNo, "<details> is not closed with an indented </details>");
8498
- let body = lines.slice(i + 1, close);
8499
- if (body[0] === "") body = body.slice(1);
8500
- if (body.at(-1) === "") body = body.slice(0, -1);
8501
- const details = body.map((l) => l.replace(/^ {1,2}/, "")).join("\n");
8502
- item.details = details === "" ? null : details;
8503
- for (let j = close + 1; j < end; j++) if (lines[j].trim() !== "") fail(j + 1, "unexpected text after </details>");
8504
- i = end - 1;
8505
- continue;
8506
- }
8507
- if (!text2.startsWith(" - ")) fail(lineNo, "expected ' - ' metadata, a ref, or <details>");
8508
- if (item.details !== null) fail(lineNo, "metadata and refs go before <details>");
8509
- const sub = text2.slice(2);
8510
- const ref = REF_LINE.exec(sub);
8511
- if (ref) {
8512
- item.refs.push(parseRef(ref[1], ref[2], lineNo));
8513
- continue;
8514
- }
8515
- applyMeta(item, sub.slice(2), lineNo);
8516
- }
8517
- return {
8518
- project: meta2.project ?? null,
8519
- description: meta2.description,
8520
- columns,
8521
- milestones: meta2.milestones ?? [],
8522
- sections
8523
- };
8621
+ return { enabled, due, record, lastHead };
8524
8622
  }
8525
8623
 
8526
- // ../core/src/services/export.ts
8527
- var PRIORITY2 = ["", "low", "medium", "high"];
8528
- function heading(level, text) {
8529
- return `${"#".repeat(Math.min(level, 6))} ${text}`;
8624
+ // ../core/src/services/architecture.ts
8625
+ import { existsSync as existsSync6, readFileSync as readFileSync3, readdirSync as readdirSync2, realpathSync as realpathSync2, statSync as statSync2, watch } from "node:fs";
8626
+ import path5 from "node:path";
8627
+
8628
+ // ../core/src/services/refs.ts
8629
+ import { existsSync as existsSync5, readFileSync as readFileSync2, statSync } from "node:fs";
8630
+ import path4 from "node:path";
8631
+ var MAX_REF_BYTES = 256 * 1024;
8632
+ var MAX_WORKSPACE_REPOS = 25;
8633
+ function sandboxError(target, root) {
8634
+ return new SlateError("sandbox", `${target} is outside the project root ${root}`, { target, root });
8530
8635
  }
8531
- function refLine(ref) {
8532
- return `- ${ref.type}: \`${ref.target}\`${ref.label ? ` (${ref.label})` : ""} [ref \`${ref.id}\`]`;
8636
+ function resolveInside(root, target) {
8637
+ const abs = path4.resolve(root, expandHome(target));
8638
+ if (!isInside(abs, root)) throw sandboxError(target, root);
8639
+ if (!isInside(normalizePath(abs), normalizePath(root))) throw sandboxError(target, root);
8640
+ return abs;
8533
8641
  }
8534
- function linked(items) {
8535
- return items.map((i) => `${i.title} (\`${i.id}\`${i.done ? ", done" : ""})`).join(", ");
8642
+ var LINE_SUFFIX = /#L(\d+)(?:-L?(\d+))?$/;
8643
+ var LINE_LIKE = /#L\d[^#/]*$/;
8644
+ function splitFileTarget(target) {
8645
+ const m = LINE_SUFFIX.exec(target);
8646
+ if (!m) {
8647
+ if (LINE_LIKE.test(target)) throw invalid(`not a line range: ${target.slice(target.lastIndexOf("#"))}; use #L40 or #L40-80`);
8648
+ return { path: target, lines: null };
8649
+ }
8650
+ const start = Number(m[1]);
8651
+ const end = m[2] === void 0 ? start : Number(m[2]);
8652
+ if (start < 1) throw invalid(`line numbers start at 1: ${target}`);
8653
+ if (end < start) throw invalid(`a line range ends at or after its start: ${target}`);
8654
+ return { path: target.slice(0, m.index), lines: { start, end } };
8536
8655
  }
8537
- function meta(item) {
8538
- const parts = [`\`${item.id}\``, item.status];
8539
- if (item.milestone) parts.push(`milestone ${item.milestone}`);
8540
- if (item.priority > 0) parts.push(`priority ${PRIORITY2[item.priority]}`);
8541
- if (item.tags.length > 0) parts.push(item.tags.map((t) => `#${t}`).join(" "));
8542
- if (item.blocked) parts.push("**blocked**");
8543
- if (item.completedAt) parts.push(`completed ${item.completedAt}`);
8544
- return parts.join(" \xB7 ");
8656
+ function lineSuffix(lines) {
8657
+ if (!lines) return "";
8658
+ return lines.end === lines.start ? `#L${lines.start}` : `#L${lines.start}-${lines.end}`;
8545
8659
  }
8546
- function itemMarkdown(item, level = 1) {
8547
- const out = [heading(level, item.title), "", meta(item)];
8548
- if (item.details) out.push("", item.details.trim());
8549
- if (item.links.blockedBy.length > 0) out.push("", `Blocked by: ${linked(item.links.blockedBy)}`);
8550
- if (item.links.blocks.length > 0) out.push("", `Blocks: ${linked(item.links.blocks)}`);
8551
- if (item.links.relates.length > 0) out.push("", `Related: ${linked(item.links.relates)}`);
8552
- if (item.refs.length > 0) out.push("", "Refs:", ...item.refs.map(refLine));
8553
- return out.join("\n");
8660
+ function splitLines(text) {
8661
+ return text === "" ? [] : text.split(/(?<=\n)/);
8554
8662
  }
8555
- function createExportService(workspaces, projects, items) {
8556
- function projectBody(project2, level) {
8557
- const out = [heading(level, project2.name), "", `Path: \`${project2.path}\`${project2.missing ? " (missing)" : ""}`];
8558
- if (project2.archived) out.push("", "Archived.");
8559
- if (project2.description) out.push("", project2.description.trim());
8560
- if (project2.milestones.length > 0) out.push("", `Milestones: ${project2.milestones.join(", ")}`);
8561
- const board = items.board({ projectId: project2.id, includeDone: true });
8562
- for (const column of board.columns) {
8563
- out.push("", heading(level + 1, `${column.label} (${column.items.length})`));
8564
- for (const summary of column.items) out.push("", itemMarkdown(items.get(summary.id), level + 2));
8663
+ function normalizeTarget(type, target, root) {
8664
+ switch (type) {
8665
+ case "file": {
8666
+ const { path: file, lines } = splitFileTarget(target);
8667
+ const rel = path4.relative(root, resolveInside(root, file));
8668
+ if (rel === "") throw invalid("a file ref must point at a file inside the project, not the project root");
8669
+ return rel.split(path4.sep).join("/") + lineSuffix(lines);
8670
+ }
8671
+ case "url": {
8672
+ let url;
8673
+ try {
8674
+ url = new URL(target);
8675
+ } catch {
8676
+ throw invalid(`not a valid URL: ${target}`);
8677
+ }
8678
+ if (url.protocol !== "http:" && url.protocol !== "https:") throw invalid("url refs must be http or https");
8679
+ return url.toString();
8680
+ }
8681
+ case "commit":
8682
+ if (!/^[0-9a-f]{4,64}$/i.test(target)) throw invalid(`not a commit sha: ${target}`);
8683
+ return target.toLowerCase();
8684
+ case "pr": {
8685
+ const n = /^#?(\d+)$/.exec(target);
8686
+ if (n) return n[1];
8687
+ if (/^https?:\/\//.test(target)) return normalizeTarget("url", target, root);
8688
+ throw invalid(`a pr ref is a number or a URL: ${target}`);
8565
8689
  }
8566
- return out;
8567
- }
8568
- function project(projectId) {
8569
- const detail = projects.get(parse(idSchema, projectId));
8570
- const board = items.board({ projectId: detail.id, includeDone: true });
8571
- return renderBoard({
8572
- name: detail.name,
8573
- description: detail.description,
8574
- milestones: detail.milestones,
8575
- columns: detail.statuses,
8576
- items: new Map(board.columns.map((c) => [c.key, c.items.map((summary) => items.get(summary.id))]))
8577
- });
8578
- }
8579
- function workspace(workspaceId) {
8580
- const ws = workspaces.get(parse(idSchema, workspaceId));
8581
- const out = [heading(1, ws.name), "", `Root: \`${ws.rootPath}\`${ws.missing ? " (missing)" : ""}`];
8582
- for (const p of projects.list({ workspaceId: ws.id })) out.push("", ...projectBody(p, 2));
8583
- return `${out.join("\n")}
8584
- `;
8585
- }
8586
- function item(itemId) {
8587
- return `${itemMarkdown(items.get(itemId))}
8588
- `;
8589
8690
  }
8590
- return { project, workspace, item };
8591
- }
8592
-
8593
- // ../core/src/services/roadmap-file.ts
8594
- import { createHash } from "node:crypto";
8595
- import { existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "node:fs";
8596
- import path5 from "node:path";
8597
-
8598
- // ../core/src/services/refs.ts
8599
- import { existsSync as existsSync4, readFileSync as readFileSync2, statSync } from "node:fs";
8600
- import path4 from "node:path";
8601
-
8602
- // ../core/src/git.ts
8603
- import fs from "node:fs";
8604
- import path3 from "node:path";
8605
- var loaded;
8606
- var lib = () => loaded ??= import("./isomorphic-git-BZUKICXS.js").then((m) => "log" in m ? m : m.default);
8607
- var GIT_CACHE_TTL_MS = 15e3;
8608
- var DEFAULT_COMMIT_SCAN = 500;
8609
- var MAX_COMMIT_SCAN = 5e3;
8610
- var SHORT = 7;
8611
- var cache = /* @__PURE__ */ new Map();
8612
- function clearGitCache() {
8613
- cache.clear();
8614
8691
  }
8615
- function isDir(p) {
8692
+ function looksBinary(buf) {
8693
+ if (buf.subarray(0, 8192).includes(0)) return true;
8616
8694
  try {
8617
- return fs.statSync(p).isDirectory();
8618
- } catch {
8695
+ new TextDecoder("utf-8", { fatal: true }).decode(buf);
8619
8696
  return false;
8620
- }
8621
- }
8622
- function isFile(p) {
8623
- try {
8624
- return fs.statSync(p).isFile();
8625
8697
  } catch {
8626
- return false;
8698
+ return true;
8627
8699
  }
8628
8700
  }
8629
- function valid(repo) {
8630
- return isFile(path3.join(repo.headDir, "HEAD")) && isDir(path3.join(repo.gitdir, "objects")) ? repo : null;
8631
- }
8632
- function fromGitFile(dotgit) {
8633
- const match = /^gitdir:\s*(.+?)\s*$/m.exec(fs.readFileSync(dotgit, "utf8"));
8634
- if (!match?.[1]) return null;
8635
- const headDir = path3.resolve(path3.dirname(dotgit), match[1]);
8636
- const commondir = path3.join(headDir, "commondir");
8637
- const gitdir = isFile(commondir) ? path3.resolve(headDir, fs.readFileSync(commondir, "utf8").trim()) : headDir;
8638
- return valid({ gitdir, headDir });
8639
- }
8640
- function currentBranch(repoPath) {
8641
- const repo = locateRepo(repoPath);
8642
- if (!repo) return null;
8643
- try {
8644
- const head = fs.readFileSync(path3.join(repo.headDir, "HEAD"), "utf8").trim();
8645
- return /^ref: refs\/heads\/(.+)$/.exec(head)?.[1] ?? null;
8646
- } catch {
8701
+ function createRefService(ctx) {
8702
+ const { store } = ctx;
8703
+ const db = store.db;
8704
+ function owner(itemId) {
8705
+ const item = itemRow(store, itemId);
8706
+ const project = projectRow(store, item.project_id);
8707
+ return { item, project };
8708
+ }
8709
+ function add(input, createdAt) {
8710
+ const { itemId: ref, type, target, label } = parse(refAddSchema, input);
8711
+ return store.tx(() => {
8712
+ const { item, project } = owner(ref);
8713
+ const itemId = item.id;
8714
+ const id = ctx.newId();
8715
+ db.prepare("INSERT INTO refs (id, item_id, type, target, label, created_at) VALUES (?, ?, ?, ?, ?, ?)").run(
8716
+ id,
8717
+ itemId,
8718
+ type,
8719
+ normalizeTarget(type, target, project.path),
8720
+ label ?? null,
8721
+ createdAt ?? ctx.now()
8722
+ );
8723
+ ctx.emit("ref.added", { workspaceId: project.workspace_id, projectId: project.id, id });
8724
+ return toRef(refRow(store, id));
8725
+ });
8726
+ }
8727
+ function remove(refId) {
8728
+ parse(idSchema, refId);
8729
+ store.tx(() => {
8730
+ const ref = refRow(store, refId);
8731
+ const { project } = owner(ref.item_id);
8732
+ db.prepare("DELETE FROM refs WHERE id = ?").run(refId);
8733
+ ctx.emit("ref.removed", { workspaceId: project.workspace_id, projectId: project.id, id: refId });
8734
+ });
8735
+ }
8736
+ function forItem(itemId) {
8737
+ return db.prepare("SELECT * FROM refs WHERE item_id = ? ORDER BY created_at, id").all(itemId).map(toRef);
8738
+ }
8739
+ function commitSources(project) {
8740
+ const own = { id: project.id, name: project.name, path: project.path };
8741
+ const others = db.prepare("SELECT * FROM projects WHERE workspace_id = ? AND id <> ? ORDER BY name, id").all(project.workspace_id, project.id);
8742
+ if (others.length === 0) return [own];
8743
+ const seen = /* @__PURE__ */ new Set();
8744
+ const ownRepo = locateRepo(project.path);
8745
+ if (ownRepo) seen.add(ownRepo.gitdir);
8746
+ const out = [own];
8747
+ for (const p of others) {
8748
+ if (out.length >= MAX_WORKSPACE_REPOS) break;
8749
+ const repo = locateRepo(p.path);
8750
+ if (!repo || seen.has(repo.gitdir)) continue;
8751
+ seen.add(repo.gitdir);
8752
+ out.push({ id: p.id, name: p.name, path: p.path });
8753
+ }
8754
+ return out;
8755
+ }
8756
+ function sourcesForItem(itemId) {
8757
+ return commitSources(owner(itemId).project);
8758
+ }
8759
+ async function findCommit(sources, sha2) {
8760
+ for (const source of sources) {
8761
+ const found = await resolveCommit(source.path, sha2);
8762
+ if (found) return { ...found, projectId: source.id, projectName: source.name, projectPath: source.path };
8763
+ }
8647
8764
  return null;
8648
8765
  }
8649
- }
8650
- async function defaultBranchShas(repoPath, limit = DEFAULT_COMMIT_SCAN) {
8651
- const repo = locateRepo(repoPath);
8652
- if (!repo) return /* @__PURE__ */ new Set();
8653
- const git = await lib();
8654
- for (const ref of ["refs/remotes/origin/HEAD", "refs/heads/main", "refs/heads/master"]) {
8655
- try {
8656
- const oid = await git.resolveRef({ fs, gitdir: repo.gitdir, ref });
8657
- const log = await git.log({ fs, gitdir: repo.gitdir, ref: oid, depth: Math.min(limit, MAX_COMMIT_SCAN) });
8658
- return new Set(log.map((c) => c.oid));
8659
- } catch {
8766
+ async function resolveForItem(ref) {
8767
+ const itemId = itemRow(store, parse(idSchema, ref)).id;
8768
+ return resolve(sourcesForItem(itemId), forItem(itemId));
8769
+ }
8770
+ async function resolve(sources, list) {
8771
+ return Promise.all(list.map(async (ref) => ref.type === "commit" ? { ...ref, commit: await findCommit(sources, ref.target) } : ref));
8772
+ }
8773
+ function read(refId, options = {}) {
8774
+ const ref = toRef(refRow(store, parse(idSchema, refId)));
8775
+ if (ref.type !== "file") throw invalid(`ref ${refId} is a ${ref.type} ref; only file refs can be read`);
8776
+ const { project } = owner(ref.itemId);
8777
+ const target = splitFileTarget(ref.target);
8778
+ const abs = resolveInside(project.path, target.path);
8779
+ if (!existsSync5(abs)) return { ref, path: abs, state: "missing" };
8780
+ const stat = statSync(abs);
8781
+ if (!stat.isFile()) throw invalid(`${target.path} is not a regular file`);
8782
+ if (stat.size > MAX_REF_BYTES) {
8783
+ throw new SlateError("too_large", `${target.path} is ${stat.size} bytes; the limit is ${MAX_REF_BYTES}`, {
8784
+ size: stat.size,
8785
+ limit: MAX_REF_BYTES
8786
+ });
8660
8787
  }
8788
+ const buf = readFileSync2(abs);
8789
+ if (looksBinary(buf)) return { ref, path: abs, state: "binary", size: buf.length };
8790
+ const content = buf.toString("utf8");
8791
+ if (!target.lines) return { ref, path: abs, state: "ok", size: buf.length, content };
8792
+ const all = splitLines(content);
8793
+ const lines = { ...target.lines, total: all.length };
8794
+ if (options.full) return { ref, path: abs, state: "ok", size: buf.length, content, lines };
8795
+ return { ref, path: abs, state: "ok", size: buf.length, content: all.slice(lines.start - 1, lines.end).join(""), lines };
8661
8796
  }
8662
- return /* @__PURE__ */ new Set();
8797
+ return { add, remove, read, forItem, resolveForItem, resolve, commitSources, sourcesForItem, findCommit };
8663
8798
  }
8664
- function keyFromBranch(branch) {
8665
- return branch && /^slate\/([A-Za-z]{2,5}-\d{1,9})(?:-|$)/.exec(branch)?.[1]?.toUpperCase() || null;
8799
+
8800
+ // ../core/src/services/architecture.ts
8801
+ var ARCHITECTURE_DIR = "docs/architecture";
8802
+ var MAX_ARCHITECTURE_VIEWS = 50;
8803
+ var MAX_ARCHITECTURE_WATCHES = 32;
8804
+ var MAX_MODEL_BYTES = 8 * 1024 * 1024;
8805
+ var ARCHITECTURE_DEBOUNCE_MS = 200;
8806
+ var NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
8807
+ var ORDER = ["system", "packages", "components"];
8808
+ var rank = (name) => {
8809
+ const i = ORDER.indexOf(name);
8810
+ return i >= 0 ? i : name.startsWith("flow-") ? ORDER.length : ORDER.length + 1;
8811
+ };
8812
+ function titleOf(markdown, name) {
8813
+ const m = /^#[ \t]+(.+?)[ \t#]*$/m.exec(markdown);
8814
+ return m ? m[1].trim() : name;
8666
8815
  }
8667
- function locateRepo(repoPath) {
8816
+ function directoryOf(root) {
8817
+ const dir = path5.join(root, ARCHITECTURE_DIR);
8818
+ if (!existsSync6(dir)) return null;
8668
8819
  try {
8669
- const start = path3.resolve(repoPath);
8670
- if (!isDir(start)) return null;
8671
- if (isFile(path3.join(start, "HEAD")) && isDir(path3.join(start, "refs"))) {
8672
- const bare = valid({ gitdir: start, headDir: start });
8673
- if (bare) return bare;
8674
- }
8675
- for (let dir = start; ; dir = path3.dirname(dir)) {
8676
- const dotgit = path3.join(dir, ".git");
8677
- let stat;
8678
- try {
8679
- stat = fs.statSync(dotgit);
8680
- } catch {
8681
- stat = void 0;
8682
- }
8683
- if (stat?.isDirectory()) return valid({ gitdir: dotgit, headDir: dotgit });
8684
- if (stat?.isFile()) return fromGitFile(dotgit);
8685
- if (path3.dirname(dir) === dir) return null;
8686
- }
8820
+ const real = realpathSync2.native(dir);
8821
+ if (!isInside(real, realpathSync2.native(root)) || !statSync2(real).isDirectory()) return null;
8822
+ return real;
8687
8823
  } catch {
8688
8824
  return null;
8689
8825
  }
8690
8826
  }
8691
- async function headOf(repo) {
8692
- let head;
8827
+ function fileOf(dir, name) {
8828
+ if (!NAME.test(name)) return null;
8829
+ const candidate = path5.join(dir, `${name}.md`);
8693
8830
  try {
8694
- head = fs.readFileSync(path3.join(repo.headDir, "HEAD"), "utf8").trim();
8831
+ const real = realpathSync2.native(candidate);
8832
+ if (path5.dirname(real) !== dir) return null;
8833
+ const stat = statSync2(real);
8834
+ if (!stat.isFile()) return null;
8835
+ return { abs: real, size: stat.size, mtime: stat.mtime };
8695
8836
  } catch {
8696
8837
  return null;
8697
8838
  }
8698
- const symbolic = /^ref:\s*(\S+)$/.exec(head);
8699
- if (!symbolic) return /^[0-9a-f]{40}([0-9a-f]{24})?$/.test(head) ? head : null;
8700
- const git = await lib();
8701
- return git.resolveRef({ fs, gitdir: repo.gitdir, ref: symbolic[1] }).catch(() => null);
8702
- }
8703
- async function entryFor(repo) {
8704
- const head = await headOf(repo);
8705
- if (!head) return null;
8706
- const now = Date.now();
8707
- const existing = cache.get(repo.gitdir);
8708
- if (existing && existing.head === head && now - existing.at < GIT_CACHE_TTL_MS) return existing;
8709
- const entry = { head, at: now, walks: /* @__PURE__ */ new Map(), shas: /* @__PURE__ */ new Map() };
8710
- cache.set(repo.gitdir, entry);
8711
- return entry;
8712
- }
8713
- function info(sha2, message, author, timestamp) {
8714
- return {
8715
- sha: sha2,
8716
- shortSha: sha2.slice(0, SHORT),
8717
- subject: message.split("\n", 1)[0].trim(),
8718
- author,
8719
- date: new Date(timestamp * 1e3).toISOString()
8720
- };
8721
8839
  }
8722
- async function resolveCommit(repoPath, sha2) {
8723
- const wanted = sha2.trim().toLowerCase();
8724
- if (!/^[0-9a-f]{4,64}$/.test(wanted)) return null;
8725
- const repo = locateRepo(repoPath);
8726
- if (!repo) return null;
8727
- const entry = await entryFor(repo);
8728
- const lookup = async () => {
8729
- const git = await lib();
8730
- try {
8731
- const oid = wanted.length >= 40 ? wanted : await git.expandOid({ fs, gitdir: repo.gitdir, oid: wanted });
8732
- const { commit } = await git.readCommit({ fs, gitdir: repo.gitdir, oid });
8733
- return info(oid, commit.message, commit.author.name, commit.author.timestamp);
8734
- } catch {
8735
- return null;
8736
- }
8737
- };
8738
- if (!entry) return lookup();
8739
- let pending = entry.shas.get(wanted);
8740
- if (!pending) {
8741
- pending = lookup();
8742
- entry.shas.set(wanted, pending);
8840
+ function createArchitectureService(ctx, events) {
8841
+ const { store } = ctx;
8842
+ function locate(projectId) {
8843
+ const project = projectRow(store, parse(idSchema, projectId));
8844
+ return { project, dir: existsSync6(project.path) ? directoryOf(project.path) : null };
8743
8845
  }
8744
- return pending;
8745
- }
8746
- async function walk(repo, entry, limit) {
8747
- let pending = entry.walks.get(limit);
8748
- if (!pending) {
8749
- pending = lib().then(
8750
- (git) => git.log({ fs, gitdir: repo.gitdir, ref: entry.head, depth: limit }).then((log) => log.map((c) => ({ sha: c.oid, message: c.commit.message, author: c.commit.author.name, timestamp: c.commit.author.timestamp }))).catch(() => [])
8751
- );
8752
- entry.walks.set(limit, pending);
8846
+ function view(name, file, markdown) {
8847
+ return { name, title: titleOf(markdown, name), file: `${ARCHITECTURE_DIR}/${name}.md`, mtime: file.mtime.toISOString(), size: file.size };
8753
8848
  }
8754
- return pending;
8755
- }
8756
- async function ignoreChecker(dir) {
8757
- const git = await lib();
8758
- let workTree = path3.resolve(dir);
8759
- for (let d = workTree; ; d = path3.dirname(d)) {
8760
- if (fs.existsSync(path3.join(d, ".git"))) {
8761
- workTree = d;
8762
- break;
8849
+ function list(projectId) {
8850
+ const { project, dir } = locate(projectId);
8851
+ watchProject(project.id);
8852
+ if (!dir) return [];
8853
+ const out = [];
8854
+ const names = readdirSync2(dir).filter((f) => f.endsWith(".md")).map((f) => f.slice(0, -3)).filter((n) => NAME.test(n));
8855
+ for (const name of names) {
8856
+ const file = fileOf(dir, name);
8857
+ if (!file || file.size > MAX_REF_BYTES) continue;
8858
+ out.push(view(name, file, readFileSync3(file.abs, "utf8")));
8763
8859
  }
8764
- if (path3.dirname(d) === d) break;
8860
+ out.sort((a, b) => rank(a.name) - rank(b.name) || a.name.localeCompare(b.name));
8861
+ return out.slice(0, MAX_ARCHITECTURE_VIEWS);
8765
8862
  }
8766
- const gitdir = locateRepo(workTree)?.gitdir ?? path3.join(workTree, ".git");
8767
- const prefix = path3.relative(workTree, path3.resolve(dir)).split(path3.sep).join("/");
8768
- return (rel, isDirectory) => {
8769
- const filepath = (prefix ? `${prefix}/${rel}` : rel) + (isDirectory ? "/" : "");
8770
- return git.isIgnored({ fs, dir: workTree, gitdir, filepath }).catch(() => false);
8863
+ function read(projectId, name) {
8864
+ const { dir } = locate(projectId);
8865
+ const file = dir ? fileOf(dir, name) : null;
8866
+ if (!dir || !file) throw notFound("architecture view", name);
8867
+ if (file.size > MAX_REF_BYTES) {
8868
+ throw new SlateError("too_large", `${name}.md is ${file.size} bytes; the limit is ${MAX_REF_BYTES}`, { size: file.size, limit: MAX_REF_BYTES });
8869
+ }
8870
+ const markdown = readFileSync3(file.abs, "utf8");
8871
+ return { ...view(name, file, markdown), markdown };
8872
+ }
8873
+ function status(projectId) {
8874
+ const { dir } = locate(projectId);
8875
+ if (!dir) return { components: "none" };
8876
+ const json = (name) => {
8877
+ const abs = path5.join(dir, name);
8878
+ try {
8879
+ const stat = statSync2(abs);
8880
+ if (!stat.isFile() || stat.size > MAX_MODEL_BYTES) return null;
8881
+ return { mtime: stat.mtimeMs, data: JSON.parse(readFileSync3(abs, "utf8")) };
8882
+ } catch {
8883
+ return null;
8884
+ }
8885
+ };
8886
+ const components = json("components.json");
8887
+ const facts = components ? json("facts.json") : null;
8888
+ if (!components || !facts) return { components: "none" };
8889
+ const hash = facts.data.sources?.hash;
8890
+ const stamp = components.data.facts;
8891
+ const behind = typeof stamp === "string" && typeof hash === "string" ? stamp !== hash : components.mtime < facts.mtime;
8892
+ return { components: behind ? "behind" : "current" };
8893
+ }
8894
+ const watches = /* @__PURE__ */ new Map();
8895
+ const pathOf = (id) => store.db.prepare("SELECT path FROM projects WHERE id = ?").get(id)?.path;
8896
+ const onEvent = (e) => {
8897
+ if (!e.type.startsWith("project.") && e.type !== "workspace.deleted") return;
8898
+ for (const [id, w] of [...watches]) {
8899
+ const now = pathOf(id);
8900
+ if (now === w.root) continue;
8901
+ unwatch(id);
8902
+ if (now) watchProject(id);
8903
+ }
8771
8904
  };
8772
- }
8773
- var TOKEN = /[A-Za-z0-9_-]+/g;
8774
- var KEY_TOKEN = /^[A-Za-z]{2,5}-\d{1,9}$/;
8775
- async function findCommitsMentioning(repoPath, ids, options = {}) {
8776
- const wanted = new Set(ids.filter((id) => id.length > 0));
8777
- if (wanted.size === 0) return [];
8778
- const limit = Math.max(1, Math.min(MAX_COMMIT_SCAN, Math.floor(options.limit ?? DEFAULT_COMMIT_SCAN)));
8779
- const repo = locateRepo(repoPath);
8780
- if (!repo) return [];
8781
- const entry = await entryFor(repo);
8782
- if (!entry) return [];
8783
- const out = [];
8784
- for (const c of await walk(repo, entry, limit)) {
8785
- const mentioned = new Set(
8786
- (c.message.match(TOKEN) ?? []).map((token) => wanted.has(token) ? token : KEY_TOKEN.test(token) && wanted.has(token.toUpperCase()) ? token.toUpperCase() : null)
8787
- );
8788
- mentioned.delete(null);
8789
- for (const id of mentioned) out.push({ itemId: id, ...info(c.sha, c.message, c.author, c.timestamp) });
8905
+ let unsubscribe = null;
8906
+ function unwatch(projectId) {
8907
+ watches.get(projectId)?.close();
8908
+ watches.delete(projectId);
8909
+ if (watches.size === 0) {
8910
+ unsubscribe?.();
8911
+ unsubscribe = null;
8912
+ }
8790
8913
  }
8791
- return out;
8792
- }
8793
-
8794
- // ../core/src/services/rows.ts
8795
- import { existsSync as existsSync3 } from "node:fs";
8796
- var ITEM_SELECT = "SELECT i.*, p.key AS project_key FROM items i JOIN projects p ON p.id = i.project_id";
8797
- function toWorkspace(row) {
8798
- return {
8799
- id: row.id,
8800
- name: row.name,
8801
- rootPath: row.root_path,
8802
- createdAt: row.created_at,
8803
- updatedAt: row.updated_at,
8804
- missing: !existsSync3(row.root_path)
8805
- };
8806
- }
8807
- function toProject(row) {
8808
- return {
8809
- id: row.id,
8810
- key: row.key,
8811
- gitTransitions: row.git_transitions === 1,
8812
- roadmapFile: row.roadmap_file,
8813
- workspaceId: row.workspace_id,
8814
- name: row.name,
8815
- path: row.path,
8816
- description: row.description,
8817
- milestones: JSON.parse(row.milestones),
8818
- archived: row.archived === 1,
8819
- createdAt: row.created_at,
8820
- updatedAt: row.updated_at,
8821
- missing: !existsSync3(row.path)
8822
- };
8823
- }
8824
- function toStatus(row) {
8825
- return { key: row.key, label: row.label, position: row.position, kind: row.kind, isDefault: row.is_default === 1 };
8914
+ function watchProject(projectId) {
8915
+ if (watches.has(projectId)) return;
8916
+ const project = projectRow(store, projectId);
8917
+ if (!existsSync6(project.path)) return;
8918
+ while (watches.size >= MAX_ARCHITECTURE_WATCHES) unwatch(watches.keys().next().value);
8919
+ const root = project.path;
8920
+ const levels = [path5.join(root, ARCHITECTURE_DIR), path5.join(root, "docs"), root];
8921
+ let watcher = null;
8922
+ let watching = -1;
8923
+ let timer = null;
8924
+ let closed = false;
8925
+ const publish = () => {
8926
+ if (timer) clearTimeout(timer);
8927
+ timer = setTimeout(() => {
8928
+ timer = null;
8929
+ if (closed) return;
8930
+ events.publish({ type: "architecture.changed", workspaceId: project.workspace_id, projectId, id: projectId, at: ctx.now() });
8931
+ }, ARCHITECTURE_DEBOUNCE_MS);
8932
+ timer.unref?.();
8933
+ };
8934
+ const deepest = () => levels.findIndex((l) => existsSync6(l));
8935
+ const arm = () => {
8936
+ for (; ; ) {
8937
+ watcher?.close();
8938
+ watcher = null;
8939
+ watching = deepest();
8940
+ if (watching < 0) return;
8941
+ try {
8942
+ watcher = watch(levels[watching], { persistent: false }, onChange);
8943
+ watcher.on("error", () => {
8944
+ if (!closed) arm();
8945
+ });
8946
+ } catch {
8947
+ watcher = null;
8948
+ }
8949
+ if (deepest() === watching) return;
8950
+ }
8951
+ };
8952
+ const onChange = () => {
8953
+ if (closed) return;
8954
+ if (deepest() !== watching) {
8955
+ const had = watching === 0;
8956
+ arm();
8957
+ if (had || watching === 0) publish();
8958
+ return;
8959
+ }
8960
+ if (watching === 0) publish();
8961
+ };
8962
+ arm();
8963
+ unsubscribe ??= events.subscribe(onEvent);
8964
+ watches.set(projectId, {
8965
+ root,
8966
+ close() {
8967
+ closed = true;
8968
+ if (timer) clearTimeout(timer);
8969
+ watcher?.close();
8970
+ }
8971
+ });
8972
+ }
8973
+ function close() {
8974
+ for (const id of [...watches.keys()]) unwatch(id);
8975
+ }
8976
+ return { list, read, status, close, watching: () => [...watches.keys()] };
8826
8977
  }
8827
- function toItem(row) {
8828
- return {
8829
- id: row.id,
8830
- key: itemKey(row.project_key ?? null, row.number),
8831
- projectId: row.project_id,
8832
- title: row.title,
8833
- details: row.details,
8834
- status: row.status,
8835
- sortKey: row.sort_key,
8836
- milestone: row.milestone,
8837
- priority: row.priority,
8838
- tags: JSON.parse(row.tags),
8839
- revision: row.revision,
8840
- createdAt: row.created_at,
8841
- updatedAt: row.updated_at,
8842
- completedAt: row.completed_at,
8843
- claim: claimOf(row)
8844
- };
8978
+
8979
+ // ../core/src/services/board-format.ts
8980
+ var import_yaml = __toESM(require_dist(), 1);
8981
+ var BOARD_FORMAT_VERSION = 1;
8982
+ var PRIORITY = ["", "low", "medium", "high"];
8983
+ var REF_LINE = /^- (file|url|commit|pr) (.*)$/;
8984
+ var ITEM_LINE = /^- \[([ xX])\] (.*)$/;
8985
+ var ITEM_ANCHOR = /\s*<!--\s*slate\s+id:(\S+)\s+rev:(\d+)\s*-->\s*$/;
8986
+ var DETAILS_OPEN = /^ {2}<details>\s*(<summary>.*<\/summary>)?\s*$/;
8987
+ var DETAILS_CLOSE = " </details>";
8988
+ var DATE = /^\d{4}-\d{2}-\d{2}$/;
8989
+ function code(value) {
8990
+ const longest = Math.max(0, ...(value.match(/`+/g) ?? []).map((run) => run.length));
8991
+ const fence = "`".repeat(longest + 1);
8992
+ const pad = longest > 0 || value.startsWith("`") || value.endsWith("`") ? " " : "";
8993
+ return `${fence}${pad}${value}${pad}${fence}`;
8845
8994
  }
8846
- function claimOf(row, now = (/* @__PURE__ */ new Date()).toISOString()) {
8847
- return row.claimed_by && row.claimed_until && row.claimed_until > now ? { by: row.claimed_by, until: row.claimed_until } : null;
8995
+ function oneLine(text) {
8996
+ return text.replace(/\s*\n\s*/g, " ");
8848
8997
  }
8849
- function toRef(row) {
8850
- return { id: row.id, itemId: row.item_id, type: row.type, target: row.target, label: row.label, createdAt: row.created_at };
8998
+ function tag(value) {
8999
+ return /^[^\s`#·,]+$/.test(value) ? `#${value}` : `#${code(value)}`;
8851
9000
  }
8852
- function workspaceRow(store, id) {
8853
- const row = store.db.prepare("SELECT * FROM workspaces WHERE id = ?").get(id);
8854
- if (!row) throw notFound("workspace", id);
8855
- return row;
9001
+ var YAML_RESERVED = /^(true|false|null|yes|no|on|off|y|n|~)$/i;
9002
+ function scalar(value) {
9003
+ if (/^[A-Za-z][A-Za-z0-9 ._/()+-]*$/.test(value) && !value.endsWith(" ") && !YAML_RESERVED.test(value)) return value;
9004
+ return JSON.stringify(value);
8856
9005
  }
8857
- function projectRow(store, id) {
8858
- const row = store.db.prepare("SELECT * FROM projects WHERE id = ?").get(id);
8859
- if (!row) throw notFound("project", id);
8860
- return row;
9006
+ function frontmatter(board) {
9007
+ const out = ["---", `slate: ${BOARD_FORMAT_VERSION}`, `project: ${scalar(board.name)}`];
9008
+ if (board.description) out.push(`description: ${scalar(board.description)}`);
9009
+ out.push("columns:");
9010
+ for (const c of board.columns) {
9011
+ out.push(` - { key: ${scalar(c.key)}, label: ${scalar(c.label)}, kind: ${c.kind}${c.isDefault ? ", default: true" : ""} }`);
9012
+ }
9013
+ out.push(`milestones: [${board.milestones.map(scalar).join(", ")}]`, "---");
9014
+ return out;
8861
9015
  }
8862
- function itemRow(store, ref) {
8863
- const id = resolveItemId(store, ref);
8864
- const row = store.db.prepare(`${ITEM_SELECT} WHERE i.id = ?`).get(id);
8865
- if (!row) throw notFound("item", id);
8866
- return row;
9016
+ function metaLine(item, order, done) {
9017
+ const byBoardOrder = (ids) => [...ids].sort((a, b) => (order.get(a) ?? Infinity) - (order.get(b) ?? Infinity) || (a < b ? -1 : a > b ? 1 : 0));
9018
+ const parts = [];
9019
+ if (item.milestone) parts.push(code(item.milestone));
9020
+ if (item.priority > 0) parts.push(PRIORITY[item.priority]);
9021
+ if (item.tags.length > 0) parts.push(item.tags.map(tag).join(" "));
9022
+ if (item.links.blockedBy.length > 0) parts.push(`blocked by ${byBoardOrder(item.links.blockedBy.map((l) => l.id)).map(code).join(", ")}`);
9023
+ if (item.links.relates.length > 0) parts.push(`relates ${byBoardOrder(item.links.relates.map((l) => l.id)).map(code).join(", ")}`);
9024
+ if (done && item.completedAt) parts.push(`done ${item.completedAt.slice(0, 10)}`);
9025
+ return parts.length > 0 ? parts.join(" \xB7 ") : null;
8867
9026
  }
8868
- function refRow(store, id) {
8869
- const row = store.db.prepare("SELECT * FROM refs WHERE id = ?").get(id);
8870
- if (!row) throw notFound("ref", id);
8871
- return row;
9027
+ function itemBlock(item, order, done) {
9028
+ const out = [`- [${done ? "x" : " "}] ${code(item.id)} ${oneLine(item.title)} <!-- slate id:${item.id} rev:${item.revision} -->`];
9029
+ const meta2 = metaLine(item, order, done);
9030
+ if (meta2) out.push(` - ${meta2}`);
9031
+ for (const ref of item.refs) out.push(` - ${ref.type} ${code(ref.target)}${ref.label ? ` \u2014 ${oneLine(ref.label)}` : ""}`);
9032
+ if (item.details) {
9033
+ out.push(" <details><summary>Details</summary>", "");
9034
+ for (const line of item.details.split("\n")) out.push(line === "" ? "" : ` ${line}`);
9035
+ out.push("", DETAILS_CLOSE);
9036
+ }
9037
+ return out;
8872
9038
  }
8873
- function hasOwnStatuses(store, projectId) {
8874
- return store.db.prepare("SELECT 1 FROM statuses WHERE scope_type = 'project' AND scope_id = ? LIMIT 1").get(projectId) !== void 0;
9039
+ function renderBoard(board) {
9040
+ const order = /* @__PURE__ */ new Map();
9041
+ for (const column of board.columns) for (const item of board.items.get(column.key) ?? []) order.set(item.id, order.size);
9042
+ const out = [...frontmatter(board), "", `# ${oneLine(board.name)}`];
9043
+ if (board.description) out.push("", ...board.description.trim().split("\n").map((l) => l ? `> ${l}` : ">"));
9044
+ for (const column of board.columns) {
9045
+ out.push("", `## ${column.label}`);
9046
+ for (const item of board.items.get(column.key) ?? []) out.push("", ...itemBlock(item, order, column.kind === "done"));
9047
+ }
9048
+ return `${out.join("\n")}
9049
+ `;
8875
9050
  }
8876
- function scopeStatuses(store, scopeType, scopeId) {
8877
- const rows = store.db.prepare("SELECT key, label, position, kind, is_default FROM statuses WHERE scope_type = ? AND scope_id = ? ORDER BY position").all(scopeType, scopeId);
8878
- return rows.map(toStatus);
9051
+ function fail(line, message) {
9052
+ throw invalid(`line ${line}: ${message}`, { line });
8879
9053
  }
8880
- function effectiveStatuses(store, projectId) {
8881
- const own = scopeStatuses(store, "project", projectId);
8882
- if (own.length > 0) return own;
8883
- return scopeStatuses(store, "workspace", projectRow(store, projectId).workspace_id);
9054
+ var frontmatterSchema = external_exports.object({
9055
+ slate: external_exports.literal(BOARD_FORMAT_VERSION, { error: `unsupported board format version; this slate reads version ${BOARD_FORMAT_VERSION}` }),
9056
+ project: external_exports.string().optional(),
9057
+ description: external_exports.string().nullable().optional(),
9058
+ columns: external_exports.array(
9059
+ external_exports.object({
9060
+ key: statusKeySchema,
9061
+ label: external_exports.string().trim().min(1).max(100),
9062
+ kind: statusKindSchema,
9063
+ default: external_exports.boolean().optional()
9064
+ })
9065
+ ).min(1),
9066
+ milestones: external_exports.array(milestoneSchema).optional()
9067
+ });
9068
+ function readCodeSpan(s, i) {
9069
+ let n = 0;
9070
+ while (s[i + n] === "`") n++;
9071
+ if (n === 0) return null;
9072
+ const fence = "`".repeat(n);
9073
+ let j = i + n;
9074
+ for (; ; ) {
9075
+ const close = s.indexOf(fence, j);
9076
+ if (close < 0) return null;
9077
+ if (s[close + n] === "`" || s[close - 1] === "`") {
9078
+ j = close + n;
9079
+ while (s[j] === "`") j++;
9080
+ continue;
9081
+ }
9082
+ let value = s.slice(i + n, close);
9083
+ if (value.length > 1 && value.startsWith(" ") && value.endsWith(" ") && value.trim() !== "") value = value.slice(1, -1);
9084
+ return { value, end: close + n };
9085
+ }
8884
9086
  }
8885
- function requireStatus(statuses, key) {
8886
- const status = statuses.find((s) => s.key === key);
8887
- if (!status) {
8888
- throw new SlateError("invalid_argument", `unknown status '${key}'`, { valid: statuses.map((s) => s.key) });
9087
+ function splitMeta(s) {
9088
+ const parts = [];
9089
+ let start = 0;
9090
+ let i = 0;
9091
+ while (i < s.length) {
9092
+ if (s[i] === "`") {
9093
+ const span = readCodeSpan(s, i);
9094
+ if (span) {
9095
+ i = span.end;
9096
+ continue;
9097
+ }
9098
+ }
9099
+ if (s.startsWith(" \xB7 ", i)) {
9100
+ parts.push(s.slice(start, i));
9101
+ i += 3;
9102
+ start = i;
9103
+ continue;
9104
+ }
9105
+ i++;
8889
9106
  }
8890
- return status;
9107
+ parts.push(s.slice(start));
9108
+ return parts.map((p) => p.trim()).filter((p) => p !== "");
8891
9109
  }
8892
- function isBlocked(store, itemId) {
8893
- return store.db.prepare(
8894
- `SELECT 1 FROM item_links l JOIN items b ON b.id = l.from_id
8895
- WHERE l.to_id = ? AND l.kind = 'blocks' AND b.completed_at IS NULL LIMIT 1`
8896
- ).get(itemId) !== void 0;
9110
+ function wholeCodeSpan(s) {
9111
+ const span = readCodeSpan(s, 0);
9112
+ return span && span.end === s.length ? span.value : null;
8897
9113
  }
8898
-
8899
- // ../core/src/services/refs.ts
8900
- var MAX_REF_BYTES = 256 * 1024;
8901
- var MAX_WORKSPACE_REPOS = 25;
8902
- function sandboxError(target, root) {
8903
- return new SlateError("sandbox", `${target} is outside the project root ${root}`, { target, root });
9114
+ function idList(s, line) {
9115
+ return s.split(",").map((part) => {
9116
+ const raw = part.trim();
9117
+ const id = wholeCodeSpan(raw) ?? raw;
9118
+ if (!/^[A-Za-z0-9_-]+$/.test(id)) fail(line, `'${raw}' is not an item id`);
9119
+ return id;
9120
+ });
8904
9121
  }
8905
- function resolveInside(root, target) {
8906
- const abs = path4.resolve(root, expandHome(target));
8907
- if (!isInside(abs, root)) throw sandboxError(target, root);
8908
- if (!isInside(normalizePath(abs), normalizePath(root))) throw sandboxError(target, root);
8909
- return abs;
9122
+ function tagList(s, line) {
9123
+ const tags = [];
9124
+ let i = 0;
9125
+ while (i < s.length) {
9126
+ if (s[i] === " ") {
9127
+ i++;
9128
+ continue;
9129
+ }
9130
+ if (s[i] !== "#") fail(line, `expected a #tag, found '${s.slice(i)}'`);
9131
+ i++;
9132
+ const span = s[i] === "`" ? readCodeSpan(s, i) : null;
9133
+ if (span) {
9134
+ tags.push(span.value);
9135
+ i = span.end;
9136
+ continue;
9137
+ }
9138
+ const end = s.indexOf(" ", i) < 0 ? s.length : s.indexOf(" ", i);
9139
+ const value = s.slice(i, end);
9140
+ if (!value) fail(line, "empty #tag");
9141
+ tags.push(value);
9142
+ i = end;
9143
+ }
9144
+ return tags;
8910
9145
  }
8911
- var LINE_SUFFIX = /#L(\d+)(?:-L?(\d+))?$/;
8912
- var LINE_LIKE = /#L\d[^#/]*$/;
8913
- function splitFileTarget(target) {
8914
- const m = LINE_SUFFIX.exec(target);
8915
- if (!m) {
8916
- if (LINE_LIKE.test(target)) throw invalid(`not a line range: ${target.slice(target.lastIndexOf("#"))}; use #L40 or #L40-80`);
8917
- return { path: target, lines: null };
9146
+ function applyMeta(item, text, line) {
9147
+ for (const part of splitMeta(text)) {
9148
+ const milestone = wholeCodeSpan(part);
9149
+ if (milestone !== null) {
9150
+ if (item.milestone !== null) fail(line, "an item has one milestone");
9151
+ item.milestone = milestone;
9152
+ } else if (PRIORITY.includes(part) && part !== "") {
9153
+ item.priority = PRIORITY.indexOf(part);
9154
+ } else if (part.startsWith("#")) {
9155
+ item.tags.push(...tagList(part, line));
9156
+ } else if (part.startsWith("blocked by ")) {
9157
+ item.blockedBy.push(...idList(part.slice("blocked by ".length), line));
9158
+ } else if (part.startsWith("relates ")) {
9159
+ item.relates.push(...idList(part.slice("relates ".length), line));
9160
+ } else if (part.startsWith("done ") && DATE.test(part.slice(5))) {
9161
+ item.completedOn = part.slice(5);
9162
+ } else {
9163
+ fail(line, `unknown metadata '${part}'; expected \`milestone\`, low|medium|high, #tags, 'blocked by', 'relates' or 'done YYYY-MM-DD'`);
9164
+ }
8918
9165
  }
8919
- const start = Number(m[1]);
8920
- const end = m[2] === void 0 ? start : Number(m[2]);
8921
- if (start < 1) throw invalid(`line numbers start at 1: ${target}`);
8922
- if (end < start) throw invalid(`a line range ends at or after its start: ${target}`);
8923
- return { path: target.slice(0, m.index), lines: { start, end } };
8924
9166
  }
8925
- function lineSuffix(lines) {
8926
- if (!lines) return "";
8927
- return lines.end === lines.start ? `#L${lines.start}` : `#L${lines.start}-${lines.end}`;
9167
+ function parseRef(type, rest, line) {
9168
+ const span = readCodeSpan(rest, 0);
9169
+ if (!span) fail(line, `a ${type} ref's target is a code span, for example: - ${type} \`target\``);
9170
+ const label = rest.slice(span.end).trim().replace(/^(—|--|-)\s*/, "").trim();
9171
+ return { type: refTypeSchema.parse(type), target: span.value, label: label || null };
8928
9172
  }
8929
- function splitLines(text) {
8930
- return text === "" ? [] : text.split(/(?<=\n)/);
9173
+ function parseFrontmatter(lines) {
9174
+ if (lines[0] !== "---") fail(1, "a board file starts with '---' frontmatter");
9175
+ const close = lines.indexOf("---", 1);
9176
+ if (close < 0) fail(1, "the frontmatter is not closed with '---'");
9177
+ let raw;
9178
+ try {
9179
+ raw = (0, import_yaml.parse)(lines.slice(1, close).join("\n"));
9180
+ } catch (err) {
9181
+ fail(2, `frontmatter is not valid YAML: ${err.message.split("\n")[0]}`);
9182
+ }
9183
+ const result = frontmatterSchema.safeParse(raw);
9184
+ if (!result.success) {
9185
+ const issue = result.error.issues[0];
9186
+ fail(1, `frontmatter ${issue.path.join(".") || "root"}: ${issue.message}`);
9187
+ }
9188
+ return { meta: result.data, next: close + 1 };
8931
9189
  }
8932
- function normalizeTarget(type, target, root) {
8933
- switch (type) {
8934
- case "file": {
8935
- const { path: file, lines } = splitFileTarget(target);
8936
- const rel = path4.relative(root, resolveInside(root, file));
8937
- if (rel === "") throw invalid("a file ref must point at a file inside the project, not the project root");
8938
- return rel.split(path4.sep).join("/") + lineSuffix(lines);
9190
+ function parseBoard(text) {
9191
+ const lines = text.replace(/\r\n/g, "\n").split("\n");
9192
+ const { meta: meta2, next } = parseFrontmatter(lines);
9193
+ const columns = meta2.columns.map((c) => ({ key: c.key, label: c.label, kind: c.kind, isDefault: c.default === true }));
9194
+ if (new Set(columns.map((c) => c.key)).size !== columns.length) fail(1, "column keys must be unique");
9195
+ if (new Set(columns.map((c) => c.label)).size !== columns.length) fail(1, "column labels must be unique");
9196
+ if (columns.filter((c) => c.isDefault).length !== 1) fail(1, "exactly one column must be 'default: true'");
9197
+ const byLabel = new Map(columns.map((c) => [c.label, c]));
9198
+ const sections = [];
9199
+ const seenIds = /* @__PURE__ */ new Map();
9200
+ let section = null;
9201
+ let item = null;
9202
+ for (let i = next; i < lines.length; i++) {
9203
+ const text2 = lines[i];
9204
+ const lineNo = i + 1;
9205
+ if (text2.trim() === "") continue;
9206
+ if (text2.startsWith("## ")) {
9207
+ const label = text2.slice(3).trim();
9208
+ const column = byLabel.get(label);
9209
+ if (!column) fail(lineNo, `'${label}' is not a column in the frontmatter (${columns.map((c) => c.label).join(", ")})`);
9210
+ if (sections.some((s) => s.column.key === column.key)) fail(lineNo, `column '${label}' appears twice`);
9211
+ section = { line: lineNo, column, items: [] };
9212
+ sections.push(section);
9213
+ item = null;
9214
+ continue;
9215
+ }
9216
+ const itemMatch = ITEM_LINE.exec(text2);
9217
+ if (itemMatch) {
9218
+ if (!section) fail(lineNo, "an item must be under a '## Column' heading");
9219
+ let rest = itemMatch[2];
9220
+ let id = null;
9221
+ let revision = null;
9222
+ const anchor = ITEM_ANCHOR.exec(rest);
9223
+ if (anchor) {
9224
+ id = anchor[1];
9225
+ revision = Number(anchor[2]);
9226
+ rest = rest.slice(0, anchor.index);
9227
+ if (seenIds.has(id)) fail(lineNo, `item ${id} also appears on line ${seenIds.get(id)}`);
9228
+ seenIds.set(id, lineNo);
9229
+ const shown = `${code(id)} `;
9230
+ if (rest.startsWith(shown)) rest = rest.slice(shown.length);
9231
+ }
9232
+ const title = rest.trim();
9233
+ if (!title) fail(lineNo, "an item needs a title");
9234
+ item = {
9235
+ line: lineNo,
9236
+ id,
9237
+ revision,
9238
+ checked: itemMatch[1] !== " ",
9239
+ title,
9240
+ details: null,
9241
+ milestone: null,
9242
+ priority: 0,
9243
+ tags: [],
9244
+ blockedBy: [],
9245
+ relates: [],
9246
+ refs: [],
9247
+ completedOn: null
9248
+ };
9249
+ section.items.push(item);
9250
+ continue;
8939
9251
  }
8940
- case "url": {
8941
- let url;
8942
- try {
8943
- url = new URL(target);
8944
- } catch {
8945
- throw invalid(`not a valid URL: ${target}`);
9252
+ if (!text2.startsWith(" ")) {
9253
+ if (/^[-*+] /.test(text2)) fail(lineNo, "not an item line; items look like '- [ ] Title'");
9254
+ continue;
9255
+ }
9256
+ if (!item) fail(lineNo, "indented line outside an item");
9257
+ if (DETAILS_OPEN.test(text2)) {
9258
+ let end = i + 1;
9259
+ while (end < lines.length && (lines[end] === "" || lines[end].startsWith(" "))) end++;
9260
+ let close = -1;
9261
+ for (let j = end - 1; j > i; j--) {
9262
+ if (lines[j] === DETAILS_CLOSE) {
9263
+ close = j;
9264
+ break;
9265
+ }
8946
9266
  }
8947
- if (url.protocol !== "http:" && url.protocol !== "https:") throw invalid("url refs must be http or https");
8948
- return url.toString();
9267
+ if (close < 0) fail(lineNo, "<details> is not closed with an indented </details>");
9268
+ let body = lines.slice(i + 1, close);
9269
+ if (body[0] === "") body = body.slice(1);
9270
+ if (body.at(-1) === "") body = body.slice(0, -1);
9271
+ const details = body.map((l) => l.replace(/^ {1,2}/, "")).join("\n");
9272
+ item.details = details === "" ? null : details;
9273
+ for (let j = close + 1; j < end; j++) if (lines[j].trim() !== "") fail(j + 1, "unexpected text after </details>");
9274
+ i = end - 1;
9275
+ continue;
8949
9276
  }
8950
- case "commit":
8951
- if (!/^[0-9a-f]{4,64}$/i.test(target)) throw invalid(`not a commit sha: ${target}`);
8952
- return target.toLowerCase();
8953
- case "pr": {
8954
- const n = /^#?(\d+)$/.exec(target);
8955
- if (n) return n[1];
8956
- if (/^https?:\/\//.test(target)) return normalizeTarget("url", target, root);
8957
- throw invalid(`a pr ref is a number or a URL: ${target}`);
9277
+ if (!text2.startsWith(" - ")) fail(lineNo, "expected ' - ' metadata, a ref, or <details>");
9278
+ if (item.details !== null) fail(lineNo, "metadata and refs go before <details>");
9279
+ const sub = text2.slice(2);
9280
+ const ref = REF_LINE.exec(sub);
9281
+ if (ref) {
9282
+ item.refs.push(parseRef(ref[1], ref[2], lineNo));
9283
+ continue;
8958
9284
  }
9285
+ applyMeta(item, sub.slice(2), lineNo);
8959
9286
  }
9287
+ return {
9288
+ project: meta2.project ?? null,
9289
+ description: meta2.description,
9290
+ columns,
9291
+ milestones: meta2.milestones ?? [],
9292
+ sections
9293
+ };
8960
9294
  }
8961
- function looksBinary(buf) {
8962
- if (buf.subarray(0, 8192).includes(0)) return true;
8963
- try {
8964
- new TextDecoder("utf-8", { fatal: true }).decode(buf);
8965
- return false;
8966
- } catch {
8967
- return true;
8968
- }
9295
+
9296
+ // ../core/src/services/export.ts
9297
+ var PRIORITY2 = ["", "low", "medium", "high"];
9298
+ function heading(level, text) {
9299
+ return `${"#".repeat(Math.min(level, 6))} ${text}`;
8969
9300
  }
8970
- function createRefService(ctx) {
8971
- const { store } = ctx;
8972
- const db = store.db;
8973
- function owner(itemId) {
8974
- const item = itemRow(store, itemId);
8975
- const project = projectRow(store, item.project_id);
8976
- return { item, project };
8977
- }
8978
- function add(input, createdAt) {
8979
- const { itemId: ref, type, target, label } = parse(refAddSchema, input);
8980
- return store.tx(() => {
8981
- const { item, project } = owner(ref);
8982
- const itemId = item.id;
8983
- const id = ctx.newId();
8984
- db.prepare("INSERT INTO refs (id, item_id, type, target, label, created_at) VALUES (?, ?, ?, ?, ?, ?)").run(
8985
- id,
8986
- itemId,
8987
- type,
8988
- normalizeTarget(type, target, project.path),
8989
- label ?? null,
8990
- createdAt ?? ctx.now()
8991
- );
8992
- ctx.emit("ref.added", { workspaceId: project.workspace_id, projectId: project.id, id });
8993
- return toRef(refRow(store, id));
8994
- });
8995
- }
8996
- function remove(refId) {
8997
- parse(idSchema, refId);
8998
- store.tx(() => {
8999
- const ref = refRow(store, refId);
9000
- const { project } = owner(ref.item_id);
9001
- db.prepare("DELETE FROM refs WHERE id = ?").run(refId);
9002
- ctx.emit("ref.removed", { workspaceId: project.workspace_id, projectId: project.id, id: refId });
9003
- });
9004
- }
9005
- function forItem(itemId) {
9006
- return db.prepare("SELECT * FROM refs WHERE item_id = ? ORDER BY created_at, id").all(itemId).map(toRef);
9007
- }
9008
- function commitSources(project) {
9009
- const own = { id: project.id, name: project.name, path: project.path };
9010
- const others = db.prepare("SELECT * FROM projects WHERE workspace_id = ? AND id <> ? ORDER BY name, id").all(project.workspace_id, project.id);
9011
- if (others.length === 0) return [own];
9012
- const seen = /* @__PURE__ */ new Set();
9013
- const ownRepo = locateRepo(project.path);
9014
- if (ownRepo) seen.add(ownRepo.gitdir);
9015
- const out = [own];
9016
- for (const p of others) {
9017
- if (out.length >= MAX_WORKSPACE_REPOS) break;
9018
- const repo = locateRepo(p.path);
9019
- if (!repo || seen.has(repo.gitdir)) continue;
9020
- seen.add(repo.gitdir);
9021
- out.push({ id: p.id, name: p.name, path: p.path });
9301
+ function refLine(ref) {
9302
+ return `- ${ref.type}: \`${ref.target}\`${ref.label ? ` (${ref.label})` : ""} [ref \`${ref.id}\`]`;
9303
+ }
9304
+ function linked(items) {
9305
+ return items.map((i) => `${i.title} (\`${i.id}\`${i.done ? ", done" : ""})`).join(", ");
9306
+ }
9307
+ function meta(item) {
9308
+ const parts = [`\`${item.id}\``, item.status];
9309
+ if (item.milestone) parts.push(`milestone ${item.milestone}`);
9310
+ if (item.priority > 0) parts.push(`priority ${PRIORITY2[item.priority]}`);
9311
+ if (item.tags.length > 0) parts.push(item.tags.map((t) => `#${t}`).join(" "));
9312
+ if (item.blocked) parts.push("**blocked**");
9313
+ if (item.completedAt) parts.push(`completed ${item.completedAt}`);
9314
+ return parts.join(" \xB7 ");
9315
+ }
9316
+ function itemMarkdown(item, level = 1) {
9317
+ const out = [heading(level, item.title), "", meta(item)];
9318
+ if (item.details) out.push("", item.details.trim());
9319
+ if (item.links.blockedBy.length > 0) out.push("", `Blocked by: ${linked(item.links.blockedBy)}`);
9320
+ if (item.links.blocks.length > 0) out.push("", `Blocks: ${linked(item.links.blocks)}`);
9321
+ if (item.links.relates.length > 0) out.push("", `Related: ${linked(item.links.relates)}`);
9322
+ if (item.refs.length > 0) out.push("", "Refs:", ...item.refs.map(refLine));
9323
+ return out.join("\n");
9324
+ }
9325
+ function createExportService(workspaces, projects, items) {
9326
+ function projectBody(project2, level) {
9327
+ const out = [heading(level, project2.name), "", `Path: \`${project2.path}\`${project2.missing ? " (missing)" : ""}`];
9328
+ if (project2.archived) out.push("", "Archived.");
9329
+ if (project2.description) out.push("", project2.description.trim());
9330
+ if (project2.milestones.length > 0) out.push("", `Milestones: ${project2.milestones.join(", ")}`);
9331
+ const board = items.board({ projectId: project2.id, includeDone: true });
9332
+ for (const column of board.columns) {
9333
+ out.push("", heading(level + 1, `${column.label} (${column.items.length})`));
9334
+ for (const summary of column.items) out.push("", itemMarkdown(items.get(summary.id), level + 2));
9022
9335
  }
9023
9336
  return out;
9024
9337
  }
9025
- function sourcesForItem(itemId) {
9026
- return commitSources(owner(itemId).project);
9027
- }
9028
- async function findCommit(sources, sha2) {
9029
- for (const source of sources) {
9030
- const found = await resolveCommit(source.path, sha2);
9031
- if (found) return { ...found, projectId: source.id, projectName: source.name, projectPath: source.path };
9032
- }
9033
- return null;
9034
- }
9035
- async function resolveForItem(ref) {
9036
- const itemId = itemRow(store, parse(idSchema, ref)).id;
9037
- return resolve(sourcesForItem(itemId), forItem(itemId));
9338
+ function project(projectId) {
9339
+ const detail = projects.get(parse(idSchema, projectId));
9340
+ const board = items.board({ projectId: detail.id, includeDone: true });
9341
+ return renderBoard({
9342
+ name: detail.name,
9343
+ description: detail.description,
9344
+ milestones: detail.milestones,
9345
+ columns: detail.statuses,
9346
+ items: new Map(board.columns.map((c) => [c.key, c.items.map((summary) => items.get(summary.id))]))
9347
+ });
9038
9348
  }
9039
- async function resolve(sources, list) {
9040
- return Promise.all(list.map(async (ref) => ref.type === "commit" ? { ...ref, commit: await findCommit(sources, ref.target) } : ref));
9349
+ function workspace(workspaceId) {
9350
+ const ws = workspaces.get(parse(idSchema, workspaceId));
9351
+ const out = [heading(1, ws.name), "", `Root: \`${ws.rootPath}\`${ws.missing ? " (missing)" : ""}`];
9352
+ for (const p of projects.list({ workspaceId: ws.id })) out.push("", ...projectBody(p, 2));
9353
+ return `${out.join("\n")}
9354
+ `;
9041
9355
  }
9042
- function read(refId, options = {}) {
9043
- const ref = toRef(refRow(store, parse(idSchema, refId)));
9044
- if (ref.type !== "file") throw invalid(`ref ${refId} is a ${ref.type} ref; only file refs can be read`);
9045
- const { project } = owner(ref.itemId);
9046
- const target = splitFileTarget(ref.target);
9047
- const abs = resolveInside(project.path, target.path);
9048
- if (!existsSync4(abs)) return { ref, path: abs, state: "missing" };
9049
- const stat = statSync(abs);
9050
- if (!stat.isFile()) throw invalid(`${target.path} is not a regular file`);
9051
- if (stat.size > MAX_REF_BYTES) {
9052
- throw new SlateError("too_large", `${target.path} is ${stat.size} bytes; the limit is ${MAX_REF_BYTES}`, {
9053
- size: stat.size,
9054
- limit: MAX_REF_BYTES
9055
- });
9056
- }
9057
- const buf = readFileSync2(abs);
9058
- if (looksBinary(buf)) return { ref, path: abs, state: "binary", size: buf.length };
9059
- const content = buf.toString("utf8");
9060
- if (!target.lines) return { ref, path: abs, state: "ok", size: buf.length, content };
9061
- const all = splitLines(content);
9062
- const lines = { ...target.lines, total: all.length };
9063
- if (options.full) return { ref, path: abs, state: "ok", size: buf.length, content, lines };
9064
- return { ref, path: abs, state: "ok", size: buf.length, content: all.slice(lines.start - 1, lines.end).join(""), lines };
9356
+ function item(itemId) {
9357
+ return `${itemMarkdown(items.get(itemId))}
9358
+ `;
9065
9359
  }
9066
- return { add, remove, read, forItem, resolveForItem, resolve, commitSources, sourcesForItem, findCommit };
9360
+ return { project, workspace, item };
9067
9361
  }
9068
9362
 
9069
9363
  // ../core/src/services/roadmap-file.ts
9364
+ import { createHash } from "node:crypto";
9365
+ import { existsSync as existsSync7, mkdirSync as mkdirSync2, readFileSync as readFileSync4, writeFileSync } from "node:fs";
9366
+ import path6 from "node:path";
9070
9367
  var DEFAULT_ROADMAP_FILE = "docs/ROADMAP.md";
9071
9368
  var sha = (text) => createHash("sha256").update(text).digest("hex");
9072
9369
  function createRoadmapFileService(ctx, exporter) {
@@ -9081,8 +9378,8 @@ function createRoadmapFileService(ctx, exporter) {
9081
9378
  const at = locate(projectId);
9082
9379
  if (!at) return { state: "off", file: null, path: null };
9083
9380
  const base = { file: at.file, path: at.abs };
9084
- if (!existsSync5(at.abs)) return { ...base, state: at.project.roadmap_hash ? "missing" : "stale" };
9085
- const content = readFileSync3(at.abs, "utf8");
9381
+ if (!existsSync7(at.abs)) return { ...base, state: at.project.roadmap_hash ? "missing" : "stale" };
9382
+ const content = readFileSync4(at.abs, "utf8");
9086
9383
  if (at.project.roadmap_hash && sha(content) !== at.project.roadmap_hash) {
9087
9384
  return { ...base, state: content === exporter.project(projectId) ? "current" : "edited" };
9088
9385
  }
@@ -9092,7 +9389,7 @@ function createRoadmapFileService(ctx, exporter) {
9092
9389
  const now = status(projectId);
9093
9390
  if (now.state !== "stale" && now.state !== "missing") return now;
9094
9391
  const md = exporter.project(projectId);
9095
- mkdirSync2(path5.dirname(now.path), { recursive: true });
9392
+ mkdirSync2(path6.dirname(now.path), { recursive: true });
9096
9393
  writeFileSync(now.path, md);
9097
9394
  db.prepare("UPDATE projects SET roadmap_hash = ? WHERE id = ?").run(sha(md), projectId);
9098
9395
  return { ...now, state: "current" };
@@ -9839,7 +10136,7 @@ function createItemService(ctx, refs, links) {
9839
10136
  return get(row.id);
9840
10137
  });
9841
10138
  }
9842
- return { list, board, get, getResolved, withCommits, commits, projectCommits, syncFromGit, create, createMany, restore, update, move, remove, next, claim, release };
10139
+ return { list, board, get, getResolved, withCommits, commits, relatedCommits, projectCommits, syncFromGit, create, createMany, restore, update, move, remove, next, claim, release };
9843
10140
  }
9844
10141
 
9845
10142
  // ../core/src/services/links.ts
@@ -9989,12 +10286,12 @@ function createOverviewService(ctx) {
9989
10286
  }
9990
10287
 
9991
10288
  // ../core/src/services/projects.ts
9992
- import { existsSync as existsSync6, lstatSync, readFileSync as readFileSync4 } from "node:fs";
9993
- import path7 from "node:path";
10289
+ import { existsSync as existsSync8, lstatSync, readFileSync as readFileSync5 } from "node:fs";
10290
+ import path8 from "node:path";
9994
10291
 
9995
10292
  // ../core/src/services/workspaces.ts
9996
- import { readdirSync as readdirSync2, statSync as statSync2 } from "node:fs";
9997
- import path6 from "node:path";
10293
+ import { readdirSync as readdirSync3, statSync as statSync3 } from "node:fs";
10294
+ import path7 from "node:path";
9998
10295
  var DEFAULT_STATUSES = [
9999
10296
  { key: "backlog", label: "Backlog", kind: "backlog", isDefault: true },
10000
10297
  { key: "planned", label: "Planned", kind: "backlog", isDefault: false },
@@ -10006,7 +10303,7 @@ var SCAN_DEPTH = 3;
10006
10303
  function requireDirectory(p) {
10007
10304
  let isDir2 = false;
10008
10305
  try {
10009
- isDir2 = statSync2(p).isDirectory();
10306
+ isDir2 = statSync3(p).isDirectory();
10010
10307
  } catch {
10011
10308
  throw invalid(`path does not exist: ${p}`, { path: p });
10012
10309
  }
@@ -10083,7 +10380,7 @@ function createWorkspaceService(ctx) {
10083
10380
  const walk2 = (dir, depth) => {
10084
10381
  let entries;
10085
10382
  try {
10086
- entries = readdirSync2(dir, { withFileTypes: true });
10383
+ entries = readdirSync3(dir, { withFileTypes: true });
10087
10384
  } catch {
10088
10385
  return;
10089
10386
  }
@@ -10091,11 +10388,11 @@ function createWorkspaceService(ctx) {
10091
10388
  if (depth >= SCAN_DEPTH) return;
10092
10389
  for (const e of entries) {
10093
10390
  if (!e.isDirectory() || e.name.startsWith(".") || e.name === "node_modules") continue;
10094
- walk2(path6.join(dir, e.name), depth + 1);
10391
+ walk2(path7.join(dir, e.name), depth + 1);
10095
10392
  }
10096
10393
  };
10097
10394
  walk2(ws.rootPath, 0);
10098
- return found.sort().map((p) => ({ path: p, name: path6.basename(p), registered: registered.has(p) }));
10395
+ return found.sort().map((p) => ({ path: p, name: path7.basename(p), registered: registered.has(p) }));
10099
10396
  }
10100
10397
  return { list, get, create, update, remove, scan };
10101
10398
  }
@@ -10103,7 +10400,7 @@ function createWorkspaceService(ctx) {
10103
10400
  // ../core/src/services/projects.ts
10104
10401
  function worktreeMainRepo(dir) {
10105
10402
  for (const candidate of ancestors(dir)) {
10106
- const gitPath = path7.join(candidate, ".git");
10403
+ const gitPath = path8.join(candidate, ".git");
10107
10404
  let stat;
10108
10405
  try {
10109
10406
  stat = lstatSync(gitPath);
@@ -10111,19 +10408,19 @@ function worktreeMainRepo(dir) {
10111
10408
  continue;
10112
10409
  }
10113
10410
  if (!stat.isFile()) return null;
10114
- const match = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync4(gitPath, "utf8"));
10411
+ const match = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync5(gitPath, "utf8"));
10115
10412
  if (!match?.[1]) return null;
10116
- const gitdir = path7.resolve(candidate, match[1]);
10413
+ const gitdir = path8.resolve(candidate, match[1]);
10117
10414
  let common = null;
10118
- const commondirFile = path7.join(gitdir, "commondir");
10119
- if (existsSync6(commondirFile)) {
10120
- common = path7.resolve(gitdir, readFileSync4(commondirFile, "utf8").trim());
10415
+ const commondirFile = path8.join(gitdir, "commondir");
10416
+ if (existsSync8(commondirFile)) {
10417
+ common = path8.resolve(gitdir, readFileSync5(commondirFile, "utf8").trim());
10121
10418
  } else {
10122
10419
  const m = /^(.*)[/\\]worktrees[/\\][^/\\]+[/\\]?$/.exec(gitdir);
10123
10420
  if (m?.[1]) common = m[1];
10124
10421
  }
10125
10422
  if (!common) return null;
10126
- return normalizePath(path7.basename(common) === ".git" ? path7.dirname(common) : common);
10423
+ return normalizePath(path8.basename(common) === ".git" ? path8.dirname(common) : common);
10127
10424
  }
10128
10425
  return null;
10129
10426
  }
@@ -10201,10 +10498,14 @@ function createProjectService(ctx) {
10201
10498
  params.push(parsed.key);
10202
10499
  }
10203
10500
  if (parsed.roadmapFile !== void 0 && parsed.roadmapFile !== row.roadmap_file) {
10204
- const file = parsed.roadmapFile === null ? null : path7.relative(row.path, resolveInside(row.path, parsed.roadmapFile));
10501
+ const file = parsed.roadmapFile === null ? null : path8.relative(row.path, resolveInside(row.path, parsed.roadmapFile));
10205
10502
  sets.push("roadmap_file = ?", "roadmap_hash = ?");
10206
10503
  params.push(file, null);
10207
10504
  }
10505
+ if (parsed.archAuto !== void 0 && parsed.archAuto !== (row.arch_auto === 1)) {
10506
+ sets.push("arch_auto = ?", "arch_head = NULL", "arch_at = NULL", "arch_state = NULL", "arch_error = NULL");
10507
+ params.push(parsed.archAuto ? 1 : 0);
10508
+ }
10208
10509
  if (parsed.gitTransitions !== void 0) {
10209
10510
  sets.push("git_transitions = ?");
10210
10511
  params.push(parsed.gitTransitions ? 1 : 0);
@@ -10442,8 +10743,8 @@ function createStatusService(ctx) {
10442
10743
  }
10443
10744
 
10444
10745
  // ../core/src/services/todos.ts
10445
- import { lstatSync as lstatSync2, readFileSync as readFileSync5, readdirSync as readdirSync3 } from "node:fs";
10446
- import path8 from "node:path";
10746
+ import { lstatSync as lstatSync2, readFileSync as readFileSync6, readdirSync as readdirSync4 } from "node:fs";
10747
+ import path9 from "node:path";
10447
10748
  var MAX_TODO_FILE_BYTES = 1024 * 1024;
10448
10749
  var MAX_TODO_FILES = 2e4;
10449
10750
  var MAX_TODOS = 1e3;
@@ -10481,7 +10782,7 @@ function createTodoService(ctx, items, statuses) {
10481
10782
  const visit = async (rel) => {
10482
10783
  let entries;
10483
10784
  try {
10484
- entries = readdirSync3(path8.join(root, rel), { withFileTypes: true });
10785
+ entries = readdirSync4(path9.join(root, rel), { withFileTypes: true });
10485
10786
  } catch {
10486
10787
  return true;
10487
10788
  }
@@ -10494,7 +10795,7 @@ function createTodoService(ctx, items, statuses) {
10494
10795
  continue;
10495
10796
  }
10496
10797
  if (!e.isFile() || await ignored(child, false)) continue;
10497
- const abs = path8.join(root, child);
10798
+ const abs = path9.join(root, child);
10498
10799
  try {
10499
10800
  if (lstatSync2(abs).size > MAX_TODO_FILE_BYTES) continue;
10500
10801
  } catch {
@@ -10502,7 +10803,7 @@ function createTodoService(ctx, items, statuses) {
10502
10803
  }
10503
10804
  let buf;
10504
10805
  try {
10505
- buf = readFileSync5(abs);
10806
+ buf = readFileSync6(abs);
10506
10807
  } catch {
10507
10808
  continue;
10508
10809
  }
@@ -10599,6 +10900,168 @@ function createTodoService(ctx, items, statuses) {
10599
10900
  return { scan };
10600
10901
  }
10601
10902
 
10903
+ // ../core/src/services/touch.ts
10904
+ import { readFileSync as readFileSync7, statSync as statSync4 } from "node:fs";
10905
+ import path10 from "node:path";
10906
+ var MAX_MODEL_BYTES2 = 8 * 1024 * 1024;
10907
+ var MAX_TOUCH_PATHS = 20;
10908
+ var OTHER = { id: "other", label: "Other", kind: "other" };
10909
+ function globToRegExp(glob) {
10910
+ let re = "";
10911
+ for (let i = 0; i < glob.length; i++) {
10912
+ const c = glob[i];
10913
+ if (c === "*" && glob[i + 1] === "*") {
10914
+ const slash = glob[i + 2] === "/";
10915
+ re += slash ? "(?:.*/)?" : ".*";
10916
+ i += slash ? 2 : 1;
10917
+ } else if (c === "*") re += "[^/]*";
10918
+ else if (c === "?") re += "[^/]";
10919
+ else re += c.replace(/[.+^${}()|[\]\\]/g, "\\$&");
10920
+ }
10921
+ return new RegExp(`^${re}$`);
10922
+ }
10923
+ var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
10924
+ function readJson(file) {
10925
+ try {
10926
+ const stat = statSync4(file);
10927
+ if (!stat.isFile() || stat.size > MAX_MODEL_BYTES2) return null;
10928
+ return JSON.parse(readFileSync7(file, "utf8"));
10929
+ } catch {
10930
+ return null;
10931
+ }
10932
+ }
10933
+ function componentsOf(doc) {
10934
+ if (!isObject(doc) || !Array.isArray(doc.components)) return [];
10935
+ const out = [];
10936
+ const seen = /* @__PURE__ */ new Set();
10937
+ for (const c of doc.components) {
10938
+ if (!isObject(c) || typeof c.id !== "string" || !c.id || c.id === OTHER.id || seen.has(c.id) || !Array.isArray(c.files)) continue;
10939
+ const globs = c.files.filter((g) => typeof g === "string" && g.length > 0).map(globToRegExp);
10940
+ if (globs.length === 0) continue;
10941
+ seen.add(c.id);
10942
+ out.push({ entry: { id: c.id, label: typeof c.label === "string" && c.label ? c.label : c.id, kind: "component" }, globs });
10943
+ }
10944
+ return out;
10945
+ }
10946
+ function packagesOf(doc) {
10947
+ if (!isObject(doc) || !Array.isArray(doc.nodes)) return [];
10948
+ const out = [];
10949
+ for (const n of doc.nodes) {
10950
+ if (!isObject(n) || n.kind !== "package" || typeof n.id !== "string") continue;
10951
+ const attrs = isObject(n.attrs) ? n.attrs : {};
10952
+ const dir = typeof attrs.dir === "string" ? attrs.dir : typeof n.file === "string" ? path10.posix.dirname(n.file) : null;
10953
+ if (dir === null) continue;
10954
+ const clean = dir === "." ? "" : dir.replace(/^\.\//, "").replace(/\/+$/, "");
10955
+ out.push({ entry: { id: n.id, label: typeof n.label === "string" && n.label ? n.label : n.id, kind: "package" }, dir: clean });
10956
+ }
10957
+ return out.sort((a, b) => b.dir.length - a.dir.length);
10958
+ }
10959
+ function classify(model, file) {
10960
+ for (const c of model.components) if (c.globs.some((g) => g.test(file))) return c.entry;
10961
+ for (const p of model.packages) if (p.dir === "" || file === p.dir || file.startsWith(`${p.dir}/`)) return p.entry;
10962
+ return OTHER;
10963
+ }
10964
+ var Tally = class {
10965
+ rows = /* @__PURE__ */ new Map();
10966
+ add(entry, file, sha2, itemIds) {
10967
+ const key = `${entry.kind}:${entry.id}`;
10968
+ let row = this.rows.get(key);
10969
+ if (!row) this.rows.set(key, row = { entry, files: /* @__PURE__ */ new Set(), commits: /* @__PURE__ */ new Set(), items: /* @__PURE__ */ new Set() });
10970
+ row.files.add(file);
10971
+ row.commits.add(sha2);
10972
+ for (const id of itemIds) row.items.add(id);
10973
+ }
10974
+ list() {
10975
+ return [...this.rows.values()].map((r) => ({ ...r.entry, files: r.files.size, commits: r.commits.size, items: r.items.size, paths: [...r.files].sort() }));
10976
+ }
10977
+ };
10978
+ var otherLast = (a, b) => Number(a.kind === "other") - Number(b.kind === "other");
10979
+ function createTouchService(ctx, items) {
10980
+ const { store } = ctx;
10981
+ const models = /* @__PURE__ */ new Map();
10982
+ function stampOf(file) {
10983
+ try {
10984
+ const s = statSync4(file);
10985
+ return `${s.mtimeMs}:${s.size}`;
10986
+ } catch {
10987
+ return "-";
10988
+ }
10989
+ }
10990
+ function modelOf(project) {
10991
+ const dir = path10.join(project.path, ARCHITECTURE_DIR);
10992
+ const componentsFile = path10.join(dir, "components.json");
10993
+ const factsFile = path10.join(dir, "facts.json");
10994
+ const stamp = `${stampOf(componentsFile)}|${stampOf(factsFile)}`;
10995
+ const known = models.get(project.id);
10996
+ if (known && known.stamp === stamp) return known.model;
10997
+ const components = componentsOf(readJson(componentsFile));
10998
+ const packages = packagesOf(readJson(factsFile));
10999
+ const model = components.length || packages.length ? { kind: components.length ? "components" : "packages", components, packages } : null;
11000
+ models.set(project.id, { stamp, model });
11001
+ return model;
11002
+ }
11003
+ async function filesOf(project, commits) {
11004
+ const own = commits.filter((c) => c.projectId === project.id);
11005
+ const diffs2 = await changedFiles(project.path, own.map((c) => c.sha));
11006
+ const root = workTreeOf(project.path);
11007
+ const prefix = root ? path10.relative(root, project.path).split(path10.sep).join("/") : "";
11008
+ const out = /* @__PURE__ */ new Map();
11009
+ for (const [sha2, diff] of diffs2) {
11010
+ const files = diff.files.map((f) => {
11011
+ if (!prefix) return { file: f, inside: true };
11012
+ return f.startsWith(`${prefix}/`) ? { file: f.slice(prefix.length + 1), inside: true } : { file: path10.posix.relative(prefix, f), inside: false };
11013
+ });
11014
+ out.set(sha2, { files, truncated: diff.truncated });
11015
+ }
11016
+ return { own, out };
11017
+ }
11018
+ async function forItem(id) {
11019
+ const row = itemRow(store, parse(idSchema, id));
11020
+ const project = projectRow(store, row.project_id);
11021
+ const model = modelOf(project);
11022
+ const commits = await items.commits(row.id);
11023
+ const { own, out } = await filesOf(project, commits);
11024
+ const tally = new Tally();
11025
+ let truncated = false;
11026
+ if (model) {
11027
+ for (const c of own) {
11028
+ const diff = out.get(c.sha);
11029
+ if (!diff) continue;
11030
+ truncated ||= diff.truncated;
11031
+ for (const f of diff.files) tally.add(f.inside ? classify(model, f.file) : OTHER, f.file, c.sha, [row.id]);
11032
+ }
11033
+ }
11034
+ const components = tally.list().map(({ items: _, paths, ...c }) => ({ ...c, paths: paths.slice(0, MAX_TOUCH_PATHS) })).sort((a, b) => otherLast(a, b) || b.files - a.files || b.commits - a.commits || a.label.localeCompare(b.label));
11035
+ return { itemId: row.id, model: model?.kind ?? null, commits: own.length, components, truncated };
11036
+ }
11037
+ async function forMilestone(projectId, milestone) {
11038
+ const project = projectRow(store, parse(idSchema, projectId));
11039
+ const wanted = milestone === void 0 || milestone === null ? milestone : parse(milestoneSchema, milestone);
11040
+ const all = wanted === void 0;
11041
+ const model = modelOf(project);
11042
+ const scope = new Set(
11043
+ store.db.prepare("SELECT id, milestone FROM items WHERE project_id = ?").all(project.id).filter((r) => all || r.milestone === wanted).map((r) => r.id)
11044
+ );
11045
+ const related = (await items.relatedCommits(project)).map((c) => ({ ...c, itemIds: c.itemIds.filter((id) => scope.has(id)) })).filter((c) => c.itemIds.length > 0);
11046
+ const { own, out } = await filesOf(project, related);
11047
+ const tally = new Tally();
11048
+ const touchedItems = /* @__PURE__ */ new Set();
11049
+ let truncated = false;
11050
+ for (const c of own) for (const id of c.itemIds) touchedItems.add(id);
11051
+ if (model) {
11052
+ for (const c of own) {
11053
+ const diff = out.get(c.sha);
11054
+ if (!diff) continue;
11055
+ truncated ||= diff.truncated;
11056
+ for (const f of diff.files) tally.add(f.inside ? classify(model, f.file) : OTHER, f.file, c.sha, c.itemIds);
11057
+ }
11058
+ }
11059
+ const components = tally.list().map(({ paths: _, ...c }) => c).sort((a, b) => otherLast(a, b) || b.items - a.items || b.files - a.files || a.label.localeCompare(b.label));
11060
+ return { projectId: project.id, milestone: all ? null : wanted, all, model: model?.kind ?? null, items: touchedItems.size, commits: own.length, components, truncated };
11061
+ }
11062
+ return { forItem, forMilestone };
11063
+ }
11064
+
10602
11065
  // ../core/src/services/index.ts
10603
11066
  function createServices(store, options = {}) {
10604
11067
  const ctx = createCtx(store, options);
@@ -10615,7 +11078,10 @@ function createServices(store, options = {}) {
10615
11078
  const overview = createOverviewService(ctx);
10616
11079
  const todos = createTodoService(ctx, items, statuses);
10617
11080
  const roadmapFile = createRoadmapFileService(ctx, exporter);
10618
- return { store, events, workspaces, projects, statuses, items, refs, links, export: exporter, import: importer, overview, todos, roadmapFile };
11081
+ const architecture = createArchitectureService(ctx, events);
11082
+ const touch = createTouchService(ctx, items);
11083
+ const archAuto = createArchAutoService(ctx);
11084
+ return { store, events, workspaces, projects, statuses, items, refs, links, export: exporter, import: importer, overview, todos, roadmapFile, architecture, archAuto, touch };
10619
11085
  }
10620
11086
 
10621
11087
  export {
@@ -10680,21 +11146,26 @@ export {
10680
11146
  resolveItemId,
10681
11147
  loadMigrations,
10682
11148
  Store,
10683
- BOARD_FORMAT_VERSION,
10684
- renderBoard,
10685
- parseBoard,
10686
- itemMarkdown,
10687
11149
  GIT_CACHE_TTL_MS,
10688
11150
  DEFAULT_COMMIT_SCAN,
10689
11151
  clearGitCache,
10690
11152
  currentBranch,
10691
11153
  keyFromBranch,
11154
+ headCommit,
10692
11155
  resolveCommit,
10693
11156
  findCommitsMentioning,
11157
+ MAX_CHANGED_FILES,
11158
+ changedFiles,
10694
11159
  MAX_REF_BYTES,
10695
11160
  MAX_WORKSPACE_REPOS,
10696
11161
  splitFileTarget,
10697
11162
  lineSuffix,
11163
+ ARCHITECTURE_DIR,
11164
+ MAX_ARCHITECTURE_VIEWS,
11165
+ BOARD_FORMAT_VERSION,
11166
+ renderBoard,
11167
+ parseBoard,
11168
+ itemMarkdown,
10698
11169
  DEFAULT_ROADMAP_FILE,
10699
11170
  DEFAULT_STATUSES,
10700
11171
  worktreeMainRepo,
@@ -10702,5 +11173,6 @@ export {
10702
11173
  MAX_TODO_FILES,
10703
11174
  MAX_TODOS,
10704
11175
  findTodos,
11176
+ MAX_TOUCH_PATHS,
10705
11177
  createServices
10706
11178
  };