@hone-ai/cli 1.17.0 → 1.18.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.
Files changed (2) hide show
  1. package/hone-cli.js +48 -1
  2. package/package.json +3 -1
package/hone-cli.js CHANGED
@@ -55,8 +55,28 @@ function getConfig() {
55
55
  return { token, apiUrl };
56
56
  }
57
57
 
58
+ // HC-019y-followup-3: module-level upgrade-warning bucket. Set by the
59
+ // axios response interceptor when the server's X-CLI-Latest-Version
60
+ // header reports a newer version than ours. Printed once at process
61
+ // exit so the warning lands AFTER the command's normal output and
62
+ // doesn't fight for attention with whatever the user is doing.
63
+ let _outdatedWarning = null;
64
+
65
+ function _compareSemverMinor(a, b) {
66
+ // Returns true if `a` is strictly older than `b` for major.minor.patch.
67
+ // Liberal-parse: anything we can't make sense of → false (don't warn).
68
+ const re = /^(\d+)\.(\d+)\.(\d+)/;
69
+ const ma = re.exec(String(a || '')), mb = re.exec(String(b || ''));
70
+ if (!ma || !mb) return false;
71
+ const [, aMaj, aMin, aPat] = ma.map(Number);
72
+ const [, bMaj, bMin, bPat] = mb.map(Number);
73
+ if (aMaj !== bMaj) return aMaj < bMaj;
74
+ if (aMin !== bMin) return aMin < bMin;
75
+ return aPat < bPat;
76
+ }
77
+
58
78
  function api(config) {
59
- return axios.create({
79
+ const client = axios.create({
60
80
  baseURL: config.apiUrl,
61
81
  headers: {
62
82
  Authorization: `Bearer ${config.token}`,
@@ -64,8 +84,35 @@ function api(config) {
64
84
  },
65
85
  timeout: 30_000,
66
86
  });
87
+ // HC-019y-followup-3: response interceptor reads server's
88
+ // X-CLI-Latest-Version, sets the upgrade-warning bucket if outdated.
89
+ // Fire-and-forget — never throws. Captures errors silently so a
90
+ // missing/malformed header can't break the command.
91
+ client.interceptors.response.use(
92
+ (response) => {
93
+ try {
94
+ const latest = response?.headers?.['x-cli-latest-version'];
95
+ if (latest && _compareSemverMinor(pkg.version, latest)) {
96
+ _outdatedWarning =
97
+ ` ⚠ @hone-ai/cli ${latest} is available — you have ${pkg.version}\n` +
98
+ ` Run: npm install -g @hone-ai/cli@latest`;
99
+ }
100
+ } catch { /* never break the response path */ }
101
+ return response;
102
+ },
103
+ (error) => Promise.reject(error)
104
+ );
105
+ return client;
67
106
  }
68
107
 
108
+ // HC-019y-followup-3: emit the upgrade warning at process exit if set.
109
+ // Wrapped in try/catch — a failed warning is fundamentally non-critical.
110
+ process.on('exit', () => {
111
+ if (_outdatedWarning) {
112
+ try { console.error('\n' + _outdatedWarning); } catch { /* swallow */ }
113
+ }
114
+ });
115
+
69
116
  // ── SETUP command ─────────────────────────────────────────────────────────────
70
117
  program
71
118
  .command('setup')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hone-ai/cli",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "Hone AI — Enterprise SDLC Pipeline CLI",
5
5
  "main": "hone-cli.js",
6
6
  "bin": {
@@ -16,6 +16,8 @@
16
16
  "scripts": {
17
17
  "test": "echo \"No tests yet\" && exit 0",
18
18
  "link": "npm link",
19
+ "sync-server-cli-version": "node scripts/sync-server-cli-version.js",
20
+ "prepublishOnly": "node scripts/sync-server-cli-version.js",
19
21
  "postinstall": "echo '\\n Hone AI CLI installed successfully.\\n Next: run `hone init --token <YOUR_TOKEN>` to configure.\\n Docs: https://github.com/subbareddyvani/hone-server\\n'"
20
22
  },
21
23
  "dependencies": {