remove excessive file writes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mikefreno/ralpi",
|
"name": "@mikefreno/ralpi",
|
||||||
"version": "0.1.5",
|
"version": "0.1.7",
|
||||||
"description": "Execute tasks from task files/PRD's using DAG-based dependency resolution with persistent progress tracking",
|
"description": "Execute tasks from task files/PRD's using DAG-based dependency resolution with persistent progress tracking",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"pi-package",
|
"pi-package",
|
||||||
|
|||||||
@@ -155,7 +155,6 @@ export async function runTask(
|
|||||||
durationMs: number;
|
durationMs: number;
|
||||||
toolUsage?: ToolUsage;
|
toolUsage?: ToolUsage;
|
||||||
outputPreview?: string;
|
outputPreview?: string;
|
||||||
sessionFile?: string;
|
|
||||||
commitMessages?: string[];
|
commitMessages?: string[];
|
||||||
commitSummary?: string;
|
commitSummary?: string;
|
||||||
}> {
|
}> {
|
||||||
@@ -169,12 +168,6 @@ export async function runTask(
|
|||||||
config.prompts.projectContext,
|
config.prompts.projectContext,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Write prompt to .ralpi/ with timestamp (for debugging)
|
|
||||||
const ralpiDir = path.join(projectDir, ".ralpi");
|
|
||||||
ensureDir(ralpiDir);
|
|
||||||
const promptFile = path.join(ralpiDir, `prompt-${startMs}.md`);
|
|
||||||
writeFileSafe(promptFile, prompt);
|
|
||||||
|
|
||||||
const taskHeader = `${task.id} · ${task.title}`;
|
const taskHeader = `${task.id} · ${task.title}`;
|
||||||
|
|
||||||
// When running in parallel, all tasks share a single widget so ordering
|
// When running in parallel, all tasks share a single widget so ordering
|
||||||
@@ -262,11 +255,6 @@ export async function runTask(
|
|||||||
// Use task-level timeout if set, otherwise fall back to config
|
// Use task-level timeout if set, otherwise fall back to config
|
||||||
const timeoutMs = task.timeoutMs ?? config.execution.timeoutMs;
|
const timeoutMs = task.timeoutMs ?? config.execution.timeoutMs;
|
||||||
|
|
||||||
// Pre-create session file path so events stream to disk (avoids 300+ MB in-memory accumulation)
|
|
||||||
const sessionsDir = path.join(ralpiDir, "sessions");
|
|
||||||
ensureDir(sessionsDir);
|
|
||||||
const sessionFilePath = path.join(sessionsDir, `${task.id}-${startMs}.txt`);
|
|
||||||
|
|
||||||
// Run task asynchronously via Pi SDK — event loop stays responsive
|
// Run task asynchronously via Pi SDK — event loop stays responsive
|
||||||
const output = await runAgentSession(
|
const output = await runAgentSession(
|
||||||
prompt,
|
prompt,
|
||||||
@@ -291,7 +279,6 @@ export async function runTask(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
undefined, // no abort signal
|
undefined, // no abort signal
|
||||||
sessionFilePath, // stream events to file
|
|
||||||
assignedModel ?? config.model,
|
assignedModel ?? config.model,
|
||||||
config.thinkingLevel,
|
config.thinkingLevel,
|
||||||
);
|
);
|
||||||
@@ -318,7 +305,6 @@ export async function runTask(
|
|||||||
success: false,
|
success: false,
|
||||||
error: output.error,
|
error: output.error,
|
||||||
durationMs,
|
durationMs,
|
||||||
sessionFile: sessionFilePath, // events streamed to file for debugging
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,13 +314,10 @@ export async function runTask(
|
|||||||
// Capture git commits made during this task
|
// Capture git commits made during this task
|
||||||
const { commitMessages, commitSummary } = captureGitCommits(projectDir);
|
const { commitMessages, commitSummary } = captureGitCommits(projectDir);
|
||||||
|
|
||||||
// Session file already written by runAgentSession (events streamed to disk)
|
|
||||||
const sessionFile = sessionFilePath;
|
|
||||||
|
|
||||||
// Build output preview (first 500 chars of agent text)
|
// Build output preview (first 500 chars of agent text)
|
||||||
const outputPreview =
|
const outputPreview =
|
||||||
agentText.length > 500
|
agentText.length > 500
|
||||||
? agentText.slice(0, 500) + "\n... (truncated, see session file)"
|
? agentText.slice(0, 500) + "\n... (truncated)"
|
||||||
: agentText;
|
: agentText;
|
||||||
|
|
||||||
// Extract reflection from agent output
|
// Extract reflection from agent output
|
||||||
@@ -350,7 +333,6 @@ export async function runTask(
|
|||||||
durationMs,
|
durationMs,
|
||||||
toolUsage,
|
toolUsage,
|
||||||
outputPreview,
|
outputPreview,
|
||||||
sessionFile,
|
|
||||||
commitMessages,
|
commitMessages,
|
||||||
commitSummary,
|
commitSummary,
|
||||||
};
|
};
|
||||||
@@ -702,7 +684,6 @@ async function executeTask(
|
|||||||
result.durationMs,
|
result.durationMs,
|
||||||
result.reflection,
|
result.reflection,
|
||||||
result.toolUsage,
|
result.toolUsage,
|
||||||
result.sessionFile,
|
|
||||||
result.outputPreview,
|
result.outputPreview,
|
||||||
result.commitMessages,
|
result.commitMessages,
|
||||||
result.commitSummary,
|
result.commitSummary,
|
||||||
|
|||||||
@@ -171,7 +171,6 @@ export class ProgressTracker {
|
|||||||
durationMs: number,
|
durationMs: number,
|
||||||
reflection?: Reflection,
|
reflection?: Reflection,
|
||||||
toolUsage?: ToolUsage,
|
toolUsage?: ToolUsage,
|
||||||
sessionFile?: string,
|
|
||||||
outputPreview?: string,
|
outputPreview?: string,
|
||||||
commitMessages?: string[],
|
commitMessages?: string[],
|
||||||
commitSummary?: string,
|
commitSummary?: string,
|
||||||
@@ -183,7 +182,6 @@ export class ProgressTracker {
|
|||||||
prd.tasks[taskId].durationMs = durationMs;
|
prd.tasks[taskId].durationMs = durationMs;
|
||||||
if (reflection) prd.tasks[taskId].reflection = reflection;
|
if (reflection) prd.tasks[taskId].reflection = reflection;
|
||||||
if (toolUsage) prd.tasks[taskId].toolUsage = toolUsage;
|
if (toolUsage) prd.tasks[taskId].toolUsage = toolUsage;
|
||||||
if (sessionFile) prd.tasks[taskId].sessionFile = sessionFile;
|
|
||||||
if (outputPreview) prd.tasks[taskId].outputPreview = outputPreview;
|
if (outputPreview) prd.tasks[taskId].outputPreview = outputPreview;
|
||||||
if (commitMessages) prd.tasks[taskId].commitMessages = commitMessages;
|
if (commitMessages) prd.tasks[taskId].commitMessages = commitMessages;
|
||||||
if (commitSummary) prd.tasks[taskId].commitSummary = commitSummary;
|
if (commitSummary) prd.tasks[taskId].commitSummary = commitSummary;
|
||||||
|
|||||||
@@ -97,8 +97,6 @@ export interface TaskProgressInfo {
|
|||||||
error?: string;
|
error?: string;
|
||||||
/** Tool usage counts from parsed subprocess output */
|
/** Tool usage counts from parsed subprocess output */
|
||||||
toolUsage?: ToolUsage;
|
toolUsage?: ToolUsage;
|
||||||
/** Path to session output file */
|
|
||||||
sessionFile?: string;
|
|
||||||
/** Truncated output preview for expanded view */
|
/** Truncated output preview for expanded view */
|
||||||
outputPreview?: string;
|
outputPreview?: string;
|
||||||
/** Git commit messages from task execution */
|
/** Git commit messages from task execution */
|
||||||
|
|||||||
24
src/utils.ts
24
src/utils.ts
@@ -432,7 +432,6 @@ export async function runAgentSession(
|
|||||||
timeoutMs: number,
|
timeoutMs: number,
|
||||||
onEvent?: (event: AgentSessionEvent) => void,
|
onEvent?: (event: AgentSessionEvent) => void,
|
||||||
signal?: AbortSignal,
|
signal?: AbortSignal,
|
||||||
sessionFile?: string,
|
|
||||||
model?: unknown,
|
model?: unknown,
|
||||||
thinkingLevel?: unknown,
|
thinkingLevel?: unknown,
|
||||||
): Promise<{
|
): Promise<{
|
||||||
@@ -450,13 +449,6 @@ export async function runAgentSession(
|
|||||||
bash: 0,
|
bash: 0,
|
||||||
other: 0,
|
other: 0,
|
||||||
};
|
};
|
||||||
// Stream events to file instead of accumulating in memory.
|
|
||||||
// Accumulating caused "Invalid string length" crashes when
|
|
||||||
// JSON.stringify(output.events, null, 2) produced 300+ MB strings.
|
|
||||||
const eventStream = sessionFile
|
|
||||||
? fs.createWriteStream(sessionFile, { flags: "a" })
|
|
||||||
: null;
|
|
||||||
|
|
||||||
// Wire timeout via abort signal (only when set; 0 means inherit Pi's defaults)
|
// Wire timeout via abort signal (only when set; 0 means inherit Pi's defaults)
|
||||||
let timeoutHandle: NodeJS.Timeout | null = null;
|
let timeoutHandle: NodeJS.Timeout | null = null;
|
||||||
if (timeoutMs > 0) {
|
if (timeoutMs > 0) {
|
||||||
@@ -500,10 +492,6 @@ export async function runAgentSession(
|
|||||||
let stopReason: string | undefined;
|
let stopReason: string | undefined;
|
||||||
|
|
||||||
const unsubscribe = result.session.subscribe((event) => {
|
const unsubscribe = result.session.subscribe((event) => {
|
||||||
// Stream event to file (avoids accumulating 300+ MB in memory)
|
|
||||||
if (eventStream) {
|
|
||||||
eventStream.write(JSON.stringify(event) + "\n");
|
|
||||||
}
|
|
||||||
onEvent?.(event);
|
onEvent?.(event);
|
||||||
|
|
||||||
if (event.type === "message_end") {
|
if (event.type === "message_end") {
|
||||||
@@ -540,11 +528,6 @@ export async function runAgentSession(
|
|||||||
signal?.removeEventListener("abort", abortHandler);
|
signal?.removeEventListener("abort", abortHandler);
|
||||||
if (timeoutHandle) clearTimeout(timeoutHandle);
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
||||||
|
|
||||||
// Flush and close the event stream before returning
|
|
||||||
if (eventStream) {
|
|
||||||
await new Promise<void>((resolve) => eventStream.end(resolve));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (errorMessage && !finalText) {
|
if (errorMessage && !finalText) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -561,19 +544,16 @@ export async function runAgentSession(
|
|||||||
text: finalText.trim(),
|
text: finalText.trim(),
|
||||||
toolUsage,
|
toolUsage,
|
||||||
stopReason,
|
stopReason,
|
||||||
events: [], // streamed to file
|
events: [],
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (timeoutHandle) clearTimeout(timeoutHandle);
|
if (timeoutHandle) clearTimeout(timeoutHandle);
|
||||||
if (eventStream && !eventStream.destroyed) {
|
|
||||||
eventStream.end();
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
text: "",
|
text: "",
|
||||||
error: error instanceof Error ? error.message : String(error),
|
error: error instanceof Error ? error.message : String(error),
|
||||||
toolUsage,
|
toolUsage,
|
||||||
events: [], // streamed to file
|
events: [],
|
||||||
};
|
};
|
||||||
} finally {
|
} finally {
|
||||||
sessionRef.session?.dispose();
|
sessionRef.session?.dispose();
|
||||||
|
|||||||
Reference in New Issue
Block a user