PlanOpticon

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

Keyboard Shortcuts

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