@researai/deepscientist 1.5.15 → 1.5.17
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/README.md +385 -104
- package/bin/ds.js +1241 -110
- package/docs/en/00_QUICK_START.md +100 -19
- package/docs/en/01_SETTINGS_REFERENCE.md +34 -1
- package/docs/en/02_START_RESEARCH_GUIDE.md +7 -0
- package/docs/en/05_TUI_GUIDE.md +6 -0
- package/docs/en/06_RUNTIME_AND_CANVAS.md +4 -3
- package/docs/en/09_DOCTOR.md +25 -8
- package/docs/en/14_PROMPT_SKILLS_AND_MCP_GUIDE.md +63 -13
- package/docs/en/15_CODEX_PROVIDER_SETUP.md +37 -11
- package/docs/en/19_EXTERNAL_CONTROLLER_GUIDE.md +226 -0
- package/docs/en/19_LOCAL_BROWSER_AUTH.md +70 -0
- package/docs/en/20_WORKSPACE_MODES_GUIDE.md +250 -0
- package/docs/en/21_LOCAL_MODEL_BACKENDS_GUIDE.md +283 -0
- package/docs/en/91_DEVELOPMENT.md +237 -0
- package/docs/en/README.md +24 -2
- package/docs/zh/00_QUICK_START.md +89 -19
- package/docs/zh/01_SETTINGS_REFERENCE.md +34 -1
- package/docs/zh/02_START_RESEARCH_GUIDE.md +7 -0
- package/docs/zh/05_TUI_GUIDE.md +6 -0
- package/docs/zh/09_DOCTOR.md +26 -9
- package/docs/zh/14_PROMPT_SKILLS_AND_MCP_GUIDE.md +63 -13
- package/docs/zh/15_CODEX_PROVIDER_SETUP.md +37 -11
- package/docs/zh/19_EXTERNAL_CONTROLLER_GUIDE.md +226 -0
- package/docs/zh/19_LOCAL_BROWSER_AUTH.md +68 -0
- package/docs/zh/20_WORKSPACE_MODES_GUIDE.md +251 -0
- package/docs/zh/21_LOCAL_MODEL_BACKENDS_GUIDE.md +281 -0
- package/docs/zh/README.md +24 -2
- package/install.sh +46 -4
- package/package.json +2 -1
- package/pyproject.toml +1 -1
- package/src/deepscientist/__init__.py +1 -1
- package/src/deepscientist/acp/envelope.py +6 -0
- package/src/deepscientist/artifact/service.py +647 -22
- package/src/deepscientist/bash_exec/service.py +234 -9
- package/src/deepscientist/bridges/connectors.py +8 -2
- package/src/deepscientist/cli.py +115 -19
- package/src/deepscientist/codex_cli_compat.py +367 -22
- package/src/deepscientist/config/models.py +2 -1
- package/src/deepscientist/config/service.py +183 -13
- package/src/deepscientist/daemon/api/handlers.py +255 -31
- package/src/deepscientist/daemon/api/router.py +9 -0
- package/src/deepscientist/daemon/app.py +1146 -105
- package/src/deepscientist/diagnostics/__init__.py +6 -0
- package/src/deepscientist/diagnostics/runner_failures.py +130 -0
- package/src/deepscientist/doctor.py +207 -3
- package/src/deepscientist/gitops/__init__.py +10 -1
- package/src/deepscientist/gitops/diff.py +129 -0
- package/src/deepscientist/gitops/service.py +4 -1
- package/src/deepscientist/mcp/server.py +39 -0
- package/src/deepscientist/prompts/builder.py +275 -34
- package/src/deepscientist/quest/layout.py +15 -2
- package/src/deepscientist/quest/service.py +707 -55
- package/src/deepscientist/quest/stage_views.py +6 -1
- package/src/deepscientist/runners/codex.py +143 -43
- package/src/deepscientist/shared.py +19 -0
- package/src/deepscientist/skills/__init__.py +2 -2
- package/src/deepscientist/skills/installer.py +196 -5
- package/src/deepscientist/skills/registry.py +66 -0
- package/src/prompts/connectors/qq.md +18 -8
- package/src/prompts/connectors/weixin.md +16 -6
- package/src/prompts/contracts/shared_interaction.md +14 -2
- package/src/prompts/system.md +23 -5
- package/src/prompts/system_copilot.md +56 -0
- package/src/skills/analysis-campaign/SKILL.md +1 -0
- package/src/skills/baseline/SKILL.md +8 -0
- package/src/skills/decision/SKILL.md +8 -0
- package/src/skills/experiment/SKILL.md +8 -0
- package/src/skills/figure-polish/SKILL.md +1 -0
- package/src/skills/finalize/SKILL.md +1 -0
- package/src/skills/idea/SKILL.md +1 -0
- package/src/skills/intake-audit/SKILL.md +8 -0
- package/src/skills/mentor/SKILL.md +217 -0
- package/src/skills/mentor/references/correction-rules.md +210 -0
- package/src/skills/mentor/references/knowledge-profile.md +91 -0
- package/src/skills/mentor/references/persona-profile.md +138 -0
- package/src/skills/mentor/references/taste-profile.md +128 -0
- package/src/skills/mentor/references/thought-style-profile.md +138 -0
- package/src/skills/mentor/references/work-profile.md +289 -0
- package/src/skills/mentor/references/workflow-profile.md +240 -0
- package/src/skills/optimize/SKILL.md +1 -0
- package/src/skills/rebuttal/SKILL.md +1 -0
- package/src/skills/review/SKILL.md +1 -0
- package/src/skills/scout/SKILL.md +8 -0
- package/src/skills/write/SKILL.md +1 -0
- package/src/tui/dist/app/AppContainer.js +19 -11
- package/src/tui/dist/index.js +4 -1
- package/src/tui/dist/lib/api.js +33 -3
- package/src/tui/package.json +1 -1
- package/src/ui/dist/assets/AiManusChatView-Bv-Z8YpU.js +204 -0
- package/src/ui/dist/assets/AnalysisPlugin-BCKAfjba.js +1 -0
- package/src/ui/dist/assets/CliPlugin-BCKcpc35.js +109 -0
- package/src/ui/dist/assets/CodeEditorPlugin-DbOfSJ8K.js +2 -0
- package/src/ui/dist/assets/CodeViewerPlugin-CbaFRrUU.js +270 -0
- package/src/ui/dist/assets/DocViewerPlugin-DAjLVeQD.js +7 -0
- package/src/ui/dist/assets/GitCommitViewerPlugin-CIUqbUDO.js +1 -0
- package/src/ui/dist/assets/GitDiffViewerPlugin-CQACjoAA.js +6 -0
- package/src/ui/dist/assets/GitSnapshotViewer-0r4nLPke.js +30 -0
- package/src/ui/dist/assets/ImageViewerPlugin-nBOmI2v_.js +26 -0
- package/src/ui/dist/assets/LabCopilotPanel-BHxOxF4z.js +14 -0
- package/src/ui/dist/assets/LabPlugin-BKoZGs95.js +22 -0
- package/src/ui/dist/assets/LatexPlugin-ZwtV8pIp.js +25 -0
- package/src/ui/dist/assets/MarkdownViewerPlugin-DKqVfKyW.js +128 -0
- package/src/ui/dist/assets/MarketplacePlugin-BwxStZ9D.js +13 -0
- package/src/ui/dist/assets/NotebookEditor-BEQhaQbt.js +81 -0
- package/src/ui/dist/assets/{NotebookEditor-CccQYZjX.css → NotebookEditor-BHH8rdGj.css} +1 -1
- package/src/ui/dist/assets/NotebookEditor-BOr3x3Ej.css +1 -0
- package/src/ui/dist/assets/NotebookEditor-DB9N_T9q.js +361 -0
- package/src/ui/dist/assets/PdfLoader-Cy5jtWrr.css +1 -0
- package/src/ui/dist/assets/PdfLoader-eWBONbQP.js +16 -0
- package/src/ui/dist/assets/PdfMarkdownPlugin-D22YOZL3.js +1 -0
- package/src/ui/dist/assets/PdfViewerPlugin-c-RK9DLM.js +17 -0
- package/src/ui/dist/assets/PdfViewerPlugin-nwwE-fjJ.css +1 -0
- package/src/ui/dist/assets/SearchPlugin-CxF9ytAx.js +16 -0
- package/src/ui/dist/assets/SearchPlugin-DA4en4hK.css +1 -0
- package/src/ui/dist/assets/TextViewerPlugin-C5xqeeUH.js +54 -0
- package/src/ui/dist/assets/VNCViewer-BoLGLnHz.js +11 -0
- package/src/ui/dist/assets/bot-DREQOxzP.js +6 -0
- package/src/ui/dist/assets/browser-CTB2jwNe.js +8 -0
- package/src/ui/dist/assets/chevron-up-C9Qpx4DE.js +6 -0
- package/src/ui/dist/assets/code-WlFHE7z_.js +6 -0
- package/src/ui/dist/assets/file-content-BZMz3RYp.js +1 -0
- package/src/ui/dist/assets/file-diff-panel-CQhw0jS2.js +1 -0
- package/src/ui/dist/assets/file-jump-queue-DA-SdG__.js +1 -0
- package/src/ui/dist/assets/file-socket-CfQPKQKj.js +1 -0
- package/src/ui/dist/assets/git-commit-horizontal-DxZ8DCZh.js +6 -0
- package/src/ui/dist/assets/image-Bgl4VIyx.js +6 -0
- package/src/ui/dist/assets/index-BpV6lusQ.css +33 -0
- package/src/ui/dist/assets/index-CBNVuWcP.js +2496 -0
- package/src/ui/dist/assets/index-CwNu1aH4.js +11 -0
- package/src/ui/dist/assets/index-DrUnlf6K.js +1 -0
- package/src/ui/dist/assets/index-NW-h8VzN.js +1 -0
- package/src/ui/dist/assets/monaco-CiHMMNH_.js +1 -0
- package/src/ui/dist/assets/pdf-effect-queue-J8OnM0jE.js +6 -0
- package/src/ui/dist/assets/plugin-monaco-C8UgLomw.js +19 -0
- package/src/ui/dist/assets/plugin-notebook-HbW2K-1c.js +169 -0
- package/src/ui/dist/assets/plugin-pdf-CR8hgQBV.js +357 -0
- package/src/ui/dist/assets/plugin-terminal-MXFIPun8.js +227 -0
- package/src/ui/dist/assets/popover-CLc0pPP8.js +1 -0
- package/src/ui/dist/assets/project-sync-C9IdzdZW.js +1 -0
- package/src/ui/dist/assets/select-Cs2PmzwL.js +11 -0
- package/src/ui/dist/assets/sigma-ClKcHAXm.js +6 -0
- package/src/ui/dist/assets/trash-DwpbFr3w.js +11 -0
- package/src/ui/dist/assets/useCliAccess-NQ8m0Let.js +1 -0
- package/src/ui/dist/assets/useFileDiffOverlay-FuhcnKiw.js +1 -0
- package/src/ui/dist/assets/wrap-text-BC-Hltpd.js +11 -0
- package/src/ui/dist/assets/zoom-out-E_gaeAxL.js +11 -0
- package/src/ui/dist/index.html +5 -2
- package/src/ui/dist/assets/AiManusChatView-DDjbFnbt.js +0 -26597
- package/src/ui/dist/assets/AnalysisPlugin-Yb5IdmaU.js +0 -123
- package/src/ui/dist/assets/CliPlugin-e64sreyu.js +0 -31037
- package/src/ui/dist/assets/CodeEditorPlugin-C4D2TIkU.js +0 -427
- package/src/ui/dist/assets/CodeViewerPlugin-BVoNZIvC.js +0 -905
- package/src/ui/dist/assets/DocViewerPlugin-CLChbllo.js +0 -278
- package/src/ui/dist/assets/GitDiffViewerPlugin-C4xeFyFQ.js +0 -2661
- package/src/ui/dist/assets/ImageViewerPlugin-OiMUAcLi.js +0 -500
- package/src/ui/dist/assets/LabCopilotPanel-BjD2ThQF.js +0 -4104
- package/src/ui/dist/assets/LabPlugin-DQPg-NrB.js +0 -2677
- package/src/ui/dist/assets/LatexPlugin-CI05XAV9.js +0 -1792
- package/src/ui/dist/assets/MarkdownViewerPlugin-DpeBLYZf.js +0 -308
- package/src/ui/dist/assets/MarketplacePlugin-DolE58Q2.js +0 -413
- package/src/ui/dist/assets/NotebookEditor-7Qm2rSWD.js +0 -4214
- package/src/ui/dist/assets/NotebookEditor-C1kWaxKi.js +0 -84873
- package/src/ui/dist/assets/NotebookEditor-C3VQ7ylN.css +0 -1405
- package/src/ui/dist/assets/PdfLoader-BfOHw8Zw.js +0 -25468
- package/src/ui/dist/assets/PdfLoader-C-Y707R3.css +0 -49
- package/src/ui/dist/assets/PdfMarkdownPlugin-BulDREv1.js +0 -409
- package/src/ui/dist/assets/PdfViewerPlugin-C-daaOaL.js +0 -3095
- package/src/ui/dist/assets/PdfViewerPlugin-DQ11QcSf.css +0 -3627
- package/src/ui/dist/assets/SearchPlugin-CjpaiJ3A.js +0 -741
- package/src/ui/dist/assets/SearchPlugin-DDMrGDkh.css +0 -379
- package/src/ui/dist/assets/TextViewerPlugin-BxIyqPQC.js +0 -472
- package/src/ui/dist/assets/VNCViewer-HAg9mF7M.js +0 -18821
- package/src/ui/dist/assets/awareness-C0NPR2Dj.js +0 -292
- package/src/ui/dist/assets/bot-0DYntytV.js +0 -21
- package/src/ui/dist/assets/browser-BAcuE0Xj.js +0 -2895
- package/src/ui/dist/assets/code-B20Slj_w.js +0 -17
- package/src/ui/dist/assets/file-content-DT24KFma.js +0 -377
- package/src/ui/dist/assets/file-diff-panel-DK13YPql.js +0 -92
- package/src/ui/dist/assets/file-jump-queue-r5XKgJEV.js +0 -16
- package/src/ui/dist/assets/file-socket-B4T2o4nR.js +0 -58
- package/src/ui/dist/assets/function-B5QZkkHC.js +0 -1895
- package/src/ui/dist/assets/image-DSeR_sDS.js +0 -18
- package/src/ui/dist/assets/index-BrFje2Uk.js +0 -120
- package/src/ui/dist/assets/index-BwRJaoTl.js +0 -25
- package/src/ui/dist/assets/index-D_E4281X.js +0 -221322
- package/src/ui/dist/assets/index-DnYB3xb1.js +0 -159
- package/src/ui/dist/assets/index-G7AcWcMu.css +0 -12594
- package/src/ui/dist/assets/monaco-LExaAN3Y.js +0 -623
- package/src/ui/dist/assets/pdf-effect-queue-BJk5okWJ.js +0 -47
- package/src/ui/dist/assets/pdf_viewer-e0g1is2C.js +0 -8206
- package/src/ui/dist/assets/popover-D3Gg_FoV.js +0 -476
- package/src/ui/dist/assets/project-sync-C_ygLlVU.js +0 -297
- package/src/ui/dist/assets/select-CpAK6uWm.js +0 -1690
- package/src/ui/dist/assets/sigma-DEccaSgk.js +0 -22
- package/src/ui/dist/assets/square-check-big-uUfyVsbD.js +0 -17
- package/src/ui/dist/assets/trash-CXvwwSe8.js +0 -32
- package/src/ui/dist/assets/useCliAccess-Bnop4mgR.js +0 -957
- package/src/ui/dist/assets/useFileDiffOverlay-B8eUAX0I.js +0 -53
- package/src/ui/dist/assets/wrap-text-9vbOBpkW.js +0 -35
- package/src/ui/dist/assets/yjs-DncrqiZ8.js +0 -11243
- package/src/ui/dist/assets/zoom-out-BgVMmOW4.js +0 -34
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/monaco-LExaAN3Y.js","assets/index-D_E4281X.js","assets/index-G7AcWcMu.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import { i as isCliFileId, R as React, f as useFileTreeStore, j as jsxRuntimeExports, b as cn, L as LoaderCircle, S as Save, B as Braces, g as RefreshCw, h as dynamic, _ as __vitePreload } from './index-D_E4281X.js';
|
|
3
|
-
import { u as useFileContentStore, a as useFileContentLoading } from './file-content-DT24KFma.js';
|
|
4
|
-
import { a as acquireFileSocket } from './file-socket-B4T2o4nR.js';
|
|
5
|
-
import { c as configureMonacoLoader } from './monaco-LExaAN3Y.js';
|
|
6
|
-
import { u as useFileDiffOverlay } from './useFileDiffOverlay-B8eUAX0I.js';
|
|
7
|
-
import { F as FileDiffPanel } from './file-diff-panel-DK13YPql.js';
|
|
8
|
-
|
|
9
|
-
const MonacoEditor = dynamic(() => __vitePreload(() => import('./monaco-LExaAN3Y.js').then(n => n.i),true?__vite__mapDeps([0,1,2]):void 0), { });
|
|
10
|
-
configureMonacoLoader();
|
|
11
|
-
function getLanguageFromName(name) {
|
|
12
|
-
const lower = name.toLowerCase();
|
|
13
|
-
if (lower.endsWith(".py") || lower.endsWith(".pyw") || lower.endsWith(".pyi")) return "python";
|
|
14
|
-
if (lower.endsWith(".json") || lower.endsWith(".jsonc") || lower.endsWith(".json5")) return "json";
|
|
15
|
-
if (lower.endsWith(".ts") || lower.endsWith(".tsx") || lower.endsWith(".mts")) return "typescript";
|
|
16
|
-
if (lower.endsWith(".js") || lower.endsWith(".jsx") || lower.endsWith(".mjs")) return "javascript";
|
|
17
|
-
if (lower.endsWith(".md") || lower.endsWith(".markdown")) return "markdown";
|
|
18
|
-
if (lower.endsWith(".yaml") || lower.endsWith(".yml")) return "yaml";
|
|
19
|
-
if (lower.endsWith(".html") || lower.endsWith(".htm")) return "html";
|
|
20
|
-
if (lower.endsWith(".css") || lower.endsWith(".scss") || lower.endsWith(".sass")) return "css";
|
|
21
|
-
return "plaintext";
|
|
22
|
-
}
|
|
23
|
-
function useIsDarkMode() {
|
|
24
|
-
const [isDark, setIsDark] = React.useState(() => {
|
|
25
|
-
if (typeof document === "undefined") return false;
|
|
26
|
-
return document.documentElement.classList.contains("dark");
|
|
27
|
-
});
|
|
28
|
-
React.useEffect(() => {
|
|
29
|
-
const el = document.documentElement;
|
|
30
|
-
const observer = new MutationObserver(() => {
|
|
31
|
-
setIsDark(el.classList.contains("dark"));
|
|
32
|
-
});
|
|
33
|
-
observer.observe(el, { attributes: true, attributeFilter: ["class"] });
|
|
34
|
-
return () => observer.disconnect();
|
|
35
|
-
}, []);
|
|
36
|
-
return isDark;
|
|
37
|
-
}
|
|
38
|
-
function useDebouncedEffect(effect, deps, delayMs) {
|
|
39
|
-
React.useEffect(() => {
|
|
40
|
-
const id = window.setTimeout(effect, delayMs);
|
|
41
|
-
return () => window.clearTimeout(id);
|
|
42
|
-
}, [...deps, delayMs]);
|
|
43
|
-
}
|
|
44
|
-
function CodeEditorPlugin({ context, tabId, setDirty, setTitle }) {
|
|
45
|
-
const projectId = context.customData?.projectId ?? void 0;
|
|
46
|
-
const fileMeta = context.customData?.fileMeta ?? void 0;
|
|
47
|
-
const fileId = context.resourceId;
|
|
48
|
-
const isCliFile = isCliFileId(fileId);
|
|
49
|
-
const filePath = context.resourcePath ?? void 0;
|
|
50
|
-
const fileName = context.resourceName || context.resourcePath || "Untitled";
|
|
51
|
-
const language = React.useMemo(() => getLanguageFromName(fileName), [fileName]);
|
|
52
|
-
const isDark = useIsDarkMode();
|
|
53
|
-
const ensureLoaded = useFileContentStore((s) => s.ensureLoaded);
|
|
54
|
-
const reloadFile = useFileContentStore((s) => s.reload);
|
|
55
|
-
const saveHttp = useFileContentStore((s) => s.save);
|
|
56
|
-
const setContent = useFileContentStore((s) => s.setContent);
|
|
57
|
-
const applyServerSnapshot = useFileContentStore((s) => s.applyServerSnapshot);
|
|
58
|
-
const key = projectId && fileId ? useFileContentStore.getState().getKey(projectId, fileId) : null;
|
|
59
|
-
const entry = useFileContentStore((s) => key ? s.entries[key] : void 0);
|
|
60
|
-
const loading = useFileContentLoading(projectId, fileId ?? void 0);
|
|
61
|
-
const updateFileMeta = useFileTreeStore((s) => s.updateFileMeta);
|
|
62
|
-
const { diffEvent, clearDiff } = useFileDiffOverlay({
|
|
63
|
-
fileId,
|
|
64
|
-
filePath,
|
|
65
|
-
projectId
|
|
66
|
-
});
|
|
67
|
-
const editorRef = React.useRef(null);
|
|
68
|
-
const socketRef = React.useRef(null);
|
|
69
|
-
const joinedRef = React.useRef(false);
|
|
70
|
-
const [socketConnected, setSocketConnected] = React.useState(false);
|
|
71
|
-
React.useEffect(() => {
|
|
72
|
-
setTitle(fileName);
|
|
73
|
-
}, [fileName, setTitle]);
|
|
74
|
-
React.useEffect(() => {
|
|
75
|
-
if (!projectId || !fileId) return;
|
|
76
|
-
ensureLoaded({
|
|
77
|
-
projectId,
|
|
78
|
-
fileId,
|
|
79
|
-
updatedAt: fileMeta?.updatedAt,
|
|
80
|
-
mimeType: context.mimeType ?? fileMeta?.mimeType,
|
|
81
|
-
sizeBytes: fileMeta?.sizeBytes
|
|
82
|
-
}).catch((e) => {
|
|
83
|
-
console.error("[CodeEditorPlugin] Failed to load file:", e);
|
|
84
|
-
});
|
|
85
|
-
}, [projectId, fileId, ensureLoaded, fileMeta?.updatedAt, fileMeta?.mimeType, fileMeta?.sizeBytes, context.mimeType]);
|
|
86
|
-
React.useEffect(() => {
|
|
87
|
-
if (!projectId || !fileId || isCliFile) return;
|
|
88
|
-
const { socket, release } = acquireFileSocket();
|
|
89
|
-
socketRef.current = { socket, release };
|
|
90
|
-
const joinIfReady = async () => {
|
|
91
|
-
if (joinedRef.current) return;
|
|
92
|
-
if (!socket.connected) return;
|
|
93
|
-
try {
|
|
94
|
-
joinedRef.current = true;
|
|
95
|
-
await socket.emitWithAck("file:join", { projectId, fileId, clientVersion: "1.0.0" });
|
|
96
|
-
setSocketConnected(true);
|
|
97
|
-
} catch (e) {
|
|
98
|
-
console.warn("[CodeEditorPlugin] file:join failed:", e);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const onConnect = () => {
|
|
102
|
-
setSocketConnected(true);
|
|
103
|
-
void joinIfReady();
|
|
104
|
-
};
|
|
105
|
-
const onDisconnect = () => {
|
|
106
|
-
setSocketConnected(false);
|
|
107
|
-
joinedRef.current = false;
|
|
108
|
-
};
|
|
109
|
-
const onRemoteUpdate = (payload) => {
|
|
110
|
-
if (payload?.fileId !== fileId) return;
|
|
111
|
-
const curKey = useFileContentStore.getState().getKey(projectId, fileId);
|
|
112
|
-
const curEntry = useFileContentStore.getState().entries[curKey];
|
|
113
|
-
if (curEntry?.isDirty) return;
|
|
114
|
-
applyServerSnapshot({
|
|
115
|
-
projectId,
|
|
116
|
-
fileId,
|
|
117
|
-
content: String(payload?.content ?? ""),
|
|
118
|
-
updatedAt: String(payload?.updatedAt ?? ""),
|
|
119
|
-
sizeBytes: typeof payload?.size === "number" ? payload.size : void 0,
|
|
120
|
-
mimeType: curEntry?.mimeType
|
|
121
|
-
});
|
|
122
|
-
updateFileMeta(fileId, {
|
|
123
|
-
updatedAt: String(payload?.updatedAt ?? ""),
|
|
124
|
-
size: typeof payload?.size === "number" ? payload.size : void 0
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
socket.on("connect", onConnect);
|
|
128
|
-
socket.on("disconnect", onDisconnect);
|
|
129
|
-
socket.on("file:content-updated", onRemoteUpdate);
|
|
130
|
-
if (socket.connected) {
|
|
131
|
-
void joinIfReady();
|
|
132
|
-
}
|
|
133
|
-
return () => {
|
|
134
|
-
try {
|
|
135
|
-
socket.off("connect", onConnect);
|
|
136
|
-
socket.off("disconnect", onDisconnect);
|
|
137
|
-
socket.off("file:content-updated", onRemoteUpdate);
|
|
138
|
-
if (joinedRef.current) {
|
|
139
|
-
void socket.emit("file:leave", { projectId, fileId });
|
|
140
|
-
}
|
|
141
|
-
} finally {
|
|
142
|
-
joinedRef.current = false;
|
|
143
|
-
setSocketConnected(false);
|
|
144
|
-
socketRef.current = null;
|
|
145
|
-
release();
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}, [projectId, fileId, isCliFile]);
|
|
149
|
-
React.useEffect(() => {
|
|
150
|
-
setDirty(!!entry?.isDirty);
|
|
151
|
-
}, [entry?.isDirty, setDirty]);
|
|
152
|
-
const saveRealtime = React.useCallback(async () => {
|
|
153
|
-
if (!projectId || !fileId || !entry) return;
|
|
154
|
-
try {
|
|
155
|
-
const k = useFileContentStore.getState().getKey(projectId, fileId);
|
|
156
|
-
useFileContentStore.setState((s) => {
|
|
157
|
-
const cur = s.entries[k];
|
|
158
|
-
if (!cur) return s;
|
|
159
|
-
return {
|
|
160
|
-
entries: {
|
|
161
|
-
...s.entries,
|
|
162
|
-
[k]: { ...cur, saveState: "saving", saveError: void 0 }
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
});
|
|
166
|
-
} catch {
|
|
167
|
-
}
|
|
168
|
-
const socket = socketRef.current?.socket;
|
|
169
|
-
if (!isCliFile && socket && socket.connected && joinedRef.current) {
|
|
170
|
-
try {
|
|
171
|
-
const resp = await socket.emitWithAck(
|
|
172
|
-
"file:update-content",
|
|
173
|
-
{ projectId, fileId, content: entry.content }
|
|
174
|
-
);
|
|
175
|
-
if ("error" in resp) {
|
|
176
|
-
throw new Error(resp.error.message);
|
|
177
|
-
}
|
|
178
|
-
applyServerSnapshot({
|
|
179
|
-
projectId,
|
|
180
|
-
fileId,
|
|
181
|
-
content: entry.content,
|
|
182
|
-
updatedAt: resp.data.updatedAt,
|
|
183
|
-
sizeBytes: typeof resp.data.size === "number" ? resp.data.size : entry.sizeBytes,
|
|
184
|
-
mimeType: entry.mimeType
|
|
185
|
-
});
|
|
186
|
-
if (!isCliFile) {
|
|
187
|
-
updateFileMeta(fileId, {
|
|
188
|
-
updatedAt: resp.data.updatedAt,
|
|
189
|
-
size: typeof resp.data.size === "number" ? resp.data.size : void 0,
|
|
190
|
-
mimeType: entry.mimeType
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
return;
|
|
194
|
-
} catch (e) {
|
|
195
|
-
console.warn("[CodeEditorPlugin] realtime save failed, fallback to HTTP:", e);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
const saved = await saveHttp({ projectId, fileId });
|
|
199
|
-
if (!isCliFile && saved.updatedAt) {
|
|
200
|
-
updateFileMeta(fileId, { updatedAt: saved.updatedAt, size: saved.sizeBytes, mimeType: saved.mimeType });
|
|
201
|
-
}
|
|
202
|
-
}, [applyServerSnapshot, entry, fileId, isCliFile, projectId, saveHttp, updateFileMeta]);
|
|
203
|
-
useDebouncedEffect(
|
|
204
|
-
() => {
|
|
205
|
-
if (!projectId || !fileId || !entry?.isDirty) return;
|
|
206
|
-
if (entry.saveState === "saving") return;
|
|
207
|
-
void saveRealtime();
|
|
208
|
-
},
|
|
209
|
-
[projectId, fileId, entry?.content, entry?.isDirty],
|
|
210
|
-
650
|
|
211
|
-
);
|
|
212
|
-
React.useEffect(() => {
|
|
213
|
-
if (!projectId || !fileId) return;
|
|
214
|
-
const handler = (e) => {
|
|
215
|
-
const isSave = (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "s";
|
|
216
|
-
if (!isSave) return;
|
|
217
|
-
e.preventDefault();
|
|
218
|
-
void saveRealtime();
|
|
219
|
-
};
|
|
220
|
-
window.addEventListener("keydown", handler);
|
|
221
|
-
return () => window.removeEventListener("keydown", handler);
|
|
222
|
-
}, [projectId, fileId, saveRealtime]);
|
|
223
|
-
const statusLabel = React.useMemo(() => {
|
|
224
|
-
if (!entry) return "";
|
|
225
|
-
if (entry.saveState === "saving") return "Saving…";
|
|
226
|
-
if (entry.saveState === "error") return entry.saveError || "Save failed";
|
|
227
|
-
if (entry.isDirty) return "Unsaved";
|
|
228
|
-
return "Saved";
|
|
229
|
-
}, [entry]);
|
|
230
|
-
const canSave = !!projectId && !!fileId && !!entry && !loading;
|
|
231
|
-
const canFormatJson = language === "json";
|
|
232
|
-
const runFormat = async () => {
|
|
233
|
-
const editor = editorRef.current;
|
|
234
|
-
if (!editor) return;
|
|
235
|
-
try {
|
|
236
|
-
await editor.getAction("editor.action.formatDocument").run();
|
|
237
|
-
} catch (e) {
|
|
238
|
-
console.warn("[CodeEditorPlugin] Format failed:", e);
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
const handleReload = React.useCallback(async () => {
|
|
242
|
-
if (!projectId || !fileId) return;
|
|
243
|
-
if (entry?.isDirty) {
|
|
244
|
-
const confirmed = window.confirm("Discard unsaved changes and reload from server?");
|
|
245
|
-
if (!confirmed) return;
|
|
246
|
-
}
|
|
247
|
-
const node = useFileTreeStore.getState().findNode(fileId);
|
|
248
|
-
const updatedAt = node?.updatedAt ?? fileMeta?.updatedAt;
|
|
249
|
-
const sizeBytes = node?.size ?? fileMeta?.sizeBytes;
|
|
250
|
-
const mimeType = node?.mimeType ?? context.mimeType ?? fileMeta?.mimeType;
|
|
251
|
-
try {
|
|
252
|
-
await reloadFile({
|
|
253
|
-
projectId,
|
|
254
|
-
fileId,
|
|
255
|
-
updatedAt,
|
|
256
|
-
sizeBytes,
|
|
257
|
-
mimeType,
|
|
258
|
-
ignoreDirty: true
|
|
259
|
-
});
|
|
260
|
-
} catch (e) {
|
|
261
|
-
console.warn("[CodeEditorPlugin] Reload failed:", e);
|
|
262
|
-
}
|
|
263
|
-
}, [
|
|
264
|
-
projectId,
|
|
265
|
-
fileId,
|
|
266
|
-
entry?.isDirty,
|
|
267
|
-
fileMeta?.updatedAt,
|
|
268
|
-
fileMeta?.sizeBytes,
|
|
269
|
-
fileMeta?.mimeType,
|
|
270
|
-
context.mimeType,
|
|
271
|
-
reloadFile
|
|
272
|
-
]);
|
|
273
|
-
React.useEffect(() => {
|
|
274
|
-
if (!diffEvent?.diff) return;
|
|
275
|
-
if (!projectId || !fileId) return;
|
|
276
|
-
if (diffEvent.changeType === "delete") return;
|
|
277
|
-
if (entry?.isDirty) return;
|
|
278
|
-
void reloadFile({
|
|
279
|
-
projectId,
|
|
280
|
-
fileId,
|
|
281
|
-
mimeType: context.mimeType ?? fileMeta?.mimeType,
|
|
282
|
-
sizeBytes: fileMeta?.sizeBytes,
|
|
283
|
-
updatedAt: fileMeta?.updatedAt,
|
|
284
|
-
ignoreDirty: true
|
|
285
|
-
});
|
|
286
|
-
}, [
|
|
287
|
-
diffEvent,
|
|
288
|
-
entry?.isDirty,
|
|
289
|
-
projectId,
|
|
290
|
-
fileId,
|
|
291
|
-
context.mimeType,
|
|
292
|
-
fileMeta?.mimeType,
|
|
293
|
-
fileMeta?.sizeBytes,
|
|
294
|
-
fileMeta?.updatedAt,
|
|
295
|
-
reloadFile
|
|
296
|
-
]);
|
|
297
|
-
if (!projectId || !fileId) {
|
|
298
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-full flex items-center justify-center text-sm text-muted-foreground", children: "No file selected." });
|
|
299
|
-
}
|
|
300
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col h-full bg-background", children: [
|
|
301
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between px-3 py-2 border-b border-border/60 bg-white/60 backdrop-blur dark:bg-black/30", children: [
|
|
302
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0 flex items-center gap-2", children: [
|
|
303
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "truncate text-sm font-medium", children: fileName }),
|
|
304
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[11px] px-2 py-0.5 rounded bg-black/[0.06] dark:bg-white/[0.08] text-muted-foreground uppercase", children: language })
|
|
305
|
-
] }),
|
|
306
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
307
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
308
|
-
"span",
|
|
309
|
-
{
|
|
310
|
-
className: cn(
|
|
311
|
-
"text-xs",
|
|
312
|
-
entry?.saveState === "error" ? "text-red-600" : "text-muted-foreground"
|
|
313
|
-
),
|
|
314
|
-
title: entry?.saveError,
|
|
315
|
-
children: [
|
|
316
|
-
statusLabel,
|
|
317
|
-
!isCliFile && !socketConnected ? " (offline)" : ""
|
|
318
|
-
]
|
|
319
|
-
}
|
|
320
|
-
),
|
|
321
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
322
|
-
"button",
|
|
323
|
-
{
|
|
324
|
-
type: "button",
|
|
325
|
-
className: cn(
|
|
326
|
-
"inline-flex items-center gap-1.5 text-xs px-2.5 py-1.5 rounded-md",
|
|
327
|
-
"border border-black/10 bg-white hover:bg-black/[0.03]",
|
|
328
|
-
"dark:border-white/10 dark:bg-white/[0.04] dark:hover:bg-white/[0.07]",
|
|
329
|
-
!canSave && "opacity-60 pointer-events-none"
|
|
330
|
-
),
|
|
331
|
-
onClick: () => void saveRealtime(),
|
|
332
|
-
title: "Save (Ctrl/Cmd+S)",
|
|
333
|
-
children: [
|
|
334
|
-
entry?.saveState === "saving" ? /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-3.5 w-3.5 animate-spin" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Save, { className: "h-3.5 w-3.5" }),
|
|
335
|
-
"Save"
|
|
336
|
-
]
|
|
337
|
-
}
|
|
338
|
-
),
|
|
339
|
-
canFormatJson ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
340
|
-
"button",
|
|
341
|
-
{
|
|
342
|
-
type: "button",
|
|
343
|
-
className: cn(
|
|
344
|
-
"inline-flex items-center gap-1.5 text-xs px-2.5 py-1.5 rounded-md",
|
|
345
|
-
"border border-black/10 bg-white hover:bg-black/[0.03]",
|
|
346
|
-
"dark:border-white/10 dark:bg-white/[0.04] dark:hover:bg-white/[0.07]"
|
|
347
|
-
),
|
|
348
|
-
onClick: runFormat,
|
|
349
|
-
title: "Format JSON",
|
|
350
|
-
children: [
|
|
351
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(Braces, { className: "h-3.5 w-3.5" }),
|
|
352
|
-
"Format"
|
|
353
|
-
]
|
|
354
|
-
}
|
|
355
|
-
) : null,
|
|
356
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
357
|
-
"button",
|
|
358
|
-
{
|
|
359
|
-
type: "button",
|
|
360
|
-
className: cn(
|
|
361
|
-
"inline-flex items-center gap-1.5 text-xs px-2.5 py-1.5 rounded-md",
|
|
362
|
-
"border border-black/10 bg-white hover:bg-black/[0.03]",
|
|
363
|
-
"dark:border-white/10 dark:bg-white/[0.04] dark:hover:bg-white/[0.07]"
|
|
364
|
-
),
|
|
365
|
-
onClick: () => void handleReload(),
|
|
366
|
-
title: "Reload from cache/server",
|
|
367
|
-
children: [
|
|
368
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx(RefreshCw, { className: "h-3.5 w-3.5" }),
|
|
369
|
-
"Reload"
|
|
370
|
-
]
|
|
371
|
-
}
|
|
372
|
-
)
|
|
373
|
-
] })
|
|
374
|
-
] }),
|
|
375
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative flex-1 min-h-0", children: [
|
|
376
|
-
diffEvent?.diff ? /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
377
|
-
FileDiffPanel,
|
|
378
|
-
{
|
|
379
|
-
diff: diffEvent.diff,
|
|
380
|
-
changeType: diffEvent.changeType,
|
|
381
|
-
title: "AI change",
|
|
382
|
-
subtitle: fileName,
|
|
383
|
-
onClose: clearDiff,
|
|
384
|
-
className: "absolute right-4 top-4 z-10 w-[min(420px,46vw)]"
|
|
385
|
-
}
|
|
386
|
-
) : null,
|
|
387
|
-
loading && !entry ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-full flex items-center justify-center text-muted-foreground", children: /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "h-6 w-6 animate-spin" }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
388
|
-
MonacoEditor,
|
|
389
|
-
{
|
|
390
|
-
height: "100%",
|
|
391
|
-
language,
|
|
392
|
-
theme: isDark ? "vs-dark" : "vs",
|
|
393
|
-
value: entry?.content ?? "",
|
|
394
|
-
beforeMount: (monaco) => {
|
|
395
|
-
try {
|
|
396
|
-
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
397
|
-
validate: true,
|
|
398
|
-
allowComments: true,
|
|
399
|
-
trailingCommas: "ignore"
|
|
400
|
-
});
|
|
401
|
-
} catch {
|
|
402
|
-
}
|
|
403
|
-
},
|
|
404
|
-
onMount: (editor) => {
|
|
405
|
-
editorRef.current = editor;
|
|
406
|
-
},
|
|
407
|
-
onChange: (val) => {
|
|
408
|
-
setContent({ projectId, fileId, content: val ?? "" });
|
|
409
|
-
},
|
|
410
|
-
options: {
|
|
411
|
-
automaticLayout: true,
|
|
412
|
-
minimap: { enabled: false },
|
|
413
|
-
fontFamily: '"Fira Code", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
|
414
|
-
fontSize: 13,
|
|
415
|
-
wordWrap: "off",
|
|
416
|
-
scrollBeyondLastLine: false,
|
|
417
|
-
renderWhitespace: "selection",
|
|
418
|
-
tabSize: 2,
|
|
419
|
-
insertSpaces: true
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
)
|
|
423
|
-
] })
|
|
424
|
-
] });
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
export { CodeEditorPlugin as default };
|