@capagents/forgeqe 3.3.0 → 3.3.2

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 (217) hide show
  1. package/HOW_TO_USE.md +32 -0
  2. package/dist/docs-site/docs/area-setup/index.html +1 -0
  3. package/dist/docs-site/docs/area-test-cases/index.html +25 -0
  4. package/dist/docs-site/docs/search.js +1 -1
  5. package/dist/forgeqe.js +1922 -1906
  6. package/dist/requirement-agent/requirements_agent/__init__.py +3 -0
  7. package/dist/requirement-agent/requirements_agent/__main__.py +5 -0
  8. package/dist/requirement-agent/requirements_agent/agent.py +363 -0
  9. package/dist/requirement-agent/requirements_agent/chat_session.py +424 -0
  10. package/dist/requirement-agent/requirements_agent/cli.py +870 -0
  11. package/dist/requirement-agent/requirements_agent/config.py +403 -0
  12. package/dist/requirement-agent/requirements_agent/console_ui.py +632 -0
  13. package/dist/requirement-agent/requirements_agent/context/__init__.py +3 -0
  14. package/dist/requirement-agent/requirements_agent/context/aggregate.py +214 -0
  15. package/dist/requirement-agent/requirements_agent/context/base.py +14 -0
  16. package/dist/requirement-agent/requirements_agent/context/folder.py +107 -0
  17. package/dist/requirement-agent/requirements_agent/context/given.py +70 -0
  18. package/dist/requirement-agent/requirements_agent/context/graph.py +181 -0
  19. package/dist/requirement-agent/requirements_agent/context/knowledge.py +192 -0
  20. package/dist/requirement-agent/requirements_agent/context/mcp.py +24 -0
  21. package/dist/requirement-agent/requirements_agent/context/memory.py +144 -0
  22. package/dist/requirement-agent/requirements_agent/context/personas.py +214 -0
  23. package/dist/requirement-agent/requirements_agent/context/rag.py +148 -0
  24. package/dist/requirement-agent/requirements_agent/context/untrusted.py +56 -0
  25. package/dist/requirement-agent/requirements_agent/docs/HOW_TO_USE.md +505 -0
  26. package/dist/requirement-agent/requirements_agent/docs/requirements-agent-architecture.html +348 -0
  27. package/dist/requirement-agent/requirements_agent/docs_cmd.py +51 -0
  28. package/dist/requirement-agent/requirements_agent/export/__init__.py +3 -0
  29. package/dist/requirement-agent/requirements_agent/export/markdown.py +55 -0
  30. package/dist/requirement-agent/requirements_agent/export/pdf.py +82 -0
  31. package/dist/requirement-agent/requirements_agent/export/requirements_json.py +120 -0
  32. package/dist/requirement-agent/requirements_agent/init_cmd.py +191 -0
  33. package/dist/requirement-agent/requirements_agent/llm/__init__.py +3 -0
  34. package/dist/requirement-agent/requirements_agent/llm/base.py +49 -0
  35. package/dist/requirement-agent/requirements_agent/llm/copilot.py +171 -0
  36. package/dist/requirement-agent/requirements_agent/llm/mock.py +144 -0
  37. package/dist/requirement-agent/requirements_agent/llm/providers.py +277 -0
  38. package/dist/requirement-agent/requirements_agent/llm/router.py +35 -0
  39. package/dist/requirement-agent/requirements_agent/models.py +73 -0
  40. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/analyst.md +29 -0
  41. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/architect.md +28 -0
  42. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/bmad-orchestrator.md +26 -0
  43. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/dev.md +27 -0
  44. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/pm.md +27 -0
  45. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/po.md +27 -0
  46. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/qa.md +28 -0
  47. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/sm.md +26 -0
  48. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-analyst.md +8 -0
  49. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-architect.md +11 -0
  50. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-dev.md +11 -0
  51. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-orchestrator.md +9 -0
  52. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-pm.md +9 -0
  53. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-po.md +10 -0
  54. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-qa.md +11 -0
  55. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-sm.md +8 -0
  56. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/data/bmad-kb.md +19 -0
  57. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/data/requirements-standards-baseline.md +188 -0
  58. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/data/technical-preferences.md +54 -0
  59. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/utils/template-format.md +7 -0
  60. package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/workflows/greenfield-fullstack.yml +177 -0
  61. package/dist/requirement-agent/requirements_agent/pipeline/__init__.py +3 -0
  62. package/dist/requirement-agent/requirements_agent/pipeline/brd.py +86 -0
  63. package/dist/requirement-agent/requirements_agent/pipeline/pack.py +233 -0
  64. package/dist/requirement-agent/requirements_agent/pipeline/progress.py +60 -0
  65. package/dist/requirement-agent/requirements_agent/pipeline/prompts.py +150 -0
  66. package/dist/requirement-agent/requirements_agent/pipeline/quality.py +124 -0
  67. package/dist/requirement-agent/requirements_agent/pipeline/refine.py +386 -0
  68. package/dist/requirement-agent/requirements_agent/pipeline/sections.py +117 -0
  69. package/dist/requirement-agent/requirements_agent/pipeline/spec_circuit.py +142 -0
  70. package/dist/requirement-agent/requirements_agent/shell/__init__.py +7 -0
  71. package/dist/requirement-agent/requirements_agent/shell/actions.py +208 -0
  72. package/dist/requirement-agent/requirements_agent/shell/app.py +902 -0
  73. package/dist/requirement-agent/requirements_agent/shell/commands.py +206 -0
  74. package/dist/requirement-agent/requirements_agent/shell/progress_pane.py +114 -0
  75. package/dist/requirement-agent/requirements_agent/shell/ref_picker.py +59 -0
  76. package/dist/requirement-agent/requirements_agent/shell/refs.py +120 -0
  77. package/dist/requirement-agent/requirements_agent/shell/session.py +362 -0
  78. package/dist/requirement-agent/requirements_agent/shell/transcript.py +241 -0
  79. package/dist/requirement-agent/requirements_agent/shell/usage.py +64 -0
  80. package/dist/requirement-agent/requirements_agent/shell/usage_llm.py +64 -0
  81. package/dist/requirement-agent/requirements_agent/shell/worker.py +378 -0
  82. package/dist/requirement-agent/requirements_agent/tuios_hook.py +182 -0
  83. package/dist/requirement-agent/requirements_agent/webops.py +627 -0
  84. package/dist/template.html +66 -66
  85. package/dist/web/assets/{3d-force-graph-DgKpiu6s.js → 3d-force-graph-DDyP5jcf.js} +1 -1
  86. package/dist/web/assets/Agent-sLaNlaQo.js +8 -0
  87. package/dist/web/assets/AgentWork-Dv0G4bt3.js +2 -0
  88. package/dist/web/assets/ApiTests-Bnw2qgWw.js +15 -0
  89. package/dist/web/assets/Browse-CBt1JY2E.js +1 -0
  90. package/dist/web/assets/Chat-DIWdnIZK.js +3 -0
  91. package/dist/web/assets/CommandPalette-DD04oS83.js +1 -0
  92. package/dist/web/assets/Compare-D0Ao8dZ6.js +1 -0
  93. package/dist/web/assets/Cost-BY_8-9Qt.js +1 -0
  94. package/dist/web/assets/{Data-CkQGUNww.js → Data-BC7R_FbW.js} +4 -4
  95. package/dist/web/assets/Desktop-CSQ2xLg0.js +1 -0
  96. package/dist/web/assets/DesktopReview-CCOhUdeJ.js +2 -0
  97. package/dist/web/assets/DeviceScreen-BHmTd9Q-.js +1 -0
  98. package/dist/web/assets/Evidence-9W4pqIkC.js +1 -0
  99. package/dist/web/assets/{Explore-k0Y19Q5T.js → Explore-BndXiEf8.js} +2 -2
  100. package/dist/web/assets/Features-BrfsTC9Q.js +1 -0
  101. package/dist/web/assets/{Flags-CXFDO-k_.js → Flags-DyykkeHU.js} +2 -2
  102. package/dist/web/assets/Flaky-C3gj_Brn.js +1 -0
  103. package/dist/web/assets/Impact-Z8nbNhbe.js +3 -0
  104. package/dist/web/assets/Jobs-CJWXAqSy.js +5 -0
  105. package/dist/web/assets/KindPage-C45x_cFz.js +6 -0
  106. package/dist/web/assets/LiveDevice-DGdLDigO.js +1 -0
  107. package/dist/web/assets/Migration-QFI5ctp7.js +8 -0
  108. package/dist/web/assets/Mobile-CuswZyee.js +1 -0
  109. package/dist/web/assets/Observability-CknZ_xBN.js +1 -0
  110. package/dist/web/assets/PageAgent-B2bmmMaP.js +1 -0
  111. package/dist/web/assets/Product-CrtwDiMv.js +12 -0
  112. package/dist/web/assets/Production-BMsytC2i.js +1 -0
  113. package/dist/web/assets/Quality-B4Aw6N3_.js +1 -0
  114. package/dist/web/assets/Readiness-CVIzTFX-.js +1 -0
  115. package/dist/web/assets/Record-B2Ic8Taj.js +1 -0
  116. package/dist/web/assets/Regression-bCIAE3Ne.js +5 -0
  117. package/dist/web/assets/RelationGraph-kG4YVMzl.js +1 -0
  118. package/dist/web/assets/Reports-NAZ-26Ub.js +2 -0
  119. package/dist/web/assets/Requirements-BkpiF-Bt.js +2 -0
  120. package/dist/web/assets/Responsive-CsaoisJq.js +3 -0
  121. package/dist/web/assets/RunDiff-BC-3Wg1b.js +1 -0
  122. package/dist/web/assets/Settings-DyBed-J5.js +21 -0
  123. package/dist/web/assets/Steps-DcQxQ4yA.js +2 -0
  124. package/dist/web/assets/TestData-wpUeU9Er.js +2 -0
  125. package/dist/web/assets/TestManagement-D0njkyAT.js +4 -0
  126. package/dist/web/assets/WhatsNew-BxIAAwgH.js +1 -0
  127. package/dist/web/assets/agentSettingsSheet-BdB7IXah.js +1 -0
  128. package/dist/web/assets/choice-C4-yW2x9.js +1 -0
  129. package/dist/web/assets/code-Jek8uWUO.js +1 -0
  130. package/dist/web/assets/{coverage-DirEXtfZ.js → coverage-q-ib7wOq.js} +1 -1
  131. package/dist/web/assets/dataParts-B2-a-pOD.js +3 -0
  132. package/dist/web/assets/desktopAppPath-C-p0zU40.js +1 -0
  133. package/dist/web/assets/frame-CjpZWX_X.js +13 -0
  134. package/dist/web/assets/index-BH5RbDNY.css +2 -0
  135. package/dist/web/assets/index-CfGXe_De.js +55 -0
  136. package/dist/web/assets/line-icons-CwCZidXs.js +1 -0
  137. package/dist/web/assets/logos-P2LOMyTK.js +1 -0
  138. package/dist/web/assets/{markdown-BnrLv6Iw.js → markdown-dXSsS-mD.js} +5 -5
  139. package/dist/web/assets/nav-BZfNOkhX.js +1 -0
  140. package/dist/web/assets/pageBack-BwKT31j3.js +3 -0
  141. package/dist/web/assets/palette-L37b4wTE.js +1 -0
  142. package/dist/web/assets/{paletteCommands-LXIICD4V.js → paletteCommands-zqGCORJu.js} +1 -1
  143. package/dist/web/assets/parts-3o6HnCp1.js +1 -0
  144. package/dist/web/assets/preload-helper-BupTYkQW.js +1 -0
  145. package/dist/web/assets/productParts-BDiEg0z6.js +1 -0
  146. package/dist/web/assets/qualityParts--CnSadOZ.js +1 -0
  147. package/dist/web/assets/radio-BLI4Ubhk.js +1 -0
  148. package/dist/web/assets/react-BDur5s0O.js +1 -0
  149. package/dist/web/assets/{recordTest-BzKpS4m5.js → recordTest-D092f975.js} +1 -1
  150. package/dist/web/assets/route-oDy8sV6H.js +1 -0
  151. package/dist/web/assets/sectionList-XiKcJNEK.js +1 -0
  152. package/dist/web/assets/step-mark-CaKf4dAR.js +1 -0
  153. package/dist/web/assets/stepper-naqAN_Nb.js +1 -0
  154. package/dist/web/assets/utils-DJRAScIl.js +1 -0
  155. package/dist/web/assets/wizardParts-DLlOHVMx.js +1 -0
  156. package/dist/web/index.html +14 -12
  157. package/docs/user-guide.html +26 -0
  158. package/package.json +2 -1
  159. package/py/forgeqe_engine/cli.py +7 -0
  160. package/dist/web/assets/Agent-BP11jrsE.js +0 -8
  161. package/dist/web/assets/AgentWork-DqiO3LUi.js +0 -2
  162. package/dist/web/assets/ApiTests-CLFt0wGW.js +0 -15
  163. package/dist/web/assets/Browse-D5VDHN9Z.js +0 -1
  164. package/dist/web/assets/Chat-BqqaT-n0.js +0 -3
  165. package/dist/web/assets/CommandPalette-D3F4iHrP.js +0 -1
  166. package/dist/web/assets/Compare-KeUsk4G3.js +0 -1
  167. package/dist/web/assets/Cost-CDdSNCkt.js +0 -1
  168. package/dist/web/assets/Desktop-COKu5aHU.js +0 -1
  169. package/dist/web/assets/DesktopReview-CMpXNurd.js +0 -2
  170. package/dist/web/assets/DeviceScreen-DJqblqBh.js +0 -1
  171. package/dist/web/assets/Evidence-CPevi78T.js +0 -1
  172. package/dist/web/assets/Features-D_miisXy.js +0 -1
  173. package/dist/web/assets/Flaky-CzaQIwXC.js +0 -1
  174. package/dist/web/assets/Impact-pos046GB.js +0 -3
  175. package/dist/web/assets/Jobs-C0TtzWA4.js +0 -5
  176. package/dist/web/assets/KindPage-DAvgKrwt.js +0 -6
  177. package/dist/web/assets/LiveDevice-C9LRZMhC.js +0 -1
  178. package/dist/web/assets/Migration-kYknzHdK.js +0 -8
  179. package/dist/web/assets/Mobile-AVi39qoN.js +0 -1
  180. package/dist/web/assets/Observability-l1ZN4JL0.js +0 -1
  181. package/dist/web/assets/PageAgent-DzVjKKYz.js +0 -1
  182. package/dist/web/assets/Product-CrnXTDkX.js +0 -12
  183. package/dist/web/assets/Production-B4VlKTlL.js +0 -1
  184. package/dist/web/assets/Quality-CtjVY15v.js +0 -1
  185. package/dist/web/assets/Readiness-RUzKklxF.js +0 -1
  186. package/dist/web/assets/Record-f87pdoaN.js +0 -1
  187. package/dist/web/assets/Regression-RSnjP5hS.js +0 -5
  188. package/dist/web/assets/RelationGraph-gc0Xmklt.js +0 -1
  189. package/dist/web/assets/Reports-881BJZ_u.js +0 -2
  190. package/dist/web/assets/Responsive-251XAuZE.js +0 -3
  191. package/dist/web/assets/RunDiff-DG0hKKDs.js +0 -1
  192. package/dist/web/assets/Settings-Cv3kUuOx.js +0 -21
  193. package/dist/web/assets/Steps-Cyjk5JtV.js +0 -2
  194. package/dist/web/assets/TestData-TcXA9UmV.js +0 -2
  195. package/dist/web/assets/TestManagement-D0e2N_Xr.js +0 -4
  196. package/dist/web/assets/WhatsNew-COVX946M.js +0 -1
  197. package/dist/web/assets/agentSettingsSheet-DGFh1_iF.js +0 -1
  198. package/dist/web/assets/choice-CiFogD01.js +0 -1
  199. package/dist/web/assets/code-DzYywAs5.js +0 -1
  200. package/dist/web/assets/dataParts-Di7PdPHu.js +0 -3
  201. package/dist/web/assets/desktopAppPath-B8j1-pX0.js +0 -1
  202. package/dist/web/assets/frame-CNLw552P.js +0 -13
  203. package/dist/web/assets/index-CuN17Qrj.js +0 -55
  204. package/dist/web/assets/index-Dchrk5Yt.css +0 -2
  205. package/dist/web/assets/line-icons-B-O8oBsY.js +0 -1
  206. package/dist/web/assets/nav-Ds_6IERv.js +0 -1
  207. package/dist/web/assets/pageBack-DJxbEPfN.js +0 -3
  208. package/dist/web/assets/palette-H2g-hemT.js +0 -1
  209. package/dist/web/assets/parts-DKRLtrjs.js +0 -1
  210. package/dist/web/assets/preload-helper-BML5SvL4.js +0 -1
  211. package/dist/web/assets/productParts-DvrCr604.js +0 -1
  212. package/dist/web/assets/qualityParts-BYx5phEI.js +0 -1
  213. package/dist/web/assets/radio-CbR6ODxQ.js +0 -1
  214. package/dist/web/assets/route-DjewvmpL.js +0 -1
  215. package/dist/web/assets/sectionList-0umoKvRv.js +0 -1
  216. package/dist/web/assets/step-mark-g8Eb6foB.js +0 -1
  217. package/dist/web/assets/stepper-CzZIC36d.js +0 -1
@@ -0,0 +1,870 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import sys
5
+ from pathlib import Path
6
+ from typing import List, Optional
7
+
8
+ import typer
9
+ from rich.markdown import Markdown
10
+ from rich.panel import Panel
11
+ from rich.table import Table
12
+
13
+ from requirements_agent.agent import RequirementsAgent
14
+ from requirements_agent.config import AppConfig, load_config, select_profile, use_forgeqe_project, user_config_dir
15
+ from requirements_agent.console_ui import RunLiveUi, RunUiState, console
16
+ from requirements_agent.docs_cmd import copy_docs, list_doc_paths, open_architecture
17
+ from requirements_agent.export.markdown import export_run_artifacts, write_markdown
18
+ from requirements_agent.export.pdf import export_pdf
19
+ from requirements_agent.init_cmd import init_workspace
20
+ from requirements_agent.llm.router import build_llm_client
21
+
22
+ app = typer.Typer(
23
+ name="req-agent",
24
+ help="Self-contained Spec Circuit Requirements Agent",
25
+ add_completion=False,
26
+ no_args_is_help=True,
27
+ )
28
+
29
+
30
+ def _read_design(design: Optional[str], design_file: Optional[Path]) -> str:
31
+ if design_file:
32
+ path = design_file.expanduser().resolve()
33
+ if not path.is_file():
34
+ console.print(
35
+ f"[red]Design file not found:[/] {path}\n"
36
+ f"[dim]Create it (e.g. brief.md) or pass --design \"…\" instead of -f.[/]"
37
+ )
38
+ raise typer.Exit(1)
39
+ return path.read_text(encoding="utf-8")
40
+ return design or ""
41
+
42
+
43
+ def _build_agent(
44
+ config_path: Optional[Path],
45
+ *,
46
+ profile: Optional[str] = None,
47
+ provider: Optional[str] = None,
48
+ model: Optional[str] = None,
49
+ llms_json: Optional[Path] = None,
50
+ attach: Optional[List[Path]] = None,
51
+ context_dir: Optional[List[Path]] = None,
52
+ project: Optional[Path] = None,
53
+ persona: Optional[List[str]] = None,
54
+ ) -> tuple[AppConfig, RequirementsAgent]:
55
+ cfg = load_config(config_path, profile_name=profile, llms_json=llms_json)
56
+ use_forgeqe_project(cfg, project, persona)
57
+ if profile and profile != cfg.llm.profile:
58
+ try:
59
+ cfg = select_profile(cfg, profile)
60
+ except KeyError as e:
61
+ console.print(f"[red]{e}[/red]")
62
+ raise typer.Exit(1) from e
63
+ if provider:
64
+ cfg.llm.provider = provider
65
+ if model:
66
+ # If model matches a profile name, switch profile; else treat as model id
67
+ if model in cfg.llm_profiles and not provider:
68
+ cfg = select_profile(cfg, model)
69
+ else:
70
+ cfg.llm.model = model
71
+ if cfg.llm.provider == "azure" and not cfg.llm.deployment:
72
+ cfg.llm.deployment = model
73
+ extra: List[str] = []
74
+ for p in attach or []:
75
+ extra.append(str(p.expanduser()))
76
+ for p in context_dir or []:
77
+ extra.append(str(p.expanduser()))
78
+ llm = build_llm_client(cfg.llm)
79
+ try:
80
+ return cfg, RequirementsAgent(cfg, llm, extra_paths=extra)
81
+ except ValueError as e: # a persona the project does not have
82
+ console.print(f"[red]{e}[/red]")
83
+ raise typer.Exit(1) from e
84
+
85
+ @app.command("init")
86
+ def init_cmd(
87
+ directory: Path = typer.Option(
88
+ Path("."),
89
+ "--dir",
90
+ "-d",
91
+ help="Directory to write config files into",
92
+ ),
93
+ profile: str = typer.Option(
94
+ "mock",
95
+ "--profile",
96
+ "-p",
97
+ help="Default LLM profile name (must exist in llms.json templates)",
98
+ ),
99
+ force: bool = typer.Option(False, "--force", help="Overwrite existing files"),
100
+ global_config: bool = typer.Option(
101
+ False,
102
+ "--global",
103
+ help=f"Write into {user_config_dir()} instead of --dir",
104
+ ),
105
+ ):
106
+ """Scaffold requirements-agent.yaml, llms.json, and .env.example."""
107
+ target = user_config_dir() if global_config else directory
108
+ created, notes = init_workspace(target, force=force, active_profile=profile, global_home=global_config)
109
+ if created:
110
+ console.print(Panel("\n".join(f"• {p}" for p in created), title="Created"))
111
+ for n in notes:
112
+ console.print(f"[yellow]{n}[/yellow]")
113
+ if not created and notes:
114
+ console.print("[dim]Nothing written.[/dim]")
115
+ raise typer.Exit(0)
116
+ console.print(
117
+ "\nNext steps:\n"
118
+ f" 1. Edit [bold]{target / 'llms.json'}[/bold] — fill endpoints / api_key_env\n"
119
+ f" 2. Set secrets from [bold]{target / '.env.example'}[/bold]\n"
120
+ f" 3. Pick active profile in [bold]{target / 'requirements-agent.yaml'}[/bold] → llm.active\n"
121
+ " 4. [bold]req-agent models[/bold] to list profiles\n"
122
+ " 5. [bold]req-agent docs --open[/bold] for the architecture diagram\n"
123
+ " 6. [bold]req-agent start[/bold] or [bold]req-agent run --profile mock …[/bold]\n"
124
+ )
125
+
126
+
127
+ @app.command("docs")
128
+ def docs_cmd(
129
+ open_html: bool = typer.Option(
130
+ False,
131
+ "--open",
132
+ "-o",
133
+ help="Open the interactive architecture HTML in your browser",
134
+ ),
135
+ copy_to: Optional[Path] = typer.Option(
136
+ None,
137
+ "--copy",
138
+ "-c",
139
+ help="Copy HOW_TO_USE.md and architecture HTML into this directory",
140
+ ),
141
+ ):
142
+ """Show or copy the bundled user guide and architecture HTML."""
143
+ if copy_to is not None:
144
+ written = copy_docs(copy_to)
145
+ if not written:
146
+ console.print("[red]No docs found in package. Reinstall requirements-agent.[/red]")
147
+ raise typer.Exit(1)
148
+ console.print(Panel("\n".join(f"• {p}" for p in written), title="Copied"))
149
+ console.print(f"[dim]Open[/] {(copy_to.expanduser().resolve() / 'requirements-agent-architecture.html')}")
150
+ return
151
+
152
+ if open_html:
153
+ try:
154
+ path = open_architecture()
155
+ except FileNotFoundError as e:
156
+ console.print(f"[red]{e}[/red]")
157
+ raise typer.Exit(1) from e
158
+ console.print(f"[green]Opened[/] {path}")
159
+ return
160
+
161
+ rows = list_doc_paths()
162
+ table = Table(title="Bundled documentation")
163
+ table.add_column("File")
164
+ table.add_column("Path")
165
+ table.add_column("Present")
166
+ missing = False
167
+ for name, path in rows:
168
+ ok = path.is_file()
169
+ if not ok:
170
+ missing = True
171
+ table.add_row(name, str(path), "yes" if ok else "missing")
172
+ console.print(table)
173
+ if missing:
174
+ console.print("[yellow]Some docs are missing — reinstall the package.[/yellow]")
175
+ raise typer.Exit(1)
176
+ console.print(
177
+ "\n[dim]Tips:[/]\n"
178
+ " req-agent docs --open # architecture in browser\n"
179
+ " req-agent docs --copy ./docs # copy guide + HTML next to your project\n"
180
+ )
181
+
182
+
183
+ @app.command("models")
184
+ def models_cmd(
185
+ config: Optional[Path] = typer.Option(None, "--config", help="Path to requirements-agent.yaml"),
186
+ llms_json: Optional[Path] = typer.Option(None, "--llms", help="Path to llms.json"),
187
+ ):
188
+ """List LLM profiles from llms.json."""
189
+ cfg = load_config(config, llms_json=llms_json)
190
+ table = Table(title="LLM profiles")
191
+ table.add_column("Profile", style="cyan")
192
+ table.add_column("Provider")
193
+ table.add_column("Model")
194
+ table.add_column("Endpoint")
195
+ table.add_column("Active")
196
+ for name, prof in sorted(cfg.llm_profiles.items()):
197
+ active = "✓" if name == cfg.llm_default_profile or name == cfg.llm.profile else ""
198
+ table.add_row(
199
+ name,
200
+ str(prof.get("provider") or ""),
201
+ str(prof.get("model") or prof.get("deployment") or ""),
202
+ str(prof.get("endpoint") or "")[:48],
203
+ active,
204
+ )
205
+ console.print(table)
206
+ if cfg.llm_models_file:
207
+ console.print(f"[dim]models_file: {cfg.llm_models_file}[/dim]")
208
+ console.print(f"[dim]active: {cfg.llm.profile or cfg.llm_default_profile} ({cfg.llm.provider}/{cfg.llm.model})[/dim]")
209
+
210
+
211
+ @app.command("start")
212
+ def start_cmd(
213
+ profile: Optional[str] = typer.Option(None, "--profile", "-p", help="LLM profile from llms.json"),
214
+ provider: Optional[str] = typer.Option(None, "--provider"),
215
+ model: Optional[str] = typer.Option(None, "--model"),
216
+ config: Optional[Path] = typer.Option(None, "--config"),
217
+ llms_json: Optional[Path] = typer.Option(None, "--llms"),
218
+ out: Path = typer.Option(Path("./out"), "--out", "-o", help="Default output dir (change later with /out)"),
219
+ ):
220
+ """Open the chat shell — set title, brief, refs, and analyse from inside."""
221
+ from requirements_agent.shell.app import run_shell
222
+
223
+ cfg = load_config(config, profile_name=profile, llms_json=llms_json)
224
+ if profile:
225
+ try:
226
+ cfg = select_profile(cfg, profile)
227
+ except KeyError:
228
+ pass
229
+ if provider:
230
+ cfg.llm.provider = provider
231
+ if model:
232
+ if model in cfg.llm_profiles and not provider:
233
+ try:
234
+ cfg = select_profile(cfg, model)
235
+ except KeyError:
236
+ cfg.llm.model = model
237
+ else:
238
+ cfg.llm.model = model
239
+
240
+ run_shell(
241
+ config=cfg,
242
+ title="",
243
+ design="",
244
+ out_dir=out.expanduser().resolve(),
245
+ autostart_analyse=False,
246
+ )
247
+
248
+
249
+ @app.command("tui")
250
+ def tui_cmd(
251
+ config: Optional[Path] = typer.Option(None, "--config", help="Path to requirements-agent.yaml"),
252
+ profile: Optional[str] = typer.Option(None, "--profile", "-p", help="LLM profile from llms.json"),
253
+ llms_json: Optional[Path] = typer.Option(None, "--llms", help="Path to llms.json"),
254
+ out: Path = typer.Option(Path("./out"), "--out", "-o"),
255
+ ):
256
+ """Alias for `req-agent start`."""
257
+ start_cmd(profile=profile, config=config, llms_json=llms_json, out=out)
258
+
259
+
260
+ @app.command("review")
261
+ def review_cmd(
262
+ title: str = typer.Option(..., "--title", "-t"),
263
+ design: Optional[str] = typer.Option(None, "--design", "-d"),
264
+ design_file: Optional[Path] = typer.Option(None, "--design-file", "-f"),
265
+ attach: Optional[List[Path]] = typer.Option(None, "--attach", "-a"),
266
+ context_dir: Optional[List[Path]] = typer.Option(None, "--context-dir", "-c"),
267
+ out: Path = typer.Option(Path("./out"), "--out", "-o"),
268
+ profile: Optional[str] = typer.Option(None, "--profile", "-p"),
269
+ provider: Optional[str] = typer.Option(None, "--provider"),
270
+ model: Optional[str] = typer.Option(None, "--model", help="Model id or profile name"),
271
+ config: Optional[Path] = typer.Option(None, "--config"),
272
+ llms_json: Optional[Path] = typer.Option(None, "--llms"),
273
+ project: Optional[Path] = typer.Option(None, "--project", help="A ForgeQE project: review with its knowledge, memory and product graph"),
274
+ persona: Optional[List[str]] = typer.Option(None, "--persona", help="A business persona's id (.forgeqe/business-personas) who reviews as a stakeholder; repeat for more"),
275
+ plain: bool = typer.Option(False, "--plain", help="Simple line logs (CI / no Live UI)"),
276
+ ):
277
+ """Run Spec Circuit multi-persona review."""
278
+ design_text = _read_design(design, design_file)
279
+ cfg, agent = _build_agent(
280
+ config,
281
+ profile=profile,
282
+ provider=provider,
283
+ model=model,
284
+ llms_json=llms_json,
285
+ attach=attach,
286
+ context_dir=context_dir,
287
+ project=project,
288
+ persona=persona,
289
+ )
290
+
291
+ ui_state = RunUiState(
292
+ title=title,
293
+ profile=cfg.llm.profile or cfg.llm_default_profile or "",
294
+ provider=cfg.llm.provider,
295
+ model=cfg.llm.model,
296
+ out_dir=str(out),
297
+ )
298
+ with RunLiveUi(ui_state, plain=plain) as ui:
299
+ result = agent.review(title, design_text, on_progress=ui.on_progress)
300
+ if result.success:
301
+ ui_state.phase = "done"
302
+ ui_state.current = "Review complete"
303
+ ui.refresh()
304
+ else:
305
+ ui_state.phase = "error"
306
+ ui_state.error = result.error
307
+ ui.refresh()
308
+
309
+ if not result.success:
310
+ raise typer.Exit(1)
311
+
312
+ paths = export_run_artifacts(
313
+ out.expanduser(),
314
+ spec_circuit=result.report_markdown,
315
+ sections=result.sections,
316
+ meta={
317
+ "title": title,
318
+ "profile": cfg.llm.profile,
319
+ "provider": cfg.llm.provider,
320
+ "model": cfg.llm.model,
321
+ },
322
+ )
323
+ console.print(Panel(f"Wrote [bold]{paths['spec_circuit']}[/bold]", title="Spec Circuit", border_style="green"))
324
+
325
+
326
+ @app.command("score")
327
+ def score_cmd(
328
+ title: str = typer.Option(..., "--title", "-t"),
329
+ design: Optional[str] = typer.Option(None, "--design", "-d"),
330
+ design_file: Optional[Path] = typer.Option(None, "--design-file", "-f"),
331
+ report: Path = typer.Option(..., "--report", "-r"),
332
+ out: Optional[Path] = typer.Option(None, "--out", "-o"),
333
+ profile: Optional[str] = typer.Option(None, "--profile", "-p"),
334
+ provider: Optional[str] = typer.Option(None, "--provider"),
335
+ model: Optional[str] = typer.Option(None, "--model"),
336
+ config: Optional[Path] = typer.Option(None, "--config"),
337
+ llms_json: Optional[Path] = typer.Option(None, "--llms"),
338
+ ):
339
+ """Score a requirements report (six dimensions)."""
340
+ design_text = _read_design(design, design_file)
341
+ _, agent = _build_agent(
342
+ config, profile=profile, provider=provider, model=model, llms_json=llms_json
343
+ )
344
+ md = report.expanduser().read_text(encoding="utf-8")
345
+ q = agent.score(title, design_text, md)
346
+ payload = {
347
+ "overall_score": q.overall_score,
348
+ "dimensions": q.dimensions,
349
+ "rationale": q.rationale,
350
+ "top_gaps": q.top_gaps,
351
+ "success": q.success,
352
+ "error": q.error,
353
+ }
354
+ console.print_json(data=payload)
355
+ if out:
356
+ out.expanduser().parent.mkdir(parents=True, exist_ok=True)
357
+ out.expanduser().write_text(json.dumps(payload, indent=2), encoding="utf-8")
358
+ if not q.success:
359
+ raise typer.Exit(1)
360
+
361
+
362
+ @app.command("questions")
363
+ def questions_cmd(
364
+ title: str = typer.Option(..., "--title", "-t"),
365
+ design: Optional[str] = typer.Option(None, "--design", "-d"),
366
+ design_file: Optional[Path] = typer.Option(None, "--design-file", "-f"),
367
+ report: Path = typer.Option(..., "--report", "-r"),
368
+ out: Optional[Path] = typer.Option(None, "--out", "-o"),
369
+ profile: Optional[str] = typer.Option(None, "--profile", "-p"),
370
+ provider: Optional[str] = typer.Option(None, "--provider"),
371
+ model: Optional[str] = typer.Option(None, "--model"),
372
+ config: Optional[Path] = typer.Option(None, "--config"),
373
+ llms_json: Optional[Path] = typer.Option(None, "--llms"),
374
+ ):
375
+ design_text = _read_design(design, design_file)
376
+ _, agent = _build_agent(
377
+ config, profile=profile, provider=provider, model=model, llms_json=llms_json
378
+ )
379
+ md = report.expanduser().read_text(encoding="utf-8")
380
+ result = agent.questions(title, design_text, md)
381
+ console.print_json(data=result)
382
+ if out:
383
+ out.expanduser().write_text(json.dumps(result, indent=2), encoding="utf-8")
384
+ if not result.get("success"):
385
+ raise typer.Exit(1)
386
+
387
+
388
+ @app.command("resolve")
389
+ def resolve_cmd(
390
+ title: str = typer.Option(..., "--title", "-t"),
391
+ design: Optional[str] = typer.Option(None, "--design", "-d"),
392
+ design_file: Optional[Path] = typer.Option(None, "--design-file", "-f"),
393
+ report: Path = typer.Option(..., "--report", "-r"),
394
+ question: str = typer.Option(..., "--question", "-q"),
395
+ profile: Optional[str] = typer.Option(None, "--profile", "-p"),
396
+ provider: Optional[str] = typer.Option(None, "--provider"),
397
+ model: Optional[str] = typer.Option(None, "--model"),
398
+ config: Optional[Path] = typer.Option(None, "--config"),
399
+ llms_json: Optional[Path] = typer.Option(None, "--llms"),
400
+ ):
401
+ design_text = _read_design(design, design_file)
402
+ _, agent = _build_agent(
403
+ config, profile=profile, provider=provider, model=model, llms_json=llms_json
404
+ )
405
+ md = report.expanduser().read_text(encoding="utf-8")
406
+ result = agent.resolve(title, design_text, md, question)
407
+ console.print_json(data=result)
408
+ if not result.get("success"):
409
+ raise typer.Exit(1)
410
+
411
+
412
+ @app.command("web", hidden=True)
413
+ def web_cmd(
414
+ op: str = typer.Argument(..., help="review | show | fix | accept | skip | undo | export"),
415
+ folder: Path = typer.Option(..., "--dir", help="The review's folder"),
416
+ profile: Optional[str] = typer.Option(None, "--profile", "-p"),
417
+ llms_json: Optional[Path] = typer.Option(None, "--llms"),
418
+ memory: Optional[Path] = typer.Option(None, "--memory", help="The review memory folder"),
419
+ ):
420
+ """For a host such as ForgeQE's web app: one operation, its request as JSON on stdin, JSON lines on stdout."""
421
+ from requirements_agent.webops import MAX_STDIN, run
422
+
423
+ text = sys.stdin.read(MAX_STDIN + 1)
424
+ args = {"profile": profile, "llms": str(llms_json) if llms_json else None, "memory": str(memory) if memory else None}
425
+ raise typer.Exit(run(op, folder.expanduser(), args, text))
426
+
427
+
428
+ @app.command("chat")
429
+ def chat_cmd(
430
+ title: str = typer.Option(..., "--title", "-t"),
431
+ design: Optional[str] = typer.Option(None, "--design", "-d"),
432
+ design_file: Optional[Path] = typer.Option(None, "--design-file", "-f"),
433
+ report: Path = typer.Option(
434
+ ...,
435
+ "--report",
436
+ "-r",
437
+ help="BRD / Spec Circuit markdown to chat against (updated live)",
438
+ ),
439
+ docs: Optional[List[Path]] = typer.Option(
440
+ None, "--docs", help="Reference document file(s) or folder(s) for Memory"
441
+ ),
442
+ attach: Optional[List[Path]] = typer.Option(
443
+ None, "--attach", "-a", help="Alias for --docs"
444
+ ),
445
+ section: Optional[str] = typer.Option(
446
+ None, "--section", "-s", help="Pin a ## section at start (number or name)"
447
+ ),
448
+ profile: Optional[str] = typer.Option(None, "--profile", "-p"),
449
+ provider: Optional[str] = typer.Option(None, "--provider"),
450
+ model: Optional[str] = typer.Option(None, "--model"),
451
+ config: Optional[Path] = typer.Option(None, "--config"),
452
+ llms_json: Optional[Path] = typer.Option(None, "--llms"),
453
+ plain: bool = typer.Option(
454
+ False, "--plain", help="Legacy line-based chat (no Textual shell)"
455
+ ),
456
+ out: Optional[Path] = typer.Option(None, "--out", "-o", help="Output dir (default: report parent)"),
457
+ ):
458
+ """Chat-first shell: 60% conversation / 40% progress, always-active input."""
459
+ design_text = _read_design(design, design_file)
460
+ doc_paths: List[Path] = []
461
+ for p in docs or []:
462
+ doc_paths.append(p)
463
+ for p in attach or []:
464
+ doc_paths.append(p)
465
+
466
+ report_path = report.expanduser().resolve()
467
+ if not report_path.is_file():
468
+ console.print(f"[red]Report not found:[/] {report_path}")
469
+ raise typer.Exit(1)
470
+
471
+ if plain or not _stdin_is_tty():
472
+ from requirements_agent.chat_session import bootstrap_chat, run_chat_session
473
+
474
+ _, agent = _build_agent(
475
+ config,
476
+ profile=profile,
477
+ provider=provider,
478
+ model=model,
479
+ llms_json=llms_json,
480
+ attach=doc_paths,
481
+ )
482
+ session = bootstrap_chat(
483
+ agent=agent,
484
+ title=title,
485
+ design=design_text,
486
+ report=report_path,
487
+ docs=doc_paths,
488
+ pin=section,
489
+ )
490
+ run_chat_session(session)
491
+ return
492
+
493
+ from requirements_agent.shell.app import run_shell
494
+
495
+ cfg = load_config(config, profile_name=profile, llms_json=llms_json)
496
+ if profile:
497
+ try:
498
+ cfg = select_profile(cfg, profile)
499
+ except KeyError:
500
+ pass
501
+ if provider:
502
+ cfg.llm.provider = provider
503
+ if model:
504
+ cfg.llm.model = model
505
+
506
+ run_shell(
507
+ config=cfg,
508
+ title=title,
509
+ design=design_text,
510
+ out_dir=out or report_path.parent,
511
+ report=report_path,
512
+ docs=doc_paths,
513
+ pin=section,
514
+ autostart_analyse=False,
515
+ )
516
+
517
+
518
+ @app.command("refine")
519
+ def refine_cmd(
520
+ title: str = typer.Option(..., "--title", "-t"),
521
+ design: Optional[str] = typer.Option(None, "--design", "-d"),
522
+ design_file: Optional[Path] = typer.Option(None, "--design-file", "-f"),
523
+ report: Path = typer.Option(..., "--report", "-r", help="Report/BRD markdown to refine"),
524
+ message: Optional[str] = typer.Option(
525
+ None, "--message", "-m", help="What to change (required unless --list-sections / --interactive)"
526
+ ),
527
+ section: Optional[str] = typer.Option(
528
+ None,
529
+ "--section",
530
+ "-s",
531
+ help="Target ## section by number, exact name, or substring (e.g. 8 or 'Non-functional')",
532
+ ),
533
+ out: Optional[Path] = typer.Option(
534
+ None,
535
+ "--out",
536
+ "-o",
537
+ help="Write path (default: update --report in place immediately)",
538
+ ),
539
+ list_sections: bool = typer.Option(
540
+ False, "--list-sections", "-l", help="List ## sections in the report and exit"
541
+ ),
542
+ interactive: bool = typer.Option(
543
+ False, "--interactive", "-i", help="Pick a section and instruction interactively"
544
+ ),
545
+ show: bool = typer.Option(
546
+ True, "--show/--no-show", help="Print the updated section (or doc summary) after write"
547
+ ),
548
+ profile: Optional[str] = typer.Option(None, "--profile", "-p"),
549
+ provider: Optional[str] = typer.Option(None, "--provider"),
550
+ model: Optional[str] = typer.Option(None, "--model"),
551
+ config: Optional[Path] = typer.Option(None, "--config"),
552
+ llms_json: Optional[Path] = typer.Option(None, "--llms"),
553
+ ):
554
+ """Refine the report — optionally one ## section — and update the file immediately."""
555
+ from rich.prompt import Prompt
556
+
557
+ from requirements_agent.pipeline.sections import format_section_menu, list_h2_sections, section_slice
558
+
559
+ report_path = report.expanduser().resolve()
560
+ if not report_path.is_file():
561
+ console.print(f"[red]Report not found:[/] {report_path}")
562
+ raise typer.Exit(1)
563
+
564
+ md = report_path.read_text(encoding="utf-8")
565
+ sections = list_h2_sections(md)
566
+
567
+ if list_sections:
568
+ console.print(Panel(format_section_menu(sections) or "(no ## sections)", title=str(report_path)))
569
+ raise typer.Exit(0)
570
+
571
+ design_text = _read_design(design, design_file)
572
+ _, agent = _build_agent(
573
+ config, profile=profile, provider=provider, model=model, llms_json=llms_json
574
+ )
575
+
576
+ section_q = section
577
+ msg = (message or "").strip()
578
+
579
+ if interactive:
580
+ console.print(Panel(format_section_menu(sections) or "(no ## sections)", title="Sections"))
581
+ section_q = Prompt.ask(
582
+ "Section number or name",
583
+ default=str(section_q or (sections[0].index if sections else "")),
584
+ ).strip()
585
+ if not msg:
586
+ msg = Prompt.ask("What should change in this section").strip()
587
+ preview_sec = None
588
+ from requirements_agent.pipeline.sections import resolve_section
589
+
590
+ preview_sec, _ = resolve_section(md, section_q)
591
+ if preview_sec:
592
+ console.print(
593
+ Panel(
594
+ Markdown(section_slice(md, preview_sec)[:1200]),
595
+ title=f"Current · [{preview_sec.index}] {preview_sec.heading}",
596
+ border_style="dim",
597
+ )
598
+ )
599
+
600
+ if not msg:
601
+ console.print("[red]Provide --message / -m, or use --interactive[/]")
602
+ raise typer.Exit(1)
603
+
604
+ console.print(
605
+ f"[dim]Refining[/] {report_path.name}"
606
+ + (f" · section [cyan]{section_q}[/]" if section_q else " · [cyan]full document[/]")
607
+ )
608
+
609
+ result = agent.refine(title, design_text, md, msg, section=section_q)
610
+ if not result.get("success"):
611
+ console.print(f"[red]{result.get('error')}[/red]")
612
+ raise typer.Exit(1)
613
+
614
+ out_path = (out.expanduser().resolve() if out else report_path)
615
+ write_markdown(out_path, result["report_markdown"])
616
+
617
+ sec_meta = result.get("section") or {}
618
+ updated_label = (
619
+ f"## {sec_meta.get('heading')}" if sec_meta.get("heading") else "full document"
620
+ )
621
+ console.print(
622
+ Panel(
623
+ f"[bold green]Updated immediately[/]\n"
624
+ f"File: {out_path}\n"
625
+ f"Target: {updated_label}\n"
626
+ f"{result.get('assistant_message') or ''}",
627
+ title="✓ Refine complete",
628
+ border_style="green",
629
+ )
630
+ )
631
+
632
+ if show:
633
+ snippet = result.get("section_markdown") or ""
634
+ if not snippet and sec_meta.get("heading"):
635
+ from requirements_agent.pipeline.sections import resolve_section as _rs
636
+
637
+ s, _ = _rs(result["report_markdown"], str(sec_meta.get("index") or sec_meta["heading"]))
638
+ if s:
639
+ snippet = section_slice(result["report_markdown"], s)
640
+ if snippet:
641
+ console.print(Panel(Markdown(snippet[:2500]), title="Updated section (preview)", border_style="cyan"))
642
+ else:
643
+ # Full doc: show first ~40 lines
644
+ lines = (result["report_markdown"] or "").splitlines()[:40]
645
+ console.print(
646
+ Panel(Markdown("\n".join(lines)), title="Document head (preview)", border_style="cyan")
647
+ )
648
+
649
+ console.print(
650
+ "\n[dim]Tip:[/] list sections with\n"
651
+ f" req-agent refine -r {report_path} -t … -l\n"
652
+ "Then:\n"
653
+ f' req-agent refine -r {report_path} -t … -s "Non-functional" -m "Add p95 latency targets"\n'
654
+ )
655
+
656
+
657
+ @app.command("consolidate")
658
+ def consolidate_cmd(
659
+ title: str = typer.Option(..., "--title", "-t"),
660
+ design: Optional[str] = typer.Option(None, "--design", "-d"),
661
+ design_file: Optional[Path] = typer.Option(None, "--design-file", "-f"),
662
+ report: Path = typer.Option(..., "--report", "-r"),
663
+ out: Path = typer.Option(..., "--out", "-o"),
664
+ profile: Optional[str] = typer.Option(None, "--profile", "-p"),
665
+ provider: Optional[str] = typer.Option(None, "--provider"),
666
+ model: Optional[str] = typer.Option(None, "--model"),
667
+ config: Optional[Path] = typer.Option(None, "--config"),
668
+ llms_json: Optional[Path] = typer.Option(None, "--llms"),
669
+ ):
670
+ """Consolidate Spec Circuit draft into BRD (# Requirements report)."""
671
+ design_text = _read_design(design, design_file)
672
+ _, agent = _build_agent(
673
+ config, profile=profile, provider=provider, model=model, llms_json=llms_json
674
+ )
675
+ md = report.expanduser().read_text(encoding="utf-8")
676
+ result = agent.consolidate(title, design_text, md)
677
+ if not result.get("success"):
678
+ console.print(f"[red]{result.get('error')}[/red]")
679
+ raise typer.Exit(1)
680
+ write_markdown(out.expanduser(), result["report_markdown"])
681
+ console.print(f"Wrote [bold]{out}[/bold]")
682
+
683
+
684
+ @app.command("export")
685
+ def export_cmd(
686
+ report: Path = typer.Option(..., "--report", "-r"),
687
+ out: Path = typer.Option(..., "--out", "-o"),
688
+ format: str = typer.Option("both", "--format", help="md | pdf | both"),
689
+ title: str = typer.Option("Requirements Report", "--title", "-t"),
690
+ ):
691
+ md = report.expanduser().read_text(encoding="utf-8")
692
+ out = out.expanduser()
693
+ out.parent.mkdir(parents=True, exist_ok=True)
694
+ fmt = format.lower()
695
+ if fmt in ("md", "both"):
696
+ target = out if out.suffix == ".md" else out.with_suffix(".md")
697
+ write_markdown(target, md)
698
+ console.print(f"MD → {target}")
699
+ if fmt in ("pdf", "both"):
700
+ target = out if out.suffix == ".pdf" else out.with_suffix(".pdf")
701
+ export_pdf(md, target, title=title)
702
+ console.print(f"PDF → {target}")
703
+
704
+
705
+ def _stdin_is_tty() -> bool:
706
+ import sys
707
+
708
+ return bool(getattr(sys.stdin, "isatty", lambda: False)())
709
+
710
+
711
+ @app.command("run")
712
+ def run_cmd(
713
+ title: Optional[str] = typer.Option(None, "--title", "-t", help="Optional; or set with /title in the shell"),
714
+ design: Optional[str] = typer.Option(None, "--design", "-d"),
715
+ design_file: Optional[Path] = typer.Option(None, "--design-file", "-f"),
716
+ attach: Optional[List[Path]] = typer.Option(None, "--attach", "-a", help="Document file(s) for Memory context"),
717
+ context_dir: Optional[List[Path]] = typer.Option(None, "--context-dir", "-c", help="Folder(s) of docs for Memory"),
718
+ docs: Optional[List[Path]] = typer.Option(None, "--docs", help="Alias for --attach / --context-dir paths"),
719
+ out: Path = typer.Option(Path("./out"), "--out", "-o"),
720
+ format: str = typer.Option("md", "--format", help="md | pdf | both"),
721
+ profile: Optional[str] = typer.Option(None, "--profile", "-p"),
722
+ provider: Optional[str] = typer.Option(None, "--provider"),
723
+ model: Optional[str] = typer.Option(None, "--model"),
724
+ config: Optional[Path] = typer.Option(None, "--config"),
725
+ llms_json: Optional[Path] = typer.Option(None, "--llms"),
726
+ no_consolidate: bool = typer.Option(False, "--no-consolidate"),
727
+ no_questions: bool = typer.Option(False, "--no-questions", help="Skip open-questions extraction"),
728
+ project: Optional[Path] = typer.Option(None, "--project", help="A ForgeQE project: review with its knowledge, memory and product graph"),
729
+ persona: Optional[List[str]] = typer.Option(None, "--persona", help="A business persona's id (.forgeqe/business-personas) who reviews as a stakeholder; repeat for more"),
730
+ plain: bool = typer.Option(
731
+ False, "--plain", help="Headless / CI line logs (skip chat-first Textual shell)"
732
+ ),
733
+ ):
734
+ """Open the chat shell (same as start). Flags are optional shortcuts; use --plain for CI."""
735
+ design_text = _read_design(design, design_file) if (design or design_file) else ""
736
+
737
+ doc_paths: List[Path] = []
738
+ for p in attach or []:
739
+ doc_paths.append(p)
740
+ for p in context_dir or []:
741
+ doc_paths.append(p)
742
+ for p in docs or []:
743
+ doc_paths.append(p)
744
+
745
+ out_abs = out.expanduser().resolve()
746
+ out_abs.mkdir(parents=True, exist_ok=True)
747
+
748
+ # Interactive: chat-first shell (autostart only when title+brief already provided)
749
+ if not plain and _stdin_is_tty():
750
+ from requirements_agent.shell.app import run_shell
751
+
752
+ cfg = load_config(config, profile_name=profile, llms_json=llms_json)
753
+ use_forgeqe_project(cfg, project, persona)
754
+ if profile:
755
+ try:
756
+ cfg = select_profile(cfg, profile)
757
+ except KeyError:
758
+ pass
759
+ if provider:
760
+ cfg.llm.provider = provider
761
+ if model:
762
+ if model in cfg.llm_profiles and not provider:
763
+ cfg = select_profile(cfg, model)
764
+ else:
765
+ cfg.llm.model = model
766
+ ready = bool((title or "").strip()) and len(design_text.strip()) >= 10
767
+ run_shell(
768
+ config=cfg,
769
+ title=title or "",
770
+ design=design_text,
771
+ out_dir=out_abs,
772
+ docs=doc_paths,
773
+ autostart_analyse=ready,
774
+ )
775
+ return
776
+
777
+ if not (title or "").strip() or len(design_text.strip()) < 10:
778
+ console.print(
779
+ "[red]Headless --plain run needs --title and --design / --design-file.[/]\n"
780
+ "[dim]Or omit --plain and use the interactive shell: req-agent start[/]"
781
+ )
782
+ raise typer.Exit(1)
783
+
784
+ cfg, agent = _build_agent(
785
+ config,
786
+ profile=profile,
787
+ provider=provider,
788
+ model=model,
789
+ llms_json=llms_json,
790
+ attach=doc_paths,
791
+ context_dir=None,
792
+ project=project,
793
+ persona=persona,
794
+ )
795
+
796
+ ui_state = RunUiState(
797
+ title=title or "Requirements",
798
+ profile=cfg.llm.profile or cfg.llm_default_profile or "",
799
+ provider=cfg.llm.provider,
800
+ model=cfg.llm.model,
801
+ out_dir=str(out_abs),
802
+ extract_questions=not no_questions,
803
+ )
804
+
805
+ result: dict = {"success": False}
806
+ try:
807
+ with RunLiveUi(ui_state, plain=True) as ui:
808
+ result = agent.run(
809
+ title or "Requirements",
810
+ design_text,
811
+ out_dir=out_abs,
812
+ export_format=format,
813
+ consolidate=not no_consolidate,
814
+ extract_questions=not no_questions,
815
+ on_progress=ui.on_progress,
816
+ )
817
+ if result.get("success"):
818
+ q = result.get("quality") or {}
819
+ ui.finish_ok(q.get("overall_score"))
820
+ else:
821
+ ui.finish_error(str(result.get("error") or "Unknown error"))
822
+ except Exception as e:
823
+ console.print(f"[bold red]Run crashed:[/] {e}")
824
+ raise typer.Exit(1) from e
825
+
826
+ paths = result.get("paths") or {}
827
+ console.print()
828
+ if not result.get("success"):
829
+ console.print(Panel(str(result.get("error")), title="Failed", border_style="red"))
830
+ if paths.get("out_dir"):
831
+ console.print(f"[dim]Partial output dir:[/] {paths.get('out_dir')}")
832
+ raise typer.Exit(1)
833
+
834
+ q = result.get("quality") or {}
835
+ file_lines = []
836
+ for key, label in (
837
+ ("spec_circuit", "Spec Circuit report"),
838
+ ("brd", "BRD / Requirements report"),
839
+ ("quality", "Quality score JSON"),
840
+ ("questions", "Open questions JSON"),
841
+ ("sections", "Persona sections"),
842
+ ("meta", "Run meta"),
843
+ ):
844
+ if paths.get(key):
845
+ file_lines.append(f"• {label}: {paths[key]}")
846
+ for pdf in paths.get("pdf") or []:
847
+ file_lines.append(f"• PDF: {pdf}")
848
+
849
+ console.print(
850
+ Panel(
851
+ f"[bold]{title}[/]\n"
852
+ f"Profile: {cfg.llm.profile or cfg.llm_default_profile} ({cfg.llm.provider}/{cfg.llm.model})\n"
853
+ f"Quality: [bold]{q.get('overall_score', '?')}[/]/100\n"
854
+ f"Output: [bold]{paths.get('out_dir', out_abs)}[/]\n\n"
855
+ + ("\n".join(file_lines) if file_lines else "[yellow]No artifact paths recorded[/]"),
856
+ title="✓ Run complete",
857
+ border_style="green",
858
+ )
859
+ )
860
+ for w in result.get("warnings") or []:
861
+ console.print(f"[yellow]Warning:[/] {w}")
862
+ if q.get("top_gaps"):
863
+ console.print(Markdown("### Top gaps\n" + "\n".join(f"- {g}" for g in q["top_gaps"])))
864
+ console.print(
865
+ "\n[dim]Next:[/] req-agent start then /open <report.md>\n"
866
+ )
867
+
868
+
869
+ if __name__ == "__main__":
870
+ app()