@sylphx/cli 0.13.1 → 0.14.1

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/dist/main.js CHANGED
@@ -15,7 +15,7 @@ var init_package = __esm({
15
15
  "package.json"() {
16
16
  package_default = {
17
17
  name: "@sylphx/cli",
18
- version: "0.13.1",
18
+ version: "0.14.1",
19
19
  description: "Sylphx Platform CLI \u2014 deploy and manage your applications from the terminal. 63 commands across deployment, logs, env vars, domains, databases, storage, monitoring, self-service (user), admin (users/quotas/audit/invitations/jwt-keys/project-migrate), and more.",
20
20
  type: "module",
21
21
  homepage: "https://sylphx.com",
@@ -12249,7 +12249,14 @@ var init_project_manifest = __esm({
12249
12249
  * apps that need one migration/release hook tied to a specific image.
12250
12250
  */
12251
12251
  release_command: Schema91.optional(Schema91.String),
12252
- /** Service port; required for `web` when it cannot be detected automatically. */
12252
+ /**
12253
+ * Advanced internal app listen-port override.
12254
+ *
12255
+ * Public URLs never expose this value — HTTP(S) remains 80/443 via platform
12256
+ * routing. When omitted for `type="web"`, the platform injects a default PORT
12257
+ * and wires the runtime to it.
12258
+ * `type="worker"` services must omit the field.
12259
+ */
12253
12260
  port: Schema91.optional(Schema91.Number.pipe(Schema91.int(), Schema91.between(1, 65535))),
12254
12261
  /** Explicit instance count. */
12255
12262
  instances: Schema91.optional(ManifestServiceInstanceCount),
@@ -12379,6 +12386,7 @@ var init_project_manifest = __esm({
12379
12386
  name: Slug2,
12380
12387
  type: Schema91.optional(ServiceType),
12381
12388
  command: Schema91.optional(Schema91.String),
12389
+ /** Advanced internal app listen-port override; see ManifestServiceSection.port. */
12382
12390
  port: Schema91.optional(Schema91.Number.pipe(Schema91.int(), Schema91.between(1, 65535))),
12383
12391
  instances: Schema91.optional(ManifestServiceInstanceCount),
12384
12392
  instance_type: Schema91.optional(MachineSize),
@@ -16335,11 +16343,12 @@ __export(environments_exports, {
16335
16343
  create: () => create4,
16336
16344
  delete: () => _delete4,
16337
16345
  list: () => list7,
16346
+ logs: () => logs,
16338
16347
  promote: () => promote,
16339
16348
  resolveId: () => resolveId,
16340
16349
  update: () => update2
16341
16350
  });
16342
- var orgHeaders2, list7, resolveId, promote, create4, update2, _delete4, clone;
16351
+ var orgHeaders2, list7, resolveId, promote, logs, create4, update2, _delete4, clone;
16343
16352
  var init_environments2 = __esm({
16344
16353
  "../management/dist/environments.js"() {
16345
16354
  "use strict";
@@ -16379,6 +16388,19 @@ var init_environments2 = __esm({
16379
16388
  headers: orgHeaders2(options)
16380
16389
  });
16381
16390
  };
16391
+ logs = (client, envId, options = {}) => {
16392
+ const { method, path: path7 } = environmentsEndpoints.logs;
16393
+ return request(client, method, interpolatePath(path7, { envId }), {
16394
+ query: {
16395
+ type: options.type,
16396
+ deploymentId: options.deploymentId,
16397
+ since: options.since,
16398
+ limit: options.limit === void 0 ? void 0 : String(options.limit),
16399
+ level: options.level
16400
+ },
16401
+ headers: orgHeaders2(options)
16402
+ });
16403
+ };
16382
16404
  create4 = (client, projectId, input, options = {}) => {
16383
16405
  const { method, path: path7 } = environmentsEndpoints.createStandalone;
16384
16406
  return request(client, method, path7, {
@@ -17555,7 +17577,7 @@ __export(saml_exports, {
17555
17577
  create: () => create13,
17556
17578
  delete: () => _delete11,
17557
17579
  get: () => get8,
17558
- logs: () => logs,
17580
+ logs: () => logs2,
17559
17581
  metadata: () => metadata,
17560
17582
  nameIdFormats: () => nameIdFormats,
17561
17583
  setStatus: () => setStatus,
@@ -17564,7 +17586,7 @@ __export(saml_exports, {
17564
17586
  testConfig: () => testConfig,
17565
17587
  update: () => update5
17566
17588
  });
17567
- var get8, create13, update5, setStatus, _delete11, metadata, logs, testConfig, templates, nameIdFormats, signatureAlgorithms;
17589
+ var get8, create13, update5, setStatus, _delete11, metadata, logs2, testConfig, templates, nameIdFormats, signatureAlgorithms;
17568
17590
  var init_saml3 = __esm({
17569
17591
  "../management/dist/saml.js"() {
17570
17592
  "use strict";
@@ -17594,7 +17616,7 @@ var init_saml3 = __esm({
17594
17616
  const { method, path: path7 } = samlEndpoints.getMetadata;
17595
17617
  return request(client, method, path7, { query: { organizationId } });
17596
17618
  };
17597
- logs = (client, providerId, limit) => {
17619
+ logs2 = (client, providerId, limit) => {
17598
17620
  const { method, path: path7 } = samlEndpoints.getLogs;
17599
17621
  return request(client, method, path7, {
17600
17622
  query: { providerId, limit: limit !== void 0 ? String(limit) : void 0 }
@@ -18744,6 +18766,13 @@ function readLinkedProject(filePath) {
18744
18766
  ...orgSlug ? { orgSlug } : {}
18745
18767
  };
18746
18768
  }
18769
+ function readProjectManifestOrg(filePath) {
18770
+ const manifest = parseManifestFile(filePath);
18771
+ const project = getProjectSection(manifest, filePath);
18772
+ if (!project) return void 0;
18773
+ const org = readString("project", project, "org")?.trim();
18774
+ return org && org.length > 0 ? org : void 0;
18775
+ }
18747
18776
  function requireLinkMetadata(link, key) {
18748
18777
  const value = link[key];
18749
18778
  if (typeof value === "string" && value.length > 0) return value;
@@ -18910,6 +18939,10 @@ var init_config = __esm({
18910
18939
  const manifestPath = findManifestPath(dir ?? process.cwd());
18911
18940
  return manifestPath ? readLinkedProject(manifestPath) : void 0;
18912
18941
  },
18942
+ getProjectManifestOrg(dir) {
18943
+ const manifestPath = findManifestPath(dir ?? process.cwd());
18944
+ return manifestPath ? readProjectManifestOrg(manifestPath) : void 0;
18945
+ },
18913
18946
  linkProject(link, dir) {
18914
18947
  writeLinkedProject(link, dir ?? process.cwd());
18915
18948
  },
@@ -19344,6 +19377,8 @@ function resolvePreferredOrgId() {
19344
19377
  const value = process.env[key]?.trim();
19345
19378
  if (value) return value;
19346
19379
  }
19380
+ const linked = config.getLinkedProject();
19381
+ if (linked?.orgId) return linked.orgId;
19347
19382
  return config.getDefaultOrg();
19348
19383
  }
19349
19384
  function mapRefreshFailure(cause) {
@@ -19486,6 +19521,21 @@ async function authedFetch(path7, init = {}) {
19486
19521
  return await res.text();
19487
19522
  });
19488
19523
  }
19524
+ async function resolveLogStreamToken() {
19525
+ if (isExternalAuthActive()) {
19526
+ const auth = resolveAuthToken();
19527
+ if (!auth.token) throw new ApiError2(401, unauthenticatedMessage(auth));
19528
+ return auth.token;
19529
+ }
19530
+ let token;
19531
+ try {
19532
+ token = await ensureFreshAccessToken();
19533
+ } catch (err) {
19534
+ throw mapRefreshFailure(err);
19535
+ }
19536
+ if (!token) throw new ApiError2(401, unauthenticatedMessage());
19537
+ return token;
19538
+ }
19489
19539
  async function createLogStream(projectId, envType, options) {
19490
19540
  const params = new URLSearchParams({ stream: "true", limit: "200" });
19491
19541
  if (options?.envId) {
@@ -19494,25 +19544,30 @@ async function createLogStream(projectId, envType, options) {
19494
19544
  params.set("envType", envType);
19495
19545
  }
19496
19546
  const preferredOrgId = options?.orgId ?? resolvePreferredOrgId();
19497
- let token;
19498
- if (isExternalAuthActive()) {
19499
- const auth = resolveAuthToken();
19500
- if (!auth.token) throw new ApiError2(401, unauthenticatedMessage(auth));
19501
- token = auth.token;
19502
- } else {
19503
- try {
19504
- token = await ensureFreshAccessToken();
19505
- } catch (err) {
19506
- throw mapRefreshFailure(err);
19507
- }
19508
- }
19509
- if (!token) throw new ApiError2(401, unauthenticatedMessage());
19547
+ const token = await resolveLogStreamToken();
19510
19548
  return {
19511
19549
  url: `${API_BASE}/projects/${encodeURIComponent(projectId)}/logs?${params.toString()}`,
19512
19550
  token,
19513
19551
  ...preferredOrgId ? { headers: { "X-Preferred-Org-Id": preferredOrgId } } : {}
19514
19552
  };
19515
19553
  }
19554
+ async function createEnvironmentLogStream(envId, options = {}) {
19555
+ const params = new URLSearchParams({
19556
+ stream: "true",
19557
+ type: options.type ?? "runtime",
19558
+ limit: String(options.limit ?? 200)
19559
+ });
19560
+ if (options.deploymentId) params.set("deploymentId", options.deploymentId);
19561
+ if (options.since) params.set("since", options.since);
19562
+ if (options.level) params.set("level", options.level);
19563
+ const preferredOrgId = options.orgId ?? resolvePreferredOrgId();
19564
+ const token = await resolveLogStreamToken();
19565
+ return {
19566
+ url: `${API_BASE}/environments/${encodeURIComponent(envId)}/logs?${params.toString()}`,
19567
+ token,
19568
+ ...preferredOrgId ? { headers: { "X-Preferred-Org-Id": preferredOrgId } } : {}
19569
+ };
19570
+ }
19516
19571
  var version, BASE_URL, USER_AGENT, PREFERRED_ORG_ENV_VARS, api, API_BASE;
19517
19572
  var init_api = __esm({
19518
19573
  "src/api.ts"() {
@@ -19603,6 +19658,7 @@ var init_api = __esm({
19603
19658
  // ── Environments ───────────────────────────────────────────────────────
19604
19659
  listEnvironments: (projectId) => withClient((c2) => environments_exports.list(c2, projectId)),
19605
19660
  resolveEnvId: (projectId, envType) => withClient((c2) => environments_exports.resolveId(c2, projectId, envType)),
19661
+ listEnvironmentLogs: (envId, options) => withClient((c2) => environments_exports.logs(c2, envId, options)),
19606
19662
  createEnvironment: (projectId, body) => withClient((c2) => environments_exports.create(c2, projectId, body)),
19607
19663
  updateEnvironment: (envId, body) => withClient((c2) => environments_exports.update(c2, envId, body)),
19608
19664
  deleteEnvironment: (envId) => withClient((c2) => environments_exports.delete(c2, envId)),
@@ -19931,7 +19987,7 @@ var init_oidc4 = __esm({
19931
19987
 
19932
19988
  // src/main.ts
19933
19989
  init_package();
19934
- import { Command as Command71 } from "@effect/cli";
19990
+ import { Command as Command71, HelpDoc, ValidationError } from "@effect/cli";
19935
19991
  import { BunContext, BunRuntime } from "@effect/platform-bun";
19936
19992
  import { Console as Console71, Effect as Effect81, Layer as Layer5 } from "effect";
19937
19993
 
@@ -20172,10 +20228,18 @@ var ApiServiceLive = Layer2.succeed(ApiService, {
20172
20228
  try: () => createLogStream(projectId, envType, options),
20173
20229
  catch: mapApiError("logs")
20174
20230
  }),
20231
+ createEnvironmentLogStream: (envId, options) => Effect7.tryPromise({
20232
+ try: () => createEnvironmentLogStream(envId, options),
20233
+ catch: mapApiError("logs")
20234
+ }),
20175
20235
  listProjectLogs: (projectId, options) => Effect7.tryPromise({
20176
20236
  try: () => withAuthedSdk((c2) => logs_exports.list(c2, projectId, options)),
20177
20237
  catch: mapApiError("logs")
20178
20238
  }),
20239
+ listEnvironmentLogs: (envId, options) => Effect7.tryPromise({
20240
+ try: () => withAuthedSdk((c2) => environments_exports.logs(c2, envId, options)),
20241
+ catch: mapApiError("logs")
20242
+ }),
20179
20243
  triggerDeploy: (projectId, envType, options) => Effect7.tryPromise({
20180
20244
  try: () => withAuthedSdk((c2) => deployments_exports.trigger(c2, projectId, envType, options)),
20181
20245
  catch: mapApiError("deploy")
@@ -20704,6 +20768,7 @@ var ConfigServiceLive = Layer3.succeed(ConfigService, {
20704
20768
  getDefaultOrg: Effect8.sync(() => config.getDefaultOrg()),
20705
20769
  setDefaultOrg: (org) => Effect8.sync(() => config.setDefaultOrg(org)),
20706
20770
  getLinkedProject: (dir) => Effect8.sync(() => config.getLinkedProject(dir)),
20771
+ getProjectManifestOrg: (dir) => Effect8.sync(() => config.getProjectManifestOrg(dir)),
20707
20772
  linkProject: (link, dir) => Effect8.sync(() => config.linkProject(link, dir)),
20708
20773
  unlinkProject: (dir) => Effect8.sync(() => config.unlinkProject(dir)),
20709
20774
  getConfigPath: Effect8.sync(() => config.getConfigPath()),
@@ -25547,7 +25612,14 @@ function parseLogLine(raw) {
25547
25612
  const level = status3 === "error" || status3 === "failed" ? "error" : status3 === "success" || status3 === "done" ? "success" : lvl;
25548
25613
  const tsRaw = entry.timestamp ?? entry.ts;
25549
25614
  const timestamp = tsRaw ? new Date(tsRaw) : void 0;
25550
- return { raw, entry, message, level, timestamp, service: entry.service };
25615
+ return {
25616
+ raw,
25617
+ entry,
25618
+ message,
25619
+ level,
25620
+ timestamp,
25621
+ service: entry.service ?? entry.source ?? void 0
25622
+ };
25551
25623
  }
25552
25624
  function formatLogEntry(raw) {
25553
25625
  let entry;
@@ -26342,29 +26414,45 @@ async function fetchLatestVersion() {
26342
26414
  return void 0;
26343
26415
  }
26344
26416
  }
26345
- async function runUpdateCheck() {
26346
- if (!shouldRunUpdateCheckForInvocation()) return;
26347
- const now = Date.now();
26348
- const cache = readCache();
26349
- const hitRegistry = shouldHitRegistry(now, cache);
26350
- let latest = cache?.latestKnown ?? void 0;
26417
+ async function resolveLatestVersionForNotice(opts) {
26418
+ const fetchLatest = opts.fetchLatestVersion ?? fetchLatestVersion;
26419
+ const persistCache = opts.writeCache ?? writeCache;
26420
+ const hitRegistry = shouldHitRegistry(opts.now, opts.cache);
26421
+ let latest = opts.cache?.latestKnown ?? void 0;
26351
26422
  if (hitRegistry) {
26352
- const fetched = await fetchLatestVersion();
26423
+ const fetched = await fetchLatest();
26424
+ latest = fetched;
26425
+ persistCache({
26426
+ lastCheck: opts.now,
26427
+ latestKnown: fetched ?? null
26428
+ });
26429
+ } else if (latest && compareSemver(opts.current, latest) < 0) {
26430
+ const fetched = await fetchLatest();
26353
26431
  latest = fetched;
26354
- writeCache({
26355
- lastCheck: now,
26432
+ persistCache({
26433
+ lastCheck: opts.now,
26356
26434
  latestKnown: fetched ?? null
26357
26435
  });
26358
26436
  }
26359
- if (!latest) return;
26437
+ if (!latest) return void 0;
26438
+ return compareSemver(opts.current, latest) < 0 ? latest : void 0;
26439
+ }
26440
+ async function runUpdateCheck() {
26441
+ if (!shouldRunUpdateCheckForInvocation()) return;
26442
+ const now = Date.now();
26443
+ const cache = readCache();
26360
26444
  const current2 = currentCliVersion();
26361
- if (compareSemver(current2, latest) < 0) {
26362
- process.stderr.write(
26363
- `
26445
+ const latest = await resolveLatestVersionForNotice({
26446
+ current: current2,
26447
+ now,
26448
+ cache
26449
+ });
26450
+ if (!latest) return;
26451
+ process.stderr.write(
26452
+ `
26364
26453
  [sylphx] Update available: ${current2} \u2192 ${latest}. Run \`bun add -g @sylphx/cli@latest\` (or \`npm i -g @sylphx/cli\`) to upgrade. Set SYLPHX_NO_UPDATE_CHECK=1 to silence.
26365
26454
  `
26366
- );
26367
- }
26455
+ );
26368
26456
  }
26369
26457
 
26370
26458
  // src/programs/doctor.ts
@@ -29411,7 +29499,7 @@ var inspectCommand = Command28.make(
29411
29499
  Options30.withDescription("Machine-readable JSON output (no colour)")
29412
29500
  )
29413
29501
  },
29414
- ({ id, wait, logs: logs2, json }) => inspectEffect({ id, wait, logs: logs2, json })
29502
+ ({ id, wait, logs: logs3, json }) => inspectEffect({ id, wait, logs: logs3, json })
29415
29503
  ).pipe(Command28.withDescription("Inspect a deployment by id"));
29416
29504
 
29417
29505
  // src/programs/link.ts
@@ -29796,6 +29884,10 @@ var serviceOption = Options32.text("service").pipe(
29796
29884
  Options32.withDescription("Restrict to a single service"),
29797
29885
  Options32.optional
29798
29886
  );
29887
+ var logTypeOption = Options32.choice("type", ["runtime", "build"]).pipe(
29888
+ Options32.withDescription("Log source to inspect: runtime app logs or build/deploy logs"),
29889
+ Options32.withDefault("runtime")
29890
+ );
29799
29891
  var jsonOption = Options32.boolean("json").pipe(
29800
29892
  Options32.withDescription("Emit machine-readable NDJSON (one JSON object per line)")
29801
29893
  );
@@ -29903,6 +29995,7 @@ function tailFormat(line) {
29903
29995
  }
29904
29996
  function describeFilters(opts) {
29905
29997
  const parts = [];
29998
+ if (opts.type) parts.push(`type=${opts.type}`);
29906
29999
  if (opts.levels && opts.levels.size > 0) {
29907
30000
  const lst = [...opts.levels].sort().join("/");
29908
30001
  parts.push(opts.levels.size === 1 ? `${lst} only` : `levels=${lst}`);
@@ -29940,13 +30033,13 @@ function logsEffect(input) {
29940
30033
  );
29941
30034
  const target = input.env ?? targetProject.defaultEnv;
29942
30035
  const scope = orgId ? { orgId } : void 0;
29943
- const resolvedEnvId = input.env ? yield* api2.resolveEnvId(targetProject.projectId, input.env, scope) : null;
29944
- if (input.env && !resolvedEnvId) {
30036
+ const resolvedEnvId = yield* api2.resolveEnvId(targetProject.projectId, target, scope);
30037
+ if (!resolvedEnvId) {
29945
30038
  return yield* Effect42.fail(
29946
30039
  new CliCommandError({
29947
30040
  command: "logs",
29948
30041
  reason: "not-found",
29949
- message: `Environment not found: ${input.env}`
30042
+ message: `Environment not found: ${target}`
29950
30043
  })
29951
30044
  );
29952
30045
  }
@@ -29954,10 +30047,11 @@ function logsEffect(input) {
29954
30047
  yield* Console32.log("");
29955
30048
  yield* Console32.log(
29956
30049
  chalk_default.bold(
29957
- ` Logs for ${chalk_default.cyan(targetProject.projectId)} [${chalk_default.white(target)}]${input.follow ? chalk_default.dim(" (following...)") : ""}`
30050
+ ` ${input.type} logs for ${chalk_default.cyan(targetProject.projectId)} [${chalk_default.white(target)}]${input.follow ? chalk_default.dim(" (following...)") : ""}`
29958
30051
  )
29959
30052
  );
29960
30053
  const summary2 = describeFilters({
30054
+ type: input.type,
29961
30055
  levels,
29962
30056
  sinceRaw: input.since,
29963
30057
  grepRaw: input.grep,
@@ -29968,32 +30062,51 @@ function logsEffect(input) {
29968
30062
  yield* Console32.log(chalk_default.dim(` ${"\u2500".repeat(50)}`));
29969
30063
  yield* Console32.log("");
29970
30064
  }
29971
- const logStream = yield* api2.createLogStream(
29972
- targetProject.projectId,
29973
- target,
29974
- orgId || resolvedEnvId ? { ...orgId ? { orgId } : {}, ...resolvedEnvId ? { envId: resolvedEnvId } : {} } : void 0
29975
- );
29976
- const url = appendQuery(logStream.url, {
29977
- since: since ? String(since.getTime()) : void 0,
29978
- limit: input.tail ? String(input.tail) : void 0,
29979
- service: input.service
29980
- });
29981
30065
  const filter = buildFilter({ levels, since, grep, service: input.service });
29982
- yield* Effect42.tryPromise({
29983
- try: () => streamLogs(url, logStream.token, {
29984
- follow: input.follow,
29985
- exitOnDone: false,
29986
- filter,
29987
- format: input.json ? jsonFormat : void 0,
29988
- limit: input.tail,
29989
- headers: logStream.headers
29990
- }),
29991
- catch: (cause) => new CliCommandError({
29992
- command: "logs",
29993
- reason: "transient",
29994
- message: `Log stream failed: ${cause instanceof Error ? cause.message : String(cause)}`
29995
- })
29996
- });
30066
+ if (!input.follow) {
30067
+ const result = yield* api2.listEnvironmentLogs(resolvedEnvId, {
30068
+ type: input.type,
30069
+ ...orgId ? { orgId } : {},
30070
+ ...since ? { since: since.toISOString() } : {},
30071
+ ...input.tail ? { limit: input.tail } : {},
30072
+ ...levels.size === 1 ? { level: [...levels][0] } : {}
30073
+ });
30074
+ let emitted = 0;
30075
+ for (const entry of result.data) {
30076
+ const raw = JSON.stringify(entry);
30077
+ const line = parseLogLine(raw);
30078
+ if (!filter(line)) continue;
30079
+ yield* Console32.log(input.json ? jsonFormat(line) : formatLogEntry(raw));
30080
+ emitted++;
30081
+ if (input.tail && emitted >= input.tail) break;
30082
+ }
30083
+ } else {
30084
+ const logStream = yield* api2.createEnvironmentLogStream(resolvedEnvId, {
30085
+ type: input.type,
30086
+ ...orgId ? { orgId } : {},
30087
+ ...since ? { since: since.toISOString() } : {},
30088
+ ...input.tail ? { limit: input.tail } : {},
30089
+ ...levels.size === 1 ? { level: [...levels][0] } : {}
30090
+ });
30091
+ const url = appendQuery(logStream.url, {
30092
+ service: input.service
30093
+ });
30094
+ yield* Effect42.tryPromise({
30095
+ try: () => streamLogs(url, logStream.token, {
30096
+ follow: true,
30097
+ exitOnDone: false,
30098
+ filter,
30099
+ format: input.json ? jsonFormat : void 0,
30100
+ limit: input.tail,
30101
+ headers: logStream.headers
30102
+ }),
30103
+ catch: (cause) => new CliCommandError({
30104
+ command: "logs",
30105
+ reason: "transient",
30106
+ message: `Log stream failed: ${cause instanceof Error ? cause.message : String(cause)}`
30107
+ })
30108
+ });
30109
+ }
29997
30110
  if (!input.follow && !input.json) {
29998
30111
  yield* Console32.log("");
29999
30112
  }
@@ -30019,6 +30132,7 @@ var logsCommand = Command32.make(
30019
30132
  project: projectOption18,
30020
30133
  org: orgOption9,
30021
30134
  env: envOption9,
30135
+ type: logTypeOption,
30022
30136
  follow: followOption,
30023
30137
  level: levelOption,
30024
30138
  since: sinceOption,
@@ -30027,10 +30141,11 @@ var logsCommand = Command32.make(
30027
30141
  service: serviceOption,
30028
30142
  json: jsonOption
30029
30143
  },
30030
- ({ project, org, env, follow, level, since, tail, grep, service, json }) => logsEffect({
30144
+ ({ project, org, env, type, follow, level, since, tail, grep, service, json }) => logsEffect({
30031
30145
  project: project._tag === "Some" ? project.value : void 0,
30032
30146
  org: org._tag === "Some" ? org.value : void 0,
30033
30147
  env: env._tag === "Some" ? env.value : void 0,
30148
+ type,
30034
30149
  follow,
30035
30150
  level,
30036
30151
  since: since._tag === "Some" ? since.value : void 0,
@@ -30039,7 +30154,11 @@ var logsCommand = Command32.make(
30039
30154
  service: service._tag === "Some" ? service.value : void 0,
30040
30155
  json
30041
30156
  })
30042
- ).pipe(Command32.withDescription("Stream build/runtime logs"));
30157
+ ).pipe(
30158
+ Command32.withDescription(
30159
+ "Inspect runtime logs; use --follow for SSE or --type build for deploy logs"
30160
+ )
30161
+ );
30043
30162
 
30044
30163
  // src/programs/migrate.ts
30045
30164
  import { Command as Command33, Options as Options34 } from "@effect/cli";
@@ -31596,14 +31715,10 @@ var orgsShowEffect = orgsShowEffectWith("pretty");
31596
31715
  function orgsShowEffectWith(output) {
31597
31716
  return Effect48.gen(function* () {
31598
31717
  yield* requireAuthEffect;
31599
- const api2 = yield* ApiService;
31600
- const [org, me] = yield* withSpinner(
31601
- "Fetching org info...",
31602
- Effect48.all([api2.getCurrentOrg, api2.whoami])
31603
- );
31718
+ const { org, orgs } = yield* withSpinner("Fetching org info...", resolveOrgDisplayContext);
31604
31719
  const formatter = makeFormatter(output);
31605
31720
  yield* formatter.print(
31606
- { org, orgs: me.orgs },
31721
+ { org, orgs },
31607
31722
  () => Effect48.gen(function* () {
31608
31723
  yield* Console38.log("");
31609
31724
  yield* Console38.log(chalk_default.bold(" Organization"));
@@ -31612,9 +31727,9 @@ function orgsShowEffectWith(output) {
31612
31727
  yield* Console38.log(` ${chalk_default.bold("Slug")} ${chalk_default.cyan(org.slug)}`);
31613
31728
  yield* Console38.log(` ${chalk_default.bold("ID")} ${chalk_default.dim(org.id)}`);
31614
31729
  yield* Console38.log("");
31615
- if (me.orgs.length > 1) {
31616
- yield* Console38.log(chalk_default.dim(` You are a member of ${me.orgs.length} organizations:`));
31617
- for (const o of me.orgs) {
31730
+ if (orgs.length > 1) {
31731
+ yield* Console38.log(chalk_default.dim(` You are a member of ${orgs.length} organizations:`));
31732
+ for (const o of orgs) {
31618
31733
  const isCurrent = o.id === org.id;
31619
31734
  yield* Console38.log(
31620
31735
  ` ${isCurrent ? chalk_default.green("\u2192") : " "} ${chalk_default.bold(o.name)} ${chalk_default.dim(`(${o.slug})`)}`
@@ -31626,10 +31741,51 @@ function orgsShowEffectWith(output) {
31626
31741
  );
31627
31742
  });
31628
31743
  }
31744
+ var resolveOrgDisplayContext = Effect48.gen(function* () {
31745
+ const api2 = yield* ApiService;
31746
+ const cfg = yield* ConfigService;
31747
+ const linked = yield* cfg.getLinkedProject();
31748
+ if (linked) {
31749
+ const me2 = yield* api2.whoami;
31750
+ const org2 = findOrg3(me2.orgs, linked.orgId, linked.orgSlug);
31751
+ if (!org2) {
31752
+ return yield* Effect48.fail(
31753
+ new CliCommandError({
31754
+ command: "orgs",
31755
+ reason: "no-org",
31756
+ message: `Linked project organization '${linked.orgSlug ?? linked.orgId}' was not found for the current account.`
31757
+ })
31758
+ );
31759
+ }
31760
+ return { org: { ...org2, email: null }, orgs: me2.orgs };
31761
+ }
31762
+ const manifestOrg = cfg.getProjectManifestOrg ? yield* cfg.getProjectManifestOrg() : void 0;
31763
+ if (manifestOrg) {
31764
+ const me2 = yield* api2.whoami;
31765
+ const org2 = findOrg3(me2.orgs, manifestOrg);
31766
+ if (!org2) {
31767
+ return yield* Effect48.fail(
31768
+ new CliCommandError({
31769
+ command: "orgs",
31770
+ reason: "no-org",
31771
+ message: `Project manifest organization '${manifestOrg}' was not found for the current account.`
31772
+ })
31773
+ );
31774
+ }
31775
+ return { org: { ...org2, email: null }, orgs: me2.orgs };
31776
+ }
31777
+ const [org, me] = yield* Effect48.all([api2.getCurrentOrg, api2.whoami]);
31778
+ return { org, orgs: me.orgs };
31779
+ });
31780
+ var resolveActiveOrg = Effect48.map(resolveOrgDisplayContext, ({ org }) => org);
31781
+ function findOrg3(orgs, primaryRef, secondaryRef) {
31782
+ const refs = new Set([primaryRef, secondaryRef].filter((ref) => Boolean(ref)));
31783
+ return orgs.find((candidate) => refs.has(candidate.id) || refs.has(candidate.slug));
31784
+ }
31629
31785
  var membersListEffect = Effect48.gen(function* () {
31630
31786
  yield* requireAuthEffect;
31631
31787
  const api2 = yield* ApiService;
31632
- const org = yield* api2.getCurrentOrg;
31788
+ const org = yield* resolveActiveOrg;
31633
31789
  const members = yield* withSpinner("Fetching members...", api2.listOrgMembers(org.id));
31634
31790
  if (members.length === 0) {
31635
31791
  yield* Console38.log(chalk_default.dim("\n No members found.\n"));
@@ -31667,7 +31823,7 @@ function membersInviteEffect(input) {
31667
31823
  }
31668
31824
  yield* requireAuthEffect;
31669
31825
  const api2 = yield* ApiService;
31670
- const org = yield* api2.getCurrentOrg;
31826
+ const org = yield* resolveActiveOrg;
31671
31827
  yield* withSpinner(
31672
31828
  `Inviting ${input.email}...`,
31673
31829
  api2.inviteOrgMember(org.id, input.email, input.role)
@@ -31684,7 +31840,7 @@ function membersRemoveEffect(userId) {
31684
31840
  return Effect48.gen(function* () {
31685
31841
  yield* requireAuthEffect;
31686
31842
  const api2 = yield* ApiService;
31687
- const org = yield* api2.getCurrentOrg;
31843
+ const org = yield* resolveActiveOrg;
31688
31844
  yield* withSpinner(`Removing member ${userId}...`, api2.removeOrgMember(org.id, userId));
31689
31845
  yield* Console38.log(
31690
31846
  chalk_default.green(`\u2713 Removed member ${chalk_default.bold(userId)} from ${chalk_default.bold(org.name)}`)
@@ -31704,7 +31860,7 @@ function membersSetRoleEffect(input) {
31704
31860
  }
31705
31861
  yield* requireAuthEffect;
31706
31862
  const api2 = yield* ApiService;
31707
- const org = yield* api2.getCurrentOrg;
31863
+ const org = yield* resolveActiveOrg;
31708
31864
  const needsConfirm = !input.yes && (input.role === "super_admin" || input.role === "admin");
31709
31865
  if (needsConfirm) {
31710
31866
  const ok = yield* confirmEffect(
@@ -31770,7 +31926,7 @@ var orgsBillingEffect = Effect48.gen(function* () {
31770
31926
  const api2 = yield* ApiService;
31771
31927
  const [org, snap] = yield* withSpinner(
31772
31928
  "Fetching billing snapshot...",
31773
- Effect48.all([api2.getCurrentOrg, api2.getOrgBillingSnapshot])
31929
+ Effect48.all([resolveActiveOrg, api2.getOrgBillingSnapshot])
31774
31930
  );
31775
31931
  yield* Console38.log("");
31776
31932
  yield* Console38.log(chalk_default.bold(` Billing \u2014 ${org.name}`));
@@ -31846,7 +32002,7 @@ function teamEffect(input) {
31846
32002
  }
31847
32003
  yield* requireAuthEffect;
31848
32004
  const api2 = yield* ApiService;
31849
- const org = yield* api2.getCurrentOrg;
32005
+ const org = yield* resolveActiveOrg;
31850
32006
  const all = yield* withSpinner("Fetching team...", api2.listOrgMembers(org.id));
31851
32007
  const members = input.role ? all.filter((m) => m.role.toLowerCase() === input.role?.toLowerCase()) : all;
31852
32008
  if (members.length === 0) {
@@ -31966,6 +32122,14 @@ var orgsCommand = Command38.make(
31966
32122
  Command38.withDescription("Manage organizations"),
31967
32123
  Command38.withSubcommands([membersCmd, billingCmd, sessionsCmd, teamCmd, auditCmd2])
31968
32124
  );
32125
+ var orgCommand = Command38.make(
32126
+ "org",
32127
+ { output: outputOption },
32128
+ ({ output }) => orgsShowEffectWith(output)
32129
+ ).pipe(
32130
+ Command38.withDescription("Alias for `orgs`"),
32131
+ Command38.withSubcommands([membersCmd, billingCmd, sessionsCmd, teamCmd, auditCmd2])
32132
+ );
31969
32133
 
31970
32134
  // src/programs/plan.ts
31971
32135
  import { Args as Args25, Command as Command39, Options as Options40 } from "@effect/cli";
@@ -36914,8 +37078,20 @@ function tailEffect(input) {
36914
37078
  projectId = linked.projectId;
36915
37079
  target = input.env ?? linked.defaultEnv;
36916
37080
  }
37081
+ const scope = orgId ? { orgId } : void 0;
37082
+ const envId = yield* api2.resolveEnvId(projectId, target, scope);
37083
+ if (!envId) {
37084
+ return yield* Effect71.fail(
37085
+ new CliCommandError({
37086
+ command: "tail",
37087
+ reason: "not-found",
37088
+ message: `Environment not found: ${target}`
37089
+ })
37090
+ );
37091
+ }
36917
37092
  if (!input.json) {
36918
37093
  const summary2 = describeFilters({
37094
+ type: input.type,
36919
37095
  levels,
36920
37096
  sinceRaw: input.since,
36921
37097
  grepRaw: input.grep,
@@ -36924,14 +37100,20 @@ function tailEffect(input) {
36924
37100
  });
36925
37101
  yield* Console61.log("");
36926
37102
  yield* Console61.log(
36927
- chalk_default.dim(` tailing ${chalk_default.cyan(projectId)} [${chalk_default.white(target)}] \xB7 ${summary2}`)
37103
+ chalk_default.dim(
37104
+ ` tailing ${input.type} logs for ${chalk_default.cyan(projectId)} [${chalk_default.white(target)}] \xB7 ${summary2}`
37105
+ )
36928
37106
  );
36929
37107
  yield* Console61.log("");
36930
37108
  }
36931
- const logStream = yield* api2.createLogStream(projectId, target, orgId ? { orgId } : void 0);
37109
+ const logStream = yield* api2.createEnvironmentLogStream(envId, {
37110
+ type: input.type,
37111
+ ...orgId ? { orgId } : {},
37112
+ ...since ? { since: since.toISOString() } : {},
37113
+ ...input.tail ? { limit: input.tail } : {},
37114
+ ...levels.size === 1 ? { level: [...levels][0] } : {}
37115
+ });
36932
37116
  const url = appendQuery(logStream.url, {
36933
- since: since ? String(since.getTime()) : void 0,
36934
- limit: input.tail ? String(input.tail) : void 0,
36935
37117
  service: input.service
36936
37118
  });
36937
37119
  const filter = buildFilter({ levels, since, grep, service: input.service });
@@ -36966,6 +37148,7 @@ var tailCommand = Command61.make(
36966
37148
  project: projectArg,
36967
37149
  org: orgOption25,
36968
37150
  env: envOption9,
37151
+ type: logTypeOption,
36969
37152
  level: levelOption,
36970
37153
  since: sinceOption,
36971
37154
  tail: tailOption,
@@ -36973,10 +37156,11 @@ var tailCommand = Command61.make(
36973
37156
  service: serviceOption,
36974
37157
  json: jsonOption
36975
37158
  },
36976
- ({ project, org, env, level, since, tail, grep, service, json }) => tailEffect({
37159
+ ({ project, org, env, type, level, since, tail, grep, service, json }) => tailEffect({
36977
37160
  project: project._tag === "Some" ? project.value : void 0,
36978
37161
  org: org._tag === "Some" ? org.value : void 0,
36979
37162
  env: env._tag === "Some" ? env.value : void 0,
37163
+ type,
36980
37164
  level,
36981
37165
  since: since._tag === "Some" ? since.value : void 0,
36982
37166
  tail: tail._tag === "Some" ? tail.value : void 0,
@@ -36984,7 +37168,7 @@ var tailCommand = Command61.make(
36984
37168
  service: service._tag === "Some" ? service.value : void 0,
36985
37169
  json
36986
37170
  })
36987
- ).pipe(Command61.withDescription("Tail logs with structured formatting (alias for logs --follow)"));
37171
+ ).pipe(Command61.withDescription("Follow runtime logs with structured formatting"));
36988
37172
 
36989
37173
  // src/programs/tasks.ts
36990
37174
  import { Args as Args42, Command as Command62, Options as Options63 } from "@effect/cli";
@@ -39155,7 +39339,7 @@ function buildErrorEnvelope(err) {
39155
39339
  };
39156
39340
  }
39157
39341
  function buildDefectEnvelope(cause) {
39158
- const message = cause instanceof Error ? cause.message : typeof cause === "string" ? cause : String(cause);
39342
+ const message = renderUnknownCause(cause);
39159
39343
  return {
39160
39344
  code: "INTERNAL_ERROR",
39161
39345
  message,
@@ -39164,6 +39348,28 @@ function buildDefectEnvelope(cause) {
39164
39348
  exitCode: ExitCode.GENERIC
39165
39349
  };
39166
39350
  }
39351
+ function renderUnknownCause(cause) {
39352
+ if (cause instanceof Error) return cause.message;
39353
+ if (typeof cause === "string") return cause;
39354
+ if (cause === null) return "null";
39355
+ if (cause === void 0) return "undefined";
39356
+ if (typeof cause === "object") {
39357
+ const record = cause;
39358
+ if (typeof record.message === "string" && record.message.trim().length > 0) {
39359
+ return record.message;
39360
+ }
39361
+ const json = safeJsonStringify(cause);
39362
+ if (json) return json;
39363
+ }
39364
+ return String(cause);
39365
+ }
39366
+ function safeJsonStringify(value) {
39367
+ try {
39368
+ return JSON.stringify(value);
39369
+ } catch {
39370
+ return void 0;
39371
+ }
39372
+ }
39167
39373
  function emitErrorEnvelope(envelope, format = resolveErrorOutputFormat()) {
39168
39374
  if (format === "json") {
39169
39375
  process.stderr.write(`${JSON.stringify({ error: envelope }, null, 2)}
@@ -39221,6 +39427,7 @@ var root = Command71.make(
39221
39427
  unlinkCommand,
39222
39428
  openCommand,
39223
39429
  projectsCommand,
39430
+ orgCommand,
39224
39431
  orgsCommand,
39225
39432
  // deployment
39226
39433
  deployCommand,
@@ -39298,12 +39505,55 @@ var cli = Command71.run(root, {
39298
39505
  name: "Sylphx Platform CLI",
39299
39506
  version: package_default.version
39300
39507
  });
39508
+ var ANSI_ESCAPE_PATTERN = /\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g;
39509
+ function renderValidationErrorMessage(err) {
39510
+ return HelpDoc.toAnsiText(err.error).replace(ANSI_ESCAPE_PATTERN, "").trimEnd();
39511
+ }
39512
+ function suppressEffectConsoleErrorsForMachineOutput(effect) {
39513
+ if (resolveErrorOutputFormat() === "pretty") return effect;
39514
+ return Console71.consoleWith(
39515
+ (current2) => effect.pipe(
39516
+ Console71.withConsole({
39517
+ ...current2,
39518
+ error: () => Effect81.void,
39519
+ unsafe: {
39520
+ ...current2.unsafe,
39521
+ error: () => void 0
39522
+ }
39523
+ })
39524
+ )
39525
+ );
39526
+ }
39301
39527
  cli(process.argv).pipe(
39528
+ suppressEffectConsoleErrorsForMachineOutput,
39302
39529
  Effect81.catchAll(
39303
39530
  (err) => Effect81.sync(() => {
39304
39531
  const format = resolveErrorOutputFormat();
39305
39532
  if (err instanceof CliCommandError) {
39306
39533
  process.exitCode = renderCliCommandError(err, format);
39534
+ } else if (err instanceof CliArgError) {
39535
+ process.exitCode = renderCliCommandError(
39536
+ new CliCommandError({
39537
+ command: err.command,
39538
+ reason: "invalid-input",
39539
+ message: err.message
39540
+ }),
39541
+ format
39542
+ );
39543
+ } else if (ValidationError.isValidationError(err)) {
39544
+ process.exitCode = ExitCode.USAGE;
39545
+ if (format !== "pretty") {
39546
+ emitErrorEnvelope(
39547
+ {
39548
+ code: "INVALID_INPUT",
39549
+ message: renderValidationErrorMessage(err),
39550
+ reason: "invalid-input",
39551
+ command: "cli",
39552
+ exitCode: ExitCode.USAGE
39553
+ },
39554
+ format
39555
+ );
39556
+ }
39307
39557
  } else {
39308
39558
  const envelope = buildDefectEnvelope(err);
39309
39559
  emitErrorEnvelope(envelope, format);