@build-astron-co/nimbus 0.4.1 → 0.4.3

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 (435) hide show
  1. package/CHANGELOG.md +268 -89
  2. package/README.md +26 -567
  3. package/dist/src/agent/compaction-agent.js +24 -12
  4. package/dist/src/agent/context-manager.js +2 -1
  5. package/dist/src/agent/expand-files.js +2 -1
  6. package/dist/src/agent/loop.js +71 -33
  7. package/dist/src/agent/permissions.js +4 -2
  8. package/dist/src/agent/system-prompt.js +34 -17
  9. package/dist/src/app.js +1 -1
  10. package/dist/src/auth/keychain.js +8 -4
  11. package/dist/src/auth/store.js +70 -107
  12. package/dist/src/cli/init.js +35 -19
  13. package/dist/src/cli/run.js +18 -10
  14. package/dist/src/cli/serve.js +4 -2
  15. package/dist/src/cli.js +52 -11
  16. package/dist/src/commands/alias.js +5 -3
  17. package/dist/src/commands/audit/index.js +2 -1
  18. package/dist/src/commands/aws-terraform.js +36 -18
  19. package/dist/src/commands/completions.js +1 -1
  20. package/dist/src/commands/config.js +3 -2
  21. package/dist/src/commands/connect-github.js +92 -0
  22. package/dist/src/commands/cost/index.js +3 -2
  23. package/dist/src/commands/deploy.js +15 -10
  24. package/dist/src/commands/doctor.js +9 -6
  25. package/dist/src/commands/drift/index.js +2 -1
  26. package/dist/src/commands/export.js +5 -3
  27. package/dist/src/commands/generate-terraform.js +110 -2
  28. package/dist/src/commands/import.js +3 -3
  29. package/dist/src/commands/incident.js +10 -5
  30. package/dist/src/commands/login.js +8 -93
  31. package/dist/src/commands/logs.js +16 -8
  32. package/dist/src/commands/onboarding.js +6 -4
  33. package/dist/src/commands/pipeline.js +6 -3
  34. package/dist/src/commands/plugin.js +3 -2
  35. package/dist/src/commands/profile.js +27 -14
  36. package/dist/src/commands/questionnaire.js +1 -1
  37. package/dist/src/commands/rollback.js +3 -2
  38. package/dist/src/commands/rollout.js +5 -3
  39. package/dist/src/commands/runbook.js +17 -10
  40. package/dist/src/commands/schedule.js +10 -5
  41. package/dist/src/commands/status.js +2 -1
  42. package/dist/src/commands/team-context.js +12 -7
  43. package/dist/src/commands/template.js +1 -1
  44. package/dist/src/commands/tf/index.js +6 -3
  45. package/dist/src/commands/upgrade.js +5 -3
  46. package/dist/src/commands/version.js +6 -3
  47. package/dist/src/commands/watch.js +6 -3
  48. package/dist/src/compat/sqlite.js +5 -3
  49. package/dist/src/config/mode-store.js +2 -1
  50. package/dist/src/config/profiles.js +4 -2
  51. package/dist/src/config/types.js +2 -1
  52. package/dist/src/engine/executor.js +8 -4
  53. package/dist/src/engine/planner.js +9 -5
  54. package/dist/src/llm/providers/anthropic.js +6 -3
  55. package/dist/src/llm/providers/ollama.js +1 -1
  56. package/dist/src/llm/router.js +22 -7
  57. package/dist/src/nimbus.js +1 -0
  58. package/dist/src/sessions/manager.js +6 -3
  59. package/dist/src/sharing/viewer.js +2 -1
  60. package/dist/src/tools/file-ops.js +1 -2
  61. package/dist/src/tools/schemas/devops.js +197 -108
  62. package/dist/src/tools/schemas/standard.js +1 -1
  63. package/dist/src/ui/App.js +25 -13
  64. package/dist/src/ui/FileDiffModal.js +22 -11
  65. package/dist/src/ui/HelpModal.js +2 -1
  66. package/dist/src/ui/InputBox.js +6 -3
  67. package/dist/src/ui/MessageList.js +40 -20
  68. package/dist/src/ui/TerminalPane.js +2 -1
  69. package/dist/src/ui/ToolCallDisplay.js +12 -6
  70. package/dist/src/ui/TreePane.js +2 -1
  71. package/dist/src/ui/ink/index.js +37 -21
  72. package/dist/src/version.js +1 -1
  73. package/dist/src/watcher/index.js +8 -4
  74. package/package.json +3 -5
  75. package/src/__tests__/alias.test.ts +0 -133
  76. package/src/__tests__/app.test.ts +0 -76
  77. package/src/__tests__/audit.test.ts +0 -877
  78. package/src/__tests__/circuit-breaker.test.ts +0 -116
  79. package/src/__tests__/cli-run.test.ts +0 -351
  80. package/src/__tests__/compat-sqlite.test.ts +0 -68
  81. package/src/__tests__/context-manager.test.ts +0 -632
  82. package/src/__tests__/context.test.ts +0 -242
  83. package/src/__tests__/devops-terminal-gaps.test.ts +0 -718
  84. package/src/__tests__/doctor.test.ts +0 -48
  85. package/src/__tests__/enterprise.test.ts +0 -401
  86. package/src/__tests__/export.test.ts +0 -236
  87. package/src/__tests__/gap-11-18-20.test.ts +0 -958
  88. package/src/__tests__/generator.test.ts +0 -433
  89. package/src/__tests__/helm-streaming.test.ts +0 -127
  90. package/src/__tests__/hooks.test.ts +0 -582
  91. package/src/__tests__/incident.test.ts +0 -179
  92. package/src/__tests__/init.test.ts +0 -487
  93. package/src/__tests__/intent-parser.test.ts +0 -229
  94. package/src/__tests__/llm-router.test.ts +0 -209
  95. package/src/__tests__/logs.test.ts +0 -107
  96. package/src/__tests__/loop-errors.test.ts +0 -244
  97. package/src/__tests__/lsp.test.ts +0 -293
  98. package/src/__tests__/modes.test.ts +0 -336
  99. package/src/__tests__/perf-optimizations.test.ts +0 -847
  100. package/src/__tests__/permissions.test.ts +0 -338
  101. package/src/__tests__/pipeline.test.ts +0 -50
  102. package/src/__tests__/polish-phase3.test.ts +0 -340
  103. package/src/__tests__/profile.test.ts +0 -237
  104. package/src/__tests__/rollback.test.ts +0 -83
  105. package/src/__tests__/runbook.test.ts +0 -219
  106. package/src/__tests__/schedule.test.ts +0 -206
  107. package/src/__tests__/serve.test.ts +0 -275
  108. package/src/__tests__/sessions.test.ts +0 -322
  109. package/src/__tests__/sharing.test.ts +0 -340
  110. package/src/__tests__/snapshots.test.ts +0 -581
  111. package/src/__tests__/standalone-migration.test.ts +0 -199
  112. package/src/__tests__/state-db.test.ts +0 -334
  113. package/src/__tests__/status.test.ts +0 -158
  114. package/src/__tests__/stream-with-tools.test.ts +0 -778
  115. package/src/__tests__/subagents.test.ts +0 -176
  116. package/src/__tests__/system-prompt.test.ts +0 -248
  117. package/src/__tests__/terminal-gap-v2.test.ts +0 -395
  118. package/src/__tests__/terminal-parity.test.ts +0 -393
  119. package/src/__tests__/tf-apply.test.ts +0 -187
  120. package/src/__tests__/tool-converter.test.ts +0 -256
  121. package/src/__tests__/tool-schemas.test.ts +0 -602
  122. package/src/__tests__/tools.test.ts +0 -144
  123. package/src/__tests__/version-json.test.ts +0 -184
  124. package/src/__tests__/version.test.ts +0 -49
  125. package/src/__tests__/watch.test.ts +0 -129
  126. package/src/agent/compaction-agent.ts +0 -266
  127. package/src/agent/context-manager.ts +0 -499
  128. package/src/agent/context.ts +0 -427
  129. package/src/agent/deploy-preview.ts +0 -487
  130. package/src/agent/expand-files.ts +0 -108
  131. package/src/agent/index.ts +0 -68
  132. package/src/agent/loop.ts +0 -1998
  133. package/src/agent/modes.ts +0 -429
  134. package/src/agent/permissions.ts +0 -513
  135. package/src/agent/subagents/base.ts +0 -116
  136. package/src/agent/subagents/cost.ts +0 -51
  137. package/src/agent/subagents/explore.ts +0 -42
  138. package/src/agent/subagents/general.ts +0 -54
  139. package/src/agent/subagents/index.ts +0 -102
  140. package/src/agent/subagents/infra.ts +0 -59
  141. package/src/agent/subagents/security.ts +0 -69
  142. package/src/agent/system-prompt.ts +0 -990
  143. package/src/app.ts +0 -180
  144. package/src/audit/activity-log.ts +0 -290
  145. package/src/audit/compliance-checker.ts +0 -540
  146. package/src/audit/cost-tracker.ts +0 -318
  147. package/src/audit/index.ts +0 -23
  148. package/src/audit/security-scanner.ts +0 -641
  149. package/src/auth/guard.ts +0 -75
  150. package/src/auth/index.ts +0 -56
  151. package/src/auth/keychain.ts +0 -82
  152. package/src/auth/oauth.ts +0 -465
  153. package/src/auth/providers.ts +0 -470
  154. package/src/auth/sso.ts +0 -113
  155. package/src/auth/store.ts +0 -505
  156. package/src/auth/types.ts +0 -187
  157. package/src/build.ts +0 -141
  158. package/src/cli/index.ts +0 -16
  159. package/src/cli/init.ts +0 -1227
  160. package/src/cli/openapi-spec.ts +0 -356
  161. package/src/cli/run.ts +0 -628
  162. package/src/cli/serve-auth.ts +0 -80
  163. package/src/cli/serve.ts +0 -539
  164. package/src/cli/web.ts +0 -71
  165. package/src/cli.ts +0 -1728
  166. package/src/clients/core-engine-client.ts +0 -227
  167. package/src/clients/enterprise-client.ts +0 -334
  168. package/src/clients/generator-client.ts +0 -351
  169. package/src/clients/git-client.ts +0 -627
  170. package/src/clients/github-client.ts +0 -410
  171. package/src/clients/helm-client.ts +0 -504
  172. package/src/clients/index.ts +0 -80
  173. package/src/clients/k8s-client.ts +0 -497
  174. package/src/clients/llm-client.ts +0 -161
  175. package/src/clients/rest-client.ts +0 -130
  176. package/src/clients/service-discovery.ts +0 -38
  177. package/src/clients/terraform-client.ts +0 -482
  178. package/src/clients/tools-client.ts +0 -1843
  179. package/src/clients/ws-client.ts +0 -115
  180. package/src/commands/alias.ts +0 -100
  181. package/src/commands/analyze/index.ts +0 -352
  182. package/src/commands/apply/helm.ts +0 -473
  183. package/src/commands/apply/index.ts +0 -213
  184. package/src/commands/apply/k8s.ts +0 -454
  185. package/src/commands/apply/terraform.ts +0 -582
  186. package/src/commands/ask.ts +0 -167
  187. package/src/commands/audit/index.ts +0 -357
  188. package/src/commands/auth-cloud.ts +0 -407
  189. package/src/commands/auth-list.ts +0 -134
  190. package/src/commands/auth-profile.ts +0 -121
  191. package/src/commands/auth-refresh.ts +0 -187
  192. package/src/commands/auth-status.ts +0 -141
  193. package/src/commands/aws/ec2.ts +0 -501
  194. package/src/commands/aws/iam.ts +0 -397
  195. package/src/commands/aws/index.ts +0 -133
  196. package/src/commands/aws/lambda.ts +0 -396
  197. package/src/commands/aws/rds.ts +0 -439
  198. package/src/commands/aws/s3.ts +0 -439
  199. package/src/commands/aws/vpc.ts +0 -393
  200. package/src/commands/aws-discover.ts +0 -542
  201. package/src/commands/aws-terraform.ts +0 -755
  202. package/src/commands/azure/aks.ts +0 -376
  203. package/src/commands/azure/functions.ts +0 -253
  204. package/src/commands/azure/index.ts +0 -116
  205. package/src/commands/azure/storage.ts +0 -478
  206. package/src/commands/azure/vm.ts +0 -355
  207. package/src/commands/billing/index.ts +0 -256
  208. package/src/commands/chat.ts +0 -320
  209. package/src/commands/completions.ts +0 -268
  210. package/src/commands/config.ts +0 -372
  211. package/src/commands/cost/cloud-cost-estimator.ts +0 -266
  212. package/src/commands/cost/estimator.ts +0 -79
  213. package/src/commands/cost/index.ts +0 -810
  214. package/src/commands/cost/parsers/terraform.ts +0 -273
  215. package/src/commands/cost/parsers/types.ts +0 -25
  216. package/src/commands/cost/pricing/aws.ts +0 -544
  217. package/src/commands/cost/pricing/azure.ts +0 -499
  218. package/src/commands/cost/pricing/gcp.ts +0 -396
  219. package/src/commands/cost/pricing/index.ts +0 -40
  220. package/src/commands/demo.ts +0 -250
  221. package/src/commands/deploy.ts +0 -260
  222. package/src/commands/doctor.ts +0 -1386
  223. package/src/commands/drift/index.ts +0 -787
  224. package/src/commands/explain.ts +0 -277
  225. package/src/commands/export.ts +0 -146
  226. package/src/commands/feedback.ts +0 -389
  227. package/src/commands/fix.ts +0 -324
  228. package/src/commands/fs/index.ts +0 -402
  229. package/src/commands/gcp/compute.ts +0 -325
  230. package/src/commands/gcp/functions.ts +0 -271
  231. package/src/commands/gcp/gke.ts +0 -438
  232. package/src/commands/gcp/iam.ts +0 -344
  233. package/src/commands/gcp/index.ts +0 -129
  234. package/src/commands/gcp/storage.ts +0 -284
  235. package/src/commands/generate-helm.ts +0 -1249
  236. package/src/commands/generate-k8s.ts +0 -1508
  237. package/src/commands/generate-terraform.ts +0 -1202
  238. package/src/commands/gh/index.ts +0 -863
  239. package/src/commands/git/index.ts +0 -1343
  240. package/src/commands/helm/index.ts +0 -1126
  241. package/src/commands/help.ts +0 -715
  242. package/src/commands/history.ts +0 -149
  243. package/src/commands/import.ts +0 -868
  244. package/src/commands/incident.ts +0 -166
  245. package/src/commands/index.ts +0 -367
  246. package/src/commands/init.ts +0 -1051
  247. package/src/commands/k8s/index.ts +0 -1137
  248. package/src/commands/login.ts +0 -716
  249. package/src/commands/logout.ts +0 -83
  250. package/src/commands/logs.ts +0 -167
  251. package/src/commands/onboarding.ts +0 -405
  252. package/src/commands/pipeline.ts +0 -186
  253. package/src/commands/plan/display.ts +0 -279
  254. package/src/commands/plan/index.ts +0 -599
  255. package/src/commands/plugin.ts +0 -398
  256. package/src/commands/preview.ts +0 -452
  257. package/src/commands/profile.ts +0 -342
  258. package/src/commands/questionnaire.ts +0 -1172
  259. package/src/commands/resume.ts +0 -47
  260. package/src/commands/rollback.ts +0 -315
  261. package/src/commands/rollout.ts +0 -88
  262. package/src/commands/runbook.ts +0 -346
  263. package/src/commands/schedule.ts +0 -236
  264. package/src/commands/status.ts +0 -252
  265. package/src/commands/team/index.ts +0 -346
  266. package/src/commands/team-context.ts +0 -220
  267. package/src/commands/template.ts +0 -233
  268. package/src/commands/tf/index.ts +0 -1093
  269. package/src/commands/upgrade.ts +0 -607
  270. package/src/commands/usage/index.ts +0 -134
  271. package/src/commands/version.ts +0 -174
  272. package/src/commands/watch.ts +0 -153
  273. package/src/compat/index.ts +0 -2
  274. package/src/compat/runtime.ts +0 -12
  275. package/src/compat/sqlite.ts +0 -177
  276. package/src/config/index.ts +0 -17
  277. package/src/config/manager.ts +0 -530
  278. package/src/config/mode-store.ts +0 -62
  279. package/src/config/profiles.ts +0 -84
  280. package/src/config/safety-policy.ts +0 -358
  281. package/src/config/schema.ts +0 -125
  282. package/src/config/types.ts +0 -609
  283. package/src/config/workspace-state.ts +0 -53
  284. package/src/context/context-db.ts +0 -199
  285. package/src/demo/index.ts +0 -349
  286. package/src/demo/scenarios/full-journey.ts +0 -229
  287. package/src/demo/scenarios/getting-started.ts +0 -127
  288. package/src/demo/scenarios/helm-release.ts +0 -341
  289. package/src/demo/scenarios/k8s-deployment.ts +0 -194
  290. package/src/demo/scenarios/terraform-vpc.ts +0 -170
  291. package/src/demo/types.ts +0 -92
  292. package/src/engine/cost-estimator.ts +0 -480
  293. package/src/engine/diagram-generator.ts +0 -256
  294. package/src/engine/drift-detector.ts +0 -902
  295. package/src/engine/executor.ts +0 -1066
  296. package/src/engine/index.ts +0 -76
  297. package/src/engine/orchestrator.ts +0 -636
  298. package/src/engine/planner.ts +0 -787
  299. package/src/engine/safety.ts +0 -743
  300. package/src/engine/verifier.ts +0 -770
  301. package/src/enterprise/audit.ts +0 -348
  302. package/src/enterprise/auth.ts +0 -270
  303. package/src/enterprise/billing.ts +0 -822
  304. package/src/enterprise/index.ts +0 -17
  305. package/src/enterprise/teams.ts +0 -443
  306. package/src/generator/best-practices.ts +0 -1608
  307. package/src/generator/helm.ts +0 -630
  308. package/src/generator/index.ts +0 -37
  309. package/src/generator/intent-parser.ts +0 -514
  310. package/src/generator/kubernetes.ts +0 -976
  311. package/src/generator/terraform.ts +0 -1875
  312. package/src/history/index.ts +0 -8
  313. package/src/history/manager.ts +0 -250
  314. package/src/history/types.ts +0 -34
  315. package/src/hooks/config.ts +0 -432
  316. package/src/hooks/engine.ts +0 -392
  317. package/src/hooks/index.ts +0 -4
  318. package/src/llm/auth-bridge.ts +0 -198
  319. package/src/llm/circuit-breaker.ts +0 -140
  320. package/src/llm/config-loader.ts +0 -201
  321. package/src/llm/cost-calculator.ts +0 -171
  322. package/src/llm/index.ts +0 -8
  323. package/src/llm/model-aliases.ts +0 -115
  324. package/src/llm/provider-registry.ts +0 -63
  325. package/src/llm/providers/anthropic.ts +0 -462
  326. package/src/llm/providers/bedrock.ts +0 -477
  327. package/src/llm/providers/google.ts +0 -405
  328. package/src/llm/providers/ollama.ts +0 -767
  329. package/src/llm/providers/openai-compatible.ts +0 -340
  330. package/src/llm/providers/openai.ts +0 -328
  331. package/src/llm/providers/openrouter.ts +0 -338
  332. package/src/llm/router.ts +0 -1104
  333. package/src/llm/types.ts +0 -232
  334. package/src/lsp/client.ts +0 -298
  335. package/src/lsp/languages.ts +0 -119
  336. package/src/lsp/manager.ts +0 -294
  337. package/src/mcp/client.ts +0 -402
  338. package/src/mcp/index.ts +0 -5
  339. package/src/mcp/manager.ts +0 -133
  340. package/src/nimbus.ts +0 -233
  341. package/src/plugins/index.ts +0 -27
  342. package/src/plugins/loader.ts +0 -334
  343. package/src/plugins/manager.ts +0 -376
  344. package/src/plugins/types.ts +0 -284
  345. package/src/scanners/cicd-scanner.ts +0 -258
  346. package/src/scanners/cloud-scanner.ts +0 -466
  347. package/src/scanners/framework-scanner.ts +0 -469
  348. package/src/scanners/iac-scanner.ts +0 -388
  349. package/src/scanners/index.ts +0 -539
  350. package/src/scanners/language-scanner.ts +0 -276
  351. package/src/scanners/package-manager-scanner.ts +0 -277
  352. package/src/scanners/types.ts +0 -172
  353. package/src/sessions/manager.ts +0 -472
  354. package/src/sessions/types.ts +0 -44
  355. package/src/sharing/sync.ts +0 -300
  356. package/src/sharing/viewer.ts +0 -163
  357. package/src/snapshots/index.ts +0 -2
  358. package/src/snapshots/manager.ts +0 -530
  359. package/src/state/artifacts.ts +0 -147
  360. package/src/state/audit.ts +0 -137
  361. package/src/state/billing.ts +0 -240
  362. package/src/state/checkpoints.ts +0 -117
  363. package/src/state/config.ts +0 -67
  364. package/src/state/conversations.ts +0 -14
  365. package/src/state/credentials.ts +0 -154
  366. package/src/state/db.ts +0 -58
  367. package/src/state/index.ts +0 -26
  368. package/src/state/messages.ts +0 -115
  369. package/src/state/projects.ts +0 -123
  370. package/src/state/schema.ts +0 -236
  371. package/src/state/sessions.ts +0 -147
  372. package/src/state/teams.ts +0 -200
  373. package/src/telemetry.ts +0 -108
  374. package/src/tools/aws-ops.ts +0 -952
  375. package/src/tools/azure-ops.ts +0 -579
  376. package/src/tools/file-ops.ts +0 -615
  377. package/src/tools/gcp-ops.ts +0 -625
  378. package/src/tools/git-ops.ts +0 -773
  379. package/src/tools/github-ops.ts +0 -799
  380. package/src/tools/helm-ops.ts +0 -943
  381. package/src/tools/index.ts +0 -17
  382. package/src/tools/k8s-ops.ts +0 -819
  383. package/src/tools/schemas/converter.ts +0 -184
  384. package/src/tools/schemas/devops.ts +0 -3502
  385. package/src/tools/schemas/index.ts +0 -73
  386. package/src/tools/schemas/standard.ts +0 -1148
  387. package/src/tools/schemas/types.ts +0 -735
  388. package/src/tools/spawn-exec.ts +0 -148
  389. package/src/tools/terraform-ops.ts +0 -862
  390. package/src/types/ambient.d.ts +0 -193
  391. package/src/types/config.ts +0 -83
  392. package/src/types/drift.ts +0 -116
  393. package/src/types/enterprise.ts +0 -335
  394. package/src/types/index.ts +0 -20
  395. package/src/types/plan.ts +0 -44
  396. package/src/types/request.ts +0 -65
  397. package/src/types/response.ts +0 -54
  398. package/src/types/service.ts +0 -51
  399. package/src/ui/App.tsx +0 -2114
  400. package/src/ui/DeployPreview.tsx +0 -174
  401. package/src/ui/FileDiffModal.tsx +0 -162
  402. package/src/ui/Header.tsx +0 -131
  403. package/src/ui/HelpModal.tsx +0 -57
  404. package/src/ui/InputBox.tsx +0 -503
  405. package/src/ui/MessageList.tsx +0 -1032
  406. package/src/ui/PermissionPrompt.tsx +0 -163
  407. package/src/ui/StatusBar.tsx +0 -277
  408. package/src/ui/TerminalPane.tsx +0 -84
  409. package/src/ui/ToolCallDisplay.tsx +0 -643
  410. package/src/ui/TreePane.tsx +0 -132
  411. package/src/ui/chat-ui.ts +0 -850
  412. package/src/ui/index.ts +0 -33
  413. package/src/ui/ink/index.ts +0 -1444
  414. package/src/ui/streaming.ts +0 -176
  415. package/src/ui/theme.ts +0 -104
  416. package/src/ui/types.ts +0 -75
  417. package/src/utils/analytics.ts +0 -72
  418. package/src/utils/cost-warning.ts +0 -27
  419. package/src/utils/env.ts +0 -46
  420. package/src/utils/errors.ts +0 -69
  421. package/src/utils/event-bus.ts +0 -38
  422. package/src/utils/index.ts +0 -24
  423. package/src/utils/logger.ts +0 -171
  424. package/src/utils/rate-limiter.ts +0 -121
  425. package/src/utils/service-auth.ts +0 -49
  426. package/src/utils/validation.ts +0 -53
  427. package/src/version.ts +0 -4
  428. package/src/watcher/index.ts +0 -214
  429. package/src/wizard/approval.ts +0 -383
  430. package/src/wizard/index.ts +0 -25
  431. package/src/wizard/prompts.ts +0 -338
  432. package/src/wizard/types.ts +0 -172
  433. package/src/wizard/ui.ts +0 -556
  434. package/src/wizard/wizard.ts +0 -304
  435. package/tsconfig.json +0 -24
@@ -1,1032 +0,0 @@
1
- /**
2
- * MessageList Component
3
- *
4
- * Renders the scrollable conversation history. User messages get a cyan "You:"
5
- * prefix, assistant messages show "Agent ({mode}):" in green, and system
6
- * messages are rendered in dim italic text. Code blocks are wrapped in a
7
- * bordered Box with syntax highlighting.
8
- */
9
-
10
- import React, { useMemo } from 'react';
11
- import { Box, Text } from 'ink';
12
- import type { UIMessage, AgentMode } from './types';
13
-
14
- /** Props accepted by the MessageList component. */
15
- export interface MessageListProps {
16
- messages: UIMessage[];
17
- mode: AgentMode;
18
- /** Maximum number of messages to display. Defaults to dynamic based on terminal rows. */
19
- maxVisible?: number;
20
- /** Number of messages to scroll back from the bottom (C1). */
21
- scrollOffset?: number;
22
- /** Filter messages to those containing this substring (M1). */
23
- searchQuery?: string;
24
- /** C1: Terminal column width for separator sizing. */
25
- columns?: number;
26
- }
27
-
28
- /**
29
- * Split message content into text segments and fenced code blocks so each
30
- * can be rendered with appropriate styling.
31
- */
32
- interface ContentSegment {
33
- type: 'text' | 'code';
34
- content: string;
35
- language?: string;
36
- }
37
-
38
- /** Public re-export for pre-computation in consumers (PERF-4b). */
39
- export type ContentSegmentPublic = ContentSegment;
40
-
41
- /** Raw (uncached) parse implementation. */
42
- function _parseContentRaw(raw: string): ContentSegment[] {
43
- const segments: ContentSegment[] = [];
44
- const codeBlockRegex = /```(\w+)?\n([\s\S]*?)```/g;
45
- let lastIndex = 0;
46
- let match: RegExpExecArray | null;
47
-
48
- while ((match = codeBlockRegex.exec(raw)) !== null) {
49
- // Text before the code block
50
- if (match.index > lastIndex) {
51
- segments.push({ type: 'text', content: raw.slice(lastIndex, match.index) });
52
- }
53
- segments.push({
54
- type: 'code',
55
- content: match[2].trimEnd(),
56
- language: match[1],
57
- });
58
- lastIndex = match.index + match[0].length;
59
- }
60
-
61
- // Trailing text after the last code block (or entire string if no blocks)
62
- if (lastIndex < raw.length) {
63
- segments.push({ type: 'text', content: raw.slice(lastIndex) });
64
- }
65
-
66
- return segments;
67
- }
68
-
69
- /**
70
- * Module-level LRU-ish cache for parsed content segments.
71
- * Hard cap at 200 entries with FIFO eviction to bound memory usage during streaming.
72
- * Exported for testing.
73
- */
74
- export const _parseContentCache: Map<string, ContentSegment[]> = new Map();
75
- const _PARSE_CACHE_MAX = 200;
76
-
77
- function parseContent(raw: string): ContentSegment[] {
78
- const cached = _parseContentCache.get(raw);
79
- if (cached !== undefined) return cached;
80
-
81
- const result = _parseContentRaw(raw);
82
-
83
- if (_parseContentCache.size >= _PARSE_CACHE_MAX) {
84
- // FIFO eviction: delete the oldest entry
85
- const firstKey = _parseContentCache.keys().next().value;
86
- if (firstKey !== undefined) _parseContentCache.delete(firstKey);
87
- }
88
- _parseContentCache.set(raw, result);
89
- return result;
90
- }
91
-
92
- /** Exported for testing only. */
93
- export function _parseContentForTesting(raw: string): ContentSegment[] {
94
- return parseContent(raw);
95
- }
96
-
97
- /* ---------------------------------------------------------------------------
98
- * Syntax highlighting
99
- * -------------------------------------------------------------------------*/
100
-
101
- type TokenType = 'keyword' | 'string' | 'comment' | 'number' | 'type' | 'plain';
102
-
103
- interface Token {
104
- type: TokenType;
105
- text: string;
106
- }
107
-
108
- const TOKEN_COLORS: Record<TokenType, string | undefined> = {
109
- keyword: 'magenta',
110
- string: 'green',
111
- comment: 'gray',
112
- number: 'yellow',
113
- type: 'cyan',
114
- plain: undefined,
115
- };
116
-
117
- const JS_TS_KEYWORDS = new Set([
118
- 'async',
119
- 'await',
120
- 'break',
121
- 'case',
122
- 'catch',
123
- 'class',
124
- 'const',
125
- 'continue',
126
- 'debugger',
127
- 'default',
128
- 'delete',
129
- 'do',
130
- 'else',
131
- 'enum',
132
- 'export',
133
- 'extends',
134
- 'finally',
135
- 'for',
136
- 'from',
137
- 'function',
138
- 'if',
139
- 'import',
140
- 'in',
141
- 'instanceof',
142
- 'interface',
143
- 'let',
144
- 'new',
145
- 'of',
146
- 'return',
147
- 'static',
148
- 'super',
149
- 'switch',
150
- 'this',
151
- 'throw',
152
- 'try',
153
- 'type',
154
- 'typeof',
155
- 'var',
156
- 'void',
157
- 'while',
158
- 'with',
159
- 'yield',
160
- 'true',
161
- 'false',
162
- 'null',
163
- 'undefined',
164
- ]);
165
-
166
- const PYTHON_KEYWORDS = new Set([
167
- 'and',
168
- 'as',
169
- 'assert',
170
- 'async',
171
- 'await',
172
- 'break',
173
- 'class',
174
- 'continue',
175
- 'def',
176
- 'del',
177
- 'elif',
178
- 'else',
179
- 'except',
180
- 'False',
181
- 'finally',
182
- 'for',
183
- 'from',
184
- 'global',
185
- 'if',
186
- 'import',
187
- 'in',
188
- 'is',
189
- 'lambda',
190
- 'None',
191
- 'nonlocal',
192
- 'not',
193
- 'or',
194
- 'pass',
195
- 'raise',
196
- 'return',
197
- 'True',
198
- 'try',
199
- 'while',
200
- 'with',
201
- 'yield',
202
- ]);
203
-
204
- const GO_KEYWORDS = new Set([
205
- 'break',
206
- 'case',
207
- 'chan',
208
- 'const',
209
- 'continue',
210
- 'default',
211
- 'defer',
212
- 'else',
213
- 'fallthrough',
214
- 'for',
215
- 'func',
216
- 'go',
217
- 'goto',
218
- 'if',
219
- 'import',
220
- 'interface',
221
- 'map',
222
- 'package',
223
- 'range',
224
- 'return',
225
- 'select',
226
- 'struct',
227
- 'switch',
228
- 'type',
229
- 'var',
230
- 'true',
231
- 'false',
232
- 'nil',
233
- ]);
234
-
235
- const HCL_KEYWORDS = new Set([
236
- 'resource',
237
- 'data',
238
- 'variable',
239
- 'output',
240
- 'module',
241
- 'provider',
242
- 'terraform',
243
- 'locals',
244
- 'for_each',
245
- 'count',
246
- 'depends_on',
247
- 'lifecycle',
248
- 'dynamic',
249
- 'true',
250
- 'false',
251
- 'null',
252
- ]);
253
-
254
- const JS_TS_TYPES = new Set([
255
- 'string',
256
- 'number',
257
- 'boolean',
258
- 'object',
259
- 'any',
260
- 'void',
261
- 'never',
262
- 'unknown',
263
- 'Array',
264
- 'Promise',
265
- 'Record',
266
- 'Partial',
267
- 'Required',
268
- 'Map',
269
- 'Set',
270
- 'Error',
271
- 'Date',
272
- 'RegExp',
273
- 'Buffer',
274
- ]);
275
-
276
- const BASH_KEYWORDS = new Set([
277
- 'if', 'then', 'else', 'elif', 'fi', 'for', 'while', 'do', 'done',
278
- 'case', 'esac', 'in', 'function', 'return', 'exit', 'echo', 'export',
279
- 'source', 'local', 'readonly', 'declare', 'unset', 'shift', 'break',
280
- 'continue', 'trap', 'set', 'unset', 'true', 'false',
281
- ]);
282
-
283
- const DOCKERFILE_INSTRUCTIONS = new Set([
284
- 'FROM', 'RUN', 'COPY', 'ADD', 'ENV', 'ARG', 'EXPOSE', 'CMD',
285
- 'ENTRYPOINT', 'WORKDIR', 'LABEL', 'USER', 'VOLUME', 'ONBUILD',
286
- 'HEALTHCHECK', 'STOPSIGNAL', 'SHELL',
287
- ]);
288
-
289
- const SQL_KEYWORDS = new Set([
290
- 'SELECT', 'FROM', 'WHERE', 'JOIN', 'LEFT', 'RIGHT', 'INNER', 'OUTER',
291
- 'ON', 'AND', 'OR', 'NOT', 'IN', 'IS', 'NULL', 'AS', 'DISTINCT',
292
- 'ORDER', 'BY', 'GROUP', 'HAVING', 'LIMIT', 'OFFSET',
293
- 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'SET', 'DELETE',
294
- 'CREATE', 'DROP', 'ALTER', 'TABLE', 'INDEX', 'VIEW', 'DATABASE',
295
- 'PRIMARY', 'KEY', 'FOREIGN', 'REFERENCES', 'UNIQUE', 'DEFAULT',
296
- 'CONSTRAINT', 'CASCADE', 'BEGIN', 'COMMIT', 'ROLLBACK', 'TRANSACTION',
297
- 'select', 'from', 'where', 'join', 'left', 'right', 'inner', 'outer',
298
- 'on', 'and', 'or', 'not', 'in', 'is', 'null', 'as', 'distinct',
299
- 'order', 'by', 'group', 'having', 'limit', 'offset',
300
- 'insert', 'into', 'values', 'update', 'set', 'delete',
301
- 'create', 'drop', 'alter', 'table', 'index', 'view', 'database',
302
- ]);
303
-
304
- function getKeywords(language?: string): Set<string> {
305
- if (!language) {
306
- return JS_TS_KEYWORDS;
307
- }
308
- const lang = language.toLowerCase();
309
- if (lang === 'python' || lang === 'py') {
310
- return PYTHON_KEYWORDS;
311
- }
312
- if (lang === 'go' || lang === 'golang') {
313
- return GO_KEYWORDS;
314
- }
315
- if (lang === 'hcl' || lang === 'terraform' || lang === 'tf') {
316
- return HCL_KEYWORDS;
317
- }
318
- if (lang === 'bash' || lang === 'sh' || lang === 'shell' || lang === 'zsh') {
319
- return BASH_KEYWORDS;
320
- }
321
- if (lang === 'sql') {
322
- return SQL_KEYWORDS;
323
- }
324
- // yaml, json, dockerfile use custom tokenizers — return empty set
325
- if (lang === 'yaml' || lang === 'yml' || lang === 'json' || lang === 'dockerfile' || lang === 'docker') {
326
- return new Set();
327
- }
328
- return JS_TS_KEYWORDS;
329
- }
330
-
331
- function getTypes(language?: string): Set<string> {
332
- if (!language) {
333
- return JS_TS_TYPES;
334
- }
335
- const lang = language.toLowerCase();
336
- if (
337
- lang === 'typescript' ||
338
- lang === 'ts' ||
339
- lang === 'javascript' ||
340
- lang === 'js' ||
341
- lang === 'tsx' ||
342
- lang === 'jsx'
343
- ) {
344
- return JS_TS_TYPES;
345
- }
346
- return new Set();
347
- }
348
-
349
- /** Tokenize a YAML line. Keys are cyan, values green, anchors magenta, --- gray. */
350
- function tokenizeYamlLine(line: string): Token[] {
351
- const tokens: Token[] = [];
352
- const trimmed = line.trim();
353
-
354
- // Document separator
355
- if (trimmed === '---' || trimmed === '...') {
356
- return [{ type: 'comment', text: line }];
357
- }
358
- // Comments
359
- if (trimmed.startsWith('#')) {
360
- return [{ type: 'comment', text: line }];
361
- }
362
- // Anchors and aliases
363
- if (trimmed.startsWith('&') || trimmed.startsWith('*')) {
364
- return [{ type: 'type', text: line }];
365
- }
366
- // Key: value pattern
367
- const keyMatch = line.match(/^(\s*)([\w\-./]+)(\s*:\s*)(.*)/);
368
- if (keyMatch) {
369
- const [, indent, key, colon, value] = keyMatch;
370
- if (indent) tokens.push({ type: 'plain', text: indent });
371
- tokens.push({ type: 'type', text: key });
372
- tokens.push({ type: 'plain', text: colon });
373
- if (value) {
374
- if (value.startsWith('"') || value.startsWith("'")) {
375
- tokens.push({ type: 'string', text: value });
376
- } else if (/^\d/.test(value) || value === 'true' || value === 'false' || value === 'null') {
377
- tokens.push({ type: 'number', text: value });
378
- } else {
379
- tokens.push({ type: 'plain', text: value });
380
- }
381
- }
382
- return tokens;
383
- }
384
- // List items
385
- if (trimmed.startsWith('-')) {
386
- const dashIdx = line.indexOf('-');
387
- tokens.push({ type: 'plain', text: line.slice(0, dashIdx + 1) });
388
- const rest = line.slice(dashIdx + 1);
389
- if (rest.trim()) tokens.push({ type: 'string', text: rest });
390
- return tokens;
391
- }
392
- return [{ type: 'plain', text: line }];
393
- }
394
-
395
- /** Tokenize a JSON line. Keys cyan, string values green, numbers/booleans yellow/magenta. */
396
- function tokenizeJsonLine(line: string): Token[] {
397
- const tokens: Token[] = [];
398
- let i = 0;
399
- while (i < line.length) {
400
- // String — could be key or value
401
- if (line[i] === '"') {
402
- let j = i + 1;
403
- while (j < line.length && line[j] !== '"') {
404
- if (line[j] === '\\') j++;
405
- j++;
406
- }
407
- j = Math.min(j + 1, line.length);
408
- const str = line.slice(i, j);
409
- // Check if it's a key (followed by optional space and colon)
410
- const afterStr = line.slice(j).trimStart();
411
- if (afterStr.startsWith(':')) {
412
- tokens.push({ type: 'type', text: str });
413
- } else {
414
- tokens.push({ type: 'string', text: str });
415
- }
416
- i = j;
417
- continue;
418
- }
419
- // Numbers
420
- if (/[0-9\-]/.test(line[i]) && (i === 0 || /[\s,\[{:]/.test(line[i - 1]))) {
421
- let j = i;
422
- while (j < line.length && /[0-9.\-eE+]/.test(line[j])) j++;
423
- tokens.push({ type: 'number', text: line.slice(i, j) });
424
- i = j;
425
- continue;
426
- }
427
- // Keywords: true, false, null
428
- if (/[a-z]/.test(line[i])) {
429
- let j = i;
430
- while (j < line.length && /[a-z]/.test(line[j])) j++;
431
- const word = line.slice(i, j);
432
- if (word === 'true' || word === 'false' || word === 'null') {
433
- tokens.push({ type: 'type', text: word });
434
- } else {
435
- tokens.push({ type: 'plain', text: word });
436
- }
437
- i = j;
438
- continue;
439
- }
440
- tokens.push({ type: 'plain', text: line[i] });
441
- i++;
442
- }
443
- return tokens;
444
- }
445
-
446
- /** Tokenize a Dockerfile line. Instructions are magenta. */
447
- function tokenizeDockerfileLine(line: string): Token[] {
448
- const trimmed = line.trim();
449
- if (trimmed.startsWith('#')) {
450
- return [{ type: 'comment', text: line }];
451
- }
452
- const instrMatch = trimmed.match(/^([A-Z]+)(\s+.*)?$/);
453
- if (instrMatch && DOCKERFILE_INSTRUCTIONS.has(instrMatch[1])) {
454
- const tokens: Token[] = [];
455
- const leadingSpaces = line.length - line.trimStart().length;
456
- if (leadingSpaces > 0) tokens.push({ type: 'plain', text: line.slice(0, leadingSpaces) });
457
- tokens.push({ type: 'keyword', text: instrMatch[1] });
458
- if (instrMatch[2]) tokens.push({ type: 'plain', text: instrMatch[2] });
459
- return tokens;
460
- }
461
- return [{ type: 'plain', text: line }];
462
- }
463
-
464
- /** Tokenize a bash line with variable references and flags. */
465
- function tokenizeBashLine(line: string, keywords: Set<string>): Token[] {
466
- const tokens: Token[] = [];
467
- let i = 0;
468
- while (i < line.length) {
469
- // Comments
470
- if (line[i] === '#' && (i === 0 || /\s/.test(line[i - 1]))) {
471
- tokens.push({ type: 'comment', text: line.slice(i) });
472
- return tokens;
473
- }
474
- // Variable references $VAR or ${VAR}
475
- if (line[i] === '$') {
476
- let j = i + 1;
477
- if (line[j] === '{') {
478
- j++;
479
- while (j < line.length && line[j] !== '}') j++;
480
- j = Math.min(j + 1, line.length);
481
- } else {
482
- while (j < line.length && /[a-zA-Z0-9_]/.test(line[j])) j++;
483
- }
484
- tokens.push({ type: 'number', text: line.slice(i, j) });
485
- i = j;
486
- continue;
487
- }
488
- // Strings
489
- if (line[i] === '"' || line[i] === "'") {
490
- const quote = line[i];
491
- let j = i + 1;
492
- while (j < line.length && line[j] !== quote) {
493
- if (line[j] === '\\') j++;
494
- j++;
495
- }
496
- j = Math.min(j + 1, line.length);
497
- tokens.push({ type: 'string', text: line.slice(i, j) });
498
- i = j;
499
- continue;
500
- }
501
- // Flags (words starting with -)
502
- if (line[i] === '-' && i > 0 && /\s/.test(line[i - 1])) {
503
- let j = i;
504
- while (j < line.length && !/\s/.test(line[j])) j++;
505
- tokens.push({ type: 'comment', text: line.slice(i, j) });
506
- i = j;
507
- continue;
508
- }
509
- // Words / keywords
510
- if (/[a-zA-Z_]/.test(line[i])) {
511
- let j = i;
512
- while (j < line.length && /[a-zA-Z0-9_]/.test(line[j])) j++;
513
- const word = line.slice(i, j);
514
- if (keywords.has(word)) {
515
- tokens.push({ type: 'keyword', text: word });
516
- } else {
517
- tokens.push({ type: 'plain', text: word });
518
- }
519
- i = j;
520
- continue;
521
- }
522
- tokens.push({ type: 'plain', text: line[i] });
523
- i++;
524
- }
525
- return tokens;
526
- }
527
-
528
- /**
529
- * Tokenize a single line of code into typed tokens for syntax highlighting.
530
- */
531
- function tokenizeLine(line: string, keywords: Set<string>, types: Set<string>, language?: string): Token[] {
532
- // Language-specific fast paths
533
- if (language) {
534
- const lang = language.toLowerCase();
535
- if (lang === 'yaml' || lang === 'yml') return tokenizeYamlLine(line);
536
- if (lang === 'json') return tokenizeJsonLine(line);
537
- if (lang === 'dockerfile' || lang === 'docker') return tokenizeDockerfileLine(line);
538
- if (lang === 'bash' || lang === 'sh' || lang === 'shell' || lang === 'zsh') return tokenizeBashLine(line, keywords);
539
- }
540
- // Generic tokenizer below
541
- /* falls through */
542
- const tokens: Token[] = [];
543
- let i = 0;
544
-
545
- while (i < line.length) {
546
- // Single-line comments: // or #
547
- if (
548
- (line[i] === '/' && line[i + 1] === '/') ||
549
- (line[i] === '#' && i === line.trimStart().length - line.length + line.indexOf('#'))
550
- ) {
551
- if (line[i] === '/' && line[i + 1] === '/') {
552
- tokens.push({ type: 'comment', text: line.slice(i) });
553
- return tokens;
554
- }
555
- if (line[i] === '#') {
556
- tokens.push({ type: 'comment', text: line.slice(i) });
557
- return tokens;
558
- }
559
- }
560
-
561
- // Strings: "...", '...', `...`
562
- if (line[i] === '"' || line[i] === "'" || line[i] === '`') {
563
- const quote = line[i];
564
- let j = i + 1;
565
- while (j < line.length && line[j] !== quote) {
566
- if (line[j] === '\\') {
567
- j++;
568
- } // skip escaped char
569
- j++;
570
- }
571
- j = Math.min(j + 1, line.length);
572
- tokens.push({ type: 'string', text: line.slice(i, j) });
573
- i = j;
574
- continue;
575
- }
576
-
577
- // Numbers
578
- if (/[0-9]/.test(line[i]) && (i === 0 || /[\s(,=+\-*/<>[\]{};:]/.test(line[i - 1]))) {
579
- let j = i;
580
- while (j < line.length && /[0-9._xXa-fA-Fn]/.test(line[j])) {
581
- j++;
582
- }
583
- tokens.push({ type: 'number', text: line.slice(i, j) });
584
- i = j;
585
- continue;
586
- }
587
-
588
- // Words (identifiers/keywords)
589
- if (/[a-zA-Z_$]/.test(line[i])) {
590
- let j = i;
591
- while (j < line.length && /[a-zA-Z0-9_$]/.test(line[j])) {
592
- j++;
593
- }
594
- const word = line.slice(i, j);
595
- if (keywords.has(word)) {
596
- tokens.push({ type: 'keyword', text: word });
597
- } else if (types.has(word)) {
598
- tokens.push({ type: 'type', text: word });
599
- } else {
600
- tokens.push({ type: 'plain', text: word });
601
- }
602
- i = j;
603
- continue;
604
- }
605
-
606
- // Other characters (operators, punctuation, whitespace)
607
- tokens.push({ type: 'plain', text: line[i] });
608
- i++;
609
- }
610
-
611
- return tokens;
612
- }
613
-
614
- /**
615
- * Render a single code block inside a dim bordered Box with syntax highlighting.
616
- */
617
- function CodeBlock({ content, language }: { content: string; language?: string }) {
618
- const keywords = getKeywords(language);
619
- const types = getTypes(language);
620
- const lines = content.split('\n');
621
-
622
- // useMemo avoids re-tokenizing all lines on every render (PERF-3c).
623
- // Invalidated only when content or language changes.
624
- const tokenizedLines = useMemo(
625
- () => lines.map(line => tokenizeLine(line, keywords, types, language)),
626
- // eslint-disable-next-line react-hooks/exhaustive-deps
627
- [content, language]
628
- );
629
-
630
- return (
631
- <Box flexDirection="column" borderStyle="single" borderColor="gray" paddingX={1} marginY={0}>
632
- {language && (
633
- <Text dimColor italic>
634
- {language}
635
- </Text>
636
- )}
637
- {tokenizedLines.map((tokens, lineIdx) => (
638
- <Text key={lineIdx}>
639
- {tokens.map((token, tokenIdx) => {
640
- const color = TOKEN_COLORS[token.type];
641
- if (color) {
642
- return (
643
- <Text key={tokenIdx} color={color}>
644
- {token.text}
645
- </Text>
646
- );
647
- }
648
- return <Text key={tokenIdx}>{token.text}</Text>;
649
- })}
650
- </Text>
651
- ))}
652
- </Box>
653
- );
654
- }
655
-
656
- /**
657
- * Render a plain text segment with basic markdown formatting:
658
- * - **bold**, *italic*, `inline code`
659
- * - # headings (h1-h3)
660
- * - - bullet lists
661
- */
662
- function FormattedText({ text }: { text: string }) {
663
- const lines = text.split('\n');
664
- const elements: React.ReactNode[] = [];
665
-
666
- for (let i = 0; i < lines.length; i++) {
667
- const line = lines[i];
668
-
669
- // Headings
670
- const headingMatch = line.match(/^(#{1,3})\s+(.+)$/);
671
- if (headingMatch) {
672
- const level = headingMatch[1].length;
673
- elements.push(
674
- <Text key={i} bold color={level === 1 ? 'yellow' : level === 2 ? 'cyan' : 'white'}>
675
- {headingMatch[2]}
676
- </Text>
677
- );
678
- continue;
679
- }
680
-
681
- // Bullet list items
682
- const bulletMatch = line.match(/^(\s*)[-*]\s+(.+)$/);
683
- if (bulletMatch) {
684
- elements.push(
685
- <Text key={i} wrap="wrap">
686
- {bulletMatch[1]}
687
- {' - '}
688
- {renderInlineMarkdown(bulletMatch[2])}
689
- </Text>
690
- );
691
- continue;
692
- }
693
-
694
- // Numbered list items
695
- const numMatch = line.match(/^(\s*)\d+\.\s+(.+)$/);
696
- if (numMatch) {
697
- elements.push(
698
- <Text key={i} wrap="wrap">
699
- {line}
700
- </Text>
701
- );
702
- continue;
703
- }
704
-
705
- // Regular line with inline formatting
706
- elements.push(
707
- <Text key={i} wrap="wrap">
708
- {renderInlineMarkdown(line)}
709
- </Text>
710
- );
711
- }
712
-
713
- return <>{elements}</>;
714
- }
715
-
716
- /**
717
- * Render inline markdown: **bold**, *italic*, `code`
718
- * Returns a flat array of React nodes.
719
- */
720
- function renderInlineMarkdown(text: string): React.ReactNode {
721
- // Split on inline formatting patterns
722
- const parts: React.ReactNode[] = [];
723
- const regex = /(\*\*(.+?)\*\*|\*(.+?)\*|`([^`]+?)`)/g;
724
- let lastIndex = 0;
725
- let match: RegExpExecArray | null;
726
- let key = 0;
727
-
728
- while ((match = regex.exec(text)) !== null) {
729
- // Text before this match
730
- if (match.index > lastIndex) {
731
- parts.push(text.slice(lastIndex, match.index));
732
- }
733
-
734
- if (match[2]) {
735
- // **bold**
736
- parts.push(
737
- <Text key={key++} bold>
738
- {match[2]}
739
- </Text>
740
- );
741
- } else if (match[3]) {
742
- // *italic*
743
- parts.push(
744
- <Text key={key++} italic>
745
- {match[3]}
746
- </Text>
747
- );
748
- } else if (match[4]) {
749
- // `inline code`
750
- parts.push(
751
- <Text key={key++} color="yellow">
752
- {match[4]}
753
- </Text>
754
- );
755
- }
756
-
757
- lastIndex = match.index + match[0].length;
758
- }
759
-
760
- // Trailing text
761
- if (lastIndex < text.length) {
762
- parts.push(text.slice(lastIndex));
763
- }
764
-
765
- return parts.length === 1 ? parts[0] : <>{parts}</>;
766
- }
767
-
768
- /**
769
- * Render the segments of a single message body (interleaving text and code).
770
- */
771
- function MessageBody({ content }: { content: string }) {
772
- const segments = parseContent(content);
773
- return (
774
- <Box flexDirection="column">
775
- {segments.map((seg, idx) => {
776
- if (seg.type === 'code') {
777
- return <CodeBlock key={idx} content={seg.content} language={seg.language} />;
778
- }
779
- return (
780
- <Box key={idx} flexDirection="column">
781
- <FormattedText text={seg.content} />
782
- </Box>
783
- );
784
- })}
785
- </Box>
786
- );
787
- }
788
-
789
- /**
790
- * H2: Highlight occurrences of `query` within `text` in yellow/bold.
791
- * Returns a React node with matching portions highlighted.
792
- */
793
- function highlightText(text: string, query: string): React.ReactNode {
794
- if (!query || !text.toLowerCase().includes(query.toLowerCase())) return text;
795
- const escaped = query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
796
- const parts = text.split(new RegExp(`(${escaped})`, 'gi'));
797
- return (
798
- <>
799
- {parts.map((p, i) =>
800
- p.toLowerCase() === query.toLowerCase() ? (
801
- <Text key={i} color="yellow" bold>{p}</Text>
802
- ) : (
803
- <Text key={i}>{p}</Text>
804
- )
805
- )}
806
- </>
807
- );
808
- }
809
-
810
- /**
811
- * M6: Parse a subagent tag from message content.
812
- * Returns the subagent name if the content starts with "[subagent:<name>]",
813
- * otherwise returns null.
814
- */
815
- function parseSubagentTag(content: string): string | null {
816
- const match = content.match(/^\[subagent:(\w+)\]/);
817
- if (match) return match[1];
818
- return null;
819
- }
820
-
821
- /**
822
- * M6: Strip the subagent tag prefix from content for clean rendering.
823
- */
824
- function stripSubagentTag(content: string): string {
825
- return content.replace(/^\[subagent:\w+\]\s*/, '');
826
- }
827
-
828
- /**
829
- * Render a single message row with role label and body.
830
- */
831
- function MessageRow({ message, mode, searchQuery }: { message: UIMessage; mode: AgentMode; searchQuery?: string }) {
832
- if (message.role === 'system') {
833
- return (
834
- <Box marginBottom={1}>
835
- <Text dimColor italic wrap="wrap">
836
- {searchQuery ? highlightText(message.content, searchQuery) : message.content}
837
- </Text>
838
- </Box>
839
- );
840
- }
841
-
842
- const isUser = message.role === 'user';
843
-
844
- // M6: Detect subagent messages — assistant messages whose content starts with [subagent:<name>]
845
- const subagentName = !isUser ? parseSubagentTag(message.content) : null;
846
- const displayContent = subagentName ? stripSubagentTag(message.content) : message.content;
847
-
848
- const label = isUser
849
- ? 'You: '
850
- : subagentName
851
- ? `[@${subagentName}]: `
852
- : `Agent (${mode}): `;
853
- const labelColor = isUser ? 'cyan' : subagentName ? 'magenta' : 'green';
854
- const time = message.timestamp.toLocaleTimeString();
855
-
856
- return (
857
- <Box flexDirection="column" marginBottom={1}>
858
- <Box>
859
- <Text bold color={labelColor}>
860
- {label}
861
- </Text>
862
- {subagentName && (
863
- <Text dimColor italic>{`subagent `}</Text>
864
- )}
865
- <Text dimColor>{time}</Text>
866
- </Box>
867
- <Box marginLeft={2}>
868
- {searchQuery
869
- ? <Text wrap="wrap">{highlightText(displayContent, searchQuery)}</Text>
870
- : <MessageBody content={displayContent} />
871
- }
872
- </Box>
873
- </Box>
874
- );
875
- }
876
-
877
- /** Props for HistoricalMessages. */
878
- interface HistoricalMessagesProps {
879
- messages: UIMessage[];
880
- mode: AgentMode;
881
- searchQuery?: string;
882
- }
883
-
884
- /**
885
- * Renders all-but-the-last visible messages with React.memo to prevent
886
- * re-rendering historical messages during streaming of the latest message.
887
- * The custom comparator returns true (skip re-render) when the messages array
888
- * reference and length are both unchanged and mode hasn't changed.
889
- */
890
- const HistoricalMessages = React.memo(
891
- function HistoricalMessages({ messages, mode, searchQuery }: HistoricalMessagesProps) {
892
- return (
893
- <>
894
- {messages.map((msg, idx) => {
895
- // M3: Insert a dim turn boundary separator after an assistant message
896
- // that is immediately followed by a user message (new conversation turn).
897
- const nextMsg = messages[idx + 1];
898
- const showSeparator =
899
- msg.role === 'assistant' &&
900
- nextMsg !== undefined &&
901
- nextMsg.role === 'user';
902
- return (
903
- <React.Fragment key={msg.id}>
904
- <MessageRow message={msg} mode={mode} searchQuery={searchQuery} />
905
- {showSeparator && (
906
- <Box marginBottom={1}>
907
- <Text dimColor>{'─'.repeat(40)}</Text>
908
- </Box>
909
- )}
910
- </React.Fragment>
911
- );
912
- })}
913
- </>
914
- );
915
- },
916
- (prev, next) =>
917
- prev.messages === next.messages &&
918
- prev.messages.length === next.messages.length &&
919
- prev.mode === next.mode &&
920
- prev.searchQuery === next.searchQuery
921
- );
922
-
923
- /** Copy text to clipboard using platform-native CLI tools. */
924
- function copyToClipboard(text: string): void {
925
- try {
926
- const { execSync } = require('node:child_process') as typeof import('node:child_process');
927
- const { platform } = process;
928
- if (platform === 'darwin') {
929
- execSync('pbcopy', { input: text, stdio: ['pipe', 'ignore', 'ignore'] });
930
- } else if (platform === 'linux') {
931
- try {
932
- execSync('xclip -selection clipboard', { input: text, stdio: ['pipe', 'ignore', 'ignore'] });
933
- } catch {
934
- execSync('xdg-open', { stdio: 'ignore' }); // fallback: at least don't crash
935
- }
936
- } else if (platform === 'win32') {
937
- execSync('clip', { input: text, stdio: ['pipe', 'ignore', 'ignore'] });
938
- }
939
- } catch {
940
- // Clipboard unavailable — silently ignore
941
- }
942
- }
943
-
944
- /** Exported alias for testing (H1). */
945
- export const _copyToClipboard = copyToClipboard;
946
-
947
- /**
948
- * MessageList displays the most recent messages that fit the display limit.
949
- * Older messages are trimmed from the top so the view always shows the latest
950
- * conversation turns.
951
- *
952
- * PERF-3a: Splits visible messages into HistoricalMessages (memoised) +
953
- * the last message rendered inline, so streaming tokens only cause the last
954
- * message to re-render.
955
- */
956
- export function MessageList({ messages, mode, maxVisible, scrollOffset = 0, searchQuery, columns }: MessageListProps) {
957
- // C2: Dynamic default — show 2.5x the terminal row height, minimum 50
958
- const effectiveMaxVisible = maxVisible ?? Math.max(50, Math.floor((process.stdout.rows ?? 40) * 2.5));
959
- const truncated = messages.length > effectiveMaxVisible;
960
- const visible = useMemo(
961
- () => truncated ? messages.slice(messages.length - effectiveMaxVisible) : messages,
962
- [messages, truncated, effectiveMaxVisible]
963
- );
964
-
965
- // M1: Filter messages by search query when set
966
- const filteredVisible = searchQuery
967
- ? visible.filter(m => m.content.toLowerCase().includes(searchQuery.toLowerCase()))
968
- : visible;
969
-
970
- // C1: Apply scroll offset — trim from the bottom so the user can read history
971
- const scrolledVisible = scrollOffset > 0
972
- ? filteredVisible.slice(0, Math.max(0, filteredVisible.length - scrollOffset))
973
- : filteredVisible;
974
-
975
- // DevOps-first welcome splash when no messages yet
976
- if (scrolledVisible.length === 0) {
977
- if (searchQuery) {
978
- return (
979
- <Box paddingX={1} paddingY={1}>
980
- <Text dimColor>No messages match &quot;{searchQuery}&quot;</Text>
981
- </Box>
982
- );
983
- }
984
- return (
985
- <Box flexDirection="column" paddingX={2} paddingY={1}>
986
- <Text bold color="cyan">What would you like to do?</Text>
987
- <Text> </Text>
988
- <Text dimColor>Infrastructure:</Text>
989
- <Text dimColor> run terraform plan and show me what will change</Text>
990
- <Text dimColor> check for pod restarts in the production namespace</Text>
991
- <Text dimColor> upgrade the nginx helm release to the latest chart</Text>
992
- <Text dimColor> show me infrastructure drift in this workspace</Text>
993
- <Text> </Text>
994
- <Text dimColor>Incident response:</Text>
995
- <Text dimColor> high CPU on api-service pods — investigate and suggest fixes</Text>
996
- <Text dimColor> the staging deployment is failing — show me the logs</Text>
997
- <Text> </Text>
998
- <Text dimColor>Generation:</Text>
999
- <Text dimColor> generate terraform for an RDS PostgreSQL instance in us-east-1</Text>
1000
- <Text dimColor> create k8s manifests for a 3-replica nginx deployment</Text>
1001
- <Text> </Text>
1002
- <Text dimColor>Press ? for keyboard shortcuts | /help for commands | /init to set up context</Text>
1003
- </Box>
1004
- );
1005
- }
1006
-
1007
- const historical = scrolledVisible.slice(0, -1);
1008
- const last = scrolledVisible[scrolledVisible.length - 1];
1009
-
1010
- return (
1011
- <Box flexDirection="column" paddingX={1}>
1012
- {truncated && !searchQuery && (
1013
- <Box marginBottom={1}>
1014
- <Text dimColor italic>
1015
- ↑ {messages.length - effectiveMaxVisible} earlier messages — /compact to summarize or /clear to reset
1016
- </Text>
1017
- </Box>
1018
- )}
1019
- {searchQuery && (
1020
- <Box marginBottom={1}>
1021
- <Text dimColor italic>
1022
- Search: "{searchQuery}" — showing {filteredVisible.length} of {visible.length} messages
1023
- </Text>
1024
- </Box>
1025
- )}
1026
- {historical.length > 0 && (
1027
- <HistoricalMessages messages={historical} mode={mode} searchQuery={searchQuery} />
1028
- )}
1029
- <MessageRow key={last.id} message={last} mode={mode} searchQuery={searchQuery} />
1030
- </Box>
1031
- );
1032
- }