Skip to content

feat(cli): install --init and init --yes for a one-shot, non-interactive bootstrap (#1578) - #1595

Open
colbymchenry wants to merge 1 commit into
mainfrom
feat/1578-install-init
Open

feat(cli): install --init and init --yes for a one-shot, non-interactive bootstrap (#1578)#1595
colbymchenry wants to merge 1 commit into
mainfrom
feat/1578-install-init

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

Fixes #1578.

What was wrong

Bootstrapping CodeGraph in a fresh environment — the issue's case is a throwaway container per AI session — took two commands, codegraph install --yes and then codegraph init, and the second one could still stop on a prompt (the gitignored-child-repos offer, the watch-fallback offer on WSL//mnt). There was no way to wire agents and build the project's index in one non-interactive line.

The installer's "never index implicitly" rule is deliberate (a surprise index of $HOME is exactly what init refuses), so the gap is an explicit opt-in, not a change in default behavior.

What this does

  • codegraph install -i, --init — after wiring the agents, runs the init flow in the current directory. It also runs when nothing was wired (--target none, no agents detected), since the installer returns normally in that case. Every init guard applies: a home directory / filesystem root / parent of home is refused with exit code 1 (no implied --force), and an already-initialized project just reports that and exits 0. --print-config and --refresh return before the install, so --init is a no-op with them.
  • codegraph init -y, --yes — non-interactive: the ignored-repos offer prints its one-line includeIgnored opt-in snippet instead of prompting (the existing non-TTY behavior), and the watch-fallback offer takes its yes default. install --init passes --yes through, so codegraph install --yes --init is a fully unattended bootstrap.
  • The init action body becomes runInit(), shared by both commands. The plain init path is behavior-identical (same refusal, already-initialized notice, supervised index, telemetry, offers, outro).
  • The post-install "Next: index a project" note gains one line mentioning --init; README gets the flag row and a --yes --init example.

On the reporter's other observation — install --yes skipping the "install the CLI on your PATH" step: that's by design for scripted use (it assumes the CLI is already present), and the bunx @colbymchenry/codegraph serve --mcp MCP entry they found is the self-contained alternative. Not changed here.

Tests

__tests__/cli-install-init.test.ts — end-to-end against the built binary with stdin closed (a blocking prompt would fail), always --target none so the suite never touches an agent config on the host:

  • install --yes --target none --init → exit 0, installer reports nothing to wire, Initialized in <tmp>, .codegraph/codegraph.db exists;
  • the same on an already-initialized project → Already initialized, exit 0;
  • the same at the filesystem root → exit 1, Refusing to initialize, nothing written;
  • init --yes with stdin closed → exit 0, index built;
  • init --help lists -y, --yes, install --help lists -i, --init.

npx vitest run __tests__/installer-targets.test.ts __tests__/upgrade.test.ts → 283 passed, 3 skipped. Full npm test → see the checks on this PR / below.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LxZj6W6Y1SHXwvpT3uwJpK

…ractive bootstrap (#1578)

A fresh container or CI job had to run two commands — `codegraph install
--yes` and then `codegraph init` — and the second could still stop on a
prompt (the gitignored-child-repos offer, the watch-fallback offer). The
installer deliberately never indexes on its own (a surprise index of
$HOME is exactly what `init` refuses), so the missing piece was an
explicit opt-in, not a behavior change.

- `codegraph install -i/--init` runs the `init` flow in the current
  directory after the agents are wired — also when nothing was wired
  (`--target none`, no agents detected), since the installer returns
  normally there. It shares every guard with `codegraph init`: an
  unsafe root (home directory, filesystem root, a parent of home) is
  refused with exit code 1 and no implied `--force`; an
  already-initialized project just says so and exits 0. Ignored by
  `--print-config` / `--refresh`, which return before the install.
- `codegraph init -y/--yes` makes every post-index offer
  non-interactive: the ignored-repos offer prints its one-line opt-in
  snippet instead of prompting (the non-TTY behavior), and the
  watch-fallback offer takes its `yes` default.
- The `init` action body is now `runInit()`, shared by both commands;
  the plain `init` path is behavior-identical.
- The post-install "Next: index a project" note mentions the flag;
  README gets the flag row + a `--yes --init` example.

Tests (`__tests__/cli-install-init.test.ts`, against the built binary,
stdin closed, `--target none` so no agent config is touched):
`install --yes --target none --init` builds `.codegraph/codegraph.db`;
the same on an already-initialized project reports it and exits 0; at
the filesystem root it refuses with exit 1 and writes nothing; `init
--yes` completes with stdin closed; both flags appear in `--help`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LxZj6W6Y1SHXwvpT3uwJpK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-i / --init flag to install command? Or self-contained MCP server?

1 participant