@hcu-lab.me/mcp-device 1.0.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/LICENSE +21 -0
- package/README.md +51 -0
- package/dist/bootstrap.d.ts +1 -0
- package/dist/bootstrap.js +22 -0
- package/dist/command-manager.d.ts +8 -0
- package/dist/command-manager.js +241 -0
- package/dist/config-field-definitions.d.ts +41 -0
- package/dist/config-field-definitions.js +37 -0
- package/dist/config-manager.d.ts +102 -0
- package/dist/config-manager.js +291 -0
- package/dist/config.d.ts +6 -0
- package/dist/config.js +10 -0
- package/dist/custom-stdio.d.ts +51 -0
- package/dist/custom-stdio.js +358 -0
- package/dist/data/official-app-ca.pem +12 -0
- package/dist/data/onboarding-prompts.json +70 -0
- package/dist/device/device-state.d.ts +13 -0
- package/dist/device/device-state.js +100 -0
- package/dist/device/device-status.d.ts +81 -0
- package/dist/device/device-status.js +156 -0
- package/dist/device/device.d.ts +16 -0
- package/dist/device/device.js +190 -0
- package/dist/device/execution-engine.d.ts +144 -0
- package/dist/device/execution-engine.js +195 -0
- package/dist/device/gateway-channel.d.ts +48 -0
- package/dist/device/gateway-channel.js +384 -0
- package/dist/device/gateway-config.d.ts +40 -0
- package/dist/device/gateway-config.js +207 -0
- package/dist/device/gateway-identity.d.ts +35 -0
- package/dist/device/gateway-identity.js +178 -0
- package/dist/device/gateway-pairing.d.ts +25 -0
- package/dist/device/gateway-pairing.js +105 -0
- package/dist/device/gateway-secure-transport.d.ts +25 -0
- package/dist/device/gateway-secure-transport.js +117 -0
- package/dist/device/gateway-tool-adapter.d.ts +17 -0
- package/dist/device/gateway-tool-adapter.js +284 -0
- package/dist/device/gateway-url-policy.d.ts +3 -0
- package/dist/device/gateway-url-policy.js +43 -0
- package/dist/device/linux-service.d.ts +70 -0
- package/dist/device/linux-service.js +268 -0
- package/dist/device/official-trust.d.ts +7 -0
- package/dist/device/official-trust.js +49 -0
- package/dist/device/project-inspection.d.ts +1 -0
- package/dist/device/project-inspection.js +180 -0
- package/dist/device/runtime-owner.d.ts +41 -0
- package/dist/device/runtime-owner.js +177 -0
- package/dist/device/windows-dpapi.d.ts +11 -0
- package/dist/device/windows-dpapi.js +67 -0
- package/dist/device/windows-service.d.ts +56 -0
- package/dist/device/windows-service.js +238 -0
- package/dist/error-handlers.d.ts +7 -0
- package/dist/error-handlers.js +15 -0
- package/dist/handlers/edit-search-handlers.d.ts +6 -0
- package/dist/handlers/edit-search-handlers.js +6 -0
- package/dist/handlers/filesystem-handlers.d.ts +38 -0
- package/dist/handlers/filesystem-handlers.js +440 -0
- package/dist/handlers/history-handlers.d.ts +12 -0
- package/dist/handlers/history-handlers.js +67 -0
- package/dist/handlers/index.d.ts +6 -0
- package/dist/handlers/index.js +7 -0
- package/dist/handlers/process-handlers.d.ts +9 -0
- package/dist/handlers/process-handlers.js +15 -0
- package/dist/handlers/search-handlers.d.ts +17 -0
- package/dist/handlers/search-handlers.js +224 -0
- package/dist/handlers/terminal-handlers.d.ts +21 -0
- package/dist/handlers/terminal-handlers.js +35 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +138 -0
- package/dist/mcp-device.d.ts +2 -0
- package/dist/mcp-device.js +7 -0
- package/dist/npm-scripts/remote.d.ts +3 -0
- package/dist/npm-scripts/remote.js +314 -0
- package/dist/search-manager.d.ts +147 -0
- package/dist/search-manager.js +828 -0
- package/dist/server.d.ts +46 -0
- package/dist/server.js +1563 -0
- package/dist/terminal-manager.d.ts +104 -0
- package/dist/terminal-manager.js +635 -0
- package/dist/tools/config.d.ts +96 -0
- package/dist/tools/config.js +260 -0
- package/dist/tools/edit.d.ts +38 -0
- package/dist/tools/edit.js +435 -0
- package/dist/tools/feedback.d.ts +8 -0
- package/dist/tools/feedback.js +132 -0
- package/dist/tools/filesystem.d.ts +79 -0
- package/dist/tools/filesystem.js +947 -0
- package/dist/tools/fuzzySearch.d.ts +12 -0
- package/dist/tools/fuzzySearch.js +74 -0
- package/dist/tools/fuzzySearchCore.d.ts +52 -0
- package/dist/tools/fuzzySearchCore.js +125 -0
- package/dist/tools/improved-process-tools.d.ts +24 -0
- package/dist/tools/improved-process-tools.js +627 -0
- package/dist/tools/mime-types.d.ts +3 -0
- package/dist/tools/mime-types.js +28 -0
- package/dist/tools/pdf/extract-images.d.ts +34 -0
- package/dist/tools/pdf/extract-images.js +132 -0
- package/dist/tools/pdf/index.d.ts +6 -0
- package/dist/tools/pdf/index.js +3 -0
- package/dist/tools/pdf/lib/pdf2md.d.ts +36 -0
- package/dist/tools/pdf/lib/pdf2md.js +76 -0
- package/dist/tools/pdf/manipulations.d.ts +13 -0
- package/dist/tools/pdf/manipulations.js +99 -0
- package/dist/tools/pdf/markdown.d.ts +26 -0
- package/dist/tools/pdf/markdown.js +275 -0
- package/dist/tools/pdf/utils.d.ts +12 -0
- package/dist/tools/pdf/utils.js +34 -0
- package/dist/tools/process.d.ts +3 -0
- package/dist/tools/process.js +56 -0
- package/dist/tools/prompts.d.ts +28 -0
- package/dist/tools/prompts.js +259 -0
- package/dist/tools/schemas.d.ts +454 -0
- package/dist/tools/schemas.js +242 -0
- package/dist/tools/usage.d.ts +5 -0
- package/dist/tools/usage.js +24 -0
- package/dist/types.d.ts +83 -0
- package/dist/types.js +1 -0
- package/dist/ui/config-editor/config-editor-runtime.js +150 -0
- package/dist/ui/config-editor/index.html +13 -0
- package/dist/ui/config-editor/src/app.d.ts +43 -0
- package/dist/ui/config-editor/src/app.js +831 -0
- package/dist/ui/config-editor/src/array-modal.d.ts +19 -0
- package/dist/ui/config-editor/src/array-modal.js +185 -0
- package/dist/ui/config-editor/src/main.d.ts +1 -0
- package/dist/ui/config-editor/src/main.js +2 -0
- package/dist/ui/config-editor/styles.css +587 -0
- package/dist/ui/contracts.d.ts +14 -0
- package/dist/ui/contracts.js +21 -0
- package/dist/ui/file-preview/index.html +16 -0
- package/dist/ui/file-preview/preview-runtime.js +469 -0
- package/dist/ui/file-preview/shared/preview-file-types.d.ts +5 -0
- package/dist/ui/file-preview/shared/preview-file-types.js +59 -0
- package/dist/ui/file-preview/src/app.d.ts +4 -0
- package/dist/ui/file-preview/src/app.js +680 -0
- package/dist/ui/file-preview/src/components/code-viewer.d.ts +6 -0
- package/dist/ui/file-preview/src/components/code-viewer.js +73 -0
- package/dist/ui/file-preview/src/components/highlighting.d.ts +2 -0
- package/dist/ui/file-preview/src/components/highlighting.js +54 -0
- package/dist/ui/file-preview/src/components/html-renderer.d.ts +5 -0
- package/dist/ui/file-preview/src/components/html-renderer.js +47 -0
- package/dist/ui/file-preview/src/components/markdown-renderer.d.ts +1 -0
- package/dist/ui/file-preview/src/components/markdown-renderer.js +59 -0
- package/dist/ui/file-preview/src/directory-controller.d.ts +8 -0
- package/dist/ui/file-preview/src/directory-controller.js +240 -0
- package/dist/ui/file-preview/src/document-layout.d.ts +20 -0
- package/dist/ui/file-preview/src/document-layout.js +109 -0
- package/dist/ui/file-preview/src/document-outline.d.ts +17 -0
- package/dist/ui/file-preview/src/document-outline.js +97 -0
- package/dist/ui/file-preview/src/document-workspace.d.ts +19 -0
- package/dist/ui/file-preview/src/document-workspace.js +33 -0
- package/dist/ui/file-preview/src/file-type-handlers.d.ts +10 -0
- package/dist/ui/file-preview/src/file-type-handlers.js +109 -0
- package/dist/ui/file-preview/src/host/external-actions.d.ts +8 -0
- package/dist/ui/file-preview/src/host/external-actions.js +55 -0
- package/dist/ui/file-preview/src/host/selection-context.d.ts +9 -0
- package/dist/ui/file-preview/src/host/selection-context.js +106 -0
- package/dist/ui/file-preview/src/image-preview.d.ts +3 -0
- package/dist/ui/file-preview/src/image-preview.js +21 -0
- package/dist/ui/file-preview/src/main.d.ts +1 -0
- package/dist/ui/file-preview/src/main.js +5 -0
- package/dist/ui/file-preview/src/markdown/conflict-dialog.d.ts +40 -0
- package/dist/ui/file-preview/src/markdown/conflict-dialog.js +163 -0
- package/dist/ui/file-preview/src/markdown/controller.d.ts +44 -0
- package/dist/ui/file-preview/src/markdown/controller.js +1043 -0
- package/dist/ui/file-preview/src/markdown/editor.d.ts +131 -0
- package/dist/ui/file-preview/src/markdown/editor.js +1479 -0
- package/dist/ui/file-preview/src/markdown/linking.d.ts +16 -0
- package/dist/ui/file-preview/src/markdown/linking.js +228 -0
- package/dist/ui/file-preview/src/markdown/outline.d.ts +2 -0
- package/dist/ui/file-preview/src/markdown/outline.js +16 -0
- package/dist/ui/file-preview/src/markdown/parser.d.ts +30 -0
- package/dist/ui/file-preview/src/markdown/parser.js +38 -0
- package/dist/ui/file-preview/src/markdown/preview.d.ts +1 -0
- package/dist/ui/file-preview/src/markdown/preview.js +20 -0
- package/dist/ui/file-preview/src/markdown/slugify.d.ts +3 -0
- package/dist/ui/file-preview/src/markdown/slugify.js +31 -0
- package/dist/ui/file-preview/src/markdown/utils.d.ts +1 -0
- package/dist/ui/file-preview/src/markdown/utils.js +15 -0
- package/dist/ui/file-preview/src/model.d.ts +35 -0
- package/dist/ui/file-preview/src/model.js +1 -0
- package/dist/ui/file-preview/src/panel-actions.d.ts +17 -0
- package/dist/ui/file-preview/src/panel-actions.js +182 -0
- package/dist/ui/file-preview/src/path-utils.d.ts +6 -0
- package/dist/ui/file-preview/src/path-utils.js +64 -0
- package/dist/ui/file-preview/src/payload-utils.d.ts +11 -0
- package/dist/ui/file-preview/src/payload-utils.js +119 -0
- package/dist/ui/file-preview/src/types.d.ts +1 -0
- package/dist/ui/file-preview/src/types.js +1 -0
- package/dist/ui/file-preview/styles.css +1631 -0
- package/dist/ui/resources.d.ts +28 -0
- package/dist/ui/resources.js +86 -0
- package/dist/ui/shared/compact-row.d.ts +11 -0
- package/dist/ui/shared/compact-row.js +18 -0
- package/dist/ui/shared/escape-html.d.ts +4 -0
- package/dist/ui/shared/escape-html.js +11 -0
- package/dist/ui/shared/host-context.d.ts +15 -0
- package/dist/ui/shared/host-context.js +51 -0
- package/dist/ui/shared/tool-bridge.d.ts +30 -0
- package/dist/ui/shared/tool-bridge.js +137 -0
- package/dist/ui/shared/tool-shell.d.ts +25 -0
- package/dist/ui/shared/tool-shell.js +107 -0
- package/dist/ui/shared/ui-event-tracker.d.ts +9 -0
- package/dist/ui/shared/ui-event-tracker.js +27 -0
- package/dist/ui/shared/widget-state.d.ts +33 -0
- package/dist/ui/shared/widget-state.js +158 -0
- package/dist/utils/ab-test.d.ts +12 -0
- package/dist/utils/ab-test.js +104 -0
- package/dist/utils/capture.d.ts +35 -0
- package/dist/utils/capture.js +481 -0
- package/dist/utils/dockerPrompt.d.ts +17 -0
- package/dist/utils/dockerPrompt.js +53 -0
- package/dist/utils/feature-flags.d.ts +59 -0
- package/dist/utils/feature-flags.js +215 -0
- package/dist/utils/files/base.d.ts +173 -0
- package/dist/utils/files/base.js +5 -0
- package/dist/utils/files/binary.d.ts +21 -0
- package/dist/utils/files/binary.js +65 -0
- package/dist/utils/files/docx.d.ts +47 -0
- package/dist/utils/files/docx.js +679 -0
- package/dist/utils/files/excel.d.ts +24 -0
- package/dist/utils/files/excel.js +437 -0
- package/dist/utils/files/factory.d.ts +41 -0
- package/dist/utils/files/factory.js +113 -0
- package/dist/utils/files/image.d.ts +21 -0
- package/dist/utils/files/image.js +78 -0
- package/dist/utils/files/index.d.ts +10 -0
- package/dist/utils/files/index.js +13 -0
- package/dist/utils/files/pdf.d.ts +32 -0
- package/dist/utils/files/pdf.js +142 -0
- package/dist/utils/files/text.d.ts +63 -0
- package/dist/utils/files/text.js +370 -0
- package/dist/utils/fuzzySearchLogger.d.ts +30 -0
- package/dist/utils/fuzzySearchLogger.js +126 -0
- package/dist/utils/lineEndingHandler.d.ts +21 -0
- package/dist/utils/lineEndingHandler.js +77 -0
- package/dist/utils/logger.d.ts +32 -0
- package/dist/utils/logger.js +72 -0
- package/dist/utils/mcp-ui-ab-test.d.ts +13 -0
- package/dist/utils/mcp-ui-ab-test.js +62 -0
- package/dist/utils/open-browser.d.ts +9 -0
- package/dist/utils/open-browser.js +42 -0
- package/dist/utils/process-detection.d.ts +23 -0
- package/dist/utils/process-detection.js +150 -0
- package/dist/utils/ripgrep-resolver.d.ts +9 -0
- package/dist/utils/ripgrep-resolver.js +74 -0
- package/dist/utils/system-info.d.ts +71 -0
- package/dist/utils/system-info.js +712 -0
- package/dist/utils/toolHistory.d.ts +86 -0
- package/dist/utils/toolHistory.js +257 -0
- package/dist/utils/trackTools.d.ts +6 -0
- package/dist/utils/trackTools.js +54 -0
- package/dist/utils/unsupportedParams.d.ts +24 -0
- package/dist/utils/unsupportedParams.js +66 -0
- package/dist/utils/usageTracker.d.ts +133 -0
- package/dist/utils/usageTracker.js +477 -0
- package/dist/utils/welcome-onboarding.d.ts +11 -0
- package/dist/utils/welcome-onboarding.js +99 -0
- package/dist/utils/withTimeout.d.ts +28 -0
- package/dist/utils/withTimeout.js +85 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/package.json +131 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the entire config including system information
|
|
3
|
+
*/
|
|
4
|
+
export declare function getConfig(): Promise<{
|
|
5
|
+
content: {
|
|
6
|
+
type: string;
|
|
7
|
+
text: string;
|
|
8
|
+
}[];
|
|
9
|
+
structuredContent: {
|
|
10
|
+
config: {
|
|
11
|
+
currentClient: {
|
|
12
|
+
name: string;
|
|
13
|
+
version: string;
|
|
14
|
+
};
|
|
15
|
+
featureFlags: Record<string, any>;
|
|
16
|
+
systemInfo: {
|
|
17
|
+
memory: {
|
|
18
|
+
rss: string;
|
|
19
|
+
heapTotal: string;
|
|
20
|
+
heapUsed: string;
|
|
21
|
+
external: string;
|
|
22
|
+
arrayBuffers: string;
|
|
23
|
+
};
|
|
24
|
+
platform: string;
|
|
25
|
+
platformName: string;
|
|
26
|
+
defaultShell: string;
|
|
27
|
+
pathSeparator: string;
|
|
28
|
+
isWindows: boolean;
|
|
29
|
+
isMacOS: boolean;
|
|
30
|
+
isLinux: boolean;
|
|
31
|
+
docker: import("../utils/system-info.js").ContainerInfo;
|
|
32
|
+
isDXT: boolean;
|
|
33
|
+
nodeInfo?: {
|
|
34
|
+
version: string;
|
|
35
|
+
path: string;
|
|
36
|
+
npmVersion?: string;
|
|
37
|
+
};
|
|
38
|
+
pythonInfo?: {
|
|
39
|
+
available: boolean;
|
|
40
|
+
command: string;
|
|
41
|
+
version?: string;
|
|
42
|
+
};
|
|
43
|
+
processInfo: {
|
|
44
|
+
pid: number;
|
|
45
|
+
arch: string;
|
|
46
|
+
platform: string;
|
|
47
|
+
versions: NodeJS.ProcessVersions;
|
|
48
|
+
};
|
|
49
|
+
examplePaths: {
|
|
50
|
+
home: string;
|
|
51
|
+
temp: string;
|
|
52
|
+
absolute: string;
|
|
53
|
+
accessible?: string[];
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
blockedCommands?: string[];
|
|
57
|
+
defaultShell?: string;
|
|
58
|
+
allowedDirectories?: string[];
|
|
59
|
+
telemetryEnabled?: boolean;
|
|
60
|
+
fileWriteLineLimit?: number;
|
|
61
|
+
fileReadLineLimit?: number;
|
|
62
|
+
clientId?: string;
|
|
63
|
+
};
|
|
64
|
+
uiHints: {
|
|
65
|
+
availableShells: string[];
|
|
66
|
+
};
|
|
67
|
+
entries: {
|
|
68
|
+
key: "defaultShell" | "blockedCommands" | "allowedDirectories" | "telemetryEnabled" | "fileReadLineLimit" | "fileWriteLineLimit";
|
|
69
|
+
value: unknown;
|
|
70
|
+
valueType: "string" | "number" | "boolean" | "array";
|
|
71
|
+
editable: boolean;
|
|
72
|
+
}[];
|
|
73
|
+
};
|
|
74
|
+
} | {
|
|
75
|
+
content: {
|
|
76
|
+
type: string;
|
|
77
|
+
text: string;
|
|
78
|
+
}[];
|
|
79
|
+
structuredContent?: undefined;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Set a specific config value
|
|
83
|
+
*/
|
|
84
|
+
export declare function setConfigValue(args: unknown): Promise<{
|
|
85
|
+
content: {
|
|
86
|
+
type: string;
|
|
87
|
+
text: string;
|
|
88
|
+
}[];
|
|
89
|
+
isError: boolean;
|
|
90
|
+
} | {
|
|
91
|
+
content: {
|
|
92
|
+
type: string;
|
|
93
|
+
text: string;
|
|
94
|
+
}[];
|
|
95
|
+
isError?: undefined;
|
|
96
|
+
}>;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { configManager } from '../config-manager.js';
|
|
2
|
+
import { SetConfigValueArgsSchema } from './schemas.js';
|
|
3
|
+
import { getSystemInfo } from '../utils/system-info.js';
|
|
4
|
+
import { currentClient } from '../server.js';
|
|
5
|
+
import { featureFlagManager } from '../utils/feature-flags.js';
|
|
6
|
+
import { access, readFile } from 'node:fs/promises';
|
|
7
|
+
import { constants as fsConstants } from 'node:fs';
|
|
8
|
+
import { CONFIG_FIELD_DEFINITIONS, CONFIG_FIELD_KEYS, isConfigFieldKey, } from '../config-field-definitions.js';
|
|
9
|
+
const ALLOWED_CONFIG_KEYS = new Set(CONFIG_FIELD_KEYS);
|
|
10
|
+
async function pathExists(pathValue) {
|
|
11
|
+
try {
|
|
12
|
+
await access(pathValue, fsConstants.X_OK);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function detectAvailableShells(systemInfo) {
|
|
20
|
+
const detected = new Set();
|
|
21
|
+
const add = (shell) => {
|
|
22
|
+
if (shell.trim().length > 0) {
|
|
23
|
+
detected.add(shell.trim());
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
add(systemInfo.defaultShell);
|
|
27
|
+
if (systemInfo.isWindows) {
|
|
28
|
+
add(process.env.ComSpec ?? '');
|
|
29
|
+
const systemRoot = process.env.SystemRoot ?? 'C:\\Windows';
|
|
30
|
+
const candidates = [
|
|
31
|
+
`${systemRoot}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`,
|
|
32
|
+
`${systemRoot}\\System32\\cmd.exe`,
|
|
33
|
+
`${systemRoot}\\System32\\bash.exe`,
|
|
34
|
+
'powershell.exe',
|
|
35
|
+
'pwsh.exe',
|
|
36
|
+
'cmd.exe',
|
|
37
|
+
'bash.exe',
|
|
38
|
+
];
|
|
39
|
+
for (const shell of candidates) {
|
|
40
|
+
if (shell.includes('\\')) {
|
|
41
|
+
if (await pathExists(shell)) {
|
|
42
|
+
add(shell);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
add(shell);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return [...detected];
|
|
50
|
+
}
|
|
51
|
+
add(process.env.SHELL ?? '');
|
|
52
|
+
const shellFiles = ['/etc/shells'];
|
|
53
|
+
for (const shellFile of shellFiles) {
|
|
54
|
+
try {
|
|
55
|
+
const content = await readFile(shellFile, 'utf8');
|
|
56
|
+
content
|
|
57
|
+
.split(/\r?\n/)
|
|
58
|
+
.map((line) => line.trim())
|
|
59
|
+
.filter((line) => line.length > 0 && !line.startsWith('#'))
|
|
60
|
+
.forEach(add);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// Best-effort discovery only.
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const fallbackCandidates = ['/bin/zsh', '/bin/bash', '/bin/sh', '/usr/bin/fish'];
|
|
67
|
+
for (const shell of fallbackCandidates) {
|
|
68
|
+
if (await pathExists(shell)) {
|
|
69
|
+
add(shell);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return [...detected];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get the entire config including system information
|
|
76
|
+
*/
|
|
77
|
+
export async function getConfig() {
|
|
78
|
+
console.error('getConfig called');
|
|
79
|
+
try {
|
|
80
|
+
const config = await configManager.getConfig();
|
|
81
|
+
// Add system information and current client to the config response
|
|
82
|
+
const systemInfo = getSystemInfo();
|
|
83
|
+
// Get memory usage
|
|
84
|
+
const memoryUsage = process.memoryUsage();
|
|
85
|
+
const memory = {
|
|
86
|
+
rss: `${(memoryUsage.rss / 1024 / 1024).toFixed(2)} MB`,
|
|
87
|
+
heapTotal: `${(memoryUsage.heapTotal / 1024 / 1024).toFixed(2)} MB`,
|
|
88
|
+
heapUsed: `${(memoryUsage.heapUsed / 1024 / 1024).toFixed(2)} MB`,
|
|
89
|
+
external: `${(memoryUsage.external / 1024 / 1024).toFixed(2)} MB`,
|
|
90
|
+
arrayBuffers: `${(memoryUsage.arrayBuffers / 1024 / 1024).toFixed(2)} MB`
|
|
91
|
+
};
|
|
92
|
+
const configWithSystemInfo = {
|
|
93
|
+
...config,
|
|
94
|
+
currentClient,
|
|
95
|
+
featureFlags: featureFlagManager.getAll(),
|
|
96
|
+
systemInfo: {
|
|
97
|
+
...systemInfo,
|
|
98
|
+
memory
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const availableShells = await detectAvailableShells(systemInfo);
|
|
102
|
+
console.error(`getConfig result: ${JSON.stringify(configWithSystemInfo, null, 2)}`);
|
|
103
|
+
return {
|
|
104
|
+
content: [{
|
|
105
|
+
type: "text",
|
|
106
|
+
text: `Current configuration:\n${JSON.stringify(configWithSystemInfo, null, 2)}`
|
|
107
|
+
}],
|
|
108
|
+
structuredContent: {
|
|
109
|
+
config: configWithSystemInfo,
|
|
110
|
+
uiHints: {
|
|
111
|
+
availableShells,
|
|
112
|
+
},
|
|
113
|
+
entries: CONFIG_FIELD_KEYS.map((key) => {
|
|
114
|
+
const definition = CONFIG_FIELD_DEFINITIONS[key];
|
|
115
|
+
const value = configWithSystemInfo[key];
|
|
116
|
+
return {
|
|
117
|
+
key,
|
|
118
|
+
value,
|
|
119
|
+
valueType: definition.valueType,
|
|
120
|
+
editable: true,
|
|
121
|
+
};
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error(`Error in getConfig: ${error instanceof Error ? error.message : String(error)}`);
|
|
128
|
+
console.error(error instanceof Error && error.stack ? error.stack : 'No stack trace available');
|
|
129
|
+
// Return empty config rather than crashing
|
|
130
|
+
return {
|
|
131
|
+
content: [{
|
|
132
|
+
type: "text",
|
|
133
|
+
text: `Error getting configuration: ${error instanceof Error ? error.message : String(error)}\nUsing empty configuration.`
|
|
134
|
+
}],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Set a specific config value
|
|
140
|
+
*/
|
|
141
|
+
export async function setConfigValue(args) {
|
|
142
|
+
console.error(`setConfigValue called with args: ${JSON.stringify(args)}`);
|
|
143
|
+
try {
|
|
144
|
+
const parsed = SetConfigValueArgsSchema.safeParse(args);
|
|
145
|
+
if (!parsed.success) {
|
|
146
|
+
console.error(`Invalid arguments for set_config_value: ${parsed.error}`);
|
|
147
|
+
return {
|
|
148
|
+
content: [{
|
|
149
|
+
type: "text",
|
|
150
|
+
text: `Invalid arguments: ${parsed.error}`
|
|
151
|
+
}],
|
|
152
|
+
isError: true
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (!isConfigFieldKey(parsed.data.key)) {
|
|
156
|
+
return {
|
|
157
|
+
content: [{
|
|
158
|
+
type: "text",
|
|
159
|
+
text: `Key "${parsed.data.key}" is not configurable via this tool. Allowed keys: ${[...ALLOWED_CONFIG_KEYS].join(', ')}`
|
|
160
|
+
}],
|
|
161
|
+
isError: true
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const fieldDefinition = CONFIG_FIELD_DEFINITIONS[parsed.data.key];
|
|
166
|
+
// Parse string values that should be arrays or objects
|
|
167
|
+
let valueToStore = parsed.data.value;
|
|
168
|
+
// If the value is a string that looks like an array or object, try to parse it
|
|
169
|
+
if (typeof valueToStore === 'string' &&
|
|
170
|
+
(valueToStore.startsWith('[') || valueToStore.startsWith('{'))) {
|
|
171
|
+
try {
|
|
172
|
+
valueToStore = JSON.parse(valueToStore);
|
|
173
|
+
console.error(`Parsed string value to object/array: ${JSON.stringify(valueToStore)}`);
|
|
174
|
+
}
|
|
175
|
+
catch (parseError) {
|
|
176
|
+
console.error(`Failed to parse string as JSON, using as-is: ${parseError}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Special handling for known array configuration keys
|
|
180
|
+
if (fieldDefinition.valueType === 'array' && !Array.isArray(valueToStore)) {
|
|
181
|
+
if (typeof valueToStore === 'string') {
|
|
182
|
+
const originalString = valueToStore;
|
|
183
|
+
try {
|
|
184
|
+
const parsedValue = JSON.parse(originalString);
|
|
185
|
+
valueToStore = parsedValue;
|
|
186
|
+
}
|
|
187
|
+
catch (parseError) {
|
|
188
|
+
console.error(`Failed to parse string as array for ${parsed.data.key}: ${parseError}`);
|
|
189
|
+
// If parsing failed and it's a single value, convert to an array with one item
|
|
190
|
+
if (!originalString.includes('[')) {
|
|
191
|
+
valueToStore = [originalString];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else if (valueToStore !== null) {
|
|
196
|
+
// If not a string or array (and not null), convert to an array with one item
|
|
197
|
+
valueToStore = [String(valueToStore)];
|
|
198
|
+
}
|
|
199
|
+
// Ensure the value is an array after all our conversions
|
|
200
|
+
if (!Array.isArray(valueToStore)) {
|
|
201
|
+
console.error(`Value for ${parsed.data.key} is still not an array, converting to array`);
|
|
202
|
+
valueToStore = [String(valueToStore)];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Harden boolean fields against stringly-typed inputs like "false".
|
|
206
|
+
if (fieldDefinition.valueType === 'boolean') {
|
|
207
|
+
if (typeof valueToStore === 'string') {
|
|
208
|
+
const normalized = valueToStore.trim().toLowerCase();
|
|
209
|
+
if (normalized === 'true') {
|
|
210
|
+
valueToStore = true;
|
|
211
|
+
}
|
|
212
|
+
else if (normalized === 'false') {
|
|
213
|
+
valueToStore = false;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (typeof valueToStore !== 'boolean') {
|
|
217
|
+
return {
|
|
218
|
+
content: [{
|
|
219
|
+
type: "text",
|
|
220
|
+
text: `Value for ${parsed.data.key} must be boolean true/false.`
|
|
221
|
+
}],
|
|
222
|
+
isError: true
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
await configManager.setValue(parsed.data.key, valueToStore);
|
|
227
|
+
// Get the updated configuration to show the user
|
|
228
|
+
const updatedConfig = await configManager.getConfig();
|
|
229
|
+
console.error(`setConfigValue: Successfully set ${parsed.data.key} to ${JSON.stringify(valueToStore)}`);
|
|
230
|
+
return {
|
|
231
|
+
content: [{
|
|
232
|
+
type: "text",
|
|
233
|
+
text: `Successfully set ${parsed.data.key} to ${JSON.stringify(valueToStore, null, 2)}\n\nUpdated configuration:\n${JSON.stringify(updatedConfig, null, 2)}`
|
|
234
|
+
}],
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
catch (saveError) {
|
|
238
|
+
console.error(`Error saving config: ${saveError.message}`);
|
|
239
|
+
// Continue with in-memory change but report error
|
|
240
|
+
return {
|
|
241
|
+
content: [{
|
|
242
|
+
type: "text",
|
|
243
|
+
text: `Value changed in memory but couldn't be saved to disk: ${saveError.message}`
|
|
244
|
+
}],
|
|
245
|
+
isError: true
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
console.error(`Error in setConfigValue: ${error instanceof Error ? error.message : String(error)}`);
|
|
251
|
+
console.error(error instanceof Error && error.stack ? error.stack : 'No stack trace available');
|
|
252
|
+
return {
|
|
253
|
+
content: [{
|
|
254
|
+
type: "text",
|
|
255
|
+
text: `Error setting value: ${error instanceof Error ? error.message : String(error)}`
|
|
256
|
+
}],
|
|
257
|
+
isError: true
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text file editing via search/replace with fuzzy matching support.
|
|
3
|
+
*
|
|
4
|
+
* TECHNICAL DEBT / ARCHITECTURAL NOTE:
|
|
5
|
+
* This file contains text editing logic that should ideally live in TextFileHandler.editRange()
|
|
6
|
+
* to be consistent with how Excel editing works (ExcelFileHandler.editRange()).
|
|
7
|
+
*
|
|
8
|
+
* Current inconsistency:
|
|
9
|
+
* - Excel: edit_block → ExcelFileHandler.editRange() ✓ uses file handler
|
|
10
|
+
* - Text: edit_block → performSearchReplace() here → bypasses TextFileHandler
|
|
11
|
+
*
|
|
12
|
+
* Future refactor should:
|
|
13
|
+
* 1. Move performSearchReplace() + fuzzy logic into TextFileHandler.editRange()
|
|
14
|
+
* 2. Make this file a thin dispatch layer that routes to appropriate FileHandler
|
|
15
|
+
* 3. Unify the editRange() signature to handle both text search/replace and structured edits
|
|
16
|
+
*/
|
|
17
|
+
import { ServerResult } from '../types.js';
|
|
18
|
+
interface SearchReplace {
|
|
19
|
+
search: string;
|
|
20
|
+
replace: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function performSearchReplace(filePath: string, block: SearchReplace, expectedReplacements?: number, origin?: 'ui' | 'llm'): Promise<ServerResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Handle edit_block command
|
|
25
|
+
*
|
|
26
|
+
* 1. Text files: String replacement (old_string/new_string)
|
|
27
|
+
* - Uses fuzzy matching for resilience
|
|
28
|
+
* - Handles expected_replacements parameter
|
|
29
|
+
*
|
|
30
|
+
* 2. Structured files (Excel): Range rewrite (range + content)
|
|
31
|
+
* - Bulk updates to cell ranges (e.g., "Sheet1!A1:C10")
|
|
32
|
+
* - Whole sheet replacement (e.g., "Sheet1")
|
|
33
|
+
* - More powerful and simpler than surgical location-based edits
|
|
34
|
+
* - Supports chunking for large datasets (e.g., 1000 rows at a time)
|
|
35
|
+
|
|
36
|
+
*/
|
|
37
|
+
export declare function handleEditBlock(args: unknown): Promise<ServerResult>;
|
|
38
|
+
export {};
|