feat(cli): auto-init agent memory on first message [LET-7779] (#1231)

This commit is contained in:
Devansh Jain
2026-03-03 20:08:30 -08:00
committed by GitHub
parent 0d741d389d
commit a284a31f97
8 changed files with 245 additions and 3 deletions

View File

@@ -6,7 +6,9 @@
*/
import { execSync } from "node:child_process";
import { getMemoryFilesystemRoot } from "../../agent/memoryFilesystem";
import { SYSTEM_REMINDER_CLOSE, SYSTEM_REMINDER_OPEN } from "../../constants";
import { settingsManager } from "../../settings-manager";
import { getSnapshot as getSubagentSnapshot } from "./subagentState";
// ── Guard ──────────────────────────────────────────────────
@@ -107,6 +109,37 @@ Instructions:
`.trim();
}
/**
* Fire auto-init for a newly created agent.
* Returns true if init was spawned, false if skipped (guard / memfs disabled).
*/
export async function fireAutoInit(
agentId: string,
onComplete: (result: { success: boolean; error?: string }) => void,
): Promise<boolean> {
if (hasActiveInitSubagent()) return false;
if (!settingsManager.isMemfsEnabled(agentId)) return false;
const gitContext = gatherGitContext();
const initPrompt = buildMemoryInitRuntimePrompt({
agentId,
workingDirectory: process.cwd(),
memoryDir: getMemoryFilesystemRoot(agentId),
gitContext,
});
const { spawnBackgroundSubagentTask } = await import("../../tools/impl/Task");
spawnBackgroundSubagentTask({
subagentType: "init",
prompt: initPrompt,
description: "Initializing memory",
silentCompletion: true,
onComplete,
});
return true;
}
/** Message for the primary agent via processConversation (legacy non-MemFS path). */
export function buildLegacyInitMessage(args: {
gitContext: string;