This document provides detailed information about developing and debugging HagiCode Desktop.
- Update Source Configuration
- macOS ARM64 Native Library Requirements
- Native Library Verification
- Development Workflow
- Environment Variables
- Web Service Runtime Recovery
- Prompt Resource Resolution
- Debugging
HagiCode Desktop supports multiple update sources for fetching application versions. By default, the application uses the official HTTP index source for both development and production builds.
The default update source is configured to use the official HagiCode server:
- Type: HTTP Index
- URL:
https://server.dl.hagicode.com/index.json - Name: HagiCode 官方源
This unified configuration ensures consistent version availability across development and production environments.
For development and testing purposes, you can override the default update source using the UPDATE_SOURCE_OVERRIDE environment variable.
# Linux/macOS
export UPDATE_SOURCE_OVERRIDE='{"type":"local-folder","name":"Local Dev Source","path":"/path/to/packages"}'
npm run dev
# Windows (PowerShell)
$env:UPDATE_SOURCE_OVERRIDE='{"type":"local-folder","name":"Local Dev Source","path":"C:\\path\\to\\packages"}'
npm run dev
# Windows (Command Prompt)
set UPDATE_SOURCE_OVERRIDE={"type":"local-folder","name":"Local Dev Source","path":"C:\\path\\to\\packages"}
npm run devFor local development and testing:
{
"type": "local-folder",
"name": "Local Development",
"path": "/path/to/release-packages"
}For custom HTTP index servers:
{
"type": "http-index",
"name": "Custom HTTP Source",
"indexUrl": "https://custom-server.com/index.json"
}For GitHub release sources:
{
"type": "github-release",
"name": "GitHub Releases",
"owner": "owner-name",
"repo": "repo-name",
"token": "optional-github-token"
}When using UPDATE_SOURCE_OVERRIDE, the configuration is validated for:
- Required fields based on source type
- Valid source type (
local-folder,github-release,http-index) - Proper JSON format
Invalid configurations will fall back to the default HTTP index source with a warning logged to the console.
# Start all development processes
npm run devThis command:
- Starts the Vite dev server for the renderer process
- Compiles the main process in watch mode
- Builds the preload script in watch mode
- Launches Electron with the development configuration
# Build all components
npm run build:all
# Build and verify
npm run build:prod# Quick validation
npm run smoke-test
# Verbose output
npm run smoke-test:verboseNODE_ENV: Set todevelopmentfor development modeHAGICO_CONFIG_PATH: Optional path to configuration directoryUPDATE_SOURCE_OVERRIDE: Override default update source (see above)
# Development with local source
NODE_ENV=development \
HAGICO_CONFIG_PATH=./local_data_root \
UPDATE_SOURCE_OVERRIDE='{"type":"local-folder","name":"Local","path":"/path/to/packages"}' \
npm run devDesktop persists web service runtime metadata so it can recover truthful service status after app restart when the backend process survives.
- Location:
<userData>/config/web-service.json - Core fields:
lastSuccessfulPortsavedAt
- Runtime recovery fields:
runtime.pidruntime.portruntime.startedAtruntime.versionIdruntime.recoverySourceruntime.recoveryMessageruntime.updatedAt
- Load persisted runtime identity from
web-service.json - Primary probe:
- PID liveness
- Port reachability
GET /api/healthsuccess
- If primary probe fails, run process-signature fallback
- Mark
stopped/erroronly when both primary and fallback checks fail - Invalidate stale runtime identity on confirmed mismatch
- Verify
runtime.portmatches expected port inweb-service.json. - Check
http://localhost:<port>/api/healthreturns200. - Confirm process command line contains
dotnetandPCode.Web.dll. - Restart desktop to rerun full recovery flow.
- Confirm
runtime.pidstill exists. - Confirm the port is bound by the expected target process.
- Stop service from desktop UI to trigger runtime state invalidation.
- If needed, remove
<userData>/config/web-service.jsonand relaunch.
The desktop app now resolves Smart Config and Diagnosis prompt files through a shared resolver.
smartConfig->config/config-prompt.llm.txtdiagnosis->scripts/diagnosis-prompt.llm.txt
For both entry points, path lookup follows this order:
- Active installed version directory (
apps/installed/<activeVersionId>/...) - Packaged resource locations (
process.resourcesPath,app.asar.unpacked,app.getAppPath()) - Development fallback (
process.cwd(), development root)
When prompt resolution fails, IPC responses include:
errorCode: stable category (PROMPT_NOT_FOUND,INVALID_PROMPT_PATH, etc.)resourceKey: requested resource (smartConfigordiagnosis)attemptedPaths: ordered candidate path list that was checkedactiveVersion: active version id at lookup time (if available)
These fields are intended for troubleshooting and can be surfaced in UI or logs.
The main process can be debugged using Chrome DevTools:
- Start the application in development mode
- The main process will automatically open DevTools on startup
- Use the console and inspector for debugging
The renderer process can be debugged using standard browser DevTools:
- Open the application
- Press
Ctrl+Shift+I(Windows/Linux) orCmd+Option+I(macOS) - Use the familiar Chrome DevTools interface
The application uses electron-log for logging:
- Main process logs are written to the console and log files
- Log files are located in the application's user data directory
- Use
log.info(),log.warn(),log.error(), etc. for logging
If the update source is not working as expected:
- Check the console for error messages
- Verify the
UPDATE_SOURCE_OVERRIDEJSON syntax - Ensure the specified path or URL is accessible
- Check network connectivity for HTTP sources
If using a local folder source:
- Verify the path is absolute and correct
- Ensure the folder contains valid package files
- Check file permissions for the specified directory
If the HTTP index source fails:
- Verify the URL is accessible in a browser
- Check network connectivity
- Ensure the index.json format is valid
- Check for authentication requirements