@cavelon/cli 0.0.0 → 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 +713 -3
- package/dist/LICENSE +201 -0
- package/dist/agents.js +107 -0
- package/dist/branches.js +61 -0
- package/dist/capacity.js +162 -0
- package/dist/cli.js +4 -0
- package/dist/command.js +62 -0
- package/dist/commands/api.js +313 -0
- package/dist/commands/async.js +207 -0
- package/dist/commands/docs.js +158 -0
- package/dist/commands/index.js +112 -0
- package/dist/commands/init.js +481 -0
- package/dist/commands/inventory.js +56 -0
- package/dist/commands/limits-set.js +633 -0
- package/dist/commands/limits.js +156 -0
- package/dist/commands/loops.js +798 -0
- package/dist/commands/models.js +197 -0
- package/dist/commands/sandboxes.js +674 -0
- package/dist/commands/session.js +480 -0
- package/dist/commands/solution.js +830 -0
- package/dist/commands/tenants.js +266 -0
- package/dist/commands/values.js +386 -0
- package/dist/commands/work.js +761 -0
- package/dist/context.js +60 -0
- package/dist/contracts.js +234 -0
- package/dist/credentials.js +134 -0
- package/dist/errors.js +64 -0
- package/dist/features.js +52 -0
- package/dist/format.js +36 -0
- package/dist/fsutil.js +43 -0
- package/dist/git.js +41 -0
- package/dist/http.js +304 -0
- package/dist/invoke.js +165 -0
- package/dist/io.js +49 -0
- package/dist/limits.js +307 -0
- package/dist/local-state.js +78 -0
- package/dist/main.js +227 -0
- package/dist/markers.js +113 -0
- package/dist/mcp.js +137 -0
- package/dist/openapi.js +233 -0
- package/dist/operations.js +107 -0
- package/dist/package-check.js +342 -0
- package/dist/package-files.js +394 -0
- package/dist/pair-order.js +39 -0
- package/dist/paths.js +77 -0
- package/dist/principal.js +33 -0
- package/dist/project.js +157 -0
- package/dist/prompt.js +34 -0
- package/dist/results.js +104 -0
- package/dist/session.js +190 -0
- package/dist/shell.js +41 -0
- package/dist/skills/cavelon-authoring/SKILL.md +224 -0
- package/dist/skills/cavelon-long-running/SKILL.md +185 -0
- package/dist/skills/cavelon-loop/SKILL.md +159 -0
- package/dist/skills/cavelon-testing/SKILL.md +97 -0
- package/dist/sse.js +44 -0
- package/dist/tar.js +172 -0
- package/dist/user-config.js +36 -0
- package/dist/version.js +17 -0
- package/dist/zip.js +132 -0
- package/package.json +40 -4
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { capText, RUN_CAP_KEYS } from "../capacity.js";
|
|
2
|
+
import { listOption, stringOption } from "../command.js";
|
|
3
|
+
import { CavelonError, ExitCode } from "../errors.js";
|
|
4
|
+
import { table } from "../format.js";
|
|
5
|
+
import { branchConcurrency, branchConcurrencyText } from "../branches.js";
|
|
6
|
+
import { bindsNow, bindsWhenText, changedBy, docsPage, formatQuota, formatQuotaValue, formatValue, isOperatorChange, readLimits, readQuotas, } from "../limits.js";
|
|
7
|
+
const SOURCE_ORDER = ["tenant", "platform", "licence"];
|
|
8
|
+
const SOURCE_TITLE = {
|
|
9
|
+
tenant: "Set by this tenant (its own settings)",
|
|
10
|
+
platform: "Set by the instance (its operator's settings)",
|
|
11
|
+
licence: "Set by the instance's licence",
|
|
12
|
+
};
|
|
13
|
+
function groupBySource(values) {
|
|
14
|
+
const sources = [...new Set(values.map((v) => v.source))].sort((a, b) => {
|
|
15
|
+
const rank = (s) => (SOURCE_ORDER.includes(s) ? SOURCE_ORDER.indexOf(s) : SOURCE_ORDER.length);
|
|
16
|
+
return rank(a) - rank(b) || a.localeCompare(b);
|
|
17
|
+
});
|
|
18
|
+
return sources.map((source) => ({ source, limits: values.filter((v) => v.source === source) }));
|
|
19
|
+
}
|
|
20
|
+
function quotaValueClose(quota) {
|
|
21
|
+
if (quota.state === "reached")
|
|
22
|
+
return "cap reached";
|
|
23
|
+
return quota.near ? "close to the cap" : "";
|
|
24
|
+
}
|
|
25
|
+
function periodText(quota) {
|
|
26
|
+
return quota.period ? ` in ${quota.period.key}` : "";
|
|
27
|
+
}
|
|
28
|
+
function quotaUse(quota) {
|
|
29
|
+
if (quota.current !== null || quota.limit !== null)
|
|
30
|
+
return formatQuota(quota);
|
|
31
|
+
const numbers = Object.entries(quota.details).filter(([, v]) => typeof v === "number");
|
|
32
|
+
return numbers.length ? numbers.map(([k, v]) => `${k} ${String(v)}`).join(", ") : "-";
|
|
33
|
+
}
|
|
34
|
+
export const limits = {
|
|
35
|
+
name: "limits",
|
|
36
|
+
summary: "Show the instance's limits for this tenant, who can change each, and the tenant's quotas with their use.",
|
|
37
|
+
description: "Read them before planning a solution: upload sizes and file types, run and tool limits, timeouts, rate limits, licence caps.\n" +
|
|
38
|
+
"Grouped by source (tenant, platform, licence); each names who changes it (a tenant admin or the operator) and the setting.\n" +
|
|
39
|
+
"A run cap also names its origin when the instance says: a platform setting (the Admin), the environment or the default.\n" +
|
|
40
|
+
"A limit that binds only while another is on says so (the archive caps apply while archive uploads are on).\n" +
|
|
41
|
+
"Branch concurrency: the width per node, the ceiling per process, and whether branches run concurrently (and which switch is off).\n" +
|
|
42
|
+
"The tenant quotas include the monthly Processing Step cap with this billing month's use, where the instance publishes it.\n" +
|
|
43
|
+
"A limit the instance does not list does not bind there. An instance older than the published limits lists none.",
|
|
44
|
+
readOnly: true,
|
|
45
|
+
idempotent: true,
|
|
46
|
+
mcpTool: "limits",
|
|
47
|
+
options: {
|
|
48
|
+
key: { type: "string", multiple: true, value: "<key>", description: "Only these limits (e.g. kb_upload_max_file_size_mb)." },
|
|
49
|
+
source: { type: "string", value: "<source>", description: "Only limits from this source: tenant, platform or licence." },
|
|
50
|
+
},
|
|
51
|
+
examples: ["cavelon limits", "cavelon limits --key kb_upload_max_file_size_mb --json", "cavelon limits --source tenant"],
|
|
52
|
+
async run(ctx, input) {
|
|
53
|
+
const contracts = await ctx.contracts();
|
|
54
|
+
const published = await readLimits(ctx);
|
|
55
|
+
if (contracts.needsTenant) {
|
|
56
|
+
throw new CavelonError(ExitCode.usage, {
|
|
57
|
+
code: "tenant_required",
|
|
58
|
+
message: "Limits belong to a tenant, and none is chosen.",
|
|
59
|
+
hint: "Choose one with `cavelon use <tenant>` or pass --tenant.",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (!published.published) {
|
|
63
|
+
ctx.warn("This instance does not publish its limits (it is older than the limits in /api/v1/meta/capabilities); none is assumed.");
|
|
64
|
+
return {
|
|
65
|
+
data: { published: false, groups: [], tenant_quotas: null, quota_values: [], near: [], branch_concurrency: null },
|
|
66
|
+
text: "This instance does not publish its limits. Commands send as they are, and the instance answers for itself.",
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const keys = listOption(input, "key").flatMap((k) => k.split(",")).map((k) => k.trim()).filter(Boolean);
|
|
70
|
+
const source = stringOption(input, "source");
|
|
71
|
+
const values = published.values.filter((v) => (!keys.length || keys.includes(v.key)) && (!source || v.source === source));
|
|
72
|
+
const unknown = keys.filter((k) => !published.byKey.has(k));
|
|
73
|
+
if (unknown.length)
|
|
74
|
+
ctx.warn(`This instance lists no limit ${unknown.join(", ")}; it does not bind here.`);
|
|
75
|
+
const groups = groupBySource(values);
|
|
76
|
+
const quotas = keys.length || source ? undefined : await readQuotas(ctx, published);
|
|
77
|
+
const quotaValues = keys.length || source ? [] : (published.tenantQuotas?.values ?? []);
|
|
78
|
+
const near = [
|
|
79
|
+
...(quotas?.items.filter((q) => q.near) ?? []).map((q) => ({ key: q.key, current: q.current, limit: q.limit, ratio: q.ratio, text: `${q.key} ${formatQuota(q)}` })),
|
|
80
|
+
...quotaValues
|
|
81
|
+
.filter((q) => q.near)
|
|
82
|
+
.map((q) => ({ key: q.key, current: q.used, limit: q.value, ratio: q.ratio, text: `${q.key} ${formatQuotaValue(q)}${q.period ? `, resets ${q.period.resets_at}` : ""}` })),
|
|
83
|
+
];
|
|
84
|
+
const branches = branchConcurrency(published, values);
|
|
85
|
+
let text = groups
|
|
86
|
+
.map(({ source: s, limits: list }) => {
|
|
87
|
+
const rows = list.map((l) => ({
|
|
88
|
+
key: l.key,
|
|
89
|
+
value: formatValue(l),
|
|
90
|
+
changed_by: changedBy(l),
|
|
91
|
+
origin: l.origin ?? "",
|
|
92
|
+
setting: l.setting,
|
|
93
|
+
docs: l.docs,
|
|
94
|
+
}));
|
|
95
|
+
const columns = list.some((l) => l.origin) ? ["key", "value", "changed_by", "origin", "setting", "docs"] : ["key", "value", "changed_by", "setting", "docs"];
|
|
96
|
+
return `${SOURCE_TITLE[s] ?? `Source: ${s}`}:\n${table(rows, columns, 80)}`;
|
|
97
|
+
})
|
|
98
|
+
.join("\n\n");
|
|
99
|
+
const caps = values.filter((v) => v.origin || (v.source === "tenant" && RUN_CAP_KEYS.includes(v.key)));
|
|
100
|
+
if (caps.length)
|
|
101
|
+
text += `\n\nWhere the run caps are set:\n${caps.map((l) => ` ${capText(l)}`).join("\n")}`;
|
|
102
|
+
const conditional = values.filter((v) => v.binds_when);
|
|
103
|
+
if (conditional.length) {
|
|
104
|
+
const lines = conditional.map((l) => ` ${l.key} ${bindsWhenText(l)}${bindsNow(l, published) ? "" : `; ${l.binds_when} is off, so it does not bind now`}`);
|
|
105
|
+
text += `\n\nOnly while another limit is on:\n${lines.join("\n")}`;
|
|
106
|
+
}
|
|
107
|
+
if (branches)
|
|
108
|
+
text += `\n\nBranch concurrency (fan-outs and Map loops):\n${branchConcurrencyText(branches)}`;
|
|
109
|
+
if (!groups.length)
|
|
110
|
+
text = keys.length || source ? "No published limit matches." : "This instance publishes no binding limit.";
|
|
111
|
+
if (quotas || quotaValues.length) {
|
|
112
|
+
const rows = [
|
|
113
|
+
...(quotas?.items ?? []).map((q) => ({ quota: q.key, use: quotaUse(q), state: typeof q.details.state === "string" ? q.details.state : "", close: q.near ? "close to the quota" : "" })),
|
|
114
|
+
...quotaValues.map((q) => ({ quota: q.key, use: `${formatQuotaValue(q)}${periodText(q)}`, state: q.state, close: quotaValueClose(q) })),
|
|
115
|
+
];
|
|
116
|
+
text += `\n\nTenant quotas (${quotas?.path ?? published.tenantQuotas.path}):\n`;
|
|
117
|
+
if (quotas?.unavailable)
|
|
118
|
+
text += ` not readable: ${quotas.unavailable}${rows.length ? "\n" : ""}`;
|
|
119
|
+
if (rows.length || !quotas?.unavailable)
|
|
120
|
+
text += table(rows, ["quota", "use", "state", "close"]) || " none";
|
|
121
|
+
}
|
|
122
|
+
if (near.length)
|
|
123
|
+
text += `\n\nClose to a quota: ${near.map((q) => q.text).join("; ")}`;
|
|
124
|
+
const quotaChanges = keys.length || source ? [] : (published.tenantQuotas?.changes ?? []);
|
|
125
|
+
const tenantChangeable = [...values.filter((v) => v.change && !isOperatorChange(v.change)).map((v) => v.key), ...quotaChanges.filter((c) => !isOperatorChange(c)).map((c) => c.key)];
|
|
126
|
+
const operatorChangeable = values.filter((v) => [v.change, v.tenant_change].some((c) => c && isOperatorChange(c))).map((v) => v.key);
|
|
127
|
+
if (tenantChangeable.length) {
|
|
128
|
+
const owner = quotaValues.filter((q) => q.changeable_by === "tenant_owner" && tenantChangeable.includes(q.key)).map((q) => q.key);
|
|
129
|
+
text += `\n\nA tenant admin changes ${tenantChangeable.length === 1 ? "it" : "these"} with: cavelon limits set <key> <value> (shows the change; --confirm sends it)`;
|
|
130
|
+
if (owner.length)
|
|
131
|
+
text += `; ${owner.join(", ")} only a Tenant Owner (settings.manage)`;
|
|
132
|
+
}
|
|
133
|
+
if (operatorChangeable.length) {
|
|
134
|
+
text += `\n\nAn operator changes ${operatorChangeable.join(", ")} with the same command and a personal access token in Platform mode of the role the change names; --tenant <id|slug> sets the tenant (one tenant's own run cap, its flag).`;
|
|
135
|
+
}
|
|
136
|
+
const pages = [...new Set(values.map((v) => docsPage(v.docs)).filter(Boolean))];
|
|
137
|
+
if (pages.length)
|
|
138
|
+
text += `\n\nHow to change one: cavelon docs get <page> (${pages.join(", ")})`;
|
|
139
|
+
return {
|
|
140
|
+
data: {
|
|
141
|
+
published: true,
|
|
142
|
+
groups: groups.map(({ source: s, limits: list }) => ({
|
|
143
|
+
source: s,
|
|
144
|
+
limits: list.map((l) => (l.binds_when ? { ...l, binds_now: bindsNow(l, published) } : l)),
|
|
145
|
+
})),
|
|
146
|
+
tenant_quotas: quotas
|
|
147
|
+
? { path: quotas.path, docs: quotas.docs, items: quotas.items, ...(quotas.unavailable ? { unavailable: quotas.unavailable } : {}) }
|
|
148
|
+
: null,
|
|
149
|
+
quota_values: quotaValues.map(({ near: isNear, ratio, ...q }) => ({ ...q, ratio, near: isNear })),
|
|
150
|
+
near: near.map(({ text: _text, ...q }) => q),
|
|
151
|
+
branch_concurrency: branches ?? null,
|
|
152
|
+
},
|
|
153
|
+
text,
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
};
|