@rbbtsn0w/adg 0.7.1-beta.9 → 0.7.2-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 +22 -6
- package/dist/src/cli/handlers.js +11 -0
- package/dist/src/commands/install.js +1 -0
- 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/vendor/skills/src/skill-lock.js +6 -1
- package/dist/vendor/skills/src/update.js +32 -4
- package/package.json +1 -1
- package/vendor/skills/PROVENANCE.md +2 -0
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) {
|
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";
|
|
@@ -292,11 +293,15 @@ async function handleSync(rest, cmd) {
|
|
|
292
293
|
async function handleUpdate(rest, cmd) {
|
|
293
294
|
const { values, positionals } = parseVerb("update", cmd.flags, rest);
|
|
294
295
|
const source = positionals[0];
|
|
296
|
+
// First paint, before the scope prompt and before any lock read, so the run
|
|
297
|
+
// never opens on a blank screen. stderr keeps stdout to the report alone.
|
|
298
|
+
process.stderr.write(`${ui.title("adg plugins update")}\n`);
|
|
295
299
|
let succeeded = 0;
|
|
296
300
|
let failed = 0;
|
|
297
301
|
for (const sc of await resolveUpdateScopes(values)) {
|
|
298
302
|
if (sc.heading)
|
|
299
303
|
console.log(`${ui.name(sc.heading)}`);
|
|
304
|
+
const progress = createProgress();
|
|
300
305
|
try {
|
|
301
306
|
const result = await updatePlugins({
|
|
302
307
|
pluginsDir: sc.dir,
|
|
@@ -305,13 +310,19 @@ async function handleUpdate(rest, cmd) {
|
|
|
305
310
|
activate: true,
|
|
306
311
|
agentScope: sc.agentScope,
|
|
307
312
|
scope: { label: sc.label, globalDir: globalPluginsDir() },
|
|
313
|
+
onProgress: (phase) => progress.update(phase),
|
|
308
314
|
});
|
|
315
|
+
// Clear the animated line before the report goes to stdout, so the two
|
|
316
|
+
// streams don't interleave mid-line.
|
|
317
|
+
progress.stop();
|
|
309
318
|
printUpdateReport(result);
|
|
310
319
|
const counts = updateResultCounts(result);
|
|
320
|
+
console.log(formatUpdateSummary(counts, progress.elapsedMs()));
|
|
311
321
|
succeeded += counts.succeeded;
|
|
312
322
|
failed += counts.failed;
|
|
313
323
|
}
|
|
314
324
|
catch (err) {
|
|
325
|
+
progress.stop();
|
|
315
326
|
console.error(`${ui.err("error:")} ${err instanceof Error ? err.message : String(err)}`);
|
|
316
327
|
failed += 1;
|
|
317
328
|
}
|
|
@@ -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
|
|
@@ -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 {
|
|
@@ -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
|
@@ -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". |
|