@giamme/forge 0.15.0 → 0.17.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 (80) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/VERSION +1 -1
  3. package/docs/artifacts.md +1 -1
  4. package/docs/commands.md +14 -3
  5. package/docs/dataset.md +8 -0
  6. package/docs/forge-ui.md +14 -0
  7. package/docs/memory.md +22 -0
  8. package/docs/reviews.md +22 -1
  9. package/forge +11 -0
  10. package/package.json +1 -1
  11. package/references/dataset.md +129 -7
  12. package/references/decision-models.md +15 -2
  13. package/references/decompose.md +95 -13
  14. package/references/harnesses.md +4 -1
  15. package/references/planning.md +3 -2
  16. package/references/solo.md +5 -1
  17. package/references/ui.md +10 -1
  18. package/scripts/forge-artifact.sh +53 -0
  19. package/scripts/forge-contract.py +107 -9
  20. package/scripts/forge-control.py +0 -2
  21. package/scripts/forge-dispatch.sh +28 -12
  22. package/scripts/forge-fail-first.py +3 -1
  23. package/scripts/forge-guard.py +247 -8
  24. package/scripts/forge-issues.py +16 -3
  25. package/scripts/forge-ledger.py +3 -1
  26. package/scripts/forge-lib-adopt.sh +266 -0
  27. package/scripts/forge-lib-attribute.sh +10 -2
  28. package/scripts/forge-lib-plans.sh +16 -4
  29. package/scripts/forge-lib-review.sh +8 -2
  30. package/scripts/forge-lib-task.sh +19 -5
  31. package/scripts/forge-memory.sh +41 -4
  32. package/scripts/forge-metrics.sh +29 -0
  33. package/scripts/forge-parallel.sh +99 -14
  34. package/scripts/forge-plan-check.py +25 -2
  35. package/scripts/forge-planner.py +20 -6
  36. package/scripts/forge-route.py +16 -2
  37. package/scripts/forge-runs-rm.py +23 -7
  38. package/scripts/forge-runtime.py +25 -2
  39. package/scripts/forge-schedule.py +5 -2
  40. package/scripts/forge-shadow.py +30 -9
  41. package/scripts/forge-solo.sh +6 -0
  42. package/scripts/forge-sweep.py +25 -10
  43. package/scripts/forge_dataset/cli.py +99 -0
  44. package/scripts/forge_dataset/export.py +1 -0
  45. package/scripts/forge_dataset/facts.py +278 -0
  46. package/scripts/forge_dataset/harvest.py +27 -3
  47. package/scripts/forge_dataset/history.py +126 -0
  48. package/scripts/forge_dataset/outcomes.py +206 -58
  49. package/scripts/forge_dataset/pairs.py +174 -0
  50. package/scripts/forge_dataset/risk.py +108 -0
  51. package/scripts/forge_dataset/tiers.py +427 -0
  52. package/scripts/forge_dataset/worktrees.py +95 -0
  53. package/scripts/forge_decide/cli.py +23 -2
  54. package/scripts/forge_decide/labels.py +30 -6
  55. package/scripts/forge_decide/replay.py +10 -4
  56. package/scripts/forge_memory_list.py +153 -0
  57. package/scripts/forge_worktrees.py +88 -0
  58. package/ui/README.md +31 -0
  59. package/ui/docs/api.md +92 -6
  60. package/ui/forge_ui/__init__.py +14 -1
  61. package/ui/forge_ui/__main__.py +1 -1
  62. package/ui/forge_ui/control.py +77 -0
  63. package/ui/forge_ui/export.py +9 -2
  64. package/ui/forge_ui/findings.py +11 -2
  65. package/ui/forge_ui/projects.py +571 -0
  66. package/ui/forge_ui/reader.py +96 -9
  67. package/ui/forge_ui/server.py +8 -0
  68. package/ui/forge_ui/static/app.js +105 -22
  69. package/ui/forge_ui/static/cloudui.js +6 -2
  70. package/ui/forge_ui/static/convo.js +1 -1
  71. package/ui/forge_ui/static/diffview.js +9 -5
  72. package/ui/forge_ui/static/files.js +1 -1
  73. package/ui/forge_ui/static/index.html +5 -1
  74. package/ui/forge_ui/static/panel.js +69 -2
  75. package/ui/forge_ui/static/projectsview.js +372 -0
  76. package/ui/forge_ui/static/settings.js +136 -4
  77. package/ui/forge_ui/static/style.css +94 -3
  78. package/ui/forge_ui/static/uikit.js +94 -1
  79. package/ui/forge_ui/static/worktreesview.js +250 -0
  80. package/ui/forge_ui/worktrees.py +570 -0
@@ -65,6 +65,22 @@ by diff length instead of by judgment required is the main way difficulty routin
65
65
  paying off — it sends the cheap model at the subtle problem and the expensive one at the
66
66
  boilerplate, which is worse than not routing at all.
67
67
 
68
+ **`risk`** is a separate rating, recorded in shadow (#122): what a mistake that gets through
69
+ would cost — what breaks, for whom, and how hard it is to undo. It changes no model, reviewer
70
+ or verdict yet; `forge dataset risk` measures whether it predicts problems difficulty misses.
71
+
72
+ | Risk | Means |
73
+ |------|-------|
74
+ | `low` | local, and easy to see and revert: docs, a test, an internal helper. |
75
+ | `medium` | wrong behaviour users would notice, undone by a revert. |
76
+ | `high` | hard to undo or reaching everyone: release and CI files, migrations and persisted data, auth and permissions, public APIs. |
77
+
78
+ A one-line change to a release script is low difficulty and high risk. Write the rating as
79
+ `low`, `medium` or `high` on the first line of `tasks/<id>/risk` before `plan` (the planner
80
+ writes it from its reply). A plan without ratings behaves exactly as before, and `tasks.tsv`
81
+ keeps its columns. A collapsed chain gets the highest of its parts' ratings, or none when a
82
+ part was not rated.
83
+
68
84
  ## tasks.tsv
69
85
 
70
86
  Tab-separated, one row per task, written by whoever decomposes the goal:
@@ -131,8 +147,9 @@ outright. Forge does not invent a model when the user has not said which one sho
131
147
  their quota.
132
148
 
133
149
  QA has no tier rules by default and falls back to `opus` at `high`, matching single-task forge.
134
- When the user names no reviewers, offer reviewers sized to the task's risk (never add them
135
- unprompted): `--qa-low sonnet:medium --qa-medium sonnet:high --qa-high opus:high`. In the
150
+ When the user names no reviewers, offer reviewers sized to the task's difficulty, which is what
151
+ the `--qa-<tier>` rules key on (a task's [risk](#the-two-axes-decompose-level-and-difficulty) is
152
+ recorded but routes nothing yet; never add them unprompted): `--qa-low sonnet:medium --qa-medium sonnet:high --qa-high opus:high`. In the
136
153
  SWE-bench Pro benchmark (#89) Sonnet reviewers gave no false PASS at about a seventh of an
137
154
  `opus:xhigh` review's cost.
138
155
 
@@ -593,8 +610,16 @@ turns shadow reviews off again.
593
610
 
594
611
  - **Which reviewer:** the first listed spec whose model family (Claude, GPT, Gemini, ...)
595
612
  differs from the task's reviewer, so the two do not share one blind spot. If none
596
- differs, the first listed spec. Forge only ever uses the specs you list. A spec that
597
- cannot run here (`doctor` fails) is dropped with a note and never fails the run.
613
+ differs, the first listed spec that does not resolve to the reviewer's own harness, model
614
+ and effort: the same model at another effort (`same_model`) or another model of the
615
+ family. Only when every listed spec is identical to the reviewer does it run as a
616
+ `control`, two reviews with one setting, which measures noise and never counts as an
617
+ effort comparison (a reviewer pool can hand a task the shadow's own spec). Forge only
618
+ ever uses the specs you list. A spec that cannot run here (`doctor` fails) is dropped
619
+ with a note and never fails the run.
620
+ - **Measuring an effort:** list only specs of the reviewers' own model at another effort,
621
+ for example `--shadow-qa sol:medium` beside `sol:high` reviewers, with a rate high enough
622
+ for at least 30 pairs per comparison. Each pair is one more review, so agree on its cost first.
598
623
  - **Which attempts:** a deterministic sample per (run, task, attempt), so a QA-only
599
624
  resume decides the same way.
600
625
  - **Same evidence, separate everything else.** The shadow reviews a byte-identical copy of
@@ -608,7 +633,11 @@ turns shadow reviews off again.
608
633
  a manual `retry`.
609
634
  - **Scope:** parallel mode only, and never under Fractal.
610
635
 
611
- `./forge dataset status` reports the agreement rate, overall and per model pair. The export
636
+ `./forge dataset status` reports the agreement rate, overall and per model pair, and
637
+ `./forge dataset pairs` splits it by what differs between the two reviewers: effort within one
638
+ model, another model of the family, another family, and controls. For each pair of settings it
639
+ gives verdict agreement with a 95% interval, the blocking findings only one side found, and the
640
+ token and time ratio (see [the dataset reference](dataset.md#paired-reviews)). The export
612
641
  adds `shadow` and `consensus` to the matching review cases' metadata.
613
642
 
614
643
  ## Severity, thresholds and known issues
@@ -640,8 +669,9 @@ every task has merged, and before the combined verification, the scheduler runs
640
669
  once. It collects the open findings at `Pn` or worse (the ones the threshold tolerated, plus
641
670
  PLAUSIBLE ones with `--sweep-plausible`), with `forge issues`' own collector, and leaves out:
642
671
 
643
- - findings a person accepted with `accept`, and findings of fix tasks (one round: what a sweep review
644
- finds goes to `forge issues`, never into another sweep);
672
+ - findings a person accepted with `accept` or kept with `adopt --approved` (listed as `accepted`), and
673
+ findings of fix tasks (one round: what a sweep review finds goes to `forge issues`, never into another
674
+ sweep);
645
675
  - dismissed ones (`forge issues --dismiss`), ones with no file, and ones whose file is gone;
646
676
  - ones whose line, as the reviewer saw it, a later merge changed (`changed`, naming those merges).
647
677
 
@@ -649,7 +679,9 @@ Every finding left out is listed in the plan with its reason. The rest become fi
649
679
  worst first, at most 8 findings each and `--sweep-max N` (default 5) tasks. Each fix task is a row
650
680
  `sweep-<n>` in `tasks.tsv` with `prompt.md` and `sweep.json`. Its implementer is the plan's low tier
651
681
  (the first spec of `--dwarf-low`, else of `--dwarf`; checked at `run` start), else the implementer of
652
- the task the worst finding came from. Its reviewer is that task's reviewer. The plan (groups, findings,
682
+ the task the worst finding came from. Its reviewer is that task's reviewer. What an adopted range's review
683
+ tolerated is swept too: its fix task's reviewer is the adoption's, and below the low tier its implementer
684
+ is the run's first task's. The plan (groups, findings,
653
685
  dispatches) is printed and kept in `<plan>/sweep/plan.md` and `plan.json`. A plan is swept at most once.
654
686
 
655
687
  Fix tasks share the run's scheduling, controls and `--retry-failed` budget. Their review is narrow
@@ -787,16 +819,27 @@ changes it; `--confirm` applies only to that key. A `NEEDS_INPUT` task at the ca
787
819
  raise the plan's cap before the answer can start an attempt.
788
820
 
789
821
  `tasks/<id>/decision.md` gives the reasons and the choices. Nothing else resumes the task: not a
790
- re-run, not `--retry-failed`, not a retry budget and not a pin. A plain `retry` exits 2. The
791
- choices:
822
+ re-run, not `--retry-failed`, not a retry budget and not a pin. A plain `retry` exits 2.
823
+
824
+ `retry` holds the plan lock until its attempts end, so to resume several tasks side by side add
825
+ `--no-dispatch` to each. It records the decision, carries the findings forward and starts nothing;
826
+ the task is then `PENDING`, and one `forge-parallel.sh run <plan>` dispatches them all under
827
+ `--max-parallel`, with dependents starting as their dependencies merge. It works on any `retry`,
828
+ not only a decision, but takes no `--retry-failed` or `--infra-retries`: give those to the `run`. A
829
+ second `--decide` on a prepared task is refused; a `--dwarf` changes its model and keeps its count.
830
+
831
+ The choices:
792
832
 
793
833
  - `forge-parallel.sh retry <plan> <id> --decide retry=N --reason "…" --approved` gives N more
794
834
  attempts, N from 1 to 20. At the cap this raises the cap by N, and it is the only choice that
795
835
  runs the task again while the attempts already spent sit on the cap.
796
836
  - `forge-parallel.sh retry <plan> <id> --decide threshold=Pn --reason "…" --approved` sets this
797
837
  task's blocking threshold (`P0`, `P1`, `P2` or `P3`) and then retries once.
798
- - `forge-parallel.sh retry <plan> <id> --dwarf <spec> --reason "…" --approved` names a model. Not
799
- together with `--decide`.
838
+ - `forge-parallel.sh retry <plan> <id> --dwarf <spec> --reason "…" --approved` names a model for
839
+ one attempt. Add `--decide retry=N` for up to N attempts: the retry policy keeps the task on that
840
+ model until they are used, and they end early the way any retry does, on a pass or when the reviews
841
+ stop converging. Or add `--decide threshold=Pn` to set the threshold too. `decisions.tsv` records it
842
+ as one row, such as `retry=2 dwarf=sol:high`.
800
843
  - `forge-parallel.sh accept <plan> <id> --reason "…" --approved` merges it; the findings become
801
844
  known issues.
802
845
  - Split it by hand: `tasks/<id>/decision.md` and the run summary say to replace its row in
@@ -1015,7 +1058,7 @@ run.
1015
1058
 
1016
1059
  forge records what it observed about how each dwarf behaved, never what the dwarf claimed:
1017
1060
  HEAD or the checked-out ref moved (**self-commit / branch switch**), processes left alive in the
1018
- harness's session after it exited (**orphans**, listed in `dwarf.orphans` and stopped; disabled by
1061
+ harness's session after it exited, or started by it in a session of their own (**orphans**, listed in `dwarf.orphans` and stopped; disabled by
1019
1062
  `FORGE_ORPHAN_GUARD=off` or under Fractal), and a final message that **promises later work**.
1020
1063
  They are written to `tasks/<id>/guard.txt`, added to the QA prompt as "Implementer guard notes" and
1021
1064
  shown in the run summary. They never change a status. The dwarf prompt itself tells the
@@ -1027,6 +1070,27 @@ its last message, and to say plainly what it could not run.
1027
1070
  Four subcommands act on plans after tasks have run. Full usage and refusal conditions are in the
1028
1071
  [README](../docs/reviews.md#accepting-a-task-despite-its-reviewer); the mechanics:
1029
1072
 
1073
+ - **`adopt <plan> <commit|a..b> --reason …`**, or **`adopt <plan> --head --reason …`** (each with
1074
+ `--qa <spec>`, `--yolo-qa`, `--approved`), brings a commit
1075
+ made outside forge into the run instead of leaving `review` refusing. The first cherry-picks onto the
1076
+ integration branch. `--head` takes what is already on it past `accepted.integration`, and it is what
1077
+ `review`'s refusal names. The run's QA (`--qa`, then `final_qa`, then the first task's) reviews that
1078
+ range alone against the reason, and no implementer runs. PASS, or a verdict the threshold accepts, moves
1079
+ `accepted.integration`, adds a row to `adoptions.tsv` (epoch, base, tip, verdict, approved, spec, review,
1080
+ reason) and to `control.log`, writes an `adopt` dataset event, and verifies as a retry does. A FAIL or
1081
+ UNKNOWN puts the branch back and exits 5, unless `--approved` keeps it, which writes the findings to the
1082
+ adoption's `known_issues.md` as `accept` does; `forge issues` and the run's report read that file (as
1083
+ accepted findings, the reason with them), and the sweep lists them as `accepted` without fixing them;
1084
+ what the review tolerated under the threshold the sweep fixes like a task's. The reviewer is told the
1085
+ run's verification command (or its lanes' commands), which runs only after the review. A review that concluded nothing always puts it back: a crash or timeout exits 5, an
1086
+ infrastructure stop exits 8, a signal exits 130 or 143. If the worktree changed during the review it is
1087
+ left as it is, with the commands to go on. A range that lived only on the branch stays at
1088
+ `refs/forge/adopt-refused/<dir>`. A merge commit is refused, and a range that does not apply exits 6. A
1089
+ diff over 400 KB is read in the snapshot rather than inlined, as in a final review.
1090
+ There is no task row, because no model implemented it; the final review reads the whole range and is told
1091
+ about it, `attribute` treats it as a step of its own, and forge-ui lists it above the final review, each
1092
+ row opening its review, its findings and the range's diff with the findings pinned.
1093
+ `adopt-<epoch>-<pid>/` keeps the review.
1030
1094
  - **`accept <plan> <task> --reason … --approved`** overrides a `FAIL`/`UNKNOWN` reviewer only
1031
1095
  when the reviewed commit is still the branch tip and the worktree still matches
1032
1096
  `source.fingerprint`. It records `known_issues.md` and `accepted.by`, merges through `merge_task`,
@@ -1052,6 +1116,7 @@ removes what it created.
1052
1116
 
1053
1117
  ```
1054
1118
  <plan-dir>/tasks/<id>/approach.md intended approach, if planned
1119
+ <plan-dir>/tasks/<id>/risk low|medium|high, recorded only (#122), if rated
1055
1120
  <repo>/.forge/ project memory (survives the run)
1056
1121
  <repo>/../.forge-worktrees/<run-id>/<task-id> task worktree
1057
1122
  <repo>/../.forge-worktrees/<run-id>/_integration integration worktree
@@ -1101,6 +1166,23 @@ tells the dwarf which submodules are present. Integration worktrees (`run`, `int
1101
1166
  `split`) get the same treatment. Out of scope: a task that moves a gitlink's recorded commit (its
1102
1167
  worktree keeps the old content) and nested submodules (left empty).
1103
1168
 
1169
+ **Reviewers get the same dependencies.** A review snapshot holds committed files only, so forge
1170
+ links the directories package managers install into (`node_modules`, `bower_components`, `.venv`,
1171
+ `venv`, `vendor`, `.bundle`, `Pods`, Mix's `deps` and `_build`, `.dart_tool`, `elm-stuff` and
1172
+ SwiftPM's `.build`) from the checkout under review (the task's
1173
+ worktree, or the integration worktree for a final review) into the snapshot, at the root and in
1174
+ workspace packages down to five levels, unless the snapshot already holds that path or lacks its
1175
+ parent. These are the directories this step filled, so they match the attempt. The links count for
1176
+ no fingerprint and stay out of the reviewer's `git status`. The prompt names what was linked and what
1177
+ is committed, or says there is none, says when forge ran no tests of its own, and tells the reviewer
1178
+ to report rather than search or install. A directory that is only partly committed (`vendor/.gitkeep`)
1179
+ keeps its committed files and gets no link. Nothing guards a write
1180
+ through a link: forge commits whatever git does not ignore, so a linked directory is an ignored one
1181
+ (a directory the attempt committed is already in the snapshot and gets no link), and a write there
1182
+ changes nothing that merges. A link dangles once its worktree is removed, which harms nothing. Each
1183
+ reviewer ends with `FORGE_TESTS: RAN`, `NOT NEEDED — why` or `COULD NOT RUN — why`; the last prints a note, and
1184
+ forge-ui and the dataset show it.
1185
+
1104
1186
  Forge does not guess this step, and the obvious guess is worth naming because it looks right and
1105
1187
  is not: symlinking the source repo's `node_modules` into the worktree. In a workspace monorepo the
1106
1188
  workspace links inside it point back at the source checkout, so the worktree builds against the
@@ -70,7 +70,10 @@ through `forge-guard.py session` (python's `os.setsid()` then `exec`, same pid,
70
70
  unless `FORGE_ORPHAN_GUARD=off` or the run is Fractal. That gives a process group to signal as a
71
71
  unit: the watchdog (TERM, then KILL for a CLI that traps TERM) and the exit trap signal the whole
72
72
  group in addition to `pkill -P`, and after a normal exit `forge-guard.py reap` lists and stops
73
- anything still alive in it (`<role>.orphans`). This is proven offline only; verify a new harness
73
+ anything still alive in it (`<role>.orphans`). Tools can leave the group (codex runs commands in
74
+ groups of their own, and a test runner's web server starts a session of its own), so
75
+ `forge-guard.py track` samples the harness's descendants every 2 s into `<role>.tracked` (pid and
76
+ start time), and `reap --tracked` stops those still alive and their children as well (#129). This is proven offline only; verify a new harness
74
77
  with one live dispatch before relying on it, and use the kill switch if a harness deliberately
75
78
  leaves a helper running.
76
79
 
@@ -75,7 +75,7 @@ given this same prompt file as `--prompt-file`.
75
75
  **The reply** holds exactly one fenced block opened by ```` ```forge-plan ```` whose body is JSON:
76
76
 
77
77
  ```
78
- {"tasks": [{"id": "parse-config", "deps": [], "difficulty": "medium",
78
+ {"tasks": [{"id": "parse-config", "deps": [], "difficulty": "medium", "risk": "low",
79
79
  "files": ["src/config.py", "tests/test_config.py"],
80
80
  "title": "Parse the new config section", "approach": "…",
81
81
  "prompt": "… ## Acceptance criteria …"}]}
@@ -88,7 +88,8 @@ matches `^[a-z0-9][a-z0-9-]{0,39}$` and is unique; `deps` are known ids with no
88
88
  `difficulty` is `low`, `medium` or `high`; `files` is a non-empty list of repo-relative paths (no
89
89
  absolute path, no `..`, no tab, comma or newline); `title` is one non-empty line without a tab;
90
90
  `approach` is a string (it may be empty); `prompt` is non-empty and has a `## Acceptance
91
- criteria` heading.
91
+ criteria` heading. `risk` (#122) is the one optional key and never refuses a reply: `low`,
92
+ `medium` or `high` is written to `tasks/<id>/risk`, anything else (or no key) writes nothing.
92
93
 
93
94
  On success it writes `tasks.tsv` (dwarf and qa `-`), `tasks/<id>/prompt.md` (the task's prompt,
94
95
  then `## The whole request` and `$PLAN/request.md` verbatim, so no requirement is lost) and, for
@@ -82,7 +82,11 @@ Solo defaults to `--output summary`; `--output full` includes raw CLI output. Re
82
82
  `.last` files once, then inspect logs only as needed. `forge-dispatch.sh report <run-dir>`
83
83
  reports immutable attempt metrics and native usage independently of project memory. Shared
84
84
  context is assembled from original requirements and approach; QA does not embed dwarf
85
- execution instructions. Review snapshots use self-contained object packs and one checkout.
85
+ execution instructions. Review snapshots use self-contained object packs and one checkout, with
86
+ the repo's dependency directories (`node_modules`, `.venv`, `vendor`, Mix's `deps` and the others
87
+ listed under [worktree setup](decompose.md#worktree-setup)) linked in, at the root and in workspace
88
+ packages, when it has them; the prompt says what is there, and the reviewer reports `FORGE_TESTS` as in
89
+ [worktree setup](decompose.md#worktree-setup).
86
90
 
87
91
  Optional [Ripwire context](ripwire.md) is enabled by default. Use `--no-ripwire`
88
92
  or `FORGE_RIPWIRE=off` to disable preparation and installation offers.
package/references/ui.md CHANGED
@@ -35,7 +35,7 @@ run goes on, with the same exit code.
35
35
  filed as GitHub issues or dismissed through `forge issues`.
36
36
  - **Delete a run:** a dry run, then `forge runs rm`: the dataset keeps the traces, an archive is
37
37
  written unless declined, and clean worktrees and unchecked-out branches can go with it.
38
- - **Settings:** `forge config show` in one view: the registry, decision-model gates, profiles,
38
+ - **Settings:** `forge config show` in one view: the registry, decision-model gates (each says what it does, when, what it sends and what `on` changes, and **How to set this up** opens a setup guide), profiles,
39
39
  the per-repo files, the dataset and `FORGE_*` variables, with edits where the server can write.
40
40
  - **Export a run:** one HTML file to share that opens without forge-ui; prompts, diffs, reports
41
41
  and local paths stay out unless chosen.
@@ -204,3 +204,12 @@ server that is already running, do not unregister runs, and do not block `forge
204
204
  close the exposure, run `forge ui stop`. Do not forward the server's port.
205
205
 
206
206
  The API contract is [ui/docs/api.md](../ui/docs/api.md).
207
+
208
+ ## Live refresh
209
+
210
+ A live refresh never cancels what the user is doing. Every view that redraws on new data goes through
211
+ `ForgeUI.guard(region, draw)` (`preserve` in `app.js` does): while a pointer is down in the region, a
212
+ selection touches it or a `<select>` in it has focus, the latest draw waits and runs when that ends. What the
213
+ user just did draws at once, and a hold that lasts five seconds shows **Newer data is waiting**, with a
214
+ button that runs it. Anything collapsible in such a view gets a `data-keep` key, which `preserve` and
215
+ `ForgeUI.keepOpen` restore. A new view that rebuilds on a poll goes through the same two.
@@ -59,6 +59,59 @@ forge_review_snapshot() ( # source, baseline tree, final tree, destination
59
59
 
60
60
  )
61
61
 
62
+ # Where package managers install into a checkout: npm and bower, Python virtualenvs, Go, PHP and Ruby
63
+ # vendor dirs, Bundler's config, CocoaPods, Mix (deps, _build), Dart, Elm and SwiftPM (#127). The same
64
+ # names as forge-fail-first.py's DEP_DIRS. Only a directory the snapshot does not hold is linked, so a
65
+ # committed one of these names is never replaced.
66
+ FORGE_DEP_DIRS='node_modules bower_components .venv venv vendor .bundle Pods deps _build .dart_tool elm-stuff .build'
67
+
68
+ _forge_dep_dirs() { # checkout: its dependency directories, relative, never one inside another
69
+ # Five levels reach apps/group/name/node_modules.
70
+ local name names=()
71
+ for name in $FORGE_DEP_DIRS; do names+=(${names[0]+-o} -name "$name"); done
72
+ (cd "$1" && find . -maxdepth 5 \( -name .git -o -name .forge \) -prune -o \
73
+ \( "${names[@]}" \) \( -type d -o -type l \) -print -prune 2>/dev/null) |
74
+ sed 's#^\./##'
75
+ }
76
+
77
+ forge_review_deps() { # source checkout, review snapshot, note file (#117)
78
+ # Links the dependency directories of the checkout under review (what .forge/setup filled, so
79
+ # they match the attempt, unlike the source repo's) into its snapshot, at the root and in
80
+ # workspace packages, and writes what the reviewer has to the note. An untracked link counts for
81
+ # no fingerprint, and the exclude keeps it out of the reviewer's `git status`: a `node_modules/`
82
+ # ignore pattern does not match a link. A directory the snapshot already holds is committed: it
83
+ # stays as it is. `ln` fails where the snapshot lacks the parent (an old run's dir in a solo
84
+ # repo): that is no part of the change, so nothing is linked there.
85
+ local src rel linked="" committed
86
+ src="$(cd "$1" && pwd)" || src=""
87
+ committed="$(_forge_dep_dirs "$2" | sort | awk 'NR > 1 { printf ", " } { printf "%s", $0 }')"
88
+ if [ -n "$src" ]; then
89
+ while IFS= read -r rel; do
90
+ [ -n "$rel" ] && [ -d "$src/$rel" ] && [ ! -e "$2/$rel" ] && [ ! -L "$2/$rel" ] || continue
91
+ ln -s "$src/$rel" "$2/$rel" 2>/dev/null || continue
92
+ mkdir -p "$2/.git/info" && echo "/$rel" >> "$2/.git/info/exclude"
93
+ linked="$linked${linked:+, }$rel"
94
+ done <<< "$(_forge_dep_dirs "$src" | sort)"
95
+ fi
96
+ {
97
+ if [ -n "$linked" ]; then
98
+ echo "Dependencies linked into your checkout from the attempt's own copy: $linked. Use them to run tests, and do not write to them. forge does not check that they are complete, or look more than five levels down."
99
+ fi
100
+ if [ -n "$committed" ]; then
101
+ echo "Dependency directories committed in your checkout, holding only what was committed: $committed."
102
+ fi
103
+ if [ -z "$linked$committed" ]; then
104
+ echo "Dependencies in your checkout: none. It holds committed files only, with no installed packages."
105
+ fi
106
+ } > "$3"
107
+ }
108
+
109
+ forge_tests_note() { # QA reply: the reason, when the reviewer says its tests could not run (#117)
110
+ grep -qs 'FORGE_TESTS:' "$1" || return 0
111
+ python3 "$SKILL_DIR/scripts/forge-contract.py" tests --qa-last "$1" 2>/dev/null |
112
+ awk -F'\t' '$1 == "could_not_run" { print ($2 == "" ? "no reason given" : $2) }'
113
+ }
114
+
62
115
  forge_fingerprint() { # forge_fingerprint <dir> [--tracked], as forge_tree
63
116
  local tree head index
64
117
  tree="$(forge_tree "$1" "${2:-}")" || return 1
@@ -54,8 +54,13 @@ line); CONFIRMED beats PLAUSIBLE; PLAUSIBLE-only blocks are ignored; "NOT CONFIR
54
54
  lowercase prose do not count. The severity is the first P0-P3 token of the block's first
55
55
  line (`[P2]`, `(P2)`, `**P2**`, `P2:`, `P2 -` or a standalone `P2`; uppercase only).
56
56
 
57
+ Facts (#119). A finding may end its first line (or, wrapped, its last) with
58
+ `{reach=main|realistic|unusual origin=new|existing evidence=ran|traced|suspected}`. They are
59
+ recorded in shadow and decide nothing: the gate never reads them, and `split_facts` cuts the
60
+ suffix for readers that show the line. A missing or malformed suffix changes nothing.
61
+
57
62
  Phantom findings. A reviewer may echo the contract it was given. Three layers keep that
58
- from creating findings or blocking: (1) FORGE_VERDICT and FORGE_LEARNING text is removed
63
+ from creating findings or blocking: (1) FORGE_VERDICT, FORGE_LEARNING and FORGE_TESTS text is removed
59
64
  before parsing (the verdict line itself says "CONFIRMED"); (2) any line that is a
60
65
  contiguous fragment of this module's own contract text (all parts, kinds and thresholds,
61
66
  whitespace-collapsed, at least 25 characters, list marker ignored) is removed, which
@@ -78,7 +83,7 @@ import sys
78
83
 
79
84
  SEVERITIES = ('P0', 'P1', 'P2', 'P3')
80
85
  PLACEHOLDER = 'path/file.py:123'
81
- KINDS = ('task', 'final', 'solo', 'sweep')
86
+ KINDS = ('task', 'final', 'solo', 'sweep', 'adopt')
82
87
  DEFAULT_THRESHOLD = 'P2'
83
88
  QA_TEST_MINUTES = 5 # the reviewer's own test time, beyond which it says the check is too broad (#89)
84
89
 
@@ -130,6 +135,12 @@ _HEAD = {
130
135
  'diff did not change, and do not report other problems you notice there: they are not this',
131
136
  "task's work.",
132
137
  ] + _NO_TRUST,
138
+ 'adopt': [
139
+ "This range was made outside forge, by a person or another agent, and is about to enter this run's",
140
+ 'integration branch. Review the diff below for correctness bugs, and for whether it does what the',
141
+ 'reason above says. Also say if it changes anything that reason does not cover.',
142
+ "Do not trust the reason's claims about which checks ran or passed; judge the diff itself.",
143
+ ],
133
144
  'final': [
134
145
  'This is the final, whole-run review. The diff below is the COMBINED result of several',
135
146
  'tasks that were implemented independently and each reviewed on its own slice only.',
@@ -163,7 +174,12 @@ _VERIFY = [
163
174
  'spend at most about %d minutes running tests. Use any test evidence forge gives you above' % QA_TEST_MINUTES,
164
175
  'before running a test yourself. When the targeted tests would take longer, or the change',
165
176
  'touches shared infrastructure (a test helper, a build file, a lockfile), say so instead of',
166
- 'running everything.',
177
+ 'running everything. If a test needs a dependency your checkout does not have, do not look for',
178
+ 'it elsewhere and do not install anything: report that it could not run.',
179
+ 'Say whether tests ran, on a line of its own before the verdict, in exactly one of these forms:',
180
+ ' FORGE_TESTS: RAN',
181
+ ' FORGE_TESTS: NOT NEEDED — why',
182
+ ' FORGE_TESTS: COULD NOT RUN — why',
167
183
  ]
168
184
 
169
185
  _SEVERITY = [
@@ -175,8 +191,22 @@ _SEVERITY = [
175
191
  ' P1 wrong behaviour on realistic input, or breaks an existing contract',
176
192
  ' P2 edge-case bug, race that needs unusual timing, missing hardening',
177
193
  ' P3 minor: cosmetic, naming, nit-level correctness',
194
+ 'End the first line of every finding with three facts about it, in braces, in this form:',
195
+ ' - [P1][CONFIRMED] path/file.py:123 — what breaks {reach=realistic origin=new evidence=traced}',
196
+ ' reach main (the main path), realistic (realistic input),',
197
+ ' or unusual (an unusual or hostile state)',
198
+ ' origin new (this change introduced it), or existing (it was there before the change)',
199
+ ' evidence ran (you ran it and saw it break), traced (you traced it in the code),',
200
+ ' or suspected',
201
+ 'The facts are recorded for measurement only: they change neither the severity nor what blocks.',
178
202
  ]
179
203
 
204
+ # The three facts of #119, recorded in shadow beside each finding's severity and confidence. They go
205
+ # at the END of the first line, never after the tags: `forge issues` would read a third tag as part
206
+ # of the location, and forge-ui strips only two.
207
+ FACTS = {'reach': ('main', 'realistic', 'unusual'), 'origin': ('new', 'existing'),
208
+ 'evidence': ('ran', 'traced', 'suspected')}
209
+
180
210
  _SWEEP_FINDINGS = [
181
211
  'Report findings only — do not edit any file. A finding here is a regression the change',
182
212
  'introduced: give its file and line, what breaks, and a concrete input that triggers it. Mark it',
@@ -225,7 +255,7 @@ def qa_text(part: str, kind: str = 'task', threshold=None) -> str:
225
255
  if part != 'tail':
226
256
  raise ValueError('part must be head or tail')
227
257
  lines = list(_SWEEP_FINDINGS if kind == 'sweep' else _FINDINGS)
228
- if kind in ('task', 'solo'):
258
+ if kind in ('task', 'solo', 'adopt'):
229
259
  lines += _ALL_CONFIRMED + _SOLO_EXTRA
230
260
  lines += [''] + _VERIFY
231
261
  lines += [''] + _SEVERITY
@@ -289,7 +319,7 @@ def dwarf_text(pre_review: bool = False, verify_after_merge: bool = False) -> st
289
319
 
290
320
  # --- parsing ---------------------------------------------------------------------
291
321
 
292
- _PROTOCOL = re.compile(r'FORGE_(?:VERDICT|LEARNING):.*$')
322
+ _PROTOCOL = re.compile(r'FORGE_(?:VERDICT|LEARNING|TESTS):.*$')
293
323
  _QUOTE = re.compile(r'^\s*(?:>[ \t]?)+')
294
324
  _MARKER = re.compile(r'^(?:[-*+•–]|\d{1,3}[.)]|#{1,6})\s+')
295
325
  _HEADING = re.compile(r'^ {0,3}#{1,6}[ \t]+\S')
@@ -327,11 +357,12 @@ def _clean(text: str) -> list:
327
357
  for number, raw in enumerate(text.replace('\r\n', '\n').replace('\r', '\n').split('\n'), 1):
328
358
  raw = raw.expandtabs(4)
329
359
  line = _PROTOCOL.sub('', raw)
330
- if line != raw and not line.strip():
360
+ if line != raw and not line.strip(' \t*_`>+-'):
331
361
  continue
332
362
  line = _QUOTE.sub('', line).rstrip()
333
363
  core = _collapse(_MARKER.sub('', line.strip()))
334
- if len(core) >= _MIN_ECHO and core in flat:
364
+ # A wrapped finding's facts on a line of their own can match the example's suffix word for word.
365
+ if len(core) >= _MIN_ECHO and core in flat and split_facts(core)[0].strip():
335
366
  continue
336
367
  out.append((number, line))
337
368
  return out
@@ -396,6 +427,37 @@ def _finding(number: int, lines: list):
396
427
  return Finding(status, severity, located, number, '\n'.join(lines))
397
428
 
398
429
 
430
+ # A brace group closing a line, markup and a full stop around it forgiven. It is the facts suffix only
431
+ # when it names at least one of the three facts: a finding's own text may end in braces (`{}`, `{a=1}`).
432
+ _FACTS_SUFFIX = re.compile(r'[ \t]*[`*_]*\{([^{}\n]*)\}[`*_.]*[ \t]*$')
433
+ _FACT = re.compile(r'([A-Za-z]+)[ \t]*[=:][ \t]*([A-Za-z]+)')
434
+
435
+
436
+ def split_facts(line: str):
437
+ """(line without its facts suffix, {reach, origin, evidence}) or (line, None) when it has none.
438
+
439
+ A fact whose value is not one of its words reads None, and keys other than the three are ignored:
440
+ a malformed suffix is still cut from the line, so it never reaches a location or a title."""
441
+ match = _FACTS_SUFFIX.search(line or '')
442
+ if not match:
443
+ return line, None
444
+ said = {key.lower(): value.lower() for key, value in _FACT.findall(match.group(1))}
445
+ if not any(key in said for key in FACTS):
446
+ return line, None
447
+ return line[:match.start()], {key: said[key] if said.get(key) in words else None
448
+ for key, words in FACTS.items()}
449
+
450
+
451
+ def facts(text: str):
452
+ """The facts of one finding block: its first line's suffix, else its last line's (a wrapped bullet)."""
453
+ lines = [line for line in (text or '').split('\n') if line.strip()]
454
+ for line in lines[:1] + lines[-1:]:
455
+ found = split_facts(line)[1]
456
+ if found is not None:
457
+ return found
458
+ return None
459
+
460
+
399
461
  def parse_findings(text: str) -> list:
400
462
  """Finding blocks of a QA reply, in order; see the module docstring for the rules."""
401
463
  found = (_finding(start, lines) for start, _, lines in _blocks(_clean(text)))
@@ -427,6 +489,35 @@ def gate(verdict: str, text: str, threshold=None) -> GateResult:
427
489
  return GateResult(decision, worst, len(confirmed), unlabelled, len(below), below)
428
490
 
429
491
 
492
+ # A reviewer's own word on whether its tests ran (#117). Only a line of its own counts, the last one
493
+ # when it repeats: a quoted example in prose is not its report. Unlike the verdict, nothing gates on
494
+ # this line and it exists to be seen, so markup and any separator are forgiven, and a line that says
495
+ # something else is `unclear` rather than silence. The forms' own "why" is the prompt echoed.
496
+ _TESTS_LINE = re.compile(r'^[ \t>*_`+-]*FORGE_TESTS:[ \t*_`]*(.*?)[ \t*_`]*$', re.M)
497
+ _TESTS_VALUE = re.compile(r'(RAN|NOT[ _]NEEDED|COULD[ _]NOT[ _]RUN)\b(.*)$', re.I)
498
+ _TESTS_STATUS = {'RAN': 'ran', 'NOT NEEDED': 'not_needed', 'COULD NOT RUN': 'could_not_run'}
499
+ _TESTS_TRIM = ' \t—–-:()'
500
+ _TESTS_REASON_MAX = 300
501
+
502
+
503
+ def _tests_reason(text: str) -> str | None:
504
+ return ''.join(ch for ch in text.strip(_TESTS_TRIM) if ch.isprintable())[:_TESTS_REASON_MAX] or None
505
+
506
+
507
+ def tests_report(text) -> dict | None:
508
+ """{status: ran|not_needed|could_not_run|unclear, reason} from a QA reply, or None when it does not say."""
509
+ report = None
510
+ for value in _TESTS_LINE.findall((text or '').replace('\r\n', '\n')):
511
+ match = _TESTS_VALUE.match(value)
512
+ if not match:
513
+ report = dict(status='unclear', reason=_tests_reason(value))
514
+ continue
515
+ reason = _tests_reason(match.group(2))
516
+ if (reason or '').lower() != 'why':
517
+ report = dict(status=_TESTS_STATUS[match.group(1).upper().replace('_', ' ')], reason=reason)
518
+ return report
519
+
520
+
430
521
  def known_issues_text(threshold, tolerated) -> str:
431
522
  name = SEVERITIES[_rank(threshold)]
432
523
  lines = ['## Known issues (QA findings below blocking threshold %s)' % name, '',
@@ -468,8 +559,8 @@ def _parser() -> argparse.ArgumentParser:
468
559
  qa.add_argument('--part', required=True, choices=('head', 'tail'),
469
560
  help='head = review preamble, tail = findings format + verdict contract')
470
561
  qa.add_argument('--kind', choices=KINDS, default='task',
471
- help='task (default), final (whole-run review), solo (solo wording) or sweep (a finding '
472
- 'sweep task: per-finding FIXED lines, regressions only)')
562
+ help='task (default), final (whole-run review), solo (solo wording), sweep (a finding '
563
+ 'sweep task: per-finding FIXED lines, regressions only) or adopt (a range made outside forge)')
473
564
  qa.add_argument('--threshold', type=_threshold_arg, default=None, metavar='P0..P3|none',
474
565
  help='least severe level that still blocks; none = P3 (default: %s)' % DEFAULT_THRESHOLD)
475
566
  dwarf = sub.add_parser('dwarf', help='print the implementer rules block')
@@ -485,6 +576,8 @@ def _parser() -> argparse.ArgumentParser:
485
576
  % DEFAULT_THRESHOLD)
486
577
  gate_parser.add_argument('--known-issues', metavar='OUT', default=None,
487
578
  help='write tolerated findings here when there are any')
579
+ tests = sub.add_parser('tests', help='print what the reply says about its tests: status, a tab, the reason')
580
+ tests.add_argument('--qa-last', required=True, metavar='FILE', help='the QA reply')
488
581
  return parser
489
582
 
490
583
 
@@ -502,6 +595,11 @@ def main(argv=None) -> int:
502
595
  except OSError as error:
503
596
  sys.stderr.write('forge-contract: cannot read %s: %s\n' % (args.qa_last, error))
504
597
  return 3
598
+ if args.command == 'tests':
599
+ report = tests_report(text)
600
+ if report:
601
+ _emit('%s\t%s\n' % (report['status'], report['reason'] or ''))
602
+ return 0
505
603
  result = gate(args.verdict, text, args.threshold)
506
604
  if args.known_issues and result.n_below >= 1:
507
605
  temporary = args.known_issues + '.%d.tmp' % os.getpid()
@@ -845,8 +845,6 @@ def decision_of(plan, args, dwarf):
845
845
  if line.strip())
846
846
  raise Refused(f'task {args.task} is waiting for your decision, and only a decision resumes it: {head or "see decision.md"} '
847
847
  '(retry --decide retry=N | threshold=Pn, or --dwarf SPEC, each with --reason TEXT --approved)')
848
- if args.decide is not None and dwarf is not None:
849
- raise Invalid('give --decide or --dwarf, not both: a decision is one choice')
850
848
  if args.decide is not None and not DECISION.fullmatch(args.decide):
851
849
  raise Invalid('--decide takes retry=N (1 to 20) or threshold=P0|P1|P2|P3')
852
850
  reason = re.sub(r'\s+', ' ', args.reason or '').strip()