@cavelon/cli 0.2.0 → 0.2.2
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/api-approval-policy.js +43 -0
- package/dist/automation-policy.js +45 -0
- package/dist/command.js +1 -0
- package/dist/commands/api.js +27 -13
- package/dist/commands/index.js +4 -1
- package/dist/commands/init.js +29 -21
- package/dist/commands/inventory.js +2 -3
- package/dist/commands/loops.js +9 -6
- package/dist/commands/solution.js +23 -9
- package/dist/confirm-token.js +8 -5
- package/dist/context.js +28 -1
- package/dist/database-queries.js +2 -3
- package/dist/file-boundary.js +54 -0
- package/dist/local-state.js +29 -14
- package/dist/main.js +1 -0
- package/dist/mcp-directory.js +3 -3
- package/dist/mcp.js +22 -30
- package/dist/native-assets/kilo-server.mjs +5 -0
- package/dist/native-assets/kilo-tui.mjs +5 -0
- package/dist/native-assets/manifest.json +13 -13
- package/dist/native-assets/omp-extension.mjs +5 -0
- package/dist/native-assets/opencode-server.mjs +5 -0
- package/dist/native-assets/opencode-tui.mjs +5 -0
- package/dist/native-assets/pi-extension.mjs +5 -0
- package/dist/package-files.js +5 -9
- package/dist/paths.js +7 -24
- package/dist/project.js +8 -5
- package/dist/session.js +4 -2
- package/dist/skills/cavelon-authoring/SKILL.md +6 -4
- package/dist/skills/cavelon-long-running/SKILL.md +11 -4
- package/dist/skills/cavelon-loop/SKILL.md +54 -29
- package/dist/skills/cavelon-testing/SKILL.md +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { realpath } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { CavelonError, ExitCode } from "./errors.js";
|
|
5
|
+
const nativeRealPath = promisify(realpath.native);
|
|
6
|
+
export async function realPath(file) {
|
|
7
|
+
const rest = [];
|
|
8
|
+
let current = path.resolve(file);
|
|
9
|
+
for (;;) {
|
|
10
|
+
try {
|
|
11
|
+
return path.join(await nativeRealPath(current), ...rest.reverse());
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
const parent = path.dirname(current);
|
|
15
|
+
if (error.code !== "ENOENT" || parent === current)
|
|
16
|
+
throw error;
|
|
17
|
+
rest.push(path.basename(current));
|
|
18
|
+
current = parent;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export function within(dir, file, fold = false) {
|
|
23
|
+
const norm = (p) => (fold && (process.platform === "win32" || process.platform === "darwin") ? p.toLowerCase() : p);
|
|
24
|
+
const rel = path.relative(norm(dir), norm(file));
|
|
25
|
+
return rel === "" || (rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
|
|
26
|
+
}
|
|
27
|
+
export async function solutionPath(root, file) {
|
|
28
|
+
const real = await realPath(file);
|
|
29
|
+
if (!within(await realPath(root), real)) {
|
|
30
|
+
throw new CavelonError(ExitCode.usage, {
|
|
31
|
+
code: "path_outside_solution",
|
|
32
|
+
message: `${path.relative(root, file)} resolves outside the solution folder; nothing was done to that path.`,
|
|
33
|
+
hint: "Move the file or directory into the solution folder, or use a link whose target stays inside it.",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return real;
|
|
37
|
+
}
|
|
38
|
+
export async function solutionPaths(root, files, privateDirs = []) {
|
|
39
|
+
for (const file of files)
|
|
40
|
+
await solutionPath(root, path.resolve(root, file));
|
|
41
|
+
await checkPrivatePaths(root, files, privateDirs);
|
|
42
|
+
}
|
|
43
|
+
export async function checkPrivatePaths(root, files, privateDirs) {
|
|
44
|
+
const privateRoots = await Promise.all(privateDirs.map(dir => realPath(dir)));
|
|
45
|
+
for (const file of files) {
|
|
46
|
+
const real = await realPath(path.resolve(root, file));
|
|
47
|
+
if (privateRoots.some(dir => within(dir, real, true) || within(real, dir, true))) {
|
|
48
|
+
throw new CavelonError(ExitCode.usage, {
|
|
49
|
+
code: "path_in_kit_directory",
|
|
50
|
+
message: `${file} overlaps cavelon's credential or cache directory; nothing was done to that path.`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
package/dist/local-state.js
CHANGED
|
@@ -2,24 +2,39 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { promises as fs } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { readJsonFile, readTextFile, writeFileAtomic } from "./fsutil.js";
|
|
5
|
+
import { solutionPath, solutionPaths } from "./file-boundary.js";
|
|
5
6
|
export const STATE_DIR = ".cavelon";
|
|
6
7
|
export function stateDir(root) {
|
|
7
8
|
return path.join(root, STATE_DIR);
|
|
8
9
|
}
|
|
10
|
+
export async function statePath(root, name) {
|
|
11
|
+
return solutionPath(root, path.join(stateDir(root), name));
|
|
12
|
+
}
|
|
13
|
+
export async function checkStatePaths(root) {
|
|
14
|
+
const names = [".gitignore", "pull.json", "pulled-files.json", "inventory.md", "inventory.json", "database-queries.json", "retired-previews.json", "previews"];
|
|
15
|
+
await solutionPaths(root, names.map(name => path.join(STATE_DIR, name)));
|
|
16
|
+
const dir = await statePath(root, "previews");
|
|
17
|
+
const entries = await fs.readdir(dir).catch((error) => {
|
|
18
|
+
if (error.code === "ENOENT")
|
|
19
|
+
return [];
|
|
20
|
+
throw error;
|
|
21
|
+
});
|
|
22
|
+
await solutionPaths(root, entries.map(name => path.join(STATE_DIR, "previews", name)));
|
|
23
|
+
}
|
|
9
24
|
export async function ensureStateDir(root) {
|
|
10
|
-
const
|
|
11
|
-
const ignore = path.join(dir, ".gitignore");
|
|
25
|
+
const ignore = await statePath(root, ".gitignore");
|
|
12
26
|
if ((await readTextFile(ignore)) !== undefined)
|
|
13
27
|
return false;
|
|
14
28
|
await writeFileAtomic(ignore, "# Local cavelon state; never committed.\n*\n");
|
|
15
29
|
return true;
|
|
16
30
|
}
|
|
17
31
|
export async function writeState(root, name, content) {
|
|
32
|
+
const file = await statePath(root, name);
|
|
18
33
|
await ensureStateDir(root);
|
|
19
|
-
await writeFileAtomic(
|
|
34
|
+
await writeFileAtomic(file, content);
|
|
20
35
|
}
|
|
21
36
|
export async function readPull(root) {
|
|
22
|
-
return readJsonFile(
|
|
37
|
+
return readJsonFile(await statePath(root, "pull.json"));
|
|
23
38
|
}
|
|
24
39
|
const PULLED_FILES = "pulled-files.json";
|
|
25
40
|
export async function fileDigest(file) {
|
|
@@ -29,13 +44,13 @@ export async function fileDigest(file) {
|
|
|
29
44
|
export async function fileDigests(root, files) {
|
|
30
45
|
const digests = {};
|
|
31
46
|
for (const file of files) {
|
|
32
|
-
const value = await fileDigest(path.join(root, file));
|
|
47
|
+
const value = await fileDigest(await solutionPath(root, path.join(root, file)));
|
|
33
48
|
if (value)
|
|
34
49
|
digests[file] = value;
|
|
35
50
|
}
|
|
36
51
|
return digests;
|
|
37
52
|
}
|
|
38
|
-
const readPulled = async (root) => (await readJsonFile(
|
|
53
|
+
const readPulled = async (root) => (await readJsonFile(await statePath(root, PULLED_FILES))) ?? {};
|
|
39
54
|
export async function writePulledFiles(root, files, items) {
|
|
40
55
|
const kept = items ?? (await readPulled(root)).items;
|
|
41
56
|
await writeState(root, PULLED_FILES, JSON.stringify({ digests: await fileDigests(root, files), ...(kept ? { items: kept } : {}) }, null, 2));
|
|
@@ -58,27 +73,27 @@ export async function readPulledFiles(root) {
|
|
|
58
73
|
export function digest(value) {
|
|
59
74
|
return createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
60
75
|
}
|
|
61
|
-
function previewFile(root, previewId) {
|
|
76
|
+
async function previewFile(root, previewId) {
|
|
62
77
|
const safe = /^[A-Za-z0-9._-]{1,100}$/.test(previewId) ? previewId : createHash("sha256").update(previewId).digest("hex").slice(0, 32);
|
|
63
|
-
return path.join(
|
|
78
|
+
return statePath(root, path.join("previews", `${safe}.json`));
|
|
64
79
|
}
|
|
65
80
|
export async function savePreview(root, preview) {
|
|
81
|
+
const file = await previewFile(root, preview.preview_id);
|
|
66
82
|
await ensureStateDir(root);
|
|
67
|
-
const file = previewFile(root, preview.preview_id);
|
|
68
83
|
await writeFileAtomic(file, JSON.stringify(preview, null, 2));
|
|
69
84
|
return file;
|
|
70
85
|
}
|
|
71
86
|
export async function loadPreview(root, previewId) {
|
|
72
|
-
const stored = await readJsonFile(previewFile(root, previewId));
|
|
87
|
+
const stored = await readJsonFile(await previewFile(root, previewId));
|
|
73
88
|
return stored?.preview_id === previewId ? stored : undefined;
|
|
74
89
|
}
|
|
75
90
|
export async function deletePreview(root, previewId) {
|
|
76
|
-
await fs.rm(previewFile(root, previewId), { force: true });
|
|
91
|
+
await fs.rm(await previewFile(root, previewId), { force: true });
|
|
77
92
|
}
|
|
78
93
|
const RETIRED_PREVIEWS = "retired-previews.json";
|
|
79
94
|
const RETIRED_KEPT = 200;
|
|
80
95
|
async function readRetired(root) {
|
|
81
|
-
const stored = await readJsonFile(
|
|
96
|
+
const stored = await readJsonFile(await statePath(root, RETIRED_PREVIEWS));
|
|
82
97
|
return Array.isArray(stored) ? stored.filter((r) => typeof r?.preview_id === "string") : [];
|
|
83
98
|
}
|
|
84
99
|
export async function retirePreviews(root, retired) {
|
|
@@ -102,7 +117,7 @@ export function previewExpiry(createdAt, now) {
|
|
|
102
117
|
return { expires_at: new Date(expires).toISOString(), expired: now.getTime() >= expires };
|
|
103
118
|
}
|
|
104
119
|
export async function listPreviews(root, now) {
|
|
105
|
-
const dir =
|
|
120
|
+
const dir = await statePath(root, "previews");
|
|
106
121
|
let names;
|
|
107
122
|
try {
|
|
108
123
|
names = await fs.readdir(dir);
|
|
@@ -112,7 +127,7 @@ export async function listPreviews(root, now) {
|
|
|
112
127
|
}
|
|
113
128
|
const out = [];
|
|
114
129
|
for (const name of names.filter((n) => n.endsWith(".json"))) {
|
|
115
|
-
const stored = await readJsonFile(path.join(
|
|
130
|
+
const stored = await readJsonFile(await statePath(root, path.join("previews", name)));
|
|
116
131
|
if (stored?.preview_id) {
|
|
117
132
|
out.push({ preview_id: stored.preview_id, created_at: stored.created_at, env: stored.env, harness: stored.harness, ...previewExpiry(stored.created_at, now) });
|
|
118
133
|
}
|
package/dist/main.js
CHANGED
|
@@ -47,6 +47,7 @@ export async function run(argv, io, commands = COMMANDS, updates = {}) {
|
|
|
47
47
|
}
|
|
48
48
|
ctx = createContext(io, {
|
|
49
49
|
json: parsed.options.json === true,
|
|
50
|
+
yolo: parsed.options.yolo === true,
|
|
50
51
|
instance: typeof parsed.options.instance === "string" ? parsed.options.instance : undefined,
|
|
51
52
|
tenant: typeof parsed.options.tenant === "string" ? parsed.options.tenant : undefined,
|
|
52
53
|
solutionEnv: spec.options?.env && typeof parsed.options.env === "string" ? parsed.options.env : undefined,
|
package/dist/mcp-directory.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { CavelonError, ExitCode, usageError } from "./errors.js";
|
|
4
|
-
import {
|
|
4
|
+
import { privateDirs, realPath, within } from "./paths.js";
|
|
5
5
|
export async function solutionDirectory(io, selection) {
|
|
6
6
|
if (selection === undefined)
|
|
7
7
|
return { io };
|
|
@@ -17,8 +17,8 @@ export async function solutionDirectory(io, selection) {
|
|
|
17
17
|
hint: "Select a folder inside the workspace, or start a separate MCP session in that repository.",
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
for (const privateDir of
|
|
21
|
-
if (within(await realPath(
|
|
20
|
+
for (const privateDir of privateDirs(io.env)) {
|
|
21
|
+
if (within(await realPath(privateDir), directory, true)) {
|
|
22
22
|
throw new CavelonError(ExitCode.usage, {
|
|
23
23
|
code: "path_in_kit_directory",
|
|
24
24
|
message: "solution_dir cannot select cavelon's credential or cache directory; nothing was done.",
|
package/dist/mcp.js
CHANGED
|
@@ -15,27 +15,19 @@ const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a pe
|
|
|
15
15
|
"(or CAVELON_TOKEN). You never see or pass the token. Tools that start work (kb_upload, test_run, " +
|
|
16
16
|
"loop_start, sandbox_seed, artifacts_export) return operation ids at once; read them with operation_status, which returns " +
|
|
17
17
|
`the state at once, or waits up to its timeout (at most ${MCP_MAX_WAIT_MS / 1000} s) when given one, and reports waited_ms, ` +
|
|
18
|
-
"and follow a loop with loop_iterations.
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"confirmation bound to the
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"on your own. With needs_person \"terminal\" this client cannot ask " +
|
|
32
|
-
"them: give the person the preview's confirm command, which they run in their own terminal, never in yours. These are " +
|
|
33
|
-
"harness_default and activate (the default route and a solution something reaches: live traffic), deactivate, tenant_create, " +
|
|
34
|
-
"variables_set replacing a value (every solution of the tenant reads it), variables_delete, limits_set, models_set_limit, trigger_identity, " +
|
|
35
|
-
"api for an operation that is not read-only, loop_start unless the trigger's solution is a draft (a run acts as the person " +
|
|
36
|
-
"and spends budget), and apply where its preview says show_to_person (tenant-wide sections, an active solution, deletions, " +
|
|
37
|
-
"env/prod, or database_queries.would_write). A draft's apply with no query writes or other person requirement, a draft's loop_start, loop_cancel, sandbox_seed and kb_upload's replace you confirm with the " +
|
|
38
|
-
"token once the person saw the preview. " +
|
|
18
|
+
"and follow a loop with loop_iterations. Routine work within the user's request needs no additional chat approval. " +
|
|
19
|
+
"In standard mode, review previews and confirm the exact token or apply preview id when no needs_person is present. " +
|
|
20
|
+
"A token binds one change, not a person's answer; confirm: true is refused, and changed input needs a new preview. " +
|
|
21
|
+
"If this server was explicitly launched with --yolo, eligible routine draft imports, selected draft loop starts and known " +
|
|
22
|
+
"routine API operations can execute in one call within the original instance, tenant, credential and solution scope. " +
|
|
23
|
+
"No tool argument or repository setting can enable this mode. A different target falls back to standard confirmation. " +
|
|
24
|
+
"Critical, shared, live and unknown changes retain needs_person in either mode. With needs_person \"client\", " +
|
|
25
|
+
"call again with the preview token: the client asks the person once. Do not ask for a separate chat yes before that dialog. " +
|
|
26
|
+
"Declined or unanswered dialogs change nothing; never supply the person's answer or reuse an earlier yes for another critical change. " +
|
|
27
|
+
"With needs_person \"terminal\", give the person the exact command to run in their own terminal, never the agent's shell. " +
|
|
28
|
+
"Instance confirmation ids remain bound to the exact request and are requested only after person approval; routine automation " +
|
|
29
|
+
"does not manufacture that approval. confirmation_required or confirmation_invalid changed nothing: return to a preview " +
|
|
30
|
+
"and the required person approval. YOLO never overrides person-only access or customer database-write consent. " +
|
|
39
31
|
"chat sends one message to a solution and returns its answer: the way to try one that is not the default route. " +
|
|
40
32
|
"kb_upload names files that match an active document of the knowledge base; with replace it replaces them, and where the " +
|
|
41
33
|
"instance's upload cannot, it returns what it would deactivate and uploads nothing without its confirm_token. " +
|
|
@@ -48,8 +40,7 @@ const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a pe
|
|
|
48
40
|
"A tool whose description starts with \"Not for this credential\" is one the instance says this token or key may not use " +
|
|
49
41
|
"in this tenant (whoami lists its permissions, an API key's scopes and the operations a person runs): do not call it to " +
|
|
50
42
|
"find out; tell the person who does it. api_list marks such operations (may_send false) and leaves them out with usable. " +
|
|
51
|
-
"Run from your shell, cavelon's api command applies the same
|
|
52
|
-
"its preview printed. Tools read and write files only " +
|
|
43
|
+
"Run from your shell, cavelon's api command applies the same policy. Tools read and write files only " +
|
|
53
44
|
"inside the solution folder (the folder of cavelon.yaml, or the one the server started in), never in cavelon's own " +
|
|
54
45
|
"directories. In a repository with several solutions, pass solution_dir to select a folder inside the server's startup workspace. " +
|
|
55
46
|
"Use the same solution_dir for preview, confirmation and follow-up tools; harness selects an instance solution, not its local folder. Never infer a folder from a harness name. " +
|
|
@@ -73,7 +64,7 @@ const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a pe
|
|
|
73
64
|
"that stays with a person. Use docs_search before guessing, " +
|
|
74
65
|
"and api_list/api_describe/api for anything without its own tool. " +
|
|
75
66
|
"use_tenant chooses the tenant for this MCP session only and never changes the tenant stored for the person; every preview " +
|
|
76
|
-
"names the instance,
|
|
67
|
+
"names the instance, tenant and mode it acts on (its target); check these against the requested work. " +
|
|
77
68
|
"The first result of a session may carry a warning that cavelon, the Cavelon plugin or this folder's skills are behind " +
|
|
78
69
|
"the latest release, with the commands that update them: pass it on to the person, who runs them; do not run them yourself.";
|
|
79
70
|
export function mcpInstructions(commands) {
|
|
@@ -246,15 +237,16 @@ async function askThroughClient(server, message, relatedRequestId) {
|
|
|
246
237
|
function mcpIo(io) {
|
|
247
238
|
return { ...io, stdout: { write: () => true, isTTY: false } };
|
|
248
239
|
}
|
|
249
|
-
export function createMcpServer(io, commands, updates = {}) {
|
|
240
|
+
export function createMcpServer(io, commands, updates = {}, startup = {}) {
|
|
250
241
|
const tools = commands.filter((c) => c.mcpTool);
|
|
251
242
|
const byName = new Map(tools.map((c) => [toolName(c), c]));
|
|
252
243
|
const server = new Server({ name: "cavelon", version: KIT_VERSION }, { capabilities: { tools: { listChanged: true } }, instructions: mcpInstructions(commands) });
|
|
253
244
|
const notice = startSessionUpdateCheck(io, updates);
|
|
254
245
|
const sessionTenants = new Map();
|
|
246
|
+
const launch = createContext(mcpIo(io), { ...startup, json: true }, "mcp").globals;
|
|
255
247
|
async function credentialAccess() {
|
|
256
248
|
const read = (async () => {
|
|
257
|
-
const ctx = createContext(mcpIo(io), { json: true, sessionTenants }, "mcp");
|
|
249
|
+
const ctx = createContext(mcpIo(io), { ...launch, json: true, sessionTenants }, "mcp");
|
|
258
250
|
const session = await ctx.session();
|
|
259
251
|
if (!session.url || !session.token)
|
|
260
252
|
return undefined;
|
|
@@ -294,7 +286,7 @@ export function createMcpServer(io, commands, updates = {}) {
|
|
|
294
286
|
return fail(usageError(`Missing ${missing.join(", ")}.`));
|
|
295
287
|
}
|
|
296
288
|
const tenant = !ownsTenant(spec) && typeof args.tenant === "string" ? args.tenant : undefined;
|
|
297
|
-
const solutionEnv = spec.options?.env && typeof args.env === "string" ? args.env :
|
|
289
|
+
const solutionEnv = spec.options?.env && typeof args.env === "string" ? args.env : launch.solutionEnv;
|
|
298
290
|
let folder;
|
|
299
291
|
try {
|
|
300
292
|
folder = await solutionDirectory(io, args.solution_dir);
|
|
@@ -302,14 +294,14 @@ export function createMcpServer(io, commands, updates = {}) {
|
|
|
302
294
|
catch (error) {
|
|
303
295
|
return fail(error);
|
|
304
296
|
}
|
|
305
|
-
const ctx = createContext(mcpIo(folder.io), { json: true, tenant, solutionEnv, sessionTenants }, "mcp");
|
|
297
|
+
const ctx = createContext(mcpIo(folder.io), { ...launch, json: true, tenant: tenant ?? launch.tenant, solutionEnv: solutionEnv ?? launch.solutionEnv, sessionTenants }, "mcp");
|
|
306
298
|
if (clientAsks(server))
|
|
307
299
|
ctx.askPerson = (message) => askThroughClient(server, message, requestId);
|
|
308
300
|
for (const message of renamed)
|
|
309
301
|
ctx.warn(message);
|
|
310
302
|
try {
|
|
311
|
-
const chosen = tenant ?? (await ctx.session().then((s) => (s.tenantSource === "session" ? s.tenant : undefined), () => undefined));
|
|
312
|
-
const { result, warnings } = await printingFor({ mode: "mcp", commands, solutionDir: folder.selected, personCwd: folder.directory, ...(spec.storesTarget ? {} : { tenant: chosen, env: solutionEnv }) }, async () => {
|
|
303
|
+
const chosen = tenant ?? launch.tenant ?? (await ctx.session().then((s) => (s.tenantSource === "session" || s.tenantSource?.startsWith("env/") ? s.tenant : undefined), () => undefined));
|
|
304
|
+
const { result, warnings } = await printingFor({ mode: "mcp", commands, solutionDir: folder.selected, personCwd: folder.directory, ...(spec.storesTarget ? {} : { instance: launch.instance, tenant: chosen, env: solutionEnv }) }, async () => {
|
|
313
305
|
try {
|
|
314
306
|
const done = await spec.run(ctx, inputFrom(spec, args));
|
|
315
307
|
return { result: { ...done, data: spokenHints(done.data) }, warnings: ctx.warnings.map(spoken) };
|
|
@@ -38486,6 +38486,11 @@ async function readTextFile(file2) {
|
|
|
38486
38486
|
// src/package-files.ts
|
|
38487
38487
|
var import_yaml2 = __toESM(require_dist2(), 1);
|
|
38488
38488
|
|
|
38489
|
+
// src/file-boundary.ts
|
|
38490
|
+
import { realpath } from "node:fs";
|
|
38491
|
+
import { promisify } from "node:util";
|
|
38492
|
+
var nativeRealPath = promisify(realpath.native);
|
|
38493
|
+
|
|
38489
38494
|
// src/package-format.ts
|
|
38490
38495
|
var import_yaml = __toESM(require_dist2(), 1);
|
|
38491
38496
|
|
|
@@ -25189,6 +25189,11 @@ async function readTextFile(file) {
|
|
|
25189
25189
|
// src/package-files.ts
|
|
25190
25190
|
var import_yaml2 = __toESM(require_dist2(), 1);
|
|
25191
25191
|
|
|
25192
|
+
// src/file-boundary.ts
|
|
25193
|
+
import { realpath } from "node:fs";
|
|
25194
|
+
import { promisify } from "node:util";
|
|
25195
|
+
var nativeRealPath = promisify(realpath.native);
|
|
25196
|
+
|
|
25192
25197
|
// src/package-format.ts
|
|
25193
25198
|
var import_yaml = __toESM(require_dist2(), 1);
|
|
25194
25199
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"format": 1,
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"entries": {
|
|
5
5
|
"omp": [
|
|
6
6
|
"omp-extension.mjs"
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
"path": "kilo-server.mjs",
|
|
28
|
-
"size":
|
|
29
|
-
"sha256": "
|
|
28
|
+
"size": 1492859,
|
|
29
|
+
"sha256": "dcabd82d25e65f242077c6bae670b70ce2bbc709fffbd82ddde4529f243cc20a"
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
"path": "kilo-tui.mjs",
|
|
33
|
-
"size":
|
|
34
|
-
"sha256": "
|
|
33
|
+
"size": 938997,
|
|
34
|
+
"sha256": "3d20226755137384071edad8c3b5452718d9f034eb900b04c440709e2fed1eae"
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
37
|
"path": "LICENSE",
|
|
@@ -45,23 +45,23 @@
|
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
"path": "omp-extension.mjs",
|
|
48
|
-
"size":
|
|
49
|
-
"sha256": "
|
|
48
|
+
"size": 1147266,
|
|
49
|
+
"sha256": "89dede5ad576accb5fa2d6e9e70a4a2265dd5bff62b71729166a39b508aa3c6d"
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
"path": "opencode-server.mjs",
|
|
53
|
-
"size":
|
|
54
|
-
"sha256": "
|
|
53
|
+
"size": 1491847,
|
|
54
|
+
"sha256": "89dffce88525b168fd1e9c870460c08da6cd4146cce727407f524dc842ac3330"
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
57
|
"path": "opencode-tui.mjs",
|
|
58
|
-
"size":
|
|
59
|
-
"sha256": "
|
|
58
|
+
"size": 938903,
|
|
59
|
+
"sha256": "4e6f6b7ccc3c883c6ec61180ac983fead85d6f4e8543782f9231199b6668c6da"
|
|
60
60
|
},
|
|
61
61
|
{
|
|
62
62
|
"path": "pi-extension.mjs",
|
|
63
|
-
"size":
|
|
64
|
-
"sha256": "
|
|
63
|
+
"size": 1147174,
|
|
64
|
+
"sha256": "2cdfb3a3d57c09a542349ecfa66f81dd25617ae670701a401d9035016efcab91"
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
"path": "THIRD-PARTY-NOTICES",
|
|
@@ -29487,6 +29487,11 @@ async function readTextFile(file) {
|
|
|
29487
29487
|
// src/package-files.ts
|
|
29488
29488
|
var import_yaml2 = __toESM(require_dist2(), 1);
|
|
29489
29489
|
|
|
29490
|
+
// src/file-boundary.ts
|
|
29491
|
+
import { realpath } from "node:fs";
|
|
29492
|
+
import { promisify } from "node:util";
|
|
29493
|
+
var nativeRealPath = promisify(realpath.native);
|
|
29494
|
+
|
|
29490
29495
|
// src/package-format.ts
|
|
29491
29496
|
var import_yaml = __toESM(require_dist2(), 1);
|
|
29492
29497
|
|
|
@@ -38486,6 +38486,11 @@ async function readTextFile(file2) {
|
|
|
38486
38486
|
// src/package-files.ts
|
|
38487
38487
|
var import_yaml2 = __toESM(require_dist2(), 1);
|
|
38488
38488
|
|
|
38489
|
+
// src/file-boundary.ts
|
|
38490
|
+
import { realpath } from "node:fs";
|
|
38491
|
+
import { promisify } from "node:util";
|
|
38492
|
+
var nativeRealPath = promisify(realpath.native);
|
|
38493
|
+
|
|
38489
38494
|
// src/package-format.ts
|
|
38490
38495
|
var import_yaml = __toESM(require_dist2(), 1);
|
|
38491
38496
|
|
|
@@ -25189,6 +25189,11 @@ async function readTextFile(file) {
|
|
|
25189
25189
|
// src/package-files.ts
|
|
25190
25190
|
var import_yaml2 = __toESM(require_dist2(), 1);
|
|
25191
25191
|
|
|
25192
|
+
// src/file-boundary.ts
|
|
25193
|
+
import { realpath } from "node:fs";
|
|
25194
|
+
import { promisify } from "node:util";
|
|
25195
|
+
var nativeRealPath = promisify(realpath.native);
|
|
25196
|
+
|
|
25192
25197
|
// src/package-format.ts
|
|
25193
25198
|
var import_yaml = __toESM(require_dist2(), 1);
|
|
25194
25199
|
|
|
@@ -29487,6 +29487,11 @@ async function readTextFile(file) {
|
|
|
29487
29487
|
// src/package-files.ts
|
|
29488
29488
|
var import_yaml2 = __toESM(require_dist2(), 1);
|
|
29489
29489
|
|
|
29490
|
+
// src/file-boundary.ts
|
|
29491
|
+
import { realpath } from "node:fs";
|
|
29492
|
+
import { promisify } from "node:util";
|
|
29493
|
+
var nativeRealPath = promisify(realpath.native);
|
|
29494
|
+
|
|
29490
29495
|
// src/package-format.ts
|
|
29491
29496
|
var import_yaml = __toESM(require_dist2(), 1);
|
|
29492
29497
|
|
package/dist/package-files.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { CST, LineCounter, Parser, parseDocument } from "yaml";
|
|
4
4
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
5
5
|
import { readTextFile, withoutBom, writeFileAtomic } from "./fsutil.js";
|
|
6
|
+
import { realPath, solutionPaths, within } from "./file-boundary.js";
|
|
6
7
|
import { canonical, MANIFEST_SECTION, PERSONA_SECTION, sameEntry, sameSectionValue, sectionContent, sectionFields, toYaml } from "./package-format.js";
|
|
7
8
|
export { canonical, toYaml };
|
|
8
9
|
export const DEFAULT_LAYOUT = { package: "package", items: {} };
|
|
@@ -69,15 +70,8 @@ async function listFiles(dir) {
|
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
export async function contentPath(root, file) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
real = await fs.realpath(file);
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return file;
|
|
78
|
-
}
|
|
79
|
-
const relative = path.relative(await fs.realpath(root).catch(() => root), real);
|
|
80
|
-
return relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative) ? real : undefined;
|
|
73
|
+
const real = await realPath(file);
|
|
74
|
+
return within(await realPath(root), real) ? real : undefined;
|
|
81
75
|
}
|
|
82
76
|
async function readSource(root, file) {
|
|
83
77
|
const relative = rel(root, file);
|
|
@@ -153,6 +147,7 @@ function parseFile(root, file, text) {
|
|
|
153
147
|
return { value: doc.toJS({ maxAliasCount: 1000 }), source: { file: relative, doc, lines } };
|
|
154
148
|
}
|
|
155
149
|
export async function readPackage(root, layout) {
|
|
150
|
+
await solutionPaths(root, [layout.package, ...Object.values(layout.items)]);
|
|
156
151
|
const pkg = {};
|
|
157
152
|
const sources = {};
|
|
158
153
|
const findings = [];
|
|
@@ -317,6 +312,7 @@ function itemFileName(item, index, taken) {
|
|
|
317
312
|
return name;
|
|
318
313
|
}
|
|
319
314
|
export async function writePackage(root, layout, pkg, schema, options = {}) {
|
|
315
|
+
await solutionPaths(root, [layout.package, ...Object.values(layout.items)]);
|
|
320
316
|
const dryRun = options.dryRun === true;
|
|
321
317
|
const skip = options.skip ?? new Set();
|
|
322
318
|
const report = { written: [], unchanged: [], removed: [], kept: [], refused: [], tenant_wide: [] };
|
package/dist/paths.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { promises as fs } from "node:fs";
|
|
3
2
|
import os from "node:os";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
6
5
|
import { findProject } from "./project.js";
|
|
6
|
+
import { realPath, within } from "./file-boundary.js";
|
|
7
|
+
export { realPath, within } from "./file-boundary.js";
|
|
7
8
|
export function homeDir(env) {
|
|
8
9
|
return env.HOME || env.USERPROFILE || os.homedir();
|
|
9
10
|
}
|
|
@@ -25,6 +26,9 @@ export function cacheDir(env) {
|
|
|
25
26
|
return path.join(env.LOCALAPPDATA, "cavelon", "cache");
|
|
26
27
|
return path.join(homeDir(env), ".cache", "cavelon");
|
|
27
28
|
}
|
|
29
|
+
export function privateDirs(env) {
|
|
30
|
+
return [configDir(env), cacheDir(env)].map(dir => path.resolve(dir));
|
|
31
|
+
}
|
|
28
32
|
export function instanceKey(url) {
|
|
29
33
|
const parsed = new URL(url);
|
|
30
34
|
const parts = [parsed.hostname, parsed.port, parsed.pathname.replace(/^\/+|\/+$/g, "")].filter(Boolean);
|
|
@@ -45,8 +49,8 @@ export async function confinedPath(ctx, raw, what, confine = ctx.mode === "mcp")
|
|
|
45
49
|
hint: "Name a file inside the solution folder, or ask the person to run the command in their terminal.",
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
|
-
for (const dir of
|
|
49
|
-
if (within(await realPath(
|
|
52
|
+
for (const dir of privateDirs(ctx.io.env)) {
|
|
53
|
+
if (within(await realPath(dir), real, true)) {
|
|
50
54
|
throw new CavelonError(ExitCode.usage, {
|
|
51
55
|
code: "path_in_kit_directory",
|
|
52
56
|
message: `${what} ${raw} is in cavelon's own directory ${dir}, which holds its login and cache; no tool reads or writes there.`,
|
|
@@ -55,24 +59,3 @@ export async function confinedPath(ctx, raw, what, confine = ctx.mode === "mcp")
|
|
|
55
59
|
}
|
|
56
60
|
return resolved;
|
|
57
61
|
}
|
|
58
|
-
export async function realPath(file) {
|
|
59
|
-
const rest = [];
|
|
60
|
-
let current = file;
|
|
61
|
-
for (;;) {
|
|
62
|
-
try {
|
|
63
|
-
return path.join(await fs.realpath(current), ...rest.reverse());
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
const parent = path.dirname(current);
|
|
67
|
-
if (error.code !== "ENOENT" || parent === current)
|
|
68
|
-
throw error;
|
|
69
|
-
rest.push(path.basename(current));
|
|
70
|
-
current = parent;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
export function within(dir, file, fold = false) {
|
|
75
|
-
const norm = (p) => (fold && (process.platform === "win32" || process.platform === "darwin") ? p.toLowerCase() : p);
|
|
76
|
-
const rel = path.relative(norm(dir), norm(file));
|
|
77
|
-
return rel === "" || (rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
|
|
78
|
-
}
|
package/dist/project.js
CHANGED
|
@@ -5,6 +5,7 @@ import { readTextFile } from "./fsutil.js";
|
|
|
5
5
|
import { CavelonError, ExitCode, usageError } from "./errors.js";
|
|
6
6
|
import { layoutFrom } from "./package-files.js";
|
|
7
7
|
import { cavelonCommand } from "./printed.js";
|
|
8
|
+
import { solutionPath, solutionPaths } from "./file-boundary.js";
|
|
8
9
|
export const PROJECT_FILE = "cavelon.yaml";
|
|
9
10
|
function stringField(value, ...keys) {
|
|
10
11
|
if (typeof value === "string" && value.trim())
|
|
@@ -18,11 +19,12 @@ function stringField(value, ...keys) {
|
|
|
18
19
|
}
|
|
19
20
|
return undefined;
|
|
20
21
|
}
|
|
21
|
-
export async function findProject(cwd) {
|
|
22
|
+
export async function findProject(cwd, privateDirs = []) {
|
|
22
23
|
let dir = path.resolve(cwd);
|
|
23
24
|
for (;;) {
|
|
24
25
|
const file = path.join(dir, PROJECT_FILE);
|
|
25
|
-
|
|
26
|
+
await solutionPaths(dir, [file], privateDirs);
|
|
27
|
+
const text = await readTextFile(await solutionPath(dir, file));
|
|
26
28
|
if (text !== undefined)
|
|
27
29
|
return parseProject(file, text);
|
|
28
30
|
const parent = path.dirname(dir);
|
|
@@ -83,7 +85,7 @@ export function envFilePath(project, name) {
|
|
|
83
85
|
export async function envNames(project) {
|
|
84
86
|
let entries;
|
|
85
87
|
try {
|
|
86
|
-
entries = await fs.readdir(path.join(project.root, ENV_DIR));
|
|
88
|
+
entries = await fs.readdir(await solutionPath(project.root, path.join(project.root, ENV_DIR)));
|
|
87
89
|
}
|
|
88
90
|
catch {
|
|
89
91
|
return [];
|
|
@@ -94,9 +96,10 @@ export async function envNames(project) {
|
|
|
94
96
|
.filter((name) => ENV_NAME.test(name))
|
|
95
97
|
.sort();
|
|
96
98
|
}
|
|
97
|
-
export async function readEnvFile(project, name) {
|
|
99
|
+
export async function readEnvFile(project, name, privateDirs = []) {
|
|
98
100
|
const file = envFilePath(project, name);
|
|
99
|
-
|
|
101
|
+
await solutionPaths(project.root, [file], privateDirs);
|
|
102
|
+
const text = await readTextFile(await solutionPath(project.root, file));
|
|
100
103
|
if (text === undefined) {
|
|
101
104
|
const known = await envNames(project);
|
|
102
105
|
throw usageError(`No ${ENV_DIR}/${name}.yaml in this solution; nothing was sent.`, known.length
|
package/dist/session.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { privateDirs as kitPrivateDirs } from "./paths.js";
|
|
1
2
|
import { CavelonError, ExitCode, notLoggedIn, usageError } from "./errors.js";
|
|
2
3
|
import { TENANT_ID_HINT } from "./http.js";
|
|
3
4
|
import { readToken } from "./credentials.js";
|
|
@@ -49,14 +50,15 @@ function sameUrl(input, url, env) {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
export async function resolveSession(env, cwd, globals) {
|
|
52
|
-
const
|
|
53
|
+
const privateDirs = kitPrivateDirs(env);
|
|
54
|
+
const project = await findProject(cwd, privateDirs);
|
|
53
55
|
const config = await loadUserConfig(env);
|
|
54
56
|
let envFile;
|
|
55
57
|
if (globals.solutionEnv) {
|
|
56
58
|
if (!project) {
|
|
57
59
|
throw usageError(`--env ${globals.solutionEnv} needs a solution folder.`, `Run it inside a folder with cavelon.yaml, or run \`${cavelonCommand("init")}\` first.`);
|
|
58
60
|
}
|
|
59
|
-
envFile = await readEnvFile(project, globals.solutionEnv);
|
|
61
|
+
envFile = await readEnvFile(project, globals.solutionEnv, privateDirs);
|
|
60
62
|
}
|
|
61
63
|
let url;
|
|
62
64
|
let urlSource;
|
|
@@ -50,7 +50,8 @@ for a public widget), **propose the change; the person decides.**
|
|
|
50
50
|
- Run `cavelon limits set <key> <value>` without `--confirm` (MCP: `limits_set`
|
|
51
51
|
without `confirm`). It changes nothing and shows the old and the new value,
|
|
52
52
|
the operation it would send and the permissions it needs. Show that to the
|
|
53
|
-
person with your reason (what fails or waits now)
|
|
53
|
+
person with your reason (what fails or waits now). Over MCP, use the native
|
|
54
|
+
approval described next without asking for a separate chat yes.
|
|
54
55
|
- The confirm is the person's. Over MCP, call `limits_set` again with the
|
|
55
56
|
same arguments and `confirm` set to the preview's `confirm_token`: the
|
|
56
57
|
client then asks the person, and nothing changes without their yes. From
|
|
@@ -121,9 +122,10 @@ endpoint.
|
|
|
121
122
|
file). For one row's limit, prefer `cavelon models set-limit`.
|
|
122
123
|
|
|
123
124
|
**Propose a limit; the person decides.** Say which value you would set and
|
|
124
|
-
why (what the endpoint serves, which rows share it, what waits or fails now)
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
why (what the endpoint serves, which rows share it, what waits or fails now).
|
|
126
|
+
Over MCP, use one native approval without a preliminary chat yes. From your
|
|
127
|
+
shell, give the person the printed `models set-limit` confirmation command to
|
|
128
|
+
run in their own terminal; never run it on their behalf. A limit
|
|
127
129
|
`cavelon limits` names as the operator's (the run caps, the slot waits, the
|
|
128
130
|
licence) is not yours or the tenant's to change: tell the person who changes
|
|
129
131
|
it and where, as the output says.
|