@h1r-ai/croche-cli 0.6.2 → 0.7.0
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/LICENSE +1 -1
- package/README.md +116 -54
- package/THIRD-PARTY-NOTICES +899 -6
- package/dist/bin.js +1 -1
- package/dist/{chunk-K3UDT4EM.js → chunk-42AQKNDN.js} +181 -543
- package/dist/config-authoring.d.ts +4 -4
- package/dist/config-push-base-E2TEF3ZJ.js +2249 -0
- package/dist/config-push-base.d.ts +2 -0
- package/dist/debugger/public/stage-targets.js +7 -0
- package/dist/debugger/public/stage.js +2 -2
- package/dist/debugger/server/collector.js +13 -2
- package/dist/debugger/server/control-bridge.js +49 -31
- package/dist/debugger/server/observe.js +1 -1
- package/dist/{debug-keys.d.ts → development-keys.d.ts} +3 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/config-push-base-35HX67AJ.js +0 -2254
|
@@ -15,13 +15,13 @@ var resultNouns = {
|
|
|
15
15
|
"projects operations": "operations",
|
|
16
16
|
"projects cost": "cost",
|
|
17
17
|
"projects usage": "usage",
|
|
18
|
-
"keys development list": "
|
|
18
|
+
"keys development list": "development_keys",
|
|
19
19
|
"keys server list": "server_keys",
|
|
20
20
|
"attestation get": "attestation",
|
|
21
21
|
"runtimes list": "runtimes",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
22
|
+
"development-keys create": "development_key",
|
|
23
|
+
"development-keys list": "development_keys",
|
|
24
|
+
"development-keys revoke": "development_key",
|
|
25
25
|
"config bases": "bases",
|
|
26
26
|
"config push-base": "base",
|
|
27
27
|
"config build": "config",
|
|
@@ -53,10 +53,6 @@ function jsonResult(path2, result) {
|
|
|
53
53
|
if (!noun) throw new Error(`Missing JSON command contract: ${path2}`);
|
|
54
54
|
if (result !== null && typeof result === "object" && !Array.isArray(result)) {
|
|
55
55
|
const value2 = result;
|
|
56
|
-
if (path2 === "keys development list" && Object.hasOwn(value2, "debug_tokens")) {
|
|
57
|
-
const { debug_tokens, ...metadata } = value2;
|
|
58
|
-
return { ...metadata, debug_keys: debug_tokens };
|
|
59
|
-
}
|
|
60
56
|
if (noun === "request" && value2.request && typeof value2.request === "object") {
|
|
61
57
|
const request = value2.request;
|
|
62
58
|
const list = { "agents.list": "agents", history: "history", tools: "tools" }[String(request.command)];
|
|
@@ -88,15 +84,15 @@ var sections = [
|
|
|
88
84
|
row("projects get", "Show one project"),
|
|
89
85
|
row("projects update", "Rename a project or change its model routing"),
|
|
90
86
|
row("projects usage", "Usage per user and agent, and budget left"),
|
|
91
|
-
row("projects cost", "
|
|
87
|
+
row("projects cost", "UTC monthly statement by funding purpose"),
|
|
92
88
|
row("projects operations", "Recent operations"),
|
|
93
89
|
row("runtimes list", "Runtimes enrolled with Cloud for a project")
|
|
94
90
|
] },
|
|
95
91
|
{ title: "Keys", rows: [
|
|
96
|
-
row("
|
|
97
|
-
row("
|
|
98
|
-
row("
|
|
99
|
-
row("keys development list", "
|
|
92
|
+
row("development-keys create", "Issue a development key and write it to .env"),
|
|
93
|
+
row("development-keys list", "List development keys (no secrets)"),
|
|
94
|
+
row("development-keys revoke", "Revoke a development key"),
|
|
95
|
+
row("keys development list", "Development keys with installs, last use, warnings"),
|
|
100
96
|
row("keys server list", "Server keys with installs, last use, spend"),
|
|
101
97
|
row("attestation get", "App Attest and Play Integrity settings")
|
|
102
98
|
] },
|
|
@@ -142,7 +138,7 @@ var footer = [
|
|
|
142
138
|
"Examples",
|
|
143
139
|
" croche login",
|
|
144
140
|
' croche projects create --name "My app"',
|
|
145
|
-
" croche
|
|
141
|
+
" croche development-keys create --project <project-id>",
|
|
146
142
|
"",
|
|
147
143
|
"Exit codes: 0 ok, 1 remote error, 2 usage or config, 3 auth, 4 network/timeout"
|
|
148
144
|
];
|
|
@@ -168,8 +164,8 @@ var flagHelp = {
|
|
|
168
164
|
name: ["NAME", "A name for the key"],
|
|
169
165
|
"projects create name": ["NAME", "Project name (required)"],
|
|
170
166
|
"projects update name": ["NAME", "New project name"],
|
|
171
|
-
"dotenv-file": ["PATH", "Where to write
|
|
172
|
-
force: ["", "Replace an existing
|
|
167
|
+
"dotenv-file": ["PATH", "Where to write CROCHE_DEVELOPMENT_KEY (default ./.env)"],
|
|
168
|
+
force: ["", "Replace an existing CROCHE_DEVELOPMENT_KEY value"],
|
|
173
169
|
print: ["", "Also print the key (hidden by default)"],
|
|
174
170
|
port: ["PORT", "Debugger port (default 8790)"],
|
|
175
171
|
"control serve port": ["PORT", "Broker port (default 8791)"],
|
|
@@ -195,7 +191,8 @@ var flagHelp = {
|
|
|
195
191
|
status: ["STATUS", "Only operations with this status"],
|
|
196
192
|
type: ["TYPE", "Only operations of this type"],
|
|
197
193
|
query: ["TEXT", "Only operations matching this text"],
|
|
198
|
-
period: ["PERIOD", "week, month (default) or
|
|
194
|
+
period: ["PERIOD", "week, month (default) or UTC YYYY-MM"],
|
|
195
|
+
month: ["YYYY-MM", "UTC statement month (default: current month)"],
|
|
199
196
|
purpose: ["PURPOSE", "production (default) or development"],
|
|
200
197
|
remote: ["IP", "Explicit viewer-only bind IP (requires --allow-origin)"],
|
|
201
198
|
role: ["ROLE", "Reveal pairing, ingest, observe, or controller token"],
|
|
@@ -1010,7 +1007,14 @@ import { dirname as dirname3, isAbsolute as isAbsolute3, join as join3, relative
|
|
|
1010
1007
|
// ../../vectors/config-capabilities.json
|
|
1011
1008
|
var config_capabilities_default = {
|
|
1012
1009
|
schema: 1,
|
|
1013
|
-
capabilities: [
|
|
1010
|
+
capabilities: [
|
|
1011
|
+
{
|
|
1012
|
+
id: "project.attachments@1",
|
|
1013
|
+
paths: [
|
|
1014
|
+
"/project/attachments"
|
|
1015
|
+
]
|
|
1016
|
+
}
|
|
1017
|
+
]
|
|
1014
1018
|
};
|
|
1015
1019
|
|
|
1016
1020
|
// ../../apps/cloud/data/v1.json
|
|
@@ -1773,13 +1777,9 @@ var v1_default = {
|
|
|
1773
1777
|
// ../../apps/cloud/src/model-profiles.ts
|
|
1774
1778
|
var table = v1_default.object;
|
|
1775
1779
|
var PROFILE_MODEL_IDS = table.models.map((model) => model.id);
|
|
1776
|
-
var REASONING_LEVELS = ["default", "off", "low", "medium", "high"];
|
|
1777
1780
|
|
|
1778
1781
|
// ../../apps/cloud/src/crypto.ts
|
|
1779
1782
|
var encoder = new TextEncoder();
|
|
1780
|
-
async function sha256(value2) {
|
|
1781
|
-
return Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(value2))), (x) => x.toString(16).padStart(2, "0")).join("");
|
|
1782
|
-
}
|
|
1783
1783
|
|
|
1784
1784
|
// ../../vectors/croche-tools-schema3.json
|
|
1785
1785
|
var croche_tools_schema3_default = {
|
|
@@ -2009,88 +2009,9 @@ var croche_tools_schema3_default = {
|
|
|
2009
2009
|
|
|
2010
2010
|
// ../../apps/cloud/src/tool-settings.ts
|
|
2011
2011
|
var bounds = croche_tools_schema3_default.bounds;
|
|
2012
|
-
var object = (value2) => value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
|
|
2013
|
-
var chars = (value2) => [...value2].length;
|
|
2014
|
-
var pointer = (key) => key.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
2015
|
-
function toolShapeProblems(tool, value2, path2) {
|
|
2016
|
-
const problems = [], problem = (key, reason) => problems.push({ path: key ? path2 + "/" + pointer(key) : path2, reason });
|
|
2017
|
-
if (tool !== "image" && tool !== "web.search") {
|
|
2018
|
-
problem("", "tool is not available");
|
|
2019
|
-
return problems;
|
|
2020
|
-
}
|
|
2021
|
-
if (value2 === false) return problems;
|
|
2022
|
-
if (value2 === true) {
|
|
2023
|
-
problem("model", "an explicit model is required");
|
|
2024
|
-
return problems;
|
|
2025
|
-
}
|
|
2026
|
-
if (tool === "image") {
|
|
2027
|
-
if (!object(value2)) {
|
|
2028
|
-
problem("", "must be false or a complete settings object with an explicit model");
|
|
2029
|
-
return problems;
|
|
2030
|
-
}
|
|
2031
|
-
for (const key of Object.keys(value2)) if (!["model", "stylePrompt", "imageSize", "aspectRatio", "maxPerTurn", "timeoutMs"].includes(key)) problem(key, "unknown tool settings field");
|
|
2032
|
-
if (typeof value2.model !== "string" || !value2.model || chars(value2.model) > 128) problem("model", "model id of 1\u2013128 characters required");
|
|
2033
|
-
if ("stylePrompt" in value2 && (typeof value2.stylePrompt !== "string" || chars(value2.stylePrompt) > 500)) problem("stylePrompt", "text of at most 500 characters required");
|
|
2034
|
-
if ("imageSize" in value2 && !["512", "1K", "2K"].includes(value2.imageSize)) problem("imageSize", "must be 512, 1K or 2K");
|
|
2035
|
-
if ("aspectRatio" in value2 && !["1:1", "3:4", "4:3", "9:16", "16:9"].includes(value2.aspectRatio)) problem("aspectRatio", "unsupported aspect ratio");
|
|
2036
|
-
for (const [key, min, max] of [["maxPerTurn", 1, 4], ["timeoutMs", 1e4, 18e4]])
|
|
2037
|
-
if (key in value2 && (!Number.isSafeInteger(value2[key]) || Number(value2[key]) < min || Number(value2[key]) > max)) problem(key, `integer from ${min} to ${max} required`);
|
|
2038
|
-
return problems;
|
|
2039
|
-
}
|
|
2040
|
-
if (tool !== "web.search") {
|
|
2041
|
-
problem("", "tool is not available in 0.5.2");
|
|
2042
|
-
return problems;
|
|
2043
|
-
}
|
|
2044
|
-
if (!object(value2)) {
|
|
2045
|
-
problem("", "must be false or a complete settings object with an explicit model");
|
|
2046
|
-
return problems;
|
|
2047
|
-
}
|
|
2048
|
-
const keys = ["model", "engine", "maxResults", "includeDomains", "excludeDomains", "maxPerTurn", "timeoutMs"];
|
|
2049
|
-
for (const key of Object.keys(value2)) if (!keys.includes(key)) problem(key, "unknown tool settings field");
|
|
2050
|
-
if (typeof value2.model !== "string" || !value2.model || chars(value2.model) > bounds.modelChars) problem("model", `text of 1\u2013${bounds.modelChars} characters required`);
|
|
2051
|
-
const integer3 = (key, range) => {
|
|
2052
|
-
if (key in value2 && (!Number.isSafeInteger(value2[key]) || Number(value2[key]) < range.min || Number(value2[key]) > range.max)) problem(key, `integer from ${range.min} to ${range.max} required`);
|
|
2053
|
-
};
|
|
2054
|
-
integer3("maxPerTurn", bounds.maxPerTurn);
|
|
2055
|
-
integer3("timeoutMs", bounds.timeoutMs);
|
|
2056
|
-
integer3("maxResults", bounds.maxResults);
|
|
2057
|
-
if ("engine" in value2 && value2.engine !== bounds.engine) problem("engine", "must be exa");
|
|
2058
|
-
for (const key of ["includeDomains", "excludeDomains"]) if (key in value2) {
|
|
2059
|
-
const list = value2[key];
|
|
2060
|
-
if (!Array.isArray(list) || list.length > bounds.domainCount || list.some((host) => typeof host !== "string" || host.length > bounds.domainChars || !new RegExp(bounds.domainPattern).test(host)))
|
|
2061
|
-
problem(key, "up to 20 lowercase hostnames (max 253 characters), without scheme, path or port required");
|
|
2062
|
-
}
|
|
2063
|
-
if (Array.isArray(value2.includeDomains) && Array.isArray(value2.excludeDomains) && value2.includeDomains.some((host) => value2.excludeDomains.includes(host))) problem("excludeDomains", "includeDomains and excludeDomains must be disjoint");
|
|
2064
|
-
return problems;
|
|
2065
|
-
}
|
|
2066
|
-
function toolSettingsProblems(tool, value2, path2, data = v1_default.object) {
|
|
2067
|
-
const problems = toolShapeProblems(tool, value2, path2);
|
|
2068
|
-
if (problems.length || value2 === false) return problems;
|
|
2069
|
-
const row2 = data.recommendations.tools[tool];
|
|
2070
|
-
const model = object(value2) ? value2.model : void 0;
|
|
2071
|
-
if (typeof model !== "string" || !row2 || !(row2.models ?? [row2.model]).includes(model)) problems.push({ path: path2 + "/model", reason: "model must be in this tool\u2019s entitlement catalogue" });
|
|
2072
|
-
return problems;
|
|
2073
|
-
}
|
|
2074
2012
|
|
|
2075
2013
|
// ../config-contract/src/index.ts
|
|
2076
|
-
var ConfigError = class extends Error {
|
|
2077
|
-
constructor(status, code, message, details) {
|
|
2078
|
-
super(message);
|
|
2079
|
-
this.status = status;
|
|
2080
|
-
this.code = code;
|
|
2081
|
-
this.details = details;
|
|
2082
|
-
}
|
|
2083
|
-
};
|
|
2084
|
-
var fail = (status, code, message, details) => {
|
|
2085
|
-
throw new ConfigError(status, code, message, details);
|
|
2086
|
-
};
|
|
2087
2014
|
var isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
2088
|
-
var fields = /* @__PURE__ */ new Set(["instructions", "markerGuide", "toolGuide", "crocheTools", "tools", "wiki", "memory", "context", "limits", "maxContextTokens", "maxOutputTokens", "maxIterations", "model", "fallbacks", "reasoning", "temperature", "defaultLanguage", "languages", "agents", "schedule", "heartbeat", "modes", "instances"]);
|
|
2089
|
-
var crocheTools = /* @__PURE__ */ new Set(["memory.save", "memory.recall", "memory.history", "wiki", "schedule"]);
|
|
2090
|
-
var asciiFold = (tag) => tag.replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
2091
|
-
var languageTag = (tag) => typeof tag === "string" && tag.length <= 35 && /^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/.exec(tag)?.[0] === tag;
|
|
2092
|
-
var configModelId = (v) => typeof v === "string" && v.length > 0 && new TextEncoder().encode(v).byteLength <= 200;
|
|
2093
|
-
var words = /* @__PURE__ */ new Set(["summary", "description"]);
|
|
2094
2015
|
var CanonicalError = class extends Error {
|
|
2095
2016
|
constructor(path2, message) {
|
|
2096
2017
|
super(message);
|
|
@@ -2098,7 +2019,7 @@ var CanonicalError = class extends Error {
|
|
|
2098
2019
|
}
|
|
2099
2020
|
code = "invalid_configuration";
|
|
2100
2021
|
};
|
|
2101
|
-
var
|
|
2022
|
+
var pointer = (key) => key.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
2102
2023
|
function encodeCanonical(value2, path2 = "") {
|
|
2103
2024
|
if (typeof value2 === "number" && (!Number.isFinite(value2) || Number.isInteger(value2) && !Number.isSafeInteger(value2))) throw new CanonicalError(path2, "unsafe or non-finite number");
|
|
2104
2025
|
if (typeof value2 === "string") {
|
|
@@ -2113,7 +2034,7 @@ function encodeCanonical(value2, path2 = "") {
|
|
|
2113
2034
|
}
|
|
2114
2035
|
if (value2 === null || typeof value2 === "boolean" || typeof value2 === "number" && Number.isFinite(value2)) return JSON.stringify(value2);
|
|
2115
2036
|
if (Array.isArray(value2)) return "[" + value2.map((v, i) => encodeCanonical(v, path2 + "/" + i)).join(",") + "]";
|
|
2116
|
-
if (isObject(value2)) return "{" + Object.keys(value2).sort().map((k) => encodeCanonical(k, path2 + "/" +
|
|
2037
|
+
if (isObject(value2)) return "{" + Object.keys(value2).sort().map((k) => encodeCanonical(k, path2 + "/" + pointer(k)) + ":" + encodeCanonical(value2[k], path2 + "/" + pointer(k))).join(",") + "}";
|
|
2117
2038
|
throw new Error("Expected JSON");
|
|
2118
2039
|
}
|
|
2119
2040
|
function canonical(value2) {
|
|
@@ -2121,356 +2042,17 @@ function canonical(value2) {
|
|
|
2121
2042
|
if (new TextEncoder().encode(encoded).byteLength > 256 * 1024) throw new CanonicalError("", "Project config exceeds 256 KiB.");
|
|
2122
2043
|
return encoded;
|
|
2123
2044
|
}
|
|
2124
|
-
function shape(value2) {
|
|
2125
|
-
if (Array.isArray(value2)) return value2.map(shape);
|
|
2126
|
-
if (isObject(value2)) return Object.fromEntries(Object.entries(value2).filter(([k]) => !words.has(k)).map(([k, v]) => [k, shape(v)]));
|
|
2127
|
-
return value2;
|
|
2128
|
-
}
|
|
2129
|
-
var shapeHash = async (command) => "sha256:" + await sha256(canonical(shape(command)));
|
|
2130
2045
|
var CONFIG_CAPABILITIES = config_capabilities_default.capabilities;
|
|
2131
|
-
function inferredRequirements(document) {
|
|
2132
|
-
const present = (value2, segments) => {
|
|
2133
|
-
if (!segments.length) return true;
|
|
2134
|
-
const [key, ...rest] = segments;
|
|
2135
|
-
if (key === "*") {
|
|
2136
|
-
const children = Array.isArray(value2) ? value2 : isObject(value2) ? Object.values(value2) : [];
|
|
2137
|
-
return children.some((child) => present(child, rest));
|
|
2138
|
-
}
|
|
2139
|
-
if (Array.isArray(value2)) return /^(0|[1-9][0-9]*)$/.test(key) && Number(key) < value2.length && present(value2[Number(key)], rest);
|
|
2140
|
-
return isObject(value2) && Object.hasOwn(value2, key) && present(value2[key], rest);
|
|
2141
|
-
};
|
|
2142
|
-
return [...new Set(CONFIG_CAPABILITIES.filter((c) => c.paths.some((path2) => present(document, path2.slice(1).split("/").map((key) => key.replaceAll("~1", "/").replaceAll("~0", "~"))))).map((c) => c.id))].sort();
|
|
2143
|
-
}
|
|
2144
|
-
function compileRequirements(document) {
|
|
2145
|
-
if (!isObject(document)) return document;
|
|
2146
|
-
if (Object.hasOwn(document, "requires")) fail(400, "invalid_configuration", "requires is compiler-owned.", { problems: [{ path: "/requires", reason: "requires is compiler-owned" }] });
|
|
2147
|
-
const requires = inferredRequirements(document);
|
|
2148
|
-
return requires.length ? { ...document, requires } : document;
|
|
2149
|
-
}
|
|
2150
2046
|
var MAX_BYTES = 256 * 1024;
|
|
2151
|
-
function validateDocumentShape(document, write = false) {
|
|
2152
|
-
const problems = [];
|
|
2153
|
-
const problem = (path2, reason) => {
|
|
2154
|
-
if (!problems.some((p) => p.path === path2 && p.reason === reason)) problems.push({ path: path2, reason });
|
|
2155
|
-
};
|
|
2156
|
-
const at2 = (path2, key) => path2 + "/" + pointer2(String(key));
|
|
2157
|
-
let encoded = "";
|
|
2158
|
-
try {
|
|
2159
|
-
encoded = encodeCanonical(document);
|
|
2160
|
-
} catch (error) {
|
|
2161
|
-
problem(error instanceof CanonicalError ? error.path : "", error instanceof Error ? error.message : "valid Unicode JSON required");
|
|
2162
|
-
}
|
|
2163
|
-
if (new TextEncoder().encode(encoded).byteLength > MAX_BYTES) fail(413, "config_too_large", "Project config exceeds 256 KiB.");
|
|
2164
|
-
if (!isObject(document) || !(write ? [6] : [2, 3, 4, 5, 6]).includes(Number(document.schema)) || typeof document.schema !== "number") problem("/schema", write ? "new writes require schema 6" : "stored schema must be 2, 3, 4, 5 or 6");
|
|
2165
|
-
const schema = isObject(document) ? document.schema : void 0;
|
|
2166
|
-
if (isObject(document)) {
|
|
2167
|
-
for (const k of Object.keys(document)) if (!(schema === 6 ? ["schema", "config", "requires"] : ["schema", "config"]).includes(k)) problem(at2("", k), "unknown document field");
|
|
2168
|
-
}
|
|
2169
|
-
if (schema === 6 && isObject(document)) {
|
|
2170
|
-
const requires = document.requires, inferred = inferredRequirements(document);
|
|
2171
|
-
if (requires !== void 0) {
|
|
2172
|
-
if (!Array.isArray(requires) || !requires.length || requires.length > 128) problem("/requires", "must be a nonempty array of at most 128 capabilities");
|
|
2173
|
-
else requires.forEach((id, i) => {
|
|
2174
|
-
if (typeof id !== "string" || !CONFIG_CAPABILITIES.some((c) => c.id === id)) problem(at2("/requires", i), "unsupported required capability");
|
|
2175
|
-
else if (i > 0 && String(requires[i - 1]) >= id) problem(at2("/requires", i), "capabilities must be sorted and unique");
|
|
2176
|
-
});
|
|
2177
|
-
}
|
|
2178
|
-
if (JSON.stringify(requires ?? []) !== JSON.stringify(inferred)) problem("/requires", "requirements must match the compiler-inferred capabilities");
|
|
2179
|
-
}
|
|
2180
|
-
const config = isObject(document) ? document.config : void 0;
|
|
2181
|
-
const defaultLanguage = isObject(config) && typeof config.defaultLanguage === "string" ? config.defaultLanguage : "en";
|
|
2182
|
-
const declarations = [], tools = /* @__PURE__ */ new Set();
|
|
2183
|
-
const nullableTemperature = /* @__PURE__ */ new Set();
|
|
2184
|
-
const collectTemperature = (value2, path2, depth = 0) => {
|
|
2185
|
-
if (depth > 64 || !isObject(value2)) return;
|
|
2186
|
-
if (typeof schema === "number" && schema >= 4) nullableTemperature.add(at2(path2, "temperature"));
|
|
2187
|
-
for (const field of ["languages", "agents"]) if (isObject(value2[field])) {
|
|
2188
|
-
for (const [name, layer] of Object.entries(value2[field])) collectTemperature(layer, at2(at2(path2, field), name), depth + 1);
|
|
2189
|
-
}
|
|
2190
|
-
};
|
|
2191
|
-
collectTemperature(config, "/config");
|
|
2192
|
-
const visitNull = (value2, path2, depth = 0) => {
|
|
2193
|
-
if (depth > 64) {
|
|
2194
|
-
problem(path2, "config is too deeply nested");
|
|
2195
|
-
return;
|
|
2196
|
-
}
|
|
2197
|
-
if (typeof value2 === "number" && (!Number.isFinite(value2) || Number.isInteger(value2) && !Number.isSafeInteger(value2))) problem(path2, "unsafe or non-finite number");
|
|
2198
|
-
if (value2 === null && !nullableTemperature.has(path2)) problem(path2, "null is not allowed");
|
|
2199
|
-
else if (typeof value2 === "string") {
|
|
2200
|
-
try {
|
|
2201
|
-
encodeCanonical(value2, path2);
|
|
2202
|
-
} catch (error) {
|
|
2203
|
-
problem(path2, error instanceof Error ? error.message : "Invalid Unicode");
|
|
2204
|
-
}
|
|
2205
|
-
} else if (Array.isArray(value2)) value2.forEach((v, i) => visitNull(v, at2(path2, i), depth + 1));
|
|
2206
|
-
else if (isObject(value2)) Object.entries(value2).forEach(([k, v]) => visitNull(v, at2(path2, k), depth + 1));
|
|
2207
|
-
};
|
|
2208
|
-
visitNull(document, "");
|
|
2209
|
-
const toolList = (value2, path2) => {
|
|
2210
|
-
if (!Array.isArray(value2)) {
|
|
2211
|
-
problem(path2, "must be an array");
|
|
2212
|
-
return;
|
|
2213
|
-
}
|
|
2214
|
-
try {
|
|
2215
|
-
if (new TextEncoder().encode(encodeCanonical(value2)).byteLength > 256e3) problem(path2, "tool registry exceeds 256,000 UTF-8 bytes");
|
|
2216
|
-
} catch {
|
|
2217
|
-
}
|
|
2218
|
-
const keys = /* @__PURE__ */ new Set(), names = /* @__PURE__ */ new Set();
|
|
2219
|
-
value2.forEach((tool, i) => {
|
|
2220
|
-
const p = at2(path2, i);
|
|
2221
|
-
if (!isObject(tool)) {
|
|
2222
|
-
problem(p, "must be an object");
|
|
2223
|
-
return;
|
|
2224
|
-
}
|
|
2225
|
-
for (const key of Object.keys(tool)) if (!["name", "summary", "commands"].includes(key)) problem(at2(p, key), "unknown field");
|
|
2226
|
-
if (typeof tool.name !== "string" || !tool.name.trim()) problem(at2(p, "name"), "required");
|
|
2227
|
-
else {
|
|
2228
|
-
if (["help", "memory", "wiki"].includes(tool.name)) problem(at2(p, "name"), "reserved tool name");
|
|
2229
|
-
if (names.has(tool.name)) problem(at2(p, "name"), "duplicate tool name");
|
|
2230
|
-
else names.add(tool.name);
|
|
2231
|
-
tools.add(tool.name);
|
|
2232
|
-
}
|
|
2233
|
-
if (typeof tool.summary !== "string" || !tool.summary.length) problem(at2(p, "summary"), "required");
|
|
2234
|
-
if (!Array.isArray(tool.commands)) problem(at2(p, "commands"), "must be an array");
|
|
2235
|
-
else {
|
|
2236
|
-
if (!tool.commands.length) problem(at2(p, "commands"), "at least one command");
|
|
2237
|
-
const routes = /* @__PURE__ */ new Set();
|
|
2238
|
-
tool.commands.forEach((command, j) => {
|
|
2239
|
-
const commandPath = at2(at2(p, "commands"), j);
|
|
2240
|
-
if (isObject(command)) {
|
|
2241
|
-
for (const key of Object.keys(command)) if (!["key", "name", "summary", "aliases", "timeoutMs", "reads", "flags", "positionals"].includes(key)) problem(at2(commandPath, key), "unknown field");
|
|
2242
|
-
for (const field of ["flags", "positionals"]) if (field in command) {
|
|
2243
|
-
const args = command[field], argPath = at2(commandPath, field);
|
|
2244
|
-
if (!Array.isArray(args)) problem(argPath, "must be an array");
|
|
2245
|
-
else args.forEach((arg, k) => {
|
|
2246
|
-
const ap = at2(argPath, k);
|
|
2247
|
-
if (!isObject(arg)) {
|
|
2248
|
-
problem(ap, "must be an object");
|
|
2249
|
-
return;
|
|
2250
|
-
}
|
|
2251
|
-
for (const key of Object.keys(arg)) if (!["name", "arg", "type", "description", "required", "default", "enum", "minimum", "maximum", "minLength", "maxLength", "aliases", "list"].includes(key)) problem(at2(ap, key), "unknown field");
|
|
2252
|
-
});
|
|
2253
|
-
}
|
|
2254
|
-
}
|
|
2255
|
-
if (isObject(command) && (typeof command.summary !== "string" || !command.summary.length)) problem(at2(commandPath, "summary"), "required");
|
|
2256
|
-
if (isObject(command) && "confirm" in command) problem(at2(at2(at2(p, "commands"), j), "confirm"), "unknown field");
|
|
2257
|
-
if (!isObject(command) || typeof command.key !== "string" || !command.key.length) problem(at2(at2(at2(p, "commands"), j), "key"), "required");
|
|
2258
|
-
else {
|
|
2259
|
-
const keyPath = at2(commandPath, "key");
|
|
2260
|
-
if (new TextEncoder().encode(command.key).byteLength > 100) problem(keyPath, "1\u2013100 UTF-8 bytes required");
|
|
2261
|
-
if (keys.has(command.key)) problem(keyPath, "duplicate command key");
|
|
2262
|
-
else keys.add(command.key);
|
|
2263
|
-
if ("name" in command && (typeof command.name !== "string" || !command.name.trim())) problem(at2(at2(at2(p, "commands"), j), "name"), "nonempty string required");
|
|
2264
|
-
const route = command.name === void 0 ? "" : typeof command.name === "string" ? command.name : void 0;
|
|
2265
|
-
if (route !== void 0) {
|
|
2266
|
-
if (routes.has(route)) problem("name" in command ? at2(commandPath, "name") : commandPath, "duplicate command route");
|
|
2267
|
-
else routes.add(route);
|
|
2268
|
-
}
|
|
2269
|
-
if (typeof tool.name === "string") declarations.push({ tool: tool.name, command });
|
|
2270
|
-
}
|
|
2271
|
-
});
|
|
2272
|
-
}
|
|
2273
|
-
});
|
|
2274
|
-
};
|
|
2275
|
-
const configLayer = (value2, path2, agent = false, root = false, depth = 0, language = false) => {
|
|
2276
|
-
if (depth > 64) {
|
|
2277
|
-
problem(path2, "config is too deeply nested");
|
|
2278
|
-
return;
|
|
2279
|
-
}
|
|
2280
|
-
if (!isObject(value2)) {
|
|
2281
|
-
problem(path2, "must be an object");
|
|
2282
|
-
return;
|
|
2283
|
-
}
|
|
2284
|
-
for (const k of Object.keys(value2)) if (!fields.has(k) && !(agent && k === "name") || !root && ["agents", "defaultLanguage", "instances"].includes(k) || language && k === "languages") problem(at2(path2, k), k === "recommendedFallbacks" ? "recommendedFallbacks was removed: use explicit fallbacks" : k === "memoryRecall" ? "memoryRecall was removed: the model reads memories with memory recall" : k === "timeContext" ? "timeContext was removed: each turn has a number and short local-time header" : "unknown field");
|
|
2285
|
-
if (schema === 6 && "maxContextTokens" in value2) problem(at2(path2, "maxContextTokens"), "removed: use context.turnTokens");
|
|
2286
|
-
if (schema !== 6 && "context" in value2) problem(at2(path2, "context"), "unknown field");
|
|
2287
|
-
if (root && (typeof value2.instructions !== "string" || !value2.instructions.trim())) problem(at2(path2, "instructions"), "nonempty string required");
|
|
2288
|
-
for (const field of ["instructions", "markerGuide"]) if (value2[field] !== void 0 && value2[field] !== null && (typeof value2[field] !== "string" || field === "instructions" && !String(value2[field]).trim())) problem(at2(path2, field), "nonempty instructions or text required");
|
|
2289
|
-
const range = (row2, field, min, max, p, zero = false) => {
|
|
2290
|
-
if (field in row2 && (!Number.isSafeInteger(row2[field]) || !(zero && row2[field] === 0) && !(Number(row2[field]) >= min && Number(row2[field]) <= max))) problem(at2(p, field), `integer from ${min} to ${max}${zero ? " or zero" : ""} required`);
|
|
2291
|
-
};
|
|
2292
|
-
for (const [field, min, max] of [["maxOutputTokens", 64, 1048576], ["maxIterations", 1, 32]]) range(value2, field, min, max, path2);
|
|
2293
|
-
if (schema !== 6) range(value2, "maxContextTokens", 250, 16777216, path2);
|
|
2294
|
-
if ("context" in value2) {
|
|
2295
|
-
const p = at2(path2, "context"), c = value2.context;
|
|
2296
|
-
if (!isObject(c)) problem(p, "must be an object");
|
|
2297
|
-
else {
|
|
2298
|
-
for (const key of Object.keys(c)) if (!["turnTokens", "memoryShare", "maxTokens"].includes(key)) problem(at2(p, key), "unknown field");
|
|
2299
|
-
range(c, "turnTokens", 1, 16777216, p);
|
|
2300
|
-
range(c, "maxTokens", 1, 16777216, p);
|
|
2301
|
-
if ("memoryShare" in c && (typeof c.memoryShare !== "number" || !Number.isFinite(c.memoryShare) || c.memoryShare < 0 || c.memoryShare > 0.5)) problem(at2(p, "memoryShare"), "number from 0 to 0.5 required");
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
|
-
if ("limits" in value2) {
|
|
2305
|
-
const p = at2(path2, "limits"), limits = value2.limits;
|
|
2306
|
-
if (!isObject(limits)) problem(p, "must be an object");
|
|
2307
|
-
else {
|
|
2308
|
-
for (const key of Object.keys(limits)) if (!["userTextChars", "appStateChars", "toolResultChars"].includes(key)) problem(at2(p, key), "unknown field");
|
|
2309
|
-
range(limits, "userTextChars", 1e3, 2e5, p);
|
|
2310
|
-
range(limits, "appStateChars", 1e3, 2e5, p);
|
|
2311
|
-
range(limits, "toolResultChars", 1e3, 1e6, p);
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
if ("temperature" in value2) {
|
|
2315
|
-
if (typeof schema !== "number" || schema < 4) problem(at2(path2, "temperature"), "unknown field");
|
|
2316
|
-
else if (value2.temperature !== null && (typeof value2.temperature !== "number" || !Number.isFinite(value2.temperature) || value2.temperature < 0 || value2.temperature > 2)) problem(at2(path2, "temperature"), "number from 0 to 2, or null to omit required");
|
|
2317
|
-
}
|
|
2318
|
-
if ("crocheTools" in value2) {
|
|
2319
|
-
const p = at2(path2, "crocheTools");
|
|
2320
|
-
if (!isObject(value2.crocheTools)) problem(p, "must be an object of boolean library switches");
|
|
2321
|
-
else for (const [key, on] of Object.entries(value2.crocheTools)) {
|
|
2322
|
-
if (key === "image" && typeof schema === "number" && schema >= 6) {
|
|
2323
|
-
for (const issue2 of toolShapeProblems(key, on, at2(p, key))) problem(issue2.path, issue2.reason);
|
|
2324
|
-
continue;
|
|
2325
|
-
}
|
|
2326
|
-
if (typeof schema === "number" && schema >= 3 && key === "web.search") {
|
|
2327
|
-
for (const issue2 of (typeof schema === "number" && schema >= 5 ? toolShapeProblems : toolSettingsProblems)(key, on, at2(p, key))) problem(issue2.path, issue2.reason);
|
|
2328
|
-
} else if (!crocheTools.has(key)) problem(at2(p, key), "unknown Croche tool");
|
|
2329
|
-
else if (typeof on !== "boolean") problem(at2(p, key), "must be a boolean");
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
if ("instances" in value2) {
|
|
2333
|
-
const p = at2(path2, "instances");
|
|
2334
|
-
if (!isObject(value2.instances)) problem(p, "must be an object");
|
|
2335
|
-
else {
|
|
2336
|
-
for (const key of Object.keys(value2.instances)) if (key !== "maxBytes") problem(at2(p, key), "unknown field");
|
|
2337
|
-
range(value2.instances, "maxBytes", 0, 1073741824, p);
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
if ("memory" in value2) {
|
|
2341
|
-
const p = at2(path2, "memory"), m = value2.memory;
|
|
2342
|
-
if (!isObject(m)) problem(p, "must be an object");
|
|
2343
|
-
else {
|
|
2344
|
-
const allowed = schema === 6 ? ["enabled", "policy"] : ["enabled", "policy", "maxTokens", "keepVerbatimTokens", "keepVerbatimTurns", "recallTokens", "prepareAfterMs", "activeMs", "foldMinTokens"];
|
|
2345
|
-
if (schema === 5) allowed.push("lowTokens", "summaryTokens", "answerFirst", "historyReach");
|
|
2346
|
-
for (const key of Object.keys(m)) if (!allowed.includes(key)) problem(at2(p, key), key === "recall" ? "memory.recall was removed: the model reads memories with memory recall" : key === "keys" ? "memory.keys was removed: Croche assigns memory ids; only the model writes memories" : key === "commands" ? 'memory.commands was removed: use crocheTools["memory.save"]' : "unknown field");
|
|
2347
|
-
if ("enabled" in m && typeof m.enabled !== "boolean") problem(at2(p, "enabled"), "must be a boolean");
|
|
2348
|
-
if (schema === 5) {
|
|
2349
|
-
for (const key of ["answerFirst", "historyReach"]) if (key in m && typeof m[key] !== "boolean") problem(at2(p, key), "must be a boolean");
|
|
2350
|
-
for (const key of ["lowTokens", "summaryTokens"]) range(m, key, 64, 16777216, p);
|
|
2351
|
-
}
|
|
2352
|
-
if ("policy" in m && (typeof m.policy !== "string" || [...m.policy].length > 4e3)) problem(at2(p, "policy"), "text of at most 4000 characters required");
|
|
2353
|
-
if (schema !== 6) for (const [field, min, max, zero] of [["maxTokens", 125, 16777216, false], ["keepVerbatimTokens", 0, 16777216, false], ["keepVerbatimTurns", 1, 200, false], ["recallTokens", 50, 16777216, false], ["foldMinTokens", 125, 16777216, false], ["prepareAfterMs", 3e4, 6048e5, true], ["activeMs", 6e4, 6048e5, true]]) range(m, field, min, max, p, zero);
|
|
2354
|
-
const prepare = Number(m.prepareAfterMs ?? (root ? 24e4 : 0)), active = Number(m.activeMs ?? (root ? 3e5 : 0));
|
|
2355
|
-
if (schema !== 6 && prepare > 0 && active > 0 && prepare >= active) problem(p, "prepareAfterMs must be shorter than activeMs");
|
|
2356
|
-
}
|
|
2357
|
-
}
|
|
2358
|
-
if ("wiki" in value2) {
|
|
2359
|
-
const p = at2(path2, "wiki"), w = value2.wiki;
|
|
2360
|
-
if (!isObject(w)) problem(p, "must be an object");
|
|
2361
|
-
else {
|
|
2362
|
-
for (const key of Object.keys(w)) if (!["docs", "include", "exclude"].includes(key)) problem(at2(p, key), "unknown field");
|
|
2363
|
-
let globBytes = 0;
|
|
2364
|
-
for (const field of ["include", "exclude"]) if (field in w) {
|
|
2365
|
-
const globs = w[field];
|
|
2366
|
-
if (!Array.isArray(globs) || globs.length > 50 || globs.some((g) => typeof g !== "string" || !g.length)) problem(at2(p, field), "up to 50 nonempty globs required");
|
|
2367
|
-
else globBytes += globs.reduce((n, g) => n + new TextEncoder().encode(g).length + 1, 0);
|
|
2368
|
-
}
|
|
2369
|
-
if (globBytes > 256) problem(p, "combined glob automaton exceeds 256 bytes");
|
|
2370
|
-
if ("docs" in w) {
|
|
2371
|
-
if (!Array.isArray(w.docs) || w.docs.length > 2e3) problem(at2(p, "docs"), "up to 2000 documents required");
|
|
2372
|
-
else w.docs.forEach((doc, i) => {
|
|
2373
|
-
const dp = at2(at2(p, "docs"), i);
|
|
2374
|
-
if (!isObject(doc)) {
|
|
2375
|
-
problem(dp, "must be an object");
|
|
2376
|
-
return;
|
|
2377
|
-
}
|
|
2378
|
-
for (const key of Object.keys(doc)) if (!["path", "markdown", "agents"].includes(key)) problem(at2(dp, key), "unknown field");
|
|
2379
|
-
const cleaned = typeof doc.path === "string" ? doc.path.trim().replaceAll("\\", "/") : "";
|
|
2380
|
-
if (!cleaned || new TextEncoder().encode(cleaned).length > 256 || cleaned.startsWith("/") || cleaned.endsWith("/") || /[\u0000-\u001f\u007f-\u009f]/.test(cleaned) || cleaned.split("/").some((s) => !s || s === "." || s === "..") || typeof doc.path === "string" && doc.path.startsWith("user/")) problem(at2(dp, "path"), "invalid app wiki path");
|
|
2381
|
-
if (typeof doc.markdown !== "string" || new TextEncoder().encode(doc.markdown).length > 65536) problem(at2(dp, "markdown"), "text of at most 65536 bytes required");
|
|
2382
|
-
if ("agents" in doc && (!Array.isArray(doc.agents) || doc.agents.some((a) => typeof a !== "string"))) problem(at2(dp, "agents"), "must be an array of strings");
|
|
2383
|
-
});
|
|
2384
|
-
}
|
|
2385
|
-
}
|
|
2386
|
-
}
|
|
2387
|
-
if (root && "defaultLanguage" in value2 && !languageTag(value2.defaultLanguage)) problem(at2(path2, "defaultLanguage"), "invalid language tag");
|
|
2388
|
-
if ("name" in value2 && (typeof value2.name !== "string" || !value2.name.length || value2.name.length > 100)) problem(at2(path2, "name"), "1\u2013100 characters required");
|
|
2389
|
-
if ("fallbacks" in value2) {
|
|
2390
|
-
if (typeof schema !== "number" || schema < 5) problem(at2(path2, "fallbacks"), "unknown field");
|
|
2391
|
-
else if (!Array.isArray(value2.fallbacks) || value2.fallbacks.length > 4 || value2.fallbacks.some((id) => !configModelId(id)) || new Set(value2.fallbacks).size !== value2.fallbacks.length) problem(at2(path2, "fallbacks"), "at most 4 distinct nonempty model ids required");
|
|
2392
|
-
}
|
|
2393
|
-
if ("model" in value2 && !configModelId(value2.model)) problem(at2(path2, "model"), "nonempty model id required");
|
|
2394
|
-
if ("reasoning" in value2 && (typeof value2.reasoning !== "string" || !REASONING_LEVELS.includes(value2.reasoning))) problem(at2(path2, "reasoning"), "must be default, off, low, medium or high");
|
|
2395
|
-
if ("toolGuide" in value2 && typeof value2.toolGuide !== "string") problem(at2(path2, "toolGuide"), "must be a string");
|
|
2396
|
-
if ("tools" in value2) toolList(value2.tools, at2(path2, "tools"));
|
|
2397
|
-
if ("schedule" in value2) {
|
|
2398
|
-
const p = at2(path2, "schedule");
|
|
2399
|
-
if (!isObject(value2.schedule)) problem(p, "must be an object");
|
|
2400
|
-
else for (const k of Object.keys(value2.schedule)) problem(at2(p, k), k === "commands" ? 'schedule.commands was removed: use crocheTools["schedule"]' : "unknown field");
|
|
2401
|
-
}
|
|
2402
|
-
if ("heartbeat" in value2) {
|
|
2403
|
-
const p = at2(path2, "heartbeat");
|
|
2404
|
-
if (!isObject(value2.heartbeat)) problem(p, "must be an object");
|
|
2405
|
-
else {
|
|
2406
|
-
for (const k of Object.keys(value2.heartbeat)) if (k !== "everyMs") problem(at2(p, k), "unknown field");
|
|
2407
|
-
const ms = value2.heartbeat.everyMs;
|
|
2408
|
-
if (!Number.isSafeInteger(ms) || Number(ms) < 9e5 || Number(ms) > 864e5) problem(at2(p, "everyMs"), "integer from 900000 to 86400000 required");
|
|
2409
|
-
}
|
|
2410
|
-
}
|
|
2411
|
-
if ("modes" in value2) {
|
|
2412
|
-
const p = at2(path2, "modes");
|
|
2413
|
-
if (!isObject(value2.modes)) problem(p, "must be an object");
|
|
2414
|
-
else for (const [name, mode] of Object.entries(value2.modes)) {
|
|
2415
|
-
const m = at2(p, name);
|
|
2416
|
-
if (!/^[A-Za-z0-9_.:-]{1,64}$/.test(name)) problem(m, "invalid mode name");
|
|
2417
|
-
if (!isObject(mode)) {
|
|
2418
|
-
problem(m, "must be an object");
|
|
2419
|
-
continue;
|
|
2420
|
-
}
|
|
2421
|
-
for (const k of Object.keys(mode)) if (!["tools", "toolGuide"].includes(k)) problem(at2(m, k), "unknown field");
|
|
2422
|
-
if ("toolGuide" in mode && typeof mode.toolGuide !== "string") problem(at2(m, "toolGuide"), "must be a string");
|
|
2423
|
-
if ("tools" in mode) toolList(mode.tools, at2(m, "tools"));
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
if (!language && "languages" in value2) {
|
|
2427
|
-
const p = at2(path2, "languages");
|
|
2428
|
-
if (!isObject(value2.languages)) problem(p, "must be an object");
|
|
2429
|
-
else {
|
|
2430
|
-
if (!Object.keys(value2.languages).length) problem(p, "must be a nonempty object");
|
|
2431
|
-
const tags = /* @__PURE__ */ new Set();
|
|
2432
|
-
for (const tag of Object.keys(value2.languages).sort()) {
|
|
2433
|
-
if (!languageTag(tag)) problem(at2(p, tag), "invalid language tag");
|
|
2434
|
-
const folded = asciiFold(tag);
|
|
2435
|
-
if (tags.has(folded)) problem(at2(p, tag), "duplicate language tag");
|
|
2436
|
-
tags.add(folded);
|
|
2437
|
-
if (folded === asciiFold(defaultLanguage)) problem(at2(p, tag), "default language belongs in config");
|
|
2438
|
-
configLayer(value2.languages[tag], at2(p, tag), agent, false, depth + 1, true);
|
|
2439
|
-
}
|
|
2440
|
-
}
|
|
2441
|
-
}
|
|
2442
|
-
if (root && "agents" in value2) {
|
|
2443
|
-
if (!isObject(value2.agents)) problem(at2(path2, "agents"), "must be an object");
|
|
2444
|
-
else Object.entries(value2.agents).forEach(([id, v]) => {
|
|
2445
|
-
const p = at2(at2(path2, "agents"), id);
|
|
2446
|
-
if (!/^[A-Za-z0-9_.:-]{1,200}$/.test(id)) problem(p, "invalid id");
|
|
2447
|
-
configLayer(v, p, true, false, depth + 1);
|
|
2448
|
-
});
|
|
2449
|
-
}
|
|
2450
|
-
};
|
|
2451
|
-
configLayer(config, "/config", false, true);
|
|
2452
|
-
if (problems.length) fail(400, "invalid_configuration", "Project config is invalid.", { problems });
|
|
2453
|
-
return { encoded, declarations, tools };
|
|
2454
|
-
}
|
|
2455
|
-
async function documentIdentity(document, write) {
|
|
2456
|
-
const { encoded, declarations, tools } = validateDocumentShape(document, write);
|
|
2457
|
-
const commands2 = [];
|
|
2458
|
-
for (const { tool, command } of declarations) {
|
|
2459
|
-
const hash = await shapeHash(command);
|
|
2460
|
-
if (!commands2.some((c) => c.tool === tool && c.key === command.key && c.shape_hash === hash)) commands2.push({ tool, key: String(command.key), shape_hash: hash });
|
|
2461
|
-
}
|
|
2462
|
-
return { id: "sha256:" + await sha256(encoded), schema: Number(document.schema), document: encoded, commands: commands2, tools: [...tools] };
|
|
2463
|
-
}
|
|
2464
|
-
var validateDocument = (document) => documentIdentity(document, true);
|
|
2465
2047
|
|
|
2466
2048
|
// src/config-authoring.ts
|
|
2467
|
-
var
|
|
2468
|
-
var
|
|
2469
|
-
var at = (path2, key) => path2 + "/" +
|
|
2049
|
+
var object = (value2) => value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
|
|
2050
|
+
var pointer2 = (key) => key.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
2051
|
+
var at = (path2, key) => path2 + "/" + pointer2(key);
|
|
2470
2052
|
var entries = (row2) => Object.keys(row2).sort().map((key) => [key, row2[key]]);
|
|
2471
|
-
var reference = (value2) =>
|
|
2472
|
-
function issue(file, path2, reason) {
|
|
2473
|
-
throw new CliError(
|
|
2053
|
+
var reference = (value2) => object(value2) && Object.hasOwn(value2, "$file");
|
|
2054
|
+
function issue(file, path2, reason, code = "invalid_configuration") {
|
|
2055
|
+
throw new CliError(code, `${file}${path2 ? `#${path2}` : ""}: ${reason}`, 2, { problems: [{ file, path: path2, reason }] });
|
|
2474
2056
|
}
|
|
2475
2057
|
function referencePath(value2, source) {
|
|
2476
2058
|
if (typeof value2 !== "string" || !value2 || isAbsolute3(value2) || win32.isAbsolute(value2) || value2.includes("\\") || value2.split("/").some((p) => !p || p === "." || p === "..") || /[\u0000-\u001f]/.test(value2))
|
|
@@ -2497,35 +2079,40 @@ function json(value2, file) {
|
|
|
2497
2079
|
issue(file, "", "Invalid JSON.");
|
|
2498
2080
|
}
|
|
2499
2081
|
}
|
|
2500
|
-
async function
|
|
2501
|
-
if (
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
if (object2(layer.memory) && "policy" in layer.memory) await visit(layer.memory, "policy", at(at(path2, "memory"), "policy"));
|
|
2505
|
-
if (object2(layer.modes)) {
|
|
2506
|
-
for (const [id, mode] of entries(layer.modes)) if (object2(mode) && "toolGuide" in mode) await visit(mode, "toolGuide", at(at(at(path2, "modes"), id), "toolGuide"));
|
|
2082
|
+
async function visitWording(layer, path2, visit) {
|
|
2083
|
+
if (!object(layer)) return;
|
|
2084
|
+
for (const field of ["instructions", "toolGuide", "wikiGuide"]) {
|
|
2085
|
+
if (Object.hasOwn(layer, field)) await visit(layer, field, at(path2, field));
|
|
2507
2086
|
}
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2087
|
+
}
|
|
2088
|
+
async function visitAgents(agents, visit, agent) {
|
|
2089
|
+
if (!object(agents)) return;
|
|
2090
|
+
for (const id of Object.keys(agents).sort()) {
|
|
2091
|
+
const path2 = at("/agents", id);
|
|
2092
|
+
await agent(agents, id, path2);
|
|
2093
|
+
const layer = agents[id];
|
|
2094
|
+
if (!object(layer)) continue;
|
|
2095
|
+
await visitWording(layer, path2, visit);
|
|
2096
|
+
if (object(layer.memory) && Object.hasOwn(layer.memory, "policy")) await visit(layer.memory, "policy", at(at(path2, "memory"), "policy"));
|
|
2097
|
+
if (object(layer.languages)) for (const [tag, wording] of entries(layer.languages)) {
|
|
2098
|
+
await visitWording(wording, at(at(path2, "languages"), tag), visit);
|
|
2099
|
+
}
|
|
2513
2100
|
}
|
|
2514
2101
|
}
|
|
2515
|
-
|
|
2102
|
+
function locate(path2, sources, fallback) {
|
|
2103
|
+
let prefix = path2;
|
|
2104
|
+
while (prefix && !sources.has(prefix)) prefix = prefix.slice(0, prefix.lastIndexOf("/"));
|
|
2105
|
+
const source = sources.get(prefix) ?? { file: fallback, pointer: "" };
|
|
2106
|
+
return { file: source.file, pointer: source.pointer + path2.slice(prefix.length) };
|
|
2107
|
+
}
|
|
2108
|
+
async function validate(raw, sources, fallback) {
|
|
2109
|
+
const { validateBundleIdentity } = await import("./config-push-base-E2TEF3ZJ.js");
|
|
2516
2110
|
try {
|
|
2517
|
-
return
|
|
2111
|
+
return validateBundleIdentity(raw);
|
|
2518
2112
|
} catch (error) {
|
|
2519
|
-
if (!(error instanceof
|
|
2520
|
-
const
|
|
2521
|
-
|
|
2522
|
-
const located = problems.map((p) => {
|
|
2523
|
-
let prefix = p.path;
|
|
2524
|
-
while (!sources.has(prefix) && prefix) prefix = prefix.slice(0, prefix.lastIndexOf("/"));
|
|
2525
|
-
const source = sources.get(prefix) ?? { file: fallback, pointer: "" };
|
|
2526
|
-
return { file: source.file, path: source.pointer + p.path.slice(prefix.length), reason: p.reason };
|
|
2527
|
-
});
|
|
2528
|
-
throw new CliError(error.code, located.map((p) => `${p.file}#${p.path}: ${p.reason}`).join("\n"), 2, { problems: located });
|
|
2113
|
+
if (!(error instanceof CliError)) throw error;
|
|
2114
|
+
const { file, pointer: pointer3 } = locate(error.details?.path ?? "", sources, fallback);
|
|
2115
|
+
issue(file, pointer3, error.message);
|
|
2529
2116
|
}
|
|
2530
2117
|
}
|
|
2531
2118
|
async function buildConfig(directory) {
|
|
@@ -2538,10 +2125,7 @@ async function buildConfig(directory) {
|
|
|
2538
2125
|
const project2 = join3(root, "project.json");
|
|
2539
2126
|
const sources = /* @__PURE__ */ new Map([["", { file: project2, pointer: "" }]]);
|
|
2540
2127
|
const load = async (value2, path2) => {
|
|
2541
|
-
|
|
2542
|
-
while (!sources.has(prefix) && prefix) prefix = prefix.slice(0, prefix.lastIndexOf("/"));
|
|
2543
|
-
const parent = sources.get(prefix) ?? { file: project2, pointer: "" };
|
|
2544
|
-
const source = { file: parent.file, pointer: parent.pointer + path2.slice(prefix.length) };
|
|
2128
|
+
const source = locate(path2, sources, project2);
|
|
2545
2129
|
if (Object.keys(value2).length !== 1) issue(source.file, source.pointer, "A file reference must contain only $file.");
|
|
2546
2130
|
const name = referencePath(value2.$file, source);
|
|
2547
2131
|
let file;
|
|
@@ -2561,7 +2145,7 @@ async function buildConfig(directory) {
|
|
|
2561
2145
|
const ref = row2[key];
|
|
2562
2146
|
const loaded = await load(ref, path2);
|
|
2563
2147
|
const parsed = json(loaded.value, loaded.file);
|
|
2564
|
-
if (
|
|
2148
|
+
if (object(parsed) && Object.hasOwn(parsed, "id") && Object.hasOwn(parsed, "config")) {
|
|
2565
2149
|
for (const field of Object.keys(parsed)) if (!["id", "config"].includes(field)) issue(loaded.file, at("", field), "Unknown agent file field.");
|
|
2566
2150
|
if (parsed.id !== key) issue(loaded.file, "/id", "Agent id must match the project.json agent key.");
|
|
2567
2151
|
row2[key] = parsed.config;
|
|
@@ -2569,38 +2153,36 @@ async function buildConfig(directory) {
|
|
|
2569
2153
|
} else row2[key] = parsed;
|
|
2570
2154
|
if (reference(row2[key])) issue(loaded.file, "", "Agent files must contain a config layer, not another reference.");
|
|
2571
2155
|
};
|
|
2572
|
-
|
|
2156
|
+
await visitAgents(object(document) ? document.agents : void 0, async (row2, key, path2) => {
|
|
2573
2157
|
if (reference(row2[key])) row2[key] = (await load(row2[key], path2)).value;
|
|
2574
2158
|
}, agent);
|
|
2575
|
-
let
|
|
2159
|
+
let encoded;
|
|
2576
2160
|
try {
|
|
2577
|
-
|
|
2161
|
+
encoded = canonical(document);
|
|
2578
2162
|
} catch (error) {
|
|
2579
|
-
if (error instanceof
|
|
2580
|
-
|
|
2163
|
+
if (!(error instanceof CanonicalError)) throw error;
|
|
2164
|
+
const { file, pointer: pointer3 } = locate(error.path, sources, project2);
|
|
2165
|
+
issue(file, pointer3, error.message);
|
|
2581
2166
|
}
|
|
2582
|
-
const
|
|
2583
|
-
return { id
|
|
2167
|
+
const id = await validate(encoded, sources, project2);
|
|
2168
|
+
return { id, schema: document.schema, document: encoded };
|
|
2584
2169
|
}
|
|
2585
2170
|
async function splitConfig(file, directory) {
|
|
2586
|
-
const
|
|
2587
|
-
|
|
2171
|
+
const raw = await text(file);
|
|
2172
|
+
const document = json(raw, file);
|
|
2173
|
+
const agents = object(document) ? document.agents : void 0;
|
|
2174
|
+
const refuse = async (row2, key, path2) => {
|
|
2588
2175
|
if (reference(row2[key])) {
|
|
2589
2176
|
referencePath(row2[key].$file, { file, pointer: path2 });
|
|
2590
2177
|
issue(file, path2, "A snapshot cannot contain an authoring reference.");
|
|
2591
2178
|
}
|
|
2592
|
-
}
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
issue(file, path2, "A snapshot cannot contain an authoring reference.");
|
|
2596
|
-
}
|
|
2597
|
-
});
|
|
2598
|
-
const result = await validate(document, /* @__PURE__ */ new Map(), file);
|
|
2599
|
-
if (object2(document)) delete document.requires;
|
|
2179
|
+
};
|
|
2180
|
+
await visitAgents(agents, refuse, refuse);
|
|
2181
|
+
const id = await validate(raw.charCodeAt(0) === 65279 ? raw.slice(1) : raw, /* @__PURE__ */ new Map(), file);
|
|
2600
2182
|
const files = /* @__PURE__ */ new Map();
|
|
2601
2183
|
const manifest = {};
|
|
2602
2184
|
let textIndex = 0, agentIndex = 0;
|
|
2603
|
-
|
|
2185
|
+
await visitAgents(agents, async (row2, key, path2) => {
|
|
2604
2186
|
if (typeof row2[key] !== "string") return;
|
|
2605
2187
|
const name = `text/${String(++textIndex).padStart(6, "0")}.txt`;
|
|
2606
2188
|
manifest[name] = { path: path2 };
|
|
@@ -2608,12 +2190,12 @@ async function splitConfig(file, directory) {
|
|
|
2608
2190
|
row2[key] = { $file: name };
|
|
2609
2191
|
}, async () => {
|
|
2610
2192
|
});
|
|
2611
|
-
if (
|
|
2612
|
-
for (const [
|
|
2193
|
+
if (object(agents)) {
|
|
2194
|
+
for (const [id2, layer] of entries(agents)) {
|
|
2613
2195
|
const name = `agents/${String(++agentIndex).padStart(6, "0")}.json`;
|
|
2614
|
-
manifest[name] = { path: at("/
|
|
2615
|
-
files.set(name, JSON.stringify({ id, config: layer }, null, 2) + "\n");
|
|
2616
|
-
|
|
2196
|
+
manifest[name] = { path: at("/agents", id2), id: id2 };
|
|
2197
|
+
files.set(name, JSON.stringify({ id: id2, config: layer }, null, 2) + "\n");
|
|
2198
|
+
agents[id2] = { $file: name };
|
|
2617
2199
|
}
|
|
2618
2200
|
}
|
|
2619
2201
|
files.set("manifest.json", JSON.stringify({ schema: 1, files: manifest }, null, 2) + "\n");
|
|
@@ -2635,7 +2217,7 @@ async function splitConfig(file, directory) {
|
|
|
2635
2217
|
await rm(output, { recursive: true, force: true });
|
|
2636
2218
|
throw error;
|
|
2637
2219
|
}
|
|
2638
|
-
return { directory: output, revision_id:
|
|
2220
|
+
return { directory: output, revision_id: id, schema: document.schema };
|
|
2639
2221
|
}
|
|
2640
2222
|
async function authoringCommand(action, args) {
|
|
2641
2223
|
if (!args.output) throw new CliError("missing_argument", "Supply --output.");
|
|
@@ -2652,20 +2234,22 @@ async function authoringCommand(action, args) {
|
|
|
2652
2234
|
// src/core-defaults.ts
|
|
2653
2235
|
var DEFAULT_CLOUD_URL = "https://api.croche.ai";
|
|
2654
2236
|
|
|
2655
|
-
// src/
|
|
2237
|
+
// src/development-keys.ts
|
|
2656
2238
|
import { appendFile, lstat as lstat3, open as open3, readFile as readFile4, realpath as realpath2, rename as rename3, unlink as unlink3 } from "node:fs/promises";
|
|
2657
2239
|
import { execFile } from "node:child_process";
|
|
2658
2240
|
import { promisify } from "node:util";
|
|
2659
2241
|
import { basename, dirname as dirname4, relative as relative2, resolve as resolve3, sep as sep2 } from "node:path";
|
|
2660
2242
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
2661
2243
|
var exec = promisify(execFile);
|
|
2662
|
-
var assignment = /^(?:export[ \t]+)?
|
|
2244
|
+
var assignment = /^(?:export[ \t]+)?CROCHE_DEVELOPMENT_KEY[ \t]*=([^\r\n]*)(\r?)$/gm;
|
|
2245
|
+
var retiredAssignment = /^(?:export[ \t]+)?CROCHE_DEBUG_KEY[ \t]*=/m;
|
|
2246
|
+
var developmentKeyEnvRename = "CROCHE_DEBUG_KEY was renamed to CROCHE_DEVELOPMENT_KEY";
|
|
2663
2247
|
var value = (line2) => line2.trim().replace(/^(['"])(.*)\1$/, "$2");
|
|
2664
2248
|
async function git(root, args) {
|
|
2665
2249
|
try {
|
|
2666
2250
|
return (await exec("git", ["-C", root, ...args])).stdout.trim();
|
|
2667
2251
|
} catch (error) {
|
|
2668
|
-
if (error.code === "ENOENT") throw new CliError("git_unavailable", "Git is required to protect the
|
|
2252
|
+
if (error.code === "ENOENT") throw new CliError("git_unavailable", "Git is required to protect the development-key file.");
|
|
2669
2253
|
return null;
|
|
2670
2254
|
}
|
|
2671
2255
|
}
|
|
@@ -2687,12 +2271,14 @@ async function target(file, force, stderr) {
|
|
|
2687
2271
|
let ignore;
|
|
2688
2272
|
if (root) {
|
|
2689
2273
|
const entry = relative2(root, path2).split(sep2).join("/");
|
|
2690
|
-
if (await git(root, ["ls-files", "--error-unmatch", "--", entry]) !== null) throw new CliError("tracked_env_file", "Refusing to write a
|
|
2274
|
+
if (await git(root, ["ls-files", "--error-unmatch", "--", entry]) !== null) throw new CliError("tracked_env_file", "Refusing to write a development key into a tracked file.");
|
|
2691
2275
|
if (await git(root, ["check-ignore", "--", entry]) === null) ignore = { root, entry };
|
|
2692
2276
|
}
|
|
2693
|
-
const
|
|
2694
|
-
|
|
2695
|
-
if (existing.
|
|
2277
|
+
const contents = before?.toString("latin1") ?? "";
|
|
2278
|
+
const existing = [...contents.matchAll(assignment)];
|
|
2279
|
+
if (existing.length === 0 && retiredAssignment.test(contents)) throw new CliError("invalid_env_file", developmentKeyEnvRename);
|
|
2280
|
+
if (existing.length > 1) throw new CliError("invalid_env_file", "The env file contains multiple CROCHE_DEVELOPMENT_KEY assignments.");
|
|
2281
|
+
if (existing.some((match) => value(match[1]) !== "") && !force) throw new CliError("development_key_exists", "CROCHE_DEVELOPMENT_KEY is already set; use --force to replace it. No key was issued.");
|
|
2696
2282
|
if (before && mode & 63) stderr("warning: the existing env file is group- or world-readable; its mode will be preserved.\n");
|
|
2697
2283
|
return { path: path2, before, mode, ignore };
|
|
2698
2284
|
}
|
|
@@ -2708,13 +2294,13 @@ async function ignoreFile(t) {
|
|
|
2708
2294
|
const entry = "/" + t.ignore.entry.replace(/[\\*?\[\]#! ]/g, "\\$&");
|
|
2709
2295
|
await appendFile(path2, (before && !before.endsWith("\n") ? "\n" : "") + entry + "\n");
|
|
2710
2296
|
}
|
|
2711
|
-
async function
|
|
2297
|
+
async function writeDevelopmentEnv(t, secret) {
|
|
2712
2298
|
const text2 = t.before?.toString("latin1") ?? "";
|
|
2713
2299
|
const matches = [...text2.matchAll(assignment)];
|
|
2714
2300
|
if (matches.length === 1 && value(matches[0][1]) === secret) return;
|
|
2715
2301
|
const newline = text2.includes("\r\n") ? "\r\n" : "\n";
|
|
2716
|
-
const updated = matches.length ? text2.replace(assignment, (_line, _old, cr) => `
|
|
2717
|
-
const temporary = resolve3(dirname4(t.path), `.croche-
|
|
2302
|
+
const updated = matches.length ? text2.replace(assignment, (_line, _old, cr) => `CROCHE_DEVELOPMENT_KEY=${secret}${cr}`) : text2 + (text2 && !text2.endsWith("\n") ? newline : "") + `CROCHE_DEVELOPMENT_KEY=${secret}${newline}`;
|
|
2303
|
+
const temporary = resolve3(dirname4(t.path), `.croche-development-${randomUUID3()}.tmp`);
|
|
2718
2304
|
let handle;
|
|
2719
2305
|
try {
|
|
2720
2306
|
handle = await open3(temporary, "wx", 384);
|
|
@@ -2740,34 +2326,34 @@ async function writeDebugEnv(t, secret) {
|
|
|
2740
2326
|
}
|
|
2741
2327
|
}
|
|
2742
2328
|
}
|
|
2743
|
-
async function
|
|
2329
|
+
async function developmentKeys(action, args, client) {
|
|
2744
2330
|
const project2 = args.project;
|
|
2745
2331
|
if (!project2 || !/^[A-Za-z0-9_.:-]{1,200}$/.test(project2)) throw new CliError("missing_argument", "Supply --project with a project id.");
|
|
2746
2332
|
const path2 = `/api/studio/projects/${encodeURIComponent(project2)}/debug-tokens`;
|
|
2747
2333
|
const metadata = (t) => ({ id: t.id, name: t.name, prefix: typeof t.prefix === "string" ? t.prefix.slice(0, 12) : t.prefix, created_at: t.created_at, last_used_at: t.last_used_at, revoked_at: t.revoked_at, installations: t.installations, warning: t.warning });
|
|
2748
2334
|
if (action === "list") {
|
|
2749
2335
|
const result2 = await client.request(path2);
|
|
2750
|
-
return {
|
|
2336
|
+
return { development_keys: result2.debug_tokens.map(metadata) };
|
|
2751
2337
|
}
|
|
2752
2338
|
if (action === "revoke") {
|
|
2753
|
-
if (!args["key-id"] || !/^[A-Za-z0-9_.:-]{1,200}$/.test(args["key-id"])) throw new CliError("missing_argument", "Supply a
|
|
2339
|
+
if (!args["key-id"] || !/^[A-Za-z0-9_.:-]{1,200}$/.test(args["key-id"])) throw new CliError("missing_argument", "Supply a development key id.");
|
|
2754
2340
|
const result2 = await client.request(path2 + "/" + encodeURIComponent(args["key-id"]), "DELETE");
|
|
2755
|
-
return {
|
|
2341
|
+
return { development_key: metadata(result2.debug_token) };
|
|
2756
2342
|
}
|
|
2757
2343
|
const stderr = client.context.stderr ?? ((text2) => process.stderr.write(text2));
|
|
2758
2344
|
const destination = args.print === "true" && !args["dotenv-file"] ? void 0 : await target(args["dotenv-file"] ?? "./.env", args.force === "true", stderr);
|
|
2759
2345
|
if (destination) await ignoreFile(destination);
|
|
2760
2346
|
const result = await client.request(path2, "POST", { name: args.name ?? "Coding agent" });
|
|
2761
2347
|
const key = metadata(result.debug_token);
|
|
2762
|
-
if (typeof result.secret !== "string" || !/^cdt_[a-f0-9]{64}$/.test(result.secret)) throw new CliError("invalid_response", `Cloud returned an invalid
|
|
2348
|
+
if (typeof result.secret !== "string" || !/^cdt_[a-f0-9]{64}$/.test(result.secret)) throw new CliError("invalid_response", `Cloud returned an invalid development key; revoke issued key ${key.id}.`, 1);
|
|
2763
2349
|
if (destination) {
|
|
2764
2350
|
try {
|
|
2765
|
-
await
|
|
2351
|
+
await writeDevelopmentEnv(destination, result.secret);
|
|
2766
2352
|
} catch {
|
|
2767
|
-
throw new CliError("env_write_failed", `Could not safely write the env file. Revoke issued key ${key.id} with
|
|
2353
|
+
throw new CliError("env_write_failed", `Could not safely write the env file. Revoke issued key ${key.id} with development-keys revoke.`, 1, { key_id: key.id });
|
|
2768
2354
|
}
|
|
2769
2355
|
}
|
|
2770
|
-
return {
|
|
2356
|
+
return { development_key: key, ...destination ? { dotenv_file: destination.path } : {}, ...args.print === "true" ? { secret: result.secret } : {} };
|
|
2771
2357
|
}
|
|
2772
2358
|
|
|
2773
2359
|
// src/index.ts
|
|
@@ -2803,12 +2389,30 @@ var project = (args) => `/api/studio/projects/${segment(required(args, "project"
|
|
|
2803
2389
|
function projectBody(args) {
|
|
2804
2390
|
return args.name !== void 0 ? { name: args.name } : {};
|
|
2805
2391
|
}
|
|
2392
|
+
async function listRuntimes(path2, client) {
|
|
2393
|
+
const runtimes = [], query = new URLSearchParams({ limit: "100" }), seen = /* @__PURE__ */ new Set();
|
|
2394
|
+
for (; ; ) {
|
|
2395
|
+
const page = await client.request(`${path2}?${query}`);
|
|
2396
|
+
if (!Array.isArray(page?.runtimes) || typeof page.has_more !== "boolean")
|
|
2397
|
+
throw new CliError("invalid_response", "Cloud returned an invalid installations page.", 4);
|
|
2398
|
+
runtimes.push(...page.runtimes);
|
|
2399
|
+
if (!page.has_more) return { ...page, runtimes };
|
|
2400
|
+
const { last_seen_at: before, runtime_instance_id: beforeId } = page.next_cursor ?? {};
|
|
2401
|
+
if (typeof before !== "string" || !before || typeof beforeId !== "string" || !beforeId)
|
|
2402
|
+
throw new CliError("invalid_response", "Cloud returned an invalid installations cursor.", 4);
|
|
2403
|
+
const cursor = JSON.stringify([before, beforeId]);
|
|
2404
|
+
if (seen.has(cursor)) throw new CliError("invalid_response", "Cloud repeated an installations cursor.", 4);
|
|
2405
|
+
seen.add(cursor);
|
|
2406
|
+
query.set("before", before);
|
|
2407
|
+
query.set("before_id", beforeId);
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2806
2410
|
var localCommands = ["agents list", "status", "history", "send", "cancel", "tools"];
|
|
2807
2411
|
var commandTable = [
|
|
2808
2412
|
{ path: "config bases", summary: "List known and unknown bundled bases, installation counts, and upload instructions.", flags: ["project", "cloud-url"], run: (a, c) => listBases(a, c) },
|
|
2809
|
-
{ path: "config push-base", summary: "Upload one validated bundled config as an immutable base; does not publish a release.", positionals: ["file"], flags: ["project", "cloud-url"], run: async (a, c) => (await import("./config-push-base-
|
|
2413
|
+
{ path: "config push-base", summary: "Upload one validated bundled config as an immutable base; does not publish a release.", positionals: ["file"], flags: ["project", "cloud-url"], run: async (a, c) => (await import("./config-push-base-E2TEF3ZJ.js")).pushBase(a, c) },
|
|
2810
2414
|
...["build", "split"].map((action) => ({ path: `config ${action}`, summary: action === "build" ? "Build one validated snapshot from project.json and referenced agent/text files; unknown fields are refused with their source path." : "Split a snapshot into bounded numbered files and an id manifest in a new directory.", positionals: [action === "build" ? "directory" : "file"], flags: ["output"], run: (a) => authoringCommand(action, a) })),
|
|
2811
|
-
...["create", "list", "revoke"].map((action) => ({ path: `
|
|
2415
|
+
...["create", "list", "revoke"].map((action) => ({ path: `development-keys ${action}`, summary: { create: "Issue a development key and safely write CROCHE_DEVELOPMENT_KEY to .env; the secret is hidden unless --print is explicit.", list: "List development-key metadata without secrets.", revoke: "Revoke a development key." }[action], positionals: action === "revoke" ? ["key-id"] : [], flags: ["project", ...action === "create" ? ["name", "dotenv-file"] : []], switches: action === "create" ? ["force", "print"] : [], run: (a, c) => developmentKeys(action, a, c) })),
|
|
2812
2416
|
...["choose", "start", "stop", "status", "connect", "disconnect", "token", "runtimes"].map((action) => ({ path: action === "choose" ? "debug" : `debug ${action}`, summary: { choose: "Discover local Runtimes and select one interactively; automation gets a list. --studio-link prints a fresh one-time Studio link instead.", start: "Start or reuse the bundled local debugger without clearing captures, and print a one-time Studio link.", stop: "Stop the local debugger that debug start launched (its captures are discarded); the pairing token is kept. Not running is success.", status: "Inspect local debugger availability without printing credentials.", connect: "Observe an app-consented v2 attachment and print its viewer URL without a token.", disconnect: "Explain app-owned detachment; a viewer cannot change app consent.", token: "Explicitly reveal one saved credential: --role pairing (default), ingest, observe, or controller.", runtimes: "List local Runtimes and their debugger capability." }[action], flags: ["port", "connection-file", ...action === "stop" ? [] : ["control-connection-file"], ...["connect", "disconnect"].includes(action) ? ["attachment-id"] : [], ...["choose", "start", "connect"].includes(action) ? ["studio-origin"] : [], ...action === "start" ? ["remote", "allow-origin"] : [], ...action === "token" ? ["role"] : []], switches: action === "choose" ? ["studio-link"] : [], run: (a, c) => debugCommand(action, a, { env: c.env, fetch: c.context.fetch, selectRuntime: c.context.selectRuntime, launch: c.context.launchDebuggerService }) })),
|
|
2813
2417
|
...["get", "save", "list", "effective"].map((action) => ({ path: `config ${action}`, summary: { get: "Read a build-base-scoped draft or revision/version; --bundled-base selects the build base.", save: "Save a schema-7 patch; --base is the last read draft revision (CAS), --bundled-base is the build base.", list: "List versions and draft for --bundled-base (the build base).", effective: "Preview the latest released config applied to --bundled-base." }[action], positionals: action === "save" ? ["file"] : [], flags: ["project", "cloud-url", "bundled-base", ...{ get: ["revision", "version", "output"], save: ["base", "note"], list: [], effective: [] }[action]], run: (a, c) => configCommand(action, a, { ...c, writeFile: c.context.writeFile, stderr: c.context.stderr ?? ((text2) => process.stderr.write(text2)) }) })),
|
|
2814
2418
|
{ path: "login", summary: "Human-only: validate and save an account key from hidden terminal input or stdin. Never pass a key as an argument.", run: async (_, c) => {
|
|
@@ -2833,14 +2437,18 @@ var commandTable = [
|
|
|
2833
2437
|
{ path: "projects update", summary: "Rename a project or update routing from a JSON runtime policy file.", positionals: ["project"], flags: ["name", "policy-file"], run: async (a, c) => {
|
|
2834
2438
|
const body = projectBody(a);
|
|
2835
2439
|
if (a["policy-file"]) {
|
|
2440
|
+
let policy;
|
|
2836
2441
|
try {
|
|
2837
|
-
|
|
2838
|
-
if (!policy || typeof policy !== "object" || Array.isArray(policy) || Object.keys(policy).length !== 1 || !Object.hasOwn(policy, "routing")) throw new CliError("invalid_policy", "The runtime policy file may contain only routing. Change budgets, allowances and security settings in web Studio.");
|
|
2839
|
-
body.runtime_policy = policy;
|
|
2442
|
+
policy = JSON.parse(await c.readFile(a["policy-file"], "The runtime policy file"));
|
|
2840
2443
|
} catch (error) {
|
|
2841
2444
|
if (error instanceof CliError) throw error;
|
|
2842
2445
|
throw new CliError("invalid_file", "Runtime policy file must contain a readable JSON object.");
|
|
2843
2446
|
}
|
|
2447
|
+
if (!policy || typeof policy !== "object" || Array.isArray(policy) || !Object.keys(policy).length)
|
|
2448
|
+
throw new CliError("invalid_policy", "The runtime policy file may contain only routing. Change budgets, allowances and security settings in web Studio.");
|
|
2449
|
+
if (Object.keys(policy).some((key) => key !== "routing"))
|
|
2450
|
+
throw new CliError("invalid_policy", "Approve this action using a signed-in Studio session.");
|
|
2451
|
+
body.runtime_policy = policy;
|
|
2844
2452
|
}
|
|
2845
2453
|
if (!Object.keys(body).length) throw new CliError("missing_argument", "Supply at least one project setting.");
|
|
2846
2454
|
return c.request(project(a), "PATCH", body);
|
|
@@ -2850,22 +2458,32 @@ var commandTable = [
|
|
|
2850
2458
|
for (const flag of ["limit", "status", "type", "query"]) if (a[flag] !== void 0) query.set(flag === "query" ? "q" : flag, flag === "limit" ? String(integer2(a[flag], flag, 1, 500)) : a[flag]);
|
|
2851
2459
|
return c.request(`${project(a)}/operations?${query}`);
|
|
2852
2460
|
} },
|
|
2853
|
-
|
|
2461
|
+
// The statement counts only receipts Cloud has received, so a zero month can still hide unreported
|
|
2462
|
+
// usage. #1795 dropped this caveat with the all-time view; it still applies to the monthly statement.
|
|
2463
|
+
{ path: "projects cost", summary: "Show a project\u2019s UTC monthly statement. Purpose defaults to production and month defaults to the current month. Usage your runtimes have not reported yet is not included. Zero operations means no received reports, not free usage.", positionals: ["project"], flags: ["purpose", "month"], run: (a, c) => {
|
|
2854
2464
|
const purpose = a.purpose ?? "production";
|
|
2855
2465
|
if (!["production", "development"].includes(purpose)) throw new CliError("invalid_argument", "purpose must be production or development.");
|
|
2856
|
-
|
|
2466
|
+
const query = new URLSearchParams();
|
|
2467
|
+
if (a.purpose !== void 0) query.set("purpose", purpose);
|
|
2468
|
+
if (a.month !== void 0) {
|
|
2469
|
+
if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(a.month)) throw new CliError("invalid_argument", "month must be UTC YYYY-MM.");
|
|
2470
|
+
query.set("month", a.month);
|
|
2471
|
+
}
|
|
2472
|
+
return c.request(`${project(a)}/cost${query.size ? `?${query}` : ""}`);
|
|
2857
2473
|
} },
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2474
|
+
{ path: "keys development list", summary: "List a project's development keys with installations, last use and misuse warnings.", positionals: ["project"], run: async (a, c) => {
|
|
2475
|
+
const { debug_tokens, ...metadata } = await c.request(`${project(a)}/debug-tokens`);
|
|
2476
|
+
return { ...metadata, development_keys: debug_tokens };
|
|
2477
|
+
} },
|
|
2478
|
+
// Server keys are issued and revoked in Studio.
|
|
2479
|
+
{ path: "keys server list", summary: "List a project's server keys with installations, last use and Runtime Credit spent.", positionals: ["project"], run: (a, c) => c.request(`${project(a)}/server-keys`) },
|
|
2862
2480
|
{ path: "projects usage", summary: "Usage per end user and per agent, project budget left and the weekly development allowance left.", positionals: ["project"], flags: ["period"], run: (a, c) => {
|
|
2863
2481
|
const period = a.period ?? "month";
|
|
2864
|
-
if (
|
|
2482
|
+
if (period !== "week" && period !== "month" && !/^\d{4}-(0[1-9]|1[0-2])$/.test(period)) throw new CliError("invalid_argument", "period must be week, month, or UTC YYYY-MM.");
|
|
2865
2483
|
return c.request(`${project(a)}/usage?period=${period}`);
|
|
2866
2484
|
} },
|
|
2867
2485
|
{ path: "attestation get", summary: "Show the App Attest and Play Integrity settings (the decryption key is never returned).", positionals: ["project"], run: (a, c) => c.request(`${project(a)}/attestation`) },
|
|
2868
|
-
{ path: "runtimes list", summary: "List Cloud Runtime enrollments for a project.", flags: ["project"], run: (a, c) =>
|
|
2486
|
+
{ path: "runtimes list", summary: "List Cloud Runtime enrollments for a project.", flags: ["project"], run: (a, c) => listRuntimes(`${project(a)}/runtimes`, c) },
|
|
2869
2487
|
{ path: "control serve", summary: "Start a v2 loopback broker with distinct ingest/controller credentials.", flags: ["port", "allow-origin", "remote"], run: async (a, c) => {
|
|
2870
2488
|
if (!c.context.serveControl) throw new CliError("unavailable", "Control server is unavailable in this embedding.", 1);
|
|
2871
2489
|
const token = c.env.CROCHE_CONTROL_TOKEN, ingestToken = c.env.CROCHE_CONTROL_INGEST_TOKEN;
|
|
@@ -2901,7 +2519,7 @@ function help(prefix = "") {
|
|
|
2901
2519
|
return groupHelp(prefix, visible) + (exact ? "\n" + commandHelp(exact) : "");
|
|
2902
2520
|
}
|
|
2903
2521
|
function globalOptions(argv) {
|
|
2904
|
-
const
|
|
2522
|
+
const words = [];
|
|
2905
2523
|
let json2 = false, asking = false, version2 = false;
|
|
2906
2524
|
for (let index = 0; index < argv.length; index++) {
|
|
2907
2525
|
const token = argv[index];
|
|
@@ -2917,10 +2535,10 @@ function globalOptions(argv) {
|
|
|
2917
2535
|
asking = true;
|
|
2918
2536
|
continue;
|
|
2919
2537
|
}
|
|
2920
|
-
|
|
2921
|
-
if (token.startsWith("--") && !token.includes("=") && !commands.some((c) => c.switches?.includes(token.slice(2))) && index + 1 < argv.length)
|
|
2538
|
+
words.push(token);
|
|
2539
|
+
if (token.startsWith("--") && !token.includes("=") && !commands.some((c) => c.switches?.includes(token.slice(2))) && index + 1 < argv.length) words.push(argv[++index]);
|
|
2922
2540
|
}
|
|
2923
|
-
return { words
|
|
2541
|
+
return { words, json: json2, asking, version: version2 };
|
|
2924
2542
|
}
|
|
2925
2543
|
function cliVersion() {
|
|
2926
2544
|
try {
|
|
@@ -2930,16 +2548,17 @@ function cliVersion() {
|
|
|
2930
2548
|
}
|
|
2931
2549
|
}
|
|
2932
2550
|
function parse(argv, env) {
|
|
2933
|
-
const { words
|
|
2551
|
+
const { words, json: json2, asking, version: version2 } = globalOptions(argv);
|
|
2552
|
+
if (words[0] === "debug-keys") throw new CliError("unknown_command", "Use `croche development-keys`.");
|
|
2934
2553
|
if (version2 && !asking) return { args: {}, json: json2, version: cliVersion() };
|
|
2935
|
-
if (!
|
|
2936
|
-
const prefix =
|
|
2554
|
+
if (!words.length || asking) {
|
|
2555
|
+
const prefix = words.slice(0, words.findIndex((word) => word.startsWith("--")) < 0 ? void 0 : words.findIndex((word) => word.startsWith("--"))).join(" ");
|
|
2937
2556
|
const exact = commands.find((c) => prefix === c.path || prefix.startsWith(c.path + " "));
|
|
2938
2557
|
return { args: {}, json: json2, help: help(exact?.path ?? prefix) };
|
|
2939
2558
|
}
|
|
2940
|
-
const command = [...commands].sort((a, b) => b.path.length - a.path.length).find((c) => c.path.split(" ").every((word, index) =>
|
|
2559
|
+
const command = [...commands].sort((a, b) => b.path.length - a.path.length).find((c) => c.path.split(" ").every((word, index) => words[index] === word));
|
|
2941
2560
|
if (!command) throw new CliError("unknown_command", "Unknown command. Run croche --help.");
|
|
2942
|
-
const rest =
|
|
2561
|
+
const rest = words.slice(command.path.split(" ").length), args = {}, positional = [...command.positionals ?? []];
|
|
2943
2562
|
let positionalProject;
|
|
2944
2563
|
for (let index = 0; index < rest.length; index++) {
|
|
2945
2564
|
const token = rest[index] === "-o" && command.path === "config get" ? "--output" : rest[index];
|
|
@@ -2979,6 +2598,11 @@ var STUDIO_FOR = { "https://api.croche.ai": "https://studio.croche.ai", "https:/
|
|
|
2979
2598
|
function studioUrl(origin2) {
|
|
2980
2599
|
return Object.hasOwn(STUDIO_FOR, origin2) ? STUDIO_FOR[origin2] : null;
|
|
2981
2600
|
}
|
|
2601
|
+
var publicDevelopmentKeyCodes = {
|
|
2602
|
+
debug_token_revoked: "development_key_revoked",
|
|
2603
|
+
debug_token_invalid: "development_key_invalid",
|
|
2604
|
+
debug_device_limit: "development_device_limit"
|
|
2605
|
+
};
|
|
2982
2606
|
function cloudUrl(value2) {
|
|
2983
2607
|
if (value2 === void 0) return DEFAULT_CLOUD_URL;
|
|
2984
2608
|
let url;
|
|
@@ -2993,7 +2617,7 @@ function cloudUrl(value2) {
|
|
|
2993
2617
|
async function runCli(argv, context = {}) {
|
|
2994
2618
|
const env = context.env ?? process.env, stdout = context.stdout ?? ((text2) => process.stdout.write(text2)), stderr = context.stderr ?? ((text2) => process.stderr.write(text2));
|
|
2995
2619
|
const jsonMode = globalOptions(argv).json;
|
|
2996
|
-
const secrets = new Set([env.CROCHE_ACCOUNT_KEY, env.CROCHE_DEVELOPER_KEY, env.CROCHE_CONTROL_TOKEN].filter((value2) => Boolean(value2)));
|
|
2620
|
+
const secrets = new Set([env.CROCHE_ACCOUNT_KEY, env.CROCHE_DEVELOPER_KEY, env.CROCHE_CONTROL_TOKEN, env.CROCHE_DEVELOPMENT_KEY, env.CROCHE_DEBUG_KEY].filter((value2) => Boolean(value2)));
|
|
2997
2621
|
try {
|
|
2998
2622
|
const parsed = parse(argv, env);
|
|
2999
2623
|
if (parsed.help) {
|
|
@@ -3005,6 +2629,7 @@ async function runCli(argv, context = {}) {
|
|
|
3005
2629
|
`);
|
|
3006
2630
|
return 0;
|
|
3007
2631
|
}
|
|
2632
|
+
if (env.CROCHE_DEBUG_KEY !== void 0 && env.CROCHE_DEVELOPMENT_KEY === void 0) throw new CliError("invalid_configuration", developmentKeyEnvRename);
|
|
3008
2633
|
const clientEnv = { ...env, ...parsed.command?.path.startsWith("config ") && parsed.args["cloud-url"] !== void 0 ? { CROCHE_CLOUD_URL: parsed.args["cloud-url"] } : {} };
|
|
3009
2634
|
if (clientEnv.CROCHE_CLOUD_URL === void 0) clientEnv.CROCHE_CLOUD_URL = DEFAULT_CLOUD_URL;
|
|
3010
2635
|
const cloud = () => {
|
|
@@ -3032,10 +2657,23 @@ async function runCli(argv, context = {}) {
|
|
|
3032
2657
|
throw new CliError("transport_error", "Cloud request failed or timed out; no automatic retry was made.", 4);
|
|
3033
2658
|
}
|
|
3034
2659
|
const data = await readResponse(response);
|
|
3035
|
-
if (
|
|
2660
|
+
if (response.status === 401 && parsed.command?.path === "login" && path2 === "/api/studio/account") throw new CliError("invalid_credentials", "Supply a valid account key.", 3);
|
|
2661
|
+
if (!response.ok) {
|
|
2662
|
+
const wireCode = String(data?.error?.code ?? "remote_error");
|
|
2663
|
+
const code = Object.hasOwn(publicDevelopmentKeyCodes, wireCode) ? publicDevelopmentKeyCodes[wireCode] : wireCode;
|
|
2664
|
+
const message = String(data?.error?.message ?? "Cloud rejected the request.") + (wireCode === "draft_conflict" ? ` Current head: ${data.error.details?.head ?? "null"}.` : "");
|
|
2665
|
+
throw new CliError(code, message, [401, 403].includes(response.status) ? 3 : 1, data?.error?.details);
|
|
2666
|
+
}
|
|
3036
2667
|
return data;
|
|
3037
2668
|
} };
|
|
3038
2669
|
const result = await parsed.command.run(parsed.args, client);
|
|
2670
|
+
if (!parsed.json && parsed.command.path === "auth whoami") {
|
|
2671
|
+
const { cloud_url, ...account } = result;
|
|
2672
|
+
stdout(`Cloud: ${cloud_url}
|
|
2673
|
+
${JSON.stringify(account, null, 2)}
|
|
2674
|
+
`);
|
|
2675
|
+
return 0;
|
|
2676
|
+
}
|
|
3039
2677
|
if (!parsed.json && parsed.command.path.startsWith("debug")) {
|
|
3040
2678
|
const debugResult = result;
|
|
3041
2679
|
if (debugResult.viewerUrl) stdout(`${debugResult.viewerUrl}${debugResult.studioUrl ? `
|