thearc 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. thearc/__init__.py +34 -0
  2. thearc/agents/__init__.py +26 -0
  3. thearc/agents/antigravity.py +8 -0
  4. thearc/agents/base.py +442 -0
  5. thearc/agents/claude.py +8 -0
  6. thearc/agents/codex.py +8 -0
  7. thearc/agents/pi.py +8 -0
  8. thearc/cli.py +23 -0
  9. thearc/config.py +173 -0
  10. thearc/flow/__init__.py +108 -0
  11. thearc/flow/decorators.py +380 -0
  12. thearc/flow/test.py +128 -0
  13. thearc/flow/utils.py +248 -0
  14. thearc/flow/viz.css +433 -0
  15. thearc/flow/viz.js +259 -0
  16. thearc/flow/viz.py +656 -0
  17. thearc/learning/__init__.py +145 -0
  18. thearc/learning/_compat.py +39 -0
  19. thearc/learning/ace/__init__.py +35 -0
  20. thearc/learning/ace/evaluation.py +70 -0
  21. thearc/learning/ace/pipeline.py +425 -0
  22. thearc/learning/ace/toy.py +262 -0
  23. thearc/learning/cli.py +25 -0
  24. thearc/learning/curation/__init__.py +22 -0
  25. thearc/learning/curation/assessments.py +182 -0
  26. thearc/learning/curation/cli.py +115 -0
  27. thearc/learning/curation/engine.py +182 -0
  28. thearc/learning/curation/epochs.py +121 -0
  29. thearc/learning/curation/factory.py +41 -0
  30. thearc/learning/curation/providers/__init__.py +10 -0
  31. thearc/learning/curation/providers/antigravity.py +16 -0
  32. thearc/learning/curation/providers/claude.py +15 -0
  33. thearc/learning/curation/providers/codex.py +21 -0
  34. thearc/learning/curation/structured.py +84 -0
  35. thearc/learning/curation/tools.py +210 -0
  36. thearc/learning/evidence/__init__.py +18 -0
  37. thearc/learning/evidence/cli.py +72 -0
  38. thearc/learning/evidence/exports.py +77 -0
  39. thearc/learning/evidence/snapshot.py +271 -0
  40. thearc/learning/evidence/tools.py +253 -0
  41. thearc/learning/privacy.py +61 -0
  42. thearc/learning/reflection/__init__.py +16 -0
  43. thearc/learning/reflection/backend.py +49 -0
  44. thearc/learning/reflection/cli.py +91 -0
  45. thearc/learning/reflection/engine.py +374 -0
  46. thearc/learning/reflection/factory.py +54 -0
  47. thearc/learning/reflection/flow.py +192 -0
  48. thearc/learning/reflection/providers/__init__.py +1 -0
  49. thearc/learning/reflection/providers/antigravity.py +127 -0
  50. thearc/learning/reflection/providers/claude.py +122 -0
  51. thearc/learning/reflection/providers/cli.py +65 -0
  52. thearc/learning/reflection/providers/codex.py +191 -0
  53. thearc/learning/runtime/__init__.py +9 -0
  54. thearc/learning/runtime/cli.py +42 -0
  55. thearc/learning/runtime/contracts.py +69 -0
  56. thearc/learning/runtime/handoff.py +152 -0
  57. thearc/learning/runtime/journal.py +148 -0
  58. thearc/learning/sessions/__init__.py +22 -0
  59. thearc/learning/sessions/adapters.py +473 -0
  60. thearc/learning/sessions/cli.py +107 -0
  61. thearc/learning/sessions/columnar.py +107 -0
  62. thearc/learning/sessions/models.py +162 -0
  63. thearc/learning/sessions/store.py +735 -0
  64. thearc/models/__init__.py +59 -0
  65. thearc/models/agent.py +706 -0
  66. thearc/models/diff.py +46 -0
  67. thearc/models/identity.py +107 -0
  68. thearc/models/markdown.py +303 -0
  69. thearc/models/ranks.py +33 -0
  70. thearc/models/schemas.py +93 -0
  71. thearc/models/session.py +471 -0
  72. thearc/models/strategies.py +134 -0
  73. thearc/models/tracker.py +302 -0
  74. thearc/models/workspace.py +158 -0
  75. thearc-0.1.0.dist-info/METADATA +173 -0
  76. thearc-0.1.0.dist-info/RECORD +79 -0
  77. thearc-0.1.0.dist-info/WHEEL +5 -0
  78. thearc-0.1.0.dist-info/entry_points.txt +2 -0
  79. thearc-0.1.0.dist-info/top_level.txt +1 -0
thearc/__init__.py ADDED
@@ -0,0 +1,34 @@
1
+ """thearc - Agent-agnostic plugin and skill installer system for Codex, Claude, and Antigravity."""
2
+
3
+ from thearc.models.agent import (
4
+ MCP,
5
+ AgentResource,
6
+ ContextDocument,
7
+ Hook,
8
+ MetaAgent,
9
+ Operation,
10
+ ResourceTarget,
11
+ Skill,
12
+ )
13
+ from thearc.models.session import (
14
+ SessionCluster,
15
+ SessionLog,
16
+ SessionSearchEngine,
17
+ SessionSearchResult,
18
+ )
19
+
20
+ __version__ = "0.1.0"
21
+ __all__ = [
22
+ "MCP",
23
+ "AgentResource",
24
+ "ContextDocument",
25
+ "Hook",
26
+ "MetaAgent",
27
+ "Operation",
28
+ "ResourceTarget",
29
+ "SessionCluster",
30
+ "SessionLog",
31
+ "SessionSearchEngine",
32
+ "SessionSearchResult",
33
+ "Skill",
34
+ ]
@@ -0,0 +1,26 @@
1
+ from __future__ import annotations
2
+
3
+ from thearc.agents.antigravity import AntigravityInstaller
4
+ from thearc.agents.base import BaseAgentInstaller
5
+ from thearc.agents.claude import ClaudeInstaller
6
+ from thearc.agents.codex import CodexInstaller
7
+ from thearc.agents.pi import PiInstaller
8
+ from thearc.config import SUPPORTED_AGENTS, normalize_agent_name
9
+
10
+ _INSTALLER_REGISTRY: dict[str, type[BaseAgentInstaller]] = {
11
+ "antigravity": AntigravityInstaller,
12
+ "claude": ClaudeInstaller,
13
+ "codex": CodexInstaller,
14
+ "pi": PiInstaller,
15
+ }
16
+
17
+ def get_installer(agent_name: str) -> BaseAgentInstaller:
18
+ """Retrieve an agent installer instance by name."""
19
+ norm_name = normalize_agent_name(agent_name)
20
+ if norm_name not in _INSTALLER_REGISTRY:
21
+ raise ValueError(f"Unsupported agent '{agent_name}'. Supported agents: {', '.join(SUPPORTED_AGENTS)}")
22
+ return _INSTALLER_REGISTRY[norm_name]()
23
+
24
+ def get_all_installers() -> list[BaseAgentInstaller]:
25
+ """Retrieve all supported agent installer instances."""
26
+ return [installer_cls() for installer_cls in _INSTALLER_REGISTRY.values()]
@@ -0,0 +1,8 @@
1
+ from thearc.agents.base import TargetAgentInstaller
2
+ from thearc.config import AGENT_ANTIGRAVITY
3
+
4
+
5
+ class AntigravityInstaller(TargetAgentInstaller):
6
+ """Installer for Antigravity Agent."""
7
+
8
+ agent_name = AGENT_ANTIGRAVITY
thearc/agents/base.py ADDED
@@ -0,0 +1,442 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ import shutil
5
+ from abc import ABC, abstractmethod
6
+ from pathlib import Path
7
+ from typing import Any, ClassVar
8
+
9
+ from thearc.config import get_global_agent_paths, get_local_agent_paths
10
+ from thearc.models.schemas import CommandDefinition, SkillDefinition
11
+ from thearc.models.strategies import get_strategy
12
+
13
+ logger = logging.getLogger("thearc")
14
+
15
+ def merge_markdown_documents(existing_text: str, new_text: str) -> str:
16
+ """
17
+ Merge new markdown content into existing markdown content when replace=False.
18
+ Merges frontmatter, updates matching sections, and appends non-matching sections.
19
+ """
20
+ from thearc.models.markdown import MarkdownDocument, MarkdownSection
21
+
22
+ if not existing_text.strip():
23
+ return new_text
24
+
25
+ existing_doc = MarkdownDocument.parse(existing_text)
26
+ new_doc = MarkdownDocument.parse(new_text)
27
+
28
+ if new_doc.frontmatter:
29
+ existing_doc.frontmatter.update(new_doc.frontmatter)
30
+
31
+ if not existing_doc.root_content.strip() and new_doc.root_content.strip():
32
+ existing_doc.root_content = new_doc.root_content.strip()
33
+ elif new_doc.root_content.strip() and new_doc.root_content.strip() not in existing_doc.root_content:
34
+ existing_doc.root_content = f"{existing_doc.root_content}\n\n{new_doc.root_content}".strip()
35
+
36
+ def _merge_sections(existing_sections: list[MarkdownSection], new_sections: list[MarkdownSection]):
37
+ for new_sec in new_sections:
38
+ matched = False
39
+ for ext_sec in existing_sections:
40
+ if ext_sec.title.strip().lower() == new_sec.title.strip().lower() or ext_sec.slug == new_sec.slug:
41
+ if new_sec.content:
42
+ ext_sec.content = new_sec.content
43
+ if new_sec.subsections:
44
+ _merge_sections(ext_sec.subsections, new_sec.subsections)
45
+ matched = True
46
+ break
47
+ if not matched:
48
+ existing_sections.append(new_sec)
49
+
50
+ _merge_sections(existing_doc.sections, new_doc.sections)
51
+ return existing_doc.to_markdown()
52
+
53
+
54
+ class BaseAgentInstaller(ABC):
55
+ """Abstract Base Class for Agent Plugin & Skill Installers."""
56
+
57
+ @property
58
+ @abstractmethod
59
+ def name(self) -> str:
60
+ """Name identifier of the agent."""
61
+
62
+ @abstractmethod
63
+ def get_local_paths(self, project_dir: Path) -> dict[str, Path]:
64
+ """Return dict of local target directory paths for this agent."""
65
+
66
+ @abstractmethod
67
+ def get_global_paths(self) -> dict[str, Path]:
68
+ """Return dict of global target directory paths for this agent."""
69
+
70
+ @abstractmethod
71
+ def format_skill_file(self, skill_name: str, raw_content: str, metadata: dict[str, Any] | None = None) -> str:
72
+ """Format skill markdown content specifically for this agent."""
73
+
74
+ @abstractmethod
75
+ def format_command_file(self, command_name: str, raw_content: str, metadata: dict[str, Any] | None = None) -> str:
76
+ """Format slash command prompt content specifically for this agent."""
77
+
78
+ def install_skill(
79
+ self,
80
+ skill_name: str,
81
+ source_dir: Path,
82
+ target_scope: str = "project",
83
+ project_dir: Path = Path("."),
84
+ force: bool = False
85
+ ) -> list[Path]:
86
+ """Install a skill (directory or SKILL.md file) into the target agent location."""
87
+ paths = self.get_local_paths(project_dir) if target_scope == "project" else self.get_global_paths()
88
+ target_skills_dir = paths["skills"]
89
+ installed_files = []
90
+
91
+ target_skill_dir = target_skills_dir / skill_name
92
+ target_skill_dir.mkdir(parents=True, exist_ok=True)
93
+
94
+ if source_dir.is_dir():
95
+ for item in source_dir.rglob("*"):
96
+ if item.is_file():
97
+ rel_path = item.relative_to(source_dir)
98
+ dest_file = target_skill_dir / rel_path
99
+ dest_file.parent.mkdir(parents=True, exist_ok=True)
100
+
101
+ if item.name == "SKILL.md":
102
+ content = item.read_text(encoding="utf-8")
103
+ formatted = self.format_skill_file(skill_name, content)
104
+ if not dest_file.exists() or force:
105
+ dest_file.write_text(formatted, encoding="utf-8")
106
+ installed_files.append(dest_file)
107
+ else:
108
+ existing_text = dest_file.read_text(encoding="utf-8")
109
+ merged_text = merge_markdown_documents(existing_text, formatted)
110
+ dest_file.write_text(merged_text, encoding="utf-8")
111
+ installed_files.append(dest_file)
112
+ else:
113
+ if not dest_file.exists() or force:
114
+ shutil.copy2(item, dest_file)
115
+ installed_files.append(dest_file)
116
+ elif source_dir.is_file():
117
+ dest_file = target_skill_dir / "SKILL.md"
118
+ content = source_dir.read_text(encoding="utf-8")
119
+ formatted = self.format_skill_file(skill_name, content)
120
+ if not dest_file.exists() or force:
121
+ dest_file.write_text(formatted, encoding="utf-8")
122
+ installed_files.append(dest_file)
123
+ else:
124
+ existing_text = dest_file.read_text(encoding="utf-8")
125
+ merged_text = merge_markdown_documents(existing_text, formatted)
126
+ dest_file.write_text(merged_text, encoding="utf-8")
127
+ installed_files.append(dest_file)
128
+
129
+ return installed_files
130
+
131
+ def install_command(
132
+ self,
133
+ command_name: str,
134
+ source_file: Path,
135
+ target_scope: str = "project",
136
+ project_dir: Path = Path("."),
137
+ force: bool = False
138
+ ) -> Path:
139
+ """Install a slash command prompt definition into the target agent location."""
140
+ paths = self.get_local_paths(project_dir) if target_scope == "project" else self.get_global_paths()
141
+ target_commands_dir = paths["commands"]
142
+ target_commands_dir.mkdir(parents=True, exist_ok=True)
143
+
144
+ dest_file = target_commands_dir / f"{command_name}.md"
145
+ content = source_file.read_text(encoding="utf-8") if source_file.is_file() else str(source_file)
146
+ formatted = self.format_command_file(command_name, content)
147
+
148
+ if not dest_file.exists() or force:
149
+ dest_file.write_text(formatted, encoding="utf-8")
150
+ else:
151
+ existing_text = dest_file.read_text(encoding="utf-8")
152
+ merged_text = merge_markdown_documents(existing_text, formatted)
153
+ dest_file.write_text(merged_text, encoding="utf-8")
154
+ return dest_file
155
+
156
+ def ensure_config_file(
157
+ self,
158
+ target_scope: str = "project",
159
+ project_dir: Path = Path("."),
160
+ force: bool = False
161
+ ) -> Path:
162
+ """Create default .thearc.toml configuration file in the agent target base directory."""
163
+ paths = self.get_local_paths(project_dir) if target_scope == "project" else self.get_global_paths()
164
+ base_dir = paths["base"]
165
+ base_dir.mkdir(parents=True, exist_ok=True)
166
+ config_file = base_dir / ".thearc.toml"
167
+
168
+ if not config_file.exists() or force:
169
+ content = (
170
+ f"# thearc configuration file for {self.name} agent\n"
171
+ f"version = \"0.1.0\"\n\n"
172
+ f"[agent]\n"
173
+ f"name = \"{self.name}\"\n\n"
174
+ f"[cli]\n"
175
+ f"default_scope = \"{target_scope}\"\n"
176
+ f"default_agent = \"{self.name}\"\n"
177
+ )
178
+ config_file.write_text(content, encoding="utf-8")
179
+
180
+ return config_file
181
+
182
+ def install_skill_object(
183
+ self,
184
+ skill: Any,
185
+ target_scope: str = "project",
186
+ project_dir: Path = Path("."),
187
+ force: bool = False
188
+ ) -> list[Path]:
189
+ """
190
+ Install a Skill model object into the target agent location.
191
+ If force=True (replace=True), replaces the file completely.
192
+ If force=False (replace=False), merges sections and updates content.
193
+ """
194
+ paths = self.get_local_paths(project_dir) if target_scope == "project" else self.get_global_paths()
195
+ target_skills_dir = paths["skills"]
196
+ target_skill_dir = target_skills_dir / skill.name
197
+ target_skill_dir.mkdir(parents=True, exist_ok=True)
198
+
199
+ installed_files = []
200
+ dest_file = target_skill_dir / "SKILL.md"
201
+
202
+ raw_content = skill.instructions if skill.instructions else f"# {skill.name}"
203
+ meta = {"description": skill.description}
204
+ if hasattr(skill, "metadata") and skill.metadata:
205
+ meta.update(skill.metadata)
206
+
207
+ if getattr(skill, "ranks", None) is not None:
208
+ meta["ranks"] = skill.ranks
209
+
210
+ formatted = self.format_skill_file(skill.name, raw_content, metadata=meta)
211
+
212
+ if not dest_file.exists() or force:
213
+ dest_file.write_text(formatted, encoding="utf-8")
214
+ installed_files.append(dest_file)
215
+ else:
216
+ existing_text = dest_file.read_text(encoding="utf-8")
217
+ merged_text = merge_markdown_documents(existing_text, formatted)
218
+ dest_file.write_text(merged_text, encoding="utf-8")
219
+ installed_files.append(dest_file)
220
+
221
+ if hasattr(skill, "files") and skill.files:
222
+ for rel_path_str, file_content in skill.files.items():
223
+ sub_file = target_skill_dir / rel_path_str
224
+ sub_file.parent.mkdir(parents=True, exist_ok=True)
225
+ if not sub_file.exists() or force:
226
+ sub_file.write_text(file_content, encoding="utf-8")
227
+ installed_files.append(sub_file)
228
+ else:
229
+ if rel_path_str.endswith(".md"):
230
+ ex_sub = sub_file.read_text(encoding="utf-8")
231
+ merged_sub = merge_markdown_documents(ex_sub, file_content)
232
+ sub_file.write_text(merged_sub, encoding="utf-8")
233
+ installed_files.append(sub_file)
234
+
235
+ return installed_files
236
+
237
+ def install_hooks(
238
+ self,
239
+ hooks: Any,
240
+ target_scope: str = "project",
241
+ project_dir: Path = Path("."),
242
+ force: bool = False
243
+ ) -> list[Path]:
244
+ """
245
+ Install hooks into the target agent location.
246
+ If force=True (replace=True), replaces existing hooks.json completely.
247
+ If force=False (replace=False), appends/updates hook definitions in hooks.json.
248
+ """
249
+ if not hooks:
250
+ return []
251
+ paths = self.get_local_paths(project_dir) if target_scope == "project" else self.get_global_paths()
252
+ hooks_dir = paths.get("hooks", paths["base"] / "hooks")
253
+ hooks_dir.mkdir(parents=True, exist_ok=True)
254
+ hooks_json_file = paths["base"] / "hooks.json"
255
+
256
+ import json
257
+ if self.name == "codex":
258
+ existing_hooks = {"hooks": {}}
259
+ if not force and hooks_json_file.exists():
260
+ try:
261
+ loaded = json.loads(hooks_json_file.read_text(encoding="utf-8"))
262
+ if isinstance(loaded.get("hooks"), dict):
263
+ existing_hooks = loaded
264
+ except (OSError, UnicodeError, json.JSONDecodeError):
265
+ pass
266
+
267
+ for hook in hooks.values():
268
+ event = "".join(part.capitalize() for part in hook.event.split("_"))
269
+ groups = existing_hooks["hooks"].setdefault(event, [])
270
+ group = next((item for item in groups if item.get("matcher") == hook.matcher), None)
271
+ if group is None:
272
+ group = {"matcher": hook.matcher, "hooks": []}
273
+ groups.append(group)
274
+ definition = {"type": "command"}
275
+ if hook.command:
276
+ definition["command"] = hook.command
277
+ elif hook.script:
278
+ definition["command"] = hook.script
279
+ if hook.extra:
280
+ definition.update(hook.extra)
281
+ group["hooks"].append(definition)
282
+
283
+ hooks_json_file.write_text(json.dumps(existing_hooks, indent=2), encoding="utf-8")
284
+ return [hooks_json_file]
285
+
286
+ existing_hooks = {}
287
+ if hooks_json_file.exists():
288
+ try:
289
+ existing_hooks = json.loads(hooks_json_file.read_text(encoding="utf-8"))
290
+ except (OSError, UnicodeError, json.JSONDecodeError):
291
+ existing_hooks = {}
292
+
293
+ hooks_dict = {name: hook.to_dict() for name, hook in hooks.items()}
294
+ if force:
295
+ merged = hooks_dict
296
+ else:
297
+ merged = {**existing_hooks, **hooks_dict}
298
+
299
+ hooks_json_file.parent.mkdir(parents=True, exist_ok=True)
300
+ hooks_json_file.write_text(json.dumps(merged, indent=2), encoding="utf-8")
301
+ installed_files = [hooks_json_file]
302
+
303
+ for hook in hooks.values():
304
+ if hasattr(hook, "script") and hook.script:
305
+ script_file = hooks_dir / f"{hook.name}.sh"
306
+ if not script_file.exists() or force:
307
+ script_file.write_text(hook.script, encoding="utf-8")
308
+ installed_files.append(script_file)
309
+
310
+ return installed_files
311
+
312
+ def install_mcps(
313
+ self,
314
+ mcps: Any,
315
+ target_scope: str = "project",
316
+ project_dir: Path = Path("."),
317
+ force: bool = False
318
+ ) -> list[Path]:
319
+ """
320
+ Install MCP server configurations into the target agent location.
321
+ If force=True (replace=True), replaces mcp.json/mcp_config.json completely.
322
+ If force=False (replace=False), appends/updates server configs in mcp.json.
323
+ """
324
+ if not mcps:
325
+ return []
326
+ paths = self.get_local_paths(project_dir) if target_scope == "project" else self.get_global_paths()
327
+ mcp_file = paths.get("mcp", paths["base"] / "mcp.json")
328
+ mcp_file.parent.mkdir(parents=True, exist_ok=True)
329
+
330
+ import json
331
+ existing_data = {"mcpServers": {}}
332
+ if mcp_file.exists():
333
+ try:
334
+ existing_data = json.loads(mcp_file.read_text(encoding="utf-8"))
335
+ if "mcpServers" not in existing_data:
336
+ existing_data["mcpServers"] = {}
337
+ except (OSError, UnicodeError, json.JSONDecodeError):
338
+ existing_data = {"mcpServers": {}}
339
+
340
+ mcp_dict = {name: mcp.to_dict() for name, mcp in mcps.items()}
341
+ if force:
342
+ existing_data["mcpServers"] = mcp_dict
343
+ else:
344
+ existing_data["mcpServers"].update(mcp_dict)
345
+
346
+ mcp_file.write_text(json.dumps(existing_data, indent=2), encoding="utf-8")
347
+ return [mcp_file]
348
+
349
+ def install_context_doc(
350
+ self,
351
+ doc: Any,
352
+ target_scope: str = "project",
353
+ project_dir: Path = Path("."),
354
+ force: bool = False
355
+ ) -> list[Path]:
356
+ """
357
+ Install context document (AGENTS.md, CLAUDE.md, etc.) into project or agent directory.
358
+ If force=True (replace=True), replaces the file completely.
359
+ If force=False (replace=False), merges sections and updates content.
360
+ """
361
+ filename = doc.filename if hasattr(doc, "filename") else "AGENTS.md"
362
+ content = doc.content if hasattr(doc, "content") else str(doc)
363
+
364
+ if target_scope == "project":
365
+ dest_file = Path(project_dir).resolve() / filename
366
+ else:
367
+ paths = self.get_global_paths()
368
+ dest_file = paths["base"] / filename
369
+
370
+ dest_file.parent.mkdir(parents=True, exist_ok=True)
371
+
372
+ if force or not dest_file.exists():
373
+ dest_file.write_text(content, encoding="utf-8")
374
+ return [dest_file]
375
+ existing_text = dest_file.read_text(encoding="utf-8")
376
+ merged_text = merge_markdown_documents(existing_text, content)
377
+ dest_file.write_text(merged_text, encoding="utf-8")
378
+ return [dest_file]
379
+
380
+ def install_resources(
381
+ self,
382
+ resources: Any,
383
+ target_scope: str = "project",
384
+ project_dir: Path = Path("."),
385
+ force: bool = False,
386
+ ) -> list[Path]:
387
+ """Install portable agent-local files such as rules and workflows."""
388
+ paths = self.get_local_paths(project_dir) if target_scope == "project" else self.get_global_paths()
389
+ locations = {
390
+ "rules": paths["rules"],
391
+ "commands": paths["commands"],
392
+ "workflows": paths["base"] / "workflows",
393
+ }
394
+ installed = []
395
+ for resource in resources:
396
+ dest_file = locations[resource.location] / resource.relative_path()
397
+ dest_file.parent.mkdir(parents=True, exist_ok=True)
398
+ if force or not dest_file.exists():
399
+ dest_file.write_text(resource.content, encoding="utf-8")
400
+ elif dest_file.suffix.lower() == ".md":
401
+ existing_text = dest_file.read_text(encoding="utf-8")
402
+ dest_file.write_text(merge_markdown_documents(existing_text, resource.content), encoding="utf-8")
403
+ installed.append(dest_file)
404
+ return installed
405
+
406
+
407
+ class TargetAgentInstaller(BaseAgentInstaller):
408
+ """Shared installer implementation for a configured agent target."""
409
+
410
+ agent_name: ClassVar[str]
411
+
412
+ @property
413
+ def name(self) -> str:
414
+ return self.agent_name
415
+
416
+ def get_local_paths(self, project_dir: Path) -> dict[str, Path]:
417
+ return get_local_agent_paths(project_dir, self.agent_name)
418
+
419
+ def get_global_paths(self) -> dict[str, Path]:
420
+ return get_global_agent_paths(self.agent_name)
421
+
422
+ def format_skill_file(
423
+ self,
424
+ skill_name: str,
425
+ raw_content: str,
426
+ metadata: dict[str, Any] | None = None,
427
+ ) -> str:
428
+ skill = SkillDefinition.from_markdown(name=skill_name, markdown_text=raw_content)
429
+ for key, value in (metadata or {}).items():
430
+ setattr(skill.metadata, key, value)
431
+ return get_strategy(self.agent_name).skill_to_markdown(skill)
432
+
433
+ def format_command_file(
434
+ self,
435
+ command_name: str,
436
+ raw_content: str,
437
+ metadata: dict[str, Any] | None = None,
438
+ ) -> str:
439
+ command = CommandDefinition.from_markdown(name=command_name, markdown_text=raw_content)
440
+ if metadata and "description" in metadata:
441
+ command.description = metadata["description"]
442
+ return get_strategy(self.agent_name).command_to_markdown(command)
@@ -0,0 +1,8 @@
1
+ from thearc.agents.base import TargetAgentInstaller
2
+ from thearc.config import AGENT_CLAUDE
3
+
4
+
5
+ class ClaudeInstaller(TargetAgentInstaller):
6
+ """Installer for Claude Code / Claude Agent."""
7
+
8
+ agent_name = AGENT_CLAUDE
thearc/agents/codex.py ADDED
@@ -0,0 +1,8 @@
1
+ from thearc.agents.base import TargetAgentInstaller
2
+ from thearc.config import AGENT_CODEX
3
+
4
+
5
+ class CodexInstaller(TargetAgentInstaller):
6
+ """Installer for OpenAI Codex / Copilot Agent."""
7
+
8
+ agent_name = AGENT_CODEX
thearc/agents/pi.py ADDED
@@ -0,0 +1,8 @@
1
+ from thearc.agents.base import TargetAgentInstaller
2
+ from thearc.config import AGENT_PI
3
+
4
+
5
+ class PiInstaller(TargetAgentInstaller):
6
+ """Installer for Pi Agent."""
7
+
8
+ agent_name = AGENT_PI
thearc/cli.py ADDED
@@ -0,0 +1,23 @@
1
+ import click
2
+
3
+ from thearc import __version__
4
+ from thearc.learning.cli import evidence, handoff_commands, history, sessions
5
+ from thearc.learning.curation.cli import curation
6
+ from thearc.learning.reflection.cli import reflection
7
+
8
+
9
+ @click.group(context_settings={"help_option_names": ["-h", "--help"]})
10
+ @click.version_option(version=__version__, prog_name="thearc")
11
+ def main():
12
+ """thearc: Inspect sessions, prepare evidence, reflect on configurations, and curate agents."""
13
+
14
+
15
+ main.add_command(sessions)
16
+ main.add_command(evidence)
17
+ main.add_command(handoff_commands)
18
+ main.add_command(history)
19
+ main.add_command(curation)
20
+ main.add_command(reflection)
21
+
22
+ if __name__ == "__main__":
23
+ main()