@cavelon/cli 0.1.13 → 0.1.15

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.
@@ -0,0 +1,160 @@
1
+ import { parameterSchema, QUERY_TOOL_TYPE, querySchema, queryTools, schemaKnowsQueries, schemaKnowsWrites } from "./database-queries.js";
2
+ import { locate } from "./package-files.js";
3
+ export const WORKFLOW_QUERY_MISSING_CODE = "tool_call_database_query_missing";
4
+ const object = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
5
+ const rows = (value) => Array.isArray(value) ? value.filter((row) => object(row) !== undefined) : [];
6
+ const pointerKey = (key) => key.replaceAll("~", "~0").replaceAll("/", "~1");
7
+ const scopeMatches = (row, scope) => row.harness_slug === undefined || row.harness_slug === scope;
8
+ const active = (row) => row.is_active !== false;
9
+ export function workflowQueryNodes(pkg) {
10
+ const queries = new Set(queryTools(pkg).map((tool) => tool.slug));
11
+ const nodes = object(pkg.registry_entities)?.orchestration_nodes;
12
+ if (!Array.isArray(nodes))
13
+ return [];
14
+ return nodes.flatMap((raw, index) => {
15
+ const node = object(raw);
16
+ const config = object(node?.config);
17
+ const slug = typeof config?.tool_slug === "string" ? config.tool_slug.trim() : undefined;
18
+ return node?.node_type === "tool_call" && config && slug && (config.tool_type === QUERY_TOOL_TYPE || queries.has(slug))
19
+ ? [{ node, index, config, slug }] : [];
20
+ });
21
+ }
22
+ function resolve(schema, raw) {
23
+ let value = object(raw);
24
+ for (let hops = 0; value && typeof value.$ref === "string" && hops < 10; hops++) {
25
+ if (!value.$ref.startsWith("#/$defs/"))
26
+ return undefined;
27
+ value = object(schema.$defs?.[value.$ref.slice("#/$defs/".length)]);
28
+ }
29
+ return value;
30
+ }
31
+ export function schemaRunsQueryNodes(schema) {
32
+ if (!schemaKnowsQueries(schema))
33
+ return false;
34
+ const registry = resolve(schema, schema.properties?.registry_entities);
35
+ const nodes = resolve(schema, object(registry?.properties)?.orchestration_nodes);
36
+ const entry = resolve(schema, nodes?.items);
37
+ for (const branch of rows(entry?.allOf)) {
38
+ const types = object(object(object(branch.if)?.properties)?.node_type)?.enum;
39
+ if (!Array.isArray(types) || !types.includes("tool_call"))
40
+ continue;
41
+ const config = resolve(schema, object(object(branch.then)?.properties)?.config);
42
+ const allowed = object(object(config?.properties)?.tool_type)?.enum;
43
+ return Array.isArray(allowed) && allowed.includes(QUERY_TOOL_TYPE);
44
+ }
45
+ return false;
46
+ }
47
+ function triggerReaches(pkg, query) {
48
+ if (!active(query.node))
49
+ return false;
50
+ const registry = object(pkg.registry_entities);
51
+ const scope = query.node.harness_slug;
52
+ const nodes = rows(registry?.orchestration_nodes).filter((node) => scopeMatches(node, scope));
53
+ const edges = rows(registry?.graph_edges).filter((edge) => active(edge) && scopeMatches(edge, scope));
54
+ const triggers = rows(registry?.triggers).filter((trigger) => active(trigger) && scopeMatches(trigger, scope));
55
+ const pending = [{ kind: "orchestration", slug: query.node.slug }];
56
+ const seen = new Set();
57
+ while (pending.length) {
58
+ const ref = pending.pop();
59
+ const key = JSON.stringify([ref.kind, ref.slug]);
60
+ if (seen.has(key))
61
+ continue;
62
+ seen.add(key);
63
+ if (ref.kind === "orchestration") {
64
+ const node = nodes.find((node) => node.slug === ref.slug);
65
+ if (node && !active(node))
66
+ continue;
67
+ if (node?.node_type === "trigger_start") {
68
+ const bound = object(node.config)?.trigger_slug;
69
+ const trigger = rows(registry?.triggers).find((trigger) => trigger.slug === bound && scopeMatches(trigger, scope));
70
+ if (!trigger || active(trigger))
71
+ return true;
72
+ }
73
+ }
74
+ else if (ref.kind === "agent" && triggers.some((trigger) => trigger.entrypoint_agent_slug === ref.slug)) {
75
+ return true;
76
+ }
77
+ for (const edge of edges) {
78
+ const to = object(edge.to_node_ref);
79
+ const from = object(edge.from_node_ref);
80
+ if (to?.kind === ref.kind && to.slug === ref.slug && typeof from?.kind === "string" && typeof from.slug === "string")
81
+ pending.push({ kind: from.kind, slug: from.slug });
82
+ }
83
+ }
84
+ return false;
85
+ }
86
+ function argumentNames(pkg, query) {
87
+ const found = [];
88
+ const input = object(query.config.input_schema);
89
+ const properties = object(input?.properties) ?? {};
90
+ const at = `/registry_entities/orchestration_nodes/${query.index}/config/input_schema`;
91
+ for (const name of Object.keys(properties))
92
+ found.push({ name, pointer: `${at}/properties/${pointerKey(name)}` });
93
+ if (Array.isArray(input?.required))
94
+ input.required.forEach((name, index) => {
95
+ if (typeof name === "string" && !Object.hasOwn(properties, name))
96
+ found.push({ name, pointer: `${at}/required/${index}` });
97
+ });
98
+ const registry = object(pkg.registry_entities);
99
+ const edges = rows(registry?.graph_edges).filter((edge) => active(edge) && scopeMatches(edge, query.node.harness_slug) && !object(edge.config)?.input_template);
100
+ const nodes = Array.isArray(registry?.orchestration_nodes) ? registry.orchestration_nodes : [];
101
+ nodes.forEach((raw, index) => {
102
+ const node = object(raw);
103
+ const config = object(node?.config);
104
+ if (!node || !active(node) || !scopeMatches(node, query.node.harness_slug) || node.node_type !== "transform" || !config)
105
+ return;
106
+ if ((config.mode ?? "json_mapping") !== "json_mapping" || (config.target_mode ?? "flat") !== "flat")
107
+ return;
108
+ if (!edges.some((edge) => {
109
+ const from = object(edge.from_node_ref);
110
+ const to = object(edge.to_node_ref);
111
+ return from?.kind === "orchestration" && from.slug === node.slug && to?.kind === "orchestration" && to.slug === query.node.slug;
112
+ }))
113
+ return;
114
+ for (const name of Object.keys(object(config.mapping) ?? {}))
115
+ found.push({ name, pointer: `/registry_entities/orchestration_nodes/${index}/config/mapping/${pointerKey(name)}` });
116
+ });
117
+ return found;
118
+ }
119
+ export function checkWorkflowQueries(disk, schema, inventory, baseline) {
120
+ if (!schemaRunsQueryNodes(schema) || disk.unreadable?.includes("tools"))
121
+ return [];
122
+ const findings = [];
123
+ const tools = queryTools(disk.package);
124
+ const defaults = object(parameterSchema(schema)?.properties);
125
+ const source = object(defaults?.source)?.default ?? "model";
126
+ for (const queryNode of workflowQueryNodes(disk.package)) {
127
+ const { node, index, slug } = queryNode;
128
+ const at = `/registry_entities/orchestration_nodes/${index}/config/tool_slug`;
129
+ const namedTool = rows(disk.package.tools).find((tool) => tool.slug === slug);
130
+ if (namedTool && namedTool.tool_type !== QUERY_TOOL_TYPE)
131
+ continue;
132
+ const tool = tools.find((tool) => tool.slug === slug)?.tool;
133
+ const query = object(tool?.database_query) ?? object(baseline?.tools[slug]?.database_query);
134
+ if (!tool && !inventory?.names.tools?.includes(slug) && Array.isArray(inventory?.names.tools)) {
135
+ findings.push({ code: WORKFLOW_QUERY_MISSING_CODE, severity: "warning", ...locate(disk, at), message: `Tool Call node "${String(node.slug ?? index)}" names database query "${slug}", which is neither in the package nor among the tenant's tools at the last pull (${inventory.written_at}); the import preview blocks it unless it exists by then.` });
136
+ }
137
+ if (!query)
138
+ continue;
139
+ const confirmation = object(object(querySchema(schema)?.properties)?.requires_confirmation);
140
+ if (schemaKnowsWrites(schema) && query.kind === "write" && confirmation && (query.requires_confirmation ?? confirmation.default) === true) {
141
+ findings.push({ code: "confirmation_unavailable", severity: "warning", ...locate(disk, at), message: `Tool Call node "${String(node.slug ?? index)}" calls write query "${slug}" with requires_confirmation: the node cannot wait for a person's click, so the instance refuses it with confirmation_unavailable.`, hint: "Call the query from an agent in a signed-in person's chat, or have the tenant's query manager turn confirmation off for an intended unattended write." });
142
+ }
143
+ const parameters = rows(query.parameters);
144
+ const model = new Set(parameters.filter((parameter) => (parameter.source ?? source) === source).map((parameter) => parameter.name));
145
+ const identity = new Set(parameters.filter((parameter) => (parameter.source ?? source) !== source).map((parameter) => parameter.name));
146
+ for (const argument of argumentNames(disk.package, queryNode)) {
147
+ if (model.has(argument.name))
148
+ continue;
149
+ findings.push({
150
+ code: "invalid_arguments", severity: "error", ...locate(disk, argument.pointer),
151
+ message: `Tool Call node "${String(node.slug ?? index)}" passes "${argument.name}" to query "${slug}": ${identity.has(argument.name) ? "an identity parameter is filled by the instance from the signed-in Chat User" : "the query has no model-sourced parameter of that name"}; the call answers invalid_arguments and runs nothing.`,
152
+ hint: "Use a Transform before the query node to emit only its model-sourced parameter names. Identity parameters come from the signed-in Chat User, never workflow data; the query's parameters decide the accepted arguments, not input_schema.",
153
+ });
154
+ }
155
+ if ((identity.size || query.allows_anonymous !== true) && triggerReaches(disk.package, queryNode)) {
156
+ findings.push({ code: "identity_required", severity: "warning", ...locate(disk, at), message: `Tool Call node "${String(node.slug ?? index)}" runs query "${slug}" in a workflow a trigger starts: the run has no signed-in Chat User, so ${identity.size ? "its identity parameters cannot be filled" : "the query does not allow anonymous calls"} and the call answers identity_required.`, hint: "Use this query in a conversation-bound run with a signed-in Chat User. A trigger can run a public-data query only when it has no identity parameters and allows_anonymous is true; a trigger execution identity is not a Chat User." });
157
+ }
158
+ }
159
+ return findings;
160
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavelon/cli",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
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",