@roarkanalytics/cli 0.61.1 → 0.68.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/CHANGELOG.md +56 -0
- package/README.md +45 -0
- package/commands.js +575 -0
- package/completions.js +4 -4
- package/man/roark-calendar-connection-check.1 +93 -0
- package/man/roark-calendar-connection-create.1 +102 -0
- package/man/roark-calendar-connection-delete.1 +93 -0
- package/man/roark-calendar-connection-get.1 +93 -0
- package/man/roark-calendar-connection-list.1 +93 -0
- package/man/roark-calendar-connection-target-get.1 +96 -0
- package/man/roark-calendar-connection-target-list.1 +93 -0
- package/man/roark-calendar-connection-update.1 +103 -0
- package/man/roark-metric-definition-update.1 +3 -0
- package/man/roark-metric-variant-update.1 +3 -0
- package/man/roark-tool-create.1 +123 -0
- package/man/roark-tool-delete.1 +93 -0
- package/man/roark-tool-get.1 +93 -0
- package/man/roark-tool-list.1 +96 -0
- package/man/roark-tool-update.1 +127 -0
- package/man/roark.1 +39 -0
- package/npm-shrinkwrap.json +6 -6
- package/package.json +15 -2
- package/runtime/commands/config-as-code.js +5 -23
- package/runtime/commands/get-started.d.ts +34 -0
- package/runtime/commands/get-started.js +350 -0
- package/runtime/config-bundle.d.ts +10 -0
- package/runtime/config-bundle.js +14 -3
- package/runtime/config-changes.d.ts +15 -0
- package/runtime/config-changes.js +32 -0
- package/runtime/get-started/account.d.ts +18 -0
- package/runtime/get-started/account.js +35 -0
- package/runtime/get-started/agent.d.ts +17 -0
- package/runtime/get-started/agent.js +116 -0
- package/runtime/get-started/answers.d.ts +15 -0
- package/runtime/get-started/answers.js +42 -0
- package/runtime/get-started/apply.d.ts +35 -0
- package/runtime/get-started/apply.js +54 -0
- package/runtime/get-started/existing.d.ts +15 -0
- package/runtime/get-started/existing.js +47 -0
- package/runtime/get-started/ladder.d.ts +37 -0
- package/runtime/get-started/ladder.js +69 -0
- package/runtime/get-started/module.d.ts +20 -0
- package/runtime/get-started/module.js +159 -0
- package/runtime/get-started/placeholder.d.ts +9 -0
- package/runtime/get-started/placeholder.js +36 -0
- package/runtime/get-started/prompt.d.ts +32 -0
- package/runtime/get-started/prompt.js +132 -0
- package/runtime/get-started/resources.d.ts +106 -0
- package/runtime/get-started/resources.js +184 -0
- package/runtime/get-started/run.d.ts +42 -0
- package/runtime/get-started/run.js +101 -0
- package/runtime/get-started/scaffold-only.d.ts +19 -0
- package/runtime/get-started/scaffold-only.js +43 -0
- package/runtime/get-started/scaffold.d.ts +15 -0
- package/runtime/get-started/scaffold.js +35 -0
- package/runtime/get-started/starter-metrics.d.ts +33 -0
- package/runtime/get-started/starter-metrics.js +104 -0
- package/runtime/get-started/steps.d.ts +33 -0
- package/runtime/get-started/steps.js +112 -0
- package/runtime/get-started/target.d.ts +47 -0
- package/runtime/get-started/target.js +81 -0
- package/runtime/get-started/types.d.ts +18 -0
- package/runtime/get-started/types.js +8 -0
- package/runtime/get-started/watch.d.ts +57 -0
- package/runtime/get-started/watch.js +103 -0
- package/runtime/program.js +5 -0
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Where the config is written, and in which form.
|
|
4
|
+
*
|
|
5
|
+
* One object rather than a loose directory string, because the format decides three things that
|
|
6
|
+
* must agree: where files land, what to call the config when pointing at it, and what
|
|
7
|
+
* `config diff` / `config apply` should be given. They were separate once, and a config module
|
|
8
|
+
* chosen at the prompt got written to one path and loaded from another.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.chooseFormat = exports.sdkIsInstalled = exports.applyCommand = exports.targetFor = exports.DEFAULT_DIR = void 0;
|
|
12
|
+
const node_fs_1 = require("node:fs");
|
|
13
|
+
const node_path_1 = require("node:path");
|
|
14
|
+
const module_1 = require("./module");
|
|
15
|
+
exports.DEFAULT_DIR = './roark';
|
|
16
|
+
const targetFor = (format, dir) => format === 'yaml' ?
|
|
17
|
+
{ format, dir, label: `${dir}/`, argument: dir }
|
|
18
|
+
: {
|
|
19
|
+
format,
|
|
20
|
+
dir,
|
|
21
|
+
label: (0, node_path_1.join)(dir, module_1.CONFIG_MODULE_FILE),
|
|
22
|
+
// `config apply` finds `roark.config.ts` in the working directory on its own, so the
|
|
23
|
+
// common case is given no argument at all.
|
|
24
|
+
argument: dir === '.' ? '' : (0, node_path_1.join)(dir, module_1.CONFIG_MODULE_FILE),
|
|
25
|
+
};
|
|
26
|
+
exports.targetFor = targetFor;
|
|
27
|
+
/** The command that applies this target, spelled the way a person would type it. */
|
|
28
|
+
const applyCommand = (binaryName, target) => `${binaryName} config apply${target.argument === '' ? '' : ` ${target.argument}`}`;
|
|
29
|
+
exports.applyCommand = applyCommand;
|
|
30
|
+
/**
|
|
31
|
+
* Whether a config module could actually be loaded from here.
|
|
32
|
+
*
|
|
33
|
+
* `roark.config.ts` imports its helpers from the SDK, and jiti resolves that from the config
|
|
34
|
+
* file's own project. Offering TypeScript where the import cannot resolve would hand someone a
|
|
35
|
+
* config that fails on the next command, so the question is only asked where it can work.
|
|
36
|
+
*/
|
|
37
|
+
const sdkIsInstalled = (dir) => {
|
|
38
|
+
// Installed, not merely declared in a package.json: the difference decides whether the config
|
|
39
|
+
// loads or throws, and a dependency somebody has not run an install for yet would offer a
|
|
40
|
+
// format that breaks on the very next step, after every question has been answered.
|
|
41
|
+
//
|
|
42
|
+
// Walked upwards because a workspace hoists its dependencies to the repository root, where a
|
|
43
|
+
// package in `packages/x` has no `node_modules` of its own.
|
|
44
|
+
let root = (0, node_path_1.resolve)(dir);
|
|
45
|
+
for (;;) {
|
|
46
|
+
const sdk = (0, node_path_1.join)(root, 'node_modules', '@roarkanalytics', 'sdk');
|
|
47
|
+
if ((0, node_fs_1.existsSync)(sdk)) {
|
|
48
|
+
// The subpath, not just the package: `lib/config` arrived in a later release, so an older
|
|
49
|
+
// SDK satisfies "installed" and then fails on the import. Checking what is actually
|
|
50
|
+
// imported is the difference between offering a format and offering a broken one.
|
|
51
|
+
return (0, node_fs_1.existsSync)((0, node_path_1.join)(sdk, 'lib', 'config.js')) || (0, node_fs_1.existsSync)((0, node_path_1.join)(sdk, 'lib', 'config.mjs'));
|
|
52
|
+
}
|
|
53
|
+
const parent = (0, node_path_1.dirname)(root);
|
|
54
|
+
if (parent === root)
|
|
55
|
+
return false;
|
|
56
|
+
root = parent;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.sdkIsInstalled = sdkIsInstalled;
|
|
60
|
+
/**
|
|
61
|
+
* Which form to write, when the flags did not say.
|
|
62
|
+
*
|
|
63
|
+
* Asked only where it is a real choice: a project that cannot import the helpers cannot load a
|
|
64
|
+
* config module, so offering one would hand someone a config that fails on the very next step,
|
|
65
|
+
* after every question had been answered.
|
|
66
|
+
*/
|
|
67
|
+
const chooseFormat = async (prompter, chosenDir, current) => {
|
|
68
|
+
if (!(0, exports.sdkIsInstalled)(current.dir))
|
|
69
|
+
return current;
|
|
70
|
+
const picked = await prompter.select('How should the config be written?', [
|
|
71
|
+
{ value: 'yaml', label: `YAML files in ${chosenDir ?? exports.DEFAULT_DIR}`, hint: 'no dependencies' },
|
|
72
|
+
{
|
|
73
|
+
value: 'ts',
|
|
74
|
+
label: `TypeScript in ${(0, node_path_1.join)(chosenDir ?? '.', module_1.CONFIG_MODULE_FILE)}`,
|
|
75
|
+
hint: 'typed helpers, imported from the SDK',
|
|
76
|
+
},
|
|
77
|
+
], 'yaml');
|
|
78
|
+
const format = picked === 'ts' ? 'ts' : 'yaml';
|
|
79
|
+
return (0, exports.targetFor)(format, chosenDir ?? (format === 'ts' ? '.' : exports.DEFAULT_DIR));
|
|
80
|
+
};
|
|
81
|
+
exports.chooseFormat = chooseFormat;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The handful of types the guided flow's own modules pass between each other.
|
|
3
|
+
*
|
|
4
|
+
* Separate from `runtime/types.ts`, which describes the generated command table: these describe
|
|
5
|
+
* how `get-started`'s phases hand work to one another, and nothing outside this folder uses them.
|
|
6
|
+
*/
|
|
7
|
+
import type Roark from '@roarkanalytics/sdk';
|
|
8
|
+
import type { OutputFormat } from '../output';
|
|
9
|
+
export type ClientFor = (options: never) => Roark;
|
|
10
|
+
/** One entry of an apply result, which is where a created resource's id comes back. */
|
|
11
|
+
export type ConfigChange = {
|
|
12
|
+
configKey: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
};
|
|
15
|
+
export type ResolveOutput = (options: never) => {
|
|
16
|
+
format: OutputFormat;
|
|
17
|
+
color: boolean;
|
|
18
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The handful of types the guided flow's own modules pass between each other.
|
|
4
|
+
*
|
|
5
|
+
* Separate from `runtime/types.ts`, which describes the generated command table: these describe
|
|
6
|
+
* how `get-started`'s phases hand work to one another, and nothing outside this folder uses them.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watching the first run finish.
|
|
3
|
+
*
|
|
4
|
+
* A simulated call takes a minute or two, and the one thing someone wants from their first run is
|
|
5
|
+
* the verdict, so the command waits for it rather than printing a job id and leaving. It is a
|
|
6
|
+
* plain poll of `GET /v1/simulation/plan/job/{id}`: no websocket, no spinner, one line per status
|
|
7
|
+
* change so a pipe or a CI log stays readable.
|
|
8
|
+
*
|
|
9
|
+
* Waiting is bounded. Timing out is reported as "still running, here is how to check", never as a
|
|
10
|
+
* failure: the run is perfectly fine, it is this command's patience that ran out.
|
|
11
|
+
*/
|
|
12
|
+
/** Statuses a run never leaves. Anything else is still in flight. */
|
|
13
|
+
export declare const TERMINAL_STATUSES: ReadonlySet<string>;
|
|
14
|
+
export interface JobVerdict {
|
|
15
|
+
passed: boolean;
|
|
16
|
+
score?: number | null;
|
|
17
|
+
}
|
|
18
|
+
export interface JobSnapshot {
|
|
19
|
+
status: string;
|
|
20
|
+
verdict?: JobVerdict | null;
|
|
21
|
+
simulationJobs?: readonly {
|
|
22
|
+
status: string;
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
25
|
+
export interface WatchOptions {
|
|
26
|
+
jobId: string;
|
|
27
|
+
getJob: (jobId: string) => Promise<JobSnapshot>;
|
|
28
|
+
/** Called whenever the rendered progress line changes, so an unchanged status stays quiet. */
|
|
29
|
+
onProgress: (line: string) => void;
|
|
30
|
+
timeoutMs: number;
|
|
31
|
+
pollMs: number;
|
|
32
|
+
sleep: (ms: number) => Promise<void>;
|
|
33
|
+
now: () => number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* How the wait ended. `settled` is the run reaching a terminal status; the other two are this
|
|
37
|
+
* command giving up, which is not a failed run and must not be reported as one.
|
|
38
|
+
*/
|
|
39
|
+
export type WatchOutcome = 'settled' | 'timeout' | 'unreachable';
|
|
40
|
+
export interface WatchResult {
|
|
41
|
+
snapshot: JobSnapshot;
|
|
42
|
+
outcome: WatchOutcome;
|
|
43
|
+
}
|
|
44
|
+
export declare const progressLine: (snapshot: JobSnapshot) => string;
|
|
45
|
+
export declare const watchJob: (options: WatchOptions) => Promise<WatchResult>;
|
|
46
|
+
/**
|
|
47
|
+
* The headline.
|
|
48
|
+
*
|
|
49
|
+
* Two different absences of a verdict, and conflating them is a lie either way. A COMPLETED run
|
|
50
|
+
* with no verdict carried no pass/fail criterion, so there was nothing to judge. A run that ended
|
|
51
|
+
* FAILED, TIMED_OUT or CANCELLED also has no verdict, but there "no pass/fail criteria on this
|
|
52
|
+
* run" would read as reassurance about a run that fell over.
|
|
53
|
+
*/
|
|
54
|
+
export declare const verdictLine: (snapshot: JobSnapshot) => string;
|
|
55
|
+
/** Green for a pass, red for a failed check or a run that fell over, yellow for nothing judged. */
|
|
56
|
+
export declare const verdictStyle: (snapshot: JobSnapshot) => "green" | "red" | "yellow";
|
|
57
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Watching the first run finish.
|
|
4
|
+
*
|
|
5
|
+
* A simulated call takes a minute or two, and the one thing someone wants from their first run is
|
|
6
|
+
* the verdict, so the command waits for it rather than printing a job id and leaving. It is a
|
|
7
|
+
* plain poll of `GET /v1/simulation/plan/job/{id}`: no websocket, no spinner, one line per status
|
|
8
|
+
* change so a pipe or a CI log stays readable.
|
|
9
|
+
*
|
|
10
|
+
* Waiting is bounded. Timing out is reported as "still running, here is how to check", never as a
|
|
11
|
+
* failure: the run is perfectly fine, it is this command's patience that ran out.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.sleep = exports.verdictStyle = exports.verdictLine = exports.watchJob = exports.progressLine = exports.TERMINAL_STATUSES = void 0;
|
|
15
|
+
/** Statuses a run never leaves. Anything else is still in flight. */
|
|
16
|
+
exports.TERMINAL_STATUSES = new Set([
|
|
17
|
+
'COMPLETED',
|
|
18
|
+
'FAILED',
|
|
19
|
+
'TIMED_OUT',
|
|
20
|
+
'CANCELLED',
|
|
21
|
+
]);
|
|
22
|
+
/** How many polls in a row may fail before the wait is given up on. */
|
|
23
|
+
const ERROR_TOLERANCE = 3;
|
|
24
|
+
/** Stands in for a run we never managed to read, so the caller still has something to print. */
|
|
25
|
+
const UNREADABLE = { status: 'UNKNOWN' };
|
|
26
|
+
const progressLine = (snapshot) => {
|
|
27
|
+
const jobs = snapshot.simulationJobs ?? [];
|
|
28
|
+
if (jobs.length === 0)
|
|
29
|
+
return snapshot.status;
|
|
30
|
+
const done = jobs.filter((job) => exports.TERMINAL_STATUSES.has(job.status)).length;
|
|
31
|
+
return `${snapshot.status} ${done}/${jobs.length} calls finished`;
|
|
32
|
+
};
|
|
33
|
+
exports.progressLine = progressLine;
|
|
34
|
+
const watchJob = async (options) => {
|
|
35
|
+
const started = options.now();
|
|
36
|
+
let last;
|
|
37
|
+
let latest;
|
|
38
|
+
let failures = 0;
|
|
39
|
+
for (;;) {
|
|
40
|
+
// A poll that throws must not take the command down with it. The run has already started by
|
|
41
|
+
// the time we are here, so an exception would lose the job id and the "check it later" line
|
|
42
|
+
// over one network blip. A few in a row is a different matter: then we stop waiting and say so.
|
|
43
|
+
let snapshot;
|
|
44
|
+
try {
|
|
45
|
+
snapshot = await options.getJob(options.jobId);
|
|
46
|
+
failures = 0;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
failures += 1;
|
|
50
|
+
if (failures >= ERROR_TOLERANCE)
|
|
51
|
+
return { snapshot: latest ?? UNREADABLE, outcome: 'unreachable' };
|
|
52
|
+
}
|
|
53
|
+
if (snapshot !== undefined) {
|
|
54
|
+
latest = snapshot;
|
|
55
|
+
const line = (0, exports.progressLine)(snapshot);
|
|
56
|
+
if (line !== last) {
|
|
57
|
+
options.onProgress(line);
|
|
58
|
+
last = line;
|
|
59
|
+
}
|
|
60
|
+
if (exports.TERMINAL_STATUSES.has(snapshot.status))
|
|
61
|
+
return { snapshot, outcome: 'settled' };
|
|
62
|
+
}
|
|
63
|
+
if (options.now() - started >= options.timeoutMs) {
|
|
64
|
+
return { snapshot: latest ?? UNREADABLE, outcome: 'timeout' };
|
|
65
|
+
}
|
|
66
|
+
await options.sleep(options.pollMs);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.watchJob = watchJob;
|
|
70
|
+
/**
|
|
71
|
+
* The headline.
|
|
72
|
+
*
|
|
73
|
+
* Two different absences of a verdict, and conflating them is a lie either way. A COMPLETED run
|
|
74
|
+
* with no verdict carried no pass/fail criterion, so there was nothing to judge. A run that ended
|
|
75
|
+
* FAILED, TIMED_OUT or CANCELLED also has no verdict, but there "no pass/fail criteria on this
|
|
76
|
+
* run" would read as reassurance about a run that fell over.
|
|
77
|
+
*/
|
|
78
|
+
const verdictLine = (snapshot) => {
|
|
79
|
+
if (snapshot.status !== 'COMPLETED') {
|
|
80
|
+
return `The run ended ${snapshot.status}, so nothing was graded.`;
|
|
81
|
+
}
|
|
82
|
+
const verdict = snapshot.verdict;
|
|
83
|
+
if (verdict === undefined || verdict === null) {
|
|
84
|
+
return 'No pass/fail criteria on this run, so there is no verdict. The metric values are on the run.';
|
|
85
|
+
}
|
|
86
|
+
const score = typeof verdict.score === 'number' ? `, score ${Math.round(verdict.score)}/100` : '';
|
|
87
|
+
return verdict.passed ? `Passed${score}` : `Failed${score}`;
|
|
88
|
+
};
|
|
89
|
+
exports.verdictLine = verdictLine;
|
|
90
|
+
/** Green for a pass, red for a failed check or a run that fell over, yellow for nothing judged. */
|
|
91
|
+
const verdictStyle = (snapshot) => {
|
|
92
|
+
if (snapshot.status !== 'COMPLETED')
|
|
93
|
+
return 'red';
|
|
94
|
+
const passed = snapshot.verdict?.passed;
|
|
95
|
+
if (passed === undefined)
|
|
96
|
+
return 'yellow';
|
|
97
|
+
return passed ? 'green' : 'red';
|
|
98
|
+
};
|
|
99
|
+
exports.verdictStyle = verdictStyle;
|
|
100
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
101
|
+
setTimeout(resolve, ms);
|
|
102
|
+
});
|
|
103
|
+
exports.sleep = sleep;
|
package/runtime/program.js
CHANGED
|
@@ -16,6 +16,7 @@ const api_1 = require("./commands/api");
|
|
|
16
16
|
const auth_1 = require("./commands/auth");
|
|
17
17
|
const config_as_code_1 = require("./commands/config-as-code");
|
|
18
18
|
const config_1 = require("./commands/config");
|
|
19
|
+
const get_started_1 = require("./commands/get-started");
|
|
19
20
|
const completion_1 = require("./commands/completion");
|
|
20
21
|
const confirm_1 = require("./confirm");
|
|
21
22
|
const config_2 = require("./config");
|
|
@@ -308,12 +309,16 @@ const createProgram = (options) => {
|
|
|
308
309
|
continue;
|
|
309
310
|
addApiCommand(root, options, definition);
|
|
310
311
|
}
|
|
312
|
+
(0, get_started_1.registerGetStartedCommand)(root, options.binaryName, clientFor, exports.resolveOutput);
|
|
311
313
|
(0, auth_1.registerAuthCommands)(root, options.binaryName, clientFor);
|
|
312
314
|
(0, config_as_code_1.registerConfigAsCodeCommands)(root, options.binaryName, clientFor, exports.resolveOutput);
|
|
313
315
|
(0, config_1.registerConfigCommands)(root, options.binaryName);
|
|
314
316
|
(0, api_1.registerApiCommand)(root, options.binaryName, clientFor, exports.resolveOutput);
|
|
315
317
|
(0, completion_1.registerCompletionCommand)(root, options.binaryName, options.completions);
|
|
316
318
|
root.addHelpText('after', [
|
|
319
|
+
'',
|
|
320
|
+
'New here?',
|
|
321
|
+
` ${options.binaryName} get-started an agent, a caller, a scenario, metrics, and a graded run`,
|
|
317
322
|
'',
|
|
318
323
|
'Environment:',
|
|
319
324
|
' ROARK_API_BEARER_TOKEN bearer token used when --token is not given',
|
package/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.
|
|
1
|
+
export declare const version = "0.68.0";
|
package/version.js
CHANGED