autoclaw 1.3.2 → 1.3.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/README.md CHANGED
@@ -130,6 +130,29 @@ Unattempted tasks are simply absent from the results file, so `--fail-fast` foll
130
130
 
131
131
  AutoClaw also keeps its own prompt lean: optional tools (web search, email, group notifications, image generation) only register once their credentials are configured, and in long loops older tool results in the model context are replaced by short excerpts.
132
132
 
133
+ ### Recipes
134
+
135
+ Daily ops sweep on Linux (crontab):
136
+ ```cron
137
+ 0 9 * * * autoclaw batch /opt/ops/daily.jsonl -y -n --resume >> /var/log/autoclaw.log 2>&1
138
+ ```
139
+
140
+ Scheduled sweep on Windows (Task Scheduler):
141
+ ```bash
142
+ schtasks /create /tn "AutoClaw Daily" /tr "autoclaw batch C:\ops\daily.jsonl -y -n" /sc daily /st 09:00
143
+ ```
144
+
145
+ Pipeline inside one manifest — each task writes files the next task reads:
146
+ ```jsonl
147
+ {"id": "sweep", "task": "检查磁盘与关键服务状态,报告写入 report/sweep.md"}
148
+ {"id": "notify", "task": "读取 report/sweep.md,用三句话总结后推送到飞书"}
149
+ ```
150
+
151
+ Diagnostics on a fresh machine or in CI:
152
+ ```bash
153
+ autoclaw doctor # exit 0 = ready; exit 1 = what's missing is printed
154
+ ```
155
+
133
156
  ### Auto-Confirm (CI/CD)
134
157
  Automatically approve all tool executions (dangerous, use with caution or in sandboxes).
135
158
  ```bash
@@ -141,14 +164,18 @@ autoclaw "Refactor src/index.ts to use ES modules" -y
141
164
  - `-P, --provider <name>`: Use a provider preset (see [Providers](#providers)).
142
165
  - `-n, --no-interactive`: Exit after processing the initial query (Headless mode).
143
166
  - `-y, --yes`: Auto-confirm all tool executions (e.g., shell commands).
167
+ - `--allow-dangerous`: Let `-y` run clearly destructive commands (rm -rf, format, shutdown, ...) that the built-in safety gate would block.
144
168
  - `--json`: Emit NDJSON events on stdout (for orchestrators; use with `-n`).
145
169
 
170
+ ### Diagnostics
171
+ `autoclaw doctor` checks everything headlessly and prints ✓/✗ per item: config files, resolved provider/baseUrl/model, API key, a live connection test, resolved shell, registered tools, and playwright browser status. Exit `0` = ready, `1` = a critical item failed (the failing item is printed). Ideal for CI or a fresh machine.
172
+
146
173
  ### Providers
147
174
  AutoClaw works with any OpenAI-compatible endpoint. Built-in presets fill in the base URL and a default model for you:
148
175
  ```bash
149
176
  autoclaw -P deepseek "Check disk usage and save a report" -y -n
150
177
  ```
151
- Available presets: `openai`, `deepseek`, `moonshot` (Kimi), `dashscope` (Qwen), `zhipu` (GLM), `openrouter`, `ollama` (local). You can still override the model with `-m` or config. When `OPENAI_API_KEY` is not set, the API key is read from the provider's own env var (e.g. `DEEPSEEK_API_KEY`, `MOONSHOT_API_KEY`, `DASHSCOPE_API_KEY`, `ZHIPU_API_KEY`, `OPENROUTER_API_KEY`).
178
+ Available presets: `openai`, `deepseek`, `moonshot` (Kimi), `dashscope` (Qwen), `zhipu` (GLM), `ark` (Volcano Ark), `siliconflow`, `openrouter`, `ollama` (local). You can still override the model with `-m` or config. When `OPENAI_API_KEY` is not set, the API key is read from the provider's own env var (e.g. `DEEPSEEK_API_KEY`, `MOONSHOT_API_KEY`, `DASHSCOPE_API_KEY`, `ZHIPU_API_KEY`, `ARK_API_KEY`, `SILICONFLOW_API_KEY`, `OPENROUTER_API_KEY`).
152
179
 
153
180
  ## Configuration
154
181
 
package/README.zh-CN.md CHANGED
@@ -131,6 +131,29 @@ autoclaw batch big.jsonl -y -c 4 # 最多 4 个任务并行
131
131
 
132
132
  AutoClaw 同时会自动给提示词瘦身:可选工具(网页搜索、邮件、群通知、图像生成)只在凭据配置后才会注册进工具定义;长循环中较早的工具结果会被替换为短摘要。
133
133
 
134
+ ### 实战配方
135
+
136
+ Linux 定时巡检(crontab):
137
+ ```cron
138
+ 0 9 * * * autoclaw batch /opt/ops/daily.jsonl -y -n --resume >> /var/log/autoclaw.log 2>&1
139
+ ```
140
+
141
+ Windows 计划任务:
142
+ ```bash
143
+ schtasks /create /tn "AutoClaw Daily" /tr "autoclaw batch C:\ops\daily.jsonl -y -n" /sc daily /st 09:00
144
+ ```
145
+
146
+ 一个清单内的流水线——前一个任务写文件,后一个任务读:
147
+ ```jsonl
148
+ {"id": "sweep", "task": "检查磁盘与关键服务状态,报告写入 report/sweep.md"}
149
+ {"id": "notify", "task": "读取 report/sweep.md,用三句话总结后推送到飞书"}
150
+ ```
151
+
152
+ 新机器或 CI 环境自检:
153
+ ```bash
154
+ autoclaw doctor # 退出 0 = 就绪;退出 1 = 打印缺失项
155
+ ```
156
+
134
157
  ### 自动确认 (CI/CD)
135
158
  自动批准所有工具执行(危险操作,请谨慎使用或在沙箱环境下运行)。
136
159
  ```bash
@@ -142,6 +165,11 @@ autoclaw "将 src/index.ts 重构为使用 ES 模块" -y
142
165
  - `-P, --provider <name>`: 使用 provider 预设 (见 [Provider 预设](#provider-预设))。
143
166
  - `-n, --no-interactive`: 处理完初始查询后退出 (无头模式)。
144
167
  - `-y, --yes`: 自动确认所有工具执行 (例如 Shell 命令)。
168
+ - `--allow-dangerous`: 允许 `-y` 直接执行内置安全闸拦截的明显破坏性命令 (rm -rf、format、shutdown 等)。
169
+ - `--json`: 在 stdout 输出 NDJSON 事件流 (供编排器使用,配合 `-n`)。
170
+
171
+ ### 诊断
172
+ `autoclaw doctor` 无头完成全面自检,逐项打印 ✓/✗:配置文件、解析出的 provider/baseUrl/model、API key、真实连接测试、解析出的 shell、已注册工具、playwright 浏览器状态。退出 `0` = 就绪,`1` = 有关键项失败(会打印是哪项)。适合 CI 或新机器。
145
173
  - `--json`: 在 stdout 输出 NDJSON 事件流 (供编排器使用,配合 `-n`)。
146
174
 
147
175
  ### Provider 预设
@@ -149,7 +177,7 @@ AutoClaw 可对接任意 OpenAI 兼容端点。内置预设可自动填好 Base
149
177
  ```bash
150
178
  autoclaw -P deepseek "检查磁盘使用情况并保存报告" -y -n
151
179
  ```
152
- 可用预设:`openai`、`deepseek`、`moonshot` (Kimi)、`dashscope` (Qwen)、`zhipu` (GLM)、`openrouter`、`ollama` (本地)。模型仍可用 `-m` 或配置覆盖。未设置 `OPENAI_API_KEY` 时,会自动读取各家自己的环境变量 (如 `DEEPSEEK_API_KEY`、`MOONSHOT_API_KEY`、`DASHSCOPE_API_KEY`、`ZHIPU_API_KEY`、`OPENROUTER_API_KEY`)。
180
+ 可用预设:`openai`、`deepseek`、`moonshot` (Kimi)、`dashscope` (Qwen)、`zhipu` (GLM)、`ark` (火山方舟)、`siliconflow` (硅基流动)、`openrouter`、`ollama` (本地)。模型仍可用 `-m` 或配置覆盖。未设置 `OPENAI_API_KEY` 时,会自动读取各家自己的环境变量 (如 `DEEPSEEK_API_KEY`、`MOONSHOT_API_KEY`、`DASHSCOPE_API_KEY`、`ZHIPU_API_KEY`、`ARK_API_KEY`、`SILICONFLOW_API_KEY`、`OPENROUTER_API_KEY`)。
153
181
 
154
182
  ## 配置
155
183
 
package/dist/doctor.js ADDED
@@ -0,0 +1,81 @@
1
+ import * as fs from 'fs';
2
+ import { createRequire } from 'module';
3
+ import { testConnection } from './setup.js';
4
+ import { getBashPath, resolveShellType } from './shell.js';
5
+ import { getToolDefinitions, listUnavailableTools } from './tools/index.js';
6
+ const require = createRequire(import.meta.url);
7
+ function playwrightBrowserStatus() {
8
+ try {
9
+ const { chromium } = require('playwright');
10
+ const exe = chromium.executablePath();
11
+ if (exe && fs.existsSync(exe)) {
12
+ return { ok: true, detail: exe };
13
+ }
14
+ return { ok: false, detail: 'playwright installed but no browser downloaded (run: npx playwright install chromium)' };
15
+ }
16
+ catch (err) {
17
+ return { ok: false, detail: `playwright not available (${String(err?.message ?? err).split('\n')[0]})` };
18
+ }
19
+ }
20
+ function maskKey(key) {
21
+ if (!key)
22
+ return 'missing';
23
+ if (key.length < 8)
24
+ return '***';
25
+ return `${key.slice(0, 6)}***${key.slice(-4)}`;
26
+ }
27
+ // Headless self-diagnosis: every check reports ok/critical/detail, so the
28
+ // CLI can render ✓/✗ and derive an exit code without any interaction.
29
+ export async function collectDoctorChecks(cfg) {
30
+ const checks = [];
31
+ checks.push({
32
+ name: 'Global config',
33
+ ok: cfg.globalExists,
34
+ critical: true,
35
+ detail: cfg.globalExists ? cfg.globalFile : `${cfg.globalFile} (missing — run: autoclaw setup)`
36
+ });
37
+ checks.push({
38
+ name: 'Project config',
39
+ ok: true,
40
+ critical: false,
41
+ detail: cfg.projectExists ? cfg.projectFile : '(none)'
42
+ });
43
+ checks.push({
44
+ name: 'API key',
45
+ ok: !!cfg.apiKey,
46
+ critical: true,
47
+ detail: maskKey(cfg.apiKey)
48
+ });
49
+ checks.push({
50
+ name: 'Endpoint',
51
+ ok: !!cfg.baseUrl,
52
+ critical: true,
53
+ detail: `${cfg.providerLabel} | ${cfg.baseUrl || '?'} | model: ${cfg.model}`
54
+ });
55
+ if (cfg.apiKey && cfg.baseUrl && cfg.model) {
56
+ const t = await testConnection(cfg.baseUrl, cfg.apiKey, cfg.model);
57
+ checks.push({ name: 'Connection', ok: t.ok, critical: true, detail: t.message });
58
+ }
59
+ else {
60
+ checks.push({ name: 'Connection', ok: false, critical: true, detail: 'skipped (key / baseUrl / model missing)' });
61
+ }
62
+ const shellType = resolveShellType(cfg.toolConfig);
63
+ const bashPath = shellType === 'bash' ? getBashPath() : null;
64
+ checks.push({
65
+ name: 'Shell',
66
+ ok: true,
67
+ critical: false,
68
+ detail: bashPath ? `${shellType} (${bashPath})` : shellType
69
+ });
70
+ const registered = getToolDefinitions(cfg.toolConfig).length;
71
+ const missing = listUnavailableTools(cfg.toolConfig);
72
+ checks.push({
73
+ name: 'Tools',
74
+ ok: true,
75
+ critical: false,
76
+ detail: `${registered} registered${missing.length ? ` (not configured: ${missing.join(', ')})` : ''}`
77
+ });
78
+ const pw = playwrightBrowserStatus();
79
+ checks.push({ name: 'Playwright browsers', ok: pw.ok, critical: false, detail: pw.detail });
80
+ return checks;
81
+ }
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import { Agent } from './agent.js';
7
7
  import { parseManifest, runBatch } from './batch.js';
8
8
  import { PROVIDER_PRESETS, providerNames, resolveProvider } from './providers.js';
9
9
  import { fetchModelIds, normalizeBaseUrl, testConnection } from './setup.js';
10
+ import { collectDoctorChecks } from './doctor.js';
10
11
  import * as fs from 'fs';
11
12
  import * as path from 'path';
12
13
  import * as os from 'os';
@@ -45,7 +46,7 @@ dotenv.config({ path: GLOBAL_ENV_FILE });
45
46
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
46
47
  // In dist/index.js, package.json is usually up one level in the root
47
48
  const pkgPath = path.join(__dirname, '..', 'package.json');
48
- let version = '1.3.2';
49
+ let version = '1.3.3';
49
50
  try {
50
51
  const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
51
52
  version = pkg.version;
@@ -59,9 +60,10 @@ program
59
60
  .description('A lightweight AI agent CLI tool')
60
61
  .version(version)
61
62
  .option('-m, --model <model>', 'Model to use')
62
- .option('-P, --provider <name>', 'Use a provider preset (openai, deepseek, moonshot, dashscope, zhipu, openrouter, ollama)')
63
+ .option('-P, --provider <name>', 'Use a provider preset (openai, deepseek, moonshot, dashscope, zhipu, ark, siliconflow, openrouter, ollama)')
63
64
  .option('-n, --no-interactive', 'Exit after processing the initial query (Headless mode)')
64
65
  .option('-y, --yes', 'Auto-confirm all tool executions (e.g., shell commands)')
66
+ .option('--allow-dangerous', 'Let -y run clearly destructive commands (rm -rf, format, shutdown, ...) without the safety block')
65
67
  .option('--json', 'Emit NDJSON events on stdout (for orchestrators; use with -n)');
66
68
  program
67
69
  .command('setup')
@@ -88,6 +90,36 @@ program
88
90
  const options = program.opts();
89
91
  await runBatchCommand(manifest, options, cmdOptions);
90
92
  });
93
+ program
94
+ .command('doctor')
95
+ .description('Diagnose configuration and environment (headless)')
96
+ .action(async () => {
97
+ const options = program.opts();
98
+ const { apiKey, baseURL, model, fullConfig } = await resolveRuntime(options, { interactive: false });
99
+ const providerName = options.provider || process.env.AUTOCLOW_PROVIDER || fullConfig.provider;
100
+ console.log(chalk.bold.cyan('AutoClaw Doctor 🦞\n'));
101
+ const checks = await collectDoctorChecks({
102
+ apiKey,
103
+ baseUrl: baseURL,
104
+ model,
105
+ providerLabel: providerName || 'custom',
106
+ globalFile: GLOBAL_CONFIG_FILE,
107
+ projectFile: LOCAL_CONFIG_FILE,
108
+ globalExists: fs.existsSync(GLOBAL_CONFIG_FILE),
109
+ projectExists: fs.existsSync(LOCAL_CONFIG_FILE),
110
+ toolConfig: fullConfig
111
+ });
112
+ for (const c of checks) {
113
+ const mark = c.ok ? chalk.green('✓') : c.critical ? chalk.red('✗') : chalk.yellow('!');
114
+ console.log(`${mark} ${c.name.padEnd(20)} ${chalk.dim(c.detail)}`);
115
+ }
116
+ const failed = checks.filter(c => c.critical && !c.ok);
117
+ if (failed.length === 0)
118
+ console.log(chalk.green('\nAll critical checks passed.'));
119
+ else
120
+ console.log(chalk.red(`\n${failed.length} critical check(s) failed.`));
121
+ process.exit(failed.length === 0 ? 0 : 1);
122
+ });
91
123
  program.parse(process.argv);
92
124
  async function runSetup(options = {}) {
93
125
  const isProject = options.project;
@@ -438,7 +470,9 @@ async function runSetup(options = {}) {
438
470
  }
439
471
  // Shared by `chat` and `batch`: resolve credentials, endpoints and runtime
440
472
  // flags from CLI args > env > project config > global config > provider preset.
441
- async function resolveRuntime(options) {
473
+ // With interactive: false (doctor), a missing key resolves to '' instead of
474
+ // prompting, so the caller can report it.
475
+ async function resolveRuntime(options, opts = {}) {
442
476
  // 1. Load Global JSON
443
477
  const globalConfig = loadJsonConfig(GLOBAL_CONFIG_FILE);
444
478
  // 2. Load Local JSON (Project Level)
@@ -461,6 +495,7 @@ async function resolveRuntime(options) {
461
495
  let model = options.model || process.env.OPENAI_MODEL || fullConfig.model || preset?.defaultModel || 'gpt-5.6';
462
496
  // Inject Runtime Flags
463
497
  fullConfig.autoConfirm = options.yes;
498
+ fullConfig.allowDangerous = !!options.allowDangerous;
464
499
  fullConfig.jsonMode = !!options.json;
465
500
  // Usage tracking is opt-in: not every OpenAI-compatible provider accepts
466
501
  // stream_options.include_usage, so never force it on.
@@ -492,6 +527,9 @@ async function resolveRuntime(options) {
492
527
  if (process.env.WECOM_KEYWORD)
493
528
  fullConfig.wecomKeyword = process.env.WECOM_KEYWORD;
494
529
  if (!apiKey) {
530
+ if (opts.interactive === false) {
531
+ return { apiKey: '', baseURL, model, fullConfig };
532
+ }
495
533
  console.log(chalk.yellow("API Key not found."));
496
534
  const { doSetup } = await inquirer.prompt([
497
535
  {
package/dist/providers.js CHANGED
@@ -29,6 +29,18 @@ export const PROVIDER_PRESETS = {
29
29
  defaultModel: 'glm-5',
30
30
  apiKeyEnv: 'ZHIPU_API_KEY'
31
31
  },
32
+ ark: {
33
+ label: 'Volcano Ark (Doubao/DeepSeek)',
34
+ baseUrl: 'https://ark.cn-beijing.volces.com/api/v3',
35
+ defaultModel: 'deepseek-v4-flash',
36
+ apiKeyEnv: 'ARK_API_KEY'
37
+ },
38
+ siliconflow: {
39
+ label: 'SiliconFlow',
40
+ baseUrl: 'https://api.siliconflow.cn/v1',
41
+ defaultModel: 'deepseek-ai/DeepSeek-V4',
42
+ apiKeyEnv: 'SILICONFLOW_API_KEY'
43
+ },
32
44
  openrouter: {
33
45
  label: 'OpenRouter',
34
46
  baseUrl: 'https://openrouter.ai/api/v1',
@@ -8,6 +8,25 @@ const SHELL_MAX_BUFFER = 10 * 1024 * 1024;
8
8
  // Bounded reads keep a huge file from exhausting memory or the model context;
9
9
  // the agent-level truncation in truncate.ts applies on top of this.
10
10
  const READ_FILE_MAX_BYTES = 1024 * 1024;
11
+ // Even with -y, an unattended agent must not execute clearly destructive
12
+ // commands — a poisoned tool result (e.g. prompt injection via a web page)
13
+ // would otherwise reach the shell directly. Matched commands are refused
14
+ // with a message the model can act on; --allow-dangerous overrides.
15
+ export const DANGEROUS_PATTERNS = [
16
+ { re: /\brm\s+(?:-\w+\s+)*-\w*[rR]\w*[fF]\b/, label: 'rm with recursive+force' },
17
+ { re: /\b(?:rd|rmdir|del|erase)\s+\/[sS]\b/, label: 'Windows recursive delete (rd/del /s)' },
18
+ { re: /\bRemove-Item\b[^;\n]*-(?:Recurse[^;\n]*Force|Force[^;\n]*Recurse)/i, label: 'PowerShell Remove-Item -Recurse -Force' },
19
+ { re: /\b(?:format|diskpart)\b/i, label: 'disk format / diskpart' },
20
+ { re: /\bmkfs(?:\.\w+)?\b/i, label: 'mkfs' },
21
+ { re: /\bdd\b[^|]*\bof=/i, label: 'dd raw write' },
22
+ { re: /(?:>>?|tee)\s*\/dev\/(?:sd|nvme|hd|vd)[a-z]/i, label: 'write to block device' },
23
+ { re: /\b(?:shutdown|reboot|halt|poweroff)\b/i, label: 'host power control' },
24
+ { re: /\breg\s+delete\b/i, label: 'registry delete' }
25
+ ];
26
+ export function matchDangerousPattern(command) {
27
+ const hit = DANGEROUS_PATTERNS.find(p => p.re.test(command));
28
+ return hit ? hit.label : null;
29
+ }
11
30
  export const ShellTool = {
12
31
  name: "Shell Execution",
13
32
  definition: {
@@ -28,6 +47,14 @@ export const ShellTool = {
28
47
  handler: async (args, config) => {
29
48
  console.log(chalk.yellow(`\nAI wants to execute: `) + chalk.bold(args.command));
30
49
  console.log(chalk.dim(`Reason: ${args.rationale}`));
50
+ // Safety gate runs first: blocked commands are refused even with --yes.
51
+ if (!config?.allowDangerous) {
52
+ const label = matchDangerousPattern(args.command);
53
+ if (label) {
54
+ console.log(chalk.red(`\n[blocked] ${label}`));
55
+ return `Error: command blocked by AutoClaw safety policy (matched: ${label}). It was NOT executed. If this task genuinely requires it, the user must restart AutoClaw with --allow-dangerous; otherwise find a safer way to achieve the same goal.`;
56
+ }
57
+ }
31
58
  const timeoutMs = Number(config?.shellTimeout || process.env.AUTOCLOW_SHELL_TIMEOUT || DEFAULT_SHELL_TIMEOUT_MS);
32
59
  // Check for auto-confirm flag
33
60
  if (!config?.autoConfirm) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autoclaw",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {