@flowapt/flowiq-cli 0.2.9 → 0.3.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/README.md CHANGED
@@ -645,6 +645,7 @@ version you have installed.
645
645
  |---|---|---|
646
646
  | `FLOWIQ_API_URL` | `https://api.flowiq.live` | Override the API host (local dev, staging). |
647
647
  | `FLOWIQ_TOKEN` | (saved in `~/.config/flowiq/auth.json`) | Override the auth token, useful for CI. |
648
+ | `FLOWIQ_NO_UPDATE_CHECK` | (unset) | Set to `1` to silence the "you're behind" update hint (also honours `NO_UPDATE_NOTIFIER=1` and any `CI` env). |
648
649
  | `FLOWMOD_EVO_DB_URL` | (none) | Full `postgres://` URL for `groups` (Evolution DB). Required for `groups`. |
649
650
  | `FLOWMOD_DB_HOST/PORT/USER/PASS/NAME` | (none) | Alternative to `FLOWMOD_EVO_DB_URL` — assembled into a connection string. |
650
651
 
@@ -660,6 +661,18 @@ flowiq --version
660
661
  Your saved token in `~/.config/flowiq/auth.json` is preserved across
661
662
  upgrades.
662
663
 
664
+ **You'll be told when you're behind.** The CLI checks npm about once a day (in a
665
+ detached background process — it never slows a command) and prints a one-line
666
+ hint to stderr on your next run when a newer version exists:
667
+
668
+ ```
669
+ ⬆ flowiq 0.3.1 is available (you're on 0.3.0)
670
+ update: npm i -g @flowapt/flowiq-cli
671
+ ```
672
+
673
+ It's stderr-only (never corrupts piped or `--json` output) and shows only in an
674
+ interactive terminal. Silence it with `FLOWIQ_NO_UPDATE_CHECK=1`.
675
+
663
676
  ## License
664
677
 
665
678
  UNLICENSED. Internal staff tool — install requires a valid `fiq_staff_…`
package/TEAM-GUIDE.md CHANGED
@@ -38,6 +38,12 @@ This guide travels with the CLI — read it any time with `flowiq guide`
38
38
  (`--reference` for the full command reference). It always matches the version
39
39
  you have installed.
40
40
 
41
+ **Keep it current.** The CLI checks npm about once a day and, on your next run,
42
+ prints a one-line hint when you're behind (e.g. `⬆ flowiq 0.3.1 is available…`).
43
+ When you see it, run `npm i -g @flowapt/flowiq-cli` — a stale version also means
44
+ `flowiq guide` shows you stale instructions. (Silence it with
45
+ `FLOWIQ_NO_UPDATE_CHECK=1` if you must.)
46
+
41
47
  > **Approving someone else's login:** when a teammate runs `auth login`, they
42
48
  > read you their code (or you open the link they send). On `/cli-auth`, check
43
49
  > the code AND the device name match what they told you, then Approve.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowapt/flowiq-cli",
3
- "version": "0.2.9",
3
+ "version": "0.3.0",
4
4
  "description": "Command-line tool for FlowIQ staff: round-trip agent prompts, questionnaires, fine-tuning, pin-board tasks, webhooks, templates, agent-updates, chat exports, and live agent testing without ever touching service-role credentials.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/config.js CHANGED
@@ -13,7 +13,7 @@ import os from "node:os";
13
13
 
14
14
  const DEFAULT_API_URL = "https://api.flowiq.live";
15
15
 
16
- function configDir() {
16
+ export function configDir() {
17
17
  // Honour XDG_CONFIG_HOME if set; else ~/.config (Linux/Mac default).
18
18
  const xdg = process.env.XDG_CONFIG_HOME;
19
19
  const base = xdg && xdg.trim() ? xdg : path.join(os.homedir(), ".config");
package/src/index.js CHANGED
@@ -29,6 +29,7 @@ import * as segmentsCmd from "./commands/segments.js";
29
29
  import * as tagCmd from "./commands/tag.js";
30
30
  import * as keywordsCmd from "./commands/keywords.js";
31
31
  import * as guideCmd from "./commands/guide.js";
32
+ import { maybeNotifyUpdate } from "./update-check.js";
32
33
 
33
34
  // Read version from package.json so it stays in sync with the published npm
34
35
  // version automatically (single source of truth — bumping package.json on each
@@ -37,6 +38,9 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
37
38
  const pkg = JSON.parse(readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
38
39
 
39
40
  export function run(argv) {
41
+ // Non-blocking "you're behind" hint (stderr; cached; detached refresh).
42
+ maybeNotifyUpdate(pkg.version);
43
+
40
44
  const program = new Command();
41
45
  program
42
46
  .name("flowiq")
@@ -0,0 +1,132 @@
1
+ // Best-effort "you're behind" nudge for the flowiq CLI.
2
+ //
3
+ // On startup we print a one-line update hint to STDERR (never stdout — so it
4
+ // can never corrupt piped / --json output) when the installed version is older
5
+ // than the latest published on npm.
6
+ //
7
+ // The nudge is driven by a CACHED value read SYNCHRONOUSLY — zero network on the
8
+ // hot path, so no command is ever slowed. The cache is refreshed at most once a
9
+ // day by a DETACHED, unref'd child process, so even `flowiq --version` returns
10
+ // instantly (the parent never waits on the registry). The hint therefore
11
+ // appears on the NEXT run after a new release — exactly how npm / update-notifier
12
+ // behave.
13
+ //
14
+ // Fully fail-silent: offline, registry down, malformed cache → no output, no
15
+ // crash, never blocks. Opt out with FLOWIQ_NO_UPDATE_CHECK=1 (also honours
16
+ // NO_UPDATE_NOTIFIER=1 and any CI env).
17
+
18
+ import fs from "node:fs";
19
+ import fsp from "node:fs/promises";
20
+ import path from "node:path";
21
+ import { spawn } from "node:child_process";
22
+ import { fileURLToPath } from "node:url";
23
+ import { configDir } from "./config.js";
24
+
25
+ const PKG = "@flowapt/flowiq-cli";
26
+ const REGISTRY = "https://registry.npmjs.org/@flowapt%2Fflowiq-cli/latest";
27
+ const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000; // refresh the cache at most once/day
28
+ const FETCH_TIMEOUT_MS = 2000;
29
+
30
+ function cacheFile() {
31
+ return path.join(configDir(), "update-check.json");
32
+ }
33
+
34
+ function disabled() {
35
+ return (
36
+ process.env.FLOWIQ_NO_UPDATE_CHECK === "1" ||
37
+ process.env.NO_UPDATE_NOTIFIER === "1" ||
38
+ !!process.env.CI
39
+ );
40
+ }
41
+
42
+ // Compare dotted numeric versions (ignoring any -prerelease). a>b → 1, a<b → -1, = → 0.
43
+ export function cmpVersion(a, b) {
44
+ const parse = (v) => String(v).split("-")[0].split(".").map((n) => parseInt(n, 10) || 0);
45
+ const pa = parse(a);
46
+ const pb = parse(b);
47
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
48
+ const d = (pa[i] || 0) - (pb[i] || 0);
49
+ if (d !== 0) return d > 0 ? 1 : -1;
50
+ }
51
+ return 0;
52
+ }
53
+
54
+ function readCacheSync() {
55
+ try {
56
+ return JSON.parse(fs.readFileSync(cacheFile(), "utf8"));
57
+ } catch {
58
+ return null;
59
+ }
60
+ }
61
+
62
+ async function writeCache(obj) {
63
+ try {
64
+ await fsp.mkdir(configDir(), { recursive: true, mode: 0o700 });
65
+ await fsp.writeFile(cacheFile(), JSON.stringify(obj) + "\n", "utf8");
66
+ } catch {
67
+ /* best-effort — a failed cache write just means we re-check next run */
68
+ }
69
+ }
70
+
71
+ // Hit the npm registry for dist-tags.latest and cache it. Runs ONLY in the
72
+ // detached child (never on the hot path). Backs off for the day even on failure
73
+ // so an offline machine doesn't spawn a refresher on every invocation.
74
+ async function refreshLatest(prevLatest) {
75
+ const ctrl = new AbortController();
76
+ const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS);
77
+ try {
78
+ const res = await fetch(REGISTRY, { signal: ctrl.signal, headers: { Accept: "application/json" } });
79
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
80
+ const body = await res.json();
81
+ await writeCache({ checked_at: Date.now(), latest: body?.version || prevLatest || null });
82
+ } catch {
83
+ await writeCache({ checked_at: Date.now(), latest: prevLatest || null });
84
+ } finally {
85
+ clearTimeout(timer);
86
+ }
87
+ }
88
+
89
+ // Print the nudge (from cache, synchronously) and, if the cache is stale, spawn
90
+ // a detached child to refresh it for the NEXT run. Never throws, never blocks.
91
+ export function maybeNotifyUpdate(currentVersion) {
92
+ try {
93
+ if (disabled()) return;
94
+ const cache = readCacheSync();
95
+ const latest = cache?.latest;
96
+
97
+ if (latest && process.stderr.isTTY && cmpVersion(latest, currentVersion) > 0) {
98
+ process.stderr.write(
99
+ `\n ⬆ flowiq ${latest} is available (you're on ${currentVersion})\n` +
100
+ ` update: npm i -g ${PKG}\n\n`
101
+ );
102
+ }
103
+
104
+ const stale = !cache || (Date.now() - (cache.checked_at || 0)) > CHECK_INTERVAL_MS;
105
+ if (stale) {
106
+ try {
107
+ const child = spawn(process.execPath, [fileURLToPath(import.meta.url), "--refresh"], {
108
+ detached: true,
109
+ stdio: "ignore",
110
+ windowsHide: true,
111
+ });
112
+ child.unref();
113
+ } catch {
114
+ /* if we can't spawn, we simply try again next run */
115
+ }
116
+ }
117
+ } catch {
118
+ /* fully silent — an update hint must never be the reason a command fails */
119
+ }
120
+ }
121
+
122
+ // When this module is executed directly as `node update-check.js --refresh`
123
+ // (the detached child spawned above), do the network refresh and exit. Guarded
124
+ // so importing the module for maybeNotifyUpdate never triggers it.
125
+ const invokedDirectly =
126
+ process.argv[1] &&
127
+ path.resolve(process.argv[1]) === fileURLToPath(import.meta.url) &&
128
+ process.argv.includes("--refresh");
129
+ if (invokedDirectly) {
130
+ const cache = readCacheSync();
131
+ refreshLatest(cache?.latest).finally(() => process.exit(0));
132
+ }