arcane-mcp 0.2.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.
- arcane/__init__.py +8 -0
- arcane/cli/__init__.py +78 -0
- arcane/cli/_plugins.py +92 -0
- arcane/cli/_utils.py +9 -0
- arcane/cli/analyze.py +73 -0
- arcane/cli/artifact.py +50 -0
- arcane/cli/backup.py +33 -0
- arcane/cli/config.py +53 -0
- arcane/cli/draft.py +74 -0
- arcane/cli/ingest.py +91 -0
- arcane/cli/journey.py +125 -0
- arcane/cli/memory.py +316 -0
- arcane/cli/migrate.py +186 -0
- arcane/cli/relationship.py +69 -0
- arcane/cli/report.py +75 -0
- arcane/domain/__init__.py +0 -0
- arcane/domain/enums.py +55 -0
- arcane/domain/models.py +220 -0
- arcane/domain/results.py +13 -0
- arcane/domain/scope.py +231 -0
- arcane/infra/__init__.py +0 -0
- arcane/infra/adapters/__init__.py +0 -0
- arcane/infra/config.py +216 -0
- arcane/infra/db/__init__.py +0 -0
- arcane/infra/db/artifact_repo.py +194 -0
- arcane/infra/db/connection.py +164 -0
- arcane/infra/db/fts.py +55 -0
- arcane/infra/db/ids.py +60 -0
- arcane/infra/db/insight_repo.py +97 -0
- arcane/infra/db/journey_repo.py +221 -0
- arcane/infra/db/memory_repo.py +642 -0
- arcane/infra/db/relationship_repo.py +161 -0
- arcane/infra/db/retrieval_repo.py +226 -0
- arcane/infra/db/schema.py +464 -0
- arcane/infra/embeddings/__init__.py +0 -0
- arcane/infra/embeddings/base.py +24 -0
- arcane/infra/embeddings/ollama.py +196 -0
- arcane/infra/embeddings/openai_embed.py +41 -0
- arcane/infra/embeddings/redacting.py +20 -0
- arcane/infra/logging.py +42 -0
- arcane/infra/markdown.py +307 -0
- arcane/infra/paths.py +43 -0
- arcane/infra/redaction.py +146 -0
- arcane/infra/search.py +161 -0
- arcane/mcp_server/__init__.py +0 -0
- arcane/mcp_server/prompts.py +96 -0
- arcane/mcp_server/resources.py +14 -0
- arcane/mcp_server/schemas.py +54 -0
- arcane/mcp_server/server.py +755 -0
- arcane/mcp_server/tools/__init__.py +0 -0
- arcane/mcp_server/tools/artifact_tools.py +49 -0
- arcane/mcp_server/tools/content_tools.py +67 -0
- arcane/mcp_server/tools/ingestion_tools.py +81 -0
- arcane/mcp_server/tools/intelligence_tools.py +41 -0
- arcane/mcp_server/tools/journey_tools.py +145 -0
- arcane/mcp_server/tools/memory_tools.py +403 -0
- arcane/mcp_server/tools/plugin_tools.py +51 -0
- arcane/mcp_server/tools/relationship_tools.py +78 -0
- arcane/mcp_server/usage.py +109 -0
- arcane/plugins/__init__.py +0 -0
- arcane/plugins/builtin/__init__.py +0 -0
- arcane/plugins/builtin/adr_gen.py +92 -0
- arcane/plugins/builtin/blog_gen.py +122 -0
- arcane/plugins/builtin/gha_ingest.py +173 -0
- arcane/plugins/builtin/git_ingest.py +143 -0
- arcane/plugins/builtin/health_audit.py +160 -0
- arcane/plugins/builtin/linear_ingest.py +191 -0
- arcane/plugins/builtin/usage.py +143 -0
- arcane/plugins/builtin/velocity.py +92 -0
- arcane/plugins/protocols.py +43 -0
- arcane/plugins/registry.py +106 -0
- arcane/services/__init__.py +0 -0
- arcane/services/backup.py +127 -0
- arcane/services/container.py +134 -0
- arcane/services/ingestion.py +100 -0
- arcane/services/intelligence.py +48 -0
- arcane/services/journey.py +164 -0
- arcane/services/memory.py +716 -0
- arcane/services/migration.py +196 -0
- arcane/services/report.py +156 -0
- arcane_mcp-0.2.0.dist-info/METADATA +253 -0
- arcane_mcp-0.2.0.dist-info/RECORD +85 -0
- arcane_mcp-0.2.0.dist-info/WHEEL +4 -0
- arcane_mcp-0.2.0.dist-info/entry_points.txt +17 -0
- arcane_mcp-0.2.0.dist-info/licenses/LICENSE +21 -0
arcane/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Arcane — Unified engineering intelligence platform."""
|
|
2
|
+
|
|
3
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
__version__ = version("arcane-mcp")
|
|
7
|
+
except PackageNotFoundError: # pragma: no cover - source checkout without an install
|
|
8
|
+
__version__ = "0.0.0+unknown"
|
arcane/cli/__init__.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Arcane CLI — command groups assembled from sub-modules."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
from arcane import __version__
|
|
8
|
+
from arcane.cli.analyze import analyze
|
|
9
|
+
from arcane.cli.artifact import artifact
|
|
10
|
+
from arcane.cli.backup import backup
|
|
11
|
+
from arcane.cli.config import config
|
|
12
|
+
from arcane.cli.draft import draft
|
|
13
|
+
from arcane.cli.ingest import ingest
|
|
14
|
+
from arcane.cli.journey import journey
|
|
15
|
+
from arcane.cli.memory import (
|
|
16
|
+
context,
|
|
17
|
+
delete,
|
|
18
|
+
details,
|
|
19
|
+
init,
|
|
20
|
+
merge_projects,
|
|
21
|
+
projects,
|
|
22
|
+
reindex,
|
|
23
|
+
save,
|
|
24
|
+
search,
|
|
25
|
+
sessions,
|
|
26
|
+
stats,
|
|
27
|
+
)
|
|
28
|
+
from arcane.cli.migrate import migrate
|
|
29
|
+
from arcane.cli.relationship import link, trace
|
|
30
|
+
from arcane.cli.report import export, report
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@click.group()
|
|
34
|
+
@click.version_option(__version__, prog_name="arcane")
|
|
35
|
+
@click.option("--verbose", "-v", is_flag=True, default=False, help="Enable debug logging.")
|
|
36
|
+
@click.pass_context
|
|
37
|
+
def main(ctx: click.Context, verbose: bool) -> None:
|
|
38
|
+
"""Arcane — unified engineering intelligence."""
|
|
39
|
+
from arcane.infra.logging import configure_logging
|
|
40
|
+
|
|
41
|
+
configure_logging(verbose=verbose)
|
|
42
|
+
ctx.ensure_object(dict)
|
|
43
|
+
ctx.obj["verbose"] = verbose
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
main.add_command(init)
|
|
47
|
+
main.add_command(save)
|
|
48
|
+
main.add_command(search)
|
|
49
|
+
main.add_command(details)
|
|
50
|
+
main.add_command(delete)
|
|
51
|
+
main.add_command(context)
|
|
52
|
+
main.add_command(reindex)
|
|
53
|
+
main.add_command(stats)
|
|
54
|
+
main.add_command(backup)
|
|
55
|
+
main.add_command(sessions)
|
|
56
|
+
main.add_command(projects)
|
|
57
|
+
main.add_command(merge_projects)
|
|
58
|
+
main.add_command(journey)
|
|
59
|
+
main.add_command(link)
|
|
60
|
+
main.add_command(trace)
|
|
61
|
+
main.add_command(migrate)
|
|
62
|
+
main.add_command(config)
|
|
63
|
+
main.add_command(ingest)
|
|
64
|
+
main.add_command(analyze)
|
|
65
|
+
main.add_command(artifact)
|
|
66
|
+
main.add_command(draft)
|
|
67
|
+
main.add_command(report)
|
|
68
|
+
main.add_command(export)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
@main.command()
|
|
72
|
+
def mcp() -> None:
|
|
73
|
+
"""Start the Arcane MCP server (stdio transport)."""
|
|
74
|
+
import asyncio
|
|
75
|
+
|
|
76
|
+
from arcane.mcp_server.server import run_server
|
|
77
|
+
|
|
78
|
+
asyncio.run(run_server())
|
arcane/cli/_plugins.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Shared Click surface for installed entry-point plugins."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import click
|
|
9
|
+
|
|
10
|
+
from arcane.cli._utils import create_container
|
|
11
|
+
from arcane.domain.scope import resolve_write_scope
|
|
12
|
+
from arcane.infra.db.ids import IdentifierResolutionError
|
|
13
|
+
from arcane.infra.redaction import redact
|
|
14
|
+
from arcane.plugins.protocols import IngestionError
|
|
15
|
+
from arcane.plugins.registry import PluginError, command_name, create_plugin, describe_plugins, plugins_for
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def json_object(value: str) -> dict[str, Any]:
|
|
19
|
+
"""Parse a JSON object passed at the command boundary."""
|
|
20
|
+
try:
|
|
21
|
+
parsed = json.loads(value)
|
|
22
|
+
except ValueError as exc:
|
|
23
|
+
raise click.BadParameter(f"Expected a JSON object: {exc}") from exc
|
|
24
|
+
if not isinstance(parsed, dict):
|
|
25
|
+
raise click.BadParameter("Expected a JSON object")
|
|
26
|
+
return parsed
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def list_plugins(kind: str) -> None:
|
|
30
|
+
for plugin in describe_plugins(kind):
|
|
31
|
+
description = plugin["description"].splitlines()[0] if plugin["description"] else "(no description)"
|
|
32
|
+
click.echo(f"{command_name(kind, plugin['name'])}: {description}")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class PluginGroup(click.Group):
|
|
36
|
+
"""Keep existing commands and discover additional installed plugins lazily."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, *args: Any, kind: str, **kwargs: Any) -> None:
|
|
39
|
+
super().__init__(*args, **kwargs)
|
|
40
|
+
self.kind = kind
|
|
41
|
+
|
|
42
|
+
def invoke(self, ctx: click.Context) -> Any:
|
|
43
|
+
try:
|
|
44
|
+
return super().invoke(ctx)
|
|
45
|
+
except (PluginError, IngestionError, IdentifierResolutionError) as exc:
|
|
46
|
+
raise click.ClickException(str(exc)) from exc
|
|
47
|
+
|
|
48
|
+
def list_commands(self, ctx: click.Context) -> list[str]:
|
|
49
|
+
discovered = {command_name(self.kind, name) for name in plugins_for(self.kind)}
|
|
50
|
+
return sorted(set(super().list_commands(ctx)) | discovered)
|
|
51
|
+
|
|
52
|
+
def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None:
|
|
53
|
+
existing = super().get_command(ctx, cmd_name)
|
|
54
|
+
if existing:
|
|
55
|
+
return existing
|
|
56
|
+
descriptions = {p["name"]: p for p in describe_plugins(self.kind)}
|
|
57
|
+
if cmd_name not in descriptions:
|
|
58
|
+
return None
|
|
59
|
+
info = descriptions[cmd_name]
|
|
60
|
+
|
|
61
|
+
@click.command(cmd_name, help=f"{info['description']}\n\nConstructor options: {info['options']}")
|
|
62
|
+
@click.option("--options", default="{}", help="Plugin constructor options as a JSON object.")
|
|
63
|
+
@click.option("--project", default=None, help="Project name (default: current repository).")
|
|
64
|
+
@click.option("--journey-id", default=None, help="Link ingested artifacts to a journey.")
|
|
65
|
+
@click.option("--context", default="{}", help="Content generation context as a JSON object.")
|
|
66
|
+
def run(options: str, project: str | None, journey_id: str | None, context: str) -> None:
|
|
67
|
+
settings = json_object(options)
|
|
68
|
+
content_context = json_object(context)
|
|
69
|
+
try:
|
|
70
|
+
with create_container() as container:
|
|
71
|
+
plugin = create_plugin(self.kind, cmd_name, container, settings)
|
|
72
|
+
if self.kind == "ingestion":
|
|
73
|
+
from arcane.services.ingestion import IngestionService
|
|
74
|
+
|
|
75
|
+
result = IngestionService(container).run_plugin(
|
|
76
|
+
plugin, project=project, journey_id=journey_id, repo_path=settings.get("repo_path")
|
|
77
|
+
)
|
|
78
|
+
elif self.kind == "intelligence":
|
|
79
|
+
from arcane.services.intelligence import IntelligenceService
|
|
80
|
+
|
|
81
|
+
result = IntelligenceService(container).run_plugin(plugin, project=project)
|
|
82
|
+
else:
|
|
83
|
+
content_context["org"] = resolve_write_scope(project, container.config).org
|
|
84
|
+
if project is not None:
|
|
85
|
+
content_context["project"] = project
|
|
86
|
+
click.echo(redact(plugin.generate(content_context), container.ignore_patterns))
|
|
87
|
+
return
|
|
88
|
+
except (PluginError, IngestionError, IdentifierResolutionError) as exc:
|
|
89
|
+
raise click.ClickException(str(exc)) from exc
|
|
90
|
+
click.echo(json.dumps(result))
|
|
91
|
+
|
|
92
|
+
return run
|
arcane/cli/_utils.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Shared utilities for CLI command modules.
|
|
2
|
+
|
|
3
|
+
Centralises the ``create_container`` import so tests have a single patch
|
|
4
|
+
target: ``arcane.cli._utils.create_container``.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from arcane.services.container import ServiceContainer, create_container
|
|
8
|
+
|
|
9
|
+
__all__ = ["ServiceContainer", "create_container"]
|
arcane/cli/analyze.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Analysis commands — velocity, health and usage."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
from arcane.cli._plugins import PluginGroup, list_plugins
|
|
8
|
+
from arcane.cli._utils import create_container
|
|
9
|
+
from arcane.plugins.registry import create_plugin
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@click.group(cls=PluginGroup, kind="intelligence", invoke_without_command=True)
|
|
13
|
+
@click.option("--list", "show_plugins", is_flag=True, help="List installed entry-point plugins.")
|
|
14
|
+
@click.pass_context
|
|
15
|
+
def analyze(ctx: click.Context, show_plugins: bool) -> None:
|
|
16
|
+
"""Run intelligence analysis plugins."""
|
|
17
|
+
if show_plugins:
|
|
18
|
+
list_plugins("intelligence")
|
|
19
|
+
elif ctx.invoked_subcommand is None:
|
|
20
|
+
click.echo(ctx.get_help())
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@analyze.command("health")
|
|
24
|
+
@click.option("--project", default=None, help="Project to attach the insights to")
|
|
25
|
+
def analyze_health(project: str | None) -> None:
|
|
26
|
+
"""Audit store health — fragmentation, orphans, duplicates, journey hygiene."""
|
|
27
|
+
|
|
28
|
+
with create_container() as container:
|
|
29
|
+
plugin = create_plugin("intelligence", "health", container)
|
|
30
|
+
from arcane.services.intelligence import IntelligenceService
|
|
31
|
+
|
|
32
|
+
result = IntelligenceService(container).run_plugin(plugin, project=project)
|
|
33
|
+
insights = container.insight_repo.list_all(
|
|
34
|
+
project=result["project"], org=result["org"], limit=result["insights_created"]
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
for insight in insights:
|
|
38
|
+
marker = "!" if insight["severity"] != "info" else "-"
|
|
39
|
+
click.echo(f"\n{marker} [{insight['severity']}] {insight['title']}")
|
|
40
|
+
click.echo(insight["body"])
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@analyze.command("usage")
|
|
44
|
+
@click.option("--days", default=30, show_default=True, help="Window to report on")
|
|
45
|
+
@click.option("--project", default=None, help="Project to attach the insights to")
|
|
46
|
+
def analyze_usage(days: int, project: str | None) -> None:
|
|
47
|
+
"""Report what agents recall — lookups, empty searches, unused memories."""
|
|
48
|
+
from arcane.services.intelligence import IntelligenceService
|
|
49
|
+
|
|
50
|
+
with create_container() as container:
|
|
51
|
+
plugin = create_plugin("intelligence", "usage", container, {"days": days})
|
|
52
|
+
result = IntelligenceService(container).run_plugin(plugin, project=project)
|
|
53
|
+
insights = container.insight_repo.list_all(
|
|
54
|
+
project=result["project"], org=result["org"], limit=result["insights_created"]
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
for insight in reversed(insights):
|
|
58
|
+
marker = "!" if insight["severity"] != "info" else "-"
|
|
59
|
+
click.echo(f"\n{marker} [{insight['severity']}] {insight['title']}")
|
|
60
|
+
click.echo(insight["body"])
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@analyze.command("velocity")
|
|
64
|
+
@click.option("--project", default=None, help="Project name")
|
|
65
|
+
def analyze_velocity(project: str | None) -> None:
|
|
66
|
+
"""Generate engineering velocity summary."""
|
|
67
|
+
from arcane.services.intelligence import IntelligenceService
|
|
68
|
+
|
|
69
|
+
with create_container() as container:
|
|
70
|
+
plugin = create_plugin("intelligence", "velocity", container)
|
|
71
|
+
result = IntelligenceService(container).run_plugin(plugin, project=project)
|
|
72
|
+
|
|
73
|
+
click.echo(f"Velocity analysis: {result['insights_created']} insight(s) created")
|
arcane/cli/artifact.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Artifact commands — search and inspect ingested external records."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from arcane.cli._utils import create_container
|
|
10
|
+
from arcane.domain.scope import resolve_write_scope
|
|
11
|
+
from arcane.infra.db.ids import IdentifierResolutionError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@click.group()
|
|
15
|
+
def artifact() -> None:
|
|
16
|
+
"""Search and inspect ingested artifacts."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@artifact.command("search")
|
|
20
|
+
@click.argument("query")
|
|
21
|
+
@click.option("--project", default=None)
|
|
22
|
+
@click.option("--type", "artifact_type", default=None)
|
|
23
|
+
@click.option("--limit", default=10)
|
|
24
|
+
def artifact_search(query: str, project: str | None, artifact_type: str | None, limit: int) -> None:
|
|
25
|
+
"""Search artifact titles, IDs, and ingested raw content."""
|
|
26
|
+
with create_container() as container:
|
|
27
|
+
scope = resolve_write_scope(project, container.config)
|
|
28
|
+
artifacts = container.artifact_repo.fts_search(
|
|
29
|
+
query, project=scope.project, org=scope.org, artifact_type=artifact_type, limit=limit
|
|
30
|
+
)
|
|
31
|
+
if not artifacts:
|
|
32
|
+
click.echo("No artifacts found.")
|
|
33
|
+
return
|
|
34
|
+
for item in artifacts:
|
|
35
|
+
click.echo(f"[{item['artifact_type']}] {item['title']} ({item['id'][:12]})")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@artifact.command("show")
|
|
39
|
+
@click.argument("artifact_id")
|
|
40
|
+
def artifact_show(artifact_id: str) -> None:
|
|
41
|
+
"""Show complete artifact data by ID or prefix."""
|
|
42
|
+
with create_container() as container:
|
|
43
|
+
try:
|
|
44
|
+
item = container.artifact_repo.get(artifact_id, org=resolve_write_scope(None, container.config).org)
|
|
45
|
+
except IdentifierResolutionError as exc:
|
|
46
|
+
raise click.ClickException(str(exc)) from exc
|
|
47
|
+
if not item:
|
|
48
|
+
click.echo(f"Artifact {artifact_id} not found.")
|
|
49
|
+
return
|
|
50
|
+
click.echo(json.dumps(item, indent=2, sort_keys=True))
|
arcane/cli/backup.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Backup command — snapshot the database and vault into a rotated archive."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@click.command()
|
|
11
|
+
@click.option(
|
|
12
|
+
"--dest",
|
|
13
|
+
default=None,
|
|
14
|
+
help="Directory for archives (default: <home>/backups). Point it off this disk to survive a disk loss.",
|
|
15
|
+
)
|
|
16
|
+
@click.option("--keep", default=14, show_default=True, help="Archives to keep; older ones are deleted. 0 keeps all.")
|
|
17
|
+
def backup(dest: str | None, keep: int) -> None:
|
|
18
|
+
"""Back up the database and vault to a timestamped .tar.gz."""
|
|
19
|
+
from arcane.infra.config import get_home
|
|
20
|
+
from arcane.services.backup import BackupError, create_backup
|
|
21
|
+
|
|
22
|
+
if keep < 0:
|
|
23
|
+
raise click.BadParameter("must be 0 or more", param_hint="--keep")
|
|
24
|
+
home = get_home()
|
|
25
|
+
target = os.path.expanduser(dest) if dest else os.path.join(home, "backups")
|
|
26
|
+
try:
|
|
27
|
+
result = create_backup(home, target, keep=keep)
|
|
28
|
+
except BackupError as exc:
|
|
29
|
+
raise click.ClickException(str(exc)) from exc
|
|
30
|
+
|
|
31
|
+
click.echo(f"Backed up {result.memories} memories to {result.path} ({result.size_bytes / 1_000_000:.1f} MB)")
|
|
32
|
+
for name in result.pruned:
|
|
33
|
+
click.echo(f" removed old backup {name}")
|
arcane/cli/config.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Config commands — show, set-home, clear-home."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
import yaml
|
|
9
|
+
|
|
10
|
+
from arcane.infra.config import (
|
|
11
|
+
clear_persisted_home,
|
|
12
|
+
load_config,
|
|
13
|
+
resolve_home,
|
|
14
|
+
set_persisted_home,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _redact_api_keys(data: dict) -> dict:
|
|
19
|
+
for section in ("embedding",):
|
|
20
|
+
cfg = data.get(section)
|
|
21
|
+
if isinstance(cfg, dict) and cfg.get("api_key"):
|
|
22
|
+
cfg["api_key"] = "<redacted>"
|
|
23
|
+
return data
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@click.group(invoke_without_command=True)
|
|
27
|
+
@click.pass_context
|
|
28
|
+
def config(ctx: click.Context) -> None:
|
|
29
|
+
"""Show or manage configuration."""
|
|
30
|
+
if ctx.invoked_subcommand is None:
|
|
31
|
+
home, source = resolve_home()
|
|
32
|
+
cfg = load_config(os.path.join(home, "config.yaml"))
|
|
33
|
+
data = _redact_api_keys(cfg.model_dump())
|
|
34
|
+
data["arcane_home"] = home
|
|
35
|
+
data["arcane_home_source"] = source
|
|
36
|
+
click.echo(yaml.safe_dump(data, sort_keys=False))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@config.command("set-home")
|
|
40
|
+
@click.argument("path")
|
|
41
|
+
def config_set_home(path: str) -> None:
|
|
42
|
+
"""Persist arcane home location."""
|
|
43
|
+
resolved = set_persisted_home(path)
|
|
44
|
+
os.makedirs(resolved, exist_ok=True)
|
|
45
|
+
os.makedirs(os.path.join(resolved, "vault"), exist_ok=True)
|
|
46
|
+
click.echo(f"Persisted arcane home: {resolved}")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@config.command("clear-home")
|
|
50
|
+
def config_clear_home() -> None:
|
|
51
|
+
"""Remove persisted home setting."""
|
|
52
|
+
changed = clear_persisted_home()
|
|
53
|
+
click.echo("Cleared." if changed else "No setting found.")
|
arcane/cli/draft.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Draft commands — blog and ADR generation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
from arcane.cli._plugins import PluginGroup, list_plugins
|
|
8
|
+
from arcane.cli._utils import create_container
|
|
9
|
+
from arcane.domain.scope import resolve_write_scope
|
|
10
|
+
from arcane.infra.redaction import redact
|
|
11
|
+
from arcane.plugins.registry import create_plugin
|
|
12
|
+
from arcane.services.memory import MemoryService
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@click.group(cls=PluginGroup, kind="content", invoke_without_command=True)
|
|
16
|
+
@click.option("--list", "show_plugins", is_flag=True, help="List installed entry-point plugins.")
|
|
17
|
+
@click.pass_context
|
|
18
|
+
def draft(ctx: click.Context, show_plugins: bool) -> None:
|
|
19
|
+
"""Generate structured content briefs."""
|
|
20
|
+
if show_plugins:
|
|
21
|
+
list_plugins("content")
|
|
22
|
+
elif ctx.invoked_subcommand is None:
|
|
23
|
+
click.echo(ctx.get_help())
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@draft.command("blog")
|
|
27
|
+
@click.option("--journey-id", default=None, help="Journey to generate brief from")
|
|
28
|
+
@click.option("--project", default=None, help="Project for memory-based brief")
|
|
29
|
+
def draft_blog(journey_id: str | None, project: str | None) -> None:
|
|
30
|
+
"""Generate a structured blog brief."""
|
|
31
|
+
|
|
32
|
+
with create_container() as container:
|
|
33
|
+
context: dict = {}
|
|
34
|
+
if journey_id:
|
|
35
|
+
from arcane.services.journey import JourneyService
|
|
36
|
+
|
|
37
|
+
journey_data = JourneyService(container).show(journey_id)
|
|
38
|
+
if not journey_data:
|
|
39
|
+
click.echo(f"Journey {journey_id} not found.")
|
|
40
|
+
return
|
|
41
|
+
context["journey"] = journey_data
|
|
42
|
+
elif project:
|
|
43
|
+
scope = resolve_write_scope(project, container.config)
|
|
44
|
+
context["memories"], _ = MemoryService(container).get_context(
|
|
45
|
+
limit=20, project=scope.project, org=scope.org
|
|
46
|
+
)
|
|
47
|
+
context["project"] = project
|
|
48
|
+
else:
|
|
49
|
+
click.echo("Provide --journey-id or --project.")
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
brief = redact(create_plugin("content", "blog", container).generate(context), container.ignore_patterns)
|
|
53
|
+
|
|
54
|
+
click.echo(brief)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@draft.command("adr")
|
|
58
|
+
@click.argument("memory_id")
|
|
59
|
+
def draft_adr(memory_id: str) -> None:
|
|
60
|
+
"""Generate a structured ADR from a decision memory."""
|
|
61
|
+
|
|
62
|
+
with create_container() as container:
|
|
63
|
+
mem = container.memory_repo.get(memory_id)
|
|
64
|
+
if not mem:
|
|
65
|
+
click.echo(f"Memory {memory_id} not found.")
|
|
66
|
+
return
|
|
67
|
+
detail = container.memory_repo.get_details(memory_id)
|
|
68
|
+
detail_body = detail["body"] if detail else ""
|
|
69
|
+
adr = redact(
|
|
70
|
+
create_plugin("content", "adr", container).generate(context={"memory": mem, "details": detail_body}),
|
|
71
|
+
container.ignore_patterns,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
click.echo(adr)
|
arcane/cli/ingest.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Ingestion commands — git, gha, linear."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import TYPE_CHECKING, Any
|
|
7
|
+
|
|
8
|
+
import click
|
|
9
|
+
|
|
10
|
+
from arcane.cli._plugins import PluginGroup, list_plugins
|
|
11
|
+
from arcane.cli._utils import create_container
|
|
12
|
+
from arcane.infra.db.ids import IdentifierResolutionError
|
|
13
|
+
from arcane.plugins.protocols import IngestionError
|
|
14
|
+
from arcane.plugins.registry import create_plugin
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from arcane.plugins.protocols import IngestionPlugin
|
|
18
|
+
from arcane.services.ingestion import IngestionService
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _run(
|
|
22
|
+
svc: IngestionService,
|
|
23
|
+
plugin: IngestionPlugin,
|
|
24
|
+
project: str | None,
|
|
25
|
+
journey_id: str | None,
|
|
26
|
+
repo_path: str | None = None,
|
|
27
|
+
) -> dict[str, Any]:
|
|
28
|
+
try:
|
|
29
|
+
return svc.run_plugin(plugin, project=project, journey_id=journey_id, repo_path=repo_path)
|
|
30
|
+
except (IdentifierResolutionError, IngestionError) as exc:
|
|
31
|
+
raise click.ClickException(str(exc)) from exc
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@click.group(cls=PluginGroup, kind="ingestion", invoke_without_command=True)
|
|
35
|
+
@click.option("--list", "show_plugins", is_flag=True, help="List installed entry-point plugins.")
|
|
36
|
+
@click.pass_context
|
|
37
|
+
def ingest(ctx: click.Context, show_plugins: bool) -> None:
|
|
38
|
+
"""Ingest data from external sources."""
|
|
39
|
+
if show_plugins:
|
|
40
|
+
list_plugins("ingestion")
|
|
41
|
+
elif ctx.invoked_subcommand is None:
|
|
42
|
+
click.echo(ctx.get_help())
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@ingest.command("git")
|
|
46
|
+
@click.option("--project", default=None, help="Project name")
|
|
47
|
+
@click.option("--repo-path", default=None, help="Path to git repo (default: cwd)")
|
|
48
|
+
@click.option("--max-count", default=100, help="Max commits to ingest")
|
|
49
|
+
@click.option("--journey-id", default=None, help="Link artifacts to a journey")
|
|
50
|
+
def ingest_git(project: str | None, repo_path: str | None, max_count: int, journey_id: str | None) -> None:
|
|
51
|
+
"""Ingest commits from a git repository."""
|
|
52
|
+
from arcane.services.ingestion import IngestionService
|
|
53
|
+
|
|
54
|
+
with create_container() as container:
|
|
55
|
+
plugin = create_plugin(
|
|
56
|
+
"ingestion", "git", container, {"repo_path": repo_path or os.getcwd(), "max_count": max_count}
|
|
57
|
+
)
|
|
58
|
+
result = _run(IngestionService(container), plugin, project, journey_id, repo_path)
|
|
59
|
+
|
|
60
|
+
click.echo(f"Git ingestion: {result['ingested']} ingested, {result['skipped']} skipped")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@ingest.command("gha")
|
|
64
|
+
@click.option("--owner", required=True, help="GitHub repo owner")
|
|
65
|
+
@click.option("--repo", required=True, help="GitHub repo name")
|
|
66
|
+
@click.option("--project", default=None, help="Project name")
|
|
67
|
+
@click.option("--journey-id", default=None, help="Link artifacts to a journey")
|
|
68
|
+
def ingest_gha(owner: str, repo: str, project: str | None, journey_id: str | None) -> None:
|
|
69
|
+
"""Ingest CI runs from GitHub Actions."""
|
|
70
|
+
from arcane.services.ingestion import IngestionService
|
|
71
|
+
|
|
72
|
+
with create_container() as container:
|
|
73
|
+
plugin = create_plugin("ingestion", "github_actions", container, {"owner": owner, "repo": repo})
|
|
74
|
+
result = _run(IngestionService(container), plugin, project, journey_id)
|
|
75
|
+
|
|
76
|
+
click.echo(f"GHA ingestion: {result['ingested']} ingested, {result['skipped']} skipped")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@ingest.command("linear")
|
|
80
|
+
@click.option("--team", required=True, help="Linear team ID")
|
|
81
|
+
@click.option("--project", default=None, help="Project name")
|
|
82
|
+
@click.option("--journey-id", default=None, help="Link artifacts to a journey")
|
|
83
|
+
def ingest_linear(team: str, project: str | None, journey_id: str | None) -> None:
|
|
84
|
+
"""Ingest tickets from Linear."""
|
|
85
|
+
from arcane.services.ingestion import IngestionService
|
|
86
|
+
|
|
87
|
+
with create_container() as container:
|
|
88
|
+
plugin = create_plugin("ingestion", "linear", container, {"team_id": team})
|
|
89
|
+
result = _run(IngestionService(container), plugin, project, journey_id)
|
|
90
|
+
|
|
91
|
+
click.echo(f"Linear ingestion: {result['ingested']} ingested, {result['skipped']} skipped")
|