MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / readTaskOutput

Function readTaskOutput

apps/vis/server/src/lib/task-store.ts:121–151  ·  view source on GitHub ↗
(
  agentDir: string,
  taskId: string,
  offset: number,
  maxBytes: number,
)

Source from the content-addressed store, hash-verified

119 * Mirrors agent-core's `readTaskOutputBytes` so large logs page identically.
120 */
121export async function readTaskOutput(
122 agentDir: string,
123 taskId: string,
124 offset: number,
125 maxBytes: number,
126): Promise<TaskOutputWindow> {
127 const start = Math.max(0, Math.trunc(offset));
128 const limit = Math.max(0, Math.trunc(maxBytes));
129 let handle;
130 try {
131 handle = await open(taskOutputFile(agentDir, taskId), 'r');
132 } catch {
133 return { offset: start, nextOffset: start, size: 0, content: '', eof: true };
134 }
135 try {
136 const size = (await handle.stat()).size;
137 if (limit === 0 || start >= size) {
138 return { offset: start, nextOffset: start, size, content: '', eof: start >= size };
139 }
140 const length = Math.min(limit, size - start);
141 const buffer = Buffer.allocUnsafe(length);
142 const { bytesRead } = await handle.read(buffer, 0, length, start);
143 const content = buffer.toString('utf-8', 0, bytesRead);
144 const nextOffset = start + bytesRead;
145 return { offset: start, nextOffset, size, content, eof: nextOffset >= size };
146 } catch {
147 return { offset: start, nextOffset: start, size: 0, content: '', eof: true };
148 } finally {
149 await handle.close();
150 }
151}
152
153// ── normalization (ported from agent-core/agent/background/persist.ts) ───────
154

Callers 2

task-store.test.tsFile · 0.90
tasksRouteFunction · 0.90

Calls 5

taskOutputFileFunction · 0.70
statMethod · 0.65
readMethod · 0.65
toStringMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected