@giamme/forge 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/SKILL.md +16 -3
- package/VERSION +1 -1
- package/docs/artifacts.md +8 -0
- package/docs/commands.md +70 -6
- package/docs/dataset.md +5 -0
- package/docs/decomposed-runs.md +8 -0
- package/docs/forge-ui.md +23 -2
- package/docs/memory.md +2 -0
- package/docs/safety.md +8 -0
- package/forge +24 -1
- package/package.json +1 -1
- package/references/dataset.md +19 -0
- package/references/decompose.md +134 -1
- package/references/solo.md +2 -1
- package/references/ui.md +5 -2
- package/scripts/forge-artifact.sh +14 -0
- package/scripts/forge-brief.py +132 -0
- package/scripts/forge-compare.py +11 -1
- package/scripts/forge-config.py +176 -9
- package/scripts/forge-contract.py +46 -3
- package/scripts/forge-control.py +86 -13
- package/scripts/forge-dispatch.sh +14 -10
- package/scripts/forge-du.py +167 -0
- package/scripts/forge-lib-adopt.sh +1 -0
- package/scripts/forge-lib-plans.sh +5 -2
- package/scripts/forge-lib-review.sh +29 -1
- package/scripts/forge-metrics.sh +7 -3
- package/scripts/forge-parallel-options.sh +4 -0
- package/scripts/forge-parallel.sh +503 -9
- package/scripts/forge-prompt.py +120 -0
- package/scripts/forge-retro.py +115 -0
- package/scripts/forge-runs-compact.py +443 -0
- package/scripts/forge-runs-rm.py +2 -0
- package/scripts/forge-runs.py +18 -3
- package/scripts/forge-schedule.py +279 -4
- package/scripts/forge-shadow.py +7 -1
- package/scripts/forge-solo.sh +2 -0
- package/scripts/forge-summarize.py +698 -0
- package/scripts/forge-ui-options.sh +10 -0
- package/scripts/forge_brief/__init__.py +587 -0
- package/scripts/forge_brief/answers.py +459 -0
- package/scripts/forge_dataset/__init__.py +10 -0
- package/scripts/forge_dataset/export.py +18 -4
- package/scripts/forge_dataset/facts.py +6 -4
- package/scripts/forge_dataset/harvest.py +40 -6
- package/scripts/forge_dataset/history.py +5 -3
- package/scripts/forge_decide/__init__.py +11 -1
- package/scripts/forge_locations.py +366 -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 +477 -0
- package/scripts/forge_storage.py +515 -0
- package/ui/README.md +68 -8
- package/ui/docs/api.md +205 -17
- package/ui/forge_ui/control.py +92 -11
- package/ui/forge_ui/export.py +24 -5
- package/ui/forge_ui/links.py +337 -0
- package/ui/forge_ui/models.py +57 -4
- package/ui/forge_ui/projects.py +4 -1
- package/ui/forge_ui/reader.py +661 -30
- package/ui/forge_ui/static/app.js +86 -4
- package/ui/forge_ui/static/briefview.js +302 -0
- package/ui/forge_ui/static/checksview.js +6 -2
- package/ui/forge_ui/static/controls.js +5 -0
- package/ui/forge_ui/static/index.html +3 -0
- package/ui/forge_ui/static/panel.js +268 -2
- package/ui/forge_ui/static/runmodel.js +13 -1
- package/ui/forge_ui/static/storageview.js +271 -0
- package/ui/forge_ui/static/style.css +99 -3
- package/ui/forge_ui/static/worktreesview.js +3 -3
- package/ui/forge_ui/storage.py +136 -0
- package/ui/forge_ui/transcripts.py +35 -10
- package/ui/forge_ui/worktrees.py +154 -13
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())
|