@rbbtsn0w/adg 0.11.1-beta.1 → 0.11.1-dev.pr200.c6ce45e

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.
Files changed (56) hide show
  1. package/README.md +131 -73
  2. package/dist/src/agents/antigravity.js +218 -45
  3. package/dist/src/agents/claude.js +98 -38
  4. package/dist/src/agents/codex.js +1 -0
  5. package/dist/src/cli/core-plugin-handlers.js +3 -3
  6. package/dist/src/cli/handlers.js +171 -39
  7. package/dist/src/cli/index.js +23 -14
  8. package/dist/src/cli/review-update.js +80 -0
  9. package/dist/src/commands/install/default-dsl.js +1 -1
  10. package/dist/src/commands/install/discovery.js +3 -1
  11. package/dist/src/commands/install/install-one.js +41 -31
  12. package/dist/src/commands/install.js +59 -24
  13. package/dist/src/commands/marketplace.js +171 -115
  14. package/dist/src/commands/migrate.js +2 -2
  15. package/dist/src/commands/projection.js +3 -1
  16. package/dist/src/commands/remove.js +10 -0
  17. package/dist/src/commands/review-executables.js +106 -0
  18. package/dist/src/commands/select-agents.js +2 -2
  19. package/dist/src/commands/select-components.js +2 -2
  20. package/dist/src/commands/select-plugins.js +15 -2
  21. package/dist/src/commands/select-scope.js +3 -4
  22. package/dist/src/commands/source-upgrade.js +552 -0
  23. package/dist/src/commands/state.js +3 -1
  24. package/dist/src/commands/update.js +3 -1
  25. package/dist/src/lock.js +13 -5
  26. package/dist/src/migration-transaction.js +1011 -0
  27. package/dist/src/native-retry.js +329 -0
  28. package/dist/src/process-identity.js +88 -0
  29. package/dist/src/render/plugins.js +149 -27
  30. package/dist/src/render/ui.js +4 -4
  31. package/dist/src/source-history.js +194 -0
  32. package/dist/src/source-intent.js +7 -0
  33. package/dist/src/store-mutex.js +179 -0
  34. package/dist/src/types.js +1 -1
  35. package/dist/src/update-executables.js +193 -0
  36. package/dist/src/upgrade-plan.js +378 -0
  37. package/docs/agents/antigravity.md +5 -0
  38. package/docs/agents-spec.md +10 -0
  39. package/docs/branching-and-release.md +369 -55
  40. package/docs/marketing/README.md +211 -0
  41. package/docs/marketing/assets.json +228 -0
  42. package/docs/marketing/capture.json +130 -0
  43. package/docs/marketing/live-readiness.json +353 -0
  44. package/docs/marketing/posts.en.md +94 -0
  45. package/docs/marketing/posts.zh-CN.md +67 -0
  46. package/docs/marketing/production.md +210 -0
  47. package/docs/marketing/source/timeline.json +29 -0
  48. package/docs/marketing/source/workflow-01.svg +16 -0
  49. package/docs/marketing/source/workflow-02.svg +14 -0
  50. package/docs/marketing/source/workflow-03.svg +19 -0
  51. package/docs/marketing/source/workflow-poster.svg +32 -0
  52. package/docs/marketing/transcript.md +48 -0
  53. package/docs/plugin-update-semantics.md +53 -10
  54. package/docs/plugin-upgrade-migrations.md +349 -0
  55. package/package.json +14 -10
  56. package/schemas/plugin-lock.schema.json +78 -1
@@ -1,17 +1,23 @@
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, allAgents } from "../agents/index.js";
3
- import { gitRemoteRevision } from "../sources.js";
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";
14
+ import { pluginState } from "../types.js";
9
15
  import { lockPath } from "../paths.js";
10
- import { readLock } from "../lock.js";
11
- import { addPlugins } from "./install.js";
16
+ import { readLock, writeLock } from "../lock.js";
12
17
  import { removePlugin } from "./remove.js";
13
18
  import { syncPlugins } from "./sync.js";
14
19
  import { updateLock } from "./update.js";
20
+ import { recordTelemetryEvent } from "../telemetry.js";
15
21
  /**
16
22
  * A stable key identifying the source a plugin came from. GitHub/git plugins
17
23
  * group by repo/url (the marketplace root, ignoring per-plugin sub-paths);
@@ -37,22 +43,29 @@ export function marketplaceList(opts) {
37
43
  const lock = readLock(lockPath(opts.pluginsDir));
38
44
  const groups = new Map();
39
45
  for (const [name, entry] of Object.entries(lock.plugins)) {
40
- const key = sourceKey(entry.origin);
46
+ const source = sourceKey(entry.origin);
41
47
  const ref = entry.origin.type === "github" || entry.origin.type === "git" ? entry.origin.ref : undefined;
42
- const g = groups.get(key) ?? { ref, installed: [] };
43
- g.installed.push(name);
44
- if (g.ref === undefined && ref !== undefined)
45
- g.ref = ref;
46
- groups.set(key, g);
48
+ const group = groups.get(source) ?? {
49
+ source, ...(ref ? { ref } : {}), installed: [], disabled: [], remote: isRemoteKey(source),
50
+ };
51
+ if (group.ref !== ref)
52
+ delete group.ref;
53
+ group.installed.push(name);
54
+ if (pluginState(entry) === "disabled")
55
+ group.disabled.push(name);
56
+ groups.set(source, group);
47
57
  }
48
- return [...groups.entries()]
49
- .map(([source, g]) => ({
50
- source,
51
- ...(g.ref ? { ref: g.ref } : {}),
52
- installed: g.installed.sort(),
53
- remote: isRemoteKey(source),
54
- }))
55
- .sort((a, b) => a.source.localeCompare(b.source));
58
+ for (const intent of lock.sources ?? []) {
59
+ const { source, ref } = intent;
60
+ if ((intent.mode === "all" || intent.deferredRecovery?.length) && !groups.has(source)) {
61
+ groups.set(source, { source, ...(ref ? { ref } : {}), installed: [], disabled: [], remote: isRemoteKey(source) });
62
+ }
63
+ }
64
+ for (const group of groups.values()) {
65
+ group.installed.sort();
66
+ group.disabled.sort();
67
+ }
68
+ return [...groups.values()].sort((a, b) => a.source.localeCompare(b.source));
56
69
  }
57
70
  /**
58
71
  * Find one source group by key, or throw with the available keys. The error is
@@ -108,20 +121,83 @@ export function mergeAgentResults(groups) {
108
121
  /**
109
122
  * The plugins-domain equivalent of `adg skills update`: re-fetch every remote
110
123
  * source (or one named `source`), report which installed plugins changed,
111
- * stayed the same, were deleted upstream, or are newly available, and refresh
124
+ * stayed the same, are missing upstream, or are newly available, and refresh
112
125
  * local-source plugins in place. Failures are recorded per-source rather than
113
126
  * aborting the whole pass, so one unreachable repo doesn't hide the rest.
114
127
  */
115
128
  export async function updatePlugins(opts) {
129
+ const executionProviders = opts.activate ? opts.agents ?? [...new Map([
130
+ ...resolveAgents(opts.targets), ...(opts.repair ? resolveAgents(["codex"]) : []),
131
+ ].map(agent => [agent.id, agent])).values()] : [];
132
+ // Replay pending operations before probing any remote revision.
133
+ const pending = discoverPendingMigrations(opts.pluginsDir).filter(item => !opts.source || item.source === opts.source);
134
+ const remote = [];
135
+ const resumedAgents = [];
136
+ const managedByMigration = new Set();
137
+ const rememberManagedNative = (targets) => {
138
+ for (const target of targets)
139
+ if (target.agent === "codex")
140
+ for (const name of target.plugins)
141
+ managedByMigration.add(name);
142
+ };
143
+ for (const item of pending) {
144
+ let resumed;
145
+ try {
146
+ resumed = await publishUpgradeTransaction(item.journalPath, executionProviders, item.source, opts.review, item.ref, opts.repair ? ["codex"] : undefined);
147
+ }
148
+ catch (error) {
149
+ if (error instanceof UpdateCancelled) {
150
+ error.partial = { remote: [...remote, ...(error.partial?.remote ?? [])], local: { results: [], missing: [] },
151
+ agents: [...resumedAgents, ...(error.partial?.agents ?? [])] };
152
+ }
153
+ throw error;
154
+ }
155
+ resumedAgents.push(...(resumed.agents ?? []));
156
+ rememberManagedNative(resumed.managedNative ?? []);
157
+ remote.push({
158
+ source: item.source, ref: item.ref, updated: [], unchanged: [], deleted: [], available: [],
159
+ ...(resumed.complete ? { resumed: true } : { pendingRuntime: resumed.failures.map(failure => failure.message) }),
160
+ });
161
+ }
162
+ const recovered = await replayNativeRetries({
163
+ pluginsDir: opts.pluginsDir, source: opts.source, agents: executionProviders,
164
+ onProgress: opts.onProgress,
165
+ });
166
+ for (const group of recovered.groups) {
167
+ const failures = recovered.pending.filter(item => item.source === group.source && item.ref === group.ref);
168
+ remote.push({ ...group, updated: [], unchanged: [], deleted: [], available: [],
169
+ ...(failures.length ? { pendingRuntime: failures.map(item => item.message) } : { resumed: true }) });
170
+ }
116
171
  const allGroups = marketplaceList({ pluginsDir: opts.pluginsDir });
117
172
  // A named source narrows to just that group (and must be remote); otherwise we
118
173
  // refresh every remote source and rescan the local bucket.
119
- const remoteGroups = opts.source
120
- ? [requireGroup(opts.pluginsDir, opts.source, opts.scope)]
174
+ const selectedGroups = opts.source
175
+ ? (remote.some(group => group.source === opts.source) ? allGroups.filter(group => group.source === opts.source)
176
+ : [requireGroup(opts.pluginsDir, opts.source, opts.scope)])
121
177
  : allGroups.filter((g) => g.remote);
122
- if (opts.source && !remoteGroups[0].remote) {
178
+ if (opts.source && selectedGroups[0]?.remote === false) {
123
179
  throw new Error(`source "${opts.source}" is local and cannot be re-synced; re-run \`adg plugins add\`.`);
124
180
  }
181
+ // The marketplace view aggregates a repository for list/remove/sync. Update
182
+ // must fetch each ref independently so one plugin cannot move a sibling's
183
+ // pin or make it appear absent at the wrong revision.
184
+ const initialLock = readLock(lockPath(opts.pluginsDir));
185
+ const remoteGroups = selectedGroups.flatMap((group) => {
186
+ const refs = new Map();
187
+ for (const name of group.installed) {
188
+ const origin = initialLock.plugins[name].origin;
189
+ const ref = origin.type === "local" ? undefined : origin.ref;
190
+ const member = refs.get(ref) ?? { source: group.source, ...(ref ? { ref } : {}), installed: [], remote: true };
191
+ member.installed.push(name);
192
+ refs.set(ref, member);
193
+ }
194
+ for (const intent of initialLock.sources ?? []) {
195
+ if (intent.source === group.source && (intent.mode === "all" || intent.deferredRecovery?.length) && !refs.has(intent.ref)) {
196
+ refs.set(intent.ref, { source: group.source, ref: intent.ref, installed: [], remote: true });
197
+ }
198
+ }
199
+ return [...refs.values()].filter(group => !remote.some(item => item.source === group.source && item.ref === group.ref));
200
+ });
125
201
  const repairAgent = opts.agents
126
202
  ? opts.agents.find((agent) => agent.id === "codex") ?? null
127
203
  : getAgent("codex");
@@ -129,46 +205,43 @@ export async function updatePlugins(opts) {
129
205
  const initial = opts.repair ? repairAgent?.inspectPlugins?.({ pluginsDir: opts.pluginsDir, plugins: [], scope: repairScope }) : undefined;
130
206
  // Source materialization proceeds, but this mode owns every Codex mutation.
131
207
  const updateAgents = opts.repair ? (opts.agents ?? resolveAgents(opts.targets)).filter((agent) => agent.id !== "codex") : opts.agents;
132
- const removalAgents = opts.repair ? (opts.deactivationAgents ?? allAgents()).filter((agent) => agent.id !== "codex") : opts.deactivationAgents;
133
208
  const now = opts.now ?? new Date().toISOString();
134
- const remote = [];
135
- const remoteAgents = [];
209
+ const remoteAgents = [...resumedAgents, ...recovered.agents];
136
210
  let sourceIndex = 0;
137
211
  for (const group of remoteGroups) {
138
212
  const position = { index: ++sourceIndex, total: remoteGroups.length };
139
213
  try {
140
214
  opts.onProgress?.({ kind: "check", ...position, source: group.source });
141
215
  const lock = readLock(lockPath(opts.pluginsDir));
142
- const revisions = group.installed.map((name) => lock.plugins[name]?.resolvedRevision).filter((revision) => Boolean(revision));
143
- const remoteRevision = await (opts.revisionResolver ?? resolveRemoteRevision)(group.source, group.ref);
144
- if (!opts.all && remoteRevision && revisions.length === group.installed.length && revisions.every((revision) => revision === remoteRevision)) {
145
- remote.push({ source: group.source, ...(group.ref ? { ref: group.ref } : {}), updated: [], unchanged: [...group.installed].sort(), deleted: [], available: [] });
216
+ const policy = sourceIntent(lock, group.source, group.ref);
217
+ const targets = opts.targets ?? policy?.targets?.filter((id) => ADAPTER_TARGETS.includes(id));
218
+ const runtime = opts.activate ? opts.agents ?? resolveAgents(targets) : [];
219
+ const refreshExisting = runtime.flatMap(agent => {
220
+ if (!agent.needsProjectionRefresh || !agent.detect())
221
+ return [];
222
+ const names = group.installed.filter(name => lock.plugins[name]?.state !== "disabled");
223
+ return agent.needsProjectionRefresh({ pluginsDir: opts.pluginsDir, scope: repairScope, plugins: names })
224
+ .map(name => ({ name, target: agent.id }));
225
+ });
226
+ const refreshProjections = async (unchanged) => {
227
+ for (const agent of runtime) {
228
+ const refresh = refreshExisting.filter(item => item.target === agent.id && unchanged.includes(item.name)).map(item => item.name);
229
+ if (refresh.length)
230
+ remoteAgents.push(await syncNativeWithRetry({
231
+ pluginsDir: opts.pluginsDir, scope: repairScope, agent, activate: [], refresh, preserveRuntimeDisabled: true,
232
+ }));
233
+ }
234
+ };
235
+ const revisions = group.installed.map((name) => policy?.retained?.includes(name) ? policy.retainedAtRevision : lock.plugins[name]?.resolvedRevision).filter((revision) => Boolean(revision));
236
+ // A supplied transport owns its checkout, including offline fixtures.
237
+ const probe = opts.revisionResolver ?? (opts.gitRunner ? undefined : resolveRemoteRevision);
238
+ const remoteRevision = await probe?.(group.source, group.ref);
239
+ if (!opts.all && !(opts.repair && policy?.deferredRecovery?.length) && revisions.length > 0 && remoteRevision && revisions.length === group.installed.length && revisions.every((revision) => revision === remoteRevision)) {
240
+ await refreshProjections(group.installed);
241
+ 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: [],
242
+ ...(policy?.deferredRecovery?.length ? { deferredRecovery: [...new Set(policy.deferredRecovery.flatMap(item => item.skills))].sort() } : {}) });
146
243
  continue;
147
244
  }
148
- const structural = group.installed.flatMap((name) => {
149
- const definition = lock.plugins[name]?.definition;
150
- return definition ? [{ name, definition, selection: lock.plugins[name]?.selection }] : [];
151
- });
152
- const ordinary = group.installed.filter((name) => !lock.plugins[name]?.definition);
153
- // A structural profile always describes the source root. Replay each
154
- // profile independently so its stable --as identity is preserved.
155
- const requests = [
156
- ...structural.map(({ name, definition, selection }) => ({
157
- plugins: [name],
158
- as: definition.as,
159
- structuralIdentity: name,
160
- defaultDescription: definition.description,
161
- authorizedComponents: definition.authorizedComponents,
162
- replaySelection: selection ?? (definition.authorizedComponents ? { components: definition.authorizedComponents } : undefined),
163
- })),
164
- // A structural profile represents the whole source root. Never append
165
- // an --all fallback that could derive a second Default DSL identity.
166
- ...(structural.length === 0 && (ordinary.length > 0 || opts.all)
167
- ? [{ plugins: opts.all ? undefined : ordinary }]
168
- : []),
169
- ];
170
- const installed = [];
171
- const available = new Set();
172
245
  const checkout = mkdtempSync(join(tmpdir(), "adg-marketplace-update-"));
173
246
  try {
174
247
  const parsed = parseGitHubSource(group.source);
@@ -176,67 +249,46 @@ export async function updatePlugins(opts) {
176
249
  const mat = await materializeSource({ ...parsed, ref: group.ref }, checkout, {
177
250
  runner: opts.gitRunner,
178
251
  resolvedRevision: remoteRevision,
252
+ // A complete source catalog is required to distinguish relocation
253
+ // from deletion, including siblings outside an earlier sparse add.
179
254
  });
180
255
  const resolvedRevision = mat.resolvedRevision ?? gitRevision(checkout);
181
- let requestIndex = 0;
182
- for (const request of requests) {
183
- opts.onProgress?.({
184
- kind: "install",
185
- index: ++requestIndex,
186
- total: requests.length,
187
- source: group.source,
188
- ...(request.structuralIdentity ? { plugin: request.structuralIdentity } : {}),
189
- });
190
- const result = await addPlugins({
191
- spec: group.source,
192
- pluginsDir: opts.pluginsDir,
193
- ref: group.ref,
194
- ...(opts.all && request.plugins === undefined ? { all: true } : { plugins: request.plugins }),
195
- missingPlugins: "skip",
196
- skipUnchanged: true,
197
- nonInteractive: true,
198
- ...(request.authorizedComponents ? { authorizedComponents: request.authorizedComponents } : {}),
199
- ...(request.structuralIdentity ? { structuralIdentity: request.structuralIdentity } : {}),
200
- ...(request.replaySelection ? { replaySelection: request.replaySelection } : {}),
201
- targets: opts.targets,
202
- marketplaceName: group.source,
203
- gitRunner: opts.gitRunner,
204
- ...(request.as ? { as: request.as } : {}),
205
- ...(request.defaultDescription ? { defaultDescription: request.defaultDescription } : {}),
206
- activate: opts.activate,
207
- scope: opts.agentScope,
208
- agents: updateAgents,
209
- deactivationAgents: removalAgents,
210
- now,
211
- preparedSourceDir: checkout,
212
- preparedResolvedRevision: resolvedRevision,
213
- ...(opts.cwd ? { cwd: opts.cwd } : {}),
214
- ...(opts.onProgress ? { onProgress: opts.onProgress } : {}),
215
- });
216
- installed.push(...result.installed);
217
- result.available.forEach((name) => available.add(name));
218
- if (result.agents)
219
- remoteAgents.push(...result.agents);
220
- }
256
+ const result = await upgradeSource({
257
+ group, checkout, revision: resolvedRevision, pluginsDir: opts.pluginsDir,
258
+ all: opts.all, repair: opts.repair, activate: opts.activate, scope: repairScope, agents: opts.agents,
259
+ targets: opts.targets, now, review: opts.review, refreshExisting,
260
+ gitRunner: opts.gitRunner, onProgress: opts.onProgress,
261
+ onAgentResults: results => remoteAgents.push(...results),
262
+ onNativeManaged: rememberManagedNative,
263
+ });
264
+ remote.push(result);
265
+ if (result.deferredRecovery?.length)
266
+ recordTelemetryEvent("adg.plugins.update.recovery_deferred", {
267
+ "skills.count": result.deferredRecovery.length,
268
+ }, opts.telemetrySpan);
269
+ if (result.missingUpstream?.length)
270
+ recordTelemetryEvent("adg.plugins.update.missing_upstream", {
271
+ "plugins.retained": result.missingUpstream.length,
272
+ "update.include_new": Boolean(opts.all),
273
+ }, opts.telemetrySpan);
274
+ else
275
+ recordTelemetryEvent("adg.plugins.update.migration", {
276
+ "migration.count": result.migrated?.length ?? 0,
277
+ "action_required.count": result.actionRequired?.length ?? 0,
278
+ "pending.count": result.pendingRuntime?.length ?? 0,
279
+ "plugins.retained": result.missingUpstream?.length ?? 0,
280
+ }, opts.telemetrySpan);
221
281
  }
222
282
  finally {
223
283
  rmSync(checkout, { recursive: true, force: true });
224
284
  }
225
- const availableSet = available;
226
- const installedNow = new Set(installed.map((r) => r.name));
227
- remote.push({
228
- source: group.source,
229
- ...(group.ref ? { ref: group.ref } : {}),
230
- updated: installed.filter((r) => r.changed).map((r) => r.name).sort(),
231
- unchanged: installed.filter((r) => !r.changed).map((r) => r.name).sort(),
232
- deleted: group.installed.filter((n) => !availableSet.has(n)).sort(),
233
- available: [...available].filter((n) => !installedNow.has(n) && !group.installed.includes(n)).sort(),
234
- changes: installed.filter((r) => r.changes).map((r) => ({
235
- name: r.name, ...r.changes, runtimeRefreshRequired: r.runtimeRefreshRequired ?? r.changed,
236
- })).sort((a, b) => a.name.localeCompare(b.name)),
237
- });
238
285
  }
239
286
  catch (err) {
287
+ if (err instanceof UpdateCancelled) {
288
+ err.partial = { remote: [...remote, ...(err.partial?.remote ?? [])], local: { results: [], missing: [] },
289
+ agents: [...remoteAgents, ...(err.partial?.agents ?? [])] };
290
+ throw err;
291
+ }
240
292
  remote.push({
241
293
  source: group.source,
242
294
  ...(group.ref ? { ref: group.ref } : {}),
@@ -261,18 +313,16 @@ export async function updatePlugins(opts) {
261
313
  ...(opts.onProgress ? { onProgress: opts.onProgress } : {}),
262
314
  })
263
315
  : { results: [], missing: [] };
264
- const repairNames = [...new Set([...remoteGroups.flatMap((group) => group.installed), ...remote.flatMap((source) => [...source.updated, ...source.unchanged]), ...localNames])];
316
+ const repairNames = [...new Set([...selectedGroups.flatMap((group) => group.installed), ...remote.flatMap((source) => [...source.updated, ...source.unchanged]), ...localNames])].filter(name => !managedByMigration.has(name));
265
317
  const currentLock = readLock(lockPath(opts.pluginsDir));
266
- const repairs = opts.repair ? [repairCodex({
267
- pluginsDir: opts.pluginsDir,
268
- plugins: repairNames.filter((name) => currentLock.plugins[name]),
269
- scope: opts.agentScope ?? "project",
318
+ const repairs = opts.activate && opts.repair && repairNames.length ? [repairCodex({
319
+ pluginsDir: opts.pluginsDir, plugins: repairNames.filter(name => currentLock.plugins[name]), scope: repairScope,
270
320
  }, false, repairAgent, {
271
321
  initial, observed: true,
272
- changed: [...remote.flatMap((source) => source.changes
273
- ? source.changes.filter((plugin) => plugin.runtimeRefreshRequired).map((plugin) => plugin.name)
274
- : source.updated), ...local.results.filter((plugin) => plugin.runtimeRefreshRequired ?? plugin.changed).map((plugin) => plugin.name)],
275
- removed: repairNames.filter((name) => !currentLock.plugins[name]),
322
+ changed: [...remote.flatMap(source => source.changes
323
+ ? source.changes.filter(plugin => plugin.runtimeRefreshRequired).map(plugin => plugin.name)
324
+ : source.updated), ...local.results.filter(plugin => plugin.runtimeRefreshRequired ?? plugin.changed).map(plugin => plugin.name)],
325
+ removed: repairNames.filter(name => !currentLock.plugins[name]),
276
326
  })] : [];
277
327
  const agents = mergeAgentResults([remoteAgents, local.agents ?? [], repairs]);
278
328
  return { remote, local, agents };
@@ -291,6 +341,12 @@ export function marketplaceRemove(opts) {
291
341
  });
292
342
  removed.push(name);
293
343
  }
344
+ const file = lockPath(opts.pluginsDir);
345
+ const lock = readLock(file);
346
+ if (lock.sources?.some(intent => intent.source === opts.source)) {
347
+ lock.sources = lock.sources.filter(intent => intent.source !== opts.source);
348
+ writeLock(file, lock);
349
+ }
294
350
  return { source: opts.source, removed };
295
351
  }
296
352
  /**
@@ -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 ((raw.version === 3 || raw.version === 4) && typeof raw.plugins === "object" && raw.plugins !== null) {
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.selection,
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
- p.cancel("Installation cancelled");
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
- p.cancel("Installation cancelled");
7
- process.exit(0);
7
+ throw new UpdateCancelled("Installation cancelled");
8
8
  }
9
9
  return false;
10
10
  }
@@ -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
- p.cancel("Installation cancelled");
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
- p.cancel("Installation cancelled");
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
- p.cancel("Cancelled");
37
- process.exit(0);
36
+ throw new UpdateCancelled("Installation cancelled");
38
37
  }
39
38
  return scope;
40
39
  }