dr-claw 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1380 -0
- package/NOTICE +17 -0
- package/README.md +875 -0
- package/README.zh-CN.md +857 -0
- package/dist/api-docs.html +878 -0
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/_basePickBy-C0n1uo4u.js +1 -0
- package/dist/assets/_baseUniq-BRNmhFkc.js +1 -0
- package/dist/assets/arc-DOMBmC_A.js +1 -0
- package/dist/assets/architectureDiagram-VXUJARFQ-CtMWglbD.js +36 -0
- package/dist/assets/blockDiagram-VD42YOAC-DK_gTkJy.js +122 -0
- package/dist/assets/c4Diagram-YG6GDRKO-DrDAvsn7.js +10 -0
- package/dist/assets/channel-BFOE7OyC.js +1 -0
- package/dist/assets/chunk-4BX2VUAB-CGbhdZcN.js +1 -0
- package/dist/assets/chunk-55IACEB6-sGeFSxen.js +1 -0
- package/dist/assets/chunk-B4BG7PRW-RxgHAU_P.js +165 -0
- package/dist/assets/chunk-DI55MBZ5-CvHUXZrx.js +220 -0
- package/dist/assets/chunk-FMBD7UC4-Sn7cXVNU.js +15 -0
- package/dist/assets/chunk-QN33PNHL-bDKOHppN.js +1 -0
- package/dist/assets/chunk-QZHKN3VN-B9kN5LGm.js +1 -0
- package/dist/assets/chunk-TZMSLE5B-CCBe6len.js +1 -0
- package/dist/assets/classDiagram-2ON5EDUG-DQoMNYlY.js +1 -0
- package/dist/assets/classDiagram-v2-WZHVMYZB-DQoMNYlY.js +1 -0
- package/dist/assets/clone-BulQSblH.js +1 -0
- package/dist/assets/cose-bilkent-S5V4N54A-r6sLiHBW.js +1 -0
- package/dist/assets/cytoscape.esm-5J0xJHOV.js +321 -0
- package/dist/assets/dagre-6UL2VRFP-AbsaR1Oa.js +4 -0
- package/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
- package/dist/assets/diagram-PSM6KHXK-DjCvdUyy.js +24 -0
- package/dist/assets/diagram-QEK2KX5R-CqiocXkH.js +43 -0
- package/dist/assets/diagram-S2PKOQOG-D5ALeoII.js +24 -0
- package/dist/assets/erDiagram-Q2GNP2WA-C1AeOsiz.js +60 -0
- package/dist/assets/flowDiagram-NV44I4VS-C98ve_DO.js +162 -0
- package/dist/assets/ganttDiagram-JELNMOA3-3zdLvcxD.js +267 -0
- package/dist/assets/gitGraphDiagram-V2S2FVAM-nDuDMsHh.js +65 -0
- package/dist/assets/graph-Blm-emkR.js +1 -0
- package/dist/assets/index-B8Yutsnm.css +1 -0
- package/dist/assets/index-Cf6gyhc3.js +654 -0
- package/dist/assets/infoDiagram-HS3SLOUP-CmzE3q0R.js +2 -0
- package/dist/assets/init-Gi6I4Gst.js +1 -0
- package/dist/assets/journeyDiagram-XKPGCS4Q-CYaW7LrP.js +139 -0
- package/dist/assets/kanban-definition-3W4ZIXB7-mkmW7p0j.js +89 -0
- package/dist/assets/layout-Ct2kFIId.js +1 -0
- package/dist/assets/linear-CKG9EwIJ.js +1 -0
- package/dist/assets/mermaid.core-CaKcUnnd.js +250 -0
- package/dist/assets/mindmap-definition-VGOIOE7T-Bct-pYin.js +68 -0
- package/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/dist/assets/pieDiagram-ADFJNKIX-C8wFD4Jr.js +30 -0
- package/dist/assets/quadrantDiagram-AYHSOK5B-CuiE_f46.js +7 -0
- package/dist/assets/requirementDiagram-UZGBJVZJ-C4v1CqU8.js +64 -0
- package/dist/assets/sankeyDiagram-TZEHDZUN-keAqqs-Y.js +10 -0
- package/dist/assets/sequenceDiagram-WL72ISMW-ClNbvKTB.js +145 -0
- package/dist/assets/stateDiagram-FKZM4ZOC-D8We-2vq.js +1 -0
- package/dist/assets/stateDiagram-v2-4FDKWEC3-BUURfjrE.js +1 -0
- package/dist/assets/timeline-definition-IT6M3QCI-DsvEMT5T.js +61 -0
- package/dist/assets/treemap-GDKQZRPO-TJrzN7Bj.js +162 -0
- package/dist/assets/vendor-codemirror-ansM-eig.js +33 -0
- package/dist/assets/vendor-react-BWF6YQQ3.js +8 -0
- package/dist/assets/vendor-xterm-DfcmCpbH.js +66 -0
- package/dist/assets/xychartDiagram-PRI3JC2R-BdATmY5F.js +7 -0
- package/dist/clear-cache.html +85 -0
- package/dist/convert-icons.md +53 -0
- package/dist/dr-claw.png +0 -0
- package/dist/favicon.png +0 -0
- package/dist/generate-icons.js +49 -0
- package/dist/icons/claude-ai-icon.svg +1 -0
- package/dist/icons/codex-white.svg +3 -0
- package/dist/icons/codex.svg +3 -0
- package/dist/icons/cursor-white.svg +12 -0
- package/dist/icons/cursor.svg +1 -0
- package/dist/icons/file.svg +16997 -0
- package/dist/icons/generate-icons.md +19 -0
- package/dist/icons/icon-128x128.png +0 -0
- package/dist/icons/icon-144x144.png +0 -0
- package/dist/icons/icon-152x152.png +0 -0
- package/dist/icons/icon-192x192.png +0 -0
- package/dist/icons/icon-384x384.png +0 -0
- package/dist/icons/icon-512x512.png +0 -0
- package/dist/icons/icon-72x72.png +0 -0
- package/dist/icons/icon-96x96.png +0 -0
- package/dist/icons/news/arxiv.svg +1 -0
- package/dist/icons/news/huggingface.svg +8 -0
- package/dist/icons/news/x-black.png +0 -0
- package/dist/icons/news/x-white.png +0 -0
- package/dist/icons/news/xiaohongshu.png +0 -0
- package/dist/index.html +51 -0
- package/dist/leveraged-cognition.png +0 -0
- package/dist/manifest.json +61 -0
- package/dist/screenshots/chat.png +0 -0
- package/dist/screenshots/new_claw.png +0 -0
- package/dist/screenshots/news_dashboard.png +0 -0
- package/dist/screenshots/project_dashboard.png +0 -0
- package/dist/screenshots/research_lab.png +0 -0
- package/dist/screenshots/skill_library.png +0 -0
- package/dist/screenshots/task_list.png +0 -0
- package/dist/screenshots/terminal_example.png +0 -0
- package/dist/screenshots/terminal_example1.png +0 -0
- package/dist/sw.js +58 -0
- package/dist/wechat-group-qr.jpg +0 -0
- package/package.json +133 -0
- package/public/api-docs.html +878 -0
- package/public/clear-cache.html +85 -0
- package/public/convert-icons.md +53 -0
- package/public/dr-claw.png +0 -0
- package/public/favicon.png +0 -0
- package/public/generate-icons.js +49 -0
- package/public/icons/claude-ai-icon.svg +1 -0
- package/public/icons/codex-white.svg +3 -0
- package/public/icons/codex.svg +3 -0
- package/public/icons/cursor-white.svg +12 -0
- package/public/icons/cursor.svg +1 -0
- package/public/icons/file.svg +16997 -0
- package/public/icons/generate-icons.md +19 -0
- package/public/icons/icon-128x128.png +0 -0
- package/public/icons/icon-144x144.png +0 -0
- package/public/icons/icon-152x152.png +0 -0
- package/public/icons/icon-192x192.png +0 -0
- package/public/icons/icon-384x384.png +0 -0
- package/public/icons/icon-512x512.png +0 -0
- package/public/icons/icon-72x72.png +0 -0
- package/public/icons/icon-96x96.png +0 -0
- package/public/icons/news/arxiv.svg +1 -0
- package/public/icons/news/huggingface.svg +8 -0
- package/public/icons/news/x-black.png +0 -0
- package/public/icons/news/x-white.png +0 -0
- package/public/icons/news/xiaohongshu.png +0 -0
- package/public/leveraged-cognition.png +0 -0
- package/public/manifest.json +61 -0
- package/public/screenshots/chat.png +0 -0
- package/public/screenshots/new_claw.png +0 -0
- package/public/screenshots/news_dashboard.png +0 -0
- package/public/screenshots/project_dashboard.png +0 -0
- package/public/screenshots/research_lab.png +0 -0
- package/public/screenshots/skill_library.png +0 -0
- package/public/screenshots/task_list.png +0 -0
- package/public/screenshots/terminal_example.png +0 -0
- package/public/screenshots/terminal_example1.png +0 -0
- package/public/sw.js +58 -0
- package/public/wechat-group-qr.jpg +0 -0
- package/scripts/export-skills-catalog-v2.mjs +746 -0
- package/scripts/fix-node-pty.js +45 -0
- package/scripts/gemini_image_core.py +470 -0
- package/scripts/install-python-tools.js +64 -0
- package/server/AGENTS.md +73 -0
- package/server/__tests__/gemini-legacy-thought.test.mjs +88 -0
- package/server/__tests__/runtimePorts.test.mjs +115 -0
- package/server/__tests__/session-delete.test.mjs +166 -0
- package/server/bin/compute-node +70 -0
- package/server/claude-sdk.js +799 -0
- package/server/cli-chat.js +488 -0
- package/server/cli.js +354 -0
- package/server/compute-node.js +439 -0
- package/server/constants/config.js +5 -0
- package/server/cursor-cli.js +340 -0
- package/server/database/auth.db +0 -0
- package/server/database/db.js +1852 -0
- package/server/database/init.sql +194 -0
- package/server/gemini-cli.js +1352 -0
- package/server/index.js +3154 -0
- package/server/load-env.js +71 -0
- package/server/local-gpu.js +860 -0
- package/server/middleware/auth.js +100 -0
- package/server/openai-codex.js +724 -0
- package/server/openrouter.js +890 -0
- package/server/project-token-usage.js +407 -0
- package/server/projects.js +3973 -0
- package/server/routes/agent.js +1272 -0
- package/server/routes/auth.js +128 -0
- package/server/routes/auto-research.js +558 -0
- package/server/routes/cli-auth.js +958 -0
- package/server/routes/codex.js +344 -0
- package/server/routes/commands.js +601 -0
- package/server/routes/compute.js +358 -0
- package/server/routes/cursor.js +795 -0
- package/server/routes/git.js +1348 -0
- package/server/routes/mcp-utils.js +48 -0
- package/server/routes/mcp.js +618 -0
- package/server/routes/news.js +711 -0
- package/server/routes/projects.js +633 -0
- package/server/routes/references.js +338 -0
- package/server/routes/settings.js +285 -0
- package/server/routes/skills.js +914 -0
- package/server/routes/taskmaster.js +2566 -0
- package/server/routes/telemetry.js +89 -0
- package/server/routes/user.js +155 -0
- package/server/scripts/fix_session_names.js +57 -0
- package/server/scripts/research-news/common_words.py +19 -0
- package/server/scripts/research-news/link_keywords.py +298 -0
- package/server/scripts/research-news/scan_existing_notes.py +266 -0
- package/server/scripts/research-news/scoring_utils.py +227 -0
- package/server/scripts/research-news/search_arxiv.py +842 -0
- package/server/scripts/research-news/search_huggingface.py +438 -0
- package/server/scripts/research-news/search_x.py +490 -0
- package/server/scripts/research-news/search_xiaohongshu.py +610 -0
- package/server/taskmaster-templates/README.md +150 -0
- package/server/taskmaster-templates/README.zh-CN.md +150 -0
- package/server/taskmaster-templates/ai-research-dataset.json +230 -0
- package/server/taskmaster-templates/ai-research-method-model.json +230 -0
- package/server/taskmaster-templates/ai-research-position-paper.json +230 -0
- package/server/telemetry.js +121 -0
- package/server/templates/AGENTS.md +103 -0
- package/server/templates/CLAUDE.md +104 -0
- package/server/templates/GEMINI.md +103 -0
- package/server/templates/cursor-project.md +108 -0
- package/server/templates/index.js +37 -0
- package/server/utils/__tests__/sessionTokenUsage.test.js +82 -0
- package/server/utils/auto-research-mailer.js +57 -0
- package/server/utils/cliResolution.js +170 -0
- package/server/utils/commandParser.js +303 -0
- package/server/utils/cursorCommand.js +61 -0
- package/server/utils/geminiApiKey.js +28 -0
- package/server/utils/gitConfig.js +24 -0
- package/server/utils/imageAttachmentFiles.js +35 -0
- package/server/utils/mcp-detector.js +198 -0
- package/server/utils/parsers/bibtex-parser.js +207 -0
- package/server/utils/permissions.js +100 -0
- package/server/utils/runtimePorts.js +212 -0
- package/server/utils/sessionFormatting.js +68 -0
- package/server/utils/sessionIndex.js +100 -0
- package/server/utils/sessionMode.js +95 -0
- package/server/utils/sessionTokenUsage.js +105 -0
- package/server/utils/taskmaster-websocket.js +129 -0
- package/server/utils/zotero-client.js +136 -0
- package/shared/errorClassifier.js +102 -0
- package/shared/geminiThinkingSupport.d.ts +22 -0
- package/shared/geminiThinkingSupport.js +96 -0
- package/shared/geminiThoughtParser.d.ts +8 -0
- package/shared/geminiThoughtParser.js +30 -0
- package/shared/modelConstants.js +139 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'child_process';
|
|
2
|
+
|
|
3
|
+
function isCommandNotFoundExitCode(code) {
|
|
4
|
+
return code === 127 || code === 9009;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Build ordered CLI command candidates from env override + defaults.
|
|
9
|
+
*
|
|
10
|
+
* @param {Object} options
|
|
11
|
+
* @param {string} options.envVarName Environment variable name containing an override command.
|
|
12
|
+
* @param {string[]} options.defaultCommands Fallback command names in preference order.
|
|
13
|
+
* @param {string} [options.platform=process.platform] Runtime platform, used for Windows suffix handling.
|
|
14
|
+
* @param {boolean} [options.appendWindowsSuffixes=false] Whether to append .cmd/.exe candidates on Windows.
|
|
15
|
+
* @returns {string[]} Unique command candidates in probe order.
|
|
16
|
+
*/
|
|
17
|
+
function getCliCommandCandidates({
|
|
18
|
+
envVarName,
|
|
19
|
+
defaultCommands,
|
|
20
|
+
platform = process.platform,
|
|
21
|
+
appendWindowsSuffixes = false
|
|
22
|
+
}) {
|
|
23
|
+
const envCommand = String(process.env[envVarName] || '').trim();
|
|
24
|
+
const rawCandidates = [];
|
|
25
|
+
|
|
26
|
+
if (envCommand) {
|
|
27
|
+
rawCandidates.push(envCommand);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
for (const command of defaultCommands) {
|
|
31
|
+
if (command) {
|
|
32
|
+
rawCandidates.push(command);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const candidates = [];
|
|
37
|
+
for (const candidate of rawCandidates) {
|
|
38
|
+
candidates.push(candidate);
|
|
39
|
+
|
|
40
|
+
if (appendWindowsSuffixes && platform === 'win32' && !/\.(cmd|exe|bat)$/i.test(candidate)) {
|
|
41
|
+
candidates.push(`${candidate}.cmd`, `${candidate}.exe`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return [...new Set(candidates)];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Probe command availability via synchronous spawn.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} command Command to check.
|
|
52
|
+
* @param {string[]} [args=['--help']] Probe arguments.
|
|
53
|
+
* @param {string} [platform=process.platform] Runtime platform.
|
|
54
|
+
* @returns {boolean} True when command can be invoked.
|
|
55
|
+
*/
|
|
56
|
+
function isCommandAvailable(command, args = ['--help'], platform = process.platform) {
|
|
57
|
+
if (!command) return false;
|
|
58
|
+
|
|
59
|
+
const result = spawnSync(command, args, {
|
|
60
|
+
stdio: 'ignore',
|
|
61
|
+
shell: platform === 'win32'
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return !result.error && !isCommandNotFoundExitCode(result.status);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Probe command availability via async spawn with timeout.
|
|
69
|
+
*
|
|
70
|
+
* @param {string} command Command to check.
|
|
71
|
+
* @param {string[]} [args=['--help']] Probe arguments.
|
|
72
|
+
* @param {Object} [options]
|
|
73
|
+
* @param {string} [options.platform=process.platform] Runtime platform.
|
|
74
|
+
* @param {number} [options.timeoutMs=3000] Max probe duration.
|
|
75
|
+
* @returns {Promise<boolean>} True when command can be spawned.
|
|
76
|
+
*/
|
|
77
|
+
function checkCommandAvailable(command, args = ['--help'], { platform = process.platform, timeoutMs = 3000 } = {}) {
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
let completed = false;
|
|
80
|
+
|
|
81
|
+
let childProcess;
|
|
82
|
+
try {
|
|
83
|
+
childProcess = spawn(command, args, {
|
|
84
|
+
stdio: 'ignore',
|
|
85
|
+
env: process.env,
|
|
86
|
+
shell: platform === 'win32'
|
|
87
|
+
});
|
|
88
|
+
} catch {
|
|
89
|
+
resolve(false);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const finish = (value) => {
|
|
94
|
+
if (completed) return;
|
|
95
|
+
completed = true;
|
|
96
|
+
resolve(value);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const timeout = setTimeout(() => {
|
|
100
|
+
if (!completed) {
|
|
101
|
+
childProcess.kill();
|
|
102
|
+
}
|
|
103
|
+
finish(true);
|
|
104
|
+
}, timeoutMs);
|
|
105
|
+
|
|
106
|
+
childProcess.on('error', (error) => {
|
|
107
|
+
clearTimeout(timeout);
|
|
108
|
+
if (error?.code === 'ENOENT') {
|
|
109
|
+
finish(false);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
finish(true);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
childProcess.on('spawn', () => {
|
|
116
|
+
if (platform !== 'win32') {
|
|
117
|
+
clearTimeout(timeout);
|
|
118
|
+
finish(true);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
childProcess.on('close', (code) => {
|
|
123
|
+
clearTimeout(timeout);
|
|
124
|
+
finish(!isCommandNotFoundExitCode(code));
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Resolve the first available command from a candidate list.
|
|
131
|
+
*
|
|
132
|
+
* @param {Object} options
|
|
133
|
+
* @param {string} options.envVarName Environment variable with command override.
|
|
134
|
+
* @param {string[]} options.defaultCommands Fallback command names in preference order.
|
|
135
|
+
* @param {string[]} [options.args=['--help']] Probe arguments.
|
|
136
|
+
* @param {string} [options.platform=process.platform] Runtime platform.
|
|
137
|
+
* @param {boolean} [options.appendWindowsSuffixes=false] Whether to append .cmd/.exe candidates on Windows.
|
|
138
|
+
* @param {(command: string, args: string[], options: {platform: string}) => Promise<boolean>} [options.probe=checkCommandAvailable] Async probe function.
|
|
139
|
+
* @returns {Promise<string|null>} First available command, or null.
|
|
140
|
+
*/
|
|
141
|
+
async function resolveAvailableCliCommand({
|
|
142
|
+
envVarName,
|
|
143
|
+
defaultCommands,
|
|
144
|
+
args = ['--help'],
|
|
145
|
+
platform = process.platform,
|
|
146
|
+
appendWindowsSuffixes = false,
|
|
147
|
+
probe = (command, probeArgs, probeOptions) => checkCommandAvailable(command, probeArgs, probeOptions)
|
|
148
|
+
}) {
|
|
149
|
+
const candidates = getCliCommandCandidates({
|
|
150
|
+
envVarName,
|
|
151
|
+
defaultCommands,
|
|
152
|
+
platform,
|
|
153
|
+
appendWindowsSuffixes
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
for (const candidate of candidates) {
|
|
157
|
+
if (await probe(candidate, args, { platform })) {
|
|
158
|
+
return candidate;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export {
|
|
166
|
+
getCliCommandCandidates,
|
|
167
|
+
isCommandAvailable,
|
|
168
|
+
checkCommandAvailable,
|
|
169
|
+
resolveAvailableCliCommand
|
|
170
|
+
};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import matter from 'gray-matter';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { execFile } from 'child_process';
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
import { parse as parseShellCommand } from 'shell-quote';
|
|
7
|
+
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
|
|
10
|
+
// Configuration
|
|
11
|
+
const MAX_INCLUDE_DEPTH = 3;
|
|
12
|
+
const BASH_TIMEOUT = 30000; // 30 seconds
|
|
13
|
+
const BASH_COMMAND_ALLOWLIST = [
|
|
14
|
+
'echo',
|
|
15
|
+
'ls',
|
|
16
|
+
'pwd',
|
|
17
|
+
'date',
|
|
18
|
+
'whoami',
|
|
19
|
+
'git',
|
|
20
|
+
'npm',
|
|
21
|
+
'node',
|
|
22
|
+
'cat',
|
|
23
|
+
'grep',
|
|
24
|
+
'find',
|
|
25
|
+
'task-master'
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parse a markdown command file and extract frontmatter and content
|
|
30
|
+
* @param {string} content - Raw markdown content
|
|
31
|
+
* @returns {object} Parsed command with data (frontmatter) and content
|
|
32
|
+
*/
|
|
33
|
+
export function parseCommand(content) {
|
|
34
|
+
try {
|
|
35
|
+
const parsed = matter(content);
|
|
36
|
+
return {
|
|
37
|
+
data: parsed.data || {},
|
|
38
|
+
content: parsed.content || '',
|
|
39
|
+
raw: content
|
|
40
|
+
};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new Error(`Failed to parse command: ${error.message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Replace argument placeholders in content
|
|
48
|
+
* @param {string} content - Content with placeholders
|
|
49
|
+
* @param {string|array} args - Arguments to replace (string or array)
|
|
50
|
+
* @returns {string} Content with replaced arguments
|
|
51
|
+
*/
|
|
52
|
+
export function replaceArguments(content, args) {
|
|
53
|
+
if (!content) return content;
|
|
54
|
+
|
|
55
|
+
let result = content;
|
|
56
|
+
|
|
57
|
+
// Convert args to array if it's a string
|
|
58
|
+
const argsArray = Array.isArray(args) ? args : (args ? [args] : []);
|
|
59
|
+
|
|
60
|
+
// Replace $ARGUMENTS with all arguments joined by space
|
|
61
|
+
const allArgs = argsArray.join(' ');
|
|
62
|
+
result = result.replace(/\$ARGUMENTS/g, allArgs);
|
|
63
|
+
|
|
64
|
+
// Replace positional arguments $1-$9
|
|
65
|
+
for (let i = 1; i <= 9; i++) {
|
|
66
|
+
const regex = new RegExp(`\\$${i}`, 'g');
|
|
67
|
+
const value = argsArray[i - 1] || '';
|
|
68
|
+
result = result.replace(regex, value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Validate file path to prevent directory traversal
|
|
76
|
+
* @param {string} filePath - Path to validate
|
|
77
|
+
* @param {string} basePath - Base directory path
|
|
78
|
+
* @returns {boolean} True if path is safe
|
|
79
|
+
*/
|
|
80
|
+
export function isPathSafe(filePath, basePath) {
|
|
81
|
+
const resolvedPath = path.resolve(basePath, filePath);
|
|
82
|
+
const resolvedBase = path.resolve(basePath);
|
|
83
|
+
const relative = path.relative(resolvedBase, resolvedPath);
|
|
84
|
+
return (
|
|
85
|
+
relative !== '' &&
|
|
86
|
+
!relative.startsWith('..') &&
|
|
87
|
+
!path.isAbsolute(relative)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Process file includes in content (@filename syntax)
|
|
93
|
+
* @param {string} content - Content with @filename includes
|
|
94
|
+
* @param {string} basePath - Base directory for resolving file paths
|
|
95
|
+
* @param {number} depth - Current recursion depth
|
|
96
|
+
* @returns {Promise<string>} Content with includes resolved
|
|
97
|
+
*/
|
|
98
|
+
export async function processFileIncludes(content, basePath, depth = 0) {
|
|
99
|
+
if (!content) return content;
|
|
100
|
+
|
|
101
|
+
// Prevent infinite recursion
|
|
102
|
+
if (depth >= MAX_INCLUDE_DEPTH) {
|
|
103
|
+
throw new Error(`Maximum include depth (${MAX_INCLUDE_DEPTH}) exceeded`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Match @filename patterns (at start of line or after whitespace)
|
|
107
|
+
const includePattern = /(?:^|\s)@([^\s]+)/gm;
|
|
108
|
+
const matches = [...content.matchAll(includePattern)];
|
|
109
|
+
|
|
110
|
+
if (matches.length === 0) {
|
|
111
|
+
return content;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let result = content;
|
|
115
|
+
|
|
116
|
+
for (const match of matches) {
|
|
117
|
+
const fullMatch = match[0];
|
|
118
|
+
const filename = match[1];
|
|
119
|
+
|
|
120
|
+
// Security: prevent directory traversal
|
|
121
|
+
if (!isPathSafe(filename, basePath)) {
|
|
122
|
+
throw new Error(`Invalid file path (directory traversal detected): ${filename}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const filePath = path.resolve(basePath, filename);
|
|
127
|
+
const fileContent = await fs.readFile(filePath, 'utf-8');
|
|
128
|
+
|
|
129
|
+
// Recursively process includes in the included file
|
|
130
|
+
const processedContent = await processFileIncludes(fileContent, basePath, depth + 1);
|
|
131
|
+
|
|
132
|
+
// Replace the @filename with the file content
|
|
133
|
+
result = result.replace(fullMatch, fullMatch.startsWith(' ') ? ' ' + processedContent : processedContent);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error.code === 'ENOENT') {
|
|
136
|
+
throw new Error(`File not found: ${filename}`);
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Validate that a command and its arguments are safe
|
|
147
|
+
* @param {string} commandString - Command string to validate
|
|
148
|
+
* @returns {{ allowed: boolean, command: string, args: string[], error?: string }} Validation result
|
|
149
|
+
*/
|
|
150
|
+
export function validateCommand(commandString) {
|
|
151
|
+
const trimmedCommand = commandString.trim();
|
|
152
|
+
if (!trimmedCommand) {
|
|
153
|
+
return { allowed: false, command: '', args: [], error: 'Empty command' };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Parse the command using shell-quote to handle quotes properly
|
|
157
|
+
const parsed = parseShellCommand(trimmedCommand);
|
|
158
|
+
|
|
159
|
+
// Check for shell operators or control structures
|
|
160
|
+
const hasOperators = parsed.some(token =>
|
|
161
|
+
typeof token === 'object' && token.op
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
if (hasOperators) {
|
|
165
|
+
return {
|
|
166
|
+
allowed: false,
|
|
167
|
+
command: '',
|
|
168
|
+
args: [],
|
|
169
|
+
error: 'Shell operators (&&, ||, |, ;, etc.) are not allowed'
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Extract command and args (all should be strings after validation)
|
|
174
|
+
const tokens = parsed.filter(token => typeof token === 'string');
|
|
175
|
+
|
|
176
|
+
if (tokens.length === 0) {
|
|
177
|
+
return { allowed: false, command: '', args: [], error: 'No valid command found' };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const [command, ...args] = tokens;
|
|
181
|
+
|
|
182
|
+
// Extract just the command name (remove path if present)
|
|
183
|
+
const commandName = path.basename(command);
|
|
184
|
+
|
|
185
|
+
// Check if command exactly matches allowlist (no prefix matching)
|
|
186
|
+
const isAllowed = BASH_COMMAND_ALLOWLIST.includes(commandName);
|
|
187
|
+
|
|
188
|
+
if (!isAllowed) {
|
|
189
|
+
return {
|
|
190
|
+
allowed: false,
|
|
191
|
+
command: commandName,
|
|
192
|
+
args,
|
|
193
|
+
error: `Command '${commandName}' is not in the allowlist`
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Validate arguments don't contain dangerous metacharacters
|
|
198
|
+
const dangerousPattern = /[;&|`$()<>{}[\]\\]/;
|
|
199
|
+
for (const arg of args) {
|
|
200
|
+
if (dangerousPattern.test(arg)) {
|
|
201
|
+
return {
|
|
202
|
+
allowed: false,
|
|
203
|
+
command: commandName,
|
|
204
|
+
args,
|
|
205
|
+
error: `Argument contains dangerous characters: ${arg}`
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return { allowed: true, command: commandName, args };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Backward compatibility: Check if command is allowed (deprecated)
|
|
215
|
+
* @deprecated Use validateCommand() instead for better security
|
|
216
|
+
* @param {string} command - Command to validate
|
|
217
|
+
* @returns {boolean} True if command is allowed
|
|
218
|
+
*/
|
|
219
|
+
export function isBashCommandAllowed(command) {
|
|
220
|
+
const result = validateCommand(command);
|
|
221
|
+
return result.allowed;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Sanitize bash command output
|
|
226
|
+
* @param {string} output - Raw command output
|
|
227
|
+
* @returns {string} Sanitized output
|
|
228
|
+
*/
|
|
229
|
+
export function sanitizeOutput(output) {
|
|
230
|
+
if (!output) return '';
|
|
231
|
+
|
|
232
|
+
// Remove control characters except \t, \n, \r
|
|
233
|
+
return [...output]
|
|
234
|
+
.filter(ch => {
|
|
235
|
+
const code = ch.charCodeAt(0);
|
|
236
|
+
return code === 9 // \t
|
|
237
|
+
|| code === 10 // \n
|
|
238
|
+
|| code === 13 // \r
|
|
239
|
+
|| (code >= 32 && code !== 127);
|
|
240
|
+
})
|
|
241
|
+
.join('');
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Process bash commands in content (!command syntax)
|
|
246
|
+
* @param {string} content - Content with !command syntax
|
|
247
|
+
* @param {object} options - Options for bash execution
|
|
248
|
+
* @returns {Promise<string>} Content with bash commands executed and replaced
|
|
249
|
+
*/
|
|
250
|
+
export async function processBashCommands(content, options = {}) {
|
|
251
|
+
if (!content) return content;
|
|
252
|
+
|
|
253
|
+
const { cwd = process.cwd(), timeout = BASH_TIMEOUT } = options;
|
|
254
|
+
|
|
255
|
+
// Match !command patterns (at start of line or after whitespace)
|
|
256
|
+
const commandPattern = /(?:^|\n)!(.+?)(?=\n|$)/g;
|
|
257
|
+
const matches = [...content.matchAll(commandPattern)];
|
|
258
|
+
|
|
259
|
+
if (matches.length === 0) {
|
|
260
|
+
return content;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
let result = content;
|
|
264
|
+
|
|
265
|
+
for (const match of matches) {
|
|
266
|
+
const fullMatch = match[0];
|
|
267
|
+
const commandString = match[1].trim();
|
|
268
|
+
|
|
269
|
+
// Security: validate command and parse args
|
|
270
|
+
const validation = validateCommand(commandString);
|
|
271
|
+
|
|
272
|
+
if (!validation.allowed) {
|
|
273
|
+
throw new Error(`Command not allowed: ${commandString} - ${validation.error}`);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
// Execute without shell using execFile with parsed args
|
|
278
|
+
const { stdout, stderr } = await execFileAsync(
|
|
279
|
+
validation.command,
|
|
280
|
+
validation.args,
|
|
281
|
+
{
|
|
282
|
+
cwd,
|
|
283
|
+
timeout,
|
|
284
|
+
maxBuffer: 1024 * 1024, // 1MB max output
|
|
285
|
+
shell: false, // IMPORTANT: No shell interpretation
|
|
286
|
+
env: { ...process.env, PATH: process.env.PATH } // Inherit PATH for finding commands
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const output = sanitizeOutput(stdout || stderr || '');
|
|
291
|
+
|
|
292
|
+
// Replace the !command with the output
|
|
293
|
+
result = result.replace(fullMatch, fullMatch.startsWith('\n') ? '\n' + output : output);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (error.killed) {
|
|
296
|
+
throw new Error(`Command timeout: ${commandString}`);
|
|
297
|
+
}
|
|
298
|
+
throw new Error(`Command failed: ${commandString} - ${error.message}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isCommandAvailable, getCliCommandCandidates } from './cliResolution.js';
|
|
2
|
+
|
|
3
|
+
let cachedCursorCommand = null;
|
|
4
|
+
|
|
5
|
+
function getCursorCommandCandidates() {
|
|
6
|
+
return getCliCommandCandidates({
|
|
7
|
+
envVarName: 'CURSOR_CLI_PATH',
|
|
8
|
+
defaultCommands: ['cursor-agent', 'agent']
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function resolveCursorCliCommand(options = {}) {
|
|
13
|
+
const { refresh = false } = options;
|
|
14
|
+
|
|
15
|
+
if (!refresh && cachedCursorCommand) {
|
|
16
|
+
return cachedCursorCommand;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const candidates = getCursorCommandCandidates();
|
|
20
|
+
|
|
21
|
+
for (const candidate of candidates) {
|
|
22
|
+
if (isCommandAvailable(candidate)) {
|
|
23
|
+
cachedCursorCommand = candidate;
|
|
24
|
+
return candidate;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isCursorLoginCommand(command = '') {
|
|
32
|
+
return /^\s*(cursor-agent|agent)\s+login(?:\s|$)/.test(command);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isGeminiLoginCommand(command = '') {
|
|
36
|
+
return /^\s*gemini\s+login(?:\s|$)/.test(command);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function normalizeCursorLoginCommand(command = '') {
|
|
40
|
+
if (isGeminiLoginCommand(command)) {
|
|
41
|
+
return command;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!isCursorLoginCommand(command)) {
|
|
45
|
+
return command;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const resolvedCommand = resolveCursorCliCommand();
|
|
49
|
+
if (!resolvedCommand) {
|
|
50
|
+
return command;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return command.replace(/^\s*(cursor-agent|agent)\b/, resolvedCommand);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
resolveCursorCliCommand,
|
|
58
|
+
isCursorLoginCommand,
|
|
59
|
+
isGeminiLoginCommand,
|
|
60
|
+
normalizeCursorLoginCommand
|
|
61
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { credentialsDb } from '../database/db.js';
|
|
2
|
+
|
|
3
|
+
export function getGeminiApiKeyForUser(userId) {
|
|
4
|
+
if (userId) {
|
|
5
|
+
try {
|
|
6
|
+
const userCredential = credentialsDb.getActiveCredential(userId, 'gemini_api_key');
|
|
7
|
+
if (userCredential) {
|
|
8
|
+
return userCredential;
|
|
9
|
+
}
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error('[WARN] Failed to load Gemini API key from DB:', error.message);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return process.env.GEMINI_API_KEY || null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function withGeminiApiKeyEnv(baseEnv = process.env, geminiApiKey = null) {
|
|
19
|
+
const nextEnv = { ...baseEnv };
|
|
20
|
+
|
|
21
|
+
if (geminiApiKey) {
|
|
22
|
+
nextEnv.GEMINI_API_KEY = geminiApiKey;
|
|
23
|
+
} else {
|
|
24
|
+
delete nextEnv.GEMINI_API_KEY;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return nextEnv;
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { exec } from 'child_process';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
|
|
4
|
+
const execAsync = promisify(exec);
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Read git configuration from system's global git config
|
|
8
|
+
* @returns {Promise<{git_name: string|null, git_email: string|null}>}
|
|
9
|
+
*/
|
|
10
|
+
export async function getSystemGitConfig() {
|
|
11
|
+
try {
|
|
12
|
+
const [nameResult, emailResult] = await Promise.all([
|
|
13
|
+
execAsync('git config --global user.name').catch(() => ({ stdout: '' })),
|
|
14
|
+
execAsync('git config --global user.email').catch(() => ({ stdout: '' }))
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
git_name: nameResult.stdout.trim() || null,
|
|
19
|
+
git_email: emailResult.stdout.trim() || null
|
|
20
|
+
};
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return { git_name: null, git_email: null };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
function normalizeMimeExtension(mimeType) {
|
|
4
|
+
const raw = String(mimeType || '').trim().toLowerCase();
|
|
5
|
+
if (!raw.includes('/')) {
|
|
6
|
+
return 'bin';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const subtype = raw.split('/')[1] || 'bin';
|
|
10
|
+
if (subtype === 'svg+xml') {
|
|
11
|
+
return 'svg';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return subtype.replace(/[^a-z0-9]+/g, '_') || 'bin';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function buildTempAttachmentFilename(index, originalName, mimeType) {
|
|
18
|
+
const ext = normalizeMimeExtension(mimeType);
|
|
19
|
+
const sanitizedOriginal = String(originalName || '')
|
|
20
|
+
.replace(/[^a-zA-Z0-9._-]/g, '_')
|
|
21
|
+
.replace(/^\.+/, '')
|
|
22
|
+
.trim();
|
|
23
|
+
|
|
24
|
+
if (sanitizedOriginal) {
|
|
25
|
+
return `${index + 1}_${sanitizedOriginal}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return `image_${index}.${ext}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function toPortableAtPath(filePath, workingDir, pathApi = path) {
|
|
32
|
+
const baseDir = workingDir || process.cwd();
|
|
33
|
+
const relativePath = pathApi.relative(baseDir, filePath);
|
|
34
|
+
return `@${relativePath.split(pathApi.sep).join('/')}`;
|
|
35
|
+
}
|