bisync-cli 0.0.4 → 0.0.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.
package/dist/bisync.js CHANGED
@@ -2,11 +2,12 @@
2
2
  // @bun
3
3
 
4
4
  // src/bin.ts
5
+ import { createWriteStream, mkdirSync } from "fs";
5
6
  import { readdir, stat } from "fs/promises";
6
7
  import { homedir } from "os";
7
8
  import { join, resolve } from "path";
8
9
  // package.json
9
- var version = "0.0.3";
10
+ var version = "0.0.5";
10
11
 
11
12
  // src/bin.ts
12
13
  var CONFIG_DIR = join(homedir(), ".agent-bisync");
@@ -30,11 +31,28 @@ Global options:
30
31
  `);
31
32
  };
32
33
  var LOG_LEVEL = "info";
34
+ var debugLogStream = null;
35
+ var getDebugLogStream = () => {
36
+ if (debugLogStream)
37
+ return debugLogStream;
38
+ try {
39
+ mkdirSync(CONFIG_DIR, { recursive: true });
40
+ debugLogStream = createWriteStream(DEBUG_LOG_PATH, { flags: "a" });
41
+ debugLogStream.on("error", () => {
42
+ debugLogStream = null;
43
+ });
44
+ return debugLogStream;
45
+ } catch {
46
+ return null;
47
+ }
48
+ };
33
49
  var log = (level, message) => {
50
+ const logMessage = `[bisync][${level}] ${message}`;
51
+ getDebugLogStream()?.write(`[${new Date().toISOString()}] ${logMessage}
52
+ `);
34
53
  if (level < LOG_LEVEL) {
35
54
  return;
36
55
  }
37
- const logMessage = `[bisync][${level}] ${message}`;
38
56
  console.log(logMessage);
39
57
  };
40
58
  var readConfig = async () => {
@@ -248,7 +266,8 @@ var uploadLogs = async (siteUrl, token, sessionId, raw) => {
248
266
  method: "POST",
249
267
  headers: {
250
268
  "Content-Type": "application/json",
251
- Authorization: `Bearer ${token}`
269
+ Authorization: `Bearer ${token}`,
270
+ ...process.env.BISYNC_SESSION_ID ? { "X-Bisync-Session-Id": process.env.BISYNC_SESSION_ID } : {}
252
271
  },
253
272
  body: JSON.stringify({
254
273
  session_id: sessionId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bisync-cli",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "bin": {
5
5
  "bisync": "dist/bisync.js"
6
6
  },
package/src/bin.ts CHANGED
@@ -2,7 +2,9 @@
2
2
  /// <reference types="bun" />
3
3
 
4
4
  import type { Dirent } from "node:fs";
5
+ import type { WriteStream } from "node:fs";
5
6
 
7
+ import { createWriteStream, mkdirSync } from "node:fs";
6
8
  import { readdir, stat } from "node:fs/promises";
7
9
  import { homedir } from "node:os";
8
10
  import { join, resolve } from "node:path";
@@ -44,11 +46,29 @@ Global options:
44
46
  };
45
47
 
46
48
  let LOG_LEVEL = "info";
49
+ let debugLogStream: WriteStream | null = null;
50
+
51
+ const getDebugLogStream = (): WriteStream | null => {
52
+ if (debugLogStream) return debugLogStream;
53
+ try {
54
+ mkdirSync(CONFIG_DIR, { recursive: true });
55
+ debugLogStream = createWriteStream(DEBUG_LOG_PATH, { flags: "a" });
56
+ debugLogStream.on("error", () => {
57
+ // Silently discard write errors to avoid breaking the CLI.
58
+ debugLogStream = null;
59
+ });
60
+ return debugLogStream;
61
+ } catch {
62
+ return null;
63
+ }
64
+ };
65
+
47
66
  const log = (level: "debug" | "info" | "warn" | "error", message: string) => {
67
+ const logMessage = `[bisync][${level}] ${message}`;
68
+ getDebugLogStream()?.write(`[${new Date().toISOString()}] ${logMessage}\n`);
48
69
  if (level < LOG_LEVEL) {
49
70
  return;
50
71
  }
51
- const logMessage = `[bisync][${level}] ${message}`;
52
72
  console.log(logMessage);
53
73
  };
54
74
 
@@ -333,6 +353,9 @@ const uploadLogs = async (siteUrl: string, token: string, sessionId: string, raw
333
353
  headers: {
334
354
  "Content-Type": "application/json",
335
355
  Authorization: `Bearer ${token}`,
356
+ ...(process.env.BISYNC_SESSION_ID
357
+ ? { "X-Bisync-Session-Id": process.env.BISYNC_SESSION_ID }
358
+ : {}),
336
359
  },
337
360
  body: JSON.stringify({
338
361
  session_id: sessionId,