@ekanos/cli 0.28.1 → 0.30.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 +14 -5
- package/dist/auth/ekanos-api.d.ts +8 -1
- package/dist/auth/ekanos-api.js +14 -2
- package/dist/auth/ekanos-api.js.map +1 -1
- package/dist/bin.js +9 -1
- package/dist/bin.js.map +1 -1
- package/dist/commands/dev.js +5 -5
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/feedback.d.ts +38 -0
- package/dist/commands/feedback.js +234 -0
- package/dist/commands/feedback.js.map +1 -0
- package/dist/commands/publish.js +1 -1
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/sources.js +4 -1
- package/dist/commands/sources.js.map +1 -1
- package/dist/commands/status.js +1 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/validate.js +2 -2
- package/dist/commands/validate.js.map +1 -1
- package/dist/context.d.ts +11 -1
- package/dist/context.js +12 -1
- package/dist/context.js.map +1 -1
- package/dist/feedback-api.d.ts +70 -0
- package/dist/feedback-api.js +111 -0
- package/dist/feedback-api.js.map +1 -0
- package/dist/feedback-context.d.ts +31 -0
- package/dist/feedback-context.js +209 -0
- package/dist/feedback-context.js.map +1 -0
- package/dist/feedback-updates.d.ts +16 -0
- package/dist/feedback-updates.js +174 -0
- package/dist/feedback-updates.js.map +1 -0
- package/dist/http-trace.d.ts +19 -0
- package/dist/http-trace.js +47 -0
- package/dist/http-trace.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +172 -13
- package/dist/index.js.map +1 -1
- package/dist/last-error.d.ts +17 -0
- package/dist/last-error.js +56 -0
- package/dist/last-error.js.map +1 -0
- package/dist/toolchain-api.d.ts +2 -1
- package/dist/toolchain-api.js +2 -2
- package/dist/toolchain-api.js.map +1 -1
- package/dist/toolchain-resolve.d.ts +4 -0
- package/dist/toolchain-resolve.js +11 -7
- package/dist/toolchain-resolve.js.map +1 -1
- package/dist/update-notice.d.ts +31 -8
- package/dist/update-notice.js +161 -31
- package/dist/update-notice.js.map +1 -1
- package/package.json +2 -2
- package/templates/AGENTS.md.tmpl +19 -0
- package/templates/claude-skill.md.tmpl +18 -0
- package/templates/experience/package.json.tmpl +4 -4
- package/templates/package.json.tmpl +4 -4
- package/templates/skills/build-agent/SKILL.md +18 -0
- package/templates/skills/build-integration/SKILL.md +18 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface LastError {
|
|
2
|
+
failedAt: string;
|
|
3
|
+
cliVersion: string;
|
|
4
|
+
/** The host the command reached last, if it reached one. */
|
|
5
|
+
host: string | null;
|
|
6
|
+
command: string | null;
|
|
7
|
+
flags: string[];
|
|
8
|
+
errorCode: string | null;
|
|
9
|
+
exitCode: number;
|
|
10
|
+
httpStatus: number | null;
|
|
11
|
+
requestId: string | null;
|
|
12
|
+
}
|
|
13
|
+
export declare function lastErrorPath(env: Record<string, string | undefined>): string;
|
|
14
|
+
/** Replace the record. Best effort: a failure to write never changes a run. */
|
|
15
|
+
export declare function writeLastError(env: Record<string, string | undefined>, record: LastError): void;
|
|
16
|
+
/** The recorded failure, or null when there is none or it is unreadable. */
|
|
17
|
+
export declare function readLastError(env: Record<string, string | undefined>): LastError | null;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { resolveEkanosHome } from './auth/credential-store.js';
|
|
4
|
+
/**
|
|
5
|
+
* The last command that failed, kept for `ekanos feedback --last-error`:
|
|
6
|
+
* one small file, `~/.ekanos/last-error.json`, mode 0600, holding the most
|
|
7
|
+
* recent failure only. It holds what a report may carry and nothing else —
|
|
8
|
+
* the command path, flag names, codes, the host's status and request id —
|
|
9
|
+
* never an argument, a value, an error message (messages name the values
|
|
10
|
+
* they were given) or anything read from a file or the environment.
|
|
11
|
+
*
|
|
12
|
+
* Written only after a failure, read only by `ekanos feedback`. Never sent
|
|
13
|
+
* anywhere unless a report is filed with it.
|
|
14
|
+
*/
|
|
15
|
+
const FILENAME = 'last-error.json';
|
|
16
|
+
const DIR_MODE = 0o700;
|
|
17
|
+
const FILE_MODE = 0o600;
|
|
18
|
+
export function lastErrorPath(env) {
|
|
19
|
+
return path.join(resolveEkanosHome(env), '.ekanos', FILENAME);
|
|
20
|
+
}
|
|
21
|
+
/** Replace the record. Best effort: a failure to write never changes a run. */
|
|
22
|
+
export function writeLastError(env, record) {
|
|
23
|
+
const target = lastErrorPath(env);
|
|
24
|
+
try {
|
|
25
|
+
fs.mkdirSync(path.dirname(target), { recursive: true, mode: DIR_MODE });
|
|
26
|
+
const tmp = `${target}.${process.pid}.tmp`;
|
|
27
|
+
fs.writeFileSync(tmp, `${JSON.stringify(record)}\n`, { mode: FILE_MODE });
|
|
28
|
+
if (process.platform !== 'win32')
|
|
29
|
+
fs.chmodSync(tmp, FILE_MODE);
|
|
30
|
+
fs.renameSync(tmp, target);
|
|
31
|
+
}
|
|
32
|
+
catch (_a) {
|
|
33
|
+
// A courtesy for a later report, not a record anyone depends on.
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** The recorded failure, or null when there is none or it is unreadable. */
|
|
37
|
+
export function readLastError(env) {
|
|
38
|
+
try {
|
|
39
|
+
const parsed = JSON.parse(fs.readFileSync(lastErrorPath(env), 'utf8'));
|
|
40
|
+
return isLastError(parsed) ? parsed : null;
|
|
41
|
+
}
|
|
42
|
+
catch (_a) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function isLastError(value) {
|
|
47
|
+
if (typeof value !== 'object' || value === null)
|
|
48
|
+
return false;
|
|
49
|
+
const candidate = value;
|
|
50
|
+
return (typeof candidate.failedAt === 'string' &&
|
|
51
|
+
typeof candidate.cliVersion === 'string' &&
|
|
52
|
+
Array.isArray(candidate.flags) &&
|
|
53
|
+
candidate.flags.every((flag) => typeof flag === 'string') &&
|
|
54
|
+
typeof candidate.exitCode === 'number');
|
|
55
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;eAAO,CAAC;QACP,iEAAiE;IACnE,CAAC;AACH,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,aAAa,CAC3B,GAAuC;IAEvC,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAChC,EAAE,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAC5C,CAAC;QACF,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7C,CAAC;eAAO,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,SAAS,GAAG,KAA2B,CAAC;IAC9C,OAAO,CACL,OAAO,SAAS,CAAC,QAAQ,KAAK,QAAQ;QACtC,OAAO,SAAS,CAAC,UAAU,KAAK,QAAQ;QACxC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC;QAC9B,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC;QACzD,OAAO,SAAS,CAAC,QAAQ,KAAK,QAAQ,CACvC,CAAC;AACJ,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { resolveEkanosHome } from './auth/credential-store';\n\n/**\n * The last command that failed, kept for `ekanos feedback --last-error`:\n * one small file, `~/.ekanos/last-error.json`, mode 0600, holding the most\n * recent failure only. It holds what a report may carry and nothing else —\n * the command path, flag names, codes, the host's status and request id —\n * never an argument, a value, an error message (messages name the values\n * they were given) or anything read from a file or the environment.\n *\n * Written only after a failure, read only by `ekanos feedback`. Never sent\n * anywhere unless a report is filed with it.\n */\n\nconst FILENAME = 'last-error.json';\nconst DIR_MODE = 0o700;\nconst FILE_MODE = 0o600;\n\nexport interface LastError {\n failedAt: string;\n cliVersion: string;\n /** The host the command reached last, if it reached one. */\n host: string | null;\n command: string | null;\n flags: string[];\n errorCode: string | null;\n exitCode: number;\n httpStatus: number | null;\n requestId: string | null;\n}\n\nexport function lastErrorPath(env: Record<string, string | undefined>): string {\n return path.join(resolveEkanosHome(env), '.ekanos', FILENAME);\n}\n\n/** Replace the record. Best effort: a failure to write never changes a run. */\nexport function writeLastError(\n env: Record<string, string | undefined>,\n record: LastError,\n): void {\n const target = lastErrorPath(env);\n try {\n fs.mkdirSync(path.dirname(target), { recursive: true, mode: DIR_MODE });\n const tmp = `${target}.${process.pid}.tmp`;\n fs.writeFileSync(tmp, `${JSON.stringify(record)}\\n`, { mode: FILE_MODE });\n if (process.platform !== 'win32') fs.chmodSync(tmp, FILE_MODE);\n fs.renameSync(tmp, target);\n } catch {\n // A courtesy for a later report, not a record anyone depends on.\n }\n}\n\n/** The recorded failure, or null when there is none or it is unreadable. */\nexport function readLastError(\n env: Record<string, string | undefined>,\n): LastError | null {\n try {\n const parsed: unknown = JSON.parse(\n fs.readFileSync(lastErrorPath(env), 'utf8'),\n );\n return isLastError(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction isLastError(value: unknown): value is LastError {\n if (typeof value !== 'object' || value === null) return false;\n const candidate = value as Partial<LastError>;\n return (\n typeof candidate.failedAt === 'string' &&\n typeof candidate.cliVersion === 'string' &&\n Array.isArray(candidate.flags) &&\n candidate.flags.every((flag) => typeof flag === 'string') &&\n typeof candidate.exitCode === 'number'\n );\n}\n"]}
|
package/dist/toolchain-api.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RequestOptions } from './auth/ekanos-api.js';
|
|
1
2
|
import { type ToolchainNote, type ToolchainVersions } from './toolchain.js';
|
|
2
3
|
/**
|
|
3
4
|
* The CLI's client for the Ekanos toolchain-advisory route.
|
|
@@ -75,4 +76,4 @@ export type FetchToolchainResult = {
|
|
|
75
76
|
} | {
|
|
76
77
|
status: 'unavailable';
|
|
77
78
|
};
|
|
78
|
-
export declare function fetchToolchainReport(host: string, accessToken: string): Promise<FetchToolchainResult>;
|
|
79
|
+
export declare function fetchToolchainReport(host: string, accessToken: string, options?: RequestOptions): Promise<FetchToolchainResult>;
|
package/dist/toolchain-api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { request } from './auth/ekanos-api.js';
|
|
2
2
|
import { TOOLCHAIN_PACKAGES, firstInexactVersion, } from './toolchain.js';
|
|
3
|
-
export async function fetchToolchainReport(host, accessToken) {
|
|
3
|
+
export async function fetchToolchainReport(host, accessToken, options = {}) {
|
|
4
4
|
try {
|
|
5
5
|
const response = await request(`${host}/api/partner/toolchain`, {
|
|
6
6
|
method: 'GET',
|
|
@@ -8,7 +8,7 @@ export async function fetchToolchainReport(host, accessToken) {
|
|
|
8
8
|
accept: 'application/json',
|
|
9
9
|
authorization: `Bearer ${accessToken}`,
|
|
10
10
|
},
|
|
11
|
-
});
|
|
11
|
+
}, options);
|
|
12
12
|
if (!response.ok)
|
|
13
13
|
return { status: 'unavailable' };
|
|
14
14
|
const body = await response.json();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolchain-api.js","sourceRoot":"","sources":["../src/toolchain-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AA6ErB,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAY,EACZ,WAAmB;IAEnB,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,GAAG,IAAI,wBAAwB,EAAE;YAC9D,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,MAAM,EAAE,kBAAkB;gBAC1B,aAAa,EAAE,UAAU,WAAW,EAAE;aACv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C,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAC7D,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACpB,CAAC;IAED,OAAO,MAA2B,CAAC;AACrC,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,IAAI,GAAG,KAA+C,CAAC;IAC7D,OAAO,CACL,CAAC,IAAI,CAAC,KAAK,KAAK,MAAM,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC;QAChD,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CACjC,CAAC;AACJ,CAAC","sourcesContent":["import { request } from './auth/ekanos-api';\nimport {\n TOOLCHAIN_PACKAGES,\n type ToolchainNote,\n type ToolchainVersions,\n firstInexactVersion,\n} from './toolchain';\n\n/**\n * The CLI's client for the Ekanos toolchain-advisory route.\n *\n * ---------------------------------------------------------------------------\n * WIRE CONTRACT — the seam between this package and the Ekanos web app.\n *\n * The server side is the host's `/api/partner/toolchain` route and ships on\n * a DIFFERENT BRANCH from this file, same as every other route in\n * `auth/ekanos-api.ts` and `publish-api.ts`. Nothing here imports host code;\n * the two halves are coupled only by HTTP, and the tests stub `fetch`,\n * never the route.\n *\n * GET /api/partner/toolchain [Authorization: Bearer <access_token>]\n * → 200 { ok: true, data: {\n * current: { cli, sdk, ui, integrationSchema, harness }, // the\n * // coherent\n * // set the\n * // host\n * // recommends\n * minimum: { cli, sdk, ui, integrationSchema, harness }, // below\n * // this the\n * // host\n * // refuses\n * notes?: [{ level: \"warn\" | \"info\", message: string }],\n * capabilities?: { experienceSubmissions?: boolean }, // optional\n * // host features; a host\n * // that predates one omits\n * // the key and a caller\n * // reads that as \"no\"\n * } }\n * → any other status, or a body that fails to parse or match this shape\n *\n * This endpoint is treated as ADVISORY, not authoritative in the way the auth\n * and submission routes are: a 404 (an older Ekanos deployment that predates\n * this route) or a 501 (deliberately unimplemented) are both entirely\n * ordinary, and a 4xx/5xx/network failure/malformed body all mean exactly the\n * same thing to every caller — \"the endpoint is unavailable, fall back to the\n * npm registry\" — so this module never throws. There is no not-configured\n * distinction to make here the way `cli-config` has: a caller with no way to\n * reach this route at all (no host, no session) never calls it in the first\n * place; see `toolchain-resolve.ts`.\n *\n * Unknown extra fields in the response are tolerated (only the fields above\n * are read); a missing `notes` defaults to an empty array.\n *\n * The one exception to \"never throws, always falls back\": a version that is\n * present but is not an exact semver (`1.2.3`, `1.2.3-rc.1`) is `invalid`, not\n * `unavailable`. Each version becomes a `pnpm add -E` spec, so a value like\n * `github:owner/repo` is a host trying to install code; that is refused\n * outright rather than quietly papered over by the npm fallback.\n * ---------------------------------------------------------------------------\n */\n\n/**\n * Optional host features, advertised additively. A key the host does not send\n * reads as `false`, so an older deployment behaves exactly as before.\n */\nexport interface HostCapabilities {\n /** `POST /api/partner/submissions` accepts `kind=experience` and the host admits it. */\n experienceSubmissions: boolean;\n}\n\nexport interface ToolchainReport {\n current: ToolchainVersions;\n minimum: ToolchainVersions;\n notes: ToolchainNote[];\n /** Absent when the host sent none (an older host). */\n capabilities?: HostCapabilities;\n}\n\nexport type FetchToolchainResult =\n | { status: 'ok'; report: ToolchainReport }\n | { status: 'invalid'; detail: string }\n | { status: 'unavailable' };\n\nexport async function fetchToolchainReport(\n host: string,\n accessToken: string,\n): Promise<FetchToolchainResult> {\n try {\n const response = await request(`${host}/api/partner/toolchain`, {\n method: 'GET',\n headers: {\n accept: 'application/json',\n authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) return { status: 'unavailable' };\n\n const body: unknown = await response.json();\n const report = parseReport(body);\n\n if (report === null) return { status: 'unavailable' };\n if ('invalid' in report)\n return { status: 'invalid', detail: report.invalid };\n return { status: 'ok', report };\n } catch {\n // Network failure, timeout, or a body that is not even JSON — all read\n // the same: the endpoint is unavailable this time, fall back to npm.\n return { status: 'unavailable' };\n }\n}\n\nfunction parseReport(\n body: unknown,\n): ToolchainReport | { invalid: string } | null {\n if (typeof body !== 'object' || body === null) return null;\n const data = (body as { data?: unknown }).data;\n if (typeof data !== 'object' || data === null) return null;\n\n const current = parseVersions((data as { current?: unknown }).current);\n const minimum = parseVersions((data as { minimum?: unknown }).minimum);\n if (!current || !minimum) return null;\n\n for (const [label, versions] of [\n ['current', current],\n ['minimum', minimum],\n ] as const) {\n const bad = firstInexactVersion(versions);\n if (bad) {\n return {\n invalid: `the host's ${label} ${TOOLCHAIN_PACKAGES[bad.key]} is ${JSON.stringify(bad.value)}, which is not an exact version`,\n };\n }\n }\n\n const rawNotes = (data as { notes?: unknown }).notes;\n const notes = Array.isArray(rawNotes) ? rawNotes.filter(isNote) : [];\n\n const capabilities = parseCapabilities(\n (data as { capabilities?: unknown }).capabilities,\n );\n\n return {\n current,\n minimum,\n notes,\n ...(capabilities ? { capabilities } : {}),\n };\n}\n\nfunction parseCapabilities(value: unknown): HostCapabilities | null {\n if (typeof value !== 'object' || value === null) return null;\n\n return {\n experienceSubmissions:\n (value as { experienceSubmissions?: unknown }).experienceSubmissions ===\n true,\n };\n}\n\nfunction parseVersions(value: unknown): ToolchainVersions | null {\n if (typeof value !== 'object' || value === null) return null;\n const record = value as Record<string, unknown>;\n const result: Partial<ToolchainVersions> = {};\n\n for (const key of Object.keys(\n TOOLCHAIN_PACKAGES,\n ) as (keyof ToolchainVersions)[]) {\n const raw = record[key];\n if (typeof raw !== 'string' || raw.length === 0) return null;\n result[key] = raw;\n }\n\n return result as ToolchainVersions;\n}\n\nfunction isNote(value: unknown): value is ToolchainNote {\n if (typeof value !== 'object' || value === null) return false;\n const note = value as { level?: unknown; message?: unknown };\n return (\n (note.level === 'warn' || note.level === 'info') &&\n typeof note.message === 'string'\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"toolchain-api.js","sourceRoot":"","sources":["../src/toolchain-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,OAAO,EAAE,MAAM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;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC7D,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,MAAM,MAAM,GAA+B,EAAE,CAAC;IAE9C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAC3B,kBAAkB,CACY,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QACxB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAC7D,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IACpB,CAAC;IAED,OAAO,MAA2B,CAAC;AACrC,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,IAAI,GAAG,KAA+C,CAAC;IAC7D,OAAO,CACL,CAAC,IAAI,CAAC,KAAK,KAAK,MAAM,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC;QAChD,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,CACjC,CAAC;AACJ,CAAC","sourcesContent":["import { type RequestOptions, request } from './auth/ekanos-api';\nimport {\n TOOLCHAIN_PACKAGES,\n type ToolchainNote,\n type ToolchainVersions,\n firstInexactVersion,\n} from './toolchain';\n\n/**\n * The CLI's client for the Ekanos toolchain-advisory route.\n *\n * ---------------------------------------------------------------------------\n * WIRE CONTRACT — the seam between this package and the Ekanos web app.\n *\n * The server side is the host's `/api/partner/toolchain` route and ships on\n * a DIFFERENT BRANCH from this file, same as every other route in\n * `auth/ekanos-api.ts` and `publish-api.ts`. Nothing here imports host code;\n * the two halves are coupled only by HTTP, and the tests stub `fetch`,\n * never the route.\n *\n * GET /api/partner/toolchain [Authorization: Bearer <access_token>]\n * → 200 { ok: true, data: {\n * current: { cli, sdk, ui, integrationSchema, harness }, // the\n * // coherent\n * // set the\n * // host\n * // recommends\n * minimum: { cli, sdk, ui, integrationSchema, harness }, // below\n * // this the\n * // host\n * // refuses\n * notes?: [{ level: \"warn\" | \"info\", message: string }],\n * capabilities?: { experienceSubmissions?: boolean }, // optional\n * // host features; a host\n * // that predates one omits\n * // the key and a caller\n * // reads that as \"no\"\n * } }\n * → any other status, or a body that fails to parse or match this shape\n *\n * This endpoint is treated as ADVISORY, not authoritative in the way the auth\n * and submission routes are: a 404 (an older Ekanos deployment that predates\n * this route) or a 501 (deliberately unimplemented) are both entirely\n * ordinary, and a 4xx/5xx/network failure/malformed body all mean exactly the\n * same thing to every caller — \"the endpoint is unavailable, fall back to the\n * npm registry\" — so this module never throws. There is no not-configured\n * distinction to make here the way `cli-config` has: a caller with no way to\n * reach this route at all (no host, no session) never calls it in the first\n * place; see `toolchain-resolve.ts`.\n *\n * Unknown extra fields in the response are tolerated (only the fields above\n * are read); a missing `notes` defaults to an empty array.\n *\n * The one exception to \"never throws, always falls back\": a version that is\n * present but is not an exact semver (`1.2.3`, `1.2.3-rc.1`) is `invalid`, not\n * `unavailable`. Each version becomes a `pnpm add -E` spec, so a value like\n * `github:owner/repo` is a host trying to install code; that is refused\n * outright rather than quietly papered over by the npm fallback.\n * ---------------------------------------------------------------------------\n */\n\n/**\n * Optional host features, advertised additively. A key the host does not send\n * reads as `false`, so an older deployment behaves exactly as before.\n */\nexport interface HostCapabilities {\n /** `POST /api/partner/submissions` accepts `kind=experience` and the host admits it. */\n experienceSubmissions: boolean;\n}\n\nexport interface ToolchainReport {\n current: ToolchainVersions;\n minimum: ToolchainVersions;\n notes: ToolchainNote[];\n /** Absent when the host sent none (an older host). */\n capabilities?: HostCapabilities;\n}\n\nexport type FetchToolchainResult =\n | { status: 'ok'; report: ToolchainReport }\n | { status: 'invalid'; detail: string }\n | { status: 'unavailable' };\n\nexport async function fetchToolchainReport(\n host: string,\n accessToken: string,\n options: RequestOptions = {},\n): Promise<FetchToolchainResult> {\n try {\n const response = await request(\n `${host}/api/partner/toolchain`,\n {\n method: 'GET',\n headers: {\n accept: 'application/json',\n authorization: `Bearer ${accessToken}`,\n },\n },\n options,\n );\n\n if (!response.ok) return { status: 'unavailable' };\n\n const body: unknown = await response.json();\n const report = parseReport(body);\n\n if (report === null) return { status: 'unavailable' };\n if ('invalid' in report)\n return { status: 'invalid', detail: report.invalid };\n return { status: 'ok', report };\n } catch {\n // Network failure, timeout, or a body that is not even JSON — all read\n // the same: the endpoint is unavailable this time, fall back to npm.\n return { status: 'unavailable' };\n }\n}\n\nfunction parseReport(\n body: unknown,\n): ToolchainReport | { invalid: string } | null {\n if (typeof body !== 'object' || body === null) return null;\n const data = (body as { data?: unknown }).data;\n if (typeof data !== 'object' || data === null) return null;\n\n const current = parseVersions((data as { current?: unknown }).current);\n const minimum = parseVersions((data as { minimum?: unknown }).minimum);\n if (!current || !minimum) return null;\n\n for (const [label, versions] of [\n ['current', current],\n ['minimum', minimum],\n ] as const) {\n const bad = firstInexactVersion(versions);\n if (bad) {\n return {\n invalid: `the host's ${label} ${TOOLCHAIN_PACKAGES[bad.key]} is ${JSON.stringify(bad.value)}, which is not an exact version`,\n };\n }\n }\n\n const rawNotes = (data as { notes?: unknown }).notes;\n const notes = Array.isArray(rawNotes) ? rawNotes.filter(isNote) : [];\n\n const capabilities = parseCapabilities(\n (data as { capabilities?: unknown }).capabilities,\n );\n\n return {\n current,\n minimum,\n notes,\n ...(capabilities ? { capabilities } : {}),\n };\n}\n\nfunction parseCapabilities(value: unknown): HostCapabilities | null {\n if (typeof value !== 'object' || value === null) return null;\n\n return {\n experienceSubmissions:\n (value as { experienceSubmissions?: unknown }).experienceSubmissions ===\n true,\n };\n}\n\nfunction parseVersions(value: unknown): ToolchainVersions | null {\n if (typeof value !== 'object' || value === null) return null;\n const record = value as Record<string, unknown>;\n const result: Partial<ToolchainVersions> = {};\n\n for (const key of Object.keys(\n TOOLCHAIN_PACKAGES,\n ) as (keyof ToolchainVersions)[]) {\n const raw = record[key];\n if (typeof raw !== 'string' || raw.length === 0) return null;\n result[key] = raw;\n }\n\n return result as ToolchainVersions;\n}\n\nfunction isNote(value: unknown): value is ToolchainNote {\n if (typeof value !== 'object' || value === null) return false;\n const note = value as { level?: unknown; message?: unknown };\n return (\n (note.level === 'warn' || note.level === 'info') &&\n typeof note.message === 'string'\n );\n}\n"]}
|
|
@@ -25,5 +25,9 @@ export interface ResolveToolchainParams {
|
|
|
25
25
|
} | null;
|
|
26
26
|
/** Per-request timeout for the underlying fetches. */
|
|
27
27
|
timeoutMs?: number;
|
|
28
|
+
/** Abort every underlying fetch early (a background check let go). */
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
/** Leave the host call out of the run's HTTP trace: a background check. */
|
|
31
|
+
untraced?: boolean;
|
|
28
32
|
}
|
|
29
33
|
export declare function resolveToolchainTarget(params: ResolveToolchainParams): Promise<ToolchainResolution>;
|
|
@@ -35,7 +35,7 @@ function registryPackageUrl(pkg, version) {
|
|
|
35
35
|
}
|
|
36
36
|
export async function resolveToolchainTarget(params) {
|
|
37
37
|
if (params.host && params.session) {
|
|
38
|
-
const hostResult = await fetchToolchainReport(params.host, params.session.accessToken);
|
|
38
|
+
const hostResult = await fetchToolchainReport(params.host, params.session.accessToken, Object.assign({ signal: params.signal, untraced: params.untraced }, (params.timeoutMs ? { timeoutMs: params.timeoutMs } : {})));
|
|
39
39
|
if (hostResult.status === 'ok') {
|
|
40
40
|
return {
|
|
41
41
|
status: 'ok',
|
|
@@ -49,14 +49,14 @@ export async function resolveToolchainTarget(params) {
|
|
|
49
49
|
return hostResult;
|
|
50
50
|
// 404 / 501 / network failure / malformed body: fall through to npm.
|
|
51
51
|
}
|
|
52
|
-
return resolveFromNpmRegistry(params.timeoutMs);
|
|
52
|
+
return resolveFromNpmRegistry(params.timeoutMs, params.signal);
|
|
53
53
|
}
|
|
54
|
-
async function resolveFromNpmRegistry(timeoutMs) {
|
|
54
|
+
async function resolveFromNpmRegistry(timeoutMs, signal) {
|
|
55
55
|
var _a;
|
|
56
56
|
const entries = Object.entries(TOOLCHAIN_PACKAGES);
|
|
57
57
|
const latests = await Promise.all(entries.map(async ([key, pkg]) => {
|
|
58
58
|
var _a;
|
|
59
|
-
const body = await fetchRegistryJson(registryPackageUrl(pkg), timeoutMs);
|
|
59
|
+
const body = await fetchRegistryJson(registryPackageUrl(pkg), timeoutMs, signal);
|
|
60
60
|
const latest = (_a = body === null || body === void 0 ? void 0 : body['dist-tags']) === null || _a === void 0 ? void 0 : _a.latest;
|
|
61
61
|
return [key, typeof latest === 'string' ? latest : null];
|
|
62
62
|
}));
|
|
@@ -82,7 +82,7 @@ async function resolveFromNpmRegistry(timeoutMs) {
|
|
|
82
82
|
`usually a multi-package publish still in flight — retry shortly.`,
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
const sdkManifest = await fetchRegistryJson(registryPackageUrl(TOOLCHAIN_PACKAGES.sdk, target.sdk), timeoutMs);
|
|
85
|
+
const sdkManifest = await fetchRegistryJson(registryPackageUrl(TOOLCHAIN_PACKAGES.sdk, target.sdk), timeoutMs, signal);
|
|
86
86
|
const sdkPinnedSchema = (_a = sdkManifest === null || sdkManifest === void 0 ? void 0 : sdkManifest.dependencies) === null || _a === void 0 ? void 0 : _a['@ekanos/integration-schema'];
|
|
87
87
|
if (typeof sdkPinnedSchema !== 'string' ||
|
|
88
88
|
sdkPinnedSchema !== target.integrationSchema) {
|
|
@@ -97,11 +97,15 @@ async function resolveFromNpmRegistry(timeoutMs) {
|
|
|
97
97
|
}
|
|
98
98
|
return { status: 'ok', source: 'npm', target };
|
|
99
99
|
}
|
|
100
|
-
async function fetchRegistryJson(url, timeoutMs) {
|
|
100
|
+
async function fetchRegistryJson(url, timeoutMs, signal) {
|
|
101
|
+
const signals = [
|
|
102
|
+
...(timeoutMs ? [AbortSignal.timeout(timeoutMs)] : []),
|
|
103
|
+
...(signal ? [signal] : []),
|
|
104
|
+
];
|
|
101
105
|
try {
|
|
102
106
|
const response = await fetch(url, {
|
|
103
107
|
headers: { accept: 'application/json' },
|
|
104
|
-
signal:
|
|
108
|
+
signal: signals.length > 0 ? AbortSignal.any(signals) : undefined,
|
|
105
109
|
});
|
|
106
110
|
if (!response.ok)
|
|
107
111
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolchain-resolve.js","sourceRoot":"","sources":["../src/toolchain-resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAIlB,mBAAmB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,MAAM,aAAa,GAAG,4BAA4B,CAAC;AAEnD,wEAAwE;AACxE,SAAS,kBAAkB,CAAC,GAAW,EAAE,OAAgB;IACvD,MAAM,OAAO,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC5D,OAAO,OAAO;QACZ,CAAC,CAAC,GAAG,aAAa,IAAI,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAAE;QAC9D,CAAC,CAAC,GAAG,aAAa,IAAI,OAAO,EAAE,CAAC;AACpC,CAAC;AAsBD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAA8B;IAE9B,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QAClC,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAC3C,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,OAAO,CAAC,WAAW,CAC3B,CAAC;QAEF,IAAI,UAAU,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;YAC/B,OAAO;gBACL,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,MAAM;gBACd,MAAM,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I,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AACjD,CAAC;AAED,KAAK,UAAU,iBAAiB,CAC9B,GAAW,EACX,SAAkB;IAElB,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;YACvC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;SAC/D,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QAC9B,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;eAAO,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import {\n TOOLCHAIN_PACKAGES,\n type ToolchainKey,\n type ToolchainNote,\n type ToolchainVersions,\n firstInexactVersion,\n} from './toolchain';\nimport { fetchToolchainReport } from './toolchain-api';\n\n/**\n * The single place that answers \"what should this toolchain be at?\" — shared\n * by `ekanos upgrade` (which installs the answer) and the proactive update\n * notice (which only reports it). Both need the exact same coherent target,\n * so there is exactly one resolution path, tried in this order:\n *\n * 1. `GET /api/partner/toolchain` on the resolved host, when both a host and\n * a session are available. Whatever the host returns is trusted as\n * already-coherent — it is the operator's own recommendation.\n * 2. The npm registry's `dist-tags.latest` for all five packages, with an\n * explicit COHERENCE check before ever calling it a \"target\": the\n * `@ekanos/sdk` / `@ekanos/ui` / `@ekanos/integration-schema` trio must\n * resolve to one identical version, and the `@ekanos/sdk` release at that\n * version must declare the exact same `@ekanos/integration-schema`\n * dependency. A multi-package publish is not atomic — this repo hit that\n * exact window mid-publish — so assembling \"latest of each, independently\"\n * can produce a set that literally cannot install together. Refusing is\n * the only safe response to a set caught in that state; the failure is\n * obvious and self-resolves the moment the publish finishes.\n *\n * Either way every version must be EXACT (`1.2.3`, `1.2.3-rc.1`): each one\n * becomes a `pnpm add -E` spec, so a host or dist-tag answering\n * `github:owner/repo` or a tarball URL resolves to `invalid` and installs\n * nothing.\n */\n\nconst REGISTRY_BASE = 'https://registry.npmjs.org';\n\n/** npm registry package URLs encode the scope's `/` but not its `@`. */\nfunction registryPackageUrl(pkg: string, version?: string): string {\n const encoded = encodeURIComponent(pkg).replace('%40', '@');\n return version\n ? `${REGISTRY_BASE}/${encoded}/${encodeURIComponent(version)}`\n : `${REGISTRY_BASE}/${encoded}`;\n}\n\nexport type ToolchainResolution =\n | {\n status: 'ok';\n source: 'host';\n target: ToolchainVersions;\n minimum: ToolchainVersions;\n notes: ToolchainNote[];\n }\n | { status: 'ok'; source: 'npm'; target: ToolchainVersions }\n | { status: 'incoherent'; detail: string }\n | { status: 'invalid'; detail: string }\n | { status: 'unavailable' };\n\nexport interface ResolveToolchainParams {\n host?: string;\n session?: { accessToken: string } | null;\n /** Per-request timeout for the underlying fetches. */\n timeoutMs?: number;\n}\n\nexport async function resolveToolchainTarget(\n params: ResolveToolchainParams,\n): Promise<ToolchainResolution> {\n if (params.host && params.session) {\n const hostResult = await fetchToolchainReport(\n params.host,\n params.session.accessToken,\n );\n\n if (hostResult.status === 'ok') {\n return {\n status: 'ok',\n source: 'host',\n target: hostResult.report.current,\n minimum: hostResult.report.minimum,\n notes: hostResult.report.notes,\n };\n }\n if (hostResult.status === 'invalid') return hostResult;\n\n // 404 / 501 / network failure / malformed body: fall through to npm.\n }\n\n return resolveFromNpmRegistry(params.timeoutMs);\n}\n\nasync function resolveFromNpmRegistry(\n timeoutMs?: number,\n): Promise<ToolchainResolution> {\n const entries = Object.entries(TOOLCHAIN_PACKAGES) as [\n ToolchainKey,\n string,\n ][];\n\n const latests = await Promise.all(\n entries.map(async ([key, pkg]) => {\n const body = await fetchRegistryJson(registryPackageUrl(pkg), timeoutMs);\n const latest = (body as { 'dist-tags'?: { latest?: unknown } } | null)?.[\n 'dist-tags'\n ]?.latest;\n return [key, typeof latest === 'string' ? latest : null] as const;\n }),\n );\n\n const versions = Object.fromEntries(latests) as Record<\n ToolchainKey,\n string | null\n >;\n\n if (Object.values(versions).some((version) => version === null)) {\n return { status: 'unavailable' };\n }\n\n const inexact = firstInexactVersion(versions);\n if (inexact) {\n return {\n status: 'invalid',\n detail: `npm's latest ${TOOLCHAIN_PACKAGES[inexact.key]} is ${JSON.stringify(inexact.value)}, which is not an exact version`,\n };\n }\n\n const target = versions as ToolchainVersions;\n\n const trio = [target.sdk, target.ui, target.integrationSchema];\n if (new Set(trio).size !== 1) {\n return {\n status: 'incoherent',\n detail:\n `the npm registry reports mismatched versions for the sdk/ui/schema ` +\n `trio: @ekanos/sdk@${target.sdk}, @ekanos/ui@${target.ui}, ` +\n `@ekanos/integration-schema@${target.integrationSchema}. This is ` +\n `usually a multi-package publish still in flight — retry shortly.`,\n };\n }\n\n const sdkManifest = await fetchRegistryJson(\n registryPackageUrl(TOOLCHAIN_PACKAGES.sdk, target.sdk),\n timeoutMs,\n );\n const sdkPinnedSchema = (\n sdkManifest as { dependencies?: Record<string, unknown> } | null\n )?.dependencies?.['@ekanos/integration-schema'];\n\n if (\n typeof sdkPinnedSchema !== 'string' ||\n sdkPinnedSchema !== target.integrationSchema\n ) {\n return {\n status: 'incoherent',\n detail:\n `@ekanos/sdk@${target.sdk} on npm depends on ` +\n `@ekanos/integration-schema@${String(sdkPinnedSchema)}, which does ` +\n `not match the published @ekanos/integration-schema@` +\n `${target.integrationSchema}. This is usually a multi-package ` +\n `publish still in flight — retry shortly.`,\n };\n }\n\n return { status: 'ok', source: 'npm', target };\n}\n\nasync function fetchRegistryJson(\n url: string,\n timeoutMs?: number,\n): Promise<unknown | null> {\n try {\n const response = await fetch(url, {\n headers: { accept: 'application/json' },\n signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined,\n });\n if (!response.ok) return null;\n return await response.json();\n } catch {\n return null;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"toolchain-res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M,EAAE,CAAC;AACjD,CAAC;AAED,KAAK,UAAU,iBAAiB,CAC9B,GAAW,EACX,SAAkB,EAClB,MAAoB;IAEpB,MAAM,OAAO,GAAG;QACd,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5B,CAAC;IACF,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;YACvC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;SAClE,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE;YAAE,OAAO,IAAI,CAAC;QAC9B,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;eAAO,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import {\n TOOLCHAIN_PACKAGES,\n type ToolchainKey,\n type ToolchainNote,\n type ToolchainVersions,\n firstInexactVersion,\n} from './toolchain';\nimport { fetchToolchainReport } from './toolchain-api';\n\n/**\n * The single place that answers \"what should this toolchain be at?\" — shared\n * by `ekanos upgrade` (which installs the answer) and the proactive update\n * notice (which only reports it). Both need the exact same coherent target,\n * so there is exactly one resolution path, tried in this order:\n *\n * 1. `GET /api/partner/toolchain` on the resolved host, when both a host and\n * a session are available. Whatever the host returns is trusted as\n * already-coherent — it is the operator's own recommendation.\n * 2. The npm registry's `dist-tags.latest` for all five packages, with an\n * explicit COHERENCE check before ever calling it a \"target\": the\n * `@ekanos/sdk` / `@ekanos/ui` / `@ekanos/integration-schema` trio must\n * resolve to one identical version, and the `@ekanos/sdk` release at that\n * version must declare the exact same `@ekanos/integration-schema`\n * dependency. A multi-package publish is not atomic — this repo hit that\n * exact window mid-publish — so assembling \"latest of each, independently\"\n * can produce a set that literally cannot install together. Refusing is\n * the only safe response to a set caught in that state; the failure is\n * obvious and self-resolves the moment the publish finishes.\n *\n * Either way every version must be EXACT (`1.2.3`, `1.2.3-rc.1`): each one\n * becomes a `pnpm add -E` spec, so a host or dist-tag answering\n * `github:owner/repo` or a tarball URL resolves to `invalid` and installs\n * nothing.\n */\n\nconst REGISTRY_BASE = 'https://registry.npmjs.org';\n\n/** npm registry package URLs encode the scope's `/` but not its `@`. */\nfunction registryPackageUrl(pkg: string, version?: string): string {\n const encoded = encodeURIComponent(pkg).replace('%40', '@');\n return version\n ? `${REGISTRY_BASE}/${encoded}/${encodeURIComponent(version)}`\n : `${REGISTRY_BASE}/${encoded}`;\n}\n\nexport type ToolchainResolution =\n | {\n status: 'ok';\n source: 'host';\n target: ToolchainVersions;\n minimum: ToolchainVersions;\n notes: ToolchainNote[];\n }\n | { status: 'ok'; source: 'npm'; target: ToolchainVersions }\n | { status: 'incoherent'; detail: string }\n | { status: 'invalid'; detail: string }\n | { status: 'unavailable' };\n\nexport interface ResolveToolchainParams {\n host?: string;\n session?: { accessToken: string } | null;\n /** Per-request timeout for the underlying fetches. */\n timeoutMs?: number;\n /** Abort every underlying fetch early (a background check let go). */\n signal?: AbortSignal;\n /** Leave the host call out of the run's HTTP trace: a background check. */\n untraced?: boolean;\n}\n\nexport async function resolveToolchainTarget(\n params: ResolveToolchainParams,\n): Promise<ToolchainResolution> {\n if (params.host && params.session) {\n const hostResult = await fetchToolchainReport(\n params.host,\n params.session.accessToken,\n {\n signal: params.signal,\n untraced: params.untraced,\n ...(params.timeoutMs ? { timeoutMs: params.timeoutMs } : {}),\n },\n );\n\n if (hostResult.status === 'ok') {\n return {\n status: 'ok',\n source: 'host',\n target: hostResult.report.current,\n minimum: hostResult.report.minimum,\n notes: hostResult.report.notes,\n };\n }\n if (hostResult.status === 'invalid') return hostResult;\n\n // 404 / 501 / network failure / malformed body: fall through to npm.\n }\n\n return resolveFromNpmRegistry(params.timeoutMs, params.signal);\n}\n\nasync function resolveFromNpmRegistry(\n timeoutMs?: number,\n signal?: AbortSignal,\n): Promise<ToolchainResolution> {\n const entries = Object.entries(TOOLCHAIN_PACKAGES) as [\n ToolchainKey,\n string,\n ][];\n\n const latests = await Promise.all(\n entries.map(async ([key, pkg]) => {\n const body = await fetchRegistryJson(\n registryPackageUrl(pkg),\n timeoutMs,\n signal,\n );\n const latest = (body as { 'dist-tags'?: { latest?: unknown } } | null)?.[\n 'dist-tags'\n ]?.latest;\n return [key, typeof latest === 'string' ? latest : null] as const;\n }),\n );\n\n const versions = Object.fromEntries(latests) as Record<\n ToolchainKey,\n string | null\n >;\n\n if (Object.values(versions).some((version) => version === null)) {\n return { status: 'unavailable' };\n }\n\n const inexact = firstInexactVersion(versions);\n if (inexact) {\n return {\n status: 'invalid',\n detail: `npm's latest ${TOOLCHAIN_PACKAGES[inexact.key]} is ${JSON.stringify(inexact.value)}, which is not an exact version`,\n };\n }\n\n const target = versions as ToolchainVersions;\n\n const trio = [target.sdk, target.ui, target.integrationSchema];\n if (new Set(trio).size !== 1) {\n return {\n status: 'incoherent',\n detail:\n `the npm registry reports mismatched versions for the sdk/ui/schema ` +\n `trio: @ekanos/sdk@${target.sdk}, @ekanos/ui@${target.ui}, ` +\n `@ekanos/integration-schema@${target.integrationSchema}. This is ` +\n `usually a multi-package publish still in flight — retry shortly.`,\n };\n }\n\n const sdkManifest = await fetchRegistryJson(\n registryPackageUrl(TOOLCHAIN_PACKAGES.sdk, target.sdk),\n timeoutMs,\n signal,\n );\n const sdkPinnedSchema = (\n sdkManifest as { dependencies?: Record<string, unknown> } | null\n )?.dependencies?.['@ekanos/integration-schema'];\n\n if (\n typeof sdkPinnedSchema !== 'string' ||\n sdkPinnedSchema !== target.integrationSchema\n ) {\n return {\n status: 'incoherent',\n detail:\n `@ekanos/sdk@${target.sdk} on npm depends on ` +\n `@ekanos/integration-schema@${String(sdkPinnedSchema)}, which does ` +\n `not match the published @ekanos/integration-schema@` +\n `${target.integrationSchema}. This is usually a multi-package ` +\n `publish still in flight — retry shortly.`,\n };\n }\n\n return { status: 'ok', source: 'npm', target };\n}\n\nasync function fetchRegistryJson(\n url: string,\n timeoutMs?: number,\n signal?: AbortSignal,\n): Promise<unknown | null> {\n const signals = [\n ...(timeoutMs ? [AbortSignal.timeout(timeoutMs)] : []),\n ...(signal ? [signal] : []),\n ];\n try {\n const response = await fetch(url, {\n headers: { accept: 'application/json' },\n signal: signals.length > 0 ? AbortSignal.any(signals) : undefined,\n });\n if (!response.ok) return null;\n return await response.json();\n } catch {\n return null;\n }\n}\n"]}
|
package/dist/update-notice.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CliContext } from './context.js';
|
|
2
2
|
import type { ToolchainVersions } from './toolchain.js';
|
|
3
|
+
export declare const UPDATE_CHECK_TTL_MS: number;
|
|
3
4
|
export interface ToolchainNoticeData {
|
|
4
5
|
status: 'behind' | 'unsupported';
|
|
5
6
|
current: {
|
|
@@ -17,16 +18,38 @@ export interface CheckForUpdateParams {
|
|
|
17
18
|
} | null;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
|
-
* Resolve whether this CLI is behind, respecting the
|
|
21
|
+
* Resolve whether this CLI is behind, respecting the 4h cache and the hard
|
|
21
22
|
* `EKANOS_NO_UPDATE_CHECK` opt-out. Returns null whenever there is nothing to
|
|
22
|
-
* say — current, unresolvable, or any failure along the way.
|
|
23
|
+
* say — current, unresolvable, or any failure along the way. Inside a run
|
|
24
|
+
* that already started the background check, it joins that check rather
|
|
25
|
+
* than asking again, unless the caller names a different host.
|
|
23
26
|
*/
|
|
24
27
|
export declare function checkForUpdate(params: CheckForUpdateParams): Promise<ToolchainNoticeData | null>;
|
|
28
|
+
export interface UpdateCheck {
|
|
29
|
+
/** Announce what is ready, if it is due, and let go of anything in flight. */
|
|
30
|
+
finish(ctx: CliContext): void;
|
|
31
|
+
/** Settles when the background work does (tests). */
|
|
32
|
+
readonly settled: Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Start the run's background check. `run()` calls it as a command starts and
|
|
36
|
+
* `finish` once the command has written its output; nothing awaits it in
|
|
37
|
+
* between, so it never delays a command. Returns null when switched off.
|
|
38
|
+
*/
|
|
39
|
+
export declare function startUpdateCheck(params: {
|
|
40
|
+
env: Record<string, string | undefined>;
|
|
41
|
+
}): UpdateCheck | null;
|
|
25
42
|
/**
|
|
26
|
-
* Surface a notice, if
|
|
27
|
-
* the `claude-code-hint` stderr line
|
|
28
|
-
*
|
|
29
|
-
* envelope's caller
|
|
30
|
-
* key in its own `data`, per the envelope docs in `context.ts`.
|
|
43
|
+
* Surface a notice, if one is due. Human mode gets one stderr line; with
|
|
44
|
+
* `--json` or a detected agent, the `claude-code-hint` stderr line carries
|
|
45
|
+
* the notice instead, so an agent sees it without parsing prose. NEVER
|
|
46
|
+
* writes to stdout — the JSON envelope's caller embeds `notice` under a
|
|
47
|
+
* `toolchain` key in its own `data`, per the envelope docs in `context.ts`.
|
|
48
|
+
*
|
|
49
|
+
* Remembers in the cache when a "behind" notice was shown, so it is said at
|
|
50
|
+
* most once per window — and only when something was really written: in CI
|
|
51
|
+
* (no TTY, no agent) nothing is, and nothing is used up.
|
|
31
52
|
*/
|
|
32
|
-
export declare function announceUpdate(ctx: CliContext, notice: ToolchainNoticeData | null
|
|
53
|
+
export declare function announceUpdate(ctx: CliContext, notice: ToolchainNoticeData | null, options?: {
|
|
54
|
+
env?: Record<string, string | undefined>;
|
|
55
|
+
}): void;
|
package/dist/update-notice.js
CHANGED
|
@@ -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.
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
|
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.
|
|
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
|
-
|
|
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(
|
|
81
|
-
return session ? { host
|
|
104
|
+
const session = store.read(host);
|
|
105
|
+
return session ? { host, session } : null;
|
|
82
106
|
}
|
|
83
|
-
catch (
|
|
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
|
|
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 <
|
|
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
|
-
|
|
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
|
|
150
|
-
if (compareVersions(
|
|
197
|
+
const installed = cliVersion();
|
|
198
|
+
if (compareVersions(installed, target.cli) >= 0)
|
|
151
199
|
return null;
|
|
152
|
-
const status = minimum && compareVersions(
|
|
200
|
+
const status = minimum && compareVersions(installed, minimum.cli) < 0
|
|
153
201
|
? 'unsupported'
|
|
154
202
|
: 'behind';
|
|
155
203
|
return {
|
|
156
204
|
status,
|
|
157
|
-
current: { cli:
|
|
205
|
+
current: { cli: installed },
|
|
158
206
|
target,
|
|
159
207
|
upgradeCommand: 'ekanos upgrade',
|
|
160
208
|
};
|
|
161
209
|
}
|
|
162
210
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
|
|
167
|
-
|
|
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
|