index.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <title>Workbench CLI Audit</title>
  7. <meta
  8. name="description"
  9. content="Architecture, current state, cloud runtime notes, and a 20-item improvement backlog for the reconstructed Workbench CLI repository."
  10. />
  11. <link rel="stylesheet" href="./styles.css" />
  12. </head>
  13. <body>
  14. <header class="hero">
  15. <div class="hero-inner">
  16. <p class="eyebrow">Static project documentation</p>
  17. <h1>Workbench CLI</h1>
  18. <p class="lede">
  19. This site documents how the reconstructed Workbench CLI works, what
  20. the cloud and remote-control surfaces do, what state the repo is in
  21. right now, and the 20 highest-value improvements that would move it
  22. closer to a maintainable release.
  23. </p>
  24. <div class="meta">
  25. <span>Audit date: 2026-03-31</span>
  26. <span>Source files in <code>src/</code>: 1,929</span>
  27. <span>Extracted files in <code>stubs/</code>: 493</span>
  28. </div>
  29. <div class="status-grid">
  30. <article class="status-card ok">
  31. <h2>Install</h2>
  32. <p><code>bun install</code> succeeds.</p>
  33. </article>
  34. <article class="status-card ok">
  35. <h2>Build</h2>
  36. <p>
  37. <code>bun run build</code> succeeds and emits
  38. <code>dist/cli.js</code>.
  39. </p>
  40. </article>
  41. <article class="status-card warn">
  42. <h2>Typecheck</h2>
  43. <p>
  44. <code>bun run typecheck</code> reports 4,469 TypeScript errors in
  45. this checkout.
  46. </p>
  47. </article>
  48. <article class="status-card info">
  49. <h2>Cloud Logic</h2>
  50. <p>
  51. Remote control, teleport, direct connect, and managed settings
  52. are all materially implemented.
  53. </p>
  54. </article>
  55. </div>
  56. </div>
  57. </header>
  58. <div class="page">
  59. <aside class="toc">
  60. <h2>Contents</h2>
  61. <nav>
  62. <a href="#overview">Overview</a>
  63. <a href="#flow">How it works</a>
  64. <a href="#files">Main files</a>
  65. <a href="#cloud">Cloud architecture</a>
  66. <a href="#state">Current state</a>
  67. <a href="#improvements">20 improvements</a>
  68. <a href="#hosting">Hosting</a>
  69. </nav>
  70. </aside>
  71. <main class="content">
  72. <section id="overview" class="panel">
  73. <h2>Overview</h2>
  74. <p>
  75. This repository is a reconstructed agentic CLI codebase built
  76. around Bun, React, a custom Ink fork, a large tool system, MCP
  77. integration, and several cloud-facing session flows. The central
  78. runtime is real and substantial: there is enough code here to study
  79. architecture, trace the execution path, and understand how local,
  80. remote, and teleported sessions are meant to behave.
  81. </p>
  82. <p>
  83. The repo is not in release shape. The biggest gaps are missing
  84. generated or extracted source files, partial native/private shims,
  85. and heavy type drift between the recovered source and the
  86. dependency versions currently installed.
  87. </p>
  88. <div class="summary-grid">
  89. <article>
  90. <h3>Architecture completeness</h3>
  91. <p>High. Most of the core execution, UI, tools, and cloud flows are present.</p>
  92. </article>
  93. <article>
  94. <h3>Build integrity</h3>
  95. <p>Medium. A fresh install now produces a working bundle, but the fallback shim layer is still fragile.</p>
  96. </article>
  97. <article>
  98. <h3>Type integrity</h3>
  99. <p>Low. The checkout currently fails typecheck at scale.</p>
  100. </article>
  101. <article>
  102. <h3>Cloud feature depth</h3>
  103. <p>Medium. Remote-control and teleport logic are real, but the release surface is incomplete.</p>
  104. </article>
  105. </div>
  106. </section>
  107. <section id="flow" class="panel">
  108. <h2>How it works</h2>
  109. <ol class="step-list">
  110. <li>
  111. <strong>Build stage.</strong> <code>build.ts</code> bundles
  112. <code>src/entrypoints/cli.tsx</code>, injects a small
  113. <code>MACRO</code> set, and relies on <code>shims/bun-bundle.ts</code>
  114. to disable all feature flags by returning <code>false</code>.
  115. </li>
  116. <li>
  117. <strong>CLI bootstrap.</strong> <code>src/entrypoints/cli.tsx</code>
  118. handles fast paths such as version printing and special entrypoints,
  119. then hands control to <code>src/main.tsx</code>.
  120. </li>
  121. <li>
  122. <strong>Initialization.</strong> <code>src/entrypoints/init.ts</code>
  123. turns on config loading, safe environment variables, TLS and proxy
  124. setup, telemetry bootstrapping, scratchpad setup, and cleanup hooks.
  125. </li>
  126. <li>
  127. <strong>Context collection.</strong> <code>src/context.ts</code>
  128. prepares system and user context, including git state snapshots and
  129. <code>CLAUDE.md</code> memory injection.
  130. </li>
  131. <li>
  132. <strong>Conversation engine.</strong> <code>src/QueryEngine.ts</code>
  133. owns turn lifecycle, message state, usage, and SDK-facing session
  134. behavior. <code>src/query.ts</code> runs the actual streaming loop.
  135. </li>
  136. <li>
  137. <strong>Model and tool orchestration.</strong>
  138. <code>src/services/api/claude.ts</code> streams model responses,
  139. while <code>src/services/tools/StreamingToolExecutor.ts</code> and
  140. <code>src/services/tools/toolOrchestration.ts</code> execute tool
  141. calls with permission checks and concurrency rules.
  142. </li>
  143. <li>
  144. <strong>Terminal UI.</strong> <code>src/replLauncher.tsx</code>
  145. mounts <code>src/screens/REPL.tsx</code>, which is the main full
  146. screen interface built on top of the custom Ink implementation in
  147. <code>src/ink/</code>.
  148. </li>
  149. <li>
  150. <strong>Extensibility.</strong> Slash commands come from
  151. <code>src/commands.ts</code>, tools from <code>src/tools.ts</code>,
  152. MCP servers from <code>src/services/mcp/</code>, plugins from
  153. <code>src/utils/plugins/</code>, and skills from
  154. <code>src/skills/</code>.
  155. </li>
  156. <li>
  157. <strong>Cloud and remote execution.</strong> Remote-control,
  158. teleport, direct connect, and session transport are split across
  159. <code>src/bridge/</code>, <code>src/remote/</code>,
  160. <code>src/server/</code>, and <code>src/utils/teleport.tsx</code>.
  161. </li>
  162. </ol>
  163. </section>
  164. <section id="files" class="panel">
  165. <h2>Main files at a glance</h2>
  166. <table>
  167. <thead>
  168. <tr>
  169. <th>File</th>
  170. <th>Role</th>
  171. <th>Why it matters</th>
  172. </tr>
  173. </thead>
  174. <tbody>
  175. <tr>
  176. <td><code>build.ts</code></td>
  177. <td>Bundle entry and macro injection</td>
  178. <td>Defines what ships and what feature-gated code survives.</td>
  179. </tr>
  180. <tr>
  181. <td><code>src/entrypoints/cli.tsx</code></td>
  182. <td>Fast-path bootstrap</td>
  183. <td>Decides whether the process becomes the CLI, a bridge, or a special worker.</td>
  184. </tr>
  185. <tr>
  186. <td><code>src/main.tsx</code></td>
  187. <td>Main runtime coordinator</td>
  188. <td>Registers commands, parses options, handles resume, teleport, and remote sessions.</td>
  189. </tr>
  190. <tr>
  191. <td><code>src/entrypoints/init.ts</code></td>
  192. <td>Config, auth, network, telemetry init</td>
  193. <td>Most cross-cutting startup side effects live here.</td>
  194. </tr>
  195. <tr>
  196. <td><code>src/context.ts</code></td>
  197. <td>Prompt context builder</td>
  198. <td>Injects git and memory context into every session.</td>
  199. </tr>
  200. <tr>
  201. <td><code>src/QueryEngine.ts</code></td>
  202. <td>Per-session execution engine</td>
  203. <td>Holds state across turns for SDK and future non-REPL usage.</td>
  204. </tr>
  205. <tr>
  206. <td><code>src/query.ts</code></td>
  207. <td>Streaming query loop</td>
  208. <td>Runs model sampling, tool execution, retries, and compaction behavior.</td>
  209. </tr>
  210. <tr>
  211. <td><code>src/services/api/claude.ts</code></td>
  212. <td>Model request layer</td>
  213. <td>Converts tools, context, betas, and auth into model calls.</td>
  214. </tr>
  215. <tr>
  216. <td><code>src/services/api/client.ts</code></td>
  217. <td>Provider client factory</td>
  218. <td>Creates Anthropic, Bedrock, Foundry, or Vertex clients.</td>
  219. </tr>
  220. <tr>
  221. <td><code>src/services/tools/StreamingToolExecutor.ts</code></td>
  222. <td>Streaming tool runner</td>
  223. <td>Controls tool concurrency, cancellation, and result ordering.</td>
  224. </tr>
  225. <tr>
  226. <td><code>src/screens/REPL.tsx</code></td>
  227. <td>Main interactive UI</td>
  228. <td>Largest single UI file and the center of operator experience.</td>
  229. </tr>
  230. <tr>
  231. <td><code>src/services/mcp/client.ts</code></td>
  232. <td>MCP transport and tool binding</td>
  233. <td>Connects external MCP servers into the tool layer.</td>
  234. </tr>
  235. <tr>
  236. <td><code>src/utils/plugins/pluginLoader.ts</code></td>
  237. <td>Plugin discovery and loading</td>
  238. <td>Owns marketplace, cache, versioning, and local plugin resolution.</td>
  239. </tr>
  240. <tr>
  241. <td><code>src/skills/loadSkillsDir.ts</code></td>
  242. <td>Skill loader</td>
  243. <td>Bridges markdown skill files into executable prompt commands.</td>
  244. </tr>
  245. <tr>
  246. <td><code>src/remote/RemoteSessionManager.ts</code></td>
  247. <td>Remote session controller</td>
  248. <td>Handles cloud session messaging and permission prompts.</td>
  249. </tr>
  250. <tr>
  251. <td><code>src/bridge/bridgeMain.ts</code></td>
  252. <td>Remote-control bridge supervisor</td>
  253. <td>Runs long-lived environment registration and work polling.</td>
  254. </tr>
  255. <tr>
  256. <td><code>src/utils/teleport.tsx</code></td>
  257. <td>Teleport flow</td>
  258. <td>Creates or resumes sessions across machines and repositories.</td>
  259. </tr>
  260. </tbody>
  261. </table>
  262. </section>
  263. <section id="cloud" class="panel">
  264. <h2>Cloud and remote architecture</h2>
  265. <p>
  266. The cloud-facing part of the repo is not a single subsystem. It is a
  267. stack of session transport, bridge control, and state handoff layers.
  268. </p>
  269. <pre class="diagram">Local CLI
  270. |
  271. +-- main.tsx
  272. | |
  273. | +-- REPL / QueryEngine / tools / MCP
  274. |
  275. +-- Remote session path
  276. | |
  277. | +-- remote/RemoteSessionManager.ts
  278. | +-- remote/SessionsWebSocket.ts
  279. | +-- remote/sdkMessageAdapter.ts
  280. |
  281. +-- Direct connect path
  282. | |
  283. | +-- server/directConnectManager.ts
  284. |
  285. +-- Remote-control bridge path
  286. | |
  287. | +-- bridge/bridgeMain.ts
  288. | +-- bridge/createSession.ts
  289. | +-- bridge/replBridge.ts
  290. |
  291. +-- Teleport path
  292. |
  293. +-- utils/teleport.tsx
  294. +-- utils/teleport/api.ts
  295. +-- services/api/sessionIngress.ts</pre>
  296. <div class="summary-grid">
  297. <article>
  298. <h3>Remote session</h3>
  299. <p>
  300. Used when the REPL attaches to a cloud session. Messages come
  301. over WebSocket and are adapted back into local REPL message types.
  302. </p>
  303. </article>
  304. <article>
  305. <h3>Direct connect</h3>
  306. <p>
  307. A simpler WebSocket path that forwards structured SDK messages
  308. and permission requests directly to a remote endpoint.
  309. </p>
  310. </article>
  311. <article>
  312. <h3>Remote control bridge</h3>
  313. <p>
  314. A long-running environment bridge that polls for work, spawns or
  315. resumes sessions, heartbeats them, and keeps web/mobile control alive.
  316. </p>
  317. </article>
  318. <article>
  319. <h3>Teleport</h3>
  320. <p>
  321. A session handoff path that validates git state, creates or
  322. resumes remote sessions, and restores the branch or transcript.
  323. </p>
  324. </article>
  325. <article>
  326. <h3>Managed settings</h3>
  327. <p>
  328. Enterprise settings can be fetched remotely and applied before
  329. other systems initialize, which affects policy, MCP, and auth.
  330. </p>
  331. </article>
  332. <article>
  333. <h3>MCP</h3>
  334. <p>
  335. MCP is the extension spine. The client layer supports stdio,
  336. SSE, streamable HTTP, WebSocket, and SDK in-process transports.
  337. </p>
  338. </article>
  339. </div>
  340. </section>
  341. <section id="state" class="panel">
  342. <h2>Current state</h2>
  343. <div class="summary-grid">
  344. <article>
  345. <h3>What is solid</h3>
  346. <p>
  347. The repo contains real core logic for startup, REPL rendering,
  348. query execution, tool orchestration, MCP integration, plugin
  349. loading, skills, auth, and cloud session flows.
  350. </p>
  351. </article>
  352. <article>
  353. <h3>What is incomplete</h3>
  354. <p>
  355. Several generated or extracted files are missing, some native or
  356. private integrations only have compatibility shims, and the
  357. type surface is out of sync with the installed dependency graph.
  358. </p>
  359. </article>
  360. <article>
  361. <h3>What is intentionally disabled</h3>
  362. <p>
  363. All feature flags are forced off by <code>shims/bun-bundle.ts</code>,
  364. so internal or Anthropic-only paths stay dead unless they are
  365. restored deliberately.
  366. </p>
  367. </article>
  368. <article>
  369. <h3>Release readiness</h3>
  370. <p>
  371. This is now a buildable developer artifact, not a production
  372. release. It is useful for study, customization, and targeted
  373. salvage, but not for shipping unchanged.
  374. </p>
  375. </article>
  376. </div>
  377. <h3>Verification snapshot</h3>
  378. <ul class="checklist">
  379. <li><code>bun install</code> passed.</li>
  380. <li>
  381. <code>bun run build</code> passed after wiring local file-based
  382. stub packages for <code>@ant/claude-for-chrome-mcp</code>,
  383. <code>@ant/computer-use-*</code>, <code>color-diff-napi</code>,
  384. and <code>modifiers-napi</code>.
  385. </li>
  386. <li>
  387. <code>bun run typecheck</code> failed with 4,469 TypeScript
  388. errors.
  389. </li>
  390. <li>
  391. The largest error families were:
  392. <code>TS7006</code> (2,087), <code>TS2307</code> (535),
  393. <code>TS2339</code> (470), and <code>TS2305</code> (410).
  394. </li>
  395. <li>
  396. The most common missing-module failures were
  397. <code>../../types/message.js</code> (81),
  398. <code>../types/message.js</code> (71), <code>./types.js</code> (51),
  399. <code>src/types/message.js</code> (20), and
  400. <code>../../types/tools.js</code> (15).
  401. </li>
  402. </ul>
  403. </section>
  404. <section id="improvements" class="panel">
  405. <h2>20 improvements</h2>
  406. <ol class="improvement-list">
  407. <li>
  408. <strong>P0: Add smoke coverage for the local stub package layer.</strong>
  409. The bundle now resolves the private and native placeholder modules,
  410. but the stubs are hand-maintained and can drift from the import
  411. surface expected by the runtime.
  412. </li>
  413. <li>
  414. <strong>P0: Replace fallback native shims with explicit capability detection.</strong>
  415. <code>color-diff-napi</code> and <code>modifiers-napi</code> now
  416. resolve, but the current placeholders silently degrade behavior.
  417. The runtime should announce unavailable features and select TS
  418. fallbacks intentionally.
  419. </li>
  420. <li>
  421. <strong>P0: Generate and commit <code>src/entrypoints/sdk/controlTypes.ts</code>.</strong>
  422. The code imports <code>./sdk/controlTypes.js</code> from many places,
  423. but only <code>controlSchemas.ts</code> exists. The protocol surface is
  424. incomplete without the generated types.
  425. </li>
  426. <li>
  427. <strong>P0: Restore <code>src/types/message.ts</code>.</strong>
  428. Message types are imported all over the runtime, UI, and cloud
  429. layers. Their absence alone causes a large fraction of the typecheck failures.
  430. </li>
  431. <li>
  432. <strong>P0: Restore <code>src/types/tools.ts</code> and related shared type files.</strong>
  433. Tool progress and transport types are missing, which breaks tool UIs,
  434. structured IO, and process-user-input helpers.
  435. </li>
  436. <li>
  437. <strong>P0: Restore or remove other dangling shared modules.</strong>
  438. Missing files such as <code>src/utils/secureStorage/types.ts</code>,
  439. assistant helpers, and transport helper files should either be recreated
  440. or fully compiled out of the external build.
  441. </li>
  442. <li>
  443. <strong>P0: Finish or fully fence off <code>contextCollapse</code>.</strong>
  444. Only <code>src/services/contextCollapse/index.ts</code> exists, but the
  445. repo still imports <code>operations.js</code> and <code>persist.js</code>.
  446. That makes the feature half-stubbed and half-live.
  447. </li>
  448. <li>
  449. <strong>P1: Decide whether the standalone release metadata should stay and wire it to a real distribution flow.</strong>
  450. The build now defines <code>MACRO.PACKAGE_URL</code>,
  451. <code>MACRO.NATIVE_PACKAGE_URL</code>, and
  452. <code>MACRO.VERSION_CHANGELOG</code>, but they still point to a
  453. placeholder release story instead of a maintained updater pipeline.
  454. </li>
  455. <li>
  456. <strong>P1: Decide whether version enforcement should exist and implement it cleanly.</strong>
  457. <code>src/utils/autoUpdater.ts</code> short-circuits
  458. <code>assertMinVersion()</code> immediately, which makes the rest of the
  459. minimum-version path dead code.
  460. </li>
  461. <li>
  462. <strong>P1: Pin a dependency set that matches the leaked source.</strong>
  463. The current checkout shows type incompatibilities in OpenTelemetry,
  464. MCP, and other libraries. A compatibility matrix or lockfile audit is needed.
  465. </li>
  466. <li>
  467. <strong>P1: Handle <code>react/compiler-runtime</code> intentionally.</strong>
  468. Roughly 395 files import the compiler runtime helper. The repo needs
  469. either the right typings and transform pipeline, or a conversion back
  470. to normal authored TSX.
  471. </li>
  472. <li>
  473. <strong>P1: Split <code>src/main.tsx</code> into domain modules.</strong>
  474. It currently mixes CLI parsing, bootstrapping, remote flows, resume
  475. logic, and command wiring in one huge file, which slows onboarding
  476. and raises change risk.
  477. </li>
  478. <li>
  479. <strong>P1: Split <code>src/screens/REPL.tsx</code> into smaller view-model slices.</strong>
  480. The REPL is the operator surface and currently does too much:
  481. messaging, tasks, permission dialogs, bridge state, IDE hooks, and notifications.
  482. </li>
  483. <li>
  484. <strong>P1: Unify the cloud transport layer.</strong>
  485. <code>RemoteSessionManager</code>, <code>SessionsWebSocket</code>,
  486. <code>DirectConnectSessionManager</code>, and the bridge stack all
  487. solve overlapping connection and message-routing problems differently.
  488. </li>
  489. <li>
  490. <strong>P1: Add reconnect, heartbeat, and backoff to direct connect.</strong>
  491. The direct-connect manager is much thinner than the bridge and CCR
  492. session managers. It should share the same resilience behavior.
  493. </li>
  494. <li>
  495. <strong>P1: Consolidate tool orchestration.</strong>
  496. The repo has both <code>StreamingToolExecutor</code> and
  497. <code>toolOrchestration.ts</code>. The concurrency and cancellation
  498. behavior should come from one path so fixes land once.
  499. </li>
  500. <li>
  501. <strong>P2: Cache heavyweight provider clients.</strong>
  502. <code>src/services/api/client.ts</code> already carries a TODO about
  503. reusing <code>GoogleAuth</code>. The same mindset should apply to other
  504. expensive auth and provider objects.
  505. </li>
  506. <li>
  507. <strong>P2: Add CI gates that reflect reality.</strong>
  508. The repo needs automated install, build, typecheck, and smoke tests.
  509. Right now the current failure set is easy to miss until someone tries a fresh checkout.
  510. </li>
  511. <li>
  512. <strong>P2: Add regression tests for remote-control, teleport, MCP, and permissions.</strong>
  513. Those are the highest-risk paths because they mix auth, filesystem state,
  514. session transport, and tool execution.
  515. </li>
  516. <li>
  517. <strong>P2: Make the public-facing docs and README operational instead of historical.</strong>
  518. The current README is leak-centered. The repo needs a product-facing
  519. explanation of architecture, setup, cloud features, and limitations.
  520. </li>
  521. </ol>
  522. </section>
  523. <section id="hosting" class="panel">
  524. <h2>Hosting this documentation</h2>
  525. <p>
  526. This site is plain static HTML and CSS. You can host it as-is from
  527. the repository <code>/docs</code> directory with GitHub Pages, Netlify,
  528. Cloudflare Pages, S3, or any static web server.
  529. </p>
  530. <ul class="checklist">
  531. <li>GitHub Pages: publish the repository <code>docs/</code> folder.</li>
  532. <li>Local preview: <code>python3 -m http.server 8080 --directory docs</code>.</li>
  533. <li>No build step is required for the documentation site itself.</li>
  534. </ul>
  535. </section>
  536. </main>
  537. </div>
  538. </body>
  539. </html>