mlai-code 0.3.1 → 0.3.3
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/README.md +1 -1
- package/package.json +2 -2
- package/src/cli.mjs +27 -7
- package/src/distribution.mjs +5 -5
- package/src/engine-key.mjs +18 -4
- package/src/engine.mjs +4 -9
- package/src/home.mjs +1 -1
- package/src/parity.mjs +3 -1
- package/src/render.mjs +3 -1
- package/src/runtime.mjs +21 -1
- package/src/sandbox.mjs +19 -3
- package/src/session.mjs +22 -2
- package/src/shared-data.mjs +1 -1
- package/src/tui/app.mjs +22 -4
- package/src/tui/chat.mjs +8 -6
- package/src/tui/cmd-core.mjs +2 -2
- package/src/tui/cmd-extensibility.mjs +8 -2
- package/src/tui/commands.mjs +2 -1
- package/src/tui/statusline.mjs +2 -1
- package/src/wakeups.mjs +2 -2
- package/vendor/client-sdk/index.cjs +3 -3
- package/vendor/cloud-cli/mlai.mjs +169 -25
- package/worker/build_planner.py +75 -7
- package/worker/cloud_pty.py +91 -2
- package/worker/command_safety.py +25 -1
- package/worker/compaction_brief.py +186 -0
- package/worker/context_manager.py +9 -3
- package/worker/conversation.py +58 -1
- package/worker/deck_render.js +11 -0
- package/worker/deck_tools.py +825 -0
- package/worker/git_sync.py +38 -13
- package/worker/goals.py +4 -0
- package/worker/image_generation.py +102 -23
- package/worker/kimi_bridge.py +406 -40
- package/worker/kimi_gates.py +84 -1
- package/worker/kimi_hook.py +113 -12
- package/worker/media_tools.py +179 -0
- package/worker/memory.py +2 -2
- package/worker/mlai_hooks.py +93 -3
- package/worker/mlai_mcp.py +23 -5
- package/worker/model_stream.py +21 -7
- package/worker/obs_mask.py +97 -0
- package/worker/offline_guard.py +1 -1
- package/worker/preview.py +47 -4
- package/worker/product_facts.py +18 -0
- package/worker/project_context.py +33 -7
- package/worker/reply_language.py +92 -10
- package/worker/roles.json +199 -37
- package/worker/roles.py +243 -8
- package/worker/runner.py +253 -42
- package/worker/site_check.py +279 -0
- package/worker/skill_library.py +15 -3
- package/worker/skill_pack.py +170 -16
- package/worker/tool_catalog.py +3 -2
- package/worker/verification.py +43 -11
- package/worker/wakeups.py +56 -4
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""Site integrity checks for build runs: navigation that points at pages that do not exist, a preview that answers
|
|
2
|
+
with a server error, and a final message that reports an open error while calling the work verified.
|
|
3
|
+
|
|
4
|
+
Bug report (Nov 16 2026): asked for a 10-page marketing site, the agent built 2 pages, left 7 navigation links that
|
|
5
|
+
404, wrote "The page itself is now 500ing" and then "Phase 1 is complete and verified". Each of these is now a
|
|
6
|
+
blocking finding, so the final gate sends the agent back to fix it (and the run continues automatically when the
|
|
7
|
+
repair rounds run out).
|
|
8
|
+
|
|
9
|
+
dead_links(repo, changed) -> findings for internal links in changed files whose route does not exist
|
|
10
|
+
live_routes(routes, base_url) -> [(route, status)] for routes the running preview answers with 404 or 5xx
|
|
11
|
+
open_error_claim(text) -> findings when the final message admits an open error yet claims done/verified
|
|
12
|
+
requested_scope(task) -> {'count', 'unit'} when the request names how many pages/screens it wants
|
|
13
|
+
"""
|
|
14
|
+
import os, re, time, urllib.request, urllib.error
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
SKIP_DIRS = frozenset(('.git', 'node_modules', '.next', 'dist', 'build', 'out', '.venv', 'venv', '__pycache__', '.mini', '.vercel', '.turbo', 'coverage', '.svelte-kit', '.astro', '.output'))
|
|
18
|
+
SOURCE = re.compile(r'\.(?:html?|[cm]?[jt]sx?|vue|svelte|astro|mdx?)$', re.I)
|
|
19
|
+
PAGE_EXT = r'(?:[cm]?[jt]sx?|mdx?)'
|
|
20
|
+
# href="/about", href='/about', href={'/about'}, href={"/about"}, href={`/about`}, to="/about", Link href: '/about' in nav arrays.
|
|
21
|
+
LINK = re.compile(r'''(?:\bhref|\bto)\s*=\s*\{?\s*["'`](/[^"'`\s{}$]*)["'`]|\b(?:href|path|url|link|to)\s*:\s*["'`](/[^"'`\s{}$]*)["'`]''')
|
|
22
|
+
ASSET = re.compile(r'\.(?:png|jpe?g|gif|svg|webp|avif|ico|css|js|mjs|map|json|xml|txt|pdf|woff2?|ttf|otf|mp4|webm|mp3|wav|zip|webmanifest)$', re.I)
|
|
23
|
+
MAX_FILES, MAX_BYTES = 600, 400000
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _walk(repo, limit=4000):
|
|
27
|
+
root = Path(repo)
|
|
28
|
+
count = 0
|
|
29
|
+
for base, dirs, files in os.walk(root):
|
|
30
|
+
dirs[:] = [d for d in dirs if d not in SKIP_DIRS and not d.startswith('.')]
|
|
31
|
+
for name in files:
|
|
32
|
+
count += 1
|
|
33
|
+
if count > limit: return
|
|
34
|
+
yield Path(base) / name
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _norm(route):
|
|
38
|
+
route = route.split('#', 1)[0].split('?', 1)[0]
|
|
39
|
+
route = re.sub(r'/{2,}', '/', route)
|
|
40
|
+
if len(route) > 1: route = route.rstrip('/')
|
|
41
|
+
return route or '/'
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _segment_pattern(seg):
|
|
45
|
+
if re.fullmatch(r'\[\[?\.\.\.[^\]]+\]\]?', seg): return '(?:/.*)?' if seg.startswith('[[') else '/.+'
|
|
46
|
+
if re.fullmatch(r'\[[^\]]+\]', seg) or re.fullmatch(r'\$[\w-]*', seg) or seg.startswith(':'): return '/[^/]+'
|
|
47
|
+
return '/' + re.escape(seg)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _pattern(parts):
|
|
51
|
+
parts = [p for p in parts if p and not (p.startswith('(') and p.endswith(')')) and not p.startswith('@') and p != 'index']
|
|
52
|
+
if not parts: return '/'
|
|
53
|
+
return ''.join(_segment_pattern(p) for p in parts)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def known_routes(repo):
|
|
57
|
+
"""(patterns, frameworks): regex patterns for routes the project defines, and which routers were recognised.
|
|
58
|
+
No recognised router means the check cannot judge links, so it reports nothing."""
|
|
59
|
+
root = Path(repo)
|
|
60
|
+
patterns, kinds = set(), set()
|
|
61
|
+
deps = _deps(root)
|
|
62
|
+
# A single-page app (React, Vue, Svelte without a file router) serves index.html for every route; its routes live
|
|
63
|
+
# in the client router, so only that router can say which links are real.
|
|
64
|
+
spa = bool(deps & {'react', 'vue', 'svelte', 'solid-js', 'preact', 'react-dom'}) and not (deps & {'next', 'astro', '@sveltejs/kit', '@remix-run/react', 'gatsby', 'nuxt', '@react-router/dev', 'vitepress'})
|
|
65
|
+
for path in _walk(repo):
|
|
66
|
+
rel = path.relative_to(root).as_posix()
|
|
67
|
+
parts = rel.split('/')
|
|
68
|
+
name = parts[-1]
|
|
69
|
+
# Next.js app router: app/**/page.tsx (also src/app). Route groups and parallel slots do not add a segment.
|
|
70
|
+
for prefix in ('app', 'src/app'):
|
|
71
|
+
pre = prefix.split('/')
|
|
72
|
+
if parts[:len(pre)] == pre and re.fullmatch(r'(?:page|route)\.' + PAGE_EXT, name):
|
|
73
|
+
segs = parts[len(pre):-1]
|
|
74
|
+
if segs[:1] == ['api']: continue
|
|
75
|
+
patterns.add(_pattern(segs)); kinds.add('next-app')
|
|
76
|
+
# Next.js pages router: pages/about.tsx, pages/blog/index.tsx (also src/pages). Astro: src/pages/*.astro.
|
|
77
|
+
for prefix in ('pages', 'src/pages'):
|
|
78
|
+
pre = prefix.split('/')
|
|
79
|
+
if parts[:len(pre)] == pre and re.search(r'\.(?:' + PAGE_EXT + r'|astro|html?)$', name, re.I):
|
|
80
|
+
segs = parts[len(pre):]
|
|
81
|
+
if segs[:1] == ['api'] or name.startswith('_'): continue
|
|
82
|
+
segs[-1] = re.sub(r'\.[^.]+$', '', segs[-1])
|
|
83
|
+
patterns.add(_pattern(segs)); kinds.add('pages')
|
|
84
|
+
# SvelteKit: src/routes/**/+page.svelte
|
|
85
|
+
if parts[:2] == ['src', 'routes'] and name.startswith('+page.'):
|
|
86
|
+
patterns.add(_pattern(parts[2:-1])); kinds.add('sveltekit')
|
|
87
|
+
# Remix flat routes: app/routes/about.tsx, app/routes/blog.$slug.tsx, app/routes/_index.tsx
|
|
88
|
+
if parts[:2] == ['app', 'routes'] and len(parts) == 3 and re.search(r'\.' + PAGE_EXT + '$', name):
|
|
89
|
+
stem = re.sub(r'\.[^.]+$', '', name)
|
|
90
|
+
segs = [s for s in stem.split('.') if s and not s.startswith('_')]
|
|
91
|
+
patterns.add(_pattern(segs)); kinds.add('remix')
|
|
92
|
+
# Static sites: about.html, about/index.html, public/about.html.
|
|
93
|
+
if re.search(r'\.html?$', name, re.I) and parts[0] not in ('src',) and 'node_modules' not in parts:
|
|
94
|
+
segs = parts[1:] if parts[0] in ('public', 'static', 'site', 'docs') else parts
|
|
95
|
+
stem = re.sub(r'\.html?$', '', segs[-1], flags=re.I)
|
|
96
|
+
if stem == '404' or stem.startswith('_'): continue
|
|
97
|
+
route = segs[:-1] + ([] if stem == 'index' else [stem])
|
|
98
|
+
patterns.add(_pattern(route))
|
|
99
|
+
if stem != 'index': patterns.add(_pattern(segs[:-1] + [segs[-1]]))
|
|
100
|
+
kinds.add('static')
|
|
101
|
+
# Client routers: <Route path="/about">, { path: '/about' } in a router file.
|
|
102
|
+
if SOURCE.search(name) and (spa and parts[0] == 'src' or re.search(r'route', rel, re.I) or name in ('App.tsx', 'App.jsx', 'main.tsx', 'main.jsx', 'router.ts', 'router.tsx')):
|
|
103
|
+
text = _read(path)
|
|
104
|
+
if text and re.search(r'react-router|createBrowserRouter|<Route\b|vue-router|createRouter', text):
|
|
105
|
+
for m in re.finditer(r'''\bpath\s*[:=]\s*\{?\s*["'`](/?[^"'`]*)["'`]''', text):
|
|
106
|
+
raw = m.group(1)
|
|
107
|
+
if raw in ('*', '/*'): patterns.add('/.*')
|
|
108
|
+
else: patterns.add(_pattern([s for s in raw.strip('/').split('/') if s != '*']) + ('(?:/.*)?' if raw.endswith('*') else ''))
|
|
109
|
+
kinds.add('client-router')
|
|
110
|
+
if spa and 'client-router' not in kinds:
|
|
111
|
+
return set(), set() # routes are decided at runtime somewhere we cannot read: do not judge links
|
|
112
|
+
# Rewrites and redirects make a source path real even without a page file.
|
|
113
|
+
for cfg in ('next.config.js', 'next.config.mjs', 'next.config.ts', 'next.config.cjs', 'vercel.json', 'netlify.toml', '_redirects', 'public/_redirects'):
|
|
114
|
+
text = _read(root / cfg)
|
|
115
|
+
if not text: continue
|
|
116
|
+
for m in re.finditer(r'''["']?(?:source|from)["']?\s*[:=]\s*["'](/[^"']*)["']''', text):
|
|
117
|
+
patterns.add(re.sub(r'/:[\w]+[*+?]?', '/[^/]+', re.escape(m.group(1)).replace('\\/', '/').replace('\\:', ':')).replace('\\(\\.\\*\\)', '.*') + '(?:/.*)?')
|
|
118
|
+
if cfg.endswith('_redirects'):
|
|
119
|
+
for line in text.splitlines():
|
|
120
|
+
bits = line.split()
|
|
121
|
+
if bits and bits[0].startswith('/'): patterns.add(re.escape(bits[0]).replace('\\*', '.*'))
|
|
122
|
+
return patterns, kinds
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _deps(root):
|
|
126
|
+
try:
|
|
127
|
+
import json
|
|
128
|
+
data = json.loads(_read(Path(root) / 'package.json') or '{}')
|
|
129
|
+
return {k for key in ('dependencies', 'devDependencies') for k in (data.get(key) or {})} if isinstance(data, dict) else set()
|
|
130
|
+
except ValueError:
|
|
131
|
+
return set()
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _read(path):
|
|
135
|
+
try:
|
|
136
|
+
path = Path(path)
|
|
137
|
+
if not path.is_file() or path.is_symlink() or path.stat().st_size > MAX_BYTES: return ''
|
|
138
|
+
return path.read_text(errors='replace')
|
|
139
|
+
except OSError:
|
|
140
|
+
return ''
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def internal_links(repo, paths):
|
|
144
|
+
"""{route: [files]} for site-internal links written in the given files."""
|
|
145
|
+
found = {}
|
|
146
|
+
for rel in list(paths or [])[:MAX_FILES]:
|
|
147
|
+
if not SOURCE.search(str(rel)) or re.search(r'(^|/)(tests?|__tests__|e2e|node_modules)/|\.(test|spec)\.', str(rel)): continue
|
|
148
|
+
text = _read(Path(repo) / rel)
|
|
149
|
+
for m in LINK.finditer(text):
|
|
150
|
+
raw = m.group(1) or m.group(2)
|
|
151
|
+
if not raw or raw.startswith('//'): continue
|
|
152
|
+
route = _norm(raw)
|
|
153
|
+
if route.startswith(('/api/', '/_next/', '/static/', '/assets/', '/images/', '/img/', '/fonts/')) or route == '/api' or ASSET.search(route): continue
|
|
154
|
+
if '[' in route or ':' in route: continue # a route template, not a link
|
|
155
|
+
found.setdefault(route, [])
|
|
156
|
+
if rel not in found[route]: found[route].append(rel)
|
|
157
|
+
return found
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def missing_routes(repo, changed):
|
|
161
|
+
"""[(route, files)] for links in changed files that no page, route or rewrite in the project serves."""
|
|
162
|
+
links = internal_links(repo, changed)
|
|
163
|
+
if not links: return []
|
|
164
|
+
patterns, kinds = known_routes(repo)
|
|
165
|
+
if not kinds: return []
|
|
166
|
+
compiled = [re.compile('^' + p + '$') for p in patterns]
|
|
167
|
+
out = []
|
|
168
|
+
for route, files in sorted(links.items()):
|
|
169
|
+
if any(c.match(route) for c in compiled): continue
|
|
170
|
+
# Static sites also serve files dropped in public/ (for example /resume.pdf is filtered above as an asset).
|
|
171
|
+
if 'static' in kinds and ((Path(repo) / route.lstrip('/')).exists() or (Path(repo) / 'public' / route.lstrip('/')).exists()): continue
|
|
172
|
+
out.append((route, files))
|
|
173
|
+
return out
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def dead_links(repo, changed):
|
|
177
|
+
gone = missing_routes(repo, changed)
|
|
178
|
+
if not gone: return []
|
|
179
|
+
listed = ', '.join(r + ' (' + f[0] + ')' for r, f in gone[:10]) + (' and %d more' % (len(gone) - 10) if len(gone) > 10 else '')
|
|
180
|
+
return [{'kind': 'dead_link', 'severity': 'block', 'routes': [r for r, _ in gone][:40],
|
|
181
|
+
'message': 'Links point to pages that do not exist: ' + listed + '. Build every page the user asked for, with real content, '
|
|
182
|
+
'or remove the link until the page exists. Navigation must never lead to a 404. Then open each route in the preview to confirm it loads.'}]
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def live_routes(routes, base_url='http://127.0.0.1:3000', timeout=25, budget=120):
|
|
186
|
+
"""[(route, status)] for routes the running preview answers with 404 or a server error. Empty when nothing listens."""
|
|
187
|
+
class NoRedirect(urllib.request.HTTPRedirectHandler):
|
|
188
|
+
def redirect_request(self, *args, **kwargs): return None
|
|
189
|
+
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}), NoRedirect())
|
|
190
|
+
def get(route):
|
|
191
|
+
try:
|
|
192
|
+
with opener.open(base_url + route, timeout=timeout) as r: return r.status
|
|
193
|
+
except urllib.error.HTTPError as e:
|
|
194
|
+
e.close(); return e.code
|
|
195
|
+
except (OSError, urllib.error.URLError, ValueError): return None
|
|
196
|
+
start = time.time()
|
|
197
|
+
first = get('/')
|
|
198
|
+
if first is None: return [] # no preview running: nothing to judge
|
|
199
|
+
bad = [('/', first)] if first >= 500 else []
|
|
200
|
+
for route in [r for r in routes if r != '/'][:20]:
|
|
201
|
+
if time.time() - start > budget: break
|
|
202
|
+
code = get(route)
|
|
203
|
+
if code is not None and (code == 404 or code >= 500): bad.append((route, code))
|
|
204
|
+
return bad
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def live_findings(bad):
|
|
208
|
+
if not bad: return []
|
|
209
|
+
errors = [b for b in bad if b[1] >= 500]; missing = [b for b in bad if b[1] == 404]
|
|
210
|
+
parts = []
|
|
211
|
+
if errors: parts.append('server errors on ' + ', '.join('%s (HTTP %d)' % b for b in errors[:8]))
|
|
212
|
+
if missing: parts.append('404 on linked pages ' + ', '.join(r for r, _ in missing[:10]))
|
|
213
|
+
return [{'kind': 'preview_errors', 'severity': 'block', 'routes': [r for r, _ in bad][:40],
|
|
214
|
+
'message': 'The running preview returns ' + '; '.join(parts) + '. Read the preview log, fix the cause, and load each route again until it answers 200. '
|
|
215
|
+
'If it truly cannot be fixed in this run, say plainly that it is still broken; do not call the work complete or verified.'}]
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
# ------------------------------------------------------------------ final-message honesty
|
|
219
|
+
_OPEN_ERROR = re.compile(
|
|
220
|
+
r"\b(?:is|are|was|were|keeps?|still|now)?\s*(?:5\d\d(?:ing|s)\b|returns?\s+(?:an?\s+)?(?:HTTP\s+)?5\d\d|(?:HTTP\s+)?5\d\d\s+(?:error|status|response)s?|internal server error|"
|
|
221
|
+
r"404(?:s|ing)?\s+for\s+now|(?:still|now|currently)\s+(?:broken|crashing|crashes|failing|fails|erroring|errors|down|blank|404s?))\b", re.I)
|
|
222
|
+
_RESOLVED = re.compile(r"\b(?:fixed|resolved|no longer|used to|previously|before (?:the|my|this) fix|was causing|caused|turned out|root cause|now (?:returns?|loads?|answers?|serves?) (?:a )?(?:200|fine|correctly|ok))\b", re.I)
|
|
223
|
+
_DONE = re.compile(r"\b(?:complete[d]?|done|finished|verified|fully working|all working|ready (?:to|for)|shipped|all set|good to go|works? end[\s-]to[\s-]end)\b", re.I)
|
|
224
|
+
_NOT_DONE = re.compile(r"\b(?:not (?:yet )?(?:complete|done|finished|verified)|isn'?t (?:complete|done|verified)|unverified|incomplete|still open|remains? open|unresolved)\b", re.I)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def _sentences(text):
|
|
228
|
+
return [s.strip() for s in re.split(r'(?<=[.!?])\s+|\n+', str(text or '')) if s.strip()]
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def open_error_claim(text):
|
|
232
|
+
"""A final message that reports an unresolved error and also calls the work complete or verified."""
|
|
233
|
+
sentences = _sentences(text)
|
|
234
|
+
errors = [s for s in sentences if _OPEN_ERROR.search(s) and not _RESOLVED.search(s)]
|
|
235
|
+
if not errors: return []
|
|
236
|
+
if any(_NOT_DONE.search(s) for s in sentences): return [] # the message already reports it as open
|
|
237
|
+
done = [s for s in sentences if _DONE.search(s) and not _OPEN_ERROR.search(s)]
|
|
238
|
+
if not done: return []
|
|
239
|
+
return [{'kind': 'open_error_claim', 'severity': 'block',
|
|
240
|
+
'message': 'The final message reports an open error ("' + errors[0][:160] + '") but also says the work is finished or verified ("' + done[0][:120] + '"). '
|
|
241
|
+
'Fix the error and check the affected page again. If it cannot be fixed now, report it as unresolved and do not call the work complete or verified.'}]
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
# ------------------------------------------------------------------ requested scope
|
|
245
|
+
_NUMBERS = {'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9, 'ten': 10, 'eleven': 11, 'twelve': 12,
|
|
246
|
+
'fifteen': 15, 'twenty': 20, 'a dozen': 12, 'dozen': 12}
|
|
247
|
+
_UNITS = r'(?:pages?|screens?|routes?|views?|sections?|landing\s+pages?|templates?|tabs?|steps?|endpoints?|components?|blog\s+posts?|posts?|articles?)'
|
|
248
|
+
_SCOPE = re.compile(r'\b(\d{1,3}|' + '|'.join(sorted(map(re.escape, _NUMBERS), key=len, reverse=True)) + r')[\s-]+(?:\w+[\s-]+){0,2}?(' + _UNITS + r')\b', re.I)
|
|
249
|
+
_LIST = re.compile(r'\bpages?\s*(?::|including|like|such as|for)\s*([^\n.]{3,300})', re.I)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def requested_scope(task):
|
|
253
|
+
"""What the person explicitly asked for: {'count': 10, 'unit': 'pages', 'names': [...]}, or None."""
|
|
254
|
+
text = str(task or '')[-6000:]
|
|
255
|
+
best = None
|
|
256
|
+
for m in _SCOPE.finditer(text):
|
|
257
|
+
raw = m.group(1).lower()
|
|
258
|
+
count = int(raw) if raw.isdigit() else _NUMBERS.get(raw)
|
|
259
|
+
if not count or count < 2 or count > 200: continue
|
|
260
|
+
unit = re.sub(r'\s+', ' ', m.group(2).lower())
|
|
261
|
+
if not unit.endswith('s'): unit += 's'
|
|
262
|
+
if best is None or count > best['count']: best = {'count': count, 'unit': unit, 'names': []}
|
|
263
|
+
lst = _LIST.search(text)
|
|
264
|
+
if lst:
|
|
265
|
+
names = [n.strip(' "\'`') for n in re.split(r',|\band\b|/|;', lst.group(1)) if 1 < len(n.strip(' "\'`')) < 40][:40]
|
|
266
|
+
if len(names) >= 2:
|
|
267
|
+
if best is None: best = {'count': len(names), 'unit': 'pages', 'names': names}
|
|
268
|
+
else: best['names'] = names
|
|
269
|
+
return best
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
def scope_rule(scope):
|
|
273
|
+
"""Prompt text that makes an explicit request binding for this run."""
|
|
274
|
+
if not scope: return ''
|
|
275
|
+
names = (' (' + ', '.join(scope['names']) + ')') if scope.get('names') else ''
|
|
276
|
+
return ('Requested scope: the user asked for %d %s%s. Deliver all %d in this run, each with real, finished content and working navigation; when you plan phases, Phase 1 contains every one of them. '
|
|
277
|
+
'Do not split the requested %s across phases and do not stop after a subset; later phases may only add work beyond what was asked '
|
|
278
|
+
'(polish, integrations, extras). If it truly cannot fit, say so before you start and ask how to proceed; never decide on your own to deliver part of it. '
|
|
279
|
+
'Before finishing, open every %s in the preview and confirm each loads without errors.' % (scope['count'], scope['unit'], names, scope['count'], scope['unit'], scope['unit'].rstrip('s')))
|
package/worker/skill_library.py
CHANGED
|
@@ -6,7 +6,7 @@ from pathlib import Path
|
|
|
6
6
|
|
|
7
7
|
MAX_BODY = 20000
|
|
8
8
|
MAX_AUTO = 3
|
|
9
|
-
MAX_CATALOG =
|
|
9
|
+
MAX_CATALOG = 90
|
|
10
10
|
_ID = re.compile(r'^[a-z0-9][a-z0-9-]{0,59}$')
|
|
11
11
|
|
|
12
12
|
def _clean(skill, source):
|
|
@@ -17,6 +17,7 @@ def _clean(skill, source):
|
|
|
17
17
|
return {'id': skill['id'], 'name': str(skill.get('name') or skill['id'])[:100], 'description': str(skill.get('description') or '')[:300],
|
|
18
18
|
'content': skill['content'][:MAX_BODY], 'triggers': words('triggers'), 'paths': words('paths'),
|
|
19
19
|
'files': {str(k)[:80]: str(v)[:MAX_BODY] for k, v in list(files.items())[:10] if isinstance(v, str)},
|
|
20
|
+
'requires': [str(x)[:60] for x in (skill.get('requires') or []) if isinstance(x, str)][:3],
|
|
20
21
|
'always': skill.get('always') is True, 'enabled': skill.get('enabled', True) is not False, 'source': source}
|
|
21
22
|
|
|
22
23
|
def load_skills(root):
|
|
@@ -75,6 +76,16 @@ def select(task, skills, limit=MAX_AUTO, preferred=()):
|
|
|
75
76
|
if hits:
|
|
76
77
|
scored.append((hits, s))
|
|
77
78
|
scored.sort(key=lambda x: (-x[0], x[1]['id']))
|
|
79
|
+
out = _select(explicit, always, scored, skills, limit, preferred)
|
|
80
|
+
# A companion skill brings the skill it builds on (deck-types needs presentations), ahead of it.
|
|
81
|
+
by_id = {s['id']: s for s in skills}
|
|
82
|
+
for s in list(out):
|
|
83
|
+
for need in s.get('requires') or ():
|
|
84
|
+
if need in by_id and by_id[need] not in out:
|
|
85
|
+
out.insert(out.index(s), by_id[need])
|
|
86
|
+
return out
|
|
87
|
+
|
|
88
|
+
def _select(explicit, always, scored, skills, limit, preferred):
|
|
78
89
|
if preferred:
|
|
79
90
|
# Role skills come first (up to 3), then the strongest trigger matches fill the remaining slots.
|
|
80
91
|
by_id = {s['id']: s for s in skills}
|
|
@@ -85,7 +96,8 @@ def select(task, skills, limit=MAX_AUTO, preferred=()):
|
|
|
85
96
|
|
|
86
97
|
def catalog(skills, loaded=()):
|
|
87
98
|
names = {s['id'] for s in loaded}
|
|
88
|
-
|
|
99
|
+
ordered = [s for s in skills if s.get('source') != 'pack'] + [s for s in skills if s.get('source') == 'pack'] # the project's own skills never fall off the end
|
|
100
|
+
rows = ['- ' + s['id'] + ': ' + (s['description'] or s['name'])[:160] + (' (loaded)' if s['id'] in names else '') for s in ordered[:MAX_CATALOG]]
|
|
89
101
|
return '\n'.join(rows)
|
|
90
102
|
|
|
91
103
|
def body(skill):
|
|
@@ -108,7 +120,7 @@ def load(skills, args):
|
|
|
108
120
|
raise ValueError('Provide a skill id')
|
|
109
121
|
skill = next((s for s in skills if s['id'] == args['id']), None)
|
|
110
122
|
if not skill:
|
|
111
|
-
raise ValueError('Unknown or disabled skill. Available: ' + ', '.join(s['id'] for s in skills[:
|
|
123
|
+
raise ValueError('Unknown or disabled skill. Available: ' + ', '.join(s['id'] for s in skills[:MAX_CATALOG]))
|
|
112
124
|
name = args.get('file')
|
|
113
125
|
if name is not None:
|
|
114
126
|
if not isinstance(name, str) or name not in skill['files']:
|