karajan-code 1.38.2 → 1.39.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "karajan-code",
3
- "version": "1.38.2",
3
+ "version": "1.39.0",
4
4
  "description": "Local multi-agent coding orchestrator with TDD, SonarQube, and code review pipeline",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0",
package/src/cli.js CHANGED
@@ -25,9 +25,14 @@ import { architectCommand } from "./commands/architect.js";
25
25
  import { auditCommand } from "./commands/audit.js";
26
26
  import { boardCommand } from "./commands/board.js";
27
27
 
28
+ import { printUpdateNotice } from "./utils/update-check.js";
29
+
28
30
  const PKG_PATH = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../package.json");
29
31
  const PKG_VERSION = JSON.parse(readFileSync(PKG_PATH, "utf8")).version;
30
32
 
33
+ // Non-blocking update check (runs in background, prints after command output)
34
+ printUpdateNotice(PKG_VERSION).catch(() => {});
35
+
31
36
  async function withConfig(commandName, flags, fn) {
32
37
  const { config } = await loadConfig();
33
38
  const merged = applyRunOverrides(config, flags || {});
@@ -0,0 +1,74 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { getKarajanHome } from "./paths.js";
4
+
5
+ const CACHE_FILE = "update-check.json";
6
+ const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
7
+ const PACKAGE_NAME = "karajan-code";
8
+
9
+ /**
10
+ * Check npm for a newer version. Non-blocking, cached for 24h.
11
+ * Returns { updateAvailable, latest, current } or null if check fails/cached.
12
+ */
13
+ export async function checkForUpdate(currentVersion) {
14
+ try {
15
+ const cachePath = path.join(getKarajanHome(), CACHE_FILE);
16
+
17
+ // Check cache first
18
+ try {
19
+ const raw = await fs.readFile(cachePath, "utf8");
20
+ const cache = JSON.parse(raw);
21
+ if (cache.checkedAt && Date.now() - cache.checkedAt < CACHE_TTL_MS) {
22
+ if (!cache.latest || cache.latest === currentVersion) return null;
23
+ return { updateAvailable: true, latest: cache.latest, current: currentVersion };
24
+ }
25
+ } catch { /* no cache or expired */ }
26
+
27
+ // Fetch from npm (timeout 3s, don't block)
28
+ const controller = new AbortController();
29
+ const timeout = setTimeout(() => controller.abort(), 3000);
30
+ const res = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {
31
+ signal: controller.signal,
32
+ headers: { "Accept": "application/json" },
33
+ });
34
+ clearTimeout(timeout);
35
+
36
+ if (!res.ok) return null;
37
+ const data = await res.json();
38
+ const latest = data.version;
39
+
40
+ // Save cache
41
+ await fs.mkdir(getKarajanHome(), { recursive: true });
42
+ await fs.writeFile(cachePath, JSON.stringify({ latest, checkedAt: Date.now() }), "utf8");
43
+
44
+ if (latest === currentVersion) return null;
45
+ if (compareVersions(latest, currentVersion) > 0) {
46
+ return { updateAvailable: true, latest, current: currentVersion };
47
+ }
48
+ return null;
49
+ } catch {
50
+ return null; // Network error, offline, etc. Never block.
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Print update notice if available. Call at CLI startup, non-blocking.
56
+ */
57
+ export async function printUpdateNotice(currentVersion) {
58
+ const result = await checkForUpdate(currentVersion);
59
+ if (result?.updateAvailable) {
60
+ console.log(`\n Update available: v${result.current} → v${result.latest}`);
61
+ console.log(` Run: npm install -g ${PACKAGE_NAME}\n`);
62
+ }
63
+ }
64
+
65
+ /** Simple semver compare: returns >0 if a > b, <0 if a < b, 0 if equal */
66
+ function compareVersions(a, b) {
67
+ const pa = a.split(".").map(Number);
68
+ const pb = b.split(".").map(Number);
69
+ for (let i = 0; i < 3; i++) {
70
+ if ((pa[i] || 0) > (pb[i] || 0)) return 1;
71
+ if ((pa[i] || 0) < (pb[i] || 0)) return -1;
72
+ }
73
+ return 0;
74
+ }