@rbbtsn0w/adg 0.4.0 → 0.5.0-beta.1
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/bin/adg.js +79 -21
- package/dist/src/agents/base.js +44 -12
- package/dist/src/sources.js +28 -1
- package/dist/src/telemetry.js +76 -0
- package/dist/vendor/skills/src/telemetry.js +88 -64
- package/dist/vendor/skills/src/update.js +79 -10
- package/docs/agents/antigravity.md +148 -0
- package/docs/agents/claude.md +113 -0
- package/docs/agents/codex.md +89 -0
- package/docs/agents-spec.md +172 -0
- package/package.json +7 -1
- package/vendor/skills/PROVENANCE.md +3 -2
- package/vendor/skills/src/telemetry.ts +108 -124
- package/vendor/skills/src/update.ts +85 -18
package/dist/bin/adg.js
CHANGED
|
@@ -7,6 +7,8 @@ import { checkForUpdate, formatUpdateNotice } from "../src/update-check.js";
|
|
|
7
7
|
import { ui } from "../src/render/ui.js";
|
|
8
8
|
import { TOP_USAGE, fail } from "../src/cli/index.js";
|
|
9
9
|
import { runPlugins } from "../src/cli/handlers.js";
|
|
10
|
+
import { getTracer, shutdownTelemetry, sanitizeArgs } from "../src/telemetry.js";
|
|
11
|
+
import { SpanKind, SpanStatusCode, propagation, context } from "@opentelemetry/api";
|
|
10
12
|
// ---------------------------------------------------------------------------
|
|
11
13
|
// `adg` entry point: thin wire-up only.
|
|
12
14
|
//
|
|
@@ -41,8 +43,17 @@ function runSkills(verb, rest) {
|
|
|
41
43
|
const ext = self.endsWith(".ts") ? ".ts" : ".js";
|
|
42
44
|
const entry = join(here, "..", "vendor", "skills", "src", `cli${ext}`);
|
|
43
45
|
const args = [verb, ...rest].filter((x) => x !== undefined);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
// Inject current active OpenTelemetry context into environment variables
|
|
47
|
+
const envCarrier = {};
|
|
48
|
+
propagation.inject(context.active(), envCarrier);
|
|
49
|
+
const r = spawnSync(process.execPath, skillsChildArgv(entry, args), {
|
|
50
|
+
stdio: "inherit",
|
|
51
|
+
env: {
|
|
52
|
+
...process.env,
|
|
53
|
+
...envCarrier,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
return r.status ?? 1;
|
|
46
57
|
}
|
|
47
58
|
/**
|
|
48
59
|
* Read the package version from package.json.
|
|
@@ -73,24 +84,65 @@ async function main(argv) {
|
|
|
73
84
|
console.log(TOP_USAGE);
|
|
74
85
|
return;
|
|
75
86
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
const tracer = getTracer();
|
|
88
|
+
return await tracer.startActiveSpan("adg", { kind: SpanKind.INTERNAL }, async (span) => {
|
|
89
|
+
let status = 0;
|
|
90
|
+
try {
|
|
91
|
+
span.setAttribute("process.executable.name", "adg");
|
|
92
|
+
span.setAttribute("process.executable.path", process.argv[1] || process.execPath);
|
|
93
|
+
span.setAttribute("process.pid", process.pid);
|
|
94
|
+
span.setAttribute("process.command_args", sanitizeArgs(["adg", ...argv]));
|
|
95
|
+
// Check for an available update (reads local cache; schedules a background
|
|
96
|
+
// network refresh when the cache is stale — the refresh uses an unreffed
|
|
97
|
+
// socket so it cannot delay process exit).
|
|
98
|
+
const currentVersion = getVersion();
|
|
99
|
+
const latestVersion = checkForUpdate(currentVersion);
|
|
100
|
+
if (latestVersion) {
|
|
101
|
+
process.stderr.write(formatUpdateNotice(currentVersion, latestVersion));
|
|
102
|
+
}
|
|
103
|
+
switch (domain) {
|
|
104
|
+
case "plugins":
|
|
105
|
+
case "plugin": // tolerated alias
|
|
106
|
+
span.setAttribute("domain", "plugins");
|
|
107
|
+
if (verb)
|
|
108
|
+
span.setAttribute("verb", verb);
|
|
109
|
+
await runPlugins(verb, rest);
|
|
110
|
+
break;
|
|
111
|
+
case "skills":
|
|
112
|
+
case "skill":
|
|
113
|
+
span.setAttribute("domain", "skills");
|
|
114
|
+
if (verb)
|
|
115
|
+
span.setAttribute("verb", verb);
|
|
116
|
+
status = runSkills(verb, rest);
|
|
117
|
+
break;
|
|
118
|
+
default:
|
|
119
|
+
fail(`unknown domain: ${domain} (expected \`plugins\` or \`skills\`)`);
|
|
120
|
+
}
|
|
121
|
+
span.setAttribute("process.exit.code", status);
|
|
122
|
+
if (status !== 0) {
|
|
123
|
+
span.setAttribute("error.type", `EXIT_CODE_${status}`);
|
|
124
|
+
span.setStatus({
|
|
125
|
+
code: SpanStatusCode.ERROR,
|
|
126
|
+
message: `CLI exited with non-zero status ${status}`,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return status;
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
status = 1;
|
|
133
|
+
span.setAttribute("process.exit.code", status);
|
|
134
|
+
span.setAttribute("error.type", error instanceof Error ? error.name : typeof error);
|
|
135
|
+
span.recordException(error);
|
|
136
|
+
span.setStatus({
|
|
137
|
+
code: SpanStatusCode.ERROR,
|
|
138
|
+
message: error instanceof Error ? error.message : String(error),
|
|
139
|
+
});
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
finally {
|
|
143
|
+
span.end();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
94
146
|
}
|
|
95
147
|
// Only run the CLI when executed directly, so the module can be imported by tests.
|
|
96
148
|
// `import.meta.url` is already realpath-resolved by Node, but `process.argv[1]`
|
|
@@ -112,8 +164,14 @@ function isInvokedDirectly() {
|
|
|
112
164
|
return fileURLToPath(import.meta.url) === resolved;
|
|
113
165
|
}
|
|
114
166
|
if (isInvokedDirectly()) {
|
|
115
|
-
main(process.argv.slice(2))
|
|
167
|
+
main(process.argv.slice(2))
|
|
168
|
+
.then(async (status) => {
|
|
169
|
+
await shutdownTelemetry();
|
|
170
|
+
process.exit(typeof status === "number" ? status : 0);
|
|
171
|
+
})
|
|
172
|
+
.catch(async (err) => {
|
|
116
173
|
console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}`);
|
|
174
|
+
await shutdownTelemetry();
|
|
117
175
|
process.exit(1);
|
|
118
176
|
});
|
|
119
177
|
}
|
package/dist/src/agents/base.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
3
|
+
import { getTracer, sanitizeArgs } from "../telemetry.js";
|
|
2
4
|
/**
|
|
3
5
|
* The canonical "CLI absent, so nothing was touched" lifecycle result. Every
|
|
4
6
|
* agent's activate/deactivate guard returns this shape; centralizing it keeps
|
|
@@ -24,18 +26,48 @@ export function makeCli(bin, opts) {
|
|
|
24
26
|
return {
|
|
25
27
|
available: () => (probed ??= spawnSync(bin, opts.probeArgs, { stdio: "ignore" }).status === 0),
|
|
26
28
|
run: (args) => {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
const tracer = getTracer();
|
|
30
|
+
return tracer.startActiveSpan(bin, { kind: SpanKind.CLIENT }, (span) => {
|
|
31
|
+
try {
|
|
32
|
+
span.setAttribute("process.executable.name", bin);
|
|
33
|
+
span.setAttribute("process.command_args", sanitizeArgs([bin, ...args]));
|
|
34
|
+
const r = spawnSync(bin, args, { encoding: "utf8" });
|
|
35
|
+
if (r.pid !== undefined) {
|
|
36
|
+
span.setAttribute("process.pid", r.pid);
|
|
37
|
+
}
|
|
38
|
+
if (r.status !== null) {
|
|
39
|
+
span.setAttribute("process.exit.code", r.status);
|
|
40
|
+
if (r.status !== 0) {
|
|
41
|
+
span.setAttribute("error.type", `EXIT_CODE_${r.status}`);
|
|
42
|
+
span.setStatus({
|
|
43
|
+
code: SpanStatusCode.ERROR,
|
|
44
|
+
message: `Command exited with non-zero status ${r.status}`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (r.error) {
|
|
49
|
+
span.setAttribute("process.exit.code", -1);
|
|
50
|
+
const errCode = r.error.code;
|
|
51
|
+
span.setAttribute("error.type", (typeof errCode === "string" || typeof errCode === "number" ? String(errCode) : null) || r.error.name || "SpawnError");
|
|
52
|
+
span.recordException(r.error);
|
|
53
|
+
span.setStatus({
|
|
54
|
+
code: SpanStatusCode.ERROR,
|
|
55
|
+
message: r.error.message,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const ok = r.status === 0 && !r.error;
|
|
59
|
+
if (!ok && opts.echoStderr) {
|
|
60
|
+
if (r.error)
|
|
61
|
+
console.error(r.error.message);
|
|
62
|
+
else if (r.stderr)
|
|
63
|
+
console.error(r.stderr.trim());
|
|
64
|
+
}
|
|
65
|
+
return { ok, out: `${r.stdout ?? ""}${r.stderr ?? ""}${r.error ? r.error.message : ""}` };
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
span.end();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
39
71
|
},
|
|
40
72
|
};
|
|
41
73
|
}
|
package/dist/src/sources.js
CHANGED
|
@@ -2,6 +2,8 @@ import { execFileSync } from "node:child_process";
|
|
|
2
2
|
import { existsSync, readdirSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { readManifest, findManifestFile } from "./manifest.js";
|
|
5
|
+
import { SpanKind, SpanStatusCode } from "@opentelemetry/api";
|
|
6
|
+
import { getTracer, sanitizeArgs } from "./telemetry.js";
|
|
5
7
|
const GH_SHORTHAND = /^([\w.-]+)\/([\w.-]+?)(?:@(.+))?$/;
|
|
6
8
|
const GH_URL = /^(?:https?:\/\/github\.com\/|git@github\.com:)([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:@(.+))?$/;
|
|
7
9
|
/**
|
|
@@ -56,7 +58,32 @@ export function cloneGitHub(src, dest, opts = {}) {
|
|
|
56
58
|
return dest;
|
|
57
59
|
}
|
|
58
60
|
const defaultGitRunner = (args) => {
|
|
59
|
-
|
|
61
|
+
const tracer = getTracer();
|
|
62
|
+
return tracer.startActiveSpan("git", { kind: SpanKind.CLIENT }, (span) => {
|
|
63
|
+
try {
|
|
64
|
+
span.setAttribute("process.executable.name", "git");
|
|
65
|
+
span.setAttribute("process.command_args", sanitizeArgs(["git", ...args]));
|
|
66
|
+
execFileSync("git", args, { stdio: "pipe" });
|
|
67
|
+
span.setAttribute("process.exit.code", 0);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
const exitCode = typeof error.status === "number" ? error.status : 1;
|
|
71
|
+
span.setAttribute("process.exit.code", exitCode);
|
|
72
|
+
if (typeof error.pid === "number") {
|
|
73
|
+
span.setAttribute("process.pid", error.pid);
|
|
74
|
+
}
|
|
75
|
+
span.setAttribute("error.type", error.code || error.name || `EXIT_CODE_${exitCode}`);
|
|
76
|
+
span.recordException(error);
|
|
77
|
+
span.setStatus({
|
|
78
|
+
code: SpanStatusCode.ERROR,
|
|
79
|
+
message: error.message,
|
|
80
|
+
});
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
span.end();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
60
87
|
};
|
|
61
88
|
/**
|
|
62
89
|
* Recursively find ADG plugins under `root` (directories containing
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
2
|
+
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
3
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
4
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
5
|
+
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
|
|
6
|
+
import * as opentelemetry from "@opentelemetry/api";
|
|
7
|
+
import {} from "@opentelemetry/api";
|
|
8
|
+
const baseEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
9
|
+
const TELEMETRY_URL = process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ||
|
|
10
|
+
(baseEndpoint
|
|
11
|
+
? `${baseEndpoint.replace(/\/$/, "")}/v1/traces`
|
|
12
|
+
: "https://telemetry-gateway.hamiltonsnow.workers.dev/v1/traces");
|
|
13
|
+
function isEnabled() {
|
|
14
|
+
return (!process.env.DISABLE_TELEMETRY &&
|
|
15
|
+
!process.env.DO_NOT_TRACK &&
|
|
16
|
+
!process.env.NODE_TEST_CONTEXT);
|
|
17
|
+
}
|
|
18
|
+
let provider = null;
|
|
19
|
+
let activeTracer = null;
|
|
20
|
+
export function getTracer() {
|
|
21
|
+
if (!isEnabled()) {
|
|
22
|
+
return opentelemetry.trace.getTracer("adg-noop");
|
|
23
|
+
}
|
|
24
|
+
if (!activeTracer) {
|
|
25
|
+
const exporter = new OTLPTraceExporter({
|
|
26
|
+
url: TELEMETRY_URL,
|
|
27
|
+
});
|
|
28
|
+
provider = new NodeTracerProvider({
|
|
29
|
+
resource: resourceFromAttributes({
|
|
30
|
+
[SemanticResourceAttributes.SERVICE_NAME]: "adg",
|
|
31
|
+
}),
|
|
32
|
+
spanProcessors: [new SimpleSpanProcessor(exporter)],
|
|
33
|
+
});
|
|
34
|
+
provider.register();
|
|
35
|
+
activeTracer = opentelemetry.trace.getTracer("adg");
|
|
36
|
+
}
|
|
37
|
+
return activeTracer;
|
|
38
|
+
}
|
|
39
|
+
export async function shutdownTelemetry() {
|
|
40
|
+
if (provider) {
|
|
41
|
+
try {
|
|
42
|
+
await provider.shutdown();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// Silently fail - telemetry should never break CLI exit
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function sanitizeArgs(args) {
|
|
50
|
+
return args.map((arg) => {
|
|
51
|
+
if (arg.startsWith("ghp_") ||
|
|
52
|
+
arg.startsWith("gho_") ||
|
|
53
|
+
arg.startsWith("ghu_") ||
|
|
54
|
+
arg.startsWith("ghs_") ||
|
|
55
|
+
arg.startsWith("ghr_") ||
|
|
56
|
+
arg.startsWith("github_pat_")) {
|
|
57
|
+
return "[REDACTED_TOKEN]";
|
|
58
|
+
}
|
|
59
|
+
if (arg.includes("@") && (arg.startsWith("http://") || arg.startsWith("https://"))) {
|
|
60
|
+
try {
|
|
61
|
+
const url = new URL(arg);
|
|
62
|
+
if (url.username) {
|
|
63
|
+
url.username = "[REDACTED]";
|
|
64
|
+
}
|
|
65
|
+
if (url.password) {
|
|
66
|
+
url.password = "[REDACTED]";
|
|
67
|
+
}
|
|
68
|
+
return url.toString();
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return "[REDACTED_URL]";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return arg;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -1,101 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
2
|
+
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
3
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
4
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
5
|
+
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
|
|
6
|
+
import * as opentelemetry from "@opentelemetry/api";
|
|
7
|
+
import { propagation, ROOT_CONTEXT } from "@opentelemetry/api";
|
|
8
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
const baseEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
12
|
+
const TELEMETRY_URL = process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ||
|
|
13
|
+
(baseEndpoint
|
|
14
|
+
? `${baseEndpoint.replace(/\/$/, "")}/v1/traces`
|
|
15
|
+
: "https://telemetry-gateway.hamiltonsnow.workers.dev/v1/traces");
|
|
16
|
+
let provider = null;
|
|
17
|
+
let activeTracer = null;
|
|
4
18
|
let detectedAgentName = null;
|
|
5
|
-
/**
|
|
6
|
-
* Set the detected AI agent name for telemetry tracking.
|
|
7
|
-
* Called once during agent detection, then included in all telemetry events.
|
|
8
|
-
*/
|
|
9
19
|
export function setDetectedAgent(agentName) {
|
|
10
20
|
detectedAgentName = agentName;
|
|
11
21
|
}
|
|
12
|
-
function isCI() {
|
|
13
|
-
return !!(process.env.CI ||
|
|
14
|
-
process.env.GITHUB_ACTIONS ||
|
|
15
|
-
process.env.GITLAB_CI ||
|
|
16
|
-
process.env.CIRCLECI ||
|
|
17
|
-
process.env.TRAVIS ||
|
|
18
|
-
process.env.BUILDKITE ||
|
|
19
|
-
process.env.JENKINS_URL ||
|
|
20
|
-
process.env.TEAMCITY_VERSION);
|
|
21
|
-
}
|
|
22
22
|
function isEnabled() {
|
|
23
|
-
return !process.env.DISABLE_TELEMETRY &&
|
|
23
|
+
return (!process.env.DISABLE_TELEMETRY &&
|
|
24
|
+
!process.env.DO_NOT_TRACK &&
|
|
25
|
+
!process.env.NODE_TEST_CONTEXT);
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
function isCI() {
|
|
28
|
+
return (process.env.CI === "true" ||
|
|
29
|
+
process.env.CI === "1" ||
|
|
30
|
+
process.env.GITHUB_ACTIONS === "true" ||
|
|
31
|
+
process.env.VERCEL === "1");
|
|
32
|
+
}
|
|
33
|
+
function getCliVersion() {
|
|
34
|
+
try {
|
|
35
|
+
const self = fileURLToPath(import.meta.url);
|
|
36
|
+
const here = dirname(self);
|
|
37
|
+
const up = self.endsWith(".ts") ? ".." : join("..", "..");
|
|
38
|
+
const pkgPath = join(here, up, "package.json");
|
|
39
|
+
if (!existsSync(pkgPath))
|
|
40
|
+
return null;
|
|
41
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
42
|
+
return pkg.version;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
27
47
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
*/
|
|
32
|
-
export async function fetchAuditData(source, skillSlugs, timeoutMs = 3000) {
|
|
33
|
-
if (skillSlugs.length === 0)
|
|
48
|
+
const cliVersion = getCliVersion();
|
|
49
|
+
async function auditSkill(url, source) {
|
|
50
|
+
if (!isEnabled())
|
|
34
51
|
return null;
|
|
35
52
|
try {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
signal: controller.signal,
|
|
53
|
+
const res = await fetch(url, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
"User-Agent": `skills-cli/${cliVersion || "unknown"}`,
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify({ source }),
|
|
44
60
|
});
|
|
45
|
-
|
|
46
|
-
if (!response.ok)
|
|
61
|
+
if (!res.ok) {
|
|
47
62
|
return null;
|
|
48
|
-
|
|
63
|
+
}
|
|
64
|
+
const data = (await res.json());
|
|
65
|
+
return data.warning || null;
|
|
49
66
|
}
|
|
50
67
|
catch {
|
|
51
68
|
return null;
|
|
52
69
|
}
|
|
53
70
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
71
|
+
export function getTracer() {
|
|
72
|
+
if (!isEnabled()) {
|
|
73
|
+
return opentelemetry.trace.getTracer("adg-noop");
|
|
74
|
+
}
|
|
75
|
+
if (!activeTracer) {
|
|
76
|
+
const exporter = new OTLPTraceExporter({
|
|
77
|
+
url: TELEMETRY_URL,
|
|
78
|
+
});
|
|
79
|
+
provider = new NodeTracerProvider({
|
|
80
|
+
resource: resourceFromAttributes({
|
|
81
|
+
[SemanticResourceAttributes.SERVICE_NAME]: "adg",
|
|
82
|
+
}),
|
|
83
|
+
spanProcessors: [new SimpleSpanProcessor(exporter)],
|
|
84
|
+
});
|
|
85
|
+
provider.register();
|
|
86
|
+
activeTracer = opentelemetry.trace.getTracer("adg");
|
|
87
|
+
}
|
|
88
|
+
return activeTracer;
|
|
89
|
+
}
|
|
57
90
|
export function track(data) {
|
|
58
91
|
if (!isEnabled())
|
|
59
92
|
return;
|
|
60
93
|
try {
|
|
61
|
-
const
|
|
62
|
-
|
|
94
|
+
const tracer = getTracer();
|
|
95
|
+
const parentContext = propagation.extract(ROOT_CONTEXT, process.env);
|
|
96
|
+
const span = tracer.startSpan(`skills-${data.event}`, {}, parentContext);
|
|
97
|
+
// Set common attributes
|
|
98
|
+
span.setAttribute("domain", "skills");
|
|
63
99
|
if (cliVersion) {
|
|
64
|
-
|
|
100
|
+
span.setAttribute("cli.version", cliVersion);
|
|
65
101
|
}
|
|
66
|
-
// Add CI flag if running in CI
|
|
67
102
|
if (isCI()) {
|
|
68
|
-
|
|
103
|
+
span.setAttribute("ci", true);
|
|
69
104
|
}
|
|
70
|
-
// Add detected AI agent name
|
|
71
105
|
if (detectedAgentName) {
|
|
72
|
-
|
|
106
|
+
span.setAttribute("agent", detectedAgentName);
|
|
73
107
|
}
|
|
74
|
-
//
|
|
108
|
+
// Set event attributes
|
|
75
109
|
for (const [key, value] of Object.entries(data)) {
|
|
76
110
|
if (value !== undefined && value !== null) {
|
|
77
|
-
|
|
111
|
+
span.setAttribute(key, String(value));
|
|
78
112
|
}
|
|
79
113
|
}
|
|
80
|
-
|
|
81
|
-
// flushTelemetry() can await it before the process exits.
|
|
82
|
-
const p = fetch(`${TELEMETRY_URL}?${params.toString()}`)
|
|
83
|
-
.catch(() => { })
|
|
84
|
-
.then(() => { });
|
|
85
|
-
pendingTelemetry.push(p);
|
|
114
|
+
span.end();
|
|
86
115
|
}
|
|
87
116
|
catch {
|
|
88
117
|
// Silently fail - telemetry should never break the CLI
|
|
89
118
|
}
|
|
90
119
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Wait for all in-flight telemetry requests to settle.
|
|
93
|
-
* Called once at CLI exit so the process doesn't hang on open sockets
|
|
94
|
-
* but also doesn't drop data by exiting too early.
|
|
95
|
-
*/
|
|
96
120
|
export async function flushTelemetry(timeoutMs = 5000) {
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
121
|
+
if (provider) {
|
|
122
|
+
const timeout = new Promise((resolve) => setTimeout(resolve, timeoutMs));
|
|
123
|
+
await Promise.race([provider.shutdown(), timeout]);
|
|
124
|
+
}
|
|
101
125
|
}
|
|
@@ -12,9 +12,10 @@ import { discoverSkills } from "./skills.js";
|
|
|
12
12
|
import { fetchRepoTree, findSkillMdPaths, getSkillFolderHashFromTree } from "./blob.js";
|
|
13
13
|
import { removeCommand } from "./remove.js";
|
|
14
14
|
import { sanitizeMetadata } from "./sanitize.js";
|
|
15
|
-
import { track } from "./telemetry.js";
|
|
15
|
+
import { track, getTracer } from "./telemetry.js";
|
|
16
16
|
import { agents, isUniversalAgent } from "./agents.js";
|
|
17
17
|
import { selfCliArgv } from "./self-cli.js";
|
|
18
|
+
import { SpanKind, SpanStatusCode } from '@opentelemetry/api';
|
|
18
19
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
19
20
|
/**
|
|
20
21
|
* ADG patch: upstream re-invokes its *built* `bin/cli.mjs` to perform an update,
|
|
@@ -23,7 +24,9 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
23
24
|
* our actual TS entry, run via Node's type-stripping (Node >= 22.6), exactly how
|
|
24
25
|
* `adg skills` launches the CLI. See vendor/skills/PROVENANCE.md.
|
|
25
26
|
*/
|
|
26
|
-
const SELF_CLI_ENTRY = join(__dirname, '
|
|
27
|
+
const SELF_CLI_ENTRY = existsSync(join(__dirname, '../../../bin/adg.ts'))
|
|
28
|
+
? join(__dirname, '../../../bin/adg.ts')
|
|
29
|
+
: join(__dirname, '../../../dist/bin/adg.js');
|
|
27
30
|
const RESET = '\x1b[0m';
|
|
28
31
|
const BOLD = '\x1b[1m';
|
|
29
32
|
const DIM = '\x1b[38;5;102m';
|
|
@@ -402,10 +405,43 @@ export async function updateGlobalSkills(options = {}) {
|
|
|
402
405
|
console.log(` ${DIM}✗ Failed to update ${safeName}: CLI entrypoint not found at ${cliEntry}${RESET}`);
|
|
403
406
|
continue;
|
|
404
407
|
}
|
|
405
|
-
const
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
408
|
+
const tracer = getTracer();
|
|
409
|
+
const args = ['skills', 'add', installUrl, '-g', '-y'];
|
|
410
|
+
const result = tracer.startActiveSpan("adg", { kind: SpanKind.CLIENT }, (span) => {
|
|
411
|
+
try {
|
|
412
|
+
span.setAttribute("process.executable.name", "adg");
|
|
413
|
+
span.setAttribute("process.command_args", ["adg", ...args]);
|
|
414
|
+
const r = spawnSync(process.execPath, selfCliArgv(cliEntry, args), {
|
|
415
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
416
|
+
encoding: 'utf-8',
|
|
417
|
+
shell: process.platform === 'win32',
|
|
418
|
+
});
|
|
419
|
+
if (r.pid !== undefined)
|
|
420
|
+
span.setAttribute("process.pid", r.pid);
|
|
421
|
+
if (r.status !== null) {
|
|
422
|
+
span.setAttribute("process.exit.code", r.status);
|
|
423
|
+
if (r.status !== 0) {
|
|
424
|
+
span.setAttribute("error.type", `EXIT_CODE_${r.status}`);
|
|
425
|
+
span.setStatus({
|
|
426
|
+
code: SpanStatusCode.ERROR,
|
|
427
|
+
message: `Subprocess exited with status ${r.status}`,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
else if (r.error) {
|
|
432
|
+
span.setAttribute("process.exit.code", -1);
|
|
433
|
+
span.setAttribute("error.type", r.error.code || r.error.name || "SpawnError");
|
|
434
|
+
span.recordException(r.error);
|
|
435
|
+
span.setStatus({
|
|
436
|
+
code: SpanStatusCode.ERROR,
|
|
437
|
+
message: r.error.message,
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
return r;
|
|
441
|
+
}
|
|
442
|
+
finally {
|
|
443
|
+
span.end();
|
|
444
|
+
}
|
|
409
445
|
});
|
|
410
446
|
if (result.status === 0) {
|
|
411
447
|
successCount++;
|
|
@@ -506,10 +542,43 @@ export async function updateProjectSkills(options = {}) {
|
|
|
506
542
|
const safeName = sanitizeMetadata(skill.name);
|
|
507
543
|
console.log(`${TEXT}Updating ${safeName}...${RESET}`);
|
|
508
544
|
const installUrl = formatSourceInput(skill.entry.source, skill.entry.ref);
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
545
|
+
const tracer = getTracer();
|
|
546
|
+
const args = ['skills', 'add', installUrl, '--skill', skill.name, '-y'];
|
|
547
|
+
const result = tracer.startActiveSpan("adg", { kind: SpanKind.CLIENT }, (span) => {
|
|
548
|
+
try {
|
|
549
|
+
span.setAttribute("process.executable.name", "adg");
|
|
550
|
+
span.setAttribute("process.command_args", ["adg", ...args]);
|
|
551
|
+
const r = spawnSync(process.execPath, selfCliArgv(cliEntry, args), {
|
|
552
|
+
stdio: ['inherit', 'pipe', 'pipe'],
|
|
553
|
+
encoding: 'utf-8',
|
|
554
|
+
shell: process.platform === 'win32',
|
|
555
|
+
});
|
|
556
|
+
if (r.pid !== undefined)
|
|
557
|
+
span.setAttribute("process.pid", r.pid);
|
|
558
|
+
if (r.status !== null) {
|
|
559
|
+
span.setAttribute("process.exit.code", r.status);
|
|
560
|
+
if (r.status !== 0) {
|
|
561
|
+
span.setAttribute("error.type", `EXIT_CODE_${r.status}`);
|
|
562
|
+
span.setStatus({
|
|
563
|
+
code: SpanStatusCode.ERROR,
|
|
564
|
+
message: `Subprocess exited with status ${r.status}`,
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
else if (r.error) {
|
|
569
|
+
span.setAttribute("process.exit.code", -1);
|
|
570
|
+
span.setAttribute("error.type", r.error.code || r.error.name || "SpawnError");
|
|
571
|
+
span.recordException(r.error);
|
|
572
|
+
span.setStatus({
|
|
573
|
+
code: SpanStatusCode.ERROR,
|
|
574
|
+
message: r.error.message,
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
return r;
|
|
578
|
+
}
|
|
579
|
+
finally {
|
|
580
|
+
span.end();
|
|
581
|
+
}
|
|
513
582
|
});
|
|
514
583
|
if (result.status === 0) {
|
|
515
584
|
successCount++;
|