@giamme/forge 0.14.1 → 0.16.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 (81) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/SKILL.md +47 -14
  3. package/VERSION +1 -1
  4. package/docs/artifacts.md +1 -1
  5. package/docs/commands.md +302 -9
  6. package/docs/forge-ui.md +14 -0
  7. package/docs/memory.md +22 -0
  8. package/docs/models.md +53 -0
  9. package/docs/reviews.md +7 -0
  10. package/forge +11 -0
  11. package/package.json +1 -1
  12. package/references/dataset.md +16 -4
  13. package/references/decompose.md +154 -9
  14. package/references/harnesses.md +21 -1
  15. package/references/planning.md +59 -0
  16. package/references/solo.md +5 -1
  17. package/references/ui.md +48 -1
  18. package/scripts/forge-artifact.sh +53 -0
  19. package/scripts/forge-compare.py +6 -3
  20. package/scripts/forge-config.py +531 -4
  21. package/scripts/forge-contract.py +55 -8
  22. package/scripts/forge-control.py +0 -2
  23. package/scripts/forge-dispatch.sh +84 -14
  24. package/scripts/forge-fail-first.py +3 -1
  25. package/scripts/forge-guard.py +247 -8
  26. package/scripts/forge-issues.py +12 -0
  27. package/scripts/forge-lib-adopt.sh +260 -0
  28. package/scripts/forge-lib-attribute.sh +10 -2
  29. package/scripts/forge-lib-plans.sh +35 -6
  30. package/scripts/forge-lib-review.sh +13 -5
  31. package/scripts/forge-lib-task.sh +138 -5
  32. package/scripts/forge-memory.sh +41 -4
  33. package/scripts/forge-metrics.sh +7 -0
  34. package/scripts/forge-parallel-options.sh +12 -6
  35. package/scripts/forge-parallel.sh +659 -32
  36. package/scripts/forge-plan-check.py +591 -8
  37. package/scripts/forge-planner.py +480 -0
  38. package/scripts/forge-route.py +16 -2
  39. package/scripts/forge-runs-rm.py +23 -7
  40. package/scripts/forge-runtime.py +111 -2
  41. package/scripts/forge-schedule.py +5 -2
  42. package/scripts/forge-shadow.py +53 -7
  43. package/scripts/forge-solo.sh +87 -7
  44. package/scripts/forge_dataset/cli.py +26 -0
  45. package/scripts/forge_dataset/efforts.py +215 -0
  46. package/scripts/forge_dataset/export.py +1 -0
  47. package/scripts/forge_dataset/harvest.py +55 -0
  48. package/scripts/forge_dataset/history.py +126 -0
  49. package/scripts/forge_dataset/worktrees.py +95 -0
  50. package/scripts/forge_decide/__init__.py +19 -1
  51. package/scripts/forge_decide/builtin_profiles.json +25 -0
  52. package/scripts/forge_decide/cli.py +12 -0
  53. package/scripts/forge_decide/profiles.py +866 -0
  54. package/scripts/forge_decide/resolve.py +38 -6
  55. package/scripts/forge_memory_list.py +153 -0
  56. package/scripts/forge_worktrees.py +88 -0
  57. package/ui/README.md +31 -0
  58. package/ui/docs/api.md +168 -12
  59. package/ui/forge_ui/__init__.py +14 -1
  60. package/ui/forge_ui/__main__.py +1 -1
  61. package/ui/forge_ui/control.py +250 -12
  62. package/ui/forge_ui/executions.py +28 -8
  63. package/ui/forge_ui/findings.py +7 -0
  64. package/ui/forge_ui/models.py +60 -1
  65. package/ui/forge_ui/projects.py +571 -0
  66. package/ui/forge_ui/reader.py +48 -8
  67. package/ui/forge_ui/static/app.js +99 -21
  68. package/ui/forge_ui/static/cloudui.js +6 -2
  69. package/ui/forge_ui/static/convo.js +1 -1
  70. package/ui/forge_ui/static/diffview.js +2 -2
  71. package/ui/forge_ui/static/files.js +1 -1
  72. package/ui/forge_ui/static/index.html +5 -1
  73. package/ui/forge_ui/static/leaderboard.js +5 -1
  74. package/ui/forge_ui/static/modelstats.js +25 -1
  75. package/ui/forge_ui/static/panel.js +47 -4
  76. package/ui/forge_ui/static/projectsview.js +372 -0
  77. package/ui/forge_ui/static/settings.js +924 -29
  78. package/ui/forge_ui/static/style.css +116 -3
  79. package/ui/forge_ui/static/uikit.js +94 -1
  80. package/ui/forge_ui/static/worktreesview.js +250 -0
  81. package/ui/forge_ui/worktrees.py +570 -0
@@ -242,6 +242,7 @@ label { cursor: pointer; }
242
242
  .brand { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink); margin-right: var(--s-2); }
243
243
  .brand-plate { font-family: var(--font-plate); font-weight: 700; font-size: 1.15rem; letter-spacing: .08em; text-transform: uppercase; padding: 3px 9px 1px; border-radius: 4px; background: var(--plate); color: var(--plate-ink); line-height: 1.2; }
244
244
  .brand-sub { font-family: var(--font-plate); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-size: .857rem; }
245
+ .brand-version { color: var(--muted); font-size: var(--t-xs); font-variant-numeric: tabular-nums; }
245
246
  .desk-nav { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--rule-2); border-radius: var(--r-key); background: var(--module-2); }
246
247
  .top-link { display: inline-flex; align-items: center; gap: 7px; min-height: 28px; padding: 0 10px; border-radius: var(--r-small); text-decoration: none; color: var(--ink-2);
247
248
  font-family: var(--font-plate); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: .929rem; transition: background-color var(--relay), color var(--relay); }
@@ -336,7 +337,7 @@ body.no-tasks .tasks-module { display: none; }
336
337
  body[data-shell=workbench].no-tasks .run-view { grid-template-rows: auto minmax(0, 1fr) auto 0; }
337
338
  body[data-shell=immersive] .sidebar { position: absolute; z-index: 4; left: var(--gap); top: var(--gap); bottom: var(--gap); width: var(--runs-w); box-shadow: var(--ply-1); }
338
339
  body[data-shell=immersive][data-runs=closed] .sidebar { display: none; }
339
- body[data-shell=immersive]:is([data-view=models], [data-view=findings], [data-view=settings], [data-view=waiting], [data-view=loading], [data-view=first-run]) #main { left: calc(var(--L) - var(--gap)); }
340
+ body[data-shell=immersive]:is([data-view=models], [data-view=findings], [data-view=settings], [data-view=worktrees], [data-view=projects], [data-view=waiting], [data-view=loading], [data-view=first-run]) #main { left: calc(var(--L) - var(--gap)); }
340
341
  body[data-shell=immersive] .stage-row, body[data-shell=immersive] .stage-col { position: absolute; inset: 0; }
341
342
  body[data-shell=immersive] .stage-col .stage-slot { position: absolute; inset: 0; }
342
343
  body[data-shell=immersive] .insp-module { position: absolute; z-index: 3; right: var(--gap); top: var(--gap); bottom: var(--gap); width: var(--insp-w); box-shadow: var(--ply-1); }
@@ -391,7 +392,7 @@ body[data-shell=workbench] .map-cards-host { overflow: auto; }
391
392
  body[data-shell=workbench] .map-cards { padding: var(--s-4); }
392
393
 
393
394
  /* content views: the leaderboard and the waiting pages */
394
- body:is([data-view=models], [data-view=findings], [data-view=settings], [data-view=waiting], [data-view=loading], [data-view=first-run]) #main { padding: var(--s-6) var(--s-6) var(--s-8); }
395
+ body:is([data-view=models], [data-view=findings], [data-view=settings], [data-view=worktrees], [data-view=projects], [data-view=waiting], [data-view=loading], [data-view=first-run]) #main { padding: var(--s-6) var(--s-6) var(--s-8); }
395
396
 
396
397
  /* ---------- the stage: the panel the run is inlaid on ---------- */
397
398
  .stage-slot { position: relative; background: var(--stage-bg); }
@@ -1209,7 +1210,11 @@ dialog.export-dialog h2 { margin-bottom: var(--s-2); }
1209
1210
  html, body { height: auto; }
1210
1211
  body { overflow: auto; min-height: 100%; }
1211
1212
  .topbar { flex-wrap: wrap; gap: var(--s-2); padding: var(--s-2) var(--s-3); }
1212
- .brand-sub, .top-search kbd, .top-search-label span { display: none; }
1213
+ /* seven views: the nav takes its own row and scrolls sideways rather than widening the page */
1214
+ .desk-nav { order: 3; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
1215
+ .desk-nav::-webkit-scrollbar { display: none; }
1216
+ .desk-nav .top-link { flex: none; }
1217
+ .brand-sub, .brand-version, .top-search kbd, .top-search-label span { display: none; }
1213
1218
  .top-search { min-width: 0; margin-left: auto; }
1214
1219
  .desk-tools { width: 100%; flex-wrap: wrap; }
1215
1220
  .desk-tools .shell-switch { display: none; }
@@ -1296,6 +1301,62 @@ dialog.fnd-dialog::backdrop { background: light-dark(rgb(17 22 19 / .35), rgb(0
1296
1301
  .fnd-created li { display: flex; align-items: flex-start; gap: 7px; overflow-wrap: anywhere; }
1297
1302
  .findings-link .findings-count:not(:empty) { font-family: var(--mono); }
1298
1303
 
1304
+ /* ---------- worktrees (#/worktrees) ---------- */
1305
+ .worktrees-view { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-3); max-width: 1600px; }
1306
+ .wt-table { min-width: 0; overflow-x: auto; }
1307
+ .wt-head { display: flex; align-items: baseline; gap: var(--s-4); flex-wrap: wrap; }
1308
+ .wt-stamp { font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
1309
+ .wt-lede, .wt-totals, .wt-run-note { margin: 0; }
1310
+ .wt-totals { font-variant-numeric: tabular-nums; }
1311
+ .wt-notes p { margin: 0; font-size: var(--t-sm); }
1312
+ .wt-filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
1313
+ .wt-status { white-space: nowrap; }
1314
+ .wt-derived { margin-left: 4px; font-size: var(--t-xs); }
1315
+ .wt-cmds { display: grid; gap: 4px; width: 30em; }
1316
+ .wt-cmd { display: flex; min-width: 0; align-items: flex-start; gap: var(--s-2); padding: 3px var(--s-2); border: 1px solid var(--rule); border-radius: var(--r-key); background: var(--module-2); }
1317
+ .wt-cmd code { min-width: 0; flex: 1; overflow-x: auto; white-space: pre; font-size: var(--t-xs); }
1318
+ .wt-copy { flex: none; }
1319
+ .wt-note { margin: 0; font-size: var(--t-xs); white-space: normal; }
1320
+ .wt-commit { display: inline-block; max-width: 28em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1321
+ table.wt-grid { width: max-content; min-width: 100%; }
1322
+ .wt-grid td { vertical-align: top; white-space: nowrap; max-width: 16em; overflow: hidden; text-overflow: ellipsis; }
1323
+ .wt-grid td.wt-command-col { white-space: normal; max-width: none; overflow: visible; }
1324
+ .wt-row-removed { color: var(--muted); }
1325
+ .wt-groups summary { cursor: pointer; }
1326
+ .wt-group { display: grid; grid-template-columns: minmax(8em, max-content) 1fr; align-items: center; gap: var(--s-3); margin: var(--s-2) 0; }
1327
+ .wt-copy:focus-visible, .wt-cmd code:focus-visible, .wt-groups summary:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }
1328
+
1329
+ /* ---------- projects (#/projects) ---------- */
1330
+ .projects-view { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s-3); max-width: 1600px; }
1331
+ .prj-head { display: flex; align-items: baseline; gap: var(--s-4); flex-wrap: wrap; }
1332
+ .prj-links { display: flex; gap: var(--s-3); font-size: var(--t-sm); }
1333
+ .prj-lede, .prj-root, .prj-count, .prj-empty, .prj-differs { margin: 0; }
1334
+ .prj-root { overflow-wrap: anywhere; font-size: var(--t-sm); }
1335
+ .prj-tabs { justify-self: start; }
1336
+ .prj-tabs { display: inline-flex; gap: 2px; }
1337
+ .prj-tabs a { padding: 6px 14px; text-decoration: none; color: inherit; border-radius: var(--r-key); }
1338
+ .prj-tabs a[aria-current=page] { background: var(--module); box-shadow: var(--ply-1, none); }
1339
+ .prj-tabs a[aria-current=page] { font-weight: 600; }
1340
+ .prj-notes p { margin: 0; font-size: var(--t-sm); }
1341
+ .prj-filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
1342
+ .prj-table { min-width: 0; overflow-x: auto; }
1343
+ .prj-name { display: inline-flex; align-items: center; gap: 6px; }
1344
+ .prj-count-chip { margin-left: 6px; font-variant-numeric: tabular-nums; }
1345
+ .prj-occ { margin: var(--s-2) 0 0; padding-left: 1.2em; font-size: var(--t-xs); }
1346
+ .prj-given, .prj-learnings { display: grid; gap: var(--s-2); }
1347
+ .prj-given h2, .prj-learnings h2, .prj-section h3 { margin: 0; }
1348
+ .prj-lines { margin: 4px 0 0; padding-left: 1.2em; }
1349
+ .prj-lines li, .prj-learning { overflow-wrap: anywhere; }
1350
+ .prj-learnings td, .prj-findings td { vertical-align: top; }
1351
+ .prj-table td.prj-cut, .prj-body td.prj-cut { white-space: nowrap; max-width: 18em; overflow: hidden; text-overflow: ellipsis; }
1352
+ .prj-body td { white-space: nowrap; }
1353
+ .prj-findings td { white-space: nowrap; }
1354
+ .prj-findings td.prj-wide { white-space: normal; min-width: 26em; }
1355
+ .prj-summary { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; max-width: 46em; }
1356
+ .prj-learning { display: inline-block; max-width: 48em; }
1357
+ .prj-where a, .project-link { white-space: nowrap; }
1358
+ .prj-tabs a:focus-visible, .prj-links a:focus-visible, .project-link:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }
1359
+
1299
1360
  /* ---------- delete a run ---------- */
1300
1361
  .del-gap { align-self: stretch; width: 1px; margin: 0 6px; background: var(--rule-2); }
1301
1362
  button.del-key { border-color: var(--lamp-red); color: var(--lamp-red); }
@@ -1417,3 +1478,55 @@ button.set-remove:focus-visible { outline: 2px solid var(--lamp-red); outline-of
1417
1478
  .set-gate select { min-width: 9em; max-width: 100%; }
1418
1479
  .set-gate input[type=text] { width: 14em; max-width: 100%; }
1419
1480
  .set-gate-skip { font-family: var(--mono); font-size: var(--t-xs); color: var(--warn-ink); }
1481
+ /* profiles: the list is the selector; the detail is the body, then the writes */
1482
+ .set-profiles { display: grid; gap: var(--s-1); width: 100%; margin: 0; padding: 0; list-style: none; }
1483
+ .set-profiles li { margin: 0; min-width: 0; }
1484
+ button.set-profile { justify-content: flex-start; align-items: baseline; gap: var(--s-2); width: 100%; min-height: 40px; padding: 6px 10px;
1485
+ text-align: left; white-space: normal;
1486
+ font-family: inherit; font-weight: 400; font-size: inherit; letter-spacing: normal; text-transform: none; line-height: 1.3; }
1487
+ button.set-profile:active:not(:disabled) { scale: 1; }
1488
+ button.set-profile[aria-pressed=true] { border-color: var(--route); background: var(--wash); }
1489
+ .set-profile-name { font-family: var(--mono); font-weight: 650; min-width: 0; overflow-wrap: anywhere; }
1490
+ .set-profile-meta { color: var(--muted); font-size: var(--t-sm); }
1491
+ .set-profile-summary { display: grid; gap: var(--s-3); width: 100%; font-variant-numeric: tabular-nums; }
1492
+ .set-profile-summary .plate { margin: 0; }
1493
+ .set-kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px var(--s-4); margin: 0; width: 100%; }
1494
+ .set-kv dt, .set-kv dd { margin: 0; overflow-wrap: anywhere; }
1495
+ .set-kv dt { color: var(--ink-2); }
1496
+ .set-summary-line { margin: 0; overflow-wrap: anywhere; }
1497
+ .set-profile-form { display: flex; flex-wrap: wrap; align-items: end; gap: var(--s-2) var(--s-3); width: 100%; }
1498
+ .set-profile-editor { display: grid; gap: var(--s-2); width: 100%; }
1499
+ .set-profile-editor > * { margin-block: 0; }
1500
+ .set-reasons { margin: 0; padding-left: 1.2em; color: var(--warn-ink); font-size: var(--t-sm); }
1501
+ .set-reasons li { overflow-wrap: anywhere; }
1502
+ button.set-profile:focus-visible, .set-profile-form select:focus-visible, .set-profile-form input:focus-visible,
1503
+ .set-profile-editor textarea:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }
1504
+
1505
+ /* Decision models: what a gate does, and the setup guide */
1506
+ .set-gate-summary { font-size: var(--t-sm); }
1507
+ .set-gate-more > summary { cursor: pointer; font-size: var(--t-sm); }
1508
+ .set-gate-more > summary:focus-visible, .set-guide-open:focus-visible, .set-guide-close:focus-visible, .set-guide-copy:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }
1509
+ .set-gate-more dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s-1) var(--s-3); margin: var(--s-2) 0 0; font-size: var(--t-sm); }
1510
+ .set-gate-more dt { font-weight: 600; }
1511
+ .set-gate-more dd { margin: 0; text-wrap: pretty; }
1512
+ .set-guide-open { justify-self: start; }
1513
+ dialog.set-guide { width: min(720px, calc(100vw - 24px)); max-height: 86vh; overflow: auto; padding: 18px 20px; border: 1px solid var(--rule); border-radius: var(--r-module); background: var(--module); color: var(--ink); box-shadow: var(--ply-2); }
1514
+ dialog.set-guide::backdrop { background: light-dark(rgb(17 22 19 / .35), rgb(0 0 0 / .55)); }
1515
+ .set-guide-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3); }
1516
+ .set-guide-head h2 { margin: 0; text-wrap: balance; }
1517
+ .set-guide h3 { margin: var(--s-4) 0 var(--s-2); font-size: var(--t-sm); }
1518
+ .set-guide p { text-wrap: pretty; }
1519
+ .set-guide-steps { display: grid; gap: var(--s-4); margin: var(--s-3) 0 0; padding-inline-start: 1.4em; }
1520
+ .set-guide-steps p { margin: var(--s-1) 0 var(--s-2); font-size: var(--t-sm); }
1521
+ .set-guide-command { display: grid; gap: 2px; margin-top: var(--s-2); font-size: var(--t-xs); }
1522
+ .set-guide-row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-2); padding: var(--s-2); border: 1px solid var(--rule); border-radius: var(--r-key); background: var(--module-2); }
1523
+ .set-guide-row code { min-width: 0; flex: 1; overflow-x: auto; white-space: pre; }
1524
+ .set-guide-copy { flex: none; }
1525
+
1526
+ /* Commits adopted from outside a run */
1527
+ .adoptions { display: grid; gap: var(--s-2); margin: 0; padding: 0; list-style: none; font-size: var(--t-sm); }
1528
+ .adoptions p { margin: var(--s-1) 0 0; text-wrap: pretty; }
1529
+
1530
+ /* A held redraw that has lasted (#115) */
1531
+ .live-held { position: fixed; right: var(--s-4); bottom: var(--s-4); z-index: 30; display: flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); border: 1px solid var(--rule); border-radius: var(--r-key); background: var(--module); color: var(--ink); box-shadow: var(--ply-2); font-size: var(--t-sm); }
1532
+ .live-held[hidden] { display: none; }
@@ -6,6 +6,9 @@
6
6
  get(path) / post(path, body) Promise<{ok, status, data, error, detail, result}>; post sends the token and never retries
7
7
  outcome(host, res, okText) an inline result line (a lamp and a sentence) in an aria-live region
8
8
  confirmInline(host, text, {danger}) Promise<bool>: an inline Confirm / Cancel strip, Escape cancels
9
+ guard(region, draw, later) draw now, or, while the user is using the region, hold the latest (`later`, else draw) (#115)
10
+ forget(region) drop a held draw: the view it would draw has gone
11
+ keepOpen(region, draw) draw, with each details[data-keep] as open as it was
9
12
  The write API is described in ui/docs/api.md, "Controls (write endpoints)". All API values enter the DOM as text. */
10
13
  (function (root, factory) {
11
14
  'use strict';
@@ -154,7 +157,97 @@
154
157
  });
155
158
  }
156
159
 
157
- return { el, token, controlsEnabled, get, post, outcome, confirmInline, requestInit, mapResponse, outcomeText };
160
+ /* A live refresh never cancels what the user is doing (#115). Replacing a node cancels a press on it, a selection in
161
+ it and an open native list, so a redraw waits while a pointer is down in the region, a selection touches it or a
162
+ <select> in it has focus, and the latest one runs when that ends. What the user just did draws at once: a click
163
+ on a task, or a change of the filter that has the focus, is the thing they asked for. A selection left in place would
164
+ hold a region for ever, so a held redraw that lasts says so and offers to run. */
165
+ const doc = env && env.document;
166
+ const HOLD_NOTE_MS = 5000;
167
+ const held = new Map(); // region -> its latest draw
168
+ let pressed = null, userTurn = 0, note = null, noteTimer = null;
169
+
170
+ function selectionTouches(region) {
171
+ const s = env.getSelection && env.getSelection();
172
+ if (!s || s.isCollapsed || !s.rangeCount) return false;
173
+ try { return s.getRangeAt(0).intersectsNode(region); } catch (_) { return false; }
174
+ }
175
+ function inUse(region) {
176
+ if (!doc) return false;
177
+ if (pressed && region.contains(pressed)) return true;
178
+ const active = doc.activeElement;
179
+ if (active && active.tagName === 'SELECT' && region.contains(active)) return true;
180
+ return selectionTouches(region);
181
+ }
182
+ function syncNote() {
183
+ if (!doc) return;
184
+ if (!held.size) {
185
+ clearTimeout(noteTimer); noteTimer = null;
186
+ if (note) note.hidden = true;
187
+ return;
188
+ }
189
+ if (noteTimer || (note && !note.hidden)) return;
190
+ noteTimer = setTimeout(() => {
191
+ noteTimer = null;
192
+ if (!held.size) return;
193
+ if (!note) {
194
+ note = el('div', undefined, 'live-held'); note.id = 'live-held'; note.setAttribute('role', 'status');
195
+ const go = el('button', 'Show it'); go.type = 'button';
196
+ go.addEventListener('click', () => {
197
+ const s = env.getSelection && env.getSelection();
198
+ if (s) s.removeAllRanges();
199
+ if (doc.activeElement && doc.activeElement.tagName === 'SELECT') doc.activeElement.blur();
200
+ flushHeld();
201
+ });
202
+ note.append(el('span', 'Newer data is waiting while you use this.'), go);
203
+ doc.body.append(note);
204
+ }
205
+ note.hidden = false;
206
+ }, HOLD_NOTE_MS);
207
+ }
208
+ function flushHeld() {
209
+ for (const [region, draw] of [...held]) {
210
+ if (!region.isConnected) held.delete(region);
211
+ else if (!inUse(region)) {
212
+ held.delete(region);
213
+ // One draw that throws must not strand the others behind it; it is still reported.
214
+ try { draw(); } catch (error) { setTimeout(() => { throw error; }, 0); }
215
+ }
216
+ }
217
+ syncNote();
218
+ }
219
+ function guard(region, draw, later) {
220
+ if (userTurn || !inUse(region)) {
221
+ held.delete(region);
222
+ draw();
223
+ syncNote();
224
+ return true;
225
+ }
226
+ held.set(region, later || draw);
227
+ syncNote();
228
+ return false;
229
+ }
230
+ function forget(region) { if (held.delete(region)) syncNote(); }
231
+ function keepOpen(region, draw) {
232
+ const open = new Map(Array.from(region.querySelectorAll('details[data-keep]'), n => [n.dataset.keep, n.open]));
233
+ draw();
234
+ for (const node of region.querySelectorAll('details[data-keep]')) if (open.has(node.dataset.keep)) node.open = open.get(node.dataset.keep);
235
+ }
236
+ if (doc && env.addEventListener) {
237
+ // The click follows the release in the same task, so the redraw waits for the next one.
238
+ const released = () => { pressed = null; setTimeout(flushHeld, 0); };
239
+ env.addEventListener('pointerdown', e => { pressed = e.target; }, true);
240
+ env.addEventListener('pointerup', released, true);
241
+ env.addEventListener('pointercancel', released, true);
242
+ env.addEventListener('blur', released);
243
+ doc.addEventListener('selectionchange', () => { if (held.size) flushHeld(); });
244
+ doc.addEventListener('focusout', () => { if (held.size) setTimeout(flushHeld, 0); });
245
+ for (const type of ['click', 'change', 'input', 'keydown', 'submit', 'hashchange', 'popstate']) {
246
+ env.addEventListener(type, () => { userTurn += 1; setTimeout(() => { userTurn -= 1; }, 0); }, true);
247
+ }
248
+ }
249
+
250
+ return { el, token, controlsEnabled, get, post, outcome, confirmInline, requestInit, mapResponse, outcomeText, guard, forget, keepOpen };
158
251
  }
159
252
 
160
253
  return { create, requestInit, mapResponse, outcomeText, TOKEN_HEADER };
@@ -0,0 +1,250 @@
1
+ /* forge-ui Worktrees screen (#125): every worktree forge created, in any repository, with its state and the command
2
+ that removes it safely (window.ForgeWorktrees, and a CommonJS module under node:test). Route #/worktrees, optionally
3
+ narrowed to one repository (#/worktrees/repo/<root>) or one run (#/worktrees/runs/<key>).
4
+ The commands come from the server, are only ever copied, and never include --force: the page runs nothing, so it
5
+ works with --read-only too. Paths, branches and commit subjects enter the page as text.
6
+ The pure helpers (filters, totals, sizes) are tested in ui/tests/js/worktreesview.test.js.
7
+ ctx = { filter?: {repo, run}, runHref(key), tablePrefs?(id), saveTablePrefs?(id, prefs) }. */
8
+ (function (root, factory) {
9
+ 'use strict';
10
+ const api = factory(root);
11
+ if (typeof module === 'object' && module.exports) module.exports = api;
12
+ else root.ForgeWorktrees = api;
13
+ })(typeof self !== 'undefined' ? self : this, function (root) {
14
+ 'use strict';
15
+
16
+ const list = v => Array.isArray(v) ? v : [];
17
+ const POLL_MS = 60000, SIZE_POLL_MS = 3000;
18
+ const STATUSES = ['in_use', 'dirty', 'locked', 'needed', 'failed', 'finished', 'missing', 'foreign', 'unknown', 'removed'];
19
+ const LABEL = { in_use: 'in use', dirty: 'uncommitted changes', locked: 'locked', needed: 'needed by the run', failed: 'failed task',
20
+ finished: 'finished', missing: 'missing on disk', foreign: "not forge's", unknown: 'unknown to git', removed: 'removed' };
21
+ const LAMP = { in_use: 'st-running', dirty: 'fnd-amber', locked: 'fnd-amber', needed: 'st-pending', failed: 'st-fail', finished: 'st-merged',
22
+ missing: 'st-unknown', foreign: 'lamp-off', unknown: 'st-unknown', removed: 'lamp-off' };
23
+ const KINDS = ['task', 'integration', 'candidate', 'attribute'];
24
+
25
+ /* ---------- pure ---------- */
26
+ // filter = { repo: '' | root, run: '' | key, status: 'all' | 'disk' (everything not removed) | one of STATUSES, kind: 'all' | KINDS | 'none' }
27
+ function filterRows(rows, filter) {
28
+ const f = filter || {}, status = f.status || 'all', kind = f.kind || 'all';
29
+ return list(rows).filter(r => (!f.repo || r.repo === f.repo) && (!f.run || r.run === f.run)
30
+ && (status === 'all' || (status === 'disk' ? r.status !== 'removed' : r.status === status))
31
+ && (kind === 'all' || (kind === 'none' ? !r.kind : r.kind === kind)));
32
+ }
33
+ // {count, onDisk, bytes, pending} of the rows shown: bytes counts only the sizes known so far
34
+ function totals(rows) {
35
+ let onDisk = 0, bytes = 0, pending = 0;
36
+ for (const r of list(rows)) {
37
+ if (r.status === 'removed' || r.status === 'missing') continue;
38
+ onDisk += 1;
39
+ if (Number.isFinite(r.size)) bytes += r.size; else pending += 1;
40
+ }
41
+ return { count: list(rows).length, onDisk, bytes, pending };
42
+ }
43
+ function humanBytes(n) {
44
+ if (!Number.isFinite(n) || n < 0) return '—';
45
+ const units = ['B', 'KB', 'MB', 'GB', 'TB'];
46
+ let i = 0, v = n;
47
+ while (v >= 1024 && i < units.length - 1) { v /= 1024; i += 1; }
48
+ return (i === 0 ? String(v) : v.toFixed(v < 10 ? 1 : 0)) + ' ' + units[i];
49
+ }
50
+ // the part of a worktree path from `.forge-worktrees` on: the folder above it is the repository's, shown beside it
51
+ const shortPath = p => { const s = String(p || ''), i = s.lastIndexOf('/.forge-worktrees/'); return i >= 0 ? s.slice(i + 1) : s || '—'; };
52
+ const repoName = p => typeof p === 'string' && p ? p.replace(/\/+$/, '').split('/').pop() : '—';
53
+ const label = status => LABEL[status] || status || '—';
54
+
55
+ /* ---------- DOM ---------- */
56
+ function render(host, ctx) {
57
+ const UI = root.ForgeUI;
58
+ const el = (tag, text, cls) => UI.el(tag, text, cls);
59
+ const start = ctx.filter || {};
60
+ const s = { data: null, error: null, filter: { repo: start.repo || '', run: start.run || '', status: 'all', kind: 'all' }, timer: null, seq: 0, loading: false };
61
+
62
+ const head = el('div', undefined, 'wt-head');
63
+ const refreshKey = el('button', 'Read again'); refreshKey.type = 'button';
64
+ refreshKey.title = 'Run git status and the other reads again now, instead of waiting for the next read';
65
+ refreshKey.addEventListener('click', () => load(true));
66
+ const stamp = el('span', '', 'muted wt-stamp');
67
+ head.append(el('h1', 'Worktrees', 'module-title'), refreshKey, stamp);
68
+ const lede = el('p', 'Every worktree forge created, in any repository it knows, with what state it is in and the command that removes it safely. Commands are only copied: this page runs nothing.', 'muted wt-lede');
69
+ const notes = el('div', undefined, 'wt-notes muted');
70
+ const sums = el('p', undefined, 'wt-totals'); sums.setAttribute('role', 'status');
71
+ const filters = el('div', undefined, 'wt-filters');
72
+ const fields = {};
73
+ const field = (name, text) => {
74
+ const l = el('label', undefined, 'fnd-field'), sel = el('select');
75
+ sel.dataset.filter = name;
76
+ sel.addEventListener('change', () => { s.filter[name] = sel.value; draw(); });
77
+ l.append(el('span', text, 'plate'), sel);
78
+ fields[name] = sel; filters.append(l);
79
+ };
80
+ field('repo', 'Repository'); field('status', 'Status'); field('kind', 'Kind');
81
+ const runNote = el('p', undefined, 'wt-run-note'); runNote.hidden = true;
82
+ const tableHost = el('div', undefined, 'wt-table');
83
+ const groups = el('section', undefined, 'wt-runs');
84
+ host.replaceChildren(head, lede, notes, sums, filters, runNote, tableHost, groups);
85
+
86
+ function options(sel, items, value) {
87
+ const want = items.map(([v, t]) => v + '\u0000' + t).join('\u0001');
88
+ if (sel.dataset.items !== want) {
89
+ sel.replaceChildren(...items.map(([v, t]) => { const o = el('option', t); o.value = v; return o; }));
90
+ sel.dataset.items = want;
91
+ }
92
+ sel.value = items.some(([v]) => v === value) ? value : items[0][0];
93
+ }
94
+ function syncFilters() {
95
+ const rows = list(s.data && s.data.rows);
96
+ const repos = Array.from(new Set(rows.map(r => r.repo).filter(Boolean).concat(s.filter.repo ? [s.filter.repo] : []))).sort();
97
+ options(fields.repo, [['', 'all']].concat(repos.map(r => [r, repoName(r)])), s.filter.repo);
98
+ const counts = (s.data && s.data.totals && s.data.totals.by_status) || {};
99
+ options(fields.status, [['all', 'all'], ['disk', 'on disk']].concat(STATUSES.map(x => [x, `${label(x)} (${counts[x] || 0})`])), s.filter.status);
100
+ options(fields.kind, [['all', 'all']].concat(KINDS.map(k => [k, k]), [['none', 'none']]), s.filter.kind);
101
+ if (s.filter.run) {
102
+ const group = list(s.data && s.data.runs).find(g => g.key === s.filter.run);
103
+ runNote.replaceChildren(el('span', 'Only the worktrees of run '), el('strong', group ? group.run_id : s.filter.run, 'mono'), el('span', '. '));
104
+ const all = el('a', 'Show every run'); all.href = '#/worktrees';
105
+ runNote.append(all);
106
+ runNote.hidden = false;
107
+ } else runNote.hidden = true;
108
+ }
109
+ function copyButton(command) {
110
+ const b = el('button', 'Copy', 'wt-copy'); b.type = 'button';
111
+ b.setAttribute('aria-label', 'Copy: ' + command);
112
+ b.addEventListener('click', async () => {
113
+ try { await navigator.clipboard.writeText(command); b.textContent = 'Copied'; }
114
+ catch (_) { b.textContent = 'Copy failed: select it'; }
115
+ setTimeout(() => { b.textContent = 'Copy'; }, 2500);
116
+ });
117
+ return b;
118
+ }
119
+ function commandBox(c) {
120
+ const box = el('div', undefined, 'wt-cmd');
121
+ const code = el('code', c.command, 'mono'); code.tabIndex = 0; code.title = c.label;
122
+ box.append(code, copyButton(c.command));
123
+ return box;
124
+ }
125
+ const when = t => Number.isFinite(t) ? new Date(t * 1000).toLocaleString() : '—';
126
+ const statusCell = r => {
127
+ const box = el('span', undefined, 'fnd-status wt-status wt-' + r.status);
128
+ box.append(el('i', undefined, 'lamp ' + (LAMP[r.status] || 'lamp-off')), el('span', label(r.status)));
129
+ if (r.derived) box.append(el('span', 'derived', 'chip wt-derived'));
130
+ if (r.note) box.title = r.note;
131
+ return box;
132
+ };
133
+ const commandCell = r => {
134
+ const box = el('div', undefined, 'wt-cmds');
135
+ for (const c of list(r.commands)) box.append(commandBox(c));
136
+ if (r.note) box.append(el('p', r.note, 'muted wt-note'));
137
+ return box;
138
+ };
139
+ const runCell = r => {
140
+ if (!r.run_id) return '—';
141
+ if (!r.run) return el('span', r.run_id, 'mono');
142
+ const a = el('a', r.run_id, 'mono'); a.href = ctx.runHref ? ctx.runHref(r.run) : '#/runs/' + encodeURIComponent(r.run);
143
+ return a;
144
+ };
145
+ const commitCell = r => {
146
+ if (!r.commit) return r.head ? el('span', String(r.head).slice(0, 12), 'mono') : '—';
147
+ const box = el('span', undefined, 'wt-commit');
148
+ box.title = `${r.commit.sha}\n${when(r.commit.time)}`;
149
+ box.append(el('span', String(r.commit.sha).slice(0, 7), 'mono'), el('span', ' ' + r.commit.subject));
150
+ return box;
151
+ };
152
+ const pathCell = r => { const n = el('span', shortPath(r.path), 'mono'); n.title = r.path; return n; };
153
+ const columns = [
154
+ { id: 'status', label: 'Status', value: r => STATUSES.indexOf(r.status), cell: statusCell },
155
+ { id: 'run', label: 'Run', value: r => r.run_id, cell: runCell },
156
+ { id: 'task', label: 'Task', value: r => r.task, mono: true, cell: r => r.task || (r.kind && r.kind !== 'task' ? r.kind : '—') },
157
+ { id: 'command', label: 'Command', sortable: false, cls: 'wt-command-col', cell: commandCell },
158
+ { id: 'repo', label: 'Repository', value: r => repoName(r.repo), cell: r => { const n = el('span', repoName(r.repo)); if (r.repo) n.title = r.repo; return n; } },
159
+ { id: 'branch', label: 'Branch', value: r => r.branch, mono: true, cell: r => r.branch || 'detached' },
160
+ { id: 'merged', label: 'Merged', title: 'whether the branch is merged into the repository\'s checked-out branch', value: r => r.merged === null || r.merged === undefined ? null : r.merged ? 1 : 0,
161
+ cell: r => r.merged === true ? 'yes' : r.merged === false ? 'no' : '—' },
162
+ { id: 'commit', label: 'Last commit', value: r => r.commit ? r.commit.time : null, cell: commitCell },
163
+ { id: 'size', label: 'Size', value: r => r.size, cell: r => r.status === 'removed' || r.status === 'missing' ? '—' : Number.isFinite(r.size) ? humanBytes(r.size) : 'measuring…' },
164
+ { id: 'removed', label: 'Removed', value: r => r.removed, cell: r => r.status !== 'removed' ? '—' : Number.isFinite(r.removed) ? when(r.removed) : 'date unknown' },
165
+ { id: 'created', label: 'Created', value: r => r.created, cell: r => when(r.created), hidden: true },
166
+ { id: 'path', label: 'Path', value: r => r.path, cell: pathCell, hidden: true },
167
+ { id: 'kind', label: 'Kind', value: r => r.kind, cell: r => r.kind || '—', hidden: true },
168
+ ];
169
+ function drawNotes() {
170
+ const d = s.data, out = [];
171
+ if (s.error) out.push(el('p', `Could not read the worktrees (${s.error}).`, 'warn'));
172
+ if (d) {
173
+ for (const n of list(d.notes)) out.push(el('p', String(n)));
174
+ if (d.dataset && d.dataset.enabled) {
175
+ out.push(el('p', Number.isFinite(d.dataset.since)
176
+ ? `forge has recorded every worktree it adds or removes since ${when(d.dataset.since)}; removed ones from before then are derived from run dirs and the dataset, without dates.`
177
+ : 'forge records the worktrees it adds and removes from this release on; removed ones until then are derived from run dirs and the dataset, without dates.'));
178
+ }
179
+ }
180
+ notes.replaceChildren(...out);
181
+ }
182
+ function drawTotals(rows) {
183
+ const t = totals(rows);
184
+ sums.replaceChildren(el('strong', `${t.onDisk} on disk`), el('span', ` · ${humanBytes(t.bytes)}${t.pending ? ` so far, ${t.pending} still being measured` : ''} · ${t.count - t.onDisk} removed or missing · ${t.count} listed`));
185
+ }
186
+ function drawGroups() {
187
+ const items = list(s.data && s.data.runs).filter(g => g.command && (!s.filter.run || g.key === s.filter.run) && (!s.filter.repo || g.repo === s.filter.repo));
188
+ if (!items.length) { groups.replaceChildren(); return; }
189
+ const d = el('details', undefined, 'wt-groups'); d.dataset.keep = 'wt-groups';
190
+ d.append(el('summary', `Whole runs (${items.length})`));
191
+ d.append(el('p', 'forge runs rm removes a run\'s clean worktrees and its branches, and deletes the run directory as well, after archiving it into the dataset. This is a dry run: it changes nothing and says what a real one would do.', 'muted'));
192
+ for (const g of items) {
193
+ const row = el('div', undefined, 'wt-group');
194
+ const a = el('a', g.run_id, 'mono'); a.href = ctx.runHref ? ctx.runHref(g.key) : '#/runs/' + encodeURIComponent(g.key);
195
+ row.append(a, commandBox({ label: 'dry run of deleting the run directory and its worktrees', command: g.command }));
196
+ d.append(row);
197
+ }
198
+ groups.replaceChildren(d);
199
+ }
200
+ function drawNow() {
201
+ syncFilters(); drawNotes();
202
+ const d = s.data;
203
+ if (!d) { tableHost.replaceChildren(el('p', s.error ? '' : 'Reading every repository\'s worktrees… the first read runs git status in each, so it can take a few seconds.', 'muted')); sums.replaceChildren(); return; }
204
+ const rows = filterRows(d.rows, s.filter);
205
+ drawTotals(rows);
206
+ UI.keepOpen(groups, drawGroups);
207
+ if (!rows.length) { tableHost.replaceChildren(el('p', list(d.rows).length ? `No worktrees match these filters (${list(d.rows).length} hidden).` : 'forge has no worktrees on record.', 'muted')); return; }
208
+ const id = 'worktrees';
209
+ tableHost.replaceChildren();
210
+ root.ForgeTable.render(tableHost, { id, label: 'Worktrees', columns, rows, className: 'wt-grid', rowClass: r => 'wt-row-' + r.status,
211
+ // a cell cut short by its width says the whole of itself on hover
212
+ onRow: (_row, tr) => { for (const td of tr.children) if (!td.classList.contains('wt-command-col') && !td.title) td.title = td.textContent; },
213
+ prefs: ctx.tablePrefs ? ctx.tablePrefs(id) : null, savePrefs: p => ctx.saveTablePrefs && ctx.saveTablePrefs(id, p) });
214
+ }
215
+ // A redraw never pulls a command out from under someone selecting or copying it (#115).
216
+ const draw = () => { if (UI.guard) UI.guard(host, drawNow); else drawNow(); };
217
+
218
+ async function load(refresh) {
219
+ if (s.loading && !refresh) return;
220
+ const mine = ++s.seq;
221
+ s.loading = true; refreshKey.disabled = true;
222
+ if (refresh) stamp.textContent = 'reading…';
223
+ const res = await UI.get('/api/worktrees' + (refresh ? '?refresh=1' : ''));
224
+ if (mine !== s.seq) return;
225
+ s.loading = false; refreshKey.disabled = false;
226
+ if (res.ok) { s.data = res.data; s.error = null; stamp.textContent = 'read ' + when(res.data.computed); }
227
+ else { s.error = res.detail || res.error || 'no answer'; stamp.textContent = ''; }
228
+ draw();
229
+ schedule();
230
+ }
231
+ function schedule() {
232
+ clearTimeout(s.timer);
233
+ if (!host.isConnected) return; // the screen was left: no more reads
234
+ const pending = s.data && s.data.sizes_pending > 0;
235
+ s.timer = setTimeout(() => { if (host.isConnected && document.visibilityState === 'visible') load(false); else schedule(); }, pending ? SIZE_POLL_MS : POLL_MS);
236
+ }
237
+ drawNow();
238
+ load(false);
239
+ return {
240
+ setFilter(f) {
241
+ const repo = (f && f.repo) || '', run = (f && f.run) || '';
242
+ if (repo === s.filter.repo && run === s.filter.run) return; // the page's own refresh: nothing changed here
243
+ s.filter.repo = repo; s.filter.run = run; draw();
244
+ },
245
+ reload: () => load(true),
246
+ };
247
+ }
248
+
249
+ return { render, filterRows, totals, humanBytes, repoName, shortPath, label, STATUSES, LABEL };
250
+ });