@giamme/forge 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -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 +13 -0
- package/docs/decomposed-runs.md +8 -0
- package/docs/forge-ui.md +23 -2
- package/docs/memory.md +2 -0
- package/docs/reviews.md +15 -1
- package/docs/safety.md +8 -0
- package/forge +24 -1
- package/package.json +1 -1
- package/references/dataset.md +143 -5
- package/references/decision-models.md +15 -2
- package/references/decompose.md +180 -11
- package/references/planning.md +3 -2
- 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 +98 -4
- package/scripts/forge-control.py +86 -13
- package/scripts/forge-dispatch.sh +14 -10
- package/scripts/forge-du.py +167 -0
- package/scripts/forge-issues.py +4 -3
- package/scripts/forge-ledger.py +3 -1
- package/scripts/forge-lib-adopt.sh +8 -1
- package/scripts/forge-lib-plans.sh +5 -2
- package/scripts/forge-lib-review.sh +29 -1
- package/scripts/forge-metrics.sh +29 -3
- package/scripts/forge-parallel-options.sh +4 -0
- package/scripts/forge-parallel.sh +506 -10
- package/scripts/forge-plan-check.py +25 -2
- package/scripts/forge-planner.py +20 -6
- 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 +35 -10
- package/scripts/forge-solo.sh +2 -0
- package/scripts/forge-summarize.py +698 -0
- package/scripts/forge-sweep.py +25 -10
- 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/cli.py +83 -0
- package/scripts/forge_dataset/export.py +18 -4
- package/scripts/forge_dataset/facts.py +280 -0
- package/scripts/forge_dataset/harvest.py +56 -9
- package/scripts/forge_dataset/history.py +5 -3
- package/scripts/forge_dataset/outcomes.py +206 -58
- package/scripts/forge_dataset/pairs.py +174 -0
- package/scripts/forge_dataset/risk.py +108 -0
- package/scripts/forge_dataset/tiers.py +427 -0
- package/scripts/forge_decide/__init__.py +11 -1
- package/scripts/forge_decide/cli.py +23 -2
- package/scripts/forge_decide/labels.py +30 -6
- package/scripts/forge_decide/replay.py +10 -4
- 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 +217 -20
- package/ui/forge_ui/control.py +92 -11
- package/ui/forge_ui/export.py +31 -5
- package/ui/forge_ui/findings.py +4 -2
- 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 +732 -34
- package/ui/forge_ui/server.py +8 -0
- package/ui/forge_ui/static/app.js +92 -5
- 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/diffview.js +7 -3
- package/ui/forge_ui/static/index.html +3 -0
- package/ui/forge_ui/static/panel.js +311 -4
- 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 +100 -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
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Brief mode: each task's open questions, asked before the task starts.
|
|
3
|
+
|
|
4
|
+
write PLAN [--task ID] [--jobs N] [--force]
|
|
5
|
+
One read-only side dispatch per task that has no brief.json (earliest projected
|
|
6
|
+
start first), stored as tasks/<id>/brief.json and brief.parked.json.
|
|
7
|
+
show PLAN [--task ID] [--json]
|
|
8
|
+
Every question with its state, flagged open questions first.
|
|
9
|
+
answer PLAN TASK QID TEXT [--actor A] [--file F]
|
|
10
|
+
Record an answer. Before the task starts it goes to brief.answers.json; after,
|
|
11
|
+
to brief.late.json. A late answer prints the tasks.tsv row and the prompt.md
|
|
12
|
+
a follow-up needs, then the `forge control add` line that queues that row.
|
|
13
|
+
--file F reads the text (- is stdin).
|
|
14
|
+
stale PLAN MERGED-TASK
|
|
15
|
+
Flag open questions of dependents that have not started, when the merge changed
|
|
16
|
+
a file outside the task's declared files. A declared directory covers the paths
|
|
17
|
+
under it.
|
|
18
|
+
|
|
19
|
+
Exit codes: 0 ok, 2 usage or an unknown task or question (the message lists the valid
|
|
20
|
+
ids), 3 PLAN is not a plan dir or, for write and show, brief is off for it.
|
|
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_brief # noqa: E402
|
|
31
|
+
import forge_brief.answers as answers # noqa: E402
|
|
32
|
+
|
|
33
|
+
REASONS = {
|
|
34
|
+
'env': 'FORGE_BRIEF=off is set',
|
|
35
|
+
'off': 'brief mode is off for this plan (plan --brief advisory|gated|strict)',
|
|
36
|
+
'never-send': "the repository's privacy is never-send",
|
|
37
|
+
'no-model': 'no brief model (plan --brief-model SPEC, or forge config set brief.model SPEC)',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _parser() -> argparse.ArgumentParser:
|
|
42
|
+
parser = argparse.ArgumentParser(
|
|
43
|
+
prog='forge brief',
|
|
44
|
+
description="Each task's open questions, asked before the task starts.")
|
|
45
|
+
sub = parser.add_subparsers(dest='command', required=True)
|
|
46
|
+
write = sub.add_parser('write', help='write the questions of the tasks that have none yet')
|
|
47
|
+
write.add_argument('plan', help='the plan directory')
|
|
48
|
+
write.add_argument('--task', help='only this task')
|
|
49
|
+
write.add_argument('--jobs', type=int, default=forge_brief.DEFAULT_JOBS,
|
|
50
|
+
help='dispatches at once (default %(default)s)')
|
|
51
|
+
write.add_argument('--force', action='store_true', help='redo a task that already has a brief.json')
|
|
52
|
+
show = sub.add_parser('show', help='every question with its state, flagged first')
|
|
53
|
+
show.add_argument('plan', help='the plan directory')
|
|
54
|
+
show.add_argument('--task', help='only this task')
|
|
55
|
+
show.add_argument('--json', action='store_true', dest='as_json', help='machine-readable output')
|
|
56
|
+
answer = sub.add_parser('answer', help='record an answer to one question')
|
|
57
|
+
answer.add_argument('plan', help='the plan directory')
|
|
58
|
+
answer.add_argument('task', help='the task the question belongs to')
|
|
59
|
+
answer.add_argument('qid', help='the question id, such as q1')
|
|
60
|
+
answer.add_argument('text', nargs='?', default=None, help='the answer (or pass --file)')
|
|
61
|
+
answer.add_argument('--actor', default='cli', help='who is answering (default cli; forge-ui passes ui)')
|
|
62
|
+
answer.add_argument('--file', default=None, help='read the answer from this file, or - for stdin')
|
|
63
|
+
stale = sub.add_parser('stale', help="flag dependents' open questions after a merge outside its files")
|
|
64
|
+
stale.add_argument('plan', help='the plan directory')
|
|
65
|
+
stale.add_argument('task', help='the task that merged')
|
|
66
|
+
return parser
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _say(result: dict) -> None:
|
|
70
|
+
if result['status'] == 'written':
|
|
71
|
+
detail = '%d question(s)' % result['questions']
|
|
72
|
+
if result['parked']:
|
|
73
|
+
detail += ', %d parked' % result['parked']
|
|
74
|
+
elif result['status'] == 'error':
|
|
75
|
+
detail = 'writer failed (%s); no questions' % result['reason']
|
|
76
|
+
else:
|
|
77
|
+
detail = 'skipped (%s)' % result['reason']
|
|
78
|
+
sys.stdout.write('%s: %s\n' % (result['task'], detail))
|
|
79
|
+
sys.stdout.flush()
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _ids(ids) -> str:
|
|
83
|
+
return ', '.join(ids) if ids else '(none)'
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def main(argv=None) -> int:
|
|
87
|
+
args = _parser().parse_args(argv)
|
|
88
|
+
if args.command == 'write' and args.jobs < 1:
|
|
89
|
+
sys.stderr.write('forge brief write: --jobs must be at least 1\n')
|
|
90
|
+
return 2
|
|
91
|
+
try:
|
|
92
|
+
if args.command == 'write':
|
|
93
|
+
forge_brief.write(args.plan, task=args.task, jobs=args.jobs, force=args.force, progress=_say)
|
|
94
|
+
return 0
|
|
95
|
+
if args.command == 'answer':
|
|
96
|
+
result = answers.answer(args.plan, args.task, args.qid, text=args.text,
|
|
97
|
+
actor=args.actor, file=args.file)
|
|
98
|
+
sys.stdout.write(result['message'])
|
|
99
|
+
return 0
|
|
100
|
+
if args.command == 'stale':
|
|
101
|
+
for task, qid in answers.stale(args.plan, args.task):
|
|
102
|
+
sys.stdout.write('%s/%s\n' % (task, qid))
|
|
103
|
+
return 0
|
|
104
|
+
found = forge_brief.collect(args.plan, task=args.task)
|
|
105
|
+
except forge_brief.NotAPlan as error:
|
|
106
|
+
sys.stderr.write('forge brief: not a plan dir: %s\n' % error)
|
|
107
|
+
return 3
|
|
108
|
+
except forge_brief.BriefOff as error:
|
|
109
|
+
sys.stderr.write('forge brief: %s\n' % REASONS.get(error.reason, error.reason))
|
|
110
|
+
return 3
|
|
111
|
+
except forge_brief.UnknownTask as error:
|
|
112
|
+
sys.stderr.write('forge brief: no such task: %s\n' % error)
|
|
113
|
+
return 2
|
|
114
|
+
except answers.NoSuchTask as error:
|
|
115
|
+
sys.stderr.write('forge brief: no such task: %s\nvalid tasks: %s\n' % (error.task, _ids(error.valid)))
|
|
116
|
+
return 2
|
|
117
|
+
except answers.NoSuchQuestion as error:
|
|
118
|
+
sys.stderr.write('forge brief: no such question: %s\nvalid questions for %s: %s\n'
|
|
119
|
+
% (error.qid, error.task, _ids(error.valid)))
|
|
120
|
+
return 2
|
|
121
|
+
except answers.Usage as error:
|
|
122
|
+
sys.stderr.write('forge brief: %s\n' % error)
|
|
123
|
+
return 2
|
|
124
|
+
if args.as_json:
|
|
125
|
+
sys.stdout.write(json.dumps(found, ensure_ascii=False, indent=2, sort_keys=True) + '\n')
|
|
126
|
+
else:
|
|
127
|
+
sys.stdout.write(forge_brief.render(found))
|
|
128
|
+
return 0
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
if __name__ == '__main__':
|
|
132
|
+
sys.exit(main())
|
package/scripts/forge-compare.py
CHANGED
|
@@ -39,7 +39,10 @@ sys.path.insert(0, str(SKILL / 'ui'))
|
|
|
39
39
|
# `plan` writes itself (routing, Jev's frozen selection) or that a fresh plan decides (exploration).
|
|
40
40
|
OPTION_FILES = ('no_ripwire', 'no_memory', 'yolo_dwarf', 'yolo_qa', 'reviewer_session', 'implementer_session', 'fast',
|
|
41
41
|
'pre_review_tests', 'pre_review_parallel', 'qa_threshold', 'timeout', 'verify_retries', 'verify_cmd',
|
|
42
|
-
'verify_parallel', 'setup_cmd', 'final_qa', 'shadow_qa', 'shadow_rate', 'escalate_after', 'fail_first', 'profile.json'
|
|
42
|
+
'verify_parallel', 'setup_cmd', 'final_qa', 'shadow_qa', 'shadow_rate', 'escalate_after', 'fail_first', 'profile.json',
|
|
43
|
+
'retro_mode', 'brief', 'brief_scope', 'brief_model', 'summaries', 'summaries_model')
|
|
44
|
+
# The feature files are rewritten from the source's effective settings (copy_plan), not only copied.
|
|
45
|
+
FEATURE_FILES = ('retro_mode', 'brief', 'brief_scope', 'brief_model', 'summaries', 'summaries_model')
|
|
43
46
|
PLAN_FILES = ('repo.identity', 'goal.txt', 'request.md')
|
|
44
47
|
TASK_FILES = ('prompt.md', 'approach.md')
|
|
45
48
|
NAME = re.compile(r'[^A-Za-z0-9._-]+')
|
|
@@ -199,6 +202,13 @@ def copy_plan(src: dict, new: dict, rows: list) -> None:
|
|
|
199
202
|
shutil.copy2(plan / name, out / name)
|
|
200
203
|
if (plan / 'verify.d').is_dir():
|
|
201
204
|
shutil.copytree(plan / 'verify.d', out / 'verify.d')
|
|
205
|
+
# Retro, brief and summaries as the source resolved them, `off` included: the new plan has
|
|
206
|
+
# no waves.tsv yet, so a missing file would let its `plan` take the user setting instead.
|
|
207
|
+
from forge_side import plan_files
|
|
208
|
+
for name in FEATURE_FILES:
|
|
209
|
+
(out / name).unlink(missing_ok=True)
|
|
210
|
+
for name, value in plan_files(plan).items():
|
|
211
|
+
(out / name).write_text(value + '\n')
|
|
202
212
|
for row in rows:
|
|
203
213
|
for name in TASK_FILES:
|
|
204
214
|
if (plan / 'tasks' / row['id'] / name).is_file():
|
package/scripts/forge-config.py
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""forge config <command>: one view of every config source, and safe edits for the per-repo
|
|
2
|
+
"""forge config <command>: one view of every config source, and safe edits for the per-repo files and the user feature settings.
|
|
3
3
|
|
|
4
|
-
show [--repo DIR] [--json] registry, Jev, decide, profiles, the repo's .forge files, dataset and FORGE_* env
|
|
4
|
+
show [--repo DIR] [--json] registry, Jev, decide, features, profiles, the repo's .forge files, dataset and FORGE_* env
|
|
5
5
|
set <key> <value> [--repo DIR] [--json] repo.verify | repo.setup | repo.verify-subset | decide.gate.<gate>[.provider|.model]
|
|
6
|
+
| retro | brief | brief.scope | brief.model | summaries | summaries.model
|
|
7
|
+
| storage.compact | storage.warn-gb
|
|
6
8
|
unset <key> [--repo DIR] [--json] repo.verify | repo.setup | repo.verify-subset
|
|
9
|
+
| retro | brief | brief.scope | brief.model | summaries | summaries.model
|
|
10
|
+
| storage.compact | storage.warn-gb
|
|
7
11
|
profile list|show|create|edit|set|unset|rm|use [--repo DIR] [--json]
|
|
8
12
|
profiles in decide.json; --repo writes the repo file, otherwise the user file
|
|
9
13
|
|
|
@@ -16,6 +20,16 @@ to off. jev.enabled is gone; set a gate with decide.gate.<gate>. The registry is
|
|
|
16
20
|
read-only here: the skill dir is often a live symlink to a checkout, so an edit would change
|
|
17
21
|
runs already in progress; edit the checkout.
|
|
18
22
|
|
|
23
|
+
`retro`, `brief`, `brief.scope`, `brief.model`, `summaries` and `summaries.model` are the user-level
|
|
24
|
+
feature settings (decide.json `features`). `brief` is the level (off, advisory, gated or strict);
|
|
25
|
+
`summaries` is the mode (off or on); `brief.scope` is task, wave or plan. A model is a spec, checked
|
|
26
|
+
the way a profile routing spec is. Setting brief or summaries on with no model is stored; refusing
|
|
27
|
+
to plan without one is a later step. `storage.compact` (auto, the default, or off) is whether forge
|
|
28
|
+
compacts a repository's idle runs in the background when a run starts, and `storage.warn-gb` (a
|
|
29
|
+
number of gigabytes, 20 by default, or off) when it warns at run start that the repository's forge
|
|
30
|
+
files have grown past it (#139; forge_storage.py). A bad value exits 2 and writes nothing. Unset removes that
|
|
31
|
+
field and keeps every other key. These keys ignore `--repo`: they always write the user file.
|
|
32
|
+
|
|
19
33
|
Only the three per-repo files are ever read for content; cloudflare.env never is. Values of FORGE_*
|
|
20
34
|
variables whose name contains TOKEN, KEY, SECRET or PASSWORD show as "<set>". A provider key never
|
|
21
35
|
appears in show.
|
|
@@ -54,6 +68,7 @@ from forge_decide import GATES, MODES, load_repo, load_user, save_repo, save_use
|
|
|
54
68
|
from forge_decide import profiles
|
|
55
69
|
from forge_decide.migrate import run as migrate_run
|
|
56
70
|
from forge_decide.providers import spec_for_site
|
|
71
|
+
from forge_side import (BRIEF_LEVELS, BRIEF_SCOPES, FEATURE_KEYS, ON_OFF, STORAGE_COMPACT, stored_features)
|
|
57
72
|
|
|
58
73
|
REPO_FILES = ('verify', 'setup', 'verify-subset')
|
|
59
74
|
KEYS = tuple('repo.' + n for n in REPO_FILES)
|
|
@@ -343,10 +358,17 @@ def _print_decide(decide):
|
|
|
343
358
|
print(' shadowed: %s: repo %r, user %r' % (entry.get('key'), entry.get('repo'), entry.get('user')))
|
|
344
359
|
|
|
345
360
|
|
|
361
|
+
def _print_features(features):
|
|
362
|
+
print('features:')
|
|
363
|
+
for key in FEATURE_KEYS:
|
|
364
|
+
value = features.get(key)
|
|
365
|
+
print(' %s: %s' % (key, '(none)' if value is None else value))
|
|
366
|
+
|
|
367
|
+
|
|
346
368
|
def cmd_show(args):
|
|
347
369
|
root = repo_root(args.repo, required=False)
|
|
348
370
|
data = dict(registry=registry_block(), jev=jev_block(), decide=decide_block(root),
|
|
349
|
-
profiles=profiles_payload(show_profiles_repo(root)))
|
|
371
|
+
features=stored_features(), profiles=profiles_payload(show_profiles_repo(root)))
|
|
350
372
|
if root:
|
|
351
373
|
data['repo'] = repo_block(root)
|
|
352
374
|
data['dataset'] = dataset_block()
|
|
@@ -363,6 +385,7 @@ def cmd_show(args):
|
|
|
363
385
|
print('jev: %s (%s, %s)' % ('enabled' if jev['enabled'] else 'disabled', jev['path'],
|
|
364
386
|
'present' if jev['exists'] else 'absent'))
|
|
365
387
|
_print_decide(data['decide'])
|
|
388
|
+
_print_features(data['features'])
|
|
366
389
|
print(profiles_text(data['profiles'], heading=True))
|
|
367
390
|
if root:
|
|
368
391
|
print('repo: %s' % root)
|
|
@@ -379,9 +402,10 @@ def cmd_show(args):
|
|
|
379
402
|
# ----------------------------------------------------------------------------------- set / unset
|
|
380
403
|
|
|
381
404
|
def check_key(key):
|
|
382
|
-
if key not in KEYS:
|
|
383
|
-
raise Invalid('unknown key %r; valid keys: %s, decide.gate.<gate>, '
|
|
384
|
-
'decide.gate.<gate>.provider, decide.gate.<gate>.model'
|
|
405
|
+
if key not in KEYS and key not in FEATURE_KEYS:
|
|
406
|
+
raise Invalid('unknown key %r; valid keys: %s, %s, decide.gate.<gate>, '
|
|
407
|
+
'decide.gate.<gate>.provider, decide.gate.<gate>.model'
|
|
408
|
+
% (key, ', '.join(KEYS), ', '.join(FEATURE_KEYS)))
|
|
385
409
|
|
|
386
410
|
|
|
387
411
|
def decide_target(key):
|
|
@@ -471,6 +495,8 @@ def emit(args, key, previous, value):
|
|
|
471
495
|
def cmd_set(args):
|
|
472
496
|
if args.key == 'jev.enabled':
|
|
473
497
|
raise Invalid('jev.enabled is gone; set a gate with decide.gate.<gate>')
|
|
498
|
+
if args.key in FEATURE_KEYS:
|
|
499
|
+
return set_feature(args)
|
|
474
500
|
if args.key not in KEYS:
|
|
475
501
|
return set_decide(args)
|
|
476
502
|
root = repo_root(args.repo, required=True)
|
|
@@ -494,6 +520,8 @@ def cmd_set(args):
|
|
|
494
520
|
def cmd_unset(args):
|
|
495
521
|
if args.key == 'jev.enabled':
|
|
496
522
|
raise Invalid('jev.enabled is gone; set a gate with decide.gate.<gate>')
|
|
523
|
+
if args.key in FEATURE_KEYS:
|
|
524
|
+
return unset_feature(args)
|
|
497
525
|
if decide_target(args.key):
|
|
498
526
|
raise Invalid('set the mode to off')
|
|
499
527
|
check_key(args.key)
|
|
@@ -512,6 +540,145 @@ def cmd_unset(args):
|
|
|
512
540
|
return 0
|
|
513
541
|
|
|
514
542
|
|
|
543
|
+
# The user `features` object. `brief` is the level; `summaries` is the mode. A model is optional
|
|
544
|
+
# here: planning refuses a feature that is on with no model, and this command only stores it.
|
|
545
|
+
_FEATURE_FIELD = {
|
|
546
|
+
'retro': ('retro', None),
|
|
547
|
+
'brief': ('brief', 'level'),
|
|
548
|
+
'brief.scope': ('brief', 'scope'),
|
|
549
|
+
'brief.model': ('brief', 'model'),
|
|
550
|
+
'summaries': ('summaries', 'mode'),
|
|
551
|
+
'summaries.model': ('summaries', 'model'),
|
|
552
|
+
'storage.compact': ('storage', 'compact'),
|
|
553
|
+
'storage.warn-gb': ('storage', 'warn_gb'),
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
def _feature_value(key, value):
|
|
558
|
+
"""The value to store, or Invalid. Checked before anything is written."""
|
|
559
|
+
if key in ('retro', 'summaries'):
|
|
560
|
+
if value not in ON_OFF:
|
|
561
|
+
raise Invalid('%s must be off or on' % key)
|
|
562
|
+
return value
|
|
563
|
+
if key == 'brief':
|
|
564
|
+
if value not in BRIEF_LEVELS:
|
|
565
|
+
raise Invalid('brief must be off, advisory, gated or strict')
|
|
566
|
+
return value
|
|
567
|
+
if key == 'storage.compact':
|
|
568
|
+
if value not in STORAGE_COMPACT:
|
|
569
|
+
raise Invalid('storage.compact must be auto or off')
|
|
570
|
+
return value
|
|
571
|
+
if key == 'storage.warn-gb':
|
|
572
|
+
if value != 'off':
|
|
573
|
+
try:
|
|
574
|
+
number = float(value)
|
|
575
|
+
except ValueError:
|
|
576
|
+
number = 0
|
|
577
|
+
if not (0 < number < float('inf')):
|
|
578
|
+
raise Invalid('storage.warn-gb must be a number of gigabytes over 0, or off')
|
|
579
|
+
return value
|
|
580
|
+
if key == 'brief.scope':
|
|
581
|
+
if value not in BRIEF_SCOPES:
|
|
582
|
+
raise Invalid('brief.scope must be task, wave or plan')
|
|
583
|
+
return value
|
|
584
|
+
reason = profiles.check_spec(value)
|
|
585
|
+
if reason:
|
|
586
|
+
raise Invalid(reason)
|
|
587
|
+
return value
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def _features_map(data):
|
|
591
|
+
features = data.get('features')
|
|
592
|
+
if not isinstance(features, dict):
|
|
593
|
+
features = {}
|
|
594
|
+
data['features'] = features
|
|
595
|
+
return features
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
def _feature_child(features, section):
|
|
599
|
+
child = features.get(section)
|
|
600
|
+
if not isinstance(child, dict):
|
|
601
|
+
child = {}
|
|
602
|
+
features[section] = child
|
|
603
|
+
return child
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
def _stored_feature(data, key):
|
|
607
|
+
features = data.get('features')
|
|
608
|
+
if not isinstance(features, dict):
|
|
609
|
+
return None
|
|
610
|
+
section, field = _FEATURE_FIELD[key]
|
|
611
|
+
if field is None:
|
|
612
|
+
value = features.get(section)
|
|
613
|
+
return value if isinstance(value, str) else None
|
|
614
|
+
child = features.get(section)
|
|
615
|
+
if not isinstance(child, dict):
|
|
616
|
+
return None
|
|
617
|
+
value = child.get(field)
|
|
618
|
+
return value if isinstance(value, str) else None
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
def _put_feature(data, key, value):
|
|
622
|
+
features = _features_map(data)
|
|
623
|
+
section, field = _FEATURE_FIELD[key]
|
|
624
|
+
if field is None:
|
|
625
|
+
features[section] = value
|
|
626
|
+
return
|
|
627
|
+
_feature_child(features, section)[field] = value
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
def _drop_feature(data, key):
|
|
631
|
+
"""Remove one field. Empty brief/summaries/features objects go too; other keys stay."""
|
|
632
|
+
previous = _stored_feature(data, key)
|
|
633
|
+
features = data.get('features')
|
|
634
|
+
if not isinstance(features, dict):
|
|
635
|
+
return None
|
|
636
|
+
section, field = _FEATURE_FIELD[key]
|
|
637
|
+
if field is None:
|
|
638
|
+
features.pop(section, None)
|
|
639
|
+
else:
|
|
640
|
+
child = features.get(section)
|
|
641
|
+
if isinstance(child, dict):
|
|
642
|
+
child.pop(field, None)
|
|
643
|
+
if not child:
|
|
644
|
+
features.pop(section, None)
|
|
645
|
+
if not features:
|
|
646
|
+
data.pop('features', None)
|
|
647
|
+
return previous
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
def set_feature(args):
|
|
651
|
+
"""Write one feature key into the user decide.json. `--repo` is ignored."""
|
|
652
|
+
value = _feature_value(args.key, args.value)
|
|
653
|
+
result = migrate_run()
|
|
654
|
+
if result['status'] == 'migrated':
|
|
655
|
+
print('forge config: migrated jev.json into %s first' % user_path(), file=sys.stderr)
|
|
656
|
+
data, error = load_user()
|
|
657
|
+
if error:
|
|
658
|
+
raise Invalid(error)
|
|
659
|
+
previous = _stored_feature(data, args.key)
|
|
660
|
+
_put_feature(data, args.key, value)
|
|
661
|
+
data.setdefault('version', 1)
|
|
662
|
+
save_user(data)
|
|
663
|
+
emit(args, args.key, previous, value)
|
|
664
|
+
return 0
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
def unset_feature(args):
|
|
668
|
+
"""Remove one feature key from the user file. A missing file is left missing."""
|
|
669
|
+
if not user_path().exists():
|
|
670
|
+
emit(args, args.key, None, None)
|
|
671
|
+
return 0
|
|
672
|
+
data, error = load_user()
|
|
673
|
+
if error:
|
|
674
|
+
raise Invalid(error)
|
|
675
|
+
previous = _drop_feature(data, args.key)
|
|
676
|
+
if previous is not None:
|
|
677
|
+
save_user(data)
|
|
678
|
+
emit(args, args.key, previous, None)
|
|
679
|
+
return 0
|
|
680
|
+
|
|
681
|
+
|
|
515
682
|
def set_decide(args):
|
|
516
683
|
"""Write one decide key at the user level: a mode through `forge decide gate`, a provider or model
|
|
517
684
|
through _write_user_field. --repo is only the repo whose effective settings are read for `previous`."""
|
|
@@ -1042,17 +1209,17 @@ def add_profile_parser(sub):
|
|
|
1042
1209
|
def parser():
|
|
1043
1210
|
p = argparse.ArgumentParser(prog='forge config', description=__doc__.split('\n\n')[0])
|
|
1044
1211
|
sub = p.add_subparsers(dest='cmd', required=True)
|
|
1045
|
-
s = sub.add_parser('show', help="every config source: registry, decide, profiles, the repo's .forge files, dataset, FORGE_* env")
|
|
1212
|
+
s = sub.add_parser('show', help="every config source: registry, decide, features, profiles, the repo's .forge files, dataset, FORGE_* env")
|
|
1046
1213
|
s.add_argument('--repo')
|
|
1047
1214
|
s.add_argument('--json', action='store_true')
|
|
1048
1215
|
s.set_defaults(fn=cmd_show)
|
|
1049
|
-
s = sub.add_parser('set', help='set repo
|
|
1216
|
+
s = sub.add_parser('set', help='set a repo file, a decide gate, or a user feature (retro, brief, summaries)')
|
|
1050
1217
|
s.add_argument('key')
|
|
1051
1218
|
s.add_argument('value')
|
|
1052
1219
|
s.add_argument('--repo')
|
|
1053
1220
|
s.add_argument('--json', action='store_true')
|
|
1054
1221
|
s.set_defaults(fn=cmd_set)
|
|
1055
|
-
s = sub.add_parser('unset', help='remove
|
|
1222
|
+
s = sub.add_parser('unset', help='remove a repo file or a user feature (retro, brief, summaries)')
|
|
1056
1223
|
s.add_argument('key')
|
|
1057
1224
|
s.add_argument('--repo')
|
|
1058
1225
|
s.add_argument('--json', action='store_true')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""The QA contract: one shared review prompt, a severity vocabulary and a deterministic gate.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Subcommands, stdlib only, no network:
|
|
5
5
|
|
|
6
6
|
qa --part head|tail [--kind task|final|solo|sweep] [--threshold P0|P1|P2|P3|none]
|
|
7
7
|
Prints one piece of the QA prompt. The caller prints everything between and
|
|
@@ -10,6 +10,9 @@ Three subcommands, stdlib only, no network:
|
|
|
10
10
|
dwarf [--pre-review]
|
|
11
11
|
Prints the implementer rules block that callers append to the dwarf prompt;
|
|
12
12
|
--pre-review adds that forge runs the affected tests before the review (#85).
|
|
13
|
+
retro --role dwarf|qa|planner|review
|
|
14
|
+
Prints the retro-note instruction. Most tasks have nothing to say. Only the
|
|
15
|
+
dwarf's text mentions writing .forge/retro-inbox.jsonl when a hard blocker hits.
|
|
13
16
|
gate --verdict PASS|FAIL|UNKNOWN --qa-last FILE [--threshold Pn|none] [--known-issues OUT]
|
|
14
17
|
Prints ONE tab-separated line
|
|
15
18
|
decision <TAB> worst_confirmed <TAB> n_confirmed <TAB> n_unlabelled <TAB> n_below
|
|
@@ -54,8 +57,13 @@ line); CONFIRMED beats PLAUSIBLE; PLAUSIBLE-only blocks are ignored; "NOT CONFIR
|
|
|
54
57
|
lowercase prose do not count. The severity is the first P0-P3 token of the block's first
|
|
55
58
|
line (`[P2]`, `(P2)`, `**P2**`, `P2:`, `P2 -` or a standalone `P2`; uppercase only).
|
|
56
59
|
|
|
60
|
+
Facts (#119). A finding may end its first line (or, wrapped, its last) with
|
|
61
|
+
`{reach=main|realistic|unusual origin=new|existing evidence=ran|traced|suspected}`. They are
|
|
62
|
+
recorded in shadow and decide nothing: the gate never reads them, and `split_facts` cuts the
|
|
63
|
+
suffix for readers that show the line. A missing or malformed suffix changes nothing.
|
|
64
|
+
|
|
57
65
|
Phantom findings. A reviewer may echo the contract it was given. Three layers keep that
|
|
58
|
-
from creating findings or blocking: (1) FORGE_VERDICT, FORGE_LEARNING and
|
|
66
|
+
from creating findings or blocking: (1) FORGE_VERDICT, FORGE_LEARNING, FORGE_TESTS and FORGE_RETRO text is removed
|
|
59
67
|
before parsing (the verdict line itself says "CONFIRMED"); (2) any line that is a
|
|
60
68
|
contiguous fragment of this module's own contract text (all parts, kinds and thresholds,
|
|
61
69
|
whitespace-collapsed, at least 25 characters, list marker ignored) is removed, which
|
|
@@ -186,8 +194,22 @@ _SEVERITY = [
|
|
|
186
194
|
' P1 wrong behaviour on realistic input, or breaks an existing contract',
|
|
187
195
|
' P2 edge-case bug, race that needs unusual timing, missing hardening',
|
|
188
196
|
' P3 minor: cosmetic, naming, nit-level correctness',
|
|
197
|
+
'End the first line of every finding with three facts about it, in braces, in this form:',
|
|
198
|
+
' - [P1][CONFIRMED] path/file.py:123 — what breaks {reach=realistic origin=new evidence=traced}',
|
|
199
|
+
' reach main (the main path), realistic (realistic input),',
|
|
200
|
+
' or unusual (an unusual or hostile state)',
|
|
201
|
+
' origin new (this change introduced it), or existing (it was there before the change)',
|
|
202
|
+
' evidence ran (you ran it and saw it break), traced (you traced it in the code),',
|
|
203
|
+
' or suspected',
|
|
204
|
+
'The facts are recorded for measurement only: they change neither the severity nor what blocks.',
|
|
189
205
|
]
|
|
190
206
|
|
|
207
|
+
# The three facts of #119, recorded in shadow beside each finding's severity and confidence. They go
|
|
208
|
+
# at the END of the first line, never after the tags: `forge issues` would read a third tag as part
|
|
209
|
+
# of the location, and forge-ui strips only two.
|
|
210
|
+
FACTS = {'reach': ('main', 'realistic', 'unusual'), 'origin': ('new', 'existing'),
|
|
211
|
+
'evidence': ('ran', 'traced', 'suspected')}
|
|
212
|
+
|
|
191
213
|
_SWEEP_FINDINGS = [
|
|
192
214
|
'Report findings only — do not edit any file. A finding here is a regression the change',
|
|
193
215
|
'introduced: give its file and line, what breaks, and a concrete input that triggers it. Mark it',
|
|
@@ -287,6 +309,38 @@ _DWARF_PRE_REVIEW = [
|
|
|
287
309
|
]
|
|
288
310
|
|
|
289
311
|
|
|
312
|
+
# Retro notes (#132). Silence is the default: the task being hard is not a note. Only the
|
|
313
|
+
# dwarf can be blocked before it has a final message, so only that text mentions the inbox.
|
|
314
|
+
RETRO_ROLES = ('dwarf', 'qa', 'planner', 'review')
|
|
315
|
+
_RETRO = [
|
|
316
|
+
'Most tasks have nothing to report. Write a retro note only for an obstacle that came',
|
|
317
|
+
'from forge, this machine, or the instructions. The task\'s own difficulty does not',
|
|
318
|
+
'belong here: a hard task is not a note.',
|
|
319
|
+
'When you do have one, put it on a line of its own in your final message, as JSON:',
|
|
320
|
+
' FORGE_RETRO: {"type":"sandbox","fixable_by":"user","summary":"the sandbox blocked git push","evidence":{"command":"git push","exit":128,"error":"fatal: unable to access"},"blocking":true,"tried":"retried the push once"}',
|
|
321
|
+
'type is one of environment, sandbox, tooling, prompt, forge-bug, other.',
|
|
322
|
+
'fixable_by is one of user, forge, unsure.',
|
|
323
|
+
'summary is one line. evidence is the command, its exit code and the error text',
|
|
324
|
+
'(keep the error under 2 KB). blocking is true when you could not finish without it.',
|
|
325
|
+
'tried is what you did before giving up. Omit the line when there is nothing to say.',
|
|
326
|
+
]
|
|
327
|
+
_RETRO_INBOX = [
|
|
328
|
+
'If a hard blocker hits before you can finish, append that same JSON object as one',
|
|
329
|
+
'line to .forge/retro-inbox.jsonl in this worktree, at that moment. .forge is already',
|
|
330
|
+
'excluded from diffs and commits.',
|
|
331
|
+
]
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def retro_text(role: str) -> str:
|
|
335
|
+
"""The retro-note instruction for one role, newline-terminated."""
|
|
336
|
+
if role not in RETRO_ROLES:
|
|
337
|
+
raise ValueError('role must be one of ' + ', '.join(RETRO_ROLES))
|
|
338
|
+
lines = list(_RETRO)
|
|
339
|
+
if role == 'dwarf':
|
|
340
|
+
lines += [''] + _RETRO_INBOX
|
|
341
|
+
return '\n'.join(lines) + '\n'
|
|
342
|
+
|
|
343
|
+
|
|
290
344
|
def dwarf_text(pre_review: bool = False, verify_after_merge: bool = False) -> str:
|
|
291
345
|
"""The implementer rules block, newline-terminated."""
|
|
292
346
|
lines = []
|
|
@@ -300,7 +354,7 @@ def dwarf_text(pre_review: bool = False, verify_after_merge: bool = False) -> st
|
|
|
300
354
|
|
|
301
355
|
# --- parsing ---------------------------------------------------------------------
|
|
302
356
|
|
|
303
|
-
_PROTOCOL = re.compile(r'FORGE_(?:VERDICT|LEARNING|TESTS):.*$')
|
|
357
|
+
_PROTOCOL = re.compile(r'FORGE_(?:VERDICT|LEARNING|TESTS|RETRO):.*$')
|
|
304
358
|
_QUOTE = re.compile(r'^\s*(?:>[ \t]?)+')
|
|
305
359
|
_MARKER = re.compile(r'^(?:[-*+•–]|\d{1,3}[.)]|#{1,6})\s+')
|
|
306
360
|
_HEADING = re.compile(r'^ {0,3}#{1,6}[ \t]+\S')
|
|
@@ -328,6 +382,8 @@ def _contract_flat() -> str:
|
|
|
328
382
|
for part in ('head', 'tail'):
|
|
329
383
|
for threshold in SEVERITIES: # None and `none` render one of these
|
|
330
384
|
parts.append(qa_text(part, kind, threshold))
|
|
385
|
+
for role in RETRO_ROLES: # an echoed retro instruction is not a finding either
|
|
386
|
+
parts.append(retro_text(role))
|
|
331
387
|
return _collapse(' '.join(parts))
|
|
332
388
|
|
|
333
389
|
|
|
@@ -342,7 +398,8 @@ def _clean(text: str) -> list:
|
|
|
342
398
|
continue
|
|
343
399
|
line = _QUOTE.sub('', line).rstrip()
|
|
344
400
|
core = _collapse(_MARKER.sub('', line.strip()))
|
|
345
|
-
|
|
401
|
+
# A wrapped finding's facts on a line of their own can match the example's suffix word for word.
|
|
402
|
+
if len(core) >= _MIN_ECHO and core in flat and split_facts(core)[0].strip():
|
|
346
403
|
continue
|
|
347
404
|
out.append((number, line))
|
|
348
405
|
return out
|
|
@@ -407,6 +464,37 @@ def _finding(number: int, lines: list):
|
|
|
407
464
|
return Finding(status, severity, located, number, '\n'.join(lines))
|
|
408
465
|
|
|
409
466
|
|
|
467
|
+
# A brace group closing a line, markup and a full stop around it forgiven. It is the facts suffix only
|
|
468
|
+
# when it names at least one of the three facts: a finding's own text may end in braces (`{}`, `{a=1}`).
|
|
469
|
+
_FACTS_SUFFIX = re.compile(r'[ \t]*[`*_]*\{([^{}\n]*)\}[`*_.]*[ \t]*$')
|
|
470
|
+
_FACT = re.compile(r'([A-Za-z]+)[ \t]*[=:][ \t]*([A-Za-z]+)')
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def split_facts(line: str):
|
|
474
|
+
"""(line without its facts suffix, {reach, origin, evidence}) or (line, None) when it has none.
|
|
475
|
+
|
|
476
|
+
A fact whose value is not one of its words reads None, and keys other than the three are ignored:
|
|
477
|
+
a malformed suffix is still cut from the line, so it never reaches a location or a title."""
|
|
478
|
+
match = _FACTS_SUFFIX.search(line or '')
|
|
479
|
+
if not match:
|
|
480
|
+
return line, None
|
|
481
|
+
said = {key.lower(): value.lower() for key, value in _FACT.findall(match.group(1))}
|
|
482
|
+
if not any(key in said for key in FACTS):
|
|
483
|
+
return line, None
|
|
484
|
+
return line[:match.start()], {key: said[key] if said.get(key) in words else None
|
|
485
|
+
for key, words in FACTS.items()}
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def facts(text: str):
|
|
489
|
+
"""The facts of one finding block: its first line's suffix, else its last line's (a wrapped bullet)."""
|
|
490
|
+
lines = [line for line in (text or '').split('\n') if line.strip()]
|
|
491
|
+
for line in lines[:1] + lines[-1:]:
|
|
492
|
+
found = split_facts(line)[1]
|
|
493
|
+
if found is not None:
|
|
494
|
+
return found
|
|
495
|
+
return None
|
|
496
|
+
|
|
497
|
+
|
|
410
498
|
def parse_findings(text: str) -> list:
|
|
411
499
|
"""Finding blocks of a QA reply, in order; see the module docstring for the rules."""
|
|
412
500
|
found = (_finding(start, lines) for start, _, lines in _blocks(_clean(text)))
|
|
@@ -516,6 +604,9 @@ def _parser() -> argparse.ArgumentParser:
|
|
|
516
604
|
dwarf.add_argument('--pre-review', action='store_true', help='forge runs the affected tests before the review')
|
|
517
605
|
dwarf.add_argument('--verify-after-merge', action='store_true',
|
|
518
606
|
help='the run verifies the repository after each merge, so the whole suite is left to it')
|
|
607
|
+
retro = sub.add_parser('retro', help='print the retro-note instruction for one role')
|
|
608
|
+
retro.add_argument('--role', required=True, choices=RETRO_ROLES,
|
|
609
|
+
help='dwarf also hears about .forge/retro-inbox.jsonl')
|
|
519
610
|
gate_parser = sub.add_parser(
|
|
520
611
|
'gate', help='print: decision (accept|fail|keep), worst_confirmed, n_confirmed, n_unlabelled, n_below')
|
|
521
612
|
gate_parser.add_argument('--verdict', required=True, choices=('PASS', 'FAIL', 'UNKNOWN'))
|
|
@@ -538,6 +629,9 @@ def main(argv=None) -> int:
|
|
|
538
629
|
if args.command == 'dwarf':
|
|
539
630
|
_emit(dwarf_text(args.pre_review, args.verify_after_merge))
|
|
540
631
|
return 0
|
|
632
|
+
if args.command == 'retro':
|
|
633
|
+
_emit(retro_text(args.role))
|
|
634
|
+
return 0
|
|
541
635
|
try:
|
|
542
636
|
with open(args.qa_last, 'rb') as handle:
|
|
543
637
|
text = handle.read().decode('utf-8', 'replace')
|