Back to home page

EIC code displayed by LXR

 
 

    


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

0001 """What's new MCP tools (docs/WHATS_NEW.md): read the list of developments,
0002 add an item, edit an item. Every write goes through help.whats_new; nothing
0003 here writes the entries itself."""
0004 from asgiref.sync import sync_to_async
0005 
0006 from monitor_app.mcp import mcp
0007 from monitor_app.mcp.common import (_get_username, _monitor_url,
0008                                     requires_authority)
0009 
0010 
0011 def _brief(row):
0012     return {
0013         'slug': row['slug'], 'title': row['title'], 'summary': row['summary'],
0014         'tags': row['tags'], 'importance': row['importance'],
0015         'shipped': row['shipped'], 'contact': row['contact'],
0016         'up': row['up'], 'down': row['down'],
0017         'comment_count': row['comment_count'],
0018         'awaiting_reply': row['awaiting_reply'],
0019         'url': _monitor_url(f"/help/whats-new/{row['slug']}/"),
0020     }
0021 
0022 
0023 def _words(value):
0024     import re
0025     if isinstance(value, (list, tuple)):
0026         return [str(v).strip().lower() for v in value if str(v).strip()]
0027     return [w.lower() for w in re.split(r'[,\s]+', value or '') if w]
0028 
0029 
0030 @mcp.tool()
0031 async def whats_new_list(tags: str = '', importance: str = '', since: str = '',
0032                          search: str = '', limit: int = 20,
0033                          include_details: bool = False) -> dict:
0034     """
0035     What's new in ePIC production, the epicprod monitor, PCS, PanDA
0036     operations and the streaming testbed: the curated list of recent
0037     developments users, operators and developers should know about,
0038     newest first. Use it for "what's new", "what are the recent epicprod
0039     developments", "what changed lately for operators", "anything new for
0040     users". Each item has a one-line title and a short summary; show those
0041     and the item URL, and fetch one item's details with whats_new_get.
0042 
0043     Args:
0044         tags: Only items carrying every one of these tags, separated by
0045             commas or spaces, e.g. "ops" or "users pcs". Common tags: users,
0046             ops, dev, testbed, pcs, panda, ddm, alarms.
0047         importance: Only these importance levels, e.g. "urgent,high".
0048             Levels: urgent, high, routine, minor.
0049         since: Only items shipped on or after this date, YYYY-MM-DD.
0050         search: Only items whose title, summary or details contain this text.
0051         limit: Maximum items returned (default 20).
0052         include_details: Also return each item's details and references.
0053 
0054     Returns:
0055         items (newest shipped first), total_count, has_more, tags_in_use
0056         (tag: count, the vocabulary to reuse), and the page URL.
0057     """
0058     @sync_to_async
0059     def run():
0060         from help import whats_new as wn
0061         rows = wn.list_items()
0062         want_tags = _words(tags)
0063         want_imp = _words(importance)
0064         text = (search or '').strip().lower()
0065         out = []
0066         for r in rows:
0067             if want_tags and not set(want_tags) <= set(r['tags']):
0068                 continue
0069             if want_imp and r['importance'] not in want_imp:
0070                 continue
0071             if since and r['shipped'] < since[:10]:
0072                 continue
0073             if text and text not in ' '.join(
0074                     (r['title'], r['summary'], r['details'])).lower():
0075                 continue
0076             item = _brief(r)
0077             if include_details:
0078                 item['details'] = r['details']
0079                 item['refs'] = r['refs']
0080             out.append(item)
0081         n = max(1, min(int(limit or 20), 200))
0082         return {'items': out[:n], 'total_count': len(out),
0083                 'has_more': len(out) > n, 'tags_in_use': wn.tags_in_use(),
0084                 'monitor_urls': [{'title': "What's new",
0085                                   'url': _monitor_url('/help/whats-new/')}]}
0086     return await run()
0087 
0088 
0089 @mcp.tool()
0090 async def whats_new_get(slug: str) -> dict:
0091     """
0092     One What's new item in full: title, summary, details and references
0093     (Markdown), tags, importance, shipped date, contact, the items it builds
0094     on and those that develop it further, the comment thread, and the
0095     number of earlier versions.
0096 
0097     Args:
0098         slug: The item's address, the last part of its URL, e.g.
0099             "help-menu-before-system" (from whats_new_list).
0100 
0101     Returns:
0102         The item, or an error naming the missing slug.
0103     """
0104     @sync_to_async
0105     def run():
0106         from help import whats_new as wn
0107         try:
0108             item = wn.get_item((slug or '').strip())
0109         except wn.WhatsNewError as e:
0110             return {'error': e.detail}
0111         item['version_count'] = len(item.pop('versions'))
0112         item['url'] = _monitor_url(f"/help/whats-new/{item['slug']}/")
0113         return item
0114     return await run()
0115 
0116 
0117 @mcp.tool()
0118 @requires_authority
0119 async def whats_new_add(title: str, summary: str, tags: list[str],
0120                         importance: str, shipped: str, contact: str,
0121                         details: str = '', refs: str = '',
0122                         builds_on: list[str] = None,
0123                         username: str = None) -> dict:
0124     """
0125     Add a What's new item: a development in production that users,
0126     operators or developers should know about. Adding it is part of the
0127     task that ships the change, like updating its documentation; it is
0128     not proposed and waits for no approval. Add it once the change is in
0129     production; check whats_new_list first so an existing item is not
0130     added again (correct it with whats_new_edit instead). The addition is
0131     posted to epicprod-live.
0132 
0133     Args:
0134         title: One line: what changed, in the reader's terms, e.g.
0135             "Help menu in the epicprod menu bar".
0136         summary: One to three lines: what it does and who it is for.
0137         tags: Topical tags: the primary audience (users, ops, dev) and the
0138             area (pcs, panda, testbed, ddm, alarms, ...). Reuse the tags in
0139             use (whats_new_list returns them).
0140         importance: urgent (readers must act), high, routine, or minor.
0141         shipped: The date the change reached production, YYYY-MM-DD.
0142         contact: The account of the principal developer, an account with
0143             the operations role.
0144         details: Optional Markdown: how to use it, what it replaces, limits.
0145         refs: Markdown: links to pages, documents, pull requests. An item
0146             on the operation or use of the system links first the section of
0147             the WFMS documentation (https://epic-wfms-docs.readthedocs.io)
0148             where its impact is described.
0149         builds_on: Optional slugs of earlier items this one develops further.
0150         username: The person whose work the item records, recorded as who
0151             added it. Through epic-devcloud.org it is the signed-in caller
0152             and need not be given.
0153 
0154     Returns:
0155         The item's slug and URL, or the reason it was refused.
0156     """
0157     @sync_to_async
0158     def run():
0159         from help import whats_new as wn
0160         try:
0161             who = _get_username(username)
0162         except RuntimeError as e:
0163             return {'success': False, 'error': str(e)}
0164         fields = {'title': title, 'summary': summary, 'details': details or '',
0165                   'refs': refs or '', 'tags': tags, 'importance': importance,
0166                   'shipped': shipped, 'contact': contact,
0167                   'builds_on': builds_on or []}
0168         try:
0169             entry, _log_id = wn.item_create(fields, changed_by=who)
0170         except wn.WhatsNewError as e:
0171             return {'success': False, 'error': e.detail}
0172         return {'success': True, 'slug': entry.name,
0173                 'url': _monitor_url(f'/help/whats-new/{entry.name}/')}
0174     return await run()
0175 
0176 
0177 @mcp.tool()
0178 @requires_authority
0179 async def whats_new_edit(slug: str, title: str = None, summary: str = None,
0180                          details: str = None, refs: str = None,
0181                          tags: list[str] = None, importance: str = None,
0182                          shipped: str = None, contact: str = None,
0183                          builds_on: list[str] = None,
0184                          username: str = None) -> dict:
0185     """
0186     Edit an existing What's new item: any field given replaces the
0187     current value; fields left out are unchanged. The previous state is
0188     kept as a version attributed to the editing person.
0189 
0190     Args:
0191         slug: The item's address (from whats_new_list).
0192         title, summary, details, refs, tags, importance, shipped, contact,
0193             builds_on: New values; see whats_new_add for each field.
0194         username: The person editing. Through epic-devcloud.org it is the
0195             signed-in caller and need not be given.
0196 
0197     Returns:
0198         The item's slug and URL, or the reason the edit was refused.
0199     """
0200     @sync_to_async
0201     def run():
0202         from help import whats_new as wn
0203         try:
0204             who = _get_username(username)
0205         except RuntimeError as e:
0206             return {'success': False, 'error': str(e)}
0207         fields = {k: v for k, v in {
0208             'title': title, 'summary': summary, 'details': details,
0209             'refs': refs, 'tags': tags, 'importance': importance,
0210             'shipped': shipped, 'contact': contact, 'builds_on': builds_on,
0211         }.items() if v is not None}
0212         if not fields:
0213             return {'success': False, 'error': 'no fields to change'}
0214         try:
0215             wn.item_edit((slug or '').strip(), fields, changed_by=who)
0216         except wn.WhatsNewError as e:
0217             return {'success': False, 'error': e.detail}
0218         return {'success': True, 'slug': slug,
0219                 'url': _monitor_url(f'/help/whats-new/{slug}/')}
0220     return await run()