@mastra/code-sdk 1.0.3-alpha.0 → 1.1.0-alpha.2
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/CHANGELOG.md +49 -0
- package/dist/acp/agent.js +155 -167
- package/dist/acp/agent.js.map +1 -1
- package/dist/acp/event-mapper.js +193 -168
- package/dist/acp/event-mapper.js.map +1 -1
- package/dist/acp/index.js +60 -49
- package/dist/acp/index.js.map +1 -1
- package/dist/acp/server.js +31 -30
- package/dist/acp/server.js.map +1 -1
- package/dist/acp.js +1 -4
- package/dist/agents/credential-resolver.js +40 -29
- package/dist/agents/credential-resolver.js.map +1 -1
- package/dist/agents/custom-provider-source.js +16 -9
- package/dist/agents/custom-provider-source.js.map +1 -1
- package/dist/agents/instructions.js +27 -36
- package/dist/agents/instructions.js.map +1 -1
- package/dist/agents/mastracode-gateway.js +355 -428
- package/dist/agents/mastracode-gateway.js.map +1 -1
- package/dist/agents/memory.js +87 -78
- package/dist/agents/memory.js.map +1 -1
- package/dist/agents/model.js +114 -119
- package/dist/agents/model.js.map +1 -1
- package/dist/agents/modes/build.js +12 -13
- package/dist/agents/modes/build.js.map +1 -1
- package/dist/agents/modes/explore.js +14 -13
- package/dist/agents/modes/explore.js.map +1 -1
- package/dist/agents/modes/plan.js +14 -15
- package/dist/agents/modes/plan.js.map +1 -1
- package/dist/agents/prompts/agent-instructions.js +78 -69
- package/dist/agents/prompts/agent-instructions.js.map +1 -1
- package/dist/agents/prompts/build.js +19 -16
- package/dist/agents/prompts/build.js.map +1 -1
- package/dist/agents/prompts/fast.js +8 -4
- package/dist/agents/prompts/fast.js.map +1 -1
- package/dist/agents/prompts/index.js +48 -47
- package/dist/agents/prompts/index.js.map +1 -1
- package/dist/agents/prompts/model.js +6 -5
- package/dist/agents/prompts/model.js.map +1 -1
- package/dist/agents/prompts/plan.js +20 -16
- package/dist/agents/prompts/plan.js.map +1 -1
- package/dist/agents/prompts/tool-guidance.js +77 -109
- package/dist/agents/prompts/tool-guidance.js.map +1 -1
- package/dist/agents/sandbox-filesystem.js +245 -259
- package/dist/agents/sandbox-filesystem.js.map +1 -1
- package/dist/agents/sandbox-reattach.js +9 -11
- package/dist/agents/sandbox-reattach.js.map +1 -1
- package/dist/agents/thread-caveman-state.js +92 -81
- package/dist/agents/thread-caveman-state.js.map +1 -1
- package/dist/agents/tool-availability.js +62 -80
- package/dist/agents/tool-availability.js.map +1 -1
- package/dist/agents/tools.js +99 -139
- package/dist/agents/tools.js.map +1 -1
- package/dist/agents/workspace.js +232 -225
- package/dist/agents/workspace.js.map +1 -1
- package/dist/analytics.js +139 -128
- package/dist/analytics.js.map +1 -1
- package/dist/auth/authorization-input.js +39 -25
- package/dist/auth/authorization-input.js.map +1 -1
- package/dist/auth/device-code.js +112 -80
- package/dist/auth/device-code.js.map +1 -1
- package/dist/auth/index.js +2 -9
- package/dist/auth/pkce.js +27 -16
- package/dist/auth/pkce.js.map +1 -1
- package/dist/auth/providers/anthropic.js +107 -93
- package/dist/auth/providers/anthropic.js.map +1 -1
- package/dist/auth/providers/github-copilot.js +304 -293
- package/dist/auth/providers/github-copilot.js.map +1 -1
- package/dist/auth/providers/openai-codex.js +442 -460
- package/dist/auth/providers/openai-codex.js.map +1 -1
- package/dist/auth/providers/xai.js +179 -145
- package/dist/auth/providers/xai.js.map +1 -1
- package/dist/auth/storage.js +182 -175
- package/dist/auth/storage.js.map +1 -1
- package/dist/auth/types.js +1 -1
- package/dist/clipboard/index.js +206 -172
- package/dist/clipboard/index.js.map +1 -1
- package/dist/constants.js +11 -16
- package/dist/constants.js.map +1 -1
- package/dist/error-classification.js +19 -11
- package/dist/error-classification.js.map +1 -1
- package/dist/evals/context-builder.js +145 -104
- package/dist/evals/context-builder.js.map +1 -1
- package/dist/evals/index.js +4 -7
- package/dist/evals/scorers/classify-command.js +62 -41
- package/dist/evals/scorers/classify-command.js.map +1 -1
- package/dist/evals/scorers/efficiency.js +239 -181
- package/dist/evals/scorers/efficiency.js.map +1 -1
- package/dist/evals/scorers/extract-tools.js +51 -47
- package/dist/evals/scorers/extract-tools.js.map +1 -1
- package/dist/evals/scorers/index.js +1 -5
- package/dist/evals/scorers/outcome.js +321 -212
- package/dist/evals/scorers/outcome.js.map +1 -1
- package/dist/goal-manager.js +266 -261
- package/dist/goal-manager.js.map +1 -1
- package/dist/goal-signal.js +14 -13
- package/dist/goal-signal.js.map +1 -1
- package/dist/headless/cli.js +153 -154
- package/dist/headless/cli.js.map +1 -1
- package/dist/headless/flags.js +180 -178
- package/dist/headless/flags.js.map +1 -1
- package/dist/headless/format.js +72 -71
- package/dist/headless/format.js.map +1 -1
- package/dist/headless/index.js +5 -31
- package/dist/headless/policy.js +35 -31
- package/dist/headless/policy.js.map +1 -1
- package/dist/headless/run-mc.js +332 -334
- package/dist/headless/run-mc.js.map +1 -1
- package/dist/headless/types.js +16 -7
- package/dist/headless/types.js.map +1 -1
- package/dist/hooks/config.js +56 -61
- package/dist/hooks/config.js.map +1 -1
- package/dist/hooks/executor.js +118 -116
- package/dist/hooks/executor.js.map +1 -1
- package/dist/hooks/index.js +4 -15
- package/dist/hooks/manager.js +221 -280
- package/dist/hooks/manager.js.map +1 -1
- package/dist/hooks/types.js +5 -4
- package/dist/hooks/types.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +632 -712
- package/dist/index.js.map +1 -1
- package/dist/ipc/ipc-reporter.js +19 -22
- package/dist/ipc/ipc-reporter.js.map +1 -1
- package/dist/lsp/client.js +248 -306
- package/dist/lsp/client.js.map +1 -1
- package/dist/lsp/index.js +1 -6
- package/dist/lsp/language.js +39 -43
- package/dist/lsp/language.js.map +1 -1
- package/dist/lsp/manager.js +78 -93
- package/dist/lsp/manager.js.map +1 -1
- package/dist/lsp/server.js +151 -120
- package/dist/lsp/server.js.map +1 -1
- package/dist/lsp/workspace.js +50 -47
- package/dist/lsp/workspace.js.map +1 -1
- package/dist/mcp/config.js +210 -199
- package/dist/mcp/config.js.map +1 -1
- package/dist/mcp/index.js +2 -9
- package/dist/mcp/manager.js +482 -475
- package/dist/mcp/manager.js.map +1 -1
- package/dist/mcp/types.js +1 -1
- package/dist/onboarding/custom-packs.js +14 -17
- package/dist/onboarding/custom-packs.js.map +1 -1
- package/dist/onboarding/custom-providers.js +22 -20
- package/dist/onboarding/custom-providers.js.map +1 -1
- package/dist/onboarding/index.d.ts +1 -1
- package/dist/onboarding/index.d.ts.map +1 -1
- package/dist/onboarding/index.js +3 -21
- package/dist/onboarding/om-settings.d.ts +5 -0
- package/dist/onboarding/om-settings.d.ts.map +1 -1
- package/dist/onboarding/om-settings.js +41 -20
- package/dist/onboarding/om-settings.js.map +1 -1
- package/dist/onboarding/packs.d.ts +4 -6
- package/dist/onboarding/packs.d.ts.map +1 -1
- package/dist/onboarding/packs.js +154 -105
- package/dist/onboarding/packs.js.map +1 -1
- package/dist/onboarding/settings.js +575 -517
- package/dist/onboarding/settings.js.map +1 -1
- package/dist/permissions.js +112 -99
- package/dist/permissions.js.map +1 -1
- package/dist/plugin.js +21 -23
- package/dist/plugin.js.map +1 -1
- package/dist/plugins/dependencies.js +64 -87
- package/dist/plugins/dependencies.js.map +1 -1
- package/dist/plugins/install.js +159 -169
- package/dist/plugins/install.js.map +1 -1
- package/dist/plugins/loader.js +170 -185
- package/dist/plugins/loader.js.map +1 -1
- package/dist/plugins/manager.js +374 -380
- package/dist/plugins/manager.js.map +1 -1
- package/dist/plugins/manifest.js +38 -63
- package/dist/plugins/manifest.js.map +1 -1
- package/dist/plugins/package-link.js +48 -64
- package/dist/plugins/package-link.js.map +1 -1
- package/dist/plugins/paths.js +18 -19
- package/dist/plugins/paths.js.map +1 -1
- package/dist/plugins/registry.js +97 -81
- package/dist/plugins/registry.js.map +1 -1
- package/dist/plugins/scaffold.js +62 -98
- package/dist/plugins/scaffold.js.map +1 -1
- package/dist/plugins/types.js +1 -1
- package/dist/processors/plan-rejection-abort.js +45 -44
- package/dist/processors/plan-rejection-abort.js.map +1 -1
- package/dist/providers/amazon-bedrock-gateway.js +134 -125
- package/dist/providers/amazon-bedrock-gateway.js.map +1 -1
- package/dist/providers/amazon-bedrock.js +68 -47
- package/dist/providers/amazon-bedrock.js.map +1 -1
- package/dist/providers/claude-max.js +153 -133
- package/dist/providers/claude-max.js.map +1 -1
- package/dist/providers/github-copilot.js +232 -230
- package/dist/providers/github-copilot.js.map +1 -1
- package/dist/providers/openai-codex.js +271 -260
- package/dist/providers/openai-codex.js.map +1 -1
- package/dist/providers/xai.js +57 -50
- package/dist/providers/xai.js.map +1 -1
- package/dist/schema.js +91 -89
- package/dist/schema.js.map +1 -1
- package/dist/theme-palette.js +18 -14
- package/dist/theme-palette.js.map +1 -1
- package/dist/tool-names.js +46 -37
- package/dist/tool-names.js.map +1 -1
- package/dist/tools/index.js +2 -8
- package/dist/tools/request-sandbox-access.js +71 -80
- package/dist/tools/request-sandbox-access.js.map +1 -1
- package/dist/tools/utils.js +26 -16
- package/dist/tools/utils.js.map +1 -1
- package/dist/tools/web-search.js +51 -55
- package/dist/tools/web-search.js.map +1 -1
- package/dist/utils/binaries.js +65 -61
- package/dist/utils/binaries.js.map +1 -1
- package/dist/utils/debug-log.js +51 -47
- package/dist/utils/debug-log.js.map +1 -1
- package/dist/utils/errors.js +157 -192
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/gateway-sync.js +49 -37
- package/dist/utils/gateway-sync.js.map +1 -1
- package/dist/utils/path-security.js +7 -6
- package/dist/utils/path-security.js.map +1 -1
- package/dist/utils/plan-diff.js +58 -39
- package/dist/utils/plan-diff.js.map +1 -1
- package/dist/utils/plans.js +92 -74
- package/dist/utils/plans.js.map +1 -1
- package/dist/utils/project.js +318 -256
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/signals-pubsub.js +117 -99
- package/dist/utils/signals-pubsub.js.map +1 -1
- package/dist/utils/slash-command-loader.js +118 -154
- package/dist/utils/slash-command-loader.js.map +1 -1
- package/dist/utils/slash-command-processor.js +92 -83
- package/dist/utils/slash-command-processor.js.map +1 -1
- package/dist/utils/stdin-pipe.js +87 -63
- package/dist/utils/stdin-pipe.js.map +1 -1
- package/dist/utils/storage-factory.js +104 -84
- package/dist/utils/storage-factory.js.map +1 -1
- package/dist/utils/storage-maintenance.js +249 -211
- package/dist/utils/storage-maintenance.js.map +1 -1
- package/dist/utils/thread-lock.js +96 -92
- package/dist/utils/thread-lock.js.map +1 -1
- package/dist/utils/token-estimator.js +12 -12
- package/dist/utils/token-estimator.js.map +1 -1
- package/dist/utils/update-check.d.ts +1 -1
- package/dist/utils/update-check.js +341 -259
- package/dist/utils/update-check.js.map +1 -1
- package/dist/voice/stt-registry.js +131 -113
- package/dist/voice/stt-registry.js.map +1 -1
- package/package.json +11 -11
- package/dist/acp.js.map +0 -1
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/types.js.map +0 -1
- package/dist/evals/index.js.map +0 -1
- package/dist/evals/scorers/index.js.map +0 -1
- package/dist/headless/index.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/lsp/index.js.map +0 -1
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/types.js.map +0 -1
- package/dist/onboarding/index.js.map +0 -1
- package/dist/plugins/types.js.map +0 -1
- package/dist/tools/index.js.map +0 -1
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Tool, ToolAction, ToolExecutionContext } from '@mastra/core/tools';\n\nexport { createTool } from '@mastra/core/tools';\nexport type { Tool, ToolAction, ToolExecutionContext } from '@mastra/core/tools';\nexport { z } from 'zod';\n\nexport type MastraCodeToolRenderConfig = {\n type: 'subagent';\n agentType?: string;\n modelId?: string;\n forked?: boolean;\n label?: string;\n maxActivityLines?: number;\n collapsedLines?: number;\n colors?: {\n border?: string;\n label?: string;\n agentType?: string;\n icon?: string;\n };\n icons?: {\n running?: string;\n success?: string;\n error?: string;\n };\n};\n\nexport type MastraCodeSubagentProgress =\n | {\n event: 'text';\n text: string;\n }\n | {\n event: 'tool_start';\n toolName: string;\n args?: unknown;\n }\n | {\n event: 'tool_end';\n toolName: string;\n result?: unknown;\n isError?: boolean;\n }\n | {\n event: 'finish';\n isError?: boolean;\n durationMs?: number;\n result?: string;\n };\n\nexport type MastraCodeToolProgress = string | { status?: string; detail?: string } | MastraCodeSubagentProgress;\n\nexport async function writeToolProgress(\n context: Pick<ToolExecutionContext, 'writer' | 'agent'> | undefined,\n progress: MastraCodeToolProgress,\n): Promise<void> {\n const toolCallId = context?.agent?.toolCallId;\n if (!toolCallId) return;\n\n const chunk = {\n type: 'data-mastracode-tool-progress',\n data: {\n toolCallId,\n progress,\n },\n transient: true,\n } as const;\n\n const outputWriter = (context.agent as { outputWriter?: (chunk: unknown) => Promise<void> } | undefined)\n ?.outputWriter;\n if (outputWriter) {\n await outputWriter(chunk);\n return;\n }\n\n await context.writer?.custom(chunk);\n}\n\nexport type MastraCodePluginConfigValue = string | boolean | undefined;\n\nexport type MastraCodePluginConfigOption = {\n type: 'model' | 'boolean' | 'string';\n label?: string;\n description?: string;\n default?: string | boolean;\n};\n\nexport type MastraCodePluginConfigSchema = Record<string, MastraCodePluginConfigOption>;\nexport type MastraCodePluginConfigValues = Record<string, MastraCodePluginConfigValue>;\n\nexport type MastraCodePluginContext = {\n cwd: string;\n scope: 'global' | 'project';\n pluginDir: string;\n config: MastraCodePluginConfigValues;\n};\n\nexport type MastraCodePluginTool = Tool | ToolAction<any, any, any, any, any, any, any>;\n\nexport type MastraCodePluginToolEntry = {\n tool: MastraCodePluginTool;\n render?: MastraCodeToolRenderConfig;\n};\n\nexport type MastraCodePluginTools = Record<string, MastraCodePluginTool>;\nexport type MastraCodePluginToolEntries = Record<string, MastraCodePluginToolEntry>;\nexport type MastraCodePluginInstructions = string | ((context: MastraCodePluginContext) => string | Promise<string>);\n\nexport type MastraCodePlugin = {\n id: string;\n name?: string;\n version?: string;\n description?: string;\n config?: MastraCodePluginConfigSchema;\n instructions?: MastraCodePluginInstructions;\n tools?:\n | MastraCodePluginToolEntries\n | ((context: MastraCodePluginContext) => MastraCodePluginToolEntries | Promise<MastraCodePluginToolEntries>);\n};\n\nexport function defineMastraCodePlugin<TPlugin extends MastraCodePlugin>(plugin: TPlugin): TPlugin {\n return plugin;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { Tool, ToolAction, ToolExecutionContext } from '@mastra/core/tools';\n\nexport { createTool } from '@mastra/core/tools';\nexport type { Tool, ToolAction, ToolExecutionContext } from '@mastra/core/tools';\nexport { z } from 'zod';\n\nexport type MastraCodeToolRenderConfig = {\n type: 'subagent';\n agentType?: string;\n modelId?: string;\n forked?: boolean;\n label?: string;\n maxActivityLines?: number;\n collapsedLines?: number;\n colors?: {\n border?: string;\n label?: string;\n agentType?: string;\n icon?: string;\n };\n icons?: {\n running?: string;\n success?: string;\n error?: string;\n };\n};\n\nexport type MastraCodeSubagentProgress =\n | {\n event: 'text';\n text: string;\n }\n | {\n event: 'tool_start';\n toolName: string;\n args?: unknown;\n }\n | {\n event: 'tool_end';\n toolName: string;\n result?: unknown;\n isError?: boolean;\n }\n | {\n event: 'finish';\n isError?: boolean;\n durationMs?: number;\n result?: string;\n };\n\nexport type MastraCodeToolProgress = string | { status?: string; detail?: string } | MastraCodeSubagentProgress;\n\nexport async function writeToolProgress(\n context: Pick<ToolExecutionContext, 'writer' | 'agent'> | undefined,\n progress: MastraCodeToolProgress,\n): Promise<void> {\n const toolCallId = context?.agent?.toolCallId;\n if (!toolCallId) return;\n\n const chunk = {\n type: 'data-mastracode-tool-progress',\n data: {\n toolCallId,\n progress,\n },\n transient: true,\n } as const;\n\n const outputWriter = (context.agent as { outputWriter?: (chunk: unknown) => Promise<void> } | undefined)\n ?.outputWriter;\n if (outputWriter) {\n await outputWriter(chunk);\n return;\n }\n\n await context.writer?.custom(chunk);\n}\n\nexport type MastraCodePluginConfigValue = string | boolean | undefined;\n\nexport type MastraCodePluginConfigOption = {\n type: 'model' | 'boolean' | 'string';\n label?: string;\n description?: string;\n default?: string | boolean;\n};\n\nexport type MastraCodePluginConfigSchema = Record<string, MastraCodePluginConfigOption>;\nexport type MastraCodePluginConfigValues = Record<string, MastraCodePluginConfigValue>;\n\nexport type MastraCodePluginContext = {\n cwd: string;\n scope: 'global' | 'project';\n pluginDir: string;\n config: MastraCodePluginConfigValues;\n};\n\nexport type MastraCodePluginTool = Tool | ToolAction<any, any, any, any, any, any, any>;\n\nexport type MastraCodePluginToolEntry = {\n tool: MastraCodePluginTool;\n render?: MastraCodeToolRenderConfig;\n};\n\nexport type MastraCodePluginTools = Record<string, MastraCodePluginTool>;\nexport type MastraCodePluginToolEntries = Record<string, MastraCodePluginToolEntry>;\nexport type MastraCodePluginInstructions = string | ((context: MastraCodePluginContext) => string | Promise<string>);\n\nexport type MastraCodePlugin = {\n id: string;\n name?: string;\n version?: string;\n description?: string;\n config?: MastraCodePluginConfigSchema;\n instructions?: MastraCodePluginInstructions;\n tools?:\n | MastraCodePluginToolEntries\n | ((context: MastraCodePluginContext) => MastraCodePluginToolEntries | Promise<MastraCodePluginToolEntries>);\n};\n\nexport function defineMastraCodePlugin<TPlugin extends MastraCodePlugin>(plugin: TPlugin): TPlugin {\n return plugin;\n}\n"],"mappings":";;;AAoDA,eAAsB,kBACpB,SACA,UACe;CACf,MAAM,aAAa,SAAS,OAAO;CACnC,IAAI,CAAC,YAAY;CAEjB,MAAM,QAAQ;EACZ,MAAM;EACN,MAAM;GACJ;GACA;EACF;EACA,WAAW;CACb;CAEA,MAAM,eAAgB,QAAQ,OAC1B;CACJ,IAAI,cAAc;EAChB,MAAM,aAAa,KAAK;EACxB;CACF;CAEA,MAAM,QAAQ,QAAQ,OAAO,KAAK;AACpC;AA4CA,SAAgB,uBAAyD,QAA0B;CACjG,OAAO;AACT"}
|
|
@@ -1,111 +1,88 @@
|
|
|
1
|
-
import fs from "
|
|
2
|
-
import path from "
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
3
|
import { execa } from "execa";
|
|
4
|
+
//#region src/plugins/dependencies.ts
|
|
4
5
|
async function installPluginDependencies(pluginRoot, commandRoot = pluginRoot, options = {}) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{ cause: error }
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
6
|
+
const packageJsonPath = path.join(pluginRoot, "package.json");
|
|
7
|
+
if (!fs.existsSync(packageJsonPath)) return false;
|
|
8
|
+
const packageJson = readPackageJson(pluginRoot);
|
|
9
|
+
const commandPackageJson = commandRoot === pluginRoot ? packageJson : readPackageJson(commandRoot);
|
|
10
|
+
const installCommand = getInstallCommand(pluginRoot, getPnpmVersion(pluginRoot, Object.hasOwn(packageJson, "packageManager") ? packageJson.packageManager : commandPackageJson.packageManager));
|
|
11
|
+
const child = execa(installCommand.command, installCommand.args, {
|
|
12
|
+
cwd: pluginRoot,
|
|
13
|
+
env: {
|
|
14
|
+
...process.env,
|
|
15
|
+
GIT_TERMINAL_PROMPT: "0"
|
|
16
|
+
},
|
|
17
|
+
stdout: options.onOutput ? "pipe" : "ignore",
|
|
18
|
+
stderr: options.onOutput ? "pipe" : "ignore",
|
|
19
|
+
cancelSignal: options.signal
|
|
20
|
+
});
|
|
21
|
+
if (options.onOutput) {
|
|
22
|
+
child.stdout?.on("data", options.onOutput);
|
|
23
|
+
child.stderr?.on("data", options.onOutput);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
await child;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (isCommandNotFoundError(error)) throw new Error("Mastra Code requires Corepack to install GitHub plugin dependencies. Install it with \"npm install --global corepack\" and try again.", { cause: error });
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
37
32
|
}
|
|
38
33
|
async function installPluginDependenciesForEntry(pluginRoot, entry, options = {}) {
|
|
39
|
-
|
|
40
|
-
await installPluginDependencies(dependencyRoot, pluginRoot, options);
|
|
41
|
-
}
|
|
34
|
+
for (const dependencyRoot of getPluginDependencyRoots(pluginRoot, entry)) await installPluginDependencies(dependencyRoot, pluginRoot, options);
|
|
42
35
|
}
|
|
43
36
|
function getPluginDependencyRoots(pluginRoot, entry) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
return roots;
|
|
37
|
+
const roots = fs.existsSync(path.join(pluginRoot, "package.json")) ? [pluginRoot] : [];
|
|
38
|
+
const entryPackageRoot = findEntryPackageRoot(pluginRoot, entry);
|
|
39
|
+
if (entryPackageRoot && entryPackageRoot !== pluginRoot) roots.push(entryPackageRoot);
|
|
40
|
+
return roots;
|
|
50
41
|
}
|
|
51
42
|
function getEntryPackageRoot(pluginRoot, entry) {
|
|
52
|
-
|
|
43
|
+
return findEntryPackageRoot(pluginRoot, entry) ?? pluginRoot;
|
|
53
44
|
}
|
|
54
45
|
function findEntryPackageRoot(pluginRoot, entry) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
current = path.dirname(current);
|
|
63
|
-
}
|
|
64
|
-
return void 0;
|
|
46
|
+
const root = path.resolve(pluginRoot);
|
|
47
|
+
let current = path.dirname(path.resolve(pluginRoot, entry));
|
|
48
|
+
while (isInsideDirectory(current, root)) {
|
|
49
|
+
if (fs.existsSync(path.join(current, "package.json"))) return current;
|
|
50
|
+
if (current === root) break;
|
|
51
|
+
current = path.dirname(current);
|
|
52
|
+
}
|
|
65
53
|
}
|
|
66
54
|
function isInsideDirectory(targetPath, root) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
const resolvedTarget = path.resolve(targetPath);
|
|
56
|
+
const resolvedRoot = path.resolve(root);
|
|
57
|
+
return resolvedTarget === resolvedRoot || resolvedTarget.startsWith(resolvedRoot + path.sep);
|
|
70
58
|
}
|
|
71
59
|
function getPnpmVersion(pluginRoot, packageManager) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
const match = /^pnpm@(\d+\.\d+\.\d+)$/.exec(packageManager);
|
|
78
|
-
if (!match?.[1]) {
|
|
79
|
-
throw new Error(
|
|
80
|
-
`Plugin at ${pluginRoot} must declare an exact pnpm version in package.json using "packageManager": "pnpm@x.y.z".`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
return match[1];
|
|
60
|
+
if (typeof packageManager !== "string") throw new Error(`Plugin at ${pluginRoot} must declare an exact pnpm version in package.json using "packageManager": "pnpm@x.y.z".`);
|
|
61
|
+
const match = /^pnpm@(\d+\.\d+\.\d+)$/.exec(packageManager);
|
|
62
|
+
if (!match?.[1]) throw new Error(`Plugin at ${pluginRoot} must declare an exact pnpm version in package.json using "packageManager": "pnpm@x.y.z".`);
|
|
63
|
+
return match[1];
|
|
84
64
|
}
|
|
85
65
|
function getInstallCommand(pluginRoot, pnpmVersion) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
66
|
+
const installArgs = ["install", "--ignore-workspace"];
|
|
67
|
+
if (hasFile(pluginRoot, "pnpm-lock.yaml")) installArgs.push("--frozen-lockfile");
|
|
68
|
+
installArgs.push("--ignore-scripts");
|
|
69
|
+
return {
|
|
70
|
+
command: "corepack",
|
|
71
|
+
args: [`pnpm@${pnpmVersion}`, ...installArgs]
|
|
72
|
+
};
|
|
93
73
|
}
|
|
94
74
|
function isCommandNotFoundError(error) {
|
|
95
|
-
|
|
75
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
96
76
|
}
|
|
97
77
|
function readPackageJson(pluginRoot) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
78
|
+
const packageJsonPath = path.join(pluginRoot, "package.json");
|
|
79
|
+
if (!fs.existsSync(packageJsonPath)) return {};
|
|
80
|
+
return JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
101
81
|
}
|
|
102
82
|
function hasFile(pluginRoot, fileName) {
|
|
103
|
-
|
|
83
|
+
return fs.existsSync(path.join(pluginRoot, fileName));
|
|
104
84
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
installPluginDependencies,
|
|
109
|
-
installPluginDependenciesForEntry
|
|
110
|
-
};
|
|
85
|
+
//#endregion
|
|
86
|
+
export { getEntryPackageRoot, getPluginDependencyRoots, installPluginDependencies, installPluginDependenciesForEntry };
|
|
87
|
+
|
|
111
88
|
//# sourceMappingURL=dependencies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/dependencies.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { execa } from 'execa';\n\ntype InstallCommand = {\n command: string;\n args: string[];\n};\n\nexport type PluginInstallExecutionOptions = {\n onOutput?: (chunk: Buffer | string) => void;\n signal?: AbortSignal;\n};\n\nexport async function installPluginDependencies(\n pluginRoot: string,\n commandRoot = pluginRoot,\n options: PluginInstallExecutionOptions = {},\n): Promise<boolean> {\n const packageJsonPath = path.join(pluginRoot, 'package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return false;\n }\n\n const packageJson = readPackageJson(pluginRoot);\n const commandPackageJson = commandRoot === pluginRoot ? packageJson : readPackageJson(commandRoot);\n const packageManager = Object.hasOwn(packageJson, 'packageManager')\n ? packageJson.packageManager\n : commandPackageJson.packageManager;\n const pnpmVersion = getPnpmVersion(pluginRoot, packageManager);\n const installCommand = getInstallCommand(pluginRoot, pnpmVersion);\n\n const child = execa(installCommand.command, installCommand.args, {\n cwd: pluginRoot,\n env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },\n stdout: options.onOutput ? 'pipe' : 'ignore',\n stderr: options.onOutput ? 'pipe' : 'ignore',\n cancelSignal: options.signal,\n });\n if (options.onOutput) {\n child.stdout?.on('data', options.onOutput);\n child.stderr?.on('data', options.onOutput);\n }\n try {\n await child;\n } catch (error) {\n if (isCommandNotFoundError(error)) {\n throw new Error(\n 'Mastra Code requires Corepack to install GitHub plugin dependencies. Install it with \"npm install --global corepack\" and try again.',\n { cause: error },\n );\n }\n throw error;\n }\n return true;\n}\n\nexport async function installPluginDependenciesForEntry(\n pluginRoot: string,\n entry: string,\n options: PluginInstallExecutionOptions = {},\n): Promise<void> {\n for (const dependencyRoot of getPluginDependencyRoots(pluginRoot, entry)) {\n await installPluginDependencies(dependencyRoot, pluginRoot, options);\n }\n}\n\nexport function getPluginDependencyRoots(pluginRoot: string, entry: string): string[] {\n const roots = fs.existsSync(path.join(pluginRoot, 'package.json')) ? [pluginRoot] : [];\n const entryPackageRoot = findEntryPackageRoot(pluginRoot, entry);\n if (entryPackageRoot && entryPackageRoot !== pluginRoot) {\n roots.push(entryPackageRoot);\n }\n return roots;\n}\n\nexport function getEntryPackageRoot(pluginRoot: string, entry: string): string {\n return findEntryPackageRoot(pluginRoot, entry) ?? pluginRoot;\n}\n\nfunction findEntryPackageRoot(pluginRoot: string, entry: string): string | undefined {\n const root = path.resolve(pluginRoot);\n let current = path.dirname(path.resolve(pluginRoot, entry));\n\n while (isInsideDirectory(current, root)) {\n if (fs.existsSync(path.join(current, 'package.json'))) {\n return current;\n }\n if (current === root) break;\n current = path.dirname(current);\n }\n\n return undefined;\n}\n\nfunction isInsideDirectory(targetPath: string, root: string): boolean {\n const resolvedTarget = path.resolve(targetPath);\n const resolvedRoot = path.resolve(root);\n return resolvedTarget === resolvedRoot || resolvedTarget.startsWith(resolvedRoot + path.sep);\n}\n\nfunction getPnpmVersion(pluginRoot: string, packageManager: unknown): string {\n if (typeof packageManager !== 'string') {\n throw new Error(\n `Plugin at ${pluginRoot} must declare an exact pnpm version in package.json using \"packageManager\": \"pnpm@x.y.z\".`,\n );\n }\n\n const match = /^pnpm@(\\d+\\.\\d+\\.\\d+)$/.exec(packageManager);\n if (!match?.[1]) {\n throw new Error(\n `Plugin at ${pluginRoot} must declare an exact pnpm version in package.json using \"packageManager\": \"pnpm@x.y.z\".`,\n );\n }\n return match[1];\n}\n\nfunction getInstallCommand(pluginRoot: string, pnpmVersion: string): InstallCommand {\n const installArgs = ['install', '--ignore-workspace'];\n if (hasFile(pluginRoot, 'pnpm-lock.yaml')) installArgs.push('--frozen-lockfile');\n installArgs.push('--ignore-scripts');\n\n return {\n command: 'corepack',\n args: [`pnpm@${pnpmVersion}`, ...installArgs],\n };\n}\n\nfunction isCommandNotFoundError(error: unknown): boolean {\n return typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT';\n}\n\nfunction readPackageJson(pluginRoot: string): { packageManager?: unknown } {\n const packageJsonPath = path.join(pluginRoot, 'package.json');\n if (!fs.existsSync(packageJsonPath)) return {};\n return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as { packageManager?: unknown };\n}\n\nfunction hasFile(pluginRoot: string, fileName: string): boolean {\n return fs.existsSync(path.join(pluginRoot, fileName));\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"dependencies.js","names":[],"sources":["../../src/plugins/dependencies.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { execa } from 'execa';\n\ntype InstallCommand = {\n command: string;\n args: string[];\n};\n\nexport type PluginInstallExecutionOptions = {\n onOutput?: (chunk: Buffer | string) => void;\n signal?: AbortSignal;\n};\n\nexport async function installPluginDependencies(\n pluginRoot: string,\n commandRoot = pluginRoot,\n options: PluginInstallExecutionOptions = {},\n): Promise<boolean> {\n const packageJsonPath = path.join(pluginRoot, 'package.json');\n if (!fs.existsSync(packageJsonPath)) {\n return false;\n }\n\n const packageJson = readPackageJson(pluginRoot);\n const commandPackageJson = commandRoot === pluginRoot ? packageJson : readPackageJson(commandRoot);\n const packageManager = Object.hasOwn(packageJson, 'packageManager')\n ? packageJson.packageManager\n : commandPackageJson.packageManager;\n const pnpmVersion = getPnpmVersion(pluginRoot, packageManager);\n const installCommand = getInstallCommand(pluginRoot, pnpmVersion);\n\n const child = execa(installCommand.command, installCommand.args, {\n cwd: pluginRoot,\n env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },\n stdout: options.onOutput ? 'pipe' : 'ignore',\n stderr: options.onOutput ? 'pipe' : 'ignore',\n cancelSignal: options.signal,\n });\n if (options.onOutput) {\n child.stdout?.on('data', options.onOutput);\n child.stderr?.on('data', options.onOutput);\n }\n try {\n await child;\n } catch (error) {\n if (isCommandNotFoundError(error)) {\n throw new Error(\n 'Mastra Code requires Corepack to install GitHub plugin dependencies. Install it with \"npm install --global corepack\" and try again.',\n { cause: error },\n );\n }\n throw error;\n }\n return true;\n}\n\nexport async function installPluginDependenciesForEntry(\n pluginRoot: string,\n entry: string,\n options: PluginInstallExecutionOptions = {},\n): Promise<void> {\n for (const dependencyRoot of getPluginDependencyRoots(pluginRoot, entry)) {\n await installPluginDependencies(dependencyRoot, pluginRoot, options);\n }\n}\n\nexport function getPluginDependencyRoots(pluginRoot: string, entry: string): string[] {\n const roots = fs.existsSync(path.join(pluginRoot, 'package.json')) ? [pluginRoot] : [];\n const entryPackageRoot = findEntryPackageRoot(pluginRoot, entry);\n if (entryPackageRoot && entryPackageRoot !== pluginRoot) {\n roots.push(entryPackageRoot);\n }\n return roots;\n}\n\nexport function getEntryPackageRoot(pluginRoot: string, entry: string): string {\n return findEntryPackageRoot(pluginRoot, entry) ?? pluginRoot;\n}\n\nfunction findEntryPackageRoot(pluginRoot: string, entry: string): string | undefined {\n const root = path.resolve(pluginRoot);\n let current = path.dirname(path.resolve(pluginRoot, entry));\n\n while (isInsideDirectory(current, root)) {\n if (fs.existsSync(path.join(current, 'package.json'))) {\n return current;\n }\n if (current === root) break;\n current = path.dirname(current);\n }\n\n return undefined;\n}\n\nfunction isInsideDirectory(targetPath: string, root: string): boolean {\n const resolvedTarget = path.resolve(targetPath);\n const resolvedRoot = path.resolve(root);\n return resolvedTarget === resolvedRoot || resolvedTarget.startsWith(resolvedRoot + path.sep);\n}\n\nfunction getPnpmVersion(pluginRoot: string, packageManager: unknown): string {\n if (typeof packageManager !== 'string') {\n throw new Error(\n `Plugin at ${pluginRoot} must declare an exact pnpm version in package.json using \"packageManager\": \"pnpm@x.y.z\".`,\n );\n }\n\n const match = /^pnpm@(\\d+\\.\\d+\\.\\d+)$/.exec(packageManager);\n if (!match?.[1]) {\n throw new Error(\n `Plugin at ${pluginRoot} must declare an exact pnpm version in package.json using \"packageManager\": \"pnpm@x.y.z\".`,\n );\n }\n return match[1];\n}\n\nfunction getInstallCommand(pluginRoot: string, pnpmVersion: string): InstallCommand {\n const installArgs = ['install', '--ignore-workspace'];\n if (hasFile(pluginRoot, 'pnpm-lock.yaml')) installArgs.push('--frozen-lockfile');\n installArgs.push('--ignore-scripts');\n\n return {\n command: 'corepack',\n args: [`pnpm@${pnpmVersion}`, ...installArgs],\n };\n}\n\nfunction isCommandNotFoundError(error: unknown): boolean {\n return typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT';\n}\n\nfunction readPackageJson(pluginRoot: string): { packageManager?: unknown } {\n const packageJsonPath = path.join(pluginRoot, 'package.json');\n if (!fs.existsSync(packageJsonPath)) return {};\n return JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as { packageManager?: unknown };\n}\n\nfunction hasFile(pluginRoot: string, fileName: string): boolean {\n return fs.existsSync(path.join(pluginRoot, fileName));\n}\n"],"mappings":"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"}
|
package/dist/plugins/install.js
CHANGED
|
@@ -1,200 +1,190 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { execa } from "execa";
|
|
4
|
-
import { DEFAULT_CONFIG_DIR } from "../constants.js";
|
|
1
|
+
import "../constants.js";
|
|
5
2
|
import { getEntryPackageRoot, installPluginDependenciesForEntry } from "./dependencies.js";
|
|
3
|
+
import { getPluginRoot, getPluginScopePaths } from "./paths.js";
|
|
4
|
+
import { loadPluginRegistry, removePluginRecord, savePluginRegistry, setPluginRecord } from "./registry.js";
|
|
6
5
|
import { loadPluginFromEntry } from "./loader.js";
|
|
7
6
|
import { getSingleManifestPlugin } from "./manifest.js";
|
|
8
7
|
import { ensureMastraCodePackageLink } from "./package-link.js";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import { execa } from "execa";
|
|
11
|
+
//#region src/plugins/install.ts
|
|
11
12
|
const ENTRY_CANDIDATES = ["src/index.ts", "index.ts"];
|
|
12
|
-
const NON_INTERACTIVE_GIT_ENV = {
|
|
13
|
+
const NON_INTERACTIVE_GIT_ENV = {
|
|
14
|
+
...process.env,
|
|
15
|
+
GIT_TERMINAL_PROMPT: "0"
|
|
16
|
+
};
|
|
13
17
|
const NON_INTERACTIVE_EXEC_OPTIONS = { env: NON_INTERACTIVE_GIT_ENV };
|
|
14
18
|
async function installLocalPlugin(localPath, scope, options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
savePluginRegistry(registryPath, setPluginRecord(registry, plugin.id, record));
|
|
33
|
-
return plugin.id;
|
|
19
|
+
const sourcePath = path.resolve(options.projectRoot, localPath);
|
|
20
|
+
if (!fs.existsSync(sourcePath) || !fs.statSync(sourcePath).isDirectory()) throw new Error(`Local plugin path does not exist or is not a directory: ${localPath}`);
|
|
21
|
+
const entry = detectEntry(sourcePath, options.entry);
|
|
22
|
+
ensureMastraCodePackageLink(sourcePath);
|
|
23
|
+
const plugin = await loadPluginFromEntry(path.join(sourcePath, entry));
|
|
24
|
+
const registryPath = getPluginScopePaths(scope, options).registryPath;
|
|
25
|
+
const registry = removePluginRecord(loadPluginRegistry(registryPath), plugin.id);
|
|
26
|
+
const record = {
|
|
27
|
+
enabled: true,
|
|
28
|
+
source: "local",
|
|
29
|
+
specifier: localPath,
|
|
30
|
+
path: sourcePath,
|
|
31
|
+
entry,
|
|
32
|
+
...plugin.version ? { version: plugin.version } : {}
|
|
33
|
+
};
|
|
34
|
+
savePluginRegistry(registryPath, setPluginRecord(registry, plugin.id, record));
|
|
35
|
+
return plugin.id;
|
|
34
36
|
}
|
|
35
37
|
async function installGithubPlugin(url, scope, options) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
38
|
+
const parsed = parseGithubUrl(url);
|
|
39
|
+
const paths = getPluginScopePaths(scope, options);
|
|
40
|
+
const checkoutDir = path.join(paths.sourcesPath, "github", `${parsed.owner}-${parsed.repo}`);
|
|
41
|
+
const githubCli = options.githubCliPath ?? "gh";
|
|
42
|
+
await assertGithubCliAvailable(githubCli);
|
|
43
|
+
await assertGithubCliAuthenticated(githubCli);
|
|
44
|
+
fs.rmSync(checkoutDir, {
|
|
45
|
+
recursive: true,
|
|
46
|
+
force: true
|
|
47
|
+
});
|
|
48
|
+
fs.mkdirSync(path.dirname(checkoutDir), { recursive: true });
|
|
49
|
+
const ref = options.ref ?? parsed.ref;
|
|
50
|
+
await runPluginInstallCommand(githubCli, [
|
|
51
|
+
"repo",
|
|
52
|
+
"clone",
|
|
53
|
+
parsed.repoSpec,
|
|
54
|
+
checkoutDir,
|
|
55
|
+
...ref ? [] : [
|
|
56
|
+
"--",
|
|
57
|
+
"--depth",
|
|
58
|
+
"1"
|
|
59
|
+
]
|
|
60
|
+
], { env: NON_INTERACTIVE_GIT_ENV }, options);
|
|
61
|
+
if (ref) await runPluginInstallCommand("git", ["checkout", ref], {
|
|
62
|
+
cwd: checkoutDir,
|
|
63
|
+
env: NON_INTERACTIVE_GIT_ENV
|
|
64
|
+
}, options);
|
|
65
|
+
const entry = detectEntry(checkoutDir, options.entry);
|
|
66
|
+
await installPluginDependenciesForEntry(checkoutDir, entry, options);
|
|
67
|
+
ensureMastraCodePackageLink(getEntryPackageRoot(checkoutDir, entry));
|
|
68
|
+
const plugin = await loadPluginFromEntry(path.join(checkoutDir, entry));
|
|
69
|
+
const registry = removePluginRecord(loadPluginRegistry(paths.registryPath), plugin.id);
|
|
70
|
+
const record = {
|
|
71
|
+
enabled: true,
|
|
72
|
+
source: "github",
|
|
73
|
+
specifier: url,
|
|
74
|
+
path: path.relative(getPluginRoot(scope, options), checkoutDir),
|
|
75
|
+
entry,
|
|
76
|
+
...ref ? { ref } : {},
|
|
77
|
+
...plugin.version ? { version: plugin.version } : {}
|
|
78
|
+
};
|
|
79
|
+
savePluginRegistry(paths.registryPath, setPluginRecord(registry, plugin.id, record));
|
|
80
|
+
return plugin.id;
|
|
72
81
|
}
|
|
73
82
|
function discoverLocalPlugins(searchRoot, options) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
const root = path.resolve(options.projectRoot, searchRoot);
|
|
84
|
+
const localSourcesRoot = path.join(root, options.configDir ?? ".mastracode", "plugins", "sources", "local");
|
|
85
|
+
const scanRoot = isLocalSourcesDir(root) ? root : localSourcesRoot;
|
|
86
|
+
const seen = /* @__PURE__ */ new Set();
|
|
87
|
+
return discoverPluginDirs(scanRoot).filter((candidate) => {
|
|
88
|
+
if (seen.has(candidate.path)) return false;
|
|
89
|
+
seen.add(candidate.path);
|
|
90
|
+
return true;
|
|
91
|
+
}).sort((a, b) => a.name.localeCompare(b.name));
|
|
83
92
|
}
|
|
84
93
|
function isLocalSourcesDir(dir) {
|
|
85
|
-
|
|
86
|
-
return normalized.endsWith("/plugins/sources/local");
|
|
94
|
+
return dir.split(path.sep).join("/").endsWith("/plugins/sources/local");
|
|
87
95
|
}
|
|
88
96
|
function discoverPluginDirs(root) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
if (!fs.existsSync(root) || !fs.statSync(root).isDirectory()) return [];
|
|
98
|
+
return fs.readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory()).flatMap((entry) => {
|
|
99
|
+
const pluginDir = path.join(root, entry.name);
|
|
100
|
+
const detectedEntry = tryDetectEntry(pluginDir);
|
|
101
|
+
return detectedEntry ? [{
|
|
102
|
+
name: entry.name,
|
|
103
|
+
path: pluginDir,
|
|
104
|
+
entry: detectedEntry
|
|
105
|
+
}] : [];
|
|
106
|
+
});
|
|
95
107
|
}
|
|
96
108
|
function tryDetectEntry(pluginDir) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
109
|
+
try {
|
|
110
|
+
return detectEntry(pluginDir);
|
|
111
|
+
} catch {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
102
114
|
}
|
|
103
115
|
function detectEntry(pluginDir, explicitEntry) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (manifestPlugin) {
|
|
124
|
-
return detectEntry(pluginDir, manifestPlugin.entry);
|
|
125
|
-
}
|
|
126
|
-
for (const candidate of ENTRY_CANDIDATES) {
|
|
127
|
-
const entryPath = path.join(pluginDir, candidate);
|
|
128
|
-
if (fs.existsSync(entryPath) && fs.statSync(entryPath).isFile()) {
|
|
129
|
-
return candidate;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
throw new Error(`Could not find a plugin entry file. Tried: ${ENTRY_CANDIDATES.join(", ")}`);
|
|
116
|
+
const root = path.resolve(pluginDir);
|
|
117
|
+
if (explicitEntry) {
|
|
118
|
+
const entryPath = path.resolve(pluginDir, explicitEntry);
|
|
119
|
+
if (!isInsideDirectory(entryPath, root)) throw new Error("Plugin entry must be inside the plugin directory");
|
|
120
|
+
if (fs.existsSync(entryPath) && fs.statSync(entryPath).isDirectory()) {
|
|
121
|
+
const nestedEntry = detectEntry(entryPath);
|
|
122
|
+
return path.relative(root, path.join(entryPath, nestedEntry));
|
|
123
|
+
}
|
|
124
|
+
if (path.extname(entryPath) !== ".ts") throw new Error("Plugin entry must be a .ts file");
|
|
125
|
+
if (!fs.existsSync(entryPath) || !fs.statSync(entryPath).isFile()) throw new Error(`Plugin entry file does not exist: ${explicitEntry}`);
|
|
126
|
+
return path.relative(root, entryPath);
|
|
127
|
+
}
|
|
128
|
+
const manifestPlugin = getSingleManifestPlugin(pluginDir);
|
|
129
|
+
if (manifestPlugin) return detectEntry(pluginDir, manifestPlugin.entry);
|
|
130
|
+
for (const candidate of ENTRY_CANDIDATES) {
|
|
131
|
+
const entryPath = path.join(pluginDir, candidate);
|
|
132
|
+
if (fs.existsSync(entryPath) && fs.statSync(entryPath).isFile()) return candidate;
|
|
133
|
+
}
|
|
134
|
+
throw new Error(`Could not find a plugin entry file. Tried: ${ENTRY_CANDIDATES.join(", ")}`);
|
|
133
135
|
}
|
|
134
136
|
function isInsideDirectory(targetPath, root) {
|
|
135
|
-
|
|
137
|
+
return targetPath === root || targetPath.startsWith(root + path.sep);
|
|
136
138
|
}
|
|
137
139
|
async function runPluginInstallCommand(command, args, execaOptions, options) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
140
|
+
const child = execa(command, args, {
|
|
141
|
+
...execaOptions,
|
|
142
|
+
stdout: options.onOutput ? "pipe" : "ignore",
|
|
143
|
+
stderr: options.onOutput ? "pipe" : "ignore",
|
|
144
|
+
cancelSignal: options.signal
|
|
145
|
+
});
|
|
146
|
+
if (options.onOutput) {
|
|
147
|
+
child.stdout?.on("data", options.onOutput);
|
|
148
|
+
child.stderr?.on("data", options.onOutput);
|
|
149
|
+
}
|
|
150
|
+
await child;
|
|
149
151
|
}
|
|
150
152
|
async function assertGithubCliAvailable(githubCli) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
try {
|
|
154
|
+
await execa(githubCli, ["--version"], NON_INTERACTIVE_EXEC_OPTIONS);
|
|
155
|
+
} catch {
|
|
156
|
+
throw new Error("GitHub CLI is required to install GitHub plugins. Install gh and run gh auth login.");
|
|
157
|
+
}
|
|
156
158
|
}
|
|
157
159
|
async function assertGithubCliAuthenticated(githubCli) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
try {
|
|
161
|
+
await execa(githubCli, ["auth", "status"], NON_INTERACTIVE_EXEC_OPTIONS);
|
|
162
|
+
} catch {
|
|
163
|
+
throw new Error("GitHub CLI is not authenticated. Run gh auth login, then install the plugin again.");
|
|
164
|
+
}
|
|
163
165
|
}
|
|
164
166
|
function parseGithubUrl(specifier) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
throw new Error("GitHub owner and repo may only contain letters, numbers, dots, underscores, and dashes");
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
owner,
|
|
188
|
-
repo,
|
|
189
|
-
repoSpec: `${owner}/${repo}`,
|
|
190
|
-
...ref ? { ref } : {}
|
|
191
|
-
};
|
|
167
|
+
const [urlPart, ref] = specifier.split("#", 2);
|
|
168
|
+
if (!urlPart) throw new Error(`Invalid GitHub URL: ${specifier}`);
|
|
169
|
+
let url;
|
|
170
|
+
try {
|
|
171
|
+
url = new URL(urlPart);
|
|
172
|
+
} catch {
|
|
173
|
+
throw new Error(`Invalid GitHub URL: ${specifier}`);
|
|
174
|
+
}
|
|
175
|
+
if (url.hostname !== "github.com") throw new Error("Only github.com plugin URLs are supported");
|
|
176
|
+
const [owner, rawRepo, ...rest] = url.pathname.split("/").filter(Boolean);
|
|
177
|
+
if (!owner || !rawRepo || rest.length > 0) throw new Error("GitHub plugin URL must be in the form https://github.com/owner/repo");
|
|
178
|
+
const repo = rawRepo.replace(/\.git$/, "");
|
|
179
|
+
if (!/^[A-Za-z0-9_.-]+$/.test(owner) || !/^[A-Za-z0-9_.-]+$/.test(repo)) throw new Error("GitHub owner and repo may only contain letters, numbers, dots, underscores, and dashes");
|
|
180
|
+
return {
|
|
181
|
+
owner,
|
|
182
|
+
repo,
|
|
183
|
+
repoSpec: `${owner}/${repo}`,
|
|
184
|
+
...ref ? { ref } : {}
|
|
185
|
+
};
|
|
192
186
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
discoverLocalPlugins,
|
|
197
|
-
installGithubPlugin,
|
|
198
|
-
installLocalPlugin
|
|
199
|
-
};
|
|
187
|
+
//#endregion
|
|
188
|
+
export { NON_INTERACTIVE_GIT_ENV, detectEntry, discoverLocalPlugins, installGithubPlugin, installLocalPlugin };
|
|
189
|
+
|
|
200
190
|
//# sourceMappingURL=install.js.map
|