mirror of
https://github.com/basicmachines-co/basic-memory
synced 2026-06-21 13:47:35 +00:00
fix(ci): improve auto bm note narrative (#893)
Signed-off-by: phernandez <paul@basicmachines.co>
This commit is contained in:
@@ -14,6 +14,7 @@ from rich.console import Console
|
||||
from basic_memory.ci.project_updates import (
|
||||
DEFAULT_CONFIG_PATH,
|
||||
DEFAULT_PROMPT_PATH,
|
||||
DEFAULT_SOUL_PATH,
|
||||
DEFAULT_WORKFLOW_PATH,
|
||||
AgentSynthesis,
|
||||
ProjectUpdateConfig,
|
||||
@@ -25,6 +26,7 @@ from basic_memory.ci.project_updates import (
|
||||
load_project_update_config,
|
||||
render_agent_synthesis_schema,
|
||||
render_capture_prompt,
|
||||
render_soul_template,
|
||||
render_workflow,
|
||||
schema_seed_specs,
|
||||
write_project_update_config,
|
||||
@@ -68,6 +70,14 @@ def setup(
|
||||
yes: bool = typer.Option(False, "--yes", help="Skip confirmation prompts"),
|
||||
local: bool = typer.Option(False, "--local", help="Force local API routing for schema seeding"),
|
||||
cloud: bool = typer.Option(False, "--cloud", help="Force cloud API routing for schema seeding"),
|
||||
refresh_schemas: bool = typer.Option(
|
||||
False,
|
||||
"--refresh-schemas",
|
||||
"--update-schemas",
|
||||
"--refresh",
|
||||
"--update",
|
||||
help="Update existing Auto BM schema notes instead of only seeding missing ones",
|
||||
),
|
||||
) -> None:
|
||||
"""Install the GitHub Actions workflow and seed project update schemas."""
|
||||
try:
|
||||
@@ -89,7 +99,12 @@ def setup(
|
||||
if not confirmed:
|
||||
raise typer.Exit(1)
|
||||
|
||||
_write_generated_files(repo_root, config, force=force)
|
||||
wrote_generated_files = _write_generated_files(
|
||||
repo_root,
|
||||
config,
|
||||
force=force,
|
||||
preserve_existing=refresh_schemas,
|
||||
)
|
||||
|
||||
with force_routing(local=local, cloud=cloud):
|
||||
seeded = run_with_cleanup(
|
||||
@@ -97,14 +112,21 @@ def setup(
|
||||
project=project,
|
||||
project_id=project_id,
|
||||
workspace=workspace,
|
||||
refresh=refresh_schemas,
|
||||
)
|
||||
)
|
||||
|
||||
console.print("[green]Auto BM GitHub workflow installed[/green]")
|
||||
if wrote_generated_files:
|
||||
console.print("[green]Auto BM GitHub workflow installed[/green]")
|
||||
else:
|
||||
console.print(
|
||||
"[yellow]Auto BM GitHub workflow already exists; generated files unchanged[/yellow]"
|
||||
)
|
||||
console.print(f"Repository: {owner}/{repo}")
|
||||
console.print(f"Project: {project}")
|
||||
if seeded:
|
||||
console.print(f"Seeded schemas: {', '.join(seeded)}")
|
||||
verb = "Updated" if refresh_schemas else "Seeded"
|
||||
console.print(f"{verb} schemas: {', '.join(seeded)}")
|
||||
else:
|
||||
console.print("Schema notes already exist; nothing seeded")
|
||||
console.print("\nAdd these GitHub secrets before enabling the workflow:")
|
||||
@@ -227,6 +249,7 @@ async def seed_project_update_schemas(
|
||||
project: str | None,
|
||||
project_id: str | None = None,
|
||||
workspace: str | None = None,
|
||||
refresh: bool = False,
|
||||
) -> list[str]:
|
||||
"""Seed Auto BM schema notes without overwriting customized schemas."""
|
||||
seeded: list[str] = []
|
||||
@@ -240,18 +263,25 @@ async def seed_project_update_schemas(
|
||||
output_format="json",
|
||||
page_size=1,
|
||||
)
|
||||
if _search_results(existing):
|
||||
existing_results = _search_results(existing)
|
||||
if existing_results and not refresh:
|
||||
continue
|
||||
|
||||
title, directory = _note_write_target(
|
||||
existing,
|
||||
default_title=spec.title,
|
||||
default_directory="schemas",
|
||||
)
|
||||
|
||||
await mcp_write_note(
|
||||
title=spec.title,
|
||||
title=title,
|
||||
content=spec.content,
|
||||
directory="schemas",
|
||||
directory=directory,
|
||||
project=routed_project,
|
||||
project_id=project_id,
|
||||
note_type="schema",
|
||||
metadata=spec.metadata,
|
||||
overwrite=False,
|
||||
overwrite=bool(existing_results) and refresh,
|
||||
output_format="json",
|
||||
)
|
||||
seeded.append(spec.entity)
|
||||
@@ -324,16 +354,28 @@ def _note_write_target(
|
||||
return title, default_directory
|
||||
|
||||
|
||||
def _write_generated_files(repo_root: Path, config: ProjectUpdateConfig, *, force: bool) -> None:
|
||||
def _write_generated_files(
|
||||
repo_root: Path,
|
||||
config: ProjectUpdateConfig,
|
||||
*,
|
||||
force: bool,
|
||||
preserve_existing: bool = False,
|
||||
) -> bool:
|
||||
files = {
|
||||
repo_root / DEFAULT_WORKFLOW_PATH: render_workflow(config),
|
||||
repo_root / DEFAULT_PROMPT_PATH: render_capture_prompt(),
|
||||
repo_root / DEFAULT_SOUL_PATH: render_soul_template(),
|
||||
}
|
||||
config_path = repo_root / DEFAULT_CONFIG_PATH
|
||||
_validate_generated_targets([*files, config_path], force=force)
|
||||
targets = [*files, config_path]
|
||||
if preserve_existing and not force and any(path.exists() for path in targets):
|
||||
return False
|
||||
|
||||
_validate_generated_targets(targets, force=force)
|
||||
for path, content in files.items():
|
||||
_write_generated_file(path, content, force=force)
|
||||
write_project_update_config(config_path, config)
|
||||
return True
|
||||
|
||||
|
||||
def _validate_generated_targets(paths: list[Path], *, force: bool) -> None:
|
||||
|
||||
Reference in New Issue
Block a user