@kivacore/cli 0.13.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.js CHANGED
@@ -89093,7 +89093,7 @@ import { createHash as createHash3 } from "node:crypto";
89093
89093
  import { existsSync as existsSync14 } from "node:fs";
89094
89094
  import fs11 from "node:fs/promises";
89095
89095
  import path9 from "node:path";
89096
- function isRecord7(value2) {
89096
+ function isRecord8(value2) {
89097
89097
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
89098
89098
  }
89099
89099
  function isNonEmptyString(value2) {
@@ -89205,14 +89205,14 @@ function migrateV1ToV2(v1) {
89205
89205
  return { version: 2, projectVersion: "0.1.0", phases, features, tasks };
89206
89206
  }
89207
89207
  function parseV1Graph(rawValue) {
89208
- const sections = Array.isArray(rawValue.sections) ? rawValue.sections.filter((value2) => isRecord7(value2)).map((value2) => ({
89208
+ const sections = Array.isArray(rawValue.sections) ? rawValue.sections.filter((value2) => isRecord8(value2)).map((value2) => ({
89209
89209
  id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
89210
89210
  title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
89211
89211
  slug: isNonEmptyString(value2.slug) ? value2.slug.trim() : "",
89212
89212
  summary: typeof value2.summary === "string" ? value2.summary.trim() : "",
89213
89213
  ...typeof value2.order === "number" ? { order: value2.order } : {}
89214
89214
  })).filter((value2) => value2.id.length > 0) : [];
89215
- const features = Array.isArray(rawValue.features) ? rawValue.features.filter((value2) => isRecord7(value2)).map((value2) => ({
89215
+ const features = Array.isArray(rawValue.features) ? rawValue.features.filter((value2) => isRecord8(value2)).map((value2) => ({
89216
89216
  id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
89217
89217
  title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
89218
89218
  slug: isNonEmptyString(value2.slug) ? value2.slug.trim() : "",
@@ -89220,7 +89220,7 @@ function parseV1Graph(rawValue) {
89220
89220
  sectionId: isNonEmptyString(value2.sectionId) ? value2.sectionId.trim() : "",
89221
89221
  ...typeof value2.order === "number" ? { order: value2.order } : {}
89222
89222
  })).filter((value2) => value2.id.length > 0) : [];
89223
- const tasks = Array.isArray(rawValue.tasks) ? rawValue.tasks.filter((value2) => isRecord7(value2)).map((value2) => ({
89223
+ const tasks = Array.isArray(rawValue.tasks) ? rawValue.tasks.filter((value2) => isRecord8(value2)).map((value2) => ({
89224
89224
  id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
89225
89225
  title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
89226
89226
  summary: typeof value2.summary === "string" ? value2.summary.trim() : "",
@@ -89236,7 +89236,7 @@ function parseV1Graph(rawValue) {
89236
89236
  }
89237
89237
  function parseV2Graph(rawValue) {
89238
89238
  const projectVersion = isNonEmptyString(rawValue.projectVersion) ? rawValue.projectVersion.trim() : "0.1.0";
89239
- const phases = Array.isArray(rawValue.phases) ? rawValue.phases.filter((value2) => isRecord7(value2)).map((value2) => ({
89239
+ const phases = Array.isArray(rawValue.phases) ? rawValue.phases.filter((value2) => isRecord8(value2)).map((value2) => ({
89240
89240
  id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
89241
89241
  title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
89242
89242
  slug: isNonEmptyString(value2.slug) ? value2.slug.trim() : "",
@@ -89244,7 +89244,7 @@ function parseV2Graph(rawValue) {
89244
89244
  ...isNonEmptyString(value2.projectVersion) ? { projectVersion: value2.projectVersion.trim() } : {},
89245
89245
  ...typeof value2.order === "number" ? { order: value2.order } : {}
89246
89246
  })).filter((value2) => value2.id.length > 0) : [];
89247
- const features = Array.isArray(rawValue.features) ? rawValue.features.filter((value2) => isRecord7(value2)).map((value2) => ({
89247
+ const features = Array.isArray(rawValue.features) ? rawValue.features.filter((value2) => isRecord8(value2)).map((value2) => ({
89248
89248
  id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
89249
89249
  title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
89250
89250
  slug: isNonEmptyString(value2.slug) ? value2.slug.trim() : "",
@@ -89254,7 +89254,7 @@ function parseV2Graph(rawValue) {
89254
89254
  ...isNonEmptyString(value2.projectVersion) ? { projectVersion: value2.projectVersion.trim() } : {},
89255
89255
  ...typeof value2.order === "number" ? { order: value2.order } : {}
89256
89256
  })).filter((value2) => value2.id.length > 0) : [];
89257
- const tasks = Array.isArray(rawValue.tasks) ? rawValue.tasks.filter((value2) => isRecord7(value2)).map((value2) => ({
89257
+ const tasks = Array.isArray(rawValue.tasks) ? rawValue.tasks.filter((value2) => isRecord8(value2)).map((value2) => ({
89258
89258
  id: isNonEmptyString(value2.id) ? value2.id.trim() : "",
89259
89259
  title: isNonEmptyString(value2.title) ? value2.title.trim() : "",
89260
89260
  summary: typeof value2.summary === "string" ? value2.summary.trim() : "",
@@ -89269,7 +89269,7 @@ function parseV2Graph(rawValue) {
89269
89269
  return sortGraph({ version: 2, projectVersion, phases, features, tasks });
89270
89270
  }
89271
89271
  function parseProjectPlanGraph(rawValue) {
89272
- if (!isRecord7(rawValue)) {
89272
+ if (!isRecord8(rawValue)) {
89273
89273
  return createEmptyProjectPlanGraph();
89274
89274
  }
89275
89275
  if (rawValue.version === 2) {
@@ -97698,7 +97698,7 @@ function resolveDisplayName(name3, aliases) {
97698
97698
  // package.json
97699
97699
  var package_default = {
97700
97700
  name: "@kivacore/cli",
97701
- version: "0.13.2",
97701
+ version: "1.0.0",
97702
97702
  private: false,
97703
97703
  description: "KIVA API CLI",
97704
97704
  bin: {
@@ -102596,6 +102596,9 @@ function extractAppRecords(payload) {
102596
102596
  }
102597
102597
  return [];
102598
102598
  }
102599
+ function isRecord4(value2) {
102600
+ return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
102601
+ }
102599
102602
  function extractString2(record2, key) {
102600
102603
  const value2 = record2[key];
102601
102604
  return typeof value2 === "string" && value2.length > 0 ? value2 : void 0;
@@ -103068,7 +103071,17 @@ async function offerWorkspaceAgentSkills(dir) {
103068
103071
  promptFn: async (question) => await promptYesNo({ question })
103069
103072
  });
103070
103073
  }
103074
+ function filterApiClientsByAppSlug(payload, appSlug) {
103075
+ if (!appSlug || !isRecord4(payload) || !Array.isArray(payload.data)) {
103076
+ return payload;
103077
+ }
103078
+ const data = payload.data.filter(
103079
+ (client) => isRecord4(client) && Array.isArray(client.tenant_apps) && client.tenant_apps.some((app) => isRecord4(app) && extractString2(app, "slug") === appSlug)
103080
+ );
103081
+ return { ...payload, data };
103082
+ }
103071
103083
  function createAppsCli(dependencies) {
103084
+ const isIncluded = (name3) => !dependencies.excludedCommands?.includes(name3);
103072
103085
  const appsCli = Cli_exports.create("apps", {
103073
103086
  description: "App commands",
103074
103087
  env: EnvSchema
@@ -103097,6 +103110,22 @@ function createAppsCli(dependencies) {
103097
103110
  });
103098
103111
  }
103099
103112
  });
103113
+ appsCli.command("list-api-clients", {
103114
+ description: "List the organization's API (OAuth2) clients: client id, redirect URIs and scopes, the API app each belongs to and the apps each is assigned to",
103115
+ options: external_exports.object({
103116
+ appSlug: external_exports.string().optional().describe("Only the clients assigned to the app with this slug")
103117
+ }),
103118
+ run: async (context) => {
103119
+ const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103120
+ const apiClient = dependencies.createApiClient(apiBaseUrl);
103121
+ const response = await apiClient.request({ method: "GET", path: "/api/clients" });
103122
+ return await injectContext({
103123
+ apiBaseUrl,
103124
+ authStore: dependencies.authStore,
103125
+ payload: filterApiClientsByAppSlug(response.data, normalizeOptional2(context.options.appSlug))
103126
+ });
103127
+ }
103128
+ });
103100
103129
  appsCli.command("update", {
103101
103130
  description: "Update an app. Store fields and array/object values must be passed via --data/--from-file.",
103102
103131
  options: external_exports.object({
@@ -103389,39 +103418,41 @@ function createAppsCli(dependencies) {
103389
103418
  });
103390
103419
  }
103391
103420
  });
103392
- appsCli.command("clone", {
103393
- description: "Clone an existing app's repo locally and write a .env for development",
103394
- options: external_exports.object({
103395
- appId: external_exports.string().optional().describe("App ID (one of --app-id/--app-slug)"),
103396
- appSlug: external_exports.string().optional().describe("App slug (one of --app-id/--app-slug)"),
103397
- dir: external_exports.string().optional().describe("Target directory (default ./<repoName>)"),
103398
- clientId: external_exports.string().optional().describe("Override the OAuth client id written to .env")
103399
- }),
103400
- run: async (context) => {
103401
- const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103402
- const apiClient = dependencies.createApiClient(apiBaseUrl);
103403
- const appId = await resolveAppId({
103404
- apiClient,
103405
- appId: context.options.appId,
103406
- appSlug: context.options.appSlug
103407
- });
103408
- const workspace = await setupLocalWorkspace({
103409
- apiClient,
103410
- environmentConfigService: dependencies.environmentConfigService,
103411
- authStore: dependencies.authStore,
103412
- apiBaseUrl,
103413
- appId,
103414
- clientIdOverride: normalizeOptional2(context.options.clientId),
103415
- targetDir: normalizeOptional2(context.options.dir)
103416
- });
103417
- await offerWorkspaceAgentSkills(workspace.path);
103418
- return await injectContext({
103419
- apiBaseUrl,
103420
- authStore: dependencies.authStore,
103421
- payload: { appId, ...workspace }
103422
- });
103423
- }
103424
- });
103421
+ if (isIncluded("clone")) {
103422
+ appsCli.command("clone", {
103423
+ description: "Clone an existing app's repo locally and write a .env for development",
103424
+ options: external_exports.object({
103425
+ appId: external_exports.string().optional().describe("App ID (one of --app-id/--app-slug)"),
103426
+ appSlug: external_exports.string().optional().describe("App slug (one of --app-id/--app-slug)"),
103427
+ dir: external_exports.string().optional().describe("Target directory (default ./<repoName>)"),
103428
+ clientId: external_exports.string().optional().describe("Override the OAuth client id written to .env")
103429
+ }),
103430
+ run: async (context) => {
103431
+ const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103432
+ const apiClient = dependencies.createApiClient(apiBaseUrl);
103433
+ const appId = await resolveAppId({
103434
+ apiClient,
103435
+ appId: context.options.appId,
103436
+ appSlug: context.options.appSlug
103437
+ });
103438
+ const workspace = await setupLocalWorkspace({
103439
+ apiClient,
103440
+ environmentConfigService: dependencies.environmentConfigService,
103441
+ authStore: dependencies.authStore,
103442
+ apiBaseUrl,
103443
+ appId,
103444
+ clientIdOverride: normalizeOptional2(context.options.clientId),
103445
+ targetDir: normalizeOptional2(context.options.dir)
103446
+ });
103447
+ await offerWorkspaceAgentSkills(workspace.path);
103448
+ return await injectContext({
103449
+ apiBaseUrl,
103450
+ authStore: dependencies.authStore,
103451
+ payload: { appId, ...workspace }
103452
+ });
103453
+ }
103454
+ });
103455
+ }
103425
103456
  appsCli.command(buildActionsCli(dependencies));
103426
103457
  appsCli.command(buildAiToolsCli(dependencies));
103427
103458
  return appsCli;
@@ -103726,60 +103757,104 @@ async function loginWithManualTokens(params) {
103726
103757
  return profile;
103727
103758
  }
103728
103759
  function createAuthCli(dependencies) {
103760
+ const isIncluded = (name3) => !dependencies.excludedCommands?.includes(name3);
103729
103761
  const authCli = Cli_exports.create("auth", {
103730
103762
  description: "Authentication commands",
103731
103763
  env: EnvSchema
103732
103764
  });
103733
- authCli.command("login", {
103734
- description: "Authorize CLI using OAuth2 device flow",
103735
- options: external_exports.object({
103736
- clientId: external_exports.string().optional().describe("OAuth2 client id"),
103737
- scope: external_exports.string().default(DEFAULT_LOGIN_SCOPES).describe("OAuth2 scopes"),
103738
- accessToken: external_exports.string().optional().describe("Manual access token; skips device flow"),
103739
- refreshToken: external_exports.string().optional().describe("Manual refresh token used with --accessToken")
103740
- }),
103741
- run: async (context) => {
103742
- const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103743
- const manualAccessToken = context.options.accessToken?.trim();
103744
- const manualRefreshToken = context.options.refreshToken?.trim();
103745
- if (manualRefreshToken && !manualAccessToken) {
103746
- throw new UserInputError("refreshToken requires accessToken. Pass --accessToken when using --refreshToken.");
103747
- }
103748
- const resolvedClient = await resolveClientId({
103749
- requestedClientId: context.options.clientId,
103750
- env: context.env,
103751
- environmentConfigService: dependencies.environmentConfigService,
103752
- globalEnvironmentConfigService: dependencies.globalEnvironmentConfigService,
103753
- allowManualFallback: Boolean(manualAccessToken)
103754
- });
103755
- const clientId = resolvedClient.clientId;
103756
- if (!clientId) {
103757
- throw new UserInputError(
103758
- "Client ID is required. Pass --clientId, set KIVA_API_CLIENT_ID, or login once with --clientId to save it."
103759
- );
103765
+ if (isIncluded("login")) {
103766
+ authCli.command("login", {
103767
+ description: "Authorize CLI using OAuth2 device flow",
103768
+ options: external_exports.object({
103769
+ clientId: external_exports.string().optional().describe("OAuth2 client id"),
103770
+ scope: external_exports.string().default(DEFAULT_LOGIN_SCOPES).describe("OAuth2 scopes"),
103771
+ accessToken: external_exports.string().optional().describe("Manual access token; skips device flow"),
103772
+ refreshToken: external_exports.string().optional().describe("Manual refresh token used with --accessToken")
103773
+ }),
103774
+ run: async (context) => {
103775
+ const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103776
+ const manualAccessToken = context.options.accessToken?.trim();
103777
+ const manualRefreshToken = context.options.refreshToken?.trim();
103778
+ if (manualRefreshToken && !manualAccessToken) {
103779
+ throw new UserInputError("refreshToken requires accessToken. Pass --accessToken when using --refreshToken.");
103780
+ }
103781
+ const resolvedClient = await resolveClientId({
103782
+ requestedClientId: context.options.clientId,
103783
+ env: context.env,
103784
+ environmentConfigService: dependencies.environmentConfigService,
103785
+ globalEnvironmentConfigService: dependencies.globalEnvironmentConfigService,
103786
+ allowManualFallback: Boolean(manualAccessToken)
103787
+ });
103788
+ const clientId = resolvedClient.clientId;
103789
+ if (!clientId) {
103790
+ throw new UserInputError(
103791
+ "Client ID is required. Pass --clientId, set KIVA_API_CLIENT_ID, or login once with --clientId to save it."
103792
+ );
103793
+ }
103794
+ let cleanupOpenInBrowserListener = () => {
103795
+ };
103796
+ try {
103797
+ const profile = manualAccessToken ? await loginWithManualTokens({
103798
+ apiBaseUrl,
103799
+ accessToken: manualAccessToken,
103800
+ refreshToken: manualRefreshToken,
103801
+ clientId: context.options.clientId,
103802
+ scope: context.options.scope,
103803
+ dependencies,
103804
+ env: context.env
103805
+ }) : await dependencies.createAuthSessionService(apiBaseUrl).loginWithDeviceFlow({
103806
+ clientId,
103807
+ scope: context.options.scope,
103808
+ onVerification: (verification) => {
103809
+ logVerificationHint(verification, context.agent, dependencies.onMessage);
103810
+ cleanupOpenInBrowserListener = listenForEnterToOpenBrowser(verification.verificationUriComplete, context.agent);
103811
+ }
103812
+ });
103813
+ if (!manualAccessToken && resolvedClient.resolvedClientId) {
103814
+ await dependencies.environmentConfigService.setDefaultClientId(resolvedClient.resolvedClientId);
103815
+ }
103816
+ return await injectContext({
103817
+ apiBaseUrl,
103818
+ authStore: dependencies.authStore,
103819
+ payload: {
103820
+ authenticated: true,
103821
+ apiBaseUrl,
103822
+ userId: profile.userId,
103823
+ email: profile.email,
103824
+ tenantId: profile.tenantId,
103825
+ tenantName: profile.tenantName,
103826
+ tenantNo: profile.tenantNo,
103827
+ clientId: profile.clientId,
103828
+ scope: profile.scope,
103829
+ expiresAt: profile.expiresAt
103830
+ }
103831
+ });
103832
+ } finally {
103833
+ cleanupOpenInBrowserListener();
103834
+ }
103760
103835
  }
103761
- let cleanupOpenInBrowserListener = () => {
103762
- };
103763
- try {
103764
- const profile = manualAccessToken ? await loginWithManualTokens({
103836
+ });
103837
+ }
103838
+ if (isIncluded("set-tokens")) {
103839
+ authCli.command("set-tokens", {
103840
+ description: "Set custom access and refresh tokens for the active environment",
103841
+ options: external_exports.object({
103842
+ clientId: external_exports.string().optional().describe("OAuth2 client id"),
103843
+ scope: external_exports.string().default(DEFAULT_LOGIN_SCOPES).describe("OAuth2 scopes"),
103844
+ accessToken: external_exports.string().min(1).describe("Custom access token"),
103845
+ refreshToken: external_exports.string().optional().describe("Custom refresh token")
103846
+ }),
103847
+ run: async (context) => {
103848
+ const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103849
+ const profile = await loginWithManualTokens({
103765
103850
  apiBaseUrl,
103766
- accessToken: manualAccessToken,
103767
- refreshToken: manualRefreshToken,
103851
+ accessToken: context.options.accessToken,
103852
+ refreshToken: context.options.refreshToken,
103768
103853
  clientId: context.options.clientId,
103769
103854
  scope: context.options.scope,
103770
103855
  dependencies,
103771
103856
  env: context.env
103772
- }) : await dependencies.createAuthSessionService(apiBaseUrl).loginWithDeviceFlow({
103773
- clientId,
103774
- scope: context.options.scope,
103775
- onVerification: (verification) => {
103776
- logVerificationHint(verification, context.agent, dependencies.onMessage);
103777
- cleanupOpenInBrowserListener = listenForEnterToOpenBrowser(verification.verificationUriComplete, context.agent);
103778
- }
103779
103857
  });
103780
- if (!manualAccessToken && resolvedClient.resolvedClientId) {
103781
- await dependencies.environmentConfigService.setDefaultClientId(resolvedClient.resolvedClientId);
103782
- }
103783
103858
  return await injectContext({
103784
103859
  apiBaseUrl,
103785
103860
  authStore: dependencies.authStore,
@@ -103796,48 +103871,9 @@ function createAuthCli(dependencies) {
103796
103871
  expiresAt: profile.expiresAt
103797
103872
  }
103798
103873
  });
103799
- } finally {
103800
- cleanupOpenInBrowserListener();
103801
103874
  }
103802
- }
103803
- });
103804
- authCli.command("set-tokens", {
103805
- description: "Set custom access and refresh tokens for the active environment",
103806
- options: external_exports.object({
103807
- clientId: external_exports.string().optional().describe("OAuth2 client id"),
103808
- scope: external_exports.string().default(DEFAULT_LOGIN_SCOPES).describe("OAuth2 scopes"),
103809
- accessToken: external_exports.string().min(1).describe("Custom access token"),
103810
- refreshToken: external_exports.string().optional().describe("Custom refresh token")
103811
- }),
103812
- run: async (context) => {
103813
- const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103814
- const profile = await loginWithManualTokens({
103815
- apiBaseUrl,
103816
- accessToken: context.options.accessToken,
103817
- refreshToken: context.options.refreshToken,
103818
- clientId: context.options.clientId,
103819
- scope: context.options.scope,
103820
- dependencies,
103821
- env: context.env
103822
- });
103823
- return await injectContext({
103824
- apiBaseUrl,
103825
- authStore: dependencies.authStore,
103826
- payload: {
103827
- authenticated: true,
103828
- apiBaseUrl,
103829
- userId: profile.userId,
103830
- email: profile.email,
103831
- tenantId: profile.tenantId,
103832
- tenantName: profile.tenantName,
103833
- tenantNo: profile.tenantNo,
103834
- clientId: profile.clientId,
103835
- scope: profile.scope,
103836
- expiresAt: profile.expiresAt
103837
- }
103838
- });
103839
- }
103840
- });
103875
+ });
103876
+ }
103841
103877
  const accountsCli = Cli_exports.create("accounts", {
103842
103878
  description: "Account management",
103843
103879
  env: EnvSchema
@@ -103855,27 +103891,29 @@ function createAuthCli(dependencies) {
103855
103891
  });
103856
103892
  }
103857
103893
  });
103858
- accountsCli.command("use", {
103859
- description: "Switch active account by user ID",
103860
- options: external_exports.object({
103861
- userId: external_exports.string().min(1).describe("User ID to activate")
103862
- }),
103863
- run: async (context) => {
103864
- const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103865
- const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
103866
- const switched = await authSessionService.switchAccount({
103867
- userId: context.options.userId
103868
- });
103869
- return await injectContext({
103870
- apiBaseUrl,
103871
- authStore: dependencies.authStore,
103872
- payload: {
103873
- switched: true,
103874
- ...switched
103875
- }
103876
- });
103877
- }
103878
- });
103894
+ if (isIncluded("accounts use")) {
103895
+ accountsCli.command("use", {
103896
+ description: "Switch active account by user ID",
103897
+ options: external_exports.object({
103898
+ userId: external_exports.string().min(1).describe("User ID to activate")
103899
+ }),
103900
+ run: async (context) => {
103901
+ const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103902
+ const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
103903
+ const switched = await authSessionService.switchAccount({
103904
+ userId: context.options.userId
103905
+ });
103906
+ return await injectContext({
103907
+ apiBaseUrl,
103908
+ authStore: dependencies.authStore,
103909
+ payload: {
103910
+ switched: true,
103911
+ ...switched
103912
+ }
103913
+ });
103914
+ }
103915
+ });
103916
+ }
103879
103917
  authCli.command(accountsCli);
103880
103918
  const tenantsCli = Cli_exports.create("tenants", {
103881
103919
  description: "Tenant management",
@@ -103899,67 +103937,71 @@ function createAuthCli(dependencies) {
103899
103937
  });
103900
103938
  }
103901
103939
  });
103902
- tenantsCli.command("use", {
103903
- description: "Switch active tenant for an account",
103904
- args: external_exports.object({
103905
- tenantSelector: external_exports.string().min(1).describe("Tenant selector: tenant no or UUID tenant id")
103906
- }),
103907
- options: external_exports.object({
103908
- userId: external_exports.string().optional().describe("User ID; defaults to active account"),
103909
- scope: external_exports.string().optional().describe("Scope used only when tenant bootstrap login is required")
103910
- }),
103911
- run: async (context) => {
103912
- const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103913
- const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
103914
- const tenantId = await resolveTenantIdSelector({
103915
- authSessionService,
103916
- selector: context.args.tenantSelector,
103917
- userId: context.options.userId
103918
- });
103919
- let cleanupOpenInBrowserListener = () => {
103920
- };
103921
- try {
103922
- const switched = await authSessionService.switchTenant({
103923
- tenantId,
103924
- userId: context.options.userId,
103925
- scope: context.options.scope,
103926
- onVerification: (verification) => {
103927
- logVerificationHint(verification, context.agent, dependencies.onMessage);
103928
- cleanupOpenInBrowserListener = listenForEnterToOpenBrowser(verification.verificationUriComplete, context.agent);
103929
- }
103940
+ if (isIncluded("tenants use")) {
103941
+ tenantsCli.command("use", {
103942
+ description: "Switch active tenant for an account",
103943
+ args: external_exports.object({
103944
+ tenantSelector: external_exports.string().min(1).describe("Tenant selector: tenant no or UUID tenant id")
103945
+ }),
103946
+ options: external_exports.object({
103947
+ userId: external_exports.string().optional().describe("User ID; defaults to active account"),
103948
+ scope: external_exports.string().optional().describe("Scope used only when tenant bootstrap login is required")
103949
+ }),
103950
+ run: async (context) => {
103951
+ const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103952
+ const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
103953
+ const tenantId = await resolveTenantIdSelector({
103954
+ authSessionService,
103955
+ selector: context.args.tenantSelector,
103956
+ userId: context.options.userId
103957
+ });
103958
+ let cleanupOpenInBrowserListener = () => {
103959
+ };
103960
+ try {
103961
+ const switched = await authSessionService.switchTenant({
103962
+ tenantId,
103963
+ userId: context.options.userId,
103964
+ scope: context.options.scope,
103965
+ onVerification: (verification) => {
103966
+ logVerificationHint(verification, context.agent, dependencies.onMessage);
103967
+ cleanupOpenInBrowserListener = listenForEnterToOpenBrowser(verification.verificationUriComplete, context.agent);
103968
+ }
103969
+ });
103970
+ return await injectContext({
103971
+ apiBaseUrl,
103972
+ authStore: dependencies.authStore,
103973
+ payload: {
103974
+ switched: true,
103975
+ ...switched
103976
+ }
103977
+ });
103978
+ } finally {
103979
+ cleanupOpenInBrowserListener();
103980
+ }
103981
+ }
103982
+ });
103983
+ }
103984
+ authCli.command(tenantsCli);
103985
+ if (isIncluded("logout")) {
103986
+ authCli.command("logout", {
103987
+ description: "Revoke and clear all tenant sessions for active account",
103988
+ options: external_exports.object({
103989
+ clientId: external_exports.string().optional().describe("OAuth2 client id override")
103990
+ }),
103991
+ run: async (context) => {
103992
+ const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103993
+ const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
103994
+ const result = await authSessionService.logout({
103995
+ clientId: context.options.clientId
103930
103996
  });
103931
103997
  return await injectContext({
103932
103998
  apiBaseUrl,
103933
103999
  authStore: dependencies.authStore,
103934
- payload: {
103935
- switched: true,
103936
- ...switched
103937
- }
104000
+ payload: result
103938
104001
  });
103939
- } finally {
103940
- cleanupOpenInBrowserListener();
103941
104002
  }
103942
- }
103943
- });
103944
- authCli.command(tenantsCli);
103945
- authCli.command("logout", {
103946
- description: "Revoke and clear all tenant sessions for active account",
103947
- options: external_exports.object({
103948
- clientId: external_exports.string().optional().describe("OAuth2 client id override")
103949
- }),
103950
- run: async (context) => {
103951
- const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
103952
- const authSessionService = dependencies.createAuthSessionService(apiBaseUrl);
103953
- const result = await authSessionService.logout({
103954
- clientId: context.options.clientId
103955
- });
103956
- return await injectContext({
103957
- apiBaseUrl,
103958
- authStore: dependencies.authStore,
103959
- payload: result
103960
- });
103961
- }
103962
- });
104003
+ });
104004
+ }
103963
104005
  authCli.command("who", {
103964
104006
  description: "Return current authenticated user",
103965
104007
  run: async (context) => {
@@ -104024,103 +104066,109 @@ function createAuthCli(dependencies) {
104024
104066
  });
104025
104067
  }
104026
104068
  });
104027
- authCli.command("github", {
104028
- description: "Rotate the server-side repo-scoped GitHub token for an app",
104029
- options: external_exports.object({
104030
- appId: external_exports.string().optional().describe("App ID; defaults to KIVA_SANDBOX_APP_ID env var")
104031
- }),
104032
- // Status only. The rotated token is never returned and never reaches a
104033
- // sandbox: git authenticates through the sandbox gateway with a
104034
- // short-lived capability, and the GitHub token stays on the control plane.
104035
- run: async (context) => {
104036
- const appId = context.options.appId?.trim() || getOptionalEnvValue(context.env, SANDBOX_APP_ID_ENV);
104037
- if (!appId) {
104038
- throw new UserInputError(`App ID is required. Pass --appId or set the ${SANDBOX_APP_ID_ENV} environment variable.`);
104039
- }
104040
- const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
104041
- const apiClient = dependencies.createApiClient(apiBaseUrl);
104042
- const response = await apiClient.request({
104043
- method: "POST",
104044
- path: `/ai/sandbox/app/${appId}/regenerateGithubToken`
104045
- });
104046
- return await injectContext({
104047
- apiBaseUrl,
104048
- authStore: dependencies.authStore,
104049
- payload: response.data
104050
- });
104051
- }
104052
- });
104053
- authCli.command("git-credential", {
104054
- description: "Git credential helper: supplies the sandbox gateway capability for the active app",
104055
- options: external_exports.object({
104056
- operation: external_exports.enum(["get", "store", "erase"]).describe("Git credential operation (passed by git)"),
104057
- appId: external_exports.string().optional().describe("App ID; defaults to KIVA_SANDBOX_APP_ID env var")
104058
- }),
104059
- // Conforms to the git credential helper protocol, so it writes the raw
104060
- // `username=`/`password=` lines straight to stdout and returns undefined
104061
- // (no injectContext envelope — git would not understand it).
104062
- run: async (context) => {
104063
- if (context.options.operation !== "get") {
104064
- return void 0;
104065
- }
104066
- const appId = context.options.appId?.trim() || getOptionalEnvValue(context.env, SANDBOX_APP_ID_ENV);
104067
- if (!appId) {
104068
- throw new UserInputError(`App ID is required. Pass --appId or set the ${SANDBOX_APP_ID_ENV} environment variable.`);
104069
- }
104070
- if (!isHostedSandbox2()) {
104071
- return void 0;
104072
- }
104073
- if (!dependencies.settingsRootPath) {
104074
- return void 0;
104075
- }
104076
- const writeStdout = dependencies.writeStdout ?? ((chunk) => process.stdout.write(chunk));
104077
- const readStdin2 = dependencies.readStdin ?? readAllStdin;
104078
- try {
104079
- const request2 = parseGitCredentialRequest(await readStdin2());
104080
- const gatewayUrl = getOptionalEnvValue(context.env, SANDBOX_GATEWAY_URL_ENV);
104081
- if (!gatewayUrl || !isGatewayGitCredentialRequest({ request: request2, baseUrl: gatewayUrl, appId })) {
104082
- return void 0;
104069
+ if (isIncluded("github")) {
104070
+ authCli.command("github", {
104071
+ description: "Rotate the server-side repo-scoped GitHub token for an app",
104072
+ options: external_exports.object({
104073
+ appId: external_exports.string().optional().describe("App ID; defaults to KIVA_SANDBOX_APP_ID env var")
104074
+ }),
104075
+ // Status only. The rotated token is never returned and never reaches a
104076
+ // sandbox: git authenticates through the sandbox gateway with a
104077
+ // short-lived capability, and the GitHub token stays on the control plane.
104078
+ run: async (context) => {
104079
+ const appId = context.options.appId?.trim() || getOptionalEnvValue(context.env, SANDBOX_APP_ID_ENV);
104080
+ if (!appId) {
104081
+ throw new UserInputError(`App ID is required. Pass --appId or set the ${SANDBOX_APP_ID_ENV} environment variable.`);
104083
104082
  }
104084
104083
  const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
104085
- const state = await getGatewayCredential({
104086
- statePath: resolveSandboxGatewayStatePath(dependencies.settingsRootPath),
104087
- appId,
104088
- createApiClient: () => dependencies.createApiClient(apiBaseUrl)
104084
+ const apiClient = dependencies.createApiClient(apiBaseUrl);
104085
+ const response = await apiClient.request({
104086
+ method: "POST",
104087
+ path: `/ai/sandbox/app/${appId}/regenerateGithubToken`
104089
104088
  });
104090
- const answer = resolveGitCredentialAnswer({ request: request2, state });
104091
- if (answer) {
104092
- writeStdout(`username=${answer.username}
104089
+ return await injectContext({
104090
+ apiBaseUrl,
104091
+ authStore: dependencies.authStore,
104092
+ payload: response.data
104093
+ });
104094
+ }
104095
+ });
104096
+ }
104097
+ if (isIncluded("git-credential")) {
104098
+ authCli.command("git-credential", {
104099
+ description: "Git credential helper: supplies the sandbox gateway capability for the active app",
104100
+ options: external_exports.object({
104101
+ operation: external_exports.enum(["get", "store", "erase"]).describe("Git credential operation (passed by git)"),
104102
+ appId: external_exports.string().optional().describe("App ID; defaults to KIVA_SANDBOX_APP_ID env var")
104103
+ }),
104104
+ // Conforms to the git credential helper protocol, so it writes the raw
104105
+ // `username=`/`password=` lines straight to stdout and returns undefined
104106
+ // (no injectContext envelope — git would not understand it).
104107
+ run: async (context) => {
104108
+ if (context.options.operation !== "get") {
104109
+ return void 0;
104110
+ }
104111
+ const appId = context.options.appId?.trim() || getOptionalEnvValue(context.env, SANDBOX_APP_ID_ENV);
104112
+ if (!appId) {
104113
+ throw new UserInputError(`App ID is required. Pass --appId or set the ${SANDBOX_APP_ID_ENV} environment variable.`);
104114
+ }
104115
+ if (!isHostedSandbox2()) {
104116
+ return void 0;
104117
+ }
104118
+ if (!dependencies.settingsRootPath) {
104119
+ return void 0;
104120
+ }
104121
+ const writeStdout = dependencies.writeStdout ?? ((chunk) => process.stdout.write(chunk));
104122
+ const readStdin2 = dependencies.readStdin ?? readAllStdin;
104123
+ try {
104124
+ const request2 = parseGitCredentialRequest(await readStdin2());
104125
+ const gatewayUrl = getOptionalEnvValue(context.env, SANDBOX_GATEWAY_URL_ENV);
104126
+ if (!gatewayUrl || !isGatewayGitCredentialRequest({ request: request2, baseUrl: gatewayUrl, appId })) {
104127
+ return void 0;
104128
+ }
104129
+ const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
104130
+ const state = await getGatewayCredential({
104131
+ statePath: resolveSandboxGatewayStatePath(dependencies.settingsRootPath),
104132
+ appId,
104133
+ createApiClient: () => dependencies.createApiClient(apiBaseUrl)
104134
+ });
104135
+ const answer = resolveGitCredentialAnswer({ request: request2, state });
104136
+ if (answer) {
104137
+ writeStdout(`username=${answer.username}
104093
104138
  password=${answer.password}
104094
104139
  `);
104140
+ }
104141
+ } catch {
104095
104142
  }
104096
- } catch {
104143
+ return void 0;
104097
104144
  }
104098
- return void 0;
104099
- }
104100
- });
104101
- authCli.command("sandbox", {
104102
- description: "Refresh and inject fresh authentication tokens into the active sandbox",
104103
- options: external_exports.object({
104104
- appId: external_exports.string().optional().describe("App ID; defaults to KIVA_SANDBOX_APP_ID env var")
104105
- }),
104106
- run: async (context) => {
104107
- const appId = context.options.appId?.trim() || getOptionalEnvValue(context.env, "KIVA_SANDBOX_APP_ID");
104108
- if (!appId) {
104109
- throw new UserInputError("App ID is required. Pass --appId or set the KIVA_SANDBOX_APP_ID environment variable.");
104145
+ });
104146
+ }
104147
+ if (isIncluded("sandbox")) {
104148
+ authCli.command("sandbox", {
104149
+ description: "Refresh and inject fresh authentication tokens into the active sandbox",
104150
+ options: external_exports.object({
104151
+ appId: external_exports.string().optional().describe("App ID; defaults to KIVA_SANDBOX_APP_ID env var")
104152
+ }),
104153
+ run: async (context) => {
104154
+ const appId = context.options.appId?.trim() || getOptionalEnvValue(context.env, "KIVA_SANDBOX_APP_ID");
104155
+ if (!appId) {
104156
+ throw new UserInputError("App ID is required. Pass --appId or set the KIVA_SANDBOX_APP_ID environment variable.");
104157
+ }
104158
+ const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
104159
+ const apiClient = dependencies.createApiClient(apiBaseUrl);
104160
+ const response = await apiClient.request({
104161
+ method: "POST",
104162
+ path: `/ai/sandbox/app/${appId}/refreshAuth`
104163
+ });
104164
+ return await injectContext({
104165
+ apiBaseUrl,
104166
+ authStore: dependencies.authStore,
104167
+ payload: response.data
104168
+ });
104110
104169
  }
104111
- const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
104112
- const apiClient = dependencies.createApiClient(apiBaseUrl);
104113
- const response = await apiClient.request({
104114
- method: "POST",
104115
- path: `/ai/sandbox/app/${appId}/refreshAuth`
104116
- });
104117
- return await injectContext({
104118
- apiBaseUrl,
104119
- authStore: dependencies.authStore,
104120
- payload: response.data
104121
- });
104122
- }
104123
- });
104170
+ });
104171
+ }
104124
104172
  return authCli;
104125
104173
  }
104126
104174
 
@@ -105577,7 +105625,7 @@ var FILE_EXTENSION_TO_CONTENT_TYPE = {
105577
105625
  ".zip": "application/zip",
105578
105626
  ".7z": "application/x-7z-compressed"
105579
105627
  };
105580
- function isRecord4(value2) {
105628
+ function isRecord5(value2) {
105581
105629
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
105582
105630
  }
105583
105631
  function normalizeOptionalString2(value2) {
@@ -105607,7 +105655,7 @@ function toBulkPayload(payload, mode) {
105607
105655
  const records = [];
105608
105656
  for (let index3 = 0; index3 < payload.length; index3 += 1) {
105609
105657
  const item = payload[index3];
105610
- if (!isRecord4(item)) {
105658
+ if (!isRecord5(item)) {
105611
105659
  throw new UserInputError(`Batch item at index ${index3} must be a JSON object.`);
105612
105660
  }
105613
105661
  if (mode === "update") {
@@ -105621,7 +105669,7 @@ function toBulkPayload(payload, mode) {
105621
105669
  return records;
105622
105670
  }
105623
105671
  function toSinglePayload(payload) {
105624
- if (!isRecord4(payload)) {
105672
+ if (!isRecord5(payload)) {
105625
105673
  throw new UserInputError("Expected a JSON object for single-item operation.");
105626
105674
  }
105627
105675
  return payload;
@@ -106114,7 +106162,7 @@ function parseIds(raw) {
106114
106162
  }
106115
106163
  return raw.split(",").map((id) => id.trim()).filter((id) => id.length > 0);
106116
106164
  }
106117
- function isRecord5(value2) {
106165
+ function isRecord6(value2) {
106118
106166
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
106119
106167
  }
106120
106168
  function normalizeNonEmptyString(value2) {
@@ -106129,13 +106177,13 @@ function tryParseJsonObject(text3) {
106129
106177
  const candidate = (fenceMatch ? fenceMatch[1] : trimmed).trim();
106130
106178
  try {
106131
106179
  const parsed = JSON.parse(candidate);
106132
- return isRecord5(parsed) ? parsed : null;
106180
+ return isRecord6(parsed) ? parsed : null;
106133
106181
  } catch {
106134
106182
  return null;
106135
106183
  }
106136
106184
  }
106137
106185
  function extractGeneratedDsql(result) {
106138
- const structured = (isRecord5(result.data) ? isRecord5(result.data.data) ? result.data.data : result.data : null) ?? tryParseJsonObject(result.text);
106186
+ const structured = (isRecord6(result.data) ? isRecord6(result.data.data) ? result.data.data : result.data : null) ?? tryParseJsonObject(result.text);
106139
106187
  const structuredQuery = structured ? normalizeNonEmptyString(structured.query) : void 0;
106140
106188
  if (structuredQuery) {
106141
106189
  return {
@@ -106349,7 +106397,7 @@ function createDsqlCli(dependencies) {
106349
106397
  prompt: generated.prompt ?? prompt,
106350
106398
  query: generated.query
106351
106399
  };
106352
- const payload = isRecord5(response.data) ? { ...base, ...response.data } : { ...base, result: response.data };
106400
+ const payload = isRecord6(response.data) ? { ...base, ...response.data } : { ...base, result: response.data };
106353
106401
  return await injectContext({
106354
106402
  apiBaseUrl,
106355
106403
  authStore: dependencies.authStore,
@@ -106554,7 +106602,7 @@ function createDsqlCli(dependencies) {
106554
106602
  // src/commands/discoverCommands.ts
106555
106603
  import { readFile as readFile10 } from "node:fs/promises";
106556
106604
  var SUPPORTED_HTTP_METHODS2 = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "TRACE"];
106557
- function isRecord6(value2) {
106605
+ function isRecord7(value2) {
106558
106606
  return typeof value2 === "object" && value2 !== null;
106559
106607
  }
106560
106608
  function isEnoentError(error62) {
@@ -106608,15 +106656,15 @@ function parseEndpointSelector(input2) {
106608
106656
  }
106609
106657
  function getPaths(document4) {
106610
106658
  const rawPaths = document4.paths;
106611
- return isRecord6(rawPaths) ? rawPaths : {};
106659
+ return isRecord7(rawPaths) ? rawPaths : {};
106612
106660
  }
106613
106661
  function getEntities(document4) {
106614
- const components = isRecord6(document4.components) ? document4.components : null;
106615
- if (components && isRecord6(components.schemas)) {
106662
+ const components = isRecord7(document4.components) ? document4.components : null;
106663
+ if (components && isRecord7(components.schemas)) {
106616
106664
  return components.schemas;
106617
106665
  }
106618
106666
  const definitions = document4.definitions;
106619
- if (isRecord6(definitions)) {
106667
+ if (isRecord7(definitions)) {
106620
106668
  return definitions;
106621
106669
  }
106622
106670
  return {};
@@ -106636,19 +106684,19 @@ function extractNamespaces(paths) {
106636
106684
  return Array.from(namespaces.values()).sort((left, right) => left.localeCompare(right));
106637
106685
  }
106638
106686
  function getPathOperation(pathItem, method) {
106639
- if (!isRecord6(pathItem)) {
106687
+ if (!isRecord7(pathItem)) {
106640
106688
  return null;
106641
106689
  }
106642
106690
  const normalizedMethod = method.toLowerCase();
106643
106691
  const operation = pathItem[normalizedMethod];
106644
- return isRecord6(operation) ? operation : null;
106692
+ return isRecord7(operation) ? operation : null;
106645
106693
  }
106646
106694
  function toEndpointMethodEntries(paths, pathFilter) {
106647
106695
  const entries = [];
106648
106696
  const sortedPaths = Object.keys(paths).filter(pathFilter).sort((left, right) => left.localeCompare(right));
106649
106697
  for (const path13 of sortedPaths) {
106650
106698
  const pathItem = paths[path13];
106651
- if (!isRecord6(pathItem)) {
106699
+ if (!isRecord7(pathItem)) {
106652
106700
  continue;
106653
106701
  }
106654
106702
  for (const method of SUPPORTED_HTTP_METHODS2) {
@@ -106677,7 +106725,7 @@ function parseOpenApiDocument(raw) {
106677
106725
  cause: error62
106678
106726
  });
106679
106727
  }
106680
- if (!isRecord6(parsed)) {
106728
+ if (!isRecord7(parsed)) {
106681
106729
  throw new UserInputError("Stored OpenAPI spec must be a JSON object. Run 'kiva discover api' to re-download.");
106682
106730
  }
106683
106731
  return parsed;
@@ -117656,11 +117704,11 @@ function requireNonEmptyObject4(payload, label) {
117656
117704
  throw new UserInputError(`${label} payload is empty. Provide flags, --data, or --from-file.`);
117657
117705
  }
117658
117706
  }
117659
- function isRecord8(value2) {
117707
+ function isRecord9(value2) {
117660
117708
  return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
117661
117709
  }
117662
117710
  function normalizeBatchUpdateFieldItem(item) {
117663
- if (!isRecord8(item)) {
117711
+ if (!isRecord9(item)) {
117664
117712
  return item;
117665
117713
  }
117666
117714
  const normalized = {
@@ -117694,7 +117742,7 @@ function normalizeBatchUpdateFieldsPayload(payload) {
117694
117742
  };
117695
117743
  }
117696
117744
  function normalizeUpdateEnumItem(item) {
117697
- if (!isRecord8(item)) {
117745
+ if (!isRecord9(item)) {
117698
117746
  return item;
117699
117747
  }
117700
117748
  if (!("enumId" in item) && typeof item.id === "string") {
@@ -119618,6 +119666,87 @@ function createUpdateCli(dependencies) {
119618
119666
  });
119619
119667
  }
119620
119668
 
119669
+ // src/rootHelpCommands.ts
119670
+ var ROOT_HELP_COMMANDS = [
119671
+ { command: "kiva -g <command>", description: "Force use of global ~/.kiva settings for this run" },
119672
+ { command: "env", description: "Show active environment and list environments" },
119673
+ { command: "env which", description: "Show the active environment and resolved settings scope for the current folder" },
119674
+ { command: "env use <id|name>", description: "Switch active environment" },
119675
+ { command: "auth login", description: "Authenticate with OAuth2 device flow" },
119676
+ { command: "auth set-tokens --accessToken <token>", description: "Save custom access and refresh tokens" },
119677
+ { command: "auth accounts list", description: "List saved user accounts" },
119678
+ { command: "auth tenants use <uuid|tenantNo>", description: "Switch active tenant for selected user" },
119679
+ { command: '"<prompt>"', description: "Start an agent with a prompt: the Coding Agent for software requests, the Work Agent otherwise" },
119680
+ { command: "work [prompt]", description: "Launch the Kiva Work Agent" },
119681
+ { command: "code [prompt]", description: "Launch the Kiva Coding Agent" },
119682
+ { command: "server", description: "Start HTTP server bridging pi agent to AI SDK useChat" },
119683
+ { command: "browser start", description: "Start a browser session (local Chrome or remote Cloudflare)" },
119684
+ { command: "browser nav <url>", description: "Navigate the active browser tab" },
119685
+ { command: "browser content <url>", description: "Extract readable page content as markdown" },
119686
+ { command: "discover api", description: "Download active tenant OpenAPI spec" },
119687
+ { command: "discover namespaces", description: "List namespaces from tenant OpenAPI spec" },
119688
+ { command: "discover path <prefix>", description: "List endpoint paths by prefix" },
119689
+ { command: "discover endpoint <path>", description: "Show endpoint object by exact path" },
119690
+ { command: "discover entity <name>", description: "Show entity object by name" },
119691
+ { command: "discover search <terms>", description: "Search in endpoint paths and entity names" },
119692
+ { command: "connect list-connectors", description: "List integration connectors" },
119693
+ { command: "connect get-connector <slug>", description: "Get connector details with data sources and actions" },
119694
+ { command: "connect get-action <slug> <key>", description: "Get connector action details" },
119695
+ { command: "connect list-connections <slug>", description: "Get connector connections" },
119696
+ { command: "connect curl <slug> <endpoint>", description: "Send request through connector" },
119697
+ { command: "connect run-action <appSlug> <actionKey>", description: "Run a connector or app action" },
119698
+ { command: "knowledge search <query>", description: "Semantic search across kiva/knowledge" },
119699
+ { command: "knowledge section <query>", description: "Show a knowledge section with refs and backlinks" },
119700
+ { command: "knowledge check", description: "Validate kiva/knowledge links and backlinks" },
119701
+ { command: "project-plan show", description: "Show the canonical project plan graph and hierarchy" },
119702
+ { command: "project-plan check", description: "Validate the canonical project plan graph" },
119703
+ { command: "ds list <appSlug> <dataSourceSlug>", description: "List data source items" },
119704
+ { command: 'dsql query "<sql>"', description: "Run a read-only logical SQL SELECT query" },
119705
+ { command: 'dsql generate "<question>"', description: "Generate a DSQL query from natural language" },
119706
+ { command: 'dsql ask "<question>"', description: "Generate a DSQL query from natural language and run it" },
119707
+ { command: "dsql schema app <appSlug>", description: "Show DSQL schema for every data source in an app" },
119708
+ { command: "dsql schema data-source <appSlug> <dataSourceSlug>", description: "Show DSQL schema for a single data source" },
119709
+ { command: "dsql list-custom-query --appSlug <slug>", description: "List saved custom query records for an app" },
119710
+ {
119711
+ command: "dsql create-custom-query --appSlug <slug> --name <name> --dsqlQuery <sql> --fields <json>",
119712
+ description: "Create a custom query record from DSQL"
119713
+ },
119714
+ { command: "dsql run-custom-query --queryId <id>", description: "Run a saved custom query (--debug/--simulate to inspect)" },
119715
+ { command: "apps list", description: "List apps" },
119716
+ { command: "apps delete --appId <id>", description: "Archive an app" },
119717
+ {
119718
+ command: "apps set-agent-context --appSlug <slug> --value <text>",
119719
+ description: "Set an app's AI agent context (or --from-file/--clear)"
119720
+ },
119721
+ { command: "apps ai-tools list --appSlug <slug>", description: "List app-scoped AI tools" },
119722
+ { command: "apps ai-tools create --appSlug <slug> --name <name> --key <key>", description: "Create an app-scoped AI tool" },
119723
+ { command: "studio list-data-sources --appSlug <slug>", description: "List studio data sources" },
119724
+ { command: "automation list --appSlug <slug>", description: "List automations for an app" },
119725
+ { command: "automation create-trigger --automationId <id> --type <type>", description: "Add a typed trigger to an automation" },
119726
+ { command: "agent list --appSlug <slug>", description: "List custom agents for an app" },
119727
+ { command: "agent create --appSlug <slug> --name <name>", description: "Create a custom agent" },
119728
+ { command: "agent tools create --appSlug <slug> --agentId <id> --toolType <type>", description: "Add a tool to an agent" },
119729
+ { command: "acl roles list", description: "List tenant roles" },
119730
+ { command: "acl roles create --slug <slug> --name <name>", description: "Create a tenant role" },
119731
+ { command: "acl role-queries list", description: "List tenant role queries" },
119732
+ { command: "acl hierarchy-units list", description: "List tenant user hierarchy units" },
119733
+ { command: "acl hierarchy-units create --name <name>", description: "Create a hierarchy unit" },
119734
+ { command: "messaging accounts", description: "List tenant email accounts (non-credential info)" },
119735
+ { command: "messaging email send --accountId <id>", description: "Send an email through a tenant email account" },
119736
+ { command: "account brands list", description: "List tenant brands" },
119737
+ { command: "account brands create --name <name>", description: "Create a tenant brand" },
119738
+ { command: "account brands update --brandId <id>", description: "Update a tenant brand" },
119739
+ { command: "account user-profile get", description: "Get the current user's profile" },
119740
+ { command: "account user-profile update --firstname <name>", description: "Update the current user's profile" },
119741
+ { command: "account tenant-preferences get", description: "Get the tenant's regional preferences" },
119742
+ { command: "account tenant-preferences update --timeZone <id>", description: "Update the tenant's regional preferences" },
119743
+ { command: "tui", description: "Launch terminal UI (OpenTUI, requires Bun)" },
119744
+ { command: "curl <path>", description: "Send arbitrary API requests" },
119745
+ { command: "agent-skills status", description: "Show whether the Kiva agent skills are installed and current in this folder" },
119746
+ { command: "agent-skills install", description: "Install or update the Kiva agent skills in this folder" },
119747
+ { command: "update", description: "Update the kiva CLI to the latest version (--check to only report)" }
119748
+ ];
119749
+
119621
119750
  // src/services/authStoreMigration.ts
119622
119751
  var LEGACY_API_BASE_URLS = /* @__PURE__ */ new Map([
119623
119752
  ["https://api.docyrus.com/v1", "https://api.kiva.app/v1"],
@@ -119691,7 +119820,7 @@ function migrateLegacyAuthApiUrls(state) {
119691
119820
 
119692
119821
  // src/services/authSession.ts
119693
119822
  var DEFAULT_MANUAL_ACCESS_TOKEN_EXPIRY_SECONDS = 3600;
119694
- function isRecord9(value2) {
119823
+ function isRecord10(value2) {
119695
119824
  return typeof value2 === "object" && value2 !== null;
119696
119825
  }
119697
119826
  function extractRecordValue(record2, keys) {
@@ -120007,11 +120136,11 @@ var AuthSessionService = class {
120007
120136
  fetchFn: this.params.fetchFn
120008
120137
  });
120009
120138
  const payload = response.data;
120010
- const dataCandidate = isRecord9(payload) && isRecord9(payload.data) ? payload.data : payload;
120011
- if (!isRecord9(dataCandidate)) {
120139
+ const dataCandidate = isRecord10(payload) && isRecord10(payload.data) ? payload.data : payload;
120140
+ if (!isRecord10(dataCandidate)) {
120012
120141
  throw new AuthSessionError("Unable to parse /users/me response.");
120013
120142
  }
120014
- const tenantCandidate = isRecord9(dataCandidate.tenant) ? dataCandidate.tenant : void 0;
120143
+ const tenantCandidate = isRecord10(dataCandidate.tenant) ? dataCandidate.tenant : void 0;
120015
120144
  const userId = extractString3(dataCandidate, ["id", "user_id"]);
120016
120145
  const email3 = extractString3(dataCandidate, ["email"]);
120017
120146
  const tenantId = tenantCandidate ? extractString3(tenantCandidate, ["id"]) : extractString3(dataCandidate, ["tenant_id", "tenantId"]);
@@ -120037,13 +120166,13 @@ var AuthSessionService = class {
120037
120166
  fetchFn: this.params.fetchFn
120038
120167
  });
120039
120168
  const payload = response.data;
120040
- const listCandidate = Array.isArray(payload) ? payload : isRecord9(payload) && Array.isArray(payload.data) ? payload.data : null;
120169
+ const listCandidate = Array.isArray(payload) ? payload : isRecord10(payload) && Array.isArray(payload.data) ? payload.data : null;
120041
120170
  if (!listCandidate) {
120042
120171
  throw new AuthSessionError("Unable to parse tenant catalog response.");
120043
120172
  }
120044
120173
  const mapped = [];
120045
120174
  for (const item of listCandidate) {
120046
- if (!isRecord9(item)) {
120175
+ if (!isRecord10(item)) {
120047
120176
  continue;
120048
120177
  }
120049
120178
  const tenantId = extractString3(item, ["id", "tenant_id"]);
@@ -122548,85 +122677,6 @@ var TenantOpenApiService = class {
122548
122677
  };
122549
122678
 
122550
122679
  // src/main.ts
122551
- var ROOT_HELP_COMMANDS = [
122552
- { command: "kiva -g <command>", description: "Force use of global ~/.kiva settings for this run" },
122553
- { command: "env", description: "Show active environment and list environments" },
122554
- { command: "env which", description: "Show the active environment and resolved settings scope for the current folder" },
122555
- { command: "env use <id|name>", description: "Switch active environment" },
122556
- { command: "auth login", description: "Authenticate with OAuth2 device flow" },
122557
- { command: "auth set-tokens --accessToken <token>", description: "Save custom access and refresh tokens" },
122558
- { command: "auth accounts list", description: "List saved user accounts" },
122559
- { command: "auth tenants use <uuid|tenantNo>", description: "Switch active tenant for selected user" },
122560
- { command: '"<prompt>"', description: "Start an agent with a prompt: the Coding Agent for software requests, the Work Agent otherwise" },
122561
- { command: "work [prompt]", description: "Launch the Kiva Work Agent" },
122562
- { command: "code [prompt]", description: "Launch the Kiva Coding Agent" },
122563
- { command: "server", description: "Start HTTP server bridging pi agent to AI SDK useChat" },
122564
- { command: "browser start", description: "Start a browser session (local Chrome or remote Cloudflare)" },
122565
- { command: "browser nav <url>", description: "Navigate the active browser tab" },
122566
- { command: "browser content <url>", description: "Extract readable page content as markdown" },
122567
- { command: "discover api", description: "Download active tenant OpenAPI spec" },
122568
- { command: "discover namespaces", description: "List namespaces from tenant OpenAPI spec" },
122569
- { command: "discover path <prefix>", description: "List endpoint paths by prefix" },
122570
- { command: "discover endpoint <path>", description: "Show endpoint object by exact path" },
122571
- { command: "discover entity <name>", description: "Show entity object by name" },
122572
- { command: "discover search <terms>", description: "Search in endpoint paths and entity names" },
122573
- { command: "connect list-connectors", description: "List integration connectors" },
122574
- { command: "connect get-connector <slug>", description: "Get connector details with data sources and actions" },
122575
- { command: "connect get-action <slug> <key>", description: "Get connector action details" },
122576
- { command: "connect list-connections <slug>", description: "Get connector connections" },
122577
- { command: "connect curl <slug> <endpoint>", description: "Send request through connector" },
122578
- { command: "connect run-action <appSlug> <actionKey>", description: "Run a connector or app action" },
122579
- { command: "knowledge search <query>", description: "Semantic search across kiva/knowledge" },
122580
- { command: "knowledge section <query>", description: "Show a knowledge section with refs and backlinks" },
122581
- { command: "knowledge check", description: "Validate kiva/knowledge links and backlinks" },
122582
- { command: "project-plan show", description: "Show the canonical project plan graph and hierarchy" },
122583
- { command: "project-plan check", description: "Validate the canonical project plan graph" },
122584
- { command: "ds list <appSlug> <dataSourceSlug>", description: "List data source items" },
122585
- { command: 'dsql query "<sql>"', description: "Run a read-only logical SQL SELECT query" },
122586
- { command: 'dsql generate "<question>"', description: "Generate a DSQL query from natural language" },
122587
- { command: 'dsql ask "<question>"', description: "Generate a DSQL query from natural language and run it" },
122588
- { command: "dsql schema app <appSlug>", description: "Show DSQL schema for every data source in an app" },
122589
- { command: "dsql schema data-source <appSlug> <dataSourceSlug>", description: "Show DSQL schema for a single data source" },
122590
- { command: "dsql list-custom-query --appSlug <slug>", description: "List saved custom query records for an app" },
122591
- {
122592
- command: "dsql create-custom-query --appSlug <slug> --name <name> --dsqlQuery <sql> --fields <json>",
122593
- description: "Create a custom query record from DSQL"
122594
- },
122595
- { command: "dsql run-custom-query --queryId <id>", description: "Run a saved custom query (--debug/--simulate to inspect)" },
122596
- { command: "apps list", description: "List apps" },
122597
- { command: "apps delete --appId <id>", description: "Archive an app" },
122598
- {
122599
- command: "apps set-agent-context --appSlug <slug> --value <text>",
122600
- description: "Set an app's AI agent context (or --from-file/--clear)"
122601
- },
122602
- { command: "apps ai-tools list --appSlug <slug>", description: "List app-scoped AI tools" },
122603
- { command: "apps ai-tools create --appSlug <slug> --name <name> --key <key>", description: "Create an app-scoped AI tool" },
122604
- { command: "studio list-data-sources --appSlug <slug>", description: "List studio data sources" },
122605
- { command: "automation list --appSlug <slug>", description: "List automations for an app" },
122606
- { command: "automation create-trigger --automationId <id> --type <type>", description: "Add a typed trigger to an automation" },
122607
- { command: "agent list --appSlug <slug>", description: "List custom agents for an app" },
122608
- { command: "agent create --appSlug <slug> --name <name>", description: "Create a custom agent" },
122609
- { command: "agent tools create --appSlug <slug> --agentId <id> --toolType <type>", description: "Add a tool to an agent" },
122610
- { command: "acl roles list", description: "List tenant roles" },
122611
- { command: "acl roles create --slug <slug> --name <name>", description: "Create a tenant role" },
122612
- { command: "acl role-queries list", description: "List tenant role queries" },
122613
- { command: "acl hierarchy-units list", description: "List tenant user hierarchy units" },
122614
- { command: "acl hierarchy-units create --name <name>", description: "Create a hierarchy unit" },
122615
- { command: "messaging accounts", description: "List tenant email accounts (non-credential info)" },
122616
- { command: "messaging email send --accountId <id>", description: "Send an email through a tenant email account" },
122617
- { command: "account brands list", description: "List tenant brands" },
122618
- { command: "account brands create --name <name>", description: "Create a tenant brand" },
122619
- { command: "account brands update --brandId <id>", description: "Update a tenant brand" },
122620
- { command: "account user-profile get", description: "Get the current user's profile" },
122621
- { command: "account user-profile update --firstname <name>", description: "Update the current user's profile" },
122622
- { command: "account tenant-preferences get", description: "Get the tenant's regional preferences" },
122623
- { command: "account tenant-preferences update --timeZone <id>", description: "Update the tenant's regional preferences" },
122624
- { command: "tui", description: "Launch terminal UI (OpenTUI, requires Bun)" },
122625
- { command: "curl <path>", description: "Send arbitrary API requests" },
122626
- { command: "agent-skills status", description: "Show whether the Kiva agent skills are installed and current in this folder" },
122627
- { command: "agent-skills install", description: "Install or update the Kiva agent skills in this folder" },
122628
- { command: "update", description: "Update the kiva CLI to the latest version (--check to only report)" }
122629
- ];
122630
122680
  function createKivaCli(params) {
122631
122681
  const settingsPaths = resolveKivaSettingsPaths({
122632
122682
  forceGlobal: params?.forceGlobalSettings,