@andre-barbosa/opencode-commit 0.1.4 → 0.1.6
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/dist/index.js +20 -35
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,10 +4,12 @@ import { buildCommitGroups, parseCommitRequest, parseModelRef, resolveConfig, }
|
|
|
4
4
|
const COMMAND_NAME = "commit";
|
|
5
5
|
const COMMAND_DESCRIPTION = "Generate a commit message or split commit plan from uncommitted changes";
|
|
6
6
|
const COMMAND_TEMPLATE = "Handled by the opencode-commit plugin.";
|
|
7
|
-
const SKIP_ERROR = "skip";
|
|
8
7
|
function textPart(text) {
|
|
9
8
|
return { type: "text", text };
|
|
10
9
|
}
|
|
10
|
+
function replaceOutputParts(output, ...parts) {
|
|
11
|
+
output.parts.splice(0, output.parts.length, ...parts);
|
|
12
|
+
}
|
|
11
13
|
function formatOutput(input) {
|
|
12
14
|
if (input.request.mode === "split") {
|
|
13
15
|
const missingFolders = input.missingFolders ?? [];
|
|
@@ -43,9 +45,6 @@ function formatOutput(input) {
|
|
|
43
45
|
function formatFolderList(folders) {
|
|
44
46
|
return folders.map((folder) => `\`${folder}\``).join(", ");
|
|
45
47
|
}
|
|
46
|
-
const skipCommand = () => {
|
|
47
|
-
throw new Error(SKIP_ERROR);
|
|
48
|
-
};
|
|
49
48
|
export const OpenCodeCommitPlugin = async ({ client, $, worktree }, options) => {
|
|
50
49
|
const config = resolveConfig(options);
|
|
51
50
|
const log = async (level, message, extra) => {
|
|
@@ -66,7 +65,6 @@ export const OpenCodeCommitPlugin = async ({ client, $, worktree }, options) =>
|
|
|
66
65
|
cfg.command[COMMAND_NAME] = {
|
|
67
66
|
description: COMMAND_DESCRIPTION,
|
|
68
67
|
template: COMMAND_TEMPLATE,
|
|
69
|
-
subtask: true,
|
|
70
68
|
};
|
|
71
69
|
if (config.model) {
|
|
72
70
|
cfg.command[COMMAND_NAME].model = config.model;
|
|
@@ -77,30 +75,24 @@ export const OpenCodeCommitPlugin = async ({ client, $, worktree }, options) =>
|
|
|
77
75
|
return;
|
|
78
76
|
try {
|
|
79
77
|
if (!config.model) {
|
|
80
|
-
output
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
];
|
|
88
|
-
return skipCommand();
|
|
78
|
+
replaceOutputParts(output, textPart([
|
|
79
|
+
"No commit model configured.",
|
|
80
|
+
"",
|
|
81
|
+
"Add a `model` option to the opencode-commit plugin config, for example:",
|
|
82
|
+
"`[\"@andre-barbosa/opencode-commit\", { \"model\": \"opencode-go/deepseek-v4-flash\" }]`",
|
|
83
|
+
].join("\n")));
|
|
84
|
+
return;
|
|
89
85
|
}
|
|
90
86
|
const model = parseModelRef(config.model);
|
|
91
87
|
const request = parseCommitRequest(input.arguments);
|
|
92
88
|
if (!(await isGitRepo($, worktree))) {
|
|
93
|
-
output.
|
|
94
|
-
|
|
95
|
-
];
|
|
96
|
-
return skipCommand();
|
|
89
|
+
replaceOutputParts(output, textPart("Not a git repository. Run `/commit` from inside a git worktree."));
|
|
90
|
+
return;
|
|
97
91
|
}
|
|
98
92
|
const context = await gatherGitContext($, worktree, config.maxDiffChars);
|
|
99
93
|
if (!context.hasUncommittedChanges) {
|
|
100
|
-
output.
|
|
101
|
-
|
|
102
|
-
];
|
|
103
|
-
return skipCommand();
|
|
94
|
+
replaceOutputParts(output, textPart("No uncommitted changes found. Make changes and run `/commit` again."));
|
|
95
|
+
return;
|
|
104
96
|
}
|
|
105
97
|
let groups;
|
|
106
98
|
let missingFolders = [];
|
|
@@ -112,8 +104,8 @@ export const OpenCodeCommitPlugin = async ({ client, $, worktree }, options) =>
|
|
|
112
104
|
const target = request.folders.length > 0
|
|
113
105
|
? `requested folder(s): ${formatFolderList(request.folders)}`
|
|
114
106
|
: "changed folders";
|
|
115
|
-
output
|
|
116
|
-
return
|
|
107
|
+
replaceOutputParts(output, textPart(`No changes found for ${target}.`));
|
|
108
|
+
return;
|
|
117
109
|
}
|
|
118
110
|
}
|
|
119
111
|
await log("info", "Generating commit message", {
|
|
@@ -131,23 +123,16 @@ export const OpenCodeCommitPlugin = async ({ client, $, worktree }, options) =>
|
|
|
131
123
|
request,
|
|
132
124
|
groups,
|
|
133
125
|
});
|
|
134
|
-
output
|
|
135
|
-
|
|
136
|
-
];
|
|
137
|
-
return skipCommand();
|
|
126
|
+
replaceOutputParts(output, textPart(formatOutput({ ...result, request, missingFolders })));
|
|
127
|
+
return;
|
|
138
128
|
}
|
|
139
129
|
catch (error) {
|
|
140
|
-
if (error instanceof Error && error.message === SKIP_ERROR) {
|
|
141
|
-
throw error;
|
|
142
|
-
}
|
|
143
130
|
await log("error", "Commit message generation failed", {
|
|
144
131
|
error: String(error),
|
|
145
132
|
sessionID: input.sessionID,
|
|
146
133
|
});
|
|
147
|
-
output
|
|
148
|
-
|
|
149
|
-
];
|
|
150
|
-
return skipCommand();
|
|
134
|
+
replaceOutputParts(output, textPart(`Failed to generate commit message: ${String(error)}`));
|
|
135
|
+
return;
|
|
151
136
|
}
|
|
152
137
|
},
|
|
153
138
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andre-barbosa/opencode-commit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "OpenCode plugin that generates Conventional Commit messages and split commit plans via /commit using a configured model",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|