Skip to content

Commit 4e2bf03

Browse files
committed
feat: Display research blueprint section titles, enhance JSON parsing error messages with content snippets, and correct prompt template application.
1 parent adc7423 commit 4e2bf03

7 files changed

Lines changed: 30 additions & 11 deletions

File tree

pdm.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies = [
99
"openai>=2.11.0",
1010
"python-dotenv>=1.2.1",
1111
"click>=8.3.1",
12-
"promptdown>=1.0.1",
12+
"promptdown>=1.1.0",
1313
"mistune>=3.2.0",
1414
"fpdf2>=2.8.5",
1515
]

src/compendiumscribe/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def handle_progress(update: ResearchProgress) -> None:
8989
**stream_kwargs,
9090
)
9191

92+
# Display blueprint section titles when available
93+
if "section_titles" in meta and meta["section_titles"]:
94+
for title in meta["section_titles"]:
95+
click.echo(f" - {title}")
96+
9297
try:
9398
config = ResearchConfig(
9499
background=not no_background,

src/compendiumscribe/research/execution/polling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def await_completion(
6767
config,
6868
phase="deep_research",
6969
status="update",
70-
message="Deep research still running; awaiting updated status.",
70+
message="In progress...",
7171
metadata={
7272
"status": status,
7373
"poll_attempt": attempts,

src/compendiumscribe/research/orchestrator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,20 @@ def build_compendium(
7070
)
7171
plan = default_research_plan(normalized_topic)
7272
else:
73+
key_sections = plan.get("key_sections", []) or []
7374
emit_progress(
7475
config,
7576
phase="planning",
7677
status="completed",
7778
message="Received refined research blueprint.",
7879
metadata={
79-
"sections": len(plan.get("key_sections", []) or []),
80+
"sections": len(key_sections),
8081
"questions": len(
8182
plan.get("research_questions", []) or []
8283
),
84+
"section_titles": [
85+
s.get("title") for s in key_sections if s.get("title")
86+
],
8387
},
8488
)
8589

src/compendiumscribe/research/parsing.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def collect_response_text(response: Any) -> str:
8484
def decode_json_payload(text: str) -> dict[str, Any]:
8585
candidate = text.strip()
8686

87+
# Helper to create a preview snippet for error messages
88+
def _snippet(s: str, max_len: int = 200) -> str:
89+
if len(s) <= max_len:
90+
return s
91+
return s[:max_len] + "..."
92+
8793
if candidate.startswith("```"):
8894
candidate = candidate.strip("`").strip()
8995
if candidate.startswith("json"):
@@ -94,20 +100,24 @@ def decode_json_payload(text: str) -> dict[str, Any]:
94100
end = candidate.rfind("}")
95101
if start == -1 or end == -1:
96102
raise DeepResearchError(
97-
"Unable to locate JSON object in response."
103+
f"Unable to locate JSON object in response. "
104+
f"Received: {_snippet(text)!r}"
98105
)
99106
candidate = candidate[start:end + 1]
100107

101108
try:
102109
payload = json.loads(candidate)
103110
except json.JSONDecodeError as exc:
104111
raise DeepResearchError(
105-
"Deep research response was not valid JSON."
112+
f"Deep research response was not valid JSON. "
113+
f"Parse error at position {exc.pos}: {exc.msg}. "
114+
f"Content: {_snippet(candidate)!r}"
106115
) from exc
107116

108117
if not isinstance(payload, dict):
109118
raise DeepResearchError(
110-
"Expected JSON object at top level of response."
119+
f"Expected JSON object at top level of response, "
120+
f"got {type(payload).__name__}: {_snippet(str(payload))!r}"
111121
)
112122

113123
return payload

src/compendiumscribe/research/planning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def generate_research_plan(
1717
) -> dict[str, Any] | None:
1818
prompt_obj = load_prompt_template("topic_blueprint.prompt.md")
1919
# Apply template values
20-
prompt_obj.apply_template_values({"topic": topic})
20+
prompt_obj = prompt_obj.apply_template_values({"topic": topic})
2121

2222
# Convert to Responses API input
2323
responses_input = prompt_obj.to_responses_input()
@@ -122,7 +122,7 @@ def compose_deep_research_prompt(topic: str, plan: dict[str, Any]) -> Any:
122122
indent=2,
123123
)
124124

125-
prompt_obj.apply_template_values(
125+
prompt_obj = prompt_obj.apply_template_values(
126126
{
127127
"topic": topic,
128128
"primary_objective": plan.get(

0 commit comments

Comments
 (0)