@giamme/forge 0.18.0 → 0.20.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 (93) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/README.md +1 -0
  3. package/SKILL.md +19 -2
  4. package/VERSION +1 -1
  5. package/docs/artifacts.md +25 -1
  6. package/docs/commands.md +217 -18
  7. package/docs/decomposed-runs.md +114 -1
  8. package/docs/development.md +2 -1
  9. package/docs/forge-ui.md +138 -18
  10. package/docs/memory.md +25 -4
  11. package/docs/models.md +8 -0
  12. package/docs/reviews.md +122 -0
  13. package/forge +26 -3
  14. package/package.json +2 -1
  15. package/references/dataset.md +20 -1
  16. package/references/decompose.md +641 -41
  17. package/references/harnesses.md +18 -3
  18. package/references/memory.md +30 -5
  19. package/references/planning.md +43 -14
  20. package/references/ui.md +53 -6
  21. package/registry.tsv +8 -3
  22. package/scripts/forge-brief.py +88 -3
  23. package/scripts/forge-compare.py +4 -3
  24. package/scripts/forge-contract.py +202 -27
  25. package/scripts/forge-control.py +117 -5
  26. package/scripts/forge-dispatch.sh +34 -5
  27. package/scripts/forge-findings.py +675 -0
  28. package/scripts/forge-group.py +496 -0
  29. package/scripts/forge-groups.py +89 -0
  30. package/scripts/forge-handoff.py +1128 -0
  31. package/scripts/forge-issues.py +228 -97
  32. package/scripts/forge-lib-group.sh +641 -0
  33. package/scripts/forge-lib-plans.sh +339 -3
  34. package/scripts/forge-lib-task.sh +197 -4
  35. package/scripts/forge-memory.sh +711 -17
  36. package/scripts/forge-parallel.sh +721 -38
  37. package/scripts/forge-planner.py +104 -8
  38. package/scripts/forge-route.py +190 -12
  39. package/scripts/forge-runs.py +9 -5
  40. package/scripts/forge-schedule.py +417 -52
  41. package/scripts/forge-solo.sh +2 -0
  42. package/scripts/forge-sweep.py +199 -44
  43. package/scripts/forge-worktrees.py +243 -0
  44. package/scripts/forge_brief/__init__.py +294 -50
  45. package/scripts/forge_brief/answers.py +58 -11
  46. package/scripts/forge_brief/proposals.py +1630 -0
  47. package/scripts/forge_dataset/efforts.py +4 -3
  48. package/scripts/forge_dataset/export.py +24 -12
  49. package/scripts/forge_dataset/facts.py +5 -3
  50. package/scripts/forge_dataset/forecast.py +8 -18
  51. package/scripts/forge_dataset/harvest.py +204 -9
  52. package/scripts/forge_dataset/history.py +11 -6
  53. package/scripts/forge_dataset/importer.py +65 -1
  54. package/scripts/forge_dataset/names.py +66 -0
  55. package/scripts/forge_dataset/reviewers.py +5 -2
  56. package/scripts/forge_dataset/risk.py +6 -3
  57. package/scripts/forge_dataset/routing.py +6 -1
  58. package/scripts/forge_findings/__init__.py +17 -0
  59. package/scripts/forge_findings/apply.py +441 -0
  60. package/scripts/forge_findings/status.py +43 -0
  61. package/scripts/forge_findings/store.py +583 -0
  62. package/scripts/forge_findings/tags.py +53 -0
  63. package/scripts/forge_findings/triage.py +603 -0
  64. package/scripts/forge_groups/__init__.py +308 -0
  65. package/scripts/forge_groups/attribute.py +289 -0
  66. package/scripts/forge_groups/review.py +286 -0
  67. package/scripts/forge_identity.py +327 -0
  68. package/scripts/forge_memory_list.py +7 -3
  69. package/scripts/forge_owner.py +152 -0
  70. package/scripts/forge_side/__init__.py +228 -38
  71. package/ui/docs/api.md +303 -29
  72. package/ui/forge_ui/control.py +1018 -6
  73. package/ui/forge_ui/executions.py +8 -1
  74. package/ui/forge_ui/export.py +31 -4
  75. package/ui/forge_ui/groups.py +264 -0
  76. package/ui/forge_ui/models.py +70 -8
  77. package/ui/forge_ui/projects.py +209 -22
  78. package/ui/forge_ui/reader.py +262 -19
  79. package/ui/forge_ui/server.py +4 -0
  80. package/ui/forge_ui/static/app.js +93 -13
  81. package/ui/forge_ui/static/briefview.js +350 -47
  82. package/ui/forge_ui/static/diffview.js +86 -1
  83. package/ui/forge_ui/static/findingsactions.js +201 -0
  84. package/ui/forge_ui/static/groupsview.js +332 -0
  85. package/ui/forge_ui/static/index.html +3 -0
  86. package/ui/forge_ui/static/panel.js +127 -7
  87. package/ui/forge_ui/static/projectsview.js +764 -30
  88. package/ui/forge_ui/static/runmodel.js +14 -3
  89. package/ui/forge_ui/static/storageview.js +91 -10
  90. package/ui/forge_ui/static/style.css +138 -5
  91. package/ui/forge_ui/static/triageview.js +423 -0
  92. package/ui/forge_ui/static/worktreesview.js +233 -12
  93. package/ui/forge_ui/storage.py +14 -0
@@ -15,6 +15,9 @@
15
15
  record_attempt() { # record_attempt <plan> <id>
16
16
  local tdir="$1/tasks/$2" cls=""
17
17
  [ "$(task_status "$1" "$2")" = BLOCKED ] && return 0 # never started: nothing to audit
18
+ # Implemented, awaiting its group's review (#140): no review judged this attempt yet. The row is
19
+ # written when the group verdict judges it (record_judged_attempt).
20
+ [ "$(task_status "$1" "$2")" = IMPLEMENTED ] && return 0
18
21
  [ "$(task_status "$1" "$2")" = INFRA ] && cls="$(sed -n 's/^class=//p' "$tdir/infra.txt" 2>/dev/null | head -1)"
19
22
  # A send-back that no reviewer judged keeps the task status FAIL; attempts.tsv names its kind.
20
23
  local st; st="$(task_status "$1" "$2")"
@@ -24,6 +27,96 @@ record_attempt() { # record_attempt <plan> <id>
24
27
  "$st" "$cls" "$(field "$1/tasks.tsv" "$2" dwarf)" >> "$tdir/attempts.tsv"
25
28
  }
26
29
 
30
+ # The row a group verdict writes for a member's attempt (#140), in record_attempt's format, with the
31
+ # status the verdict gave it and the attempt the member is on now.
32
+ record_judged_attempt() { # record_judged_attempt <plan> <id> <status>
33
+ local tdir="$1/tasks/$2"
34
+ printf '%s\t%s\t%s\t%s\t%s\n' "$(date +%s)" "$(cat "$tdir/attempt" 2>/dev/null || echo 0)" \
35
+ "$3" "" "$(field "$1/tasks.tsv" "$2" dwarf)" >> "$tdir/attempts.tsv"
36
+ }
37
+
38
+ # What follows every attempt that was judged: the escalation check, then the decision a FAIL may stop
39
+ # for. do_task runs it after its own attempt, and a group verdict runs it after judging a member's.
40
+ # An IMPLEMENTED or STALE attempt was not judged, so neither step runs for it.
41
+ post_attempt() { # post_attempt <plan> <id>
42
+ local crc=0 stop_before
43
+ [ "$(task_status "$1" "$2")" = IMPLEMENTED ] && return 0
44
+ # A STALE attempt (its prompt changed while it ran, #150) was not judged and spends nothing.
45
+ [ "$(task_status "$1" "$2")" = STALE ] && return 0
46
+ # A FAIL whose every blocking finding needs a file this task does not declare is the plan's fault (#149):
47
+ # stop for a decision now, before the escalation check can write a marker for a model that cannot help.
48
+ if outside_stop_check "$1" "$2"; then
49
+ python3 "$SKILL_DIR/scripts/forge-ledger.py" append "$1" "$2" >/dev/null 2>&1 \
50
+ || note "$2: could not add this review to the findings ledger"
51
+ # A write that fails leaves the task FAIL. Continuing would append this review to the
52
+ # ledger again and let the escalation check mark a model that cannot fix the plan.
53
+ stop_for_decision "$1" "$2" plan || return 1
54
+ return 0
55
+ else
56
+ rm -f "$1/tasks/$2/outside.json"
57
+ fi
58
+ # The retry policy's state (escalation.next or escalation.stop), decided now rather than
59
+ # at the next retry so a spent retry budget still reports it and the scheduler sees it.
60
+ stop_before="$(cat "$1/tasks/$2/escalation.stop" 2>/dev/null)"
61
+ python3 "$SKILL_DIR/scripts/forge-route.py" escalation --plan "$1" --task "$2" --check \
62
+ --qa-only-next "$(qa_only_next_flag "$1" "$2")" >/dev/null 2>&1 || crc=$?
63
+ # A FAIL that does not converge, or that the policy could not move to a stronger model, waits
64
+ # for a person (NEEDS_DECISION). attempts.tsv was written above and keeps FAIL.
65
+ decision_after_attempt "$1" "$2" "$stop_before" "$crc"
66
+ }
67
+
68
+ # Whether the last review's every blocking finding needs a file outside the task (#149). 0 only when the
69
+ # task is FAIL on a real review, at least one finding blocks at the task's threshold, each of those carries
70
+ # {outside=...}, and no path it names is declared by the task itself. Writes tasks/<id>/outside.json:
71
+ # [{path, owner, owners, owner_status}], owner_status being the owner's task_status (null for no owner).
72
+ # Any tool error returns non-zero and writes nothing.
73
+ outside_stop_check() { # outside_stop_check <plan> <id>
74
+ local PLAN="$1" id="$2" tdir="$1/tasks/$2" thr rep paths owned tmp="$1/tasks/$2/.outside.json.tmp" p
75
+ local -a plist=()
76
+ [ "$(task_status "$PLAN" "$id")" = FAIL ] || return 1
77
+ [ -s "$tdir/qa.last" ] || return 1
78
+ case "$(forge_verdict "$tdir/qa.last" 2>/dev/null)" in PASS|FAIL) ;; *) return 1 ;; esac
79
+ thr="$(qa_threshold_for "$PLAN" "$id")" || return 1
80
+ rep="$(python3 "$SKILL_DIR/scripts/forge-contract.py" outside --qa-last "$tdir/qa.last" --threshold "$thr" 2>/dev/null)" || return 1
81
+ paths="$(printf '%s' "$rep" | python3 -c '
82
+ import json, sys
83
+ rows = json.load(sys.stdin)
84
+ blocking = [r for r in rows if r.get("blocking")]
85
+ if not blocking or any(not r.get("outside") for r in blocking):
86
+ sys.exit(1)
87
+ seen = []
88
+ for r in blocking:
89
+ for p in r["outside"]:
90
+ if p not in seen:
91
+ seen.append(p)
92
+ print("\n".join(seen))
93
+ ' 2>/dev/null)" || return 1
94
+ [ -n "$paths" ] || return 1
95
+ while IFS= read -r p; do plist+=("$p"); done <<< "$paths"
96
+ owned="$(python3 "$SKILL_DIR/scripts/forge_owner.py" "$PLAN" "${plist[@]}" --task "$id" 2>/dev/null)" || return 1
97
+ printf '%s' "$owned" | python3 -c '
98
+ import json, os, sys
99
+ plan = sys.argv[1]
100
+ items = json.load(sys.stdin)["paths"]
101
+ if not items or any(i["outside"] is not True for i in items):
102
+ sys.exit(1)
103
+ def status(task):
104
+ base = os.path.join(plan, "tasks", task)
105
+ if os.path.exists(os.path.join(base, "merged")):
106
+ return "MERGED"
107
+ try:
108
+ with open(os.path.join(base, "status"), encoding="utf-8") as f:
109
+ return f.read().strip()
110
+ except OSError:
111
+ return "PENDING"
112
+ out = [{"path": i["path"], "owner": i["owner"], "owners": i["owners"],
113
+ "owner_status": status(i["owner"]) if i["owner"] else None} for i in items]
114
+ json.dump(out, sys.stdout, indent=1)
115
+ sys.stdout.write("\n")
116
+ ' "$PLAN" > "$tmp" 2>/dev/null && mv "$tmp" "$tdir/outside.json" || { rm -f "${tmp:?}"; return 1; }
117
+ return 0
118
+ }
119
+
27
120
  # --- infrastructure stops -------------------------------------------------------
28
121
  # A dispatch that failed because of quota, auth, a rate limit, the network or empty
29
122
  # output says nothing about the work. The task is marked INFRA and the attempt is not
@@ -389,6 +482,29 @@ carry_implementer_session() { # carry_implementer_session <tdir>
389
482
  }
390
483
 
391
484
  # --- reviewer-session continuation (plan --reviewer-session, an opt-in experiment) ------------
485
+ # reviewer_session_pick <plan> <rate>: the task ids whose reviews continue under
486
+ # --reviewer-session-rate, one per line. Within each difficulty, round(rate x n) tasks with the
487
+ # lowest sha256 of "<run id>/<task id>", so the halves are balanced by difficulty and stable.
488
+ reviewer_session_pick() {
489
+ python3 - "$1/tasks.tsv" "$(cat "$1/run_id" 2>/dev/null || basename "$1")" "$2" <<'PY'
490
+ import hashlib, sys
491
+ from collections import defaultdict
492
+ rows = [line.split('\t') for line in open(sys.argv[1], encoding='utf-8').read().splitlines()
493
+ if line and not line.startswith('#')]
494
+ run, rate = sys.argv[2], float(sys.argv[3])
495
+ tiers = defaultdict(list)
496
+ for row in rows:
497
+ tiers[row[2] if len(row) > 2 else ''].append(row[0])
498
+ keep = set()
499
+ for ids in tiers.values():
500
+ ids.sort(key=lambda i: hashlib.sha256(('%s/%s' % (run, i)).encode()).hexdigest())
501
+ keep.update(ids[:int(rate * len(ids) + 0.5)])
502
+ for row in rows:
503
+ if row[0] in keep:
504
+ print(row[0])
505
+ PY
506
+ }
507
+
392
508
  # review_session_decide <session-file> <resolved-file> <resolution-file> [harnesses]: whether this
393
509
  # round continues the earlier session. Prints `mode<TAB>reason<TAB>session`; the session is the
394
510
  # id to continue, and empty for every fresh answer.
@@ -502,6 +618,7 @@ decision_reason_text() { # decision_reason_text <reason>: what a reason in decis
502
618
  case "$1" in
503
619
  converging) echo "the last reviews failed one after another, most of their findings were new, and the worst severity did not improve: more attempts keep finding new problems instead of closing the old ones" ;;
504
620
  split) echo "the retry policy found no stronger model to escalate to after repeated failures on one: another attempt on the same model rarely passes" ;;
621
+ plan) echo "every blocking finding of the last review needs a change in a file this task does not declare: the plan, not the implementer, has to change" ;;
505
622
  cap) echo "the attempts spent across runs reach the task's cap (max_attempts, plus each retry=N a person granted): another attempt needs a person's retry=N" ;;
506
623
  *) echo "$1" ;;
507
624
  esac
@@ -596,6 +713,27 @@ stop_for_decision() { # stop_for_decision <plan> <id> <reason>...
596
713
  read -r used cap <<< "$(attempt_cap_of "$PLAN" "$id")"
597
714
  if [ "$cap" = - ]; then echo "Attempts used so far: $used (no cap)"; else echo "Attempts used so far: $used (attempts $used of $cap)"; fi
598
715
  echo
716
+ case ",${reasons// /}," in *,plan,*)
717
+ if [ -s "$tdir/outside.json" ]; then
718
+ echo "Files outside this task:"
719
+ python3 - "$tdir/outside.json" <<'PYEOF' 2>/dev/null
720
+ import json, sys
721
+ for item in json.load(open(sys.argv[1], encoding="utf-8")):
722
+ if item.get("owner"):
723
+ print(" %s \u2014 declared by %s (%s)" % (item["path"], item["owner"], item.get("owner_status") or "PENDING"))
724
+ else:
725
+ print(" %s \u2014 declared by no task" % item["path"])
726
+ PYEOF
727
+ echo
728
+ echo "Plan choices (this is a change of the plan, edit $PLAN/tasks.tsv):"
729
+ echo " 1. add the path to this task's files"
730
+ echo " 2. make this task depend on the owner (edit its deps)"
731
+ echo " 3. merge the two rows into one task"
732
+ echo " After editing tasks.tsv: forge-parallel.sh plan $PLAN again when no run is live, then"
733
+ echo " forge-parallel.sh retry $PLAN $id --decide retry=1 --reason \"...\" --approved"
734
+ echo
735
+ fi ;;
736
+ esac
599
737
  echo "Choices (each needs your reason; --approved says the decision is yours):"
600
738
  echo " N more attempts: forge-parallel.sh retry $PLAN $id --decide retry=N --reason \"...\" --approved"
601
739
  case ",${reasons// /}," in
@@ -628,7 +766,10 @@ decision_after_attempt() { # decision_after_attempt <plan> <id> <stop-before> <c
628
766
  python3 "$SKILL_DIR/scripts/forge-ledger.py" append "$PLAN" "$id" >/dev/null 2>&1 \
629
767
  || note "$id: could not add this review to the findings ledger"
630
768
  [ "$(task_status "$PLAN" "$id")" = FAIL ] || return 0
631
- if python3 "$SKILL_DIR/scripts/forge-ledger.py" signal "$tdir" >/dev/null 2>&1; then reasons="converging"; fi
769
+ # A scripted task's reviews judge the same command again, not findings a person closes one by one:
770
+ # no convergence count (#142).
771
+ if [ "$(field "$PLAN/tasks.tsv" "$id" dwarf)" != script ] \
772
+ && python3 "$SKILL_DIR/scripts/forge-ledger.py" signal "$tdir" >/dev/null 2>&1; then reasons="converging"; fi
632
773
  stop="$(cat "$tdir/escalation.stop" 2>/dev/null)"
633
774
  if [ -n "$stop" ] && { [ "$crc" = 3 ] || [ "$stop" != "$before" ]; }; then reasons="${reasons:+$reasons }split"; fi
634
775
  read -r used cap <<< "$(attempt_cap_of "$PLAN" "$id")"
@@ -826,7 +967,7 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
826
967
  # (default 3) the next attempt goes a tier up in the user's own pools instead of repeating
827
968
  # the dispatch whose fourth try passes least often, or the task stops with a split
828
969
  # suggestion.
829
- local cur next rc esc_source="" pinned="" has_pin=0
970
+ local cur next rc esc_source="" pinned="" has_pin=0 per_model=""
830
971
  cur="$(field "$T" "$id" dwarf)"
831
972
  [ -f "$tdir/escalation.pin" ] && [ ! -L "$tdir/escalation.pin" ] && has_pin=1
832
973
  if [ -n "$newdwarf" ]; then
@@ -853,7 +994,18 @@ prepare_retry() { # prepare_retry <plan> <id> [new-dwarf [decided]]
853
994
  return 3
854
995
  fi
855
996
  if [ -n "$next" ]; then
856
- note "$id: escalating from $cur to $next after $(cat "$PLAN/escalate_after" 2>/dev/null || echo 3) failed attempts on one model (--escalate-after 0 turns this off)"
997
+ # retry_per_model replaces escalate_after (forge-route.py escalation). The note names the
998
+ # count that moved the task, and does not point at a flag that no longer governs the plan.
999
+ per_model="$(tr -d '[:space:]' < "$PLAN/retry_per_model" 2>/dev/null || true)"
1000
+ case "$per_model" in
1001
+ [1-9]|[1-9][0-9]) ;;
1002
+ *) per_model="" ;;
1003
+ esac
1004
+ if [ -n "$per_model" ]; then
1005
+ note "$id: escalating from $cur to $next after $per_model failed attempts on one model"
1006
+ else
1007
+ note "$id: escalating from $cur to $next after $(cat "$PLAN/escalate_after" 2>/dev/null || echo 3) failed attempts on one model (--escalate-after 0 turns this off)"
1008
+ fi
857
1009
  newdwarf="$next"
858
1010
  esc_source=policy
859
1011
  fi
@@ -1002,12 +1154,53 @@ prepare_fallback() { # prepare_fallback <plan> <id> <excluded harness/model,...>
1002
1154
  fi
1003
1155
  }
1004
1156
 
1157
+ # The next entry of a STALE task (#150): its prompt or approach changed while the attempt ran, so the
1158
+ # attempt was not reviewed and spent nothing. The attempt number is given back (as a dwarf-stage infra
1159
+ # stop does), the implementer is told what changed, and no escalation, decision or attempt-cap gate runs:
1160
+ # nothing was spent. The status is cleared by the caller.
1161
+ prepare_prompt_retry() { # prepare_prompt_retry <plan> <id>
1162
+ local PLAN="$1" id="$2" tdir="$1/tasks/$2" st attempt n
1163
+ st="$(task_status "$PLAN" "$id")"
1164
+ if [ "$st" != STALE ]; then
1165
+ note "$id: is $st, not STALE; --prompt only prepares a task whose prompt changed during its attempt"
1166
+ return 2
1167
+ fi
1168
+ attempt="$(cat "$tdir/attempt" 2>/dev/null)"
1169
+ case "$attempt" in ''|*[!0-9]*) attempt=0 ;; esac
1170
+ [ "$attempt" -gt 0 ] && echo $((attempt - 1)) > "$tdir/attempt"
1171
+ {
1172
+ printf 'The requirements changed while you worked on this task. The full new requirements are above; what changed follows.\n\n'
1173
+ printf 'Bring your committed work in line with the new text, keep what still holds, and explain anything you change.\n\n'
1174
+ printf '```diff\n'
1175
+ cat "$tdir/stale.diff" 2>/dev/null
1176
+ printf '```\n'
1177
+ } > "$tdir/.retry_findings.md.tmp" && mv "$tdir/.retry_findings.md.tmp" "$tdir/retry_findings.md" || return 1
1178
+ printf 'prompt\n' > "$tdir/.retry_findings.source.tmp" && mv "$tdir/.retry_findings.source.tmp" "$tdir/retry_findings.source" || return 1
1179
+ rm -f "$tdir/retry_findings.commit" "$tdir/resume" "$tdir/retry_findings.session" "$tdir/retry_findings.resolved"
1180
+ if [ -f "$PLAN/implementer_session" ]; then
1181
+ carry_implementer_session "$tdir"
1182
+ else
1183
+ for n in session resolved; do rm -f "$tdir/retry_findings.dwarf.$n"; done
1184
+ fi
1185
+ # The stale attempt was never reviewed, and the requirements it worked from are gone. A re-dispatch
1186
+ # that keeps its committed work (a wording fix needs no code change) must be reviewed, not refused as
1187
+ # "identical to the previous attempt": forge-parallel.sh compares the new diff with changes.prev.diff,
1188
+ # which a dwarf stage fills from changes.diff, so neither is left for it to compare. The stale diff of
1189
+ # the prompt (stale.diff) and committed.diff stay as the record.
1190
+ rm -f "$tdir/changes.diff" "$tdir/changes.prev.diff"
1191
+ rm -f "$tdir/status" "$tdir/noretry"
1192
+ }
1193
+
1005
1194
  # The scheduler's `_prepare_retry` target: prepare, then clear the status so the task
1006
1195
  # reads as PENDING again. `retry` clears it itself, after its own preflight. With --resume it
1007
1196
  # prepares an infrastructure stop's resume instead (prepare_resume), and the status stays;
1008
1197
  # with --dwarf <spec> the spec is the explicit new implementer; --fallback <pairs> [--cause <cause> [--role qa]]
1009
1198
  # is prepare_fallback.
1010
- retry_for_scheduler() { # retry_for_scheduler <plan> <id> [--resume | --dwarf <spec> | --fallback <pairs> [--cause <cause> [--role qa]]]
1199
+ retry_for_scheduler() { # retry_for_scheduler <plan> <id> [--resume | --prompt | --dwarf <spec> | --fallback <pairs> [--cause <cause> [--role qa]]]
1200
+ if [ "${3:-}" = --prompt ]; then
1201
+ prepare_prompt_retry "$1" "$2"
1202
+ return $?
1203
+ fi
1011
1204
  if [ "${3:-}" = --resume ]; then
1012
1205
  # An infrastructure stop spends no attempt, but the resume starts one: at the cap it is stopped for a decision.
1013
1206
  attempt_cap_gate "$1" "$2" INFRA "" || return 4