mlai-code 0.3.3 → 0.3.5
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 +39 -11
- 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 +16 -5
- 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/tui/transcript.mjs +13 -2
- 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 +125 -13
- package/worker/git_sync.py +4 -4
- package/worker/image_generation.py +2 -2
- package/worker/kimi_bridge.py +251 -31
- package/worker/kimi_gates.py +25 -6
- package/worker/kimi_hook.py +154 -13
- 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 +164 -23
- package/worker/runtime_control.py +95 -9
- 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 +5 -2
- package/worker/verification.py +113 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"""Cancelable inference and factual completion evidence; no automatic effect replay."""
|
|
2
|
-
import json, queue, re, shlex, threading, time, urllib.request
|
|
2
|
+
import json, os, queue, re, shlex, threading, time, urllib.request
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
5
|
# Keep this classification aligned with lib/conversation-view.ts. A command's exit
|
|
@@ -38,14 +38,50 @@ def latest_checks(checks):
|
|
|
38
38
|
broader = [c for k, c in items[n + 1:] if k[0] == key[0] and isinstance(k[1], str) and isinstance(key[1], str)
|
|
39
39
|
and key[1].startswith(k[1] + ' ') and NARROWING.search(key[1][len(k[1]):]) and check_status(c) == 'passed']
|
|
40
40
|
if broader and check_status(check) == 'failed': continue
|
|
41
|
+
if check_status(check) == 'failed' and isinstance(key[1], str) and _rerun_inside(key, items[n + 1:]): continue
|
|
41
42
|
out.append(check)
|
|
42
43
|
return out
|
|
43
44
|
|
|
45
|
+
# BUG-0256: `npm test` failed during development, then `until curl -sf localhost:3000; do sleep 1; done && npm test`
|
|
46
|
+
# passed at the end. The combined check reran the same steps, so the earlier failure is history, not the current state.
|
|
47
|
+
_SEGMENT_SPLIT = re.compile(r'\s*(?:&&|\|\||;|\n)\s*')
|
|
48
|
+
_SEGMENT_LEAD = re.compile(r'^(?:(?:until|while|if|then|do|else|elif)\s+|\(\s*)+')
|
|
49
|
+
_TRIVIAL_SEGMENT = re.compile(r'^(?:sleep\b.*|cd\b.*|echo\b.*|printf\b.*|export\b.*|true|false|wait|done|fi|then|do|else|\)|\(|exit\b.*|set\b.*)?$')
|
|
50
|
+
|
|
51
|
+
def check_segments(command):
|
|
52
|
+
"""The meaningful steps of a check command, each normalised like check_key."""
|
|
53
|
+
out = []
|
|
54
|
+
for part in _SEGMENT_SPLIT.split(str(command or '')):
|
|
55
|
+
part = check_key(_SEGMENT_LEAD.sub('', part.strip()).rstrip(') ').strip())
|
|
56
|
+
if part and not _TRIVIAL_SEGMENT.match(part): out.append(part)
|
|
57
|
+
return out
|
|
58
|
+
|
|
59
|
+
def _rerun_inside(key, later):
|
|
60
|
+
"""Every step of a failing check was rerun by later passing checks in the same scope."""
|
|
61
|
+
steps = check_segments(key[1])
|
|
62
|
+
if not steps: return False
|
|
63
|
+
rerun = set()
|
|
64
|
+
for k, c in later:
|
|
65
|
+
if k[0] == key[0] and isinstance(k[1], str) and check_status(c) == 'passed': rerun.update(check_segments(k[1]))
|
|
66
|
+
return all(s in rerun for s in steps)
|
|
67
|
+
|
|
68
|
+
_ECHO_STATUS = re.compile(r'(?:;|&&|\|\||\n)\s*echo\b[^;&|\n]*\$\{?(?:\?|PIPESTATUS)', re.I)
|
|
69
|
+
_PRINTED_EXIT = re.compile(r'\b(?:exit(?:[ _-]?code)?|exit[ _-]?status|status|rc|code)\s*[=:]\s*(-?\d+)\b', re.I)
|
|
70
|
+
def masked_exit(command, output):
|
|
71
|
+
"""`npm test; echo "exit=$?"` exits 0 because echo ran last, while the output says exit=1. Returns the printed failing
|
|
72
|
+
exit code, or None (CLI bug list: such a line was marked "Check passed" and the task ended Done)."""
|
|
73
|
+
if not _ECHO_STATUS.search(str(command or '')): return None
|
|
74
|
+
found = _PRINTED_EXIT.findall(str(output or '')[-4000:])
|
|
75
|
+
if not found: return None
|
|
76
|
+
code = int(found[-1])
|
|
77
|
+
return code if code != 0 else None
|
|
78
|
+
|
|
44
79
|
def check_status(check):
|
|
45
80
|
if check.get('executed') is not True: return 'not_run'
|
|
46
81
|
verdict = check.get('verdict') or {}
|
|
47
82
|
if verdict.get('status') in ('failed', 'blocked'): return 'failed'
|
|
48
83
|
if check.get('returncode') not in (0, None): return 'failed'
|
|
84
|
+
if masked_exit(check.get('command'), check.get('output')): return 'failed'
|
|
49
85
|
if check.get('returncode') is None or (verdict.get('status') not in (None, 'passed')) or ZERO_TEST_OUTPUT.search(str(check.get('output') or '')):
|
|
50
86
|
return 'inconclusive'
|
|
51
87
|
# A pass recorded before the last code edit describes code that no longer exists.
|
|
@@ -87,12 +123,20 @@ def request_json(request, cancelled, timeout=100):
|
|
|
87
123
|
if not ok: raise value
|
|
88
124
|
return value
|
|
89
125
|
|
|
90
|
-
def completion_paths(repo,base=None):
|
|
126
|
+
def completion_paths(repo,base=None,since=None):
|
|
91
127
|
import subprocess
|
|
92
128
|
from repo_hygiene import change_path,is_noise
|
|
93
129
|
# -uall lists new files individually instead of collapsing them into a bare folder name.
|
|
94
130
|
git=subprocess.run(['git','status','--porcelain','-uall'],cwd=repo,capture_output=True,text=True,timeout=10)
|
|
95
131
|
lines=git.stdout.splitlines() if git.returncode==0 else []
|
|
132
|
+
if since:
|
|
133
|
+
# BUG-0577: a new file that was already there before this run started (made by the person in the Terminal)
|
|
134
|
+
# is not this run's change, so the reply does not offer it as its document.
|
|
135
|
+
def fresh(line):
|
|
136
|
+
if not line.startswith('??'):return True
|
|
137
|
+
try:return os.path.getmtime(os.path.join(repo,change_path(line)))>=float(since)-1
|
|
138
|
+
except (OSError,ValueError,TypeError):return True
|
|
139
|
+
lines=[l for l in lines if fresh(l)]
|
|
96
140
|
if base:
|
|
97
141
|
diff=subprocess.run(['git','diff','--name-status',base],cwd=repo,capture_output=True,text=True,timeout=10)
|
|
98
142
|
if diff.returncode==0:lines=diff.stdout.splitlines()+[line for line in lines if line.startswith('??')]
|
|
@@ -100,14 +144,19 @@ def completion_paths(repo,base=None):
|
|
|
100
144
|
return [p for p in dict.fromkeys(change_path(l) for l in lines) if p and not is_noise(p)]
|
|
101
145
|
|
|
102
146
|
|
|
103
|
-
def completion_report(root,repo,base=None):
|
|
147
|
+
def completion_report(root,repo,base=None,since=None):
|
|
104
148
|
import subprocess
|
|
105
149
|
root=Path(root)
|
|
106
150
|
def read(name,fallback):
|
|
107
151
|
try:return json.loads((root/name).read_text())
|
|
108
152
|
except (OSError,ValueError):return fallback
|
|
109
153
|
checks=read('checks.json',[]);todos=read('todos.json',[])
|
|
110
|
-
|
|
154
|
+
if since is None:since=read('status.json',{}).get('started') if isinstance(read('status.json',{}),dict) else None
|
|
155
|
+
changes=completion_paths(repo,base,since)
|
|
156
|
+
# Only what this turn changed: paths already changed or untracked when the turn started (save_start_dirty) are the
|
|
157
|
+
# person's own work. Subtracted before the list is clipped, so 600 old files cannot hide the one this turn made.
|
|
158
|
+
snapshot=read(START_DIRTY,None)
|
|
159
|
+
if isinstance(snapshot,dict):changes=changed_during_turn(repo,changes,snapshot)
|
|
111
160
|
summary = check_summary(checks)
|
|
112
161
|
unfinished = [t.get('text','') for t in todos if isinstance(t, dict) and t.get('status') not in ('done','cancelled')]
|
|
113
162
|
note = ('Local checks: %(passed)d passed, %(failed)d failed, %(notRun)d not run, %(inconclusive)d inconclusive.' % summary) if checks else 'No verification checks recorded.'
|
|
@@ -118,7 +167,7 @@ def completion_report(root,repo,base=None):
|
|
|
118
167
|
if unfinished: note += ' %d plan items remain unfinished.' % len(unfinished)
|
|
119
168
|
status = 'remote_pending' if summary['remotePendingOnly'] and not unfinished else 'needs_attention' if summary['needsAttention'] or unfinished else 'passed' if summary['passed'] else 'unverified'
|
|
120
169
|
if status == 'remote_pending': note += ' Local checks passed; the remote result has not been observed, so this is not yet confirmed end to end.'
|
|
121
|
-
return {'changedFiles':changes[:100], 'checksPassed':summary['passed'], 'checksFailed':summary['failed'],
|
|
170
|
+
return {'changedFiles':changes[:100], 'changedFilesTotal':len(changes), 'checksPassed':summary['passed'], 'checksFailed':summary['failed'],
|
|
122
171
|
'checksNotRun':summary['notRun'], 'checksInconclusive':summary['inconclusive'], 'checksStale':summary['stale'], 'externalChecksPassed':summary['externalPassed'],
|
|
123
172
|
'externalChecksPending':summary['externalPending'], 'externalChecksFailed':summary['externalFailed'],
|
|
124
173
|
'unfinishedTasks':unfinished, 'verification':note, 'verificationStatus':status, 'created':time.time()}
|
|
@@ -140,17 +189,54 @@ def _fingerprint(repo,path):
|
|
|
140
189
|
return 'missing'
|
|
141
190
|
|
|
142
191
|
|
|
143
|
-
def
|
|
144
|
-
"""
|
|
192
|
+
def _stat_fingerprint(repo,path):
|
|
193
|
+
"""A cheap fingerprint (size and modification time) for snapshots too large to hash file by file."""
|
|
194
|
+
try:
|
|
195
|
+
st=(Path(repo)/path).lstat()
|
|
196
|
+
return 'stat:%d:%d'%(st.st_size,st.st_mtime_ns)
|
|
197
|
+
except OSError:return 'stat:missing'
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def dirty_snapshot(repo,base=None,limit=None,hash_limit=2000,hash_bytes=2_000_000):
|
|
201
|
+
"""Paths that were already changed when the turn started, with a fingerprint of each. Every path is recorded (a folder
|
|
202
|
+
with 600 untracked files must not report the 401st as this turn's change); the first hash_limit small files get a
|
|
203
|
+
content hash, the rest a size/mtime fingerprint. limit is kept for callers that want a bounded sample."""
|
|
145
204
|
try:paths=completion_paths(repo,base)
|
|
146
205
|
except Exception:return {}
|
|
147
|
-
|
|
206
|
+
if limit is not None:paths=paths[:limit]
|
|
207
|
+
snap={}
|
|
208
|
+
for i,p in enumerate(paths):
|
|
209
|
+
target=Path(repo)/p
|
|
210
|
+
try:small=i<hash_limit and (target.is_dir() or not target.is_file() or target.stat().st_size<=hash_bytes)
|
|
211
|
+
except OSError:small=True
|
|
212
|
+
snap[p]=_fingerprint(repo,p) if small else _stat_fingerprint(repo,p)
|
|
213
|
+
return snap
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
START_DIRTY='start-dirty.json'
|
|
217
|
+
|
|
218
|
+
def save_start_dirty(root,repo,base=None):
|
|
219
|
+
"""BUG-0495/0497: remember what was already changed or untracked when the turn started, so the checker and the
|
|
220
|
+
"N files changed" summary only count what this turn did. Best effort: a failure keeps the old behavior."""
|
|
221
|
+
try:
|
|
222
|
+
snap=dirty_snapshot(repo,base)
|
|
223
|
+
(Path(root)/START_DIRTY).write_text(json.dumps(snap))
|
|
224
|
+
return snap
|
|
225
|
+
except Exception:return None
|
|
148
226
|
|
|
227
|
+
def turn_changes(root,repo,changed):
|
|
228
|
+
"""changed minus the paths that were already like this when the turn started (see save_start_dirty)."""
|
|
229
|
+
try:snap=json.loads((Path(root)/START_DIRTY).read_text())
|
|
230
|
+
except (OSError,ValueError):return list(changed or [])
|
|
231
|
+
return changed_during_turn(repo,changed,snap)
|
|
149
232
|
|
|
150
233
|
def changed_during_turn(repo,changed,snapshot):
|
|
151
234
|
"""Of the paths changed now, the ones the turn itself changed: new, or different from the start snapshot."""
|
|
152
235
|
if not isinstance(snapshot,dict):return list(changed or [])
|
|
153
|
-
|
|
236
|
+
def same(p):
|
|
237
|
+
old=snapshot[p]
|
|
238
|
+
return old==(_stat_fingerprint(repo,p) if str(old).startswith('stat:') else _fingerprint(repo,p))
|
|
239
|
+
return [p for p in changed or [] if p not in snapshot or not same(p)]
|
|
154
240
|
|
|
155
241
|
|
|
156
242
|
SAFE_PROGRAMS=frozenset(('ls','cat','head','tail','wc','grep','rg','pwd','echo','tree','stat','file','du','df','which','whoami','date','uname','jq','sort','uniq','cut','tr','basename','dirname','realpath','diff','true','nl','column'))
|
package/worker/secret_scan.py
CHANGED
|
@@ -14,7 +14,8 @@ PATTERNS = [
|
|
|
14
14
|
('github', 'GITHUB_TOKEN', r'\b(?:github_pat_[A-Za-z0-9_]{40,255}|gh[pousr]_[A-Za-z0-9]{30,255})\b'),
|
|
15
15
|
('anthropic', 'ANTHROPIC_API_KEY', r'\bsk-ant-[A-Za-z0-9_-]{20,300}'),
|
|
16
16
|
('openrouter', 'OPENROUTER_API_KEY', r'\bsk-or-v1-[A-Za-z0-9]{32,128}\b'),
|
|
17
|
-
('openai', 'OPENAI_API_KEY', r'\bsk-(?:proj-|svcacct-|admin-)
|
|
17
|
+
('openai', 'OPENAI_API_KEY', r'\bsk-(?:proj-|svcacct-|admin-)[A-Za-z0-9_-]{20,300}'),
|
|
18
|
+
('api_key', 'API_KEY', r'\bsk-[A-Za-z0-9_-]{20,300}'), # BUG-0549: bare sk- keys belong to many services
|
|
18
19
|
('stripe', 'STRIPE_SECRET_KEY', r'\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{16,255}\b'),
|
|
19
20
|
('stripe_webhook', 'STRIPE_WEBHOOK_SECRET', r'\bwhsec_[A-Za-z0-9]{24,255}\b'),
|
|
20
21
|
('slack', 'SLACK_TOKEN', r'\bxox[abposr]-[A-Za-z0-9-]{10,255}\b'),
|
|
@@ -100,7 +101,7 @@ def findings_for(path, text, allow=()):
|
|
|
100
101
|
|
|
101
102
|
|
|
102
103
|
def describe(f):
|
|
103
|
-
label = {'stripe': 'a Stripe key', 'github': 'a GitHub token', 'aws': 'an AWS access key', 'openai': 'an OpenAI key', 'anthropic': 'an Anthropic key', 'pem': 'a private key', 'vercel': 'a Vercel token', 'jwt': 'a signed token (JWT)', 'mlai': 'an ML AI Code token'}.get(f['kind'], 'a credential (' + f['name'] + ')')
|
|
104
|
+
label = {'stripe': 'a Stripe key', 'github': 'a GitHub token', 'aws': 'an AWS access key', 'openai': 'an OpenAI key', 'api_key': 'an API key', 'anthropic': 'an Anthropic key', 'pem': 'a private key', 'vercel': 'a Vercel token', 'jwt': 'a signed token (JWT)', 'mlai': 'an ML AI Code token'}.get(f['kind'], 'a credential (' + f['name'] + ')')
|
|
104
105
|
return label + ' at ' + f['file'] + ':' + str(f['line'])
|
|
105
106
|
|
|
106
107
|
|
|
@@ -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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"""Task-scoped tool disclosure; execution permissions remain runner-owned."""
|
|
2
2
|
import os
|
|
3
|
+
from conversation import web_available
|
|
3
4
|
GROUPS={
|
|
4
5
|
'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.'},
|
|
6
|
+
'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
7
|
'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
8
|
'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
9
|
'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.'},
|
|
@@ -22,7 +23,9 @@ def groups(config):
|
|
|
22
23
|
selected=set(config.get('_tool_groups',[]))|{'repository','planning'}
|
|
23
24
|
# The Mac app's iOS Simulator pane is there when the app gave this run its address (worker/ios_simulator.py).
|
|
24
25
|
if os.environ.get('MINI_SIM_URL') and config.get('mode')!='plan' and not config.get('subagent'):selected.add('simulator')
|
|
25
|
-
|
|
26
|
+
# Web search is part of every main-agent turn (a chat question about the weather needs it as much as a research
|
|
27
|
+
# turn), so the model knows from its first call that it can look things up instead of saying it has no web access.
|
|
28
|
+
if config.get('conversation_route')=='research' or web_available(config):selected.add('research')
|
|
26
29
|
if config.get('mode')!='plan':selected|={'editing','decks'}
|
|
27
30
|
# The Mac app's browser pane is there when the app gave this run its address (worker/browser_pane.py).
|
|
28
31
|
if os.environ.get('MINI_PANE_URL') and config.get('mode')!='plan' and not config.get('subagent'):selected.add('pane')
|
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 ''
|