MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / recordTurn

Function recordTurn

packages/opencode-atomic-hooks/src/index.ts:186–318  ·  view source on GitHub ↗
(sessionID: string)

Source from the content-addressed store, hash-verified

184 };
185
186 const recordTurn = async (sessionID: string) => {
187 const state = ensure(sessionID);
188
189 if (!state.started) {
190 await hook(sessionID, "session-start", { source: "startup" });
191 state.started = true;
192 }
193
194 state.turnCount++;
195
196 const turnMsg = state.prompt
197 ? state.prompt.substring(0, 200)
198 : `Turn ${state.turnCount}`;
199
200 await hook(sessionID, "user-prompt", {
201 prompt: turnMsg,
202 ...(state.model ? { model: state.model } : {}),
203 ...(state.provider ? { provider: state.provider } : {}),
204 ...(state.agent ? { agent: state.agent } : {}),
205 });
206
207 for (const tc of state.completedTools) {
208 const extra: Record<string, unknown> = tc as any;
209 await hook(sessionID, "after-tool", {
210 tool_name: tc.tool,
211 tool_call_id: tc.callID,
212 status: tc.status,
213 duration: tc.startTime > 0 ? Date.now() - tc.startTime : undefined,
214 modified_files: [
215 "edit",
216 "write",
217 "multiedit",
218 "patch",
219 "create",
220 ].includes(tc.tool),
221 tool_input: tc.input,
222 tool_output: tc.output?.substring(0, 500),
223 // Rich metadata from tool.execute.after hook
224 ...(extra.title ? { title: extra.title } : {}),
225 ...(extra.filePath ? { file_path: extra.filePath } : {}),
226 ...(extra.filediff ? { filediff: extra.filediff } : {}),
227 ...(extra.diagnostics ? { diagnostics: extra.diagnostics } : {}),
228 ...(extra.exitCode !== undefined ? { exit_code: extra.exitCode } : {}),
229 });
230 }
231 state.completedTools = [];
232
233 // Build concatenated reasoning text and extract last signature
234 const reasoningText = state.turnReasoningBlocks
235 .map((b) => b.text)
236 .filter((t) => t.length > 0)
237 .join("\n---\n");
238 const lastSignature = [...state.turnReasoningBlocks]
239 .reverse()
240 .find((b) => b.signature)?.signature;
241 const totalReasoningDurationMs = state.turnReasoningBlocks.reduce(
242 (sum, b) => sum + b.durationMs,
243 0,

Callers 1

AtomicHooksPluginFunction · 0.85

Calls 5

ensureFunction · 0.85
includesMethod · 0.80
hookFunction · 0.70
logFunction · 0.70
reverseMethod · 0.45

Tested by

no test coverage detected