mlai-code 0.0.0-stage → 0.3.0

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.
Files changed (182) hide show
  1. package/README.md +12 -2
  2. package/bin/mlai.mjs +3 -0
  3. package/package.json +18 -3
  4. package/src/browser-setup.mjs +77 -0
  5. package/src/cli-ext.mjs +146 -0
  6. package/src/cli.mjs +534 -0
  7. package/src/cloud.mjs +29 -0
  8. package/src/completion.mjs +159 -0
  9. package/src/credentials.mjs +54 -0
  10. package/src/deploy.mjs +134 -0
  11. package/src/distribution.mjs +373 -0
  12. package/src/engine-key.mjs +4 -0
  13. package/src/engine.mjs +167 -0
  14. package/src/headless.mjs +196 -0
  15. package/src/home.mjs +22 -0
  16. package/src/host.mjs +123 -0
  17. package/src/local-models.mjs +64 -0
  18. package/src/modes.mjs +38 -0
  19. package/src/netbox.mjs +97 -0
  20. package/src/netjail.py +59 -0
  21. package/src/offline.mjs +98 -0
  22. package/src/parity.mjs +86 -0
  23. package/src/project.mjs +68 -0
  24. package/src/relay.mjs +140 -0
  25. package/src/render.mjs +73 -0
  26. package/src/restricted.mjs +47 -0
  27. package/src/review.mjs +70 -0
  28. package/src/runner.mjs +127 -0
  29. package/src/runtime.mjs +75 -0
  30. package/src/sandbox.mjs +135 -0
  31. package/src/sdk.mjs +11 -0
  32. package/src/server.mjs +110 -0
  33. package/src/session.mjs +290 -0
  34. package/src/settings.mjs +135 -0
  35. package/src/shared-data.mjs +3 -0
  36. package/src/tui/acp.mjs +145 -0
  37. package/src/tui/agents-cli.mjs +114 -0
  38. package/src/tui/agents-local.mjs +65 -0
  39. package/src/tui/ansi.mjs +123 -0
  40. package/src/tui/app.mjs +710 -0
  41. package/src/tui/approval.mjs +88 -0
  42. package/src/tui/bg.mjs +172 -0
  43. package/src/tui/bgterm.mjs +79 -0
  44. package/src/tui/chat.mjs +230 -0
  45. package/src/tui/clipboard.mjs +74 -0
  46. package/src/tui/cloud-cli.mjs +57 -0
  47. package/src/tui/cloud-run.mjs +123 -0
  48. package/src/tui/cmd-agents.mjs +130 -0
  49. package/src/tui/cmd-auto-review.mjs +94 -0
  50. package/src/tui/cmd-cloud.mjs +17 -0
  51. package/src/tui/cmd-config.mjs +104 -0
  52. package/src/tui/cmd-core.mjs +160 -0
  53. package/src/tui/cmd-distribution.mjs +15 -0
  54. package/src/tui/cmd-ecosystem.mjs +169 -0
  55. package/src/tui/cmd-extensibility.mjs +333 -0
  56. package/src/tui/cmd-remote.mjs +18 -0
  57. package/src/tui/cmd-review.mjs +58 -0
  58. package/src/tui/cmd-session-extra.mjs +152 -0
  59. package/src/tui/cmd-tui.mjs +200 -0
  60. package/src/tui/commands.mjs +160 -0
  61. package/src/tui/custom-commands.mjs +98 -0
  62. package/src/tui/diff.mjs +60 -0
  63. package/src/tui/editor.mjs +190 -0
  64. package/src/tui/ext-state.mjs +16 -0
  65. package/src/tui/extensions-local.mjs +140 -0
  66. package/src/tui/files.mjs +72 -0
  67. package/src/tui/handoff.mjs +110 -0
  68. package/src/tui/import-setups.mjs +151 -0
  69. package/src/tui/init.mjs +104 -0
  70. package/src/tui/keymap.mjs +70 -0
  71. package/src/tui/keys.mjs +101 -0
  72. package/src/tui/loop.mjs +75 -0
  73. package/src/tui/markdown.mjs +118 -0
  74. package/src/tui/mcp-config.mjs +225 -0
  75. package/src/tui/mcp-oauth.mjs +162 -0
  76. package/src/tui/permissions.mjs +189 -0
  77. package/src/tui/plain.mjs +32 -0
  78. package/src/tui/plugins-local.mjs +103 -0
  79. package/src/tui/remote.mjs +125 -0
  80. package/src/tui/review-cli.mjs +332 -0
  81. package/src/tui/review-github.mjs +59 -0
  82. package/src/tui/screen.mjs +60 -0
  83. package/src/tui/session-ops.mjs +104 -0
  84. package/src/tui/skills-local.mjs +92 -0
  85. package/src/tui/snapshots.mjs +87 -0
  86. package/src/tui/statusline.mjs +98 -0
  87. package/src/tui/transcript.mjs +116 -0
  88. package/src/two-words.mjs +36 -0
  89. package/src/wakeups.mjs +53 -0
  90. package/src/winenv.mjs +94 -0
  91. package/src/winsandbox.py +351 -0
  92. package/src/workspace-api.mjs +621 -0
  93. package/src/worktree.mjs +128 -0
  94. package/vendor/client-sdk/controller.cjs +115 -0
  95. package/vendor/client-sdk/files.cjs +38 -0
  96. package/vendor/client-sdk/index.cjs +133 -0
  97. package/vendor/client-sdk/login.cjs +52 -0
  98. package/vendor/client-sdk/updates.cjs +41 -0
  99. package/vendor/cloud-cli/mlai.mjs +394 -0
  100. package/worker/architecture_parse.cjs +23 -0
  101. package/worker/architecture_worker.py +394 -0
  102. package/worker/ask_first.py +96 -0
  103. package/worker/attachment_reader.py +66 -0
  104. package/worker/background_jobs.py +111 -0
  105. package/worker/brief_questions.py +56 -0
  106. package/worker/browser_local.py +49 -0
  107. package/worker/browser_pane.py +89 -0
  108. package/worker/browser_tool.py +101 -0
  109. package/worker/build_planner.py +187 -0
  110. package/worker/chat_fork.py +277 -0
  111. package/worker/checkpoints.py +133 -0
  112. package/worker/cloud_pty.py +351 -0
  113. package/worker/command_policy.py +39 -0
  114. package/worker/command_safety.py +717 -0
  115. package/worker/computer_card.sh +23 -0
  116. package/worker/computer_setup.sh +86 -0
  117. package/worker/computer_use.py +221 -0
  118. package/worker/connector_search.py +43 -0
  119. package/worker/context_manager.py +60 -0
  120. package/worker/conversation.py +144 -0
  121. package/worker/deploy_pack.py +116 -0
  122. package/worker/design_director.py +240 -0
  123. package/worker/dev_jobs.py +166 -0
  124. package/worker/edit_guard.py +99 -0
  125. package/worker/env_setup.py +129 -0
  126. package/worker/evidence.py +109 -0
  127. package/worker/fast_search.py +24 -0
  128. package/worker/git_sync.py +333 -0
  129. package/worker/goals.py +156 -0
  130. package/worker/handover.py +98 -0
  131. package/worker/harness_memory.py +194 -0
  132. package/worker/image_generation.py +173 -0
  133. package/worker/intelligence.py +149 -0
  134. package/worker/intent_model.py +78 -0
  135. package/worker/intent_weights.json +1 -0
  136. package/worker/ios_simulator.py +87 -0
  137. package/worker/kimi_bridge.py +997 -0
  138. package/worker/kimi_compact.py +93 -0
  139. package/worker/kimi_gates.py +304 -0
  140. package/worker/kimi_hook.py +617 -0
  141. package/worker/lifecycle.py +95 -0
  142. package/worker/lsp.py +77 -0
  143. package/worker/mcp_local.py +293 -0
  144. package/worker/memory.py +99 -0
  145. package/worker/mlai_auto_review.py +177 -0
  146. package/worker/mlai_hooks.py +966 -0
  147. package/worker/mlai_mcp.py +441 -0
  148. package/worker/mlai_permissions.py +283 -0
  149. package/worker/model_stream.py +75 -0
  150. package/worker/nested_repos.py +76 -0
  151. package/worker/offline_guard.py +17 -0
  152. package/worker/preview.py +806 -0
  153. package/worker/proc_watch.py +124 -0
  154. package/worker/project_context.py +72 -0
  155. package/worker/project_rules.py +99 -0
  156. package/worker/quality.py +180 -0
  157. package/worker/reply_language.py +56 -0
  158. package/worker/repo_hygiene.py +132 -0
  159. package/worker/repo_memory.py +101 -0
  160. package/worker/repo_policy.py +269 -0
  161. package/worker/roles.json +3173 -0
  162. package/worker/roles.py +303 -0
  163. package/worker/runner.py +1795 -0
  164. package/worker/runtime_control.py +205 -0
  165. package/worker/secret_scan.py +168 -0
  166. package/worker/session_hub.py +80 -0
  167. package/worker/skill_library.py +129 -0
  168. package/worker/skill_pack.py +533 -0
  169. package/worker/subagents.py +91 -0
  170. package/worker/task_controller.py +139 -0
  171. package/worker/task_skills.py +159 -0
  172. package/worker/team_checkpoint.py +33 -0
  173. package/worker/token_count.py +32 -0
  174. package/worker/tool_catalog.py +38 -0
  175. package/worker/upload_storage.py +531 -0
  176. package/worker/verification.py +725 -0
  177. package/worker/vision.py +84 -0
  178. package/worker/wakeups.py +63 -0
  179. package/worker/web_tools.py +203 -0
  180. package/worker/winproc.py +135 -0
  181. package/worker/work_ledger.py +117 -0
  182. package/worker/worktrees.py +79 -0
@@ -0,0 +1,79 @@
1
+ """Writable subagents use independent Git worktrees; merge is a separate approved action."""
2
+ import json,os,re,signal,subprocess,sys,time,uuid
3
+ from pathlib import Path
4
+
5
+ def git(repo,*args):
6
+ p=subprocess.run(['git',*args],cwd=repo,capture_output=True,text=True,timeout=30)
7
+ if p.returncode:raise ValueError(p.stderr[-2000:] or 'Git operation failed')
8
+ return p.stdout.strip()
9
+
10
+ def run_writers(config,tasks,root,repo,cancelled,emit):
11
+ if config.get('subagent'):raise ValueError('Subagent recursion denied')
12
+ if not isinstance(tasks,list) or not 1<=len(tasks)<=3 or any(not isinstance(t,str) or not 1<=len(t)<=5000 for t in tasks):raise ValueError('Provide one to three bounded tasks')
13
+ if git(repo,'status','--porcelain'):raise ValueError('Commit or checkpoint current changes before writable delegation')
14
+ root=Path(root);base=git(repo,'rev-parse','HEAD');jobs=[];reports=[];deadline=time.monotonic()+240
15
+ try:
16
+ for task in tasks:
17
+ ident=uuid.uuid4().hex[:16];directory=root/'writers'/ident;directory.mkdir(parents=True)
18
+ workspace=directory/'repo';branch='mini-agent/'+ident
19
+ git(repo,'worktree','add','-b',branch,str(workspace),base)
20
+ meta={'id':ident,'branch':branch,'base':base,'workspace':str(workspace),'task':task};(directory/'meta.json').write_text(json.dumps(meta))
21
+ child={**config,'task':'Implement only this assigned task in your worktree. Run relevant tests and commit intended changes locally in this worktree so the parent can review new files. Do not push, deploy, change branches or merge.\n'+task,'mode':'auto','steps':12,'tools':[],'subagent':True}
22
+ (directory/'request.json').write_text(json.dumps(child))
23
+ env={k:v for k,v in os.environ.items() if k!='VERCEL_OIDC_TOKEN'};env.update(MINI_ROOT=str(directory),MINI_REPO=str(workspace))
24
+ process=subprocess.Popen([sys.executable,str(Path(__file__).with_name('runner.py'))],env=env,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,start_new_session=True)
25
+ jobs.append((meta,directory,process));emit('subagent',id=ident,state='running',content=task+' (isolated Git worktree)')
26
+ while any(p.poll() is None for _,_,p in jobs):
27
+ cancelled()
28
+ if time.monotonic()>deadline:raise ValueError('Writable agent time budget reached; branches retained for inspection')
29
+ time.sleep(.2)
30
+ for meta,directory,proc in jobs:
31
+ try:status=json.loads((directory/'status.json').read_text())
32
+ except (OSError,ValueError):status={'state':'error','error':'Worker exited without status'}
33
+ # No auto-merge and no auto-commit. Parent inspects the exact diff first.
34
+ diff=git(meta['workspace'],'diff','--stat');untracked=git(meta['workspace'],'ls-files','--others','--exclude-standard')
35
+ report={**meta,'state':status.get('state'),'diffStat':diff,'untracked':untracked,'tokens':status.get('tokens',0),'calls':status.get('calls',0)}
36
+ reports.append(report);emit('subagent',id=meta['id'],state=report['state'],content=json.dumps(report))
37
+ return reports
38
+ finally:
39
+ from lifecycle import load,alive
40
+ for _,directory,process in jobs:
41
+ child=load(directory,'child.json')
42
+ if child and alive(child):
43
+ try:os.killpg(child['pid'],signal.SIGKILL)
44
+ except ProcessLookupError:pass
45
+ if process.poll() is None:
46
+ try:os.killpg(process.pid,signal.SIGKILL)
47
+ except ProcessLookupError:pass
48
+ process.wait()
49
+
50
+ def inspect_writer(root,repo,ident):
51
+ if not isinstance(ident,str) or not re.fullmatch('[a-f0-9]{16}',ident):raise ValueError('Invalid agent ID')
52
+ directory=Path(root)/'writers'/ident;meta=json.loads((directory/'meta.json').read_text());workspace=directory/'repo'
53
+ if not workspace.is_dir() or Path(meta['workspace']).resolve()!=workspace.resolve():raise ValueError('Invalid agent workspace')
54
+ return {'id':ident,'branch':meta['branch'],'base':meta['base'],'diff':git(workspace,'diff',meta['base'])[:30000],'untracked':git(workspace,'ls-files','--others','--exclude-standard'),'note':'Review files and tests. Merge is manual; no changes applied to parent.'}
55
+
56
+ def integration_plan(root,repo,ident):
57
+ import hashlib
58
+ inspected=inspect_writer(root,repo,ident)
59
+ directory=Path(root)/'writers'/ident;workspace=directory/'repo'
60
+ if git(workspace,'ls-files','--others','--exclude-standard'):
61
+ raise ValueError('The child must commit all intended new files before integration; inspect untracked files first')
62
+ patch=subprocess.run(['git','diff','--binary',inspected['base'],'--'],cwd=workspace,capture_output=True,text=True,check=True,timeout=30).stdout
63
+ names=git(workspace,'diff','--name-only',inspected['base'],'--').splitlines()
64
+ for name in names:
65
+ if any(part.startswith('.env') or part in ('.mini','.git') or part.endswith(('.pem','.key')) for part in Path(name).parts):raise ValueError('Integration contains credential/state paths; inspect and remove them first')
66
+ head=git(repo,'rev-parse','HEAD')
67
+ digest=hashlib.sha256((head+'\0'+patch).encode()).hexdigest()
68
+ return {'id':ident,'hash':digest,'parentHead':head,'files':names,'patch':patch,'empty':not bool(patch),'note':'Review this exact patch; integration fails if either branch changes or parent has uncommitted work.'}
69
+
70
+ def integrate_writer(root,repo,ident,expected_hash):
71
+ plan=integration_plan(root,repo,ident)
72
+ if plan['hash']!=expected_hash:raise ValueError('Integration plan changed; review it again')
73
+ if git(repo,'status','--porcelain'):raise ValueError('Parent has uncommitted changes; checkpoint before integration')
74
+ if plan['empty']:raise ValueError('Child has no changes to integrate')
75
+ check=subprocess.run(['git','apply','--check','--binary','-'],cwd=repo,input=plan['patch'],text=True,capture_output=True,timeout=30)
76
+ if check.returncode:raise ValueError('Conflicting patch; parent unchanged. Resolve in the child worktree and review again: '+check.stderr[-1500:])
77
+ result=subprocess.run(['git','apply','--binary','-'],cwd=repo,input=plan['patch'],text=True,capture_output=True,timeout=30)
78
+ if result.returncode:raise ValueError('Integration failed: '+result.stderr[-1500:])
79
+ return {'id':ident,'files':plan['files'],'state':'applied','note':'Changes applied to parent, not committed. Run parent tests before committing.'}