@codetelemetry/connect 0.1.3 → 0.1.5
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/dist/config.d.ts +1 -0
- package/dist/config.js +1 -0
- package/dist/graderArtifact.d.ts +14 -0
- package/dist/graderArtifact.js +94 -0
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
|
@@ -35,6 +35,7 @@ export function resolveEndpoints(overrides = {}) {
|
|
|
35
35
|
agentImportStatusUrl: `${apiBase}/api/agent/import-status`,
|
|
36
36
|
agentGraderUrl: `${apiBase}/api/agent/grader`,
|
|
37
37
|
agentGraderConfigureUrl: `${apiBase}/api/agent/grader/configure`,
|
|
38
|
+
agentGraderPublishUrl: `${apiBase}/api/agent/grader/publish`,
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
export function resolveSettingsPath(opts = {}) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Format = "auto" | "terraform" | "pulumi";
|
|
2
|
+
export declare function writeGraderArtifact(options: {
|
|
3
|
+
repositoryPath: string;
|
|
4
|
+
format?: Format;
|
|
5
|
+
features: string;
|
|
6
|
+
checks: unknown[];
|
|
7
|
+
}): {
|
|
8
|
+
path: string;
|
|
9
|
+
format: string;
|
|
10
|
+
evidence: string[];
|
|
11
|
+
nextSteps: string;
|
|
12
|
+
note: string;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
const SKIP = new Set([".git", "node_modules", "vendor", "dist", "build", "target", ".terraform", ".pulumi", ".venv", "venv"]);
|
|
5
|
+
export function writeGraderArtifact(options) {
|
|
6
|
+
const root = fs.realpathSync(options.repositoryPath);
|
|
7
|
+
if (!fs.statSync(root).isDirectory() || root === os.homedir() || root === path.parse(root).root)
|
|
8
|
+
throw new Error("Choose a project directory for the artifact.");
|
|
9
|
+
let entries = 0;
|
|
10
|
+
let truncated = false;
|
|
11
|
+
const detected = new Set();
|
|
12
|
+
const evidence = [];
|
|
13
|
+
const walk = (directory, depth) => {
|
|
14
|
+
const handle = fs.opendirSync(directory);
|
|
15
|
+
const children = [];
|
|
16
|
+
try {
|
|
17
|
+
let entry;
|
|
18
|
+
while ((entry = handle.readSync()) !== null) {
|
|
19
|
+
if (++entries > 4000) {
|
|
20
|
+
truncated = true;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
children.push(entry);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
handle.closeSync();
|
|
28
|
+
}
|
|
29
|
+
for (const entry of children.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
30
|
+
if (entry.isSymbolicLink() || SKIP.has(entry.name))
|
|
31
|
+
continue;
|
|
32
|
+
const file = path.join(directory, entry.name);
|
|
33
|
+
if (entry.isFile()) {
|
|
34
|
+
const format = /\.tf(?:\.json)?$/.test(entry.name) ? "terraform" : /^Pulumi\.ya?ml$/.test(entry.name) ? "pulumi" : undefined;
|
|
35
|
+
if (format) {
|
|
36
|
+
detected.add(format);
|
|
37
|
+
if (evidence.length < 20)
|
|
38
|
+
evidence.push(path.relative(root, file));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (entry.isDirectory() && !entry.name.startsWith(".")) {
|
|
42
|
+
if (depth >= 5)
|
|
43
|
+
truncated = true;
|
|
44
|
+
else if (entries <= 4000)
|
|
45
|
+
walk(file, depth + 1);
|
|
46
|
+
}
|
|
47
|
+
if (entries > 4000)
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const requested = options.format ?? "auto";
|
|
52
|
+
if (requested === "auto")
|
|
53
|
+
walk(root, 0);
|
|
54
|
+
if (requested === "auto" && (detected.size !== 1 || truncated))
|
|
55
|
+
throw new Error("IaC context is absent, mixed, or incomplete. Set format to terraform or pulumi, or choose a narrower repositoryPath.");
|
|
56
|
+
const format = requested === "auto" ? [...detected][0] : requested;
|
|
57
|
+
const relative = format === "terraform" ? "codetelemetry-grader.tf.json" : "codetelemetry-grader.pulumi.yaml";
|
|
58
|
+
const terraformLiteral = (value) => value.replaceAll("${", () => "$${").replaceAll("%{", "%%{");
|
|
59
|
+
const pulumiLiteral = (value) => value.replaceAll("${", () => "$${");
|
|
60
|
+
const contents = format === "terraform" ? {
|
|
61
|
+
locals: { codetelemetry_grader_requested_features: terraformLiteral(options.features) },
|
|
62
|
+
resource: { codetelemetry_grader_config: { instructions: { checks_json: terraformLiteral(JSON.stringify(options.checks)) } } },
|
|
63
|
+
} : {
|
|
64
|
+
name: "codetelemetry-grader", runtime: "yaml", description: options.features,
|
|
65
|
+
packages: { codetelemetry: { source: "terraform-provider", version: "1.5.0", parameters: ["./bin/terraform-provider-codetelemetry"] } },
|
|
66
|
+
resources: { grader: { type: "codetelemetry:index/graderConfig:GraderConfig", properties: { checksJson: { "fn::secret": pulumiLiteral(JSON.stringify(options.checks)) } } } },
|
|
67
|
+
};
|
|
68
|
+
const text = JSON.stringify(contents, null, 2) + "\n";
|
|
69
|
+
if (/\b(?:cot_[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{20,}|npm_[A-Za-z0-9]{20,}|(?:AKIA|ASIA)[A-Z0-9]{16})\b|-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----/.test(text))
|
|
70
|
+
throw new Error("Remove credential-shaped values from features and checks before writing an artifact.");
|
|
71
|
+
if (Buffer.byteLength(text) > 128 * 1024)
|
|
72
|
+
throw new Error("Artifact exceeds 128 KiB; select fewer checks.");
|
|
73
|
+
const directory = fs.openSync(root, fs.constants.O_RDONLY | fs.constants.O_DIRECTORY | fs.constants.O_NOFOLLOW);
|
|
74
|
+
try {
|
|
75
|
+
const destination = process.platform === "linux" ? `/proc/self/fd/${directory}/${relative}` : path.join(root, relative);
|
|
76
|
+
if (fs.realpathSync(root) !== root)
|
|
77
|
+
throw new Error("Repository path changed; retry.");
|
|
78
|
+
const fd = fs.openSync(destination, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_NOFOLLOW, 0o600);
|
|
79
|
+
try {
|
|
80
|
+
fs.writeFileSync(fd, text);
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
fs.closeSync(fd);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
fs.closeSync(directory);
|
|
88
|
+
}
|
|
89
|
+
return { path: path.join(root, relative), format, evidence,
|
|
90
|
+
nextSteps: format === "terraform"
|
|
91
|
+
? "Configure the local codetelemetry provider from codetelemetry-providers, then review terraform plan. The resource owns only the listed check ids. The locals retain requested focus; the dashboard API preserves its existing requestedFeatures."
|
|
92
|
+
: "Move this file to a separate directory as Pulumi.yaml (JSON is valid YAML), build the codetelemetry-providers binary at ./bin/terraform-provider-codetelemetry in that directory, then run pulumi install and pulumi preview. The resource owns only the listed check ids. The program description retains requested focus; the dashboard API preserves its existing requestedFeatures.",
|
|
93
|
+
note: "No commands ran and nothing was published. Supply CODETELEMETRY_ENDPOINT and a Cognito ID token as CODETELEMETRY_TOKEN through your secret manager when applying. This artifact contains no credentials. Use MCP publish_grader_config to publish draft changes separately when requested." };
|
|
94
|
+
}
|