ia_rewrite_ntapp 1.0.6 → 1.0.8

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 (2) hide show
  1. package/index.js +32 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -39,7 +39,7 @@ function runVbsSendKeys(keys) {
39
39
  }
40
40
 
41
41
  function readClipboardFallback() {
42
- const output = execSync("powershell -NoProfile -Command Get-Clipboard", { encoding: "utf8" });
42
+ const output = execSync("powershell -NoProfile -Command Get-Clipboard -Raw", { encoding: "utf8" });
43
43
  return String(output);
44
44
  }
45
45
 
@@ -51,6 +51,17 @@ async function readClipboard() {
51
51
  }
52
52
  }
53
53
 
54
+ async function readClipboardWithRetry(previousValue, maxWaitMs = 1500) {
55
+ const start = Date.now();
56
+ let current = await readClipboard();
57
+ while (Date.now() - start < maxWaitMs) {
58
+ if (current && current.trim() && current !== previousValue) return current;
59
+ await new Promise((r) => setTimeout(r, 100));
60
+ current = await readClipboard();
61
+ }
62
+ return current;
63
+ }
64
+
54
65
  function writeClipboardFallback(text) {
55
66
  const tmpPath = path.join(os.tmpdir(), `ia_rewrite_clip_${Date.now()}_${Math.random()}.txt`);
56
67
  fs.writeFileSync(tmpPath, String(text), "utf8");
@@ -69,6 +80,21 @@ async function writeClipboard(text) {
69
80
  }
70
81
  }
71
82
 
83
+ async function writeClipboardWithVerify(text, maxWaitMs = 1500) {
84
+ await writeClipboard(text);
85
+ const start = Date.now();
86
+ let current = await readClipboard();
87
+ while (Date.now() - start < maxWaitMs) {
88
+ if (current === text) return true;
89
+ await new Promise((r) => setTimeout(r, 100));
90
+ current = await readClipboard();
91
+ }
92
+ // força fallback se não confirmou
93
+ writeClipboardFallback(text);
94
+ current = await readClipboard();
95
+ return current === text;
96
+ }
97
+
72
98
  function loadConfig() {
73
99
  if (!fs.existsSync(CONFIG_FILE)) return null;
74
100
  const raw = fs.readFileSync(CONFIG_FILE, "utf8").trim();
@@ -112,7 +138,8 @@ async function main() {
112
138
  runVbsSendKeys("^c");
113
139
  await new Promise((r) => setTimeout(r, 150));
114
140
 
115
- const original = (await readClipboard()).trim();
141
+ const beforeCopy = await readClipboard();
142
+ const original = (await readClipboardWithRetry(beforeCopy)).trim();
116
143
  log(`Clipboard lido. Tamanho: ${original.length}`);
117
144
  if (!original) {
118
145
  notify("ia_rewrite_ntapp", "Clipboard vazio. Selecione um texto e tente novamente.");
@@ -124,7 +151,9 @@ async function main() {
124
151
  log("Chamando API...");
125
152
  const rewritten = await callModel(config, original);
126
153
  log(`Resposta recebida. Tamanho: ${rewritten.length}`);
127
- await writeClipboard(rewritten);
154
+ const ok = await writeClipboardWithVerify(rewritten);
155
+ log(`Clipboard gravado: ${ok ? "ok" : "falha"}`);
156
+ await new Promise((r) => setTimeout(r, 150));
128
157
  runVbsSendKeys("^v");
129
158
  notify("ia_rewrite_ntapp", "Texto reescrito e colado com sucesso.");
130
159
  log("Sucesso: texto colado.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ia_rewrite_ntapp",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "CLI para reescrever texto selecionado via IA",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",