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
39 changes: 39 additions & 0 deletions docs/issues/agent-exec-utility-process-crash/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Plan

## Diagnosis

The source entrypoint gates `appMain` behind `runBackgroundExecUtilityHostIfRequested()`, but the
main build inlines dynamic imports. The built `out/main/index.js` still contains `appMain` top-level
startup code after the utility-host branch, so a utility child process can continue into the normal
app lifecycle and exit before responding to exec RPCs.

The utility host also listens to `process.parentPort` as if the callback receives the raw payload.
Electron sends a message event object whose `data` field contains the payload.

The formal `v1.0.5-beta.4` and `v1.0.5-beta.5` macOS arm64 artifacts both contain the same fragile
main-bundle utility entrypoint. A direct `utilityProcess.fork()` probe against those artifacts exits
with code 1 while loading `@electron-toolkit/utils`, because utility processes do not expose
main-process-only Electron exports such as `BrowserWindow`.

## Design

- Move `appMain` side effects into an exported `startApp()` function.
- Add a dedicated `backgroundExecUtilityHost` main build entrypoint that only loads the exec runtime.
- Keep `src/main/index.ts` as the normal app bootstrap and call `startApp()` there.
- Resolve the utility host entrypoint to `out/main/backgroundExecUtilityHost.js` in development,
unpacked, and packaged app layouts.
- Normalize parent-port messages in the utility host so both raw test payloads and Electron
`MessageEvent` payloads work.
- Keep the utility host event loop alive while it waits for parent-port RPC messages.
- Remove utility-host imports of `@electron-toolkit/utils`, because it statically imports
main-process-only Electron exports such as `BrowserWindow`.
- Keep shell environment and session path helpers free of `electron.app` imports so the utility
process can load the exec runtime.
- Add focused unit coverage for the host message normalization.

## Validation

- Run focused Vitest coverage for background exec runtime tests.
- Rebuild the main bundle and probe `utilityProcess.fork(out/main/backgroundExecUtilityHost.js)`
with `list` and `start` RPCs.
- Run project formatting, i18n check, and lint after implementation.
34 changes: 34 additions & 0 deletions docs/issues/agent-exec-utility-process-crash/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Agent Exec Utility Process Crash

## Summary

`agent-filesystem.exec` must run simple shell commands after the background exec manager moved
behind an Electron `utilityProcess` host. In `v1.0.5-beta.5`, every exec request can fail before
the shell command starts because the utility host exits instead of serving RPC requests.

## User Story

As an agent user, I can ask the built-in filesystem tool to run `true`, `echo hello`, `ls`, or a
long-running foreground command and get either normal output or a yielded background session.

## Acceptance Criteria

- The utility host starts without running the main app bootstrap.
- The utility host entrypoint has no static dependency on Electron main-process-only exports such as
`app` or `BrowserWindow`.
- The host accepts Electron `process.parentPort` message events and handles the contained RPC
payload.
- A foreground exec command that completes quickly returns the command result instead of a utility
process exit error.
- Existing crashed-session behavior remains intact when the utility process exits unexpectedly.

## Non-Goals

- Changing shell selection, command permissions, or session cleanup semantics.
- Replacing the `utilityProcess` architecture.
- Changing renderer tool-call UI.

## Constraints

- Keep the fix inside the main-process agent runtime/bootstrap path.
- Preserve packaged and development entrypoint resolution.
15 changes: 15 additions & 0 deletions docs/issues/agent-exec-utility-process-crash/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Tasks

- [x] Refactor `appMain` startup into an explicit function.
- [x] Add a dedicated utility-host main entrypoint.
- [x] Update `index.ts` to be the normal app bootstrap only.
- [x] Keep the app bootstrap graph out of the utility host.
- [x] Resolve the utility host entrypoint from development and packaged main builds.
- [x] Normalize utility-host parent-port message events.
- [x] Keep the utility host alive while waiting for RPC messages.
- [x] Remove the utility-host logger dependency on `@electron-toolkit/utils`.
- [x] Remove the utility-host shell-env dependency on `electron.app`.
- [x] Remove the utility-host session-path dependency on `electron.app`.
- [x] Add tests for raw payload and MessageEvent payload handling.
- [x] Run focused runtime tests and build/probe validation.
- [x] Run `pnpm run format`, `pnpm run i18n`, and `pnpm run lint`.
22 changes: 22 additions & 0 deletions docs/issues/vite-mixed-import-warnings/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Vite Mixed Import Warnings Plan

## Approach

- Replace ineffective dynamic imports with ordinary static imports when the target is already part
of the eager main-process graph.
- For file MIME detection, move the detection helpers into a small dependency-free module so
`BaseFileAdapter` can import them statically without creating a direct adapter registry cycle.
- Keep `mime.ts` as the adapter registry facade by re-exporting the MIME detection helpers.

## Validation

- Search for remaining dynamic imports of the warned modules.
- Run formatting, i18n validation, lint, and a main build check to confirm the warnings are gone.

## Risks

- Static presenter imports are cyclic with `presenter/index.ts`; this project already uses the
exported singleton through static imports in several presenter modules. The changed call sites
only read the binding inside methods after initialization.
- Extracting MIME detection must preserve the existing exported symbols from `mime.ts` so current
callers do not need behavioral changes.
31 changes: 31 additions & 0 deletions docs/issues/vite-mixed-import-warnings/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Vite Mixed Import Warnings

## Problem

Electron Vite build output reports Rollup warnings when a module is dynamically imported while
also being statically imported elsewhere. The affected modules are:

- `src/main/presenter/filePresenter/mime.ts`
- `src/main/presenter/agentSessionPresenter/legacyImportService.ts`
- `src/main/presenter/index.ts`

Because the modules are already in the static graph, the dynamic imports cannot create separate
chunks and the build remains noisy.

## Acceptance Criteria

- The listed mixed static/dynamic import warnings no longer appear in the main-process build.
- Runtime behavior for file MIME detection, legacy chat import, data reset, shutdown interception,
and sync import broadcast remains unchanged.
- The fix stays scoped to import structure and avoids broad presenter refactors.

## Non-Goals

- Reworking presenter singleton ownership.
- Changing backup, reset, shutdown, or legacy import behavior.
- Optimizing chunk boundaries beyond removing ineffective dynamic imports.

## Constraints

- Keep the existing presenter and service APIs stable.
- Avoid introducing unresolved circular runtime reads during module initialization.
7 changes: 7 additions & 0 deletions docs/issues/vite-mixed-import-warnings/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Vite Mixed Import Warnings Tasks

- [x] Add SDD notes for the warning cleanup.
- [x] Extract MIME detection helpers away from the adapter registry.
- [x] Replace ineffective dynamic imports for legacy import and presenter singleton access.
- [x] Verify no warned dynamic imports remain.
- [x] Run required quality checks.
9 changes: 7 additions & 2 deletions electron.vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ export default defineConfig({
exclude: ['mermaid']
},
rollupOptions: {
input: {
index: resolve('src/main/index.ts'),
backgroundExecUtilityHost: resolve('src/main/backgroundExecUtilityHostEntry.ts')
},
external: ['sharp', '@duckdb/node-api'],
output: {
inlineDynamicImports: true,
manualChunks: undefined, // Disable automatic chunk splitting
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name]-[hash].js',
manualChunks: undefined
}
}
}
Expand Down
Loading