Tools as PATH deployments; demote behavior from lifecycle logic

- manifest: RunPath (runner: path) — a CLI on PATH via `uv tool install`, manager
  = path, no unit/route (like remote/static).
- lifecycle/service: a path deployment's start/stop = install/uninstall (routed
  through activate/deactivate, which skip the reinstall when already on PATH).
  `castle service start/stop <tool>` and status now dispatch by manager; status
  shows the manager tag [systemd|caddy|path|none].
- config.tools() now derives from `runner: path` services, not the behavior label.
- castle-api: the "installed" flag derives from manager==path, not behavior==tool.
- create: a python-cli stack emits a `runner: path` service.

`behavior` no longer drives any runtime logic — it survives only as a display
label + `list --behavior` filter. Verified live: html2text uninstall→reinstall
round-trip via `castle service stop/start`.
This commit is contained in:
2026-07-01 06:59:40 -07:00
parent 57861e58c1
commit 7eca3cc217
10 changed files with 82 additions and 35 deletions

View File

@@ -14,6 +14,7 @@ from castle_cli.manifest import (
HttpInternal,
ManageSpec,
ProgramSpec,
RunPath,
RunPython,
RunStatic,
ServiceSpec,
@@ -109,7 +110,12 @@ def run_create(args: argparse.Namespace) -> int:
behavior=behavior,
build=build,
)
if behavior == "frontend":
if behavior == "tool":
# A PATH-managed deployment: installed via `uv tool install`, no unit/route.
config.services[name] = ServiceSpec(
id=name, program=name, run=RunPath(runner="path")
)
elif behavior == "frontend":
# A caddy-managed static service: no systemd unit, served from the build dir.
config.services[name] = ServiceSpec(
id=name,

View File

@@ -133,20 +133,13 @@ def _path_lifecycle(config: CastleConfig, name: str, action: str) -> int:
"""A `path` (tool) deployment's lifecycle is install/uninstall on PATH."""
import asyncio
from castle_core.stacks import run_action
from castle_core.lifecycle import activate, deactivate
program = config.services[name].program or name
comp = config.programs.get(program)
if comp is None:
print(f"Error: path service '{name}' references unknown program '{program}'.")
return 1
verb = {"start": "install", "stop": "uninstall", "restart": "install"}[action]
res = asyncio.run(run_action(verb, program, comp, config.root))
ok = res.status == "ok"
print(f" {name}: {verb + 'ed' if ok else verb + ' FAILED'}")
if not ok and res.output:
print(res.output)
return 0 if ok else 1
# stop → uninstall; start/restart → ensure installed (activate skips if on PATH).
coro = deactivate if action == "stop" else activate
res = asyncio.run(coro(name, config, config.root))
print(f" {res.output}")
return 0 if res.status == "ok" else 1
def _services_restart(config: CastleConfig) -> int:
@@ -218,30 +211,23 @@ def _service_disable(config: CastleConfig, name: str) -> int:
def _service_status(config: CastleConfig) -> int:
"""Show status of all managed services and jobs."""
"""Show status of all services and jobs, dispatched by manager."""
from castle_core.lifecycle import is_active
print("\nCastle Services")
print("=" * 50)
for name, svc in config.services.items():
svc_unit = unit_name(name)
result = subprocess.run(
["systemctl", "--user", "is-active", svc_unit],
capture_output=True,
text=True,
)
status = result.stdout.strip()
if status == "active":
color = "\033[92m"
elif status == "inactive":
color = "\033[90m"
else:
color = "\033[91m"
active = is_active(name, config) # manager-aware (systemd/caddy/path/none)
manager = manager_for(svc.run.runner)
color = "\033[92m" if active else "\033[90m"
reset = "\033[0m"
label = "active" if active else "inactive"
port_str = ""
if svc.expose and svc.expose.http:
port_str = f":{svc.expose.http.internal.port}"
print(f" {color}{status:10s}{reset} {name}{port_str}")
print(f" {color}{label:10s}{reset} {name}{port_str} \033[90m[{manager}]{reset}")
if config.jobs:
print(f"\n{'' * 50}")

View File

@@ -75,6 +75,8 @@ class TestCreateCommand:
assert "my-tool2" in config.programs
comp = config.programs["my-tool2"]
assert comp.behavior == "tool"
# A tool is a PATH deployment: a `runner: path` service.
assert config.services["my-tool2"].run.runner == "path"
def test_create_supabase_app(self, castle_root: Path, tmp_path: Path) -> None:
"""A supabase app scaffolds a Patch-shaped project registered as a static