agents-inc 0.176.0 → 0.177.0

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 (104) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/README.md +2 -2
  3. package/dist/{chunk-FACDJH6O.js → chunk-2FE4AJNC.js} +20 -26
  4. package/dist/chunk-2FE4AJNC.js.map +1 -0
  5. package/dist/{chunk-U46LYYRA.js → chunk-4SIBDIIO.js} +49 -13
  6. package/dist/chunk-4SIBDIIO.js.map +1 -0
  7. package/dist/chunk-5ZK4IND4.js +30 -0
  8. package/dist/chunk-5ZK4IND4.js.map +1 -0
  9. package/dist/{chunk-MQZNDK5F.js → chunk-77SHXTDD.js} +137 -56
  10. package/dist/chunk-77SHXTDD.js.map +1 -0
  11. package/dist/{chunk-U672FZVC.js → chunk-7OJ2SS4E.js} +10 -86
  12. package/dist/chunk-7OJ2SS4E.js.map +1 -0
  13. package/dist/{chunk-C2BSCEDN.js → chunk-7WN6TUZP.js} +7 -8
  14. package/dist/chunk-7WN6TUZP.js.map +1 -0
  15. package/dist/chunk-AVKX3IXF.js +117 -0
  16. package/dist/chunk-AVKX3IXF.js.map +1 -0
  17. package/dist/{chunk-ENET4IF6.js → chunk-D2PC7NIR.js} +1653 -1734
  18. package/dist/chunk-D2PC7NIR.js.map +1 -0
  19. package/dist/{chunk-JTMSFBCA.js → chunk-E6W3PYGF.js} +823 -72
  20. package/dist/chunk-E6W3PYGF.js.map +1 -0
  21. package/dist/chunk-H33ZAEKH.js +147 -0
  22. package/dist/chunk-H33ZAEKH.js.map +1 -0
  23. package/dist/{chunk-B7AVWSK2.js → chunk-JEFVFZAR.js} +39 -151
  24. package/dist/chunk-JEFVFZAR.js.map +1 -0
  25. package/dist/{chunk-UE4Z3YMB.js → chunk-KKGJH46C.js} +3 -21
  26. package/dist/chunk-KKGJH46C.js.map +1 -0
  27. package/dist/chunk-OIQKRXHH.js +142 -0
  28. package/dist/chunk-OIQKRXHH.js.map +1 -0
  29. package/dist/{chunk-CKBWEWHZ.js → chunk-TNN72UL6.js} +264 -247
  30. package/dist/chunk-TNN72UL6.js.map +1 -0
  31. package/dist/{chunk-XMQIWPIR.js → chunk-V3WJMNBF.js} +45 -18
  32. package/dist/chunk-V3WJMNBF.js.map +1 -0
  33. package/dist/chunk-VFD2XYM7.js +14 -0
  34. package/dist/chunk-VFD2XYM7.js.map +1 -0
  35. package/dist/{chunk-XYBHH3M5.js → chunk-WH7JXGDA.js} +2 -2
  36. package/dist/{chunk-JNRACLNS.js → chunk-XSR4WRXJ.js} +3 -3
  37. package/dist/{chunk-3F5LT433.js → chunk-Y5VMB73R.js} +202 -116
  38. package/dist/chunk-Y5VMB73R.js.map +1 -0
  39. package/dist/chunk-ZIBWVTLN.js +18 -0
  40. package/dist/chunk-ZIBWVTLN.js.map +1 -0
  41. package/dist/commands/build/marketplace.js +6 -10
  42. package/dist/commands/build/marketplace.js.map +1 -1
  43. package/dist/commands/build/plugins.js +10 -39
  44. package/dist/commands/build/plugins.js.map +1 -1
  45. package/dist/commands/compile.js +60 -81
  46. package/dist/commands/compile.js.map +1 -1
  47. package/dist/commands/doctor.js +234 -145
  48. package/dist/commands/doctor.js.map +1 -1
  49. package/dist/commands/edit.js +64 -159
  50. package/dist/commands/edit.js.map +1 -1
  51. package/dist/commands/eject.js +64 -54
  52. package/dist/commands/eject.js.map +1 -1
  53. package/dist/commands/init.js +19 -17
  54. package/dist/commands/list.js +10 -12
  55. package/dist/commands/list.js.map +1 -1
  56. package/dist/commands/new/marketplace.js +5 -5
  57. package/dist/commands/search.js +14 -13
  58. package/dist/commands/search.js.map +1 -1
  59. package/dist/commands/share.js +21 -44
  60. package/dist/commands/share.js.map +1 -1
  61. package/dist/commands/uninstall.js +139 -56
  62. package/dist/commands/uninstall.js.map +1 -1
  63. package/dist/commands/update.js +22 -37
  64. package/dist/commands/update.js.map +1 -1
  65. package/dist/components/common/header-row.js +9 -0
  66. package/dist/components/common/select-list.js +2 -2
  67. package/dist/components/common/skill-agent-summary.js +4 -4
  68. package/dist/components/common/summary-panel.js +6 -5
  69. package/dist/hooks/init.js +35 -22
  70. package/dist/hooks/init.js.map +1 -1
  71. package/dist/load-agent-defs-OCFWOZD2.js +14 -0
  72. package/dist/{recompile-project-agents-U3UGHPWG.js → recompile-project-agents-CXZBPIUS.js} +9 -9
  73. package/dist/{recompile-project-agents-U3UGHPWG.js.map → recompile-project-agents-CXZBPIUS.js.map} +1 -1
  74. package/dist/{source-loader-E2Y5MMN5.js → source-loader-GGDQDMN4.js} +6 -4
  75. package/dist/source-loader-GGDQDMN4.js.map +1 -0
  76. package/package.json +1 -1
  77. package/src/schemas/stacks.schema.json +105 -1
  78. package/dist/chunk-3F5LT433.js.map +0 -1
  79. package/dist/chunk-5CFHP6Z5.js +0 -109
  80. package/dist/chunk-5CFHP6Z5.js.map +0 -1
  81. package/dist/chunk-B7AVWSK2.js.map +0 -1
  82. package/dist/chunk-C2BSCEDN.js.map +0 -1
  83. package/dist/chunk-CKBWEWHZ.js.map +0 -1
  84. package/dist/chunk-EC3JXT23.js +0 -160
  85. package/dist/chunk-EC3JXT23.js.map +0 -1
  86. package/dist/chunk-ENET4IF6.js.map +0 -1
  87. package/dist/chunk-FACDJH6O.js.map +0 -1
  88. package/dist/chunk-H6WUOW5F.js +0 -35
  89. package/dist/chunk-H6WUOW5F.js.map +0 -1
  90. package/dist/chunk-JTMSFBCA.js.map +0 -1
  91. package/dist/chunk-MQZNDK5F.js.map +0 -1
  92. package/dist/chunk-SN64WNWE.js +0 -428
  93. package/dist/chunk-SN64WNWE.js.map +0 -1
  94. package/dist/chunk-U46LYYRA.js.map +0 -1
  95. package/dist/chunk-U672FZVC.js.map +0 -1
  96. package/dist/chunk-UE4Z3YMB.js.map +0 -1
  97. package/dist/chunk-XMQIWPIR.js.map +0 -1
  98. package/dist/chunk-ZBI6GFJD.js +0 -39
  99. package/dist/chunk-ZBI6GFJD.js.map +0 -1
  100. package/dist/load-agent-defs-5BSECHE6.js +0 -14
  101. /package/dist/{chunk-XYBHH3M5.js.map → chunk-WH7JXGDA.js.map} +0 -0
  102. /package/dist/{chunk-JNRACLNS.js.map → chunk-XSR4WRXJ.js.map} +0 -0
  103. /package/dist/{load-agent-defs-5BSECHE6.js.map → components/common/header-row.js.map} +0 -0
  104. /package/dist/{source-loader-E2Y5MMN5.js.map → load-agent-defs-OCFWOZD2.js.map} +0 -0
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  getLocalAgentDefinitions
4
- } from "./chunk-EC3JXT23.js";
4
+ } from "./chunk-5ZK4IND4.js";
5
5
  import {
6
6
  loadMergedAgents
7
- } from "./chunk-ENET4IF6.js";
7
+ } from "./chunk-D2PC7NIR.js";
8
8
 
9
9
  // src/cli/lib/operations/project/load-agent-defs.ts
10
10
  async function loadAgentDefs() {
@@ -20,4 +20,4 @@ async function loadAgentDefs() {
20
20
  export {
21
21
  loadAgentDefs
22
22
  };
23
- //# sourceMappingURL=chunk-JNRACLNS.js.map
23
+ //# sourceMappingURL=chunk-XSR4WRXJ.js.map
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  SelectList
4
- } from "./chunk-XYBHH3M5.js";
4
+ } from "./chunk-WH7JXGDA.js";
5
5
  import {
6
- openUrl
7
- } from "./chunk-H6WUOW5F.js";
8
- import {
9
- fetchSeedConfig
10
- } from "./chunk-SN64WNWE.js";
6
+ filesATakeBackMayEmpty,
7
+ foldersAPluginInstallMayEmpty,
8
+ foldersATakeBackMayEmpty,
9
+ removeIfHoldingNothing
10
+ } from "./chunk-AVKX3IXF.js";
11
11
  import {
12
12
  Confirm
13
13
  } from "./chunk-OZXAJNLA.js";
@@ -18,10 +18,10 @@ import {
18
18
  import {
19
19
  summaryPanelBlock,
20
20
  useTerminalDimensions
21
- } from "./chunk-C2BSCEDN.js";
21
+ } from "./chunk-7WN6TUZP.js";
22
22
  import {
23
23
  hostCompileNotices
24
- } from "./chunk-U672FZVC.js";
24
+ } from "./chunk-7OJ2SS4E.js";
25
25
  import {
26
26
  compileAgentsAllScopes,
27
27
  compileProjectScope,
@@ -29,16 +29,19 @@ import {
29
29
  movedGlobalAgentInputs,
30
30
  sayCapturedWarnings,
31
31
  writeProjectConfig
32
- } from "./chunk-CKBWEWHZ.js";
32
+ } from "./chunk-TNN72UL6.js";
33
33
  import {
34
34
  copyLocalSkills,
35
35
  discoverInstalledSkills,
36
36
  removeSkillFoldersCreatedSince,
37
37
  skillFoldersAt
38
- } from "./chunk-XMQIWPIR.js";
38
+ } from "./chunk-V3WJMNBF.js";
39
39
  import {
40
40
  loadAgentDefs
41
- } from "./chunk-JNRACLNS.js";
41
+ } from "./chunk-XSR4WRXJ.js";
42
+ import {
43
+ mapInTurn
44
+ } from "./chunk-VFD2XYM7.js";
42
45
  import {
43
46
  render
44
47
  } from "./chunk-KIK5EZYD.js";
@@ -47,22 +50,18 @@ import {
47
50
  EXIT_CODES,
48
51
  clearTerminalScreen,
49
52
  holdInstalledGlobal,
50
- installationToName,
51
- installsAtHome,
52
53
  joinedStatement,
54
+ keptAsInstalledStatement,
53
55
  notInstalledGlobally,
54
- panelRowEntries,
55
56
  providerFlag,
56
57
  providerNamedBy,
57
58
  providerNeedsAConfigurationToInstall,
58
59
  readInstalledGlobal,
59
- registerExternalSkills,
60
- writeExternalSkills
61
- } from "./chunk-JTMSFBCA.js";
60
+ runFromHomeFor
61
+ } from "./chunk-E6W3PYGF.js";
62
62
  import {
63
- agentChangesAmong,
64
- namedByActiveEntries
65
- } from "./chunk-FACDJH6O.js";
63
+ agentChangesAmong
64
+ } from "./chunk-2FE4AJNC.js";
66
65
  import {
67
66
  ERROR_MESSAGES,
68
67
  INCOMPLETE_WORK_RECOVERY,
@@ -75,12 +74,10 @@ import {
75
74
  advisesOnPermissions,
76
75
  agentCodec,
77
76
  agentsNotCompiled,
78
- applySharedConfigHere,
79
77
  assertNamedSourceUsable,
80
78
  buildAgentScopeMap,
81
79
  buildMarketplacePluginRef,
82
80
  carriedSkillsRemovedAfterRefusedSave,
83
- carriedSkillsWritten,
84
81
  chooseProviderForThisRun,
85
82
  copiedSkillsRemovedAfterRefusedSave,
86
83
  deriveInstallMode,
@@ -90,31 +87,35 @@ import {
90
87
  getErrorMessage,
91
88
  getInstallationsByProvider,
92
89
  globalScopedAgentsHint,
93
- holdsItsOwnInstallation,
94
90
  hostAt,
91
+ hostCompilesAgent,
95
92
  initSucceeded,
96
93
  isHomeDirectory,
94
+ isKnownAbsent,
97
95
  isLocalSource,
98
- keptAsInstalledGlobally,
96
+ marketplaceRemovedAfterRefusedSave,
99
97
  permissionFiles,
98
+ pluginKeptAfterRefusedSave,
100
99
  providerAtScope,
101
100
  providerInUse,
102
101
  providerToNameAt,
103
102
  readFileSafe,
104
103
  relativeConfigPath,
104
+ removeDirIfEmpty,
105
105
  resolveBranding,
106
106
  resolveInstallPaths,
107
- seedToInstallSelection,
108
107
  settingsFileSchema,
109
108
  sharedConfigExistingInstall,
110
109
  stoppingOnARefusal,
111
110
  subAgentChanged,
111
+ toPosixPath,
112
112
  verbose,
113
- warn
114
- } from "./chunk-ENET4IF6.js";
113
+ warn,
114
+ whileInstallingInto
115
+ } from "./chunk-D2PC7NIR.js";
115
116
  import {
116
117
  plural
117
- } from "./chunk-UE4Z3YMB.js";
118
+ } from "./chunk-KKGJH46C.js";
118
119
  import {
119
120
  ASCII_LOGO,
120
121
  CLI_COLORS,
@@ -126,14 +127,14 @@ import {
126
127
  MAX_CONFIG_FILE_SIZE,
127
128
  editorConfigUrl,
128
129
  isActiveAt
129
- } from "./chunk-U46LYYRA.js";
130
+ } from "./chunk-4SIBDIIO.js";
130
131
 
131
132
  // src/cli/commands/init.tsx
132
- import os from "os";
133
133
  import "react";
134
+ import path2 from "path";
134
135
  import { Errors, Flags } from "@oclif/core";
135
136
  import { Box as Box2, Text as Text2, useApp } from "ink";
136
- import { partition } from "remeda";
137
+ import { partition, unique } from "remeda";
137
138
 
138
139
  // src/cli/lib/permission-checker.tsx
139
140
  import "react";
@@ -165,7 +166,7 @@ async function loadPermissions(files) {
165
166
  return void 0;
166
167
  }
167
168
  function asUserWritesIt(projectRoot, file) {
168
- return path.relative(projectRoot, file).split(path.sep).join("/");
169
+ return toPosixPath(path.relative(projectRoot, file));
169
170
  }
170
171
  async function checkPermissions(projectRoot) {
171
172
  if (!advisesOnPermissions(providerInUse(projectRoot))) return null;
@@ -350,14 +351,11 @@ var Init = class _Init extends BaseCommand {
350
351
  async openEditor(projectDir, provider, id, marketplace) {
351
352
  const url = id === void 0 ? EDITOR_URL : editorConfigUrl(id);
352
353
  const marketplaceLine = marketplace === void 0 ? void 0 : this.addMarketplaceLineOrFail(marketplace);
353
- const installedHere = await holdsItsOwnInstallation(projectDir);
354
- const toName = installedHere ? await installationToName(projectDir, provider) : provider;
354
+ const applyHere = await this.howToApplyItHere(id, projectDir, provider);
355
355
  this.log(id === void 0 ? `Build it at ${url}` : `Open it at ${url}`);
356
356
  if (marketplaceLine !== void 0) this.log(marketplaceLine);
357
- this.log(applySharedConfigHere(id, installedHere, toName));
358
- if (!process.stdin.isTTY) return;
359
- const opened = await openUrl(url);
360
- if (!opened.ok) this.warn(opened.error);
357
+ this.log(applyHere);
358
+ await this.openInBrowserAtATerminal(url);
361
359
  }
362
360
  async install() {
363
361
  const { flags } = await this.parse(_Init);
@@ -372,15 +370,20 @@ var Init = class _Init extends BaseCommand {
372
370
  flags.marketplace
373
371
  );
374
372
  }
373
+ const { from } = flags;
374
+ if (from === void 0) return this.showDashboardOrOpenEditor(projectDir);
375
+ return whileInstallingInto(projectDir, () => this.installSharedConfig(from, flags, projectDir));
376
+ }
377
+ async installSharedConfig(id, flags, projectDir) {
375
378
  await this.ensureConfigReadable(projectDir);
376
- if (flags.from === void 0) return this.showDashboardOrOpenEditor(projectDir);
377
379
  this.brandingName = await this.resolveBrandingName(projectDir);
378
- const selection = await this.selectionFromSharedConfig(flags.from, flags, projectDir);
380
+ const selection = await this.selectionFromSharedConfig(id, flags, projectDir);
379
381
  if (!selection) this.exit(EXIT_CODES.CANCELLED);
380
382
  this.reportValidationErrors(selection.result.validation);
381
383
  await this.handleInstallation(selection, projectDir);
382
384
  }
383
385
  async showDashboardOrOpenEditor(projectDir) {
386
+ await this.ensureConfigReadable(projectDir);
384
387
  const dashboard = await runDashboardFlow(projectDir, this.config, (msg) => this.log(msg));
385
388
  switch (dashboard) {
386
389
  case "cancelled":
@@ -415,6 +418,7 @@ var Init = class _Init extends BaseCommand {
415
418
  }
416
419
  /** Every refusal fires before anything is written. */
417
420
  async selectionFromSharedConfig(id, flags, projectDir) {
421
+ const hostPathsMissing = await hostPathsMissingAt(projectDir);
418
422
  await this.refuseInstalledProject(projectDir, id);
419
423
  const payload = await this.fetchSharedConfigOrFail(id);
420
424
  const sourceFlags = sharedConfigSourceFlags(flags, payload);
@@ -440,23 +444,23 @@ var Init = class _Init extends BaseCommand {
440
444
  this.warnOfSkippedEntries(mapping, sourceResult.unloadedSkillIds);
441
445
  this.refuseAnEmptySelection(held.result, id);
442
446
  const stackName = await this.stackNameOf(result.selectedStackId, sourceResult);
443
- this.logWhatGoesWhere(held, installedGlobal, stackName, {
444
- id: installsAtHome(result) ? id : void 0,
445
- provider: providerToNameAt(os.homedir(), providerInUse(projectDir))
446
- });
447
+ this.logWhatGoesWhere(held, installedGlobal, stackName, runFromHomeFor(result, id, projectDir));
447
448
  if (process.stdin.isTTY && !await this.confirmInstall()) {
448
449
  this.log("Setup cancelled");
449
450
  return null;
450
451
  }
451
452
  const skillFoldersBefore = await skillFoldersAt(projectDir);
453
+ const installFoldersMissing = await installFoldersMissingAt(projectDir);
452
454
  await this.writeCarriedSkills(arrivingCarried);
453
- this.announceArrivingSkills(held, result.selectedAgents.length);
455
+ this.announceArrivingSkills(held, countCompiledAgents(projectDir, result.agentConfigs));
454
456
  return {
455
457
  result: held.result,
456
458
  sourceResult,
457
459
  sourceFlags,
458
460
  installedAlready: new Set(held.installed.skillIds),
459
461
  skillFoldersBefore,
462
+ installFoldersMissing,
463
+ hostPathsMissing,
460
464
  carriedSkillDirs: new Set(arrivingCarried.map(({ skillDir }) => skillDir))
461
465
  };
462
466
  }
@@ -469,7 +473,7 @@ var Init = class _Init extends BaseCommand {
469
473
  const lines = summaryPanelBlock(
470
474
  installPanel(held, installedGlobal, joined, stackName),
471
475
  joined.map(subAgentChanged),
472
- [...joinedStatement(held), ...keptAsInstalledStatement(held, runFromHome)]
476
+ [...joinedStatement(held), ...keptAsInstalledStatement(held, [], runFromHome)]
473
477
  );
474
478
  for (const line of lines) {
475
479
  this.log(line);
@@ -484,8 +488,10 @@ var Init = class _Init extends BaseCommand {
484
488
  announceArrivingSkills(held, agentCount) {
485
489
  const arriving = notInstalledGlobally(held.result.skills, held);
486
490
  if (arriving.length === 0) return;
487
- this.log(`Installing ${arriving.length} skill(s) across ${agentCount} sub-agent(s)
488
- `);
491
+ this.log(
492
+ `Installing ${plural(arriving.length, "skill")} across ${plural(agentCount, "sub-agent")}
493
+ `
494
+ );
489
495
  }
490
496
  async confirmInstall() {
491
497
  const outcome = await promptConfirm(({ onConfirm, onCancel }) => /* @__PURE__ */ jsx2(
@@ -507,39 +513,6 @@ var Init = class _Init extends BaseCommand {
507
513
  exit: EXIT_CODES.ERROR
508
514
  });
509
515
  }
510
- async fetchSharedConfigOrFail(id) {
511
- this.log(`Fetching configuration ${id}...`);
512
- const fetched = await fetchSeedConfig(id);
513
- if (!fetched.ok) {
514
- this.error(fetched.error, { exit: EXIT_CODES.ERROR });
515
- }
516
- return fetched.payload;
517
- }
518
- decodeSeedOrFail(payload, matrix) {
519
- try {
520
- return seedToInstallSelection(payload, matrix);
521
- } catch (error) {
522
- this.handleError(error);
523
- }
524
- }
525
- registerExternalSkillsOrFail(payload, matrix, projectDir) {
526
- try {
527
- return registerExternalSkills(payload, matrix, projectDir);
528
- } catch (error) {
529
- this.handleError(error);
530
- }
531
- }
532
- async writeCarriedSkills(carried) {
533
- if (carried.length === 0) return;
534
- await writeExternalSkills(carried);
535
- const recorded = carried.map(({ id, skill }) => ({ id, displayName: skill.displayName }));
536
- this.log(
537
- carriedSkillsWritten(
538
- carried.map(({ id }) => id),
539
- namedByActiveEntries(recorded)
540
- )
541
- );
542
- }
543
516
  async loadSourceOrFail(flags, projectDir) {
544
517
  try {
545
518
  const loaded = await stoppingOnARefusal(
@@ -564,19 +537,21 @@ var Init = class _Init extends BaseCommand {
564
537
  sourceFlags,
565
538
  installedAlready,
566
539
  skillFoldersBefore,
540
+ installFoldersMissing,
541
+ hostPathsMissing,
567
542
  carriedSkillDirs
568
543
  }, projectDir) {
569
544
  const plan = planInstall(result, installedAlready);
570
545
  this.logInstallPlan(plan);
571
- const resolvedMarketplace = await this.marketplaceForPluginSkills(
546
+ const marketplace = await this.marketplaceForPluginSkills(
572
547
  plan.pluginSkills,
573
548
  sourceResult,
574
549
  projectDir
575
550
  );
576
551
  const copyResult = await this.copyEjectedSkills(plan, projectDir, sourceResult);
577
- const pluginsNewlyInstalled = await this.installPluginSkillsNotingWhatWasHeld(
552
+ const plugins = await this.installPluginSkillsNotingWhatWasHeld(
578
553
  plan.pluginSkills,
579
- resolvedMarketplace,
554
+ marketplace,
580
555
  projectDir,
581
556
  sourceResult.matrix
582
557
  );
@@ -585,7 +560,15 @@ var Init = class _Init extends BaseCommand {
585
560
  sourceResult,
586
561
  sourceFlags,
587
562
  projectDir,
588
- { skillFoldersBefore, carriedSkillDirs, copyResult, pluginsNewlyInstalled }
563
+ {
564
+ skillFoldersBefore,
565
+ installFoldersMissing,
566
+ hostPathsMissing,
567
+ carriedSkillDirs,
568
+ copyResult,
569
+ plugins,
570
+ marketplace
571
+ }
589
572
  );
590
573
  try {
591
574
  const written = await this.compileWrittenConfig(configResult, projectDir);
@@ -597,12 +580,15 @@ var Init = class _Init extends BaseCommand {
597
580
  }
598
581
  async marketplaceForPluginSkills(pluginSkills, sourceResult, projectDir) {
599
582
  if (pluginSkills.length === 0) return null;
600
- return this.requireMarketplaceOrExit(
583
+ const host = hostAt(projectDir);
584
+ const heldBefore = await marketplacesHeldBy(host);
585
+ const name = await this.requireMarketplaceOrExit(
601
586
  sourceResult,
602
587
  "install plugin skills",
603
- hostAt(projectDir),
588
+ host,
604
589
  (marketplace) => this.log(`Registering marketplace "${marketplace}"...`)
605
590
  );
591
+ return { name, newlyRegistered: !heldBefore(name) };
606
592
  }
607
593
  /** One frame, then unmount: the notice has no exit of its own and `--from` must run headless. */
608
594
  async showPermissionNotice(projectDir) {
@@ -623,12 +609,13 @@ var Init = class _Init extends BaseCommand {
623
609
  this.log(skillsCopiedLine(copyResult, installMode, projectDir));
624
610
  return copyResult;
625
611
  }
626
- /** Each plugin this run installed that the host did not already hold, at the scope it went to. */
627
612
  async installPluginSkillsNotingWhatWasHeld(pluginSkills, marketplace, projectDir, matrix) {
628
- if (marketplace === null) return [];
613
+ if (marketplace === null) return { newlyInstalled: [], perhapsHeld: [], foldersMissing: [] };
629
614
  const heldBefore = await pluginRefsHeldAt(projectDir);
630
- await this.installPluginSkillsReported(pluginSkills, marketplace, projectDir, matrix);
631
- return pluginSkills.map(({ id, scope }) => ({ ref: buildMarketplacePluginRef(id, marketplace), scope })).filter(({ ref }) => !heldBefore(ref));
615
+ const foldersMissing = await pluginInstallFoldersMissingAt(projectDir, marketplace.name);
616
+ await this.installPluginSkillsReported(pluginSkills, marketplace.name, projectDir, matrix);
617
+ const installed = pluginsInstalledFrom(marketplace.name, pluginSkills);
618
+ return { ...splitByWhatWasHeld(installed, heldBefore), foldersMissing };
632
619
  }
633
620
  async compileWrittenConfig(configResult, projectDir) {
634
621
  const agentScopeMap = buildAgentScopeMap(configResult.config);
@@ -662,19 +649,25 @@ var Init = class _Init extends BaseCommand {
662
649
  this.reportUnassignedSkills(configResult.config, result.skills);
663
650
  return configResult;
664
651
  }
665
- /** Fails with the write's own cause once nothing this run put down is left with no config. */
666
652
  async takingBackOnFailure(putDown, projectDir, write) {
667
653
  try {
668
654
  return await write();
669
655
  } catch (error) {
670
656
  const foldersRemoved = await removeNewSkillFolders(putDown.skillFoldersBefore, projectDir);
671
- await uninstallEach(putDown.pluginsNewlyInstalled, projectDir);
672
- this.failSayingWhatWasRemoved(error, skillsRemoved(putDown, foldersRemoved));
657
+ await uninstallEach(putDown.plugins.newlyInstalled, projectDir);
658
+ const marketplaceRemoved = await removeNewMarketplace(putDown, projectDir);
659
+ await removeHostFilesLeftEmpty(putDown.hostPathsMissing.files);
660
+ await removeFoldersLeftEmpty(foldersThisRunMade(putDown));
661
+ this.failSayingWhatWasTakenBack(error, {
662
+ ...skillsRemoved(putDown, foldersRemoved),
663
+ marketplace: marketplaceRemoved,
664
+ pluginsKept: putDown.plugins.perhapsHeld.map(({ ref }) => ref)
665
+ });
673
666
  }
674
667
  }
675
668
  /** oclif prints a thrown error last, so this one is printed here and thrown already printed. */
676
- failSayingWhatWasRemoved(error, removed) {
677
- const lines = linesSayingWhatWasRemoved(removed);
669
+ failSayingWhatWasTakenBack(error, takenBack) {
670
+ const lines = linesSayingWhatWasTakenBack(takenBack);
678
671
  if (lines.length === 0) this.handleError(error);
679
672
  const message = getErrorMessage(error);
680
673
  this.error(message, { exit: false });
@@ -769,19 +762,6 @@ async function installedGlobalToHold(projectDir) {
769
762
  if (isHomeDirectory(projectDir)) return null;
770
763
  return await readInstalledGlobal(projectDir);
771
764
  }
772
- function keptAsInstalledStatement(held, runFromHome) {
773
- const { skillIds, agentNames } = held.keptAsInstalled;
774
- if (skillIds.length === 0 && agentNames.length === 0) return [];
775
- return [
776
- keptAsInstalledGlobally(
777
- skillIds,
778
- agentNames,
779
- runFromHome.id,
780
- runFromHome.provider,
781
- panelRowEntries(held)
782
- )
783
- ];
784
- }
785
765
  function inheritedGlobal(held, installedGlobal) {
786
766
  if (installedGlobal === null) return { skills: [], agents: [] };
787
767
  const namedSkills = new Set(held.result.skills.filter(isGlobal).map(({ id }) => id));
@@ -836,11 +816,30 @@ function installModeDescription({ installMode, ejectedSkills, pluginSkills }) {
836
816
  }
837
817
  async function pluginRefsHeldAt(projectDir) {
838
818
  try {
839
- const held = await hostAt(projectDir).listPlugins(projectDir);
840
- const refs = new Set(held.map(({ pluginKey }) => pluginKey));
841
- return (ref) => refs.has(ref);
819
+ return new Set(await hostAt(projectDir).pluginsHeld(projectDir));
842
820
  } catch (error) {
843
821
  verbose(`Could not read the plugins installed before this run: ${getErrorMessage(error)}`);
822
+ return null;
823
+ }
824
+ }
825
+ function pluginsInstalledFrom(marketplace, pluginSkills) {
826
+ return pluginSkills.map(({ id, scope }) => ({
827
+ ref: buildMarketplacePluginRef(id, marketplace),
828
+ scope
829
+ }));
830
+ }
831
+ function splitByWhatWasHeld(installed, heldBefore) {
832
+ if (heldBefore === null) return { newlyInstalled: [], perhapsHeld: installed };
833
+ return { newlyInstalled: installed.filter(({ ref }) => !heldBefore.has(ref)), perhapsHeld: [] };
834
+ }
835
+ async function marketplacesHeldBy(host) {
836
+ try {
837
+ const held = new Set(await host.marketplaceTakeBack.marketplacesHeld());
838
+ return (name) => held.has(name);
839
+ } catch (error) {
840
+ verbose(
841
+ `Could not read the marketplaces registered before this run: ${getErrorMessage(error)}`
842
+ );
844
843
  return () => true;
845
844
  }
846
845
  }
@@ -852,6 +851,64 @@ async function removeNewSkillFolders(before, projectDir) {
852
851
  return /* @__PURE__ */ new Set();
853
852
  }
854
853
  }
854
+ async function installFoldersMissingAt(projectDir) {
855
+ return foldersMissingOnTheWayToEach(foldersWrittenBeforeTheSave(projectDir));
856
+ }
857
+ function foldersWrittenBeforeTheSave(projectDir) {
858
+ const project = resolveInstallPaths(projectDir, "project");
859
+ return [
860
+ project.skillsDir,
861
+ resolveInstallPaths(projectDir, "global").skillsDir,
862
+ path2.dirname(project.configPath)
863
+ ];
864
+ }
865
+ async function foldersMissingOnTheWayToEach(folders) {
866
+ const chains = await Promise.all(folders.map(foldersMissingOnTheWayTo));
867
+ return unique(chains.flat());
868
+ }
869
+ async function foldersMissingOnTheWayTo(dir) {
870
+ if (!await isKnownAbsent(dir)) return [];
871
+ return [dir, ...await foldersMissingOnTheWayTo(path2.dirname(dir))];
872
+ }
873
+ async function hostPathsMissingAt(projectDir) {
874
+ const provider = providerInUse(projectDir);
875
+ const files = filesATakeBackMayEmpty(provider, projectDir);
876
+ const absent = await Promise.all(files.map(isKnownAbsent));
877
+ return {
878
+ files: files.filter((_, at) => absent[at]),
879
+ folders: await foldersMissingOnTheWayToEach(foldersATakeBackMayEmpty(provider, projectDir))
880
+ };
881
+ }
882
+ async function pluginInstallFoldersMissingAt(projectDir, marketplace) {
883
+ const provider = providerInUse(projectDir);
884
+ return foldersMissingOnTheWayToEach(
885
+ foldersAPluginInstallMayEmpty(provider, projectDir, marketplace)
886
+ );
887
+ }
888
+ function foldersThisRunMade({
889
+ installFoldersMissing,
890
+ hostPathsMissing,
891
+ plugins
892
+ }) {
893
+ return [...installFoldersMissing, ...hostPathsMissing.folders, ...plugins.foldersMissing];
894
+ }
895
+ async function removeHostFilesLeftEmpty(files) {
896
+ await Promise.all(
897
+ files.map(
898
+ (file) => removeIfHoldingNothing(file).catch((error) => {
899
+ verbose(`Could not remove ${file}, which this run created: ${getErrorMessage(error)}`);
900
+ })
901
+ )
902
+ );
903
+ }
904
+ async function removeFoldersLeftEmpty(folders) {
905
+ const deepestFirst = unique(folders).toSorted((a, b) => b.length - a.length);
906
+ try {
907
+ await mapInTurn(deepestFirst, removeDirIfEmpty);
908
+ } catch (error) {
909
+ verbose(`Could not remove a folder this run made: ${getErrorMessage(error)}`);
910
+ }
911
+ }
855
912
  async function uninstallEach(plugins, projectDir) {
856
913
  const host = hostAt(projectDir);
857
914
  for (const { ref, scope } of plugins) {
@@ -860,6 +917,19 @@ async function uninstallEach(plugins, projectDir) {
860
917
  });
861
918
  }
862
919
  }
920
+ async function removeNewMarketplace({ marketplace, plugins }, projectDir) {
921
+ const keepsAPluginFromIt = plugins.perhapsHeld.length > 0;
922
+ if (marketplace === null || !marketplace.newlyRegistered || keepsAPluginFromIt) return null;
923
+ try {
924
+ await hostAt(projectDir).marketplaceTakeBack.removeMarketplace(marketplace.name);
925
+ return marketplace.name;
926
+ } catch (error) {
927
+ verbose(
928
+ `Could not remove the marketplace "${marketplace.name}", which this run registered: ${getErrorMessage(error)}`
929
+ );
930
+ return null;
931
+ }
932
+ }
863
933
  function skillsRemoved({ copyResult, carriedSkillDirs }, folders) {
864
934
  const countRemoved = (dirs) => dirs.filter((dir) => folders.has(dir)).length;
865
935
  const copies = copyDestinations(copyResult).filter((dir) => !carriedSkillDirs.has(dir));
@@ -869,10 +939,17 @@ function copyDestinations(copyResult) {
869
939
  if (copyResult === null) return [];
870
940
  return [...copyResult.projectCopied, ...copyResult.globalCopied].map(({ destPath }) => destPath);
871
941
  }
872
- function linesSayingWhatWasRemoved({ copied, carried }) {
942
+ function linesSayingWhatWasTakenBack({
943
+ copied,
944
+ carried,
945
+ marketplace,
946
+ pluginsKept
947
+ }) {
873
948
  return [
874
949
  ...copied > 0 ? [copiedSkillsRemovedAfterRefusedSave(copied)] : [],
875
- ...carried > 0 ? [carriedSkillsRemovedAfterRefusedSave(carried)] : []
950
+ ...carried > 0 ? [carriedSkillsRemovedAfterRefusedSave(carried)] : [],
951
+ ...marketplace !== null ? [marketplaceRemovedAfterRefusedSave(marketplace)] : [],
952
+ ...pluginsKept.map(pluginKeptAfterRefusedSave)
876
953
  ];
877
954
  }
878
955
  function compilesGlobalScope(cwd, written) {
@@ -936,13 +1013,22 @@ function compiledAgentsBlock(projectDir, scope, agents) {
936
1013
  }
937
1014
  function splitAgentScopes(cwd, agentScopeMap) {
938
1015
  if (isHomeDirectory(cwd)) return { globalAgentCount: 0, isGlobalOnly: false };
939
- const scopes = [...agentScopeMap.values()];
1016
+ const scopes = scopesOfCompiledAgents(cwd, agentScopeMap);
940
1017
  const globalAgentCount = scopes.filter((scope) => scope === "global").length;
941
1018
  return {
942
1019
  globalAgentCount,
943
1020
  isGlobalOnly: globalAgentCount > 0 && globalAgentCount === scopes.length
944
1021
  };
945
1022
  }
1023
+ function compiledAt(cwd, name, scope) {
1024
+ return hostCompilesAgent(providerAtScope(cwd, scope), name);
1025
+ }
1026
+ function scopesOfCompiledAgents(cwd, agentScopeMap) {
1027
+ return [...agentScopeMap].filter(([name, scope]) => compiledAt(cwd, name, scope)).map(([, scope]) => scope);
1028
+ }
1029
+ function countCompiledAgents(cwd, agents) {
1030
+ return agents.filter(({ name, scope }) => compiledAt(cwd, name, scope)).length;
1031
+ }
946
1032
  function configsWritten(projectDir, paths, globalWritten) {
947
1033
  if (isHomeDirectory(projectDir)) return [paths.project];
948
1034
  return globalWritten ? [paths.global, paths.project] : [paths.project];
@@ -972,4 +1058,4 @@ export {
972
1058
  runDashboardFlow,
973
1059
  Init
974
1060
  };
975
- //# sourceMappingURL=chunk-3F5LT433.js.map
1061
+ //# sourceMappingURL=chunk-Y5VMB73R.js.map