From 6f410661a18fefb6768fe37f5f6ffc599204eb10 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 1 Dec 2026 09:19:25 +0000 Subject: code-modernization: choose rule-extraction depth and approve a number of agents Add --depth standard|thorough. Standard, the default, keeps the previous extraction wording; Thorough writes one rule per decision and costs more. Every run shows the estimate for both and never starts more agents than were approved. Spread batches over the system and size them by the densest shards seen, so dense code that comes late is not extracted and left unrefereed. Keep same-named rules whose citations a referee swaps or moves. Merge follow-up runs with a script that never drops a confirmed rule because a re-run failed. --- plugins/code-modernization/scripts/make_shards.py | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'plugins/code-modernization/scripts/make_shards.py') diff --git a/plugins/code-modernization/scripts/make_shards.py b/plugins/code-modernization/scripts/make_shards.py index 1365d9bc..54ee208f 100644 --- a/plugins/code-modernization/scripts/make_shards.py +++ b/plugins/code-modernization/scripts/make_shards.py @@ -13,6 +13,7 @@ import codecs import collections import fnmatch import json +import math import os import re import sys @@ -48,6 +49,13 @@ CUT_WINDOW = 100 # how far a cut may move to land between two blocks of cod SMALL = 300 TINY_ESTATE = 30 # files; a tiny estate also fits in one shard (MAX_LOC lines) MAX_BYTES = 5_000_000 +# Estimated agents per 1,000 lines for each depth: code that is mostly plumbing, and very dense business logic. Taken from +# simulated runs (T-SQL procedures, C utilities) and, for the low end of standard, from a 30,000-line estate. +AGENTS_PER_KLOC = {'Standard': (15, 55), 'Thorough': (20, 190)} +SMALL_SHARD = {'Standard': 40, 'Thorough': 125} # a short dense file needs more per line: 10 + lines / 5, up to this +LENS_AGENTS = {'Standard': (15, 100), 'Thorough': (20, 250)} # a tiny estate, about 1,000 lines +LENS_MIN_TOP = {'Standard': 100, 'Thorough': 150} +TOKENS_PER_AGENT = 16_000 def too_broad(path): @@ -276,6 +284,23 @@ def split_long_files(shards, source): return out +def estimate(sizes, tiny): + """One line with the agents and tokens each depth is expected to need, from the number of lines in each shard.""" + def rounded(n): + return math.ceil(n / 10) * 10 + + parts = [] + for depth in AGENTS_PER_KLOC: + if tiny: + low, top = LENS_AGENTS[depth][0], max(LENS_MIN_TOP[depth], LENS_AGENTS[depth][1] * sum(sizes) / 1000) + else: + low = AGENTS_PER_KLOC[depth][0] * sum(sizes) / 1000 + top = sum(max(AGENTS_PER_KLOC[depth][1] * n / 1000, min(SMALL_SHARD[depth], 10 + n / 5)) for n in sizes) + low, top = max(rounded(low), 20), max(rounded(top), 30) + parts.append(f'{depth} {low} to {top} agents (about {low * TOKENS_PER_AGENT / 1e6:.1f}M to {top * TOKENS_PER_AGENT / 1e6:.1f}M tokens)') + return 'estimate: ' + '; '.join(parts) + ', from mostly plumbing to very dense business logic' + + def quoted(names): """Up to five file names for a note, quoted and shortened.""" return ', '.join(json.dumps(name[-80:]) + extra for name, extra in names[:5]) @@ -371,6 +396,8 @@ def main(argv): tiny = max(len(mapped), len(tree)) < TINY_ESTATE and max(loc, sum(n for _, n in tree)) <= MAX_LOC and not unread if unmapped_note and not tiny: # lens mode reads every file notes.append(unmapped_note) + # The map's sizes can be missing or out of date, so the files are counted. + print(estimate([s['loc'] if 'lines' in s else sum(count_lines(os.path.join(source, f)) or 0 for f in s['files']) or s['loc'] or 0 for s in shards], tiny)) if tiny: print(f'tiny estate: the system has fewer than {TINY_ESTATE} source files and at most {MAX_LOC} lines, so sharding adds little (run the workflow in lens mode).') for note in notes: -- cgit