@ekanos/cli 0.30.0 → 0.32.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 +4 -3
- package/dist/commands/apps.d.ts +10 -0
- package/dist/commands/apps.js +39 -12
- package/dist/commands/apps.js.map +1 -1
- package/dist/commands/contract.js +12 -11
- package/dist/commands/contract.js.map +1 -1
- package/dist/commands/dev.js +1 -0
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.d.ts +29 -0
- package/dist/commands/doctor.js +188 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/init.js +3 -0
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/status.js +48 -2
- package/dist/commands/status.js.map +1 -1
- package/dist/contract-verification.d.ts +20 -0
- package/dist/contract-verification.js +49 -0
- package/dist/contract-verification.js.map +1 -0
- package/dist/doctor-api.d.ts +41 -0
- package/dist/doctor-api.js +79 -0
- package/dist/doctor-api.js.map +1 -0
- package/dist/feedback-context.js +1 -0
- package/dist/feedback-context.js.map +1 -1
- package/dist/host-snapshots.d.ts +7 -1
- package/dist/host-snapshots.js +15 -2
- package/dist/host-snapshots.js.map +1 -1
- package/dist/index.js +35 -1
- package/dist/index.js.map +1 -1
- package/dist/project.js +12 -0
- package/dist/project.js.map +1 -1
- package/dist/toolchain-snapshot.d.ts +36 -0
- package/dist/toolchain-snapshot.js +144 -0
- package/dist/toolchain-snapshot.js.map +1 -0
- package/dist/validate-findings.js +10 -1
- package/dist/validate-findings.js.map +1 -1
- package/package.json +2 -2
- package/templates/AGENTS.md.tmpl +1 -1
- package/templates/experience/package.json.tmpl +4 -4
- package/templates/package.json.tmpl +4 -4
- package/templates/src/integration.ts.tmpl +5 -56
- package/templates/src/widget.ts.tmpl +65 -0
package/dist/host-snapshots.js
CHANGED
|
@@ -8,6 +8,7 @@ import { CliError } from './errors.js';
|
|
|
8
8
|
import { listSubmissions } from './publish-api.js';
|
|
9
9
|
import { fetchSeatsWithOneRefresh } from './seats.js';
|
|
10
10
|
import { resolveSourceTarget } from './source-target.js';
|
|
11
|
+
import { createToolchainReader, writeToolchainSnapshot, } from './toolchain-snapshot.js';
|
|
11
12
|
/**
|
|
12
13
|
* What `ekanos dev` hands the harness about the host, beside the session
|
|
13
14
|
* catalog: the catalog a developer browses (`catalog.json`) and the Source's
|
|
@@ -233,7 +234,9 @@ export function nextRefreshDelay(publish) {
|
|
|
233
234
|
/**
|
|
234
235
|
* Keep both snapshots fresh while the harness runs: read now, then again on a
|
|
235
236
|
* timer (30 s while a version is in flight, 5 min otherwise) and whenever the
|
|
236
|
-
* harness writes `.ekanos/refresh-request`.
|
|
237
|
+
* harness writes `.ekanos/refresh-request`. The toolchain snapshot rides the
|
|
238
|
+
* same cycle, after the host read so it uses the session that read refreshed.
|
|
239
|
+
* Returns a stop function.
|
|
237
240
|
*/
|
|
238
241
|
export function startHostSnapshotRefresher(params) {
|
|
239
242
|
const dir = path.join(params.projectDir, '.ekanos');
|
|
@@ -241,7 +244,10 @@ export function startHostSnapshotRefresher(params) {
|
|
|
241
244
|
let stopped = false;
|
|
242
245
|
let running = false;
|
|
243
246
|
let queued = false;
|
|
247
|
+
/** The Refresh button asked: read the versions to be on again too. */
|
|
248
|
+
let fresh = false;
|
|
244
249
|
let timer = null;
|
|
250
|
+
const readToolchain = createToolchainReader(params.toolchainDeps);
|
|
245
251
|
const schedule = (delay) => {
|
|
246
252
|
if (stopped)
|
|
247
253
|
return;
|
|
@@ -264,6 +270,11 @@ export function startHostSnapshotRefresher(params) {
|
|
|
264
270
|
if (!stopped)
|
|
265
271
|
writeHostSnapshots(params.projectDir, snapshots);
|
|
266
272
|
delay = nextRefreshDelay(snapshots.publish);
|
|
273
|
+
const asked = fresh;
|
|
274
|
+
fresh = false;
|
|
275
|
+
const toolchain = await readToolchain(Object.assign(Object.assign({ ctx: params.ctx, env: params.env, projectDir: params.projectDir }, (params.packageDirs ? { packageDirs: params.packageDirs } : {})), { fresh: asked }));
|
|
276
|
+
if (!stopped)
|
|
277
|
+
writeToolchainSnapshot(params.projectDir, toolchain);
|
|
267
278
|
}
|
|
268
279
|
catch (error) {
|
|
269
280
|
params.ctx.log(params.ctx.ui.dim(`Could not refresh the catalog and publish status: ${messageOf(error)}`));
|
|
@@ -281,8 +292,10 @@ export function startHostSnapshotRefresher(params) {
|
|
|
281
292
|
let watcher = null;
|
|
282
293
|
try {
|
|
283
294
|
watcher = fs.watch(dir, (_event, filename) => {
|
|
284
|
-
if (filename === REFRESH_REQUEST_FILE)
|
|
295
|
+
if (filename === REFRESH_REQUEST_FILE) {
|
|
296
|
+
fresh = true;
|
|
285
297
|
void refresh();
|
|
298
|
+
}
|
|
286
299
|
});
|
|
287
300
|
watcher.unref();
|
|
288
301
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-snapshots.js","sourceRoot":"","sources":["../src/host-snapshots.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,qBAAqB,EACrB,2BAA2B,EAG3B,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAEL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,c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AAK,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,CAAC,GAAG,CACZ,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CACf,qDAAqD,SAAS,CAAC,KAAK,CAAC,EAAE,CACxE,CACF,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC;QACD,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,GAAG,KAAK,CAAC;YACf,KAAK,OAAO,EAAE,CAAC;YACf,OAAO;QACT,CAAC;QACD,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC;IAEF,IAAI,OAAO,GAAwB,IAAI,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE;YAC3C,IAAI,QAAQ,KAAK,oBAAoB;gBAAE,KAAK,OAAO,EAAE,CAAC;QACxD,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,GAAG,CAAC,GAAG,CACZ,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CACf,mEAAmE,SAAS,CAAC,KAAK,CAAC,EAAE,CACtF,CACF,CAAC;IACJ,CAAC;IAED,KAAK,OAAO,EAAE,CAAC;IAEf,OAAO,GAAG,EAAE;QACV,OAAO,GAAG,IAAI,CAAC;QACf,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type CatalogProduct,\n type CatalogSnapshot,\n CatalogSnapshotSchema,\n PublishStatusSnapshotSchema,\n type PublishStatusSnapshot,\n type PublishedPackage,\n SourceSelectionSchema,\n} from '@ekanos/integration-schema';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { StoredSession } from './auth/credential-store';\nimport {\n type AuthEnvironment,\n refreshStoredSession,\n resolveAuthEnvironment,\n} from './auth/session';\nimport { fetchPublicCatalog, fetchSourceCatalog } from './catalog-api';\nimport { readActiveSource } from './commands/sources';\nimport type { CliContext } from './context';\nimport { CliError } from './errors';\nimport { listSubmissions } from './publish-api';\nimport { fetchSeatsWithOneRefresh } from './seats';\nimport { resolveSourceTarget } from './source-target';\n\n/**\n * What `ekanos dev` hands the harness about the host, beside the session\n * catalog: the catalog a developer browses (`catalog.json`) and the Source's\n * published packages (`publish-status.json`). The CLI holds the login, so the\n * harness never sees a token and never refreshes one (a second refresher would\n * race the CLI for the rotating refresh token). The harness asks for a fresh\n * read by writing `refresh-request`.\n */\nexport const CATALOG_SNAPSHOT_FILE = path.join('.ekanos', 'catalog.json');\nexport const PUBLISH_STATUS_FILE = path.join('.ekanos', 'publish-status.json');\nexport const REFRESH_REQUEST_FILE = 'refresh-request';\n/**\n * The Source the harness's switcher picked (`{ \"source\": \"<slug>\" }`). It\n * decides which Source the harness reads, ahead of ekanos.json, while it is\n * still one of the developer's seats; it never changes where `publish` goes.\n */\nexport const SOURCE_SELECTION_FILE = path.join(\n '.ekanos',\n 'source-selection.json',\n);\n\n/** Poll fast while a version is still moving through the pipeline. */\nconst IN_FLIGHT_STATES = new Set(['submitted', 'gated']);\nexport const IN_FLIGHT_INTERVAL_MS = 30_000;\nexport const IDLE_INTERVAL_MS = 300_000;\n\ntype Unavailable = NonNullable<CatalogSnapshot['unavailable']>;\n\nexport interface HostSnapshots {\n catalog: CatalogSnapshot;\n publish: PublishStatusSnapshot;\n}\n\n/** The network calls, injectable for tests. */\nexport interface HostSnapshotDeps {\n fetchSourceCatalog: typeof fetchSourceCatalog;\n fetchPublicCatalog: typeof fetchPublicCatalog;\n listSubmissions: typeof listSubmissions;\n fetchSeats: typeof fetchSeatsWithOneRefresh;\n resolveSourceTarget: typeof resolveSourceTarget;\n refreshStoredSession: typeof refreshStoredSession;\n now: () => Date;\n}\n\nconst DEFAULT_DEPS: HostSnapshotDeps = {\n fetchSourceCatalog,\n fetchPublicCatalog,\n listSubmissions,\n fetchSeats: fetchSeatsWithOneRefresh,\n resolveSourceTarget,\n refreshStoredSession,\n now: () => new Date(),\n};\n\nfunction messageOf(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/** The error's message and, for a CLI error, what to do about it. */\nfunction messageWithHint(error: unknown): string {\n if (error instanceof CliError) return `${error.message} ${error.hint}`;\n return messageOf(error);\n}\n\n/**\n * Read both snapshots from the host, never throwing: every way it can fail is\n * written down as `unavailable`, in words the harness shows as is.\n */\nexport async function readHostSnapshots(params: {\n ctx: CliContext;\n env: Record<string, string | undefined>;\n projectDir: string;\n /** The Source to read when the project itself names none (a repo's packages' shared one). */\n fallbackSource?: string | null;\n deps?: Partial<HostSnapshotDeps>;\n}): Promise<HostSnapshots> {\n const deps = { ...DEFAULT_DEPS, ...params.deps };\n const fetchedAt = deps.now().toISOString();\n /** The developer's seats, once read: the harness's switcher offers them. */\n let seats: Array<{ slug: string; name: string | null }> | undefined;\n\n const empty = (\n host: string | null,\n unavailable: Unavailable | null,\n ): HostSnapshots => ({\n catalog: {\n fetchedAt,\n host,\n scope: null,\n source: null,\n unavailable,\n products: [],\n ...(seats ? { seats } : {}),\n },\n publish: {\n fetchedAt,\n host,\n source: null,\n unavailable,\n packages: [],\n },\n });\n\n let auth: AuthEnvironment;\n try {\n auth = resolveAuthEnvironment(params.ctx, undefined, params.env, {\n projectDir: params.projectDir,\n });\n } catch {\n return empty(null, {\n reason: 'not-logged-in',\n message:\n 'No Ekanos host is known for this project. Run \"ekanos login\" to see the catalog and your publishes.',\n });\n }\n const host = auth.host;\n\n /** The host's public catalog, for a developer with no Source to read. */\n const publicCatalog = async (\n unavailable: Unavailable,\n ): Promise<HostSnapshots> => {\n const result = empty(host, unavailable);\n try {\n const catalog = await deps.fetchPublicCatalog(host);\n if (catalog) {\n result.catalog = {\n ...result.catalog,\n scope: 'public',\n unavailable: null,\n products: catalog.products,\n };\n }\n } catch (error) {\n result.catalog.unavailable = {\n reason: 'host-error',\n message: `Could not read the public catalog from ${host}: ${messageOf(error)}`,\n };\n }\n return result;\n };\n\n let session: StoredSession | null = auth.store.read(host);\n if (!session) {\n return publicCatalog({\n reason: 'not-logged-in',\n message: `Not logged in to ${host}. Run \"ekanos login\" to see your Source's catalog and your publishes.`,\n });\n }\n\n // The seats, for the switcher and to hold the harness's pick to one. A\n // failed read only leaves the switcher out; the catalog route still checks.\n try {\n const listed = await deps.fetchSeats(auth, session);\n if (listed.status === 'ok') {\n session = listed.session;\n seats = listed.sources.map((seat) => ({\n slug: seat.slug,\n name: seat.name,\n }));\n }\n } catch {\n seats = undefined;\n }\n const selected = readSourceSelection(params.projectDir);\n const picked =\n selected && seats?.some((seat) => seat.slug === selected) ? selected : null;\n\n let source: string;\n try {\n const target = await deps.resolveSourceTarget(auth, session, {\n dir: params.projectDir,\n ...(picked\n ? { source: picked }\n : params.fallbackSource && !readActiveSource(params.projectDir)\n ? { source: params.fallbackSource }\n : {}),\n });\n source = target.source;\n session = target.session;\n } catch (error) {\n return publicCatalog({\n reason: 'no-source',\n message: messageWithHint(error),\n });\n }\n\n /** One call, retried once with a refreshed session on a 401. */\n async function withSession<T extends { status: string }>(\n call: (token: string) => Promise<T>,\n ): Promise<T> {\n const current = session!;\n const first = await call(current.accessToken);\n if (first.status !== 'unauthorized') return first;\n session = await deps.refreshStoredSession(auth, current);\n return call(session.accessToken);\n }\n\n const result = empty(host, null);\n result.publish.source = source;\n\n try {\n const catalog = await withSession((token) =>\n deps.fetchSourceCatalog(host, token, { source }),\n );\n if (catalog.status === 'ok') {\n result.catalog = {\n fetchedAt,\n host,\n scope: 'source',\n source: {\n slug: catalog.catalog.source.slug,\n name: catalog.catalog.source.name,\n },\n unavailable: null,\n products: catalog.catalog.products satisfies CatalogProduct[],\n ...(seats ? { seats } : {}),\n };\n } else {\n result.catalog.unavailable = {\n reason: 'not-logged-in',\n message: `The session for ${host} has expired. Run \"ekanos login\".`,\n };\n }\n } catch (error) {\n result.catalog.unavailable = {\n reason: 'host-error',\n message: `Could not read the catalog for ${source}: ${messageOf(error)}`,\n };\n }\n\n try {\n const listed = await withSession((token) =>\n deps.listSubmissions(host, token, source, { detail: 'findings' }),\n );\n if (listed.status === 'ok') {\n result.publish.packages = listed.integrations as PublishedPackage[];\n } else {\n result.publish.unavailable = {\n reason: 'not-logged-in',\n message: `The session for ${host} has expired. Run \"ekanos login\".`,\n };\n }\n } catch (error) {\n result.publish.unavailable = {\n reason: 'host-error',\n message: `Could not read the publishes for ${source}: ${messageOf(error)}`,\n };\n }\n\n return result;\n}\n\n/** The Source the harness's switcher picked, or null. Never throws. */\nexport function readSourceSelection(projectDir: string): string | null {\n try {\n const parsed = SourceSelectionSchema.safeParse(\n JSON.parse(\n fs.readFileSync(path.join(projectDir, SOURCE_SELECTION_FILE), 'utf8'),\n ),\n );\n return parsed.success ? parsed.data.source : null;\n } catch {\n return null;\n }\n}\n\n/**\n * The one Source every package of a repo names in its `ekanos.json`, or null\n * when they name none or disagree (then the account's seats decide, as for\n * any project).\n */\nexport function sharedPackageSource(dirs: readonly string[]): string | null {\n const named = new Set(\n dirs.map((dir) => readActiveSource(dir)).filter((v): v is string => !!v),\n );\n return named.size === 1 ? [...named][0]! : null;\n}\n\n/** Write both snapshots for the harness, owner-only, never a token. */\nexport function writeHostSnapshots(\n projectDir: string,\n snapshots: HostSnapshots,\n): void {\n const write = (file: string, value: unknown) => {\n const target = path.join(projectDir, file);\n fs.mkdirSync(path.dirname(target), { recursive: true });\n const temp = `${target}.tmp`;\n fs.writeFileSync(temp, `${JSON.stringify(value)}\\n`, { mode: 0o600 });\n fs.renameSync(temp, target);\n };\n const catalog = CatalogSnapshotSchema.safeParse(snapshots.catalog);\n if (catalog.success) write(CATALOG_SNAPSHOT_FILE, catalog.data);\n const publish = PublishStatusSnapshotSchema.safeParse(snapshots.publish);\n if (publish.success) write(PUBLISH_STATUS_FILE, publish.data);\n}\n\n/** How long to wait before the next read: fast while a version is in flight. */\nexport function nextRefreshDelay(publish: PublishStatusSnapshot): number {\n const inFlight = publish.packages.some((pkg) =>\n pkg.versions.some((version) => IN_FLIGHT_STATES.has(version.state)),\n );\n return inFlight ? IN_FLIGHT_INTERVAL_MS : IDLE_INTERVAL_MS;\n}\n\n/**\n * Keep both snapshots fresh while the harness runs: read now, then again on a\n * timer (30 s while a version is in flight, 5 min otherwise) and whenever the\n * harness writes `.ekanos/refresh-request`. Returns a stop function.\n */\nexport function startHostSnapshotRefresher(params: {\n ctx: CliContext;\n env: Record<string, string | undefined>;\n projectDir: string;\n fallbackSource?: string | null;\n deps?: Partial<HostSnapshotDeps>;\n}): () => void {\n const dir = path.join(params.projectDir, '.ekanos');\n fs.mkdirSync(dir, { recursive: true });\n\n let stopped = false;\n let running = false;\n let queued = false;\n let timer: NodeJS.Timeout | null = null;\n\n const schedule = (delay: number) => {\n if (stopped) return;\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => void refresh(), delay);\n timer.unref();\n };\n\n const refresh = async () => {\n if (stopped) return;\n if (running) {\n queued = true;\n return;\n }\n running = true;\n let delay = IDLE_INTERVAL_MS;\n try {\n const snapshots = await readHostSnapshots(params);\n if (!stopped) writeHostSnapshots(params.projectDir, snapshots);\n delay = nextRefreshDelay(snapshots.publish);\n } catch (error) {\n params.ctx.log(\n params.ctx.ui.dim(\n `Could not refresh the catalog and publish status: ${messageOf(error)}`,\n ),\n );\n } finally {\n running = false;\n }\n if (queued) {\n queued = false;\n void refresh();\n return;\n }\n schedule(delay);\n };\n\n let watcher: fs.FSWatcher | null = null;\n try {\n watcher = fs.watch(dir, (_event, filename) => {\n if (filename === REFRESH_REQUEST_FILE) void refresh();\n });\n watcher.unref();\n } catch (error) {\n params.ctx.log(\n params.ctx.ui.dim(\n `The harness's Refresh button will wait for the next timed read: ${messageOf(error)}`,\n ),\n );\n }\n\n void refresh();\n\n return () => {\n stopped = true;\n if (timer) clearTimeout(timer);\n watcher?.close();\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"host-snapshots.js","sourceRoot":"","sources":["../src/host-snapshots.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,qBAAqB,EACrB,2BAA2B,EAG3B,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAEL,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAEL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,qBAAqB,CAAC,CAAC;AAC/E,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AACtD;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC,IAAI,CAC5C,SAAS,EACT,uBAAuB,CACxB,CAAC;AAEF,sEAAsE;AACtE,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAA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AAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import {\n type CatalogProduct,\n type CatalogSnapshot,\n CatalogSnapshotSchema,\n PublishStatusSnapshotSchema,\n type PublishStatusSnapshot,\n type PublishedPackage,\n SourceSelectionSchema,\n} from '@ekanos/integration-schema';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { StoredSession } from './auth/credential-store';\nimport {\n type AuthEnvironment,\n refreshStoredSession,\n resolveAuthEnvironment,\n} from './auth/session';\nimport { fetchPublicCatalog, fetchSourceCatalog } from './catalog-api';\nimport { readActiveSource } from './commands/sources';\nimport type { CliContext } from './context';\nimport { CliError } from './errors';\nimport { listSubmissions } from './publish-api';\nimport { fetchSeatsWithOneRefresh } from './seats';\nimport { resolveSourceTarget } from './source-target';\nimport {\n type ToolchainSnapshotDeps,\n createToolchainReader,\n writeToolchainSnapshot,\n} from './toolchain-snapshot';\n\n/**\n * What `ekanos dev` hands the harness about the host, beside the session\n * catalog: the catalog a developer browses (`catalog.json`) and the Source's\n * published packages (`publish-status.json`). The CLI holds the login, so the\n * harness never sees a token and never refreshes one (a second refresher would\n * race the CLI for the rotating refresh token). The harness asks for a fresh\n * read by writing `refresh-request`.\n */\nexport const CATALOG_SNAPSHOT_FILE = path.join('.ekanos', 'catalog.json');\nexport const PUBLISH_STATUS_FILE = path.join('.ekanos', 'publish-status.json');\nexport const REFRESH_REQUEST_FILE = 'refresh-request';\n/**\n * The Source the harness's switcher picked (`{ \"source\": \"<slug>\" }`). It\n * decides which Source the harness reads, ahead of ekanos.json, while it is\n * still one of the developer's seats; it never changes where `publish` goes.\n */\nexport const SOURCE_SELECTION_FILE = path.join(\n '.ekanos',\n 'source-selection.json',\n);\n\n/** Poll fast while a version is still moving through the pipeline. */\nconst IN_FLIGHT_STATES = new Set(['submitted', 'gated']);\nexport const IN_FLIGHT_INTERVAL_MS = 30_000;\nexport const IDLE_INTERVAL_MS = 300_000;\n\ntype Unavailable = NonNullable<CatalogSnapshot['unavailable']>;\n\nexport interface HostSnapshots {\n catalog: CatalogSnapshot;\n publish: PublishStatusSnapshot;\n}\n\n/** The network calls, injectable for tests. */\nexport interface HostSnapshotDeps {\n fetchSourceCatalog: typeof fetchSourceCatalog;\n fetchPublicCatalog: typeof fetchPublicCatalog;\n listSubmissions: typeof listSubmissions;\n fetchSeats: typeof fetchSeatsWithOneRefresh;\n resolveSourceTarget: typeof resolveSourceTarget;\n refreshStoredSession: typeof refreshStoredSession;\n now: () => Date;\n}\n\nconst DEFAULT_DEPS: HostSnapshotDeps = {\n fetchSourceCatalog,\n fetchPublicCatalog,\n listSubmissions,\n fetchSeats: fetchSeatsWithOneRefresh,\n resolveSourceTarget,\n refreshStoredSession,\n now: () => new Date(),\n};\n\nfunction messageOf(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/** The error's message and, for a CLI error, what to do about it. */\nfunction messageWithHint(error: unknown): string {\n if (error instanceof CliError) return `${error.message} ${error.hint}`;\n return messageOf(error);\n}\n\n/**\n * Read both snapshots from the host, never throwing: every way it can fail is\n * written down as `unavailable`, in words the harness shows as is.\n */\nexport async function readHostSnapshots(params: {\n ctx: CliContext;\n env: Record<string, string | undefined>;\n projectDir: string;\n /** The Source to read when the project itself names none (a repo's packages' shared one). */\n fallbackSource?: string | null;\n deps?: Partial<HostSnapshotDeps>;\n}): Promise<HostSnapshots> {\n const deps = { ...DEFAULT_DEPS, ...params.deps };\n const fetchedAt = deps.now().toISOString();\n /** The developer's seats, once read: the harness's switcher offers them. */\n let seats: Array<{ slug: string; name: string | null }> | undefined;\n\n const empty = (\n host: string | null,\n unavailable: Unavailable | null,\n ): HostSnapshots => ({\n catalog: {\n fetchedAt,\n host,\n scope: null,\n source: null,\n unavailable,\n products: [],\n ...(seats ? { seats } : {}),\n },\n publish: {\n fetchedAt,\n host,\n source: null,\n unavailable,\n packages: [],\n },\n });\n\n let auth: AuthEnvironment;\n try {\n auth = resolveAuthEnvironment(params.ctx, undefined, params.env, {\n projectDir: params.projectDir,\n });\n } catch {\n return empty(null, {\n reason: 'not-logged-in',\n message:\n 'No Ekanos host is known for this project. Run \"ekanos login\" to see the catalog and your publishes.',\n });\n }\n const host = auth.host;\n\n /** The host's public catalog, for a developer with no Source to read. */\n const publicCatalog = async (\n unavailable: Unavailable,\n ): Promise<HostSnapshots> => {\n const result = empty(host, unavailable);\n try {\n const catalog = await deps.fetchPublicCatalog(host);\n if (catalog) {\n result.catalog = {\n ...result.catalog,\n scope: 'public',\n unavailable: null,\n products: catalog.products,\n };\n }\n } catch (error) {\n result.catalog.unavailable = {\n reason: 'host-error',\n message: `Could not read the public catalog from ${host}: ${messageOf(error)}`,\n };\n }\n return result;\n };\n\n let session: StoredSession | null = auth.store.read(host);\n if (!session) {\n return publicCatalog({\n reason: 'not-logged-in',\n message: `Not logged in to ${host}. Run \"ekanos login\" to see your Source's catalog and your publishes.`,\n });\n }\n\n // The seats, for the switcher and to hold the harness's pick to one. A\n // failed read only leaves the switcher out; the catalog route still checks.\n try {\n const listed = await deps.fetchSeats(auth, session);\n if (listed.status === 'ok') {\n session = listed.session;\n seats = listed.sources.map((seat) => ({\n slug: seat.slug,\n name: seat.name,\n }));\n }\n } catch {\n seats = undefined;\n }\n const selected = readSourceSelection(params.projectDir);\n const picked =\n selected && seats?.some((seat) => seat.slug === selected) ? selected : null;\n\n let source: string;\n try {\n const target = await deps.resolveSourceTarget(auth, session, {\n dir: params.projectDir,\n ...(picked\n ? { source: picked }\n : params.fallbackSource && !readActiveSource(params.projectDir)\n ? { source: params.fallbackSource }\n : {}),\n });\n source = target.source;\n session = target.session;\n } catch (error) {\n return publicCatalog({\n reason: 'no-source',\n message: messageWithHint(error),\n });\n }\n\n /** One call, retried once with a refreshed session on a 401. */\n async function withSession<T extends { status: string }>(\n call: (token: string) => Promise<T>,\n ): Promise<T> {\n const current = session!;\n const first = await call(current.accessToken);\n if (first.status !== 'unauthorized') return first;\n session = await deps.refreshStoredSession(auth, current);\n return call(session.accessToken);\n }\n\n const result = empty(host, null);\n result.publish.source = source;\n\n try {\n const catalog = await withSession((token) =>\n deps.fetchSourceCatalog(host, token, { source }),\n );\n if (catalog.status === 'ok') {\n result.catalog = {\n fetchedAt,\n host,\n scope: 'source',\n source: {\n slug: catalog.catalog.source.slug,\n name: catalog.catalog.source.name,\n },\n unavailable: null,\n products: catalog.catalog.products satisfies CatalogProduct[],\n ...(seats ? { seats } : {}),\n };\n } else {\n result.catalog.unavailable = {\n reason: 'not-logged-in',\n message: `The session for ${host} has expired. Run \"ekanos login\".`,\n };\n }\n } catch (error) {\n result.catalog.unavailable = {\n reason: 'host-error',\n message: `Could not read the catalog for ${source}: ${messageOf(error)}`,\n };\n }\n\n try {\n const listed = await withSession((token) =>\n deps.listSubmissions(host, token, source, { detail: 'findings' }),\n );\n if (listed.status === 'ok') {\n result.publish.packages = listed.integrations as PublishedPackage[];\n } else {\n result.publish.unavailable = {\n reason: 'not-logged-in',\n message: `The session for ${host} has expired. Run \"ekanos login\".`,\n };\n }\n } catch (error) {\n result.publish.unavailable = {\n reason: 'host-error',\n message: `Could not read the publishes for ${source}: ${messageOf(error)}`,\n };\n }\n\n return result;\n}\n\n/** The Source the harness's switcher picked, or null. Never throws. */\nexport function readSourceSelection(projectDir: string): string | null {\n try {\n const parsed = SourceSelectionSchema.safeParse(\n JSON.parse(\n fs.readFileSync(path.join(projectDir, SOURCE_SELECTION_FILE), 'utf8'),\n ),\n );\n return parsed.success ? parsed.data.source : null;\n } catch {\n return null;\n }\n}\n\n/**\n * The one Source every package of a repo names in its `ekanos.json`, or null\n * when they name none or disagree (then the account's seats decide, as for\n * any project).\n */\nexport function sharedPackageSource(dirs: readonly string[]): string | null {\n const named = new Set(\n dirs.map((dir) => readActiveSource(dir)).filter((v): v is string => !!v),\n );\n return named.size === 1 ? [...named][0]! : null;\n}\n\n/** Write both snapshots for the harness, owner-only, never a token. */\nexport function writeHostSnapshots(\n projectDir: string,\n snapshots: HostSnapshots,\n): void {\n const write = (file: string, value: unknown) => {\n const target = path.join(projectDir, file);\n fs.mkdirSync(path.dirname(target), { recursive: true });\n const temp = `${target}.tmp`;\n fs.writeFileSync(temp, `${JSON.stringify(value)}\\n`, { mode: 0o600 });\n fs.renameSync(temp, target);\n };\n const catalog = CatalogSnapshotSchema.safeParse(snapshots.catalog);\n if (catalog.success) write(CATALOG_SNAPSHOT_FILE, catalog.data);\n const publish = PublishStatusSnapshotSchema.safeParse(snapshots.publish);\n if (publish.success) write(PUBLISH_STATUS_FILE, publish.data);\n}\n\n/** How long to wait before the next read: fast while a version is in flight. */\nexport function nextRefreshDelay(publish: PublishStatusSnapshot): number {\n const inFlight = publish.packages.some((pkg) =>\n pkg.versions.some((version) => IN_FLIGHT_STATES.has(version.state)),\n );\n return inFlight ? IN_FLIGHT_INTERVAL_MS : IDLE_INTERVAL_MS;\n}\n\n/**\n * Keep both snapshots fresh while the harness runs: read now, then again on a\n * timer (30 s while a version is in flight, 5 min otherwise) and whenever the\n * harness writes `.ekanos/refresh-request`. The toolchain snapshot rides the\n * same cycle, after the host read so it uses the session that read refreshed.\n * Returns a stop function.\n */\nexport function startHostSnapshotRefresher(params: {\n ctx: CliContext;\n env: Record<string, string | undefined>;\n projectDir: string;\n fallbackSource?: string | null;\n /** A repo's package directories, for the toolchain versions they install. */\n packageDirs?: readonly string[];\n deps?: Partial<HostSnapshotDeps>;\n toolchainDeps?: Partial<ToolchainSnapshotDeps>;\n}): () => void {\n const dir = path.join(params.projectDir, '.ekanos');\n fs.mkdirSync(dir, { recursive: true });\n\n let stopped = false;\n let running = false;\n let queued = false;\n /** The Refresh button asked: read the versions to be on again too. */\n let fresh = false;\n let timer: NodeJS.Timeout | null = null;\n const readToolchain = createToolchainReader(params.toolchainDeps);\n\n const schedule = (delay: number) => {\n if (stopped) return;\n if (timer) clearTimeout(timer);\n timer = setTimeout(() => void refresh(), delay);\n timer.unref();\n };\n\n const refresh = async () => {\n if (stopped) return;\n if (running) {\n queued = true;\n return;\n }\n running = true;\n let delay = IDLE_INTERVAL_MS;\n try {\n const snapshots = await readHostSnapshots(params);\n if (!stopped) writeHostSnapshots(params.projectDir, snapshots);\n delay = nextRefreshDelay(snapshots.publish);\n const asked = fresh;\n fresh = false;\n const toolchain = await readToolchain({\n ctx: params.ctx,\n env: params.env,\n projectDir: params.projectDir,\n ...(params.packageDirs ? { packageDirs: params.packageDirs } : {}),\n fresh: asked,\n });\n if (!stopped) writeToolchainSnapshot(params.projectDir, toolchain);\n } catch (error) {\n params.ctx.log(\n params.ctx.ui.dim(\n `Could not refresh the catalog and publish status: ${messageOf(error)}`,\n ),\n );\n } finally {\n running = false;\n }\n if (queued) {\n queued = false;\n void refresh();\n return;\n }\n schedule(delay);\n };\n\n let watcher: fs.FSWatcher | null = null;\n try {\n watcher = fs.watch(dir, (_event, filename) => {\n if (filename === REFRESH_REQUEST_FILE) {\n fresh = true;\n void refresh();\n }\n });\n watcher.unref();\n } catch (error) {\n params.ctx.log(\n params.ctx.ui.dim(\n `The harness's Refresh button will wait for the next timed read: ${messageOf(error)}`,\n ),\n );\n }\n\n void refresh();\n\n return () => {\n stopped = true;\n if (timer) clearTimeout(timer);\n watcher?.close();\n };\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { runApps } from './commands/apps.js';
|
|
|
18
18
|
import { runAudiences } from './commands/audiences.js';
|
|
19
19
|
import { runCatalog } from './commands/catalog.js';
|
|
20
20
|
import { runDev } from './commands/dev.js';
|
|
21
|
+
import { runDoctor } from './commands/doctor.js';
|
|
21
22
|
import { runFeedback } from './commands/feedback.js';
|
|
22
23
|
import { EXPERIENCE_COMMANDS } from './commands/index-experience.js';
|
|
23
24
|
import { runInit } from './commands/init.js';
|
|
@@ -305,6 +306,19 @@ const COMMAND_SPECS = {
|
|
|
305
306
|
description: "not only SDK packages: the Source's in-repo integrations and Features too",
|
|
306
307
|
},
|
|
307
308
|
},
|
|
309
|
+
doctor: {
|
|
310
|
+
host: HOST,
|
|
311
|
+
source: SOURCE,
|
|
312
|
+
dir: DIR,
|
|
313
|
+
team: {
|
|
314
|
+
type: 'string',
|
|
315
|
+
description: "The team's slug: also check the connection each integration resolves to, as you",
|
|
316
|
+
},
|
|
317
|
+
kind: {
|
|
318
|
+
type: 'string',
|
|
319
|
+
description: 'integration or experience (else the host is asked as each)',
|
|
320
|
+
},
|
|
321
|
+
},
|
|
308
322
|
apps: Object.assign({ host: HOST, source: SOURCE, dir: DIR, 'no-wait': {
|
|
309
323
|
type: 'boolean',
|
|
310
324
|
description: 'connect: print the links and return without waiting',
|
|
@@ -823,6 +837,7 @@ const POSITIONAL_COMMANDS = {
|
|
|
823
837
|
// `sources scopes add <scope> <product>` is the longest form.
|
|
824
838
|
sources: ['subcommand', 'verb', 'product-or-scope', 'product-slug'],
|
|
825
839
|
catalog: ['product-slug'],
|
|
840
|
+
doctor: ['token-or-ref'],
|
|
826
841
|
audiences: ['subcommand', 'audience'],
|
|
827
842
|
apps: ['subcommand', 'product-slug'],
|
|
828
843
|
// `teams agents policy <team> <key> set <tool> auto` is the longest form.
|
|
@@ -927,6 +942,15 @@ const USAGE = [
|
|
|
927
942
|
' Features); one product shows its tools with their inputs and',
|
|
928
943
|
' whose connection agent runs use',
|
|
929
944
|
' ("ekanos catalog [<product-slug>] --source <slug> [--all]", --json)',
|
|
945
|
+
' doctor Whether a published integration or experience resolves on the',
|
|
946
|
+
' host, check by check, without calling it: registry, contract,',
|
|
947
|
+
' product row, visibility, entitlement, release, and for an',
|
|
948
|
+
' experience each integration it uses with the refusal the',
|
|
949
|
+
' executor would give. Lists the OAuth redirect URI each',
|
|
950
|
+
' connection expects and warns where the stored one drifted.',
|
|
951
|
+
' Exit 1 when it is not ready',
|
|
952
|
+
' ("ekanos doctor <token-or-ref> [--team <slug>] [--source <slug>]',
|
|
953
|
+
' [--kind integration|experience]", --json)',
|
|
930
954
|
" apps The Source's app for an integration teams sign in through:",
|
|
931
955
|
' show <product> | set <product> (Source admin; takes the secret',
|
|
932
956
|
' at your terminal, Enter keeps a saved value; without one,',
|
|
@@ -1182,7 +1206,7 @@ const USAGE = [
|
|
|
1182
1206
|
' bare "ekanos upgrade" MUTATES the project (installs the target versions,',
|
|
1183
1207
|
' verifies with validate + the test script, rolls back on any failure).',
|
|
1184
1208
|
'',
|
|
1185
|
-
'Host resolution (logout, whoami, status, sources, catalog, apps, teams, names, reviewers, routes, agents, skills, knowledge, runs, approvals, workflows, use, publish, upgrade, feedback):',
|
|
1209
|
+
'Host resolution (logout, whoami, status, sources, catalog, doctor, apps, teams, names, reviewers, routes, agents, skills, knowledge, runs, approvals, workflows, use, publish, upgrade, feedback):',
|
|
1186
1210
|
' --host, else EKANOS_HOST, else the "host" field in ekanos.json, else the',
|
|
1187
1211
|
' sole stored login. "ekanos publish" saves host and source to ekanos.json.',
|
|
1188
1212
|
' "ekanos login" never reads ekanos.json for a host (--host, else',
|
|
@@ -1474,6 +1498,16 @@ async function dispatch(argv, options, ctx, cwd, env, trace) {
|
|
|
1474
1498
|
dir,
|
|
1475
1499
|
env,
|
|
1476
1500
|
});
|
|
1501
|
+
case 'doctor':
|
|
1502
|
+
return await runDoctor(ctx, {
|
|
1503
|
+
host: parsed.flags.host,
|
|
1504
|
+
source: parsed.flags.source,
|
|
1505
|
+
target: parsed.positionals[0],
|
|
1506
|
+
kind: parsed.flags.kind,
|
|
1507
|
+
team: parsed.flags.team,
|
|
1508
|
+
dir,
|
|
1509
|
+
env,
|
|
1510
|
+
});
|
|
1477
1511
|
case 'apps':
|
|
1478
1512
|
return await runApps(ctx, {
|
|
1479
1513
|
host: parsed.flags.host,
|