Build reproducible capability advisor and scheduled source capture
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a09c77-b1a9-7eb3-b501-6cb24b458c97
This commit is contained in:
parent
a1edefd7c5
commit
29ceb77938
68 changed files with 2431 additions and 85 deletions
|
|
@ -80,12 +80,8 @@ def record(root, value):
|
|||
path = root / 'data/observations' / f'{ident}.json'
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
envelope = {'id': ident, 'record': value}
|
||||
try:
|
||||
with path.open('x') as stream:
|
||||
stream.write(json.dumps(envelope, indent=2, ensure_ascii=False) + '\n')
|
||||
except FileExistsError:
|
||||
if json.loads(path.read_text()) != envelope:
|
||||
raise ValueError('existing observation differs; refusing overwrite') from None
|
||||
from .store import atomic
|
||||
atomic(path, (json.dumps(envelope, indent=2, ensure_ascii=False) + '\n').encode(), immutable=True)
|
||||
return ident
|
||||
|
||||
|
||||
|
|
@ -141,6 +137,14 @@ def check(root):
|
|||
raise ValueError('archive path escapes history')
|
||||
if hashlib.sha256(path.read_bytes()).hexdigest() != item['sha256']:
|
||||
raise ValueError(f'archive checksum mismatch: {path}')
|
||||
from .ingest import check_artifacts
|
||||
from .store import all_records
|
||||
check_artifacts(root)
|
||||
for kind in ('recommendations', 'outcomes', 'ingestion-runs', 'scheduler-runs'):
|
||||
all_records(root, kind)
|
||||
from .advisor import replay
|
||||
for ident, _ in all_records(root, 'recommendations'):
|
||||
replay(root, ident)
|
||||
return len(ledger(root))
|
||||
|
||||
|
||||
|
|
@ -154,9 +158,54 @@ def main(argv=None):
|
|||
add.add_argument('input', type=Path)
|
||||
render = commands.add_parser('digest', help='create a daily or ISO-week draft, refusing overwrite')
|
||||
render.add_argument('period')
|
||||
ingest_command = commands.add_parser('ingest', help='capture registered primary-source artifacts')
|
||||
ingest_command.add_argument('registry', type=Path)
|
||||
advisor_command = commands.add_parser('advise', help='save a reproducible task-specific recommendation')
|
||||
advisor_command.add_argument('task', type=Path)
|
||||
advisor_command.add_argument('--catalog', type=Path, required=True)
|
||||
advisor_command.add_argument('--policy', type=Path, default=Path('policies/advisor-v0.2.json'))
|
||||
advisor_command.add_argument('--as-of', required=True)
|
||||
advisor_command.add_argument('--synthetic', action='store_true')
|
||||
report_command = commands.add_parser('report', help='render a saved comparison as Markdown')
|
||||
report_command.add_argument('id')
|
||||
replay_command = commands.add_parser('replay', help='verify a saved recommendation using its frozen inputs')
|
||||
replay_command.add_argument('id')
|
||||
outcome_command = commands.add_parser('outcome', help='record an actual task execution and acceptance result')
|
||||
outcome_command.add_argument('input', type=Path)
|
||||
schedule_command = commands.add_parser('run-due', help='run latest due daily/weekly jobs; safe to invoke repeatedly')
|
||||
schedule_command.add_argument('--config', type=Path, default=Path('ops/schedule.json'))
|
||||
commands.add_parser('health', help='show durable scheduler health')
|
||||
args = parser.parse_args(argv)
|
||||
try:
|
||||
if args.command == 'record':
|
||||
if args.command == 'ingest':
|
||||
from .ingest import ingest
|
||||
result = ingest(args.root, json.loads(args.registry.read_text()))
|
||||
print(json.dumps(result, indent=2))
|
||||
return 0 if result['ok'] else 1
|
||||
elif args.command == 'advise':
|
||||
from .advisor import recommend
|
||||
ident, report = recommend(args.root, json.loads(args.task.read_text()),
|
||||
json.loads(args.catalog.read_text()), json.loads(args.policy.read_text()),
|
||||
args.as_of, args.synthetic)
|
||||
print(json.dumps({'recommendation_id': ident, **report}, indent=2))
|
||||
elif args.command == 'report':
|
||||
from .advisor import render_report
|
||||
print(render_report(args.root, args.id))
|
||||
elif args.command == 'replay':
|
||||
from .advisor import replay
|
||||
print(json.dumps(replay(args.root, args.id), indent=2))
|
||||
elif args.command == 'outcome':
|
||||
from .advisor import outcome
|
||||
print(outcome(args.root, json.loads(args.input.read_text())))
|
||||
elif args.command == 'run-due':
|
||||
from .scheduler import run_due
|
||||
result = run_due(args.root, json.loads(args.config.read_text()))
|
||||
print(json.dumps(result, indent=2))
|
||||
return 0 if result['ok'] else 1
|
||||
elif args.command == 'health':
|
||||
path = args.root / '.runtime/scheduler.json'
|
||||
print(path.read_text() if path.exists() else '{"status": "not_run"}')
|
||||
elif args.command == 'record':
|
||||
print(record(args.root, json.loads(args.input.read_text())))
|
||||
elif args.command == 'digest':
|
||||
print(draft(args.root, args.period))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue