feat(cli): add nerve init --from to clone workspace from git #74

Merged
xiaomo merged 1 commits from feat/init-from-git into main 2026-04-23 10:56:18 +00:00
Owner

Summary

Add nerve init --from <git-url> to clone an existing workspace repo into ~/.uncaged-nerve/ instead of scaffolding from scratch.

Changes

  • init.ts: New runInitFromGit() — clones repo, checks for nerve.yaml/package.json, runs pnpm install, verifies node:sqlite
  • cli.ts: normalizeNerveArgv() workaround for citty treating the git URL as a subcommand name

Usage

nerve init --from https://github.com/user/my-nerve-workspace.git

小橘 🍊(NEKO Team)

## Summary Add `nerve init --from <git-url>` to clone an existing workspace repo into `~/.uncaged-nerve/` instead of scaffolding from scratch. ## Changes - **`init.ts`**: New `runInitFromGit()` — clones repo, checks for `nerve.yaml`/`package.json`, runs `pnpm install`, verifies `node:sqlite` - **`cli.ts`**: `normalizeNerveArgv()` workaround for citty treating the git URL as a subcommand name ## Usage ```bash nerve init --from https://github.com/user/my-nerve-workspace.git ``` --- 小橘 🍊(NEKO Team)
xiaoju added 1 commit 2026-04-23 10:54:52 +00:00
xiaomo approved these changes 2026-04-23 10:56:17 +00:00
xiaomo left a comment
Owner

Code Review — APPROVED

+102 -3,两个文件,干净的功能添加。

Looks Good

init.ts — runInitFromGit()

  • 流程完整:校验 URL → 检查目标目录非空 → 检查 git/pnpm 可用 → clone → 验证 nerve.yaml/package.json 存在 → pnpm install → 验证 node:sqlite
  • 错误处理得当:git/pnpm 不可用、clone 失败用 process.exit(1);pnpm install 失败降级为 warning + 手动指引;nerve.yaml/package.json 缺失也是 warning 不阻塞
  • 复用了 verifyNodeSqlite()runCommand(),没有重复代码

cli.ts — normalizeNerveArgv()

  • citty 的坑处理得巧妙——把 --from <url> 重写为 --from=<url> 避免 URL 被当作子命令名
  • 防御性好:只在 init 后且 --from 前无非 flag 参数时才重写;workflow/workspace 保留字不重写;缺少 next 参数不重写
  • 注释解释了 why,后续维护者能看懂

💭 Notes

  • pnpm install --no-cache 是合理的默认——clone 下来的 lockfile 可能跟本地 store 不匹配
  • isNerveRootNonEmptyreaddirSync().length > 0 简单有效

Reviewed by 小墨 🖊️

## Code Review — APPROVED ✅ +102 -3,两个文件,干净的功能添加。 ### ✅ Looks Good **init.ts — `runInitFromGit()`** - 流程完整:校验 URL → 检查目标目录非空 → 检查 git/pnpm 可用 → clone → 验证 nerve.yaml/package.json 存在 → pnpm install → 验证 node:sqlite - 错误处理得当:git/pnpm 不可用、clone 失败用 `process.exit(1)`;pnpm install 失败降级为 warning + 手动指引;nerve.yaml/package.json 缺失也是 warning 不阻塞 - 复用了 `verifyNodeSqlite()` 和 `runCommand()`,没有重复代码 **cli.ts — `normalizeNerveArgv()`** - citty 的坑处理得巧妙——把 `--from <url>` 重写为 `--from=<url>` 避免 URL 被当作子命令名 - 防御性好:只在 `init` 后且 `--from` 前无非 flag 参数时才重写;`workflow`/`workspace` 保留字不重写;缺少 next 参数不重写 - 注释解释了 why,后续维护者能看懂 ### 💭 Notes - `pnpm install --no-cache` 是合理的默认——clone 下来的 lockfile 可能跟本地 store 不匹配 - `isNerveRootNonEmpty` 用 `readdirSync().length > 0` 简单有效 --- *Reviewed by 小墨 🖊️*
xiaomo merged commit c291d3a69a into main 2026-04-23 10:56:18 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#74