@clue-ai/cli 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -3
- package/bin/clue-cli.mjs +805 -762
- package/commands/claude-code/clue-init.md +7 -1
- package/commands/codex/clue-init.md +7 -1
- package/package.json +1 -1
- package/src/ai-provider.mjs +146 -0
- package/src/command-spec.mjs +7 -7
- package/src/contracts.mjs +49 -15
- package/src/init-tool.mjs +158 -124
- package/src/lifecycle-init.mjs +180 -205
- package/src/public-schema.cjs +1 -1
- package/src/semantic-ci.mjs +122 -163
- package/src/setup-check.mjs +373 -372
- package/src/setup-prepare.mjs +266 -147
- package/src/setup-tool.mjs +231 -229
|
@@ -11,10 +11,16 @@ Required fields:
|
|
|
11
11
|
- `allowed_source_paths`
|
|
12
12
|
- `excluded_source_paths`
|
|
13
13
|
|
|
14
|
-
Required
|
|
14
|
+
Required environment:
|
|
15
15
|
|
|
16
16
|
- `CLUE_API_KEY`
|
|
17
|
+
- `AI_PROVIDER`
|
|
17
18
|
- `AI_PROVIDER_API_KEY`
|
|
19
|
+
- `CLUE_AI_MODEL`
|
|
20
|
+
|
|
21
|
+
`AI_PROVIDER` must be `openai` or `anthropic`. `AI_PROVIDER_API_KEY` must be the
|
|
22
|
+
API key for the selected provider. `CLUE_AI_MODEL` must be the model name for the
|
|
23
|
+
selected provider.
|
|
18
24
|
|
|
19
25
|
Behavior:
|
|
20
26
|
|
|
@@ -11,10 +11,16 @@ Required fields:
|
|
|
11
11
|
- `allowed_source_paths`
|
|
12
12
|
- `excluded_source_paths`
|
|
13
13
|
|
|
14
|
-
Required
|
|
14
|
+
Required environment:
|
|
15
15
|
|
|
16
16
|
- `CLUE_API_KEY`
|
|
17
|
+
- `AI_PROVIDER`
|
|
17
18
|
- `AI_PROVIDER_API_KEY`
|
|
19
|
+
- `CLUE_AI_MODEL`
|
|
20
|
+
|
|
21
|
+
`AI_PROVIDER` must be `openai` or `anthropic`. `AI_PROVIDER_API_KEY` must be the
|
|
22
|
+
API key for the selected provider. `CLUE_AI_MODEL` must be the model name for the
|
|
23
|
+
selected provider.
|
|
18
24
|
|
|
19
25
|
Behavior:
|
|
20
26
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
const SUPPORTED_AI_PROVIDERS = new Set(["openai", "anthropic"]);
|
|
2
|
+
|
|
3
|
+
const normalizeProvider = (value) => {
|
|
4
|
+
const provider = String(value || "openai")
|
|
5
|
+
.trim()
|
|
6
|
+
.toLowerCase();
|
|
7
|
+
if (!SUPPORTED_AI_PROVIDERS.has(provider)) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
`CLUE_AI_PROVIDER must be one of: ${Array.from(SUPPORTED_AI_PROVIDERS).join(", ")}`,
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return provider;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const trimTrailingSlash = (value) => String(value).replace(/\/+$/, "");
|
|
16
|
+
|
|
17
|
+
const providerBaseUrl = ({ provider, env = {}, request = {} }) => {
|
|
18
|
+
const explicit =
|
|
19
|
+
request.ai_provider_base_url || env.CLUE_AI_PROVIDER_BASE_URL || null;
|
|
20
|
+
if (explicit) {
|
|
21
|
+
return trimTrailingSlash(explicit);
|
|
22
|
+
}
|
|
23
|
+
return provider === "anthropic"
|
|
24
|
+
? "https://api.anthropic.com/v1"
|
|
25
|
+
: "https://api.openai.com/v1";
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const providerModel = ({ env = {}, request = {} }) => {
|
|
29
|
+
const configuredModel =
|
|
30
|
+
env.CLUE_INIT_AI_MODEL || env.CLUE_AI_MODEL || request.ai_model;
|
|
31
|
+
const model = String(configuredModel || "").trim();
|
|
32
|
+
if (!model) {
|
|
33
|
+
throw new Error("CLUE_AI_MODEL is required");
|
|
34
|
+
}
|
|
35
|
+
return model;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const resolveAiProviderConfig = ({ env = {}, request = {}, apiKey }) => {
|
|
39
|
+
const provider = normalizeProvider(
|
|
40
|
+
request.ai_provider || env.CLUE_AI_PROVIDER,
|
|
41
|
+
);
|
|
42
|
+
const resolvedApiKey = apiKey || env.CLUE_AI_PROVIDER_API_KEY;
|
|
43
|
+
if (!resolvedApiKey) {
|
|
44
|
+
throw new Error("CLUE_AI_PROVIDER_API_KEY is required");
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
provider,
|
|
48
|
+
apiKey: resolvedApiKey,
|
|
49
|
+
baseUrl: providerBaseUrl({ provider, env, request }),
|
|
50
|
+
model: providerModel({ env, request }),
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const parseOpenAiJson = async ({ response, emptyMessage }) => {
|
|
55
|
+
const body = await response.json();
|
|
56
|
+
const content = body?.choices?.[0]?.message?.content;
|
|
57
|
+
if (typeof content !== "string" || content.trim() === "") {
|
|
58
|
+
throw new Error(emptyMessage);
|
|
59
|
+
}
|
|
60
|
+
return JSON.parse(content);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const parseAnthropicJson = async ({ response, toolName, emptyMessage }) => {
|
|
64
|
+
const body = await response.json();
|
|
65
|
+
const toolUse = Array.isArray(body?.content)
|
|
66
|
+
? body.content.find(
|
|
67
|
+
(entry) => entry?.type === "tool_use" && entry.name === toolName,
|
|
68
|
+
)
|
|
69
|
+
: null;
|
|
70
|
+
if (toolUse?.input && typeof toolUse.input === "object") {
|
|
71
|
+
return toolUse.input;
|
|
72
|
+
}
|
|
73
|
+
const text = Array.isArray(body?.content)
|
|
74
|
+
? body.content
|
|
75
|
+
.filter(
|
|
76
|
+
(entry) => entry?.type === "text" && typeof entry.text === "string",
|
|
77
|
+
)
|
|
78
|
+
.map((entry) => entry.text)
|
|
79
|
+
.join("")
|
|
80
|
+
.trim()
|
|
81
|
+
: "";
|
|
82
|
+
if (!text) {
|
|
83
|
+
throw new Error(emptyMessage);
|
|
84
|
+
}
|
|
85
|
+
return JSON.parse(text);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const callJsonAiProvider = async ({
|
|
89
|
+
config,
|
|
90
|
+
system,
|
|
91
|
+
user,
|
|
92
|
+
toolName = "return_json",
|
|
93
|
+
toolDescription = "Return schema-valid JSON for this Clue task.",
|
|
94
|
+
failureMessage = "AI provider failed",
|
|
95
|
+
emptyMessage = "AI provider returned empty content",
|
|
96
|
+
}) => {
|
|
97
|
+
const response =
|
|
98
|
+
config.provider === "anthropic"
|
|
99
|
+
? await fetch(`${config.baseUrl}/messages`, {
|
|
100
|
+
method: "POST",
|
|
101
|
+
headers: {
|
|
102
|
+
"content-type": "application/json",
|
|
103
|
+
"x-api-key": config.apiKey,
|
|
104
|
+
"anthropic-version": "2023-06-01",
|
|
105
|
+
},
|
|
106
|
+
body: JSON.stringify({
|
|
107
|
+
model: config.model,
|
|
108
|
+
max_tokens: 4096,
|
|
109
|
+
system,
|
|
110
|
+
messages: [{ role: "user", content: user }],
|
|
111
|
+
tools: [
|
|
112
|
+
{
|
|
113
|
+
name: toolName,
|
|
114
|
+
description: toolDescription,
|
|
115
|
+
input_schema: {
|
|
116
|
+
type: "object",
|
|
117
|
+
additionalProperties: true,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
tool_choice: { type: "tool", name: toolName },
|
|
122
|
+
}),
|
|
123
|
+
})
|
|
124
|
+
: await fetch(`${config.baseUrl}/chat/completions`, {
|
|
125
|
+
method: "POST",
|
|
126
|
+
headers: {
|
|
127
|
+
"content-type": "application/json",
|
|
128
|
+
authorization: `Bearer ${config.apiKey}`,
|
|
129
|
+
},
|
|
130
|
+
body: JSON.stringify({
|
|
131
|
+
model: config.model,
|
|
132
|
+
messages: [
|
|
133
|
+
{ role: "system", content: system },
|
|
134
|
+
{ role: "user", content: user },
|
|
135
|
+
],
|
|
136
|
+
response_format: { type: "json_object" },
|
|
137
|
+
}),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (!response.ok) {
|
|
141
|
+
throw new Error(`${failureMessage}: ${response.status}`);
|
|
142
|
+
}
|
|
143
|
+
return config.provider === "anthropic"
|
|
144
|
+
? parseAnthropicJson({ response, toolName, emptyMessage })
|
|
145
|
+
: parseOpenAiJson({ response, emptyMessage });
|
|
146
|
+
};
|
package/src/command-spec.mjs
CHANGED
|
@@ -2,7 +2,7 @@ export const CLUE_INIT_COMMAND_NAME = "/clue-init";
|
|
|
2
2
|
|
|
3
3
|
export const REQUIRED_SECRET_NAMES = [
|
|
4
4
|
"CLUE_API_KEY",
|
|
5
|
-
"
|
|
5
|
+
"CLUE_AI_PROVIDER_API_KEY",
|
|
6
6
|
];
|
|
7
7
|
|
|
8
8
|
export const CLUE_INIT_COMMAND_FIELDS = [
|
|
@@ -55,15 +55,14 @@ const deriveServiceKeyFromBackendRootPath = (backendRootPath) => {
|
|
|
55
55
|
.replace(/[^a-z0-9_-]+/g, "-")
|
|
56
56
|
.replace(/^-+|-+$/g, "");
|
|
57
57
|
if (!normalized) {
|
|
58
|
-
throw new Error(
|
|
58
|
+
throw new Error(
|
|
59
|
+
`service_key cannot be derived from backend_root_path for ${CLUE_INIT_COMMAND_NAME}`,
|
|
60
|
+
);
|
|
59
61
|
}
|
|
60
62
|
return normalized;
|
|
61
63
|
};
|
|
62
64
|
|
|
63
|
-
export const buildClueInitRequestFromCommandInput = ({
|
|
64
|
-
targetTool,
|
|
65
|
-
input,
|
|
66
|
-
}) => {
|
|
65
|
+
export const buildClueInitRequestFromCommandInput = ({ targetTool, input }) => {
|
|
67
66
|
const backendRootPath = requireField(input, "backend_root_path");
|
|
68
67
|
const serviceKey =
|
|
69
68
|
typeof input?.service_key === "string" && input.service_key.trim()
|
|
@@ -85,7 +84,8 @@ export const buildClueInitRequestFromCommandInput = ({
|
|
|
85
84
|
[],
|
|
86
85
|
"excluded_source_paths",
|
|
87
86
|
),
|
|
88
|
-
...(typeof input?.ci_workflow_path === "string" &&
|
|
87
|
+
...(typeof input?.ci_workflow_path === "string" &&
|
|
88
|
+
input.ci_workflow_path.trim()
|
|
89
89
|
? { ci_workflow_path: input.ci_workflow_path.trim() }
|
|
90
90
|
: {}),
|
|
91
91
|
};
|
package/src/contracts.mjs
CHANGED
|
@@ -48,7 +48,11 @@ const stringArray = (value, field, { min = 0 } = {}) => {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
export const validateInitRequest = (input) => {
|
|
51
|
-
const parsed = parseWithSchema(
|
|
51
|
+
const parsed = parseWithSchema(
|
|
52
|
+
clueInitToolRequestSchema,
|
|
53
|
+
input,
|
|
54
|
+
"init request",
|
|
55
|
+
);
|
|
52
56
|
return {
|
|
53
57
|
...parsed,
|
|
54
58
|
allowed_source_paths: [...new Set(parsed.allowed_source_paths)],
|
|
@@ -56,14 +60,18 @@ export const validateInitRequest = (input) => {
|
|
|
56
60
|
};
|
|
57
61
|
};
|
|
58
62
|
|
|
59
|
-
export const buildInitReport = ({
|
|
63
|
+
export const buildInitReport = ({
|
|
64
|
+
request,
|
|
65
|
+
lifecycleInsertions,
|
|
66
|
+
warnings = [],
|
|
67
|
+
}) =>
|
|
60
68
|
parseWithSchema(
|
|
61
69
|
clueInitToolReportSchema,
|
|
62
70
|
{
|
|
63
71
|
target_tool: request.target_tool,
|
|
64
72
|
ci_workflow_path: request.ci_workflow_path,
|
|
65
73
|
ci_workflow_added: true,
|
|
66
|
-
required_secrets: ["CLUE_API_KEY", "
|
|
74
|
+
required_secrets: ["CLUE_API_KEY", "CLUE_AI_PROVIDER_API_KEY"],
|
|
67
75
|
lifecycle_insertions: lifecycleInsertions,
|
|
68
76
|
semantic_generation_timing: "after_merge_ci",
|
|
69
77
|
semantic_preview_generated: false,
|
|
@@ -81,9 +89,13 @@ export const validateSemanticCiRequest = (input) => ({
|
|
|
81
89
|
project_key: nonEmpty(input.project_key, "project_key"),
|
|
82
90
|
environment: nonEmpty(input.environment, "environment"),
|
|
83
91
|
service_key: nonEmpty(input.service_key, "service_key"),
|
|
92
|
+
ai_provider: optionalNonEmpty(input.ai_provider) ?? "openai",
|
|
84
93
|
repository: {
|
|
85
94
|
provider: nonEmpty(input.repository?.provider, "repository.provider"),
|
|
86
|
-
repository_id: nonEmpty(
|
|
95
|
+
repository_id: nonEmpty(
|
|
96
|
+
input.repository?.repository_id,
|
|
97
|
+
"repository.repository_id",
|
|
98
|
+
),
|
|
87
99
|
...(optionalNonEmpty(input.repository?.owner)
|
|
88
100
|
? { owner: optionalNonEmpty(input.repository.owner) }
|
|
89
101
|
: {}),
|
|
@@ -93,11 +105,15 @@ export const validateSemanticCiRequest = (input) => ({
|
|
|
93
105
|
...(optionalNonEmpty(input.repository?.default_branch)
|
|
94
106
|
? { default_branch: optionalNonEmpty(input.repository.default_branch) }
|
|
95
107
|
: {}),
|
|
96
|
-
merge_commit: nonEmpty(
|
|
108
|
+
merge_commit: nonEmpty(
|
|
109
|
+
input.repository?.merge_commit,
|
|
110
|
+
"repository.merge_commit",
|
|
111
|
+
),
|
|
97
112
|
...(optionalNonEmpty(input.repository?.merged_at)
|
|
98
113
|
? { merged_at: optionalNonEmpty(input.repository.merged_at) }
|
|
99
114
|
: {}),
|
|
100
|
-
...(input.repository?.pull_request_number === undefined ||
|
|
115
|
+
...(input.repository?.pull_request_number === undefined ||
|
|
116
|
+
input.repository?.pull_request_number === null
|
|
101
117
|
? {}
|
|
102
118
|
: { pull_request_number: input.repository.pull_request_number }),
|
|
103
119
|
...(optionalNonEmpty(input.repository?.workflow_run_id)
|
|
@@ -105,25 +121,43 @@ export const validateSemanticCiRequest = (input) => ({
|
|
|
105
121
|
: {}),
|
|
106
122
|
},
|
|
107
123
|
service: {
|
|
108
|
-
service_key: nonEmpty(
|
|
124
|
+
service_key: nonEmpty(
|
|
125
|
+
input.service?.service_key ?? input.service_key,
|
|
126
|
+
"service.service_key",
|
|
127
|
+
),
|
|
109
128
|
root_path: input.service?.root_path ?? null,
|
|
110
129
|
framework: input.service?.framework ?? "fastapi",
|
|
111
130
|
language: input.service?.language ?? "python",
|
|
112
131
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
132
|
+
allowed_source_paths: stringArray(
|
|
133
|
+
input.allowed_source_paths,
|
|
134
|
+
"allowed_source_paths",
|
|
135
|
+
{ min: 1 },
|
|
136
|
+
),
|
|
137
|
+
excluded_source_paths: stringArray(
|
|
138
|
+
input.excluded_source_paths ?? [],
|
|
139
|
+
"excluded_source_paths",
|
|
140
|
+
),
|
|
141
|
+
clue_api_base_url: nonEmpty(input.clue_api_base_url, "clue_api_base_url"),
|
|
142
|
+
ai_provider_base_url: optionalNonEmpty(input.ai_provider_base_url) ?? null,
|
|
143
|
+
ai_model: nonEmpty(input.ai_model, "ai_model"),
|
|
144
|
+
});
|
|
119
145
|
|
|
120
146
|
export const buildOperationSourceKey = (method, pathTemplate) =>
|
|
121
147
|
`route.${method.toUpperCase()}.${pathTemplate}`;
|
|
122
148
|
|
|
123
149
|
export const validateSemanticSnapshotRequest = (input) => {
|
|
124
|
-
return parseWithSchema(
|
|
150
|
+
return parseWithSchema(
|
|
151
|
+
semanticSnapshotRequestSchema,
|
|
152
|
+
input,
|
|
153
|
+
"semantic snapshot",
|
|
154
|
+
);
|
|
125
155
|
};
|
|
126
156
|
|
|
127
157
|
export const validateSemanticSnapshotResponse = (input) => {
|
|
128
|
-
return parseWithSchema(
|
|
158
|
+
return parseWithSchema(
|
|
159
|
+
semanticSnapshotResponseSchema,
|
|
160
|
+
input,
|
|
161
|
+
"semantic snapshot response",
|
|
162
|
+
);
|
|
129
163
|
};
|
package/src/init-tool.mjs
CHANGED
|
@@ -2,115 +2,135 @@ import { mkdir, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { buildInitReport, validateInitRequest } from "./contracts.mjs";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
applyLifecyclePlan,
|
|
6
|
+
planLifecycleInsertions,
|
|
7
7
|
} from "./lifecycle-init.mjs";
|
|
8
8
|
|
|
9
9
|
const DEFAULT_SEMANTIC_WORKFLOW_PATH =
|
|
10
|
-
|
|
10
|
+
".github/workflows/clue-semantic-snapshot.yml";
|
|
11
11
|
|
|
12
12
|
const nonEmpty = (value, field) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
14
|
+
throw new Error(`${field} is required`);
|
|
15
|
+
}
|
|
16
|
+
return value.trim();
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
const normalizeStringArray = (value, field, { min = 0 } = {}) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
if (!Array.isArray(value)) {
|
|
21
|
+
throw new Error(`${field} must be an array`);
|
|
22
|
+
}
|
|
23
|
+
const result = value
|
|
24
|
+
.filter((entry) => typeof entry === "string" && entry.trim())
|
|
25
|
+
.map((entry) => entry.trim());
|
|
26
|
+
if (result.length < min) {
|
|
27
|
+
throw new Error(`${field} must include at least ${min} item(s)`);
|
|
28
|
+
}
|
|
29
|
+
return [...new Set(result)];
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
const splitCsv = (value) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
typeof value === "string"
|
|
34
|
+
? value
|
|
35
|
+
.split(",")
|
|
36
|
+
.map((entry) => entry.trim())
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
: [];
|
|
39
39
|
|
|
40
40
|
const deriveServiceKeyFromPath = (backendRootPath) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
const segment = backendRootPath
|
|
42
|
+
.split("/")
|
|
43
|
+
.map((part) => part.trim())
|
|
44
|
+
.filter(Boolean)
|
|
45
|
+
.at(-1);
|
|
46
|
+
const normalized = segment
|
|
47
|
+
?.toLowerCase()
|
|
48
|
+
.replace(/[^a-z0-9_-]+/g, "-")
|
|
49
|
+
.replace(/^-+|-+$/g, "");
|
|
50
|
+
if (!normalized) {
|
|
51
|
+
throw new Error("service-key cannot be derived from backend-root-path");
|
|
52
|
+
}
|
|
53
|
+
return normalized;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export const buildSemanticWorkflowRequestFromFlags = (flags) => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
57
|
+
const backendRootPath = nonEmpty(flags.backendRootPath, "backend-root-path");
|
|
58
|
+
const allowedSourcePaths = splitCsv(flags.allowedSourcePaths);
|
|
59
|
+
const projectKey =
|
|
60
|
+
typeof flags.projectKey === "string" && flags.projectKey.trim()
|
|
61
|
+
? flags.projectKey.trim()
|
|
62
|
+
: "${{ vars.CLUE_PROJECT_KEY }}";
|
|
63
|
+
const environment =
|
|
64
|
+
typeof flags.environment === "string" && flags.environment.trim()
|
|
65
|
+
? flags.environment.trim()
|
|
66
|
+
: "${{ vars.CLUE_ENVIRONMENT }}";
|
|
67
|
+
const clueApiBaseUrl =
|
|
68
|
+
typeof flags.clueApiBaseUrl === "string" && flags.clueApiBaseUrl.trim()
|
|
69
|
+
? flags.clueApiBaseUrl.trim()
|
|
70
|
+
: "${{ vars.CLUE_API_BASE_URL }}";
|
|
71
|
+
return {
|
|
72
|
+
project_key: projectKey,
|
|
73
|
+
environment,
|
|
74
|
+
clue_api_base_url: clueApiBaseUrl,
|
|
75
|
+
ci_workflow_path:
|
|
76
|
+
typeof flags.workflowPath === "string" && flags.workflowPath.trim()
|
|
77
|
+
? flags.workflowPath.trim()
|
|
78
|
+
: DEFAULT_SEMANTIC_WORKFLOW_PATH,
|
|
79
|
+
service_key:
|
|
80
|
+
typeof flags.serviceKey === "string" && flags.serviceKey.trim()
|
|
81
|
+
? flags.serviceKey.trim()
|
|
82
|
+
: deriveServiceKeyFromPath(backendRootPath),
|
|
83
|
+
framework: nonEmpty(flags.framework, "framework"),
|
|
84
|
+
allowed_source_paths: normalizeStringArray(
|
|
85
|
+
allowedSourcePaths.length ? allowedSourcePaths : [backendRootPath],
|
|
86
|
+
"allowed-source-paths",
|
|
87
|
+
{ min: 1 },
|
|
88
|
+
),
|
|
89
|
+
excluded_source_paths: normalizeStringArray(
|
|
90
|
+
splitCsv(flags.excludedSourcePaths),
|
|
91
|
+
"excluded-source-paths",
|
|
92
|
+
),
|
|
93
|
+
};
|
|
79
94
|
};
|
|
80
95
|
|
|
96
|
+
const usesGithubVariable = (value) =>
|
|
97
|
+
typeof value === "string" && value.includes("${{ vars.");
|
|
98
|
+
|
|
81
99
|
const workflowRequestPayload = (request) =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
JSON.stringify(
|
|
101
|
+
{
|
|
102
|
+
project_key: request.project_key ?? "${{ vars.CLUE_PROJECT_KEY }}",
|
|
103
|
+
environment: request.environment ?? "${{ vars.CLUE_ENVIRONMENT }}",
|
|
104
|
+
service_key: request.service_key,
|
|
105
|
+
repository: {
|
|
106
|
+
provider: "github",
|
|
107
|
+
repository_id: "${{ github.repository_id }}",
|
|
108
|
+
merge_commit: "${{ github.sha }}",
|
|
109
|
+
workflow_run_id: "${{ github.run_id }}",
|
|
110
|
+
},
|
|
111
|
+
service: {
|
|
112
|
+
service_key: request.service_key,
|
|
113
|
+
root_path: request.allowed_source_paths[0],
|
|
114
|
+
framework: request.framework,
|
|
115
|
+
language: "python",
|
|
116
|
+
},
|
|
117
|
+
allowed_source_paths: request.allowed_source_paths,
|
|
118
|
+
excluded_source_paths: request.excluded_source_paths,
|
|
119
|
+
clue_api_base_url:
|
|
120
|
+
request.clue_api_base_url ?? "${{ vars.CLUE_API_BASE_URL }}",
|
|
121
|
+
ai_provider: "${{ vars.CLUE_AI_PROVIDER }}",
|
|
122
|
+
ai_model: "${{ vars.CLUE_AI_MODEL }}",
|
|
123
|
+
},
|
|
124
|
+
null,
|
|
125
|
+
10,
|
|
126
|
+
).trim();
|
|
107
127
|
|
|
108
128
|
const indentMultiline = (value, spaces) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
129
|
+
const prefix = " ".repeat(spaces);
|
|
130
|
+
return value
|
|
131
|
+
.split("\n")
|
|
132
|
+
.map((line) => `${prefix}${line}`)
|
|
133
|
+
.join("\n");
|
|
114
134
|
};
|
|
115
135
|
|
|
116
136
|
const workflowTemplate = (request) => `name: Clue Semantic Snapshot
|
|
@@ -135,7 +155,8 @@ jobs:
|
|
|
135
155
|
- name: Run Clue semantic generation
|
|
136
156
|
env:
|
|
137
157
|
CLUE_API_KEY: \${{ secrets.CLUE_API_KEY }}
|
|
138
|
-
|
|
158
|
+
CLUE_AI_PROVIDER_API_KEY: \${{ secrets.CLUE_AI_PROVIDER_API_KEY }}
|
|
159
|
+
CLUE_AI_PROVIDER: \${{ vars.CLUE_AI_PROVIDER }}
|
|
139
160
|
CLUE_SEMANTIC_REQUEST_JSON: |
|
|
140
161
|
${indentMultiline(workflowRequestPayload(request), 12)}
|
|
141
162
|
run: |
|
|
@@ -143,43 +164,56 @@ ${indentMultiline(workflowRequestPayload(request), 12)}
|
|
|
143
164
|
`;
|
|
144
165
|
|
|
145
166
|
export const writeSemanticWorkflow = async ({ repoRoot, request }) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
167
|
+
const workflowPath = join(repoRoot, request.ci_workflow_path);
|
|
168
|
+
await mkdir(dirname(workflowPath), { recursive: true });
|
|
169
|
+
await writeFile(workflowPath, workflowTemplate(request), "utf8");
|
|
170
|
+
return {
|
|
171
|
+
ci_workflow_path: request.ci_workflow_path,
|
|
172
|
+
ci_workflow_added: true,
|
|
173
|
+
required_secrets: ["CLUE_API_KEY", "CLUE_AI_PROVIDER_API_KEY"],
|
|
174
|
+
required_variables: [
|
|
175
|
+
"CLUE_AI_PROVIDER",
|
|
176
|
+
...(usesGithubVariable(
|
|
177
|
+
request.project_key ?? "${{ vars.CLUE_PROJECT_KEY }}",
|
|
178
|
+
)
|
|
179
|
+
? ["CLUE_PROJECT_KEY"]
|
|
180
|
+
: []),
|
|
181
|
+
...(usesGithubVariable(
|
|
182
|
+
request.environment ?? "${{ vars.CLUE_ENVIRONMENT }}",
|
|
183
|
+
)
|
|
184
|
+
? ["CLUE_ENVIRONMENT"]
|
|
185
|
+
: []),
|
|
186
|
+
...(usesGithubVariable(
|
|
187
|
+
request.clue_api_base_url ?? "${{ vars.CLUE_API_BASE_URL }}",
|
|
188
|
+
)
|
|
189
|
+
? ["CLUE_API_BASE_URL"]
|
|
190
|
+
: []),
|
|
191
|
+
"CLUE_AI_MODEL",
|
|
192
|
+
],
|
|
193
|
+
runtime_request_committed: false,
|
|
194
|
+
semantic_generation_timing: "after_merge_ci",
|
|
195
|
+
allowed_source_paths: request.allowed_source_paths,
|
|
196
|
+
excluded_source_paths: request.excluded_source_paths,
|
|
197
|
+
};
|
|
164
198
|
};
|
|
165
199
|
|
|
166
200
|
export const runInitTool = async ({
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
201
|
+
repoRoot,
|
|
202
|
+
request: rawRequest,
|
|
203
|
+
env = process.env,
|
|
204
|
+
lifecyclePlanner = planLifecycleInsertions,
|
|
171
205
|
}) => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
206
|
+
const request = validateInitRequest(rawRequest);
|
|
207
|
+
await writeSemanticWorkflow({ repoRoot, request });
|
|
208
|
+
const lifecyclePlan = await lifecyclePlanner({ repoRoot, request, env });
|
|
209
|
+
const lifecycleResult = await applyLifecyclePlan({
|
|
210
|
+
repoRoot,
|
|
211
|
+
plan: lifecyclePlan,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return buildInitReport({
|
|
215
|
+
request,
|
|
216
|
+
lifecycleInsertions: lifecycleResult.lifecycleInsertions,
|
|
217
|
+
warnings: [...lifecycleResult.warnings],
|
|
218
|
+
});
|
|
185
219
|
};
|