ia_rewrite_ntapp 1.0.1 → 1.0.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.
Files changed (3) hide show
  1. package/index.js +16 -0
  2. package/package.json +1 -1
  3. package/setup.js +13 -2
package/index.js CHANGED
@@ -7,6 +7,15 @@ const notifier = require("node-notifier");
7
7
  const { execFileSync, execSync } = require("child_process");
8
8
  const { ensureConfig, CONFIG_FILE } = require("./configure");
9
9
 
10
+ const LOG_FILE = path.join(process.env.USERPROFILE || os.homedir(), ".ia-rewrite-log.txt");
11
+
12
+ function log(message) {
13
+ const line = `[${new Date().toISOString()}] ${message}\n`;
14
+ try {
15
+ fs.appendFileSync(LOG_FILE, line, "utf8");
16
+ } catch (_) {}
17
+ }
18
+
10
19
  function notify(title, message) {
11
20
  try {
12
21
  notifier.notify({ title, message });
@@ -90,6 +99,7 @@ async function callModel(config, text) {
90
99
  }
91
100
 
92
101
  async function main() {
102
+ log("Iniciando execução.");
93
103
  let config = loadConfig();
94
104
  if (!config) config = ensureConfig();
95
105
 
@@ -97,18 +107,24 @@ async function main() {
97
107
  await new Promise((r) => setTimeout(r, 150));
98
108
 
99
109
  const original = (await readClipboard()).trim();
110
+ log(`Clipboard lido. Tamanho: ${original.length}`);
100
111
  if (!original) {
101
112
  notify("ia_rewrite_ntapp", "Clipboard vazio. Selecione um texto e tente novamente.");
113
+ log("Clipboard vazio.");
102
114
  return;
103
115
  }
104
116
 
105
117
  try {
118
+ log("Chamando API...");
106
119
  const rewritten = await callModel(config, original);
120
+ log(`Resposta recebida. Tamanho: ${rewritten.length}`);
107
121
  await writeClipboard(rewritten);
108
122
  runVbsSendKeys("^v");
109
123
  notify("ia_rewrite_ntapp", "Texto reescrito e colado com sucesso.");
124
+ log("Sucesso: texto colado.");
110
125
  } catch (err) {
111
126
  notify("ia_rewrite_ntapp", `Erro: ${err.message || err}`);
127
+ log(`Erro: ${err && (err.stack || err.message || err)}`);
112
128
  }
113
129
  }
114
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ia_rewrite_ntapp",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "CLI para reescrever texto selecionado via IA",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
package/setup.js CHANGED
@@ -12,8 +12,19 @@ function createShortcut() {
12
12
  "Start Menu",
13
13
  "Programs"
14
14
  );
15
+ fs.mkdirSync(startMenuPrograms, { recursive: true });
16
+
17
+ let moduleDir = __dirname;
18
+ try {
19
+ const npmRoot = execSync("npm root -g", { encoding: "utf8" }).trim();
20
+ if (npmRoot) {
21
+ const candidate = path.join(npmRoot, "ia_rewrite_ntapp");
22
+ if (fs.existsSync(candidate)) moduleDir = candidate;
23
+ }
24
+ } catch (_) {}
25
+
15
26
  const target = process.execPath;
16
- const script = path.join(__dirname, "index.js");
27
+ const script = path.join(moduleDir, "index.js");
17
28
  const lnkPath = path.join(startMenuPrograms, "ia_rewrite_ntapp.lnk");
18
29
 
19
30
  const ps = [
@@ -21,7 +32,7 @@ function createShortcut() {
21
32
  `$Shortcut = $WshShell.CreateShortcut(\\"${lnkPath}\\")`,
22
33
  `$Shortcut.TargetPath = \\\"${target}\\\"`,
23
34
  `$Shortcut.Arguments = \\\"${script}\\\"`,
24
- `$Shortcut.WorkingDirectory = \\\"${__dirname}\\\"`,
35
+ `$Shortcut.WorkingDirectory = \\\"${moduleDir}\\\"`,
25
36
  "$Shortcut.WindowStyle = 7",
26
37
  "$Shortcut.Hotkey = 'Ctrl+Alt+R'",
27
38
  "$Shortcut.Save()",