@rbbtsn0w/adg 0.11.3 → 1.0.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/README.md +31 -12
- package/dist/src/agents/antigravity.js +218 -45
- package/dist/src/agents/claude.js +98 -38
- package/dist/src/agents/codex.js +1 -0
- package/dist/src/cli/core-plugin-handlers.js +3 -3
- package/dist/src/cli/handlers.js +160 -36
- package/dist/src/cli/index.js +19 -12
- package/dist/src/cli/review-update.js +80 -0
- package/dist/src/commands/install/default-dsl.js +1 -1
- package/dist/src/commands/install/install-one.js +41 -31
- package/dist/src/commands/install.js +38 -23
- package/dist/src/commands/marketplace.js +136 -109
- package/dist/src/commands/migrate.js +2 -2
- package/dist/src/commands/projection.js +3 -1
- package/dist/src/commands/remove.js +10 -0
- package/dist/src/commands/review-executables.js +106 -0
- package/dist/src/commands/select-agents.js +2 -2
- package/dist/src/commands/select-components.js +2 -2
- package/dist/src/commands/select-plugins.js +15 -2
- package/dist/src/commands/select-scope.js +3 -4
- package/dist/src/commands/source-upgrade.js +552 -0
- package/dist/src/commands/state.js +3 -1
- package/dist/src/commands/update.js +3 -1
- package/dist/src/lock.js +13 -5
- package/dist/src/migration-transaction.js +1011 -0
- package/dist/src/native-retry.js +329 -0
- package/dist/src/process-identity.js +65 -0
- package/dist/src/render/plugins.js +115 -9
- package/dist/src/source-history.js +194 -0
- package/dist/src/source-intent.js +7 -0
- package/dist/src/store-mutex.js +179 -0
- package/dist/src/types.js +1 -1
- package/dist/src/update-executables.js +193 -0
- package/dist/src/upgrade-plan.js +378 -0
- package/docs/agents/antigravity.md +5 -0
- package/docs/agents-spec.md +10 -0
- package/docs/branching-and-release.md +92 -0
- package/docs/plugin-update-semantics.md +30 -34
- package/docs/plugin-upgrade-migrations.md +349 -0
- package/package.json +4 -3
- package/schemas/plugin-lock.schema.json +78 -1
|
@@ -3,7 +3,10 @@ import { tmpdir } from "node:os";
|
|
|
3
3
|
import { join, relative, resolve } from "node:path";
|
|
4
4
|
import { toPosix } from "../fsutil.js";
|
|
5
5
|
import { lockPath } from "../paths.js";
|
|
6
|
-
import {
|
|
6
|
+
import { syncNativeBatchWithRetry } from "../native-retry.js";
|
|
7
|
+
import { installedHistory } from "../source-history.js";
|
|
8
|
+
import { sourceIntent, setSourceIntent } from "../source-intent.js";
|
|
9
|
+
import { readLock, writeLock } from "../lock.js";
|
|
7
10
|
import { resolveInstallOrder } from "../deps.js";
|
|
8
11
|
import { cloneGitHub, gitRevision, parseGitHubSource, parseSource } from "../sources.js";
|
|
9
12
|
import { materializeSource } from "../remote/index.js";
|
|
@@ -67,7 +70,7 @@ async function prepareSource(opts, parsed, sourceRef) {
|
|
|
67
70
|
throw error;
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
|
-
function activateInstalled(opts, targets, installed, existingPlugins) {
|
|
73
|
+
async function activateInstalled(opts, targets, installed, existingPlugins) {
|
|
71
74
|
const updatedLock = readLock(lockPath(opts.pluginsDir));
|
|
72
75
|
const eligible = installed.filter((result) => pluginState(updatedLock.plugins[result.name]) === "enabled");
|
|
73
76
|
const toActivate = opts.skipUnchanged ? eligible.filter((result) => result.runtimeRefreshRequired ?? result.changed) : eligible;
|
|
@@ -76,30 +79,23 @@ function activateInstalled(opts, targets, installed, existingPlugins) {
|
|
|
76
79
|
const resolved = opts.agents ?? resolveAgents(targets);
|
|
77
80
|
const scope = opts.scope ?? "project";
|
|
78
81
|
const ctxFor = (names) => ({ pluginsDir: opts.pluginsDir, plugins: names, scope });
|
|
79
|
-
|
|
82
|
+
const requests = [];
|
|
83
|
+
for (const agent of resolved) {
|
|
80
84
|
opts.onProgress?.({ kind: "activate", agent: agent.id, count: toActivate.length });
|
|
81
85
|
const queryResult = agent.listInstalled?.(ctxFor([]));
|
|
82
86
|
const agentInstalled = Array.isArray(queryResult) ? queryResult : undefined;
|
|
83
87
|
const alreadyInstalled = (name) => agentInstalled !== undefined
|
|
84
|
-
? agentInstalled.includes(name)
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
affected: [...acc.affected, ...result.affected],
|
|
96
|
-
skipped: acc.skipped && result.skipped,
|
|
97
|
-
...((acc.failures?.length || result.failures?.length) ? { failures: [...(acc.failures ?? []), ...(result.failures ?? [])] } : {}),
|
|
98
|
-
...Object.fromEntries(["verified", "unverified", "preservedDisabled"]
|
|
99
|
-
.filter((field) => acc[field] !== undefined || result[field] !== undefined)
|
|
100
|
-
.map((field) => [field, [...new Set([...(acc[field] ?? []), ...(result[field] ?? [])])]])),
|
|
101
|
-
}), { agent: agent.id, affected: [], skipped: true });
|
|
102
|
-
});
|
|
88
|
+
? agentInstalled.includes(name) : existingPlugins.has(name);
|
|
89
|
+
const activateNames = toActivate.filter(result => !alreadyInstalled(result.name)).map(result => result.name);
|
|
90
|
+
const refreshNames = toActivate.filter(result => alreadyInstalled(result.name)).map(result => result.name);
|
|
91
|
+
requests.push({
|
|
92
|
+
agent,
|
|
93
|
+
activate: activateNames,
|
|
94
|
+
refresh: refreshNames,
|
|
95
|
+
preserveRuntimeDisabled: Boolean(opts.skipUnchanged || opts.preserveExisting),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return syncNativeBatchWithRetry({ pluginsDir: opts.pluginsDir, scope, requests });
|
|
103
99
|
}
|
|
104
100
|
/**
|
|
105
101
|
* The unified install entrypoint. Treats any source as a marketplace: clone or
|
|
@@ -241,7 +237,26 @@ export async function addPlugins(opts) {
|
|
|
241
237
|
// undefined targets = all registered agents. Under skipUnchanged (the update
|
|
242
238
|
// path) only re-activate plugins that actually changed — re-running an agent
|
|
243
239
|
// CLI for an untouched plugin is wasted work.
|
|
244
|
-
|
|
240
|
+
if (!opts.preserveExisting && parsed.kind === "github") {
|
|
241
|
+
const file = lockPath(opts.pluginsDir);
|
|
242
|
+
const lock = readLock(file);
|
|
243
|
+
const previous = sourceIntent(existingLock, parsed.source, sourceRef);
|
|
244
|
+
const followAll = Boolean((opts.all || opts.followAllSelected) && !opts.plugins?.length && !opts.sparse?.length && !structuralName);
|
|
245
|
+
setSourceIntent(lock, {
|
|
246
|
+
source: parsed.source, ref: sourceRef, mode: followAll ? "all" : "selected",
|
|
247
|
+
roots: selected, excluded: followAll ? [] : (previous?.excluded ?? []).filter((name) => !order.includes(name)),
|
|
248
|
+
appliedMigrations: [],
|
|
249
|
+
history: installedHistory(opts.pluginsDir, lock, parsed.source, sourceRef),
|
|
250
|
+
deferredRecovery: previous?.deferredRecovery,
|
|
251
|
+
executableDecisions: previous?.executableDecisions,
|
|
252
|
+
...(targets ? { targets } : {}),
|
|
253
|
+
withDeps: opts.withDeps !== false,
|
|
254
|
+
...(opts.sparse ? { sparse: opts.sparse } : {}),
|
|
255
|
+
...(opts.only || opts.skillsSubset || opts.mcpSubset ? { selection: selections.get(selected[0]) } : {}),
|
|
256
|
+
});
|
|
257
|
+
writeLock(file, lock);
|
|
258
|
+
}
|
|
259
|
+
const agents = await activateInstalled(opts, targets, installed, existingPlugins);
|
|
245
260
|
return { order, installed, removed, converted, available, agents };
|
|
246
261
|
}
|
|
247
262
|
finally {
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import { upgradeSource, publishUpgradeTransaction, UpdateCancelled } from "./source-upgrade.js";
|
|
2
|
+
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
3
|
+
import { sourceIntent } from "../source-intent.js";
|
|
4
|
+
import { replayNativeRetries, syncNativeWithRetry } from "../native-retry.js";
|
|
5
|
+
import { discoverPendingMigrations } from "../migration-transaction.js";
|
|
1
6
|
import { repairCodex } from "./runtime-repair.js";
|
|
2
|
-
import { getAgent, resolveAgents
|
|
3
|
-
import {
|
|
7
|
+
import { getAgent, resolveAgents } from "../agents/index.js";
|
|
8
|
+
import {} from "../sources.js";
|
|
4
9
|
import { cloneGitHub, gitRevision, parseGitHubSource } from "../sources.js";
|
|
5
10
|
import { materializeSource, resolveRemoteRevision } from "../remote/index.js";
|
|
6
11
|
import { mkdtempSync, rmSync } from "node:fs";
|
|
7
12
|
import { tmpdir } from "node:os";
|
|
8
13
|
import { join } from "node:path";
|
|
9
14
|
import { lockPath } from "../paths.js";
|
|
10
|
-
import { readLock } from "../lock.js";
|
|
11
|
-
import { addPlugins } from "./install.js";
|
|
15
|
+
import { readLock, writeLock } from "../lock.js";
|
|
12
16
|
import { removePlugin } from "./remove.js";
|
|
13
17
|
import { syncPlugins } from "./sync.js";
|
|
14
18
|
import { updateLock } from "./update.js";
|
|
@@ -46,6 +50,10 @@ export function marketplaceList(opts) {
|
|
|
46
50
|
g.ref = ref;
|
|
47
51
|
groups.set(key, g);
|
|
48
52
|
}
|
|
53
|
+
for (const intent of lock.sources ?? []) {
|
|
54
|
+
if ((intent.mode === "all" || intent.deferredRecovery?.length) && !groups.has(intent.source))
|
|
55
|
+
groups.set(intent.source, { ref: intent.ref, installed: [] });
|
|
56
|
+
}
|
|
49
57
|
return [...groups.entries()]
|
|
50
58
|
.map(([source, g]) => ({
|
|
51
59
|
source,
|
|
@@ -114,13 +122,56 @@ export function mergeAgentResults(groups) {
|
|
|
114
122
|
* aborting the whole pass, so one unreachable repo doesn't hide the rest.
|
|
115
123
|
*/
|
|
116
124
|
export async function updatePlugins(opts) {
|
|
125
|
+
const executionProviders = opts.activate ? opts.agents ?? [...new Map([
|
|
126
|
+
...resolveAgents(opts.targets), ...(opts.repair ? resolveAgents(["codex"]) : []),
|
|
127
|
+
].map(agent => [agent.id, agent])).values()] : [];
|
|
128
|
+
// Replay pending operations before probing any remote revision.
|
|
129
|
+
const pending = discoverPendingMigrations(opts.pluginsDir).filter(item => !opts.source || item.source === opts.source);
|
|
130
|
+
const remote = [];
|
|
131
|
+
const resumedAgents = [];
|
|
132
|
+
const managedByMigration = new Set();
|
|
133
|
+
const rememberManagedNative = (targets) => {
|
|
134
|
+
for (const target of targets)
|
|
135
|
+
if (target.agent === "codex")
|
|
136
|
+
for (const name of target.plugins)
|
|
137
|
+
managedByMigration.add(name);
|
|
138
|
+
};
|
|
139
|
+
for (const item of pending) {
|
|
140
|
+
let resumed;
|
|
141
|
+
try {
|
|
142
|
+
resumed = await publishUpgradeTransaction(item.journalPath, executionProviders, item.source, opts.review, item.ref, opts.repair ? ["codex"] : undefined);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
if (error instanceof UpdateCancelled) {
|
|
146
|
+
error.partial = { remote: [...remote, ...(error.partial?.remote ?? [])], local: { results: [], missing: [] },
|
|
147
|
+
agents: [...resumedAgents, ...(error.partial?.agents ?? [])] };
|
|
148
|
+
}
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
resumedAgents.push(...(resumed.agents ?? []));
|
|
152
|
+
rememberManagedNative(resumed.managedNative ?? []);
|
|
153
|
+
remote.push({
|
|
154
|
+
source: item.source, ref: item.ref, updated: [], unchanged: [], deleted: [], available: [],
|
|
155
|
+
...(resumed.complete ? { resumed: true } : { pendingRuntime: resumed.failures.map(failure => failure.message) }),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
const recovered = await replayNativeRetries({
|
|
159
|
+
pluginsDir: opts.pluginsDir, source: opts.source, agents: executionProviders,
|
|
160
|
+
onProgress: opts.onProgress,
|
|
161
|
+
});
|
|
162
|
+
for (const group of recovered.groups) {
|
|
163
|
+
const failures = recovered.pending.filter(item => item.source === group.source && item.ref === group.ref);
|
|
164
|
+
remote.push({ ...group, updated: [], unchanged: [], deleted: [], available: [],
|
|
165
|
+
...(failures.length ? { pendingRuntime: failures.map(item => item.message) } : { resumed: true }) });
|
|
166
|
+
}
|
|
117
167
|
const allGroups = marketplaceList({ pluginsDir: opts.pluginsDir });
|
|
118
168
|
// A named source narrows to just that group (and must be remote); otherwise we
|
|
119
169
|
// refresh every remote source and rescan the local bucket.
|
|
120
170
|
const selectedGroups = opts.source
|
|
121
|
-
?
|
|
171
|
+
? (remote.some(group => group.source === opts.source) ? allGroups.filter(group => group.source === opts.source)
|
|
172
|
+
: [requireGroup(opts.pluginsDir, opts.source, opts.scope)])
|
|
122
173
|
: allGroups.filter((g) => g.remote);
|
|
123
|
-
if (opts.source &&
|
|
174
|
+
if (opts.source && selectedGroups[0]?.remote === false) {
|
|
124
175
|
throw new Error(`source "${opts.source}" is local and cannot be re-synced; re-run \`adg plugins add\`.`);
|
|
125
176
|
}
|
|
126
177
|
// The marketplace view aggregates a repository for list/remove/sync. Update
|
|
@@ -136,7 +187,12 @@ export async function updatePlugins(opts) {
|
|
|
136
187
|
member.installed.push(name);
|
|
137
188
|
refs.set(ref, member);
|
|
138
189
|
}
|
|
139
|
-
|
|
190
|
+
for (const intent of initialLock.sources ?? []) {
|
|
191
|
+
if (intent.source === group.source && (intent.mode === "all" || intent.deferredRecovery?.length) && !refs.has(intent.ref)) {
|
|
192
|
+
refs.set(intent.ref, { source: group.source, ref: intent.ref, installed: [], remote: true });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return [...refs.values()].filter(group => !remote.some(item => item.source === group.source && item.ref === group.ref));
|
|
140
196
|
});
|
|
141
197
|
const repairAgent = opts.agents
|
|
142
198
|
? opts.agents.find((agent) => agent.id === "codex") ?? null
|
|
@@ -145,46 +201,43 @@ export async function updatePlugins(opts) {
|
|
|
145
201
|
const initial = opts.repair ? repairAgent?.inspectPlugins?.({ pluginsDir: opts.pluginsDir, plugins: [], scope: repairScope }) : undefined;
|
|
146
202
|
// Source materialization proceeds, but this mode owns every Codex mutation.
|
|
147
203
|
const updateAgents = opts.repair ? (opts.agents ?? resolveAgents(opts.targets)).filter((agent) => agent.id !== "codex") : opts.agents;
|
|
148
|
-
const removalAgents = opts.repair ? (opts.deactivationAgents ?? allAgents()).filter((agent) => agent.id !== "codex") : opts.deactivationAgents;
|
|
149
204
|
const now = opts.now ?? new Date().toISOString();
|
|
150
|
-
const
|
|
151
|
-
const remoteAgents = [];
|
|
205
|
+
const remoteAgents = [...resumedAgents, ...recovered.agents];
|
|
152
206
|
let sourceIndex = 0;
|
|
153
207
|
for (const group of remoteGroups) {
|
|
154
208
|
const position = { index: ++sourceIndex, total: remoteGroups.length };
|
|
155
209
|
try {
|
|
156
210
|
opts.onProgress?.({ kind: "check", ...position, source: group.source });
|
|
157
211
|
const lock = readLock(lockPath(opts.pluginsDir));
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
212
|
+
const policy = sourceIntent(lock, group.source, group.ref);
|
|
213
|
+
const targets = opts.targets ?? policy?.targets?.filter((id) => ADAPTER_TARGETS.includes(id));
|
|
214
|
+
const runtime = opts.activate ? opts.agents ?? resolveAgents(targets) : [];
|
|
215
|
+
const refreshExisting = runtime.flatMap(agent => {
|
|
216
|
+
if (!agent.needsProjectionRefresh || !agent.detect())
|
|
217
|
+
return [];
|
|
218
|
+
const names = group.installed.filter(name => lock.plugins[name]?.state !== "disabled");
|
|
219
|
+
return agent.needsProjectionRefresh({ pluginsDir: opts.pluginsDir, scope: repairScope, plugins: names })
|
|
220
|
+
.map(name => ({ name, target: agent.id }));
|
|
221
|
+
});
|
|
222
|
+
const refreshProjections = async (unchanged) => {
|
|
223
|
+
for (const agent of runtime) {
|
|
224
|
+
const refresh = refreshExisting.filter(item => item.target === agent.id && unchanged.includes(item.name)).map(item => item.name);
|
|
225
|
+
if (refresh.length)
|
|
226
|
+
remoteAgents.push(await syncNativeWithRetry({
|
|
227
|
+
pluginsDir: opts.pluginsDir, scope: repairScope, agent, activate: [], refresh, preserveRuntimeDisabled: true,
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const revisions = group.installed.map((name) => policy?.retained?.includes(name) ? policy.retainedAtRevision : lock.plugins[name]?.resolvedRevision).filter((revision) => Boolean(revision));
|
|
232
|
+
// A supplied transport owns its checkout, including offline fixtures.
|
|
233
|
+
const probe = opts.revisionResolver ?? (opts.gitRunner ? undefined : resolveRemoteRevision);
|
|
234
|
+
const remoteRevision = await probe?.(group.source, group.ref);
|
|
235
|
+
if (!opts.all && !(opts.repair && policy?.deferredRecovery?.length) && revisions.length > 0 && remoteRevision && revisions.length === group.installed.length && revisions.every((revision) => revision === remoteRevision)) {
|
|
236
|
+
await refreshProjections(group.installed);
|
|
237
|
+
remote.push({ source: group.source, ...(group.ref ? { ref: group.ref } : {}), updated: [], unchanged: group.installed.filter(name => !policy?.retained?.includes(name)).sort(), retained: policy?.retained, deleted: [], available: [],
|
|
238
|
+
...(policy?.deferredRecovery?.length ? { deferredRecovery: [...new Set(policy.deferredRecovery.flatMap(item => item.skills))].sort() } : {}) });
|
|
162
239
|
continue;
|
|
163
240
|
}
|
|
164
|
-
const structural = group.installed.flatMap((name) => {
|
|
165
|
-
const definition = lock.plugins[name]?.definition;
|
|
166
|
-
return definition ? [{ name, definition, selection: lock.plugins[name]?.selection }] : [];
|
|
167
|
-
});
|
|
168
|
-
const ordinary = group.installed.filter((name) => !lock.plugins[name]?.definition);
|
|
169
|
-
// A structural profile always describes the source root. Replay each
|
|
170
|
-
// profile independently so its stable --as identity is preserved.
|
|
171
|
-
const requests = [
|
|
172
|
-
...structural.map(({ name, definition, selection }) => ({
|
|
173
|
-
plugins: [name],
|
|
174
|
-
as: definition.as,
|
|
175
|
-
structuralIdentity: name,
|
|
176
|
-
defaultDescription: definition.description,
|
|
177
|
-
authorizedComponents: definition.authorizedComponents,
|
|
178
|
-
replaySelection: selection ?? (definition.authorizedComponents ? { components: definition.authorizedComponents } : undefined),
|
|
179
|
-
})),
|
|
180
|
-
// A structural profile represents the whole source root. Never append
|
|
181
|
-
// an --all fallback that could derive a second Default DSL identity.
|
|
182
|
-
...(structural.length === 0 && (ordinary.length > 0 || opts.all)
|
|
183
|
-
? [{ plugins: opts.all ? undefined : ordinary }]
|
|
184
|
-
: []),
|
|
185
|
-
];
|
|
186
|
-
const installed = [];
|
|
187
|
-
const available = new Set();
|
|
188
241
|
const checkout = mkdtempSync(join(tmpdir(), "adg-marketplace-update-"));
|
|
189
242
|
try {
|
|
190
243
|
const parsed = parseGitHubSource(group.source);
|
|
@@ -192,76 +245,46 @@ export async function updatePlugins(opts) {
|
|
|
192
245
|
const mat = await materializeSource({ ...parsed, ref: group.ref }, checkout, {
|
|
193
246
|
runner: opts.gitRunner,
|
|
194
247
|
resolvedRevision: remoteRevision,
|
|
248
|
+
// A complete source catalog is required to distinguish relocation
|
|
249
|
+
// from deletion, including siblings outside an earlier sparse add.
|
|
195
250
|
});
|
|
196
251
|
const resolvedRevision = mat.resolvedRevision ?? gitRevision(checkout);
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
opts.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
...(request.defaultDescription ? { defaultDescription: request.defaultDescription } : {}),
|
|
223
|
-
activate: opts.activate,
|
|
224
|
-
scope: opts.agentScope,
|
|
225
|
-
agents: updateAgents,
|
|
226
|
-
deactivationAgents: removalAgents,
|
|
227
|
-
now,
|
|
228
|
-
preparedSourceDir: checkout,
|
|
229
|
-
preparedResolvedRevision: resolvedRevision,
|
|
230
|
-
...(opts.cwd ? { cwd: opts.cwd } : {}),
|
|
231
|
-
...(opts.onProgress ? { onProgress: opts.onProgress } : {}),
|
|
232
|
-
});
|
|
233
|
-
installed.push(...result.installed);
|
|
234
|
-
result.available.forEach((name) => available.add(name));
|
|
235
|
-
if (result.agents)
|
|
236
|
-
remoteAgents.push(...result.agents);
|
|
237
|
-
}
|
|
252
|
+
const result = await upgradeSource({
|
|
253
|
+
group, checkout, revision: resolvedRevision, pluginsDir: opts.pluginsDir,
|
|
254
|
+
all: opts.all, repair: opts.repair, activate: opts.activate, scope: repairScope, agents: opts.agents,
|
|
255
|
+
targets: opts.targets, now, review: opts.review, refreshExisting,
|
|
256
|
+
gitRunner: opts.gitRunner, onProgress: opts.onProgress,
|
|
257
|
+
onAgentResults: results => remoteAgents.push(...results),
|
|
258
|
+
onNativeManaged: rememberManagedNative,
|
|
259
|
+
});
|
|
260
|
+
remote.push(result);
|
|
261
|
+
if (result.deferredRecovery?.length)
|
|
262
|
+
recordTelemetryEvent("adg.plugins.update.recovery_deferred", {
|
|
263
|
+
"skills.count": result.deferredRecovery.length,
|
|
264
|
+
}, opts.telemetrySpan);
|
|
265
|
+
if (result.missingUpstream?.length)
|
|
266
|
+
recordTelemetryEvent("adg.plugins.update.missing_upstream", {
|
|
267
|
+
"plugins.retained": result.missingUpstream.length,
|
|
268
|
+
"update.include_new": Boolean(opts.all),
|
|
269
|
+
}, opts.telemetrySpan);
|
|
270
|
+
else
|
|
271
|
+
recordTelemetryEvent("adg.plugins.update.migration", {
|
|
272
|
+
"migration.count": result.migrated?.length ?? 0,
|
|
273
|
+
"action_required.count": result.actionRequired?.length ?? 0,
|
|
274
|
+
"pending.count": result.pendingRuntime?.length ?? 0,
|
|
275
|
+
"plugins.retained": result.missingUpstream?.length ?? 0,
|
|
276
|
+
}, opts.telemetrySpan);
|
|
238
277
|
}
|
|
239
278
|
finally {
|
|
240
279
|
rmSync(checkout, { recursive: true, force: true });
|
|
241
280
|
}
|
|
242
|
-
const availableSet = available;
|
|
243
|
-
const installedNow = new Set(Object.keys(readLock(lockPath(opts.pluginsDir)).plugins));
|
|
244
|
-
const missingUpstream = group.installed.filter((name) => !availableSet.has(name)).sort();
|
|
245
|
-
if (missingUpstream.length > 0) {
|
|
246
|
-
recordTelemetryEvent("adg.plugins.update.missing_upstream", {
|
|
247
|
-
"plugins.retained": missingUpstream.length,
|
|
248
|
-
"update.include_new": Boolean(opts.all),
|
|
249
|
-
}, opts.telemetrySpan);
|
|
250
|
-
}
|
|
251
|
-
remote.push({
|
|
252
|
-
source: group.source,
|
|
253
|
-
...(group.ref ? { ref: group.ref } : {}),
|
|
254
|
-
updated: installed.filter((r) => r.changed).map((r) => r.name).sort(),
|
|
255
|
-
unchanged: installed.filter((r) => !r.changed).map((r) => r.name).sort(),
|
|
256
|
-
deleted: [],
|
|
257
|
-
...(missingUpstream.length > 0 ? { missingUpstream } : {}),
|
|
258
|
-
available: [...available].filter((n) => !installedNow.has(n)).sort(),
|
|
259
|
-
changes: installed.filter((r) => r.changes).map((r) => ({
|
|
260
|
-
name: r.name, ...r.changes, runtimeRefreshRequired: r.runtimeRefreshRequired ?? r.changed,
|
|
261
|
-
})).sort((a, b) => a.name.localeCompare(b.name)),
|
|
262
|
-
});
|
|
263
281
|
}
|
|
264
282
|
catch (err) {
|
|
283
|
+
if (err instanceof UpdateCancelled) {
|
|
284
|
+
err.partial = { remote: [...remote, ...(err.partial?.remote ?? [])], local: { results: [], missing: [] },
|
|
285
|
+
agents: [...remoteAgents, ...(err.partial?.agents ?? [])] };
|
|
286
|
+
throw err;
|
|
287
|
+
}
|
|
265
288
|
remote.push({
|
|
266
289
|
source: group.source,
|
|
267
290
|
...(group.ref ? { ref: group.ref } : {}),
|
|
@@ -286,18 +309,16 @@ export async function updatePlugins(opts) {
|
|
|
286
309
|
...(opts.onProgress ? { onProgress: opts.onProgress } : {}),
|
|
287
310
|
})
|
|
288
311
|
: { results: [], missing: [] };
|
|
289
|
-
const repairNames = [...new Set([...
|
|
312
|
+
const repairNames = [...new Set([...selectedGroups.flatMap((group) => group.installed), ...remote.flatMap((source) => [...source.updated, ...source.unchanged]), ...localNames])].filter(name => !managedByMigration.has(name));
|
|
290
313
|
const currentLock = readLock(lockPath(opts.pluginsDir));
|
|
291
|
-
const repairs = opts.repair ? [repairCodex({
|
|
292
|
-
pluginsDir: opts.pluginsDir,
|
|
293
|
-
plugins: repairNames.filter((name) => currentLock.plugins[name]),
|
|
294
|
-
scope: opts.agentScope ?? "project",
|
|
314
|
+
const repairs = opts.activate && opts.repair && repairNames.length ? [repairCodex({
|
|
315
|
+
pluginsDir: opts.pluginsDir, plugins: repairNames.filter(name => currentLock.plugins[name]), scope: repairScope,
|
|
295
316
|
}, false, repairAgent, {
|
|
296
317
|
initial, observed: true,
|
|
297
|
-
changed: [...remote.flatMap(
|
|
298
|
-
? source.changes.filter(
|
|
299
|
-
: source.updated), ...local.results.filter(
|
|
300
|
-
removed: repairNames.filter(
|
|
318
|
+
changed: [...remote.flatMap(source => source.changes
|
|
319
|
+
? source.changes.filter(plugin => plugin.runtimeRefreshRequired).map(plugin => plugin.name)
|
|
320
|
+
: source.updated), ...local.results.filter(plugin => plugin.runtimeRefreshRequired ?? plugin.changed).map(plugin => plugin.name)],
|
|
321
|
+
removed: repairNames.filter(name => !currentLock.plugins[name]),
|
|
301
322
|
})] : [];
|
|
302
323
|
const agents = mergeAgentResults([remoteAgents, local.agents ?? [], repairs]);
|
|
303
324
|
return { remote, local, agents };
|
|
@@ -316,6 +337,12 @@ export function marketplaceRemove(opts) {
|
|
|
316
337
|
});
|
|
317
338
|
removed.push(name);
|
|
318
339
|
}
|
|
340
|
+
const file = lockPath(opts.pluginsDir);
|
|
341
|
+
const lock = readLock(file);
|
|
342
|
+
if (lock.sources?.some(intent => intent.source === opts.source)) {
|
|
343
|
+
lock.sources = lock.sources.filter(intent => intent.source !== opts.source);
|
|
344
|
+
writeLock(file, lock);
|
|
345
|
+
}
|
|
319
346
|
return { source: opts.source, removed };
|
|
320
347
|
}
|
|
321
348
|
/**
|
|
@@ -73,9 +73,9 @@ function migrateLock(pluginsDir, telemetrySpan) {
|
|
|
73
73
|
if (raw.version === LOCK_VERSION)
|
|
74
74
|
return false;
|
|
75
75
|
if (typeof raw?.version === "number") {
|
|
76
|
-
recordTelemetryEvent("adg.lock.read", { "format.version": raw.version === 2 || raw.version === 3 || raw.version === 4 ? raw.version : -1 }, telemetrySpan);
|
|
76
|
+
recordTelemetryEvent("adg.lock.read", { "format.version": raw.version === 2 || raw.version === 3 || raw.version === 4 || raw.version === 5 ? raw.version : -1 }, telemetrySpan);
|
|
77
77
|
}
|
|
78
|
-
if (
|
|
78
|
+
if ([3, 4, 5].includes(raw.version) && typeof raw.plugins === "object" && raw.plugins !== null) {
|
|
79
79
|
// v3 has the same payload model; v4 adds optional immutable provenance.
|
|
80
80
|
// Existing remote entries remain explicitly legacy until an update/add
|
|
81
81
|
// resolves their commit, rather than inventing a moving ref as a revision.
|
|
@@ -3,6 +3,7 @@ import { relative } from "node:path";
|
|
|
3
3
|
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
4
4
|
import { installPlugin } from "./install.js";
|
|
5
5
|
import { resolvePluginSourceSnapshot } from "../source-cache.js";
|
|
6
|
+
import { preservedSelection, requestedSelectionKnown } from "../source-history.js";
|
|
6
7
|
/**
|
|
7
8
|
* Shared selection for the projection verbs (link / unlink / sync). Resolve which
|
|
8
9
|
* installed plugins to act on: the named subset (validated against the store), or
|
|
@@ -42,7 +43,8 @@ export function rematerializeInstalled(pluginsDir, plugins) {
|
|
|
42
43
|
pluginsDir,
|
|
43
44
|
origin: plugin.origin,
|
|
44
45
|
resolvedRevision: plugin.resolvedRevision,
|
|
45
|
-
selection: plugin.
|
|
46
|
+
selection: preservedSelection(pluginsDir, plugin.name, plugin),
|
|
47
|
+
selectionKnown: requestedSelectionKnown(plugin),
|
|
46
48
|
targets: [...ADAPTER_TARGETS],
|
|
47
49
|
forceMaterialize: true,
|
|
48
50
|
}));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sourceIntent } from "../source-intent.js";
|
|
1
2
|
import { existsSync, lstatSync, readdirSync, readlinkSync, rmdirSync, rmSync } from "node:fs";
|
|
2
3
|
import { basename, dirname, join, resolve } from "node:path";
|
|
3
4
|
import { claudeSkillsDir, lockPath, marketplacePath, pluginCacheRoot, pluginDir, pluginSourceCacheDir } from "../paths.js";
|
|
@@ -64,6 +65,15 @@ export function removePlugin(opts) {
|
|
|
64
65
|
if (existsSync(cacheRoot) && readdirSync(cacheRoot).length === 0)
|
|
65
66
|
rmSync(cacheRoot, { recursive: true, force: true });
|
|
66
67
|
}
|
|
68
|
+
const origin = lock.plugins[name]?.origin;
|
|
69
|
+
if (origin?.type === "github") {
|
|
70
|
+
const intent = sourceIntent(lock, origin.repo, origin.ref);
|
|
71
|
+
if (intent) {
|
|
72
|
+
intent.roots = intent.roots.filter((root) => root !== name);
|
|
73
|
+
if (!intent.excluded.includes(name))
|
|
74
|
+
intent.excluded.push(name);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
67
77
|
const removedFromLock = removeEntry(lock, name);
|
|
68
78
|
if (removedFromLock)
|
|
69
79
|
writeLock(lockFile, lock);
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { pluginContents } from "../components.js";
|
|
4
|
+
import { readManifest } from "../manifest.js";
|
|
5
|
+
import { pluginSourceCacheDir } from "../paths.js";
|
|
6
|
+
import { COMPONENT_TYPES, resolveSelectionDependencies, } from "../types.js";
|
|
7
|
+
import { executableInventory } from "../update-executables.js";
|
|
8
|
+
import { contentHash } from "./install/install-one.js";
|
|
9
|
+
import { requestedSelectionKnown, verifiedInstalledPayload } from "../source-history.js";
|
|
10
|
+
export class UpdateCancelled extends Error {
|
|
11
|
+
partial;
|
|
12
|
+
}
|
|
13
|
+
export function verifiedSource(pluginsDir, name, entry) {
|
|
14
|
+
const cached = pluginSourceCacheDir(pluginsDir, name);
|
|
15
|
+
try {
|
|
16
|
+
if (existsSync(cached) && contentHash(cached, readManifest(cached)) === entry.sourceHash)
|
|
17
|
+
return cached;
|
|
18
|
+
}
|
|
19
|
+
catch { /* Damaged source metadata is unavailable evidence; the update can rebuild it. */ }
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
/** Selections are shared across projections. Ask once per effective service or hook file. */
|
|
23
|
+
export async function reviewExecutables(pluginsDir, intent, candidates, targets, review) {
|
|
24
|
+
const permissions = [];
|
|
25
|
+
const selections = new Map();
|
|
26
|
+
const blockers = [];
|
|
27
|
+
for (const { name, candidate, selection, old } of candidates) {
|
|
28
|
+
const effective = resolveSelectionDependencies(candidate.manifest, selection);
|
|
29
|
+
const proposed = executableInventory(candidate.dir, candidate.manifest, effective, targets);
|
|
30
|
+
if (!proposed.length)
|
|
31
|
+
continue;
|
|
32
|
+
const selectionKnown = old && requestedSelectionKnown(old);
|
|
33
|
+
// Complete source bytes establish permission only with a known requested policy.
|
|
34
|
+
const previous = old && ((selectionKnown ? verifiedSource(pluginsDir, name, old) : undefined)
|
|
35
|
+
?? verifiedInstalledPayload(pluginsDir, name, old));
|
|
36
|
+
const prior = previous
|
|
37
|
+
? executableInventory(previous, readManifest(previous), selectionKnown ? resolveSelectionDependencies(readManifest(previous), old?.selection) : undefined, targets)
|
|
38
|
+
: [];
|
|
39
|
+
const approved = new Set(prior.map((entry) => entry.id));
|
|
40
|
+
const groups = new Map();
|
|
41
|
+
for (const entry of proposed) {
|
|
42
|
+
const group = entry.component + ":" + entry.member;
|
|
43
|
+
const entries = groups.get(group) ?? [];
|
|
44
|
+
entries.push(entry);
|
|
45
|
+
groups.set(group, entries);
|
|
46
|
+
}
|
|
47
|
+
for (const entries of groups.values()) {
|
|
48
|
+
if (entries.every((entry) => approved.has(entry.id)))
|
|
49
|
+
continue;
|
|
50
|
+
const first = entries[0];
|
|
51
|
+
const hash = createHash("sha256")
|
|
52
|
+
.update(JSON.stringify(entries.map((entry) => entry.id).sort()))
|
|
53
|
+
.digest("hex");
|
|
54
|
+
permissions.push({
|
|
55
|
+
key: name + ":" + hash,
|
|
56
|
+
name,
|
|
57
|
+
component: first.component,
|
|
58
|
+
member: first.member,
|
|
59
|
+
label: name +
|
|
60
|
+
" / " +
|
|
61
|
+
[...new Set(entries.filter((entry) => !approved.has(entry.id)).map((entry) => entry.label))].join(", "),
|
|
62
|
+
previouslyEnabled: prior.some((entry) => entry.component === first.component && (first.component === "hooks" || entry.member === first.member)),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const unknown = permissions.filter((item) => intent.executableDecisions?.[item.key] === undefined);
|
|
67
|
+
if (unknown.length) {
|
|
68
|
+
if (!review)
|
|
69
|
+
return { selections, blockers: unknown.map((item) => "Approval required: " + item.label), reviewed: false };
|
|
70
|
+
const answer = await review({ source: intent.source, history: [], executable: unknown });
|
|
71
|
+
if (!answer)
|
|
72
|
+
throw new UpdateCancelled();
|
|
73
|
+
intent.executableDecisions ??= {};
|
|
74
|
+
for (const item of unknown)
|
|
75
|
+
intent.executableDecisions[item.key] = answer.allow.includes(item.key);
|
|
76
|
+
}
|
|
77
|
+
for (const { name, candidate, selection } of candidates) {
|
|
78
|
+
const denied = permissions.filter((item) => item.name === name && !intent.executableDecisions?.[item.key]);
|
|
79
|
+
if (!denied.length)
|
|
80
|
+
continue;
|
|
81
|
+
// Replacing an existing live handler/service with a denied revision would
|
|
82
|
+
// remove a capability the user already relies on. Preserve the old group.
|
|
83
|
+
if (denied.some((item) => item.previouslyEnabled)) {
|
|
84
|
+
blockers.push("The existing installation was kept because this update changes " +
|
|
85
|
+
denied.map((item) => item.label).join(", ") +
|
|
86
|
+
".");
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const denyHooks = denied.some((item) => item.component === "hooks");
|
|
90
|
+
const servers = denied.filter((item) => item.component === "mcp").map((item) => item.member);
|
|
91
|
+
const filtered = {
|
|
92
|
+
...selection,
|
|
93
|
+
components: (selection?.components ?? [...COMPONENT_TYPES]).filter((component) => component !== "hooks" || !denyHooks),
|
|
94
|
+
};
|
|
95
|
+
if (servers.length)
|
|
96
|
+
filtered.mcp = (selection?.mcp ?? pluginContents(candidate.dir, candidate.manifest).mcp).filter((server) => !servers.includes(server));
|
|
97
|
+
const checked = resolveSelectionDependencies(candidate.manifest, filtered);
|
|
98
|
+
if (executableInventory(candidate.dir, candidate.manifest, checked, targets).some((item) => (denyHooks && item.component === "hooks") || (item.component === "mcp" && servers.includes(item.member)))) {
|
|
99
|
+
blockers.push(name + " requires a declined executable component. The current installation was kept.");
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
selections.set(name, filtered);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return { selections, blockers, reviewed: permissions.length > 0 };
|
|
106
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UpdateCancelled } from "./source-upgrade.js";
|
|
1
2
|
import * as p from "@clack/prompts";
|
|
2
3
|
import pc from "picocolors";
|
|
3
4
|
import { allAgents, detectedAgents } from "../agents/index.js";
|
|
@@ -33,8 +34,7 @@ export async function selectTargetsInteractive() {
|
|
|
33
34
|
required: true,
|
|
34
35
|
});
|
|
35
36
|
if (p.isCancel(selected)) {
|
|
36
|
-
|
|
37
|
-
process.exit(0);
|
|
37
|
+
throw new UpdateCancelled("Installation cancelled");
|
|
38
38
|
}
|
|
39
39
|
return selected;
|
|
40
40
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { UpdateCancelled } from "./source-upgrade.js";
|
|
1
2
|
import * as p from "@clack/prompts";
|
|
2
3
|
import pc from "picocolors";
|
|
3
4
|
import { multiselectSkills } from "./multiselect-skills.js";
|
|
4
5
|
function cancelled(value) {
|
|
5
6
|
if (p.isCancel(value)) {
|
|
6
|
-
|
|
7
|
-
process.exit(0);
|
|
7
|
+
throw new UpdateCancelled("Installation cancelled");
|
|
8
8
|
}
|
|
9
9
|
return false;
|
|
10
10
|
}
|