mlai-code 0.3.8 → 0.3.10
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/bin/mlai.mjs +4 -1
- package/package.json +1 -1
- package/src/cli.mjs +67 -12
- package/src/headless.mjs +59 -9
- package/src/home.mjs +1 -1
- package/src/modes.mjs +5 -1
- package/src/render.mjs +4 -0
- package/src/session.mjs +15 -1
- package/src/tui/agents-cli.mjs +2 -0
- package/src/tui/app.mjs +1 -0
- package/src/tui/chat.mjs +7 -3
- package/src/tui/cmd-core.mjs +1 -1
- package/src/tui/extensions-local.mjs +5 -2
- package/src/tui/plain.mjs +16 -0
- package/src/tui/review-cli.mjs +2 -1
- package/src/tui/snapshots.mjs +30 -1
- package/src/tui/transcript.mjs +15 -1
- package/src/two-words.mjs +9 -0
- package/vendor/cloud-cli/mlai.mjs +41 -10
- package/worker/browser_tool.py +42 -4
- package/worker/checkpoints.py +23 -3
- package/worker/command_safety.py +18 -0
- package/worker/conversation.py +18 -1
- package/worker/design_director.py +2 -1
- package/worker/kimi_bridge.py +201 -47
- package/worker/kimi_gates.py +19 -2
- package/worker/kimi_hook.py +53 -10
- package/worker/mcp_local.py +33 -0
- package/worker/mlai_auto_review.py +25 -4
- package/worker/mlai_hooks.py +113 -7
- package/worker/mlai_mcp.py +16 -1
- package/worker/mlai_permissions.py +5 -3
- package/worker/mlai_review/__main__.py +3 -1
- package/worker/mlai_review/application/streaming.py +10 -0
- package/worker/mlai_review/infrastructure/local/publisher.py +25 -3
- package/worker/preview.py +399 -29
- package/worker/proc_watch.py +388 -50
- package/worker/runner.py +72 -1
- package/worker/verification.py +69 -3
package/worker/verification.py
CHANGED
|
@@ -9,7 +9,7 @@ pre_existing(repo, base, command) -> True when the same command also fails on t
|
|
|
9
9
|
Findings are dicts {'kind', 'message', 'severity': 'block'|'note'}; the hook and bridge turn `block` findings into
|
|
10
10
|
repair rounds and every finding into a `verification_report` event for the activity feed.
|
|
11
11
|
"""
|
|
12
|
-
import os, re, subprocess, tempfile, shutil
|
|
12
|
+
import os, re, signal, subprocess, sys, tempfile, time, shutil
|
|
13
13
|
from pathlib import Path
|
|
14
14
|
from runtime_control import latest_checks, check_status, clip, EXTERNAL_SCOPES
|
|
15
15
|
|
|
@@ -255,8 +255,10 @@ def pre_existing(repo, base, command, timeout=300):
|
|
|
255
255
|
try: os.symlink(src, Path(tmp) / link)
|
|
256
256
|
except OSError: pass
|
|
257
257
|
env = {k: v for k, v in os.environ.items() if k not in ('MODEL_API_KEY', 'MINI_KIMI_PROXY_TOKEN', 'VERCEL_OIDC_TOKEN')}
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
code, _out, why = bounded_run( # bounded on Windows too: a leftover child holding the output pipe cannot block it
|
|
259
|
+
['bash', '-lc', command], cwd=tmp, env=env, timeout=timeout)
|
|
260
|
+
if why: return None
|
|
261
|
+
return code != 0
|
|
260
262
|
except (OSError, subprocess.SubprocessError): return None
|
|
261
263
|
finally:
|
|
262
264
|
subprocess.run(['git', 'worktree', 'remove', '--force', tmp], cwd=repo, capture_output=True, timeout=60)
|
|
@@ -979,3 +981,67 @@ def program_run_check(command, repo):
|
|
|
979
981
|
if target.is_file() and Path(repo).resolve() in target.parents: return m.group(1)
|
|
980
982
|
except OSError: pass
|
|
981
983
|
return ''
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
# Bounded shell commands for checks the harness replays on its own (CLI r7).
|
|
987
|
+
# Bounded shell commands for the harness (checks it replays on its own).
|
|
988
|
+
#
|
|
989
|
+
# subprocess.run(..., capture_output=True, timeout=N) is not bounded on Windows: after the timeout it kills only the shell
|
|
990
|
+
# and then reads the pipes with no timeout, so a child that is still alive (a headless browser left by an e2e script) keeps
|
|
991
|
+
# the pipe open and the harness waits forever. One tester's run sat at "Working" for 45 minutes after its final answer.
|
|
992
|
+
#
|
|
993
|
+
# run() sends output to a temporary file instead of a pipe, starts the command in its own process group, and stops the
|
|
994
|
+
# whole tree on timeout or when stop() returns True. It always returns within about the timeout.
|
|
995
|
+
WINDOWS = os.name == 'nt'
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
def _kill_tree(proc):
|
|
999
|
+
"""Stops a started command and everything it launched. Never raises."""
|
|
1000
|
+
try:
|
|
1001
|
+
if proc.poll() is not None and not WINDOWS:
|
|
1002
|
+
# The shell is gone; its children may still be in the group.
|
|
1003
|
+
os.killpg(proc.pid, signal.SIGKILL); return
|
|
1004
|
+
except (OSError, ProcessLookupError): return
|
|
1005
|
+
try:
|
|
1006
|
+
if WINDOWS:
|
|
1007
|
+
import winproc
|
|
1008
|
+
winproc.kill_tree(proc.pid)
|
|
1009
|
+
else:
|
|
1010
|
+
os.killpg(proc.pid, signal.SIGKILL)
|
|
1011
|
+
except (OSError, ProcessLookupError, subprocess.SubprocessError):
|
|
1012
|
+
try: proc.kill()
|
|
1013
|
+
except OSError: pass
|
|
1014
|
+
|
|
1015
|
+
|
|
1016
|
+
def bounded_run(argv, cwd=None, env=None, timeout=150, stop=None, tail=4000, poll=0.25):
|
|
1017
|
+
"""Returns (returncode, output, reason). returncode is None when the command was stopped; reason is '' when it
|
|
1018
|
+
finished, 'timeout' or 'stopped' otherwise. output is the last `tail` characters of stdout and stderr together."""
|
|
1019
|
+
out = tempfile.TemporaryFile()
|
|
1020
|
+
kwargs = {'cwd': cwd, 'env': env, 'stdin': subprocess.DEVNULL, 'stdout': out, 'stderr': subprocess.STDOUT}
|
|
1021
|
+
if WINDOWS: kwargs['creationflags'] = getattr(subprocess, 'CREATE_NEW_PROCESS_GROUP', 0) | getattr(subprocess, 'CREATE_NO_WINDOW', 0)
|
|
1022
|
+
else: kwargs['start_new_session'] = True
|
|
1023
|
+
try:
|
|
1024
|
+
try: proc = subprocess.Popen(argv, **kwargs)
|
|
1025
|
+
except OSError as exc: return None, str(exc)[-tail:], 'error'
|
|
1026
|
+
deadline = time.time() + max(1, timeout)
|
|
1027
|
+
reason = ''
|
|
1028
|
+
while proc.poll() is None:
|
|
1029
|
+
if stop and stop(): reason = 'stopped'; break
|
|
1030
|
+
if time.time() >= deadline: reason = 'timeout'; break
|
|
1031
|
+
time.sleep(poll)
|
|
1032
|
+
code = proc.returncode
|
|
1033
|
+
if reason:
|
|
1034
|
+
_kill_tree(proc)
|
|
1035
|
+
try: proc.wait(timeout=10)
|
|
1036
|
+
except subprocess.TimeoutExpired: pass
|
|
1037
|
+
code = None
|
|
1038
|
+
elif not WINDOWS:
|
|
1039
|
+
# A background child left by the command must not outlive the check.
|
|
1040
|
+
try: os.killpg(proc.pid, signal.SIGKILL)
|
|
1041
|
+
except (OSError, ProcessLookupError): pass
|
|
1042
|
+
out.seek(0)
|
|
1043
|
+
text = out.read()[-tail * 4:].decode('utf-8', 'replace')[-tail:]
|
|
1044
|
+
if reason == 'timeout': text = (text + '\n' if text else '') + 'Stopped after %ds (timeout).' % timeout
|
|
1045
|
+
return code, text, reason
|
|
1046
|
+
finally:
|
|
1047
|
+
out.close()
|