Files
gitea 362acfba58 feat(cli): 分离 hose-aipro 独立命令体系并升级至 v0.9.0
1. 架构对称性与声明式注册表抽取:
   - 新增 src/cli/aipro-registry.ts,声明式定义 AIPRO_COMMAND_REGISTRY 及其别名映射与 mutating 突变检查
   - 重构 src/aipro-cli.ts,移除过程式 switch-case 分发,改为查表式声明分发,与 hose-use 的 CLI_COMMAND_REGISTRY 保持 100% 对称
   - 在 src/cli/registry.ts 统一重导出 aipro-registry,巩固其作为顶层声明注册表的单一事实源地位
   - 增加 aipro-cli 测试用例,强制校验 COMMAND_METADATA["hose-aipro"] 与声明式注册表双向一致性

2. 双 Skill 独立打包与内嵌部署:
   - 注册两个独立技能:skills/hose-use 与 skills/hose-aipro,互相关联引用
   - src/packaging/embedded-skill.ts 增加双 Skill 编译期嵌入与 installSkillFiles 全量同步
   - hose-use / hose-aipro 下的 skill status/dump/install 完全对齐

3. 守护服务交叉治理:
   - src/cli/service.ts 支持 ServiceTargetName ("hose-use" | "hose-aipro"),默认端口 8888 与 8889
   - 支持 hose-use aipro <start|stop|...> 与 hose-aipro hose-use <start|stop|...> 双向服务纳管
   - 误触非本领域业务命令时提供友好互导拦截

4. 审批领域数据层防御加固:
   - 迁移 004:approval_runs 增加 short_id 唯一约束
   - 增加 allocateUniqueShortId 冲突重试,多步写操作纳入事务

5. 版本升级至 v0.9.0:
   - package.json、README.md、specs、.zcode-plugin 及两套 Skill 同步更新至 0.9.0
   - bump-version 脚本适配多 Skill 自动递增
2026-11-03 19:16:12 +08:00

126 lines
6.5 KiB
TypeScript

#!/usr/bin/env bun
import { readFileSync, writeFileSync, existsSync } from "node:fs";
import { join } from "node:path";
import { execFileSync } from "node:child_process";
export function bumpVersion(ROOT: string, input: string, rebuild = () => {
execFileSync(process.execPath, ["run", "openapi:all"], { cwd: ROOT, stdio: "inherit" });
execFileSync(process.execPath, ["run", "build:plugin"], { cwd: ROOT, stdio: "inherit" });
execFileSync(process.execPath, ["run", "check:version"], { cwd: ROOT, stdio: "inherit" });
}): string {
const pkgPath = join(ROOT, "package.json");
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
const currentVersion: string = pkg.version;
if (!input) {
console.error("Usage: bun run bump <version | patch | minor | major>");
console.error(`Current version: ${currentVersion}`);
throw new Error("A release version is required");
}
let nextVersion = input.replace(/^v/, "");
if (input === "patch" || input === "minor" || input === "major") {
const [major, minor, patch] = currentVersion.split("-")[0].split(".").map(Number);
if (input === "patch") nextVersion = `${major}.${minor}.${patch + 1}`;
if (input === "minor") nextVersion = `${major}.${minor + 1}.0`;
if (input === "major") nextVersion = `${major + 1}.0.0`;
}
if (!isReleaseVersion(nextVersion)) throw new Error(`Invalid SemVer format: '${nextVersion}'`);
if (Bun.semver.order(nextVersion, currentVersion) <= 0) throw new Error(`Version must increase: ${currentVersion} -> ${nextVersion}`);
const git = (args: string[]) => execFileSync("git", args, { cwd: ROOT, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
if (git(["status", "--porcelain"])) throw new Error("Release preparation requires a clean working tree");
const branch = git(["branch", "--show-current"]);
if (!["codex/release-v", "release/v"].some(prefix => branch === `${prefix}${nextVersion}`)) {
throw new Error(`Prepare the release on codex/release-v${nextVersion} or release/v${nextVersion}; current branch: ${branch || "detached HEAD"}`);
}
if (git(["tag", "--list", `v${nextVersion}`])) throw new Error(`Tag v${nextVersion} already exists`);
// Read all versioned sources before writing any of them.
for (const file of ["README.md", "skills/hose-use/SKILL.md"]) readFileSync(join(ROOT, file), "utf8");
for (const file of ["specs/hose-open-api/openapi.yaml", ".zcode-plugin/plugin.json"]) {
if (existsSync(join(ROOT, file))) {
const content = readFileSync(join(ROOT, file), "utf8");
if (file.endsWith(".json")) JSON.parse(content);
}
}
console.log(`==> Bumping version: ${currentVersion} -> ${nextVersion}`);
// 1. package.json
pkg.version = nextVersion;
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
console.log("✓ Updated package.json");
// 2. README.md
const readmePath = join(ROOT, "README.md");
let readmeContent = readFileSync(readmePath, "utf-8");
readmeContent = readmeContent.replace(/# hose-use \(v\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?\)/g, `# hose-use (v${nextVersion})`);
writeFileSync(readmePath, readmeContent);
console.log("✓ Updated README.md");
// 3. skills/hose-use/SKILL.md & skills/hose-aipro/SKILL.md
for (const subSkill of ["hose-use", "hose-aipro"]) {
const skillPath = join(ROOT, "skills", subSkill, "SKILL.md");
if (existsSync(skillPath)) {
let skillContent = readFileSync(skillPath, "utf-8");
skillContent = skillContent.replace(new RegExp(`# ${subSkill} \\(v\\d+\\.\\d+\\.\\d+(?:-[A-Za-z0-9.-]+)?\\)`, "g"), `# ${subSkill} (v${nextVersion})`);
skillContent = skillContent.replace(/v\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?:/g, `v${nextVersion}:`);
skillContent = skillContent.replace(/version: \d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?/g, `version: ${nextVersion}`);
skillContent = skillContent.replace(/\(v\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?\)/g, `(v${nextVersion})`);
writeFileSync(skillPath, skillContent);
console.log(`✓ Updated skills/${subSkill}/SKILL.md`);
}
}
// 4. specs/hose-open-api/openapi.yaml
const openapiPath = join(ROOT, "specs", "hose-open-api", "openapi.yaml");
if (existsSync(openapiPath)) {
let openapiContent = readFileSync(openapiPath, "utf-8");
openapiContent = openapiContent.replace(/version: \d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?/g, `version: ${nextVersion}`);
writeFileSync(openapiPath, openapiContent);
console.log("✓ Updated specs/hose-open-api/openapi.yaml");
}
// 4.5 .zcode-plugin/plugin.json
const pluginJsonPath = join(ROOT, ".zcode-plugin", "plugin.json");
if (existsSync(pluginJsonPath)) {
const pluginJson = JSON.parse(readFileSync(pluginJsonPath, "utf-8"));
pluginJson.version = nextVersion;
writeFileSync(pluginJsonPath, JSON.stringify(pluginJson, null, 2) + "\n");
console.log("✓ Updated .zcode-plugin/plugin.json");
}
// 5. Sync to global ~/.agents/skills/hose-use/ is now an explicit dev:override step.
// A version bump must not overwrite personal Skill files in the user's environment.
// 7. Rebuild OpenAPI and plugin bundles so generated artifacts stay in lockstep.
console.log("==> Rebuilding OpenAPI and plugin bundles...");
rebuild();
console.log("\n🎉 Successfully bumped version to " + nextVersion + "!");
console.log("\nNext steps to publish:");
console.log(` 1. Review the diff, then run bun test && bun run check && bun run check:version`);
console.log(` 2. Commit on ${branch}, push that branch and open a PR to main`);
console.log(` 3. Wait for CI and review, then merge the PR`);
console.log(` 4. Switch to main; git pull --ff-only origin main; git push home main`);
console.log(` 5. Create annotated tag v${nextVersion} on the merged release commit`);
console.log(` 6. git push home refs/tags/v${nextVersion} (first), then git push origin refs/tags/v${nextVersion}`);
console.log(` 7. Verify the Release build, binary archives and checksums on both sources`);
console.log(` Optional: bun run dev:override to explicitly sync your global development binary and Skill`);
return nextVersion;
}
export function isReleaseVersion(value: string): boolean {
const match = value.match(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*))?$/);
return !!match && (!match[4] || match[4].split(".").every(part => !/^0\d+$/.test(part)));
}
if (import.meta.main) {
try {
bumpVersion(join(import.meta.dirname, "../.."), process.argv[2]?.trim() || "");
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
}
}