Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-02 10:29:06

0001 #!/usr/bin/env python3
0002 """whats-new-proposals-retire.py — retire the pending What's new AI
0003 proposals (swf-monitor docs/WHATS_NEW.md, Items added by LLM sessions).
0004 What's new items are added as part of the task that ships a change, not
0005 proposed (Torre Wenaus, 2026-11-12), so the proposals the retired
0006 ``whats_new`` category left pending are settled here: each one named in
0007 ``--add`` becomes its item, through ``help.whats_new.item_create`` with
0008 the proposal as its origin, and is marked executed; each one named in
0009 ``--withdraw`` (a duplicate, or an item not wanted) is marked withdrawn.
0010 
0011 Usage::
0012 
0013     cd /data/wenauseic/github/swf-monitor/src
0014     source ~/.env
0015     /data/wenauseic/github/swf-testbed/.venv/bin/python \\
0016         ../scripts/whats-new-proposals-retire.py --add 3974 3975 \\
0017         --withdraw 3978 --by wenaus --decided-by swf-1 [--apply]
0018 
0019 Dry run by default: what would be added and withdrawn is printed.
0020 """
0021 import argparse
0022 import os
0023 import sys
0024 
0025 THIS_DIR = os.path.dirname(os.path.abspath(__file__))
0026 sys.path.insert(0, os.path.join(THIS_DIR, '..', 'src'))
0027 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'swf_monitor_project.settings')
0028 
0029 import django  # noqa: E402
0030 django.setup()
0031 
0032 from django.db import transaction  # noqa: E402
0033 from django.utils import timezone  # noqa: E402
0034 
0035 from ai.models import Proposal  # noqa: E402
0036 from ai.services import _mark_decided  # noqa: E402
0037 from help import whats_new  # noqa: E402
0038 
0039 
0040 def main():
0041     ap = argparse.ArgumentParser(description=__doc__.split('\n\n')[0])
0042     ap.add_argument('--add', type=int, nargs='*', default=[],
0043                     help='proposal ids whose items are added')
0044     ap.add_argument('--withdraw', type=int, nargs='*', default=[],
0045                     help='proposal ids withdrawn without an item')
0046     ap.add_argument('--by', required=True,
0047                     help='the person the added items record as who added them')
0048     ap.add_argument('--decided-by', required=True,
0049                     help='recorded on each settled proposal')
0050     ap.add_argument('--apply', action='store_true')
0051     args = ap.parse_args()
0052 
0053     ids = args.add + args.withdraw
0054     rows = {r.pk: r for r in Proposal.objects.filter(
0055         pk__in=ids, action='whats_new', status='proposed')}
0056     missing = sorted(set(ids) - set(rows))
0057     if missing:
0058         sys.exit(f'not pending What\'s new proposals: {missing}')
0059     now = timezone.now()
0060     failed = 0
0061     for pk in args.add:
0062         row = rows[pk]
0063         fields = {k: (row.payload or {}).get(k) for k in whats_new.FIELDS}
0064         print(f'add {row.ref}: {fields["title"]}')
0065         if not args.apply:
0066             continue
0067         origin = {'kind': 'ai_proposal', 'ref': row.ref,
0068                   'proposer': row.proposer, 'batch_id': row.batch_id,
0069                   'proposed_at': row.created_at.isoformat()}
0070         try:
0071             with transaction.atomic():
0072                 entry, log_id = whats_new.item_create(
0073                     fields, changed_by=args.by, origin=origin)
0074                 _mark_decided(row, 'executed', args.decided_by, now,
0075                               quality='', log_id=log_id)
0076         except whats_new.WhatsNewError as e:
0077             failed += 1
0078             print(f'  refused: {e.detail}', file=sys.stderr)
0079             continue
0080         print(f'  added /help/whats-new/{entry.name}/')
0081     for pk in args.withdraw:
0082         row = rows[pk]
0083         print(f'withdraw {row.ref}: {(row.payload or {}).get("title")}')
0084         if args.apply:
0085             _mark_decided(row, 'withdrawn', args.decided_by, now)
0086     if not args.apply:
0087         print('dry run: nothing written (--apply to write)')
0088     sys.exit(1 if failed else 0)
0089 
0090 
0091 if __name__ == '__main__':
0092     main()