@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
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/agents.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { usageError } from "./errors.js";
|
|
5
|
+
import { GENERATED_TOKEN } from "./markers.js";
|
|
6
|
+
import { KIT_VERSION } from "./version.js";
|
|
7
|
+
export const MCP_COMMAND = { command: "npx", args: ["-y", "@cavelon/cli@0.1", "mcp"] };
|
|
8
|
+
export function mcpCommand(platform = process.platform) {
|
|
9
|
+
return platform === "win32" ? { command: "cmd", args: ["/c", MCP_COMMAND.command, ...MCP_COMMAND.args] } : MCP_COMMAND;
|
|
10
|
+
}
|
|
11
|
+
const PLATFORMS = ["win32", "linux"];
|
|
12
|
+
const otherPlatforms = () => PLATFORMS.filter((p) => (p === "win32") !== (process.platform === "win32"));
|
|
13
|
+
const jsonServer = (file, key = "mcpServers", extra = {}) => ({
|
|
14
|
+
file,
|
|
15
|
+
format: "json",
|
|
16
|
+
keys: [key, "cavelon"],
|
|
17
|
+
entry: { ...extra, ...mcpCommand() },
|
|
18
|
+
others: otherPlatforms().map((p) => ({ ...extra, ...mcpCommand(p) })),
|
|
19
|
+
});
|
|
20
|
+
const tomlServer = (file) => {
|
|
21
|
+
const block = (platform) => {
|
|
22
|
+
const { command, args } = mcpCommand(platform);
|
|
23
|
+
return ["[mcp_servers.cavelon]", `command = "${command}"`, `args = [${args.map((a) => `"${a}"`).join(", ")}]`].join("\n");
|
|
24
|
+
};
|
|
25
|
+
return { file, format: "toml", block: block(process.platform), others: otherPlatforms().map(block) };
|
|
26
|
+
};
|
|
27
|
+
function agent(name, label, mcp) {
|
|
28
|
+
if (!mcp)
|
|
29
|
+
return { name, label };
|
|
30
|
+
return {
|
|
31
|
+
name,
|
|
32
|
+
label,
|
|
33
|
+
get mcp() {
|
|
34
|
+
return mcp();
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export const AGENTS = [
|
|
39
|
+
agent("claude", "Claude Code", () => jsonServer(".mcp.json")),
|
|
40
|
+
agent("codex", "Codex", () => tomlServer(".codex/config.toml")),
|
|
41
|
+
agent("cursor", "Cursor", () => jsonServer(".cursor/mcp.json")),
|
|
42
|
+
agent("copilot", "GitHub Copilot in VS Code", () => jsonServer(".vscode/mcp.json", "servers", { type: "stdio" })),
|
|
43
|
+
agent("gemini", "Gemini CLI", () => jsonServer(".gemini/settings.json")),
|
|
44
|
+
agent("kiro", "Kiro", () => jsonServer(".kiro/settings/mcp.json")),
|
|
45
|
+
agent("pi", "Pi"),
|
|
46
|
+
agent("other", "any other agent with a shell"),
|
|
47
|
+
];
|
|
48
|
+
const ALIASES = { "claude-code": "claude", vscode: "copilot", "gemini-cli": "gemini" };
|
|
49
|
+
export function parseAgents(values) {
|
|
50
|
+
const names = values.flatMap((v) => v.split(",")).map((v) => v.trim().toLowerCase()).filter(Boolean);
|
|
51
|
+
if (names.includes("all"))
|
|
52
|
+
return AGENTS;
|
|
53
|
+
const out = [];
|
|
54
|
+
for (const raw of names) {
|
|
55
|
+
const name = ALIASES[raw] ?? raw;
|
|
56
|
+
const target = AGENTS.find((a) => a.name === name);
|
|
57
|
+
if (!target)
|
|
58
|
+
throw usageError(`Unknown agent "${raw}".`, `Known: ${AGENTS.map((a) => a.name).join(", ")}, or all.`);
|
|
59
|
+
if (!out.includes(target))
|
|
60
|
+
out.push(target);
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
export const SKILL_ROOTS = [".agents/skills", ".claude/skills"];
|
|
65
|
+
export function skillsSource() {
|
|
66
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
67
|
+
return [path.join(here, "skills"), path.resolve(here, "..", "..", "plugin", "skills")];
|
|
68
|
+
}
|
|
69
|
+
export async function bundledSkills() {
|
|
70
|
+
for (const dir of skillsSource()) {
|
|
71
|
+
let entries;
|
|
72
|
+
try {
|
|
73
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
const skills = [];
|
|
79
|
+
for (const entry of entries.filter((e) => e.isDirectory()).sort((a, b) => a.name.localeCompare(b.name, "en"))) {
|
|
80
|
+
const files = [];
|
|
81
|
+
const walk = async (sub) => {
|
|
82
|
+
for (const item of await fs.readdir(path.join(dir, entry.name, sub), { withFileTypes: true })) {
|
|
83
|
+
const relative = sub ? `${sub}/${item.name}` : item.name;
|
|
84
|
+
if (item.isDirectory())
|
|
85
|
+
await walk(relative);
|
|
86
|
+
else if (item.isFile())
|
|
87
|
+
files.push({ path: relative, content: (await fs.readFile(path.join(dir, entry.name, relative), "utf8")).replace(/\r\n/g, "\n") });
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
await walk("");
|
|
91
|
+
if (files.some((f) => f.path === "SKILL.md"))
|
|
92
|
+
skills.push({ name: entry.name, files: files.sort((a, b) => a.path.localeCompare(b.path, "en")) });
|
|
93
|
+
}
|
|
94
|
+
if (skills.length)
|
|
95
|
+
return skills;
|
|
96
|
+
}
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
export function generatedCopy(file) {
|
|
100
|
+
if (!file.path.endsWith(".md"))
|
|
101
|
+
return file.content;
|
|
102
|
+
const mark = `<!-- ${GENERATED_TOKEN}: written by \`cavelon init --agents\` (cavelon ${KIT_VERSION}); \`cavelon init --update\` replaces this file. Put your own notes in another file. -->`;
|
|
103
|
+
const front = /^---\r?\n[\s\S]*?\r?\n---\r?\n/.exec(file.content);
|
|
104
|
+
if (front)
|
|
105
|
+
return `${front[0]}${mark}\n${file.content.slice(front[0].length)}`;
|
|
106
|
+
return `${mark}\n${file.content}`;
|
|
107
|
+
}
|
package/dist/branches.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isOperatorChange } from "./limits.js";
|
|
2
|
+
export const BRANCH_WIDTH_KEY = "orchestration_max_branch_concurrency";
|
|
3
|
+
export const BRANCH_PROCESS_KEY = "orchestration_process_max_branch_inflight";
|
|
4
|
+
export const PARALLEL_BRANCHES_KEY = "orchestration_parallel_branches";
|
|
5
|
+
export const BRANCH_KEYS = [BRANCH_WIDTH_KEY, BRANCH_PROCESS_KEY, PARALLEL_BRANCHES_KEY];
|
|
6
|
+
export function branchConcurrency(published, values) {
|
|
7
|
+
if (!published?.published)
|
|
8
|
+
return undefined;
|
|
9
|
+
const pick = (key) => (values ?? published.values).find((v) => v.key === key);
|
|
10
|
+
const width = pick(BRANCH_WIDTH_KEY);
|
|
11
|
+
const process = pick(BRANCH_PROCESS_KEY);
|
|
12
|
+
const parallel = pick(PARALLEL_BRANCHES_KEY);
|
|
13
|
+
if (!width && !process && !parallel)
|
|
14
|
+
return undefined;
|
|
15
|
+
const switches = parallel?.switches ?? [];
|
|
16
|
+
return {
|
|
17
|
+
width: typeof width?.value === "number" ? width.value : null,
|
|
18
|
+
width_setting: width?.setting ?? null,
|
|
19
|
+
process_ceiling: typeof process?.value === "number" ? process.value : null,
|
|
20
|
+
process_setting: process?.setting ?? null,
|
|
21
|
+
parallel: typeof parallel?.value === "boolean" ? parallel.value : null,
|
|
22
|
+
deciding_setting: parallel?.setting ?? null,
|
|
23
|
+
switches,
|
|
24
|
+
off: switches.filter((s) => !s.enabled).map((s) => s.setting),
|
|
25
|
+
change: parallel?.change ?? null,
|
|
26
|
+
docs: (parallel ?? width ?? process)?.docs || null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function switchOnText(item, change) {
|
|
30
|
+
if (item.source !== "tenant")
|
|
31
|
+
return `the instance operator turns it on with ${item.setting} (a deploy)`;
|
|
32
|
+
if (change && isOperatorChange(change)) {
|
|
33
|
+
return (`an operator turns it on in the Admin (Configure › Feature Flags), or with cavelon limits set ${PARALLEL_BRANCHES_KEY} on ` +
|
|
34
|
+
"--tenant <tenant> --confirm and a Platform-mode token");
|
|
35
|
+
}
|
|
36
|
+
if (change)
|
|
37
|
+
return `a tenant admin turns it on with cavelon limits set ${PARALLEL_BRANCHES_KEY} on --confirm`;
|
|
38
|
+
return "the instance operator turns it on for this tenant in the Admin (Configure › Feature Flags)";
|
|
39
|
+
}
|
|
40
|
+
export function offText(branches) {
|
|
41
|
+
const off = branches.switches.filter((s) => !s.enabled);
|
|
42
|
+
if (!off.length)
|
|
43
|
+
return branches.deciding_setting ? `${branches.deciding_setting} is off` : "a switch is off";
|
|
44
|
+
return off.map((s) => `${s.setting} is off (${switchOnText(s, branches.change)})`).join("; ");
|
|
45
|
+
}
|
|
46
|
+
export function branchConcurrencyText(branches) {
|
|
47
|
+
const lines = [];
|
|
48
|
+
if (branches.width !== null)
|
|
49
|
+
lines.push(` width per node: ${branches.width} (${branches.width_setting}); a node's max_concurrency above it is capped`);
|
|
50
|
+
if (branches.process_ceiling !== null) {
|
|
51
|
+
lines.push(` per process: ${branches.process_ceiling} (${branches.process_setting}), shared by every run in one worker or API process`);
|
|
52
|
+
}
|
|
53
|
+
if (branches.parallel === true) {
|
|
54
|
+
const named = branches.switches.length ? ` (${branches.switches.map((s) => s.setting).join(" and ")} are on)` : "";
|
|
55
|
+
lines.push(` concurrent: yes${named}`);
|
|
56
|
+
}
|
|
57
|
+
else if (branches.parallel === false) {
|
|
58
|
+
lines.push(` concurrent: no, fan-outs and Map loops run one branch after another (same result, slower): ${offText(branches)}`);
|
|
59
|
+
}
|
|
60
|
+
return lines.join("\n");
|
|
61
|
+
}
|
package/dist/capacity.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { changedBy, formatValue, readLimits } from "./limits.js";
|
|
2
|
+
export const CAPACITY_WAIT_AFTER_MS = 30_000;
|
|
3
|
+
export const RUN_CAPACITY_BUSY = "run_capacity_busy";
|
|
4
|
+
export const MODEL_ENDPOINT_BUSY = "model_endpoint_busy";
|
|
5
|
+
export const CAPACITY_CODES = [RUN_CAPACITY_BUSY, MODEL_ENDPOINT_BUSY];
|
|
6
|
+
export const RUN_CAP_KEYS = ["max_concurrent_agent_runs_per_tenant", "max_concurrent_agent_runs_global"];
|
|
7
|
+
export const RUN_SLOT_WAIT_KEY = "agent_run_slot_wait_seconds";
|
|
8
|
+
export const ENDPOINT_SLOT_WAIT_KEY = "model_endpoint_slot_wait_seconds";
|
|
9
|
+
export const CAPACITY_KEYS = [...RUN_CAP_KEYS, RUN_SLOT_WAIT_KEY, ENDPOINT_SLOT_WAIT_KEY];
|
|
10
|
+
const TENANT_LIMITS_ROUTE = "PATCH /api/v1/tenants/{tenant_id}/limits";
|
|
11
|
+
const PLATFORM_CAPS_ROUTE = "/api/v1/platform-settings/runs/capacity";
|
|
12
|
+
export const CAPACITY_CONCEPT_PAGE = "concepts/capacity-and-concurrency";
|
|
13
|
+
export const CAPACITY_TUTORIAL_PAGE = "tutorials/plan-model-capacity";
|
|
14
|
+
export const CAPACITY_PAGES = [CAPACITY_CONCEPT_PAGE, CAPACITY_TUTORIAL_PAGE];
|
|
15
|
+
const NOT_STARTED = new Set(["queued", "pending"]);
|
|
16
|
+
export function originText(limit) {
|
|
17
|
+
switch (limit.origin) {
|
|
18
|
+
case "platform_setting":
|
|
19
|
+
return `a platform setting, changed in the Admin (Platform › Operations › Rate limits) or at ${PLATFORM_CAPS_ROUTE}`;
|
|
20
|
+
case "environment":
|
|
21
|
+
return `the environment variable ${limit.setting} (a deploy), until a platform setting replaces it in the Admin`;
|
|
22
|
+
case "default":
|
|
23
|
+
return `the built-in default; the operator sets it in the Admin (Platform › Operations › Rate limits) or with ${limit.setting}`;
|
|
24
|
+
default:
|
|
25
|
+
return limit.origin ? `origin ${limit.origin}` : undefined;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function capText(limit) {
|
|
29
|
+
const value = formatValue(limit);
|
|
30
|
+
if (limit.source === "tenant") {
|
|
31
|
+
return `${limit.key} is ${value}, this tenant's own cap (${limit.setting}; ${changedBy(limit)} changes it with ${TENANT_LIMITS_ROUTE})`;
|
|
32
|
+
}
|
|
33
|
+
const where = originText(limit) ?? `${limit.setting} (source: ${limit.source})`;
|
|
34
|
+
return `${limit.key} is ${value}, set by ${where}; ${changedBy(limit)} changes it`;
|
|
35
|
+
}
|
|
36
|
+
export function runCaps(limits) {
|
|
37
|
+
return RUN_CAP_KEYS.map((key) => limits?.byKey.get(key)).filter((l) => Boolean(l));
|
|
38
|
+
}
|
|
39
|
+
export function capacityLimits(limits) {
|
|
40
|
+
return CAPACITY_KEYS.map((key) => limits?.byKey.get(key)).filter((l) => Boolean(l));
|
|
41
|
+
}
|
|
42
|
+
function sinceMs(createdAt, now) {
|
|
43
|
+
if (!createdAt)
|
|
44
|
+
return undefined;
|
|
45
|
+
const created = Date.parse(createdAt);
|
|
46
|
+
if (Number.isNaN(created))
|
|
47
|
+
return undefined;
|
|
48
|
+
return Math.max(0, now.getTime() - created);
|
|
49
|
+
}
|
|
50
|
+
export function queuedForMs(status, createdAt, now) {
|
|
51
|
+
if (!status || !NOT_STARTED.has(status))
|
|
52
|
+
return undefined;
|
|
53
|
+
return sinceMs(createdAt, now);
|
|
54
|
+
}
|
|
55
|
+
export function publishedWait(run) {
|
|
56
|
+
return typeof run.waiting_for_capacity === "boolean" ? run.waiting_for_capacity : undefined;
|
|
57
|
+
}
|
|
58
|
+
export function waitsForCapacity(run, now) {
|
|
59
|
+
const published = publishedWait(run);
|
|
60
|
+
if (published !== undefined)
|
|
61
|
+
return published;
|
|
62
|
+
const queued = queuedForMs(run.status, run.created_at, now);
|
|
63
|
+
return queued !== undefined && queued >= CAPACITY_WAIT_AFTER_MS;
|
|
64
|
+
}
|
|
65
|
+
export function capacityWait(run, now, limits) {
|
|
66
|
+
if (!waitsForCapacity(run, now))
|
|
67
|
+
return undefined;
|
|
68
|
+
const inferred = publishedWait(run) === undefined;
|
|
69
|
+
const queued = sinceMs(run.created_at, now);
|
|
70
|
+
const seconds = queued === undefined ? null : Math.round(queued / 1000);
|
|
71
|
+
const caps = runCaps(limits);
|
|
72
|
+
const named = caps.length ? ` ${caps.map(capText).join("; ")}.` : "";
|
|
73
|
+
return {
|
|
74
|
+
waiting_for: "run_capacity",
|
|
75
|
+
inferred,
|
|
76
|
+
queued_seconds: seconds,
|
|
77
|
+
caps: caps.map((l) => ({ key: l.key, value: l.value, source: l.source, origin: l.origin ?? null, setting: l.setting, changeable_by: l.changeable_by })),
|
|
78
|
+
note: `waiting for run capacity${seconds === null ? "" : ` (queued ${seconds} s)`}: every run slot is in use, and the instance starts it once one frees; it is not stuck.${named}`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function capacityCodeIn(...texts) {
|
|
82
|
+
return CAPACITY_CODES.find((code) => texts.some((text) => typeof text === "string" && text.includes(code)));
|
|
83
|
+
}
|
|
84
|
+
export function capacityHint(code, limits) {
|
|
85
|
+
if (code === RUN_CAPACITY_BUSY) {
|
|
86
|
+
const caps = runCaps(limits);
|
|
87
|
+
const now = caps.length ? ` Now: ${caps.map(capText).join("; ")}.` : "";
|
|
88
|
+
const kit = caps.some((c) => c.change?.requires_role?.length)
|
|
89
|
+
? ` With a Platform-mode personal access token, the operator runs cavelon limits set max_concurrent_agent_runs_per_tenant <n> --tenant <tenant> --confirm.`
|
|
90
|
+
: "";
|
|
91
|
+
return ("Retrying later is fine; a trigger or channel run waits for a free slot on its own. " +
|
|
92
|
+
"To run more at once, the instance operator raises max_concurrent_agent_runs_per_tenant: for this tenant alone " +
|
|
93
|
+
`with ${TENANT_LIMITS_ROUTE} (limits.manage), or for every tenant as a platform setting in the Admin ` +
|
|
94
|
+
`(Platform › Operations › Rate limits); max_concurrent_agent_runs_global caps the whole instance.${kit}${now}`);
|
|
95
|
+
}
|
|
96
|
+
const wait = limits?.byKey.get(ENDPOINT_SLOT_WAIT_KEY);
|
|
97
|
+
const waited = wait ? ` (${ENDPOINT_SLOT_WAIT_KEY} is ${formatValue(wait)}; ${changedBy(wait)} changes it with ${wait.setting})` : "";
|
|
98
|
+
return (`Retrying later is fine. The model endpoint was serving its max_concurrent_requests and no slot freed in time${waited}. ` +
|
|
99
|
+
"If the endpoint can serve more at once, a tenant admin raises max_concurrent_requests on its Model Registry row " +
|
|
100
|
+
"(cavelon models set-limit <model_id> <n>, the Admin's model form, or PATCH /api/v1/model-registry/{model_registry_id}); " +
|
|
101
|
+
"every row with the same base_url shares that count.");
|
|
102
|
+
}
|
|
103
|
+
function readLinkedRun(client, op) {
|
|
104
|
+
const href = op.result_ref?.type === "agent_run" ? op.result_ref.href : undefined;
|
|
105
|
+
if (!href)
|
|
106
|
+
return Promise.resolve(undefined);
|
|
107
|
+
return client
|
|
108
|
+
.get(href, { allow: [403, 404] })
|
|
109
|
+
.then((response) => (response.status === 200 && response.data && typeof response.data === "object" ? response.data : undefined))
|
|
110
|
+
.catch(() => undefined);
|
|
111
|
+
}
|
|
112
|
+
export function capacityNotes(ctx, client, known) {
|
|
113
|
+
let limits = known ? Promise.resolve(known) : undefined;
|
|
114
|
+
const published = () => (limits ??= readLimits(ctx).catch(() => undefined));
|
|
115
|
+
const failures = new Map();
|
|
116
|
+
const failureCode = (op) => {
|
|
117
|
+
const own = capacityCodeIn(op.error?.code, op.error?.message);
|
|
118
|
+
const href = op.result_ref?.type === "agent_run" ? op.result_ref.href : undefined;
|
|
119
|
+
if (own || !href)
|
|
120
|
+
return Promise.resolve(own);
|
|
121
|
+
let code = failures.get(op.id);
|
|
122
|
+
if (!code) {
|
|
123
|
+
code = client
|
|
124
|
+
.get(href, { allow: [403, 404] })
|
|
125
|
+
.then((response) => (response.status === 200 ? capacityCodeIn(response.data?.error_summary) : undefined))
|
|
126
|
+
.catch(() => undefined);
|
|
127
|
+
failures.set(op.id, code);
|
|
128
|
+
}
|
|
129
|
+
return code;
|
|
130
|
+
};
|
|
131
|
+
return async function note(op) {
|
|
132
|
+
if (op.status === "failed") {
|
|
133
|
+
const code = await failureCode(op);
|
|
134
|
+
return code ? { capacity_refusal: { code, hint: capacityHint(code, await published()) } } : undefined;
|
|
135
|
+
}
|
|
136
|
+
if (op.result_ref?.type !== "agent_run" || !NOT_STARTED.has(op.status))
|
|
137
|
+
return undefined;
|
|
138
|
+
const run = await readLinkedRun(client, op);
|
|
139
|
+
const state = { status: op.status, created_at: op.created_at ?? run?.created_at, waiting_for_capacity: run?.waiting_for_capacity };
|
|
140
|
+
if (!waitsForCapacity(state, ctx.io.now()))
|
|
141
|
+
return undefined;
|
|
142
|
+
const wait = capacityWait(state, ctx.io.now(), await published());
|
|
143
|
+
return wait ? { capacity_wait: wait } : undefined;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
export async function runCapacityNote(ctx, run) {
|
|
147
|
+
const code = run.status === "failed" ? capacityCodeIn(run.error_summary) : undefined;
|
|
148
|
+
if (!code && !waitsForCapacity(run, ctx.io.now()))
|
|
149
|
+
return undefined;
|
|
150
|
+
const limits = await readLimits(ctx).catch(() => undefined);
|
|
151
|
+
if (code)
|
|
152
|
+
return { capacity_refusal: { code, hint: capacityHint(code, limits) } };
|
|
153
|
+
const wait = capacityWait(run, ctx.io.now(), limits);
|
|
154
|
+
return wait ? { capacity_wait: wait } : undefined;
|
|
155
|
+
}
|
|
156
|
+
export function noteLines(note) {
|
|
157
|
+
if (note?.capacity_wait)
|
|
158
|
+
return `\n ${note.capacity_wait.note}`;
|
|
159
|
+
if (note?.capacity_refusal)
|
|
160
|
+
return `\n ${note.capacity_refusal.code}: ${note.capacity_refusal.hint}`;
|
|
161
|
+
return "";
|
|
162
|
+
}
|
package/dist/cli.js
ADDED
package/dist/command.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { usageError } from "./errors.js";
|
|
2
|
+
export const GLOBAL_OPTIONS = {
|
|
3
|
+
json: { type: "boolean", description: "Print one JSON document instead of text." },
|
|
4
|
+
instance: { type: "string", value: "<url>", description: "The instance URL (overrides CAVELON_URL and cavelon.yaml)." },
|
|
5
|
+
tenant: { type: "string", value: "<tenant>", description: "Tenant slug, name or id (overrides CAVELON_TENANT and cavelon.yaml)." },
|
|
6
|
+
help: { type: "boolean", short: "h", description: "Show help for the command." },
|
|
7
|
+
};
|
|
8
|
+
export function stringOption(input, name) {
|
|
9
|
+
const value = input.options[name];
|
|
10
|
+
if (Array.isArray(value))
|
|
11
|
+
return value[value.length - 1];
|
|
12
|
+
return typeof value === "string" ? value : undefined;
|
|
13
|
+
}
|
|
14
|
+
export function listOption(input, name) {
|
|
15
|
+
const value = input.options[name];
|
|
16
|
+
if (Array.isArray(value))
|
|
17
|
+
return value;
|
|
18
|
+
return typeof value === "string" ? [value] : [];
|
|
19
|
+
}
|
|
20
|
+
export function boolOption(input, name) {
|
|
21
|
+
return input.options[name] === true;
|
|
22
|
+
}
|
|
23
|
+
export function positional(input, name) {
|
|
24
|
+
const value = input.positionals[name];
|
|
25
|
+
return Array.isArray(value) ? value[0] : value;
|
|
26
|
+
}
|
|
27
|
+
export function intOption(input, name, bounds = {}) {
|
|
28
|
+
const raw = stringOption(input, name);
|
|
29
|
+
if (raw === undefined)
|
|
30
|
+
return bounds.fallback;
|
|
31
|
+
const value = Number(raw);
|
|
32
|
+
if (!Number.isInteger(value))
|
|
33
|
+
throw usageError(`--${name} must be a whole number, got "${raw}".`);
|
|
34
|
+
if (bounds.min !== undefined && value < bounds.min)
|
|
35
|
+
throw usageError(`--${name} must be at least ${bounds.min}.`);
|
|
36
|
+
if (bounds.max !== undefined && value > bounds.max)
|
|
37
|
+
throw usageError(`--${name} must be at most ${bounds.max}.`);
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
export function parseDuration(raw, name = "timeout") {
|
|
41
|
+
const match = /^(\d+(?:\.\d+)?)(ms|s|m|h)?$/.exec(raw.trim());
|
|
42
|
+
if (!match)
|
|
43
|
+
throw usageError(`--${name} must be a duration such as 90s, 5m or 1h, got "${raw}".`);
|
|
44
|
+
const value = Number(match[1]);
|
|
45
|
+
const unit = match[2] ?? "s";
|
|
46
|
+
const factor = unit === "ms" ? 1 : unit === "s" ? 1000 : unit === "m" ? 60_000 : 3_600_000;
|
|
47
|
+
return Math.round(value * factor);
|
|
48
|
+
}
|
|
49
|
+
export const LIMIT_OPTION = { type: "string", value: "<n>", description: "Return at most n items." };
|
|
50
|
+
export const CURSOR_OPTION = {
|
|
51
|
+
type: "string",
|
|
52
|
+
value: "<cursor>",
|
|
53
|
+
description: "Continue after the previous page (its next_cursor).",
|
|
54
|
+
};
|
|
55
|
+
export function pageOf(items, limit, cursor) {
|
|
56
|
+
const offset = cursor === undefined ? 0 : Number(cursor);
|
|
57
|
+
if (!Number.isInteger(offset) || offset < 0)
|
|
58
|
+
throw usageError(`--cursor "${cursor}" is not a cursor from a previous page.`);
|
|
59
|
+
const slice = items.slice(offset, offset + limit);
|
|
60
|
+
const next = offset + limit < items.length ? String(offset + limit) : null;
|
|
61
|
+
return { items: slice, next_cursor: next, total: items.length };
|
|
62
|
+
}
|