bitboss-ui 3.0.0-beta.73 → 3.0.0-beta.74

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 (179) hide show
  1. package/README.md +4 -2
  2. package/bin/bitboss-ui-mcp.mjs +101 -3
  3. package/bin/bitboss-ui.mjs +6 -1
  4. package/bin/cli.mjs +31 -5
  5. package/dist/ai/BbBadge.md +4 -4
  6. package/dist/ai/BbCalendar.md +4 -3
  7. package/dist/ai/BbColorPalette.md +8 -9
  8. package/dist/ai/BbConfirmPortal.md +1 -1
  9. package/dist/ai/BbDatePicker.md +4 -3
  10. package/dist/ai/BbDialog.md +14 -4
  11. package/dist/ai/BbDropdown.md +23 -10
  12. package/dist/ai/BbDropdownButton.md +2 -2
  13. package/dist/ai/BbForm.md +4 -1
  14. package/dist/ai/BbHoverCardPortal.md +1 -1
  15. package/dist/ai/BbNumberInput.md +5 -3
  16. package/dist/ai/BbPopoverPortal.md +1 -1
  17. package/dist/ai/BbTable.md +43 -19
  18. package/dist/ai/BbTimePicker.md +4 -3
  19. package/dist/ai/BbToastPortal.md +1 -1
  20. package/dist/ai/changelog.json +56 -4
  21. package/dist/ai/components.json +54 -18
  22. package/dist/ai/guides/design-tokens.md +20 -0
  23. package/dist/ai/guides/eslint-rules.md +1 -1
  24. package/dist/ai/guides/inertia-helpers.md +613 -53
  25. package/dist/ai/guides/migration/adoption-checklist.md +5 -5
  26. package/dist/ai/guides/migration/v2-to-v3.md +24 -0
  27. package/dist/ai/guides/migration/v3-beta-tooling.md +3 -0
  28. package/dist/ai/guides/preset-components.md +15 -2
  29. package/dist/ai/guides/reporting.md +49 -0
  30. package/dist/ai/helpers/inertia/manifest.json +33 -38
  31. package/dist/ai/helpers/inertia/useHasChanged.ts +25 -37
  32. package/dist/ai/helpers/inertia/useQuery.ts +24 -6
  33. package/dist/ai/helpers/inertia/utils.ts +552 -3
  34. package/dist/ai/index.md +1 -0
  35. package/dist/ai/manifest/components/BbAlert.tree.json +1 -1
  36. package/dist/ai/manifest/components/BbCalendar.json +2 -2
  37. package/dist/ai/manifest/components/BbColorPalette.json +3 -3
  38. package/dist/ai/manifest/components/BbConfirmPortal.json +1 -1
  39. package/dist/ai/manifest/components/BbDatePicker.json +3 -3
  40. package/dist/ai/manifest/components/BbDialog.tree.json +5 -1
  41. package/dist/ai/manifest/components/BbDropdown.json +3 -3
  42. package/dist/ai/manifest/components/BbDropdown.tree.json +3 -2
  43. package/dist/ai/manifest/components/BbDropdownButton.json +2 -2
  44. package/dist/ai/manifest/components/BbForm.json +1 -1
  45. package/dist/ai/manifest/components/BbHoverCard.json +1 -1
  46. package/dist/ai/manifest/components/BbHoverCardPortal.json +1 -1
  47. package/dist/ai/manifest/components/BbNumberInput.json +1 -1
  48. package/dist/ai/manifest/components/BbPopover.json +1 -1
  49. package/dist/ai/manifest/components/BbPopoverPortal.json +1 -1
  50. package/dist/ai/manifest/components/BbSelectPopover.json +1 -1
  51. package/dist/ai/manifest/components/BbTable.tree.json +12 -6
  52. package/dist/ai/manifest/components/BbTimePicker.json +3 -3
  53. package/dist/ai/manifest/components/BbToastPortal.json +1 -1
  54. package/dist/ai/manifest/components/CommonPopover.json +1 -1
  55. package/dist/ai/manifest/index.json +2 -2
  56. package/dist/ai/manifest/meta.json +36 -0
  57. package/dist/ai/manifest/types.advanced.json +81 -80
  58. package/dist/ai/manifest/types.api.json +66 -65
  59. package/dist/ai/manifest/types.wrapper.json +155 -118
  60. package/dist/ai/recipes/inertia/layout-scaffold.md +3 -1
  61. package/dist/ai/recipes/nuxt/layout-scaffold.md +3 -1
  62. package/dist/ai/recipes/vue/layout-scaffold.md +3 -1
  63. package/dist/ai/source/BbAlert.md +16 -4
  64. package/dist/ai/source/BbAvatar.md +2 -0
  65. package/dist/ai/source/BbBreadcrumbs.md +4 -1
  66. package/dist/ai/source/BbCalendar.md +22 -12
  67. package/dist/ai/source/BbColorPalette.md +41 -12
  68. package/dist/ai/source/BbConfirm.md +7 -0
  69. package/dist/ai/source/BbConfirmPortal.md +9 -4
  70. package/dist/ai/source/BbDatePicker.md +53 -22
  71. package/dist/ai/source/BbDatePickerInput.md +32 -8
  72. package/dist/ai/source/BbDialog.md +31 -1
  73. package/dist/ai/source/BbDropdown.md +52 -24
  74. package/dist/ai/source/BbDropdownGroup.md +17 -21
  75. package/dist/ai/source/BbForm.md +73 -6
  76. package/dist/ai/source/BbHoverCard.md +7 -0
  77. package/dist/ai/source/BbHoverCardPortal.md +9 -5
  78. package/dist/ai/source/BbNumberInput.md +5 -6
  79. package/dist/ai/source/BbOffCanvas.md +34 -1
  80. package/dist/ai/source/BbPopover.md +7 -0
  81. package/dist/ai/source/BbPopoverPortal.md +9 -5
  82. package/dist/ai/source/BbRadio.md +4 -3
  83. package/dist/ai/source/BbRadioGroup.md +7 -5
  84. package/dist/ai/source/BbTable.md +54 -6
  85. package/dist/ai/source/BbTag.md +10 -3
  86. package/dist/ai/source/BbTimePicker.md +50 -15
  87. package/dist/ai/source/BbTimePickerInput.md +30 -7
  88. package/dist/ai/source/BbToast.md +14 -0
  89. package/dist/ai/source/BbToastPortal.md +16 -4
  90. package/dist/ai/source/CommonFieldInput.md +11 -5
  91. package/dist/ai/source/CommonPopover.md +4 -1
  92. package/dist/components/BbAlert/BbAlert.vue_vue_type_script_setup_true_lang.js +31 -26
  93. package/dist/components/BbBreadcrumbs/BbBreadcrumbs.vue_vue_type_script_setup_true_lang.js +1 -1
  94. package/dist/components/BbCalendar/BbCalendar.vue.d.ts +1 -1
  95. package/dist/components/BbCalendar/BbCalendar.vue_vue_type_script_setup_true_lang.js +235 -234
  96. package/dist/components/BbCalendar/types.d.ts +2 -2
  97. package/dist/components/BbCalendar/useDayjsLocale.js +11 -8
  98. package/dist/components/BbColorPalette/BbColorPalette.vue_vue_type_script_setup_true_lang.js +197 -192
  99. package/dist/components/BbColorPalette/types.d.ts +1 -1
  100. package/dist/components/BbConfirm/BbConfirmPortal.vue.d.ts +2 -4
  101. package/dist/components/BbConfirm/types.d.ts +5 -0
  102. package/dist/components/BbDatePicker/BbDatePicker.vue.d.ts +1 -1
  103. package/dist/components/BbDatePicker/BbDatePicker.vue_vue_type_script_setup_true_lang.js +145 -139
  104. package/dist/components/BbDatePicker/types.d.ts +2 -2
  105. package/dist/components/BbDatePickerInput/BbDatePickerInput.vue_vue_type_script_setup_true_lang.js +337 -335
  106. package/dist/components/BbDialog/BbDialog.vue_vue_type_script_setup_true_lang.js +253 -245
  107. package/dist/components/BbDialog/leaveGhost.js +33 -0
  108. package/dist/components/BbDialog/overlayActions.js +34 -20
  109. package/dist/components/BbDropdown/BbDropdown.vue_vue_type_script_setup_true_lang.js +11 -3
  110. package/dist/components/BbDropdown/BbDropdownList.vue_vue_type_script_setup_true_lang.js +4 -4
  111. package/dist/components/BbDropdown/DropdownPipelineResolver.vue_vue_type_script_setup_true_lang.js +119 -120
  112. package/dist/components/BbDropdown/types.d.ts +8 -17
  113. package/dist/components/BbForm/BbForm.vue.d.ts +2 -21
  114. package/dist/components/BbForm/BbForm.vue_vue_type_script_setup_true_lang.js +229 -227
  115. package/dist/components/BbForm/types.d.ts +31 -0
  116. package/dist/components/BbHoverCard/BbHoverCardPortal.vue.d.ts +2 -5
  117. package/dist/components/BbHoverCard/types.d.ts +5 -0
  118. package/dist/components/BbNumberInput/BbNumberInput.vue_vue_type_script_setup_true_lang.js +1 -1
  119. package/dist/components/BbNumberInput/numberDisplay.js +102 -106
  120. package/dist/components/BbNumberInput/types.d.ts +4 -3
  121. package/dist/components/BbOffCanvas/BbOffCanvas.vue_vue_type_script_setup_true_lang.js +385 -377
  122. package/dist/components/BbPopover/BbPopoverPortal.vue.d.ts +2 -5
  123. package/dist/components/BbPopover/types.d.ts +5 -0
  124. package/dist/components/BbRadio/types.d.ts +4 -3
  125. package/dist/components/BbRadioGroup/BbRadioGroup.vue_vue_type_script_setup_true_lang.js +10 -12
  126. package/dist/components/BbTable/BbTable.vue_vue_type_script_setup_true_lang.js +231 -231
  127. package/dist/components/BbTable/BbTableDataRow.js +96 -96
  128. package/dist/components/BbTag/BbTag.vue_vue_type_script_setup_true_lang.js +9 -3
  129. package/dist/components/BbTimePicker/BbTimePicker.vue.d.ts +1 -1
  130. package/dist/components/BbTimePicker/BbTimePicker.vue_vue_type_script_setup_true_lang.js +106 -100
  131. package/dist/components/BbTimePicker/types.d.ts +2 -2
  132. package/dist/components/BbTimePickerInput/BbTimePickerInput.vue_vue_type_script_setup_true_lang.js +214 -213
  133. package/dist/components/BbToast/BbToastPortal.vue.d.ts +2 -4
  134. package/dist/components/BbToast/types.d.ts +5 -0
  135. package/dist/components/CommonFieldInput/CommonFieldInput.vue_vue_type_script_setup_true_lang.js +36 -36
  136. package/dist/components/CommonPopover/CommonPopover.vue_vue_type_script_setup_true_lang.js +1 -1
  137. package/dist/components/CommonTimeSelector/useMeridiem.js +6 -6
  138. package/dist/composables/formSubmitLock.js +2 -1
  139. package/dist/composables/overlayRegistry.js +52 -42
  140. package/dist/composables/useActiveInactiveState.js +8 -4
  141. package/dist/composables/useBbDialog.js +5 -5
  142. package/dist/composables/useOwnModel.js +16 -0
  143. package/dist/composables/useSegmentedFields.js +31 -20
  144. package/dist/i18n/currencyDigits.js +58 -0
  145. package/dist/i18n/regionDates.js +250 -0
  146. package/dist/i18n/regionHints.js +30 -41
  147. package/dist/index.d.ts +34 -30
  148. package/dist/llms-full.txt +860 -129
  149. package/dist/llms.txt +3 -1
  150. package/dist/styles.css +2 -2
  151. package/dist/types/ActionButton.d.ts +3 -1
  152. package/dist/types/CommonProps.d.ts +8 -0
  153. package/dist/utilities/functions/hash.js +97 -64
  154. package/dist/utilities/functions/isEqual.js +33 -25
  155. package/dist/utils/versionCheck.js +1 -1
  156. package/dist/vite-plugin.d.ts +2 -1
  157. package/dist/vite.js +8 -4
  158. package/llms.txt +3 -1
  159. package/package.json +1 -2
  160. package/scripts/README.md +1 -1
  161. package/scripts/lib/adoption-checklist.json +6 -5
  162. package/scripts/lib/agent-manifest.mjs +33 -6
  163. package/scripts/lib/agent-setup.mjs +54 -6
  164. package/scripts/lib/cldr-pins.ts +182 -0
  165. package/scripts/lib/engines-include.d.mts +5 -0
  166. package/scripts/lib/engines-include.mjs +40 -0
  167. package/scripts/lib/eslint-plugin.mjs +8 -2
  168. package/scripts/lib/hidden-label-placeholder.mjs +25 -5
  169. package/scripts/lib/idiom-scan.mjs +30 -3
  170. package/scripts/lib/legacy-agent-files.json +152 -0
  171. package/scripts/lib/mcp-config.mjs +74 -7
  172. package/scripts/lib/portal-names.mjs +78 -8
  173. package/scripts/lib/release-results.mjs +5 -2
  174. package/scripts/lib/report.mjs +340 -0
  175. package/scripts/lib/run-beat.mjs +14 -0
  176. package/scripts/lib/run-records.mjs +313 -0
  177. package/scripts/lib/selector-log.mjs +98 -0
  178. package/scripts/lib/ticket-beat.mjs +30 -0
  179. package/scripts/lib/validate-bb-markup.mjs +17 -2
@@ -106,9 +106,70 @@ export const stdioEntry = (root) => {
106
106
  };
107
107
  export const vscodeEntry = (root) => ({ type: 'stdio', ...stdioEntry(root) });
108
108
 
109
- function writeJson(path, data) {
109
+ /*
110
+ * JSON the way Prettier (and oxfmt, Biome) print it, so a
111
+ * file we write passes the app's `format --check` untouched: objects
112
+ * expanded, an array of scalars on one line when it fits in 80 columns
113
+ * (`"args": ["bitboss-ui", "mcp"]`), the indent unit the app uses.
114
+ */
115
+ const PRINT_WIDTH = 80;
116
+ const columns = (text) => text.replace(/\t/g, ' ').length;
117
+
118
+ /**
119
+ * @param {unknown} value
120
+ * @param {string} unit one indent step (`'\t'`, `' '`, `' '`)
121
+ * @param {string} [indent] the indent of the line the value starts on
122
+ * @param {number} [column] where on that line the value starts
123
+ * @param {string} [eol]
124
+ */
125
+ export function formatJson(value, unit, indent = '', column = 0, eol = '\n') {
126
+ if (Array.isArray(value)) {
127
+ if (value.length === 0) return '[]';
128
+ if (value.every((v) => v === null || typeof v !== 'object')) {
129
+ const flat = `[${value.map((v) => JSON.stringify(v ?? null)).join(', ')}]`;
130
+ // + 1: the comma after it.
131
+ if (column + flat.length + 1 <= PRINT_WIDTH) return flat;
132
+ }
133
+ const inner = indent + unit;
134
+ return `[${eol}${value
135
+ .map(
136
+ (v) =>
137
+ `${inner}${formatJson(v ?? null, unit, inner, columns(inner), eol)}`
138
+ )
139
+ .join(`,${eol}`)}${eol}${indent}]`;
140
+ }
141
+ if (value && typeof value === 'object') {
142
+ const entries = Object.entries(value).filter(
143
+ ([, v]) => v !== undefined && typeof v !== 'function'
144
+ );
145
+ if (entries.length === 0) return '{}';
146
+ const inner = indent + unit;
147
+ return `{${eol}${entries
148
+ .map(([key, v]) => {
149
+ const head = `${inner}${JSON.stringify(key)}: `;
150
+ return head + formatJson(v, unit, inner, columns(head), eol);
151
+ })
152
+ .join(`,${eol}`)}${eol}${indent}}`;
153
+ }
154
+ return JSON.stringify(value);
155
+ }
156
+
157
+ /** The app's indent step, read off its package.json; two spaces by default. */
158
+ export function projectIndent(root) {
159
+ try {
160
+ return (
161
+ readFileSync(join(root, 'package.json'), 'utf-8').match(
162
+ /^([ \t]+)\S/m
163
+ )?.[1] ?? ' '
164
+ );
165
+ } catch {
166
+ return ' ';
167
+ }
168
+ }
169
+
170
+ function writeJson(path, data, unit) {
110
171
  mkdirSync(dirname(path), { recursive: true });
111
- writeFileAtomicSync(path, `${JSON.stringify(data, null, '\t')}\n`, 'utf-8');
172
+ writeFileAtomicSync(path, `${formatJson(data, unit)}\n`, 'utf-8');
112
173
  }
113
174
 
114
175
  /**
@@ -210,11 +271,17 @@ function spliceEntry(raw, containerKey, entry) {
210
271
  const eol = raw.includes('\r\n') ? '\r\n' : '\n';
211
272
  const indentAt = (offset) =>
212
273
  raw.slice(raw.lastIndexOf('\n', offset) + 1).match(/^[ \t]*/)[0];
213
- const format = (value, indent) =>
214
- JSON.stringify(value, null, unit).replace(/\n/g, `${eol}${indent}`);
274
+ const lineBefore = (offset) =>
275
+ raw.slice(raw.lastIndexOf('\n', offset - 1) + 1, offset);
276
+ const format = (value, indent, column) =>
277
+ formatJson(value, unit, indent, column, eol);
215
278
  const replace = (member, value) =>
216
279
  raw.slice(0, member.valueStart) +
217
- format(value, indentAt(member.valueStart)) +
280
+ format(
281
+ value,
282
+ indentAt(member.valueStart),
283
+ columns(lineBefore(member.valueStart))
284
+ ) +
218
285
  raw.slice(member.valueEnd);
219
286
  // A new first member, right after the object's `{` — unless the rest of
220
287
  // that line is only a comment (`{ // header`), in which case after the
@@ -265,7 +332,7 @@ function spliceEntry(raw, containerKey, entry) {
265
332
  }
266
333
  return (
267
334
  raw.slice(0, at) +
268
- `${eol}${indent}${JSON.stringify(key)}: ${format(value, indent)}${tail}` +
335
+ `${eol}${indent}${JSON.stringify(key)}: ${format(value, indent, columns(`${indent}${JSON.stringify(key)}: `))}${tail}` +
269
336
  raw.slice(at)
270
337
  );
271
338
  };
@@ -374,7 +441,7 @@ export function ensureEntry(path, containerKey, entry, label, root) {
374
441
  config[containerKey][MCP_SERVER_NAME] = entry;
375
442
  try {
376
443
  if (raw === null) {
377
- writeJson(path, config);
444
+ writeJson(path, config, projectIndent(root ?? dirname(path)));
378
445
  } else {
379
446
  const next = spliceEntry(raw, containerKey, entry);
380
447
  // The splice must read back as exactly the merged config, or the
@@ -17,7 +17,8 @@
17
17
  * Dialog ids ride the same scan as two more families: `v-bb-dialog`
18
18
  * / `v-bb-off-canvas` with `"'id'"` or `{ id: 'id' }`, and
19
19
  * `useBbDialog('id')` / `useBbOffCanvas('id')` in a script,
20
- * against `<BbDialog | BbOffCanvas id="x">`. One finding, `unknown-dialog`
20
+ * against `<BbDialog | BbOffCanvas id="x">`, or the same on a
21
+ * `definePreset(BbDialog, …)` wrapper. One finding, `unknown-dialog`
21
22
  * (error): the id is declared nowhere, or by the other family. Never an
22
23
  * unused one: a dialog driven by its `v-model` legitimately has an id
23
24
  * nothing opens. A `:id` with a static head (`` `row-${n}` ``, `'row-' + n`)
@@ -91,6 +92,53 @@ export const PORTAL_FAMILIES = {
91
92
  const FAMILY_BY_COMPONENT = new Map(
92
93
  Object.entries(PORTAL_FAMILIES).map(([family, f]) => [f.component, family])
93
94
  );
95
+
96
+ /**
97
+ * the `definePreset(BbDialog, …)` wrappers a file defines,
98
+ * as tag → base, for the families this scan judges: a named `const X =
99
+ * definePreset(Bb…)`, and an anonymous `export default definePreset(Bb…)`,
100
+ * whose tag is the file's name (`AppSeparatedDialog.ts`), as an import or an
101
+ * auto-import names it.
102
+ * @param {string} code
103
+ * @param {string} path
104
+ */
105
+ export function familyPresets(code, path) {
106
+ const out = new Map();
107
+ if (!code.includes('definePreset')) return out;
108
+ const keep = (tag, base) => {
109
+ if (FAMILY_BY_COMPONENT.has(base)) out.set(tag, base);
110
+ };
111
+ for (const [, tag, base] of code.matchAll(
112
+ /\b(?:const|let|var)\s+([A-Z][\w$]*)\s*(?::[^=]+)?=\s*definePreset\s*(?:<[^>()]*>)?\s*\(\s*(Bb[A-Za-z]+)\b/g
113
+ ))
114
+ keep(tag, base);
115
+ const anonymous =
116
+ /\bexport\s+default\s+definePreset\s*(?:<[^>()]*>)?\s*\(\s*(Bb[A-Za-z]+)\b/.exec(
117
+ code
118
+ );
119
+ if (anonymous) {
120
+ const file = /([^/\\]+?)(?:\.[cm]?[jt]sx?|\.vue)$/.exec(path)?.[1];
121
+ if (file) keep(pascal(file), anonymous[1]);
122
+ }
123
+ return out;
124
+ }
125
+
126
+ /**
127
+ * The preset tags a `.vue` file can use: the project's, plus a default
128
+ * import renamed on the way in (`import Edit from './AppSeparatedDialog'`).
129
+ */
130
+ const presetsIn = (scripts, presets) => {
131
+ if (!presets?.size) return presets;
132
+ const out = new Map(presets);
133
+ for (const [, local, from] of scripts.matchAll(
134
+ /\bimport\s+([A-Z][\w$]*)\s+from\s+['"]([^'"]+)['"]/g
135
+ )) {
136
+ const file = /([^/\\]+?)(?:\.[cm]?[jt]sx?|\.vue)?$/.exec(from)?.[1];
137
+ const base = file && presets.get(pascal(file));
138
+ if (base) out.set(local, base);
139
+ }
140
+ return out;
141
+ };
94
142
  const FAMILY_BY_DIRECTIVE = new Map(
95
143
  Object.entries(PORTAL_FAMILIES)
96
144
  .filter(([, f]) => f.directive)
@@ -365,8 +413,9 @@ const declarationName = (node, attr = 'name', optional = false) => {
365
413
  * The portal sites of one file.
366
414
  * @param {string} code
367
415
  * @param {string} [path] decides `.vue` vs a script file
416
+ * @param {Map<string, string>} [presets] preset tag → base
368
417
  */
369
- export function fileSites(code, path = 'x.vue') {
418
+ export function fileSites(code, path = 'x.vue', presets = new Map()) {
370
419
  const sites = {
371
420
  declarations: [],
372
421
  calls: [],
@@ -388,11 +437,19 @@ export function fileSites(code, path = 'x.vue') {
388
437
  }
389
438
  for (const block of [descriptor.script, descriptor.scriptSetup])
390
439
  if (block) scriptSites(block.content, block.loc.start.line, code, sites);
440
+ const tags = presetsIn(
441
+ [descriptor.script, descriptor.scriptSetup]
442
+ .map((block) => block?.content ?? '')
443
+ .join('\n'),
444
+ new Map([...presets, ...familyPresets(code, path)])
445
+ );
391
446
 
392
447
  const walkTemplate = (node) => {
393
448
  if (!node || typeof node !== 'object') return;
394
449
  if (node.type === NODE_ELEMENT) {
395
- const family = FAMILY_BY_COMPONENT.get(pascal(node.tag));
450
+ const tag = pascal(node.tag);
451
+ const family =
452
+ FAMILY_BY_COMPONENT.get(tag) ?? FAMILY_BY_COMPONENT.get(tags.get(tag));
396
453
  if (family) {
397
454
  const f = PORTAL_FAMILIES[family];
398
455
  const declared = declarationName(node, f.attr, !!f.ids);
@@ -452,22 +509,28 @@ const cache = new Map();
452
509
  export function projectPortalIndex(projectRoot) {
453
510
  if (cache.has(projectRoot)) return cache.get(projectRoot);
454
511
  const index = emptyIndex();
512
+ const sources = [];
455
513
  for (const path of walk(projectRoot)) {
456
514
  if (path.endsWith('.d.ts') || !SOURCE.test(path)) continue;
457
- let code;
458
515
  try {
459
- code = readFileSync(path, 'utf-8');
516
+ sources.push([path, readFileSync(path, 'utf-8')]);
460
517
  } catch {
461
518
  continue;
462
519
  }
463
- if (!MAY_HAVE_PORTALS.test(code)) {
520
+ }
521
+ // a `definePreset(BbDialog, …)` tag declares ids too.
522
+ for (const [path, code] of sources)
523
+ for (const [tag, base] of familyPresets(code, path))
524
+ index.presets.set(tag, base);
525
+ for (const [path, code] of sources) {
526
+ if (!MAY_HAVE_PORTALS.test(code) && !hasPresetTag(code, index.presets)) {
464
527
  // Still a source of string literals for `unused-portal`.
465
528
  literalsIn(code, index.literals);
466
529
  for (const [, value] of code.matchAll(/`([^`$\\\n]{1,120})`/g))
467
530
  index.literals.add(value);
468
531
  continue;
469
532
  }
470
- addSites(index, fileSites(code, path), path);
533
+ addSites(index, fileSites(code, path, index.presets), path);
471
534
  }
472
535
  for (const name of configuredExternalDialogIds(projectRoot))
473
536
  for (const family of Object.keys(PORTAL_FAMILIES))
@@ -519,9 +582,16 @@ function emptyIndex() {
519
582
  literals: new Set(),
520
583
  /** family → id prefixes a template-literal `:id` covers */
521
584
  prefixes: new Map(),
585
+ /** preset tag → its Bb* base */
586
+ presets: new Map(),
522
587
  };
523
588
  }
524
589
 
590
+ const hasPresetTag = (code, presets) => {
591
+ for (const tag of presets.keys()) if (code.includes(tag)) return true;
592
+ return false;
593
+ };
594
+
525
595
  function addSites(index, sites, path) {
526
596
  for (const { family, name } of sites.declarations) {
527
597
  const byName = index.declared.get(family);
@@ -561,7 +631,7 @@ const declaration = (family, name) =>
561
631
  * @param {ReturnType<typeof projectPortalIndex> | null} index
562
632
  */
563
633
  export function portalFindings(code, path, index) {
564
- const sites = fileSites(code, path);
634
+ const sites = fileSites(code, path, index?.presets);
565
635
  if (!sites.calls.length && !sites.declarations.length) return [];
566
636
  const merged = emptyIndex();
567
637
  if (index) {
@@ -310,17 +310,20 @@ function mergeStep(next) {
310
310
  * (release:check --plan says so and passes), so they cannot stay owed.
311
311
  * `base` keeps the full run the reruns started from, and `warn` is
312
312
  * re-derived from the merged steps, not the rerun's alone.
313
+ * A step kept from `previous` is marked `kept: true`: the rerun did not run
314
+ * it, so `gate --stats` (wall-stats.mjs) does not count its seconds again.
313
315
  */
314
316
  export function mergeRerun(previous, rerun) {
315
317
  const byName = new Map(rerun.steps.map((s) => [s.name, s]));
318
+ const kept = (s) => ({ ...s, kept: true });
316
319
  const steps = previous.steps.map((prev) => {
317
320
  const next = byName.get(prev.name);
318
- if (!next) return prev;
321
+ if (!next) return kept(prev);
319
322
  if (WALL_RECORD_STEPS.has(prev.name) && next.sub?.length && prev.sub) {
320
323
  const subNext = new Map(next.sub.map((s) => [s.name, s]));
321
324
  const known = new Set(prev.sub.map((p) => p.name));
322
325
  const sub = prev.sub.map((p) =>
323
- subNext.has(p.name) ? mergeStep(subNext.get(p.name)) : p
326
+ subNext.has(p.name) ? mergeStep(subNext.get(p.name)) : kept(p)
324
327
  );
325
328
  for (const s of next.sub) if (!known.has(s.name)) sub.push(mergeStep(s));
326
329
  const status = sub.some(owed) ? 'FAIL' : 'pass';
@@ -0,0 +1,340 @@
1
+ /**
2
+ * The report inbox client: `npx bitboss-ui report` and the MCP `report_issue`
3
+ * tool both send through `sendReport`. Zero dependencies (Node's fetch and
4
+ * crypto), so `report` runs on the CLI's slim path with nothing else
5
+ * installed.
6
+ *
7
+ * The inbox is the docs site's `/api/report`: `GET` on it returns the
8
+ * contract as JSON. A bare POST is accepted; the optional proof of work
9
+ * (`x-bitboss-pow`) marks the report verified, which lifts it out of the
10
+ * smaller unverified daily ceiling.
11
+ */
12
+ import { createHash } from 'node:crypto';
13
+ import { readFileSync } from 'node:fs';
14
+ import { join } from 'node:path';
15
+ import { parseArgs } from 'node:util';
16
+
17
+ /**
18
+ * Whether the app at `root` reports to the maintainers. On by default; an
19
+ * app turns it off with `"bitboss-ui": { "report": false }` in its
20
+ * package.json, read like the key's other entries
21
+ * (`dialogIdsWhitelist`, `registeredRules`). Only a literal `false` turns it
22
+ * off; a missing or broken package.json leaves it on.
23
+ * @param {string} [root] the project root (default: the working directory)
24
+ */
25
+ export function reportingEnabled(root = process.cwd()) {
26
+ try {
27
+ const pkg = JSON.parse(readFileSync(join(root, 'package.json'), 'utf-8'));
28
+ return pkg?.['bitboss-ui']?.report !== false;
29
+ } catch {
30
+ return true;
31
+ }
32
+ }
33
+
34
+ /** What `report` prints when the app turned reporting off. */
35
+ export const REPORTING_OFF =
36
+ '[bitboss-ui] report: reporting is off in this project: package.json bitboss-ui.report';
37
+
38
+ export const REPORT_URL = 'https://ui-components.bitboss.it/api/report';
39
+
40
+ /** One line per kind, the same words the inbox serves on `GET /api/report`. */
41
+ export const KIND_DEFINITIONS = {
42
+ bug: 'The library does the wrong thing.',
43
+ friction:
44
+ 'It works, but getting there took trial and error, or the docs or types misled you.',
45
+ glue: 'Code you had to write around the library for a common need (a wrapper, an adapter, wiring you repeat across screens). Put the glue in `snippet`.',
46
+ smell:
47
+ 'It works, but something feels wrong: an inconsistent API, an odd name, a surprising default.',
48
+ feature: "Something the library doesn't do and should.",
49
+ docs: 'Docs that are wrong, missing or unfindable.',
50
+ };
51
+ export const REPORT_KINDS = Object.keys(KIND_DEFINITIONS);
52
+
53
+ /** The no-install way to report, as the agent docs print it. */
54
+ export const REPORT_CURL = `curl -sS ${REPORT_URL} -H 'content-type: application/json' -d '{"kind":"bug","component":"BbSelect","version":"<installed bitboss-ui version>","expected":"…","actual":"…"}'`;
55
+
56
+ /** The body's fields, in contract order. Unknown keys are refused by the inbox. */
57
+ export const REPORT_FIELDS = [
58
+ 'component',
59
+ 'kind',
60
+ 'version',
61
+ 'expected',
62
+ 'actual',
63
+ 'workaround',
64
+ 'snippet',
65
+ 'page',
66
+ 'reporter',
67
+ ];
68
+ const REQUIRED = ['component', 'kind', 'version', 'expected', 'actual'];
69
+
70
+ /** The inbox's default difficulty; a 401 names the current one. */
71
+ const POW_BITS = 20;
72
+
73
+ function leadingZeroBits(buffer) {
74
+ let bits = 0;
75
+ for (const byte of buffer) {
76
+ if (byte === 0) {
77
+ bits += 8;
78
+ continue;
79
+ }
80
+ return bits + Math.clz32(byte) - 24;
81
+ }
82
+ return bits;
83
+ }
84
+
85
+ /**
86
+ * The inbox's proof of work, copied from its reference solver: a nonce such
87
+ * that `sha256("<ts>.<nonce>.<sha256 hex of the exact body>")` starts with
88
+ * `bits` zero bits. About a second of CPU at 20 bits.
89
+ * @param {string} rawBody the exact string that will be POSTed
90
+ * @param {number} bits
91
+ * @param {number} [nowSeconds]
92
+ * @returns {string} the `x-bitboss-pow` header value
93
+ */
94
+ export function solvePow(
95
+ rawBody,
96
+ bits,
97
+ nowSeconds = Math.floor(Date.now() / 1000)
98
+ ) {
99
+ const digest = createHash('sha256').update(rawBody).digest('hex');
100
+ for (let nonce = 0; ; nonce++) {
101
+ const n = nonce.toString(36);
102
+ const hash = createHash('sha256')
103
+ .update(`${nowSeconds}.${n}.${digest}`)
104
+ .digest();
105
+ if (leadingZeroBits(hash) >= bits) return `${nowSeconds}.${n}`;
106
+ }
107
+ }
108
+
109
+ /** Whether `header` solves `rawBody` at `bits` (for tests). */
110
+ export function powSolves(header, rawBody, bits) {
111
+ const [ts, nonce] = header.split('.');
112
+ const digest = createHash('sha256').update(rawBody).digest('hex');
113
+ const hash = createHash('sha256').update(`${ts}.${nonce}.${digest}`).digest();
114
+ return leadingZeroBits(hash) >= bits;
115
+ }
116
+
117
+ /**
118
+ * The body to send: known fields only, empty strings dropped, `version`
119
+ * filled with the installed one when the caller left it out.
120
+ * @returns {{ body: Record<string, string>, problems: string[] }}
121
+ */
122
+ export function buildReport(input, { version }) {
123
+ const body = {};
124
+ const problems = [];
125
+ for (const key of Object.keys(input ?? {})) {
126
+ if (!REPORT_FIELDS.includes(key)) problems.push(`unknown field \`${key}\``);
127
+ }
128
+ for (const field of REPORT_FIELDS) {
129
+ const value = input?.[field];
130
+ if (value === undefined || value === null) continue;
131
+ if (typeof value !== 'string') {
132
+ problems.push(`\`${field}\` must be a string`);
133
+ continue;
134
+ }
135
+ if (value.trim() !== '') body[field] = value;
136
+ }
137
+ body.version ??= version || 'unknown';
138
+ for (const field of REQUIRED) {
139
+ if (!(field in body)) problems.push(`\`${field}\` is required`);
140
+ }
141
+ if (body.kind && !REPORT_KINDS.includes(body.kind))
142
+ problems.push(`\`kind\` is one of ${REPORT_KINDS.join(', ')}`);
143
+ // Contract order, so the bytes are stable for the proof of work.
144
+ const ordered = {};
145
+ for (const field of REPORT_FIELDS)
146
+ if (field in body) ordered[field] = body[field];
147
+ return { body: ordered, problems };
148
+ }
149
+
150
+ /**
151
+ * POST a report. Solves the proof of work unless `pow: false`; on a 401
152
+ * that names another difficulty it solves once more at that one, and
153
+ * otherwise resends without the proof (an unverified report still lands).
154
+ * @param {Record<string, string>} body from {@link buildReport}
155
+ * @param {{ client: string, fetch?: typeof fetch, url?: string, pow?: boolean, bits?: number }} options
156
+ * @returns {Promise<{ status: number, body: any }>}
157
+ */
158
+ export async function sendReport(
159
+ body,
160
+ {
161
+ client,
162
+ fetch: fetchImpl = globalThis.fetch,
163
+ url = process.env.BITBOSS_UI_REPORT_URL || REPORT_URL,
164
+ pow = true,
165
+ bits = POW_BITS,
166
+ }
167
+ ) {
168
+ const raw = JSON.stringify(body);
169
+ const post = async (proof) => {
170
+ const headers = {
171
+ 'content-type': 'application/json',
172
+ 'x-bitboss-client': client,
173
+ };
174
+ if (proof) headers['x-bitboss-pow'] = proof;
175
+ const response = await fetchImpl(url, {
176
+ method: 'POST',
177
+ headers,
178
+ body: raw,
179
+ });
180
+ let json;
181
+ try {
182
+ json = await response.json();
183
+ } catch {
184
+ json = { error: `HTTP ${response.status}` };
185
+ }
186
+ return { status: response.status, body: json };
187
+ };
188
+ let result = await post(pow && bits > 0 ? solvePow(raw, bits) : undefined);
189
+ if (result.status === 401 && result.body?.error === 'proof_of_work_invalid') {
190
+ const next = Number(result.body.bits);
191
+ result = await post(
192
+ Number.isInteger(next) && next > 0 && next <= 32 && next !== bits
193
+ ? solvePow(raw, next)
194
+ : undefined
195
+ );
196
+ }
197
+ return result;
198
+ }
199
+
200
+ /** One human line per outcome; `ok` says whether the report landed. */
201
+ export function describeResult({ status, body }) {
202
+ if ((status === 200 || status === 201) && body?.id) {
203
+ const where = body.duplicate ? 'Added to an open report' : 'Report filed';
204
+ return {
205
+ ok: true,
206
+ lines: [
207
+ `${where}: ${body.id}${body.verified === false ? ' (unverified)' : ''}`,
208
+ `Status: ${body.statusUrl}`,
209
+ ],
210
+ };
211
+ }
212
+ if (status === 400 && Array.isArray(body?.issues))
213
+ return {
214
+ ok: false,
215
+ lines: [
216
+ 'The inbox refused the report:',
217
+ ...body.issues.map((i) => ` ${i.field || '(body)'}: ${i.message}`),
218
+ ],
219
+ };
220
+ if (status === 429 || status === 503)
221
+ return {
222
+ ok: false,
223
+ lines: [
224
+ `The inbox is busy (${body?.error ?? status}); retry in ${body?.retryAfter ?? 60} s.`,
225
+ ],
226
+ };
227
+ return {
228
+ ok: false,
229
+ lines: [
230
+ `The inbox answered ${status}: ${body?.error ?? 'unknown error'}${body?.hint ? ` (${body.hint})` : ''}`,
231
+ ],
232
+ };
233
+ }
234
+
235
+ export const REPORT_HELP = `Usage:
236
+ npx bitboss-ui report --kind <kind> --component <name> --expected <text> --actual <text>
237
+ [--workaround <text>] [--snippet <text>] [--page <path>]
238
+ [--reporter <contact>] [--version <v>] [--json]
239
+ npx bitboss-ui report --stdin [--json] < report.json
240
+
241
+ Kinds:
242
+ ${REPORT_KINDS.map((k) => ` ${k.padEnd(9)}${KIND_DEFINITIONS[k]}`).join('\n')}
243
+
244
+ --component is a Bb* name, or the surface (cli, mcp, vite-plugin, nuxt-module,
245
+ docs, other). --version defaults to the installed bitboss-ui. --stdin reads one
246
+ JSON object with the same field names; flags override it. Send a minimal repro
247
+ only: never app data, customer data, secrets or proprietary code. Keep your
248
+ workaround in place: a report never waits on a fix.`;
249
+
250
+ function readStdin() {
251
+ return readFileSync(0, 'utf-8');
252
+ }
253
+
254
+ /**
255
+ * `npx bitboss-ui report`. Exit 0 when the report landed, 1 otherwise.
256
+ * @param {string[]} argv
257
+ * @param {{ version?: string, fetch?: typeof fetch, bits?: number, stdin?: () => string, log?: (s: string) => void, error?: (s: string) => void, root?: string }} [io] test seams
258
+ */
259
+ export async function reportCli(argv, io = {}) {
260
+ const log = io.log ?? ((s) => console.log(s));
261
+ const error = io.error ?? ((s) => console.error(s));
262
+ if (!reportingEnabled(io.root)) {
263
+ error(REPORTING_OFF);
264
+ return 1;
265
+ }
266
+ const version = io.version ?? installedVersion();
267
+ let values;
268
+ try {
269
+ ({ values } = parseArgs({
270
+ args: argv,
271
+ allowPositionals: false,
272
+ options: {
273
+ ...Object.fromEntries(
274
+ REPORT_FIELDS.map((f) => [f, { type: 'string' }])
275
+ ),
276
+ stdin: { type: 'boolean' },
277
+ json: { type: 'boolean' },
278
+ help: { type: 'boolean', short: 'h' },
279
+ },
280
+ }));
281
+ } catch (e) {
282
+ error(`[bitboss-ui] report: ${e instanceof Error ? e.message : String(e)}`);
283
+ error(REPORT_HELP);
284
+ return 1;
285
+ }
286
+ if (values.help) {
287
+ log(REPORT_HELP);
288
+ return 0;
289
+ }
290
+ let input = {};
291
+ if (values.stdin) {
292
+ try {
293
+ input = JSON.parse((io.stdin ?? readStdin)());
294
+ } catch (e) {
295
+ error(
296
+ `[bitboss-ui] report: --stdin needs one JSON object (${e instanceof Error ? e.message : String(e)})`
297
+ );
298
+ return 1;
299
+ }
300
+ if (!input || typeof input !== 'object' || Array.isArray(input)) {
301
+ error('[bitboss-ui] report: --stdin needs one JSON object');
302
+ return 1;
303
+ }
304
+ }
305
+ for (const field of REPORT_FIELDS)
306
+ if (values[field] !== undefined) input[field] = values[field];
307
+ const { body, problems } = buildReport(input, { version });
308
+ if (problems.length) {
309
+ error(`[bitboss-ui] report: ${problems.join('; ')}`);
310
+ error(REPORT_HELP);
311
+ return 1;
312
+ }
313
+ let result;
314
+ try {
315
+ result = await sendReport(body, {
316
+ client: `bitboss-ui-cli/${version}`,
317
+ fetch: io.fetch,
318
+ bits: io.bits,
319
+ });
320
+ } catch (e) {
321
+ error(
322
+ `[bitboss-ui] report: could not reach the inbox (${e instanceof Error ? e.message : String(e)})`
323
+ );
324
+ return 1;
325
+ }
326
+ const { ok, lines } = describeResult(result);
327
+ if (values.json) log(JSON.stringify(result.body));
328
+ else (ok ? log : error)(lines.join('\n'));
329
+ return ok ? 0 : 1;
330
+ }
331
+
332
+ export function installedVersion() {
333
+ try {
334
+ return JSON.parse(
335
+ readFileSync(new URL('../../package.json', import.meta.url), 'utf-8')
336
+ ).version;
337
+ } catch {
338
+ return 'unknown';
339
+ }
340
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The heartbeat of a recorded run (run-records.mjs startRun), as its own
3
+ * detached process: the gates run their steps with spawnSync, which blocks
4
+ * the parent's timers. Every BEAT_MS it appends a `beat` line with a load
5
+ * and memory sample; when the parent is gone without having stopped it (a
6
+ * kill, a crash: the run writes no history), it appends `gone` and exits.
7
+ *
8
+ * Usage: node scripts/lib/run-beat.mjs <run log> <runId> <parent pid>
9
+ */
10
+ import { beatLoop } from './run-records.mjs';
11
+
12
+ const [log, runId, parent] = process.argv.slice(2);
13
+ beatLoop({ env: { BB_RUN_LOG: log, BB_RUN_ID: runId }, pid: Number(parent) });
14
+ process.on('SIGTERM', () => process.exit(0));