@oh-my-pi/pi-coding-agent 8.0.16 → 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.
Files changed (166) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/package.json +14 -11
  3. package/scripts/generate-wasm-b64.ts +24 -0
  4. package/src/capability/context-file.ts +1 -1
  5. package/src/capability/extension-module.ts +1 -1
  6. package/src/capability/extension.ts +1 -1
  7. package/src/capability/hook.ts +1 -1
  8. package/src/capability/instruction.ts +1 -1
  9. package/src/capability/mcp.ts +1 -1
  10. package/src/capability/prompt.ts +1 -1
  11. package/src/capability/rule.ts +1 -1
  12. package/src/capability/settings.ts +1 -1
  13. package/src/capability/skill.ts +1 -1
  14. package/src/capability/slash-command.ts +1 -1
  15. package/src/capability/ssh.ts +1 -1
  16. package/src/capability/system-prompt.ts +1 -1
  17. package/src/capability/tool.ts +1 -1
  18. package/src/cli/args.ts +1 -1
  19. package/src/cli/plugin-cli.ts +1 -5
  20. package/src/commit/agentic/agent.ts +309 -0
  21. package/src/commit/agentic/fallback.ts +96 -0
  22. package/src/commit/agentic/index.ts +359 -0
  23. package/src/commit/agentic/prompts/analyze-file.md +22 -0
  24. package/src/commit/agentic/prompts/session-user.md +26 -0
  25. package/src/commit/agentic/prompts/split-confirm.md +1 -0
  26. package/src/commit/agentic/prompts/system.md +40 -0
  27. package/src/commit/agentic/state.ts +74 -0
  28. package/src/commit/agentic/tools/analyze-file.ts +131 -0
  29. package/src/commit/agentic/tools/git-file-diff.ts +194 -0
  30. package/src/commit/agentic/tools/git-hunk.ts +50 -0
  31. package/src/commit/agentic/tools/git-overview.ts +84 -0
  32. package/src/commit/agentic/tools/index.ts +56 -0
  33. package/src/commit/agentic/tools/propose-changelog.ts +128 -0
  34. package/src/commit/agentic/tools/propose-commit.ts +154 -0
  35. package/src/commit/agentic/tools/recent-commits.ts +81 -0
  36. package/src/commit/agentic/tools/split-commit.ts +284 -0
  37. package/src/commit/agentic/topo-sort.ts +44 -0
  38. package/src/commit/agentic/trivial.ts +51 -0
  39. package/src/commit/agentic/validation.ts +200 -0
  40. package/src/commit/analysis/conventional.ts +169 -0
  41. package/src/commit/analysis/index.ts +4 -0
  42. package/src/commit/analysis/scope.ts +242 -0
  43. package/src/commit/analysis/summary.ts +114 -0
  44. package/src/commit/analysis/validation.ts +66 -0
  45. package/src/commit/changelog/detect.ts +36 -0
  46. package/src/commit/changelog/generate.ts +112 -0
  47. package/src/commit/changelog/index.ts +233 -0
  48. package/src/commit/changelog/parse.ts +44 -0
  49. package/src/commit/cli.ts +93 -0
  50. package/src/commit/git/diff.ts +148 -0
  51. package/src/commit/git/errors.ts +11 -0
  52. package/src/commit/git/index.ts +217 -0
  53. package/src/commit/git/operations.ts +53 -0
  54. package/src/commit/index.ts +5 -0
  55. package/src/commit/map-reduce/.map-phase.ts.kate-swp +0 -0
  56. package/src/commit/map-reduce/index.ts +63 -0
  57. package/src/commit/map-reduce/map-phase.ts +193 -0
  58. package/src/commit/map-reduce/reduce-phase.ts +147 -0
  59. package/src/commit/map-reduce/utils.ts +9 -0
  60. package/src/commit/message.ts +11 -0
  61. package/src/commit/model-selection.ts +84 -0
  62. package/src/commit/pipeline.ts +242 -0
  63. package/src/commit/prompts/analysis-system.md +155 -0
  64. package/src/commit/prompts/analysis-user.md +41 -0
  65. package/src/commit/prompts/changelog-system.md +56 -0
  66. package/src/commit/prompts/changelog-user.md +19 -0
  67. package/src/commit/prompts/file-observer-system.md +26 -0
  68. package/src/commit/prompts/file-observer-user.md +9 -0
  69. package/src/commit/prompts/reduce-system.md +60 -0
  70. package/src/commit/prompts/reduce-user.md +17 -0
  71. package/src/commit/prompts/summary-retry.md +4 -0
  72. package/src/commit/prompts/summary-system.md +52 -0
  73. package/src/commit/prompts/summary-user.md +13 -0
  74. package/src/commit/prompts/types-description.md +2 -0
  75. package/src/commit/types.ts +109 -0
  76. package/src/commit/utils/exclusions.ts +42 -0
  77. package/src/config/file-lock.ts +111 -0
  78. package/src/config/model-registry.ts +16 -7
  79. package/src/config/settings-manager.ts +115 -40
  80. package/src/config.ts +5 -5
  81. package/src/discovery/agents-md.ts +1 -1
  82. package/src/discovery/builtin.ts +1 -1
  83. package/src/discovery/claude.ts +1 -1
  84. package/src/discovery/cline.ts +1 -1
  85. package/src/discovery/codex.ts +1 -1
  86. package/src/discovery/cursor.ts +1 -1
  87. package/src/discovery/gemini.ts +1 -1
  88. package/src/discovery/github.ts +1 -1
  89. package/src/discovery/index.ts +11 -11
  90. package/src/discovery/mcp-json.ts +1 -1
  91. package/src/discovery/ssh.ts +1 -1
  92. package/src/discovery/vscode.ts +1 -1
  93. package/src/discovery/windsurf.ts +1 -1
  94. package/src/extensibility/custom-commands/loader.ts +1 -1
  95. package/src/extensibility/custom-commands/types.ts +1 -1
  96. package/src/extensibility/custom-tools/loader.ts +1 -1
  97. package/src/extensibility/custom-tools/types.ts +1 -1
  98. package/src/extensibility/extensions/loader.ts +1 -1
  99. package/src/extensibility/extensions/types.ts +1 -1
  100. package/src/extensibility/hooks/loader.ts +1 -1
  101. package/src/extensibility/hooks/types.ts +3 -3
  102. package/src/index.ts +10 -10
  103. package/src/ipy/executor.ts +97 -1
  104. package/src/lsp/index.ts +1 -1
  105. package/src/lsp/render.ts +90 -46
  106. package/src/main.ts +16 -3
  107. package/src/mcp/loader.ts +3 -3
  108. package/src/migrations.ts +3 -3
  109. package/src/modes/components/assistant-message.ts +29 -1
  110. package/src/modes/components/tool-execution.ts +5 -3
  111. package/src/modes/components/tree-selector.ts +1 -1
  112. package/src/modes/controllers/extension-ui-controller.ts +1 -1
  113. package/src/modes/controllers/selector-controller.ts +1 -1
  114. package/src/modes/interactive-mode.ts +5 -3
  115. package/src/modes/rpc/rpc-client.ts +1 -1
  116. package/src/modes/rpc/rpc-mode.ts +1 -4
  117. package/src/modes/rpc/rpc-types.ts +1 -1
  118. package/src/modes/theme/mermaid-cache.ts +89 -0
  119. package/src/modes/theme/theme.ts +2 -0
  120. package/src/modes/types.ts +2 -2
  121. package/src/patch/index.ts +3 -9
  122. package/src/patch/shared.ts +33 -5
  123. package/src/prompts/tools/task.md +2 -0
  124. package/src/sdk.ts +60 -22
  125. package/src/session/agent-session.ts +3 -3
  126. package/src/session/agent-storage.ts +32 -28
  127. package/src/session/artifacts.ts +24 -1
  128. package/src/session/auth-storage.ts +25 -10
  129. package/src/session/storage-migration.ts +12 -53
  130. package/src/system-prompt.ts +2 -2
  131. package/src/task/.executor.ts.kate-swp +0 -0
  132. package/src/task/executor.ts +1 -1
  133. package/src/task/index.ts +10 -1
  134. package/src/task/output-manager.ts +94 -0
  135. package/src/task/render.ts +7 -12
  136. package/src/task/worker.ts +1 -1
  137. package/src/tools/ask.ts +35 -13
  138. package/src/tools/bash.ts +80 -87
  139. package/src/tools/calculator.ts +42 -40
  140. package/src/tools/complete.ts +1 -1
  141. package/src/tools/fetch.ts +67 -104
  142. package/src/tools/find.ts +83 -86
  143. package/src/tools/grep.ts +80 -96
  144. package/src/tools/index.ts +10 -7
  145. package/src/tools/ls.ts +39 -65
  146. package/src/tools/notebook.ts +48 -64
  147. package/src/tools/output-utils.ts +1 -1
  148. package/src/tools/python.ts +71 -183
  149. package/src/tools/read.ts +74 -15
  150. package/src/tools/render-utils.ts +1 -15
  151. package/src/tools/ssh.ts +43 -24
  152. package/src/tools/todo-write.ts +27 -15
  153. package/src/tools/write.ts +93 -64
  154. package/src/tui/code-cell.ts +115 -0
  155. package/src/tui/file-list.ts +48 -0
  156. package/src/tui/index.ts +11 -0
  157. package/src/tui/output-block.ts +73 -0
  158. package/src/tui/status-line.ts +40 -0
  159. package/src/tui/tree-list.ts +56 -0
  160. package/src/tui/types.ts +17 -0
  161. package/src/tui/utils.ts +49 -0
  162. package/src/vendor/photon/photon_rs_bg.wasm.b64.js +1 -0
  163. package/src/web/search/auth.ts +1 -1
  164. package/src/web/search/index.ts +1 -1
  165. package/src/web/search/render.ts +119 -163
  166. package/tsconfig.json +0 -42
@@ -0,0 +1,154 @@
1
+ import type { CommitAgentState } from "@oh-my-pi/pi-coding-agent/commit/agentic/state";
2
+ import {
3
+ capDetails,
4
+ MAX_DETAIL_ITEMS,
5
+ normalizeSummary,
6
+ SUMMARY_MAX_CHARS,
7
+ validateSummaryRules,
8
+ validateTypeConsistency,
9
+ } from "@oh-my-pi/pi-coding-agent/commit/agentic/validation";
10
+ import { validateAnalysis } from "@oh-my-pi/pi-coding-agent/commit/analysis/validation";
11
+ import type { ControlledGit } from "@oh-my-pi/pi-coding-agent/commit/git";
12
+ import type { CommitType, ConventionalAnalysis, ConventionalDetail } from "@oh-my-pi/pi-coding-agent/commit/types";
13
+ import type { CustomTool } from "@oh-my-pi/pi-coding-agent/extensibility/custom-tools/types";
14
+ import { Type } from "@sinclair/typebox";
15
+
16
+ const commitTypeSchema = Type.Union([
17
+ Type.Literal("feat"),
18
+ Type.Literal("fix"),
19
+ Type.Literal("refactor"),
20
+ Type.Literal("perf"),
21
+ Type.Literal("docs"),
22
+ Type.Literal("test"),
23
+ Type.Literal("build"),
24
+ Type.Literal("ci"),
25
+ Type.Literal("chore"),
26
+ Type.Literal("style"),
27
+ Type.Literal("revert"),
28
+ ]);
29
+
30
+ const detailSchema = Type.Object({
31
+ text: Type.String(),
32
+ changelog_category: Type.Optional(
33
+ Type.Union([
34
+ Type.Literal("Added"),
35
+ Type.Literal("Changed"),
36
+ Type.Literal("Fixed"),
37
+ Type.Literal("Deprecated"),
38
+ Type.Literal("Removed"),
39
+ Type.Literal("Security"),
40
+ Type.Literal("Breaking Changes"),
41
+ ]),
42
+ ),
43
+ user_visible: Type.Optional(Type.Boolean()),
44
+ });
45
+
46
+ const proposeCommitSchema = Type.Object({
47
+ type: commitTypeSchema,
48
+ scope: Type.Union([Type.String(), Type.Null()]),
49
+ summary: Type.String(),
50
+ details: Type.Array(detailSchema),
51
+ issue_refs: Type.Array(Type.String()),
52
+ });
53
+
54
+ interface ProposalResponse {
55
+ valid: boolean;
56
+ errors: string[];
57
+ warnings: string[];
58
+ proposal?: {
59
+ type: CommitType;
60
+ scope: string | null;
61
+ summary: string;
62
+ details: ConventionalDetail[];
63
+ issue_refs: string[];
64
+ };
65
+ }
66
+
67
+ function normalizeDetails(
68
+ details: Array<{
69
+ text: string;
70
+ changelog_category?: ConventionalDetail["changelogCategory"];
71
+ user_visible?: boolean;
72
+ }>,
73
+ ): ConventionalDetail[] {
74
+ return details.map((detail) => ({
75
+ text: detail.text.trim(),
76
+ changelogCategory: detail.user_visible ? detail.changelog_category : undefined,
77
+ userVisible: detail.user_visible ?? false,
78
+ }));
79
+ }
80
+
81
+ export function createProposeCommitTool(
82
+ git: ControlledGit,
83
+ state: CommitAgentState,
84
+ ): CustomTool<typeof proposeCommitSchema> {
85
+ return {
86
+ name: "propose_commit",
87
+ label: "Propose Commit",
88
+ description: "Submit the final conventional commit proposal.",
89
+ parameters: proposeCommitSchema,
90
+ async execute(_toolCallId, params) {
91
+ const scope = params.scope?.trim() || null;
92
+ const summary = normalizeSummary(params.summary, params.type, scope);
93
+ const details = normalizeDetails(params.details);
94
+ const { details: cappedDetails, warnings: detailWarnings } = capDetails(details);
95
+ const analysis: ConventionalAnalysis = {
96
+ type: params.type,
97
+ scope,
98
+ details: cappedDetails,
99
+ issueRefs: params.issue_refs ?? [],
100
+ };
101
+
102
+ const summaryValidation = validateSummaryRules(summary);
103
+ const analysisValidation = validateAnalysis(analysis);
104
+ const stagedFiles = state.overview?.files ?? (await git.getStagedFiles());
105
+ const diffText = state.diffText ?? (await git.getDiff(true));
106
+ const typeValidation = validateTypeConsistency(params.type, stagedFiles, {
107
+ diffText,
108
+ summary,
109
+ details: cappedDetails,
110
+ });
111
+
112
+ const errors = [...summaryValidation.errors, ...analysisValidation.errors, ...typeValidation.errors];
113
+ const warnings = [...summaryValidation.warnings, ...detailWarnings, ...typeValidation.warnings];
114
+
115
+ const response: ProposalResponse = {
116
+ valid: errors.length === 0,
117
+ errors,
118
+ warnings,
119
+ };
120
+
121
+ if (response.valid) {
122
+ response.proposal = {
123
+ type: analysis.type,
124
+ scope: analysis.scope,
125
+ summary,
126
+ details: analysis.details,
127
+ issue_refs: analysis.issueRefs,
128
+ };
129
+ state.proposal = {
130
+ analysis,
131
+ summary,
132
+ warnings,
133
+ };
134
+ }
135
+
136
+ const text = JSON.stringify(
137
+ {
138
+ ...response,
139
+ constraints: {
140
+ maxSummaryChars: SUMMARY_MAX_CHARS,
141
+ maxDetailItems: MAX_DETAIL_ITEMS,
142
+ },
143
+ },
144
+ null,
145
+ 2,
146
+ );
147
+
148
+ return {
149
+ content: [{ type: "text", text }],
150
+ details: response,
151
+ };
152
+ },
153
+ };
154
+ }
@@ -0,0 +1,81 @@
1
+ import type { ControlledGit } from "@oh-my-pi/pi-coding-agent/commit/git";
2
+ import type { CustomTool } from "@oh-my-pi/pi-coding-agent/extensibility/custom-tools/types";
3
+ import { Type } from "@sinclair/typebox";
4
+
5
+ const recentCommitsSchema = Type.Object({
6
+ count: Type.Optional(Type.Number({ description: "Number of commits to fetch", minimum: 1, maximum: 50 })),
7
+ });
8
+
9
+ interface RecentCommitStats {
10
+ scopeUsagePercent: number;
11
+ commonVerbs: Record<string, number>;
12
+ summaryLength: { min: number; max: number; average: number };
13
+ lowercaseSummaryPercent: number;
14
+ topScopes: Record<string, number>;
15
+ }
16
+
17
+ function extractSummary(subject: string): string {
18
+ const match = subject.match(/^[a-z]+(?:\([^)]+\))?:\s+(.*)$/i);
19
+ if (match?.[1]) return match[1].trim();
20
+ return subject.trim();
21
+ }
22
+
23
+ function extractScope(subject: string): string | null {
24
+ const match = subject.match(/^[a-z]+\(([^)]+)\):/i);
25
+ return match?.[1]?.trim() ?? null;
26
+ }
27
+
28
+ export function createRecentCommitsTool(git: ControlledGit): CustomTool<typeof recentCommitsSchema> {
29
+ return {
30
+ name: "recent_commits",
31
+ label: "Recent Commits",
32
+ description: "Return recent commit subjects with style statistics.",
33
+ parameters: recentCommitsSchema,
34
+ async execute(_toolCallId, params) {
35
+ const count = params.count ?? 8;
36
+ const commits = await git.getRecentCommits(count);
37
+ const verbs: Record<string, number> = {};
38
+ const scopes: Record<string, number> = {};
39
+ const lengths: number[] = [];
40
+ let scopeCount = 0;
41
+ let lowercaseCount = 0;
42
+
43
+ for (const subject of commits) {
44
+ const summary = extractSummary(subject);
45
+ const scope = extractScope(subject);
46
+ if (scope) {
47
+ scopeCount += 1;
48
+ scopes[scope] = (scopes[scope] ?? 0) + 1;
49
+ }
50
+ if (summary[0] && summary[0] === summary[0].toLowerCase()) {
51
+ lowercaseCount += 1;
52
+ }
53
+ const firstWord = summary.split(/\s+/)[0]?.toLowerCase();
54
+ if (firstWord) {
55
+ verbs[firstWord] = (verbs[firstWord] ?? 0) + 1;
56
+ }
57
+ lengths.push(summary.length);
58
+ }
59
+
60
+ const min = lengths.length > 0 ? Math.min(...lengths) : 0;
61
+ const max = lengths.length > 0 ? Math.max(...lengths) : 0;
62
+ const average = lengths.length > 0 ? lengths.reduce((sum, value) => sum + value, 0) / lengths.length : 0;
63
+ const scopeUsagePercent = commits.length > 0 ? Math.round((scopeCount / commits.length) * 100) : 0;
64
+ const lowercaseSummaryPercent = commits.length > 0 ? Math.round((lowercaseCount / commits.length) * 100) : 0;
65
+
66
+ const stats: RecentCommitStats = {
67
+ scopeUsagePercent,
68
+ commonVerbs: verbs,
69
+ summaryLength: { min, max, average: Number(average.toFixed(1)) },
70
+ lowercaseSummaryPercent,
71
+ topScopes: scopes,
72
+ };
73
+
74
+ const payload = { commits, stats };
75
+ return {
76
+ content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
77
+ details: payload,
78
+ };
79
+ },
80
+ };
81
+ }
@@ -0,0 +1,284 @@
1
+ import type {
2
+ CommitAgentState,
3
+ SplitCommitGroup,
4
+ SplitCommitPlan,
5
+ } from "@oh-my-pi/pi-coding-agent/commit/agentic/state";
6
+ import { computeDependencyOrder } from "@oh-my-pi/pi-coding-agent/commit/agentic/topo-sort";
7
+ import {
8
+ capDetails,
9
+ MAX_DETAIL_ITEMS,
10
+ normalizeSummary,
11
+ SUMMARY_MAX_CHARS,
12
+ validateSummaryRules,
13
+ validateTypeConsistency,
14
+ } from "@oh-my-pi/pi-coding-agent/commit/agentic/validation";
15
+ import { validateScope } from "@oh-my-pi/pi-coding-agent/commit/analysis/validation";
16
+ import type { ControlledGit } from "@oh-my-pi/pi-coding-agent/commit/git";
17
+ import type { ConventionalDetail } from "@oh-my-pi/pi-coding-agent/commit/types";
18
+ import type { CustomTool } from "@oh-my-pi/pi-coding-agent/extensibility/custom-tools/types";
19
+ import { Type } from "@sinclair/typebox";
20
+
21
+ const commitTypeSchema = Type.Union([
22
+ Type.Literal("feat"),
23
+ Type.Literal("fix"),
24
+ Type.Literal("refactor"),
25
+ Type.Literal("perf"),
26
+ Type.Literal("docs"),
27
+ Type.Literal("test"),
28
+ Type.Literal("build"),
29
+ Type.Literal("ci"),
30
+ Type.Literal("chore"),
31
+ Type.Literal("style"),
32
+ Type.Literal("revert"),
33
+ ]);
34
+
35
+ const detailSchema = Type.Object({
36
+ text: Type.String(),
37
+ changelog_category: Type.Optional(
38
+ Type.Union([
39
+ Type.Literal("Added"),
40
+ Type.Literal("Changed"),
41
+ Type.Literal("Fixed"),
42
+ Type.Literal("Deprecated"),
43
+ Type.Literal("Removed"),
44
+ Type.Literal("Security"),
45
+ Type.Literal("Breaking Changes"),
46
+ ]),
47
+ ),
48
+ user_visible: Type.Optional(Type.Boolean()),
49
+ });
50
+
51
+ const hunkSelectorSchema = Type.Union([
52
+ Type.Object({ type: Type.Literal("all") }),
53
+ Type.Object({ type: Type.Literal("indices"), indices: Type.Array(Type.Number(), { minItems: 1 }) }),
54
+ Type.Object({ type: Type.Literal("lines"), start: Type.Number(), end: Type.Number() }),
55
+ ]);
56
+
57
+ const fileChangeSchema = Type.Object({
58
+ path: Type.String(),
59
+ hunks: hunkSelectorSchema,
60
+ });
61
+
62
+ const splitCommitSchema = Type.Object({
63
+ commits: Type.Array(
64
+ Type.Object({
65
+ changes: Type.Array(fileChangeSchema, { minItems: 1 }),
66
+ type: commitTypeSchema,
67
+ scope: Type.Union([Type.String(), Type.Null()]),
68
+ summary: Type.String(),
69
+ details: Type.Optional(Type.Array(detailSchema)),
70
+ issue_refs: Type.Optional(Type.Array(Type.String())),
71
+ rationale: Type.Optional(Type.String()),
72
+ dependencies: Type.Optional(Type.Array(Type.Number())),
73
+ }),
74
+ { minItems: 2 },
75
+ ),
76
+ });
77
+
78
+ interface SplitCommitResponse {
79
+ valid: boolean;
80
+ errors: string[];
81
+ warnings: string[];
82
+ proposal?: SplitCommitPlan;
83
+ }
84
+
85
+ function normalizeDetails(
86
+ details: Array<{
87
+ text: string;
88
+ changelog_category?: ConventionalDetail["changelogCategory"];
89
+ user_visible?: boolean;
90
+ }>,
91
+ ): ConventionalDetail[] {
92
+ return details.map((detail) => ({
93
+ text: detail.text.trim(),
94
+ changelogCategory: detail.user_visible ? detail.changelog_category : undefined,
95
+ userVisible: detail.user_visible ?? false,
96
+ }));
97
+ }
98
+
99
+ export function createSplitCommitTool(
100
+ git: ControlledGit,
101
+ state: CommitAgentState,
102
+ changelogTargets: string[],
103
+ ): CustomTool<typeof splitCommitSchema> {
104
+ return {
105
+ name: "split_commit",
106
+ label: "Split Commit",
107
+ description: "Propose multiple atomic commits for unrelated changes.",
108
+ parameters: splitCommitSchema,
109
+ async execute(_toolCallId, params) {
110
+ const stagedFiles = state.overview?.files ?? (await git.getStagedFiles());
111
+ const stagedSet = new Set(stagedFiles);
112
+ const changelogSet = new Set(changelogTargets);
113
+ const usedFiles = new Set<string>();
114
+ const errors: string[] = [];
115
+ const warnings: string[] = [];
116
+ const diffText = await git.getDiff(true);
117
+
118
+ const commits: SplitCommitGroup[] = params.commits.map((commit, index) => {
119
+ const scope = commit.scope?.trim() || null;
120
+ const summary = normalizeSummary(commit.summary, commit.type, scope);
121
+ const detailInput = normalizeDetails(commit.details ?? []);
122
+ const detailResult = capDetails(detailInput);
123
+ warnings.push(...detailResult.warnings.map((warning) => `Commit ${index + 1}: ${warning}`));
124
+ const issueRefs = commit.issue_refs ?? [];
125
+ const dependencies = (commit.dependencies ?? []).map((dep) => Math.floor(dep));
126
+ const changes = commit.changes.map((change) => ({
127
+ path: change.path,
128
+ hunks: change.hunks,
129
+ }));
130
+ const files = changes.map((change) => change.path);
131
+
132
+ const summaryValidation = validateSummaryRules(summary);
133
+ const scopeValidation = validateScope(scope);
134
+ const typeValidation = validateTypeConsistency(commit.type, files, {
135
+ diffText,
136
+ summary,
137
+ details: detailResult.details,
138
+ });
139
+
140
+ if (summaryValidation.errors.length > 0) {
141
+ errors.push(...summaryValidation.errors.map((error) => `Commit ${index + 1}: ${error}`));
142
+ }
143
+ if (!scopeValidation.valid) {
144
+ errors.push(...scopeValidation.errors.map((error) => `Commit ${index + 1}: ${error}`));
145
+ }
146
+ if (typeValidation.errors.length > 0) {
147
+ errors.push(...typeValidation.errors.map((error) => `Commit ${index + 1}: ${error}`));
148
+ }
149
+ warnings.push(...summaryValidation.warnings.map((warning) => `Commit ${index + 1}: ${warning}`));
150
+ warnings.push(...typeValidation.warnings.map((warning) => `Commit ${index + 1}: ${warning}`));
151
+ const hunkValidation = validateHunkSelectors(index, changes, files);
152
+ warnings.push(...hunkValidation.warnings);
153
+ errors.push(...hunkValidation.errors);
154
+ errors.push(...validateDependencies(index, dependencies, params.commits.length));
155
+
156
+ return {
157
+ changes,
158
+ type: commit.type,
159
+ scope,
160
+ summary,
161
+ details: detailResult.details,
162
+ issueRefs,
163
+ rationale: commit.rationale?.trim() || undefined,
164
+ dependencies,
165
+ };
166
+ });
167
+
168
+ for (const commit of commits) {
169
+ const seen = new Set<string>();
170
+ for (const change of commit.changes) {
171
+ const file = change.path;
172
+ if (!stagedSet.has(file) && !changelogSet.has(file)) {
173
+ errors.push(`File not staged: ${file}`);
174
+ continue;
175
+ }
176
+ if (seen.has(file)) {
177
+ errors.push(`File listed multiple times in commit ${commit.summary}: ${file}`);
178
+ continue;
179
+ }
180
+ if (usedFiles.has(file)) {
181
+ errors.push(`File appears in multiple commits: ${file}`);
182
+ continue;
183
+ }
184
+ seen.add(file);
185
+ usedFiles.add(file);
186
+ }
187
+ }
188
+
189
+ for (const file of stagedFiles) {
190
+ if (!usedFiles.has(file)) {
191
+ errors.push(`Staged file missing from split plan: ${file}`);
192
+ }
193
+ }
194
+
195
+ const dependencyCheck = computeDependencyOrder(commits);
196
+ if ("error" in dependencyCheck) {
197
+ errors.push(dependencyCheck.error);
198
+ }
199
+
200
+ const response: SplitCommitResponse = {
201
+ valid: errors.length === 0,
202
+ errors,
203
+ warnings,
204
+ };
205
+
206
+ if (response.valid) {
207
+ response.proposal = { commits, warnings };
208
+ state.splitProposal = response.proposal;
209
+ }
210
+
211
+ const text = JSON.stringify(
212
+ {
213
+ ...response,
214
+ constraints: {
215
+ maxSummaryChars: SUMMARY_MAX_CHARS,
216
+ maxDetailItems: MAX_DETAIL_ITEMS,
217
+ },
218
+ },
219
+ null,
220
+ 2,
221
+ );
222
+
223
+ return {
224
+ content: [{ type: "text", text }],
225
+ details: response,
226
+ };
227
+ },
228
+ };
229
+ }
230
+
231
+ function validateHunkSelectors(
232
+ commitIndex: number,
233
+ changes: SplitCommitGroup["changes"],
234
+ files: string[],
235
+ ): { errors: string[]; warnings: string[] } {
236
+ const errors: string[] = [];
237
+ const warnings: string[] = [];
238
+ const prefix = `Commit ${commitIndex + 1}`;
239
+ if (files.length === 0) {
240
+ errors.push(`${prefix}: no files specified`);
241
+ return { errors, warnings };
242
+ }
243
+ for (const change of changes) {
244
+ if (change.hunks.type === "indices") {
245
+ const invalid = change.hunks.indices.filter(
246
+ (value) => !Number.isFinite(value) || Math.floor(value) !== value || value < 1,
247
+ );
248
+ if (invalid.length > 0) {
249
+ errors.push(`${prefix}: invalid hunk indices for ${change.path}`);
250
+ }
251
+ continue;
252
+ }
253
+ if (change.hunks.type === "lines") {
254
+ const { start, end } = change.hunks;
255
+ if (!Number.isFinite(start) || !Number.isFinite(end)) {
256
+ errors.push(`${prefix}: invalid line range for ${change.path}`);
257
+ continue;
258
+ }
259
+ if (Math.floor(start) !== start || Math.floor(end) !== end || start < 1 || end < start) {
260
+ errors.push(`${prefix}: invalid line range for ${change.path}`);
261
+ }
262
+ }
263
+ }
264
+ return { errors, warnings };
265
+ }
266
+
267
+ function validateDependencies(commitIndex: number, dependencies: number[], totalCommits: number): string[] {
268
+ const errors: string[] = [];
269
+ const prefix = `Commit ${commitIndex + 1}`;
270
+ for (const dependency of dependencies) {
271
+ if (!Number.isFinite(dependency) || Math.floor(dependency) !== dependency) {
272
+ errors.push(`${prefix}: dependency index must be an integer`);
273
+ continue;
274
+ }
275
+ if (dependency === commitIndex) {
276
+ errors.push(`${prefix}: cannot depend on itself`);
277
+ continue;
278
+ }
279
+ if (dependency < 0 || dependency >= totalCommits) {
280
+ errors.push(`${prefix}: dependency index out of range (${dependency})`);
281
+ }
282
+ }
283
+ return errors;
284
+ }
@@ -0,0 +1,44 @@
1
+ import type { SplitCommitGroup } from "@oh-my-pi/pi-coding-agent/commit/agentic/state";
2
+
3
+ export function computeDependencyOrder(groups: SplitCommitGroup[]): number[] | { error: string } {
4
+ const total = groups.length;
5
+ const inDegree = new Array<number>(total).fill(0);
6
+ const edges = Array.from({ length: total }, () => new Set<number>());
7
+
8
+ for (let index = 0; index < total; index += 1) {
9
+ const dependencies = groups[index]?.dependencies ?? [];
10
+ for (const dependency of dependencies) {
11
+ if (dependency < 0 || dependency >= total) {
12
+ return { error: `Invalid dependency index: ${dependency}` };
13
+ }
14
+ if (!edges[dependency]?.has(index)) {
15
+ edges[dependency]?.add(index);
16
+ inDegree[index] += 1;
17
+ }
18
+ }
19
+ }
20
+
21
+ const queue: number[] = [];
22
+ for (let index = 0; index < total; index += 1) {
23
+ if (inDegree[index] === 0) queue.push(index);
24
+ }
25
+
26
+ const order: number[] = [];
27
+ while (queue.length > 0) {
28
+ const current = queue.shift();
29
+ if (current === undefined) break;
30
+ order.push(current);
31
+ for (const next of edges[current] ?? []) {
32
+ inDegree[next] -= 1;
33
+ if (inDegree[next] === 0) {
34
+ queue.push(next);
35
+ }
36
+ }
37
+ }
38
+
39
+ if (order.length !== total) {
40
+ return { error: "Circular dependency detected in split commit plan." };
41
+ }
42
+
43
+ return order;
44
+ }
@@ -0,0 +1,51 @@
1
+ import type { CommitType } from "@oh-my-pi/pi-coding-agent/commit/types";
2
+
3
+ export interface TrivialChangeResult {
4
+ isTrivial: true;
5
+ type: CommitType;
6
+ summary: string;
7
+ }
8
+
9
+ const WHITESPACE_ONLY_PATTERN = /^[-+][\t ]*$/;
10
+ const IMPORT_LINE_PATTERN = /^[-+]\s*(import\s|from\s|export\s.*from|require\(|module\.exports)/;
11
+ const EMPTY_LINE_PATTERN = /^[-+]\s*$/;
12
+
13
+ export function detectTrivialChange(diff: string): TrivialChangeResult | null {
14
+ const lines = diff.split("\n");
15
+ const changeLines = lines.filter((line) => line.startsWith("+") || line.startsWith("-"));
16
+ const contentLines = changeLines.filter(
17
+ (line) => !line.startsWith("+++") && !line.startsWith("---") && !line.startsWith("@@"),
18
+ );
19
+
20
+ if (contentLines.length === 0) return null;
21
+
22
+ if (isOnlyWhitespace(contentLines)) {
23
+ return { isTrivial: true, type: "style", summary: "formatted code" };
24
+ }
25
+
26
+ if (isOnlyImports(contentLines)) {
27
+ return { isTrivial: true, type: "style", summary: "reorganized imports" };
28
+ }
29
+
30
+ return null;
31
+ }
32
+
33
+ function isOnlyWhitespace(lines: string[]): boolean {
34
+ for (const line of lines) {
35
+ const content = line.slice(1);
36
+ if (content.trim().length > 0 && !WHITESPACE_ONLY_PATTERN.test(line)) {
37
+ return false;
38
+ }
39
+ }
40
+ return true;
41
+ }
42
+
43
+ function isOnlyImports(lines: string[]): boolean {
44
+ for (const line of lines) {
45
+ if (EMPTY_LINE_PATTERN.test(line)) continue;
46
+ if (!IMPORT_LINE_PATTERN.test(line)) {
47
+ return false;
48
+ }
49
+ }
50
+ return true;
51
+ }