@ekanos/cli 0.1.4 → 0.1.6
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 +132 -6
- package/dist/bin.js +14 -1
- package/dist/bin.js.map +1 -1
- package/dist/commands/dev.d.ts +4 -0
- package/dist/commands/dev.js +6 -20
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/init.d.ts +25 -0
- package/dist/commands/init.js +19 -8
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/publish.d.ts +59 -1
- package/dist/commands/publish.js +209 -25
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/sources.d.ts +17 -0
- package/dist/commands/sources.js +75 -0
- package/dist/commands/sources.js.map +1 -0
- package/dist/commands/status.js +9 -2
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/upgrade.d.ts +47 -0
- package/dist/commands/upgrade.js +445 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/commands/use.d.ts +21 -0
- package/dist/commands/use.js +62 -0
- package/dist/commands/use.js.map +1 -0
- package/dist/commands/validate.d.ts +5 -0
- package/dist/commands/validate.js +20 -6
- package/dist/commands/validate.js.map +1 -1
- package/dist/commands/whoami.d.ts +6 -0
- package/dist/commands/whoami.js +26 -1
- package/dist/commands/whoami.js.map +1 -1
- package/dist/context.d.ts +9 -0
- package/dist/context.js +9 -0
- package/dist/context.js.map +1 -1
- package/dist/delegate.d.ts +28 -0
- package/dist/delegate.js +136 -0
- package/dist/delegate.js.map +1 -0
- package/dist/harness-scaffold.d.ts +21 -6
- package/dist/harness-scaffold.js +8 -5
- package/dist/harness-scaffold.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +81 -4
- package/dist/index.js.map +1 -1
- package/dist/package-manager.d.ts +10 -0
- package/dist/package-manager.js +32 -0
- package/dist/package-manager.js.map +1 -1
- package/dist/schema-skew.d.ts +77 -0
- package/dist/schema-skew.js +163 -0
- package/dist/schema-skew.js.map +1 -0
- package/dist/seats.d.ts +21 -0
- package/dist/seats.js +15 -0
- package/dist/seats.js.map +1 -0
- package/dist/sources-api.d.ts +44 -0
- package/dist/sources-api.js +69 -0
- package/dist/sources-api.js.map +1 -0
- package/dist/toolchain-api.d.ts +54 -0
- package/dist/toolchain-api.js +58 -0
- package/dist/toolchain-api.js.map +1 -0
- package/dist/toolchain-resolve.d.ts +26 -0
- package/dist/toolchain-resolve.js +100 -0
- package/dist/toolchain-resolve.js.map +1 -0
- package/dist/toolchain.d.ts +21 -0
- package/dist/toolchain.js +16 -0
- package/dist/toolchain.js.map +1 -0
- package/dist/update-notice.d.ts +32 -0
- package/dist/update-notice.js +180 -0
- package/dist/update-notice.js.map +1 -0
- package/dist/validate-findings.d.ts +12 -0
- package/dist/validate-findings.js +12 -0
- package/dist/validate-findings.js.map +1 -1
- package/package.json +1 -1
- package/templates/AGENTS.md.tmpl +81 -18
- package/templates/CLAUDE.md.tmpl +2 -1
- package/templates/claude-skill.md.tmpl +45 -13
package/dist/commands/publish.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { refreshStoredSession, requireSession, resolveAuthEnvironment, } from '../auth/session.js';
|
|
4
|
-
import { gateFailedError, preconditionError, validationError } from '../errors.js';
|
|
4
|
+
import { forbiddenError, gateFailedError, preconditionError, validationError, } from '../errors.js';
|
|
5
5
|
import { packProject } from '../pack.js';
|
|
6
6
|
import { loadProject, serializeProject } from '../project.js';
|
|
7
7
|
import { MAX_MANIFEST_BYTES, stillUnauthorized, submitArchive, } from '../publish-api.js';
|
|
8
|
+
import { assertSchemaNotSkewed } from '../schema-skew.js';
|
|
9
|
+
import { fetchSeatsWithOneRefresh } from '../seats.js';
|
|
10
|
+
import { stillUnauthorizedSourceSeats } from '../sources-api.js';
|
|
11
|
+
import { announceUpdate, checkForUpdate } from '../update-notice.js';
|
|
8
12
|
import { collectAllFindings } from '../validate-findings.js';
|
|
9
13
|
/**
|
|
10
14
|
* `publish` — pack the project and submit it to a Fusion deployment.
|
|
@@ -20,12 +24,33 @@ import { collectAllFindings } from '../validate-findings.js';
|
|
|
20
24
|
* so later publishes need no `--source`.
|
|
21
25
|
*/
|
|
22
26
|
export async function runPublish(ctx, args) {
|
|
27
|
+
var _a, _b;
|
|
23
28
|
const env = resolveAuthEnvironment(ctx, args.host, args.env, {
|
|
24
29
|
projectDir: args.dir,
|
|
25
30
|
});
|
|
26
31
|
const session = requireSession(env.store, env.host);
|
|
27
32
|
const loaded = loadProject(args.dir);
|
|
28
|
-
|
|
33
|
+
// Fail fast, before anything else: a project whose schema is newer than
|
|
34
|
+
// this CLI bundles cannot be trusted to validate correctly, so publishing
|
|
35
|
+
// it — the one verb whose findings gate is meant to be authoritative —
|
|
36
|
+
// must refuse before packing or submitting anything. See `schema-skew.ts`.
|
|
37
|
+
const skew = assertSchemaNotSkewed(ctx, loaded.projectDir);
|
|
38
|
+
const notice = await checkForUpdate({
|
|
39
|
+
env: args.env,
|
|
40
|
+
host: env.host,
|
|
41
|
+
session,
|
|
42
|
+
});
|
|
43
|
+
announceUpdate(ctx, notice);
|
|
44
|
+
// The host would reject a build from a CLI it has declared unsupported
|
|
45
|
+
// anyway (see the wire contract in `toolchain-api.ts`) — refuse here with a
|
|
46
|
+
// hint naming the fix, rather than let the submission round-trip fail with
|
|
47
|
+
// whatever generic error the host happens to answer with.
|
|
48
|
+
if ((notice === null || notice === void 0 ? void 0 : notice.status) === 'unsupported') {
|
|
49
|
+
throw preconditionError(`@ekanos/cli ${notice.current.cli} is below ${env.host}'s minimum ` +
|
|
50
|
+
`supported version (needs at least ${notice.target.cli}).`, 'Run "ekanos upgrade" before publishing — the host will refuse this ' +
|
|
51
|
+
'submission from an unsupported CLI regardless.');
|
|
52
|
+
}
|
|
53
|
+
const resolution = await resolveSourceSlug(env, session, args.source, loaded);
|
|
29
54
|
const version = readProjectVersion(loaded.projectDir);
|
|
30
55
|
const slug = loaded.primary.slug;
|
|
31
56
|
ctx.log(`Validating ${slug} before publishing…`);
|
|
@@ -37,11 +62,26 @@ export async function runPublish(ctx, args) {
|
|
|
37
62
|
'exactly what "ekanos validate" reports), then re-run ' +
|
|
38
63
|
'"ekanos publish".'), { slug, version, findings });
|
|
39
64
|
}
|
|
65
|
+
// The 100%-certainty mechanism: confirm the resolved source is one the
|
|
66
|
+
// caller actually holds a seat on — and, when it was resolved IMPLICITLY
|
|
67
|
+
// from ekanos.json with more than one seat in play, that a human (or an
|
|
68
|
+
// explicit --yes) actually intends this target — BEFORE anything is packed
|
|
69
|
+
// or sent over the wire.
|
|
70
|
+
const verified = await verifyPublishTarget(ctx, env, resolution.session, {
|
|
71
|
+
source: resolution.source,
|
|
72
|
+
explicit: resolution.explicit,
|
|
73
|
+
slug,
|
|
74
|
+
version,
|
|
75
|
+
yes: args.yes,
|
|
76
|
+
stdinIsTTY: (_a = args.stdinIsTTY) !== null && _a !== void 0 ? _a : process.stdin.isTTY === true,
|
|
77
|
+
confirm: (_b = args.confirm) !== null && _b !== void 0 ? _b : promptYesNo,
|
|
78
|
+
});
|
|
79
|
+
const source = verified.sourceSeat.slug;
|
|
40
80
|
ctx.log(`Packing ${slug}@${version}…`);
|
|
41
81
|
const packed = packProject(loaded.projectDir);
|
|
42
82
|
const manifest = buildManifest(loaded, packed.files);
|
|
43
83
|
ctx.log(`Submitting to ${env.host} (source "${source}")…`);
|
|
44
|
-
const receipt = await submitWithOneRefresh(env, session, {
|
|
84
|
+
const receipt = await submitWithOneRefresh(env, verified.session, {
|
|
45
85
|
source,
|
|
46
86
|
slug,
|
|
47
87
|
version,
|
|
@@ -58,19 +98,19 @@ export async function runPublish(ctx, args) {
|
|
|
58
98
|
`"host": "${persisted.hostOverride}" — a one-off override never ` +
|
|
59
99
|
`replaces the saved host; edit ekanos.json to change it.`
|
|
60
100
|
: '';
|
|
61
|
-
return ctx.succeed({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
version: receipt.version,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
101
|
+
return ctx.succeed(Object.assign(Object.assign({ host: env.host, source: {
|
|
102
|
+
id: verified.sourceSeat.id,
|
|
103
|
+
slug: verified.sourceSeat.slug,
|
|
104
|
+
name: verified.sourceSeat.name,
|
|
105
|
+
}, slug: receipt.slug, version: receipt.version, submissionId: receipt.submissionId, state: receipt.state, archiveSha256: receipt.archiveSha256, files: packed.files, sourcePersisted: persisted.source, hostPersisted: persisted.host, hostOverride: persisted.hostOverride }, (skew.status === 'project-older'
|
|
106
|
+
? {
|
|
107
|
+
schemaSkew: {
|
|
108
|
+
status: skew.status,
|
|
109
|
+
cliSchemaVersion: skew.cliSchemaVersion,
|
|
110
|
+
projectSchemaVersion: skew.projectSchemaVersion,
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
: {})), (notice ? { toolchain: notice } : {})), `publish: submitted ${receipt.slug}@${receipt.version} to ${env.host} ` +
|
|
74
114
|
`(source "${source}", state "${receipt.state}").` +
|
|
75
115
|
(persistedNote.length > 0
|
|
76
116
|
? ` Saved ${persistedNote.join(' and ')} to ekanos.json — future ` +
|
|
@@ -78,6 +118,118 @@ export async function runPublish(ctx, args) {
|
|
|
78
118
|
: '') +
|
|
79
119
|
overrideNote);
|
|
80
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* The publish-target verification gate.
|
|
123
|
+
*
|
|
124
|
+
* FORBIDDEN (exit 5) whenever the resolved source is not among the caller's
|
|
125
|
+
* seats — regardless of whether it came from `--source` or ekanos.json.
|
|
126
|
+
* Beyond that, the confirmation rules branch on how the source was resolved:
|
|
127
|
+
*
|
|
128
|
+
* - `--source` THIS invocation: explicit is consent. Proceed.
|
|
129
|
+
* - ekanos.json, exactly one seat held (which must be the match, or the
|
|
130
|
+
* FORBIDDEN check above would have already fired): proceed, but say so —
|
|
131
|
+
* there is nothing to disambiguate, but the target should never be silent.
|
|
132
|
+
* - ekanos.json, multiple seats held: the ambiguous case this mechanism
|
|
133
|
+
* exists for. Only when BOTH human (non-JSON) mode AND stdin is a real
|
|
134
|
+
* TTY does it print the target and require an explicit y/N confirm
|
|
135
|
+
* (`--yes` skips it) — see `canPrompt` below for why stdin matters, not
|
|
136
|
+
* just stdout. Every other combination (JSON mode, or human mode with a
|
|
137
|
+
* closed/non-interactive stdin) NEVER prompts — it proceeds only with
|
|
138
|
+
* `--yes`, otherwise VALIDATION (exit 3) with the seat list, naming
|
|
139
|
+
* `--source`, `--yes` and `ekanos use`.
|
|
140
|
+
*/
|
|
141
|
+
async function verifyPublishTarget(ctx, env, session, args) {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
const result = await fetchSeatsWithOneRefresh(env, session);
|
|
144
|
+
if (result.status === 'unauthorized') {
|
|
145
|
+
stillUnauthorizedSourceSeats(env.host);
|
|
146
|
+
}
|
|
147
|
+
const seat = result.sources.find((s) => s.slug === args.source);
|
|
148
|
+
if (!seat) {
|
|
149
|
+
throw forbiddenError(`This account does not hold a seat on source "${args.source}" on ${env.host}.`, seatsHint(result.sources, env.host));
|
|
150
|
+
}
|
|
151
|
+
if (args.explicit) {
|
|
152
|
+
return { sourceSeat: seat, session: result.session };
|
|
153
|
+
}
|
|
154
|
+
if (result.sources.length === 1) {
|
|
155
|
+
ctx.log(`Publishing to ${(_a = seat.name) !== null && _a !== void 0 ? _a : seat.slug} (${seat.slug}) — your only ` +
|
|
156
|
+
`developer seat.`);
|
|
157
|
+
return { sourceSeat: seat, session: result.session };
|
|
158
|
+
}
|
|
159
|
+
// Implicit source, multiple seats: the ambiguous case.
|
|
160
|
+
//
|
|
161
|
+
// `ctx.jsonMode` alone is NOT enough to decide whether an interactive
|
|
162
|
+
// confirm is safe: `--no-json` forces human mode even when stdout is
|
|
163
|
+
// piped, and neither `--no-json` nor a bare human run says anything about
|
|
164
|
+
// stdin. Prompting `readline`'s `.question()` against a closed/non-TTY
|
|
165
|
+
// stdin (a cron job, a wrapper script piping stdout but not attached to a
|
|
166
|
+
// terminal) never resolves — the process hangs instead of exiting with a
|
|
167
|
+
// clean code. So an actual prompt requires BOTH: human mode AND a real
|
|
168
|
+
// stdin TTY. Anything else — JSON mode, or human mode with non-interactive
|
|
169
|
+
// stdin — falls through to the same non-prompting `--yes`-or-refuse rule.
|
|
170
|
+
const canPrompt = !ctx.jsonMode && args.stdinIsTTY;
|
|
171
|
+
if (canPrompt) {
|
|
172
|
+
ctx.log(`Publishing ${args.slug}@${args.version} to SOURCE ${(_b = seat.name) !== null && _b !== void 0 ? _b : seat.slug} ` +
|
|
173
|
+
`(${seat.slug}) on ${env.host}`);
|
|
174
|
+
if (!args.yes) {
|
|
175
|
+
const confirmed = await args.confirm('Proceed? [y/N]');
|
|
176
|
+
if (!confirmed) {
|
|
177
|
+
throw validationError(`Publish to "${seat.slug}" was not confirmed.`, multiSeatHint(result.sources));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return { sourceSeat: seat, session: result.session };
|
|
181
|
+
}
|
|
182
|
+
if (args.yes) {
|
|
183
|
+
return { sourceSeat: seat, session: result.session };
|
|
184
|
+
}
|
|
185
|
+
throw validationError(`Ambiguous publish target: this account holds ${result.sources.length} ` +
|
|
186
|
+
`developer seats and the source was resolved from ekanos.json, not ` +
|
|
187
|
+
`an explicit flag.`, multiSeatHint(result.sources));
|
|
188
|
+
}
|
|
189
|
+
function seatsHint(sources, host) {
|
|
190
|
+
if (sources.length === 0) {
|
|
191
|
+
return (`You hold no seats on any source on ${host}. Ask a Fusion super-admin ` +
|
|
192
|
+
`to grant your account the developer seat on the intended source.`);
|
|
193
|
+
}
|
|
194
|
+
return (`You hold a seat on: ${describeSeats(sources)}. Pass "--source <slug>" ` +
|
|
195
|
+
`naming one of these, or run "ekanos use <slug>" to set the project's ` +
|
|
196
|
+
`default.`);
|
|
197
|
+
}
|
|
198
|
+
function multiSeatHint(sources) {
|
|
199
|
+
return (`You hold seats on: ${describeSeats(sources)}. Pass "--source <slug>" ` +
|
|
200
|
+
`to name the target explicitly, add "--yes" to confirm the target ` +
|
|
201
|
+
`already in ekanos.json non-interactively, or run "ekanos use <slug>" ` +
|
|
202
|
+
`to change the project's default.`);
|
|
203
|
+
}
|
|
204
|
+
function describeSeats(sources) {
|
|
205
|
+
return sources.map((s) => `${s.slug} (${s.roles.join(', ')})`).join(', ');
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The real, non-test y/N prompt. Reads a line from stdin and writes the
|
|
209
|
+
* question to stderr, so it never touches stdout — the one stream the JSON
|
|
210
|
+
* envelope invariant depends on. Only reachable when `verifyPublishTarget`'s
|
|
211
|
+
* `canPrompt` is true — human mode AND a real stdin TTY — so this never
|
|
212
|
+
* blocks on a closed or non-interactive stdin.
|
|
213
|
+
*/
|
|
214
|
+
/**
|
|
215
|
+
* Exported so `upgrade` can reuse the exact same y/N prompt rather than
|
|
216
|
+
* writing a second one — see `canPrompt` above for the stdin-TTY gating this
|
|
217
|
+
* is only ever invoked behind.
|
|
218
|
+
*/
|
|
219
|
+
export async function promptYesNo(question) {
|
|
220
|
+
const readline = await import('node:readline/promises');
|
|
221
|
+
const rl = readline.createInterface({
|
|
222
|
+
input: process.stdin,
|
|
223
|
+
output: process.stderr,
|
|
224
|
+
});
|
|
225
|
+
try {
|
|
226
|
+
const answer = await rl.question(`${question} `);
|
|
227
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
rl.close();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
81
233
|
async function submitWithOneRefresh(env, session, payload) {
|
|
82
234
|
const first = await submitArchive(env.host, session.accessToken, payload);
|
|
83
235
|
if (first.status === 'ok')
|
|
@@ -90,14 +242,46 @@ async function submitWithOneRefresh(env, session, payload) {
|
|
|
90
242
|
return second.receipt;
|
|
91
243
|
return stillUnauthorized(env.host);
|
|
92
244
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
245
|
+
/**
|
|
246
|
+
* Resolve the source slug (flag → ekanos.json) and whether it was given
|
|
247
|
+
* EXPLICITLY this invocation — the fact `verifyPublishTarget` uses to decide
|
|
248
|
+
* whether a confirmation is even in play. `flag !== undefined` (rather than
|
|
249
|
+
* "non-empty after trim") is deliberate: an explicit `--source` that is
|
|
250
|
+
* effectively empty is still a caller who typed the flag, not one who
|
|
251
|
+
* fell through to ekanos.json.
|
|
252
|
+
*/
|
|
253
|
+
async function resolveSourceSlug(env, session, flag, loaded) {
|
|
254
|
+
const explicit = flag !== undefined;
|
|
255
|
+
const raw = flag !== null && flag !== void 0 ? flag : loaded.project.source;
|
|
256
|
+
if (!raw || raw.trim().length === 0) {
|
|
257
|
+
return noSourceError(env, session);
|
|
258
|
+
}
|
|
259
|
+
return { source: raw.trim(), explicit, session };
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* The no-source validation error, enriched with the caller's seat list when
|
|
263
|
+
* it can be fetched — best-effort, since a session is guaranteed to exist
|
|
264
|
+
* here (publish already called `requireSession`) but the fetch itself can
|
|
265
|
+
* still fail (network, MFA, a down deployment). A failure to enrich must
|
|
266
|
+
* never mask or replace the primary "no source given" error.
|
|
267
|
+
*/
|
|
268
|
+
async function noSourceError(env, session) {
|
|
269
|
+
let seatsNote = '';
|
|
270
|
+
try {
|
|
271
|
+
const result = await fetchSeatsWithOneRefresh(env, session);
|
|
272
|
+
if (result.status === 'ok') {
|
|
273
|
+
seatsNote =
|
|
274
|
+
result.sources.length > 0
|
|
275
|
+
? ` You hold a seat on: ${describeSeats(result.sources)}.`
|
|
276
|
+
: ' You hold no seats on any source on this host yet.';
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch (_a) {
|
|
280
|
+
// Best-effort — the primary error below stands on its own.
|
|
281
|
+
}
|
|
282
|
+
throw validationError('No Fusion source given for the submission.', 'Pass "--source <slug>" (your operator names the source), or set ' +
|
|
283
|
+
'"source": "<slug>" in ekanos.json. A successful publish saves it ' +
|
|
284
|
+
`there for you.${seatsNote}`);
|
|
101
285
|
}
|
|
102
286
|
/**
|
|
103
287
|
* Persist the chosen source AND host into ekanos.json after a SUCCESSFUL
|
|
@@ -119,7 +303,7 @@ function resolveSourceSlug(flag, loaded) {
|
|
|
119
303
|
* always-update semantics — it is scoped BY the host, and updating it is the
|
|
120
304
|
* documented way to repoint a project.
|
|
121
305
|
*/
|
|
122
|
-
function persistProjectFields(loaded, source, host) {
|
|
306
|
+
export function persistProjectFields(loaded, source, host) {
|
|
123
307
|
const wants = {
|
|
124
308
|
source: loaded.project.source !== source,
|
|
125
309
|
host: loaded.project.host === undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/commands/publish.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAsB,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAa1D;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAe,EACf,IAAiB;IAEjB,MAAM,GAAG,GAAG,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAA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CAAC;QACf,MAAM,iBAAiB,CACrB,kBAAkB,YAAY,KAC5B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,EAAE,EACF,uEAAuE;YACrE,sBAAsB,CACzB,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GACX,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAC3C,CAAC,CAAE,MAAgC,CAAC,OAAO;QAC3C,CAAC,CAAC,SAAS,CAAC;IAEhB,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACjE,MAAM,eAAe,CACnB,6BACE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,SACjD,kCAAkC,EAClC,oBAAoB,YAAY,oCAAoC;YAClE,+BAA+B,CAClC,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { StoredSession } from '../auth/credential-store';\nimport {\n refreshStoredSession,\n requireSession,\n resolveAuthEnvironment,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport { gateFailedError, preconditionError, validationError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { packProject } from '../pack';\nimport { type LoadedProject, loadProject, serializeProject } from '../project';\nimport {\n MAX_MANIFEST_BYTES,\n stillUnauthorized,\n submitArchive,\n} from '../publish-api';\nimport { collectAllFindings } from '../validate-findings';\n\nexport interface PublishArgs {\n host?: string;\n /** Fusion source slug. Falls back to ekanos.json's \"source\" field. */\n source?: string;\n /** Project directory (contains ekanos.json). Defaults to cwd. */\n dir: string;\n /** Accepted for non-interactive ergonomics; publish never prompts regardless. */\n yes: boolean;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `publish` — pack the project and submit it to a Fusion deployment.\n *\n * The submission gate is the SAME findings pass `validate` runs (one\n * implementation, `validate-findings.ts`): any error-severity finding refuses\n * the publish with GATE_FAILED (exit 10) and the findings in `data`, so an\n * agent can branch on the code and fix-then-retry without re-running validate.\n *\n * Authorization is server-side — the dev seat on the target source — and the\n * stored session is refreshed once on a 401, mirroring `whoami`. On the first\n * successful publish the chosen source slug is persisted into `ekanos.json`\n * so later publishes need no `--source`.\n */\nexport async function runPublish(\n ctx: CliContext,\n args: PublishArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const session = requireSession(env.store, env.host);\n\n const loaded = loadProject(args.dir);\n const source = resolveSourceSlug(args.source, loaded);\n const version = readProjectVersion(loaded.projectDir);\n const slug = loaded.primary.slug;\n\n ctx.log(`Validating ${slug} before publishing…`);\n\n const findings = await collectAllFindings(loaded);\n const errorCount = findings.filter((f) => f.severity === 'error').length;\n\n if (errorCount > 0) {\n return ctx.fail(\n gateFailedError(\n `Refusing to publish: ${errorCount} validation finding` +\n `${errorCount === 1 ? '' : 's'}.`,\n 'Resolve the error-severity findings in data.findings (they are ' +\n 'exactly what \"ekanos validate\" reports), then re-run ' +\n '\"ekanos publish\".',\n ),\n { slug, version, findings },\n );\n }\n\n ctx.log(`Packing ${slug}@${version}…`);\n\n const packed = packProject(loaded.projectDir);\n const manifest = buildManifest(loaded, packed.files);\n\n ctx.log(`Submitting to ${env.host} (source \"${source}\")…`);\n\n const receipt = await submitWithOneRefresh(env, session, {\n source,\n slug,\n version,\n manifest,\n archive: packed.archive,\n });\n\n const persisted = persistProjectFields(loaded, source, env.host);\n\n const persistedNote = [\n ...(persisted.source ? [`\"source\": \"${source}\"`] : []),\n ...(persisted.host ? [`\"host\": \"${env.host}\"`] : []),\n ];\n\n const overrideNote = persisted.hostOverride\n ? ` NOTE: this publish went to ${env.host}, but ekanos.json keeps ` +\n `\"host\": \"${persisted.hostOverride}\" — a one-off override never ` +\n `replaces the saved host; edit ekanos.json to change it.`\n : '';\n\n return ctx.succeed(\n {\n host: env.host,\n source,\n slug: receipt.slug,\n version: receipt.version,\n submissionId: receipt.submissionId,\n state: receipt.state,\n archiveSha256: receipt.archiveSha256,\n files: packed.files,\n sourcePersisted: persisted.source,\n hostPersisted: persisted.host,\n hostOverride: persisted.hostOverride,\n },\n `publish: submitted ${receipt.slug}@${receipt.version} to ${env.host} ` +\n `(source \"${source}\", state \"${receipt.state}\").` +\n (persistedNote.length > 0\n ? ` Saved ${persistedNote.join(' and ')} to ekanos.json — future ` +\n `publishes won't need the flag${persistedNote.length === 1 ? '' : 's'}.`\n : '') +\n overrideNote,\n );\n}\n\nasync function submitWithOneRefresh(\n env: ReturnType<typeof resolveAuthEnvironment>,\n session: StoredSession,\n payload: Parameters<typeof submitArchive>[2],\n) {\n const first = await submitArchive(env.host, session.accessToken, payload);\n\n if (first.status === 'ok') return first.receipt;\n\n // The access token no longer authenticates — an ordinary event, not an\n // error. One refresh, one retry; a second 401 is authoritative.\n const refreshed = await refreshStoredSession(env, session);\n const second = await submitArchive(env.host, refreshed.accessToken, payload);\n\n if (second.status === 'ok') return second.receipt;\n\n return stillUnauthorized(env.host);\n}\n\nfunction resolveSourceSlug(\n flag: string | undefined,\n loaded: LoadedProject,\n): string {\n const source = flag ?? loaded.project.source;\n\n if (!source || source.trim().length === 0) {\n throw validationError(\n 'No Fusion source given for the submission.',\n 'Pass \"--source <slug>\" (your operator names the source), or set ' +\n '\"source\": \"<slug>\" in ekanos.json. A successful publish saves it ' +\n 'there for you.',\n );\n }\n\n return source.trim();\n}\n\n/**\n * Persist the chosen source AND host into ekanos.json after a SUCCESSFUL\n * publish, so the next publish — and every other host-taking verb — needs no\n * flag. Returns what was written. A write failure is reported but never fails\n * the command — the submission already landed.\n *\n * `publish` is the only verb that writes ekanos.json: it is the one verb that\n * proves the (host, source) pair actually works, and it always runs inside a\n * project. `login` deliberately never writes — it is routinely run outside\n * one, and the credential store's sole-host fallback covers it.\n *\n * `host` persists on FIRST WRITE ONLY. It decides where every future verb\n * sends the bearer token and the source archive, so a one-off `--host`\n * override (a staging test, say) must not silently become the project's\n * sticky default; when the override differs from the stored host, the stored\n * value is kept and the difference is called out in the result instead.\n * Changing it is an explicit edit of ekanos.json. `source` keeps the simpler\n * always-update semantics — it is scoped BY the host, and updating it is the\n * documented way to repoint a project.\n */\nfunction persistProjectFields(\n loaded: LoadedProject,\n source: string,\n host: string,\n): { source: boolean; host: boolean; hostOverride: string | null } {\n const wants = {\n source: loaded.project.source !== source,\n host: loaded.project.host === undefined,\n };\n\n const hostOverride =\n loaded.project.host !== undefined && loaded.project.host !== host\n ? loaded.project.host\n : null;\n\n if (!wants.source && !wants.host) {\n return { source: false, host: false, hostOverride };\n }\n\n try {\n fs.writeFileSync(\n loaded.configPath,\n serializeProject({\n ...loaded.project,\n source,\n host: wants.host ? host : loaded.project.host,\n }),\n );\n\n return { ...wants, hostOverride };\n } catch {\n // Diagnostics-only: the publish succeeded; a read-only ekanos.json just\n // means the next publish needs the flags again.\n return { source: false, host: false, hostOverride };\n }\n}\n\n/**\n * How many packed paths the manifest embeds before switching to a truncated\n * list plus a `filesTruncated` total. The manifest is metadata — the archive\n * itself is the payload — and the server caps it at MAX_MANIFEST_BYTES, so a\n * many-small-files project must not be able to blow the cap with its file\n * list alone.\n */\nconst MANIFEST_FILE_LIST_CAP = 200;\n\n/**\n * The submission manifest: the parsed ekanos.json, the integration entries,\n * and (a bounded prefix of) the packed file list. Refuses to build one over\n * the server's byte cap — a clear VALIDATION error here beats the server's\n * generic 400 after a 4 MiB upload.\n */\nfunction buildManifest(loaded: LoadedProject, files: string[]): string {\n const manifest = JSON.stringify({\n project: loaded.project,\n integrations: loaded.integrations.map((i) => ({\n slug: i.slug,\n entry: i.entry,\n })),\n files: files.slice(0, MANIFEST_FILE_LIST_CAP),\n ...(files.length > MANIFEST_FILE_LIST_CAP\n ? { filesTruncated: files.length }\n : {}),\n });\n\n const bytes = Buffer.byteLength(manifest, 'utf8');\n\n if (bytes > MAX_MANIFEST_BYTES) {\n throw validationError(\n `The submission manifest is ${bytes} bytes, over the ` +\n `${MAX_MANIFEST_BYTES}-byte server cap.`,\n 'The manifest embeds your ekanos.json — trim oversized fields there ' +\n '(sourceGlobs is the usual culprit), then re-run \"ekanos publish\".',\n );\n }\n\n return manifest;\n}\n\nconst SEMVER_PATTERN =\n /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$/;\n\n/**\n * The submitted version is the project's own `package.json#version` — one\n * source of truth, the same field npm would publish.\n */\nfunction readProjectVersion(projectDir: string): string {\n const manifestPath = path.join(projectDir, 'package.json');\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n } catch (error) {\n throw preconditionError(\n `Could not read ${manifestPath}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n `Ensure the project has a valid package.json — its \"version\" field is ` +\n `what gets submitted.`,\n );\n }\n\n const version =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as { version?: unknown }).version\n : undefined;\n\n if (typeof version !== 'string' || !SEMVER_PATTERN.test(version)) {\n throw validationError(\n `package.json \"version\" is ${\n typeof version === 'string' ? `\"${version}\"` : 'missing'\n }, which is not a semver version.`,\n `Set \"version\" in ${manifestPath} to a semver string like \"0.1.0\", ` +\n `then re-run \"ekanos publish\".`,\n );\n }\n\n return version;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/commands/publish.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EAEL,oBAAoB,EACpB,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,cAAc,EACd,eAAe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YACpD,GAAG,kBAAkB,mBAAmB,EAC1C,qEAAqE;YACnE,mEAAmE,CACtE,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,cAAc,GAClB,gGAAgG,CAAC;AAEnG;;;GAGG;AACH,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAE3D,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,iBAAiB,CACrB,kBAAkB,YAAY,KAC5B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,EAAE,EACF,uEAAuE;YACrE,sBAAsB,CACzB,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GACX,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;QAC3C,CAAC,CAAE,MAAgC,CAAC,OAAO;QAC3C,CAAC,CAAC,SAAS,CAAC;IAEhB,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACjE,MAAM,eAAe,CACnB,6BACE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,SACjD,kCAAkC,EAClC,oBAAoB,YAAY,oCAAoC;YAClE,+BAA+B,CAClC,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import * 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 requireSession,\n resolveAuthEnvironment,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport {\n forbiddenError,\n gateFailedError,\n preconditionError,\n validationError,\n} from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { packProject } from '../pack';\nimport { type LoadedProject, loadProject, serializeProject } from '../project';\nimport {\n MAX_MANIFEST_BYTES,\n stillUnauthorized,\n submitArchive,\n} from '../publish-api';\nimport { assertSchemaNotSkewed } from '../schema-skew';\nimport { fetchSeatsWithOneRefresh } from '../seats';\nimport { type SourceSeat, stillUnauthorizedSourceSeats } from '../sources-api';\nimport { announceUpdate, checkForUpdate } from '../update-notice';\nimport { collectAllFindings } from '../validate-findings';\n\nexport interface PublishArgs {\n host?: string;\n /** Fusion source slug. Falls back to ekanos.json's \"source\" field. */\n source?: string;\n /** Project directory (contains ekanos.json). Defaults to cwd. */\n dir: string;\n /**\n * Skips the interactive confirm when the source resolved IMPLICITLY (from\n * ekanos.json) and the caller holds more than one developer seat. Has no\n * effect when `--source` was passed this invocation (explicit is already\n * consent) or when the caller holds exactly one seat (nothing to\n * disambiguate).\n */\n yes: boolean;\n env: Record<string, string | undefined>;\n /**\n * Whether stdin is a real interactive terminal — the SECOND condition (with\n * human/non-JSON mode) required before publish will ever prompt. Defaults\n * to `process.stdin.isTTY === true`. Injectable so tests can exercise the\n * confirm branch without a real TTY.\n */\n stdinIsTTY?: boolean;\n /**\n * Injectable y/N prompt, for tests. Defaults to a real readline prompt over\n * stdin/stderr. Never invoked unless BOTH human mode and a real stdin TTY\n * are in play — see `canPrompt` in `verifyPublishTarget`.\n */\n confirm?: (question: string) => Promise<boolean>;\n}\n\n/** Where the resolved source slug came from — governs the confirmation rules below. */\ninterface SourceResolution {\n source: string;\n /** True iff `--source` was passed THIS invocation. */\n explicit: boolean;\n}\n\n/**\n * `publish` — pack the project and submit it to a Fusion deployment.\n *\n * The submission gate is the SAME findings pass `validate` runs (one\n * implementation, `validate-findings.ts`): any error-severity finding refuses\n * the publish with GATE_FAILED (exit 10) and the findings in `data`, so an\n * agent can branch on the code and fix-then-retry without re-running validate.\n *\n * Authorization is server-side — the dev seat on the target source — and the\n * stored session is refreshed once on a 401, mirroring `whoami`. On the first\n * successful publish the chosen source slug is persisted into `ekanos.json`\n * so later publishes need no `--source`.\n */\nexport async function runPublish(\n ctx: CliContext,\n args: PublishArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const session = requireSession(env.store, env.host);\n\n const loaded = loadProject(args.dir);\n\n // Fail fast, before anything else: a project whose schema is newer than\n // this CLI bundles cannot be trusted to validate correctly, so publishing\n // it — the one verb whose findings gate is meant to be authoritative —\n // must refuse before packing or submitting anything. See `schema-skew.ts`.\n const skew = assertSchemaNotSkewed(ctx, loaded.projectDir);\n\n const notice = await checkForUpdate({\n env: args.env,\n host: env.host,\n session,\n });\n announceUpdate(ctx, notice);\n\n // The host would reject a build from a CLI it has declared unsupported\n // anyway (see the wire contract in `toolchain-api.ts`) — refuse here with a\n // hint naming the fix, rather than let the submission round-trip fail with\n // whatever generic error the host happens to answer with.\n if (notice?.status === 'unsupported') {\n throw preconditionError(\n `@ekanos/cli ${notice.current.cli} is below ${env.host}'s minimum ` +\n `supported version (needs at least ${notice.target.cli}).`,\n 'Run \"ekanos upgrade\" before publishing — the host will refuse this ' +\n 'submission from an unsupported CLI regardless.',\n );\n }\n\n const resolution = await resolveSourceSlug(env, session, args.source, loaded);\n const version = readProjectVersion(loaded.projectDir);\n const slug = loaded.primary.slug;\n\n ctx.log(`Validating ${slug} before publishing…`);\n\n const findings = await collectAllFindings(loaded);\n const errorCount = findings.filter((f) => f.severity === 'error').length;\n\n if (errorCount > 0) {\n return ctx.fail(\n gateFailedError(\n `Refusing to publish: ${errorCount} validation finding` +\n `${errorCount === 1 ? '' : 's'}.`,\n 'Resolve the error-severity findings in data.findings (they are ' +\n 'exactly what \"ekanos validate\" reports), then re-run ' +\n '\"ekanos publish\".',\n ),\n { slug, version, findings },\n );\n }\n\n // The 100%-certainty mechanism: confirm the resolved source is one the\n // caller actually holds a seat on — and, when it was resolved IMPLICITLY\n // from ekanos.json with more than one seat in play, that a human (or an\n // explicit --yes) actually intends this target — BEFORE anything is packed\n // or sent over the wire.\n const verified = await verifyPublishTarget(ctx, env, resolution.session, {\n source: resolution.source,\n explicit: resolution.explicit,\n slug,\n version,\n yes: args.yes,\n stdinIsTTY: args.stdinIsTTY ?? process.stdin.isTTY === true,\n confirm: args.confirm ?? promptYesNo,\n });\n\n const source = verified.sourceSeat.slug;\n\n ctx.log(`Packing ${slug}@${version}…`);\n\n const packed = packProject(loaded.projectDir);\n const manifest = buildManifest(loaded, packed.files);\n\n ctx.log(`Submitting to ${env.host} (source \"${source}\")…`);\n\n const receipt = await submitWithOneRefresh(env, verified.session, {\n source,\n slug,\n version,\n manifest,\n archive: packed.archive,\n });\n\n const persisted = persistProjectFields(loaded, source, env.host);\n\n const persistedNote = [\n ...(persisted.source ? [`\"source\": \"${source}\"`] : []),\n ...(persisted.host ? [`\"host\": \"${env.host}\"`] : []),\n ];\n\n const overrideNote = persisted.hostOverride\n ? ` NOTE: this publish went to ${env.host}, but ekanos.json keeps ` +\n `\"host\": \"${persisted.hostOverride}\" — a one-off override never ` +\n `replaces the saved host; edit ekanos.json to change it.`\n : '';\n\n return ctx.succeed(\n {\n host: env.host,\n source: {\n id: verified.sourceSeat.id,\n slug: verified.sourceSeat.slug,\n name: verified.sourceSeat.name,\n },\n slug: receipt.slug,\n version: receipt.version,\n submissionId: receipt.submissionId,\n state: receipt.state,\n archiveSha256: receipt.archiveSha256,\n files: packed.files,\n sourcePersisted: persisted.source,\n hostPersisted: persisted.host,\n hostOverride: persisted.hostOverride,\n ...(skew.status === 'project-older'\n ? {\n schemaSkew: {\n status: skew.status,\n cliSchemaVersion: skew.cliSchemaVersion,\n projectSchemaVersion: skew.projectSchemaVersion,\n },\n }\n : {}),\n ...(notice ? { toolchain: notice } : {}),\n },\n `publish: submitted ${receipt.slug}@${receipt.version} to ${env.host} ` +\n `(source \"${source}\", state \"${receipt.state}\").` +\n (persistedNote.length > 0\n ? ` Saved ${persistedNote.join(' and ')} to ekanos.json — future ` +\n `publishes won't need the flag${persistedNote.length === 1 ? '' : 's'}.`\n : '') +\n overrideNote,\n );\n}\n\n/**\n * The publish-target verification gate.\n *\n * FORBIDDEN (exit 5) whenever the resolved source is not among the caller's\n * seats — regardless of whether it came from `--source` or ekanos.json.\n * Beyond that, the confirmation rules branch on how the source was resolved:\n *\n * - `--source` THIS invocation: explicit is consent. Proceed.\n * - ekanos.json, exactly one seat held (which must be the match, or the\n * FORBIDDEN check above would have already fired): proceed, but say so —\n * there is nothing to disambiguate, but the target should never be silent.\n * - ekanos.json, multiple seats held: the ambiguous case this mechanism\n * exists for. Only when BOTH human (non-JSON) mode AND stdin is a real\n * TTY does it print the target and require an explicit y/N confirm\n * (`--yes` skips it) — see `canPrompt` below for why stdin matters, not\n * just stdout. Every other combination (JSON mode, or human mode with a\n * closed/non-interactive stdin) NEVER prompts — it proceeds only with\n * `--yes`, otherwise VALIDATION (exit 3) with the seat list, naming\n * `--source`, `--yes` and `ekanos use`.\n */\nasync function verifyPublishTarget(\n ctx: CliContext,\n env: AuthEnvironment,\n session: StoredSession,\n args: SourceResolution & {\n slug: string;\n version: string;\n yes: boolean;\n /** Real interactivity signal for stdin — see `canPrompt` below. */\n stdinIsTTY: boolean;\n confirm: (question: string) => Promise<boolean>;\n },\n): Promise<{ sourceSeat: SourceSeat; session: StoredSession }> {\n const result = await fetchSeatsWithOneRefresh(env, session);\n\n if (result.status === 'unauthorized') {\n stillUnauthorizedSourceSeats(env.host);\n }\n\n const seat = result.sources.find((s) => s.slug === args.source);\n\n if (!seat) {\n throw forbiddenError(\n `This account does not hold a seat on source \"${args.source}\" on ${env.host}.`,\n seatsHint(result.sources, env.host),\n );\n }\n\n if (args.explicit) {\n return { sourceSeat: seat, session: result.session };\n }\n\n if (result.sources.length === 1) {\n ctx.log(\n `Publishing to ${seat.name ?? seat.slug} (${seat.slug}) — your only ` +\n `developer seat.`,\n );\n return { sourceSeat: seat, session: result.session };\n }\n\n // Implicit source, multiple seats: the ambiguous case.\n //\n // `ctx.jsonMode` alone is NOT enough to decide whether an interactive\n // confirm is safe: `--no-json` forces human mode even when stdout is\n // piped, and neither `--no-json` nor a bare human run says anything about\n // stdin. Prompting `readline`'s `.question()` against a closed/non-TTY\n // stdin (a cron job, a wrapper script piping stdout but not attached to a\n // terminal) never resolves — the process hangs instead of exiting with a\n // clean code. So an actual prompt requires BOTH: human mode AND a real\n // stdin TTY. Anything else — JSON mode, or human mode with non-interactive\n // stdin — falls through to the same non-prompting `--yes`-or-refuse rule.\n const canPrompt = !ctx.jsonMode && args.stdinIsTTY;\n\n if (canPrompt) {\n ctx.log(\n `Publishing ${args.slug}@${args.version} to SOURCE ${seat.name ?? seat.slug} ` +\n `(${seat.slug}) on ${env.host}`,\n );\n\n if (!args.yes) {\n const confirmed = await args.confirm('Proceed? [y/N]');\n\n if (!confirmed) {\n throw validationError(\n `Publish to \"${seat.slug}\" was not confirmed.`,\n multiSeatHint(result.sources),\n );\n }\n }\n\n return { sourceSeat: seat, session: result.session };\n }\n\n if (args.yes) {\n return { sourceSeat: seat, session: result.session };\n }\n\n throw validationError(\n `Ambiguous publish target: this account holds ${result.sources.length} ` +\n `developer seats and the source was resolved from ekanos.json, not ` +\n `an explicit flag.`,\n multiSeatHint(result.sources),\n );\n}\n\nfunction seatsHint(sources: SourceSeat[], host: string): string {\n if (sources.length === 0) {\n return (\n `You hold no seats on any source on ${host}. Ask a Fusion super-admin ` +\n `to grant your account the developer seat on the intended source.`\n );\n }\n\n return (\n `You hold a seat on: ${describeSeats(sources)}. Pass \"--source <slug>\" ` +\n `naming one of these, or run \"ekanos use <slug>\" to set the project's ` +\n `default.`\n );\n}\n\nfunction multiSeatHint(sources: SourceSeat[]): string {\n return (\n `You hold seats on: ${describeSeats(sources)}. Pass \"--source <slug>\" ` +\n `to name the target explicitly, add \"--yes\" to confirm the target ` +\n `already in ekanos.json non-interactively, or run \"ekanos use <slug>\" ` +\n `to change the project's default.`\n );\n}\n\nfunction describeSeats(sources: SourceSeat[]): string {\n return sources.map((s) => `${s.slug} (${s.roles.join(', ')})`).join(', ');\n}\n\n/**\n * The real, non-test y/N prompt. Reads a line from stdin and writes the\n * question to stderr, so it never touches stdout — the one stream the JSON\n * envelope invariant depends on. Only reachable when `verifyPublishTarget`'s\n * `canPrompt` is true — human mode AND a real stdin TTY — so this never\n * blocks on a closed or non-interactive stdin.\n */\n/**\n * Exported so `upgrade` can reuse the exact same y/N prompt rather than\n * writing a second one — see `canPrompt` above for the stdin-TTY gating this\n * is only ever invoked behind.\n */\nexport async function promptYesNo(question: string): Promise<boolean> {\n const readline = await import('node:readline/promises');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stderr,\n });\n\n try {\n const answer = await rl.question(`${question} `);\n return /^y(es)?$/i.test(answer.trim());\n } finally {\n rl.close();\n }\n}\n\nasync function submitWithOneRefresh(\n env: ReturnType<typeof resolveAuthEnvironment>,\n session: StoredSession,\n payload: Parameters<typeof submitArchive>[2],\n) {\n const first = await submitArchive(env.host, session.accessToken, payload);\n\n if (first.status === 'ok') return first.receipt;\n\n // The access token no longer authenticates — an ordinary event, not an\n // error. One refresh, one retry; a second 401 is authoritative.\n const refreshed = await refreshStoredSession(env, session);\n const second = await submitArchive(env.host, refreshed.accessToken, payload);\n\n if (second.status === 'ok') return second.receipt;\n\n return stillUnauthorized(env.host);\n}\n\n/**\n * Resolve the source slug (flag → ekanos.json) and whether it was given\n * EXPLICITLY this invocation — the fact `verifyPublishTarget` uses to decide\n * whether a confirmation is even in play. `flag !== undefined` (rather than\n * \"non-empty after trim\") is deliberate: an explicit `--source` that is\n * effectively empty is still a caller who typed the flag, not one who\n * fell through to ekanos.json.\n */\nasync function resolveSourceSlug(\n env: AuthEnvironment,\n session: StoredSession,\n flag: string | undefined,\n loaded: LoadedProject,\n): Promise<SourceResolution & { session: StoredSession }> {\n const explicit = flag !== undefined;\n const raw = flag ?? loaded.project.source;\n\n if (!raw || raw.trim().length === 0) {\n return noSourceError(env, session);\n }\n\n return { source: raw.trim(), explicit, session };\n}\n\n/**\n * The no-source validation error, enriched with the caller's seat list when\n * it can be fetched — best-effort, since a session is guaranteed to exist\n * here (publish already called `requireSession`) but the fetch itself can\n * still fail (network, MFA, a down deployment). A failure to enrich must\n * never mask or replace the primary \"no source given\" error.\n */\nasync function noSourceError(\n env: AuthEnvironment,\n session: StoredSession,\n): Promise<never> {\n let seatsNote = '';\n\n try {\n const result = await fetchSeatsWithOneRefresh(env, session);\n\n if (result.status === 'ok') {\n seatsNote =\n result.sources.length > 0\n ? ` You hold a seat on: ${describeSeats(result.sources)}.`\n : ' You hold no seats on any source on this host yet.';\n }\n } catch {\n // Best-effort — the primary error below stands on its own.\n }\n\n throw validationError(\n 'No Fusion source given for the submission.',\n 'Pass \"--source <slug>\" (your operator names the source), or set ' +\n '\"source\": \"<slug>\" in ekanos.json. A successful publish saves it ' +\n `there for you.${seatsNote}`,\n );\n}\n\n/**\n * Persist the chosen source AND host into ekanos.json after a SUCCESSFUL\n * publish, so the next publish — and every other host-taking verb — needs no\n * flag. Returns what was written. A write failure is reported but never fails\n * the command — the submission already landed.\n *\n * `publish` is the only verb that writes ekanos.json: it is the one verb that\n * proves the (host, source) pair actually works, and it always runs inside a\n * project. `login` deliberately never writes — it is routinely run outside\n * one, and the credential store's sole-host fallback covers it.\n *\n * `host` persists on FIRST WRITE ONLY. It decides where every future verb\n * sends the bearer token and the source archive, so a one-off `--host`\n * override (a staging test, say) must not silently become the project's\n * sticky default; when the override differs from the stored host, the stored\n * value is kept and the difference is called out in the result instead.\n * Changing it is an explicit edit of ekanos.json. `source` keeps the simpler\n * always-update semantics — it is scoped BY the host, and updating it is the\n * documented way to repoint a project.\n */\nexport function persistProjectFields(\n loaded: LoadedProject,\n source: string,\n host: string,\n): { source: boolean; host: boolean; hostOverride: string | null } {\n const wants = {\n source: loaded.project.source !== source,\n host: loaded.project.host === undefined,\n };\n\n const hostOverride =\n loaded.project.host !== undefined && loaded.project.host !== host\n ? loaded.project.host\n : null;\n\n if (!wants.source && !wants.host) {\n return { source: false, host: false, hostOverride };\n }\n\n try {\n fs.writeFileSync(\n loaded.configPath,\n serializeProject({\n ...loaded.project,\n source,\n host: wants.host ? host : loaded.project.host,\n }),\n );\n\n return { ...wants, hostOverride };\n } catch {\n // Diagnostics-only: the publish succeeded; a read-only ekanos.json just\n // means the next publish needs the flags again.\n return { source: false, host: false, hostOverride };\n }\n}\n\n/**\n * How many packed paths the manifest embeds before switching to a truncated\n * list plus a `filesTruncated` total. The manifest is metadata — the archive\n * itself is the payload — and the server caps it at MAX_MANIFEST_BYTES, so a\n * many-small-files project must not be able to blow the cap with its file\n * list alone.\n */\nconst MANIFEST_FILE_LIST_CAP = 200;\n\n/**\n * The submission manifest: the parsed ekanos.json, the integration entries,\n * and (a bounded prefix of) the packed file list. Refuses to build one over\n * the server's byte cap — a clear VALIDATION error here beats the server's\n * generic 400 after a 4 MiB upload.\n */\nfunction buildManifest(loaded: LoadedProject, files: string[]): string {\n const manifest = JSON.stringify({\n project: loaded.project,\n integrations: loaded.integrations.map((i) => ({\n slug: i.slug,\n entry: i.entry,\n })),\n files: files.slice(0, MANIFEST_FILE_LIST_CAP),\n ...(files.length > MANIFEST_FILE_LIST_CAP\n ? { filesTruncated: files.length }\n : {}),\n });\n\n const bytes = Buffer.byteLength(manifest, 'utf8');\n\n if (bytes > MAX_MANIFEST_BYTES) {\n throw validationError(\n `The submission manifest is ${bytes} bytes, over the ` +\n `${MAX_MANIFEST_BYTES}-byte server cap.`,\n 'The manifest embeds your ekanos.json — trim oversized fields there ' +\n '(sourceGlobs is the usual culprit), then re-run \"ekanos publish\".',\n );\n }\n\n return manifest;\n}\n\nconst SEMVER_PATTERN =\n /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$/;\n\n/**\n * The submitted version is the project's own `package.json#version` — one\n * source of truth, the same field npm would publish.\n */\nfunction readProjectVersion(projectDir: string): string {\n const manifestPath = path.join(projectDir, 'package.json');\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n } catch (error) {\n throw preconditionError(\n `Could not read ${manifestPath}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n `Ensure the project has a valid package.json — its \"version\" field is ` +\n `what gets submitted.`,\n );\n }\n\n const version =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as { version?: unknown }).version\n : undefined;\n\n if (typeof version !== 'string' || !SEMVER_PATTERN.test(version)) {\n throw validationError(\n `package.json \"version\" is ${\n typeof version === 'string' ? `\"${version}\"` : 'missing'\n }, which is not a semver version.`,\n `Set \"version\" in ${manifestPath} to a semver string like \"0.1.0\", ` +\n `then re-run \"ekanos publish\".`,\n );\n }\n\n return version;\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CliContext } from '../context.js';
|
|
2
|
+
import type { ExitCode } from '../exit-codes.js';
|
|
3
|
+
export interface SourcesArgs {
|
|
4
|
+
host?: string;
|
|
5
|
+
/** Where a project's ekanos.json may sit — its `source` field, if any, is the marker. */
|
|
6
|
+
dir: string;
|
|
7
|
+
env: Record<string, string | undefined>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* `sources` — list every source the caller holds a developer or admin seat
|
|
11
|
+
* on, the read half of the publish-target-verification story.
|
|
12
|
+
*
|
|
13
|
+
* The list itself is the mechanism that makes `publish` safe: a partner (or
|
|
14
|
+
* an agent acting for one) can always answer "which sources can I possibly
|
|
15
|
+
* publish to?" before running `ekanos use` or passing `--source`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function runSources(ctx: CliContext, args: SourcesArgs): Promise<ExitCode>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { requireSession, resolveAuthEnvironment } from '../auth/session.js';
|
|
4
|
+
import { EKANOS_CONFIG_FILENAME } from '../project.js';
|
|
5
|
+
import { fetchSeatsWithOneRefresh } from '../seats.js';
|
|
6
|
+
import { stillUnauthorizedSourceSeats } from '../sources-api.js';
|
|
7
|
+
/**
|
|
8
|
+
* `sources` — list every source the caller holds a developer or admin seat
|
|
9
|
+
* on, the read half of the publish-target-verification story.
|
|
10
|
+
*
|
|
11
|
+
* The list itself is the mechanism that makes `publish` safe: a partner (or
|
|
12
|
+
* an agent acting for one) can always answer "which sources can I possibly
|
|
13
|
+
* publish to?" before running `ekanos use` or passing `--source`.
|
|
14
|
+
*/
|
|
15
|
+
export async function runSources(ctx, args) {
|
|
16
|
+
const env = resolveAuthEnvironment(ctx, args.host, args.env, {
|
|
17
|
+
projectDir: args.dir,
|
|
18
|
+
});
|
|
19
|
+
const session = requireSession(env.store, env.host);
|
|
20
|
+
const result = await fetchSeatsWithOneRefresh(env, session);
|
|
21
|
+
if (result.status === 'unauthorized') {
|
|
22
|
+
stillUnauthorizedSourceSeats(env.host);
|
|
23
|
+
}
|
|
24
|
+
const activeSource = readActiveSource(args.dir);
|
|
25
|
+
return ctx.succeed({ host: env.host, sources: result.sources, activeSource }, humanSummary(result.sources, activeSource));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Best-effort, lenient read of ekanos.json's `source` field — mirrors
|
|
29
|
+
* `readProjectHost` in `auth/session.ts`. A missing, unparseable, or
|
|
30
|
+
* sourceless ekanos.json (or no project at all) simply means "no active
|
|
31
|
+
* source to mark", never an error: `sources` must answer outside a project
|
|
32
|
+
* too.
|
|
33
|
+
*/
|
|
34
|
+
function readActiveSource(dir) {
|
|
35
|
+
const configPath = path.join(dir, EKANOS_CONFIG_FILENAME);
|
|
36
|
+
let raw;
|
|
37
|
+
try {
|
|
38
|
+
raw = fs.readFileSync(configPath, 'utf8');
|
|
39
|
+
}
|
|
40
|
+
catch (_a) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
let parsed;
|
|
44
|
+
try {
|
|
45
|
+
parsed = JSON.parse(raw);
|
|
46
|
+
}
|
|
47
|
+
catch (_b) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const source = typeof parsed === 'object' && parsed !== null
|
|
51
|
+
? parsed.source
|
|
52
|
+
: undefined;
|
|
53
|
+
return typeof source === 'string' && source.trim().length > 0
|
|
54
|
+
? source.trim()
|
|
55
|
+
: null;
|
|
56
|
+
}
|
|
57
|
+
function humanSummary(sources, activeSource) {
|
|
58
|
+
var _a;
|
|
59
|
+
if (sources.length === 0) {
|
|
60
|
+
return 'sources: you hold no developer seats on this host.';
|
|
61
|
+
}
|
|
62
|
+
const lines = ['sources:'];
|
|
63
|
+
for (const source of sources) {
|
|
64
|
+
const marker = source.slug === activeSource ? '*' : ' ';
|
|
65
|
+
lines.push(` ${marker} ${source.slug} ${(_a = source.name) !== null && _a !== void 0 ? _a : '(unnamed)'} ` +
|
|
66
|
+
`[${source.roles.join(', ')}]`);
|
|
67
|
+
}
|
|
68
|
+
if (activeSource && !sources.some((s) => s.slug === activeSource)) {
|
|
69
|
+
lines.push(` ! this project's ekanos.json points at "${activeSource}", which is ` +
|
|
70
|
+
`not in the list above.`);
|
|
71
|
+
}
|
|
72
|
+
lines.push('(* marks the current project publish target)');
|
|
73
|
+
return lines.join('\n');
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=sources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sources.js","sourceRoot":"","sources":["../../src/commands/sources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,iBAAiB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YAAY,cAAc;YACrE,wBAAwB,CAC3B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;IAE3D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport { requireSession, resolveAuthEnvironment } from '../auth/session';\nimport type { CliContext } from '../context';\nimport type { ExitCode } from '../exit-codes';\nimport { EKANOS_CONFIG_FILENAME } from '../project';\nimport { fetchSeatsWithOneRefresh } from '../seats';\nimport { type SourceSeat, stillUnauthorizedSourceSeats } from '../sources-api';\n\nexport interface SourcesArgs {\n host?: string;\n /** Where a project's ekanos.json may sit — its `source` field, if any, is the marker. */\n dir: string;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `sources` — list every source the caller holds a developer or admin seat\n * on, the read half of the publish-target-verification story.\n *\n * The list itself is the mechanism that makes `publish` safe: a partner (or\n * an agent acting for one) can always answer \"which sources can I possibly\n * publish to?\" before running `ekanos use` or passing `--source`.\n */\nexport async function runSources(\n ctx: CliContext,\n args: SourcesArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const session = requireSession(env.store, env.host);\n\n const result = await fetchSeatsWithOneRefresh(env, session);\n\n if (result.status === 'unauthorized') {\n stillUnauthorizedSourceSeats(env.host);\n }\n\n const activeSource = readActiveSource(args.dir);\n\n return ctx.succeed(\n { host: env.host, sources: result.sources, activeSource },\n humanSummary(result.sources, activeSource),\n );\n}\n\n/**\n * Best-effort, lenient read of ekanos.json's `source` field — mirrors\n * `readProjectHost` in `auth/session.ts`. A missing, unparseable, or\n * sourceless ekanos.json (or no project at all) simply means \"no active\n * source to mark\", never an error: `sources` must answer outside a project\n * too.\n */\nfunction readActiveSource(dir: string): string | null {\n const configPath = path.join(dir, EKANOS_CONFIG_FILENAME);\n\n let raw: string;\n try {\n raw = fs.readFileSync(configPath, 'utf8');\n } catch {\n return null;\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return null;\n }\n\n const source =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as { source?: unknown }).source\n : undefined;\n\n return typeof source === 'string' && source.trim().length > 0\n ? source.trim()\n : null;\n}\n\nfunction humanSummary(\n sources: SourceSeat[],\n activeSource: string | null,\n): string {\n if (sources.length === 0) {\n return 'sources: you hold no developer seats on this host.';\n }\n\n const lines = ['sources:'];\n\n for (const source of sources) {\n const marker = source.slug === activeSource ? '*' : ' ';\n lines.push(\n ` ${marker} ${source.slug} ${source.name ?? '(unnamed)'} ` +\n `[${source.roles.join(', ')}]`,\n );\n }\n\n if (activeSource && !sources.some((s) => s.slug === activeSource)) {\n lines.push(\n ` ! this project's ekanos.json points at \"${activeSource}\", which is ` +\n `not in the list above.`,\n );\n }\n\n lines.push('(* marks the current project publish target)');\n\n return lines.join('\\n');\n}\n"]}
|
package/dist/commands/status.js
CHANGED
|
@@ -5,6 +5,7 @@ import { CliError, authRequiredError } from '../errors.js';
|
|
|
5
5
|
import { ERROR_CODES } from '../exit-codes.js';
|
|
6
6
|
import { EKANOS_CONFIG_FILENAME, loadProject } from '../project.js';
|
|
7
7
|
import { listSubmissions } from '../publish-api.js';
|
|
8
|
+
import { announceUpdate, checkForUpdate } from '../update-notice.js';
|
|
8
9
|
/**
|
|
9
10
|
* `status` — the read verb: where am I pointed, who am I, and what has this
|
|
10
11
|
* project submitted?
|
|
@@ -30,6 +31,12 @@ export async function runStatus(ctx, args) {
|
|
|
30
31
|
projectDir: args.dir,
|
|
31
32
|
});
|
|
32
33
|
const stored = env.store.read(env.host);
|
|
34
|
+
const notice = await checkForUpdate({
|
|
35
|
+
env: args.env,
|
|
36
|
+
host: env.host,
|
|
37
|
+
session: stored !== null && stored !== void 0 ? stored : undefined,
|
|
38
|
+
});
|
|
39
|
+
announceUpdate(ctx, notice);
|
|
33
40
|
const session = stored
|
|
34
41
|
? await probeSession(env, stored)
|
|
35
42
|
: {
|
|
@@ -57,8 +64,8 @@ export async function runStatus(ctx, args) {
|
|
|
57
64
|
'"ekanos publish --source <slug>" saves one, and status will list ' +
|
|
58
65
|
'submissions from then on.');
|
|
59
66
|
}
|
|
60
|
-
return ctx.succeed(Object.assign(Object.assign({ host: env.host }, session), { credentialsPath: env.store.filePath, project,
|
|
61
|
-
submissions }), humanSummary(env.host, session, project, submissions));
|
|
67
|
+
return ctx.succeed(Object.assign(Object.assign(Object.assign({ host: env.host }, session), { credentialsPath: env.store.filePath, project,
|
|
68
|
+
submissions }), (notice ? { toolchain: notice } : {})), humanSummary(env.host, session, project, submissions));
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* whoami's identity resolution, with AUTH_REQUIRED absorbed into
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,WAAW,EAAiB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAA0B,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAsBzE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAe,EACf,IAAgB;;IAEhB,MAAM,GAAG,GAAG,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;QAC3D,UAAU,EAAE,IAAI,CAAC,GAAG;KACrB,CAAC,CAAC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C,SAAS,CAAC,CAAC,CAAC,qBAAqB,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG;QAC1E,CAAC,CAAC,4BAA4B,IAAI,GAAG,CACxC,CAAC;IAEF,IAAI,OAAO,EAAE,CAAC;QACZ,KAAK,CAAC,IAAI,CACR,cAAc,OAAO,CAAC,IAAI,OAAO,OAAO,CAAC,GAAG,EAAE;YAC5C,CAAC,OAAO,CAAC,MAAM;gBACb,CAAC,CAAC,aAAa,OAAO,CAAC,MAAM,IAAI;gBACjC,CAAC,CAAC,6BAA6B,CAAC,CACrC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,KAAK,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACzC,CAAC;QAED,KAAK,MAAM,WAAW,IAAI,WAAW,EAAE,CAAC;YACtC,KAAK,MAAM,OAAO,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;gBAC3C,KAAK,CAAC,IAAI,CACR,kBAAkB,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,OAAO,KAAK;oBACxD,GAAG,OAAO,CAAC,KAAK,GACd,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe,OAAO,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,EAChE,EAAE,CACL,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { StoredSession } from '../auth/credential-store';\nimport {\n refreshStoredSession,\n resolveAuthEnvironment,\n resolveIdentity,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport { CliError, authRequiredError } from '../errors';\nimport { ERROR_CODES, type ExitCode } from '../exit-codes';\nimport { EKANOS_CONFIG_FILENAME, loadProject } from '../project';\nimport { type SubmissionListing, listSubmissions } from '../publish-api';\n\nexport interface StatusArgs {\n host?: string;\n /** Project directory (may contain ekanos.json). Defaults to cwd. */\n dir: string;\n env: Record<string, string | undefined>;\n}\n\ninterface SessionReport {\n authenticated: boolean;\n user?: { id: string; email: string | null; name: string | null };\n expiresAt?: string;\n hint?: string;\n}\n\ninterface ProjectReport {\n dir: string;\n slug: string;\n source: string | null;\n}\n\n/**\n * `status` — the read verb: where am I pointed, who am I, and what has this\n * project submitted?\n *\n * Three sections, each degrading gracefully rather than failing:\n *\n * - **session** — whoami's server-side identity check, but an absent or dead\n * session reports `authenticated: false` with a hint instead of exit 4. A\n * partner asking \"what is my state?\" must get an answer, not an error whose\n * answer it is.\n * - **project** — the ekanos.json in `--dir` (default cwd), when there is\n * one. No project is an ordinary state for `status`, never an error.\n * - **submissions** — `GET /api/partner/submissions?source=…` for the\n * project's resolved source, only when both a session and a source exist.\n * Server errors here DO map through the taxonomy: an unreachable host or a\n * missing source is a fault to surface, not a state to absorb.\n *\n * Exit 0 whenever the report itself could be assembled.\n */\nexport async function runStatus(\n ctx: CliContext,\n args: StatusArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n\n const stored = env.store.read(env.host);\n const session = stored\n ? await probeSession(env, stored)\n : {\n authenticated: false,\n hint: `Run \"ekanos login --host ${env.host}\" to sign in.`,\n };\n\n // probeSession may have refreshed the session — persisting a NEW access\n // token and ROTATING the refresh token on disk. Re-read before using it:\n // the pre-probe object now holds a dead access token and an already-spent\n // refresh token, and presenting those would turn \"logged in, token was\n // merely stale\" into a hard exit-4 — the one failure this command promises\n // never to produce.\n const live = stored ? (env.store.read(env.host) ?? stored) : null;\n\n const project = readProjectReport(args.dir);\n\n let submissions: SubmissionListing[] | null = null;\n\n if (project?.source && session.authenticated && live) {\n submissions = await listWithOneRefresh(env, live, project.source);\n } else if (project?.source && !session.authenticated) {\n ctx.log(\n `ekanos: not logged in to ${env.host} — skipping the submission list. ` +\n (session.hint ?? ''),\n );\n } else if (project && !project.source) {\n ctx.log(\n 'ekanos: this project has no \"source\" in ekanos.json yet — the first ' +\n '\"ekanos publish --source <slug>\" saves one, and status will list ' +\n 'submissions from then on.',\n );\n }\n\n return ctx.succeed(\n {\n host: env.host,\n ...session,\n credentialsPath: env.store.filePath,\n project,\n submissions,\n },\n humanSummary(env.host, session, project, submissions),\n );\n}\n\n/**\n * whoami's identity resolution, with AUTH_REQUIRED absorbed into\n * `authenticated: false`. Anything else — network, precondition, MFA mapped\n * to auth by `fetchIdentity` — still propagates: \"the host was unreachable\"\n * must never be reported as \"you are logged out\".\n */\nasync function probeSession(\n env: ReturnType<typeof resolveAuthEnvironment>,\n stored: StoredSession,\n): Promise<SessionReport> {\n try {\n const { identity, session } = await resolveIdentity(env, stored);\n\n return {\n authenticated: true,\n user: { id: identity.id, email: identity.email, name: identity.name },\n expiresAt: session.expiresAt,\n };\n } catch (error) {\n if (error instanceof CliError && error.code === ERROR_CODES.AUTH_REQUIRED) {\n return { authenticated: false, hint: error.hint };\n }\n\n throw error;\n }\n}\n\n/**\n * Lenient project read: no ekanos.json means \"not in a project\", which is an\n * answer, not an error. An ekanos.json that EXISTS but does not load keeps\n * `loadProject`'s strict behaviour — a broken project file is a fault the\n * partner needs named, whatever verb they ran.\n */\nfunction readProjectReport(dir: string): ProjectReport | null {\n const projectDir = path.resolve(dir);\n\n if (!fs.existsSync(path.join(projectDir, EKANOS_CONFIG_FILENAME))) {\n return null;\n }\n\n const loaded = loadProject(projectDir);\n\n return {\n dir: loaded.projectDir,\n slug: loaded.primary.slug,\n source: loaded.project.source ?? null,\n };\n}\n\n/** Mirrors publish's one-refresh-one-retry on a stale access token. */\nasync function listWithOneRefresh(\n env: ReturnType<typeof resolveAuthEnvironment>,\n session: StoredSession,\n source: string,\n): Promise<SubmissionListing[]> {\n const first = await listSubmissions(env.host, session.accessToken, source);\n\n if (first.status === 'ok') return first.integrations;\n\n const refreshed = await refreshStoredSession(env, session);\n const second = await listSubmissions(env.host, refreshed.accessToken, source);\n\n if (second.status === 'ok') return second.integrations;\n\n // Authenticated a moment ago, unauthorized twice here: report the list as\n // unavailable rather than the session as dead — probeSession already proved\n // it. This is unreachable in practice; belt and braces for a racing revoke.\n throw authRequiredError(\n `The session for ${env.host} could not authorize the submission list.`,\n `Run \"ekanos login --host ${env.host}\" and retry.`,\n );\n}\n\nfunction humanSummary(\n host: string,\n session: SessionReport,\n project: ProjectReport | null,\n submissions: SubmissionListing[] | null,\n): string {\n const lines: string[] = [];\n\n lines.push(\n session.authenticated\n ? `status: logged in to ${host} as ${\n session.user?.email ?? session.user?.id\n }${session.expiresAt ? ` (session expires ${session.expiresAt})` : ''}.`\n : `status: not logged in to ${host}.`,\n );\n\n if (project) {\n lines.push(\n ` project: ${project.slug} in ${project.dir}` +\n (project.source\n ? ` (source \"${project.source}\")`\n : ' (no source configured yet)'),\n );\n } else {\n lines.push(' project: none (no ekanos.json here).');\n }\n\n if (submissions) {\n if (submissions.length === 0) {\n lines.push(' submissions: none yet.');\n }\n\n for (const integration of submissions) {\n for (const version of integration.versions) {\n lines.push(\n ` submissions: ${integration.slug}@${version.version} — ` +\n `${version.state}${\n version.submittedAt ? ` (submitted ${version.submittedAt})` : ''\n }`,\n );\n }\n }\n }\n\n return lines.join('\\n');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EA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wCAAwC,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,KAAK,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QACzC,CAAC;QAED,KAAK,MAAM,WAAW,IAAI,WAAW,EAAE,CAAC;YACtC,KAAK,MAAM,OAAO,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;gBAC3C,KAAK,CAAC,IAAI,CACR,kBAAkB,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,OAAO,KAAK;oBACxD,GAAG,OAAO,CAAC,KAAK,GACd,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe,OAAO,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,EAChE,EAAE,CACL,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { StoredSession } from '../auth/credential-store';\nimport {\n refreshStoredSession,\n resolveAuthEnvironment,\n resolveIdentity,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport { CliError, authRequiredError } from '../errors';\nimport { ERROR_CODES, type ExitCode } from '../exit-codes';\nimport { EKANOS_CONFIG_FILENAME, loadProject } from '../project';\nimport { type SubmissionListing, listSubmissions } from '../publish-api';\nimport { announceUpdate, checkForUpdate } from '../update-notice';\n\nexport interface StatusArgs {\n host?: string;\n /** Project directory (may contain ekanos.json). Defaults to cwd. */\n dir: string;\n env: Record<string, string | undefined>;\n}\n\ninterface SessionReport {\n authenticated: boolean;\n user?: { id: string; email: string | null; name: string | null };\n expiresAt?: string;\n hint?: string;\n}\n\ninterface ProjectReport {\n dir: string;\n slug: string;\n source: string | null;\n}\n\n/**\n * `status` — the read verb: where am I pointed, who am I, and what has this\n * project submitted?\n *\n * Three sections, each degrading gracefully rather than failing:\n *\n * - **session** — whoami's server-side identity check, but an absent or dead\n * session reports `authenticated: false` with a hint instead of exit 4. A\n * partner asking \"what is my state?\" must get an answer, not an error whose\n * answer it is.\n * - **project** — the ekanos.json in `--dir` (default cwd), when there is\n * one. No project is an ordinary state for `status`, never an error.\n * - **submissions** — `GET /api/partner/submissions?source=…` for the\n * project's resolved source, only when both a session and a source exist.\n * Server errors here DO map through the taxonomy: an unreachable host or a\n * missing source is a fault to surface, not a state to absorb.\n *\n * Exit 0 whenever the report itself could be assembled.\n */\nexport async function runStatus(\n ctx: CliContext,\n args: StatusArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n\n const stored = env.store.read(env.host);\n\n const notice = await checkForUpdate({\n env: args.env,\n host: env.host,\n session: stored ?? undefined,\n });\n announceUpdate(ctx, notice);\n\n const session = stored\n ? await probeSession(env, stored)\n : {\n authenticated: false,\n hint: `Run \"ekanos login --host ${env.host}\" to sign in.`,\n };\n\n // probeSession may have refreshed the session — persisting a NEW access\n // token and ROTATING the refresh token on disk. Re-read before using it:\n // the pre-probe object now holds a dead access token and an already-spent\n // refresh token, and presenting those would turn \"logged in, token was\n // merely stale\" into a hard exit-4 — the one failure this command promises\n // never to produce.\n const live = stored ? (env.store.read(env.host) ?? stored) : null;\n\n const project = readProjectReport(args.dir);\n\n let submissions: SubmissionListing[] | null = null;\n\n if (project?.source && session.authenticated && live) {\n submissions = await listWithOneRefresh(env, live, project.source);\n } else if (project?.source && !session.authenticated) {\n ctx.log(\n `ekanos: not logged in to ${env.host} — skipping the submission list. ` +\n (session.hint ?? ''),\n );\n } else if (project && !project.source) {\n ctx.log(\n 'ekanos: this project has no \"source\" in ekanos.json yet — the first ' +\n '\"ekanos publish --source <slug>\" saves one, and status will list ' +\n 'submissions from then on.',\n );\n }\n\n return ctx.succeed(\n {\n host: env.host,\n ...session,\n credentialsPath: env.store.filePath,\n project,\n submissions,\n ...(notice ? { toolchain: notice } : {}),\n },\n humanSummary(env.host, session, project, submissions),\n );\n}\n\n/**\n * whoami's identity resolution, with AUTH_REQUIRED absorbed into\n * `authenticated: false`. Anything else — network, precondition, MFA mapped\n * to auth by `fetchIdentity` — still propagates: \"the host was unreachable\"\n * must never be reported as \"you are logged out\".\n */\nasync function probeSession(\n env: ReturnType<typeof resolveAuthEnvironment>,\n stored: StoredSession,\n): Promise<SessionReport> {\n try {\n const { identity, session } = await resolveIdentity(env, stored);\n\n return {\n authenticated: true,\n user: { id: identity.id, email: identity.email, name: identity.name },\n expiresAt: session.expiresAt,\n };\n } catch (error) {\n if (error instanceof CliError && error.code === ERROR_CODES.AUTH_REQUIRED) {\n return { authenticated: false, hint: error.hint };\n }\n\n throw error;\n }\n}\n\n/**\n * Lenient project read: no ekanos.json means \"not in a project\", which is an\n * answer, not an error. An ekanos.json that EXISTS but does not load keeps\n * `loadProject`'s strict behaviour — a broken project file is a fault the\n * partner needs named, whatever verb they ran.\n */\nfunction readProjectReport(dir: string): ProjectReport | null {\n const projectDir = path.resolve(dir);\n\n if (!fs.existsSync(path.join(projectDir, EKANOS_CONFIG_FILENAME))) {\n return null;\n }\n\n const loaded = loadProject(projectDir);\n\n return {\n dir: loaded.projectDir,\n slug: loaded.primary.slug,\n source: loaded.project.source ?? null,\n };\n}\n\n/** Mirrors publish's one-refresh-one-retry on a stale access token. */\nasync function listWithOneRefresh(\n env: ReturnType<typeof resolveAuthEnvironment>,\n session: StoredSession,\n source: string,\n): Promise<SubmissionListing[]> {\n const first = await listSubmissions(env.host, session.accessToken, source);\n\n if (first.status === 'ok') return first.integrations;\n\n const refreshed = await refreshStoredSession(env, session);\n const second = await listSubmissions(env.host, refreshed.accessToken, source);\n\n if (second.status === 'ok') return second.integrations;\n\n // Authenticated a moment ago, unauthorized twice here: report the list as\n // unavailable rather than the session as dead — probeSession already proved\n // it. This is unreachable in practice; belt and braces for a racing revoke.\n throw authRequiredError(\n `The session for ${env.host} could not authorize the submission list.`,\n `Run \"ekanos login --host ${env.host}\" and retry.`,\n );\n}\n\nfunction humanSummary(\n host: string,\n session: SessionReport,\n project: ProjectReport | null,\n submissions: SubmissionListing[] | null,\n): string {\n const lines: string[] = [];\n\n lines.push(\n session.authenticated\n ? `status: logged in to ${host} as ${\n session.user?.email ?? session.user?.id\n }${session.expiresAt ? ` (session expires ${session.expiresAt})` : ''}.`\n : `status: not logged in to ${host}.`,\n );\n\n if (project) {\n lines.push(\n ` project: ${project.slug} in ${project.dir}` +\n (project.source\n ? ` (source \"${project.source}\")`\n : ' (no source configured yet)'),\n );\n } else {\n lines.push(' project: none (no ekanos.json here).');\n }\n\n if (submissions) {\n if (submissions.length === 0) {\n lines.push(' submissions: none yet.');\n }\n\n for (const integration of submissions) {\n for (const version of integration.versions) {\n lines.push(\n ` submissions: ${integration.slug}@${version.version} — ` +\n `${version.state}${\n version.submittedAt ? ` (submitted ${version.submittedAt})` : ''\n }`,\n );\n }\n }\n }\n\n return lines.join('\\n');\n}\n"]}
|