mlai-code 0.3.2 → 0.3.4
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 +1 -1
- package/src/checkpoints.mjs +217 -0
- package/src/cli.mjs +178 -31
- package/src/cloud.mjs +2 -0
- package/src/engine.mjs +1 -1
- package/src/headless.mjs +25 -9
- package/src/home.mjs +3 -2
- package/src/host.mjs +141 -13
- package/src/ide-quick.mjs +147 -0
- package/src/ide.mjs +182 -0
- package/src/netbox.mjs +1 -1
- package/src/parity.mjs +20 -1
- package/src/relay.mjs +1 -1
- package/src/render.mjs +12 -3
- package/src/runtime.mjs +23 -1
- package/src/sandbox.mjs +19 -3
- package/src/server.mjs +46 -7
- package/src/session.mjs +53 -10
- package/src/shared-data.mjs +1 -1
- package/src/tui/acp.mjs +121 -19
- package/src/tui/app.mjs +24 -5
- package/src/tui/chat.mjs +43 -16
- package/src/tui/cmd-config.mjs +3 -1
- package/src/tui/cmd-core.mjs +11 -7
- package/src/tui/cmd-extensibility.mjs +13 -2
- package/src/tui/commands.mjs +2 -1
- package/src/tui/extensions-local.mjs +2 -0
- package/src/tui/mcp-config.mjs +22 -4
- package/src/tui/review-cli.mjs +15 -4
- package/src/tui/snapshots.mjs +57 -16
- package/src/tui/statusline.mjs +2 -1
- package/src/two-words.mjs +14 -8
- package/src/view-sync.mjs +48 -0
- package/src/wakeups.mjs +2 -2
- package/src/winenv.mjs +1 -1
- package/src/workspace-api.mjs +21 -4
- package/vendor/client-sdk/index.cjs +5 -4
- package/vendor/cloud-cli/mlai.mjs +184 -28
- package/worker/architecture_worker.py +33 -4
- package/worker/browser_tool.py +19 -1
- package/worker/build_planner.py +75 -7
- package/worker/chat_fork.py +4 -1
- package/worker/checkpoints.py +71 -8
- package/worker/cloud_pty.py +91 -2
- package/worker/command_safety.py +80 -3
- package/worker/compaction_brief.py +186 -0
- package/worker/connected_turn.py +30 -0
- package/worker/context_manager.py +6 -0
- package/worker/conversation.py +139 -12
- package/worker/deck_render.js +11 -0
- package/worker/deck_tools.py +825 -0
- package/worker/git_sync.py +42 -17
- package/worker/goals.py +4 -0
- package/worker/image_generation.py +102 -23
- package/worker/kimi_bridge.py +580 -52
- package/worker/kimi_gates.py +74 -6
- package/worker/kimi_hook.py +213 -19
- package/worker/media_tools.py +182 -0
- package/worker/memory.py +2 -2
- package/worker/mlai_hooks.py +314 -5
- package/worker/mlai_mcp.py +49 -11
- package/worker/mlai_review/README.md +35 -0
- package/worker/mlai_review/__init__.py +1 -0
- package/worker/mlai_review/__main__.py +261 -0
- package/worker/mlai_review/_compat.py +29 -0
- package/worker/mlai_review/analysis/__init__.py +3 -0
- package/worker/mlai_review/analysis/detect.py +50 -0
- package/worker/mlai_review/analysis/main.py +128 -0
- package/worker/mlai_review/analysis/messages.py +8 -0
- package/worker/mlai_review/analysis/tools.py +194 -0
- package/worker/mlai_review/application/__init__.py +1 -0
- package/worker/mlai_review/application/asking.py +53 -0
- package/worker/mlai_review/application/challengers.py +142 -0
- package/worker/mlai_review/application/context_builder.py +194 -0
- package/worker/mlai_review/application/errors.py +17 -0
- package/worker/mlai_review/application/feedback.py +52 -0
- package/worker/mlai_review/application/matching.py +46 -0
- package/worker/mlai_review/application/messages.py +41 -0
- package/worker/mlai_review/application/ports.py +222 -0
- package/worker/mlai_review/application/prompts.py +342 -0
- package/worker/mlai_review/application/review_service.py +200 -0
- package/worker/mlai_review/application/reviewers.py +438 -0
- package/worker/mlai_review/application/streaming.py +91 -0
- package/worker/mlai_review/application/tools.py +138 -0
- package/worker/mlai_review/application/usage.py +145 -0
- package/worker/mlai_review/application/write_check.py +46 -0
- package/worker/mlai_review/contracts/__init__.py +5 -0
- package/worker/mlai_review/contracts/analysis.py +57 -0
- package/worker/mlai_review/contracts/review.py +42 -0
- package/worker/mlai_review/domain/__init__.py +4 -0
- package/worker/mlai_review/domain/changes.py +77 -0
- package/worker/mlai_review/domain/context.py +147 -0
- package/worker/mlai_review/domain/diagnostics.py +239 -0
- package/worker/mlai_review/domain/feedback.py +216 -0
- package/worker/mlai_review/domain/findings.py +505 -0
- package/worker/mlai_review/domain/lifecycle.py +85 -0
- package/worker/mlai_review/domain/partition.py +42 -0
- package/worker/mlai_review/domain/relations.py +166 -0
- package/worker/mlai_review/domain/relevance.py +202 -0
- package/worker/mlai_review/domain/report.py +99 -0
- package/worker/mlai_review/domain/structure.py +56 -0
- package/worker/mlai_review/domain/writes.py +86 -0
- package/worker/mlai_review/eval.py +221 -0
- package/worker/mlai_review/eval_cases/clean-rename.json +11 -0
- package/worker/mlai_review/eval_cases/missing-ownership-check.json +22 -0
- package/worker/mlai_review/eval_cases/off-by-one.json +22 -0
- package/worker/mlai_review/eval_cases/sql-injection.json +20 -0
- package/worker/mlai_review/feedback_report.py +60 -0
- package/worker/mlai_review/infrastructure/__init__.py +1 -0
- package/worker/mlai_review/infrastructure/analysis/__init__.py +1 -0
- package/worker/mlai_review/infrastructure/analysis/none.py +12 -0
- package/worker/mlai_review/infrastructure/analysis/translate.py +17 -0
- package/worker/mlai_review/infrastructure/github/__init__.py +0 -0
- package/worker/mlai_review/infrastructure/github/client.py +445 -0
- package/worker/mlai_review/infrastructure/github/feedback.py +212 -0
- package/worker/mlai_review/infrastructure/github/http.py +31 -0
- package/worker/mlai_review/infrastructure/github/rendering.py +398 -0
- package/worker/mlai_review/infrastructure/github/token.py +20 -0
- package/worker/mlai_review/infrastructure/local/__init__.py +1 -0
- package/worker/mlai_review/infrastructure/local/analyzer.py +48 -0
- package/worker/mlai_review/infrastructure/local/events.py +100 -0
- package/worker/mlai_review/infrastructure/local/git_reader.py +233 -0
- package/worker/mlai_review/infrastructure/local/publisher.py +138 -0
- package/worker/mlai_review/infrastructure/messages.py +54 -0
- package/worker/mlai_review/infrastructure/models/__init__.py +0 -0
- package/worker/mlai_review/infrastructure/models/openai_compatible.py +269 -0
- package/worker/mlai_review/infrastructure/structure/__init__.py +1 -0
- package/worker/mlai_review/infrastructure/structure/heuristic.py +186 -0
- package/worker/mlai_review/infrastructure/structure/tree_sitter.py +186 -0
- package/worker/mlai_review/infrastructure/workspace/__init__.py +1 -0
- package/worker/mlai_review/infrastructure/workspace/local.py +105 -0
- package/worker/mlai_review/infrastructure/workspace/memory.py +77 -0
- package/worker/mlai_review/infrastructure/workspace/paths.py +17 -0
- package/worker/mlai_review/pipeline.py +89 -0
- package/worker/mlai_review/runtime.py +194 -0
- package/worker/mlai_review/settings.py +139 -0
- package/worker/model_stream.py +21 -7
- package/worker/offline_guard.py +1 -1
- package/worker/preview.py +62 -4
- package/worker/product_facts.py +20 -0
- package/worker/project_context.py +33 -7
- package/worker/reply_language.py +92 -10
- package/worker/repo_policy.py +5 -0
- package/worker/roles.json +199 -37
- package/worker/roles.py +271 -9
- package/worker/runner.py +366 -53
- package/worker/runtime_control.py +64 -3
- package/worker/secret_scan.py +3 -2
- package/worker/server_memory.py +122 -0
- package/worker/site_check.py +279 -0
- package/worker/skill_library.py +15 -3
- package/worker/skill_pack.py +170 -16
- package/worker/subagents.py +6 -2
- package/worker/tool_catalog.py +4 -3
- package/worker/verification.py +156 -19
- package/worker/wakeups.py +56 -4
package/worker/roles.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Engineering roles: one definition (roles.json) drives the prompt, mapped skills, build planning, the design step and a done-check.
|
|
2
2
|
|
|
3
3
|
Roles are guidance plus a bounded completion check. They never grant permissions."""
|
|
4
|
-
import fnmatch, json, re, subprocess
|
|
4
|
+
import fnmatch, json, math, re, subprocess
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
|
|
7
7
|
_DATA = None
|
|
@@ -37,7 +37,91 @@ def ids():
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
def _hit(text, phrase):
|
|
40
|
-
|
|
40
|
+
"""Whole-phrase match that also accepts common word forms: deploy/deploys/deployed/deploying, anomaly/anomalies."""
|
|
41
|
+
stem = re.escape(phrase)
|
|
42
|
+
if len(phrase) >= 4 and phrase[-1] == 'y' and phrase[-2] not in 'aeiou':
|
|
43
|
+
stem = re.escape(phrase[:-1]) + r'(?:y|ies|ied)'
|
|
44
|
+
elif len(phrase) >= 4 and phrase[-1] == 'e':
|
|
45
|
+
stem = re.escape(phrase[:-1]) + r'(?:e|es|ed|ing)'
|
|
46
|
+
# A word inside a file name (qa-upload.txt, migration_notes.md) is not a request for that kind of work (BUG-0125).
|
|
47
|
+
return re.search(r'(?<![a-z0-9_])' + stem + r'(?:s|es|ed|ing)?(?![a-z0-9_])(?![-.][a-z0-9_-]*\.[a-z0-9]{1,5}\b)', text) is not None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
_RX = {}
|
|
51
|
+
_STOP = set('a an the and or of to in on for with by from at as is are be our my we i you it this that these those your their into over under can should '
|
|
52
|
+
'make add build write fix set up use using so its than then when what how why which new all every each more most less any some not no do does '
|
|
53
|
+
'have has get let need want help please across whole improve better change update work works working thing things stuff'.split())
|
|
54
|
+
_INDEX = None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _stem(word):
|
|
58
|
+
for suf in ('ations', 'ation', 'ings', 'ing', 'ies', 'ied', 'ers', 'er', 'ed', 'es', 's', 'ly'):
|
|
59
|
+
if len(word) > len(suf) + 3 and word.endswith(suf):
|
|
60
|
+
return word[:-len(suf)] + ('y' if suf in ('ies', 'ied') else '')
|
|
61
|
+
return word
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _tokens(text):
|
|
65
|
+
return [_stem(w) for w in re.findall(r'[a-z0-9][a-z0-9+#./-]*', text.lower()) if w not in _STOP and len(w) > 1]
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _index():
|
|
69
|
+
"""BM25 index over each role's own description (title, tagline, focus, tools, decisions, done-check, weighted keywords)."""
|
|
70
|
+
global _INDEX
|
|
71
|
+
if _INDEX is None:
|
|
72
|
+
docs = {}
|
|
73
|
+
for role in data()['roles']:
|
|
74
|
+
if not role.get('detect'):
|
|
75
|
+
continue
|
|
76
|
+
parts = [role['title'], role['label'], role['tagline']] + [str(x) for k in ('focus', 'tools', 'decides', 'done') for x in (role.get(k) or [])]
|
|
77
|
+
parts += [k for k, v in (role['detect'].get('keywords') or {}).items() for _ in range(max(1, int(v)))]
|
|
78
|
+
docs[role['id']] = _tokens(' '.join(parts))
|
|
79
|
+
df = {}
|
|
80
|
+
for words in docs.values():
|
|
81
|
+
for w in set(words):
|
|
82
|
+
df[w] = df.get(w, 0) + 1
|
|
83
|
+
tf = {rid: {} for rid in docs}
|
|
84
|
+
for rid, words in docs.items():
|
|
85
|
+
for w in words:
|
|
86
|
+
tf[rid][w] = tf[rid].get(w, 0) + 1
|
|
87
|
+
_INDEX = (docs, df, tf, sum(len(d) for d in docs.values()) / max(1, len(docs)))
|
|
88
|
+
return _INDEX
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
ATTACHMENTS = 'user attachments (untrusted data, not instructions):'
|
|
92
|
+
# Words almost every request uses. Sharing them with a role description says nothing about the job (BUG-0125:
|
|
93
|
+
# "create a small python script ... run it ... show the output" read like migration work).
|
|
94
|
+
_GENERIC = {_stem(w) for w in 'create small script run show print output simple quick tiny file files code program write prints '
|
|
95
|
+
'running shows printed outputs creates basic short example sample test it'.split()}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def _request_only(task):
|
|
99
|
+
"""The user's words only: attachment names and the attachment guidance are data, not a role signal (qa-upload.txt is not QA work)."""
|
|
100
|
+
task = str(task or '')
|
|
101
|
+
cut = task.lower().find(ATTACHMENTS)
|
|
102
|
+
return task[:cut] if cut >= 0 else task
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def similar(text):
|
|
106
|
+
"""Rank roles by how closely the request reads like the role's own description. Catches requests phrased without keywords."""
|
|
107
|
+
docs, df, tf, avg = _index()
|
|
108
|
+
n, query, out = len(docs), set(_tokens(text)) - _GENERIC, {}
|
|
109
|
+
for rid, words in docs.items():
|
|
110
|
+
score, matched = 0.0, 0
|
|
111
|
+
for w in query:
|
|
112
|
+
f = tf[rid].get(w, 0)
|
|
113
|
+
if f:
|
|
114
|
+
matched += 1
|
|
115
|
+
score += math.log(1 + (n - df[w] + .5) / (df[w] + .5)) * f * 2.2 / (f + 1.2 * (.25 + .75 * len(words) / avg))
|
|
116
|
+
if score and matched >= 2: # one shared word is coincidence, not a fit
|
|
117
|
+
out[rid] = round(score, 2)
|
|
118
|
+
return sorted(out.items(), key=lambda kv: -kv[1])
|
|
119
|
+
|
|
120
|
+
def _pattern(text, rx):
|
|
121
|
+
if rx not in _RX:
|
|
122
|
+
_RX[rx] = re.compile(rx, re.I)
|
|
123
|
+
m = _RX[rx].search(text)
|
|
124
|
+
return m.group(0) if m else None
|
|
41
125
|
|
|
42
126
|
|
|
43
127
|
def _repo_files(repo, limit=3000):
|
|
@@ -71,6 +155,7 @@ def match(path, globs):
|
|
|
71
155
|
# A broad build whose strong signals span both sides of the product is a full-stack job, not a backend or frontend one.
|
|
72
156
|
CLIENT_SIDE = {'frontend', 'a11y', 'design-eng', 'i18n'}
|
|
73
157
|
SERVER_SIDE = {'backend', 'api', 'dba', 'devops', 'security', 'realtime'}
|
|
158
|
+
SIM_MIN, SIM_LEAD = 7.0, 1.35 # calibrated on the dev split of tests/fixtures/roles-eval.json
|
|
74
159
|
BUILDER_ROLES = {'fullstack', 'frontend', 'backend', 'mobile', 'embedded', 'desktop', 'game', 'cli', 'extension', 'api', 'data-eng', 'ml', 'web3', 'realtime'}
|
|
75
160
|
|
|
76
161
|
def table_title(role_id):
|
|
@@ -87,9 +172,66 @@ def _broad(task, ranked):
|
|
|
87
172
|
spread = len(strong) >= 3 or (second and second >= 0.6 * top)
|
|
88
173
|
return bool(long and spread)
|
|
89
174
|
|
|
175
|
+
# Creative writing and other non-engineering asks (BUG-0377: a poem about "security" got the Security engineer, a story
|
|
176
|
+
# about a lighthouse keeper the Performance engineer). A writing request with no software cue gets no specialist role.
|
|
177
|
+
_PROSE = re.compile(r'\b(?:poem|poems|poetry|haiku|sonnet|limerick|verse|lyrics?|song|rap|story|stories|tale|fable|novel|chapter|'
|
|
178
|
+
r'essay|letter|speech|toast|eulogy|joke|jokes|riddle|bedtime|monologue|screenplay|script for a (?:play|film|movie|video))\b')
|
|
179
|
+
_SOFTWARE = re.compile(r'\b(?:code|coding|app|apps|application|website|web ?site|web ?page|landing page|site|repo|repository|program|'
|
|
180
|
+
r'function|class|module|component|api|endpoint|server|backend|frontend|database|schema|bug|bugs|deploy|'
|
|
181
|
+
r'implement|refactor|compile|build (?:a|an|the|me)|pull request|commit|branch|test suite|unit tests?|'
|
|
182
|
+
r'html|css|javascript|typescript|python|react|node|sql|docker|generator|bot|cli|terminal|command)\b'
|
|
183
|
+
r'|\.(?:[cm]?[jt]sx?|py|go|rb|rs|java|kt|swift|php|html|css|sql|ya?ml|json|toml|sh)\b')
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
# Read-back and recall requests ("repeat what this project stored", "what is our tech stack") ask for information, not
|
|
187
|
+
# engineering work. Word similarity alone must not give them a specialist (web bug list, Bug-010: Frontend engineer).
|
|
188
|
+
_READBACK = re.compile(r'\b(?:repeat|read (?:it |them )?back|recite|quote|word for word|what (?:is|are|was|were) (?:our|the|my|this)|'
|
|
189
|
+
r'tell me (?:what|which)|list (?:the|every|each|all)|remind me|summari[sz]e what|'
|
|
190
|
+
r'show (?:me )?(?:the|our|my|this) (?:project )?(?:instructions|memory|description|files|rules))\b')
|
|
191
|
+
_CHANGE = re.compile(r'\b(?:build|create|make|fix|implement|refactor|add|change|update|edit|write (?:the |a |some )?(?:code|tests?|component)|'
|
|
192
|
+
r'design|redesign|style|deploy|migrate|optimi[sz]e|debug|scaffold|install|set ?up)\b')
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def readback_request(text):
|
|
196
|
+
t = str(text or '').lower()
|
|
197
|
+
return bool(_READBACK.search(t)) and not _CHANGE.search(re.sub(r"\b(?:do not|don't|dont|never|without)\s+(?:\w+\s+){0,2}", ' ', t))
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
_FILE_NAMED = re.compile(r'(?:^|[\s"\'`(])(?:[\w.-]+/)*[\w-]+\.(?:[cm]?[jt]sx?|py|css|scss|html?|json|md|ya?ml|toml|go|rs|rb|java|kt|swift|php|vue|svelte|sh|txt)\b', re.I)
|
|
201
|
+
_LINE_EDIT = re.compile(r'\b(?:replace|change|rename|set|edit|delete|remove|insert|put|swap|comment out|uncomment)\b[^.\n]{0,80}\b(?:line|lines|word|text|value|string|import|character|comment)\b', re.I)
|
|
202
|
+
|
|
203
|
+
def pinpoint_edit(text):
|
|
204
|
+
"""A short request that names a file and a line-level edit ("Replace the first line of src/main.jsx with the word
|
|
205
|
+
broken. Run npm run build."). Its words match no specialty; guessing one from them turned it into CLI work and the
|
|
206
|
+
CLI role's done-check added an unrequested bin/cli.js (CLI bug list, 0.3.3)."""
|
|
207
|
+
t = str(text or '')
|
|
208
|
+
return len(t) <= 400 and bool(_FILE_NAMED.search(t)) and bool(_LINE_EDIT.search(t))
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
_RUN_COMMAND = re.compile(r'\b(?:run|execute|use|type)\b[^.\n]{0,30}\b(?:shell |terminal |bash )?command\b', re.I)
|
|
212
|
+
|
|
213
|
+
def command_request(text):
|
|
214
|
+
""""Run the shell command rm notes.txt" asks for one command, not CLI tooling work (BUG-0529: the CLI role's
|
|
215
|
+
done-check then pushed an unrequested entry point and tests after the user denied the command)."""
|
|
216
|
+
t = str(text or '')
|
|
217
|
+
return len(t) <= 400 and bool(_RUN_COMMAND.search(t))
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
_ASKS_TESTS = re.compile(r'\b(?:tests?|testing|unit ?tests?|specs?|coverage|pytest|jest|vitest|tdd)\b', re.I)
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def prose_request(text):
|
|
224
|
+
"""A request to write prose (poem, story, letter...) that names nothing to build or change in software."""
|
|
225
|
+
t = str(text or '').lower()
|
|
226
|
+
return bool(_PROSE.search(t)) and not _SOFTWARE.search(t)
|
|
227
|
+
|
|
228
|
+
|
|
90
229
|
def detect(task, repo=None, build=False):
|
|
91
230
|
"""Pick a role for Auto. Returns {id, reason, score, scores}. Low-signal requests return id None (no role layer)."""
|
|
92
|
-
|
|
231
|
+
task = _request_only(task)
|
|
232
|
+
text = task[-6000:].lower()
|
|
233
|
+
if prose_request(text):
|
|
234
|
+
return {'id': None, 'reason': 'A writing request, not engineering work; using the general engineer.', 'score': 0, 'scores': {}}
|
|
93
235
|
files = _repo_files(repo) if repo else []
|
|
94
236
|
scores, why = {}, {}
|
|
95
237
|
for role in data()['roles']:
|
|
@@ -101,6 +243,11 @@ def detect(task, repo=None, build=False):
|
|
|
101
243
|
if _hit(text, phrase):
|
|
102
244
|
score += weight
|
|
103
245
|
hits.append(phrase)
|
|
246
|
+
for rx, weight in (d.get('patterns') or {}).items():
|
|
247
|
+
found = _pattern(text, rx)
|
|
248
|
+
if found:
|
|
249
|
+
score += weight
|
|
250
|
+
hits.append(found)
|
|
104
251
|
repo_hits = [g for g in (d.get('files') or []) if any(match(f, [g]) for f in files)]
|
|
105
252
|
if repo_hits:
|
|
106
253
|
# Domain repos (firmware, mobile, data, ML) define the job even for vague requests; generic files only nudge.
|
|
@@ -121,8 +268,30 @@ def detect(task, repo=None, build=False):
|
|
|
121
268
|
areas = [table_title(r) for r, _ in ranked[:4]]
|
|
122
269
|
return {'id': 'fullstack', 'reason': 'Broad product request covering ' + ', '.join(areas[:-1]) + (' and ' + areas[-1] if len(areas) > 1 else areas[0] if areas else '') + ', so it is built end to end with those areas as checks.',
|
|
123
270
|
'score': scores.get('fullstack', 0), 'scores': dict(ranked[:5]), 'broad': True}
|
|
124
|
-
|
|
271
|
+
top = ranked[0][1] if ranked else 0
|
|
272
|
+
second = ranked[1][1] if len(ranked) > 1 else 0
|
|
273
|
+
# A strong signal wins outright; a moderate one wins when it clearly leads every other specialty and rests on
|
|
274
|
+
# more than one cue (a lone "README" in "fix the typo in README" is not a docs job).
|
|
275
|
+
lead = ranked and top >= 3 and top - second >= 2 and (len(why[ranked[0][0]][0]) >= 2 or ranked[0][0] in BUILDER_ROLES and build)
|
|
276
|
+
sim = similar(text)
|
|
277
|
+
sim_top = sim[0][1] if sim else 0
|
|
278
|
+
sim_second = sim[1][1] if len(sim) > 1 else 0
|
|
279
|
+
if top >= 4 or lead:
|
|
125
280
|
best = ranked[0][0]
|
|
281
|
+
# Close keyword race (e.g. "fine-tuned model ... vLLM" scores ML and MLOps alike): the role whose description fits best wins.
|
|
282
|
+
close = [r for r, v in ranked if v >= top - 1 and v >= 3]
|
|
283
|
+
if len(close) > 1 and sim:
|
|
284
|
+
fit = dict(sim)
|
|
285
|
+
pick = max(close, key=lambda r: fit.get(r, 0))
|
|
286
|
+
if fit.get(pick, 0) >= 1.5 * max(fit.get(r, 0) for r in close if r != pick) and fit.get(pick, 0) >= SIM_MIN:
|
|
287
|
+
best = pick
|
|
288
|
+
why.setdefault(best, ([], []))
|
|
289
|
+
elif sim and sim_top >= SIM_MIN and sim_top >= SIM_LEAD * sim_second and not readback_request(text) and not pinpoint_edit(text) and not command_request(text):
|
|
290
|
+
# No keyword pinned it, but the request reads clearly like one specialty.
|
|
291
|
+
best = sim[0][0]
|
|
292
|
+
why.setdefault(best, ([], []))
|
|
293
|
+
if not why[best][0]:
|
|
294
|
+
why[best] = (['the request reads like ' + table_title(best).lower() + ' work'], why[best][1])
|
|
126
295
|
elif build:
|
|
127
296
|
best = 'fullstack' # an app request with no stronger signal: build it properly end to end
|
|
128
297
|
why.setdefault(best, ([], []))
|
|
@@ -131,7 +300,8 @@ def detect(task, repo=None, build=False):
|
|
|
131
300
|
hits, repo_hits = why.get(best, ([], []))
|
|
132
301
|
parts = []
|
|
133
302
|
if hits:
|
|
134
|
-
|
|
303
|
+
said = [h for h in hits if not h.startswith('the request reads like')]
|
|
304
|
+
parts.append('you mentioned ' + ', '.join('"' + h + '"' for h in said[:4]) if said else hits[0])
|
|
135
305
|
if repo_hits:
|
|
136
306
|
parts.append('the repo has ' + ', '.join(repo_hits[:3]))
|
|
137
307
|
if not parts:
|
|
@@ -145,12 +315,12 @@ def resolve(config, repo=None, build=False):
|
|
|
145
315
|
table = roles()
|
|
146
316
|
if wanted != 'auto' and wanted in table:
|
|
147
317
|
role = table[wanted]
|
|
148
|
-
return {'id': wanted, 'label': role['label'], 'title': role['title'], 'auto': False, 'reason': 'Selected by you.'}
|
|
318
|
+
return {'id': wanted, 'label': role['label'], 'title': role['title'], 'auto': False, 'reason': 'Selected by you.', 'skills': fit_skills(role['skills'], config.get('task', ''), repo), 'stack': stack_rule(config.get('task', ''), repo)}
|
|
149
319
|
picked = detect(config.get('task', ''), repo, build)
|
|
150
320
|
if not picked['id']:
|
|
151
321
|
return None
|
|
152
322
|
role = table[picked['id']]
|
|
153
|
-
return {'id': role['id'], 'label': role['label'], 'title': role['title'], 'auto': True, 'reason': picked['reason'], 'scores': picked['scores']}
|
|
323
|
+
return {'id': role['id'], 'label': role['label'], 'title': role['title'], 'auto': True, 'reason': picked['reason'], 'scores': picked['scores'], 'skills': fit_skills(role['skills'], config.get('task', ''), repo), 'stack': stack_rule(config.get('task', ''), repo)}
|
|
154
324
|
|
|
155
325
|
|
|
156
326
|
def prompt(resolved, readonly=False):
|
|
@@ -163,6 +333,8 @@ def prompt(resolved, readonly=False):
|
|
|
163
333
|
if role.get('design'):
|
|
164
334
|
lines.append('Design standard (this role leads design for every screen it touches):')
|
|
165
335
|
lines += ['- ' + d for d in role['design']]
|
|
336
|
+
if resolved.get('stack'):
|
|
337
|
+
lines.append(resolved['stack'])
|
|
166
338
|
if role.get('tools'):
|
|
167
339
|
lines.append('Tools this role reaches for (prefer what the repo already uses): ' + '; '.join(role['tools']) + '.')
|
|
168
340
|
if role.get('decides'):
|
|
@@ -177,8 +349,94 @@ def prompt(resolved, readonly=False):
|
|
|
177
349
|
return '\n'.join(lines)
|
|
178
350
|
|
|
179
351
|
|
|
352
|
+
# Framework and vendor skills a role lists by default. They only apply when the request or the repo uses that stack
|
|
353
|
+
# (web bug list Bug-004 and BUG-033: a React Native request was built as Next.js, and a React/Node shop showed
|
|
354
|
+
# Next.js, Supabase and Clerk on its role card).
|
|
355
|
+
STACK_SKILLS = {
|
|
356
|
+
'nextjs-app': {'say': ('next.js', 'nextjs', 'next js', 'app router'), 'deps': ('next',), 'files': ('next.config.*',)},
|
|
357
|
+
'supabase': {'say': ('supabase',), 'deps': ('@supabase/supabase-js', '@supabase/ssr'), 'files': ('supabase/config.toml',)},
|
|
358
|
+
'clerk-auth': {'say': ('clerk',), 'deps': ('@clerk/nextjs', '@clerk/clerk-react', '@clerk/clerk-expo', '@clerk/express'), 'files': ()},
|
|
359
|
+
'postgres-orm': {'say': ('postgres', 'postgresql', 'neon', 'drizzle', 'prisma'), 'deps': ('drizzle-orm', 'prisma', '@prisma/client', 'pg', 'postgres', '@neondatabase/serverless'), 'files': ('drizzle.config.*', 'prisma/schema.prisma')},
|
|
360
|
+
'expo-mobile': {'say': ('expo', 'react native', 'react-native', 'mobile app', 'ios app', 'android app', 'iphone app'), 'deps': ('expo', 'react-native'), 'files': ('app.json', 'eas.json')},
|
|
361
|
+
}
|
|
362
|
+
# Stacks a user can name. Naming one rules out the other web frameworks a role would otherwise default to.
|
|
363
|
+
NAMED_STACKS = (
|
|
364
|
+
('React Native', r'react[\s-]?native'), ('Expo', r'\bexpo\b'), ('Flutter', r'\bflutter\b'), ('SwiftUI', r'\bswiftui\b'),
|
|
365
|
+
('Kotlin', r'\bkotlin\b'), ('Next.js', r'\bnext\.?js\b|\bnext js\b'), ('Remix', r'\bremix\b'), ('Vite', r'\bvite\b'),
|
|
366
|
+
('Create React App', r'create[\s-]react[\s-]app'), ('Vue', r'\bvue(?:\.js)?\b'), ('Nuxt', r'\bnuxt\b'), ('Svelte', r'\bsvelte(?:kit)?\b'),
|
|
367
|
+
('Angular', r'\bangular\b'), ('Astro', r'\bastro\b'), ('Express', r'\bexpress(?:\.js)?\b'), ('Node.js', r'\bnode(?:\.js|js)?\b'),
|
|
368
|
+
('Fastify', r'\bfastify\b'), ('NestJS', r'\bnest\.?js\b'), ('Django', r'\bdjango\b'), ('Flask', r'\bflask\b'),
|
|
369
|
+
('FastAPI', r'\bfastapi\b'), ('Rails', r'\brails\b'), ('Laravel', r'\blaravel\b'), ('Go', r'\bgolang\b'),
|
|
370
|
+
('Firebase', r'\bfirebase\b'), ('Supabase', r'\bsupabase\b'), ('MongoDB', r'\bmongo(?:db)?\b'), ('SQLite', r'\bsqlite\b'),
|
|
371
|
+
('PostgreSQL', r'\bpostgres(?:ql)?\b'), ('MySQL', r'\bmysql\b'), ('Prisma', r'\bprisma\b'), ('Drizzle', r'\bdrizzle\b'),
|
|
372
|
+
('Clerk', r'\bclerk\b'), ('Auth.js', r'\bnext-?auth\b|\bauth\.js\b'), ('Tailwind', r'\btailwind\b'), ('TypeScript', r'\btypescript\b'),
|
|
373
|
+
('React', r'\breact(?![\s-]?native)\b'),
|
|
374
|
+
)
|
|
375
|
+
OTHER_WEB = {'React Native', 'Expo', 'Flutter', 'SwiftUI', 'Kotlin', 'Remix', 'Vite', 'Create React App', 'Vue', 'Nuxt', 'Svelte', 'Angular', 'Astro', 'Express', 'Node.js', 'Fastify', 'NestJS', 'Django', 'Flask', 'FastAPI', 'Rails', 'Laravel', 'Go'}
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def named_stack(task):
|
|
379
|
+
"""Technologies the request names, in a fixed order: ['React Native', 'Expo', 'TypeScript']."""
|
|
380
|
+
t = _request_only(str(task or '')).lower()
|
|
381
|
+
return [name for name, rx in NAMED_STACKS if re.search(rx, t)]
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _repo_deps(repo):
|
|
385
|
+
"""Dependency names from package.json files at the repo root and one level down."""
|
|
386
|
+
deps = set()
|
|
387
|
+
if not repo:
|
|
388
|
+
return deps
|
|
389
|
+
root = Path(repo)
|
|
390
|
+
for pkg in [root / 'package.json'] + sorted(root.glob('*/package.json'))[:12]:
|
|
391
|
+
try:
|
|
392
|
+
j = json.loads(pkg.read_text(errors='replace'))
|
|
393
|
+
except (OSError, ValueError):
|
|
394
|
+
continue
|
|
395
|
+
for key in ('dependencies', 'devDependencies', 'peerDependencies'):
|
|
396
|
+
if isinstance(j.get(key), dict):
|
|
397
|
+
deps.update(j[key])
|
|
398
|
+
return deps
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def fit_skills(skills, task='', repo=None):
|
|
402
|
+
"""Drop stack skills that neither the request nor the repo uses. A new, empty project keeps a role's default stack
|
|
403
|
+
only when the request names no other framework."""
|
|
404
|
+
text = _request_only(str(task or '')).lower()
|
|
405
|
+
named = set(named_stack(task))
|
|
406
|
+
deps = _repo_deps(repo)
|
|
407
|
+
files = _repo_files(repo) if repo else []
|
|
408
|
+
has_code = bool(deps) or any(f.endswith(('.js', '.jsx', '.ts', '.tsx', '.py', '.dart', '.swift', '.kt')) for f in files)
|
|
409
|
+
out = []
|
|
410
|
+
for sid in skills:
|
|
411
|
+
rule = STACK_SKILLS.get(sid)
|
|
412
|
+
if not rule:
|
|
413
|
+
out.append(sid)
|
|
414
|
+
continue
|
|
415
|
+
said = any(_hit(text, s) for s in rule['say'])
|
|
416
|
+
used = any(d in deps for d in rule['deps']) or any(match(f, list(rule['files'])) for f in files)
|
|
417
|
+
if said or used:
|
|
418
|
+
out.append(sid)
|
|
419
|
+
elif not has_code and not named:
|
|
420
|
+
out.append(sid) # a new project with no stated stack: the role's default stack is the plan
|
|
421
|
+
return out
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
def stack_rule(task, repo=None):
|
|
425
|
+
"""A hard instruction when the request names its stack, so the agent never swaps in another framework."""
|
|
426
|
+
named = named_stack(task)
|
|
427
|
+
if not named:
|
|
428
|
+
return ''
|
|
429
|
+
line = 'Stack the user asked for: ' + ', '.join(named) + '. Build with exactly this stack and the app type it implies'
|
|
430
|
+
if named and set(named) & {'React Native', 'Expo', 'Flutter', 'SwiftUI', 'Kotlin'}:
|
|
431
|
+
line += ' (a mobile app, not a web app)'
|
|
432
|
+
line += '. Do not substitute another framework, database or auth provider'
|
|
433
|
+
if 'Next.js' not in named and set(named) & OTHER_WEB:
|
|
434
|
+
line += ' (no Next.js)'
|
|
435
|
+
return line + '. If one of them cannot work here, say so and ask before switching.'
|
|
436
|
+
|
|
437
|
+
|
|
180
438
|
def preferred_skills(resolved, lead=None):
|
|
181
|
-
skills = list(roles()[resolved['id']]['skills']) if resolved else []
|
|
439
|
+
skills = list(resolved['skills']) if resolved and isinstance(resolved.get('skills'), list) else list(roles()[resolved['id']]['skills']) if resolved else []
|
|
182
440
|
if lead == 'full':
|
|
183
441
|
# The first three role skills are loaded in full, so the design skill goes first.
|
|
184
442
|
skills = [DESIGN_SKILL] + [s for s in skills if s != DESIGN_SKILL]
|
|
@@ -284,7 +542,7 @@ def changed_files(repo, base=None):
|
|
|
284
542
|
return [p for p in dict.fromkeys(x.strip() for x in out) if p and not p.startswith('.mini/')][:400]
|
|
285
543
|
|
|
286
544
|
|
|
287
|
-
def gate(resolved, repo, base, changed, task=''):
|
|
545
|
+
def gate(resolved, repo, base, changed, task='', laptop=False):
|
|
288
546
|
"""Issues that block completion once for this role. Empty when the role is satisfied or not applicable."""
|
|
289
547
|
if not resolved or not changed:
|
|
290
548
|
return []
|
|
@@ -294,6 +552,10 @@ def gate(resolved, repo, base, changed, task=''):
|
|
|
294
552
|
code_changed = any(CODE_EXT.search(p) for p in changed)
|
|
295
553
|
if code_changed or role['id'] == 'architect':
|
|
296
554
|
for artifact in spec.get('artifacts') or []:
|
|
555
|
+
# BUG-0531: "Automated tests" made the agent add test files and install pytest for a one-function fix.
|
|
556
|
+
# On the person's computer new tests are only required when the request asks for them; otherwise the agent runs the existing ones.
|
|
557
|
+
# Runs on the person's own computer (CLI, Mac app) only; cloud builds keep the requirement.
|
|
558
|
+
if laptop and artifact.get('label') == 'Automated tests' and not _ASKS_TESTS.search(task or ''): continue
|
|
297
559
|
if not any(match(p, artifact['globs']) for p in changed):
|
|
298
560
|
issues.append({'kind': 'artifact', 'label': artifact['label'], 'message': 'Missing for the ' + role['title'] + ' done-check: ' + artifact['label'] + '.'})
|
|
299
561
|
if spec.get('noMock') and not MOCK_OK.search(task or ''):
|