@basestream/cli 0.2.5 → 0.2.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/dist/cli.mjs +42 -4
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -14,7 +14,7 @@ import fs from "node:fs";
14
14
  import path from "node:path";
15
15
  import os from "node:os";
16
16
  function ensureDirs() {
17
- for (const dir of [BASESTREAM_DIR, BUFFER_DIR, SESSION_DIR]) {
17
+ for (const dir of [BASESTREAM_DIR, BUFFER_DIR, SESSION_DIR, LOG_DIR]) {
18
18
  fs.mkdirSync(dir, { recursive: true });
19
19
  }
20
20
  }
@@ -34,7 +34,7 @@ function writeConfig(config) {
34
34
  ensureDirs();
35
35
  fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
36
36
  }
37
- var BASESTREAM_DIR, BUFFER_DIR, CONFIG_FILE, SESSION_DIR;
37
+ var BASESTREAM_DIR, BUFFER_DIR, CONFIG_FILE, SESSION_DIR, LOG_DIR, LOG_RETENTION_DAYS;
38
38
  var init_config = __esm({
39
39
  "src/cli/config.ts"() {
40
40
  "use strict";
@@ -42,6 +42,8 @@ var init_config = __esm({
42
42
  BUFFER_DIR = path.join(BASESTREAM_DIR, "buffer");
43
43
  CONFIG_FILE = path.join(BASESTREAM_DIR, "config.json");
44
44
  SESSION_DIR = path.join(BASESTREAM_DIR, "sessions");
45
+ LOG_DIR = path.join(BASESTREAM_DIR, "logs");
46
+ LOG_RETENTION_DAYS = 7;
45
47
  }
46
48
  });
47
49
 
@@ -725,6 +727,30 @@ function buildSummary(acc, category) {
725
727
  }
726
728
  return parts.length > 0 ? parts.join(", ") : `Claude Code session in ${acc.projectName || "unknown project"}`;
727
729
  }
730
+ function makeLogger(sessionId) {
731
+ ensureDirs();
732
+ const logFile = path5.join(LOG_DIR, `${sessionId}.log`);
733
+ return (...args) => {
734
+ const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${args.join(" ")}
735
+ `;
736
+ try {
737
+ fs5.appendFileSync(logFile, line);
738
+ } catch {
739
+ }
740
+ };
741
+ }
742
+ function pruneOldLogs() {
743
+ try {
744
+ const cutoff = Date.now() - LOG_RETENTION_DAYS * 24 * 60 * 60 * 1e3;
745
+ for (const file of fs5.readdirSync(LOG_DIR)) {
746
+ if (!file.endsWith(".log")) continue;
747
+ const full = path5.join(LOG_DIR, file);
748
+ const stat = fs5.statSync(full);
749
+ if (stat.mtimeMs < cutoff) fs5.unlinkSync(full);
750
+ }
751
+ } catch {
752
+ }
753
+ }
728
754
  async function hookStop() {
729
755
  let payload;
730
756
  try {
@@ -739,6 +765,9 @@ async function hookStop() {
739
765
  const { session_id, transcript_path, cwd } = payload;
740
766
  if (!session_id) process.exit(0);
741
767
  ensureDirs();
768
+ pruneOldLogs();
769
+ const log = makeLogger(session_id);
770
+ log("hook fired", "cwd=" + cwd);
742
771
  let acc = readSessionAccumulator(session_id);
743
772
  if (!acc) {
744
773
  const gitInfo = extractGitInfo(cwd);
@@ -755,11 +784,13 @@ async function hookStop() {
755
784
  gitRepo: gitInfo.repo,
756
785
  projectName: gitInfo.projectName
757
786
  };
787
+ log("new session");
758
788
  }
759
789
  if (transcript_path) {
760
790
  acc = analyzeTranscript(transcript_path, acc);
761
791
  }
762
792
  acc.lastUpdatedAt = (/* @__PURE__ */ new Date()).toISOString();
793
+ log(`turns=${acc.turns} files=${acc.filesWritten.size} commits=${acc.commitShas.size}`);
763
794
  writeSessionAccumulator(acc);
764
795
  if (acc.filesWritten.size > 0 || acc.commitShas.size > 0 || acc.turns >= 3) {
765
796
  flushToBuffer(acc);
@@ -768,9 +799,16 @@ async function hookStop() {
768
799
  try {
769
800
  const { syncEntries: syncEntries2 } = await Promise.resolve().then(() => (init_sync(), sync_exports));
770
801
  await syncEntries2(config);
771
- } catch {
802
+ log("synced");
803
+ process.stdout.write(JSON.stringify({ systemMessage: "basestream synced" }) + "\n");
804
+ } catch (e) {
805
+ log("sync error:", String(e));
772
806
  }
807
+ } else {
808
+ log("no apiKey, skipping sync");
773
809
  }
810
+ } else {
811
+ log("nothing to flush");
774
812
  }
775
813
  }
776
814
 
@@ -887,7 +925,7 @@ async function main() {
887
925
  process.exit(0);
888
926
  }
889
927
  if (command === "--version" || command === "-v") {
890
- console.log(true ? "0.2.5" : "dev");
928
+ console.log(true ? "0.2.6" : "dev");
891
929
  process.exit(0);
892
930
  }
893
931
  switch (command || "init") {
package/package.json CHANGED
@@ -18,5 +18,5 @@
18
18
  "unlink:cli": "npm unlink -g @basestream/cli"
19
19
  },
20
20
  "type": "module",
21
- "version": "0.2.5"
21
+ "version": "0.2.6"
22
22
  }