@evomap/evolver-cli 2.0.0-beta.1 → 2.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/antiGeneBenchmark.js +12 -0
  2. package/dist/antiGeneEvidence.d.ts +15 -0
  3. package/dist/antiGeneEvidence.js +49 -0
  4. package/dist/antiGeneRollout.d.ts +3 -1
  5. package/dist/antiGeneRollout.js +16 -2
  6. package/dist/assetHealth.d.ts +6 -0
  7. package/dist/assetHealth.js +107 -0
  8. package/dist/assetSidecarRecovery.d.ts +14 -0
  9. package/dist/assetSidecarRecovery.js +171 -0
  10. package/dist/assetTrust.d.ts +24 -0
  11. package/dist/assetTrust.js +218 -0
  12. package/dist/atp.js +4 -2
  13. package/dist/autoDistillLlm.d.ts +6 -0
  14. package/dist/autoDistillLlm.js +44 -7
  15. package/dist/autoexec.d.ts +14 -12
  16. package/dist/autoexec.js +84 -34
  17. package/dist/autoexecConfig.d.ts +10 -0
  18. package/dist/autoexecConfig.js +68 -0
  19. package/dist/cli.js +12 -5
  20. package/dist/cliContracts.js +30 -3
  21. package/dist/cliLifecycle.d.ts +7 -0
  22. package/dist/cliLifecycle.js +9 -0
  23. package/dist/cycleConsumer.d.ts +61 -1
  24. package/dist/cycleConsumer.js +551 -16
  25. package/dist/dashboard.d.ts +33 -0
  26. package/dist/dashboard.js +352 -0
  27. package/dist/dispatch.d.ts +10 -1
  28. package/dist/dispatch.js +40 -2
  29. package/dist/distillAdmission.d.ts +13 -0
  30. package/dist/distillAdmission.js +35 -0
  31. package/dist/distillObserver.js +6 -8
  32. package/dist/distillPrimitives.d.ts +9 -7
  33. package/dist/distillPrimitives.js +65 -12
  34. package/dist/doctor.d.ts +2 -0
  35. package/dist/doctor.js +49 -3
  36. package/dist/index.d.ts +8 -2
  37. package/dist/index.js +350 -42
  38. package/dist/issueReport.d.ts +7 -0
  39. package/dist/issueReport.js +291 -0
  40. package/dist/lifecycle.d.ts +22 -1
  41. package/dist/lifecycle.js +226 -29
  42. package/dist/localMemoryGraph.d.ts +97 -0
  43. package/dist/localMemoryGraph.js +889 -0
  44. package/dist/login.d.ts +20 -4
  45. package/dist/login.js +58 -8
  46. package/dist/materialPackage.d.ts +52 -0
  47. package/dist/materialPackage.js +401 -0
  48. package/dist/materialSnapshot.d.ts +54 -0
  49. package/dist/materialSnapshot.js +370 -0
  50. package/dist/memoryEventMirror.d.ts +23 -0
  51. package/dist/memoryEventMirror.js +140 -0
  52. package/dist/migrate/fieldMap.js +25 -0
  53. package/dist/migrate/v1Import.d.ts +7 -1
  54. package/dist/migrate/v1Import.js +132 -11
  55. package/dist/nonGitWorkspaceNotice.d.ts +24 -0
  56. package/dist/nonGitWorkspaceNotice.js +122 -0
  57. package/dist/proxyToken.d.ts +10 -0
  58. package/dist/proxyToken.js +80 -0
  59. package/dist/recipe.d.ts +12 -2
  60. package/dist/recipe.js +381 -8
  61. package/dist/reuse.d.ts +5 -3
  62. package/dist/reuse.js +126 -15
  63. package/dist/reuseReport.js +16 -16
  64. package/dist/runtimeCapabilities.d.ts +18 -0
  65. package/dist/runtimeCapabilities.js +81 -0
  66. package/dist/runtimeSessionSource.d.ts +10 -0
  67. package/dist/runtimeSessionSource.js +32 -5
  68. package/dist/setupHooks.d.ts +11 -1
  69. package/dist/setupHooks.js +235 -16
  70. package/dist/skill2gep.d.ts +38 -9
  71. package/dist/skill2gep.js +147 -14
  72. package/dist/skillDistill.d.ts +1 -0
  73. package/dist/skillDistill.js +4 -4
  74. package/dist/skillFetch.d.ts +18 -0
  75. package/dist/skillFetch.js +391 -0
  76. package/dist/solo/mode.js +5 -0
  77. package/dist/sync.d.ts +38 -0
  78. package/dist/sync.js +1981 -0
  79. package/dist/trajectoryExport.js +23 -12
  80. package/dist/v1Compat.d.ts +24 -0
  81. package/dist/v1Compat.js +249 -0
  82. package/dist/workflow.d.ts +39 -0
  83. package/dist/workflow.js +386 -0
  84. package/dist/workflowRuntime.d.ts +66 -0
  85. package/dist/workflowRuntime.js +631 -0
  86. package/package.json +12 -6
package/dist/lifecycle.js CHANGED
@@ -4,7 +4,7 @@ import { existsSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync }
4
4
  import { homedir } from 'node:os';
5
5
  import { basename, dirname, join } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
- import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
7
+ import { loadEnvFile, loadEnvFileFromEnv } from '@evomap/evolver-mcp';
8
8
  const requireFromHere = createRequire(import.meta.url);
9
9
  const DEFAULT_DAEMON_NAME = 'evolver-proxy';
10
10
  const DEFAULT_LABEL = 'com.evomap.evolver-proxy';
@@ -66,8 +66,14 @@ async function runLifecycleCommandInner(argv, deps) {
66
66
  case 'watch':
67
67
  return runWatch(paths, env, flags, stdout, stderr);
68
68
  case 'install-service': {
69
+ const requestedEnvFile = typeof flags['env-file'] === 'string' ? flags['env-file'] : undefined;
70
+ const envFileResult = requestedEnvFile
71
+ ? loadEnvFile(requestedEnvFile, env)
72
+ : loadEnvFileFromEnv(env);
73
+ if (envFileResult.error)
74
+ throw new Error('failed to load lifecycle environment file');
69
75
  const target = serviceTarget(flags);
70
- const result = installService(target, flags, env, deps.argv1 ?? process.argv[1]);
76
+ const result = await installService(target, flags, env, deps.argv1 ?? process.argv[1], deps.loadUnixRecoveryController);
71
77
  stdout(`${JSON.stringify(result, null, 2)}\n`);
72
78
  return 0;
73
79
  }
@@ -130,7 +136,7 @@ export async function startLifecycle(paths, env = process.env) {
130
136
  cwd,
131
137
  detached: true,
132
138
  stdio: ['ignore', out, err],
133
- env: { ...env },
139
+ env: oneShotChildEnv(env),
134
140
  windowsHide: true,
135
141
  });
136
142
  child.once('error', (err) => {
@@ -150,6 +156,11 @@ export async function startLifecycle(paths, env = process.env) {
150
156
  });
151
157
  return { status: 'started', pid: child.pid, logFile: paths.logFile };
152
158
  }
159
+ function oneShotChildEnv(env) {
160
+ const childEnv = { ...env };
161
+ delete childEnv['EVOLVER_SELF_UPDATE_SUPERVISOR'];
162
+ return childEnv;
163
+ }
153
164
  export function stopLifecycle(paths, deps = {}) {
154
165
  const pidFile = readPidFile(paths.pidFile);
155
166
  const pid = pidFile.pid;
@@ -216,16 +227,20 @@ export function lifecyclePaths(env = process.env) {
216
227
  const stateDir = env['EVOLVER_LIFECYCLE_STATE_DIR'] ?? join(home, 'lifecycle');
217
228
  const logDir = env['EVOLVER_LIFECYCLE_LOG_DIR'] ?? join(home, 'logs');
218
229
  const name = env['EVOLVER_LIFECYCLE_NAME'] ?? DEFAULT_DAEMON_NAME;
219
- const settingsHome = env['EVOLVER_SETTINGS_DIR'] ?? join(homedir(), '.evolver');
230
+ const settingsHome = nonBlankEnv(env, 'EVOLVER_SETTINGS_DIR') ?? join(homedir(), '.evolver');
220
231
  return {
221
232
  home,
222
233
  stateDir,
223
234
  logDir,
224
235
  pidFile: env['EVOLVER_LIFECYCLE_PID_FILE'] ?? join(stateDir, `${name}.pid`),
225
236
  logFile: env['EVOLVER_LIFECYCLE_LOG_FILE'] ?? join(logDir, `${name}.log`),
226
- settingsFile: env['EVOLVER_PROXY_SETTINGS_FILE'] ?? join(settingsHome, 'settings.json'),
237
+ settingsFile: nonBlankEnv(env, 'EVOLVER_PROXY_SETTINGS_FILE') ?? join(settingsHome, 'settings.json'),
227
238
  };
228
239
  }
240
+ function nonBlankEnv(env, key) {
241
+ const value = env[key]?.trim();
242
+ return value ? value : undefined;
243
+ }
229
244
  export function renderSystemdUnit(opts = {}) {
230
245
  return [
231
246
  '# Linux systemd user unit -- ~/.config/systemd/user/evolver-proxy.service',
@@ -240,6 +255,13 @@ export function renderSystemdUnit(opts = {}) {
240
255
  'Type=simple',
241
256
  `WorkingDirectory=${opts.workingDirectory ?? '%h'}`,
242
257
  ...(opts.envFile ? [`Environment="EVOLVER_ENV_FILE=${escapeSystemdEnvValue(opts.envFile)}"`] : []),
258
+ 'Environment="EVOLVER_SELF_UPDATE_SUPERVISOR=systemd"',
259
+ ...(opts.selfUpdateStateDir
260
+ ? [`Environment="EVOLVER_SELF_UPDATE_STATE_DIR=${escapeSystemdEnvValue(opts.selfUpdateStateDir)}"`]
261
+ : []),
262
+ ...(opts.selfUpdateTarget
263
+ ? [`Environment="EVOLVER_SELF_UPDATE_TARGET_PATH=${escapeSystemdEnvValue(opts.selfUpdateTarget)}"`]
264
+ : []),
243
265
  `ExecStart=${opts.execStart ?? defaultServiceExecStart()}`,
244
266
  'Restart=on-failure',
245
267
  'RestartSec=5s',
@@ -261,6 +283,7 @@ export function renderLaunchdPlist(opts = {}) {
261
283
  const workingDirectory = opts.workingDirectory ?? '/Users/YOU/your-project';
262
284
  const nodePath = opts.nodePath ?? '/usr/local/bin/node';
263
285
  const proxyBin = opts.proxyBin ?? '/Users/YOU/your-project/node_modules/@evomap/evolver-proxy/dist/bin/evolver-proxy.js';
286
+ const programArguments = opts.programArguments ?? [nodePath, proxyBin];
264
287
  const logDir = opts.logDir ?? '/Users/YOU/Library/Logs';
265
288
  const envFileBlock = opts.envFile ? ` <key>EVOLVER_ENV_FILE</key>\n <string>${escapeXml(opts.envFile)}</string>\n` : '';
266
289
  return [
@@ -272,14 +295,23 @@ export function renderLaunchdPlist(opts = {}) {
272
295
  ` <string>${DEFAULT_LABEL}</string>`,
273
296
  ' <key>ProgramArguments</key>',
274
297
  ' <array>',
275
- ` <string>${escapeXml(nodePath)}</string>`,
276
- ` <string>${escapeXml(proxyBin)}</string>`,
298
+ ...programArguments.map((argument) => ` <string>${escapeXml(argument)}</string>`),
277
299
  ' </array>',
278
300
  ' <key>WorkingDirectory</key>',
279
301
  ` <string>${escapeXml(workingDirectory)}</string>`,
280
302
  ' <key>EnvironmentVariables</key>',
281
303
  ' <dict>',
282
304
  envFileBlock.trimEnd(),
305
+ ' <key>EVOLVER_SELF_UPDATE_SUPERVISOR</key>',
306
+ ' <string>launchd</string>',
307
+ ...(opts.selfUpdateStateDir ? [
308
+ ' <key>EVOLVER_SELF_UPDATE_STATE_DIR</key>',
309
+ ` <string>${escapeXml(opts.selfUpdateStateDir)}</string>`,
310
+ ] : []),
311
+ ...(opts.selfUpdateTarget ? [
312
+ ' <key>EVOLVER_SELF_UPDATE_TARGET_PATH</key>',
313
+ ` <string>${escapeXml(opts.selfUpdateTarget)}</string>`,
314
+ ] : []),
283
315
  ' <key>PATH</key>',
284
316
  ' <string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin</string>',
285
317
  ' </dict>',
@@ -307,20 +339,23 @@ export function renderLaunchdPlist(opts = {}) {
307
339
  '',
308
340
  ].filter((line) => line !== '').join('\n');
309
341
  }
310
- export function renderWindowsInstaller() {
342
+ export function renderWindowsInstaller(defaults = {}) {
343
+ const ps = (value) => `'${(value ?? '').replaceAll("'", "''")}'`;
311
344
  return String.raw `param(
312
345
  [switch]$Install,
313
346
  [switch]$Uninstall,
314
347
  [string]$TaskName = 'EvoMapEvolverProxyDaemon',
315
- [string]$NodePath,
316
- [string]$ProxyBin,
317
- [string]$EnvFile
348
+ [string]$EvolverBin = ${ps(defaults.evolverBin)},
349
+ [string]$NodePath = ${ps(defaults.nodePath)},
350
+ [string]$ProxyBin = ${ps(defaults.proxyBin)},
351
+ [string]$EnvFile = ${ps(defaults.envFile)},
352
+ [string]$SelfUpdateStateDir = ${ps(defaults.selfUpdateStateDir)}
318
353
  )
319
354
 
320
355
  $ErrorActionPreference = 'Stop'
321
356
 
322
357
  if (-not ($Install -or $Uninstall)) {
323
- Write-Host 'Usage: install-evolver-proxy-windows.ps1 -Install [-NodePath ...] [-ProxyBin ...] [-EnvFile ...]'
358
+ Write-Host 'Usage: install-evolver-proxy-windows.ps1 -Install [-EvolverBin ... | -NodePath ... -ProxyBin ...] [-EnvFile ...]'
324
359
  Write-Host ' install-evolver-proxy-windows.ps1 -Uninstall [-TaskName ...]'
325
360
  exit 1
326
361
  }
@@ -333,31 +368,94 @@ if ($Uninstall) {
333
368
  exit 0
334
369
  }
335
370
 
336
- if (-not $NodePath) {
337
- $cmd = Get-Command node -ErrorAction SilentlyContinue
338
- if (-not $cmd) { Write-Error 'node.exe not on PATH; pass -NodePath explicitly.'; exit 1 }
339
- $NodePath = $cmd.Source
371
+ if (-not $EvolverBin) {
372
+ if (-not $NodePath) {
373
+ $cmd = Get-Command node -ErrorAction SilentlyContinue
374
+ if (-not $cmd) { Write-Error 'Pass -EvolverBin, or install node.exe / pass -NodePath.'; exit 1 }
375
+ $NodePath = $cmd.Source
376
+ }
377
+ if (-not $ProxyBin) { Write-Error 'Pass -EvolverBin, or -ProxyBin pointing at evolver-proxy.js.'; exit 1 }
378
+ if (-not (Test-Path $ProxyBin)) { Write-Error "Proxy bin not found at $ProxyBin"; exit 1 }
379
+ } elseif (-not (Test-Path $EvolverBin)) {
380
+ Write-Error "Evolver binary not found at $EvolverBin"; exit 1
381
+ }
382
+
383
+ if ($EvolverBin) {
384
+ if (-not $SelfUpdateStateDir) { $SelfUpdateStateDir = $env:EVOLVER_SELF_UPDATE_STATE_DIR }
385
+ if (-not $SelfUpdateStateDir) {
386
+ $SelfUpdateStateDir = Join-Path (Split-Path -Parent $EvolverBin) '.evolver-update'
387
+ }
388
+ }
389
+
390
+ foreach ($launcherValue in @($EvolverBin, $NodePath, $ProxyBin, $EnvFile, $SelfUpdateStateDir)) {
391
+ if ($launcherValue -match "[\r\n]") {
392
+ Write-Error 'Launcher paths must not contain line breaks.'
393
+ exit 1
394
+ }
395
+ }
396
+
397
+ if ($EvolverBin) {
398
+ $EvolverBin = [System.IO.Path]::GetFullPath($EvolverBin)
399
+ $SelfUpdateStateDir = [System.IO.Path]::GetFullPath($SelfUpdateStateDir)
400
+ # Service installation is the explicit upgrade boundary for the stable controller.
401
+ $existingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
402
+ if ($existingTask -and $existingTask.State -eq 'Running') {
403
+ Stop-ScheduledTask -TaskName $TaskName
404
+ $stopDeadline = [DateTime]::UtcNow.AddSeconds(15)
405
+ do {
406
+ Start-Sleep -Milliseconds 100
407
+ $existingTask = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
408
+ } while ($existingTask -and $existingTask.State -eq 'Running' -and [DateTime]::UtcNow -lt $stopDeadline)
409
+ if ($existingTask -and $existingTask.State -eq 'Running') {
410
+ Write-Error 'Existing Evolver Scheduled Task did not stop; refusing to replace its recovery controller.'
411
+ exit 1
412
+ }
413
+ }
414
+ $env:EVOLVER_SELF_UPDATE_STATE_DIR = $SelfUpdateStateDir
415
+ $env:EVOLVER_SELF_UPDATE_TARGET_PATH = $EvolverBin
416
+ & $EvolverBin 'proxy' '--evolver-windows-recovery-controller-provision'
417
+ if ($LASTEXITCODE -ne 0) {
418
+ Write-Error 'Failed to provision the stable Windows recovery controller.'
419
+ exit 1
420
+ }
340
421
  }
341
- if (-not $ProxyBin) { Write-Error 'Pass -ProxyBin pointing at evolver-proxy.js.'; exit 1 }
342
- if (-not (Test-Path $ProxyBin)) { Write-Error "Proxy bin not found at $ProxyBin"; exit 1 }
343
422
 
344
423
  $launcherDir = Join-Path $env:LOCALAPPDATA 'EvoMap'
345
424
  if (-not (Test-Path $launcherDir)) { New-Item -ItemType Directory -Path $launcherDir | Out-Null }
346
425
  $launcherPath = Join-Path $launcherDir 'evolver-proxy-task-launcher.vbs'
347
426
 
348
- $nodeEsc = $NodePath.Replace('"', '""')
349
- $proxyEsc = $ProxyBin.Replace('"', '""')
427
+ $nodeEsc = if ($NodePath) { $NodePath.Replace('"', '""') } else { '' }
428
+ $proxyEsc = if ($ProxyBin) { $ProxyBin.Replace('"', '""') } else { '' }
429
+ $evolverEsc = if ($EvolverBin) { $EvolverBin.Replace('"', '""') } else { '' }
350
430
  $envEsc = if ($EnvFile) { $EnvFile.Replace('"', '""') } else { '' }
431
+ $stateDirEsc = if ($SelfUpdateStateDir) { $SelfUpdateStateDir.Replace('"', '""') } else { '' }
351
432
 
352
433
  $launcherBody = @"
353
434
  ' AUTO-GENERATED by install-evolver-proxy-windows.ps1 -- do not edit.
354
435
  ' wscript.exe is a Windows-subsystem host. WshShell.Run(..., 0, True)
355
436
  ' launches node.exe hidden and waits so Task Scheduler sees the exit code.
356
- Dim WshShell, env, cmd, rc
437
+ Dim WshShell, env, fso, stateDir, pendingPath, updaterPath, controllerPath, controllerCmd, cmd, rc
357
438
  Set WshShell = CreateObject("WScript.Shell")
358
439
  Set env = WshShell.Environment("PROCESS")
440
+ Set fso = CreateObject("Scripting.FileSystemObject")
359
441
  If "$envEsc" <> "" Then env("EVOLVER_ENV_FILE") = "$envEsc"
360
- cmd = """$nodeEsc"" ""$proxyEsc"""
442
+ env("EVOLVER_SELF_UPDATE_SUPERVISOR") = "windows-scheduled-task"
443
+ If "$evolverEsc" <> "" Then
444
+ stateDir = "$stateDirEsc"
445
+ env("EVOLVER_SELF_UPDATE_STATE_DIR") = stateDir
446
+ env("EVOLVER_SELF_UPDATE_TARGET_PATH") = "$evolverEsc"
447
+ pendingPath = stateDir & "\windows-updater\pending.json"
448
+ updaterPath = stateDir & "\windows-updater\updater.exe"
449
+ controllerPath = stateDir & "\windows-controller\evolver-recovery-controller.exe"
450
+ cmd = """$evolverEsc"" proxy"
451
+ If Not fso.FileExists(controllerPath) Then WScript.Quit 1
452
+ If fso.FileExists(pendingPath) And Not fso.FileExists(updaterPath) Then WScript.Quit 1
453
+ controllerCmd = """" & controllerPath & """ proxy --evolver-windows-recovery-controller"
454
+ rc = WshShell.Run(controllerCmd, 0, True)
455
+ WScript.Quit rc
456
+ Else
457
+ cmd = """$nodeEsc"" ""$proxyEsc"""
458
+ End If
361
459
  rc = WshShell.Run(cmd, 0, True)
362
460
  WScript.Quit rc
363
461
  "@
@@ -396,31 +494,86 @@ function serviceTarget(flags) {
396
494
  return value;
397
495
  throw new Error('missing or invalid --target (expected: launchd|systemd|windows)');
398
496
  }
399
- function installService(target, flags, env, argv1) {
497
+ async function installService(target, flags, env, argv1, loadUnixRecoveryController = () => import('@evomap/evolver-proxy')) {
400
498
  const dryRun = flags['dry-run'] === true;
401
499
  const envFile = typeof flags['env-file'] === 'string' ? flags['env-file'] : env['EVOLVER_ENV_FILE'];
500
+ const supervised = configuredSelfUpdateTarget(env)
501
+ ? resolveDaemonCommand(env, process.execPath, argv1)
502
+ : resolveSelfUpdatingExecutable(process.execPath, argv1);
503
+ const standaloneTarget = supervised?.args.length === 1 && supervised.args[0] === 'proxy'
504
+ ? supervised.command
505
+ : undefined;
506
+ let unixController;
507
+ let unixControllerStateDir;
508
+ if (target !== 'windows' && standaloneTarget) {
509
+ const { provisionStableUnixRecoveryController, stableUnixRecoveryControllerPathForTarget, UNIX_RECOVERY_CONTROLLER_ARG, } = await loadUnixRecoveryController();
510
+ const stateDir = env['EVOLVER_SELF_UPDATE_STATE_DIR']?.trim() || undefined;
511
+ const controllerPath = dryRun
512
+ ? stableUnixRecoveryControllerPathForTarget(standaloneTarget, stateDir)
513
+ : await provisionStableUnixRecoveryController({
514
+ env: { ...env, EVOLVER_SELF_UPDATE_TARGET_PATH: standaloneTarget },
515
+ processExecPath: standaloneTarget,
516
+ });
517
+ unixController = {
518
+ command: controllerPath,
519
+ args: ['proxy', UNIX_RECOVERY_CONTROLLER_ARG],
520
+ display: `${controllerPath} proxy ${UNIX_RECOVERY_CONTROLLER_ARG}`,
521
+ };
522
+ unixControllerStateDir = dirname(dirname(controllerPath));
523
+ }
524
+ const serviceCommand = unixController ?? supervised;
402
525
  if (target === 'systemd') {
403
526
  const path = expandHome('~/.config/systemd/user/evolver-proxy.service');
404
- const unit = renderSystemdUnit({ envFile, workingDirectory: typeof flags['cwd'] === 'string' ? flags['cwd'] : undefined });
527
+ const unit = renderSystemdUnit({
528
+ envFile,
529
+ workingDirectory: typeof flags['cwd'] === 'string' ? flags['cwd'] : undefined,
530
+ ...(serviceCommand
531
+ ? { execStart: [serviceCommand.command, ...serviceCommand.args].map(quoteSystemdArg).join(' ') }
532
+ : {}),
533
+ ...(standaloneTarget ? { selfUpdateTarget: standaloneTarget } : {}),
534
+ ...(unixControllerStateDir ? { selfUpdateStateDir: unixControllerStateDir } : {}),
535
+ });
405
536
  if (!dryRun)
406
537
  writeTextFile(path, unit, 0o644);
407
- return { status: dryRun ? 'rendered' : 'installed', files: [path], service: 'systemd-user' };
538
+ return {
539
+ status: dryRun ? 'rendered' : 'installed',
540
+ files: [path, ...(unixController ? [unixController.command] : [])],
541
+ service: 'systemd-user',
542
+ };
408
543
  }
409
544
  if (target === 'launchd') {
410
545
  const path = expandHome('~/Library/LaunchAgents/com.evomap.evolver-proxy.plist');
411
546
  const plist = renderLaunchdPlist({
412
547
  envFile,
413
548
  workingDirectory: typeof flags['cwd'] === 'string' ? flags['cwd'] : process.cwd(),
549
+ ...(serviceCommand
550
+ ? { programArguments: [serviceCommand.command, ...serviceCommand.args] }
551
+ : {}),
552
+ ...(standaloneTarget ? { selfUpdateTarget: standaloneTarget } : {}),
553
+ ...(unixControllerStateDir ? { selfUpdateStateDir: unixControllerStateDir } : {}),
414
554
  nodePath: resolveStableNodePath(),
415
555
  proxyBin: resolveProxyBinPath() ?? (argv1?.startsWith('/') ? argv1 : undefined) ?? '/ABSOLUTE/PATH/TO/evolver-proxy.js',
416
556
  logDir: join(homedir(), 'Library', 'Logs'),
417
557
  });
418
558
  if (!dryRun)
419
559
  writeTextFile(path, plist, 0o644);
420
- return { status: dryRun ? 'rendered' : 'installed', files: [path], service: 'launchd' };
560
+ return {
561
+ status: dryRun ? 'rendered' : 'installed',
562
+ files: [path, ...(unixController ? [unixController.command] : [])],
563
+ service: 'launchd',
564
+ };
421
565
  }
422
566
  const path = expandHome('~/install-evolver-proxy-windows.ps1');
423
- const script = renderWindowsInstaller();
567
+ const selfUpdateStateDir = env['EVOLVER_SELF_UPDATE_STATE_DIR']?.trim();
568
+ const standalone = standaloneTarget;
569
+ const script = renderWindowsInstaller({
570
+ ...(standalone ? { evolverBin: standalone } : {
571
+ nodePath: resolveStableNodePath(),
572
+ proxyBin: resolveProxyBinPath(),
573
+ }),
574
+ ...(envFile ? { envFile } : {}),
575
+ ...(selfUpdateStateDir ? { selfUpdateStateDir } : {}),
576
+ });
424
577
  if (!dryRun)
425
578
  writeTextFile(path, script, 0o644);
426
579
  return { status: dryRun ? 'rendered' : 'installed', files: [path], service: 'windows-scheduled-task' };
@@ -465,19 +618,63 @@ async function runWatch(paths, env, flags, stdout, stderr) {
465
618
  stdout(`[Watch] Supervisor running every ${Math.round(intervalMs / 1000)}s. Ctrl-C to stop.\n`);
466
619
  return new Promise(() => { });
467
620
  }
468
- function resolveDaemonCommand(env) {
621
+ export function resolveDaemonCommand(env, execPath = process.execPath, argv1 = process.argv[1]) {
469
622
  const explicit = env['EVOLVER_LIFECYCLE_COMMAND']?.trim();
623
+ const selfUpdateTarget = configuredSelfUpdateTarget(env);
624
+ if (selfUpdateTarget) {
625
+ const supervised = standaloneProxyCommand(selfUpdateTarget);
626
+ if (explicit) {
627
+ const parsed = repairUnquotedWindowsExePath(explicit, parseCommandLine(explicit));
628
+ if (!matchesStandaloneProxyCommand(parsed, selfUpdateTarget)) {
629
+ throw new Error('EVOLVER_LIFECYCLE_COMMAND must invoke EVOLVER_SELF_UPDATE_TARGET_PATH with only the "proxy" argument; refusing mismatched self-update supervision');
630
+ }
631
+ }
632
+ return supervised;
633
+ }
470
634
  if (explicit) {
471
635
  const parsed = repairUnquotedWindowsExePath(explicit, parseCommandLine(explicit));
472
636
  if (parsed.length === 0)
473
637
  throw new Error('EVOLVER_LIFECYCLE_COMMAND is empty');
474
638
  return { command: parsed[0], args: parsed.slice(1), display: explicit };
475
639
  }
640
+ const selfExecutable = resolveSelfUpdatingExecutable(execPath, argv1);
641
+ if (selfExecutable)
642
+ return selfExecutable;
476
643
  const proxyBin = resolveProxyBinPath();
477
644
  if (proxyBin)
478
- return { command: process.execPath, args: [proxyBin], display: `${process.execPath} ${proxyBin}` };
645
+ return { command: execPath, args: [proxyBin], display: `${execPath} ${proxyBin}` };
479
646
  return { command: DEFAULT_DAEMON_NAME, args: [], display: DEFAULT_DAEMON_NAME };
480
647
  }
648
+ function configuredSelfUpdateTarget(env) {
649
+ const target = env['EVOLVER_SELF_UPDATE_TARGET_PATH']?.trim();
650
+ return target || undefined;
651
+ }
652
+ function standaloneProxyCommand(targetPath) {
653
+ return { command: targetPath, args: ['proxy'], display: `${targetPath} proxy` };
654
+ }
655
+ function matchesStandaloneProxyCommand(parsed, targetPath) {
656
+ return parsed.length === 2
657
+ && sameExecutablePath(parsed[0], targetPath)
658
+ && parsed[1] === 'proxy';
659
+ }
660
+ function sameExecutablePath(left, right) {
661
+ if (left === right)
662
+ return true;
663
+ if (process.platform !== 'win32')
664
+ return false;
665
+ const normalizeWindowsPath = (value) => value.replaceAll('/', '\\').toLowerCase();
666
+ return normalizeWindowsPath(left) === normalizeWindowsPath(right);
667
+ }
668
+ export function resolveSelfUpdatingExecutable(execPath, argv1) {
669
+ const executableName = basename(execPath).toLowerCase();
670
+ if (/^evolver(?:\.exe|-(?:darwin-(?:arm64|x64)|linux-(?:arm64|x64)|windows-x64\.exe))?$/.test(executableName)) {
671
+ return { command: execPath, args: ['proxy'], display: `${execPath} proxy` };
672
+ }
673
+ if (argv1 && basename(argv1).toLowerCase() === 'cli.js') {
674
+ return { command: execPath, args: [argv1, 'proxy'], display: `${execPath} ${argv1} proxy` };
675
+ }
676
+ return undefined;
677
+ }
481
678
  export function resolveProxyBinPath() {
482
679
  try {
483
680
  const entry = requireFromHere.resolve('@evomap/evolver-proxy');
@@ -0,0 +1,97 @@
1
+ import { type UserInfo } from 'node:os';
2
+ import { algo } from '@evomap/evolver-core';
3
+ export interface LocalMemoryGraphOptions {
4
+ dir: string;
5
+ userId: string;
6
+ legacyUserIds?: readonly string[];
7
+ now?: () => number;
8
+ maxActiveBytes?: number;
9
+ maxTailBytes?: number;
10
+ maxLineBytes?: number;
11
+ maxCompactBytes?: number;
12
+ maxCompactEdges?: number;
13
+ archiveRetention?: number;
14
+ }
15
+ export declare function resolveLocalMemoryUserId(info?: Pick<UserInfo<string>, 'uid' | 'username' | 'homedir'>): string;
16
+ export declare function resolveLocalMemoryUserIdentity(graphDir: string, info?: Pick<UserInfo<string>, 'uid' | 'username' | 'homedir'>): {
17
+ userId: string;
18
+ legacyUserIds: string[];
19
+ };
20
+ export interface MemoryGraphMaintenanceReport {
21
+ rotated: boolean;
22
+ compactedRecords: number;
23
+ corruptLines: number;
24
+ oversizedLines: number;
25
+ archives: number;
26
+ recovery: 'healthy' | 'degraded' | 'recovered' | 'empty';
27
+ }
28
+ export interface MemoryGraphHealthReport {
29
+ recovery: MemoryGraphMaintenanceReport['recovery'];
30
+ compactedRecords: number;
31
+ activeRecords: number;
32
+ corruptLines: number;
33
+ oversizedLines: number;
34
+ oversizedFiles: number;
35
+ archives: number;
36
+ busy?: boolean;
37
+ }
38
+ export interface MemoryGraphOperatorStatus extends MemoryGraphHealthReport {
39
+ selectionReason?: string;
40
+ }
41
+ export declare class MemoryGraphImportStateRejectedError extends Error {
42
+ constructor();
43
+ }
44
+ export declare class MemoryGraphBusyError extends Error {
45
+ constructor();
46
+ }
47
+ export declare class LocalMemoryGraph implements algo.MemoryGraphProvider {
48
+ private readonly dir;
49
+ private readonly userScope;
50
+ private readonly readableUserScopes;
51
+ private readonly now;
52
+ private readonly maxActiveBytes;
53
+ private readonly maxTailBytes;
54
+ private readonly maxLineBytes;
55
+ private readonly maxCompactBytes;
56
+ private readonly maxCompactEdges;
57
+ private readonly archiveRetention;
58
+ private readonly importedFingerprints;
59
+ constructor(options: LocalMemoryGraphOptions);
60
+ query(input: algo.MemoryGraphQueryInput): algo.MemoryGraphAdvice;
61
+ recordOutcome(input: algo.MemoryGraphRecordInput): void;
62
+ importV1Outcome(workspace: string, raw: unknown, source?: string): boolean;
63
+ maintain(): MemoryGraphMaintenanceReport;
64
+ private maintainUnlocked;
65
+ recoverFromArchives(): MemoryGraphMaintenanceReport;
66
+ private recoverFromArchivesUnlocked;
67
+ inspectHealth(): MemoryGraphHealthReport;
68
+ private inspectHealthUnlocked;
69
+ private withGraphLock;
70
+ private importStateFingerprint;
71
+ private appendRecordUnlocked;
72
+ private rotateAndCompactUnlocked;
73
+ private compactRequiresRecovery;
74
+ private readQueryableRecords;
75
+ private readImportRecords;
76
+ private readCompact;
77
+ private readWholeBounded;
78
+ private readTail;
79
+ private readTailFromFd;
80
+ private readRawTail;
81
+ private parseBuffer;
82
+ private writeCompact;
83
+ private writeAtomic;
84
+ private ensureSecureDir;
85
+ private secureRegularFile;
86
+ private workspaceScope;
87
+ private archiveFiles;
88
+ private nextArchivePath;
89
+ private pruneArchives;
90
+ private writeRecoveryMarker;
91
+ private hasRecoveryMarker;
92
+ private clearRecoveryMarker;
93
+ private readRawBounded;
94
+ }
95
+ export declare function sanitizeMemoryGraphSelectionReason(value: unknown): string | undefined;
96
+ export declare function formatMemoryGraphOperatorStatus(status: MemoryGraphOperatorStatus): string;
97
+ export declare function loadMemoryGraphOperatorStatus(env?: Record<string, string | undefined>): MemoryGraphOperatorStatus;