Skip to content

Commit d2bcbca

Browse files
IM.codesclaude
andcommitted
fix: move P2P discussion files to ~/.imcodes/discussions/ for persistence
/tmp is cleared on reboot. Discussion context files now stored under ~/.imcodes/discussions/ so history is preserved across daemon restarts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b200e4c commit d2bcbca

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/daemon/p2p-orchestrator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export function listP2pRuns(): P2pRun[] { return [...activeRuns.values()]; }
6666

6767
// ── Constants ─────────────────────────────────────────────────────────────
6868

69-
const P2P_TMP_DIR = '/tmp/imcodes-p2p';
69+
import { homedir } from 'node:os';
70+
const P2P_DIR = join(homedir(), '.imcodes', 'discussions');
7071
let IDLE_POLL_MS = 3_000;
7172

7273
/** Override poll interval for tests. */
@@ -142,8 +143,8 @@ export async function startP2pRun(
142143
const now = new Date().toISOString();
143144

144145
// Create temp context file
145-
await mkdir(P2P_TMP_DIR, { recursive: true });
146-
const contextFilePath = join(P2P_TMP_DIR, `${runId}.md`);
146+
await mkdir(P2P_DIR, { recursive: true });
147+
const contextFilePath = join(P2P_DIR, `${runId}.md`);
147148

148149
let seed = `# P2P Discussion: ${runId}\n\n`;
149150
seed += `## User Request\n\n${userText}\n\n`;

test/daemon/p2p-orchestrator.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ beforeEach(() => {
131131
// then firing an idle hook after a short delay
132132
sendKeysDelayedEnterMock.mockImplementation(async (session: string, prompt: string) => {
133133
// Extract the context file path from the prompt and append a section
134-
const pathMatch = prompt.match(/\/tmp\/imcodes-p2p\/[^\s]+\.md/);
134+
const pathMatch = prompt.match(/\/[^\s]*\.imcodes\/discussions\/[^\s]+\.md/);
135135
if (pathMatch) {
136136
const { appendFile } = await import('node:fs/promises');
137137
await appendFile(pathMatch[0], `\n## Output from ${session}\n\nSome analysis.\n`);
@@ -148,7 +148,9 @@ afterEach(async () => {
148148
_setIdlePollMs(3_000); // restore default
149149
// Clean up temp files
150150
const { rm } = await import('node:fs/promises');
151-
await rm('/tmp/imcodes-p2p', { recursive: true, force: true }).catch(() => {});
151+
const { homedir } = await import('node:os');
152+
const { join } = await import('node:path');
153+
await rm(join(homedir(), '.imcodes', 'discussions'), { recursive: true, force: true }).catch(() => {});
152154
});
153155

154156
// =============================================================================
@@ -771,7 +773,7 @@ describe('Group 12: Completion Detection', () => {
771773
detectStatusMock.mockReturnValue('thinking');
772774

773775
sendKeysDelayedEnterMock.mockImplementation(async (_session: string, prompt: string) => {
774-
const pathMatch = prompt.match(/\/tmp\/imcodes-p2p\/[^\s]+\.md/);
776+
const pathMatch = prompt.match(/\/[^\s]*\.imcodes\/discussions\/[^\s]+\.md/);
775777
if (pathMatch) {
776778
const { appendFile } = await import('node:fs/promises');
777779
await appendFile(pathMatch[0], '\n## Growing\nContent.\n');

0 commit comments

Comments
 (0)