@fabioforest/openclaw 3.7.1 → 3.8.0

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/lib/cli/ide.js CHANGED
@@ -13,6 +13,7 @@ const path = require("path");
13
13
  const readline = require("readline");
14
14
  const { detectContext, getAuditHeader } = require("../context");
15
15
  const { copyDirRecursive } = require("./init");
16
+ const { writeCliAudit } = require("../utils/audit-writer");
16
17
 
17
18
  // Caminho dos templates do pacote
18
19
  const TEMPLATES_DIR = path.join(__dirname, "..", "..", "templates");
@@ -22,21 +23,9 @@ function ask(q) {
22
23
  return new Promise((res) => rl.question(q, (ans) => { rl.close(); res(ans.trim()); }));
23
24
  }
24
25
 
25
- /**
26
- * Grava log de auditoria para o comando ide.
27
- */
26
+ // writeAudit extraído para lib/utils/audit-writer.js (DRY)
28
27
  function writeAudit(targetPath, lines, flags) {
29
- if (flags.audit === false) return;
30
- const auditDir = path.join(targetPath, ".agent", "audit");
31
- if (!fs.existsSync(auditDir)) {
32
- try { fs.mkdirSync(auditDir, { recursive: true }); } catch (e) { }
33
- }
34
- const filename = `ide-${new Date().toISOString().replace(/[:.]/g, "-")}.md`;
35
- try {
36
- fs.writeFileSync(path.join(auditDir, filename), lines.join("\n") + "\n", "utf8");
37
- } catch (e) {
38
- console.error("⚠️ Falha ao gravar auditoria:", e.message);
39
- }
28
+ writeCliAudit(targetPath, lines, flags, "ide");
40
29
  }
41
30
 
42
31
  /**
package/lib/cli/init.js CHANGED
@@ -13,6 +13,7 @@ const path = require("path");
13
13
  const readline = require("readline");
14
14
  const { initConfigDefaults, writeJsonSafe } = require("../config");
15
15
  const { detectContext, getAuditHeader } = require("../context");
16
+ const { writeCliAudit } = require("../utils/audit-writer");
16
17
 
17
18
  // Caminho dos templates incluídos no pacote
18
19
  const TEMPLATES_DIR = path.join(__dirname, "..", "..", "templates", ".agent");
@@ -26,20 +27,9 @@ function safeRel(targetPath, p) {
26
27
  return path.relative(targetPath, p);
27
28
  }
28
29
 
30
+ // writeAudit extraído para lib/utils/audit-writer.js (DRY)
29
31
  function writeAudit(targetPath, lines, flags) {
30
- if (flags.audit === false) return;
31
- const auditDir = path.join(targetPath, ".agent", "audit");
32
- if (!fs.existsSync(auditDir)) {
33
- // Tenta criar apenas se estivermos em modo apply, mas aqui já devemos estar
34
- try { fs.mkdirSync(auditDir, { recursive: true }); } catch (e) { }
35
- }
36
- const filename = `init-${new Date().toISOString().replace(/[:.]/g, "-")}.md`;
37
- const auditPath = path.join(auditDir, filename);
38
- try {
39
- fs.writeFileSync(auditPath, lines.join("\n") + "\n", "utf8");
40
- } catch (e) {
41
- console.error("⚠️ Falha ao gravar auditoria:", e.message);
42
- }
32
+ writeCliAudit(targetPath, lines, flags, "init");
43
33
  }
44
34
 
45
35
  /**
package/lib/cli/update.js CHANGED
@@ -14,6 +14,7 @@ const path = require("path");
14
14
  const crypto = require("crypto");
15
15
  const readline = require("readline");
16
16
  const { detectContext, getAuditHeader } = require("../context");
17
+ const { writeCliAudit } = require("../utils/audit-writer");
17
18
 
18
19
  // Caminho dos templates incluídos no pacote
19
20
  const TEMPLATES_DIR = path.join(__dirname, "..", "..", "templates", ".agent");
@@ -27,19 +28,9 @@ function safeRel(targetPath, p) {
27
28
  return path.relative(targetPath, p);
28
29
  }
29
30
 
31
+ // writeAudit extraído para lib/utils/audit-writer.js (DRY)
30
32
  function writeAudit(targetPath, lines, flags) {
31
- if (flags.audit === false) return;
32
- const auditDir = path.join(targetPath, ".agent", "audit");
33
- if (!fs.existsSync(auditDir)) {
34
- try { fs.mkdirSync(auditDir, { recursive: true }); } catch (e) { }
35
- }
36
- const filename = `update-${new Date().toISOString().replace(/[:.]/g, "-")}.md`;
37
- const auditPath = path.join(auditDir, filename);
38
- try {
39
- fs.writeFileSync(auditPath, lines.join("\n") + "\n", "utf8");
40
- } catch (e) {
41
- console.error("⚠️ Falha ao gravar auditoria:", e.message);
42
- }
33
+ writeCliAudit(targetPath, lines, flags, "update");
43
34
  }
44
35
 
45
36
  /**
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Utilitário compartilhado para gravação de audit logs CLI.
5
+ *
6
+ * Centraliza a lógica de escrita de audit logs markdown que antes
7
+ * estava duplicada em init.js, update.js e ide.js.
8
+ *
9
+ * @module lib/utils/audit-writer
10
+ */
11
+
12
+ const fs = require("fs");
13
+ const path = require("path");
14
+
15
+ /**
16
+ * Grava um log de auditoria em formato markdown no diretório .agent/audit/.
17
+ *
18
+ * @param {string} targetPath — diretório raiz do projeto
19
+ * @param {string[]} lines — linhas do relatório de auditoria
20
+ * @param {object} flags — flags do CLI (verifica flags.audit)
21
+ * @param {string} prefix — prefixo do arquivo (ex: "init", "update", "ide")
22
+ */
23
+ function writeCliAudit(targetPath, lines, flags, prefix = "cli") {
24
+ // Se auditoria desabilitada via flag --no-audit, não grava
25
+ if (flags.audit === false) return;
26
+
27
+ const auditDir = path.join(targetPath, ".agent", "audit");
28
+ if (!fs.existsSync(auditDir)) {
29
+ try {
30
+ fs.mkdirSync(auditDir, { recursive: true });
31
+ } catch (e) {
32
+ // Silencia erro se não conseguir criar diretório
33
+ }
34
+ }
35
+
36
+ const filename = `${prefix}-${new Date().toISOString().replace(/[:.]/g, "-")}.md`;
37
+ const auditPath = path.join(auditDir, filename);
38
+
39
+ try {
40
+ fs.writeFileSync(auditPath, lines.join("\n") + "\n", "utf8");
41
+ } catch (e) {
42
+ console.error("⚠️ Falha ao gravar auditoria:", e.message);
43
+ }
44
+ }
45
+
46
+ module.exports = { writeCliAudit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabioforest/openclaw",
3
- "version": "3.7.1",
3
+ "version": "3.8.0",
4
4
  "description": "Agentes autônomos para engenharia de software",
5
5
  "publishConfig": {
6
6
  "access": "public"