chatroom-cli 1.68.1 → 1.68.3

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/index.js CHANGED
@@ -101356,48 +101356,59 @@ var init_workspace_visibility_policy = __esm(() => {
101356
101356
  ];
101357
101357
  });
101358
101358
 
101359
- // src/commands/machine/daemon-start/file-content-fulfillment.ts
101360
- import { readFile as readFile7 } from "node:fs/promises";
101361
- import { gzipSync as gzipSync2 } from "node:zlib";
101362
- function getErrorCause(error40) {
101363
- if (typeof error40 === "object" && error40 !== null && "cause" in error40 && error40.cause !== undefined) {
101364
- return error40.cause;
101365
- }
101366
- return error40;
101367
- }
101368
- function isENOENT(error40) {
101369
- const cause3 = getErrorCause(error40);
101370
- return typeof cause3 === "object" && cause3 !== null && "code" in cause3 && cause3.code === "ENOENT";
101371
- }
101372
- function isBinaryFile(path3) {
101359
+ // src/commands/machine/daemon-start/file-content-classifier.ts
101360
+ function extensionOf(path3) {
101373
101361
  const lastDot = path3.lastIndexOf(".");
101374
101362
  if (lastDot === -1)
101375
- return false;
101376
- return BINARY_EXTENSIONS.has(path3.slice(lastDot).toLowerCase());
101363
+ return null;
101364
+ return path3.slice(lastDot).toLowerCase();
101377
101365
  }
101378
- function gzipPlainText(text) {
101379
- return gzipSync2(Buffer.from(text)).toString("base64");
101366
+ function hasKnownBinaryExtension(path3) {
101367
+ const ext = extensionOf(path3);
101368
+ return ext !== null && BINARY_EXTENSIONS.has(ext);
101380
101369
  }
101381
- function fulfillGzippedContentEffect(session2, workingDir, filePath, plainText, truncated) {
101382
- return exports_Effect.catchAll(exports_Effect.tryPromise(() => session2.backend.mutation(api.workspaceFiles.fulfillFileContentV2, {
101383
- sessionId: session2.sessionId,
101384
- machineId: session2.machineId,
101385
- workingDir,
101386
- filePath,
101387
- data: { compression: "gzip", content: gzipPlainText(plainText) },
101388
- encoding: "utf8",
101389
- truncated
101390
- })), () => exports_Effect.void);
101370
+ function hasNulByte(buffer) {
101371
+ return buffer.includes(0);
101391
101372
  }
101392
- var MAX_CONTENT_BYTES, BINARY_EXTENSIONS, fulfillFileContentRequestsEffect;
101393
- var init_file_content_fulfillment = __esm(() => {
101394
- init_esm();
101395
- init_daemon_services();
101396
- init_api3();
101397
- init_assert_registered_working_dir();
101398
- init_workspace_path_security();
101399
- init_workspace_visibility_policy();
101400
- MAX_CONTENT_BYTES = 500 * 1024;
101373
+ function hasTooManyControlChars(buffer) {
101374
+ let count3 = 0;
101375
+ const threshold = Math.max(1, Math.floor(buffer.length * 0.01));
101376
+ for (const byte of buffer) {
101377
+ if (byte === 0)
101378
+ return true;
101379
+ if (byte < 32 && byte !== 9 && byte !== 10 && byte !== 13) {
101380
+ count3++;
101381
+ if (count3 > threshold)
101382
+ return true;
101383
+ }
101384
+ }
101385
+ return false;
101386
+ }
101387
+ function classifyFileContent(path3, buffer) {
101388
+ if (hasKnownBinaryExtension(path3)) {
101389
+ return { kind: "binary", encoding: "binary" };
101390
+ }
101391
+ if (buffer.length === 0) {
101392
+ return { kind: "text", encoding: "utf8" };
101393
+ }
101394
+ if (hasNulByte(buffer)) {
101395
+ return { kind: "binary", encoding: "binary" };
101396
+ }
101397
+ try {
101398
+ const decoded = new TextDecoder("utf-8", { fatal: true }).decode(buffer);
101399
+ if (decoded.length === 0) {
101400
+ return { kind: "text", encoding: "utf8" };
101401
+ }
101402
+ if (hasTooManyControlChars(buffer)) {
101403
+ return { kind: "binary", encoding: "binary" };
101404
+ }
101405
+ return { kind: "text", encoding: "utf8" };
101406
+ } catch {
101407
+ return { kind: "binary", encoding: "binary" };
101408
+ }
101409
+ }
101410
+ var BINARY_EXTENSIONS;
101411
+ var init_file_content_classifier = __esm(() => {
101401
101412
  BINARY_EXTENSIONS = new Set([
101402
101413
  ".png",
101403
101414
  ".jpg",
@@ -101405,7 +101416,6 @@ var init_file_content_fulfillment = __esm(() => {
101405
101416
  ".gif",
101406
101417
  ".webp",
101407
101418
  ".ico",
101408
- ".svg",
101409
101419
  ".mp3",
101410
101420
  ".mp4",
101411
101421
  ".wav",
@@ -101438,6 +101448,46 @@ var init_file_content_fulfillment = __esm(() => {
101438
101448
  ".db",
101439
101449
  ".sqlite"
101440
101450
  ]);
101451
+ });
101452
+
101453
+ // src/commands/machine/daemon-start/file-content-fulfillment.ts
101454
+ import { readFile as readFile7 } from "node:fs/promises";
101455
+ import { gzipSync as gzipSync2 } from "node:zlib";
101456
+ function getErrorCause(error40) {
101457
+ if (typeof error40 === "object" && error40 !== null && "cause" in error40 && error40.cause !== undefined) {
101458
+ return error40.cause;
101459
+ }
101460
+ return error40;
101461
+ }
101462
+ function isENOENT(error40) {
101463
+ const cause3 = getErrorCause(error40);
101464
+ return typeof cause3 === "object" && cause3 !== null && "code" in cause3 && cause3.code === "ENOENT";
101465
+ }
101466
+ function gzipPlainText(text) {
101467
+ return gzipSync2(Buffer.from(text)).toString("base64");
101468
+ }
101469
+ function fulfillGzippedContentEffect(session2, workingDir, filePath, plainText, truncated, encoding = "utf8") {
101470
+ const content = gzipPlainText(plainText);
101471
+ return exports_Effect.catchAll(exports_Effect.tryPromise(() => session2.backend.mutation(api.workspaceFiles.fulfillFileContentV2, {
101472
+ sessionId: session2.sessionId,
101473
+ machineId: session2.machineId,
101474
+ workingDir,
101475
+ filePath,
101476
+ data: { compression: "gzip", content },
101477
+ encoding,
101478
+ truncated
101479
+ })), () => exports_Effect.void);
101480
+ }
101481
+ var MAX_CONTENT_BYTES, fulfillFileContentRequestsEffect;
101482
+ var init_file_content_fulfillment = __esm(() => {
101483
+ init_esm();
101484
+ init_daemon_services();
101485
+ init_api3();
101486
+ init_assert_registered_working_dir();
101487
+ init_workspace_path_security();
101488
+ init_workspace_visibility_policy();
101489
+ init_file_content_classifier();
101490
+ MAX_CONTENT_BYTES = 500 * 1024;
101441
101491
  fulfillFileContentRequestsEffect = exports_Effect.gen(function* () {
101442
101492
  const session2 = yield* DaemonSessionService;
101443
101493
  const requests = yield* exports_Effect.catchAll(exports_Effect.tryPromise(() => session2.backend.query(api.workspaceFiles.getPendingFileContentRequests, {
@@ -101463,8 +101513,8 @@ var init_file_content_fulfillment = __esm(() => {
101463
101513
  continue;
101464
101514
  }
101465
101515
  const absolutePath = resolved.absolutePath;
101466
- if (isBinaryFile(filePath)) {
101467
- yield* fulfillGzippedContentEffect(session2, workingDir, filePath, "[Binary file]", false);
101516
+ if (hasKnownBinaryExtension(filePath)) {
101517
+ yield* fulfillGzippedContentEffect(session2, workingDir, filePath, "[Binary file]", false, "binary");
101468
101518
  const elapsed4 = Date.now() - startTime;
101469
101519
  console.log(`[${formatTimestamp()}] \uD83D\uDCC4 File content synced to Convex: ${filePath} [binary] (${elapsed4}ms)`);
101470
101520
  continue;
@@ -101475,29 +101525,28 @@ var init_file_content_fulfillment = __esm(() => {
101475
101525
  console.log(`[${formatTimestamp()}] \uD83D\uDCC4 File content blocked: ${filePath} [secret] (${elapsed4}ms)`);
101476
101526
  continue;
101477
101527
  }
101478
- const readOutcome = yield* exports_Effect.catchAll(exports_Effect.tryPromise(() => readFile7(absolutePath)).pipe(exports_Effect.map((buffer) => {
101479
- if (buffer.length > MAX_CONTENT_BYTES) {
101480
- return {
101481
- kind: "ok",
101482
- content: buffer.subarray(0, MAX_CONTENT_BYTES).toString("utf8"),
101483
- truncated: true
101484
- };
101528
+ let fileNotFound = false;
101529
+ const buffer = yield* exports_Effect.catchAll(exports_Effect.tryPromise(() => readFile7(absolutePath)), (error40) => {
101530
+ if (isENOENT(error40)) {
101531
+ fileNotFound = true;
101532
+ return exports_Effect.succeed(Buffer.alloc(0));
101485
101533
  }
101486
- return {
101487
- kind: "ok",
101488
- content: buffer.toString("utf8"),
101489
- truncated: false
101490
- };
101491
- })), (error40) => isENOENT(error40) ? exports_Effect.succeed({ kind: "missing" }) : exports_Effect.succeed({
101492
- kind: "error",
101493
- content: "[Error reading file]",
101494
- truncated: false
101495
- }));
101496
- if (readOutcome.kind === "missing") {
101534
+ return exports_Effect.succeed(Buffer.from("[Error reading file]"));
101535
+ });
101536
+ if (fileNotFound) {
101497
101537
  console.log(`[${formatTimestamp()}] ⏳ File not on disk yet, deferring content sync: ${filePath}`);
101498
101538
  continue;
101499
101539
  }
101500
- const { content, truncated } = readOutcome.kind === "ok" ? readOutcome : { content: readOutcome.content, truncated: readOutcome.truncated };
101540
+ const classification = classifyFileContent(filePath, new Uint8Array(buffer));
101541
+ if (classification.kind === "binary") {
101542
+ yield* fulfillGzippedContentEffect(session2, workingDir, filePath, "[Binary file]", false, "binary");
101543
+ const elapsed4 = Date.now() - startTime;
101544
+ console.log(`[${formatTimestamp()}] \uD83D\uDCC4 File content synced to Convex: ${filePath} [binary] (${elapsed4}ms)`);
101545
+ continue;
101546
+ }
101547
+ const truncated = buffer.length > MAX_CONTENT_BYTES;
101548
+ const slice = truncated ? buffer.subarray(0, MAX_CONTENT_BYTES) : buffer;
101549
+ const content = slice.toString("utf8");
101501
101550
  const compressed = gzipSync2(Buffer.from(content));
101502
101551
  const contentCompressed = compressed.toString("base64");
101503
101552
  yield* exports_Effect.catchAll(exports_Effect.tryPromise(() => session2.backend.mutation(api.workspaceFiles.fulfillFileContentV2, {
@@ -113001,4 +113050,4 @@ program2.hook("preAction", async (_thisCommand, actionCommand) => {
113001
113050
  });
113002
113051
  program2.parse();
113003
113052
 
113004
- //# debugId=B20428C3563382D064756E2164756E21
113053
+ //# debugId=D6990493E373D3A464756E2164756E21