@giamme/forge 0.13.0 → 0.13.1
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 +11 -0
- package/VERSION +1 -1
- package/docs/forge-ui.md +7 -1
- package/package.json +1 -1
- package/references/decision-models.md +5 -1
- package/scripts/forge-lib-plans.sh +5 -0
- package/scripts/forge-parallel.sh +2 -0
- package/scripts/forge-solo.sh +1 -0
- package/scripts/forge-ui-options.sh +25 -0
- package/scripts/forge_dataset/export.py +87 -41
- package/scripts/forge_decide/budget.py +39 -8
- package/scripts/forge_decide/doctor.py +49 -0
- package/ui/docs/api.md +32 -7
- package/ui/forge_ui/control.py +11 -3
- package/ui/forge_ui/models.py +16 -16
- package/ui/forge_ui/reader.py +45 -7
- package/ui/forge_ui/repos.py +428 -0
- package/ui/forge_ui/static/app.js +22 -3
- package/ui/forge_ui/static/cloudmodel.js +8 -5
- package/ui/forge_ui/static/modelstats.js +12 -8
- package/ui/forge_ui/static/runmodel.js +25 -6
- package/ui/forge_ui/static/settings.js +147 -29
- package/ui/forge_ui/static/style.css +38 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ All notable changes to this project are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and versions follow the format `{major}.{minor}[.{patch}]` ([...] parts appear only when non-zero).
|
|
7
7
|
|
|
8
|
+
## [0.13.1] - 2026-10-30
|
|
9
|
+
|
|
10
|
+
Runs started from a git worktree now sit under their repository in forge-ui, showing the worktree and branch they started in. Also exact decision-model spend caps, and the right gate on each exported review.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Decision-model spend caps: token caps compare exactly, a cost that overflowed to infinity counts as reaching the USD caps, and `forge decide doctor` names a provider whose price is unusable (`bad-price`).
|
|
15
|
+
- `forge dataset export` gives each review the gate decision of its own QA execution: a review that ended in an outage before a QA-only resume no longer inherits the gate of the review the attempt ended on, and separate runs that met the same diff still export as one review case.
|
|
16
|
+
- forge-ui groups runs by repository: a run started in any worktree of a repository joins that repository's group, also after the worktree is removed, and shows the worktree and branch it started in. New runs record `repo.identity` (root, worktree, branch); older runs are matched by their base commit. `/api/runs` carries `repo_root`, `repo_worktree` and `repo_branch`, and per-repository settings resolve against the repository rather than the worktree.
|
|
17
|
+
- forge-ui Settings: the repository picker lists runs by repository with each run's worktree and branch, works from the keyboard (arrow keys, Enter, Escape, typing), and the page names the directory the configuration was actually read from.
|
|
18
|
+
|
|
8
19
|
## [0.13] - 2026-10-30
|
|
9
20
|
|
|
10
21
|
Decision-model gates are now yours to set, off, shadow or on, per user or per repository with `forge decide`, and when on they act: drift and forward edit the plan, prompt and coverage send it back to the planner, and five new gates bounce unaddressed retries, read the implementer's final message, find the merge that broke verification and triage leftover findings. QA verdicts now follow a P2 blocking threshold in both directions, and a retry can continue the implementer's own session.
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.13
|
|
1
|
+
0.13.1
|
package/docs/forge-ui.md
CHANGED
|
@@ -8,6 +8,9 @@ run in one full-screen view, grouped by project, in five layouts (helix, sphere,
|
|
|
8
8
|
timeline, constellation), filtered down to exactly the runs you want; drag any run anywhere
|
|
9
9
|
and the cloud remembers it.
|
|
10
10
|
|
|
11
|
+
Runs are grouped by repository. A run started in any worktree of a repository shares that
|
|
12
|
+
repository's group, and each run shows the worktree and branch it started in.
|
|
13
|
+
|
|
11
14
|
<p align="center">
|
|
12
15
|
<img src="../ui/docs/media/cloud.webp" width="880" alt="The run cloud: about seventy runs as blocks in five project spirals, orbited, then laid out as galaxies and as a timeline with one lane per project.">
|
|
13
16
|
</p>
|
|
@@ -133,7 +136,10 @@ indistinguishable from the same command typed in a terminal, except that `contro
|
|
|
133
136
|
out. Anything that is not the run's own, or has uncommitted changes, is listed and left alone.
|
|
134
137
|
- **Settings:** every config source in one view (`forge config show`) and edits for the
|
|
135
138
|
per-repo ones (`repo.verify`, `repo.setup`, `repo.verify-subset`, and Jev on or off). The
|
|
136
|
-
registry stays read-only: the skill directory is often a live symlink to a checkout.
|
|
139
|
+
registry stays read-only: the skill directory is often a live symlink to a checkout. You pick
|
|
140
|
+
the repository through one of its runs, from a list grouped by repository that shows each
|
|
141
|
+
run's worktree and branch (arrow keys and typing work in it), and the page names the
|
|
142
|
+
directory the configuration was read from.
|
|
137
143
|
|
|
138
144
|
Writing is protected, because anything that can reach the server could otherwise change your
|
|
139
145
|
runs. The server makes a random token each time it starts and puts it in the page it serves;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giamme/forge",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "Multi-model coding with a reviewer that reads the code: plan, build in parallel worktrees, review every real diff, merge only what passes.",
|
|
5
5
|
"keywords": ["claude-code", "codex", "opencode", "agent-skill", "code-review", "multi-model"],
|
|
6
6
|
"license": "MIT",
|
|
@@ -370,7 +370,11 @@ the measured default), `shadowed` (the user file wins over the repo), `privacy-f
|
|
|
370
370
|
Problems: `retired-threshold`, `unknown-provider` (a gate names a provider that is not
|
|
371
371
|
configured), `unused-provider`, `misplaced` (providers or a daily budget in a repo file, or
|
|
372
372
|
`privacy` in the user file), `key-file` (missing, or not mode `0600`), `not-migrated`
|
|
373
|
-
(`jev.json` exists and `decide.json` does not), `config-error
|
|
373
|
+
(`jev.json` exists and `decide.json` does not), `config-error`, `bad-price` (a stored
|
|
374
|
+
`price_usd_per_mtok` is not a finite number above zero, so it is ignored and that
|
|
375
|
+
provider's spend does not count toward a USD cap). A non-finite price is reported as
|
|
376
|
+
the string `Infinity`, `-Infinity` or `NaN`, including when it sits inside a list or
|
|
377
|
+
object, so `doctor --json` is standard JSON.
|
|
374
378
|
|
|
375
379
|
`--live` sends one fixed synthetic request, with no repo data, to each configured provider.
|
|
376
380
|
It is the only `forge decide` subcommand that uses the network, and it is skipped when the
|
|
@@ -500,6 +500,9 @@ Retry or accept them (or split them off into their own plan) first." 3
|
|
|
500
500
|
for p in "${SRC[@]}"; do awk -F'\t' '!/^#/ && NF' "$p/tasks.tsv"; done
|
|
501
501
|
} > "$tsv" || ok=0
|
|
502
502
|
printf '%s\n' "$repo_text" > "$NEW/repo" || ok=0
|
|
503
|
+
# The same repository as the first source, so its identity carries over (none when it has none).
|
|
504
|
+
# Best effort: a copy that fails leaves no file and never fails the combine.
|
|
505
|
+
[ ! -f "${SRC[0]}/repo.identity" ] || cp -p "${SRC[0]}/repo.identity" "$NEW/repo.identity" 2>/dev/null || rm -f "$NEW/repo.identity"
|
|
503
506
|
printf '%s\n' "$NEWRID" > "$NEW/run_id" || ok=0
|
|
504
507
|
printf '%s\n' "$NEWWTR" > "$NEW/wt_root" || ok=0
|
|
505
508
|
git -C "$NEWINT" rev-parse HEAD > "$NEW/accepted.integration" || ok=0
|
|
@@ -750,6 +753,8 @@ except Exception:
|
|
|
750
753
|
}' "$T"
|
|
751
754
|
} > "$NEW/tasks.tsv" || ok=0
|
|
752
755
|
printf '%s\n' "$repo_text" > "$NEW/repo" || ok=0
|
|
756
|
+
# Best effort, as in combine: a copy that fails leaves no file and never fails the split.
|
|
757
|
+
[ ! -f "$PLAN/repo.identity" ] || cp -p "$PLAN/repo.identity" "$NEW/repo.identity" 2>/dev/null || rm -f "$NEW/repo.identity"
|
|
753
758
|
printf '%s\n' "$NEWRID" > "$NEW/run_id" || ok=0
|
|
754
759
|
printf '%s\n' "$NEWWTR" > "$NEW/wt_root" || ok=0
|
|
755
760
|
printf '%s\n' "$acc" > "$NEW/accepted.integration" || ok=0
|
|
@@ -274,6 +274,8 @@ do_plan() {
|
|
|
274
274
|
fi
|
|
275
275
|
[ -s "$PLAN/repo" ] || die "plan needs --repo the first time"
|
|
276
276
|
REPO="$(cat "$PLAN/repo")"
|
|
277
|
+
# The repository the checkout belongs to, recorded once: a plan that has none gets one now.
|
|
278
|
+
forge_repo_identity "$REPO" "$PLAN"
|
|
277
279
|
# Before any decision-model step: the privacy floor and the run budget read these.
|
|
278
280
|
[ "$JEV_OPTS" = 1 ] && forge_decide_env "$REPO" "$PLAN"
|
|
279
281
|
[ -s "$PLAN/run_id" ] || basename "$PLAN" | sed 's/^forge-//' > "$PLAN/run_id"
|
package/scripts/forge-solo.sh
CHANGED
|
@@ -200,6 +200,7 @@ fi
|
|
|
200
200
|
|
|
201
201
|
# The dispatches see a review snapshot, not the repo, so the run dir names it for the dataset.
|
|
202
202
|
[ "$DRY" = 1 ] || printf '%s\n' "$REPO" > "$RUN/repo"
|
|
203
|
+
[ "$DRY" = 1 ] || forge_repo_identity "$REPO" "$RUN"
|
|
203
204
|
# Every real run, --ui or not: forge-ui's view of this repo's runs reads the registry.
|
|
204
205
|
[ "$DRY" = 1 ] || forge_ui_register "$RUN"
|
|
205
206
|
# Recorded before any dispatch: forge-ui opens this dir immediately, and a re-run
|
|
@@ -40,3 +40,28 @@ forge_ui_register() {
|
|
|
40
40
|
python3 -I "$SKILL_DIR/scripts/forge_registry.py" register "$1" </dev/null >/dev/null 2>&1 || true
|
|
41
41
|
return 0
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
# forge_repo_identity CHECKOUT DIR — write DIR/repo.identity, the repository CHECKOUT belongs to:
|
|
45
|
+
# {"root", "worktree", "branch"}. root is the main working tree, the same for the main checkout
|
|
46
|
+
# and every linked worktree; worktree is CHECKOUT's physical path when it differs from root, else
|
|
47
|
+
# null; branch is its branch, null when HEAD is detached. It names the repository after a
|
|
48
|
+
# worktree is removed, which the path in `repo` cannot. Written once, at creation: an existing
|
|
49
|
+
# file stays.
|
|
50
|
+
# Best effort like forge_ui_register: a failure leaves no file, and this always returns 0 and
|
|
51
|
+
# prints nothing. Callers skip it in a --dry-run.
|
|
52
|
+
forge_repo_identity() {
|
|
53
|
+
local checkout="${1:-}" dir="${2:-}" root phys rootphys worktree="" branch tmp
|
|
54
|
+
[ -n "$dir" ] && [ ! -e "$dir/repo.identity" ] || return 0
|
|
55
|
+
root="$(git -C "$checkout" worktree list --porcelain 2>/dev/null | awk '/^worktree /{ sub(/^worktree /, ""); print; exit }')"
|
|
56
|
+
[ -n "$root" ] || return 0
|
|
57
|
+
phys="$(cd "$checkout" 2>/dev/null && pwd -P)" || return 0
|
|
58
|
+
rootphys="$(cd "$root" 2>/dev/null && pwd -P)" || return 0
|
|
59
|
+
[ "$phys" = "$rootphys" ] || worktree="$phys"
|
|
60
|
+
branch="$(git -C "$checkout" symbolic-ref --short -q HEAD 2>/dev/null)"
|
|
61
|
+
tmp="$dir/repo.identity.$$.tmp"
|
|
62
|
+
# The values go in as arguments, never into the code. The redirect and mv sit in the group,
|
|
63
|
+
# so a refused write is silent too.
|
|
64
|
+
{ python3 -I -c 'import json, sys; r, w, b = sys.argv[1:4]; print(json.dumps({"root": r, "worktree": w or None, "branch": b or None}, separators=(",", ":")))' "$root" "$worktree" "$branch" > "$tmp" \
|
|
65
|
+
&& mv "$tmp" "$dir/repo.identity"; } 2>/dev/null || rm -f "$tmp" 2>/dev/null
|
|
66
|
+
return 0
|
|
67
|
+
}
|
|
@@ -571,6 +571,21 @@ def session_continued(event) -> bool:
|
|
|
571
571
|
return (event.get('d') or {}).get('session_continue') is not None
|
|
572
572
|
|
|
573
573
|
|
|
574
|
+
def _ending_qa(rows) -> dict:
|
|
575
|
+
"""Index, per attempt, of the last primary dispatch with a PASS or FAIL verdict.
|
|
576
|
+
|
|
577
|
+
`rows` is the chronological list `runs.dispatches[(run, task, 'qa')]`. The choice is
|
|
578
|
+
made before continued sessions are removed: the dispatch the attempt ended on may have
|
|
579
|
+
continued a reviewer session, and an earlier fresh verdict must not stand in for it.
|
|
580
|
+
Same choice as `shadow_pairs`.
|
|
581
|
+
"""
|
|
582
|
+
ending = {}
|
|
583
|
+
for index, event in enumerate(rows):
|
|
584
|
+
if (event.get('d') or {}).get('verdict') in ('PASS', 'FAIL'):
|
|
585
|
+
ending[event['attempt']] = index
|
|
586
|
+
return ending
|
|
587
|
+
|
|
588
|
+
|
|
574
589
|
def _qa_rows(runs: Runs):
|
|
575
590
|
"""Every independent QA dispatch with a verdict, with the diff it was shown and its task text.
|
|
576
591
|
|
|
@@ -578,6 +593,11 @@ def _qa_rows(runs: Runs):
|
|
|
578
593
|
one whose continue failed after it had already printed a verdict. A fresh fallback in
|
|
579
594
|
the same round has no `session_continue` and stays. There is no switch to put the
|
|
580
595
|
continued ones back, so a slice never mixes the two.
|
|
596
|
+
|
|
597
|
+
The attempt event's gate belongs to the QA execution the attempt ended on (see
|
|
598
|
+
`_ending_qa`). Every earlier dispatch of that attempt gets `gate=None`. When the one
|
|
599
|
+
the attempt ended on continued a session, it is skipped below, so no row of the
|
|
600
|
+
attempt carries the gate.
|
|
581
601
|
"""
|
|
582
602
|
store = runs.store
|
|
583
603
|
effort = {}
|
|
@@ -592,7 +612,8 @@ def _qa_rows(runs: Runs):
|
|
|
592
612
|
for (run, task, role), rows in runs.dispatches.items():
|
|
593
613
|
if role != 'qa':
|
|
594
614
|
continue
|
|
595
|
-
|
|
615
|
+
ending = _ending_qa(rows)
|
|
616
|
+
for index, e in enumerate(rows):
|
|
596
617
|
if session_continued(e):
|
|
597
618
|
continue
|
|
598
619
|
d = e['d']
|
|
@@ -603,15 +624,24 @@ def _qa_rows(runs: Runs):
|
|
|
603
624
|
if not blocks or not blocks[-1].strip():
|
|
604
625
|
continue
|
|
605
626
|
found = d.get('findings') or []
|
|
627
|
+
# Only the dispatch the attempt ended on was gated. An earlier one in the same
|
|
628
|
+
# attempt (a QA-only re-run keeps the number) was never the gate's input.
|
|
629
|
+
gate = gates.get((run, task, e['attempt'])) if ending.get(e['attempt']) == index else None
|
|
606
630
|
yield dict(run=run, task=task, attempt=e['attempt'], repo=e['repo'], verdict=d['verdict'],
|
|
607
|
-
gate=
|
|
631
|
+
gate=gate,
|
|
608
632
|
diff=blocks[-1], review=store.text((d.get('blobs') or {}).get('message')),
|
|
609
633
|
effort=effort.get((run, task, e['attempt'])), model=d.get('model'),
|
|
610
634
|
reviewer=dict(model=d.get('model'), effort=d.get('effort'), harness=d.get('harness')),
|
|
611
635
|
# Receipts from before findings_parse existed: an empty list then cannot
|
|
612
636
|
# tell a clean review from a parser failure, which was rare; read it as clean.
|
|
613
637
|
completeness=d.get('findings_parse') or review_completeness(d['verdict'], found),
|
|
614
|
-
worst=_worst(found)
|
|
638
|
+
worst=_worst(found),
|
|
639
|
+
# The dispatch this row was built from. A shadow pair names that event,
|
|
640
|
+
# so an earlier execution of the same attempt cannot claim it.
|
|
641
|
+
dispatch=e,
|
|
642
|
+
# Its place in the task's chronological QA dispatches: a split review
|
|
643
|
+
# case is keyed by it, never by the order rows come out of the store.
|
|
644
|
+
execution=index)
|
|
615
645
|
|
|
616
646
|
|
|
617
647
|
def _worst(found) -> str:
|
|
@@ -694,44 +724,60 @@ def review_cases(runs: Runs):
|
|
|
694
724
|
if len(verdicts) != 1:
|
|
695
725
|
# Two reviews of the same diff disagreed: the label is noise, not an outcome.
|
|
696
726
|
continue
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
#
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
727
|
+
# Same verdict on one diff stays one case, separate runs that met the same diff
|
|
728
|
+
# included. Only the executions of one attempt split, when forge gated them
|
|
729
|
+
# differently: the first row's gate must not hide the one the attempt ended on.
|
|
730
|
+
gates = defaultdict(set)
|
|
731
|
+
for item, _ in items:
|
|
732
|
+
gates[(item['run'], item['task'], item['attempt'])].add(item['gate'])
|
|
733
|
+
split = any(len(g) > 1 for g in gates.values())
|
|
734
|
+
exported = items if split else [items[0]]
|
|
735
|
+
for r, task in exported:
|
|
736
|
+
cohort = [(r, task)] if split else items
|
|
737
|
+
diff = r['diff']
|
|
738
|
+
# Who reviews decides the outcome as much as the diff: the same diff meets a 0.93 pass rate
|
|
739
|
+
# from one reviewer and 0.39 from another, so the reviewer is part of the state.
|
|
740
|
+
state = dict(diff=diff[:DIFF_CHARS], task=task, truncated=len(diff) > DIFF_CHARS, reviewer=r['reviewer'])
|
|
741
|
+
baseline = {}
|
|
742
|
+
if r['effort'] and r['effort'][0] in EFFORT_RANK:
|
|
743
|
+
baseline['passes'] = dict(source='hosted-jev qa effort', risk=EFFORT_RANK[r['effort'][0]] / 4.0)
|
|
744
|
+
questions, expected = dict(passes=review_passes()), dict(passes=r['verdict'] == 'PASS')
|
|
745
|
+
label_source = dict(passes='QA verdict')
|
|
746
|
+
# A graded label only where every review of this diff agrees. The gate split
|
|
747
|
+
# exports each execution, but severity stays a property of the whole group:
|
|
748
|
+
# a clean PASS beside a PASS that lists a confirmed P2 disagree, so neither
|
|
749
|
+
# case is graded. Skipping an unreadable review keeps "none" honest.
|
|
750
|
+
if all(item['completeness'] in ('clean', 'graded') for item, _ in items) and \
|
|
751
|
+
len({item['worst'] for item, _ in items}) == 1:
|
|
752
|
+
questions['severity'], expected['severity'] = review_severity(), r['worst']
|
|
753
|
+
label_source['severity'] = 'worst CONFIRMED finding (%s)' % r['completeness']
|
|
754
|
+
meta = dict(completeness=r['completeness'], gate=r['gate'])
|
|
755
|
+
# A second reviewer of the same diff, never consulted by the run: agreement is how
|
|
756
|
+
# much of this label is the diff and how much is who happened to review it.
|
|
757
|
+
# shadow_pairs binds that comparison to the dispatch the attempt ended on. A gate
|
|
758
|
+
# split exports every execution; only the cohort that contains that dispatch may
|
|
759
|
+
# carry it, or an earlier review of the same attempt would count the pair too.
|
|
760
|
+
paired = next((shadows[k] for k in dict.fromkeys((i['run'], i['task'], i['attempt']) for i, _ in cohort)
|
|
761
|
+
if k in shadows and any(item.get('dispatch') is shadows[k][0] for item, _ in cohort)), None)
|
|
762
|
+
if paired:
|
|
763
|
+
primary, shadow = paired
|
|
764
|
+
meta['shadow'] = dict(verdict=shadow['d']['verdict'], reviewer=shadow['d'].get('model'),
|
|
765
|
+
worst=_worst(shadow['d'].get('findings') or []))
|
|
766
|
+
meta['consensus'] = shadow['d']['verdict'] == primary['d']['verdict']
|
|
767
|
+
# The one label here no reviewer decides: whether the merged diff's lines stayed.
|
|
768
|
+
landed = next((runs.survival[c] for c in (runs.reviewed.get((i['run'], i['task'], i['attempt']))
|
|
769
|
+
for i, _ in cohort) if c in runs.survival), None)
|
|
770
|
+
if landed:
|
|
771
|
+
kept = landed['surviving'] / landed['added']
|
|
772
|
+
questions['survives'] = review_survives()
|
|
773
|
+
expected['survives'] = kept >= SURVIVES_AT and not landed.get('reverted_by')
|
|
774
|
+
label_source['survives'] = 'git blame %d days after integrate' % landed['horizon_days']
|
|
775
|
+
meta['survival'] = dict(added=landed['added'], surviving=landed['surviving'],
|
|
776
|
+
reverted_by=landed.get('reverted_by') or [], horizon_days=landed['horizon_days'])
|
|
777
|
+
yield dict(slice='review', key=key if not split else _sha(key, r['run'], r['task'], r['attempt'], r['execution']),
|
|
778
|
+
run=r['run'], repo=r['repo'], task=r['task'], state=state,
|
|
779
|
+
questions=questions, expected=expected, baseline=baseline, label_source=label_source,
|
|
780
|
+
reviewer=r['model'], meta=meta)
|
|
735
781
|
|
|
736
782
|
|
|
737
783
|
_SKIP_PREFIXES = ('.git/', '.forge/', 'node_modules/', 'vendor/', 'target/', 'dist/',
|
|
@@ -7,9 +7,12 @@ left alone). The transports call check() before a request and charge() after it;
|
|
|
7
7
|
has been reached turns every remaining call into a skip with reason 'budget'.
|
|
8
8
|
|
|
9
9
|
Fail-open throughout: check() and charge() never raise, a counter that cannot be read or
|
|
10
|
-
parsed counts as zero, and a lock or write failure skips the charge.
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
parsed counts as zero, and a lock or write failure skips the charge. A stored usd of positive
|
|
11
|
+
infinity is kept: an overflowed cost has reached the USD caps, and a later charge leaves it
|
|
12
|
+
infinite. NaN, a negative, a non-number and an integer too big for a float still count as
|
|
13
|
+
zero. Several processes of one run may charge at once, so each read-modify-write holds
|
|
14
|
+
flock(LOCK_EX) on a sibling .lock file and the write is a temp file plus os.replace. Standard
|
|
15
|
+
library only.
|
|
13
16
|
"""
|
|
14
17
|
from __future__ import annotations
|
|
15
18
|
|
|
@@ -37,6 +40,31 @@ def _number(value) -> float:
|
|
|
37
40
|
return 0
|
|
38
41
|
|
|
39
42
|
|
|
43
|
+
def _usd(value) -> float:
|
|
44
|
+
"""Stored USD spend. +inf stays inf: an overflowed cost reached the cap. NaN, a negative,
|
|
45
|
+
a non-number, or an integer too big for a float counts as zero."""
|
|
46
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)):
|
|
47
|
+
return 0.0
|
|
48
|
+
try:
|
|
49
|
+
number = float(value)
|
|
50
|
+
except OverflowError:
|
|
51
|
+
return 0.0
|
|
52
|
+
if math.isnan(number) or number <= 0:
|
|
53
|
+
return 0.0
|
|
54
|
+
return number
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _sum_usd(current: float, extra: float) -> float:
|
|
58
|
+
"""Positive infinity stays infinity. A later charge must not turn it into NaN or zero."""
|
|
59
|
+
if _positive_inf(current) or _positive_inf(extra):
|
|
60
|
+
return math.inf
|
|
61
|
+
return current + extra
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _positive_inf(value) -> bool:
|
|
65
|
+
return isinstance(value, float) and math.isinf(value) and value > 0
|
|
66
|
+
|
|
67
|
+
|
|
40
68
|
def usage_tokens(usage) -> int:
|
|
41
69
|
"""Tokens a response used: input+output, else prompt+completion, else total."""
|
|
42
70
|
if not isinstance(usage, dict):
|
|
@@ -76,7 +104,7 @@ def _read(path: Path | None) -> dict:
|
|
|
76
104
|
return zero
|
|
77
105
|
try:
|
|
78
106
|
data = json.loads(path.read_text())
|
|
79
|
-
return {'tokens': int(_number(data['tokens'])), 'usd':
|
|
107
|
+
return {'tokens': int(_number(data['tokens'])), 'usd': _usd(data['usd'])}
|
|
80
108
|
except (OSError, ValueError, KeyError, TypeError, OverflowError, RecursionError):
|
|
81
109
|
return zero
|
|
82
110
|
|
|
@@ -88,7 +116,7 @@ def _add(path: Path, tokens: int, usd: float) -> None:
|
|
|
88
116
|
fcntl.flock(lock, fcntl.LOCK_EX)
|
|
89
117
|
total = _read(path)
|
|
90
118
|
total['tokens'] += tokens
|
|
91
|
-
total['usd']
|
|
119
|
+
total['usd'] = _sum_usd(total['usd'], usd)
|
|
92
120
|
tmp = path.with_name(f'{path.name}.{os.getpid()}.tmp')
|
|
93
121
|
try:
|
|
94
122
|
tmp.write_text(json.dumps(total))
|
|
@@ -100,12 +128,15 @@ def _add(path: Path, tokens: int, usd: float) -> None:
|
|
|
100
128
|
|
|
101
129
|
|
|
102
130
|
def _reached(spent, cap, slack=0.0) -> bool:
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
131
|
+
# Token caps pass no slack and compare as integers, so a count above 2^53 is exact.
|
|
132
|
+
# USD caps pass USD_SLACK, which scales the (finite) spend, never the cap: an int cap
|
|
133
|
+
# too big for a float still compares exactly. A cap that cannot be compared never
|
|
134
|
+
# blocks, and never stops the other caps from being checked.
|
|
106
135
|
if cap is None:
|
|
107
136
|
return False
|
|
108
137
|
try:
|
|
138
|
+
if not slack:
|
|
139
|
+
return spent >= cap
|
|
109
140
|
return spent * (1 + slack) >= cap
|
|
110
141
|
except Exception:
|
|
111
142
|
return False
|
|
@@ -14,6 +14,11 @@ and thresholds only. Kinds:
|
|
|
14
14
|
shadowed a repo value the user file overrides
|
|
15
15
|
misplaced a user-only key in a repo file, or `privacy` in a user file
|
|
16
16
|
key-file a provider's key file is missing or not mode 0600
|
|
17
|
+
bad-price a provider's price_usd_per_mtok is not a finite number above zero,
|
|
18
|
+
so the price is ignored ({provider, value}). NaN and ±Infinity are
|
|
19
|
+
the strings "NaN", "Infinity" and "-Infinity" wherever they sit,
|
|
20
|
+
including inside a list or object: they are not JSON numbers, and
|
|
21
|
+
`doctor --json` must stay standard JSON
|
|
17
22
|
privacy-floor the repo has `privacy: never-send`
|
|
18
23
|
not-migrated jev.json exists but decide.json does not
|
|
19
24
|
config-error anything else wrong with reading the files
|
|
@@ -27,6 +32,7 @@ from pathlib import Path
|
|
|
27
32
|
|
|
28
33
|
from . import GATES, config_dir, load_repo, load_user, repo_path, user_path
|
|
29
34
|
from .migrate import retired_thresholds
|
|
35
|
+
from .providers import _positive
|
|
30
36
|
from .resolve import resolve
|
|
31
37
|
|
|
32
38
|
MISPLACED_MARKERS = ('user file only', 'only in a repo file')
|
|
@@ -133,6 +139,48 @@ def _key_path(value: str) -> Path:
|
|
|
133
139
|
return path if path.is_absolute() else config_dir() / path
|
|
134
140
|
|
|
135
141
|
|
|
142
|
+
def _price_text(value) -> str:
|
|
143
|
+
if isinstance(value, float) and value != value:
|
|
144
|
+
return 'NaN'
|
|
145
|
+
if value == float('inf'):
|
|
146
|
+
return 'Infinity'
|
|
147
|
+
if value == float('-inf'):
|
|
148
|
+
return '-Infinity'
|
|
149
|
+
return str(value)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _json_price(value):
|
|
153
|
+
"""The stored price as strict JSON can carry it. NaN and Infinity are not JSON numbers,
|
|
154
|
+
so each becomes the string "NaN", "Infinity" or "-Infinity", including one nested in a
|
|
155
|
+
list or object. A finite number (0, -1) stays a number."""
|
|
156
|
+
if isinstance(value, float):
|
|
157
|
+
shown = _price_text(value)
|
|
158
|
+
if shown in ('NaN', 'Infinity', '-Infinity'):
|
|
159
|
+
return shown
|
|
160
|
+
return value
|
|
161
|
+
if isinstance(value, list):
|
|
162
|
+
return [_json_price(item) for item in value]
|
|
163
|
+
if isinstance(value, dict):
|
|
164
|
+
return {key: _json_price(item) for key, item in value.items()}
|
|
165
|
+
return value
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _bad_prices(providers: dict, items: list) -> None:
|
|
169
|
+
"""A stored price _positive() would drop never counts toward a USD cap. A missing price
|
|
170
|
+
is unpriced on purpose and is not reported."""
|
|
171
|
+
for name in sorted(providers):
|
|
172
|
+
provider = providers[name]
|
|
173
|
+
if not isinstance(provider, dict) or 'price_usd_per_mtok' not in provider:
|
|
174
|
+
continue
|
|
175
|
+
value = provider['price_usd_per_mtok']
|
|
176
|
+
if value is None or _positive(value) is not None:
|
|
177
|
+
continue
|
|
178
|
+
shown = _price_text(value)
|
|
179
|
+
items.append(dict(kind='bad-price', provider=name, value=_json_price(value),
|
|
180
|
+
message=f'provider {name}: price_usd_per_mtok {shown} is ignored; '
|
|
181
|
+
f'set a finite number above zero with `forge decide provider add --price`'))
|
|
182
|
+
|
|
183
|
+
|
|
136
184
|
def _key_files(providers: dict, items: list) -> None:
|
|
137
185
|
for name, provider in sorted(providers.items()):
|
|
138
186
|
key_file = provider.get('key_file') if isinstance(provider, dict) else None
|
|
@@ -195,6 +243,7 @@ def _checks(repo, env, items: list) -> None:
|
|
|
195
243
|
if name not in used:
|
|
196
244
|
items.append(dict(kind='unused-provider', provider=name,
|
|
197
245
|
message=f'provider {name!r} is configured but no gate uses it'))
|
|
246
|
+
_bad_prices(providers, items)
|
|
198
247
|
|
|
199
248
|
for entry in resolved['shadowed']:
|
|
200
249
|
items.append(dict(kind='shadowed', **entry,
|
package/ui/docs/api.md
CHANGED
|
@@ -38,6 +38,7 @@ written), and the reader must never raise because of one.
|
|
|
38
38
|
| `results.tsv` | `id<TAB>status<TAB>branch` per line, e.g. `reader MERGED forge/20261016-1530/reader` |
|
|
39
39
|
| `run_id` | one line, e.g. `20261016-153012-ab12` |
|
|
40
40
|
| `repo` | one line, absolute path of the target repo |
|
|
41
|
+
| `repo.identity` | optional, written by forge 0.13.1 and later, once at creation: `{"root", "worktree", "branch"}`, the repository `repo` belongs to. `root` is its main working tree (the same for every linked worktree), `worktree` the checkout's physical path when it differs from `root` (else `null`), `branch` its branch (`null` when HEAD is detached) |
|
|
41
42
|
| `goal.txt`, `request.md` | free text |
|
|
42
43
|
| `decompose_level` | `low`, `medium` or `high` |
|
|
43
44
|
| `explore`, `shadow_rate` | one number each (e.g. `0.5`) |
|
|
@@ -117,6 +118,7 @@ raise because of one. Older solo dirs have `verdict` and not `status`.
|
|
|
117
118
|
|---|---|
|
|
118
119
|
| `prompt.md` | the implementation prompt |
|
|
119
120
|
| `repo` | one line, absolute path of the target repo |
|
|
121
|
+
| `repo.identity` | optional, written by forge 0.13.1 and later, once at creation: `{"root", "worktree", "branch"}`, the repository `repo` belongs to. `root` is its main working tree (the same for every linked worktree), `worktree` the checkout's physical path when it differs from `root` (else `null`), `branch` its branch (`null` when HEAD is detached) |
|
|
120
122
|
| `goal.txt`, `request.md` | free text; the summary goal is the first line of `goal.txt` |
|
|
121
123
|
| `status` | one word: `RUNNING`, then `PASS`, `FAIL`, `UNKNOWN`, `NOCHANGES`, `INVALIDATED`, `TIMEOUT`, `INFRA`, `INTERRUPTED` or `ERROR` |
|
|
122
124
|
| `verdict` | one word, the legacy status (`PASS`, `FAIL`, `UNKNOWN`, `NOCHANGES`, `INVALIDATED`, …) |
|
|
@@ -185,6 +187,7 @@ class Catalog:
|
|
|
185
187
|
def __init__(self, plans=(), roots=(), registry=True, registry_dir=None): ...
|
|
186
188
|
def runs(self) -> list[dict] # RunSummary list, newest `updated` first
|
|
187
189
|
def get(self, key) -> dict | None # RunDetail for that run_key, or None
|
|
190
|
+
def identity(self, key) -> dict | None # {root, worktree, branch, source} of that run; None for an unknown key
|
|
188
191
|
def task(self, key, task_id) -> dict | None
|
|
189
192
|
def execution(self, key, name) -> dict | None
|
|
190
193
|
def final_review(self, key, name) -> dict | None
|
|
@@ -256,7 +259,7 @@ its last 20,000 behind a leading `…`. Their `truncated` lists the field names
|
|
|
256
259
|
| `POST /api/runs/<key>/issues/dismiss` | dismiss or (`undo`) restore findings; authenticated |
|
|
257
260
|
| `POST /api/runs/<key>/delete` | dry-run or delete a run with `forge runs rm`; authenticated, 900 s timeout; later requests for the key answer `404` |
|
|
258
261
|
| `GET /api/models/reviewers` | `200` the `forge dataset reviewers --json` report (how each reviewer's PASSed work held up); no parameters |
|
|
259
|
-
| `GET /api/config?run=<key>` | `200` the `forge config show --json` of that run's
|
|
262
|
+
| `GET /api/config?run=<key>` | `200` the `forge config show --json` of that run's repository root (see Config) |
|
|
260
263
|
| `POST /api/config` | set or unset one allowed key (`repo.verify`, `repo.setup`, `repo.verify-subset`, `decide.gate.<gate>`, `decide.gate.<gate>.provider`, `decide.gate.<gate>.model`); `jev.enabled` is gone; authenticated |
|
|
261
264
|
| `GET /api/runs/<key>/export?texts=0\|1&paths=0\|1` | `200` the run as one HTML file (see Export), `Content-Disposition: attachment`, `Content-Security-Policy: default-src 'none'; sandbox`; `404` for an unknown run |
|
|
262
265
|
| `GET /api/runs/<key>/tasks/<id>/fractal` | `200 TaskFractal` |
|
|
@@ -305,6 +308,9 @@ nothing when there is none. Every other response keeps
|
|
|
305
308
|
"kind": "plan",
|
|
306
309
|
"run_id": "20261016-153012-ab12",
|
|
307
310
|
"repo": "/Users/me/dev/forge-ui",
|
|
311
|
+
"repo_root": "/Users/me/dev/forge-ui",
|
|
312
|
+
"repo_worktree": null,
|
|
313
|
+
"repo_branch": "main",
|
|
308
314
|
"goal": "first line of goal.txt",
|
|
309
315
|
"decompose_level": "medium",
|
|
310
316
|
"updated": 1760621412.5,
|
|
@@ -329,6 +335,18 @@ nothing when there is none. Every other response keeps
|
|
|
329
335
|
- `created`: when the run began: the earliest birth time (else mtime) of the files a run writes
|
|
330
336
|
once at its start (plan: `run_id`, `repo`, `request.md`, `goal.txt`, `tasks.tsv`; solo: `prompt.md`,
|
|
331
337
|
`repo`, `request.md`, `goal.txt`), else `null`. These are stat'ed only, and never move `updated`.
|
|
338
|
+
- `repo_root`: the repository the run belongs to, and the key to group runs by. It is the identity's
|
|
339
|
+
root, or `repo` when nothing better is known (`null` only when the run has no `repo`). It is found in
|
|
340
|
+
four steps, the first that answers: (1) `repo.identity` in the run dir, written once at creation by
|
|
341
|
+
forge 0.13.1 and later, its `root`; (2) the `repo` path is a live git checkout: the main working tree
|
|
342
|
+
of its `git worktree list`; (3) the `repo` path is gone: the run's base commit (`integration.base`,
|
|
343
|
+
else a plan's first readable `tasks/*/base_ref`, else a solo run's `dwarf.head.before`) is in exactly
|
|
344
|
+
one root that steps 1 and 2 found in the same listing; (4) otherwise `repo` itself. Clients should
|
|
345
|
+
group by `repo_root` and fall back to `repo` when it is absent (an older server).
|
|
346
|
+
- `repo_worktree`: the checkout the run started in, when that is not `repo_root` (a linked worktree; for
|
|
347
|
+
a worktree that was removed, its `repo` text), else `null`.
|
|
348
|
+
- `repo_branch`: the branch the run started on, from `repo.identity` only; `null` when unknown (a
|
|
349
|
+
detached HEAD, or a run whose root came from step 2 or 3).
|
|
332
350
|
- `dwarf_models`, `qa_models`: `models` split by role.
|
|
333
351
|
- `models`: the sorted distinct specs of the `dwarf` and `qa` columns (a solo run: its `dwarf`
|
|
334
352
|
and `qa` specs as its task has them), nulls left out.
|
|
@@ -1045,7 +1063,8 @@ lines follow, a line was cut, or reaching them took more than 64 MB of reading.
|
|
|
1045
1063
|
|
|
1046
1064
|
```json
|
|
1047
1065
|
{"generated": 1760621412.5, "runs": 12, "truncated": false,
|
|
1048
|
-
"tasks": [{"run": "3f9a0c1d2e4b", "task": "reader", "kind": "plan", "repo": "/x/y", "
|
|
1066
|
+
"tasks": [{"run": "3f9a0c1d2e4b", "task": "reader", "kind": "plan", "repo": "/x/y", "repo_root": "/x/y",
|
|
1067
|
+
"difficulty": "high",
|
|
1049
1068
|
"created": 1760619000.0, "explored": true, "propensity": 0.125, "final_status": "MERGED",
|
|
1050
1069
|
"accepted": true,
|
|
1051
1070
|
"attempts": [{"n": 1, "alias": "luna", "spec": "luna", "source": "execution", "outcome": "fail",
|
|
@@ -1053,12 +1072,14 @@ lines follow, a line was cut, or reaching them took more than 64 MB of reading.
|
|
|
1053
1072
|
"tokens": {"input": 120000, "cached": 90000, "output": 8000}, "timed_out": false}],
|
|
1054
1073
|
"escalations": [{"n": 1, "from": "luna", "to": "sol:xhigh"}]}],
|
|
1055
1074
|
"reviews": [{"run": "3f9a0c1d2e4b", "task": "reader", "n": 1, "kind": "primary", "alias": "opus", "spec": "opus",
|
|
1075
|
+
"repo_root": "/x/y",
|
|
1056
1076
|
"verdict": "FAIL", "findings": FindingsSummary, "duration_s": 270.0, "tokens": {...},
|
|
1057
1077
|
"agreement": null, "primary_alias": null}],
|
|
1058
1078
|
"warnings": ["3f9a0c1d2e4b: tasks/x/attempts.tsv line 2: invalid attempt"]}
|
|
1059
1079
|
```
|
|
1060
1080
|
|
|
1061
|
-
- `tasks[]`: one per task (`solo` for a solo run). `
|
|
1081
|
+
- `tasks[]`: one per task (`solo` for a solo run). `repo` is the run's `repo` text and `repo_root` its
|
|
1082
|
+
grouping key, both as in RunSummary (the same for every row of a run). `explored` as Task's; `propensity` that of
|
|
1062
1083
|
the newest `route.jsonl` decision, else `null`; `final_status` the task (or solo) status;
|
|
1063
1084
|
`accepted` whether `accepted.by` is non-empty (`false` for a solo run). `escalations` is
|
|
1064
1085
|
`escalations.tsv` as it is (`n` its attempt column, `from`/`to` specs).
|
|
@@ -1080,9 +1101,10 @@ lines follow, a line was cut, or reaching them took more than 64 MB of reading.
|
|
|
1080
1101
|
`shadow.status` is `done` (`alias`/`spec` its execution's model, else `shadow.json`'s spec;
|
|
1081
1102
|
`agreement` and `primary_alias` against the primary review of its attempt); every finished
|
|
1082
1103
|
final review (`kind` `final`, `task` and `n` `null`, `verdict` `PASS`/`FAIL` else `null`,
|
|
1083
|
-
timing from its newest execution).
|
|
1104
|
+
timing from its newest execution). Every review row also has `repo_root`, the run's (reviews have no
|
|
1105
|
+
`repo` of their own).
|
|
1084
1106
|
- Per run the facts are kept, keyed by its realpath, until its RunSummary's `updated`,
|
|
1085
|
-
`task_count`, `counts` or `final_review` changes (4,096 runs); a run with a `RUNNING` task is
|
|
1107
|
+
`task_count`, `counts` or `final_review`, or its `repo_root`, changes (4,096 runs); a run with a `RUNNING` task is
|
|
1086
1108
|
read again after 120 s. One computation runs at a time. Past 50,000 task rows the next run
|
|
1087
1109
|
is left out and `truncated` is true. `warnings` (first 500) are prefixed by the run key.
|
|
1088
1110
|
|
|
@@ -1386,8 +1408,11 @@ Reviewers table's Did not hold column and nothing else. Timeout 60 s.
|
|
|
1386
1408
|
|
|
1387
1409
|
### `GET /api/config?run=<key>` and `POST /api/config`
|
|
1388
1410
|
|
|
1389
|
-
The repository is the run's
|
|
1390
|
-
|
|
1411
|
+
The repository is the run's `repo_root` (see RunSummary) when that is an existing absolute directory,
|
|
1412
|
+
else the run's own `repo` file (first line, an existing absolute directory; else `409`), never a client
|
|
1413
|
+
field. The settings resolve against the root: every worktree of a repository shares its committed
|
|
1414
|
+
`.forge/` config, so the run of a removed worktree reads and writes the main checkout. A run whose root
|
|
1415
|
+
is unknown and whose `repo` is gone is still `409`. `GET` runs `config show --repo <repo> --json` and answers with its
|
|
1391
1416
|
object. The `decide` block is the `forge decide status --json` object for that repo, plus `ready`
|
|
1392
1417
|
on each gate (`true` when the gate is `shadow` or `on`, nothing skips it, and its provider is
|
|
1393
1418
|
local or has a key on file), plus two fields from `forge decide status --json`: `forced` (bool: the
|