Codemod db pass-through calls to domain modules: tasks + agents (C1 part 1/3)
Rewrite ~525 call sites from `db.<method>()` to `db.<module>.<method>()` for tasks and agents domains (including `getAgent`/`findAgent`/`getTask` which live on the `entityCrud` field). Delete the corresponding pass-through methods on AppDatabaseBase. Structural types that narrowed `db` to a bag of flat methods (CapabilityMatchDb, EscalationDeps, SweepStaleReviewsDeps) are reshaped to match the new namespace. Internal callback references inside database.ts/database-base.ts now invoke the owning module directly (e.g. `this.agents.saveAgent`) rather than the deleted pass-through. The codemod lives at scripts/codemod/remove-appdatabase-passthrough.mjs and filters by owning module + optional explicit method list. It is idempotent and does not re-rewrite already-namespaced calls.
This commit is contained in:
1 parent
411294afa6
commit
5e9b7acbc6
95 files changed
+1123
-793
No files matched your search
@@ -43,7 +43,7 @@ function scaffold(db: AppDatabase, connectorId: ConnectorId = "gemini-cli") {
|
||||
repoRef: "",
|
||||
isPrimary: true,
|
||||
});
|
||||
const agentId = db.saveAgent({
|
||||
const agentId = db.agents.saveAgent({
|
||||
companyId,
|
||||
name: "Worker Agent",
|
||||
role: "developer",
|
||||
@@ -72,7 +72,7 @@ function scaffold(db: AppDatabase, connectorId: ConnectorId = "gemini-cli") {
|
||||
status: "in_progress",
|
||||
targetDate: null,
|
||||
});
|
||||
const taskId = db.saveTask({
|
||||
const taskId = db.tasks.saveTask({
|
||||
companyId,
|
||||
projectId,
|
||||
goalId,
|
||||
@@ -114,7 +114,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
const sessionService = createSessionManagementService({ db, logger: mockLogger });
|
||||
|
||||
// Create a session
|
||||
const sessionId = db.createNewSession({
|
||||
const sessionId = db.tasks.createNewSession({
|
||||
companyId,
|
||||
agentId,
|
||||
adapterType: "gemini-cli",
|
||||
@@ -122,11 +122,11 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
|
||||
// Simulate runs until we reach the maxRuns threshold (20)
|
||||
for (let i = 0; i < 20; i++) {
|
||||
db.incrementSessionUsage(sessionId, 1000, 500, `run-${i}`);
|
||||
db.tasks.incrementSessionUsage(sessionId, 1000, 500, `run-${i}`);
|
||||
}
|
||||
|
||||
// Get the updated session from DB
|
||||
const session = db.getSessionById(sessionId);
|
||||
const session = db.tasks.getSessionById(sessionId);
|
||||
expect(session).not.toBeNull();
|
||||
expect(session!.runCount).toBe(20); // matches maxRuns threshold in session-management-service
|
||||
|
||||
@@ -140,16 +140,16 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
const { companyId, agentId, taskId } = scaffold(db);
|
||||
const sessionService = createSessionManagementService({ db, logger: mockLogger });
|
||||
|
||||
const sessionId = db.createNewSession({
|
||||
const sessionId = db.tasks.createNewSession({
|
||||
companyId,
|
||||
agentId,
|
||||
adapterType: "gemini-cli",
|
||||
});
|
||||
|
||||
// Accumulate tokens past the 500_000 maxTokens threshold in one big call
|
||||
db.incrementSessionUsage(sessionId, 300000, 250000, "big-run");
|
||||
db.tasks.incrementSessionUsage(sessionId, 300000, 250000, "big-run");
|
||||
|
||||
const session = db.getSessionById(sessionId);
|
||||
const session = db.tasks.getSessionById(sessionId);
|
||||
expect(session).not.toBeNull();
|
||||
const totalTokens = session!.totalInputTokens + session!.totalOutputTokens;
|
||||
expect(totalTokens).toBe(550000);
|
||||
@@ -163,7 +163,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
const { companyId, agentId, taskId, workspaceId } = scaffold(db);
|
||||
const sessionService = createSessionManagementService({ db, logger: mockLogger });
|
||||
|
||||
const sessionId = db.createNewSession({
|
||||
const sessionId = db.tasks.createNewSession({
|
||||
companyId,
|
||||
agentId,
|
||||
adapterType: "gemini-cli",
|
||||
@@ -171,7 +171,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
|
||||
// Accumulate enough to trigger rotation
|
||||
for (let i = 0; i < 20; i++) {
|
||||
db.incrementSessionUsage(sessionId, 1000, 500, `run-${i}`);
|
||||
db.tasks.incrementSessionUsage(sessionId, 1000, 500, `run-${i}`);
|
||||
}
|
||||
|
||||
// Create a completed run for history (so generateHandoff has run data)
|
||||
@@ -193,7 +193,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
unattributedCost: false,
|
||||
});
|
||||
|
||||
const session = db.getSessionById(sessionId)!;
|
||||
const session = db.tasks.getSessionById(sessionId)!;
|
||||
// generateHandoff is agent-scoped: it walks the agent's runs across
|
||||
// all tasks + taskless heartbeats, not a single task.
|
||||
const handoff = sessionService.generateHandoff(session);
|
||||
@@ -203,7 +203,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
expect(handoff).toContain("## Recent Run History");
|
||||
|
||||
// Archive the old session with handoff
|
||||
db.archiveSession(sessionId, "max_runs", handoff);
|
||||
db.tasks.archiveSession(sessionId, "max_runs", handoff);
|
||||
|
||||
// Verify archived session has handoff stored
|
||||
const archivedRows = db.queryAll<{ handoffMarkdown: string | null }>(
|
||||
@@ -217,27 +217,27 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
const { companyId, agentId, taskId } = scaffold(db);
|
||||
|
||||
// Create initial session
|
||||
const oldSessionId = db.createNewSession({
|
||||
const oldSessionId = db.tasks.createNewSession({
|
||||
companyId,
|
||||
agentId,
|
||||
adapterType: "gemini-cli",
|
||||
});
|
||||
|
||||
// Add usage to the old session
|
||||
db.incrementSessionUsage(oldSessionId, 300000, 250000, "run-final");
|
||||
db.tasks.incrementSessionUsage(oldSessionId, 300000, 250000, "run-final");
|
||||
|
||||
// Archive the old session
|
||||
db.archiveSession(oldSessionId, "max_tokens", "# Session Handoff\nPrevious work summary.");
|
||||
db.tasks.archiveSession(oldSessionId, "max_tokens", "# Session Handoff\nPrevious work summary.");
|
||||
|
||||
// Create new session
|
||||
const newSessionId = db.createNewSession({
|
||||
const newSessionId = db.tasks.createNewSession({
|
||||
companyId,
|
||||
agentId,
|
||||
adapterType: "gemini-cli",
|
||||
});
|
||||
|
||||
// Get the new active session
|
||||
const newSession = db.getSessionById(newSessionId);
|
||||
const newSession = db.tasks.getSessionById(newSessionId);
|
||||
expect(newSession).not.toBeNull();
|
||||
expect(newSession!.id).toBe(newSessionId);
|
||||
expect(newSession!.id).not.toBe(oldSessionId);
|
||||
@@ -252,7 +252,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
const { companyId, agentId, taskId } = scaffold(db, "gemini-cli");
|
||||
const sessionService = createSessionManagementService({ db, logger: mockLogger });
|
||||
|
||||
const sessionId = db.createNewSession({
|
||||
const sessionId = db.tasks.createNewSession({
|
||||
companyId,
|
||||
agentId,
|
||||
adapterType: "claude-pro",
|
||||
@@ -260,10 +260,10 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
|
||||
// Accumulate way past all thresholds
|
||||
for (let i = 0; i < 25; i++) {
|
||||
db.incrementSessionUsage(sessionId, 30000, 20000, `run-${i}`);
|
||||
db.tasks.incrementSessionUsage(sessionId, 30000, 20000, `run-${i}`);
|
||||
}
|
||||
|
||||
const session = db.getSessionById(sessionId)!;
|
||||
const session = db.tasks.getSessionById(sessionId)!;
|
||||
// Pi-mono delegates compaction to pi-agent-core; AgentCompany still applies rotation uniformly.
|
||||
const result = sessionService.evaluateRotation(session);
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
@@ -274,7 +274,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
const { companyId, agentId, taskId } = scaffold(db, "gemini-cli");
|
||||
const sessionService = createSessionManagementService({ db, logger: mockLogger });
|
||||
|
||||
const sessionId = db.createNewSession({
|
||||
const sessionId = db.tasks.createNewSession({
|
||||
companyId,
|
||||
agentId,
|
||||
adapterType: "openai-codex",
|
||||
@@ -282,10 +282,10 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
|
||||
// Accumulate way past all thresholds
|
||||
for (let i = 0; i < 25; i++) {
|
||||
db.incrementSessionUsage(sessionId, 30000, 20000, `run-${i}`);
|
||||
db.tasks.incrementSessionUsage(sessionId, 30000, 20000, `run-${i}`);
|
||||
}
|
||||
|
||||
const session = db.getSessionById(sessionId)!;
|
||||
const session = db.tasks.getSessionById(sessionId)!;
|
||||
// Pi-mono delegates compaction to pi-agent-core; AgentCompany still applies rotation uniformly.
|
||||
const result = sessionService.evaluateRotation(session);
|
||||
expect(result.shouldRotate).toBe(true);
|
||||
@@ -297,12 +297,12 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
const sessionService = createSessionManagementService({ db, logger: mockLogger });
|
||||
|
||||
// Create session and add usage
|
||||
const sessionId = db.createNewSession({
|
||||
const sessionId = db.tasks.createNewSession({
|
||||
companyId,
|
||||
agentId,
|
||||
adapterType: "gemini-cli",
|
||||
});
|
||||
db.incrementSessionUsage(sessionId, 300000, 200000, "run-1");
|
||||
db.tasks.incrementSessionUsage(sessionId, 300000, 200000, "run-1");
|
||||
|
||||
// Create a completed run for run history
|
||||
const run = db.createRun({
|
||||
@@ -324,7 +324,7 @@ describe("Edge Case: Session Rotation During Execution (D-05.3)", () => {
|
||||
});
|
||||
|
||||
// Rotate the session (archives old, creates new)
|
||||
const oldSession = db.getSessionById(sessionId)!;
|
||||
const oldSession = db.tasks.getSessionById(sessionId)!;
|
||||
sessionService.rotateSession(oldSession);
|
||||
|
||||
// After rotation, the handoff should be retrievable for the next run
|
||||
|
||||
Reference in new issue
Block a user