mastracode 0.26.0-alpha.6 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +104 -0
- package/dist/{acp-7ADCI4VS.js → acp-G5OLW7EV.js} +4 -4
- package/dist/{acp-7ADCI4VS.js.map → acp-G5OLW7EV.js.map} +1 -1
- package/dist/{acp-4KUBWHJK.cjs → acp-YSYEXVBE.cjs} +6 -6
- package/dist/{acp-4KUBWHJK.cjs.map → acp-YSYEXVBE.cjs.map} +1 -1
- package/dist/agents/modes/plan.d.ts.map +1 -1
- package/dist/agents/prompts/plan.d.ts +5 -4
- package/dist/agents/prompts/plan.d.ts.map +1 -1
- package/dist/agents/tool-availability.d.ts +5 -1
- package/dist/agents/tool-availability.d.ts.map +1 -1
- package/dist/{chunk-SHA3DXLU.js → chunk-GT3A3LAA.js} +119 -41
- package/dist/chunk-GT3A3LAA.js.map +1 -0
- package/dist/{chunk-DVBJN36L.cjs → chunk-KGBCGF6C.cjs} +47 -23
- package/dist/chunk-KGBCGF6C.cjs.map +1 -0
- package/dist/{chunk-IXP7JO6S.js → chunk-LUSQ75XP.js} +122 -66
- package/dist/chunk-LUSQ75XP.js.map +1 -0
- package/dist/{chunk-F3TKSK3C.js → chunk-NDCWIAKG.js} +43 -21
- package/dist/chunk-NDCWIAKG.js.map +1 -0
- package/dist/{chunk-EMEAUCQ7.cjs → chunk-NUKVNLFS.cjs} +1046 -990
- package/dist/chunk-NUKVNLFS.cjs.map +1 -0
- package/dist/{chunk-QPIUDTEY.cjs → chunk-Z3HFSXTB.cjs} +153 -75
- package/dist/chunk-Z3HFSXTB.cjs.map +1 -0
- package/dist/cli.cjs +19 -19
- package/dist/cli.js +4 -4
- package/dist/index.cjs +7 -7
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/processors/plan-rejection-abort.d.ts.map +1 -1
- package/dist/tui/components/plan-approval-inline.d.ts.map +1 -1
- package/dist/tui/handlers/agent-lifecycle.d.ts.map +1 -1
- package/dist/tui/handlers/prompts.d.ts +1 -1
- package/dist/tui/handlers/prompts.d.ts.map +1 -1
- package/dist/tui/render-messages.d.ts.map +1 -1
- package/dist/tui/state.d.ts +8 -2
- package/dist/tui/state.d.ts.map +1 -1
- package/dist/tui.cjs +19 -19
- package/dist/tui.js +2 -2
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.d.ts.map +1 -0
- package/dist/utils/plans.d.ts +41 -12
- package/dist/utils/plans.d.ts.map +1 -1
- package/package.json +16 -16
- package/dist/chunk-DVBJN36L.cjs.map +0 -1
- package/dist/chunk-EMEAUCQ7.cjs.map +0 -1
- package/dist/chunk-F3TKSK3C.js.map +0 -1
- package/dist/chunk-IXP7JO6S.js.map +0 -1
- package/dist/chunk-QPIUDTEY.cjs.map +0 -1
- package/dist/chunk-SHA3DXLU.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkKGBCGF6C_cjs = require('./chunk-KGBCGF6C.cjs');
|
|
4
4
|
var chunkBULVNQ2P_cjs = require('./chunk-BULVNQ2P.cjs');
|
|
5
5
|
var chunkJHYTJMKT_cjs = require('./chunk-JHYTJMKT.cjs');
|
|
6
6
|
var crypto = require('crypto');
|
|
@@ -338,7 +338,10 @@ When something breaks:
|
|
|
338
338
|
`;
|
|
339
339
|
|
|
340
340
|
// src/agents/prompts/plan.ts
|
|
341
|
-
|
|
341
|
+
function planModePrompt(_ctx) {
|
|
342
|
+
const plansDir = chunkKGBCGF6C_cjs.getLocalPlansRelativeDir();
|
|
343
|
+
const examplePath = `${plansDir}/add-dark-mode.md`;
|
|
344
|
+
return `
|
|
342
345
|
# Plan Mode \u2014 READ-ONLY (except plan files)
|
|
343
346
|
|
|
344
347
|
You are in PLAN mode. Your job is to explore the codebase and design an implementation plan \u2014 NOT to make changes to the project.
|
|
@@ -351,7 +354,7 @@ This mode is **read-only for project files**. You must NOT modify the project.
|
|
|
351
354
|
- Do NOT run commands that change state (no git commit, no npm install, no file creation)
|
|
352
355
|
- Do NOT run build commands, tests, or scripts that have side effects
|
|
353
356
|
|
|
354
|
-
The ONE exception is
|
|
357
|
+
The ONE exception is plan files: you CAN create and edit markdown files inside \`${plansDir}/\` (e.g. \`${examplePath}\`). You may NOT write anywhere else.
|
|
355
358
|
|
|
356
359
|
If the user asks you to make changes while in Plan mode, explain that you're in read-only mode and they should switch to Build mode (\`/mode build\`) first.
|
|
357
360
|
|
|
@@ -397,24 +400,25 @@ For each step:
|
|
|
397
400
|
|
|
398
401
|
## Plan File Workflow
|
|
399
402
|
|
|
400
|
-
|
|
403
|
+
Write each plan to its own markdown file under \`${plansDir}/\` (e.g. \`${examplePath}\`). Start the file with a \`# Title\` heading describing the plan.
|
|
401
404
|
|
|
402
|
-
1. **First submission**: Write your plan to
|
|
403
|
-
2. **Reading**: Use \`view\` to read
|
|
405
|
+
1. **First submission**: Write your plan to a file under \`${plansDir}/\` using \`write_file\`, then call \`submit_plan\` with the \`path\` to that file.
|
|
406
|
+
2. **Reading**: Use \`view\` to read a plan file.
|
|
404
407
|
3. **Editing**: Use \`string_replace_lsp\` for targeted edits to specific sections.
|
|
405
408
|
|
|
409
|
+
**Reuse the same file while you keep iterating on the same plan.** Only create a NEW file when you're starting a genuinely different plan \u2014 that keeps each plan available to look back at and keeps revision diffs meaningful.
|
|
410
|
+
|
|
406
411
|
## IMMEDIATE ACTION: Write plan file, then call submit_plan
|
|
407
412
|
|
|
408
413
|
As soon as your plan is complete:
|
|
409
|
-
1. Write it to
|
|
410
|
-
2. Call \`submit_plan\` with the
|
|
414
|
+
1. Write it to a file under \`${plansDir}/\` using \`write_file\`
|
|
415
|
+
2. Call \`submit_plan\` with the \`path\` to that file
|
|
411
416
|
|
|
412
|
-
**CRITICAL:** Do NOT generate a long text response describing your plan. The plan content belongs in the file
|
|
417
|
+
**CRITICAL:** Do NOT generate a long text response describing your plan. The plan content belongs in the plan file, not in your text output or the \`submit_plan\` arguments.
|
|
413
418
|
|
|
414
419
|
\`\`\`javascript
|
|
415
420
|
submit_plan({
|
|
416
|
-
|
|
417
|
-
plan: "your full plan in markdown"
|
|
421
|
+
path: "${examplePath}"
|
|
418
422
|
})
|
|
419
423
|
\`\`\`
|
|
420
424
|
|
|
@@ -426,17 +430,16 @@ The user will see the plan rendered inline and can:
|
|
|
426
430
|
## Revision Workflow
|
|
427
431
|
|
|
428
432
|
If the user requests changes, you will be stopped immediately. Wait for their next message \u2014 it will contain their revision feedback. When you receive it:
|
|
429
|
-
1. Use \`view\` to read
|
|
433
|
+
1. Use \`view\` to read the SAME plan file
|
|
430
434
|
2. Use \`string_replace_lsp\` to make targeted edits based on feedback
|
|
431
435
|
3. Use \`view\` to re-read the updated file
|
|
432
|
-
4. Call \`submit_plan\` again with the
|
|
433
|
-
|
|
434
|
-
The user will see a diff of what changed between the previous and revised plan. Use \`string_replace_lsp\` for targeted edits so the diff is clear and meaningful \u2014 do NOT rewrite the entire plan from scratch for small changes.
|
|
436
|
+
4. Call \`submit_plan\` again with the same \`path\` \u2014 editing the file alone does NOT resubmit it
|
|
435
437
|
|
|
436
|
-
|
|
438
|
+
The user will see a diff of what changed between the previous and revised plan. Use \`string_replace_lsp\` for targeted edits so the diff is clear and meaningful \u2014 do NOT rewrite the entire plan from scratch for small changes, and do NOT move the plan to a new file for a revision.
|
|
437
439
|
|
|
438
440
|
Do NOT start implementing until the plan is approved.
|
|
439
441
|
`;
|
|
442
|
+
}
|
|
440
443
|
|
|
441
444
|
// src/agents/prompts/fast.ts
|
|
442
445
|
var fastModePrompt = `
|
|
@@ -527,10 +530,62 @@ Error: ${r.error}`);
|
|
|
527
530
|
}
|
|
528
531
|
});
|
|
529
532
|
}
|
|
530
|
-
|
|
531
|
-
|
|
533
|
+
var PLAN_MODE_WRITE_TOOL_NAMES = /* @__PURE__ */ new Set([
|
|
534
|
+
workspace.WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE,
|
|
535
|
+
workspace.WORKSPACE_TOOLS.FILESYSTEM.EDIT_FILE
|
|
536
|
+
]);
|
|
537
|
+
function getRequestContextValue(requestContext, key) {
|
|
538
|
+
if (!requestContext) return void 0;
|
|
539
|
+
if (typeof requestContext.get === "function") {
|
|
540
|
+
return requestContext.get(key);
|
|
541
|
+
}
|
|
542
|
+
return requestContext[key];
|
|
543
|
+
}
|
|
544
|
+
function getHarnessContext(context) {
|
|
545
|
+
const requestContext = context?.requestContext;
|
|
546
|
+
const harness = getRequestContextValue(requestContext, "harness");
|
|
547
|
+
return harness && typeof harness === "object" ? harness : void 0;
|
|
548
|
+
}
|
|
549
|
+
function getHarnessState(harness) {
|
|
550
|
+
const state = harness?.session?.state?.get?.();
|
|
551
|
+
return state && typeof state === "object" ? state : void 0;
|
|
552
|
+
}
|
|
553
|
+
function getHarnessModeId(harness) {
|
|
554
|
+
const modeId = harness?.session?.modeId ?? getHarnessState(harness)?.modeId;
|
|
555
|
+
return typeof modeId === "string" ? modeId : void 0;
|
|
556
|
+
}
|
|
557
|
+
function getHarnessProjectPath(harness) {
|
|
558
|
+
const projectPath = getHarnessState(harness)?.projectPath;
|
|
559
|
+
return typeof projectPath === "string" ? projectPath : void 0;
|
|
560
|
+
}
|
|
561
|
+
function getToolInputPath(input) {
|
|
562
|
+
const toolPath = input?.path;
|
|
563
|
+
return typeof toolPath === "string" ? toolPath : void 0;
|
|
564
|
+
}
|
|
565
|
+
var PLAN_DIR_HINT = `${chunkKGBCGF6C_cjs.getLocalPlansRelativeDir()}/`;
|
|
566
|
+
function guardPlanModePlanFileWrites({ workspaceToolName, input, context }) {
|
|
567
|
+
if (!PLAN_MODE_WRITE_TOOL_NAMES.has(workspaceToolName)) return;
|
|
568
|
+
const harness = getHarnessContext(context);
|
|
569
|
+
if (getHarnessModeId(harness) !== "plan") return;
|
|
570
|
+
const projectPath = getHarnessProjectPath(harness);
|
|
571
|
+
const inputPath = getToolInputPath(input);
|
|
572
|
+
if (!projectPath || !inputPath) {
|
|
573
|
+
return {
|
|
574
|
+
proceed: false,
|
|
575
|
+
output: `Plan mode can only write plan files inside ${PLAN_DIR_HINT}.`
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
if (chunkKGBCGF6C_cjs.isPlanFilePath(projectPath, inputPath)) return;
|
|
579
|
+
return {
|
|
580
|
+
proceed: false,
|
|
581
|
+
output: `Plan mode can only write plan files inside ${PLAN_DIR_HINT}. Refusing to edit ${inputPath}.`
|
|
582
|
+
};
|
|
583
|
+
}
|
|
532
584
|
var MASTRACODE_WORKSPACE_TOOLS = {
|
|
533
|
-
...chunkJHYTJMKT_cjs.TOOL_NAME_OVERRIDES
|
|
585
|
+
...chunkJHYTJMKT_cjs.TOOL_NAME_OVERRIDES,
|
|
586
|
+
hooks: {
|
|
587
|
+
beforeToolCall: guardPlanModePlanFileWrites
|
|
588
|
+
}
|
|
534
589
|
};
|
|
535
590
|
var PLAN_MODE_AVAILABLE_TOOLS = [
|
|
536
591
|
// Read-only exploration tools
|
|
@@ -539,9 +594,8 @@ var PLAN_MODE_AVAILABLE_TOOLS = [
|
|
|
539
594
|
chunkJHYTJMKT_cjs.MC_TOOLS.SEARCH_CONTENT,
|
|
540
595
|
chunkJHYTJMKT_cjs.MC_TOOLS.FILE_STAT,
|
|
541
596
|
chunkJHYTJMKT_cjs.MC_TOOLS.LSP_INSPECT,
|
|
542
|
-
// Plan file writing
|
|
543
|
-
//
|
|
544
|
-
// scope writes to .mastracode/plans/)
|
|
597
|
+
// Plan file writing. Tool hooks enforce that these can only write `.md`
|
|
598
|
+
// files inside `.mastracode/plans/` while the session is in plan mode.
|
|
545
599
|
chunkJHYTJMKT_cjs.MC_TOOLS.WRITE_FILE,
|
|
546
600
|
chunkJHYTJMKT_cjs.MC_TOOLS.STRING_REPLACE_LSP,
|
|
547
601
|
// Plan delivery tools
|
|
@@ -631,7 +685,7 @@ function buildSkillPaths(projectPath, configDir, homeDir = os__namespace.default
|
|
|
631
685
|
agentSkillsGlobalPath
|
|
632
686
|
]);
|
|
633
687
|
}
|
|
634
|
-
var DEFAULT_ALLOWED_PATHS = [os__namespace.default.tmpdir(), "/tmp",
|
|
688
|
+
var DEFAULT_ALLOWED_PATHS = [os__namespace.default.tmpdir(), "/tmp", chunkKGBCGF6C_cjs.getPlansDir()].reduce((acc, p) => {
|
|
635
689
|
const resolved = path__namespace.default.resolve(p);
|
|
636
690
|
if (!acc.includes(resolved)) acc.push(resolved);
|
|
637
691
|
return acc;
|
|
@@ -668,8 +722,8 @@ function getDynamicWorkspace({ requestContext, mastra: mastra2 }) {
|
|
|
668
722
|
existing.setToolsConfig(workspaceTools);
|
|
669
723
|
return existing;
|
|
670
724
|
}
|
|
671
|
-
const userLsp =
|
|
672
|
-
const mcModulePath = path.join(path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
725
|
+
const userLsp = chunkKGBCGF6C_cjs.loadSettings().lsp ?? {};
|
|
726
|
+
const mcModulePath = path.join(path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-Z3HFSXTB.cjs', document.baseURI).href)))), "..");
|
|
673
727
|
const lspConfig = {
|
|
674
728
|
...userLsp,
|
|
675
729
|
packageRunner: userLsp.packageRunner || detectPackageRunner(projectPath),
|
|
@@ -1055,14 +1109,14 @@ ${patchToolGuidance}
|
|
|
1055
1109
|
- Call this tool when your plan is complete. Do NOT just describe your plan in text \u2014 you MUST call this tool.
|
|
1056
1110
|
- The plan will be rendered as markdown and the user can approve, reject, or request changes.
|
|
1057
1111
|
- On approval, the system automatically switches to the default mode so you can implement.
|
|
1058
|
-
- Takes
|
|
1112
|
+
- Takes one argument: \`path\` (the plan markdown file you wrote under \`.mastracode/plans/\`). Do NOT pass the plan body \u2014 it lives in the file.`);
|
|
1059
1113
|
}
|
|
1060
1114
|
if (modeId === "plan") {
|
|
1061
1115
|
sections.push(`
|
|
1062
|
-
**Plan file access** \u2014 Your plan lives in \`.mastracode/plans/\`
|
|
1116
|
+
**Plan file access** \u2014 Your plan lives in a markdown file under \`.mastracode/plans/\` (e.g. \`add-dark-mode-toggle.md\`)
|
|
1063
1117
|
- Use \`write_file\` to create the plan file, \`view\` to read it, and \`string_replace_lsp\` for targeted edits.
|
|
1064
|
-
- On first submission: write the plan to the file, then call \`submit_plan\`.
|
|
1065
|
-
- On revision: read the existing file, edit specific sections, re-read, then call \`submit_plan\` with
|
|
1118
|
+
- On first submission: write the plan to the file, then call \`submit_plan\` with its \`path\`.
|
|
1119
|
+
- On revision: read the existing file, edit specific sections, re-read, then call \`submit_plan\` with the same \`path\`.
|
|
1066
1120
|
- If a plan file already exists, you previously submitted it \u2014 read it before revising.`);
|
|
1067
1121
|
}
|
|
1068
1122
|
if (!denied.has("subagent")) {
|
|
@@ -1688,7 +1742,7 @@ var MastraCodeGateway = class _MastraCodeGateway extends llm.MastraModelGateway
|
|
|
1688
1742
|
this.#settingsPath = settingsPath;
|
|
1689
1743
|
}
|
|
1690
1744
|
static getMemoryGatewayApiKey() {
|
|
1691
|
-
return authStorage.getStoredApiKey(
|
|
1745
|
+
return authStorage.getStoredApiKey(chunkKGBCGF6C_cjs.MEMORY_GATEWAY_PROVIDER) ?? process.env["MASTRA_GATEWAY_API_KEY"];
|
|
1692
1746
|
}
|
|
1693
1747
|
/**
|
|
1694
1748
|
* Claim an unprefixed model id (e.g. a bare `anthropic/...`) when this gateway
|
|
@@ -1701,7 +1755,7 @@ var MastraCodeGateway = class _MastraCodeGateway extends llm.MastraModelGateway
|
|
|
1701
1755
|
if (!parsed.providerId || !parsed.modelId) return false;
|
|
1702
1756
|
if (this.#routeThroughMastraGateway && this.#mastraGatewayApiKey) return true;
|
|
1703
1757
|
const customProvider = this.#getCustomProviders().find(
|
|
1704
|
-
(provider) => parsed.providerId ===
|
|
1758
|
+
(provider) => parsed.providerId === chunkKGBCGF6C_cjs.getCustomProviderId(provider.name)
|
|
1705
1759
|
);
|
|
1706
1760
|
if (customProvider?.apiKey) return true;
|
|
1707
1761
|
return hasResolvedAuth(
|
|
@@ -1752,14 +1806,14 @@ var MastraCodeGateway = class _MastraCodeGateway extends llm.MastraModelGateway
|
|
|
1752
1806
|
return _MastraCodeGateway.createModelCatalogProvider(this);
|
|
1753
1807
|
}
|
|
1754
1808
|
#getCustomProviders() {
|
|
1755
|
-
return this.#customProviders ??
|
|
1809
|
+
return this.#customProviders ?? chunkKGBCGF6C_cjs.loadSettings(this.#settingsPath).customProviders;
|
|
1756
1810
|
}
|
|
1757
1811
|
async fetchProviders() {
|
|
1758
1812
|
const providers = {};
|
|
1759
1813
|
for (const provider of this.#getCustomProviders()) {
|
|
1760
1814
|
const models = provider.models ?? [];
|
|
1761
1815
|
if (!models.length) continue;
|
|
1762
|
-
providers[
|
|
1816
|
+
providers[chunkKGBCGF6C_cjs.getCustomProviderId(provider.name)] = {
|
|
1763
1817
|
name: provider.name,
|
|
1764
1818
|
url: provider.url,
|
|
1765
1819
|
apiKeyEnvVar: "",
|
|
@@ -1795,7 +1849,7 @@ var MastraCodeGateway = class _MastraCodeGateway extends llm.MastraModelGateway
|
|
|
1795
1849
|
return { apiKey: this.#mastraGatewayApiKey, source: "gateway" };
|
|
1796
1850
|
}
|
|
1797
1851
|
const customProvider = this.#getCustomProviders().find(
|
|
1798
|
-
(provider) => request.providerId ===
|
|
1852
|
+
(provider) => request.providerId === chunkKGBCGF6C_cjs.getCustomProviderId(provider.name)
|
|
1799
1853
|
);
|
|
1800
1854
|
if (customProvider?.apiKey) {
|
|
1801
1855
|
return { apiKey: customProvider.apiKey, source: "gateway" };
|
|
@@ -1804,7 +1858,7 @@ var MastraCodeGateway = class _MastraCodeGateway extends llm.MastraModelGateway
|
|
|
1804
1858
|
}
|
|
1805
1859
|
resolveLanguageModel(args) {
|
|
1806
1860
|
const customProvider = this.#getCustomProviders().find(
|
|
1807
|
-
(provider) => args.providerId ===
|
|
1861
|
+
(provider) => args.providerId === chunkKGBCGF6C_cjs.getCustomProviderId(provider.name)
|
|
1808
1862
|
);
|
|
1809
1863
|
if (customProvider) {
|
|
1810
1864
|
const provider = openaiCompatible.createOpenAICompatible({
|
|
@@ -1888,9 +1942,9 @@ var MastraCodeGateway = class _MastraCodeGateway extends llm.MastraModelGateway
|
|
|
1888
1942
|
const resolvedModelId = remapOpenAIModelForCodexOAuth(`openai/${args.modelId}`);
|
|
1889
1943
|
const resolvedBareModelId = resolvedModelId.substring(OPENAI_PREFIX.length);
|
|
1890
1944
|
const requestedLevel = this.#thinkingLevel ?? "medium";
|
|
1891
|
-
const effectiveLevel =
|
|
1892
|
-
const reasoningEffort =
|
|
1893
|
-
const middleware =
|
|
1945
|
+
const effectiveLevel = chunkKGBCGF6C_cjs.getEffectiveThinkingLevel(resolvedBareModelId, requestedLevel);
|
|
1946
|
+
const reasoningEffort = chunkKGBCGF6C_cjs.THINKING_LEVEL_TO_REASONING_EFFORT[effectiveLevel];
|
|
1947
|
+
const middleware = chunkKGBCGF6C_cjs.createCodexMiddleware(reasoningEffort);
|
|
1894
1948
|
const openai$1 = openai.createOpenAI({
|
|
1895
1949
|
apiKey: "oauth-gateway-placeholder",
|
|
1896
1950
|
baseURL: `${this.#mastraGatewayBaseUrl}/v1`,
|
|
@@ -1898,7 +1952,7 @@ var MastraCodeGateway = class _MastraCodeGateway extends llm.MastraModelGateway
|
|
|
1898
1952
|
[llm.GATEWAY_AUTH_HEADER]: `Bearer ${args.apiKey}`,
|
|
1899
1953
|
...args.headers
|
|
1900
1954
|
},
|
|
1901
|
-
fetch:
|
|
1955
|
+
fetch: chunkKGBCGF6C_cjs.buildOpenAICodexOAuthFetch({ authStorage, rewriteUrl: false })
|
|
1902
1956
|
});
|
|
1903
1957
|
return ai.wrapLanguageModel({
|
|
1904
1958
|
model: openai$1.responses(resolvedBareModelId),
|
|
@@ -1909,7 +1963,7 @@ var MastraCodeGateway = class _MastraCodeGateway extends llm.MastraModelGateway
|
|
|
1909
1963
|
}
|
|
1910
1964
|
if (storedCred?.type === "oauth") {
|
|
1911
1965
|
const resolvedModelId = remapOpenAIModelForCodexOAuth(`openai/${args.modelId}`);
|
|
1912
|
-
return
|
|
1966
|
+
return chunkKGBCGF6C_cjs.openaiCodexProvider(resolvedModelId.substring(OPENAI_PREFIX.length), {
|
|
1913
1967
|
thinkingLevel: this.#thinkingLevel,
|
|
1914
1968
|
headers: args.headers
|
|
1915
1969
|
});
|
|
@@ -1937,7 +1991,7 @@ function createMastraCodeGateway(options) {
|
|
|
1937
1991
|
function resolveModel(modelId, options) {
|
|
1938
1992
|
reloadAuthStorage();
|
|
1939
1993
|
const headers = getAgentControllerHeaders(options?.requestContext);
|
|
1940
|
-
const settings =
|
|
1994
|
+
const settings = chunkKGBCGF6C_cjs.loadSettings();
|
|
1941
1995
|
const isMastraGatewayModel = modelId.startsWith(MASTRA_GATEWAY_PREFIX);
|
|
1942
1996
|
const normalizedModelId = stripMastraGatewayPrefix(modelId);
|
|
1943
1997
|
const [providerId, ...modelParts] = normalizedModelId.split("/");
|
|
@@ -1978,7 +2032,7 @@ function getDynamicModel({ requestContext }) {
|
|
|
1978
2032
|
return resolveModel(modelId, { thinkingLevel, requestContext });
|
|
1979
2033
|
}
|
|
1980
2034
|
function getGoalJudgeModel({ requestContext }, settingsPath) {
|
|
1981
|
-
const judgeModelId =
|
|
2035
|
+
const judgeModelId = chunkKGBCGF6C_cjs.loadSettings(settingsPath).models.goalJudgeModel;
|
|
1982
2036
|
if (!judgeModelId) return void 0;
|
|
1983
2037
|
return resolveModel(judgeModelId, { requestContext });
|
|
1984
2038
|
}
|
|
@@ -2170,7 +2224,7 @@ var planMode = {
|
|
|
2170
2224
|
|
|
2171
2225
|
## Rules
|
|
2172
2226
|
- You have READ-ONLY access to the project. You cannot modify project files or run commands.
|
|
2173
|
-
- The one exception is
|
|
2227
|
+
- The one exception is plan files: you can create and edit markdown files inside \`.mastracode/plans/\` using \`write_file\`, \`view\`, and \`string_replace_lsp\`. You may not write anywhere else.
|
|
2174
2228
|
- First, explore the codebase to understand existing patterns, architecture, and conventions.
|
|
2175
2229
|
- Produce a concrete, actionable plan \u2014 not vague suggestions.
|
|
2176
2230
|
|
|
@@ -2181,11 +2235,13 @@ var planMode = {
|
|
|
2181
2235
|
- **Parallelize**: Make multiple independent tool calls when exploring different areas
|
|
2182
2236
|
|
|
2183
2237
|
## Plan Delivery
|
|
2184
|
-
- Write your plan to \`.mastracode/plans
|
|
2185
|
-
-
|
|
2238
|
+
- Write your plan to a markdown file under \`.mastracode/plans/\` (e.g. \`.mastracode/plans/add-dark-mode.md\`) using \`write_file\`, then call \`submit_plan({ path })\` with the path to that file (never the plan body).
|
|
2239
|
+
- Start the file with a \`# Title\` heading describing the plan.
|
|
2240
|
+
- Reuse the same file while iterating on the same plan; only create a new file for a genuinely different plan so each plan stays available to review.
|
|
2241
|
+
- Do NOT output the plan as text \u2014 it MUST live in the plan file.
|
|
2186
2242
|
- Be concise: reference files by path and line number, don't include raw contents.
|
|
2187
2243
|
- Focus on actionable details, not general observations.
|
|
2188
|
-
-
|
|
2244
|
+
- To revise after "Request changes", edit the same file in place with \`string_replace_lsp\`, and call \`submit_plan\` again with the same path.`,
|
|
2189
2245
|
metadata: {
|
|
2190
2246
|
default: false
|
|
2191
2247
|
},
|
|
@@ -3742,6 +3798,21 @@ function createMcpManager(projectDir, configDirName = chunkBULVNQ2P_cjs.DEFAULT_
|
|
|
3742
3798
|
|
|
3743
3799
|
// src/processors/plan-rejection-abort.ts
|
|
3744
3800
|
var PLAN_REJECTED_PREFIX = "Plan was not approved";
|
|
3801
|
+
function resultText(result) {
|
|
3802
|
+
if (typeof result === "string") return result;
|
|
3803
|
+
if (result && typeof result === "object") {
|
|
3804
|
+
const content = result.content;
|
|
3805
|
+
if (typeof content === "string") return content;
|
|
3806
|
+
}
|
|
3807
|
+
return "";
|
|
3808
|
+
}
|
|
3809
|
+
function isPlanRejection(inv) {
|
|
3810
|
+
if (!inv || inv.state !== "result" || inv.toolName !== "submit_plan") return false;
|
|
3811
|
+
return resultText(inv.result).startsWith(PLAN_REJECTED_PREFIX);
|
|
3812
|
+
}
|
|
3813
|
+
function isPlanRejectionResultPart(part) {
|
|
3814
|
+
return part.type === "tool_result" && part.name === "submit_plan" && resultText(part.result).startsWith(PLAN_REJECTED_PREFIX);
|
|
3815
|
+
}
|
|
3745
3816
|
var PlanRejectionAbortProcessor = class {
|
|
3746
3817
|
id = "plan-rejection-abort";
|
|
3747
3818
|
async processInputStep({ messages, stepNumber, abort }) {
|
|
@@ -3750,18 +3821,24 @@ var PlanRejectionAbortProcessor = class {
|
|
|
3750
3821
|
const msg = messages[i];
|
|
3751
3822
|
if (!msg || msg.role !== "assistant") continue;
|
|
3752
3823
|
const content = msg.content;
|
|
3753
|
-
const parts = content?.parts;
|
|
3754
|
-
if (!Array.isArray(parts)) break;
|
|
3824
|
+
const parts = Array.isArray(content) ? content : Array.isArray(content?.parts) ? content.parts : [];
|
|
3755
3825
|
for (const part of parts) {
|
|
3756
3826
|
if (!part || typeof part !== "object") continue;
|
|
3757
3827
|
const p = part;
|
|
3758
|
-
if (p.type
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3828
|
+
if (p.type === "tool-invocation" && isPlanRejection(p.toolInvocation)) {
|
|
3829
|
+
abort("Plan rejected by user \u2014 no further response needed");
|
|
3830
|
+
return void 0;
|
|
3831
|
+
}
|
|
3832
|
+
if (isPlanRejectionResultPart(p)) {
|
|
3833
|
+
abort("Plan rejected by user \u2014 no further response needed");
|
|
3834
|
+
return void 0;
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
const legacy = !Array.isArray(content) && Array.isArray(content?.toolInvocations) ? content.toolInvocations : [];
|
|
3838
|
+
for (const inv of legacy) {
|
|
3839
|
+
if (isPlanRejection(inv)) {
|
|
3764
3840
|
abort("Plan rejected by user \u2014 no further response needed");
|
|
3841
|
+
return void 0;
|
|
3765
3842
|
}
|
|
3766
3843
|
}
|
|
3767
3844
|
break;
|
|
@@ -4078,14 +4155,14 @@ function applyEffectiveDefaultsToModes(modes, effectiveDefaults) {
|
|
|
4078
4155
|
function createAuthStorage() {
|
|
4079
4156
|
const authStorage2 = new chunkBULVNQ2P_cjs.AuthStorage();
|
|
4080
4157
|
setAuthStorage2(authStorage2);
|
|
4081
|
-
|
|
4158
|
+
chunkKGBCGF6C_cjs.setAuthStorage(authStorage2);
|
|
4082
4159
|
setAuthStorage3(authStorage2);
|
|
4083
4160
|
return authStorage2;
|
|
4084
4161
|
}
|
|
4085
4162
|
function resolveCloudObservabilityConfig(settings, authStorage2, resourceId) {
|
|
4086
4163
|
const resourceConfig = settings.observability.resources[resourceId];
|
|
4087
4164
|
if (resourceConfig) {
|
|
4088
|
-
const token = authStorage2.getStoredApiKey(`${
|
|
4165
|
+
const token = authStorage2.getStoredApiKey(`${chunkKGBCGF6C_cjs.OBSERVABILITY_AUTH_PREFIX}${resourceId}`);
|
|
4089
4166
|
if (token) {
|
|
4090
4167
|
return { accessToken: token, projectId: resourceConfig.projectId };
|
|
4091
4168
|
}
|
|
@@ -4108,8 +4185,8 @@ async function createMastraCodeAgentController(config) {
|
|
|
4108
4185
|
} catch {
|
|
4109
4186
|
}
|
|
4110
4187
|
const authStorage2 = createAuthStorage();
|
|
4111
|
-
const globalSettings =
|
|
4112
|
-
const storedGatewayKey = authStorage2.getStoredApiKey(
|
|
4188
|
+
const globalSettings = chunkKGBCGF6C_cjs.loadSettings(config?.settingsPath);
|
|
4189
|
+
const storedGatewayKey = authStorage2.getStoredApiKey(chunkKGBCGF6C_cjs.MEMORY_GATEWAY_PROVIDER);
|
|
4113
4190
|
const storedGatewayUrl = globalSettings.memoryGateway?.baseUrl;
|
|
4114
4191
|
if (storedGatewayKey) {
|
|
4115
4192
|
process.env["MASTRA_GATEWAY_API_KEY"] ??= storedGatewayKey;
|
|
@@ -4124,11 +4201,11 @@ async function createMastraCodeAgentController(config) {
|
|
|
4124
4201
|
const envVars = cfg?.apiKeyEnvVar;
|
|
4125
4202
|
providerEnvVars[provider] = Array.isArray(envVars) ? envVars[0] : envVars;
|
|
4126
4203
|
}
|
|
4127
|
-
providerEnvVars[
|
|
4204
|
+
providerEnvVars[chunkKGBCGF6C_cjs.MEMORY_GATEWAY_PROVIDER] ??= "MASTRA_GATEWAY_API_KEY";
|
|
4128
4205
|
authStorage2.loadStoredApiKeysIntoEnv(providerEnvVars);
|
|
4129
4206
|
} catch {
|
|
4130
4207
|
authStorage2.loadStoredApiKeysIntoEnv({
|
|
4131
|
-
[
|
|
4208
|
+
[chunkKGBCGF6C_cjs.MEMORY_GATEWAY_PROVIDER]: "MASTRA_GATEWAY_API_KEY",
|
|
4132
4209
|
anthropic: "ANTHROPIC_API_KEY",
|
|
4133
4210
|
openai: "OPENAI_API_KEY",
|
|
4134
4211
|
google: "GOOGLE_GENERATIVE_AI_API_KEY",
|
|
@@ -4369,21 +4446,21 @@ async function createMastraCodeAgentController(config) {
|
|
|
4369
4446
|
...buildMode,
|
|
4370
4447
|
metadata: {
|
|
4371
4448
|
...buildMode.metadata,
|
|
4372
|
-
color:
|
|
4449
|
+
color: chunkKGBCGF6C_cjs.mastra.green
|
|
4373
4450
|
}
|
|
4374
4451
|
},
|
|
4375
4452
|
{
|
|
4376
4453
|
...planMode,
|
|
4377
4454
|
metadata: {
|
|
4378
4455
|
...planMode.metadata,
|
|
4379
|
-
color:
|
|
4456
|
+
color: chunkKGBCGF6C_cjs.mastra.purple
|
|
4380
4457
|
}
|
|
4381
4458
|
},
|
|
4382
4459
|
{
|
|
4383
4460
|
...fastMode,
|
|
4384
4461
|
metadata: {
|
|
4385
4462
|
...fastMode.metadata,
|
|
4386
|
-
color:
|
|
4463
|
+
color: chunkKGBCGF6C_cjs.mastra.orange
|
|
4387
4464
|
}
|
|
4388
4465
|
}
|
|
4389
4466
|
];
|
|
@@ -4424,11 +4501,11 @@ async function createMastraCodeAgentController(config) {
|
|
|
4424
4501
|
}
|
|
4425
4502
|
} catch {
|
|
4426
4503
|
}
|
|
4427
|
-
const builtinPacks =
|
|
4428
|
-
const builtinOmPacks =
|
|
4429
|
-
const effectiveDefaults =
|
|
4430
|
-
const effectiveObserverModel =
|
|
4431
|
-
const effectiveReflectorModel =
|
|
4504
|
+
const builtinPacks = chunkKGBCGF6C_cjs.getAvailableModePacks(startupAccess);
|
|
4505
|
+
const builtinOmPacks = chunkKGBCGF6C_cjs.getAvailableOmPacks(startupAccess);
|
|
4506
|
+
const effectiveDefaults = chunkKGBCGF6C_cjs.resolveModelDefaults(globalSettings, builtinPacks);
|
|
4507
|
+
const effectiveObserverModel = chunkKGBCGF6C_cjs.resolveOmRoleModel(globalSettings, "observer", builtinOmPacks);
|
|
4508
|
+
const effectiveReflectorModel = chunkKGBCGF6C_cjs.resolveOmRoleModel(globalSettings, "reflector", builtinOmPacks);
|
|
4432
4509
|
const effectiveObservationThreshold = globalSettings.models.omObservationThreshold ?? void 0;
|
|
4433
4510
|
const effectiveReflectionThreshold = globalSettings.models.omReflectionThreshold ?? void 0;
|
|
4434
4511
|
const effectiveCavemanObservations = globalSettings.models.omCavemanObservations ?? void 0;
|
|
@@ -4485,6 +4562,7 @@ async function createMastraCodeAgentController(config) {
|
|
|
4485
4562
|
gateways: [mastraCodeGateway],
|
|
4486
4563
|
workspace: config?.workspace ?? ((args) => getDynamicWorkspace(args)),
|
|
4487
4564
|
browser: config?.browser,
|
|
4565
|
+
idGenerator: config?.idGenerator,
|
|
4488
4566
|
toolCategoryResolver: chunkJHYTJMKT_cjs.getToolCategory,
|
|
4489
4567
|
initialState: {
|
|
4490
4568
|
projectPath: project.rootPath,
|
|
@@ -4499,19 +4577,19 @@ async function createMastraCodeAgentController(config) {
|
|
|
4499
4577
|
},
|
|
4500
4578
|
modes,
|
|
4501
4579
|
heartbeatHandlers,
|
|
4502
|
-
modelUseCountProvider: () =>
|
|
4580
|
+
modelUseCountProvider: () => chunkKGBCGF6C_cjs.loadSettings().modelUseCounts,
|
|
4503
4581
|
modelUseCountTracker: (modelId) => {
|
|
4504
4582
|
try {
|
|
4505
|
-
const settings =
|
|
4583
|
+
const settings = chunkKGBCGF6C_cjs.loadSettings();
|
|
4506
4584
|
settings.modelUseCounts[modelId] = (settings.modelUseCounts[modelId] ?? 0) + 1;
|
|
4507
|
-
|
|
4585
|
+
chunkKGBCGF6C_cjs.saveSettings(settings);
|
|
4508
4586
|
} catch (error) {
|
|
4509
4587
|
console.error("Failed to persist model usage count", error);
|
|
4510
4588
|
}
|
|
4511
4589
|
},
|
|
4512
4590
|
threadLock: crossProcessPubSub ? void 0 : {
|
|
4513
|
-
acquire:
|
|
4514
|
-
release:
|
|
4591
|
+
acquire: chunkKGBCGF6C_cjs.acquireThreadLock,
|
|
4592
|
+
release: chunkKGBCGF6C_cjs.releaseThreadLock
|
|
4515
4593
|
}
|
|
4516
4594
|
});
|
|
4517
4595
|
return {
|
|
@@ -4614,5 +4692,5 @@ exports.createMastraCode = createMastraCode;
|
|
|
4614
4692
|
exports.createMastraCodeAgentController = createMastraCodeAgentController;
|
|
4615
4693
|
exports.mountAgentControllerOnMastra = mountAgentControllerOnMastra;
|
|
4616
4694
|
exports.wireSessionConcerns = wireSessionConcerns;
|
|
4617
|
-
//# sourceMappingURL=chunk-
|
|
4618
|
-
//# sourceMappingURL=chunk-
|
|
4695
|
+
//# sourceMappingURL=chunk-Z3HFSXTB.cjs.map
|
|
4696
|
+
//# sourceMappingURL=chunk-Z3HFSXTB.cjs.map
|