PlanOpticon

planopticon / video_processor / agent / skills / artifact_export.py
Source Blame History 94 lines
0981a08… noreply 1 """Skill: Export artifacts in agent-ready formats to a directory structure."""
0981a08… noreply 2
0981a08… noreply 3 import json
0981a08… noreply 4 from pathlib import Path
0981a08… noreply 5
0981a08… noreply 6 from video_processor.agent.skills.base import AgentContext, Artifact, Skill, register_skill
0981a08… noreply 7
0981a08… noreply 8 # Maps artifact_type to output filename
0981a08… noreply 9 _TYPE_TO_FILE = {
0981a08… noreply 10 "project_plan": "project_plan.md",
0981a08… noreply 11 "prd": "prd.md",
0981a08… noreply 12 "roadmap": "roadmap.md",
0981a08… noreply 13 "task_list": "tasks.json",
0981a08… noreply 14 "issues": "issues.json",
0981a08… noreply 15 "requirements": "requirements.json",
0981a08… noreply 16 }
0981a08… noreply 17
0981a08… noreply 18
0981a08… noreply 19 def _write_artifact(artifact: Artifact, output_dir: Path) -> dict:
0981a08… noreply 20 """Write a single artifact to the appropriate file. Returns manifest entry."""
0981a08… noreply 21 filename = _TYPE_TO_FILE.get(artifact.artifact_type)
0981a08… noreply 22 if filename:
0981a08… noreply 23 dest = output_dir / filename
0981a08… noreply 24 elif artifact.artifact_type == "document":
0981a08… noreply 25 docs_dir = output_dir / "docs"
0981a08… noreply 26 docs_dir.mkdir(parents=True, exist_ok=True)
0981a08… noreply 27 safe_name = artifact.name.replace(" ", "_").replace("/", "_").lower()
0981a08… noreply 28 ext = ".json" if artifact.format == "json" else ".md"
0981a08… noreply 29 dest = docs_dir / f"{safe_name}{ext}"
0981a08… noreply 30 else:
0981a08… noreply 31 safe_name = artifact.name.replace(" ", "_").replace("/", "_").lower()
0981a08… noreply 32 ext = ".json" if artifact.format == "json" else ".md"
0981a08… noreply 33 dest = output_dir / f"{safe_name}{ext}"
0981a08… noreply 34
0981a08… noreply 35 dest.write_text(artifact.content, encoding="utf-8")
0981a08… noreply 36 return {
0981a08… noreply 37 "file": str(dest),
0981a08… noreply 38 "name": artifact.name,
0981a08… noreply 39 "artifact_type": artifact.artifact_type,
0981a08… noreply 40 "format": artifact.format,
0981a08… noreply 41 }
0981a08… noreply 42
0981a08… noreply 43
0981a08… noreply 44 class ArtifactExportSkill(Skill):
0981a08… noreply 45 name = "artifact_export"
0981a08… noreply 46 description = "Export artifacts in agent-ready formats"
0981a08… noreply 47
0981a08… noreply 48 def execute(self, context: AgentContext, **kwargs) -> Artifact:
0981a08… noreply 49 output_dir = Path(kwargs.get("output_dir", "plan"))
0981a08… noreply 50 output_dir.mkdir(parents=True, exist_ok=True)
0981a08… noreply 51
0981a08… noreply 52 manifest_entries = []
0981a08… noreply 53 for artifact in context.artifacts:
0981a08… noreply 54 entry = _write_artifact(artifact, output_dir)
0981a08… noreply 55 manifest_entries.append(entry)
0981a08… noreply 56
0981a08… noreply 57 manifest = {
0981a08… noreply 58 "artifact_count": len(manifest_entries),
0981a08… noreply 59 "output_dir": str(output_dir),
0981a08… noreply 60 "files": manifest_entries,
0981a08… noreply 61 }
0981a08… noreply 62 manifest_path = output_dir / "manifest.json"
0981a08… noreply 63 manifest_json = json.dumps(manifest, indent=2)
0981a08… noreply 64 manifest_path.write_text(manifest_json, encoding="utf-8")
0981a08… noreply 65
0981a08… noreply 66 return Artifact(
0981a08… noreply 67 name="Export Manifest",
0981a08… noreply 68 content=manifest_json,
0981a08… noreply 69 artifact_type="export_manifest",
0981a08… noreply 70 format="json",
0981a08… noreply 71 )
0981a08… noreply 72
0981a08… noreply 73
0981a08… noreply 74 register_skill(ArtifactExportSkill())
0981a08… noreply 75
0981a08… noreply 76
0981a08… noreply 77 def export_artifacts(artifacts: list, output_dir: Path) -> dict:
0981a08… noreply 78 """Standalone helper: export a list of Artifact objects to a directory."""
0981a08… noreply 79 output_dir = Path(output_dir)
0981a08… noreply 80 output_dir.mkdir(parents=True, exist_ok=True)
0981a08… noreply 81
0981a08… noreply 82 manifest_entries = []
0981a08… noreply 83 for artifact in artifacts:
0981a08… noreply 84 entry = _write_artifact(artifact, output_dir)
0981a08… noreply 85 manifest_entries.append(entry)
0981a08… noreply 86
0981a08… noreply 87 manifest = {
0981a08… noreply 88 "artifact_count": len(manifest_entries),
0981a08… noreply 89 "output_dir": str(output_dir),
0981a08… noreply 90 "files": manifest_entries,
0981a08… noreply 91 }
0981a08… noreply 92 manifest_path = output_dir / "manifest.json"
0981a08… noreply 93 manifest_path.write_text(json.dumps(manifest, indent=2), encoding="utf-8")
0981a08… noreply 94 return manifest

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button