@cavelon/cli 0.1.16 → 0.1.17
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 +35 -4
- package/dist/agent-env.js +1 -0
- package/dist/agents.js +2 -0
- package/dist/commands/db.js +6 -2
- package/dist/commands/limits-set.js +11 -1
- package/dist/commands/limits.js +7 -1
- package/dist/commands/setup.js +3 -3
- package/dist/database-limits.js +46 -0
- package/dist/mcp-entry.js +3 -3
- package/dist/native-approval/kilo-server.js +33 -0
- package/dist/native-approval/kilo-tui.js +13 -0
- package/dist/native-approval/omp-extension.js +8 -0
- package/dist/native-approval/opencode-server.js +2 -2
- package/dist/native-approval/opencode-tui.js +2 -2
- package/dist/native-approval/pi-extension.js +5 -3
- package/dist/native-approval/profile.js +16 -9
- package/dist/native-assets/THIRD-PARTY-NOTICES +18 -0
- package/dist/native-assets/kilo-server.mjs +39719 -0
- package/dist/native-assets/kilo-tui.mjs +26477 -0
- package/dist/native-assets/manifest.json +31 -9
- package/dist/native-assets/omp-extension.mjs +30729 -0
- package/dist/native-assets/opencode-server.mjs +7541 -122
- package/dist/native-assets/opencode-tui.mjs +7531 -112
- package/dist/native-assets/pi-extension.mjs +7552 -128
- package/dist/native-clients.js +217 -1
- package/dist/native-install.js +41 -16
- package/dist/omp-config.js +85 -0
- package/dist/setup-agents.js +15 -6
- package/dist/yaml-config.js +215 -0
- package/package.json +1 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
import { isAlias, isMap, isNode, isPair, isScalar, parseDocument, visit } from "yaml";
|
|
3
|
+
function document(text) {
|
|
4
|
+
const doc = parseDocument(text, { keepSourceTokens: true, uniqueKeys: true });
|
|
5
|
+
if (doc.errors.length || doc.warnings.length)
|
|
6
|
+
return { error: "it has a YAML syntax error or unsupported tag" };
|
|
7
|
+
if (doc.contents !== null && !isMap(doc.contents))
|
|
8
|
+
return { error: "it is not a YAML mapping" };
|
|
9
|
+
let ambiguous = false;
|
|
10
|
+
visit(doc, (_key, node) => {
|
|
11
|
+
if (isAlias(node) || (isNode(node) && (node.anchor || node.tag)))
|
|
12
|
+
ambiguous = true;
|
|
13
|
+
if (isPair(node) && (!isScalar(node.key) || typeof node.key.value !== "string" || node.key.value === "<<"))
|
|
14
|
+
ambiguous = true;
|
|
15
|
+
});
|
|
16
|
+
if (ambiguous)
|
|
17
|
+
return { error: "YAML aliases, anchors, tags, merge keys or complex keys require manual configuration" };
|
|
18
|
+
return { doc };
|
|
19
|
+
}
|
|
20
|
+
function validPath(keys) {
|
|
21
|
+
return keys.length > 0 && keys.every(key => key.length > 0 && !["__proto__", "constructor", "prototype"].includes(key));
|
|
22
|
+
}
|
|
23
|
+
export function readYamlEntry(text, keys) {
|
|
24
|
+
if (!validPath(keys))
|
|
25
|
+
return { error: "the configuration entry path is invalid" };
|
|
26
|
+
if (text === undefined)
|
|
27
|
+
return { value: undefined, kept: 0 };
|
|
28
|
+
const parsed = document(text);
|
|
29
|
+
if ("error" in parsed)
|
|
30
|
+
return parsed;
|
|
31
|
+
if (parsed.doc.contents === null)
|
|
32
|
+
return { value: undefined, kept: 0 };
|
|
33
|
+
let map = parsed.doc.contents;
|
|
34
|
+
let kept = 0;
|
|
35
|
+
for (const key of keys) {
|
|
36
|
+
if (!isMap(map))
|
|
37
|
+
return { error: `its "${keys.slice(0, kept).join(".")}" is not a mapping` };
|
|
38
|
+
if (!map.has(key))
|
|
39
|
+
return { value: undefined, kept };
|
|
40
|
+
const node = map.get(key, true);
|
|
41
|
+
kept++;
|
|
42
|
+
if (kept === keys.length)
|
|
43
|
+
return { value: isNode(node) ? node.toJSON() : node, kept };
|
|
44
|
+
map = node;
|
|
45
|
+
}
|
|
46
|
+
return { value: undefined, kept };
|
|
47
|
+
}
|
|
48
|
+
function hasComments(node) {
|
|
49
|
+
let found = false;
|
|
50
|
+
visit(node, (_key, child) => {
|
|
51
|
+
if (isNode(child) && (child.comment || child.commentBefore))
|
|
52
|
+
found = true;
|
|
53
|
+
});
|
|
54
|
+
return found;
|
|
55
|
+
}
|
|
56
|
+
function editRange(text, start, end, content) {
|
|
57
|
+
const updated = text.slice(0, start) + content + text.slice(end);
|
|
58
|
+
const checked = document(updated);
|
|
59
|
+
if ("error" in checked)
|
|
60
|
+
return { outcome: "skipped", reason: "this YAML cannot be edited safely; configure it manually" };
|
|
61
|
+
const before = document(text);
|
|
62
|
+
if ("error" in before)
|
|
63
|
+
return { outcome: "skipped", reason: before.error };
|
|
64
|
+
const comments = (doc) => {
|
|
65
|
+
const found = [];
|
|
66
|
+
for (const value of [doc.comment, doc.commentBefore])
|
|
67
|
+
if (typeof value === "string")
|
|
68
|
+
found.push(value);
|
|
69
|
+
visit(doc, (_key, node) => { if (isNode(node))
|
|
70
|
+
for (const value of [node.comment, node.commentBefore])
|
|
71
|
+
if (typeof value === "string")
|
|
72
|
+
found.push(value); });
|
|
73
|
+
return found.sort((left, right) => left.localeCompare(right));
|
|
74
|
+
};
|
|
75
|
+
if (!isDeepStrictEqual(comments(before.doc), comments(checked.doc)))
|
|
76
|
+
return { outcome: "skipped", reason: "changing this entry would remove a personal comment; edit it manually" };
|
|
77
|
+
return { outcome: "updated", content: updated };
|
|
78
|
+
}
|
|
79
|
+
function suffix(text, start, end) {
|
|
80
|
+
if (!text.slice(start, end).endsWith("\n"))
|
|
81
|
+
return "";
|
|
82
|
+
return text.includes("\r\n") ? "\r\n" : "\n";
|
|
83
|
+
}
|
|
84
|
+
function lineStart(text, offset) {
|
|
85
|
+
const start = text.lastIndexOf("\n", offset - 1) + 1;
|
|
86
|
+
return text.slice(start, offset).trim() ? offset : start;
|
|
87
|
+
}
|
|
88
|
+
function nestedValue(keys, value) {
|
|
89
|
+
let nested = value;
|
|
90
|
+
for (let index = keys.length - 1; index >= 0; index--)
|
|
91
|
+
nested = { [keys[index]]: nested };
|
|
92
|
+
return nested;
|
|
93
|
+
}
|
|
94
|
+
function appendValue(existing, parent, keys, depth, value) {
|
|
95
|
+
if (!parent.range)
|
|
96
|
+
return { outcome: "skipped", reason: "this YAML mapping cannot be edited safely" };
|
|
97
|
+
const property = `${JSON.stringify(keys[depth])}: ${JSON.stringify(nestedValue(keys.slice(depth + 1), value))}`;
|
|
98
|
+
let result;
|
|
99
|
+
if (parent.flow) {
|
|
100
|
+
const end = existing.lastIndexOf("}", parent.range[1] - 1);
|
|
101
|
+
result = editRange(existing, end, end, `${parent.items.length ? ", " : ""}${property}`);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const firstKey = parent.items[0]?.key;
|
|
105
|
+
const offset = isNode(firstKey) && firstKey.range ? firstKey.range[0] : parent.range[0];
|
|
106
|
+
const indent = " ".repeat(offset - lineStart(existing, offset));
|
|
107
|
+
const end = parent.range[1];
|
|
108
|
+
const newline = existing.includes("\r\n") ? "\r\n" : "\n";
|
|
109
|
+
const leading = end && !existing.slice(0, end).endsWith("\n") ? newline : "";
|
|
110
|
+
result = editRange(existing, end, end, `${leading}${indent}${property}${newline}`);
|
|
111
|
+
}
|
|
112
|
+
return result.outcome === "updated" ? { ...result, outcome: "appended" } : result;
|
|
113
|
+
}
|
|
114
|
+
function updateValue(existing, node, value) {
|
|
115
|
+
if (!isNode(node) || !node.range || hasComments(node))
|
|
116
|
+
return { outcome: "skipped", reason: "changing this entry would remove a personal comment; edit it manually" };
|
|
117
|
+
return editRange(existing, node.range[0], node.range[1], JSON.stringify(value) + suffix(existing, node.range[0], node.range[1]));
|
|
118
|
+
}
|
|
119
|
+
function appendToEmpty(existing, keys, value) {
|
|
120
|
+
const newline = existing.includes("\r\n") ? "\r\n" : "\n";
|
|
121
|
+
const leading = existing && !existing.endsWith("\n") ? newline : "";
|
|
122
|
+
const result = editRange(existing, existing.length, existing.length, `${leading}${JSON.stringify(keys[0])}: ${JSON.stringify(nestedValue(keys.slice(1), value))}${newline}`);
|
|
123
|
+
return result.outcome === "updated" ? { ...result, outcome: "appended" } : result;
|
|
124
|
+
}
|
|
125
|
+
export function upsertYamlEntry(existing, keys, value, options = {}) {
|
|
126
|
+
const current = readYamlEntry(existing, keys);
|
|
127
|
+
if ("error" in current)
|
|
128
|
+
return { outcome: "skipped", reason: current.error };
|
|
129
|
+
if (isDeepStrictEqual(current.value, value))
|
|
130
|
+
return { outcome: "unchanged" };
|
|
131
|
+
if (current.value === undefined && options.onlyExisting)
|
|
132
|
+
return { outcome: "skipped", reason: "it has no Cavelon entry" };
|
|
133
|
+
if (current.value !== undefined && !options.matches?.(current.value))
|
|
134
|
+
return { outcome: "skipped", reason: `its "${keys.join(".")}" is a personal or conflicting entry` };
|
|
135
|
+
if (existing === undefined)
|
|
136
|
+
return { outcome: "created", content: JSON.stringify(nestedValue(keys, value), null, 2) + "\n" };
|
|
137
|
+
const parsed = document(existing);
|
|
138
|
+
if ("error" in parsed)
|
|
139
|
+
return { outcome: "skipped", reason: parsed.error };
|
|
140
|
+
if (parsed.doc.contents === null)
|
|
141
|
+
return appendToEmpty(existing, keys, value);
|
|
142
|
+
if (current.value !== undefined)
|
|
143
|
+
return updateValue(existing, parsed.doc.getIn(keys, true), value);
|
|
144
|
+
const parent = current.kept ? parsed.doc.getIn(keys.slice(0, current.kept), true) : parsed.doc.contents;
|
|
145
|
+
if (!isMap(parent))
|
|
146
|
+
return { outcome: "skipped", reason: "this YAML mapping cannot be edited safely" };
|
|
147
|
+
return appendValue(existing, parent, keys, current.kept, value);
|
|
148
|
+
}
|
|
149
|
+
function removalParent(doc, keys, keep) {
|
|
150
|
+
let removing = keys;
|
|
151
|
+
let parent = doc.getIn(removing.slice(0, -1), true);
|
|
152
|
+
while (isMap(parent) && parent.items.length === 1 && removing.length - 1 > keep && !hasComments(parent)) {
|
|
153
|
+
removing = removing.slice(0, -1);
|
|
154
|
+
parent = doc.getIn(removing.slice(0, -1), true);
|
|
155
|
+
}
|
|
156
|
+
return { removing, parent };
|
|
157
|
+
}
|
|
158
|
+
function pairRanges(pair) {
|
|
159
|
+
if (!pair || !isNode(pair.key) || !pair.key.range || !isNode(pair.value) || !pair.value.range || pair.key.comment || hasComments(pair.value))
|
|
160
|
+
return undefined;
|
|
161
|
+
return { key: pair.key.range, value: pair.value.range };
|
|
162
|
+
}
|
|
163
|
+
function removeFlowPair(existing, parent, index, ranges) {
|
|
164
|
+
let start = ranges.key[0];
|
|
165
|
+
let end = ranges.value[1];
|
|
166
|
+
if (index < parent.items.length - 1) {
|
|
167
|
+
const comma = existing.indexOf(",", end);
|
|
168
|
+
if (comma < 0 || comma >= parent.range[1])
|
|
169
|
+
return { outcome: "skipped", reason: "this YAML separator cannot be edited safely" };
|
|
170
|
+
end = comma + 1;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
start = existing.lastIndexOf(",", start);
|
|
174
|
+
if (start < parent.range[0])
|
|
175
|
+
return { outcome: "skipped", reason: "this YAML separator cannot be edited safely" };
|
|
176
|
+
}
|
|
177
|
+
return editRange(existing, start, end, "");
|
|
178
|
+
}
|
|
179
|
+
function removePair(existing, parent, key) {
|
|
180
|
+
if (!parent.range)
|
|
181
|
+
return { outcome: "skipped", reason: "this YAML mapping cannot be edited safely" };
|
|
182
|
+
const index = parent.items.findIndex(pair => isScalar(pair.key) && pair.key.value === key);
|
|
183
|
+
const ranges = pairRanges(parent.items[index]);
|
|
184
|
+
if (!ranges)
|
|
185
|
+
return { outcome: "skipped", reason: "removing this entry would remove a personal comment; edit it manually" };
|
|
186
|
+
if (parent.items.length === 1)
|
|
187
|
+
return editRange(existing, parent.range[0], parent.range[1], "{}" + suffix(existing, parent.range[0], parent.range[1]));
|
|
188
|
+
if (parent.flow)
|
|
189
|
+
return removeFlowPair(existing, parent, index, ranges);
|
|
190
|
+
return editRange(existing, lineStart(existing, ranges.key[0]), ranges.value[2], "");
|
|
191
|
+
}
|
|
192
|
+
function emptyDocument(text) {
|
|
193
|
+
const final = document(text);
|
|
194
|
+
if ("error" in final)
|
|
195
|
+
return false;
|
|
196
|
+
const doc = final.doc;
|
|
197
|
+
return isMap(doc.contents) && !doc.contents.items.length && !hasComments(doc.contents) && !doc.comment && !doc.commentBefore;
|
|
198
|
+
}
|
|
199
|
+
export function removeYamlEntry(existing, keys, matches, keep = 0) {
|
|
200
|
+
const current = readYamlEntry(existing, keys);
|
|
201
|
+
if ("error" in current)
|
|
202
|
+
return { outcome: "skipped", reason: current.error };
|
|
203
|
+
if (current.value === undefined || existing === undefined)
|
|
204
|
+
return { outcome: "unchanged" };
|
|
205
|
+
if (!matches(current.value))
|
|
206
|
+
return { outcome: "skipped", reason: `its "${keys.join(".")}" was changed since cavelon wrote it` };
|
|
207
|
+
const parsed = document(existing);
|
|
208
|
+
if ("error" in parsed)
|
|
209
|
+
return { outcome: "skipped", reason: parsed.error };
|
|
210
|
+
const { removing, parent } = removalParent(parsed.doc, keys, keep);
|
|
211
|
+
if (!isMap(parent))
|
|
212
|
+
return { outcome: "skipped", reason: "this YAML mapping cannot be edited safely" };
|
|
213
|
+
const result = removePair(existing, parent, removing.at(-1));
|
|
214
|
+
return result.outcome === "updated" ? { ...result, empty: emptyDocument(result.content) } : result;
|
|
215
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cavelon/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
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",
|