mlai-code 0.3.3 → 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 +153 -26
- 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 +17 -0
- package/src/relay.mjs +1 -1
- package/src/render.mjs +9 -2
- package/src/runtime.mjs +2 -0
- package/src/server.mjs +46 -7
- package/src/session.mjs +31 -8
- package/src/tui/acp.mjs +121 -19
- package/src/tui/app.mjs +2 -1
- package/src/tui/chat.mjs +35 -10
- package/src/tui/cmd-config.mjs +3 -1
- package/src/tui/cmd-core.mjs +9 -5
- package/src/tui/cmd-extensibility.mjs +5 -0
- 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/two-words.mjs +14 -8
- package/src/view-sync.mjs +48 -0
- package/src/winenv.mjs +1 -1
- package/src/workspace-api.mjs +21 -4
- package/vendor/client-sdk/index.cjs +2 -1
- package/vendor/cloud-cli/mlai.mjs +23 -11
- package/worker/architecture_worker.py +33 -4
- package/worker/browser_tool.py +19 -1
- package/worker/chat_fork.py +4 -1
- package/worker/checkpoints.py +71 -8
- package/worker/command_safety.py +56 -3
- package/worker/connected_turn.py +30 -0
- package/worker/conversation.py +81 -11
- package/worker/git_sync.py +4 -4
- package/worker/image_generation.py +2 -2
- package/worker/kimi_bridge.py +247 -27
- package/worker/kimi_gates.py +25 -6
- package/worker/kimi_hook.py +153 -12
- package/worker/media_tools.py +4 -1
- package/worker/mlai_hooks.py +222 -3
- package/worker/mlai_mcp.py +26 -6
- 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/preview.py +15 -0
- package/worker/product_facts.py +3 -1
- package/worker/repo_policy.py +5 -0
- package/worker/roles.py +29 -2
- package/worker/runner.py +126 -18
- package/worker/runtime_control.py +64 -3
- package/worker/secret_scan.py +3 -2
- package/worker/server_memory.py +122 -0
- package/worker/subagents.py +6 -2
- package/worker/tool_catalog.py +1 -1
- package/worker/verification.py +113 -8
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""BUG-0203: remember the dev servers the agent left running, so a chat that wakes up on a new cloud computer
|
|
2
|
+
can say which servers stopped and offer a one-click Restart. Nothing is restarted by itself: the start
|
|
3
|
+
commands are stored in the run state (.mini/servers.json) and only run when the person clicks Restart.
|
|
4
|
+
|
|
5
|
+
CLI (used by app/api/workspace/route.ts):
|
|
6
|
+
python3 server_memory.py stopped -> JSON list of servers that ran on a previous computer
|
|
7
|
+
python3 server_memory.py restart <id> -> starts that server again in the background
|
|
8
|
+
python3 server_memory.py dismiss [<id>] -> stop showing the notice for one or all servers
|
|
9
|
+
"""
|
|
10
|
+
import hashlib, json, os, pathlib, re, socket, subprocess, sys, time
|
|
11
|
+
|
|
12
|
+
FILE = 'servers.json'
|
|
13
|
+
LIMIT = 8
|
|
14
|
+
SERVER = re.compile(
|
|
15
|
+
r'\b(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|start|serve|preview)\b|\bnext\s+(?:dev|start)\b|\bvite(?:\s|$)|'
|
|
16
|
+
r'\bpython3?\s+-m\s+http\.server\b|\buvicorn\b|\bflask\s+run\b|\bgunicorn\b|manage\.py\s+runserver\b|'
|
|
17
|
+
r'\brails\s+s(?:erver)?\b|\bhttp-server\b|\bphp\s+-S\b|\bnode\s+\S*(?:server|app|index|main)\.[cm]?[jt]s\b|'
|
|
18
|
+
r'\bstreamlit\s+run\b|\bjupyter\s+(?:lab|notebook)\b', re.I)
|
|
19
|
+
PORT = re.compile(r'(?:--port[ =]|-p\s+|PORT=|localhost:|0\.0\.0\.0:|127\.0\.0\.1:)(\d{2,5})\b')
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def boot_id():
|
|
23
|
+
try: return pathlib.Path('/proc/sys/kernel/random/boot_id').read_text().strip() or socket.gethostname()
|
|
24
|
+
except OSError: return socket.gethostname()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def is_server(command):
|
|
28
|
+
return bool(SERVER.search(str(command or '')))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _path(root): return pathlib.Path(root) / FILE
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def load(root):
|
|
35
|
+
try:
|
|
36
|
+
data = json.loads(_path(root).read_text())
|
|
37
|
+
return [s for s in data if isinstance(s, dict) and s.get('id') and s.get('command')] if isinstance(data, list) else []
|
|
38
|
+
except (OSError, ValueError): return []
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def save(root, servers):
|
|
42
|
+
p = _path(root); p.parent.mkdir(parents=True, exist_ok=True)
|
|
43
|
+
tmp = p.with_suffix('.tmp'); tmp.write_text(json.dumps(servers[-LIMIT:])); os.replace(tmp, p)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def label(command):
|
|
47
|
+
m = PORT.search(command)
|
|
48
|
+
head = ' '.join(command.split()[:4])
|
|
49
|
+
return head[:60] + (' (port %s)' % m.group(1) if m else '')
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def remember(root, command, cwd, boot=None):
|
|
53
|
+
"""Record a server the agent started in the background on this computer."""
|
|
54
|
+
command = str(command or '').strip()
|
|
55
|
+
if not command or not is_server(command) or len(command) > 2000: return None
|
|
56
|
+
sid = hashlib.sha1(command.encode()).hexdigest()[:10]
|
|
57
|
+
port = PORT.search(command)
|
|
58
|
+
entry = {'id': sid, 'command': command, 'cwd': str(cwd or ''), 'label': label(command),
|
|
59
|
+
'port': int(port.group(1)) if port else None, 'boot': boot or boot_id(), 'time': time.time()}
|
|
60
|
+
servers = [s for s in load(root) if s['id'] != sid] + [entry]
|
|
61
|
+
save(root, servers)
|
|
62
|
+
return entry
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def stopped(root, boot=None):
|
|
66
|
+
"""Servers recorded on a different computer (boot) that nobody restarted or dismissed."""
|
|
67
|
+
now = boot or boot_id()
|
|
68
|
+
return [{k: s.get(k) for k in ('id', 'command', 'label', 'port')} for s in load(root)
|
|
69
|
+
if s.get('boot') != now and not s.get('dismissed')]
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def agent_note(root, boot=None):
|
|
73
|
+
"""Once per new computer: tell the agent which servers stopped. It may suggest Restart; it must not assume they run."""
|
|
74
|
+
now = boot or boot_id()
|
|
75
|
+
servers = load(root)
|
|
76
|
+
gone = [s for s in servers if s.get('boot') != now and not s.get('dismissed') and s.get('noted') != now]
|
|
77
|
+
if not gone: return ''
|
|
78
|
+
for s in servers:
|
|
79
|
+
if s in gone: s['noted'] = now
|
|
80
|
+
save(root, servers)
|
|
81
|
+
return ('This chat is on a new cloud computer. Servers that were running before have stopped: '
|
|
82
|
+
+ '; '.join(s['command'] for s in gone)
|
|
83
|
+
+ '. They are not running now. Do not restart them unless the request needs them; the person can use Restart in the chat.')
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def dismiss(root, sid=None):
|
|
87
|
+
servers = load(root)
|
|
88
|
+
for s in servers:
|
|
89
|
+
if sid is None or s['id'] == sid: s['dismissed'] = True
|
|
90
|
+
save(root, servers)
|
|
91
|
+
return {'dismissed': True}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def restart(root, sid, repo, boot=None):
|
|
95
|
+
"""Start one remembered server again, detached, logging to .mini/server-<id>.log. Only on an explicit click."""
|
|
96
|
+
servers = load(root)
|
|
97
|
+
hit = next((s for s in servers if s['id'] == sid), None)
|
|
98
|
+
if not hit: return {'error': 'That server is no longer remembered.'}
|
|
99
|
+
try:
|
|
100
|
+
import command_safety
|
|
101
|
+
effect = command_safety.classify(hit['command'], str(repo)).effect
|
|
102
|
+
if effect in ('destructive', 'catastrophic', 'privilege', 'unknown', 'external'):
|
|
103
|
+
return {'error': 'This command needs the agent to run it, so it can ask first.'}
|
|
104
|
+
except Exception: pass
|
|
105
|
+
cwd = hit.get('cwd') or str(repo)
|
|
106
|
+
if not os.path.isdir(cwd): cwd = str(repo)
|
|
107
|
+
log = pathlib.Path(root) / ('server-%s.log' % sid)
|
|
108
|
+
with open(log, 'ab') as out:
|
|
109
|
+
subprocess.Popen(['bash', '-lc', hit['command']], cwd=cwd, stdout=out, stderr=subprocess.STDOUT,
|
|
110
|
+
stdin=subprocess.DEVNULL, start_new_session=True)
|
|
111
|
+
hit['boot'] = boot or boot_id(); hit['time'] = time.time(); hit.pop('dismissed', None)
|
|
112
|
+
save(root, servers)
|
|
113
|
+
return {'restarted': hit['id'], 'label': hit['label'], 'port': hit.get('port')}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
if __name__ == '__main__':
|
|
117
|
+
root = pathlib.Path(__file__).resolve().parent
|
|
118
|
+
repo = root.parent / 'repo'
|
|
119
|
+
cmd = sys.argv[1] if len(sys.argv) > 1 else 'stopped'
|
|
120
|
+
if cmd == 'restart': print(json.dumps(restart(root, sys.argv[2] if len(sys.argv) > 2 else '', repo)))
|
|
121
|
+
elif cmd == 'dismiss': print(json.dumps(dismiss(root, sys.argv[2] if len(sys.argv) > 2 else None)))
|
|
122
|
+
else: print(json.dumps(stopped(root)))
|
package/worker/subagents.py
CHANGED
|
@@ -76,8 +76,12 @@ def agents_guidance(config,kimi=False):
|
|
|
76
76
|
if not agents or config.get('subagent'):return ''
|
|
77
77
|
rows='\n'.join('- '+a['name']+': '+(a['description'] or a['prompt'].strip().split('\n')[0][:160]) for a in agents)
|
|
78
78
|
if kimi:
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
# BUG-0518: the model passed the custom name as subagent_type and the engine refused it ("Allowed: coder, explore, plan").
|
|
80
|
+
# Say which built-in type carries each one, and that the name itself is never a subagent_type.
|
|
81
|
+
return ('Custom helper agents the user defined. When one fits (or the user names it), start it with the Agent tool. The name is NOT a '
|
|
82
|
+
'subagent_type: the Agent tool only takes subagent_type coder, explore or plan. Use the type given for each agent below, and make the '
|
|
83
|
+
'prompt its instructions followed by the self-contained task:\n'
|
|
84
|
+
+'\n\n'.join('## '+a['name']+' (subagent_type "'+('explore' if a['readOnly'] else 'coder')+'")\n'+a['prompt'].strip()[:4000] for a in agents)+'\n')
|
|
81
85
|
return ('Custom helper agents the user defined; hand one a self-contained task with subagents {tasks:[{agent:"<name>",task:"..."}]} when its description fits. '
|
|
82
86
|
'They run read-only and report back; you apply any changes they suggest.\n'+rows)
|
|
83
87
|
|
package/worker/tool_catalog.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import os
|
|
3
3
|
GROUPS={
|
|
4
4
|
'repository':{'tools':['read_file','read_files','parallel_reads','list_files','search_text','repo_map','symbols','context_read','impact','skill_load','tool_search'],'help':'read_file {path,start?,end?}; read_files {files:[{path,start?,end?}]}; search_text {query}; list_files {}; repo_map {}; symbols {query?,path?}; context_read {archive,start?,end?}. Prefer focused ranges and batch independent reads: parallel_reads {calls:[{name,arguments}]} runs up to eight read_file/search_text/list_files/repo_map/symbols/context_read/command_output calls at once, or send several read-only calls in one reply. skill_load {id,file?} loads a skill from the catalog (stack how-tos: setup, Vault variable names, verification). tool_search {query} returns full schemas of matching connected integration tools when the catalog lists names only.'},
|
|
5
|
-
'planning':{'tools':['todo','task_contract','evidence','tool_catalog','schedule_wakeup'],'help':'schedule_wakeup {in_minutes|at,note} resumes this session later; {cancel:true} removes it. task_contract {} reads the current objective, requirements and revision. Use the task-contract/recovery protocol in workflow guidance. evidence {} reads sources and recorded claims. tool_catalog {groups:[name]} loads focused tool references; {} lists groups.'},
|
|
5
|
+
'planning':{'tools':['todo','task_contract','evidence','tool_catalog','schedule_wakeup','cannot_complete'],'help':'cannot_complete {reason} reports that the request cannot be done as asked (call once, then answer). schedule_wakeup {in_minutes|at,note} resumes this session later; {cancel:true} removes it. task_contract {} reads the current objective, requirements and revision. Use the task-contract/recovery protocol in workflow guidance. evidence {} reads sources and recorded claims. tool_catalog {groups:[name]} loads focused tool references; {} lists groups.'},
|
|
6
6
|
'research':{'tools':['web_search','web_fetch','evidence'],'help':'web_search {query,objective?,max_results?}; web_fetch {urls:[https_url]}. Eight total provider attempts, cached 30 minutes. Do not send secrets or private code. Read primary pages and record evidence before recommendations.'},
|
|
7
7
|
'editing':{'tools':['generate_image','stock_photo','brand_lookup','edit_file','verify','command_output','test_plan','capability_check'],'help':'generate_image {prompt,filename,aspect_ratio?} creates an original image under public/generated/ (up to six per run, set in Settings; each uses credits). stock_photo {query,filename,orientation?,pick?} saves a real Pixabay photo under public/stock/ (free) and returns other matches. brand_lookup {domain} returns the brand colours and fonts and saves its logos under public/brand/. Load image-generation skill for art direction. edit_file {path,old,new} replaces exactly one match. verify {label,command,junitReport?,requiredTests?} records actual results. Prefer a newly generated JUnit XML report in a gitignored directory; requiredTests uses classname::name IDs and cannot be dropped on reruns of the same command. Missing/skipped tests never pass. command_output {id,offset?,length?} reads retained logs. test_plan {} and capability_check {} inspect available checks. Reproduce failures, fix the public behavior, run affected checks, review, then verify the reviewed source before completion.'},
|
|
8
8
|
'browser':{'tools':['browser'],'help':'browser {url,width,height,steps:[{action,role,name,selector,value,key,text,url}]} tests localhost port 3000. Actions: goto/click/fill/press/assert_text. Start dev servers bound to 0.0.0.0:3000, verify HTTP and main flow. Test mobile and desktop. Screenshots alone are not visual assessment.'},
|
package/worker/verification.py
CHANGED
|
@@ -13,9 +13,10 @@ import os, re, subprocess, tempfile, shutil
|
|
|
13
13
|
from pathlib import Path
|
|
14
14
|
from runtime_control import latest_checks, check_status, clip, EXTERNAL_SCOPES
|
|
15
15
|
|
|
16
|
-
RUNNER = re.compile(r'(^|[;&|(\s])(pytest|py\.test|python3? -m (pytest|unittest|mypy|ruff)|npm (run )?(test|build|lint|typecheck|type-check|check)|pnpm (run )?(test|build|lint|typecheck|check)|yarn (run )?(test|build|lint|typecheck)|npx (tsc|vitest|jest|playwright|eslint|biome|mocha|cypress|prettier --check)|tsc( |$)|vitest|jest|mocha|go (test|build|vet)|cargo (test|build|check|clippy)|make (test|check|build)?$|make (test|check|build)|bun (run )?test|deno (test|check)|mvn[w]?( -q)? (test|verify|package)|gradle[w]? (test|build)|ruff|mypy|pyright|flake8|eslint|node --test|dotnet (test|build)|mix test|rspec|phpunit|ctest|swift (test|build))', re.I | re.M)
|
|
16
|
+
RUNNER = re.compile(r'(^|[;&|(\s])(pytest|py\.test|python3? -m (pytest|unittest|mypy|ruff)|npm (run )?(test|build|lint|typecheck|type-check|check)|pnpm (run )?(test|build|lint|typecheck|check)|yarn (run )?(test|build|lint|typecheck)|npx (tsc|vitest|jest|playwright|eslint|biome|mocha|cypress|prettier --check)|tsc( |$)|vitest|jest|mocha|go (test|build|vet)|cargo (test|build|check|clippy)|make (test|check|build)?$|make (test|check|build)|bun (run )?test|deno (test|check)|mvn[w]?( -q)? (test|verify|package)|gradle[w]? (test|build)|ruff|mypy|pyright|flake8|eslint|node --test|dotnet (test|build)|mix test|rspec|phpunit|ctest|swift (test|build)|swiftc\b[^;&|\n]*\s-(typecheck|parse)\b|xcodebuild\b[^;&|\n]*\b(build|test)\b)', re.I | re.M)
|
|
17
17
|
INLINE_RUN = re.compile(r'(^|[;&|(\s])(python3?|node|bun|deno run|tsx|ts-node)\s+(-c\b|-e\b|-\s|-$|<<|[\w./-]+\.(py|[cm]?js|ts)\b)', re.M)
|
|
18
|
-
|
|
18
|
+
# BUG-0296: `if (greet('World') !== 'Hello, World') process.exit(1)` asserts as much as assert() does.
|
|
19
|
+
INLINE_ASSERT = re.compile(r'\bassert\b|console\.assert|\bexpect\(|\bassert\.\w+\(|[\w./-]*(test_\w+|\w+_test|\w+\.test|\w+\.spec)\.(py|[cm]?js|ts)\b|\bprocess\.exit\(\s*[1-9]|\bprocess\.exitCode\s*=\s*[1-9]|\bsys\.exit\(\s*[1-9]|\bthrow new Error\(|\braise (?:SystemExit|AssertionError|ValueError|RuntimeError)\b')
|
|
19
20
|
# Claims about verification in the final message. Each tuple: (pattern, what it claims).
|
|
20
21
|
CLAIMS = (
|
|
21
22
|
(re.compile(r'\b(all |the )?(unit |integration |e2e |existing )?tests? (now |all |still )?(pass|passes|passed|passing|are passing|is passing|succeed|succeeded|green)\b', re.I), 'tests'),
|
|
@@ -156,7 +157,9 @@ def diff_checks(repo, base, task=''):
|
|
|
156
157
|
elif line.startswith('+') and ASSERT_LINE.search(line[1:]): added_asserts += 1
|
|
157
158
|
if removed_asserts and removed_asserts > added_asserts:
|
|
158
159
|
findings.append({'kind': 'assertions_weakened', 'severity': 'block', 'message': '%d assertion%s removed from existing tests (%s) while implementation files changed. Existing tests define the expected behaviour: fix the code, not the tests, unless the task says the test was wrong (then explain which and why in the final message).' % (removed_asserts, '' if removed_asserts == 1 else 's were', ', '.join(tests_changed[:3]))})
|
|
159
|
-
|
|
160
|
+
# BUG-0397: only tests that existed before the run count as "existing"; a brand-new test file is not an edit.
|
|
161
|
+
elif (existing := [p for p in tests_changed if _existed(repo, base, p)]):
|
|
162
|
+
tests_changed = existing
|
|
160
163
|
findings.append({'kind': 'tests_edited', 'severity': 'note', 'message': 'Existing tests were edited alongside the implementation (' + ', '.join(tests_changed[:3]) + '). State in the final message what changed in the tests and why.',
|
|
161
164
|
'user': 'Existing tests changed along with the code (' + ', '.join(tests_changed[:3]) + '). Look over those test changes before you rely on them.'})
|
|
162
165
|
for path in code_changed[:40]:
|
|
@@ -169,6 +172,14 @@ def diff_checks(repo, base, task=''):
|
|
|
169
172
|
return findings
|
|
170
173
|
|
|
171
174
|
|
|
175
|
+
def _existed(repo, base, path):
|
|
176
|
+
"""True when path is in the base commit (it existed before the run)."""
|
|
177
|
+
try:
|
|
178
|
+
r = subprocess.run(['git', 'cat-file', '-e', (base or 'HEAD') + ':' + path], cwd=repo, capture_output=True, timeout=20)
|
|
179
|
+
return r.returncode == 0
|
|
180
|
+
except (OSError, subprocess.SubprocessError): return False
|
|
181
|
+
|
|
182
|
+
|
|
172
183
|
def _file_diff(repo, base, path):
|
|
173
184
|
text = _git(repo, 'diff', '--unified=0', base or 'HEAD', '--', path)
|
|
174
185
|
if text: return text
|
|
@@ -379,12 +390,37 @@ def out_of_scope(files, scope):
|
|
|
379
390
|
e = re.sub(r'\*.*$', '', re.sub(r'^\./', '', raw)).rstrip('/')
|
|
380
391
|
if e == '' or path == e or path.startswith(e + '/'): return True
|
|
381
392
|
return False
|
|
382
|
-
|
|
393
|
+
# BUG-0580: PLAN.md is the project plan the harness keeps (build_planner ticks its boxes after a phase), not a change to approve.
|
|
394
|
+
outside = [f['path'] for f in files if not LOCKFILE.search(f['path']) and not f['path'].startswith('.mini/') and f['path'] != 'PLAN.md' and not inside(f['path'])]
|
|
383
395
|
if not outside: return []
|
|
384
396
|
return [{'kind': 'out_of_scope', 'severity': 'note', 'file': outside[0], 'line': 1,
|
|
385
397
|
'message': '%d file%s changed outside the areas approved for this task (%s). Check that these changes are wanted.' % (len(outside), '' if len(outside) == 1 else 's', ', '.join(outside[:5]))}]
|
|
386
398
|
|
|
387
399
|
|
|
400
|
+
NO_TEST_SCRIPT = re.compile(r"\b(?:do not|don't|never|without)\s+(?:add(?:ing)?|creat(?:e|ing)|writ(?:e|ing)|introduc(?:e|ing))\s+(?:a\s+|any\s+|new\s+)*(?:\"?test\"?\s+scripts?|tests?(?:\s+files?)?)\b", re.I)
|
|
401
|
+
def forbidden_test_script(files, task=''):
|
|
402
|
+
"""CLI bug list: "Keep running npm test until it passes. Do not add a test script." The agent decided the first
|
|
403
|
+
sentence overrode the second, added "test": "node --test" and a test file, and closed Done. A "do not add" stays."""
|
|
404
|
+
if not NO_TEST_SCRIPT.search(str(task or '')): return []
|
|
405
|
+
added = []
|
|
406
|
+
for f in files:
|
|
407
|
+
path = f.get('path') or ''
|
|
408
|
+
if f.get('deleted'): continue
|
|
409
|
+
if path.split('/')[-1] == 'package.json' and any(re.search(r'^\s*"test"\s*:', str(text)) for _, text in f.get('added') or []):
|
|
410
|
+
added.append(path + ' ("test" script)')
|
|
411
|
+
elif TEST_PATH.search(path) and f.get('added'):
|
|
412
|
+
added.append(path)
|
|
413
|
+
if not added: return []
|
|
414
|
+
return [{'kind': 'forbidden_change', 'severity': 'block', 'file': added[0].split(' ')[0], 'line': 1,
|
|
415
|
+
'message': 'The request says not to add a test script or tests, but this change adds ' + ', '.join(added[:4]) + '. Undo that and report the real result instead (for example: npm test fails because the project has no test script).',
|
|
416
|
+
'user': 'The request said not to add a test script, but the change added ' + ', '.join(added[:4]) + '.'}]
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def in_git(repo):
|
|
420
|
+
"""Outside a git work tree there is no diff, so an empty one says nothing about the edits (BUG-0508)."""
|
|
421
|
+
return _git(repo, 'rev-parse', '--is-inside-work-tree').strip() == 'true'
|
|
422
|
+
|
|
423
|
+
|
|
388
424
|
def empty_change(edits, files, task=''):
|
|
389
425
|
"""Files were edited during the task but nothing is left behind: the edits cancelled out. An unchanged repository is
|
|
390
426
|
the correct outcome when the user asked for no changes (an assessment or review), so it is not flagged then."""
|
|
@@ -423,6 +459,8 @@ RETRACTS = re.compile(r"\b(earlier|previously|before|correction|i was wrong|was
|
|
|
423
459
|
DENIAL = re.compile(r"\b(never|at no point|did(?: not|n't)|have(?: not|n't)|had(?: not|n't)|was(?: not|n't)|were(?: not|n't)|no)\b[^.!?\n]{0,70}?\b(browser|playwright|viewport|run|ran|tests?|tested|testing|verif(?:y|ied|ication)|check(?:ed|s)?)\b", re.I)
|
|
424
460
|
WHOLE_PAST = re.compile(r"\b(never|at no point|at all|actually|earlier|previous(ly)?|before|prior|so far|in this (session|conversation|project|thread)|to date|any (browser|real|actual))\b", re.I)
|
|
425
461
|
THIS_TURN = re.compile(r"\b(this (turn|time|step|change|round)|just now|since (the|my) (last|latest)|after (the|my) (last|latest)|yet for|again|re-?r[au]n)\b", re.I)
|
|
462
|
+
ABSENT_THING = re.compile(r"\b(no|without( a| any)?|missing|lacks?( a| any)?|has(?: not|n't)( got)?( a| any)?|does(?: not|n't) have( a| any)?)\s+(\"?test\"?|tests?|testing|build|lint|check)\s+(script|scripts|file|files|suite|runner|framework|command|setup|configured|defined)\b|\bmissing script\b", re.I)
|
|
463
|
+
TEST_TOPIC = re.compile(r'\b(test|tests|jest|vitest|pytest|mocha|spec|unittest|playwright test)\b', re.I)
|
|
426
464
|
BROWSER_WORDS = re.compile(r'\b(browser|playwright|viewport|\d{3,4} ?px|mobile width|desktop width|screenshot)\b', re.I)
|
|
427
465
|
ALL_PASSED = re.compile(r"\b(all|every|everything)\b[^.!?\n]{0,50}?\b(pass(?:ed|es|ing)?|green|succe(?:ss|ed|eded|ssful))\b|\b(\d+)\s*(?:/|of|out of)\s*(\d+)\b[^.!?\n]{0,30}\b(pass(?:ed|es|ing)?)\b", re.I)
|
|
428
466
|
REMOTE_OPEN = re.compile(r"\b(ci|remote|github actions?|pipeline|workflow|deploy(?:ment)? check)\b[^.!?\n]{0,90}\b(pending|not (?:yet )?(?:run|finished|complete[d]?|verified|checked|confirmed|observed)|still running|in progress|unverified|queued|waiting|has(?: not|n't)|have(?: not|n't)|did(?: not|n't))\b|\b(pending|waiting on|not (?:yet )?(?:verified|checked|confirmed|observed)|unverified)\b[^.!?\n]{0,90}\b(ci|remote|github actions?|pipeline|workflow)\b", re.I)
|
|
@@ -551,7 +589,11 @@ def denial_check(text, record):
|
|
|
551
589
|
import time as _time
|
|
552
590
|
for s in _sentences(text):
|
|
553
591
|
if not DENIAL.search(s) or not WHOLE_PAST.search(s) or THIS_TURN.search(s) or s.endswith('?'): continue
|
|
592
|
+
# "There is no test script in this project" says what the project lacks, not that nothing was checked (CLI bug list:
|
|
593
|
+
# a true "npm test fails" answer was blocked against an older, passing npm run build).
|
|
594
|
+
if ABSENT_THING.search(s): continue
|
|
554
595
|
browser = bool(BROWSER_WORDS.search(s))
|
|
596
|
+
topic = TEST_TOPIC if re.search(r'\btest', s, re.I) and not re.search(r'\b(check|verif)', s, re.I) else None
|
|
555
597
|
for run in reversed(list(record or [])):
|
|
556
598
|
if not isinstance(run, dict): continue
|
|
557
599
|
when = _time.strftime('%Y-%m-%d %H:%M UTC', _time.gmtime(float(run.get('time') or 0)))
|
|
@@ -561,7 +603,8 @@ def denial_check(text, record):
|
|
|
561
603
|
return [{'kind': 'contradicted_denial', 'severity': 'block', 'message': 'The final message says "' + quote(s) + '", but the run record shows passing browser checks on ' + when + ' at ' + ', '.join('%dpx' % w for w in widths) + '. Correct the statement: say what was tested and when, and whether the code has changed since.',
|
|
562
604
|
'user': 'The reply says "' + quote(s) + '", but the run record shows passing browser checks on ' + when + ' at ' + ', '.join('%dpx' % w for w in widths) + '.'}]
|
|
563
605
|
else:
|
|
564
|
-
passed = [clip(c.get('command') or '', 160) for c in run.get('checks') or [] if isinstance(c, dict) and c.get('status') == 'passed'
|
|
606
|
+
passed = [clip(c.get('command') or '', 160) for c in run.get('checks') or [] if isinstance(c, dict) and c.get('status') == 'passed'
|
|
607
|
+
and (topic is None or topic.search(str(c.get('command') or c.get('label') or '')))]
|
|
565
608
|
if passed:
|
|
566
609
|
return [{'kind': 'contradicted_denial', 'severity': 'block', 'message': 'The final message says "' + quote(s) + '", but the run record shows passing checks on ' + when + ' (' + '; '.join(passed[:3]) + '). Correct the statement: say what was run and when, and whether the code has changed since.',
|
|
567
610
|
'user': 'The reply says "' + quote(s) + '", but the run record shows passing checks on ' + when + ' (' + '; '.join(passed[:3]) + ').'}]
|
|
@@ -659,7 +702,7 @@ def report(repo, base, final_text, commands, checks, task='', last_edit=None, ed
|
|
|
659
702
|
try: files = file_diffs(repo, base)
|
|
660
703
|
except Exception: pass
|
|
661
704
|
if files is not None:
|
|
662
|
-
for check in (lambda: line_rules(files, task), lambda: check_weakening(files, task), lambda: invalid_json(repo, files), lambda: out_of_scope(files, scope), lambda: empty_change(edits, files, task)):
|
|
705
|
+
for check in (lambda: line_rules(files, task), lambda: check_weakening(files, task), lambda: invalid_json(repo, files), lambda: out_of_scope(files, scope), lambda: empty_change(edits, files, task) if in_git(repo) else [], lambda: forbidden_test_script(files, task)):
|
|
663
706
|
try: findings += check()
|
|
664
707
|
except Exception: pass
|
|
665
708
|
# Build integrity: navigation into pages that were never built, and a message that admits an open error yet says done.
|
|
@@ -680,10 +723,12 @@ def report(repo, base, final_text, commands, checks, task='', last_edit=None, ed
|
|
|
680
723
|
|
|
681
724
|
|
|
682
725
|
# Shell commands that count as checks (shared by the bridge and the PreToolUse hook).
|
|
683
|
-
|
|
726
|
+
# BUG-0350: `swiftc -typecheck *.swift` and `xcodebuild ... build` are the type check and build of a Swift project.
|
|
727
|
+
TEST_COMMAND = re.compile(r'(^|[;&|(\s])(pytest|python3? -m (pytest|unittest)|npm (run )?(test|build|lint|typecheck)|pnpm (run )?(test|build|lint)|yarn (run )?(test|build|lint)|npx (tsc|vitest|jest|playwright|eslint)|tsc( |$)|vitest|jest|go (test|build|vet)|cargo (test|build|check)|make (test|check)|bun (run )?test|deno test|mvn( -q)? test|gradle test|ruff|mypy|node --test|swift (test|build)|swiftc\b[^;&|\n]*\s-(typecheck|parse)\b|xcrun swiftc\b[^;&|\n]*\s-typecheck\b|xcodebuild\b[^;&|\n]*\b(build|test)\b)', re.I)
|
|
684
728
|
# Inline checks: an interpreter run (heredoc, -c/-e or a script) that asserts on behaviour, or runs a test-named file.
|
|
685
729
|
INLINE_RUN = re.compile(r'(^|[;&|(\s])(python3?|node|bun|deno run|tsx|ts-node)\s+(-c\b|-e\b|-\s|-$|<<|[\w./-]+\.(py|[cm]?js|ts)\b)', re.M)
|
|
686
|
-
|
|
730
|
+
# BUG-0296: `if (greet('World') !== 'Hello, World') process.exit(1)` asserts as much as assert() does.
|
|
731
|
+
INLINE_ASSERT = re.compile(r'\bassert\b|console\.assert|\bexpect\(|\bassert\.\w+\(|[\w./-]*(test_\w+|\w+_test|\w+\.test|\w+\.spec)\.(py|[cm]?js|ts)\b|\bprocess\.exit\(\s*[1-9]|\bprocess\.exitCode\s*=\s*[1-9]|\bsys\.exit\(\s*[1-9]|\bthrow new Error\(|\braise (?:SystemExit|AssertionError|ValueError|RuntimeError)\b')
|
|
687
732
|
# An inline script that rewrites files is an edit, not a check, even when it asserts that its search text was found
|
|
688
733
|
# (Windows bug list, item 7: python3 heredoc edits to .tsx files showed up as failed checks).
|
|
689
734
|
EDIT_SCRIPT = re.compile(r'\.write_text\(|\.write_bytes\(|writeFileSync\(|open\([^)]*,\s*[\'"][wa]\+?[\'"]|\bsed\s+-i')
|
|
@@ -755,3 +800,63 @@ def unverified_banner(report):
|
|
|
755
800
|
detail = ('; '.join(parts) + '. ') if parts else ''
|
|
756
801
|
return ('> **Not verified.** The final checks did not confirm this work (' + detail.rstrip('. ') + ').' if parts else '> **Not verified.** The final checks did not confirm this work.') + \
|
|
757
802
|
' Any "verified" or "working" claims below are unconfirmed until the checks are rerun and pass.\n\n'
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
# ---------------------------------------------------------------- BUG-0542: projects with no test suite
|
|
806
|
+
# A project with no tests, build or type check cannot be "verified" by one. Running the changed program itself
|
|
807
|
+
# (node app.js, python3 tool.py, ./run.sh) and seeing it exit 0 is the best check there is, so it counts as one.
|
|
808
|
+
RUN_FILE = re.compile(r'^\s*(?:(?:node|python3?|bash|sh|bun|deno run|tsx|ts-node)\s+(?:-[\w-]+\s+)*)?(\.{0,2}/?[\w./-]+\.(?:py|[cm]?js|ts|sh)|\./[\w./-]+)(?:\s+[^;&|<>`$]*)?$')
|
|
809
|
+
SUITE_FILES = re.compile(r'(^|/)(pytest\.ini|tox\.ini|conftest\.py|noxfile\.py|Cargo\.toml|go\.mod|pom\.xml|build\.gradle(\.kts)?|tsconfig\.json|jest\.config\.[cm]?[jt]s|vitest\.config\.[cm]?[jt]s|test_[^/]+\.py|[^/]+_test\.(py|go)|[^/]+\.(test|spec)\.[cm]?[jt]sx?)$|(^|/)(tests?|__tests__|spec)/', re.I)
|
|
810
|
+
|
|
811
|
+
def has_test_suite(repo):
|
|
812
|
+
"""True when the project has something a check can run: test files, a test/build/lint script, or a build config."""
|
|
813
|
+
import subprocess, json
|
|
814
|
+
root = Path(repo)
|
|
815
|
+
try:
|
|
816
|
+
pkg = json.loads((root / 'package.json').read_text())
|
|
817
|
+
scripts = pkg.get('scripts') if isinstance(pkg.get('scripts'), dict) else {}
|
|
818
|
+
for k in ('test', 'build', 'lint', 'typecheck', 'check'):
|
|
819
|
+
v = str(scripts.get(k) or '')
|
|
820
|
+
if v and 'no test specified' not in v: return True
|
|
821
|
+
except (OSError, ValueError, AttributeError): pass
|
|
822
|
+
try:
|
|
823
|
+
if re.search(r'^\s*(test|check)\s*:', (root / 'Makefile').read_text(errors='replace'), re.M): return True
|
|
824
|
+
except OSError: pass
|
|
825
|
+
try:
|
|
826
|
+
if '[tool.pytest' in (root / 'pyproject.toml').read_text(errors='replace'): return True
|
|
827
|
+
except OSError: pass
|
|
828
|
+
try:
|
|
829
|
+
out = subprocess.run(['git', 'ls-files', '-co', '--exclude-standard'], cwd=root, capture_output=True, text=True, timeout=10)
|
|
830
|
+
names = out.stdout.splitlines() if out.returncode == 0 else [str(p.relative_to(root)) for p in list(root.rglob('*'))[:5000] if '/node_modules/' not in str(p)]
|
|
831
|
+
except (OSError, subprocess.SubprocessError, ValueError): names = []
|
|
832
|
+
return any(SUITE_FILES.search(n.replace('\\', '/')) for n in names[:20000] if not n.startswith('node_modules/'))
|
|
833
|
+
|
|
834
|
+
INLINE_MODULE = re.compile(r"""\brequire\(\s*['"](\.{1,2}/[\w./-]+)['"]\s*\)|\bimport\(\s*['"](\.{1,2}/[\w./-]+)['"]\s*\)|\bfrom\s+['"](\.{1,2}/[\w./-]+)['"]|(?:^|[;"'])\s*from\s+([\w.]+)\s+import\b|(?:^|[;"'])\s*import\s+([\w.]+)""", re.M)
|
|
835
|
+
|
|
836
|
+
def inline_module_check(command, repo):
|
|
837
|
+
"""BUG-0296: `node -e "const {greet} = require('./greet'); console.log(greet('World'))"` loads the changed file and runs
|
|
838
|
+
it. In a project with no test suite that is the check the agent can run, like `node greet.js`. Returns the file, or ''."""
|
|
839
|
+
command = str(command or '')
|
|
840
|
+
if not re.search(r'(^|[;&|(\s])(python3?|node|bun|tsx|ts-node)\s+(-c\b|-e\b|-p\b|-\s|-$|<<)', command, re.M) or EDIT_SCRIPT.search(command): return ''
|
|
841
|
+
root = Path(repo).resolve()
|
|
842
|
+
for m in INLINE_MODULE.finditer(command):
|
|
843
|
+
rel = next(g for g in m.groups() if g)
|
|
844
|
+
candidates = [rel] if rel.startswith('.') else [rel.replace('.', '/')]
|
|
845
|
+
for base in candidates:
|
|
846
|
+
for ext in ('', '.js', '.mjs', '.cjs', '.ts', '.py', '/index.js', '/__init__.py'):
|
|
847
|
+
try:
|
|
848
|
+
target = (root / (base + ext)).resolve()
|
|
849
|
+
if target.is_file() and root in target.parents: return str(target.relative_to(root))
|
|
850
|
+
except (OSError, ValueError): pass
|
|
851
|
+
return ''
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
def program_run_check(command, repo):
|
|
855
|
+
"""The repository file a command runs directly (node a.js, ./run.sh), when that file exists; else ''."""
|
|
856
|
+
m = RUN_FILE.match(str(command or ''))
|
|
857
|
+
if not m: return inline_module_check(command, repo)
|
|
858
|
+
target = (Path(repo) / m.group(1)).resolve()
|
|
859
|
+
try:
|
|
860
|
+
if target.is_file() and Path(repo).resolve() in target.parents: return m.group(1)
|
|
861
|
+
except OSError: pass
|
|
862
|
+
return ''
|