@giamme/forge 0.12.1 → 0.13.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 (107) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +1 -1
  3. package/SKILL.md +29 -12
  4. package/VERSION +1 -1
  5. package/docs/add-ons.md +11 -6
  6. package/docs/artifacts.md +12 -6
  7. package/docs/commands.md +179 -17
  8. package/docs/decomposed-runs.md +13 -5
  9. package/docs/forge-ui.md +7 -3
  10. package/docs/memory.md +2 -1
  11. package/docs/models.md +4 -2
  12. package/docs/reviews.md +49 -20
  13. package/docs/troubleshooting.md +3 -1
  14. package/forge +17 -1
  15. package/package.json +1 -1
  16. package/references/dataset.md +39 -13
  17. package/references/decision-models.md +759 -0
  18. package/references/decompose.md +166 -29
  19. package/references/harnesses.md +10 -3
  20. package/references/planning.md +8 -0
  21. package/references/solo.md +13 -3
  22. package/scripts/forge-artifact.sh +30 -4
  23. package/scripts/forge-config.py +238 -29
  24. package/scripts/forge-contract.py +95 -56
  25. package/scripts/forge-control.py +40 -9
  26. package/scripts/forge-decide.py +6 -0
  27. package/scripts/forge-dispatch.sh +38 -16
  28. package/scripts/forge-fail-first.py +2 -2
  29. package/scripts/forge-gate-addressed.sh +40 -0
  30. package/scripts/forge-gate-message.sh +64 -0
  31. package/scripts/forge-issues.py +321 -33
  32. package/scripts/forge-jev-options.sh +269 -42
  33. package/scripts/forge-lib-attribute.sh +447 -0
  34. package/scripts/forge-lib-gates.sh +32 -0
  35. package/scripts/forge-lib-plans.sh +17 -6
  36. package/scripts/forge-lib-review.sh +22 -17
  37. package/scripts/forge-lib-task.sh +217 -38
  38. package/scripts/forge-lib-verify.sh +45 -8
  39. package/scripts/forge-memory.sh +3 -3
  40. package/scripts/forge-parallel-options.sh +18 -5
  41. package/scripts/forge-parallel.sh +455 -303
  42. package/scripts/forge-plan-check.py +35 -1
  43. package/scripts/forge-pre-review.py +437 -0
  44. package/scripts/forge-prompt.py +25 -5
  45. package/scripts/forge-route.py +2 -2
  46. package/scripts/forge-runtime.py +10 -4
  47. package/scripts/forge-schedule.py +21 -5
  48. package/scripts/forge-shadow.py +2 -2
  49. package/scripts/forge-solo.sh +38 -9
  50. package/scripts/forge-submodules.py +389 -0
  51. package/scripts/forge_dataset/cli.py +12 -6
  52. package/scripts/forge_dataset/export.py +55 -45
  53. package/scripts/forge_dataset/harvest.py +33 -5
  54. package/scripts/{forge_jev/outcome.py → forge_dataset/states.py} +21 -7
  55. package/scripts/forge_decide/__init__.py +141 -0
  56. package/scripts/forge_decide/budget.py +149 -0
  57. package/scripts/forge_decide/cache.py +66 -0
  58. package/scripts/forge_decide/cli.py +953 -0
  59. package/scripts/forge_decide/doctor.py +221 -0
  60. package/scripts/forge_decide/label_addressed.py +75 -0
  61. package/scripts/forge_decide/label_attribution.py +62 -0
  62. package/scripts/forge_decide/label_coverage.py +81 -0
  63. package/scripts/forge_decide/label_message.py +38 -0
  64. package/scripts/forge_decide/label_prompt.py +139 -0
  65. package/scripts/forge_decide/labels.py +328 -0
  66. package/scripts/forge_decide/metrics.py +125 -0
  67. package/scripts/forge_decide/migrate.py +226 -0
  68. package/scripts/forge_decide/providers.py +292 -0
  69. package/scripts/forge_decide/replay.py +350 -0
  70. package/scripts/forge_decide/report.py +382 -0
  71. package/scripts/forge_decide/resolve.py +397 -0
  72. package/scripts/forge_decide/sites.py +377 -0
  73. package/scripts/forge_jev/__init__.py +202 -104
  74. package/scripts/forge_jev/addressed.py +171 -0
  75. package/scripts/forge_jev/attribution.py +198 -0
  76. package/scripts/forge_jev/cli.py +460 -382
  77. package/scripts/forge_jev/client.py +155 -77
  78. package/scripts/forge_jev/coupling.py +19 -87
  79. package/scripts/forge_jev/coverage.py +303 -0
  80. package/scripts/forge_jev/findings.py +219 -0
  81. package/scripts/forge_jev/gates.py +225 -27
  82. package/scripts/forge_jev/memory.py +65 -4
  83. package/scripts/forge_jev/message.py +134 -0
  84. package/scripts/forge_jev/plan_gates.py +294 -0
  85. package/scripts/forge_jev/questions.py +173 -313
  86. package/scripts/forge_jev/verify.py +130 -104
  87. package/ui/README.md +2 -2
  88. package/ui/docs/api.md +60 -32
  89. package/ui/forge_ui/control.py +60 -11
  90. package/ui/forge_ui/export.py +2 -1
  91. package/ui/forge_ui/models.py +1 -0
  92. package/ui/forge_ui/reader.py +87 -14
  93. package/ui/forge_ui/static/app.js +2 -2
  94. package/ui/forge_ui/static/controls.js +20 -13
  95. package/ui/forge_ui/static/panel.js +63 -17
  96. package/ui/forge_ui/static/runmodel.js +23 -1
  97. package/ui/forge_ui/static/scene3d.js +2 -15
  98. package/ui/forge_ui/static/settings.js +336 -41
  99. package/ui/forge_ui/static/style.css +19 -7
  100. package/references/jev.md +0 -865
  101. package/scripts/forge_jev/backtest.py +0 -322
  102. package/scripts/forge_jev/corpus.py +0 -156
  103. package/scripts/forge_jev/features.py +0 -24
  104. package/scripts/forge_jev/predict.py +0 -204
  105. package/scripts/forge_jev/review.py +0 -73
  106. package/scripts/forge_jev/routing.py +0 -271
  107. package/scripts/forge_jev/subset.py +0 -123
@@ -4,7 +4,8 @@
4
4
  show <plan> [--json] every control, per-task overrides, pins and the change log
5
5
  set <plan> <key> <value> [--task ID] qa-threshold, timeout, escalate-after, escalate-effort,
6
6
  verify-retries, retry-budget, infra-retries, infra-backoff
7
- (none drops it), max-parallel (1-64)
7
+ (none drops it), max-parallel (1-64), pre-review-tests
8
+ (on/off), pre-review-parallel (1-64)
8
9
  pin <plan> <task> <spec> the model the task's next FULL implementer retry uses
9
10
  unpin <plan> <task>
10
11
  retry <plan> <task> [--dwarf SPEC] queue a retry of a stopped or failed task into the live run
@@ -18,8 +19,8 @@
18
19
  them like SIGTERM
19
20
 
20
21
  `show` reports escalate-after and verify-retries at their defaults (3 and 1) when unset,
21
- escalate-effort as on or off (off when the file is absent), and the two budgets only while a
22
- scheduler is live.
22
+ escalate-effort and pre-review-tests as on or off (off when the file is absent), pre-review-parallel
23
+ at its default (2) when unset, and the two budgets only while a scheduler is live.
23
24
 
24
25
  Every change is validated, written atomically under the plan's control lock (`control.lock`),
25
26
  appended to `control.log` and recorded as a dataset `control` event. This is the only writer of
@@ -63,6 +64,7 @@ LOG_TAIL = 256 * 1024
63
64
  READ_MAX = 8 * 1024 * 1024
64
65
  DEFAULT_ESCALATE_AFTER = 3 # forge-route.py
65
66
  DEFAULT_VERIFY_RETRIES = 1 # forge-parallel.sh
67
+ DEFAULT_PRE_REVIEW_PARALLEL = 2 # forge-artifact.sh forge_pre_review
66
68
  LEVELS = ('P0', 'P1', 'P2', 'P3')
67
69
  STOP_MARKERS = ('escalation.stop', 'split.suggested', 'escalation.next')
68
70
  DIR_FLAGS = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC
@@ -372,6 +374,25 @@ def level(text, task_level=False):
372
374
  return text if text in LEVELS or (task_level and text == 'none') else None
373
375
 
374
376
 
377
+ _CONTRACT = None
378
+
379
+
380
+ def run_threshold(text):
381
+ """(effective level, 'set' | 'default') of the plan file's text; `none` means P3."""
382
+ global _CONTRACT
383
+ if _CONTRACT is None:
384
+ import importlib.util
385
+ spec = importlib.util.spec_from_file_location('forge_contract', os.path.join(SKILL, 'scripts', 'forge-contract.py'))
386
+ _CONTRACT = importlib.util.module_from_spec(spec)
387
+ spec.loader.exec_module(_CONTRACT)
388
+ value = (text.splitlines()[0].replace(' ', '').upper() if text else '')
389
+ if value == 'NONE':
390
+ return LEVELS[-1], 'set'
391
+ if value in LEVELS:
392
+ return value, 'set'
393
+ return _CONTRACT.DEFAULT_THRESHOLD, 'default'
394
+
395
+
375
396
  def nullable(value):
376
397
  return None if value in (None, '', '-', 'UNASSIGNED') else value
377
398
 
@@ -399,7 +420,8 @@ def show(plan, rows):
399
420
  def budget(rel):
400
421
  return number(get(rel)) if live else None
401
422
 
402
- run = dict(qa_threshold=level(get('qa_threshold')), timeout=number(get('timeout')),
423
+ threshold, source = run_threshold(get('qa_threshold'))
424
+ run = dict(qa_threshold=threshold, qa_threshold_source=source, timeout=number(get('timeout')),
403
425
  escalate_after=number(get('escalate_after')),
404
426
  escalate_effort='on' if get('escalate_effort') == 'on' else 'off',
405
427
  verify_retries=number(get('verify_retries')),
@@ -415,6 +437,10 @@ def show(plan, rows):
415
437
  run['escalate_after'] = DEFAULT_ESCALATE_AFTER
416
438
  if run['verify_retries'] is None:
417
439
  run['verify_retries'] = DEFAULT_VERIFY_RETRIES
440
+ # Pre-review tests (#85): the plan file's presence turns them on (`plan --pre-review-tests`).
441
+ run['pre_review_tests'] = 'on' if has(plan, 'pre_review_tests') else 'off'
442
+ slots = number(get('pre_review_parallel'))
443
+ run['pre_review_parallel'] = slots if slots and slots <= 64 else DEFAULT_PRE_REVIEW_PARALLEL
418
444
  tasks = {}
419
445
  for row in rows:
420
446
  task = row[0]
@@ -445,9 +471,10 @@ def show(plan, rows):
445
471
  # ------------------------------------------------------------------------------------ changes
446
472
 
447
473
  def _qa(value, task):
448
- if value in LEVELS or value == 'none' or (task and value == 'inherit'):
474
+ if value in LEVELS or value == 'none' or (task and value == 'inherit') or (not task and value == 'default'):
449
475
  return value
450
- raise Invalid('qa-threshold needs P0, P1, P2, P3 or none' + (' (or inherit for a task)' if task else ''))
476
+ raise Invalid('qa-threshold needs P0, P1, P2, P3 or none (none means P3)'
477
+ + (' (or inherit to drop the override)' if task else ', or default to drop the file'))
451
478
 
452
479
 
453
480
  def _int(value, task):
@@ -511,6 +538,8 @@ KEYS = {
511
538
  'infra-retries': ('plan', _int, 'infra_budget', True, NEXT_DECISION),
512
539
  'infra-backoff': ('plan', _backoff, 'infra_backoff', False, NEXT_INFRA_WAIT),
513
540
  'max-parallel': ('plan', _parallel, 'max_parallel', True, NEXT_DISPATCH),
541
+ 'pre-review-tests': ('plan', _onoff, 'pre_review_tests', False, NEXT_ATTEMPT),
542
+ 'pre-review-parallel': ('plan', _parallel, 'pre_review_parallel', False, NEXT_ATTEMPT),
514
543
  }
515
544
 
516
545
 
@@ -573,7 +602,8 @@ def cmd_set(args):
573
602
  except Invalid as error:
574
603
  raise Invalid(f'{args.key}: {error}')
575
604
  rel = f'tasks/{task}/{name}' if task else name
576
- drop = value == 'inherit' or (value == 'none' and not task) or (args.key == 'escalate-effort' and value == 'off')
605
+ drop = (value in ('inherit', 'default') or (args.key in ('escalate-effort', 'pre-review-tests') and value == 'off')
606
+ or (args.key == 'infra-backoff' and value == 'none'))
577
607
  # Plan-wide stop markers go when the policy that wrote them changes: the policy turned off
578
608
  # (escalate-after 0), or the effort step turned on, which may yet have a move for them.
579
609
  wide = (args.key == 'escalate-after' and value == '0') or (args.key == 'escalate-effort' and value == 'on')
@@ -789,7 +819,8 @@ def cmd_show(args):
789
819
  run = controls['run']
790
820
  print(f"{plan} run {cell(controls['run_id'])} live {'yes' if controls['live'] else 'no'}"
791
821
  f" fractal {'yes' if controls['fractal'] else 'no'}")
792
- print(' ' + ' '.join(f"{k.replace('_', '-')} {cell(v)}" for k, v in run.items() if k != 'infra_paused'))
822
+ print(' ' + ' '.join(f"{k.replace('_', '-')} {cell(v)}" + (' (default)' if k == 'qa_threshold' and run['qa_threshold_source'] == 'default' else '')
823
+ for k, v in run.items() if k not in ('infra_paused', 'qa_threshold_source')))
793
824
  for p in run['infra_paused'] or []:
794
825
  tasks = ','.join(t for t in (p['tasks'] or []) if isinstance(t, str)) or '-'
795
826
  if p['exhausted']:
@@ -836,7 +867,7 @@ def parser():
836
867
  p.set_defaults(func=cmd_show)
837
868
  p = sub.add_parser('set', help='change a control', description='Keys: ' + ', '.join(KEYS) + '. '
838
869
  'retry-budget, infra-retries and max-parallel change only while a run is live. '
839
- 'qa-threshold and retry-budget also take --task (value inherit drops the override).')
870
+ 'qa-threshold and retry-budget also take --task (value inherit drops the override; at run level, default drops the file and none means P3).')
840
871
  common(p)
841
872
  p.add_argument('key', choices=list(KEYS))
842
873
  p.add_argument('value')
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env python3
2
+ """Repository-local entry point for forge decide, the decision-model gates."""
3
+ from forge_decide.cli import main
4
+
5
+ if __name__ == '__main__':
6
+ raise SystemExit(main())
@@ -11,6 +11,8 @@
11
11
  # [--native-review [--review-base <ref>]]
12
12
  # forge-dispatch.sh qa <spec> ... --continue-session <id> continue that reviewer session
13
13
  # (claude, openclaude, codex; custom prompt only)
14
+ # forge-dispatch.sh dwarf <spec> ... --continue-session <id> continue that implementer session
15
+ # (claude, openclaude)
14
16
  # any role: [--no-ripwire] [--ripwire-query-file <requirements>]
15
17
  # any role: [--timeout <seconds>] 0 disables the watchdog
16
18
  # forge-dispatch.sh efforts --spec <spec>
@@ -278,8 +280,10 @@ if [ "$NATIVE_REVIEW" = 1 ] && { [ "$ROLE" != qa ] || [ "$HARNESS" != codex ]; }
278
280
  die "--native-review requires QA on codex"
279
281
  fi
280
282
  if [ "$CONTINUE_GIVEN" = 1 ]; then
281
- [ "$ROLE" = qa ] && [ "$NATIVE_REVIEW" != 1 ] && { [ "$HARNESS" = codex ] || [ "$HARNESS" = claude ] || [ "$HARNESS" = openclaude ]; } \
282
- || die "--continue-session needs the qa role on codex, claude or openclaude, without --native-review"
283
+ # codex's `exec resume` takes no sandbox flag, so only a read-only reviewer continues there:
284
+ # an implementer's write access would rest on a config override nothing verifies.
285
+ [ "$NATIVE_REVIEW" != 1 ] && case "$ROLE:$HARNESS" in qa:codex|qa:claude|qa:openclaude|dwarf:claude|dwarf:openclaude) true ;; *) false ;; esac \
286
+ || die "--continue-session needs the qa role on codex, claude or openclaude, or the dwarf role on claude or openclaude, without --native-review"
283
287
  case "$CONTINUE_ID" in ''|*[!A-Za-z0-9-]*) die "--continue-session id must be letters, digits and '-' only" ;; esac
284
288
  [ "${#CONTINUE_ID}" -ge 8 ] && [ "${#CONTINUE_ID}" -le 128 ] || die "--continue-session id must be 8 to 128 characters"
285
289
  fi
@@ -307,11 +311,13 @@ if [ "$NO_EFFORT" = 1 ]; then
307
311
  EFFORT=""
308
312
  else
309
313
  if [ -z "$EFFORT" ]; then
310
- # Build at medium, review high: a reviewer that thinks less than the
311
- # implementer tends to rubber-stamp, which defeats the point of a second model.
312
- # Planning is the stage where thinking pays for itself most cheaply — a bad
313
- # plan is executed at full cost by every dwarf downstream of it.
314
- case "$ROLE" in dwarf) EFFORT="medium" ;; qa|planner) EFFORT="xhigh" ;; esac
314
+ # Build at medium, review at high: a reviewer that thinks less than the
315
+ # implementer tends to rubber-stamp, which defeats the point of a second model;
316
+ # xhigh reviews cost about twice as much for the same verdicts (#89). Planning is
317
+ # the stage where thinking pays for itself most cheaply — a bad plan is executed
318
+ # at full cost by every dwarf downstream of it. forge-parallel.sh's approval
319
+ # table names the QA default (render_table).
320
+ case "$ROLE" in dwarf) EFFORT="medium" ;; qa) EFFORT="high" ;; planner) EFFORT="xhigh" ;; esac
315
321
  DEFAULTED=1
316
322
  [ -n "$LADDER" ] || EFFORT="" # opencode: no ladder, let the provider choose
317
323
  else
@@ -459,15 +465,25 @@ if [ -n "$ATTEMPT" ]; then
459
465
  --prompt "$PROMPT_FILE" --query "$RIPWIRE_QUERY" --baseline "$REVIEW_BASE" \
460
466
  --artifacts "$ATTEMPT" --native "$NATIVE_REVIEW" || note "Ripwire preparation failed; continuing"
461
467
  fi
462
- # A continued reviewer remembers the earlier round, including its instructions. $ROLE.prompt
463
- # records what was sent, so the preamble goes into the file itself.
468
+ # A continued session remembers the earlier round, including its instructions. $ROLE.prompt
469
+ # records what was sent, so the preamble goes into the file itself. A continued implementer's
470
+ # work is exactly as it left it (forge-parallel.sh continues only then), so it need not re-read
471
+ # it; a continued reviewer is looking at changed work.
464
472
  if [ -n "$CONTINUE_ID" ]; then
465
473
  continued_prompt="$(mktemp "$RUN_DIR/.prompt.XXXXXX")" || die "cannot create continued prompt"
466
474
  {
467
- printf 'This continues your earlier review of this work. The work has changed since you last\n'
468
- printf 'looked. Your working directory is now %s. Re-read files rather than relying on what\n' "$REPO"
469
- printf 'you read before. Review this round exactly as instructed below; where it differs from\n'
470
- printf "earlier instructions (a threshold, for example), this round's instructions win.\n\n"
475
+ if [ "$ROLE" = dwarf ]; then
476
+ printf 'This continues your earlier work on this task, which has been reviewed since. Your\n'
477
+ printf 'working directory is %s; your changes are there as you left them,\n' "$REPO"
478
+ printf 'committed on the task branch, so you need not read them again. Work this attempt\n'
479
+ printf "exactly as instructed below; where it differs from earlier instructions, this attempt's\n"
480
+ printf 'instructions win.\n\n'
481
+ else
482
+ printf 'This continues your earlier review of this work. The work has changed since you last\n'
483
+ printf 'looked. Your working directory is now %s. Re-read files rather than relying on what\n' "$REPO"
484
+ printf 'you read before. Review this round exactly as instructed below; where it differs from\n'
485
+ printf "earlier instructions (a threshold, for example), this round's instructions win.\n\n"
486
+ fi
471
487
  cat "$PROMPT_FILE"
472
488
  } > "$continued_prompt" && mv "$continued_prompt" "$RUN_DIR/$ROLE.prompt" || { rm -f "$continued_prompt"; die "cannot install continued prompt"; }
473
489
  fi
@@ -727,7 +743,7 @@ fi
727
743
  # when a stale $LAST is already there. That is harmless when each run gets a fresh
728
744
  # run-dir, and silently wrong for `forge-parallel.sh retry`, which reuses the task
729
745
  # directory — it would read the first attempt's result and never notice.
730
- rm -f "$LAST" "$LOG" "$RUN_DIR/$ROLE.clock" "$RUN_DIR/$ROLE.timedout" "$RUN_DIR/$ROLE.infra" "$RUN_DIR/$ROLE.orphans" "$RUN_DIR/$ROLE.harness"
746
+ rm -f "$LAST" "$LOG" "$RUN_DIR/$ROLE.clock" "$RUN_DIR/$ROLE.clock.stop" "$RUN_DIR/$ROLE.timedout" "$RUN_DIR/$ROLE.infra" "$RUN_DIR/$ROLE.orphans" "$RUN_DIR/$ROLE.harness"
731
747
  python3 "$RUNTIME" phase "$ATTEMPT" model
732
748
  t0="$(date +%s)"
733
749
  # Process-group guard. A dwarf that starts `npm test &` and ends its turn leaves that
@@ -794,8 +810,14 @@ if [ "${LIMIT:-0}" != "0" ]; then
794
810
  fi
795
811
 
796
812
  wait "$hpid"; rc=$?
797
- # Its last sample is in before `finish` copies the clock into the attempt.
798
- if [ -n "$cpid" ]; then kill "$cpid" 2>/dev/null; wait "$cpid" 2>/dev/null; cpid=""; fi
813
+ # Its last sample is in before `finish` copies the clock into the attempt. A stop file, not a TERM:
814
+ # a signal could reach a sampler still starting up and kill it before its first sample (#84). When
815
+ # the file cannot be written (the run dir is gone, the disk is full), a TERM it is: the sampler
816
+ # waits for that file or for its parent, and its parent is this `wait` (#100).
817
+ if [ -n "$cpid" ]; then
818
+ { : > "$RUN_DIR/$ROLE.clock.stop"; } 2>/dev/null || kill -TERM "$cpid" 2>/dev/null
819
+ wait "$cpid" 2>/dev/null; cpid=""; rm -f "$RUN_DIR/$ROLE.clock.stop"
820
+ fi
799
821
  if [ -n "$wpid" ]; then
800
822
  # The watchdog is asleep in a child of its own; kill that too or it outlives the
801
823
  # run as an orphan holding the timer.
@@ -38,8 +38,8 @@ import sys
38
38
  import tempfile
39
39
  import time
40
40
 
41
- # The same two conditions as forge_jev/subset.py: a test path, and for the files that are run,
42
- # a source suffix (README.md and JSON fixtures under tests/ are carried over, never run).
41
+ # Two conditions: a test path, and for the files that are run, a source suffix
42
+ # (README.md and JSON fixtures under tests/ are carried over, never run).
43
43
  TEST_PATH = re.compile(r'(^|/)(tests?|spec|specs|__tests__)/'
44
44
  r'|(^|/)test_[^/]*$|_test\.[^/]+$|\.(test|spec)\.[^/]+$')
45
45
  CODE_SUFFIXES = ('.py', '.go', '.js', '.jsx', '.ts', '.tsx', '.rb', '.rs', '.java',
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+ # The retry-addressed gate (#43): a retry whose diff leaves a blocking finding untouched goes
3
+ # back to the implementer without a review. Sourced by forge-lib-gates.sh; forge_pre_qa_gates
4
+ # calls it right after reviewed.commit is written, before QA is dispatched.
5
+ #
6
+ # It can only send work back: it never accepts anything, and it fails open (no key, no answer, a
7
+ # shadow gate, any error all return 0). The attempt after a bounce has retry_findings.source
8
+ # `bounce`, so this never runs twice in a row and QA always comes next.
9
+
10
+ forge_gate_addressed() { # forge_gate_addressed <plan> <id> <tdir> <wt> <attempt> <reviewed>
11
+ local plan="$1" id="$2" tdir="$3" wt="$4" attempt="$5" reviewed="$6"
12
+ declare -F forge_decide_active >/dev/null || return 0
13
+ forge_decide_active retry-addressed || return 0
14
+ [ "$attempt" -gt 1 ] 2>/dev/null || return 0
15
+ [ "$(cat "$tdir/retry_findings.source" 2>/dev/null)" = review ] || return 0
16
+
17
+ attempt_delta "$tdir" "$wt" "$reviewed"
18
+ [ -s "$tdir/changes.since.diff" ] || return 0
19
+
20
+ local rows rc=0 count row_id row_p row_finding
21
+ rows="$(python3 "$SKILL_DIR/scripts/forge-jev.py" retry-addressed \
22
+ --plan "$plan" --task "$id" --attempt "$attempt" --repo "$REPO" 2>/dev/null)" || rc=$?
23
+ [ "$rc" -eq 0 ] && [ -n "$rows" ] || return 0
24
+
25
+ count="$(printf '%s\n' "$rows" | grep -c .)"
26
+ {
27
+ echo "forge: these blocking findings look unaddressed by your change:"
28
+ echo
29
+ while IFS=$'\t' read -r row_id row_p row_finding; do
30
+ printf -- '- %s\n' "$row_finding"
31
+ done <<< "$rows"
32
+ echo
33
+ cat "$tdir/retry_findings.md"
34
+ } > "$tdir/.bounce.md.tmp" && mv "$tdir/.bounce.md.tmp" "$tdir/bounce.md" || return 0
35
+ : > "$tdir/bounced"
36
+ rm -f "$tdir/qa.last"
37
+ echo FAIL > "$tdir/status"
38
+ note "$id: the retry leaves $count blocking finding(s) untouched — sent back without a review (see $tdir/bounce.md)"
39
+ return 1
40
+ }
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env bash
2
+ # The dwarf-message gate (#44): the implementer's final message is read before a review is paid
3
+ # for. Sourced by forge-lib-gates.sh; forge_post_dwarf_gates calls it right after the dwarf's
4
+ # reply is in, before the diff snapshot and its empty-diff exits.
5
+ #
6
+ # `question` stops the task as NEEDS_INPUT for the user's answer; `blocked` and `unfinished`
7
+ # send the attempt back as FAIL, with the implementer's own words as the retry's findings, and no
8
+ # review. Neither writes qa.gate or dispatches QA. It fails open (a gate that is off or in
9
+ # shadow, no key, no answer, any error all return 0), and it is the only way an attempt that
10
+ # changed nothing can fail on what its dwarf said.
11
+
12
+ forge_gate_message() { # forge_gate_message <plan> <id> <tdir> <wt> <attempt>
13
+ local plan="$1" id="$2" tdir="$3" wt="$4" attempt="$5"
14
+ declare -F forge_decide_active >/dev/null || return 0
15
+ forge_decide_active dwarf-message || return 0
16
+
17
+ local row rc=0 which p said
18
+ row="$(python3 "$SKILL_DIR/scripts/forge-jev.py" dwarf-message \
19
+ --plan "$plan" --task "$id" --attempt "$attempt" --repo "$REPO" 2>/dev/null)" || rc=$?
20
+ [ "$rc" -eq 0 ] && [ -n "$row" ] || return 0
21
+ IFS=$'\t' read -r which p <<< "$row"
22
+ # the last 3000 characters, not bytes: a byte cut can split a UTF-8 character, and sed then
23
+ # fails on the illegal byte sequence (invalid input bytes become U+FFFD)
24
+ said="$(python3 -c '
25
+ import sys
26
+ text = open(sys.argv[1], "rb").read().decode("utf-8", "replace")[-3000:]
27
+ sys.stdout.buffer.write(text.encode("utf-8"))' "$tdir/dwarf.last" 2>/dev/null)"
28
+
29
+ case "$which" in
30
+ question)
31
+ {
32
+ echo "The implementer asked:"
33
+ echo
34
+ printf '%s\n' "$said"
35
+ } > "$tdir/.needs_input.md.tmp" && mv "$tdir/.needs_input.md.tmp" "$tdir/needs_input.md" || return 0
36
+ rm -f "$tdir/qa.last" # an earlier review describes other code
37
+ : > "$tdir/noretry"
38
+ echo NEEDS_INPUT > "$tdir/status"
39
+ note "$id: the implementer asked a question only you can answer — stopped (see $tdir/needs_input.md)"
40
+ return 1
41
+ ;;
42
+ blocked|unfinished)
43
+ {
44
+ echo "forge: the implementer's final message says it did not finish ($which, $p); its own words:"
45
+ echo
46
+ printf '%s\n' "$said" | sed 's/^/> /'
47
+ # The findings this attempt was sent replace nothing: they go on with the retry, as
48
+ # a bounce keeps them (forge-gate-addressed.sh).
49
+ if [ -s "$tdir/retry_findings.md" ]; then
50
+ echo
51
+ echo "The findings this attempt was sent, still to fix:"
52
+ echo
53
+ cat "$tdir/retry_findings.md"
54
+ fi
55
+ } > "$tdir/.message.md.tmp" && mv "$tdir/.message.md.tmp" "$tdir/message.md" || return 0
56
+ : > "$tdir/message.failed"
57
+ rm -f "$tdir/qa.last"
58
+ echo FAIL > "$tdir/status"
59
+ note "$id: the implementer says it did not finish ($which) — sent back without a review (see $tdir/message.md)"
60
+ return 1
61
+ ;;
62
+ esac
63
+ return 0
64
+ }