Some checks failed
CI / build-check-test (push) Has been cancelled
Document main/upstream-sync/feature branch strategy, add sync/push scripts, track .pi/agent extensions and webui in git, and disable startup changelog via showChangelogOnStartup. Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
/**
|
||
* sproutclaw / mengya 命令安装扩展
|
||
*
|
||
* 启动后自动在 /usr/local/bin/ 下创建 mengya 和 sproutclaw 命令,
|
||
* 方便快速启动 sproutclaw(cd 到项目目录并执行 ./pi-test.sh)。
|
||
*
|
||
* 命令 /install-commands 可随时手动重装。
|
||
*/
|
||
|
||
import { existsSync, writeFileSync, chmodSync, readFileSync } from "node:fs";
|
||
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
||
|
||
const SPROUTCLAW_DIR = "/shumengya/project/agent/sproutclaw";
|
||
const BIN_DIR = "/usr/local/bin";
|
||
const COMMANDS = ["mengya", "sproutclaw"];
|
||
|
||
/** 创建或修复命令脚本 */
|
||
function installCommand(name: string): boolean {
|
||
const path = `${BIN_DIR}/${name}`;
|
||
|
||
const script = `#!/usr/bin/env bash
|
||
set -euo pipefail
|
||
cd ${SPROUTCLAW_DIR}
|
||
exec ./pi-test.sh "$@"
|
||
`;
|
||
if (existsSync(path)) {
|
||
try {
|
||
const current = readFileSync(path, "utf-8");
|
||
if (current === script) return false;
|
||
} catch {
|
||
// Rewrite unreadable or invalid command files below.
|
||
}
|
||
}
|
||
writeFileSync(path, script, "utf-8");
|
||
chmodSync(path, 0o755);
|
||
return true;
|
||
}
|
||
|
||
export default function (pi: ExtensionAPI) {
|
||
// 启动时自动安装
|
||
for (const name of COMMANDS) {
|
||
const created = installCommand(name);
|
||
if (created) {
|
||
console.log(`[sproutclaw-setup] Created /usr/local/bin/${name}`);
|
||
}
|
||
}
|
||
|
||
// 命令:手动重装
|
||
pi.registerCommand("install-commands", {
|
||
description: "Install mengya and sproutclaw commands to /usr/local/bin",
|
||
handler: async (_args, ctx) => {
|
||
let count = 0;
|
||
for (const name of COMMANDS) {
|
||
if (installCommand(name)) count++;
|
||
}
|
||
if (count > 0) {
|
||
ctx.ui.notify(`Installed ${count} command(s): mengya, sproutclaw`, "success");
|
||
} else {
|
||
ctx.ui.notify("Both commands already exist", "info");
|
||
}
|
||
},
|
||
});
|
||
}
|