feat(lanes): extract skills-install lib, add POST /api/skills/install (F4)

This commit is contained in:
2026-08-06 09:26:43 +07:00
parent 99465d2095
commit e7ef7bcef9
4 changed files with 70 additions and 8 deletions
+8 -8
View File
@@ -1529,16 +1529,16 @@ async function cmdLanesAdd(args) {
* existing global copy with the current one.
*/
function cmdSkillsInstall() {
const src = path.join(REPO_ROOT, ".claude", "skills", "ship-feature-lane");
if (!fs.existsSync(src)) {
console.error(`✖ not found: ${src}`);
const { installShipFeatureLaneSkill } = require(
path.join(REPO_ROOT, "server", "lib", "skills-install.js")
);
try {
const result = installShipFeatureLaneSkill({ repoRoot: REPO_ROOT });
console.log(`${c.green("✔")} installed ship-feature-lane skill -> ${result.path}`);
} catch (err) {
console.error(`${err.message}`);
process.exitCode = 1;
return;
}
const dest = path.join(require("node:os").homedir(), ".claude", "skills", "ship-feature-lane");
fs.mkdirSync(path.dirname(dest), { recursive: true });
fs.cpSync(src, dest, { recursive: true, force: true });
console.log(`${c.green("✔")} installed ship-feature-lane skill -> ${dest}`);
}
/**
+2
View File
@@ -67,6 +67,7 @@ const remoteSourcesRouter = require("./routes/remote-sources");
const metricsRouter = require("./routes/metrics");
const lanesRouter = require("./routes/lanes");
const locksRouter = require("./routes/locks");
const skillsRouter = require("./routes/skills");
const APP_VERSION = (() => {
try {
@@ -107,6 +108,7 @@ function createApp() {
app.use("/api/webhooks", webhooksRouter);
app.use("/api/remote-sources", remoteSourcesRouter);
app.use("/api/metrics", metricsRouter);
app.use("/api/skills", skillsRouter);
app.get("/api/openapi.json", (_req, res) => {
res.json(openApiSpec);
});
+32
View File
@@ -0,0 +1,32 @@
/**
* @file Installs .claude/skills/ship-feature-lane/ into ~/.claude/skills/, so
* /ship-feature-lane is discoverable from a session running inside any
* lane's own working directory not just inside this repo, where it lives
* until installed. Shared by bin/ccam.js's `ccam skills install` CLI and the
* POST /api/skills/install route, so there is exactly one copy of this
* logic. Pure filesystem action.
* @author Nguyễn Ngọc Trí <vinnt@smartgift.vn>
*/
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
/**
* @param {{repoRoot: string}} options - `repoRoot` is this checkout's own
* root (bin/ccam.js already computes this as `REPO_ROOT`; the server
* computes its own equivalent see the route for how).
* @returns {{installed: true, path: string}}
*/
function installShipFeatureLaneSkill({ repoRoot }) {
const src = path.join(repoRoot, ".claude", "skills", "ship-feature-lane");
if (!fs.existsSync(src)) {
throw Object.assign(new Error(`not found: ${src}`), { code: "ENOSKILLSRC" });
}
const dest = path.join(os.homedir(), ".claude", "skills", "ship-feature-lane");
fs.mkdirSync(path.dirname(dest), { recursive: true });
fs.cpSync(src, dest, { recursive: true, force: true });
return { installed: true, path: dest };
}
module.exports = { installShipFeatureLaneSkill };
+28
View File
@@ -0,0 +1,28 @@
/**
* @file Machine-wide (not lane-scoped) skill installation.
* @author Nguyễn Ngọc Trí <vinnt@smartgift.vn>
*/
const { Router } = require("express");
const path = require("node:path");
const { installShipFeatureLaneSkill } = require("../lib/skills-install");
const { sameOriginGuard } = require("./run");
const router = Router();
/** This server's own checkout root server/routes/skills.js is two levels
* under it (server/routes/), same computation bin/ccam.js's REPO_ROOT
* already does from its own location. */
const REPO_ROOT = path.resolve(__dirname, "..", "..");
router.post("/install", sameOriginGuard, (req, res) => {
try {
res.json(installShipFeatureLaneSkill({ repoRoot: REPO_ROOT }));
} catch (err) {
if (err.code === "ENOSKILLSRC") {
return res.status(400).json({ error: { code: err.code, message: err.message } });
}
res.status(500).json({ error: { code: err.code || "ERUNTIME", message: err.message } });
}
});
module.exports = router;