added
This commit is contained in:
1 parent
31253e14c1
commit
8596c42ea1
2029 files changed
+225999
-30819
No files matched your search
@@ -15,10 +15,10 @@ import shutil
|
||||
import sys
|
||||
from datetime import date, datetime, timezone
|
||||
from typing import Any, Iterable
|
||||
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
|
||||
from urllib.parse import parse_qsl, quote, urlencode, urlsplit, urlunsplit
|
||||
|
||||
|
||||
PIPELINE_VERSION = "1.2.0"
|
||||
PIPELINE_VERSION = "1.4.0"
|
||||
PUBLIC_SCHEMA_VERSION = "1.2"
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
REPOSITORY_ROOT = BASE_DIR.parents[1]
|
||||
@@ -26,6 +26,9 @@ DEFAULT_CONFIG = BASE_DIR / "config" / "local.json"
|
||||
SCHEMA_PATH = BASE_DIR / "schemas" / "future-map-signal.schema.json"
|
||||
PATCH_SCHEMA_PATH = BASE_DIR / "schemas" / "reasoning-patch.schema.json"
|
||||
READINESS_PATCH_SCHEMA_PATH = BASE_DIR / "schemas" / "readiness-patch.schema.json"
|
||||
CONNECTIONS_SCHEMA_PATH = BASE_DIR / "schemas" / "connections.schema.json"
|
||||
DERIVATIVE_SCHEMA_PATH = BASE_DIR / "schemas" / "future-map-derivative.schema.json"
|
||||
DERIVATIVE_PATCH_SCHEMA_PATH = BASE_DIR / "schemas" / "derivative-patch.schema.json"
|
||||
TRACKING_KEYS = {
|
||||
"token", "auth", "signature", "sig", "key", "j", "r", "redirect",
|
||||
"fbclid", "gclid", "mc_cid", "mc_eid", "isfreemail",
|
||||
@@ -82,6 +85,11 @@ def sha256_file(path: Path) -> str:
|
||||
return "sha256:" + digest.hexdigest()
|
||||
|
||||
|
||||
def sha256_json(value: Any) -> str:
|
||||
payload = json.dumps(value, ensure_ascii=False, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
||||
return sha256_bytes(payload)
|
||||
|
||||
|
||||
def normalize_list(value: Any) -> list[str]:
|
||||
if value is None:
|
||||
return []
|
||||
@@ -395,7 +403,9 @@ def build_record(
|
||||
reasoning = dict(reasoning)
|
||||
reasoning["status"] = "stale"
|
||||
warnings.append("Source or connected media changed after enrichment")
|
||||
elif reasoning.get("status") not in {"complete", "stale"}:
|
||||
elif previous and reasoning.get("status") == "excluded" and source_changed:
|
||||
reasoning = empty_reasoning()
|
||||
elif reasoning.get("status") not in {"complete", "stale", "excluded"}:
|
||||
reasoning = empty_reasoning()
|
||||
|
||||
if previous and not source_changed and previous.get("source_assessment"):
|
||||
@@ -553,15 +563,419 @@ def records_from_output(base: Path) -> list[dict[str, Any]]:
|
||||
return result
|
||||
|
||||
|
||||
def publication_settings(base: Path) -> dict[str, Any]:
|
||||
return load_json(base / "config" / "publication.json") or {}
|
||||
|
||||
|
||||
def public_repository_url(settings: dict[str, Any], repository_path: str, locator: str | None = None) -> str | None:
|
||||
base_url = str(settings.get("repository_browser_base_url") or "").rstrip("/")
|
||||
if not base_url:
|
||||
return None
|
||||
encoded_path = quote(repository_path.replace("\\", "/"), safe="/-_.~()")
|
||||
return f"{base_url}/{encoded_path}{locator or ''}"
|
||||
|
||||
|
||||
def connection_identifier(source_id: str, target_type: str, target_id: str, relationship: str) -> str:
|
||||
payload = f"{source_id}|{target_type}|{target_id}|{relationship}".encode("utf-8")
|
||||
return "fm-connection-" + hashlib.sha256(payload).hexdigest()[:20]
|
||||
|
||||
|
||||
def resolve_connections(records: list[dict[str, Any]], base: Path) -> tuple[dict[str, Any], dict[str, list[dict[str, Any]]], dict[str, list[dict[str, Any]]], list[dict[str, Any]]]:
|
||||
settings = publication_settings(base)
|
||||
section_index = load_json(base / "indexes" / "core-document-sections.json") or {}
|
||||
section_targets: dict[tuple[str, str], dict[str, Any]] = {}
|
||||
for document in section_index.get("documents", []):
|
||||
for section in document.get("sections", []):
|
||||
section_targets[(document.get("document_id"), section.get("section_id"))] = {
|
||||
"document_title": document.get("title") or document.get("document_id"),
|
||||
"repository_path": document.get("path"),
|
||||
"format": document.get("format"),
|
||||
"section_title": section.get("heading") or section.get("section_id"),
|
||||
"locator": section.get("locator"),
|
||||
}
|
||||
|
||||
record_by_id = {record["id"]: record for record in records}
|
||||
titles = {
|
||||
record["id"]: record["source_record"].get("title") or f"Future Map Signal {record['source_record']['source_file_id']}"
|
||||
for record in records
|
||||
}
|
||||
outgoing: dict[str, list[dict[str, Any]]] = {record["id"]: [] for record in records}
|
||||
incoming_signals: dict[str, list[dict[str, Any]]] = {record["id"]: [] for record in records}
|
||||
core_backlinks: dict[str, list[dict[str, Any]]] = {}
|
||||
connections: list[dict[str, Any]] = []
|
||||
issues: list[dict[str, Any]] = []
|
||||
|
||||
for record in records:
|
||||
source_id = record["id"]
|
||||
source_page = f"signals/{source_id}.md"
|
||||
reasoning = record.get("reasoning", {})
|
||||
for relationship in reasoning.get("related_documents", []):
|
||||
document_id = str(relationship.get("document_id") or "")
|
||||
section_id = str(relationship.get("section_id") or "")
|
||||
target = section_targets.get((document_id, section_id))
|
||||
if not target or not target.get("repository_path"):
|
||||
issues.append({
|
||||
"source_signal_id": source_id,
|
||||
"target_type": "core-section",
|
||||
"document_id": document_id,
|
||||
"section_id": section_id,
|
||||
"issue": "unresolved-core-section-target",
|
||||
})
|
||||
continue
|
||||
target_id = f"{document_id}#{section_id}"
|
||||
locator = target.get("locator") or ""
|
||||
repository_path = str(target["repository_path"])
|
||||
edge = {
|
||||
"connection_id": connection_identifier(source_id, "core-section", target_id, relationship.get("relationship", "illustrates")),
|
||||
"source_signal_id": source_id,
|
||||
"source_label": titles[source_id],
|
||||
"source_page_path": source_page,
|
||||
"source_public_url": public_repository_url(settings, f"data/insights-hub/{source_page}"),
|
||||
"target_type": "core-section",
|
||||
"target_id": target_id,
|
||||
"document_id": document_id,
|
||||
"section_id": section_id,
|
||||
"label": f"{target['document_title']} — {target['section_title']}",
|
||||
"relationship": relationship.get("relationship", "illustrates"),
|
||||
"relevance": relationship.get("relevance"),
|
||||
"review_status": relationship.get("review_status", "machine-proposed"),
|
||||
"repository_path": repository_path,
|
||||
"locator": locator or None,
|
||||
"relative_url": f"../../{repository_path}{locator}",
|
||||
"page_relative_url": f"../../../{repository_path}{locator}",
|
||||
"public_url": public_repository_url(settings, repository_path, locator),
|
||||
}
|
||||
connections.append(edge)
|
||||
outgoing[source_id].append(edge)
|
||||
core_backlinks.setdefault(target_id, []).append(edge)
|
||||
|
||||
for relationship in reasoning.get("related_signals", []):
|
||||
target_signal_id = str(relationship.get("signal_id") or "")
|
||||
if target_signal_id == source_id or target_signal_id not in record_by_id:
|
||||
issues.append({
|
||||
"source_signal_id": source_id,
|
||||
"target_type": "signal",
|
||||
"target_signal_id": target_signal_id,
|
||||
"issue": "self-link" if target_signal_id == source_id else "unresolved-signal-target",
|
||||
})
|
||||
continue
|
||||
target_path = f"signals/{target_signal_id}.md"
|
||||
edge = {
|
||||
"connection_id": connection_identifier(source_id, "signal", target_signal_id, relationship.get("relationship", "illustrates")),
|
||||
"source_signal_id": source_id,
|
||||
"source_label": titles[source_id],
|
||||
"source_page_path": source_page,
|
||||
"source_public_url": public_repository_url(settings, f"data/insights-hub/{source_page}"),
|
||||
"target_type": "signal",
|
||||
"target_id": target_signal_id,
|
||||
"label": titles[target_signal_id],
|
||||
"relationship": relationship.get("relationship", "illustrates"),
|
||||
"relevance": relationship.get("relevance"),
|
||||
"review_status": relationship.get("review_status", "machine-proposed"),
|
||||
"repository_path": f"data/insights-hub/{target_path}",
|
||||
"locator": None,
|
||||
"relative_url": target_path,
|
||||
"page_relative_url": f"{target_signal_id}.md",
|
||||
"public_url": public_repository_url(settings, f"data/insights-hub/{target_path}"),
|
||||
}
|
||||
connections.append(edge)
|
||||
outgoing[source_id].append(edge)
|
||||
incoming_signals[target_signal_id].append(edge)
|
||||
|
||||
connections.sort(key=lambda item: (item["source_signal_id"], item["target_type"], item["target_id"], item["relationship"]))
|
||||
for values in outgoing.values():
|
||||
values.sort(key=lambda item: (item["target_type"], item["label"], item["relationship"]))
|
||||
for values in incoming_signals.values():
|
||||
values.sort(key=lambda item: (-(item.get("relevance") or 0), item["source_label"], item["relationship"]))
|
||||
|
||||
signal_backlinks = [
|
||||
{
|
||||
"signal_id": signal_id,
|
||||
"label": titles[signal_id],
|
||||
"page_path": f"signals/{signal_id}.md",
|
||||
"incoming": [
|
||||
{
|
||||
"connection_id": edge["connection_id"],
|
||||
"source_signal_id": edge["source_signal_id"],
|
||||
"source_label": edge["source_label"],
|
||||
"relationship": edge["relationship"],
|
||||
"relevance": edge["relevance"],
|
||||
"source_page_path": edge["source_page_path"],
|
||||
"source_public_url": edge["source_public_url"],
|
||||
}
|
||||
for edge in incoming_signals[signal_id]
|
||||
],
|
||||
}
|
||||
for signal_id in sorted(incoming_signals)
|
||||
if incoming_signals[signal_id]
|
||||
]
|
||||
core_section_backlinks = [
|
||||
{
|
||||
"target_id": target_id,
|
||||
"document_id": edges[0]["document_id"],
|
||||
"section_id": edges[0]["section_id"],
|
||||
"label": edges[0]["label"],
|
||||
"repository_path": edges[0]["repository_path"],
|
||||
"locator": edges[0]["locator"],
|
||||
"public_url": edges[0]["public_url"],
|
||||
"incoming": [
|
||||
{
|
||||
"connection_id": edge["connection_id"],
|
||||
"source_signal_id": edge["source_signal_id"],
|
||||
"source_label": edge["source_label"],
|
||||
"relationship": edge["relationship"],
|
||||
"relevance": edge["relevance"],
|
||||
"source_page_path": edge["source_page_path"],
|
||||
"source_public_url": edge["source_public_url"],
|
||||
}
|
||||
for edge in sorted(edges, key=lambda item: (item["source_label"], item["relationship"]))
|
||||
],
|
||||
}
|
||||
for target_id, edges in sorted(core_backlinks.items())
|
||||
]
|
||||
payload = {
|
||||
"schema_version": "1.0",
|
||||
"generated_at": utc_now(),
|
||||
"connection_count": len(connections),
|
||||
"core_section_connection_count": sum(1 for item in connections if item["target_type"] == "core-section"),
|
||||
"signal_connection_count": sum(1 for item in connections if item["target_type"] == "signal"),
|
||||
"connections": connections,
|
||||
"signal_backlinks": signal_backlinks,
|
||||
"core_section_backlinks": core_section_backlinks,
|
||||
}
|
||||
return payload, outgoing, incoming_signals, issues
|
||||
|
||||
|
||||
def derivative_json_paths(base: Path) -> list[Path]:
|
||||
root = base / "derivatives"
|
||||
if not root.exists():
|
||||
return []
|
||||
return sorted(path for path in root.glob("*/*.json") if path.is_file())
|
||||
|
||||
|
||||
def derivative_lineage_status(
|
||||
derivative: dict[str, Any],
|
||||
records_by_id: dict[str, dict[str, Any]],
|
||||
connections_by_id: dict[str, dict[str, Any]],
|
||||
) -> str:
|
||||
record = records_by_id.get(str(derivative.get("source_signal_id") or ""))
|
||||
if not record or record.get("reasoning", {}).get("status") != "complete":
|
||||
return "source-unavailable"
|
||||
lineage = derivative.get("lineage", {})
|
||||
if lineage.get("source_record_hash") != record.get("provenance", {}).get("source_hash"):
|
||||
return "stale"
|
||||
if lineage.get("source_reasoning_hash") != sha256_json(record.get("reasoning", {})):
|
||||
return "stale"
|
||||
connection_ids = [item.get("connection_id") for item in derivative.get("references", [])]
|
||||
if any(connection_id not in connections_by_id for connection_id in connection_ids):
|
||||
return "broken-reference"
|
||||
selected = [connections_by_id[connection_id] for connection_id in connection_ids]
|
||||
if lineage.get("selected_connections_hash") != sha256_json(selected):
|
||||
return "broken-reference"
|
||||
return "current"
|
||||
|
||||
|
||||
def render_derivative_page(derivative: dict[str, Any], lineage_status: str) -> str:
|
||||
title = derivative.get("title") or derivative["id"]
|
||||
lines = [
|
||||
f"# {markdown_clean(title)}", "",
|
||||
f"**Derivative ID:** `{derivative['id']}`", "",
|
||||
f"**Source signal:** [{derivative['source_signal_id']}](../../signals/{derivative['source_signal_id']}.md)", "",
|
||||
f"**Artifact:** {derivative['artifact_type']} · {derivative['channel']}", "",
|
||||
f"**Review:** {derivative['review']['status']}", "",
|
||||
f"**Lineage:** {lineage_status}", "",
|
||||
"## Draft", "", markdown_clean(derivative["content"]), "",
|
||||
]
|
||||
if derivative.get("call_to_action"):
|
||||
lines.extend(["## Call to action", "", markdown_clean(derivative["call_to_action"]), ""])
|
||||
if derivative.get("references"):
|
||||
lines.extend(["## Connected Future Map context", ""])
|
||||
for reference in derivative["references"]:
|
||||
url = reference["url"]
|
||||
if not url.startswith(("http://", "https://")):
|
||||
url = f"../../{url}"
|
||||
lines.append(f"- [{markdown_clean(reference['label'])} ({reference['relationship']})]({url})")
|
||||
lines.append("")
|
||||
if derivative.get("claims_used"):
|
||||
lines.extend(["## Claims used", ""])
|
||||
for claim in derivative["claims_used"]:
|
||||
lines.append(f"- {markdown_clean(claim['text'])} _({claim['type']}; {claim['confidence']} confidence)_")
|
||||
lines.append("")
|
||||
lines.extend([f"[Structured derivative]({derivative['id']}.json)", ""])
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def render_derivatives(
|
||||
base: Path,
|
||||
records: list[dict[str, Any]],
|
||||
connections: list[dict[str, Any]],
|
||||
) -> tuple[dict[str, list[dict[str, Any]]], dict[str, int], dict[str, int]]:
|
||||
records_by_id = {record["id"]: record for record in records}
|
||||
connections_by_id = {edge["connection_id"]: edge for edge in connections}
|
||||
by_source: dict[str, list[dict[str, Any]]] = {record["id"]: [] for record in records}
|
||||
review_counts: dict[str, int] = {}
|
||||
lineage_counts: dict[str, int] = {}
|
||||
index_lines: list[str] = []
|
||||
review_lines: list[str] = []
|
||||
collection = [
|
||||
"# Future Map Authored Derivatives", "",
|
||||
"Versioned drafts derived from enriched Future Map signals. Each artifact preserves its selected claims, references, and lineage.", "",
|
||||
"- [Machine-readable derivative index](../derivative-index.jsonl)",
|
||||
"- [Derivative review queue](../review/derivatives.jsonl)", "",
|
||||
"## All derivatives", "",
|
||||
]
|
||||
for path in derivative_json_paths(base):
|
||||
derivative = load_json(path)
|
||||
if not derivative:
|
||||
continue
|
||||
status = derivative_lineage_status(derivative, records_by_id, connections_by_id)
|
||||
review_status = derivative.get("review", {}).get("status", "draft")
|
||||
lineage_counts[status] = lineage_counts.get(status, 0) + 1
|
||||
review_counts[review_status] = review_counts.get(review_status, 0) + 1
|
||||
source_id = str(derivative.get("source_signal_id") or "")
|
||||
source_file_id = source_id.removeprefix("fm-signal-")
|
||||
markdown_path = path.with_suffix(".md")
|
||||
write_text_if_changed(markdown_path, render_derivative_page(derivative, status))
|
||||
relative_json = path.relative_to(base).as_posix()
|
||||
relative_markdown = markdown_path.relative_to(base).as_posix()
|
||||
entry = {
|
||||
"id": derivative.get("id"), "source_signal_id": source_id,
|
||||
"artifact_type": derivative.get("artifact_type"), "channel": derivative.get("channel"),
|
||||
"audiences": derivative.get("audiences", []), "objective": derivative.get("objective"),
|
||||
"title": derivative.get("title"), "content": derivative.get("content"),
|
||||
"review_status": review_status, "publication_status": derivative.get("publication", {}).get("status"),
|
||||
"lineage_status": status, "json_path": relative_json, "page_path": relative_markdown,
|
||||
}
|
||||
index_lines.append(json.dumps(entry, ensure_ascii=False))
|
||||
if source_id in by_source:
|
||||
by_source[source_id].append(entry)
|
||||
if review_status in {"draft", "human-reviewed"} or status != "current":
|
||||
review_lines.append(json.dumps(entry, ensure_ascii=False))
|
||||
collection.append(f"- [{markdown_clean(derivative.get('title') or derivative['id'])}]({source_file_id}/{derivative['id']}.md) — {derivative['artifact_type']} · {review_status} · {status}")
|
||||
collection.append("")
|
||||
write_text_if_changed(base / "derivative-index.jsonl", "\n".join(index_lines) + ("\n" if index_lines else ""))
|
||||
write_text_if_changed(base / "review" / "derivatives.jsonl", "\n".join(review_lines) + ("\n" if review_lines else ""))
|
||||
write_text_if_changed(base / "derivatives" / "README.md", "\n".join(collection))
|
||||
return by_source, review_counts, lineage_counts
|
||||
|
||||
|
||||
def render_signal_page(
|
||||
record: dict[str, Any],
|
||||
outgoing: list[dict[str, Any]],
|
||||
incoming: list[dict[str, Any]],
|
||||
derivatives: list[dict[str, Any]],
|
||||
) -> str:
|
||||
source = record["source_record"]
|
||||
reasoning = record["reasoning"]
|
||||
title = source.get("title") or f"Future Map Signal {source['source_file_id']}"
|
||||
lines = [
|
||||
f"# {markdown_clean(title)}", "",
|
||||
f"**Signal ID:** `{record['id']}`", "",
|
||||
f"**Date:** {source.get('date') or source.get('date_original') or 'Unknown'}", "",
|
||||
f"**Reasoning:** {reasoning.get('status', 'pending')}", "",
|
||||
"[Future Map Insights Hub](../future-map-insights.md)", "",
|
||||
]
|
||||
if source.get("summary"):
|
||||
lines.extend(["## Source observation", "", markdown_clean(source["summary"]), ""])
|
||||
capture_context = source.get("capture_context", {}).get("text")
|
||||
if capture_context:
|
||||
lines.extend(["## Capture context", "", markdown_clean(capture_context), ""])
|
||||
if reasoning.get("analysis"):
|
||||
lines.extend(["## Future Map analysis", "", markdown_clean(reasoning["analysis"]), ""])
|
||||
if reasoning.get("implications"):
|
||||
lines.extend(["## Implications", ""] + [f"- {markdown_clean(item)}" for item in reasoning["implications"]] + [""])
|
||||
classification = reasoning.get("classification", {})
|
||||
if reasoning.get("status") == "complete":
|
||||
lines.extend(["## Classification", ""])
|
||||
for label, key in (("Signal types", "signal_types"), ("Topics", "topics"), ("Future Map concepts", "future_map_concepts"), ("Time horizons", "time_horizons")):
|
||||
values = classification.get(key, [])
|
||||
if values:
|
||||
lines.append(f"- **{label}:** {', '.join(markdown_clean(value) for value in values)}")
|
||||
lines.extend([f"- **Direction:** {classification.get('direction', 'uncertain')}", f"- **Maturity:** {classification.get('maturity', 'uncertain')}", f"- **Confidence:** {reasoning.get('confidence', 'unrated')}", ""])
|
||||
if outgoing:
|
||||
lines.extend(["## Connected Future Map context", ""])
|
||||
for edge in outgoing:
|
||||
prefix = "Core section" if edge["target_type"] == "core-section" else "Related signal"
|
||||
lines.append(f"- [{prefix}: {markdown_clean(edge['label'])} ({edge['relationship']})]({edge['page_relative_url']})")
|
||||
lines.append("")
|
||||
if incoming:
|
||||
lines.extend(["## Signals that reference this signal", ""])
|
||||
for edge in incoming[:20]:
|
||||
lines.append(f"- [{markdown_clean(edge['source_label'])} ({edge['relationship']})]({edge['source_signal_id']}.md)")
|
||||
if len(incoming) > 20:
|
||||
lines.append(f"- {len(incoming) - 20} additional backlinks are available in the [connection index](../indexes/connections.json).")
|
||||
lines.append("")
|
||||
if derivatives:
|
||||
lines.extend(["## Authored derivatives", ""])
|
||||
for derivative in derivatives:
|
||||
label = derivative.get("title") or derivative["id"]
|
||||
page = f"../{derivative['page_path']}"
|
||||
lines.append(f"- [{markdown_clean(label)}]({page}) — {derivative['artifact_type']} · {derivative['review_status']} · {derivative['lineage_status']}")
|
||||
lines.append("")
|
||||
for item in record.get("media", []):
|
||||
public_path = item.get("public_path")
|
||||
if item.get("copy_status") != "copied" or not public_path:
|
||||
continue
|
||||
page_path = f"../{public_path}"
|
||||
if item.get("media_type") == "image":
|
||||
lines.extend([f"", ""])
|
||||
else:
|
||||
lines.extend([f"[Connected {item.get('media_type', 'file')}]({page_path})", ""])
|
||||
if record.get("links"):
|
||||
lines.extend(["## Source links", ""] + [f"- [{markdown_clean(link.get('title') or link['url'])}]({link['url']})" for link in record["links"]] + [""])
|
||||
lines.extend([f"[Authoritative structured record](../hrecords/{source['source_file_id']}.json)", ""])
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def render_outputs(base: Path) -> dict[str, int]:
|
||||
records = records_from_output(base)
|
||||
records.sort(key=lambda item: (item.get("source_record", {}).get("date") or "", item.get("id", "")), reverse=True)
|
||||
content_index = load_json(base.parents[1] / "content-index.json") if len(base.parents) > 1 else None
|
||||
document_paths = {
|
||||
item.get("content_id"): item.get("path")
|
||||
for item in (content_index or {}).get("items", [])
|
||||
if item.get("content_id") and item.get("path")
|
||||
}
|
||||
settings = publication_settings(base)
|
||||
connection_data, outgoing, incoming, connection_issues = resolve_connections(records, base)
|
||||
previous_connections = load_json(base / "indexes" / "connections.json")
|
||||
if previous_connections:
|
||||
comparable_old = dict(previous_connections)
|
||||
comparable_new = dict(connection_data)
|
||||
comparable_old.pop("generated_at", None)
|
||||
comparable_new.pop("generated_at", None)
|
||||
if comparable_old == comparable_new:
|
||||
connection_data["generated_at"] = previous_connections.get("generated_at")
|
||||
write_json_if_changed(base / "indexes" / "connections.json", connection_data)
|
||||
write_text_if_changed(base / "review" / "connection-issues.jsonl", "\n".join(json.dumps(item, ensure_ascii=False) for item in connection_issues) + ("\n" if connection_issues else ""))
|
||||
derivatives_by_source, derivative_review_counts, derivative_lineage_counts = render_derivatives(
|
||||
base, records, connection_data["connections"]
|
||||
)
|
||||
|
||||
signal_directory = base / "signals"
|
||||
signal_directory.mkdir(parents=True, exist_ok=True)
|
||||
expected_pages: set[str] = set()
|
||||
for record in records:
|
||||
page_name = f"{record['id']}.md"
|
||||
expected_pages.add(page_name)
|
||||
write_text_if_changed(
|
||||
signal_directory / page_name,
|
||||
render_signal_page(record, outgoing[record["id"]], incoming[record["id"]], derivatives_by_source[record["id"]]),
|
||||
)
|
||||
for page in signal_directory.glob("fm-signal-*.md"):
|
||||
if page.name not in expected_pages:
|
||||
page.unlink()
|
||||
collection_page = [
|
||||
"# Future Map Signal Pages", "",
|
||||
f"Browse {len(records)} generated public signal pages.", "",
|
||||
"- [Reverse-chronological Insights Hub](../future-map-insights.md)",
|
||||
"- [Machine-readable signal index](../signal-index.jsonl)",
|
||||
"- [Resolved connection and backlink index](../indexes/connections.json)",
|
||||
"- [Authored derivative collection](../derivatives/README.md)",
|
||||
"", "## All signals", "",
|
||||
]
|
||||
for record in records:
|
||||
source = record["source_record"]
|
||||
title = source.get("title") or f"Future Map Signal {source['source_file_id']}"
|
||||
date_label = source.get("date") or source.get("date_original") or "Unknown date"
|
||||
collection_page.append(f"- [{markdown_clean(title)}]({record['id']}.md) — {date_label}")
|
||||
collection_page.append("")
|
||||
write_text_if_changed(signal_directory / "README.md", "\n".join(collection_page))
|
||||
|
||||
counts = {state: 0 for state in ("pending", "complete", "stale", "failed", "excluded")}
|
||||
readiness_counts = {state: 0 for state in ("unassessed", "sufficient", "partial", "insufficient", "unavailable", "needs-human-context")}
|
||||
inspection_counts: dict[str, int] = {}
|
||||
@@ -587,8 +1001,9 @@ def render_outputs(base: Path) -> dict[str, int]:
|
||||
summary = source.get("summary")
|
||||
capture_context = source.get("capture_context", {}).get("text")
|
||||
intended_use = source.get("intended_use", [])
|
||||
signal_page = f"signals/{record['id']}.md"
|
||||
md.extend([
|
||||
f"## {title}", "",
|
||||
f"## [{markdown_clean(title)}]({signal_page})", "",
|
||||
f"**Signal ID:** `{record['id']}`", "",
|
||||
f"**Date:** {source.get('date') or source.get('date_original') or 'Unknown'}", "",
|
||||
f"**Capture type:** {source.get('capture_type', 'legacy')}", "",
|
||||
@@ -606,81 +1021,72 @@ def render_outputs(base: Path) -> dict[str, int]:
|
||||
if reasoning.get("implications"):
|
||||
md.extend(["### Implications", ""] + [f"- {markdown_clean(item)}" for item in reasoning["implications"]] + [""])
|
||||
classification = reasoning.get("classification", {})
|
||||
if reasoning.get("status") == "complete":
|
||||
if state == "complete":
|
||||
md.extend(["### Future Map classification", ""])
|
||||
for label, key in (
|
||||
("Signal types", "signal_types"),
|
||||
("Topics", "topics"),
|
||||
("Future Map concepts", "future_map_concepts"),
|
||||
("Time horizons", "time_horizons"),
|
||||
):
|
||||
for label, key in (("Signal types", "signal_types"), ("Topics", "topics"), ("Future Map concepts", "future_map_concepts"), ("Time horizons", "time_horizons")):
|
||||
values = classification.get(key, [])
|
||||
if values:
|
||||
md.append(f"- **{label}:** {', '.join(markdown_clean(value) for value in values)}")
|
||||
md.extend([
|
||||
f"- **Direction:** {markdown_clean(classification.get('direction', 'uncertain'))}",
|
||||
f"- **Maturity:** {markdown_clean(classification.get('maturity', 'uncertain'))}",
|
||||
f"- **Confidence:** {markdown_clean(reasoning.get('confidence', 'unrated'))}",
|
||||
"",
|
||||
])
|
||||
related_documents = reasoning.get("related_documents", [])
|
||||
related_signals = reasoning.get("related_signals", [])
|
||||
if related_documents or related_signals:
|
||||
md.extend([f"- **Direction:** {classification.get('direction', 'uncertain')}", f"- **Maturity:** {classification.get('maturity', 'uncertain')}", f"- **Confidence:** {reasoning.get('confidence', 'unrated')}", ""])
|
||||
if outgoing[record["id"]]:
|
||||
md.extend(["### Connected Future Map context", ""])
|
||||
for item in related_documents:
|
||||
document_id = item.get("document_id")
|
||||
relationship = item.get("relationship", "related")
|
||||
path = document_paths.get(document_id)
|
||||
label = f"Core document: {document_id} ({relationship})"
|
||||
md.append(f"- [{label}](../../{path})" if path else f"- {label}")
|
||||
for item in related_signals:
|
||||
signal_id = item.get("signal_id", "")
|
||||
relationship = item.get("relationship", "related")
|
||||
source_file_id = signal_id.removeprefix("fm-signal-")
|
||||
md.append(f"- [Related signal: {signal_id} ({relationship})](hrecords/{source_file_id}.json)")
|
||||
for edge in outgoing[record["id"]]:
|
||||
prefix = "Core section" if edge["target_type"] == "core-section" else "Related signal"
|
||||
md.append(f"- [{prefix}: {markdown_clean(edge['label'])} ({edge['relationship']})]({edge['relative_url']})")
|
||||
md.append("")
|
||||
if incoming[record["id"]]:
|
||||
md.extend(["### Referenced by", ""])
|
||||
for edge in incoming[record["id"]][:5]:
|
||||
md.append(f"- [{markdown_clean(edge['source_label'])} ({edge['relationship']})]({edge['source_page_path']})")
|
||||
if len(incoming[record["id"]]) > 5:
|
||||
md.append(f"- {len(incoming[record['id']]) - 5} additional backlinks are listed on the [signal page]({signal_page}).")
|
||||
md.append("")
|
||||
for item in record.get("media", []):
|
||||
public_path = item.get("public_path")
|
||||
if public_path:
|
||||
media_names.add(Path(public_path).name)
|
||||
if item.get("media_type") == "image" and item.get("copy_status") == "copied" and public_path:
|
||||
md.extend([f"", ""])
|
||||
md.extend([f"", ""])
|
||||
elif item.get("copy_status") == "copied" and public_path:
|
||||
md.extend([f"[Connected {item.get('media_type', 'file')}]({public_path})", ""])
|
||||
if record.get("links"):
|
||||
md.extend(["### Links", ""] + [f"- [{link.get('title') or link['url']}]({link['url']})" for link in record["links"]] + [""])
|
||||
md.extend([f"[Structured record](hrecords/{source['source_file_id']}.json)", "", "---", ""])
|
||||
md.extend(["### Links", ""] + [f"- [{markdown_clean(link.get('title') or link['url'])}]({link['url']})" for link in record["links"]] + [""])
|
||||
md.extend([f"[Readable signal page]({signal_page}) · [Structured record](hrecords/{source['source_file_id']}.json)", "", "---", ""])
|
||||
|
||||
index_lines.append(json.dumps({
|
||||
"id": record["id"], "source_file_id": source["source_file_id"], "hub_id": source.get("hub_id"), "date": source.get("date"),
|
||||
"title": title, "summary": summary, "capture_type": source.get("capture_type", "legacy"),
|
||||
"capture_context": capture_context, "intended_use": intended_use, "reasoning_status": state,
|
||||
"source_readiness_status": readiness_state,
|
||||
"required_media_pending": required_media_pending,
|
||||
"signal_types": reasoning.get("classification", {}).get("signal_types", []),
|
||||
"topics": reasoning.get("classification", {}).get("topics", []),
|
||||
"source_readiness_status": readiness_state, "required_media_pending": required_media_pending,
|
||||
"signal_types": classification.get("signal_types", []), "topics": classification.get("topics", []),
|
||||
"related_documents": [item.get("document_id") for item in reasoning.get("related_documents", [])],
|
||||
"related_signals": [item.get("signal_id") for item in reasoning.get("related_signals", [])],
|
||||
"record_path": f"hrecords/{source['source_file_id']}.json",
|
||||
"connection_ids": [edge["connection_id"] for edge in outgoing[record["id"]]],
|
||||
"backlink_connection_ids": [edge["connection_id"] for edge in incoming[record["id"]]],
|
||||
"derivative_ids": [item["id"] for item in derivatives_by_source[record["id"]]],
|
||||
"record_path": f"hrecords/{source['source_file_id']}.json", "page_path": signal_page,
|
||||
"page_url": public_repository_url(settings, f"data/insights-hub/{signal_page}"),
|
||||
"media_paths": [item.get("public_path") for item in record.get("media", []) if item.get("public_path")],
|
||||
}, ensure_ascii=False))
|
||||
if state in {"pending", "stale", "failed"} or assessment.get("review_required") or required_media_pending or record.get("review", {}).get("warnings"):
|
||||
pending_lines.append(json.dumps({
|
||||
"id": record["id"], "source_file_id": source["source_file_id"], "hub_id": source.get("hub_id"), "date": source.get("date"),
|
||||
"title": title, "reasoning_status": state,
|
||||
"source_readiness_status": readiness_state,
|
||||
"source_readiness_review_required": bool(assessment.get("review_required")),
|
||||
"required_media_pending": required_media_pending,
|
||||
"warnings": record.get("review", {}).get("warnings", []),
|
||||
"record_path": f"hrecords/{source['source_file_id']}.json",
|
||||
"title": title, "reasoning_status": state, "source_readiness_status": readiness_state,
|
||||
"source_readiness_review_required": bool(assessment.get("review_required")), "required_media_pending": required_media_pending,
|
||||
"warnings": record.get("review", {}).get("warnings", []), "record_path": f"hrecords/{source['source_file_id']}.json",
|
||||
}, ensure_ascii=False))
|
||||
|
||||
manifest = {
|
||||
"schema_version": "1.0", "pipeline_version": PIPELINE_VERSION,
|
||||
"required_tag": "Future Map", "record_count": len(records),
|
||||
"schema_version": "1.2", "pipeline_version": PIPELINE_VERSION,
|
||||
"required_tag": "Future Map", "record_count": len(records), "signal_page_count": len(expected_pages),
|
||||
"connection_count": connection_data["connection_count"],
|
||||
"core_section_connection_count": connection_data["core_section_connection_count"],
|
||||
"signal_connection_count": connection_data["signal_connection_count"],
|
||||
"derivative_count": sum(derivative_review_counts.values()),
|
||||
"derivative_review_counts": derivative_review_counts,
|
||||
"derivative_lineage_counts": derivative_lineage_counts,
|
||||
"media_file_count": len(media_names), "reasoning_counts": counts,
|
||||
"source_assessment_counts": readiness_counts,
|
||||
"media_inspection_counts": inspection_counts,
|
||||
"source_assessment_counts": readiness_counts, "media_inspection_counts": inspection_counts,
|
||||
"latest_source_date": max((item["source_record"].get("date") or "" for item in records), default="") or None,
|
||||
"generated_at": utc_now(),
|
||||
}
|
||||
@@ -702,17 +1108,102 @@ def render_outputs(base: Path) -> dict[str, int]:
|
||||
def validate_output(base: Path) -> tuple[int, int]:
|
||||
errors: list[str] = []
|
||||
warnings = 0
|
||||
for path in iter_json_files(base / "hrecords"):
|
||||
record_paths = list(iter_json_files(base / "hrecords"))
|
||||
signal_ids: set[str] = set()
|
||||
for path in record_paths:
|
||||
record = load_json(path)
|
||||
if not record:
|
||||
errors.append(f"{path.name}: unreadable record")
|
||||
continue
|
||||
signal_ids.add(record.get("id", ""))
|
||||
for issue in basic_validate(record, base) + schema_validate(record, SCHEMA_PATH):
|
||||
errors.append(f"{path.name}: {issue}")
|
||||
warnings += len(record.get("review", {}).get("warnings", []))
|
||||
|
||||
connections_path = base / "indexes" / "connections.json"
|
||||
connections = load_json(connections_path)
|
||||
if not connections:
|
||||
errors.append("missing or unreadable indexes/connections.json")
|
||||
else:
|
||||
if CONNECTIONS_SCHEMA_PATH.exists():
|
||||
errors.extend(f"connections.json: {issue}" for issue in schema_validate(connections, CONNECTIONS_SCHEMA_PATH))
|
||||
if connections.get("connection_count") != len(connections.get("connections", [])):
|
||||
errors.append("connections.json connection_count does not match connections array")
|
||||
for edge in connections.get("connections", []):
|
||||
if edge.get("source_signal_id") not in signal_ids:
|
||||
errors.append(f"connection has missing source signal: {edge.get('connection_id')}")
|
||||
if edge.get("target_type") == "signal":
|
||||
if edge.get("target_id") not in signal_ids:
|
||||
errors.append(f"connection has missing target signal: {edge.get('connection_id')}")
|
||||
target_page = base / str(edge.get("relative_url") or "")
|
||||
if not target_page.exists():
|
||||
errors.append(f"connection has missing signal page: {edge.get('connection_id')}")
|
||||
elif edge.get("target_type") == "core-section":
|
||||
repository_root = base.parents[1] if len(base.parents) > 1 else base
|
||||
if not (repository_root / str(edge.get("repository_path") or "")).exists():
|
||||
errors.append(f"connection has missing core document: {edge.get('connection_id')}")
|
||||
|
||||
records_by_id = {
|
||||
record["id"]: record
|
||||
for path in record_paths
|
||||
if (record := load_json(path)) and record.get("id")
|
||||
}
|
||||
connections_by_id = {
|
||||
edge["connection_id"]: edge
|
||||
for edge in (connections or {}).get("connections", [])
|
||||
if edge.get("connection_id")
|
||||
}
|
||||
derivative_paths = derivative_json_paths(base)
|
||||
for path in derivative_paths:
|
||||
derivative = load_json(path)
|
||||
if not derivative:
|
||||
errors.append(f"{path}: unreadable derivative")
|
||||
continue
|
||||
errors.extend(f"{path.name}: {issue}" for issue in schema_validate(derivative, DERIVATIVE_SCHEMA_PATH))
|
||||
source_id = derivative.get("source_signal_id")
|
||||
source_file_id = str(source_id or "").removeprefix("fm-signal-")
|
||||
if path.parent.name != source_file_id:
|
||||
errors.append(f"{path.name}: derivative folder does not match source signal")
|
||||
if path.stem != derivative.get("id"):
|
||||
errors.append(f"{path.name}: derivative filename does not match ID")
|
||||
status = derivative_lineage_status(derivative, records_by_id, connections_by_id)
|
||||
if status == "broken-reference":
|
||||
errors.append(f"{path.name}: derivative has a broken connection reference")
|
||||
elif status != "current":
|
||||
warnings += 1
|
||||
for reference in derivative.get("references", []):
|
||||
edge = connections_by_id.get(reference.get("connection_id"))
|
||||
if edge and edge.get("source_signal_id") != source_id:
|
||||
errors.append(f"{path.name}: connection does not originate from source signal")
|
||||
if not path.with_suffix(".md").exists():
|
||||
errors.append(f"{path.name}: missing generated Markdown derivative")
|
||||
|
||||
derivative_index_path = base / "derivative-index.jsonl"
|
||||
derivative_index_lines = [
|
||||
line for line in derivative_index_path.read_text(encoding="utf-8").splitlines() if line.strip()
|
||||
] if derivative_index_path.exists() else []
|
||||
if len(derivative_index_lines) != len(derivative_paths):
|
||||
errors.append(
|
||||
f"derivative index count {len(derivative_index_lines)} does not match derivative count {len(derivative_paths)}"
|
||||
)
|
||||
|
||||
issue_path = base / "review" / "connection-issues.jsonl"
|
||||
connection_issues = [line for line in issue_path.read_text(encoding="utf-8").splitlines() if line.strip()] if issue_path.exists() else []
|
||||
for issue in connection_issues:
|
||||
errors.append(f"unresolved connection: {issue}")
|
||||
|
||||
page_paths = list((base / "signals").glob("fm-signal-*.md")) if (base / "signals").exists() else []
|
||||
if len(page_paths) != len(record_paths):
|
||||
errors.append(f"signal page count {len(page_paths)} does not match record count {len(record_paths)}")
|
||||
for signal_id in signal_ids:
|
||||
if not (base / "signals" / f"{signal_id}.md").exists():
|
||||
errors.append(f"missing signal page for {signal_id}")
|
||||
for error in errors:
|
||||
print("ERROR", error)
|
||||
print(f"Validated records: {len(list((base / 'hrecords').glob('*.json')))}")
|
||||
print(f"Validated records: {len(record_paths)}")
|
||||
print(f"Validated signal pages: {len(page_paths)}")
|
||||
print(f"Validated connections: {len((connections or {}).get('connections', []))}")
|
||||
print(f"Validated derivatives: {len(derivative_paths)}")
|
||||
print(f"Validation errors: {len(errors)}")
|
||||
print(f"Review warnings: {warnings}")
|
||||
return len(errors), warnings
|
||||
@@ -867,6 +1358,149 @@ def validate_readiness_patch(patch: dict[str, Any], record: dict[str, Any]) -> l
|
||||
return errors
|
||||
|
||||
|
||||
def validate_derivative_patch(patch: dict[str, Any]) -> list[str]:
|
||||
errors = schema_validate(patch, DERIVATIVE_PATCH_SCHEMA_PATH)
|
||||
required = {
|
||||
"schema_version", "derivative_id", "source_signal_id", "artifact_type", "channel",
|
||||
"audiences", "objective", "title", "content", "content_format", "call_to_action",
|
||||
"claim_indexes", "connection_ids", "authoring_notes", "generated_by",
|
||||
"supersedes_derivative_id",
|
||||
}
|
||||
missing = required - set(patch)
|
||||
if missing:
|
||||
errors.append("missing fields: " + ", ".join(sorted(missing)))
|
||||
if len(str(patch.get("objective") or "")) < 10:
|
||||
errors.append("objective must contain at least 10 characters")
|
||||
if len(str(patch.get("content") or "")) < 20:
|
||||
errors.append("content must contain at least 20 characters")
|
||||
if not patch.get("audiences"):
|
||||
errors.append("at least one audience is required")
|
||||
return errors
|
||||
|
||||
|
||||
def command_apply_derivative(args: argparse.Namespace) -> int:
|
||||
base = Path(args.output_root).resolve() if args.output_root else BASE_DIR
|
||||
patch = json.loads(Path(args.patch).read_text(encoding="utf-8"))
|
||||
if patch.get("source_signal_id") != args.record_id:
|
||||
raise RuntimeError("Patch source_signal_id does not match --record-id")
|
||||
issues = validate_derivative_patch(patch)
|
||||
if issues:
|
||||
for issue in issues:
|
||||
print("ERROR", issue)
|
||||
return 1
|
||||
source_file_id = args.record_id.removeprefix("fm-signal-")
|
||||
if not patch["derivative_id"].startswith(f"fm-derivative-{source_file_id}-"):
|
||||
raise RuntimeError("Derivative ID must include the source file ID")
|
||||
record_path = base / "hrecords" / f"{source_file_id}.json"
|
||||
record = load_json(record_path)
|
||||
if not record or record.get("id") != args.record_id:
|
||||
raise FileNotFoundError(f"Signal record not found: {record_path}")
|
||||
reasoning = record.get("reasoning", {})
|
||||
if reasoning.get("status") != "complete":
|
||||
raise RuntimeError("Derivative authoring requires complete reasoning")
|
||||
|
||||
claims = reasoning.get("claims", [])
|
||||
claim_indexes = patch.get("claim_indexes", [])
|
||||
invalid_claim_indexes = [index for index in claim_indexes if not isinstance(index, int) or index < 0 or index >= len(claims)]
|
||||
if invalid_claim_indexes:
|
||||
raise RuntimeError("Invalid claim indexes: " + ", ".join(str(index) for index in invalid_claim_indexes))
|
||||
claims_used = [
|
||||
{
|
||||
"claim_index": index,
|
||||
"text": claims[index]["text"],
|
||||
"type": claims[index]["type"],
|
||||
"confidence": claims[index]["confidence"],
|
||||
}
|
||||
for index in claim_indexes
|
||||
]
|
||||
|
||||
connection_data = load_json(base / "indexes" / "connections.json") or {}
|
||||
connections_by_id = {item["connection_id"]: item for item in connection_data.get("connections", [])}
|
||||
selected_connections: list[dict[str, Any]] = []
|
||||
for connection_id in patch.get("connection_ids", []):
|
||||
edge = connections_by_id.get(connection_id)
|
||||
if not edge:
|
||||
raise RuntimeError(f"Unknown connection ID: {connection_id}")
|
||||
if edge.get("source_signal_id") != args.record_id:
|
||||
raise RuntimeError(f"Connection does not originate from {args.record_id}: {connection_id}")
|
||||
selected_connections.append(edge)
|
||||
references = [
|
||||
{
|
||||
"connection_id": edge["connection_id"],
|
||||
"target_type": edge["target_type"],
|
||||
"target_id": edge["target_id"],
|
||||
"relationship": edge["relationship"],
|
||||
"label": edge["label"],
|
||||
"repository_path": edge["repository_path"],
|
||||
"url": edge.get("public_url") or edge["relative_url"],
|
||||
}
|
||||
for edge in selected_connections
|
||||
]
|
||||
|
||||
derivative_id = patch["derivative_id"]
|
||||
output_path = base / "derivatives" / source_file_id / f"{derivative_id}.json"
|
||||
patch_hash = sha256_json(patch)
|
||||
existing = load_json(output_path) if output_path.exists() else None
|
||||
if existing:
|
||||
if existing.get("lineage", {}).get("authoring_patch_hash") == patch_hash:
|
||||
print(f"Derivative unchanged: {derivative_id}")
|
||||
render_outputs(base)
|
||||
errors, _ = validate_output(base)
|
||||
return 1 if errors else 0
|
||||
if not args.replace:
|
||||
raise RuntimeError("Derivative ID already exists with different content; use --replace intentionally")
|
||||
if existing.get("review", {}).get("status") not in {"draft", "rejected"}:
|
||||
raise RuntimeError("Only draft or rejected derivatives can be replaced")
|
||||
|
||||
supersedes = patch.get("supersedes_derivative_id")
|
||||
if supersedes:
|
||||
superseded_path = base / "derivatives" / source_file_id / f"{supersedes}.json"
|
||||
if not superseded_path.exists():
|
||||
raise RuntimeError(f"Superseded derivative does not exist for this source: {supersedes}")
|
||||
derivative = {
|
||||
"schema_version": "1.0",
|
||||
"id": derivative_id,
|
||||
"source_signal_id": args.record_id,
|
||||
"artifact_type": patch["artifact_type"],
|
||||
"channel": patch["channel"],
|
||||
"audiences": patch["audiences"],
|
||||
"objective": patch["objective"],
|
||||
"title": patch.get("title"),
|
||||
"content": patch["content"],
|
||||
"content_format": patch["content_format"],
|
||||
"call_to_action": patch.get("call_to_action"),
|
||||
"claims_used": claims_used,
|
||||
"references": references,
|
||||
"authoring": {
|
||||
"skill": "eddie-voice-writing",
|
||||
"source_repository": "ES-authoring-skills",
|
||||
"source_path": "skills/ES-writing-skill.md",
|
||||
"voice_profile": "eddie-soehnel",
|
||||
"authoring_notes": patch.get("authoring_notes", []),
|
||||
"generated_by": patch["generated_by"],
|
||||
"generated_at": utc_now(),
|
||||
},
|
||||
"review": {"status": "draft", "reviewer": None, "reviewed_at": None, "feedback": None},
|
||||
"publication": {"status": "not-published", "url": None, "published_at": None, "channel": None},
|
||||
"lineage": {
|
||||
"source_record_hash": record.get("provenance", {}).get("source_hash"),
|
||||
"source_reasoning_hash": sha256_json(reasoning),
|
||||
"selected_connections_hash": sha256_json(selected_connections),
|
||||
"authoring_patch_hash": patch_hash,
|
||||
"supersedes_derivative_id": supersedes,
|
||||
},
|
||||
}
|
||||
derivative_issues = schema_validate(derivative, DERIVATIVE_SCHEMA_PATH)
|
||||
if derivative_issues:
|
||||
for issue in derivative_issues:
|
||||
print("ERROR", issue)
|
||||
return 1
|
||||
write_json_if_changed(output_path, derivative)
|
||||
render_outputs(base)
|
||||
errors, _ = validate_output(base)
|
||||
return 1 if errors else 0
|
||||
|
||||
|
||||
def command_apply_readiness(args: argparse.Namespace) -> int:
|
||||
base = Path(args.output_root).resolve() if args.output_root else BASE_DIR
|
||||
patch = json.loads(Path(args.patch).read_text(encoding="utf-8"))
|
||||
@@ -975,6 +1609,11 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
apply_readiness.add_argument("--record-id", required=True)
|
||||
apply_readiness.add_argument("--patch", required=True)
|
||||
apply_readiness.add_argument("--output-root")
|
||||
apply_derivative = subparsers.add_parser("apply-derivative", help="Apply one validated authored-derivative patch.")
|
||||
apply_derivative.add_argument("--record-id", required=True)
|
||||
apply_derivative.add_argument("--patch", required=True)
|
||||
apply_derivative.add_argument("--output-root")
|
||||
apply_derivative.add_argument("--replace", action="store_true")
|
||||
return parser
|
||||
|
||||
|
||||
@@ -993,6 +1632,8 @@ def main() -> int:
|
||||
return command_apply_reasoning(args)
|
||||
if args.command == "apply-readiness":
|
||||
return command_apply_readiness(args)
|
||||
if args.command == "apply-derivative":
|
||||
return command_apply_derivative(args)
|
||||
return 2
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user