@giamme/forge 0.17.0 → 0.18.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 (76) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/SKILL.md +16 -3
  3. package/VERSION +1 -1
  4. package/docs/artifacts.md +8 -0
  5. package/docs/commands.md +70 -6
  6. package/docs/dataset.md +5 -0
  7. package/docs/decomposed-runs.md +8 -0
  8. package/docs/forge-ui.md +23 -2
  9. package/docs/memory.md +2 -0
  10. package/docs/safety.md +8 -0
  11. package/forge +24 -1
  12. package/package.json +1 -1
  13. package/references/dataset.md +19 -0
  14. package/references/decompose.md +134 -1
  15. package/references/solo.md +2 -1
  16. package/references/ui.md +5 -2
  17. package/scripts/forge-artifact.sh +14 -0
  18. package/scripts/forge-brief.py +132 -0
  19. package/scripts/forge-compare.py +11 -1
  20. package/scripts/forge-config.py +176 -9
  21. package/scripts/forge-contract.py +46 -3
  22. package/scripts/forge-control.py +86 -13
  23. package/scripts/forge-dispatch.sh +14 -10
  24. package/scripts/forge-du.py +167 -0
  25. package/scripts/forge-lib-adopt.sh +1 -0
  26. package/scripts/forge-lib-plans.sh +5 -2
  27. package/scripts/forge-lib-review.sh +29 -1
  28. package/scripts/forge-metrics.sh +7 -3
  29. package/scripts/forge-parallel-options.sh +4 -0
  30. package/scripts/forge-parallel.sh +503 -9
  31. package/scripts/forge-prompt.py +120 -0
  32. package/scripts/forge-retro.py +115 -0
  33. package/scripts/forge-runs-compact.py +443 -0
  34. package/scripts/forge-runs-rm.py +2 -0
  35. package/scripts/forge-runs.py +18 -3
  36. package/scripts/forge-schedule.py +279 -4
  37. package/scripts/forge-shadow.py +7 -1
  38. package/scripts/forge-solo.sh +2 -0
  39. package/scripts/forge-summarize.py +698 -0
  40. package/scripts/forge-ui-options.sh +10 -0
  41. package/scripts/forge_brief/__init__.py +587 -0
  42. package/scripts/forge_brief/answers.py +459 -0
  43. package/scripts/forge_dataset/__init__.py +10 -0
  44. package/scripts/forge_dataset/export.py +18 -4
  45. package/scripts/forge_dataset/facts.py +6 -4
  46. package/scripts/forge_dataset/harvest.py +40 -6
  47. package/scripts/forge_dataset/history.py +5 -3
  48. package/scripts/forge_decide/__init__.py +11 -1
  49. package/scripts/forge_locations.py +366 -0
  50. package/scripts/forge_registry.py +19 -0
  51. package/scripts/forge_retro/__init__.py +417 -0
  52. package/scripts/forge_retro/issues.py +1193 -0
  53. package/scripts/forge_retro/report.py +671 -0
  54. package/scripts/forge_side/__init__.py +477 -0
  55. package/scripts/forge_storage.py +515 -0
  56. package/ui/README.md +68 -8
  57. package/ui/docs/api.md +205 -17
  58. package/ui/forge_ui/control.py +92 -11
  59. package/ui/forge_ui/export.py +24 -5
  60. package/ui/forge_ui/links.py +337 -0
  61. package/ui/forge_ui/models.py +57 -4
  62. package/ui/forge_ui/projects.py +4 -1
  63. package/ui/forge_ui/reader.py +661 -30
  64. package/ui/forge_ui/static/app.js +86 -4
  65. package/ui/forge_ui/static/briefview.js +302 -0
  66. package/ui/forge_ui/static/checksview.js +6 -2
  67. package/ui/forge_ui/static/controls.js +5 -0
  68. package/ui/forge_ui/static/index.html +3 -0
  69. package/ui/forge_ui/static/panel.js +268 -2
  70. package/ui/forge_ui/static/runmodel.js +13 -1
  71. package/ui/forge_ui/static/storageview.js +271 -0
  72. package/ui/forge_ui/static/style.css +99 -3
  73. package/ui/forge_ui/static/worktreesview.js +3 -3
  74. package/ui/forge_ui/storage.py +136 -0
  75. package/ui/forge_ui/transcripts.py +35 -10
  76. package/ui/forge_ui/worktrees.py +154 -13
@@ -20,6 +20,9 @@ run leaves branches behind.
20
20
  - [Planning](#planning)
21
21
  - [Plan shape](#plan-shape)
22
22
  - [QA verdicts](#qa-verdicts)
23
+ - [Retro notes (opt-in)](#retro-notes-opt-in)
24
+ - [Brief mode (opt-in)](#brief-mode-opt-in)
25
+ - [Task summaries (opt-in)](#task-summaries-opt-in)
23
26
  - [Severity, thresholds and known issues](#severity-thresholds-and-known-issues)
24
27
  - [Retrying, and resuming an interrupted run](#retrying-and-resuming-an-interrupted-run)
25
28
  - [Infrastructure failures](#infrastructure-failures)
@@ -640,6 +643,128 @@ gives verdict agreement with a 95% interval, the blocking findings only one side
640
643
  token and time ratio (see [the dataset reference](dataset.md#paired-reviews)). The export
641
644
  adds `shadow` and `consensus` to the matching review cases' metadata.
642
645
 
646
+ ## Retro notes (opt-in)
647
+
648
+ `plan --retro` makes each agent record what got in its way: a sandbox that blocked a command, a
649
+ tool that is not installed, an instruction it could not follow, a forge fault. A note says what
650
+ happened and who can fix it. Without a flag a plan keeps its earlier choice, and a first plan
651
+ takes the user setting (`forge config set retro on`). `plan --no-retro` turns it off.
652
+
653
+ - **What an agent writes.** Most tasks have nothing to report, and a hard task is not a note.
654
+ A note is one `FORGE_RETRO: {json}` line in the final message. The planner, QA and the
655
+ whole-run review write it the same way. A dwarf blocked before it finishes also appends the
656
+ same JSON to `.forge/retro-inbox.jsonl` in its worktree, which forge reads when the dispatch
657
+ ends. The fields are `type` (`environment`, `sandbox`, `tooling`, `prompt`, `forge-bug` or
658
+ `other`), `fixable_by` (`user`, `forge` or `unsure`), `summary`, `evidence` (the command, its
659
+ exit code and the error, up to 2 KB), `blocking` and `tried`.
660
+ - **Checked against the log.** forge looks for the note's command and the first line of its
661
+ error in that dispatch's log. When both are there the note is `verified`; otherwise `claimed`.
662
+ - **Orchestrator notes.** `forge retro note PLAN --type T --fixable-by F --summary S` records
663
+ one note of the run's own, with `--command`, `--exit`, `--error`, `--blocking` and `--tried`
664
+ as needed. It is always `claimed`, and it does not check the retro setting.
665
+ - **Where it goes.** `<plan>/retro/notes.jsonl`, `tasks/<id>/retro.json` for a task, and one
666
+ `retro_note` dataset event per note. `forge retro report PLAN` writes `<plan>/retro.md`.
667
+ Notes with the same type and the same normalised command form one pattern; a note with no
668
+ command is matched on its normalised summary instead. Each pattern
669
+ goes to the group its majority `fixable_by` names: **You can fix this on this machine**
670
+ (`user`), **forge should fix this** (`forge`), or **Not sure who should fix this** (`unsure`,
671
+ also on a tie). A run prints one line with the pattern count and the path when there are any
672
+ patterns. The first plan with retro on says what is recorded, once per user.
673
+ - **Filing.** `forge retro issues PLAN` drafts one redacted issue per `forge` pattern, for
674
+ forge's own repository, and posts nothing. The dry run prints the texts and their hash.
675
+ `forge retro issues PLAN --apply --approve HASH` posts only when the hash matches those texts
676
+ and the `--choice rN=new|comment:N|skip` choices. It needs an authenticated `gh`, and it
677
+ refuses a never-send repository. Both refusals exit `3`.
678
+ - **Never memory.** Notes never go into `.forge/memory.md` or the ledger, and no prompt reads
679
+ them back. A retro plan does add a short instruction block to each prompt, at its end.
680
+ - **Off.** With retro off (`--no-retro`, no setting, or `FORGE_RETRO=off`) no instruction is
681
+ added to any prompt, the inbox is not read, and forge stores no note from a dispatch. Its
682
+ prompts stay as they were without the feature. `forge retro note` still records a note when
683
+ it is called, because it does not check the setting.
684
+
685
+ Files it adds: `retro_mode` (plan file), `retro/notes.jsonl`, `retro/.lock`, `retro.md`,
686
+ `tasks/<id>/retro.json`, and `.forge/retro-inbox.jsonl` in a worktree (removed once its notes
687
+ are stored). It costs no model call of its own.
688
+
689
+ ## Brief mode (opt-in)
690
+
691
+ With `plan --brief advisory|gated|strict --brief-model SPEC`, a read-only side dispatch writes
692
+ the questions each task needs answered before it starts. Each question has a default. A task
693
+ with no answer follows the default. The user answers with `forge brief answer`,
694
+ and each answer goes into that task's prompt. forge never answers for the user.
695
+
696
+ - **Cost.** One dispatch per task that has no `brief.json`, at effort `low`, four at a time.
697
+ A reply that is not valid JSON, or has the wrong shape, is retried once; a second failure
698
+ stores no questions and the reason in `brief.json`'s `error`. Answers and stale flags call no
699
+ model.
700
+ - **When.** `run` writes the missing briefs when it starts. `strict` waits for them; `advisory`
701
+ and `gated` write them alongside the scheduler. `forge brief write PLAN [--task ID] [--jobs N]
702
+ [--force]` does the same by hand, and `--force` redoes a task that already has a brief.
703
+ - **Levels.**
704
+ - `advisory`: the run does not wait. Open questions reach the prompt under "Open questions:
705
+ follow the stated default", with each default.
706
+ - `gated`: a task with an unanswered must-answer question is held. The run prints
707
+ `forge: <task> waits for your answer to <qid>` with the `forge brief answer` line. A task
708
+ whose brief is still being written waits too.
709
+ - `strict`: `run` exits `3` before any task starts while a question of an unstarted task is
710
+ open. It prints each question, its default and the answer command. Answer them and run again.
711
+ - **Answers.** `forge brief answer PLAN TASK QID TEXT` (or `--file F`; `-` reads stdin). Before
712
+ the task starts, the answer goes to `brief.answers.json` and to the prompt under "Decisions the
713
+ user made", which overrides what the requirements say. After it starts, the answer goes to
714
+ `brief.late.json` and changes nothing in the run. The command then prints the `tasks.tsv` row,
715
+ the `prompt.md` a follow-up needs, and the `forge control add` line that queues it.
716
+ - **Scope.** `--brief-scope task` (the default) is the only scope that acts. A `wave` or `plan`
717
+ question is parked in `brief.parked.json` and acts on nothing.
718
+ - **Stale.** After a task merges, a merge that changed files outside that task's declared files
719
+ flags the open questions of its dependents that have not started (`possibly_stale`). `forge
720
+ brief stale PLAN TASK` does this by hand.
721
+ - **Model.** `--brief-model SPEC` is required with brief on, and it must resolve; otherwise
722
+ `plan` exits `2`. forge never picks the model.
723
+ - **Privacy.** A never-send repository gets no brief dispatch (`never-send`), so its tasks have
724
+ no questions and nothing holds them.
725
+ - **Off.** With `--brief off`, no setting, or `FORGE_BRIEF=off`, there is no writer, no hold and
726
+ no prompt addition. `forge-prompt.py` adds nothing without a `brief` file. `forge brief write`
727
+ and `forge brief show` exit `3` for such a plan.
728
+
729
+ Files it adds: the plan files `brief`, `brief_scope` and `brief_model`; `brief.out` (the
730
+ writer's output) and `brief.pid` (while the writer runs); and per task `tasks/<id>/brief.json`,
731
+ `brief.parked.json`, `brief.answers.json` and `brief.late.json`. Its events are `brief_question`,
732
+ `brief_answer` and `side_dispatch` (kind `brief`).
733
+
734
+ ## Task summaries (opt-in)
735
+
736
+ `plan --summaries on --summaries-model SPEC` writes a short summary of each task to
737
+ `tasks/<id>/summary.json`. The model sees only the task's facts: its status, its attempt trail
738
+ (attempt, dwarf spec, verdict, findings count, worst severity, retry reason), the latest review's
739
+ finding titles and severities, its known issues, and its dependencies and dependents. The facts
740
+ are capped at 8 KB. The model never sees the repository, the diff or the task prompt.
741
+
742
+ - **Cost.** One read-only dispatch per task, at effort `low`, when its facts change. Unchanged
743
+ facts are not dispatched again, because `inputs_hash` matches the stored summary. Each kind
744
+ of side dispatch is capped per run at `max(10, 3 × tasks)`.
745
+ - **When.** During `run`, the scheduler starts a detached `forge summarize PLAN --task ID` for
746
+ each task whose status, dwarf reply, attempt trail, verdict or retry count changed since its
747
+ last look. The first look at a task only remembers it. The scheduler never waits for a
748
+ summary, and a failed one changes nothing in the run. On a finished run, `forge control set
749
+ PLAN summaries on` starts `forge summarize` itself, with its output in `summaries.out`.
750
+ - **Output.** `summary.json` holds `text`, `sentence`, `model`, `generated_at`, `inputs_hash`
751
+ and `sources` (the attempts and findings the facts came from). The prompt asks for 3 to 5
752
+ short lines. A reply that is not a JSON object with `text` and `sentence`, or whose text runs
753
+ past 8 lines, is rejected: the previous `summary.json` stays and `summary.error` says why.
754
+ - **Commands.** `forge summarize PLAN [--task ID] [--force] [--json]`. `--force` dispatches even
755
+ when the facts did not change. `--json` prints one object per task: `task`, `status`, `reason`.
756
+ `forge control set PLAN summaries on|off` sets the plan. `--task ID on|off|inherit` sets one
757
+ task; its own `on` or `off` overrides the plan, and `inherit` drops that override.
758
+ - **Model.** `--summaries-model SPEC` is required with summaries on, and it must resolve;
759
+ otherwise `plan` exits `2`. Set a user default with `forge config set summaries.model SPEC`.
760
+ - **Off.** With `--summaries off`, no setting, or `FORGE_SUMMARIES=off`, there is no dispatch and
761
+ no `summary.json`.
762
+
763
+ Files it adds: the plan files `summaries` and `summaries_model`; `summaries.out`; and per task
764
+ `tasks/<id>/summary.json`, `summary.error` (after a failed reply) and `tasks/<id>/summaries`
765
+ (`on` or `off`, the task's override). Its events are `side_dispatch` (kind `summary`) and the
766
+ `side_summary` role in the dataset.
767
+
643
768
  ## Severity, thresholds and known issues
644
769
 
645
770
  QA labels each finding `- [P0..P3][CONFIRMED|PLAUSIBLE] file:line — what breaks (input)`:
@@ -748,6 +873,11 @@ as `retry` does (same findings carry-forward, same pinned base, same cumulative
748
873
  tasks keep running; dependents wait for the task to merge. It applies per invocation (not
749
874
  remembered), never to `TIMEOUT`/`ERROR`/`CONFLICT` or an `INVALIDATED` merge, and never after a retry that
750
875
  changed nothing (`tasks/<id>/noretry`). Every entry is logged in `tasks/<id>/attempts.tsv`.
876
+ An attempt that carries retry findings also gets one row in `tasks/<id>/retry_sources.tsv`:
877
+ the attempt number, the source of those findings (`review`, `prereview`, `bounce`, `message` or
878
+ `answer`) and the epoch time. A row for the same attempt replaces the earlier one, because an
879
+ infrastructure stop refunds the attempt and its restart runs the same number again. forge-ui's
880
+ attempt trail reads this file.
751
881
 
752
882
  **Escalation after repeated failures.** In forge's history the first three attempts at a task
753
883
  pass review at about the same rate (43%, 42%, 47%), and the fourth and later at 29%, whether
@@ -868,7 +998,9 @@ The choices:
868
998
  ([below](#accepting-splitting-combining-and-the-whole-run-review)).
869
999
 
870
1000
  A live scheduler takes the same decision as `forge control retry <plan> <id> --decide …` (or
871
- `--dwarf`), with `--reason` and `--approved`; that only queues the request. The answer is appended
1001
+ `--dwarf`), and an accept as `forge control accept <plan> <id>`, each with `--reason` and
1002
+ `--approved`; that only queues the request. An accepted task merges and its dependents start in
1003
+ the same run (#138). The answer is appended
872
1004
  to `tasks/<id>/decisions.tsv` (epoch, attempt, choice, reason). The run summary lists these tasks
873
1005
  under `waiting for your decision:`. A run that ends with such a task unmerged exits 5.
874
1006
 
@@ -1117,6 +1249,7 @@ removes what it created.
1117
1249
  ```
1118
1250
  <plan-dir>/tasks/<id>/approach.md intended approach, if planned
1119
1251
  <plan-dir>/tasks/<id>/risk low|medium|high, recorded only (#122), if rated
1252
+ <plan-dir>/tasks/<id>/retry_sources.tsv attempt, source, epoch: why each retried attempt ran (#133)
1120
1253
  <repo>/.forge/ project memory (survives the run)
1121
1254
  <repo>/../.forge-worktrees/<run-id>/<task-id> task worktree
1122
1255
  <repo>/../.forge-worktrees/<run-id>/_integration integration worktree
@@ -86,7 +86,8 @@ execution instructions. Review snapshots use self-contained object packs and one
86
86
  the repo's dependency directories (`node_modules`, `.venv`, `vendor`, Mix's `deps` and the others
87
87
  listed under [worktree setup](decompose.md#worktree-setup)) linked in, at the root and in workspace
88
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).
89
+ [worktree setup](decompose.md#worktree-setup). The snapshot is removed when the review ends
90
+ (`FORGE_KEEP_SNAPSHOTS=1` keeps it).
90
91
 
91
92
  Optional [Ripwire context](ripwire.md) is enabled by default. Use `--no-ripwire`
92
93
  or `FORGE_RIPWIRE=off` to disable preparation and installation offers.
package/references/ui.md CHANGED
@@ -31,6 +31,7 @@ run goes on, with the same exit code.
31
31
  request until the scheduler applies or refuses it. Each infrastructure pause gets a line: what
32
32
  is paused, why, its tasks and the time left. Each is one `forge control` call; the change is
33
33
  confirmed first and logged in `control.log`.
34
+ - **Brief questions and summaries:** forge-ui can answer a brief question and turn summaries on or off (for a run or one task), both through forge commands: `forge brief answer` and `forge control set summaries`.
34
35
  - **Open findings and issues:** the findings a run (or all of its repository's runs) left open,
35
36
  filed as GitHub issues or dismissed through `forge issues`.
36
37
  - **Delete a run:** a dry run, then `forge runs rm`: the dataset keeps the traces, an archive is
@@ -69,7 +70,9 @@ run goes on, with the same exit code.
69
70
  port in use, …) that several tasks' failed commands met gets one banner in the run header.
70
71
  - **Opening a node** shows its attempts, dwarves and reviews, and an inspector with the prompt
71
72
  that launched each one, the model, timings by phase, tokens, verdicts and the P0–P3 findings
72
- of every review (the final review's included).
73
+ of every review (the final review's included). A task's inspector opens on its header, its attempt trail
74
+ with each attempt's reason, its Summary and its Questions (brief questions); Run details has a Retro section
75
+ when retro mode wrote one.
73
76
  - **Solo run:** one task: its attempts, specs, prompts and the final messages.
74
77
  - It refreshes every two seconds while something runs (five otherwise) while the tab is
75
78
  visible, so a run can be watched as it goes. A run can also be replayed from its record.
@@ -150,7 +153,7 @@ bash <skill_dir>/scripts/forge-solo.sh "$FORGE_RUN" --repo "$REPO" --dwarf <spec
150
153
  | `FORGE_UI_BROWSER=off` | print the link, never open a browser |
151
154
  | `FORGE_UI_PORT` | preferred port, default `8765`; `--port` wins; a taken port falls back to a free one |
152
155
  | `FORGE_UI_IDLE_S` | idle seconds before the server exits, default `14400`; `0` never |
153
- | `FORGE_RUN_REGISTRY=off` | runs stop registering themselves (`--ui` and `forge ui open DIR` still register the run they open) |
156
+ | `FORGE_RUN_REGISTRY=off` | runs stop registering themselves (`--ui` and `forge ui open DIR` still register the run they open), and stop writing forge's location list (`<config home>/forge/locations.jsonl`) |
154
157
 
155
158
  ## One shared server
156
159
 
@@ -59,6 +59,20 @@ forge_review_snapshot() ( # source, baseline tree, final tree, destination
59
59
 
60
60
  )
61
61
 
62
+ # A review snapshot is a full export of the reviewed tree plus a git store, as large as the repository's
63
+ # tree, and nothing reads it once its review is over: the fingerprint check that ends the review is its
64
+ # last use (#139). review.base, review.deps, the prompt, the log and the verdict sit beside it and stay.
65
+ # FORGE_KEEP_SNAPSHOTS=1 keeps it, for debugging. Only a directory named like a snapshot is removed, never
66
+ # a link (rm -rf does not follow the dependency links forge_review_deps put inside it).
67
+ forge_drop_snapshot() { # review snapshot dir; always returns 0
68
+ local dir="${1:-}"
69
+ [ -n "$dir" ] && [ "${FORGE_KEEP_SNAPSHOTS:-0}" != 1 ] || return 0
70
+ case "${dir##*/}" in review|review-*) ;; *) return 0 ;; esac
71
+ [ -d "$dir" ] && [ ! -L "$dir" ] || return 0
72
+ rm -rf -- "$dir" 2>/dev/null
73
+ return 0
74
+ }
75
+
62
76
  # Where package managers install into a checkout: npm and bower, Python virtualenvs, Go, PHP and Ruby
63
77
  # vendor dirs, Bundler's config, CocoaPods, Mix (deps, _build), Dart, Elm and SwiftPM (#127). The same
64
78
  # names as forge-fail-first.py's DEP_DIRS. Only a directory the snapshot does not hold is linked, so a
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env python3
2
+ """Brief mode: each task's open questions, asked before the task starts.
3
+
4
+ write PLAN [--task ID] [--jobs N] [--force]
5
+ One read-only side dispatch per task that has no brief.json (earliest projected
6
+ start first), stored as tasks/<id>/brief.json and brief.parked.json.
7
+ show PLAN [--task ID] [--json]
8
+ Every question with its state, flagged open questions first.
9
+ answer PLAN TASK QID TEXT [--actor A] [--file F]
10
+ Record an answer. Before the task starts it goes to brief.answers.json; after,
11
+ to brief.late.json. A late answer prints the tasks.tsv row and the prompt.md
12
+ a follow-up needs, then the `forge control add` line that queues that row.
13
+ --file F reads the text (- is stdin).
14
+ stale PLAN MERGED-TASK
15
+ Flag open questions of dependents that have not started, when the merge changed
16
+ a file outside the task's declared files. A declared directory covers the paths
17
+ under it.
18
+
19
+ Exit codes: 0 ok, 2 usage or an unknown task or question (the message lists the valid
20
+ ids), 3 PLAN is not a plan dir or, for write and show, brief is off for it.
21
+ """
22
+ from __future__ import annotations
23
+
24
+ import argparse
25
+ import json
26
+ import sys
27
+ from pathlib import Path
28
+
29
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
30
+ import forge_brief # noqa: E402
31
+ import forge_brief.answers as answers # noqa: E402
32
+
33
+ REASONS = {
34
+ 'env': 'FORGE_BRIEF=off is set',
35
+ 'off': 'brief mode is off for this plan (plan --brief advisory|gated|strict)',
36
+ 'never-send': "the repository's privacy is never-send",
37
+ 'no-model': 'no brief model (plan --brief-model SPEC, or forge config set brief.model SPEC)',
38
+ }
39
+
40
+
41
+ def _parser() -> argparse.ArgumentParser:
42
+ parser = argparse.ArgumentParser(
43
+ prog='forge brief',
44
+ description="Each task's open questions, asked before the task starts.")
45
+ sub = parser.add_subparsers(dest='command', required=True)
46
+ write = sub.add_parser('write', help='write the questions of the tasks that have none yet')
47
+ write.add_argument('plan', help='the plan directory')
48
+ write.add_argument('--task', help='only this task')
49
+ write.add_argument('--jobs', type=int, default=forge_brief.DEFAULT_JOBS,
50
+ help='dispatches at once (default %(default)s)')
51
+ write.add_argument('--force', action='store_true', help='redo a task that already has a brief.json')
52
+ show = sub.add_parser('show', help='every question with its state, flagged first')
53
+ show.add_argument('plan', help='the plan directory')
54
+ show.add_argument('--task', help='only this task')
55
+ show.add_argument('--json', action='store_true', dest='as_json', help='machine-readable output')
56
+ answer = sub.add_parser('answer', help='record an answer to one question')
57
+ answer.add_argument('plan', help='the plan directory')
58
+ answer.add_argument('task', help='the task the question belongs to')
59
+ answer.add_argument('qid', help='the question id, such as q1')
60
+ answer.add_argument('text', nargs='?', default=None, help='the answer (or pass --file)')
61
+ answer.add_argument('--actor', default='cli', help='who is answering (default cli; forge-ui passes ui)')
62
+ answer.add_argument('--file', default=None, help='read the answer from this file, or - for stdin')
63
+ stale = sub.add_parser('stale', help="flag dependents' open questions after a merge outside its files")
64
+ stale.add_argument('plan', help='the plan directory')
65
+ stale.add_argument('task', help='the task that merged')
66
+ return parser
67
+
68
+
69
+ def _say(result: dict) -> None:
70
+ if result['status'] == 'written':
71
+ detail = '%d question(s)' % result['questions']
72
+ if result['parked']:
73
+ detail += ', %d parked' % result['parked']
74
+ elif result['status'] == 'error':
75
+ detail = 'writer failed (%s); no questions' % result['reason']
76
+ else:
77
+ detail = 'skipped (%s)' % result['reason']
78
+ sys.stdout.write('%s: %s\n' % (result['task'], detail))
79
+ sys.stdout.flush()
80
+
81
+
82
+ def _ids(ids) -> str:
83
+ return ', '.join(ids) if ids else '(none)'
84
+
85
+
86
+ def main(argv=None) -> int:
87
+ args = _parser().parse_args(argv)
88
+ if args.command == 'write' and args.jobs < 1:
89
+ sys.stderr.write('forge brief write: --jobs must be at least 1\n')
90
+ return 2
91
+ try:
92
+ if args.command == 'write':
93
+ forge_brief.write(args.plan, task=args.task, jobs=args.jobs, force=args.force, progress=_say)
94
+ return 0
95
+ if args.command == 'answer':
96
+ result = answers.answer(args.plan, args.task, args.qid, text=args.text,
97
+ actor=args.actor, file=args.file)
98
+ sys.stdout.write(result['message'])
99
+ return 0
100
+ if args.command == 'stale':
101
+ for task, qid in answers.stale(args.plan, args.task):
102
+ sys.stdout.write('%s/%s\n' % (task, qid))
103
+ return 0
104
+ found = forge_brief.collect(args.plan, task=args.task)
105
+ except forge_brief.NotAPlan as error:
106
+ sys.stderr.write('forge brief: not a plan dir: %s\n' % error)
107
+ return 3
108
+ except forge_brief.BriefOff as error:
109
+ sys.stderr.write('forge brief: %s\n' % REASONS.get(error.reason, error.reason))
110
+ return 3
111
+ except forge_brief.UnknownTask as error:
112
+ sys.stderr.write('forge brief: no such task: %s\n' % error)
113
+ return 2
114
+ except answers.NoSuchTask as error:
115
+ sys.stderr.write('forge brief: no such task: %s\nvalid tasks: %s\n' % (error.task, _ids(error.valid)))
116
+ return 2
117
+ except answers.NoSuchQuestion as error:
118
+ sys.stderr.write('forge brief: no such question: %s\nvalid questions for %s: %s\n'
119
+ % (error.qid, error.task, _ids(error.valid)))
120
+ return 2
121
+ except answers.Usage as error:
122
+ sys.stderr.write('forge brief: %s\n' % error)
123
+ return 2
124
+ if args.as_json:
125
+ sys.stdout.write(json.dumps(found, ensure_ascii=False, indent=2, sort_keys=True) + '\n')
126
+ else:
127
+ sys.stdout.write(forge_brief.render(found))
128
+ return 0
129
+
130
+
131
+ if __name__ == '__main__':
132
+ sys.exit(main())
@@ -39,7 +39,10 @@ sys.path.insert(0, str(SKILL / 'ui'))
39
39
  # `plan` writes itself (routing, Jev's frozen selection) or that a fresh plan decides (exploration).
40
40
  OPTION_FILES = ('no_ripwire', 'no_memory', 'yolo_dwarf', 'yolo_qa', 'reviewer_session', 'implementer_session', 'fast',
41
41
  'pre_review_tests', 'pre_review_parallel', 'qa_threshold', 'timeout', 'verify_retries', 'verify_cmd',
42
- 'verify_parallel', 'setup_cmd', 'final_qa', 'shadow_qa', 'shadow_rate', 'escalate_after', 'fail_first', 'profile.json')
42
+ 'verify_parallel', 'setup_cmd', 'final_qa', 'shadow_qa', 'shadow_rate', 'escalate_after', 'fail_first', 'profile.json',
43
+ 'retro_mode', 'brief', 'brief_scope', 'brief_model', 'summaries', 'summaries_model')
44
+ # The feature files are rewritten from the source's effective settings (copy_plan), not only copied.
45
+ FEATURE_FILES = ('retro_mode', 'brief', 'brief_scope', 'brief_model', 'summaries', 'summaries_model')
43
46
  PLAN_FILES = ('repo.identity', 'goal.txt', 'request.md')
44
47
  TASK_FILES = ('prompt.md', 'approach.md')
45
48
  NAME = re.compile(r'[^A-Za-z0-9._-]+')
@@ -199,6 +202,13 @@ def copy_plan(src: dict, new: dict, rows: list) -> None:
199
202
  shutil.copy2(plan / name, out / name)
200
203
  if (plan / 'verify.d').is_dir():
201
204
  shutil.copytree(plan / 'verify.d', out / 'verify.d')
205
+ # Retro, brief and summaries as the source resolved them, `off` included: the new plan has
206
+ # no waves.tsv yet, so a missing file would let its `plan` take the user setting instead.
207
+ from forge_side import plan_files
208
+ for name in FEATURE_FILES:
209
+ (out / name).unlink(missing_ok=True)
210
+ for name, value in plan_files(plan).items():
211
+ (out / name).write_text(value + '\n')
202
212
  for row in rows:
203
213
  for name in TASK_FILES:
204
214
  if (plan / 'tasks' / row['id'] / name).is_file():
@@ -1,9 +1,13 @@
1
1
  #!/usr/bin/env python3
2
- """forge config <command>: one view of every config source, and safe edits for the per-repo ones.
2
+ """forge config <command>: one view of every config source, and safe edits for the per-repo files and the user feature settings.
3
3
 
4
- show [--repo DIR] [--json] registry, Jev, decide, profiles, the repo's .forge files, dataset and FORGE_* env
4
+ show [--repo DIR] [--json] registry, Jev, decide, features, profiles, the repo's .forge files, dataset and FORGE_* env
5
5
  set <key> <value> [--repo DIR] [--json] repo.verify | repo.setup | repo.verify-subset | decide.gate.<gate>[.provider|.model]
6
+ | retro | brief | brief.scope | brief.model | summaries | summaries.model
7
+ | storage.compact | storage.warn-gb
6
8
  unset <key> [--repo DIR] [--json] repo.verify | repo.setup | repo.verify-subset
9
+ | retro | brief | brief.scope | brief.model | summaries | summaries.model
10
+ | storage.compact | storage.warn-gb
7
11
  profile list|show|create|edit|set|unset|rm|use [--repo DIR] [--json]
8
12
  profiles in decide.json; --repo writes the repo file, otherwise the user file
9
13
 
@@ -16,6 +20,16 @@ to off. jev.enabled is gone; set a gate with decide.gate.<gate>. The registry is
16
20
  read-only here: the skill dir is often a live symlink to a checkout, so an edit would change
17
21
  runs already in progress; edit the checkout.
18
22
 
23
+ `retro`, `brief`, `brief.scope`, `brief.model`, `summaries` and `summaries.model` are the user-level
24
+ feature settings (decide.json `features`). `brief` is the level (off, advisory, gated or strict);
25
+ `summaries` is the mode (off or on); `brief.scope` is task, wave or plan. A model is a spec, checked
26
+ the way a profile routing spec is. Setting brief or summaries on with no model is stored; refusing
27
+ to plan without one is a later step. `storage.compact` (auto, the default, or off) is whether forge
28
+ compacts a repository's idle runs in the background when a run starts, and `storage.warn-gb` (a
29
+ number of gigabytes, 20 by default, or off) when it warns at run start that the repository's forge
30
+ files have grown past it (#139; forge_storage.py). A bad value exits 2 and writes nothing. Unset removes that
31
+ field and keeps every other key. These keys ignore `--repo`: they always write the user file.
32
+
19
33
  Only the three per-repo files are ever read for content; cloudflare.env never is. Values of FORGE_*
20
34
  variables whose name contains TOKEN, KEY, SECRET or PASSWORD show as "<set>". A provider key never
21
35
  appears in show.
@@ -54,6 +68,7 @@ from forge_decide import GATES, MODES, load_repo, load_user, save_repo, save_use
54
68
  from forge_decide import profiles
55
69
  from forge_decide.migrate import run as migrate_run
56
70
  from forge_decide.providers import spec_for_site
71
+ from forge_side import (BRIEF_LEVELS, BRIEF_SCOPES, FEATURE_KEYS, ON_OFF, STORAGE_COMPACT, stored_features)
57
72
 
58
73
  REPO_FILES = ('verify', 'setup', 'verify-subset')
59
74
  KEYS = tuple('repo.' + n for n in REPO_FILES)
@@ -343,10 +358,17 @@ def _print_decide(decide):
343
358
  print(' shadowed: %s: repo %r, user %r' % (entry.get('key'), entry.get('repo'), entry.get('user')))
344
359
 
345
360
 
361
+ def _print_features(features):
362
+ print('features:')
363
+ for key in FEATURE_KEYS:
364
+ value = features.get(key)
365
+ print(' %s: %s' % (key, '(none)' if value is None else value))
366
+
367
+
346
368
  def cmd_show(args):
347
369
  root = repo_root(args.repo, required=False)
348
370
  data = dict(registry=registry_block(), jev=jev_block(), decide=decide_block(root),
349
- profiles=profiles_payload(show_profiles_repo(root)))
371
+ features=stored_features(), profiles=profiles_payload(show_profiles_repo(root)))
350
372
  if root:
351
373
  data['repo'] = repo_block(root)
352
374
  data['dataset'] = dataset_block()
@@ -363,6 +385,7 @@ def cmd_show(args):
363
385
  print('jev: %s (%s, %s)' % ('enabled' if jev['enabled'] else 'disabled', jev['path'],
364
386
  'present' if jev['exists'] else 'absent'))
365
387
  _print_decide(data['decide'])
388
+ _print_features(data['features'])
366
389
  print(profiles_text(data['profiles'], heading=True))
367
390
  if root:
368
391
  print('repo: %s' % root)
@@ -379,9 +402,10 @@ def cmd_show(args):
379
402
  # ----------------------------------------------------------------------------------- set / unset
380
403
 
381
404
  def check_key(key):
382
- if key not in KEYS:
383
- raise Invalid('unknown key %r; valid keys: %s, decide.gate.<gate>, '
384
- 'decide.gate.<gate>.provider, decide.gate.<gate>.model' % (key, ', '.join(KEYS)))
405
+ if key not in KEYS and key not in FEATURE_KEYS:
406
+ raise Invalid('unknown key %r; valid keys: %s, %s, decide.gate.<gate>, '
407
+ 'decide.gate.<gate>.provider, decide.gate.<gate>.model'
408
+ % (key, ', '.join(KEYS), ', '.join(FEATURE_KEYS)))
385
409
 
386
410
 
387
411
  def decide_target(key):
@@ -471,6 +495,8 @@ def emit(args, key, previous, value):
471
495
  def cmd_set(args):
472
496
  if args.key == 'jev.enabled':
473
497
  raise Invalid('jev.enabled is gone; set a gate with decide.gate.<gate>')
498
+ if args.key in FEATURE_KEYS:
499
+ return set_feature(args)
474
500
  if args.key not in KEYS:
475
501
  return set_decide(args)
476
502
  root = repo_root(args.repo, required=True)
@@ -494,6 +520,8 @@ def cmd_set(args):
494
520
  def cmd_unset(args):
495
521
  if args.key == 'jev.enabled':
496
522
  raise Invalid('jev.enabled is gone; set a gate with decide.gate.<gate>')
523
+ if args.key in FEATURE_KEYS:
524
+ return unset_feature(args)
497
525
  if decide_target(args.key):
498
526
  raise Invalid('set the mode to off')
499
527
  check_key(args.key)
@@ -512,6 +540,145 @@ def cmd_unset(args):
512
540
  return 0
513
541
 
514
542
 
543
+ # The user `features` object. `brief` is the level; `summaries` is the mode. A model is optional
544
+ # here: planning refuses a feature that is on with no model, and this command only stores it.
545
+ _FEATURE_FIELD = {
546
+ 'retro': ('retro', None),
547
+ 'brief': ('brief', 'level'),
548
+ 'brief.scope': ('brief', 'scope'),
549
+ 'brief.model': ('brief', 'model'),
550
+ 'summaries': ('summaries', 'mode'),
551
+ 'summaries.model': ('summaries', 'model'),
552
+ 'storage.compact': ('storage', 'compact'),
553
+ 'storage.warn-gb': ('storage', 'warn_gb'),
554
+ }
555
+
556
+
557
+ def _feature_value(key, value):
558
+ """The value to store, or Invalid. Checked before anything is written."""
559
+ if key in ('retro', 'summaries'):
560
+ if value not in ON_OFF:
561
+ raise Invalid('%s must be off or on' % key)
562
+ return value
563
+ if key == 'brief':
564
+ if value not in BRIEF_LEVELS:
565
+ raise Invalid('brief must be off, advisory, gated or strict')
566
+ return value
567
+ if key == 'storage.compact':
568
+ if value not in STORAGE_COMPACT:
569
+ raise Invalid('storage.compact must be auto or off')
570
+ return value
571
+ if key == 'storage.warn-gb':
572
+ if value != 'off':
573
+ try:
574
+ number = float(value)
575
+ except ValueError:
576
+ number = 0
577
+ if not (0 < number < float('inf')):
578
+ raise Invalid('storage.warn-gb must be a number of gigabytes over 0, or off')
579
+ return value
580
+ if key == 'brief.scope':
581
+ if value not in BRIEF_SCOPES:
582
+ raise Invalid('brief.scope must be task, wave or plan')
583
+ return value
584
+ reason = profiles.check_spec(value)
585
+ if reason:
586
+ raise Invalid(reason)
587
+ return value
588
+
589
+
590
+ def _features_map(data):
591
+ features = data.get('features')
592
+ if not isinstance(features, dict):
593
+ features = {}
594
+ data['features'] = features
595
+ return features
596
+
597
+
598
+ def _feature_child(features, section):
599
+ child = features.get(section)
600
+ if not isinstance(child, dict):
601
+ child = {}
602
+ features[section] = child
603
+ return child
604
+
605
+
606
+ def _stored_feature(data, key):
607
+ features = data.get('features')
608
+ if not isinstance(features, dict):
609
+ return None
610
+ section, field = _FEATURE_FIELD[key]
611
+ if field is None:
612
+ value = features.get(section)
613
+ return value if isinstance(value, str) else None
614
+ child = features.get(section)
615
+ if not isinstance(child, dict):
616
+ return None
617
+ value = child.get(field)
618
+ return value if isinstance(value, str) else None
619
+
620
+
621
+ def _put_feature(data, key, value):
622
+ features = _features_map(data)
623
+ section, field = _FEATURE_FIELD[key]
624
+ if field is None:
625
+ features[section] = value
626
+ return
627
+ _feature_child(features, section)[field] = value
628
+
629
+
630
+ def _drop_feature(data, key):
631
+ """Remove one field. Empty brief/summaries/features objects go too; other keys stay."""
632
+ previous = _stored_feature(data, key)
633
+ features = data.get('features')
634
+ if not isinstance(features, dict):
635
+ return None
636
+ section, field = _FEATURE_FIELD[key]
637
+ if field is None:
638
+ features.pop(section, None)
639
+ else:
640
+ child = features.get(section)
641
+ if isinstance(child, dict):
642
+ child.pop(field, None)
643
+ if not child:
644
+ features.pop(section, None)
645
+ if not features:
646
+ data.pop('features', None)
647
+ return previous
648
+
649
+
650
+ def set_feature(args):
651
+ """Write one feature key into the user decide.json. `--repo` is ignored."""
652
+ value = _feature_value(args.key, args.value)
653
+ result = migrate_run()
654
+ if result['status'] == 'migrated':
655
+ print('forge config: migrated jev.json into %s first' % user_path(), file=sys.stderr)
656
+ data, error = load_user()
657
+ if error:
658
+ raise Invalid(error)
659
+ previous = _stored_feature(data, args.key)
660
+ _put_feature(data, args.key, value)
661
+ data.setdefault('version', 1)
662
+ save_user(data)
663
+ emit(args, args.key, previous, value)
664
+ return 0
665
+
666
+
667
+ def unset_feature(args):
668
+ """Remove one feature key from the user file. A missing file is left missing."""
669
+ if not user_path().exists():
670
+ emit(args, args.key, None, None)
671
+ return 0
672
+ data, error = load_user()
673
+ if error:
674
+ raise Invalid(error)
675
+ previous = _drop_feature(data, args.key)
676
+ if previous is not None:
677
+ save_user(data)
678
+ emit(args, args.key, previous, None)
679
+ return 0
680
+
681
+
515
682
  def set_decide(args):
516
683
  """Write one decide key at the user level: a mode through `forge decide gate`, a provider or model
517
684
  through _write_user_field. --repo is only the repo whose effective settings are read for `previous`."""
@@ -1042,17 +1209,17 @@ def add_profile_parser(sub):
1042
1209
  def parser():
1043
1210
  p = argparse.ArgumentParser(prog='forge config', description=__doc__.split('\n\n')[0])
1044
1211
  sub = p.add_subparsers(dest='cmd', required=True)
1045
- s = sub.add_parser('show', help="every config source: registry, decide, profiles, the repo's .forge files, dataset, FORGE_* env")
1212
+ s = sub.add_parser('show', help="every config source: registry, decide, features, profiles, the repo's .forge files, dataset, FORGE_* env")
1046
1213
  s.add_argument('--repo')
1047
1214
  s.add_argument('--json', action='store_true')
1048
1215
  s.set_defaults(fn=cmd_show)
1049
- s = sub.add_parser('set', help='set repo.verify, repo.setup, repo.verify-subset or decide.gate.<gate>')
1216
+ s = sub.add_parser('set', help='set a repo file, a decide gate, or a user feature (retro, brief, summaries)')
1050
1217
  s.add_argument('key')
1051
1218
  s.add_argument('value')
1052
1219
  s.add_argument('--repo')
1053
1220
  s.add_argument('--json', action='store_true')
1054
1221
  s.set_defaults(fn=cmd_set)
1055
- s = sub.add_parser('unset', help='remove repo.verify, repo.setup or repo.verify-subset')
1222
+ s = sub.add_parser('unset', help='remove a repo file or a user feature (retro, brief, summaries)')
1056
1223
  s.add_argument('key')
1057
1224
  s.add_argument('--repo')
1058
1225
  s.add_argument('--json', action='store_true')