@giamme/forge 0.16.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 (95) hide show
  1. package/CHANGELOG.md +43 -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 +13 -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/reviews.md +15 -1
  11. package/docs/safety.md +8 -0
  12. package/forge +24 -1
  13. package/package.json +1 -1
  14. package/references/dataset.md +143 -5
  15. package/references/decision-models.md +15 -2
  16. package/references/decompose.md +180 -11
  17. package/references/planning.md +3 -2
  18. package/references/solo.md +2 -1
  19. package/references/ui.md +5 -2
  20. package/scripts/forge-artifact.sh +14 -0
  21. package/scripts/forge-brief.py +132 -0
  22. package/scripts/forge-compare.py +11 -1
  23. package/scripts/forge-config.py +176 -9
  24. package/scripts/forge-contract.py +98 -4
  25. package/scripts/forge-control.py +86 -13
  26. package/scripts/forge-dispatch.sh +14 -10
  27. package/scripts/forge-du.py +167 -0
  28. package/scripts/forge-issues.py +4 -3
  29. package/scripts/forge-ledger.py +3 -1
  30. package/scripts/forge-lib-adopt.sh +8 -1
  31. package/scripts/forge-lib-plans.sh +5 -2
  32. package/scripts/forge-lib-review.sh +29 -1
  33. package/scripts/forge-metrics.sh +29 -3
  34. package/scripts/forge-parallel-options.sh +4 -0
  35. package/scripts/forge-parallel.sh +506 -10
  36. package/scripts/forge-plan-check.py +25 -2
  37. package/scripts/forge-planner.py +20 -6
  38. package/scripts/forge-prompt.py +120 -0
  39. package/scripts/forge-retro.py +115 -0
  40. package/scripts/forge-runs-compact.py +443 -0
  41. package/scripts/forge-runs-rm.py +2 -0
  42. package/scripts/forge-runs.py +18 -3
  43. package/scripts/forge-schedule.py +279 -4
  44. package/scripts/forge-shadow.py +35 -10
  45. package/scripts/forge-solo.sh +2 -0
  46. package/scripts/forge-summarize.py +698 -0
  47. package/scripts/forge-sweep.py +25 -10
  48. package/scripts/forge-ui-options.sh +10 -0
  49. package/scripts/forge_brief/__init__.py +587 -0
  50. package/scripts/forge_brief/answers.py +459 -0
  51. package/scripts/forge_dataset/__init__.py +10 -0
  52. package/scripts/forge_dataset/cli.py +83 -0
  53. package/scripts/forge_dataset/export.py +18 -4
  54. package/scripts/forge_dataset/facts.py +280 -0
  55. package/scripts/forge_dataset/harvest.py +56 -9
  56. package/scripts/forge_dataset/history.py +5 -3
  57. package/scripts/forge_dataset/outcomes.py +206 -58
  58. package/scripts/forge_dataset/pairs.py +174 -0
  59. package/scripts/forge_dataset/risk.py +108 -0
  60. package/scripts/forge_dataset/tiers.py +427 -0
  61. package/scripts/forge_decide/__init__.py +11 -1
  62. package/scripts/forge_decide/cli.py +23 -2
  63. package/scripts/forge_decide/labels.py +30 -6
  64. package/scripts/forge_decide/replay.py +10 -4
  65. package/scripts/forge_locations.py +366 -0
  66. package/scripts/forge_registry.py +19 -0
  67. package/scripts/forge_retro/__init__.py +417 -0
  68. package/scripts/forge_retro/issues.py +1193 -0
  69. package/scripts/forge_retro/report.py +671 -0
  70. package/scripts/forge_side/__init__.py +477 -0
  71. package/scripts/forge_storage.py +515 -0
  72. package/ui/README.md +68 -8
  73. package/ui/docs/api.md +217 -20
  74. package/ui/forge_ui/control.py +92 -11
  75. package/ui/forge_ui/export.py +31 -5
  76. package/ui/forge_ui/findings.py +4 -2
  77. package/ui/forge_ui/links.py +337 -0
  78. package/ui/forge_ui/models.py +57 -4
  79. package/ui/forge_ui/projects.py +4 -1
  80. package/ui/forge_ui/reader.py +732 -34
  81. package/ui/forge_ui/server.py +8 -0
  82. package/ui/forge_ui/static/app.js +92 -5
  83. package/ui/forge_ui/static/briefview.js +302 -0
  84. package/ui/forge_ui/static/checksview.js +6 -2
  85. package/ui/forge_ui/static/controls.js +5 -0
  86. package/ui/forge_ui/static/diffview.js +7 -3
  87. package/ui/forge_ui/static/index.html +3 -0
  88. package/ui/forge_ui/static/panel.js +311 -4
  89. package/ui/forge_ui/static/runmodel.js +13 -1
  90. package/ui/forge_ui/static/storageview.js +271 -0
  91. package/ui/forge_ui/static/style.css +100 -3
  92. package/ui/forge_ui/static/worktreesview.js +3 -3
  93. package/ui/forge_ui/storage.py +136 -0
  94. package/ui/forge_ui/transcripts.py +35 -10
  95. package/ui/forge_ui/worktrees.py +154 -13
@@ -59,6 +59,19 @@
59
59
  # still what the review judged, and starts fresh whenever it cannot;
60
60
  # each attempt is logged in tasks/<id>/implementer_sessions.tsv.
61
61
  # `--no-implementer-session` turns it off (the default)
62
+ # --retro | --no-retro agents record what got in their way (retro, #132); plan file `retro_mode`
63
+ # (on or off; not `retro`, the notes directory). Without a flag the plan
64
+ # keeps its earlier choice, else (first plan only) takes the user
65
+ # `features` setting. The first plan with it on says what is recorded
66
+ # --brief LEVEL advisory, gated, strict or off (#135): one cheap read-only dispatch per
67
+ # task before it starts. Plan files `brief`, `brief_scope` (--brief-scope
68
+ # task|wave|plan, default task) and `brief_model` (--brief-model SPEC). On
69
+ # with no model is refused (exit 2); `off` writes `off` and drops the rest
70
+ # --summaries on|off a generated summary per task (#133); plan files `summaries` and
71
+ # `summaries_model` (--summaries-model SPEC); on with no model is refused.
72
+ # A flag beats the user setting (forge config show), which is read once, at
73
+ # the first plan; a re-plan without the flag keeps what the plan has, and an
74
+ # explicit off (--no-retro, --brief off, --summaries off) is kept as `off`
62
75
  # --fast ROLES which of dwarf, qa, planner, review ask for the fast service tier
63
76
  # (comma list, or all, or none). Kept in the plan; a re-plan without
64
77
  # the flag keeps it, and none removes it. codex and claude only
@@ -305,6 +318,272 @@ $(forge_profile_py value "$1/profile.json" policy.retry_failed policy.infra_retr
305
318
  EOF
306
319
  }
307
320
 
321
+ # --- retro, brief and summaries (#132, #135, #133): options frozen into the plan -------
322
+ # `plan` writes six plan files (retro_mode, brief, brief_scope, brief_model, summaries,
323
+ # summaries_model) that forge_side.settings(plan) reads at run time. The retro file is not
324
+ # called `retro`: <plan>/retro/ is where the notes are kept. For each, a flag of this call
325
+ # wins, then what the plan already has (a re-plan without the flag keeps it, as
326
+ # --reviewer-session is kept), then the user `features` setting, read here once. The user
327
+ # setting turns a feature on or off only before the plan is first planned (no waves.tsv):
328
+ # after that the plan is frozen, here as in forge_side.settings, and a feature a re-plan does
329
+ # not name stays as it was. (A flag that turns a feature on may still take its scope and
330
+ # model from the user setting.) A feature that is on writes its files. One that is off
331
+ # because a flag said so, or because the plan already said `off`, writes `off` into its
332
+ # switch file (retro_mode, brief, summaries), so a later re-plan or a plan made from this
333
+ # one cannot take it from the user setting again; its scope and model files go. One that is
334
+ # merely off by default (no flag, no file, the user setting off) writes nothing, which is
335
+ # what keeps a plan with every feature off exactly what it was before these options.
336
+ #
337
+ # forge_features_resolve sets FEAT_* and writes nothing; it returns 2 (FEAT_ERR says why) when
338
+ # a feature is on with no model, or a model spec does not resolve. forge_features_store writes
339
+ # the files and says what retro records the first time. An empty value means "no file".
340
+ forge_features_user() { # prints key=value lines: the stored user settings, defaults when unreadable
341
+ PYTHONPATH="$SKILL_DIR/scripts${PYTHONPATH:+:$PYTHONPATH}" python3 - <<'PY' 2>/dev/null || true
342
+ import forge_side
343
+ f = forge_side.stored_features()
344
+ for k in ('retro', 'brief', 'brief.scope', 'brief.model', 'summaries', 'summaries.model'):
345
+ print('%s=%s' % (k, f.get(k) or ''))
346
+ PY
347
+ }
348
+
349
+ forge_feature_file() { # forge_feature_file <plan> <name> -> first line, trimmed; empty when absent
350
+ local line=""
351
+ if [ -f "$1/$2" ] && [ -r "$1/$2" ]; then IFS= read -r line < "$1/$2" || true; fi
352
+ line="${line#"${line%%[![:space:]]*}"}"
353
+ printf '%s' "${line%"${line##*[![:space:]]}"}"
354
+ }
355
+
356
+ forge_feature_spec_ok() { # forge_feature_spec_ok <flag name> <spec>: dispatch's own dry run, as a --qa spec resolves
357
+ local tmp err rc=0
358
+ tmp="$(mktemp -d)" || { FEAT_ERR="could not make a temporary directory"; return 2; }
359
+ mkdir -p "$tmp/repo" "$tmp/run"; echo spec-check > "$tmp/prompt"
360
+ bash "$SKILL_DIR/scripts/forge-dispatch.sh" side "$2" --repo "$tmp/repo" --run-dir "$tmp/run" \
361
+ --prompt-file "$tmp/prompt" --dry-run >/dev/null 2>"$tmp/err" || rc=$?
362
+ err="$(awk 'NF { line = $0 } END { print line }' "$tmp/err" 2>/dev/null)"
363
+ rm -rf "${tmp:?}"
364
+ [ "$rc" -eq 0 ] || { FEAT_ERR="$1: '$2' does not resolve to a model${err:+ ($err)}"; return 2; }
365
+ }
366
+
367
+ forge_features_resolve() { # forge_features_resolve <plan>
368
+ local plan="$1" key val
369
+ local u_retro=off u_brief=off u_scope=task u_bmodel="" u_summ=off u_smodel=""
370
+ while IFS== read -r key val; do
371
+ case "$key" in
372
+ retro) [ "$val" = on ] && u_retro=on ;;
373
+ brief) [ -n "$val" ] && u_brief="$val" ;;
374
+ brief.scope) [ -n "$val" ] && u_scope="$val" ;;
375
+ brief.model) u_bmodel="$val" ;;
376
+ summaries) [ -n "$val" ] && u_summ="$val" ;;
377
+ summaries.model) u_smodel="$val" ;;
378
+ esac
379
+ done <<FEATURES_EOF
380
+ $(forge_features_user)
381
+ FEATURES_EOF
382
+ # Planned before: the user setting no longer turns anything on or off (see above).
383
+ if [ -e "$plan/waves.tsv" ]; then u_retro=off; u_brief=off; u_summ=off; fi
384
+ local f_retro f_brief f_scope f_bmodel f_summ f_smodel
385
+ f_retro="$(forge_feature_file "$plan" retro_mode)"; f_brief="$(forge_feature_file "$plan" brief)"
386
+ f_scope="$(forge_feature_file "$plan" brief_scope)"; f_bmodel="$(forge_feature_file "$plan" brief_model)"
387
+ f_summ="$(forge_feature_file "$plan" summaries)"; f_smodel="$(forge_feature_file "$plan" summaries_model)"
388
+
389
+ # retro: `on`; `off` when a flag or the plan says so; else no file
390
+ local retro="${RETRO_FLAG:-${f_retro:-$u_retro}}"
391
+ FEAT_RETRO=""
392
+ if [ "$retro" = on ]; then FEAT_RETRO=on
393
+ elif [ -n "$RETRO_FLAG" ] || [ -n "$f_retro" ]; then FEAT_RETRO=off; fi
394
+
395
+ # brief: the level, its scope and its model
396
+ local level="${BRIEF_FLAG:-${f_brief:-$u_brief}}"
397
+ case "$level" in advisory|gated|strict|off) ;; *) level=off ;; esac
398
+ FEAT_BRIEF=""; FEAT_BRIEF_SCOPE=""; FEAT_BRIEF_MODEL=""
399
+ if [ "$level" = off ] && { [ -n "$BRIEF_FLAG" ] || [ -n "$f_brief" ]; }; then FEAT_BRIEF=off; fi
400
+ if [ "$level" != off ]; then
401
+ local scope="${BRIEF_SCOPE_FLAG:-${f_scope:-$u_scope}}" bmodel="${BRIEF_MODEL_FLAG:-${f_bmodel:-$u_bmodel}}"
402
+ case "$scope" in task|wave|plan) ;; *) scope=task ;; esac
403
+ if [ -z "$bmodel" ]; then
404
+ FEAT_ERR="brief is $level but has no model: pass --brief-model SPEC or run 'forge config set brief.model SPEC'"
405
+ return 2
406
+ fi
407
+ FEAT_BRIEF="$level"; FEAT_BRIEF_SCOPE="$scope"; FEAT_BRIEF_MODEL="$bmodel"
408
+ fi
409
+
410
+ # summaries: the mode and its model
411
+ local mode="${SUMM_FLAG:-${f_summ:-$u_summ}}"
412
+ case "$mode" in on|off) ;; *) mode=off ;; esac
413
+ FEAT_SUMM=""; FEAT_SUMM_MODEL=""
414
+ if [ "$mode" = off ] && { [ -n "$SUMM_FLAG" ] || [ -n "$f_summ" ]; }; then FEAT_SUMM=off; fi
415
+ if [ "$mode" = on ]; then
416
+ local smodel="${SUMM_MODEL_FLAG:-${f_smodel:-$u_smodel}}"
417
+ if [ -z "$smodel" ]; then
418
+ FEAT_ERR="summaries is on but has no model: pass --summaries-model SPEC or run 'forge config set summaries.model SPEC'"
419
+ return 2
420
+ fi
421
+ FEAT_SUMM=on; FEAT_SUMM_MODEL="$smodel"
422
+ fi
423
+
424
+ # Every model that will be dispatched resolves now, not at its first dispatch.
425
+ if [ -n "$FEAT_BRIEF_MODEL" ]; then forge_feature_spec_ok --brief-model "$FEAT_BRIEF_MODEL" || return 2; fi
426
+ if [ -n "$FEAT_SUMM_MODEL" ] && [ "$FEAT_SUMM_MODEL" != "$FEAT_BRIEF_MODEL" ]; then
427
+ forge_feature_spec_ok --summaries-model "$FEAT_SUMM_MODEL" || return 2
428
+ fi
429
+ return 0
430
+ }
431
+
432
+ # The six flags are read in a pass of their own, before the main loop: the shared flags
433
+ # (--qa-threshold, ...) write into the plan dir as they are parsed, so a refusal that came
434
+ # after them would leave their files behind. Here nothing has been written yet, and every bad
435
+ # value or missing model ends the call with the plan dir untouched.
436
+ forge_features_scan() { # forge_features_scan "$@": sets the *_FLAG variables of do_plan
437
+ while [ $# -gt 0 ]; do
438
+ case "$1" in
439
+ --retro) RETRO_FLAG=on ;;
440
+ --no-retro) RETRO_FLAG=off ;;
441
+ --brief)
442
+ case "${2:-}" in advisory|gated|strict|off) BRIEF_FLAG="$2"; shift ;;
443
+ *) die "--brief must be advisory, gated, strict or off" ;; esac ;;
444
+ --brief-scope)
445
+ case "${2:-}" in task|wave|plan) BRIEF_SCOPE_FLAG="$2"; shift ;;
446
+ *) die "--brief-scope must be task, wave or plan" ;; esac ;;
447
+ --brief-model)
448
+ [ -n "${2:-}" ] || die "--brief-model needs a model spec"
449
+ BRIEF_MODEL_FLAG="$2"; shift ;;
450
+ --summaries)
451
+ case "${2:-}" in on|off) SUMM_FLAG="$2"; shift ;;
452
+ *) die "--summaries must be on or off" ;; esac ;;
453
+ --summaries-model)
454
+ [ -n "${2:-}" ] || die "--summaries-model needs a model spec"
455
+ SUMM_MODEL_FLAG="$2"; shift ;;
456
+ esac
457
+ shift
458
+ done
459
+ }
460
+
461
+ forge_features_store() { # forge_features_store <plan>
462
+ local plan="$1" pair name var val
463
+ for pair in retro_mode:FEAT_RETRO brief:FEAT_BRIEF brief_scope:FEAT_BRIEF_SCOPE brief_model:FEAT_BRIEF_MODEL \
464
+ summaries:FEAT_SUMM summaries_model:FEAT_SUMM_MODEL; do
465
+ name="${pair%%:*}"; var="${pair#*:}"; val="${!var}"
466
+ if [ -z "$val" ]; then
467
+ rm -f "${plan:?}/${name:?}"
468
+ else
469
+ printf '%s\n' "$val" > "$plan/$name" || die "could not write $plan/$name" 3
470
+ fi
471
+ done
472
+ if [ "$FEAT_RETRO" = on ]; then forge_retro_notice "$plan"; fi
473
+ return 0
474
+ }
475
+
476
+ # Said once per user, to stderr, the first time a plan has retro on. The marker is in the state dir.
477
+ forge_retro_notice() { # forge_retro_notice <plan>
478
+ local marker="${XDG_STATE_HOME:-$HOME/.local/state}/forge/retro.noticed"
479
+ [ ! -e "$marker" ] || return 0
480
+ note "retro is on. Each agent records what got in its way: a note with the command it ran and an excerpt of the error."
481
+ note " Kept in $1/retro/, in tasks/<id>/retro.json and in the local dataset. Nothing leaves this machine"
482
+ note " unless you approve it with 'forge retro issues'. This notice is shown once per user."
483
+ { mkdir -p "${marker%/*}" && : > "$marker"; } 2>/dev/null || true
484
+ }
485
+
486
+ # 0 when this plan records retro notes. settings() is the switch: the plan file, the user
487
+ # setting before waves.tsv, and FORGE_RETRO=off. Auto's planner is dispatched before `plan`
488
+ # writes retro_mode, so AUTO_RETRO_FLAG (on, off, or empty) carries the flag that call will
489
+ # hand to plan. Off from the environment still wins. Prints nothing and writes nothing.
490
+ forge_retro_on() { # forge_retro_on <plan>
491
+ local flag="${AUTO_RETRO_FLAG:-}"
492
+ PYTHONPATH="$SKILL_DIR/scripts${PYTHONPATH:+:$PYTHONPATH}" \
493
+ python3 - "$1" "$flag" >/dev/null <<'PY'
494
+ import os, sys
495
+ import forge_side
496
+ plan, flag = sys.argv[1], sys.argv[2]
497
+ if os.environ.get('FORGE_RETRO', '').strip().lower() == 'off':
498
+ sys.exit(1)
499
+ if flag == 'on':
500
+ sys.exit(0)
501
+ if flag == 'off':
502
+ sys.exit(1)
503
+ sys.exit(0 if forge_side.settings(plan).get('retro') else 1)
504
+ PY
505
+ }
506
+
507
+ # The retro instruction, printed so it can be the last block of a prompt. Nothing when retro
508
+ # is off, which is what keeps that prompt byte-identical.
509
+ forge_retro_prompt() { # forge_retro_prompt <plan> <role>
510
+ forge_retro_on "$1" || return 0
511
+ echo
512
+ python3 "$SKILL_DIR/scripts/forge-contract.py" retro --role "$2" \
513
+ || note "retro: could not write the $2 instruction"
514
+ return 0
515
+ }
516
+
517
+ # One dispatch's notes. A failure is one warning and never the caller's result: the status
518
+ # and the exit code stay whatever the dispatch already decided. No task for a whole-run
519
+ # dispatch (the planner, the final review). The inbox is the dwarf worktree's.
520
+ forge_retro_record() { # forge_retro_record <plan> <role> <dir> [task] [attempt] [inbox]
521
+ forge_retro_on "$1" || return 0
522
+ local plan="$1" role="$2" dir="$3" task="${4:-}" attempt="${5:-}" inbox="${6:-}"
523
+ local cmd=(python3 "$SKILL_DIR/scripts/forge-retro.py" record "$plan" --role "$role" --dir "$dir")
524
+ [ -n "$task" ] && cmd+=(--task "$task")
525
+ [ -n "$attempt" ] && cmd+=(--attempt "$attempt")
526
+ [ -n "$inbox" ] && cmd+=(--inbox "$inbox")
527
+ if ! "${cmd[@]}" >/dev/null 2>&1; then
528
+ note "retro: could not record the $role notes${task:+ for $task}"
529
+ fi
530
+ return 0
531
+ }
532
+
533
+ # Rewrite retro.md. Quiet: integrate and review regenerate after their dispatches, and the
534
+ # run's own summary line is forge_retro_summary_line. A failure is one warning.
535
+ forge_retro_report() { # forge_retro_report <plan>
536
+ forge_retro_on "$1" || return 0
537
+ python3 "$SKILL_DIR/scripts/forge-retro.py" report "$1" >/dev/null 2>&1 \
538
+ || note "retro: could not write the report"
539
+ return 0
540
+ }
541
+
542
+ # Write retro.md and print the one summary line when the report has any pattern. Nothing
543
+ # when it does not, or when retro is off (no call, no file).
544
+ forge_retro_summary_line() { # forge_retro_summary_line <plan>
545
+ forge_retro_on "$1" || return 0
546
+ local json
547
+ json="$(python3 "$SKILL_DIR/scripts/forge-retro.py" report "$1" --json 2>/dev/null)" || {
548
+ note "retro: could not write the report"
549
+ return 0
550
+ }
551
+ printf '%s' "$json" | python3 -c '
552
+ import json, sys
553
+ doc = json.load(sys.stdin)
554
+ plan = sys.argv[1]
555
+ n = u = f = 0
556
+ for group in doc.get("groups") or []:
557
+ k = len(group.get("patterns") or [])
558
+ n += k
559
+ if group.get("id") == "user":
560
+ u += k
561
+ elif group.get("id") == "forge":
562
+ f += k
563
+ if n:
564
+ sys.stdout.write("retro: %d patterns (%d you can fix, %d for forge): %s/retro.md\n" % (n, u, f, plan))
565
+ ' "$1"
566
+ return 0
567
+ }
568
+
569
+ # One line per feature that is on, from the plan files (what the run will do).
570
+ forge_features_table() { # forge_features_table <plan>
571
+ local plan="$1" level scope model
572
+ if [ "$(forge_feature_file "$plan" retro_mode)" = on ]; then
573
+ echo "retro: agents record what got in their way; report at retro.md (local only)"
574
+ fi
575
+ level="$(forge_feature_file "$plan" brief)"
576
+ case "$level" in
577
+ advisory|gated|strict)
578
+ scope="$(forge_feature_file "$plan" brief_scope)"; model="$(forge_feature_file "$plan" brief_model)"
579
+ echo "brief: $level, ${scope:-task} scope, ${model:-no model}; one cheap read-only dispatch per task before it starts" ;;
580
+ esac
581
+ if [ "$(forge_feature_file "$plan" summaries)" = on ]; then
582
+ echo "summaries: on, $(forge_feature_file "$plan" summaries_model); one cheap dispatch per task when its attempts or status change"
583
+ fi
584
+ return 0
585
+ }
586
+
308
587
  do_plan() {
309
588
  local PLAN="${1:?plan needs a plan dir}"; shift
310
589
  local PF_NAME="" PF_NONE=0 PF_QT=0
@@ -313,7 +592,13 @@ do_plan() {
313
592
  PP_INFRA_FALLBACK=""
314
593
  local PLANNER="" NOMEM=0 jev_rc=0 DLEVEL="" SHADOW_QA="" SHADOW_RATE="" EXPLORE="" FAIL_FIRST="" REVIEWER_SESSION="" IMPLEMENTER_SESSION="" PRE_REVIEW="" PRE_REVIEW_PARALLEL=""
315
594
  local FAST_GIVEN=0 FAST_PARSED=""
316
- local COLLAPSE=0 COLLAPSED_NOW=0
595
+ local RETRO_FLAG="" BRIEF_FLAG="" BRIEF_SCOPE_FLAG="" BRIEF_MODEL_FLAG="" SUMM_FLAG="" SUMM_MODEL_FLAG=""
596
+ local COLLAPSE=0 COLLAPSED_NOW=0 FEAT_ERR=""
597
+ # The retro, brief and summaries choices, settled before anything is written: a refusal
598
+ # (a bad value, no model, a spec that does not resolve) leaves the plan dir as it was.
599
+ forge_features_scan "$@"
600
+ [ -d "$PLAN" ] || die "plan dir '$PLAN' does not exist"
601
+ forge_features_resolve "$PLAN" || die "$FEAT_ERR" 2
317
602
  while [ $# -gt 0 ]; do
318
603
  case "$1" in
319
604
  --repo) REPO="${2:?}"; shift 2 ;;
@@ -359,6 +644,8 @@ do_plan() {
359
644
  forge_fast_parse "$2" plan
360
645
  FAST_GIVEN=1
361
646
  shift 2 ;;
647
+ --retro|--no-retro) shift ;; # read by forge_features_scan
648
+ --brief|--brief-scope|--brief-model|--summaries|--summaries-model) shift 2 ;;
362
649
  *)
363
650
  # `case` is not a loop, so `continue` here belongs to the enclosing while.
364
651
  # The shared flags write into the plan dir (--qa-threshold), so it must exist first.
@@ -420,6 +707,8 @@ do_plan() {
420
707
  case "$IMPLEMENTER_SESSION" in on) printf '%s\n' on > "$PLAN/implementer_session" ;; off) rm -f "$PLAN/implementer_session" ;; esac
421
708
  # Which roles ask for the fast tier. Omitted on a re-plan, so an earlier choice stays.
422
709
  forge_fast_store "$PLAN"
710
+ # Retro, brief and summaries (#132, #133, #135), as forge_features_resolve settled them.
711
+ forge_features_store "$PLAN"
423
712
  # Exploration is decided here and only here, so the table and preflight see what will run.
424
713
  # On by default: choosing models from measured pass rates needs some randomized picks, and
425
714
  # history had almost none (9 tasks ever ran on more than one spec). The flag wins, then
@@ -817,6 +1106,7 @@ render_table() {
817
1106
  fast_roles="$(awk 'NF { printf "%s%s", (n++ ? ", " : ""), $0 }' "$PLAN/fast")"
818
1107
  echo "fast tier: $fast_roles — billed at a higher rate (codex service_tier=fast; claude fast mode needs extra usage enabled)"
819
1108
  fi
1109
+ forge_features_table "$PLAN"
820
1110
  if [ -f "$PLAN/profile.json" ]; then
821
1111
  local profile_line; profile_line="$(forge_profile_py line "$PLAN/profile.json" 2>/dev/null)"
822
1112
  [ -z "$profile_line" ] || echo "$profile_line"
@@ -1141,6 +1431,27 @@ check_drift() { # check_drift <declared-comma-list> <tdir> <wt> <base>
1141
1431
  return 0
1142
1432
  }
1143
1433
 
1434
+ # The attempt trail (#133): one line per attempt that starts with carried findings, saying why it
1435
+ # happened, as `<attempt>\t<source>\t<epoch>`. The source is read the way forge-prompt.py reads it
1436
+ # (a missing or unknown one is a review). A line for the same attempt number is replaced rather than
1437
+ # repeated: an infrastructure stop refunds the attempt, so its restart runs the same number again.
1438
+ # An existing trail that cannot be read is left as it is (non-zero return): rewriting it from this
1439
+ # one line would drop the history.
1440
+ record_retry_source() { # record_retry_source <tdir> <attempt>
1441
+ local tdir="$1" n="$2" src trail tmp
1442
+ trail="$tdir/retry_sources.tsv"; tmp="$tdir/.retry_sources.tsv.tmp"
1443
+ [ -s "$tdir/retry_findings.md" ] || return 0
1444
+ src="$(cat "$tdir/retry_findings.source" 2>/dev/null)"
1445
+ case "$src" in review|prereview|bounce|message|answer) ;; *) src=review ;; esac
1446
+ if [ -e "$trail" ]; then
1447
+ [ -f "$trail" ] && [ -r "$trail" ] || return 1
1448
+ awk -F'\t' -v n="$n" '$1 != n' "$trail" > "$tmp" 2>/dev/null || { rm -f "$tmp"; return 1; }
1449
+ else
1450
+ : > "$tmp" || return 1
1451
+ fi
1452
+ printf '%s\t%s\t%s\n' "$n" "$src" "$(date +%s)" >> "$tmp" && mv "$tmp" "$trail" || { rm -f "$tmp"; return 1; }
1453
+ }
1454
+
1144
1455
  do_task_body() (
1145
1456
  local PLAN="${1:?}" id="${2:?}"
1146
1457
  local T="$PLAN/tasks.tsv" REPO run_id base wt br tdir attempt resume=""
@@ -1224,7 +1535,11 @@ do_task_body() (
1224
1535
  echo; python3 "$SKILL_DIR/scripts/forge-contract.py" dwarf $([ ! -f "$PLAN/pre_review_tests" ] || echo --pre-review) \
1225
1536
  $([ -z "$(verify_source_for "$PLAN" "$REPO")" ] || echo --verify-after-merge)
1226
1537
  echo; /bin/bash "$MEMORY" note dwarf
1538
+ # Last, after the memory note. Nothing is printed when retro is off.
1539
+ forge_retro_prompt "$PLAN" dwarf
1227
1540
  } > "$tdir/dwarf.input"
1541
+ # This attempt starts with the findings just written to dwarf.input (#133).
1542
+ record_retry_source "$tdir" "$attempt" || note "$id: retry_sources.tsv not updated; the attempt trail stays as it was"
1228
1543
  guard_before_dwarf "$wt" "$tdir"
1229
1544
  # Whether this attempt continues the implementer's earlier session (plan
1230
1545
  # --implementer-session, #90): only a retry of judged work that is still exactly what was
@@ -1268,6 +1583,9 @@ do_task_body() (
1268
1583
  if [ -n "$is_fp" ] && [ "$(forge_fingerprint "$wt")" = "$is_fp" ]; then
1269
1584
  # It changed nothing, so the same input goes to a fresh session, which decides the attempt.
1270
1585
  is_mode=fresh
1586
+ # The fresh dispatch deletes dwarf.last and dwarf.log as it starts. Record the
1587
+ # continuation first; a failure to record does not change the attempt.
1588
+ forge_retro_record "$PLAN" dwarf "$tdir" "$id" "$attempt" "$wt/.forge/retro-inbox.jsonl"
1271
1589
  "${dwarf_cmd[@]}" >"$tdir/dwarf.out" 2>&1
1272
1590
  rc=$?
1273
1591
  else
@@ -1287,6 +1605,9 @@ do_task_body() (
1287
1605
  fi
1288
1606
  if [ "${FORGE_OUTPUT:-summary}" = full ]; then cat "$tdir/dwarf.out"; fi
1289
1607
  if [ "$rc" -ne 0 ]; then
1608
+ # The dispatch ended without a result memory would record. Keep its notes anyway;
1609
+ # a failure to record them does not change the status this case is about to write.
1610
+ forge_retro_record "$PLAN" dwarf "$tdir" "$id" "$attempt" "$wt/.forge/retro-inbox.jsonl"
1290
1611
  case "$rc" in
1291
1612
  7) echo TIMEOUT > "$tdir/status"; note "$id: dwarf hit the dispatch timeout — see $tdir/dwarf.out" ;;
1292
1613
  8) infra_stop "$tdir" "$id" dwarf "$attempt"; return 8 ;;
@@ -1298,6 +1619,7 @@ do_task_body() (
1298
1619
  /bin/bash "$MEMORY" record "$REPO" --last "$tdir/dwarf.last" --role dwarf \
1299
1620
  --run-id "$run_id" --task "$id" --model "$dw" --run-dir "$tdir" \
1300
1621
  --duration "$(dispatch_duration "$tdir" dwarf)" >/dev/null 2>&1
1622
+ forge_retro_record "$PLAN" dwarf "$tdir" "$id" "$attempt" "$wt/.forge/retro-inbox.jsonl"
1301
1623
 
1302
1624
  guard_after_dwarf "$wt" "$tdir" "$id"
1303
1625
  # Before the snapshot, so a dwarf that only asked a question (and changed nothing) still reaches it.
@@ -1367,6 +1689,11 @@ do_task_body() (
1367
1689
  reviewed="$(cat "$tdir/reviewed.commit")"
1368
1690
  fi
1369
1691
  review="$tdir/review-$attempt-$$"
1692
+ # One review of a task at a time, so any snapshot already here is an interrupted review's: a signal
1693
+ # ends this subshell without its EXIT trap (#139).
1694
+ local stale
1695
+ for stale in "$tdir"/review-*; do forge_drop_snapshot "$stale"; done
1696
+ FORGE_REVIEW_SNAPSHOT="$review" # forge_metric_begin's EXIT trap removes it, whatever the outcome
1370
1697
  forge_review_snapshot "$wt" "$base" "$reviewed" "$review" || { echo ERROR > "$tdir/status"; return 1; }
1371
1698
  forge_review_deps "$wt" "$review" "$tdir/review.deps"
1372
1699
  source_fp="$(forge_fingerprint "$wt")" || return 1
@@ -1458,6 +1785,9 @@ do_task_body() (
1458
1785
  echo '```diff'; git -C "$wt" diff --binary --irreversible-delete "$base" "$reviewed" -- . ':(exclude).forge'; echo '```'
1459
1786
  echo; /bin/bash "$MEMORY" note qa
1460
1787
  echo "Place any learning notes before the final FORGE_VERDICT: PASS or FORGE_VERDICT: FAIL line."
1788
+ # Last, so a shadow review, which copies this file byte for byte, carries the same
1789
+ # instruction. Its notes are not recorded: only this task's own dispatch is.
1790
+ forge_retro_prompt "$PLAN" qa
1461
1791
  } > "$tdir/qa.input"
1462
1792
  # Opt-in (plan --shadow-qa): a second, independent review of this same diff, to measure
1463
1793
  # how often two reviewers agree. It reviews its own snapshot from its own dir under
@@ -1501,6 +1831,9 @@ do_task_body() (
1501
1831
  fi
1502
1832
  rs_mode=fresh
1503
1833
  mv "$tdir/qa.out" "$tdir/qa.continue.out" 2>/dev/null || true
1834
+ # The fresh dispatch deletes qa.last and qa.log as it starts. Record the continuation
1835
+ # first; a failure to record does not change the round.
1836
+ forge_retro_record "$PLAN" qa "$tdir" "$id" "$attempt"
1504
1837
  "${qa_cmd[@]}" >"$tdir/qa.out" 2>&1
1505
1838
  rc=$?
1506
1839
  fi
@@ -1518,6 +1851,7 @@ do_task_body() (
1518
1851
  fi
1519
1852
  if [ "${FORGE_OUTPUT:-summary}" = full ]; then cat "$tdir/qa.out"; fi
1520
1853
  if [ "$rc" -ne 0 ]; then
1854
+ forge_retro_record "$PLAN" qa "$tdir" "$id" "$attempt"
1521
1855
  case "$rc" in
1522
1856
  7) echo TIMEOUT > "$tdir/status"; note "$id: qa hit the dispatch timeout — see $tdir/qa.out" ;;
1523
1857
  8) infra_stop "$tdir" "$id" qa "$attempt"; return 8 ;;
@@ -1528,6 +1862,9 @@ do_task_body() (
1528
1862
  rm -f "$tdir/resume"
1529
1863
 
1530
1864
  forge_metric_phase verification
1865
+ # Before the invalidation return: a review that changed a tracked file still finished,
1866
+ # and its notes are the point of that dispatch. Recording never changes the status.
1867
+ forge_retro_record "$PLAN" qa "$tdir" "$id" "$attempt"
1531
1868
  if [ "$(forge_fingerprint "$wt")" != "$source_fp" ] || [ "$(forge_fingerprint "$review" --tracked)" != "$review_fp" ]; then
1532
1869
  # The committed work is untouched, so --retry-failed may review it again (reason `review`);
1533
1870
  # the merge-time invalidations below leave no reason and wait for a human.
@@ -1914,6 +2251,7 @@ do_retry() {
1914
2251
  if [ "$st" = "PASS" ]; then
1915
2252
  if merge_task "$PLAN" "$id"; then
1916
2253
  note "$id PASS -> merged"
2254
+ forge_brief_stale "$PLAN" "$id"
1917
2255
  else
1918
2256
  note "$id PASS but conflicted on merge — branch preserved"
1919
2257
  fi
@@ -2279,6 +2617,99 @@ run_signal() {
2279
2617
  # Not a ( ) function: main runs it as `( do_run ... ) &`, one subshell that is both the
2280
2618
  # background job and the home of its signal handler. A function called with `&` would be a
2281
2619
  # second subshell level, and an async function does not run its EXIT trap.
2620
+ # --- brief mode in a run (#135) ------------------------------------------------------
2621
+ # The effective level: advisory, gated, strict or off. Settings are the switch (the plan file and
2622
+ # FORGE_BRIEF=off); anything that cannot be read is off, so a broken brief never holds a run.
2623
+ forge_brief_level() { # forge_brief_level <plan>
2624
+ local level
2625
+ level="$(PYTHONPATH="$SKILL_DIR/scripts${PYTHONPATH:+:$PYTHONPATH}" python3 - "$1" 2>/dev/null <<'PY'
2626
+ import sys
2627
+ import forge_side
2628
+ print(forge_side.settings(sys.argv[1])['brief']['level'])
2629
+ PY
2630
+ )" || level=off
2631
+ case "$level" in advisory|gated|strict) echo "$level" ;; *) echo off ;; esac
2632
+ }
2633
+
2634
+ # `forge-brief.py write` in a session of its own, output to brief.out, without waiting. brief.pid holds
2635
+ # the writer's supervisor, which removes it when the writer ends: the scheduler's gated wait reads it.
2636
+ forge_brief_start() { # forge_brief_start <plan>
2637
+ local plan="$1"
2638
+ rm -f "$plan/brief.pid"
2639
+ python3 - "$plan" "$SKILL_DIR/scripts/forge-brief.py" <<'PY' || { note "brief: could not start the question writer"; return 0; }
2640
+ import os, subprocess, sys
2641
+ plan, script = sys.argv[1], sys.argv[2]
2642
+ pidfile = os.path.join(plan, 'brief.pid')
2643
+ ready, signal_ready = os.pipe()
2644
+ child = os.fork()
2645
+ if child:
2646
+ os.close(signal_ready)
2647
+ os.read(ready, 1) # the child wrote brief.pid (or gave up): the file is there before this returns
2648
+ sys.exit(0)
2649
+ code = 1
2650
+ try:
2651
+ os.close(ready)
2652
+ os.setsid()
2653
+ out = os.open(os.path.join(plan, 'brief.out'), os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0o644)
2654
+ null = os.open(os.devnull, os.O_RDONLY)
2655
+ os.dup2(null, 0); os.dup2(out, 1); os.dup2(out, 2)
2656
+ with open(pidfile, 'w') as handle:
2657
+ handle.write('%d\n' % os.getpid())
2658
+ os.write(signal_ready, b'1'); os.close(signal_ready)
2659
+ code = subprocess.run([sys.executable, script, 'write', plan], stdin=subprocess.DEVNULL).returncode
2660
+ except BaseException:
2661
+ pass
2662
+ finally:
2663
+ try:
2664
+ os.write(signal_ready, b'1')
2665
+ except OSError:
2666
+ pass
2667
+ try:
2668
+ os.unlink(pidfile)
2669
+ except OSError:
2670
+ pass
2671
+ os._exit(code)
2672
+ PY
2673
+ }
2674
+
2675
+ # Strict: the questions of the tasks that have not started and nobody answered, each with the command that
2676
+ # answers it. Exit 3 when there are any, so the caller refuses before the scheduler starts.
2677
+ forge_brief_strict() { # forge_brief_strict <plan>
2678
+ local plan="$1" rc=0
2679
+ python3 "$SKILL_DIR/scripts/forge-brief.py" write "$plan" >&2 || note "brief: the question writer did not finish; tasks without questions are not held"
2680
+ PYTHONPATH="$SKILL_DIR/scripts${PYTHONPATH:+:$PYTHONPATH}" python3 - "$plan" <<'PY' || rc=$?
2681
+ import shlex, sys
2682
+ import forge_brief
2683
+ import forge_brief.answers as answers
2684
+ plan = sys.argv[1]
2685
+ try:
2686
+ found = forge_brief.collect(plan)['questions']
2687
+ except Exception:
2688
+ sys.exit(0)
2689
+ open_ = [q for q in found if q['state'] in ('open', 'possibly_stale') and not answers.past_start(plan, q['task'])]
2690
+ if not open_:
2691
+ sys.exit(0)
2692
+ err = sys.stderr
2693
+ err.write('forge: strict brief: %d question(s) wait for your answer before any task starts:\n' % len(open_))
2694
+ for q in open_:
2695
+ err.write(' %s %s: %s\n' % (q['task'], q['id'], q['text']))
2696
+ err.write(' default: %s\n' % (q['default'] or '(none)'))
2697
+ err.write(' forge brief answer %s %s %s "…"\n' % (shlex.quote(plan), q['task'], q['id']))
2698
+ err.write('forge: nothing was started. Answer them, then run again.\n')
2699
+ sys.exit(3)
2700
+ PY
2701
+ return "$rc"
2702
+ }
2703
+
2704
+ # After a merge, with brief on: flag the dependents' open questions when the merge touched files outside
2705
+ # the task's own. A failure is one line and changes nothing else.
2706
+ forge_brief_stale() { # forge_brief_stale <plan> <merged-task>
2707
+ [ "$(forge_brief_level "$1")" = off ] && return 0
2708
+ python3 "$SKILL_DIR/scripts/forge-brief.py" stale "$1" "$2" >/dev/null 2>&1 \
2709
+ || note "brief: could not flag the dependents of $2 as possibly stale"
2710
+ return 0
2711
+ }
2712
+
2282
2713
  do_run() {
2283
2714
  local run_child="" run_stop=0 run_phase=pre run_rc=0 interrupted=0 vstopped=0
2284
2715
  FORGE_RUN_STOPPABLE=1
@@ -2337,6 +2768,7 @@ do_run() {
2337
2768
  printf '%s\n' "$MAXP" > "$PLAN/max_parallel"
2338
2769
  # Plan registers too; this also picks up plans made before it did.
2339
2770
  forge_ui_register "$PLAN"
2771
+ forge_storage_check "$PLAN" "$REPO"
2340
2772
  fi
2341
2773
  forge_fractal_parallel_run "$PLAN" "$REPO" "$DRY" ${fractal_pipeline_args[@]+"${fractal_pipeline_args[@]}"} || return $?
2342
2774
  forge_fast_fractal_note "$PLAN"
@@ -2402,8 +2834,16 @@ do_run() {
2402
2834
  # Also before any model is paid for: what this plan is likely to cost, and which tasks
2403
2835
  # history says may bounce. Advisory, budgeted and silent without history; it never stops a run.
2404
2836
  [ "$FORECAST" = 1 ] && forecast_report "$PLAN"
2405
- # Invalid verification lanes stop the run here, before any model is paid for.
2837
+ # Invalid verification lanes stop the run here, before any model is paid for, so before the question writer below.
2406
2838
  verify_lanes_check "$PLAN" "$REPO" "$int_wt"
2839
+ # Brief mode (#135), when the plan has it on. Strict asks first and refuses to start while a question of a
2840
+ # task that has not started is unanswered; advisory and gated write the questions beside the scheduler.
2841
+ local brief_level
2842
+ brief_level="$(forge_brief_level "$PLAN")"
2843
+ case "$brief_level" in
2844
+ strict) forge_brief_strict "$PLAN" || exit $? ;;
2845
+ advisory|gated) forge_brief_start "$PLAN" ;;
2846
+ esac
2407
2847
  # Say now, before any model is paid for, which suites the verify command will not run.
2408
2848
  verify_coverage_report "$REPO" "$(verify_command_for "$PLAN" "$REPO")" "$PLAN/verification.coverage.txt"
2409
2849
  local sched_rc=0 paused=0 sched_args=()
@@ -2456,12 +2896,18 @@ do_run() {
2456
2896
  done
2457
2897
  fi
2458
2898
 
2899
+ # After the scheduler (and verification) and before the summary. Retro off: no call,
2900
+ # no retro.md. A failure here does not change the exit code decided below.
2901
+ local retro_line=""
2902
+ retro_line="$(forge_retro_summary_line "$PLAN")"
2903
+
2459
2904
  echo
2460
2905
  echo "results (integration branch: $int_br)"
2461
2906
  echo "artifacts: $PLAN/tasks/<id>/{dwarf,qa}.{last,log}; results: $PLAN/results.tsv"
2462
2907
  printf ' %-14s %-9s %s\n' id status branch
2463
2908
  awk -F'\t' '{printf " %-14s %-9s %s\n", $1, $2, $3}' "$PLAN/results.tsv"
2464
2909
  echo
2910
+ if [ -n "$retro_line" ]; then printf '%s\n\n' "$retro_line"; fi
2465
2911
  run_report_extras "$PLAN"
2466
2912
  # Pre-review tests (#85): every check of the plan, and the reviews the red ones saved.
2467
2913
  local pre_review
@@ -2665,14 +3111,35 @@ forge_auto_unparse() { # forge_auto_unparse <plan-dir>
2665
3111
  rm -f "$1/tasks.tsv" "$1/tasks.declared.tsv"
2666
3112
  }
2667
3113
 
3114
+ # The planner's notes, once. A dispatch that ran before `plan` wrote run_id leaves
3115
+ # AUTO_PLANNER_RECORDED=0; recording then would store run_id null for good. The caller
3116
+ # records after `plan`, or on an exit that will never reach it. A later dispatch (the
3117
+ # send-back) already has the file and records itself.
3118
+ forge_auto_record_planner() { # forge_auto_record_planner <plan>
3119
+ [ "${AUTO_PLANNER_RECORDED:-1}" = 0 ] || return 0
3120
+ forge_retro_record "$1" planner "$1"
3121
+ AUTO_PLANNER_RECORDED=1
3122
+ }
3123
+
2668
3124
  # One planner dispatch: prompt in $PLAN/planner.prompt, reply in $PLAN/planner.last. Sets
2669
3125
  # AUTO_RC (0, 4 or 8) for the caller instead of exiting, so a send-back can reuse it.
2670
3126
  forge_auto_dispatch() { # forge_auto_dispatch <plan-dir> <repo> <spec> <fast-option-or-empty>
2671
3127
  local plan="$1" repo="$2" spec="$3" tier="$4" rc=0
2672
3128
  AUTO_RC=0
3129
+ AUTO_PLANNER_RECORDED=0
2673
3130
  note "auto: dispatching the planner ($spec) for the whole plan"
3131
+ # Last. The planner runs before `plan` stores retro_mode; AUTO_RETRO_FLAG says whether
3132
+ # this call's flags will turn it on. Off appends nothing, so the file stays as written.
3133
+ forge_retro_prompt "$plan" planner >> "$plan/planner.prompt"
2674
3134
  bash "$DISPATCH" planner "$spec" --repo "$repo" --run-dir "$plan" --prompt-file "$plan/planner.prompt" \
2675
3135
  --output summary ${tier:+$tier} >&2 || rc=$?
3136
+ # No task: the planner is the whole plan. Its result is AUTO_RC, set below, not this.
3137
+ # run_id is written by `plan`, which has not run yet on a new directory. Record now only
3138
+ # when that file is already there (a send-back); otherwise the caller records after `plan`.
3139
+ if [ -s "$plan/run_id" ]; then
3140
+ forge_retro_record "$plan" planner "$plan"
3141
+ AUTO_PLANNER_RECORDED=1
3142
+ fi
2676
3143
  if [ "$rc" -eq 8 ]; then
2677
3144
  note "auto: the planner stopped on an infrastructure failure (see $plan/planner.infra). Nothing was dispatched after the planner; fix the cause and run auto again"
2678
3145
  AUTO_RC=8
@@ -2785,23 +3252,41 @@ AUTO_PROFILE
2785
3252
  forge_fast_store "$PLAN"
2786
3253
  fast_tier="$(forge_fast_tier "$PLAN" planner)"
2787
3254
 
3255
+ # The flag `plan` is about to store. The planner is dispatched before that write, and
3256
+ # FORGE_RETRO=off still wins inside forge_retro_on. Last flag wins, as plan's own scan.
3257
+ AUTO_RETRO_FLAG=""
3258
+ local retro_scan=""
3259
+ for retro_scan in ${PLAN_ARGS[@]+"${PLAN_ARGS[@]}"}; do
3260
+ case "$retro_scan" in
3261
+ --retro) AUTO_RETRO_FLAG=on ;;
3262
+ --no-retro) AUTO_RETRO_FLAG=off ;;
3263
+ esac
3264
+ done
2788
3265
  note "auto: checking the planner ($PLANNER) before any model call"
2789
3266
  bash "$DISPATCH" doctor --spec "$PLANNER" --role planner ${fast_tier:+$fast_tier} >&2 || exit $?
2790
3267
  python3 "$PLANNER_PY" prompt --plan "$PLAN" --goal-file "$REQUEST" ${DLEVEL:+--level "$DLEVEL"} >/dev/null || exit $?
2791
3268
  forge_auto_dispatch "$PLAN" "$REPO" "$PLANNER" "$fast_tier"
2792
- [ "$AUTO_RC" -eq 0 ] || exit "$AUTO_RC"
3269
+ if [ "$AUTO_RC" -ne 0 ]; then
3270
+ forge_auto_record_planner "$PLAN"
3271
+ exit "$AUTO_RC"
3272
+ fi
2793
3273
  python3 "$PLANNER_PY" parse --plan "$PLAN" --reply "$PLAN/planner.last" || rc=$?
2794
3274
  case "$rc" in
2795
3275
  0) ;;
2796
- 4) note "auto: the planner's reply was refused (see $PLAN/planner.refused). Nothing was dispatched after the planner"
3276
+ 4) forge_auto_record_planner "$PLAN"
3277
+ note "auto: the planner's reply was refused (see $PLAN/planner.refused). Nothing was dispatched after the planner"
2797
3278
  exit 4 ;;
2798
- *) exit "$rc" ;;
3279
+ *) forge_auto_record_planner "$PLAN"
3280
+ exit "$rc" ;;
2799
3281
  esac
2800
3282
  from_planner=1
2801
3283
  fi
2802
3284
 
2803
3285
  # 4. plan, and one send-back when the plan gates ask for it.
2804
3286
  bash "$SELF" plan "$PLAN" ${PLAN_ARGS[@]+"${PLAN_ARGS[@]}"}; rc=$?
3287
+ # planner.last is still the first reply. plan has written run_id when it got that far,
3288
+ # and the send-back below overwrites the reply, so this is the moment to record it.
3289
+ forge_auto_record_planner "$PLAN"
2805
3290
  if [ "$rc" -eq 4 ] && [ "$from_planner" = 1 ] && [ -s "$PLAN/plan.sendback.md" ]; then
2806
3291
  note "auto: the plan gates sent items back; asking the planner once more"
2807
3292
  cp "$PLAN/planner.last" "$PLAN/planner.first.last" 2>/dev/null || true
@@ -2814,16 +3299,22 @@ AUTO_PROFILE
2814
3299
  cat "$PLAN/plan.sendback.md"
2815
3300
  } >> "$PLAN/planner.prompt"
2816
3301
  forge_auto_dispatch "$PLAN" "$REPO" "$PLANNER" "$fast_tier"
2817
- [ "$AUTO_RC" -eq 0 ] || exit "$AUTO_RC"
3302
+ if [ "$AUTO_RC" -ne 0 ]; then
3303
+ forge_auto_record_planner "$PLAN"
3304
+ exit "$AUTO_RC"
3305
+ fi
2818
3306
  rc=0
2819
3307
  python3 "$PLANNER_PY" parse --plan "$PLAN" --reply "$PLAN/planner.last" || rc=$?
2820
3308
  case "$rc" in
2821
3309
  0) ;;
2822
- 4) note "auto: the planner's second reply was refused (see $PLAN/planner.refused). Nothing was dispatched after the planner"
3310
+ 4) forge_auto_record_planner "$PLAN"
3311
+ note "auto: the planner's second reply was refused (see $PLAN/planner.refused). Nothing was dispatched after the planner"
2823
3312
  exit 4 ;;
2824
- *) exit "$rc" ;;
3313
+ *) forge_auto_record_planner "$PLAN"
3314
+ exit "$rc" ;;
2825
3315
  esac
2826
3316
  bash "$SELF" plan "$PLAN" ${PLAN_ARGS[@]+"${PLAN_ARGS[@]}"}; rc=$?
3317
+ forge_auto_record_planner "$PLAN"
2827
3318
  if [ "$rc" -eq 4 ]; then
2828
3319
  note "auto: the plan gates sent items back a second time; stopping. See $PLAN/plan.sendback.md"
2829
3320
  fi
@@ -2868,7 +3359,8 @@ case "$CMD" in
2868
3359
  FORGE_DATASET_INVOCATION="inv-$(date +%s)-$$-$RANDOM"; export FORGE_DATASET_INVOCATION
2869
3360
  FORGE_DATASET_STARTED="$(date +%s)"
2870
3361
  FORGE_DATASET_ARGV=("$@")
2871
- trap 'forge_dataset_rc=$?; trap - EXIT; forge_dataset_invocation "$CMD" "$forge_dataset_rc" "$FORGE_DATASET_STARTED" ${FORGE_DATASET_ARGV[@]+"${FORGE_DATASET_ARGV[@]}"}; exit "$forge_dataset_rc"' EXIT ;;
3362
+ # An adopt's or final review's snapshot goes too, whatever the exit path (#139).
3363
+ trap 'forge_dataset_rc=$?; trap - EXIT; forge_drop_snapshot "${FORGE_REVIEW_SNAPSHOT:-}"; forge_drop_snapshot "${FINAL_REVIEW_SNAPSHOT:-}"; forge_dataset_invocation "$CMD" "$forge_dataset_rc" "$FORGE_DATASET_STARTED" ${FORGE_DATASET_ARGV[@]+"${FORGE_DATASET_ARGV[@]}"}; exit "$forge_dataset_rc"' EXIT ;;
2872
3364
  esac
2873
3365
  # Subcommands implemented in the optional libraries fail clearly if the library is absent.
2874
3366
  need_fn() { declare -F "$1" >/dev/null || die "'$CMD' is not available: $1 is missing" 3; }
@@ -2890,6 +3382,8 @@ case "$CMD" in
2890
3382
  run_wait "$run_job"; rc=$run_rc
2891
3383
  trap - TERM INT
2892
3384
  [ "$run_signalled" = 1 ] && [ "$rc" -gt 128 ] && rc=130
3385
+ # Older integrations' outcomes that came due (#120), unless the run was interrupted: bounded, never the exit code.
3386
+ [ "$run_signalled" = 1 ] || forge_outcomes_harvest "${1:-}"
2893
3387
  forge_update_notice; exit "$rc" ;;
2894
3388
  retry)
2895
3389
  # As run: the handler lives at the pid the user started, and do_retry runs in a background
@@ -2904,7 +3398,7 @@ case "$CMD" in
2904
3398
  trap - TERM INT
2905
3399
  [ "$retry_signalled" = 1 ] && [ "$rc" -le 128 ] && rc=143
2906
3400
  exit "$rc" ;;
2907
- integrate) do_integrate "$@" ;;
3401
+ integrate) do_integrate "$@"; rc=$?; forge_outcomes_harvest "${1:-}"; exit "$rc" ;;
2908
3402
  accept) need_fn do_accept; do_accept "$@" ;;
2909
3403
  adopt) need_fn do_adopt; do_adopt "$@" ;;
2910
3404
  review) need_fn do_review; do_review "$@" ;;
@@ -2913,6 +3407,8 @@ case "$CMD" in
2913
3407
  combine) need_fn do_combine; do_combine "$@" ;;
2914
3408
  _task) do_task "$@" ;;
2915
3409
  _merge) merge_task "$@" ;;
3410
+ # The live scheduler's accept (forge control accept, #138): it holds the plan lock already.
3411
+ _accept) need_fn do_accept; FORGE_ACCEPT_LIVE=1 do_accept "$@" ;;
2916
3412
  _prepare_retry) retry_for_scheduler "$@" ;;
2917
3413
  _qa_only) qa_only_next "$@" ;;
2918
3414
  _waves) compute_waves "$@" ;;