@rbbtsn0w/adg 0.7.1 → 0.7.2-beta.2
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 +24 -0
- package/dist/bin/adg.js +22 -6
- package/dist/src/adapters/antigravity-hook-runner.mjs +172 -0
- package/dist/src/adapters/antigravity-hooks.js +27 -145
- package/dist/src/cli/handlers.js +29 -40
- package/dist/src/commands/install.js +112 -54
- package/dist/src/commands/marketplace.js +20 -1
- package/dist/src/commands/update.js +7 -1
- package/dist/src/render/progress.js +102 -0
- package/dist/src/self-update.js +21 -0
- package/dist/src/source-cache.js +4 -2
- package/dist/src/sources.js +48 -6
- package/dist/src/telemetry.js +35 -1
- package/dist/vendor/skills/src/skill-lock.js +6 -1
- package/dist/vendor/skills/src/update.js +32 -4
- package/package.json +2 -2
- package/vendor/skills/PROVENANCE.md +2 -0
package/README.md
CHANGED
|
@@ -459,6 +459,30 @@ Debugging tips:
|
|
|
459
459
|
- GitHub clone/sparse logic is injectable (`gitRunner`) and covered offline by
|
|
460
460
|
the test suite; live network clones are exercised by `import owner/repo`.
|
|
461
461
|
|
|
462
|
+
## Telemetry
|
|
463
|
+
|
|
464
|
+
`adg` sends anonymous OpenTelemetry usage spans (command names, outcomes,
|
|
465
|
+
timings) to `https://telemetry-gateway.hamiltonsnow.workers.dev/v1/traces`, a
|
|
466
|
+
maintainer-run gateway on Cloudflare Workers, by default. A sanitized command
|
|
467
|
+
*shape* is included in each span: [`sanitizeArgs`](src/telemetry.ts) keeps
|
|
468
|
+
only the top two positions after `adg` — the domain and its verb (e.g. `adg
|
|
469
|
+
plugins add [VALUE] [FLAG]`) — redacting everything past that depth (`adg
|
|
470
|
+
plugins marketplace list` → `adg plugins marketplace [VALUE]`) as well as
|
|
471
|
+
every positional value, including file paths, to `[VALUE]`. The literal
|
|
472
|
+
argument values themselves — plugin names, sources, paths — are never
|
|
473
|
+
included.
|
|
474
|
+
|
|
475
|
+
Opt out with any of:
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
export DO_NOT_TRACK=1 # community-standard opt-out
|
|
479
|
+
export DISABLE_TELEMETRY=1 # adg-specific opt-out
|
|
480
|
+
export OTEL_SDK_DISABLED=true
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
See [src/telemetry.ts](src/telemetry.ts) for exactly what's collected and how
|
|
484
|
+
it's sanitized.
|
|
485
|
+
|
|
462
486
|
## Contributing
|
|
463
487
|
|
|
464
488
|
All feature/fix pull requests target the **`beta`** integration branch; `main`
|
package/dist/bin/adg.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { readFileSync, realpathSync } from "node:fs";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { selfUpdateCommand, parseSelfUpdateArgs, SELF_UPDATE_USAGE, selfUpdateSpawnOptions } from "../src/self-update.js";
|
|
5
|
+
import { selfUpdateCommand, parseSelfUpdateArgs, SELF_UPDATE_USAGE, selfUpdateSpawnOptions, formatSelfUpdateStart, formatSelfUpdateResult, selfUpdateFailureHint, } from "../src/self-update.js";
|
|
6
6
|
import { checkForUpdate, formatUpdateNotice } from "../src/update-check.js";
|
|
7
7
|
import { ui } from "../src/render/ui.js";
|
|
8
8
|
import { TARGET_ALIASES, TOP_USAGE, fail } from "../src/cli/index.js";
|
|
@@ -58,6 +58,12 @@ function runSkills(verb, rest) {
|
|
|
58
58
|
const envCarrier = {};
|
|
59
59
|
propagation.inject(context.active(), envCarrier);
|
|
60
60
|
const childArgs = skillsChildArgv(entry, args);
|
|
61
|
+
// The skills domain runs in a second Node process, so there is a cold-start
|
|
62
|
+
// gap (~2s) before the child prints anything. Claim the screen first; `--help`
|
|
63
|
+
// and the bare domain are excluded since they print immediately anyway.
|
|
64
|
+
if (verb && !args.some((a) => a === "--help" || a === "-h")) {
|
|
65
|
+
process.stderr.write(`${ui.title(`adg skills ${verb}`)}\n`);
|
|
66
|
+
}
|
|
61
67
|
const r = runSubprocessSync(process.execPath, childArgs, {
|
|
62
68
|
stdio: "inherit",
|
|
63
69
|
env: {
|
|
@@ -77,15 +83,25 @@ function runSelfUpdate(args) {
|
|
|
77
83
|
return commandOutcome("success");
|
|
78
84
|
}
|
|
79
85
|
const command = selfUpdateCommand(options.beta);
|
|
86
|
+
// npm's own inherited output is the progress indicator once it starts; this
|
|
87
|
+
// frames the silent stretch before it and states what is about to happen.
|
|
88
|
+
process.stderr.write(`${ui.meta(formatSelfUpdateStart(getVersion(), options.beta))}\n`);
|
|
89
|
+
const started = Date.now();
|
|
80
90
|
const r = runSubprocessSync(command.command, command.args, selfUpdateSpawnOptions());
|
|
81
91
|
if (r.error) {
|
|
82
|
-
console.error(r.error.message);
|
|
92
|
+
console.error(`${ui.err("error:")} ${r.error.message}`);
|
|
93
|
+
console.error(ui.meta(selfUpdateFailureHint(options.beta)));
|
|
83
94
|
return commandOutcome("failure", "dependency");
|
|
84
95
|
}
|
|
85
96
|
const exitCode = r.status ?? 1;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
97
|
+
const elapsed = Date.now() - started;
|
|
98
|
+
if (exitCode === 0) {
|
|
99
|
+
process.stderr.write(`${ui.ok(formatSelfUpdateResult(true, elapsed))}\n`);
|
|
100
|
+
return commandOutcome("success");
|
|
101
|
+
}
|
|
102
|
+
process.stderr.write(`${ui.err(formatSelfUpdateResult(false, elapsed))}\n`);
|
|
103
|
+
console.error(ui.meta(selfUpdateFailureHint(options.beta)));
|
|
104
|
+
return { ...commandOutcome("failure", "dependency"), exitCode };
|
|
89
105
|
}
|
|
90
106
|
/**
|
|
91
107
|
* Read the package version from package.json.
|
|
@@ -143,7 +159,7 @@ async function main(argv) {
|
|
|
143
159
|
const currentVersion = getVersion();
|
|
144
160
|
span.setAttribute("cli.version", currentVersion);
|
|
145
161
|
const latestVersion = checkForUpdate(currentVersion);
|
|
146
|
-
if (latestVersion) {
|
|
162
|
+
if (latestVersion && domain !== "update") {
|
|
147
163
|
process.stderr.write(formatUpdateNotice(currentVersion, latestVersion));
|
|
148
164
|
}
|
|
149
165
|
switch (domain) {
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Antigravity tool name -> Claude tool name, the inverse of TOOL_ALIASES in
|
|
8
|
+
* antigravity-hooks.ts. Kept as a literal (not derived at runtime — this file
|
|
9
|
+
* runs standalone, as a child process, with no import access to the TS
|
|
10
|
+
* module) but `test/antigravity-hook-runner.test.ts` asserts it stays the
|
|
11
|
+
* exact inverse of TOOL_ALIASES so the two tables can't silently drift.
|
|
12
|
+
*/
|
|
13
|
+
export function claudeToolName(name) {
|
|
14
|
+
return ({
|
|
15
|
+
run_command: "Bash",
|
|
16
|
+
view_file: "Read",
|
|
17
|
+
write_to_file: "Write",
|
|
18
|
+
replace_file_content: "Edit",
|
|
19
|
+
multi_replace_file_content: "Edit",
|
|
20
|
+
find_by_name: "Glob",
|
|
21
|
+
grep_search: "Grep",
|
|
22
|
+
search_web: "WebSearch",
|
|
23
|
+
read_url_content: "WebFetch",
|
|
24
|
+
invoke_subagent: "Agent",
|
|
25
|
+
ask_question: "AskUserQuestion",
|
|
26
|
+
})[name] ?? name;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function main() {
|
|
30
|
+
const [event, encodedCommand] = process.argv.slice(2);
|
|
31
|
+
const rawInput = readFileSync(0, "utf8");
|
|
32
|
+
let input;
|
|
33
|
+
try {
|
|
34
|
+
input = rawInput.trim() ? JSON.parse(rawInput) : {};
|
|
35
|
+
} catch (error) {
|
|
36
|
+
fail("invalid Antigravity hook input", error);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (event === "SessionStart" && input.invocationNum !== 0) {
|
|
40
|
+
emit({});
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
45
|
+
const command = Buffer.from(encodedCommand, "base64url").toString("utf8")
|
|
46
|
+
.replaceAll("${CLAUDE_PLUGIN_ROOT}", pluginRoot)
|
|
47
|
+
.replaceAll("${PLUGIN_ROOT}", pluginRoot);
|
|
48
|
+
const childInput = claudeInput(event, input, pluginRoot);
|
|
49
|
+
const child = spawnSync(command, {
|
|
50
|
+
cwd: pluginRoot,
|
|
51
|
+
env: { ...process.env, CLAUDE_PLUGIN_ROOT: pluginRoot, PLUGIN_ROOT: pluginRoot },
|
|
52
|
+
input: JSON.stringify(childInput),
|
|
53
|
+
encoding: "utf8",
|
|
54
|
+
shell: true,
|
|
55
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
56
|
+
});
|
|
57
|
+
if (child.stderr) process.stderr.write(child.stderr);
|
|
58
|
+
if (child.error) fail("failed to launch hook command", child.error);
|
|
59
|
+
if (child.status !== 0) process.exit(child.status ?? 1);
|
|
60
|
+
|
|
61
|
+
const output = parseOutput(event, child.stdout);
|
|
62
|
+
emit(antigravityOutput(event, output));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function claudeInput(hookEvent, source, pluginRoot) {
|
|
66
|
+
const common = {
|
|
67
|
+
...source,
|
|
68
|
+
session_id: source.conversationId,
|
|
69
|
+
transcript_path: source.transcriptPath,
|
|
70
|
+
cwd: source.workspacePaths?.[0] ?? pluginRoot,
|
|
71
|
+
hook_event_name: hookEvent,
|
|
72
|
+
};
|
|
73
|
+
if (hookEvent === "SessionStart") return { ...common, source: "startup" };
|
|
74
|
+
if (hookEvent === "PreToolUse" || hookEvent === "PostToolUse") {
|
|
75
|
+
return {
|
|
76
|
+
...common,
|
|
77
|
+
tool_name: claudeToolName(source.toolCall?.name),
|
|
78
|
+
tool_input: source.toolCall?.args ?? {},
|
|
79
|
+
tool_response: source.toolCall?.result,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (hookEvent === "Stop") return { ...common, stop_hook_active: false };
|
|
83
|
+
return common;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function parseOutput(hookEvent, stdout) {
|
|
87
|
+
const text = stdout.trim();
|
|
88
|
+
if (!text) return {};
|
|
89
|
+
try {
|
|
90
|
+
const parsed = JSON.parse(text);
|
|
91
|
+
return (typeof parsed === "object" && parsed !== null) ? parsed : {};
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (hookEvent === "SessionStart") return { additionalContext: text };
|
|
94
|
+
fail("hook command returned invalid JSON", error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function antigravityOutput(hookEvent, output) {
|
|
99
|
+
if (output.continue === false) {
|
|
100
|
+
const reason = output.stopReason ?? output.reason ?? "Claude hook stopped processing";
|
|
101
|
+
if (hookEvent === "PreToolUse") return { decision: "deny", reason };
|
|
102
|
+
if (hookEvent === "Stop") return { decision: "stop" };
|
|
103
|
+
fail(hookEvent + " continue:false output has no safe Antigravity mapping", reason);
|
|
104
|
+
}
|
|
105
|
+
if (hookEvent === "SessionStart") {
|
|
106
|
+
if (Array.isArray(output.injectSteps)) return output;
|
|
107
|
+
const context = output.hookSpecificOutput?.additionalContext
|
|
108
|
+
?? output.additionalContext
|
|
109
|
+
?? output.additional_context;
|
|
110
|
+
return typeof context === "string" && context ? { injectSteps: [{ ephemeralMessage: context }] } : {};
|
|
111
|
+
}
|
|
112
|
+
if (hookEvent === "PreToolUse") {
|
|
113
|
+
const specific = output.hookSpecificOutput ?? {};
|
|
114
|
+
const decision = specific.permissionDecision ?? output.permissionDecision ?? output.decision;
|
|
115
|
+
const reason = specific.permissionDecisionReason ?? output.reason;
|
|
116
|
+
if (specific.updatedInput !== undefined) {
|
|
117
|
+
process.stderr.write("antigravity hook bridge: Claude updatedInput is unsupported; requesting confirmation\n");
|
|
118
|
+
return { decision: "ask", reason: reason ?? "Hook requested a tool-input change that Antigravity cannot apply" };
|
|
119
|
+
}
|
|
120
|
+
if (decision === "deny" || decision === "block") return { decision: "deny", ...(reason ? { reason } : {}) };
|
|
121
|
+
if (decision === "allow" || decision === "approve") return { decision: "allow", ...(reason ? { reason } : {}) };
|
|
122
|
+
if (decision === "ask") return { decision: "ask", ...(reason ? { reason } : {}) };
|
|
123
|
+
if (decision === "defer") {
|
|
124
|
+
process.stderr.write("antigravity hook bridge: Claude defer is unsupported; requesting confirmation\n");
|
|
125
|
+
return { decision: "ask", reason: reason ?? "Hook deferred to Antigravity's permission flow" };
|
|
126
|
+
}
|
|
127
|
+
return { decision: "allow", ...(reason ? { reason } : {}) };
|
|
128
|
+
}
|
|
129
|
+
if (hookEvent === "PostToolUse") {
|
|
130
|
+
if (output.decision === "block") {
|
|
131
|
+
fail("PostToolUse block output has no safe Antigravity mapping", output.reason ?? "block");
|
|
132
|
+
}
|
|
133
|
+
return {};
|
|
134
|
+
}
|
|
135
|
+
if (hookEvent === "Stop") {
|
|
136
|
+
return output.decision === "block"
|
|
137
|
+
? { decision: "continue", ...(output.reason ? { reason: output.reason } : {}) }
|
|
138
|
+
: { decision: "stop" };
|
|
139
|
+
}
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function emit(value) {
|
|
144
|
+
process.stdout.write(JSON.stringify(value) + "\n");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function fail(message, error) {
|
|
148
|
+
process.stderr.write("antigravity hook bridge: " + message + ": " + String(error) + "\n");
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Only run the hook bridge when executed directly (`node hook-runner.mjs ...`),
|
|
153
|
+
// so the module can be imported for its pure exports (claudeToolName) in tests
|
|
154
|
+
// without reading stdin or spawning a child process. Realpath process.argv[1]
|
|
155
|
+
// first: import.meta.url is symlink-resolved by Node (e.g. macOS /tmp is a
|
|
156
|
+
// symlink to /private/tmp) but the literal argv[1] is not, so a plain string
|
|
157
|
+
// comparison between the two silently never matches on such systems.
|
|
158
|
+
function isDirectlyExecuted() {
|
|
159
|
+
if (!process.argv[1]) return false;
|
|
160
|
+
try {
|
|
161
|
+
// realpathSync throws when argv[1] isn't a real filesystem path — e.g.
|
|
162
|
+
// `node -e "..."` sets it to the literal string "-e". A throw here means
|
|
163
|
+
// this can't be the running entry file, not that the check failed.
|
|
164
|
+
return import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href;
|
|
165
|
+
} catch {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (isDirectlyExecuted()) {
|
|
171
|
+
main();
|
|
172
|
+
}
|
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { cpSync, existsSync, readFileSync, renameSync, rmSync, statSync } from "node:fs";
|
|
3
|
-
import { basename, join, resolve } from "node:path";
|
|
3
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { isExposed } from "../components.js";
|
|
5
6
|
import { writeJson, writeText } from "../fsutil.js";
|
|
6
7
|
const TARGET_FILE = "hooks.json";
|
|
7
8
|
const PROJECTION_DIR = ".antigravity-plugin";
|
|
8
9
|
const RUNNER_FILE = "hook-runner.mjs";
|
|
10
|
+
const RUNNER_ASSET = "antigravity-hook-runner.mjs";
|
|
9
11
|
const NATIVE_OVERRIDE = "hooks-antigravity.json";
|
|
12
|
+
let cachedHookRunner;
|
|
13
|
+
/**
|
|
14
|
+
* The runner materialized into each plugin's projection dir. A real,
|
|
15
|
+
* standalone, lintable/testable .mjs (see antigravity-hook-runner.mjs and
|
|
16
|
+
* test/antigravity-hook-runner.test.ts), copied into `dist/` alongside the
|
|
17
|
+
* compiled output by the `build` script since tsc only emits .ts. Read lazily
|
|
18
|
+
* and cached so an `adg` invocation with no antigravity hooks never touches it.
|
|
19
|
+
*/
|
|
20
|
+
function hookRunnerSource() {
|
|
21
|
+
if (cachedHookRunner === undefined) {
|
|
22
|
+
cachedHookRunner = readFileSync(join(dirname(fileURLToPath(import.meta.url)), RUNNER_ASSET), "utf8");
|
|
23
|
+
}
|
|
24
|
+
return cachedHookRunner;
|
|
25
|
+
}
|
|
10
26
|
const EVENT_MAP = {
|
|
11
27
|
SessionStart: "PreInvocation",
|
|
12
28
|
PreToolUse: "PreToolUse",
|
|
13
29
|
PostToolUse: "PostToolUse",
|
|
14
30
|
Stop: "Stop",
|
|
15
31
|
};
|
|
16
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Claude tool name -> Antigravity tool name(s) ("|"-joined when a Claude tool
|
|
34
|
+
* has more than one Antigravity counterpart). The inverse direction lives in
|
|
35
|
+
* antigravity-hook-runner.mjs's `claudeToolName` — that file runs as a
|
|
36
|
+
* standalone child process with no import access to this module, so the two
|
|
37
|
+
* tables can't be unified into one; `test/antigravity-hook-runner.test.ts`
|
|
38
|
+
* asserts they stay exact inverses of each other instead.
|
|
39
|
+
*/
|
|
40
|
+
export const TOOL_ALIASES = {
|
|
17
41
|
Bash: "run_command",
|
|
18
42
|
Read: "view_file",
|
|
19
43
|
Write: "write_to_file",
|
|
@@ -313,7 +337,7 @@ export function writeAntigravityHooks(pluginDir, manifest, selection) {
|
|
|
313
337
|
if (Object.keys(definition).length) {
|
|
314
338
|
const projected = { [manifest.name]: definition };
|
|
315
339
|
validateNativeDocument(projected);
|
|
316
|
-
replaceText(join(pluginDir, PROJECTION_DIR, RUNNER_FILE),
|
|
340
|
+
replaceText(join(pluginDir, PROJECTION_DIR, RUNNER_FILE), hookRunnerSource());
|
|
317
341
|
replaceJson(target, projected);
|
|
318
342
|
}
|
|
319
343
|
else {
|
|
@@ -321,145 +345,3 @@ export function writeAntigravityHooks(pluginDir, manifest, selection) {
|
|
|
321
345
|
}
|
|
322
346
|
return warnings;
|
|
323
347
|
}
|
|
324
|
-
const HOOK_RUNNER = String.raw `import { spawnSync } from "node:child_process";
|
|
325
|
-
import { readFileSync } from "node:fs";
|
|
326
|
-
import { dirname, resolve } from "node:path";
|
|
327
|
-
import { fileURLToPath } from "node:url";
|
|
328
|
-
|
|
329
|
-
const [event, encodedCommand] = process.argv.slice(2);
|
|
330
|
-
const rawInput = readFileSync(0, "utf8");
|
|
331
|
-
let input;
|
|
332
|
-
try {
|
|
333
|
-
input = rawInput.trim() ? JSON.parse(rawInput) : {};
|
|
334
|
-
} catch (error) {
|
|
335
|
-
fail("invalid Antigravity hook input", error);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (event === "SessionStart" && input.invocationNum !== 0) {
|
|
339
|
-
emit({});
|
|
340
|
-
process.exit(0);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
344
|
-
const command = Buffer.from(encodedCommand, "base64url").toString("utf8")
|
|
345
|
-
.replaceAll("$" + "{CLAUDE_PLUGIN_ROOT}", pluginRoot)
|
|
346
|
-
.replaceAll("$" + "{PLUGIN_ROOT}", pluginRoot);
|
|
347
|
-
const childInput = claudeInput(event, input);
|
|
348
|
-
const child = spawnSync(command, {
|
|
349
|
-
cwd: pluginRoot,
|
|
350
|
-
env: { ...process.env, CLAUDE_PLUGIN_ROOT: pluginRoot, PLUGIN_ROOT: pluginRoot },
|
|
351
|
-
input: JSON.stringify(childInput),
|
|
352
|
-
encoding: "utf8",
|
|
353
|
-
shell: true,
|
|
354
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
355
|
-
});
|
|
356
|
-
if (child.stderr) process.stderr.write(child.stderr);
|
|
357
|
-
if (child.error) fail("failed to launch hook command", child.error);
|
|
358
|
-
if (child.status !== 0) process.exit(child.status ?? 1);
|
|
359
|
-
|
|
360
|
-
const output = parseOutput(event, child.stdout);
|
|
361
|
-
emit(antigravityOutput(event, output));
|
|
362
|
-
|
|
363
|
-
function claudeInput(hookEvent, source) {
|
|
364
|
-
const common = {
|
|
365
|
-
...source,
|
|
366
|
-
session_id: source.conversationId,
|
|
367
|
-
transcript_path: source.transcriptPath,
|
|
368
|
-
cwd: source.workspacePaths?.[0] ?? pluginRoot,
|
|
369
|
-
hook_event_name: hookEvent,
|
|
370
|
-
};
|
|
371
|
-
if (hookEvent === "SessionStart") return { ...common, source: "startup" };
|
|
372
|
-
if (hookEvent === "PreToolUse" || hookEvent === "PostToolUse") {
|
|
373
|
-
return {
|
|
374
|
-
...common,
|
|
375
|
-
tool_name: claudeToolName(source.toolCall?.name),
|
|
376
|
-
tool_input: source.toolCall?.args ?? {},
|
|
377
|
-
tool_response: source.toolCall?.result,
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
if (hookEvent === "Stop") return { ...common, stop_hook_active: false };
|
|
381
|
-
return common;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
function claudeToolName(name) {
|
|
385
|
-
return ({
|
|
386
|
-
run_command: "Bash",
|
|
387
|
-
view_file: "Read",
|
|
388
|
-
write_to_file: "Write",
|
|
389
|
-
replace_file_content: "Edit",
|
|
390
|
-
multi_replace_file_content: "Edit",
|
|
391
|
-
find_by_name: "Glob",
|
|
392
|
-
grep_search: "Grep",
|
|
393
|
-
search_web: "WebSearch",
|
|
394
|
-
read_url_content: "WebFetch",
|
|
395
|
-
invoke_subagent: "Agent",
|
|
396
|
-
ask_question: "AskUserQuestion",
|
|
397
|
-
})[name] ?? name;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
function parseOutput(hookEvent, stdout) {
|
|
401
|
-
const text = stdout.trim();
|
|
402
|
-
if (!text) return {};
|
|
403
|
-
try {
|
|
404
|
-
const parsed = JSON.parse(text);
|
|
405
|
-
return (typeof parsed === "object" && parsed !== null) ? parsed : {};
|
|
406
|
-
} catch (error) {
|
|
407
|
-
if (hookEvent === "SessionStart") return { additionalContext: text };
|
|
408
|
-
fail("hook command returned invalid JSON", error);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
function antigravityOutput(hookEvent, output) {
|
|
413
|
-
if (output.continue === false) {
|
|
414
|
-
const reason = output.stopReason ?? output.reason ?? "Claude hook stopped processing";
|
|
415
|
-
if (hookEvent === "PreToolUse") return { decision: "deny", reason };
|
|
416
|
-
if (hookEvent === "Stop") return { decision: "stop" };
|
|
417
|
-
fail(hookEvent + " continue:false output has no safe Antigravity mapping", reason);
|
|
418
|
-
}
|
|
419
|
-
if (hookEvent === "SessionStart") {
|
|
420
|
-
if (Array.isArray(output.injectSteps)) return output;
|
|
421
|
-
const context = output.hookSpecificOutput?.additionalContext
|
|
422
|
-
?? output.additionalContext
|
|
423
|
-
?? output.additional_context;
|
|
424
|
-
return typeof context === "string" && context ? { injectSteps: [{ ephemeralMessage: context }] } : {};
|
|
425
|
-
}
|
|
426
|
-
if (hookEvent === "PreToolUse") {
|
|
427
|
-
const specific = output.hookSpecificOutput ?? {};
|
|
428
|
-
const decision = specific.permissionDecision ?? output.permissionDecision ?? output.decision;
|
|
429
|
-
const reason = specific.permissionDecisionReason ?? output.reason;
|
|
430
|
-
if (specific.updatedInput !== undefined) {
|
|
431
|
-
process.stderr.write("antigravity hook bridge: Claude updatedInput is unsupported; requesting confirmation\n");
|
|
432
|
-
return { decision: "ask", reason: reason ?? "Hook requested a tool-input change that Antigravity cannot apply" };
|
|
433
|
-
}
|
|
434
|
-
if (decision === "deny" || decision === "block") return { decision: "deny", ...(reason ? { reason } : {}) };
|
|
435
|
-
if (decision === "allow" || decision === "approve") return { decision: "allow", ...(reason ? { reason } : {}) };
|
|
436
|
-
if (decision === "ask") return { decision: "ask", ...(reason ? { reason } : {}) };
|
|
437
|
-
if (decision === "defer") {
|
|
438
|
-
process.stderr.write("antigravity hook bridge: Claude defer is unsupported; requesting confirmation\n");
|
|
439
|
-
return { decision: "ask", reason: reason ?? "Hook deferred to Antigravity's permission flow" };
|
|
440
|
-
}
|
|
441
|
-
return { decision: "allow", ...(reason ? { reason } : {}) };
|
|
442
|
-
}
|
|
443
|
-
if (hookEvent === "PostToolUse") {
|
|
444
|
-
if (output.decision === "block") {
|
|
445
|
-
fail("PostToolUse block output has no safe Antigravity mapping", output.reason ?? "block");
|
|
446
|
-
}
|
|
447
|
-
return {};
|
|
448
|
-
}
|
|
449
|
-
if (hookEvent === "Stop") {
|
|
450
|
-
return output.decision === "block"
|
|
451
|
-
? { decision: "continue", ...(output.reason ? { reason: output.reason } : {}) }
|
|
452
|
-
: { decision: "stop" };
|
|
453
|
-
}
|
|
454
|
-
return {};
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
function emit(value) {
|
|
458
|
-
process.stdout.write(JSON.stringify(value) + "\n");
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
function fail(message, error) {
|
|
462
|
-
process.stderr.write("antigravity hook bridge: " + message + ": " + String(error) + "\n");
|
|
463
|
-
process.exit(1);
|
|
464
|
-
}
|
|
465
|
-
`;
|
package/dist/src/cli/handlers.js
CHANGED
|
@@ -18,6 +18,7 @@ import { selectScopeInteractive, selectUpdateScopeInteractive } from "../command
|
|
|
18
18
|
import { globalPluginsDir, projectPluginsDir, lockPath } from "../paths.js";
|
|
19
19
|
import { getAgent } from "../agents/index.js";
|
|
20
20
|
import { ui } from "../render/ui.js";
|
|
21
|
+
import { createProgress, formatUpdateSummary } from "../render/progress.js";
|
|
21
22
|
import { renderAgentReport, renderMarketplaceList, renderUpdateReport, } from "../render/plugins.js";
|
|
22
23
|
import { CACHE_USAGE, MARKETPLACE_USAGE, PLUGIN_ALIASES, PLUGIN_COMMANDS, SCOPE, fail, parseVerb, renderPluginsHelp, renderVerbHelp, requireSingleTarget, resolveComponents, resolveScopeDir, resolveTargets, scopeOf, wantsHelp, } from "./index.js";
|
|
23
24
|
import { handleCorePluginVerb } from "./core-plugin-handlers.js";
|
|
@@ -289,29 +290,41 @@ async function handleSync(rest, cmd) {
|
|
|
289
290
|
printCliUnavailableNote(target, `manifests were regenerated, but nothing was re-synced in ${target}.`);
|
|
290
291
|
}
|
|
291
292
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
293
|
+
/**
|
|
294
|
+
* Re-fetch every scope in `resolveUpdateScopes(values)` and refresh its
|
|
295
|
+
* installed plugins, with per-scope progress reporting and error handling.
|
|
296
|
+
* Shared by `plugins update` and its deprecated `marketplace upgrade` alias
|
|
297
|
+
* so the two verbs can't drift from each other.
|
|
298
|
+
*/
|
|
299
|
+
async function runUpdateAcrossScopes(values, opts) {
|
|
295
300
|
let succeeded = 0;
|
|
296
301
|
let failed = 0;
|
|
297
302
|
for (const sc of await resolveUpdateScopes(values)) {
|
|
298
303
|
if (sc.heading)
|
|
299
304
|
console.log(`${ui.name(sc.heading)}`);
|
|
305
|
+
const progress = createProgress();
|
|
300
306
|
try {
|
|
301
307
|
const result = await updatePlugins({
|
|
302
308
|
pluginsDir: sc.dir,
|
|
303
|
-
source,
|
|
309
|
+
source: opts.source,
|
|
304
310
|
all: values.all,
|
|
305
311
|
activate: true,
|
|
306
312
|
agentScope: sc.agentScope,
|
|
307
313
|
scope: { label: sc.label, globalDir: globalPluginsDir() },
|
|
314
|
+
targets: opts.targets,
|
|
315
|
+
onProgress: (phase) => progress.update(phase),
|
|
308
316
|
});
|
|
317
|
+
// Clear the animated line before the report goes to stdout, so the two
|
|
318
|
+
// streams don't interleave mid-line.
|
|
319
|
+
progress.stop();
|
|
309
320
|
printUpdateReport(result);
|
|
310
321
|
const counts = updateResultCounts(result);
|
|
322
|
+
console.log(formatUpdateSummary(counts, progress.elapsedMs()));
|
|
311
323
|
succeeded += counts.succeeded;
|
|
312
324
|
failed += counts.failed;
|
|
313
325
|
}
|
|
314
326
|
catch (err) {
|
|
327
|
+
progress.stop();
|
|
315
328
|
console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}`);
|
|
316
329
|
failed += 1;
|
|
317
330
|
}
|
|
@@ -320,6 +333,13 @@ async function handleUpdate(rest, cmd) {
|
|
|
320
333
|
return commandOutcome("success");
|
|
321
334
|
return commandOutcome(succeeded > 0 ? "partial" : "failure", "dependency");
|
|
322
335
|
}
|
|
336
|
+
async function handleUpdate(rest, cmd) {
|
|
337
|
+
const { values, positionals } = parseVerb("update", cmd.flags, rest);
|
|
338
|
+
// First paint, before the scope prompt and before any lock read, so the run
|
|
339
|
+
// never opens on a blank screen. stderr keeps stdout to the report alone.
|
|
340
|
+
process.stderr.write(`${ui.title("adg plugins update")}\n`);
|
|
341
|
+
return runUpdateAcrossScopes(values, { source: positionals[0] });
|
|
342
|
+
}
|
|
323
343
|
async function runPluginsVerb(verb, rest, cmd) {
|
|
324
344
|
if (await handleCorePluginVerb(verb, rest, cmd))
|
|
325
345
|
return;
|
|
@@ -462,45 +482,14 @@ async function runMarketplace(args) {
|
|
|
462
482
|
return commandOutcome("success");
|
|
463
483
|
}
|
|
464
484
|
case "upgrade": {
|
|
465
|
-
// Deprecated: a thin alias for `adg plugins update`. It
|
|
466
|
-
//
|
|
467
|
-
//
|
|
485
|
+
// Deprecated: a thin alias for `adg plugins update`. It calls the same
|
|
486
|
+
// `runUpdateAcrossScopes` helper (scope resolution, progress reporting,
|
|
487
|
+
// and error handling) so the alias can't drift from the verb it aliases.
|
|
488
|
+
// `--target` narrows the runtimes.
|
|
468
489
|
console.error(ui.warn("note: `marketplace upgrade` is a deprecated alias for `adg plugins update`."));
|
|
469
490
|
const { values, positionals } = parseVerb("marketplace", ["all", "target", ...SCOPE], rest);
|
|
470
|
-
// Drive the exact same scope resolution + per-scope loop as `plugins update`
|
|
471
|
-
// (project/global/both, with the home==global trap guard) so the deprecated
|
|
472
|
-
// alias can't drift from the verb it aliases. `--target` narrows the runtimes.
|
|
473
491
|
const targets = values.target !== undefined ? resolveTargets(values.target) : undefined;
|
|
474
|
-
|
|
475
|
-
let failed = 0;
|
|
476
|
-
for (const sc of await resolveUpdateScopes(values)) {
|
|
477
|
-
if (sc.heading)
|
|
478
|
-
console.log(`${ui.name(sc.heading)}`);
|
|
479
|
-
// Mirror `plugins update`'s error handling: report a failed re-fetch and
|
|
480
|
-
// exit cleanly rather than throwing to the top-level catch.
|
|
481
|
-
try {
|
|
482
|
-
const result = await updatePlugins({
|
|
483
|
-
pluginsDir: sc.dir,
|
|
484
|
-
scope: { label: sc.label, globalDir: globalPluginsDir() },
|
|
485
|
-
activate: true,
|
|
486
|
-
agentScope: sc.agentScope,
|
|
487
|
-
source: positionals[0],
|
|
488
|
-
all: values.all,
|
|
489
|
-
targets,
|
|
490
|
-
});
|
|
491
|
-
printUpdateReport(result);
|
|
492
|
-
const counts = updateResultCounts(result);
|
|
493
|
-
succeeded += counts.succeeded;
|
|
494
|
-
failed += counts.failed;
|
|
495
|
-
}
|
|
496
|
-
catch (err) {
|
|
497
|
-
console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}`);
|
|
498
|
-
failed += 1;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
if (failed === 0)
|
|
502
|
-
return commandOutcome("success");
|
|
503
|
-
return commandOutcome(succeeded > 0 ? "partial" : "failure", "dependency");
|
|
492
|
+
return runUpdateAcrossScopes(values, { source: positionals[0], targets });
|
|
504
493
|
}
|
|
505
494
|
case "remove":
|
|
506
495
|
case "rm": {
|
|
@@ -293,6 +293,7 @@ function activateInstalled(opts, targets, installed, existingPlugins) {
|
|
|
293
293
|
const scope = opts.scope ?? "project";
|
|
294
294
|
const ctxFor = (names) => ({ pluginsDir: opts.pluginsDir, plugins: names, scope });
|
|
295
295
|
return resolved.map((agent) => {
|
|
296
|
+
opts.onProgress?.({ kind: "activate", agent: agent.id, count: toActivate.length });
|
|
296
297
|
const queryResult = agent.listInstalled?.(ctxFor([]));
|
|
297
298
|
const agentInstalled = Array.isArray(queryResult) ? queryResult : undefined;
|
|
298
299
|
const alreadyInstalled = (name) => agentInstalled !== undefined
|
|
@@ -308,6 +309,105 @@ function activateInstalled(opts, targets, installed, existingPlugins) {
|
|
|
308
309
|
return parts.reduce((acc, result) => ({ agent: result.agent, affected: [...acc.affected, ...result.affected], skipped: acc.skipped && result.skipped }), { agent: agent.id, affected: [], skipped: true });
|
|
309
310
|
});
|
|
310
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Resolve `opts.spec` to a local working directory plus an origin builder and
|
|
314
|
+
* cleanup, covering the three source kinds: a prepared checkout (remote
|
|
315
|
+
* marketplace update, already on disk), a local directory (no clone, no
|
|
316
|
+
* cleanup), or a GitHub source (clone to a temp dir, cleaned up by the caller).
|
|
317
|
+
*/
|
|
318
|
+
function prepareSource(opts, parsed, sourceRef) {
|
|
319
|
+
if (opts.preparedSourceDir) {
|
|
320
|
+
const workRoot = resolve(opts.preparedSourceDir);
|
|
321
|
+
return {
|
|
322
|
+
workRoot,
|
|
323
|
+
resolvedRevision: opts.preparedResolvedRevision,
|
|
324
|
+
buildOrigin: (dir, dirOverride) => ({
|
|
325
|
+
type: "github",
|
|
326
|
+
repo: parsed.kind === "github" ? parsed.source : opts.spec,
|
|
327
|
+
...(sourceRef ? { ref: sourceRef } : {}),
|
|
328
|
+
path: toPosix(relative(workRoot, dirOverride ?? dir)) || ".",
|
|
329
|
+
}),
|
|
330
|
+
cleanup: undefined,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
if (parsed.kind === "local") {
|
|
334
|
+
const workRoot = resolve(parsed.dir);
|
|
335
|
+
return {
|
|
336
|
+
workRoot,
|
|
337
|
+
resolvedRevision: undefined,
|
|
338
|
+
buildOrigin: (dir, dirOverride) => ({ type: "local", path: resolve(dirOverride ?? dir) }),
|
|
339
|
+
cleanup: undefined,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
const tmp = mkdtempSync(join(tmpdir(), "adg-clone-"));
|
|
343
|
+
try {
|
|
344
|
+
cloneGitHub({ ...parsed, ref: sourceRef }, tmp, { sparse: opts.sparse, runner: opts.gitRunner });
|
|
345
|
+
const resolvedRevision = gitRevision(tmp);
|
|
346
|
+
return {
|
|
347
|
+
workRoot: tmp,
|
|
348
|
+
resolvedRevision,
|
|
349
|
+
buildOrigin: (dir, dirOverride) => ({
|
|
350
|
+
type: "github",
|
|
351
|
+
repo: parsed.source,
|
|
352
|
+
...(sourceRef ? { ref: sourceRef } : {}),
|
|
353
|
+
path: toPosix(relative(tmp, dirOverride ?? dir)) || ".",
|
|
354
|
+
}),
|
|
355
|
+
cleanup: () => rmSync(tmp, { recursive: true, force: true }),
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
360
|
+
throw error;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Synthesize a single Default DSL plugin from a source that holds no explicit
|
|
365
|
+
* ADG/native manifest: generate a manifest for the whole tree, stage a copy
|
|
366
|
+
* with it written in, and scan that staging copy as the sole candidate.
|
|
367
|
+
*/
|
|
368
|
+
async function synthesizeDefaultDslPlugin(opts, parsed, workRoot, resolvedRevision) {
|
|
369
|
+
const defaultDescription = parsed.kind === "github" && !opts.preparedSourceDir && !opts.defaultDescription
|
|
370
|
+
? await githubRepositoryDescription(parsed.source)
|
|
371
|
+
: undefined;
|
|
372
|
+
const structuralIdentity = opts.as ?? opts.structuralIdentity ?? (parsed.kind === "github" ? parsed.source : basename(workRoot));
|
|
373
|
+
const generated = resolveDefaultDsl(workRoot, {
|
|
374
|
+
name: structuralIdentity,
|
|
375
|
+
description: defaultDescription ?? opts.defaultDescription ?? structuralIdentity,
|
|
376
|
+
}, {
|
|
377
|
+
...(parsed.kind === "github" && resolvedRevision ? { resolvedRevision } : {}),
|
|
378
|
+
});
|
|
379
|
+
const authorized = opts.authorizedComponents;
|
|
380
|
+
const unauthorizedRisk = generated.components.some((c) => (c === "hooks" || c === "mcp") && !authorized?.includes(c));
|
|
381
|
+
if (opts.nonInteractive && unauthorizedRisk && opts.only === undefined) {
|
|
382
|
+
throw new Error("default source exposes hooks or MCP; pass --only to explicitly authorize selected components");
|
|
383
|
+
}
|
|
384
|
+
const staging = mkdtempSync(join(tmpdir(), "adg-default-plugin-"));
|
|
385
|
+
let candidates;
|
|
386
|
+
try {
|
|
387
|
+
copyPluginDir(workRoot, staging);
|
|
388
|
+
writeJson(join(staging, ADG_MANIFEST_PATH), generated.manifest);
|
|
389
|
+
candidates = scanPlugins(staging);
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
rmSync(staging, { recursive: true, force: true });
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
candidates,
|
|
397
|
+
converted: [],
|
|
398
|
+
structuralName: generated.manifest.name,
|
|
399
|
+
originDirOverride: workRoot,
|
|
400
|
+
definition: {
|
|
401
|
+
kind: "default-dsl/v1",
|
|
402
|
+
root: ".",
|
|
403
|
+
...(opts.as ? { as: generated.manifest.name } : {}),
|
|
404
|
+
description: generated.manifest.description,
|
|
405
|
+
fingerprint: generated.fingerprint,
|
|
406
|
+
authorizedComponents: authorized ?? (opts.only ?? generated.components),
|
|
407
|
+
},
|
|
408
|
+
cleanup: () => rmSync(staging, { recursive: true, force: true }),
|
|
409
|
+
};
|
|
410
|
+
}
|
|
311
411
|
/**
|
|
312
412
|
* The unified install entrypoint. Treats any source as a marketplace: clone or
|
|
313
413
|
* read it, discover every plugin (ADG plus reverse-adapted native), choose a
|
|
@@ -322,36 +422,12 @@ export async function addPlugins(opts) {
|
|
|
322
422
|
if (parsed.kind === "github" && parsed.path) {
|
|
323
423
|
throw new Error("GitHub subdirectory sources are not supported; define a marketplace and select with --plugin or --all");
|
|
324
424
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
let
|
|
328
|
-
let cleanup;
|
|
425
|
+
const prepared = prepareSource(opts, parsed, sourceRef);
|
|
426
|
+
const { workRoot, buildOrigin, resolvedRevision } = prepared;
|
|
427
|
+
let cleanup = prepared.cleanup;
|
|
329
428
|
let originDirOverride;
|
|
330
429
|
let definition;
|
|
331
|
-
let defaultDescription;
|
|
332
430
|
let structuralName;
|
|
333
|
-
if (opts.preparedSourceDir) {
|
|
334
|
-
workRoot = resolve(opts.preparedSourceDir);
|
|
335
|
-
resolvedRevision = opts.preparedResolvedRevision;
|
|
336
|
-
buildOrigin = (dir) => ({ type: "github", repo: parsed.kind === "github" ? parsed.source : opts.spec, ...(sourceRef ? { ref: sourceRef } : {}), path: toPosix(relative(workRoot, originDirOverride ?? dir)) || "." });
|
|
337
|
-
}
|
|
338
|
-
else if (parsed.kind === "local") {
|
|
339
|
-
workRoot = resolve(parsed.dir);
|
|
340
|
-
buildOrigin = (dir) => ({ type: "local", path: resolve(originDirOverride ?? dir) });
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
const tmp = mkdtempSync(join(tmpdir(), "adg-clone-"));
|
|
344
|
-
cleanup = () => rmSync(tmp, { recursive: true, force: true });
|
|
345
|
-
cloneGitHub({ ...parsed, ref: sourceRef }, tmp, { sparse: opts.sparse, runner: opts.gitRunner });
|
|
346
|
-
workRoot = tmp;
|
|
347
|
-
resolvedRevision = gitRevision(tmp);
|
|
348
|
-
buildOrigin = (dir) => ({
|
|
349
|
-
type: "github",
|
|
350
|
-
repo: parsed.source,
|
|
351
|
-
...(sourceRef ? { ref: sourceRef } : {}),
|
|
352
|
-
path: toPosix(relative(tmp, originDirOverride ?? dir)) || ".",
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
431
|
try {
|
|
356
432
|
let { candidates, converted } = discoverPlugins(workRoot);
|
|
357
433
|
const existingLock = readLock(lockPath(opts.pluginsDir));
|
|
@@ -364,32 +440,14 @@ export async function addPlugins(opts) {
|
|
|
364
440
|
}
|
|
365
441
|
}
|
|
366
442
|
if (candidates.size === 0) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
});
|
|
376
|
-
const authorized = opts.authorizedComponents;
|
|
377
|
-
const unauthorizedRisk = generated.components.some((c) => (c === "hooks" || c === "mcp") && !authorized?.includes(c));
|
|
378
|
-
if (opts.nonInteractive && unauthorizedRisk && opts.only === undefined) {
|
|
379
|
-
throw new Error("default source exposes hooks or MCP; pass --only to explicitly authorize selected components");
|
|
380
|
-
}
|
|
381
|
-
const staging = mkdtempSync(join(tmpdir(), "adg-default-plugin-"));
|
|
382
|
-
copyPluginDir(workRoot, staging);
|
|
383
|
-
writeJson(join(staging, ADG_MANIFEST_PATH), generated.manifest);
|
|
384
|
-
candidates = scanPlugins(staging);
|
|
385
|
-
structuralName = generated.manifest.name;
|
|
386
|
-
converted = [];
|
|
387
|
-
originDirOverride = workRoot;
|
|
388
|
-
definition = { kind: "default-dsl/v1", root: ".", ...(opts.as ? { as: generated.manifest.name } : {}), description: generated.manifest.description, fingerprint: generated.fingerprint, authorizedComponents: authorized ?? (opts.only ?? generated.components) };
|
|
389
|
-
cleanup = (() => {
|
|
390
|
-
const prior = cleanup;
|
|
391
|
-
return () => { rmSync(staging, { recursive: true, force: true }); prior?.(); };
|
|
392
|
-
})();
|
|
443
|
+
const synthesized = await synthesizeDefaultDslPlugin(opts, parsed, workRoot, resolvedRevision);
|
|
444
|
+
candidates = synthesized.candidates;
|
|
445
|
+
converted = synthesized.converted;
|
|
446
|
+
structuralName = synthesized.structuralName;
|
|
447
|
+
originDirOverride = synthesized.originDirOverride;
|
|
448
|
+
definition = synthesized.definition;
|
|
449
|
+
const priorCleanup = cleanup;
|
|
450
|
+
cleanup = () => { synthesized.cleanup(); priorCleanup?.(); };
|
|
393
451
|
}
|
|
394
452
|
const selected = structuralName ? [structuralName] : await selectPluginNames(opts, candidates, converted);
|
|
395
453
|
// Resolve adapter targets after the plugin choice (lets a CLI agent picker
|
|
@@ -445,7 +503,7 @@ export async function addPlugins(opts) {
|
|
|
445
503
|
installed.push(installPlugin({
|
|
446
504
|
source: candidate.dir,
|
|
447
505
|
pluginsDir: opts.pluginsDir,
|
|
448
|
-
origin: buildOrigin(candidate.dir),
|
|
506
|
+
origin: buildOrigin(candidate.dir, originDirOverride),
|
|
449
507
|
resolvedRevision,
|
|
450
508
|
marketplaceName: opts.marketplaceName,
|
|
451
509
|
targets,
|
|
@@ -116,8 +116,11 @@ export async function updatePlugins(opts) {
|
|
|
116
116
|
const now = opts.now ?? new Date().toISOString();
|
|
117
117
|
const remote = [];
|
|
118
118
|
const remoteAgents = [];
|
|
119
|
+
let sourceIndex = 0;
|
|
119
120
|
for (const group of remoteGroups) {
|
|
121
|
+
const position = { index: ++sourceIndex, total: remoteGroups.length };
|
|
120
122
|
try {
|
|
123
|
+
opts.onProgress?.({ kind: "check", ...position, source: group.source });
|
|
121
124
|
const lock = readLock(lockPath(opts.pluginsDir));
|
|
122
125
|
const revisions = group.installed.map((name) => lock.plugins[name]?.resolvedRevision).filter((revision) => Boolean(revision));
|
|
123
126
|
const remoteRevision = (opts.revisionResolver ?? gitRemoteRevision)(group.source, group.ref);
|
|
@@ -152,9 +155,18 @@ export async function updatePlugins(opts) {
|
|
|
152
155
|
const checkout = mkdtempSync(join(tmpdir(), "adg-marketplace-update-"));
|
|
153
156
|
try {
|
|
154
157
|
const parsed = parseGitHubSource(group.source);
|
|
158
|
+
opts.onProgress?.({ kind: "fetch", ...position, source: group.source, ...(group.ref ? { ref: group.ref } : {}) });
|
|
155
159
|
cloneGitHub({ ...parsed, ref: group.ref }, checkout, { runner: opts.gitRunner });
|
|
156
160
|
const resolvedRevision = gitRevision(checkout);
|
|
161
|
+
let requestIndex = 0;
|
|
157
162
|
for (const request of requests) {
|
|
163
|
+
opts.onProgress?.({
|
|
164
|
+
kind: "install",
|
|
165
|
+
index: ++requestIndex,
|
|
166
|
+
total: requests.length,
|
|
167
|
+
source: group.source,
|
|
168
|
+
...(request.structuralIdentity ? { plugin: request.structuralIdentity } : {}),
|
|
169
|
+
});
|
|
158
170
|
const result = await addPlugins({
|
|
159
171
|
spec: group.source,
|
|
160
172
|
pluginsDir: opts.pluginsDir,
|
|
@@ -178,6 +190,7 @@ export async function updatePlugins(opts) {
|
|
|
178
190
|
now,
|
|
179
191
|
preparedSourceDir: checkout,
|
|
180
192
|
preparedResolvedRevision: resolvedRevision,
|
|
193
|
+
...(opts.onProgress ? { onProgress: opts.onProgress } : {}),
|
|
181
194
|
});
|
|
182
195
|
installed.push(...result.installed);
|
|
183
196
|
result.available.forEach((name) => available.add(name));
|
|
@@ -216,7 +229,13 @@ export async function updatePlugins(opts) {
|
|
|
216
229
|
// source) and only for the local bucket — remote ones were just re-fetched.
|
|
217
230
|
const localNames = opts.source ? [] : (allGroups.find((g) => !g.remote)?.installed ?? []);
|
|
218
231
|
const local = localNames.length
|
|
219
|
-
? updateLock(opts.pluginsDir, now, {
|
|
232
|
+
? updateLock(opts.pluginsDir, now, {
|
|
233
|
+
only: localNames,
|
|
234
|
+
resync: opts.activate,
|
|
235
|
+
scope: opts.agentScope,
|
|
236
|
+
agents: opts.agents,
|
|
237
|
+
...(opts.onProgress ? { onProgress: opts.onProgress } : {}),
|
|
238
|
+
})
|
|
220
239
|
: { results: [], missing: [] };
|
|
221
240
|
const agents = mergeAgentResults([remoteAgents, local.agents ?? []]);
|
|
222
241
|
return { remote, local, agents };
|
|
@@ -18,9 +18,12 @@ export function updateLock(pluginsDir, now = new Date().toISOString(), opts = {}
|
|
|
18
18
|
const results = [];
|
|
19
19
|
const missing = [];
|
|
20
20
|
const changedNames = [];
|
|
21
|
+
const scheduled = Object.keys(snapshot.plugins).filter((name) => !only || only.has(name));
|
|
22
|
+
let localIndex = 0;
|
|
21
23
|
for (const [name, entry] of Object.entries(snapshot.plugins)) {
|
|
22
24
|
if (only && !only.has(name))
|
|
23
25
|
continue;
|
|
26
|
+
opts.onProgress?.({ kind: "local", index: ++localIndex, total: scheduled.length, plugin: name });
|
|
24
27
|
const installedDir = installedPluginDir(pluginsDir, name, entry.origin);
|
|
25
28
|
const resolvedSource = entry.origin.type === "local" ? resolve(pluginsDir, entry.origin.path) : undefined;
|
|
26
29
|
const localSource = resolvedSource && resolvedSource !== resolve(installedDir)
|
|
@@ -90,7 +93,10 @@ export function updateLock(pluginsDir, now = new Date().toISOString(), opts = {}
|
|
|
90
93
|
const out = { results, missing };
|
|
91
94
|
if (opts.resync && changedNames.length > 0) {
|
|
92
95
|
const ctx = { pluginsDir, plugins: changedNames, scope: opts.scope ?? "project" };
|
|
93
|
-
out.agents = (opts.agents ?? resolveAgents()).map((agent) =>
|
|
96
|
+
out.agents = (opts.agents ?? resolveAgents()).map((agent) => {
|
|
97
|
+
opts.onProgress?.({ kind: "activate", agent: agent.id, count: changedNames.length });
|
|
98
|
+
return agent.refresh(ctx);
|
|
99
|
+
});
|
|
94
100
|
}
|
|
95
101
|
return out;
|
|
96
102
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ui } from "./ui.js";
|
|
2
|
+
/**
|
|
3
|
+
* Render one phase as a single line. Pure, so the wording is assertable in the
|
|
4
|
+
* plain-string style of test/render.test.ts. Labels name the actual cost (a
|
|
5
|
+
* remote probe, a clone, an agent re-sync) rather than a generic "working…".
|
|
6
|
+
*/
|
|
7
|
+
export function formatPhase(phase) {
|
|
8
|
+
switch (phase.kind) {
|
|
9
|
+
case "check":
|
|
10
|
+
return `${ui.meta(`checking remotes (${phase.index}/${phase.total})`)} ${ui.name(phase.source)}`;
|
|
11
|
+
case "fetch":
|
|
12
|
+
return `${ui.meta("fetching")} ${ui.name(`${phase.source}${phase.ref ? `@${phase.ref}` : ""}`)}`;
|
|
13
|
+
case "install": {
|
|
14
|
+
const what = phase.plugin ? ui.name(phase.plugin) : ui.name(phase.source);
|
|
15
|
+
return `${ui.meta(`installing (${phase.index}/${phase.total})`)} ${what}`;
|
|
16
|
+
}
|
|
17
|
+
case "local":
|
|
18
|
+
return `${ui.meta(`rescanning local (${phase.index}/${phase.total})`)} ${ui.name(phase.plugin)}`;
|
|
19
|
+
case "activate":
|
|
20
|
+
return `${ui.meta("re-syncing")} ${ui.name(phase.agent)} ${ui.meta(`— ${phase.count} plugin${phase.count === 1 ? "" : "s"}`)}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
24
|
+
const CLEAR_LINE = "\r\x1b[K";
|
|
25
|
+
/**
|
|
26
|
+
* A deliberately minimal spinner instead of `@clack/prompts`'s: clack's writes
|
|
27
|
+
* to stdout, which would break the JSON-purity contract above, and the plugins
|
|
28
|
+
* domain otherwise uses clack for prompts only.
|
|
29
|
+
*
|
|
30
|
+
* On a TTY it rewrites one line in place (no trailing newline). Off a TTY it
|
|
31
|
+
* prints one newline-terminated line per phase and `stop()` is a no-op, so a
|
|
32
|
+
* piped log gets a readable trace with no cursor movement and no `\r` — those
|
|
33
|
+
* are what corrupt a captured log.
|
|
34
|
+
*
|
|
35
|
+
* Color is deliberately NOT stripped off a TTY. Every renderer in `src/`
|
|
36
|
+
* delegates that decision to picocolors (see `ui.ts`), which disables color on
|
|
37
|
+
* a non-TTY or under NO_COLOR but deliberately keeps it when `CI=true`, since
|
|
38
|
+
* CI log viewers render SGR. Stripping here would make progress the only
|
|
39
|
+
* renderer in the repo that second-guesses that, and would leave this stderr
|
|
40
|
+
* trace colorless while the stdout report beside it stayed colored.
|
|
41
|
+
*
|
|
42
|
+
* The frame advances per event rather than on a timer, and deliberately so: the
|
|
43
|
+
* work being reported (`execFileSync` git calls, `spawnSync` agent CLIs) blocks
|
|
44
|
+
* the event loop, so an interval would never fire mid-phase. Animation is not
|
|
45
|
+
* available here — the phase *label*, with its counter, is what tells the user
|
|
46
|
+
* the run is alive. Do not "fix" this with setInterval; it cannot tick.
|
|
47
|
+
*/
|
|
48
|
+
export function createProgress(opts = {}) {
|
|
49
|
+
const stream = opts.stream ?? process.stderr;
|
|
50
|
+
const tty = opts.isTTY ?? Boolean(process.stderr.isTTY);
|
|
51
|
+
const now = opts.now ?? (() => Date.now());
|
|
52
|
+
const started = now();
|
|
53
|
+
let frame = 0;
|
|
54
|
+
let active = false;
|
|
55
|
+
// Defined as closures rather than methods on the returned literal: nothing
|
|
56
|
+
// here may depend on `this`, since callers legitimately destructure the
|
|
57
|
+
// factory result (`const { update, stop } = createProgress()`).
|
|
58
|
+
const update = (phase) => {
|
|
59
|
+
const line = formatPhase(phase);
|
|
60
|
+
if (!tty) {
|
|
61
|
+
stream.write(`${line}\n`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
stream.write(`${CLEAR_LINE}${ui.meta(FRAMES[frame % FRAMES.length])} ${line}`);
|
|
65
|
+
frame += 1;
|
|
66
|
+
active = true;
|
|
67
|
+
};
|
|
68
|
+
const stop = () => {
|
|
69
|
+
if (!tty || !active)
|
|
70
|
+
return;
|
|
71
|
+
stream.write(CLEAR_LINE);
|
|
72
|
+
active = false;
|
|
73
|
+
};
|
|
74
|
+
return { update, stop, elapsedMs: () => now() - started };
|
|
75
|
+
}
|
|
76
|
+
/** Format a wall-clock duration for the summary line (e.g. "1.4s", "2m 05s"). */
|
|
77
|
+
export function formatDuration(ms) {
|
|
78
|
+
if (ms < 1000)
|
|
79
|
+
return `${ms}ms`;
|
|
80
|
+
// Round to the unit actually being printed *before* splitting into minutes
|
|
81
|
+
// and seconds. Deriving the parts from the unrounded value lets a duration
|
|
82
|
+
// that rounds up across a boundary render an impossible pair: 119_900ms was
|
|
83
|
+
// floor(1.998)=1 minute with round(59.9)=60 seconds, i.e. "1m 60s". Choosing
|
|
84
|
+
// the branch on rounded tenths likewise keeps 59_950ms out of "60.0s".
|
|
85
|
+
const tenths = Math.round(ms / 100);
|
|
86
|
+
if (tenths < 600)
|
|
87
|
+
return `${(tenths / 10).toFixed(1)}s`;
|
|
88
|
+
const totalSeconds = Math.round(ms / 1000);
|
|
89
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
90
|
+
return `${minutes}m ${String(totalSeconds - minutes * 60).padStart(2, "0")}s`;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The closing line of an update run. `updateResultCounts` already computes these
|
|
94
|
+
* numbers for the exit code; printing them saves the user from counting rows.
|
|
95
|
+
*/
|
|
96
|
+
export function formatUpdateSummary(counts, elapsedMs) {
|
|
97
|
+
const parts = [ui.ok(`${counts.succeeded} ok`)];
|
|
98
|
+
if (counts.failed > 0)
|
|
99
|
+
parts.push(ui.err(`${counts.failed} failed`));
|
|
100
|
+
parts.push(ui.meta(formatDuration(elapsedMs)));
|
|
101
|
+
return parts.join(ui.meta(" · "));
|
|
102
|
+
}
|
package/dist/src/self-update.js
CHANGED
|
@@ -29,6 +29,27 @@ export function selfUpdateCommand(beta, npmBin = "npm") {
|
|
|
29
29
|
export function selfUpdateSpawnOptions(platform = process.platform) {
|
|
30
30
|
return { stdio: "inherit", shell: platform === "win32" };
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* The line printed before npm is spawned. `npm install -g` is silent for several
|
|
34
|
+
* seconds, so without this the command that is *named* "update" shows nothing at
|
|
35
|
+
* all until npm's summary block appears.
|
|
36
|
+
*/
|
|
37
|
+
export function formatSelfUpdateStart(currentVersion, beta) {
|
|
38
|
+
const { command, args } = selfUpdateCommand(beta);
|
|
39
|
+
return `adg ${currentVersion} → installing ${selfUpdateTarget(beta)} (${command} ${args.join(" ")})`;
|
|
40
|
+
}
|
|
41
|
+
/** Closing line for a self-update run. */
|
|
42
|
+
export function formatSelfUpdateResult(ok, elapsedMs) {
|
|
43
|
+
const seconds = `${(elapsedMs / 1000).toFixed(1)}s`;
|
|
44
|
+
return ok
|
|
45
|
+
? `updated · ${seconds} — run \`adg --version\` to confirm`
|
|
46
|
+
: `update failed · ${seconds}`;
|
|
47
|
+
}
|
|
48
|
+
/** Actionable next step when npm could not be launched or exited non-zero. */
|
|
49
|
+
export function selfUpdateFailureHint(beta) {
|
|
50
|
+
const { command, args } = selfUpdateCommand(beta);
|
|
51
|
+
return `try running it directly: ${command} ${args.join(" ")}\nif that fails with EACCES, npm's global prefix needs write access (or install via a version manager).`;
|
|
52
|
+
}
|
|
32
53
|
export function selfUpdateHint(latestVersion) {
|
|
33
54
|
const channel = prereleaseChannel(latestVersion);
|
|
34
55
|
if (channel === "beta")
|
package/dist/src/source-cache.js
CHANGED
|
@@ -7,7 +7,7 @@ import { withPluginSourceCache } from "./materialize.js";
|
|
|
7
7
|
import { PROJECTION_DIRS, packageFilter } from "./package.js";
|
|
8
8
|
import { legacyPluginSourceCacheDir, pluginSourceCacheDir } from "./paths.js";
|
|
9
9
|
import { recordTelemetryEvent } from "./telemetry.js";
|
|
10
|
-
import { runGit } from "./sources.js";
|
|
10
|
+
import { runGit, GIT_CLONE_TIMEOUT_MS } from "./sources.js";
|
|
11
11
|
class SourceCacheIntegrityError extends Error {
|
|
12
12
|
}
|
|
13
13
|
function sourceHash(dir) {
|
|
@@ -42,7 +42,9 @@ function restoreExactRemoteSnapshot(pluginsDir, name, entry) {
|
|
|
42
42
|
// only the exact commit persisted by the v4 lock instead.
|
|
43
43
|
runGit(["-C", temp, "init"]);
|
|
44
44
|
runGit(["-C", temp, "remote", "add", "origin", url]);
|
|
45
|
-
|
|
45
|
+
// Bounded like every other network git call: an unbounded fetch is an
|
|
46
|
+
// indefinite, output-free hang.
|
|
47
|
+
runGit(["-C", temp, "fetch", "--depth", "1", "origin", entry.resolvedRevision], false, GIT_CLONE_TIMEOUT_MS);
|
|
46
48
|
runGit(["-C", temp, "checkout", "--detach", "FETCH_HEAD"]);
|
|
47
49
|
const source = resolve(temp, entry.origin.path || ".");
|
|
48
50
|
const rel = relative(temp, source);
|
package/dist/src/sources.js
CHANGED
|
@@ -115,24 +115,66 @@ export function cloneGitHub(src, dest, opts = {}) {
|
|
|
115
115
|
}
|
|
116
116
|
return dest;
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Default timeouts. A remote probe is a metadata round trip and should be quick;
|
|
120
|
+
* a clone legitimately takes minutes on a large repository. Both exist because
|
|
121
|
+
* an unbounded `execFileSync` here is an indefinite, output-free hang.
|
|
122
|
+
*/
|
|
123
|
+
export const GIT_REMOTE_PROBE_TIMEOUT_MS = 20_000;
|
|
124
|
+
export const GIT_CLONE_TIMEOUT_MS = 300_000;
|
|
118
125
|
export const defaultGitRunner = (args) => {
|
|
119
|
-
runGit(args);
|
|
126
|
+
runGit(args, false, GIT_CLONE_TIMEOUT_MS);
|
|
120
127
|
};
|
|
121
128
|
/** Return a low-cardinality, string-safe error type for Git subprocess spans. */
|
|
122
129
|
export function gitErrorType(error, exitCode) {
|
|
123
130
|
const code = error && typeof error === "object" ? error.code : undefined;
|
|
124
131
|
return code === undefined || code === null ? `EXIT_CODE_${exitCode}` : String(code);
|
|
125
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Environment for every git subprocess we spawn.
|
|
135
|
+
*
|
|
136
|
+
* `GIT_TERMINAL_PROMPT=0` is the important one: a private or moved repository
|
|
137
|
+
* makes git prompt for credentials, and because these calls run with
|
|
138
|
+
* `stdio: "ignore"` that prompt is invisible — the CLI simply hangs forever with
|
|
139
|
+
* nothing on screen. Disabling the prompt turns that into a fast, reportable
|
|
140
|
+
* failure that surfaces per-source as "could not be checked". `GIT_ASKPASS` /
|
|
141
|
+
* `SSH_ASKPASS` are neutralized for the same reason: an IDE-injected helper can
|
|
142
|
+
* re-introduce an invisible interactive wait. Ordinary credential helpers
|
|
143
|
+
* (`credential.helper`), proxies, and `SSH_AUTH_SOCK` are left alone, matching
|
|
144
|
+
* the vendored fork's sanitization (see vendor/skills/src/git.ts).
|
|
145
|
+
*
|
|
146
|
+
* Deliberately NOT set: `GIT_SSH_COMMAND`. The environment variable outranks the
|
|
147
|
+
* `core.sshCommand` git config, so defaulting it here would silently discard a
|
|
148
|
+
* user's configured ssh invocation (a deploy key, a proxy command) for `git`
|
|
149
|
+
* origins that carry an ssh URL. Bounding ssh's own prompts is the timeout's
|
|
150
|
+
* job, not this function's.
|
|
151
|
+
*/
|
|
152
|
+
export function gitEnv() {
|
|
153
|
+
const env = { ...process.env };
|
|
154
|
+
// Case-insensitive: Windows env keys preserve case but compare insensitively,
|
|
155
|
+
// so an exact-key delete alone can be bypassed.
|
|
156
|
+
for (const key of Object.keys(env)) {
|
|
157
|
+
const upper = key.toUpperCase();
|
|
158
|
+
if (upper === "GIT_ASKPASS" || upper === "SSH_ASKPASS")
|
|
159
|
+
delete env[key];
|
|
160
|
+
}
|
|
161
|
+
env.GIT_TERMINAL_PROMPT = "0";
|
|
162
|
+
return env;
|
|
163
|
+
}
|
|
126
164
|
/** Run git under the shared CLI semantic-convention instrumentation. */
|
|
127
|
-
export function runGit(args, captureOutput = false) {
|
|
165
|
+
export function runGit(args, captureOutput = false, timeoutMs) {
|
|
128
166
|
const tracer = getTracer();
|
|
129
167
|
return tracer.startActiveSpan("git", { kind: SpanKind.CLIENT }, (span) => {
|
|
130
168
|
try {
|
|
131
169
|
span.setAttribute("process.executable.name", "git");
|
|
132
170
|
span.setAttribute("process.command_args", sanitizeArgs(["git", ...args]));
|
|
133
|
-
const output = execFileSync("git", args,
|
|
134
|
-
|
|
135
|
-
|
|
171
|
+
const output = execFileSync("git", args, {
|
|
172
|
+
...(captureOutput
|
|
173
|
+
? { stdio: "pipe", encoding: "utf8" }
|
|
174
|
+
: { stdio: "ignore" }),
|
|
175
|
+
env: gitEnv(),
|
|
176
|
+
...(timeoutMs === undefined ? {} : { timeout: timeoutMs }),
|
|
177
|
+
});
|
|
136
178
|
span.setAttribute("process.exit.code", 0);
|
|
137
179
|
return captureOutput ? String(output).trimEnd() : undefined;
|
|
138
180
|
}
|
|
@@ -181,7 +223,7 @@ export function gitRemoteRevision(repo, ref) {
|
|
|
181
223
|
return ref.toLowerCase();
|
|
182
224
|
try {
|
|
183
225
|
const pattern = ref || "HEAD";
|
|
184
|
-
const output = runGit(["ls-remote", `https://github.com/${repo}.git`, pattern, `${pattern}^{}`], true);
|
|
226
|
+
const output = runGit(["ls-remote", `https://github.com/${repo}.git`, pattern, `${pattern}^{}`], true, GIT_REMOTE_PROBE_TIMEOUT_MS);
|
|
185
227
|
return parseRemoteRevision(output, ref);
|
|
186
228
|
}
|
|
187
229
|
catch {
|
package/dist/src/telemetry.js
CHANGED
|
@@ -161,10 +161,44 @@ export function sanitizePath(path) {
|
|
|
161
161
|
return "";
|
|
162
162
|
return "[PATH]";
|
|
163
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* `adg <domain> <verb>` positionals safe to record verbatim: the top-level
|
|
166
|
+
* domains (`plugin`/`plugins`/`skill`/`skills`/`update`) plus every `plugins`
|
|
167
|
+
* verb and alias (`test/telemetry.test.ts` asserts this stays a superset of
|
|
168
|
+
* `PLUGIN_COMMANDS` and `PLUGIN_ALIASES` in `src/cli/index.ts`, so a new verb
|
|
169
|
+
* can't silently fall through to `[VALUE]`).
|
|
170
|
+
*/
|
|
171
|
+
export const ADG_SAFE_POSITIONALS = new Set([
|
|
172
|
+
"plugin",
|
|
173
|
+
"plugins",
|
|
174
|
+
"skill",
|
|
175
|
+
"skills",
|
|
176
|
+
"update",
|
|
177
|
+
"add",
|
|
178
|
+
"list",
|
|
179
|
+
"status",
|
|
180
|
+
"remove",
|
|
181
|
+
"disable",
|
|
182
|
+
"enable",
|
|
183
|
+
"init",
|
|
184
|
+
"adapt",
|
|
185
|
+
"validate",
|
|
186
|
+
"inspect",
|
|
187
|
+
"link",
|
|
188
|
+
"unlink",
|
|
189
|
+
"sync",
|
|
190
|
+
"migrate",
|
|
191
|
+
"marketplace",
|
|
192
|
+
"cache",
|
|
193
|
+
"import-skills",
|
|
194
|
+
// PLUGIN_ALIASES
|
|
195
|
+
"rm",
|
|
196
|
+
"mp",
|
|
197
|
+
]);
|
|
164
198
|
export function sanitizeArgs(args) {
|
|
165
199
|
const [executableName, ...rest] = args;
|
|
166
200
|
const safePositionals = executableName === "adg"
|
|
167
|
-
?
|
|
201
|
+
? ADG_SAFE_POSITIONALS
|
|
168
202
|
: executableName === "git"
|
|
169
203
|
? new Set(["clone", "fetch", "pull", "rev-parse", "ls-remote", "show", "init", "add", "commit", "sparse-checkout"])
|
|
170
204
|
: executableName === "npm"
|
|
@@ -98,7 +98,12 @@ export function getGitHubToken() {
|
|
|
98
98
|
// ADG patch: message broadened — this resolver is now also used to reach
|
|
99
99
|
// private repos, not just to recover from a rate limit.
|
|
100
100
|
if (!_ghWarningShown) {
|
|
101
|
-
|
|
101
|
+
// ADG patch: `skills update` parks the cursor on a transient stdout status
|
|
102
|
+
// line ("Checking skills from source: …", no trailing newline). This warning
|
|
103
|
+
// goes to stderr but lands on that same physical line in a terminal, so it
|
|
104
|
+
// would be concatenated onto it. Rewind and clear first.
|
|
105
|
+
process.stderr.write((process.stderr.isTTY ? '\r\x1b[K' : '') +
|
|
106
|
+
`${pc.yellow('│')} ${pc.yellow('GitHub authentication needed')} — using your ${pc.cyan('gh')} login to continue.\n` +
|
|
102
107
|
`${pc.yellow('│')} ${pc.dim(`Tip: set ${pc.cyan('GITHUB_TOKEN')} to avoid this prompt, or use ${pc.cyan('--full-depth')} to clone instead.\n`)}`);
|
|
103
108
|
_ghWarningShown = true;
|
|
104
109
|
}
|
|
@@ -52,6 +52,25 @@ const RESET = '\x1b[0m';
|
|
|
52
52
|
const BOLD = '\x1b[1m';
|
|
53
53
|
const DIM = '\x1b[38;5;102m';
|
|
54
54
|
const TEXT = '\x1b[38;5;145m';
|
|
55
|
+
// ADG patch: the per-source status line is *transient* on a TTY — it carries no
|
|
56
|
+
// trailing newline so the next source overwrites it in place. That means the
|
|
57
|
+
// cursor stays parked on it, and anything else written while a source is being
|
|
58
|
+
// checked (an error line, a deletion warning, a clack prompt) would be
|
|
59
|
+
// concatenated onto it. Every such site clears the line first via
|
|
60
|
+
// `clearSourceStatus()`. Off a TTY the line is an ordinary log line and both
|
|
61
|
+
// helpers degrade to plain behavior.
|
|
62
|
+
function writeSourceStatus(source) {
|
|
63
|
+
if (process.stdout.isTTY) {
|
|
64
|
+
process.stdout.write(`\r${DIM}Checking skills from source: ${source}${RESET}\x1b[K`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
process.stdout.write(`Checking skills from source: ${source}\n`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function clearSourceStatus() {
|
|
71
|
+
if (process.stdout.isTTY)
|
|
72
|
+
process.stdout.write('\r\x1b[K');
|
|
73
|
+
}
|
|
55
74
|
export function parseUpdateOptions(args) {
|
|
56
75
|
const options = {};
|
|
57
76
|
const positional = [];
|
|
@@ -234,6 +253,9 @@ export async function checkAndPromptForDeletions(source, allLockedForSource, loc
|
|
|
234
253
|
return !discoveredPaths.includes(entry.skillPath);
|
|
235
254
|
});
|
|
236
255
|
if (deletedSkills.length > 0) {
|
|
256
|
+
// ADG patch: this warning and the confirm prompt below land while the
|
|
257
|
+
// transient per-source status line still owns the cursor.
|
|
258
|
+
clearSourceStatus();
|
|
237
259
|
console.log();
|
|
238
260
|
console.log(`${DIM}Warning:${RESET} The following skills from ${DIM}${source}${RESET} appear to have been deleted upstream:`);
|
|
239
261
|
for (const s of deletedSkills) {
|
|
@@ -306,7 +328,10 @@ export async function updateGlobalSkills(options = {}) {
|
|
|
306
328
|
const firstEntry = itemsForSource[0].entry;
|
|
307
329
|
const sourceUrl = firstEntry.sourceUrl || firstEntry.source;
|
|
308
330
|
let tempDir = null;
|
|
309
|
-
|
|
331
|
+
// ADG patch: was terminated with \n despite the leading \r + clear-to-EOL,
|
|
332
|
+
// so every source left a permanent line behind and the cleanup below
|
|
333
|
+
// cleared an already blank line. See writeSourceStatus().
|
|
334
|
+
writeSourceStatus(source);
|
|
310
335
|
try {
|
|
311
336
|
const isGitHubSource = firstEntry.sourceType === 'github';
|
|
312
337
|
if (isGitHubSource) {
|
|
@@ -315,6 +340,7 @@ export async function updateGlobalSkills(options = {}) {
|
|
|
315
340
|
// ADG patch: a private repo returns 404 to anon and fetchRepoTree now
|
|
316
341
|
// retries with a token; reaching here means even that failed (no token
|
|
317
342
|
// or no access). Record it so the summary is honest.
|
|
343
|
+
clearSourceStatus();
|
|
318
344
|
console.log(` ${DIM}✗ Could not check ${source} — private repo or no GitHub access.${RESET}`);
|
|
319
345
|
console.log(` ${DIM}Set ${RESET}${TEXT}GITHUB_TOKEN${RESET}${DIM} or run ${RESET}${TEXT}gh auth login${RESET}${DIM} with access to it.${RESET}`);
|
|
320
346
|
failedSources.push(source);
|
|
@@ -372,6 +398,7 @@ export async function updateGlobalSkills(options = {}) {
|
|
|
372
398
|
}
|
|
373
399
|
}
|
|
374
400
|
catch (error) {
|
|
401
|
+
clearSourceStatus();
|
|
375
402
|
console.log(` ${DIM}✗ Failed to check skills from ${source}${RESET}`);
|
|
376
403
|
failedSources.push(source); // ADG patch: surface in the summary
|
|
377
404
|
}
|
|
@@ -380,9 +407,10 @@ export async function updateGlobalSkills(options = {}) {
|
|
|
380
407
|
await cleanupTempDir(tempDir);
|
|
381
408
|
}
|
|
382
409
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
410
|
+
// ADG patch: only meaningful now that the status line above no longer ends in
|
|
411
|
+
// a newline — the cursor is actually parked on it. No-op off a TTY.
|
|
412
|
+
if (checkable.length > 0)
|
|
413
|
+
clearSourceStatus();
|
|
386
414
|
// ADG patch: persist any self-healed (normalized) hashes once.
|
|
387
415
|
if (healed) {
|
|
388
416
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbbtsn0w/adg",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2-beta.2",
|
|
4
4
|
"description": "Agent Directory Group (ADG) toolkit — two domains: plugins and skills.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"adg": "node ./bin/adg.ts",
|
|
26
|
-
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json --noCheck && node -e \"require('fs').chmodSync('dist/bin/adg.js',0o755)\"",
|
|
26
|
+
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json --noCheck && node -e \"require('fs').cpSync('src/adapters/antigravity-hook-runner.mjs','dist/src/adapters/antigravity-hook-runner.mjs')\" && node -e \"require('fs').chmodSync('dist/bin/adg.js',0o755)\"",
|
|
27
27
|
"test": "node scripts/run-tests.mjs \"test/**/*.test.ts\" test/cache-sandbox.test.mjs",
|
|
28
28
|
"test:codex-sandbox": "node --test test/codex-sandbox.test.mjs",
|
|
29
29
|
"test:cache-sandbox": "node --test test/cache-sandbox.test.mjs",
|
|
@@ -84,4 +84,6 @@ re-vendoring. Each is marked inline with an `ADG patch:` comment.
|
|
|
84
84
|
| `src/git-tree.ts` (**new ADG file**) + `src/add.ts` clone-fallback branch | github source that falls back to a `git clone` now records the git **tree SHA** (`git rev-parse HEAD:<folder>`), not a sha256 content hash | Install and update must use ONE hash scheme per source. Update-check always uses the git tree SHA; the old clone fallback stored a sha256 content hash, so those skills were re-flagged on **every** update (a collection repo appeared to "fully update" each run). `git-tree.ts` is standalone (uses `child_process`, no simple-git) so it typechecks under ADG's strict tsconfig when a test imports it. |
|
|
85
85
|
| `src/git-tree.ts` → `gitTreeShaForFolder` | Route the ADG-added `git rev-parse` subprocess through the root OTel CLIENT-span runner | Keeps the local fallback compliant with ADG's CLI semantic-convention policy without duplicating instrumentation inside the vendored fork. |
|
|
86
86
|
| `src/skill-lock.ts`, `src/update.ts`, `src/use.ts` | Route GitHub auth, self-update, and interactive agent subprocesses through the root OTel CLIENT-span runner | Enforces required exit/error attributes and privacy-safe command arguments consistently across the vendored CLI. |
|
|
87
|
+
| `src/skill-lock.ts` → `getGitHubToken` auth warning | Prefix the one-shot stderr warning with `\r\x1b[K` on a TTY | The warning lands on the same physical terminal line as `update.ts`'s transient stdout status line, which carries no trailing newline — without rewinding, the two are rendered concatenated. |
|
|
88
|
+
| `src/update.ts` → `updateGlobalSkills` per-source status line | Drop the trailing `\n` from the transient "Checking skills from source" line on a TTY (plain line off a TTY); gate the paired `\r\x1b[K` cleanup on TTY | The line opened with `\r` + `\x1b[K`, clearly intended to overwrite in place, but ended with `\n` — so each source **accumulated** a permanent line and the cleanup ran against an already-blank line (a no-op). Off a TTY the escapes were pure noise in CI logs. |
|
|
87
89
|
| `src/update.ts` → `updateGlobalSkills` self-heal | A github entry whose stored hash isn't a 40-hex tree SHA (legacy clone-fallback) is normalized to the current tree SHA and NOT flagged; lock rewritten once | Heals locks written before the fix above without a version bump / lock wipe, and stops the perpetual false "update". |
|