@cavelon/cli 0.1.18 → 0.2.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/README.md +1 -1
- package/dist/commands/db-connections.js +13 -3
- package/dist/commands/init.js +31 -23
- package/dist/commands/inventory.js +2 -3
- package/dist/commands/setup.js +1 -1
- package/dist/context.js +25 -1
- package/dist/database-queries.js +79 -3
- package/dist/file-boundary.js +54 -0
- package/dist/local-state.js +29 -14
- package/dist/mcp-command.js +13 -3
- package/dist/mcp-directory.js +3 -3
- package/dist/mcp-entry.js +8 -2
- 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/setup-agents.js +2 -4
- package/dist/skills/cavelon-authoring/SKILL.md +13 -2
- package/dist/skills/cavelon-loop/SKILL.md +3 -2
- package/dist/skills/cavelon-testing/SKILL.md +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -213,10 +213,12 @@ export const dbLoginScript = {
|
|
|
213
213
|
name: "db login-script", summary: "Print the instance's published read-only login SQL for a dialect or saved connection; no database is contacted.",
|
|
214
214
|
description: "Needs database_connectors.view. The DBA replaces the script's password placeholder locally, outside the kit.\n" +
|
|
215
215
|
"Only variants this instance publishes are offered; this build publishes read_only. Omitted inputs use its defaults.\n" +
|
|
216
|
-
"For SQL Server, connection_limit_enforced is false; --schema scopes SELECT instead of granting db_datareader
|
|
216
|
+
"For SQL Server, connection_limit_enforced is false; --schema scopes SELECT instead of granting db_datareader.\n" +
|
|
217
|
+
"For Oracle, --schema names the one schema READ covers (omitted: the placeholder YOUR_SCHEMA); a profile sets the limit.",
|
|
217
218
|
readOnly: true, idempotent: true, mcpTool: "db_login_script", operations: ["GET /api/v1/database-connectors/login-script", `GET ${CONNECTION}/login-script`],
|
|
218
219
|
positionals: [{ name: "dialect", description: "Database dialect; omit only with --connection." }],
|
|
219
220
|
options: {
|
|
221
|
+
dialect: { ...textOption("Database dialect, as the dialect argument; give one of the two.", "<dialect>"), cliOnly: true },
|
|
220
222
|
connection: textOption("Use dialect, database, user and TLS from this saved connection (name or id).", "<connection>"),
|
|
221
223
|
"database-name": textOption("Database the login may read (without --connection).", "<name>"),
|
|
222
224
|
username: textOption("Database login name (without --connection).", "<name>"),
|
|
@@ -225,9 +227,17 @@ export const dbLoginScript = {
|
|
|
225
227
|
"connection-limit": textOption("Connections to allow; omitted uses the instance's pool size times four.", "<n>"),
|
|
226
228
|
"require-tls": textOption("MySQL REQUIRE SSL (true or false, without --connection).", "<true|false>"),
|
|
227
229
|
},
|
|
228
|
-
examples: [
|
|
230
|
+
examples: [
|
|
231
|
+
"cavelon db login-script postgresql --database-name shop --username cavelon_reader",
|
|
232
|
+
"cavelon db login-script --dialect oracle --database-name SHOPPDB --username cavelon_ro --schema SHOP",
|
|
233
|
+
"cavelon db login-script --connection shop-db --schema public",
|
|
234
|
+
],
|
|
229
235
|
async run(ctx, input) {
|
|
230
|
-
const
|
|
236
|
+
const argument = positional(input, "dialect");
|
|
237
|
+
const option = stringOption(input, "dialect");
|
|
238
|
+
if (argument !== undefined && option !== undefined)
|
|
239
|
+
throw usageError("Give the dialect once: as the argument or with --dialect, not both.");
|
|
240
|
+
const dialect = argument ?? option;
|
|
231
241
|
const connectionRef = stringOption(input, "connection");
|
|
232
242
|
if (Boolean(dialect) === Boolean(connectionRef))
|
|
233
243
|
throw usageError("Give a dialect or --connection, exactly one.");
|
package/dist/commands/init.js
CHANGED
|
@@ -6,13 +6,14 @@ import { AGENTS, bundledSkills, generatedCopy, parseAgents, KNOWN_SKILL_ROOTS, s
|
|
|
6
6
|
import { nativeClient, resolveNativeMcp, hasNativeApprovalAdapter } from "../native-clients.js";
|
|
7
7
|
import { applyNativeInstallation, planNativeInstallation } from "../native-install.js";
|
|
8
8
|
import { serverCommand } from "../setup-agents.js";
|
|
9
|
-
import { encodeMcpEntry, isKitMcpEntry } from "../mcp-entry.js";
|
|
9
|
+
import { encodeMcpEntry, isCurrentMcpEntry, isKitMcpEntry } from "../mcp-entry.js";
|
|
10
10
|
import { upsertJsoncEntry } from "../jsonc-config.js";
|
|
11
11
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
12
|
-
import { confinedPath, realPath, within } from "../paths.js";
|
|
12
|
+
import { privateDirs, confinedPath, realPath, within } from "../paths.js";
|
|
13
|
+
import { solutionPath, solutionPaths } from "../file-boundary.js";
|
|
13
14
|
import { readTextFile, withoutBom, writeFileAtomic } from "../fsutil.js";
|
|
14
15
|
import { git } from "../git.js";
|
|
15
|
-
import { ensureStateDir, fileDigests, rememberAppliedFiles, STATE_DIR } from "../local-state.js";
|
|
16
|
+
import { checkStatePaths, ensureStateDir, fileDigests, rememberAppliedFiles, STATE_DIR } from "../local-state.js";
|
|
16
17
|
import { isGenerated, upsertBlock, upsertJsonEntry } from "../markers.js";
|
|
17
18
|
import { packageVersionOf } from "../package-check.js";
|
|
18
19
|
import { MANIFEST_SECTION, PERSONA_SECTION, personaYaml, requiredFields, sectionFields } from "../package-format.js";
|
|
@@ -46,17 +47,9 @@ const GITIGNORE_BLOCK = ["# Local cavelon state (inventory, previews); never com
|
|
|
46
47
|
function rel(root, file) {
|
|
47
48
|
return path.relative(root, file).split(path.sep).join("/");
|
|
48
49
|
}
|
|
49
|
-
async function
|
|
50
|
-
try {
|
|
51
|
-
return await fs.realpath(file);
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
return file;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async function applyBlock(root, file, result, mode) {
|
|
50
|
+
async function applyBlock(root, file, result, mode, boundary = root) {
|
|
58
51
|
if (result.content !== undefined && result.outcome !== "unchanged" && result.outcome !== "skipped") {
|
|
59
|
-
const target = await
|
|
52
|
+
const target = await solutionPath(boundary, file);
|
|
60
53
|
const current = await fs.stat(target).then((st) => st.mode & 0o777, () => undefined);
|
|
61
54
|
await writeFileAtomic(target, result.content, current ?? mode);
|
|
62
55
|
}
|
|
@@ -64,19 +57,20 @@ async function applyBlock(root, file, result, mode) {
|
|
|
64
57
|
}
|
|
65
58
|
async function block(root, relative, body, style, options = {}) {
|
|
66
59
|
const file = path.join(root, relative);
|
|
67
|
-
|
|
60
|
+
const target = await solutionPath(root, file);
|
|
61
|
+
return applyBlock(root, file, upsertBlock(await readTextFile(target), body, style, options));
|
|
68
62
|
}
|
|
69
63
|
async function claudeImport(root, onlyExisting) {
|
|
70
|
-
const claude = path.join(root, "CLAUDE.md");
|
|
64
|
+
const claude = await solutionPath(root, path.join(root, "CLAUDE.md"));
|
|
71
65
|
if ((await readTextFile(claude)) === undefined)
|
|
72
66
|
return undefined;
|
|
73
|
-
if ((await
|
|
67
|
+
if ((await realPath(claude)) === (await realPath(path.join(root, "AGENTS.md")))) {
|
|
74
68
|
return { file: "CLAUDE.md", action: "unchanged", reason: "it is AGENTS.md" };
|
|
75
69
|
}
|
|
76
70
|
return block(root, "CLAUDE.md", "@AGENTS.md", "html", { onlyExisting });
|
|
77
71
|
}
|
|
78
72
|
async function ownFile(root, relative, content) {
|
|
79
|
-
const file = path.join(root, relative);
|
|
73
|
+
const file = await solutionPath(root, path.join(root, relative));
|
|
80
74
|
if ((await readTextFile(file)) !== undefined)
|
|
81
75
|
return { file: relative, action: "unchanged" };
|
|
82
76
|
await writeFileAtomic(file, content);
|
|
@@ -153,7 +147,7 @@ async function manifestFile(ctx, session, project, chosen) {
|
|
|
153
147
|
return action;
|
|
154
148
|
}
|
|
155
149
|
async function generatedFile(root, relative, content) {
|
|
156
|
-
const file = path.join(root, relative);
|
|
150
|
+
const file = await solutionPath(root, path.join(root, relative));
|
|
157
151
|
const existing = await readTextFile(file);
|
|
158
152
|
if (existing === undefined) {
|
|
159
153
|
await writeFileAtomic(file, content);
|
|
@@ -167,7 +161,7 @@ async function generatedFile(root, relative, content) {
|
|
|
167
161
|
return { file: relative, action: "updated" };
|
|
168
162
|
}
|
|
169
163
|
async function folder(root, relative) {
|
|
170
|
-
const dir = path.join(root, relative);
|
|
164
|
+
const dir = await solutionPath(root, path.join(root, relative));
|
|
171
165
|
try {
|
|
172
166
|
await fs.stat(dir);
|
|
173
167
|
return [];
|
|
@@ -204,7 +198,7 @@ async function writeMcp(root, target, onlyExisting, env) {
|
|
|
204
198
|
const selected = await resolveNativeMcp(config, root);
|
|
205
199
|
if ("error" in selected)
|
|
206
200
|
return { file: rel(root, selected.file), action: "skipped", reason: selected.error };
|
|
207
|
-
if (selected.current !== undefined &&
|
|
201
|
+
if (selected.current !== undefined && isCurrentMcpEntry(selected.current, config.entryFormat, config.extra))
|
|
208
202
|
return { file: rel(root, selected.file), action: "unchanged" };
|
|
209
203
|
const value = encodeMcpEntry(await serverCommand(env), config.entryFormat, config.extra);
|
|
210
204
|
return applyBlock(root, selected.file, upsertJsoncEntry(selected.text, config.keys, value, { onlyExisting, matches: current => isKitMcpEntry(current, config.entryFormat, config.extra) }));
|
|
@@ -222,7 +216,7 @@ async function writeMcp(root, target, onlyExisting, env) {
|
|
|
222
216
|
return { file: rel(root, plan.directory), action: exists ? "updated" : "created" };
|
|
223
217
|
}
|
|
224
218
|
const file = path.join(root, target.file);
|
|
225
|
-
const existing = await readTextFile(file);
|
|
219
|
+
const existing = await readTextFile(await solutionPath(root, file));
|
|
226
220
|
if (existing !== undefined && holdsOtherForm(existing, target))
|
|
227
221
|
return { file: target.file, action: "unchanged" };
|
|
228
222
|
if (target.format === "toml")
|
|
@@ -308,12 +302,14 @@ async function installHook(root, onlyExisting) {
|
|
|
308
302
|
reason: `core.hooksPath points to ${path.dirname(file)}, outside this repository, where other repositories' hooks may be; add the block yourself if you want it there`,
|
|
309
303
|
};
|
|
310
304
|
}
|
|
305
|
+
const boundary = own[inside.indexOf(true)];
|
|
306
|
+
await solutionPath(boundary, file);
|
|
311
307
|
const body = HOOK_LINES(prefix).join("\n");
|
|
312
308
|
const existing = await readTextFile(file);
|
|
313
309
|
let result = upsertBlock(existing, body, "hash", { onlyExisting, afterShebang: true });
|
|
314
310
|
if (result.outcome === "created")
|
|
315
311
|
result = { ...result, content: `#!/bin/sh\n${result.content}` };
|
|
316
|
-
const action = await applyBlock(root, file, result, 0o700);
|
|
312
|
+
const action = await applyBlock(root, file, result, 0o700, boundary);
|
|
317
313
|
if (action.action !== "skipped" && action.action !== "unchanged") {
|
|
318
314
|
const mode = (await fs.stat(file)).mode & 0o777;
|
|
319
315
|
if (!(mode & 0o100))
|
|
@@ -566,6 +562,17 @@ async function importPackage(ctx, project, from, pkg, force) {
|
|
|
566
562
|
ctx.warn(`Did not write section ${JSON.stringify(section)}: its name is not a plain file name.`);
|
|
567
563
|
return { from, files, ignored, package_version: version ?? null };
|
|
568
564
|
}
|
|
565
|
+
async function checkInitPaths(ctx, root, agents, update) {
|
|
566
|
+
const project = (await ctx.session()).project;
|
|
567
|
+
const layouts = project?.root === root ? [project.layout.package, ...Object.values(project.layout.items)] : ["package", "tests"];
|
|
568
|
+
const roots = update ? KNOWN_SKILL_ROOTS : agents.length ? skillRootsFor(agents) : [];
|
|
569
|
+
const skills = roots.length ? await bundledSkills() : [];
|
|
570
|
+
const files = [PROJECT_FILE, ...layouts, "tests", "seeds", "env/test.yaml", "env/prod.yaml", STATE_DIR, "AGENTS.md", "CLAUDE.md", ".gitignore",
|
|
571
|
+
...roots, ...roots.flatMap(dir => skills.flatMap(skill => skill.files.map(file => `${dir}/${skill.name}/${file.path}`))),
|
|
572
|
+
...(update ? AGENTS : agents).flatMap(agent => agent.mcp && agent.mcp.format !== "native" ? [agent.mcp.file] : [])];
|
|
573
|
+
await solutionPaths(root, files, privateDirs(ctx.io.env));
|
|
574
|
+
await checkStatePaths(root);
|
|
575
|
+
}
|
|
569
576
|
async function runInit(ctx, input) {
|
|
570
577
|
const update = boolOption(input, "update");
|
|
571
578
|
const from = stringOption(input, "from");
|
|
@@ -583,6 +590,7 @@ async function runInit(ctx, input) {
|
|
|
583
590
|
if (boolOption(input, "new") && (update || (!stringOption(input, "harness") && !from))) {
|
|
584
591
|
throw usageError("--new needs the new solution's name: --harness <name>.", `\`${cavelonCommand("init", "--harness", fill("name"), "--new")}\` creates it as a draft, even when an existing solution has a similar name.`);
|
|
585
592
|
}
|
|
593
|
+
await checkInitPaths(ctx, update ? session.project?.root ?? ctx.io.cwd : ctx.io.cwd, agents, update);
|
|
586
594
|
const imported = from ? await readImportFile(ctx, from) : undefined;
|
|
587
595
|
if (update) {
|
|
588
596
|
if (!session.project)
|
|
@@ -656,7 +664,7 @@ async function runInit(ctx, input) {
|
|
|
656
664
|
values.package_version = version;
|
|
657
665
|
values.layout = defaultLayoutFor(schema);
|
|
658
666
|
const note = tenant && (tenant.name || tenant.id !== tenant.ref) ? commentText([tenant.name, tenant.id !== tenant.ref ? tenant.id : undefined].filter(Boolean).join(", ")) : undefined;
|
|
659
|
-
await writeFileAtomic(path.join(root, PROJECT_FILE), solutionYaml(values, note));
|
|
667
|
+
await writeFileAtomic(await solutionPath(root, path.join(root, PROJECT_FILE)), solutionYaml(values, note));
|
|
660
668
|
actions.push({ file: PROJECT_FILE, action: "created" });
|
|
661
669
|
}
|
|
662
670
|
const project = parseProject(path.join(root, PROJECT_FILE), (await readTextFile(path.join(root, PROJECT_FILE))));
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
1
|
import { CavelonError } from "../errors.js";
|
|
3
2
|
import { table } from "../format.js";
|
|
4
3
|
import { readJsonFile } from "../fsutil.js";
|
|
5
4
|
import { callStable } from "../invoke.js";
|
|
6
|
-
import { STATE_DIR,
|
|
5
|
+
import { STATE_DIR, statePath, writeState } from "../local-state.js";
|
|
7
6
|
const LISTINGS = [
|
|
8
7
|
{ label: "solutions", path: "/api/v1/harnesses", kind: "solutions", field: "slug" },
|
|
9
8
|
{ label: "knowledge bases", path: "/api/v1/knowledge-bases", query: { page_size: 100 }, kind: "knowledge_bases", field: "name" },
|
|
@@ -15,7 +14,7 @@ const LISTINGS = [
|
|
|
15
14
|
];
|
|
16
15
|
const INVENTORY_JSON = "inventory.json";
|
|
17
16
|
export async function readInventory(root) {
|
|
18
|
-
const inventory = await readJsonFile(
|
|
17
|
+
const inventory = await readJsonFile(await statePath(root, INVENTORY_JSON));
|
|
19
18
|
return inventory && typeof inventory === "object" && inventory.names && typeof inventory.names === "object" ? inventory : undefined;
|
|
20
19
|
}
|
|
21
20
|
export async function refreshInventory(root, kind, names, now) {
|
package/dist/commands/setup.js
CHANGED
|
@@ -431,7 +431,7 @@ export const setup = {
|
|
|
431
431
|
type: "string",
|
|
432
432
|
value: "<list>",
|
|
433
433
|
multiple: true,
|
|
434
|
-
description: "Only these agents: claude, codex, cursor, copilot, gemini, kiro, opencode, pi, qwen, cline, kilo, or all (comma-separated). Default: every agent found.",
|
|
434
|
+
description: "Only these agents: claude, codex, cursor, copilot, gemini, kiro, opencode, pi, qwen, cline, kilo, goose, omp, or all (comma-separated). Default: every agent found.",
|
|
435
435
|
},
|
|
436
436
|
yes: { type: "boolean", short: "y", description: "Make the changes without asking." },
|
|
437
437
|
check: { type: "boolean", description: "Report what is set up and working; change nothing." },
|
package/dist/context.js
CHANGED
|
@@ -5,6 +5,11 @@ import { ApiClient } from "./http.js";
|
|
|
5
5
|
import { colorEnabled, styleFor } from "./io.js";
|
|
6
6
|
import { requireInstance, requireToken, resolveSession, resolveTenantId } from "./session.js";
|
|
7
7
|
import { detectShell, useShell } from "./shell.js";
|
|
8
|
+
import { checkStatePaths } from "./local-state.js";
|
|
9
|
+
import { promises as fs } from "node:fs";
|
|
10
|
+
import { checkPrivatePaths, solutionPaths } from "./file-boundary.js";
|
|
11
|
+
import { privateDirs as kitPrivateDirs } from "./paths.js";
|
|
12
|
+
import path from "node:path";
|
|
8
13
|
export function createContext(io, globals, mode = "cli") {
|
|
9
14
|
const warnings = [];
|
|
10
15
|
useShell(detectShell(io.env));
|
|
@@ -23,7 +28,26 @@ export function createContext(io, globals, mode = "cli") {
|
|
|
23
28
|
warnings.push(message);
|
|
24
29
|
},
|
|
25
30
|
session() {
|
|
26
|
-
sessionPromise ??=
|
|
31
|
+
sessionPromise ??= (async () => {
|
|
32
|
+
const session = await resolveSession(io.env, io.cwd, globals);
|
|
33
|
+
const project = session.project;
|
|
34
|
+
if (project) {
|
|
35
|
+
const privateDirs = kitPrivateDirs(io.env);
|
|
36
|
+
const dirs = [project.layout.package, ...Object.values(project.layout.items), ".cavelon", "env"];
|
|
37
|
+
await solutionPaths(project.root, dirs, privateDirs);
|
|
38
|
+
await checkStatePaths(project.root);
|
|
39
|
+
for (const dir of [...dirs, ".cavelon/previews"]) {
|
|
40
|
+
const files = await fs.readdir(path.resolve(project.root, dir)).catch((error) => {
|
|
41
|
+
if (error.code === "ENOENT")
|
|
42
|
+
return [];
|
|
43
|
+
throw error;
|
|
44
|
+
});
|
|
45
|
+
await checkPrivatePaths(project.root, files.map(file => path.join(dir, file)), privateDirs);
|
|
46
|
+
}
|
|
47
|
+
await checkPrivatePaths(project.root, [project.file], privateDirs);
|
|
48
|
+
}
|
|
49
|
+
return session;
|
|
50
|
+
})();
|
|
27
51
|
return sessionPromise;
|
|
28
52
|
},
|
|
29
53
|
async client(options = {}) {
|
package/dist/database-queries.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
1
|
import { readJsonFile } from "./fsutil.js";
|
|
3
|
-
import {
|
|
2
|
+
import { statePath, writeState } from "./local-state.js";
|
|
4
3
|
import { locate } from "./package-files.js";
|
|
5
4
|
import { canonical, settledForm } from "./package-format.js";
|
|
6
5
|
export const QUERY_TOOL_TYPE = "database_query";
|
|
@@ -229,6 +228,23 @@ function startsLineComment(sql, i, dialect) {
|
|
|
229
228
|
return dialect !== "mysql" || i + 2 >= sql.length || /\s/.test(sql[i + 2]);
|
|
230
229
|
return dialect === "mysql" && sql[i] === "#";
|
|
231
230
|
}
|
|
231
|
+
const ORACLE_DIALECT = "oracle";
|
|
232
|
+
const ORACLE_Q_CLOSERS = { "[": "]", "{": "}", "(": ")", "<": ">" };
|
|
233
|
+
function oracleQuoteAt(sql, i) {
|
|
234
|
+
const prefix = /[nN]?[qQ]'/y;
|
|
235
|
+
prefix.lastIndex = i;
|
|
236
|
+
const match = prefix.exec(sql);
|
|
237
|
+
if (!match || (i > 0 && /[\p{L}\p{N}_$#]/u.test(sql[i - 1])))
|
|
238
|
+
return 0;
|
|
239
|
+
return match[0].length;
|
|
240
|
+
}
|
|
241
|
+
function oracleQuoteEnd(sql, start) {
|
|
242
|
+
if (start >= sql.length || /\s/.test(sql[start]))
|
|
243
|
+
return undefined;
|
|
244
|
+
const closer = `${ORACLE_Q_CLOSERS[sql[start]] ?? sql[start]}'`;
|
|
245
|
+
const end = sql.indexOf(closer, start + 1);
|
|
246
|
+
return end === -1 ? undefined : end + closer.length;
|
|
247
|
+
}
|
|
232
248
|
function dollarTagAt(sql, i) {
|
|
233
249
|
const tag = /\$(?:[A-Za-z_][A-Za-z0-9_]*)?\$/y;
|
|
234
250
|
tag.lastIndex = i;
|
|
@@ -254,6 +270,10 @@ function sqlTokens(sql, dialect) {
|
|
|
254
270
|
end = blockCommentEnd(sql, i, dialect === "postgresql");
|
|
255
271
|
kind = "comment";
|
|
256
272
|
}
|
|
273
|
+
else if (dialect === ORACLE_DIALECT && oracleQuoteAt(sql, i)) {
|
|
274
|
+
end = oracleQuoteEnd(sql, i + oracleQuoteAt(sql, i));
|
|
275
|
+
kind = "string";
|
|
276
|
+
}
|
|
257
277
|
else if (char === "'") {
|
|
258
278
|
const escapePrefix = i > 0 && /[eE]/.test(sql[i - 1]) && (i < 2 || !/[\p{L}\p{N}]/u.test(sql[i - 2]));
|
|
259
279
|
end = closing(sql, i, "'", dialect === "mysql" || (dialect === "postgresql" && escapePrefix));
|
|
@@ -376,6 +396,53 @@ export function isProcedureCall(sql, dialect) {
|
|
|
376
396
|
const code = sqlTokens(sql, dialect)?.filter((t) => t.kind !== "comment");
|
|
377
397
|
return isWord(code?.find((t) => !isSymbol(t, "(")), "EXEC", "EXECUTE");
|
|
378
398
|
}
|
|
399
|
+
const READ_FORBIDDEN_WORDS = [
|
|
400
|
+
"INSERT", "UPDATE", "DELETE", "MERGE", "UPSERT", "INTO", "TRUNCATE", "DROP", "ALTER", "CREATE", "GRANT", "REVOKE", "COPY", "CALL", "EXEC", "EXECUTE",
|
|
401
|
+
"UPDLOCK", "XLOCK", "HOLDLOCK", "TABLOCKX",
|
|
402
|
+
];
|
|
403
|
+
const LOCKING_AFTER_FOR = ["SHARE", "KEY", "NO", "UPDATE"];
|
|
404
|
+
const ORACLE_FORBIDDEN_WORDS = ["BEGIN", "DECLARE", "FUNCTION", "PROCEDURE", "PACKAGE", "PRAGMA", "COMMIT", "ROLLBACK", "SAVEPOINT", "HTTPURITYPE", "DBURITYPE", "XDBURITYPE"];
|
|
405
|
+
const ORACLE_FORBIDDEN_PREFIXES = ["DBMS_", "UTL_"];
|
|
406
|
+
function commonReadRefusal(code) {
|
|
407
|
+
return code.some((token, i) => {
|
|
408
|
+
if (token.kind !== "word")
|
|
409
|
+
return false;
|
|
410
|
+
const word = token.text.toUpperCase();
|
|
411
|
+
const next = code[i + 1];
|
|
412
|
+
return READ_FORBIDDEN_WORDS.includes(word) || (word === "FOR" && next?.kind === "word" && LOCKING_AFTER_FOR.includes(next.text.toUpperCase())) || (word === "LOCK" && isWord(next, "IN"));
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
export function oracleQueryProblem(sql, dialect, write) {
|
|
416
|
+
if (dialect !== ORACLE_DIALECT)
|
|
417
|
+
return undefined;
|
|
418
|
+
const tokens = sqlTokens(sql, dialect);
|
|
419
|
+
if (!tokens || tokens.some((t) => t.kind === "comment" && /^\/\*M?!/.test(t.text)))
|
|
420
|
+
return undefined;
|
|
421
|
+
const code = tokens.filter((t) => t.kind !== "comment");
|
|
422
|
+
if (code.some((t, i) => t.kind === "semicolon" && i !== code.length - 1))
|
|
423
|
+
return undefined;
|
|
424
|
+
if (write ? !isWord(code[0], "INSERT", "UPDATE", "DELETE") : !isWord(code.find((t) => !isSymbol(t, "(")), "SELECT", "WITH") || commonReadRefusal(code))
|
|
425
|
+
return undefined;
|
|
426
|
+
const refused = (message) => problem(write ? "write_statement_refused" : "forbidden_keyword", message, "sql_text");
|
|
427
|
+
for (const token of code) {
|
|
428
|
+
if (isSymbol(token, "@"))
|
|
429
|
+
return refused("The SQL may not reach another database: a database link (table@link) is not allowed.");
|
|
430
|
+
const name = token.kind === "word" ? token.text.toUpperCase() : token.kind === "identifier" ? token.text.slice(1, -1).replaceAll('""', '"').toUpperCase() : undefined;
|
|
431
|
+
if (name === undefined)
|
|
432
|
+
continue;
|
|
433
|
+
if (ORACLE_FORBIDDEN_WORDS.includes(name))
|
|
434
|
+
return refused(write ? `A write query may not hold ${name}.` : `The SQL may only read: ${name} is not allowed on Oracle.`);
|
|
435
|
+
if (ORACLE_FORBIDDEN_PREFIXES.some((prefix) => name.startsWith(prefix))) {
|
|
436
|
+
return refused(write
|
|
437
|
+
? `A write query may not call ${token.text}: Oracle's supplied packages are refused.`
|
|
438
|
+
: `The SQL may not call ${token.text}: Oracle's DBMS_* and UTL_* packages reach the network, files or dynamic SQL.`);
|
|
439
|
+
}
|
|
440
|
+
if (write && (name === "RETURNING" || name === "RETURN")) {
|
|
441
|
+
return refused("On Oracle a write query may not hold RETURNING: its INTO needs output binds, which a write query does not have. Read the changed rows with a separate read query.");
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return undefined;
|
|
445
|
+
}
|
|
379
446
|
export function listOutsideIn(sql, dialect, listNames) {
|
|
380
447
|
if (!listNames.length)
|
|
381
448
|
return undefined;
|
|
@@ -410,7 +477,7 @@ function baselineOf(schema, tool) {
|
|
|
410
477
|
return out;
|
|
411
478
|
}
|
|
412
479
|
export async function readQueryBaseline(root) {
|
|
413
|
-
const stored = await readJsonFile(
|
|
480
|
+
const stored = await readJsonFile(await statePath(root, BASELINE_FILE));
|
|
414
481
|
return stored && isObject(stored.tools) ? stored : undefined;
|
|
415
482
|
}
|
|
416
483
|
export async function rememberQueries(root, pkg, schema, by, now) {
|
|
@@ -477,6 +544,15 @@ export function checkQueryTools(disk, schema, baseline, connections) {
|
|
|
477
544
|
message: `Query tool "${slug}": ${call.message}`,
|
|
478
545
|
});
|
|
479
546
|
}
|
|
547
|
+
const oracle = typeof query.sql_text === "string" ? oracleQueryProblem(query.sql_text, dialect, write) : undefined;
|
|
548
|
+
if (oracle) {
|
|
549
|
+
findings.push({
|
|
550
|
+
code: oracle.code,
|
|
551
|
+
severity: "warning",
|
|
552
|
+
...locate(disk, `/${TOOLS_SECTION}/${index}/${QUERY_FIELD}/${oracle.at}`),
|
|
553
|
+
message: `Query tool "${slug}": ${oracle.message} The instance refuses it when the query is saved (${oracle.code}).`,
|
|
554
|
+
});
|
|
555
|
+
}
|
|
480
556
|
const connection = isObject(query.connection) ? query.connection : undefined;
|
|
481
557
|
if (write && connections?.some(c => c.name === connection?.name && c.dialect === dialect && c.allows_writes === false)) {
|
|
482
558
|
findings.push({
|
|
@@ -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/mcp-command.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
const RELEASE_LINE = "0.2";
|
|
2
|
+
export const EARLIER_RELEASE_LINES = ["0.1"];
|
|
3
|
+
const npx = (line) => ({ command: "npx", args: ["-y", `@cavelon/cli@${line}`, "mcp"] });
|
|
4
|
+
export const MCP_COMMAND = npx(RELEASE_LINE);
|
|
2
5
|
export const INSTALLED_MCP_COMMAND = { command: "cavelon", args: ["mcp"] };
|
|
3
|
-
export function mcpCommand(platform = process.platform) {
|
|
4
|
-
|
|
6
|
+
export function mcpCommand(platform = process.platform, line = RELEASE_LINE) {
|
|
7
|
+
const command = line === RELEASE_LINE ? MCP_COMMAND : npx(line);
|
|
8
|
+
return platform === "win32" ? { command: "cmd", args: ["/c", command.command, ...command.args] } : command;
|
|
9
|
+
}
|
|
10
|
+
export function currentMcpCommands() {
|
|
11
|
+
return [INSTALLED_MCP_COMMAND, mcpCommand("linux"), mcpCommand("win32")];
|
|
12
|
+
}
|
|
13
|
+
export function kitMcpCommands() {
|
|
14
|
+
return [...currentMcpCommands(), ...EARLIER_RELEASE_LINES.flatMap(line => [mcpCommand("linux", line), mcpCommand("win32", line)])];
|
|
5
15
|
}
|
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-entry.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isDeepStrictEqual } from "node:util";
|
|
2
|
-
import {
|
|
2
|
+
import { currentMcpCommands, kitMcpCommands } from "./mcp-command.js";
|
|
3
3
|
export function encodeMcpEntry(command, format, extra = {}) {
|
|
4
4
|
return format === "command-array" ? { ...extra, command: [command.command, ...command.args] } : { ...extra, [format === "goose-stdio" ? "cmd" : "command"]: command.command, args: command.args };
|
|
5
5
|
}
|
|
@@ -15,7 +15,13 @@ export function decodeMcpEntry(value, format) {
|
|
|
15
15
|
return { command: words[0], args: words.slice(1) };
|
|
16
16
|
}
|
|
17
17
|
export function isKitMcpEntry(value, format, extra = {}) {
|
|
18
|
+
return matchesAny(kitMcpCommands(), value, format, extra);
|
|
19
|
+
}
|
|
20
|
+
export function isCurrentMcpEntry(value, format, extra = {}) {
|
|
21
|
+
return matchesAny(currentMcpCommands(), value, format, extra);
|
|
22
|
+
}
|
|
23
|
+
function matchesAny(commands, value, format, extra) {
|
|
18
24
|
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
19
25
|
return false;
|
|
20
|
-
return
|
|
26
|
+
return commands.some(command => isDeepStrictEqual(encodeMcpEntry(command, format, extra), value));
|
|
21
27
|
}
|
|
@@ -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.1
|
|
3
|
+
"version": "0.2.1",
|
|
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;
|
package/dist/setup-agents.js
CHANGED
|
@@ -9,6 +9,7 @@ import { runProgram } from "./run-program.js";
|
|
|
9
9
|
import { KIT_VERSION } from "./version.js";
|
|
10
10
|
import { NATIVE_CLIENTS, nativeClient, hasNativeApprovalAdapter, readNativeMcp, resolveNativeMcp } from "./native-clients.js";
|
|
11
11
|
import { decodeMcpEntry, encodeMcpEntry, isKitMcpEntry } from "./mcp-entry.js";
|
|
12
|
+
import { kitMcpCommands } from "./mcp-command.js";
|
|
12
13
|
import { removeJsoncEntry, upsertJsoncEntry } from "./jsonc-config.js";
|
|
13
14
|
import { removeYamlEntry, upsertYamlEntry } from "./yaml-config.js";
|
|
14
15
|
import { applyNativeInstallation, checkNativeInstallation, planNativeInstallation, removeNativeInstallation } from "./native-install.js";
|
|
@@ -117,14 +118,11 @@ async function isDirectory(dir) {
|
|
|
117
118
|
export async function serverCommand(env, platform = process.platform) {
|
|
118
119
|
return (await findProgram("cavelon", env, platform, [".exe"])) ? INSTALLED_MCP_COMMAND : mcpCommand(platform);
|
|
119
120
|
}
|
|
120
|
-
function knownCommands() {
|
|
121
|
-
return [INSTALLED_MCP_COMMAND, mcpCommand("linux"), mcpCommand("win32")];
|
|
122
|
-
}
|
|
123
121
|
function jsonEntry(mcp, command) {
|
|
124
122
|
return { ...mcp.extra, command: command.command, args: command.args };
|
|
125
123
|
}
|
|
126
124
|
function isOwnJsonEntry(mcp, value) {
|
|
127
|
-
return
|
|
125
|
+
return kitMcpCommands().some((c) => JSON.stringify(jsonEntry(mcp, c)) === JSON.stringify(value));
|
|
128
126
|
}
|
|
129
127
|
function tomlBlock(command) {
|
|
130
128
|
return ["[mcp_servers.cavelon]", `command = ${JSON.stringify(command.command)}`, `args = [${command.args.map((a) => JSON.stringify(a)).join(", ")}]`].join("\n");
|
|
@@ -340,7 +340,7 @@ says who does what on the instance.
|
|
|
340
340
|
tool_type: database_query
|
|
341
341
|
scope: tenant_local
|
|
342
342
|
database_query:
|
|
343
|
-
connection: { name: shop-db, dialect: postgresql } # by name only: never a host, user or password; postgresql, mysql or
|
|
343
|
+
connection: { name: shop-db, dialect: postgresql } # by name only: never a host, user or password; postgresql, mysql, mssql or oracle
|
|
344
344
|
sql_text: SELECT number, status, shipped_at FROM orders WHERE number = :order_no AND email = :email LIMIT 5
|
|
345
345
|
parameters:
|
|
346
346
|
- name: order_no
|
|
@@ -419,6 +419,16 @@ says who does what on the instance.
|
|
|
419
419
|
reads (`procedure_definition_unreadable`, `procedure_definition_writes`):
|
|
420
420
|
ask the person for a read-only login with `EXECUTE` and `VIEW DEFINITION`
|
|
421
421
|
on procedures that read. Where a procedure is not needed, write a `SELECT`.
|
|
422
|
+
- **Oracle.** On an `oracle` connection the instance also refuses PL/SQL
|
|
423
|
+
(`BEGIN`, `DECLARE`, `WITH FUNCTION`), transaction control, `DBMS_*` and
|
|
424
|
+
`UTL_*` packages, `HTTPURITYPE` and database links (`table@link`):
|
|
425
|
+
`forbidden_keyword` in a read, `write_statement_refused` in a write, which
|
|
426
|
+
also may not hold `RETURNING`. Text in `q'[…]'` literals, strings and
|
|
427
|
+
comments is not SQL, and one trailing semicolon is accepted. Bound rows with
|
|
428
|
+
`FETCH FIRST n ROWS ONLY`. `cavelon validate` warns of these in one
|
|
429
|
+
`SELECT`/`WITH` read or `INSERT`/`UPDATE`/`DELETE` write; a PL/SQL block,
|
|
430
|
+
another first keyword or several statements get no local warning, and the
|
|
431
|
+
instance refuses them when it saves the query.
|
|
422
432
|
- `cavelon explain <code>` explains every code the connector uses: what
|
|
423
433
|
`validate` and the preview name, the codes of a failed call (`timeout`,
|
|
424
434
|
`identity_required`, …) and of a connection test.
|
|
@@ -441,7 +451,8 @@ parameters and replace the SQL and write settings with:
|
|
|
441
451
|
```
|
|
442
452
|
|
|
443
453
|
One `INSERT`, `UPDATE` or `DELETE`; `UPDATE`/`DELETE` need a parameterized
|
|
444
|
-
`WHERE`. Upserts and `RETURNING`/`OUTPUT` are allowed
|
|
454
|
+
`WHERE`. Upserts and `RETURNING`/`OUTPUT` are allowed (not `RETURNING` on
|
|
455
|
+
Oracle), a leading `WITH` and
|
|
445
456
|
multiple statements are not (`write_statement_refused`). On SQL Server one
|
|
446
457
|
`EXEC` of a writing procedure is allowed, subject to the instance's
|
|
447
458
|
`write_procedure_definition_refused` checks, including no transaction
|
|
@@ -132,8 +132,9 @@ use it when you parse the result.
|
|
|
132
132
|
in the Admin; preserve `credential_required_for_target_change`.
|
|
133
133
|
Older instances may lack these routes or keep management person-only;
|
|
134
134
|
follow their published gate and direct a person to their dashboard.
|
|
135
|
-
The dialects are `postgresql`, `mysql
|
|
136
|
-
`mssql` (SQL Server)
|
|
135
|
+
The dialects are `postgresql`, `mysql`,
|
|
136
|
+
`mssql` (SQL Server) and `oracle`; an instance accepts those its OpenAPI
|
|
137
|
+
publishes. A SQL Server login that can write keeps the
|
|
137
138
|
connection's queries from running (`write_privileges_unacknowledged`) until
|
|
138
139
|
it may only read or the Owner acknowledges it in the Admin, so ask for a
|
|
139
140
|
read-only login. A stored-procedure query (`EXEC`, SQL Server only) needs
|
|
@@ -180,6 +180,11 @@ the Admin. Then:
|
|
|
180
180
|
identity parameters included; it shows what the model would see. A list
|
|
181
181
|
parameter's value is a JSON array: `--value 'skus=["X-1","X-2"]'`. Never put
|
|
182
182
|
a real customer's data into a test file.
|
|
183
|
+
- An Oracle query is test-run the same way. Save-time refusals of PL/SQL,
|
|
184
|
+
`DBMS_*`/`UTL_*` packages, database links or a write's `RETURNING`
|
|
185
|
+
(`forbidden_keyword`, `write_statement_refused`) come before any test run.
|
|
186
|
+
`cavelon validate` warns of them in one recognizable read or write; a PL/SQL
|
|
187
|
+
block or several statements are refused only by the instance, on save.
|
|
183
188
|
- A read stored-procedure query (SQL Server) is test-run the same way; the
|
|
184
189
|
instance refuses the run while the connection's login can write or the
|
|
185
190
|
procedure's definition writes or cannot be read, with a code
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cavelon/cli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "The cavelon binary: CLI and local MCP server for building Cavelon solutions with a coding agent.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/goodguys-gmbh/cavelon-dev-kit",
|