-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_spec_agent.py
More file actions
96 lines (81 loc) · 2.91 KB
/
Copy pathgenerate_spec_agent.py
File metadata and controls
96 lines (81 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python3
"""Generate collaborative spec draft + Cursor Agent prompt (no Ollama)."""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from src.agent_spec import ( # noqa: E402
agent_prompt_path,
build_agent_prompt_document,
)
from src.spec_generator import load_extraction_report # noqa: E402
from src.spec_skeleton import build_draft_spec, draft_spec_path # noqa: E402
def main() -> int:
parser = argparse.ArgumentParser(
description=(
"Build a collaborative DRAFT_SPEC and Cursor AGENT_PROMPT "
"from extraction JSON — no LLM call."
)
)
parser.add_argument(
"extraction",
type=Path,
help="Path to extractions/<name>_extraction.json",
)
parser.add_argument(
"--draft-only",
action="store_true",
help="Write only specs/<name>_DRAFT_SPEC.md",
)
parser.add_argument(
"--prompt-only",
action="store_true",
help="Write only specs/<name>_AGENT_PROMPT.md",
)
parser.add_argument(
"--lang",
default="en",
choices=["fr", "en"],
help="Language hint for the agent task (default: en)",
)
args = parser.parse_args()
if not args.extraction.is_file():
print(f"Error: file not found — {args.extraction}", file=sys.stderr)
return 1
report = load_extraction_report(args.extraction)
draft_path = draft_spec_path(args.extraction)
prompt_path = agent_prompt_path(args.extraction)
write_draft = not args.prompt_only
write_prompt = not args.draft_only
if write_draft:
draft_path.parent.mkdir(parents=True, exist_ok=True)
draft_path.write_text(
build_draft_spec(report, source_json=args.extraction),
encoding="utf-8",
)
print(f" -> {draft_path}")
print(" Open, complete « Your answer / Your correction », then validate.")
if write_prompt:
prompt_path.parent.mkdir(parents=True, exist_ok=True)
prompt_path.write_text(
build_agent_prompt_document(
report,
extraction_path=args.extraction,
draft_path=draft_path if draft_path.exists() else None,
language=args.lang,
),
encoding="utf-8",
)
print(f" -> {prompt_path}")
print(" Paste into Cursor Agent with the extraction JSON attached.")
if write_draft and write_prompt:
print("\nWorkflow:")
print(" 1. Fill user sections in DRAFT_SPEC (your Excel knowledge)")
print(" 2. Run Cursor Agent with AGENT_PROMPT + extraction JSON")
print(" 3. Review FUNCTIONAL_SPEC, merge corrections, check validation boxes")
return 0
if __name__ == "__main__":
raise SystemExit(main())