@clue-ai/cli 0.0.8 → 0.0.9
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/package.json +1 -1
- package/src/contracts.mjs +132 -127
- package/src/lifecycle-init.mjs +184 -179
- package/src/public-schema.cjs +4 -0
- package/src/setup-check.mjs +3 -1
- package/src/setup-tool.mjs +388 -375
package/package.json
CHANGED
package/src/contracts.mjs
CHANGED
|
@@ -2,163 +2,168 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
|
|
3
3
|
const require = createRequire(import.meta.url);
|
|
4
4
|
const schemaPackage = require("./public-schema.cjs");
|
|
5
|
+
|
|
5
6
|
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
clueInitToolRequestSchema,
|
|
8
|
+
clueInitToolReportSchema,
|
|
9
|
+
semanticSnapshotRequestSchema,
|
|
10
|
+
semanticSnapshotResponseSchema,
|
|
10
11
|
} = schemaPackage;
|
|
11
12
|
|
|
12
13
|
const formatSchemaError = (result, field) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const issues = result.error.issues.map((issue) => {
|
|
15
|
+
const path = issue.path.length ? issue.path.join(".") : field;
|
|
16
|
+
return `${path}: ${issue.message}`;
|
|
17
|
+
});
|
|
18
|
+
return `${field} is invalid: ${issues.join("; ")}`;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
const parseWithSchema = (schema, input, field) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const result = schema.safeParse(input);
|
|
23
|
+
if (!result.success) {
|
|
24
|
+
throw new Error(formatSchemaError(result, field));
|
|
25
|
+
}
|
|
26
|
+
return result.data;
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
const nonEmpty = (value, field) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
31
|
+
throw new Error(`${field} is required`);
|
|
32
|
+
}
|
|
33
|
+
return value.trim();
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
const optionalNonEmpty = (value) =>
|
|
36
|
-
|
|
37
|
+
typeof value === "string" && value.trim() ? value.trim() : null;
|
|
37
38
|
|
|
38
39
|
const stringArray = (value, field, { min = 0 } = {}) => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
if (!Array.isArray(value)) {
|
|
41
|
+
throw new Error(`${field} must be an array`);
|
|
42
|
+
}
|
|
43
|
+
const result = value.map((entry) => nonEmpty(entry, field));
|
|
44
|
+
if (result.length < min) {
|
|
45
|
+
throw new Error(`${field} must include at least ${min} item(s)`);
|
|
46
|
+
}
|
|
47
|
+
return [...new Set(result)];
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
export const validateInitRequest = (input) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
const parsed = parseWithSchema(
|
|
52
|
+
clueInitToolRequestSchema,
|
|
53
|
+
input,
|
|
54
|
+
"init request",
|
|
55
|
+
);
|
|
56
|
+
return {
|
|
57
|
+
...parsed,
|
|
58
|
+
allowed_source_paths: [...new Set(parsed.allowed_source_paths)],
|
|
59
|
+
excluded_source_paths: [...new Set(parsed.excluded_source_paths ?? [])],
|
|
60
|
+
};
|
|
60
61
|
};
|
|
61
62
|
|
|
62
63
|
export const buildInitReport = ({
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
request,
|
|
65
|
+
lifecycleInsertions,
|
|
66
|
+
requiredVariables = [],
|
|
67
|
+
warnings = [],
|
|
67
68
|
}) =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
69
|
+
parseWithSchema(
|
|
70
|
+
clueInitToolReportSchema,
|
|
71
|
+
{
|
|
72
|
+
target_tool: request.target_tool,
|
|
73
|
+
ci_workflow_path: request.ci_workflow_path,
|
|
74
|
+
ci_workflow_added: true,
|
|
75
|
+
required_secrets: ["CLUE_API_KEY", "CLUE_AI_PROVIDER_API_KEY"],
|
|
76
|
+
required_variables: requiredVariables,
|
|
77
|
+
lifecycle_insertions: lifecycleInsertions,
|
|
78
|
+
semantic_generation_timing: "after_merge_ci",
|
|
79
|
+
semantic_preview_generated: false,
|
|
80
|
+
client_repo_generated_files_committed: false,
|
|
81
|
+
frontend_api_key_exposed: false,
|
|
82
|
+
browser_token_endpoint_required: true,
|
|
83
|
+
browser_token_provider_required: true,
|
|
84
|
+
browser_token_endpoint_path: "/api/v1/ingest/browser-tokens",
|
|
85
|
+
clue_track_inserted: false,
|
|
86
|
+
clue_dom_tag_inserted: false,
|
|
87
|
+
allowed_source_paths: request.allowed_source_paths,
|
|
88
|
+
excluded_source_paths: request.excluded_source_paths,
|
|
89
|
+
warnings,
|
|
90
|
+
},
|
|
91
|
+
"init report",
|
|
92
|
+
);
|
|
88
93
|
|
|
89
94
|
export const validateSemanticCiRequest = (input) => ({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
95
|
+
project_key: nonEmpty(input.project_key, "project_key"),
|
|
96
|
+
environment: nonEmpty(input.environment, "environment"),
|
|
97
|
+
service_key: nonEmpty(input.service_key, "service_key"),
|
|
98
|
+
repository: {
|
|
99
|
+
provider: nonEmpty(input.repository?.provider, "repository.provider"),
|
|
100
|
+
repository_id: nonEmpty(
|
|
101
|
+
input.repository?.repository_id,
|
|
102
|
+
"repository.repository_id",
|
|
103
|
+
),
|
|
104
|
+
...(optionalNonEmpty(input.repository?.owner)
|
|
105
|
+
? { owner: optionalNonEmpty(input.repository.owner) }
|
|
106
|
+
: {}),
|
|
107
|
+
...(optionalNonEmpty(input.repository?.name)
|
|
108
|
+
? { name: optionalNonEmpty(input.repository.name) }
|
|
109
|
+
: {}),
|
|
110
|
+
...(optionalNonEmpty(input.repository?.default_branch)
|
|
111
|
+
? { default_branch: optionalNonEmpty(input.repository.default_branch) }
|
|
112
|
+
: {}),
|
|
113
|
+
merge_commit: nonEmpty(
|
|
114
|
+
input.repository?.merge_commit,
|
|
115
|
+
"repository.merge_commit",
|
|
116
|
+
),
|
|
117
|
+
...(optionalNonEmpty(input.repository?.merged_at)
|
|
118
|
+
? { merged_at: optionalNonEmpty(input.repository.merged_at) }
|
|
119
|
+
: {}),
|
|
120
|
+
...(input.repository?.pull_request_number === undefined ||
|
|
121
|
+
input.repository?.pull_request_number === null
|
|
122
|
+
? {}
|
|
123
|
+
: { pull_request_number: input.repository.pull_request_number }),
|
|
124
|
+
...(optionalNonEmpty(input.repository?.workflow_run_id)
|
|
125
|
+
? { workflow_run_id: optionalNonEmpty(input.repository.workflow_run_id) }
|
|
126
|
+
: {}),
|
|
127
|
+
},
|
|
128
|
+
service: {
|
|
129
|
+
service_key: nonEmpty(
|
|
130
|
+
input.service?.service_key ?? input.service_key,
|
|
131
|
+
"service.service_key",
|
|
132
|
+
),
|
|
133
|
+
root_path: input.service?.root_path ?? null,
|
|
134
|
+
framework: input.service?.framework ?? "fastapi",
|
|
135
|
+
language: input.service?.language ?? "python",
|
|
136
|
+
},
|
|
137
|
+
allowed_source_paths: stringArray(
|
|
138
|
+
input.allowed_source_paths,
|
|
139
|
+
"allowed_source_paths",
|
|
140
|
+
{ min: 1 },
|
|
141
|
+
),
|
|
142
|
+
excluded_source_paths: stringArray(
|
|
143
|
+
input.excluded_source_paths ?? [],
|
|
144
|
+
"excluded_source_paths",
|
|
145
|
+
),
|
|
146
|
+
clue_api_base_url: nonEmpty(input.clue_api_base_url, "clue_api_base_url"),
|
|
147
|
+
ai_provider_base_url: null,
|
|
148
|
+
ai_provider: optionalNonEmpty(input.ai_provider),
|
|
149
|
+
ai_model: optionalNonEmpty(input.ai_model),
|
|
145
150
|
});
|
|
146
151
|
|
|
147
152
|
export const buildOperationSourceKey = (method, pathTemplate) =>
|
|
148
|
-
|
|
153
|
+
`route.${method.toUpperCase()}.${pathTemplate}`;
|
|
149
154
|
|
|
150
155
|
export const validateSemanticSnapshotRequest = (input) => {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
return parseWithSchema(
|
|
157
|
+
semanticSnapshotRequestSchema,
|
|
158
|
+
input,
|
|
159
|
+
"semantic snapshot",
|
|
160
|
+
);
|
|
156
161
|
};
|
|
157
162
|
|
|
158
163
|
export const validateSemanticSnapshotResponse = (input) => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
+
return parseWithSchema(
|
|
165
|
+
semanticSnapshotResponseSchema,
|
|
166
|
+
input,
|
|
167
|
+
"semantic snapshot response",
|
|
168
|
+
);
|
|
164
169
|
};
|