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.
Files changed (2) hide show
  1. package/dist/index.js +30 -8
  2. 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 verbatim. Do not call other tools.",
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
- // Find the longest project name for alignment
293
- const maxNameLen = Math.max(...projects.map((p) => p.field.length), "Total".length);
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 (const p of projects) {
296
- const name = p.field.padEnd(maxNameLen + 2);
297
- lines.push(` ${name}${formatMinutes(p.minutes)}`);
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 + 8)}`);
300
- lines.push(` ${"Total".padEnd(maxNameLen + 2)}${formatMinutes(totalMinutes)}`);
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-codetime",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "description": "CodeTime plugin for OpenCode - Track AI coding activity and time spent with codetime.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",