|
| 1 | +"""Argument parser for the SourceOS Portable AI Kit command group.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import argparse |
| 6 | + |
| 7 | +from sourceosctl.commands import portable_ai |
| 8 | + |
| 9 | + |
| 10 | +SURFACES = [ |
| 11 | + "turtleterm", |
| 12 | + "agent-term", |
| 13 | + "bearbrowser", |
| 14 | + "local-web", |
| 15 | + "anythingllm-adapter", |
| 16 | +] |
| 17 | + |
| 18 | + |
| 19 | +def build_parser() -> argparse.ArgumentParser: |
| 20 | + parser = argparse.ArgumentParser( |
| 21 | + prog="sourceosctl portable-ai", |
| 22 | + description="SourceOS Portable AI Kit helpers (dry-run / evidence-first surface)", |
| 23 | + ) |
| 24 | + sub = parser.add_subparsers(dest="command", metavar="<command>") |
| 25 | + sub.required = True |
| 26 | + |
| 27 | + profiles_p = sub.add_parser("profiles", help="List built-in portable AI profiles") |
| 28 | + profiles_p.set_defaults(func=portable_ai.profiles) |
| 29 | + |
| 30 | + preflight_p = sub.add_parser( |
| 31 | + "preflight", |
| 32 | + help="Inspect a portable root target without mutating it", |
| 33 | + ) |
| 34 | + preflight_p.add_argument("target_root", help="Target USB/SSD portable root") |
| 35 | + preflight_p.add_argument( |
| 36 | + "--benchmark", |
| 37 | + action="store_true", |
| 38 | + default=False, |
| 39 | + help="Reserve flag for future read/write benchmark", |
| 40 | + ) |
| 41 | + preflight_p.set_defaults(func=portable_ai.preflight) |
| 42 | + |
| 43 | + prepare_p = sub.add_parser( |
| 44 | + "prepare", |
| 45 | + help="Render or execute portable root materialization", |
| 46 | + ) |
| 47 | + prepare_p.add_argument("target_root", help="Target USB/SSD portable root") |
| 48 | + prepare_p.add_argument( |
| 49 | + "--profile", |
| 50 | + default="laptop-safe", |
| 51 | + choices=sorted(portable_ai.PORTABLE_PROFILES), |
| 52 | + help="Portable profile", |
| 53 | + ) |
| 54 | + prepare_p.add_argument( |
| 55 | + "--dry-run", |
| 56 | + action="store_true", |
| 57 | + default=True, |
| 58 | + dest="dry_run", |
| 59 | + help="Render plan without writing files", |
| 60 | + ) |
| 61 | + prepare_p.add_argument( |
| 62 | + "--execute", |
| 63 | + action="store_true", |
| 64 | + default=False, |
| 65 | + help="Create declared portable-root directories and manifest", |
| 66 | + ) |
| 67 | + prepare_p.add_argument( |
| 68 | + "--policy-ok", |
| 69 | + action="store_true", |
| 70 | + default=False, |
| 71 | + help="Confirm policy/operator approval for materialization", |
| 72 | + ) |
| 73 | + prepare_p.add_argument("--evidence-out", default=None, help="Optional evidence JSON path") |
| 74 | + prepare_p.set_defaults(func=portable_ai.prepare) |
| 75 | + |
| 76 | + start_p = sub.add_parser( |
| 77 | + "start-plan", |
| 78 | + help="Render a local runtime/surface launch plan without starting daemons", |
| 79 | + ) |
| 80 | + start_p.add_argument("target_root", help="Target USB/SSD portable root") |
| 81 | + start_p.add_argument( |
| 82 | + "--surface", |
| 83 | + default="turtleterm", |
| 84 | + choices=SURFACES, |
| 85 | + help="Launch surface", |
| 86 | + ) |
| 87 | + start_p.set_defaults(func=portable_ai.start_plan) |
| 88 | + |
| 89 | + inspect_p = sub.add_parser("inspect", help="Inspect portable root layout state") |
| 90 | + inspect_p.add_argument("target_root", help="Target USB/SSD portable root") |
| 91 | + inspect_p.set_defaults(func=portable_ai.inspect) |
| 92 | + |
| 93 | + evidence_p = sub.add_parser("evidence", help="Portable AI evidence helpers") |
| 94 | + evidence_sub = evidence_p.add_subparsers(dest="evidence_command", metavar="<subcommand>") |
| 95 | + evidence_sub.required = True |
| 96 | + evidence_inspect_p = evidence_sub.add_parser("inspect", help="Inspect portable AI evidence JSON") |
| 97 | + evidence_inspect_p.add_argument("path", help="Evidence JSON path") |
| 98 | + evidence_inspect_p.set_defaults(func=portable_ai.evidence_inspect) |
| 99 | + |
| 100 | + return parser |
| 101 | + |
| 102 | + |
| 103 | +def main(argv=None) -> int: |
| 104 | + parser = build_parser() |
| 105 | + args = parser.parse_args(argv) |
| 106 | + return args.func(args) or 0 |
0 commit comments