@cavelon/cli 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -7
- package/dist/agents.js +33 -17
- package/dist/command.js +1 -1
- package/dist/commands/api.js +76 -6
- package/dist/commands/init.js +35 -6
- package/dist/commands/limits-set.js +15 -6
- package/dist/commands/limits.js +1 -1
- package/dist/commands/loops.js +11 -5
- package/dist/commands/sandboxes.js +25 -18
- package/dist/commands/session.js +8 -4
- package/dist/commands/solution.js +127 -57
- package/dist/commands/values.js +8 -5
- package/dist/commands/work.js +31 -14
- package/dist/context.js +5 -1
- package/dist/contracts.js +83 -38
- package/dist/features.js +15 -0
- package/dist/fsutil.js +3 -0
- package/dist/http.js +29 -11
- package/dist/invoke.js +17 -13
- package/dist/limits.js +9 -1
- package/dist/local-state.js +18 -0
- package/dist/mcp.js +9 -2
- package/dist/openapi.js +10 -0
- package/dist/operations.js +1 -1
- package/dist/package-check.js +1 -1
- package/dist/package-files.js +103 -38
- package/dist/paths.js +50 -1
- package/dist/project.js +23 -4
- package/dist/results.js +47 -9
- package/dist/session.js +31 -7
- package/dist/skills/cavelon-authoring/SKILL.md +13 -3
- package/dist/skills/cavelon-long-running/SKILL.md +5 -1
- package/dist/skills/cavelon-loop/SKILL.md +4 -3
- package/dist/skills/cavelon-testing/SKILL.md +8 -1
- package/package.json +1 -1
package/dist/contracts.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
3
4
|
import { NOT_HERE } from "./http.js";
|
|
4
5
|
import { cacheDir, instanceKey } from "./paths.js";
|
|
5
6
|
import { readJsonFile, readTextFile, writeFileAtomic } from "./fsutil.js";
|
|
6
7
|
import { SUPPORTED_CONTRACTS } from "./version.js";
|
|
8
|
+
const NOT_MODIFIED = Symbol("not modified");
|
|
9
|
+
const RELEASE_TTL_SECONDS = 3600;
|
|
10
|
+
const DEVELOPMENT_TTL_SECONDS = 60;
|
|
7
11
|
const OPENAPI_PATHS = ["/openapi.json", "/api/v1/openapi.json"];
|
|
8
12
|
export class Contracts {
|
|
9
13
|
client;
|
|
@@ -21,26 +25,29 @@ export class Contracts {
|
|
|
21
25
|
get root() {
|
|
22
26
|
return path.join(cacheDir(this.env), instanceKey(this.client.url));
|
|
23
27
|
}
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
28
|
+
ttlSeconds(version) {
|
|
29
|
+
const raw = this.env.CAVELON_CONTRACT_TTL_SECONDS;
|
|
30
|
+
const seconds = Number(raw);
|
|
31
|
+
if (raw !== undefined && raw !== "" && Number.isFinite(seconds) && seconds >= 0)
|
|
32
|
+
return seconds;
|
|
33
|
+
return Contracts.isDevelopment(version) ? DEVELOPMENT_TTL_SECONDS : RELEASE_TTL_SECONDS;
|
|
27
34
|
}
|
|
28
|
-
|
|
35
|
+
static isDevelopment(version) {
|
|
29
36
|
return version === "unknown" || /dev|snapshot|local/i.test(version);
|
|
30
37
|
}
|
|
31
38
|
versionDir(version) {
|
|
32
39
|
return path.join(this.root, version.replace(/[^A-Za-z0-9._-]+/g, "_"));
|
|
33
40
|
}
|
|
34
|
-
fresh(fetchedAt) {
|
|
41
|
+
fresh(fetchedAt, version) {
|
|
35
42
|
if (!fetchedAt)
|
|
36
43
|
return false;
|
|
37
|
-
return this.now().getTime() - new Date(fetchedAt).getTime() < this.
|
|
44
|
+
return this.now().getTime() - new Date(fetchedAt).getTime() < this.ttlSeconds(version) * 1000;
|
|
38
45
|
}
|
|
39
46
|
async capabilities(options = {}) {
|
|
40
47
|
if (this.caps !== undefined && !options.refresh)
|
|
41
48
|
return this.caps;
|
|
42
49
|
const state = await readJsonFile(path.join(this.root, "state.json"));
|
|
43
|
-
if (!options.refresh && state && this.fresh(state.checked_at)) {
|
|
50
|
+
if (!options.refresh && state && this.fresh(state.checked_at, state.version)) {
|
|
44
51
|
const cached = await readJsonFile(path.join(this.versionDir(state.version), "capabilities.json"));
|
|
45
52
|
if (cached) {
|
|
46
53
|
this.caps = cached;
|
|
@@ -83,30 +90,58 @@ export class Contracts {
|
|
|
83
90
|
async cached(file, load, parse, options = {}) {
|
|
84
91
|
const version = await this.version();
|
|
85
92
|
const target = path.join(this.versionDir(version), file);
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
93
|
+
const metaFile = path.join(this.versionDir(version), `${file}.meta.json`);
|
|
94
|
+
const text = await readTextFile(target);
|
|
95
|
+
const meta = await readJsonFile(metaFile);
|
|
96
|
+
let cached;
|
|
97
|
+
if (text !== undefined) {
|
|
98
|
+
try {
|
|
99
|
+
cached = { value: parse(text) };
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
await
|
|
101
|
-
|
|
104
|
+
if (cached && !options.refresh && (!Contracts.isDevelopment(version) || this.fresh(meta?.fetched_at, version)))
|
|
105
|
+
return cached.value;
|
|
106
|
+
const loaded = await load(cached ? meta?.etag : undefined);
|
|
107
|
+
const fetchedAt = this.now().toISOString();
|
|
108
|
+
if (loaded === NOT_MODIFIED) {
|
|
109
|
+
if (!cached)
|
|
110
|
+
throw new Error(`${file}: the instance answered 304 Not Modified without being sent an ETag.`);
|
|
111
|
+
await writeFileAtomic(metaFile, JSON.stringify({ ...meta, fetched_at: fetchedAt }));
|
|
112
|
+
return cached.value;
|
|
113
|
+
}
|
|
114
|
+
await writeFileAtomic(target, loaded.serialized);
|
|
115
|
+
await writeFileAtomic(metaFile, JSON.stringify({ fetched_at: fetchedAt, ...(loaded.etag ? { etag: loaded.etag } : {}) }));
|
|
116
|
+
return loaded.value;
|
|
117
|
+
}
|
|
118
|
+
async getJson(route, etag, options = {}) {
|
|
119
|
+
const response = await this.client.get(route, {
|
|
120
|
+
query: options.query,
|
|
121
|
+
timeoutMs: options.timeoutMs,
|
|
122
|
+
allow: [...(options.allow ?? []), ...(etag ? [304] : [])],
|
|
123
|
+
headers: etag ? { "If-None-Match": etag } : undefined,
|
|
124
|
+
});
|
|
125
|
+
if (etag && response.status === 304)
|
|
126
|
+
return NOT_MODIFIED;
|
|
127
|
+
if (response.status < 200 || response.status >= 300)
|
|
128
|
+
return undefined;
|
|
129
|
+
return { value: response.data, serialized: response.text, etag: response.headers.get("etag") ?? undefined };
|
|
130
|
+
}
|
|
131
|
+
async getRequired(route, etag, query) {
|
|
132
|
+
const loaded = await this.getJson(route, etag, { query });
|
|
133
|
+
if (!loaded)
|
|
134
|
+
throw new Error(`${route} answered neither a body nor an error.`);
|
|
135
|
+
return loaded;
|
|
102
136
|
}
|
|
103
137
|
async openapi(options = {}) {
|
|
104
|
-
return this.cached("openapi.json", async () => {
|
|
138
|
+
return this.cached("openapi.json", async (etag) => {
|
|
105
139
|
for (const candidate of OPENAPI_PATHS) {
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
108
|
-
return
|
|
109
|
-
|
|
140
|
+
const loaded = await this.getJson(candidate, etag, { allow: NOT_HERE, timeoutMs: 120_000 });
|
|
141
|
+
if (loaded === NOT_MODIFIED)
|
|
142
|
+
return loaded;
|
|
143
|
+
if (loaded?.value && typeof loaded.value === "object" && "paths" in loaded.value)
|
|
144
|
+
return loaded;
|
|
110
145
|
}
|
|
111
146
|
throw new CavelonError(ExitCode.failure, {
|
|
112
147
|
code: "openapi_unavailable",
|
|
@@ -117,10 +152,7 @@ export class Contracts {
|
|
|
117
152
|
}
|
|
118
153
|
async errorCatalog(options = {}) {
|
|
119
154
|
try {
|
|
120
|
-
return await this.cached("error-catalog.json",
|
|
121
|
-
const response = await this.client.get("/api/v1/meta/error-catalog");
|
|
122
|
-
return { value: response.data, serialized: response.text };
|
|
123
|
-
}, (text) => JSON.parse(text), options);
|
|
155
|
+
return await this.cached("error-catalog.json", (etag) => this.getRequired("/api/v1/meta/error-catalog", etag), (text) => JSON.parse(text), options);
|
|
124
156
|
}
|
|
125
157
|
catch (error) {
|
|
126
158
|
if (error instanceof CavelonError && error.status === 404)
|
|
@@ -132,12 +164,7 @@ export class Contracts {
|
|
|
132
164
|
const wanted = version ?? (await this.capabilities())?.contracts?.package_versions?.current;
|
|
133
165
|
const file = Contracts.packageSchemaFile(wanted ?? "current");
|
|
134
166
|
try {
|
|
135
|
-
return await this.cached(file,
|
|
136
|
-
const response = await this.client.get("/api/v1/meta/package-schema", {
|
|
137
|
-
query: { version: wanted },
|
|
138
|
-
});
|
|
139
|
-
return { value: response.data, serialized: response.text };
|
|
140
|
-
}, (text) => JSON.parse(text), options);
|
|
167
|
+
return await this.cached(file, (etag) => this.getRequired("/api/v1/meta/package-schema", etag, { version: wanted }), (text) => JSON.parse(text), options);
|
|
141
168
|
}
|
|
142
169
|
catch (error) {
|
|
143
170
|
if (error instanceof CavelonError && error.status === 404) {
|
|
@@ -157,8 +184,26 @@ export class Contracts {
|
|
|
157
184
|
const state = await readJsonFile(path.join(this.root, "state.json"));
|
|
158
185
|
if (!state)
|
|
159
186
|
return undefined;
|
|
160
|
-
const
|
|
161
|
-
|
|
187
|
+
const target = path.join(this.versionDir(state.version), file);
|
|
188
|
+
const text = await readTextFile(target);
|
|
189
|
+
if (text === undefined)
|
|
190
|
+
return undefined;
|
|
191
|
+
let value;
|
|
192
|
+
try {
|
|
193
|
+
value = JSON.parse(text);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
const meta = file === "capabilities.json" ? { fetched_at: state.checked_at } : await readJsonFile(`${target}.meta.json`);
|
|
199
|
+
return {
|
|
200
|
+
value,
|
|
201
|
+
version: state.version,
|
|
202
|
+
fetched_at: meta?.fetched_at ?? null,
|
|
203
|
+
etag: meta?.etag ?? null,
|
|
204
|
+
sha256: createHash("sha256").update(text).digest("hex").slice(0, 12),
|
|
205
|
+
stale: Contracts.isDevelopment(state.version) && !this.fresh(meta?.fetched_at, state.version),
|
|
206
|
+
};
|
|
162
207
|
}
|
|
163
208
|
static packageSchemaFile(version) {
|
|
164
209
|
return `package-schema-${version.replace(/[^A-Za-z0-9._-]+/g, "_")}.json`;
|
package/dist/features.js
CHANGED
|
@@ -30,6 +30,21 @@ export function idempotencyKey(input) {
|
|
|
30
30
|
throw usageError("--idempotency-key must be a UUID.");
|
|
31
31
|
return given.toLowerCase();
|
|
32
32
|
}
|
|
33
|
+
export function withRetryKey(error, key) {
|
|
34
|
+
if (!(error instanceof CavelonError) || error.exitCode !== ExitCode.server)
|
|
35
|
+
return error;
|
|
36
|
+
const rest = error.hint?.replace(/^Retry[;.]\s*/, "");
|
|
37
|
+
const details = error.details && typeof error.details === "object" && !Array.isArray(error.details) ? error.details : {};
|
|
38
|
+
return new CavelonError(error.exitCode, {
|
|
39
|
+
code: error.code,
|
|
40
|
+
message: error.message,
|
|
41
|
+
hint: [`Retry with --idempotency-key ${key}, so the instance does not do it twice.`, rest ? rest[0].toUpperCase() + rest.slice(1) : ""].filter(Boolean).join(" "),
|
|
42
|
+
docs: error.docs,
|
|
43
|
+
status: error.status,
|
|
44
|
+
details: { ...details, idempotency_key: key },
|
|
45
|
+
blockers: error.blockers,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
33
48
|
export function stableKey(seed) {
|
|
34
49
|
const hex = createHash("sha256").update(seed).digest("hex");
|
|
35
50
|
const variant = ((Number.parseInt(hex[16], 16) & 0x3) | 0x8).toString(16);
|
package/dist/fsutil.js
CHANGED
|
@@ -23,6 +23,9 @@ export async function readTextFile(file) {
|
|
|
23
23
|
throw error;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
export function withoutBom(text) {
|
|
27
|
+
return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
28
|
+
}
|
|
26
29
|
export async function writeFileAtomic(file, content, mode = 0o644, dirMode = 0o755) {
|
|
27
30
|
await fs.mkdir(path.dirname(file), { recursive: true, mode: dirMode });
|
|
28
31
|
const tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
|
package/dist/http.js
CHANGED
|
@@ -15,6 +15,12 @@ export function tokensDisabledError(url) {
|
|
|
15
15
|
"works for the commands that accept one: a person runs `cavelon login` with it.",
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
+
function leading(text, slashes) {
|
|
19
|
+
let i = 0;
|
|
20
|
+
while (i < text.length && (text.charCodeAt(i) <= 0x20 || (slashes && (text[i] === "/" || text[i] === "\\"))))
|
|
21
|
+
i++;
|
|
22
|
+
return i;
|
|
23
|
+
}
|
|
18
24
|
export class ApiClient {
|
|
19
25
|
target;
|
|
20
26
|
env;
|
|
@@ -28,19 +34,23 @@ export class ApiClient {
|
|
|
28
34
|
}
|
|
29
35
|
resolve(pathOrUrl, query) {
|
|
30
36
|
const base = new URL(this.target.url.endsWith("/") ? this.target.url : `${this.target.url}/`);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
throw new CavelonError(ExitCode.usage, {
|
|
36
|
-
code: "foreign_url",
|
|
37
|
-
message: `Refusing to send the token to ${url.origin}; the instance is ${base.origin}.`,
|
|
38
|
-
});
|
|
37
|
+
const foreign = (where, why = `the instance is ${base.origin}`) => new CavelonError(ExitCode.usage, { code: "foreign_url", message: `Refusing to send the token to ${where}; ${why}.` });
|
|
38
|
+
const parse = (input, against) => {
|
|
39
|
+
try {
|
|
40
|
+
return new URL(input, against);
|
|
39
41
|
}
|
|
42
|
+
catch {
|
|
43
|
+
throw foreign(JSON.stringify(input), "it is not a URL on the instance");
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const hasScheme = /^[a-z][a-z0-9+.-]*:/i.test(pathOrUrl.slice(leading(pathOrUrl, false)));
|
|
47
|
+
const url = hasScheme ? parse(pathOrUrl) : parse(pathOrUrl.slice(leading(pathOrUrl, true)), base);
|
|
48
|
+
for (const candidate of [url, parse(pathOrUrl, base)]) {
|
|
49
|
+
if (candidate.origin !== base.origin)
|
|
50
|
+
throw foreign(candidate.origin === "null" ? candidate.protocol : candidate.origin);
|
|
40
51
|
}
|
|
41
|
-
|
|
42
|
-
url
|
|
43
|
-
}
|
|
52
|
+
if (!hasScheme && !url.pathname.startsWith(base.pathname))
|
|
53
|
+
throw foreign(url.pathname, `it is outside the instance's path ${base.pathname}`);
|
|
44
54
|
for (const [key, value] of Object.entries(query ?? {})) {
|
|
45
55
|
if (value === undefined || value === null)
|
|
46
56
|
continue;
|
|
@@ -149,6 +159,14 @@ function parseBody(text, contentType) {
|
|
|
149
159
|
}
|
|
150
160
|
return text;
|
|
151
161
|
}
|
|
162
|
+
export async function bodyBytes(response, url, signal) {
|
|
163
|
+
try {
|
|
164
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
throw networkError(error, url, signal);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
152
170
|
function networkError(error, url, signal) {
|
|
153
171
|
const reason = signal?.reason;
|
|
154
172
|
if (reason?.name === "TimeoutError" || error?.name === "TimeoutError") {
|
package/dist/invoke.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { CavelonError, ExitCode, validationError } from "./errors.js";
|
|
4
|
+
import { bodyBytes } from "./http.js";
|
|
4
5
|
import { coerceParameter, isArrayParameter, operationAt, validateBody } from "./openapi.js";
|
|
5
6
|
export async function openapiOrWarn(ctx) {
|
|
6
7
|
try {
|
|
@@ -18,13 +19,14 @@ export function buildRequest(op, args) {
|
|
|
18
19
|
const given = { ...(args.params ?? {}) };
|
|
19
20
|
const query = {};
|
|
20
21
|
const headers = { ...(args.headers ?? {}) };
|
|
22
|
+
const sentHeaders = new Set(Object.keys(headers).map((h) => h.toLowerCase()));
|
|
21
23
|
let filled = op.path;
|
|
22
24
|
const missing = [];
|
|
23
25
|
for (const param of op.parameters) {
|
|
24
26
|
const values = given[param.name];
|
|
25
27
|
delete given[param.name];
|
|
26
28
|
if (!values || values.length === 0) {
|
|
27
|
-
if (param.required)
|
|
29
|
+
if (param.required && !(param.in === "header" && sentHeaders.has(param.name.toLowerCase())))
|
|
28
30
|
missing.push(`${param.name} (${param.in})`);
|
|
29
31
|
continue;
|
|
30
32
|
}
|
|
@@ -56,13 +58,21 @@ export function buildRequest(op, args) {
|
|
|
56
58
|
}
|
|
57
59
|
return { path: filled, query, headers };
|
|
58
60
|
}
|
|
61
|
+
function isMultipart(op, args) {
|
|
62
|
+
const contentTypes = Object.keys(op.requestBody?.content ?? {});
|
|
63
|
+
return (contentTypes.includes("multipart/form-data") && !contentTypes.includes("application/json")) || Boolean(args.files?.length);
|
|
64
|
+
}
|
|
65
|
+
export function previewRequest(doc, op, args) {
|
|
66
|
+
const { path: target, query, headers } = buildRequest(op, args);
|
|
67
|
+
if (!isMultipart(op, args) && args.body !== undefined && doc)
|
|
68
|
+
validateBody(doc, op, args.body);
|
|
69
|
+
return { method: op.method, path: target, query, headers, body: args.body ?? null };
|
|
70
|
+
}
|
|
59
71
|
export async function callOperation(ctx, client, doc, op, args) {
|
|
60
72
|
const { path: target, query, headers } = buildRequest(op, args);
|
|
61
|
-
const contentTypes = Object.keys(op.requestBody?.content ?? {});
|
|
62
|
-
const multipart = contentTypes.includes("multipart/form-data") && !contentTypes.includes("application/json");
|
|
63
73
|
let form;
|
|
64
74
|
let json;
|
|
65
|
-
if (
|
|
75
|
+
if (isMultipart(op, args)) {
|
|
66
76
|
form = new FormData();
|
|
67
77
|
if (args.body && typeof args.body === "object") {
|
|
68
78
|
for (const [key, value] of Object.entries(args.body)) {
|
|
@@ -81,16 +91,10 @@ export async function callOperation(ctx, client, doc, op, args) {
|
|
|
81
91
|
validateBody(doc, op, args.body);
|
|
82
92
|
json = args.body;
|
|
83
93
|
}
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
headers,
|
|
87
|
-
json,
|
|
88
|
-
form,
|
|
89
|
-
sendTenant: args.sendTenant,
|
|
90
|
-
signal: AbortSignal.timeout(args.timeoutMs ?? (Number(ctx.io.env.CAVELON_HTTP_TIMEOUT_MS) || 30_000)),
|
|
91
|
-
});
|
|
94
|
+
const signal = AbortSignal.timeout(args.timeoutMs ?? (Number(ctx.io.env.CAVELON_HTTP_TIMEOUT_MS) || 30_000));
|
|
95
|
+
const response = await client.fetchRaw(op.method, target, { query, headers, json, form, sendTenant: args.sendTenant, signal });
|
|
92
96
|
const contentType = response.headers.get("content-type") ?? "";
|
|
93
|
-
const bytes =
|
|
97
|
+
const bytes = await bodyBytes(response, client.resolve(target), signal);
|
|
94
98
|
const isText = /json|text|xml|yaml|markdown|event-stream/.test(contentType) || bytes.length === 0;
|
|
95
99
|
const text = isText ? new TextDecoder().decode(bytes) : "";
|
|
96
100
|
let data = text;
|
package/dist/limits.js
CHANGED
|
@@ -243,8 +243,16 @@ export async function readQuotas(ctx, limits) {
|
|
|
243
243
|
if (!link)
|
|
244
244
|
return undefined;
|
|
245
245
|
const client = await ctx.client();
|
|
246
|
-
const response = await client.get(link.path, { allow: [400, 403, 404] });
|
|
247
246
|
const base = { path: link.path, docs: link.docs ?? null };
|
|
247
|
+
let response;
|
|
248
|
+
try {
|
|
249
|
+
response = await client.get(link.path, { allow: [400, 403, 404] });
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if (!(error instanceof CavelonError))
|
|
253
|
+
throw error;
|
|
254
|
+
return { ...base, items: [], unavailable: `${link.path}: ${error.message}` };
|
|
255
|
+
}
|
|
248
256
|
if (response.status !== 200 || !response.data || typeof response.data !== "object") {
|
|
249
257
|
return { ...base, items: [], unavailable: `${link.path} answered ${response.status}.` };
|
|
250
258
|
}
|
package/dist/local-state.js
CHANGED
|
@@ -21,6 +21,24 @@ export async function writeState(root, name, content) {
|
|
|
21
21
|
export async function readPull(root) {
|
|
22
22
|
return readJsonFile(path.join(stateDir(root), "pull.json"));
|
|
23
23
|
}
|
|
24
|
+
const PULLED_FILES = "pulled-files.json";
|
|
25
|
+
export async function fileDigest(file) {
|
|
26
|
+
const bytes = await fs.readFile(file).catch(() => undefined);
|
|
27
|
+
return bytes && createHash("sha256").update(bytes).digest("hex");
|
|
28
|
+
}
|
|
29
|
+
export async function writePulledFiles(root, files) {
|
|
30
|
+
const digests = {};
|
|
31
|
+
for (const file of files) {
|
|
32
|
+
const value = await fileDigest(path.join(root, file));
|
|
33
|
+
if (value)
|
|
34
|
+
digests[file] = value;
|
|
35
|
+
}
|
|
36
|
+
await writeState(root, PULLED_FILES, JSON.stringify({ digests }, null, 2));
|
|
37
|
+
}
|
|
38
|
+
export async function readPulledFiles(root) {
|
|
39
|
+
const stored = await readJsonFile(path.join(stateDir(root), PULLED_FILES));
|
|
40
|
+
return stored?.digests && typeof stored.digests === "object" ? stored.digests : {};
|
|
41
|
+
}
|
|
24
42
|
export function digest(value) {
|
|
25
43
|
return createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
|
26
44
|
}
|
package/dist/mcp.js
CHANGED
|
@@ -6,8 +6,15 @@ import { KIT_VERSION } from "./version.js";
|
|
|
6
6
|
const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a person stored with `cavelon login` " +
|
|
7
7
|
"(or CAVELON_TOKEN). You never see or pass the token. Tools that start work (kb_upload, test_run, " +
|
|
8
8
|
"loop_start, sandbox_seed, artifacts_export) return operation ids at once; read them with operation_status, " +
|
|
9
|
-
"and follow a loop with loop_iterations.
|
|
10
|
-
"
|
|
9
|
+
"and follow a loop with loop_iterations. What needs confirmation: apply imports only with confirm set to a preview's id; " +
|
|
10
|
+
"limits_set, models_set_limit, loop_cancel, sandbox_seed, trigger_identity, and api for an operation that is not read-only, " +
|
|
11
|
+
"return what they would do and change nothing without confirm: true; show the person that first. " +
|
|
12
|
+
"init and pull write files in the solution folder without confirm (pull refuses to replace package files with uncommitted changes unless force), " +
|
|
13
|
+
"and the other changing tools act at once. api refuses, even with confirm, an operation the instance marks for a person " +
|
|
14
|
+
"(x-cavelon-person-only; its reason is in the error), or on an instance that marks none, one that changes a secret, " +
|
|
15
|
+
"creates or revokes a credential (tokens, API keys, sign-in) or decides an approval. Tools read and write files only " +
|
|
16
|
+
"inside the solution folder (the folder of cavelon.yaml, or the one the server started in), never in cavelon's own " +
|
|
17
|
+
"config or cache directory. Read limits before planning a solution: it lists what the " +
|
|
11
18
|
"instance allows this tenant (upload sizes and types, run and tool limits, timeouts, quotas) and who changes each. " +
|
|
12
19
|
"Never change a limit on your own: propose the old and new value (limits_set for a limit a tenant admin changes, " +
|
|
13
20
|
"models_set_limit for an endpoint's max_concurrent_requests) and let the person decide; an operator's limit goes to the operator. " +
|
package/dist/openapi.js
CHANGED
|
@@ -38,12 +38,22 @@ export function operations(doc) {
|
|
|
38
38
|
requestBody: raw.requestBody ? deref(doc, raw.requestBody) : undefined,
|
|
39
39
|
responses: raw.responses ?? {},
|
|
40
40
|
readOnly: method === "get" || method === "head" || method === "options",
|
|
41
|
+
personOnly: personOnlyOf(raw),
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
indexCache.set(doc, out);
|
|
45
46
|
return out;
|
|
46
47
|
}
|
|
48
|
+
function personOnlyOf(raw) {
|
|
49
|
+
if (!("x-cavelon-person-only" in raw))
|
|
50
|
+
return undefined;
|
|
51
|
+
const reason = raw["x-cavelon-person-only-reason"];
|
|
52
|
+
return {
|
|
53
|
+
marked: raw["x-cavelon-person-only"] === true,
|
|
54
|
+
...(typeof reason === "string" && reason.trim() ? { reason: reason.trim() } : {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
47
57
|
export function deref(doc, value) {
|
|
48
58
|
let current = value;
|
|
49
59
|
for (let i = 0; i < 10 && current && typeof current === "object" && typeof current.$ref === "string"; i++) {
|
package/dist/operations.js
CHANGED
package/dist/package-check.js
CHANGED
|
@@ -32,7 +32,7 @@ export const KIT_CODES = [
|
|
|
32
32
|
{
|
|
33
33
|
code: "package_file_invalid",
|
|
34
34
|
area: "package",
|
|
35
|
-
message: "A package file is not valid YAML or JSON.",
|
|
35
|
+
message: "A package file is not valid YAML or JSON, or is a link to a file outside the solution or to none.",
|
|
36
36
|
hint: "Fix the syntax at the line the finding names.",
|
|
37
37
|
docs: PACKAGE_DOCS,
|
|
38
38
|
},
|