@bolt-cli/cli 0.0.0-stage → 0.13.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/LICENSE +75 -0
- package/README.md +155 -2
- package/bin/bolt.js +21 -0
- package/lib/agent.js +361 -0
- package/lib/api.js +246 -0
- package/lib/bootstrap.js +292 -0
- package/lib/browser.js +152 -0
- package/lib/cancel.js +153 -0
- package/lib/checkpoints.js +67 -0
- package/lib/cli.js +2637 -0
- package/lib/completion.js +77 -0
- package/lib/config.js +80 -0
- package/lib/doctor.js +110 -0
- package/lib/export.js +77 -0
- package/lib/history.js +78 -0
- package/lib/memory.js +80 -0
- package/lib/output.js +88 -0
- package/lib/permissions.js +167 -0
- package/lib/present.js +181 -0
- package/lib/redact.js +56 -0
- package/lib/session.js +153 -0
- package/lib/toolparse.js +752 -0
- package/lib/tools.js +606 -0
- package/lib/ui.js +783 -0
- package/lib/updatecheck.js +114 -0
- package/lib/watch.js +698 -0
- package/package.json +36 -6
- package/templates/README.md +44 -0
- package/templates/aslr-offset-probe.sh +96 -0
- package/templates/crash-offset-pattern.sh +81 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Update check: one quiet npm-registry lookup per 12h per machine. The result
|
|
3
|
+
// is cached in ~/.bolt/config.json, so the next session greets the operator
|
|
4
|
+
// with the notice even if the check itself happened offline mid-session.
|
|
5
|
+
// Never blocking, never throwing: a failed fetch simply means no notice today
|
|
6
|
+
// and a retry next session. Opt out with BOLT_NO_UPDATE_CHECK=1.
|
|
7
|
+
const config = require("./config");
|
|
8
|
+
|
|
9
|
+
const REGISTRY_URL = "https://registry.npmjs.org/@bolt-cli/cli/latest";
|
|
10
|
+
const CHECK_INTERVAL_MS = 12 * 60 * 60 * 1000;
|
|
11
|
+
const FETCH_TIMEOUT_MS = 4000;
|
|
12
|
+
|
|
13
|
+
function optOut() {
|
|
14
|
+
return process.env.BOLT_NO_UPDATE_CHECK === "1";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function parseVersion(value) {
|
|
18
|
+
const raw = String(value || "").trim().replace(/^v/i, "");
|
|
19
|
+
const dash = raw.indexOf("-");
|
|
20
|
+
const core = dash === -1 ? raw : raw.slice(0, dash);
|
|
21
|
+
const pre = dash === -1 ? "" : raw.slice(dash + 1);
|
|
22
|
+
const nums = core
|
|
23
|
+
.split(".")
|
|
24
|
+
.map((part) => (/^\d+$/.test(part) ? Number(part) : 0));
|
|
25
|
+
return { nums, pre };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Numeric dot-compare with semver prerelease awareness (0.13.0-rc1 sorts
|
|
30
|
+
* below 0.13.0). Unknown shapes degrade to 0, never to a false upgrade.
|
|
31
|
+
*/
|
|
32
|
+
function compareVersions(a, b) {
|
|
33
|
+
const va = parseVersion(a);
|
|
34
|
+
const vb = parseVersion(b);
|
|
35
|
+
const len = Math.max(va.nums.length, vb.nums.length);
|
|
36
|
+
for (let i = 0; i < len; i++) {
|
|
37
|
+
const na = va.nums[i] || 0;
|
|
38
|
+
const nb = vb.nums[i] || 0;
|
|
39
|
+
if (na !== nb) return na > nb ? 1 : -1;
|
|
40
|
+
}
|
|
41
|
+
if (va.pre !== vb.pre) {
|
|
42
|
+
// Same core: a prerelease sorts below the release it belongs to.
|
|
43
|
+
if (!va.pre) return 1;
|
|
44
|
+
if (!vb.pre) return -1;
|
|
45
|
+
return va.pre > vb.pre ? 1 : -1;
|
|
46
|
+
}
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isNewer(latest, current) {
|
|
51
|
+
return compareVersions(latest, current) > 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function noticeText(current, latest) {
|
|
55
|
+
return `Update available: v${current} -> v${latest} - run: npm update -g @bolt-cli/cli (or: bolt update)`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The notice from the cached state only. Synchronous, zero network. */
|
|
59
|
+
function cachedNotice(current, store) {
|
|
60
|
+
if (optOut()) return null;
|
|
61
|
+
const cfg = (store || config).load();
|
|
62
|
+
if (!cfg.updateLatest || !isNewer(cfg.updateLatest, current)) return null;
|
|
63
|
+
return noticeText(current, cfg.updateLatest);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** npm registry "latest" version, or "" on any failure/timeout. */
|
|
67
|
+
async function fetchLatest(fetchImpl) {
|
|
68
|
+
const doFetch = fetchImpl || globalThis.fetch;
|
|
69
|
+
if (!doFetch) return "";
|
|
70
|
+
const controller = new AbortController();
|
|
71
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
72
|
+
try {
|
|
73
|
+
const res = await doFetch(REGISTRY_URL, { signal: controller.signal, headers: { accept: "application/json" } });
|
|
74
|
+
if (!res.ok) return "";
|
|
75
|
+
const body = await res.json();
|
|
76
|
+
return body && typeof body.version === "string" ? body.version.trim() : "";
|
|
77
|
+
} catch {
|
|
78
|
+
return "";
|
|
79
|
+
} finally {
|
|
80
|
+
clearTimeout(timer);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Refresh the cached latest-version. Fired detached at REPL start; onNotice
|
|
86
|
+
* only fires when an upgrade is newly discovered this session, so a notice
|
|
87
|
+
* already rendered from cache is never printed twice.
|
|
88
|
+
*/
|
|
89
|
+
async function refresh(current, opts = {}) {
|
|
90
|
+
if (optOut()) return { available: false, latest: "", notice: null };
|
|
91
|
+
const store = opts.store || config;
|
|
92
|
+
const cfg = store.load();
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
if (cfg.updateCheckedAt && now - cfg.updateCheckedAt < CHECK_INTERVAL_MS) {
|
|
95
|
+
// Fresh cache decides without a network call.
|
|
96
|
+
if (cfg.updateLatest && isNewer(cfg.updateLatest, current)) {
|
|
97
|
+
const notice = noticeText(current, cfg.updateLatest);
|
|
98
|
+
if (opts.onNotice) opts.onNotice(notice);
|
|
99
|
+
return { available: true, latest: cfg.updateLatest, notice };
|
|
100
|
+
}
|
|
101
|
+
return { available: false, latest: cfg.updateLatest, notice: null };
|
|
102
|
+
}
|
|
103
|
+
const latest = await fetchLatest(opts.fetchImpl);
|
|
104
|
+
// Explicit fields win over the merge-preservation in config.save.
|
|
105
|
+
store.save({ ...cfg, updateCheckedAt: now, updateLatest: latest });
|
|
106
|
+
if (latest && isNewer(latest, current)) {
|
|
107
|
+
const notice = noticeText(current, latest);
|
|
108
|
+
if (opts.onNotice) opts.onNotice(notice);
|
|
109
|
+
return { available: true, latest, notice };
|
|
110
|
+
}
|
|
111
|
+
return { available: false, latest, notice: null };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
module.exports = { cachedNotice, refresh, noticeText, compareVersions, isNewer, fetchLatest, REGISTRY_URL, CHECK_INTERVAL_MS };
|