@kivacore/cli 0.13.0 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -1
- package/agent-loader.js +7 -1
- package/agent-loader.js.map +2 -2
- package/main.js +133 -11
- package/main.js.map +4 -4
- package/package.json +1 -1
- package/resources/pi-agent/prompts/agent-system.md +15 -1
package/main.js
CHANGED
|
@@ -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.
|
|
97701
|
+
version: "0.13.2",
|
|
97702
97702
|
private: false,
|
|
97703
97703
|
description: "KIVA API CLI",
|
|
97704
97704
|
bin: {
|
|
@@ -100200,8 +100200,36 @@ var StudioResolver = class {
|
|
|
100200
100200
|
if (dataSourceId) {
|
|
100201
100201
|
return dataSourceId;
|
|
100202
100202
|
}
|
|
100203
|
-
|
|
100204
|
-
|
|
100203
|
+
try {
|
|
100204
|
+
const dataSources = await this.getDataSourcesForApp(options.appId);
|
|
100205
|
+
return resolveBySlug("Data source", dataSources, dataSourceSlug);
|
|
100206
|
+
} catch (error62) {
|
|
100207
|
+
const systemAppSlug = lookupSystemAppSlugById(options.appId);
|
|
100208
|
+
if (!systemAppSlug || !(error62 instanceof ApiResponseError) || error62.httpStatusCode !== 404) {
|
|
100209
|
+
throw error62;
|
|
100210
|
+
}
|
|
100211
|
+
return await this.#resolveSystemDataSourceId({ appSlug: systemAppSlug, dataSourceSlug });
|
|
100212
|
+
}
|
|
100213
|
+
}
|
|
100214
|
+
async #resolveSystemDataSourceId(params) {
|
|
100215
|
+
const notFound = new UserInputError(`Data source slug '${params.dataSourceSlug}' was not found in app '${params.appSlug}'.`);
|
|
100216
|
+
try {
|
|
100217
|
+
const response = await this.apiClient.request({
|
|
100218
|
+
method: "GET",
|
|
100219
|
+
path: `/dsql/schema/apps/${encodeURIComponent(params.appSlug)}/data-sources/${encodeURIComponent(params.dataSourceSlug)}`
|
|
100220
|
+
});
|
|
100221
|
+
const payload = isRecord3(response.data) && isRecord3(response.data.data) ? response.data.data : response.data;
|
|
100222
|
+
const id = isRecord3(payload) ? extractString(payload, "id") : void 0;
|
|
100223
|
+
if (!id) {
|
|
100224
|
+
throw notFound;
|
|
100225
|
+
}
|
|
100226
|
+
return id;
|
|
100227
|
+
} catch (error62) {
|
|
100228
|
+
if (error62 instanceof ApiResponseError && error62.httpStatusCode === 404) {
|
|
100229
|
+
throw notFound;
|
|
100230
|
+
}
|
|
100231
|
+
throw error62;
|
|
100232
|
+
}
|
|
100205
100233
|
}
|
|
100206
100234
|
async resolveAppSlug(options) {
|
|
100207
100235
|
const appId = normalizeOptional(options.appId);
|
|
@@ -106135,6 +106163,10 @@ async function generateDsqlQuery(params) {
|
|
|
106135
106163
|
});
|
|
106136
106164
|
return extractGeneratedDsql(result);
|
|
106137
106165
|
}
|
|
106166
|
+
var EXPAND_ENUMS_DESCRIPTION = "List each enum field's option ids and labels under its column.";
|
|
106167
|
+
function expandEnumsQuery(expandEnums) {
|
|
106168
|
+
return expandEnums ? { expandEnums: "true" } : {};
|
|
106169
|
+
}
|
|
106138
106170
|
function createDsqlCli(dependencies) {
|
|
106139
106171
|
const dsqlCli = Cli_exports.create("dsql", {
|
|
106140
106172
|
description: "Logical SQL query and schema discovery commands",
|
|
@@ -106176,12 +106208,16 @@ function createDsqlCli(dependencies) {
|
|
|
106176
106208
|
args: external_exports.object({
|
|
106177
106209
|
appSlug: external_exports.string().min(1)
|
|
106178
106210
|
}),
|
|
106211
|
+
options: external_exports.object({
|
|
106212
|
+
expandEnums: external_exports.boolean().default(false).describe(EXPAND_ENUMS_DESCRIPTION)
|
|
106213
|
+
}),
|
|
106179
106214
|
run: async (context) => {
|
|
106180
106215
|
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
106181
106216
|
const apiClient = dependencies.createApiClient(apiBaseUrl);
|
|
106182
106217
|
const response = await apiClient.request({
|
|
106183
106218
|
method: "GET",
|
|
106184
|
-
path: `/dsql/schema/apps/${context.args.appSlug}
|
|
106219
|
+
path: `/dsql/schema/apps/${context.args.appSlug}`,
|
|
106220
|
+
query: expandEnumsQuery(context.options.expandEnums)
|
|
106185
106221
|
});
|
|
106186
106222
|
return await injectContext({
|
|
106187
106223
|
apiBaseUrl,
|
|
@@ -106196,12 +106232,18 @@ function createDsqlCli(dependencies) {
|
|
|
106196
106232
|
appSlug: external_exports.string().min(1),
|
|
106197
106233
|
dataSourceSlug: external_exports.string().min(1)
|
|
106198
106234
|
}),
|
|
106235
|
+
options: external_exports.object({
|
|
106236
|
+
// On by default: a single table is small, and its enum labels are what a
|
|
106237
|
+
// filter such as "open tasks" has to be written against.
|
|
106238
|
+
expandEnums: external_exports.boolean().default(true).describe(`${EXPAND_ENUMS_DESCRIPTION} On by default; pass --no-expand-enums to omit`)
|
|
106239
|
+
}),
|
|
106199
106240
|
run: async (context) => {
|
|
106200
106241
|
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
106201
106242
|
const apiClient = dependencies.createApiClient(apiBaseUrl);
|
|
106202
106243
|
const response = await apiClient.request({
|
|
106203
106244
|
method: "GET",
|
|
106204
|
-
path: `/dsql/schema/apps/${context.args.appSlug}/data-sources/${context.args.dataSourceSlug}
|
|
106245
|
+
path: `/dsql/schema/apps/${context.args.appSlug}/data-sources/${context.args.dataSourceSlug}`,
|
|
106246
|
+
query: expandEnumsQuery(context.options.expandEnums)
|
|
106205
106247
|
});
|
|
106206
106248
|
return await injectContext({
|
|
106207
106249
|
apiBaseUrl,
|
|
@@ -106213,7 +106255,8 @@ function createDsqlCli(dependencies) {
|
|
|
106213
106255
|
schemaCli.command("data-sources", {
|
|
106214
106256
|
description: "Get the DSQL schema for data sources matching the given ids",
|
|
106215
106257
|
options: external_exports.object({
|
|
106216
|
-
ids: external_exports.string().optional().describe("Comma-separated data source ids")
|
|
106258
|
+
ids: external_exports.string().optional().describe("Comma-separated data source ids"),
|
|
106259
|
+
expandEnums: external_exports.boolean().default(false).describe(EXPAND_ENUMS_DESCRIPTION)
|
|
106217
106260
|
}),
|
|
106218
106261
|
run: async (context) => {
|
|
106219
106262
|
const apiBaseUrl = await dependencies.environmentConfigService.getActiveApiBaseUrl();
|
|
@@ -106226,7 +106269,8 @@ function createDsqlCli(dependencies) {
|
|
|
106226
106269
|
method: "GET",
|
|
106227
106270
|
path: "/dsql/schema/data-sources",
|
|
106228
106271
|
query: {
|
|
106229
|
-
ids: ids.join(",")
|
|
106272
|
+
ids: ids.join(","),
|
|
106273
|
+
...expandEnumsQuery(context.options.expandEnums)
|
|
106230
106274
|
}
|
|
106231
106275
|
});
|
|
106232
106276
|
return await injectContext({
|
|
@@ -120675,6 +120719,66 @@ var AuthStore = class _AuthStore {
|
|
|
120675
120719
|
}
|
|
120676
120720
|
};
|
|
120677
120721
|
|
|
120722
|
+
// src/services/barePrompt.ts
|
|
120723
|
+
var BARE_PROMPT_AGENT_COMMANDS = ["work", "code"];
|
|
120724
|
+
var BARE_PROMPT_COMMAND = "work";
|
|
120725
|
+
var SENTENCE_RE = /\S\s+\S/u;
|
|
120726
|
+
function findBarePrompt(argv) {
|
|
120727
|
+
for (const [index3, token] of argv.entries()) {
|
|
120728
|
+
if (token.startsWith("-")) {
|
|
120729
|
+
continue;
|
|
120730
|
+
}
|
|
120731
|
+
if (SENTENCE_RE.test(token)) {
|
|
120732
|
+
return token;
|
|
120733
|
+
}
|
|
120734
|
+
const previous2 = argv[index3 - 1];
|
|
120735
|
+
if (previous2?.startsWith("-") && !previous2.includes("=")) {
|
|
120736
|
+
continue;
|
|
120737
|
+
}
|
|
120738
|
+
break;
|
|
120739
|
+
}
|
|
120740
|
+
return void 0;
|
|
120741
|
+
}
|
|
120742
|
+
function rewriteBarePromptArgv(argv, command2 = BARE_PROMPT_COMMAND) {
|
|
120743
|
+
return findBarePrompt(argv) === void 0 ? [...argv] : [command2, ...argv];
|
|
120744
|
+
}
|
|
120745
|
+
|
|
120746
|
+
// src/services/barePromptAgent.ts
|
|
120747
|
+
var BARE_PROMPT_DECISION_PATH = "/ai/decideCliAgent";
|
|
120748
|
+
var DECISION_TIMEOUT_MS = 3e3;
|
|
120749
|
+
function isAgentCommand(value2) {
|
|
120750
|
+
return BARE_PROMPT_AGENT_COMMANDS.includes(value2);
|
|
120751
|
+
}
|
|
120752
|
+
async function decideBarePromptAgent(params) {
|
|
120753
|
+
if (isHostedSandbox(params.env)) {
|
|
120754
|
+
return BARE_PROMPT_COMMAND;
|
|
120755
|
+
}
|
|
120756
|
+
let timer;
|
|
120757
|
+
try {
|
|
120758
|
+
const apiBaseUrl = normalizeApiBaseUrl(await params.environmentConfigService.getActiveApiBaseUrl());
|
|
120759
|
+
if (!await params.authStore.getActiveProfile(apiBaseUrl)) {
|
|
120760
|
+
return BARE_PROMPT_COMMAND;
|
|
120761
|
+
}
|
|
120762
|
+
const apiClient = params.createApiClient?.(apiBaseUrl) ?? new ApiClient({ apiBaseUrl, authSessionService: new AuthSessionService({ apiBaseUrl, authStore: params.authStore }) });
|
|
120763
|
+
const decision = requestApiData({
|
|
120764
|
+
apiClient,
|
|
120765
|
+
request: { method: "POST", path: BARE_PROMPT_DECISION_PATH, body: { prompt: params.prompt } }
|
|
120766
|
+
}).then((payload) => {
|
|
120767
|
+
const agent = payload?.agent ?? payload?.data?.agent;
|
|
120768
|
+
return isAgentCommand(agent) ? agent : BARE_PROMPT_COMMAND;
|
|
120769
|
+
});
|
|
120770
|
+
decision.catch(() => void 0);
|
|
120771
|
+
const deadline = new Promise((resolve9) => {
|
|
120772
|
+
timer = setTimeout(() => resolve9(BARE_PROMPT_COMMAND), params.timeoutMs ?? DECISION_TIMEOUT_MS);
|
|
120773
|
+
});
|
|
120774
|
+
return await Promise.race([decision, deadline]);
|
|
120775
|
+
} catch {
|
|
120776
|
+
return BARE_PROMPT_COMMAND;
|
|
120777
|
+
} finally {
|
|
120778
|
+
clearTimeout(timer);
|
|
120779
|
+
}
|
|
120780
|
+
}
|
|
120781
|
+
|
|
120678
120782
|
// src/services/environmentConfig.ts
|
|
120679
120783
|
import { chmod as chmod6, mkdir as mkdir12, readFile as readFile22, writeFile as writeFile11 } from "node:fs/promises";
|
|
120680
120784
|
import { dirname as dirname17 } from "node:path";
|
|
@@ -122453,6 +122557,7 @@ var ROOT_HELP_COMMANDS = [
|
|
|
122453
122557
|
{ command: "auth set-tokens --accessToken <token>", description: "Save custom access and refresh tokens" },
|
|
122454
122558
|
{ command: "auth accounts list", description: "List saved user accounts" },
|
|
122455
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" },
|
|
122456
122561
|
{ command: "work [prompt]", description: "Launch the Kiva Work Agent" },
|
|
122457
122562
|
{ command: "code [prompt]", description: "Launch the Kiva Coding Agent" },
|
|
122458
122563
|
{ command: "server", description: "Start HTTP server bridging pi agent to AI SDK useChat" },
|
|
@@ -122750,15 +122855,32 @@ function createKivaCli(params) {
|
|
|
122750
122855
|
return cli2;
|
|
122751
122856
|
}
|
|
122752
122857
|
migrateLegacyBrandDirectories();
|
|
122753
|
-
var
|
|
122858
|
+
var extractedArgs = extractGlobalFlagFromArgv(process.argv.slice(2));
|
|
122754
122859
|
var cli = createKivaCli({
|
|
122755
|
-
forceGlobalSettings:
|
|
122860
|
+
forceGlobalSettings: extractedArgs.forceGlobal
|
|
122756
122861
|
});
|
|
122862
|
+
async function resolveRuntimeArgv() {
|
|
122863
|
+
const prompt = findBarePrompt(extractedArgs.argv);
|
|
122864
|
+
if (prompt === void 0) {
|
|
122865
|
+
return [...extractedArgs.argv];
|
|
122866
|
+
}
|
|
122867
|
+
const settingsPaths = resolveKivaSettingsPaths({ forceGlobal: extractedArgs.forceGlobal });
|
|
122868
|
+
const agent = await decideBarePromptAgent({
|
|
122869
|
+
prompt,
|
|
122870
|
+
authStore: new AuthStore(settingsPaths.authFilePath),
|
|
122871
|
+
environmentConfigService: new EnvironmentConfigService(settingsPaths.configFilePath)
|
|
122872
|
+
});
|
|
122873
|
+
if (agent === "code") {
|
|
122874
|
+
process.stderr.write('Starting the Kiva Coding Agent for this request. To choose yourself: kiva work "<prompt>"\n');
|
|
122875
|
+
}
|
|
122876
|
+
return rewriteBarePromptArgv(extractedArgs.argv, agent);
|
|
122877
|
+
}
|
|
122757
122878
|
void runWithIncurSkillsOutOfDateWarningSuppressed({
|
|
122758
122879
|
run: async () => {
|
|
122880
|
+
const argv = await resolveRuntimeArgv();
|
|
122759
122881
|
const gate = await enforceLatestCliVersion({
|
|
122760
122882
|
currentVersion: package_default.version,
|
|
122761
|
-
argv
|
|
122883
|
+
argv,
|
|
122762
122884
|
interactive: isInteractiveSession(),
|
|
122763
122885
|
promptFn: async (question) => await promptYesNo({ question })
|
|
122764
122886
|
});
|
|
@@ -122766,7 +122888,7 @@ void runWithIncurSkillsOutOfDateWarningSuppressed({
|
|
|
122766
122888
|
process.exitCode = gate.exitCode;
|
|
122767
122889
|
return;
|
|
122768
122890
|
}
|
|
122769
|
-
await cli.serve(
|
|
122891
|
+
await cli.serve(argv);
|
|
122770
122892
|
}
|
|
122771
122893
|
});
|
|
122772
122894
|
var main_default = cli;
|