@capagents/forgeqe 3.3.1 → 3.3.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.
- package/HOW_TO_USE.md +337 -8
- package/dist/docs-site/docs/area-operations/index.html +126 -2
- package/dist/docs-site/docs/area-quality/index.html +159 -3
- 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/overview/index.html +2 -2
- package/dist/docs-site/docs/search.js +1 -1
- package/dist/forgeqe.js +2159 -1928
- 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-KUdc_88B.js} +3 -3
- package/dist/web/assets/Agent-Bd54dLhD.js +10 -0
- package/dist/web/assets/AgentWork-CqMhsFBP.js +2 -0
- package/dist/web/assets/ApiTests-BO_sKAg8.js +15 -0
- package/dist/web/assets/Browse-BjPPdirz.js +1 -0
- package/dist/web/assets/Chat-DO-UvDWX.js +3 -0
- package/dist/web/assets/CommandPalette-BBGtkkz4.js +1 -0
- package/dist/web/assets/Compare-BFuLcrBB.js +1 -0
- package/dist/web/assets/Cost-DbKrBm9m.js +1 -0
- package/dist/web/assets/{Data-Be3ZNkUu.js → Data-B6_6Rm7C.js} +4 -4
- package/dist/web/assets/Desktop-CnBxMp68.js +1 -0
- package/dist/web/assets/DesktopReview-DVITz4Jv.js +2 -0
- package/dist/web/assets/DeviceScreen-BHmTd9Q-.js +1 -0
- package/dist/web/assets/Evidence-BZx9UF1t.js +1 -0
- package/dist/web/assets/{Explore-AtSStzNg.js → Explore-Kkl9koqy.js} +2 -2
- package/dist/web/assets/Features-_WrrIGBz.js +1 -0
- package/dist/web/assets/{Flags-GxmNrnSn.js → Flags-BGqG09qD.js} +2 -2
- package/dist/web/assets/Flaky-B7mr96H8.js +1 -0
- package/dist/web/assets/Impact-DzAtWie1.js +3 -0
- package/dist/web/assets/Jobs-YSmfG7C9.js +5 -0
- package/dist/web/assets/KindPage-UqU2qh63.js +6 -0
- package/dist/web/assets/LiveDevice-jFCQ_zeU.js +1 -0
- package/dist/web/assets/Migration-CfHZeobD.js +8 -0
- package/dist/web/assets/Mobile-DTMPjWeO.js +1 -0
- package/dist/web/assets/Observability-B-9cikxK.js +1 -0
- package/dist/web/assets/OwnItems-BC9M20At.js +5 -0
- package/dist/web/assets/PageAgent-CvV8gwuP.js +1 -0
- package/dist/web/assets/Product-lDXsflpD.js +6 -0
- package/dist/web/assets/Production-BHXWX-ww.js +1 -0
- package/dist/web/assets/Quality-Bsljiu_v.js +1 -0
- package/dist/web/assets/Readiness-BZppEirK.js +1 -0
- package/dist/web/assets/Record-7h0EFEiJ.js +1 -0
- package/dist/web/assets/Regression-DdM66t2E.js +5 -0
- package/dist/web/assets/RelationGraph-CBY9FhUu.js +1 -0
- package/dist/web/assets/Reports-u72R1XBV.js +2 -0
- package/dist/web/assets/Requirements-BAcEi5Fl.js +2 -0
- package/dist/web/assets/Responsive-CCPzSbdd.js +3 -0
- package/dist/web/assets/RunDiff-CGhLqPpP.js +1 -0
- package/dist/web/assets/Settings-DDCiQZ0T.js +21 -0
- package/dist/web/assets/Steps-sfVkdv7g.js +2 -0
- package/dist/web/assets/TestData-B4-xVlvt.js +2 -0
- package/dist/web/assets/TestManagement-BGBKGV1L.js +4 -0
- package/dist/web/assets/WhatsNew-BMTuBbaX.js +1 -0
- package/dist/web/assets/agentSettingsSheet-Cc2W6lyp.js +1 -0
- package/dist/web/assets/api-BsiuHmJq.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-pqIlfEP0.js} +1 -1
- package/dist/web/assets/dataParts-CkwgLllh.js +3 -0
- package/dist/web/assets/desktopAppPath-D3mGDKPz.js +1 -0
- package/dist/web/assets/flowTheme-DKuXe5nP.js +7 -0
- package/dist/web/assets/frame-BMpSUo2-.js +13 -0
- package/dist/web/assets/index-6SZomYE0.js +55 -0
- package/dist/web/assets/index-CWqwtFKz.css +2 -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-1wY7hIbM.js} +5 -5
- package/dist/web/assets/nav-B_68FVw_.js +1 -0
- package/dist/web/assets/pageBack-CbyKfisx.js +3 -0
- package/dist/web/assets/palette-6YAAmgkD.js +1 -0
- package/dist/web/assets/{paletteCommands-LXIICD4V.js → paletteCommands-Isq1rLs-.js} +1 -1
- package/dist/web/assets/parts-ClnDV-6r.js +1 -0
- package/dist/web/assets/preload-helper-BupTYkQW.js +1 -0
- package/dist/web/assets/productParts-D18glCBr.js +1 -0
- package/dist/web/assets/qualityParts-1F1Ee4Ay.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-7uIZiqOW.js} +1 -1
- package/dist/web/assets/route-oDy8sV6H.js +1 -0
- package/dist/web/assets/sectionList-B651VPon.js +1 -0
- package/dist/web/assets/step-mark-CaKf4dAR.js +1 -0
- package/dist/web/assets/stepper-DdgwJtbU.js +1 -0
- package/dist/web/assets/utils-DJRAScIl.js +1 -0
- package/dist/web/assets/wizardParts-C0cNmIK9.js +1 -0
- package/dist/web/index.html +15 -13
- package/docs/user-guide.html +309 -3
- package/evals/prompts/perf-report/limit-broken.yaml +28 -0
- package/evals/prompts/perf-report/regression-other-load.yaml +28 -0
- package/forgeqe.example.yaml +10 -0
- package/package.json +2 -1
- package/prompts/README.md +4 -0
- package/prompts/brain.md +17 -0
- package/prompts/perf-report.md +41 -0
- package/prompts/perf-strategy.md +45 -0
- package/prompts/perf.md +45 -0
- package/prompts/team-builder.md +50 -0
- 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/api-6pHfHEgB.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
- /package/dist/web/assets/{Product-DLioOiRN.css → flowTheme-DLioOiRN.css} +0 -0
|
@@ -0,0 +1,902 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import threading
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import List, Optional
|
|
6
|
+
|
|
7
|
+
from textual.app import App, ComposeResult
|
|
8
|
+
from textual.binding import Binding
|
|
9
|
+
from textual.containers import Horizontal, Vertical
|
|
10
|
+
from textual.timer import Timer
|
|
11
|
+
from textual.widgets import Input, Static
|
|
12
|
+
|
|
13
|
+
from requirements_agent.chat_session import parse_chat_turn
|
|
14
|
+
from requirements_agent.config import AppConfig, load_config
|
|
15
|
+
from requirements_agent.pipeline.sections import format_section_menu, list_h2_sections, resolve_section
|
|
16
|
+
from requirements_agent.shell.actions import (
|
|
17
|
+
build_fix_instruction,
|
|
18
|
+
get_fix_item,
|
|
19
|
+
list_fix_items,
|
|
20
|
+
map_item_to_section,
|
|
21
|
+
parse_fix_args,
|
|
22
|
+
)
|
|
23
|
+
from requirements_agent.shell.commands import (
|
|
24
|
+
ref_token,
|
|
25
|
+
HELP,
|
|
26
|
+
is_url,
|
|
27
|
+
looks_like_path,
|
|
28
|
+
parse_input,
|
|
29
|
+
path_completions,
|
|
30
|
+
split_report_format,
|
|
31
|
+
)
|
|
32
|
+
from requirements_agent.shell.progress_pane import ProgressPane
|
|
33
|
+
from requirements_agent.shell.ref_picker import RefPickerScreen
|
|
34
|
+
from requirements_agent.shell.refs import add_git_ref, add_path_ref, add_url_ref, add_workspace_ref
|
|
35
|
+
from requirements_agent.shell.session import ShellSession
|
|
36
|
+
from requirements_agent.shell.transcript import Transcript
|
|
37
|
+
from requirements_agent.shell.worker import ShellWorker
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _clip_line(text: str, n: int = 100) -> str:
|
|
41
|
+
s = (text or "").replace("\n", " ").strip()
|
|
42
|
+
return s if len(s) <= n else s[: n - 1] + "…"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _fix_items_payload(session: ShellSession) -> List[dict]:
|
|
46
|
+
return [
|
|
47
|
+
{
|
|
48
|
+
"index": i.index,
|
|
49
|
+
"kind": i.kind,
|
|
50
|
+
"category": i.category,
|
|
51
|
+
"text": i.text,
|
|
52
|
+
}
|
|
53
|
+
for i in list_fix_items(session)
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class ShellHeader(Static):
|
|
58
|
+
def __init__(self, *args, **kwargs) -> None:
|
|
59
|
+
kwargs.setdefault("markup", True)
|
|
60
|
+
super().__init__(*args, **kwargs)
|
|
61
|
+
|
|
62
|
+
def refresh_from(self, session: ShellSession) -> None:
|
|
63
|
+
status = session.status
|
|
64
|
+
if session.awaiting_confirm:
|
|
65
|
+
status = "confirm"
|
|
66
|
+
elif session.ui_mode == "done" and status == "idle":
|
|
67
|
+
status = "done"
|
|
68
|
+
elif session.ui_mode == "refine" and status == "idle":
|
|
69
|
+
status = "refine"
|
|
70
|
+
color = {
|
|
71
|
+
"idle": "dim",
|
|
72
|
+
"analyzing": "yellow",
|
|
73
|
+
"refining": "yellow",
|
|
74
|
+
"reporting": "yellow",
|
|
75
|
+
"refine": "cyan",
|
|
76
|
+
"confirm": "magenta",
|
|
77
|
+
"done": "green",
|
|
78
|
+
"stopped": "red",
|
|
79
|
+
}.get(status, "white")
|
|
80
|
+
usage = session.usage_label()
|
|
81
|
+
hint = "[red]/stop[/]" if status in ("analyzing", "refining", "reporting", "working") else "[dim]/exit[/]"
|
|
82
|
+
self.update(
|
|
83
|
+
f"[bold]◉ Requirements Agent[/] "
|
|
84
|
+
f"[{color}]● {status}[/] {session.elapsed_label()} "
|
|
85
|
+
f"[dim]{usage}[/] {hint}"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class Completions(Static):
|
|
90
|
+
"""Inline path completions under the input."""
|
|
91
|
+
|
|
92
|
+
def show(self, items: List[str]) -> None:
|
|
93
|
+
if not items:
|
|
94
|
+
self.update("")
|
|
95
|
+
return
|
|
96
|
+
self.update(" ".join(items[:8]))
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class RequirementsShell(App):
|
|
100
|
+
TITLE = "Requirements Agent"
|
|
101
|
+
BINDINGS = [
|
|
102
|
+
Binding("ctrl+c", "quit", "Quit", show=False),
|
|
103
|
+
Binding("ctrl+q", "quit", "Quit", show=False),
|
|
104
|
+
Binding("ctrl+s", "stop_run", "Stop", show=False),
|
|
105
|
+
Binding("escape", "focus_input", "Input", show=False),
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
CSS = """
|
|
109
|
+
/* Open flow in the terminal — avoid nested “app box” panels */
|
|
110
|
+
Screen {
|
|
111
|
+
background: transparent;
|
|
112
|
+
color: #e6edf3;
|
|
113
|
+
padding: 1 1 0 1;
|
|
114
|
+
}
|
|
115
|
+
#header {
|
|
116
|
+
dock: top;
|
|
117
|
+
height: 2;
|
|
118
|
+
padding: 1 1 0 1;
|
|
119
|
+
background: transparent;
|
|
120
|
+
border: none;
|
|
121
|
+
}
|
|
122
|
+
#body {
|
|
123
|
+
height: 1fr;
|
|
124
|
+
layout: horizontal;
|
|
125
|
+
background: transparent;
|
|
126
|
+
border: none;
|
|
127
|
+
}
|
|
128
|
+
#chat-pane {
|
|
129
|
+
width: 3fr;
|
|
130
|
+
min-width: 40;
|
|
131
|
+
padding: 0 1 0 0;
|
|
132
|
+
background: transparent;
|
|
133
|
+
border: none;
|
|
134
|
+
}
|
|
135
|
+
#progress-pane {
|
|
136
|
+
width: 2fr;
|
|
137
|
+
min-width: 36;
|
|
138
|
+
height: 1fr;
|
|
139
|
+
padding: 0 0 0 2;
|
|
140
|
+
background: transparent;
|
|
141
|
+
border-left: tall #30363d;
|
|
142
|
+
layout: vertical;
|
|
143
|
+
}
|
|
144
|
+
#live-scroll {
|
|
145
|
+
height: 1fr;
|
|
146
|
+
min-height: 10;
|
|
147
|
+
width: 100%;
|
|
148
|
+
padding: 0;
|
|
149
|
+
margin: 0;
|
|
150
|
+
scrollbar-size-vertical: 1;
|
|
151
|
+
}
|
|
152
|
+
.live-block {
|
|
153
|
+
width: 100%;
|
|
154
|
+
height: auto;
|
|
155
|
+
min-height: 1;
|
|
156
|
+
padding: 0;
|
|
157
|
+
margin: 0;
|
|
158
|
+
color: #8b949e;
|
|
159
|
+
text-wrap: wrap;
|
|
160
|
+
}
|
|
161
|
+
#personas-block, #stages-block, #stats-line, #progress-line {
|
|
162
|
+
width: 100%;
|
|
163
|
+
height: auto;
|
|
164
|
+
}
|
|
165
|
+
.chat-md { width: 100%; padding: 0 0 0 0; }
|
|
166
|
+
.chat-line { height: auto; margin: 0 0 1 0; padding: 0; width: 100%; }
|
|
167
|
+
#input-dock {
|
|
168
|
+
dock: bottom;
|
|
169
|
+
height: auto;
|
|
170
|
+
padding: 1 0 0 0;
|
|
171
|
+
background: transparent;
|
|
172
|
+
border-top: none;
|
|
173
|
+
border: none;
|
|
174
|
+
}
|
|
175
|
+
#composer {
|
|
176
|
+
width: 1fr;
|
|
177
|
+
background: transparent;
|
|
178
|
+
border: tall #388bfd;
|
|
179
|
+
padding: 0 1;
|
|
180
|
+
}
|
|
181
|
+
#composer:focus {
|
|
182
|
+
border: tall #58a6ff;
|
|
183
|
+
}
|
|
184
|
+
#completions { color: #8b949e; height: 1; padding: 0 1; }
|
|
185
|
+
#footer-stats { color: #8b949e; height: 1; padding: 0 1; }
|
|
186
|
+
#transcript {
|
|
187
|
+
height: 1fr;
|
|
188
|
+
padding: 0;
|
|
189
|
+
background: transparent;
|
|
190
|
+
border: none;
|
|
191
|
+
scrollbar-size-vertical: 1;
|
|
192
|
+
}
|
|
193
|
+
.chat-error { color: #ff7b72; }
|
|
194
|
+
.soft-line { height: auto; margin: 0; }
|
|
195
|
+
.steps-block { height: auto; margin: 0 0 1 0; }
|
|
196
|
+
.finding-line { height: auto; margin: 0; width: 100%; }
|
|
197
|
+
.board-block { height: auto; margin: 0 0 1 0; padding: 0; color: #8b949e; width: 100%; }
|
|
198
|
+
.board-preview { color: #e6edf3; }
|
|
199
|
+
.board-sections { color: #e6edf3; }
|
|
200
|
+
.board-questions { color: #e6edf3; }
|
|
201
|
+
.board-files { color: #7ee787; }
|
|
202
|
+
.board-tip { color: #8b949e; }
|
|
203
|
+
#prog-title, #stages-title, #mid-title, #live-title { height: 1; margin-top: 1; }
|
|
204
|
+
ProgressBar { margin: 0; height: 1; }
|
|
205
|
+
Input { border: tall #388bfd; background: transparent; }
|
|
206
|
+
Input:focus { border: tall #58a6ff; }
|
|
207
|
+
"""
|
|
208
|
+
|
|
209
|
+
def __init__(
|
|
210
|
+
self,
|
|
211
|
+
session: ShellSession,
|
|
212
|
+
*,
|
|
213
|
+
autostart_analyse: bool = False,
|
|
214
|
+
analyse_focus: str = "",
|
|
215
|
+
):
|
|
216
|
+
super().__init__()
|
|
217
|
+
self.session = session
|
|
218
|
+
self.worker = ShellWorker(session, on_ui=self._on_worker_ui)
|
|
219
|
+
self.autostart_analyse = autostart_analyse
|
|
220
|
+
self.analyse_focus = analyse_focus
|
|
221
|
+
self._timer: Optional[Timer] = None
|
|
222
|
+
|
|
223
|
+
def compose(self) -> ComposeResult:
|
|
224
|
+
yield ShellHeader(id="header")
|
|
225
|
+
with Horizontal(id="body"):
|
|
226
|
+
with Vertical(id="chat-pane"):
|
|
227
|
+
yield Transcript(id="transcript")
|
|
228
|
+
yield ProgressPane(id="progress-pane")
|
|
229
|
+
with Vertical(id="input-dock"):
|
|
230
|
+
yield Static("", id="footer-stats")
|
|
231
|
+
yield Completions(id="completions")
|
|
232
|
+
yield Input(
|
|
233
|
+
placeholder="› message · /stop cancel run · /exit leave",
|
|
234
|
+
id="composer",
|
|
235
|
+
)
|
|
236
|
+
# No Footer — the Keys palette was confusing and ate space
|
|
237
|
+
|
|
238
|
+
def on_mount(self) -> None:
|
|
239
|
+
self.query_one("#composer", Input).focus()
|
|
240
|
+
self._refresh_chrome()
|
|
241
|
+
tr = self.query_one("#transcript", Transcript)
|
|
242
|
+
if self.session.active_doc():
|
|
243
|
+
self.session.load_open_questions_file()
|
|
244
|
+
self.session.enter_refine_mode()
|
|
245
|
+
tr.add_agent(
|
|
246
|
+
f"Loaded report ({len(self.session.active_doc()):,} chars).\n"
|
|
247
|
+
"Refine with `/fix N`, plain language, or /section N. /exit to leave."
|
|
248
|
+
)
|
|
249
|
+
tr.show_refine_board(
|
|
250
|
+
sections=self.session.section_outline(),
|
|
251
|
+
questions=list(self.session.open_questions),
|
|
252
|
+
fix_items=_fix_items_payload(self.session),
|
|
253
|
+
quality=self.session.quality or {},
|
|
254
|
+
out_dir=str(self.session.out_dir),
|
|
255
|
+
)
|
|
256
|
+
elif self.session.title and self.session.title != "Requirements" and len(self.session.design.strip()) >= 10:
|
|
257
|
+
tr.add_agent(
|
|
258
|
+
f"Ready for «{self.session.title}».\n"
|
|
259
|
+
"Add /ref docs if needed, then /analyse (or /run). Input stays live while I work."
|
|
260
|
+
)
|
|
261
|
+
else:
|
|
262
|
+
tr.add_agent(
|
|
263
|
+
"Welcome — set everything up in chat:\n"
|
|
264
|
+
" /title Identity Hub SSO\n"
|
|
265
|
+
" /brief ./brief.md\n"
|
|
266
|
+
" /ref ./contracts/\n"
|
|
267
|
+
" /analyse\n"
|
|
268
|
+
"Paste a path anytime to attach it. /help · /exit"
|
|
269
|
+
)
|
|
270
|
+
if self.session.refs and not self.session.active_doc():
|
|
271
|
+
tr.add_agent(f"{len(self.session.refs)} reference(s) loaded.")
|
|
272
|
+
self._timer = self.set_interval(1.0, self._tick)
|
|
273
|
+
if self.autostart_analyse:
|
|
274
|
+
self._handle_analyse(self.analyse_focus)
|
|
275
|
+
|
|
276
|
+
def action_focus_input(self) -> None:
|
|
277
|
+
self.query_one("#composer", Input).focus()
|
|
278
|
+
|
|
279
|
+
def action_stop_run(self) -> None:
|
|
280
|
+
self._do_stop()
|
|
281
|
+
|
|
282
|
+
def _do_stop(self) -> None:
|
|
283
|
+
tr = self.query_one("#transcript", Transcript)
|
|
284
|
+
if self.worker.busy:
|
|
285
|
+
self.worker.stop()
|
|
286
|
+
tr.add_agent("Stop requested — cancelling after the current LLM step…", error=True)
|
|
287
|
+
else:
|
|
288
|
+
tr.add_agent("Nothing running. Type /exit to leave the shell.")
|
|
289
|
+
self._refresh_chrome()
|
|
290
|
+
self.query_one("#composer", Input).focus()
|
|
291
|
+
|
|
292
|
+
def _tick(self) -> None:
|
|
293
|
+
# Keep timer + token/cost live while working (and briefly after)
|
|
294
|
+
self._refresh_chrome()
|
|
295
|
+
|
|
296
|
+
def _refresh_chrome(self) -> None:
|
|
297
|
+
self.query_one("#header", ShellHeader).refresh_from(self.session)
|
|
298
|
+
self.query_one("#progress-pane", ProgressPane).refresh_from(self.session)
|
|
299
|
+
self.query_one("#footer-stats", Static).update(
|
|
300
|
+
f"{len(self.session.refs)} refs · "
|
|
301
|
+
f"{self.session.finding_count} findings · "
|
|
302
|
+
f"{self.session.risk_count} risks · "
|
|
303
|
+
f"{self.session.progress_pct}% · "
|
|
304
|
+
f"{self.session.usage_label()}"
|
|
305
|
+
)
|
|
306
|
+
# Best-effort tuios rail / OSC progress (no-op outside tuios)
|
|
307
|
+
try:
|
|
308
|
+
from requirements_agent.tuios_hook import sync_shell_status
|
|
309
|
+
|
|
310
|
+
detail = self.session.active_persona or self.session.phase or None
|
|
311
|
+
status = self.session.status
|
|
312
|
+
if self.session.awaiting_confirm:
|
|
313
|
+
status = "confirm"
|
|
314
|
+
elif self.session.ui_mode == "done" and status == "idle":
|
|
315
|
+
status = "done"
|
|
316
|
+
elif self.session.ui_mode == "refine" and status == "idle":
|
|
317
|
+
status = "refine"
|
|
318
|
+
sync_shell_status(
|
|
319
|
+
status=status,
|
|
320
|
+
progress_pct=self.session.progress_pct,
|
|
321
|
+
detail=detail,
|
|
322
|
+
awaiting_confirm=self.session.awaiting_confirm,
|
|
323
|
+
)
|
|
324
|
+
except Exception:
|
|
325
|
+
pass
|
|
326
|
+
|
|
327
|
+
def _on_worker_ui(self, kind: str, payload: dict) -> None:
|
|
328
|
+
# Worker threads must marshal via call_from_thread; UI-thread callers
|
|
329
|
+
# (e.g. /stop, /ref while idle) must apply directly.
|
|
330
|
+
if getattr(self, "_thread_id", None) == threading.get_ident():
|
|
331
|
+
self._apply_ui(kind, payload)
|
|
332
|
+
else:
|
|
333
|
+
self.call_from_thread(self._apply_ui, kind, payload)
|
|
334
|
+
|
|
335
|
+
def _apply_ui(self, kind: str, payload: dict) -> None:
|
|
336
|
+
tr = self.query_one("#transcript", Transcript)
|
|
337
|
+
if kind == "agent":
|
|
338
|
+
tr.add_agent(
|
|
339
|
+
str(payload.get("text") or ""),
|
|
340
|
+
steps=payload.get("steps"),
|
|
341
|
+
error=bool(payload.get("error")),
|
|
342
|
+
)
|
|
343
|
+
elif kind == "agent_soft":
|
|
344
|
+
pass
|
|
345
|
+
elif kind == "finding":
|
|
346
|
+
tr.add_finding(str(payload.get("text") or ""), kind=str(payload.get("kind") or "finding"))
|
|
347
|
+
elif kind == "refine_ready":
|
|
348
|
+
tr.show_refine_board(
|
|
349
|
+
sections=list(payload.get("sections") or []),
|
|
350
|
+
questions=list(payload.get("questions") or []),
|
|
351
|
+
fix_items=list(payload.get("fix_items") or []),
|
|
352
|
+
quality=payload.get("quality") or {},
|
|
353
|
+
out_dir=str(payload.get("out_dir") or ""),
|
|
354
|
+
)
|
|
355
|
+
elif kind == "refine_confirm":
|
|
356
|
+
tr.show_confirm_board(
|
|
357
|
+
label=str(payload.get("label") or "document"),
|
|
358
|
+
path=str(payload.get("path") or ""),
|
|
359
|
+
preview=str(payload.get("preview") or ""),
|
|
360
|
+
)
|
|
361
|
+
elif kind == "report_ready":
|
|
362
|
+
tr.show_report_ready(
|
|
363
|
+
paths=list(payload.get("paths") or []),
|
|
364
|
+
preview=str(payload.get("preview") or ""),
|
|
365
|
+
sections=list(payload.get("sections") or []),
|
|
366
|
+
quality=payload.get("quality") or {},
|
|
367
|
+
)
|
|
368
|
+
elif kind in ("steps", "progress", "status", "usage"):
|
|
369
|
+
pass
|
|
370
|
+
self._refresh_chrome()
|
|
371
|
+
self.query_one("#composer", Input).focus()
|
|
372
|
+
|
|
373
|
+
def on_input_changed(self, event: Input.Changed) -> None:
|
|
374
|
+
if event.input.id != "composer":
|
|
375
|
+
return
|
|
376
|
+
val = event.value
|
|
377
|
+
comps = self.query_one("#completions", Completions)
|
|
378
|
+
if any(val.startswith(p) for p in ("/ref ", "/brief ", "/design ", "/open ", "/out ")):
|
|
379
|
+
rest = val.split(" ", 1)[-1] if " " in val else ""
|
|
380
|
+
if rest and not is_url(rest.strip()) and not rest.strip().startswith("@"):
|
|
381
|
+
comps.show(path_completions(val, cwd=str(Path.cwd())))
|
|
382
|
+
return
|
|
383
|
+
comps.show([])
|
|
384
|
+
|
|
385
|
+
def on_input_submitted(self, event: Input.Submitted) -> None:
|
|
386
|
+
if event.input.id != "composer":
|
|
387
|
+
return
|
|
388
|
+
raw = event.value.strip()
|
|
389
|
+
event.input.value = ""
|
|
390
|
+
self.query_one("#completions", Completions).show([])
|
|
391
|
+
if not raw:
|
|
392
|
+
return
|
|
393
|
+
tr = self.query_one("#transcript", Transcript)
|
|
394
|
+
tr.add_user(raw)
|
|
395
|
+
|
|
396
|
+
kind, cmd = parse_input(raw)
|
|
397
|
+
if kind == "command" and cmd:
|
|
398
|
+
self._route_command(cmd.name, cmd.args, cmd.raw)
|
|
399
|
+
elif kind == "message":
|
|
400
|
+
self._route_user_text(raw)
|
|
401
|
+
self._refresh_chrome()
|
|
402
|
+
self.query_one("#composer", Input).focus()
|
|
403
|
+
|
|
404
|
+
def _route_command(self, name: str, args: str, raw: str) -> None:
|
|
405
|
+
tr = self.query_one("#transcript", Transcript)
|
|
406
|
+
if name == "help":
|
|
407
|
+
tr.add_agent(HELP)
|
|
408
|
+
return
|
|
409
|
+
if name == "quit":
|
|
410
|
+
self.exit()
|
|
411
|
+
return
|
|
412
|
+
if name in ("yes", "keep", "confirm", "ok"):
|
|
413
|
+
self._handle_confirm_yes()
|
|
414
|
+
return
|
|
415
|
+
if name == "undo":
|
|
416
|
+
self._handle_undo()
|
|
417
|
+
return
|
|
418
|
+
if name == "stop":
|
|
419
|
+
self._do_stop()
|
|
420
|
+
return
|
|
421
|
+
if name == "status":
|
|
422
|
+
brief_preview = (self.session.design or "").strip().replace("\n", " ")[:80]
|
|
423
|
+
tr.add_agent(
|
|
424
|
+
f"Status: {self.session.status}\n"
|
|
425
|
+
f"Title: {self.session.title or '(not set — /title …)'}\n"
|
|
426
|
+
f"Brief: {brief_preview or '(not set — /brief ./file.md)'}{'…' if len(self.session.design) > 80 else ''}\n"
|
|
427
|
+
f"Pinned: {self.session.pinned_section or 'full document'}\n"
|
|
428
|
+
f"Out: {self.session.out_dir}\n"
|
|
429
|
+
f"Progress: {self.session.progress_pct}%\n"
|
|
430
|
+
f"Refs: {len(self.session.refs)} · Findings: {self.session.finding_count} · "
|
|
431
|
+
f"Risks: {self.session.risk_count}"
|
|
432
|
+
)
|
|
433
|
+
return
|
|
434
|
+
if name == "title":
|
|
435
|
+
if not args.strip():
|
|
436
|
+
tr.add_agent(f"Current title: {self.session.title or '(none)'}\nUsage: /title Identity Hub SSO")
|
|
437
|
+
return
|
|
438
|
+
self.session.title = args.strip()
|
|
439
|
+
tr.add_agent(f"Title set → {self.session.title}")
|
|
440
|
+
return
|
|
441
|
+
if name == "brief":
|
|
442
|
+
self._handle_brief(args)
|
|
443
|
+
return
|
|
444
|
+
if name == "out":
|
|
445
|
+
if not args.strip():
|
|
446
|
+
tr.add_agent(f"Output dir: {self.session.out_dir}\nUsage: /out ./out/my-project")
|
|
447
|
+
return
|
|
448
|
+
out = Path(args.strip()).expanduser().resolve()
|
|
449
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
450
|
+
self.session.out_dir = out
|
|
451
|
+
tr.add_agent(f"Output → {out}")
|
|
452
|
+
return
|
|
453
|
+
if name == "open":
|
|
454
|
+
self._handle_open(args)
|
|
455
|
+
return
|
|
456
|
+
if name == "ref":
|
|
457
|
+
self._handle_ref(args)
|
|
458
|
+
return
|
|
459
|
+
if name == "analyse":
|
|
460
|
+
self._handle_analyse(args)
|
|
461
|
+
return
|
|
462
|
+
if name == "report":
|
|
463
|
+
fmt = split_report_format(args)
|
|
464
|
+
self.session.clear_confirm()
|
|
465
|
+
if self.worker.busy:
|
|
466
|
+
self.worker.queue_prompt(f"/report --format {fmt}")
|
|
467
|
+
return
|
|
468
|
+
tr.add_agent("Generating report…")
|
|
469
|
+
self.worker.start_report(fmt)
|
|
470
|
+
return
|
|
471
|
+
if name == "context":
|
|
472
|
+
if not self.session.refs:
|
|
473
|
+
tr.add_agent("No references. Use /ref")
|
|
474
|
+
return
|
|
475
|
+
lines = [f"• [{r.kind}] {r.label} — {r.detail}" for r in self.session.refs]
|
|
476
|
+
tr.add_agent("References:\n" + "\n".join(lines))
|
|
477
|
+
return
|
|
478
|
+
if name == "clear-context":
|
|
479
|
+
self.session.clear_refs()
|
|
480
|
+
tr.add_agent("References cleared.")
|
|
481
|
+
return
|
|
482
|
+
if name == "risk":
|
|
483
|
+
risks = [f for f in self.session.findings if f.kind == "risk"]
|
|
484
|
+
if not risks:
|
|
485
|
+
tr.add_agent("No risks recorded yet.")
|
|
486
|
+
return
|
|
487
|
+
for f in risks:
|
|
488
|
+
tr.add_finding(f.text, kind="risk")
|
|
489
|
+
return
|
|
490
|
+
if name == "gaps":
|
|
491
|
+
items = [i for i in list_fix_items(self.session) if i.kind == "gap"]
|
|
492
|
+
if not items:
|
|
493
|
+
tr.add_agent("No gaps/findings yet.")
|
|
494
|
+
return
|
|
495
|
+
lines = [f"**`/fix {i.index}`** {i.text}" for i in items]
|
|
496
|
+
tr.add_agent("Gaps (use `/fix N` to resolve):\n" + "\n".join(lines))
|
|
497
|
+
return
|
|
498
|
+
if name == "questions":
|
|
499
|
+
if not self.session.open_questions:
|
|
500
|
+
self.session.load_open_questions_file()
|
|
501
|
+
items = [i for i in list_fix_items(self.session) if i.kind == "question"]
|
|
502
|
+
if not items:
|
|
503
|
+
tr.add_agent("No open questions yet. Run /analyse first.")
|
|
504
|
+
return
|
|
505
|
+
lines = [
|
|
506
|
+
f"**`/fix {i.index}`** [{i.category}] {i.text}" for i in items
|
|
507
|
+
]
|
|
508
|
+
tr.add_agent("Open questions (use `/fix N` to resolve):\n" + "\n".join(lines))
|
|
509
|
+
return
|
|
510
|
+
if name == "fix":
|
|
511
|
+
self._handle_fix(args)
|
|
512
|
+
return
|
|
513
|
+
if name == "find":
|
|
514
|
+
self._handle_find(args)
|
|
515
|
+
return
|
|
516
|
+
if name == "trace":
|
|
517
|
+
md = self.session.active_doc()
|
|
518
|
+
if not md:
|
|
519
|
+
tr.add_agent("No report loaded.")
|
|
520
|
+
return
|
|
521
|
+
tr.add_agent("Sections:\n" + format_section_menu(list_h2_sections(md)))
|
|
522
|
+
return
|
|
523
|
+
if name == "section":
|
|
524
|
+
if not args or args.lower() in ("clear", "none", "full"):
|
|
525
|
+
self.session.pinned_section = None
|
|
526
|
+
tr.add_agent("Pinned: full document")
|
|
527
|
+
return
|
|
528
|
+
sec, _ = resolve_section(self.session.active_doc(), args)
|
|
529
|
+
if not sec:
|
|
530
|
+
tr.add_agent(f"Section not found: {args}")
|
|
531
|
+
return
|
|
532
|
+
self.session.pinned_section = str(sec.index)
|
|
533
|
+
tr.add_agent(f"Pinned [{sec.index}] {sec.heading}")
|
|
534
|
+
return
|
|
535
|
+
if name == "score":
|
|
536
|
+
if self.worker.busy:
|
|
537
|
+
self.worker.queue_prompt("/score")
|
|
538
|
+
return
|
|
539
|
+
self.worker.start_score()
|
|
540
|
+
return
|
|
541
|
+
tr.add_agent(f"Unknown command /{name}. Try /help")
|
|
542
|
+
|
|
543
|
+
def _handle_fix(self, args: str) -> None:
|
|
544
|
+
tr = self.query_one("#transcript", Transcript)
|
|
545
|
+
if not self.session.active_doc():
|
|
546
|
+
tr.add_agent("No report yet. Run /analyse first.")
|
|
547
|
+
return
|
|
548
|
+
if not self.session.open_questions:
|
|
549
|
+
self.session.load_open_questions_file()
|
|
550
|
+
items = list_fix_items(self.session)
|
|
551
|
+
if not items:
|
|
552
|
+
tr.add_agent("Nothing to fix. Run /analyse first, or check /gaps and /questions.")
|
|
553
|
+
return
|
|
554
|
+
idx, answer = parse_fix_args(args)
|
|
555
|
+
if idx is None:
|
|
556
|
+
preview = "\n".join(
|
|
557
|
+
f"- **/fix {i.index}** [{i.category}] {_clip_line(i.text, 90)}"
|
|
558
|
+
for i in items[:12]
|
|
559
|
+
)
|
|
560
|
+
more = f"\n- … +{len(items) - 12} more" if len(items) > 12 else ""
|
|
561
|
+
tr.add_agent(
|
|
562
|
+
"Usage: `/fix <n> [optional guidance]`\n\n" + preview + more
|
|
563
|
+
)
|
|
564
|
+
return
|
|
565
|
+
item = get_fix_item(self.session, idx)
|
|
566
|
+
if item is None:
|
|
567
|
+
tr.add_agent(f"No item #{idx}. Valid range: 1–{len(items)}. Try `/gaps` or `/questions`.")
|
|
568
|
+
return
|
|
569
|
+
|
|
570
|
+
section = map_item_to_section(self.session.active_doc(), item.text)
|
|
571
|
+
self.session.pinned_section = section
|
|
572
|
+
instruction = build_fix_instruction(item, answer)
|
|
573
|
+
|
|
574
|
+
if section:
|
|
575
|
+
sec, _ = resolve_section(self.session.active_doc(), section)
|
|
576
|
+
target = f"section [{sec.index}] {sec.heading}" if sec else f"section [{section}]"
|
|
577
|
+
else:
|
|
578
|
+
target = "full document"
|
|
579
|
+
|
|
580
|
+
label = "gap" if item.kind == "gap" else "question"
|
|
581
|
+
tip = f" · guidance: {answer}" if answer else ""
|
|
582
|
+
msg = f"Resolving **/fix {item.index}** ({label}) → {target}{tip}"
|
|
583
|
+
|
|
584
|
+
if self.worker.busy:
|
|
585
|
+
self.worker.queue_prompt(f"/fix {idx}" + (f" {answer}" if answer else ""))
|
|
586
|
+
tr.add_agent(msg + "\nQueued — will run after the current job.")
|
|
587
|
+
return
|
|
588
|
+
|
|
589
|
+
self.session.clear_confirm()
|
|
590
|
+
self.session.last_fix = {
|
|
591
|
+
"item": item.text,
|
|
592
|
+
"category": item.category or label.title(),
|
|
593
|
+
"answer": answer,
|
|
594
|
+
"section": target,
|
|
595
|
+
}
|
|
596
|
+
tr.add_agent(msg + "\n" + _clip_line(item.text, 160))
|
|
597
|
+
if not self.worker.start_refine(instruction, section):
|
|
598
|
+
tr.add_agent("Could not start refine (busy or no report).")
|
|
599
|
+
|
|
600
|
+
def _handle_confirm_yes(self) -> None:
|
|
601
|
+
tr = self.query_one("#transcript", Transcript)
|
|
602
|
+
self._remember_fix()
|
|
603
|
+
self.session.clear_confirm()
|
|
604
|
+
tr.show_next_step_board()
|
|
605
|
+
self._refresh_chrome()
|
|
606
|
+
|
|
607
|
+
def _remember_fix(self) -> None:
|
|
608
|
+
"""A fix kept with the person's own answer is a decision later reviews of the product keep to (context/memory.py)."""
|
|
609
|
+
fix, self.session.last_fix = self.session.last_fix, None
|
|
610
|
+
if not fix or not fix.get("answer"):
|
|
611
|
+
return
|
|
612
|
+
try:
|
|
613
|
+
from requirements_agent.context.memory import ReviewMemory
|
|
614
|
+
|
|
615
|
+
folder = self.session.agent.config.context.memory.get("dir")
|
|
616
|
+
ReviewMemory(Path(folder).expanduser() if folder else None).add(
|
|
617
|
+
{"kind": "decision", "title": self.session.title, **fix}
|
|
618
|
+
)
|
|
619
|
+
except Exception:
|
|
620
|
+
pass # memory is a help, never a reason a kept change fails
|
|
621
|
+
|
|
622
|
+
def _handle_undo(self) -> None:
|
|
623
|
+
tr = self.query_one("#transcript", Transcript)
|
|
624
|
+
self.session.last_fix = None
|
|
625
|
+
if self.session.undo():
|
|
626
|
+
self.session.clear_confirm()
|
|
627
|
+
self.session.enter_refine_mode()
|
|
628
|
+
tr.add_agent("Reverted last change. Document restored.")
|
|
629
|
+
else:
|
|
630
|
+
tr.add_agent("Nothing to undo.")
|
|
631
|
+
self._refresh_chrome()
|
|
632
|
+
|
|
633
|
+
def _handle_brief(self, args: str) -> None:
|
|
634
|
+
tr = self.query_one("#transcript", Transcript)
|
|
635
|
+
if not args.strip():
|
|
636
|
+
tr.add_agent("Usage: /brief ./brief.md\nOr paste the path.")
|
|
637
|
+
return
|
|
638
|
+
path = Path(args.strip().strip("'\"")).expanduser()
|
|
639
|
+
if not path.is_absolute():
|
|
640
|
+
path = (Path.cwd() / path).resolve()
|
|
641
|
+
else:
|
|
642
|
+
path = path.resolve()
|
|
643
|
+
if not path.is_file():
|
|
644
|
+
tr.add_agent(f"Brief not found: {path}")
|
|
645
|
+
return
|
|
646
|
+
self.session.design = path.read_text(encoding="utf-8")
|
|
647
|
+
# Also attach as a reference so Memory sees it
|
|
648
|
+
ref, _msg = add_path_ref(str(path))
|
|
649
|
+
if ref:
|
|
650
|
+
self.session.add_ref(ref)
|
|
651
|
+
if not self.session.title or self.session.title in ("Requirements", ""):
|
|
652
|
+
# soft default from filename
|
|
653
|
+
self.session.title = path.stem.replace("-", " ").replace("_", " ").title()
|
|
654
|
+
tr.add_agent(
|
|
655
|
+
f"Brief loaded ({len(self.session.design):,} chars) from {path.name}\n"
|
|
656
|
+
f"Title: {self.session.title}\n"
|
|
657
|
+
"Add more /ref docs if needed, then /analyse"
|
|
658
|
+
)
|
|
659
|
+
self._refresh_chrome()
|
|
660
|
+
|
|
661
|
+
def _handle_open(self, args: str) -> None:
|
|
662
|
+
tr = self.query_one("#transcript", Transcript)
|
|
663
|
+
if not args.strip():
|
|
664
|
+
tr.add_agent("Usage: /open ./out/02-requirements-report.md")
|
|
665
|
+
return
|
|
666
|
+
path = Path(args.strip().strip("'\"")).expanduser()
|
|
667
|
+
if not path.is_absolute():
|
|
668
|
+
path = (Path.cwd() / path).resolve()
|
|
669
|
+
else:
|
|
670
|
+
path = path.resolve()
|
|
671
|
+
if not path.is_file():
|
|
672
|
+
tr.add_agent(f"Report not found: {path}")
|
|
673
|
+
return
|
|
674
|
+
md = path.read_text(encoding="utf-8")
|
|
675
|
+
self.session.report_path = path
|
|
676
|
+
if "requirements-report" in path.name or md.lstrip().startswith("# Requirements"):
|
|
677
|
+
self.session.brd_markdown = md
|
|
678
|
+
else:
|
|
679
|
+
self.session.markdown = md
|
|
680
|
+
self.session.out_dir = path.parent
|
|
681
|
+
self.session.load_open_questions_file()
|
|
682
|
+
self.session.enter_refine_mode()
|
|
683
|
+
tr.add_agent(f"Opened {path.name} ({len(md):,} chars).")
|
|
684
|
+
tr.show_refine_board(
|
|
685
|
+
sections=self.session.section_outline(),
|
|
686
|
+
questions=list(self.session.open_questions),
|
|
687
|
+
fix_items=_fix_items_payload(self.session),
|
|
688
|
+
quality=self.session.quality or {},
|
|
689
|
+
out_dir=str(self.session.out_dir),
|
|
690
|
+
)
|
|
691
|
+
self._refresh_chrome()
|
|
692
|
+
|
|
693
|
+
def _handle_ref(self, args: str) -> None:
|
|
694
|
+
tr = self.query_one("#transcript", Transcript)
|
|
695
|
+
if not args:
|
|
696
|
+
self.push_screen(RefPickerScreen(), self._ref_picker_done)
|
|
697
|
+
return
|
|
698
|
+
self._apply_ref_arg(args)
|
|
699
|
+
|
|
700
|
+
def _ref_picker_done(self, value: Optional[str]) -> None:
|
|
701
|
+
tr = self.query_one("#transcript", Transcript)
|
|
702
|
+
if not value:
|
|
703
|
+
tr.add_agent("Reference cancelled.")
|
|
704
|
+
return
|
|
705
|
+
if value == "__ado_stub__":
|
|
706
|
+
tr.add_agent("ADO / Jira references are coming soon. Use /ref <path> or /ref <url> for now.")
|
|
707
|
+
return
|
|
708
|
+
if value == "__ask_path__":
|
|
709
|
+
tr.add_agent("Type: /ref ./path/to/file-or-folder")
|
|
710
|
+
return
|
|
711
|
+
if value == "__ask_url__":
|
|
712
|
+
tr.add_agent("Type: /ref https://…")
|
|
713
|
+
return
|
|
714
|
+
self._apply_ref_arg(value)
|
|
715
|
+
|
|
716
|
+
def _apply_ref_arg(self, args: str) -> None:
|
|
717
|
+
tr = self.query_one("#transcript", Transcript)
|
|
718
|
+
token = ref_token(args)
|
|
719
|
+
|
|
720
|
+
if token == "@workspace":
|
|
721
|
+
ref, msg = add_workspace_ref()
|
|
722
|
+
elif token == "@git":
|
|
723
|
+
ref, msg = add_git_ref()
|
|
724
|
+
elif is_url(token):
|
|
725
|
+
tr.add_agent("Fetching and indexing URL…")
|
|
726
|
+
ref, msg = add_url_ref(token)
|
|
727
|
+
else:
|
|
728
|
+
ref, msg = add_path_ref(token)
|
|
729
|
+
|
|
730
|
+
if not ref:
|
|
731
|
+
tr.add_agent(msg)
|
|
732
|
+
return
|
|
733
|
+
self.session.add_ref(ref)
|
|
734
|
+
# Mid-run refs still apply (agent rebuilt for next step / queued work)
|
|
735
|
+
tr.add_agent(
|
|
736
|
+
f"✓ Reference added\n{ref.label}\n{ref.detail}\n\nI'll use this as additional context."
|
|
737
|
+
)
|
|
738
|
+
if self.worker.busy:
|
|
739
|
+
tr.add_soft("(Attached live — will ground the next step / follow-up.)")
|
|
740
|
+
self._refresh_chrome()
|
|
741
|
+
|
|
742
|
+
def _handle_analyse(self, focus: str = "") -> None:
|
|
743
|
+
tr = self.query_one("#transcript", Transcript)
|
|
744
|
+
if len(self.session.design.strip()) < 10:
|
|
745
|
+
tr.add_agent("Before analysing, load a brief:\n /brief ./brief.md\nOr paste the design text.")
|
|
746
|
+
return
|
|
747
|
+
if not (self.session.title or "").strip():
|
|
748
|
+
for line in self.session.design.splitlines():
|
|
749
|
+
s = line.strip()
|
|
750
|
+
if s.startswith("#"):
|
|
751
|
+
self.session.title = s.lstrip("#").strip()
|
|
752
|
+
break
|
|
753
|
+
if not self.session.title:
|
|
754
|
+
self.session.title = "Requirements"
|
|
755
|
+
tr.add_soft(f"Using title: {self.session.title}")
|
|
756
|
+
if self.worker.busy:
|
|
757
|
+
self.worker.queue_prompt(f"/analyse {focus}".strip())
|
|
758
|
+
return
|
|
759
|
+
self.worker.start_analyse(focus)
|
|
760
|
+
|
|
761
|
+
def _handle_find(self, query: str) -> None:
|
|
762
|
+
tr = self.query_one("#transcript", Transcript)
|
|
763
|
+
q = (query or "").strip().lower()
|
|
764
|
+
if not q:
|
|
765
|
+
tr.add_agent("Usage: /find <text>")
|
|
766
|
+
return
|
|
767
|
+
md = self.session.active_doc()
|
|
768
|
+
if not md:
|
|
769
|
+
tr.add_agent("No report loaded.")
|
|
770
|
+
return
|
|
771
|
+
hits = []
|
|
772
|
+
for i, line in enumerate(md.splitlines(), 1):
|
|
773
|
+
if q in line.lower():
|
|
774
|
+
hits.append(f"L{i}: {line.strip()[:120]}")
|
|
775
|
+
if len(hits) >= 15:
|
|
776
|
+
break
|
|
777
|
+
tr.add_agent("\n".join(hits) if hits else "No matches.")
|
|
778
|
+
|
|
779
|
+
def _route_user_text(self, text: str) -> None:
|
|
780
|
+
tr = self.query_one("#transcript", Transcript)
|
|
781
|
+
low = text.strip().lower()
|
|
782
|
+
|
|
783
|
+
# Easy exit without slash
|
|
784
|
+
if low in ("exit", "quit", "q", "bye"):
|
|
785
|
+
self.exit()
|
|
786
|
+
return
|
|
787
|
+
if low in ("stop", "cancel", "abort"):
|
|
788
|
+
self._do_stop()
|
|
789
|
+
return
|
|
790
|
+
|
|
791
|
+
# Confirm step after refine
|
|
792
|
+
if self.session.awaiting_confirm and low in (
|
|
793
|
+
"y",
|
|
794
|
+
"yes",
|
|
795
|
+
"keep",
|
|
796
|
+
"ok",
|
|
797
|
+
"confirm",
|
|
798
|
+
"accept",
|
|
799
|
+
"lgtm",
|
|
800
|
+
):
|
|
801
|
+
self._handle_confirm_yes()
|
|
802
|
+
return
|
|
803
|
+
if self.session.awaiting_confirm and low in ("n", "no", "undo", "revert"):
|
|
804
|
+
self._handle_undo()
|
|
805
|
+
return
|
|
806
|
+
|
|
807
|
+
# Bare path / URL → attach (or load as brief if unused)
|
|
808
|
+
candidate = text.strip().strip("'\"")
|
|
809
|
+
if looks_like_path(candidate) or is_url(candidate):
|
|
810
|
+
self.session.clear_confirm()
|
|
811
|
+
low_path = candidate.lower()
|
|
812
|
+
if (
|
|
813
|
+
not is_url(candidate)
|
|
814
|
+
and len(self.session.design.strip()) < 10
|
|
815
|
+
and Path(candidate).expanduser().is_file()
|
|
816
|
+
and (low_path.endswith(".md") or "brief" in low_path or "design" in low_path)
|
|
817
|
+
):
|
|
818
|
+
self._handle_brief(candidate)
|
|
819
|
+
return
|
|
820
|
+
self._apply_ref_arg(candidate)
|
|
821
|
+
return
|
|
822
|
+
|
|
823
|
+
# title: ...
|
|
824
|
+
if text.lower().startswith("title:"):
|
|
825
|
+
self.session.title = text.split(":", 1)[1].strip()
|
|
826
|
+
tr.add_agent(f"Title set → {self.session.title}")
|
|
827
|
+
return
|
|
828
|
+
|
|
829
|
+
# If busy, queue
|
|
830
|
+
if self.worker.busy:
|
|
831
|
+
self.worker.queue_prompt(text)
|
|
832
|
+
return
|
|
833
|
+
|
|
834
|
+
# Starting another refine clears confirm wait
|
|
835
|
+
self.session.clear_confirm()
|
|
836
|
+
|
|
837
|
+
# No report yet → treat as analyse focus / kickoff when brief exists
|
|
838
|
+
if not self.session.active_doc():
|
|
839
|
+
if len(self.session.design.strip()) >= 10 and any(
|
|
840
|
+
k in text.lower() for k in ("analys", "review", "gap", "requirement", "run", "go")
|
|
841
|
+
):
|
|
842
|
+
self.worker.start_analyse(text)
|
|
843
|
+
return
|
|
844
|
+
if len(self.session.design.strip()) < 10 and len(text) > 80:
|
|
845
|
+
# treat long paste as the brief itself
|
|
846
|
+
self.session.design = text
|
|
847
|
+
tr.add_agent(
|
|
848
|
+
f"Treated that as your design brief ({len(text):,} chars).\n"
|
|
849
|
+
"Set /title if needed, add /ref docs, then /analyse"
|
|
850
|
+
)
|
|
851
|
+
return
|
|
852
|
+
tr.add_agent(
|
|
853
|
+
"No report yet. Load a brief (/brief ./file.md), set /title, add /ref, then /analyse.\n"
|
|
854
|
+
"Or paste a file path to attach it."
|
|
855
|
+
)
|
|
856
|
+
return
|
|
857
|
+
|
|
858
|
+
section_q, instruction = parse_chat_turn(text, self.session.pinned_section)
|
|
859
|
+
if section_q and section_q != self.session.pinned_section:
|
|
860
|
+
sec, _ = resolve_section(self.session.active_doc(), section_q)
|
|
861
|
+
if sec is None:
|
|
862
|
+
section_q = self.session.pinned_section
|
|
863
|
+
self.worker.start_refine(instruction or text, section_q)
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
def run_shell(
|
|
867
|
+
*,
|
|
868
|
+
config: Optional[AppConfig] = None,
|
|
869
|
+
config_path: Optional[Path] = None,
|
|
870
|
+
profile_name: Optional[str] = None,
|
|
871
|
+
llms_json: Optional[Path] = None,
|
|
872
|
+
title: str = "",
|
|
873
|
+
design: str = "",
|
|
874
|
+
out_dir: Optional[Path] = None,
|
|
875
|
+
report: Optional[Path] = None,
|
|
876
|
+
docs: Optional[List[Path]] = None,
|
|
877
|
+
pin: Optional[str] = None,
|
|
878
|
+
autostart_analyse: bool = False,
|
|
879
|
+
analyse_focus: str = "",
|
|
880
|
+
) -> None:
|
|
881
|
+
cfg = config or load_config(config_path, profile_name=profile_name, llms_json=llms_json)
|
|
882
|
+
session = ShellSession(
|
|
883
|
+
config=cfg,
|
|
884
|
+
title=title or "",
|
|
885
|
+
design=design or "",
|
|
886
|
+
out_dir=out_dir or Path(cfg.export.out_dir),
|
|
887
|
+
report_path=report,
|
|
888
|
+
)
|
|
889
|
+
for p in docs or []:
|
|
890
|
+
ref, _msg = add_path_ref(str(p))
|
|
891
|
+
if ref:
|
|
892
|
+
session.add_ref(ref)
|
|
893
|
+
if pin and session.active_doc():
|
|
894
|
+
sec, _ = resolve_section(session.active_doc(), pin)
|
|
895
|
+
if sec:
|
|
896
|
+
session.pinned_section = str(sec.index)
|
|
897
|
+
app = RequirementsShell(
|
|
898
|
+
session,
|
|
899
|
+
autostart_analyse=autostart_analyse,
|
|
900
|
+
analyse_focus=analyse_focus,
|
|
901
|
+
)
|
|
902
|
+
app.run()
|