opencode-codetime 0.5.1 → 0.6.1
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 +30 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -163,6 +163,22 @@ function formatMinutes(minutes) {
|
|
|
163
163
|
return `${hours}h`;
|
|
164
164
|
return `${hours}h ${mins}m`;
|
|
165
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Format a project field for display by wrapping the suffix in brackets.
|
|
168
|
+
* If the field already contains '[', it's returned as-is.
|
|
169
|
+
* Otherwise, everything after the first space is treated as a suffix.
|
|
170
|
+
* E.g. "test WSL: Ubuntu-24.04" → "test [WSL: Ubuntu-24.04]"
|
|
171
|
+
*/
|
|
172
|
+
function formatProjectName(field) {
|
|
173
|
+
if (field.includes("["))
|
|
174
|
+
return field;
|
|
175
|
+
const spaceIdx = field.indexOf(" ");
|
|
176
|
+
if (spaceIdx === -1)
|
|
177
|
+
return field;
|
|
178
|
+
const name = field.substring(0, spaceIdx);
|
|
179
|
+
const suffix = field.substring(spaceIdx + 1);
|
|
180
|
+
return `${name} [${suffix}]`;
|
|
181
|
+
}
|
|
166
182
|
// ---- Plugin entry point ----
|
|
167
183
|
export const plugin = async (ctx) => {
|
|
168
184
|
try {
|
|
@@ -262,7 +278,7 @@ export const plugin = async (ctx) => {
|
|
|
262
278
|
'- If no arguments (empty/blank), call `codetime` with `project: "current"` to show current project time.\n' +
|
|
263
279
|
"- If the argument is `breakdown`, call `codetime` with `breakdown: true` to show all projects.\n" +
|
|
264
280
|
"- Otherwise, call `codetime` with `project` set to the argument value to show that specific project's time.\n\n" +
|
|
265
|
-
"Return the output
|
|
281
|
+
"IMPORTANT: Return ONLY the exact output from the codetime tool, with absolutely no additional text, formatting, markdown, explanation, or commentary before or after it. Do not wrap it in code blocks. Do not add any other text.",
|
|
266
282
|
};
|
|
267
283
|
},
|
|
268
284
|
tool: {
|
|
@@ -289,15 +305,21 @@ export const plugin = async (ctx) => {
|
|
|
289
305
|
}
|
|
290
306
|
// Calculate total
|
|
291
307
|
const totalMinutes = projects.reduce((sum, p) => sum + p.minutes, 0);
|
|
292
|
-
//
|
|
293
|
-
const
|
|
308
|
+
// Pre-compute display names and formatted times
|
|
309
|
+
const displayNames = projects.map((p) => formatProjectName(p.field));
|
|
310
|
+
const formattedTimes = projects.map((p) => formatMinutes(p.minutes));
|
|
311
|
+
const totalTime = formatMinutes(totalMinutes);
|
|
312
|
+
// Find the longest display name and time for alignment
|
|
313
|
+
const maxNameLen = Math.max(...displayNames.map((n) => n.length), "Total".length);
|
|
314
|
+
const maxTimeLen = Math.max(...formattedTimes.map((t) => t.length), totalTime.length);
|
|
294
315
|
const lines = ["Today's coding time by project:", ""];
|
|
295
|
-
for (
|
|
296
|
-
const name =
|
|
297
|
-
|
|
316
|
+
for (let i = 0; i < projects.length; i++) {
|
|
317
|
+
const name = displayNames[i].padEnd(maxNameLen + 2);
|
|
318
|
+
const time = formattedTimes[i].padStart(maxTimeLen);
|
|
319
|
+
lines.push(` ${name}${time}`);
|
|
298
320
|
}
|
|
299
|
-
lines.push(` ${"─".repeat(maxNameLen + 2 +
|
|
300
|
-
lines.push(` ${"Total".padEnd(maxNameLen + 2)}${
|
|
321
|
+
lines.push(` ${"─".repeat(maxNameLen + 2 + maxTimeLen)}`);
|
|
322
|
+
lines.push(` ${"Total".padEnd(maxNameLen + 2)}${totalTime.padStart(maxTimeLen)}`);
|
|
301
323
|
return lines.join("\n");
|
|
302
324
|
}
|
|
303
325
|
// Project-specific mode
|