@oh-my-pi/pi-coding-agent 8.0.20 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +105 -0
- package/package.json +14 -11
- package/scripts/generate-wasm-b64.ts +24 -0
- package/src/capability/context-file.ts +1 -1
- package/src/capability/extension-module.ts +1 -1
- package/src/capability/extension.ts +1 -1
- package/src/capability/hook.ts +1 -1
- package/src/capability/instruction.ts +1 -1
- package/src/capability/mcp.ts +1 -1
- package/src/capability/prompt.ts +1 -1
- package/src/capability/rule.ts +1 -1
- package/src/capability/settings.ts +1 -1
- package/src/capability/skill.ts +1 -1
- package/src/capability/slash-command.ts +1 -1
- package/src/capability/ssh.ts +1 -1
- package/src/capability/system-prompt.ts +1 -1
- package/src/capability/tool.ts +1 -1
- package/src/cli/args.ts +1 -1
- package/src/cli/plugin-cli.ts +1 -5
- package/src/commit/agentic/agent.ts +309 -0
- package/src/commit/agentic/fallback.ts +96 -0
- package/src/commit/agentic/index.ts +359 -0
- package/src/commit/agentic/prompts/analyze-file.md +22 -0
- package/src/commit/agentic/prompts/session-user.md +26 -0
- package/src/commit/agentic/prompts/split-confirm.md +1 -0
- package/src/commit/agentic/prompts/system.md +40 -0
- package/src/commit/agentic/state.ts +74 -0
- package/src/commit/agentic/tools/analyze-file.ts +131 -0
- package/src/commit/agentic/tools/git-file-diff.ts +194 -0
- package/src/commit/agentic/tools/git-hunk.ts +50 -0
- package/src/commit/agentic/tools/git-overview.ts +84 -0
- package/src/commit/agentic/tools/index.ts +56 -0
- package/src/commit/agentic/tools/propose-changelog.ts +128 -0
- package/src/commit/agentic/tools/propose-commit.ts +154 -0
- package/src/commit/agentic/tools/recent-commits.ts +81 -0
- package/src/commit/agentic/tools/split-commit.ts +284 -0
- package/src/commit/agentic/topo-sort.ts +44 -0
- package/src/commit/agentic/trivial.ts +51 -0
- package/src/commit/agentic/validation.ts +200 -0
- package/src/commit/analysis/conventional.ts +169 -0
- package/src/commit/analysis/index.ts +4 -0
- package/src/commit/analysis/scope.ts +242 -0
- package/src/commit/analysis/summary.ts +114 -0
- package/src/commit/analysis/validation.ts +66 -0
- package/src/commit/changelog/detect.ts +36 -0
- package/src/commit/changelog/generate.ts +112 -0
- package/src/commit/changelog/index.ts +233 -0
- package/src/commit/changelog/parse.ts +44 -0
- package/src/commit/cli.ts +93 -0
- package/src/commit/git/diff.ts +148 -0
- package/src/commit/git/errors.ts +11 -0
- package/src/commit/git/index.ts +217 -0
- package/src/commit/git/operations.ts +53 -0
- package/src/commit/index.ts +5 -0
- package/src/commit/map-reduce/.map-phase.ts.kate-swp +0 -0
- package/src/commit/map-reduce/index.ts +63 -0
- package/src/commit/map-reduce/map-phase.ts +193 -0
- package/src/commit/map-reduce/reduce-phase.ts +147 -0
- package/src/commit/map-reduce/utils.ts +9 -0
- package/src/commit/message.ts +11 -0
- package/src/commit/model-selection.ts +84 -0
- package/src/commit/pipeline.ts +242 -0
- package/src/commit/prompts/analysis-system.md +155 -0
- package/src/commit/prompts/analysis-user.md +41 -0
- package/src/commit/prompts/changelog-system.md +56 -0
- package/src/commit/prompts/changelog-user.md +19 -0
- package/src/commit/prompts/file-observer-system.md +26 -0
- package/src/commit/prompts/file-observer-user.md +9 -0
- package/src/commit/prompts/reduce-system.md +60 -0
- package/src/commit/prompts/reduce-user.md +17 -0
- package/src/commit/prompts/summary-retry.md +4 -0
- package/src/commit/prompts/summary-system.md +52 -0
- package/src/commit/prompts/summary-user.md +13 -0
- package/src/commit/prompts/types-description.md +2 -0
- package/src/commit/types.ts +109 -0
- package/src/commit/utils/exclusions.ts +42 -0
- package/src/config/file-lock.ts +111 -0
- package/src/config/model-registry.ts +16 -7
- package/src/config/settings-manager.ts +115 -40
- package/src/config.ts +5 -5
- package/src/discovery/agents-md.ts +1 -1
- package/src/discovery/builtin.ts +1 -1
- package/src/discovery/claude.ts +1 -1
- package/src/discovery/cline.ts +1 -1
- package/src/discovery/codex.ts +1 -1
- package/src/discovery/cursor.ts +1 -1
- package/src/discovery/gemini.ts +1 -1
- package/src/discovery/github.ts +1 -1
- package/src/discovery/index.ts +11 -11
- package/src/discovery/mcp-json.ts +1 -1
- package/src/discovery/ssh.ts +1 -1
- package/src/discovery/vscode.ts +1 -1
- package/src/discovery/windsurf.ts +1 -1
- package/src/extensibility/custom-commands/loader.ts +1 -1
- package/src/extensibility/custom-commands/types.ts +1 -1
- package/src/extensibility/custom-tools/loader.ts +1 -1
- package/src/extensibility/custom-tools/types.ts +1 -1
- package/src/extensibility/extensions/loader.ts +1 -1
- package/src/extensibility/extensions/types.ts +1 -1
- package/src/extensibility/hooks/loader.ts +1 -1
- package/src/extensibility/hooks/types.ts +3 -3
- package/src/index.ts +10 -10
- package/src/ipy/executor.ts +97 -1
- package/src/lsp/index.ts +1 -1
- package/src/lsp/render.ts +90 -46
- package/src/main.ts +16 -3
- package/src/mcp/loader.ts +3 -3
- package/src/migrations.ts +3 -3
- package/src/modes/components/assistant-message.ts +29 -1
- package/src/modes/components/tool-execution.ts +5 -3
- package/src/modes/components/tree-selector.ts +1 -1
- package/src/modes/controllers/extension-ui-controller.ts +1 -1
- package/src/modes/controllers/selector-controller.ts +1 -1
- package/src/modes/interactive-mode.ts +5 -3
- package/src/modes/rpc/rpc-client.ts +1 -1
- package/src/modes/rpc/rpc-mode.ts +1 -4
- package/src/modes/rpc/rpc-types.ts +1 -1
- package/src/modes/theme/mermaid-cache.ts +89 -0
- package/src/modes/theme/theme.ts +2 -0
- package/src/modes/types.ts +2 -2
- package/src/patch/index.ts +3 -9
- package/src/patch/shared.ts +33 -5
- package/src/prompts/tools/task.md +2 -0
- package/src/sdk.ts +60 -22
- package/src/session/agent-session.ts +3 -3
- package/src/session/agent-storage.ts +32 -28
- package/src/session/artifacts.ts +24 -1
- package/src/session/auth-storage.ts +25 -10
- package/src/session/storage-migration.ts +12 -53
- package/src/system-prompt.ts +2 -2
- package/src/task/.executor.ts.kate-swp +0 -0
- package/src/task/executor.ts +1 -1
- package/src/task/index.ts +10 -1
- package/src/task/output-manager.ts +94 -0
- package/src/task/render.ts +7 -12
- package/src/task/worker.ts +1 -1
- package/src/tools/ask.ts +35 -13
- package/src/tools/bash.ts +80 -87
- package/src/tools/calculator.ts +42 -40
- package/src/tools/complete.ts +1 -1
- package/src/tools/fetch.ts +67 -104
- package/src/tools/find.ts +83 -86
- package/src/tools/grep.ts +80 -96
- package/src/tools/index.ts +10 -7
- package/src/tools/ls.ts +39 -65
- package/src/tools/notebook.ts +48 -64
- package/src/tools/output-utils.ts +1 -1
- package/src/tools/python.ts +71 -183
- package/src/tools/read.ts +74 -15
- package/src/tools/render-utils.ts +1 -15
- package/src/tools/ssh.ts +43 -24
- package/src/tools/todo-write.ts +27 -15
- package/src/tools/write.ts +93 -64
- package/src/tui/code-cell.ts +115 -0
- package/src/tui/file-list.ts +48 -0
- package/src/tui/index.ts +11 -0
- package/src/tui/output-block.ts +73 -0
- package/src/tui/status-line.ts +40 -0
- package/src/tui/tree-list.ts +56 -0
- package/src/tui/types.ts +17 -0
- package/src/tui/utils.ts +49 -0
- package/src/vendor/photon/photon_rs_bg.wasm.b64.js +1 -0
- package/src/web/search/auth.ts +1 -1
- package/src/web/search/index.ts +1 -1
- package/src/web/search/render.ts +119 -163
- package/tsconfig.json +0 -42
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { Api, AssistantMessage, Model, ToolCall } from "@oh-my-pi/pi-ai";
|
|
2
|
+
import { completeSimple, validateToolCall } from "@oh-my-pi/pi-ai";
|
|
3
|
+
import reduceSystemPrompt from "@oh-my-pi/pi-coding-agent/commit/prompts/reduce-system.md" with { type: "text" };
|
|
4
|
+
import reduceUserPrompt from "@oh-my-pi/pi-coding-agent/commit/prompts/reduce-user.md" with { type: "text" };
|
|
5
|
+
import type { ChangelogCategory, ConventionalAnalysis, FileObservation } from "@oh-my-pi/pi-coding-agent/commit/types";
|
|
6
|
+
import { renderPromptTemplate } from "@oh-my-pi/pi-coding-agent/config/prompt-templates";
|
|
7
|
+
import { Type } from "@sinclair/typebox";
|
|
8
|
+
|
|
9
|
+
const ReduceTool = {
|
|
10
|
+
name: "create_conventional_analysis",
|
|
11
|
+
description: "Synthesize file observations into a conventional commit analysis.",
|
|
12
|
+
parameters: Type.Object({
|
|
13
|
+
type: Type.Union([
|
|
14
|
+
Type.Literal("feat"),
|
|
15
|
+
Type.Literal("fix"),
|
|
16
|
+
Type.Literal("refactor"),
|
|
17
|
+
Type.Literal("docs"),
|
|
18
|
+
Type.Literal("test"),
|
|
19
|
+
Type.Literal("chore"),
|
|
20
|
+
Type.Literal("style"),
|
|
21
|
+
Type.Literal("perf"),
|
|
22
|
+
Type.Literal("build"),
|
|
23
|
+
Type.Literal("ci"),
|
|
24
|
+
Type.Literal("revert"),
|
|
25
|
+
]),
|
|
26
|
+
scope: Type.Union([Type.String(), Type.Null()]),
|
|
27
|
+
details: Type.Array(
|
|
28
|
+
Type.Object({
|
|
29
|
+
text: Type.String(),
|
|
30
|
+
changelog_category: Type.Optional(
|
|
31
|
+
Type.Union([
|
|
32
|
+
Type.Literal("Added"),
|
|
33
|
+
Type.Literal("Changed"),
|
|
34
|
+
Type.Literal("Fixed"),
|
|
35
|
+
Type.Literal("Deprecated"),
|
|
36
|
+
Type.Literal("Removed"),
|
|
37
|
+
Type.Literal("Security"),
|
|
38
|
+
Type.Literal("Breaking Changes"),
|
|
39
|
+
]),
|
|
40
|
+
),
|
|
41
|
+
user_visible: Type.Optional(Type.Boolean()),
|
|
42
|
+
}),
|
|
43
|
+
),
|
|
44
|
+
issue_refs: Type.Array(Type.String()),
|
|
45
|
+
}),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export interface ReducePhaseInput {
|
|
49
|
+
model: Model<Api>;
|
|
50
|
+
apiKey: string;
|
|
51
|
+
observations: FileObservation[];
|
|
52
|
+
stat: string;
|
|
53
|
+
scopeCandidates: string;
|
|
54
|
+
typesDescription?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function runReducePhase({
|
|
58
|
+
model,
|
|
59
|
+
apiKey,
|
|
60
|
+
observations,
|
|
61
|
+
stat,
|
|
62
|
+
scopeCandidates,
|
|
63
|
+
typesDescription,
|
|
64
|
+
}: ReducePhaseInput): Promise<ConventionalAnalysis> {
|
|
65
|
+
const prompt = renderPromptTemplate(reduceUserPrompt, {
|
|
66
|
+
types_description: typesDescription,
|
|
67
|
+
observations: observations.flatMap((obs) => obs.observations.map((line) => `- ${obs.file}: ${line}`)).join("\n"),
|
|
68
|
+
stat,
|
|
69
|
+
scope_candidates: scopeCandidates,
|
|
70
|
+
});
|
|
71
|
+
const response = await completeSimple(
|
|
72
|
+
model,
|
|
73
|
+
{
|
|
74
|
+
systemPrompt: renderPromptTemplate(reduceSystemPrompt),
|
|
75
|
+
messages: [{ role: "user", content: prompt, timestamp: Date.now() }],
|
|
76
|
+
tools: [ReduceTool],
|
|
77
|
+
},
|
|
78
|
+
{ apiKey, maxTokens: 2400 },
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return parseAnalysisResponse(response);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function parseAnalysisResponse(message: AssistantMessage): ConventionalAnalysis {
|
|
85
|
+
const toolCall = extractToolCall(message, "create_conventional_analysis");
|
|
86
|
+
if (toolCall) {
|
|
87
|
+
const parsed = validateToolCall([ReduceTool], toolCall) as {
|
|
88
|
+
type: ConventionalAnalysis["type"];
|
|
89
|
+
scope: string | null;
|
|
90
|
+
details: Array<{ text: string; changelog_category?: ChangelogCategory; user_visible?: boolean }>;
|
|
91
|
+
issue_refs: string[];
|
|
92
|
+
};
|
|
93
|
+
return normalizeAnalysis(parsed);
|
|
94
|
+
}
|
|
95
|
+
const text = extractTextContent(message);
|
|
96
|
+
const parsed = parseJsonPayload(text) as {
|
|
97
|
+
type: ConventionalAnalysis["type"];
|
|
98
|
+
scope: string | null;
|
|
99
|
+
details: Array<{ text: string; changelog_category?: ChangelogCategory; user_visible?: boolean }>;
|
|
100
|
+
issue_refs: string[];
|
|
101
|
+
};
|
|
102
|
+
return normalizeAnalysis(parsed);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function parseJsonPayload(text: string): unknown {
|
|
106
|
+
const trimmed = text.trim();
|
|
107
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
108
|
+
return JSON.parse(trimmed) as unknown;
|
|
109
|
+
}
|
|
110
|
+
const match = trimmed.match(/\{[\s\S]*\}/);
|
|
111
|
+
if (!match) {
|
|
112
|
+
throw new Error("No JSON payload found in reduce response");
|
|
113
|
+
}
|
|
114
|
+
return JSON.parse(match[0]) as unknown;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function normalizeAnalysis(parsed: {
|
|
118
|
+
type: ConventionalAnalysis["type"];
|
|
119
|
+
scope: string | null;
|
|
120
|
+
details: Array<{ text: string; changelog_category?: ChangelogCategory; user_visible?: boolean }>;
|
|
121
|
+
issue_refs: string[];
|
|
122
|
+
}): ConventionalAnalysis {
|
|
123
|
+
return {
|
|
124
|
+
type: parsed.type,
|
|
125
|
+
scope: parsed.scope?.trim() || null,
|
|
126
|
+
details: parsed.details.map((detail) => ({
|
|
127
|
+
text: detail.text.trim(),
|
|
128
|
+
changelogCategory: detail.user_visible ? detail.changelog_category : undefined,
|
|
129
|
+
userVisible: detail.user_visible ?? false,
|
|
130
|
+
})),
|
|
131
|
+
issueRefs: parsed.issue_refs ?? [],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function extractToolCall(message: AssistantMessage, name: string): ToolCall | undefined {
|
|
136
|
+
return message.content.find((content) => content.type === "toolCall" && content.name === name) as
|
|
137
|
+
| ToolCall
|
|
138
|
+
| undefined;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function extractTextContent(message: AssistantMessage): string {
|
|
142
|
+
return message.content
|
|
143
|
+
.filter((content) => content.type === "text")
|
|
144
|
+
.map((content) => content.text)
|
|
145
|
+
.join("")
|
|
146
|
+
.trim();
|
|
147
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function estimateTokens(text: string): number {
|
|
2
|
+
return Math.ceil(text.length / 4);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function truncateToTokenLimit(text: string, maxTokens: number): string {
|
|
6
|
+
const maxChars = maxTokens * 4;
|
|
7
|
+
if (text.length <= maxChars) return text;
|
|
8
|
+
return `${text.slice(0, maxChars)}\n... (truncated)`;
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ConventionalAnalysis } from "@oh-my-pi/pi-coding-agent/commit/types";
|
|
2
|
+
|
|
3
|
+
export function formatCommitMessage(analysis: ConventionalAnalysis, summary: string): string {
|
|
4
|
+
const scopePart = analysis.scope ? `(${analysis.scope})` : "";
|
|
5
|
+
const header = `${analysis.type}${scopePart}: ${summary}`;
|
|
6
|
+
const bodyLines = analysis.details.map((detail) => `- ${detail.text.trim()}`);
|
|
7
|
+
if (bodyLines.length === 0) {
|
|
8
|
+
return header;
|
|
9
|
+
}
|
|
10
|
+
return `${header}\n\n${bodyLines.join("\n")}`;
|
|
11
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Api, Model } from "@oh-my-pi/pi-ai";
|
|
2
|
+
import {
|
|
3
|
+
parseModelPattern,
|
|
4
|
+
parseModelString,
|
|
5
|
+
SMOL_MODEL_PRIORITY,
|
|
6
|
+
} from "@oh-my-pi/pi-coding-agent/config/model-resolver";
|
|
7
|
+
import type { SettingsManager } from "@oh-my-pi/pi-coding-agent/config/settings-manager";
|
|
8
|
+
|
|
9
|
+
export async function resolvePrimaryModel(
|
|
10
|
+
override: string | undefined,
|
|
11
|
+
settingsManager: SettingsManager,
|
|
12
|
+
modelRegistry: {
|
|
13
|
+
getAvailable: () => Model<Api>[];
|
|
14
|
+
getApiKey: (model: Model<Api>) => Promise<string | undefined>;
|
|
15
|
+
},
|
|
16
|
+
): Promise<{ model: Model<Api>; apiKey: string }> {
|
|
17
|
+
const available = modelRegistry.getAvailable();
|
|
18
|
+
const model = override
|
|
19
|
+
? resolveModelFromString(expandRoleAlias(override, settingsManager), available)
|
|
20
|
+
: resolveModelFromSettings(settingsManager, available);
|
|
21
|
+
if (!model) {
|
|
22
|
+
throw new Error("No model available for commit generation");
|
|
23
|
+
}
|
|
24
|
+
const apiKey = await modelRegistry.getApiKey(model);
|
|
25
|
+
if (!apiKey) {
|
|
26
|
+
throw new Error(`No API key available for model ${model.provider}/${model.id}`);
|
|
27
|
+
}
|
|
28
|
+
return { model, apiKey };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function resolveSmolModel(
|
|
32
|
+
settingsManager: SettingsManager,
|
|
33
|
+
modelRegistry: {
|
|
34
|
+
getAvailable: () => Model<Api>[];
|
|
35
|
+
getApiKey: (model: Model<Api>) => Promise<string | undefined>;
|
|
36
|
+
},
|
|
37
|
+
fallbackModel: Model<Api>,
|
|
38
|
+
fallbackApiKey: string,
|
|
39
|
+
): Promise<{ model: Model<Api>; apiKey: string }> {
|
|
40
|
+
const available = modelRegistry.getAvailable();
|
|
41
|
+
const role = settingsManager.getModelRole("smol");
|
|
42
|
+
const roleModel = role ? resolveModelFromString(role, available) : undefined;
|
|
43
|
+
if (roleModel) {
|
|
44
|
+
const apiKey = await modelRegistry.getApiKey(roleModel);
|
|
45
|
+
if (apiKey) return { model: roleModel, apiKey };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (const pattern of SMOL_MODEL_PRIORITY) {
|
|
49
|
+
const candidate = parseModelPattern(pattern, available).model;
|
|
50
|
+
if (!candidate) continue;
|
|
51
|
+
const apiKey = await modelRegistry.getApiKey(candidate);
|
|
52
|
+
if (apiKey) return { model: candidate, apiKey };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { model: fallbackModel, apiKey: fallbackApiKey };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function resolveModelFromSettings(settingsManager: SettingsManager, available: Model<Api>[]): Model<Api> | undefined {
|
|
59
|
+
const roles = ["commit", "smol", "default"];
|
|
60
|
+
for (const role of roles) {
|
|
61
|
+
const configured = settingsManager.getModelRole(role);
|
|
62
|
+
if (!configured) continue;
|
|
63
|
+
const resolved = resolveModelFromString(expandRoleAlias(configured, settingsManager), available);
|
|
64
|
+
if (resolved) return resolved;
|
|
65
|
+
}
|
|
66
|
+
return available[0];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function resolveModelFromString(value: string, available: Model<Api>[]): Model<Api> | undefined {
|
|
70
|
+
const parsed = parseModelString(value);
|
|
71
|
+
if (parsed) {
|
|
72
|
+
return available.find((model) => model.provider === parsed.provider && model.id === parsed.id);
|
|
73
|
+
}
|
|
74
|
+
return parseModelPattern(value, available).model;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function expandRoleAlias(value: string, settingsManager: SettingsManager): string {
|
|
78
|
+
const lower = value.toLowerCase();
|
|
79
|
+
if (lower.startsWith("pi/") || lower.startsWith("omp/")) {
|
|
80
|
+
const role = lower.startsWith("pi/") ? value.slice(3) : value.slice(4);
|
|
81
|
+
return settingsManager.getModelRole(role) ?? value;
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { relative } from "node:path";
|
|
2
|
+
import type { Api, Model } from "@oh-my-pi/pi-ai";
|
|
3
|
+
import { runAgenticCommit } from "@oh-my-pi/pi-coding-agent/commit/agentic";
|
|
4
|
+
import {
|
|
5
|
+
extractScopeCandidates,
|
|
6
|
+
generateConventionalAnalysis,
|
|
7
|
+
generateSummary,
|
|
8
|
+
validateAnalysis,
|
|
9
|
+
validateSummary,
|
|
10
|
+
} from "@oh-my-pi/pi-coding-agent/commit/analysis";
|
|
11
|
+
import { runChangelogFlow } from "@oh-my-pi/pi-coding-agent/commit/changelog";
|
|
12
|
+
import { ControlledGit } from "@oh-my-pi/pi-coding-agent/commit/git";
|
|
13
|
+
import { runMapReduceAnalysis, shouldUseMapReduce } from "@oh-my-pi/pi-coding-agent/commit/map-reduce";
|
|
14
|
+
import { formatCommitMessage } from "@oh-my-pi/pi-coding-agent/commit/message";
|
|
15
|
+
import { resolvePrimaryModel, resolveSmolModel } from "@oh-my-pi/pi-coding-agent/commit/model-selection";
|
|
16
|
+
import summaryRetryPrompt from "@oh-my-pi/pi-coding-agent/commit/prompts/summary-retry.md" with { type: "text" };
|
|
17
|
+
import typesDescriptionPrompt from "@oh-my-pi/pi-coding-agent/commit/prompts/types-description.md" with {
|
|
18
|
+
type: "text",
|
|
19
|
+
};
|
|
20
|
+
import type { CommitCommandArgs, ConventionalAnalysis } from "@oh-my-pi/pi-coding-agent/commit/types";
|
|
21
|
+
import { renderPromptTemplate } from "@oh-my-pi/pi-coding-agent/config/prompt-templates";
|
|
22
|
+
import { SettingsManager } from "@oh-my-pi/pi-coding-agent/config/settings-manager";
|
|
23
|
+
import { discoverAuthStorage, discoverModels } from "@oh-my-pi/pi-coding-agent/sdk";
|
|
24
|
+
import { loadProjectContextFiles } from "@oh-my-pi/pi-coding-agent/system-prompt";
|
|
25
|
+
import { logger } from "@oh-my-pi/pi-utils";
|
|
26
|
+
|
|
27
|
+
const SUMMARY_MAX_CHARS = 72;
|
|
28
|
+
const RECENT_COMMITS_COUNT = 8;
|
|
29
|
+
const TYPES_DESCRIPTION = renderPromptTemplate(typesDescriptionPrompt);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Execute the omp commit pipeline for staged changes.
|
|
33
|
+
*/
|
|
34
|
+
export async function runCommitCommand(args: CommitCommandArgs): Promise<void> {
|
|
35
|
+
if (args.legacy) {
|
|
36
|
+
return runLegacyCommitCommand(args);
|
|
37
|
+
}
|
|
38
|
+
return runAgenticCommit(args);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function runLegacyCommitCommand(args: CommitCommandArgs): Promise<void> {
|
|
42
|
+
const cwd = process.cwd();
|
|
43
|
+
const settingsManager = await SettingsManager.create(cwd);
|
|
44
|
+
const commitSettings = settingsManager.getCommitSettings();
|
|
45
|
+
const authStorage = await discoverAuthStorage();
|
|
46
|
+
const modelRegistry = await discoverModels(authStorage);
|
|
47
|
+
|
|
48
|
+
const { model: primaryModel, apiKey: primaryApiKey } = await resolvePrimaryModel(
|
|
49
|
+
args.model,
|
|
50
|
+
settingsManager,
|
|
51
|
+
modelRegistry,
|
|
52
|
+
);
|
|
53
|
+
const { model: smolModel, apiKey: smolApiKey } = await resolveSmolModel(
|
|
54
|
+
settingsManager,
|
|
55
|
+
modelRegistry,
|
|
56
|
+
primaryModel,
|
|
57
|
+
primaryApiKey,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const git = new ControlledGit(cwd);
|
|
61
|
+
let stagedFiles = await git.getStagedFiles();
|
|
62
|
+
if (stagedFiles.length === 0) {
|
|
63
|
+
writeStdout("No staged changes detected, staging all changes...");
|
|
64
|
+
await git.stageAll();
|
|
65
|
+
stagedFiles = await git.getStagedFiles();
|
|
66
|
+
}
|
|
67
|
+
if (stagedFiles.length === 0) {
|
|
68
|
+
writeStderr("No changes to commit.");
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!args.noChangelog) {
|
|
73
|
+
await runChangelogFlow({
|
|
74
|
+
git,
|
|
75
|
+
cwd,
|
|
76
|
+
model: primaryModel,
|
|
77
|
+
apiKey: primaryApiKey,
|
|
78
|
+
stagedFiles,
|
|
79
|
+
dryRun: args.dryRun,
|
|
80
|
+
maxDiffChars: commitSettings.changelogMaxDiffChars,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const diff = await git.getDiff(true);
|
|
85
|
+
const stat = await git.getStat(true);
|
|
86
|
+
const numstat = await git.getNumstat(true);
|
|
87
|
+
const scopeCandidates = extractScopeCandidates(numstat).scopeCandidates;
|
|
88
|
+
const recentCommits = await git.getRecentCommits(RECENT_COMMITS_COUNT);
|
|
89
|
+
const contextFiles = await loadProjectContextFiles({ cwd });
|
|
90
|
+
const formattedContextFiles = contextFiles.map((file) => ({
|
|
91
|
+
path: relative(cwd, file.path),
|
|
92
|
+
content: file.content,
|
|
93
|
+
}));
|
|
94
|
+
|
|
95
|
+
const analysis = await generateAnalysis({
|
|
96
|
+
diff,
|
|
97
|
+
stat,
|
|
98
|
+
scopeCandidates,
|
|
99
|
+
recentCommits,
|
|
100
|
+
contextFiles: formattedContextFiles,
|
|
101
|
+
userContext: args.context,
|
|
102
|
+
primaryModel,
|
|
103
|
+
primaryApiKey,
|
|
104
|
+
smolModel,
|
|
105
|
+
smolApiKey,
|
|
106
|
+
commitSettings,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const analysisValidation = validateAnalysis(analysis);
|
|
110
|
+
if (!analysisValidation.valid) {
|
|
111
|
+
logger.warn("commit analysis validation failed", { errors: analysisValidation.errors });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const summary = await generateSummaryWithRetry({
|
|
115
|
+
analysis,
|
|
116
|
+
stat,
|
|
117
|
+
model: primaryModel,
|
|
118
|
+
apiKey: primaryApiKey,
|
|
119
|
+
userContext: args.context,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const commitMessage = formatCommitMessage(analysis, summary.summary);
|
|
123
|
+
|
|
124
|
+
if (args.dryRun) {
|
|
125
|
+
writeStdout("\nGenerated commit message:\n");
|
|
126
|
+
writeStdout(commitMessage);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
await git.commit(commitMessage);
|
|
131
|
+
writeStdout("Commit created.");
|
|
132
|
+
if (args.push) {
|
|
133
|
+
await git.push();
|
|
134
|
+
writeStdout("Pushed to remote.");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function generateAnalysis(input: {
|
|
139
|
+
diff: string;
|
|
140
|
+
stat: string;
|
|
141
|
+
scopeCandidates: string;
|
|
142
|
+
recentCommits: string[];
|
|
143
|
+
contextFiles: Array<{ path: string; content: string }>;
|
|
144
|
+
userContext?: string;
|
|
145
|
+
primaryModel: Model<Api>;
|
|
146
|
+
primaryApiKey: string;
|
|
147
|
+
smolModel: Model<Api>;
|
|
148
|
+
smolApiKey: string;
|
|
149
|
+
commitSettings: {
|
|
150
|
+
mapReduceEnabled: boolean;
|
|
151
|
+
mapReduceMinFiles: number;
|
|
152
|
+
mapReduceMaxFileTokens: number;
|
|
153
|
+
mapReduceTimeoutMs: number;
|
|
154
|
+
mapReduceMaxConcurrency: number;
|
|
155
|
+
changelogMaxDiffChars: number;
|
|
156
|
+
};
|
|
157
|
+
}): Promise<ConventionalAnalysis> {
|
|
158
|
+
if (
|
|
159
|
+
shouldUseMapReduce(input.diff, {
|
|
160
|
+
enabled: input.commitSettings.mapReduceEnabled,
|
|
161
|
+
minFiles: input.commitSettings.mapReduceMinFiles,
|
|
162
|
+
maxFileTokens: input.commitSettings.mapReduceMaxFileTokens,
|
|
163
|
+
})
|
|
164
|
+
) {
|
|
165
|
+
writeStdout("Large diff detected, using map-reduce analysis...");
|
|
166
|
+
return runMapReduceAnalysis({
|
|
167
|
+
model: input.primaryModel,
|
|
168
|
+
apiKey: input.primaryApiKey,
|
|
169
|
+
smolModel: input.smolModel,
|
|
170
|
+
smolApiKey: input.smolApiKey,
|
|
171
|
+
diff: input.diff,
|
|
172
|
+
stat: input.stat,
|
|
173
|
+
scopeCandidates: input.scopeCandidates,
|
|
174
|
+
typesDescription: TYPES_DESCRIPTION,
|
|
175
|
+
settings: {
|
|
176
|
+
enabled: input.commitSettings.mapReduceEnabled,
|
|
177
|
+
minFiles: input.commitSettings.mapReduceMinFiles,
|
|
178
|
+
maxFileTokens: input.commitSettings.mapReduceMaxFileTokens,
|
|
179
|
+
maxConcurrency: input.commitSettings.mapReduceMaxConcurrency,
|
|
180
|
+
timeoutMs: input.commitSettings.mapReduceTimeoutMs,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return generateConventionalAnalysis({
|
|
186
|
+
model: input.primaryModel,
|
|
187
|
+
apiKey: input.primaryApiKey,
|
|
188
|
+
contextFiles: input.contextFiles,
|
|
189
|
+
userContext: input.userContext,
|
|
190
|
+
typesDescription: TYPES_DESCRIPTION,
|
|
191
|
+
recentCommits: input.recentCommits,
|
|
192
|
+
scopeCandidates: input.scopeCandidates,
|
|
193
|
+
stat: input.stat,
|
|
194
|
+
diff: input.diff,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function generateSummaryWithRetry(input: {
|
|
199
|
+
analysis: ConventionalAnalysis;
|
|
200
|
+
stat: string;
|
|
201
|
+
model: Model<Api>;
|
|
202
|
+
apiKey: string;
|
|
203
|
+
userContext?: string;
|
|
204
|
+
}): Promise<{ summary: string }> {
|
|
205
|
+
let context = input.userContext;
|
|
206
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
207
|
+
const result = await generateSummary({
|
|
208
|
+
model: input.model,
|
|
209
|
+
apiKey: input.apiKey,
|
|
210
|
+
commitType: input.analysis.type,
|
|
211
|
+
scope: input.analysis.scope,
|
|
212
|
+
details: input.analysis.details.map((detail) => detail.text),
|
|
213
|
+
stat: input.stat,
|
|
214
|
+
maxChars: SUMMARY_MAX_CHARS,
|
|
215
|
+
userContext: context,
|
|
216
|
+
});
|
|
217
|
+
const validation = validateSummary(result.summary, SUMMARY_MAX_CHARS);
|
|
218
|
+
if (validation.valid) {
|
|
219
|
+
return result;
|
|
220
|
+
}
|
|
221
|
+
if (attempt === 2) {
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
context = buildRetryContext(input.userContext, validation.errors);
|
|
225
|
+
}
|
|
226
|
+
throw new Error("Summary generation failed");
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function buildRetryContext(base: string | undefined, errors: string[]): string {
|
|
230
|
+
return renderPromptTemplate(summaryRetryPrompt, {
|
|
231
|
+
base_context: base,
|
|
232
|
+
errors: errors.join("; "),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function writeStdout(message: string): void {
|
|
237
|
+
process.stdout.write(`${message}\n`);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function writeStderr(message: string): void {
|
|
241
|
+
process.stderr.write(`${message}\n`);
|
|
242
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<context>
|
|
2
|
+
You are a senior release engineer who writes precise, changelog-ready commit classifications. Your output feeds directly into automated release tooling.
|
|
3
|
+
</context>
|
|
4
|
+
|
|
5
|
+
<instructions>
|
|
6
|
+
Classify this git diff into conventional commit format. Get this right — it affects release notes and semantic versioning.
|
|
7
|
+
|
|
8
|
+
## 1. Determine Scope
|
|
9
|
+
|
|
10
|
+
Apply scope when 60%+ of line changes target a single component:
|
|
11
|
+
- 150 lines in src/api/, 30 in src/lib.rs -> "api"
|
|
12
|
+
- 50 lines in src/api/, 50 in src/types/ -> null (50/50 split)
|
|
13
|
+
|
|
14
|
+
Use null for: cross-cutting changes, no dominant component, project-wide refactoring.
|
|
15
|
+
|
|
16
|
+
Forbidden scopes (use null): src, lib, include, tests, benches, examples, docs, project name, app, main, entire, all, misc.
|
|
17
|
+
|
|
18
|
+
Prefer scopes from <common_scopes> over inventing new ones.
|
|
19
|
+
|
|
20
|
+
## 2. Generate Details (0-6 items)
|
|
21
|
+
|
|
22
|
+
Each detail:
|
|
23
|
+
1. Past-tense verb, ends with period
|
|
24
|
+
2. Explains impact/rationale (skip trivial what-changed)
|
|
25
|
+
3. Uses precise names (modules, APIs, files)
|
|
26
|
+
4. Under 120 characters
|
|
27
|
+
|
|
28
|
+
Abstraction preference:
|
|
29
|
+
- BEST: "Replaced polling with event-driven model for 10x throughput."
|
|
30
|
+
- GOOD: "Consolidated three HTTP builders into unified API."
|
|
31
|
+
- SKIP: "Renamed workspacePath to locate."
|
|
32
|
+
|
|
33
|
+
Group 3+ similar changes: "Updated 5 test files for new API." (not five bullets).
|
|
34
|
+
|
|
35
|
+
Issue references inline: (#123), (#123, #456), (#123-#125).
|
|
36
|
+
|
|
37
|
+
Priority: user-visible -> perf/security -> architecture -> internal.
|
|
38
|
+
|
|
39
|
+
Exclude: import changes, whitespace, formatting, trivial renames, debug prints, comment-only, file moves without modification.
|
|
40
|
+
|
|
41
|
+
State only visible rationale. If unclear, use neutral: "Updated logic for correctness."
|
|
42
|
+
|
|
43
|
+
## 3. Assign Changelog Metadata
|
|
44
|
+
|
|
45
|
+
| Condition | changelog_category |
|
|
46
|
+
|-----------|--------------------|
|
|
47
|
+
| New public API, feature, capability | "Added" |
|
|
48
|
+
| Modified existing behavior | "Changed" |
|
|
49
|
+
| Bug fix, correction | "Fixed" |
|
|
50
|
+
| Feature marked for removal | "Deprecated" |
|
|
51
|
+
| Feature/API removed | "Removed" |
|
|
52
|
+
| Security fix or improvement | "Security" |
|
|
53
|
+
|
|
54
|
+
user_visible: true for: new features, APIs, breaking changes, user-affecting bug fixes, user-facing docs, security fixes.
|
|
55
|
+
|
|
56
|
+
user_visible: false for: internal refactoring, performance optimizations (unless documented), test/build/CI, code style.
|
|
57
|
+
|
|
58
|
+
Omit changelog_category when user_visible is false.
|
|
59
|
+
</instructions>
|
|
60
|
+
|
|
61
|
+
<output_format>
|
|
62
|
+
Call create_conventional_analysis with:
|
|
63
|
+
|
|
64
|
+
{
|
|
65
|
+
"type": "feat|fix|refactor|docs|test|chore|style|perf|build|ci|revert",
|
|
66
|
+
"scope": "component-name" | null,
|
|
67
|
+
"details": [
|
|
68
|
+
{
|
|
69
|
+
"text": "Past-tense description ending with period.",
|
|
70
|
+
"changelog_category": "Added|Changed|Fixed|Deprecated|Removed|Security",
|
|
71
|
+
"user_visible": true
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"text": "Internal change description.",
|
|
75
|
+
"user_visible": false
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"issue_refs": []
|
|
79
|
+
}
|
|
80
|
+
</output_format>
|
|
81
|
+
|
|
82
|
+
<examples>
|
|
83
|
+
<example name="feature-with-api">
|
|
84
|
+
{
|
|
85
|
+
"type": "feat",
|
|
86
|
+
"scope": "api",
|
|
87
|
+
"details": [
|
|
88
|
+
{
|
|
89
|
+
"text": "Added TLS mutual authentication to prevent man-in-the-middle attacks (#100).",
|
|
90
|
+
"changelog_category": "Added",
|
|
91
|
+
"user_visible": true
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"text": "Implemented builder pattern to simplify transport configuration (#101).",
|
|
95
|
+
"changelog_category": "Added",
|
|
96
|
+
"user_visible": true
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"text": "Migrated 6 integration tests to exercise new security features.",
|
|
100
|
+
"user_visible": false
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
"issue_refs": []
|
|
104
|
+
}
|
|
105
|
+
</example>
|
|
106
|
+
|
|
107
|
+
<example name="internal-refactor">
|
|
108
|
+
{
|
|
109
|
+
"type": "refactor",
|
|
110
|
+
"scope": "parser",
|
|
111
|
+
"details": [
|
|
112
|
+
{
|
|
113
|
+
"text": "Extracted validation logic into separate module for reusability.",
|
|
114
|
+
"user_visible": false
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"text": "Consolidated error handling across 12 functions to reduce duplication.",
|
|
118
|
+
"user_visible": false
|
|
119
|
+
}
|
|
120
|
+
],
|
|
121
|
+
"issue_refs": []
|
|
122
|
+
}
|
|
123
|
+
</example>
|
|
124
|
+
|
|
125
|
+
<example name="bug-fix">
|
|
126
|
+
{
|
|
127
|
+
"type": "fix",
|
|
128
|
+
"scope": "parser",
|
|
129
|
+
"details": [
|
|
130
|
+
{
|
|
131
|
+
"text": "Corrected off-by-one error causing buffer overflow on large inputs (#456).",
|
|
132
|
+
"changelog_category": "Fixed",
|
|
133
|
+
"user_visible": true
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"text": "Added bounds checking to prevent panic on empty files (#457).",
|
|
137
|
+
"changelog_category": "Fixed",
|
|
138
|
+
"user_visible": true
|
|
139
|
+
}
|
|
140
|
+
],
|
|
141
|
+
"issue_refs": []
|
|
142
|
+
}
|
|
143
|
+
</example>
|
|
144
|
+
|
|
145
|
+
<example name="minimal-chore">
|
|
146
|
+
{
|
|
147
|
+
"type": "chore",
|
|
148
|
+
"scope": "deps",
|
|
149
|
+
"details": [],
|
|
150
|
+
"issue_refs": []
|
|
151
|
+
}
|
|
152
|
+
</example>
|
|
153
|
+
</examples>
|
|
154
|
+
|
|
155
|
+
Be thorough. This matters.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{{#if context_files}}
|
|
2
|
+
<project_context>
|
|
3
|
+
{{#each context_files}}
|
|
4
|
+
<file path="{{ path }}">
|
|
5
|
+
{{ content }}
|
|
6
|
+
</file>
|
|
7
|
+
{{/each}}
|
|
8
|
+
</project_context>
|
|
9
|
+
{{/if}}
|
|
10
|
+
{{#if user_context}}
|
|
11
|
+
<user_context>
|
|
12
|
+
{{ user_context }}
|
|
13
|
+
</user_context>
|
|
14
|
+
{{/if}}
|
|
15
|
+
{{#if types_description}}
|
|
16
|
+
<commit_types>
|
|
17
|
+
{{ types_description }}
|
|
18
|
+
</commit_types>
|
|
19
|
+
{{/if}}
|
|
20
|
+
|
|
21
|
+
<diff_statistics>
|
|
22
|
+
{{ stat }}
|
|
23
|
+
</diff_statistics>
|
|
24
|
+
|
|
25
|
+
<scope_candidates>
|
|
26
|
+
{{ scope_candidates }}
|
|
27
|
+
</scope_candidates>
|
|
28
|
+
{{#if common_scopes}}
|
|
29
|
+
<common_scopes>
|
|
30
|
+
{{ common_scopes }}
|
|
31
|
+
</common_scopes>
|
|
32
|
+
{{/if}}
|
|
33
|
+
{{#if recent_commits}}
|
|
34
|
+
<style_patterns>
|
|
35
|
+
{{ recent_commits }}
|
|
36
|
+
</style_patterns>
|
|
37
|
+
{{/if}}
|
|
38
|
+
|
|
39
|
+
<diff>
|
|
40
|
+
{{ diff }}
|
|
41
|
+
</diff>
|