@giamme/forge 0.13.0 → 0.14.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 (60) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/SKILL.md +17 -11
  3. package/VERSION +1 -1
  4. package/docs/artifacts.md +1 -0
  5. package/docs/commands.md +121 -7
  6. package/docs/development.md +3 -0
  7. package/docs/forge-ui.md +7 -1
  8. package/docs/reviews.md +2 -0
  9. package/docs/troubleshooting.md +5 -1
  10. package/forge +28 -1
  11. package/package.json +1 -1
  12. package/references/dataset.md +3 -1
  13. package/references/decision-models.md +5 -1
  14. package/references/decompose.md +199 -61
  15. package/references/runtime.md +29 -0
  16. package/references/ui.md +10 -0
  17. package/scripts/forge-compare.py +491 -0
  18. package/scripts/forge-config.py +3 -3
  19. package/scripts/forge-contract.py +34 -8
  20. package/scripts/forge-control.py +105 -13
  21. package/scripts/forge-dispatch.sh +9 -5
  22. package/scripts/forge-jev-options.sh +17 -4
  23. package/scripts/forge-ledger.py +387 -0
  24. package/scripts/forge-lib-plans.sh +16 -2
  25. package/scripts/forge-lib-task.sh +390 -28
  26. package/scripts/forge-parallel-options.sh +20 -4
  27. package/scripts/forge-parallel.sh +118 -12
  28. package/scripts/forge-plan-check.py +68 -3
  29. package/scripts/forge-pr.py +276 -0
  30. package/scripts/forge-route.py +350 -34
  31. package/scripts/forge-runs.py +18 -1
  32. package/scripts/forge-runtime.py +23 -7
  33. package/scripts/forge-schedule.py +303 -46
  34. package/scripts/forge-solo.sh +1 -0
  35. package/scripts/forge-ui-options.sh +25 -0
  36. package/scripts/forge-verify-failed.py +111 -0
  37. package/scripts/forge-watch.py +372 -0
  38. package/scripts/forge_dataset/export.py +87 -41
  39. package/scripts/forge_dataset/harvest.py +3 -1
  40. package/scripts/forge_decide/budget.py +39 -8
  41. package/scripts/forge_decide/doctor.py +49 -0
  42. package/scripts/forge_fractal/cli.py +23 -6
  43. package/scripts/forge_infra.py +274 -0
  44. package/scripts/forge_jev/client.py +13 -9
  45. package/ui/docs/api.md +83 -15
  46. package/ui/forge_ui/control.py +11 -3
  47. package/ui/forge_ui/export.py +6 -2
  48. package/ui/forge_ui/models.py +16 -16
  49. package/ui/forge_ui/reader.py +217 -13
  50. package/ui/forge_ui/repos.py +428 -0
  51. package/ui/forge_ui/static/app.js +24 -5
  52. package/ui/forge_ui/static/checksview.js +20 -7
  53. package/ui/forge_ui/static/cloudmodel.js +8 -5
  54. package/ui/forge_ui/static/controls.js +6 -3
  55. package/ui/forge_ui/static/modelstats.js +12 -8
  56. package/ui/forge_ui/static/panel.js +69 -4
  57. package/ui/forge_ui/static/runmodel.js +55 -10
  58. package/ui/forge_ui/static/scene3d.js +3 -2
  59. package/ui/forge_ui/static/settings.js +147 -29
  60. package/ui/forge_ui/static/style.css +49 -7
@@ -0,0 +1,274 @@
1
+ """The one table of infrastructure causes, for every Python reader (the scheduler, forge-control.py,
2
+ the summary). Standard library only.
3
+
4
+ forge-runtime.py gives each infrastructure stop a class, the name written to <role>.infra and
5
+ infra.txt. A class names a symptom, not a recovery: `quota` once covered a window that resets and
6
+ money that is gone. CAUSES says what each cause means for a recovery. Each entry is a dict with:
7
+
8
+ scope model | harness | all: what a pause holds back (one model, one harness, everything)
9
+ move lateral | wait | retry: what to do first. lateral moves the work to a peer (another
10
+ model or harness); wait pauses until the cause clears; retry dispatches again
11
+ without_peer wait | ask | wait_if_reset: what to do when no peer can take the work. wait_if_reset
12
+ waits when the reset is known and inside WAIT_CAP_S, and asks otherwise
13
+ hint a sentence for a person, with {harness} filled in by hint(); None when there is
14
+ nothing to say
15
+
16
+ LEGACY maps the class names runs recorded before the split still carry.
17
+
18
+ The run summary and `forge control show` both say what a stop is (label, reset_text, stop_of, the
19
+ summary lines), so the wording lives here too. The summary (forge-lib-task.sh) calls this file as a
20
+ program: see main().
21
+ """
22
+ from __future__ import annotations
23
+
24
+ import argparse
25
+ import json
26
+ import math
27
+ import os
28
+ import sys
29
+ import time
30
+
31
+ # The longest wait worth holding a run for; the same value as INFRA_WAIT_CAP in forge-schedule.py
32
+ # (a test keeps the two equal).
33
+ WAIT_CAP_S = 6 * 3600
34
+
35
+ CAUSES = {
36
+ 'capacity': {'scope': 'model', 'move': 'lateral', 'without_peer': 'wait', 'hint': None},
37
+ 'rate_limit': {'scope': 'model', 'move': 'wait', 'without_peer': 'wait', 'hint': None},
38
+ 'usage_limit': {'scope': 'harness', 'move': 'lateral', 'without_peer': 'wait_if_reset',
39
+ 'hint': "wait for the reset, or add another harness to this tier's pool"},
40
+ 'budget': {'scope': 'harness', 'move': 'lateral', 'without_peer': 'ask',
41
+ 'hint': 'add credits, or check the billing of {harness}'},
42
+ 'auth': {'scope': 'harness', 'move': 'lateral', 'without_peer': 'ask',
43
+ 'hint': 'log in to {harness} again'},
44
+ 'network': {'scope': 'all', 'move': 'wait', 'without_peer': 'wait', 'hint': None},
45
+ 'provider_down': {'scope': 'harness', 'move': 'lateral', 'without_peer': 'wait', 'hint': None},
46
+ 'empty': {'scope': 'model', 'move': 'retry', 'without_peer': 'wait', 'hint': None},
47
+ 'cancelled': {'scope': 'model', 'move': 'retry', 'without_peer': 'ask',
48
+ 'hint': "check {harness}'s approval and permission settings"},
49
+ }
50
+
51
+ LEGACY = {'quota': 'usage_limit'}
52
+
53
+
54
+ def cause_of(cls) -> str:
55
+ """The cause a stored class stands for: a legacy name is mapped, an unknown name is returned
56
+ as it is, and None or empty gives ''."""
57
+ if not cls:
58
+ return ''
59
+ return LEGACY.get(cls, cls)
60
+
61
+
62
+ def entry(cls) -> dict:
63
+ """The table entry for a stored class. An unknown cause acts like network: pause everything, wait."""
64
+ found = CAUSES.get(cause_of(cls))
65
+ return dict(found if found is not None else CAUSES['network'])
66
+
67
+
68
+ def needs_you(cls, has_peer, reset_known, reset_within_cap) -> bool:
69
+ """True when the recovery ends in a person: no peer to move to, and the cause will not clear
70
+ by itself (it asks outright, or it waits for a reset that is unknown or past the cap)."""
71
+ if has_peer:
72
+ return False
73
+ without_peer = entry(cls)['without_peer']
74
+ if without_peer == 'ask':
75
+ return True
76
+ return without_peer == 'wait_if_reset' and not (reset_known and reset_within_cap)
77
+
78
+
79
+ def hint(cls, harness) -> str | None:
80
+ """What to tell a person about this cause for this harness, or None when there is nothing to say."""
81
+ text = entry(cls)['hint']
82
+ return None if text is None else text.format(harness=harness or 'the harness')
83
+
84
+
85
+ def label(cls) -> str:
86
+ """The cause as a person reads it: the stored class as written (a legacy `quota` stays `quota`),
87
+ or `unknown` when there is none."""
88
+ return cls or 'unknown'
89
+
90
+
91
+ def reset_text(epoch, now) -> str:
92
+ """`resets HH:MM` for when a limit lifts, in local time; the date follows when it is not today
93
+ (as of `now`). '' when the reset is unknown."""
94
+ if epoch is None:
95
+ return ''
96
+ try:
97
+ at, today = time.localtime(epoch), time.localtime(now)
98
+ except (OverflowError, OSError, TypeError, ValueError):
99
+ return ''
100
+ if time.strftime('%Y-%m-%d', at) == time.strftime('%Y-%m-%d', today):
101
+ return 'resets ' + time.strftime('%H:%M', at)
102
+ return 'resets ' + time.strftime('%Y-%m-%d %H:%M', at)
103
+
104
+
105
+ def _epoch(value) -> float | int | None:
106
+ """A finite non-negative number from a stored value, else None."""
107
+ try:
108
+ number = float(value)
109
+ except (TypeError, ValueError):
110
+ return None
111
+ if not math.isfinite(number) or number < 0:
112
+ return None
113
+ return int(number) if number == int(number) else number
114
+
115
+
116
+ def parse_stop(text) -> dict:
117
+ """The key=value lines of a task's infra.txt, `stage=` included; a later line of a key wins."""
118
+ info = {}
119
+ for line in (text or '').splitlines():
120
+ key, sep, value = line.partition('=')
121
+ if sep and key.strip():
122
+ info[key.strip()] = value.strip()
123
+ return info
124
+
125
+
126
+ def parse_pauses(text) -> list:
127
+ """The scopes of an infra.paused file; [] when it is absent or unreadable."""
128
+ try:
129
+ scopes = json.loads(text or '')['scopes']
130
+ except (ValueError, KeyError, TypeError):
131
+ return []
132
+ if not isinstance(scopes, list):
133
+ return []
134
+ return [scope for scope in scopes if isinstance(scope, dict)]
135
+
136
+
137
+ def stop_of(task, info, scopes, now) -> dict:
138
+ """What a person needs to know about an INFRA task: its cause, where it stopped, when its limit
139
+ resets and whether a person must act. The scope that names the task in its `tasks` decides
140
+ needs_you and the hint when one does; otherwise the cause decides as it would with no peer."""
141
+ cls = info.get('class', '')
142
+ harness, model = info.get('harness', ''), info.get('model', '')
143
+ reset = _epoch(info.get('reset_at'))
144
+ # A scope on another harness is not this stop's pause, whatever its list says (an earlier run's record).
145
+ scope = next((s for s in scopes if isinstance(s.get('tasks'), list) and task in s['tasks']
146
+ and (not s.get('harness') or not harness or s.get('harness') == harness)), None)
147
+ if scope is not None:
148
+ needs, text = bool(scope.get('needs_you')), scope.get('hint')
149
+ else:
150
+ within = reset is not None and reset - now <= WAIT_CAP_S
151
+ needs, text = needs_you(cls, False, reset is not None, within), hint(cls, harness)
152
+ return dict(cause=label(cls), harness=harness, model=model, stage=info.get('stage', ''),
153
+ reset_at=reset, needs_you=needs, hint=text)
154
+
155
+
156
+ def stop_line(task, record, now) -> str:
157
+ """The run summary's line for an INFRA task, from its stop_of record."""
158
+ where = '/'.join(part for part in (record['harness'], record['model']) if part) or 'unknown'
159
+ line = ' %-14s %s on %s (%s stage)' % (task, record['cause'], where, record['stage'] or 'unknown')
160
+ reset = reset_text(record['reset_at'], now)
161
+ if reset:
162
+ line += ', ' + reset
163
+ if record['needs_you']:
164
+ line += ' — needs you' + (': ' + record['hint'] if isinstance(record['hint'], str) and record['hint'] else '')
165
+ return line
166
+
167
+
168
+ def parse_laterals(task, text, since) -> list:
169
+ """The lateral moves in one task's lateral.tsv made at or after `since`, an epoch in seconds. The rows
170
+ hold whole seconds, so `since` is taken down to one. Each move is a dict: task, role, frm, to, cause."""
171
+ moves, floor = [], math.floor(since)
172
+ for line in (text or '').splitlines():
173
+ cols = line.split('\t')
174
+ if len(cols) < 5 or not cols[0].isdigit() or int(cols[0]) < floor:
175
+ continue
176
+ cause = cols[5] if len(cols) > 5 and cols[5] != '-' else ''
177
+ moves.append(dict(task=task, role=cols[2], frm=cols[3], to=cols[4], cause=cause))
178
+ return moves
179
+
180
+
181
+ def held_lines(scopes, still_held=lambda task: True) -> list:
182
+ """The run summary's lines for the tasks a pause held back without a dispatch (infra.last's `held`):
183
+ they never stopped, so they have no stop record of their own, but the pause may need a person. A task
184
+ that has run since (`still_held` is false) is no longer held back."""
185
+ lines = []
186
+ for scope in scopes:
187
+ held = [task for task in scope.get('held') or [] if isinstance(task, str) and still_held(task)]
188
+ if not held:
189
+ continue
190
+ where = '/'.join(part for part in (scope.get('harness'), scope.get('model')) if part) or 'everything'
191
+ line = ' %-14s held back: %s on %s' % (', '.join(held), label(scope.get('class')), where)
192
+ if scope.get('needs_you') is True:
193
+ hint = scope.get('hint')
194
+ line += ' — needs you' + (': ' + hint if isinstance(hint, str) and hint else '')
195
+ lines.append(line)
196
+ return lines
197
+
198
+
199
+ def moved_line(move) -> str:
200
+ """The run summary's line for a lateral move."""
201
+ return 'moved sideways: %s %s %s → %s (%s)' % (move['task'], move['role'], move['frm'], move['to'],
202
+ label(move['cause']))
203
+
204
+
205
+ # --- the summary's helper ------------------------------------------------------------------------
206
+ def _read(plan, name) -> str:
207
+ try:
208
+ with open(os.path.join(plan, name), errors='replace') as handle:
209
+ return handle.read()
210
+ except OSError:
211
+ return ''
212
+
213
+
214
+ def _task_ids(plan) -> list:
215
+ """The task ids of tasks.tsv, in its order (the first field of each row that is not a comment)."""
216
+ return [line.split('\t')[0] for line in _read(plan, 'tasks.tsv').splitlines() if line and not line.startswith('#')]
217
+
218
+
219
+ def _stop(plan, task, scopes, now) -> dict:
220
+ return stop_of(task, parse_stop(_read(plan, os.path.join('tasks', task, 'infra.txt'))), scopes, now)
221
+
222
+
223
+ def _not_started(plan, task) -> bool:
224
+ """True while a task has neither merged nor a status: what a held task was when its run ended."""
225
+ return (not os.path.exists(os.path.join(plan, 'tasks', task, 'merged'))
226
+ and _read(plan, os.path.join('tasks', task, 'status')).strip() in ('', 'PENDING'))
227
+
228
+
229
+ def pauses_of(plan) -> list:
230
+ """The pauses of a live scheduler (infra.paused), else those its end left (infra.last)."""
231
+ return parse_pauses(_read(plan, 'infra.paused')) or parse_pauses(_read(plan, 'infra.last'))
232
+
233
+
234
+ def main(argv=None) -> int:
235
+ """forge-lib-task.sh's run summary calls this for the infrastructure block. `stop` prints one
236
+ line for an INFRA task; `needs-you` exits 0 when one of the tasks needs a person and 1 when none
237
+ does; `held` prints a line for the tasks each pause held back undispatched; `moved` prints a line
238
+ for each lateral move made at or after the given epoch time."""
239
+ parser = argparse.ArgumentParser(prog='forge_infra.py', description=main.__doc__)
240
+ commands = parser.add_subparsers(dest='command', required=True)
241
+ stop = commands.add_parser('stop', help='the summary line for one INFRA task')
242
+ stop.add_argument('plan')
243
+ stop.add_argument('task')
244
+ needs = commands.add_parser('needs-you', help='exit 0 when one of these INFRA tasks needs a person')
245
+ needs.add_argument('plan')
246
+ needs.add_argument('tasks', nargs='+')
247
+ moved = commands.add_parser('moved', help='the lateral moves made at or after a time')
248
+ moved.add_argument('plan')
249
+ moved.add_argument('since', type=float)
250
+ held = commands.add_parser('held', help='the tasks a pause held back when the run ended; exit 0 when one '
251
+ 'of those pauses needs a person')
252
+ held.add_argument('plan')
253
+ args = parser.parse_args(argv)
254
+ now = time.time()
255
+ scopes = pauses_of(args.plan)
256
+ if args.command == 'held':
257
+ still = lambda task: _not_started(args.plan, task) # noqa: E731
258
+ for line in held_lines(scopes, still):
259
+ print(line)
260
+ return 0 if any(s.get('needs_you') is True and any(still(t) for t in s.get('held') or [] if isinstance(t, str))
261
+ for s in scopes) else 1
262
+ if args.command == 'stop':
263
+ print(stop_line(args.task, _stop(args.plan, args.task, scopes, now), now))
264
+ return 0
265
+ if args.command == 'needs-you':
266
+ return 0 if any(_stop(args.plan, task, scopes, now)['needs_you'] for task in args.tasks) else 1
267
+ for task in _task_ids(args.plan):
268
+ for move in parse_laterals(task, _read(args.plan, os.path.join('tasks', task, 'lateral.tsv')), args.since):
269
+ print(moved_line(move))
270
+ return 0
271
+
272
+
273
+ if __name__ == '__main__':
274
+ sys.exit(main())
@@ -53,23 +53,25 @@ def _skip(run_dir: Path | str | None, site: str, reason: str) -> None:
53
53
  pass
54
54
 
55
55
 
56
- def _gate_fields(site) -> dict:
56
+ def _gate_fields(site, resolved: dict | None = None) -> dict:
57
57
  """The gate a site answers to and its resolved mode. `shadow` is that mode, or --jev-shadow
58
58
  on a gate the legacy level turned on (no user decide.json yet), which acts as it always
59
- did and is marked shadow as it always was."""
60
- gate = _gate(site, _resolved())
59
+ did and is marked shadow as it always was. `resolved` is the resolution the request was
60
+ sent under (ask() resolves for the repo it finds, which can be the working directory's);
61
+ without it, current_repo()'s."""
62
+ gate = _gate(site, resolved if resolved is not None else _resolved())
61
63
  mode = gate['mode'] if gate else 'off'
62
64
  legacy = mode == 'on' and gate.get('source') == 'legacy' and shadow()
63
65
  return dict(gate=SITE_GATE.get(site), mode=mode, shadow=mode == 'shadow' or legacy)
64
66
 
65
67
 
66
68
  def _log(run_dir, site, key, ok, reason, latency_s, model, usage, questions, answers, provider='typesafe',
67
- cached=False) -> None:
69
+ cached=False, resolved=None) -> None:
68
70
  if run_dir is None:
69
71
  return
70
72
  entry = dict(at=time.time(), site=site, key=key, ok=ok, reason=reason, latency_s=latency_s,
71
73
  model=model, usage=usage, questions=questions, answers=answers,
72
- acting=acting(), provider=provider, cached=cached, **_gate_fields(site))
74
+ acting=acting(), provider=provider, cached=cached, **_gate_fields(site, resolved))
73
75
  try:
74
76
  with (Path(run_dir) / 'jev.jsonl').open('a') as handle:
75
77
  handle.write(json.dumps(entry) + '\n')
@@ -85,7 +87,8 @@ def _log(run_dir, site, key, ok, reason, latency_s, model, usage, questions, ans
85
87
  _DATASET_SKIP_SITES = ('setup-probe',)
86
88
 
87
89
 
88
- def _dataset(site, key, canonical, ok, reason, latency, model, usage, qids, answers, run_dir, extra=None) -> None:
90
+ def _dataset(site, key, canonical, ok, reason, latency, model, usage, qids, answers, run_dir, extra=None,
91
+ resolved=None) -> None:
89
92
  """Keep the full request (state and questions) with its answers in the run dataset.
90
93
 
91
94
  jev.jsonl keeps only the request's sha256, so a judgment could never be replayed
@@ -99,7 +102,7 @@ def _dataset(site, key, canonical, ok, reason, latency, model, usage, qids, answ
99
102
  if scripts not in sys.path:
100
103
  sys.path.insert(0, scripts)
101
104
  from forge_dataset.capture import jev
102
- fields = _gate_fields(site)
105
+ fields = _gate_fields(site, resolved)
103
106
  jev(site=site, key=key, canonical=canonical, ok=ok, reason=reason, latency=latency, model=model,
104
107
  usage=usage, questions=qids, answers=answers, run_dir=run_dir, acting=acting(),
105
108
  shadow=fields.pop('shadow'), extra=dict(extra or {}, **fields))
@@ -373,11 +376,12 @@ def ask(state, questions: dict, *, site: str, run_dir=None, config: dict | None
373
376
  def done(ok, reason, result, model=None, usage=None, latency=None, cached=False):
374
377
  latency = latency if latency is not None else time.time() - started
375
378
  answers = result['answers'] if result else None
376
- _log(run_dir, site, fixture_key, ok, reason, latency, model, usage, qids, answers, provider, cached)
379
+ _log(run_dir, site, fixture_key, ok, reason, latency, model, usage, qids, answers, provider, cached,
380
+ resolved)
377
381
  # A cache hit is not a new judgment: the dataset keeps live ones, as it does for fixtures.
378
382
  if canonical is not None and not cached:
379
383
  _dataset(site, fixture_key, canonical, ok, reason, latency, model, usage, qids, answers, run_dir,
380
- extra)
384
+ extra, resolved)
381
385
  return result
382
386
 
383
387
  fixture_key = canonical = None
package/ui/docs/api.md CHANGED
@@ -38,6 +38,7 @@ written), and the reader must never raise because of one.
38
38
  | `results.tsv` | `id<TAB>status<TAB>branch` per line, e.g. `reader MERGED forge/20261016-1530/reader` |
39
39
  | `run_id` | one line, e.g. `20261016-153012-ab12` |
40
40
  | `repo` | one line, absolute path of the target repo |
41
+ | `repo.identity` | optional, written by forge 0.13.1 and later, once at creation: `{"root", "worktree", "branch"}`, the repository `repo` belongs to. `root` is its main working tree (the same for every linked worktree), `worktree` the checkout's physical path when it differs from `root` (else `null`), `branch` its branch (`null` when HEAD is detached) |
41
42
  | `goal.txt`, `request.md` | free text |
42
43
  | `decompose_level` | `low`, `medium` or `high` |
43
44
  | `explore`, `shadow_rate` | one number each (e.g. `0.5`) |
@@ -58,13 +59,18 @@ written), and the reader must never raise because of one.
58
59
  | `final-review` | a symlink to the newest *published* review dir; `final-review.verdict` a copy of its verdict |
59
60
  | `integrate-<epoch>-<pid>/` | one `integrate`: `setup.log`, `merge.log`, `verification.*`, `attempts/verification-<uuid>/`, and `final-review/` (a review dir as above) when it ran one |
60
61
  | `tasks/<id>/merged` | exists when the task was merged; its mtime is when |
61
- | `tasks/<id>/status` | one word: `RUNNING PASS FAIL ERROR INFRA TIMEOUT UNKNOWN INVALIDATED BLOCKED INTERRUPTED NOCHANGES CONFLICT NEEDS_INPUT` |
62
+ | `tasks/<id>/status` | one word: `RUNNING PASS FAIL ERROR INFRA TIMEOUT UNKNOWN INVALIDATED BLOCKED INTERRUPTED NOCHANGES CONFLICT NEEDS_INPUT NEEDS_DECISION` |
62
63
  | `tasks/<id>/attempt` | the current attempt number |
63
64
  | `tasks/<id>/attempts.tsv` | `epoch<TAB>attempt<TAB>status<TAB>infra_class` per line, one per attempt entry; status may also be `MERGED`, `BOUNCED` or `INCOMPLETE` (a send-back that no reviewer judged: the task status stays `FAIL`), `infra_class` may be empty, `-` or missing |
64
65
  | `tasks/<id>/escalations.tsv` | `epoch<TAB>attempt<TAB>from_spec<TAB>to_spec[<TAB>source]` per line; `source` (who decided: `policy`, a human's `retry --dwarf` as `retry`, or a `pin`) is missing on older rows, which read as `policy` |
65
66
  | `tasks/<id>/qa.last` | the reviewer's final message; its last line matching `FORGE_VERDICT: PASS` or `FORGE_VERDICT: FAIL` is the verdict |
66
67
  | `tasks/<id>/prompt.md`, `approach.md`, `retry_findings.md` | free text |
67
68
  | `tasks/<id>/needs_input.md` | the question for the user, written when the task stopped `NEEDS_INPUT`: `The implementer asked:`, then the end of the dwarf's last message; free text, returned as `needs_input` |
69
+ | `tasks/<id>/infra.txt` | the stop record of an `INFRA` task: `key=value` lines `class` (the cause: `capacity`, `rate_limit`, `usage_limit`, `budget`, `auth`, `network`, `provider_down`, `empty` or `cancelled`; older runs say `quota`, `rate_limit` or `network`, shown as they are), `stage`, `harness`, `model`, `retry_after` (seconds), `reset_at` (an epoch, when known), `detail`, and `rc`, `role`; returned as `infra` |
70
+ | `tasks/<id>/lateral.tsv` | `epoch<TAB>attempt<TAB>role<TAB>from<TAB>to<TAB>cause` per line, one per move of a stopped dispatch to another model of the same tier (`role` `dwarf` or `qa`); returned as `lateral` |
71
+ | `tasks/<id>/ledger.tsv` | `epoch<TAB>attempt<TAB>review<TAB>verdict<TAB>gate<TAB>worst<TAB>confirmed<TAB>new<TAB>carried<TAB>diff_bytes<TAB>delta_bytes` per line, one per review (no header); `gate`, `worst` and `delta_bytes` may be `-`; returned as `ledger` |
72
+ | `tasks/<id>/decision.md` | written when the task stopped `NEEDS_DECISION`: its first line `reasons: converging, cap` (comma-separated, from `converging`, `split` and `cap`), then markdown for the user; returned as `decision` |
73
+ | `tasks/<id>/decisions.tsv` | `epoch<TAB>attempt<TAB>choice<TAB>reason` per line, one per human decision; a `retry=N` choice grants N more attempts; returned as `decisions` |
68
74
  | `tasks/<id>/accepted.by` | who accepted a task over a reviewer's FAIL, and why (`key=value`: `task`, `status`, `reason`, `by`, `at`, `epoch`, `attempt`, `reviewed_commit`; older runs are free text; returned as text) |
69
75
  | `tasks/<id>/qa.gate` | `threshold<TAB>decision<TAB>worst<TAB>n_confirmed<TAB>n_unlabelled<TAB>n_below` (`decision` is `accept` (the reviewer said FAIL, every CONFIRMED finding was below the threshold), `fail` (the reviewer said PASS, but listed a blocking CONFIRMED finding) or `keep`, `-` for none) |
70
76
  | `tasks/<id>/known_issues.md` | the confirmed findings a threshold tolerated |
@@ -73,7 +79,8 @@ written), and the reader must never raise because of one.
73
79
  | `tasks/<id>/<role>.log`, `<role>.clock` | the running dispatch's harness log and its clock: one `<epoch> <bytes>` line each time the log grew (forge-dispatch.sh samples it every second; `FORGE_LOG_CLOCK=off` writes none) |
74
80
  | `tasks/<id>/escalation.stop`, `split.suggested` | the retry policy stopped the task: `<attempts><TAB><model>`, and the split it suggests (free text) |
75
81
  | `scheduler.live` | `{"pid": n}`: the scheduler running the plan; it is live while that process is |
76
- | `drain`, `stop`, `max_parallel`, `infra.paused` | a live scheduler's controls (Controls below): a drain, a stop (`graceful` or `now`), a capacity, and its infrastructure pauses as `{"scopes": [{scope, class, harness, model, tasks, cycle, until, exhausted}]}` |
82
+ | `drain`, `stop`, `max_parallel`, `infra.paused` | a live scheduler's controls (Controls below): a drain, a stop (`graceful` or `now`), a capacity, and its infrastructure pauses as `{"scopes": [{scope, class, harness, model, tasks, cycle, until, exhausted, needs_you, hint, reset_at}]}`; `needs_you` (a bool), `hint` (text or `null`) and `reset_at` (an epoch or `null`) are absent in older runs, which read as `false`, `null` and `null` |
83
+ | `max_attempts` | the base attempt cap of every task, an integer: `0` for no cap; without the file it is `8`. A task's `retry=N` decisions add to it (see `attempt_cap` below) |
77
84
  | `tasks/<id>/attempts/<role>-<uuid>/` | one execution of the task: `task`, `dwarf` or `qa` |
78
85
  | `tasks/<id>/changes.diff` | `git diff --binary` of the task's work since its base, cumulative, rewritten every attempt; `changes.prev.diff` the previous attempt's; `committed.diff` base..the reviewed commit |
79
86
  | `tasks/<id>/drift.txt`, `conflict.files` | one path per line: files the diff changed without declaring them; files that conflicted on merge |
@@ -117,6 +124,7 @@ raise because of one. Older solo dirs have `verdict` and not `status`.
117
124
  |---|---|
118
125
  | `prompt.md` | the implementation prompt |
119
126
  | `repo` | one line, absolute path of the target repo |
127
+ | `repo.identity` | optional, written by forge 0.13.1 and later, once at creation: `{"root", "worktree", "branch"}`, the repository `repo` belongs to. `root` is its main working tree (the same for every linked worktree), `worktree` the checkout's physical path when it differs from `root` (else `null`), `branch` its branch (`null` when HEAD is detached) |
120
128
  | `goal.txt`, `request.md` | free text; the summary goal is the first line of `goal.txt` |
121
129
  | `status` | one word: `RUNNING`, then `PASS`, `FAIL`, `UNKNOWN`, `NOCHANGES`, `INVALIDATED`, `TIMEOUT`, `INFRA`, `INTERRUPTED` or `ERROR` |
122
130
  | `verdict` | one word, the legacy status (`PASS`, `FAIL`, `UNKNOWN`, `NOCHANGES`, `INVALIDATED`, …) |
@@ -185,6 +193,7 @@ class Catalog:
185
193
  def __init__(self, plans=(), roots=(), registry=True, registry_dir=None): ...
186
194
  def runs(self) -> list[dict] # RunSummary list, newest `updated` first
187
195
  def get(self, key) -> dict | None # RunDetail for that run_key, or None
196
+ def identity(self, key) -> dict | None # {root, worktree, branch, source} of that run; None for an unknown key
188
197
  def task(self, key, task_id) -> dict | None
189
198
  def execution(self, key, name) -> dict | None
190
199
  def final_review(self, key, name) -> dict | None
@@ -214,7 +223,7 @@ loaded. When it cannot be loaded, `findings_available` is `false` and every find
214
223
  is `null`; verdicts and `gate` do not need it.
215
224
 
216
225
  Text fields are capped so one huge file cannot blow up a response: `request`, `prompt`,
217
- `approach`, `retry_findings`, `needs_input` keep their first 20,000 characters; `qa_tail`, `dwarf_tail`
226
+ `approach`, `retry_findings`, `needs_input` and the `decision` text keep their first 20,000 characters, and an `infra` `detail` its first 400; `qa_tail`, `dwarf_tail`
218
227
  and `verification.log_tail` keep their last 4,000. A capped field ends (or, for tails,
219
228
  starts) with `…` and the value of `truncated` lists the field names that were cut.
220
229
 
@@ -256,7 +265,7 @@ its last 20,000 behind a leading `…`. Their `truncated` lists the field names
256
265
  | `POST /api/runs/<key>/issues/dismiss` | dismiss or (`undo`) restore findings; authenticated |
257
266
  | `POST /api/runs/<key>/delete` | dry-run or delete a run with `forge runs rm`; authenticated, 900 s timeout; later requests for the key answer `404` |
258
267
  | `GET /api/models/reviewers` | `200` the `forge dataset reviewers --json` report (how each reviewer's PASSed work held up); no parameters |
259
- | `GET /api/config?run=<key>` | `200` the `forge config show --json` of that run's repo |
268
+ | `GET /api/config?run=<key>` | `200` the `forge config show --json` of that run's repository root (see Config) |
260
269
  | `POST /api/config` | set or unset one allowed key (`repo.verify`, `repo.setup`, `repo.verify-subset`, `decide.gate.<gate>`, `decide.gate.<gate>.provider`, `decide.gate.<gate>.model`); `jev.enabled` is gone; authenticated |
261
270
  | `GET /api/runs/<key>/export?texts=0\|1&paths=0\|1` | `200` the run as one HTML file (see Export), `Content-Disposition: attachment`, `Content-Security-Policy: default-src 'none'; sandbox`; `404` for an unknown run |
262
271
  | `GET /api/runs/<key>/tasks/<id>/fractal` | `200 TaskFractal` |
@@ -305,6 +314,9 @@ nothing when there is none. Every other response keeps
305
314
  "kind": "plan",
306
315
  "run_id": "20261016-153012-ab12",
307
316
  "repo": "/Users/me/dev/forge-ui",
317
+ "repo_root": "/Users/me/dev/forge-ui",
318
+ "repo_worktree": null,
319
+ "repo_branch": "main",
308
320
  "goal": "first line of goal.txt",
309
321
  "decompose_level": "medium",
310
322
  "updated": 1760621412.5,
@@ -329,6 +341,18 @@ nothing when there is none. Every other response keeps
329
341
  - `created`: when the run began: the earliest birth time (else mtime) of the files a run writes
330
342
  once at its start (plan: `run_id`, `repo`, `request.md`, `goal.txt`, `tasks.tsv`; solo: `prompt.md`,
331
343
  `repo`, `request.md`, `goal.txt`), else `null`. These are stat'ed only, and never move `updated`.
344
+ - `repo_root`: the repository the run belongs to, and the key to group runs by. It is the identity's
345
+ root, or `repo` when nothing better is known (`null` only when the run has no `repo`). It is found in
346
+ four steps, the first that answers: (1) `repo.identity` in the run dir, written once at creation by
347
+ forge 0.13.1 and later, its `root`; (2) the `repo` path is a live git checkout: the main working tree
348
+ of its `git worktree list`; (3) the `repo` path is gone: the run's base commit (`integration.base`,
349
+ else a plan's first readable `tasks/*/base_ref`, else a solo run's `dwarf.head.before`) is in exactly
350
+ one root that steps 1 and 2 found in the same listing; (4) otherwise `repo` itself. Clients should
351
+ group by `repo_root` and fall back to `repo` when it is absent (an older server).
352
+ - `repo_worktree`: the checkout the run started in, when that is not `repo_root` (a linked worktree; for
353
+ a worktree that was removed, its `repo` text), else `null`.
354
+ - `repo_branch`: the branch the run started on, from `repo.identity` only; `null` when unknown (a
355
+ detached HEAD, or a run whose root came from step 2 or 3).
332
356
  - `dwarf_models`, `qa_models`: `models` split by role.
333
357
  - `models`: the sorted distinct specs of the `dwarf` and `qa` columns (a solo run: its `dwarf`
334
358
  and `qa` specs as its task has them), nulls left out.
@@ -483,7 +507,9 @@ Every RunSummary field, plus:
483
507
  - `scheduler`: `live` is whether the pid in `scheduler.live` is a running process. Only then are the
484
508
  rest read: `drained` (a `drain` file), `stopping` (`stop` holds `graceful` or `now`, else `null`),
485
509
  `max_parallel` (the `max_parallel` file when it holds 1 to 64, else `null`) and `pauses` (the scopes of
486
- `infra.paused`, `[]` without it); while no scheduler runs they are `false`, `null`, `null` and `[]`.
510
+ `infra.paused`, `[]` without it; each with `needs_you` (`true` only for a bool `true`), `hint` (a string or
511
+ `null`) and `reset_at` (an epoch or `null`), which an older scope lacks, so they read as `false`, `null`, `null`);
512
+ while no scheduler runs they are `false`, `null`, `null` and `[]`.
487
513
  A solo run's `scheduler` is `null`.
488
514
  - `sweep`: the run's finding sweep (`run --sweep`), `null` without `sweep/plan.json` (and for a solo
489
515
  run). `tasks` are its fix tasks (tasks with a `sweep.json`), `findings` how many findings they took
@@ -536,6 +562,15 @@ Every RunSummary field, plus:
536
562
  "approach": null,
537
563
  "retry_findings": "...",
538
564
  "needs_input": "the question in tasks/<id>/needs_input.md, or null",
565
+ "infra": {"cause": "capacity", "stage": "dwarf", "harness": "claude", "model": "opus", "reset_at": 1760630000.0,
566
+ "retry_after": 600.0, "detail": "the model is overloaded", "needs_you": false, "hint": null},
567
+ "lateral": [{"at": 1760620500.0, "attempt": 1, "role": "dwarf", "from": "luna", "to": "sol", "cause": "capacity"}],
568
+ "ledger": [{"at": 1760620500.0, "attempt": 1, "review": "final-review-1760620500-4242", "verdict": "FAIL", "gate": "P2",
569
+ "worst": "P1", "confirmed": 2, "new": 1, "carried": 0, "diff_bytes": 4096, "delta_bytes": null}],
570
+ "decision": {"reasons": ["converging", "cap"], "text": "the markdown in tasks/<id>/decision.md, after its first line"},
571
+ "decisions": [{"at": 1760621000.0, "attempt": 2, "choice": "retry=3", "reason": "the fix is close"}],
572
+ "attempts_total": 2,
573
+ "attempt_cap": 9,
539
574
  "qa_tail": "last 4000 chars of qa.last",
540
575
  "dwarf_tail": "last 4000 chars of dwarf.last",
541
576
  "executions": [Execution, ...],
@@ -593,6 +628,28 @@ Every RunSummary field, plus:
593
628
  malformed (malformed is warned).
594
629
  - `needs_input`: the text of `tasks/<id>/needs_input.md`, capped like `prompt`, or `null` when the file is
595
630
  missing. The question a task stopped `NEEDS_INPUT` for; the export leaves it out unless texts are chosen.
631
+ - `infra`: for an `INFRA` task, the stop record in `tasks/<id>/infra.txt`: `cause` (its `class=`, as written),
632
+ `stage`, `harness`, `model`, `reset_at` (an epoch), `retry_after` (seconds) and `detail` (capped at 400
633
+ characters; the export leaves it out unless texts are chosen). A missing value is `null`, and a missing
634
+ file gives all of them `null`. `needs_you` (a boolean) and `hint` (or `null`) are forge's own answer
635
+ (`forge_infra.stop_of`): the scheduler's pause that names the task, live (`infra.paused`) or the one the run
636
+ ended with (`infra.last`), else what the cause asks for when no peer can take the work. `null` for every
637
+ other status.
638
+ - `lateral`: the rows of `tasks/<id>/lateral.tsv`, as `escalations` are read (a row with fewer than six columns
639
+ or a bad epoch or attempt is warned and skipped); `[]` without the file.
640
+ - `ledger`: the rows of `tasks/<id>/ledger.tsv`, the newest 50 (the list is in `truncated` when rows were cut).
641
+ `gate`, `worst` and `delta_bytes` read `-` as `null`; the counts and `diff_bytes` are integers; a row with a
642
+ bad number is warned and skipped. `[]` without the file.
643
+ - `decision`: for a `NEEDS_DECISION` task, `{reasons, text}`: `reasons` from the first line of
644
+ `tasks/<id>/decision.md` (`[]` when it has none, and that is warned), `text` the rest of the file, capped
645
+ like `needs_input` (`null` when the file is missing). `null` for every other status. Its `text` is blanked
646
+ by the export unless texts are chosen; `reasons` stay.
647
+ - `decisions`: the rows of `tasks/<id>/decisions.tsv` as `{at, attempt, choice, reason}`, `reason` `null` when
648
+ empty; `[]` without the file. A human's `retry=N` grants N more attempts (see `attempt_cap`).
649
+ - `attempts_total`: the number of `attempts.tsv` rows whose status is not `INFRA`: an infrastructure stop
650
+ spends no attempt. `attempt` is still the highest attempt number.
651
+ - `attempt_cap`: the attempt cap of the task: the plan's `max_attempts` (`8` without the file, `null` when it
652
+ is `0`, no cap) plus the N of each `retry=N` decision; `null` when there is no cap. Solo runs have `null`.
596
653
  - `known_issues`: whether `known_issues.md` is a non-empty file.
597
654
  - `now`: `null` unless the task is `RUNNING`. Then where it is: the newest running non-shadow `dwarf`
598
655
  or `qa` execution (`role`, `execution`, `attempt`, `phase`, `phase_started`, `started`), else the
@@ -607,7 +664,8 @@ Every RunSummary field, plus:
607
664
  not a scheduler runs); else, while `scheduler.live` is true, for a `PENDING` or `INFRA` task:
608
665
  `infra` (a pause in `scheduler.pauses` holds it: scope `all`, or its id in `tasks`; the pause's
609
666
  keys plus `kind`), then for a `PENDING` task `deps` (`on`: its deps not merged, `stopped`: those
610
- in a stopped status such as `FAIL`), `stopping` (`mode`), `drained`, `overlap` (`on`: running
667
+ in a stopped status such as `FAIL`; a dep at `NEEDS_INPUT` or `NEEDS_DECISION` is in `on` only, as the user
668
+ holds it and the retry policy did not stop it), `stopping` (`mode`), `drained`, `overlap` (`on`: running
611
669
  tasks whose files overlap its own, as forge-schedule.py tells overlap), `slot` (`running`,
612
670
  `max_parallel`: the run is at its capacity) or `next` (nothing holds it).
613
671
  - `sweep`: `null` unless the task is a finding sweep's fix task (it has a `sweep.json`). Then `file`
@@ -626,7 +684,9 @@ from the run dir's `attempts.tsv`. `status` is the solo status; `attempt` is the
626
684
  in `attempts.tsv`, or `null`. `escalations`, `route` and `shadow` are empty. `verdict` and
627
685
  `qa_tail` come from `qa.last`, and `prompt` comes from `prompt.md`. `deps` and `files` are
628
686
  `[]`; `difficulty`, `accepted_by`, `approach`, `retry_findings` and `needs_input` are `null`; `accepted` is
629
- false; `accepted_attempt` and `accepted_over` are `null`; `explored` is false; `waiting` and `sweep` are `null`, `swept` is `[]`. `request` on
687
+ false; `accepted_attempt` and `accepted_over` are `null`; `explored` is false; `waiting` and `sweep` are `null`, `swept` is `[]`.
688
+ `infra` and `decision` are `null`, `lateral`, `ledger` and `decisions` are `[]`, `attempt_cap` is `null`, and `attempts_total`
689
+ counts the run dir's `attempts.tsv` rows that are not `INFRA`. `request` on
630
690
  the detail is `request.md`.
631
691
 
632
692
  ## Execution
@@ -1045,7 +1105,8 @@ lines follow, a line was cut, or reaching them took more than 64 MB of reading.
1045
1105
 
1046
1106
  ```json
1047
1107
  {"generated": 1760621412.5, "runs": 12, "truncated": false,
1048
- "tasks": [{"run": "3f9a0c1d2e4b", "task": "reader", "kind": "plan", "repo": "/x/y", "difficulty": "high",
1108
+ "tasks": [{"run": "3f9a0c1d2e4b", "task": "reader", "kind": "plan", "repo": "/x/y", "repo_root": "/x/y",
1109
+ "difficulty": "high",
1049
1110
  "created": 1760619000.0, "explored": true, "propensity": 0.125, "final_status": "MERGED",
1050
1111
  "accepted": true,
1051
1112
  "attempts": [{"n": 1, "alias": "luna", "spec": "luna", "source": "execution", "outcome": "fail",
@@ -1053,12 +1114,14 @@ lines follow, a line was cut, or reaching them took more than 64 MB of reading.
1053
1114
  "tokens": {"input": 120000, "cached": 90000, "output": 8000}, "timed_out": false}],
1054
1115
  "escalations": [{"n": 1, "from": "luna", "to": "sol:xhigh"}]}],
1055
1116
  "reviews": [{"run": "3f9a0c1d2e4b", "task": "reader", "n": 1, "kind": "primary", "alias": "opus", "spec": "opus",
1117
+ "repo_root": "/x/y",
1056
1118
  "verdict": "FAIL", "findings": FindingsSummary, "duration_s": 270.0, "tokens": {...},
1057
1119
  "agreement": null, "primary_alias": null}],
1058
1120
  "warnings": ["3f9a0c1d2e4b: tasks/x/attempts.tsv line 2: invalid attempt"]}
1059
1121
  ```
1060
1122
 
1061
- - `tasks[]`: one per task (`solo` for a solo run). `explored` as Task's; `propensity` that of
1123
+ - `tasks[]`: one per task (`solo` for a solo run). `repo` is the run's `repo` text and `repo_root` its
1124
+ grouping key, both as in RunSummary (the same for every row of a run). `explored` as Task's; `propensity` that of
1062
1125
  the newest `route.jsonl` decision, else `null`; `final_status` the task (or solo) status;
1063
1126
  `accepted` whether `accepted.by` is non-empty (`false` for a solo run). `escalations` is
1064
1127
  `escalations.tsv` as it is (`n` its attempt column, `from`/`to` specs).
@@ -1080,9 +1143,10 @@ lines follow, a line was cut, or reaching them took more than 64 MB of reading.
1080
1143
  `shadow.status` is `done` (`alias`/`spec` its execution's model, else `shadow.json`'s spec;
1081
1144
  `agreement` and `primary_alias` against the primary review of its attempt); every finished
1082
1145
  final review (`kind` `final`, `task` and `n` `null`, `verdict` `PASS`/`FAIL` else `null`,
1083
- timing from its newest execution).
1146
+ timing from its newest execution). Every review row also has `repo_root`, the run's (reviews have no
1147
+ `repo` of their own).
1084
1148
  - Per run the facts are kept, keyed by its realpath, until its RunSummary's `updated`,
1085
- `task_count`, `counts` or `final_review` changes (4,096 runs); a run with a `RUNNING` task is
1149
+ `task_count`, `counts` or `final_review`, or its `repo_root`, changes (4,096 runs); a run with a `RUNNING` task is
1086
1150
  read again after 120 s. One computation runs at a time. Past 50,000 task rows the next run
1087
1151
  is left out and `truncated` is true. `warnings` (first 500) are prefixed by the run key.
1088
1152
 
@@ -1182,7 +1246,7 @@ difficulty paths deps model` each), `decomposition_history` (its newest 20, each
1182
1246
  (under their tail paths; line ranges are not stored, so the page shows the tail).
1183
1247
  - `texts=0` (the default) nulls these keys wherever they hold a string, list or object: `prompt
1184
1248
  last request log_tail dwarf_tail qa_tail qa_last qa_input tasks_summary known_issues texts text
1185
- planning_last approach retry_findings needs_input dwarf_input error last_line message excerpt tail lines call split`,
1249
+ planning_last approach retry_findings needs_input dwarf_input error last_line message excerpt tail lines call split detail`,
1186
1250
  and stores no diff, no transcript, no checks and no environment problems (a command is a text). A finding keeps its `summary`, a failing test its `name`.
1187
1251
  - `paths=0` (the default) makes every string that is a whole absolute path (but `/api/…`, `url`s
1188
1252
  and `command`s) its last component, and replaces the run dir, the repo and the home dir inside other
@@ -1386,8 +1450,11 @@ Reviewers table's Did not hold column and nothing else. Timeout 60 s.
1386
1450
 
1387
1451
  ### `GET /api/config?run=<key>` and `POST /api/config`
1388
1452
 
1389
- The repository is the run's own `repo` file (first line, an existing absolute directory; else
1390
- `409`), never a client field. `GET` runs `config show --repo <repo> --json` and answers with its
1453
+ The repository is the run's `repo_root` (see RunSummary) when that is an existing absolute directory,
1454
+ else the run's own `repo` file (first line, an existing absolute directory; else `409`), never a client
1455
+ field. The settings resolve against the root: every worktree of a repository shares its committed
1456
+ `.forge/` config, so the run of a removed worktree reads and writes the main checkout. A run whose root
1457
+ is unknown and whose `repo` is gone is still `409`. `GET` runs `config show --repo <repo> --json` and answers with its
1391
1458
  object. The `decide` block is the `forge decide status --json` object for that repo, plus `ready`
1392
1459
  on each gate (`true` when the gate is `shadow` or `on`, nothing skips it, and its provider is
1393
1460
  local or has a key on file), plus two fields from `forge decide status --json`: `forced` (bool: the
@@ -1427,7 +1494,8 @@ stage's own background and accent are `--stage-bg` and `--stage-accent` on `.sta
1427
1494
 
1428
1495
  Suggested meaning: merged and pass green, running blue, pending grey, fail, error and conflict
1429
1496
  red, infra and timeout orange, blocked, interrupted, invalidated, unknown and nochanges muted
1430
- purple.
1497
+ purple. `NEEDS_DECISION` takes the same waiting colour as `NEEDS_INPUT` (`--lamp-wait`, the
1498
+ `st-needs_input` class in `style.css`): a task that waits for the user is neither done nor failed.
1431
1499
 
1432
1500
  ## The graph (`forge_ui/static/graph.js`)
1433
1501
 
@@ -490,6 +490,12 @@ def _delete(ctx):
490
490
  return ctx.locked(work)
491
491
 
492
492
 
493
+ def _directory(value):
494
+ """`value` when it is an absolute existing directory with no control characters, else None."""
495
+ ok = isinstance(value, str) and os.path.isabs(value) and _no_control_chars(value) and os.path.isdir(value)
496
+ return value if ok else None
497
+
498
+
493
499
  def _repo_of(path):
494
500
  """The repository the run's own `repo` file names, or None."""
495
501
  try:
@@ -497,17 +503,19 @@ def _repo_of(path):
497
503
  line = handle.readline().strip()
498
504
  except (OSError, UnicodeDecodeError):
499
505
  return None
500
- return line if line and os.path.isabs(line) and _no_control_chars(line) and os.path.isdir(line) else None
506
+ return _directory(line)
501
507
 
502
508
 
503
509
  def _config_run(ctx, key):
504
- """(repo, error answer) for the run key a config request names."""
510
+ """(repo, error answer) for the run key a config request names. The repository is the run's root
511
+ (every worktree of one repository shares its .forge/ config), else the directory its `repo` names."""
505
512
  if not isinstance(key, str) or not re.fullmatch(r'[0-9a-f]{12}', key):
506
513
  return None, _invalid('run must be a 12-hex run key')
507
514
  found = ctx.server.catalog.locate(key)
508
515
  if not found:
509
516
  return None, (404, {'error': 'not found'})
510
- repo = _repo_of(found[0])
517
+ identity = ctx.server.catalog.identity(key)
518
+ repo = _directory(identity and identity['root']) or _repo_of(found[0])
511
519
  if repo is None:
512
520
  return None, (409, {'error': 'refused', 'detail': 'the run names no repository directory'})
513
521
  return repo, None