@cavelon/cli 0.1.1 → 0.1.3
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 +50 -20
- package/dist/agents.js +43 -19
- package/dist/choose.js +112 -0
- package/dist/command.js +1 -1
- package/dist/commands/api.js +76 -6
- package/dist/commands/index.js +2 -0
- package/dist/commands/init.js +196 -29
- package/dist/commands/limits-set.js +17 -8
- package/dist/commands/limits.js +2 -2
- package/dist/commands/loops.js +12 -6
- package/dist/commands/sandboxes.js +27 -20
- package/dist/commands/session.js +179 -45
- package/dist/commands/setup.js +426 -0
- package/dist/commands/solution.js +137 -91
- package/dist/commands/tenants.js +33 -22
- package/dist/commands/values.js +8 -5
- package/dist/commands/work.js +33 -16
- package/dist/context.js +5 -1
- package/dist/contracts.js +83 -38
- package/dist/embedded.js +7 -0
- package/dist/features.js +15 -0
- package/dist/fsutil.js +3 -0
- package/dist/git.js +14 -9
- package/dist/harness-ref.js +54 -0
- package/dist/http.js +44 -18
- package/dist/install.js +94 -0
- package/dist/invoke.js +17 -13
- package/dist/limits.js +9 -1
- package/dist/local-state.js +18 -0
- package/dist/main.js +31 -2
- package/dist/markers.js +53 -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 +53 -4
- package/dist/principal.js +43 -0
- package/dist/project.js +23 -4
- package/dist/prompt.js +55 -11
- package/dist/results.js +47 -9
- package/dist/run-program.js +92 -0
- package/dist/session.js +100 -19
- package/dist/setup-agents.js +544 -0
- 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 +15 -9
- package/dist/skills/cavelon-testing/SKILL.md +9 -2
- package/dist/tenant-choice.js +93 -0
- package/dist/update-check.js +118 -0
- package/dist/version.js +2 -1
- package/package.json +5 -2
|
@@ -37,6 +37,9 @@ the person would see: that the approval was reached, who approves, the facts
|
|
|
37
37
|
and the recommendation in the instructions. The branches after the decision
|
|
38
38
|
(approved, rejected, expired) are never reached by a test; a person checks them
|
|
39
39
|
on a draft solution by deciding a real approval, and you never decide one.
|
|
40
|
+
Who may decide (`approvers`, `forbid_self_approval`) is enforced when a person
|
|
41
|
+
decides, not in a test: with tiers by amount, write one case per tier that
|
|
42
|
+
reaches the approval, and leave the refusals to the instance.
|
|
40
43
|
`examples/expense-approval` in the dev-kit repository has such a suite.
|
|
41
44
|
|
|
42
45
|
## Running
|
|
@@ -52,7 +55,11 @@ each call under your shell's time limit). `test run --wait --timeout 5m` does
|
|
|
52
55
|
both in one call where your client allows long commands; when its wait ends
|
|
53
56
|
first, its last line is the command that resumes, with the same timeout. Exit 1 after a run
|
|
54
57
|
means a case failed, even though the run itself finished; the output names the
|
|
55
|
-
cases that did not pass and why, and `cavelon trace <run>` shows each one.
|
|
58
|
+
cases that did not pass and why, and `cavelon trace <run>` shows each one. Exit
|
|
59
|
+
1 also means the run measured nothing comparable (steps not run, technical
|
|
60
|
+
errors, no pass rate): it is no evidence the solution works, so do not go on to
|
|
61
|
+
`activate`; find the cause and run again. Exit 5 means answers wait for a
|
|
62
|
+
person's verdict or a value a case needs: tell the person.
|
|
56
63
|
|
|
57
64
|
## Reading what happened
|
|
58
65
|
|
|
@@ -86,5 +93,5 @@ Change one thing at a time, then run the same suite again and compare:
|
|
|
86
93
|
a smaller model or fewer tool rounds often suffice for a step.
|
|
87
94
|
|
|
88
95
|
Record why a change helped in the commit message. When every suite passes,
|
|
89
|
-
`cavelon activate --harness <slug>` goes through the readiness gate; if the
|
|
96
|
+
`cavelon activate --harness <name or slug>` goes through the readiness gate; if the
|
|
90
97
|
token may not activate, a person activates in the Admin.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { closest, displayName, MAX_LISTED, pick } from "./choose.js";
|
|
2
|
+
import { CavelonError, ExitCode } from "./errors.js";
|
|
3
|
+
import { readTenantless } from "./principal.js";
|
|
4
|
+
import { canAsk } from "./prompt.js";
|
|
5
|
+
import { cavelonCommand } from "./shell.js";
|
|
6
|
+
export function listsTenants(tenantless) {
|
|
7
|
+
return Boolean(tenantless && !tenantless.refused && tenantless.tenants);
|
|
8
|
+
}
|
|
9
|
+
export function tenantRef(tenant) {
|
|
10
|
+
return tenant.slug ?? tenant.id;
|
|
11
|
+
}
|
|
12
|
+
export function tenantTitle(tenant) {
|
|
13
|
+
const names = [tenant.slug && tenant.slug !== tenant.name ? tenant.slug : undefined, tenant.id].filter(Boolean).join(", ");
|
|
14
|
+
return tenant.name ? `${tenant.name} (${names})` : tenant.slug ? `${tenant.slug} (${tenant.id})` : tenant.id;
|
|
15
|
+
}
|
|
16
|
+
export async function searchTenants(client, text) {
|
|
17
|
+
const found = await readTenantless(client, { search: text });
|
|
18
|
+
return found && !found.refused ? (found.tenants ?? []) : [];
|
|
19
|
+
}
|
|
20
|
+
export async function chooseTenant(ctx, client, reach) {
|
|
21
|
+
const { tenants, reachesAll } = reach;
|
|
22
|
+
if (!reachesAll && tenants.length === 1)
|
|
23
|
+
return { kind: "chosen", tenant: tenants[0], how: "only" };
|
|
24
|
+
if (!reachesAll && tenants.length === 0)
|
|
25
|
+
return { kind: "none" };
|
|
26
|
+
if (!canAsk(ctx))
|
|
27
|
+
return { kind: "open" };
|
|
28
|
+
const intro = reachesAll
|
|
29
|
+
? `This token reaches every tenant on ${client.url}.${tenants.length ? " Yours:" : ""}`
|
|
30
|
+
: `This token reaches ${tenants.length} tenants on ${client.url}:`;
|
|
31
|
+
const picked = await pick(ctx, {
|
|
32
|
+
intro,
|
|
33
|
+
question: "Which tenant?",
|
|
34
|
+
items: tenants,
|
|
35
|
+
extra: (t) => t.role ?? undefined,
|
|
36
|
+
preferred: tenants.find((t) => t.is_default),
|
|
37
|
+
search: reachesAll ? (text) => searchTenants(client, text) : undefined,
|
|
38
|
+
});
|
|
39
|
+
if (!("item" in picked))
|
|
40
|
+
throw new Error("unreachable: the tenant list offers no other entry");
|
|
41
|
+
return { kind: "chosen", tenant: picked.item, how: "picked" };
|
|
42
|
+
}
|
|
43
|
+
export function commandLines(tenants, command) {
|
|
44
|
+
const shown = tenants.slice(0, MAX_LISTED).map((t) => ({ text: command(tenantRef(t)), name: t.name && t.name !== t.slug ? t.name : "" }));
|
|
45
|
+
const width = Math.max(...shown.map((s) => s.text.length));
|
|
46
|
+
const lines = shown.map((s) => ` ${s.name ? `${s.text.padEnd(width)} ${s.name}` : s.text}`);
|
|
47
|
+
if (tenants.length > shown.length)
|
|
48
|
+
lines.push(` … and ${tenants.length - shown.length} more (\`cavelon tenant list\` lists them)`);
|
|
49
|
+
return lines.join("\n");
|
|
50
|
+
}
|
|
51
|
+
export function choicesOf(tenants, command) {
|
|
52
|
+
return tenants.map((t) => ({ id: t.id, slug: t.slug, name: t.name, role: t.role, is_default: t.is_default, command: command(tenantRef(t)) }));
|
|
53
|
+
}
|
|
54
|
+
export function tenantOpenError(url, reach, lead, command = { line: (ref) => cavelonCommand("use", ref), template: "cavelon use <name or slug>" }) {
|
|
55
|
+
const { tenants, reachesAll } = reach;
|
|
56
|
+
const what = reachesAll ? "every tenant" : `${tenants.length} tenants`;
|
|
57
|
+
const lines = tenants.length ? `Run the line for the tenant you want:\n${commandLines(tenants, command.line)}` : "";
|
|
58
|
+
const search = reachesAll
|
|
59
|
+
? `${lines ? "\nAny other tenant: " : "Choose one: "}\`${command.template}\`; \`cavelon tenant list --search <part of the name>\` finds its slug.`
|
|
60
|
+
: "";
|
|
61
|
+
return new CavelonError(ExitCode.usage, {
|
|
62
|
+
code: "tenant_required",
|
|
63
|
+
message: `${lead}This token reaches ${what} on ${url}, and there is no terminal to ask which one to use.`,
|
|
64
|
+
hint: `${lines}${search}`,
|
|
65
|
+
details: { tenants: choicesOf(tenants, command.line), reaches_all_tenants: reachesAll },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export function noTenantError(url, atLogin = true) {
|
|
69
|
+
return new CavelonError(ExitCode.unauthorized, {
|
|
70
|
+
code: "no_tenant_reached",
|
|
71
|
+
message: `This token reaches no tenant on ${url}${atLogin ? ", so nothing was stored" : ""}.`,
|
|
72
|
+
hint: `Open ${url}/account/access-tokens, create a token for the tenant you work in (or ask a tenant administrator to add you to one), ` +
|
|
73
|
+
"then run `cavelon login` again with the new token.",
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
export function tenantMissError(ref, pool, reachesAll, from) {
|
|
77
|
+
const near = closest(pool, ref);
|
|
78
|
+
const listed = near.length ? near : pool.slice(0, MAX_LISTED);
|
|
79
|
+
const label = near.length ? "Closest" : "This token reaches";
|
|
80
|
+
const names = listed.map(displayName).join(", ");
|
|
81
|
+
const hints = [];
|
|
82
|
+
if (listed.length)
|
|
83
|
+
hints.push(`Run the line for the tenant you mean:\n${commandLines(listed, (r) => cavelonCommand("use", r))}`);
|
|
84
|
+
hints.push(reachesAll
|
|
85
|
+
? "This token reaches every tenant: `cavelon tenant list --search <part of the name>` finds one."
|
|
86
|
+
: "`cavelon tenant list` shows the tenants this token reaches with name, slug and id; `cavelon use` alone lets you choose.");
|
|
87
|
+
return new CavelonError(ExitCode.failure, {
|
|
88
|
+
code: "tenant_not_found",
|
|
89
|
+
message: `No tenant "${ref}" that this token reaches${from ? ` (from ${from})` : ""}.${names ? ` ${label}: ${names}.` : ""}`,
|
|
90
|
+
hint: hints.join("\n"),
|
|
91
|
+
details: { tenants: listed.map((t) => ({ id: t.id, slug: t.slug, name: t.name })) },
|
|
92
|
+
});
|
|
93
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { NPM_PACKAGE, REPOSITORY } from "./install.js";
|
|
3
|
+
import { readJsonFile, writeFileAtomic } from "./fsutil.js";
|
|
4
|
+
import { cacheDir } from "./paths.js";
|
|
5
|
+
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
6
|
+
export const CHECK_TIMEOUT_MS = 1500;
|
|
7
|
+
const MAX_BODY = 1024 * 1024;
|
|
8
|
+
const STATE_FILE = "update-check.json";
|
|
9
|
+
const SOURCES = {
|
|
10
|
+
github: { url: `https://api.github.com/repos/${REPOSITORY}/releases/latest`, field: "tag_name" },
|
|
11
|
+
npm: { url: `https://registry.npmjs.org/${NPM_PACKAGE}/latest`, field: "version" },
|
|
12
|
+
};
|
|
13
|
+
const CI_VARIABLES = ["CI", "CONTINUOUS_INTEGRATION", "BUILD_NUMBER", "RUN_ID", "GITHUB_ACTIONS", "GITLAB_CI", "TF_BUILD", "BUILDKITE", "JENKINS_URL", "TEAMCITY_VERSION", "CODEBUILD_BUILD_ID"];
|
|
14
|
+
function setTo(value) {
|
|
15
|
+
return value !== undefined && !["", "0", "false", "no"].includes(value.trim().toLowerCase());
|
|
16
|
+
}
|
|
17
|
+
export function quietReason(request) {
|
|
18
|
+
const { io, install } = request;
|
|
19
|
+
if (setTo(io.env.CAVELON_NO_UPDATE_CHECK))
|
|
20
|
+
return "CAVELON_NO_UPDATE_CHECK";
|
|
21
|
+
if (request.json)
|
|
22
|
+
return "json";
|
|
23
|
+
if (request.command === "mcp")
|
|
24
|
+
return "mcp";
|
|
25
|
+
if (CI_VARIABLES.some((name) => setTo(io.env[name])))
|
|
26
|
+
return "ci";
|
|
27
|
+
if (!io.stderr.isTTY)
|
|
28
|
+
return "no terminal";
|
|
29
|
+
if (!install.source)
|
|
30
|
+
return install.method;
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
export function startUpdateCheck(request) {
|
|
34
|
+
if (quietReason(request))
|
|
35
|
+
return Promise.resolve(undefined);
|
|
36
|
+
return check(request).catch(() => undefined);
|
|
37
|
+
}
|
|
38
|
+
async function check(request) {
|
|
39
|
+
const { io, install, version } = request;
|
|
40
|
+
const source = install.source;
|
|
41
|
+
const file = path.join(cacheDir(io.env), STATE_FILE);
|
|
42
|
+
const state = (await readJsonFile(file)) ?? {};
|
|
43
|
+
const now = io.now();
|
|
44
|
+
const before = JSON.stringify(state);
|
|
45
|
+
if (state.source !== source) {
|
|
46
|
+
delete state.latest;
|
|
47
|
+
delete state.checked_at;
|
|
48
|
+
state.source = source;
|
|
49
|
+
}
|
|
50
|
+
if (!within(state.checked_at, now)) {
|
|
51
|
+
state.checked_at = now.toISOString();
|
|
52
|
+
const latest = await latestVersion(source, version, request.fetch ?? fetch).catch(() => undefined);
|
|
53
|
+
if (latest)
|
|
54
|
+
state.latest = latest;
|
|
55
|
+
}
|
|
56
|
+
let notice;
|
|
57
|
+
if (state.latest && newer(state.latest, version) && !within(state.notified_at, now)) {
|
|
58
|
+
notice = noticeText(state.latest, version, install);
|
|
59
|
+
state.notified_at = now.toISOString();
|
|
60
|
+
}
|
|
61
|
+
if (JSON.stringify(state) !== before)
|
|
62
|
+
await writeFileAtomic(file, `${JSON.stringify(state, null, 2)}\n`, 0o600, 0o700);
|
|
63
|
+
return notice;
|
|
64
|
+
}
|
|
65
|
+
function within(stamp, now) {
|
|
66
|
+
const at = stamp ? Date.parse(stamp) : NaN;
|
|
67
|
+
return Number.isFinite(at) && at <= now.getTime() && now.getTime() - at < DAY_MS;
|
|
68
|
+
}
|
|
69
|
+
async function latestVersion(source, version, fetchImpl) {
|
|
70
|
+
const { url, field } = SOURCES[source];
|
|
71
|
+
const response = await fetchImpl(url, {
|
|
72
|
+
headers: { accept: source === "github" ? "application/vnd.github+json" : "application/json", "user-agent": `cavelon/${version}` },
|
|
73
|
+
redirect: "follow",
|
|
74
|
+
signal: AbortSignal.timeout(CHECK_TIMEOUT_MS),
|
|
75
|
+
});
|
|
76
|
+
if (!response.ok)
|
|
77
|
+
return undefined;
|
|
78
|
+
const length = Number(response.headers.get("content-length") ?? 0);
|
|
79
|
+
if (length > MAX_BODY)
|
|
80
|
+
return undefined;
|
|
81
|
+
const text = await response.text();
|
|
82
|
+
if (text.length > MAX_BODY)
|
|
83
|
+
return undefined;
|
|
84
|
+
const value = JSON.parse(text)[field];
|
|
85
|
+
if (typeof value !== "string")
|
|
86
|
+
return undefined;
|
|
87
|
+
const parsed = parseVersion(value);
|
|
88
|
+
return parsed && !parsed.pre ? parsed.text : undefined;
|
|
89
|
+
}
|
|
90
|
+
export function parseVersion(value) {
|
|
91
|
+
let text = value.trim();
|
|
92
|
+
if (text.startsWith("v"))
|
|
93
|
+
text = text.slice(1);
|
|
94
|
+
const dash = text.indexOf("-");
|
|
95
|
+
const pre = dash < 0 ? undefined : text.slice(dash + 1);
|
|
96
|
+
const match = /^(\d{1,9})\.(\d{1,9})\.(\d{1,9})$/.exec(dash < 0 ? text : text.slice(0, dash));
|
|
97
|
+
if (!match || (pre !== undefined && !/^[0-9A-Za-z.-]{1,64}$/.test(pre)))
|
|
98
|
+
return undefined;
|
|
99
|
+
const parts = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
100
|
+
return { parts, pre, text: `${parts.join(".")}${pre ? `-${pre}` : ""}` };
|
|
101
|
+
}
|
|
102
|
+
export function newer(candidate, current) {
|
|
103
|
+
const a = parseVersion(candidate);
|
|
104
|
+
const b = parseVersion(current);
|
|
105
|
+
if (!a || !b)
|
|
106
|
+
return false;
|
|
107
|
+
for (let i = 0; i < 3; i++) {
|
|
108
|
+
if (a.parts[i] !== b.parts[i])
|
|
109
|
+
return a.parts[i] > b.parts[i];
|
|
110
|
+
}
|
|
111
|
+
return !a.pre && b.pre !== undefined;
|
|
112
|
+
}
|
|
113
|
+
export function noticeText(latest, version, install) {
|
|
114
|
+
const head = `cavelon ${latest} is out; this is ${version}.`;
|
|
115
|
+
if (install.update)
|
|
116
|
+
return `${head} Update with:\n ${install.update}\n`;
|
|
117
|
+
return `${head}${install.advice ? ` ${install.advice}` : ""}\n`;
|
|
118
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { embeddedContent } from "./embedded.js";
|
|
4
5
|
function readVersion() {
|
|
5
6
|
const file = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "package.json");
|
|
6
7
|
try {
|
|
@@ -10,7 +11,7 @@ function readVersion() {
|
|
|
10
11
|
return "0.0.0";
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
export const KIT_VERSION = readVersion();
|
|
14
|
+
export const KIT_VERSION = embeddedContent()?.version ?? readVersion();
|
|
14
15
|
export const SUPPORTED_CONTRACTS = {
|
|
15
16
|
api_versions: ["v1"],
|
|
16
17
|
package_versions: ["v1", "v2", "v3"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cavelon/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"dist/",
|
|
18
|
+
"!dist/executable.js",
|
|
18
19
|
"README.md"
|
|
19
20
|
],
|
|
20
21
|
"engines": {
|
|
@@ -26,7 +27,9 @@
|
|
|
26
27
|
"lint": "eslint .",
|
|
27
28
|
"test": "vitest run",
|
|
28
29
|
"docs:commands": "vitest run test/commands-doc.test.ts --update",
|
|
29
|
-
"prepack": "npm run build"
|
|
30
|
+
"prepack": "npm run build",
|
|
31
|
+
"build:executable": "bun scripts/build-executable.mjs",
|
|
32
|
+
"test:executable": "vitest run test/executable.test.ts"
|
|
30
33
|
},
|
|
31
34
|
"dependencies": {
|
|
32
35
|
"@modelcontextprotocol/sdk": "^1.31.0",
|