apex-code 0.0.1-alpha.5 → 0.0.1-alpha.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.js +10 -1
  4. package/dist/cli.js.map +1 -1
  5. package/dist/core/agent-session.d.ts +17 -0
  6. package/dist/core/agent-session.d.ts.map +1 -1
  7. package/dist/core/agent-session.js +46 -3
  8. package/dist/core/agent-session.js.map +1 -1
  9. package/dist/core/package-manager.d.ts.map +1 -1
  10. package/dist/core/package-manager.js +15 -0
  11. package/dist/core/package-manager.js.map +1 -1
  12. package/dist/core/permissions/gate.d.ts +7 -0
  13. package/dist/core/permissions/gate.d.ts.map +1 -1
  14. package/dist/core/permissions/gate.js.map +1 -1
  15. package/dist/core/permissions/startup.d.ts +12 -0
  16. package/dist/core/permissions/startup.d.ts.map +1 -1
  17. package/dist/core/permissions/startup.js +12 -4
  18. package/dist/core/permissions/startup.js.map +1 -1
  19. package/dist/core/sandbox/cli-launch.d.ts +43 -0
  20. package/dist/core/sandbox/cli-launch.d.ts.map +1 -1
  21. package/dist/core/sandbox/cli-launch.js +70 -3
  22. package/dist/core/sandbox/cli-launch.js.map +1 -1
  23. package/dist/core/sandbox/cli-supervisor.d.ts +2 -0
  24. package/dist/core/sandbox/cli-supervisor.d.ts.map +1 -1
  25. package/dist/core/sandbox/cli-supervisor.js +1 -0
  26. package/dist/core/sandbox/cli-supervisor.js.map +1 -1
  27. package/dist/core/skills.d.ts +19 -7
  28. package/dist/core/skills.d.ts.map +1 -1
  29. package/dist/core/skills.js +77 -19
  30. package/dist/core/skills.js.map +1 -1
  31. package/dist/core/slash-commands.d.ts.map +1 -1
  32. package/dist/core/slash-commands.js +1 -1
  33. package/dist/core/slash-commands.js.map +1 -1
  34. package/dist/core/system-prompt.d.ts.map +1 -1
  35. package/dist/core/system-prompt.js +3 -3
  36. package/dist/core/system-prompt.js.map +1 -1
  37. package/dist/core/tools/index.d.ts +5 -1
  38. package/dist/core/tools/index.d.ts.map +1 -1
  39. package/dist/core/tools/index.js +12 -0
  40. package/dist/core/tools/index.js.map +1 -1
  41. package/dist/core/tools/skill-search.d.ts +32 -0
  42. package/dist/core/tools/skill-search.d.ts.map +1 -0
  43. package/dist/core/tools/skill-search.js +56 -0
  44. package/dist/core/tools/skill-search.js.map +1 -0
  45. package/dist/main.d.ts.map +1 -1
  46. package/dist/main.js +1 -0
  47. package/dist/main.js.map +1 -1
  48. package/dist/modes/interactive/components/footer.d.ts +3 -0
  49. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  50. package/dist/modes/interactive/components/footer.js +13 -0
  51. package/dist/modes/interactive/components/footer.js.map +1 -1
  52. package/dist/modes/interactive/components/model-selector.d.ts +19 -6
  53. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  54. package/dist/modes/interactive/components/model-selector.js +172 -89
  55. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  56. package/dist/modes/interactive/components/settings-selector.d.ts +13 -0
  57. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  58. package/dist/modes/interactive/components/settings-selector.js +96 -0
  59. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  60. package/dist/modes/interactive/interactive-mode.d.ts +11 -0
  61. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  62. package/dist/modes/interactive/interactive-mode.js +64 -4
  63. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  64. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  65. package/dist/modes/rpc/rpc-mode.js +2 -1
  66. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  67. package/docs/skills.md +54 -4
  68. package/npm-shrinkwrap.json +5 -5
  69. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # Apex Code changelog
2
2
 
3
+ ## [0.0.1-alpha.7] - 2026-08-21
4
+
5
+ - The permission mode is now switchable from `/settings` instead of only at launch through
6
+ `--permission-mode`. Every mode already existed and worked; there was simply no way to
7
+ reach one from a running session, so `bypassPermissions` in particular was documented but
8
+ effectively unreachable for anyone who had already started typing. The row writes to user
9
+ scope (`~/.apex-code/agent/permissions.json`) and applies to the next tool call, because
10
+ the gate re-reads the store on every decision. Choosing `bypassPermissions` takes a
11
+ confirm step first, since the row is arrow-cyclable like every other setting and
12
+ "allow every tool call" should not be one stray keypress away. `--permission-mode`,
13
+ `.apex-code/permissions.json`, and `permissions.local.json` all still outrank a user-scope
14
+ write, so when one of them is in force the setting reports what actually applies rather
15
+ than appearing to save and doing nothing. Any mode other than `default` is now named in
16
+ the footer: `bypassPermissions` and `plan` both look like the agent misbehaving rather
17
+ than a mode being on. Shift+Tab still cycles the thinking level and is unchanged.
18
+
19
+ ## [0.0.1-alpha.6] - 2026-08-21
20
+
21
+ - Fixed skills being invisible in every sandboxed session. The OS sandbox hides the host
22
+ home directory and repoints `HOME` and the agent directory into the workspace, so the two
23
+ directories skills discover from (`~/.apex-code/agent/skills`, `~/.agents/skills`) resolved
24
+ to empty workspace paths — no user-scope skill ever loaded, silently, since the sandbox
25
+ landed. Both roots are now mounted back in, read-only, at their original host paths, the
26
+ same mechanism already used for the host-owned credential file. A root that resolves —
27
+ directly or through a symlink — onto the host home directory or an ancestor of it is refused
28
+ rather than mounted, since mounting it would re-expose the whole home tree the sandbox
29
+ deliberately hides. A skill whose name isn't a valid slash-command token (spaces, capitals —
30
+ loading stays lenient, per the Agent Skills standard's own allowance) is now invocable
31
+ through a derived command token instead of never resolving.
32
+ - The system prompt now lists skill names only, alphabetically, bounded by a fixed token
33
+ budget, instead of each skill's full description and file location inline. A real
34
+ 115-skill library cost 6,742 prefix tokens under the old shape against a 128-token margin
35
+ — unaffordable at any size, since it's the one prefix contributor sized by the user's own
36
+ data rather than the product. A new `skill_search` tool resolves a skill's description on
37
+ demand; `read` still loads its full content, unchanged. A library too large to list in full
38
+ states how many names were left out and points at `skill_search`.
39
+ - `/model` now picks in two steps: a provider first, then that provider's models. The single
40
+ flat list mixed every model from every configured provider into one scroll, so choosing one
41
+ meant reading past dozens of rows belonging to providers you weren't after. The provider
42
+ screen shows each provider's model count and marks the one the session is on. Escape steps
43
+ back to the provider list; ctrl+c still closes outright. Two cases skip the provider step,
44
+ where it would cost a keystroke and decide nothing: a single configured provider, and
45
+ `/model <search>`, which still opens straight onto matches drawn from every provider. Fuzzy
46
+ search, the all/scoped tab, and the background catalog refresh are unchanged.
47
+
3
48
  ## [0.0.1-alpha.5] - 2026-08-20
4
49
 
5
50
  - `edit` and `write` now capture bounded language-server diagnostic evidence after a
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"","sourcesContent":["#!/usr/bin/env node\nimport { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n/** The public CLI either supervises a sandbox child or starts an ordinary runtime. */\nimport { fileURLToPath } from \"node:url\";\nimport { APP_NAME, getAgentDir, getPackageDir } from \"./config.ts\";\nimport { setApexEnvironment } from \"./core/environment.ts\";\nimport { configureHttpDispatcher } from \"./core/http-dispatcher.ts\";\nimport { requiresSandboxedChild, resolveSupervisorAllowedHosts } from \"./core/sandbox/cli-launch.ts\";\nimport { launchSandboxedCli } from \"./core/sandbox/cli-supervisor.ts\";\nimport { prepareHostToolBinaries } from \"./utils/tools-manager.ts\";\n\nasync function run(): Promise<void> {\n\tconst args = process.argv.slice(2);\n\t// Validate session IDs before entering the sandbox. Invalid metadata must fail fast\n\t// without starting a child process or touching network/sandbox setup.\n\tconst sessionIdIndex = args.indexOf(\"--session-id\");\n\tconst sessionId = sessionIdIndex >= 0 ? args[sessionIdIndex + 1] : undefined;\n\tif (sessionId !== undefined && !/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/.test(sessionId)) {\n\t\tconsole.error(\n\t\t\t\"Error: Session id must be non-empty, contain only alphanumeric characters, '-', '_', and '.', and start and end with an alphanumeric character\",\n\t\t);\n\t\tprocess.exitCode = 1;\n\t\treturn;\n\t}\n\tif (requiresSandboxedChild(args)) {\n\t\tconst allowedHosts = resolveSupervisorAllowedHosts(process.cwd(), getAgentDir());\n\t\tconst authPath = join(getAgentDir(), \"auth.json\");\n\t\t// Resolve fd and rg out here, where the host home and the network are both still\n\t\t// reachable. The child's own PATH still names host directories the sandbox has\n\t\t// replaced, so without this projection it finds nothing and cannot download either.\n\t\t// Silent because this runs ahead of every mode, including --print and --mode rpc,\n\t\t// whose stdout carries machine-readable output; the child still reports a genuinely\n\t\t// missing tool through its own startup path.\n\t\tconst toolBinaries = await prepareHostToolBinaries(true);\n\n\t\tprocess.exitCode = await launchSandboxedCli({\n\t\t\tcommand: process.execPath,\n\t\t\targs: [\n\t\t\t\tfileURLToPath(\n\t\t\t\t\tnew URL(`./core/sandbox/child-entry${import.meta.url.endsWith(\".ts\") ? \".ts\" : \".js\"}`, import.meta.url),\n\t\t\t\t),\n\t\t\t\t...args,\n\t\t\t],\n\t\t\tenvironment: process.env,\n\t\t\tworkspace: process.cwd(),\n\t\t\tallowedHosts,\n\t\t\tauthPath: existsSync(authPath) ? authPath : undefined,\n\t\t\treadOnlyPaths: [getPackageDir(), dirname(getPackageDir())],\n\t\t\ttoolBinaries,\n\t\t});\n\t\treturn;\n\t}\n\n\tprocess.title = APP_NAME;\n\tsetApexEnvironment(\"APEX_CODE_CODING_AGENT\", \"true\");\n\tprocess.env.AI_AGENT = \"apex-code\";\n\tprocess.emitWarning = (() => {}) as typeof process.emitWarning;\n\tconfigureHttpDispatcher();\n\tconst { main } = await import(\"./main.ts\");\n\tawait main(args);\n}\n\nawait run();\n"]}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"","sourcesContent":["#!/usr/bin/env node\nimport { existsSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n/** The public CLI either supervises a sandbox child or starts an ordinary runtime. */\nimport { fileURLToPath } from \"node:url\";\nimport { APP_NAME, getAgentDir, getPackageDir } from \"./config.ts\";\nimport { setApexEnvironment } from \"./core/environment.ts\";\nimport { configureHttpDispatcher } from \"./core/http-dispatcher.ts\";\nimport {\n\trequiresSandboxedChild,\n\tresolveHostSkillPaths,\n\tresolveSupervisorAllowedHosts,\n} from \"./core/sandbox/cli-launch.ts\";\nimport { launchSandboxedCli } from \"./core/sandbox/cli-supervisor.ts\";\nimport { prepareHostToolBinaries } from \"./utils/tools-manager.ts\";\n\nasync function run(): Promise<void> {\n\tconst args = process.argv.slice(2);\n\t// Validate session IDs before entering the sandbox. Invalid metadata must fail fast\n\t// without starting a child process or touching network/sandbox setup.\n\tconst sessionIdIndex = args.indexOf(\"--session-id\");\n\tconst sessionId = sessionIdIndex >= 0 ? args[sessionIdIndex + 1] : undefined;\n\tif (sessionId !== undefined && !/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/.test(sessionId)) {\n\t\tconsole.error(\n\t\t\t\"Error: Session id must be non-empty, contain only alphanumeric characters, '-', '_', and '.', and start and end with an alphanumeric character\",\n\t\t);\n\t\tprocess.exitCode = 1;\n\t\treturn;\n\t}\n\tif (requiresSandboxedChild(args)) {\n\t\tconst allowedHosts = resolveSupervisorAllowedHosts(process.cwd(), getAgentDir());\n\t\tconst authPath = join(getAgentDir(), \"auth.json\");\n\t\t// Resolve fd and rg out here, where the host home and the network are both still\n\t\t// reachable. The child's own PATH still names host directories the sandbox has\n\t\t// replaced, so without this projection it finds nothing and cannot download either.\n\t\t// Silent because this runs ahead of every mode, including --print and --mode rpc,\n\t\t// whose stdout carries machine-readable output; the child still reports a genuinely\n\t\t// missing tool through its own startup path.\n\t\tconst toolBinaries = await prepareHostToolBinaries(true);\n\t\t// Resolved here, where the host home is still reachable -- exactly like the\n\t\t// tool binaries above and unlike anything sourced from project files, which\n\t\t// ADR 0016 forbids as supervisor input before trust is established.\n\t\tconst { paths: skillPaths, refusals: skillPathRefusals } = resolveHostSkillPaths(\n\t\t\tgetAgentDir(),\n\t\t\tprocess.env.HOME || homedir(),\n\t\t);\n\t\tfor (const refusal of skillPathRefusals) {\n\t\t\tprocess.stderr.write(`Warning: not mounting skill directory ${refusal.path}: ${refusal.reason}\\n`);\n\t\t}\n\n\t\tprocess.exitCode = await launchSandboxedCli({\n\t\t\tcommand: process.execPath,\n\t\t\targs: [\n\t\t\t\tfileURLToPath(\n\t\t\t\t\tnew URL(`./core/sandbox/child-entry${import.meta.url.endsWith(\".ts\") ? \".ts\" : \".js\"}`, import.meta.url),\n\t\t\t\t),\n\t\t\t\t...args,\n\t\t\t],\n\t\t\tenvironment: process.env,\n\t\t\tworkspace: process.cwd(),\n\t\t\tallowedHosts,\n\t\t\tauthPath: existsSync(authPath) ? authPath : undefined,\n\t\t\treadOnlyPaths: [getPackageDir(), dirname(getPackageDir())],\n\t\t\ttoolBinaries,\n\t\t\tskillPaths,\n\t\t});\n\t\treturn;\n\t}\n\n\tprocess.title = APP_NAME;\n\tsetApexEnvironment(\"APEX_CODE_CODING_AGENT\", \"true\");\n\tprocess.env.AI_AGENT = \"apex-code\";\n\tprocess.emitWarning = (() => {}) as typeof process.emitWarning;\n\tconfigureHttpDispatcher();\n\tconst { main } = await import(\"./main.ts\");\n\tawait main(args);\n}\n\nawait run();\n"]}
package/dist/cli.js CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync } from "node:fs";
3
+ import { homedir } from "node:os";
3
4
  import { dirname, join } from "node:path";
4
5
  /** The public CLI either supervises a sandbox child or starts an ordinary runtime. */
5
6
  import { fileURLToPath } from "node:url";
6
7
  import { APP_NAME, getAgentDir, getPackageDir } from "./config.js";
7
8
  import { setApexEnvironment } from "./core/environment.js";
8
9
  import { configureHttpDispatcher } from "./core/http-dispatcher.js";
9
- import { requiresSandboxedChild, resolveSupervisorAllowedHosts } from "./core/sandbox/cli-launch.js";
10
+ import { requiresSandboxedChild, resolveHostSkillPaths, resolveSupervisorAllowedHosts, } from "./core/sandbox/cli-launch.js";
10
11
  import { launchSandboxedCli } from "./core/sandbox/cli-supervisor.js";
11
12
  import { prepareHostToolBinaries } from "./utils/tools-manager.js";
12
13
  async function run() {
@@ -30,6 +31,13 @@ async function run() {
30
31
  // whose stdout carries machine-readable output; the child still reports a genuinely
31
32
  // missing tool through its own startup path.
32
33
  const toolBinaries = await prepareHostToolBinaries(true);
34
+ // Resolved here, where the host home is still reachable -- exactly like the
35
+ // tool binaries above and unlike anything sourced from project files, which
36
+ // ADR 0016 forbids as supervisor input before trust is established.
37
+ const { paths: skillPaths, refusals: skillPathRefusals } = resolveHostSkillPaths(getAgentDir(), process.env.HOME || homedir());
38
+ for (const refusal of skillPathRefusals) {
39
+ process.stderr.write(`Warning: not mounting skill directory ${refusal.path}: ${refusal.reason}\n`);
40
+ }
33
41
  process.exitCode = await launchSandboxedCli({
34
42
  command: process.execPath,
35
43
  args: [
@@ -42,6 +50,7 @@ async function run() {
42
50
  authPath: existsSync(authPath) ? authPath : undefined,
43
51
  readOnlyPaths: [getPackageDir(), dirname(getPackageDir())],
44
52
  toolBinaries,
53
+ skillPaths,
45
54
  });
46
55
  return;
47
56
  }
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,sFAAsF;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA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,CAAC,6BAA6B,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CACxG;gBACD,GAAG,IAAI;aACP;YACD,WAAW,EAAE,OAAO,CAAC,GAAG;YACxB,SAAS,EAAE,OAAO,CAAC,GAAG,EAAE;YACxB,YAAY;YACZ,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YACrD,aAAa,EAAE,CAAC,aAAa,EAAE,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;YAC1D,YAAY;SACZ,CAAC,CAAC;QACH,OAAO;IACR,CAAC;IAED,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;IACzB,kBAAkB,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,WAAW,CAAC;IACnC,OAAO,CAAC,WAAW,GAAG,CAAC,GAAG,EAAE,CAAC,EAAC,CAAC,CAA+B,CAAC;IAC/D,uBAAuB,EAAE,CAAC;IAC1B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACjB;AAED,MAAM,GAAG,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n/** The public CLI either supervises a sandbox child or starts an ordinary runtime. */\nimport { fileURLToPath } from \"node:url\";\nimport { APP_NAME, getAgentDir, getPackageDir } from \"./config.ts\";\nimport { setApexEnvironment } from \"./core/environment.ts\";\nimport { configureHttpDispatcher } from \"./core/http-dispatcher.ts\";\nimport { requiresSandboxedChild, resolveSupervisorAllowedHosts } from \"./core/sandbox/cli-launch.ts\";\nimport { launchSandboxedCli } from \"./core/sandbox/cli-supervisor.ts\";\nimport { prepareHostToolBinaries } from \"./utils/tools-manager.ts\";\n\nasync function run(): Promise<void> {\n\tconst args = process.argv.slice(2);\n\t// Validate session IDs before entering the sandbox. Invalid metadata must fail fast\n\t// without starting a child process or touching network/sandbox setup.\n\tconst sessionIdIndex = args.indexOf(\"--session-id\");\n\tconst sessionId = sessionIdIndex >= 0 ? args[sessionIdIndex + 1] : undefined;\n\tif (sessionId !== undefined && !/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/.test(sessionId)) {\n\t\tconsole.error(\n\t\t\t\"Error: Session id must be non-empty, contain only alphanumeric characters, '-', '_', and '.', and start and end with an alphanumeric character\",\n\t\t);\n\t\tprocess.exitCode = 1;\n\t\treturn;\n\t}\n\tif (requiresSandboxedChild(args)) {\n\t\tconst allowedHosts = resolveSupervisorAllowedHosts(process.cwd(), getAgentDir());\n\t\tconst authPath = join(getAgentDir(), \"auth.json\");\n\t\t// Resolve fd and rg out here, where the host home and the network are both still\n\t\t// reachable. The child's own PATH still names host directories the sandbox has\n\t\t// replaced, so without this projection it finds nothing and cannot download either.\n\t\t// Silent because this runs ahead of every mode, including --print and --mode rpc,\n\t\t// whose stdout carries machine-readable output; the child still reports a genuinely\n\t\t// missing tool through its own startup path.\n\t\tconst toolBinaries = await prepareHostToolBinaries(true);\n\n\t\tprocess.exitCode = await launchSandboxedCli({\n\t\t\tcommand: process.execPath,\n\t\t\targs: [\n\t\t\t\tfileURLToPath(\n\t\t\t\t\tnew URL(`./core/sandbox/child-entry${import.meta.url.endsWith(\".ts\") ? \".ts\" : \".js\"}`, import.meta.url),\n\t\t\t\t),\n\t\t\t\t...args,\n\t\t\t],\n\t\t\tenvironment: process.env,\n\t\t\tworkspace: process.cwd(),\n\t\t\tallowedHosts,\n\t\t\tauthPath: existsSync(authPath) ? authPath : undefined,\n\t\t\treadOnlyPaths: [getPackageDir(), dirname(getPackageDir())],\n\t\t\ttoolBinaries,\n\t\t});\n\t\treturn;\n\t}\n\n\tprocess.title = APP_NAME;\n\tsetApexEnvironment(\"APEX_CODE_CODING_AGENT\", \"true\");\n\tprocess.env.AI_AGENT = \"apex-code\";\n\tprocess.emitWarning = (() => {}) as typeof process.emitWarning;\n\tconfigureHttpDispatcher();\n\tconst { main } = await import(\"./main.ts\");\n\tawait main(args);\n}\n\nawait run();\n"]}
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,sFAAsF;AACtF,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACN,sBAAsB,EACtB,qBAAqB,EACrB,6BAA6B,GAC7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,KAAK,UAAU,GAAG,GAAkB;IACnC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,oFAAoF;IACpF,sEAAsE;IACtE,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,cAAc,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,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,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CACxG;gBACD,GAAG,IAAI;aACP;YACD,WAAW,EAAE,OAAO,CAAC,GAAG;YACxB,SAAS,EAAE,OAAO,CAAC,GAAG,EAAE;YACxB,YAAY;YACZ,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YACrD,aAAa,EAAE,CAAC,aAAa,EAAE,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;YAC1D,YAAY;YACZ,UAAU;SACV,CAAC,CAAC;QACH,OAAO;IACR,CAAC;IAED,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;IACzB,kBAAkB,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;IACrD,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,WAAW,CAAC;IACnC,OAAO,CAAC,WAAW,GAAG,CAAC,GAAG,EAAE,CAAC,EAAC,CAAC,CAA+B,CAAC;IAC/D,uBAAuB,EAAE,CAAC;IAC1B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;IAC3C,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACjB;AAED,MAAM,GAAG,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { existsSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n/** The public CLI either supervises a sandbox child or starts an ordinary runtime. */\nimport { fileURLToPath } from \"node:url\";\nimport { APP_NAME, getAgentDir, getPackageDir } from \"./config.ts\";\nimport { setApexEnvironment } from \"./core/environment.ts\";\nimport { configureHttpDispatcher } from \"./core/http-dispatcher.ts\";\nimport {\n\trequiresSandboxedChild,\n\tresolveHostSkillPaths,\n\tresolveSupervisorAllowedHosts,\n} from \"./core/sandbox/cli-launch.ts\";\nimport { launchSandboxedCli } from \"./core/sandbox/cli-supervisor.ts\";\nimport { prepareHostToolBinaries } from \"./utils/tools-manager.ts\";\n\nasync function run(): Promise<void> {\n\tconst args = process.argv.slice(2);\n\t// Validate session IDs before entering the sandbox. Invalid metadata must fail fast\n\t// without starting a child process or touching network/sandbox setup.\n\tconst sessionIdIndex = args.indexOf(\"--session-id\");\n\tconst sessionId = sessionIdIndex >= 0 ? args[sessionIdIndex + 1] : undefined;\n\tif (sessionId !== undefined && !/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/.test(sessionId)) {\n\t\tconsole.error(\n\t\t\t\"Error: Session id must be non-empty, contain only alphanumeric characters, '-', '_', and '.', and start and end with an alphanumeric character\",\n\t\t);\n\t\tprocess.exitCode = 1;\n\t\treturn;\n\t}\n\tif (requiresSandboxedChild(args)) {\n\t\tconst allowedHosts = resolveSupervisorAllowedHosts(process.cwd(), getAgentDir());\n\t\tconst authPath = join(getAgentDir(), \"auth.json\");\n\t\t// Resolve fd and rg out here, where the host home and the network are both still\n\t\t// reachable. The child's own PATH still names host directories the sandbox has\n\t\t// replaced, so without this projection it finds nothing and cannot download either.\n\t\t// Silent because this runs ahead of every mode, including --print and --mode rpc,\n\t\t// whose stdout carries machine-readable output; the child still reports a genuinely\n\t\t// missing tool through its own startup path.\n\t\tconst toolBinaries = await prepareHostToolBinaries(true);\n\t\t// Resolved here, where the host home is still reachable -- exactly like the\n\t\t// tool binaries above and unlike anything sourced from project files, which\n\t\t// ADR 0016 forbids as supervisor input before trust is established.\n\t\tconst { paths: skillPaths, refusals: skillPathRefusals } = resolveHostSkillPaths(\n\t\t\tgetAgentDir(),\n\t\t\tprocess.env.HOME || homedir(),\n\t\t);\n\t\tfor (const refusal of skillPathRefusals) {\n\t\t\tprocess.stderr.write(`Warning: not mounting skill directory ${refusal.path}: ${refusal.reason}\\n`);\n\t\t}\n\n\t\tprocess.exitCode = await launchSandboxedCli({\n\t\t\tcommand: process.execPath,\n\t\t\targs: [\n\t\t\t\tfileURLToPath(\n\t\t\t\t\tnew URL(`./core/sandbox/child-entry${import.meta.url.endsWith(\".ts\") ? \".ts\" : \".js\"}`, import.meta.url),\n\t\t\t\t),\n\t\t\t\t...args,\n\t\t\t],\n\t\t\tenvironment: process.env,\n\t\t\tworkspace: process.cwd(),\n\t\t\tallowedHosts,\n\t\t\tauthPath: existsSync(authPath) ? authPath : undefined,\n\t\t\treadOnlyPaths: [getPackageDir(), dirname(getPackageDir())],\n\t\t\ttoolBinaries,\n\t\t\tskillPaths,\n\t\t});\n\t\treturn;\n\t}\n\n\tprocess.title = APP_NAME;\n\tsetApexEnvironment(\"APEX_CODE_CODING_AGENT\", \"true\");\n\tprocess.env.AI_AGENT = \"apex-code\";\n\tprocess.emitWarning = (() => {}) as typeof process.emitWarning;\n\tconfigureHttpDispatcher();\n\tconst { main } = await import(\"./main.ts\");\n\tawait main(args);\n}\n\nawait run();\n"]}
@@ -20,6 +20,8 @@ import { type ContextUsage, type ExtensionCommandContextActions, type ExtensionE
20
20
  import type { CustomMessage } from "./messages.ts";
21
21
  import type { ModelRuntime } from "./model-runtime.ts";
22
22
  import { type PermissionGateOptions } from "./permissions/gate.ts";
23
+ import { type EffectiveModeResolution } from "./permissions/startup.ts";
24
+ import type { PermissionMode } from "./permissions/store.ts";
23
25
  import { type PromptTemplate } from "./prompt-templates.ts";
24
26
  import type { ResourceLoader } from "./resource-loader.ts";
25
27
  import type { BranchSummaryEntry, SessionEntry, SessionManager } from "./session-manager.ts";
@@ -494,6 +496,21 @@ export declare class AgentSession {
494
496
  abort(): Promise<void>;
495
497
  waitForIdle(): Promise<void>;
496
498
  private _emitModelSelect;
499
+ /** True when this session runs behind a permission gate at all. */
500
+ get hasPermissionGate(): boolean;
501
+ /**
502
+ * The mode in force right now, and which source won. `getMode` in the gate
503
+ * config re-reads the store on every decision, so a mode written here applies
504
+ * to the next tool call with no restart.
505
+ */
506
+ getPermissionMode(): Promise<EffectiveModeResolution | undefined>;
507
+ /**
508
+ * Persist a permission mode to user scope (`~/.apex-code/agent/permissions.json`).
509
+ * Returns the resolution that is actually in force afterwards, which is *not*
510
+ * necessarily `mode`: `flag`, `local`, and `project` all outrank `user`, so the
511
+ * caller has to be able to tell the user their choice was recorded but shadowed.
512
+ */
513
+ setPermissionMode(mode: PermissionMode): Promise<EffectiveModeResolution | undefined>;
497
514
  /**
498
515
  * Set model directly.
499
516
  * Validates that auth is configured, saves to session and settings.