Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .claude/docs/V1.2.1_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ Then pushed `v1.2.1` to `origin` at the maintainer's request. **No merge and no

**#168 (IDE), thirteenth PR of epic #163: split editor** [confirmed: unit tests (`tabs.test.ts`, split session), the gate, Playwright on Linux at 1280x800: `Ctrl+\` splits, typing in one group updates both and marks one dirty state, `Ctrl+1` focuses the first group, a tab dragged to the other strip moves, the sash resizes, undo clears the dirty mark in both, the split restores after a restart with the deep-analysis scene open (editor column 396 px, groups 156/240), closing the second group's tabs collapses it and `Ctrl+2` reopens it; no horizontal overflow]. `editor/editorGroup.ts` was restructured into documents (one Monaco model, save state, disk watch, lens state), tabs and up to two groups, each with its own Monaco editor, tab strip and placeholder; the breadcrumbs move to the active group. `TabSession` gains optional `second`, `split` and `focus` (same `SESSION_VERSION`, old sessions read as one group). Commands `editor.splitRight` (`CmdOrCtrl+\`), `workbench.focusFirstEditorGroup` (`CmdOrCtrl+1`), `workbench.focusSecondEditorGroup` (`CmdOrCtrl+2`); tab menu item Split Right. Plugin: nothing to do, VS Code splits natively (parity rule covers Code-XR features only).

**#179 (IDE), fourteenth PR of epic #163: Markdown preview** [confirmed: unit tests (`markdown.test.ts`: blocks and their lines, links, images, slugs, `readImage`, `isOpenableExternalLink`), the gate, Playwright on Linux at 1280x800 in dark and light: headings with ids, nested and task lists, a table, a Python block coloured by Monaco, a folder PNG inlined as data:, a remote badge turned into a link, `<script>`, `<img onerror>`, `<style>` and a `javascript:` link all neutralised (no flag set, body still shown), live re-render while typing, editor scroll followed, a relative link opened `docs/api.md` and the preview followed it, close button]. `editor/markdownModel.ts` (pure: marked's top-level tokens rendered one block each with its start line, `resolveLink`/`resolveImage`), `editor/markdownPreview.ts` (own DOMPurify instance, per-call config, images rewritten in the inert document), `editor/markdownPath.ts` (kept out of the startup chunk), the pane and its sash in `editorGroup.ts`. Main: `Workspace.readImage` (raster only, 8 MB), IPC `codexr:workspace:read-image` and `codexr:workspace:open-external-link` (`isOpenableExternalLink`: http, https, mailto). Command `markdown.showPreviewToSide` (`CmdOrCtrl+K V`), tab menu item on Markdown files. Dependencies: `marked` 14.0.0 and `dompurify` 3.4.15 added to the IDE workspace (already in the lock through Monaco; notices added). Found: `<img src=x onerror=...>` makes Chromium report a `script-src-attr` CSP violation while DOMPurify's inert document parses it; nothing executes. Plugin: nothing to do, VS Code previews Markdown natively.

### IDE epic #11 — story #203: the analysis on open never asks, and the header says how many files it took [confirmed by unit tests, the smoke run and a Playwright check] (2026-11-26, branch `claude/project-thread-zeculq`)

**Why**: Adrián's Code-XR clone triggered #139's "more than 5,000 files" dialog although the analyser takes ~870 files: the bounded walk counted everything outside a few known folders, not what the analyser keeps. He wants no prompt at all.
Expand Down
2 changes: 2 additions & 0 deletions apps/ide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ The renderer only reports the slot's bounds (`analysis.setSceneBounds`, sanitise

**Split editor (#168).** **Split Editor Right** (`Ctrl/Cmd+\`, or Split Right in the tab menu) opens the file in a second editor group beside the first; `Ctrl/Cmd+1` and `Ctrl/Cmd+2` focus a group (the second is created on first use). Both groups share one Monaco model per file, so an edit in either shows in both and the file has a single dirty state; closing a file asks about unsaved changes only when its last tab goes. A tab dragged onto the other group's strip moves there with its view state. The sash between the groups drags (pointer or arrow keys) and resets on double-click; each group keeps at least 120 px, half the editor column's minimum, so the XR scene column keeps its width. The group that has the focus owns the breadcrumbs, the status bar and the commands. A group left without tabs closes. The second group, the split ratio and the focused group are part of the folder's tab session, so a restart restores them; a session saved before the split existed reads as one group (`editor/editorGroup.ts`, `editor/tabsModel.ts`). Not implemented: vertical splits and more than two groups.

**Markdown preview (#179).** **Open Preview to the Side** (`Ctrl/Cmd+K V`, or the tab menu of a Markdown file) opens a pane to the right of the editor groups that renders the active Markdown file with GitHub-flavoured Markdown (headings, lists, task lists, tables, code blocks coloured by Monaco's own tokenizer, images). It re-renders as you type, follows the editor's scroll, takes over whichever Markdown file becomes active, and uses the workbench's colours, so it follows the theme. Its sash drags and resets on double-click like the split one. The preview is the only place in the renderer that inserts parsed markup, so it is fenced: DOMPurify sanitises everything (no script, no `<style>` or `style` attribute, no forms or frames, document ids prefixed); the window's CSP is unchanged; images of the open folder are read by the main process (`workspace.readImage`, checked against the folder, PNG/JPEG/GIF/WebP/BMP only, up to 8 MB) and inlined as `data:` URLs, while a remote image is shown as a link that opens it in the browser, so the preview never goes online; a `#heading` link scrolls the preview, a relative link opens the file in the IDE, and only http, https and mailto links leave the IDE (`workspace.openExternalLink`, scheme checked by the main process). Raw HTML that tries an inline event handler still trips the CSP's `script-src-attr` report while DOMPurify parses it; nothing runs (`editor/markdownModel.ts`, `editor/markdownPreview.ts`). Not saved in the session: the preview closes with the window.

**Settings (#18, part 2).** The **Settings** view (the gear at the foot of the activity bar, **File > Preferences > Settings**, `Ctrl/Cmd+,`) lists every setting with its control, a filter, and two tabs: **User** (yours, in every folder: `settings.json` in the IDE's user-data folder) and **Folder** (the open folder's, in `.codexr/settings.json`, so it can be committed with the project; **Open Folder Settings (JSON)** opens it in the editor, and saving it there takes effect). A folder value wins over a user value, which wins over the default; a row marks what its scope sets itself and resets it. The schema (`shared/settings.ts`) is shared by both processes: the main process (`main/settings/settingsService.ts`) only stores values it accepts, keeps keys it does not know (a newer IDE's), reads files with comments and trailing commas as VS Code's are, and reports a file it cannot read instead of overwriting it. A change to the user's settings reaches every window. Today's settings cover the editor (font, line height, tab size and indentation detection, word wrap, line numbers, whitespace, minimap, sticky scroll, bracket colours, cursor, smooth scrolling) and the terminal's font size; the analysis and visualisation settings come with the analysis views.

**Saving (#170).** Four settings shape a save: **Format On Save** (the language's own formatter: Monaco's for TypeScript, JavaScript, JSON, CSS and HTML today, the language servers' once #21 lands; nothing is downloaded), **Trim Trailing Whitespace**, **Insert Final Newline** and **Auto Save** (off, after a delay, `files.autoSaveDelay` ms after the last edit, or when the editor loses the focus). The save-time changes are one undoable edit, so the editor shows exactly what was written. A formatter that fails or takes longer than 1.5 s never blocks the save: the file is saved unformatted and the status bar says why. An auto save after a delay leaves the lines holding a cursor alone (no whitespace is trimmed under the person typing) and skips formatting, as VS Code does; no auto save ever asks a question, so a file that changed on disk waits for an explicit save. A project's `.editorconfig` files (the folder root down to the file's own folder, stopping at `root = true`) win over the settings per file: `indent_style`, `indent_size`, `tab_width` set the editor's indentation (and the status bar) when the file opens, and `end_of_line`, `charset` (`utf-8` / `utf-8-bom`), `trim_trailing_whitespace` and `insert_final_newline` apply on save; editing an `.editorconfig` re-applies it to the open files. **Format Document** is `Shift+Alt+F` (`editor/editorConfig.ts`, `editor/saveTransforms.ts`, both pure and unit-tested).
Expand Down
20 changes: 20 additions & 0 deletions apps/ide/THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,23 @@ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
Usage in this package:

- Bundled into the renderer by Vite, through the extension's shared core: the QR code a standalone headset scans to open a shared scene (#19, `apps/vscode-extension/src/core/xr/headsetQr.ts`). Declared as a dependency of the extension workspace, like the rest of the core's. "QR Code" is a registered trademark of DENSO WAVE INCORPORATED.

## marked (Markdown parser)

- Project: `marked` on npm, 14.0.0, by Christopher Jeffrey and the marked contributors
- Source: https://github.com/markedjs/marked
- License: MIT

Usage in this package:

- Bundled into the renderer by Vite: parses the Markdown preview (#179, `src/renderer/editor/markdownModel.ts`). The same version Monaco already depends on.

## DOMPurify (HTML sanitiser)

- Project: `dompurify` on npm, 3.4.15, by Cure53 and contributors
- Source: https://github.com/cure53/DOMPurify
- License: Apache-2.0 or MPL-2.0 (dual licensed; used here under Apache-2.0)

Usage in this package:

- Bundled into the renderer by Vite: sanitises the Markdown preview's HTML before it reaches the page (#179, `src/renderer/editor/markdownPreview.ts`). The same version Monaco already depends on.
2 changes: 2 additions & 0 deletions apps/ide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
"@types/node": "^22.20.7",
"@xterm/addon-fit": "0.11.0",
"@xterm/xterm": "6.0.0",
"dompurify": "3.4.15",
"electron": "^45.5.0",
"electron-builder": "26.18.1",
"marked": "14.0.0",
"material-icon-theme": "^5.40.0",
"monaco-editor": "0.57.0",
"vite": "^8.3.8",
Expand Down
10 changes: 9 additions & 1 deletion apps/ide/src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { registerGitHandlers } from './git/gitIpc.ts';
import type { LspHost } from './lsp/lspHost.ts';
import { registerLspHandlers } from './lsp/lspIpc.ts';
import { reportUnsaved } from './unsavedGuard.ts';
import { isTrustedIpcCall } from './security.ts';
import { isOpenableExternalLink, isTrustedIpcCall } from './security.ts';
import { log } from './log.ts';
import { setSceneBounds, windowOfScene } from './analysis/sceneView.ts';
import { SCENE_OPEN_IN_EDITOR_CHANNEL, toSceneEditorTarget } from '../shared/sceneBridge.ts';
Expand Down Expand Up @@ -137,6 +137,14 @@ export function registerIpcHandlers(origins: ReadonlySet<string>, isDevelopment:
handle(IPC_CHANNELS.workspaceCopyPath, (event, path, kind) => {
clipboard.writeText(workspaceOf(event.sender).displayPath(path, kind));
});
// #179: the Markdown preview's images and links; the path and the URL are checked here.
handle(IPC_CHANNELS.workspaceReadImage, (event, path) => workspaceOf(event.sender).readImage(path));
handle(IPC_CHANNELS.workspaceOpenExternalLink, async (_event, url) => {
if (!isOpenableExternalLink(url)) {
throw new Error('Only http, https and mailto links open outside the IDE.');
}
await shell.openExternal(url);
});
handle(IPC_CHANNELS.workspaceTrash, (event, path) => workspaceOf(event.sender).trash(path, (absolute) => shell.trashItem(absolute)));
handle(IPC_CHANNELS.workspaceRecentFolders, () => recentFolderList());
handle(IPC_CHANNELS.workspaceOpenRecent, (event, folder) => openRecentFolder(event.sender, folder));
Expand Down
12 changes: 12 additions & 0 deletions apps/ide/src/main/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,15 @@ export function isTrustedIpcCall(
const origin = originOf(senderFrameUrl);
return origin !== null && origins.has(origin);
}

/** #179: the only links the renderer may hand to the operating system: http, https and mailto. */
export function isOpenableExternalLink(url: unknown): url is string {
if (typeof url !== 'string' || url.length > 8192) {
return false;
}
try {
return ['http:', 'https:', 'mailto:'].includes(new URL(url).protocol);
} catch {
return false;
}
}
26 changes: 26 additions & 0 deletions apps/ide/src/main/workspace/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ import { replaceInText, type CompiledQuery } from '../../shared/searchText.ts';
export const MAX_EDITOR_FILE_BYTES = 5 * 1024 * 1024;
/** A NUL byte in the first chunk marks a file as binary, as git does. */
const BINARY_SNIFF_BYTES = 8000;
/** #179: the largest image the Markdown preview inlines. */
export const MAX_PREVIEW_IMAGE_BYTES = 8 * 1024 * 1024;
/**
* Raster images only: an SVG is a document that can carry script and
* external references, and the preview has no reason to take that on.
*/
const IMAGE_TYPES: Record<string, string> = { png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', bmp: 'image/bmp' };

export function imageMimeType(path: string): string | null {
const dot = path.lastIndexOf('.');
return dot > path.lastIndexOf('/') ? IMAGE_TYPES[path.slice(dot + 1).toLowerCase()] ?? null : null;
}

const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });

Expand Down Expand Up @@ -135,6 +147,20 @@ export class Workspace {
return { kind: 'text', path: entryPath, text: bytes.toString('utf8'), mtimeMs: stat.mtimeMs };
}

/** #179: an image of the folder as a data: URL (the renderer's CSP allows data: images only). */
async readImage(relativePath: unknown): Promise<string | null> {
const mime = imageMimeType(parseWorkspacePath(relativePath).join('/'));
if (!mime) {
return null;
}
const absolute = await this.realPathInside(relativePath);
const stat = await fs.stat(absolute);
if (!stat.isFile() || stat.size > MAX_PREVIEW_IMAGE_BYTES) {
return null;
}
return `data:${mime};base64,${(await fs.readFile(absolute)).toString('base64')}`;
}

/**
* Overwrites an existing file with `text` (UTF-8). Refuses a folder, a text
* over the editor limit, and, when `expectedMtimeMs` is given, a file whose
Expand Down
2 changes: 2 additions & 0 deletions apps/ide/src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ const api: CodeXRApi = Object.freeze({
ipcRenderer.invoke(IPC_CHANNELS.workspaceCreateEntry, parent, name, kind),
rename: (path: string, newName: string) => ipcRenderer.invoke(IPC_CHANNELS.workspaceRename, path, newName),
copyPath: (path: string, kind: 'absolute' | 'relative') => ipcRenderer.invoke(IPC_CHANNELS.workspaceCopyPath, path, kind),
readImage: (path: string) => ipcRenderer.invoke(IPC_CHANNELS.workspaceReadImage, path),
openExternalLink: (url: string) => ipcRenderer.invoke(IPC_CHANNELS.workspaceOpenExternalLink, url),
trash: (path: string) => ipcRenderer.invoke(IPC_CHANNELS.workspaceTrash, path),
recentFolders: () => ipcRenderer.invoke(IPC_CHANNELS.workspaceRecentFolders),
openRecent: (folder: string) => ipcRenderer.invoke(IPC_CHANNELS.workspaceOpenRecent, folder),
Expand Down
4 changes: 4 additions & 0 deletions apps/ide/src/renderer/commands/workbenchCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export interface WorkbenchCommandTargets {
splitEditor(): void;
/** #168: focuses group 0 or 1; returns false when that group does not exist. */
focusEditorGroup(index: number): boolean;
/** #179: the Markdown preview beside the editor, on the active file. */
openMarkdownPreview(): void;
canPreviewMarkdown(): boolean;
}

export function workbenchCommands(targets: WorkbenchCommandTargets): CommandDefinition[] {
Expand Down Expand Up @@ -96,6 +99,7 @@ export function workbenchCommands(targets: WorkbenchCommandTargets): CommandDefi
{ id: 'editor.splitRight', category: 'View', title: 'Split Editor Right', keybinding: 'CmdOrCtrl+\\', enabled: targets.hasActiveEditor, run: targets.splitEditor },
{ id: 'workbench.focusFirstEditorGroup', category: 'View', title: 'Focus First Editor Group', keybinding: 'CmdOrCtrl+1', recordRecent: false, run: () => { targets.focusEditorGroup(0); } },
{ id: 'workbench.focusSecondEditorGroup', category: 'View', title: 'Focus Second Editor Group', keybinding: 'CmdOrCtrl+2', recordRecent: false, run: () => { if (!targets.focusEditorGroup(1)) { targets.splitEditor(); } } },
{ id: 'markdown.showPreviewToSide', category: 'Markdown', title: 'Open Preview to the Side', keybinding: 'CmdOrCtrl+K V', enabled: targets.canPreviewMarkdown, run: targets.openMarkdownPreview },
{ id: 'editor.keep', category: 'View', title: 'Keep Editor', keybinding: 'CmdOrCtrl+K Enter', enabled: targets.hasActiveEditor, run: targets.keepEditor },
{ id: 'file.copyPath', category: 'File', title: 'Copy Path of Active File', enabled: targets.hasActiveEditor, run: () => targets.copyActivePath('absolute') },
{ id: 'file.copyRelativePath', category: 'File', title: 'Copy Relative Path of Active File', enabled: targets.hasActiveEditor, run: () => targets.copyActivePath('relative') },
Expand Down
Loading
Loading