@codewizard-dt/bootstrap 5.1.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +11 -3
  2. package/bin/cli.js +16 -0
  3. package/lib/hooks/README.md +124 -3
  4. package/lib/hooks/claude-settings-guard.js +8 -2
  5. package/lib/prompts/README.md +1 -1
  6. package/lib/prompts/migrate-wiki.md +7 -7
  7. package/lib/scripts/README.md +111 -10
  8. package/lib/scripts/bootstrap-prefs-tui.js +1222 -0
  9. package/lib/scripts/install-global.sh +137 -6
  10. package/lib/scripts/migrate-project.sh +52 -10
  11. package/lib/scripts/rename-wiki-ids.js +232 -0
  12. package/lib/scripts/templates/CLAUDE-wiki.md +6 -6
  13. package/lib/scripts/templates/bootstrap-prefs-schema.json +11 -2
  14. package/lib/scripts/templates/settings-sandbox-unattended.json +36 -0
  15. package/lib/scripts/templates/settings-sandbox.json +7 -0
  16. package/lib/scripts/templates/wiki/conventions.md +12 -10
  17. package/lib/scripts/templates/wiki/dashboard.html +527 -23
  18. package/lib/scripts/templates/wiki/index.md +2 -2
  19. package/lib/scripts/templates/wiki/work/bugs/lifecycle.md +1 -1
  20. package/lib/scripts/templates/wiki/work/decisions/index.md +12 -4
  21. package/lib/scripts/templates/wiki/work/decisions/lifecycle.md +11 -9
  22. package/lib/scripts/templates/wiki/work/requirements/index.md +12 -4
  23. package/lib/scripts/templates/wiki/work/requirements/lifecycle.md +8 -8
  24. package/lib/scripts/templates/wiki/work/roadmaps/index.md +11 -3
  25. package/lib/scripts/templates/wiki/work/roadmaps/lifecycle.md +7 -5
  26. package/lib/scripts/templates/wiki/work/tasks/index.md +1 -1
  27. package/lib/scripts/templates/wiki/work/tasks/lifecycle.md +16 -8
  28. package/lib/scripts/templates/wiki/work/uat/lifecycle.md +3 -3
  29. package/lib/scripts/wiki-dashboard-server.js +98 -0
  30. package/lib/skills/README.md +27 -22
  31. package/lib/skills/_shared/ARCHIVE-WORK-ITEM.md +103 -0
  32. package/lib/skills/_shared/ID-RESOLUTION.md +142 -0
  33. package/lib/skills/_shared/SKILL-BOILERPLATE.md +50 -0
  34. package/lib/skills/adr-assess/SKILL.md +112 -0
  35. package/lib/skills/{decision-create → adr-create}/SKILL.md +27 -26
  36. package/lib/skills/adr-deprecate/SKILL.md +190 -0
  37. package/lib/skills/adr-extract/SKILL.md +255 -0
  38. package/lib/skills/{decision-finalize → adr-finalize}/SKILL.md +38 -38
  39. package/lib/skills/{decision-next → adr-next}/SKILL.md +20 -19
  40. package/lib/skills/{decision-walkthrough → adr-walkthrough}/SKILL.md +23 -29
  41. package/lib/skills/architecture-audit/SKILL.md +24 -3
  42. package/lib/skills/autopilot/SKILL.md +110 -0
  43. package/lib/skills/bootstrap-config/SKILL.md +1 -1
  44. package/lib/skills/bug-assess/SKILL.md +3 -3
  45. package/lib/skills/bug-close/SKILL.md +15 -26
  46. package/lib/skills/{bug-file → bug-create}/SKILL.md +25 -15
  47. package/lib/skills/bug-triage/SKILL.md +5 -19
  48. package/lib/skills/demo/SKILL.md +11 -11
  49. package/lib/skills/elevator-pitch/SKILL.md +1 -1
  50. package/lib/skills/extract-feature/SKILL.md +29 -87
  51. package/lib/skills/git-commit/SKILL.md +4 -4
  52. package/lib/skills/marp-slideshow/SKILL.md +2 -2
  53. package/lib/skills/port-feature/SKILL.md +28 -83
  54. package/lib/skills/power-mode/SKILL.md +42 -49
  55. package/lib/skills/prd-assess/SKILL.md +105 -0
  56. package/lib/skills/{req-compile → prd-compile}/SKILL.md +6 -13
  57. package/lib/skills/{req-create → prd-create}/SKILL.md +19 -19
  58. package/lib/skills/prd-deprecate/SKILL.md +173 -0
  59. package/lib/skills/{req-finalize → prd-finalize}/SKILL.md +20 -29
  60. package/lib/skills/primer/SKILL.md +2 -2
  61. package/lib/skills/research/SKILL.md +3 -3
  62. package/lib/skills/roadmap-assess/SKILL.md +20 -20
  63. package/lib/skills/roadmap-create/SKILL.md +23 -29
  64. package/lib/skills/roadmap-next/SKILL.md +16 -28
  65. package/lib/skills/security-audit/SKILL.md +3 -3
  66. package/lib/skills/tackle/SKILL.md +13 -15
  67. package/lib/skills/{task-audit → task-assess}/SKILL.md +34 -44
  68. package/lib/skills/task-close/SKILL.md +73 -0
  69. package/lib/skills/{task-add → task-create}/SKILL.md +44 -24
  70. package/lib/skills/uat-assess/SKILL.md +124 -0
  71. package/lib/skills/uat-auto/SKILL.md +9 -6
  72. package/lib/skills/uat-auto-plus/SKILL.md +2 -2
  73. package/lib/skills/{uat-generate → uat-create}/SKILL.md +10 -12
  74. package/lib/skills/uat-skip/SKILL.md +5 -9
  75. package/lib/skills/uat-walk/SKILL.md +2 -2
  76. package/lib/skills/uat-walk/UAT-CORE.md +29 -16
  77. package/lib/skills/update-docs/SKILL.md +1 -1
  78. package/lib/skills/usage-report/SKILL.md +52 -0
  79. package/lib/skills/usage-report/scripts/pricing.json +22 -0
  80. package/lib/skills/usage-report/scripts/usage-report.js +518 -0
  81. package/lib/skills/whats-next/SKILL.md +177 -0
  82. package/lib/skills/wiki-archive/SKILL.md +12 -23
  83. package/lib/skills/wiki-lint/SKILL.md +42 -5
  84. package/lib/skills/wiki-query/SKILL.md +1 -1
  85. package/lib/skills/wiki-rotate-log/SKILL.md +1 -1
  86. package/lib/skills/wiki-tidy/SKILL.md +6 -9
  87. package/package.json +1 -1
  88. package/lib/scripts/templates/wiki/work/decisions/archive/index.md +0 -10
  89. package/lib/scripts/templates/wiki/work/requirements/archive/index.md +0 -10
  90. package/lib/scripts/templates/wiki/work/roadmaps/archive/index.md +0 -10
  91. package/lib/skills/req-extract-decisions/SKILL.md +0 -241
  92. package/lib/skills/req-retire/SKILL.md +0 -185
  93. package/lib/skills/req-update/SKILL.md +0 -265
  94. package/lib/skills/task-trash/SKILL.md +0 -115
  95. package/lib/skills/task-update/SKILL.md +0 -136
@@ -700,6 +700,97 @@
700
700
  font-weight: 600;
701
701
  }
702
702
 
703
+ /* ---- Usage page ---- */
704
+ .usage-page {
705
+ display: flex;
706
+ flex-direction: column;
707
+ gap: 18px;
708
+ }
709
+
710
+ .usage-meta {
711
+ font-size: 12px;
712
+ color: var(--text-faint);
713
+ }
714
+
715
+ .usage-totals {
716
+ display: grid;
717
+ grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
718
+ gap: 12px;
719
+ }
720
+
721
+ .usage-stat {
722
+ display: flex;
723
+ flex-direction: column;
724
+ gap: 2px;
725
+ }
726
+
727
+ .usage-stat-label {
728
+ font-size: 11px;
729
+ color: var(--text-muted);
730
+ text-transform: uppercase;
731
+ letter-spacing: 0.04em;
732
+ }
733
+
734
+ .usage-stat-value {
735
+ font-family: var(--mono);
736
+ font-size: 16px;
737
+ font-weight: 600;
738
+ }
739
+
740
+ .usage-scroll {
741
+ overflow-x: auto;
742
+ max-width: 100%;
743
+ }
744
+
745
+ .usage-table {
746
+ border-collapse: collapse;
747
+ width: 100%;
748
+ font-size: 13px;
749
+ }
750
+
751
+ .usage-table th, .usage-table td {
752
+ border: 1px solid var(--panel-border);
753
+ padding: 5px 10px;
754
+ text-align: left;
755
+ }
756
+
757
+ .usage-table th {
758
+ background: var(--count-bg);
759
+ font-weight: 600;
760
+ white-space: nowrap;
761
+ }
762
+
763
+ .usage-table .num {
764
+ text-align: right;
765
+ font-family: var(--mono);
766
+ white-space: nowrap;
767
+ }
768
+
769
+ .usage-table .mono {
770
+ font-family: var(--mono);
771
+ font-size: 12px;
772
+ }
773
+
774
+ .usage-notice {
775
+ padding: 8px 12px;
776
+ border-radius: 8px;
777
+ background: var(--badge-bad-bg);
778
+ color: var(--badge-bad-text);
779
+ font-size: 12px;
780
+ }
781
+
782
+ .usage-footnote {
783
+ margin: 0;
784
+ font-size: 12px;
785
+ color: var(--text-muted);
786
+ }
787
+
788
+ .card-desc {
789
+ font-size: 12px;
790
+ color: var(--text-muted);
791
+ min-height: 22px;
792
+ }
793
+
703
794
  .not-found {
704
795
  color: var(--text-muted);
705
796
  font-style: italic;
@@ -774,6 +865,15 @@
774
865
  bugs: 'Bugs',
775
866
  };
776
867
 
868
+ // Families whose finished items stay in place and are listed under the
869
+ // "## Closed" heading of the family index.md (no archive/). tasks, uat and
870
+ // bugs still archive, so their section is labelled "Archived".
871
+ const IN_PLACE_FAMILIES = ['requirements', 'decisions', 'roadmaps'];
872
+
873
+ function closedLabel(family) {
874
+ return IN_PLACE_FAMILIES.indexOf(family) !== -1 ? 'Closed' : 'Archived';
875
+ }
876
+
777
877
  // How often (ms) the poll loop re-fetches the family indexes.
778
878
  const POLL_INTERVAL_MS = 5000;
779
879
 
@@ -786,6 +886,7 @@
786
886
  'proposed': 'neutral',
787
887
  'pending': 'neutral',
788
888
  'in-progress': 'accent',
889
+ 'pending-uat': 'accent',
789
890
  'triaged': 'accent',
790
891
  'active': 'accent',
791
892
  'done': 'good',
@@ -797,6 +898,7 @@
797
898
  'trashed': 'muted',
798
899
  'skipped': 'muted',
799
900
  'retired': 'muted',
901
+ 'deprecated': 'muted',
800
902
  'superseded': 'muted',
801
903
  'wontfix': 'muted',
802
904
  'duplicate': 'muted',
@@ -905,25 +1007,47 @@
905
1007
  return items;
906
1008
  }
907
1009
 
908
- // --- Fetch one file, returning parsed items ([] on any failure/404) ---
909
- async function fetchIndexFile(url) {
1010
+ // --- Fetch one file's raw text ('' on any failure/404) ---
1011
+ async function fetchIndexText(url) {
910
1012
  try {
911
1013
  const resp = await fetch(url, { cache: 'no-store' });
912
- if (!resp.ok) return []; // 404 (no archive/empty family) etc. -> zero items
913
- const text = await resp.text();
914
- return parseIndexMarkdown(text);
1014
+ if (!resp.ok) return ''; // 404 (no archive/empty family) etc. -> zero items
1015
+ return await resp.text();
915
1016
  } catch (_err) {
916
- return [];
1017
+ return '';
917
1018
  }
918
1019
  }
919
1020
 
920
- // --- Fetch one family's active + archived items ---
1021
+ // --- Split a family index.md at its "## Closed" heading ---
1022
+ // In-place families (roadmaps, decisions, requirements) list finished
1023
+ // items under "## Closed"; everything before it is the Active section.
1024
+ // Indexes without that heading (tasks/uat/bugs, or an un-migrated
1025
+ // project) come back with empty closedText, so the whole file is active.
1026
+ function splitClosedSection(text) {
1027
+ const lines = (text || '').split(/\r?\n/);
1028
+ const at = lines.findIndex(function (line) {
1029
+ return /^## Closed\s*$/.test(line);
1030
+ });
1031
+ if (at === -1) return { activeText: text || '', closedText: '' };
1032
+ return {
1033
+ activeText: lines.slice(0, at).join('\n'),
1034
+ closedText: lines.slice(at + 1).join('\n'),
1035
+ };
1036
+ }
1037
+
1038
+ // --- Fetch one family's active + archived/closed items ---
1039
+ // archived = Closed-section rows of index.md, then any legacy
1040
+ // archive/index.md rows (tasks/uat/bugs, and un-migrated projects).
921
1041
  async function fetchFamily(familyName) {
922
- const [active, archived] = await Promise.all([
923
- fetchIndexFile('/wiki/work/' + familyName + '/index.md'),
924
- fetchIndexFile('/wiki/work/' + familyName + '/archive/index.md'),
1042
+ const [indexText, archiveText] = await Promise.all([
1043
+ fetchIndexText('/wiki/work/' + familyName + '/index.md'),
1044
+ fetchIndexText('/wiki/work/' + familyName + '/archive/index.md'),
925
1045
  ]);
926
- return { active: active, archived: archived };
1046
+ const sections = splitClosedSection(indexText);
1047
+ return {
1048
+ active: parseIndexMarkdown(sections.activeText),
1049
+ archived: parseIndexMarkdown(sections.closedText).concat(parseIndexMarkdown(archiveText)),
1050
+ };
927
1051
  }
928
1052
 
929
1053
  // --- Fetch + parse the wiki data for all six families ---
@@ -967,6 +1091,7 @@
967
1091
  try { return decodeURIComponent(p); } catch (e) { return p; }
968
1092
  });
969
1093
  const family = parts[0];
1094
+ if (family === 'usage') return { view: 'usage' };
970
1095
  if (FAMILIES.indexOf(family) === -1) return { view: 'overview' };
971
1096
  if (parts.length === 1) return { view: 'family', family: family };
972
1097
  const file = parts.slice(1).join('/');
@@ -1028,7 +1153,7 @@
1028
1153
 
1029
1154
  const arch = document.createElement('div');
1030
1155
  arch.className = 'card-archived';
1031
- arch.textContent = archived.length + ' archived';
1156
+ arch.textContent = archived.length + ' ' + closedLabel(family).toLowerCase();
1032
1157
  card.appendChild(arch);
1033
1158
 
1034
1159
  return card;
@@ -1042,9 +1167,32 @@
1042
1167
  const bucket = (data && data[family]) || { active: [], archived: [] };
1043
1168
  grid.appendChild(buildFamilyCard(family, bucket));
1044
1169
  });
1170
+ grid.appendChild(buildUsageCard());
1045
1171
  container.appendChild(grid);
1046
1172
  }
1047
1173
 
1174
+ // Static entry card for the usage page. It never fetches: the usage
1175
+ // report parse is heavy, so data loads only once #/usage is entered.
1176
+ function buildUsageCard() {
1177
+ const card = document.createElement('a');
1178
+ card.className = 'family-card';
1179
+ card.href = '#/usage';
1180
+
1181
+ const top = document.createElement('div');
1182
+ top.className = 'card-top';
1183
+ const h2 = document.createElement('h2');
1184
+ h2.textContent = 'Usage';
1185
+ top.appendChild(h2);
1186
+ card.appendChild(top);
1187
+
1188
+ const desc = document.createElement('div');
1189
+ desc.className = 'card-desc';
1190
+ desc.textContent = 'Token and cost rollup by model and skill';
1191
+ card.appendChild(desc);
1192
+
1193
+ return card;
1194
+ }
1195
+
1048
1196
  // ============================================================
1049
1197
  // View: family page
1050
1198
  // ============================================================
@@ -1116,10 +1264,12 @@
1116
1264
  return row;
1117
1265
  }
1118
1266
 
1119
- // Archived row: ID chip + title + final-status badge + archived date.
1120
- // Unlinked: archive tables carry [[ID]] wiki-links, not paths, and
1121
- // deriving a filename from an ID is unreliable (slugs vary).
1122
- function buildArchiveRow(item) {
1267
+ // Archived/Closed row: ID chip + title + final-status badge + archived date.
1268
+ // Archive-table rows are unlinked: they carry [[ID]] wiki-links, not paths,
1269
+ // and deriving a filename from an ID is unreliable (slugs vary). Closed
1270
+ // rows from an in-place index are bullets with a real relative path, so
1271
+ // their title links to the item page.
1272
+ function buildArchiveRow(item, family) {
1123
1273
  const row = document.createElement('div');
1124
1274
  row.className = 'archive-item';
1125
1275
 
@@ -1132,9 +1282,13 @@
1132
1282
  row.appendChild(idEl);
1133
1283
  }
1134
1284
 
1135
- const labelEl = document.createElement('span');
1285
+ const labelEl = document.createElement(item.path ? 'a' : 'span');
1136
1286
  labelEl.className = 'item-label';
1137
1287
  labelEl.textContent = parsed.label || '(untitled)';
1288
+ if (item.path) {
1289
+ labelEl.href = itemHash(family, item.path);
1290
+ labelEl.title = item.path;
1291
+ }
1138
1292
  row.appendChild(labelEl);
1139
1293
 
1140
1294
  const kw = statusKeyword(item.status);
@@ -1207,7 +1361,7 @@
1207
1361
  details.className = 'panel-archive';
1208
1362
  details.open = archiveWasOpen;
1209
1363
  const summary = document.createElement('summary');
1210
- summary.appendChild(document.createTextNode('Archived '));
1364
+ summary.appendChild(document.createTextNode(closedLabel(family) + ' '));
1211
1365
  const archCount = document.createElement('span');
1212
1366
  archCount.className = 'archive-count';
1213
1367
  archCount.textContent = String(archived.length);
@@ -1217,10 +1371,10 @@
1217
1371
  const list = document.createElement('div');
1218
1372
  list.className = 'panel-archive-list';
1219
1373
  if (archived.length === 0) {
1220
- list.appendChild(emptyNote('Nothing archived.'));
1374
+ list.appendChild(emptyNote('Nothing ' + closedLabel(family).toLowerCase() + '.'));
1221
1375
  } else {
1222
1376
  archived.forEach(function (item) {
1223
- list.appendChild(buildArchiveRow(item));
1377
+ list.appendChild(buildArchiveRow(item, family));
1224
1378
  });
1225
1379
  }
1226
1380
  details.appendChild(list);
@@ -1557,6 +1711,342 @@
1557
1711
  page.appendChild(renderMarkdown(split.body, family));
1558
1712
  }
1559
1713
 
1714
+ // ============================================================
1715
+ // View: usage (token and cost rollup from GET /api/usage)
1716
+ // ============================================================
1717
+
1718
+ const USAGE_TIER_TONES = { haiku: 'muted', sonnet: 'accent', opus: 'good', other: 'neutral' };
1719
+ const USAGE_DAYS_SHOWN = 14;
1720
+
1721
+ let usageResult = null;
1722
+ let usageSerialized = null;
1723
+ let usageInFlight = false;
1724
+
1725
+ // Never throws: { state: 'ok', data } on 200, { state: 'empty' } on 404,
1726
+ // { state: 'error' } on any other status or a network/parse failure.
1727
+ async function fetchUsage() {
1728
+ try {
1729
+ const res = await fetch('/api/usage', { cache: 'no-store' });
1730
+ if (res.status === 404) return { state: 'empty' };
1731
+ if (res.status !== 200) return { state: 'error' };
1732
+ const data = await res.json();
1733
+ return { state: 'ok', data: data };
1734
+ } catch (e) {
1735
+ return { state: 'error' };
1736
+ }
1737
+ }
1738
+
1739
+ // Fetch with an overlap guard (the parse can take seconds); re-render only
1740
+ // when the result changed and the viewer is still on the usage page.
1741
+ async function loadUsage() {
1742
+ if (usageInFlight) return;
1743
+ usageInFlight = true;
1744
+ try {
1745
+ const result = await fetchUsage();
1746
+ const serialized = JSON.stringify(result);
1747
+ const changed = serialized !== usageSerialized;
1748
+ usageResult = result;
1749
+ usageSerialized = serialized;
1750
+ if (changed && parseRoute().view === 'usage') renderRoute();
1751
+ } finally {
1752
+ usageInFlight = false;
1753
+ }
1754
+ }
1755
+
1756
+ function usageNum(v) {
1757
+ return typeof v === 'number' && isFinite(v) ? v.toLocaleString() : '—';
1758
+ }
1759
+
1760
+ // Cost is always shown as an estimate; null means no price is known.
1761
+ function usageCost(v) {
1762
+ if (v === null) return 'unpriced';
1763
+ if (typeof v !== 'number' || !isFinite(v)) return '—';
1764
+ return '~$' + v.toLocaleString(undefined, {
1765
+ minimumFractionDigits: 2,
1766
+ maximumFractionDigits: 2,
1767
+ });
1768
+ }
1769
+
1770
+ function usageText(v) {
1771
+ return typeof v === 'string' && v ? v : '—';
1772
+ }
1773
+
1774
+ function usageRows(v) {
1775
+ return Array.isArray(v)
1776
+ ? v.filter(function (r) { return r && typeof r === 'object'; })
1777
+ : [];
1778
+ }
1779
+
1780
+ // Cost-desc sort key: unpriced or missing costs sink to the bottom.
1781
+ function usageCostKey(row) {
1782
+ return typeof row.cost === 'number' && isFinite(row.cost) ? row.cost : -1;
1783
+ }
1784
+
1785
+ function usageObservedModels(row) {
1786
+ if (!row.models || typeof row.models !== 'object') return null;
1787
+ return Object.keys(row.models);
1788
+ }
1789
+
1790
+ // The usage-report script compares declared vs observed model FAMILIES and
1791
+ // emits the verdict as row.modelCheck (match | mismatch | undeclared | unknown);
1792
+ // the dashboard only displays it.
1793
+ function usageDeclaredMismatch(row) {
1794
+ return row.modelCheck === 'mismatch';
1795
+ }
1796
+
1797
+ function buildUsageTierBadge(tier) {
1798
+ const el = document.createElement('span');
1799
+ const key = typeof tier === 'string' ? tier : 'other';
1800
+ el.className = 'badge badge-' + (USAGE_TIER_TONES[key] || 'neutral');
1801
+ el.textContent = typeof tier === 'string' && tier ? tier : '—';
1802
+ return el;
1803
+ }
1804
+
1805
+ // columns: [{ label, num?, mono?, cell(row) -> string | Node }]
1806
+ function buildUsageTable(columns, rows) {
1807
+ const wrap = document.createElement('div');
1808
+ wrap.className = 'usage-scroll';
1809
+ const table = document.createElement('table');
1810
+ table.className = 'usage-table';
1811
+
1812
+ const thead = document.createElement('thead');
1813
+ const headRow = document.createElement('tr');
1814
+ columns.forEach(function (col) {
1815
+ const th = document.createElement('th');
1816
+ if (col.num) th.className = 'num';
1817
+ th.textContent = col.label;
1818
+ headRow.appendChild(th);
1819
+ });
1820
+ thead.appendChild(headRow);
1821
+ table.appendChild(thead);
1822
+
1823
+ const tbody = document.createElement('tbody');
1824
+ rows.forEach(function (row) {
1825
+ const tr = document.createElement('tr');
1826
+ columns.forEach(function (col) {
1827
+ const td = document.createElement('td');
1828
+ if (col.num) td.className = 'num';
1829
+ else if (col.mono) td.className = 'mono';
1830
+ const value = col.cell(row);
1831
+ if (value instanceof Node) td.appendChild(value);
1832
+ else td.textContent = value;
1833
+ tr.appendChild(td);
1834
+ });
1835
+ tbody.appendChild(tr);
1836
+ });
1837
+ table.appendChild(tbody);
1838
+ wrap.appendChild(table);
1839
+ return wrap;
1840
+ }
1841
+
1842
+ function buildUsagePanel(titleText, bodyNode, metaText) {
1843
+ const panel = document.createElement('section');
1844
+ panel.className = 'panel';
1845
+
1846
+ const header = document.createElement('div');
1847
+ header.className = 'panel-header';
1848
+ const title = document.createElement('h2');
1849
+ title.className = 'panel-title';
1850
+ title.textContent = titleText;
1851
+ header.appendChild(title);
1852
+ if (metaText) {
1853
+ const meta = document.createElement('span');
1854
+ meta.className = 'usage-meta';
1855
+ meta.textContent = metaText;
1856
+ header.appendChild(meta);
1857
+ }
1858
+ panel.appendChild(header);
1859
+
1860
+ const body = document.createElement('div');
1861
+ body.className = 'panel-body';
1862
+ body.appendChild(bodyNode);
1863
+ panel.appendChild(body);
1864
+ return panel;
1865
+ }
1866
+
1867
+ function buildUsageTotals(totals) {
1868
+ const grid = document.createElement('div');
1869
+ grid.className = 'usage-totals';
1870
+ [
1871
+ ['Input', usageNum(totals.input)],
1872
+ ['Output', usageNum(totals.output)],
1873
+ ['Cache write', usageNum(totals.cacheCreation)],
1874
+ ['Cache read', usageNum(totals.cacheRead)],
1875
+ ['Est. cost', usageCost(totals.cost)],
1876
+ ['Turns', usageNum(totals.turns)],
1877
+ ].forEach(function (pair) {
1878
+ const stat = document.createElement('div');
1879
+ stat.className = 'usage-stat';
1880
+ const label = document.createElement('span');
1881
+ label.className = 'usage-stat-label';
1882
+ label.textContent = pair[0];
1883
+ const value = document.createElement('span');
1884
+ value.className = 'usage-stat-value';
1885
+ value.textContent = pair[1];
1886
+ stat.appendChild(label);
1887
+ stat.appendChild(value);
1888
+ grid.appendChild(stat);
1889
+ });
1890
+ return grid;
1891
+ }
1892
+
1893
+ function buildUsageByModel(rows) {
1894
+ if (rows.length === 0) return emptyNote('No per-model data.');
1895
+ return buildUsageTable([
1896
+ { label: 'Model', mono: true, cell: function (r) { return usageText(r.model); } },
1897
+ { label: 'Tier', cell: function (r) { return buildUsageTierBadge(r.tier); } },
1898
+ { label: 'Input', num: true, cell: function (r) { return usageNum(r.input); } },
1899
+ { label: 'Output', num: true, cell: function (r) { return usageNum(r.output); } },
1900
+ { label: 'Cache write', num: true, cell: function (r) { return usageNum(r.cacheCreation); } },
1901
+ { label: 'Cache read', num: true, cell: function (r) { return usageNum(r.cacheRead); } },
1902
+ { label: 'Est. cost', num: true, cell: function (r) { return usageCost(r.cost); } },
1903
+ { label: 'Turns', num: true, cell: function (r) { return usageNum(r.turns); } },
1904
+ ], rows);
1905
+ }
1906
+
1907
+ function buildUsageBySkill(rows) {
1908
+ if (rows.length === 0) return emptyNote('No per-skill data.');
1909
+ const sorted = rows.slice().sort(function (a, b) {
1910
+ const diff = usageCostKey(b) - usageCostKey(a);
1911
+ if (diff !== 0) return diff;
1912
+ return (Number(b.turns) || 0) - (Number(a.turns) || 0);
1913
+ });
1914
+ return buildUsageTable([
1915
+ { label: 'Skill', mono: true, cell: function (r) { return usageText(r.skill); } },
1916
+ { label: 'Declared', mono: true, cell: function (r) { return usageText(r.declaredModel); } },
1917
+ {
1918
+ label: 'Observed',
1919
+ mono: true,
1920
+ cell: function (r) {
1921
+ const observed = usageObservedModels(r);
1922
+ if (!observed || observed.length === 0) return '—';
1923
+ return observed
1924
+ .sort(function (a, b) { return (Number(r.models[b]) || 0) - (Number(r.models[a]) || 0); })
1925
+ .map(function (m) { return m + ' ×' + usageNum(r.models[m]); })
1926
+ .join(', ');
1927
+ },
1928
+ },
1929
+ {
1930
+ label: 'Check',
1931
+ cell: function (r) {
1932
+ if (r.modelCheck !== 'match' && r.modelCheck !== 'mismatch') return '—';
1933
+ const badge = document.createElement('span');
1934
+ if (usageDeclaredMismatch(r)) {
1935
+ badge.className = 'badge badge-bad';
1936
+ badge.textContent = 'mismatch';
1937
+ badge.title = 'A different model family than the declared one ran in this skill\'s turns';
1938
+ } else {
1939
+ badge.className = 'badge badge-good';
1940
+ badge.textContent = 'match';
1941
+ }
1942
+ return badge;
1943
+ },
1944
+ },
1945
+ { label: 'Input', num: true, cell: function (r) { return usageNum(r.input); } },
1946
+ { label: 'Output', num: true, cell: function (r) { return usageNum(r.output); } },
1947
+ { label: 'Est. cost', num: true, cell: function (r) { return usageCost(r.cost); } },
1948
+ { label: 'Turns', num: true, cell: function (r) { return usageNum(r.turns); } },
1949
+ ], sorted);
1950
+ }
1951
+
1952
+ // Most recent days first, capped at USAGE_DAYS_SHOWN.
1953
+ function buildUsageByDay(rows) {
1954
+ if (rows.length === 0) return emptyNote('No daily data.');
1955
+ const recent = rows
1956
+ .slice()
1957
+ .sort(function (a, b) { return String(a.date).localeCompare(String(b.date)); })
1958
+ .slice(-USAGE_DAYS_SHOWN)
1959
+ .reverse();
1960
+ return buildUsageTable([
1961
+ { label: 'Date', mono: true, cell: function (r) { return usageText(r.date); } },
1962
+ { label: 'Est. cost', num: true, cell: function (r) { return usageCost(r.cost); } },
1963
+ { label: 'Turns', num: true, cell: function (r) { return usageNum(r.turns); } },
1964
+ ], recent);
1965
+ }
1966
+
1967
+ function buildUsageFootnote(meta) {
1968
+ const parts = [
1969
+ 'Costs are estimates, not billing figures.',
1970
+ 'Attribution is last-invoked-skill: each turn is credited to the most recently invoked skill.',
1971
+ ];
1972
+ if (typeof meta.pricingAsOf === 'string' && meta.pricingAsOf) {
1973
+ parts.push('Pricing as of ' + meta.pricingAsOf + '.');
1974
+ }
1975
+ if (Array.isArray(meta.unpricedModels) && meta.unpricedModels.length > 0) {
1976
+ parts.push('Unpriced models (cost not estimated): ' + meta.unpricedModels.join(', ') + '.');
1977
+ }
1978
+ const p = document.createElement('p');
1979
+ p.className = 'usage-footnote';
1980
+ p.textContent = parts.join(' ');
1981
+ return p;
1982
+ }
1983
+
1984
+ function renderUsagePage(container, result) {
1985
+ container.textContent = '';
1986
+
1987
+ const back = document.createElement('a');
1988
+ back.className = 'back-link';
1989
+ back.href = '#/';
1990
+ back.textContent = '← Overview';
1991
+ container.appendChild(back);
1992
+
1993
+ const page = document.createElement('div');
1994
+ page.className = 'usage-page';
1995
+ container.appendChild(page);
1996
+
1997
+ function message(text) {
1998
+ page.appendChild(buildUsagePanel('Usage', emptyNote(text)));
1999
+ }
2000
+
2001
+ const emptyText =
2002
+ 'No usage found for this project yet. Run `/usage-report` to check that transcripts are being read.';
2003
+
2004
+ if (!result) {
2005
+ message('Loading usage report… this can take a few seconds.');
2006
+ return;
2007
+ }
2008
+ if (result.state === 'error') {
2009
+ message('The usage report could not be generated.');
2010
+ return;
2011
+ }
2012
+ if (result.state === 'empty') {
2013
+ message(emptyText);
2014
+ return;
2015
+ }
2016
+
2017
+ const data = result.data && typeof result.data === 'object' ? result.data : {};
2018
+ const totals = data.totals && typeof data.totals === 'object' ? data.totals : {};
2019
+ const meta = data.meta && typeof data.meta === 'object' ? data.meta : {};
2020
+
2021
+ if (totals.turns === 0) {
2022
+ message(emptyText);
2023
+ return;
2024
+ }
2025
+
2026
+ if (data.schemaVersion !== 1) {
2027
+ const notice = document.createElement('div');
2028
+ notice.className = 'usage-notice';
2029
+ notice.textContent =
2030
+ 'Unexpected usage schema version (' + String(data.schemaVersion) +
2031
+ '); expected 1. Figures below may be incomplete or wrong.';
2032
+ page.appendChild(notice);
2033
+ }
2034
+
2035
+ const metaBits = [];
2036
+ if (typeof data.scope === 'string' && data.scope) metaBits.push(data.scope);
2037
+ if (typeof data.generatedAt === 'string' && data.generatedAt) {
2038
+ metaBits.push('generated ' + data.generatedAt);
2039
+ }
2040
+
2041
+ page.appendChild(buildUsagePanel('Totals', buildUsageTotals(totals), metaBits.join(' · ')));
2042
+ page.appendChild(buildUsagePanel('By model', buildUsageByModel(usageRows(data.byModel))));
2043
+ page.appendChild(buildUsagePanel('By skill', buildUsageBySkill(usageRows(data.bySkill))));
2044
+ page.appendChild(
2045
+ buildUsagePanel('Last ' + USAGE_DAYS_SHOWN + ' days', buildUsageByDay(usageRows(data.byDay)))
2046
+ );
2047
+ page.appendChild(buildUsageFootnote(meta));
2048
+ }
2049
+
1560
2050
  // ============================================================
1561
2051
  // Shell: breadcrumbs, routing, polling, theme
1562
2052
  // ============================================================
@@ -1579,10 +2069,12 @@
1579
2069
  sep1.textContent = '›';
1580
2070
  nav.appendChild(sep1);
1581
2071
 
1582
- if (route.view === 'family') {
2072
+ if (route.view === 'family' || route.view === 'usage') {
1583
2073
  const cur = document.createElement('span');
1584
2074
  cur.className = 'crumb-current';
1585
- cur.textContent = FAMILY_LABELS[route.family] || route.family;
2075
+ cur.textContent = route.view === 'usage'
2076
+ ? 'Usage'
2077
+ : (FAMILY_LABELS[route.family] || route.family);
1586
2078
  nav.appendChild(cur);
1587
2079
  return;
1588
2080
  }
@@ -1613,11 +2105,20 @@
1613
2105
  renderFamilyPage(container, route.family, wikiData);
1614
2106
  } else if (route.view === 'item') {
1615
2107
  renderItemPage(container, route.family, route.file);
2108
+ } else if (route.view === 'usage') {
2109
+ renderUsagePage(container, usageResult);
1616
2110
  } else {
1617
2111
  renderOverview(container, wikiData);
1618
2112
  }
1619
2113
  }
1620
2114
 
2115
+ // Hash navigation: paint the route, and kick off the usage fetch only
2116
+ // when the viewer actually enters #/usage.
2117
+ function onHashChange() {
2118
+ renderRoute();
2119
+ if (parseRoute().view === 'usage') loadUsage();
2120
+ }
2121
+
1621
2122
  function updateTimestamp(date) {
1622
2123
  const container = document.getElementById('last-updated');
1623
2124
  if (!container) return;
@@ -1664,6 +2165,9 @@
1664
2165
  } else if (changed || force) {
1665
2166
  renderRoute();
1666
2167
  }
2168
+ // Usage is re-fetched only while its page is showing, so the poll
2169
+ // never runs the report script for a viewer on another page.
2170
+ if (route.view === 'usage') loadUsage();
1667
2171
  updateTimestamp(new Date());
1668
2172
  setBanner(null);
1669
2173
  } catch (err) {
@@ -1716,7 +2220,7 @@
1716
2220
  if (btn) {
1717
2221
  btn.addEventListener('click', function () { refresh(true); });
1718
2222
  }
1719
- window.addEventListener('hashchange', renderRoute);
2223
+ window.addEventListener('hashchange', onHashChange);
1720
2224
  initTheme();
1721
2225
  renderRoute(); // paint the shell immediately (empty data)
1722
2226
  refresh(true); // then fill with first data
@@ -38,8 +38,8 @@ _(none yet)_ — one page per entity, filed by sub-type:
38
38
 
39
39
  Each family's `index.md` lists its **active items only** (completed/terminal items drop off the list; files never move — status lives in frontmatter).
40
40
 
41
- - **Requirements** — REQ-NNNN. [Active index](work/requirements/index.md) · [lifecycle](work/requirements/lifecycle.md)
42
- - **Decisions** — DEC-NNNN (per-decision `#DM`). [Active index](work/decisions/index.md) · [lifecycle](work/decisions/lifecycle.md)
41
+ - **Requirements** — PRD-NNNN. [Active index](work/requirements/index.md) · [lifecycle](work/requirements/lifecycle.md)
42
+ - **Decisions** — ADR-NNNN (per-decision `#DM`). [Active index](work/decisions/index.md) · [lifecycle](work/decisions/lifecycle.md)
43
43
  - **Roadmaps** — ROADMAP-NNNN. [Active index](work/roadmaps/index.md) · [lifecycle](work/roadmaps/lifecycle.md)
44
44
  - **Tasks** — TASK-NNNN. [Active index](work/tasks/index.md) · [lifecycle](work/tasks/lifecycle.md)
45
45
  - **UAT** — UAT-NNNN, one per task. [Active index](work/uat/index.md) · [lifecycle](work/uat/lifecycle.md)