@giamme/forge 0.18.0 → 0.20.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 +49 -0
- package/README.md +1 -0
- package/SKILL.md +19 -2
- package/VERSION +1 -1
- package/docs/artifacts.md +25 -1
- package/docs/commands.md +217 -18
- package/docs/decomposed-runs.md +114 -1
- package/docs/development.md +2 -1
- package/docs/forge-ui.md +138 -18
- package/docs/memory.md +25 -4
- package/docs/models.md +8 -0
- package/docs/reviews.md +122 -0
- package/forge +26 -3
- package/package.json +2 -1
- package/references/dataset.md +20 -1
- package/references/decompose.md +641 -41
- package/references/harnesses.md +18 -3
- package/references/memory.md +30 -5
- 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-findings.py +675 -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-issues.py +228 -97
- 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 +711 -17
- package/scripts/forge-parallel.sh +721 -38
- 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 +417 -52
- package/scripts/forge-solo.sh +2 -0
- package/scripts/forge-sweep.py +199 -44
- 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_findings/__init__.py +17 -0
- package/scripts/forge_findings/apply.py +441 -0
- package/scripts/forge_findings/status.py +43 -0
- package/scripts/forge_findings/store.py +583 -0
- package/scripts/forge_findings/tags.py +53 -0
- package/scripts/forge_findings/triage.py +603 -0
- 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_identity.py +327 -0
- package/scripts/forge_memory_list.py +7 -3
- package/scripts/forge_owner.py +152 -0
- package/scripts/forge_side/__init__.py +228 -38
- package/ui/docs/api.md +303 -29
- package/ui/forge_ui/control.py +1018 -6
- 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/projects.py +209 -22
- 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/findingsactions.js +201 -0
- package/ui/forge_ui/static/groupsview.js +332 -0
- package/ui/forge_ui/static/index.html +3 -0
- package/ui/forge_ui/static/panel.js +127 -7
- package/ui/forge_ui/static/projectsview.js +764 -30
- 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 +138 -5
- package/ui/forge_ui/static/triageview.js +423 -0
- package/ui/forge_ui/static/worktreesview.js +233 -12
- package/ui/forge_ui/storage.py +14 -0
|
@@ -5,15 +5,25 @@
|
|
|
5
5
|
- `tasks/<id>/brief.json`: `{questions: [{id, text, why, options, default, scope: "task",
|
|
6
6
|
must_answer}], model, generated_at}`. `must_answer` survives only under the `gated` level.
|
|
7
7
|
- `tasks/<id>/brief.parked.json`: the same shape for questions whose scope is `wave` or
|
|
8
|
-
`plan`. Only task scope acts
|
|
9
|
-
`
|
|
8
|
+
`plan`. Only task scope acts, so wider scopes are parked whatever `brief_scope` says.
|
|
9
|
+
A wave question from a task that belongs to a group also stores `"group": "<gid>"`;
|
|
10
|
+
a plan question from such a task stores `"group": null`. A task in no group stores
|
|
11
|
+
neither key, so its parked file stays as it was.
|
|
12
|
+
|
|
13
|
+
When the task belongs to a group (`<plan>/groups.tsv`), the prompt names that group's
|
|
14
|
+
title, goal and the other tasks in it, and says what `wave` and `plan` mean for the
|
|
15
|
+
group. A task in no group gets the prompt it got before groups existed. A `wave` or
|
|
16
|
+
`plan` brief scope with no `groups.tsv` prints one note and continues; `brief.groups.noted`
|
|
17
|
+
keeps that note to once per plan. Nothing here acts on an answer.
|
|
10
18
|
|
|
11
19
|
A broken writer never holds a task: a reply that is not valid JSON, or has the wrong
|
|
12
20
|
shape, is retried once, and a second failure (or a failed dispatch) stores
|
|
13
21
|
`{"questions": [], "error": "<reason>"}` as `brief.json`.
|
|
14
22
|
|
|
15
23
|
`show` lists every question with its state: `open`, `answered` (`brief.answers.json`),
|
|
16
|
-
`late` (`brief.late.json`) or `possibly_stale` (a flag in brief.json).
|
|
24
|
+
`late` (`brief.late.json`) or `possibly_stale` (a flag in brief.json). A task with
|
|
25
|
+
`brief.affected` is marked `affected by <pid>`, and `flagged (already started)` when
|
|
26
|
+
that marker is `flag_only`. `--json` includes those rows as `affected`.
|
|
17
27
|
|
|
18
28
|
`answer` and `stale` (answers.py) write those. An answer given before the task starts
|
|
19
29
|
goes to `brief.answers.json`; one given after goes to `brief.late.json` and does not
|
|
@@ -38,6 +48,7 @@ SCRIPTS = Path(__file__).resolve().parent.parent
|
|
|
38
48
|
if str(SCRIPTS) not in sys.path:
|
|
39
49
|
sys.path.insert(0, str(SCRIPTS))
|
|
40
50
|
|
|
51
|
+
import forge_groups # noqa: E402
|
|
41
52
|
import forge_side # noqa: E402
|
|
42
53
|
|
|
43
54
|
MAX_QUESTIONS = 3
|
|
@@ -150,10 +161,76 @@ def _now() -> str:
|
|
|
150
161
|
|
|
151
162
|
# --- the prompt and the reply ----------------------------------------------------
|
|
152
163
|
|
|
164
|
+
def _task_group(plan, task_id):
|
|
165
|
+
"""The task's group, or None when it is in none (or groups.tsv cannot be read).
|
|
166
|
+
|
|
167
|
+
A broken groups.tsv must not hold the task: the writer then behaves as it does for a
|
|
168
|
+
task in no group.
|
|
169
|
+
"""
|
|
170
|
+
try:
|
|
171
|
+
return forge_groups.group_of(plan, task_id)
|
|
172
|
+
except (forge_groups.GroupError, OSError, UnicodeDecodeError):
|
|
173
|
+
return None
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _group_section(group, task: dict, tasks: list) -> str:
|
|
177
|
+
"""The group block that follows the task's own prompt.md and approach.md.
|
|
178
|
+
|
|
179
|
+
The goal line is left out when the goal is `-`: that cell means the group has none,
|
|
180
|
+
and the prompt does not invent a `(no goal)` line. An empty title stays as `-`, which
|
|
181
|
+
is the cell groups.tsv stores.
|
|
182
|
+
"""
|
|
183
|
+
by_id = {item['id']: item for item in tasks}
|
|
184
|
+
lines = ['Group %s: %s' % (group.id, group.title)]
|
|
185
|
+
if group.goal != '-':
|
|
186
|
+
lines.append('Goal: %s' % group.goal)
|
|
187
|
+
others = []
|
|
188
|
+
for member in group.members:
|
|
189
|
+
if member == task['id']:
|
|
190
|
+
continue
|
|
191
|
+
item = by_id.get(member)
|
|
192
|
+
title = (item['title'] if item else '') or '(no title)'
|
|
193
|
+
others.append('%s — %s' % (member, title))
|
|
194
|
+
if others:
|
|
195
|
+
lines.append('Other tasks in this group: %s' % ', '.join(others))
|
|
196
|
+
else:
|
|
197
|
+
lines.append('Other tasks in this group:')
|
|
198
|
+
return '\n'.join(lines) + '\n'
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
# The scope sentence is the only line that changes for a grouped task. The ungrouped
|
|
202
|
+
# wording stays the sentence the prompt had before groups, so that prompt is byte-identical.
|
|
203
|
+
_ASK = (
|
|
204
|
+
'## What to ask\n\n'
|
|
205
|
+
'Ask an open question only where a design choice or an ambiguity would make the '
|
|
206
|
+
'implementer guess. "Nothing to ask" is the expected answer for most tasks: when '
|
|
207
|
+
'the prompt and approach are clear, reply {"questions": []}. At most %d questions.\n\n'
|
|
208
|
+
'Each question is answered by a person before or while earlier tasks are built, so '
|
|
209
|
+
'make it short and answerable in a line, and give the options when there are a few.\n\n'
|
|
210
|
+
'## Reply format\n\n'
|
|
211
|
+
'Reply with JSON only, no prose and no code fence:\n\n'
|
|
212
|
+
'{"questions": [{"text": "...", "why": "...", "options": ["..."], "default": "...", '
|
|
213
|
+
'"scope": "task", "must_answer": false}]}\n\n'
|
|
214
|
+
'- text: the question.\n'
|
|
215
|
+
'- why: what depends on the answer.\n'
|
|
216
|
+
'- options: the plausible answers, or [].\n'
|
|
217
|
+
'- default: what the implementer will do if nobody answers.\n'
|
|
218
|
+
'%s'
|
|
219
|
+
'- must_answer: true only when the decision cannot be defaulted safely.\n')
|
|
220
|
+
_SCOPE_UNGROUPED = (
|
|
221
|
+
'- scope: "task" when only this task needs the answer, "wave" when the other tasks '
|
|
222
|
+
'that run alongside it do too, "plan" when the whole run does.\n')
|
|
223
|
+
_SCOPE_GROUPED = (
|
|
224
|
+
'- scope: "task" when only this task needs the answer, "wave" when the answer would '
|
|
225
|
+
'change how several tasks of this group are done, "plan" when the answer would add, '
|
|
226
|
+
'remove or split tasks, or change their order.\n')
|
|
227
|
+
|
|
228
|
+
|
|
153
229
|
def build_prompt(plan, task: dict, tasks: list, repo: str) -> str:
|
|
154
230
|
plan = Path(plan)
|
|
155
231
|
tdir = task_dir(plan, task['id'])
|
|
156
232
|
by_id = {item['id']: item for item in tasks}
|
|
233
|
+
group = _task_group(plan, task['id'])
|
|
157
234
|
parts = [
|
|
158
235
|
'You are preparing the open questions for ONE task of a multi-task coding run, '
|
|
159
236
|
'before an implementer starts it.\n'
|
|
@@ -165,6 +242,8 @@ def build_prompt(plan, task: dict, tasks: list, repo: str) -> str:
|
|
|
165
242
|
approach = _text(tdir / 'approach.md').strip()
|
|
166
243
|
if approach:
|
|
167
244
|
parts.append('### approach.md\n\n%s\n' % approach)
|
|
245
|
+
if group is not None:
|
|
246
|
+
parts.append(_group_section(group, task, tasks))
|
|
168
247
|
parts.append('### Its tasks.tsv row\n\n(id, deps, difficulty, files, dwarf, qa, title)\n\n%s\n' % task['row'])
|
|
169
248
|
parts.append('### All tasks in this run\n\n%s\n' % '\n'.join(
|
|
170
249
|
'- %s: %s' % (item['id'], item['title'] or '(no title)') for item in tasks))
|
|
@@ -175,24 +254,8 @@ def build_prompt(plan, task: dict, tasks: list, repo: str) -> str:
|
|
|
175
254
|
parts.append('#### %s\n\n%s\n' % (
|
|
176
255
|
dep['id'], forge_side.cap(_text(task_dir(plan, dep['id']) / 'prompt.md').strip(),
|
|
177
256
|
DEP_PROMPT_LIMIT)))
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
'Ask an open question only where a design choice or an ambiguity would make the '
|
|
181
|
-
'implementer guess. "Nothing to ask" is the expected answer for most tasks: when '
|
|
182
|
-
'the prompt and approach are clear, reply {"questions": []}. At most %d questions.\n\n'
|
|
183
|
-
'Each question is answered by a person before or while earlier tasks are built, so '
|
|
184
|
-
'make it short and answerable in a line, and give the options when there are a few.\n\n'
|
|
185
|
-
'## Reply format\n\n'
|
|
186
|
-
'Reply with JSON only, no prose and no code fence:\n\n'
|
|
187
|
-
'{"questions": [{"text": "...", "why": "...", "options": ["..."], "default": "...", '
|
|
188
|
-
'"scope": "task", "must_answer": false}]}\n\n'
|
|
189
|
-
'- text: the question.\n'
|
|
190
|
-
'- why: what depends on the answer.\n'
|
|
191
|
-
'- options: the plausible answers, or [].\n'
|
|
192
|
-
'- default: what the implementer will do if nobody answers.\n'
|
|
193
|
-
'- scope: "task" when only this task needs the answer, "wave" when the other tasks '
|
|
194
|
-
'that run alongside it do too, "plan" when the whole run does.\n'
|
|
195
|
-
'- must_answer: true only when the decision cannot be defaulted safely.\n' % MAX_QUESTIONS)
|
|
257
|
+
scope = _SCOPE_GROUPED if group is not None else _SCOPE_UNGROUPED
|
|
258
|
+
parts.append(_ASK % (MAX_QUESTIONS, scope))
|
|
196
259
|
return '\n'.join(parts)
|
|
197
260
|
|
|
198
261
|
|
|
@@ -333,13 +396,23 @@ def _task_lock(plan: Path, task: str):
|
|
|
333
396
|
|
|
334
397
|
|
|
335
398
|
def _record(plan: Path, task: str, model: str, level: str, questions, error) -> dict:
|
|
336
|
-
"""Store brief.json (and brief.parked.json) for one task and emit the events.
|
|
399
|
+
"""Store brief.json (and brief.parked.json) for one task and emit the events.
|
|
400
|
+
|
|
401
|
+
A parked question from a grouped task records `group`: the group id for `wave`, null
|
|
402
|
+
for `plan`. An ungrouped task's parked questions have no `group` key.
|
|
403
|
+
"""
|
|
337
404
|
stamp = _now()
|
|
405
|
+
group = _task_group(plan, task)
|
|
338
406
|
kept, parked = [], []
|
|
339
407
|
for number, question in enumerate((questions or [])[:MAX_QUESTIONS], 1):
|
|
340
408
|
entry = dict(question, id='q%d' % number)
|
|
341
409
|
entry['must_answer'] = bool(question['must_answer']) and level == 'gated'
|
|
342
|
-
|
|
410
|
+
if question['scope'] == 'task':
|
|
411
|
+
kept.append(entry)
|
|
412
|
+
else:
|
|
413
|
+
if group is not None:
|
|
414
|
+
entry['group'] = group.id if question['scope'] == 'wave' else None
|
|
415
|
+
parked.append(entry)
|
|
343
416
|
brief = {'questions': kept, 'model': model, 'generated_at': stamp}
|
|
344
417
|
if error:
|
|
345
418
|
brief['error'] = error
|
|
@@ -360,12 +433,70 @@ def _record(plan: Path, task: str, model: str, level: str, questions, error) ->
|
|
|
360
433
|
|
|
361
434
|
|
|
362
435
|
def _emit(plan: Path, task: str, question: dict, parked: bool) -> None:
|
|
363
|
-
"""One `brief_question` dataset event. Fail-open, like every other capture.
|
|
436
|
+
"""One `brief_question` dataset event. Fail-open, like every other capture.
|
|
437
|
+
|
|
438
|
+
`group` is set only for a parked question that names a group. A plan question, an
|
|
439
|
+
ungrouped question and a task question omit the field, so those events stay as they were.
|
|
440
|
+
"""
|
|
364
441
|
try:
|
|
365
442
|
from forge_dataset.capture import point
|
|
366
|
-
|
|
443
|
+
body = {
|
|
367
444
|
'task': str(task), 'qid': question['id'], 'scope': question['scope'],
|
|
368
|
-
'must_answer': question['must_answer'], 'parked': parked}
|
|
445
|
+
'must_answer': question['must_answer'], 'parked': parked}
|
|
446
|
+
if question.get('group'):
|
|
447
|
+
body['group'] = question['group']
|
|
448
|
+
point('brief_question', str(plan), str(task), body)
|
|
449
|
+
except Exception:
|
|
450
|
+
pass
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
# Said once per plan, when brief is on at wave or plan scope and the plan has no groups.
|
|
454
|
+
GROUPS_NOTE = (
|
|
455
|
+
'brief scope %s: no groups.tsv — run plan --groups waves, or let the planner write groups; '
|
|
456
|
+
'wave questions stay parked\n')
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def _note_missing_groups(plan: Path, scope: str) -> None:
|
|
460
|
+
"""One note when wave or plan scope has nothing to attach a wave question to.
|
|
461
|
+
|
|
462
|
+
The marker `brief.groups.noted` is created first, so a second writer, in this process
|
|
463
|
+
or another, does not say it again. The write itself is unchanged.
|
|
464
|
+
"""
|
|
465
|
+
if scope not in ('wave', 'plan'):
|
|
466
|
+
return
|
|
467
|
+
if (plan / 'groups.tsv').is_file():
|
|
468
|
+
return
|
|
469
|
+
marker = plan / 'brief.groups.noted'
|
|
470
|
+
try:
|
|
471
|
+
fd = os.open(marker, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
|
|
472
|
+
except FileExistsError:
|
|
473
|
+
return
|
|
474
|
+
except OSError:
|
|
475
|
+
sys.stderr.write(GROUPS_NOTE % scope)
|
|
476
|
+
sys.stderr.flush()
|
|
477
|
+
return
|
|
478
|
+
try:
|
|
479
|
+
os.write(fd, (scope + '\n').encode())
|
|
480
|
+
except OSError:
|
|
481
|
+
pass
|
|
482
|
+
finally:
|
|
483
|
+
os.close(fd)
|
|
484
|
+
sys.stderr.write(GROUPS_NOTE % scope)
|
|
485
|
+
sys.stderr.flush()
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def note_missing_groups(plan) -> None:
|
|
489
|
+
"""Say the missing-groups note now, on this process's stderr, if it is due.
|
|
490
|
+
|
|
491
|
+
`forge-parallel.sh` calls this before it starts the writer in the background (advisory and
|
|
492
|
+
gated), whose output goes to brief.out where nobody would read the note. The marker then
|
|
493
|
+
keeps the writer quiet. Never raises: a note is not worth stopping a run for.
|
|
494
|
+
"""
|
|
495
|
+
try:
|
|
496
|
+
plan = Path(plan)
|
|
497
|
+
found = forge_side.settings(plan)['brief']
|
|
498
|
+
if found['level'] != 'off':
|
|
499
|
+
_note_missing_groups(plan, found['scope'])
|
|
369
500
|
except Exception:
|
|
370
501
|
pass
|
|
371
502
|
|
|
@@ -388,6 +519,9 @@ def write(plan, task=None, jobs=DEFAULT_JOBS, force=False, timeout=900, progress
|
|
|
388
519
|
order they were dispatched: status is `written`, `error` (an empty brief.json with the
|
|
389
520
|
error recorded) or `skipped` (with a reason: `exists`, `cap`, ...). Raises `NotAPlan`,
|
|
390
521
|
`BriefOff` (brief is off, or `allowed` refuses for a plan-wide reason) and `UnknownTask`.
|
|
522
|
+
|
|
523
|
+
With brief scope `wave` or `plan` and no `groups.tsv`, prints one note to stderr and
|
|
524
|
+
continues. `brief.groups.noted` keeps the note to once per plan.
|
|
391
525
|
"""
|
|
392
526
|
plan, found = _guard(plan)
|
|
393
527
|
tasks = read_tasks(plan)
|
|
@@ -396,6 +530,8 @@ def write(plan, task=None, jobs=DEFAULT_JOBS, force=False, timeout=900, progress
|
|
|
396
530
|
ok, reason = forge_side.allowed('brief', plan)
|
|
397
531
|
if not ok and reason != 'cap':
|
|
398
532
|
raise BriefOff(reason)
|
|
533
|
+
# plan resolves these flags in the shell, before this writer starts. Say it here, once.
|
|
534
|
+
_note_missing_groups(plan, found['scope'])
|
|
399
535
|
chosen = [item for item in ordered(plan, tasks) if task is None or item['id'] == task]
|
|
400
536
|
spec, level = found['model'], found['level']
|
|
401
537
|
repo = _text(plan / 'repo').strip()
|
|
@@ -508,17 +644,41 @@ def _questions(data) -> list:
|
|
|
508
644
|
return [q for q in items if isinstance(q, dict)] if isinstance(items, list) else []
|
|
509
645
|
|
|
510
646
|
|
|
647
|
+
def _affected_rows(plan, tasks, only=None) -> list:
|
|
648
|
+
"""`brief.affected` markers in tasks.tsv order: `{task, pid, reason, t, flag_only}`.
|
|
649
|
+
|
|
650
|
+
A task with no brief.json is included when it has a marker (an added task that was
|
|
651
|
+
marked and not regenerated yet). A marker that is not the object `apply` writes is skipped.
|
|
652
|
+
"""
|
|
653
|
+
rows = []
|
|
654
|
+
for item in tasks:
|
|
655
|
+
if only is not None and item['id'] != only:
|
|
656
|
+
continue
|
|
657
|
+
data = _json(task_dir(plan, item['id']) / 'brief.affected')
|
|
658
|
+
if not isinstance(data, dict):
|
|
659
|
+
continue
|
|
660
|
+
pid, reason = data.get('pid'), data.get('reason')
|
|
661
|
+
if not isinstance(pid, str) or not pid or not isinstance(reason, str) or not reason:
|
|
662
|
+
continue
|
|
663
|
+
rows.append({'task': item['id'], 'pid': pid, 'reason': reason, 't': data.get('t'),
|
|
664
|
+
'flag_only': data.get('flag_only') is True})
|
|
665
|
+
return rows
|
|
666
|
+
|
|
667
|
+
|
|
511
668
|
def collect(plan, task=None) -> dict:
|
|
512
669
|
"""Every question of the plan (or one task) with its state, flagged open ones first.
|
|
513
670
|
|
|
514
|
-
`{questions: [...], parked: [...], errors: [{task, error}]}`. A question
|
|
515
|
-
`task`, `id`, `text`, `why`, `options`, `default`, `scope`, `must_answer`, `state`
|
|
516
|
-
and, once answered, `answer`.
|
|
671
|
+
`{questions: [...], parked: [...], errors: [{task, error}], affected: [...]}`. A question
|
|
672
|
+
carries `task`, `id`, `text`, `why`, `options`, `default`, `scope`, `must_answer`, `state`
|
|
673
|
+
and, once answered, `answer`. A parked question stores `group` when its file has that
|
|
674
|
+
key: the group id, or null for a plan question. `affected` is the `brief.affected` markers
|
|
675
|
+
(`task`, `pid`, `reason`, `t`, `flag_only`), in tasks.tsv order.
|
|
517
676
|
"""
|
|
518
677
|
plan, _ = _guard(plan)
|
|
519
678
|
tasks = read_tasks(plan)
|
|
520
679
|
if task is not None and task not in {item['id'] for item in tasks}:
|
|
521
680
|
raise UnknownTask(task)
|
|
681
|
+
affected = _affected_rows(plan, tasks, task)
|
|
522
682
|
questions, parked, errors = [], [], []
|
|
523
683
|
for item in ordered(plan, tasks):
|
|
524
684
|
if task is not None and item['id'] != task:
|
|
@@ -547,41 +707,125 @@ def collect(plan, task=None) -> dict:
|
|
|
547
707
|
row['state'] = 'open'
|
|
548
708
|
questions.append(row)
|
|
549
709
|
for q in _questions(_json(tdir / 'brief.parked.json')):
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
710
|
+
row = {'task': item['id'], 'id': str(q.get('id', '')), 'text': q.get('text', ''),
|
|
711
|
+
'why': q.get('why', ''), 'options': q.get('options') or [],
|
|
712
|
+
'default': q.get('default', ''), 'scope': q.get('scope', 'wave'),
|
|
713
|
+
'must_answer': bool(q.get('must_answer')), 'state': 'parked'}
|
|
714
|
+
if 'group' in q:
|
|
715
|
+
row['group'] = q.get('group')
|
|
716
|
+
parked.append(row)
|
|
554
717
|
|
|
555
718
|
def rank(row):
|
|
556
719
|
if row['state'] in ('open', 'possibly_stale'):
|
|
557
720
|
return 0 if row['must_answer'] else 1
|
|
558
721
|
return 2
|
|
559
722
|
questions.sort(key=rank) # stable: wave order and question order inside a rank
|
|
560
|
-
return {'questions': questions, 'parked': parked, 'errors': errors}
|
|
723
|
+
return {'questions': questions, 'parked': parked, 'errors': errors, 'affected': affected}
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
def _question_lines(row) -> list:
|
|
727
|
+
flag = ' [must answer]' if row['must_answer'] else ''
|
|
728
|
+
out = ['%s/%s %s%s' % (row['task'], row['id'], row['state'], flag), ' %s' % row['text']]
|
|
729
|
+
if row['options']:
|
|
730
|
+
out.append(' options: %s' % ' | '.join(row['options']))
|
|
731
|
+
if row['default']:
|
|
732
|
+
out.append(' default: %s' % row['default'])
|
|
733
|
+
if row.get('answer'):
|
|
734
|
+
out.append(' answer: %s (%s)' % (row['answer'].get('text', ''), row['answer'].get('actor', '')))
|
|
735
|
+
return out
|
|
561
736
|
|
|
562
737
|
|
|
563
|
-
def
|
|
738
|
+
def _group_titles(plan) -> dict:
|
|
739
|
+
if not plan:
|
|
740
|
+
return {}
|
|
741
|
+
try:
|
|
742
|
+
return {g.id: g.title for g in forge_groups.load(plan)}
|
|
743
|
+
except (forge_groups.GroupError, OSError, UnicodeDecodeError):
|
|
744
|
+
return {}
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
def _grouped_parked_lines(rows, plan) -> list:
|
|
748
|
+
"""Parked questions that carry a `group` key, listed by group, then under `Plan:`.
|
|
749
|
+
|
|
750
|
+
A wave question is `Group <gid> (<title>): <question>`, with the asking task on the
|
|
751
|
+
next line. The title comes from groups.tsv and the parentheses are left off when it
|
|
752
|
+
is `-` or the group is gone. A plan question (`group` null) goes under `Plan:`.
|
|
753
|
+
A question with no `group` key, in a plan that also has grouped ones, stays in the
|
|
754
|
+
old parked block so an older file is still shown.
|
|
755
|
+
"""
|
|
756
|
+
titles = _group_titles(plan)
|
|
757
|
+
order, by, plans, loose = [], {}, [], []
|
|
758
|
+
for row in rows:
|
|
759
|
+
if 'group' not in row:
|
|
760
|
+
loose.append(row)
|
|
761
|
+
continue
|
|
762
|
+
gid = row.get('group')
|
|
763
|
+
if not isinstance(gid, str) or not gid:
|
|
764
|
+
plans.append(row)
|
|
765
|
+
continue
|
|
766
|
+
if gid not in by:
|
|
767
|
+
order.append(gid)
|
|
768
|
+
by[gid] = []
|
|
769
|
+
by[gid].append(row)
|
|
770
|
+
lines = []
|
|
771
|
+
for gid in order:
|
|
772
|
+
title = titles.get(gid, '-')
|
|
773
|
+
head = 'Group %s (%s)' % (gid, title) if title and title != '-' else 'Group %s' % gid
|
|
774
|
+
for row in by[gid]:
|
|
775
|
+
lines.append('%s: %s' % (head, row['text']))
|
|
776
|
+
flag = ' [must answer]' if row['must_answer'] else ''
|
|
777
|
+
lines.append(' %s/%s %s%s' % (row['task'], row['id'], row['state'], flag))
|
|
778
|
+
if row['options']:
|
|
779
|
+
lines.append(' options: %s' % ' | '.join(row['options']))
|
|
780
|
+
if row['default']:
|
|
781
|
+
lines.append(' default: %s' % row['default'])
|
|
782
|
+
if plans:
|
|
783
|
+
lines.append('Plan:')
|
|
784
|
+
for row in plans:
|
|
785
|
+
lines.extend(_question_lines(row))
|
|
786
|
+
if loose:
|
|
787
|
+
lines.append('Parked (wider scope):')
|
|
788
|
+
for row in loose:
|
|
789
|
+
lines.extend(_question_lines(row))
|
|
790
|
+
return lines
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
def _affected_lines(rows) -> list:
|
|
794
|
+
"""One line per marked task: `a affected by p3`, plus `flagged (already started)`."""
|
|
564
795
|
lines = []
|
|
796
|
+
for row in rows:
|
|
797
|
+
line = '%s affected by %s' % (row['task'], row['pid'])
|
|
798
|
+
if row.get('flag_only'):
|
|
799
|
+
line += ' flagged (already started)'
|
|
800
|
+
lines.append(line)
|
|
801
|
+
return lines
|
|
802
|
+
|
|
565
803
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
lines.append(' default: %s' % row['default'])
|
|
574
|
-
if row.get('answer'):
|
|
575
|
-
lines.append(' answer: %s (%s)' % (row['answer'].get('text', ''), row['answer'].get('actor', '')))
|
|
804
|
+
def render(found: dict, plan=None) -> str:
|
|
805
|
+
"""Text for `forge brief show`. `plan` is where group titles are read.
|
|
806
|
+
|
|
807
|
+
A plan whose parked questions have no `group` key renders as it did before groups.
|
|
808
|
+
Marked tasks are listed after the questions (`affected by <pid>`).
|
|
809
|
+
"""
|
|
810
|
+
lines = []
|
|
576
811
|
for row in found['questions']:
|
|
577
|
-
|
|
578
|
-
|
|
812
|
+
lines.extend(_question_lines(row))
|
|
813
|
+
parked = found['parked']
|
|
814
|
+
if parked:
|
|
579
815
|
lines.append('')
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
816
|
+
if any('group' in row for row in parked):
|
|
817
|
+
lines.extend(_grouped_parked_lines(parked, plan))
|
|
818
|
+
else:
|
|
819
|
+
lines.append('Parked (wider scope):')
|
|
820
|
+
for row in parked:
|
|
821
|
+
lines.extend(_question_lines(row))
|
|
583
822
|
for err in found['errors']:
|
|
584
823
|
lines.append('%s: the question writer failed: %s' % (err['task'], err['error']))
|
|
824
|
+
affected = _affected_lines(found.get('affected') or [])
|
|
825
|
+
if affected:
|
|
826
|
+
if lines:
|
|
827
|
+
lines.append('')
|
|
828
|
+
lines.extend(affected)
|
|
585
829
|
if not lines:
|
|
586
830
|
lines.append('no questions')
|
|
587
831
|
return '\n'.join(lines) + '\n'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Record brief answers, and flag questions a merge may have made stale (#135).
|
|
1
|
+
"""Record brief answers, and flag questions a merge may have made stale (#135, #136).
|
|
2
2
|
|
|
3
3
|
`answer` writes `tasks/<id>/brief.answers.json` as `{qid: {text, actor, t}}` while the
|
|
4
4
|
task is still PENDING and has no `attempts.tsv` row. Once it is past starting, nothing
|
|
@@ -7,6 +7,13 @@ prints the `tasks.tsv` row and the `prompt.md` a follow-up needs, then the
|
|
|
7
7
|
`forge control add` line that queues that row. `add` only takes the plan and a task id
|
|
8
8
|
that is already in `tasks.tsv`, and the prompt is what carries the answer.
|
|
9
9
|
|
|
10
|
+
A parked question (`brief.parked.json`: scope `wave` or `plan`) is answerable only when the
|
|
11
|
+
plan's brief scope is at least as wide as the question's: `--brief-scope wave` takes wave
|
|
12
|
+
questions, `plan` takes both, and the default `task` takes neither (the question id is then
|
|
13
|
+
unknown, as it always was). Such an answer goes to `brief.parked.answers.json` as `{qid: {text,
|
|
14
|
+
actor, t}}`, whatever the task's status, and the command prints `forge brief propose`. Answering
|
|
15
|
+
never changes a prompt: `proposals.py` turns the answer into a diff that waits for approval.
|
|
16
|
+
|
|
10
17
|
`stale` runs after a task has merged. When that merge's `changes.diff` (or, if the diff
|
|
11
18
|
is gone, the task's attempt events) names a file outside the task's declared files,
|
|
12
19
|
every open question of a direct dependent that has not started gets `possibly_stale:
|
|
@@ -25,6 +32,7 @@ import unicodedata
|
|
|
25
32
|
from pathlib import Path
|
|
26
33
|
|
|
27
34
|
import forge_brief
|
|
35
|
+
import forge_side
|
|
28
36
|
|
|
29
37
|
# Bytes, matching the cap forge-prompt.py uses when it quotes an answer.
|
|
30
38
|
ANSWER_CAP = 4 * 1024
|
|
@@ -125,6 +133,36 @@ def question_ids(plan, task) -> list:
|
|
|
125
133
|
return found
|
|
126
134
|
|
|
127
135
|
|
|
136
|
+
SCOPE_RANK = {'task': 0, 'wave': 1, 'plan': 2}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def parked_questions(plan, task) -> dict:
|
|
140
|
+
"""`{qid: question}` for the task's parked questions, in file order. Every parked question, answerable or not."""
|
|
141
|
+
data = forge_brief._json(forge_brief.task_dir(plan, task) / 'brief.parked.json')
|
|
142
|
+
found = {}
|
|
143
|
+
for question in forge_brief._questions(data if isinstance(data, dict) else None):
|
|
144
|
+
qid = question.get('id')
|
|
145
|
+
if isinstance(qid, str) and qid:
|
|
146
|
+
found[qid] = question
|
|
147
|
+
return found
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def answerable_parked(plan, task) -> dict:
|
|
151
|
+
"""The parked questions an answer may be recorded for under the plan's brief scope.
|
|
152
|
+
|
|
153
|
+
A question of scope `wave` or `plan` is answerable when the brief scope is at that scope
|
|
154
|
+
or wider. With brief scope `task` (the default) none is.
|
|
155
|
+
"""
|
|
156
|
+
reach = SCOPE_RANK.get(forge_side.settings(plan)['brief']['scope'], 0)
|
|
157
|
+
return {qid: question for qid, question in parked_questions(plan, task).items()
|
|
158
|
+
if SCOPE_RANK.get(question.get('scope'), 0) >= 1
|
|
159
|
+
and SCOPE_RANK[question.get('scope')] <= reach}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def propose_line(plan, task, qid) -> str:
|
|
163
|
+
return 'forge brief propose %s %s %s' % (shlex.quote(str(plan)), shlex.quote(task), shlex.quote(qid))
|
|
164
|
+
|
|
165
|
+
|
|
128
166
|
def clean_answer(text) -> str:
|
|
129
167
|
"""Drop control characters, then keep the leading 4 KB of what remains."""
|
|
130
168
|
if text is None:
|
|
@@ -284,9 +322,11 @@ def _emit(plan, task, qid, actor, late) -> None:
|
|
|
284
322
|
def answer(plan, task, qid, text=None, actor='cli', file=None) -> dict:
|
|
285
323
|
"""Record one answer. Raises `Usage`, `NotAPlan`, `NoSuchTask` or `NoSuchQuestion`.
|
|
286
324
|
|
|
287
|
-
Returns `{task, qid, late, text, message}`. `message` is what the command prints.
|
|
325
|
+
Returns `{task, qid, late, parked, text, message}`. `message` is what the command prints.
|
|
288
326
|
A late answer's message gives the tasks.tsv row and the prompt text, then the
|
|
289
|
-
`forge control add` line that queues that follow-up once a scheduler is live.
|
|
327
|
+
`forge control add` line that queues that follow-up once a scheduler is live. An answer to
|
|
328
|
+
a parked question is never late: it is stored in `brief.parked.answers.json` and the
|
|
329
|
+
message names the `forge brief propose` command.
|
|
290
330
|
"""
|
|
291
331
|
if file is not None and text is not None:
|
|
292
332
|
raise Usage('give the answer as text or --file, not both')
|
|
@@ -302,18 +342,25 @@ def answer(plan, task, qid, text=None, actor='cli', file=None) -> dict:
|
|
|
302
342
|
if task not in ids:
|
|
303
343
|
raise NoSuchTask(task, ids)
|
|
304
344
|
valid = question_ids(plan, task)
|
|
305
|
-
if qid not in valid:
|
|
306
|
-
raise NoSuchQuestion(task, qid, valid)
|
|
345
|
+
if qid not in valid and qid not in answerable_parked(plan, task):
|
|
346
|
+
raise NoSuchQuestion(task, qid, valid + list(answerable_parked(plan, task)))
|
|
307
347
|
tdir = forge_brief.task_dir(plan, task)
|
|
308
348
|
with forge_brief._task_lock(plan, task):
|
|
309
349
|
# The brief may have been regenerated while this answer waited for the lock.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
350
|
+
valid = question_ids(plan, task)
|
|
351
|
+
parked = qid not in valid
|
|
352
|
+
if parked and qid not in answerable_parked(plan, task):
|
|
353
|
+
raise NoSuchQuestion(task, qid, valid + list(answerable_parked(plan, task)))
|
|
354
|
+
late = False if parked else past_start(plan, task)
|
|
313
355
|
record = {'text': cleaned, 'actor': who, 't': time.time()}
|
|
314
|
-
|
|
315
|
-
previous = _put(
|
|
356
|
+
name = 'brief.parked.answers.json' if parked else ('brief.late.json' if late else 'brief.answers.json')
|
|
357
|
+
previous = _put(tdir / name, qid, record)
|
|
316
358
|
_log(plan, who, task, qid, cleaned, previous, late)
|
|
359
|
+
if parked:
|
|
360
|
+
message = '%s/%s answered (%s scope, parked); nothing changes until you propose and approve a diff\n%s\n' % (
|
|
361
|
+
task, qid, answerable_parked(plan, task).get(qid, {}).get('scope', 'wave'),
|
|
362
|
+
propose_line(plan, task, qid))
|
|
363
|
+
return {'task': task, 'qid': qid, 'late': False, 'parked': True, 'text': cleaned, 'message': message}
|
|
317
364
|
if late:
|
|
318
365
|
source = next(item for item in tasks if item['id'] == task)
|
|
319
366
|
follow = _follow_up_id(tasks, task, qid)
|
|
@@ -321,7 +368,7 @@ def answer(plan, task, qid, text=None, actor='cli', file=None) -> dict:
|
|
|
321
368
|
_question_text(plan, task, qid), cleaned)
|
|
322
369
|
else:
|
|
323
370
|
message = '%s/%s answered\n' % (task, qid)
|
|
324
|
-
return {'task': task, 'qid': qid, 'late': late, 'text': cleaned, 'message': message}
|
|
371
|
+
return {'task': task, 'qid': qid, 'late': late, 'parked': False, 'text': cleaned, 'message': message}
|
|
325
372
|
|
|
326
373
|
|
|
327
374
|
# --- stale -----------------------------------------------------------------------
|