@yhong91/vibetime 0.1.41 → 0.1.42

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 +30 -8
  2. package/package.json +1 -1
package/bin/vibetime.mjs CHANGED
@@ -1928,7 +1928,7 @@ function countTextLines(text) {
1928
1928
  }
1929
1929
 
1930
1930
  // src/lib/constants.ts
1931
- var PACKAGE_VERSION = true ? "0.1.41" : "0.1.1";
1931
+ var PACKAGE_VERSION = true ? "0.1.42" : "0.1.1";
1932
1932
  var DEFAULT_API_URL = "http://121.196.224.82:3001";
1933
1933
  var DEFAULT_BACKFILL_BATCH_SIZE = 50;
1934
1934
  var DEFAULT_BACKFILL_BATCH_BYTES = 800 * 1024;
@@ -11397,7 +11397,11 @@ async function postRollupBatch(remote, rollups, options = {}) {
11397
11397
  const response = await remote.fetchImpl(joinUrl(remote.baseUrl, "/v3/agent/ingest"), {
11398
11398
  method: "POST",
11399
11399
  headers: buildHeaders(remote.token, options.machine),
11400
- body: JSON.stringify({ rollups, replace: options.replace !== false })
11400
+ body: JSON.stringify({
11401
+ rollups,
11402
+ replace: options.replace !== false,
11403
+ allowHistoricalRewrite: options.allowHistoricalRewrite === true
11404
+ })
11401
11405
  });
11402
11406
  if (!response.ok) {
11403
11407
  const body = await response.text();
@@ -11412,7 +11416,7 @@ async function postRollupBatch(remote, rollups, options = {}) {
11412
11416
  };
11413
11417
  }
11414
11418
  async function deleteRollupsBySource(remote, source, machine, options = {}) {
11415
- const query = `source=${encodeURIComponent(source)}${options.preserveTokens ? "&preserveTokens=1" : ""}`;
11419
+ const query = `source=${encodeURIComponent(source)}${options.preserveTokens ? "&preserveTokens=1" : ""}${options.allowHistoricalRewrite ? "&allowHistoricalRewrite=1" : ""}`;
11416
11420
  const response = await remote.fetchImpl(
11417
11421
  joinUrl(remote.baseUrl, `/v3/agent/sessions?${query}`),
11418
11422
  { method: "DELETE", headers: buildHeaders(remote.token, machine) }
@@ -11460,6 +11464,7 @@ async function deleteMachine(remote, id) {
11460
11464
  var BACKFILL_STATE_SCHEMA_VERSION = 6;
11461
11465
 
11462
11466
  // src/cli.ts
11467
+ var SESSION_REWRITE_DAYS = 7;
11463
11468
  function createRegistry() {
11464
11469
  const registry = new AdapterRegistry();
11465
11470
  registry.register(createCodexAdapter());
@@ -11537,7 +11542,7 @@ function createCli(ctx, registry) {
11537
11542
  cli.command("hook", "Read agent hook JSON from stdin and report a throttled event").option("--agent <name>", "Agent name").option("--project <name>", "Project name").option("--min-interval <seconds>", "Minimum seconds between similar hook reports").action((options) => hookCommand(normalizeOptions(options), ctx));
11538
11543
  cli.command("sync-local-trigger", "Trigger one background local sync with throttle and locking").option("--min-interval <seconds>", "Minimum seconds between sync triggers").action((options) => syncLocalTriggerCommand(normalizeOptions(options), ctx, registry));
11539
11544
  cli.command("sync-local-runner", "Internal background local sync runner").option("--lock-file <path>", "Lock file for the active sync").option("--state-file <path>", "State file for trigger metadata").action((options) => syncLocalRunnerCommand(normalizeOptions(options), ctx, registry));
11540
- cli.command("backfill [action]", "Inspect local history import candidates").option("--source <source>", "Backfill source").option("--since <time>", "Only include history after this time").option("--until <time>", "Only include history before this time").option("--project <name>", "Project filter").option("--source-root <path>", "Override source history root").option("--include-source-path", "Include local source paths in output").option("--import-run <id>", "Import run id for verify/resume workflows").option("--limit <count>", "Maximum session files to parse").option("--batch-size <count>", "Max rollups per request (also bounded by --batch-bytes)").option("--batch-bytes <bytes>", "Soft byte cap for the JSON body of a single ingest POST").option("--replace", "Replace conflicting records during import (default)").option("--skip-conflicts", "Skip conflicting records instead of replacing them").option("--force", "Force full re-import: clear watermark and re-process all files (keeps server rollups that already have tokens)").option("--purge-all", "With --force: also delete token-bearing server rollups before re-importing (DANGEROUS \u2014 tokens whose local sources were rotated away are lost forever)").action((action, options) => backfillCommand({ ...normalizeOptions(options), action }, ctx, registry));
11545
+ cli.command("backfill [action]", "Inspect local history import candidates").option("--source <source>", "Backfill source").option("--since <time>", "Only include history after this time").option("--until <time>", "Only include history before this time").option("--project <name>", "Project filter").option("--source-root <path>", "Override source history root").option("--include-source-path", "Include local source paths in output").option("--import-run <id>", "Import run id for verify/resume workflows").option("--limit <count>", "Maximum session files to parse").option("--batch-size <count>", "Max rollups per request (also bounded by --batch-bytes)").option("--batch-bytes <bytes>", "Soft byte cap for the JSON body of a single ingest POST").option("--replace", "Replace conflicting records during import (default)").option("--skip-conflicts", "Skip conflicting records instead of replacing them").option("--force", "Force re-import of sessions active within the last 7 days").option("--purge-all", "With --force: unlock and replace history older than 7 days (DANGEROUS)").action((action, options) => backfillCommand({ ...normalizeOptions(options), action }, ctx, registry));
11541
11546
  cli.command("token [action] [value]", "Set, show, or clear the persisted API token").option("--remote <url>", "Override API base URL when setting a token").action((action, value, options) => tokenCommand(action, value, normalizeOptions(options), ctx));
11542
11547
  cli.command("machine [action]", "List or rename machines (requires login)").option("--name <name>", "New display name (used by `machine rename`)").option("--id <id>", "Machine id (defaults to current machine)").action((action, options) => machineCommand(action, normalizeOptions(options), ctx));
11543
11548
  return cli;
@@ -11827,6 +11832,10 @@ async function backfillCommand(options, ctx, registry) {
11827
11832
  if (action === "verify") {
11828
11833
  return backfillVerifyCommand(options, ctx);
11829
11834
  }
11835
+ if (options["purge-all"] && !options.force) {
11836
+ write(ctx.stderr, "--purge-all requires --force\n");
11837
+ return 1;
11838
+ }
11830
11839
  if (action === "import" && !options["dry-run"]) {
11831
11840
  const requested = normalizeBackfillSource(stringOption(options.source) || "all");
11832
11841
  const supported = /* @__PURE__ */ new Set(["all", ...BACKFILL_SOURCE_IDS]);
@@ -12102,7 +12111,7 @@ async function importBackfillPlan(plan, options, ctx, registry) {
12102
12111
  options,
12103
12112
  ctx
12104
12113
  );
12105
- const rollups = buildSessionRollups(canonicalEvents);
12114
+ const rollups = selectRollupsForUpload(buildSessionRollups(canonicalEvents), options);
12106
12115
  const counts = await uploadSessionRollups(rollups, canonicalEvents.length, options, ctx);
12107
12116
  const result = {
12108
12117
  importRunId: plan.importRun.importRunId,
@@ -12134,7 +12143,7 @@ async function purgeForcedSources(sourceDefs, home, remoteKey, options, ctx) {
12134
12143
  try {
12135
12144
  const deleted = await deleteSessionRollupsBySourceAPI(item.id, options, ctx, preserveTokens);
12136
12145
  if (!options.json) {
12137
- const suffix = preserveTokens ? " (token-bearing rollups kept)" : "";
12146
+ const suffix = preserveTokens ? " (token-bearing and sessions older than 7 days kept)" : "";
12138
12147
  write(ctx.stdout, `purged ${item.id}: ${deleted} old rollups${suffix}
12139
12148
  `);
12140
12149
  }
@@ -12261,7 +12270,8 @@ async function sendSessionRollupBatch(rollups, options, ctx) {
12261
12270
  };
12262
12271
  const result = await postRollupBatch(remote, rollups, {
12263
12272
  replace: options["skip-conflicts"] !== true,
12264
- machine
12273
+ machine,
12274
+ allowHistoricalRewrite: options["purge-all"] === true
12265
12275
  });
12266
12276
  return result;
12267
12277
  }
@@ -12275,7 +12285,17 @@ async function deleteSessionRollupsBySourceAPI(source, options, ctx, preserveTok
12275
12285
  id: ensureLocalMachineId(home),
12276
12286
  hostname: defaultMachineName(),
12277
12287
  platform: process.platform
12278
- }, { preserveTokens });
12288
+ }, {
12289
+ preserveTokens,
12290
+ allowHistoricalRewrite: options["purge-all"] === true
12291
+ });
12292
+ }
12293
+ function selectRollupsForUpload(rollups, options, now = /* @__PURE__ */ new Date()) {
12294
+ if (!options.force || options["purge-all"]) {
12295
+ return rollups;
12296
+ }
12297
+ const cutoff = now.getTime() - SESSION_REWRITE_DAYS * 24 * 60 * 60 * 1e3;
12298
+ return rollups.filter((rollup) => Date.parse(rollup.lastEventAt) >= cutoff);
12279
12299
  }
12280
12300
  function shouldUseIncrementalBackfill(options) {
12281
12301
  return !stringOption(options.since) && !stringOption(options.until) && !stringOption(options["source-root"]) && numberOption(options.limit) === void 0;
@@ -12767,8 +12787,10 @@ Environment:
12767
12787
  `;
12768
12788
  }
12769
12789
  export {
12790
+ SESSION_REWRITE_DAYS,
12770
12791
  run,
12771
12792
  selectBackfillFilesForImport,
12793
+ selectRollupsForUpload,
12772
12794
  syncLocalRunnerEntryArgs
12773
12795
  };
12774
12796
  const code = await run(process.argv.slice(2));process.exitCode = code;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yhong91/vibetime",
3
3
  "type": "module",
4
- "version": "0.1.41",
4
+ "version": "0.1.42",
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": {