Skip to content

Commit cdd8ea7

Browse files
committed
Update copilot instructions
1 parent 885890e commit cdd8ea7

7 files changed

+132
-37
lines changed

.github/instructions/build-and-config.instructions.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,32 @@ This repository uses npm, Rspack, TypeScript, and ESLint to build and lint the F
77
When working on the build, config, or tooling files matched by this pattern:
88

99
- Use `npm install` to install dependencies. Prefer npm scripts in `package.json` over ad-hoc commands.
10+
11+
**Build System (Rspack):**
12+
1013
- Builds are driven by **Rspack mode** (not `NODE_ENV`):
1114
- `npm run build` runs `rspack build --mode development`
1215
- `npm run watch` runs `rspack build --watch --mode development`
1316
- `npm run prod` runs `rspack build --mode production`
14-
- Use `npm run lint` to lint the codebase.
15-
- Use `npm run format` to apply Prettier formatting.
16-
- Use `npm run typecheck` to run Svelte type checking.
17+
- `rspack.config.ts` exports a dual configuration: one for the Node.js extension backend (`extensionConfig`) and one for the Svelte webviews (`webviewsConfig`).
18+
- Rspack uses `builtin:swc-loader` for fast transpilation and `ForkTsCheckerWebpackPlugin` for type checking.
19+
- Rspack automatically copies the compiled native addons (`.node` files) from `build/Release/` to `dist/` based on the host OS.
20+
21+
**TypeScript Configuration:**
22+
23+
- The project uses a composite TypeScript setup:
24+
- `tsconfig.json`: Base configuration with project references.
25+
- `tsconfig.node.json`: For the extension backend (`src/extension`) and shared code.
26+
- `tsconfig.app.json`: For the webview frontend (`src/webview`) and shared code.
27+
28+
**Linting & Formatting:**
29+
30+
- Use `npm run lint` to lint the codebase. ESLint uses the Flat Config format (`eslint.config.mjs`) with `@typescript-eslint` (`projectService: true`) and supports Svelte 5 runes as globals.
31+
- Use `npm run format` to apply Prettier formatting, or `npm run check` to verify formatting.
32+
- Use `npm run svelte:check` to run Svelte type checking against `tsconfig.app.json`.
33+
34+
**Native Addons & Packaging:**
35+
36+
- Use `npm run build:addon` to compile the C++ process monitor addons via `node-gyp`.
37+
- Use `npm run test` to run the monitor tests.
38+
- Use `npm run package` to package the extension via `vsce`.

.github/instructions/extension-backend.instructions.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,29 @@ Both Judge and Stress implement the same file-switching pattern:
1919
5. `_switchToNoFile()` handles cases where no valid file is open
2020
6. `_rehydrateWebviewFromState()` sends current in-memory state to the webview
2121

22-
When switching files, stop any running processes for the previous file before switching to the new one.
22+
When switching files, processes are **not** stopped. Instead, they are moved to the background (e.g., via `_moveCurrentStateToBackground`) and trigger `_onDidChangeBackgroundTasks`. The `PanelViewProvider` monitors and displays these running background tasks.
2323

24-
## TextHandler
24+
## Run Settings
2525

26-
Use `TextHandler` from `src/extension/utils/vscode.ts` for all streamed output. It:
26+
- **`runSettingsCommands.ts`**: Registers commands (`editRunSettings`, `resetRunSettings`) and provides default `languageTemplates`.
27+
- **`vscode.ts`**: Provides `getFileRunSettings`, `initializeRunSettingsWatcher`, and `resolveVariables` to parse and resolve VS Code variables (like `${fileDirname}`) in commands.
2728

28-
- Keeps full data internally for comparisons (answer checking)
29-
- Truncates display output (max characters/lines)
30-
- Normalizes CRLF to LF
31-
- Ensures trailing newline on final writes
29+
## Extended VS Code Utilities (`vscode.ts`)
3230

33-
Write modes:
31+
- **`TextHandler`**: For all streamed output. Keeps full data internally, truncates display output, normalizes CRLF to LF, ensures trailing newline. Write modes: `"batch"`, `"force"`, `"final"`. Always call `.reset()` before a fresh run.
32+
- **`ReadonlyStringProvider`**: Manages the custom `fastolympiccoding` URI scheme for displaying read-only text documents.
33+
- **`openInNewEditor` / `openInTerminalTab`**: Helpers for displaying output. Terminal tabs support ANSI colors and native clickable file links.
34+
- **`openOrCreateFile`**: Helper for file management.
3435

35-
- `"batch"`: Batched updates, throttled for performance
36-
- `"force"`: Immediate update, bypasses throttling
37-
- `"final"`: Final write, applies truncation rules and trailing newline
36+
## UI/UX Features
3837

39-
Always call `.reset()` before a fresh run.
38+
- **Template Folding (`folding.ts`)**: `TemplateFoldingProvider` handles folding ranges for inserted template regions.
39+
- **Changelog (`changelog.ts`)**: `showChangelog` handles semver comparison and displays the changelog on extension updates.
40+
- **Status Bar (`statusBar.ts`)**: `createStatusBarItem` creates the main status bar entry point that triggers the `PanelViewProvider`.
41+
42+
## Template Dependency Resolution
43+
44+
`getTemplateContent` in `index.ts` handles reading template files and detecting cyclic dependencies via DFS before insertion.
4045

4146
## Runnable and runtime.ts
4247

@@ -63,15 +68,15 @@ Debug support uses **attach mode**:
6368
3. Start debug-wrapped process via `Runnable`
6469
4. Call `vscode.debug.startDebugging()` with fully-resolved config
6570

66-
Track debug sessions via `onDidStartDebugSession` / `onDidTerminateDebugSession`. Tag configs with `fastolympiccodingTestcaseId` to identify which testcase is being debugged.
71+
Track debug sessions via `onDidStartDebugSession` / `onDidTerminateDebugSession`. Tag configs with `fastolympiccodingTestcaseUuid` to identify which testcase is being debugged.
6772

6873
## Competitive Companion
6974

7075
`competitiveCompanion.ts` implements an HTTP server receiving problem data from the browser extension. Problems are queued in `ProblemQueue` and processed sequentially. Users select target files via QuickPick for batch problems.
7176

7277
## Logging
7378

74-
Use `getLogger(component)` from `src/extension/utils/logging.ts`. Component names: `"runtime"`, `"judge"`, `"stress"`, `"competitive-companion"`.
79+
Use `getLogger(component)` from `src/extension/utils/logging.ts`. Component names: `"runtime"`, `"judge"`, `"stress"`, `"competitive-companion"`, `"compilation"`, `"vscode"`.
7580

7681
Log levels (controlled via VS Code's "Developer: Set Log Level"):
7782

.github/instructions/judge-provider.instructions.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,22 @@ Status determination uses `severityNumberToInteractiveStatus()` to combine both
5353

5454
## Action Handling
5555

56-
The `handleMessage` method dispatches to action handlers based on `action` field:
56+
The `handleMessage` method dispatches based on `msg.type`. Top-level message types include:
57+
58+
- `LOADED`: Loads the current file data
59+
- `NEXT`: Moves to the next testcase
60+
- `SAVE`: Saves testcase data
61+
- `VIEW`: Opens full stdio in a new editor
62+
- `COPY`: Copies stdio content to clipboard
63+
- `STDIN`: Updates stdin
64+
- `TL`: Updates time limit
65+
- `ML`: Updates memory limit
66+
- `REQUEST_TRIMMED_DATA`: Fetches truncated data for display
67+
- `REQUEST_FULL_DATA`: Fetches full data for editing
68+
- `NEW_INTERACTOR_SECRET`: Generates a new interactor secret
69+
- `ACTION`: Calls `this._action(msg)` which dispatches based on the `action` field
70+
71+
Actions handled by `_action`:
5772

5873
- `RUN`: Execute single testcase
5974
- `STOP`: Cancel running testcase
@@ -64,15 +79,17 @@ The `handleMessage` method dispatches to action handlers based on `action` field
6479
- `TOGGLE_SKIP`: Toggle skip flag
6580
- `COMPARE`: Open diff view
6681
- `DEBUG`: Run in debug mode
67-
- `REQUEST_DATA`: Fetch full data for editing
6882
- `OPEN_INTERACTOR`: Open interactor file
83+
- `TOGGLE_INTERACTIVE`: Toggle interactive mode
6984

7085
## Background Task Tracking
7186

7287
`_contexts` map holds contexts for all files (not just active). Methods:
7388

7489
- `getAllBackgroundTasks()`: Returns Map of file → running testcase UUIDs
90+
- `getBackgroundTasksForFile(file)`: Returns an array of running testcase UUIDs for a specific file
7591
- `stopBackgroundTasksForFile(file)`: Stop all running testcases for a file
92+
- `stopAllBackgroundTasks()`: Stops all background tasks across all files
7693
- `onDidChangeBackgroundTasks`: Event for PanelViewProvider to refresh
7794

7895
## Key Methods
@@ -82,3 +99,5 @@ The `handleMessage` method dispatches to action handlers based on `action` field
8299
- `_launchTestcase(ctx, bypassLimits, debugMode)`: Spawns process, wires stdio
83100
- `_launchInteractiveTestcase(ctx, bypassLimits, debugMode)`: Handles two-process interactive flow
84101
- `addTestcaseToFile(file, testcase, timeLimit?, memoryLimit?)`: Adds testcase from external source (Competitive Companion)
102+
- `exportTestcasesForFile(file)`: Serializes and exports testcases for a given file
103+
- `appendImportedTestcasesForFile(file, rawData)`: Parses, imports, and appends testcases to a file

.github/instructions/native-addon.instructions.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Platform-specific native addons for strict process execution with:
1717
- Uses `pidfd_open` (kernel 5.3+) to avoid PID reuse races
1818
- Polls `/proc/[pid]/status` for `VmHWM` (Peak Resident Set Size)
1919
- **Critical**: Capture `VmHWM` before reaping zombie; values disappear after `wait4`
20-
- Memory enforcement via polling (50ms interval), not `RLIMIT_AS`
20+
- Memory enforcement via polling (10ms interval), not `RLIMIT_AS`
21+
- Uses `eventfd` to signal and wake the worker thread for cancellation
2122

2223
### macOS (`darwin-process-monitor.cpp`)
2324

@@ -29,15 +30,17 @@ Platform-specific native addons for strict process execution with:
2930

3031
- Uses **Job Objects** for hard memory/CPU limits (OS-enforced)
3132
- Process created suspended, added to Job, then resumed
32-
- Uses completion ports for efficient wait
33+
- Uses `WaitForMultipleObjects` with a polling loop to handle process exit, cancellation events, and wall-clock timeouts
3334
- **All APIs use Wide Strings** (`CreateProcessW`, `std::wstring`)
3435

3536
## Spawn API
3637

3738
```typescript
39+
// Spawn function signature
40+
// spawn(command, args, cwd, timeoutMs, memoryLimitMB, pipeNameIn, pipeNameOut, pipeNameErr, onSpawn)
41+
3842
interface NativeSpawnResult {
3943
pid: number;
40-
stdio: [number, number, number]; // fd handles
4144
result: Promise<AddonResult>;
4245
cancel: () => void;
4346
}
@@ -54,7 +57,7 @@ interface AddonResult {
5457

5558
## IPC
5659

57-
Stdio uses Named Pipes (Windows) or Unix Sockets (Linux/macOS) established before process spawn. The extension's `Runnable` class connects to these pipes.
60+
Stdio uses Named Pipes (Windows) or Unix Sockets (Linux/macOS). The extension creates the pipes/sockets and passes their paths to the addon's `spawn` function, which then connects to them internally before executing the child process.
5861

5962
## Cancellation
6063

.github/instructions/shared-contracts.instructions.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ applyTo: "src/shared/**/*.ts"
88

99
## Enums (String Literal Tuples)
1010

11-
Enums are `const` string literal tuples validated via `v.picklist()`:
11+
Enums are `const` string literal tuples validated via `v.picklist()`. All string literal tuples (including `ActionValues`, `InputTypeValues`, `ProviderMessageTypeValues`, `WebviewMessageTypeValues`, etc.) follow the same append-only rule.
1212

1313
### Status
1414

@@ -74,9 +74,19 @@ StateIdValue = ["Generator", "Solution", "Judge"] as const;
7474

7575
## Schema Patterns
7676

77-
Use Valibot for all schemas. Pattern:
77+
Use Valibot for all schemas.
78+
79+
### Message Type Arrays
80+
81+
When adding a new message schema, its `type` literal **must** also be appended to the corresponding `ProviderMessageTypeValues` or `WebviewMessageTypeValues` array. This prevents the arrays from falling out of sync with the union schemas.
7882

7983
```typescript
84+
export const ProviderMessageTypeValues = [
85+
"EXAMPLE",
86+
"OTHER",
87+
// Append new types here
88+
] as const;
89+
8090
export const ExampleMessageSchema = v.object({
8191
type: v.literal("EXAMPLE"),
8292
payload: v.string(),
@@ -90,6 +100,20 @@ export const AllMessagesSchema = v.union([ExampleMessageSchema, OtherMessageSche
90100
export type AllMessages = v.InferOutput<typeof AllMessagesSchema>;
91101
```
92102

103+
### Advanced Valibot Patterns
104+
105+
- **Default Values:** Use `v.fallback()` to provide default state values (e.g., `v.fallback(v.string(), "")` or `v.fallback(v.string(), () => crypto.randomUUID())`).
106+
- **Complex Validation:** Use `v.pipe()`, `v.looseObject()`, and `v.check()` for custom validation logic (e.g., in `RunSettingsSchema`).
107+
- **Optional & Record Types:** Use `v.optional()` and `v.record()` for flexible configurations.
108+
109+
### Type Inference and Utility Types
110+
111+
Derive property types from schemas using TypeScript utility types. For example:
112+
113+
```typescript
114+
export type TestcaseProperty = Exclude<keyof Testcase, "uuid">;
115+
```
116+
93117
## Append-Only Rule
94118

95119
When adding new enum values or message types, **append to the end** of arrays. Never rename or reorder existing values—they may be persisted in workspaceState.

.github/instructions/stress-provider.instructions.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,34 +69,38 @@ interface State {
6969
In interactive mode:
7070

7171
- Generator produces a "secret" (like interactor in Judge)
72-
- Solution and Judge run with Generator mediating
72+
- The **Judge** acts as the interactor (running `interactorFile`), communicating back and forth with the **Solution** (the user's solution).
73+
- The **Generator** provides the initial secret to the Judge.
7374
- Uses `interactiveSecretPromise` to wait for webview to receive the secret
74-
- Solution runs as interactor between Generator and user solution
7575

7676
## State Persistence
7777

78-
Persisted per-file data:
78+
Persisted per-file data via `StressDataSchema` in `_saveState`:
7979

8080
- `interactiveMode`: boolean
81-
- `states`: Array of `{ state: StateId, shown: boolean }`
81+
- `states`: Array of `{ state: StateId, shown: boolean, stdin: string, stdout: string, stderr: string, status: Status }`
8282

83-
The stdio content is NOT persisted (only visibility state).
83+
The stdio content, status, state, and visibility are all persisted for each component.
8484

8585
## Message Handling
8686

87+
- `LOADED`: Loads the current file data
8788
- `RUN`: Start stress loop
8889
- `STOP`: Set stopFlag, stop current iteration
8990
- `VIEW`: Open full stdio in new editor
91+
- `COPY`: Copies specific stdio content to the clipboard
9092
- `ADD`: Copy Generator output to Judge testcases
9193
- `OPEN`: Open the corresponding file (generator/judge file)
9294
- `CLEAR`: Stop and clear all state
9395
- `SAVE`: Persist interactiveMode setting
9496
- `TOGGLE_VISIBILITY`: Toggle state details visibility
97+
- `TOGGLE_INTERACTIVE`: Toggles the interactive mode state
9598

9699
## Background Task Tracking
97100

98101
- `getRunningStressSessions()`: Returns array of file paths with running stress
99102
- `stopStressSession(file)`: Stop stress for a specific file
103+
- `stopAll()`: Stops all stress sessions across all files in the workspace
100104
- `onDidChangeBackgroundTasks`: Event for PanelViewProvider
101105

102106
## Key Methods

.github/instructions/webview-frontend.instructions.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,37 @@ Receive messages in `App.svelte` via `window.addEventListener("message", ...)` i
2525

2626
- **App.svelte**: Entry point, message handling, testcase list rendering
2727
- **TestcaseToolbar.svelte**: Status badges, action buttons (run, stop, debug, delete)
28-
- **Testcase.svelte**: Stdio textareas (stdin, stdout, stderr, acceptedStdout)
28+
- **Testcase.svelte**: Stdio textareas (stdin, stdout, stderr, acceptedStdout, interactorSecret)
2929

3030
Rendering pattern:
3131

3232
```svelte
33-
{#each testcases as testcase (testcase.uuid)}
34-
<TestcaseToolbar {testcase} onprerun={() => handlePrerun(testcase.uuid)} />
35-
<Testcase {testcase} bind:this={testcaseRefs[testcase.uuid]} />
33+
{#each testcases as testcase, index (testcase.uuid)}
34+
<div class="testcase-item">
35+
<TestcaseToolbar {testcase} onprerun={() => handlePrerun(testcase.uuid)} />
36+
{#if testcase.status === "COMPILING" || testcase.skipped}
37+
<div class="half-opacity">
38+
<Testcase bind:testcase={testcases[index]} bind:this={testcaseRefs[testcase.uuid]} />
39+
</div>
40+
{:else}
41+
<Testcase bind:testcase={testcases[index]} bind:this={testcaseRefs[testcase.uuid]} />
42+
{/if}
43+
</div>
3644
{/each}
3745
```
3846

3947
### Stress View (`src/webview/stress/`)
4048

4149
- **App.svelte**: Entry point, message handling, state list rendering
42-
- **StateToolbar.svelte**: Status badges, action buttons (add, open file)
50+
- **StateToolbar.svelte**: Status badges, action buttons (add, open file, toggle interactive mode)
4351
- **State.svelte**: Stdio textareas for Generator/Solution/Judge
4452

4553
### Shared Components (`src/webview/`)
4654

4755
- **AutoresizeTextarea.svelte**: Resizable textarea with ANSI color support
4856
- **Tooltip.svelte**: Global tooltip singleton
57+
- **Button.svelte**: Standard button component
58+
- **ButtonDropdown.svelte**: Composite component providing a main button alongside a dropdown menu
4959

5060
## AutoresizeTextarea
5161

@@ -56,14 +66,20 @@ Key props:
5666
- `editing`: Bindable, tracks edit mode
5767
- `hiddenOnEmpty`: Hide when empty
5868
- `variant`: `"default"` | `"stderr"` | `"accepted"` | `"active"` | `"interactor-secret"`
69+
- `placeholder`: Text to display when empty
70+
- `ctrlEnterNewline`: Boolean to toggle specific Ctrl+Enter newline behavior
71+
- `actions`: A Svelte `Snippet` prop for injecting custom action buttons into the textarea overlay
5972

60-
Editing callbacks:
73+
Callbacks:
6174

6275
- `onpreedit`: Called before entering edit mode (fetch full data from extension)
6376
- `onsave`: Called when saving changes
6477
- `oncancel`: Called when canceling edit
78+
- `onexpand`: Called when the user clicks the expand icon (to view full stdio)
79+
- `oncopy`: Called when the user clicks the copy icon
80+
- `onkeyup`: Keyboard event handler
6581

66-
Pattern for fetching full data on edit:
82+
Pattern for fetching full data on edit and handling actions:
6783

6884
```svelte
6985
<AutoresizeTextarea
@@ -76,6 +92,8 @@ Pattern for fetching full data on edit:
7692
oncancel={() => {
7793
postProviderMessage({ type: "REQUEST_TRIMMED_DATA", uuid: testcase.uuid, stdio: "STDIN" });
7894
}}
95+
onexpand={() => handleExpand("STDIN")}
96+
oncopy={() => handleCopy("STDIN")}
7997
/>
8098
```
8199

0 commit comments

Comments
 (0)