opencode-codetime 0.1.0 → 0.2.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/dist/index.js +39 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as os from "node:os";
|
|
2
2
|
import * as path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { tool } from "@opencode-ai/plugin/tool";
|
|
4
|
+
import { sendHeartbeat, validateToken, getTodayMinutes, } from "./codetime.js";
|
|
4
5
|
import { getGitBranch, getGitOrigin } from "./git.js";
|
|
5
6
|
import { detectLanguage } from "./language.js";
|
|
6
7
|
import { initLogger, info, warn, error, debug } from "./logger.js";
|
|
@@ -134,6 +135,18 @@ function pruneProcessedIds() {
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
}
|
|
138
|
+
// ---- Time formatting ----
|
|
139
|
+
function formatMinutes(minutes) {
|
|
140
|
+
if (minutes < 1)
|
|
141
|
+
return "0m";
|
|
142
|
+
const hours = Math.floor(minutes / 60);
|
|
143
|
+
const mins = Math.round(minutes % 60);
|
|
144
|
+
if (hours === 0)
|
|
145
|
+
return `${mins}m`;
|
|
146
|
+
if (mins === 0)
|
|
147
|
+
return `${hours}h`;
|
|
148
|
+
return `${hours}h ${mins}m`;
|
|
149
|
+
}
|
|
137
150
|
// ---- Plugin entry point ----
|
|
138
151
|
export const plugin = async (ctx) => {
|
|
139
152
|
try {
|
|
@@ -166,7 +179,7 @@ export const plugin = async (ctx) => {
|
|
|
166
179
|
initState();
|
|
167
180
|
_projectDir = directory;
|
|
168
181
|
_worktree = worktree;
|
|
169
|
-
_projectName = path.basename(directory)
|
|
182
|
+
_projectName = `[opencode] ${path.basename(directory)}`;
|
|
170
183
|
_platform = os.platform();
|
|
171
184
|
// Fetch git info
|
|
172
185
|
if (worktree) {
|
|
@@ -231,6 +244,30 @@ export const plugin = async (ctx) => {
|
|
|
231
244
|
await error("Chat message handler error", { error: String(err) }).catch(() => { });
|
|
232
245
|
}
|
|
233
246
|
},
|
|
247
|
+
tool: {
|
|
248
|
+
codetime: tool({
|
|
249
|
+
description: "Show today's coding time tracked by CodeTime. " +
|
|
250
|
+
"Use this when the user asks about their coding time, " +
|
|
251
|
+
"how long they've been coding, or wants to see their CodeTime stats.",
|
|
252
|
+
args: {},
|
|
253
|
+
async execute() {
|
|
254
|
+
if (!_token) {
|
|
255
|
+
return "CodeTime is not configured. Set CODETIME_TOKEN environment variable to enable tracking. Get your token from https://codetime.dev/dashboard/settings";
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
const minutes = await getTodayMinutes(_token);
|
|
259
|
+
if (minutes === null) {
|
|
260
|
+
return "Failed to fetch coding time from CodeTime API.";
|
|
261
|
+
}
|
|
262
|
+
const formatted = formatMinutes(minutes);
|
|
263
|
+
return `Today's coding time: ${formatted}`;
|
|
264
|
+
}
|
|
265
|
+
catch (err) {
|
|
266
|
+
return `Failed to fetch coding time: ${String(err)}`;
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
}),
|
|
270
|
+
},
|
|
234
271
|
};
|
|
235
272
|
}
|
|
236
273
|
catch (err) {
|