@neuralconfig/nrepo 0.0.3 → 0.0.4
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/dist/index.js +103 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { Command } from "commander";
|
|
5
|
-
import
|
|
5
|
+
import chalk21 from "chalk";
|
|
6
6
|
|
|
7
7
|
// src/config.ts
|
|
8
8
|
import { readFile, writeFile, mkdir } from "fs/promises";
|
|
@@ -1415,9 +1415,104 @@ async function graphCommand(id, opts) {
|
|
|
1415
1415
|
}
|
|
1416
1416
|
}
|
|
1417
1417
|
|
|
1418
|
+
// src/update-check.ts
|
|
1419
|
+
import { readFileSync, existsSync as existsSync2 } from "fs";
|
|
1420
|
+
import { writeFile as writeFile3, mkdir as mkdir3, copyFile } from "fs/promises";
|
|
1421
|
+
import { homedir as homedir2 } from "os";
|
|
1422
|
+
import { join as join3, dirname } from "path";
|
|
1423
|
+
import { fileURLToPath } from "url";
|
|
1424
|
+
import chalk20 from "chalk";
|
|
1425
|
+
var CHECK_FILE = join3(CONFIG_DIR, "update-check.json");
|
|
1426
|
+
var WEEK_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
1427
|
+
var PACKAGE_NAME = "@neuralconfig/nrepo";
|
|
1428
|
+
function checkForUpdates(currentVersion) {
|
|
1429
|
+
if (process.env["NREPO_NO_UPDATE_CHECK"] === "1") return;
|
|
1430
|
+
try {
|
|
1431
|
+
const cached = readCachedCheck();
|
|
1432
|
+
if (cached?.latest_version && isNewer(cached.latest_version, currentVersion)) {
|
|
1433
|
+
printUpdateNotice(currentVersion, cached.latest_version);
|
|
1434
|
+
}
|
|
1435
|
+
if (!cached || isStale(cached.last_checked)) {
|
|
1436
|
+
fetchAndCache(currentVersion);
|
|
1437
|
+
}
|
|
1438
|
+
} catch {
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
function printUpdateNotice(current, latest) {
|
|
1442
|
+
console.error(
|
|
1443
|
+
chalk20.dim(` nrepo ${latest} available (current: ${current}). Run `) + chalk20.dim.bold("npm i -g @neuralconfig/nrepo") + chalk20.dim(" to update.")
|
|
1444
|
+
);
|
|
1445
|
+
console.error("");
|
|
1446
|
+
}
|
|
1447
|
+
function readCachedCheck() {
|
|
1448
|
+
if (!existsSync2(CHECK_FILE)) return null;
|
|
1449
|
+
try {
|
|
1450
|
+
const raw = readFileSync(CHECK_FILE, "utf-8");
|
|
1451
|
+
return JSON.parse(raw);
|
|
1452
|
+
} catch {
|
|
1453
|
+
return null;
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
function isStale(lastChecked) {
|
|
1457
|
+
return Date.now() - new Date(lastChecked).getTime() > WEEK_MS;
|
|
1458
|
+
}
|
|
1459
|
+
function isNewer(latest, current) {
|
|
1460
|
+
const l = latest.split(".").map(Number);
|
|
1461
|
+
const c = current.split(".").map(Number);
|
|
1462
|
+
for (let i = 0; i < 3; i++) {
|
|
1463
|
+
if ((l[i] ?? 0) > (c[i] ?? 0)) return true;
|
|
1464
|
+
if ((l[i] ?? 0) < (c[i] ?? 0)) return false;
|
|
1465
|
+
}
|
|
1466
|
+
return false;
|
|
1467
|
+
}
|
|
1468
|
+
function fetchAndCache(currentVersion) {
|
|
1469
|
+
(async () => {
|
|
1470
|
+
const controller = new AbortController();
|
|
1471
|
+
const timeout = setTimeout(() => controller.abort(), 5e3);
|
|
1472
|
+
try {
|
|
1473
|
+
const res = await fetch(
|
|
1474
|
+
`https://registry.npmjs.org/${PACKAGE_NAME}/latest`,
|
|
1475
|
+
{ signal: controller.signal }
|
|
1476
|
+
);
|
|
1477
|
+
clearTimeout(timeout);
|
|
1478
|
+
if (!res.ok) return;
|
|
1479
|
+
const data = await res.json();
|
|
1480
|
+
const latest = data.version;
|
|
1481
|
+
if (!existsSync2(CONFIG_DIR)) {
|
|
1482
|
+
await mkdir3(CONFIG_DIR, { recursive: true });
|
|
1483
|
+
}
|
|
1484
|
+
const check = {
|
|
1485
|
+
last_checked: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1486
|
+
latest_version: latest
|
|
1487
|
+
};
|
|
1488
|
+
await writeFile3(CHECK_FILE, JSON.stringify(check, null, 2) + "\n", "utf-8");
|
|
1489
|
+
if (isNewer(latest, currentVersion)) {
|
|
1490
|
+
await updateSkillFile();
|
|
1491
|
+
}
|
|
1492
|
+
} catch {
|
|
1493
|
+
}
|
|
1494
|
+
})();
|
|
1495
|
+
}
|
|
1496
|
+
async function updateSkillFile() {
|
|
1497
|
+
try {
|
|
1498
|
+
const claudeDir = join3(homedir2(), ".claude");
|
|
1499
|
+
if (!existsSync2(claudeDir)) return;
|
|
1500
|
+
const skillDir = join3(claudeDir, "skills", "neuralrepo");
|
|
1501
|
+
if (!existsSync2(skillDir)) {
|
|
1502
|
+
await mkdir3(skillDir, { recursive: true });
|
|
1503
|
+
}
|
|
1504
|
+
const src = join3(dirname(fileURLToPath(import.meta.url)), "..", "skill", "SKILL.md");
|
|
1505
|
+
if (!existsSync2(src)) return;
|
|
1506
|
+
const dest = join3(skillDir, "SKILL.md");
|
|
1507
|
+
await copyFile(src, dest);
|
|
1508
|
+
} catch {
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1418
1512
|
// src/index.ts
|
|
1513
|
+
var VERSION = "0.0.4";
|
|
1419
1514
|
var program = new Command();
|
|
1420
|
-
program.name("nrepo").description("NeuralRepo \u2014 capture and manage ideas from the terminal").version(
|
|
1515
|
+
program.name("nrepo").description("NeuralRepo \u2014 capture and manage ideas from the terminal").version(VERSION);
|
|
1421
1516
|
program.command("login").description("Authenticate with NeuralRepo").option("--api-key", "Login with an API key instead of browser OAuth").action(wrap(loginCommand));
|
|
1422
1517
|
program.command("logout").description("Clear stored credentials").action(wrap(async () => {
|
|
1423
1518
|
await clearConfig();
|
|
@@ -1465,6 +1560,7 @@ var keys = program.command("key").description("Manage API keys");
|
|
|
1465
1560
|
keys.command("list").description("List all API keys").option("--json", "Output as JSON").option("--human", "Force human-readable output").action(wrap(keysListCommand));
|
|
1466
1561
|
keys.command("create <label>").description("Create a new API key").option("--json", "Output as JSON").option("--human", "Force human-readable output").action(wrap(keysCreateCommand));
|
|
1467
1562
|
keys.command("revoke <key-id>").description("Revoke an API key").option("--json", "Output as JSON").option("--human", "Force human-readable output").action(wrap(keysRevokeCommand));
|
|
1563
|
+
checkForUpdates(VERSION);
|
|
1468
1564
|
program.parse();
|
|
1469
1565
|
function collect(value, previous) {
|
|
1470
1566
|
return previous.concat([value]);
|
|
@@ -1496,21 +1592,21 @@ function wrap(fn) {
|
|
|
1496
1592
|
process.exit(1);
|
|
1497
1593
|
}
|
|
1498
1594
|
if (err instanceof AuthError) {
|
|
1499
|
-
console.error(
|
|
1595
|
+
console.error(chalk21.red(err.message));
|
|
1500
1596
|
process.exit(1);
|
|
1501
1597
|
}
|
|
1502
1598
|
if (err instanceof ApiError) {
|
|
1503
1599
|
if (err.status === 401) {
|
|
1504
|
-
console.error(
|
|
1600
|
+
console.error(chalk21.red("Authentication expired. Run `nrepo login` to re-authenticate."));
|
|
1505
1601
|
} else if (err.status === 403) {
|
|
1506
|
-
console.error(
|
|
1602
|
+
console.error(chalk21.yellow("This feature requires a Pro plan. Upgrade at https://neuralrepo.com/settings"));
|
|
1507
1603
|
} else {
|
|
1508
|
-
console.error(
|
|
1604
|
+
console.error(chalk21.red(`API error (${err.status}): ${err.message}`));
|
|
1509
1605
|
}
|
|
1510
1606
|
process.exit(1);
|
|
1511
1607
|
}
|
|
1512
1608
|
if (err instanceof Error && err.message.startsWith("Network error")) {
|
|
1513
|
-
console.error(
|
|
1609
|
+
console.error(chalk21.red(err.message));
|
|
1514
1610
|
process.exit(1);
|
|
1515
1611
|
}
|
|
1516
1612
|
throw err;
|