@ekanos/cli 0.29.0 → 0.31.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.
@@ -1,25 +1,40 @@
1
1
  import * as fs from 'node:fs';
2
2
  import * as path from 'node:path';
3
- import { CredentialStore, resolveEkanosHome } from './auth/credential-store.js';
3
+ import { CredentialStore, normalizeHost, resolveEkanosHome, } from './auth/credential-store.js';
4
4
  import { isPlaintextRemoteHost } from './auth/host-trust.js';
5
5
  import { cliVersion, compareVersions } from './compatibility.js';
6
6
  import { resolveToolchainTarget } from './toolchain-resolve.js';
7
7
  /**
8
- * The proactive, NEVER-mutating "your CLI is behind" notice. Runs on
9
- * `validate`, `dev`, `publish` and `status` — the verbs a partner (or an
10
- * agent acting for one) runs constantly — so staleness is discovered on the
11
- * next ordinary command instead of only when something breaks.
8
+ * The proactive, NEVER-mutating "your CLI is behind" notice.
9
+ *
10
+ * WHEN it runs: on every command except the few in
11
+ * `NO_TOOLCHAIN_CHECK_COMMANDS` (`index.ts`). `run()` starts it in the
12
+ * background alongside the command (`startUpdateCheck`) and announces after
13
+ * the command's own output (`finish`). `validate`, `dev`, `publish` and
14
+ * `status` also await it themselves (`checkForUpdate`) because they embed the
15
+ * notice under `toolchain` in their JSON `data`, and `publish` refuses an
16
+ * unsupported CLI; that await joins the run's background check, so one run
17
+ * makes one request and announces once.
18
+ *
19
+ * HOW OFTEN: the answer is cached for 4 hours in `~/.ekanos/update-check.json`
20
+ * (0600), so at most one network request per window. A "behind" notice is
21
+ * announced at most once per window too, unless the target is newer than the
22
+ * one last announced, which is said at once. The "unsupported" notice (below
23
+ * the host's minimum) repeats on every command: that state needs action, and
24
+ * `publish` refuses it anyway.
12
25
  *
13
26
  * The one rule that governs every line of this file: this check must be
14
27
  * INVISIBLE on failure. A partner offline, a flaky registry, a host that
15
28
  * predates this endpoint — none of that may add meaningful latency, change a
16
29
  * verb's exit code, or so much as touch the JSON envelope's `ok` field.
17
30
  * Every failure path below resolves to `null` ("say nothing"), never a throw.
31
+ * A background check still in flight when its command ends is let go
32
+ * (aborted) and asked again on the next command; nothing waits on it.
18
33
  */
19
34
  const CACHE_FILENAME = 'update-check.json';
20
35
  const CACHE_DIR_MODE = 0o700;
21
36
  const CACHE_FILE_MODE = 0o600;
22
- const TTL_MS = 24 * 60 * 60 * 1000;
37
+ export const UPDATE_CHECK_TTL_MS = 4 * 60 * 60 * 1000;
23
38
  /** The hard ceiling on this check's total network time, whatever else happens. */
24
39
  const DEADLINE_MS = 1500;
25
40
  function cachePath(env) {
@@ -67,25 +82,35 @@ function isCacheFile(value) {
67
82
  * throwing machinery in `auth/session.ts` — `resolveHost` is built to demand
68
83
  * an answer (a usage error naming the ambiguity) because a real command needs
69
84
  * one; this check needs an answer only if one is obvious, and silence
70
- * otherwise. Exactly one stored host is "obvious"; zero or several are not,
85
+ * otherwise. `EKANOS_HOST` (with a stored session) is "obvious", as is
86
+ * exactly one stored host, the rule `feedback-updates.ts` uses; zero or
87
+ * several stored hosts are not,
71
88
  * and this never prompts or guesses to resolve that ambiguity — it just
72
89
  * falls back to the npm registry, same as no session at all.
73
90
  */
74
91
  function bestEffortHostSession(env) {
92
+ var _a;
75
93
  try {
76
94
  const store = new CredentialStore({ home: resolveEkanosHome(env) });
95
+ const fromEnv = (_a = env.EKANOS_HOST) === null || _a === void 0 ? void 0 : _a.trim();
77
96
  const hosts = store.hosts();
78
- if (hosts.length !== 1 || isPlaintextRemoteHost(hosts[0]))
97
+ const host = fromEnv
98
+ ? normalizeHost(fromEnv)
99
+ : hosts.length === 1
100
+ ? hosts[0]
101
+ : null;
102
+ if (!host || isPlaintextRemoteHost(host))
79
103
  return null;
80
- const session = store.read(hosts[0]);
81
- return session ? { host: hosts[0], session } : null;
104
+ const session = store.read(host);
105
+ return session ? { host, session } : null;
82
106
  }
83
- catch (_a) {
107
+ catch (_b) {
84
108
  return null;
85
109
  }
86
110
  }
87
111
  function withDeadline(promise, ms) {
88
112
  return new Promise((resolve) => {
113
+ var _a;
89
114
  let settled = false;
90
115
  const timer = setTimeout(() => {
91
116
  if (!settled) {
@@ -93,6 +118,8 @@ function withDeadline(promise, ms) {
93
118
  resolve(null);
94
119
  }
95
120
  }, ms);
121
+ // Never the reason the process stays up after its command has ended.
122
+ (_a = timer.unref) === null || _a === void 0 ? void 0 : _a.call(timer);
96
123
  // A rejection is a failure like any other here — resolve to null rather
97
124
  // than letting it become an unhandled rejection.
98
125
  promise.then((value) => {
@@ -110,19 +137,40 @@ function withDeadline(promise, ms) {
110
137
  });
111
138
  });
112
139
  }
140
+ let current = null;
113
141
  /**
114
- * Resolve whether this CLI is behind, respecting the 24h cache and the hard
142
+ * Resolve whether this CLI is behind, respecting the 4h cache and the hard
115
143
  * `EKANOS_NO_UPDATE_CHECK` opt-out. Returns null whenever there is nothing to
116
- * say — current, unresolvable, or any failure along the way.
144
+ * say — current, unresolvable, or any failure along the way. Inside a run
145
+ * that already started the background check, it joins that check rather
146
+ * than asking again, unless the caller names a different host.
117
147
  */
118
148
  export async function checkForUpdate(params) {
119
149
  if (params.env.EKANOS_NO_UPDATE_CHECK)
120
150
  return null;
151
+ const run = current;
152
+ if (run &&
153
+ run.env === params.env &&
154
+ (!params.host || !params.session || params.host === run.host)) {
155
+ return run.promise;
156
+ }
157
+ return resolveNotice(params);
158
+ }
159
+ async function resolveNotice(params) {
160
+ try {
161
+ return await resolveNoticeUnsafe(params);
162
+ }
163
+ catch (_a) {
164
+ return null;
165
+ }
166
+ }
167
+ async function resolveNoticeUnsafe(params) {
168
+ var _a;
121
169
  const cached = readCache(params.env);
122
170
  const now = Date.now();
123
171
  let target;
124
172
  let minimum;
125
- if (cached && now - cached.checkedAt < TTL_MS) {
173
+ if (cached && now - cached.checkedAt < UPDATE_CHECK_TTL_MS) {
126
174
  target = cached.target;
127
175
  minimum = cached.minimum;
128
176
  }
@@ -134,48 +182,130 @@ export async function checkForUpdate(params) {
134
182
  host: auth === null || auth === void 0 ? void 0 : auth.host,
135
183
  session: auth === null || auth === void 0 ? void 0 : auth.session,
136
184
  timeoutMs: DEADLINE_MS,
185
+ signal: params.signal,
186
+ untraced: true,
137
187
  }), DEADLINE_MS);
138
188
  if (!resolution || resolution.status !== 'ok')
139
189
  return null;
190
+ if ((_a = params.signal) === null || _a === void 0 ? void 0 : _a.aborted)
191
+ return null;
140
192
  target = resolution.target;
141
193
  minimum = resolution.source === 'host' ? resolution.minimum : undefined;
142
- writeCache(params.env, {
143
- checkedAt: now,
144
- target,
145
- minimum,
146
- source: resolution.source,
147
- });
194
+ writeCache(params.env, Object.assign({ checkedAt: now, target,
195
+ minimum, source: resolution.source }, ((cached === null || cached === void 0 ? void 0 : cached.announced) ? { announced: cached.announced } : {})));
148
196
  }
149
- const current = cliVersion();
150
- if (compareVersions(current, target.cli) >= 0)
197
+ const installed = cliVersion();
198
+ if (compareVersions(installed, target.cli) >= 0)
151
199
  return null;
152
- const status = minimum && compareVersions(current, minimum.cli) < 0
200
+ const status = minimum && compareVersions(installed, minimum.cli) < 0
153
201
  ? 'unsupported'
154
202
  : 'behind';
155
203
  return {
156
204
  status,
157
- current: { cli: current },
205
+ current: { cli: installed },
158
206
  target,
159
207
  upgradeCommand: 'ekanos upgrade',
160
208
  };
161
209
  }
162
210
  /**
163
- * Surface a notice, if any. Human mode gets one stderr line; every mode gets
164
- * the `claude-code-hint` stderr line so an agent parsing stderr for that
165
- * marker sees it regardless of `--json`. NEVER writes to stdout — the JSON
166
- * envelope's caller is responsible for embedding `notice` under a `toolchain`
167
- * key in its own `data`, per the envelope docs in `context.ts`.
211
+ * Start the run's background check. `run()` calls it as a command starts and
212
+ * `finish` once the command has written its output; nothing awaits it in
213
+ * between, so it never delays a command. Returns null when switched off.
214
+ */
215
+ export function startUpdateCheck(params) {
216
+ const { env } = params;
217
+ if (env.EKANOS_NO_UPDATE_CHECK)
218
+ return null;
219
+ const controller = new AbortController();
220
+ const auth = bestEffortHostSession(env);
221
+ const run = {
222
+ env,
223
+ host: auth === null || auth === void 0 ? void 0 : auth.host,
224
+ controller,
225
+ promise: Promise.resolve(null),
226
+ result: null,
227
+ announced: false,
228
+ };
229
+ run.promise = resolveNotice({
230
+ env,
231
+ host: auth === null || auth === void 0 ? void 0 : auth.host,
232
+ session: auth === null || auth === void 0 ? void 0 : auth.session,
233
+ signal: controller.signal,
234
+ }).then((notice) => {
235
+ run.result = { notice };
236
+ return notice;
237
+ });
238
+ current = run;
239
+ return {
240
+ settled: run.promise.then(() => undefined),
241
+ finish(ctx) {
242
+ if (current === run)
243
+ current = null;
244
+ controller.abort();
245
+ if (!run.result || run.announced)
246
+ return;
247
+ announceUpdate(ctx, run.result.notice, { env });
248
+ },
249
+ };
250
+ }
251
+ /** Whether a notice is due, against what this machine last announced. */
252
+ function isDue(notice, cached) {
253
+ if (notice.status === 'unsupported')
254
+ return true;
255
+ const last = cached === null || cached === void 0 ? void 0 : cached.announced;
256
+ if (!last)
257
+ return true;
258
+ if (compareVersions(notice.target.cli, last.cli) > 0)
259
+ return true;
260
+ return Date.now() - last.at >= UPDATE_CHECK_TTL_MS;
261
+ }
262
+ /**
263
+ * Surface a notice, if one is due. Human mode gets one stderr line; with
264
+ * `--json` or a detected agent, the `claude-code-hint` stderr line carries
265
+ * the notice instead, so an agent sees it without parsing prose. NEVER
266
+ * writes to stdout — the JSON envelope's caller embeds `notice` under a
267
+ * `toolchain` key in its own `data`, per the envelope docs in `context.ts`.
268
+ *
269
+ * Remembers in the cache when a "behind" notice was shown, so it is said at
270
+ * most once per window — and only when something was really written: in CI
271
+ * (no TTY, no agent) nothing is, and nothing is used up.
168
272
  */
169
- export function announceUpdate(ctx, notice) {
273
+ export function announceUpdate(ctx, notice, options = {}) {
274
+ var _a;
170
275
  if (!notice)
171
276
  return;
277
+ const env = (_a = options.env) !== null && _a !== void 0 ? _a : ctx.env;
278
+ const run = current && current.env === env ? current : null;
279
+ if (run === null || run === void 0 ? void 0 : run.announced)
280
+ return;
281
+ const cached = readCache(env);
282
+ if (!isDue(notice, cached))
283
+ return;
284
+ let wrote = false;
172
285
  if (!ctx.jsonMode) {
173
286
  ctx.warn(notice.status === 'unsupported'
174
287
  ? `ekanos: @ekanos/cli ${notice.current.cli} is below the version ` +
175
288
  `this host requires (${notice.target.cli}). Run "ekanos upgrade".`
176
289
  : `ekanos: a newer @ekanos/cli is available (${notice.current.cli} ` +
177
290
  `→ ${notice.target.cli}). Run "ekanos upgrade".`);
291
+ wrote = true;
292
+ }
293
+ if (ctx.emitClaudeCodeHint({ tool: 'ekanos', toolchain: notice })) {
294
+ wrote = true;
295
+ }
296
+ if (!wrote)
297
+ return;
298
+ if (run)
299
+ run.announced = true;
300
+ if (notice.status === 'behind') {
301
+ // With no cache to add to (its write failed), checkedAt 0 keeps the
302
+ // next run asking the network rather than trusting this target.
303
+ const base = cached !== null && cached !== void 0 ? cached : {
304
+ checkedAt: 0,
305
+ target: notice.target,
306
+ source: 'npm',
307
+ };
308
+ writeCache(env, Object.assign(Object.assign({}, base), { announced: { at: Date.now(), cli: notice.target.cli } }));
178
309
  }
179
- ctx.emitClaudeCodeHint({ tool: 'ekanos', toolchain: notice });
180
310
  }
181
311
  //# sourceMappingURL=update-notice.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"update-notice.js","sourceRoot":"","sources":["../src/update-notice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAG9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;;;;;;;;;;GAWG;AAEH,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAC3C,MAAM,cAAc,GAAG,KAA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UAAU,cAAc,CAC5B,GAAe,EACf,MAAkC;IAElC,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QAClB,GAAG,CAAC,IAAI,CACN,MAAM,CAAC,MAAM,KAAK,aAAa;YAC7B,CAAC,CAAC,uBAAuB,MAAM,CAAC,OAAO,CAAC,GAAG,wBAAwB;gBAC/D,uBAAuB,MAAM,CAAC,MAAM,CAAC,GAAG,0BAA0B;YACtE,CAAC,CAAC,6CAA6C,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG;gBAChE,KAAK,MAAM,CAAC,MAAM,CAAC,GAAG,0BAA0B,CACvD,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { CredentialStore, resolveEkanosHome } from './auth/credential-store';\nimport { isPlaintextRemoteHost } from './auth/host-trust';\nimport { cliVersion, compareVersions } from './compatibility';\nimport type { CliContext } from './context';\nimport type { ToolchainVersions } from './toolchain';\nimport { resolveToolchainTarget } from './toolchain-resolve';\n\n/**\n * The proactive, NEVER-mutating \"your CLI is behind\" notice. Runs on\n * `validate`, `dev`, `publish` and `status` — the verbs a partner (or an\n * agent acting for one) runs constantly — so staleness is discovered on the\n * next ordinary command instead of only when something breaks.\n *\n * The one rule that governs every line of this file: this check must be\n * INVISIBLE on failure. A partner offline, a flaky registry, a host that\n * predates this endpoint — none of that may add meaningful latency, change a\n * verb's exit code, or so much as touch the JSON envelope's `ok` field.\n * Every failure path below resolves to `null` (\"say nothing\"), never a throw.\n */\n\nconst CACHE_FILENAME = 'update-check.json';\nconst CACHE_DIR_MODE = 0o700;\nconst CACHE_FILE_MODE = 0o600;\nconst TTL_MS = 24 * 60 * 60 * 1000;\n/** The hard ceiling on this check's total network time, whatever else happens. */\nconst DEADLINE_MS = 1500;\n\nexport interface ToolchainNoticeData {\n status: 'behind' | 'unsupported';\n current: { cli: string };\n target: ToolchainVersions;\n upgradeCommand: 'ekanos upgrade';\n}\n\ninterface CacheFile {\n checkedAt: number;\n target: ToolchainVersions;\n minimum?: ToolchainVersions;\n source: 'host' | 'npm';\n}\n\nfunction cachePath(env: Record<string, string | undefined>): string {\n return path.join(resolveEkanosHome(env), '.ekanos', CACHE_FILENAME);\n}\n\nfunction readCache(env: Record<string, string | undefined>): CacheFile | null {\n try {\n const raw = fs.readFileSync(cachePath(env), 'utf8');\n const parsed: unknown = JSON.parse(raw);\n return isCacheFile(parsed) ? parsed : null;\n } catch {\n // Missing, unreadable, or corrupt — all read as \"no cache\", never an\n // error. This check is a courtesy, not a source of truth.\n return null;\n }\n}\n\nfunction writeCache(\n env: Record<string, string | undefined>,\n file: CacheFile,\n): void {\n const target = cachePath(env);\n try {\n fs.mkdirSync(path.dirname(target), {\n recursive: true,\n mode: CACHE_DIR_MODE,\n });\n const tmp = `${target}.${process.pid}.tmp`;\n fs.writeFileSync(tmp, JSON.stringify(file), { mode: CACHE_FILE_MODE });\n fs.renameSync(tmp, target);\n } catch {\n // Best-effort. The next run simply re-checks — this is a cache, not a\n // durable record.\n }\n}\n\nfunction isCacheFile(value: unknown): value is CacheFile {\n if (typeof value !== 'object' || value === null) return false;\n const candidate = value as Partial<CacheFile>;\n return (\n typeof candidate.checkedAt === 'number' &&\n typeof candidate.target === 'object' &&\n candidate.target !== null &&\n (candidate.source === 'host' || candidate.source === 'npm')\n );\n}\n\n/**\n * The one host/session this check will ever try, resolved WITHOUT any of the\n * throwing machinery in `auth/session.ts` — `resolveHost` is built to demand\n * an answer (a usage error naming the ambiguity) because a real command needs\n * one; this check needs an answer only if one is obvious, and silence\n * otherwise. Exactly one stored host is \"obvious\"; zero or several are not,\n * and this never prompts or guesses to resolve that ambiguity — it just\n * falls back to the npm registry, same as no session at all.\n */\nfunction bestEffortHostSession(\n env: Record<string, string | undefined>,\n): { host: string; session: { accessToken: string } } | null {\n try {\n const store = new CredentialStore({ home: resolveEkanosHome(env) });\n const hosts = store.hosts();\n if (hosts.length !== 1 || isPlaintextRemoteHost(hosts[0]!)) return null;\n const session = store.read(hosts[0]!);\n return session ? { host: hosts[0]!, session } : null;\n } catch {\n return null;\n }\n}\n\nfunction withDeadline<T>(promise: Promise<T>, ms: number): Promise<T | null> {\n return new Promise((resolve) => {\n let settled = false;\n const timer = setTimeout(() => {\n if (!settled) {\n settled = true;\n resolve(null);\n }\n }, ms);\n // A rejection is a failure like any other here — resolve to null rather\n // than letting it become an unhandled rejection.\n promise.then(\n (value) => {\n if (!settled) {\n settled = true;\n clearTimeout(timer);\n resolve(value);\n }\n },\n () => {\n if (!settled) {\n settled = true;\n clearTimeout(timer);\n resolve(null);\n }\n },\n );\n });\n}\n\nexport interface CheckForUpdateParams {\n env: Record<string, string | undefined>;\n /** An already-resolved Ekanos host/session, when the caller has one handy. */\n host?: string;\n session?: { accessToken: string } | null;\n}\n\n/**\n * Resolve whether this CLI is behind, respecting the 24h cache and the hard\n * `EKANOS_NO_UPDATE_CHECK` opt-out. Returns null whenever there is nothing to\n * say — current, unresolvable, or any failure along the way.\n */\nexport async function checkForUpdate(\n params: CheckForUpdateParams,\n): Promise<ToolchainNoticeData | null> {\n if (params.env.EKANOS_NO_UPDATE_CHECK) return null;\n\n const cached = readCache(params.env);\n const now = Date.now();\n\n let target: ToolchainVersions;\n let minimum: ToolchainVersions | undefined;\n\n if (cached && now - cached.checkedAt < TTL_MS) {\n target = cached.target;\n minimum = cached.minimum;\n } else {\n const auth =\n params.host && params.session\n ? { host: params.host, session: params.session }\n : bestEffortHostSession(params.env);\n\n const resolution = await withDeadline(\n resolveToolchainTarget({\n host: auth?.host,\n session: auth?.session,\n timeoutMs: DEADLINE_MS,\n }),\n DEADLINE_MS,\n );\n\n if (!resolution || resolution.status !== 'ok') return null;\n\n target = resolution.target;\n minimum = resolution.source === 'host' ? resolution.minimum : undefined;\n\n writeCache(params.env, {\n checkedAt: now,\n target,\n minimum,\n source: resolution.source,\n });\n }\n\n const current = cliVersion();\n if (compareVersions(current, target.cli) >= 0) return null;\n\n const status =\n minimum && compareVersions(current, minimum.cli) < 0\n ? 'unsupported'\n : 'behind';\n\n return {\n status,\n current: { cli: current },\n target,\n upgradeCommand: 'ekanos upgrade',\n };\n}\n\n/**\n * Surface a notice, if any. Human mode gets one stderr line; every mode gets\n * the `claude-code-hint` stderr line so an agent parsing stderr for that\n * marker sees it regardless of `--json`. NEVER writes to stdout — the JSON\n * envelope's caller is responsible for embedding `notice` under a `toolchain`\n * key in its own `data`, per the envelope docs in `context.ts`.\n */\nexport function announceUpdate(\n ctx: CliContext,\n notice: ToolchainNoticeData | null,\n): void {\n if (!notice) return;\n\n if (!ctx.jsonMode) {\n ctx.warn(\n notice.status === 'unsupported'\n ? `ekanos: @ekanos/cli ${notice.current.cli} is below the version ` +\n `this host requires (${notice.target.cli}). Run \"ekanos upgrade\".`\n : `ekanos: a newer @ekanos/cli is available (${notice.current.cli} ` +\n `→ ${notice.target.cli}). Run \"ekanos upgrade\".`,\n );\n }\n\n ctx.emitClaudeCodeHint({ tool: 'ekanos', toolchain: notice });\n}\n"]}
1
+ {"version":3,"file":"update-notice.js","sourceRoot":"","sources":["../src/update-notice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EACL,eAAe,EACf,aAAa,EACb,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAG9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,MAAM,cAAc,GA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M,CAAC,GAAG,0BAA0B;YACtE,CAAC,CAAC,6CAA6C,MAAM,CAAC,OAAO,CAAC,GAAG,GAAG;gBAChE,KAAK,MAAM,CAAC,MAAM,CAAC,GAAG,0BAA0B,CACvD,CAAC;QACF,KAAK,GAAG,IAAI,CAAC;IACf,CAAC;IACD,IAAI,GAAG,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;QAClE,KAAK,GAAG,IAAI,CAAC;IACf,CAAC;IACD,IAAI,CAAC,KAAK;QAAE,OAAO;IAEnB,IAAI,GAAG;QAAE,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;IAC9B,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,oEAAoE;QACpE,gEAAgE;QAChE,MAAM,IAAI,GAAc,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI;YAChC,SAAS,EAAE,CAAC;YACZ,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,KAAK;SACd,CAAC;QACF,UAAU,CAAC,GAAG,kCACT,IAAI,KACP,SAAS,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,IACrD,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport {\n CredentialStore,\n normalizeHost,\n resolveEkanosHome,\n} from './auth/credential-store';\nimport { isPlaintextRemoteHost } from './auth/host-trust';\nimport { cliVersion, compareVersions } from './compatibility';\nimport type { CliContext } from './context';\nimport type { ToolchainVersions } from './toolchain';\nimport { resolveToolchainTarget } from './toolchain-resolve';\n\n/**\n * The proactive, NEVER-mutating \"your CLI is behind\" notice.\n *\n * WHEN it runs: on every command except the few in\n * `NO_TOOLCHAIN_CHECK_COMMANDS` (`index.ts`). `run()` starts it in the\n * background alongside the command (`startUpdateCheck`) and announces after\n * the command's own output (`finish`). `validate`, `dev`, `publish` and\n * `status` also await it themselves (`checkForUpdate`) because they embed the\n * notice under `toolchain` in their JSON `data`, and `publish` refuses an\n * unsupported CLI; that await joins the run's background check, so one run\n * makes one request and announces once.\n *\n * HOW OFTEN: the answer is cached for 4 hours in `~/.ekanos/update-check.json`\n * (0600), so at most one network request per window. A \"behind\" notice is\n * announced at most once per window too, unless the target is newer than the\n * one last announced, which is said at once. The \"unsupported\" notice (below\n * the host's minimum) repeats on every command: that state needs action, and\n * `publish` refuses it anyway.\n *\n * The one rule that governs every line of this file: this check must be\n * INVISIBLE on failure. A partner offline, a flaky registry, a host that\n * predates this endpoint — none of that may add meaningful latency, change a\n * verb's exit code, or so much as touch the JSON envelope's `ok` field.\n * Every failure path below resolves to `null` (\"say nothing\"), never a throw.\n * A background check still in flight when its command ends is let go\n * (aborted) and asked again on the next command; nothing waits on it.\n */\n\nconst CACHE_FILENAME = 'update-check.json';\nconst CACHE_DIR_MODE = 0o700;\nconst CACHE_FILE_MODE = 0o600;\nexport const UPDATE_CHECK_TTL_MS = 4 * 60 * 60 * 1000;\n/** The hard ceiling on this check's total network time, whatever else happens. */\nconst DEADLINE_MS = 1500;\n\nexport interface ToolchainNoticeData {\n status: 'behind' | 'unsupported';\n current: { cli: string };\n target: ToolchainVersions;\n upgradeCommand: 'ekanos upgrade';\n}\n\ninterface CacheFile {\n checkedAt: number;\n target: ToolchainVersions;\n minimum?: ToolchainVersions;\n source: 'host' | 'npm';\n /** When a \"behind\" notice was last shown on this machine, and for which version. */\n announced?: { at: number; cli: string };\n}\n\nfunction cachePath(env: Record<string, string | undefined>): string {\n return path.join(resolveEkanosHome(env), '.ekanos', CACHE_FILENAME);\n}\n\nfunction readCache(env: Record<string, string | undefined>): CacheFile | null {\n try {\n const raw = fs.readFileSync(cachePath(env), 'utf8');\n const parsed: unknown = JSON.parse(raw);\n return isCacheFile(parsed) ? parsed : null;\n } catch {\n // Missing, unreadable, or corrupt — all read as \"no cache\", never an\n // error. This check is a courtesy, not a source of truth.\n return null;\n }\n}\n\nfunction writeCache(\n env: Record<string, string | undefined>,\n file: CacheFile,\n): void {\n const target = cachePath(env);\n try {\n fs.mkdirSync(path.dirname(target), {\n recursive: true,\n mode: CACHE_DIR_MODE,\n });\n const tmp = `${target}.${process.pid}.tmp`;\n fs.writeFileSync(tmp, JSON.stringify(file), { mode: CACHE_FILE_MODE });\n fs.renameSync(tmp, target);\n } catch {\n // Best-effort. The next run simply re-checks — this is a cache, not a\n // durable record.\n }\n}\n\nfunction isCacheFile(value: unknown): value is CacheFile {\n if (typeof value !== 'object' || value === null) return false;\n const candidate = value as Partial<CacheFile>;\n return (\n typeof candidate.checkedAt === 'number' &&\n typeof candidate.target === 'object' &&\n candidate.target !== null &&\n (candidate.source === 'host' || candidate.source === 'npm')\n );\n}\n\n/**\n * The one host/session this check will ever try, resolved WITHOUT any of the\n * throwing machinery in `auth/session.ts` — `resolveHost` is built to demand\n * an answer (a usage error naming the ambiguity) because a real command needs\n * one; this check needs an answer only if one is obvious, and silence\n * otherwise. `EKANOS_HOST` (with a stored session) is \"obvious\", as is\n * exactly one stored host, the rule `feedback-updates.ts` uses; zero or\n * several stored hosts are not,\n * and this never prompts or guesses to resolve that ambiguity — it just\n * falls back to the npm registry, same as no session at all.\n */\nfunction bestEffortHostSession(\n env: Record<string, string | undefined>,\n): { host: string; session: { accessToken: string } } | null {\n try {\n const store = new CredentialStore({ home: resolveEkanosHome(env) });\n const fromEnv = env.EKANOS_HOST?.trim();\n const hosts = store.hosts();\n const host = fromEnv\n ? normalizeHost(fromEnv)\n : hosts.length === 1\n ? hosts[0]!\n : null;\n if (!host || isPlaintextRemoteHost(host)) return null;\n const session = store.read(host);\n return session ? { host, session } : null;\n } catch {\n return null;\n }\n}\n\nfunction withDeadline<T>(promise: Promise<T>, ms: number): Promise<T | null> {\n return new Promise((resolve) => {\n let settled = false;\n const timer = setTimeout(() => {\n if (!settled) {\n settled = true;\n resolve(null);\n }\n }, ms);\n // Never the reason the process stays up after its command has ended.\n timer.unref?.();\n // A rejection is a failure like any other here — resolve to null rather\n // than letting it become an unhandled rejection.\n promise.then(\n (value) => {\n if (!settled) {\n settled = true;\n clearTimeout(timer);\n resolve(value);\n }\n },\n () => {\n if (!settled) {\n settled = true;\n clearTimeout(timer);\n resolve(null);\n }\n },\n );\n });\n}\n\nexport interface CheckForUpdateParams {\n env: Record<string, string | undefined>;\n /** An already-resolved Ekanos host/session, when the caller has one handy. */\n host?: string;\n session?: { accessToken: string } | null;\n}\n\n/** The run's background check, while `run()` holds one (`startUpdateCheck`). */\ninterface RunCheck {\n env: Record<string, string | undefined>;\n host: string | undefined;\n controller: AbortController;\n promise: Promise<ToolchainNoticeData | null>;\n /** Set once the promise settles, so `finish` can read it without waiting. */\n result: { notice: ToolchainNoticeData | null } | null;\n /** This run already said it (a verb announced before its own output). */\n announced: boolean;\n}\n\nlet current: RunCheck | null = null;\n\n/**\n * Resolve whether this CLI is behind, respecting the 4h cache and the hard\n * `EKANOS_NO_UPDATE_CHECK` opt-out. Returns null whenever there is nothing to\n * say — current, unresolvable, or any failure along the way. Inside a run\n * that already started the background check, it joins that check rather\n * than asking again, unless the caller names a different host.\n */\nexport async function checkForUpdate(\n params: CheckForUpdateParams,\n): Promise<ToolchainNoticeData | null> {\n if (params.env.EKANOS_NO_UPDATE_CHECK) return null;\n const run = current;\n if (\n run &&\n run.env === params.env &&\n (!params.host || !params.session || params.host === run.host)\n ) {\n return run.promise;\n }\n return resolveNotice(params);\n}\n\nasync function resolveNotice(\n params: CheckForUpdateParams & { signal?: AbortSignal },\n): Promise<ToolchainNoticeData | null> {\n try {\n return await resolveNoticeUnsafe(params);\n } catch {\n return null;\n }\n}\n\nasync function resolveNoticeUnsafe(\n params: CheckForUpdateParams & { signal?: AbortSignal },\n): Promise<ToolchainNoticeData | null> {\n const cached = readCache(params.env);\n const now = Date.now();\n\n let target: ToolchainVersions;\n let minimum: ToolchainVersions | undefined;\n\n if (cached && now - cached.checkedAt < UPDATE_CHECK_TTL_MS) {\n target = cached.target;\n minimum = cached.minimum;\n } else {\n const auth =\n params.host && params.session\n ? { host: params.host, session: params.session }\n : bestEffortHostSession(params.env);\n\n const resolution = await withDeadline(\n resolveToolchainTarget({\n host: auth?.host,\n session: auth?.session,\n timeoutMs: DEADLINE_MS,\n signal: params.signal,\n untraced: true,\n }),\n DEADLINE_MS,\n );\n\n if (!resolution || resolution.status !== 'ok') return null;\n if (params.signal?.aborted) return null;\n\n target = resolution.target;\n minimum = resolution.source === 'host' ? resolution.minimum : undefined;\n\n writeCache(params.env, {\n checkedAt: now,\n target,\n minimum,\n source: resolution.source,\n ...(cached?.announced ? { announced: cached.announced } : {}),\n });\n }\n\n const installed = cliVersion();\n if (compareVersions(installed, target.cli) >= 0) return null;\n\n const status =\n minimum && compareVersions(installed, minimum.cli) < 0\n ? 'unsupported'\n : 'behind';\n\n return {\n status,\n current: { cli: installed },\n target,\n upgradeCommand: 'ekanos upgrade',\n };\n}\n\nexport interface UpdateCheck {\n /** Announce what is ready, if it is due, and let go of anything in flight. */\n finish(ctx: CliContext): void;\n /** Settles when the background work does (tests). */\n readonly settled: Promise<void>;\n}\n\n/**\n * Start the run's background check. `run()` calls it as a command starts and\n * `finish` once the command has written its output; nothing awaits it in\n * between, so it never delays a command. Returns null when switched off.\n */\nexport function startUpdateCheck(params: {\n env: Record<string, string | undefined>;\n}): UpdateCheck | null {\n const { env } = params;\n if (env.EKANOS_NO_UPDATE_CHECK) return null;\n\n const controller = new AbortController();\n const auth = bestEffortHostSession(env);\n const run: RunCheck = {\n env,\n host: auth?.host,\n controller,\n promise: Promise.resolve(null),\n result: null,\n announced: false,\n };\n run.promise = resolveNotice({\n env,\n host: auth?.host,\n session: auth?.session,\n signal: controller.signal,\n }).then((notice) => {\n run.result = { notice };\n return notice;\n });\n current = run;\n\n return {\n settled: run.promise.then(() => undefined),\n finish(ctx) {\n if (current === run) current = null;\n controller.abort();\n if (!run.result || run.announced) return;\n announceUpdate(ctx, run.result.notice, { env });\n },\n };\n}\n\n/** Whether a notice is due, against what this machine last announced. */\nfunction isDue(notice: ToolchainNoticeData, cached: CacheFile | null): boolean {\n if (notice.status === 'unsupported') return true;\n const last = cached?.announced;\n if (!last) return true;\n if (compareVersions(notice.target.cli, last.cli) > 0) return true;\n return Date.now() - last.at >= UPDATE_CHECK_TTL_MS;\n}\n\n/**\n * Surface a notice, if one is due. Human mode gets one stderr line; with\n * `--json` or a detected agent, the `claude-code-hint` stderr line carries\n * the notice instead, so an agent sees it without parsing prose. NEVER\n * writes to stdout — the JSON envelope's caller embeds `notice` under a\n * `toolchain` key in its own `data`, per the envelope docs in `context.ts`.\n *\n * Remembers in the cache when a \"behind\" notice was shown, so it is said at\n * most once per window — and only when something was really written: in CI\n * (no TTY, no agent) nothing is, and nothing is used up.\n */\nexport function announceUpdate(\n ctx: CliContext,\n notice: ToolchainNoticeData | null,\n options: { env?: Record<string, string | undefined> } = {},\n): void {\n if (!notice) return;\n const env = options.env ?? ctx.env;\n const run = current && current.env === env ? current : null;\n if (run?.announced) return;\n\n const cached = readCache(env);\n if (!isDue(notice, cached)) return;\n\n let wrote = false;\n if (!ctx.jsonMode) {\n ctx.warn(\n notice.status === 'unsupported'\n ? `ekanos: @ekanos/cli ${notice.current.cli} is below the version ` +\n `this host requires (${notice.target.cli}). Run \"ekanos upgrade\".`\n : `ekanos: a newer @ekanos/cli is available (${notice.current.cli} ` +\n `→ ${notice.target.cli}). Run \"ekanos upgrade\".`,\n );\n wrote = true;\n }\n if (ctx.emitClaudeCodeHint({ tool: 'ekanos', toolchain: notice })) {\n wrote = true;\n }\n if (!wrote) return;\n\n if (run) run.announced = true;\n if (notice.status === 'behind') {\n // With no cache to add to (its write failed), checkedAt 0 keeps the\n // next run asking the network rather than trusting this target.\n const base: CacheFile = cached ?? {\n checkedAt: 0,\n target: notice.target,\n source: 'npm',\n };\n writeCache(env, {\n ...base,\n announced: { at: Date.now(), cli: notice.target.cli },\n });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekanos/cli",
3
- "version": "0.29.0",
3
+ "version": "0.31.0",
4
4
  "private": false,
5
5
  "description": "The Ekanos partner toolchain CLI: scaffold, validate, and test an Ekanos integration against the published @ekanos packages. Agent-native — every verb speaks JSON with a stable exit-code taxonomy.",
6
6
  "keywords": [
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@clack/prompts": "1.9.0",
38
- "@ekanos/integration-schema": "0.34.0",
38
+ "@ekanos/integration-schema": "0.35.0",
39
39
  "esbuild": "0.28.2",
40
40
  "picocolors": "1.1.1"
41
41
  },
@@ -22,16 +22,16 @@
22
22
  "build": "npx ekanos build"
23
23
  },
24
24
  "dependencies": {
25
- "@ekanos/sdk": "^0.34.0",
26
- "@ekanos/ui": "^0.34.0",
25
+ "@ekanos/sdk": "^0.35.0",
26
+ "@ekanos/ui": "^0.35.0",
27
27
  "@tanstack/react-query": "^5.101.4",
28
28
  "react": "^19.2.8",
29
29
  "react-dom": "^19.2.8",
30
30
  "zod": "^4.6.7"
31
31
  },
32
32
  "devDependencies": {
33
- "@ekanos/cli": "^0.29.0",
34
- "@ekanos/harness": "^0.34.0",
33
+ "@ekanos/cli": "^0.31.0",
34
+ "@ekanos/harness": "^0.35.0",
35
35
  "@tailwindcss/postcss": "^4.3.3",
36
36
  "@typescript-eslint/parser": "^8.46.2",
37
37
  "@types/react": "^19.2.0",
@@ -12,12 +12,12 @@
12
12
  "prepare": "node scripts/setup-hooks.mjs"
13
13
  },
14
14
  "dependencies": {
15
- "@ekanos/sdk": "^0.34.0",
16
- "@ekanos/ui": "^0.34.0"
15
+ "@ekanos/sdk": "^0.35.0",
16
+ "@ekanos/ui": "^0.35.0"
17
17
  },
18
18
  "devDependencies": {
19
- "@ekanos/cli": "^0.29.0",
20
- "@ekanos/harness": "^0.34.0",
19
+ "@ekanos/cli": "^0.31.0",
20
+ "@ekanos/harness": "^0.35.0",
21
21
  "@hookform/resolvers": "^5.2.2",
22
22
  "@tailwindcss/postcss": "^4.3.3",
23
23
  "@tanstack/react-query": "^5.101.4",