autoclaw 1.0.27 → 1.0.29

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.
@@ -1,6 +1,7 @@
1
1
  import { chromium } from 'playwright';
2
2
  import * as fs from 'fs';
3
3
  import * as os from 'os';
4
+ import * as child_process from 'child_process';
4
5
  // Helper to check for common CJK and Emoji font paths on Linux
5
6
  const checkLinuxFonts = () => {
6
7
  if (os.platform() !== 'linux')
@@ -21,7 +22,6 @@ const checkLinuxFonts = () => {
21
22
  const hasEmoji = commonEmojiFontFiles.some(path => fs.existsSync(path));
22
23
  // Also check if fc-list finds fonts (if available) - secondary check
23
24
  try {
24
- const child_process = require('child_process');
25
25
  const cjkOutput = child_process.execSync('fc-list :lang=zh', { stdio: 'pipe' }).toString();
26
26
  const emojiOutput = child_process.execSync('fc-list :family=Emoji', { stdio: 'pipe' }).toString(); // Approximate check
27
27
  return {
@@ -34,6 +34,46 @@ const checkLinuxFonts = () => {
34
34
  return { cjk: hasCJK, emoji: hasEmoji };
35
35
  }
36
36
  };
37
+ const installFonts = (missing) => {
38
+ try {
39
+ let installCmd = '';
40
+ if (fs.existsSync('/etc/alpine-release')) {
41
+ // Alpine
42
+ const pkgs = [];
43
+ if (!missing.cjk)
44
+ pkgs.push('font-noto-cjk');
45
+ if (!missing.emoji)
46
+ pkgs.push('font-noto-emoji');
47
+ if (pkgs.length > 0) {
48
+ installCmd = `apk add --no-cache ${pkgs.join(' ')}`;
49
+ }
50
+ }
51
+ else if (fs.existsSync('/etc/debian_version')) {
52
+ // Debian/Ubuntu
53
+ const pkgs = [];
54
+ if (!missing.cjk)
55
+ pkgs.push('fonts-noto-cjk', 'fonts-wqy-zenhei');
56
+ if (!missing.emoji)
57
+ pkgs.push('fonts-noto-color-emoji');
58
+ if (pkgs.length > 0) {
59
+ // apt-get update is often needed first in clean containers
60
+ installCmd = `apt-get update && apt-get install -y ${pkgs.join(' ')}`;
61
+ }
62
+ }
63
+ if (installCmd) {
64
+ console.log(`Creating font environment... (${installCmd})`);
65
+ console.log("This may take a few moments...");
66
+ child_process.execSync(installCmd, { stdio: 'inherit' });
67
+ console.log('✅ Fonts installed successfully.');
68
+ return true;
69
+ }
70
+ }
71
+ catch (e) {
72
+ console.warn(`⚠️ Failed to auto-install fonts: ${e.message}`);
73
+ console.warn('Please install them manually to fix "tofu" characters.');
74
+ }
75
+ return false;
76
+ };
37
77
  export const ScreenshotTool = {
38
78
  name: "Screenshot Tool",
39
79
  configKeys: [],
@@ -66,13 +106,9 @@ export const ScreenshotTool = {
66
106
  // Check for fonts on Linux to prevent "tofu" characters
67
107
  if (os.platform() === 'linux') {
68
108
  const fonts = checkLinuxFonts();
69
- if (!fonts.cjk) {
70
- console.warn("⚠️ Warning: No CJK fonts detected. Chinese characters may appear as squares (tofu).");
71
- console.warn(" Run 'apk add font-noto-cjk' (Alpine) or 'apt-get install fonts-noto-cjk' (Debian/Ubuntu).");
72
- }
73
- if (!fonts.emoji) {
74
- console.warn("⚠️ Warning: No Emoji fonts detected. Emojis may appear as squares.");
75
- console.warn(" Run 'apk add font-noto-emoji' (Alpine) or 'apt-get install fonts-noto-color-emoji' (Debian/Ubuntu).");
109
+ if (!fonts.cjk || !fonts.emoji) {
110
+ console.log("Missing fonts detected. Attempting to fix environment...");
111
+ installFonts(fonts);
76
112
  }
77
113
  }
78
114
  let browser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoclaw",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {