refactor: reorganized exports and removed obsolete helper branches
- Removed export leakage by demoting many helper and const symbols to module-local scope. - Renamed underscore-prefixed internals and cache fields, then updated related references and `satisfies never` checks. - Deleted obsolete logic branches and helpers, including harmony-stream interruption flow and unused benchmark runtime helpers. - Updated Biome config and manifests by broadening lint coverage and removing an unused `@napi-rs/cli` dev dependency. - Adjusted tests and utilities to use renamed test helpers and remove redundant private test-only helpers/locals.
This commit is contained in:
@@ -1,52 +1,16 @@
|
||||
import type { ThinkingLevel } from "@oh-my-pi/pi-agent-core";
|
||||
import type { Api, AssistantMessage, Model } from "@oh-my-pi/pi-ai";
|
||||
import { completeSimple, validateToolCall } from "@oh-my-pi/pi-ai";
|
||||
import type { Api, Model } from "@oh-my-pi/pi-ai";
|
||||
import { completeSimple } from "@oh-my-pi/pi-ai";
|
||||
import { prompt } from "@oh-my-pi/pi-utils";
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import analysisSystemPrompt from "../../commit/prompts/analysis-system.md" with { type: "text" };
|
||||
import analysisUserPrompt from "../../commit/prompts/analysis-user.md" with { type: "text" };
|
||||
import type { ChangelogCategory, ConventionalAnalysis } from "../../commit/types";
|
||||
import type { ConventionalAnalysis } from "../../commit/types";
|
||||
import { toReasoningEffort } from "../../thinking";
|
||||
import { extractTextContent, extractToolCall, normalizeAnalysis, parseJsonPayload } from "../utils";
|
||||
import { createConventionalAnalysisTool, parseConventionalAnalysisResponse } from "../shared-llm";
|
||||
|
||||
const ConventionalAnalysisTool = {
|
||||
name: "create_conventional_analysis",
|
||||
description: "Analyze a diff and return conventional commit classification.",
|
||||
parameters: Type.Object({
|
||||
type: Type.Union([
|
||||
Type.Literal("feat"),
|
||||
Type.Literal("fix"),
|
||||
Type.Literal("refactor"),
|
||||
Type.Literal("docs"),
|
||||
Type.Literal("test"),
|
||||
Type.Literal("chore"),
|
||||
Type.Literal("style"),
|
||||
Type.Literal("perf"),
|
||||
Type.Literal("build"),
|
||||
Type.Literal("ci"),
|
||||
Type.Literal("revert"),
|
||||
]),
|
||||
scope: Type.Union([Type.String(), Type.Null()]),
|
||||
details: Type.Array(
|
||||
Type.Object({
|
||||
text: Type.String(),
|
||||
changelog_category: Type.Optional(
|
||||
Type.Union([
|
||||
Type.Literal("Added"),
|
||||
Type.Literal("Changed"),
|
||||
Type.Literal("Fixed"),
|
||||
Type.Literal("Deprecated"),
|
||||
Type.Literal("Removed"),
|
||||
Type.Literal("Security"),
|
||||
Type.Literal("Breaking Changes"),
|
||||
]),
|
||||
),
|
||||
user_visible: Type.Optional(Type.Boolean()),
|
||||
}),
|
||||
),
|
||||
issue_refs: Type.Array(Type.String()),
|
||||
}),
|
||||
};
|
||||
const ConventionalAnalysisTool = createConventionalAnalysisTool(
|
||||
"Analyze a diff and return conventional commit classification.",
|
||||
);
|
||||
|
||||
export interface ConventionalAnalysisInput {
|
||||
model: Model<Api>;
|
||||
@@ -96,27 +60,5 @@ export async function generateConventionalAnalysis({
|
||||
{ apiKey, maxTokens: 2400, reasoning: toReasoningEffort(thinkingLevel) },
|
||||
);
|
||||
|
||||
return parseAnalysisFromResponse(response);
|
||||
}
|
||||
|
||||
function parseAnalysisFromResponse(message: AssistantMessage): ConventionalAnalysis {
|
||||
const toolCall = extractToolCall(message, "create_conventional_analysis");
|
||||
if (toolCall) {
|
||||
const parsed = validateToolCall([ConventionalAnalysisTool], toolCall) as {
|
||||
type: ConventionalAnalysis["type"];
|
||||
scope: string | null;
|
||||
details: Array<{ text: string; changelog_category?: ChangelogCategory; user_visible?: boolean }>;
|
||||
issue_refs: string[];
|
||||
};
|
||||
return normalizeAnalysis(parsed);
|
||||
}
|
||||
|
||||
const text = extractTextContent(message);
|
||||
const parsed = parseJsonPayload(text) as {
|
||||
type: ConventionalAnalysis["type"];
|
||||
scope: string | null;
|
||||
details: Array<{ text: string; changelog_category?: ChangelogCategory; user_visible?: boolean }>;
|
||||
issue_refs: string[];
|
||||
};
|
||||
return normalizeAnalysis(parsed);
|
||||
return parseConventionalAnalysisResponse(response, ConventionalAnalysisTool);
|
||||
}
|
||||
|
||||
@@ -1,52 +1,14 @@
|
||||
import type { ThinkingLevel } from "@oh-my-pi/pi-agent-core";
|
||||
import type { Api, AssistantMessage, Model } from "@oh-my-pi/pi-ai";
|
||||
import { completeSimple, validateToolCall } from "@oh-my-pi/pi-ai";
|
||||
import type { Api, Model } from "@oh-my-pi/pi-ai";
|
||||
import { completeSimple } from "@oh-my-pi/pi-ai";
|
||||
import { prompt } from "@oh-my-pi/pi-utils";
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import reduceSystemPrompt from "../../commit/prompts/reduce-system.md" with { type: "text" };
|
||||
import reduceUserPrompt from "../../commit/prompts/reduce-user.md" with { type: "text" };
|
||||
import type { ChangelogCategory, ConventionalAnalysis, FileObservation } from "../../commit/types";
|
||||
import type { ConventionalAnalysis, FileObservation } from "../../commit/types";
|
||||
import { toReasoningEffort } from "../../thinking";
|
||||
import { extractTextContent, extractToolCall, normalizeAnalysis, parseJsonPayload } from "../utils";
|
||||
import { createConventionalAnalysisTool, parseConventionalAnalysisResponse } from "../shared-llm";
|
||||
|
||||
const ReduceTool = {
|
||||
name: "create_conventional_analysis",
|
||||
description: "Synthesize file observations into a conventional commit analysis.",
|
||||
parameters: Type.Object({
|
||||
type: Type.Union([
|
||||
Type.Literal("feat"),
|
||||
Type.Literal("fix"),
|
||||
Type.Literal("refactor"),
|
||||
Type.Literal("docs"),
|
||||
Type.Literal("test"),
|
||||
Type.Literal("chore"),
|
||||
Type.Literal("style"),
|
||||
Type.Literal("perf"),
|
||||
Type.Literal("build"),
|
||||
Type.Literal("ci"),
|
||||
Type.Literal("revert"),
|
||||
]),
|
||||
scope: Type.Union([Type.String(), Type.Null()]),
|
||||
details: Type.Array(
|
||||
Type.Object({
|
||||
text: Type.String(),
|
||||
changelog_category: Type.Optional(
|
||||
Type.Union([
|
||||
Type.Literal("Added"),
|
||||
Type.Literal("Changed"),
|
||||
Type.Literal("Fixed"),
|
||||
Type.Literal("Deprecated"),
|
||||
Type.Literal("Removed"),
|
||||
Type.Literal("Security"),
|
||||
Type.Literal("Breaking Changes"),
|
||||
]),
|
||||
),
|
||||
user_visible: Type.Optional(Type.Boolean()),
|
||||
}),
|
||||
),
|
||||
issue_refs: Type.Array(Type.String()),
|
||||
}),
|
||||
};
|
||||
const ReduceTool = createConventionalAnalysisTool("Synthesize file observations into a conventional commit analysis.");
|
||||
|
||||
export interface ReducePhaseInput {
|
||||
model: Model<Api>;
|
||||
@@ -83,26 +45,5 @@ export async function runReducePhase({
|
||||
{ apiKey, maxTokens: 2400, reasoning: toReasoningEffort(thinkingLevel) },
|
||||
);
|
||||
|
||||
return parseAnalysisResponse(response);
|
||||
}
|
||||
|
||||
function parseAnalysisResponse(message: AssistantMessage): ConventionalAnalysis {
|
||||
const toolCall = extractToolCall(message, "create_conventional_analysis");
|
||||
if (toolCall) {
|
||||
const parsed = validateToolCall([ReduceTool], toolCall) as {
|
||||
type: ConventionalAnalysis["type"];
|
||||
scope: string | null;
|
||||
details: Array<{ text: string; changelog_category?: ChangelogCategory; user_visible?: boolean }>;
|
||||
issue_refs: string[];
|
||||
};
|
||||
return normalizeAnalysis(parsed);
|
||||
}
|
||||
const text = extractTextContent(message);
|
||||
const parsed = parseJsonPayload(text) as {
|
||||
type: ConventionalAnalysis["type"];
|
||||
scope: string | null;
|
||||
details: Array<{ text: string; changelog_category?: ChangelogCategory; user_visible?: boolean }>;
|
||||
issue_refs: string[];
|
||||
};
|
||||
return normalizeAnalysis(parsed);
|
||||
return parseConventionalAnalysisResponse(response, ReduceTool);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ import type { CommitCommandArgs, ConventionalAnalysis } from "./types";
|
||||
|
||||
const SUMMARY_MAX_CHARS = 72;
|
||||
const RECENT_COMMITS_COUNT = 8;
|
||||
let _typesDescription: string | undefined;
|
||||
const TYPES_DESCRIPTION = (): string => (_typesDescription ??= prompt.render(typesDescriptionPrompt));
|
||||
let typesDescription: string | undefined;
|
||||
const TYPES_DESCRIPTION = (): string => (typesDescription ??= prompt.render(typesDescriptionPrompt));
|
||||
|
||||
/**
|
||||
* Execute the omp commit pipeline for staged changes.
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import type { AssistantMessage } from "@oh-my-pi/pi-ai";
|
||||
import { validateToolCall } from "@oh-my-pi/pi-ai";
|
||||
import { Type } from "@sinclair/typebox";
|
||||
import type { ChangelogCategory, ConventionalAnalysis } from "./types";
|
||||
import { extractTextContent, extractToolCall, normalizeAnalysis, parseJsonPayload } from "./utils";
|
||||
|
||||
/**
|
||||
* Shared TypeBox schema for the `create_conventional_analysis` tool used by
|
||||
* both the single-pass analysis call and the map-reduce reduce phase. Schemas
|
||||
* are identical across phases — only the surrounding tool `description`
|
||||
* differs to reflect the input the phase is summarizing.
|
||||
*/
|
||||
export const conventionalAnalysisParameters = Type.Object({
|
||||
type: Type.Union([
|
||||
Type.Literal("feat"),
|
||||
Type.Literal("fix"),
|
||||
Type.Literal("refactor"),
|
||||
Type.Literal("docs"),
|
||||
Type.Literal("test"),
|
||||
Type.Literal("chore"),
|
||||
Type.Literal("style"),
|
||||
Type.Literal("perf"),
|
||||
Type.Literal("build"),
|
||||
Type.Literal("ci"),
|
||||
Type.Literal("revert"),
|
||||
]),
|
||||
scope: Type.Union([Type.String(), Type.Null()]),
|
||||
details: Type.Array(
|
||||
Type.Object({
|
||||
text: Type.String(),
|
||||
changelog_category: Type.Optional(
|
||||
Type.Union([
|
||||
Type.Literal("Added"),
|
||||
Type.Literal("Changed"),
|
||||
Type.Literal("Fixed"),
|
||||
Type.Literal("Deprecated"),
|
||||
Type.Literal("Removed"),
|
||||
Type.Literal("Security"),
|
||||
Type.Literal("Breaking Changes"),
|
||||
]),
|
||||
),
|
||||
user_visible: Type.Optional(Type.Boolean()),
|
||||
}),
|
||||
),
|
||||
issue_refs: Type.Array(Type.String()),
|
||||
});
|
||||
|
||||
export interface ConventionalAnalysisTool {
|
||||
name: "create_conventional_analysis";
|
||||
description: string;
|
||||
parameters: typeof conventionalAnalysisParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a `create_conventional_analysis` tool descriptor. Phase-specific
|
||||
* `description` text is the only thing that varies between callers.
|
||||
*/
|
||||
export function createConventionalAnalysisTool(description: string): ConventionalAnalysisTool {
|
||||
return {
|
||||
name: "create_conventional_analysis",
|
||||
description,
|
||||
parameters: conventionalAnalysisParameters,
|
||||
};
|
||||
}
|
||||
|
||||
interface ParsedConventionalAnalysis {
|
||||
type: ConventionalAnalysis["type"];
|
||||
scope: string | null;
|
||||
details: Array<{ text: string; changelog_category?: ChangelogCategory; user_visible?: boolean }>;
|
||||
issue_refs: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a {@link ConventionalAnalysis} from an assistant response, preferring
|
||||
* a structured tool call and falling back to JSON embedded in text content.
|
||||
*/
|
||||
export function parseConventionalAnalysisResponse(
|
||||
message: AssistantMessage,
|
||||
tool: ConventionalAnalysisTool,
|
||||
): ConventionalAnalysis {
|
||||
const toolCall = extractToolCall(message, tool.name);
|
||||
if (toolCall) {
|
||||
const parsed = validateToolCall([tool], toolCall) as ParsedConventionalAnalysis;
|
||||
return normalizeAnalysis(parsed);
|
||||
}
|
||||
const text = extractTextContent(message);
|
||||
const parsed = parseJsonPayload(text) as ParsedConventionalAnalysis;
|
||||
return normalizeAnalysis(parsed);
|
||||
}
|
||||
Reference in New Issue
Block a user