korveniq 1.0.4 → 1.0.6
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/README.md +6 -5
- package/lib/build-profile.json +2 -2
- package/lib/update-commands.js +7 -0
- package/lib/update-source.js +13 -5
- package/lib/update-view.js +3 -0
- package/lib/update.js +59 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -823,11 +823,12 @@ commands, the browser) inherits it.
|
|
|
823
823
|
terminal may be left in raw mode (type `stty sane` or `reset` to fix it), and
|
|
824
824
|
commands the agent was running keep running in their own process group.
|
|
825
825
|
|
|
826
|
-
**Tested runtimes
|
|
827
|
-
Ubuntu 24.04)
|
|
828
|
-
Node.js 18.17 some of the project's test and benchmark
|
|
829
|
-
CLI's tests pass on Linux when that is worked around).
|
|
830
|
-
tests against an installed package:
|
|
826
|
+
**Tested runtimes.** The full suite last ran for 1.0.4, on Node.js 24.11.1 (macOS
|
|
827
|
+
and Ubuntu 24.04). The updater tests also run on 18.17 (and, for 1.0.4, on 20.18
|
|
828
|
+
and 22.12) on Linux. On Node.js 18.17 some of the project's test and benchmark
|
|
829
|
+
tooling does not run (the CLI's tests pass on Linux when that is worked around).
|
|
830
|
+
To run the end-to-end tests against an installed package:
|
|
831
|
+
`KORVENIQ_TEST_BIN=$(which korveniq) npm test`.
|
|
831
832
|
|
|
832
833
|
---
|
|
833
834
|
|
package/lib/build-profile.json
CHANGED
package/lib/update-commands.js
CHANGED
|
@@ -67,6 +67,13 @@ async function update({ check: checkOnly = false } = {}, { install = state.detec
|
|
|
67
67
|
outcome = installer.apply(install);
|
|
68
68
|
} catch (err) {
|
|
69
69
|
reporter.done();
|
|
70
|
+
if (err.code === 'NOT_READY') {
|
|
71
|
+
throw new CliError(`v${manifest.version} cannot be downloaded yet`, {
|
|
72
|
+
cause: 'A release that was just published can take a few minutes to become downloadable. Your current version is unchanged.',
|
|
73
|
+
action: 'Run `korveniq update` again in a few minutes. If this goes on, update by hand:',
|
|
74
|
+
commands: [install.command],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
70
77
|
throw err instanceof updater.UpdateError ? failure(err) : err;
|
|
71
78
|
}
|
|
72
79
|
if (outcome.status === 'installed') view.print(view.installed(outcome.version));
|
package/lib/update-source.js
CHANGED
|
@@ -48,7 +48,7 @@ function _setSourceForTests(next, nextLimits) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
class UpdateError extends Error {
|
|
51
|
-
/** code: OFFLINE TIMEOUT RATE_LIMIT HTTP MALFORMED UNTRUSTED KEY_UNKNOWN INTEGRITY TOO_LARGE INTERRUPTED ABORTED PACKAGE INSTALL BUSY UNSUPPORTED */
|
|
51
|
+
/** code: OFFLINE TIMEOUT RATE_LIMIT HTTP NOT_READY MALFORMED UNTRUSTED KEY_UNKNOWN INTEGRITY TOO_LARGE INTERRUPTED ABORTED PACKAGE INSTALL BUSY UNSUPPORTED */
|
|
52
52
|
constructor(code, message, extra = {}) {
|
|
53
53
|
super(message);
|
|
54
54
|
this.name = 'UpdateError';
|
|
@@ -210,10 +210,18 @@ async function fetchLatest({ signal, userAgent, retries = 0, timeoutMs } = {}) {
|
|
|
210
210
|
async function download(manifest, { signal, userAgent, onProgress } = {}) {
|
|
211
211
|
verifySignature(manifest);
|
|
212
212
|
if (manifest.tarball !== tarballUrl(manifest.version)) throw new UpdateError('UNTRUSTED', 'The download address is not the official one for this version');
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
let bytes;
|
|
214
|
+
try {
|
|
215
|
+
bytes = await withRetries(
|
|
216
|
+
() => get(manifest.tarball, { accept: 'application/octet-stream', maxBytes: limits.tarballBytes, timeoutMs: limits.downloadTimeoutMs, stallMs: limits.stallTimeoutMs, signal, userAgent, onProgress }),
|
|
217
|
+
{ retries: limits.retries, signal },
|
|
218
|
+
);
|
|
219
|
+
} catch (err) {
|
|
220
|
+
// The registry announces a new release some minutes before its file can be downloaded. Only that one answer, for
|
|
221
|
+
// the file of a verified release, means "not yet"; the caller decides how long to keep believing it (lib/update.js).
|
|
222
|
+
if (err.code === 'HTTP' && err.status === 404) throw new UpdateError('NOT_READY', 'The package of this release cannot be downloaded yet', { status: 404 });
|
|
223
|
+
throw err;
|
|
224
|
+
}
|
|
217
225
|
verifyBytes(bytes, manifest);
|
|
218
226
|
return bytes;
|
|
219
227
|
}
|
package/lib/update-view.js
CHANGED
|
@@ -25,6 +25,9 @@ const detail = (text) => ui.theme.dim(` ${ui.glyphs(text)}`);
|
|
|
25
25
|
/** Lines for a notice between turns. */
|
|
26
26
|
function notice(kind, { current, version, progress, followUp, install, auto }) {
|
|
27
27
|
if (kind === 'failed') return failed(null, install);
|
|
28
|
+
if (kind === 'deferred') {
|
|
29
|
+
return [`${ui.theme.info(glyph().up)} Update v${version} cannot be downloaded yet.`, detail('Korveniq will try again later. Your current version keeps working.')];
|
|
30
|
+
}
|
|
28
31
|
if (kind === 'unverifiable') {
|
|
29
32
|
return [
|
|
30
33
|
`${ui.theme.warn(ui.symbols.warning)} Korveniq cannot verify new releases automatically.`,
|
package/lib/update.js
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* → available (automatic updates off, or this installation cannot be changed)
|
|
14
14
|
* → downloading → staged → (on exit) installed | waiting | failed
|
|
15
15
|
* → failed
|
|
16
|
+
* downloading → deferred the new release is announced but its file is not there yet: tried again after 1, 2, 4,
|
|
17
|
+
* 8, then every 15 minutes; reported as failed if it is still missing after an hour
|
|
16
18
|
* checking → unverifiable npm signs with a key this version does not know (said once, nothing installed)
|
|
17
19
|
* → rejected the release failed verification (said once, nothing installed)
|
|
18
20
|
*
|
|
@@ -41,6 +43,9 @@ const MAX_BACKOFF_MS = 24 * 60 * 60_000;
|
|
|
41
43
|
const FAILED_VERSION_PAUSE_MS = 24 * 60 * 60_000;
|
|
42
44
|
const FINISH_GRACE_MS = 2_000;
|
|
43
45
|
const VERIFICATION = ['KEY_UNKNOWN', 'UNTRUSTED'];
|
|
46
|
+
const MINUTE = 60_000;
|
|
47
|
+
const NOT_READY_DELAYS_MS = Object.freeze([1, 2, 4, 8, 15].map((m) => m * MINUTE));
|
|
48
|
+
const NOT_READY_LIMIT_MS = 60 * MINUTE;
|
|
44
49
|
|
|
45
50
|
const userAgent = `korveniq-cli/${pkg.version}`;
|
|
46
51
|
const debug = (message) => ui.event('DEBUG', `update: ${message}`);
|
|
@@ -97,6 +102,27 @@ async function check({ force = false, signal, now = Date.now, intervalMs, cacheF
|
|
|
97
102
|
/** Is `manifest` something to move to from `current`? Deprecated releases are never offered. */
|
|
98
103
|
const isOffer = (manifest, current) => Boolean(manifest) && !manifest.deprecated && semver.isUpgrade(manifest.version, current);
|
|
99
104
|
|
|
105
|
+
// A release whose file is not downloadable yet, remembered next to the installation so that every session (and the
|
|
106
|
+
// next launch) keeps to the same pace: { version, attempts, firstAt, retryAt }.
|
|
107
|
+
const deferralFile = (install) => path.join(install.stateDir, 'deferred.json');
|
|
108
|
+
|
|
109
|
+
/** The record for `version`, or null. Times that make no sense (a clock that moved, a damaged file) are not believed. */
|
|
110
|
+
function readDeferral(install, version, now, delays = NOT_READY_DELAYS_MS) {
|
|
111
|
+
const d = state.readJson(deferralFile(install));
|
|
112
|
+
if (!d || d.version !== version || !Number.isInteger(d.attempts) || d.attempts < 1) return null;
|
|
113
|
+
if (!(d.firstAt <= now + MINUTE) || !(d.retryAt <= now + Math.max(...delays))) return null;
|
|
114
|
+
return d;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Count one more "not there yet" and say when to look again. */
|
|
118
|
+
function defer(install, version, now, delays = NOT_READY_DELAYS_MS) {
|
|
119
|
+
const earlier = readDeferral(install, version, now, delays);
|
|
120
|
+
const attempts = earlier ? earlier.attempts + 1 : 1;
|
|
121
|
+
const record = { version, attempts, firstAt: earlier ? earlier.firstAt : now, retryAt: now + delays[Math.min(attempts, delays.length) - 1] };
|
|
122
|
+
state.writeJson(deferralFile(install), record);
|
|
123
|
+
return record;
|
|
124
|
+
}
|
|
125
|
+
|
|
100
126
|
/**
|
|
101
127
|
* Download and verify `manifest` and keep it for installation. Only one process downloads at a time.
|
|
102
128
|
* @returns {Promise<'staged'|'busy'>}
|
|
@@ -114,6 +140,7 @@ async function stage(install, manifest, { signal, onProgress, manual = false } =
|
|
|
114
140
|
for (const name of fs.readdirSync(install.stateDir)) if (name.endsWith('.part')) fs.rmSync(path.join(install.stateDir, name), { force: true });
|
|
115
141
|
const bytes = await source.download(manifest, { signal, userAgent, onProgress });
|
|
116
142
|
installer.writeStaged(install, manifest, bytes, { manual });
|
|
143
|
+
fs.rmSync(deferralFile(install), { force: true });
|
|
117
144
|
return 'staged';
|
|
118
145
|
} finally {
|
|
119
146
|
lock.release();
|
|
@@ -129,7 +156,7 @@ function sessionAllowed({ env = process.env, stdin = process.stdin, stdout = pro
|
|
|
129
156
|
}
|
|
130
157
|
|
|
131
158
|
class Session {
|
|
132
|
-
constructor({ install = state.detect(), current = pkg.version, now = Date.now, cacheFile = CACHE_FILE, print = view.print, enabled } = {}) {
|
|
159
|
+
constructor({ install = state.detect(), current = pkg.version, now = Date.now, cacheFile = CACHE_FILE, print = view.print, enabled, retryDelaysMs = NOT_READY_DELAYS_MS } = {}) {
|
|
133
160
|
this.install = install;
|
|
134
161
|
this.current = current;
|
|
135
162
|
this.now = now;
|
|
@@ -143,6 +170,22 @@ class Session {
|
|
|
143
170
|
this.abort = new AbortController();
|
|
144
171
|
this.work = null;
|
|
145
172
|
this.nextCheckAt = 0;
|
|
173
|
+
this.retryDelaysMs = retryDelaysMs;
|
|
174
|
+
this.timer = null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Look again at `at`, even if nobody types meanwhile. The timer never keeps the process alive and prints nothing. */
|
|
178
|
+
retryAt(at) {
|
|
179
|
+
clearTimeout(this.timer);
|
|
180
|
+
this.nextCheckAt = at;
|
|
181
|
+
this.timer = setTimeout(() => this.tick(), Math.max(0, at - this.now()) + 20);
|
|
182
|
+
this.timer.unref();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The release is announced but not downloadable: wait while that is plausible, report it once it is not. */
|
|
186
|
+
postpone(record) {
|
|
187
|
+
this.phase = this.now() - record.firstAt < NOT_READY_LIMIT_MS ? 'deferred' : 'failed';
|
|
188
|
+
this.retryAt(record.retryAt);
|
|
146
189
|
}
|
|
147
190
|
|
|
148
191
|
/** Start (or, once the cache has aged, repeat) the background check. Returns immediately. */
|
|
@@ -191,17 +234,28 @@ class Session {
|
|
|
191
234
|
this.phase = 'available';
|
|
192
235
|
return;
|
|
193
236
|
}
|
|
237
|
+
const waiting = readDeferral(this.install, manifest.version, this.now(), this.retryDelaysMs);
|
|
238
|
+
if (waiting && waiting.retryAt > this.now()) return this.postpone(waiting);
|
|
194
239
|
this.phase = 'downloading';
|
|
195
240
|
this.progress = null;
|
|
196
|
-
|
|
241
|
+
let staged;
|
|
242
|
+
try {
|
|
243
|
+
staged = await stage(this.install, manifest, { signal: this.abort.signal, onProgress: (received, total) => (this.progress = { received, total }) });
|
|
244
|
+
} catch (err) {
|
|
245
|
+
if (err.code !== 'NOT_READY') throw err;
|
|
246
|
+
debug(`${err.code}: ${err.message}`);
|
|
247
|
+
return this.postpone(defer(this.install, manifest.version, this.now(), this.retryDelaysMs));
|
|
248
|
+
}
|
|
197
249
|
this.phase = staged === 'staged' ? 'staged' : 'current'; // busy: another session is downloading it
|
|
198
250
|
}
|
|
199
251
|
|
|
200
252
|
/** Called while no reply, tool or question is active. Says each thing about a version once. */
|
|
201
253
|
notice() {
|
|
202
254
|
if (!this.enabled) return;
|
|
203
|
-
const kind = ['available', 'downloading', 'staged', 'failed', 'unverifiable', 'rejected'].includes(this.phase) ? this.phase : null;
|
|
255
|
+
const kind = ['available', 'downloading', 'deferred', 'staged', 'failed', 'unverifiable', 'rejected'].includes(this.phase) ? this.phase : null;
|
|
204
256
|
if (!kind) return;
|
|
257
|
+
// Waiting for a release is not news, unless the user was already told that it is on its way.
|
|
258
|
+
if (kind === 'deferred' && !this.announced.has(`downloading:${this.version}`)) return;
|
|
205
259
|
const key = `${kind}:${this.version}`;
|
|
206
260
|
if (this.announced.has(key)) return;
|
|
207
261
|
this.announced.add(key);
|
|
@@ -220,6 +274,7 @@ class Session {
|
|
|
220
274
|
await Promise.race([this.work, new Promise((resolve) => setTimeout(resolve, FINISH_GRACE_MS).unref())]);
|
|
221
275
|
}
|
|
222
276
|
this.abort.abort();
|
|
277
|
+
clearTimeout(this.timer);
|
|
223
278
|
if (!allowed) return null;
|
|
224
279
|
try {
|
|
225
280
|
const staged = fs.existsSync(this.install.stateDir) ? installer.readStaged(this.install) : null;
|
|
@@ -240,4 +295,4 @@ class Session {
|
|
|
240
295
|
}
|
|
241
296
|
}
|
|
242
297
|
|
|
243
|
-
module.exports = { check, stage, isOffer, sessionAllowed, Session, UpdateError, CACHE_FILE };
|
|
298
|
+
module.exports = { NOT_READY_DELAYS_MS, NOT_READY_LIMIT_MS, check, stage, isOffer, sessionAllowed, Session, UpdateError, CACHE_FILE };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "korveniq",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Official command-line interface for the Korveniq AI platform",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"keywords": [
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"llm"
|
|
15
15
|
],
|
|
16
16
|
"author": "Korveniq",
|
|
17
|
-
"homepage": "https://github.com/korveniq/
|
|
17
|
+
"homepage": "https://github.com/korveniq/Korveniq-AI-CLI#readme",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/korveniq/
|
|
20
|
+
"url": "git+https://github.com/korveniq/Korveniq-AI-CLI.git"
|
|
21
21
|
},
|
|
22
22
|
"bugs": {
|
|
23
|
-
"url": "https://github.com/korveniq/
|
|
23
|
+
"url": "https://github.com/korveniq/Korveniq-AI-CLI/issues"
|
|
24
24
|
},
|
|
25
25
|
"main": "bin/index.js",
|
|
26
26
|
"bin": {
|