mastracode 0.4.0 → 0.5.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 +328 -0
- package/LICENSE.md +15 -0
- package/README.md +68 -29
- package/dist/agents/memory.d.ts.map +1 -1
- package/dist/agents/model.d.ts +17 -6
- package/dist/agents/model.d.ts.map +1 -1
- package/dist/agents/prompts/index.d.ts.map +1 -1
- package/dist/agents/prompts/tool-guidance.d.ts +2 -0
- package/dist/agents/prompts/tool-guidance.d.ts.map +1 -1
- package/dist/agents/subagents/audit-tests.d.ts +0 -7
- package/dist/agents/subagents/audit-tests.d.ts.map +1 -1
- package/dist/agents/subagents/execute.d.ts +0 -7
- package/dist/agents/subagents/execute.d.ts.map +1 -1
- package/dist/agents/subagents/explore.d.ts +0 -7
- package/dist/agents/subagents/explore.d.ts.map +1 -1
- package/dist/agents/subagents/index.d.ts.map +1 -1
- package/dist/agents/subagents/plan.d.ts +0 -7
- package/dist/agents/subagents/plan.d.ts.map +1 -1
- package/dist/agents/tools.d.ts +3 -1
- package/dist/agents/tools.d.ts.map +1 -1
- package/dist/agents/workspace.d.ts +4 -1
- package/dist/agents/workspace.d.ts.map +1 -1
- package/dist/{chunk-K4WJUBEC.cjs → chunk-AJEYT7X3.cjs} +763 -429
- package/dist/chunk-AJEYT7X3.cjs.map +1 -0
- package/dist/{chunk-U5A7TFNT.js → chunk-CC2724NI.js} +46 -10
- package/dist/chunk-CC2724NI.js.map +1 -0
- package/dist/{chunk-REVOTI2T.js → chunk-JI4M5525.js} +740 -412
- package/dist/chunk-JI4M5525.js.map +1 -0
- package/dist/{chunk-Z4QRXVST.cjs → chunk-MBPGUMYQ.cjs} +325 -251
- package/dist/chunk-MBPGUMYQ.cjs.map +1 -0
- package/dist/{chunk-MT3YCFCC.cjs → chunk-OEDRHUU5.cjs} +47 -9
- package/dist/chunk-OEDRHUU5.cjs.map +1 -0
- package/dist/{chunk-M5LKPQB4.js → chunk-WKPHD54B.js} +283 -209
- package/dist/chunk-WKPHD54B.js.map +1 -0
- package/dist/{chunk-C4X3C2DL.cjs → chunk-XVYUS2EA.cjs} +2213 -1035
- package/dist/chunk-XVYUS2EA.cjs.map +1 -0
- package/dist/{chunk-X3BGE7CL.js → chunk-YQNZ7DHQ.js} +1788 -613
- package/dist/chunk-YQNZ7DHQ.js.map +1 -0
- package/dist/cli.cjs +79 -31
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +71 -23
- package/dist/cli.js.map +1 -1
- package/dist/clipboard/index.d.ts +5 -0
- package/dist/clipboard/index.d.ts.map +1 -1
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.d.ts.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/mcp/config.d.ts +8 -0
- package/dist/mcp/config.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/manager.d.ts +4 -2
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/types.d.ts +30 -3
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/onboarding/onboarding-inline.d.ts +2 -0
- package/dist/onboarding/onboarding-inline.d.ts.map +1 -1
- package/dist/onboarding/packs.d.ts +1 -0
- package/dist/onboarding/packs.d.ts.map +1 -1
- package/dist/onboarding/settings.d.ts +37 -2
- package/dist/onboarding/settings.d.ts.map +1 -1
- package/dist/permissions-S3LGXIDB.js +3 -0
- package/dist/{permissions-CVXKYIWR.js.map → permissions-S3LGXIDB.js.map} +1 -1
- package/dist/permissions-VGABAVGD.cjs +40 -0
- package/dist/{permissions-2HIUSRQN.cjs.map → permissions-VGABAVGD.cjs.map} +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/providers/claude-max.d.ts +13 -0
- package/dist/providers/claude-max.d.ts.map +1 -1
- package/dist/providers/openai-codex.d.ts +1 -0
- package/dist/providers/openai-codex.d.ts.map +1 -1
- package/dist/tool-names.d.ts +68 -0
- package/dist/tool-names.d.ts.map +1 -0
- package/dist/tools/ast-smart-edit.d.ts +77 -5
- package/dist/tools/ast-smart-edit.d.ts.map +1 -1
- package/dist/tools/index.d.ts +2 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/string-replace-lsp.d.ts +15 -0
- package/dist/tools/string-replace-lsp.d.ts.map +1 -1
- package/dist/tools/subagent.d.ts.map +1 -1
- package/dist/tools/utils.d.ts +4 -2
- package/dist/tools/utils.d.ts.map +1 -1
- package/dist/tui/command-dispatch.d.ts.map +1 -1
- package/dist/tui/commands/clone.d.ts +29 -0
- package/dist/tui/commands/clone.d.ts.map +1 -0
- package/dist/tui/commands/custom-providers.d.ts +8 -0
- package/dist/tui/commands/custom-providers.d.ts.map +1 -0
- package/dist/tui/commands/index.d.ts +3 -1
- package/dist/tui/commands/index.d.ts.map +1 -1
- package/dist/tui/commands/mcp.d.ts.map +1 -1
- package/dist/tui/commands/models-pack.d.ts +4 -0
- package/dist/tui/commands/models-pack.d.ts.map +1 -1
- package/dist/tui/commands/om.d.ts.map +1 -1
- package/dist/tui/commands/report-issue.d.ts +3 -0
- package/dist/tui/commands/report-issue.d.ts.map +1 -0
- package/dist/tui/commands/resource.d.ts.map +1 -1
- package/dist/tui/commands/settings.d.ts.map +1 -1
- package/dist/tui/commands/threads.d.ts +1 -0
- package/dist/tui/commands/threads.d.ts.map +1 -1
- package/dist/tui/components/ask-question-inline.d.ts +3 -0
- package/dist/tui/components/ask-question-inline.d.ts.map +1 -1
- package/dist/tui/components/custom-editor.d.ts +1 -1
- package/dist/tui/components/custom-editor.d.ts.map +1 -1
- package/dist/tui/components/help-overlay.d.ts.map +1 -1
- package/dist/tui/components/plan-approval-inline.d.ts.map +1 -1
- package/dist/tui/components/settings.d.ts +2 -0
- package/dist/tui/components/settings.d.ts.map +1 -1
- package/dist/tui/components/subagent-execution.d.ts +6 -1
- package/dist/tui/components/subagent-execution.d.ts.map +1 -1
- package/dist/tui/components/thread-selector.d.ts +6 -0
- package/dist/tui/components/thread-selector.d.ts.map +1 -1
- package/dist/tui/components/tool-execution-enhanced.d.ts +1 -0
- package/dist/tui/components/tool-execution-enhanced.d.ts.map +1 -1
- package/dist/tui/components/tool-validation-error.d.ts.map +1 -1
- package/dist/tui/handlers/message.d.ts.map +1 -1
- package/dist/tui/handlers/prompts.d.ts +6 -0
- package/dist/tui/handlers/prompts.d.ts.map +1 -1
- package/dist/tui/handlers/subagent.d.ts.map +1 -1
- package/dist/tui/mastra-tui.d.ts +14 -5
- package/dist/tui/mastra-tui.d.ts.map +1 -1
- package/dist/tui/render-messages.d.ts.map +1 -1
- package/dist/tui/setup.d.ts.map +1 -1
- package/dist/tui/state.d.ts +4 -5
- package/dist/tui/state.d.ts.map +1 -1
- package/dist/tui.cjs +19 -19
- package/dist/tui.js +2 -2
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.d.ts.map +1 -0
- package/dist/utils/plans.d.ts +7 -0
- package/dist/utils/plans.d.ts.map +1 -0
- package/dist/utils/update-check.d.ts +40 -0
- package/dist/utils/update-check.d.ts.map +1 -0
- package/package.json +8 -8
- package/dist/chunk-C4X3C2DL.cjs.map +0 -1
- package/dist/chunk-K4WJUBEC.cjs.map +0 -1
- package/dist/chunk-M5LKPQB4.js.map +0 -1
- package/dist/chunk-MT3YCFCC.cjs.map +0 -1
- package/dist/chunk-REVOTI2T.js.map +0 -1
- package/dist/chunk-U5A7TFNT.js.map +0 -1
- package/dist/chunk-X3BGE7CL.js.map +0 -1
- package/dist/chunk-Z4QRXVST.cjs.map +0 -1
- package/dist/docs/SKILL.md +0 -30
- package/dist/docs/assets/SOURCE_MAP.json +0 -11
- package/dist/docs/references/docs-mastra-code-configuration.md +0 -299
- package/dist/docs/references/docs-mastra-code-customization.md +0 -228
- package/dist/docs/references/docs-mastra-code-modes.md +0 -104
- package/dist/docs/references/docs-mastra-code-overview.md +0 -135
- package/dist/docs/references/docs-mastra-code-tools.md +0 -229
- package/dist/docs/references/reference-mastra-code-createMastraCode.md +0 -108
- package/dist/permissions-2HIUSRQN.cjs +0 -40
- package/dist/permissions-CVXKYIWR.js +0 -3
- package/dist/tui/commands/models.d.ts +0 -3
- package/dist/tui/commands/models.d.ts.map +0 -1
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkS5ZLN7DR_cjs = require('./chunk-S5ZLN7DR.cjs');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var chunkOEDRHUU5_cjs = require('./chunk-OEDRHUU5.cjs');
|
|
5
|
+
var fs9 = require('fs');
|
|
6
|
+
var path2 = require('path');
|
|
6
7
|
var os = require('os');
|
|
7
|
-
var
|
|
8
|
+
var url = require('url');
|
|
9
|
+
var workspace = require('@mastra/core/workspace');
|
|
10
|
+
var child_process = require('child_process');
|
|
8
11
|
var util = require('util');
|
|
9
12
|
var tools = require('@mastra/core/tools');
|
|
10
13
|
var zod = require('zod');
|
|
@@ -16,7 +19,6 @@ var treeKill = require('tree-kill');
|
|
|
16
19
|
var node_js = require('vscode-jsonrpc/node.js');
|
|
17
20
|
var vscodeLanguageserverProtocol = require('vscode-languageserver-protocol');
|
|
18
21
|
var module$1 = require('module');
|
|
19
|
-
var url = require('url');
|
|
20
22
|
var fastestLevenshtein = require('fastest-levenshtein');
|
|
21
23
|
var anthropic = require('@ai-sdk/anthropic');
|
|
22
24
|
var ai = require('ai');
|
|
@@ -26,6 +28,7 @@ var core = require('@tavily/core');
|
|
|
26
28
|
var napi = require('@ast-grep/napi');
|
|
27
29
|
var chalk = require('chalk');
|
|
28
30
|
|
|
31
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
29
32
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
30
33
|
|
|
31
34
|
function _interopNamespace(e) {
|
|
@@ -46,13 +49,418 @@ function _interopNamespace(e) {
|
|
|
46
49
|
return Object.freeze(n);
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
var
|
|
50
|
-
var
|
|
52
|
+
var fs9__namespace = /*#__PURE__*/_interopNamespace(fs9);
|
|
53
|
+
var path2__namespace = /*#__PURE__*/_interopNamespace(path2);
|
|
54
|
+
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
51
55
|
var o200k_base__default = /*#__PURE__*/_interopDefault(o200k_base);
|
|
52
56
|
var stripAnsi__default = /*#__PURE__*/_interopDefault(stripAnsi);
|
|
53
57
|
var treeKill__default = /*#__PURE__*/_interopDefault(treeKill);
|
|
54
58
|
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
55
59
|
|
|
60
|
+
var STORAGE_DEFAULTS = {
|
|
61
|
+
backend: "libsql",
|
|
62
|
+
libsql: {},
|
|
63
|
+
pg: {}
|
|
64
|
+
};
|
|
65
|
+
var DEFAULTS = {
|
|
66
|
+
onboarding: {
|
|
67
|
+
completedAt: null,
|
|
68
|
+
skippedAt: null,
|
|
69
|
+
version: 0,
|
|
70
|
+
modePackId: null,
|
|
71
|
+
omPackId: null,
|
|
72
|
+
claudeMaxOAuthWarningAcknowledgedAt: null
|
|
73
|
+
},
|
|
74
|
+
models: {
|
|
75
|
+
activeModelPackId: null,
|
|
76
|
+
modeDefaults: {},
|
|
77
|
+
activeOmPackId: null,
|
|
78
|
+
omModelOverride: null,
|
|
79
|
+
subagentModels: {}
|
|
80
|
+
},
|
|
81
|
+
preferences: {
|
|
82
|
+
yolo: null,
|
|
83
|
+
theme: "auto",
|
|
84
|
+
quietMode: false
|
|
85
|
+
},
|
|
86
|
+
storage: { ...STORAGE_DEFAULTS },
|
|
87
|
+
customModelPacks: [],
|
|
88
|
+
customProviders: [],
|
|
89
|
+
modelUseCounts: {},
|
|
90
|
+
updateDismissedVersion: null,
|
|
91
|
+
lsp: {}
|
|
92
|
+
};
|
|
93
|
+
function getSettingsPath() {
|
|
94
|
+
return path2.join(chunkS5ZLN7DR_cjs.getAppDataDir(), "settings.json");
|
|
95
|
+
}
|
|
96
|
+
function getCustomProviderId(name) {
|
|
97
|
+
const slug = name.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
98
|
+
return slug || "provider";
|
|
99
|
+
}
|
|
100
|
+
function toCustomProviderModelId(providerName, modelName) {
|
|
101
|
+
const providerId = getCustomProviderId(providerName);
|
|
102
|
+
const trimmedModelName = modelName.trim();
|
|
103
|
+
const providerPrefix = `${providerId}/`;
|
|
104
|
+
if (trimmedModelName.startsWith(providerPrefix)) {
|
|
105
|
+
return trimmedModelName;
|
|
106
|
+
}
|
|
107
|
+
return `${providerId}/${trimmedModelName}`;
|
|
108
|
+
}
|
|
109
|
+
function parseCustomProviders(rawProviders) {
|
|
110
|
+
if (!Array.isArray(rawProviders)) return [];
|
|
111
|
+
const parsedProviders = [];
|
|
112
|
+
for (const rawProvider of rawProviders) {
|
|
113
|
+
if (!rawProvider || typeof rawProvider !== "object") continue;
|
|
114
|
+
const candidate = rawProvider;
|
|
115
|
+
const name = typeof candidate.name === "string" ? candidate.name.trim() : "";
|
|
116
|
+
const url = typeof candidate.url === "string" ? candidate.url.trim() : "";
|
|
117
|
+
if (!name || !url) continue;
|
|
118
|
+
const providerId = getCustomProviderId(name);
|
|
119
|
+
const models = Array.isArray(candidate.models) ? [
|
|
120
|
+
...new Set(
|
|
121
|
+
candidate.models.filter((model) => typeof model === "string").map((model) => model.trim()).map((model) => {
|
|
122
|
+
const providerPrefix = `${providerId}/`;
|
|
123
|
+
if (model.startsWith(providerPrefix)) {
|
|
124
|
+
return model.slice(providerPrefix.length);
|
|
125
|
+
}
|
|
126
|
+
return model;
|
|
127
|
+
})
|
|
128
|
+
)
|
|
129
|
+
].filter((model) => model.length > 0) : [];
|
|
130
|
+
const apiKey = typeof candidate.apiKey === "string" && candidate.apiKey.trim().length > 0 ? candidate.apiKey.trim() : void 0;
|
|
131
|
+
parsedProviders.push({
|
|
132
|
+
name,
|
|
133
|
+
url,
|
|
134
|
+
...apiKey ? { apiKey } : {},
|
|
135
|
+
models
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return parsedProviders;
|
|
139
|
+
}
|
|
140
|
+
function migrateFromAuth(settingsPath) {
|
|
141
|
+
const authPath = path2.join(chunkS5ZLN7DR_cjs.getAppDataDir(), "auth.json");
|
|
142
|
+
if (!fs9.existsSync(authPath)) return false;
|
|
143
|
+
let authData;
|
|
144
|
+
try {
|
|
145
|
+
authData = JSON.parse(fs9.readFileSync(authPath, "utf-8"));
|
|
146
|
+
} catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const modelKeys = Object.keys(authData).filter((k) => k.startsWith("_"));
|
|
150
|
+
if (modelKeys.length === 0) return false;
|
|
151
|
+
let settings;
|
|
152
|
+
if (fs9.existsSync(settingsPath)) {
|
|
153
|
+
try {
|
|
154
|
+
const raw = JSON.parse(fs9.readFileSync(settingsPath, "utf-8"));
|
|
155
|
+
settings = {
|
|
156
|
+
onboarding: { ...DEFAULTS.onboarding, ...raw.onboarding },
|
|
157
|
+
models: { ...DEFAULTS.models, ...raw.models },
|
|
158
|
+
preferences: { ...DEFAULTS.preferences, ...raw.preferences },
|
|
159
|
+
storage: {
|
|
160
|
+
...STORAGE_DEFAULTS,
|
|
161
|
+
...raw.storage,
|
|
162
|
+
libsql: { ...STORAGE_DEFAULTS.libsql, ...raw.storage?.libsql },
|
|
163
|
+
pg: { ...STORAGE_DEFAULTS.pg, ...raw.storage?.pg }
|
|
164
|
+
},
|
|
165
|
+
customModelPacks: Array.isArray(raw.customModelPacks) ? raw.customModelPacks : [],
|
|
166
|
+
customProviders: parseCustomProviders(raw.customProviders),
|
|
167
|
+
modelUseCounts: raw.modelUseCounts && typeof raw.modelUseCounts === "object" ? raw.modelUseCounts : {},
|
|
168
|
+
updateDismissedVersion: typeof raw.updateDismissedVersion === "string" ? raw.updateDismissedVersion : null,
|
|
169
|
+
lsp: raw.lsp && typeof raw.lsp === "object" ? raw.lsp : void 0
|
|
170
|
+
};
|
|
171
|
+
} catch {
|
|
172
|
+
settings = structuredClone(DEFAULTS);
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
settings = structuredClone(DEFAULTS);
|
|
176
|
+
}
|
|
177
|
+
if (authData._modelRanks && typeof authData._modelRanks === "object") {
|
|
178
|
+
settings.modelUseCounts = { ...authData._modelRanks, ...settings.modelUseCounts };
|
|
179
|
+
}
|
|
180
|
+
for (const key of modelKeys) {
|
|
181
|
+
const modeMatch = key.match(/^_modeModelId_(.+)$/);
|
|
182
|
+
if (modeMatch?.[1] && typeof authData[key] === "string" && !settings.models.modeDefaults[modeMatch[1]]) {
|
|
183
|
+
settings.models.modeDefaults[modeMatch[1]] = authData[key];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
for (const key of modelKeys) {
|
|
187
|
+
if (key === "_subagentModelId" && typeof authData[key] === "string" && !settings.models.subagentModels["default"]) {
|
|
188
|
+
settings.models.subagentModels["default"] = authData[key];
|
|
189
|
+
}
|
|
190
|
+
const saMatch = key.match(/^_subagentModelId_(.+)$/);
|
|
191
|
+
if (saMatch?.[1] && typeof authData[key] === "string" && !settings.models.subagentModels[saMatch[1]]) {
|
|
192
|
+
settings.models.subagentModels[saMatch[1]] = authData[key];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
saveSettings(settings, settingsPath);
|
|
196
|
+
for (const key of modelKeys) {
|
|
197
|
+
delete authData[key];
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
fs9.writeFileSync(authPath, JSON.stringify(authData, null, 2), "utf-8");
|
|
201
|
+
} catch {
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
var LEGACY_VARIED_MODELS = {
|
|
206
|
+
plan: "openai/gpt-5.3-codex",
|
|
207
|
+
build: "anthropic/claude-sonnet-4-5",
|
|
208
|
+
fast: "anthropic/claude-haiku-4-5"
|
|
209
|
+
};
|
|
210
|
+
function migrateLegacyVariedPack(settings) {
|
|
211
|
+
const legacyPackId = "varied";
|
|
212
|
+
const customPackId = "custom:varied";
|
|
213
|
+
const hasLegacyReference = settings.models.activeModelPackId === legacyPackId || settings.onboarding.modePackId === legacyPackId;
|
|
214
|
+
if (!hasLegacyReference) return false;
|
|
215
|
+
const existingIdx = settings.customModelPacks.findIndex((p) => p.name === "varied");
|
|
216
|
+
if (existingIdx >= 0) {
|
|
217
|
+
const existing = settings.customModelPacks[existingIdx];
|
|
218
|
+
const modelsMatch = Object.entries(LEGACY_VARIED_MODELS).every(([k, v]) => existing.models[k] === v);
|
|
219
|
+
if (!modelsMatch) {
|
|
220
|
+
existing.models = { ...LEGACY_VARIED_MODELS };
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
settings.customModelPacks.push({
|
|
224
|
+
name: "varied",
|
|
225
|
+
models: { ...LEGACY_VARIED_MODELS },
|
|
226
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
if (settings.models.activeModelPackId === legacyPackId) {
|
|
230
|
+
settings.models.activeModelPackId = customPackId;
|
|
231
|
+
if (Object.keys(settings.models.modeDefaults).length === 0) {
|
|
232
|
+
settings.models.modeDefaults = { ...LEGACY_VARIED_MODELS };
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (settings.onboarding.modePackId === legacyPackId) {
|
|
236
|
+
settings.onboarding.modePackId = customPackId;
|
|
237
|
+
}
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
function loadSettings(filePath = getSettingsPath()) {
|
|
241
|
+
migrateFromAuth(filePath);
|
|
242
|
+
if (!fs9.existsSync(filePath)) return structuredClone(DEFAULTS);
|
|
243
|
+
try {
|
|
244
|
+
const raw = JSON.parse(fs9.readFileSync(filePath, "utf-8"));
|
|
245
|
+
const settings = {
|
|
246
|
+
...raw,
|
|
247
|
+
onboarding: { ...DEFAULTS.onboarding, ...raw.onboarding },
|
|
248
|
+
models: { ...DEFAULTS.models, ...raw.models },
|
|
249
|
+
preferences: { ...DEFAULTS.preferences, ...raw.preferences },
|
|
250
|
+
storage: {
|
|
251
|
+
...STORAGE_DEFAULTS,
|
|
252
|
+
...raw.storage,
|
|
253
|
+
libsql: { ...STORAGE_DEFAULTS.libsql, ...raw.storage?.libsql },
|
|
254
|
+
pg: { ...STORAGE_DEFAULTS.pg, ...raw.storage?.pg }
|
|
255
|
+
},
|
|
256
|
+
customModelPacks: Array.isArray(raw.customModelPacks) ? raw.customModelPacks : [],
|
|
257
|
+
customProviders: parseCustomProviders(raw.customProviders),
|
|
258
|
+
modelUseCounts: raw.modelUseCounts && typeof raw.modelUseCounts === "object" ? raw.modelUseCounts : {},
|
|
259
|
+
updateDismissedVersion: typeof raw.updateDismissedVersion === "string" ? raw.updateDismissedVersion : null,
|
|
260
|
+
lsp: raw.lsp && typeof raw.lsp === "object" ? raw.lsp : void 0
|
|
261
|
+
};
|
|
262
|
+
let settingsChanged = false;
|
|
263
|
+
if (raw.models?.omModelId && !settings.models.omModelOverride) {
|
|
264
|
+
settings.models.omModelOverride = raw.models.omModelId;
|
|
265
|
+
settingsChanged = true;
|
|
266
|
+
}
|
|
267
|
+
if (migrateLegacyVariedPack(settings)) {
|
|
268
|
+
settingsChanged = true;
|
|
269
|
+
}
|
|
270
|
+
if (settingsChanged) {
|
|
271
|
+
saveSettings(settings, filePath);
|
|
272
|
+
}
|
|
273
|
+
return settings;
|
|
274
|
+
} catch {
|
|
275
|
+
return structuredClone(DEFAULTS);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
var THREAD_ACTIVE_MODEL_PACK_ID_KEY = "activeModelPackId";
|
|
279
|
+
function parseThreadSettings(metadata) {
|
|
280
|
+
const modeModelIds = {};
|
|
281
|
+
for (const [key, value] of Object.entries(metadata ?? {})) {
|
|
282
|
+
const modeMatch = key.match(/^modeModelId_(.+)$/);
|
|
283
|
+
if (modeMatch?.[1] && typeof value === "string" && value.length > 0) {
|
|
284
|
+
modeModelIds[modeMatch[1]] = value;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const rawPackId = metadata?.[THREAD_ACTIVE_MODEL_PACK_ID_KEY];
|
|
288
|
+
const activeModelPackId = typeof rawPackId === "string" && rawPackId.length > 0 ? rawPackId : null;
|
|
289
|
+
return {
|
|
290
|
+
activeModelPackId,
|
|
291
|
+
modeModelIds
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function resolveThreadActiveModelPackId(settings, builtinPacks, metadata) {
|
|
295
|
+
const threadSettings = parseThreadSettings(metadata);
|
|
296
|
+
const isKnownPack = (packId) => {
|
|
297
|
+
if (packId.startsWith("custom:")) {
|
|
298
|
+
const name = packId.slice("custom:".length);
|
|
299
|
+
return settings.customModelPacks.some((p) => p.name === name);
|
|
300
|
+
}
|
|
301
|
+
return builtinPacks.some((p) => p.id === packId);
|
|
302
|
+
};
|
|
303
|
+
if (threadSettings.activeModelPackId && isKnownPack(threadSettings.activeModelPackId)) {
|
|
304
|
+
return threadSettings.activeModelPackId;
|
|
305
|
+
}
|
|
306
|
+
const allPacks = [
|
|
307
|
+
...builtinPacks,
|
|
308
|
+
...settings.customModelPacks.map((p) => ({ id: `custom:${p.name}`, models: p.models }))
|
|
309
|
+
];
|
|
310
|
+
for (const pack of allPacks) {
|
|
311
|
+
const packEntries = Object.entries(pack.models);
|
|
312
|
+
const threadEntries = Object.keys(threadSettings.modeModelIds);
|
|
313
|
+
const matches = packEntries.length === threadEntries.length && packEntries.every(([modeId, modelId]) => threadSettings.modeModelIds[modeId] === modelId);
|
|
314
|
+
if (matches) return pack.id;
|
|
315
|
+
}
|
|
316
|
+
if (settings.models.activeModelPackId && isKnownPack(settings.models.activeModelPackId)) {
|
|
317
|
+
return settings.models.activeModelPackId;
|
|
318
|
+
}
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
function resolveModelDefaults(settings, builtinPacks) {
|
|
322
|
+
const { activeModelPackId, modeDefaults } = settings.models;
|
|
323
|
+
if (!activeModelPackId) return modeDefaults;
|
|
324
|
+
if (activeModelPackId.startsWith("custom:")) {
|
|
325
|
+
const name = activeModelPackId.slice("custom:".length);
|
|
326
|
+
const pack = settings.customModelPacks.find((p) => p.name === name);
|
|
327
|
+
if (pack) return pack.models;
|
|
328
|
+
return modeDefaults;
|
|
329
|
+
}
|
|
330
|
+
const builtin = builtinPacks.find((p) => p.id === activeModelPackId);
|
|
331
|
+
if (builtin) return builtin.models;
|
|
332
|
+
return modeDefaults;
|
|
333
|
+
}
|
|
334
|
+
function resolveOmModel(settings, builtinOmPacks) {
|
|
335
|
+
const { activeOmPackId, omModelOverride } = settings.models;
|
|
336
|
+
if (!activeOmPackId) return omModelOverride;
|
|
337
|
+
if (activeOmPackId === "custom") return omModelOverride;
|
|
338
|
+
const pack = builtinOmPacks.find((p) => p.id === activeOmPackId);
|
|
339
|
+
if (pack) return pack.modelId;
|
|
340
|
+
return omModelOverride;
|
|
341
|
+
}
|
|
342
|
+
function saveSettings(settings, filePath = getSettingsPath()) {
|
|
343
|
+
const dir = path2.dirname(filePath);
|
|
344
|
+
if (!fs9.existsSync(dir)) {
|
|
345
|
+
fs9.mkdirSync(dir, { recursive: true });
|
|
346
|
+
}
|
|
347
|
+
fs9.writeFileSync(filePath, JSON.stringify(settings, null, 2), "utf-8");
|
|
348
|
+
}
|
|
349
|
+
var mastraCodeLocalSkillsPath = path2__namespace.default.join(process.cwd(), ".mastracode", "skills");
|
|
350
|
+
var claudeLocalSkillsPath = path2__namespace.default.join(process.cwd(), ".claude", "skills");
|
|
351
|
+
var mastraCodeGlobalSkillsPath = path2__namespace.default.join(os__default.default.homedir(), ".mastracode", "skills");
|
|
352
|
+
var claudeGlobalSkillsPath = path2__namespace.default.join(os__default.default.homedir(), ".claude", "skills");
|
|
353
|
+
function collectSkillPaths(skillsDirs) {
|
|
354
|
+
const paths = [];
|
|
355
|
+
const seen = /* @__PURE__ */ new Set();
|
|
356
|
+
for (const skillsDir of skillsDirs) {
|
|
357
|
+
if (!fs9__namespace.default.existsSync(skillsDir)) continue;
|
|
358
|
+
const resolved = fs9__namespace.default.realpathSync(skillsDir);
|
|
359
|
+
if (!seen.has(resolved)) {
|
|
360
|
+
seen.add(resolved);
|
|
361
|
+
paths.push(skillsDir);
|
|
362
|
+
}
|
|
363
|
+
try {
|
|
364
|
+
const entries = fs9__namespace.default.readdirSync(skillsDir, { withFileTypes: true });
|
|
365
|
+
for (const entry of entries) {
|
|
366
|
+
if (entry.isSymbolicLink()) {
|
|
367
|
+
const linkPath = path2__namespace.default.join(skillsDir, entry.name);
|
|
368
|
+
const realPath = fs9__namespace.default.realpathSync(linkPath);
|
|
369
|
+
const stat = fs9__namespace.default.statSync(realPath);
|
|
370
|
+
if (stat.isDirectory()) {
|
|
371
|
+
const realParent = path2__namespace.default.dirname(realPath);
|
|
372
|
+
if (!seen.has(realParent)) {
|
|
373
|
+
seen.add(realParent);
|
|
374
|
+
paths.push(realParent);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
} catch {
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return paths;
|
|
383
|
+
}
|
|
384
|
+
var skillPaths = collectSkillPaths([
|
|
385
|
+
mastraCodeLocalSkillsPath,
|
|
386
|
+
claudeLocalSkillsPath,
|
|
387
|
+
mastraCodeGlobalSkillsPath,
|
|
388
|
+
claudeGlobalSkillsPath
|
|
389
|
+
]);
|
|
390
|
+
var WORKSPACE_ID_PREFIX = "mastra-code-workspace";
|
|
391
|
+
function detectPackageRunner(projectPath) {
|
|
392
|
+
if (fs9.existsSync(path2.join(projectPath, "pnpm-lock.yaml"))) return "pnpm dlx";
|
|
393
|
+
if (fs9.existsSync(path2.join(projectPath, "bun.lockb")) || fs9.existsSync(path2.join(projectPath, "bun.lock"))) return "bunx";
|
|
394
|
+
if (fs9.existsSync(path2.join(projectPath, "yarn.lock"))) return "yarn dlx";
|
|
395
|
+
if (fs9.existsSync(path2.join(projectPath, "package-lock.json"))) return "npx --yes";
|
|
396
|
+
return "npx --yes";
|
|
397
|
+
}
|
|
398
|
+
function getDynamicWorkspace({ requestContext, mastra: mastra2 }) {
|
|
399
|
+
const ctx = requestContext.get("harness");
|
|
400
|
+
const state = ctx?.getState?.();
|
|
401
|
+
const modeId = ctx?.modeId ?? "build";
|
|
402
|
+
const rawProjectPath = state?.projectPath;
|
|
403
|
+
if (!rawProjectPath) {
|
|
404
|
+
throw new Error("Project path is required");
|
|
405
|
+
}
|
|
406
|
+
const projectPath = path2__namespace.default.resolve(rawProjectPath);
|
|
407
|
+
const workspaceId = `${WORKSPACE_ID_PREFIX}-${projectPath}`;
|
|
408
|
+
const sandboxPaths = state?.sandboxAllowedPaths ?? [];
|
|
409
|
+
const allowedPaths = [...skillPaths, ...sandboxPaths.map((p) => path2__namespace.default.resolve(p))];
|
|
410
|
+
const isPlanMode = modeId === "plan";
|
|
411
|
+
const planModeTools = {
|
|
412
|
+
mastra_workspace_write_file: { ...chunkOEDRHUU5_cjs.TOOL_NAME_OVERRIDES.mastra_workspace_write_file, enabled: false },
|
|
413
|
+
mastra_workspace_edit_file: { ...chunkOEDRHUU5_cjs.TOOL_NAME_OVERRIDES.mastra_workspace_edit_file, enabled: false },
|
|
414
|
+
mastra_workspace_ast_edit: { ...chunkOEDRHUU5_cjs.TOOL_NAME_OVERRIDES.mastra_workspace_ast_edit, enabled: false }
|
|
415
|
+
};
|
|
416
|
+
let existing;
|
|
417
|
+
try {
|
|
418
|
+
existing = mastra2?.getWorkspaceById(workspaceId);
|
|
419
|
+
} catch {
|
|
420
|
+
}
|
|
421
|
+
if (existing) {
|
|
422
|
+
existing.filesystem.setAllowedPaths(allowedPaths);
|
|
423
|
+
existing.setToolsConfig(isPlanMode ? { ...chunkOEDRHUU5_cjs.TOOL_NAME_OVERRIDES, ...planModeTools } : chunkOEDRHUU5_cjs.TOOL_NAME_OVERRIDES);
|
|
424
|
+
return existing;
|
|
425
|
+
}
|
|
426
|
+
const userLsp = loadSettings().lsp ?? {};
|
|
427
|
+
const mcModulePath = path2.join(path2.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-AJEYT7X3.cjs', document.baseURI).href)))), "..");
|
|
428
|
+
const lspConfig = {
|
|
429
|
+
...userLsp,
|
|
430
|
+
packageRunner: userLsp.packageRunner || detectPackageRunner(projectPath),
|
|
431
|
+
// Detected runner is the fallback — user's packageRunner always wins
|
|
432
|
+
searchPaths: [mcModulePath, ...userLsp.searchPaths ?? []]
|
|
433
|
+
};
|
|
434
|
+
return new workspace.Workspace({
|
|
435
|
+
id: workspaceId,
|
|
436
|
+
name: "Mastra Code Workspace",
|
|
437
|
+
filesystem: new workspace.LocalFilesystem({
|
|
438
|
+
basePath: projectPath,
|
|
439
|
+
allowedPaths
|
|
440
|
+
}),
|
|
441
|
+
sandbox: new workspace.LocalSandbox({
|
|
442
|
+
workingDirectory: projectPath,
|
|
443
|
+
env: {
|
|
444
|
+
...process.env,
|
|
445
|
+
FORCE_COLOR: "1",
|
|
446
|
+
CLICOLOR_FORCE: "1",
|
|
447
|
+
TERM: process.env.TERM || "xterm-256color",
|
|
448
|
+
CI: "true",
|
|
449
|
+
NONINTERACTIVE: "1",
|
|
450
|
+
DEBIAN_FRONTEND: "noninteractive"
|
|
451
|
+
}
|
|
452
|
+
}),
|
|
453
|
+
tools: isPlanMode ? { ...chunkOEDRHUU5_cjs.TOOL_NAME_OVERRIDES, ...planModeTools } : chunkOEDRHUU5_cjs.TOOL_NAME_OVERRIDES,
|
|
454
|
+
...skillPaths.length > 0 ? { skills: skillPaths } : {},
|
|
455
|
+
lsp: lspConfig
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
if (skillPaths.length > 0) {
|
|
459
|
+
console.info(`Skills loaded from:`);
|
|
460
|
+
for (const p of skillPaths) {
|
|
461
|
+
console.info(` - ${p}`);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
56
464
|
var enc = new lite.Tiktoken(o200k_base__default.default);
|
|
57
465
|
function sanitizeInput(text) {
|
|
58
466
|
if (!text) return "";
|
|
@@ -76,19 +484,19 @@ var ToolError = class extends Error {
|
|
|
76
484
|
// src/tools/utils.ts
|
|
77
485
|
var fileWriteQueues = /* @__PURE__ */ new Map();
|
|
78
486
|
async function withWriteLock(filePath, fn) {
|
|
79
|
-
const normalizedPath =
|
|
487
|
+
const normalizedPath = path2__namespace.resolve(filePath);
|
|
80
488
|
const currentQueue = fileWriteQueues.get(normalizedPath) ?? Promise.resolve();
|
|
81
|
-
let
|
|
489
|
+
let resolve11;
|
|
82
490
|
let reject;
|
|
83
491
|
const ourPromise = new Promise((res, rej) => {
|
|
84
|
-
|
|
492
|
+
resolve11 = res;
|
|
85
493
|
reject = rej;
|
|
86
494
|
});
|
|
87
495
|
const queuePromise = currentQueue.catch(() => {
|
|
88
496
|
}).then(async () => {
|
|
89
497
|
try {
|
|
90
498
|
const result = await fn();
|
|
91
|
-
|
|
499
|
+
resolve11(result);
|
|
92
500
|
} catch (error) {
|
|
93
501
|
reject(error);
|
|
94
502
|
}
|
|
@@ -104,7 +512,7 @@ async function withWriteLock(filePath, fn) {
|
|
|
104
512
|
var SNIPPET_LINES = 4;
|
|
105
513
|
async function readFile(filePath) {
|
|
106
514
|
try {
|
|
107
|
-
return await
|
|
515
|
+
return await fs9.promises.readFile(filePath, "utf8");
|
|
108
516
|
} catch (e) {
|
|
109
517
|
const error = e instanceof Error ? e : new Error("Unknown error");
|
|
110
518
|
throw new Error(`Failed to read ${filePath}: ${error.message}`);
|
|
@@ -112,8 +520,8 @@ async function readFile(filePath) {
|
|
|
112
520
|
}
|
|
113
521
|
async function writeFile(filePath, content) {
|
|
114
522
|
try {
|
|
115
|
-
await
|
|
116
|
-
await
|
|
523
|
+
await fs9.promises.mkdir(path2__namespace.dirname(filePath), { recursive: true });
|
|
524
|
+
await fs9.promises.writeFile(filePath, content, "utf8");
|
|
117
525
|
} catch (e) {
|
|
118
526
|
const error = e instanceof Error ? e : new Error("Unknown error");
|
|
119
527
|
throw new Error(`Failed to write to ${filePath}: ${error.message}`);
|
|
@@ -123,7 +531,7 @@ function makeOutput(fileContent, fileDescriptor, initLine = 1, expandTabs = true
|
|
|
123
531
|
if (expandTabs) {
|
|
124
532
|
fileContent = fileContent.replace(/\t/g, " ");
|
|
125
533
|
}
|
|
126
|
-
const displayPath =
|
|
534
|
+
const displayPath = path2__namespace.isAbsolute(fileDescriptor) ? path2__namespace.relative(process.cwd(), fileDescriptor) : fileDescriptor;
|
|
127
535
|
const lines = fileContent.split("\n");
|
|
128
536
|
const numberedLines = lines.map((line, i) => `${(i + initLine).toString().padStart(6)} ${line}`).join("\n");
|
|
129
537
|
return `Here's the result of running \`cat -n\` on ${displayPath}:
|
|
@@ -131,12 +539,12 @@ ${truncateStringForTokenEstimate(numberedLines, 500, false)}
|
|
|
131
539
|
`;
|
|
132
540
|
}
|
|
133
541
|
async function validatePath(command, filePath) {
|
|
134
|
-
const absolutePath =
|
|
135
|
-
if (!
|
|
542
|
+
const absolutePath = path2__namespace.isAbsolute(filePath) ? filePath : path2__namespace.join(process.cwd(), filePath);
|
|
543
|
+
if (!path2__namespace.isAbsolute(filePath)) {
|
|
136
544
|
filePath = absolutePath;
|
|
137
545
|
}
|
|
138
546
|
try {
|
|
139
|
-
const stats = await
|
|
547
|
+
const stats = await fs9.promises.stat(filePath);
|
|
140
548
|
if (stats.isDirectory() && command !== "view") {
|
|
141
549
|
throw new ToolError(
|
|
142
550
|
`The path ${filePath} is a directory and only the \`view\` command can be used on directories`
|
|
@@ -156,23 +564,26 @@ async function validatePath(command, filePath) {
|
|
|
156
564
|
}
|
|
157
565
|
}
|
|
158
566
|
function isPathAllowed(targetPath, projectRoot, allowedPaths = []) {
|
|
159
|
-
const resolved =
|
|
160
|
-
const roots = [projectRoot, ...allowedPaths].map((p) =>
|
|
161
|
-
return roots.some((root) => resolved === root || resolved.startsWith(root +
|
|
567
|
+
const resolved = path2__namespace.resolve(targetPath);
|
|
568
|
+
const roots = [projectRoot, ...allowedPaths].map((p) => path2__namespace.resolve(p));
|
|
569
|
+
return roots.some((root) => resolved === root || resolved.startsWith(root + path2__namespace.sep));
|
|
162
570
|
}
|
|
163
571
|
function assertPathAllowed(targetPath, projectRoot, allowedPaths = []) {
|
|
164
572
|
if (!isPathAllowed(targetPath, projectRoot, allowedPaths)) {
|
|
165
|
-
const resolvedTarget =
|
|
166
|
-
const resolvedRoot =
|
|
573
|
+
const resolvedTarget = path2__namespace.resolve(targetPath);
|
|
574
|
+
const resolvedRoot = path2__namespace.resolve(projectRoot);
|
|
167
575
|
throw new ToolError(
|
|
168
576
|
`Access denied: "${resolvedTarget}" is outside the project root "${resolvedRoot}"` + (allowedPaths.length ? ` and allowed paths [${allowedPaths.join(", ")}]` : "") + `. Use /sandbox to add additional allowed paths.`
|
|
169
577
|
);
|
|
170
578
|
}
|
|
171
579
|
}
|
|
172
580
|
function getAllowedPathsFromContext(toolContext) {
|
|
173
|
-
if (!toolContext?.requestContext)
|
|
581
|
+
if (!toolContext?.requestContext) {
|
|
582
|
+
return [...skillPaths];
|
|
583
|
+
}
|
|
174
584
|
const harnessCtx = toolContext.requestContext.get("harness");
|
|
175
|
-
|
|
585
|
+
const sandboxPaths = harnessCtx?.getState?.()?.sandboxAllowedPaths ?? harnessCtx?.state?.sandboxAllowedPaths ?? [];
|
|
586
|
+
return [...skillPaths, ...sandboxPaths];
|
|
176
587
|
}
|
|
177
588
|
|
|
178
589
|
// src/tools/file-view.ts
|
|
@@ -206,7 +617,7 @@ ${numberedLines}
|
|
|
206
617
|
}
|
|
207
618
|
async function readFile2(filePath) {
|
|
208
619
|
try {
|
|
209
|
-
return await
|
|
620
|
+
return await fs9.promises.readFile(filePath, "utf8");
|
|
210
621
|
} catch (e) {
|
|
211
622
|
const error = e instanceof Error ? e : new Error("Unknown error");
|
|
212
623
|
throw new Error(`Failed to read ${filePath}: ${error.message}`);
|
|
@@ -214,19 +625,19 @@ async function readFile2(filePath) {
|
|
|
214
625
|
}
|
|
215
626
|
async function isDirectory(filePath) {
|
|
216
627
|
try {
|
|
217
|
-
const stats = await
|
|
628
|
+
const stats = await fs9.promises.stat(filePath);
|
|
218
629
|
return stats.isDirectory();
|
|
219
630
|
} catch {
|
|
220
631
|
return false;
|
|
221
632
|
}
|
|
222
633
|
}
|
|
223
634
|
async function validatePath2(command, filePath) {
|
|
224
|
-
const absolutePath =
|
|
225
|
-
if (!
|
|
635
|
+
const absolutePath = path2__namespace.isAbsolute(filePath) ? filePath : path2__namespace.join(process.cwd(), filePath);
|
|
636
|
+
if (!path2__namespace.isAbsolute(filePath)) {
|
|
226
637
|
filePath = absolutePath;
|
|
227
638
|
}
|
|
228
639
|
try {
|
|
229
|
-
const stats = await
|
|
640
|
+
const stats = await fs9.promises.stat(filePath);
|
|
230
641
|
if (stats.isDirectory() && command !== "view") ;
|
|
231
642
|
} catch (e) {
|
|
232
643
|
const error = e instanceof Error ? e : new Error("Unknown error");
|
|
@@ -256,7 +667,7 @@ Usage notes:
|
|
|
256
667
|
try {
|
|
257
668
|
const { path: filePath, view_range } = context;
|
|
258
669
|
const root = projectRoot || process.cwd();
|
|
259
|
-
const absolutePath =
|
|
670
|
+
const absolutePath = path2__namespace.resolve(root, filePath);
|
|
260
671
|
const allowedPaths = getAllowedPathsFromContext(toolContext);
|
|
261
672
|
assertPathAllowed(absolutePath, root, allowedPaths);
|
|
262
673
|
await validatePath2("view", absolutePath);
|
|
@@ -423,7 +834,7 @@ Usage notes:
|
|
|
423
834
|
const root = projectRoot || process.cwd();
|
|
424
835
|
if (context.cwd) {
|
|
425
836
|
const allowedPaths = getAllowedPathsFromContext(toolContext);
|
|
426
|
-
const resolvedCwd =
|
|
837
|
+
const resolvedCwd = path2__namespace.resolve(context.cwd);
|
|
427
838
|
if (!isPathAllowed(resolvedCwd, root, allowedPaths)) {
|
|
428
839
|
return {
|
|
429
840
|
content: [
|
|
@@ -756,9 +1167,9 @@ ${truncateStringForTokenEstimate(cleanOutput, 1e3)}` : "[User aborted command]"
|
|
|
756
1167
|
const pid = subprocess?.pid;
|
|
757
1168
|
if (pid) {
|
|
758
1169
|
try {
|
|
759
|
-
await new Promise((
|
|
1170
|
+
await new Promise((resolve11) => {
|
|
760
1171
|
treeKill__default.default(pid, "SIGKILL", (err) => {
|
|
761
|
-
|
|
1172
|
+
resolve11();
|
|
762
1173
|
});
|
|
763
1174
|
});
|
|
764
1175
|
} catch {
|
|
@@ -1026,7 +1437,7 @@ var LSPClient = class {
|
|
|
1026
1437
|
return currentDiagnostics;
|
|
1027
1438
|
}
|
|
1028
1439
|
}
|
|
1029
|
-
await new Promise((
|
|
1440
|
+
await new Promise((resolve11) => setTimeout(resolve11, 100));
|
|
1030
1441
|
}
|
|
1031
1442
|
return waitForChange ? initialDiagnostics || [] : [];
|
|
1032
1443
|
}
|
|
@@ -1117,11 +1528,11 @@ function findNearestRoot(cwd, markers) {
|
|
|
1117
1528
|
let current = cwd;
|
|
1118
1529
|
while (current !== "/") {
|
|
1119
1530
|
for (const marker of markers) {
|
|
1120
|
-
if (
|
|
1531
|
+
if (fs9.existsSync(path2.join(current, marker))) {
|
|
1121
1532
|
return current;
|
|
1122
1533
|
}
|
|
1123
1534
|
}
|
|
1124
|
-
const parent =
|
|
1535
|
+
const parent = path2.join(current, "..");
|
|
1125
1536
|
if (parent === current) break;
|
|
1126
1537
|
current = parent;
|
|
1127
1538
|
}
|
|
@@ -1134,7 +1545,7 @@ var BUILTIN_SERVERS = {
|
|
|
1134
1545
|
languageIds: ["typescript", "typescriptreact", "javascript", "javascriptreact"],
|
|
1135
1546
|
root: (cwd) => findNearestRoot(cwd, ["tsconfig.json", "package.json"]),
|
|
1136
1547
|
spawn: async (root) => {
|
|
1137
|
-
const requireFromRoot = module$1.createRequire(url.pathToFileURL(
|
|
1548
|
+
const requireFromRoot = module$1.createRequire(url.pathToFileURL(path2__namespace.default.join(root, "package.json")));
|
|
1138
1549
|
let tsserver;
|
|
1139
1550
|
try {
|
|
1140
1551
|
tsserver = requireFromRoot.resolve("typescript/lib/tsserver.js");
|
|
@@ -1144,12 +1555,12 @@ var BUILTIN_SERVERS = {
|
|
|
1144
1555
|
if (!tsserver) {
|
|
1145
1556
|
return void 0;
|
|
1146
1557
|
}
|
|
1147
|
-
const localBin =
|
|
1148
|
-
const cwdBin =
|
|
1558
|
+
const localBin = path2.join(root, "node_modules", ".bin", "typescript-language-server");
|
|
1559
|
+
const cwdBin = path2.join(process.cwd(), "node_modules", ".bin", "typescript-language-server");
|
|
1149
1560
|
let tslsBinary;
|
|
1150
|
-
if (
|
|
1561
|
+
if (fs9.existsSync(localBin)) {
|
|
1151
1562
|
tslsBinary = localBin;
|
|
1152
|
-
} else if (
|
|
1563
|
+
} else if (fs9.existsSync(cwdBin)) {
|
|
1153
1564
|
tslsBinary = cwdBin;
|
|
1154
1565
|
} else {
|
|
1155
1566
|
tslsBinary = "npx";
|
|
@@ -1176,7 +1587,7 @@ var BUILTIN_SERVERS = {
|
|
|
1176
1587
|
languageIds: ["typescript", "typescriptreact", "javascript", "javascriptreact"],
|
|
1177
1588
|
root: (cwd) => findNearestRoot(cwd, ["package.json", ".eslintrc.js", ".eslintrc.json", ".eslintrc.yml", ".eslintrc.yaml"]),
|
|
1178
1589
|
spawn: (root) => {
|
|
1179
|
-
const binaryPath =
|
|
1590
|
+
const binaryPath = path2.join(process.cwd(), "node_modules", ".bin", "eslint-lsp");
|
|
1180
1591
|
return child_process.spawn(binaryPath, ["--stdio"], {
|
|
1181
1592
|
cwd: root,
|
|
1182
1593
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -1189,8 +1600,8 @@ var BUILTIN_SERVERS = {
|
|
|
1189
1600
|
languageIds: ["python"],
|
|
1190
1601
|
root: (cwd) => findNearestRoot(cwd, ["pyproject.toml", "setup.py", "requirements.txt", ".git"]),
|
|
1191
1602
|
spawn: (root) => {
|
|
1192
|
-
const localPath =
|
|
1193
|
-
const binaryPath =
|
|
1603
|
+
const localPath = path2.join(process.cwd(), "node_modules", ".bin", "pyright-langserver");
|
|
1604
|
+
const binaryPath = fs9.existsSync(localPath) ? localPath : "pyright-langserver";
|
|
1194
1605
|
return child_process.spawn(binaryPath, ["--stdio"], {
|
|
1195
1606
|
cwd: root,
|
|
1196
1607
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -1332,18 +1743,18 @@ var WORKSPACE_MARKERS = [
|
|
|
1332
1743
|
"composer.json"
|
|
1333
1744
|
];
|
|
1334
1745
|
function findWorkspaceRoot(filePath) {
|
|
1335
|
-
let currentDir =
|
|
1336
|
-
const root =
|
|
1746
|
+
let currentDir = path2__namespace.dirname(path2__namespace.resolve(filePath));
|
|
1747
|
+
const root = path2__namespace.parse(currentDir).root;
|
|
1337
1748
|
let closestProjectRoot = null;
|
|
1338
1749
|
let searchDir = currentDir;
|
|
1339
1750
|
while (searchDir !== root) {
|
|
1340
|
-
const hasTsConfig =
|
|
1341
|
-
const hasPackageJson =
|
|
1751
|
+
const hasTsConfig = fs9__namespace.existsSync(path2__namespace.join(searchDir, "tsconfig.json"));
|
|
1752
|
+
const hasPackageJson = fs9__namespace.existsSync(path2__namespace.join(searchDir, "package.json"));
|
|
1342
1753
|
if (hasTsConfig || hasPackageJson) {
|
|
1343
1754
|
closestProjectRoot = searchDir;
|
|
1344
1755
|
break;
|
|
1345
1756
|
}
|
|
1346
|
-
const parentDir =
|
|
1757
|
+
const parentDir = path2__namespace.dirname(searchDir);
|
|
1347
1758
|
if (parentDir === searchDir) {
|
|
1348
1759
|
break;
|
|
1349
1760
|
}
|
|
@@ -1352,21 +1763,21 @@ function findWorkspaceRoot(filePath) {
|
|
|
1352
1763
|
if (closestProjectRoot) {
|
|
1353
1764
|
return closestProjectRoot;
|
|
1354
1765
|
}
|
|
1355
|
-
currentDir =
|
|
1766
|
+
currentDir = path2__namespace.dirname(path2__namespace.resolve(filePath));
|
|
1356
1767
|
while (currentDir !== root) {
|
|
1357
1768
|
for (const marker of WORKSPACE_MARKERS) {
|
|
1358
|
-
const markerPath =
|
|
1359
|
-
if (
|
|
1769
|
+
const markerPath = path2__namespace.join(currentDir, marker);
|
|
1770
|
+
if (fs9__namespace.existsSync(markerPath)) {
|
|
1360
1771
|
return currentDir;
|
|
1361
1772
|
}
|
|
1362
1773
|
}
|
|
1363
|
-
const parentDir =
|
|
1774
|
+
const parentDir = path2__namespace.dirname(currentDir);
|
|
1364
1775
|
if (parentDir === currentDir) {
|
|
1365
1776
|
break;
|
|
1366
1777
|
}
|
|
1367
1778
|
currentDir = parentDir;
|
|
1368
1779
|
}
|
|
1369
|
-
return
|
|
1780
|
+
return path2__namespace.dirname(path2__namespace.resolve(filePath));
|
|
1370
1781
|
}
|
|
1371
1782
|
function removeWhitespace(str) {
|
|
1372
1783
|
return str.replace(/\t/g, "").replace(/ +/g, "").replace(/^ +| +$/gm, "").replace(/\r?\n/g, "\n").replace(/\s/g, "");
|
|
@@ -1696,7 +2107,7 @@ ${divergedMessage ? divergedMessage : ``}Try adjusting your input or the file co
|
|
|
1696
2107
|
}
|
|
1697
2108
|
async isDirectory(filePath) {
|
|
1698
2109
|
try {
|
|
1699
|
-
const stats = await
|
|
2110
|
+
const stats = await fs9.promises.stat(filePath);
|
|
1700
2111
|
return stats.isDirectory();
|
|
1701
2112
|
} catch {
|
|
1702
2113
|
return false;
|
|
@@ -1706,9 +2117,10 @@ ${divergedMessage ? divergedMessage : ``}Try adjusting your input or the file co
|
|
|
1706
2117
|
var sharedFileEditor = new FileEditor();
|
|
1707
2118
|
|
|
1708
2119
|
// src/tools/string-replace-lsp.ts
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
2120
|
+
function createStringReplaceLspTool(projectRoot) {
|
|
2121
|
+
return tools.createTool({
|
|
2122
|
+
id: "string_replace_lsp",
|
|
2123
|
+
description: `Edit a file by replacing exact text matches. Returns Language Server Protocol (LSP) diagnostics to show any errors/warnings introduced by your edit.
|
|
1712
2124
|
|
|
1713
2125
|
Usage notes:
|
|
1714
2126
|
- You MUST use the view tool to read a file before editing it. Never edit blind.
|
|
@@ -1718,99 +2130,104 @@ Usage notes:
|
|
|
1718
2130
|
- Use start_line to narrow the search to a specific region of the file.
|
|
1719
2131
|
- After editing, real LSP diagnostics are returned (TypeScript errors, linting warnings, etc).
|
|
1720
2132
|
- For creating NEW files, use the write_file tool instead.`,
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
try {
|
|
1731
|
-
const absoluteFilePath = path__namespace.isAbsolute(filePath) ? filePath : path__namespace.join(process.cwd(), filePath);
|
|
1732
|
-
const root = process.cwd();
|
|
1733
|
-
const allowedPaths = getAllowedPathsFromContext(toolContext);
|
|
1734
|
-
assertPathAllowed(absoluteFilePath, root, allowedPaths);
|
|
1735
|
-
const result = await sharedFileEditor.strReplace({
|
|
1736
|
-
path: filePath,
|
|
1737
|
-
old_str,
|
|
1738
|
-
new_str: new_str || "",
|
|
1739
|
-
start_line
|
|
1740
|
-
});
|
|
1741
|
-
let diagnosticOutput = "";
|
|
2133
|
+
// requireApproval: true,
|
|
2134
|
+
inputSchema: zod.z.object({
|
|
2135
|
+
path: zod.z.string(),
|
|
2136
|
+
old_str: zod.z.string(),
|
|
2137
|
+
new_str: zod.z.string().optional(),
|
|
2138
|
+
start_line: zod.z.number().optional()
|
|
2139
|
+
}),
|
|
2140
|
+
async execute(context, toolContext) {
|
|
2141
|
+
const { path: filePath, old_str, new_str, start_line } = context;
|
|
1742
2142
|
try {
|
|
1743
|
-
const
|
|
1744
|
-
const
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
const
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
const
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
2143
|
+
const root = projectRoot || process.cwd();
|
|
2144
|
+
const absoluteFilePath = path2__namespace.resolve(root, filePath);
|
|
2145
|
+
const allowedPaths = getAllowedPathsFromContext(toolContext);
|
|
2146
|
+
assertPathAllowed(absoluteFilePath, root, allowedPaths);
|
|
2147
|
+
const result = await sharedFileEditor.strReplace({
|
|
2148
|
+
path: absoluteFilePath,
|
|
2149
|
+
old_str,
|
|
2150
|
+
new_str: new_str || "",
|
|
2151
|
+
start_line
|
|
2152
|
+
});
|
|
2153
|
+
let diagnosticOutput = "";
|
|
2154
|
+
try {
|
|
2155
|
+
const workspaceRoot = findWorkspaceRoot(absoluteFilePath);
|
|
2156
|
+
const client = await lspManager.getClient(absoluteFilePath, workspaceRoot);
|
|
2157
|
+
if (client) {
|
|
2158
|
+
const contentNew = fs9__namespace.readFileSync(absoluteFilePath, "utf-8");
|
|
2159
|
+
const languageId = getLanguageId(absoluteFilePath) || path2__namespace.extname(absoluteFilePath).slice(1);
|
|
2160
|
+
client.notifyOpen(absoluteFilePath, contentNew, languageId);
|
|
2161
|
+
client.notifyChange(absoluteFilePath, contentNew, 1);
|
|
2162
|
+
const diagnostics = await client.waitForDiagnostics(absoluteFilePath, 3e3).catch(() => []);
|
|
2163
|
+
if (diagnostics.length > 0) {
|
|
2164
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2165
|
+
const dedup = diagnostics.filter((d) => {
|
|
2166
|
+
const key = `${d.severity}:${d.range.start.line}:${d.range.start.character}:${d.message}`;
|
|
2167
|
+
if (seen.has(key)) return false;
|
|
2168
|
+
seen.add(key);
|
|
2169
|
+
return true;
|
|
2170
|
+
});
|
|
2171
|
+
const errors = dedup.filter((d) => d.severity === 1);
|
|
2172
|
+
const warnings = dedup.filter((d) => d.severity === 2);
|
|
2173
|
+
const info = dedup.filter((d) => d.severity === 3);
|
|
2174
|
+
const hints = dedup.filter((d) => d.severity === 4);
|
|
2175
|
+
const formatDiags = (items) => items.map((d) => ` ${d.range.start.line + 1}:${d.range.start.character + 1} - ${d.message}`).join("\n");
|
|
2176
|
+
let diagnosticText = "";
|
|
2177
|
+
if (errors.length > 0) {
|
|
2178
|
+
diagnosticText += `
|
|
1767
2179
|
Errors:
|
|
1768
2180
|
${formatDiags(errors)}`;
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
2181
|
+
}
|
|
2182
|
+
if (warnings.length > 0) {
|
|
2183
|
+
diagnosticText += `
|
|
1772
2184
|
Warnings:
|
|
1773
2185
|
${formatDiags(warnings)}`;
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
2186
|
+
}
|
|
2187
|
+
if (info.length > 0) {
|
|
2188
|
+
diagnosticText += `
|
|
1777
2189
|
Info:
|
|
1778
2190
|
${formatDiags(info)}`;
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
2191
|
+
}
|
|
2192
|
+
if (hints.length > 0) {
|
|
2193
|
+
diagnosticText += `
|
|
1782
2194
|
Hints:
|
|
1783
2195
|
${formatDiags(hints)}`;
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
2196
|
+
}
|
|
2197
|
+
if (diagnosticText) {
|
|
2198
|
+
diagnosticOutput = truncateStringForTokenEstimate(`
|
|
1787
2199
|
|
|
1788
2200
|
LSP Diagnostics:${diagnosticText}`, 500, false);
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
2201
|
+
}
|
|
2202
|
+
} else {
|
|
2203
|
+
diagnosticOutput = `
|
|
1792
2204
|
|
|
1793
2205
|
LSP Diagnostics:
|
|
1794
2206
|
No errors or warnings`;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
} catch (lspError) {
|
|
2210
|
+
if (process.env.DEBUG === "true") {
|
|
2211
|
+
console.info("string_replace_lsp: failed to retrieve LSP diagnostics", lspError);
|
|
1795
2212
|
}
|
|
1796
2213
|
}
|
|
1797
|
-
|
|
2214
|
+
return {
|
|
2215
|
+
content: [
|
|
2216
|
+
{
|
|
2217
|
+
type: "text",
|
|
2218
|
+
text: result + diagnosticOutput
|
|
2219
|
+
}
|
|
2220
|
+
]
|
|
2221
|
+
};
|
|
2222
|
+
} catch (e) {
|
|
2223
|
+
return {
|
|
2224
|
+
error: e instanceof Error ? e.message : JSON.stringify(e, null, 2)
|
|
2225
|
+
};
|
|
1798
2226
|
}
|
|
1799
|
-
return {
|
|
1800
|
-
content: [
|
|
1801
|
-
{
|
|
1802
|
-
type: "text",
|
|
1803
|
-
text: result + diagnosticOutput
|
|
1804
|
-
}
|
|
1805
|
-
]
|
|
1806
|
-
};
|
|
1807
|
-
} catch (e) {
|
|
1808
|
-
return {
|
|
1809
|
-
error: e instanceof Error ? e.message : JSON.stringify(e, null, 2)
|
|
1810
|
-
};
|
|
1811
2227
|
}
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
2228
|
+
});
|
|
2229
|
+
}
|
|
2230
|
+
createStringReplaceLspTool();
|
|
1814
2231
|
var MAX_GREP_TOKENS = 2e3;
|
|
1815
2232
|
var rgAvailable = null;
|
|
1816
2233
|
async function hasRipgrep() {
|
|
@@ -1848,7 +2265,7 @@ Usage notes:
|
|
|
1848
2265
|
execute: async (context, toolContext) => {
|
|
1849
2266
|
try {
|
|
1850
2267
|
const root = projectRoot || process.cwd();
|
|
1851
|
-
const searchPath = context.path ?
|
|
2268
|
+
const searchPath = context.path ? path2__namespace.resolve(root, context.path) : root;
|
|
1852
2269
|
const allowedPaths = getAllowedPathsFromContext(toolContext);
|
|
1853
2270
|
assertPathAllowed(searchPath, root, allowedPaths);
|
|
1854
2271
|
const maxResults = context.maxResults ?? 100;
|
|
@@ -1963,7 +2380,7 @@ async function matchGlob(pattern, searchPath, root) {
|
|
|
1963
2380
|
if (result.exitCode !== 0) {
|
|
1964
2381
|
return matchGlobWithFind(pattern, searchPath);
|
|
1965
2382
|
}
|
|
1966
|
-
const allFiles = result.stdout.split("\n").filter((f) => f.trim()).map((f) =>
|
|
2383
|
+
const allFiles = result.stdout.split("\n").filter((f) => f.trim()).map((f) => path2__namespace.resolve(searchPath, f));
|
|
1967
2384
|
return filterByGlob(allFiles, pattern, searchPath);
|
|
1968
2385
|
}
|
|
1969
2386
|
return matchGlobWithFind(pattern, searchPath);
|
|
@@ -1997,7 +2414,7 @@ async function matchGlobWithFind(pattern, searchPath) {
|
|
|
1997
2414
|
function filterByGlob(files, pattern, basePath) {
|
|
1998
2415
|
const regex = globToRegex(pattern);
|
|
1999
2416
|
return files.filter((file) => {
|
|
2000
|
-
const rel =
|
|
2417
|
+
const rel = path2__namespace.relative(basePath, file);
|
|
2001
2418
|
return regex.test(rel);
|
|
2002
2419
|
});
|
|
2003
2420
|
}
|
|
@@ -2053,7 +2470,7 @@ function escapeRegex(s) {
|
|
|
2053
2470
|
}
|
|
2054
2471
|
async function getModTime(filePath) {
|
|
2055
2472
|
try {
|
|
2056
|
-
const stat = await
|
|
2473
|
+
const stat = await fs9__namespace.promises.stat(filePath);
|
|
2057
2474
|
return stat.mtimeMs;
|
|
2058
2475
|
} catch {
|
|
2059
2476
|
return 0;
|
|
@@ -2081,7 +2498,7 @@ Usage notes:
|
|
|
2081
2498
|
execute: async (context, toolContext) => {
|
|
2082
2499
|
try {
|
|
2083
2500
|
const root = projectRoot || process.cwd();
|
|
2084
|
-
const searchPath = context.path ?
|
|
2501
|
+
const searchPath = context.path ? path2__namespace.resolve(root, context.path) : root;
|
|
2085
2502
|
const allowedPaths = getAllowedPathsFromContext(toolContext);
|
|
2086
2503
|
assertPathAllowed(searchPath, root, allowedPaths);
|
|
2087
2504
|
const matches = await matchGlob(context.pattern, searchPath, root);
|
|
@@ -2098,7 +2515,7 @@ Usage notes:
|
|
|
2098
2515
|
}))
|
|
2099
2516
|
);
|
|
2100
2517
|
withTimes.sort((a, b) => b.mtime - a.mtime);
|
|
2101
|
-
const relativePaths = withTimes.map((f) =>
|
|
2518
|
+
const relativePaths = withTimes.map((f) => path2__namespace.relative(root, f.path));
|
|
2102
2519
|
const header = `Found ${relativePaths.length} file${relativePaths.length !== 1 ? "s" : ""} matching "${context.pattern}":
|
|
2103
2520
|
|
|
2104
2521
|
`;
|
|
@@ -2138,17 +2555,17 @@ Usage notes:
|
|
|
2138
2555
|
try {
|
|
2139
2556
|
const root = projectRoot || process.cwd();
|
|
2140
2557
|
const filePath = context.path;
|
|
2141
|
-
const absolutePath =
|
|
2558
|
+
const absolutePath = path2__namespace.resolve(root, filePath);
|
|
2142
2559
|
const allowedPaths = getAllowedPathsFromContext(toolContext);
|
|
2143
2560
|
assertPathAllowed(absolutePath, root, allowedPaths);
|
|
2144
|
-
const exists =
|
|
2145
|
-
const dir =
|
|
2146
|
-
if (!
|
|
2147
|
-
|
|
2561
|
+
const exists = fs9__namespace.existsSync(absolutePath);
|
|
2562
|
+
const dir = path2__namespace.dirname(absolutePath);
|
|
2563
|
+
if (!fs9__namespace.existsSync(dir)) {
|
|
2564
|
+
fs9__namespace.mkdirSync(dir, { recursive: true });
|
|
2148
2565
|
}
|
|
2149
|
-
|
|
2566
|
+
fs9__namespace.writeFileSync(absolutePath, context.content, "utf-8");
|
|
2150
2567
|
const lineCount = context.content.split("\n").length;
|
|
2151
|
-
const relPath =
|
|
2568
|
+
const relPath = path2__namespace.relative(root, absolutePath);
|
|
2152
2569
|
if (exists) {
|
|
2153
2570
|
return {
|
|
2154
2571
|
content: `Overwrote ${relPath} (${lineCount} lines)`,
|
|
@@ -2294,6 +2711,13 @@ function setAuthStorage2(storage) {
|
|
|
2294
2711
|
var CODEX_INSTRUCTIONS = `You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
|
|
2295
2712
|
|
|
2296
2713
|
IMPORTANT: You should be concise, direct, and helpful. Focus on solving the user's problem efficiently.`;
|
|
2714
|
+
var GPT5_MODEL_RE = /^gpt-5(?:\.|-|$)/;
|
|
2715
|
+
function getEffectiveThinkingLevel(modelId, level) {
|
|
2716
|
+
if (GPT5_MODEL_RE.test(modelId) && level === "off") {
|
|
2717
|
+
return "low";
|
|
2718
|
+
}
|
|
2719
|
+
return level;
|
|
2720
|
+
}
|
|
2297
2721
|
var THINKING_LEVEL_TO_REASONING_EFFORT = {
|
|
2298
2722
|
off: void 0,
|
|
2299
2723
|
low: "low",
|
|
@@ -2326,8 +2750,9 @@ function createCodexMiddleware(reasoningEffort) {
|
|
|
2326
2750
|
};
|
|
2327
2751
|
}
|
|
2328
2752
|
function openaiCodexProvider(modelId = "codex-mini-latest", options) {
|
|
2329
|
-
const
|
|
2330
|
-
const
|
|
2753
|
+
const requestedLevel = options?.thinkingLevel ?? "medium";
|
|
2754
|
+
const effectiveLevel = getEffectiveThinkingLevel(modelId, requestedLevel);
|
|
2755
|
+
const reasoningEffort = THINKING_LEVEL_TO_REASONING_EFFORT[effectiveLevel];
|
|
2331
2756
|
const middleware = createCodexMiddleware(reasoningEffort);
|
|
2332
2757
|
if (process.env.NODE_ENV === "test" || process.env.VITEST) {
|
|
2333
2758
|
const openai2 = openai.createOpenAI({
|
|
@@ -2400,10 +2825,61 @@ function openaiCodexProvider(modelId = "codex-mini-latest", options) {
|
|
|
2400
2825
|
});
|
|
2401
2826
|
}
|
|
2402
2827
|
var authStorage = new chunkS5ZLN7DR_cjs.AuthStorage();
|
|
2828
|
+
var OPENAI_PREFIX = "openai/";
|
|
2829
|
+
var CODEX_OPENAI_MODEL_REMAPS = {
|
|
2830
|
+
"gpt-5.3": "gpt-5.3-codex",
|
|
2831
|
+
"gpt-5.2": "gpt-5.2-codex",
|
|
2832
|
+
"gpt-5.1": "gpt-5.1-codex",
|
|
2833
|
+
"gpt-5.1-mini": "gpt-5.1-codex-mini",
|
|
2834
|
+
"gpt-5": "gpt-5-codex"
|
|
2835
|
+
};
|
|
2836
|
+
function remapOpenAIModelForCodexOAuth(modelId) {
|
|
2837
|
+
if (!modelId.startsWith(OPENAI_PREFIX)) {
|
|
2838
|
+
return modelId;
|
|
2839
|
+
}
|
|
2840
|
+
const openaiModelId = modelId.substring(OPENAI_PREFIX.length);
|
|
2841
|
+
if (openaiModelId.includes("-codex")) {
|
|
2842
|
+
return modelId;
|
|
2843
|
+
}
|
|
2844
|
+
const codexModelId = CODEX_OPENAI_MODEL_REMAPS[openaiModelId];
|
|
2845
|
+
if (!codexModelId) {
|
|
2846
|
+
return modelId;
|
|
2847
|
+
}
|
|
2848
|
+
return `${OPENAI_PREFIX}${codexModelId}`;
|
|
2849
|
+
}
|
|
2850
|
+
function getAnthropicApiKey() {
|
|
2851
|
+
if (process.env.ANTHROPIC_API_KEY) {
|
|
2852
|
+
return process.env.ANTHROPIC_API_KEY;
|
|
2853
|
+
}
|
|
2854
|
+
const storedCred = authStorage.get("anthropic");
|
|
2855
|
+
if (storedCred?.type === "api_key") {
|
|
2856
|
+
return storedCred.key;
|
|
2857
|
+
}
|
|
2858
|
+
return void 0;
|
|
2859
|
+
}
|
|
2860
|
+
function anthropicApiKeyProvider(modelId, apiKey) {
|
|
2861
|
+
const anthropic$1 = anthropic.createAnthropic({ apiKey });
|
|
2862
|
+
return ai.wrapLanguageModel({
|
|
2863
|
+
model: anthropic$1(modelId),
|
|
2864
|
+
middleware: [promptCacheMiddleware]
|
|
2865
|
+
});
|
|
2866
|
+
}
|
|
2403
2867
|
function resolveModel(modelId, options) {
|
|
2404
2868
|
authStorage.reload();
|
|
2869
|
+
const [providerId, modelName] = modelId.split("/", 2);
|
|
2870
|
+
const settings = loadSettings();
|
|
2871
|
+
const customProvider = providerId && modelName ? settings.customProviders.find((provider) => {
|
|
2872
|
+
return providerId === getCustomProviderId(provider.name);
|
|
2873
|
+
}) : void 0;
|
|
2874
|
+
if (customProvider) {
|
|
2875
|
+
return new llm.ModelRouterLanguageModel({
|
|
2876
|
+
id: modelId,
|
|
2877
|
+
url: customProvider.url,
|
|
2878
|
+
apiKey: customProvider.apiKey
|
|
2879
|
+
});
|
|
2880
|
+
}
|
|
2405
2881
|
const isAnthropicModel = modelId.startsWith("anthropic/");
|
|
2406
|
-
const isOpenAIModel = modelId.startsWith(
|
|
2882
|
+
const isOpenAIModel = modelId.startsWith(OPENAI_PREFIX);
|
|
2407
2883
|
const isMoonshotModel = modelId.startsWith("moonshotai/");
|
|
2408
2884
|
if (isMoonshotModel) {
|
|
2409
2885
|
if (!process.env.MOONSHOT_AI_API_KEY) {
|
|
@@ -2415,18 +2891,25 @@ function resolveModel(modelId, options) {
|
|
|
2415
2891
|
name: "moonshotai.anthropicv1"
|
|
2416
2892
|
})(modelId.substring("moonshotai/".length));
|
|
2417
2893
|
} else if (isAnthropicModel) {
|
|
2418
|
-
|
|
2894
|
+
const bareModelId = modelId.substring("anthropic/".length);
|
|
2895
|
+
if (authStorage.isLoggedIn("anthropic")) {
|
|
2896
|
+
return opencodeClaudeMaxProvider(bareModelId);
|
|
2897
|
+
}
|
|
2898
|
+
const apiKey = getAnthropicApiKey();
|
|
2899
|
+
if (apiKey) {
|
|
2900
|
+
return anthropicApiKeyProvider(bareModelId, apiKey);
|
|
2901
|
+
}
|
|
2902
|
+
return opencodeClaudeMaxProvider(bareModelId);
|
|
2419
2903
|
} else if (isOpenAIModel && authStorage.isLoggedIn("openai-codex")) {
|
|
2420
|
-
|
|
2904
|
+
const resolvedModelId = options?.remapForCodexOAuth ? remapOpenAIModelForCodexOAuth(modelId) : modelId;
|
|
2905
|
+
return openaiCodexProvider(resolvedModelId.substring(OPENAI_PREFIX.length), {
|
|
2421
2906
|
thinkingLevel: options?.thinkingLevel
|
|
2422
2907
|
});
|
|
2423
2908
|
} else {
|
|
2424
2909
|
return new llm.ModelRouterLanguageModel(modelId);
|
|
2425
2910
|
}
|
|
2426
2911
|
}
|
|
2427
|
-
function getDynamicModel({
|
|
2428
|
-
requestContext
|
|
2429
|
-
}) {
|
|
2912
|
+
function getDynamicModel({ requestContext }) {
|
|
2430
2913
|
const harnessContext = requestContext.get("harness");
|
|
2431
2914
|
const modelId = harnessContext?.state?.currentModelId;
|
|
2432
2915
|
if (!modelId) {
|
|
@@ -2475,14 +2958,14 @@ End with a structured summary:
|
|
|
2475
2958
|
. **Notes**: Follow-up needed (if any)`,
|
|
2476
2959
|
allowedTools: [
|
|
2477
2960
|
// Read tools
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2961
|
+
chunkOEDRHUU5_cjs.MC_TOOLS.VIEW,
|
|
2962
|
+
chunkOEDRHUU5_cjs.MC_TOOLS.SEARCH_CONTENT,
|
|
2963
|
+
chunkOEDRHUU5_cjs.MC_TOOLS.FIND_FILES,
|
|
2481
2964
|
// Write tools
|
|
2482
|
-
|
|
2483
|
-
|
|
2965
|
+
chunkOEDRHUU5_cjs.MC_TOOLS.STRING_REPLACE_LSP,
|
|
2966
|
+
chunkOEDRHUU5_cjs.MC_TOOLS.WRITE_FILE,
|
|
2484
2967
|
// Execution tool
|
|
2485
|
-
|
|
2968
|
+
chunkOEDRHUU5_cjs.MC_TOOLS.EXECUTE_COMMAND,
|
|
2486
2969
|
// Task tracking (built-in harness tools)
|
|
2487
2970
|
"task_write",
|
|
2488
2971
|
"task_check"
|
|
@@ -2519,7 +3002,7 @@ End with a structured summary:
|
|
|
2519
3002
|
. **Details**: Additional context if needed
|
|
2520
3003
|
|
|
2521
3004
|
Keep your summary under 300 words.`,
|
|
2522
|
-
allowedTools: [
|
|
3005
|
+
allowedTools: [chunkOEDRHUU5_cjs.MC_TOOLS.VIEW, chunkOEDRHUU5_cjs.MC_TOOLS.SEARCH_CONTENT, chunkOEDRHUU5_cjs.MC_TOOLS.FIND_FILES]
|
|
2523
3006
|
};
|
|
2524
3007
|
|
|
2525
3008
|
// src/agents/subagents/plan.ts
|
|
@@ -2554,7 +3037,7 @@ Structure your plan as:
|
|
|
2554
3037
|
. **Risks**: Potential issues or edge cases (if any)
|
|
2555
3038
|
|
|
2556
3039
|
Be specific about code locations (file paths, function names, line numbers). Keep the plan actionable and under 500 words.`,
|
|
2557
|
-
allowedTools: [
|
|
3040
|
+
allowedTools: [chunkOEDRHUU5_cjs.MC_TOOLS.VIEW, chunkOEDRHUU5_cjs.MC_TOOLS.SEARCH_CONTENT, chunkOEDRHUU5_cjs.MC_TOOLS.FIND_FILES]
|
|
2558
3041
|
};
|
|
2559
3042
|
var MAX_WEB_SEARCH_TOKENS = 2e3;
|
|
2560
3043
|
var MAX_WEB_EXTRACT_TOKENS = 2e3;
|
|
@@ -2665,7 +3148,6 @@ function parseSubagentMeta(content) {
|
|
|
2665
3148
|
}) : [];
|
|
2666
3149
|
return { text, modelId, durationMs, toolCalls };
|
|
2667
3150
|
}
|
|
2668
|
-
var getProjectRoot = () => process.cwd();
|
|
2669
3151
|
var astSmartEditSchema = zod.z.object({
|
|
2670
3152
|
path: zod.z.string().describe("File path relative to project root"),
|
|
2671
3153
|
pattern: zod.z.string().optional().describe("AST pattern to search for (supports $VARIABLE placeholders)"),
|
|
@@ -2680,9 +3162,10 @@ var astSmartEditSchema = zod.z.object({
|
|
|
2680
3162
|
isDefault: zod.z.boolean().optional()
|
|
2681
3163
|
}).optional().describe("Import specification for add-import transform")
|
|
2682
3164
|
});
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
3165
|
+
function createAstSmartEditTool(projectRoot) {
|
|
3166
|
+
return tools.createTool({
|
|
3167
|
+
id: "ast_smart_edit",
|
|
3168
|
+
description: `Edit code using AST-based analysis for intelligent transformations.
|
|
2686
3169
|
|
|
2687
3170
|
Supports various code transformations:
|
|
2688
3171
|
- Pattern-based search and replace with syntax awareness
|
|
@@ -2695,92 +3178,100 @@ Examples:
|
|
|
2695
3178
|
- Add import: { transform: 'add-import', importSpec: { module: 'react', names: ['useState'] } }
|
|
2696
3179
|
- Rename function: { transform: 'rename-function', targetName: 'oldFunc', newName: 'newFunc' }
|
|
2697
3180
|
- Pattern replace: { pattern: 'console.log($ARG)', replacement: 'logger.debug($ARG)' }`,
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
3181
|
+
// requireApproval: true,
|
|
3182
|
+
inputSchema: astSmartEditSchema,
|
|
3183
|
+
execute: async ({ path: path13, pattern, replacement, selector, transform, targetName, newName, importSpec }, toolContext) => {
|
|
3184
|
+
try {
|
|
3185
|
+
const root = process.cwd();
|
|
3186
|
+
const filePath = path2.resolve(root, path13);
|
|
3187
|
+
const allowedPaths = getAllowedPathsFromContext(toolContext);
|
|
3188
|
+
assertPathAllowed(filePath, root, allowedPaths);
|
|
3189
|
+
const content = fs9.readFileSync(filePath, "utf-8");
|
|
3190
|
+
const lang = getLanguageFromPath(filePath);
|
|
3191
|
+
const ast = napi.parse(lang, content);
|
|
3192
|
+
const astRoot = ast.root();
|
|
3193
|
+
let modifiedContent = content;
|
|
3194
|
+
const changes = [];
|
|
3195
|
+
if (transform) {
|
|
3196
|
+
switch (transform) {
|
|
3197
|
+
case "add-import":
|
|
3198
|
+
if (!importSpec) {
|
|
3199
|
+
throw new Error("importSpec is required for add-import transform");
|
|
3200
|
+
}
|
|
3201
|
+
modifiedContent = addImport(content, astRoot, importSpec);
|
|
3202
|
+
changes.push(`Added import from '${importSpec.module}'`);
|
|
3203
|
+
break;
|
|
3204
|
+
case "remove-import":
|
|
3205
|
+
if (!targetName) {
|
|
3206
|
+
throw new Error("targetName is required for remove-import transform");
|
|
3207
|
+
}
|
|
3208
|
+
modifiedContent = removeImport(content, astRoot, targetName);
|
|
3209
|
+
changes.push(`Removed import '${targetName}'`);
|
|
3210
|
+
break;
|
|
3211
|
+
case "rename-function":
|
|
3212
|
+
if (!targetName || !newName) {
|
|
3213
|
+
throw new Error("targetName and newName are required for rename-function transform");
|
|
3214
|
+
}
|
|
3215
|
+
const funcResult = renameFunction(content, astRoot, targetName, newName);
|
|
3216
|
+
modifiedContent = funcResult.content;
|
|
3217
|
+
changes.push(`Renamed function '${targetName}' to '${newName}' (${funcResult.count} occurrences)`);
|
|
3218
|
+
break;
|
|
3219
|
+
case "rename-variable":
|
|
3220
|
+
if (!targetName || !newName) {
|
|
3221
|
+
throw new Error("targetName and newName are required for rename-variable transform");
|
|
3222
|
+
}
|
|
3223
|
+
const varResult = renameVariable(content, astRoot, targetName, newName);
|
|
3224
|
+
modifiedContent = varResult.content;
|
|
3225
|
+
changes.push(`Renamed variable '${targetName}' to '${newName}' (${varResult.count} occurrences)`);
|
|
3226
|
+
break;
|
|
3227
|
+
default:
|
|
3228
|
+
throw new Error(`Unsupported transform: ${transform}`);
|
|
3229
|
+
}
|
|
3230
|
+
} else if (pattern && replacement !== void 0) {
|
|
3231
|
+
const result = patternReplace(content, astRoot, pattern, replacement);
|
|
3232
|
+
modifiedContent = result.content;
|
|
3233
|
+
changes.push(`Replaced ${result.count} occurrences of pattern`);
|
|
3234
|
+
} else if (selector) {
|
|
3235
|
+
const matches = astRoot.findAll(selector);
|
|
3236
|
+
const matchInfo = matches.map((match) => ({
|
|
3237
|
+
text: match.text(),
|
|
3238
|
+
range: match.range(),
|
|
3239
|
+
kind: match.kind()
|
|
3240
|
+
}));
|
|
3241
|
+
return {
|
|
3242
|
+
matches: matchInfo.length,
|
|
3243
|
+
details: matchInfo.slice(0, 10)
|
|
3244
|
+
// Limit to first 10 matches
|
|
3245
|
+
};
|
|
3246
|
+
} else {
|
|
3247
|
+
throw new Error("Must provide either transform, pattern/replacement, or selector");
|
|
3248
|
+
}
|
|
3249
|
+
if (modifiedContent !== content) {
|
|
3250
|
+
fs9.writeFileSync(filePath, modifiedContent, "utf-8");
|
|
2746
3251
|
}
|
|
2747
|
-
} else if (pattern && replacement !== void 0) {
|
|
2748
|
-
const result = patternReplace(content, root, pattern, replacement);
|
|
2749
|
-
modifiedContent = result.content;
|
|
2750
|
-
changes.push(`Replaced ${result.count} occurrences of pattern`);
|
|
2751
|
-
} else if (selector) {
|
|
2752
|
-
const matches = root.findAll(selector);
|
|
2753
|
-
const matchInfo = matches.map((match) => ({
|
|
2754
|
-
text: match.text(),
|
|
2755
|
-
range: match.range(),
|
|
2756
|
-
kind: match.kind()
|
|
2757
|
-
}));
|
|
2758
3252
|
return {
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
3253
|
+
success: true,
|
|
3254
|
+
changes,
|
|
3255
|
+
modified: modifiedContent !== content
|
|
3256
|
+
};
|
|
3257
|
+
} catch (error) {
|
|
3258
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3259
|
+
if (process.env.DEBUG === "true" && error instanceof Error && error.stack) {
|
|
3260
|
+
return {
|
|
3261
|
+
error: message,
|
|
3262
|
+
stack: error.stack
|
|
3263
|
+
};
|
|
3264
|
+
}
|
|
3265
|
+
return {
|
|
3266
|
+
error: message
|
|
2762
3267
|
};
|
|
2763
|
-
} else {
|
|
2764
|
-
throw new Error("Must provide either transform, pattern/replacement, or selector");
|
|
2765
|
-
}
|
|
2766
|
-
if (modifiedContent !== content) {
|
|
2767
|
-
fs8.writeFileSync(filePath, modifiedContent, "utf-8");
|
|
2768
3268
|
}
|
|
2769
|
-
return {
|
|
2770
|
-
success: true,
|
|
2771
|
-
changes,
|
|
2772
|
-
modified: modifiedContent !== content
|
|
2773
|
-
};
|
|
2774
|
-
} catch (error) {
|
|
2775
|
-
return {
|
|
2776
|
-
error: error.message,
|
|
2777
|
-
stack: error.stack
|
|
2778
|
-
};
|
|
2779
3269
|
}
|
|
2780
|
-
}
|
|
2781
|
-
}
|
|
2782
|
-
|
|
2783
|
-
|
|
3270
|
+
});
|
|
3271
|
+
}
|
|
3272
|
+
createAstSmartEditTool();
|
|
3273
|
+
function getLanguageFromPath(path13) {
|
|
3274
|
+
const ext = path13.split(".").pop()?.toLowerCase();
|
|
2784
3275
|
switch (ext) {
|
|
2785
3276
|
case "ts":
|
|
2786
3277
|
case "tsx":
|
|
@@ -2990,7 +3481,7 @@ var requestSandboxAccessTool = tools.createTool({
|
|
|
2990
3481
|
execute: async ({ path: requestedPath, reason }, context) => {
|
|
2991
3482
|
try {
|
|
2992
3483
|
const harnessCtx = context?.requestContext?.get("harness");
|
|
2993
|
-
const absolutePath =
|
|
3484
|
+
const absolutePath = path2__namespace.isAbsolute(requestedPath) ? requestedPath : path2__namespace.resolve(process.cwd(), requestedPath);
|
|
2994
3485
|
const projectRoot = process.cwd();
|
|
2995
3486
|
const allowedPaths = getAllowedPathsFromContext(context);
|
|
2996
3487
|
if (isPathAllowed(absolutePath, projectRoot, allowedPaths)) {
|
|
@@ -3006,8 +3497,8 @@ var requestSandboxAccessTool = tools.createTool({
|
|
|
3006
3497
|
};
|
|
3007
3498
|
}
|
|
3008
3499
|
const questionId = `sandbox_${++requestCounter}_${Date.now()}`;
|
|
3009
|
-
const answer = await new Promise((
|
|
3010
|
-
harnessCtx.registerQuestion({ questionId, resolve:
|
|
3500
|
+
const answer = await new Promise((resolve11) => {
|
|
3501
|
+
harnessCtx.registerQuestion({ questionId, resolve: resolve11 });
|
|
3011
3502
|
harnessCtx.emitEvent({
|
|
3012
3503
|
type: "sandbox_access_request",
|
|
3013
3504
|
questionId,
|
|
@@ -3048,18 +3539,6 @@ function getAvailableModePacks(access, savedCustomPacks = []) {
|
|
|
3048
3539
|
const packs = [];
|
|
3049
3540
|
const openaiCodex = "openai/gpt-5.3-codex";
|
|
3050
3541
|
const anthropicBuild = access.anthropic === "oauth" ? "anthropic/claude-opus-4-6" : "anthropic/claude-sonnet-4-5";
|
|
3051
|
-
if (access.anthropic && access.openai) {
|
|
3052
|
-
packs.push({
|
|
3053
|
-
id: "varied",
|
|
3054
|
-
name: "Varied",
|
|
3055
|
-
description: "Models from multiple providers",
|
|
3056
|
-
models: {
|
|
3057
|
-
build: anthropicBuild,
|
|
3058
|
-
plan: openaiCodex,
|
|
3059
|
-
fast: access.cerebras ? "cerebras/zai-glm-4.7" : "anthropic/claude-haiku-4-5"
|
|
3060
|
-
}
|
|
3061
|
-
});
|
|
3062
|
-
}
|
|
3063
3542
|
if (access.anthropic) {
|
|
3064
3543
|
packs.push({
|
|
3065
3544
|
id: "anthropic",
|
|
@@ -3148,155 +3627,6 @@ function getAvailableOmPacks(access) {
|
|
|
3148
3627
|
return packs;
|
|
3149
3628
|
}
|
|
3150
3629
|
var ONBOARDING_VERSION = 1;
|
|
3151
|
-
var STORAGE_DEFAULTS = {
|
|
3152
|
-
backend: "libsql",
|
|
3153
|
-
libsql: {},
|
|
3154
|
-
pg: {}
|
|
3155
|
-
};
|
|
3156
|
-
var DEFAULTS = {
|
|
3157
|
-
onboarding: {
|
|
3158
|
-
completedAt: null,
|
|
3159
|
-
skippedAt: null,
|
|
3160
|
-
version: 0,
|
|
3161
|
-
modePackId: null,
|
|
3162
|
-
omPackId: null,
|
|
3163
|
-
claudeMaxOAuthWarningAcknowledgedAt: null
|
|
3164
|
-
},
|
|
3165
|
-
models: {
|
|
3166
|
-
activeModelPackId: null,
|
|
3167
|
-
modeDefaults: {},
|
|
3168
|
-
activeOmPackId: null,
|
|
3169
|
-
omModelOverride: null,
|
|
3170
|
-
subagentModels: {}
|
|
3171
|
-
},
|
|
3172
|
-
preferences: {
|
|
3173
|
-
yolo: null,
|
|
3174
|
-
theme: "auto"
|
|
3175
|
-
},
|
|
3176
|
-
storage: { ...STORAGE_DEFAULTS },
|
|
3177
|
-
customModelPacks: [],
|
|
3178
|
-
modelUseCounts: {}
|
|
3179
|
-
};
|
|
3180
|
-
function getSettingsPath() {
|
|
3181
|
-
return path.join(chunkS5ZLN7DR_cjs.getAppDataDir(), "settings.json");
|
|
3182
|
-
}
|
|
3183
|
-
function migrateFromAuth(settingsPath) {
|
|
3184
|
-
const authPath = path.join(chunkS5ZLN7DR_cjs.getAppDataDir(), "auth.json");
|
|
3185
|
-
if (!fs8.existsSync(authPath)) return false;
|
|
3186
|
-
let authData;
|
|
3187
|
-
try {
|
|
3188
|
-
authData = JSON.parse(fs8.readFileSync(authPath, "utf-8"));
|
|
3189
|
-
} catch {
|
|
3190
|
-
return false;
|
|
3191
|
-
}
|
|
3192
|
-
const modelKeys = Object.keys(authData).filter((k) => k.startsWith("_"));
|
|
3193
|
-
if (modelKeys.length === 0) return false;
|
|
3194
|
-
let settings;
|
|
3195
|
-
if (fs8.existsSync(settingsPath)) {
|
|
3196
|
-
try {
|
|
3197
|
-
const raw = JSON.parse(fs8.readFileSync(settingsPath, "utf-8"));
|
|
3198
|
-
settings = {
|
|
3199
|
-
onboarding: { ...DEFAULTS.onboarding, ...raw.onboarding },
|
|
3200
|
-
models: { ...DEFAULTS.models, ...raw.models },
|
|
3201
|
-
preferences: { ...DEFAULTS.preferences, ...raw.preferences },
|
|
3202
|
-
storage: {
|
|
3203
|
-
...STORAGE_DEFAULTS,
|
|
3204
|
-
...raw.storage,
|
|
3205
|
-
libsql: { ...STORAGE_DEFAULTS.libsql, ...raw.storage?.libsql },
|
|
3206
|
-
pg: { ...STORAGE_DEFAULTS.pg, ...raw.storage?.pg }
|
|
3207
|
-
},
|
|
3208
|
-
customModelPacks: Array.isArray(raw.customModelPacks) ? raw.customModelPacks : [],
|
|
3209
|
-
modelUseCounts: raw.modelUseCounts && typeof raw.modelUseCounts === "object" ? raw.modelUseCounts : {}
|
|
3210
|
-
};
|
|
3211
|
-
} catch {
|
|
3212
|
-
settings = structuredClone(DEFAULTS);
|
|
3213
|
-
}
|
|
3214
|
-
} else {
|
|
3215
|
-
settings = structuredClone(DEFAULTS);
|
|
3216
|
-
}
|
|
3217
|
-
if (authData._modelRanks && typeof authData._modelRanks === "object") {
|
|
3218
|
-
settings.modelUseCounts = { ...authData._modelRanks, ...settings.modelUseCounts };
|
|
3219
|
-
}
|
|
3220
|
-
for (const key of modelKeys) {
|
|
3221
|
-
const modeMatch = key.match(/^_modeModelId_(.+)$/);
|
|
3222
|
-
if (modeMatch?.[1] && typeof authData[key] === "string" && !settings.models.modeDefaults[modeMatch[1]]) {
|
|
3223
|
-
settings.models.modeDefaults[modeMatch[1]] = authData[key];
|
|
3224
|
-
}
|
|
3225
|
-
}
|
|
3226
|
-
for (const key of modelKeys) {
|
|
3227
|
-
if (key === "_subagentModelId" && typeof authData[key] === "string" && !settings.models.subagentModels["default"]) {
|
|
3228
|
-
settings.models.subagentModels["default"] = authData[key];
|
|
3229
|
-
}
|
|
3230
|
-
const saMatch = key.match(/^_subagentModelId_(.+)$/);
|
|
3231
|
-
if (saMatch?.[1] && typeof authData[key] === "string" && !settings.models.subagentModels[saMatch[1]]) {
|
|
3232
|
-
settings.models.subagentModels[saMatch[1]] = authData[key];
|
|
3233
|
-
}
|
|
3234
|
-
}
|
|
3235
|
-
saveSettings(settings, settingsPath);
|
|
3236
|
-
for (const key of modelKeys) {
|
|
3237
|
-
delete authData[key];
|
|
3238
|
-
}
|
|
3239
|
-
try {
|
|
3240
|
-
fs8.writeFileSync(authPath, JSON.stringify(authData, null, 2), "utf-8");
|
|
3241
|
-
} catch {
|
|
3242
|
-
}
|
|
3243
|
-
return true;
|
|
3244
|
-
}
|
|
3245
|
-
function loadSettings(filePath = getSettingsPath()) {
|
|
3246
|
-
migrateFromAuth(filePath);
|
|
3247
|
-
if (!fs8.existsSync(filePath)) return structuredClone(DEFAULTS);
|
|
3248
|
-
try {
|
|
3249
|
-
const raw = JSON.parse(fs8.readFileSync(filePath, "utf-8"));
|
|
3250
|
-
const settings = {
|
|
3251
|
-
onboarding: { ...DEFAULTS.onboarding, ...raw.onboarding },
|
|
3252
|
-
models: { ...DEFAULTS.models, ...raw.models },
|
|
3253
|
-
preferences: { ...DEFAULTS.preferences, ...raw.preferences },
|
|
3254
|
-
storage: {
|
|
3255
|
-
...STORAGE_DEFAULTS,
|
|
3256
|
-
...raw.storage,
|
|
3257
|
-
libsql: { ...STORAGE_DEFAULTS.libsql, ...raw.storage?.libsql },
|
|
3258
|
-
pg: { ...STORAGE_DEFAULTS.pg, ...raw.storage?.pg }
|
|
3259
|
-
},
|
|
3260
|
-
customModelPacks: Array.isArray(raw.customModelPacks) ? raw.customModelPacks : [],
|
|
3261
|
-
modelUseCounts: raw.modelUseCounts && typeof raw.modelUseCounts === "object" ? raw.modelUseCounts : {}
|
|
3262
|
-
};
|
|
3263
|
-
if (raw.models?.omModelId && !settings.models.omModelOverride) {
|
|
3264
|
-
settings.models.omModelOverride = raw.models.omModelId;
|
|
3265
|
-
saveSettings(settings, filePath);
|
|
3266
|
-
}
|
|
3267
|
-
return settings;
|
|
3268
|
-
} catch {
|
|
3269
|
-
return structuredClone(DEFAULTS);
|
|
3270
|
-
}
|
|
3271
|
-
}
|
|
3272
|
-
function resolveModelDefaults(settings, builtinPacks) {
|
|
3273
|
-
const { activeModelPackId, modeDefaults } = settings.models;
|
|
3274
|
-
if (!activeModelPackId) return modeDefaults;
|
|
3275
|
-
if (activeModelPackId.startsWith("custom:")) {
|
|
3276
|
-
const name = activeModelPackId.slice("custom:".length);
|
|
3277
|
-
const pack = settings.customModelPacks.find((p) => p.name === name);
|
|
3278
|
-
if (pack) return pack.models;
|
|
3279
|
-
return modeDefaults;
|
|
3280
|
-
}
|
|
3281
|
-
const builtin = builtinPacks.find((p) => p.id === activeModelPackId);
|
|
3282
|
-
if (builtin) return builtin.models;
|
|
3283
|
-
return modeDefaults;
|
|
3284
|
-
}
|
|
3285
|
-
function resolveOmModel(settings, builtinOmPacks) {
|
|
3286
|
-
const { activeOmPackId, omModelOverride } = settings.models;
|
|
3287
|
-
if (!activeOmPackId) return omModelOverride;
|
|
3288
|
-
if (activeOmPackId === "custom") return omModelOverride;
|
|
3289
|
-
const pack = builtinOmPacks.find((p) => p.id === activeOmPackId);
|
|
3290
|
-
if (pack) return pack.modelId;
|
|
3291
|
-
return omModelOverride;
|
|
3292
|
-
}
|
|
3293
|
-
function saveSettings(settings, filePath = getSettingsPath()) {
|
|
3294
|
-
const dir = path.dirname(filePath);
|
|
3295
|
-
if (!fs8.existsSync(dir)) {
|
|
3296
|
-
fs8.mkdirSync(dir, { recursive: true });
|
|
3297
|
-
}
|
|
3298
|
-
fs8.writeFileSync(filePath, JSON.stringify(settings, null, 2), "utf-8");
|
|
3299
|
-
}
|
|
3300
3630
|
var currentThemeMode = "dark";
|
|
3301
3631
|
function getThemeMode() {
|
|
3302
3632
|
return currentThemeMode;
|
|
@@ -3562,15 +3892,15 @@ var ThreadLockError = class extends Error {
|
|
|
3562
3892
|
}
|
|
3563
3893
|
};
|
|
3564
3894
|
function getLocksDir() {
|
|
3565
|
-
const dir =
|
|
3566
|
-
if (!
|
|
3567
|
-
|
|
3895
|
+
const dir = path2__namespace.join(chunkS5ZLN7DR_cjs.getAppDataDir(), "locks");
|
|
3896
|
+
if (!fs9__namespace.existsSync(dir)) {
|
|
3897
|
+
fs9__namespace.mkdirSync(dir, { recursive: true });
|
|
3568
3898
|
}
|
|
3569
3899
|
return dir;
|
|
3570
3900
|
}
|
|
3571
3901
|
function getLockPath(threadId) {
|
|
3572
3902
|
const safeId = threadId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
3573
|
-
return
|
|
3903
|
+
return path2__namespace.join(getLocksDir(), `${safeId}.lock`);
|
|
3574
3904
|
}
|
|
3575
3905
|
function isProcessAlive(pid) {
|
|
3576
3906
|
try {
|
|
@@ -3583,9 +3913,9 @@ function isProcessAlive(pid) {
|
|
|
3583
3913
|
function acquireThreadLock(threadId) {
|
|
3584
3914
|
const lockPath = getLockPath(threadId);
|
|
3585
3915
|
const myPid = process.pid;
|
|
3586
|
-
if (
|
|
3916
|
+
if (fs9__namespace.existsSync(lockPath)) {
|
|
3587
3917
|
try {
|
|
3588
|
-
const content =
|
|
3918
|
+
const content = fs9__namespace.readFileSync(lockPath, "utf-8").trim();
|
|
3589
3919
|
const ownerPid = parseInt(content, 10);
|
|
3590
3920
|
if (!isNaN(ownerPid) && ownerPid !== myPid && isProcessAlive(ownerPid)) {
|
|
3591
3921
|
throw new ThreadLockError(threadId, ownerPid);
|
|
@@ -3594,17 +3924,17 @@ function acquireThreadLock(threadId) {
|
|
|
3594
3924
|
if (error instanceof ThreadLockError) throw error;
|
|
3595
3925
|
}
|
|
3596
3926
|
}
|
|
3597
|
-
|
|
3927
|
+
fs9__namespace.writeFileSync(lockPath, String(myPid), { mode: 420 });
|
|
3598
3928
|
}
|
|
3599
3929
|
function releaseThreadLock(threadId) {
|
|
3600
3930
|
const lockPath = getLockPath(threadId);
|
|
3601
3931
|
const myPid = process.pid;
|
|
3602
3932
|
try {
|
|
3603
|
-
if (!
|
|
3604
|
-
const content =
|
|
3933
|
+
if (!fs9__namespace.existsSync(lockPath)) return;
|
|
3934
|
+
const content = fs9__namespace.readFileSync(lockPath, "utf-8").trim();
|
|
3605
3935
|
const ownerPid = parseInt(content, 10);
|
|
3606
3936
|
if (ownerPid === myPid) {
|
|
3607
|
-
|
|
3937
|
+
fs9__namespace.unlinkSync(lockPath);
|
|
3608
3938
|
}
|
|
3609
3939
|
} catch {
|
|
3610
3940
|
}
|
|
@@ -3612,15 +3942,15 @@ function releaseThreadLock(threadId) {
|
|
|
3612
3942
|
function releaseAllThreadLocks() {
|
|
3613
3943
|
try {
|
|
3614
3944
|
const locksDir = getLocksDir();
|
|
3615
|
-
const files =
|
|
3945
|
+
const files = fs9__namespace.readdirSync(locksDir);
|
|
3616
3946
|
const myPid = String(process.pid);
|
|
3617
3947
|
for (const file of files) {
|
|
3618
3948
|
if (!file.endsWith(".lock")) continue;
|
|
3619
|
-
const lockPath =
|
|
3949
|
+
const lockPath = path2__namespace.join(locksDir, file);
|
|
3620
3950
|
try {
|
|
3621
|
-
const content =
|
|
3951
|
+
const content = fs9__namespace.readFileSync(lockPath, "utf-8").trim();
|
|
3622
3952
|
if (content === myPid) {
|
|
3623
|
-
|
|
3953
|
+
fs9__namespace.unlinkSync(lockPath);
|
|
3624
3954
|
}
|
|
3625
3955
|
} catch {
|
|
3626
3956
|
}
|
|
@@ -3630,13 +3960,14 @@ function releaseAllThreadLocks() {
|
|
|
3630
3960
|
}
|
|
3631
3961
|
|
|
3632
3962
|
exports.ONBOARDING_VERSION = ONBOARDING_VERSION;
|
|
3963
|
+
exports.THREAD_ACTIVE_MODEL_PACK_ID_KEY = THREAD_ACTIVE_MODEL_PACK_ID_KEY;
|
|
3633
3964
|
exports.ThreadLockError = ThreadLockError;
|
|
3634
3965
|
exports.acquireThreadLock = acquireThreadLock;
|
|
3635
3966
|
exports.applyThemeMode = applyThemeMode;
|
|
3636
|
-
exports.astSmartEditTool = astSmartEditTool;
|
|
3637
3967
|
exports.createExecuteCommandTool = createExecuteCommandTool;
|
|
3638
3968
|
exports.createGlobTool = createGlobTool;
|
|
3639
3969
|
exports.createGrepTool = createGrepTool;
|
|
3970
|
+
exports.createStringReplaceLspTool = createStringReplaceLspTool;
|
|
3640
3971
|
exports.createViewTool = createViewTool;
|
|
3641
3972
|
exports.createWebExtractTool = createWebExtractTool;
|
|
3642
3973
|
exports.createWebSearchTool = createWebSearchTool;
|
|
@@ -3645,7 +3976,9 @@ exports.executeSubagent = executeSubagent;
|
|
|
3645
3976
|
exports.exploreSubagent = exploreSubagent;
|
|
3646
3977
|
exports.getAvailableModePacks = getAvailableModePacks;
|
|
3647
3978
|
exports.getAvailableOmPacks = getAvailableOmPacks;
|
|
3979
|
+
exports.getCustomProviderId = getCustomProviderId;
|
|
3648
3980
|
exports.getDynamicModel = getDynamicModel;
|
|
3981
|
+
exports.getDynamicWorkspace = getDynamicWorkspace;
|
|
3649
3982
|
exports.getEditorTheme = getEditorTheme;
|
|
3650
3983
|
exports.getMarkdownTheme = getMarkdownTheme;
|
|
3651
3984
|
exports.getSelectListTheme = getSelectListTheme;
|
|
@@ -3663,11 +3996,12 @@ exports.requestSandboxAccessTool = requestSandboxAccessTool;
|
|
|
3663
3996
|
exports.resolveModel = resolveModel;
|
|
3664
3997
|
exports.resolveModelDefaults = resolveModelDefaults;
|
|
3665
3998
|
exports.resolveOmModel = resolveOmModel;
|
|
3999
|
+
exports.resolveThreadActiveModelPackId = resolveThreadActiveModelPackId;
|
|
3666
4000
|
exports.saveSettings = saveSettings;
|
|
3667
4001
|
exports.setAuthStorage = setAuthStorage;
|
|
3668
4002
|
exports.setAuthStorage2 = setAuthStorage2;
|
|
3669
|
-
exports.stringReplaceLspTool = stringReplaceLspTool;
|
|
3670
4003
|
exports.theme = theme;
|
|
3671
4004
|
exports.tintHex = tintHex;
|
|
3672
|
-
|
|
3673
|
-
//# sourceMappingURL=chunk-
|
|
4005
|
+
exports.toCustomProviderModelId = toCustomProviderModelId;
|
|
4006
|
+
//# sourceMappingURL=chunk-AJEYT7X3.cjs.map
|
|
4007
|
+
//# sourceMappingURL=chunk-AJEYT7X3.cjs.map
|