@yhong91/vibetime 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.
Files changed (2) hide show
  1. package/bin/vibetime.mjs +129 -4
  2. package/package.json +1 -1
package/bin/vibetime.mjs CHANGED
@@ -1195,7 +1195,7 @@ function countTextLines(text) {
1195
1195
  }
1196
1196
 
1197
1197
  // src/lib/constants.ts
1198
- var PACKAGE_VERSION = true ? "0.1.4" : "0.1.1";
1198
+ var PACKAGE_VERSION = true ? "0.1.6" : "0.1.1";
1199
1199
  var DEFAULT_API_URL = "http://121.196.224.82:3001";
1200
1200
  var DEFAULT_BACKFILL_BATCH_SIZE = 50;
1201
1201
  var DEFAULT_BACKFILL_BATCH_BYTES = 800 * 1024;
@@ -3024,6 +3024,7 @@ function createClaudeCoworkAdapter() {
3024
3024
  // src/adapters/codebuddy.ts
3025
3025
  import { readFile as readFile5, readdir as readdir4 } from "node:fs/promises";
3026
3026
  import path8 from "node:path";
3027
+ var ENDPOINT_MODEL_ID_RE = /^(?:ep|endpoint)-/i;
3027
3028
  async function parseCodebuddyTraceFile(filePath, options) {
3028
3029
  const text = await readFile5(filePath, "utf8");
3029
3030
  const sourcePathHash = `sha256:${createStableHash(filePath)}`;
@@ -3051,7 +3052,7 @@ async function parseCodebuddyTraceFile(filePath, options) {
3051
3052
  }
3052
3053
  const project = cwd ? path8.basename(cwd) : void 0;
3053
3054
  const workspaceId = createWorkspaceId({ projectName: project, repoRoot: cwd });
3054
- const model = trace.modelInfo?.models?.[0];
3055
+ const model = resolveCodebuddyModel(trace, spans);
3055
3056
  const baseEvent = (event) => ({
3056
3057
  schemaVersion: AGENT_TIME_SCHEMA_VERSION,
3057
3058
  source: "codebuddy",
@@ -3314,6 +3315,87 @@ async function parseCodebuddyTraceFile(filePath, options) {
3314
3315
  }
3315
3316
  return events.filter((event) => validateCanonicalEvent(event).valid);
3316
3317
  }
3318
+ function resolveCodebuddyModel(trace, spans) {
3319
+ const spanModel = modelFromSpans(spans);
3320
+ if (spanModel) {
3321
+ return spanModel;
3322
+ }
3323
+ const metadataModel = findHumanModelName(trace.metadata);
3324
+ if (metadataModel) {
3325
+ return metadataModel;
3326
+ }
3327
+ for (const candidate of trace.modelInfo?.models || []) {
3328
+ const normalized = normalizeModelCandidate(candidate);
3329
+ if (normalized) {
3330
+ return normalized;
3331
+ }
3332
+ }
3333
+ return void 0;
3334
+ }
3335
+ function modelFromSpans(spans) {
3336
+ for (const span of spans) {
3337
+ const parsedOutput = parseEmbeddedJson(span.toolOutput);
3338
+ const outputModel = findHumanModelName(parsedOutput);
3339
+ if (outputModel) {
3340
+ return outputModel;
3341
+ }
3342
+ const parsedInput = parseEmbeddedJson(span.toolInput);
3343
+ const inputModel = findHumanModelName(parsedInput);
3344
+ if (inputModel) {
3345
+ return inputModel;
3346
+ }
3347
+ }
3348
+ return void 0;
3349
+ }
3350
+ function parseEmbeddedJson(value) {
3351
+ if (!value?.trim()) {
3352
+ return void 0;
3353
+ }
3354
+ try {
3355
+ return JSON.parse(value);
3356
+ } catch {
3357
+ return void 0;
3358
+ }
3359
+ }
3360
+ function findHumanModelName(value) {
3361
+ const queue = [value];
3362
+ while (queue.length > 0) {
3363
+ const current = queue.shift();
3364
+ if (Array.isArray(current)) {
3365
+ queue.push(...current);
3366
+ continue;
3367
+ }
3368
+ if (!isPlainObject(current)) {
3369
+ continue;
3370
+ }
3371
+ const preferred = [
3372
+ stringField(current, "requestModelName"),
3373
+ stringField(current, "modelName"),
3374
+ stringField(current, "model_name"),
3375
+ stringField(current, "model"),
3376
+ stringField(current, "requestModelId"),
3377
+ stringField(current, "modelId")
3378
+ ];
3379
+ for (const candidate of preferred) {
3380
+ const normalized = normalizeModelCandidate(candidate);
3381
+ if (normalized) {
3382
+ return normalized;
3383
+ }
3384
+ }
3385
+ queue.push(...Object.values(current));
3386
+ }
3387
+ return void 0;
3388
+ }
3389
+ function normalizeModelCandidate(value) {
3390
+ if (!value) {
3391
+ return void 0;
3392
+ }
3393
+ const trimmed = value.trim();
3394
+ if (!trimmed || ENDPOINT_MODEL_ID_RE.test(trimmed)) {
3395
+ return void 0;
3396
+ }
3397
+ return trimmed;
3398
+ }
3317
3399
  function modelUsageFromTrace(trace, generationIndex, totalGenerations) {
3318
3400
  const info = trace.modelInfo;
3319
3401
  if (!info || !info.totalInputTokens && !info.totalOutputTokens && !trace.totalTokens) {
@@ -6914,7 +6996,7 @@ function createWorkbuddyAdapter() {
6914
6996
 
6915
6997
  // src/adapters/zcode.ts
6916
6998
  import { execFile } from "node:child_process";
6917
- import { stat as stat8 } from "node:fs/promises";
6999
+ import { readFile as readFile11, stat as stat8 } from "node:fs/promises";
6918
7000
  import path15 from "node:path";
6919
7001
  import { promisify as promisify2 } from "node:util";
6920
7002
  init_fs();
@@ -6929,6 +7011,34 @@ function zcodeCliDir(home, env) {
6929
7011
  function zcodeDbPath(home, env) {
6930
7012
  return path15.join(zcodeCliDir(home, env), "db", "db.sqlite");
6931
7013
  }
7014
+ var providerNameCache = null;
7015
+ async function loadProviderNames(configPath2) {
7016
+ let fileMtime = 0;
7017
+ try {
7018
+ const info = await stat8(configPath2);
7019
+ fileMtime = info.mtimeMs;
7020
+ } catch {
7021
+ return /* @__PURE__ */ new Map();
7022
+ }
7023
+ if (providerNameCache && providerNameCache.path === configPath2 && providerNameCache.mtimeMs === fileMtime) {
7024
+ return providerNameCache.map;
7025
+ }
7026
+ const map = /* @__PURE__ */ new Map();
7027
+ try {
7028
+ const raw = await readFile11(configPath2, "utf-8");
7029
+ const config = JSON.parse(raw);
7030
+ const providers = config?.provider;
7031
+ if (isPlainObject(providers)) {
7032
+ for (const [id, entry] of Object.entries(providers)) {
7033
+ const name = stringField(entry, "name");
7034
+ if (name) map.set(id, name);
7035
+ }
7036
+ }
7037
+ } catch {
7038
+ }
7039
+ providerNameCache = { path: configPath2, mtimeMs: fileMtime, map };
7040
+ return map;
7041
+ }
6932
7042
  function sourceHash2(filePath) {
6933
7043
  return `sha256:${createStableHash(filePath)}`;
6934
7044
  }
@@ -7089,6 +7199,21 @@ async function parseZCodeDb(filePath, options) {
7089
7199
  if (rows.length === 0) {
7090
7200
  return [];
7091
7201
  }
7202
+ let candidate = path15.resolve(filePath);
7203
+ let configPath2 = "";
7204
+ for (let i = 0; i < 12; i++) {
7205
+ const probe = path15.join(candidate, ".zcode", "v2", "config.json");
7206
+ try {
7207
+ await stat8(probe);
7208
+ configPath2 = probe;
7209
+ break;
7210
+ } catch {
7211
+ const parent = path15.dirname(candidate);
7212
+ if (parent === candidate) break;
7213
+ candidate = parent;
7214
+ }
7215
+ }
7216
+ const nameMap = configPath2 ? await loadProviderNames(configPath2) : /* @__PURE__ */ new Map();
7092
7217
  const sessions = /* @__PURE__ */ new Map();
7093
7218
  for (const row of rows) {
7094
7219
  if (row.kind === "session") {
@@ -7216,7 +7341,7 @@ async function parseZCodeDb(filePath, options) {
7216
7341
  sessionId: ctx.sessionId,
7217
7342
  turnId: stringField(row, "turn_id") ? `zcode:${stringField(row, "turn_id")}` : void 0,
7218
7343
  agent: stringField(row, "agent") || "zcode",
7219
- provider: stringField(row, "provider_id"),
7344
+ provider: nameMap.get(stringField(row, "provider_id") || "") || stringField(row, "provider_id"),
7220
7345
  model: modelId,
7221
7346
  success: stringField(row, "status") === "completed",
7222
7347
  metrics: modelMetrics(row),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yhong91/vibetime",
3
3
  "type": "module",
4
- "version": "0.1.4",
4
+ "version": "0.1.6",
5
5
  "description": "vibetime CLI — install AI-agent hooks (Claude Code, Codex, OpenCode, Pi) and report activity to vibetime.",
6
6
  "license": "MIT",
7
7
  "publishConfig": {