@cavelon/cli 0.2.0 → 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.
@@ -9,10 +9,11 @@ import { serverCommand } from "../setup-agents.js";
9
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 realFile(file) {
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 realFile(file);
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
- return applyBlock(root, file, upsertBlock(await readTextFile(file), body, style, options));
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 realFile(claude)) === (await realFile(path.join(root, "AGENTS.md")))) {
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 [];
@@ -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, stateDir, writeState } from "../local-state.js";
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(path.join(stateDir(root), INVENTORY_JSON));
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/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 ??= resolveSession(io.env, io.cwd, globals);
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 = {}) {
@@ -1,6 +1,5 @@
1
- import path from "node:path";
2
1
  import { readJsonFile } from "./fsutil.js";
3
- import { stateDir, writeState } from "./local-state.js";
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";
@@ -478,7 +477,7 @@ function baselineOf(schema, tool) {
478
477
  return out;
479
478
  }
480
479
  export async function readQueryBaseline(root) {
481
- const stored = await readJsonFile(path.join(stateDir(root), BASELINE_FILE));
480
+ const stored = await readJsonFile(await statePath(root, BASELINE_FILE));
482
481
  return stored && isObject(stored.tools) ? stored : undefined;
483
482
  }
484
483
  export async function rememberQueries(root, pkg, schema, by, now) {
@@ -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
+ }
@@ -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 dir = stateDir(root);
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(path.join(stateDir(root), name), content);
34
+ await writeFileAtomic(file, content);
20
35
  }
21
36
  export async function readPull(root) {
22
- return readJsonFile(path.join(stateDir(root), "pull.json"));
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(path.join(stateDir(root), PULLED_FILES))) ?? {};
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(stateDir(root), "previews", `${safe}.json`);
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(path.join(stateDir(root), RETIRED_PREVIEWS));
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 = path.join(stateDir(root), "previews");
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(dir, name));
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
  }
@@ -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 { cacheDir, configDir, realPath, within } from "./paths.js";
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 [configDir(io.env), cacheDir(io.env)]) {
21
- if (within(await realPath(path.resolve(io.cwd, privateDir)), directory, true)) {
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.",
@@ -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.0",
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": 1492710,
29
- "sha256": "43099d2808917a4c587a4aa02c395f84af48729097e761e9dbe207b8b3147b00"
28
+ "size": 1492859,
29
+ "sha256": "dcabd82d25e65f242077c6bae670b70ce2bbc709fffbd82ddde4529f243cc20a"
30
30
  },
31
31
  {
32
32
  "path": "kilo-tui.mjs",
33
- "size": 938848,
34
- "sha256": "49e877d36eec917e1090589ecc4a92e5598489b70c22a4678c0564865c6b587b"
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": 1147117,
49
- "sha256": "400b01735ef1bdcb5fbd41bf217ba71c6b3476a3f99582e219d49105d3d94ea4"
48
+ "size": 1147266,
49
+ "sha256": "89dede5ad576accb5fa2d6e9e70a4a2265dd5bff62b71729166a39b508aa3c6d"
50
50
  },
51
51
  {
52
52
  "path": "opencode-server.mjs",
53
- "size": 1491698,
54
- "sha256": "978359ec19d4a77abb54a747feba73b696a22e9a02d3d507765b3600f4afcb99"
53
+ "size": 1491847,
54
+ "sha256": "89dffce88525b168fd1e9c870460c08da6cd4146cce727407f524dc842ac3330"
55
55
  },
56
56
  {
57
57
  "path": "opencode-tui.mjs",
58
- "size": 938754,
59
- "sha256": "338d394dde6ecded1b8b19c3d462790abb1759df624d5f3d6179b2abf0cab530"
58
+ "size": 938903,
59
+ "sha256": "4e6f6b7ccc3c883c6ec61180ac983fead85d6f4e8543782f9231199b6668c6da"
60
60
  },
61
61
  {
62
62
  "path": "pi-extension.mjs",
63
- "size": 1147025,
64
- "sha256": "1e87fb60974b3112fc57467adf23cc88cb41b8540f6c0420b447af0060aead9c"
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
 
@@ -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
- let real;
73
- try {
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 [configDir(ctx.io.env), cacheDir(ctx.io.env)]) {
49
- if (within(await realPath(path.resolve(ctx.io.cwd, dir)), real, true)) {
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
- const text = await readTextFile(file);
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
- const text = await readTextFile(file);
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 project = await findProject(cwd);
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavelon/cli",
3
- "version": "0.2.0",
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",