@acryldev/workspace 0.2.1 → 0.2.3

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/lib/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { randomBytes, randomUUID } from "node:crypto";
2
- import { basename, dirname, isAbsolute, join, normalize, resolve, sep } from "node:path";
2
+ import { basename, dirname, extname, isAbsolute, join, normalize, resolve, sep } from "node:path";
3
+ import { loopbackOnly, trustedFront } from "@acryldev/blends/loopback-only";
3
4
  import { Acryl } from "@acryldev/blends";
4
5
  import { INVALID_JSON, jsonBody, ownPage, ownPageSocket, privateApi, readJson } from "@acryldev/loopback-http/router";
5
6
  import { chmod, lstat, mkdir, readFile, readdir, realpath, rename, rmdir, stat, unlink, writeFile } from "node:fs/promises";
6
7
  import { bearerAuth } from "@acryldev/blends/bearer-auth";
7
- import { loopbackOnly } from "@acryldev/blends/loopback-only";
8
8
  import { execFile, spawn } from "node:child_process";
9
9
  import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
10
10
  import z from "@deepseek-ai/schemastery";
@@ -30,13 +30,14 @@ function isRecord$5(value) {
30
30
  }
31
31
  //#endregion
32
32
  //#region src/agents/known-agents.ts
33
- const agent = (id, label, command, homepageUrl, color, yoloArgs = [], yoloEnv) => ({
33
+ const agent = (id, label, command, homepageUrl, color, yoloArgs = [], yoloEnv, installCommand) => ({
34
34
  id,
35
35
  label,
36
36
  command,
37
37
  homepageUrl,
38
38
  yoloArgs,
39
39
  ...yoloEnv === void 0 ? {} : { yoloEnv },
40
+ ...installCommand === void 0 ? {} : { installCommand },
40
41
  badge: {
41
42
  letter: [...label][0]?.toUpperCase() ?? "?",
42
43
  color
@@ -45,15 +46,15 @@ const agent = (id, label, command, homepageUrl, color, yoloArgs = [], yoloEnv) =
45
46
  /** In the order the lists show them. Ids of agents that shipped earlier keep their spelling. */
46
47
  const KNOWN_AGENTS = [
47
48
  {
48
- ...agent("claude", "Claude", "claude", "https://code.claude.com/docs", "#d97757", ["--dangerously-skip-permissions"]),
49
+ ...agent("claude", "Claude", "claude", "https://code.claude.com/docs", "#d97757", ["--dangerously-skip-permissions"], void 0, "npm i -g @anthropic-ai/claude-code"),
49
50
  statusHooks: "claude"
50
51
  },
51
- agent("codex", "Codex", "codex", "https://github.com/openai/codex", "#10a37f", ["--dangerously-bypass-approvals-and-sandbox"]),
52
+ agent("codex", "Codex", "codex", "https://github.com/openai/codex", "#10a37f", ["--dangerously-bypass-approvals-and-sandbox"], void 0, "npm i -g @openai/codex"),
52
53
  agent("grok", "Grok", "grok", "https://x.ai/cli", "#94a3b8", ["--permission-mode", "bypassPermissions"]),
53
54
  agent("copilot", "GitHub Copilot", "copilot", "https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli", "#a78bfa", ["--yolo"]),
54
55
  agent("opencode", "OpenCode", "opencode", "https://opencode.ai/docs/cli/", "#94a3b8"),
55
56
  agent("ante", "Ante", "ante", "https://github.com/AntigmaLabs/ante-preview", "#fb923c", ["--yolo"]),
56
- agent("pi", "Pi", "pi", "https://pi.dev", "#a78bfa"),
57
+ agent("pi", "Pi", "pi", "https://pi.dev", "#a78bfa", [], void 0, "npm i -g @earendil-works/pi-coding-agent"),
57
58
  agent("omp", "OMP", "omp", "https://omp.sh", "#a78bfa"),
58
59
  agent("gemini", "Gemini", "gemini", "https://github.com/google-gemini/gemini-cli", "#4285f4", ["--yolo"]),
59
60
  agent("antigravity", "Antigravity", "agy", "https://antigravity.google/docs/cli-overview", "#4285f4", ["--dangerously-skip-permissions"]),
@@ -2846,12 +2847,13 @@ function workspacePtySpawnDirs(env, platform) {
2846
2847
  */
2847
2848
  function resolveWorkspacePtyCommand(command, dirs, platform) {
2848
2849
  if (isAbsolute(command) || command.includes("/") || command.includes("\\")) return command;
2849
- const names = platform === "win32" ? [
2850
- command,
2851
- `${command}.exe`,
2852
- `${command}.cmd`,
2853
- `${command}.bat`
2854
- ] : [command];
2850
+ const runnable = [
2851
+ ".exe",
2852
+ ".cmd",
2853
+ ".bat",
2854
+ ".com"
2855
+ ];
2856
+ const names = platform !== "win32" ? [command] : runnable.includes(extname(command).toLowerCase()) ? [command] : runnable.map((ext) => `${command}${ext}`);
2855
2857
  for (const dir of dirs) for (const name of names) try {
2856
2858
  const candidate = join(dir, name);
2857
2859
  const stat = statSync(candidate);
@@ -2958,7 +2960,10 @@ var WorkspacePtyRegistry = class {
2958
2960
  let process;
2959
2961
  try {
2960
2962
  const resolved = resolveWorkspacePtyCommand(plan.command, dirs, this.platform);
2961
- if (resolved === void 0 && !plan.command.includes("/") && !plan.command.includes("\\")) throw new Error(`workspace PTY command not found in PATH: ${plan.command}`);
2963
+ if (resolved === void 0 && !plan.command.includes("/") && !plan.command.includes("\\")) {
2964
+ const install = known?.installCommand;
2965
+ throw new Error(`workspace PTY command not found in PATH: ${plan.command}${install === void 0 ? "" : ` - install it with: ${install}`}`);
2966
+ }
2962
2967
  const reporting = plan.statusHooks !== void 0 && this.agentStatus !== void 0;
2963
2968
  const shared = commandId === "shell" ? void 0 : this.launchContext?.launchFor(commandId, cwd ?? this.cwd);
2964
2969
  const args = [
@@ -3672,7 +3677,7 @@ const inject = [
3672
3677
  * @param ctx - Host context for this generation.
3673
3678
  */
3674
3679
  function apply(ctx, config = {}) {
3675
- if (ctx.acrylWeb.host !== "127.0.0.1") throw new Error("@acryldev/workspace: requires a loopback Web server");
3680
+ if (ctx.acrylWeb.host !== "127.0.0.1" && trustedFront() === void 0) throw new Error("@acryldev/workspace: requires a loopback Web server, or a hosted app with a trusted front (ACRYL_PUBLIC_ORIGIN and ACRYL_TRUSTED_PROXY)");
3676
3681
  const appPage = typeof config.appPage === "string" && config.appPage.startsWith("/") ? config.appPage : void 0;
3677
3682
  const rendererOrigin = `http://127.0.0.1:${String(ctx.acrylWeb.port)}`;
3678
3683
  const reportHostError = (operation, cause) => {