@cccarv82/freya 3.7.6 → 3.7.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cccarv82/freya",
3
- "version": "3.7.6",
3
+ "version": "3.7.7",
4
4
  "description": "Personal AI Assistant with local-first persistence",
5
5
  "scripts": {
6
6
  "health": "node scripts/validate-data.js && node scripts/validate-structure.js",
@@ -198,34 +198,74 @@ async function main() {
198
198
  // Step 3: Extract tasks/blockers from each daily log via planner
199
199
  console.log('── Step 3: Extracting tasks & blockers via planner ──');
200
200
 
201
- // Detect copilot command (now uses PowerShell on Windows, so fnm PATH works)
202
- let cmd = process.env.COPILOT_CMD || '';
203
- let useGhCopilot = false;
204
- if (!cmd) {
201
+ // Detect copilot use same approach as web.js (resolve full path)
202
+ let copilotResolved = process.env.COPILOT_CMD || '';
203
+ if (!copilotResolved) {
205
204
  console.log(' ℹ Detecting copilot CLI...');
206
- const testCopilot = await run('copilot', ['--version'], workspaceDir);
207
- if (testCopilot.code === 0) {
208
- cmd = 'copilot';
209
- console.log(` ✓ Found: ${(testCopilot.stdout || '').trim().split(/\r?\n/)[0]}`);
205
+ if (process.platform === 'win32') {
206
+ // Try 'where' first (system PATH)
207
+ try {
208
+ const p = execSync('where copilot 2>nul', { encoding: 'utf8', timeout: 5000 }).trim().split(/\r?\n/)[0];
209
+ if (p && fs.existsSync(p)) copilotResolved = p;
210
+ } catch { }
211
+ // Use PowerShell to resolve (works with fnm, nvm-windows, etc.)
212
+ if (!copilotResolved) {
213
+ try {
214
+ const p = execSync(
215
+ 'powershell.exe -NoProfile -Command "(Get-Command copilot -ErrorAction SilentlyContinue).Source"',
216
+ { encoding: 'utf8', timeout: 10000 }
217
+ ).trim();
218
+ if (p && fs.existsSync(p)) copilotResolved = p;
219
+ } catch { }
220
+ }
221
+ // Try gh copilot
222
+ if (!copilotResolved) {
223
+ try {
224
+ const p = execSync(
225
+ 'powershell.exe -NoProfile -Command "(Get-Command gh -ErrorAction SilentlyContinue).Source"',
226
+ { encoding: 'utf8', timeout: 10000 }
227
+ ).trim();
228
+ if (p && fs.existsSync(p)) copilotResolved = `gh-copilot:${p}`;
229
+ } catch { }
230
+ }
210
231
  } else {
211
- const testGh = await run('gh', ['copilot', '--version'], workspaceDir);
212
- if (testGh.code === 0) {
213
- cmd = 'gh';
214
- useGhCopilot = true;
215
- console.log(' ✓ Using gh copilot');
216
- } else {
217
- console.log(' Could not find copilot CLI.');
218
- console.log(` copilot stderr: ${(testCopilot.stderr || '').slice(0, 200)}`);
219
- console.log(` gh stderr: ${(testGh.stderr || '').slice(0, 200)}`);
220
- console.log(' Skipping task/blocker extraction.');
221
- dl.db.save();
222
- console.log('\n✅ Retroactive ingestion complete (embeddings only)!');
223
- return;
232
+ try {
233
+ const p = execSync('which copilot 2>/dev/null', { encoding: 'utf8', timeout: 5000 }).trim();
234
+ if (p) copilotResolved = p;
235
+ } catch { }
236
+ if (!copilotResolved) {
237
+ try {
238
+ const p = execSync('which gh 2>/dev/null', { encoding: 'utf8', timeout: 5000 }).trim();
239
+ if (p) copilotResolved = `gh-copilot:${p}`;
240
+ } catch { }
224
241
  }
225
242
  }
243
+ if (!copilotResolved) {
244
+ copilotResolved = 'copilot'; // last resort fallback
245
+ }
246
+ }
247
+ // Verify it works
248
+ const testArgs = copilotResolved.startsWith('gh-copilot:')
249
+ ? { cmd: copilotResolved.slice('gh-copilot:'.length), args: ['copilot', '--version'] }
250
+ : { cmd: copilotResolved, args: ['--version'] };
251
+ const testResult = await run(testArgs.cmd, testArgs.args, workspaceDir);
252
+ if (testResult.code === 0) {
253
+ console.log(` ✓ Found: ${(testResult.stdout || '').trim().split(/\r?\n/)[0]}`);
226
254
  } else {
227
- console.log(` Using COPILOT_CMD: ${cmd}`);
228
- useGhCopilot = cmd.toLowerCase().includes('gh') && !cmd.toLowerCase().includes('copilot');
255
+ console.log(' Could not find copilot CLI.');
256
+ console.log(` stderr: ${(testResult.stderr || '').slice(0, 200)}`);
257
+ console.log(' Skipping task/blocker extraction.');
258
+ dl.db.save();
259
+ console.log('\n✅ Retroactive ingestion complete (embeddings only)!');
260
+ return;
261
+ }
262
+ // Helper to build spawn args (same as copilotSpawnArgs in web.js)
263
+ function buildCopilotArgs(extraArgs) {
264
+ if (copilotResolved.startsWith('gh-copilot:')) {
265
+ const ghPath = copilotResolved.slice('gh-copilot:'.length);
266
+ return { cmd: ghPath, args: ['copilot', ...extraArgs] };
267
+ }
268
+ return { cmd: copilotResolved, args: extraArgs };
229
269
  }
230
270
  const agentEnv = { FREYA_WORKSPACE_DIR: workspaceDir };
231
271
  const slugMap = readProjectSlugMap(workspaceDir);
@@ -279,18 +319,18 @@ IMPORTANTE: Extraia APENAS informações explícitas do log. NÃO invente dados.
279
319
 
280
320
  try {
281
321
  let r;
282
- const baseArgs = useGhCopilot
283
- ? ['copilot', '-s', '--no-color', '--stream', 'off']
284
- : ['-s', '--no-color', '--stream', 'off'];
322
+ const copilotExtra = ['-s', '--no-color', '--stream', 'off'];
285
323
 
286
324
  if (fullPrompt.length > SAFE_ARG_LEN) {
287
325
  const tmpFile = path.join(os.tmpdir(), `freya-retro-${Date.now()}.txt`);
288
326
  fs.writeFileSync(tmpFile, fullPrompt, 'utf8');
289
327
  const filePrompt = `Leia o arquivo abaixo e extraia tasks/blockers conforme as instruções contidas nele.\nARQUIVO: ${tmpFile}`;
290
- r = await run(cmd, [...baseArgs, '--add-dir', os.tmpdir(), '--allow-all-tools', '-p', filePrompt], workspaceDir, agentEnv);
328
+ const { cmd: sc, args: sa } = buildCopilotArgs([...copilotExtra, '--add-dir', os.tmpdir(), '--allow-all-tools', '-p', filePrompt]);
329
+ r = await run(sc, sa, workspaceDir, agentEnv);
291
330
  try { fs.unlinkSync(tmpFile); } catch { }
292
331
  } else {
293
- r = await run(cmd, [...baseArgs, '-p', fullPrompt], workspaceDir, agentEnv);
332
+ const { cmd: sc, args: sa } = buildCopilotArgs([...copilotExtra, '-p', fullPrompt]);
333
+ r = await run(sc, sa, workspaceDir, agentEnv);
294
334
  }
295
335
 
296
336
  const out = (r.stdout + r.stderr).trim();
@@ -299,7 +339,7 @@ IMPORTANTE: Extraia APENAS informações explícitas do log. NÃO invente dados.
299
339
  // On first error, show verbose diagnostic
300
340
  if (totalErrors === 1) {
301
341
  console.log(`\n ⚠ Planner diagnostic for ${date}:`);
302
- console.log(` Command: ${cmd} ${(useGhCopilot ? baseArgs : ['-s', '--no-color', '--stream', 'off', '-p', '...']).join(' ')}`);
342
+ console.log(` Command: ${copilotResolved} -s --no-color --stream off -p ...`);
303
343
  console.log(` Exit code: ${r.code}`);
304
344
  console.log(` stdout: ${(r.stdout || '').slice(0, 300)}`);
305
345
  console.log(` stderr: ${(r.stderr || '').slice(0, 300)}`);