@capagents/forgeqe 3.3.1 → 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.
- package/HOW_TO_USE.md +32 -0
- package/dist/docs-site/docs/area-setup/index.html +1 -0
- package/dist/docs-site/docs/area-test-cases/index.html +25 -0
- package/dist/docs-site/docs/search.js +1 -1
- package/dist/forgeqe.js +1922 -1906
- package/dist/requirement-agent/requirements_agent/__init__.py +3 -0
- package/dist/requirement-agent/requirements_agent/__main__.py +5 -0
- package/dist/requirement-agent/requirements_agent/agent.py +363 -0
- package/dist/requirement-agent/requirements_agent/chat_session.py +424 -0
- package/dist/requirement-agent/requirements_agent/cli.py +870 -0
- package/dist/requirement-agent/requirements_agent/config.py +403 -0
- package/dist/requirement-agent/requirements_agent/console_ui.py +632 -0
- package/dist/requirement-agent/requirements_agent/context/__init__.py +3 -0
- package/dist/requirement-agent/requirements_agent/context/aggregate.py +214 -0
- package/dist/requirement-agent/requirements_agent/context/base.py +14 -0
- package/dist/requirement-agent/requirements_agent/context/folder.py +107 -0
- package/dist/requirement-agent/requirements_agent/context/given.py +70 -0
- package/dist/requirement-agent/requirements_agent/context/graph.py +181 -0
- package/dist/requirement-agent/requirements_agent/context/knowledge.py +192 -0
- package/dist/requirement-agent/requirements_agent/context/mcp.py +24 -0
- package/dist/requirement-agent/requirements_agent/context/memory.py +144 -0
- package/dist/requirement-agent/requirements_agent/context/personas.py +214 -0
- package/dist/requirement-agent/requirements_agent/context/rag.py +148 -0
- package/dist/requirement-agent/requirements_agent/context/untrusted.py +56 -0
- package/dist/requirement-agent/requirements_agent/docs/HOW_TO_USE.md +505 -0
- package/dist/requirement-agent/requirements_agent/docs/requirements-agent-architecture.html +348 -0
- package/dist/requirement-agent/requirements_agent/docs_cmd.py +51 -0
- package/dist/requirement-agent/requirements_agent/export/__init__.py +3 -0
- package/dist/requirement-agent/requirements_agent/export/markdown.py +55 -0
- package/dist/requirement-agent/requirements_agent/export/pdf.py +82 -0
- package/dist/requirement-agent/requirements_agent/export/requirements_json.py +120 -0
- package/dist/requirement-agent/requirements_agent/init_cmd.py +191 -0
- package/dist/requirement-agent/requirements_agent/llm/__init__.py +3 -0
- package/dist/requirement-agent/requirements_agent/llm/base.py +49 -0
- package/dist/requirement-agent/requirements_agent/llm/copilot.py +171 -0
- package/dist/requirement-agent/requirements_agent/llm/mock.py +144 -0
- package/dist/requirement-agent/requirements_agent/llm/providers.py +277 -0
- package/dist/requirement-agent/requirements_agent/llm/router.py +35 -0
- package/dist/requirement-agent/requirements_agent/models.py +73 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/analyst.md +29 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/architect.md +28 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/bmad-orchestrator.md +26 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/dev.md +27 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/pm.md +27 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/po.md +27 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/qa.md +28 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/agents/sm.md +26 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-analyst.md +8 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-architect.md +11 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-dev.md +11 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-orchestrator.md +9 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-pm.md +9 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-po.md +10 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-qa.md +11 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/checklists/spec-circuit-sm.md +8 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/data/bmad-kb.md +19 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/data/requirements-standards-baseline.md +188 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/data/technical-preferences.md +54 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/utils/template-format.md +7 -0
- package/dist/requirement-agent/requirements_agent/packs/bmad-core-spec/workflows/greenfield-fullstack.yml +177 -0
- package/dist/requirement-agent/requirements_agent/pipeline/__init__.py +3 -0
- package/dist/requirement-agent/requirements_agent/pipeline/brd.py +86 -0
- package/dist/requirement-agent/requirements_agent/pipeline/pack.py +233 -0
- package/dist/requirement-agent/requirements_agent/pipeline/progress.py +60 -0
- package/dist/requirement-agent/requirements_agent/pipeline/prompts.py +150 -0
- package/dist/requirement-agent/requirements_agent/pipeline/quality.py +124 -0
- package/dist/requirement-agent/requirements_agent/pipeline/refine.py +386 -0
- package/dist/requirement-agent/requirements_agent/pipeline/sections.py +117 -0
- package/dist/requirement-agent/requirements_agent/pipeline/spec_circuit.py +142 -0
- package/dist/requirement-agent/requirements_agent/shell/__init__.py +7 -0
- package/dist/requirement-agent/requirements_agent/shell/actions.py +208 -0
- package/dist/requirement-agent/requirements_agent/shell/app.py +902 -0
- package/dist/requirement-agent/requirements_agent/shell/commands.py +206 -0
- package/dist/requirement-agent/requirements_agent/shell/progress_pane.py +114 -0
- package/dist/requirement-agent/requirements_agent/shell/ref_picker.py +59 -0
- package/dist/requirement-agent/requirements_agent/shell/refs.py +120 -0
- package/dist/requirement-agent/requirements_agent/shell/session.py +362 -0
- package/dist/requirement-agent/requirements_agent/shell/transcript.py +241 -0
- package/dist/requirement-agent/requirements_agent/shell/usage.py +64 -0
- package/dist/requirement-agent/requirements_agent/shell/usage_llm.py +64 -0
- package/dist/requirement-agent/requirements_agent/shell/worker.py +378 -0
- package/dist/requirement-agent/requirements_agent/tuios_hook.py +182 -0
- package/dist/requirement-agent/requirements_agent/webops.py +627 -0
- package/dist/template.html +67 -67
- package/dist/web/assets/{3d-force-graph-Df2wOlpF.js → 3d-force-graph-DDyP5jcf.js} +1 -1
- package/dist/web/assets/Agent-sLaNlaQo.js +8 -0
- package/dist/web/assets/AgentWork-Dv0G4bt3.js +2 -0
- package/dist/web/assets/ApiTests-Bnw2qgWw.js +15 -0
- package/dist/web/assets/Browse-CBt1JY2E.js +1 -0
- package/dist/web/assets/Chat-DIWdnIZK.js +3 -0
- package/dist/web/assets/CommandPalette-DD04oS83.js +1 -0
- package/dist/web/assets/Compare-D0Ao8dZ6.js +1 -0
- package/dist/web/assets/Cost-BY_8-9Qt.js +1 -0
- package/dist/web/assets/{Data-Be3ZNkUu.js → Data-BC7R_FbW.js} +4 -4
- package/dist/web/assets/Desktop-CSQ2xLg0.js +1 -0
- package/dist/web/assets/DesktopReview-CCOhUdeJ.js +2 -0
- package/dist/web/assets/DeviceScreen-BHmTd9Q-.js +1 -0
- package/dist/web/assets/Evidence-9W4pqIkC.js +1 -0
- package/dist/web/assets/{Explore-AtSStzNg.js → Explore-BndXiEf8.js} +2 -2
- package/dist/web/assets/Features-BrfsTC9Q.js +1 -0
- package/dist/web/assets/{Flags-GxmNrnSn.js → Flags-DyykkeHU.js} +2 -2
- package/dist/web/assets/Flaky-C3gj_Brn.js +1 -0
- package/dist/web/assets/Impact-Z8nbNhbe.js +3 -0
- package/dist/web/assets/Jobs-CJWXAqSy.js +5 -0
- package/dist/web/assets/KindPage-C45x_cFz.js +6 -0
- package/dist/web/assets/LiveDevice-DGdLDigO.js +1 -0
- package/dist/web/assets/Migration-QFI5ctp7.js +8 -0
- package/dist/web/assets/Mobile-CuswZyee.js +1 -0
- package/dist/web/assets/Observability-CknZ_xBN.js +1 -0
- package/dist/web/assets/PageAgent-B2bmmMaP.js +1 -0
- package/dist/web/assets/Product-CrtwDiMv.js +12 -0
- package/dist/web/assets/Production-BMsytC2i.js +1 -0
- package/dist/web/assets/Quality-B4Aw6N3_.js +1 -0
- package/dist/web/assets/Readiness-CVIzTFX-.js +1 -0
- package/dist/web/assets/Record-B2Ic8Taj.js +1 -0
- package/dist/web/assets/Regression-bCIAE3Ne.js +5 -0
- package/dist/web/assets/RelationGraph-kG4YVMzl.js +1 -0
- package/dist/web/assets/Reports-NAZ-26Ub.js +2 -0
- package/dist/web/assets/Requirements-BkpiF-Bt.js +2 -0
- package/dist/web/assets/Responsive-CsaoisJq.js +3 -0
- package/dist/web/assets/RunDiff-BC-3Wg1b.js +1 -0
- package/dist/web/assets/Settings-DyBed-J5.js +21 -0
- package/dist/web/assets/Steps-DcQxQ4yA.js +2 -0
- package/dist/web/assets/TestData-wpUeU9Er.js +2 -0
- package/dist/web/assets/TestManagement-D0njkyAT.js +4 -0
- package/dist/web/assets/WhatsNew-BxIAAwgH.js +1 -0
- package/dist/web/assets/agentSettingsSheet-BdB7IXah.js +1 -0
- package/dist/web/assets/choice-C4-yW2x9.js +1 -0
- package/dist/web/assets/code-Jek8uWUO.js +1 -0
- package/dist/web/assets/{coverage-DirEXtfZ.js → coverage-q-ib7wOq.js} +1 -1
- package/dist/web/assets/dataParts-B2-a-pOD.js +3 -0
- package/dist/web/assets/desktopAppPath-C-p0zU40.js +1 -0
- package/dist/web/assets/frame-CjpZWX_X.js +13 -0
- package/dist/web/assets/index-BH5RbDNY.css +2 -0
- package/dist/web/assets/index-CfGXe_De.js +55 -0
- package/dist/web/assets/line-icons-CwCZidXs.js +1 -0
- package/dist/web/assets/logos-P2LOMyTK.js +1 -0
- package/dist/web/assets/{markdown-BnrLv6Iw.js → markdown-dXSsS-mD.js} +5 -5
- package/dist/web/assets/nav-BZfNOkhX.js +1 -0
- package/dist/web/assets/pageBack-BwKT31j3.js +3 -0
- package/dist/web/assets/palette-L37b4wTE.js +1 -0
- package/dist/web/assets/{paletteCommands-LXIICD4V.js → paletteCommands-zqGCORJu.js} +1 -1
- package/dist/web/assets/parts-3o6HnCp1.js +1 -0
- package/dist/web/assets/preload-helper-BupTYkQW.js +1 -0
- package/dist/web/assets/productParts-BDiEg0z6.js +1 -0
- package/dist/web/assets/qualityParts--CnSadOZ.js +1 -0
- package/dist/web/assets/radio-BLI4Ubhk.js +1 -0
- package/dist/web/assets/react-BDur5s0O.js +1 -0
- package/dist/web/assets/{recordTest-BzKpS4m5.js → recordTest-D092f975.js} +1 -1
- package/dist/web/assets/route-oDy8sV6H.js +1 -0
- package/dist/web/assets/sectionList-XiKcJNEK.js +1 -0
- package/dist/web/assets/step-mark-CaKf4dAR.js +1 -0
- package/dist/web/assets/stepper-naqAN_Nb.js +1 -0
- package/dist/web/assets/utils-DJRAScIl.js +1 -0
- package/dist/web/assets/wizardParts-DLlOHVMx.js +1 -0
- package/dist/web/index.html +14 -12
- package/docs/user-guide.html +26 -0
- package/package.json +2 -1
- package/py/forgeqe_engine/cli.py +7 -0
- package/dist/web/assets/Agent-CRfgRnq2.js +0 -8
- package/dist/web/assets/AgentWork-DqiO3LUi.js +0 -2
- package/dist/web/assets/ApiTests-DCAnizu5.js +0 -15
- package/dist/web/assets/Browse-D5VDHN9Z.js +0 -1
- package/dist/web/assets/Chat-CLGQ1ymU.js +0 -3
- package/dist/web/assets/CommandPalette-D3F4iHrP.js +0 -1
- package/dist/web/assets/Compare-B1WN67Ny.js +0 -1
- package/dist/web/assets/Cost-Dk4m3r8z.js +0 -1
- package/dist/web/assets/Desktop-B3GcbaPu.js +0 -1
- package/dist/web/assets/DesktopReview-DfvAL3m8.js +0 -2
- package/dist/web/assets/DeviceScreen-DJqblqBh.js +0 -1
- package/dist/web/assets/Evidence-BsA7vCZG.js +0 -1
- package/dist/web/assets/Features-CDBlFLaJ.js +0 -1
- package/dist/web/assets/Flaky-C062Mh6z.js +0 -1
- package/dist/web/assets/Impact-BeXw3-oL.js +0 -3
- package/dist/web/assets/Jobs-QYWqmdDI.js +0 -5
- package/dist/web/assets/KindPage-C2g51s9c.js +0 -6
- package/dist/web/assets/LiveDevice-C9LRZMhC.js +0 -1
- package/dist/web/assets/Migration-ByUU0Oa_.js +0 -8
- package/dist/web/assets/Mobile-Dd3jL0Cn.js +0 -1
- package/dist/web/assets/Observability-Dx4ZCRDj.js +0 -1
- package/dist/web/assets/PageAgent-DYBOhs2x.js +0 -1
- package/dist/web/assets/Product-Ch1XAeAT.js +0 -12
- package/dist/web/assets/Production-TEdyFmo4.js +0 -1
- package/dist/web/assets/Quality-DH8EdI2u.js +0 -1
- package/dist/web/assets/Readiness-B8S7Ex0C.js +0 -1
- package/dist/web/assets/Record-uFQ-YaHg.js +0 -1
- package/dist/web/assets/Regression-CSDT2AnY.js +0 -5
- package/dist/web/assets/RelationGraph-gc0Xmklt.js +0 -1
- package/dist/web/assets/Reports-CSHhRfWv.js +0 -2
- package/dist/web/assets/Responsive-CEG1hbbQ.js +0 -3
- package/dist/web/assets/RunDiff-CHrMivzC.js +0 -1
- package/dist/web/assets/Settings-B63s0b1g.js +0 -21
- package/dist/web/assets/Steps-BsDjv-pm.js +0 -2
- package/dist/web/assets/TestData-CJoCXihI.js +0 -2
- package/dist/web/assets/TestManagement-Dkb-paWh.js +0 -4
- package/dist/web/assets/WhatsNew-Dtk9mJU4.js +0 -1
- package/dist/web/assets/agentSettingsSheet-BlM8KSpN.js +0 -1
- package/dist/web/assets/choice-CiFogD01.js +0 -1
- package/dist/web/assets/code-DzYywAs5.js +0 -1
- package/dist/web/assets/dataParts-Di7PdPHu.js +0 -3
- package/dist/web/assets/desktopAppPath-B8j1-pX0.js +0 -1
- package/dist/web/assets/frame-CNLw552P.js +0 -13
- package/dist/web/assets/index-DLuCgQKX.js +0 -55
- package/dist/web/assets/index-DRcPg81h.css +0 -2
- package/dist/web/assets/line-icons-B-O8oBsY.js +0 -1
- package/dist/web/assets/nav-Ds_6IERv.js +0 -1
- package/dist/web/assets/pageBack-DJxbEPfN.js +0 -3
- package/dist/web/assets/palette-H2g-hemT.js +0 -1
- package/dist/web/assets/parts-DKRLtrjs.js +0 -1
- package/dist/web/assets/preload-helper-BML5SvL4.js +0 -1
- package/dist/web/assets/productParts-imNtw-1N.js +0 -1
- package/dist/web/assets/qualityParts-DJhFlgCm.js +0 -1
- package/dist/web/assets/radio-CbR6ODxQ.js +0 -1
- package/dist/web/assets/route-DjewvmpL.js +0 -1
- package/dist/web/assets/sectionList-0umoKvRv.js +0 -1
- package/dist/web/assets/step-mark-g8Eb6foB.js +0 -1
- package/dist/web/assets/stepper-CzZIC36d.js +0 -1
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
import shutil
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any, Dict, List, Optional
|
|
8
|
+
|
|
9
|
+
from rich.markdown import Markdown
|
|
10
|
+
from rich.panel import Panel
|
|
11
|
+
from rich.prompt import Prompt
|
|
12
|
+
from rich.table import Table
|
|
13
|
+
|
|
14
|
+
from requirements_agent.agent import RequirementsAgent
|
|
15
|
+
from requirements_agent.console_ui import console
|
|
16
|
+
from requirements_agent.export.markdown import write_markdown
|
|
17
|
+
from requirements_agent.pipeline.sections import (
|
|
18
|
+
format_section_menu,
|
|
19
|
+
list_h2_sections,
|
|
20
|
+
resolve_section,
|
|
21
|
+
section_slice,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
HELP_TEXT = """
|
|
25
|
+
[bold]Chat with the Requirements Agent[/]
|
|
26
|
+
|
|
27
|
+
[cyan]Natural language[/] (with a section pinned, or @section in the message):
|
|
28
|
+
Add p95 latency < 300ms and owners
|
|
29
|
+
@8 Clarify acceptance signals
|
|
30
|
+
@Non-functional Add availability 99.9%
|
|
31
|
+
|
|
32
|
+
[cyan]Slash commands[/]
|
|
33
|
+
/sections List ## sections
|
|
34
|
+
/section <n|name> Pin a section for the next edits
|
|
35
|
+
/section clear Unpin (full-document refine)
|
|
36
|
+
/show [n|name] Preview a section (or pinned / doc head)
|
|
37
|
+
/docs List reference documents
|
|
38
|
+
/docs add <path> Attach a file or folder
|
|
39
|
+
/score Re-score quality
|
|
40
|
+
/questions Extract open questions
|
|
41
|
+
/status Session summary
|
|
42
|
+
/undo Restore previous document version
|
|
43
|
+
/save Force-save (auto-saves after each refine)
|
|
44
|
+
/help This help
|
|
45
|
+
/quit Exit chat
|
|
46
|
+
""".strip()
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@dataclass
|
|
50
|
+
class ChatSession:
|
|
51
|
+
agent: RequirementsAgent
|
|
52
|
+
title: str
|
|
53
|
+
design: str
|
|
54
|
+
report_path: Path
|
|
55
|
+
markdown: str
|
|
56
|
+
doc_paths: List[str] = field(default_factory=list)
|
|
57
|
+
pinned_section: Optional[str] = None # index or heading query
|
|
58
|
+
history: List[Dict[str, str]] = field(default_factory=list)
|
|
59
|
+
quality: Optional[Dict[str, Any]] = None
|
|
60
|
+
undo_stack: List[str] = field(default_factory=list)
|
|
61
|
+
max_undo: int = 8
|
|
62
|
+
|
|
63
|
+
def save(self) -> Path:
|
|
64
|
+
write_markdown(self.report_path, self.markdown)
|
|
65
|
+
# Kept in step with the report, for ForgeQE to write and trace test cases from.
|
|
66
|
+
try:
|
|
67
|
+
from requirements_agent.export.requirements_json import write_requirements_json
|
|
68
|
+
|
|
69
|
+
write_requirements_json(self.report_path, self.markdown)
|
|
70
|
+
except Exception:
|
|
71
|
+
pass
|
|
72
|
+
return self.report_path
|
|
73
|
+
|
|
74
|
+
def push_undo(self) -> None:
|
|
75
|
+
self.undo_stack.append(self.markdown)
|
|
76
|
+
if len(self.undo_stack) > self.max_undo:
|
|
77
|
+
self.undo_stack = self.undo_stack[-self.max_undo :]
|
|
78
|
+
|
|
79
|
+
def undo(self) -> bool:
|
|
80
|
+
if not self.undo_stack:
|
|
81
|
+
return False
|
|
82
|
+
self.markdown = self.undo_stack.pop()
|
|
83
|
+
self.save()
|
|
84
|
+
return True
|
|
85
|
+
|
|
86
|
+
def pinned_label(self) -> str:
|
|
87
|
+
if not self.pinned_section:
|
|
88
|
+
return "full document"
|
|
89
|
+
sec, _ = resolve_section(self.markdown, self.pinned_section)
|
|
90
|
+
if sec:
|
|
91
|
+
return f"[{sec.index}] {sec.heading}"
|
|
92
|
+
return f"(unresolved: {self.pinned_section})"
|
|
93
|
+
|
|
94
|
+
def rebuild_agent_with_docs(self) -> None:
|
|
95
|
+
"""Recreate agent so newly attached docs are in Memory context."""
|
|
96
|
+
from requirements_agent.llm.router import build_llm_client
|
|
97
|
+
|
|
98
|
+
cfg = self.agent.config
|
|
99
|
+
llm = build_llm_client(cfg.llm)
|
|
100
|
+
self.agent = RequirementsAgent(cfg, llm, extra_paths=list(self.doc_paths))
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
_AT_SECTION = re.compile(
|
|
104
|
+
r"^@(?P<ref>\d+|[\w][\w\s\-/&]+?)\s+(?P<body>.+)$",
|
|
105
|
+
re.IGNORECASE | re.DOTALL,
|
|
106
|
+
)
|
|
107
|
+
_IN_SECTION = re.compile(
|
|
108
|
+
r"(?:^|\b)(?:in|for|on|update|refine|focus(?:\s+on)?)\s+(?:section\s+)?(?P<ref>\d+|##\s*[^\n,:]+|[A-Za-z][\w\s\-/&]{2,40})\s*[:\-–—,]?\s*(?P<body>.+)$",
|
|
109
|
+
re.IGNORECASE | re.DOTALL,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def parse_chat_turn(text: str, pinned: Optional[str]) -> tuple[Optional[str], str]:
|
|
114
|
+
"""Return (section_query_or_None, instruction)."""
|
|
115
|
+
raw = (text or "").strip()
|
|
116
|
+
if not raw:
|
|
117
|
+
return pinned, ""
|
|
118
|
+
|
|
119
|
+
m = _AT_SECTION.match(raw)
|
|
120
|
+
if m:
|
|
121
|
+
return m.group("ref").strip(), m.group("body").strip()
|
|
122
|
+
|
|
123
|
+
m = _IN_SECTION.match(raw)
|
|
124
|
+
if m:
|
|
125
|
+
ref = m.group("ref").strip()
|
|
126
|
+
if ref.startswith("##"):
|
|
127
|
+
ref = ref[2:].strip()
|
|
128
|
+
body = m.group("body").strip()
|
|
129
|
+
# Avoid false positives like "in scope for v1 add ..." when no real section match —
|
|
130
|
+
# caller still resolves; if resolve fails we fall back to pinned/full.
|
|
131
|
+
return ref, body
|
|
132
|
+
|
|
133
|
+
return pinned, raw
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _print_sections(md: str) -> None:
|
|
137
|
+
secs = list_h2_sections(md)
|
|
138
|
+
console.print(Panel(format_section_menu(secs) or "(no ## sections)", title="Sections", border_style="cyan"))
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _print_preview(md: str, section_q: Optional[str] = None, *, title: str = "Preview") -> None:
|
|
142
|
+
if section_q:
|
|
143
|
+
sec, _ = resolve_section(md, section_q)
|
|
144
|
+
if sec:
|
|
145
|
+
console.print(
|
|
146
|
+
Panel(
|
|
147
|
+
Markdown(section_slice(md, sec)[:3000]),
|
|
148
|
+
title=f"{title} · [{sec.index}] {sec.heading}",
|
|
149
|
+
border_style="green",
|
|
150
|
+
)
|
|
151
|
+
)
|
|
152
|
+
return
|
|
153
|
+
lines = md.splitlines()[:35]
|
|
154
|
+
console.print(Panel(Markdown("\n".join(lines)), title=f"{title} · document head", border_style="dim"))
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _print_status(session: ChatSession) -> None:
|
|
158
|
+
t = Table(show_header=False, box=None, padding=(0, 1))
|
|
159
|
+
t.add_column("k", style="dim")
|
|
160
|
+
t.add_column("v")
|
|
161
|
+
t.add_row("Title", session.title)
|
|
162
|
+
t.add_row("Report", str(session.report_path))
|
|
163
|
+
t.add_row("Pinned", session.pinned_label())
|
|
164
|
+
t.add_row("Docs", str(len(session.doc_paths)) + (" — " + ", ".join(Path(p).name for p in session.doc_paths[:5]) if session.doc_paths else ""))
|
|
165
|
+
if session.quality:
|
|
166
|
+
t.add_row("Quality", f"{session.quality.get('overall_score', '?')}/100")
|
|
167
|
+
t.add_row("Undo", f"{len(session.undo_stack)} version(s)")
|
|
168
|
+
console.print(Panel(t, title="Session", border_style="magenta"))
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def run_chat_session(session: ChatSession) -> None:
|
|
172
|
+
console.print(
|
|
173
|
+
Panel(
|
|
174
|
+
f"[bold]{session.title}[/]\n"
|
|
175
|
+
f"Report: {session.report_path}\n"
|
|
176
|
+
f"Pinned: [cyan]{session.pinned_label()}[/]\n"
|
|
177
|
+
f"Docs: {len(session.doc_paths)}\n\n"
|
|
178
|
+
"Type [bold]/help[/] for commands. Pin a section with [bold]/section 8[/], then just type what to change.",
|
|
179
|
+
title="Requirements Agent · chat",
|
|
180
|
+
border_style="cyan",
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
_print_sections(session.markdown)
|
|
184
|
+
|
|
185
|
+
while True:
|
|
186
|
+
try:
|
|
187
|
+
pin = session.pinned_label()
|
|
188
|
+
line = Prompt.ask(f"[bold cyan]ba[/] [dim]({pin})[/]").strip()
|
|
189
|
+
except (EOFError, KeyboardInterrupt):
|
|
190
|
+
console.print("\n[dim]Bye — document saved.[/]")
|
|
191
|
+
session.save()
|
|
192
|
+
break
|
|
193
|
+
|
|
194
|
+
if not line:
|
|
195
|
+
continue
|
|
196
|
+
|
|
197
|
+
# Slash commands
|
|
198
|
+
if line.startswith("/"):
|
|
199
|
+
handled = _handle_command(session, line)
|
|
200
|
+
if handled == "quit":
|
|
201
|
+
session.save()
|
|
202
|
+
console.print(f"[green]Saved[/] {session.report_path}")
|
|
203
|
+
break
|
|
204
|
+
continue
|
|
205
|
+
|
|
206
|
+
# Natural language refine turn
|
|
207
|
+
section_q, instruction = parse_chat_turn(line, session.pinned_section)
|
|
208
|
+
if not instruction:
|
|
209
|
+
console.print("[yellow]Empty instruction — try again or /help[/]")
|
|
210
|
+
continue
|
|
211
|
+
|
|
212
|
+
# If section_q was inferred from "in X …" but doesn't resolve, fall back
|
|
213
|
+
if section_q and section_q != session.pinned_section:
|
|
214
|
+
sec, _ = resolve_section(session.markdown, section_q)
|
|
215
|
+
if sec is None:
|
|
216
|
+
# Maybe false positive from "in scope for…" — use pinned / full
|
|
217
|
+
section_q = session.pinned_section
|
|
218
|
+
|
|
219
|
+
target_label = "full document"
|
|
220
|
+
if section_q:
|
|
221
|
+
sec, _ = resolve_section(session.markdown, section_q)
|
|
222
|
+
if sec:
|
|
223
|
+
target_label = f"[{sec.index}] {sec.heading}"
|
|
224
|
+
else:
|
|
225
|
+
console.print(f"[red]Section not found:[/] {section_q}")
|
|
226
|
+
_print_sections(session.markdown)
|
|
227
|
+
continue
|
|
228
|
+
|
|
229
|
+
console.print(f"[dim]Refining {target_label}…[/]")
|
|
230
|
+
session.push_undo()
|
|
231
|
+
result = session.agent.refine(
|
|
232
|
+
session.title,
|
|
233
|
+
session.design,
|
|
234
|
+
session.markdown,
|
|
235
|
+
instruction,
|
|
236
|
+
history=session.history,
|
|
237
|
+
section=section_q,
|
|
238
|
+
)
|
|
239
|
+
if not result.get("success"):
|
|
240
|
+
session.undo_stack.pop() # discard empty undo
|
|
241
|
+
console.print(f"[red]{result.get('error')}[/red]")
|
|
242
|
+
continue
|
|
243
|
+
|
|
244
|
+
session.markdown = result["report_markdown"]
|
|
245
|
+
session.history.append({"role": "user", "content": instruction})
|
|
246
|
+
session.history.append(
|
|
247
|
+
{"role": "assistant", "content": result.get("assistant_message") or "updated"}
|
|
248
|
+
)
|
|
249
|
+
session.save()
|
|
250
|
+
|
|
251
|
+
console.print(
|
|
252
|
+
Panel(
|
|
253
|
+
f"[bold green]Updated immediately[/] → {session.report_path.name}\n"
|
|
254
|
+
f"{result.get('assistant_message') or ''}",
|
|
255
|
+
border_style="green",
|
|
256
|
+
)
|
|
257
|
+
)
|
|
258
|
+
preview_q = str((result.get("section") or {}).get("index") or section_q or "")
|
|
259
|
+
_print_preview(session.markdown, preview_q or None, title="Updated")
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _handle_command(session: ChatSession, line: str) -> Optional[str]:
|
|
263
|
+
parts = line.strip().split(maxsplit=2)
|
|
264
|
+
cmd = parts[0].lower()
|
|
265
|
+
arg = parts[1] if len(parts) > 1 else ""
|
|
266
|
+
rest = parts[2] if len(parts) > 2 else ""
|
|
267
|
+
|
|
268
|
+
if cmd in ("/quit", "/exit", "/q"):
|
|
269
|
+
return "quit"
|
|
270
|
+
|
|
271
|
+
if cmd in ("/help", "/h", "/?"):
|
|
272
|
+
console.print(Panel(HELP_TEXT, title="Help", border_style="cyan"))
|
|
273
|
+
return None
|
|
274
|
+
|
|
275
|
+
if cmd in ("/sections", "/ls"):
|
|
276
|
+
_print_sections(session.markdown)
|
|
277
|
+
return None
|
|
278
|
+
|
|
279
|
+
if cmd in ("/section", "/pin"):
|
|
280
|
+
if not arg or arg.lower() in ("clear", "none", "full", "-"):
|
|
281
|
+
session.pinned_section = None
|
|
282
|
+
console.print("[dim]Pinned:[/] full document")
|
|
283
|
+
return None
|
|
284
|
+
query = f"{arg} {rest}".strip() if rest else arg
|
|
285
|
+
sec, _ = resolve_section(session.markdown, query)
|
|
286
|
+
if not sec:
|
|
287
|
+
console.print(f"[red]Section not found:[/] {query}")
|
|
288
|
+
_print_sections(session.markdown)
|
|
289
|
+
return None
|
|
290
|
+
session.pinned_section = str(sec.index)
|
|
291
|
+
console.print(f"[green]Pinned[/] [{sec.index}] {sec.heading}")
|
|
292
|
+
_print_preview(session.markdown, str(sec.index), title="Pinned section")
|
|
293
|
+
return None
|
|
294
|
+
|
|
295
|
+
if cmd == "/show":
|
|
296
|
+
q = f"{arg} {rest}".strip() if arg else session.pinned_section
|
|
297
|
+
_print_preview(session.markdown, q, title="Show")
|
|
298
|
+
return None
|
|
299
|
+
|
|
300
|
+
if cmd == "/docs":
|
|
301
|
+
if arg.lower() == "add":
|
|
302
|
+
path = (rest or "").strip() or Prompt.ask("Path to file or folder").strip()
|
|
303
|
+
if not path:
|
|
304
|
+
return None
|
|
305
|
+
p = Path(path).expanduser().resolve()
|
|
306
|
+
if not p.exists():
|
|
307
|
+
console.print(f"[red]Not found:[/] {p}")
|
|
308
|
+
return None
|
|
309
|
+
session.doc_paths.append(str(p))
|
|
310
|
+
session.rebuild_agent_with_docs()
|
|
311
|
+
console.print(f"[green]Attached[/] {p} ({len(session.doc_paths)} doc path(s))")
|
|
312
|
+
return None
|
|
313
|
+
if not session.doc_paths:
|
|
314
|
+
console.print("[dim]No reference documents attached. Use /docs add <path>[/]")
|
|
315
|
+
return None
|
|
316
|
+
for i, d in enumerate(session.doc_paths, 1):
|
|
317
|
+
console.print(f" {i}. {d}")
|
|
318
|
+
return None
|
|
319
|
+
|
|
320
|
+
if cmd == "/score":
|
|
321
|
+
console.print("[dim]Scoring…[/]")
|
|
322
|
+
q = session.agent.score(session.title, session.design, session.markdown)
|
|
323
|
+
session.quality = {
|
|
324
|
+
"overall_score": q.overall_score,
|
|
325
|
+
"dimensions": q.dimensions,
|
|
326
|
+
"rationale": q.rationale,
|
|
327
|
+
"top_gaps": q.top_gaps,
|
|
328
|
+
"success": q.success,
|
|
329
|
+
}
|
|
330
|
+
gaps = "\n".join(f"- {g}" for g in (q.top_gaps or [])[:5]) or "_none_"
|
|
331
|
+
console.print(
|
|
332
|
+
Panel(
|
|
333
|
+
f"[bold]{q.overall_score}/100[/]\n\n{q.rationale or ''}\n\n### Top gaps\n{gaps}",
|
|
334
|
+
title="Quality",
|
|
335
|
+
border_style="magenta",
|
|
336
|
+
)
|
|
337
|
+
)
|
|
338
|
+
# Persist score next to report if possible
|
|
339
|
+
score_path = session.report_path.parent / "quality-score.json"
|
|
340
|
+
try:
|
|
341
|
+
from requirements_agent.export.markdown import write_json
|
|
342
|
+
|
|
343
|
+
write_json(score_path, session.quality)
|
|
344
|
+
except Exception:
|
|
345
|
+
pass
|
|
346
|
+
return None
|
|
347
|
+
|
|
348
|
+
if cmd == "/questions":
|
|
349
|
+
console.print("[dim]Extracting open questions…[/]")
|
|
350
|
+
result = session.agent.questions(session.title, session.design, session.markdown)
|
|
351
|
+
if not result.get("success"):
|
|
352
|
+
console.print(f"[red]{result.get('error')}[/red]")
|
|
353
|
+
return None
|
|
354
|
+
lines = []
|
|
355
|
+
for cat in result.get("categories") or []:
|
|
356
|
+
lines.append(f"### {cat.get('title')}")
|
|
357
|
+
for q in cat.get("questions") or []:
|
|
358
|
+
lines.append(f"- {q}")
|
|
359
|
+
lines.append("")
|
|
360
|
+
console.print(Panel(Markdown("\n".join(lines) or "_none_"), title="Open questions", border_style="yellow"))
|
|
361
|
+
qpath = session.report_path.parent / "open-questions.json"
|
|
362
|
+
try:
|
|
363
|
+
from requirements_agent.export.markdown import write_json
|
|
364
|
+
|
|
365
|
+
write_json(qpath, result)
|
|
366
|
+
except Exception:
|
|
367
|
+
pass
|
|
368
|
+
return None
|
|
369
|
+
|
|
370
|
+
if cmd == "/status":
|
|
371
|
+
_print_status(session)
|
|
372
|
+
return None
|
|
373
|
+
|
|
374
|
+
if cmd == "/undo":
|
|
375
|
+
if session.undo():
|
|
376
|
+
console.print(f"[green]Restored previous version →[/] {session.report_path.name}")
|
|
377
|
+
_print_preview(session.markdown, session.pinned_section, title="After undo")
|
|
378
|
+
else:
|
|
379
|
+
console.print("[yellow]Nothing to undo[/]")
|
|
380
|
+
return None
|
|
381
|
+
|
|
382
|
+
if cmd == "/save":
|
|
383
|
+
session.save()
|
|
384
|
+
console.print(f"[green]Saved[/] {session.report_path}")
|
|
385
|
+
return None
|
|
386
|
+
|
|
387
|
+
console.print(f"[yellow]Unknown command[/] {cmd} — try /help")
|
|
388
|
+
return None
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def bootstrap_chat(
|
|
392
|
+
*,
|
|
393
|
+
agent: RequirementsAgent,
|
|
394
|
+
title: str,
|
|
395
|
+
design: str,
|
|
396
|
+
report: Path,
|
|
397
|
+
docs: Optional[List[Path]] = None,
|
|
398
|
+
pin: Optional[str] = None,
|
|
399
|
+
) -> ChatSession:
|
|
400
|
+
report = report.expanduser().resolve()
|
|
401
|
+
if not report.is_file():
|
|
402
|
+
raise FileNotFoundError(f"Report not found: {report}")
|
|
403
|
+
# Keep a .bak once per chat start
|
|
404
|
+
bak = report.with_suffix(report.suffix + ".bak")
|
|
405
|
+
if not bak.exists():
|
|
406
|
+
shutil.copy2(report, bak)
|
|
407
|
+
|
|
408
|
+
doc_paths = [str(p.expanduser().resolve()) for p in (docs or [])]
|
|
409
|
+
session = ChatSession(
|
|
410
|
+
agent=agent,
|
|
411
|
+
title=title,
|
|
412
|
+
design=design,
|
|
413
|
+
report_path=report,
|
|
414
|
+
markdown=report.read_text(encoding="utf-8"),
|
|
415
|
+
doc_paths=doc_paths,
|
|
416
|
+
pinned_section=None,
|
|
417
|
+
)
|
|
418
|
+
if doc_paths:
|
|
419
|
+
session.rebuild_agent_with_docs()
|
|
420
|
+
if pin:
|
|
421
|
+
sec, _ = resolve_section(session.markdown, pin)
|
|
422
|
+
if sec:
|
|
423
|
+
session.pinned_section = str(sec.index)
|
|
424
|
+
return session
|