@giamme/forge 0.17.0 → 0.19.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.
- package/CHANGELOG.md +57 -0
- package/README.md +1 -0
- package/SKILL.md +32 -5
- package/VERSION +1 -1
- package/docs/artifacts.md +33 -1
- package/docs/commands.md +147 -16
- package/docs/dataset.md +5 -0
- package/docs/decomposed-runs.md +122 -1
- package/docs/development.md +2 -1
- package/docs/forge-ui.md +98 -8
- package/docs/memory.md +27 -4
- package/docs/models.md +8 -0
- package/docs/reviews.md +122 -0
- package/docs/safety.md +8 -0
- package/forge +44 -4
- package/package.json +2 -1
- package/references/dataset.md +39 -1
- package/references/decompose.md +737 -16
- package/references/harnesses.md +18 -3
- package/references/planning.md +43 -14
- package/references/solo.md +2 -1
- package/references/ui.md +56 -6
- package/registry.tsv +8 -3
- package/scripts/forge-artifact.sh +14 -0
- package/scripts/forge-brief.py +217 -0
- package/scripts/forge-compare.py +13 -2
- package/scripts/forge-config.py +176 -9
- package/scripts/forge-contract.py +246 -28
- package/scripts/forge-control.py +200 -15
- package/scripts/forge-dispatch.sh +48 -15
- package/scripts/forge-du.py +167 -0
- package/scripts/forge-group.py +496 -0
- package/scripts/forge-groups.py +89 -0
- package/scripts/forge-handoff.py +1128 -0
- package/scripts/forge-lib-adopt.sh +1 -0
- package/scripts/forge-lib-group.sh +641 -0
- package/scripts/forge-lib-plans.sh +343 -4
- package/scripts/forge-lib-review.sh +29 -1
- package/scripts/forge-lib-task.sh +197 -4
- package/scripts/forge-memory.sh +245 -3
- package/scripts/forge-metrics.sh +7 -3
- package/scripts/forge-parallel-options.sh +4 -0
- package/scripts/forge-parallel.sh +1216 -41
- package/scripts/forge-planner.py +104 -8
- package/scripts/forge-prompt.py +120 -0
- package/scripts/forge-retro.py +115 -0
- package/scripts/forge-route.py +190 -12
- package/scripts/forge-runs-compact.py +443 -0
- package/scripts/forge-runs-rm.py +2 -0
- package/scripts/forge-runs.py +27 -8
- package/scripts/forge-schedule.py +633 -49
- package/scripts/forge-shadow.py +7 -1
- package/scripts/forge-solo.sh +4 -0
- package/scripts/forge-summarize.py +698 -0
- package/scripts/forge-ui-options.sh +10 -0
- package/scripts/forge-worktrees.py +243 -0
- package/scripts/forge_brief/__init__.py +831 -0
- package/scripts/forge_brief/answers.py +506 -0
- package/scripts/forge_brief/proposals.py +1630 -0
- package/scripts/forge_dataset/__init__.py +10 -0
- package/scripts/forge_dataset/efforts.py +4 -3
- package/scripts/forge_dataset/export.py +36 -10
- package/scripts/forge_dataset/facts.py +8 -4
- package/scripts/forge_dataset/forecast.py +8 -18
- package/scripts/forge_dataset/harvest.py +241 -12
- package/scripts/forge_dataset/history.py +13 -6
- package/scripts/forge_dataset/importer.py +65 -1
- package/scripts/forge_dataset/names.py +66 -0
- package/scripts/forge_dataset/reviewers.py +5 -2
- package/scripts/forge_dataset/risk.py +6 -3
- package/scripts/forge_dataset/routing.py +6 -1
- package/scripts/forge_decide/__init__.py +11 -1
- package/scripts/forge_groups/__init__.py +308 -0
- package/scripts/forge_groups/attribute.py +289 -0
- package/scripts/forge_groups/review.py +286 -0
- package/scripts/forge_locations.py +366 -0
- package/scripts/forge_owner.py +152 -0
- package/scripts/forge_registry.py +19 -0
- package/scripts/forge_retro/__init__.py +417 -0
- package/scripts/forge_retro/issues.py +1193 -0
- package/scripts/forge_retro/report.py +671 -0
- package/scripts/forge_side/__init__.py +482 -0
- package/scripts/forge_storage.py +515 -0
- package/ui/README.md +68 -8
- package/ui/docs/api.md +375 -31
- package/ui/forge_ui/control.py +451 -11
- package/ui/forge_ui/executions.py +8 -1
- package/ui/forge_ui/export.py +53 -7
- package/ui/forge_ui/groups.py +264 -0
- package/ui/forge_ui/links.py +337 -0
- package/ui/forge_ui/models.py +125 -10
- package/ui/forge_ui/projects.py +4 -1
- package/ui/forge_ui/reader.py +919 -45
- package/ui/forge_ui/server.py +4 -0
- package/ui/forge_ui/static/app.js +173 -11
- package/ui/forge_ui/static/briefview.js +605 -0
- package/ui/forge_ui/static/checksview.js +6 -2
- package/ui/forge_ui/static/controls.js +5 -0
- package/ui/forge_ui/static/diffview.js +86 -1
- package/ui/forge_ui/static/groupsview.js +332 -0
- package/ui/forge_ui/static/index.html +4 -0
- package/ui/forge_ui/static/panel.js +394 -8
- package/ui/forge_ui/static/projectsview.js +189 -10
- package/ui/forge_ui/static/runmodel.js +27 -4
- package/ui/forge_ui/static/storageview.js +352 -0
- package/ui/forge_ui/static/style.css +176 -6
- package/ui/forge_ui/static/worktreesview.js +235 -14
- package/ui/forge_ui/storage.py +150 -0
- package/ui/forge_ui/transcripts.py +35 -10
- package/ui/forge_ui/worktrees.py +154 -13
package/scripts/forge-planner.py
CHANGED
|
@@ -9,8 +9,9 @@ gate and the one-task plan. Standard library only; no shell wiring.
|
|
|
9
9
|
forge-planner.py parse --plan P --reply FILE
|
|
10
10
|
Turns the planner's reply into P/tasks.tsv, P/tasks/<id>/prompt.md and, when it is not
|
|
11
11
|
empty, P/tasks/<id>/approach.md; a task's `risk` (#122) goes to P/tasks/<id>/risk, and a
|
|
12
|
-
missing or unknown one writes nothing.
|
|
13
|
-
|
|
12
|
+
missing or unknown one writes nothing. A reply that includes `groups` also writes
|
|
13
|
+
P/groups.tsv (review always `task`, qa `-`). It never guesses or repairs: a reply that breaks
|
|
14
|
+
one rule writes nothing but P/planner.refused (the first reason and the reply's path), prints
|
|
14
15
|
both and exits 4. P/request.md must hold the user's request (exit 2 when it is missing);
|
|
15
16
|
it is attached to every task prompt so no requirement is lost.
|
|
16
17
|
|
|
@@ -32,8 +33,10 @@ import os
|
|
|
32
33
|
from pathlib import Path
|
|
33
34
|
import re
|
|
34
35
|
import sys
|
|
36
|
+
import tempfile
|
|
35
37
|
|
|
36
38
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
39
|
+
import forge_groups # noqa: E402
|
|
37
40
|
from forge_jev.coverage import split_requirements # noqa: E402 (read-only use)
|
|
38
41
|
|
|
39
42
|
# The gate: a request at or under both limits skips the planner. On #86's 16 benchmark plans
|
|
@@ -47,6 +50,10 @@ TASK_KEYS = ('id', 'deps', 'difficulty', 'files', 'title', 'approach', 'prompt')
|
|
|
47
50
|
# #122: a task's risk, recorded in shadow beside its difficulty. Optional, and the one key that never refuses a
|
|
48
51
|
# reply: a missing or unknown value records nothing, because a label nothing routes on must not cost a plan.
|
|
49
52
|
OPTIONAL_KEYS = ('risk',)
|
|
53
|
+
# #136: groups are optional on the reply. A missing key writes no groups.tsv. A present one is
|
|
54
|
+
# checked strictly; the planner never sets review=group (that is plan --group-review, or an edit).
|
|
55
|
+
GROUP_KEYS = ('id', 'title', 'goal', 'members')
|
|
56
|
+
MAX_GROUP_TEXT = 200
|
|
50
57
|
DIFFICULTIES = ('low', 'medium', 'high')
|
|
51
58
|
RISKS = ('low', 'medium', 'high')
|
|
52
59
|
LEVELS = DIFFICULTIES
|
|
@@ -85,6 +92,11 @@ EXAMPLE = """\
|
|
|
85
92
|
"title": "Parse the new config section",
|
|
86
93
|
"approach": "Add parse_section() beside load(); keep load()'s signature.",
|
|
87
94
|
"prompt": "Add the `limits` section to the config parser in src/config.py ...\\n\\n## Acceptance criteria\\n\\n- `limits` is read into Config.limits, with the defaults the request names.\\n- python3 -m unittest tests.test_config passes."}
|
|
95
|
+
],
|
|
96
|
+
"groups": [
|
|
97
|
+
{"id": "config-limits", "title": "Config limits",
|
|
98
|
+
"goal": "The limits section is read into Config with the defaults the request names.",
|
|
99
|
+
"members": ["parse-config"]}
|
|
88
100
|
]}
|
|
89
101
|
```"""
|
|
90
102
|
|
|
@@ -174,6 +186,10 @@ def build_prompt(request: str, level: str | None) -> str:
|
|
|
174
186
|
'**Keep each task** under about 7000 characters of prompt and 9 files. A smaller task with '
|
|
175
187
|
'stated acceptance criteria passes its first review far more often.',
|
|
176
188
|
f'At most {MAX_TASKS} tasks.',
|
|
189
|
+
'**Groups.** Tasks that together deliver one goal, and that the user will think of as one '
|
|
190
|
+
'step, form one group (usually one per wave of the plan\'s dependency order). Each group '
|
|
191
|
+
'has a short title and a goal sentence that says what is true once its tasks are done. A '
|
|
192
|
+
'group may have one task. A task may be left out of every group.',
|
|
177
193
|
]
|
|
178
194
|
numbered = '\n'.join(f'{n}. {rule}' for n, rule in enumerate(rules, 1))
|
|
179
195
|
return f"""\
|
|
@@ -195,8 +211,8 @@ The request follows verbatim between the markers. It is the whole requirement.
|
|
|
195
211
|
# Reply format
|
|
196
212
|
|
|
197
213
|
Reply with exactly one fenced block whose opening line is ```forge-plan and whose body is one
|
|
198
|
-
JSON object with
|
|
199
|
-
these keys and no others:
|
|
214
|
+
JSON object with the key `tasks` and, optionally, `groups`. `tasks` is a list of 1 to {MAX_TASKS}
|
|
215
|
+
objects, each with exactly these keys and no others:
|
|
200
216
|
|
|
201
217
|
- `id`: lowercase slug matching `^[a-z0-9][a-z0-9-]{{0,39}}$`, unique in the plan;
|
|
202
218
|
- `deps`: list of ids of tasks that must land first (`[]` for none), no cycles;
|
|
@@ -208,6 +224,15 @@ these keys and no others:
|
|
|
208
224
|
- `approach`: a few lines on the intended shape (a string; `""` for none);
|
|
209
225
|
- `prompt`: the task's full instruction, ending with a `## Acceptance criteria` section.
|
|
210
226
|
|
|
227
|
+
`groups`, when present, is a list of objects with exactly these keys and no others. Omit the key
|
|
228
|
+
to return no groups:
|
|
229
|
+
|
|
230
|
+
- `id`: the same slug as a task id, unique in the plan, and not a task id;
|
|
231
|
+
- `title`: one short line, at most 200 characters;
|
|
232
|
+
- `goal`: one line, at most 200 characters, what is true once the group's tasks are done;
|
|
233
|
+
- `members`: ids of tasks from this reply, in order. A group may have one task. A task is in at
|
|
234
|
+
most one group, and a task may be left out of every group.
|
|
235
|
+
|
|
211
236
|
Put no other `forge-plan` block in the reply. Text outside the block is ignored. Anything that
|
|
212
237
|
breaks these rules makes the whole reply refused; nothing is repaired. A valid reply:
|
|
213
238
|
|
|
@@ -339,6 +364,73 @@ def check_task(task, index: int, seen: set) -> dict:
|
|
|
339
364
|
return dict(task, risk=risk if isinstance(risk, str) and risk in RISKS else None)
|
|
340
365
|
|
|
341
366
|
|
|
367
|
+
def check_group_line(value, where: str):
|
|
368
|
+
"""A group's title or goal: one non-empty line, at most MAX_GROUP_TEXT characters."""
|
|
369
|
+
if not isinstance(value, str):
|
|
370
|
+
raise Refusal(f'{where} is not a string')
|
|
371
|
+
# Line separators first, so a tab or other control is not reported as a second line.
|
|
372
|
+
# Not a raw string: \n, \x85 and \u2028 have to be the characters, not the escape text.
|
|
373
|
+
if re.search('[\n\r\x85\u2028\u2029]', value):
|
|
374
|
+
raise Refusal(f'{where} is not one line')
|
|
375
|
+
if LINE_BREAKS_RE.search(value):
|
|
376
|
+
raise Refusal(f'{where} holds a tab or a control character')
|
|
377
|
+
if not value.strip():
|
|
378
|
+
raise Refusal(f'{where} is empty')
|
|
379
|
+
if len(value) > MAX_GROUP_TEXT:
|
|
380
|
+
raise Refusal(f'{where} is longer than {MAX_GROUP_TEXT} characters')
|
|
381
|
+
check_text(value, where)
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def check_groups(raw, task_ids: set) -> list:
|
|
385
|
+
"""The reply's groups, each forced to review=task and qa=-. Order is the reply's."""
|
|
386
|
+
if not isinstance(raw, list):
|
|
387
|
+
raise Refusal('groups is not a list')
|
|
388
|
+
seen: set = set()
|
|
389
|
+
owner: dict = {}
|
|
390
|
+
groups = []
|
|
391
|
+
for index, group in enumerate(raw):
|
|
392
|
+
where = f'group {index + 1}'
|
|
393
|
+
check_keys(group, GROUP_KEYS, where)
|
|
394
|
+
gid = group['id']
|
|
395
|
+
if not isinstance(gid, str) or not ID_RE.fullmatch(gid):
|
|
396
|
+
raise Refusal(f'{where}: id {gid!r} does not match ^[a-z0-9][a-z0-9-]{{0,39}}$')
|
|
397
|
+
where = f'group {gid}'
|
|
398
|
+
if gid in seen:
|
|
399
|
+
raise Refusal(f'{where}: duplicate id')
|
|
400
|
+
seen.add(gid)
|
|
401
|
+
if gid in task_ids:
|
|
402
|
+
raise Refusal(f'{where}: the id is also a task id')
|
|
403
|
+
check_group_line(group['title'], f'{where}: title')
|
|
404
|
+
check_group_line(group['goal'], f'{where}: goal')
|
|
405
|
+
members = group['members']
|
|
406
|
+
if not isinstance(members, list) or not all(isinstance(m, str) for m in members):
|
|
407
|
+
raise Refusal(f'{where}: members is not a list of task ids')
|
|
408
|
+
if not members:
|
|
409
|
+
raise Refusal(f'{where}: members is empty')
|
|
410
|
+
for member in members:
|
|
411
|
+
if member not in task_ids:
|
|
412
|
+
raise Refusal(f'{where}: member {member!r} is not a task of the reply')
|
|
413
|
+
if member in owner:
|
|
414
|
+
prior = owner[member]
|
|
415
|
+
if prior == gid:
|
|
416
|
+
raise Refusal(f'{where}: task {member} is listed twice')
|
|
417
|
+
raise Refusal(f'{where}: task {member} is in two groups ({prior} and {gid})')
|
|
418
|
+
owner[member] = gid
|
|
419
|
+
groups.append(forge_groups.Group(gid, 'task', '-', tuple(members), group['title'], group['goal']))
|
|
420
|
+
return groups
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
def groups_tsv_bytes(groups) -> bytes:
|
|
424
|
+
"""Bytes `forge_groups.write` emits, held until the other outputs are written too.
|
|
425
|
+
|
|
426
|
+
A refusal must write none of the plan. write() would touch the disk now, so the bytes are
|
|
427
|
+
captured and joined to the outputs list cmd_parse already flushes in one pass.
|
|
428
|
+
"""
|
|
429
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
430
|
+
forge_groups.write(tmp, groups)
|
|
431
|
+
return (Path(tmp) / 'groups.tsv').read_bytes()
|
|
432
|
+
|
|
433
|
+
|
|
342
434
|
def check_graph(tasks: list):
|
|
343
435
|
ids = {t['id'] for t in tasks}
|
|
344
436
|
for t in tasks:
|
|
@@ -363,7 +455,8 @@ def check_graph(tasks: list):
|
|
|
363
455
|
visit(t['id'], [t['id']])
|
|
364
456
|
|
|
365
457
|
|
|
366
|
-
def parse_reply(reply: str)
|
|
458
|
+
def parse_reply(reply: str):
|
|
459
|
+
"""(tasks, groups). groups is None when the reply has no groups key, else a list (maybe empty)."""
|
|
367
460
|
body = extract_block(reply)
|
|
368
461
|
try:
|
|
369
462
|
data = json.loads(body, object_pairs_hook=no_duplicate_keys)
|
|
@@ -371,7 +464,7 @@ def parse_reply(reply: str) -> list:
|
|
|
371
464
|
# JSONDecodeError is a ValueError; so is Python's limit on integer digits. Nesting deeper
|
|
372
465
|
# than the interpreter allows raises RecursionError.
|
|
373
466
|
raise Refusal(f'the forge-plan body is not valid JSON: {type(err).__name__}: {str(err)[:200]}')
|
|
374
|
-
check_keys(data, ('tasks',), 'the forge-plan body')
|
|
467
|
+
check_keys(data, ('tasks',), 'the forge-plan body', ('groups',))
|
|
375
468
|
tasks = data['tasks']
|
|
376
469
|
if not isinstance(tasks, list) or not 1 <= len(tasks) <= MAX_TASKS:
|
|
377
470
|
count = f' ({len(tasks)})' if isinstance(tasks, list) else ''
|
|
@@ -379,7 +472,8 @@ def parse_reply(reply: str) -> list:
|
|
|
379
472
|
seen: set = set()
|
|
380
473
|
checked = [check_task(t, i, seen) for i, t in enumerate(tasks)]
|
|
381
474
|
check_graph(checked)
|
|
382
|
-
|
|
475
|
+
groups = check_groups(data['groups'], seen) if 'groups' in data else None
|
|
476
|
+
return checked, groups
|
|
383
477
|
|
|
384
478
|
|
|
385
479
|
def cmd_parse(args) -> int:
|
|
@@ -390,7 +484,7 @@ def cmd_parse(args) -> int:
|
|
|
390
484
|
request = read_text(request_path, 'request')
|
|
391
485
|
reply = read_text(args.reply, 'reply')
|
|
392
486
|
try:
|
|
393
|
-
tasks = parse_reply(reply)
|
|
487
|
+
tasks, groups = parse_reply(reply)
|
|
394
488
|
except Refusal as err:
|
|
395
489
|
# A key or path may hold a lone surrogate; escape it so the reason can be written and printed.
|
|
396
490
|
reason = str(err).encode('utf-8', 'backslashreplace').decode('utf-8')
|
|
@@ -412,6 +506,8 @@ def cmd_parse(args) -> int:
|
|
|
412
506
|
outputs.append((folder / 'approach.md', t['approach'].encode('utf-8') if t['approach'].strip() else None))
|
|
413
507
|
outputs.append((folder / 'risk', (t['risk'] + '\n').encode('utf-8') if t['risk'] else None))
|
|
414
508
|
outputs.append((plan / 'tasks.tsv', ('\n'.join(rows) + '\n').encode('utf-8')))
|
|
509
|
+
if groups is not None:
|
|
510
|
+
outputs.append((plan / 'groups.tsv', groups_tsv_bytes(groups)))
|
|
415
511
|
for path, data in outputs:
|
|
416
512
|
if data is None:
|
|
417
513
|
path.unlink(missing_ok=True) # an empty approach must not keep an older one alive
|
package/scripts/forge-prompt.py
CHANGED
|
@@ -3,10 +3,15 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import argparse
|
|
6
|
+
import json
|
|
6
7
|
from pathlib import Path
|
|
7
8
|
|
|
8
9
|
DIFF_INLINE_CAP = 100 * 1024
|
|
9
10
|
REPLY_CAP = 8 * 1024
|
|
11
|
+
# A brief answer, and each brief section, stay small enough to leave the task itself
|
|
12
|
+
# in the prompt. The cut matches the reply cap: keep the leading bytes, then a marker.
|
|
13
|
+
ANSWER_CAP = 4 * 1024
|
|
14
|
+
BRIEF_CHUNK_CAP = 16 * 1024
|
|
10
15
|
|
|
11
16
|
# What a reviewer is asked to do with the previous round's report. The labelled-line rule
|
|
12
17
|
# matters: the severity gate, `forge issues` and forge-ui count every `- [Px][...]` line as open.
|
|
@@ -72,6 +77,119 @@ def qa_round(findings: str, diff: str | None, span: str | None, stat: str | None
|
|
|
72
77
|
return '\n\n'.join(parts) + '\n'
|
|
73
78
|
|
|
74
79
|
|
|
80
|
+
# Brief is opt-in. `<plan>/brief` names the level and `<plan>/tasks/<id>/brief.json` holds
|
|
81
|
+
# the questions. Answers given before the task starts live in `brief.answers.json`.
|
|
82
|
+
# `brief.late.json` is written after the start and is never read here. No level file, no
|
|
83
|
+
# brief.json, or no questions: nothing is added, and the prompt stays byte-identical.
|
|
84
|
+
DECISIONS_TITLE = 'Decisions the user made'
|
|
85
|
+
OPEN_TITLE = 'Open questions: follow the stated default'
|
|
86
|
+
DECISIONS_NOTE = (
|
|
87
|
+
'Treat these as constraints that override anything in the requirements or approach '
|
|
88
|
+
'they contradict.'
|
|
89
|
+
)
|
|
90
|
+
DECISIONS_QA = (
|
|
91
|
+
"These are the user's own decisions, so following them is not a deviation and must "
|
|
92
|
+
'not be reported as a finding.'
|
|
93
|
+
)
|
|
94
|
+
OPEN_NOTE = (
|
|
95
|
+
'Follow the default for each question below, and say in the final message which '
|
|
96
|
+
'defaults were used.'
|
|
97
|
+
)
|
|
98
|
+
OPEN_QA = (
|
|
99
|
+
'These are the defaults the implementer was told to follow. The implementer was told '
|
|
100
|
+
'to say in the final message which defaults were used.'
|
|
101
|
+
)
|
|
102
|
+
OPEN_LEVELS = ('advisory', 'gated')
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def clip(text: str, limit: int, marker: str) -> str:
|
|
106
|
+
"""Keep the leading bytes. A cut keeps the marker, as a long reply does."""
|
|
107
|
+
raw = text.encode()
|
|
108
|
+
if len(raw) <= limit:
|
|
109
|
+
return text
|
|
110
|
+
return raw[:limit].decode(errors='ignore') + marker
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def load_json(path: Path):
|
|
114
|
+
if not path.is_file():
|
|
115
|
+
return None
|
|
116
|
+
try:
|
|
117
|
+
return json.loads(path.read_text(encoding='utf-8'))
|
|
118
|
+
except (OSError, UnicodeError, json.JSONDecodeError):
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def task_dir_of(requirements: str | None, approach: str | None) -> Path | None:
|
|
123
|
+
"""`<plan>/tasks/<id>`, from the prompt.md or approach.md path callers already pass.
|
|
124
|
+
|
|
125
|
+
A solo run and a fixture that is not that shape have no plan brief, so they get nothing.
|
|
126
|
+
"""
|
|
127
|
+
found = None
|
|
128
|
+
for path in (requirements, approach):
|
|
129
|
+
if not path:
|
|
130
|
+
continue
|
|
131
|
+
candidate = Path(path)
|
|
132
|
+
if candidate.name not in ('prompt.md', 'approach.md'):
|
|
133
|
+
continue
|
|
134
|
+
# candidate = <plan>/tasks/<id>/<file>
|
|
135
|
+
if candidate.parent.parent.name != 'tasks':
|
|
136
|
+
continue
|
|
137
|
+
if candidate.name == 'prompt.md':
|
|
138
|
+
return candidate.parent
|
|
139
|
+
found = candidate.parent
|
|
140
|
+
return found
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def brief_rows(questions: list, answers: dict) -> tuple[list[tuple[str, str]], list[tuple[str, str]]]:
|
|
144
|
+
decided, pending = [], []
|
|
145
|
+
for question in questions:
|
|
146
|
+
if not isinstance(question, dict):
|
|
147
|
+
continue
|
|
148
|
+
qid, text = question.get('id'), question.get('text')
|
|
149
|
+
if not isinstance(qid, str) or not qid or not isinstance(text, str) or not text.strip():
|
|
150
|
+
continue
|
|
151
|
+
entry = answers.get(qid)
|
|
152
|
+
answer = entry.get('text') if isinstance(entry, dict) else None
|
|
153
|
+
if isinstance(answer, str):
|
|
154
|
+
decided.append((text.strip(), clip(answer, ANSWER_CAP,
|
|
155
|
+
'\n[... the answer continues; cut here ...]')))
|
|
156
|
+
else:
|
|
157
|
+
default = question.get('default')
|
|
158
|
+
pending.append((text.strip(), default if isinstance(default, str) else ''))
|
|
159
|
+
return decided, pending
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def brief_section(title: str, note: str, rows: list[tuple[str, str]], label: str) -> str:
|
|
163
|
+
items = '\n\n'.join('- ' + text + '\n ' + label + ': ' + value for text, value in rows)
|
|
164
|
+
# Trailing newline matches the other sections, whose source files end with one.
|
|
165
|
+
body = '## ' + title + '\n' + note + '\n\n' + items + '\n'
|
|
166
|
+
return clip(body, BRIEF_CHUNK_CAP, '\n[... the brief continues; cut here ...]\n')
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def brief_chunks(requirements: str | None, approach: str | None, role: str) -> list[str]:
|
|
170
|
+
task = task_dir_of(requirements, approach)
|
|
171
|
+
if task is None:
|
|
172
|
+
return []
|
|
173
|
+
plan = task.parent.parent
|
|
174
|
+
if not (plan / 'brief').is_file() or not (task / 'brief.json').is_file():
|
|
175
|
+
return []
|
|
176
|
+
spec = load_json(task / 'brief.json')
|
|
177
|
+
questions = spec.get('questions') if isinstance(spec, dict) else None
|
|
178
|
+
if not isinstance(questions, list) or not questions:
|
|
179
|
+
return []
|
|
180
|
+
answers = load_json(task / 'brief.answers.json')
|
|
181
|
+
decided, pending = brief_rows(questions, answers if isinstance(answers, dict) else {})
|
|
182
|
+
chunks = []
|
|
183
|
+
if decided:
|
|
184
|
+
note = DECISIONS_NOTE + (' ' + DECISIONS_QA if role == 'qa' else '')
|
|
185
|
+
chunks.append(brief_section(DECISIONS_TITLE, note, decided, 'Answer'))
|
|
186
|
+
# strict has no open questions: run refuses to start until every one is answered.
|
|
187
|
+
if pending and read(str(plan / 'brief')).strip() in OPEN_LEVELS:
|
|
188
|
+
note = OPEN_QA if role == 'qa' else OPEN_NOTE
|
|
189
|
+
chunks.append(brief_section(OPEN_TITLE, note, pending, 'Default'))
|
|
190
|
+
return chunks
|
|
191
|
+
|
|
192
|
+
|
|
75
193
|
def context(
|
|
76
194
|
requirements: str, approach: str | None = None, capsule: str | None = None,
|
|
77
195
|
retry: str | None = None, goal: str | None = None, memories: tuple[str, ...] = (),
|
|
@@ -85,6 +203,8 @@ def context(
|
|
|
85
203
|
('Complete implementation requirements', requirements),
|
|
86
204
|
('Intended approach', approach),
|
|
87
205
|
(RETRY_HEADINGS[retry_source], retry)]:
|
|
206
|
+
if title == RETRY_HEADINGS[retry_source]:
|
|
207
|
+
chunks.extend(brief_chunks(requirements, approach, role))
|
|
88
208
|
data = read(path) if path and Path(path).is_file() else ''
|
|
89
209
|
if data:
|
|
90
210
|
if role == 'qa' and path == retry:
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Retro notes for one plan.
|
|
3
|
+
|
|
4
|
+
record PLAN --role ROLE --dir DISPATCH [--task ID] [--attempt N] [--inbox PATH]
|
|
5
|
+
Parse the dispatch's FORGE_RETRO lines (and, for a dwarf, its inbox), check them
|
|
6
|
+
against the log, and store them.
|
|
7
|
+
note PLAN --type T --fixable-by F --summary S [--command C --exit N --error E]
|
|
8
|
+
[--blocking] [--tried TEXT]
|
|
9
|
+
Record one orchestrator note. It is always claimed.
|
|
10
|
+
report PLAN [--json]
|
|
11
|
+
Write PLAN/retro.md from the stored notes and print its path. --json prints the
|
|
12
|
+
structure instead of the path.
|
|
13
|
+
issues PLAN [--json] [--choice rN=new|comment:N|skip ...] [--apply --approve HASH]
|
|
14
|
+
Draft one redacted issue per forge-group pattern for forge's own repository.
|
|
15
|
+
The dry run prints the text and posts nothing. --apply posts only when HASH is
|
|
16
|
+
the sha256 of those drafts and choices.
|
|
17
|
+
|
|
18
|
+
Exit codes: 0 stored, reported, drafted or posted, 2 usage, 3 PLAN is not a directory,
|
|
19
|
+
never-send, gh is missing or unauthenticated, or the approval hash does not match.
|
|
20
|
+
`record` and `note` print each stored note as one JSON line.
|
|
21
|
+
"""
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import argparse
|
|
25
|
+
import json
|
|
26
|
+
import sys
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
|
|
29
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
30
|
+
import forge_retro # noqa: E402
|
|
31
|
+
import forge_retro.issues as retro_issues # noqa: E402
|
|
32
|
+
import forge_retro.report as retro_report # noqa: E402
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _parser() -> argparse.ArgumentParser:
|
|
36
|
+
parser = argparse.ArgumentParser(
|
|
37
|
+
prog='forge retro',
|
|
38
|
+
description='Notes on what got in a run\'s way. Kept on this machine, never in a prompt.')
|
|
39
|
+
sub = parser.add_subparsers(dest='command', required=True)
|
|
40
|
+
record = sub.add_parser('record', help='parse a dispatch and store its retro notes')
|
|
41
|
+
record.add_argument('plan', help='the plan directory')
|
|
42
|
+
record.add_argument('--role', required=True, help='the dispatch role, e.g. dwarf or qa')
|
|
43
|
+
record.add_argument('--dir', required=True, dest='dispatch_dir',
|
|
44
|
+
help='the directory that holds <role>.last and <role>.log')
|
|
45
|
+
record.add_argument('--task', help='task id; also writes tasks/<id>/retro.json')
|
|
46
|
+
record.add_argument('--attempt', type=int, help='the attempt number')
|
|
47
|
+
record.add_argument('--inbox', help="the dwarf worktree's .forge/retro-inbox.jsonl")
|
|
48
|
+
note = sub.add_parser('note', help='record an orchestrator note (always claimed)')
|
|
49
|
+
note.add_argument('plan', help='the plan directory')
|
|
50
|
+
note.add_argument('--type', required=True, choices=forge_retro.TYPES)
|
|
51
|
+
note.add_argument('--fixable-by', required=True, dest='fixable_by', choices=forge_retro.FIXABLE)
|
|
52
|
+
note.add_argument('--summary', required=True)
|
|
53
|
+
note.add_argument('--command', dest='command_text', help='the command that failed')
|
|
54
|
+
note.add_argument('--exit', dest='exit_code', type=int, help='that command\'s exit code')
|
|
55
|
+
note.add_argument('--error', help='the error text, kept up to 2 KB')
|
|
56
|
+
note.add_argument('--blocking', action='store_true', help='the run could not finish without this')
|
|
57
|
+
note.add_argument('--tried', help='what was tried before giving up')
|
|
58
|
+
report = sub.add_parser('report', help='write retro.md from the stored notes')
|
|
59
|
+
report.add_argument('plan', help='the plan directory')
|
|
60
|
+
report.add_argument('--json', action='store_true', dest='as_json',
|
|
61
|
+
help='print the report structure instead of the path')
|
|
62
|
+
issues = sub.add_parser('issues', help='draft redacted issues for forge\'s own repository')
|
|
63
|
+
issues.add_argument('plan', help='the plan directory')
|
|
64
|
+
issues.add_argument('--json', action='store_true', dest='as_json',
|
|
65
|
+
help='print the drafts as JSON')
|
|
66
|
+
issues.add_argument('--choice', action='append', default=[],
|
|
67
|
+
help='rN=new, rN=comment:N or rN=skip; repeatable')
|
|
68
|
+
issues.add_argument('--apply', action='store_true',
|
|
69
|
+
help='post the chosen drafts; requires a matching --approve hash')
|
|
70
|
+
issues.add_argument('--approve', help='sha256 of the draft texts and choices to post')
|
|
71
|
+
return parser
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _emit(notes: list) -> None:
|
|
75
|
+
if not notes:
|
|
76
|
+
return
|
|
77
|
+
blob = ''.join(json.dumps(note, ensure_ascii=False, sort_keys=True) + '\n' for note in notes)
|
|
78
|
+
sys.stdout.buffer.write(blob.encode('utf-8'))
|
|
79
|
+
sys.stdout.buffer.flush()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _report(args) -> int:
|
|
83
|
+
document, path = retro_report.write(args.plan)
|
|
84
|
+
if args.as_json:
|
|
85
|
+
text = json.dumps(document, ensure_ascii=False, indent=2, sort_keys=True) + '\n'
|
|
86
|
+
else:
|
|
87
|
+
text = str(path) + '\n'
|
|
88
|
+
sys.stdout.write(text)
|
|
89
|
+
sys.stdout.flush()
|
|
90
|
+
return 0
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def main(argv=None) -> int:
|
|
94
|
+
args = _parser().parse_args(argv)
|
|
95
|
+
try:
|
|
96
|
+
if args.command == 'report':
|
|
97
|
+
return _report(args)
|
|
98
|
+
if args.command == 'issues':
|
|
99
|
+
return retro_issues.execute(args)
|
|
100
|
+
if args.command == 'record':
|
|
101
|
+
notes = forge_retro.record(args.plan, args.role, args.dispatch_dir, task=args.task,
|
|
102
|
+
attempt=args.attempt, inbox=args.inbox)
|
|
103
|
+
else:
|
|
104
|
+
notes = forge_retro.note(args.plan, type=args.type, fixable_by=args.fixable_by,
|
|
105
|
+
summary=args.summary, command=args.command_text, exit=args.exit_code,
|
|
106
|
+
error=args.error, blocking=args.blocking, tried=args.tried)
|
|
107
|
+
except FileNotFoundError as error:
|
|
108
|
+
sys.stderr.write('forge retro: not a plan dir: %s\n' % error)
|
|
109
|
+
return 3
|
|
110
|
+
_emit(notes)
|
|
111
|
+
return 0
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
if __name__ == '__main__':
|
|
115
|
+
sys.exit(main())
|