refactor: codebase audit cleanup — dead code, dedup, module splits
Multi-agent audit + aggressive cleanup across server/web/coder/booterm, delivered behind a DEFER discipline so none of the in-flight files were touched. Removes dead code/deps/columns, dedups server + coder helpers, and splits the oversized modules (tools.ts, opencode-server.ts, sentinel-summaries, turn.ts, TerminalPane.tsx) behind stable contracts. Adds 78 parity/unit tests (server 587, coder 323); fixes two latent bugs (ChatPane queue keys, FileViewerOverlay blank-line parity). Intended tag: v2.7.12-audit-cleanup. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -24,12 +24,12 @@ import { TOOLS_BY_NAME } from './tools.js';
|
||||
import { streamCompletion } from './inference/stream-phase.js';
|
||||
import { SYNTHESIS_SYSTEM_PROMPT } from './synthesisPrompt.js';
|
||||
import { insertParts } from './inference/parts.js';
|
||||
import * as modelContext from './model-context.js';
|
||||
import { finalizeStreamedRow } from './inference/error-handler.js';
|
||||
import { readTruncation } from './truncate.js';
|
||||
|
||||
import type { Session } from '../types/api.js';
|
||||
import type { OpenAiMessage } from './inference/payload.js';
|
||||
import type { InferenceContext, TurnArgs } from './inference/turn.js';
|
||||
import type { InferenceContext, TurnArgs } from './inference/types.js';
|
||||
|
||||
export const SYNTHESIS_TOOLS: ReadonlySet<string> = new Set([
|
||||
'get_codebase_overview',
|
||||
@@ -192,44 +192,28 @@ export async function runSynthesisPass(p: SynthesisParams): Promise<boolean> {
|
||||
combinedSignal,
|
||||
);
|
||||
|
||||
const mctx = await modelContext.getModelContext(p.session.model);
|
||||
const nCtx = mctx?.n_ctx ?? null;
|
||||
const [updated] = await p.ctx.sql<
|
||||
{
|
||||
tokens_used: number | null;
|
||||
ctx_used: number | null;
|
||||
ctx_max: number | null;
|
||||
finished_at: string | null;
|
||||
}[]
|
||||
>`
|
||||
UPDATE messages
|
||||
SET content = ${streamResult.content},
|
||||
status = 'complete',
|
||||
tokens_used = ${streamResult.completionTokens},
|
||||
ctx_used = ${streamResult.promptTokens},
|
||||
ctx_max = ${nCtx},
|
||||
finished_at = clock_timestamp()
|
||||
WHERE id = ${synthMessageId}
|
||||
RETURNING tokens_used, ctx_used, ctx_max, finished_at
|
||||
`;
|
||||
await insertParts(p.ctx.sql, [
|
||||
{
|
||||
message_id: synthMessageId,
|
||||
sequence: 0,
|
||||
kind: 'synthesis',
|
||||
payload: { text: streamResult.content },
|
||||
},
|
||||
]);
|
||||
p.ctx.publish(p.args.sessionId, {
|
||||
type: 'message_complete',
|
||||
message_id: synthMessageId,
|
||||
chat_id: p.args.chatId,
|
||||
tokens_used: updated?.tokens_used ?? null,
|
||||
ctx_used: updated?.ctx_used ?? null,
|
||||
ctx_max: updated?.ctx_max ?? null,
|
||||
started_at: startedAt,
|
||||
finished_at: updated?.finished_at ?? null,
|
||||
// P5: the n_ctx lookup + complete UPDATE + message_complete frame are the
|
||||
// shared success-finalize atom (finalizeStreamedRow). beforeComplete writes
|
||||
// the kind='synthesis' part in the original order (UPDATE → insertParts →
|
||||
// message_complete), preserving timing exactly.
|
||||
await finalizeStreamedRow(p.ctx, {
|
||||
sessionId: p.args.sessionId,
|
||||
chatId: p.args.chatId,
|
||||
messageId: synthMessageId,
|
||||
model: p.session.model,
|
||||
content: streamResult.content,
|
||||
completionTokens: streamResult.completionTokens,
|
||||
promptTokens: streamResult.promptTokens,
|
||||
startedAt,
|
||||
beforeComplete: () =>
|
||||
insertParts(p.ctx.sql, [
|
||||
{
|
||||
message_id: synthMessageId!,
|
||||
sequence: 0,
|
||||
kind: 'synthesis',
|
||||
payload: { text: streamResult.content },
|
||||
},
|
||||
]),
|
||||
});
|
||||
p.ctx.publishUser({
|
||||
type: 'chat_status',
|
||||
|
||||
Reference in New Issue
Block a user