@hmawla/co-assistant 1.0.5 → 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
@@ -1691,8 +1691,55 @@ function createPluginRegistry(pluginsDir) {
1691
1691
  // src/plugins/manager.ts
1692
1692
  init_logger();
1693
1693
  import path3 from "path";
1694
- import { existsSync as existsSync4 } from "fs";
1695
- import { register } from "tsx/esm/api";
1694
+ import { existsSync as existsSync4, statSync as statSync2 } from "fs";
1695
+ import { fileURLToPath, pathToFileURL } from "url";
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
+ }
1709
+ async function compilePlugin(tsEntryPath) {
1710
+ const outfile = tsEntryPath.replace(/\.ts$/, ".compiled.mjs");
1711
+ const pluginDir = path3.dirname(tsEntryPath);
1712
+ if (existsSync4(outfile)) {
1713
+ try {
1714
+ const compiledMtime = statSync2(outfile).mtimeMs;
1715
+ const dirMtime = statSync2(pluginDir).mtimeMs;
1716
+ if (compiledMtime >= dirMtime) {
1717
+ pluginLogger.debug({ outfile }, "Using cached compiled plugin");
1718
+ return outfile;
1719
+ }
1720
+ } catch {
1721
+ }
1722
+ }
1723
+ pluginLogger.debug({ tsEntryPath, outfile }, "Compiling plugin with esbuild");
1724
+ const pkgNodeModules = findNodeModules();
1725
+ const esbuild = await import("esbuild");
1726
+ await esbuild.build({
1727
+ entryPoints: [tsEntryPath],
1728
+ bundle: true,
1729
+ format: "esm",
1730
+ platform: "node",
1731
+ target: "node20",
1732
+ outfile,
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] : [],
1738
+ logLevel: "warning"
1739
+ });
1740
+ pluginLogger.debug({ outfile }, "Plugin compiled successfully");
1741
+ return outfile;
1742
+ }
1696
1743
  var PluginManager = class {
1697
1744
  constructor(registry, sandbox, credentials, stateRepo) {
1698
1745
  this.registry = registry;
@@ -1792,12 +1839,8 @@ var PluginManager = class {
1792
1839
  let mod;
1793
1840
  try {
1794
1841
  if (pluginPath.endsWith(".ts")) {
1795
- const unregister = register();
1796
- try {
1797
- mod = await import(pluginPath);
1798
- } finally {
1799
- unregister();
1800
- }
1842
+ const compiledPath = await compilePlugin(pluginPath);
1843
+ mod = await import(pathToFileURL(compiledPath).href);
1801
1844
  } else {
1802
1845
  mod = await import(pluginPath);
1803
1846
  }
@@ -1817,15 +1860,15 @@ var PluginManager = class {
1817
1860
  }
1818
1861
  const plugin = factory();
1819
1862
  const context = this.buildPluginContext(pluginId, creds);
1820
- const initResult = await this.sandbox.safeExecute(
1863
+ await this.sandbox.safeExecute(
1821
1864
  pluginId,
1822
1865
  "initialize",
1823
1866
  () => plugin.initialize(context)
1824
1867
  );
1825
- if (initResult === void 0 && manifest.requiredCredentials.length > 0) {
1868
+ if (this.sandbox.getFailureCount(pluginId) > 0) {
1826
1869
  this.logger.warn(
1827
1870
  { pluginId },
1828
- `Plugin "${pluginId}" initialize() did not succeed \u2014 marking as error`
1871
+ `Plugin "${pluginId}" initialize() failed \u2014 check credentials and plugin health`
1829
1872
  );
1830
1873
  }
1831
1874
  this.plugins.set(pluginId, plugin);
@@ -3988,9 +4031,9 @@ import {
3988
4031
  cpSync
3989
4032
  } from "fs";
3990
4033
  import path4 from "path";
3991
- import { fileURLToPath } from "url";
4034
+ import { fileURLToPath as fileURLToPath2 } from "url";
3992
4035
  function getPackagePluginsDir() {
3993
- const thisFile = fileURLToPath(import.meta.url);
4036
+ const thisFile = fileURLToPath2(import.meta.url);
3994
4037
  const pkgRoot = path4.resolve(path4.dirname(thisFile), "..", "..", "..");
3995
4038
  const pluginsDir = path4.join(pkgRoot, "plugins");
3996
4039
  if (!existsSync7(pluginsDir)) {
@@ -4289,7 +4332,10 @@ async function handleInstall(pluginId, options) {
4289
4332
  skipped++;
4290
4333
  continue;
4291
4334
  }
4292
- cpSync(plugin.sourcePath, destDir, { recursive: true });
4335
+ cpSync(plugin.sourcePath, destDir, {
4336
+ recursive: true,
4337
+ filter: (src) => !src.endsWith(".compiled.mjs")
4338
+ });
4293
4339
  console.log(` \u2705 ${plugin.id} \u2014 installed to plugins/${plugin.id}/`);
4294
4340
  installed++;
4295
4341
  }