@giamme/forge 0.18.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 +33 -0
- package/README.md +1 -0
- package/SKILL.md +16 -2
- package/VERSION +1 -1
- package/docs/artifacts.md +25 -1
- package/docs/commands.md +81 -14
- package/docs/decomposed-runs.md +114 -1
- package/docs/development.md +2 -1
- package/docs/forge-ui.md +84 -15
- package/docs/memory.md +25 -4
- package/docs/models.md +8 -0
- package/docs/reviews.md +122 -0
- package/forge +20 -3
- package/package.json +2 -1
- package/references/dataset.md +20 -1
- package/references/decompose.md +621 -33
- package/references/harnesses.md +18 -3
- package/references/planning.md +43 -14
- package/references/ui.md +53 -6
- package/registry.tsv +8 -3
- package/scripts/forge-brief.py +88 -3
- package/scripts/forge-compare.py +4 -3
- package/scripts/forge-contract.py +202 -27
- package/scripts/forge-control.py +117 -5
- package/scripts/forge-dispatch.sh +34 -5
- 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-group.sh +641 -0
- package/scripts/forge-lib-plans.sh +339 -3
- package/scripts/forge-lib-task.sh +197 -4
- package/scripts/forge-memory.sh +245 -3
- package/scripts/forge-parallel.sh +715 -34
- package/scripts/forge-planner.py +104 -8
- package/scripts/forge-route.py +190 -12
- package/scripts/forge-runs.py +9 -5
- package/scripts/forge-schedule.py +354 -45
- package/scripts/forge-solo.sh +2 -0
- package/scripts/forge-worktrees.py +243 -0
- package/scripts/forge_brief/__init__.py +294 -50
- package/scripts/forge_brief/answers.py +58 -11
- package/scripts/forge_brief/proposals.py +1630 -0
- package/scripts/forge_dataset/efforts.py +4 -3
- package/scripts/forge_dataset/export.py +24 -12
- package/scripts/forge_dataset/facts.py +5 -3
- package/scripts/forge_dataset/forecast.py +8 -18
- package/scripts/forge_dataset/harvest.py +204 -9
- package/scripts/forge_dataset/history.py +11 -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_groups/__init__.py +308 -0
- package/scripts/forge_groups/attribute.py +289 -0
- package/scripts/forge_groups/review.py +286 -0
- package/scripts/forge_owner.py +152 -0
- package/scripts/forge_side/__init__.py +12 -7
- package/ui/docs/api.md +173 -17
- package/ui/forge_ui/control.py +361 -2
- package/ui/forge_ui/executions.py +8 -1
- package/ui/forge_ui/export.py +31 -4
- package/ui/forge_ui/groups.py +264 -0
- package/ui/forge_ui/models.py +70 -8
- package/ui/forge_ui/reader.py +262 -19
- package/ui/forge_ui/server.py +4 -0
- package/ui/forge_ui/static/app.js +93 -13
- package/ui/forge_ui/static/briefview.js +350 -47
- 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 +1 -0
- package/ui/forge_ui/static/panel.js +127 -7
- package/ui/forge_ui/static/projectsview.js +189 -10
- package/ui/forge_ui/static/runmodel.js +14 -3
- package/ui/forge_ui/static/storageview.js +91 -10
- package/ui/forge_ui/static/style.css +79 -5
- package/ui/forge_ui/static/worktreesview.js +233 -12
- package/ui/forge_ui/storage.py +14 -0
package/ui/forge_ui/control.py
CHANGED
|
@@ -5,7 +5,8 @@ The server never writes a run dir, a repo or forge's config itself. A write is o
|
|
|
5
5
|
this module holds the route table, the body validation, the call and the mapping of the CLI's
|
|
6
6
|
exit code to an HTTP answer. server.py does the authentication and hands each authenticated POST
|
|
7
7
|
to `dispatch`. Profile create and edit write a JSON body to the CLI's stdin (`--file -`);
|
|
8
|
-
a brief answer writes the answer text the same way.
|
|
8
|
+
a brief answer writes the answer text the same way. Approving, rejecting and proposing a brief
|
|
9
|
+
change print text and take no stdin. Every other call has no stdin.
|
|
9
10
|
"""
|
|
10
11
|
from __future__ import annotations
|
|
11
12
|
|
|
@@ -25,6 +26,25 @@ MAX_FIELD = 256
|
|
|
25
26
|
ISSUES_LIST_TIMEOUT_S = 120 # a listing asks gh for the filed state
|
|
26
27
|
ISSUES_FILE_TIMEOUT_S = 300 # filing up to 25 issues
|
|
27
28
|
DELETE_TIMEOUT_S = 900 # removing worktrees, branches and the archive can be slow
|
|
29
|
+
COMPACT_TIMEOUT_S = 900 # `forge runs compact` can take minutes on a large store
|
|
30
|
+
MAX_PATHS = 200 # worktrees to remove, and memory keys to forget, in one request
|
|
31
|
+
MAX_TASK_ANSWER = 8000 # the answer to a task that waits for input, in characters, after stripping
|
|
32
|
+
# One brief model call, end to end. proposals.propose and forge_brief.write pass 900s to
|
|
33
|
+
# forge_side.run, which waits that plus _DISPATCH_GRACE_S (30) before it returns its own
|
|
34
|
+
# timeout. The extra minute is the CLI storing the result and exiting, so a call that uses
|
|
35
|
+
# its whole wait is a refusal on the page and not a process this route killed.
|
|
36
|
+
_BRIEF_MODEL_S = 900
|
|
37
|
+
_BRIEF_DISPATCH_GRACE_S = 30
|
|
38
|
+
_BRIEF_CALL_S = _BRIEF_MODEL_S + _BRIEF_DISPATCH_GRACE_S
|
|
39
|
+
_BRIEF_SETTLE_S = 60
|
|
40
|
+
BRIEF_PROPOSE_TIMEOUT_S = _BRIEF_CALL_S + _BRIEF_SETTLE_S
|
|
41
|
+
# apply may spend 120s refreshing waves.tsv, then regenerates each unstarted affected task:
|
|
42
|
+
# one model call, in order. The budget is forty of those calls (twice the planner's task
|
|
43
|
+
# ceiling) plus the waves refresh. A faster call releases the run lock when the CLI exits.
|
|
44
|
+
# Past this, a regeneration that is still running is killed, the same way a 60s cap was.
|
|
45
|
+
_WAVES_REFRESH_S = 120
|
|
46
|
+
_APPLY_TASKS = 40
|
|
47
|
+
BRIEF_APPLY_TIMEOUT_S = _WAVES_REFRESH_S + _APPLY_TASKS * _BRIEF_CALL_S + _BRIEF_SETTLE_S
|
|
28
48
|
MAX_FPS = 25
|
|
29
49
|
MAX_LABELS = 5
|
|
30
50
|
MAX_LABEL = 50
|
|
@@ -38,6 +58,9 @@ MAX_PROFILE_BODY = 64 * 1024
|
|
|
38
58
|
# strips control characters; this bound is the one the route enforces before that call.
|
|
39
59
|
MAX_ANSWER = 4096
|
|
40
60
|
_QID = re.compile(r'^q[0-9]+$')
|
|
61
|
+
# The page accepts the same width the route captures. The CLI's own ids are p1, p2, …; p0 still reaches it.
|
|
62
|
+
_PID = re.compile(r'^p[0-9]{1,6}$')
|
|
63
|
+
_TASK_ID = re.compile(r'^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$')
|
|
41
64
|
_PROFILE_NAME = re.compile(r'^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$')
|
|
42
65
|
_PROFILE_KEY = re.compile(r'^(routing|policy)\.[a-z_.]+$')
|
|
43
66
|
_PROFILE_ACTIONS = ('create', 'edit', 'set', 'unset', 'rm', 'use')
|
|
@@ -369,6 +392,102 @@ def _brief_answer(ctx):
|
|
|
369
392
|
stdin=stdin, json_stdout=False))
|
|
370
393
|
|
|
371
394
|
|
|
395
|
+
def _brief_pid(ctx):
|
|
396
|
+
pid = ctx.parts[0] if ctx.parts else ''
|
|
397
|
+
if not isinstance(pid, str) or not _PID.fullmatch(pid):
|
|
398
|
+
raise BadBody('pid must match ^p[0-9]{1,6}$')
|
|
399
|
+
return pid
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
def _optional_reason(value):
|
|
403
|
+
"""None when the reason is absent, null or blank. BadBody when it is not acceptable text.
|
|
404
|
+
|
|
405
|
+
Newline and tab are allowed, as on a dismissal. A leading '-' is safe: the CLI gets `--reason=`.
|
|
406
|
+
"""
|
|
407
|
+
if value is None:
|
|
408
|
+
return None
|
|
409
|
+
if not isinstance(value, str) or len(value) > MAX_REASON or not _no_control_chars(value.replace('\n', ' ').replace('\t', ' ')):
|
|
410
|
+
raise BadBody(f'reason must be a text of at most {MAX_REASON} characters, without control characters (newline and tab are allowed)')
|
|
411
|
+
return value.strip() or None
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def _plan_or_404(ctx):
|
|
415
|
+
path = ctx.locate(('plan',))
|
|
416
|
+
if path is None:
|
|
417
|
+
return None
|
|
418
|
+
return path
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
def _brief_apply(ctx):
|
|
422
|
+
"""POST `{hash}`: `forge brief apply <plan> <pid> --approve <hash> --actor ui`.
|
|
423
|
+
|
|
424
|
+
Exit 0 prints text (the files written, the notes, and the plan-again line), so the body is that text.
|
|
425
|
+
Regeneration is one brief model call per unstarted affected task, so the wait is
|
|
426
|
+
`BRIEF_APPLY_TIMEOUT_S` and not the 60s default. The plan files are written before that
|
|
427
|
+
regeneration; killing it here would leave it half-done and drop the text the page shows.
|
|
428
|
+
"""
|
|
429
|
+
ctx.route = 'brief apply'
|
|
430
|
+
try:
|
|
431
|
+
if not isinstance(ctx.body, dict):
|
|
432
|
+
raise BadBody('body must be a JSON object')
|
|
433
|
+
pid = _brief_pid(ctx)
|
|
434
|
+
_check_fields(ctx.body, ('hash',))
|
|
435
|
+
digest = _text(ctx.body, 'hash')
|
|
436
|
+
except BadBody as exc:
|
|
437
|
+
return _invalid(str(exc))
|
|
438
|
+
path = _plan_or_404(ctx)
|
|
439
|
+
if path is None:
|
|
440
|
+
return 404, {'error': 'not found'}
|
|
441
|
+
return ctx.locked(lambda: ctx.call('brief', 'apply', path, pid, '--approve', digest, '--actor', 'ui',
|
|
442
|
+
json_stdout=False, limit=BRIEF_APPLY_TIMEOUT_S))
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
def _brief_reject(ctx):
|
|
446
|
+
"""POST `{reason}`: `forge brief reject <plan> <pid> [--reason=TEXT] --actor ui`. The reason may be empty."""
|
|
447
|
+
ctx.route = 'brief reject'
|
|
448
|
+
try:
|
|
449
|
+
if not isinstance(ctx.body, dict):
|
|
450
|
+
raise BadBody('body must be a JSON object')
|
|
451
|
+
pid = _brief_pid(ctx)
|
|
452
|
+
_check_fields(ctx.body, ('reason',))
|
|
453
|
+
reason = _optional_reason(ctx.body.get('reason'))
|
|
454
|
+
except BadBody as exc:
|
|
455
|
+
return _invalid(str(exc))
|
|
456
|
+
path = _plan_or_404(ctx)
|
|
457
|
+
if path is None:
|
|
458
|
+
return 404, {'error': 'not found'}
|
|
459
|
+
argv = ['brief', 'reject', path, pid]
|
|
460
|
+
if reason:
|
|
461
|
+
argv.append('--reason=' + reason)
|
|
462
|
+
argv += ['--actor', 'ui']
|
|
463
|
+
return ctx.locked(lambda: ctx.call(*argv, json_stdout=False))
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
def _brief_propose(ctx):
|
|
467
|
+
"""POST `{task, qid}`: `forge brief propose <plan> <task> <qid> --actor ui` for a parked wave or plan question.
|
|
468
|
+
|
|
469
|
+
One brief-change model call. The wait is `BRIEF_PROPOSE_TIMEOUT_S`, past the CLI's own 900s.
|
|
470
|
+
"""
|
|
471
|
+
ctx.route = 'brief propose'
|
|
472
|
+
try:
|
|
473
|
+
if not isinstance(ctx.body, dict):
|
|
474
|
+
raise BadBody('body must be a JSON object')
|
|
475
|
+
_check_fields(ctx.body, ('task', 'qid'))
|
|
476
|
+
task = _text(ctx.body, 'task')
|
|
477
|
+
if not _TASK_ID.fullmatch(task):
|
|
478
|
+
raise BadBody('task must be a task id')
|
|
479
|
+
qid = _text(ctx.body, 'qid')
|
|
480
|
+
if not _QID.fullmatch(qid):
|
|
481
|
+
raise BadBody('qid must match ^q[0-9]+$')
|
|
482
|
+
except BadBody as exc:
|
|
483
|
+
return _invalid(str(exc))
|
|
484
|
+
path = _plan_or_404(ctx)
|
|
485
|
+
if path is None:
|
|
486
|
+
return 404, {'error': 'not found'}
|
|
487
|
+
return ctx.locked(lambda: ctx.call('brief', 'propose', path, task, qid, '--actor', 'ui',
|
|
488
|
+
json_stdout=False, limit=BRIEF_PROPOSE_TIMEOUT_S))
|
|
489
|
+
|
|
490
|
+
|
|
372
491
|
# ----------------------------------------------------------------- issues, delete and config routes
|
|
373
492
|
|
|
374
493
|
def _invalid(detail):
|
|
@@ -913,7 +1032,7 @@ def _storage(ctx):
|
|
|
913
1032
|
refresh = _bit(params, 'refresh')
|
|
914
1033
|
except BadBody as exc:
|
|
915
1034
|
return _invalid(str(exc))
|
|
916
|
-
return 200, storage.screen(ctx.server).answer(refresh=refresh)
|
|
1035
|
+
return 200, storage.with_keys(storage.screen(ctx.server).answer(refresh=refresh), ctx.server.catalog.keys())
|
|
917
1036
|
|
|
918
1037
|
|
|
919
1038
|
def _worktrees(ctx):
|
|
@@ -933,15 +1052,255 @@ def _worktrees(ctx):
|
|
|
933
1052
|
return 200, worktrees.screen(ctx.server).answer(ctx.server.catalog, history, refresh=refresh)
|
|
934
1053
|
|
|
935
1054
|
|
|
1055
|
+
# ----------------------------------------------------------------- remove, forget, compact, answer (#147)
|
|
1056
|
+
|
|
1057
|
+
def _body_object(ctx, allowed):
|
|
1058
|
+
if not isinstance(ctx.body, dict):
|
|
1059
|
+
raise BadBody('body must be a JSON object')
|
|
1060
|
+
_check_fields(ctx.body, allowed)
|
|
1061
|
+
return ctx.body
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
def _string_list(value, name, check):
|
|
1065
|
+
if not isinstance(value, list) or not 1 <= len(value) <= MAX_PATHS:
|
|
1066
|
+
raise BadBody(f'{name} must be a list of 1 to {MAX_PATHS} strings')
|
|
1067
|
+
for item in value:
|
|
1068
|
+
if not isinstance(item, str) or not item or len(item) > 4096 or not _no_control_chars(item) or not check(item):
|
|
1069
|
+
raise BadBody(f'{name} holds a value that is not acceptable')
|
|
1070
|
+
return list(dict.fromkeys(value))
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
def invalidate_worktrees(server):
|
|
1074
|
+
"""The next GET /api/worktrees reads git and the run dirs again."""
|
|
1075
|
+
from forge_ui import worktrees
|
|
1076
|
+
screen = worktrees.screen(server)
|
|
1077
|
+
with screen.lock:
|
|
1078
|
+
screen.result = None
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
def invalidate_storage(server):
|
|
1082
|
+
"""The next GET /api/storage measures again; the answer it has stays on show until then."""
|
|
1083
|
+
from forge_ui import storage
|
|
1084
|
+
screen = storage.screen(server)
|
|
1085
|
+
with screen.lock:
|
|
1086
|
+
if screen.result is not None:
|
|
1087
|
+
screen.result = dict(screen.result, computed=0)
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
def invalidate_memories(server):
|
|
1091
|
+
"""The next GET of a project's memories reads the CLI again (the project screen's `memory` answers)."""
|
|
1092
|
+
from forge_ui import projects
|
|
1093
|
+
screen = projects.screen(server)
|
|
1094
|
+
with screen.lock:
|
|
1095
|
+
for key in [k for k in screen.cli if isinstance(k, tuple) and k and k[0] == 'memory']:
|
|
1096
|
+
del screen.cli[key]
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
def _worktrees_remove(ctx):
|
|
1100
|
+
"""POST `{paths, branches?, dry_run?}`: `forge worktrees rm <paths> [--branches] [--dry-run] --json --actor ui`.
|
|
1101
|
+
|
|
1102
|
+
Each path must be one of the rows of the Worktrees screen. Exit 4 (a row failed) is a 200 with
|
|
1103
|
+
`ok: false`: the page needs the rows to say which one failed.
|
|
1104
|
+
"""
|
|
1105
|
+
from forge_ui import worktrees
|
|
1106
|
+
ctx.route = 'worktrees remove'
|
|
1107
|
+
try:
|
|
1108
|
+
body = _body_object(ctx, ('paths', 'branches', 'dry_run'))
|
|
1109
|
+
paths = _string_list(body.get('paths'), 'paths', os.path.isabs)
|
|
1110
|
+
branches = _flag(body, 'branches')
|
|
1111
|
+
dry = _flag(body, 'dry_run')
|
|
1112
|
+
except BadBody as exc:
|
|
1113
|
+
return _invalid(str(exc))
|
|
1114
|
+
|
|
1115
|
+
def history():
|
|
1116
|
+
status, found = ctx.call('dataset', 'worktrees', '--json')
|
|
1117
|
+
return found if status == 200 else None
|
|
1118
|
+
|
|
1119
|
+
def listed(refresh):
|
|
1120
|
+
answer = worktrees.screen(ctx.server).answer(ctx.server.catalog, history, refresh=refresh)
|
|
1121
|
+
return {row.get('path') for row in answer.get('rows') or []}
|
|
1122
|
+
known = listed(False)
|
|
1123
|
+
if not all(path in known for path in paths):
|
|
1124
|
+
known = listed(True)
|
|
1125
|
+
missing = [path for path in paths if path not in known]
|
|
1126
|
+
if missing:
|
|
1127
|
+
return _invalid(f'{missing[0]!r} is not a worktree the Worktrees screen lists')
|
|
1128
|
+
lock = _server_lock(ctx.server, 'worktrees_lock')
|
|
1129
|
+
if not lock.acquire(blocking=False):
|
|
1130
|
+
return 409, {'error': 'busy'}
|
|
1131
|
+
try:
|
|
1132
|
+
argv = ['worktrees', 'rm', *paths]
|
|
1133
|
+
if branches:
|
|
1134
|
+
argv.append('--branches')
|
|
1135
|
+
if dry:
|
|
1136
|
+
argv.append('--dry-run')
|
|
1137
|
+
status, answer = ctx.call(*argv, '--json', '--actor', 'ui', limit=DELETE_TIMEOUT_S)
|
|
1138
|
+
if status == 500 and isinstance(answer.get('result'), dict) and isinstance(answer['result'].get('rows'), list):
|
|
1139
|
+
status, answer = 200, dict(answer['result'], ok=False)
|
|
1140
|
+
if not dry:
|
|
1141
|
+
invalidate_worktrees(ctx.server)
|
|
1142
|
+
invalidate_storage(ctx.server)
|
|
1143
|
+
return status, answer
|
|
1144
|
+
finally:
|
|
1145
|
+
lock.release()
|
|
1146
|
+
|
|
1147
|
+
|
|
1148
|
+
_MEMORY_KEY = re.compile(r'^[^:\s-][^:]*:.+$')
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
def _forget_keys(value):
|
|
1152
|
+
return _string_list(value, 'keys', lambda key: len(key) <= MAX_FIELD and bool(_MEMORY_KEY.match(key)))
|
|
1153
|
+
|
|
1154
|
+
|
|
1155
|
+
def _memories_forget(ctx):
|
|
1156
|
+
"""POST `{keys, dry_run?, path?}`: `forge memory forget <checkout> <keys> [--dry-run] --json --actor ui`,
|
|
1157
|
+
once per existing checkout of the project (or only the one `path` names)."""
|
|
1158
|
+
from forge_ui import projects
|
|
1159
|
+
ctx.route = 'memories forget'
|
|
1160
|
+
try:
|
|
1161
|
+
body = _body_object(ctx, ('keys', 'dry_run', 'path'))
|
|
1162
|
+
keys = _forget_keys(body.get('keys'))
|
|
1163
|
+
dry = _flag(body, 'dry_run')
|
|
1164
|
+
path = body.get('path')
|
|
1165
|
+
if path is not None and (not isinstance(path, str) or not path):
|
|
1166
|
+
raise BadBody('path must be a checkout path')
|
|
1167
|
+
except BadBody as exc:
|
|
1168
|
+
return _invalid(str(exc))
|
|
1169
|
+
project = projects.screen(ctx.server).projects(ctx.server.catalog).get(ctx.key)
|
|
1170
|
+
if project is None:
|
|
1171
|
+
return 404, {'error': 'not found'}
|
|
1172
|
+
existing = [c['path'] for c in projects.checkouts(project) if c['exists']]
|
|
1173
|
+
if path is not None:
|
|
1174
|
+
if path not in existing:
|
|
1175
|
+
return _invalid('path is not a checkout of this project')
|
|
1176
|
+
existing = [path]
|
|
1177
|
+
if not existing:
|
|
1178
|
+
return 409, {'error': 'refused', 'detail': 'no checkout of this project exists'}
|
|
1179
|
+
lock = _server_lock(ctx.server, 'memory_lock')
|
|
1180
|
+
if not lock.acquire(blocking=False):
|
|
1181
|
+
return 409, {'error': 'busy'}
|
|
1182
|
+
try:
|
|
1183
|
+
argv_tail = [*keys, *(['--dry-run'] if dry else []), '--json', '--actor', 'ui']
|
|
1184
|
+
results, failed = [], []
|
|
1185
|
+
for checkout in existing:
|
|
1186
|
+
status, answer = ctx.call('memory', 'forget', checkout, *argv_tail)
|
|
1187
|
+
if status == 200:
|
|
1188
|
+
results.append({'path': checkout, 'result': answer})
|
|
1189
|
+
else:
|
|
1190
|
+
failed.append((status, answer))
|
|
1191
|
+
results.append({'path': checkout, 'result': None, 'status': status, 'error': answer})
|
|
1192
|
+
if not dry:
|
|
1193
|
+
invalidate_memories(ctx.server)
|
|
1194
|
+
if failed and len(failed) == len(results):
|
|
1195
|
+
return failed[0]
|
|
1196
|
+
return 200, {'ok': not failed, 'dry_run': dry, 'checkouts': results}
|
|
1197
|
+
finally:
|
|
1198
|
+
lock.release()
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
def _storage_compact(ctx):
|
|
1202
|
+
"""POST `{run | all, dry_run?}`: `forge runs compact <run dir>|--all --logs --json [--dry-run]`."""
|
|
1203
|
+
ctx.route = 'compact'
|
|
1204
|
+
try:
|
|
1205
|
+
body = _body_object(ctx, ('run', 'all', 'dry_run'))
|
|
1206
|
+
dry = _flag(body, 'dry_run')
|
|
1207
|
+
run = body.get('run')
|
|
1208
|
+
if ('run' in body) == ('all' in body):
|
|
1209
|
+
raise BadBody('give exactly one of run and all')
|
|
1210
|
+
if 'all' in body and body['all'] is not True:
|
|
1211
|
+
raise BadBody('all must be true')
|
|
1212
|
+
if 'run' in body and (not isinstance(run, str) or not re.fullmatch(r'[0-9a-f]{12}', run)):
|
|
1213
|
+
raise BadBody('run must be a 12-hex run key')
|
|
1214
|
+
except BadBody as exc:
|
|
1215
|
+
return _invalid(str(exc))
|
|
1216
|
+
target = ['--all']
|
|
1217
|
+
if run is not None:
|
|
1218
|
+
ctx.key = run
|
|
1219
|
+
found = ctx.server.catalog.locate(run)
|
|
1220
|
+
if not found:
|
|
1221
|
+
return 404, {'error': 'not found'}
|
|
1222
|
+
target = [str(found[0])]
|
|
1223
|
+
lock = _server_lock(ctx.server, 'compact_lock')
|
|
1224
|
+
if not lock.acquire(blocking=False):
|
|
1225
|
+
return 409, {'error': 'busy'}
|
|
1226
|
+
try:
|
|
1227
|
+
status, answer = ctx.call('runs', 'compact', *target, '--logs', '--json', *(['--dry-run'] if dry else []),
|
|
1228
|
+
limit=COMPACT_TIMEOUT_S)
|
|
1229
|
+
if not dry:
|
|
1230
|
+
invalidate_storage(ctx.server)
|
|
1231
|
+
return status, answer
|
|
1232
|
+
finally:
|
|
1233
|
+
lock.release()
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
def _scheduler_live(path):
|
|
1237
|
+
"""Whether the plan's scheduler.live names a process that is alive (as reader._scheduler judges it)."""
|
|
1238
|
+
try:
|
|
1239
|
+
with open(os.path.join(path, 'scheduler.live'), encoding='utf-8') as handle:
|
|
1240
|
+
pid = json.load(handle).get('pid')
|
|
1241
|
+
except (OSError, ValueError, AttributeError, RecursionError):
|
|
1242
|
+
return False
|
|
1243
|
+
if type(pid) is not int or pid <= 0:
|
|
1244
|
+
return False
|
|
1245
|
+
try:
|
|
1246
|
+
os.kill(pid, 0)
|
|
1247
|
+
except PermissionError:
|
|
1248
|
+
return True
|
|
1249
|
+
except (OSError, OverflowError):
|
|
1250
|
+
return False
|
|
1251
|
+
return True
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
def _task_answer(ctx):
|
|
1255
|
+
"""POST `{text}`: `forge control retry <plan> <id> --answer-file - --actor ui --json`, the text on stdin.
|
|
1256
|
+
|
|
1257
|
+
forge control queues the answer for a live scheduler and prepares the retry itself when there is none."""
|
|
1258
|
+
ctx.route = 'answer'
|
|
1259
|
+
task = ctx.parts[0]
|
|
1260
|
+
try:
|
|
1261
|
+
body = _body_object(ctx, ('text',))
|
|
1262
|
+
text = body.get('text')
|
|
1263
|
+
if not isinstance(text, str):
|
|
1264
|
+
raise BadBody('text must be a string')
|
|
1265
|
+
text = text.strip()
|
|
1266
|
+
if '\x00' in text:
|
|
1267
|
+
raise BadBody('text must not contain a NUL')
|
|
1268
|
+
if not 1 <= len(text) <= MAX_TASK_ANSWER:
|
|
1269
|
+
raise BadBody(f'text must be 1 to {MAX_TASK_ANSWER} characters')
|
|
1270
|
+
try:
|
|
1271
|
+
stdin = text.encode('utf-8')
|
|
1272
|
+
except UnicodeEncodeError:
|
|
1273
|
+
raise BadBody('text must be valid text')
|
|
1274
|
+
except BadBody as exc:
|
|
1275
|
+
return _invalid(str(exc))
|
|
1276
|
+
path = ctx.locate(('plan',))
|
|
1277
|
+
if path is None:
|
|
1278
|
+
return 404, {'error': 'not found'}
|
|
1279
|
+
|
|
1280
|
+
def work():
|
|
1281
|
+
live = _scheduler_live(path)
|
|
1282
|
+
status, answer = ctx.call('control', 'retry', path, task, '--answer-file', '-', '--actor', 'ui', '--json',
|
|
1283
|
+
stdin=stdin)
|
|
1284
|
+
return (200, {'live': live, 'result': answer}) if status == 200 else (status, answer)
|
|
1285
|
+
return ctx.locked(work)
|
|
1286
|
+
|
|
1287
|
+
|
|
936
1288
|
ROUTES = [
|
|
937
1289
|
('GET', re.compile(r'/api/runs/([0-9a-f]{12})/controls'), _show),
|
|
938
1290
|
('POST', re.compile(r'/api/runs/([0-9a-f]{12})/controls'), _change),
|
|
939
1291
|
('POST', re.compile(r'/api/runs/([0-9a-f]{12})/tasks/([A-Za-z0-9][A-Za-z0-9._-]{0,127})/brief/([^/]+)'),
|
|
940
1292
|
_brief_answer),
|
|
1293
|
+
('POST', re.compile(r'/api/runs/([0-9a-f]{12})/proposals/([^/]+)/apply'), _brief_apply),
|
|
1294
|
+
('POST', re.compile(r'/api/runs/([0-9a-f]{12})/proposals/([^/]+)/reject'), _brief_reject),
|
|
1295
|
+
('POST', re.compile(r'/api/runs/([0-9a-f]{12})/proposals'), _brief_propose),
|
|
941
1296
|
('GET', re.compile(r'/api/runs/([0-9a-f]{12})/issues'), _issues_list),
|
|
942
1297
|
('POST', re.compile(r'/api/runs/([0-9a-f]{12})/issues'), _issues_file),
|
|
943
1298
|
('POST', re.compile(r'/api/runs/([0-9a-f]{12})/issues/dismiss'), _issues_dismiss),
|
|
944
1299
|
('POST', re.compile(r'/api/runs/([0-9a-f]{12})/delete'), _delete),
|
|
1300
|
+
('POST', re.compile(r'/api/runs/([0-9a-f]{12})/tasks/([A-Za-z0-9][A-Za-z0-9._-]{0,127})/answer'), _task_answer),
|
|
1301
|
+
('POST', re.compile(r'/api/worktrees/remove()'), _worktrees_remove),
|
|
1302
|
+
('POST', re.compile(r'/api/storage/compact()'), _storage_compact),
|
|
1303
|
+
('POST', re.compile(r'/api/projects/([0-9a-f]{8})/memories/forget'), _memories_forget),
|
|
945
1304
|
('GET', re.compile(r'/api/config/profiles()'), _config_profiles_get),
|
|
946
1305
|
('POST', re.compile(r'/api/config/profiles()'), _config_profiles_set),
|
|
947
1306
|
('GET', re.compile(r'/api/config()'), _config_get),
|
|
@@ -14,9 +14,13 @@ import time
|
|
|
14
14
|
from forge_ui import findings
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
# A model dispatch's id is <role>-<32 hex>. A scripted task's command is script-<16 hex>
|
|
18
|
+
# (forge-parallel.sh). It is an execution, not a model role.
|
|
19
|
+
NAME = re.compile(r'(?:(?:task|dwarf|qa|solo|verification|parallel)-[0-9a-f]{32}|script-[0-9a-f]{16})')
|
|
18
20
|
_KIND = re.compile(r'(final-review|integrate)-([0-9]+)-([0-9]+)')
|
|
19
21
|
_SHADOW = re.compile(r'[0-9]+-[0-9]+')
|
|
22
|
+
# A group dir under groups/. The same shape as a group id (forge_groups, the group route).
|
|
23
|
+
_GROUP_DIR = re.compile(r'[a-z0-9][a-z0-9-]{0,39}')
|
|
20
24
|
CONTAINERS = ('task', 'solo')
|
|
21
25
|
_MODEL_ROLES = ('dwarf', 'qa')
|
|
22
26
|
# attempts.tsv is appended right after the task execution's EXIT trap ran finish().
|
|
@@ -445,6 +449,9 @@ def locate(run_path, name, task_ids):
|
|
|
445
449
|
for child in kinds:
|
|
446
450
|
if child.startswith('integrate-'):
|
|
447
451
|
yield child + '/final-review/attempts'
|
|
452
|
+
# A review=group group's QA dispatch writes its attempts here, as a task's land in the task dir.
|
|
453
|
+
for child in listed('groups', _GROUP_DIR):
|
|
454
|
+
yield f'groups/{child}/attempts'
|
|
448
455
|
|
|
449
456
|
for rel in candidates():
|
|
450
457
|
try:
|
package/ui/forge_ui/export.py
CHANGED
|
@@ -26,8 +26,10 @@ from forge_ui import __version__, reader, server
|
|
|
26
26
|
|
|
27
27
|
STATIC = server.STATIC_DIR
|
|
28
28
|
# what the exported page runs; every other script index.html loads is in LEFT_OUT, with the reason
|
|
29
|
+
# groupsview.js is the group page. It is named here before that file exists; _page skips a
|
|
30
|
+
# SCRIPTS entry whose file is absent, so the export still builds.
|
|
29
31
|
SCRIPTS = ('theme.js', 'icons.js', 'datatable.js', 'shell.js', 'runmodel.js', 'cloudmodel.js', 'graph.js', 'gantt.js', 'verifyview.js', 'checksview.js',
|
|
30
|
-
'briefview.js', 'panel.js', 'diffview.js', 'convo.js', 'files.js', 'map3d.js', 'search.js', 'app.js')
|
|
32
|
+
'briefview.js', 'groupsview.js', 'panel.js', 'diffview.js', 'convo.js', 'files.js', 'map3d.js', 'search.js', 'app.js')
|
|
31
33
|
LEFT_OUT = {
|
|
32
34
|
'uikit.js': 'write helpers and the guards that keep a poll from redrawing what a person holds; a snapshot neither writes nor polls',
|
|
33
35
|
'controls.js': 'changes a live run',
|
|
@@ -48,6 +50,9 @@ TRANSCRIPT_CAP = 2 << 20 # one execution's tr
|
|
|
48
50
|
TOTAL_CAP = 25 << 20 # every response together
|
|
49
51
|
CDN = 'https://cdn.jsdelivr.net/npm/three@0.160.0/'
|
|
50
52
|
_EXEC = re.compile(r'(?:task|dwarf|qa|solo|verification|parallel)-[0-9a-f]{32}')
|
|
53
|
+
# GET /api/runs/<key>/groups/<gid> is the group dict itself, so its goal and decision are not nested
|
|
54
|
+
# under a `groups` key. clean() is told the parent is `groups` for that path.
|
|
55
|
+
_GROUP_DETAIL = re.compile(r'/groups/[a-z0-9][a-z0-9-]{0,39}$')
|
|
51
56
|
# texts that can hold code, prompts or private notes: nulled unless texts=True
|
|
52
57
|
_TEXT_KEYS = frozenset(('prompt', 'last', 'request', 'log_tail', 'dwarf_tail', 'qa_tail', 'qa_last', 'qa_input',
|
|
53
58
|
'tasks_summary', 'known_issues', 'texts', 'text', 'planning_last', 'approach', 'retry_findings',
|
|
@@ -56,12 +61,19 @@ _TEXT_KEYS = frozenset(('prompt', 'last', 'request', 'log_tail', 'dwarf_tail', '
|
|
|
56
61
|
# keys that are private text only under one parent: a person's --reason on each decision (`reason` elsewhere is
|
|
57
62
|
# a short machine word, such as a sweep's dropped-finding reason, and stays); the --reason of each adoption too.
|
|
58
63
|
# A task header's goal and criteria are paragraphs of the prompt; the run's own `goal` (its title) stays.
|
|
64
|
+
# A group's goal (the planner's line in groups.tsv) and the first line of its decision.md are private too,
|
|
65
|
+
# on the run's `groups` list and on GET …/groups/<gid>. A group's title stays. A task's `decision` is an
|
|
66
|
+
# object under `tasks` (its `text` is already in _TEXT_KEYS); it is not this string.
|
|
59
67
|
# A brief question's why, the choices in options, its default and the answer a person typed are private
|
|
60
68
|
# only under `questions` and `parked` (`text` is already in _TEXT_KEYS). `scope`, `state` and `id` stay.
|
|
69
|
+
# A proposal's summary, diff and refusal reason are the model's prose and the patch. pid, state, scope,
|
|
70
|
+
# group, hash and the truncation flag stay. `reason` under `affected` is a short machine word and stays.
|
|
61
71
|
_TEXT_KEYS_UNDER = {'decisions': frozenset(('reason',)), 'adoptions': frozenset(('reason',)),
|
|
62
72
|
'adoption': frozenset(('reason',)), 'header': frozenset(('goal', 'criteria')),
|
|
73
|
+
'groups': frozenset(('goal', 'decision')),
|
|
63
74
|
'questions': frozenset(('why', 'options', 'default', 'answer')),
|
|
64
|
-
'parked': frozenset(('why', 'options', 'default', 'answer'))
|
|
75
|
+
'parked': frozenset(('why', 'options', 'default', 'answer')),
|
|
76
|
+
'proposals': frozenset(('summary', 'diff', 'reason'))}
|
|
65
77
|
|
|
66
78
|
|
|
67
79
|
def _enc(value):
|
|
@@ -121,7 +133,9 @@ class _Snapshot:
|
|
|
121
133
|
value = server.api_get(self.catalog, path)
|
|
122
134
|
if value is server.NO_ROUTE or value is None:
|
|
123
135
|
return None
|
|
124
|
-
|
|
136
|
+
# The group route returns the group at the root, so goal and decision blank the way they do
|
|
137
|
+
# under the run's `groups` list.
|
|
138
|
+
value = self.clean(value, 'groups' if _GROUP_DETAIL.search(path) else None)
|
|
125
139
|
size = len(json.dumps(value, ensure_ascii=False).encode('utf-8'))
|
|
126
140
|
if not required and ((cap and size > cap) or self.size + size > TOTAL_CAP):
|
|
127
141
|
self.omitted.append({'path': path, 'bytes': size, 'why': 'larger than 1 MB' if cap and size > cap else 'over the 25 MB total'})
|
|
@@ -186,7 +200,20 @@ def build(catalog, key, texts=False, paths=False, now=None):
|
|
|
186
200
|
tasks = [t for t in (detail.get('tasks') or []) if isinstance(t, dict) and t.get('id')]
|
|
187
201
|
for task in tasks:
|
|
188
202
|
snap.add(f"{base}/tasks/{_enc(task['id'])}")
|
|
189
|
-
|
|
203
|
+
# A group's review dispatch is not named on the run, only on its own detail. Snapshot that detail,
|
|
204
|
+
# and fold the dispatch into the execution list so its transcript is stored with the others.
|
|
205
|
+
extra_execs = []
|
|
206
|
+
for item in run.get('groups') or []:
|
|
207
|
+
if not isinstance(item, dict):
|
|
208
|
+
continue
|
|
209
|
+
gid = item.get('id')
|
|
210
|
+
if not isinstance(gid, str) or not re.fullmatch(r'[a-z0-9][a-z0-9-]{0,39}', gid):
|
|
211
|
+
continue
|
|
212
|
+
body = snap.add(f'{base}/groups/{_enc(gid)}')
|
|
213
|
+
execution = body.get('execution') if isinstance(body, dict) else None
|
|
214
|
+
if isinstance(execution, dict) and isinstance(execution.get('id'), str):
|
|
215
|
+
extra_execs.append(execution['id'])
|
|
216
|
+
names = sorted(set(_EXEC.findall(json.dumps(run))) | {name for name in extra_execs if _EXEC.fullmatch(name)})
|
|
190
217
|
for name in names:
|
|
191
218
|
snap.add(f'{base}/executions/{name}')
|
|
192
219
|
reviews = [r.get('name') for r in (run.get('final_reviews') or []) if isinstance(r, dict) and r.get('name')]
|