@hmawla/co-assistant 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/index.js CHANGED
@@ -1692,8 +1692,20 @@ function createPluginRegistry(pluginsDir) {
1692
1692
  init_logger();
1693
1693
  import path3 from "path";
1694
1694
  import { existsSync as existsSync4, statSync as statSync2 } from "fs";
1695
- import { pathToFileURL } from "url";
1695
+ import { fileURLToPath, pathToFileURL } from "url";
1696
1696
  var pluginLogger = createChildLogger("plugins:manager");
1697
+ function findNodeModules() {
1698
+ const thisFile = fileURLToPath(import.meta.url);
1699
+ let dir = path3.dirname(thisFile);
1700
+ for (let i = 0; i < 10; i++) {
1701
+ const candidate = path3.join(dir, "node_modules");
1702
+ if (existsSync4(candidate)) return candidate;
1703
+ const parent = path3.dirname(dir);
1704
+ if (parent === dir) break;
1705
+ dir = parent;
1706
+ }
1707
+ return null;
1708
+ }
1697
1709
  async function compilePlugin(tsEntryPath) {
1698
1710
  const outfile = tsEntryPath.replace(/\.ts$/, ".compiled.mjs");
1699
1711
  const pluginDir = path3.dirname(tsEntryPath);
@@ -1709,6 +1721,7 @@ async function compilePlugin(tsEntryPath) {
1709
1721
  }
1710
1722
  }
1711
1723
  pluginLogger.debug({ tsEntryPath, outfile }, "Compiling plugin with esbuild");
1724
+ const pkgNodeModules = findNodeModules();
1712
1725
  const esbuild = await import("esbuild");
1713
1726
  await esbuild.build({
1714
1727
  entryPoints: [tsEntryPath],
@@ -1717,9 +1730,11 @@ async function compilePlugin(tsEntryPath) {
1717
1730
  platform: "node",
1718
1731
  target: "node20",
1719
1732
  outfile,
1720
- // Externalize all bare-specifier packages (node_modules) but bundle
1721
- // local relative imports (./auth.js ./auth.ts, ./tools.js, etc.)
1722
- packages: "external",
1733
+ // Bundle EVERYTHING including node_modules packages — so the
1734
+ // compiled plugin is fully self-contained and works regardless of
1735
+ // which directory the user runs co-assistant from.
1736
+ // esbuild's nodePaths lets us find the package's own deps.
1737
+ nodePaths: pkgNodeModules ? [pkgNodeModules] : [],
1723
1738
  logLevel: "warning"
1724
1739
  });
1725
1740
  pluginLogger.debug({ outfile }, "Plugin compiled successfully");
@@ -1845,15 +1860,15 @@ var PluginManager = class {
1845
1860
  }
1846
1861
  const plugin = factory();
1847
1862
  const context = this.buildPluginContext(pluginId, creds);
1848
- const initResult = await this.sandbox.safeExecute(
1863
+ await this.sandbox.safeExecute(
1849
1864
  pluginId,
1850
1865
  "initialize",
1851
1866
  () => plugin.initialize(context)
1852
1867
  );
1853
- if (initResult === void 0 && manifest.requiredCredentials.length > 0) {
1868
+ if (this.sandbox.getFailureCount(pluginId) > 0) {
1854
1869
  this.logger.warn(
1855
1870
  { pluginId },
1856
- `Plugin "${pluginId}" initialize() did not succeed \u2014 marking as error`
1871
+ `Plugin "${pluginId}" initialize() failed \u2014 check credentials and plugin health`
1857
1872
  );
1858
1873
  }
1859
1874
  this.plugins.set(pluginId, plugin);
@@ -4016,9 +4031,9 @@ import {
4016
4031
  cpSync
4017
4032
  } from "fs";
4018
4033
  import path4 from "path";
4019
- import { fileURLToPath } from "url";
4034
+ import { fileURLToPath as fileURLToPath2 } from "url";
4020
4035
  function getPackagePluginsDir() {
4021
- const thisFile = fileURLToPath(import.meta.url);
4036
+ const thisFile = fileURLToPath2(import.meta.url);
4022
4037
  const pkgRoot = path4.resolve(path4.dirname(thisFile), "..", "..", "..");
4023
4038
  const pluginsDir = path4.join(pkgRoot, "plugins");
4024
4039
  if (!existsSync7(pluginsDir)) {
@@ -4317,7 +4332,10 @@ async function handleInstall(pluginId, options) {
4317
4332
  skipped++;
4318
4333
  continue;
4319
4334
  }
4320
- cpSync(plugin.sourcePath, destDir, { recursive: true });
4335
+ cpSync(plugin.sourcePath, destDir, {
4336
+ recursive: true,
4337
+ filter: (src) => !src.endsWith(".compiled.mjs")
4338
+ });
4321
4339
  console.log(` \u2705 ${plugin.id} \u2014 installed to plugins/${plugin.id}/`);
4322
4340
  installed++;
4323
4341
  }