@diafunc/cli 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/bin/diafunc.js +6 -6
- package/dist/bin/diafunc.js.map +1 -1
- package/dist/{chunk-T7BPK4LW.js → chunk-5AB7E3K4.js} +2090 -858
- package/dist/chunk-5AB7E3K4.js.map +1 -0
- package/dist/{chunk-Z5XCMRDG.js → chunk-CL2LMFXH.js} +2 -2
- package/dist/{chunk-CWZPEFGN.js → chunk-GZI6AECR.js} +2 -2
- package/dist/{chunk-CWZPEFGN.js.map → chunk-GZI6AECR.js.map} +1 -1
- package/dist/src/index.js +2 -2
- package/dist/update-check-KHHHTIDF.js +8 -0
- package/package.json +1 -1
- package/dist/chunk-T7BPK4LW.js.map +0 -1
- package/dist/update-check-7CVBVYDK.js +0 -8
- /package/dist/{chunk-Z5XCMRDG.js.map → chunk-CL2LMFXH.js.map} +0 -0
- /package/dist/{update-check-7CVBVYDK.js.map → update-check-KHHHTIDF.js.map} +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
package_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GZI6AECR.js";
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
|
-
import
|
|
6
|
+
import chalk41 from "chalk";
|
|
7
7
|
|
|
8
8
|
// src/commands/auth/login.ts
|
|
9
9
|
import chalk4 from "chalk";
|
|
@@ -258,13 +258,13 @@ function resolveEndpoint(config, profileOverride) {
|
|
|
258
258
|
import chalk from "chalk";
|
|
259
259
|
|
|
260
260
|
// src/client/errors.ts
|
|
261
|
-
var
|
|
262
|
-
licence_required: "A public project needs a
|
|
263
|
-
licence_not_selectable: "That
|
|
264
|
-
licence_share_alike_mismatch: "This project is a fork of a share-alike project, so it has to carry the
|
|
265
|
-
licence_forbids_fork: "The
|
|
261
|
+
var LICENSE_REFUSALS = {
|
|
262
|
+
licence_required: "A public project needs a license. Name one with --license <id>.",
|
|
263
|
+
licence_not_selectable: "That license cannot be chosen: it is not in the catalog, or it is deprecated or withdrawn.",
|
|
264
|
+
licence_share_alike_mismatch: "This project is a fork of a share-alike project, so it has to carry the license of the project it was forked from.",
|
|
265
|
+
licence_forbids_fork: "The license of this project does not allow adaptations, so it cannot be forked."
|
|
266
266
|
};
|
|
267
|
-
var
|
|
267
|
+
var LICENSE_LIST_REFUSALS = /* @__PURE__ */ new Set(["licence_required", "licence_not_selectable"]);
|
|
268
268
|
var ApiError = class _ApiError extends Error {
|
|
269
269
|
status;
|
|
270
270
|
details;
|
|
@@ -281,7 +281,7 @@ var ApiError = class _ApiError extends Error {
|
|
|
281
281
|
return new _ApiError(status, body.message, body.details, typeof body.error === "string" ? body.error : void 0);
|
|
282
282
|
}
|
|
283
283
|
toUserMessage() {
|
|
284
|
-
const refusal = this.code && Object.prototype.hasOwnProperty.call(
|
|
284
|
+
const refusal = this.code && Object.prototype.hasOwnProperty.call(LICENSE_REFUSALS, this.code) ? LICENSE_REFUSALS[this.code] : void 0;
|
|
285
285
|
if (refusal) return refusal;
|
|
286
286
|
const detail2 = this.readableMessage();
|
|
287
287
|
switch (this.status) {
|
|
@@ -748,19 +748,19 @@ function createAdminService(client) {
|
|
|
748
748
|
path: `/projects/${encodeURIComponent(projectId)}`
|
|
749
749
|
});
|
|
750
750
|
},
|
|
751
|
-
//
|
|
752
|
-
async
|
|
751
|
+
// Licenses: the catalog answers anyone, signed in or not.
|
|
752
|
+
async listLicenses() {
|
|
753
753
|
return client.request({
|
|
754
754
|
method: "GET",
|
|
755
755
|
service: SERVICE,
|
|
756
756
|
path: "/licences"
|
|
757
757
|
});
|
|
758
758
|
},
|
|
759
|
-
async
|
|
759
|
+
async getLicense(licenseId) {
|
|
760
760
|
return client.request({
|
|
761
761
|
method: "GET",
|
|
762
762
|
service: SERVICE,
|
|
763
|
-
path: `/licences/${encodeURIComponent(
|
|
763
|
+
path: `/licences/${encodeURIComponent(licenseId)}`
|
|
764
764
|
});
|
|
765
765
|
},
|
|
766
766
|
async createProject(request) {
|
|
@@ -1074,7 +1074,7 @@ function createAdminService(client) {
|
|
|
1074
1074
|
body: setting
|
|
1075
1075
|
});
|
|
1076
1076
|
},
|
|
1077
|
-
// Platform settings: the operator-facing
|
|
1077
|
+
// Platform settings: the operator-facing catalog, distinct from the per-user settings above.
|
|
1078
1078
|
// Every entry carries its compiled default, so an unset override reads as null rather than absent.
|
|
1079
1079
|
async listPlatformSettings() {
|
|
1080
1080
|
return client.request({
|
|
@@ -1240,7 +1240,7 @@ function handleError(error) {
|
|
|
1240
1240
|
failure(error.toUserMessage());
|
|
1241
1241
|
if (error.status === 401 && !(error instanceof SignInRefusedError)) hint(`Run 'diafunc auth login' to sign in.`);
|
|
1242
1242
|
if (error.status === 404) hint(`Check the id, or list what exists with the matching 'list' command.`);
|
|
1243
|
-
if (error.code &&
|
|
1243
|
+
if (error.code && LICENSE_LIST_REFUSALS.has(error.code)) hint(`List the licenses that can be chosen with 'diafunc license list'.`);
|
|
1244
1244
|
process.exit(error.status === 401 || error.status === 403 ? EXIT_AUTH : EXIT_FAILURE);
|
|
1245
1245
|
}
|
|
1246
1246
|
if (error instanceof NetworkError) {
|
|
@@ -1289,7 +1289,7 @@ function registerLoginCommand(parent) {
|
|
|
1289
1289
|
const client = createHttpClient();
|
|
1290
1290
|
const admin = createAdminService(client);
|
|
1291
1291
|
const user = await admin.getMyUser();
|
|
1292
|
-
success("
|
|
1292
|
+
success("Signed in.");
|
|
1293
1293
|
console.log(` User: ${chalk4.bold(user.name)}`);
|
|
1294
1294
|
console.log(` Email: ${user.email}`);
|
|
1295
1295
|
console.log(` Profile: ${config.currentProfile}`);
|
|
@@ -1317,7 +1317,7 @@ async function deviceCodeLogin(config, profile) {
|
|
|
1317
1317
|
});
|
|
1318
1318
|
if (!deviceResponse.ok) {
|
|
1319
1319
|
const text2 = await deviceResponse.text();
|
|
1320
|
-
failure(`
|
|
1320
|
+
failure(`The sign-in could not start: ${text2 || deviceResponse.statusText}`);
|
|
1321
1321
|
process.exit(1);
|
|
1322
1322
|
}
|
|
1323
1323
|
const device = await deviceResponse.json();
|
|
@@ -1355,7 +1355,7 @@ async function deviceCodeLogin(config, profile) {
|
|
|
1355
1355
|
const client = createHttpClient();
|
|
1356
1356
|
const admin = createAdminService(client);
|
|
1357
1357
|
const user = await admin.getMyUser();
|
|
1358
|
-
success("
|
|
1358
|
+
success("Signed in.");
|
|
1359
1359
|
console.log(` User: ${chalk4.bold(user.name)}`);
|
|
1360
1360
|
console.log(` Email: ${user.email}`);
|
|
1361
1361
|
console.log(` Profile: ${config.currentProfile}`);
|
|
@@ -1940,6 +1940,14 @@ function createAnalysisService(client) {
|
|
|
1940
1940
|
});
|
|
1941
1941
|
},
|
|
1942
1942
|
/** The depth the platform would give the caller's next analysis if its creation named none. */
|
|
1943
|
+
/** The depths an analysis is offered at, shallowest first: the one list every surface shows. */
|
|
1944
|
+
async getDepths() {
|
|
1945
|
+
return client.request({
|
|
1946
|
+
method: "GET",
|
|
1947
|
+
service: SERVICE2,
|
|
1948
|
+
path: "/depths"
|
|
1949
|
+
});
|
|
1950
|
+
},
|
|
1943
1951
|
async getDepthDefault() {
|
|
1944
1952
|
return client.request({
|
|
1945
1953
|
method: "GET",
|
|
@@ -2046,6 +2054,69 @@ function createAnalysisService(client) {
|
|
|
2046
2054
|
body: request
|
|
2047
2055
|
});
|
|
2048
2056
|
},
|
|
2057
|
+
// ----- The owner's notes ("What you know and what matters") ------------------------
|
|
2058
|
+
/** Stores the notes only; reading them into proposals is {@link interpretIntent}. */
|
|
2059
|
+
async patchIntent(analysisId, request) {
|
|
2060
|
+
return client.request({
|
|
2061
|
+
method: "PATCH",
|
|
2062
|
+
service: SERVICE2,
|
|
2063
|
+
path: `/${encodeURIComponent(analysisId)}/intent`,
|
|
2064
|
+
body: request
|
|
2065
|
+
});
|
|
2066
|
+
},
|
|
2067
|
+
/** Reads the notes against the setup in the body; nothing is applied. */
|
|
2068
|
+
async interpretIntent(analysisId, request, options = {}) {
|
|
2069
|
+
const query = {};
|
|
2070
|
+
if (options.force) query.force = "true";
|
|
2071
|
+
if (options.refine) query.refine = "true";
|
|
2072
|
+
return client.request({
|
|
2073
|
+
method: "POST",
|
|
2074
|
+
service: SERVICE2,
|
|
2075
|
+
path: `/${encodeURIComponent(analysisId)}/intent/interpretation`,
|
|
2076
|
+
query,
|
|
2077
|
+
body: request
|
|
2078
|
+
});
|
|
2079
|
+
},
|
|
2080
|
+
async getIntentInterpretation(analysisId) {
|
|
2081
|
+
return client.request({
|
|
2082
|
+
method: "GET",
|
|
2083
|
+
service: SERVICE2,
|
|
2084
|
+
path: `/${encodeURIComponent(analysisId)}/intent/interpretation`
|
|
2085
|
+
});
|
|
2086
|
+
},
|
|
2087
|
+
/** Confirms (applies), declines or re-proposes proposals of the stored interpretation. */
|
|
2088
|
+
async decideIntentItems(analysisId, request) {
|
|
2089
|
+
return client.request({
|
|
2090
|
+
method: "PATCH",
|
|
2091
|
+
service: SERVICE2,
|
|
2092
|
+
path: `/${encodeURIComponent(analysisId)}/intent/interpretation/items`,
|
|
2093
|
+
body: request
|
|
2094
|
+
});
|
|
2095
|
+
},
|
|
2096
|
+
async patchShapeExpectations(analysisId, request) {
|
|
2097
|
+
return client.request({
|
|
2098
|
+
method: "PATCH",
|
|
2099
|
+
service: SERVICE2,
|
|
2100
|
+
path: `/${encodeURIComponent(analysisId)}/shape-expectations`,
|
|
2101
|
+
body: request
|
|
2102
|
+
});
|
|
2103
|
+
},
|
|
2104
|
+
async patchRequestedPairs(analysisId, request) {
|
|
2105
|
+
return client.request({
|
|
2106
|
+
method: "PATCH",
|
|
2107
|
+
service: SERVICE2,
|
|
2108
|
+
path: `/${encodeURIComponent(analysisId)}/requested-pairs`,
|
|
2109
|
+
body: request
|
|
2110
|
+
});
|
|
2111
|
+
},
|
|
2112
|
+
async patchFocusFamilies(analysisId, request) {
|
|
2113
|
+
return client.request({
|
|
2114
|
+
method: "PATCH",
|
|
2115
|
+
service: SERVICE2,
|
|
2116
|
+
path: `/${encodeURIComponent(analysisId)}/focus-families`,
|
|
2117
|
+
body: request
|
|
2118
|
+
});
|
|
2119
|
+
},
|
|
2049
2120
|
// ----- Data ingest ----------------------------------------------------------------
|
|
2050
2121
|
async uploadDataMultipart(analysisId, formData) {
|
|
2051
2122
|
return client.request({
|
|
@@ -2173,6 +2244,29 @@ function createAnalysisService(client) {
|
|
|
2173
2244
|
path: `/${encodeURIComponent(analysisId)}/navigation`
|
|
2174
2245
|
});
|
|
2175
2246
|
},
|
|
2247
|
+
/**
|
|
2248
|
+
* The report as Markdown. Without `chapter`: the summary and the outline of chapter titles.
|
|
2249
|
+
* `chapter` is a title, or a path of titles separated by `>` (`Age > Correlation`). `maxBytes` is
|
|
2250
|
+
* clamped by the platform to 4-256 KiB, 32 KiB when absent. A chapter that does not fit comes in
|
|
2251
|
+
* parts; `part` (from 1) names the one to read and is ignored without `chapter`.
|
|
2252
|
+
*/
|
|
2253
|
+
async getReportMarkdown(analysisId, options = {}) {
|
|
2254
|
+
return client.request({
|
|
2255
|
+
method: "GET",
|
|
2256
|
+
service: SERVICE2,
|
|
2257
|
+
path: `/${encodeURIComponent(analysisId)}/report.md`,
|
|
2258
|
+
query: { chapter: options.chapter, part: options.part, maxBytes: options.maxBytes }
|
|
2259
|
+
});
|
|
2260
|
+
},
|
|
2261
|
+
/** The model of one target as source code or a formula in `language`; `target` is needed when there are several. */
|
|
2262
|
+
async exportModel(analysisId, options) {
|
|
2263
|
+
return client.request({
|
|
2264
|
+
method: "GET",
|
|
2265
|
+
service: SERVICE2,
|
|
2266
|
+
path: `/${encodeURIComponent(analysisId)}/model-export`,
|
|
2267
|
+
query: { language: options.language, target: options.target }
|
|
2268
|
+
});
|
|
2269
|
+
},
|
|
2176
2270
|
// ----- Runs -----------------------------------------------------------------------
|
|
2177
2271
|
async runAnalysis(analysisId) {
|
|
2178
2272
|
return client.request({
|
|
@@ -3340,7 +3434,16 @@ function createApiClient(options = {}) {
|
|
|
3340
3434
|
}
|
|
3341
3435
|
|
|
3342
3436
|
// src/commands/auth/token.ts
|
|
3343
|
-
var VALID_RESOURCE_TYPES = ["project", "team"];
|
|
3437
|
+
var VALID_RESOURCE_TYPES = ["project", "team", "user"];
|
|
3438
|
+
function requireResourceUnlessPersonal(create) {
|
|
3439
|
+
const internals = create;
|
|
3440
|
+
const report = internals.missingMandatoryOptionValue.bind(create);
|
|
3441
|
+
internals.missingMandatoryOptionValue = (option) => {
|
|
3442
|
+
const type = String(create.getOptionValue("resourceType") ?? "").trim().toLowerCase();
|
|
3443
|
+
if (option.attributeName() === "resource" && type === "user") return;
|
|
3444
|
+
report(option);
|
|
3445
|
+
};
|
|
3446
|
+
}
|
|
3344
3447
|
var VALID_SCOPES = [
|
|
3345
3448
|
"project:read",
|
|
3346
3449
|
"project:write",
|
|
@@ -3349,9 +3452,19 @@ var VALID_SCOPES = [
|
|
|
3349
3452
|
"evaluation:read",
|
|
3350
3453
|
"evaluation:execute"
|
|
3351
3454
|
];
|
|
3455
|
+
var TOKEN_CREATE_HELP = `
|
|
3456
|
+
A project token reaches one project, a team token the projects of one team. A personal token
|
|
3457
|
+
(--resource-type user) acts for your own account across the projects you can reach, limited by
|
|
3458
|
+
its scopes. No API token reaches account settings: password, sign-in methods, billing and tokens.
|
|
3459
|
+
|
|
3460
|
+
$ diafunc auth token create --name ci --resource <projectId> --scopes project:read,storage:read
|
|
3461
|
+
$ diafunc auth token create --name assistant --resource-type user --scopes project:read,project:write
|
|
3462
|
+
`;
|
|
3352
3463
|
function registerTokenCommands(parent) {
|
|
3353
3464
|
const token = parent.command("token").description("Manage API tokens");
|
|
3354
|
-
token.command("create").description("Create a new API token").requiredOption("--name <name>", "Token name").requiredOption("--resource <id>", "
|
|
3465
|
+
const create = token.command("create").description("Create a new API token for a project, a team, or your own account").requiredOption("--name <name>", "Token name").requiredOption("--resource <id>", "Project or team ID (not needed with --resource-type user)").requiredOption("--scopes <scopes>", `Comma-separated scopes: ${VALID_SCOPES.join(", ")}`).option("--resource-type <type>", `Resource type: ${VALID_RESOURCE_TYPES.join(", ")}`, "project").option("--days <days>", "Validity in days (default: 365)", "365").addHelpText("after", TOKEN_CREATE_HELP);
|
|
3466
|
+
requireResourceUnlessPersonal(create);
|
|
3467
|
+
create.action(async (options, cmd) => {
|
|
3355
3468
|
try {
|
|
3356
3469
|
const config = loadConfig();
|
|
3357
3470
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -3374,13 +3487,15 @@ function registerTokenCommands(parent) {
|
|
|
3374
3487
|
const api = createApiClient();
|
|
3375
3488
|
const result = await api.admin.createApiToken({
|
|
3376
3489
|
name: options.name,
|
|
3377
|
-
|
|
3490
|
+
// A personal token's resource is the caller's own account, which the platform fills in.
|
|
3491
|
+
// A given id is passed on; the platform refuses one that is not the caller's.
|
|
3492
|
+
...options.resource !== void 0 ? { resourceId: options.resource } : {},
|
|
3378
3493
|
resourceType,
|
|
3379
3494
|
scopes,
|
|
3380
3495
|
validityDays: parseInt(options.days, 10)
|
|
3381
3496
|
});
|
|
3382
3497
|
if (outputFormat === "human") {
|
|
3383
|
-
success("API token created
|
|
3498
|
+
success("API token created.");
|
|
3384
3499
|
console.log();
|
|
3385
3500
|
console.log(` Token: ${chalk8.bold(result.token)}`);
|
|
3386
3501
|
console.log(` Token ID: ${result.tokenId}`);
|
|
@@ -3404,7 +3519,7 @@ function registerTokenCommands(parent) {
|
|
|
3404
3519
|
const tokens = options.resource ? await api.admin.getApiTokensByResource(options.resource) : await api.admin.getApiTokens();
|
|
3405
3520
|
format(tokens, {
|
|
3406
3521
|
format: outputFormat,
|
|
3407
|
-
columns: ["tokenId", "name", "resourceId", "scopes", "createdAt", "expiresAt"]
|
|
3522
|
+
columns: ["tokenId", "name", "resourceType", "resourceId", "scopes", "createdAt", "expiresAt"]
|
|
3408
3523
|
});
|
|
3409
3524
|
} catch (error) {
|
|
3410
3525
|
handleError(error);
|
|
@@ -3574,6 +3689,55 @@ function getNestedValue(obj, path13) {
|
|
|
3574
3689
|
// src/commands/project/index.ts
|
|
3575
3690
|
import chalk13 from "chalk";
|
|
3576
3691
|
|
|
3692
|
+
// src/util/hidden-aliases.ts
|
|
3693
|
+
import { Help, Option } from "commander";
|
|
3694
|
+
var hidden = /* @__PURE__ */ new WeakMap();
|
|
3695
|
+
function hiddenAlias(cmd, alias) {
|
|
3696
|
+
cmd.alias(alias);
|
|
3697
|
+
const names = hidden.get(cmd) ?? /* @__PURE__ */ new Set();
|
|
3698
|
+
names.add(alias);
|
|
3699
|
+
hidden.set(cmd, names);
|
|
3700
|
+
return cmd;
|
|
3701
|
+
}
|
|
3702
|
+
function visibleAliases(cmd) {
|
|
3703
|
+
const names = hidden.get(cmd);
|
|
3704
|
+
return cmd.aliases().filter((alias) => !names?.has(alias));
|
|
3705
|
+
}
|
|
3706
|
+
function withVisibleAliasesOnly(cmd, render) {
|
|
3707
|
+
const target = cmd;
|
|
3708
|
+
const all = target._aliases;
|
|
3709
|
+
target._aliases = visibleAliases(cmd);
|
|
3710
|
+
try {
|
|
3711
|
+
return render();
|
|
3712
|
+
} finally {
|
|
3713
|
+
target._aliases = all;
|
|
3714
|
+
}
|
|
3715
|
+
}
|
|
3716
|
+
var HIDDEN_ALIAS_HELP = {
|
|
3717
|
+
subcommandTerm(cmd) {
|
|
3718
|
+
return withVisibleAliasesOnly(cmd, () => Help.prototype.subcommandTerm.call(this, cmd));
|
|
3719
|
+
},
|
|
3720
|
+
commandUsage(cmd) {
|
|
3721
|
+
return withVisibleAliasesOnly(cmd, () => Help.prototype.commandUsage.call(this, cmd));
|
|
3722
|
+
}
|
|
3723
|
+
};
|
|
3724
|
+
var optionTargets = /* @__PURE__ */ new WeakMap();
|
|
3725
|
+
function hiddenOptionAlias(oldFlags, target) {
|
|
3726
|
+
const option = new Option(oldFlags).hideHelp();
|
|
3727
|
+
optionTargets.set(option, target);
|
|
3728
|
+
return option;
|
|
3729
|
+
}
|
|
3730
|
+
function wireHiddenOptionAliases(cmd) {
|
|
3731
|
+
for (const option of cmd.options) {
|
|
3732
|
+
const target = optionTargets.get(option);
|
|
3733
|
+
if (!target) continue;
|
|
3734
|
+
cmd.on(`option:${option.name()}`, (value) => {
|
|
3735
|
+
cmd.setOptionValue(target, value);
|
|
3736
|
+
});
|
|
3737
|
+
}
|
|
3738
|
+
for (const sub of cmd.commands) wireHiddenOptionAliases(sub);
|
|
3739
|
+
}
|
|
3740
|
+
|
|
3577
3741
|
// src/util/references.ts
|
|
3578
3742
|
function parseEntityReference(ref, overrides) {
|
|
3579
3743
|
const config = loadConfig();
|
|
@@ -3933,6 +4097,81 @@ async function projectNames(api, projectIds) {
|
|
|
3933
4097
|
return names;
|
|
3934
4098
|
}
|
|
3935
4099
|
|
|
4100
|
+
// src/util/entity-attributes.ts
|
|
4101
|
+
function encodeTextAttribute(value) {
|
|
4102
|
+
return Buffer.from(value, "utf-8").toString("base64");
|
|
4103
|
+
}
|
|
4104
|
+
function decodeTextAttribute(value) {
|
|
4105
|
+
if (value === null || value === void 0) return null;
|
|
4106
|
+
return Buffer.from(value, "base64").toString("utf-8");
|
|
4107
|
+
}
|
|
4108
|
+
function encodeLongAttribute(value) {
|
|
4109
|
+
if (!Number.isSafeInteger(value)) {
|
|
4110
|
+
throw new RangeError(`Not an integer attribute value: ${value}`);
|
|
4111
|
+
}
|
|
4112
|
+
const bytes = Buffer.alloc(8);
|
|
4113
|
+
bytes.writeBigInt64BE(BigInt(value));
|
|
4114
|
+
return bytes.toString("base64");
|
|
4115
|
+
}
|
|
4116
|
+
|
|
4117
|
+
// src/util/project-entity.ts
|
|
4118
|
+
function buildProjectRootEntity(args) {
|
|
4119
|
+
const now = Date.now();
|
|
4120
|
+
const attributes = {};
|
|
4121
|
+
const attributeTypes = {};
|
|
4122
|
+
if (args.name) {
|
|
4123
|
+
attributes.name = encodeTextAttribute(args.name);
|
|
4124
|
+
attributeTypes.name = "text";
|
|
4125
|
+
}
|
|
4126
|
+
if (args.description) {
|
|
4127
|
+
attributes.description = encodeTextAttribute(args.description);
|
|
4128
|
+
attributeTypes.description = "text";
|
|
4129
|
+
}
|
|
4130
|
+
return {
|
|
4131
|
+
projectId: args.projectId,
|
|
4132
|
+
projectBranch: "main",
|
|
4133
|
+
entityId: args.projectId,
|
|
4134
|
+
entityBranch: "main",
|
|
4135
|
+
head: true,
|
|
4136
|
+
version: 1,
|
|
4137
|
+
type: "project",
|
|
4138
|
+
attributes,
|
|
4139
|
+
attributeTypes,
|
|
4140
|
+
metaAttributes: {},
|
|
4141
|
+
metaAttributeTypes: {},
|
|
4142
|
+
tags: [],
|
|
4143
|
+
modified: now,
|
|
4144
|
+
created: now,
|
|
4145
|
+
versioned: false,
|
|
4146
|
+
versionTtl: null,
|
|
4147
|
+
retain: false,
|
|
4148
|
+
contentAvailable: false,
|
|
4149
|
+
contentLoaded: false,
|
|
4150
|
+
contentType: null,
|
|
4151
|
+
contentSize: null,
|
|
4152
|
+
content: null
|
|
4153
|
+
};
|
|
4154
|
+
}
|
|
4155
|
+
function withProjectTexts(root, texts) {
|
|
4156
|
+
const attributes = { ...root.attributes ?? {} };
|
|
4157
|
+
const attributeTypes = { ...root.attributeTypes ?? {} };
|
|
4158
|
+
if (texts.name !== void 0) {
|
|
4159
|
+
attributes.name = encodeTextAttribute(texts.name.trim());
|
|
4160
|
+
attributeTypes.name = "text";
|
|
4161
|
+
}
|
|
4162
|
+
if (texts.description !== void 0) {
|
|
4163
|
+
const description = texts.description.trim();
|
|
4164
|
+
if (description) {
|
|
4165
|
+
attributes.description = encodeTextAttribute(description);
|
|
4166
|
+
attributeTypes.description = "text";
|
|
4167
|
+
} else {
|
|
4168
|
+
delete attributes.description;
|
|
4169
|
+
delete attributeTypes.description;
|
|
4170
|
+
}
|
|
4171
|
+
}
|
|
4172
|
+
return { ...root, attributes, attributeTypes, content: null };
|
|
4173
|
+
}
|
|
4174
|
+
|
|
3936
4175
|
// src/commands/entity/tags.ts
|
|
3937
4176
|
import chalk12 from "chalk";
|
|
3938
4177
|
|
|
@@ -4204,11 +4443,13 @@ Showing ${capped.length} of ${projects.length}. Pass --limit 0 to see them all.`
|
|
|
4204
4443
|
handleError(error);
|
|
4205
4444
|
}
|
|
4206
4445
|
});
|
|
4207
|
-
project.command("create").description("Create a new project").option("--visibility <visibility>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--language <language>", "The project's default language for functions (Java, Kotlin, Python, JavaScript, Scala)", DEFAULT_FUNCTION_LANGUAGE).option("--
|
|
4446
|
+
project.command("create").description("Create a new project").option("--name <name>", "The project's name; without one, a project bundle imported into it names it").option("--description <text>", "The project's description").option("--visibility <visibility>", "Project visibility (PRIVATE or PUBLIC)", "PRIVATE").option("--language <language>", "The project's default language for functions (Java, Kotlin, Python, JavaScript, Scala)", DEFAULT_FUNCTION_LANGUAGE).option("--license <licenseId>", "License a public project is published under, an id of the license catalog (see 'diafunc license list')").addOption(hiddenOptionAlias("--licence <licenseId>", "license")).addHelpText("after", `
|
|
4208
4447
|
Examples:
|
|
4209
4448
|
$ diafunc project create a private project
|
|
4210
|
-
$ diafunc project create --
|
|
4211
|
-
$ diafunc
|
|
4449
|
+
$ diafunc project create --name "Vineyard yield" a private project with a name
|
|
4450
|
+
$ diafunc project import <projectId> guide.dfproj an unnamed one takes the bundle's name
|
|
4451
|
+
$ diafunc project create --visibility PUBLIC --license CC-BY-4.0 a public one, open for reuse with attribution
|
|
4452
|
+
$ diafunc license list the licenses that can be chosen
|
|
4212
4453
|
`).action(async (options, cmd) => {
|
|
4213
4454
|
try {
|
|
4214
4455
|
const outputFormat = getOutputFormat2(cmd);
|
|
@@ -4217,19 +4458,25 @@ Examples:
|
|
|
4217
4458
|
visibility: options.visibility.toUpperCase(),
|
|
4218
4459
|
language: options.language,
|
|
4219
4460
|
active: true,
|
|
4220
|
-
...options.
|
|
4461
|
+
...options.license ? { licenceId: options.license } : {}
|
|
4221
4462
|
});
|
|
4222
4463
|
await api.storage.createProjectBranch({
|
|
4223
4464
|
projectId: p.projectId,
|
|
4224
4465
|
sourceProjectBranch: null,
|
|
4225
4466
|
targetProjectBranch: "main"
|
|
4226
4467
|
});
|
|
4468
|
+
await api.storage.saveEntities([buildProjectRootEntity({
|
|
4469
|
+
projectId: p.projectId,
|
|
4470
|
+
name: options.name,
|
|
4471
|
+
description: options.description
|
|
4472
|
+
})]);
|
|
4227
4473
|
if (outputFormat === "human") {
|
|
4228
4474
|
success("Project created.");
|
|
4475
|
+
if (options.name) console.log(` Name: ${options.name}`);
|
|
4229
4476
|
console.log(` Project ID: ${chalk13.bold(p.projectId)}`);
|
|
4230
4477
|
console.log(` Visibility: ${p.visibility}`);
|
|
4231
4478
|
console.log(` Language: ${p.language}`);
|
|
4232
|
-
if (p.licenceId) console.log(`
|
|
4479
|
+
if (p.licenceId) console.log(` License: ${p.licenceId}`);
|
|
4233
4480
|
} else {
|
|
4234
4481
|
format(p, { format: outputFormat });
|
|
4235
4482
|
}
|
|
@@ -4237,16 +4484,46 @@ Examples:
|
|
|
4237
4484
|
handleError(error);
|
|
4238
4485
|
}
|
|
4239
4486
|
});
|
|
4240
|
-
project.command("update").description("Update a project").argument("<projectId>", "Project ID").option("--visibility <visibility>", "PRIVATE or PUBLIC").option("--language <language>", "Project language").option("--active <bool>", "Whether the project is active (true/false)").option("--
|
|
4241
|
-
|
|
4242
|
-
|
|
4487
|
+
project.command("update").description("Update a project").argument("<projectId>", "Project ID").option("--name <name>", "The project's name, shown on Explore and in the project header").option("--description <text>", "The project's description, shown on Explore; an empty value removes it").option("--visibility <visibility>", "PRIVATE or PUBLIC").option("--language <language>", "Project language").option("--active <bool>", "Whether the project is active (true/false)").option("--license <licenseId>", "License a public project is published under, an id of the license catalog (CC-BY-4.0, CC0-1.0, diafunc-view-only, ...)").addOption(hiddenOptionAlias("--licence <licenseId>", "license")).option("--data-source-name <name>", "Who published the data the project analyzes; an empty value clears it").option("--data-source-url <url>", "Where the data was obtained, an http(s) address; an empty value clears it").addHelpText("after", `
|
|
4488
|
+
Examples:
|
|
4489
|
+
$ diafunc project update <projectId> --name "Vineyard yield" rename the project
|
|
4490
|
+
$ diafunc project update <projectId> --description "Yield per hectare" set the text Explore shows
|
|
4491
|
+
$ diafunc project update <projectId> --license CC-BY-4.0 publish it under another license
|
|
4492
|
+
`).action(async (projectId, options) => {
|
|
4493
|
+
try {
|
|
4494
|
+
const api = createApiClient();
|
|
4495
|
+
const projectOptions = ["visibility", "language", "active", "license", "dataSourceName", "dataSourceUrl"];
|
|
4496
|
+
const changesProject = projectOptions.some((key) => options[key] !== void 0);
|
|
4497
|
+
const changesTexts = options.name !== void 0 || options.description !== void 0;
|
|
4498
|
+
if (!changesProject && !changesTexts) {
|
|
4499
|
+
throw new Error("Nothing to update: give at least one option (see --help).");
|
|
4500
|
+
}
|
|
4501
|
+
if (options.name !== void 0 && !options.name.trim()) {
|
|
4502
|
+
throw new Error("A project name cannot be empty.");
|
|
4503
|
+
}
|
|
4504
|
+
if (changesTexts) {
|
|
4505
|
+
const root = await api.storage.getEntity({
|
|
4506
|
+
projectId,
|
|
4507
|
+
projectBranch: "main",
|
|
4508
|
+
entityId: projectId,
|
|
4509
|
+
entityBranch: "main"
|
|
4510
|
+
});
|
|
4511
|
+
await api.storage.saveEntities([withProjectTexts(root, {
|
|
4512
|
+
name: options.name,
|
|
4513
|
+
description: options.description
|
|
4514
|
+
})]);
|
|
4515
|
+
}
|
|
4516
|
+
if (!changesProject) {
|
|
4517
|
+
success(`Project "${projectId}" updated.`);
|
|
4518
|
+
return;
|
|
4519
|
+
}
|
|
4243
4520
|
const current = await api.admin.getProject(projectId);
|
|
4244
4521
|
const updated = {
|
|
4245
4522
|
...current,
|
|
4246
4523
|
...options.visibility ? { visibility: options.visibility.toUpperCase() } : {},
|
|
4247
4524
|
...options.language ? { language: options.language } : {},
|
|
4248
4525
|
...options.active !== void 0 ? { active: options.active === "true" } : {},
|
|
4249
|
-
...options.
|
|
4526
|
+
...options.license ? { licenceId: options.license } : {},
|
|
4250
4527
|
...options.dataSourceName !== void 0 ? { dataSourceName: options.dataSourceName } : {},
|
|
4251
4528
|
...options.dataSourceUrl !== void 0 ? { dataSourceUrl: options.dataSourceUrl } : {}
|
|
4252
4529
|
};
|
|
@@ -4363,7 +4640,7 @@ Examples:
|
|
|
4363
4640
|
handleError(error);
|
|
4364
4641
|
}
|
|
4365
4642
|
});
|
|
4366
|
-
project.command("import").description("Import a .dfproj (or any) bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project2, file, options, cmd) => {
|
|
4643
|
+
project.command("import").description("Import a .dfproj (or any) bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the bundle").option("--on-conflict <policy>", "copy (default; copy only entities whose id already exists, under a new id), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project2, file, options, cmd) => {
|
|
4367
4644
|
try {
|
|
4368
4645
|
const outputFormat = getOutputFormat2(cmd);
|
|
4369
4646
|
const overrides = getOverrides(cmd);
|
|
@@ -4560,7 +4837,7 @@ Examples:
|
|
|
4560
4837
|
const api = createApiClient();
|
|
4561
4838
|
const response = await api.admin.cancelTeam(teamId);
|
|
4562
4839
|
success(
|
|
4563
|
-
`Team "${teamId}"
|
|
4840
|
+
`Team "${teamId}" canceled. Access ends ${response.endsAt ?? "at the end of the period"}.`,
|
|
4564
4841
|
{ format: getOutputFormat3(cmd) }
|
|
4565
4842
|
);
|
|
4566
4843
|
} catch (error) {
|
|
@@ -4796,7 +5073,7 @@ function registerOwnershipCommands(team) {
|
|
|
4796
5073
|
try {
|
|
4797
5074
|
const api = createApiClient();
|
|
4798
5075
|
await api.admin.cancelOwnershipTransfer(teamId);
|
|
4799
|
-
success(`
|
|
5076
|
+
success(`Canceled the ownership transfer for team "${teamId}".`, {
|
|
4800
5077
|
format: getOutputFormat3(cmd)
|
|
4801
5078
|
});
|
|
4802
5079
|
} catch (error) {
|
|
@@ -5015,7 +5292,7 @@ Examples:
|
|
|
5015
5292
|
handleError(error);
|
|
5016
5293
|
}
|
|
5017
5294
|
});
|
|
5018
|
-
entity.command("import").description("Import a .dfset (or any) bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project, file, options, cmd) => {
|
|
5295
|
+
entity.command("import").description("Import a .dfset (or any) bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the bundle").option("--on-conflict <policy>", "copy (default; copy only entities whose id already exists, under a new id), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project, file, options, cmd) => {
|
|
5019
5296
|
try {
|
|
5020
5297
|
const outputFormat = getOutputFormat4(cmd);
|
|
5021
5298
|
const overrides = getOverrides2(cmd);
|
|
@@ -5164,8 +5441,8 @@ function registerEventCommands(program) {
|
|
|
5164
5441
|
});
|
|
5165
5442
|
event.command("create").description("Create one or more events (body from JSON file or stdin)").argument("[file]", "JSON file containing a BareEvent array; defaults to stdin").action(async (file) => {
|
|
5166
5443
|
try {
|
|
5167
|
-
const
|
|
5168
|
-
const body = file ?
|
|
5444
|
+
const fs19 = await import("fs");
|
|
5445
|
+
const body = file ? fs19.readFileSync(file, "utf-8") : await new Promise((resolve2, reject) => {
|
|
5169
5446
|
let data = "";
|
|
5170
5447
|
process.stdin.setEncoding("utf-8");
|
|
5171
5448
|
process.stdin.on("data", (chunk) => {
|
|
@@ -5227,7 +5504,7 @@ function registerBranchCommands(program) {
|
|
|
5227
5504
|
Examples:
|
|
5228
5505
|
$ diafunc branch list <projectId>
|
|
5229
5506
|
$ diafunc branch create <projectId> experiment
|
|
5230
|
-
$ diafunc branch merge --
|
|
5507
|
+
$ diafunc branch merge --source <projectId>/experiment/<entityId>/main --target <projectId>/main
|
|
5231
5508
|
`);
|
|
5232
5509
|
;
|
|
5233
5510
|
branch.command("list").description("List branches for a project").argument("[projectId]", "Project ID (uses default if omitted)").action(async (projectId, _options, cmd) => {
|
|
@@ -5395,7 +5672,7 @@ async function fetchWindow(fetchPart, window, maxCells = SNAPSHOT_MAX_CELLS) {
|
|
|
5395
5672
|
}
|
|
5396
5673
|
function describeWindow(window, rows, columns) {
|
|
5397
5674
|
const whole = window.rows.from === 0 && window.rows.to === rows && window.columns.from === 0 && window.columns.to === columns;
|
|
5398
|
-
const line = `Rows ${window.rows.from}
|
|
5675
|
+
const line = `Rows ${window.rows.from} to ${window.rows.to - 1} of ${rows} \xB7 columns ${window.columns.from} to ${window.columns.to - 1} of ${columns}`;
|
|
5399
5676
|
return whole ? line : `${line} \xB7 use --rows/--cols for more`;
|
|
5400
5677
|
}
|
|
5401
5678
|
function decodeCellValue(value, type) {
|
|
@@ -5415,23 +5692,6 @@ function decodeCellValue(value, type) {
|
|
|
5415
5692
|
return bytes.toString("utf-8");
|
|
5416
5693
|
}
|
|
5417
5694
|
|
|
5418
|
-
// src/util/entity-attributes.ts
|
|
5419
|
-
function encodeTextAttribute(value) {
|
|
5420
|
-
return Buffer.from(value, "utf-8").toString("base64");
|
|
5421
|
-
}
|
|
5422
|
-
function decodeTextAttribute(value) {
|
|
5423
|
-
if (value === null || value === void 0) return null;
|
|
5424
|
-
return Buffer.from(value, "base64").toString("utf-8");
|
|
5425
|
-
}
|
|
5426
|
-
function encodeLongAttribute(value) {
|
|
5427
|
-
if (!Number.isSafeInteger(value)) {
|
|
5428
|
-
throw new RangeError(`Not an integer attribute value: ${value}`);
|
|
5429
|
-
}
|
|
5430
|
-
const bytes = Buffer.alloc(8);
|
|
5431
|
-
bytes.writeBigInt64BE(BigInt(value));
|
|
5432
|
-
return bytes.toString("base64");
|
|
5433
|
-
}
|
|
5434
|
-
|
|
5435
5695
|
// src/util/table-entity.ts
|
|
5436
5696
|
function buildTableEntity(args) {
|
|
5437
5697
|
const now = Date.now();
|
|
@@ -5727,7 +5987,7 @@ Examples:
|
|
|
5727
5987
|
const formats = await api.storage.getSupportedExportFormats();
|
|
5728
5988
|
const format2 = formats.formats.find((f) => f.id.toLowerCase() === fmt.toLowerCase());
|
|
5729
5989
|
if (!format2) {
|
|
5730
|
-
failure(`Unknown format: "${fmt}". Run \`diafunc table export-formats\` to see the
|
|
5990
|
+
failure(`Unknown format: "${fmt}". Run \`diafunc table export-formats\` to see the catalog.`);
|
|
5731
5991
|
process.exit(1);
|
|
5732
5992
|
}
|
|
5733
5993
|
if (options.compression && !formats.compressionAlgorithms.includes(options.compression)) {
|
|
@@ -6011,7 +6271,7 @@ function getOverrides7(cmd) {
|
|
|
6011
6271
|
function registerNotebookCommands(program) {
|
|
6012
6272
|
const notebook = program.command("notebook").description("Export and import notebook bundles").addHelpText("after", `
|
|
6013
6273
|
Examples:
|
|
6014
|
-
$ diafunc notebook export <project> <notebookId>
|
|
6274
|
+
$ diafunc notebook export <project> <notebookId> --out notebook.dfnb
|
|
6015
6275
|
$ diafunc notebook import <project> notebook.dfnb --preview
|
|
6016
6276
|
$ diafunc notebook import <project> notebook.dfnb
|
|
6017
6277
|
`);
|
|
@@ -6037,7 +6297,7 @@ Examples:
|
|
|
6037
6297
|
handleError(error);
|
|
6038
6298
|
}
|
|
6039
6299
|
});
|
|
6040
|
-
notebook.command("import").description("Import a .dfnb bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the .dfnb bundle").option("--on-conflict <policy>", "copy (default), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project, file, options, cmd) => {
|
|
6300
|
+
notebook.command("import").description("Import a .dfnb bundle into a project").argument("<project>", "Target project reference (projectId or projectId/branch)").argument("<file>", "Path to the .dfnb bundle").option("--on-conflict <policy>", "copy (default; copy only entities whose id already exists, under a new id), overwrite, or skip", "copy").option("--preview", "Show the bundle inventory without importing").action(async (project, file, options, cmd) => {
|
|
6041
6301
|
try {
|
|
6042
6302
|
const outputFormat = getOutputFormat9(cmd);
|
|
6043
6303
|
const overrides = getOverrides7(cmd);
|
|
@@ -6306,7 +6566,7 @@ Examples:
|
|
|
6306
6566
|
} else {
|
|
6307
6567
|
if (outputFormat === "human") {
|
|
6308
6568
|
if (result.successful) {
|
|
6309
|
-
success("Function completed
|
|
6569
|
+
success("Function completed.");
|
|
6310
6570
|
if (result.result) {
|
|
6311
6571
|
console.log(` Result: ${resultText(result.result, result.resultEncoding)}`);
|
|
6312
6572
|
}
|
|
@@ -6573,58 +6833,890 @@ function extensionFor(language) {
|
|
|
6573
6833
|
return "txt";
|
|
6574
6834
|
}
|
|
6575
6835
|
|
|
6576
|
-
// src/commands/
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6836
|
+
// src/commands/analyze/intent.ts
|
|
6837
|
+
import * as fs9 from "fs";
|
|
6838
|
+
import chalk19 from "chalk";
|
|
6839
|
+
|
|
6840
|
+
// src/commands/analyze/columns.ts
|
|
6841
|
+
var MAX_COLUMNS_LISTED = 30;
|
|
6842
|
+
var MAX_NEAR_MATCHES = 3;
|
|
6843
|
+
function parseColumnList(text2) {
|
|
6844
|
+
const names = [];
|
|
6845
|
+
let i = 0;
|
|
6846
|
+
while (i < text2.length) {
|
|
6847
|
+
while (i < text2.length && isSpace(text2[i])) i++;
|
|
6848
|
+
if (i >= text2.length) break;
|
|
6849
|
+
if (text2[i] === '"') {
|
|
6850
|
+
let name = "";
|
|
6851
|
+
let closed = false;
|
|
6852
|
+
i++;
|
|
6853
|
+
while (i < text2.length) {
|
|
6854
|
+
if (text2[i] === '"' && text2[i + 1] === '"') {
|
|
6855
|
+
name += '"';
|
|
6856
|
+
i += 2;
|
|
6857
|
+
} else if (text2[i] === '"') {
|
|
6858
|
+
closed = true;
|
|
6859
|
+
i++;
|
|
6860
|
+
break;
|
|
6861
|
+
} else {
|
|
6862
|
+
name += text2[i++];
|
|
6863
|
+
}
|
|
6864
|
+
}
|
|
6865
|
+
if (!closed) {
|
|
6866
|
+
throw new CliError(`A double quote is opened and never closed in: ${text2}`, {
|
|
6867
|
+
exitCode: EXIT_USAGE,
|
|
6868
|
+
hint: QUOTING_HINT
|
|
6869
|
+
});
|
|
6870
|
+
}
|
|
6871
|
+
while (i < text2.length && isSpace(text2[i])) i++;
|
|
6872
|
+
if (i < text2.length && text2[i] !== ",") {
|
|
6873
|
+
throw new CliError(`Text follows a closing double quote without a comma in: ${text2}`, {
|
|
6874
|
+
exitCode: EXIT_USAGE,
|
|
6875
|
+
hint: QUOTING_HINT
|
|
6876
|
+
});
|
|
6877
|
+
}
|
|
6878
|
+
i++;
|
|
6879
|
+
if (name.length > 0) names.push(name);
|
|
6880
|
+
} else {
|
|
6881
|
+
const end = text2.indexOf(",", i);
|
|
6882
|
+
const name = text2.slice(i, end === -1 ? text2.length : end).trim();
|
|
6883
|
+
i = end === -1 ? text2.length : end + 1;
|
|
6884
|
+
if (name.length > 0) names.push(name);
|
|
6885
|
+
}
|
|
6886
|
+
}
|
|
6887
|
+
return names;
|
|
6581
6888
|
}
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
return
|
|
6889
|
+
var QUOTING_HINT = `Inside a list, put a name that contains a comma in double quotes and write a quote in it twice: '"a, b",c'.`;
|
|
6890
|
+
function isSpace(char) {
|
|
6891
|
+
return char === " " || char === " ";
|
|
6585
6892
|
}
|
|
6586
|
-
function
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
;
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6893
|
+
function quoteColumn(name) {
|
|
6894
|
+
return `"${name.replace(/"/g, '""')}"`;
|
|
6895
|
+
}
|
|
6896
|
+
function loose(name) {
|
|
6897
|
+
return name.trim().toLowerCase();
|
|
6898
|
+
}
|
|
6899
|
+
function matchColumn(name, columns) {
|
|
6900
|
+
if (columns.includes(name)) return { kind: "column", column: name };
|
|
6901
|
+
const wanted = loose(name);
|
|
6902
|
+
const candidates = columns.filter((column) => loose(column) === wanted);
|
|
6903
|
+
if (candidates.length === 1) return { kind: "column", column: candidates[0] };
|
|
6904
|
+
return candidates.length > 1 ? { kind: "ambiguous", candidates } : { kind: "unknown" };
|
|
6905
|
+
}
|
|
6906
|
+
function nearMatches(name, columns) {
|
|
6907
|
+
const wanted = loose(name);
|
|
6908
|
+
if (wanted.length === 0) return [];
|
|
6909
|
+
return columns.map((column) => ({ column, distance: distanceTo(wanted, loose(column)) })).filter((scored) => scored.distance !== null).sort((a, b) => a.distance - b.distance).slice(0, MAX_NEAR_MATCHES).map((scored) => scored.column);
|
|
6910
|
+
}
|
|
6911
|
+
function distanceTo(wanted, column) {
|
|
6912
|
+
const edits = editDistance(wanted, column);
|
|
6913
|
+
if (edits <= Math.max(1, Math.floor(Math.min(wanted.length, column.length) / 4))) return edits;
|
|
6914
|
+
if (wanted.length >= 3 && (column.includes(wanted) || wanted.includes(column)) && column.length > 0) {
|
|
6915
|
+
return 100 + Math.abs(column.length - wanted.length);
|
|
6916
|
+
}
|
|
6917
|
+
return null;
|
|
6918
|
+
}
|
|
6919
|
+
function editDistance(a, b) {
|
|
6920
|
+
let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
6921
|
+
for (let i = 1; i <= a.length; i++) {
|
|
6922
|
+
const current = [i];
|
|
6923
|
+
for (let j = 1; j <= b.length; j++) {
|
|
6924
|
+
current[j] = Math.min(
|
|
6925
|
+
previous[j] + 1,
|
|
6926
|
+
current[j - 1] + 1,
|
|
6927
|
+
previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)
|
|
6928
|
+
);
|
|
6929
|
+
}
|
|
6930
|
+
previous = current;
|
|
6931
|
+
}
|
|
6932
|
+
return previous[b.length];
|
|
6933
|
+
}
|
|
6934
|
+
function take(name, columns, into, problems) {
|
|
6935
|
+
const match = matchColumn(name, columns);
|
|
6936
|
+
if (match.kind === "column") {
|
|
6937
|
+
if (!into.includes(match.column)) into.push(match.column);
|
|
6938
|
+
return true;
|
|
6939
|
+
}
|
|
6940
|
+
if (match.kind === "ambiguous") problems.ambiguous.push({ name, candidates: match.candidates });
|
|
6941
|
+
else problems.unknown.push(name);
|
|
6942
|
+
return false;
|
|
6943
|
+
}
|
|
6944
|
+
function refuse(problems, columns, analysisId) {
|
|
6945
|
+
const sentences = [];
|
|
6946
|
+
if (problems.unknown.length === 1) {
|
|
6947
|
+
sentences.push(`${quoteColumn(problems.unknown[0])} is not a column of the analysis data.`);
|
|
6948
|
+
} else if (problems.unknown.length > 1) {
|
|
6949
|
+
sentences.push(`These are not columns of the analysis data: ${problems.unknown.map(quoteColumn).join(", ")}.`);
|
|
6950
|
+
}
|
|
6951
|
+
for (const { name, candidates } of problems.ambiguous) {
|
|
6952
|
+
sentences.push(`${quoteColumn(name)} matches more than one column: ${candidates.map(quoteColumn).join(", ")}. Type the one you mean exactly.`);
|
|
6953
|
+
}
|
|
6954
|
+
const hints = [];
|
|
6955
|
+
const near = [...new Set(problems.unknown.flatMap((name) => nearMatches(name, columns)))];
|
|
6956
|
+
if (near.length > 0) hints.push(`Did you mean ${near.map(quoteColumn).join(" or ")}?`);
|
|
6957
|
+
const listed2 = columns.slice(0, MAX_COLUMNS_LISTED).map(quoteColumn).join(", ");
|
|
6958
|
+
const more = columns.length > MAX_COLUMNS_LISTED ? ` and ${columns.length - MAX_COLUMNS_LISTED} more${analysisId ? ` ('diafunc analyze columns ${analysisId}' lists them all)` : ""}` : "";
|
|
6959
|
+
hints.push(`The columns are: ${listed2}${more}.`);
|
|
6960
|
+
if (problems.fromList) {
|
|
6961
|
+
hints.push(`A name that contains a comma is an argument of its own, or goes in double quotes inside a list: '"a, b",c'.`);
|
|
6962
|
+
}
|
|
6963
|
+
throw new CliError(sentences.join(" "), { exitCode: EXIT_USAGE, hint: hints.join("\n ") });
|
|
6964
|
+
}
|
|
6965
|
+
function resolveColumnArguments(given, columns, analysisId) {
|
|
6966
|
+
const resolved = [];
|
|
6967
|
+
if (columns.length === 0) {
|
|
6968
|
+
for (const name of given.flatMap(parseColumnList)) {
|
|
6969
|
+
if (!resolved.includes(name)) resolved.push(name);
|
|
6970
|
+
}
|
|
6971
|
+
return resolved;
|
|
6972
|
+
}
|
|
6973
|
+
const problems = { unknown: [], ambiguous: [], fromList: false };
|
|
6974
|
+
for (const argument of given) {
|
|
6975
|
+
if (argument.trim().length === 0) continue;
|
|
6976
|
+
const whole = matchColumn(argument, columns);
|
|
6977
|
+
if (whole.kind === "column") {
|
|
6978
|
+
if (!resolved.includes(whole.column)) resolved.push(whole.column);
|
|
6979
|
+
continue;
|
|
6980
|
+
}
|
|
6981
|
+
const names = parseColumnList(argument);
|
|
6982
|
+
const single = names.length === 1 && names[0] === argument.trim();
|
|
6983
|
+
for (const name of names) {
|
|
6984
|
+
if (!take(name, columns, resolved, problems) && !single) problems.fromList = true;
|
|
6985
|
+
}
|
|
6986
|
+
}
|
|
6987
|
+
if (problems.unknown.length > 0 || problems.ambiguous.length > 0) refuse(problems, columns, analysisId);
|
|
6988
|
+
return resolved;
|
|
6989
|
+
}
|
|
6990
|
+
function resolveColumnNames(names, columns, analysisId) {
|
|
6991
|
+
if (columns.length === 0) return [...names];
|
|
6992
|
+
const resolved = [];
|
|
6993
|
+
const problems = { unknown: [], ambiguous: [], fromList: false };
|
|
6994
|
+
for (const name of names) take(name, columns, resolved, problems);
|
|
6995
|
+
if (problems.unknown.length > 0 || problems.ambiguous.length > 0) refuse(problems, columns, analysisId);
|
|
6996
|
+
return resolved;
|
|
6997
|
+
}
|
|
6998
|
+
function resolveColumnArgument(given, columns, analysisId) {
|
|
6999
|
+
if (columns.length === 0) return given;
|
|
7000
|
+
return resolveColumnNames([given], columns, analysisId)[0];
|
|
7001
|
+
}
|
|
7002
|
+
function occurrences(value) {
|
|
7003
|
+
if (value === void 0) return void 0;
|
|
7004
|
+
return Array.isArray(value) ? value : [value];
|
|
7005
|
+
}
|
|
7006
|
+
function collectColumns(value, previous = []) {
|
|
7007
|
+
return previous.concat([value]);
|
|
7008
|
+
}
|
|
7009
|
+
|
|
7010
|
+
// src/commands/analyze/intent.ts
|
|
7011
|
+
var MAX_INTENT_LENGTH = 8e3;
|
|
7012
|
+
var MAX_PAIRS = 12;
|
|
7013
|
+
var MAX_FOCUS = 3;
|
|
7014
|
+
var CHART_KINDS = ["scatter", "groups", "counts"];
|
|
7015
|
+
var SHAPE_KINDS = ["increasing", "decreasing", "convex", "concave", "range"];
|
|
7016
|
+
var FOCUS_FAMILIES = [
|
|
7017
|
+
{ id: "formula", label: "the formula" },
|
|
7018
|
+
{ id: "accuracy", label: "how accurate the model is" },
|
|
7019
|
+
{ id: "input_importance", label: "which inputs matter most" },
|
|
7020
|
+
{ id: "search", label: "how the search went" },
|
|
7021
|
+
{ id: "baselines", label: "the comparison with simple baselines" },
|
|
7022
|
+
{ id: "partial_dependence", label: "how each input moves the prediction" },
|
|
7023
|
+
{ id: "extrapolation", label: "behavior outside the observed range" },
|
|
7024
|
+
{ id: "what_if", label: "what-if scenarios and sensitivity" },
|
|
7025
|
+
{ id: "interactions", label: "interactions between inputs" },
|
|
7026
|
+
{ id: "term_ablation", label: "what each term of the formula adds" },
|
|
7027
|
+
{ id: "residuals", label: "errors and prediction intervals" },
|
|
7028
|
+
{ id: "temporal", label: "behavior over time" },
|
|
7029
|
+
{ id: "classification", label: "classification performance" },
|
|
7030
|
+
{ id: "rating_levels", label: "the rating levels" },
|
|
7031
|
+
{ id: "count_distribution", label: "the distribution of counts" },
|
|
7032
|
+
{ id: "segments", label: "differences between groups" },
|
|
7033
|
+
{ id: "fairness", label: "fairness across groups of people" },
|
|
7034
|
+
{ id: "out_of_distribution", label: "inputs unlike the training data" },
|
|
7035
|
+
{ id: "causality", label: "whether the relationships are causal" },
|
|
7036
|
+
{ id: "deployment", label: "whether the model is ready to use" },
|
|
7037
|
+
{ id: "multiple_targets", label: "how the targets relate to each other" },
|
|
7038
|
+
{ id: "columns", label: "what each column holds" },
|
|
7039
|
+
{ id: "correlations", label: "how the columns move together" },
|
|
7040
|
+
{ id: "leakage", label: "columns that give the answer away" },
|
|
7041
|
+
{ id: "duplicates", label: "duplicate rows" },
|
|
7042
|
+
{ id: "trends", label: "trends over time in the data" },
|
|
7043
|
+
{ id: "geography", label: "where the rows are located" }
|
|
7044
|
+
];
|
|
7045
|
+
function notesFromOptions(options) {
|
|
7046
|
+
if (options.intent !== void 0 && options.intentFile !== void 0) {
|
|
7047
|
+
usageError("Give the notes with --intent or with --intent-file, not both.");
|
|
7048
|
+
}
|
|
7049
|
+
let text2 = options.intent;
|
|
7050
|
+
if (options.intentFile !== void 0) {
|
|
7051
|
+
if (!fs9.existsSync(options.intentFile)) {
|
|
7052
|
+
throw new CliError(`File not found: ${options.intentFile}`, { exitCode: EXIT_USAGE });
|
|
7053
|
+
}
|
|
7054
|
+
text2 = fs9.readFileSync(options.intentFile, "utf8");
|
|
7055
|
+
}
|
|
7056
|
+
if (text2 === void 0) return void 0;
|
|
7057
|
+
checkNotesLength(text2);
|
|
7058
|
+
return text2.trim();
|
|
7059
|
+
}
|
|
7060
|
+
function checkNotesLength(text2) {
|
|
7061
|
+
if (text2.length > MAX_INTENT_LENGTH) {
|
|
7062
|
+
usageError(`The notes are ${text2.length.toLocaleString("en-US")} characters long; at most ${MAX_INTENT_LENGTH.toLocaleString("en-US")} are kept.`, "Shorten them and run it again.");
|
|
7063
|
+
}
|
|
7064
|
+
}
|
|
7065
|
+
function checkedStatement(statement) {
|
|
7066
|
+
const text2 = statement.trim();
|
|
7067
|
+
const refuse2 = (why) => usageError(
|
|
7068
|
+
`'${statement}' is not a shape expectation: ${why}.`,
|
|
7069
|
+
"Write one of increasing(input), decreasing(input, from, to), convex(input), concave(input) or range(lower, upper), with 'check:' (the default) or 'require:' in front."
|
|
7070
|
+
);
|
|
7071
|
+
if (text2.length === 0) refuse2("it is empty");
|
|
7072
|
+
if (/[;\n]/.test(text2)) refuse2("give one expectation per statement");
|
|
7073
|
+
let body = text2;
|
|
7074
|
+
const colon = text2.indexOf(":");
|
|
7075
|
+
const open = text2.indexOf("(");
|
|
7076
|
+
if (colon > 0 && (open < 0 || colon < open)) {
|
|
7077
|
+
const mode = text2.slice(0, colon).trim().toLowerCase();
|
|
7078
|
+
if (mode !== "check" && mode !== "require") refuse2(`the mode '${mode}' is neither check nor require`);
|
|
7079
|
+
body = text2.slice(colon + 1).trim();
|
|
7080
|
+
}
|
|
7081
|
+
const kindEnd = body.indexOf("(");
|
|
7082
|
+
if (kindEnd <= 0 || !body.endsWith(")")) refuse2("it has no kind(arguments) form");
|
|
7083
|
+
const kind = body.slice(0, kindEnd).trim().toLowerCase();
|
|
7084
|
+
if (!SHAPE_KINDS.includes(kind)) refuse2(`'${kind}' is not a kind of expectation`);
|
|
7085
|
+
return text2;
|
|
7086
|
+
}
|
|
7087
|
+
function parseShapeFlag(given) {
|
|
7088
|
+
const equals = given.lastIndexOf("=");
|
|
7089
|
+
if (equals <= 0) {
|
|
7090
|
+
usageError(`'${given}' names no target.`, "Write --shape <target>=<statement>, for example --shape 'price=increasing(size_m2)'.");
|
|
7091
|
+
}
|
|
7092
|
+
const target = given.slice(0, equals).trim();
|
|
7093
|
+
if (target.length === 0) usageError(`'${given}' names no target.`);
|
|
7094
|
+
return { target, statement: checkedStatement(given.slice(equals + 1)) };
|
|
7095
|
+
}
|
|
7096
|
+
function shapesOf(given) {
|
|
7097
|
+
if (given === void 0 || given.length === 0) return null;
|
|
7098
|
+
const byTarget = {};
|
|
7099
|
+
for (const flag of given) {
|
|
7100
|
+
const { target, statement } = parseShapeFlag(flag);
|
|
7101
|
+
byTarget[target] ??= [];
|
|
7102
|
+
if (!byTarget[target].includes(statement)) byTarget[target].push(statement);
|
|
7103
|
+
}
|
|
7104
|
+
return byTarget;
|
|
7105
|
+
}
|
|
7106
|
+
function resolveShapeTargets(byTarget, columns, analysisId) {
|
|
7107
|
+
const resolved = {};
|
|
7108
|
+
for (const [target, statements] of Object.entries(byTarget)) {
|
|
7109
|
+
const column = resolveColumnArgument(target, columns, analysisId);
|
|
7110
|
+
resolved[column] = [...resolved[column] ?? [], ...statements.filter((s) => !(resolved[column] ?? []).includes(s))];
|
|
7111
|
+
}
|
|
7112
|
+
return resolved;
|
|
7113
|
+
}
|
|
7114
|
+
function boundText(text2) {
|
|
7115
|
+
const trimmed = text2.trim();
|
|
7116
|
+
const n = Number(trimmed);
|
|
7117
|
+
return Number.isFinite(n) ? n.toLocaleString("en-US", { maximumFractionDigits: 6 }) : trimmed;
|
|
7118
|
+
}
|
|
7119
|
+
function isOpen(text2) {
|
|
7120
|
+
if (text2 === void 0) return true;
|
|
7121
|
+
const t = text2.trim().toLowerCase();
|
|
7122
|
+
return t === "" || t === "inf" || t === "+inf" || t === "-inf" || t === "infinity" || t === "-infinity";
|
|
7123
|
+
}
|
|
7124
|
+
function expectationText(target, statement) {
|
|
7125
|
+
const read = /^\s*(?:(check|require)\s*:)?\s*([a-z]+)\s*\((.*)\)\s*$/i.exec(statement);
|
|
7126
|
+
if (!read) return `${target}: ${statement}`;
|
|
7127
|
+
const steer = (read[1] ?? "check").toLowerCase() === "require";
|
|
7128
|
+
const kind = read[2].toLowerCase();
|
|
7129
|
+
const args = read[3].split(",").map((a) => a.trim());
|
|
7130
|
+
const mode = steer ? "Steers the model" : "Checked";
|
|
7131
|
+
if (kind === "range") {
|
|
7132
|
+
const [lower, upper] = args;
|
|
7133
|
+
const sentence = !isOpen(lower) && !isOpen(upper) ? `${target} stays between ${boundText(lower)} and ${boundText(upper)}` : !isOpen(lower) ? `${target} is never below ${boundText(lower)}` : !isOpen(upper) ? `${target} is never above ${boundText(upper)}` : `${target} has no bound`;
|
|
7134
|
+
return `${sentence}. ${mode}.`;
|
|
7135
|
+
}
|
|
7136
|
+
const input = args[0];
|
|
7137
|
+
const shape = kind === "increasing" ? `does not fall as ${input} grows` : kind === "decreasing" ? `does not rise as ${input} grows` : kind === "convex" ? `curves upward as ${input} grows` : kind === "concave" ? `levels off as ${input} grows` : null;
|
|
7138
|
+
if (!shape) return `${target}: ${statement}`;
|
|
7139
|
+
const window = args.length === 3 && !(isOpen(args[1]) && isOpen(args[2])) ? ` (${input} ${boundText(args[1])} to ${boundText(args[2])})` : args.length === 1 ? ` (across the observed ${input} values)` : "";
|
|
7140
|
+
return `${target} ${shape}${window}. ${mode}.`;
|
|
7141
|
+
}
|
|
7142
|
+
function expectationLines(byTarget) {
|
|
7143
|
+
if (!byTarget) return [];
|
|
7144
|
+
return Object.entries(byTarget).flatMap(([target, statements]) => statements.map((s) => expectationText(target, s)));
|
|
7145
|
+
}
|
|
7146
|
+
function parsePair(given) {
|
|
7147
|
+
const entries = parseColumnList(given);
|
|
7148
|
+
const usage = `Write <first>,<second> or <first>,<second>,<kind> with kind one of ${CHART_KINDS.join(", ")}; a column whose name holds a comma goes in double quotes: '"a, b",price'.`;
|
|
7149
|
+
if (entries.length < 2 || entries.length > 3) {
|
|
7150
|
+
usageError(`'${given}' is not a chart: it names ${entries.length} ${entries.length === 1 ? "entry" : "entries"}.`, usage);
|
|
7151
|
+
}
|
|
7152
|
+
let kind = null;
|
|
7153
|
+
if (entries.length === 3) {
|
|
7154
|
+
const typed2 = entries[2].trim().toLowerCase();
|
|
7155
|
+
if (!CHART_KINDS.includes(typed2)) {
|
|
7156
|
+
usageError(`'${entries[2]}' is not a chart kind.`, usage);
|
|
7157
|
+
}
|
|
7158
|
+
kind = typed2;
|
|
7159
|
+
}
|
|
7160
|
+
if (entries[0] === entries[1]) usageError(`'${given}' names the same column twice; a chart needs two different columns.`);
|
|
7161
|
+
return { first: entries[0], second: entries[1], kind };
|
|
7162
|
+
}
|
|
7163
|
+
function pairsOf(given) {
|
|
7164
|
+
if (given === void 0) return null;
|
|
7165
|
+
const pairs = [];
|
|
7166
|
+
for (const entry of given) {
|
|
7167
|
+
if (entry.trim().length === 0) continue;
|
|
7168
|
+
const pair = parsePair(entry);
|
|
7169
|
+
if (!pairs.some((p) => p.first === pair.first && p.second === pair.second && p.kind === pair.kind)) pairs.push(pair);
|
|
7170
|
+
}
|
|
7171
|
+
if (pairs.length > MAX_PAIRS) usageError(`${pairs.length} charts are asked for; at most ${MAX_PAIRS} can be.`);
|
|
7172
|
+
return pairs;
|
|
7173
|
+
}
|
|
7174
|
+
function resolvePairs(pairs, columns, analysisId) {
|
|
7175
|
+
return pairs.map((pair) => {
|
|
7176
|
+
const [first, second] = resolveColumnNames([pair.first, pair.second], columns, analysisId);
|
|
7177
|
+
if (second === void 0) {
|
|
7178
|
+
usageError(`${quoteColumn(pair.first)} and ${quoteColumn(pair.second)} are the same column; a chart needs two different columns.`);
|
|
7179
|
+
}
|
|
7180
|
+
return { first, second, kind: pair.kind };
|
|
7181
|
+
});
|
|
7182
|
+
}
|
|
7183
|
+
function pairText(pair) {
|
|
7184
|
+
const how = pair.kind === "scatter" ? " as a scatter plot" : pair.kind === "groups" ? " by group" : pair.kind === "counts" ? " as counts" : "";
|
|
7185
|
+
return `${pair.second} against ${pair.first}${how}`;
|
|
7186
|
+
}
|
|
7187
|
+
function familyId(typed2) {
|
|
7188
|
+
return typed2.trim().toLowerCase().replace(/[- ]/g, "_");
|
|
7189
|
+
}
|
|
7190
|
+
function focusOf(given) {
|
|
7191
|
+
if (given === void 0) return null;
|
|
7192
|
+
const families = [];
|
|
7193
|
+
const unknown = [];
|
|
7194
|
+
for (const typed2 of given.flatMap((g) => g.split(","))) {
|
|
7195
|
+
if (typed2.trim().length === 0) continue;
|
|
7196
|
+
const id = familyId(typed2);
|
|
7197
|
+
if (!FOCUS_FAMILIES.some((f) => f.id === id)) unknown.push(typed2.trim());
|
|
7198
|
+
else if (!families.includes(id)) families.push(id);
|
|
7199
|
+
}
|
|
7200
|
+
if (unknown.length > 0) {
|
|
7201
|
+
usageError(
|
|
7202
|
+
`${unknown.map((u) => `'${u}'`).join(", ")} ${unknown.length === 1 ? "is not a question family" : "are not question families"}.`,
|
|
7203
|
+
`The families are: ${FOCUS_FAMILIES.map((f) => f.id).join(", ")}.`
|
|
7204
|
+
);
|
|
7205
|
+
}
|
|
7206
|
+
if (families.length > MAX_FOCUS) {
|
|
7207
|
+
usageError(`${families.length} families are named; at most ${MAX_FOCUS} can be in focus.`, "Name the ones that matter most.");
|
|
7208
|
+
}
|
|
7209
|
+
return families;
|
|
7210
|
+
}
|
|
7211
|
+
function focusText(id) {
|
|
7212
|
+
return FOCUS_FAMILIES.find((f) => f.id === id)?.label ?? id;
|
|
7213
|
+
}
|
|
7214
|
+
function intentRecipeLines(analysis) {
|
|
7215
|
+
const lines = [];
|
|
7216
|
+
const statements = Object.values(analysis.shapeExpectations ?? {}).flat();
|
|
7217
|
+
if (statements.length > 0) {
|
|
7218
|
+
const steering = statements.filter((s) => /^\s*require\s*:/i.test(s)).length;
|
|
7219
|
+
const checked = statements.length - steering;
|
|
7220
|
+
const parts = [checked > 0 ? `${checked} checked` : null, steering > 0 ? `${steering} ${steering === 1 ? "steers" : "steer"} the model` : null].filter(Boolean);
|
|
7221
|
+
lines.push(`Expectations: ${parts.join(", ")}`);
|
|
7222
|
+
}
|
|
7223
|
+
const pairs = analysis.requestedPairs ?? [];
|
|
7224
|
+
if (pairs.length > 0) lines.push(`Charts: ${pairs.map(pairText).join("; ")}`);
|
|
7225
|
+
const focus = analysis.focusFamilies ?? [];
|
|
7226
|
+
if (focus.length > 0) lines.push(`Focus: ${focus.map(focusText).join(", ")}`);
|
|
7227
|
+
return lines;
|
|
7228
|
+
}
|
|
7229
|
+
function interpretRequestOf(analysis, intent) {
|
|
7230
|
+
return {
|
|
7231
|
+
intent,
|
|
7232
|
+
targets: analysis.targets ?? [],
|
|
7233
|
+
segment: analysis.segment ?? null,
|
|
7234
|
+
inputExclusions: analysis.inputExclusions ?? [],
|
|
7235
|
+
targetKinds: analysis.targetKinds ?? {}
|
|
7236
|
+
};
|
|
7237
|
+
}
|
|
7238
|
+
var PROFILE_ATTEMPTS = 10;
|
|
7239
|
+
var PROFILE_INTERVAL_MS = 2e3;
|
|
7240
|
+
function waitingForProfile(interpretation) {
|
|
7241
|
+
return interpretation.status === "UNAVAILABLE" && (interpretation.findings ?? []).some((f) => /profiled/i.test(f.text ?? ""));
|
|
7242
|
+
}
|
|
7243
|
+
function isProfilePending(error) {
|
|
7244
|
+
return error instanceof ApiError && error.status === 400 && /profiled/i.test(error.message);
|
|
7245
|
+
}
|
|
7246
|
+
var pause2 = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
7247
|
+
async function readNotes(api, analysisId, request, options = {}) {
|
|
7248
|
+
let interpretation = await api.analysis.interpretIntent(analysisId, request, options);
|
|
7249
|
+
for (let attempt = 1; attempt < PROFILE_ATTEMPTS && waitingForProfile(interpretation); attempt++) {
|
|
7250
|
+
await pause2(PROFILE_INTERVAL_MS);
|
|
7251
|
+
interpretation = await api.analysis.interpretIntent(analysisId, request, options);
|
|
7252
|
+
}
|
|
7253
|
+
return interpretation;
|
|
7254
|
+
}
|
|
7255
|
+
async function whenProfiled(save) {
|
|
7256
|
+
for (let attempt = 1; ; attempt++) {
|
|
7257
|
+
try {
|
|
7258
|
+
return await save();
|
|
7259
|
+
} catch (error) {
|
|
7260
|
+
if (attempt >= PROFILE_ATTEMPTS || !isProfilePending(error)) throw error;
|
|
7261
|
+
await pause2(PROFILE_INTERVAL_MS);
|
|
7262
|
+
}
|
|
7263
|
+
}
|
|
7264
|
+
}
|
|
7265
|
+
function effectLabel(item) {
|
|
7266
|
+
switch (item.effect) {
|
|
7267
|
+
case "checks":
|
|
7268
|
+
return item.steer ? "Steers the model" : "Checks the model";
|
|
7269
|
+
case "changes":
|
|
7270
|
+
return "Changes what is analyzed";
|
|
7271
|
+
case "presents":
|
|
7272
|
+
return item.kind === "pair" ? "Adds a chart" : item.kind === "question" ? "Adds a question" : item.kind === "focus" ? "Sets the focus" : "Changes what the report shows";
|
|
7273
|
+
case "note":
|
|
7274
|
+
return "A note only";
|
|
7275
|
+
case "unavailable":
|
|
7276
|
+
return "Not possible on this run";
|
|
7277
|
+
default:
|
|
7278
|
+
return item.effect;
|
|
7279
|
+
}
|
|
7280
|
+
}
|
|
7281
|
+
function stateLabel(state) {
|
|
7282
|
+
return state === "CONFIRMED" ? "Used" : state === "DECLINED" ? "Not used" : "Proposed";
|
|
7283
|
+
}
|
|
7284
|
+
function groupOf(item) {
|
|
7285
|
+
if (item.effect === "checks" || item.effect === "changes") return 0;
|
|
7286
|
+
if (item.effect === "presents") return 1;
|
|
7287
|
+
if (item.effect === "note") return 2;
|
|
7288
|
+
return 3;
|
|
7289
|
+
}
|
|
7290
|
+
var GROUP_HEADINGS = [
|
|
7291
|
+
"About the model and the data",
|
|
7292
|
+
"What the report shows",
|
|
7293
|
+
"Notes for the report",
|
|
7294
|
+
"Not possible on this run"
|
|
7295
|
+
];
|
|
7296
|
+
function orderedItems(items) {
|
|
7297
|
+
return [...items].sort((a, b) => groupOf(a) - groupOf(b));
|
|
7298
|
+
}
|
|
7299
|
+
function printInterpretation(interpretation, analysisId) {
|
|
7300
|
+
const items = orderedItems(interpretation.items ?? []);
|
|
7301
|
+
if (interpretation.status === "EMPTY") {
|
|
7302
|
+
console.log(chalk19.dim("No notes to read."));
|
|
7303
|
+
hint(`Write them with 'diafunc analyze intent ${analysisId} "<text>"'.`);
|
|
7304
|
+
return;
|
|
7305
|
+
}
|
|
7306
|
+
if (interpretation.status === "UNAVAILABLE") {
|
|
7307
|
+
for (const finding of interpretation.findings ?? []) warn(finding.text);
|
|
7308
|
+
if ((interpretation.findings ?? []).length === 0) warn("Your notes could not be read just now. Nothing was changed.");
|
|
7309
|
+
return;
|
|
7310
|
+
}
|
|
7311
|
+
if (items.length === 0) console.log(chalk19.dim("Nothing in the notes could be turned into a proposal."));
|
|
7312
|
+
let group = -1;
|
|
7313
|
+
for (const item of items) {
|
|
7314
|
+
if (groupOf(item) !== group) {
|
|
7315
|
+
group = groupOf(item);
|
|
7316
|
+
heading(GROUP_HEADINGS[group]);
|
|
7317
|
+
}
|
|
7318
|
+
console.log(` ${chalk19.cyan(item.id)} ${stateLabel(item.state)} \xB7 ${effectLabel(item)}`);
|
|
7319
|
+
console.log(` ${item.statement}`);
|
|
7320
|
+
if (item.quote) detail(` from: "${item.quote}"`);
|
|
7321
|
+
}
|
|
7322
|
+
const notUnderstood = interpretation.notUnderstood ?? [];
|
|
7323
|
+
if (notUnderstood.length > 0) {
|
|
7324
|
+
heading("Not understood");
|
|
7325
|
+
for (const note of notUnderstood) console.log(` "${note.quote}"${note.reason ? `: ${note.reason}` : ""}`);
|
|
7326
|
+
}
|
|
7327
|
+
const rejections = interpretation.rejections ?? [];
|
|
7328
|
+
if (rejections.length > 0) {
|
|
7329
|
+
heading("Not used");
|
|
7330
|
+
for (const note of rejections) console.log(` "${note.quote}"${note.reason ? `: ${note.reason}` : ""}`);
|
|
7331
|
+
}
|
|
7332
|
+
const findings = interpretation.findings ?? [];
|
|
7333
|
+
if (findings.length > 0) {
|
|
7334
|
+
heading("Before you launch");
|
|
7335
|
+
for (const finding of findings) console.log(` ${finding.title ? `${finding.title}: ` : ""}${finding.text}`);
|
|
7336
|
+
}
|
|
7337
|
+
if (items.some((item) => item.state === "PROPOSED" && item.effect !== "unavailable")) {
|
|
7338
|
+
console.log();
|
|
7339
|
+
hint("Nothing changes until you confirm a proposal. Expectations are checked; add --steer to let one steer the model.");
|
|
7340
|
+
hint(`Use one with 'diafunc analyze intent confirm ${analysisId} <proposalId...>', or 'decline' it.`);
|
|
7341
|
+
}
|
|
7342
|
+
}
|
|
7343
|
+
async function promptIntentDecisions(prompter, interpretation) {
|
|
7344
|
+
const decisions = [];
|
|
7345
|
+
for (const item of orderedItems(interpretation.items ?? [])) {
|
|
7346
|
+
if (item.state !== "PROPOSED" || item.effect === "unavailable") continue;
|
|
7347
|
+
if (item.quote) detail(`from your notes: "${item.quote}"`);
|
|
7348
|
+
const use = await prompter.confirm({
|
|
7349
|
+
message: `${item.statement} (${effectLabel(item)}) Use it?`,
|
|
7350
|
+
default: item.effect === "presents"
|
|
7351
|
+
});
|
|
7352
|
+
if (!use) {
|
|
7353
|
+
decisions.push({ id: item.id, state: "DECLINED", steer: null });
|
|
7354
|
+
continue;
|
|
7355
|
+
}
|
|
7356
|
+
const steer = item.effect === "checks" ? await prompter.confirm({
|
|
7357
|
+
message: "Also use it to steer the model? Without steering it is checked and reported, and never decides which model is delivered.",
|
|
7358
|
+
default: false
|
|
7359
|
+
}) : null;
|
|
7360
|
+
decisions.push({ id: item.id, state: "CONFIRMED", steer });
|
|
7361
|
+
}
|
|
7362
|
+
return decisions;
|
|
7363
|
+
}
|
|
7364
|
+
function printUnavailable(interpretation) {
|
|
7365
|
+
for (const item of interpretation.items ?? []) {
|
|
7366
|
+
if (item.effect === "unavailable") warn(item.statement);
|
|
7367
|
+
}
|
|
7368
|
+
}
|
|
7369
|
+
|
|
7370
|
+
// src/commands/analyze/report.ts
|
|
7371
|
+
var EXPORT_LANGUAGES = [
|
|
7372
|
+
"formula",
|
|
7373
|
+
"python",
|
|
7374
|
+
"r",
|
|
7375
|
+
"sql",
|
|
7376
|
+
"javascript",
|
|
7377
|
+
"java",
|
|
7378
|
+
"kotlin",
|
|
7379
|
+
"c",
|
|
7380
|
+
"latex"
|
|
7381
|
+
];
|
|
7382
|
+
function writeText(text2) {
|
|
7383
|
+
if (text2.length === 0) return;
|
|
7384
|
+
process.stdout.write(text2);
|
|
7385
|
+
if (!text2.endsWith("\n")) process.stdout.write("\n");
|
|
7386
|
+
}
|
|
7387
|
+
function parseMaxBytes(given) {
|
|
7388
|
+
if (given === void 0) return void 0;
|
|
7389
|
+
const trimmed = given.trim();
|
|
7390
|
+
if (!/^\d+$/.test(trimmed) || Number(trimmed) <= 0) {
|
|
7391
|
+
usageError(
|
|
7392
|
+
`--max-bytes must be a whole number of bytes, not "${given}".`,
|
|
7393
|
+
"The platform reads between 4096 and 262144; without the flag it reads 32768."
|
|
7394
|
+
);
|
|
7395
|
+
}
|
|
7396
|
+
return Number(trimmed);
|
|
7397
|
+
}
|
|
7398
|
+
function parsePart(given, chapter) {
|
|
7399
|
+
if (given === void 0) return void 0;
|
|
7400
|
+
const trimmed = given.trim();
|
|
7401
|
+
if (!/^\d+$/.test(trimmed) || Number(trimmed) < 1) {
|
|
7402
|
+
usageError(`--part must be a whole number from 1, not "${given}".`);
|
|
7403
|
+
}
|
|
7404
|
+
if (chapter === void 0) {
|
|
7405
|
+
usageError(
|
|
7406
|
+
"--part reads one part of a chapter, so it needs --chapter.",
|
|
7407
|
+
"Without --chapter the command prints the summary, which does not come in parts."
|
|
7408
|
+
);
|
|
7409
|
+
}
|
|
7410
|
+
return Number(trimmed);
|
|
7411
|
+
}
|
|
7412
|
+
function parseExportLanguage(given) {
|
|
7413
|
+
const language = given.trim().toLowerCase();
|
|
7414
|
+
if (!EXPORT_LANGUAGES.includes(language)) {
|
|
7415
|
+
usageError(
|
|
7416
|
+
`"${given}" is not a language a model can be exported in.`,
|
|
7417
|
+
`Choose one of: ${EXPORT_LANGUAGES.join(", ")}.`
|
|
7418
|
+
);
|
|
7419
|
+
}
|
|
7420
|
+
return language;
|
|
7421
|
+
}
|
|
7422
|
+
async function printReport(analysisId, options) {
|
|
7423
|
+
const maxBytes = parseMaxBytes(options.maxBytes);
|
|
7424
|
+
const chapter = options.chapter?.trim() || void 0;
|
|
7425
|
+
const part = parsePart(options.part, chapter);
|
|
7426
|
+
const api = createApiClient();
|
|
7427
|
+
const markdown = await api.analysis.getReportMarkdown(analysisId, { chapter, part, maxBytes });
|
|
7428
|
+
writeText(markdown);
|
|
7429
|
+
}
|
|
7430
|
+
async function printModelExport(analysisId, options) {
|
|
7431
|
+
const language = parseExportLanguage(options.language);
|
|
7432
|
+
const target = options.target?.trim() || void 0;
|
|
7433
|
+
const api = createApiClient();
|
|
7434
|
+
const source = await api.analysis.exportModel(analysisId, { language, target });
|
|
7435
|
+
writeText(source);
|
|
7436
|
+
}
|
|
7437
|
+
var REPORT_HELP = `
|
|
7438
|
+
Without --chapter it prints the summary of the report and the titles of its chapters. Name a
|
|
7439
|
+
chapter to read it whole with the chapters below it. A title several chapters share is narrowed
|
|
7440
|
+
by naming chapters above it, separated by ">":
|
|
7441
|
+
|
|
7442
|
+
$ diafunc analyze report <id>
|
|
7443
|
+
$ diafunc analyze report <id> --chapter "Age > Correlation"
|
|
7444
|
+
$ diafunc analyze report <id> --max-bytes 131072 > report.md
|
|
7445
|
+
|
|
7446
|
+
A chapter larger than --max-bytes comes in parts. Each part ends with a line naming the next;
|
|
7447
|
+
read it with --part:
|
|
7448
|
+
|
|
7449
|
+
$ diafunc analyze report <id> --chapter Data --part 2
|
|
7450
|
+
|
|
7451
|
+
A title no chapter carries prints a sentence saying so, followed by the titles there are.
|
|
7452
|
+
Figures are not drawn; the numbers behind them are in the chapter's tables and values.
|
|
7453
|
+
`;
|
|
7454
|
+
var EXPORT_MODEL_HELP = `
|
|
7455
|
+
Prints the model the analysis found for one target, as a formula or as source code. With
|
|
7456
|
+
several targets, name one with --target. Public analyses can be exported too.
|
|
7457
|
+
|
|
7458
|
+
$ diafunc analyze export-model <id> --language formula
|
|
7459
|
+
$ diafunc analyze export-model <id> --language python --target price > model.py
|
|
7460
|
+
`;
|
|
7461
|
+
|
|
7462
|
+
// src/prompting/resolvers.ts
|
|
7463
|
+
var PROJECT_ROLES = ["OWNER", "ADMIN", "DEVELOPER", "GUEST"];
|
|
7464
|
+
var TRIGGER_TYPES = ["CRON", "INTERVAL", "CONTINUOUS", "EVENT"];
|
|
7465
|
+
var ANALYSIS_TRIGGER_KINDS = ["ONCE", "CRON"];
|
|
7466
|
+
var VISIBILITIES = ["PRIVATE", "PUBLIC"];
|
|
7467
|
+
var SHELLS = ["bash", "zsh", "fish"];
|
|
7468
|
+
var CONFIG_KEYS = ["defaults.project", "defaults.branch", "defaults.output"];
|
|
7469
|
+
var ENTITY_TYPE_BY_GROUP = {
|
|
7470
|
+
table: "table",
|
|
7471
|
+
function: "function",
|
|
7472
|
+
trigger: "function",
|
|
7473
|
+
schedule: "function"
|
|
7474
|
+
};
|
|
7475
|
+
var TEXT = { kind: "text" };
|
|
7476
|
+
var TEXT_OR_EMPTY = { kind: "text", allowEmpty: true };
|
|
7477
|
+
var POSITIVE = { kind: "number", min: 0, integer: false, exclusive: true };
|
|
7478
|
+
var INDEX = { kind: "number", min: 0, integer: true };
|
|
7479
|
+
var BY_COMMAND = {
|
|
7480
|
+
"analyze segment": { "<name>": { kind: "analysisColumns", multiple: false, allowEmpty: true } },
|
|
7481
|
+
"analyze targets": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: false } },
|
|
7482
|
+
"analyze input-exclusions": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: true } },
|
|
7483
|
+
"analyze confirmed-inputs": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: true } },
|
|
7484
|
+
"analyze questions": { "<question>": TEXT_OR_EMPTY },
|
|
7485
|
+
"analyze description": { "<text>": TEXT_OR_EMPTY },
|
|
7486
|
+
"analyze introduction": { "<markdown>": TEXT_OR_EMPTY },
|
|
7487
|
+
"analyze intent confirm": { "<proposalId>": TEXT },
|
|
7488
|
+
"analyze intent decline": { "<proposalId>": TEXT },
|
|
7489
|
+
"analyze intent reset": { "<proposalId>": TEXT },
|
|
7490
|
+
"analyze charts": { "<pair>": TEXT_OR_EMPTY },
|
|
7491
|
+
"analyze focus": { "<family>": { kind: "choices", choices: FOCUS_FAMILIES.map((f) => f.id) } },
|
|
7492
|
+
// Not the analysis picker: that one offers the reader's own analyses, and this command needs no account.
|
|
7493
|
+
"public show": { "<analysisId>": TEXT },
|
|
7494
|
+
"analyze export-model": { "--language": { kind: "choice", choices: EXPORT_LANGUAGES } },
|
|
7495
|
+
"analyze presets save": { "--targets": TEXT, "--hours": POSITIVE, "--budget": POSITIVE },
|
|
7496
|
+
"branch merge": {
|
|
7497
|
+
"--source": { kind: "entity", form: "ref" },
|
|
7498
|
+
"--target": { kind: "project", withBranch: true }
|
|
7499
|
+
},
|
|
7500
|
+
"branch create": { "<branchName>": TEXT },
|
|
7501
|
+
"branch delete": { "<branchName>": { kind: "projectBranch", projectFrom: "projectId" } },
|
|
7502
|
+
"admin backup restore-project": { "<projectBranch>": { kind: "projectBranch", projectFrom: "projectId" } },
|
|
7503
|
+
"data-sources create": {
|
|
7504
|
+
"--project-id": { kind: "project", withBranch: false },
|
|
7505
|
+
"--project-branch": { kind: "projectBranch", projectFrom: "projectId" },
|
|
7506
|
+
"--target-entity-id": { kind: "entity", form: "id", contentType: "table", projectFrom: "projectId" },
|
|
7507
|
+
"--target-entity-branch": { kind: "text", defaultValue: "main" },
|
|
7508
|
+
"--type": { kind: "connectorType" }
|
|
7509
|
+
},
|
|
7510
|
+
"table-exporters create": {
|
|
7511
|
+
"--function-project": { kind: "project", withBranch: false },
|
|
7512
|
+
"--function-entity": { kind: "entity", form: "id", contentType: "function", projectFrom: "functionProject" },
|
|
7513
|
+
"--format": TEXT
|
|
7514
|
+
},
|
|
7515
|
+
"table exports get": { "--ref": { kind: "entity", form: "ref", contentType: "table" } },
|
|
7516
|
+
"table export": { "<format>": { kind: "exportFormat" } },
|
|
7517
|
+
"entity export": { "<entityIds>": { kind: "entity", form: "id", projectFrom: "project", multiple: true } },
|
|
7518
|
+
"notebook export": {
|
|
7519
|
+
"<notebookIds>": { kind: "entity", form: "id", contentType: "notebook", projectFrom: "project", multiple: true }
|
|
7520
|
+
},
|
|
7521
|
+
"entity tags set": { "<tags>": TEXT_OR_EMPTY },
|
|
7522
|
+
"project tags set": { "<tags>": TEXT_OR_EMPTY },
|
|
7523
|
+
"admin curated-tags create": { "--display-name": TEXT },
|
|
7524
|
+
"link delete": { "<linkId>": { kind: "link" } },
|
|
7525
|
+
"link create": { "<linkId>": TEXT },
|
|
7526
|
+
"config profile use": { "<name>": { kind: "profile" } },
|
|
7527
|
+
"config profile remove": { "<name>": { kind: "profile" } },
|
|
7528
|
+
"config get": { "<key>": { kind: "choice", choices: CONFIG_KEYS } },
|
|
7529
|
+
"config set": { "<key>": { kind: "choice", choices: CONFIG_KEYS } },
|
|
7530
|
+
"project members invite": { "<userId>": TEXT, "<role>": { kind: "choice", choices: PROJECT_ROLES } },
|
|
7531
|
+
"project members join": { "<userId>": TEXT },
|
|
7532
|
+
"trigger create": { "--type": { kind: "choice", choices: TRIGGER_TYPES } },
|
|
7533
|
+
"analyze triggers create": { "--kind": { kind: "choice", choices: ANALYSIS_TRIGGER_KINDS } },
|
|
7534
|
+
"function outputs": { "<evaluationId>": TEXT },
|
|
7535
|
+
"team create": { "--seats": { kind: "number", min: 1, integer: true } },
|
|
7536
|
+
"team seats preview": { "<count>": { kind: "number", min: 1, integer: true } },
|
|
7537
|
+
"team seats set": { "<count>": { kind: "number", min: 1, integer: true } }
|
|
7538
|
+
};
|
|
7539
|
+
var BY_NAME = {
|
|
7540
|
+
projectId: { kind: "project", withBranch: false },
|
|
7541
|
+
projectRef: { kind: "project", withBranch: true },
|
|
7542
|
+
project: { kind: "project", withBranch: true },
|
|
7543
|
+
teamId: { kind: "team" },
|
|
7544
|
+
invitationId: { kind: "teamInvitation" },
|
|
7545
|
+
analysisId: { kind: "analysis" },
|
|
7546
|
+
licenseId: { kind: "license" },
|
|
7547
|
+
sessionId: { kind: "chatSession" },
|
|
7548
|
+
tokenId: { kind: "apiToken" },
|
|
7549
|
+
resource: { kind: "tokenResource" },
|
|
7550
|
+
scopes: { kind: "choices", choices: VALID_SCOPES },
|
|
7551
|
+
evaluationId: { kind: "evaluation" },
|
|
7552
|
+
eventId: { kind: "event" },
|
|
7553
|
+
occurrenceId: { kind: "occurrence" },
|
|
7554
|
+
exportId: { kind: "tableExport" },
|
|
7555
|
+
invoiceNumber: { kind: "invoice" },
|
|
7556
|
+
fileName: { kind: "invoiceDocument" },
|
|
7557
|
+
shell: { kind: "choice", choices: SHELLS },
|
|
7558
|
+
vis: { kind: "choice", choices: VISIBILITIES },
|
|
7559
|
+
kind: { kind: "choice", choices: ANALYSIS_TRIGGER_KINDS },
|
|
7560
|
+
date: { kind: "date" },
|
|
7561
|
+
file: { kind: "file" },
|
|
7562
|
+
email: { kind: "text", email: true },
|
|
7563
|
+
index: INDEX,
|
|
7564
|
+
row: INDEX,
|
|
7565
|
+
col: INDEX,
|
|
7566
|
+
count: INDEX,
|
|
7567
|
+
version: { kind: "number", min: 1, integer: true },
|
|
7568
|
+
hours: POSITIVE,
|
|
7569
|
+
credits: POSITIVE,
|
|
7570
|
+
seats: { kind: "number", min: 1, integer: true },
|
|
7571
|
+
value: TEXT_OR_EMPTY,
|
|
7572
|
+
// Free text: names, messages and ids the reader is creating rather than choosing.
|
|
7573
|
+
name: TEXT,
|
|
7574
|
+
tag: TEXT,
|
|
7575
|
+
tags: TEXT,
|
|
7576
|
+
newId: TEXT,
|
|
7577
|
+
message: TEXT,
|
|
7578
|
+
query: TEXT,
|
|
7579
|
+
title: TEXT,
|
|
7580
|
+
token: TEXT,
|
|
7581
|
+
subscriptionToken: TEXT,
|
|
7582
|
+
forkProjectId: TEXT,
|
|
7583
|
+
targetBranch: TEXT,
|
|
7584
|
+
bucketName: TEXT,
|
|
7585
|
+
objectName: TEXT,
|
|
7586
|
+
template: TEXT,
|
|
7587
|
+
plan: TEXT,
|
|
7588
|
+
schedule: TEXT,
|
|
7589
|
+
consumerType: TEXT,
|
|
7590
|
+
consumerId: TEXT,
|
|
7591
|
+
format: TEXT,
|
|
7592
|
+
key: TEXT
|
|
7593
|
+
};
|
|
7594
|
+
function tokenOf(input) {
|
|
7595
|
+
return input.kind === "option" ? input.flag ?? `--${input.name}` : `<${input.name}>`;
|
|
7596
|
+
}
|
|
7597
|
+
function specFor(path13, input) {
|
|
7598
|
+
const exact = BY_COMMAND[path13]?.[tokenOf(input)];
|
|
7599
|
+
if (exact) return exact;
|
|
7600
|
+
const group = path13.split(" ")[0];
|
|
7601
|
+
const sub = path13.split(" ").slice(0, 2).join(" ");
|
|
7602
|
+
switch (input.name) {
|
|
7603
|
+
case "ref":
|
|
7604
|
+
case "sourceRef":
|
|
7605
|
+
case "targetRef":
|
|
7606
|
+
return { kind: "entity", form: "ref", contentType: ENTITY_TYPE_BY_GROUP[group] };
|
|
7607
|
+
case "userId":
|
|
7608
|
+
return group === "team" ? { kind: "teamMember" } : { kind: "projectMember" };
|
|
7609
|
+
case "id":
|
|
7610
|
+
if (sub === "analyze presets") return { kind: "preset" };
|
|
7611
|
+
if (group === "analyze") return { kind: "analysis" };
|
|
7612
|
+
if (group === "data-sources") return { kind: "dataSource" };
|
|
7613
|
+
if (group === "skeleton") return { kind: "skeleton" };
|
|
7614
|
+
if (group === "table-exporters") return { kind: "tableExporter" };
|
|
7615
|
+
if (group === "status") return { kind: "statusComponent" };
|
|
7616
|
+
return null;
|
|
7617
|
+
case "runId":
|
|
7618
|
+
if (group === "analyze") return { kind: "analysisRun" };
|
|
7619
|
+
if (group === "data-sources") return { kind: "dataSourceRun" };
|
|
7620
|
+
return null;
|
|
7621
|
+
case "triggerId":
|
|
7622
|
+
if (group === "analyze") return { kind: "analysisTrigger" };
|
|
7623
|
+
if (group === "trigger") return { kind: "functionTrigger" };
|
|
7624
|
+
return null;
|
|
7625
|
+
case "role":
|
|
7626
|
+
return { kind: "choice", choices: PROJECT_ROLES };
|
|
7627
|
+
case "type":
|
|
7628
|
+
return null;
|
|
7629
|
+
default:
|
|
7630
|
+
return BY_NAME[input.name] ?? null;
|
|
7631
|
+
}
|
|
7632
|
+
}
|
|
7633
|
+
function dependencies(spec) {
|
|
7634
|
+
switch (spec.kind) {
|
|
7635
|
+
case "teamMember":
|
|
7636
|
+
case "teamInvitation":
|
|
7637
|
+
return ["teamId"];
|
|
7638
|
+
case "projectMember":
|
|
7639
|
+
return ["projectId"];
|
|
7640
|
+
case "analysisColumns":
|
|
7641
|
+
return ["id"];
|
|
7642
|
+
case "evaluation":
|
|
7643
|
+
return ["ref", "date"];
|
|
7644
|
+
case "functionTrigger":
|
|
7645
|
+
case "event":
|
|
7646
|
+
case "tableExport":
|
|
7647
|
+
return ["ref"];
|
|
7648
|
+
case "occurrence":
|
|
7649
|
+
return ["ref", "eventId"];
|
|
7650
|
+
case "link":
|
|
7651
|
+
return ["sourceRef"];
|
|
7652
|
+
case "tokenResource":
|
|
7653
|
+
return ["resourceType"];
|
|
7654
|
+
case "dataSourceRun":
|
|
7655
|
+
return ["id"];
|
|
7656
|
+
case "invoiceDocument":
|
|
7657
|
+
return ["invoiceNumber"];
|
|
7658
|
+
case "projectBranch":
|
|
7659
|
+
return [spec.projectFrom];
|
|
7660
|
+
case "entity":
|
|
7661
|
+
return spec.projectFrom ? [spec.projectFrom] : [];
|
|
7662
|
+
default:
|
|
7663
|
+
return [];
|
|
7664
|
+
}
|
|
7665
|
+
}
|
|
7666
|
+
|
|
7667
|
+
// src/commands/trigger/index.ts
|
|
7668
|
+
function getOutputFormat11(cmd) {
|
|
7669
|
+
const config = loadConfig();
|
|
7670
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
7671
|
+
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
7672
|
+
}
|
|
7673
|
+
function getOverrides9(cmd) {
|
|
7674
|
+
const opts = cmd.optsWithGlobals();
|
|
7675
|
+
return { project: opts.project, branch: opts.branch };
|
|
7676
|
+
}
|
|
7677
|
+
function registerTriggerCommands(program) {
|
|
7678
|
+
const trigger = program.command("trigger").description("Manage function triggers").addHelpText("after", `
|
|
7679
|
+
Examples:
|
|
7680
|
+
$ diafunc trigger list <ref>
|
|
7681
|
+
$ diafunc trigger create <ref> --type CRON --expression '0 0 6 * * ?' every day at 06:00 (Quartz cron)
|
|
7682
|
+
$ diafunc trigger create <ref> --type INTERVAL --expression '15min' every 15 minutes
|
|
7683
|
+
$ diafunc trigger delete <ref> <triggerId>
|
|
7684
|
+
`);
|
|
7685
|
+
trigger.command("list").description("List triggers for a function").argument("<ref>", "Function entity reference").action(async (ref, _options, cmd) => {
|
|
7686
|
+
try {
|
|
7687
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
7688
|
+
const overrides = getOverrides9(cmd);
|
|
7689
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
7690
|
+
const api = createApiClient();
|
|
7691
|
+
const triggers = await api.evaluation.getTriggers(
|
|
7692
|
+
resolved.projectId,
|
|
7693
|
+
resolved.projectBranch,
|
|
7694
|
+
resolved.entityId,
|
|
7695
|
+
resolved.entityBranch
|
|
7696
|
+
);
|
|
7697
|
+
const summary = triggers.map((t) => ({
|
|
7698
|
+
triggerId: t.triggerId,
|
|
7699
|
+
type: t.type,
|
|
7700
|
+
active: t.active,
|
|
7701
|
+
expression: t.expression ?? "\u2014",
|
|
7702
|
+
fired: t.fired,
|
|
7703
|
+
persistent: t.persistent,
|
|
7704
|
+
createdBy: t.createdBy ? t.createdBy : "paused (save it again to resume)"
|
|
7705
|
+
}));
|
|
7706
|
+
format(summary, {
|
|
7707
|
+
format: outputFormat,
|
|
7708
|
+
columns: ["triggerId", "type", "active", "expression", "fired", "persistent", "createdBy"]
|
|
7709
|
+
});
|
|
7710
|
+
} catch (error) {
|
|
7711
|
+
handleError(error);
|
|
7712
|
+
}
|
|
7713
|
+
});
|
|
7714
|
+
trigger.command("get").description("Get a specific trigger").argument("<ref>", "Function entity reference").argument("<triggerId>", "Trigger ID").action(async (ref, triggerId, _options, cmd) => {
|
|
7715
|
+
try {
|
|
7716
|
+
const outputFormat = getOutputFormat11(cmd);
|
|
7717
|
+
const overrides = getOverrides9(cmd);
|
|
7718
|
+
const resolved = parseEntityReference(ref, overrides);
|
|
7719
|
+
const api = createApiClient();
|
|
6628
7720
|
const t = await api.evaluation.getTrigger(
|
|
6629
7721
|
resolved.projectId,
|
|
6630
7722
|
resolved.projectBranch,
|
|
@@ -6654,10 +7746,18 @@ Examples:
|
|
|
6654
7746
|
handleError(error);
|
|
6655
7747
|
}
|
|
6656
7748
|
});
|
|
6657
|
-
trigger.command("create").description("Create or update a trigger on a function").argument("<ref>", "Function entity reference").requiredOption("--type <type>",
|
|
7749
|
+
trigger.command("create").description("Create or update a trigger on a function").argument("<ref>", "Function entity reference").requiredOption("--type <type>", `Trigger type (${TRIGGER_TYPES.join(", ")})`).option("--trigger-id <id>", "Trigger ID (auto-generated if omitted)").option("--expression <expr>", "CRON: a Quartz cron expression ('0 0 6 * * ?'); INTERVAL: a duration ('15min', '1h 30min')").option("--origin <ref>", "Origin entity reference (for EVENT)").option("--count <n>", "Runs started each time the trigger fires", "1").option("--persistent", "Persistent trigger (survives after first fire)").option("--inactive", "Create the trigger inactive").option("--max <n>", "Maximum fire count (0 = unlimited)", "0").option("--args <json>", "Arguments passed on fire (JSON object)").action(async (ref, options, cmd) => {
|
|
6658
7750
|
try {
|
|
6659
7751
|
const overrides = getOverrides9(cmd);
|
|
6660
7752
|
const fn = parseEntityReference(ref, overrides);
|
|
7753
|
+
const type = String(options.type).toUpperCase();
|
|
7754
|
+
if (!TRIGGER_TYPES.includes(type)) {
|
|
7755
|
+
throw new Error(`Unknown trigger type "${options.type}": use one of ${TRIGGER_TYPES.join(", ")}.`);
|
|
7756
|
+
}
|
|
7757
|
+
const count = Number(options.count);
|
|
7758
|
+
if (!Number.isInteger(count) || count < 1) {
|
|
7759
|
+
throw new Error(`--count must be a whole number of at least 1, not "${options.count}".`);
|
|
7760
|
+
}
|
|
6661
7761
|
const api = createApiClient();
|
|
6662
7762
|
const args = options.args ? JSON.parse(options.args) : null;
|
|
6663
7763
|
const types = args ? Object.fromEntries(
|
|
@@ -6677,14 +7777,14 @@ Examples:
|
|
|
6677
7777
|
functionBranch: fn.entityBranch,
|
|
6678
7778
|
triggerId: options.triggerId ?? null,
|
|
6679
7779
|
bucketId: null,
|
|
6680
|
-
type
|
|
7780
|
+
type,
|
|
6681
7781
|
expression: options.expression ?? null,
|
|
6682
7782
|
conditions: null,
|
|
6683
7783
|
conditionTypes: null,
|
|
6684
7784
|
originEntityId,
|
|
6685
7785
|
originEntityBranch,
|
|
6686
7786
|
active: !options.inactive,
|
|
6687
|
-
quantity:
|
|
7787
|
+
quantity: count,
|
|
6688
7788
|
fired: 0,
|
|
6689
7789
|
maximum: options.max ? parseInt(options.max, 10) || null : null,
|
|
6690
7790
|
evaluationIds: null,
|
|
@@ -6797,7 +7897,7 @@ function registerScheduleCommands(program) {
|
|
|
6797
7897
|
resolved.entityId,
|
|
6798
7898
|
resolved.entityBranch
|
|
6799
7899
|
);
|
|
6800
|
-
const scheduled = triggers.filter((t) => t.type === "
|
|
7900
|
+
const scheduled = triggers.filter((t) => t.type === "CRON" || t.type === "INTERVAL");
|
|
6801
7901
|
const rows = scheduled.map((t) => ({
|
|
6802
7902
|
triggerId: t.triggerId,
|
|
6803
7903
|
expression: t.expression,
|
|
@@ -6817,12 +7917,12 @@ function registerScheduleCommands(program) {
|
|
|
6817
7917
|
}
|
|
6818
7918
|
|
|
6819
7919
|
// src/commands/chat/index.ts
|
|
6820
|
-
import
|
|
6821
|
-
import * as
|
|
7920
|
+
import chalk21 from "chalk";
|
|
7921
|
+
import * as fs10 from "fs";
|
|
6822
7922
|
import * as path7 from "path";
|
|
6823
7923
|
|
|
6824
7924
|
// src/output/markdown.ts
|
|
6825
|
-
import
|
|
7925
|
+
import chalk20 from "chalk";
|
|
6826
7926
|
var CODE_OPEN = "\0c";
|
|
6827
7927
|
var CODE_CLOSE = "\0";
|
|
6828
7928
|
var MarkdownRenderer = class {
|
|
@@ -6858,25 +7958,25 @@ var MarkdownRenderer = class {
|
|
|
6858
7958
|
if (fence) {
|
|
6859
7959
|
const opening = !this.inFence;
|
|
6860
7960
|
this.inFence = !this.inFence;
|
|
6861
|
-
return opening && fence[1] ? [
|
|
7961
|
+
return opening && fence[1] ? [chalk20.dim(` ${fence[1]}`)] : [];
|
|
6862
7962
|
}
|
|
6863
7963
|
if (this.inFence) {
|
|
6864
|
-
return [
|
|
7964
|
+
return [chalk20.cyan(` ${line}`)];
|
|
6865
7965
|
}
|
|
6866
7966
|
const heading2 = line.match(/^(#{1,6})\s+(.*)$/);
|
|
6867
7967
|
if (heading2) {
|
|
6868
7968
|
const text2 = inline(heading2[2]);
|
|
6869
|
-
return ["", heading2[1].length <= 2 ?
|
|
7969
|
+
return ["", heading2[1].length <= 2 ? chalk20.bold.underline(text2) : chalk20.bold(text2)];
|
|
6870
7970
|
}
|
|
6871
7971
|
if (/^\s*([-*_])\1{2,}\s*$/.test(line)) {
|
|
6872
|
-
return [
|
|
7972
|
+
return [chalk20.dim("\u2500".repeat(Math.min(this.width, 60)))];
|
|
6873
7973
|
}
|
|
6874
7974
|
const quote2 = line.match(/^\s*>\s?(.*)$/);
|
|
6875
|
-
if (quote2) return [
|
|
7975
|
+
if (quote2) return [chalk20.dim(` \u2502 ${inline(quote2[1])}`)];
|
|
6876
7976
|
const bullet = line.match(/^(\s*)[-*+]\s+(.*)$/);
|
|
6877
7977
|
if (bullet) {
|
|
6878
7978
|
return wrapWithIndent(
|
|
6879
|
-
`${bullet[1]}${
|
|
7979
|
+
`${bullet[1]}${chalk20.cyan("\u2022")} ${inline(bullet[2])}`,
|
|
6880
7980
|
bullet[1].length + 2,
|
|
6881
7981
|
this.width
|
|
6882
7982
|
);
|
|
@@ -6884,7 +7984,7 @@ var MarkdownRenderer = class {
|
|
|
6884
7984
|
const numbered = line.match(/^(\s*)(\d+)\.\s+(.*)$/);
|
|
6885
7985
|
if (numbered) {
|
|
6886
7986
|
return wrapWithIndent(
|
|
6887
|
-
`${numbered[1]}${
|
|
7987
|
+
`${numbered[1]}${chalk20.cyan(`${numbered[2]}.`)} ${inline(numbered[3])}`,
|
|
6888
7988
|
numbered[1].length + numbered[2].length + 2,
|
|
6889
7989
|
this.width
|
|
6890
7990
|
);
|
|
@@ -6907,10 +8007,10 @@ function inline(text2) {
|
|
|
6907
8007
|
codeSpans.push(code);
|
|
6908
8008
|
return `${CODE_OPEN}${codeSpans.length - 1}${CODE_CLOSE}`;
|
|
6909
8009
|
});
|
|
6910
|
-
working = working.replace(/\*\*([^*]+)\*\*/g, (_m, t) =>
|
|
8010
|
+
working = working.replace(/\*\*([^*]+)\*\*/g, (_m, t) => chalk20.bold(t)).replace(/__([^_]+)__/g, (_m, t) => chalk20.bold(t)).replace(/(^|[^*])\*([^*\n]+)\*/g, (_m, lead, t) => lead + chalk20.italic(t)).replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, label, url) => `${chalk20.underline(label)} ${chalk20.dim(`(${url})`)}`);
|
|
6911
8011
|
return working.replace(
|
|
6912
8012
|
new RegExp(`${CODE_OPEN}(\\d+)${CODE_CLOSE}`, "g"),
|
|
6913
|
-
(_m, i) =>
|
|
8013
|
+
(_m, i) => chalk20.yellow(codeSpans[Number(i)])
|
|
6914
8014
|
);
|
|
6915
8015
|
}
|
|
6916
8016
|
|
|
@@ -6923,7 +8023,7 @@ function getOutputFormat13(cmd) {
|
|
|
6923
8023
|
async function streamOneTurn(message, sessionId, projectId, branch, signal) {
|
|
6924
8024
|
const api = createApiClient();
|
|
6925
8025
|
const status = new Status();
|
|
6926
|
-
status.set([` ${
|
|
8026
|
+
status.set([` ${chalk21.magenta(SPINNER)} ${chalk21.dim("thinking")}`]);
|
|
6927
8027
|
status.start();
|
|
6928
8028
|
let response;
|
|
6929
8029
|
try {
|
|
@@ -7000,19 +8100,19 @@ var HELP = [
|
|
|
7000
8100
|
];
|
|
7001
8101
|
async function runChatRepl(options) {
|
|
7002
8102
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
7003
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
8103
|
+
const { getUpdateNotice } = await import("./update-check-KHHHTIDF.js");
|
|
7004
8104
|
let sessionId = options.session;
|
|
7005
8105
|
let lastReportedSession;
|
|
7006
|
-
console.log(
|
|
7007
|
-
if (options.project) console.log(
|
|
7008
|
-
if (sessionId) console.log(
|
|
8106
|
+
console.log(chalk21.bold("Diafunc chat") + chalk21.dim(" \xB7 /help for commands, /quit to exit"));
|
|
8107
|
+
if (options.project) console.log(chalk21.dim(`Project context: ${options.project}`));
|
|
8108
|
+
if (sessionId) console.log(chalk21.dim(`Continuing session ${sessionId}`));
|
|
7009
8109
|
const notice = await getUpdateNotice();
|
|
7010
|
-
if (notice) console.log(
|
|
8110
|
+
if (notice) console.log(chalk21.dim(notice));
|
|
7011
8111
|
console.log();
|
|
7012
8112
|
for (; ; ) {
|
|
7013
8113
|
let line;
|
|
7014
8114
|
try {
|
|
7015
|
-
line = await promptInput({ message:
|
|
8115
|
+
line = await promptInput({ message: chalk21.cyan.bold("you >") });
|
|
7016
8116
|
} catch {
|
|
7017
8117
|
console.log();
|
|
7018
8118
|
return;
|
|
@@ -7030,27 +8130,27 @@ async function runChatRepl(options) {
|
|
|
7030
8130
|
case "new":
|
|
7031
8131
|
sessionId = void 0;
|
|
7032
8132
|
lastReportedSession = void 0;
|
|
7033
|
-
console.log(
|
|
8133
|
+
console.log(chalk21.dim("Started a new session."));
|
|
7034
8134
|
continue;
|
|
7035
8135
|
case "clear":
|
|
7036
8136
|
console.clear();
|
|
7037
8137
|
continue;
|
|
7038
8138
|
case "session":
|
|
7039
8139
|
if (!arg) {
|
|
7040
|
-
console.log(
|
|
8140
|
+
console.log(chalk21.dim(`Current session: ${sessionId ?? "(new)"}`));
|
|
7041
8141
|
} else {
|
|
7042
8142
|
sessionId = arg;
|
|
7043
8143
|
lastReportedSession = void 0;
|
|
7044
|
-
console.log(
|
|
8144
|
+
console.log(chalk21.dim(`Switched to session ${sessionId}`));
|
|
7045
8145
|
}
|
|
7046
8146
|
continue;
|
|
7047
8147
|
case "help":
|
|
7048
8148
|
case "h":
|
|
7049
8149
|
case "?":
|
|
7050
|
-
for (const l of HELP) console.log(
|
|
8150
|
+
for (const l of HELP) console.log(chalk21.dim(l));
|
|
7051
8151
|
continue;
|
|
7052
8152
|
default:
|
|
7053
|
-
console.log(
|
|
8153
|
+
console.log(chalk21.dim(`Unknown command: /${cmd}. Try /help.`));
|
|
7054
8154
|
continue;
|
|
7055
8155
|
}
|
|
7056
8156
|
}
|
|
@@ -7063,19 +8163,19 @@ async function runChatRepl(options) {
|
|
|
7063
8163
|
sessionId = result.sessionId || sessionId;
|
|
7064
8164
|
console.log();
|
|
7065
8165
|
if (controller.signal.aborted) {
|
|
7066
|
-
console.log(
|
|
8166
|
+
console.log(chalk21.dim(" (canceled)"));
|
|
7067
8167
|
} else {
|
|
7068
8168
|
const parts = [`${result.input} in / ${result.output} out`];
|
|
7069
8169
|
if (sessionId && sessionId !== lastReportedSession) {
|
|
7070
8170
|
parts.push(`session ${sessionId}`);
|
|
7071
8171
|
lastReportedSession = sessionId;
|
|
7072
8172
|
}
|
|
7073
|
-
console.log(
|
|
8173
|
+
console.log(chalk21.dim(` ${parts.join(" \xB7 ")}`));
|
|
7074
8174
|
}
|
|
7075
8175
|
console.log();
|
|
7076
8176
|
} catch (error) {
|
|
7077
8177
|
if (controller.signal.aborted) {
|
|
7078
|
-
console.log(
|
|
8178
|
+
console.log(chalk21.dim(" (canceled)"));
|
|
7079
8179
|
console.log();
|
|
7080
8180
|
} else {
|
|
7081
8181
|
failure(`Request failed: ${error.message}`);
|
|
@@ -7119,7 +8219,7 @@ Examples:
|
|
|
7119
8219
|
if (outputFormat === "human") {
|
|
7120
8220
|
console.log(renderMarkdown(response.content));
|
|
7121
8221
|
console.log();
|
|
7122
|
-
console.log(
|
|
8222
|
+
console.log(chalk21.dim(
|
|
7123
8223
|
` session ${response.sessionId} \xB7 ${response.inputTokens} in / ${response.outputTokens} out`
|
|
7124
8224
|
));
|
|
7125
8225
|
} else {
|
|
@@ -7187,7 +8287,7 @@ Examples:
|
|
|
7187
8287
|
sessionId = event.sessionId ?? "";
|
|
7188
8288
|
console.log();
|
|
7189
8289
|
console.log();
|
|
7190
|
-
console.log(
|
|
8290
|
+
console.log(chalk21.dim(`Session: ${sessionId} | Tokens: ${event.inputTokens} in, ${event.outputTokens} out`));
|
|
7191
8291
|
} else if (event.type === "error") {
|
|
7192
8292
|
failure(`Error: ${event.content}`);
|
|
7193
8293
|
}
|
|
@@ -7203,12 +8303,12 @@ Examples:
|
|
|
7203
8303
|
});
|
|
7204
8304
|
chat.command("upload").description("Upload a file for chat context").argument("<file>", "File to upload").action(async (file) => {
|
|
7205
8305
|
try {
|
|
7206
|
-
if (!
|
|
8306
|
+
if (!fs10.existsSync(file)) {
|
|
7207
8307
|
failure(`File not found: ${file}`);
|
|
7208
8308
|
process.exit(1);
|
|
7209
8309
|
}
|
|
7210
8310
|
const api = createApiClient();
|
|
7211
|
-
const fileBuffer =
|
|
8311
|
+
const fileBuffer = fs10.readFileSync(file);
|
|
7212
8312
|
const blob = new Blob([fileBuffer]);
|
|
7213
8313
|
const formData = new FormData();
|
|
7214
8314
|
formData.append("file", blob, path7.basename(file));
|
|
@@ -7247,11 +8347,11 @@ Examples:
|
|
|
7247
8347
|
const api = createApiClient();
|
|
7248
8348
|
const detail2 = await api.language.getSession(sessionId);
|
|
7249
8349
|
if (outputFormat === "human") {
|
|
7250
|
-
console.log(
|
|
8350
|
+
console.log(chalk21.bold(detail2.title) + chalk21.dim(` (${detail2.sessionId})`));
|
|
7251
8351
|
console.log();
|
|
7252
8352
|
for (const msg of detail2.messages) {
|
|
7253
|
-
const role = msg.role === "user" ?
|
|
7254
|
-
console.log(`${role} ${
|
|
8353
|
+
const role = msg.role === "user" ? chalk21.cyan.bold("You") : chalk21.magenta.bold("Diafunc");
|
|
8354
|
+
console.log(`${role} ${chalk21.dim(msg.created)}`);
|
|
7255
8355
|
console.log(msg.content);
|
|
7256
8356
|
console.log();
|
|
7257
8357
|
}
|
|
@@ -7284,7 +8384,7 @@ Examples:
|
|
|
7284
8384
|
}
|
|
7285
8385
|
|
|
7286
8386
|
// src/commands/search/index.ts
|
|
7287
|
-
import
|
|
8387
|
+
import chalk22 from "chalk";
|
|
7288
8388
|
function getOutputFormat14(cmd) {
|
|
7289
8389
|
const config = loadConfig();
|
|
7290
8390
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -7346,7 +8446,7 @@ whose discovered model has the better quality comes first; inside one project th
|
|
|
7346
8446
|
});
|
|
7347
8447
|
}
|
|
7348
8448
|
if (page.nextCursor && isInteractive()) {
|
|
7349
|
-
console.log(
|
|
8449
|
+
console.log(chalk22.dim(`More results available. Raise --limit to see them.`));
|
|
7350
8450
|
}
|
|
7351
8451
|
} catch (error) {
|
|
7352
8452
|
handleError(error);
|
|
@@ -7368,12 +8468,12 @@ function renderResults(items) {
|
|
|
7368
8468
|
for (const item of items) {
|
|
7369
8469
|
const name = item.name || "(unnamed)";
|
|
7370
8470
|
console.log();
|
|
7371
|
-
console.log(`${
|
|
8471
|
+
console.log(`${chalk22.dim(`[${item.contentType}]`)} ${chalk22.bold(name)}${qualityNote(item)}`);
|
|
7372
8472
|
const raw = item.snippetField === "name" ? item.description : item.snippet ?? item.description;
|
|
7373
8473
|
const line = raw ? collapse(raw) : null;
|
|
7374
8474
|
if (line && stripHighlight(line) !== name) console.log(` ${highlight(line)}`);
|
|
7375
8475
|
const ref = item.entityId ? `${item.projectId}/${item.projectBranch}/${item.entityId}/${item.entityBranch ?? "main"}` : item.projectId;
|
|
7376
|
-
console.log(` ${
|
|
8476
|
+
console.log(` ${chalk22.dim(ref)}`);
|
|
7377
8477
|
}
|
|
7378
8478
|
console.log();
|
|
7379
8479
|
}
|
|
@@ -7381,16 +8481,16 @@ function qualityNote(item) {
|
|
|
7381
8481
|
if (item.contentType !== "project" || typeof item.quality !== "number" || !Number.isFinite(item.quality)) {
|
|
7382
8482
|
return "";
|
|
7383
8483
|
}
|
|
7384
|
-
return
|
|
8484
|
+
return chalk22.dim(` quality ${percent(item.quality).trim()}`);
|
|
7385
8485
|
}
|
|
7386
8486
|
var HIGHLIGHT_OPEN = /<mark>/g;
|
|
7387
8487
|
var HIGHLIGHT_CLOSE = /<\/mark>/g;
|
|
7388
8488
|
function highlight(text2) {
|
|
7389
8489
|
const parts = text2.split(HIGHLIGHT_OPEN);
|
|
7390
8490
|
return parts.map((part, i) => {
|
|
7391
|
-
if (i === 0) return
|
|
8491
|
+
if (i === 0) return chalk22.dim(part);
|
|
7392
8492
|
const [marked, ...rest] = part.split(HIGHLIGHT_CLOSE);
|
|
7393
|
-
return
|
|
8493
|
+
return chalk22.bold.cyan(marked) + chalk22.dim(rest.join(""));
|
|
7394
8494
|
}).join("");
|
|
7395
8495
|
}
|
|
7396
8496
|
function stripHighlight(text2) {
|
|
@@ -7405,7 +8505,7 @@ function collapse(text2) {
|
|
|
7405
8505
|
import { readFile } from "fs/promises";
|
|
7406
8506
|
|
|
7407
8507
|
// src/commands/admin/curated-tags.ts
|
|
7408
|
-
import
|
|
8508
|
+
import chalk23 from "chalk";
|
|
7409
8509
|
function getOutputFormat15(cmd) {
|
|
7410
8510
|
const config = loadConfig();
|
|
7411
8511
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -7421,7 +8521,7 @@ var COLUMNS = [
|
|
|
7421
8521
|
function curatedTagOf(typed2) {
|
|
7422
8522
|
const tag = normalizeTag(typed2);
|
|
7423
8523
|
if (tag === "") usageError(`"${typed2}" is not a usable tag: a tag needs at least one letter or digit.`);
|
|
7424
|
-
if (tag !== typed2) console.error(
|
|
8524
|
+
if (tag !== typed2) console.error(chalk23.dim(`"${typed2}" is written as "${tag}", the form tags are searched by.`));
|
|
7425
8525
|
return tag;
|
|
7426
8526
|
}
|
|
7427
8527
|
function parseSortOrder(raw) {
|
|
@@ -7687,7 +8787,7 @@ function registerAdminCommands(program) {
|
|
|
7687
8787
|
);
|
|
7688
8788
|
const api = createApiClient();
|
|
7689
8789
|
await api.storage.restoreFullBackup({ bucketName, objectName });
|
|
7690
|
-
success(`Full restore
|
|
8790
|
+
success(`Full restore started from ${bucketName}/${objectName}.`);
|
|
7691
8791
|
} catch (error) {
|
|
7692
8792
|
handleError(error);
|
|
7693
8793
|
}
|
|
@@ -7698,10 +8798,10 @@ function registerAdminCommands(program) {
|
|
|
7698
8798
|
const { project } = cmd.optsWithGlobals();
|
|
7699
8799
|
if (project) {
|
|
7700
8800
|
await api.index.rebuildProject(project);
|
|
7701
|
-
success(`Index rebuild
|
|
8801
|
+
success(`Index rebuild started for project "${project}".`);
|
|
7702
8802
|
} else {
|
|
7703
8803
|
await api.index.rebuildAll();
|
|
7704
|
-
success("Index rebuild
|
|
8804
|
+
success("Index rebuild started for all projects.");
|
|
7705
8805
|
}
|
|
7706
8806
|
} catch (error) {
|
|
7707
8807
|
handleError(error);
|
|
@@ -7744,7 +8844,7 @@ function registerAdminCommands(program) {
|
|
|
7744
8844
|
}
|
|
7745
8845
|
|
|
7746
8846
|
// src/commands/status/summary.ts
|
|
7747
|
-
import
|
|
8847
|
+
import chalk24 from "chalk";
|
|
7748
8848
|
|
|
7749
8849
|
// src/client/services/status.ts
|
|
7750
8850
|
function createStatusService() {
|
|
@@ -7770,24 +8870,24 @@ function createStatusService() {
|
|
|
7770
8870
|
|
|
7771
8871
|
// src/commands/status/summary.ts
|
|
7772
8872
|
var STATE_COLORS = {
|
|
7773
|
-
UP:
|
|
7774
|
-
DEGRADED:
|
|
7775
|
-
DOWN:
|
|
7776
|
-
UNKNOWN:
|
|
8873
|
+
UP: chalk24.green,
|
|
8874
|
+
DEGRADED: chalk24.yellow,
|
|
8875
|
+
DOWN: chalk24.red,
|
|
8876
|
+
UNKNOWN: chalk24.gray
|
|
7777
8877
|
};
|
|
7778
8878
|
function stateColor(state) {
|
|
7779
|
-
return STATE_COLORS[state] ??
|
|
8879
|
+
return STATE_COLORS[state] ?? chalk24.gray;
|
|
7780
8880
|
}
|
|
7781
8881
|
function stateSymbol(state) {
|
|
7782
8882
|
switch (state) {
|
|
7783
8883
|
case "UP":
|
|
7784
|
-
return
|
|
8884
|
+
return chalk24.green("\u25CF");
|
|
7785
8885
|
case "DEGRADED":
|
|
7786
|
-
return
|
|
8886
|
+
return chalk24.yellow("\u25CF");
|
|
7787
8887
|
case "DOWN":
|
|
7788
|
-
return
|
|
8888
|
+
return chalk24.red("\u25CF");
|
|
7789
8889
|
default:
|
|
7790
|
-
return
|
|
8890
|
+
return chalk24.gray("\u25CB");
|
|
7791
8891
|
}
|
|
7792
8892
|
}
|
|
7793
8893
|
function registerSummaryCommand(parent) {
|
|
@@ -7812,20 +8912,20 @@ function registerSummaryCommand(parent) {
|
|
|
7812
8912
|
const label = stateColor(domain.state)(domain.state.padEnd(10));
|
|
7813
8913
|
console.log(` ${stateSymbol(domain.state)} ${label} ${domain.name}`);
|
|
7814
8914
|
if (domain.componentIds.length > 0) {
|
|
7815
|
-
console.log(` ${
|
|
8915
|
+
console.log(` ${chalk24.dim(domain.componentIds.join(", "))}`);
|
|
7816
8916
|
}
|
|
7817
8917
|
}
|
|
7818
8918
|
console.log();
|
|
7819
8919
|
if (summary.openIncidents > 0) {
|
|
7820
|
-
console.log(
|
|
8920
|
+
console.log(chalk24.yellow(` ${summary.openIncidents} active incident(s)`));
|
|
7821
8921
|
} else {
|
|
7822
|
-
console.log(
|
|
8922
|
+
console.log(chalk24.dim(" No active incidents"));
|
|
7823
8923
|
}
|
|
7824
|
-
console.log(
|
|
8924
|
+
console.log(chalk24.dim(
|
|
7825
8925
|
`
|
|
7826
8926
|
Platform v${version.platformVersion} \xB7 checked ${formatInstant(summary.timestamp)}`
|
|
7827
8927
|
));
|
|
7828
|
-
console.log(
|
|
8928
|
+
console.log(chalk24.dim(` Drill into one with 'diafunc status component <id>'.`));
|
|
7829
8929
|
console.log();
|
|
7830
8930
|
} catch (error) {
|
|
7831
8931
|
handleError(error);
|
|
@@ -7834,17 +8934,17 @@ function registerSummaryCommand(parent) {
|
|
|
7834
8934
|
}
|
|
7835
8935
|
|
|
7836
8936
|
// src/commands/status/component.ts
|
|
7837
|
-
import
|
|
8937
|
+
import chalk25 from "chalk";
|
|
7838
8938
|
function stateSymbol2(state) {
|
|
7839
8939
|
switch (state) {
|
|
7840
8940
|
case "UP":
|
|
7841
|
-
return
|
|
8941
|
+
return chalk25.green("\u25CF");
|
|
7842
8942
|
case "DEGRADED":
|
|
7843
|
-
return
|
|
8943
|
+
return chalk25.yellow("\u25CF");
|
|
7844
8944
|
case "DOWN":
|
|
7845
|
-
return
|
|
8945
|
+
return chalk25.red("\u25CF");
|
|
7846
8946
|
default:
|
|
7847
|
-
return
|
|
8947
|
+
return chalk25.gray("\u25CB");
|
|
7848
8948
|
}
|
|
7849
8949
|
}
|
|
7850
8950
|
function registerComponentCommand(parent) {
|
|
@@ -7869,7 +8969,7 @@ function registerComponentCommand(parent) {
|
|
|
7869
8969
|
return;
|
|
7870
8970
|
}
|
|
7871
8971
|
console.log();
|
|
7872
|
-
console.log(` ${stateSymbol2(match.state)} ${
|
|
8972
|
+
console.log(` ${stateSymbol2(match.state)} ${chalk25.bold(match.id)} ${match.version ? chalk25.dim("v" + match.version) : ""}`);
|
|
7873
8973
|
console.log(` State: ${renderState(match.state)}`);
|
|
7874
8974
|
if (match.lastCheckAt) {
|
|
7875
8975
|
console.log(` Last check: ${formatInstant(match.lastCheckAt)}`);
|
|
@@ -7878,7 +8978,7 @@ function registerComponentCommand(parent) {
|
|
|
7878
8978
|
console.log();
|
|
7879
8979
|
console.log(" Checks:");
|
|
7880
8980
|
for (const check of match.checks) {
|
|
7881
|
-
const cat = check.category ?
|
|
8981
|
+
const cat = check.category ? chalk25.dim(` (${check.category})`) : "";
|
|
7882
8982
|
console.log(` ${stateSymbol2(check.state)} ${check.name}${cat}`);
|
|
7883
8983
|
}
|
|
7884
8984
|
}
|
|
@@ -7890,12 +8990,12 @@ function registerComponentCommand(parent) {
|
|
|
7890
8990
|
}
|
|
7891
8991
|
|
|
7892
8992
|
// src/commands/status/incidents.ts
|
|
7893
|
-
import
|
|
8993
|
+
import chalk26 from "chalk";
|
|
7894
8994
|
var SEVERITY_COLORS = {
|
|
7895
|
-
ERROR:
|
|
7896
|
-
WARNING:
|
|
7897
|
-
INFO:
|
|
7898
|
-
MAINTENANCE:
|
|
8995
|
+
ERROR: chalk26.red,
|
|
8996
|
+
WARNING: chalk26.yellow,
|
|
8997
|
+
INFO: chalk26.blue,
|
|
8998
|
+
MAINTENANCE: chalk26.cyan
|
|
7899
8999
|
};
|
|
7900
9000
|
function registerIncidentsCommand(parent) {
|
|
7901
9001
|
parent.command("incidents").description("List recent incidents").option("-w, --window <window>", "Time window (e.g. 24h, 48h)", "24h").action(async (options, cmd) => {
|
|
@@ -7909,22 +9009,22 @@ function registerIncidentsCommand(parent) {
|
|
|
7909
9009
|
return;
|
|
7910
9010
|
}
|
|
7911
9011
|
if (incidents.length === 0) {
|
|
7912
|
-
console.log(
|
|
9012
|
+
console.log(chalk26.dim(`
|
|
7913
9013
|
No incidents in the last ${options.window}.
|
|
7914
9014
|
`));
|
|
7915
9015
|
return;
|
|
7916
9016
|
}
|
|
7917
9017
|
console.log();
|
|
7918
9018
|
for (const incident of incidents) {
|
|
7919
|
-
const color = SEVERITY_COLORS[incident.severity] ??
|
|
9019
|
+
const color = SEVERITY_COLORS[incident.severity] ?? chalk26.gray;
|
|
7920
9020
|
const severity = color(incident.severity.padEnd(8));
|
|
7921
9021
|
const time = incident.startedAt ? new Date(incident.startedAt).toLocaleString() : "";
|
|
7922
|
-
const resolved = incident.resolvedAt ?
|
|
9022
|
+
const resolved = incident.resolvedAt ? chalk26.green(" [resolved]") : chalk26.yellow(" [open]");
|
|
7923
9023
|
console.log(` ${severity} ${incident.summary}${resolved}`);
|
|
7924
|
-
console.log(
|
|
9024
|
+
console.log(chalk26.dim(` ${time}`));
|
|
7925
9025
|
for (const update of incident.updates) {
|
|
7926
9026
|
const updateTime = new Date(update.at).toLocaleTimeString();
|
|
7927
|
-
console.log(
|
|
9027
|
+
console.log(chalk26.dim(` ${updateTime} ${update.status} ${update.message}`));
|
|
7928
9028
|
}
|
|
7929
9029
|
console.log();
|
|
7930
9030
|
}
|
|
@@ -7940,7 +9040,7 @@ function registerStatusCommands(program) {
|
|
|
7940
9040
|
Examples:
|
|
7941
9041
|
$ diafunc status summary everything, at a glance
|
|
7942
9042
|
$ diafunc status component storage one service in detail
|
|
7943
|
-
$ diafunc status incidents --
|
|
9043
|
+
$ diafunc status incidents --window 168h
|
|
7944
9044
|
`);
|
|
7945
9045
|
;
|
|
7946
9046
|
registerSummaryCommand(status);
|
|
@@ -7949,12 +9049,12 @@ Examples:
|
|
|
7949
9049
|
}
|
|
7950
9050
|
|
|
7951
9051
|
// src/commands/analyze/index.ts
|
|
7952
|
-
import * as
|
|
9052
|
+
import * as fs12 from "fs";
|
|
7953
9053
|
import * as path9 from "path";
|
|
7954
9054
|
import { spawn as spawn2 } from "child_process";
|
|
7955
9055
|
|
|
7956
9056
|
// src/commands/analyze/watch-view.ts
|
|
7957
|
-
import
|
|
9057
|
+
import chalk27 from "chalk";
|
|
7958
9058
|
|
|
7959
9059
|
// src/client/types/analysis.ts
|
|
7960
9060
|
var RUN_PHASE_LABELS = {
|
|
@@ -7974,6 +9074,7 @@ function phaseLabel(run) {
|
|
|
7974
9074
|
if (run.state === "DISPATCHING") return STARTING;
|
|
7975
9075
|
if (run.phase && RUN_PHASE_LABELS[run.phase]) return RUN_PHASE_LABELS[run.phase];
|
|
7976
9076
|
if (run.state === "RUNNING" && !((run.progressTotal ?? 0) > 0)) return RUN_PHASE_LABELS.PREPARING;
|
|
9077
|
+
if (run.state === "CANCELLED") return "Canceled";
|
|
7977
9078
|
return run.state.charAt(0) + run.state.slice(1).toLowerCase();
|
|
7978
9079
|
}
|
|
7979
9080
|
function waitLabel(run) {
|
|
@@ -8009,7 +9110,7 @@ function latestRunSentence(state) {
|
|
|
8009
9110
|
case "FAILED":
|
|
8010
9111
|
return "The latest run failed.";
|
|
8011
9112
|
case "CANCELLED":
|
|
8012
|
-
return "The latest run was
|
|
9113
|
+
return "The latest run was canceled.";
|
|
8013
9114
|
case "QUEUED":
|
|
8014
9115
|
return "The latest run is waiting for a slot.";
|
|
8015
9116
|
case "DISPATCHING":
|
|
@@ -8021,7 +9122,7 @@ function latestRunSentence(state) {
|
|
|
8021
9122
|
function cancelSentence(run) {
|
|
8022
9123
|
switch (run.state) {
|
|
8023
9124
|
case "CANCELLED":
|
|
8024
|
-
return `
|
|
9125
|
+
return `Canceled run ${run.runId}.`;
|
|
8025
9126
|
case "COMPLETED":
|
|
8026
9127
|
return `Run ${run.runId} had already completed.`;
|
|
8027
9128
|
case "FAILED":
|
|
@@ -8039,7 +9140,7 @@ function terminalSentence(state, duration, credits = null) {
|
|
|
8039
9140
|
case "COMPLETED":
|
|
8040
9141
|
return `Analysis completed in ${duration}${cost}.`;
|
|
8041
9142
|
case "CANCELLED":
|
|
8042
|
-
return `Analysis
|
|
9143
|
+
return `Analysis canceled after ${duration}${cost}.`;
|
|
8043
9144
|
default:
|
|
8044
9145
|
return `Analysis failed after ${duration}${cost}.`;
|
|
8045
9146
|
}
|
|
@@ -8050,7 +9151,7 @@ function isImporting(dataImport) {
|
|
|
8050
9151
|
function importingLabel(dataImport) {
|
|
8051
9152
|
const progress = dataImport.progress;
|
|
8052
9153
|
if (progress === null || progress === void 0 || !Number.isFinite(progress)) return "Importing data";
|
|
8053
|
-
return `Importing data, ${Math.floor(Math.max(0, Math.min(progress, 1)) * 100)}
|
|
9154
|
+
return `Importing data, ${Math.floor(Math.max(0, Math.min(progress, 1)) * 100)}%`;
|
|
8054
9155
|
}
|
|
8055
9156
|
function verdictLabel(run) {
|
|
8056
9157
|
switch (run.validity) {
|
|
@@ -8101,232 +9202,71 @@ function phaseDetail(run) {
|
|
|
8101
9202
|
if (run.fitBudgetFraction !== null && run.fitBudgetFraction !== void 0) {
|
|
8102
9203
|
parts.push(`${Math.round(run.fitBudgetFraction * 100)}% of budget used`);
|
|
8103
9204
|
}
|
|
8104
|
-
}
|
|
8105
|
-
if (parts.length === 0 && run.progressTotal && run.progressTotal > 0) {
|
|
8106
|
-
parts.push(`${formatNumber(run.progressDone ?? 0)} of ${formatNumber(run.progressTotal)} tasks`);
|
|
8107
|
-
} else if (parts.length === 0 && run.phaseFraction !== null && run.phaseFraction !== void 0) {
|
|
8108
|
-
parts.push(`${Math.round(run.phaseFraction * 100)}% of this step`);
|
|
8109
|
-
}
|
|
8110
|
-
return parts.length > 0 ? parts.join(" \xB7 ") : null;
|
|
8111
|
-
}
|
|
8112
|
-
function renderWatchBlock(input) {
|
|
8113
|
-
const { run, elapsedMs, caption, budgetHours } = input;
|
|
8114
|
-
const lines = [];
|
|
8115
|
-
const step = stepCounter(run);
|
|
8116
|
-
const headline = [
|
|
8117
|
-
chalk26.cyan(SPINNER),
|
|
8118
|
-
chalk26.bold(phaseLabel(run)),
|
|
8119
|
-
step ? chalk26.dim(step) : null
|
|
8120
|
-
].filter(Boolean).join(" ");
|
|
8121
|
-
lines.push(` ${headline}`);
|
|
8122
|
-
const fraction = overallProgress(run);
|
|
8123
|
-
const elapsed = chalk26.dim(formatDurationPrecise(elapsedMs));
|
|
8124
|
-
if (fraction === null) {
|
|
8125
|
-
lines.push(` ${chalk26.dim("working")} ${elapsed}`);
|
|
8126
|
-
} else {
|
|
8127
|
-
const ceiling = remainingCeiling(run, budgetHours);
|
|
8128
|
-
lines.push(
|
|
8129
|
-
` ${bar(fraction)} ${percent(fraction)} ${elapsed}` + (ceiling !== null ? chalk26.dim(` \xB7 at most ${formatDurationPrecise(ceiling)} remaining`) : "")
|
|
8130
|
-
);
|
|
8131
|
-
}
|
|
8132
|
-
const detail2 = caption ?? phaseDetail(run);
|
|
8133
|
-
if (detail2) lines.push(` ${chalk26.dim(detail2)}`);
|
|
8134
|
-
if (run.retryAttempts && run.retryAttempts > 0) {
|
|
8135
|
-
lines.push(` ${chalk26.yellow("!")} ${chalk26.dim(
|
|
8136
|
-
`restarted ${run.retryAttempts === 1 ? "once" : `${run.retryAttempts} times`} after an interruption; progress restarts from the beginning`
|
|
8137
|
-
)}`);
|
|
8138
|
-
}
|
|
8139
|
-
return lines;
|
|
8140
|
-
}
|
|
8141
|
-
|
|
8142
|
-
// src/commands/analyze/wizard.ts
|
|
8143
|
-
import chalk27 from "chalk";
|
|
8144
|
-
|
|
8145
|
-
// src/commands/analyze/columns.ts
|
|
8146
|
-
var MAX_COLUMNS_LISTED = 30;
|
|
8147
|
-
var MAX_NEAR_MATCHES = 3;
|
|
8148
|
-
function parseColumnList(text2) {
|
|
8149
|
-
const names = [];
|
|
8150
|
-
let i = 0;
|
|
8151
|
-
while (i < text2.length) {
|
|
8152
|
-
while (i < text2.length && isSpace(text2[i])) i++;
|
|
8153
|
-
if (i >= text2.length) break;
|
|
8154
|
-
if (text2[i] === '"') {
|
|
8155
|
-
let name = "";
|
|
8156
|
-
let closed = false;
|
|
8157
|
-
i++;
|
|
8158
|
-
while (i < text2.length) {
|
|
8159
|
-
if (text2[i] === '"' && text2[i + 1] === '"') {
|
|
8160
|
-
name += '"';
|
|
8161
|
-
i += 2;
|
|
8162
|
-
} else if (text2[i] === '"') {
|
|
8163
|
-
closed = true;
|
|
8164
|
-
i++;
|
|
8165
|
-
break;
|
|
8166
|
-
} else {
|
|
8167
|
-
name += text2[i++];
|
|
8168
|
-
}
|
|
8169
|
-
}
|
|
8170
|
-
if (!closed) {
|
|
8171
|
-
throw new CliError(`A double quote is opened and never closed in: ${text2}`, {
|
|
8172
|
-
exitCode: EXIT_USAGE,
|
|
8173
|
-
hint: QUOTING_HINT
|
|
8174
|
-
});
|
|
8175
|
-
}
|
|
8176
|
-
while (i < text2.length && isSpace(text2[i])) i++;
|
|
8177
|
-
if (i < text2.length && text2[i] !== ",") {
|
|
8178
|
-
throw new CliError(`Text follows a closing double quote without a comma in: ${text2}`, {
|
|
8179
|
-
exitCode: EXIT_USAGE,
|
|
8180
|
-
hint: QUOTING_HINT
|
|
8181
|
-
});
|
|
8182
|
-
}
|
|
8183
|
-
i++;
|
|
8184
|
-
if (name.length > 0) names.push(name);
|
|
8185
|
-
} else {
|
|
8186
|
-
const end = text2.indexOf(",", i);
|
|
8187
|
-
const name = text2.slice(i, end === -1 ? text2.length : end).trim();
|
|
8188
|
-
i = end === -1 ? text2.length : end + 1;
|
|
8189
|
-
if (name.length > 0) names.push(name);
|
|
8190
|
-
}
|
|
8191
|
-
}
|
|
8192
|
-
return names;
|
|
8193
|
-
}
|
|
8194
|
-
var QUOTING_HINT = `Inside a list, put a name that contains a comma in double quotes and write a quote in it twice: '"a, b",c'.`;
|
|
8195
|
-
function isSpace(char) {
|
|
8196
|
-
return char === " " || char === " ";
|
|
8197
|
-
}
|
|
8198
|
-
function quoteColumn(name) {
|
|
8199
|
-
return `"${name.replace(/"/g, '""')}"`;
|
|
8200
|
-
}
|
|
8201
|
-
function loose(name) {
|
|
8202
|
-
return name.trim().toLowerCase();
|
|
8203
|
-
}
|
|
8204
|
-
function matchColumn(name, columns) {
|
|
8205
|
-
if (columns.includes(name)) return { kind: "column", column: name };
|
|
8206
|
-
const wanted = loose(name);
|
|
8207
|
-
const candidates = columns.filter((column) => loose(column) === wanted);
|
|
8208
|
-
if (candidates.length === 1) return { kind: "column", column: candidates[0] };
|
|
8209
|
-
return candidates.length > 1 ? { kind: "ambiguous", candidates } : { kind: "unknown" };
|
|
8210
|
-
}
|
|
8211
|
-
function nearMatches(name, columns) {
|
|
8212
|
-
const wanted = loose(name);
|
|
8213
|
-
if (wanted.length === 0) return [];
|
|
8214
|
-
return columns.map((column) => ({ column, distance: distanceTo(wanted, loose(column)) })).filter((scored) => scored.distance !== null).sort((a, b) => a.distance - b.distance).slice(0, MAX_NEAR_MATCHES).map((scored) => scored.column);
|
|
8215
|
-
}
|
|
8216
|
-
function distanceTo(wanted, column) {
|
|
8217
|
-
const edits = editDistance(wanted, column);
|
|
8218
|
-
if (edits <= Math.max(1, Math.floor(Math.min(wanted.length, column.length) / 4))) return edits;
|
|
8219
|
-
if (wanted.length >= 3 && (column.includes(wanted) || wanted.includes(column)) && column.length > 0) {
|
|
8220
|
-
return 100 + Math.abs(column.length - wanted.length);
|
|
8221
|
-
}
|
|
8222
|
-
return null;
|
|
8223
|
-
}
|
|
8224
|
-
function editDistance(a, b) {
|
|
8225
|
-
let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
8226
|
-
for (let i = 1; i <= a.length; i++) {
|
|
8227
|
-
const current = [i];
|
|
8228
|
-
for (let j = 1; j <= b.length; j++) {
|
|
8229
|
-
current[j] = Math.min(
|
|
8230
|
-
previous[j] + 1,
|
|
8231
|
-
current[j - 1] + 1,
|
|
8232
|
-
previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1)
|
|
8233
|
-
);
|
|
8234
|
-
}
|
|
8235
|
-
previous = current;
|
|
8236
|
-
}
|
|
8237
|
-
return previous[b.length];
|
|
8238
|
-
}
|
|
8239
|
-
function take(name, columns, into, problems) {
|
|
8240
|
-
const match = matchColumn(name, columns);
|
|
8241
|
-
if (match.kind === "column") {
|
|
8242
|
-
if (!into.includes(match.column)) into.push(match.column);
|
|
8243
|
-
return true;
|
|
8244
|
-
}
|
|
8245
|
-
if (match.kind === "ambiguous") problems.ambiguous.push({ name, candidates: match.candidates });
|
|
8246
|
-
else problems.unknown.push(name);
|
|
8247
|
-
return false;
|
|
8248
|
-
}
|
|
8249
|
-
function refuse(problems, columns, analysisId) {
|
|
8250
|
-
const sentences = [];
|
|
8251
|
-
if (problems.unknown.length === 1) {
|
|
8252
|
-
sentences.push(`${quoteColumn(problems.unknown[0])} is not a column of the analysis data.`);
|
|
8253
|
-
} else if (problems.unknown.length > 1) {
|
|
8254
|
-
sentences.push(`These are not columns of the analysis data: ${problems.unknown.map(quoteColumn).join(", ")}.`);
|
|
8255
|
-
}
|
|
8256
|
-
for (const { name, candidates } of problems.ambiguous) {
|
|
8257
|
-
sentences.push(`${quoteColumn(name)} matches more than one column: ${candidates.map(quoteColumn).join(", ")}. Type the one you mean exactly.`);
|
|
8258
|
-
}
|
|
8259
|
-
const hints = [];
|
|
8260
|
-
const near = [...new Set(problems.unknown.flatMap((name) => nearMatches(name, columns)))];
|
|
8261
|
-
if (near.length > 0) hints.push(`Did you mean ${near.map(quoteColumn).join(" or ")}?`);
|
|
8262
|
-
const listed2 = columns.slice(0, MAX_COLUMNS_LISTED).map(quoteColumn).join(", ");
|
|
8263
|
-
const more = columns.length > MAX_COLUMNS_LISTED ? ` and ${columns.length - MAX_COLUMNS_LISTED} more${analysisId ? ` ('diafunc analyze columns ${analysisId}' lists them all)` : ""}` : "";
|
|
8264
|
-
hints.push(`The columns are: ${listed2}${more}.`);
|
|
8265
|
-
if (problems.fromList) {
|
|
8266
|
-
hints.push(`A name that contains a comma is an argument of its own, or goes in double quotes inside a list: '"a, b",c'.`);
|
|
8267
|
-
}
|
|
8268
|
-
throw new CliError(sentences.join(" "), { exitCode: EXIT_USAGE, hint: hints.join("\n ") });
|
|
8269
|
-
}
|
|
8270
|
-
function resolveColumnArguments(given, columns, analysisId) {
|
|
8271
|
-
const resolved = [];
|
|
8272
|
-
if (columns.length === 0) {
|
|
8273
|
-
for (const name of given.flatMap(parseColumnList)) {
|
|
8274
|
-
if (!resolved.includes(name)) resolved.push(name);
|
|
8275
|
-
}
|
|
8276
|
-
return resolved;
|
|
8277
|
-
}
|
|
8278
|
-
const problems = { unknown: [], ambiguous: [], fromList: false };
|
|
8279
|
-
for (const argument of given) {
|
|
8280
|
-
if (argument.trim().length === 0) continue;
|
|
8281
|
-
const whole = matchColumn(argument, columns);
|
|
8282
|
-
if (whole.kind === "column") {
|
|
8283
|
-
if (!resolved.includes(whole.column)) resolved.push(whole.column);
|
|
8284
|
-
continue;
|
|
8285
|
-
}
|
|
8286
|
-
const names = parseColumnList(argument);
|
|
8287
|
-
const single = names.length === 1 && names[0] === argument.trim();
|
|
8288
|
-
for (const name of names) {
|
|
8289
|
-
if (!take(name, columns, resolved, problems) && !single) problems.fromList = true;
|
|
8290
|
-
}
|
|
8291
|
-
}
|
|
8292
|
-
if (problems.unknown.length > 0 || problems.ambiguous.length > 0) refuse(problems, columns, analysisId);
|
|
8293
|
-
return resolved;
|
|
8294
|
-
}
|
|
8295
|
-
function resolveColumnNames(names, columns, analysisId) {
|
|
8296
|
-
if (columns.length === 0) return [...names];
|
|
8297
|
-
const resolved = [];
|
|
8298
|
-
const problems = { unknown: [], ambiguous: [], fromList: false };
|
|
8299
|
-
for (const name of names) take(name, columns, resolved, problems);
|
|
8300
|
-
if (problems.unknown.length > 0 || problems.ambiguous.length > 0) refuse(problems, columns, analysisId);
|
|
8301
|
-
return resolved;
|
|
8302
|
-
}
|
|
8303
|
-
function resolveColumnArgument(given, columns, analysisId) {
|
|
8304
|
-
if (columns.length === 0) return given;
|
|
8305
|
-
return resolveColumnNames([given], columns, analysisId)[0];
|
|
8306
|
-
}
|
|
8307
|
-
function occurrences(value) {
|
|
8308
|
-
if (value === void 0) return void 0;
|
|
8309
|
-
return Array.isArray(value) ? value : [value];
|
|
9205
|
+
}
|
|
9206
|
+
if (parts.length === 0 && run.progressTotal && run.progressTotal > 0) {
|
|
9207
|
+
parts.push(`${formatNumber(run.progressDone ?? 0)} of ${formatNumber(run.progressTotal)} tasks`);
|
|
9208
|
+
} else if (parts.length === 0 && run.phaseFraction !== null && run.phaseFraction !== void 0) {
|
|
9209
|
+
parts.push(`${Math.round(run.phaseFraction * 100)}% of this step`);
|
|
9210
|
+
}
|
|
9211
|
+
return parts.length > 0 ? parts.join(" \xB7 ") : null;
|
|
8310
9212
|
}
|
|
8311
|
-
function
|
|
8312
|
-
|
|
9213
|
+
function renderWatchBlock(input) {
|
|
9214
|
+
const { run, elapsedMs, caption, budgetHours } = input;
|
|
9215
|
+
const lines = [];
|
|
9216
|
+
const step = stepCounter(run);
|
|
9217
|
+
const headline = [
|
|
9218
|
+
chalk27.cyan(SPINNER),
|
|
9219
|
+
chalk27.bold(phaseLabel(run)),
|
|
9220
|
+
step ? chalk27.dim(step) : null
|
|
9221
|
+
].filter(Boolean).join(" ");
|
|
9222
|
+
lines.push(` ${headline}`);
|
|
9223
|
+
const fraction = overallProgress(run);
|
|
9224
|
+
const elapsed = chalk27.dim(formatDurationPrecise(elapsedMs));
|
|
9225
|
+
if (fraction === null) {
|
|
9226
|
+
lines.push(` ${chalk27.dim("working")} ${elapsed}`);
|
|
9227
|
+
} else {
|
|
9228
|
+
const ceiling = remainingCeiling(run, budgetHours);
|
|
9229
|
+
lines.push(
|
|
9230
|
+
` ${bar(fraction)} ${percent(fraction)} ${elapsed}` + (ceiling !== null ? chalk27.dim(` \xB7 at most ${formatDurationPrecise(ceiling)} remaining`) : "")
|
|
9231
|
+
);
|
|
9232
|
+
}
|
|
9233
|
+
const detail2 = caption ?? phaseDetail(run);
|
|
9234
|
+
if (detail2) lines.push(` ${chalk27.dim(detail2)}`);
|
|
9235
|
+
if (run.retryAttempts && run.retryAttempts > 0) {
|
|
9236
|
+
lines.push(` ${chalk27.yellow("!")} ${chalk27.dim(
|
|
9237
|
+
`restarted ${run.retryAttempts === 1 ? "once" : `${run.retryAttempts} times`} after an interruption; progress restarts from the beginning`
|
|
9238
|
+
)}`);
|
|
9239
|
+
}
|
|
9240
|
+
return lines;
|
|
8313
9241
|
}
|
|
8314
9242
|
|
|
8315
9243
|
// src/commands/analyze/wizard.ts
|
|
8316
|
-
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
{
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
9244
|
+
import chalk28 from "chalk";
|
|
9245
|
+
var STARTING_DEPTH_RULE = "Defaults to the account's starting depth: Express (1 hour, 500 credits) until the account has a finished analysis, Standard (4 hours, 4,000 credits) afterwards.";
|
|
9246
|
+
function creditsLabel(budget) {
|
|
9247
|
+
const n = Number(budget);
|
|
9248
|
+
return `${Number.isFinite(n) ? n.toLocaleString("en-US") : budget} credits`;
|
|
9249
|
+
}
|
|
9250
|
+
function timeLabel(hours) {
|
|
9251
|
+
const h = Number(hours);
|
|
9252
|
+
if (!Number.isFinite(h) || h <= 0) return `${hours} hours`;
|
|
9253
|
+
const trim = (v) => Number.isInteger(v) ? v.toString() : (Math.round(v * 10) / 10).toString();
|
|
9254
|
+
if (h < 24) return h === 1 ? "1 hour" : `${trim(h)} hours`;
|
|
9255
|
+
const days = h / 24;
|
|
9256
|
+
if (days < 14) return days === 1 ? "1 day" : `${trim(Math.round(days * 10) / 10)} days`;
|
|
9257
|
+
return `${Math.round(days / 7)} weeks`;
|
|
9258
|
+
}
|
|
9259
|
+
function findDepth(depths, nameOrCredits) {
|
|
9260
|
+
const wanted = nameOrCredits.trim();
|
|
9261
|
+
const credits = wanted.replace(/[,_]/g, "");
|
|
9262
|
+
return depths.find((step) => step.name.toLowerCase() === wanted.toLowerCase() || step.budget === credits);
|
|
9263
|
+
}
|
|
8324
9264
|
function depthOf(hours, budget) {
|
|
8325
9265
|
const h = hours?.trim();
|
|
8326
9266
|
const b = budget?.trim();
|
|
8327
9267
|
return h && b ? { hours: h, budget: b } : null;
|
|
8328
9268
|
}
|
|
8329
|
-
async function promptCreationFields(prompter, supplied, fallbackName,
|
|
9269
|
+
async function promptCreationFields(prompter, supplied, fallbackName, licenses) {
|
|
8330
9270
|
const name = supplied.name ?? await prompter.input({
|
|
8331
9271
|
message: "Analysis name",
|
|
8332
9272
|
default: fallbackName,
|
|
@@ -8344,34 +9284,34 @@ async function promptCreationFields(prompter, supplied, fallbackName, licences)
|
|
|
8344
9284
|
]
|
|
8345
9285
|
});
|
|
8346
9286
|
const answers = { name: name.trim(), description: description.trim() || null, visibility };
|
|
8347
|
-
const
|
|
8348
|
-
if (
|
|
9287
|
+
const licenseId = supplied.licenceId ?? (visibility === "PUBLIC" && licenses ? await promptLicense(prompter, await licenses()) : void 0);
|
|
9288
|
+
if (licenseId) answers.licenceId = licenseId;
|
|
8349
9289
|
return answers;
|
|
8350
9290
|
}
|
|
8351
|
-
var
|
|
8352
|
-
async function
|
|
8353
|
-
const selectable =
|
|
9291
|
+
var ALL_LICENSES = ":all";
|
|
9292
|
+
async function promptLicense(prompter, catalog) {
|
|
9293
|
+
const selectable = catalog.filter((l) => l.state === "ACTIVE");
|
|
8354
9294
|
if (selectable.length === 0) return void 0;
|
|
8355
9295
|
const choice = (l) => ({ name: `${l.name} (${l.licenceId})`, value: l.licenceId, description: l.summary ?? void 0 });
|
|
8356
9296
|
const recommended = selectable.filter((l) => l.recommended);
|
|
8357
9297
|
const others = selectable.filter((l) => !l.recommended);
|
|
8358
9298
|
if (recommended.length === 0 || others.length === 0) {
|
|
8359
|
-
return prompter.select({ message: "
|
|
9299
|
+
return prompter.select({ message: "License", default: selectable[0].licenceId, choices: selectable.map(choice) });
|
|
8360
9300
|
}
|
|
8361
9301
|
const picked = await prompter.select({
|
|
8362
|
-
message: "
|
|
9302
|
+
message: "License",
|
|
8363
9303
|
default: recommended[0].licenceId,
|
|
8364
9304
|
choices: [
|
|
8365
9305
|
...recommended.map(choice),
|
|
8366
|
-
{ name: "Another
|
|
9306
|
+
{ name: "Another license\u2026", value: ALL_LICENSES, description: `${others.length} more in the catalog.` }
|
|
8367
9307
|
]
|
|
8368
9308
|
});
|
|
8369
|
-
if (picked !==
|
|
8370
|
-
return prompter.select({ message: "
|
|
9309
|
+
if (picked !== ALL_LICENSES) return picked;
|
|
9310
|
+
return prompter.select({ message: "License (all)", default: others[0].licenceId, choices: selectable.map(choice) });
|
|
8371
9311
|
}
|
|
8372
|
-
function matchDepthPreset(hours, budget) {
|
|
9312
|
+
function matchDepthPreset(depths, hours, budget) {
|
|
8373
9313
|
if (!hours || !budget) return null;
|
|
8374
|
-
return
|
|
9314
|
+
return depths.find((p) => p.hours === hours && p.budget === budget) ?? null;
|
|
8375
9315
|
}
|
|
8376
9316
|
function defaultTargets(columns) {
|
|
8377
9317
|
const named = columns.filter((c) => c.name && c.name.length > 0);
|
|
@@ -8386,6 +9326,7 @@ function positiveNumber(label) {
|
|
|
8386
9326
|
}
|
|
8387
9327
|
async function promptRunFields(prompter, options) {
|
|
8388
9328
|
const { columns, depthDefault } = options;
|
|
9329
|
+
const depths = options.depths ?? [];
|
|
8389
9330
|
const named = columns.filter((c) => c.name && c.name.length > 0);
|
|
8390
9331
|
let supplied = { ...options.supplied };
|
|
8391
9332
|
const nothingSupplied = supplied.targets === void 0 && supplied.segment === void 0 && supplied.questions === void 0 && supplied.hours === void 0 && supplied.budget === void 0;
|
|
@@ -8407,6 +9348,7 @@ async function promptRunFields(prompter, options) {
|
|
|
8407
9348
|
targets: preset.targets.length > 0 ? preset.targets : void 0,
|
|
8408
9349
|
questions: preset.questions.length > 0 ? preset.questions : void 0,
|
|
8409
9350
|
segment: preset.segmentKey ?? void 0,
|
|
9351
|
+
intent: supplied.intent,
|
|
8410
9352
|
hours: preset.time || void 0,
|
|
8411
9353
|
budget: preset.budget || void 0
|
|
8412
9354
|
};
|
|
@@ -8419,7 +9361,7 @@ async function promptRunFields(prompter, options) {
|
|
|
8419
9361
|
targets = await prompter.checkbox({
|
|
8420
9362
|
message: "Target columns: what should the analysis predict?",
|
|
8421
9363
|
choices: named.map((c) => ({
|
|
8422
|
-
name: c.valueType ? `${c.name} ${
|
|
9364
|
+
name: c.valueType ? `${c.name} ${chalk28.dim(`(${c.valueType})`)}` : c.name,
|
|
8423
9365
|
value: c.name,
|
|
8424
9366
|
checked: preselected.has(c.name)
|
|
8425
9367
|
})),
|
|
@@ -8448,7 +9390,7 @@ async function promptRunFields(prompter, options) {
|
|
|
8448
9390
|
choices: [
|
|
8449
9391
|
{ name: "No segmentation", value: null },
|
|
8450
9392
|
...remaining.map((c) => ({
|
|
8451
|
-
name: c.valueType ? `${c.name} ${
|
|
9393
|
+
name: c.valueType ? `${c.name} ${chalk28.dim(`(${c.valueType})`)}` : c.name,
|
|
8452
9394
|
value: c.name
|
|
8453
9395
|
}))
|
|
8454
9396
|
]
|
|
@@ -8473,19 +9415,27 @@ async function promptRunFields(prompter, options) {
|
|
|
8473
9415
|
questions = collected.length > 0 ? collected : null;
|
|
8474
9416
|
}
|
|
8475
9417
|
}
|
|
9418
|
+
let intent = supplied.intent ?? null;
|
|
9419
|
+
if (supplied.intent === void 0) {
|
|
9420
|
+
const typed2 = await prompter.input({
|
|
9421
|
+
message: "What you know and what matters (optional, private to you; blank to skip)",
|
|
9422
|
+
validate: (value) => value.length <= MAX_INTENT_LENGTH || `At most ${MAX_INTENT_LENGTH.toLocaleString("en-US")} characters; --intent-file takes longer notes.`
|
|
9423
|
+
});
|
|
9424
|
+
intent = typed2.trim() || null;
|
|
9425
|
+
}
|
|
8476
9426
|
let hours = supplied.hours;
|
|
8477
9427
|
let budget = supplied.budget;
|
|
8478
|
-
if (hours === void 0 && budget === void 0) {
|
|
9428
|
+
if (hours === void 0 && budget === void 0 && depths.length > 0) {
|
|
8479
9429
|
const chosen = await prompter.select({
|
|
8480
|
-
message: "Depth:
|
|
8481
|
-
default: matchDepthPreset(depthDefault?.hours, depthDefault?.budget) ?? void 0,
|
|
9430
|
+
message: "Depth: what may the analysis spend, and how long may it take?",
|
|
9431
|
+
default: matchDepthPreset(depths, depthDefault?.hours, depthDefault?.budget) ?? void 0,
|
|
8482
9432
|
choices: [
|
|
8483
|
-
...
|
|
8484
|
-
name: p.name,
|
|
9433
|
+
...depths.map((p) => ({
|
|
9434
|
+
name: `${p.name}: ${creditsLabel(p.budget)}, up to ${timeLabel(p.hours)}`,
|
|
8485
9435
|
value: p,
|
|
8486
|
-
description:
|
|
9436
|
+
description: p.longRun ? "A long analysis: it runs for days and shares the server. If the platform restarts, its search starts again; the interrupted attempt is not charged." : void 0
|
|
8487
9437
|
})),
|
|
8488
|
-
{ name: "Set your own", value: null }
|
|
9438
|
+
{ name: "Set your own time and credits", value: null }
|
|
8489
9439
|
]
|
|
8490
9440
|
});
|
|
8491
9441
|
if (chosen) {
|
|
@@ -8511,6 +9461,7 @@ async function promptRunFields(prompter, options) {
|
|
|
8511
9461
|
targets: targets ?? [],
|
|
8512
9462
|
segment,
|
|
8513
9463
|
questions,
|
|
9464
|
+
intent,
|
|
8514
9465
|
hours: hours.trim(),
|
|
8515
9466
|
budget: budget.trim()
|
|
8516
9467
|
};
|
|
@@ -8523,24 +9474,25 @@ function describePreset(preset) {
|
|
|
8523
9474
|
if (preset.segmentKey) parts.push(`segmented by ${preset.segmentKey}`);
|
|
8524
9475
|
return parts.join(" \xB7 ");
|
|
8525
9476
|
}
|
|
8526
|
-
function summaryLines(creation, run) {
|
|
9477
|
+
function summaryLines(creation, run, depths = []) {
|
|
8527
9478
|
const lines = [
|
|
8528
9479
|
`Name: ${creation.name}`,
|
|
8529
9480
|
`Visibility: ${creation.visibility === "PUBLIC" ? "Public" : "Private"}`
|
|
8530
9481
|
];
|
|
8531
|
-
if (creation.licenceId) lines.push(`
|
|
9482
|
+
if (creation.licenceId) lines.push(`License: ${creation.licenceId}`);
|
|
8532
9483
|
lines.push(`Targets: ${run.targets.join(", ")}`);
|
|
8533
9484
|
if (run.segment) lines.push(`Segment: ${run.segment}`);
|
|
8534
9485
|
if (run.questions && run.questions.length > 0) {
|
|
8535
9486
|
lines.push(`Questions: ${run.questions.length}`);
|
|
8536
9487
|
}
|
|
8537
|
-
lines.push(
|
|
9488
|
+
if (run.intent) lines.push("Notes: written (private to you)");
|
|
9489
|
+
lines.push(`Depth: ${depthLabel(run, depths)}`);
|
|
8538
9490
|
return lines;
|
|
8539
9491
|
}
|
|
8540
|
-
function depthLabel(depth) {
|
|
8541
|
-
const preset = matchDepthPreset(depth.hours, depth.budget);
|
|
9492
|
+
function depthLabel(depth, depths = []) {
|
|
9493
|
+
const preset = matchDepthPreset(depths, depth.hours, depth.budget);
|
|
8542
9494
|
const named = preset ? `${preset.name}, ` : "";
|
|
8543
|
-
return `${named}${depth.
|
|
9495
|
+
return `${named}${creditsLabel(depth.budget)}, up to ${timeLabel(depth.hours)}`;
|
|
8544
9496
|
}
|
|
8545
9497
|
function missingRunFields(recipe) {
|
|
8546
9498
|
const missing = [];
|
|
@@ -8555,7 +9507,8 @@ function suppliedFromAnalysis(analysis) {
|
|
|
8555
9507
|
hours: analysis.hours?.trim() ? analysis.hours : void 0,
|
|
8556
9508
|
budget: analysis.budget?.trim() ? analysis.budget : void 0,
|
|
8557
9509
|
segment: analysis.segment ?? null,
|
|
8558
|
-
questions: analysis.questions ?? null
|
|
9510
|
+
questions: analysis.questions ?? null,
|
|
9511
|
+
intent: analysis.intent ?? null
|
|
8559
9512
|
};
|
|
8560
9513
|
}
|
|
8561
9514
|
var FIELD_COMMANDS = {
|
|
@@ -8577,10 +9530,10 @@ function joinList(items) {
|
|
|
8577
9530
|
}
|
|
8578
9531
|
|
|
8579
9532
|
// src/prompting/prompter.ts
|
|
8580
|
-
var
|
|
9533
|
+
var PromptCanceled = class extends Error {
|
|
8581
9534
|
constructor() {
|
|
8582
|
-
super("
|
|
8583
|
-
this.name = "
|
|
9535
|
+
super("Canceled.");
|
|
9536
|
+
this.name = "PromptCanceled";
|
|
8584
9537
|
}
|
|
8585
9538
|
};
|
|
8586
9539
|
function createInquirerPrompter() {
|
|
@@ -8589,7 +9542,7 @@ function createInquirerPrompter() {
|
|
|
8589
9542
|
try {
|
|
8590
9543
|
return await work();
|
|
8591
9544
|
} catch (error) {
|
|
8592
|
-
if (error instanceof Error && error.name === "ExitPromptError") throw new
|
|
9545
|
+
if (error instanceof Error && error.name === "ExitPromptError") throw new PromptCanceled();
|
|
8593
9546
|
throw error;
|
|
8594
9547
|
}
|
|
8595
9548
|
};
|
|
@@ -8632,7 +9585,7 @@ function whyNoPrompt(outputFormat, noInteractive) {
|
|
|
8632
9585
|
}
|
|
8633
9586
|
|
|
8634
9587
|
// src/commands/analyze/data-import.ts
|
|
8635
|
-
import
|
|
9588
|
+
import chalk29 from "chalk";
|
|
8636
9589
|
|
|
8637
9590
|
// src/commands/analyze/details.ts
|
|
8638
9591
|
function analysisDetails(analysis, endpoint, verdict = null) {
|
|
@@ -8641,7 +9594,7 @@ function analysisDetails(analysis, endpoint, verdict = null) {
|
|
|
8641
9594
|
name: analysis.name,
|
|
8642
9595
|
description: analysis.description,
|
|
8643
9596
|
visibility: sentenceCase(analysis.visibility),
|
|
8644
|
-
|
|
9597
|
+
license: licenseText(analysis),
|
|
8645
9598
|
introduction: analysis.introduction,
|
|
8646
9599
|
data: dataShape(analysis.rowCount, analysis.columnCount),
|
|
8647
9600
|
dataImport: analysis.dataImport?.message ?? null,
|
|
@@ -8651,6 +9604,11 @@ function analysisDetails(analysis, endpoint, verdict = null) {
|
|
|
8651
9604
|
confirmedInputs: analysis.confirmedInputs,
|
|
8652
9605
|
questions: analysis.questions,
|
|
8653
9606
|
segment: analysis.segment,
|
|
9607
|
+
// The platform sends the notes to their owner only; for anyone else they are null and the line is empty.
|
|
9608
|
+
intent: analysis.intent ?? null,
|
|
9609
|
+
expectations: joinedLines(expectationLines(analysis.shapeExpectations)),
|
|
9610
|
+
charts: joinedLines((analysis.requestedPairs ?? []).map(pairText)),
|
|
9611
|
+
focus: joinedLines((analysis.focusFamilies ?? []).map(focusText)),
|
|
8654
9612
|
hours: hoursText(analysis.hours),
|
|
8655
9613
|
budget: creditsText(analysis.budget),
|
|
8656
9614
|
constraints: constraintsText(analysis),
|
|
@@ -8674,16 +9632,20 @@ function analysisDetails(analysis, endpoint, verdict = null) {
|
|
|
8674
9632
|
{ key: "name", header: "Name" },
|
|
8675
9633
|
{ key: "description", header: "Description" },
|
|
8676
9634
|
{ key: "visibility", header: "Visibility" },
|
|
8677
|
-
{ key: "
|
|
9635
|
+
{ key: "license", header: "License" },
|
|
8678
9636
|
{ key: "introduction", header: "Introduction" },
|
|
8679
9637
|
{ key: "data", header: "Data" },
|
|
8680
9638
|
{ key: "dataImport", header: "Data import" },
|
|
8681
9639
|
{ key: "targets", header: "Targets" },
|
|
8682
9640
|
{ key: "targetKinds", header: "Target kinds" },
|
|
8683
|
-
{ key: "inputExclusions", header: "Columns left out
|
|
9641
|
+
{ key: "inputExclusions", header: "Columns left out as inputs" },
|
|
8684
9642
|
{ key: "confirmedInputs", header: "Known before the target" },
|
|
8685
9643
|
{ key: "questions", header: "Questions" },
|
|
8686
9644
|
{ key: "segment", header: "Segment" },
|
|
9645
|
+
{ key: "intent", header: "Your notes" },
|
|
9646
|
+
{ key: "expectations", header: "Expectations" },
|
|
9647
|
+
{ key: "charts", header: "Charts you asked for" },
|
|
9648
|
+
{ key: "focus", header: "Focus" },
|
|
8687
9649
|
{ key: "hours", header: "Time limit" },
|
|
8688
9650
|
{ key: "budget", header: "Credit budget" },
|
|
8689
9651
|
{ key: "constraints", header: "Constraints" },
|
|
@@ -8703,7 +9665,10 @@ function analysisDetails(analysis, endpoint, verdict = null) {
|
|
|
8703
9665
|
];
|
|
8704
9666
|
return { data, columns };
|
|
8705
9667
|
}
|
|
8706
|
-
function
|
|
9668
|
+
function joinedLines(lines) {
|
|
9669
|
+
return lines.length > 0 ? lines.join("\n") : null;
|
|
9670
|
+
}
|
|
9671
|
+
function licenseText(analysis) {
|
|
8707
9672
|
if (analysis.licenceId) return analysis.licenceId;
|
|
8708
9673
|
return analysis.visibility === "PUBLIC" ? "none chosen" : null;
|
|
8709
9674
|
}
|
|
@@ -8732,7 +9697,7 @@ function dataShape(rows, columns) {
|
|
|
8732
9697
|
}
|
|
8733
9698
|
function qualityText(analysis, verdict) {
|
|
8734
9699
|
if (verdict?.validity === "not_valid") return "not shown: the result is not valid";
|
|
8735
|
-
const figure = analysis.heldOutQuality != null ? qualityPercent(analysis.heldOutQuality) : analysis.resultRunQuality != null ? `${qualityPercent(analysis.resultRunQuality)} on the training rows` : null;
|
|
9700
|
+
const figure = analysis.heldOutQuality != null ? qualityPercent(analysis.heldOutQuality) + rowsText(analysis.heldOutRows, analysis.searchRows) : analysis.resultRunQuality != null ? `${qualityPercent(analysis.resultRunQuality)} on the training rows` : null;
|
|
8736
9701
|
if (figure == null) return null;
|
|
8737
9702
|
return verdict?.validity === "needs_review" ? `${figure}, needs review` : figure;
|
|
8738
9703
|
}
|
|
@@ -8741,12 +9706,17 @@ function targetResultsText(analysis) {
|
|
|
8741
9706
|
if (results.length === 0) return null;
|
|
8742
9707
|
const lines = results.map((r) => {
|
|
8743
9708
|
const name = r.title ?? r.target ?? "target";
|
|
8744
|
-
return r.quality != null ? `${name}: ${qualityPercent(r.quality)}` : name;
|
|
9709
|
+
return r.quality != null ? `${name}: ${qualityPercent(r.quality)}${rowsText(r.heldOutRows, r.searchRows)}` : name;
|
|
8745
9710
|
});
|
|
8746
9711
|
const more = (analysis.targetResultCount ?? results.length) - results.length;
|
|
8747
9712
|
if (more > 0) lines.push(`and ${formatNumber(more)} more`);
|
|
8748
9713
|
return lines.join("\n");
|
|
8749
9714
|
}
|
|
9715
|
+
function rowsText(heldOutRows, searchRows) {
|
|
9716
|
+
if (heldOutRows == null || !(heldOutRows > 0)) return "";
|
|
9717
|
+
const measured = ` on ${formatNumber(heldOutRows)} held-out ${heldOutRows === 1 ? "row" : "rows"}`;
|
|
9718
|
+
return searchRows != null && searchRows > 0 ? `${measured}, found on ${formatNumber(searchRows)} ${searchRows === 1 ? "row" : "rows"}` : measured;
|
|
9719
|
+
}
|
|
8750
9720
|
function errorPercent(error) {
|
|
8751
9721
|
return `${formatNumber(Math.round(error * 1e3) / 10)}%`;
|
|
8752
9722
|
}
|
|
@@ -8765,12 +9735,12 @@ function constraintsText(analysis) {
|
|
|
8765
9735
|
var IMPORT_POLL_INTERVAL_MS = 2e3;
|
|
8766
9736
|
function renderImportBlock(dataImport, elapsedMs) {
|
|
8767
9737
|
const title = dataImport.state === "STOPPING" ? "Stopping the data import" : "Importing data";
|
|
8768
|
-
const lines = [` ${
|
|
8769
|
-
const elapsed =
|
|
9738
|
+
const lines = [` ${chalk29.cyan(SPINNER)} ${chalk29.bold(title)}`];
|
|
9739
|
+
const elapsed = chalk29.dim(formatDurationPrecise(elapsedMs));
|
|
8770
9740
|
if (dataImport.state === "IMPORTING" && dataImport.progress !== null && dataImport.progress !== void 0) {
|
|
8771
9741
|
lines.push(` ${bar(dataImport.progress)} ${percent(dataImport.progress)} ${elapsed}`);
|
|
8772
9742
|
} else {
|
|
8773
|
-
lines.push(` ${
|
|
9743
|
+
lines.push(` ${chalk29.dim(dataImport.message)} ${elapsed}`);
|
|
8774
9744
|
}
|
|
8775
9745
|
return lines;
|
|
8776
9746
|
}
|
|
@@ -8802,10 +9772,10 @@ async function followImport(ctx, first) {
|
|
|
8802
9772
|
try {
|
|
8803
9773
|
for (; ; ) {
|
|
8804
9774
|
if (ctx.live) status.set(renderImportBlock(current, Date.now() - since));
|
|
8805
|
-
const
|
|
8806
|
-
const woke = await Promise.race([
|
|
9775
|
+
const pause3 = sleep3(IMPORT_POLL_INTERVAL_MS);
|
|
9776
|
+
const woke = await Promise.race([pause3.done, interrupted]);
|
|
8807
9777
|
if (woke === "interrupted") {
|
|
8808
|
-
|
|
9778
|
+
pause3.cancel();
|
|
8809
9779
|
status.stop();
|
|
8810
9780
|
warn("Stopped waiting. The import keeps running on the platform.");
|
|
8811
9781
|
hint(`See how far it is with 'diafunc analyze get ${analysisId}'.`);
|
|
@@ -8938,7 +9908,7 @@ async function queueRun(api, analysisId) {
|
|
|
8938
9908
|
}
|
|
8939
9909
|
|
|
8940
9910
|
// src/commands/analyze/sources.ts
|
|
8941
|
-
import * as
|
|
9911
|
+
import * as fs11 from "fs";
|
|
8942
9912
|
import * as path8 from "path";
|
|
8943
9913
|
var CAUTIONS = /* @__PURE__ */ new Set([
|
|
8944
9914
|
"UNEVEN_COLUMNS",
|
|
@@ -9033,12 +10003,12 @@ function planLines(plan) {
|
|
|
9033
10003
|
}
|
|
9034
10004
|
function multipart(file) {
|
|
9035
10005
|
const formData = new FormData();
|
|
9036
|
-
formData.append("content", new Blob([
|
|
10006
|
+
formData.append("content", new Blob([fs11.readFileSync(file)]), path8.basename(file));
|
|
9037
10007
|
return formData;
|
|
9038
10008
|
}
|
|
9039
10009
|
async function uploadSeveral(api, analysisId, files, choices, human) {
|
|
9040
10010
|
for (const file of files) {
|
|
9041
|
-
if (!
|
|
10011
|
+
if (!fs11.existsSync(file)) {
|
|
9042
10012
|
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
9043
10013
|
}
|
|
9044
10014
|
}
|
|
@@ -9158,19 +10128,75 @@ function budgetHoursOf(hours) {
|
|
|
9158
10128
|
return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
|
|
9159
10129
|
}
|
|
9160
10130
|
function multipartFromFile(file) {
|
|
9161
|
-
const buffer =
|
|
10131
|
+
const buffer = fs12.readFileSync(file);
|
|
9162
10132
|
const blob = new Blob([buffer]);
|
|
9163
10133
|
const formData = new FormData();
|
|
9164
10134
|
formData.append("content", blob, path9.basename(file));
|
|
9165
10135
|
return formData;
|
|
9166
10136
|
}
|
|
9167
10137
|
function reportCommandError(error) {
|
|
9168
|
-
if (error instanceof
|
|
10138
|
+
if (error instanceof PromptCanceled) throw error;
|
|
9169
10139
|
handleError(error);
|
|
9170
10140
|
}
|
|
10141
|
+
var DEPTH_HELP = "A step of the depth ladder, by name or credits (for example standard, deep or 32000); not together with --hours and --budget";
|
|
10142
|
+
function launchIntentOf(options) {
|
|
10143
|
+
return {
|
|
10144
|
+
notes: notesFromOptions(options),
|
|
10145
|
+
shapes: shapesOf(options.shape),
|
|
10146
|
+
pairs: pairsOf(options.pair),
|
|
10147
|
+
focus: focusOf(options.focus)
|
|
10148
|
+
};
|
|
10149
|
+
}
|
|
10150
|
+
function creationIntent(launch) {
|
|
10151
|
+
const fields = {};
|
|
10152
|
+
if (launch.notes) fields.intent = launch.notes;
|
|
10153
|
+
if (launch.focus && launch.focus.length > 0) fields.focusFamilies = launch.focus;
|
|
10154
|
+
return fields;
|
|
10155
|
+
}
|
|
10156
|
+
async function saveLaunchFields(api, analysisId, columns, launch) {
|
|
10157
|
+
const names = columns.map((c) => c.name).filter((name) => name && name.length > 0);
|
|
10158
|
+
const pickUp = (what, command) => (error) => {
|
|
10159
|
+
const message = error instanceof ApiError ? error.toUserMessage() : error instanceof Error ? error.message : String(error);
|
|
10160
|
+
throw new CliError(message, {
|
|
10161
|
+
exitCode: error instanceof CliError ? error.exitCode : EXIT_FAILURE,
|
|
10162
|
+
hint: [
|
|
10163
|
+
error instanceof CliError ? error.hint : void 0,
|
|
10164
|
+
`Analysis ${analysisId} is created and holds the data. Set the ${what} with '${command}' and start it with 'diafunc analyze rerun ${analysisId}'.`
|
|
10165
|
+
].filter(Boolean).join("\n ")
|
|
10166
|
+
});
|
|
10167
|
+
};
|
|
10168
|
+
if (launch.shapes) {
|
|
10169
|
+
try {
|
|
10170
|
+
const byTarget = resolveShapeTargets(launch.shapes, names, analysisId);
|
|
10171
|
+
await withStatus("Saving the expectations", () => whenProfiled(
|
|
10172
|
+
() => api.analysis.patchShapeExpectations(analysisId, { byTarget })
|
|
10173
|
+
));
|
|
10174
|
+
} catch (error) {
|
|
10175
|
+
pickUp("expectations", `diafunc analyze expectations ${analysisId} --target <target> <statement...>`)(error);
|
|
10176
|
+
}
|
|
10177
|
+
}
|
|
10178
|
+
if (launch.pairs && launch.pairs.length > 0) {
|
|
10179
|
+
try {
|
|
10180
|
+
const pairs = resolvePairs(launch.pairs, names, analysisId);
|
|
10181
|
+
await withStatus("Saving the charts", () => api.analysis.patchRequestedPairs(analysisId, { pairs }));
|
|
10182
|
+
} catch (error) {
|
|
10183
|
+
pickUp("charts", `diafunc analyze charts ${analysisId} <first>,<second>[,<kind>]...`)(error);
|
|
10184
|
+
}
|
|
10185
|
+
}
|
|
10186
|
+
}
|
|
10187
|
+
async function readNotesUnattended(api, analysis, notes, outputFormat) {
|
|
10188
|
+
const reading = () => readNotes(api, analysis.analysisId, interpretRequestOf(analysis, notes));
|
|
10189
|
+
const interpretation = outputFormat === "human" ? await withStatus("Reading your notes", reading) : await reading();
|
|
10190
|
+
if (outputFormat !== "human") {
|
|
10191
|
+
process.stdout.write(JSON.stringify({ type: "intent", ...interpretation }) + "\n");
|
|
10192
|
+
return;
|
|
10193
|
+
}
|
|
10194
|
+
printInterpretation(interpretation, analysis.analysisId);
|
|
10195
|
+
console.log();
|
|
10196
|
+
}
|
|
9171
10197
|
async function runAnalysis(files, options, cmd) {
|
|
9172
10198
|
for (const candidate of files) {
|
|
9173
|
-
if (!
|
|
10199
|
+
if (!fs12.existsSync(candidate)) {
|
|
9174
10200
|
failure(`File not found: ${candidate}`);
|
|
9175
10201
|
process.exit(EXIT_FAILURE);
|
|
9176
10202
|
}
|
|
@@ -9179,7 +10205,9 @@ async function runAnalysis(files, options, cmd) {
|
|
|
9179
10205
|
const outputFormat = getOutputFormat17(cmd);
|
|
9180
10206
|
const noInteractive = noInteractiveFlag(cmd);
|
|
9181
10207
|
const interactive = canPrompt(outputFormat, noInteractive);
|
|
10208
|
+
const launch = launchIntentOf(options);
|
|
9182
10209
|
const api = createApiClient();
|
|
10210
|
+
applyDepthOption(options, options.depth === void 0 ? [] : await readDepths(api));
|
|
9183
10211
|
let presetTargets;
|
|
9184
10212
|
if (options.preset) {
|
|
9185
10213
|
const opt = await api.analysis.getPreset(options.preset);
|
|
@@ -9209,12 +10237,12 @@ async function runAnalysis(files, options, cmd) {
|
|
|
9209
10237
|
name: options.name,
|
|
9210
10238
|
description: options.description,
|
|
9211
10239
|
visibility: options.visibility === void 0 ? void 0 : parseVisibility(options.visibility),
|
|
9212
|
-
licenceId: options.
|
|
9213
|
-
}, fallbackName, () => api.admin.
|
|
10240
|
+
licenceId: options.license
|
|
10241
|
+
}, fallbackName, () => api.admin.listLicenses()) : {
|
|
9214
10242
|
name: options.name ?? fallbackName,
|
|
9215
10243
|
description: options.description?.trim() || null,
|
|
9216
10244
|
visibility: options.visibility === void 0 ? "PRIVATE" : parseVisibility(options.visibility),
|
|
9217
|
-
licenceId: options.
|
|
10245
|
+
licenceId: options.license
|
|
9218
10246
|
};
|
|
9219
10247
|
const request = {
|
|
9220
10248
|
name: creation.name,
|
|
@@ -9230,6 +10258,7 @@ async function runAnalysis(files, options, cmd) {
|
|
|
9230
10258
|
};
|
|
9231
10259
|
const created = await withStatus(`Creating analysis "${creation.name}"`, () => api.analysis.create({
|
|
9232
10260
|
...request,
|
|
10261
|
+
...creationIntent(launch),
|
|
9233
10262
|
...creation.licenceId ? { licenceId: creation.licenceId } : {}
|
|
9234
10263
|
}));
|
|
9235
10264
|
if (isDryRun()) {
|
|
@@ -9249,7 +10278,7 @@ async function runAnalysis(files, options, cmd) {
|
|
|
9249
10278
|
}
|
|
9250
10279
|
);
|
|
9251
10280
|
}
|
|
9252
|
-
detail(`depth: ${depthLabel(stored)}${created.depthPreselection ? " (the account's starting depth)" : ""}`);
|
|
10281
|
+
detail(`depth: ${depthLabel(stored, await readDepths(api))}${created.depthPreselection ? " (the account's starting depth)" : ""}`);
|
|
9253
10282
|
}
|
|
9254
10283
|
await sendData(importContext(api, created.analysisId, cmd, "stream"), () => files.length > 1 ? uploadSeveral(api, created.analysisId, files, stackChoices(options, files), outputFormat === "human") : uploadOne(api, created.analysisId, file, asUploadedOf(options.asUploaded, files), outputFormat === "human"));
|
|
9255
10284
|
const columns = await readColumns(api, created.analysisId);
|
|
@@ -9265,17 +10294,23 @@ async function runAnalysis(files, options, cmd) {
|
|
|
9265
10294
|
targets: named.targets,
|
|
9266
10295
|
segment: named.segment,
|
|
9267
10296
|
questions: options.question === void 0 ? void 0 : questionsOf(options.question),
|
|
10297
|
+
intent: launch.notes === void 0 ? void 0 : launch.notes || null,
|
|
9268
10298
|
hours: options.hours,
|
|
9269
10299
|
budget: options.budget
|
|
9270
|
-
}, columns, creation.licenceId);
|
|
10300
|
+
}, columns, creation.licenceId, { launch, storedNotes: launch.notes || null });
|
|
9271
10301
|
if (configuredHours === null) return;
|
|
9272
10302
|
runHours = configuredHours;
|
|
9273
10303
|
} else {
|
|
9274
|
-
await withStatus("Saving the analysis settings", () => api.analysis.update(created.analysisId, {
|
|
10304
|
+
const saved = await withStatus("Saving the analysis settings", () => api.analysis.update(created.analysisId, {
|
|
9275
10305
|
...recipe,
|
|
9276
10306
|
targets: named.targets ?? null,
|
|
9277
10307
|
segment: named.segment ?? null
|
|
9278
10308
|
}));
|
|
10309
|
+
await saveLaunchFields(api, created.analysisId, columns, launch);
|
|
10310
|
+
if (launch.notes) {
|
|
10311
|
+
await readNotesUnattended(api, { ...created, ...saved, analysisId: created.analysisId }, launch.notes, outputFormat);
|
|
10312
|
+
if (outputFormat === "human") hint(`Confirmed proposals take part from the next run: 'diafunc analyze rerun ${created.analysisId}'.`);
|
|
10313
|
+
}
|
|
9279
10314
|
}
|
|
9280
10315
|
const run = await withStatus("Queuing analysis run", () => queueRun(api, created.analysisId));
|
|
9281
10316
|
detail(`runId: ${run.runId}`);
|
|
@@ -9306,13 +10341,14 @@ function namedColumns(analysisId, columns, interactive, given) {
|
|
|
9306
10341
|
const segment = given.segment === void 0 || given.segment === "" ? void 0 : read(() => resolveColumnArgument(given.segment, names, analysisId));
|
|
9307
10342
|
return { targets, segment };
|
|
9308
10343
|
}
|
|
9309
|
-
async function configureInteractively(api, prompter, analysisId, recipe, supplied, knownColumns, licenceId) {
|
|
10344
|
+
async function configureInteractively(api, prompter, analysisId, recipe, supplied, knownColumns, licenceId, fromCommandLine) {
|
|
9310
10345
|
const columns = knownColumns ?? await readColumns(api, analysisId);
|
|
9311
10346
|
const presets = await readPresets(api);
|
|
9312
10347
|
const depthAsked = supplied.hours === void 0 || supplied.budget === void 0;
|
|
9313
10348
|
const depthDefault = depthAsked ? await readDepthDefault(api, recipe) : null;
|
|
10349
|
+
const depths = await readDepths(api);
|
|
9314
10350
|
console.log();
|
|
9315
|
-
const answers = await promptRunFields(prompter, { columns, presets, supplied, depthDefault });
|
|
10351
|
+
const answers = await promptRunFields(prompter, { columns, presets, supplied, depthDefault, depths });
|
|
9316
10352
|
console.log();
|
|
9317
10353
|
const saved = await withStatus("Saving the analysis settings", () => api.analysis.update(analysisId, {
|
|
9318
10354
|
...recipe,
|
|
@@ -9322,6 +10358,16 @@ async function configureInteractively(api, prompter, analysisId, recipe, supplie
|
|
|
9322
10358
|
hours: answers.hours,
|
|
9323
10359
|
budget: answers.budget
|
|
9324
10360
|
}));
|
|
10361
|
+
const recipeNow = await settleNotes(
|
|
10362
|
+
api,
|
|
10363
|
+
prompter,
|
|
10364
|
+
analysisId,
|
|
10365
|
+
saved,
|
|
10366
|
+
columns,
|
|
10367
|
+
answers.intent,
|
|
10368
|
+
fromCommandLine ?? { launch: null, storedNotes: supplied.intent ?? null },
|
|
10369
|
+
{ targets: answers.targets, segment: answers.segment }
|
|
10370
|
+
);
|
|
9325
10371
|
console.log();
|
|
9326
10372
|
heading("Ready to run");
|
|
9327
10373
|
const identity = {
|
|
@@ -9331,7 +10377,8 @@ async function configureInteractively(api, prompter, analysisId, recipe, supplie
|
|
|
9331
10377
|
...licenceId ? { licenceId } : {}
|
|
9332
10378
|
};
|
|
9333
10379
|
const depth = depthOf(saved?.hours, saved?.budget) ?? { hours: answers.hours, budget: answers.budget };
|
|
9334
|
-
for (const line of summaryLines(identity, { ...answers, ...depth })) detail(line);
|
|
10380
|
+
for (const line of summaryLines(identity, { ...answers, ...depth }, depths)) detail(line);
|
|
10381
|
+
for (const line of intentRecipeLines(recipeNow ?? {})) detail(line);
|
|
9335
10382
|
console.log();
|
|
9336
10383
|
if (!await prompter.confirm({ message: "Start the analysis?", default: true })) {
|
|
9337
10384
|
warn("Not started. The analysis and these settings are saved.");
|
|
@@ -9340,6 +10387,65 @@ async function configureInteractively(api, prompter, analysisId, recipe, supplie
|
|
|
9340
10387
|
}
|
|
9341
10388
|
return depth.hours;
|
|
9342
10389
|
}
|
|
10390
|
+
async function settleNotes(api, prompter, analysisId, saved, columns, notes, given, setup) {
|
|
10391
|
+
let touched = false;
|
|
10392
|
+
if (given.launch && (given.launch.shapes || (given.launch.pairs?.length ?? 0) > 0)) {
|
|
10393
|
+
await saveLaunchFields(api, analysisId, columns, given.launch);
|
|
10394
|
+
touched = true;
|
|
10395
|
+
}
|
|
10396
|
+
if (notes && notes !== given.storedNotes) {
|
|
10397
|
+
await withStatus("Saving your notes", () => api.analysis.patchIntent(analysisId, { intent: notes }));
|
|
10398
|
+
}
|
|
10399
|
+
if (notes && !isDryRun()) {
|
|
10400
|
+
const base = { ...saved, analysisId, targets: saved?.targets ?? setup.targets, segment: saved?.segment ?? setup.segment };
|
|
10401
|
+
const interpretation = await withStatus("Reading your notes", () => readNotes(api, analysisId, interpretRequestOf(base, notes)));
|
|
10402
|
+
if (interpretation.status !== "READY") {
|
|
10403
|
+
printInterpretation(interpretation, analysisId);
|
|
10404
|
+
} else {
|
|
10405
|
+
printUnavailable(interpretation);
|
|
10406
|
+
for (const note of [...interpretation.notUnderstood ?? [], ...interpretation.rejections ?? []]) {
|
|
10407
|
+
warn(`Not used: "${note.quote}"${note.reason ? `: ${note.reason}` : ""}`);
|
|
10408
|
+
}
|
|
10409
|
+
const decisions = await promptIntentDecisions(prompter, interpretation);
|
|
10410
|
+
if (decisions.length > 0) {
|
|
10411
|
+
await withStatus("Saving your decisions", () => api.analysis.decideIntentItems(analysisId, { decisions }));
|
|
10412
|
+
touched = true;
|
|
10413
|
+
}
|
|
10414
|
+
}
|
|
10415
|
+
}
|
|
10416
|
+
if (!touched || isDryRun()) return saved;
|
|
10417
|
+
try {
|
|
10418
|
+
return (await api.analysis.get(analysisId)).analysis ?? saved;
|
|
10419
|
+
} catch (error) {
|
|
10420
|
+
if (isAuthenticationFailure(error)) throw error;
|
|
10421
|
+
return saved;
|
|
10422
|
+
}
|
|
10423
|
+
}
|
|
10424
|
+
async function readDepths(api) {
|
|
10425
|
+
try {
|
|
10426
|
+
return await api.analysis.getDepths() ?? [];
|
|
10427
|
+
} catch {
|
|
10428
|
+
return [];
|
|
10429
|
+
}
|
|
10430
|
+
}
|
|
10431
|
+
function applyDepthOption(options, depths) {
|
|
10432
|
+
if (options.depth === void 0) return;
|
|
10433
|
+
if (options.hours !== void 0 || options.budget !== void 0) {
|
|
10434
|
+
usageError("Name a depth with --depth, or a time limit and a credit budget with --hours and --budget, not both.");
|
|
10435
|
+
}
|
|
10436
|
+
if (depths.length === 0) {
|
|
10437
|
+
usageError("The depths could not be read from the platform.", "Pass --hours and --budget instead.");
|
|
10438
|
+
}
|
|
10439
|
+
const step = findDepth(depths, options.depth);
|
|
10440
|
+
if (!step) {
|
|
10441
|
+
usageError(
|
|
10442
|
+
`There is no depth '${options.depth}'.`,
|
|
10443
|
+
`Name one of ${depths.map((d) => d.name).join(", ")}, or its credits (for example --depth 4000).`
|
|
10444
|
+
);
|
|
10445
|
+
}
|
|
10446
|
+
options.hours = step.hours;
|
|
10447
|
+
options.budget = step.budget;
|
|
10448
|
+
}
|
|
9343
10449
|
async function readDepthDefault(api, stored) {
|
|
9344
10450
|
try {
|
|
9345
10451
|
const answer = await api.analysis.getDepthDefault();
|
|
@@ -9539,7 +10645,11 @@ async function getAnalysisDetails(analysisId, options, cmd) {
|
|
|
9539
10645
|
format(result.analysis, { format: outputFormat });
|
|
9540
10646
|
return;
|
|
9541
10647
|
}
|
|
9542
|
-
const analysis = options.full ? result.analysis : {
|
|
10648
|
+
const analysis = options.full ? result.analysis : {
|
|
10649
|
+
...result.analysis,
|
|
10650
|
+
introduction: abbreviate(result.analysis.introduction),
|
|
10651
|
+
intent: abbreviate(result.analysis.intent ?? null)
|
|
10652
|
+
};
|
|
9543
10653
|
const config = loadConfig();
|
|
9544
10654
|
const endpoint = config.profiles[config.currentProfile]?.endpoint ?? "https://diafunc.com";
|
|
9545
10655
|
const details = analysisDetails(analysis, endpoint, await resultVerdict(api, result.analysis));
|
|
@@ -9547,6 +10657,9 @@ async function getAnalysisDetails(analysisId, options, cmd) {
|
|
|
9547
10657
|
if (!options.full && isLong(result.analysis.introduction)) {
|
|
9548
10658
|
hint("Introduction abbreviated. Pass --full to print it whole.");
|
|
9549
10659
|
}
|
|
10660
|
+
if (!options.full && isLong(result.analysis.intent ?? null)) {
|
|
10661
|
+
hint("Your notes abbreviated. Pass --full, or run 'diafunc analyze intent " + result.analysis.analysisId + "', to print them whole.");
|
|
10662
|
+
}
|
|
9550
10663
|
}
|
|
9551
10664
|
async function resultVerdict(api, analysis) {
|
|
9552
10665
|
if (!analysis.resultRunId) return null;
|
|
@@ -9665,13 +10778,29 @@ async function openAnalysis(analysisId) {
|
|
|
9665
10778
|
hint("The notebook is not available yet. Run the analysis first.");
|
|
9666
10779
|
}
|
|
9667
10780
|
}
|
|
10781
|
+
function windowedShapes(shapes) {
|
|
10782
|
+
if (!shapes) return null;
|
|
10783
|
+
for (const statement of Object.values(shapes).flat()) {
|
|
10784
|
+
const args = /\((.*)\)\s*$/.exec(statement)?.[1].split(",") ?? [];
|
|
10785
|
+
if (!/range\s*\(/i.test(statement) && args.length !== 3) {
|
|
10786
|
+
usageError(
|
|
10787
|
+
`'${statement}' has no window, and an analysis without data has no observed range to bind it to.`,
|
|
10788
|
+
"Give the window, for example increasing(size_m2, 20, 200), or set the expectation after the upload with 'diafunc analyze expectations <id> --target <target> <statement...>'."
|
|
10789
|
+
);
|
|
10790
|
+
}
|
|
10791
|
+
}
|
|
10792
|
+
return shapes;
|
|
10793
|
+
}
|
|
9668
10794
|
function typedColumns(given) {
|
|
9669
10795
|
const entries = occurrences(given);
|
|
9670
10796
|
return entries === void 0 ? null : resolveColumnArguments(entries, []);
|
|
9671
10797
|
}
|
|
9672
10798
|
async function createAnalysis(options, cmd) {
|
|
9673
10799
|
const outputFormat = getOutputFormat17(cmd);
|
|
10800
|
+
const launch = launchIntentOf(options);
|
|
10801
|
+
const shapes = windowedShapes(launch.shapes);
|
|
9674
10802
|
const api = createApiClient();
|
|
10803
|
+
applyDepthOption(options, options.depth === void 0 ? [] : await readDepths(api));
|
|
9675
10804
|
const visibility = parseVisibility(options.visibility);
|
|
9676
10805
|
const request = {
|
|
9677
10806
|
name: options.name ?? "CLI Analysis",
|
|
@@ -9685,13 +10814,19 @@ async function createAnalysis(options, cmd) {
|
|
|
9685
10814
|
};
|
|
9686
10815
|
const created = await api.analysis.create({
|
|
9687
10816
|
...request,
|
|
9688
|
-
...
|
|
10817
|
+
...creationIntent(launch),
|
|
10818
|
+
...shapes ? { shapeExpectations: shapes } : {},
|
|
10819
|
+
...launch.pairs && launch.pairs.length > 0 ? { requestedPairs: launch.pairs } : {},
|
|
10820
|
+
...options.license ? { licenceId: options.license } : {}
|
|
9689
10821
|
});
|
|
9690
10822
|
if (isDryRun()) {
|
|
9691
10823
|
hint("Dry run: nothing was created.");
|
|
9692
10824
|
return;
|
|
9693
10825
|
}
|
|
9694
10826
|
format(created, { format: outputFormat });
|
|
10827
|
+
if (launch.notes && outputFormat === "human") {
|
|
10828
|
+
hint(`Your notes are stored. Read them into proposals once the data is uploaded: 'diafunc analyze intent read ${created.analysisId}'.`);
|
|
10829
|
+
}
|
|
9695
10830
|
}
|
|
9696
10831
|
async function deleteAnalysis(analysisId) {
|
|
9697
10832
|
const api = createApiClient();
|
|
@@ -9724,6 +10859,223 @@ async function patchColumns(analysisId, given, send, successLabel, cmd) {
|
|
|
9724
10859
|
const columns = resolveColumnArguments(occurrences(given) ?? [], await columnNames(api, analysisId), analysisId);
|
|
9725
10860
|
await patchAndPrint(analysisId, "", () => send(api, columns), successLabel, cmd);
|
|
9726
10861
|
}
|
|
10862
|
+
async function ownAnalysis(api, analysisId) {
|
|
10863
|
+
const found = await api.analysis.get(analysisId);
|
|
10864
|
+
if (!found.analysis) {
|
|
10865
|
+
failure(`Analysis not found: ${analysisId}`);
|
|
10866
|
+
process.exit(EXIT_FAILURE);
|
|
10867
|
+
}
|
|
10868
|
+
return found.analysis;
|
|
10869
|
+
}
|
|
10870
|
+
async function notesCommand(analysisId, text2, options, cmd) {
|
|
10871
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
10872
|
+
const api = createApiClient();
|
|
10873
|
+
const given = [text2 !== void 0, options.file !== void 0, options.clear === true].filter(Boolean).length;
|
|
10874
|
+
if (given > 1) usageError("Give the notes as text, with --file, or clear them with --clear: one of the three.");
|
|
10875
|
+
if (given === 0) {
|
|
10876
|
+
const analysis = await ownAnalysis(api, analysisId);
|
|
10877
|
+
if (outputFormat !== "human") {
|
|
10878
|
+
format({ analysisId, intent: analysis.intent ?? null }, { format: outputFormat });
|
|
10879
|
+
return;
|
|
10880
|
+
}
|
|
10881
|
+
if (!analysis.intent) {
|
|
10882
|
+
empty("notes");
|
|
10883
|
+
hint(`Write them with 'diafunc analyze intent ${analysisId} "<text>"'. Only you can read them.`);
|
|
10884
|
+
return;
|
|
10885
|
+
}
|
|
10886
|
+
console.log(analysis.intent);
|
|
10887
|
+
hint(`Only you can read these notes. Read them into proposals with 'diafunc analyze intent read ${analysisId}'.`);
|
|
10888
|
+
return;
|
|
10889
|
+
}
|
|
10890
|
+
let notes;
|
|
10891
|
+
if (options.clear) {
|
|
10892
|
+
notes = null;
|
|
10893
|
+
} else if (options.file !== void 0) {
|
|
10894
|
+
notes = notesFromOptions({ intentFile: options.file }) || null;
|
|
10895
|
+
} else {
|
|
10896
|
+
checkNotesLength(text2);
|
|
10897
|
+
notes = text2.trim() || null;
|
|
10898
|
+
}
|
|
10899
|
+
const updated = await api.analysis.patchIntent(analysisId, { intent: notes });
|
|
10900
|
+
if (isDryRun()) {
|
|
10901
|
+
hint("Dry run: nothing was changed.");
|
|
10902
|
+
return;
|
|
10903
|
+
}
|
|
10904
|
+
if (outputFormat !== "human") {
|
|
10905
|
+
format(updated, { format: outputFormat });
|
|
10906
|
+
return;
|
|
10907
|
+
}
|
|
10908
|
+
if (notes === null) {
|
|
10909
|
+
success(`Notes cleared for analysis ${analysisId}.`);
|
|
10910
|
+
hint("Proposals you confirmed earlier stay in place until you decline them.");
|
|
10911
|
+
return;
|
|
10912
|
+
}
|
|
10913
|
+
success(`Notes saved for analysis ${analysisId}. Only you can read them.`);
|
|
10914
|
+
hint(`Read them into proposals with 'diafunc analyze intent read ${analysisId}'. Nothing changes until you confirm one.`);
|
|
10915
|
+
}
|
|
10916
|
+
async function readNotesCommand(analysisId, options, cmd) {
|
|
10917
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
10918
|
+
const api = createApiClient();
|
|
10919
|
+
const analysis = await ownAnalysis(api, analysisId);
|
|
10920
|
+
if (!analysis.intent) {
|
|
10921
|
+
if (outputFormat !== "human") {
|
|
10922
|
+
format(
|
|
10923
|
+
{ status: "EMPTY", hash: null, derivedAt: null, items: [], notUnderstood: [], rejections: [], findings: [] },
|
|
10924
|
+
{ format: outputFormat }
|
|
10925
|
+
);
|
|
10926
|
+
return;
|
|
10927
|
+
}
|
|
10928
|
+
empty("notes");
|
|
10929
|
+
hint(`Write them first with 'diafunc analyze intent ${analysisId} "<text>"'.`);
|
|
10930
|
+
return;
|
|
10931
|
+
}
|
|
10932
|
+
const reading = () => readNotes(
|
|
10933
|
+
api,
|
|
10934
|
+
analysisId,
|
|
10935
|
+
interpretRequestOf(analysis, analysis.intent),
|
|
10936
|
+
{ force: options.force, refine: options.refine }
|
|
10937
|
+
);
|
|
10938
|
+
const interpretation = outputFormat === "human" ? await withStatus("Reading your notes", reading) : await reading();
|
|
10939
|
+
if (isDryRun()) {
|
|
10940
|
+
hint("Dry run: the notes were not read.");
|
|
10941
|
+
return;
|
|
10942
|
+
}
|
|
10943
|
+
if (outputFormat !== "human") {
|
|
10944
|
+
format(interpretation, { format: outputFormat });
|
|
10945
|
+
return;
|
|
10946
|
+
}
|
|
10947
|
+
printInterpretation(interpretation, analysisId);
|
|
10948
|
+
}
|
|
10949
|
+
async function decideCommand(state, analysisId, ids, options, cmd) {
|
|
10950
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
10951
|
+
const wanted = [...new Set(ids.flatMap((id) => id.split(",")).map((id) => id.trim()).filter((id) => id.length > 0))];
|
|
10952
|
+
if (wanted.length === 0) usageError("Name at least one proposal.", `The ids are in 'diafunc analyze intent read ${analysisId}'.`);
|
|
10953
|
+
if (options.steer !== void 0 && state !== "CONFIRMED") {
|
|
10954
|
+
usageError("--steer and --no-steer go with confirm only.");
|
|
10955
|
+
}
|
|
10956
|
+
const api = createApiClient();
|
|
10957
|
+
const stored = await api.analysis.getIntentInterpretation(analysisId);
|
|
10958
|
+
const known = new Map((stored.items ?? []).map((item) => [item.id, item]));
|
|
10959
|
+
const unknown = wanted.filter((id) => !known.has(id));
|
|
10960
|
+
if (unknown.length > 0) {
|
|
10961
|
+
usageError(
|
|
10962
|
+
`${unknown.map((id) => `'${id}'`).join(", ")} ${unknown.length === 1 ? "is not a proposal" : "are not proposals"} of analysis ${analysisId}.`,
|
|
10963
|
+
`List the proposals with 'diafunc analyze intent read ${analysisId}'.`
|
|
10964
|
+
);
|
|
10965
|
+
}
|
|
10966
|
+
if (options.steer !== void 0) {
|
|
10967
|
+
const notExpectations = wanted.filter((id) => known.get(id)?.effect !== "checks");
|
|
10968
|
+
if (notExpectations.length > 0) {
|
|
10969
|
+
usageError(`Only an expectation can steer the model; ${notExpectations.map((id) => `'${id}'`).join(", ")} ${notExpectations.length === 1 ? "is" : "are"} not one.`);
|
|
10970
|
+
}
|
|
10971
|
+
}
|
|
10972
|
+
const decisions = wanted.map((id) => ({ id, state, steer: options.steer ?? null }));
|
|
10973
|
+
const decided = await api.analysis.decideIntentItems(analysisId, { decisions });
|
|
10974
|
+
if (isDryRun()) {
|
|
10975
|
+
hint("Dry run: nothing was changed.");
|
|
10976
|
+
return;
|
|
10977
|
+
}
|
|
10978
|
+
if (outputFormat !== "human") {
|
|
10979
|
+
format(decided, { format: outputFormat });
|
|
10980
|
+
return;
|
|
10981
|
+
}
|
|
10982
|
+
const verb = state === "CONFIRMED" ? "Using" : state === "DECLINED" ? "Not using" : "Open again:";
|
|
10983
|
+
for (const item of (decided.items ?? []).filter((i) => wanted.includes(i.id))) {
|
|
10984
|
+
success(`${verb} ${item.id}: ${item.statement}`);
|
|
10985
|
+
}
|
|
10986
|
+
if (state === "CONFIRMED") hint(`It takes part from the next run: 'diafunc analyze rerun ${analysisId}'.`);
|
|
10987
|
+
}
|
|
10988
|
+
async function expectationsCommand(analysisId, given, options, cmd) {
|
|
10989
|
+
const outputFormat = getOutputFormat17(cmd);
|
|
10990
|
+
const api = createApiClient();
|
|
10991
|
+
const analysis = await ownAnalysis(api, analysisId);
|
|
10992
|
+
const current = analysis.shapeExpectations ?? {};
|
|
10993
|
+
const statements = given.filter((g) => g.trim().length > 0);
|
|
10994
|
+
if (options.clear && statements.length > 0) usageError("Give statements or --clear, not both.");
|
|
10995
|
+
if (!options.clear && statements.length === 0) {
|
|
10996
|
+
const shown = options.target === void 0 ? current : Object.fromEntries(Object.entries(current).filter(([target]) => target === options.target));
|
|
10997
|
+
if (outputFormat !== "human") {
|
|
10998
|
+
format({ analysisId, shapeExpectations: shown }, { format: outputFormat });
|
|
10999
|
+
return;
|
|
11000
|
+
}
|
|
11001
|
+
const lines = expectationLines(shown);
|
|
11002
|
+
if (lines.length === 0) {
|
|
11003
|
+
empty("expectations");
|
|
11004
|
+
hint(`Set one with 'diafunc analyze expectations ${analysisId} --target <target> "increasing(<input>)"'.`);
|
|
11005
|
+
return;
|
|
11006
|
+
}
|
|
11007
|
+
for (const line of lines) console.log(line);
|
|
11008
|
+
hint("An expectation is checked and reported; one written with require: also steers the model.");
|
|
11009
|
+
return;
|
|
11010
|
+
}
|
|
11011
|
+
const columns = await columnNames(api, analysisId);
|
|
11012
|
+
const targetOf = (typed2) => resolveColumnArgument(typed2, columns, analysisId);
|
|
11013
|
+
const byTarget = Object.fromEntries(Object.entries(current).map(([t, s]) => [t, [...s]]));
|
|
11014
|
+
if (options.clear) {
|
|
11015
|
+
if (options.target === void 0) {
|
|
11016
|
+
for (const target of Object.keys(byTarget)) delete byTarget[target];
|
|
11017
|
+
} else {
|
|
11018
|
+
delete byTarget[targetOf(options.target)];
|
|
11019
|
+
}
|
|
11020
|
+
} else {
|
|
11021
|
+
const named = {};
|
|
11022
|
+
for (const entry of statements) {
|
|
11023
|
+
let target;
|
|
11024
|
+
let statement;
|
|
11025
|
+
if (options.target !== void 0) {
|
|
11026
|
+
target = targetOf(options.target);
|
|
11027
|
+
statement = checkedStatement(entry);
|
|
11028
|
+
} else if (entry.includes("=")) {
|
|
11029
|
+
const read = parseShapeFlag(entry);
|
|
11030
|
+
target = targetOf(read.target);
|
|
11031
|
+
statement = read.statement;
|
|
11032
|
+
} else if ((analysis.targets ?? []).length === 1) {
|
|
11033
|
+
target = analysis.targets[0];
|
|
11034
|
+
statement = checkedStatement(entry);
|
|
11035
|
+
} else {
|
|
11036
|
+
usageError(
|
|
11037
|
+
`'${entry}' names no target, and the analysis has ${(analysis.targets ?? []).length === 0 ? "none yet" : "several"}.`,
|
|
11038
|
+
`Pass --target <target>, or write <target>=<statement>.`
|
|
11039
|
+
);
|
|
11040
|
+
}
|
|
11041
|
+
named[target] ??= [];
|
|
11042
|
+
if (!named[target].includes(statement)) named[target].push(statement);
|
|
11043
|
+
}
|
|
11044
|
+
Object.assign(byTarget, named);
|
|
11045
|
+
}
|
|
11046
|
+
const updated = await api.analysis.patchShapeExpectations(analysisId, { byTarget });
|
|
11047
|
+
if (isDryRun()) {
|
|
11048
|
+
hint("Dry run: nothing was changed.");
|
|
11049
|
+
return;
|
|
11050
|
+
}
|
|
11051
|
+
if (outputFormat !== "human") {
|
|
11052
|
+
format(updated, { format: outputFormat });
|
|
11053
|
+
return;
|
|
11054
|
+
}
|
|
11055
|
+
success(`Expectations updated for analysis ${analysisId}.`);
|
|
11056
|
+
for (const line of expectationLines(updated?.shapeExpectations)) detail(line);
|
|
11057
|
+
}
|
|
11058
|
+
async function chartsCommand(analysisId, given, cmd) {
|
|
11059
|
+
const api = createApiClient();
|
|
11060
|
+
const pairs = resolvePairs(pairsOf(given) ?? [], await columnNames(api, analysisId), analysisId);
|
|
11061
|
+
await patchAndPrint(
|
|
11062
|
+
analysisId,
|
|
11063
|
+
pairs.map(pairText).join("; "),
|
|
11064
|
+
() => api.analysis.patchRequestedPairs(analysisId, { pairs }),
|
|
11065
|
+
"Charts",
|
|
11066
|
+
cmd
|
|
11067
|
+
);
|
|
11068
|
+
}
|
|
11069
|
+
async function focusCommand(analysisId, given, cmd) {
|
|
11070
|
+
const families = focusOf(given) ?? [];
|
|
11071
|
+
await patchAndPrint(
|
|
11072
|
+
analysisId,
|
|
11073
|
+
families.map(focusText).join(", "),
|
|
11074
|
+
(api, aid) => api.analysis.patchFocusFamilies(aid, { families }),
|
|
11075
|
+
"Focus",
|
|
11076
|
+
cmd
|
|
11077
|
+
);
|
|
11078
|
+
}
|
|
9727
11079
|
function collectAsUploaded(value, previous) {
|
|
9728
11080
|
return [...Array.isArray(previous) ? previous : [], value];
|
|
9729
11081
|
}
|
|
@@ -9787,7 +11139,7 @@ async function uploadData(analysisId, files, options, cmd) {
|
|
|
9787
11139
|
`For example: diafunc analyze upload ${analysisId} data.csv`
|
|
9788
11140
|
);
|
|
9789
11141
|
}
|
|
9790
|
-
if (!
|
|
11142
|
+
if (!fs12.existsSync(file)) {
|
|
9791
11143
|
throw new CliError(`File not found: ${file}`, { exitCode: EXIT_USAGE });
|
|
9792
11144
|
}
|
|
9793
11145
|
}
|
|
@@ -10012,11 +11364,21 @@ async function updateTriggerCmd(triggerId, options, cmd) {
|
|
|
10012
11364
|
format(trigger, { format: outputFormat });
|
|
10013
11365
|
}
|
|
10014
11366
|
var COLUMN_LIST_HELP = "one argument each or comma-separated; a name that contains a comma is an argument of its own, or goes in double quotes inside a list";
|
|
10015
|
-
var
|
|
11367
|
+
var LICENSE_HELP = "With PUBLIC: the license the analysis's project is published under, an id of the license catalog (see 'diafunc license list')";
|
|
10016
11368
|
var TARGETS_HELP = `Target column names: repeat the flag or separate them with commas; a name that contains a comma is one flag of its own, or goes in double quotes inside a list`;
|
|
11369
|
+
var INTENT_HELP = "What you know about the data and what matters to you, in your own words. Private to you. It is read into proposals; nothing changes until you confirm one";
|
|
11370
|
+
var SHAPE_HELP = "An expectation about a target's shape, <target>=<statement>, for example price=increasing(size_m2); checked and reported, or with require: in front also steering the model; repeat the flag for several";
|
|
11371
|
+
var PAIR_QUOTING_HELP = `A column whose name holds a comma goes in double quotes: '"a, b",price'`;
|
|
11372
|
+
var PAIR_HELP = `A chart to add to the report: the second column against the first, with kind scatter, groups or counts, or none; at most ${MAX_PAIRS}; repeat the flag for several. ${PAIR_QUOTING_HELP}`;
|
|
11373
|
+
var FOCUS_HELP = `A question family that matters most to you, for example extrapolation or input_importance; at most ${MAX_FOCUS}, most important first; repeat the flag for several`;
|
|
11374
|
+
var FOCUS_FAMILY_LINES = FOCUS_FAMILIES.map((f) => ` ${f.id.padEnd(20)}${f.label}`).join("\n");
|
|
11375
|
+
var FOCUS_FAMILIES_HELP = `
|
|
11376
|
+
Question families:
|
|
11377
|
+
${FOCUS_FAMILY_LINES}
|
|
11378
|
+
`;
|
|
10017
11379
|
function registerAnalyzeCommand(program) {
|
|
10018
11380
|
const analyze = program.command("analyze").description("Run and manage automatic analyses");
|
|
10019
|
-
analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[files...]", "Data file to analyze (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files are combined into one table: files with the same columns are stacked, a file that shares a key adds its columns").option("--name <name>", "Analysis name (asked for, or derived from the filename)").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC (default: PRIVATE)").option("--licence <
|
|
11381
|
+
analyze.command("run", { isDefault: true }).description("Create an analysis from a data file, configure it and run it (the default: `analyze <file>`)").argument("[files...]", "Data file to analyze (CSV, Excel and more than 45 file formats; see `table import-formats`). Several files are combined into one table: files with the same columns are stacked, a file that shares a key adds its columns").option("--name <name>", "Analysis name (asked for, or derived from the filename)").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC (default: PRIVATE)").option("--license <licenseId>", LICENSE_HELP).addOption(hiddenOptionAlias("--licence <licenseId>", "license")).option("--depth <name or credits>", DEPTH_HELP).option("--hours <hours>", `Time limit (hours) for a depth of your own. ${STARTING_DEPTH_RULE}`).option("--budget <credits>", `Credit budget for a depth of your own. ${STARTING_DEPTH_RULE}`).option("--targets <columns>", `${TARGETS_HELP} (required when not interactive)`, collectColumns).option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction shown at the top of the notebook").option("--preset <id>", "Apply a saved preset as defaults (explicit flags override it)").option("--no-file-column", "With several files: do not add the column that records the file each row came from").option("--keep-duplicates", "With several files: keep rows that occur in more than one file").option("--rows-of <file>", "With several files that can be read two ways: the file in which one row is one observation").option("--as-uploaded [file]", AS_UPLOADED_HELP, collectAsUploaded).option("--intent <text>", INTENT_HELP).option("--intent-file <path>", "Read the notes from a file instead (for notes longer than a line)").option("--shape <target=statement>", SHAPE_HELP, collectQuestion).option("--pair <first,second[,kind]>", PAIR_HELP, collectQuestion).option("--focus <family>", FOCUS_HELP, collectQuestion).action(async (files, options, cmd) => {
|
|
10020
11382
|
try {
|
|
10021
11383
|
if (files.length === 0) {
|
|
10022
11384
|
analyze.help();
|
|
@@ -10034,7 +11396,7 @@ function registerAnalyzeCommand(program) {
|
|
|
10034
11396
|
handleError(error);
|
|
10035
11397
|
}
|
|
10036
11398
|
});
|
|
10037
|
-
analyze.command("get").description("Show details of an analysis").argument("[id]", "Analysis ID (defaults to the most recent)").option("--full", "Print the introduction in full instead of abbreviating
|
|
11399
|
+
analyze.command("get").description("Show details of an analysis").argument("[id]", "Analysis ID (defaults to the most recent)").option("--full", "Print the introduction and your notes in full instead of abbreviating them").addHelpText("after", REPORT_TERMS_HELP).action(async (id, options, cmd) => {
|
|
10038
11400
|
try {
|
|
10039
11401
|
await getAnalysisDetails(id, options, cmd);
|
|
10040
11402
|
} catch (error) {
|
|
@@ -10055,6 +11417,20 @@ function registerAnalyzeCommand(program) {
|
|
|
10055
11417
|
handleError(error);
|
|
10056
11418
|
}
|
|
10057
11419
|
});
|
|
11420
|
+
analyze.command("report").description("Print the report of an analysis as Markdown: the summary and the chapter titles, or one chapter").argument("<id>", "Analysis ID").option("--chapter <title or path>", 'A chapter title, or a path of titles separated by ">" (for example "Age > Correlation")').option("--part <n>", "With --chapter: the part to read of a chapter that comes in parts, from 1 (default: 1)").option("--max-bytes <n>", "Largest answer in bytes; the platform reads 4096 to 262144 (default: 32768)").addHelpText("after", REPORT_HELP).action(async (id, options) => {
|
|
11421
|
+
try {
|
|
11422
|
+
await printReport(id, options);
|
|
11423
|
+
} catch (error) {
|
|
11424
|
+
handleError(error);
|
|
11425
|
+
}
|
|
11426
|
+
});
|
|
11427
|
+
analyze.command("export-model").description("Print the model of a target as a formula or as source code").argument("<id>", "Analysis ID").requiredOption("--language <language>", `One of: ${EXPORT_LANGUAGES.join(", ")}`).option("--target <name>", "The target whose model to export (required when the analysis has several)").addHelpText("after", EXPORT_MODEL_HELP).action(async (id, options) => {
|
|
11428
|
+
try {
|
|
11429
|
+
await printModelExport(id, options);
|
|
11430
|
+
} catch (error) {
|
|
11431
|
+
handleError(error);
|
|
11432
|
+
}
|
|
11433
|
+
});
|
|
10058
11434
|
analyze.command("rerun").description("Queue a fresh run on an existing analysis (asks for anything a run still needs). A run cannot start while the data is still being imported").argument("<id>", "Analysis ID to rerun").action(async (id, _options, cmd) => {
|
|
10059
11435
|
try {
|
|
10060
11436
|
await rerunAnalysis(id, cmd);
|
|
@@ -10062,14 +11438,14 @@ function registerAnalyzeCommand(program) {
|
|
|
10062
11438
|
reportCommandError(error);
|
|
10063
11439
|
}
|
|
10064
11440
|
});
|
|
10065
|
-
analyze.command("create").description("Create an analysis without uploading data or running it").option("--name <name>", "Analysis name").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--licence <
|
|
11441
|
+
analyze.command("create").description("Create an analysis without uploading data or running it").option("--name <name>", "Analysis name").option("--description <text>", "Analysis description").option("--visibility <vis>", "PRIVATE or PUBLIC", "PRIVATE").option("--license <licenseId>", LICENSE_HELP).addOption(hiddenOptionAlias("--licence <licenseId>", "license")).option("--depth <name or credits>", DEPTH_HELP).option("--hours <hours>", `Time limit (hours) for a depth of your own. ${STARTING_DEPTH_RULE}`).option("--budget <credits>", `Credit budget for a depth of your own. ${STARTING_DEPTH_RULE}`).option("--targets <columns>", TARGETS_HELP, collectColumns).option("--question <text>", "A question for the analysis to answer; repeat the flag for several", collectQuestion).option("--segment <name>", "Column to segment the analysis by").option("--introduction <markdown>", "Markdown introduction shown at the top of the notebook").option("--intent <text>", INTENT_HELP).option("--intent-file <path>", "Read the notes from a file instead (for notes longer than a line)").option("--shape <target=statement>", SHAPE_HELP, collectQuestion).option("--pair <first,second[,kind]>", PAIR_HELP, collectQuestion).option("--focus <family>", FOCUS_HELP, collectQuestion).action(async (options, cmd) => {
|
|
10066
11442
|
try {
|
|
10067
11443
|
await createAnalysis(options, cmd);
|
|
10068
11444
|
} catch (error) {
|
|
10069
11445
|
handleError(error);
|
|
10070
11446
|
}
|
|
10071
11447
|
});
|
|
10072
|
-
analyze.command("delete").description("Delete an analysis,
|
|
11448
|
+
analyze.command("delete").description("Delete an analysis, canceling any run still in flight").argument("<id>", "Analysis ID").option("-y, --yes", "Skip confirmation prompt (for CI / scripted use)").action(async (id, options) => {
|
|
10073
11449
|
try {
|
|
10074
11450
|
await confirmDestructive(`This will permanently delete analysis "${id}".`, { yes: options.yes, resourceId: id });
|
|
10075
11451
|
await deleteAnalysis(id);
|
|
@@ -10103,10 +11479,10 @@ function registerAnalyzeCommand(program) {
|
|
|
10103
11479
|
handleError(error);
|
|
10104
11480
|
}
|
|
10105
11481
|
});
|
|
10106
|
-
analyze.command("visibility").description("Set analysis visibility (PRIVATE or PUBLIC)").argument("<id>", "Analysis ID").argument("<vis>", "PRIVATE or PUBLIC").option("--licence <
|
|
11482
|
+
analyze.command("visibility").description("Set analysis visibility (PRIVATE or PUBLIC)").argument("<id>", "Analysis ID").argument("<vis>", "PRIVATE or PUBLIC").option("--license <licenseId>", LICENSE_HELP).addOption(hiddenOptionAlias("--licence <licenseId>", "license")).addHelpText("after", `
|
|
10107
11483
|
Examples:
|
|
10108
|
-
$ diafunc analyze visibility <id> PUBLIC --
|
|
10109
|
-
$ diafunc analyze visibility <id> PRIVATE withdraw it; the
|
|
11484
|
+
$ diafunc analyze visibility <id> PUBLIC --license CC-BY-4.0 publish under a license
|
|
11485
|
+
$ diafunc analyze visibility <id> PRIVATE withdraw it; the license is kept for later
|
|
10110
11486
|
`).action(async (id, vis, options, cmd) => {
|
|
10111
11487
|
try {
|
|
10112
11488
|
const visibility = parseVisibility(vis);
|
|
@@ -10115,7 +11491,7 @@ Examples:
|
|
|
10115
11491
|
visibility,
|
|
10116
11492
|
(api, aid, v) => api.analysis.patchVisibility(aid, {
|
|
10117
11493
|
visibility: v,
|
|
10118
|
-
...options.
|
|
11494
|
+
...options.license ? { licenceId: options.license } : {}
|
|
10119
11495
|
}),
|
|
10120
11496
|
"Visibility",
|
|
10121
11497
|
cmd
|
|
@@ -10176,13 +11552,13 @@ Examples:
|
|
|
10176
11552
|
handleError(error);
|
|
10177
11553
|
}
|
|
10178
11554
|
});
|
|
10179
|
-
analyze.command("input-exclusions").description("Set the columns
|
|
11555
|
+
analyze.command("input-exclusions").description("Set the columns the analysis leaves out as inputs (a single empty string leaves nothing out)").argument("<id>", "Analysis ID").argument("<column...>", `Column names, ${COLUMN_LIST_HELP}`).action(async (id, given, _options, cmd) => {
|
|
10180
11556
|
try {
|
|
10181
11557
|
await patchColumns(
|
|
10182
11558
|
id,
|
|
10183
11559
|
given,
|
|
10184
11560
|
(api, columns) => api.analysis.patchInputExclusions(id, { columns }),
|
|
10185
|
-
"Columns left out
|
|
11561
|
+
"Columns left out as inputs",
|
|
10186
11562
|
cmd
|
|
10187
11563
|
);
|
|
10188
11564
|
} catch (error) {
|
|
@@ -10202,31 +11578,85 @@ Examples:
|
|
|
10202
11578
|
handleError(error);
|
|
10203
11579
|
}
|
|
10204
11580
|
});
|
|
10205
|
-
analyze.command("questions").description("Set the questions the analysis answers, one argument per question").argument("<id>", "Analysis ID").argument("<question...>", "The questions, each quoted as one argument (a single empty string clears them)").action(async (id, given, _options, cmd) => {
|
|
11581
|
+
analyze.command("questions").description("Set the questions the analysis answers, one argument per question").argument("<id>", "Analysis ID").argument("<question...>", "The questions, each quoted as one argument (a single empty string clears them)").action(async (id, given, _options, cmd) => {
|
|
11582
|
+
try {
|
|
11583
|
+
const questions = questionsOf(Array.isArray(given) ? given : [given]) ?? [];
|
|
11584
|
+
await patchAndPrint(
|
|
11585
|
+
id,
|
|
11586
|
+
questions.join(" | "),
|
|
11587
|
+
(api, aid) => api.analysis.patchQuestions(aid, { questions }),
|
|
11588
|
+
"Questions",
|
|
11589
|
+
cmd
|
|
11590
|
+
);
|
|
11591
|
+
} catch (error) {
|
|
11592
|
+
handleError(error);
|
|
11593
|
+
}
|
|
11594
|
+
});
|
|
11595
|
+
analyze.command("segment").description("Set or clear the segmentation column (empty string clears)").argument("<id>", "Analysis ID").argument("<name>", "Column name, matched against the columns of the analysis data (empty string to clear)").action(async (id, name, _options, cmd) => {
|
|
11596
|
+
try {
|
|
11597
|
+
const api = createApiClient();
|
|
11598
|
+
const segment = name === "" ? null : resolveColumnArgument(name, await columnNames(api, id), id);
|
|
11599
|
+
await patchAndPrint(
|
|
11600
|
+
id,
|
|
11601
|
+
name,
|
|
11602
|
+
() => api.analysis.patchSegment(id, { segment }),
|
|
11603
|
+
"Segment",
|
|
11604
|
+
cmd
|
|
11605
|
+
);
|
|
11606
|
+
} catch (error) {
|
|
11607
|
+
handleError(error);
|
|
11608
|
+
}
|
|
11609
|
+
});
|
|
11610
|
+
const intent = analyze.command("intent").description('Your private notes ("What you know and what matters"), read into proposals that apply only when you confirm them');
|
|
11611
|
+
intent.command("notes", { isDefault: true }).description("Show your notes, or set them (an empty text or --clear clears them). Only you can read them; storing them does not read them").argument("<id>", "Analysis ID").argument("[text]", `The notes, in your own words (at most ${MAX_INTENT_LENGTH.toLocaleString("en-US")} characters)`).option("--file <path>", "Read the notes from a file").option("--clear", "Clear the notes").action(async (id, text2, options, cmd) => {
|
|
11612
|
+
try {
|
|
11613
|
+
await notesCommand(id, text2, options, cmd);
|
|
11614
|
+
} catch (error) {
|
|
11615
|
+
handleError(error);
|
|
11616
|
+
}
|
|
11617
|
+
});
|
|
11618
|
+
intent.command("read").description("Read your notes into proposals and print them. Nothing changes until you confirm one").argument("<id>", "Analysis ID").option("--force", "Read them again even when nothing changed since the last reading").option("--refine", "Read them for a refinement of the analysis, where a row focus can be applied").action(async (id, options, cmd) => {
|
|
11619
|
+
try {
|
|
11620
|
+
await readNotesCommand(id, options, cmd);
|
|
11621
|
+
} catch (error) {
|
|
11622
|
+
handleError(error);
|
|
11623
|
+
}
|
|
11624
|
+
});
|
|
11625
|
+
const decisions = [
|
|
11626
|
+
{ name: "confirm", state: "CONFIRMED", description: "Use proposals: each is applied to the analysis from the next run. An expectation is checked; --steer lets it steer the model too" },
|
|
11627
|
+
{ name: "decline", state: "DECLINED", description: "Do not use proposals; one that was applied is taken back out" },
|
|
11628
|
+
{ name: "reset", state: "PROPOSED", description: "Open proposals again, undoing the decision; one that was applied is taken back out" }
|
|
11629
|
+
];
|
|
11630
|
+
for (const decision of decisions) {
|
|
11631
|
+
const command = intent.command(decision.name).description(decision.description).argument("<id>", "Analysis ID").argument("<proposalId...>", "Proposal ids, as 'analyze intent read' prints them");
|
|
11632
|
+
if (decision.state === "CONFIRMED") {
|
|
11633
|
+
command.option("--steer", "Also let the expectations steer which model is delivered").option("--no-steer", "Check and report the expectations only (the default for a new one)");
|
|
11634
|
+
}
|
|
11635
|
+
command.action(async (id, ids, options, cmd) => {
|
|
11636
|
+
try {
|
|
11637
|
+
await decideCommand(decision.state, id, ids, options, cmd);
|
|
11638
|
+
} catch (error) {
|
|
11639
|
+
handleError(error);
|
|
11640
|
+
}
|
|
11641
|
+
});
|
|
11642
|
+
}
|
|
11643
|
+
analyze.command("expectations").description("Show or set expectations about a target's shape. Each is checked and reported; one written with require: also steers the model").argument("<id>", "Analysis ID").argument("[statements...]", "Statements such as increasing(size_m2), decreasing(price, 1, 20), convex(x), concave(x) or range(0, inf), each with check: (the default) or require: in front; without --target written <target>=<statement>. A window left open is the input's observed range").option("--target <target>", "The target the statements are about; with --clear, the target to clear").option("--clear", "Clear the expectations of the target named, or all of them").action(async (id, statements, options, cmd) => {
|
|
11644
|
+
try {
|
|
11645
|
+
await expectationsCommand(id, statements, options, cmd);
|
|
11646
|
+
} catch (error) {
|
|
11647
|
+
handleError(error);
|
|
11648
|
+
}
|
|
11649
|
+
});
|
|
11650
|
+
analyze.command("charts").description(`Set the charts to add to the report, at most ${MAX_PAIRS} (a single empty string clears them)`).argument("<id>", "Analysis ID").argument("<pair...>", `Each <first>,<second>[,<kind>]: the second column against the first; kind is scatter, groups or counts, or left out for the chart rules to choose. ${PAIR_QUOTING_HELP}`).action(async (id, given, _options, cmd) => {
|
|
10206
11651
|
try {
|
|
10207
|
-
|
|
10208
|
-
await patchAndPrint(
|
|
10209
|
-
id,
|
|
10210
|
-
questions.join(" | "),
|
|
10211
|
-
(api, aid) => api.analysis.patchQuestions(aid, { questions }),
|
|
10212
|
-
"Questions",
|
|
10213
|
-
cmd
|
|
10214
|
-
);
|
|
11652
|
+
await chartsCommand(id, given, cmd);
|
|
10215
11653
|
} catch (error) {
|
|
10216
11654
|
handleError(error);
|
|
10217
11655
|
}
|
|
10218
11656
|
});
|
|
10219
|
-
analyze.command("
|
|
11657
|
+
analyze.command("focus").description(`Set what matters most to you, as question families, most important first, at most ${MAX_FOCUS} (a single empty string clears them). The report answers these first`).argument("<id>", "Analysis ID").argument("<family...>", "Question families, for example extrapolation or input_importance").addHelpText("after", FOCUS_FAMILIES_HELP).action(async (id, given, _options, cmd) => {
|
|
10220
11658
|
try {
|
|
10221
|
-
|
|
10222
|
-
const segment = name === "" ? null : resolveColumnArgument(name, await columnNames(api, id), id);
|
|
10223
|
-
await patchAndPrint(
|
|
10224
|
-
id,
|
|
10225
|
-
name,
|
|
10226
|
-
() => api.analysis.patchSegment(id, { segment }),
|
|
10227
|
-
"Segment",
|
|
10228
|
-
cmd
|
|
10229
|
-
);
|
|
11659
|
+
await focusCommand(id, given, cmd);
|
|
10230
11660
|
} catch (error) {
|
|
10231
11661
|
handleError(error);
|
|
10232
11662
|
}
|
|
@@ -10407,7 +11837,7 @@ async function listPublicAnalyses(options, cmd) {
|
|
|
10407
11837
|
{ key: "projectId", kind: "id" },
|
|
10408
11838
|
{ key: "publishedAt", header: "published", kind: "date" },
|
|
10409
11839
|
{ key: "changedAt", header: "changed", kind: "date" },
|
|
10410
|
-
{ key: "licenceId", header: "
|
|
11840
|
+
{ key: "licenceId", header: "license" }
|
|
10411
11841
|
]
|
|
10412
11842
|
});
|
|
10413
11843
|
}
|
|
@@ -10494,44 +11924,44 @@ Examples:
|
|
|
10494
11924
|
});
|
|
10495
11925
|
}
|
|
10496
11926
|
|
|
10497
|
-
// src/commands/
|
|
10498
|
-
import
|
|
11927
|
+
// src/commands/license/index.ts
|
|
11928
|
+
import chalk30 from "chalk";
|
|
10499
11929
|
function getOutputFormat19(cmd) {
|
|
10500
11930
|
const config = loadConfig();
|
|
10501
11931
|
const globalOpts = cmd.optsWithGlobals();
|
|
10502
11932
|
return globalOpts.output ?? config.defaults.output ?? "human";
|
|
10503
11933
|
}
|
|
10504
|
-
var
|
|
11934
|
+
var LICENSE_MARKS = [
|
|
10505
11935
|
{ mark: "C", flag: "commercialUse", meaning: "commercial use" },
|
|
10506
11936
|
{ mark: "D", flag: "derivatives", meaning: "adaptations and forks" },
|
|
10507
11937
|
{ mark: "R", flag: "redistribution", meaning: "redistribution" },
|
|
10508
11938
|
{ mark: "BY", flag: "attributionRequired", meaning: "attribution required" },
|
|
10509
11939
|
{ mark: "SA", flag: "shareAlike", meaning: "share-alike" }
|
|
10510
11940
|
];
|
|
10511
|
-
function
|
|
10512
|
-
const marks =
|
|
11941
|
+
function licenseMarks(license) {
|
|
11942
|
+
const marks = LICENSE_MARKS.filter(({ flag }) => license[flag] === true).map(({ mark }) => mark);
|
|
10513
11943
|
return marks.length > 0 ? marks.join(" ") : null;
|
|
10514
11944
|
}
|
|
10515
11945
|
function stateWord(state) {
|
|
10516
11946
|
return state.toLowerCase();
|
|
10517
11947
|
}
|
|
10518
|
-
async function
|
|
11948
|
+
async function listLicenses(cmd) {
|
|
10519
11949
|
const outputFormat = getOutputFormat19(cmd);
|
|
10520
11950
|
const api = createApiClient();
|
|
10521
|
-
const
|
|
11951
|
+
const licenses = await api.admin.listLicenses();
|
|
10522
11952
|
if (outputFormat === "json") {
|
|
10523
|
-
format(
|
|
11953
|
+
format(licenses, { format: outputFormat });
|
|
10524
11954
|
return;
|
|
10525
11955
|
}
|
|
10526
|
-
if (
|
|
10527
|
-
empty("
|
|
11956
|
+
if (licenses.length === 0 && outputFormat === "human") {
|
|
11957
|
+
empty("licenses");
|
|
10528
11958
|
return;
|
|
10529
11959
|
}
|
|
10530
|
-
format(
|
|
11960
|
+
format(licenses.map((l) => ({
|
|
10531
11961
|
licenceId: l.licenceId,
|
|
10532
11962
|
name: l.name,
|
|
10533
11963
|
state: stateWord(l.state),
|
|
10534
|
-
flags:
|
|
11964
|
+
flags: licenseMarks(l),
|
|
10535
11965
|
recommended: l.recommended
|
|
10536
11966
|
})), {
|
|
10537
11967
|
format: outputFormat,
|
|
@@ -10544,42 +11974,42 @@ async function listLicences(cmd) {
|
|
|
10544
11974
|
]
|
|
10545
11975
|
});
|
|
10546
11976
|
if (outputFormat === "human") {
|
|
10547
|
-
console.error(
|
|
11977
|
+
console.error(chalk30.dim(
|
|
10548
11978
|
`
|
|
10549
|
-
Flags: ${
|
|
11979
|
+
Flags: ${LICENSE_MARKS.map(({ mark, meaning }) => `${mark} ${meaning}`).join(", ")}. A deprecated license stays on the projects that carry it and cannot be chosen.`
|
|
10550
11980
|
));
|
|
10551
11981
|
}
|
|
10552
11982
|
}
|
|
10553
|
-
async function
|
|
11983
|
+
async function showLicense(licenseId, cmd) {
|
|
10554
11984
|
const outputFormat = getOutputFormat19(cmd);
|
|
10555
11985
|
const api = createApiClient();
|
|
10556
|
-
let
|
|
11986
|
+
let license;
|
|
10557
11987
|
try {
|
|
10558
|
-
|
|
11988
|
+
license = await api.admin.getLicense(licenseId);
|
|
10559
11989
|
} catch (error) {
|
|
10560
11990
|
if (error instanceof ApiError && error.status === 404) {
|
|
10561
|
-
throw new CliError(`No
|
|
10562
|
-
hint: `List the
|
|
11991
|
+
throw new CliError(`No license "${licenseId}" in the catalog.`, {
|
|
11992
|
+
hint: `List the licenses with 'diafunc license list'.`
|
|
10563
11993
|
});
|
|
10564
11994
|
}
|
|
10565
11995
|
throw error;
|
|
10566
11996
|
}
|
|
10567
11997
|
if (outputFormat !== "human") {
|
|
10568
|
-
format(
|
|
11998
|
+
format(license, { format: outputFormat });
|
|
10569
11999
|
return;
|
|
10570
12000
|
}
|
|
10571
12001
|
format({
|
|
10572
|
-
licenceId:
|
|
10573
|
-
name:
|
|
10574
|
-
state: stateWord(
|
|
10575
|
-
summary:
|
|
10576
|
-
url:
|
|
10577
|
-
commercialUse:
|
|
10578
|
-
derivatives:
|
|
10579
|
-
redistribution:
|
|
10580
|
-
attributionRequired:
|
|
10581
|
-
shareAlike:
|
|
10582
|
-
recommended:
|
|
12002
|
+
licenceId: license.licenceId,
|
|
12003
|
+
name: license.name,
|
|
12004
|
+
state: stateWord(license.state),
|
|
12005
|
+
summary: license.summary,
|
|
12006
|
+
url: license.url,
|
|
12007
|
+
commercialUse: license.commercialUse,
|
|
12008
|
+
derivatives: license.derivatives,
|
|
12009
|
+
redistribution: license.redistribution,
|
|
12010
|
+
attributionRequired: license.attributionRequired,
|
|
12011
|
+
shareAlike: license.shareAlike,
|
|
12012
|
+
recommended: license.recommended
|
|
10583
12013
|
}, {
|
|
10584
12014
|
format: outputFormat,
|
|
10585
12015
|
columns: [
|
|
@@ -10587,7 +12017,7 @@ async function showLicence(licenceId, cmd) {
|
|
|
10587
12017
|
{ key: "name", header: "Name" },
|
|
10588
12018
|
{ key: "state", header: "State", kind: "state" },
|
|
10589
12019
|
{ key: "summary", header: "Summary" },
|
|
10590
|
-
{ key: "url", header: "
|
|
12020
|
+
{ key: "url", header: "License text" },
|
|
10591
12021
|
{ key: "commercialUse", header: "Commercial use", kind: "boolean" },
|
|
10592
12022
|
{ key: "derivatives", header: "Adaptations and forks", kind: "boolean" },
|
|
10593
12023
|
{ key: "redistribution", header: "Redistribution", kind: "boolean" },
|
|
@@ -10597,24 +12027,24 @@ async function showLicence(licenceId, cmd) {
|
|
|
10597
12027
|
]
|
|
10598
12028
|
});
|
|
10599
12029
|
}
|
|
10600
|
-
function
|
|
10601
|
-
const
|
|
12030
|
+
function registerLicenseCommands(program) {
|
|
12031
|
+
const license = hiddenAlias(program.command("license"), "licence").description("The licenses a public project can be published under (no sign-in needed)").addHelpText("after", `
|
|
10602
12032
|
Examples:
|
|
10603
|
-
$ diafunc
|
|
10604
|
-
$ diafunc
|
|
10605
|
-
$ diafunc project create --visibility PUBLIC --
|
|
10606
|
-
$ diafunc analyze visibility <id> PUBLIC --
|
|
12033
|
+
$ diafunc license list the licenses that can be chosen
|
|
12034
|
+
$ diafunc license show CC-BY-4.0 one license and what it allows
|
|
12035
|
+
$ diafunc project create --visibility PUBLIC --license CC-BY-4.0
|
|
12036
|
+
$ diafunc analyze visibility <id> PUBLIC --license CC0-1.0
|
|
10607
12037
|
`);
|
|
10608
|
-
|
|
12038
|
+
license.command("list").description("List the license catalog: the active and the deprecated licenses, in catalog order").action(async (_options, cmd) => {
|
|
10609
12039
|
try {
|
|
10610
|
-
await
|
|
12040
|
+
await listLicenses(cmd);
|
|
10611
12041
|
} catch (error) {
|
|
10612
12042
|
handleError(error);
|
|
10613
12043
|
}
|
|
10614
12044
|
});
|
|
10615
|
-
|
|
12045
|
+
license.command("show").description("Show one license, in any state, and what it allows").argument("<licenseId>", "License ID (CC-BY-4.0, CC0-1.0, diafunc-view-only, ...)").action(async (licenseId, _options, cmd) => {
|
|
10616
12046
|
try {
|
|
10617
|
-
await
|
|
12047
|
+
await showLicense(licenseId, cmd);
|
|
10618
12048
|
} catch (error) {
|
|
10619
12049
|
handleError(error);
|
|
10620
12050
|
}
|
|
@@ -10622,7 +12052,7 @@ Examples:
|
|
|
10622
12052
|
}
|
|
10623
12053
|
|
|
10624
12054
|
// src/commands/data-sources/index.ts
|
|
10625
|
-
import
|
|
12055
|
+
import chalk31 from "chalk";
|
|
10626
12056
|
function getOutputFormat20(cmd) {
|
|
10627
12057
|
const config = loadConfig();
|
|
10628
12058
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -10758,7 +12188,7 @@ async function showDashboard(projectId, cmd) {
|
|
|
10758
12188
|
return;
|
|
10759
12189
|
}
|
|
10760
12190
|
const r = dashboard.rollup;
|
|
10761
|
-
let line =
|
|
12191
|
+
let line = chalk31.bold(`DataSources in ${projectId}: `) + `${r.totalSources} total, ${r.scheduledSources} scheduled, ${r.sourcesWithRecentFailure} failing recently`;
|
|
10762
12192
|
if (r.lastActivityAt) line += `, last activity ${r.lastActivityAt}`;
|
|
10763
12193
|
console.log(line);
|
|
10764
12194
|
if (dashboard.sources.length === 0) {
|
|
@@ -10819,9 +12249,9 @@ async function createForAnalysis(api, options, human) {
|
|
|
10819
12249
|
if (human) {
|
|
10820
12250
|
success(`Added ${source.fileName} to analysis ${analysisId} from data source ${source.dataSourceId ?? ""}`.trimEnd());
|
|
10821
12251
|
for (const line of planLines(build.plan)) {
|
|
10822
|
-
console.log(line.caution ?
|
|
12252
|
+
console.log(line.caution ? chalk31.yellow(` ${line.text}`) : chalk31.dim(` ${line.text}`));
|
|
10823
12253
|
}
|
|
10824
|
-
console.log(
|
|
12254
|
+
console.log(chalk31.dim(options.scheduleCron ? ` Refreshes ${humanizeCron(options.scheduleCron)}; each refresh replaces the file and builds the data again.` : " No schedule of its own: refresh it with `data-sources refresh`, or let a trigger fetch it before a run (`analyze triggers create --refresh-first`)."));
|
|
10825
12255
|
}
|
|
10826
12256
|
return { source, build };
|
|
10827
12257
|
}
|
|
@@ -10849,8 +12279,8 @@ async function createDataSource(options, cmd) {
|
|
|
10849
12279
|
const ds = await api.storage.createDataSource(request);
|
|
10850
12280
|
if (outputFormat === "human") {
|
|
10851
12281
|
success(`Created data source ${ds.id}`);
|
|
10852
|
-
console.log(
|
|
10853
|
-
if (ds.lastRunError) console.log(
|
|
12282
|
+
console.log(chalk31.dim(` Last run: ${ds.lastRunStatus ?? "\u2014"}`));
|
|
12283
|
+
if (ds.lastRunError) console.log(chalk31.dim(` Error: ${ds.lastRunError}`));
|
|
10854
12284
|
} else {
|
|
10855
12285
|
format(ds, { format: outputFormat });
|
|
10856
12286
|
}
|
|
@@ -10896,7 +12326,7 @@ async function refreshDataSource(id, cmd) {
|
|
|
10896
12326
|
const run = await api.storage.refreshDataSource(id);
|
|
10897
12327
|
if (outputFormat === "human") {
|
|
10898
12328
|
success(`Refresh queued: run ${run.runId}, status ${run.status}.`);
|
|
10899
|
-
if (run.errorMessage) console.log(
|
|
12329
|
+
if (run.errorMessage) console.log(chalk31.red(` Error: ${run.errorMessage}`));
|
|
10900
12330
|
} else {
|
|
10901
12331
|
format(run, { format: outputFormat });
|
|
10902
12332
|
}
|
|
@@ -11023,7 +12453,7 @@ Examples:
|
|
|
11023
12453
|
}
|
|
11024
12454
|
|
|
11025
12455
|
// src/commands/table-exporters/index.ts
|
|
11026
|
-
import
|
|
12456
|
+
import chalk32 from "chalk";
|
|
11027
12457
|
function getOutputFormat21(cmd) {
|
|
11028
12458
|
const config = loadConfig();
|
|
11029
12459
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -11054,7 +12484,7 @@ function registerTableExportersCommands(program) {
|
|
|
11054
12484
|
format: outputFormat,
|
|
11055
12485
|
columns: ["id", "name", "format", "extension", "mimeType", "priority", "function", "createdBy"]
|
|
11056
12486
|
});
|
|
11057
|
-
console.log(
|
|
12487
|
+
console.log(chalk32.dim(`${list.length} exporter(s)`));
|
|
11058
12488
|
} catch (error) {
|
|
11059
12489
|
handleError(error);
|
|
11060
12490
|
}
|
|
@@ -11112,8 +12542,8 @@ function registerTableExportersCommands(program) {
|
|
|
11112
12542
|
}
|
|
11113
12543
|
|
|
11114
12544
|
// src/commands/skeleton/index.ts
|
|
11115
|
-
import
|
|
11116
|
-
import * as
|
|
12545
|
+
import chalk33 from "chalk";
|
|
12546
|
+
import * as fs13 from "fs";
|
|
11117
12547
|
function getOutputFormat22(cmd) {
|
|
11118
12548
|
const config = loadConfig();
|
|
11119
12549
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -11125,7 +12555,7 @@ function resolveProjectId2(cmd) {
|
|
|
11125
12555
|
const config = loadConfig();
|
|
11126
12556
|
if (config.defaults.project) return config.defaults.project;
|
|
11127
12557
|
throw new Error(
|
|
11128
|
-
"No project specified. Pass --project <id>, set the global --project flag, or run `diafunc config defaults
|
|
12558
|
+
"No project specified. Pass --project <id>, set the global --project flag, or run `diafunc config set defaults.project <id>`."
|
|
11129
12559
|
);
|
|
11130
12560
|
}
|
|
11131
12561
|
function resolveTemplate(raw) {
|
|
@@ -11137,10 +12567,10 @@ function resolveTemplate(raw) {
|
|
|
11137
12567
|
if (!file) {
|
|
11138
12568
|
throw new Error("--template @ requires a filename after the @, e.g. --template @template.txt");
|
|
11139
12569
|
}
|
|
11140
|
-
if (!
|
|
12570
|
+
if (!fs13.existsSync(file)) {
|
|
11141
12571
|
throw new Error(`Template file not found: ${file}`);
|
|
11142
12572
|
}
|
|
11143
|
-
return
|
|
12573
|
+
return fs13.readFileSync(file, "utf-8").trim();
|
|
11144
12574
|
}
|
|
11145
12575
|
return raw;
|
|
11146
12576
|
}
|
|
@@ -11179,10 +12609,10 @@ async function createSkeleton(options, cmd) {
|
|
|
11179
12609
|
const skeleton = await api.storage.createSkeleton(request);
|
|
11180
12610
|
if (outputFormat === "human") {
|
|
11181
12611
|
success(`Created skeleton ${skeleton.id}`);
|
|
11182
|
-
console.log(
|
|
11183
|
-
console.log(
|
|
11184
|
-
console.log(
|
|
11185
|
-
console.log(
|
|
12612
|
+
console.log(chalk33.dim(` name: ${skeleton.name}`));
|
|
12613
|
+
console.log(chalk33.dim(` template: ${skeleton.template}`));
|
|
12614
|
+
console.log(chalk33.dim(` paramCount: ${skeleton.paramCount}`));
|
|
12615
|
+
console.log(chalk33.dim(` weight: ${skeleton.weight}`));
|
|
11186
12616
|
} else {
|
|
11187
12617
|
format(skeleton, { format: outputFormat });
|
|
11188
12618
|
}
|
|
@@ -11221,10 +12651,10 @@ async function updateSkeleton(id, options, cmd) {
|
|
|
11221
12651
|
const skeleton = await api.storage.updateSkeleton(id, request);
|
|
11222
12652
|
if (outputFormat === "human") {
|
|
11223
12653
|
success(`Updated skeleton ${skeleton.id}`);
|
|
11224
|
-
console.log(
|
|
11225
|
-
console.log(
|
|
11226
|
-
console.log(
|
|
11227
|
-
console.log(
|
|
12654
|
+
console.log(chalk33.dim(` name: ${skeleton.name}`));
|
|
12655
|
+
console.log(chalk33.dim(` template: ${skeleton.template}`));
|
|
12656
|
+
console.log(chalk33.dim(` paramCount: ${skeleton.paramCount}`));
|
|
12657
|
+
console.log(chalk33.dim(` weight: ${skeleton.weight}`));
|
|
11228
12658
|
} else {
|
|
11229
12659
|
format(skeleton, { format: outputFormat });
|
|
11230
12660
|
}
|
|
@@ -11241,7 +12671,7 @@ Examples:
|
|
|
11241
12671
|
$ diafunc skeleton create --project <id> --name linear --template 'a*x+b'
|
|
11242
12672
|
`);
|
|
11243
12673
|
;
|
|
11244
|
-
skeleton.command("create").description("Create a skeleton.
|
|
12674
|
+
skeleton.command("create").description("Create a skeleton. A template the platform cannot parse is reported on stderr.").requiredOption("--name <name>", "Display name").requiredOption(
|
|
11245
12675
|
"--template <expr>",
|
|
11246
12676
|
'Skeleton template expression (e.g. "?*x+?"). Use "@file.txt" to read from a file; "@@\u2026" escapes a literal leading @.'
|
|
11247
12677
|
).option("--weight <number>", "Sampling weight (positive; server default applies if omitted)").action(async (options, cmd) => {
|
|
@@ -11549,7 +12979,7 @@ function registerCompletionCommand(program) {
|
|
|
11549
12979
|
}
|
|
11550
12980
|
|
|
11551
12981
|
// src/commands/whoami/index.ts
|
|
11552
|
-
import
|
|
12982
|
+
import chalk34 from "chalk";
|
|
11553
12983
|
function registerWhoamiCommand(program) {
|
|
11554
12984
|
program.command("whoami").description("Show the currently authenticated user").action(async (_options, cmd) => {
|
|
11555
12985
|
try {
|
|
@@ -11559,8 +12989,8 @@ function registerWhoamiCommand(program) {
|
|
|
11559
12989
|
const api = createApiClient();
|
|
11560
12990
|
const user = await api.admin.getMyUser();
|
|
11561
12991
|
if (outputFormat === "human") {
|
|
11562
|
-
console.log(
|
|
11563
|
-
console.log(
|
|
12992
|
+
console.log(chalk34.bold(user.name) + chalk34.dim(` <${user.email}>`));
|
|
12993
|
+
console.log(chalk34.dim(` Role: ${user.role} \xB7 Remaining credits: ${user.remainingCredits} \xB7 Profile: ${config.currentProfile}`));
|
|
11564
12994
|
} else {
|
|
11565
12995
|
format(user, { format: outputFormat });
|
|
11566
12996
|
}
|
|
@@ -11571,7 +13001,7 @@ function registerWhoamiCommand(program) {
|
|
|
11571
13001
|
}
|
|
11572
13002
|
|
|
11573
13003
|
// src/commands/utilization/index.ts
|
|
11574
|
-
import
|
|
13004
|
+
import chalk35 from "chalk";
|
|
11575
13005
|
function getOutputFormat23(cmd) {
|
|
11576
13006
|
const config = loadConfig();
|
|
11577
13007
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -11588,19 +13018,19 @@ function windowLabel(u) {
|
|
|
11588
13018
|
}
|
|
11589
13019
|
function printUtilizationHuman(u, label) {
|
|
11590
13020
|
const when2 = windowLabel(u);
|
|
11591
|
-
console.log(label ?
|
|
13021
|
+
console.log(label ? chalk35.bold(label) + " " + chalk35.dim(when2) : chalk35.bold(when2));
|
|
11592
13022
|
if (u.types.length === 0) {
|
|
11593
|
-
console.log(
|
|
13023
|
+
console.log(chalk35.dim(" (no usage)"));
|
|
11594
13024
|
return;
|
|
11595
13025
|
}
|
|
11596
13026
|
const types = [...u.types].sort((a, b) => b.credits - a.credits);
|
|
11597
13027
|
const width = Math.max(...types.map((t) => t.type.length));
|
|
11598
13028
|
for (const t of types) {
|
|
11599
|
-
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${
|
|
11600
|
-
console.log(t.credits === 0 ?
|
|
13029
|
+
const line = ` ${t.type.padEnd(width)} ${formatNumber(t.quantity).padStart(12)} ${chalk35.dim("credits")} ${t.credits.toFixed(2).padStart(10)}`;
|
|
13030
|
+
console.log(t.credits === 0 ? chalk35.dim(line) : line);
|
|
11601
13031
|
}
|
|
11602
13032
|
const total = u.totalCredits ?? u.types.reduce((s, t) => s + t.credits, 0);
|
|
11603
|
-
console.log(
|
|
13033
|
+
console.log(chalk35.bold(` ${"Total".padEnd(width)} ${" ".repeat(12)} ${chalk35.dim("credits")} ${total.toFixed(2).padStart(10)}`));
|
|
11604
13034
|
}
|
|
11605
13035
|
function formatDailyHistory(history) {
|
|
11606
13036
|
const spentOn = (u) => u.dailyCredits ?? u.types.reduce((sum, t) => sum + (t.dailyCredits ?? 0), 0);
|
|
@@ -11617,14 +13047,14 @@ function formatDailyHistory(history) {
|
|
|
11617
13047
|
for (const u of history) {
|
|
11618
13048
|
const spent = spentOn(u);
|
|
11619
13049
|
total += spent;
|
|
11620
|
-
const line = `${windowLabel(u).padEnd(width)} ${amount(spent)} ${
|
|
11621
|
-
lines.push(spent > 0 ?
|
|
13050
|
+
const line = `${windowLabel(u).padEnd(width)} ${amount(spent)} ${chalk35.dim("credits")}`;
|
|
13051
|
+
lines.push(spent > 0 ? chalk35.bold(line) : chalk35.dim(line));
|
|
11622
13052
|
for (const t of costly(u)) {
|
|
11623
13053
|
lines.push(` ${t.type.padEnd(width - 2)} ${amount(t.dailyCredits ?? 0)}`);
|
|
11624
13054
|
}
|
|
11625
13055
|
}
|
|
11626
13056
|
lines.push("");
|
|
11627
|
-
lines.push(
|
|
13057
|
+
lines.push(chalk35.bold(`${totalLabel.padEnd(width)} ${amount(total)} ${chalk35.dim("credits")}`));
|
|
11628
13058
|
return lines;
|
|
11629
13059
|
}
|
|
11630
13060
|
function registerUtilizationCommand(program) {
|
|
@@ -11780,7 +13210,7 @@ Examples:
|
|
|
11780
13210
|
}
|
|
11781
13211
|
|
|
11782
13212
|
// src/commands/invoice/index.ts
|
|
11783
|
-
import * as
|
|
13213
|
+
import * as fs14 from "fs";
|
|
11784
13214
|
function getOutputFormat26(cmd) {
|
|
11785
13215
|
const config = loadConfig();
|
|
11786
13216
|
const globalOpts = cmd.optsWithGlobals();
|
|
@@ -11818,7 +13248,7 @@ Examples:
|
|
|
11818
13248
|
const response = await api.admin.downloadInvoice(invoiceNumber, fileName);
|
|
11819
13249
|
const buffer = Buffer.from(await response.arrayBuffer());
|
|
11820
13250
|
const outPath = options.out ?? fileName;
|
|
11821
|
-
|
|
13251
|
+
fs14.writeFileSync(outPath, buffer);
|
|
11822
13252
|
success(`Invoice saved to ${outPath}`);
|
|
11823
13253
|
} catch (error) {
|
|
11824
13254
|
handleError(error);
|
|
@@ -11827,8 +13257,8 @@ Examples:
|
|
|
11827
13257
|
}
|
|
11828
13258
|
|
|
11829
13259
|
// src/commands/shell/index.ts
|
|
11830
|
-
import
|
|
11831
|
-
import * as
|
|
13260
|
+
import chalk36 from "chalk";
|
|
13261
|
+
import * as fs15 from "fs";
|
|
11832
13262
|
import * as os4 from "os";
|
|
11833
13263
|
import * as path10 from "path";
|
|
11834
13264
|
import { spawn as spawn3 } from "child_process";
|
|
@@ -11844,15 +13274,15 @@ function extensionFor2(language) {
|
|
|
11844
13274
|
}
|
|
11845
13275
|
async function openInEditor(initial, ext) {
|
|
11846
13276
|
const tmpFile = path10.join(os4.tmpdir(), `diafunc-shell-${randomUUID4()}.${ext}`);
|
|
11847
|
-
|
|
13277
|
+
fs15.writeFileSync(tmpFile, initial);
|
|
11848
13278
|
const editor = process.env.VISUAL ?? process.env.EDITOR ?? "vi";
|
|
11849
13279
|
await new Promise((resolve2, reject) => {
|
|
11850
13280
|
const child = spawn3(editor, [tmpFile], { stdio: "inherit" });
|
|
11851
13281
|
child.on("exit", (code) => code === 0 ? resolve2() : reject(new Error(`Editor exited with ${code}`)));
|
|
11852
13282
|
child.on("error", reject);
|
|
11853
13283
|
});
|
|
11854
|
-
const content =
|
|
11855
|
-
|
|
13284
|
+
const content = fs15.readFileSync(tmpFile, "utf-8");
|
|
13285
|
+
fs15.unlinkSync(tmpFile);
|
|
11856
13286
|
return content;
|
|
11857
13287
|
}
|
|
11858
13288
|
function utcNowParts() {
|
|
@@ -11893,21 +13323,21 @@ async function evaluate(api, fnRef, language, sourceCode) {
|
|
|
11893
13323
|
}, false);
|
|
11894
13324
|
if (result.outputs?.length) {
|
|
11895
13325
|
for (const out of result.outputs) {
|
|
11896
|
-
console.log(
|
|
13326
|
+
console.log(chalk36.dim(` [${out.type}]`) + " " + out.output);
|
|
11897
13327
|
}
|
|
11898
13328
|
}
|
|
11899
13329
|
if (result.successful) {
|
|
11900
13330
|
if (result.result) {
|
|
11901
|
-
console.log(
|
|
13331
|
+
console.log(chalk36.green("=>") + " " + resultText(result.result, result.resultEncoding));
|
|
11902
13332
|
} else {
|
|
11903
|
-
console.log(
|
|
13333
|
+
console.log(chalk36.dim("=> (no value)"));
|
|
11904
13334
|
}
|
|
11905
13335
|
const duration = result.completed - result.started;
|
|
11906
|
-
console.log(
|
|
13336
|
+
console.log(chalk36.dim(` [${duration}ms \xB7 ${evaluationId}]`));
|
|
11907
13337
|
} else {
|
|
11908
|
-
console.log(
|
|
13338
|
+
console.log(chalk36.red("error: ") + result.error);
|
|
11909
13339
|
if (result.lineNumber > 0) {
|
|
11910
|
-
console.log(
|
|
13340
|
+
console.log(chalk36.dim(` at line ${result.lineNumber}, col ${result.columnNumber}`));
|
|
11911
13341
|
}
|
|
11912
13342
|
}
|
|
11913
13343
|
}
|
|
@@ -11928,19 +13358,19 @@ function registerShellCommand(program) {
|
|
|
11928
13358
|
});
|
|
11929
13359
|
const api = createApiClient();
|
|
11930
13360
|
const { input: promptInput } = await import("@inquirer/prompts");
|
|
11931
|
-
const { getUpdateNotice } = await import("./update-check-
|
|
13361
|
+
const { getUpdateNotice } = await import("./update-check-KHHHTIDF.js");
|
|
11932
13362
|
const resolvedLanguage = await resolveLanguage(api, fnRef.projectId, options.language);
|
|
11933
|
-
console.log(
|
|
11934
|
-
console.log(
|
|
11935
|
-
console.log(
|
|
13363
|
+
console.log(chalk36.bold("Diafunc shell") + chalk36.dim(` \xB7 function ${fnRef.entityId} \xB7 ${resolvedLanguage}`));
|
|
13364
|
+
console.log(chalk36.dim(`Endpoint: ${config.profiles[config.currentProfile]?.endpoint}`));
|
|
13365
|
+
console.log(chalk36.dim("Commands: /edit (multi-line in $EDITOR), /lang <name>, /file <path>, /help, /quit"));
|
|
11936
13366
|
const notice = await getUpdateNotice();
|
|
11937
|
-
if (notice) console.log(
|
|
13367
|
+
if (notice) console.log(chalk36.dim(notice));
|
|
11938
13368
|
console.log();
|
|
11939
13369
|
let language = resolvedLanguage;
|
|
11940
13370
|
for (; ; ) {
|
|
11941
13371
|
let line;
|
|
11942
13372
|
try {
|
|
11943
|
-
line = await promptInput({ message:
|
|
13373
|
+
line = await promptInput({ message: chalk36.cyan.bold(`${language} >`) });
|
|
11944
13374
|
} catch {
|
|
11945
13375
|
console.log();
|
|
11946
13376
|
return;
|
|
@@ -11958,54 +13388,54 @@ function registerShellCommand(program) {
|
|
|
11958
13388
|
case "help":
|
|
11959
13389
|
case "h":
|
|
11960
13390
|
case "?":
|
|
11961
|
-
console.log(
|
|
11962
|
-
console.log(
|
|
11963
|
-
console.log(
|
|
11964
|
-
console.log(
|
|
13391
|
+
console.log(chalk36.dim(" /edit open $EDITOR for multi-line code"));
|
|
13392
|
+
console.log(chalk36.dim(" /file <path> evaluate the contents of a file"));
|
|
13393
|
+
console.log(chalk36.dim(" /lang <name> switch language (Java, JavaScript, Kotlin, Python, Scala)"));
|
|
13394
|
+
console.log(chalk36.dim(" /quit exit the shell"));
|
|
11965
13395
|
continue;
|
|
11966
13396
|
case "lang":
|
|
11967
13397
|
if (arg) language = arg;
|
|
11968
|
-
console.log(
|
|
13398
|
+
console.log(chalk36.dim(`Language: ${language}`));
|
|
11969
13399
|
continue;
|
|
11970
13400
|
case "edit": {
|
|
11971
13401
|
const sourceCode = await openInEditor("", extensionFor2(language));
|
|
11972
13402
|
if (!sourceCode.trim()) {
|
|
11973
|
-
console.log(
|
|
13403
|
+
console.log(chalk36.dim("(empty; not evaluated)"));
|
|
11974
13404
|
continue;
|
|
11975
13405
|
}
|
|
11976
13406
|
try {
|
|
11977
13407
|
await evaluate(api, fnRef, language, sourceCode);
|
|
11978
13408
|
} catch (e) {
|
|
11979
|
-
console.error(
|
|
13409
|
+
console.error(chalk36.red(e.message));
|
|
11980
13410
|
}
|
|
11981
13411
|
continue;
|
|
11982
13412
|
}
|
|
11983
13413
|
case "file": {
|
|
11984
13414
|
if (!arg) {
|
|
11985
|
-
console.log(
|
|
13415
|
+
console.log(chalk36.dim("usage: /file <path>"));
|
|
11986
13416
|
continue;
|
|
11987
13417
|
}
|
|
11988
|
-
if (!
|
|
11989
|
-
console.log(
|
|
13418
|
+
if (!fs15.existsSync(arg)) {
|
|
13419
|
+
console.log(chalk36.red(`file not found: ${arg}`));
|
|
11990
13420
|
continue;
|
|
11991
13421
|
}
|
|
11992
|
-
const sourceCode =
|
|
13422
|
+
const sourceCode = fs15.readFileSync(arg, "utf-8");
|
|
11993
13423
|
try {
|
|
11994
13424
|
await evaluate(api, fnRef, language, sourceCode);
|
|
11995
13425
|
} catch (e) {
|
|
11996
|
-
console.error(
|
|
13426
|
+
console.error(chalk36.red(e.message));
|
|
11997
13427
|
}
|
|
11998
13428
|
continue;
|
|
11999
13429
|
}
|
|
12000
13430
|
default:
|
|
12001
|
-
console.log(
|
|
13431
|
+
console.log(chalk36.dim(`Unknown command: /${cmd2}. Try /help.`));
|
|
12002
13432
|
continue;
|
|
12003
13433
|
}
|
|
12004
13434
|
}
|
|
12005
13435
|
try {
|
|
12006
13436
|
await evaluate(api, fnRef, language, trimmed);
|
|
12007
13437
|
} catch (e) {
|
|
12008
|
-
console.error(
|
|
13438
|
+
console.error(chalk36.red(e.message));
|
|
12009
13439
|
}
|
|
12010
13440
|
}
|
|
12011
13441
|
} catch (error) {
|
|
@@ -12015,19 +13445,19 @@ function registerShellCommand(program) {
|
|
|
12015
13445
|
}
|
|
12016
13446
|
|
|
12017
13447
|
// src/commands/update/index.ts
|
|
12018
|
-
import
|
|
13448
|
+
import chalk37 from "chalk";
|
|
12019
13449
|
import * as path11 from "path";
|
|
12020
13450
|
import { spawn as spawn4 } from "child_process";
|
|
12021
13451
|
|
|
12022
13452
|
// src/util/install-method.ts
|
|
12023
|
-
import * as
|
|
13453
|
+
import * as fs16 from "fs";
|
|
12024
13454
|
function detectInstall() {
|
|
12025
13455
|
const exec = process.execPath;
|
|
12026
13456
|
const exe = exec.replace(/\\/g, "/").toLowerCase();
|
|
12027
13457
|
const isNode = exe.endsWith("/node") || exe.endsWith("/node.exe");
|
|
12028
13458
|
return {
|
|
12029
13459
|
method: isNode ? "npm" : "binary",
|
|
12030
|
-
binaryPath: isNode ? exec :
|
|
13460
|
+
binaryPath: isNode ? exec : fs16.realpathSync(exec)
|
|
12031
13461
|
};
|
|
12032
13462
|
}
|
|
12033
13463
|
|
|
@@ -12061,14 +13491,14 @@ function registerUpdateCommand(program) {
|
|
|
12061
13491
|
const install = detectInstall();
|
|
12062
13492
|
const latest = await fetchLatestVersion();
|
|
12063
13493
|
if (latest === package_default.version) {
|
|
12064
|
-
console.log(
|
|
13494
|
+
console.log(chalk37.dim(`diafunc is already at the latest version (${package_default.version}).`));
|
|
12065
13495
|
return;
|
|
12066
13496
|
}
|
|
12067
|
-
console.log(
|
|
13497
|
+
console.log(chalk37.dim(`Current: ${package_default.version} \u2192 Available: ${latest}`));
|
|
12068
13498
|
if (install.method === "npm") {
|
|
12069
13499
|
console.log();
|
|
12070
13500
|
console.log("Installed via npm. Upgrade with:");
|
|
12071
|
-
console.log(
|
|
13501
|
+
console.log(chalk37.bold(` npm install -g @diafunc/cli@${latest}`));
|
|
12072
13502
|
return;
|
|
12073
13503
|
}
|
|
12074
13504
|
const installDir = path11.dirname(install.binaryPath);
|
|
@@ -12082,9 +13512,9 @@ function registerUpdateCommand(program) {
|
|
|
12082
13512
|
}
|
|
12083
13513
|
|
|
12084
13514
|
// src/commands/uninstall/index.ts
|
|
12085
|
-
import
|
|
13515
|
+
import chalk38 from "chalk";
|
|
12086
13516
|
import { spawn as spawn5 } from "child_process";
|
|
12087
|
-
import * as
|
|
13517
|
+
import * as fs17 from "fs";
|
|
12088
13518
|
import * as os5 from "os";
|
|
12089
13519
|
import * as path12 from "path";
|
|
12090
13520
|
function registerUninstallCommand(program) {
|
|
@@ -12094,11 +13524,11 @@ function registerUninstallCommand(program) {
|
|
|
12094
13524
|
const configDir = path12.join(os5.homedir(), ".diafunc");
|
|
12095
13525
|
if (install.method === "npm") {
|
|
12096
13526
|
console.log("Installed via npm. Remove with:");
|
|
12097
|
-
console.log(
|
|
12098
|
-
if (
|
|
13527
|
+
console.log(chalk38.bold(" npm uninstall -g @diafunc/cli"));
|
|
13528
|
+
if (fs17.existsSync(configDir)) {
|
|
12099
13529
|
console.log();
|
|
12100
13530
|
console.log(`Config and credentials live at ${configDir}. Remove them manually with:`);
|
|
12101
|
-
console.log(
|
|
13531
|
+
console.log(chalk38.bold(` rm -rf ${configDir}`));
|
|
12102
13532
|
}
|
|
12103
13533
|
return;
|
|
12104
13534
|
}
|
|
@@ -12108,19 +13538,19 @@ function registerUninstallCommand(program) {
|
|
|
12108
13538
|
default: false
|
|
12109
13539
|
});
|
|
12110
13540
|
if (!removeBinary) {
|
|
12111
|
-
console.log(
|
|
13541
|
+
console.log(chalk38.dim("Aborted."));
|
|
12112
13542
|
return;
|
|
12113
13543
|
}
|
|
12114
13544
|
let removeConfig = options.purge ?? false;
|
|
12115
|
-
if (!options.purge && !options.yes &&
|
|
13545
|
+
if (!options.purge && !options.yes && fs17.existsSync(configDir)) {
|
|
12116
13546
|
removeConfig = await confirm({
|
|
12117
13547
|
message: `Also remove ${configDir} (config + credentials)?`,
|
|
12118
13548
|
default: false
|
|
12119
13549
|
});
|
|
12120
13550
|
}
|
|
12121
|
-
if (removeConfig &&
|
|
12122
|
-
|
|
12123
|
-
console.log(
|
|
13551
|
+
if (removeConfig && fs17.existsSync(configDir)) {
|
|
13552
|
+
fs17.rmSync(configDir, { recursive: true, force: true });
|
|
13553
|
+
console.log(chalk38.dim(`Removed ${configDir}`));
|
|
12124
13554
|
}
|
|
12125
13555
|
if (process.platform === "win32") {
|
|
12126
13556
|
const cmd = `timeout /t 2 /nobreak >nul & del /f /q "${install.binaryPath}"`;
|
|
@@ -12130,13 +13560,13 @@ function registerUninstallCommand(program) {
|
|
|
12130
13560
|
windowsHide: true
|
|
12131
13561
|
});
|
|
12132
13562
|
child.unref();
|
|
12133
|
-
console.log(
|
|
13563
|
+
console.log(chalk38.dim(`Removing ${install.binaryPath} on exit...`));
|
|
12134
13564
|
console.log();
|
|
12135
13565
|
console.log("diafunc uninstalled.");
|
|
12136
13566
|
return;
|
|
12137
13567
|
}
|
|
12138
|
-
|
|
12139
|
-
console.log(
|
|
13568
|
+
fs17.rmSync(install.binaryPath, { force: true });
|
|
13569
|
+
console.log(chalk38.dim(`Removed ${install.binaryPath}`));
|
|
12140
13570
|
console.log();
|
|
12141
13571
|
console.log("diafunc uninstalled.");
|
|
12142
13572
|
} catch (error) {
|
|
@@ -12146,9 +13576,9 @@ function registerUninstallCommand(program) {
|
|
|
12146
13576
|
}
|
|
12147
13577
|
|
|
12148
13578
|
// src/prompting/command.ts
|
|
12149
|
-
import { Command } from "commander";
|
|
12150
|
-
var commanderOriginal =
|
|
12151
|
-
var DiafuncCommand = class _DiafuncCommand extends
|
|
13579
|
+
import { Command as Command2 } from "commander";
|
|
13580
|
+
var commanderOriginal = Command2.prototype;
|
|
13581
|
+
var DiafuncCommand = class _DiafuncCommand extends Command2 {
|
|
12152
13582
|
/** Gaps recorded during the current parse, in the order commander found them. */
|
|
12153
13583
|
pendingInputs = [];
|
|
12154
13584
|
/** Set on the program only; every command reads it from there. */
|
|
@@ -12200,210 +13630,11 @@ var DiafuncCommand = class _DiafuncCommand extends Command {
|
|
|
12200
13630
|
};
|
|
12201
13631
|
|
|
12202
13632
|
// src/prompting/fill.ts
|
|
12203
|
-
import
|
|
12204
|
-
|
|
12205
|
-
// src/prompting/resolvers.ts
|
|
12206
|
-
var PROJECT_ROLES = ["OWNER", "ADMIN", "DEVELOPER", "GUEST"];
|
|
12207
|
-
var TRIGGER_TYPES = ["SCHEDULE", "EVENT", "LINK", "MANUAL"];
|
|
12208
|
-
var ANALYSIS_TRIGGER_KINDS = ["ONCE", "CRON"];
|
|
12209
|
-
var VISIBILITIES = ["PRIVATE", "PUBLIC"];
|
|
12210
|
-
var SHELLS = ["bash", "zsh", "fish"];
|
|
12211
|
-
var CONFIG_KEYS = ["defaults.project", "defaults.branch", "defaults.output"];
|
|
12212
|
-
var ENTITY_TYPE_BY_GROUP = {
|
|
12213
|
-
table: "table",
|
|
12214
|
-
function: "function",
|
|
12215
|
-
trigger: "function",
|
|
12216
|
-
schedule: "function"
|
|
12217
|
-
};
|
|
12218
|
-
var TEXT = { kind: "text" };
|
|
12219
|
-
var TEXT_OR_EMPTY = { kind: "text", allowEmpty: true };
|
|
12220
|
-
var POSITIVE = { kind: "number", min: 0, integer: false, exclusive: true };
|
|
12221
|
-
var INDEX = { kind: "number", min: 0, integer: true };
|
|
12222
|
-
var BY_COMMAND = {
|
|
12223
|
-
"analyze segment": { "<name>": { kind: "analysisColumns", multiple: false, allowEmpty: true } },
|
|
12224
|
-
"analyze targets": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: false } },
|
|
12225
|
-
"analyze input-exclusions": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: true } },
|
|
12226
|
-
"analyze confirmed-inputs": { "<column>": { kind: "analysisColumns", multiple: true, allowEmpty: true } },
|
|
12227
|
-
"analyze questions": { "<question>": TEXT_OR_EMPTY },
|
|
12228
|
-
"analyze description": { "<text>": TEXT_OR_EMPTY },
|
|
12229
|
-
"analyze introduction": { "<markdown>": TEXT_OR_EMPTY },
|
|
12230
|
-
// Not the analysis picker: that one offers the reader's own analyses, and this command needs no account.
|
|
12231
|
-
"public show": { "<analysisId>": TEXT },
|
|
12232
|
-
"analyze presets save": { "--targets": TEXT, "--hours": POSITIVE, "--budget": POSITIVE },
|
|
12233
|
-
"branch merge": {
|
|
12234
|
-
"--source": { kind: "entity", form: "ref" },
|
|
12235
|
-
"--target": { kind: "project", withBranch: true }
|
|
12236
|
-
},
|
|
12237
|
-
"branch create": { "<branchName>": TEXT },
|
|
12238
|
-
"branch delete": { "<branchName>": { kind: "projectBranch", projectFrom: "projectId" } },
|
|
12239
|
-
"admin backup restore-project": { "<projectBranch>": { kind: "projectBranch", projectFrom: "projectId" } },
|
|
12240
|
-
"data-sources create": {
|
|
12241
|
-
"--project-id": { kind: "project", withBranch: false },
|
|
12242
|
-
"--project-branch": { kind: "projectBranch", projectFrom: "projectId" },
|
|
12243
|
-
"--target-entity-id": { kind: "entity", form: "id", contentType: "table", projectFrom: "projectId" },
|
|
12244
|
-
"--target-entity-branch": { kind: "text", defaultValue: "main" },
|
|
12245
|
-
"--type": { kind: "connectorType" }
|
|
12246
|
-
},
|
|
12247
|
-
"table-exporters create": {
|
|
12248
|
-
"--function-project": { kind: "project", withBranch: false },
|
|
12249
|
-
"--function-entity": { kind: "entity", form: "id", contentType: "function", projectFrom: "functionProject" },
|
|
12250
|
-
"--format": TEXT
|
|
12251
|
-
},
|
|
12252
|
-
"table exports get": { "--ref": { kind: "entity", form: "ref", contentType: "table" } },
|
|
12253
|
-
"table export": { "<format>": { kind: "exportFormat" } },
|
|
12254
|
-
"entity export": { "<entityIds>": { kind: "entity", form: "id", projectFrom: "project", multiple: true } },
|
|
12255
|
-
"notebook export": {
|
|
12256
|
-
"<notebookIds>": { kind: "entity", form: "id", contentType: "notebook", projectFrom: "project", multiple: true }
|
|
12257
|
-
},
|
|
12258
|
-
"entity tags set": { "<tags>": TEXT_OR_EMPTY },
|
|
12259
|
-
"project tags set": { "<tags>": TEXT_OR_EMPTY },
|
|
12260
|
-
"admin curated-tags create": { "--display-name": TEXT },
|
|
12261
|
-
"link delete": { "<linkId>": { kind: "link" } },
|
|
12262
|
-
"link create": { "<linkId>": TEXT },
|
|
12263
|
-
"config profile use": { "<name>": { kind: "profile" } },
|
|
12264
|
-
"config profile remove": { "<name>": { kind: "profile" } },
|
|
12265
|
-
"config get": { "<key>": { kind: "choice", choices: CONFIG_KEYS } },
|
|
12266
|
-
"config set": { "<key>": { kind: "choice", choices: CONFIG_KEYS } },
|
|
12267
|
-
"project members invite": { "<userId>": TEXT, "<role>": { kind: "choice", choices: PROJECT_ROLES } },
|
|
12268
|
-
"project members join": { "<userId>": TEXT },
|
|
12269
|
-
"trigger create": { "--type": { kind: "choice", choices: TRIGGER_TYPES } },
|
|
12270
|
-
"analyze triggers create": { "--kind": { kind: "choice", choices: ANALYSIS_TRIGGER_KINDS } },
|
|
12271
|
-
"function outputs": { "<evaluationId>": TEXT },
|
|
12272
|
-
"team create": { "--seats": { kind: "number", min: 1, integer: true } },
|
|
12273
|
-
"team seats preview": { "<count>": { kind: "number", min: 1, integer: true } },
|
|
12274
|
-
"team seats set": { "<count>": { kind: "number", min: 1, integer: true } }
|
|
12275
|
-
};
|
|
12276
|
-
var BY_NAME = {
|
|
12277
|
-
projectId: { kind: "project", withBranch: false },
|
|
12278
|
-
projectRef: { kind: "project", withBranch: true },
|
|
12279
|
-
project: { kind: "project", withBranch: true },
|
|
12280
|
-
teamId: { kind: "team" },
|
|
12281
|
-
invitationId: { kind: "teamInvitation" },
|
|
12282
|
-
analysisId: { kind: "analysis" },
|
|
12283
|
-
licenceId: { kind: "licence" },
|
|
12284
|
-
sessionId: { kind: "chatSession" },
|
|
12285
|
-
tokenId: { kind: "apiToken" },
|
|
12286
|
-
resource: { kind: "tokenResource" },
|
|
12287
|
-
scopes: { kind: "choices", choices: VALID_SCOPES },
|
|
12288
|
-
evaluationId: { kind: "evaluation" },
|
|
12289
|
-
eventId: { kind: "event" },
|
|
12290
|
-
occurrenceId: { kind: "occurrence" },
|
|
12291
|
-
exportId: { kind: "tableExport" },
|
|
12292
|
-
invoiceNumber: { kind: "invoice" },
|
|
12293
|
-
fileName: { kind: "invoiceDocument" },
|
|
12294
|
-
shell: { kind: "choice", choices: SHELLS },
|
|
12295
|
-
vis: { kind: "choice", choices: VISIBILITIES },
|
|
12296
|
-
kind: { kind: "choice", choices: ANALYSIS_TRIGGER_KINDS },
|
|
12297
|
-
date: { kind: "date" },
|
|
12298
|
-
file: { kind: "file" },
|
|
12299
|
-
email: { kind: "text", email: true },
|
|
12300
|
-
index: INDEX,
|
|
12301
|
-
row: INDEX,
|
|
12302
|
-
col: INDEX,
|
|
12303
|
-
count: INDEX,
|
|
12304
|
-
version: { kind: "number", min: 1, integer: true },
|
|
12305
|
-
hours: POSITIVE,
|
|
12306
|
-
credits: POSITIVE,
|
|
12307
|
-
seats: { kind: "number", min: 1, integer: true },
|
|
12308
|
-
value: TEXT_OR_EMPTY,
|
|
12309
|
-
// Free text: names, messages and ids the reader is creating rather than choosing.
|
|
12310
|
-
name: TEXT,
|
|
12311
|
-
tag: TEXT,
|
|
12312
|
-
tags: TEXT,
|
|
12313
|
-
newId: TEXT,
|
|
12314
|
-
message: TEXT,
|
|
12315
|
-
query: TEXT,
|
|
12316
|
-
title: TEXT,
|
|
12317
|
-
token: TEXT,
|
|
12318
|
-
subscriptionToken: TEXT,
|
|
12319
|
-
forkProjectId: TEXT,
|
|
12320
|
-
targetBranch: TEXT,
|
|
12321
|
-
bucketName: TEXT,
|
|
12322
|
-
objectName: TEXT,
|
|
12323
|
-
template: TEXT,
|
|
12324
|
-
plan: TEXT,
|
|
12325
|
-
schedule: TEXT,
|
|
12326
|
-
consumerType: TEXT,
|
|
12327
|
-
consumerId: TEXT,
|
|
12328
|
-
format: TEXT,
|
|
12329
|
-
key: TEXT
|
|
12330
|
-
};
|
|
12331
|
-
function tokenOf(input) {
|
|
12332
|
-
return input.kind === "option" ? input.flag ?? `--${input.name}` : `<${input.name}>`;
|
|
12333
|
-
}
|
|
12334
|
-
function specFor(path13, input) {
|
|
12335
|
-
const exact = BY_COMMAND[path13]?.[tokenOf(input)];
|
|
12336
|
-
if (exact) return exact;
|
|
12337
|
-
const group = path13.split(" ")[0];
|
|
12338
|
-
const sub = path13.split(" ").slice(0, 2).join(" ");
|
|
12339
|
-
switch (input.name) {
|
|
12340
|
-
case "ref":
|
|
12341
|
-
case "sourceRef":
|
|
12342
|
-
case "targetRef":
|
|
12343
|
-
return { kind: "entity", form: "ref", contentType: ENTITY_TYPE_BY_GROUP[group] };
|
|
12344
|
-
case "userId":
|
|
12345
|
-
return group === "team" ? { kind: "teamMember" } : { kind: "projectMember" };
|
|
12346
|
-
case "id":
|
|
12347
|
-
if (sub === "analyze presets") return { kind: "preset" };
|
|
12348
|
-
if (group === "analyze") return { kind: "analysis" };
|
|
12349
|
-
if (group === "data-sources") return { kind: "dataSource" };
|
|
12350
|
-
if (group === "skeleton") return { kind: "skeleton" };
|
|
12351
|
-
if (group === "table-exporters") return { kind: "tableExporter" };
|
|
12352
|
-
if (group === "status") return { kind: "statusComponent" };
|
|
12353
|
-
return null;
|
|
12354
|
-
case "runId":
|
|
12355
|
-
if (group === "analyze") return { kind: "analysisRun" };
|
|
12356
|
-
if (group === "data-sources") return { kind: "dataSourceRun" };
|
|
12357
|
-
return null;
|
|
12358
|
-
case "triggerId":
|
|
12359
|
-
if (group === "analyze") return { kind: "analysisTrigger" };
|
|
12360
|
-
if (group === "trigger") return { kind: "functionTrigger" };
|
|
12361
|
-
return null;
|
|
12362
|
-
case "role":
|
|
12363
|
-
return { kind: "choice", choices: PROJECT_ROLES };
|
|
12364
|
-
case "type":
|
|
12365
|
-
return null;
|
|
12366
|
-
default:
|
|
12367
|
-
return BY_NAME[input.name] ?? null;
|
|
12368
|
-
}
|
|
12369
|
-
}
|
|
12370
|
-
function dependencies(spec) {
|
|
12371
|
-
switch (spec.kind) {
|
|
12372
|
-
case "teamMember":
|
|
12373
|
-
case "teamInvitation":
|
|
12374
|
-
return ["teamId"];
|
|
12375
|
-
case "projectMember":
|
|
12376
|
-
return ["projectId"];
|
|
12377
|
-
case "analysisColumns":
|
|
12378
|
-
return ["id"];
|
|
12379
|
-
case "evaluation":
|
|
12380
|
-
return ["ref", "date"];
|
|
12381
|
-
case "functionTrigger":
|
|
12382
|
-
case "event":
|
|
12383
|
-
case "tableExport":
|
|
12384
|
-
return ["ref"];
|
|
12385
|
-
case "occurrence":
|
|
12386
|
-
return ["ref", "eventId"];
|
|
12387
|
-
case "link":
|
|
12388
|
-
return ["sourceRef"];
|
|
12389
|
-
case "tokenResource":
|
|
12390
|
-
return ["resourceType"];
|
|
12391
|
-
case "dataSourceRun":
|
|
12392
|
-
return ["id"];
|
|
12393
|
-
case "invoiceDocument":
|
|
12394
|
-
return ["invoiceNumber"];
|
|
12395
|
-
case "projectBranch":
|
|
12396
|
-
return [spec.projectFrom];
|
|
12397
|
-
case "entity":
|
|
12398
|
-
return spec.projectFrom ? [spec.projectFrom] : [];
|
|
12399
|
-
default:
|
|
12400
|
-
return [];
|
|
12401
|
-
}
|
|
12402
|
-
}
|
|
13633
|
+
import chalk40 from "chalk";
|
|
12403
13634
|
|
|
12404
13635
|
// src/prompting/pickers.ts
|
|
12405
|
-
import * as
|
|
12406
|
-
import
|
|
13636
|
+
import * as fs18 from "fs";
|
|
13637
|
+
import chalk39 from "chalk";
|
|
12407
13638
|
var SEARCH_THRESHOLD = 10;
|
|
12408
13639
|
var TYPE_IT = "\0type-it";
|
|
12409
13640
|
async function askFor(spec, input, ctx) {
|
|
@@ -12491,7 +13722,7 @@ async function askFor(spec, input, ctx) {
|
|
|
12491
13722
|
const invoices = await ctx.api().admin.getInvoices();
|
|
12492
13723
|
for (const i of invoices) ctx.prefill.set(`invoiceKind:${i.invoiceNumber}`, i.kind ?? "INVOICE");
|
|
12493
13724
|
return invoices.map((i) => ({
|
|
12494
|
-
label: `#${i.invoiceNumber} ${i.periodFrom ?? ""}
|
|
13725
|
+
label: `#${i.invoiceNumber} ${i.periodFrom ?? ""} to ${i.periodTo ?? ""}`,
|
|
12495
13726
|
value: String(i.invoiceNumber),
|
|
12496
13727
|
hint: `${i.status ?? ""} \xB7 ${i.total ?? ""} ${i.currency ?? ""}`.trim()
|
|
12497
13728
|
}));
|
|
@@ -12525,8 +13756,8 @@ async function askFor(spec, input, ctx) {
|
|
|
12525
13756
|
return listed(ctx, "profiles", messageFor(input, "Profile"), async () => Object.keys(loadConfig().profiles).map((p) => ({ label: p, value: p })));
|
|
12526
13757
|
case "statusComponent":
|
|
12527
13758
|
return listed(ctx, "components", messageFor(input, "Component"), async () => (await createStatusService().getComponents()).map((c) => ({ label: c.id, value: c.id, hint: `${c.state} \xB7 ${c.domainId}` })));
|
|
12528
|
-
case "
|
|
12529
|
-
return listed(ctx, "
|
|
13759
|
+
case "license":
|
|
13760
|
+
return listed(ctx, "licenses", messageFor(input, "License"), async () => (await ctx.api().admin.listLicenses()).map((l) => ({ label: l.name, value: l.licenceId, hint: `${l.state.toLowerCase()} \xB7 ${l.licenceId}` })));
|
|
12530
13761
|
case "choice":
|
|
12531
13762
|
return choose(ctx, question(input), spec.choices.map((c) => ({ label: c, value: c })));
|
|
12532
13763
|
case "choices": {
|
|
@@ -12539,7 +13770,7 @@ async function askFor(spec, input, ctx) {
|
|
|
12539
13770
|
}
|
|
12540
13771
|
case "file":
|
|
12541
13772
|
return typed(ctx, question(input), {
|
|
12542
|
-
validate: (value) =>
|
|
13773
|
+
validate: (value) => fs18.existsSync(value.trim()) || `No file at ${value.trim()}.`
|
|
12543
13774
|
});
|
|
12544
13775
|
case "number":
|
|
12545
13776
|
return typed(ctx, question(input), { validate: numberRule(spec) });
|
|
@@ -12753,7 +13984,7 @@ function typedValue(ctx, message) {
|
|
|
12753
13984
|
return typed(ctx, message);
|
|
12754
13985
|
}
|
|
12755
13986
|
function typeItChoice() {
|
|
12756
|
-
return { name:
|
|
13987
|
+
return { name: chalk39.dim("Type it instead"), value: TYPE_IT };
|
|
12757
13988
|
}
|
|
12758
13989
|
function text(ctx, name) {
|
|
12759
13990
|
const value = ctx.known.get(name);
|
|
@@ -12783,7 +14014,7 @@ function capitalize(value) {
|
|
|
12783
14014
|
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
12784
14015
|
}
|
|
12785
14016
|
function labelled(label, hint2) {
|
|
12786
|
-
return hint2 && hint2 !== label ? `${label} ${
|
|
14017
|
+
return hint2 && hint2 !== label ? `${label} ${chalk39.dim(hint2)}` : label;
|
|
12787
14018
|
}
|
|
12788
14019
|
function numberRule(spec) {
|
|
12789
14020
|
return (raw) => {
|
|
@@ -12829,7 +14060,7 @@ async function fillPendingInputs(actionCommand) {
|
|
|
12829
14060
|
known: knownValues(actionCommand),
|
|
12830
14061
|
globals: actionCommand.optsWithGlobals(),
|
|
12831
14062
|
prefill: /* @__PURE__ */ new Map(),
|
|
12832
|
-
note: (line) => process.stderr.write(
|
|
14063
|
+
note: (line) => process.stderr.write(chalk40.dim(` ${line}
|
|
12833
14064
|
`))
|
|
12834
14065
|
};
|
|
12835
14066
|
for (const item of orderByDependencies(pending)) {
|
|
@@ -12838,7 +14069,7 @@ async function fillPendingInputs(actionCommand) {
|
|
|
12838
14069
|
ctx.known.set(item.input.name, value);
|
|
12839
14070
|
}
|
|
12840
14071
|
const log = env.log ?? ((line) => console.log(line));
|
|
12841
|
-
log(
|
|
14072
|
+
log(chalk40.dim(` Equivalent: ${equivalentCommand(actionCommand)}`));
|
|
12842
14073
|
}
|
|
12843
14074
|
function commandChain(cmd) {
|
|
12844
14075
|
const chain = [];
|
|
@@ -12935,7 +14166,7 @@ Docs: https://diafunc.com/documentation
|
|
|
12935
14166
|
function createProgram(environment = {}) {
|
|
12936
14167
|
const program = new DiafuncCommand();
|
|
12937
14168
|
program.promptEnvironment = environment;
|
|
12938
|
-
program.name("diafunc").description("Diafunc CLI: the command-line interface for the Diafunc platform").version(package_default.version).option("-p, --profile <name>", "Profile to use").option("-o, --output <format>", "Output format: human, json, table (default: human)").option("--project <id>", "Project to work in (overrides defaults.project)").option("--branch <name>", "Project branch (overrides defaults.branch)").option("--dry-run", "Preview mutating operations without executing them").option("--verbose", "Echo every HTTP request to stderr").option("--no-color", "Disable
|
|
14169
|
+
program.name("diafunc").description("Diafunc CLI: the command-line interface for the Diafunc platform").version(package_default.version).option("-p, --profile <name>", "Profile to use").option("-o, --output <format>", "Output format: human, json, table (default: human)").option("--project <id>", "Project to work in (overrides defaults.project)").option("--branch <name>", "Project branch (overrides defaults.branch)").option("--dry-run", "Preview mutating operations without executing them").option("--verbose", "Echo every HTTP request to stderr").option("--no-color", "Disable colored output").option("--no-interactive", "Never prompt: a missing required input fails as it would in a script").showSuggestionAfterError().showHelpAfterError(`(run 'diafunc --help' to see the available commands)`).configureHelp({ showGlobalOptions: true, ...HIDDEN_ALIAS_HELP }).configureOutput({
|
|
12939
14170
|
// Commander writes usage errors to stdout by default, which puts a complaint in the middle
|
|
12940
14171
|
// of whatever a caller was capturing.
|
|
12941
14172
|
writeErr: (str) => process.stderr.write(str)
|
|
@@ -12943,7 +14174,7 @@ function createProgram(environment = {}) {
|
|
|
12943
14174
|
const opts = thisCommand.optsWithGlobals();
|
|
12944
14175
|
if (opts.dryRun) setDryRun(true);
|
|
12945
14176
|
if (opts.verbose) setVerbose(true);
|
|
12946
|
-
if (opts.color === false)
|
|
14177
|
+
if (opts.color === false) chalk41.level = 0;
|
|
12947
14178
|
}).hook("preAction", (_thisCommand, actionCommand) => fillPendingInputs(actionCommand));
|
|
12948
14179
|
program.addHelpText("after", HELP_EPILOGUE);
|
|
12949
14180
|
registerAuthCommands(program);
|
|
@@ -12965,7 +14196,7 @@ function createProgram(environment = {}) {
|
|
|
12965
14196
|
registerStatusCommands(program);
|
|
12966
14197
|
registerAnalyzeCommand(program);
|
|
12967
14198
|
registerPublicCommands(program);
|
|
12968
|
-
|
|
14199
|
+
registerLicenseCommands(program);
|
|
12969
14200
|
registerDataSourcesCommands(program);
|
|
12970
14201
|
registerTableExportersCommands(program);
|
|
12971
14202
|
registerSkeletonCommands(program);
|
|
@@ -12978,13 +14209,14 @@ function createProgram(environment = {}) {
|
|
|
12978
14209
|
registerShellCommand(program);
|
|
12979
14210
|
registerUpdateCommand(program);
|
|
12980
14211
|
registerUninstallCommand(program);
|
|
14212
|
+
wireHiddenOptionAliases(program);
|
|
12981
14213
|
return program;
|
|
12982
14214
|
}
|
|
12983
14215
|
|
|
12984
14216
|
export {
|
|
12985
14217
|
EXIT_CANCELLED,
|
|
12986
14218
|
handleError,
|
|
12987
|
-
|
|
14219
|
+
PromptCanceled,
|
|
12988
14220
|
createProgram
|
|
12989
14221
|
};
|
|
12990
|
-
//# sourceMappingURL=chunk-
|
|
14222
|
+
//# sourceMappingURL=chunk-5AB7E3K4.js.map
|