@cappa/cli 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +70 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +70 -12
- package/dist/index.mjs.map +1 -1
- package/integrations/skills/cappa/SKILL.md +2 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -38,7 +38,7 @@ let _cappa_client = require("@cappa/client");
|
|
|
38
38
|
let _cappa_server = require("@cappa/server");
|
|
39
39
|
let node_crypto = require("node:crypto");
|
|
40
40
|
//#region package.json
|
|
41
|
-
var version = "0.15.
|
|
41
|
+
var version = "0.15.1";
|
|
42
42
|
//#endregion
|
|
43
43
|
//#region src/utils/agentSkills.ts
|
|
44
44
|
/**
|
|
@@ -114,6 +114,43 @@ const detectSkillStacks = (cwd) => {
|
|
|
114
114
|
else if (has(".agents") || has("AGENTS.md")) stacks.push("agents");
|
|
115
115
|
return stacks.length > 0 ? stacks : ["claude"];
|
|
116
116
|
};
|
|
117
|
+
const LOCKFILES = {
|
|
118
|
+
"pnpm-lock.yaml": "pnpm",
|
|
119
|
+
"yarn.lock": "yarn",
|
|
120
|
+
"bun.lock": "bun",
|
|
121
|
+
"bun.lockb": "bun",
|
|
122
|
+
"package-lock.json": "npm"
|
|
123
|
+
};
|
|
124
|
+
const detectPackageManager = (dir) => {
|
|
125
|
+
for (const [lockfile, manager] of Object.entries(LOCKFILES)) if (node_fs.default.existsSync(node_path.default.join(dir, lockfile))) return manager;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* The directory agents work from: the workspace root holding the lockfile.
|
|
129
|
+
*
|
|
130
|
+
* `cappa` is often installed in a single workspace package and run with
|
|
131
|
+
* `pnpm -F <pkg> exec cappa`, which puts `cwd` inside that package — but
|
|
132
|
+
* agents only read `.claude/` and `.agents/` from the root they were started
|
|
133
|
+
* in. Walk up to the nearest lockfile or `pnpm-workspace.yaml`, without
|
|
134
|
+
* leaving the git repository; `cwd` itself when there is neither.
|
|
135
|
+
*/
|
|
136
|
+
const findProjectRoot = (cwd) => {
|
|
137
|
+
let current = node_path.default.resolve(cwd);
|
|
138
|
+
while (true) {
|
|
139
|
+
const has = (entry) => node_fs.default.existsSync(node_path.default.join(current, entry));
|
|
140
|
+
if (detectPackageManager(current) || has("pnpm-workspace.yaml")) return current;
|
|
141
|
+
const parent = node_path.default.dirname(current);
|
|
142
|
+
if (has(".git") || parent === current) return node_path.default.resolve(cwd);
|
|
143
|
+
current = parent;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const readPackageName = (dir) => {
|
|
147
|
+
try {
|
|
148
|
+
const { name } = JSON.parse(node_fs.default.readFileSync(node_path.default.join(dir, "package.json"), "utf8"));
|
|
149
|
+
return typeof name === "string" ? name : void 0;
|
|
150
|
+
} catch {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
117
154
|
/**
|
|
118
155
|
* How the project runs its own `cappa` binary, from its lockfile.
|
|
119
156
|
*
|
|
@@ -121,18 +158,34 @@ const detectSkillStacks = (cwd) => {
|
|
|
121
158
|
* commands *before* the model sees anything, so a bare `cappa` that is not on
|
|
122
159
|
* `PATH` would inject an error instead of the review state; and agent
|
|
123
160
|
* permission rules match the command text literally.
|
|
161
|
+
*
|
|
162
|
+
* When `cwd` is a package below `root`, the command switches into it: that is
|
|
163
|
+
* where `cappa` is installed and where `cappa.config.ts` lives, while agents
|
|
164
|
+
* run commands from the root.
|
|
124
165
|
*/
|
|
125
|
-
const detectCappaRunner = (cwd) => {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
166
|
+
const detectCappaRunner = (root, cwd = root) => {
|
|
167
|
+
const manager = detectPackageManager(root);
|
|
168
|
+
const dir = node_path.default.relative(root, cwd).split(node_path.default.sep).join("/");
|
|
169
|
+
if (!dir) return {
|
|
170
|
+
pnpm: "pnpm exec cappa",
|
|
171
|
+
yarn: "yarn cappa",
|
|
172
|
+
bun: "bunx cappa",
|
|
173
|
+
npm: "npx cappa"
|
|
174
|
+
}[manager ?? "npm"];
|
|
175
|
+
switch (manager) {
|
|
176
|
+
case "pnpm": return `pnpm -C ${dir} exec cappa`;
|
|
177
|
+
case "yarn": {
|
|
178
|
+
const name = readPackageName(cwd);
|
|
179
|
+
return name ? `yarn workspace ${name} cappa` : `yarn --cwd ${dir} cappa`;
|
|
180
|
+
}
|
|
181
|
+
case "bun": return `bun --cwd ${dir} x cappa`;
|
|
182
|
+
default: return `npm exec -w ${dir} -- cappa`;
|
|
183
|
+
}
|
|
131
184
|
};
|
|
132
185
|
/** Fill the `{{cappa}}` placeholder in a source file. */
|
|
133
186
|
const renderIntegrationFile = (source, runner) => source.replaceAll("{{cappa}}", runner);
|
|
134
187
|
/**
|
|
135
|
-
* Copy each stack's files into the project.
|
|
188
|
+
* Copy each stack's files into the project root (see `findProjectRoot`).
|
|
136
189
|
*
|
|
137
190
|
* A file that exists with different content is left alone unless `force` is
|
|
138
191
|
* set: users are expected to tailor these to their project, and an upgrade
|
|
@@ -141,11 +194,12 @@ const renderIntegrationFile = (source, runner) => source.replaceAll("{{cappa}}",
|
|
|
141
194
|
*/
|
|
142
195
|
const installAgentSkills = async (options) => {
|
|
143
196
|
const sourceDir = options.sourceDir ?? findIntegrationsDir();
|
|
144
|
-
const
|
|
197
|
+
const root = options.root ?? findProjectRoot(options.cwd);
|
|
198
|
+
const runner = options.runner ?? detectCappaRunner(root, options.cwd);
|
|
145
199
|
const files = [];
|
|
146
200
|
const seen = /* @__PURE__ */ new Set();
|
|
147
201
|
for (const stack of options.stacks) for (const mapping of STACK_FILES[stack]) {
|
|
148
|
-
const target = node_path.default.resolve(
|
|
202
|
+
const target = node_path.default.resolve(root, mapping.target);
|
|
149
203
|
if (seen.has(target)) continue;
|
|
150
204
|
seen.add(target);
|
|
151
205
|
const source = renderIntegrationFile(await node_fs_promises.default.readFile(node_path.default.join(sourceDir, mapping.source), "utf8"), runner);
|
|
@@ -175,9 +229,10 @@ const installAgentSkills = async (options) => {
|
|
|
175
229
|
});
|
|
176
230
|
}
|
|
177
231
|
const warnings = [];
|
|
178
|
-
const claudeSkill = node_fs.default.existsSync(node_path.default.resolve(
|
|
232
|
+
const claudeSkill = node_fs.default.existsSync(node_path.default.resolve(root, ".claude/skills/cappa/SKILL.md"));
|
|
179
233
|
if (options.stacks.includes("opencode") && claudeSkill) warnings.push("OpenCode reads .claude/skills too, and uses that copy of the cappa skill over the one in .agents/skills — keep the two in sync if you tailor them.");
|
|
180
234
|
return {
|
|
235
|
+
root,
|
|
181
236
|
runner,
|
|
182
237
|
files,
|
|
183
238
|
warnings
|
|
@@ -305,15 +360,18 @@ const agentApprove = (names, options) => run$1(options, async () => {
|
|
|
305
360
|
});
|
|
306
361
|
const agentInit = (options) => run$1(options, async () => {
|
|
307
362
|
const cwd = process.cwd();
|
|
308
|
-
const
|
|
363
|
+
const root = findProjectRoot(cwd);
|
|
364
|
+
const stacks = options.stack === "all" ? SKILL_STACK_NAMES : options.stack ? [options.stack] : detectSkillStacks(root);
|
|
309
365
|
const { runner, files, warnings } = await installAgentSkills({
|
|
310
366
|
cwd,
|
|
367
|
+
root,
|
|
311
368
|
stacks,
|
|
312
369
|
force: options.force,
|
|
313
370
|
runner: options.runner
|
|
314
371
|
});
|
|
315
372
|
if (options.json) {
|
|
316
373
|
printJson({
|
|
374
|
+
root,
|
|
317
375
|
stacks,
|
|
318
376
|
runner,
|
|
319
377
|
files,
|