mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-09 05:19:33 -10:00
Update the Go module path, imports, install scripts, docs, workflows, packaging and action defaults from Gitlawb/zero to Twigpine/zero. The npm scope (already @twigpine/zero on main, with its @gitlawb/zero migration notes), LICENSE, action author, the OpenGateway provider and historical CHANGELOG links are unchanged. The X-AIMLAPI-Integration-Repo header keeps Gitlawb/zero: it is what AIMLAPI sees for attribution, so changing it needs a maintainer's yes. docs/INSTALL.md keeps `go install github.com/Gitlawb/zero/...`, because every tagged release so far declares that module path. The Homebrew formula comment names the Twigpine/homebrew-tap tap. Co-authored-by: Claude Opus 5.5 <[email protected]>
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/Twigpine/zero/internal/agentinit"
|
|
)
|
|
|
|
// runInit implements `zero init`: investigate the repo and generate an
|
|
// AGENTS.md. It builds a bootstrap prompt seeded with repo facts and forwards
|
|
// it to the normal `exec` machinery (provider, tools, sandbox, AGENTS.md write
|
|
// path are all the standard ones). Any flags the user passes (--model, -w,
|
|
// --add-dir, …) are forwarded to exec unchanged; the built prompt is appended
|
|
// as the trailing positional, so a user-supplied prompt is not expected.
|
|
func runInit(args []string, stdout io.Writer, stderr io.Writer, deps appDeps) int {
|
|
if wantsHelp(args) {
|
|
_, _ = io.WriteString(stdout, initHelp)
|
|
return exitSuccess
|
|
}
|
|
|
|
// Resolve the workspace the same way exec will, so the seeded facts describe
|
|
// the right repo. A failure here is non-fatal — BuildPrompt degrades to
|
|
// "investigate yourself".
|
|
cwd := initCwdFromArgs(args)
|
|
workspaceRoot, err := resolveWorkspaceRoot(cwd, deps)
|
|
if err != nil {
|
|
workspaceRoot = cwd
|
|
}
|
|
prompt := agentinit.BuildPrompt(context.Background(), workspaceRoot, time.Now())
|
|
|
|
// Forward the user's flags, then the built prompt as the trailing positional.
|
|
execArgs := append(append([]string{}, args...), prompt)
|
|
return runExec(execArgs, stdout, stderr, deps)
|
|
}
|
|
|
|
// initCwdFromArgs extracts a -C/--cwd value if present, else "" (exec defaults
|
|
// to the process cwd). Kept minimal — exec owns the real flag parsing.
|
|
func initCwdFromArgs(args []string) string {
|
|
for i, a := range args {
|
|
switch {
|
|
case a == "-C" || a == "--cwd":
|
|
if i+1 < len(args) {
|
|
return args[i+1]
|
|
}
|
|
case strings.HasPrefix(a, "--cwd="):
|
|
return strings.TrimPrefix(a, "--cwd=")
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func wantsHelp(args []string) bool {
|
|
for _, a := range args {
|
|
if a == "-h" || a == "--help" || a == "help" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
const initHelp = `zero init — investigate the repository and generate an AGENTS.md.
|
|
|
|
Runs an agent turn seeded with a local repo scan (languages, build/test tools,
|
|
CI, workspace layout), investigates the gaps, and writes a concise AGENTS.md at
|
|
the repo root so future runs start with project context.
|
|
|
|
Usage:
|
|
zero init [exec flags]
|
|
|
|
Accepts the same flags as 'zero exec' (e.g. --model, -w/--worktree, --add-dir).
|
|
`
|