@rbbtsn0w/adg 0.11.4 → 1.0.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 +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 +88 -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 +53 -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
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import * as p from "@clack/prompts";
|
|
2
2
|
import pc from "picocolors";
|
|
3
|
+
import { UpdateCancelled } from "./source-upgrade.js";
|
|
4
|
+
export const FOLLOW_ALL_PLUGINS = ":follow-all";
|
|
3
5
|
/**
|
|
4
6
|
* Interactive multiselect for choosing which plugins to install from a source
|
|
5
7
|
* that holds several. Mirrors the skills install flow. Native (reverse-adapted)
|
|
6
8
|
* plugins are flagged so the user knows they came from a Claude/Codex manifest.
|
|
7
9
|
*/
|
|
8
10
|
export async function selectPluginsInteractive(choices) {
|
|
11
|
+
const subscription = await p.select({
|
|
12
|
+
message: "Choose how this source is followed",
|
|
13
|
+
options: [
|
|
14
|
+
{ value: "selected", label: "Choose plugins", hint: "update selected plugins; do not automatically add future plugins" },
|
|
15
|
+
{ value: "all", label: "Follow all plugins", hint: "install every current plugin and subscribe to future additions" },
|
|
16
|
+
],
|
|
17
|
+
initialValue: "selected",
|
|
18
|
+
});
|
|
19
|
+
if (p.isCancel(subscription))
|
|
20
|
+
throw new UpdateCancelled("Installation cancelled");
|
|
21
|
+
if (subscription === "all")
|
|
22
|
+
return [FOLLOW_ALL_PLUGINS];
|
|
9
23
|
const selected = await p.multiselect({
|
|
10
24
|
message: `Select plugins to install ${pc.dim("(space to toggle)")}`,
|
|
11
25
|
options: choices.map((c) => ({
|
|
@@ -18,8 +32,7 @@ export async function selectPluginsInteractive(choices) {
|
|
|
18
32
|
required: true,
|
|
19
33
|
});
|
|
20
34
|
if (p.isCancel(selected)) {
|
|
21
|
-
|
|
22
|
-
process.exit(0);
|
|
35
|
+
throw new UpdateCancelled("Installation cancelled");
|
|
23
36
|
}
|
|
24
37
|
return selected;
|
|
25
38
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UpdateCancelled } from "./source-upgrade.js";
|
|
1
2
|
import * as p from "@clack/prompts";
|
|
2
3
|
/**
|
|
3
4
|
* Ask whether to install into the project (.agents/plugins) or globally
|
|
@@ -13,8 +14,7 @@ export async function selectScopeInteractive() {
|
|
|
13
14
|
],
|
|
14
15
|
});
|
|
15
16
|
if (p.isCancel(scope)) {
|
|
16
|
-
|
|
17
|
-
process.exit(0);
|
|
17
|
+
throw new UpdateCancelled("Installation cancelled");
|
|
18
18
|
}
|
|
19
19
|
return scope;
|
|
20
20
|
}
|
|
@@ -33,8 +33,7 @@ export async function selectUpdateScopeInteractive() {
|
|
|
33
33
|
],
|
|
34
34
|
});
|
|
35
35
|
if (p.isCancel(scope)) {
|
|
36
|
-
|
|
37
|
-
process.exit(0);
|
|
36
|
+
throw new UpdateCancelled("Installation cancelled");
|
|
38
37
|
}
|
|
39
38
|
return scope;
|
|
40
39
|
}
|
|
@@ -0,0 +1,552 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { isDeepStrictEqual } from "node:util";
|
|
4
|
+
import { join, relative } from "node:path";
|
|
5
|
+
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
6
|
+
import { resolveAgents } from "../agents/index.js";
|
|
7
|
+
import { pluginContents } from "../components.js";
|
|
8
|
+
import { resolveInstallOrder } from "../deps.js";
|
|
9
|
+
import { toPosix } from "../fsutil.js";
|
|
10
|
+
import { readLock, writeLock } from "../lock.js";
|
|
11
|
+
import { readManifest } from "../manifest.js";
|
|
12
|
+
import { prepareMigrationTransaction, publishMigrationTransaction, } from "../migration-transaction.js";
|
|
13
|
+
import { installedPluginDir, lockPath, pluginCacheRoot, pluginSourceCacheDir } from "../paths.js";
|
|
14
|
+
import { planMigration, } from "../upgrade-plan.js";
|
|
15
|
+
import { installedHistory, marketplaceRenames, recoverLegacyHistory, requestedSelectionKnown, sourceCatalogNames } from "../source-history.js";
|
|
16
|
+
import { pluginComparisonHash } from "../plugin-changes.js";
|
|
17
|
+
import { sourceIntent } from "../source-intent.js";
|
|
18
|
+
import { COMPONENT_TYPES, resolveSelectionDependencies, } from "../types.js";
|
|
19
|
+
import { reviewExecutables, verifiedSource, UpdateCancelled } from "./review-executables.js";
|
|
20
|
+
export { UpdateCancelled } from "./review-executables.js";
|
|
21
|
+
import { discoverPlugins } from "./install/discovery.js";
|
|
22
|
+
import { synthesizeDefaultDslPlugin } from "./install/default-dsl.js";
|
|
23
|
+
import { parseGitHubSource } from "../sources.js";
|
|
24
|
+
import { installPlugin, verifyInstallation } from "./install/install-one.js";
|
|
25
|
+
function emptyContents() {
|
|
26
|
+
return { skills: [], agents: [], commands: [], mcp: [], hooks: [], apps: [] };
|
|
27
|
+
}
|
|
28
|
+
/** Resolve a newly available runtime's saved state conflict within the same update. */
|
|
29
|
+
export async function publishUpgradeTransaction(journalPath, targets, source, review, ref, repairTargets) {
|
|
30
|
+
const first = await publishMigrationTransaction(journalPath, { targets, repairTargets });
|
|
31
|
+
if (!first.stateDecisions?.length || !review)
|
|
32
|
+
return first;
|
|
33
|
+
const answer = await review({ source, executable: [], history: first.stateDecisions.map(item => ({
|
|
34
|
+
id: `state:${item.agent}/${item.plugin}`, skills: [], choices: ["enabled", "disabled"],
|
|
35
|
+
})) });
|
|
36
|
+
if (!answer) {
|
|
37
|
+
const cancelled = new UpdateCancelled();
|
|
38
|
+
cancelled.partial = {
|
|
39
|
+
remote: [{ source, ...(ref ? { ref } : {}), updated: [], unchanged: [], deleted: [], available: [],
|
|
40
|
+
pendingRuntime: first.failures.map(item => item.message) }],
|
|
41
|
+
local: { results: [], missing: [] }, agents: first.agents ?? [],
|
|
42
|
+
};
|
|
43
|
+
throw cancelled;
|
|
44
|
+
}
|
|
45
|
+
const stateDecisions = first.stateDecisions.map(item => {
|
|
46
|
+
const action = answer.history[`state:${item.agent}/${item.plugin}`]?.action;
|
|
47
|
+
if (action !== "enabled" && action !== "disabled")
|
|
48
|
+
throw new Error(`Choose the runtime state for ${item.plugin}.`);
|
|
49
|
+
return { ...item, enabled: action === "enabled" };
|
|
50
|
+
});
|
|
51
|
+
const last = await publishMigrationTransaction(journalPath, { targets, stateDecisions, repairTargets });
|
|
52
|
+
const resolved = new Set(stateDecisions.map(item => `${item.agent}/${item.plugin}`));
|
|
53
|
+
const prior = (first.agents ?? []).map(result => ({ ...result,
|
|
54
|
+
failures: result.failures?.filter(item => !item.plugin || !resolved.has(`${result.agent}/${item.plugin}`)),
|
|
55
|
+
unverified: result.unverified?.filter(name => !resolved.has(`${result.agent}/${name}`)),
|
|
56
|
+
}));
|
|
57
|
+
return { ...last, agents: [...prior, ...(last.agents ?? [])] };
|
|
58
|
+
}
|
|
59
|
+
async function reviewRuntimeStates(destinations, targets, pluginsDir, scope, source, lock, review) {
|
|
60
|
+
const successors = destinations.map(item => ({ name: item.name, predecessors: item.predecessors }));
|
|
61
|
+
const questions = [];
|
|
62
|
+
for (const target of targets.filter(agent => agent.detect())) {
|
|
63
|
+
const names = [...new Set(destinations.flatMap(item => [item.name, ...item.predecessors]))];
|
|
64
|
+
if (!names.length)
|
|
65
|
+
continue;
|
|
66
|
+
const records = target.available() ? target.inspectPlugins?.({ pluginsDir, scope, plugins: names }) : undefined;
|
|
67
|
+
for (const [index, dest] of destinations.entries()) {
|
|
68
|
+
if (dest.stateResolved) {
|
|
69
|
+
(successors[index].enabledByTarget ??= {})[target.id] = dest.state === "enabled";
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (!Array.isArray(records) || records.some(item => item.name === dest.name && item.installed))
|
|
73
|
+
continue;
|
|
74
|
+
if (typeof lock.plugins[dest.name]?.runtimeStates?.[target.id] === "boolean")
|
|
75
|
+
continue;
|
|
76
|
+
const states = new Set(dest.predecessors.flatMap(name => {
|
|
77
|
+
const native = records.find(item => item.installed && item.name === name);
|
|
78
|
+
if (native)
|
|
79
|
+
return [native.enabled];
|
|
80
|
+
const saved = lock.plugins[name]?.runtimeStates?.[target.id];
|
|
81
|
+
if (typeof saved === "boolean")
|
|
82
|
+
return [saved];
|
|
83
|
+
return lock.plugins[name]?.state === "disabled" ? [false] : [];
|
|
84
|
+
}));
|
|
85
|
+
if (states.size > 1)
|
|
86
|
+
questions.push({ id: `state:${target.id}/${dest.name}`, skills: [], choices: ["enabled", "disabled"] });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!questions.length)
|
|
90
|
+
return { successors, blockers: [] };
|
|
91
|
+
if (!review)
|
|
92
|
+
return { successors, blockers: questions.map(item => `Review ${item.id}: enabled state`) };
|
|
93
|
+
const answer = await review({ source, history: questions, executable: [] });
|
|
94
|
+
if (!answer)
|
|
95
|
+
throw new UpdateCancelled();
|
|
96
|
+
for (const question of questions) {
|
|
97
|
+
const action = answer.history[question.id]?.action;
|
|
98
|
+
if (action !== "enabled" && action !== "disabled")
|
|
99
|
+
return { successors, blockers: [`Choose ${question.id}.`] };
|
|
100
|
+
const [target, name] = question.id.slice(6).split("/");
|
|
101
|
+
(successors.find(item => item.name === name).enabledByTarget ??= {})[target] = action === "enabled";
|
|
102
|
+
}
|
|
103
|
+
return { successors, blockers: [] };
|
|
104
|
+
}
|
|
105
|
+
/** Prepare the complete checked source before publishing payloads or native changes. */
|
|
106
|
+
export async function upgradeSource(opts) {
|
|
107
|
+
const { group, checkout, pluginsDir } = opts;
|
|
108
|
+
const lock = readLock(lockPath(pluginsDir));
|
|
109
|
+
const { candidates } = discoverPlugins(checkout);
|
|
110
|
+
const declaredNames = sourceCatalogNames(checkout);
|
|
111
|
+
if (declaredNames)
|
|
112
|
+
for (const name of candidates.keys())
|
|
113
|
+
if (!declaredNames.has(name))
|
|
114
|
+
candidates.delete(name);
|
|
115
|
+
const profiles = group.installed.filter((name) => lock.plugins[name]?.definition);
|
|
116
|
+
const generated = new Map();
|
|
117
|
+
const cleanups = [];
|
|
118
|
+
try {
|
|
119
|
+
if (profiles.length && !candidates.size && !declaredNames) {
|
|
120
|
+
for (const name of profiles) {
|
|
121
|
+
const entry = lock.plugins[name];
|
|
122
|
+
const definition = entry.definition;
|
|
123
|
+
const result = await synthesizeDefaultDslPlugin({
|
|
124
|
+
spec: group.source,
|
|
125
|
+
pluginsDir,
|
|
126
|
+
as: definition.as,
|
|
127
|
+
structuralIdentity: name,
|
|
128
|
+
defaultDescription: definition.description,
|
|
129
|
+
preparedSourceDir: checkout,
|
|
130
|
+
authorizedComponents: definition.authorizedComponents,
|
|
131
|
+
}, parseGitHubSource(group.source), checkout, opts.revision);
|
|
132
|
+
cleanups.push(result.cleanup);
|
|
133
|
+
candidates.set(name, result.candidates.get(name));
|
|
134
|
+
generated.set(name, result.definition);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (profiles.some((name) => !candidates.has(name))) {
|
|
138
|
+
const missing = profiles.filter(name => !candidates.has(name));
|
|
139
|
+
throw new Error(`Source definition changed, but none match the installed identity "${missing.join('", "')}"; all structural identities were preserved.`);
|
|
140
|
+
}
|
|
141
|
+
return await upgradeCandidates(opts, candidates, generated);
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
for (const cleanup of cleanups)
|
|
145
|
+
cleanup();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function resolveHistoricalSelections(inputs, intent, review, reconsider = false) {
|
|
149
|
+
let plan = planMigration(inputs);
|
|
150
|
+
const decisions = {};
|
|
151
|
+
const notRestored = [];
|
|
152
|
+
const restored = [];
|
|
153
|
+
while (plan.decisions.length && !plan.blockers.length) {
|
|
154
|
+
const pending = plan.decisions;
|
|
155
|
+
const uncertain = pending.filter(item => {
|
|
156
|
+
const prior = intent.deferredRecovery?.find(entry => entry.id === item.id);
|
|
157
|
+
const unchanged = prior && isDeepStrictEqual(prior.skills, item.skills);
|
|
158
|
+
if ((item.uncertain || item.choices.includes("restore")) && (!review || (unchanged && !reconsider))) {
|
|
159
|
+
decisions[item.id] = { action: "keep" };
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return true;
|
|
163
|
+
});
|
|
164
|
+
const answer = uncertain.length && review
|
|
165
|
+
? await review({ source: intent.source, history: uncertain, executable: [] })
|
|
166
|
+
: { history: {}, allow: [] };
|
|
167
|
+
if (!answer)
|
|
168
|
+
throw new UpdateCancelled();
|
|
169
|
+
if (uncertain.length && !review)
|
|
170
|
+
return {
|
|
171
|
+
plan,
|
|
172
|
+
notRestored, restored,
|
|
173
|
+
blockers: uncertain.map((item) => `Review ${item.id}: ${item.skills.join(", ") || "enabled state"}`),
|
|
174
|
+
};
|
|
175
|
+
for (const item of uncertain) {
|
|
176
|
+
const choice = answer.history[item.id];
|
|
177
|
+
if (!choice || !item.choices.includes(choice.action))
|
|
178
|
+
return { plan, notRestored, restored, blockers: [`Choose how to apply ${item.id}.`] };
|
|
179
|
+
decisions[item.id] = choice;
|
|
180
|
+
if (item.uncertain || item.choices.includes("restore")) {
|
|
181
|
+
if (choice.action === "restore")
|
|
182
|
+
restored.push(...item.skills);
|
|
183
|
+
if (choice.action === "select")
|
|
184
|
+
restored.push(...(choice.skills ?? []));
|
|
185
|
+
}
|
|
186
|
+
if (choice.action === "select")
|
|
187
|
+
notRestored.push(...item.skills.filter((skill) => !choice.skills?.includes(skill)));
|
|
188
|
+
}
|
|
189
|
+
plan = planMigration({ ...inputs, decisions });
|
|
190
|
+
}
|
|
191
|
+
return { plan, notRestored, restored, blockers: plan.blockers };
|
|
192
|
+
}
|
|
193
|
+
async function upgradeCandidates(opts, candidates, generated) {
|
|
194
|
+
const { group, checkout, pluginsDir } = opts;
|
|
195
|
+
const lock = readLock(lockPath(pluginsDir));
|
|
196
|
+
const previous = sourceIntent(lock, group.source, group.ref);
|
|
197
|
+
const intent = structuredClone(previous ?? {
|
|
198
|
+
source: group.source,
|
|
199
|
+
ref: group.ref,
|
|
200
|
+
mode: "selected",
|
|
201
|
+
roots: group.installed,
|
|
202
|
+
excluded: [],
|
|
203
|
+
appliedMigrations: [],
|
|
204
|
+
});
|
|
205
|
+
const base = {
|
|
206
|
+
source: group.source,
|
|
207
|
+
...(group.ref ? { ref: group.ref } : {}),
|
|
208
|
+
updated: [],
|
|
209
|
+
unchanged: [],
|
|
210
|
+
deleted: [],
|
|
211
|
+
available: [],
|
|
212
|
+
};
|
|
213
|
+
const needsDecision = (messages) => ({ ...base, actionRequired: messages });
|
|
214
|
+
const inventory = [...candidates].map(([name, p]) => ({
|
|
215
|
+
name, version: p.manifest.version, contents: pluginContents(p.dir, p.manifest),
|
|
216
|
+
}));
|
|
217
|
+
const source = { type: "github", repo: group.source, ref: group.ref };
|
|
218
|
+
const currentHistory = installedHistory(pluginsDir, lock, group.source, group.ref);
|
|
219
|
+
const existingSelectionFor = (name) => {
|
|
220
|
+
const saved = intent.desiredSelections;
|
|
221
|
+
if (saved && Object.hasOwn(saved, name))
|
|
222
|
+
return saved[name] ?? undefined;
|
|
223
|
+
const old = lock.plugins[name];
|
|
224
|
+
if (!old)
|
|
225
|
+
return undefined;
|
|
226
|
+
const proof = currentHistory.find(item => item.name === name);
|
|
227
|
+
return old.selection ?? (proof?.selectionKnown === false ? proof.effectiveSelection : undefined) ??
|
|
228
|
+
(old.definition?.authorizedComponents && COMPONENT_TYPES.some(type => !old.definition.authorizedComponents.includes(type) && inventory.find(item => item.name === name).contents[type].length)
|
|
229
|
+
? { components: old.definition.authorizedComponents } : undefined);
|
|
230
|
+
};
|
|
231
|
+
const plannerInventory = inventory.map(item => ({ ...item,
|
|
232
|
+
...(lock.plugins[item.name] ? {
|
|
233
|
+
requestedSelection: existingSelectionFor(item.name) ?? null,
|
|
234
|
+
effectiveSelection: resolveSelectionDependencies(candidates.get(item.name).manifest, existingSelectionFor(item.name)) ?? null,
|
|
235
|
+
} : {}),
|
|
236
|
+
}));
|
|
237
|
+
const unverifiable = group.installed.filter(name => !currentHistory.some(item => item.name === name) && !requestedSelectionKnown(lock.plugins[name]));
|
|
238
|
+
if (unverifiable.length)
|
|
239
|
+
return needsDecision(unverifiable.map(name => `Cannot verify the historical selection of ${name}; preserve its contents until a selection is provided.`));
|
|
240
|
+
const historicalInventory = intent.history?.length ? intent.history : await recoverLegacyHistory({
|
|
241
|
+
source: group.source, ref: group.ref, lock, installed: currentHistory,
|
|
242
|
+
currentNames: new Set(candidates.keys()), runner: opts.gitRunner,
|
|
243
|
+
});
|
|
244
|
+
const history = historicalInventory.map(item => {
|
|
245
|
+
const proof = currentHistory.find(current => current.name === item.name && current.version === item.version && current.sourceHash === item.sourceHash);
|
|
246
|
+
const known = requestedSelectionKnown(item);
|
|
247
|
+
const evidence = item.evidence ?? (known ? "selection" : proof?.evidence ?? "catalog");
|
|
248
|
+
return { ...item, selectionKnown: known, evidence,
|
|
249
|
+
...(!known && !item.evidence && proof ? { effectiveSelection: proof.effectiveSelection } : {}),
|
|
250
|
+
uncertain: "uncertain" in item ? Boolean(item.uncertain) : evidence === "catalog" && !known };
|
|
251
|
+
});
|
|
252
|
+
const installed = Object.entries(lock.plugins).map(([name, entry]) => {
|
|
253
|
+
const proof = currentHistory.find(p => p.name === name);
|
|
254
|
+
return { ...entry, name, contents: proof?.contents ?? emptyContents(), effectiveSelection: proof?.effectiveSelection,
|
|
255
|
+
selectionKnown: proof?.selectionKnown ?? false, evidence: proof?.evidence,
|
|
256
|
+
uncertain: proof?.evidence === "catalog" && proof.selectionKnown !== true };
|
|
257
|
+
});
|
|
258
|
+
const { plan, notRestored, restored, blockers } = await resolveHistoricalSelections({ source, installed, history, candidates: plannerInventory, renames: marketplaceRenames(checkout), deferredRecovery: intent.deferredRecovery }, intent, opts.review, opts.repair);
|
|
259
|
+
if (blockers.length)
|
|
260
|
+
return needsDecision(blockers);
|
|
261
|
+
plan.applied = plan.applied.filter(id => !intent.appliedMigrations.includes(id));
|
|
262
|
+
if (plan.deferredRecovery.length)
|
|
263
|
+
intent.deferredRecovery = plan.deferredRecovery;
|
|
264
|
+
else
|
|
265
|
+
delete intent.deferredRecovery;
|
|
266
|
+
const deferredRecovery = [...new Set(plan.deferredRecovery.flatMap(item => item.skills))].sort();
|
|
267
|
+
const previouslyRetained = intent.retained ?? [];
|
|
268
|
+
const missing = group.installed.filter((name) => !candidates.has(name) && !plan.retired.includes(name) && !plan.retained.includes(name));
|
|
269
|
+
const retained = new Set([...previouslyRetained.filter((name) => missing.includes(name)), ...plan.retained]);
|
|
270
|
+
const unknown = missing.filter((name) => !retained.has(name));
|
|
271
|
+
if (!opts.review && unknown.length && group.installed.every((name) => !candidates.has(name))) {
|
|
272
|
+
for (const name of candidates.keys()) {
|
|
273
|
+
if ((intent.mode === "all" || opts.all) && lock.plugins[name] && !group.installed.includes(name)) {
|
|
274
|
+
throw new Error(`name collision: "${name}" belongs to another source`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
...base,
|
|
279
|
+
missingUpstream: unknown,
|
|
280
|
+
available: [...candidates.keys()].sort(),
|
|
281
|
+
actionRequired: unknown.map((name) => `Keep or remove ${name} (unmapped:${name}).`),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
if (opts.review && unknown.length) {
|
|
285
|
+
const questions = unknown.map((name) => ({
|
|
286
|
+
id: "unmapped:" + name,
|
|
287
|
+
skills: [name],
|
|
288
|
+
choices: ["keep", "drop"],
|
|
289
|
+
}));
|
|
290
|
+
const answer = await opts.review({ source: group.source, history: questions, executable: [] });
|
|
291
|
+
if (!answer)
|
|
292
|
+
throw new UpdateCancelled();
|
|
293
|
+
for (const name of unknown) {
|
|
294
|
+
const choice = answer.history["unmapped:" + name]?.action;
|
|
295
|
+
if (choice === "keep")
|
|
296
|
+
retained.add(name);
|
|
297
|
+
else if (choice === "drop")
|
|
298
|
+
plan.retired.push(name);
|
|
299
|
+
else
|
|
300
|
+
return needsDecision(["Choose whether to keep " + name + "."]);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const pendingMissing = missing.filter((name) => !retained.has(name) && !plan.retired.includes(name));
|
|
304
|
+
if (retained.size) {
|
|
305
|
+
intent.retained = [...retained].sort();
|
|
306
|
+
intent.retainedAtRevision = opts.revision;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
delete intent.retained;
|
|
310
|
+
delete intent.retainedAtRevision;
|
|
311
|
+
}
|
|
312
|
+
const destinations = new Map();
|
|
313
|
+
const included = new Set(group.installed.filter((name) => candidates.has(name) && !plan.retired.includes(name) && !retained.has(name)));
|
|
314
|
+
const follow = !pendingMissing.length && (intent.mode === "all" || opts.all);
|
|
315
|
+
const excluded = new Set(intent.excluded);
|
|
316
|
+
if (follow)
|
|
317
|
+
for (const name of candidates.keys()) {
|
|
318
|
+
const entry = lock.plugins[name];
|
|
319
|
+
if (!excluded.has(name) && !retained.has(name) && !plan.retired.includes(name) && (!entry || group.installed.includes(name)))
|
|
320
|
+
included.add(name);
|
|
321
|
+
}
|
|
322
|
+
for (const dest of plan.destinations) {
|
|
323
|
+
if (excluded.has(dest.name))
|
|
324
|
+
return needsDecision([`Previously removed replacement: ${dest.name}`]);
|
|
325
|
+
included.add(dest.name);
|
|
326
|
+
destinations.set(dest.name, dest);
|
|
327
|
+
}
|
|
328
|
+
// Unknown recovery targets cannot acquire unrelated contents through --all.
|
|
329
|
+
for (const address of deferredRecovery) {
|
|
330
|
+
const name = address.split(":")[0];
|
|
331
|
+
if (!lock.plugins[name] && !destinations.has(name))
|
|
332
|
+
included.delete(name);
|
|
333
|
+
}
|
|
334
|
+
for (const name of [...included]) {
|
|
335
|
+
for (const dependency of intent.withDeps === false ? [] : resolveInstallOrder(name, candidates)) {
|
|
336
|
+
if (excluded.has(dependency))
|
|
337
|
+
return needsDecision([`${name} requires excluded plugin ${dependency}.`]);
|
|
338
|
+
included.add(dependency);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
for (const [name, entry] of Object.entries(lock.plugins)) {
|
|
342
|
+
if (plan.retired.includes(name))
|
|
343
|
+
continue;
|
|
344
|
+
const dependencies = included.has(name)
|
|
345
|
+
? candidates.get(name)?.manifest.dependencies?.map((d) => d.name)
|
|
346
|
+
: Object.keys(entry.dependencies ?? {});
|
|
347
|
+
if (dependencies?.some((dep) => plan.retired.includes(dep)))
|
|
348
|
+
return needsDecision([`${name} still requires a retired plugin.`]);
|
|
349
|
+
}
|
|
350
|
+
const targets = opts.targets ?? intent.targets?.filter((id) => ADAPTER_TARGETS.includes(id));
|
|
351
|
+
const projectionTargets = [...new Set([
|
|
352
|
+
...(targets ?? ADAPTER_TARGETS), ...(opts.repair ? ["codex"] : []),
|
|
353
|
+
])];
|
|
354
|
+
const selectionFor = (name) => {
|
|
355
|
+
const old = lock.plugins[name];
|
|
356
|
+
const mapped = destinations.get(name);
|
|
357
|
+
const saved = intent.desiredSelections;
|
|
358
|
+
if (mapped)
|
|
359
|
+
return mapped.selection;
|
|
360
|
+
if (old || (saved && Object.hasOwn(saved, name)))
|
|
361
|
+
return existingSelectionFor(name);
|
|
362
|
+
if (!follow)
|
|
363
|
+
return undefined;
|
|
364
|
+
const selection = intent.selection;
|
|
365
|
+
if (!selection)
|
|
366
|
+
return undefined;
|
|
367
|
+
const contents = inventory.find((item) => item.name === name).contents;
|
|
368
|
+
return {
|
|
369
|
+
...selection,
|
|
370
|
+
...(selection.skills ? { skills: selection.skills.filter((skill) => contents.skills.includes(skill)) } : {}),
|
|
371
|
+
...(selection.mcp ? { mcp: selection.mcp.filter((server) => contents.mcp.includes(server)) } : {}),
|
|
372
|
+
};
|
|
373
|
+
};
|
|
374
|
+
const proposed = [...included].map((name) => {
|
|
375
|
+
if (lock.plugins[name] && !group.installed.includes(name))
|
|
376
|
+
throw new Error(`dependency plugin "${name}" belongs to a different source ref`);
|
|
377
|
+
let selection = selectionFor(name);
|
|
378
|
+
const blocked = new Set(deferredRecovery.filter(address => address.startsWith(`${name}:`)).map(address => address.slice(name.length + 1)));
|
|
379
|
+
if (blocked.size) {
|
|
380
|
+
const members = inventory.find(item => item.name === name).contents;
|
|
381
|
+
selection = { components: [...(selection?.components ?? COMPONENT_TYPES)], ...selection,
|
|
382
|
+
skills: (selection?.skills ?? members.skills).filter(skill => !blocked.has(skill)) };
|
|
383
|
+
}
|
|
384
|
+
return { name, candidate: candidates.get(name), old: lock.plugins[name], selection };
|
|
385
|
+
});
|
|
386
|
+
const permissions = await reviewExecutables(pluginsDir, intent, proposed, projectionTargets, opts.review);
|
|
387
|
+
if (permissions.blockers.length)
|
|
388
|
+
return needsDecision(permissions.blockers);
|
|
389
|
+
const materializedSelections = new Map(proposed.map((item) => [item.name, permissions.selections.get(item.name) ?? item.selection]));
|
|
390
|
+
for (const { name, selection } of proposed) {
|
|
391
|
+
if (permissions.selections.has(name)) {
|
|
392
|
+
intent.desiredSelections ??= {};
|
|
393
|
+
intent.desiredSelections[name] = selection ?? null;
|
|
394
|
+
}
|
|
395
|
+
else if (intent.desiredSelections) {
|
|
396
|
+
delete intent.desiredSelections[name];
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
let policyChanged = previous ? !isDeepStrictEqual(intent, previous) : Boolean(retained.size || permissions.reviewed);
|
|
400
|
+
const stage = mkdtempSync(join(tmpdir(), "adg-upgrade-"));
|
|
401
|
+
try {
|
|
402
|
+
const prepared = [];
|
|
403
|
+
const unchanged = [];
|
|
404
|
+
const changes = [];
|
|
405
|
+
const order = [
|
|
406
|
+
...new Set([...included].flatMap((name) => (intent.withDeps === false ? [name] : resolveInstallOrder(name, candidates)))),
|
|
407
|
+
];
|
|
408
|
+
for (const name of order) {
|
|
409
|
+
opts.onProgress?.({ kind: "install", index: order.indexOf(name) + 1, total: order.length, source: group.source, plugin: name });
|
|
410
|
+
const p = candidates.get(name);
|
|
411
|
+
const selection = materializedSelections.get(name);
|
|
412
|
+
const origin = { ...source, path: generated.has(name) ? "." : toPosix(relative(checkout, p.dir)) || "." };
|
|
413
|
+
const built = installPlugin({
|
|
414
|
+
source: p.dir,
|
|
415
|
+
pluginsDir: stage,
|
|
416
|
+
origin,
|
|
417
|
+
selection,
|
|
418
|
+
selectionKnown: false,
|
|
419
|
+
targets: projectionTargets,
|
|
420
|
+
definition: generated.get(name),
|
|
421
|
+
now: opts.now,
|
|
422
|
+
resolvedRevision: opts.revision,
|
|
423
|
+
});
|
|
424
|
+
const entry = readLock(lockPath(stage)).plugins[name];
|
|
425
|
+
const old = lock.plugins[name];
|
|
426
|
+
const mapped = plan.destinations.find(item => item.name === name);
|
|
427
|
+
const known = (plugin) => currentHistory.find(item => item.name === plugin)?.selectionKnown === true;
|
|
428
|
+
entry.selectionKnown = old ? known(name) : mapped ? mapped.predecessors.every(known) : true;
|
|
429
|
+
if (restored.some(address => address.startsWith(`${name}:`)))
|
|
430
|
+
entry.selectionKnown = true;
|
|
431
|
+
if (deferredRecovery.some(address => address.startsWith(`${name}:`)))
|
|
432
|
+
entry.selectionKnown = false;
|
|
433
|
+
const verification = old ? verifyInstallation(installedPluginDir(pluginsDir, name, old.origin), old.installedHash, old.selection, projectionTargets) : undefined;
|
|
434
|
+
entry.installedAt = old?.installedAt ?? entry.installedAt;
|
|
435
|
+
entry.state = destinations.get(name)?.state ?? old?.state;
|
|
436
|
+
if (old?.runtimeStates)
|
|
437
|
+
entry.runtimeStates = old.runtimeStates;
|
|
438
|
+
if (old &&
|
|
439
|
+
old.sourceHash === entry.sourceHash &&
|
|
440
|
+
old.installedHash === entry.installedHash &&
|
|
441
|
+
isDeepStrictEqual(old.selection, entry.selection) &&
|
|
442
|
+
(old.state ?? "enabled") === (entry.state ?? "enabled") &&
|
|
443
|
+
verification?.installationIntact && verification.projectionsIntact &&
|
|
444
|
+
verifiedSource(pluginsDir, name, old)) {
|
|
445
|
+
unchanged.push(name);
|
|
446
|
+
continue;
|
|
447
|
+
}
|
|
448
|
+
const cached = old && verifiedSource(pluginsDir, name, old);
|
|
449
|
+
const delta = {
|
|
450
|
+
version: !old || old.version !== entry.version,
|
|
451
|
+
content: !cached || pluginComparisonHash(cached, readManifest(cached)) !== pluginComparisonHash(p.dir, p.manifest),
|
|
452
|
+
selection: !isDeepStrictEqual(old?.selection, entry.selection),
|
|
453
|
+
source: Boolean(old && opts.revision && old.resolvedRevision !== opts.revision),
|
|
454
|
+
};
|
|
455
|
+
const runtimeRefreshRequired = !old || delta.version || delta.selection || old.installedHash !== entry.installedHash || !verification?.projectionsIntact;
|
|
456
|
+
changes.push({ name, ...delta, runtimeRefreshRequired });
|
|
457
|
+
prepared.push({ name, entry, dir: built.installedTo, cacheDir: pluginSourceCacheDir(stage, name), runtimeRefreshRequired });
|
|
458
|
+
}
|
|
459
|
+
intent.roots = [
|
|
460
|
+
...new Set([
|
|
461
|
+
...intent.roots.filter((name) => !plan.retired.includes(name)),
|
|
462
|
+
...plan.destinations.map((p) => p.name),
|
|
463
|
+
...[...included].filter((name) => !lock.plugins[name] && follow),
|
|
464
|
+
]),
|
|
465
|
+
].sort();
|
|
466
|
+
intent.appliedMigrations = [...new Set([...intent.appliedMigrations, ...plan.applied])];
|
|
467
|
+
intent.history = [...currentHistory.filter(p => retained.has(p.name)), ...order.map(name => {
|
|
468
|
+
const candidate = candidates.get(name);
|
|
469
|
+
const entry = prepared.find(p => p.name === name)?.entry ?? lock.plugins[name];
|
|
470
|
+
return { name, origin: entry.origin, version: entry.version, sourceHash: entry.sourceHash,
|
|
471
|
+
contents: pluginContents(candidate.dir, candidate.manifest), selection: entry.selection,
|
|
472
|
+
selectionKnown: entry.selectionKnown, evidence: entry.selectionKnown === false ? "installed" : "selection",
|
|
473
|
+
effectiveSelection: resolveSelectionDependencies(candidate.manifest, entry.selection), state: entry.state };
|
|
474
|
+
})];
|
|
475
|
+
policyChanged = previous ? !isDeepStrictEqual(JSON.parse(JSON.stringify(intent)), previous) : true;
|
|
476
|
+
const checkpointNeeded = opts.revision && unchanged.some(name => lock.plugins[name].resolvedRevision !== opts.revision);
|
|
477
|
+
const knownRuntime = (id) => group.installed.some(name => Object.hasOwn(lock.plugins[name]?.runtimeStates ?? {}, id));
|
|
478
|
+
const selectedRuntime = opts.activate ? (opts.agents ?? [...new Map([
|
|
479
|
+
...resolveAgents(targets).filter(agent => targets !== undefined || agent.detect() || agent.available() || knownRuntime(agent.id)),
|
|
480
|
+
...(opts.repair ? resolveAgents(["codex"]) : []),
|
|
481
|
+
].map(agent => [agent.id, agent])).values()]) : [];
|
|
482
|
+
// Changed native payloads belong to the same durable transaction, including
|
|
483
|
+
// Codex repair; standalone repair still handles unchanged missing members.
|
|
484
|
+
const runtime = selectedRuntime;
|
|
485
|
+
const retireTargets = plan.retired.length ? (opts.agents ?? resolveAgents().filter(agent => agent.detect() || knownRuntime(agent.id))) : [];
|
|
486
|
+
const allRuntime = [...new Map([...runtime, ...retireTargets].map(agent => [agent.id, agent])).values()];
|
|
487
|
+
const refreshExisting = opts.refreshExisting?.filter(item => unchanged.includes(item.name));
|
|
488
|
+
const successors = plan.destinations.map(item => ({ ...item, predecessors: item.predecessors.filter(name => group.installed.includes(name)) }));
|
|
489
|
+
const stateReview = await reviewRuntimeStates(successors, allRuntime, pluginsDir, opts.scope, group.source, lock, opts.review);
|
|
490
|
+
if (stateReview.blockers.length)
|
|
491
|
+
return needsDecision(stateReview.blockers);
|
|
492
|
+
if (!prepared.length && !plan.retired.length && !plan.applied.length && !policyChanged && !refreshExisting?.length && !checkpointNeeded) {
|
|
493
|
+
return {
|
|
494
|
+
...base,
|
|
495
|
+
unchanged,
|
|
496
|
+
retained: [...retained],
|
|
497
|
+
...(deferredRecovery.length ? { deferredRecovery } : {}),
|
|
498
|
+
available: [...candidates.keys()].filter((name) => !included.has(name) && !lock.plugins[name]),
|
|
499
|
+
...(pendingMissing.length ? { missingUpstream: pendingMissing } : {}),
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
const journal = await prepareMigrationTransaction({
|
|
503
|
+
pluginsDir,
|
|
504
|
+
source: group.source,
|
|
505
|
+
ref: group.ref,
|
|
506
|
+
revision: opts.revision ?? (prepared.map((p) => p.entry.sourceHash).join(",") || "verified-local-snapshot"),
|
|
507
|
+
prepared,
|
|
508
|
+
retire: plan.retired,
|
|
509
|
+
refreshExisting,
|
|
510
|
+
scope: opts.scope,
|
|
511
|
+
targets: runtime,
|
|
512
|
+
retireTargets,
|
|
513
|
+
inspectionRequiredTargets: opts.repair ? ["codex"] : undefined,
|
|
514
|
+
successors: stateReview.successors,
|
|
515
|
+
projectionTargets,
|
|
516
|
+
sourceIntent: intent,
|
|
517
|
+
});
|
|
518
|
+
for (const agent of allRuntime) {
|
|
519
|
+
const count = prepared.filter(p => p.runtimeRefreshRequired && p.entry.state !== "disabled").length;
|
|
520
|
+
if (count)
|
|
521
|
+
opts.onProgress?.({ kind: "activate", agent: agent.id, count });
|
|
522
|
+
}
|
|
523
|
+
const published = await publishUpgradeTransaction(journal, opts.activate ? allRuntime : [], group.source, opts.review, group.ref, opts.repair ? ["codex"] : undefined);
|
|
524
|
+
opts.onNativeManaged?.(published.managedNative ?? []);
|
|
525
|
+
opts.onAgentResults?.(published.agents ?? []);
|
|
526
|
+
if (published.complete && opts.revision && unchanged.length) {
|
|
527
|
+
const after = readLock(lockPath(pluginsDir));
|
|
528
|
+
for (const name of unchanged)
|
|
529
|
+
after.plugins[name].resolvedRevision = opts.revision;
|
|
530
|
+
writeLock(lockPath(pluginsDir), after);
|
|
531
|
+
}
|
|
532
|
+
return {
|
|
533
|
+
...base,
|
|
534
|
+
updated: prepared.map((p) => p.name),
|
|
535
|
+
unchanged,
|
|
536
|
+
retained: [...retained],
|
|
537
|
+
migrated: published.complete ? plan.applied : [],
|
|
538
|
+
deleted: published.complete ? plan.retired : [],
|
|
539
|
+
notRestored,
|
|
540
|
+
...(deferredRecovery.length ? { deferredRecovery } : {}),
|
|
541
|
+
restored: published.complete ? restored : [],
|
|
542
|
+
changes,
|
|
543
|
+
...(pendingMissing.length ? { missingUpstream: pendingMissing } : {}),
|
|
544
|
+
available: [...candidates.keys()].filter((name) => !included.has(name) && !lock.plugins[name]).sort(),
|
|
545
|
+
...(!published.complete ? { pendingRuntime: published.failures.map((f) => f.message) } : {}),
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
finally {
|
|
549
|
+
rmSync(pluginCacheRoot(stage), { recursive: true, force: true });
|
|
550
|
+
rmSync(stage, { recursive: true, force: true });
|
|
551
|
+
}
|
|
552
|
+
}
|
|
@@ -8,6 +8,7 @@ import { readLock, writeLock } from "../lock.js";
|
|
|
8
8
|
import { pluginState } from "../types.js";
|
|
9
9
|
import { ADAPTER_TARGETS } from "../adapters/index.js";
|
|
10
10
|
import { installPlugin } from "./install.js";
|
|
11
|
+
import { preservedSelection, requestedSelectionKnown } from "../source-history.js";
|
|
11
12
|
function selectedLock(opts) {
|
|
12
13
|
const lock = readLock(lockPath(opts.pluginsDir));
|
|
13
14
|
const names = [...new Set(opts.names)];
|
|
@@ -55,7 +56,8 @@ export function enablePlugins(opts) {
|
|
|
55
56
|
pluginsDir: opts.pluginsDir,
|
|
56
57
|
origin: entry.origin,
|
|
57
58
|
resolvedRevision: entry.resolvedRevision,
|
|
58
|
-
selection:
|
|
59
|
+
selection: preservedSelection(opts.pluginsDir, name, entry),
|
|
60
|
+
selectionKnown: requestedSelectionKnown(entry),
|
|
59
61
|
targets: [...ADAPTER_TARGETS],
|
|
60
62
|
forceMaterialize: true,
|
|
61
63
|
});
|
|
@@ -9,6 +9,7 @@ import { resolveDefaultDsl } from "../default-dsl.js";
|
|
|
9
9
|
import { ADG_MANIFEST_PATH } from "../manifest.js";
|
|
10
10
|
import { copyPluginDir, writeJson } from "../fsutil.js";
|
|
11
11
|
import { pluginState } from "../types.js";
|
|
12
|
+
import { preservedSelection, requestedSelectionKnown } from "../source-history.js";
|
|
12
13
|
/**
|
|
13
14
|
* Refresh local sources and repair effective installations from their complete
|
|
14
15
|
* source snapshots. Runtime installations are never treated as upstream input.
|
|
@@ -71,7 +72,8 @@ export function updateLock(pluginsDir, now = new Date().toISOString(), opts = {}
|
|
|
71
72
|
source: installSource,
|
|
72
73
|
pluginsDir,
|
|
73
74
|
origin: entry.origin,
|
|
74
|
-
selection: entry
|
|
75
|
+
selection: preservedSelection(pluginsDir, name, entry) ?? (entry.definition?.authorizedComponents ? { components: entry.definition.authorizedComponents } : undefined),
|
|
76
|
+
selectionKnown: requestedSelectionKnown(entry),
|
|
75
77
|
skipUnchanged: true,
|
|
76
78
|
now,
|
|
77
79
|
definition,
|