|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""agentic-stack onboarding wizard — populates .agent/memory/personal/PREFERENCES.md.""" |
| 3 | +import sys, os |
| 4 | +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| 5 | + |
| 6 | +from onboard_ui import print_banner, intro, note, outro, step_done, BAR, R, MUTED, GREEN, PURPLE, WHITE, B |
| 7 | +from onboard_widgets import ask_text, ask_select, ask_confirm |
| 8 | +from onboard_render import render |
| 9 | +from onboard_write import write_prefs, is_customized, REL |
| 10 | + |
| 11 | +_CI_VARS = ("CI", "GITHUB_ACTIONS", "CIRCLECI", "BUILDKITE", "JENKINS_URL", "TRAVIS") |
| 12 | + |
| 13 | + |
| 14 | +def _is_ci(): |
| 15 | + if not sys.stdin.isatty(): return True |
| 16 | + return any(os.environ.get(v) for v in _CI_VARS) |
| 17 | + |
| 18 | + |
| 19 | +def _parse_args(): |
| 20 | + args = sys.argv[1:] |
| 21 | + flags = {a for a in args if a.startswith("-")} |
| 22 | + pos = [a for a in args if not a.startswith("-")] |
| 23 | + return ( |
| 24 | + pos[0] if pos else os.getcwd(), |
| 25 | + "--yes" in flags or "-y" in flags, |
| 26 | + "--force" in flags, |
| 27 | + "--reconfigure" in flags, |
| 28 | + ) |
| 29 | + |
| 30 | + |
| 31 | +def _wizard(target, force): |
| 32 | + """Run the interactive Q&A. Returns answers dict, or None to abort.""" |
| 33 | + if is_customized(target) and not force: |
| 34 | + note("Already configured", |
| 35 | + ["PREFERENCES.md already has custom content.", |
| 36 | + "Pass --reconfigure to update it."]) |
| 37 | + return None |
| 38 | + |
| 39 | + intro("agentic-stack setup") |
| 40 | + note("What this does", [ |
| 41 | + "Fills .agent/memory/personal/PREFERENCES.md —", |
| 42 | + "the FIRST file your AI reads every session.", |
| 43 | + "Takes about 30 seconds.", |
| 44 | + ]) |
| 45 | + |
| 46 | + a = {} |
| 47 | + a["name"] = ask_text("What should I call you?", |
| 48 | + hint="press Enter to skip") |
| 49 | + a["languages"] = ask_text("Primary language(s)?", |
| 50 | + default="unspecified", |
| 51 | + hint="e.g. TypeScript, Python, Rust") |
| 52 | + a["style"] = ask_select("Explanation style?", |
| 53 | + ["concise", "detailed"]) |
| 54 | + a["tests"] = ask_select("Test strategy?", |
| 55 | + ["test-after", "tdd", "minimal"]) |
| 56 | + a["commits"] = ask_select("Commit message style?", |
| 57 | + ["conventional commits", "free-form", "emoji"]) |
| 58 | + a["review"] = ask_select("Code review depth?", |
| 59 | + ["critical issues only", "everything"]) |
| 60 | + return a |
| 61 | + |
| 62 | + |
| 63 | +def main(): |
| 64 | + target, yes, force, reconf = _parse_args() |
| 65 | + |
| 66 | + if _is_ci() and not yes: |
| 67 | + print(f"[onboard] non-interactive — skipping wizard (edit {REL} manually)") |
| 68 | + sys.exit(0) |
| 69 | + |
| 70 | + print_banner() |
| 71 | + |
| 72 | + if yes: |
| 73 | + path = write_prefs(target, render({}), force=True) |
| 74 | + print(f"{GREEN}◆{R} {WHITE}{B}PREFERENCES.md{R} written with defaults") |
| 75 | + print(f"{MUTED} {path}{R}\n") |
| 76 | + sys.exit(0) |
| 77 | + |
| 78 | + try: |
| 79 | + answers = _wizard(target, force=reconf) |
| 80 | + if answers is None: |
| 81 | + sys.exit(0) |
| 82 | + path = write_prefs(target, render(answers), force=reconf) |
| 83 | + outro([ |
| 84 | + f"PREFERENCES.md written", |
| 85 | + f"{path}", |
| 86 | + "Edit it any time — your AI re-reads it every session.", |
| 87 | + "Tip: git add .agent/memory/ to track your brain.", |
| 88 | + ]) |
| 89 | + except KeyboardInterrupt: |
| 90 | + print(f"\n\n{MUTED} Setup cancelled.{R}\n") |
| 91 | + sys.exit(1) |
| 92 | + |
| 93 | + |
| 94 | +if __name__ == "__main__": |
| 95 | + main() |
0 commit comments