kly 0.1.1 → 0.2.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.
package/dist/bin/kly.mjs CHANGED
@@ -950,9 +950,10 @@ function createResourceProvider(options) {
950
950
  * 4. Returns execution result
951
951
  */
952
952
  async function launchSandbox(options) {
953
- const { scriptPath, args: args$1, appId, sandboxConfig, allowApiKey } = options;
953
+ const { scriptPath, args: args$1, appId, invokeDir, sandboxConfig, allowApiKey } = options;
954
954
  await SandboxManager.initialize(sandboxConfig);
955
955
  const absoluteScriptPath = resolve(process.cwd(), scriptPath);
956
+ const _scriptDir = absoluteScriptPath.substring(0, absoluteScriptPath.lastIndexOf("/"));
956
957
  const executorPath = resolve(__dirname, "../sandbox/bundled-executor.mjs");
957
958
  if (!SandboxManager.isSandboxingEnabled()) {
958
959
  console.warn("⚠️ Sandboxing is not supported on this platform.");
@@ -973,6 +974,7 @@ async function launchSandbox(options) {
973
974
  "inherit",
974
975
  "ipc"
975
976
  ],
977
+ cwd: _scriptDir,
976
978
  env: {
977
979
  ...process.env,
978
980
  KLY_SANDBOX_MODE: "true"
@@ -994,6 +996,7 @@ async function launchSandbox(options) {
994
996
  scriptPath: absoluteScriptPath,
995
997
  args: args$1,
996
998
  appId,
999
+ invokeDir,
997
1000
  permissions: {
998
1001
  allowApiKey,
999
1002
  sandboxConfig
@@ -1843,12 +1846,14 @@ async function clearAllPermissionsAction() {
1843
1846
  */
1844
1847
  const PROTECTED_PATHS = {
1845
1848
  alwaysDenyWrite: [
1846
- join(homedir(), ".kly"),
1849
+ join(homedir(), ".kly/config"),
1850
+ join(homedir(), ".kly/permissions.json"),
1851
+ join(homedir(), ".kly/kly.sum"),
1847
1852
  join(homedir(), ".ssh"),
1848
1853
  join(homedir(), ".aws"),
1849
1854
  join(homedir(), ".gnupg")
1850
1855
  ],
1851
- alwaysDenyRead: [join(homedir(), ".kly")]
1856
+ alwaysDenyRead: [join(homedir(), ".kly/config"), join(homedir(), ".kly/permissions.json")]
1852
1857
  };
1853
1858
  /**
1854
1859
  * Resolve filesystem path with special marker support
@@ -1909,7 +1914,8 @@ function buildSandboxConfig(permissions) {
1909
1914
  denyRead,
1910
1915
  allowWrite,
1911
1916
  denyWrite: PROTECTED_PATHS.alwaysDenyWrite
1912
- }
1917
+ },
1918
+ allowPty: true
1913
1919
  };
1914
1920
  }
1915
1921
  /**
@@ -2348,9 +2354,13 @@ const ENTRY_CANDIDATES = [
2348
2354
  ];
2349
2355
  /**
2350
2356
  * Resolve entry point for a kly app
2351
- * Priority: main field > convention candidates
2357
+ * Priority: convention candidates > main field
2358
+ *
2359
+ * We prioritize convention-based source files over package.json main field
2360
+ * because remote apps are run from source, not from built artifacts.
2352
2361
  */
2353
2362
  function resolveEntryPoint(repoPath) {
2363
+ for (const candidate of ENTRY_CANDIDATES) if (existsSync(join(repoPath, candidate))) return candidate;
2354
2364
  const pkgPath = join(repoPath, "package.json");
2355
2365
  if (existsSync(pkgPath)) try {
2356
2366
  const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
@@ -2358,7 +2368,6 @@ function resolveEntryPoint(repoPath) {
2358
2368
  if (existsSync(join(repoPath, pkg.main))) return pkg.main;
2359
2369
  }
2360
2370
  } catch {}
2361
- for (const candidate of ENTRY_CANDIDATES) if (existsSync(join(repoPath, candidate))) return candidate;
2362
2371
  return null;
2363
2372
  }
2364
2373
  /**
@@ -2764,6 +2773,7 @@ async function executeApp(ref, repoPath, args$1, mcp) {
2764
2773
  process.exit(1);
2765
2774
  }
2766
2775
  }
2776
+ if (!sandboxConfig.filesystem.allowWrite.includes(repoPath)) sandboxConfig.filesystem.allowWrite.push(repoPath);
2767
2777
  if (mcp) {
2768
2778
  console.warn("⚠️ MCP mode with remote repos not yet fully supported in new architecture");
2769
2779
  process.env[ENV_VARS.MCP_MODE] = "true";
@@ -2775,6 +2785,7 @@ async function executeApp(ref, repoPath, args$1, mcp) {
2775
2785
  scriptPath: absoluteEntryPath,
2776
2786
  args: args$1,
2777
2787
  appId,
2788
+ invokeDir: process.cwd(),
2778
2789
  sandboxConfig,
2779
2790
  allowApiKey
2780
2791
  });
@@ -2846,6 +2857,7 @@ async function main() {
2846
2857
  }
2847
2858
  async function runFile(filePath, appArgs) {
2848
2859
  const absolutePath = resolve(process.cwd(), filePath);
2860
+ const invokeDir = process.cwd();
2849
2861
  const prevLocalRef = process.env.KLY_LOCAL_REF;
2850
2862
  process.env.KLY_LOCAL_REF = `local:${absolutePath}`;
2851
2863
  try {
@@ -2870,6 +2882,7 @@ async function runFile(filePath, appArgs) {
2870
2882
  scriptPath: absolutePath,
2871
2883
  args: appArgs,
2872
2884
  appId,
2885
+ invokeDir,
2873
2886
  sandboxConfig,
2874
2887
  allowApiKey
2875
2888
  });