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
41 changes: 34 additions & 7 deletions .claude/docs/V1.2.1_STATUS.md

Large diffs are not rendered by default.

27 changes: 18 additions & 9 deletions apps/ide/README.md

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions apps/ide/THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,26 @@ Usage in this package:
- Its worker (`pdfjs-dist/build/pdf.worker.mjs`) is bundled the same way and served from the app's origin, so the CSP's `worker-src 'self'` covers it.
- The text-layer rules in `src/renderer/viewers/viewers.css` are a trimmed copy of the `.textLayer` block of its `web/pdf_viewer.css`.
- The optional `@napi-rs/canvas` dependency is only used by PDF.js under Node and is not bundled.

## xterm.js search and web-links addons (terminal find and links)

- Project: `@xterm/addon-search` 0.16.0 and `@xterm/addon-web-links` 0.12.0 on npm, by the xterm.js authors (released with `@xterm/xterm` 6.0.0)
- Source: https://github.com/xtermjs/xterm.js
- License: MIT

Usage in this package:

- Bundled into the renderer by Vite, in the terminal's chunk (`src/renderer/terminal/xtermView.ts`), which loads with the first terminal (#286).
- The search addon finds text in a terminal's scrollback and counts the matches for the find widget; the web-links addon detects http(s) URLs, which open through `workspace.openExternalLink` (the main process checks the scheme).

Licence text:

```
Copyright (c) 2017, The xterm.js authors (https://github.com/xtermjs/xterm.js)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```
2 changes: 2 additions & 0 deletions apps/ide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"@types/vscode": "1.146.0",
"@types/yauzl": "3.4.0",
"@xterm/addon-fit": "0.11.0",
"@xterm/addon-search": "0.16.0",
"@xterm/addon-web-links": "0.12.0",
"@xterm/xterm": "6.0.0",
"dompurify": "3.4.15",
"electron": "^45.5.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/ide/scripts/smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ child.on('exit', (code) => {
}
const result = JSON.parse(line.slice(PREFIX.length));
if (result.ok && code === 0) {
console.log(`[smoke] OK on ${result.platform}: window opened, renderer sandboxed, CSP and navigation guards active, IPC answered, explorer listed the folder and refused to leave it, Monaco opened a file, F1 opened the command palette, quick open found a file, the Search view found a symbol, the status bar showed the editor position, the layout resized, toggled and saved, zen mode answered its chord, preview tabs replaced each other and the tab menu closed them, the Settings view changed the editor font, the Output panel showed the logs, the Problems panel opened, file icons loaded from the app, no CSP violation, the terminal (${result.terminal?.profile}) ran echo and drew its output.`);
console.log(`[smoke] OK on ${result.platform}: window opened, renderer sandboxed, CSP and navigation guards active, IPC answered, explorer listed the folder and refused to leave it, Monaco opened a file, F1 opened the command palette, quick open found a file, the Search view found a symbol, the status bar showed the editor position, the layout resized, toggled and saved, zen mode answered its chord, preview tabs replaced each other and the tab menu closed them, the Settings view changed the editor font, the Output panel showed the logs, the Problems panel opened, file icons loaded from the app, no CSP violation, the terminal (${result.terminal?.profile}) ran echo and drew its output, found it with Ctrl/Cmd+F and opened a file link at its line.`);
process.exit(0);
}
const reasons = [...result.failures];
Expand Down
88 changes: 85 additions & 3 deletions apps/ide/src/main/git/gitIpc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { BrowserWindow, dialog, shell, type IpcMainInvokeEvent, type MessageBoxOptions, type WebContents } from 'electron';
import fs from 'node:fs';
import path from 'node:path';
import { emptyGitStatus, GIT_IPC_CHANNELS, GIT_IPC_EVENTS, type GitCommitResult, type GitStatus } from '../../shared/git.ts';
import { emptyGitStatus, GIT_IPC_CHANNELS, GIT_IPC_EVENTS, isGitRemoteOperation, type GitCommitResult, type GitDeleteBranchResult, type GitRemoteResult, type GitStatus } from '../../shared/git.ts';
import type { GitBlameLine } from '../../shared/gitGutter.ts';
import { log } from '../log.ts';
import { channelLog, log } from '../log.ts';
import { workspaceOrNull } from '../workspace/workspaceWindows.ts';
import { GitService } from './gitService.ts';
import { GitService, type RemoteOptions } from './gitService.ts';
import { GitCancelledError } from './gitRunner.ts';
import { addTrustChangeListener, isWorkspaceTrusted } from '../trust/workspaceTrust.ts';

type Handle = (channel: string, handler: (event: IpcMainInvokeEvent, ...args: unknown[]) => unknown) => void;
Expand All @@ -28,6 +29,10 @@ interface WindowGit {
}

const windows = new Map<number, WindowGit>();
/** #284: the remote operation each window is running, to cancel it; one at a time per window. */
const remoteRuns = new Map<number, AbortController>();
/** #284: the Output panel's Git channel. */
const gitLog = channelLog('git');
/** Windows whose `destroyed` listener is installed (once per window). */
const tracked = new Set<number>();

Expand Down Expand Up @@ -66,6 +71,8 @@ export function gitServiceOf(contents: WebContents): GitService | null {
}

function dispose(id: number): void {
// #284: a folder change, a trust change or a closed window stops its push, pull or fetch.
remoteRuns.get(id)?.abort();
const entry = windows.get(id);
if (!entry) {
return;
Expand Down Expand Up @@ -251,6 +258,81 @@ export function registerGitHandlers(handle: Handle): void {
await requireService(event.sender).createBranch(name);
return statusOf(event.sender);
});
// #284: push, pull, fetch and sync. Trust-gated like every other call; one per window, cancellable.
handle(GIT_IPC_CHANNELS.gitRemote, async (event, operation): Promise<GitRemoteResult> => {
if (!isGitRemoteOperation(operation)) {
throw new Error('Unknown Git remote operation.');
}
const service = requireService(event.sender);
const id = event.sender.id;
if (remoteRuns.has(id)) {
throw new Error('A push, pull or fetch is already running in this window.');
}
const controller = new AbortController();
remoteRuns.set(id, controller);
const options: RemoteOptions = {
signal: controller.signal,
chooseRemote: async (remotes) => {
const shown = remotes.slice(0, 8);
const response = await confirm(event.sender, {
type: 'question',
title: 'Publish Branch',
message: 'Which remote should this branch be published to?',
detail: 'The branch has no upstream yet. It is pushed under the same name and tracks it from then on.',
buttons: [...shown, 'Cancel'],
defaultId: 0,
cancelId: shown.length,
noLink: true,
});
return shown[response] ?? null;
},
};
gitLog.info(`${operation}: started in ${service.root}`);
try {
const output = await service[operation](options);
if (output) {
gitLog.info(output);
}
gitLog.info(output === null ? `${operation}: cancelled before it started.` : `${operation}: done.`);
return { status: await statusOf(event.sender), done: output !== null };
} catch (error) {
if (error instanceof GitCancelledError) {
gitLog.warn(`${operation}: cancelled.`);
} else {
gitLog.error(`${operation}: failed.\n${error instanceof Error ? error.message : String(error)}`);
}
throw error;
} finally {
remoteRuns.delete(id);
}
});
handle(GIT_IPC_CHANNELS.gitCancelRemote, (event) => {
const controller = remoteRuns.get(event.sender.id);
controller?.abort();
return controller !== undefined;
});
handle(GIT_IPC_CHANNELS.gitStash, async (event, includeUntracked) => {
await requireService(event.sender).stash(includeUntracked === true);
return statusOf(event.sender);
});
handle(GIT_IPC_CHANNELS.gitStashes, (event) => requireService(event.sender).stashes());
handle(GIT_IPC_CHANNELS.gitStashApply, async (event, index) => {
await requireService(event.sender).stashAction('apply', index);
return statusOf(event.sender);
});
handle(GIT_IPC_CHANNELS.gitStashPop, async (event, index) => {
await requireService(event.sender).stashAction('pop', index);
return statusOf(event.sender);
});
handle(GIT_IPC_CHANNELS.gitStashDrop, async (event, index) => {
await requireService(event.sender).stashAction('drop', index);
return statusOf(event.sender);
});
// #284: -d first; an unmerged branch comes back as `notMerged` and the page asks before forcing.
handle(GIT_IPC_CHANNELS.gitDeleteBranch, async (event, name, force): Promise<GitDeleteBranchResult> => {
const result = await requireService(event.sender).deleteBranch(name, force === true);
return { status: await statusOf(event.sender), deleted: result === 'deleted', notMerged: result === 'not-merged' };
});
handle(GIT_IPC_CHANNELS.gitHeadContent, (event, file) => requireService(event.sender).headContent(file));
// #175: the editor asks on every file it opens, so "nothing to show" is null, never an error.
handle(GIT_IPC_CHANNELS.gitBaseline, async (event, file) => {
Expand Down
50 changes: 46 additions & 4 deletions apps/ide/src/main/git/gitRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ export interface GitRunOptions {
readonly timeoutMs?: number | undefined;
/** Written to git's standard input (`blame --contents -`); stdin is closed either way. */
readonly input?: string | undefined;
/** #284: aborting it kills git and rejects with `GitCancelledError` (a remote operation's Cancel). */
readonly signal?: AbortSignal | undefined;
/** #284: variables added to `gitEnvironment` (the remote operations' `REMOTE_GIT_ENV`). */
readonly env?: Readonly<Record<string, string>> | undefined;
/**
* #284: false leaves `--literal-pathspecs` out, for a command given no
* pathspec that runs one internally: `stash --include-untracked` cleans
* with the pathspec `:/`, which literally matches nothing, so the
* untracked files would be saved but stay in the work tree.
*/
readonly literalPathspecs?: false | undefined;
}

/** Thrown when no `git` executable is on PATH. */
Expand All @@ -43,6 +54,14 @@ export class GitCommandError extends Error {
}
}

/** #284: thrown when a run was cancelled through its `signal`. */
export class GitCancelledError extends Error {
constructor(args: readonly string[]) {
super(`git ${args[0] ?? ''} was cancelled.`);
this.name = 'GitCancelledError';
}
}

export const DEFAULT_GIT_TIMEOUT_MS = 30_000;
const MAX_OUTPUT_BYTES = 64 * 1024 * 1024;

Expand Down Expand Up @@ -72,12 +91,31 @@ export function gitEnvironment(base: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
return env;
}

/**
* #284: what push, pull and fetch add. Credentials come from git's own
* helpers and SSH agent only: no prompt in a terminal (`GIT_TERMINAL_PROMPT`)
* nor in Git Credential Manager's window (`GCM_INTERACTIVE`), so a missing
* credential fails at once with git's message instead of waiting for input
* nobody can give.
*/
export const REMOTE_GIT_ENV: Readonly<Record<string, string>> = {
GIT_TERMINAL_PROMPT: '0',
GCM_INTERACTIVE: 'never',
};

export const runGit: GitRunner = (cwd, args, options = {}) => new Promise((resolve, reject) => {
const fullArgs = [...BASE_ARGS, ...args];
const base = options.literalPathspecs === false ? BASE_ARGS.filter((arg) => arg !== '--literal-pathspecs') : BASE_ARGS;
const fullArgs = [...base, ...args];
const timeoutMs = options.timeoutMs ?? DEFAULT_GIT_TIMEOUT_MS;
if (options.signal?.aborted) {
reject(new GitCancelledError(args));
return;
}
const child = execFile('git', fullArgs, {
cwd,
env: gitEnvironment(process.env),
timeout: options.timeoutMs ?? DEFAULT_GIT_TIMEOUT_MS,
env: { ...gitEnvironment(process.env), ...options.env },
timeout: timeoutMs,
...(options.signal ? { signal: options.signal } : {}),
maxBuffer: MAX_OUTPUT_BYTES,
windowsHide: true,
encoding: 'utf8',
Expand All @@ -88,13 +126,17 @@ export const runGit: GitRunner = (cwd, args, options = {}) => new Promise((resol
reject(new GitNotFoundError());
return;
}
if (options.signal?.aborted) {
reject(new GitCancelledError(args));
return;
}
const exitCode = typeof code === 'number' ? code : -1;
if ((options.okExitCodes ?? []).includes(exitCode)) {
resolve({ stdout, stderr, exitCode });
return;
}
if ((error as { killed?: boolean }).killed) {
reject(new GitCommandError(args, exitCode, `git ${args[0] ?? ''} timed out.`));
reject(new GitCommandError(args, exitCode, `git ${args[0] ?? ''} timed out after ${timeoutMs / 1000} s.`));
return;
}
reject(new GitCommandError(args, exitCode, stderr));
Expand Down
Loading
Loading