MCPcopy Create free account
hub / github.com/EvoMap/evolver / runInjection

Function runInjection

src/adapters/scripts/evolver-session-start.js:513–569  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

511}
512
513function runInjection() {
514 if (shouldSkipInjection()) {
515 process.stdout.write(JSON.stringify({}));
516 return;
517 }
518
519 const currentDir = resolveProjectDir();
520
521 // Non-git notice: evolver records nothing in a non-git folder (outcomes come
522 // from git diffs), so tell the user — once per folder per TTL — instead of
523 // failing silently. Emitted regardless of whether any memory exists below.
524 const parts = [];
525 if (!isGitWorkspace(currentDir) && !throttled('nongit:' + currentDir, NON_GIT_NOTICE_TTL_MS, getNoticeStatePath())) {
526 parts.push(NON_GIT_NOTICE);
527 }
528
529 const evolverRoot = findEvolverRoot();
530
531 // Attempt to restart the daemon in the background if it has died since the
532 // last session (idle-death / macOS sleep / OOM). Fire-and-forget: errors are
533 // swallowed and this never delays the JSON output below.
534 _maybeRestartDaemon(evolverRoot);
535
536 const graphPath = findMemoryGraph(evolverRoot);
537
538 // Scope to the current workspace BEFORE trimming to the most-recent window,
539 // so other projects sharing the user-level fallback graph can't crowd this
540 // workspace's outcomes out of view. When the workspace id can't be resolved,
541 // belongsToWorkspace() falls back to "show it" — no regression vs. the old
542 // unscoped behavior.
543 if (graphPath) {
544 const currentId = resolveWorkspaceId(evolverRoot, currentDir);
545 const recent = readRecentWorkspaceEntries(graphPath, currentId, currentDir, 5);
546 const filtered = filterRelevantOutcomes(recent);
547 if (filtered.length > 0) {
548 const successCount = filtered.filter(e => e.outcome && e.outcome.status === 'success').length;
549 const failCount = filtered.filter(e => e.outcome && e.outcome.status === 'failed').length;
550 parts.push([
551 `[Evolution Memory] Recent ${filtered.length} outcomes (${successCount} success, ${failCount} failed):`,
552 ...filtered.map(formatOutcome),
553 '',
554 'Use successful approaches. Avoid repeating failed patterns.',
555 ].join('\n'));
556 }
557 }
558
559 if (parts.length === 0) {
560 process.stdout.write(JSON.stringify({}));
561 return;
562 }
563
564 const out = parts.join('\n\n');
565 process.stdout.write(JSON.stringify({
566 agent_message: out,
567 additionalContext: out,
568 }));
569}
570

Callers 1

finishWithInputFunction · 0.85

Calls 11

shouldSkipInjectionFunction · 0.85
resolveProjectDirFunction · 0.85
isGitWorkspaceFunction · 0.85
throttledFunction · 0.85
getNoticeStatePathFunction · 0.85
findEvolverRootFunction · 0.85
_maybeRestartDaemonFunction · 0.85
findMemoryGraphFunction · 0.85
resolveWorkspaceIdFunction · 0.85
filterRelevantOutcomesFunction · 0.85

Tested by

no test coverage detected