@tiny-fish/cli 0.41.2-next.326 → 0.41.2-next.327
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/lib/notice.js +14 -5
- package/package.json +1 -1
package/dist/lib/notice.js
CHANGED
|
@@ -3,7 +3,9 @@ import { detectHumanInitiated } from './harness.js';
|
|
|
3
3
|
import { err, sanitizeLine, warnLine } from './output.js';
|
|
4
4
|
const NOTICE_HEADER = 'x-tf-notice';
|
|
5
5
|
const LEVEL_HEADER = 'x-tf-notice-level';
|
|
6
|
+
const LATEST_HEADER = 'x-tf-notice-latest';
|
|
6
7
|
const MAX_LENGTH = 300;
|
|
8
|
+
const PLAIN_VERSION = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/;
|
|
7
9
|
const VALID_LEVELS = new Set(['required', 'recommended']);
|
|
8
10
|
let captured;
|
|
9
11
|
let printed = false;
|
|
@@ -24,26 +26,33 @@ export function captureNotice(headers) {
|
|
|
24
26
|
if (!message)
|
|
25
27
|
return;
|
|
26
28
|
const rawLevel = headers.get(LEVEL_HEADER)?.trim().toLowerCase();
|
|
29
|
+
const rawLatest = headers.get(LATEST_HEADER)?.trim() ?? '';
|
|
27
30
|
// Spread rather than `level: undefined`, which exactOptionalPropertyTypes rejects.
|
|
28
|
-
captured = {
|
|
31
|
+
captured = {
|
|
32
|
+
message,
|
|
33
|
+
...(rawLevel && VALID_LEVELS.has(rawLevel) ? { level: rawLevel } : {}),
|
|
34
|
+
...(PLAIN_VERSION.test(rawLatest) ? { latest: rawLatest } : {}),
|
|
35
|
+
};
|
|
29
36
|
}
|
|
30
37
|
/** Built here, not by the server, so nothing it sends can reach an agent's context as instructions. */
|
|
31
|
-
function agentMessage(level) {
|
|
38
|
+
function agentMessage({ level, latest }) {
|
|
39
|
+
// Latest is the registry version, not the required floor; only the soft level names it.
|
|
40
|
+
const target = latest ? ` (latest ${latest})` : '';
|
|
32
41
|
return level === 'required'
|
|
33
42
|
? `This TinyFish CLI (${CLI_VERSION}) is below the required minimum. Run: tinyfish upgrade`
|
|
34
|
-
: `A TinyFish CLI update is available (you have ${CLI_VERSION}). Run: tinyfish upgrade`;
|
|
43
|
+
: `A TinyFish CLI update is available${target} (you have ${CLI_VERSION}). Run: tinyfish upgrade`;
|
|
35
44
|
}
|
|
36
45
|
/** Advisory only, never changes stdout, the exit code, or control flow. */
|
|
37
46
|
export function emitNotice() {
|
|
38
47
|
if (printed || !captured)
|
|
39
48
|
return;
|
|
40
49
|
printed = true;
|
|
41
|
-
const { message,
|
|
50
|
+
const { message, ...rest } = captured;
|
|
42
51
|
if (detectHumanInitiated()) {
|
|
43
52
|
warnLine(message);
|
|
44
53
|
return;
|
|
45
54
|
}
|
|
46
|
-
err({ notice: agentMessage(
|
|
55
|
+
err({ notice: agentMessage(rest), ...rest });
|
|
47
56
|
}
|
|
48
57
|
/** For commands that are the fix themselves, such as `upgrade`, where the nudge is noise. */
|
|
49
58
|
export function suppressNotice() {
|