gsd-pi 2.37.1-dev.d3ace49 → 2.38.0-dev.29edcdc

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 (188) hide show
  1. package/dist/app-paths.js +1 -1
  2. package/dist/cli.js +9 -0
  3. package/dist/extension-discovery.d.ts +5 -3
  4. package/dist/extension-discovery.js +14 -9
  5. package/dist/extension-registry.js +2 -2
  6. package/dist/remote-questions-config.js +2 -2
  7. package/dist/resource-loader.js +34 -1
  8. package/dist/resources/extensions/browser-tools/package.json +3 -1
  9. package/dist/resources/extensions/cmux/index.js +55 -1
  10. package/dist/resources/extensions/context7/package.json +1 -1
  11. package/dist/resources/extensions/env-utils.js +29 -0
  12. package/dist/resources/extensions/get-secrets-from-user.js +5 -24
  13. package/dist/resources/extensions/github-sync/cli.js +284 -0
  14. package/dist/resources/extensions/github-sync/index.js +73 -0
  15. package/dist/resources/extensions/github-sync/mapping.js +67 -0
  16. package/dist/resources/extensions/github-sync/sync.js +424 -0
  17. package/dist/resources/extensions/github-sync/templates.js +118 -0
  18. package/dist/resources/extensions/github-sync/types.js +7 -0
  19. package/dist/resources/extensions/google-search/package.json +3 -1
  20. package/dist/resources/extensions/gsd/auto/session.js +6 -23
  21. package/dist/resources/extensions/gsd/auto-dispatch.js +8 -9
  22. package/dist/resources/extensions/gsd/auto-loop.js +597 -588
  23. package/dist/resources/extensions/gsd/auto-post-unit.js +99 -70
  24. package/dist/resources/extensions/gsd/auto-prompts.js +23 -43
  25. package/dist/resources/extensions/gsd/auto-start.js +13 -2
  26. package/dist/resources/extensions/gsd/auto-worktree-sync.js +13 -5
  27. package/dist/resources/extensions/gsd/auto-worktree.js +3 -3
  28. package/dist/resources/extensions/gsd/auto.js +143 -96
  29. package/dist/resources/extensions/gsd/captures.js +9 -1
  30. package/dist/resources/extensions/gsd/commands-extensions.js +3 -2
  31. package/dist/resources/extensions/gsd/commands-handlers.js +16 -3
  32. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +1 -1
  33. package/dist/resources/extensions/gsd/commands.js +24 -3
  34. package/dist/resources/extensions/gsd/context-budget.js +2 -10
  35. package/dist/resources/extensions/gsd/detection.js +1 -2
  36. package/dist/resources/extensions/gsd/docs/preferences-reference.md +0 -2
  37. package/dist/resources/extensions/gsd/doctor-checks.js +82 -0
  38. package/dist/resources/extensions/gsd/doctor-environment.js +78 -0
  39. package/dist/resources/extensions/gsd/doctor-format.js +15 -0
  40. package/dist/resources/extensions/gsd/doctor-providers.js +27 -11
  41. package/dist/resources/extensions/gsd/doctor.js +204 -12
  42. package/dist/resources/extensions/gsd/exit-command.js +2 -1
  43. package/dist/resources/extensions/gsd/export.js +1 -1
  44. package/dist/resources/extensions/gsd/files.js +6 -2
  45. package/dist/resources/extensions/gsd/forensics.js +1 -1
  46. package/dist/resources/extensions/gsd/git-service.js +15 -12
  47. package/dist/resources/extensions/gsd/guided-flow.js +82 -32
  48. package/dist/resources/extensions/gsd/index.js +24 -20
  49. package/dist/resources/extensions/gsd/migrate/parsers.js +1 -1
  50. package/dist/resources/extensions/gsd/native-git-bridge.js +37 -0
  51. package/dist/resources/extensions/gsd/package.json +1 -1
  52. package/dist/resources/extensions/gsd/preferences-models.js +0 -12
  53. package/dist/resources/extensions/gsd/preferences-types.js +1 -1
  54. package/dist/resources/extensions/gsd/preferences-validation.js +59 -11
  55. package/dist/resources/extensions/gsd/preferences.js +8 -5
  56. package/dist/resources/extensions/gsd/prompts/discuss.md +11 -14
  57. package/dist/resources/extensions/gsd/prompts/execute-task.md +2 -2
  58. package/dist/resources/extensions/gsd/prompts/guided-discuss-milestone.md +11 -12
  59. package/dist/resources/extensions/gsd/prompts/guided-discuss-slice.md +8 -10
  60. package/dist/resources/extensions/gsd/prompts/guided-resume-task.md +1 -1
  61. package/dist/resources/extensions/gsd/prompts/queue.md +4 -8
  62. package/dist/resources/extensions/gsd/prompts/reactive-execute.md +11 -8
  63. package/dist/resources/extensions/gsd/prompts/run-uat.md +27 -10
  64. package/dist/resources/extensions/gsd/prompts/workflow-start.md +2 -2
  65. package/dist/resources/extensions/gsd/repo-identity.js +21 -4
  66. package/dist/resources/extensions/gsd/resource-version.js +2 -1
  67. package/dist/resources/extensions/gsd/roadmap-mutations.js +24 -0
  68. package/dist/resources/extensions/gsd/state.js +1 -1
  69. package/dist/resources/extensions/gsd/visualizer-data.js +1 -1
  70. package/dist/resources/extensions/gsd/worktree.js +35 -16
  71. package/dist/resources/extensions/mcp-client/index.js +14 -1
  72. package/dist/resources/extensions/remote-questions/status.js +2 -1
  73. package/dist/resources/extensions/remote-questions/store.js +2 -1
  74. package/dist/resources/extensions/search-the-web/provider.js +2 -1
  75. package/dist/resources/extensions/subagent/index.js +12 -3
  76. package/dist/resources/extensions/subagent/isolation.js +2 -1
  77. package/dist/resources/extensions/ttsr/rule-loader.js +2 -1
  78. package/dist/resources/extensions/universal-config/package.json +1 -1
  79. package/dist/welcome-screen.d.ts +12 -0
  80. package/dist/welcome-screen.js +53 -0
  81. package/package.json +1 -1
  82. package/packages/pi-ai/dist/utils/oauth/anthropic.js +2 -2
  83. package/packages/pi-ai/dist/utils/oauth/anthropic.js.map +1 -1
  84. package/packages/pi-ai/src/utils/oauth/anthropic.ts +2 -2
  85. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  86. package/packages/pi-coding-agent/dist/core/extensions/loader.js +205 -7
  87. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  88. package/packages/pi-coding-agent/dist/core/package-manager.d.ts.map +1 -1
  89. package/packages/pi-coding-agent/dist/core/package-manager.js +8 -4
  90. package/packages/pi-coding-agent/dist/core/package-manager.js.map +1 -1
  91. package/packages/pi-coding-agent/package.json +1 -1
  92. package/packages/pi-coding-agent/src/core/extensions/loader.ts +223 -7
  93. package/packages/pi-coding-agent/src/core/package-manager.ts +8 -4
  94. package/pkg/package.json +1 -1
  95. package/src/resources/extensions/cmux/index.ts +57 -1
  96. package/src/resources/extensions/env-utils.ts +31 -0
  97. package/src/resources/extensions/get-secrets-from-user.ts +5 -24
  98. package/src/resources/extensions/github-sync/cli.ts +364 -0
  99. package/src/resources/extensions/github-sync/index.ts +93 -0
  100. package/src/resources/extensions/github-sync/mapping.ts +81 -0
  101. package/src/resources/extensions/github-sync/sync.ts +556 -0
  102. package/src/resources/extensions/github-sync/templates.ts +183 -0
  103. package/src/resources/extensions/github-sync/tests/cli.test.ts +20 -0
  104. package/src/resources/extensions/github-sync/tests/commit-linking.test.ts +39 -0
  105. package/src/resources/extensions/github-sync/tests/mapping.test.ts +104 -0
  106. package/src/resources/extensions/github-sync/tests/templates.test.ts +110 -0
  107. package/src/resources/extensions/github-sync/types.ts +47 -0
  108. package/src/resources/extensions/gsd/auto/session.ts +7 -25
  109. package/src/resources/extensions/gsd/auto-dispatch.ts +7 -9
  110. package/src/resources/extensions/gsd/auto-loop.ts +484 -546
  111. package/src/resources/extensions/gsd/auto-post-unit.ts +80 -44
  112. package/src/resources/extensions/gsd/auto-prompts.ts +25 -45
  113. package/src/resources/extensions/gsd/auto-start.ts +18 -2
  114. package/src/resources/extensions/gsd/auto-worktree-sync.ts +15 -4
  115. package/src/resources/extensions/gsd/auto-worktree.ts +3 -3
  116. package/src/resources/extensions/gsd/auto.ts +139 -101
  117. package/src/resources/extensions/gsd/captures.ts +10 -1
  118. package/src/resources/extensions/gsd/commands-extensions.ts +4 -2
  119. package/src/resources/extensions/gsd/commands-handlers.ts +17 -2
  120. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +1 -1
  121. package/src/resources/extensions/gsd/commands.ts +26 -4
  122. package/src/resources/extensions/gsd/context-budget.ts +2 -12
  123. package/src/resources/extensions/gsd/detection.ts +2 -2
  124. package/src/resources/extensions/gsd/docs/preferences-reference.md +0 -2
  125. package/src/resources/extensions/gsd/doctor-checks.ts +75 -0
  126. package/src/resources/extensions/gsd/doctor-environment.ts +82 -1
  127. package/src/resources/extensions/gsd/doctor-format.ts +20 -0
  128. package/src/resources/extensions/gsd/doctor-providers.ts +26 -9
  129. package/src/resources/extensions/gsd/doctor-types.ts +16 -1
  130. package/src/resources/extensions/gsd/doctor.ts +199 -14
  131. package/src/resources/extensions/gsd/exit-command.ts +2 -2
  132. package/src/resources/extensions/gsd/export.ts +1 -1
  133. package/src/resources/extensions/gsd/files.ts +5 -3
  134. package/src/resources/extensions/gsd/forensics.ts +1 -1
  135. package/src/resources/extensions/gsd/git-service.ts +20 -10
  136. package/src/resources/extensions/gsd/guided-flow.ts +110 -38
  137. package/src/resources/extensions/gsd/index.ts +24 -17
  138. package/src/resources/extensions/gsd/migrate/parsers.ts +1 -1
  139. package/src/resources/extensions/gsd/native-git-bridge.ts +37 -0
  140. package/src/resources/extensions/gsd/preferences-models.ts +0 -12
  141. package/src/resources/extensions/gsd/preferences-types.ts +4 -4
  142. package/src/resources/extensions/gsd/preferences-validation.ts +51 -11
  143. package/src/resources/extensions/gsd/preferences.ts +8 -5
  144. package/src/resources/extensions/gsd/prompts/discuss.md +11 -14
  145. package/src/resources/extensions/gsd/prompts/execute-task.md +2 -2
  146. package/src/resources/extensions/gsd/prompts/guided-discuss-milestone.md +11 -12
  147. package/src/resources/extensions/gsd/prompts/guided-discuss-slice.md +8 -10
  148. package/src/resources/extensions/gsd/prompts/guided-resume-task.md +1 -1
  149. package/src/resources/extensions/gsd/prompts/queue.md +4 -8
  150. package/src/resources/extensions/gsd/prompts/reactive-execute.md +11 -8
  151. package/src/resources/extensions/gsd/prompts/run-uat.md +27 -10
  152. package/src/resources/extensions/gsd/prompts/workflow-start.md +2 -2
  153. package/src/resources/extensions/gsd/repo-identity.ts +23 -4
  154. package/src/resources/extensions/gsd/resource-version.ts +3 -1
  155. package/src/resources/extensions/gsd/roadmap-mutations.ts +29 -0
  156. package/src/resources/extensions/gsd/state.ts +1 -1
  157. package/src/resources/extensions/gsd/tests/agent-end-retry.test.ts +21 -18
  158. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +122 -68
  159. package/src/resources/extensions/gsd/tests/cmux.test.ts +93 -0
  160. package/src/resources/extensions/gsd/tests/doctor-enhancements.test.ts +266 -0
  161. package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +86 -3
  162. package/src/resources/extensions/gsd/tests/preferences.test.ts +2 -7
  163. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +59 -0
  164. package/src/resources/extensions/gsd/tests/repo-identity-worktree.test.ts +21 -1
  165. package/src/resources/extensions/gsd/tests/run-uat.test.ts +11 -3
  166. package/src/resources/extensions/gsd/tests/worktree.test.ts +47 -0
  167. package/src/resources/extensions/gsd/types.ts +0 -1
  168. package/src/resources/extensions/gsd/visualizer-data.ts +1 -1
  169. package/src/resources/extensions/gsd/worktree.ts +35 -15
  170. package/src/resources/extensions/mcp-client/index.ts +17 -1
  171. package/src/resources/extensions/remote-questions/status.ts +3 -1
  172. package/src/resources/extensions/remote-questions/store.ts +3 -1
  173. package/src/resources/extensions/search-the-web/provider.ts +2 -1
  174. package/src/resources/extensions/subagent/index.ts +12 -3
  175. package/src/resources/extensions/subagent/isolation.ts +3 -1
  176. package/src/resources/extensions/ttsr/rule-loader.ts +3 -1
  177. package/dist/resources/extensions/gsd/prompt-compressor.js +0 -393
  178. package/dist/resources/extensions/gsd/semantic-chunker.js +0 -254
  179. package/dist/resources/extensions/gsd/summary-distiller.js +0 -212
  180. package/src/resources/extensions/gsd/prompt-compressor.ts +0 -508
  181. package/src/resources/extensions/gsd/semantic-chunker.ts +0 -336
  182. package/src/resources/extensions/gsd/summary-distiller.ts +0 -258
  183. package/src/resources/extensions/gsd/tests/context-compression.test.ts +0 -193
  184. package/src/resources/extensions/gsd/tests/prompt-compressor.test.ts +0 -529
  185. package/src/resources/extensions/gsd/tests/semantic-chunker.test.ts +0 -426
  186. package/src/resources/extensions/gsd/tests/summary-distiller.test.ts +0 -323
  187. package/src/resources/extensions/gsd/tests/token-optimization-benchmark.test.ts +0 -1272
  188. package/src/resources/extensions/gsd/tests/token-optimization-prefs.test.ts +0 -164
@@ -4,8 +4,9 @@
4
4
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { join } from "node:path";
6
6
  import { homedir } from "node:os";
7
+ const gsdHome = process.env.GSD_HOME || join(homedir(), ".gsd");
7
8
  function runtimeDir() {
8
- return join(homedir(), ".gsd", "runtime", "remote-questions");
9
+ return join(gsdHome, "runtime", "remote-questions");
9
10
  }
10
11
  function recordPath(id) {
11
12
  return join(runtimeDir(), `${id}.json`);
@@ -15,7 +15,8 @@ import { resolveSearchProviderFromPreferences } from '../gsd/preferences.js';
15
15
  // Compute authFilePath locally instead of importing from app-paths.ts,
16
16
  // because extensions are copied to ~/.gsd/agent/extensions/ at runtime
17
17
  // where the relative import '../../../app-paths.ts' doesn't resolve.
18
- const authFilePath = join(homedir(), '.gsd', 'agent', 'auth.json');
18
+ const gsdHome = process.env.GSD_HOME || join(homedir(), '.gsd');
19
+ const authFilePath = join(gsdHome, 'agent', 'auth.json');
19
20
  const VALID_PREFERENCES = new Set(['tavily', 'brave', 'ollama', 'auto']);
20
21
  const PREFERENCE_KEY = 'search_provider';
21
22
  /** Returns the Tavily API key from the environment, or empty string if not set. */
@@ -360,7 +360,7 @@ async function runSingleAgent(defaultCwd, agents, agentName, task, cwd, step, si
360
360
  }
361
361
  }
362
362
  }
363
- async function runSingleAgentInCmuxSplit(cmuxClient, direction, defaultCwd, agents, agentName, task, cwd, step, signal, onUpdate, makeDetails) {
363
+ async function runSingleAgentInCmuxSplit(cmuxClient, directionOrSurfaceId, defaultCwd, agents, agentName, task, cwd, step, signal, onUpdate, makeDetails) {
364
364
  const agent = agents.find((a) => a.name === agentName);
365
365
  if (!agent) {
366
366
  return runSingleAgent(defaultCwd, agents, agentName, task, cwd, step, signal, onUpdate, makeDetails);
@@ -397,7 +397,12 @@ async function runSingleAgentInCmuxSplit(cmuxClient, direction, defaultCwd, agen
397
397
  const stdoutPath = path.join(tmpOutputDir, "stdout.jsonl");
398
398
  const stderrPath = path.join(tmpOutputDir, "stderr.log");
399
399
  const exitPath = path.join(tmpOutputDir, "exit.code");
400
- const cmuxSurfaceId = await cmuxClient.createSplit(direction);
400
+ // Accept either a pre-created surface ID or a direction to create a new split
401
+ const isDirection = directionOrSurfaceId === "right" || directionOrSurfaceId === "down"
402
+ || directionOrSurfaceId === "left" || directionOrSurfaceId === "up";
403
+ const cmuxSurfaceId = isDirection
404
+ ? await cmuxClient.createSplit(directionOrSurfaceId)
405
+ : directionOrSurfaceId;
401
406
  if (!cmuxSurfaceId) {
402
407
  return runSingleAgent(defaultCwd, agents, agentName, task, cwd, step, signal, onUpdate, makeDetails);
403
408
  }
@@ -656,10 +661,14 @@ export default function (pi) {
656
661
  const MAX_RETRIES = 1; // Retry failed tasks once
657
662
  const batchId = crypto.randomUUID();
658
663
  const batchSize = params.tasks.length;
664
+ // Pre-create a grid layout for cmux splits so agents get a clean tiled arrangement
665
+ const gridSurfaces = cmuxSplitsEnabled
666
+ ? await cmuxClient.createGridLayout(Math.min(batchSize, MAX_CONCURRENCY))
667
+ : [];
659
668
  const results = await mapWithConcurrencyLimit(params.tasks, MAX_CONCURRENCY, async (t, index) => {
660
669
  const workerId = registerWorker(t.agent, t.task, index, batchSize, batchId);
661
670
  const runTask = () => cmuxSplitsEnabled
662
- ? runSingleAgentInCmuxSplit(cmuxClient, index % 2 === 0 ? "right" : "down", ctx.cwd, agents, t.agent, t.task, t.cwd, undefined, signal, (partial) => {
671
+ ? runSingleAgentInCmuxSplit(cmuxClient, gridSurfaces[index] ?? (index % 2 === 0 ? "right" : "down"), ctx.cwd, agents, t.agent, t.task, t.cwd, undefined, signal, (partial) => {
663
672
  if (partial.details?.results[0]) {
664
673
  allResults[index] = partial.details.results[0];
665
674
  emitParallelUpdate();
@@ -17,8 +17,9 @@ const execFile = promisify(execFileCb);
17
17
  function encodeCwd(cwd) {
18
18
  return cwd.replace(/\//g, "--");
19
19
  }
20
+ const gsdHome = process.env.GSD_HOME || path.join(os.homedir(), ".gsd");
20
21
  function getIsolationBaseDir(cwd, taskId) {
21
- return path.join(os.homedir(), ".gsd", "wt", encodeCwd(cwd), taskId);
22
+ return path.join(gsdHome, "wt", encodeCwd(cwd), taskId);
22
23
  }
23
24
  // Track active isolation dirs for cleanup on exit
24
25
  const activeIsolations = new Set();
@@ -8,6 +8,7 @@
8
8
  import { readdirSync, readFileSync, existsSync } from "node:fs";
9
9
  import { join, basename } from "node:path";
10
10
  import { homedir } from "node:os";
11
+ const gsdHome = process.env.GSD_HOME || join(homedir(), ".gsd");
11
12
  import { splitFrontmatter, parseFrontmatterMap } from "../shared/frontmatter.js";
12
13
  function parseRuleFile(filePath) {
13
14
  let content;
@@ -56,7 +57,7 @@ function scanDir(dir) {
56
57
  * Project rules override global rules with the same name.
57
58
  */
58
59
  export function loadRules(cwd) {
59
- const globalDir = join(homedir(), ".gsd", "agent", "rules");
60
+ const globalDir = join(gsdHome, "agent", "rules");
60
61
  const projectDir = join(cwd, ".gsd", "rules");
61
62
  const globalRules = scanDir(globalDir);
62
63
  const projectRules = scanDir(projectDir);
@@ -5,7 +5,7 @@
5
5
  "type": "module",
6
6
  "pi": {
7
7
  "extensions": [
8
- "./index.ts"
8
+ "./index.js"
9
9
  ]
10
10
  }
11
11
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * GSD Welcome Screen
3
+ *
4
+ * Rendered to stderr before the TUI takes over.
5
+ * No box, no panels — logo with metadata alongside, dim hint below.
6
+ */
7
+ export interface WelcomeScreenOptions {
8
+ version: string;
9
+ modelName?: string;
10
+ provider?: string;
11
+ }
12
+ export declare function printWelcomeScreen(opts: WelcomeScreenOptions): void;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * GSD Welcome Screen
3
+ *
4
+ * Rendered to stderr before the TUI takes over.
5
+ * No box, no panels — logo with metadata alongside, dim hint below.
6
+ */
7
+ import os from 'node:os';
8
+ import chalk from 'chalk';
9
+ import { GSD_LOGO } from './logo.js';
10
+ function getShortCwd() {
11
+ const cwd = process.cwd();
12
+ const home = os.homedir();
13
+ return cwd.startsWith(home) ? '~' + cwd.slice(home.length) : cwd;
14
+ }
15
+ export function printWelcomeScreen(opts) {
16
+ if (!process.stderr.isTTY)
17
+ return;
18
+ const { version, modelName, provider } = opts;
19
+ const shortCwd = getShortCwd();
20
+ // Info lines to sit alongside the logo (one per logo row)
21
+ const modelLine = [modelName, provider].filter(Boolean).join(' · ');
22
+ const INFO = [
23
+ ` ${chalk.bold('Get Shit Done')} ${chalk.dim('v' + version)}`,
24
+ undefined,
25
+ modelLine ? ` ${chalk.dim(modelLine)}` : undefined,
26
+ ` ${chalk.dim(shortCwd)}`,
27
+ undefined,
28
+ undefined,
29
+ ];
30
+ const lines = [''];
31
+ for (let i = 0; i < GSD_LOGO.length; i++) {
32
+ lines.push(chalk.cyan(GSD_LOGO[i]) + (INFO[i] ?? ''));
33
+ }
34
+ // Tool status + hint — dim, aligned under the info text
35
+ const pad = ' '.repeat(28) + ' '; // aligns with the info text column
36
+ const toolParts = [];
37
+ if (process.env.BRAVE_API_KEY)
38
+ toolParts.push('Brave ✓');
39
+ if (process.env.BRAVE_ANSWERS_KEY)
40
+ toolParts.push('Answers ✓');
41
+ if (process.env.JINA_API_KEY)
42
+ toolParts.push('Jina ✓');
43
+ if (process.env.TAVILY_API_KEY)
44
+ toolParts.push('Tavily ✓');
45
+ if (process.env.CONTEXT7_API_KEY)
46
+ toolParts.push('Context7 ✓');
47
+ if (toolParts.length > 0) {
48
+ lines.push(chalk.dim(pad + ['Web search loaded', ...toolParts].join(' · ')));
49
+ }
50
+ lines.push(chalk.dim(pad + '/gsd to begin · /gsd help for all commands'));
51
+ lines.push('');
52
+ process.stderr.write(lines.join('\n') + '\n');
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gsd-pi",
3
- "version": "2.37.1-dev.d3ace49",
3
+ "version": "2.38.0-dev.29edcdc",
4
4
  "description": "GSD — Get Shit Done coding agent",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -5,8 +5,8 @@ import { generatePKCE } from "./pkce.js";
5
5
  const decode = (s) => atob(s);
6
6
  const CLIENT_ID = decode("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl");
7
7
  const AUTHORIZE_URL = "https://claude.ai/oauth/authorize";
8
- const TOKEN_URL = "https://console.anthropic.com/v1/oauth/token";
9
- const REDIRECT_URI = "https://console.anthropic.com/oauth/code/callback";
8
+ const TOKEN_URL = "https://platform.claude.com/v1/oauth/token";
9
+ const REDIRECT_URI = "https://platform.claude.com/oauth/code/callback";
10
10
  const SCOPES = "org:create_api_key user:profile user:inference";
11
11
  /**
12
12
  * Login with Anthropic OAuth (device code flow)
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/utils/oauth/anthropic.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACtC,MAAM,SAAS,GAAG,MAAM,CAAC,kDAAkD,CAAC,CAAC;AAC7E,MAAM,aAAa,GAAG,mCAAmC,CAAC;AAC1D,MAAM,SAAS,GAAG,8CAA8C,CAAC;AACjE,MAAM,YAAY,GAAG,mDAAmD,CAAC;AACzE,MAAM,MAAM,GAAG,gDAAgD,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,SAAgC,EAChC,YAAmC;IAEnC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,YAAY,EAAE,CAAC;IAErD,0BAA0B;IAC1B,MAAM,UAAU,GAAG,IAAI,eAAe,CAAC;QACtC,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,SAAS;QACpB,aAAa,EAAE,MAAM;QACrB,YAAY,EAAE,YAAY;QAC1B,KAAK,EAAE,MAAM;QACb,cAAc,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AAC,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAClC,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,+BAA+B,EAAE,CAAC,CACtE,CAAC;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,WAA6B;QAC/C,OAAO,qBAAqB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,SAAS,CAAC,WAA6B;QACtC,OAAO,WAAW,CAAC,MAAM,CAAC;IAC3B,CAAC;CACD,CAAC","sourcesContent":["/**\n * Anthropic OAuth flow (Claude Pro/Max)\n */\n\nimport { generatePKCE } from \"./pkce.js\";\nimport type { OAuthCredentials, OAuthLoginCallbacks, OAuthProviderInterface } from \"./types.js\";\n\nconst decode = (s: string) => atob(s);\nconst CLIENT_ID = decode(\"OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl\");\nconst AUTHORIZE_URL = \"https://claude.ai/oauth/authorize\";\nconst TOKEN_URL = \"https://console.anthropic.com/v1/oauth/token\";\nconst REDIRECT_URI = \"https://console.anthropic.com/oauth/code/callback\";\nconst SCOPES = \"org:create_api_key user:profile user:inference\";\n\n/**\n * Login with Anthropic OAuth (device code flow)\n *\n * @param onAuthUrl - Callback to handle the authorization URL (e.g., open browser)\n * @param onPromptCode - Callback to prompt user for the authorization code\n */\nexport async function loginAnthropic(\n\tonAuthUrl: (url: string) => void,\n\tonPromptCode: () => Promise<string>,\n): Promise<OAuthCredentials> {\n\tconst { verifier, challenge } = await generatePKCE();\n\n\t// Build authorization URL\n\tconst authParams = new URLSearchParams({\n\t\tcode: \"true\",\n\t\tclient_id: CLIENT_ID,\n\t\tresponse_type: \"code\",\n\t\tredirect_uri: REDIRECT_URI,\n\t\tscope: SCOPES,\n\t\tcode_challenge: challenge,\n\t\tcode_challenge_method: \"S256\",\n\t\tstate: verifier,\n\t});\n\n\tconst authUrl = `${AUTHORIZE_URL}?${authParams.toString()}`;\n\n\t// Notify caller with URL to open\n\tonAuthUrl(authUrl);\n\n\t// Wait for user to paste authorization code (format: code#state)\n\tconst authCode = await onPromptCode();\n\tconst splits = authCode.split(\"#\");\n\tconst code = splits[0];\n\tconst state = splits[1];\n\n\t// Exchange code for tokens\n\tconst tokenResponse = await fetch(TOKEN_URL, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\tgrant_type: \"authorization_code\",\n\t\t\tclient_id: CLIENT_ID,\n\t\t\tcode: code,\n\t\t\tstate: state,\n\t\t\tredirect_uri: REDIRECT_URI,\n\t\t\tcode_verifier: verifier,\n\t\t}),\n\t\tsignal: AbortSignal.timeout(30_000),\n\t});\n\n\tif (!tokenResponse.ok) {\n\t\tconst error = await tokenResponse.text();\n\t\tthrow new Error(`Token exchange failed: ${error}`);\n\t}\n\n\tconst tokenData = (await tokenResponse.json()) as {\n\t\taccess_token: string;\n\t\trefresh_token: string;\n\t\texpires_in: number;\n\t};\n\n\t// Calculate expiry time (current time + expires_in seconds - 5 min buffer)\n\tconst expiresAt = Date.now() + tokenData.expires_in * 1000 - 5 * 60 * 1000;\n\n\t// Save credentials\n\treturn {\n\t\trefresh: tokenData.refresh_token,\n\t\taccess: tokenData.access_token,\n\t\texpires: expiresAt,\n\t};\n}\n\n/**\n * Refresh Anthropic OAuth token\n */\nexport async function refreshAnthropicToken(refreshToken: string): Promise<OAuthCredentials> {\n\tconst response = await fetch(TOKEN_URL, {\n\t\tmethod: \"POST\",\n\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\tbody: JSON.stringify({\n\t\t\tgrant_type: \"refresh_token\",\n\t\t\tclient_id: CLIENT_ID,\n\t\t\trefresh_token: refreshToken,\n\t\t}),\n\t\tsignal: AbortSignal.timeout(30_000),\n\t});\n\n\tif (!response.ok) {\n\t\tconst error = await response.text();\n\t\tthrow new Error(`Anthropic token refresh failed: ${error}`);\n\t}\n\n\tconst data = (await response.json()) as {\n\t\taccess_token: string;\n\t\trefresh_token: string;\n\t\texpires_in: number;\n\t};\n\n\treturn {\n\t\trefresh: data.refresh_token,\n\t\taccess: data.access_token,\n\t\texpires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000,\n\t};\n}\n\nexport const anthropicOAuthProvider: OAuthProviderInterface = {\n\tid: \"anthropic\",\n\tname: \"Anthropic (Claude Pro/Max)\",\n\n\tasync login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials> {\n\t\treturn loginAnthropic(\n\t\t\t(url) => callbacks.onAuth({ url }),\n\t\t\t() => callbacks.onPrompt({ message: \"Paste the authorization code:\" }),\n\t\t);\n\t},\n\n\tasync refreshToken(credentials: OAuthCredentials): Promise<OAuthCredentials> {\n\t\treturn refreshAnthropicToken(credentials.refresh);\n\t},\n\n\tgetApiKey(credentials: OAuthCredentials): string {\n\t\treturn credentials.access;\n\t},\n};\n"]}
1
+ {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/utils/oauth/anthropic.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACtC,MAAM,SAAS,GAAG,MAAM,CAAC,kDAAkD,CAAC,CAAC;AAC7E,MAAM,aAAa,GAAG,mCAAmC,CAAC;AAC1D,MAAM,SAAS,GAAG,4CAA4C,CAAC;AAC/D,MAAM,YAAY,GAAG,iDAAiD,CAAC;AACvE,MAAM,MAAM,GAAG,gDAAgD,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,SAAgC,EAChC,YAAmC;IAEnC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,MAAM,YAAY,EAAE,CAAC;IAErD,0BAA0B;IAC1B,MAAM,UAAU,GAAG,IA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sB,GAA2B;IAC7D,EAAE,EAAE,WAAW;IACf,IAAI,EAAE,4BAA4B;IAElC,KAAK,CAAC,KAAK,CAAC,SAA8B;QACzC,OAAO,cAAc,CACpB,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAClC,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,+BAA+B,EAAE,CAAC,CACtE,CAAC;IACH,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,WAA6B;QAC/C,OAAO,qBAAqB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACnD,CAAC;IAED,SAAS,CAAC,WAA6B;QACtC,OAAO,WAAW,CAAC,MAAM,CAAC;IAC3B,CAAC;CACD,CAAC","sourcesContent":["/**\n * Anthropic OAuth flow (Claude Pro/Max)\n */\n\nimport { generatePKCE } from \"./pkce.js\";\nimport type { OAuthCredentials, OAuthLoginCallbacks, OAuthProviderInterface } from \"./types.js\";\n\nconst decode = (s: string) => atob(s);\nconst CLIENT_ID = decode(\"OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl\");\nconst AUTHORIZE_URL = \"https://claude.ai/oauth/authorize\";\nconst TOKEN_URL = \"https://platform.claude.com/v1/oauth/token\";\nconst REDIRECT_URI = \"https://platform.claude.com/oauth/code/callback\";\nconst SCOPES = \"org:create_api_key user:profile user:inference\";\n\n/**\n * Login with Anthropic OAuth (device code flow)\n *\n * @param onAuthUrl - Callback to handle the authorization URL (e.g., open browser)\n * @param onPromptCode - Callback to prompt user for the authorization code\n */\nexport async function loginAnthropic(\n\tonAuthUrl: (url: string) => void,\n\tonPromptCode: () => Promise<string>,\n): Promise<OAuthCredentials> {\n\tconst { verifier, challenge } = await generatePKCE();\n\n\t// Build authorization URL\n\tconst authParams = new URLSearchParams({\n\t\tcode: \"true\",\n\t\tclient_id: CLIENT_ID,\n\t\tresponse_type: \"code\",\n\t\tredirect_uri: REDIRECT_URI,\n\t\tscope: SCOPES,\n\t\tcode_challenge: challenge,\n\t\tcode_challenge_method: \"S256\",\n\t\tstate: verifier,\n\t});\n\n\tconst authUrl = `${AUTHORIZE_URL}?${authParams.toString()}`;\n\n\t// Notify caller with URL to open\n\tonAuthUrl(authUrl);\n\n\t// Wait for user to paste authorization code (format: code#state)\n\tconst authCode = await onPromptCode();\n\tconst splits = authCode.split(\"#\");\n\tconst code = splits[0];\n\tconst state = splits[1];\n\n\t// Exchange code for tokens\n\tconst tokenResponse = await fetch(TOKEN_URL, {\n\t\tmethod: \"POST\",\n\t\theaders: {\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\tgrant_type: \"authorization_code\",\n\t\t\tclient_id: CLIENT_ID,\n\t\t\tcode: code,\n\t\t\tstate: state,\n\t\t\tredirect_uri: REDIRECT_URI,\n\t\t\tcode_verifier: verifier,\n\t\t}),\n\t\tsignal: AbortSignal.timeout(30_000),\n\t});\n\n\tif (!tokenResponse.ok) {\n\t\tconst error = await tokenResponse.text();\n\t\tthrow new Error(`Token exchange failed: ${error}`);\n\t}\n\n\tconst tokenData = (await tokenResponse.json()) as {\n\t\taccess_token: string;\n\t\trefresh_token: string;\n\t\texpires_in: number;\n\t};\n\n\t// Calculate expiry time (current time + expires_in seconds - 5 min buffer)\n\tconst expiresAt = Date.now() + tokenData.expires_in * 1000 - 5 * 60 * 1000;\n\n\t// Save credentials\n\treturn {\n\t\trefresh: tokenData.refresh_token,\n\t\taccess: tokenData.access_token,\n\t\texpires: expiresAt,\n\t};\n}\n\n/**\n * Refresh Anthropic OAuth token\n */\nexport async function refreshAnthropicToken(refreshToken: string): Promise<OAuthCredentials> {\n\tconst response = await fetch(TOKEN_URL, {\n\t\tmethod: \"POST\",\n\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\tbody: JSON.stringify({\n\t\t\tgrant_type: \"refresh_token\",\n\t\t\tclient_id: CLIENT_ID,\n\t\t\trefresh_token: refreshToken,\n\t\t}),\n\t\tsignal: AbortSignal.timeout(30_000),\n\t});\n\n\tif (!response.ok) {\n\t\tconst error = await response.text();\n\t\tthrow new Error(`Anthropic token refresh failed: ${error}`);\n\t}\n\n\tconst data = (await response.json()) as {\n\t\taccess_token: string;\n\t\trefresh_token: string;\n\t\texpires_in: number;\n\t};\n\n\treturn {\n\t\trefresh: data.refresh_token,\n\t\taccess: data.access_token,\n\t\texpires: Date.now() + data.expires_in * 1000 - 5 * 60 * 1000,\n\t};\n}\n\nexport const anthropicOAuthProvider: OAuthProviderInterface = {\n\tid: \"anthropic\",\n\tname: \"Anthropic (Claude Pro/Max)\",\n\n\tasync login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials> {\n\t\treturn loginAnthropic(\n\t\t\t(url) => callbacks.onAuth({ url }),\n\t\t\t() => callbacks.onPrompt({ message: \"Paste the authorization code:\" }),\n\t\t);\n\t},\n\n\tasync refreshToken(credentials: OAuthCredentials): Promise<OAuthCredentials> {\n\t\treturn refreshAnthropicToken(credentials.refresh);\n\t},\n\n\tgetApiKey(credentials: OAuthCredentials): string {\n\t\treturn credentials.access;\n\t},\n};\n"]}
@@ -8,8 +8,8 @@ import type { OAuthCredentials, OAuthLoginCallbacks, OAuthProviderInterface } fr
8
8
  const decode = (s: string) => atob(s);
9
9
  const CLIENT_ID = decode("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl");
10
10
  const AUTHORIZE_URL = "https://claude.ai/oauth/authorize";
11
- const TOKEN_URL = "https://console.anthropic.com/v1/oauth/token";
12
- const REDIRECT_URI = "https://console.anthropic.com/oauth/code/callback";
11
+ const TOKEN_URL = "https://platform.claude.com/v1/oauth/token";
12
+ const REDIRECT_URI = "https://platform.claude.com/oauth/code/callback";
13
13
  const SCOPES = "org:create_api_key user:profile user:inference";
14
14
 
15
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/loader.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAyBH,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIhE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,KAAK,EACX,SAAS,EAET,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EAKpB,MAAM,YAAY,CAAC;AAoGpB,wBAAsB,qBAAqB,CAAC,CAAC,GAAG,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAI/G;AA6BD;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAmCzD;AAkMD;;GAEG;AACH,wBAAsB,wBAAwB,CAC7C,OAAO,EAAE,gBAAgB,EACzB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,gBAAgB,EACzB,aAAa,SAAa,GACxB,OAAO,CAAC,SAAS,CAAC,CAKpB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAyBrH;AAmHD;;GAEG;AACH,wBAAsB,yBAAyB,CAC9C,eAAe,EAAE,MAAM,EAAE,EACzB,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,MAAsB,EAChC,QAAQ,CAAC,EAAE,QAAQ,GACjB,OAAO,CAAC,oBAAoB,CAAC,CAoD/B"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/loader.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA+BH,OAAO,EAAkB,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIhE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,KAAK,EACX,SAAS,EAET,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EAKpB,MAAM,YAAY,CAAC;AAsTpB,wBAAsB,qBAAqB,CAAC,CAAC,GAAG,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAI/G;AA6BD;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAmCzD;AAkMD;;GAEG;AACH,wBAAsB,wBAAwB,CAC7C,OAAO,EAAE,gBAAgB,EACzB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,gBAAgB,EACzB,aAAa,SAAa,GACxB,OAAO,CAAC,SAAS,CAAC,CAKpB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAyBrH;AAmHD;;GAEG;AACH,wBAAsB,yBAAyB,CAC9C,eAAe,EAAE,MAAM,EAAE,EACzB,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,MAAsB,EAChC,QAAQ,CAAC,EAAE,QAAQ,GACjB,OAAO,CAAC,oBAAoB,CAAC,CAoD/B"}
@@ -21,6 +21,12 @@ import * as _bundledYaml from "yaml";
21
21
  import * as _bundledMcpClient from "@modelcontextprotocol/sdk/client";
22
22
  import * as _bundledMcpStdio from "@modelcontextprotocol/sdk/client/stdio.js";
23
23
  import * as _bundledMcpStreamableHttp from "@modelcontextprotocol/sdk/client/streamableHttp.js";
24
+ import * as _bundledMcpSse from "@modelcontextprotocol/sdk/client/sse.js";
25
+ import * as _bundledMcpServer from "@modelcontextprotocol/sdk/server";
26
+ import * as _bundledMcpServerStdio from "@modelcontextprotocol/sdk/server/stdio.js";
27
+ import * as _bundledMcpServerSse from "@modelcontextprotocol/sdk/server/sse.js";
28
+ import * as _bundledMcpServerStreamableHttp from "@modelcontextprotocol/sdk/server/streamableHttp.js";
29
+ import * as _bundledMcpTypes from "@modelcontextprotocol/sdk/types.js";
24
30
  import { getAgentDir, isBunBinary } from "../../config.js";
25
31
  // NOTE: This import works because loader.ts exports are NOT re-exported from index.ts,
26
32
  // avoiding a circular dependency. Extensions can import from @gsd/pi-coding-agent.
@@ -29,8 +35,11 @@ import { createEventBus } from "../event-bus.js";
29
35
  import { execCommand } from "../exec.js";
30
36
  import { getUntrustedExtensionPaths } from "./project-trust.js";
31
37
  export { isProjectTrusted, trustProject, getUntrustedExtensionPaths } from "./project-trust.js";
32
- /** Modules available to extensions via virtualModules (for compiled Bun binary) */
33
- const VIRTUAL_MODULES = {
38
+ /**
39
+ * Statically imported modules for Bun binary virtualModules.
40
+ * Maps specifier -> module object for subpaths that must be available in compiled binaries.
41
+ */
42
+ const STATIC_BUNDLED_MODULES = {
34
43
  "@sinclair/typebox": _bundledTypebox,
35
44
  "@gsd/pi-agent-core": _bundledPiAgentCore,
36
45
  "@gsd/pi-tui": _bundledPiTui,
@@ -43,6 +52,17 @@ const VIRTUAL_MODULES = {
43
52
  "@modelcontextprotocol/sdk/client/stdio.js": _bundledMcpStdio,
44
53
  "@modelcontextprotocol/sdk/client/streamableHttp": _bundledMcpStreamableHttp,
45
54
  "@modelcontextprotocol/sdk/client/streamableHttp.js": _bundledMcpStreamableHttp,
55
+ "@modelcontextprotocol/sdk/client/sse": _bundledMcpSse,
56
+ "@modelcontextprotocol/sdk/client/sse.js": _bundledMcpSse,
57
+ "@modelcontextprotocol/sdk/server": _bundledMcpServer,
58
+ "@modelcontextprotocol/sdk/server/stdio": _bundledMcpServerStdio,
59
+ "@modelcontextprotocol/sdk/server/stdio.js": _bundledMcpServerStdio,
60
+ "@modelcontextprotocol/sdk/server/sse": _bundledMcpServerSse,
61
+ "@modelcontextprotocol/sdk/server/sse.js": _bundledMcpServerSse,
62
+ "@modelcontextprotocol/sdk/server/streamableHttp": _bundledMcpServerStreamableHttp,
63
+ "@modelcontextprotocol/sdk/server/streamableHttp.js": _bundledMcpServerStreamableHttp,
64
+ "@modelcontextprotocol/sdk/types": _bundledMcpTypes,
65
+ "@modelcontextprotocol/sdk/types.js": _bundledMcpTypes,
46
66
  // Aliases for external PI ecosystem packages that import from the original scope
47
67
  "@mariozechner/pi-agent-core": _bundledPiAgentCore,
48
68
  "@mariozechner/pi-tui": _bundledPiTui,
@@ -50,8 +70,180 @@ const VIRTUAL_MODULES = {
50
70
  "@mariozechner/pi-ai/oauth": _bundledPiAiOauth,
51
71
  "@mariozechner/pi-coding-agent": _bundledPiCodingAgent,
52
72
  };
73
+ /** Modules available to extensions via virtualModules (for compiled Bun binary) */
74
+ const VIRTUAL_MODULES = { ...STATIC_BUNDLED_MODULES };
53
75
  const require = createRequire(import.meta.url);
54
76
  const EXTENSION_TIMING_ENABLED = process.env.GSD_STARTUP_TIMING === "1" || process.env.PI_TIMING === "1";
77
+ /**
78
+ * Bundled npm packages whose subpath exports should be auto-resolved for extensions.
79
+ * Each package listed here will have its `exports` field read from package.json,
80
+ * and all subpath exports will be registered as jiti aliases (Node.js mode) so that
81
+ * extensions can import any standard subpath without hitting jiti's CJS double-resolve bug.
82
+ */
83
+ const BUNDLED_PACKAGES_WITH_EXPORTS = [
84
+ "@modelcontextprotocol/sdk",
85
+ "yaml",
86
+ ];
87
+ /**
88
+ * Read a package's `exports` field and return alias entries mapping
89
+ * specifiers (e.g. `@modelcontextprotocol/sdk/server`) to resolved file paths.
90
+ *
91
+ * Handles:
92
+ * - Explicit subpath exports: `./client` -> `@pkg/client`
93
+ * - Wildcard exports (`./*`): scans the package's dist directory for actual files
94
+ * - Both `.js`-suffixed and bare specifiers for each subpath
95
+ */
96
+ function resolveSubpathExports(packageName) {
97
+ const aliases = {};
98
+ let packageJsonPath;
99
+ try {
100
+ // Resolve the package's root directory via its package.json
101
+ packageJsonPath = require.resolve(`${packageName}/package.json`);
102
+ }
103
+ catch {
104
+ // Package doesn't allow importing package.json via exports — find it manually
105
+ try {
106
+ const anyEntry = require.resolve(packageName);
107
+ // Walk up from the resolved entry to find package.json
108
+ let dir = path.dirname(anyEntry);
109
+ while (dir !== path.dirname(dir)) {
110
+ const candidate = path.join(dir, "package.json");
111
+ if (fs.existsSync(candidate)) {
112
+ try {
113
+ const pkg = JSON.parse(fs.readFileSync(candidate, "utf-8"));
114
+ if (pkg.name === packageName) {
115
+ packageJsonPath = candidate;
116
+ break;
117
+ }
118
+ }
119
+ catch {
120
+ // not valid JSON, keep walking
121
+ }
122
+ }
123
+ dir = path.dirname(dir);
124
+ }
125
+ }
126
+ catch {
127
+ return aliases;
128
+ }
129
+ if (!packageJsonPath)
130
+ return aliases;
131
+ }
132
+ let pkg;
133
+ try {
134
+ pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
135
+ }
136
+ catch {
137
+ return aliases;
138
+ }
139
+ const exports = pkg.exports;
140
+ if (!exports || typeof exports !== "object")
141
+ return aliases;
142
+ const packageDir = path.dirname(packageJsonPath);
143
+ for (const [subpath, target] of Object.entries(exports)) {
144
+ if (subpath === ".")
145
+ continue; // Root export handled by static imports
146
+ // Handle wildcard exports like "./*"
147
+ if (subpath.includes("*")) {
148
+ resolveWildcardExports(packageName, packageDir, subpath, target, aliases);
149
+ continue;
150
+ }
151
+ // Explicit subpath: "./client" -> "@pkg/client"
152
+ const specifier = `${packageName}/${subpath.replace(/^\.\//, "")}`;
153
+ try {
154
+ const resolved = require.resolve(specifier);
155
+ aliases[specifier] = resolved;
156
+ // Add .js-suffixed variant if the specifier doesn't already end in .js
157
+ if (!specifier.endsWith(".js")) {
158
+ const jsSpecifier = `${specifier}.js`;
159
+ try {
160
+ const jsResolved = require.resolve(jsSpecifier);
161
+ aliases[jsSpecifier] = jsResolved;
162
+ }
163
+ catch {
164
+ // .js variant doesn't resolve — that's fine
165
+ }
166
+ }
167
+ // Add bare variant (without .js) if it ends in .js
168
+ if (specifier.endsWith(".js")) {
169
+ const bareSpecifier = specifier.slice(0, -3);
170
+ try {
171
+ const bareResolved = require.resolve(bareSpecifier);
172
+ aliases[bareSpecifier] = bareResolved;
173
+ }
174
+ catch {
175
+ // bare variant doesn't resolve — that's fine
176
+ }
177
+ }
178
+ }
179
+ catch {
180
+ // Subpath doesn't resolve — skip it
181
+ }
182
+ }
183
+ return aliases;
184
+ }
185
+ /**
186
+ * Resolve wildcard export patterns (e.g. `./*`) by scanning the package's
187
+ * file structure to find all matching files and generate alias entries.
188
+ */
189
+ function resolveWildcardExports(packageName, packageDir, subpathPattern, target, aliases) {
190
+ // Extract the target directory pattern from the export target
191
+ // e.g. { "require": "./dist/cjs/*" } -> "dist/cjs"
192
+ let targetDir = null;
193
+ if (typeof target === "string") {
194
+ targetDir = target.replace(/\/\*$/, "").replace(/^\.\//, "");
195
+ }
196
+ else if (target && typeof target === "object") {
197
+ const targetObj = target;
198
+ // Prefer "require" for CJS compatibility with jiti, fall back to "import"
199
+ const resolved = targetObj.require ?? targetObj.import ?? targetObj.default;
200
+ if (typeof resolved === "string") {
201
+ targetDir = resolved.replace(/\/\*$/, "").replace(/^\.\//, "");
202
+ }
203
+ }
204
+ if (!targetDir)
205
+ return;
206
+ const fullTargetDir = path.join(packageDir, targetDir);
207
+ if (!fs.existsSync(fullTargetDir))
208
+ return;
209
+ // Scan for .js files and generate specifiers
210
+ const subpathPrefix = subpathPattern.replace(/\/?\*$/, "").replace(/^\.\//, "");
211
+ scanDirForExports(packageName, fullTargetDir, subpathPrefix, aliases);
212
+ }
213
+ /**
214
+ * Recursively scan a directory for .js files and register them as aliases.
215
+ */
216
+ function scanDirForExports(packageName, dir, relativePath, aliases) {
217
+ let entries;
218
+ try {
219
+ entries = fs.readdirSync(dir, { withFileTypes: true });
220
+ }
221
+ catch {
222
+ return;
223
+ }
224
+ for (const entry of entries) {
225
+ const entryRelative = relativePath ? `${relativePath}/${entry.name}` : entry.name;
226
+ if (entry.isDirectory()) {
227
+ // Skip examples/test directories — extensions don't need them
228
+ if (entry.name === "examples" || entry.name === "__tests__" || entry.name === "test")
229
+ continue;
230
+ scanDirForExports(packageName, path.join(dir, entry.name), entryRelative, aliases);
231
+ }
232
+ else if (entry.name.endsWith(".js") && !entry.name.endsWith(".d.js")) {
233
+ const filePath = path.join(dir, entry.name);
234
+ const specifier = `${packageName}/${entryRelative}`;
235
+ // Only add if not already covered by an explicit export
236
+ if (!(specifier in aliases)) {
237
+ aliases[specifier] = filePath;
238
+ }
239
+ // Also add bare (no .js) variant
240
+ const bareSpecifier = specifier.replace(/\.js$/, "");
241
+ if (!(bareSpecifier in aliases)) {
242
+ aliases[bareSpecifier] = filePath;
243
+ }
244
+ }
245
+ }
246
+ }
55
247
  function logExtensionTiming(extensionPath, ms, outcome) {
56
248
  if (!EXTENSION_TIMING_ENABLED)
57
249
  return;
@@ -79,7 +271,18 @@ function getAliases() {
79
271
  }
80
272
  return fileURLToPath(import.meta.resolve(specifier));
81
273
  };
274
+ // Auto-discover subpath exports from bundled npm packages.
275
+ // This ensures extensions can import any standard subpath (e.g. @modelcontextprotocol/sdk/server)
276
+ // without hitting jiti's CJS double-resolve bug.
277
+ const autoDiscovered = {};
278
+ for (const packageName of BUNDLED_PACKAGES_WITH_EXPORTS) {
279
+ const subpathAliases = resolveSubpathExports(packageName);
280
+ Object.assign(autoDiscovered, subpathAliases);
281
+ }
82
282
  _aliases = {
283
+ // Auto-discovered subpath exports (lowest priority — overridden by manual entries below)
284
+ ...autoDiscovered,
285
+ // Manual entries for workspace packages and packages needing special resolution
83
286
  "@gsd/pi-coding-agent": packageIndex,
84
287
  "@gsd/pi-agent-core": resolveWorkspaceOrImport("agent/dist/index.js", "@gsd/pi-agent-core"),
85
288
  "@gsd/pi-tui": resolveWorkspaceOrImport("tui/dist/index.js", "@gsd/pi-tui"),
@@ -87,11 +290,6 @@ function getAliases() {
87
290
  "@gsd/pi-ai/oauth": resolveWorkspaceOrImport("ai/dist/oauth.js", "@gsd/pi-ai/oauth"),
88
291
  "@sinclair/typebox": typeboxRoot,
89
292
  "yaml": yamlRoot,
90
- "@modelcontextprotocol/sdk/client": require.resolve("@modelcontextprotocol/sdk/client"),
91
- "@modelcontextprotocol/sdk/client/stdio": require.resolve("@modelcontextprotocol/sdk/client/stdio.js"),
92
- "@modelcontextprotocol/sdk/client/stdio.js": require.resolve("@modelcontextprotocol/sdk/client/stdio.js"),
93
- "@modelcontextprotocol/sdk/client/streamableHttp": require.resolve("@modelcontextprotocol/sdk/client/streamableHttp.js"),
94
- "@modelcontextprotocol/sdk/client/streamableHttp.js": require.resolve("@modelcontextprotocol/sdk/client/streamableHttp.js"),
95
293
  // Aliases for external PI ecosystem packages that import from the original scope
96
294
  "@mariozechner/pi-coding-agent": packageIndex,
97
295
  "@mariozechner/pi-agent-core": resolveWorkspaceOrImport("agent/dist/index.js", "@gsd/pi-agent-core"),