Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

fix: reconcile marketplace defaults on startup

wyt3cdd84aefc0b
diff --git a/run.cmd b/run.cmd
index 77fd7a38..ffba45fe 100644
--- a/run.cmd
+++ b/run.cmd
@@ -19,7 +19,12 @@ if errorlevel 1 exit /b 1
pushd "%APP_DIR%"
taskkill /F /IM electron.exe >nul 2>nul
-call npm start
+set "ELECTRON_USER_DATA_DIR=%TEMP%\orkas-electron-source"
+if exist "%APP_DIR%\node_modules\.bin\electron.cmd" (
+ call "%APP_DIR%\node_modules\.bin\electron.cmd" "--user-data-dir=%ELECTRON_USER_DATA_DIR%" "%APP_DIR%"
+) else (
+ call npm start
+)
set "RC=%ERRORLEVEL%"
popd
exit /b %RC%
diff --git a/run.sh b/run.sh
index ea93c2a5..9a74d473 100755
--- a/run.sh
+++ b/run.sh
@@ -46,10 +46,17 @@ cd "$APP_DIR"
pkill -9 -f "$APP_DIR/node_modules/electron/dist" >/dev/null 2>&1 || true
sleep 0.3
+# Keep the Orkas product identity and install data root unchanged, but give
+# source launches their own Electron profile. Without this, a packaged Orkas
+# instance that is already running owns the same Electron single-instance lock
+# and this checkout exits before app.whenReady().
+PROFILE_KEY="$(printf '%s' "$APP_DIR" | cksum | awk '{print $1}')"
+ELECTRON_USER_DATA_DIR="${TMPDIR:-/tmp}/orkas-electron-source-$PROFILE_KEY"
+
if [ "$(uname -s)" = "Darwin" ]; then
APP_BUNDLE="$APP_DIR/node_modules/electron/dist/Orkas.app"
if [ -d "$APP_BUNDLE" ]; then
- ARGS=("$APP_DIR")
+ ARGS=("--user-data-dir=$ELECTRON_USER_DATA_DIR" "$APP_DIR")
# Launch through LaunchServices so macOS routes orkas:// open-url events to this dev app
# instance. Directly executing `Electron .` leaves the app running, but protocol callbacks
# may be delivered to the .app bundle instead of the command-line process.
@@ -62,4 +69,7 @@ fi
# This is ANGLE fallback noise when probing driver attributes and has no
# functional impact. Filter only that stderr line; pass through everything else.
# If `unbuffer` is unavailable, default line buffering is fine (macOS bash built-in).
+if [ -x "$APP_DIR/node_modules/.bin/electron" ]; then
+ exec "$APP_DIR/node_modules/.bin/electron" "--user-data-dir=$ELECTRON_USER_DATA_DIR" "$APP_DIR" 2> >(grep -v --line-buffered "EGL Driver message" >&2)
+fi
exec npm start 2> >(grep -v --line-buffered "EGL Driver message" >&2)
diff --git a/src/main/index.ts b/src/main/index.ts
index 54278cd1..0900948e 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -42,6 +42,9 @@ import './install-data-root.cjs';
import { desktopPlatform, osVersion } from './system_info';
const APP_USER_MODEL_ID = 'com.orkas.desktop';
+const MARKETPLACE_DEFAULTS_REFRESH_INTERVAL_MS = 12 * 60 * 60 * 1000;
+const MARKETPLACE_SERVER_CHECK_INTERVAL_MS = 12 * 60 * 60 * 1000;
+const MARKETPLACE_DEFAULTS_RETRY_DELAYS_MS = [3_000, 3_000, 3_000] as const;
// Source and packaged builds share one app identity and one server
// environment: global prod. This keeps local data paths and OS app grouping
@@ -103,6 +106,7 @@ import * as storage from './storage';
import { initLogger, createLogger } from './logger';
initLogger();
const log = createLogger('orkas');
+const marketplaceBootLog = createLogger('marketplace_boot');
// Replay any pin / migration warnings buffered by install-data-root
// (which runs before logger.ts can be imported) into the daily log.
@@ -407,6 +411,158 @@ async function runBootMaintenanceSweeps(): Promise<void> {
} catch (err) { log.warn('workspace empty-dir sweep failed', { error: (err as Error).message }); }
}
+let marketplaceReconcileStatusSubscribed = false;
+let marketplaceReconcileInFlight: Promise<void> | null = null;
+let marketplaceReconcileInFlightKey = '';
+const marketplaceDefaultsRetryTimers = new Map<string, ReturnType<typeof setTimeout>>();
+const marketplaceDefaultsRetryAttempts = new Map<string, number>();
+
+function subscribeMarketplaceReconcileStatus(m: typeof import('./features/marketplace_reconcile')): void {
+ if (marketplaceReconcileStatusSubscribed) return;
+ marketplaceReconcileStatusSubscribed = true;
+ m.subscribeReconcileStatus((status) => {
+ ipc.broadcastToRenderer('marketplace:reconcile-status', status);
+ });
+}
+
+function marketplaceBootContextStillActive(uid: string): boolean {
+ if (!uid || users.isAnonymousLocalId(uid)) return false;
+ try { return users.getActiveUserId() === uid; }
+ catch { return false; }
+}
+
+function clearMarketplaceDefaultsRetry(runKey: string): void {
+ const timer = marketplaceDefaultsRetryTimers.get(runKey);
+ if (timer) clearTimeout(timer);
+ marketplaceDefaultsRetryTimers.delete(runKey);
+ marketplaceDefaultsRetryAttempts.delete(runKey);
+}
+
+function scheduleMarketplaceDefaultsRetry(runKey: string, uid: string, error: string): void {
+ if (marketplaceDefaultsRetryTimers.has(runKey)) return;
+ const attempt = marketplaceDefaultsRetryAttempts.get(runKey) || 0;
+ const delayMs = MARKETPLACE_DEFAULTS_RETRY_DELAYS_MS[attempt];
+ if (delayMs === undefined) {
+ marketplaceBootLog.warn('marketplace default installs retry exhausted', { error });
+ marketplaceDefaultsRetryAttempts.delete(runKey);
+ return;
+ }
+ marketplaceDefaultsRetryAttempts.set(runKey, attempt + 1);
+ const timer = setTimeout(() => {
+ marketplaceDefaultsRetryTimers.delete(runKey);
+ if (!marketplaceBootContextStillActive(uid)) {
+ marketplaceDefaultsRetryAttempts.delete(runKey);
+ return;
+ }
+ runMarketplaceInstallReconcile('marketplace-defaults-retry').catch((err) => {
+ marketplaceBootLog.warn('marketplace default installs retry failed', {
+ error: (err as Error).message,
+ });
+ });
+ }, delayMs);
+ timer.unref?.();
+ marketplaceDefaultsRetryTimers.set(runKey, timer);
+ marketplaceBootLog.info('scheduled marketplace default installs retry', {
+ attempt: attempt + 1,
+ delay_ms: delayMs,
+ error,
+ });
+}
+
+async function runMarketplaceInstallReconcile(reason: string): Promise<void> {
+ const uid = users.getActiveUserId();
+ if (!marketplaceBootContextStillActive(uid)) {
+ marketplaceBootLog.info('skip marketplace reconcile: local user unavailable', { reason });
+ return;
+ }
+
+ const runKey = uid;
+ if (marketplaceReconcileInFlight && marketplaceReconcileInFlightKey === runKey) {
+ await marketplaceReconcileInFlight;
+ return;
+ }
+
+ const shouldContinue = (): boolean => marketplaceBootContextStillActive(uid);
+ marketplaceReconcileInFlightKey = runKey;
+ marketplaceReconcileInFlight = (async () => {
+ let defaultSeedStatusActive = false;
+ let marketplaceReconcileModule: typeof import('./features/marketplace_reconcile') | null = null;
+ const clearDefaultSeedStatus = (): void => {
+ if (marketplaceReconcileModule && defaultSeedStatusActive) {
+ marketplaceReconcileModule.setDefaultInstallSeedStatus(false);
+ defaultSeedStatusActive = false;
+ }
+ };
+
+ try {
+ const [mp, m] = await Promise.all([
+ import('./features/marketplace'),
+ import('./features/marketplace_reconcile'),
+ ]);
+ marketplaceReconcileModule = m;
+ subscribeMarketplaceReconcileStatus(m);
+
+ if (await mp.hasKnownDefaultInstallWork(uid)) {
+ m.setDefaultInstallSeedStatus(true);
+ defaultSeedStatusActive = true;
+ }
+
+ if (!shouldContinue()) {
+ clearDefaultSeedStatus();
+ return;
+ }
+
+ const forceMarketplaceNetwork = reason === 'marketplace-defaults-retry';
+ const seeded = await mp.ensureDefaultInstalls(uid, {
+ shouldContinue,
+ minIntervalMs: forceMarketplaceNetwork ? 0 : MARKETPLACE_DEFAULTS_REFRESH_INTERVAL_MS,
+ force: forceMarketplaceNetwork,
+ });
+ if (seeded.failed) {
+ clearDefaultSeedStatus();
+ scheduleMarketplaceDefaultsRetry(runKey, uid, seeded.error || 'unknown error');
+ } else {
+ clearMarketplaceDefaultsRetry(runKey);
+ }
+ if ((seeded.seeded_agents || seeded.seeded_skills) && !defaultSeedStatusActive) {
+ m.setDefaultInstallSeedStatus(true);
+ defaultSeedStatusActive = true;
+ }
+
+ if (!shouldContinue()) {
+ clearDefaultSeedStatus();
+ return;
+ }
+
+ await m.checkServerUpdatesForInstalls(uid, {
+ shouldContinue,
+ minIntervalMs: MARKETPLACE_SERVER_CHECK_INTERVAL_MS,
+ });
+ const result = await m.reconcileInstalls(uid, { shouldContinue });
+ if (
+ result.pulled_agents || result.pulled_skills
+ || result.pruned_agents || result.pruned_skills
+ || result.restored_agents || result.restored_skills
+ || result.patched_agents || result.patched_skills
+ ) {
+ marketplaceBootLog.info('marketplace install reconcile completed', { reason, ...result });
+ }
+ } catch (err) {
+ clearDefaultSeedStatus();
+ marketplaceBootLog.warn('marketplace install reconcile failed', {
+ reason,
+ error: (err as Error).message,
+ });
+ }
+ })().finally(() => {
+ if (marketplaceReconcileInFlightKey === runKey) {
+ marketplaceReconcileInFlight = null;
+ marketplaceReconcileInFlightKey = '';
+ }
+ });
+ await marketplaceReconcileInFlight;
+}
+
// `kb-file://<relpath>` — maps a KB-relative path to the active user's
// `<uid>/cloud/contexts/<relpath>` on disk and returns the bytes with an
// explicit Content-Type. Used by the renderer's PDF viewer iframe.
@@ -827,6 +983,7 @@ if (!gotLock) {
const m = await import('./features/marketplace_biz');
await m.primeCategoryCache({ localOnly: true });
});
+ registerDeferred('marketplace:reconcile', () => runMarketplaceInstallReconcile('startup'));
// Deferred after the renderer has had a few seconds to paint. Per-agent
// metacognitive reflection (single 12h-chained loop; the delay just stops