Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refactor: break the cos.js re-export import cycle (#5684)

Adam Eivy086786c42a7f
diff --git a/server/services/agentImportCycles.test.js b/server/services/agentImportCycles.test.js
index d1221732e0..6ff9d04924 100644
--- a/server/services/agentImportCycles.test.js
+++ b/server/services/agentImportCycles.test.js
@@ -473,6 +473,25 @@ describe('agent lifecycle cluster — no static import cycles (#2837)', () => {
expect(graph.get('agents.js')).toContain('agentOrchestrator.js');
});
+ it('keeps cos.js out of every static import cycle (#5684)', () => {
+ // cos.js re-exports cosState/cosTaskStore for backward compat with
+ // `import * as cos`. Two leaf services used to reach THROUGH that barrel for
+ // one symbol each (memoryEmbeddings -> getConfig, character -> getAllTasks),
+ // and because cos.js transitively reaches the CoS tool registry -> voice
+ // tools -> askService -> both of those leaves, each one-symbol forward closed
+ // a 7-module ring. Both now import the DECLARING module, which is the same
+ // rule the transition-caller guard above enforces for the agent cluster.
+ const offending = findCycles(graph).filter(cycle => cycle.split(' -> ').includes('cos.js'));
+ expect(offending, `cos.js is back in a static import cycle:\n${offending.join('\n')}`).toEqual([]);
+
+ // Name the two back-edges directly, so a reintroduced one-symbol import of
+ // the barrel fails with the reason rather than as an opaque ring.
+ expect(graph.get('memoryEmbeddings.js'), 'memoryEmbeddings must import getConfig from cosState.js').not.toContain('cos.js');
+ expect(graph.get('memoryEmbeddings.js')).toContain('cosState.js');
+ expect(graph.get('character.js'), 'character must import getAllTasks from cosTaskStore.js').not.toContain('cos.js');
+ expect(graph.get('character.js')).toContain('cosTaskStore.js');
+ });
+
it('no longer needs the dynamic-import workaround for handleOrphanedTask', () => {
// The cycle-dodge this issue was filed for: agentLifecycle reached
// agentManagement via `await import()` because agentManagement imported it back.
diff --git a/server/services/character.js b/server/services/character.js
index 16d0371686..9b0ddaaf2b 100644
--- a/server/services/character.js
+++ b/server/services/character.js
@@ -17,7 +17,7 @@ import crypto from 'crypto';
import path from 'path';
import { atomicWrite, ensureDir, readJSONFile, PATHS, sleep } from '../lib/fileUtils.js';
import * as jiraService from './jira.js';
-import * as cosService from './cos.js';
+import { getAllTasks } from './cosTaskStore.js';
import { getBirthDateStrict } from './meatspace.js';
import { getCharacterSkills } from './characterSkills.js';
import { getCharacterMetrics } from './characterMetrics.js';
@@ -424,7 +424,7 @@ export async function syncJiraXP() {
export async function syncTaskXP() {
const character = await loadRawCharacter();
- const { user: userTasks, cos: cosTasks } = await cosService.getAllTasks();
+ const { user: userTasks, cos: cosTasks } = await getAllTasks();
let totalXP = 0;
let taskCount = 0;
diff --git a/server/services/character.test.js b/server/services/character.test.js
index eccb0be6b9..cccc28202d 100644
--- a/server/services/character.test.js
+++ b/server/services/character.test.js
@@ -33,7 +33,9 @@ const FAKE_METRICS = [{ id: 'recordsCreated', label: 'Records Created', unit: 'c
// registries were handed the SAME one (the whole point of #2676's read-once contract).
const FAKE_READ = vi.hoisted(() => vi.fn());
vi.mock('./jira.js', () => ({}));
-vi.mock('./cos.js', () => ({}));
+// character.js reaches cosTaskStore for the one symbol it uses (getAllTasks); syncTaskXP
+// is not exercised here, so the stub only has to satisfy the static import.
+vi.mock('./cosTaskStore.js', () => ({ getAllTasks: async () => ({ user: { tasks: [] }, cos: { tasks: [] } }) }));
vi.mock('./characterSkills.js', () => ({
getCharacterSkills: vi.fn(async () => FAKE_SKILLS),
}));
diff --git a/server/services/memoryEmbeddings.js b/server/services/memoryEmbeddings.js
index 6bb16fd6c2..df79db0973 100644
--- a/server/services/memoryEmbeddings.js
+++ b/server/services/memoryEmbeddings.js
@@ -7,7 +7,7 @@
import { DEFAULT_MEMORY_CONFIG } from './memoryBackend.js';
import { getProviderById } from './providers.js';
-import { getConfig as getCosConfig } from './cos.js';
+import { getConfig as getCosConfig } from './cosState.js';
import { fetchWithTimeout } from '../lib/fetchWithTimeout.js';
import { readResponseJson } from '../lib/readResponseJson.js';
import { estimateTokens, CHARS_PER_TOKEN } from '../lib/contextBudget.js';
diff --git a/server/services/memoryEmbeddings.test.js b/server/services/memoryEmbeddings.test.js
index 08e9239c0e..b2d7ccb63b 100644
--- a/server/services/memoryEmbeddings.test.js
+++ b/server/services/memoryEmbeddings.test.js
@@ -5,7 +5,7 @@ const getCosConfig = vi.fn();
const getProviderById = vi.fn();
const summarizeForEmbedding = vi.fn();
-vi.mock('./cos.js', () => ({ getConfig: getCosConfig }));
+vi.mock('./cosState.js', () => ({ getConfig: getCosConfig }));
vi.mock('./providers.js', () => ({ getProviderById }));
// generateMemoryEmbedding dynamically imports this for over-budget records.
vi.mock('./memorySummarizer.js', () => ({ summarizeForEmbedding }));