htmlgraph 0.9.3__py3-none-any.whl → 0.27.5__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 (331) hide show
  1. htmlgraph/.htmlgraph/.session-warning-state.json +6 -0
  2. htmlgraph/.htmlgraph/agents.json +72 -0
  3. htmlgraph/.htmlgraph/htmlgraph.db +0 -0
  4. htmlgraph/__init__.py +173 -17
  5. htmlgraph/__init__.pyi +123 -0
  6. htmlgraph/agent_detection.py +127 -0
  7. htmlgraph/agent_registry.py +45 -30
  8. htmlgraph/agents.py +160 -107
  9. htmlgraph/analytics/__init__.py +9 -2
  10. htmlgraph/analytics/cli.py +190 -51
  11. htmlgraph/analytics/cost_analyzer.py +391 -0
  12. htmlgraph/analytics/cost_monitor.py +664 -0
  13. htmlgraph/analytics/cost_reporter.py +675 -0
  14. htmlgraph/analytics/cross_session.py +617 -0
  15. htmlgraph/analytics/dependency.py +192 -100
  16. htmlgraph/analytics/pattern_learning.py +771 -0
  17. htmlgraph/analytics/session_graph.py +707 -0
  18. htmlgraph/analytics/strategic/__init__.py +80 -0
  19. htmlgraph/analytics/strategic/cost_optimizer.py +611 -0
  20. htmlgraph/analytics/strategic/pattern_detector.py +876 -0
  21. htmlgraph/analytics/strategic/preference_manager.py +709 -0
  22. htmlgraph/analytics/strategic/suggestion_engine.py +747 -0
  23. htmlgraph/analytics/work_type.py +190 -14
  24. htmlgraph/analytics_index.py +135 -51
  25. htmlgraph/api/__init__.py +3 -0
  26. htmlgraph/api/cost_alerts_websocket.py +416 -0
  27. htmlgraph/api/main.py +2498 -0
  28. htmlgraph/api/static/htmx.min.js +1 -0
  29. htmlgraph/api/static/style-redesign.css +1344 -0
  30. htmlgraph/api/static/style.css +1079 -0
  31. htmlgraph/api/templates/dashboard-redesign.html +1366 -0
  32. htmlgraph/api/templates/dashboard.html +794 -0
  33. htmlgraph/api/templates/partials/activity-feed-hierarchical.html +326 -0
  34. htmlgraph/api/templates/partials/activity-feed.html +1100 -0
  35. htmlgraph/api/templates/partials/agents-redesign.html +317 -0
  36. htmlgraph/api/templates/partials/agents.html +317 -0
  37. htmlgraph/api/templates/partials/event-traces.html +373 -0
  38. htmlgraph/api/templates/partials/features-kanban-redesign.html +509 -0
  39. htmlgraph/api/templates/partials/features.html +578 -0
  40. htmlgraph/api/templates/partials/metrics-redesign.html +346 -0
  41. htmlgraph/api/templates/partials/metrics.html +346 -0
  42. htmlgraph/api/templates/partials/orchestration-redesign.html +443 -0
  43. htmlgraph/api/templates/partials/orchestration.html +198 -0
  44. htmlgraph/api/templates/partials/spawners.html +375 -0
  45. htmlgraph/api/templates/partials/work-items.html +613 -0
  46. htmlgraph/api/websocket.py +538 -0
  47. htmlgraph/archive/__init__.py +24 -0
  48. htmlgraph/archive/bloom.py +234 -0
  49. htmlgraph/archive/fts.py +297 -0
  50. htmlgraph/archive/manager.py +583 -0
  51. htmlgraph/archive/search.py +244 -0
  52. htmlgraph/atomic_ops.py +560 -0
  53. htmlgraph/attribute_index.py +208 -0
  54. htmlgraph/bounded_paths.py +539 -0
  55. htmlgraph/builders/__init__.py +14 -0
  56. htmlgraph/builders/base.py +118 -29
  57. htmlgraph/builders/bug.py +150 -0
  58. htmlgraph/builders/chore.py +119 -0
  59. htmlgraph/builders/epic.py +150 -0
  60. htmlgraph/builders/feature.py +31 -6
  61. htmlgraph/builders/insight.py +195 -0
  62. htmlgraph/builders/metric.py +217 -0
  63. htmlgraph/builders/pattern.py +202 -0
  64. htmlgraph/builders/phase.py +162 -0
  65. htmlgraph/builders/spike.py +52 -19
  66. htmlgraph/builders/track.py +148 -72
  67. htmlgraph/cigs/__init__.py +81 -0
  68. htmlgraph/cigs/autonomy.py +385 -0
  69. htmlgraph/cigs/cost.py +475 -0
  70. htmlgraph/cigs/messages_basic.py +472 -0
  71. htmlgraph/cigs/messaging.py +365 -0
  72. htmlgraph/cigs/models.py +771 -0
  73. htmlgraph/cigs/pattern_storage.py +427 -0
  74. htmlgraph/cigs/patterns.py +503 -0
  75. htmlgraph/cigs/posttool_analyzer.py +234 -0
  76. htmlgraph/cigs/reporter.py +818 -0
  77. htmlgraph/cigs/tracker.py +317 -0
  78. htmlgraph/cli/.htmlgraph/.session-warning-state.json +6 -0
  79. htmlgraph/cli/.htmlgraph/agents.json +72 -0
  80. htmlgraph/cli/.htmlgraph/htmlgraph.db +0 -0
  81. htmlgraph/cli/__init__.py +42 -0
  82. htmlgraph/cli/__main__.py +6 -0
  83. htmlgraph/cli/analytics.py +1424 -0
  84. htmlgraph/cli/base.py +685 -0
  85. htmlgraph/cli/constants.py +206 -0
  86. htmlgraph/cli/core.py +954 -0
  87. htmlgraph/cli/main.py +147 -0
  88. htmlgraph/cli/models.py +475 -0
  89. htmlgraph/cli/templates/__init__.py +1 -0
  90. htmlgraph/cli/templates/cost_dashboard.py +399 -0
  91. htmlgraph/cli/work/__init__.py +239 -0
  92. htmlgraph/cli/work/browse.py +115 -0
  93. htmlgraph/cli/work/features.py +568 -0
  94. htmlgraph/cli/work/orchestration.py +676 -0
  95. htmlgraph/cli/work/report.py +728 -0
  96. htmlgraph/cli/work/sessions.py +466 -0
  97. htmlgraph/cli/work/snapshot.py +559 -0
  98. htmlgraph/cli/work/tracks.py +486 -0
  99. htmlgraph/cli_commands/__init__.py +1 -0
  100. htmlgraph/cli_commands/feature.py +195 -0
  101. htmlgraph/cli_framework.py +115 -0
  102. htmlgraph/collections/__init__.py +18 -0
  103. htmlgraph/collections/base.py +415 -98
  104. htmlgraph/collections/bug.py +53 -0
  105. htmlgraph/collections/chore.py +53 -0
  106. htmlgraph/collections/epic.py +53 -0
  107. htmlgraph/collections/feature.py +12 -26
  108. htmlgraph/collections/insight.py +100 -0
  109. htmlgraph/collections/metric.py +92 -0
  110. htmlgraph/collections/pattern.py +97 -0
  111. htmlgraph/collections/phase.py +53 -0
  112. htmlgraph/collections/session.py +194 -0
  113. htmlgraph/collections/spike.py +56 -16
  114. htmlgraph/collections/task_delegation.py +241 -0
  115. htmlgraph/collections/todo.py +511 -0
  116. htmlgraph/collections/traces.py +487 -0
  117. htmlgraph/config/cost_models.json +56 -0
  118. htmlgraph/config.py +190 -0
  119. htmlgraph/context_analytics.py +344 -0
  120. htmlgraph/converter.py +216 -28
  121. htmlgraph/cost_analysis/__init__.py +5 -0
  122. htmlgraph/cost_analysis/analyzer.py +438 -0
  123. htmlgraph/dashboard.html +2406 -307
  124. htmlgraph/dashboard.html.backup +6592 -0
  125. htmlgraph/dashboard.html.bak +7181 -0
  126. htmlgraph/dashboard.html.bak2 +7231 -0
  127. htmlgraph/dashboard.html.bak3 +7232 -0
  128. htmlgraph/db/__init__.py +38 -0
  129. htmlgraph/db/queries.py +790 -0
  130. htmlgraph/db/schema.py +1788 -0
  131. htmlgraph/decorators.py +317 -0
  132. htmlgraph/dependency_models.py +19 -2
  133. htmlgraph/deploy.py +142 -125
  134. htmlgraph/deployment_models.py +474 -0
  135. htmlgraph/docs/API_REFERENCE.md +841 -0
  136. htmlgraph/docs/HTTP_API.md +750 -0
  137. htmlgraph/docs/INTEGRATION_GUIDE.md +752 -0
  138. htmlgraph/docs/ORCHESTRATION_PATTERNS.md +717 -0
  139. htmlgraph/docs/README.md +532 -0
  140. htmlgraph/docs/__init__.py +77 -0
  141. htmlgraph/docs/docs_version.py +55 -0
  142. htmlgraph/docs/metadata.py +93 -0
  143. htmlgraph/docs/migrations.py +232 -0
  144. htmlgraph/docs/template_engine.py +143 -0
  145. htmlgraph/docs/templates/_sections/cli_reference.md.j2 +52 -0
  146. htmlgraph/docs/templates/_sections/core_concepts.md.j2 +29 -0
  147. htmlgraph/docs/templates/_sections/sdk_basics.md.j2 +69 -0
  148. htmlgraph/docs/templates/base_agents.md.j2 +78 -0
  149. htmlgraph/docs/templates/example_user_override.md.j2 +47 -0
  150. htmlgraph/docs/version_check.py +163 -0
  151. htmlgraph/edge_index.py +182 -27
  152. htmlgraph/error_handler.py +544 -0
  153. htmlgraph/event_log.py +100 -52
  154. htmlgraph/event_migration.py +13 -4
  155. htmlgraph/exceptions.py +49 -0
  156. htmlgraph/file_watcher.py +101 -28
  157. htmlgraph/find_api.py +75 -63
  158. htmlgraph/git_events.py +145 -63
  159. htmlgraph/graph.py +1122 -106
  160. htmlgraph/hooks/.htmlgraph/.session-warning-state.json +6 -0
  161. htmlgraph/hooks/.htmlgraph/agents.json +72 -0
  162. htmlgraph/hooks/.htmlgraph/index.sqlite +0 -0
  163. htmlgraph/hooks/__init__.py +45 -0
  164. htmlgraph/hooks/bootstrap.py +169 -0
  165. htmlgraph/hooks/cigs_pretool_enforcer.py +354 -0
  166. htmlgraph/hooks/concurrent_sessions.py +208 -0
  167. htmlgraph/hooks/context.py +350 -0
  168. htmlgraph/hooks/drift_handler.py +525 -0
  169. htmlgraph/hooks/event_tracker.py +1314 -0
  170. htmlgraph/hooks/git_commands.py +175 -0
  171. htmlgraph/hooks/hooks-config.example.json +12 -0
  172. htmlgraph/hooks/installer.py +343 -0
  173. htmlgraph/hooks/orchestrator.py +674 -0
  174. htmlgraph/hooks/orchestrator_reflector.py +223 -0
  175. htmlgraph/hooks/post-checkout.sh +28 -0
  176. htmlgraph/hooks/post-commit.sh +24 -0
  177. htmlgraph/hooks/post-merge.sh +26 -0
  178. htmlgraph/hooks/post_tool_use_failure.py +273 -0
  179. htmlgraph/hooks/post_tool_use_handler.py +257 -0
  180. htmlgraph/hooks/posttooluse.py +408 -0
  181. htmlgraph/hooks/pre-commit.sh +94 -0
  182. htmlgraph/hooks/pre-push.sh +28 -0
  183. htmlgraph/hooks/pretooluse.py +819 -0
  184. htmlgraph/hooks/prompt_analyzer.py +637 -0
  185. htmlgraph/hooks/session_handler.py +668 -0
  186. htmlgraph/hooks/session_summary.py +395 -0
  187. htmlgraph/hooks/state_manager.py +504 -0
  188. htmlgraph/hooks/subagent_detection.py +202 -0
  189. htmlgraph/hooks/subagent_stop.py +369 -0
  190. htmlgraph/hooks/task_enforcer.py +255 -0
  191. htmlgraph/hooks/task_validator.py +177 -0
  192. htmlgraph/hooks/validator.py +628 -0
  193. htmlgraph/ids.py +41 -27
  194. htmlgraph/index.d.ts +286 -0
  195. htmlgraph/learning.py +767 -0
  196. htmlgraph/mcp_server.py +69 -23
  197. htmlgraph/models.py +1586 -87
  198. htmlgraph/operations/README.md +62 -0
  199. htmlgraph/operations/__init__.py +79 -0
  200. htmlgraph/operations/analytics.py +339 -0
  201. htmlgraph/operations/bootstrap.py +289 -0
  202. htmlgraph/operations/events.py +244 -0
  203. htmlgraph/operations/fastapi_server.py +231 -0
  204. htmlgraph/operations/hooks.py +350 -0
  205. htmlgraph/operations/initialization.py +597 -0
  206. htmlgraph/operations/initialization.py.backup +228 -0
  207. htmlgraph/operations/server.py +303 -0
  208. htmlgraph/orchestration/__init__.py +58 -0
  209. htmlgraph/orchestration/claude_launcher.py +179 -0
  210. htmlgraph/orchestration/command_builder.py +72 -0
  211. htmlgraph/orchestration/headless_spawner.py +281 -0
  212. htmlgraph/orchestration/live_events.py +377 -0
  213. htmlgraph/orchestration/model_selection.py +327 -0
  214. htmlgraph/orchestration/plugin_manager.py +140 -0
  215. htmlgraph/orchestration/prompts.py +137 -0
  216. htmlgraph/orchestration/spawner_event_tracker.py +383 -0
  217. htmlgraph/orchestration/spawners/__init__.py +16 -0
  218. htmlgraph/orchestration/spawners/base.py +194 -0
  219. htmlgraph/orchestration/spawners/claude.py +173 -0
  220. htmlgraph/orchestration/spawners/codex.py +435 -0
  221. htmlgraph/orchestration/spawners/copilot.py +294 -0
  222. htmlgraph/orchestration/spawners/gemini.py +471 -0
  223. htmlgraph/orchestration/subprocess_runner.py +36 -0
  224. htmlgraph/orchestration/task_coordination.py +343 -0
  225. htmlgraph/orchestration.md +563 -0
  226. htmlgraph/orchestrator-system-prompt-optimized.txt +863 -0
  227. htmlgraph/orchestrator.py +669 -0
  228. htmlgraph/orchestrator_config.py +357 -0
  229. htmlgraph/orchestrator_mode.py +328 -0
  230. htmlgraph/orchestrator_validator.py +133 -0
  231. htmlgraph/parallel.py +646 -0
  232. htmlgraph/parser.py +160 -35
  233. htmlgraph/path_query.py +608 -0
  234. htmlgraph/pattern_matcher.py +636 -0
  235. htmlgraph/planning.py +147 -52
  236. htmlgraph/pydantic_models.py +476 -0
  237. htmlgraph/quality_gates.py +350 -0
  238. htmlgraph/query_builder.py +109 -72
  239. htmlgraph/query_composer.py +509 -0
  240. htmlgraph/reflection.py +443 -0
  241. htmlgraph/refs.py +344 -0
  242. htmlgraph/repo_hash.py +512 -0
  243. htmlgraph/repositories/__init__.py +292 -0
  244. htmlgraph/repositories/analytics_repository.py +455 -0
  245. htmlgraph/repositories/analytics_repository_standard.py +628 -0
  246. htmlgraph/repositories/feature_repository.py +581 -0
  247. htmlgraph/repositories/feature_repository_htmlfile.py +668 -0
  248. htmlgraph/repositories/feature_repository_memory.py +607 -0
  249. htmlgraph/repositories/feature_repository_sqlite.py +858 -0
  250. htmlgraph/repositories/filter_service.py +620 -0
  251. htmlgraph/repositories/filter_service_standard.py +445 -0
  252. htmlgraph/repositories/shared_cache.py +621 -0
  253. htmlgraph/repositories/shared_cache_memory.py +395 -0
  254. htmlgraph/repositories/track_repository.py +552 -0
  255. htmlgraph/repositories/track_repository_htmlfile.py +619 -0
  256. htmlgraph/repositories/track_repository_memory.py +508 -0
  257. htmlgraph/repositories/track_repository_sqlite.py +711 -0
  258. htmlgraph/routing.py +8 -19
  259. htmlgraph/scripts/deploy.py +1 -2
  260. htmlgraph/sdk/__init__.py +398 -0
  261. htmlgraph/sdk/__init__.pyi +14 -0
  262. htmlgraph/sdk/analytics/__init__.py +19 -0
  263. htmlgraph/sdk/analytics/engine.py +155 -0
  264. htmlgraph/sdk/analytics/helpers.py +178 -0
  265. htmlgraph/sdk/analytics/registry.py +109 -0
  266. htmlgraph/sdk/base.py +484 -0
  267. htmlgraph/sdk/constants.py +216 -0
  268. htmlgraph/sdk/core.pyi +308 -0
  269. htmlgraph/sdk/discovery.py +120 -0
  270. htmlgraph/sdk/help/__init__.py +12 -0
  271. htmlgraph/sdk/help/mixin.py +699 -0
  272. htmlgraph/sdk/mixins/__init__.py +15 -0
  273. htmlgraph/sdk/mixins/attribution.py +113 -0
  274. htmlgraph/sdk/mixins/mixin.py +410 -0
  275. htmlgraph/sdk/operations/__init__.py +12 -0
  276. htmlgraph/sdk/operations/mixin.py +427 -0
  277. htmlgraph/sdk/orchestration/__init__.py +17 -0
  278. htmlgraph/sdk/orchestration/coordinator.py +203 -0
  279. htmlgraph/sdk/orchestration/spawner.py +204 -0
  280. htmlgraph/sdk/planning/__init__.py +19 -0
  281. htmlgraph/sdk/planning/bottlenecks.py +93 -0
  282. htmlgraph/sdk/planning/mixin.py +211 -0
  283. htmlgraph/sdk/planning/parallel.py +186 -0
  284. htmlgraph/sdk/planning/queue.py +210 -0
  285. htmlgraph/sdk/planning/recommendations.py +87 -0
  286. htmlgraph/sdk/planning/smart_planning.py +319 -0
  287. htmlgraph/sdk/session/__init__.py +19 -0
  288. htmlgraph/sdk/session/continuity.py +57 -0
  289. htmlgraph/sdk/session/handoff.py +110 -0
  290. htmlgraph/sdk/session/info.py +309 -0
  291. htmlgraph/sdk/session/manager.py +103 -0
  292. htmlgraph/sdk/strategic/__init__.py +26 -0
  293. htmlgraph/sdk/strategic/mixin.py +563 -0
  294. htmlgraph/server.py +685 -180
  295. htmlgraph/services/__init__.py +10 -0
  296. htmlgraph/services/claiming.py +199 -0
  297. htmlgraph/session_hooks.py +300 -0
  298. htmlgraph/session_manager.py +1392 -175
  299. htmlgraph/session_registry.py +587 -0
  300. htmlgraph/session_state.py +436 -0
  301. htmlgraph/session_warning.py +201 -0
  302. htmlgraph/sessions/__init__.py +23 -0
  303. htmlgraph/sessions/handoff.py +756 -0
  304. htmlgraph/setup.py +34 -17
  305. htmlgraph/spike_index.py +143 -0
  306. htmlgraph/sync_docs.py +12 -15
  307. htmlgraph/system_prompts.py +450 -0
  308. htmlgraph/templates/AGENTS.md.template +366 -0
  309. htmlgraph/templates/CLAUDE.md.template +97 -0
  310. htmlgraph/templates/GEMINI.md.template +87 -0
  311. htmlgraph/templates/orchestration-view.html +350 -0
  312. htmlgraph/track_builder.py +146 -15
  313. htmlgraph/track_manager.py +69 -21
  314. htmlgraph/transcript.py +890 -0
  315. htmlgraph/transcript_analytics.py +699 -0
  316. htmlgraph/types.py +323 -0
  317. htmlgraph/validation.py +115 -0
  318. htmlgraph/watch.py +8 -5
  319. htmlgraph/work_type_utils.py +3 -2
  320. {htmlgraph-0.9.3.data → htmlgraph-0.27.5.data}/data/htmlgraph/dashboard.html +2406 -307
  321. htmlgraph-0.27.5.data/data/htmlgraph/templates/AGENTS.md.template +366 -0
  322. htmlgraph-0.27.5.data/data/htmlgraph/templates/CLAUDE.md.template +97 -0
  323. htmlgraph-0.27.5.data/data/htmlgraph/templates/GEMINI.md.template +87 -0
  324. {htmlgraph-0.9.3.dist-info → htmlgraph-0.27.5.dist-info}/METADATA +97 -64
  325. htmlgraph-0.27.5.dist-info/RECORD +337 -0
  326. {htmlgraph-0.9.3.dist-info → htmlgraph-0.27.5.dist-info}/entry_points.txt +1 -1
  327. htmlgraph/cli.py +0 -2688
  328. htmlgraph/sdk.py +0 -709
  329. htmlgraph-0.9.3.dist-info/RECORD +0 -61
  330. {htmlgraph-0.9.3.data → htmlgraph-0.27.5.data}/data/htmlgraph/styles.css +0 -0
  331. {htmlgraph-0.9.3.dist-info → htmlgraph-0.27.5.dist-info}/WHEEL +0 -0
@@ -0,0 +1,93 @@
1
+ """
2
+ Documentation metadata storage and management.
3
+ """
4
+
5
+ from datetime import datetime
6
+ from pathlib import Path
7
+
8
+ from pydantic import BaseModel, Field
9
+
10
+
11
+ class DocsMetadata(BaseModel):
12
+ """Metadata for project documentation."""
13
+
14
+ schema_version: int = 2
15
+ last_updated: datetime = Field(default_factory=datetime.now)
16
+ customizations: list[str] = [] # List of user-customized sections
17
+ base_version_on_last_update: str = "0.21.0"
18
+
19
+ @classmethod
20
+ def load(cls, htmlgraph_dir: Path) -> "DocsMetadata":
21
+ """Load metadata from .docs-metadata.json.
22
+
23
+ Args:
24
+ htmlgraph_dir: Path to .htmlgraph directory
25
+
26
+ Returns:
27
+ DocsMetadata instance (default if file doesn't exist)
28
+ """
29
+ import json
30
+
31
+ metadata_file = htmlgraph_dir / ".docs-metadata.json"
32
+ if metadata_file.exists():
33
+ data = json.loads(metadata_file.read_text())
34
+ return cls(**data)
35
+ return cls() # Default
36
+
37
+ def save(self, htmlgraph_dir: Path) -> None:
38
+ """Save metadata to .docs-metadata.json.
39
+
40
+ Args:
41
+ htmlgraph_dir: Path to .htmlgraph directory
42
+ """
43
+ metadata_file = htmlgraph_dir / ".docs-metadata.json"
44
+ metadata_file.write_text(self.model_dump_json(indent=2))
45
+
46
+ @classmethod
47
+ def create_initial(
48
+ cls, htmlgraph_dir: Path, schema_version: int = 2
49
+ ) -> "DocsMetadata":
50
+ """Create initial metadata file.
51
+
52
+ Args:
53
+ htmlgraph_dir: Path to .htmlgraph directory
54
+ schema_version: Documentation schema version
55
+
56
+ Returns:
57
+ New DocsMetadata instance
58
+ """
59
+ from htmlgraph import __version__
60
+
61
+ metadata = cls(
62
+ schema_version=schema_version,
63
+ base_version_on_last_update=__version__,
64
+ customizations=[],
65
+ )
66
+ metadata.save(htmlgraph_dir)
67
+ return metadata
68
+
69
+ def add_customization(self, section_name: str) -> None:
70
+ """Mark a section as customized.
71
+
72
+ Args:
73
+ section_name: Name of the customized section
74
+ """
75
+ if section_name not in self.customizations:
76
+ self.customizations.append(section_name)
77
+
78
+ def remove_customization(self, section_name: str) -> None:
79
+ """Remove a customization marker.
80
+
81
+ Args:
82
+ section_name: Name of the section to unmark
83
+ """
84
+ if section_name in self.customizations:
85
+ self.customizations.remove(section_name)
86
+
87
+ def has_customizations(self) -> bool:
88
+ """Check if any customizations exist.
89
+
90
+ Returns:
91
+ True if user has customized documentation
92
+ """
93
+ return len(self.customizations) > 0
@@ -0,0 +1,232 @@
1
+ """
2
+ Documentation migration system.
3
+
4
+ Handles version migrations with automatic customization preservation.
5
+ """
6
+
7
+ import shutil
8
+ from abc import ABC, abstractmethod
9
+ from datetime import datetime
10
+ from pathlib import Path
11
+
12
+ from htmlgraph.docs.metadata import DocsMetadata
13
+
14
+
15
+ class MigrationScript(ABC):
16
+ """Base class for documentation migrations."""
17
+
18
+ from_version: int
19
+ to_version: int
20
+
21
+ @abstractmethod
22
+ def migrate(self, htmlgraph_dir: Path, backup_dir: Path) -> bool:
23
+ """Execute migration. Returns True if successful.
24
+
25
+ Args:
26
+ htmlgraph_dir: Path to .htmlgraph directory
27
+ backup_dir: Path to backup directory
28
+
29
+ Returns:
30
+ True if migration successful
31
+ """
32
+ pass
33
+
34
+ @abstractmethod
35
+ def rollback(self, htmlgraph_dir: Path, backup_dir: Path) -> None:
36
+ """Rollback migration to previous state.
37
+
38
+ Args:
39
+ htmlgraph_dir: Path to .htmlgraph directory
40
+ backup_dir: Path to backup directory
41
+ """
42
+ pass
43
+
44
+ def backup_docs(self, htmlgraph_dir: Path, backup_dir: Path) -> Path:
45
+ """Backup current documentation before migration.
46
+
47
+ Args:
48
+ htmlgraph_dir: Path to .htmlgraph directory
49
+ backup_dir: Path to backup directory
50
+
51
+ Returns:
52
+ Path to created backup subdirectory
53
+ """
54
+ backup_subdir = (
55
+ backup_dir / f"v{self.from_version}_{datetime.now():%Y%m%d_%H%M%S}"
56
+ )
57
+ backup_subdir.mkdir(parents=True, exist_ok=True)
58
+
59
+ # Backup all docs
60
+ docs_dir = htmlgraph_dir / "docs"
61
+ if docs_dir.exists():
62
+ for doc_file in docs_dir.glob("*.md"):
63
+ shutil.copy2(doc_file, backup_subdir / doc_file.name)
64
+
65
+ # Also backup root-level docs (legacy)
66
+ for doc_file in htmlgraph_dir.glob("*.md"):
67
+ shutil.copy2(doc_file, backup_subdir / doc_file.name)
68
+
69
+ return backup_subdir
70
+
71
+
72
+ class V1toV2Migration(MigrationScript):
73
+ """Migrate from v1 (root-level docs) to v2 (template-based docs)."""
74
+
75
+ from_version = 1
76
+ to_version = 2
77
+
78
+ def migrate(self, htmlgraph_dir: Path, backup_dir: Path) -> bool:
79
+ """Migrate v1 docs to v2 template structure.
80
+
81
+ Args:
82
+ htmlgraph_dir: Path to .htmlgraph directory
83
+ backup_dir: Path to backup directory
84
+
85
+ Returns:
86
+ True if migration successful
87
+ """
88
+ # Backup first
89
+ backup_path = self.backup_docs(htmlgraph_dir, backup_dir)
90
+ print(f"✅ Backed up to {backup_path}")
91
+
92
+ # Detect user customizations in old AGENTS.md
93
+ customizations = self._detect_customizations(htmlgraph_dir / "AGENTS.md")
94
+ if customizations:
95
+ print(f"📝 Detected customizations: {', '.join(customizations)}")
96
+
97
+ # Move old docs to archive
98
+ old_agents_md = htmlgraph_dir / "AGENTS.md"
99
+ if old_agents_md.exists():
100
+ old_agents_md.rename(htmlgraph_dir / "AGENTS.md.v1.backup")
101
+ print("📦 Archived old AGENTS.md")
102
+
103
+ # Generate new v2 docs with customizations preserved
104
+ self._generate_v2_docs(htmlgraph_dir, customizations)
105
+ print("✨ Generated v2 documentation")
106
+
107
+ # Update metadata
108
+ metadata = DocsMetadata.load(htmlgraph_dir)
109
+ metadata.schema_version = 2
110
+ metadata.customizations = customizations
111
+ metadata.save(htmlgraph_dir)
112
+ print("💾 Updated metadata")
113
+
114
+ return True
115
+
116
+ def _detect_customizations(self, agents_md_path: Path) -> list[str]:
117
+ """Detect user-customized sections in old AGENTS.md.
118
+
119
+ Args:
120
+ agents_md_path: Path to AGENTS.md file
121
+
122
+ Returns:
123
+ List of customized section names
124
+ """
125
+ if not agents_md_path.exists():
126
+ return []
127
+
128
+ content = agents_md_path.read_text()
129
+ customizations = []
130
+
131
+ # Simple heuristic: sections not in base template
132
+ if "## Our Team" in content:
133
+ customizations.append("custom_workflows")
134
+ if "## Project Conventions" in content:
135
+ customizations.append("project_conventions")
136
+ if "## Custom Workflows" in content:
137
+ customizations.append("custom_workflows")
138
+
139
+ return customizations
140
+
141
+ def _generate_v2_docs(self, htmlgraph_dir: Path, customizations: list[str]) -> None:
142
+ """Generate v2 template-based docs with customizations.
143
+
144
+ Args:
145
+ htmlgraph_dir: Path to .htmlgraph directory
146
+ customizations: List of customized sections to preserve
147
+ """
148
+ # NOTE: This would integrate with sync_docs.py
149
+ # For now, just create placeholder
150
+ docs_dir = htmlgraph_dir / "docs"
151
+ docs_dir.mkdir(exist_ok=True)
152
+
153
+ placeholder = docs_dir / "AGENTS.md"
154
+ placeholder.write_text(
155
+ """# HtmlGraph Agent Documentation (v2)
156
+
157
+ This file was migrated from v1 to v2.
158
+
159
+ Run `uv run htmlgraph sync-docs` to regenerate from templates.
160
+ """
161
+ )
162
+
163
+ # Inject customizations as template overrides if needed
164
+ if customizations:
165
+ self._create_override_template(htmlgraph_dir, customizations)
166
+
167
+ def _create_override_template(
168
+ self, htmlgraph_dir: Path, customizations: list[str]
169
+ ) -> None:
170
+ """Create template overrides for customizations.
171
+
172
+ Args:
173
+ htmlgraph_dir: Path to .htmlgraph directory
174
+ customizations: List of customizations to preserve
175
+ """
176
+ overrides_file = htmlgraph_dir / "docs" / "overrides.md"
177
+ overrides_file.write_text(
178
+ f"""# Documentation Customizations
179
+
180
+ The following sections were customized in v1:
181
+
182
+ {chr(10).join(f"- {c}" for c in customizations)}
183
+
184
+ To preserve these customizations, add them back manually after running sync-docs.
185
+ """
186
+ )
187
+
188
+ def rollback(self, htmlgraph_dir: Path, backup_dir: Path) -> None:
189
+ """Rollback to v1 docs from backup.
190
+
191
+ Args:
192
+ htmlgraph_dir: Path to .htmlgraph directory
193
+ backup_dir: Path to backup directory
194
+ """
195
+ # Find latest backup
196
+ backups = sorted(backup_dir.glob("v1_*"))
197
+ if not backups:
198
+ raise ValueError("No backup found for rollback")
199
+
200
+ latest_backup = backups[-1]
201
+ print(f"🔄 Rolling back from {latest_backup}")
202
+
203
+ # Restore old AGENTS.md
204
+ backup_agents = latest_backup / "AGENTS.md"
205
+ if backup_agents.exists():
206
+ shutil.copy2(backup_agents, htmlgraph_dir / "AGENTS.md")
207
+ print("✅ Restored AGENTS.md")
208
+
209
+ # Update metadata
210
+ metadata = DocsMetadata.load(htmlgraph_dir)
211
+ metadata.schema_version = 1
212
+ metadata.save(htmlgraph_dir)
213
+ print("💾 Updated metadata to v1")
214
+
215
+
216
+ # Migration registry
217
+ MIGRATIONS: dict[tuple[int, int], MigrationScript] = {
218
+ (1, 2): V1toV2Migration(),
219
+ }
220
+
221
+
222
+ def get_migration(from_version: int, to_version: int) -> MigrationScript | None:
223
+ """Get migration script for version transition.
224
+
225
+ Args:
226
+ from_version: Source schema version
227
+ to_version: Target schema version
228
+
229
+ Returns:
230
+ MigrationScript instance or None if no migration exists
231
+ """
232
+ return MIGRATIONS.get((from_version, to_version))
@@ -0,0 +1,143 @@
1
+ """Jinja2-based template engine for documentation with user customization."""
2
+
3
+ from datetime import datetime
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ from jinja2 import ChoiceLoader, Environment, FileSystemLoader
8
+
9
+
10
+ class DocTemplateEngine:
11
+ """Renders documentation templates with user customization support.
12
+
13
+ Template Priority:
14
+ 1. User templates in .htmlgraph/docs/templates/ (highest priority)
15
+ 2. Package templates in htmlgraph/docs/templates/ (fallback)
16
+
17
+ Example:
18
+ >>> engine = DocTemplateEngine(Path(".htmlgraph"))
19
+ >>> content = engine.render_agents_md("0.21.0", "claude")
20
+ >>> print(content)
21
+ """
22
+
23
+ def __init__(self, htmlgraph_dir: Path):
24
+ """Initialize template engine with multi-loader.
25
+
26
+ Args:
27
+ htmlgraph_dir: Path to .htmlgraph directory
28
+ """
29
+ # Package templates (bundled with pip install)
30
+ package_templates = Path(__file__).parent / "templates"
31
+
32
+ # User templates (project-specific customizations)
33
+ user_templates = htmlgraph_dir / "docs" / "templates"
34
+
35
+ # Multi-loader: User templates have priority over package templates
36
+ loaders = []
37
+ if user_templates.exists():
38
+ loaders.append(FileSystemLoader(str(user_templates)))
39
+ loaders.append(FileSystemLoader(str(package_templates)))
40
+
41
+ self.env = Environment(loader=ChoiceLoader(loaders))
42
+
43
+ # Add custom filters
44
+ self.env.filters["format_date"] = self._format_date
45
+ self.env.filters["highlight_code"] = self._highlight_code
46
+
47
+ def render(self, template_name: str, context: dict[str, Any]) -> str:
48
+ """Render template with context, merging user overrides.
49
+
50
+ Args:
51
+ template_name: Name of template file (e.g., "agents.md.j2")
52
+ context: Template variables
53
+
54
+ Returns:
55
+ Rendered content with user customizations applied
56
+
57
+ Example:
58
+ >>> engine.render("agents.md.j2", {"platform": "claude"})
59
+ """
60
+ template = self.env.get_template(template_name)
61
+ return template.render(**context)
62
+
63
+ def render_agents_md(self, sdk_version: str, platform: str = "claude") -> str:
64
+ """Render AGENTS.md with platform-specific customizations.
65
+
66
+ Args:
67
+ sdk_version: HtmlGraph SDK version (e.g., "0.21.0")
68
+ platform: Platform name (claude, gemini, api, etc.)
69
+
70
+ Returns:
71
+ Rendered AGENTS.md content
72
+
73
+ Example:
74
+ >>> content = engine.render_agents_md("0.21.0", "claude")
75
+ """
76
+ context = {
77
+ "sdk_version": sdk_version,
78
+ "platform": platform,
79
+ "features_enabled": self._get_enabled_features(),
80
+ "custom_workflows": self._load_custom_workflows(),
81
+ "generated_at": datetime.now().isoformat(),
82
+ }
83
+ # User templates should extend "base_agents.md.j2" to avoid recursion
84
+ # Priority: agents.md.j2 (user override) → base_agents.md.j2 (package default)
85
+ template_name = "agents.md.j2"
86
+ try:
87
+ # Try to get user template first (will succeed if it exists in user dir)
88
+ self.env.get_template(template_name)
89
+ return self.render(template_name, context)
90
+ except: # noqa
91
+ # Fall back to base template (always exists in package)
92
+ return self.render("base_agents.md.j2", context)
93
+
94
+ def _format_date(self, value: str) -> str:
95
+ """Format ISO date string for display.
96
+
97
+ Args:
98
+ value: ISO 8601 date string
99
+
100
+ Returns:
101
+ Formatted date string
102
+ """
103
+ try:
104
+ dt = datetime.fromisoformat(value)
105
+ return dt.strftime("%Y-%m-%d %H:%M")
106
+ except (ValueError, AttributeError):
107
+ return value
108
+
109
+ def _highlight_code(self, code: str, language: str = "python") -> str:
110
+ """Add markdown code fence with syntax highlighting.
111
+
112
+ Args:
113
+ code: Code snippet
114
+ language: Programming language for syntax highlighting
115
+
116
+ Returns:
117
+ Markdown code block
118
+ """
119
+ return f"```{language}\n{code}\n```"
120
+
121
+ def _get_enabled_features(self) -> dict[str, bool]:
122
+ """Get enabled features for this installation.
123
+
124
+ Returns:
125
+ Dictionary of feature flags
126
+ """
127
+ # TODO: Read from config or detect dynamically
128
+ return {
129
+ "sessions": True,
130
+ "tracks": True,
131
+ "analytics": True,
132
+ "mcp": True,
133
+ "cli": True,
134
+ }
135
+
136
+ def _load_custom_workflows(self) -> str | None:
137
+ """Load custom workflows from user template.
138
+
139
+ Returns:
140
+ Custom workflow markdown or None
141
+ """
142
+ # TODO: Load from .htmlgraph/docs/workflows.md if exists
143
+ return None
@@ -0,0 +1,52 @@
1
+ ## CLI Reference
2
+
3
+ ### Installation
4
+
5
+ ```bash
6
+ pip install htmlgraph
7
+ ```
8
+
9
+ ### Basic Commands
10
+
11
+ ```bash
12
+ # Initialize project
13
+ htmlgraph init
14
+
15
+ # Create work items
16
+ htmlgraph feature create "Add authentication"
17
+ htmlgraph bug create "Fix login redirect"
18
+ htmlgraph spike create "Research OAuth providers"
19
+
20
+ # List work items
21
+ htmlgraph feature list
22
+ htmlgraph status
23
+
24
+ # Start MCP server
25
+ htmlgraph mcp
26
+ ```
27
+
28
+ ### Session Management
29
+
30
+ ```bash
31
+ # List sessions
32
+ htmlgraph session list
33
+
34
+ # Show active sessions
35
+ htmlgraph session list --active
36
+
37
+ # Link session to work item
38
+ htmlgraph session link <session-id> <feature-id>
39
+ ```
40
+
41
+ ### Documentation
42
+
43
+ ```bash
44
+ # Generate documentation
45
+ htmlgraph docs generate --platform {{ platform }}
46
+
47
+ # Sync documentation files
48
+ htmlgraph sync-docs
49
+
50
+ # Validate documentation
51
+ htmlgraph docs validate
52
+ ```
@@ -0,0 +1,29 @@
1
+ ## Core Concepts
2
+
3
+ ### Graph Structure
4
+
5
+ HtmlGraph uses HTML files as graph nodes and hyperlinks as edges:
6
+
7
+ - **Nodes**: HTML files with `data-*` attributes
8
+ - **Edges**: `<a href>` links between files
9
+ - **Properties**: `data-*` attributes on elements
10
+ - **Query Language**: CSS selectors
11
+
12
+ ### Work Item Types
13
+
14
+ HtmlGraph supports multiple work item types:
15
+
16
+ 1. **Features** - New capabilities or enhancements
17
+ 2. **Bugs** - Issues to fix
18
+ 3. **Spikes** - Research or investigation tasks
19
+ 4. **Chores** - Maintenance and refactoring
20
+ 5. **Tracks** - Multi-feature initiatives
21
+
22
+ ### Session Tracking
23
+
24
+ HtmlGraph automatically tracks agent sessions via git hooks:
25
+
26
+ - Session start/end detection
27
+ - Work item linking
28
+ - Event logging
29
+ - Transcript capture
@@ -0,0 +1,69 @@
1
+ ## SDK Reference
2
+
3
+ ### SDK Initialization
4
+
5
+ ```python
6
+ from htmlgraph import SDK
7
+
8
+ # Initialize with agent name
9
+ sdk = SDK(agent="{{ platform }}")
10
+
11
+ # Access collections
12
+ features = sdk.features
13
+ bugs = sdk.bugs
14
+ spikes = sdk.spikes
15
+ tracks = sdk.tracks
16
+ sessions = sdk.sessions
17
+ ```
18
+
19
+ ### Features API
20
+
21
+ ```python
22
+ # Create feature
23
+ feature = sdk.features.create("Add authentication") \
24
+ .set_priority("high") \
25
+ .set_status("in-progress") \
26
+ .add_steps([
27
+ "Setup OAuth provider",
28
+ "Implement JWT tokens",
29
+ "Add session management"
30
+ ]) \
31
+ .save()
32
+
33
+ # Update feature
34
+ feature = sdk.features.get(feature.id) \
35
+ .complete_step(0) \
36
+ .save()
37
+
38
+ # List features
39
+ all_features = sdk.features.list()
40
+ high_priority = sdk.features.filter(priority="high")
41
+ in_progress = sdk.features.filter(status="in-progress")
42
+ ```
43
+
44
+ ### Tracks API
45
+
46
+ ```python
47
+ # Create track
48
+ track = sdk.tracks.create("Authentication System") \
49
+ .set_priority("high") \
50
+ .add_feature(feature.id) \
51
+ .save()
52
+
53
+ # Get track progress
54
+ progress = track.get_progress()
55
+ print(f"Completion: {progress['completion_percentage']}%")
56
+ ```
57
+
58
+ ### Analytics
59
+
60
+ ```python
61
+ # Get strategic recommendations
62
+ next_work = sdk.analytics.recommend_next_work(limit=5)
63
+
64
+ # Find bottlenecks
65
+ bottlenecks = sdk.analytics.find_bottlenecks()
66
+
67
+ # Get summary
68
+ summary = sdk.summary()
69
+ ```
@@ -0,0 +1,78 @@
1
+ {# Base template for AGENTS.md - Package provides this #}
2
+ ---
3
+ version: "{{ sdk_version }}"
4
+ platform: "{{ platform }}"
5
+ generated: "{{ generated_at }}"
6
+ ---
7
+
8
+ {% block header %}
9
+ # HtmlGraph Agent Documentation
10
+ {% endblock %}
11
+
12
+ {% block introduction %}
13
+ ## Introduction
14
+
15
+ HtmlGraph is a lightweight graph database framework built entirely on web standards (HTML, CSS, JavaScript) for AI agent coordination and human observability.
16
+
17
+ **Tagline**: "HTML is All You Need"
18
+ {% endblock %}
19
+
20
+ {% block quick_start %}
21
+ ## Quick Start
22
+
23
+ ```python
24
+ from htmlgraph import SDK
25
+
26
+ # Initialize SDK for your agent
27
+ sdk = SDK(agent="{{ platform }}")
28
+
29
+ # Create a feature
30
+ feature = sdk.features.create("Add authentication") \
31
+ .set_priority("high") \
32
+ .add_steps(["Setup OAuth", "Add JWT", "Test login"]) \
33
+ .save()
34
+
35
+ # Track progress
36
+ sdk.features.get(feature.id).complete_step(0).save()
37
+ ```
38
+ {% endblock %}
39
+
40
+ {% block core_concepts %}
41
+ {% include "_sections/core_concepts.md.j2" %}
42
+ {% endblock %}
43
+
44
+ {% block sdk_reference %}
45
+ {% include "_sections/sdk_basics.md.j2" %}
46
+ {% endblock %}
47
+
48
+ {% block cli_reference %}
49
+ {% include "_sections/cli_reference.md.j2" %}
50
+ {% endblock %}
51
+
52
+ {% block custom_workflows %}
53
+ {# Users can override this block in .htmlgraph/docs/templates/agents.md.j2 #}
54
+ {% if custom_workflows %}
55
+ ## Custom Workflows
56
+
57
+ {{ custom_workflows }}
58
+ {% endif %}
59
+ {% endblock %}
60
+
61
+ {% block deployment %}
62
+ ## Deployment
63
+
64
+ For deployment instructions, see the deployment guide:
65
+
66
+ ```bash
67
+ # Build and publish package
68
+ ./scripts/deploy-all.sh 0.21.0 --no-confirm
69
+
70
+ # Documentation changes only
71
+ ./scripts/deploy-all.sh --docs-only
72
+ ```
73
+ {% endblock %}
74
+
75
+ {% block footer %}
76
+ ---
77
+ *Generated by HtmlGraph v{{ sdk_version }} on {{ generated_at }}*
78
+ {% endblock %}