@nouter/platform-cli 0.4.0 → 0.5.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 +143 -0
- package/dist/index.js +2497 -290
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3718,7 +3718,7 @@ var require_errors = __commonJS({
|
|
|
3718
3718
|
this.pos = pos;
|
|
3719
3719
|
}
|
|
3720
3720
|
};
|
|
3721
|
-
var
|
|
3721
|
+
var YAMLParseError2 = class extends YAMLError {
|
|
3722
3722
|
constructor(pos, code, message) {
|
|
3723
3723
|
super("YAMLParseError", pos, code, message);
|
|
3724
3724
|
}
|
|
@@ -3764,7 +3764,7 @@ ${pointer}
|
|
|
3764
3764
|
}
|
|
3765
3765
|
};
|
|
3766
3766
|
exports.YAMLError = YAMLError;
|
|
3767
|
-
exports.YAMLParseError =
|
|
3767
|
+
exports.YAMLParseError = YAMLParseError2;
|
|
3768
3768
|
exports.YAMLWarning = YAMLWarning;
|
|
3769
3769
|
exports.prettifyError = prettifyError;
|
|
3770
3770
|
}
|
|
@@ -3999,10 +3999,10 @@ var require_resolve_block_map = __commonJS({
|
|
|
3999
3999
|
let offset = bm.offset;
|
|
4000
4000
|
let commentEnd = null;
|
|
4001
4001
|
for (const collItem of bm.items) {
|
|
4002
|
-
const { start, key, sep, value } = collItem;
|
|
4002
|
+
const { start, key, sep: sep2, value } = collItem;
|
|
4003
4003
|
const keyProps = resolveProps.resolveProps(start, {
|
|
4004
4004
|
indicator: "explicit-key-ind",
|
|
4005
|
-
next: key ??
|
|
4005
|
+
next: key ?? sep2?.[0],
|
|
4006
4006
|
offset,
|
|
4007
4007
|
onError,
|
|
4008
4008
|
parentIndent: bm.indent,
|
|
@@ -4016,7 +4016,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
4016
4016
|
else if ("indent" in key && key.indent !== bm.indent)
|
|
4017
4017
|
onError(offset, "BAD_INDENT", startColMsg);
|
|
4018
4018
|
}
|
|
4019
|
-
if (!keyProps.anchor && !keyProps.tag && !
|
|
4019
|
+
if (!keyProps.anchor && !keyProps.tag && !sep2) {
|
|
4020
4020
|
commentEnd = keyProps.end;
|
|
4021
4021
|
if (keyProps.comment) {
|
|
4022
4022
|
if (map.comment)
|
|
@@ -4040,7 +4040,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
4040
4040
|
ctx.atKey = false;
|
|
4041
4041
|
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
4042
4042
|
onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
|
|
4043
|
-
const valueProps = resolveProps.resolveProps(
|
|
4043
|
+
const valueProps = resolveProps.resolveProps(sep2 ?? [], {
|
|
4044
4044
|
indicator: "map-value-ind",
|
|
4045
4045
|
next: value,
|
|
4046
4046
|
offset: keyNode.range[2],
|
|
@@ -4056,7 +4056,7 @@ var require_resolve_block_map = __commonJS({
|
|
|
4056
4056
|
if (ctx.options.strict && keyProps.start < valueProps.found.offset - 1024)
|
|
4057
4057
|
onError(keyNode.range, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit block mapping key");
|
|
4058
4058
|
}
|
|
4059
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset,
|
|
4059
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset, sep2, null, valueProps, onError);
|
|
4060
4060
|
if (ctx.schema.compat)
|
|
4061
4061
|
utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
|
|
4062
4062
|
offset = valueNode.range[2];
|
|
@@ -4147,7 +4147,7 @@ var require_resolve_end = __commonJS({
|
|
|
4147
4147
|
let comment = "";
|
|
4148
4148
|
if (end) {
|
|
4149
4149
|
let hasSpace = false;
|
|
4150
|
-
let
|
|
4150
|
+
let sep2 = "";
|
|
4151
4151
|
for (const token of end) {
|
|
4152
4152
|
const { source, type } = token;
|
|
4153
4153
|
switch (type) {
|
|
@@ -4161,13 +4161,13 @@ var require_resolve_end = __commonJS({
|
|
|
4161
4161
|
if (!comment)
|
|
4162
4162
|
comment = cb;
|
|
4163
4163
|
else
|
|
4164
|
-
comment +=
|
|
4165
|
-
|
|
4164
|
+
comment += sep2 + cb;
|
|
4165
|
+
sep2 = "";
|
|
4166
4166
|
break;
|
|
4167
4167
|
}
|
|
4168
4168
|
case "newline":
|
|
4169
4169
|
if (comment)
|
|
4170
|
-
|
|
4170
|
+
sep2 += source;
|
|
4171
4171
|
hasSpace = true;
|
|
4172
4172
|
break;
|
|
4173
4173
|
default:
|
|
@@ -4210,18 +4210,18 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4210
4210
|
let offset = fc.offset + fc.start.source.length;
|
|
4211
4211
|
for (let i = 0; i < fc.items.length; ++i) {
|
|
4212
4212
|
const collItem = fc.items[i];
|
|
4213
|
-
const { start, key, sep, value } = collItem;
|
|
4213
|
+
const { start, key, sep: sep2, value } = collItem;
|
|
4214
4214
|
const props = resolveProps.resolveProps(start, {
|
|
4215
4215
|
flow: fcName,
|
|
4216
4216
|
indicator: "explicit-key-ind",
|
|
4217
|
-
next: key ??
|
|
4217
|
+
next: key ?? sep2?.[0],
|
|
4218
4218
|
offset,
|
|
4219
4219
|
onError,
|
|
4220
4220
|
parentIndent: fc.indent,
|
|
4221
4221
|
startOnNewline: false
|
|
4222
4222
|
});
|
|
4223
4223
|
if (!props.found) {
|
|
4224
|
-
if (!props.anchor && !props.tag && !
|
|
4224
|
+
if (!props.anchor && !props.tag && !sep2 && !value) {
|
|
4225
4225
|
if (i === 0 && props.comma)
|
|
4226
4226
|
onError(props.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${fcName}`);
|
|
4227
4227
|
else if (i < fc.items.length - 1)
|
|
@@ -4275,8 +4275,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4275
4275
|
}
|
|
4276
4276
|
}
|
|
4277
4277
|
}
|
|
4278
|
-
if (!isMap && !
|
|
4279
|
-
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end,
|
|
4278
|
+
if (!isMap && !sep2 && !props.found) {
|
|
4279
|
+
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, sep2, null, props, onError);
|
|
4280
4280
|
coll.items.push(valueNode);
|
|
4281
4281
|
offset = valueNode.range[2];
|
|
4282
4282
|
if (isBlock(value))
|
|
@@ -4288,7 +4288,7 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4288
4288
|
if (isBlock(key))
|
|
4289
4289
|
onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
4290
4290
|
ctx.atKey = false;
|
|
4291
|
-
const valueProps = resolveProps.resolveProps(
|
|
4291
|
+
const valueProps = resolveProps.resolveProps(sep2 ?? [], {
|
|
4292
4292
|
flow: fcName,
|
|
4293
4293
|
indicator: "map-value-ind",
|
|
4294
4294
|
next: value,
|
|
@@ -4299,8 +4299,8 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4299
4299
|
});
|
|
4300
4300
|
if (valueProps.found) {
|
|
4301
4301
|
if (!isMap && !props.found && ctx.options.strict) {
|
|
4302
|
-
if (
|
|
4303
|
-
for (const st of
|
|
4302
|
+
if (sep2)
|
|
4303
|
+
for (const st of sep2) {
|
|
4304
4304
|
if (st === valueProps.found)
|
|
4305
4305
|
break;
|
|
4306
4306
|
if (st.type === "newline") {
|
|
@@ -4317,7 +4317,7 @@ var require_resolve_flow_collection = __commonJS({
|
|
|
4317
4317
|
else
|
|
4318
4318
|
onError(valueProps.start, "MISSING_CHAR", `Missing , or : between ${fcName} items`);
|
|
4319
4319
|
}
|
|
4320
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end,
|
|
4320
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end, sep2, null, valueProps, onError) : null;
|
|
4321
4321
|
if (valueNode) {
|
|
4322
4322
|
if (isBlock(value))
|
|
4323
4323
|
onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
@@ -4497,7 +4497,7 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
4497
4497
|
chompStart = i + 1;
|
|
4498
4498
|
}
|
|
4499
4499
|
let value = "";
|
|
4500
|
-
let
|
|
4500
|
+
let sep2 = "";
|
|
4501
4501
|
let prevMoreIndented = false;
|
|
4502
4502
|
for (let i = 0; i < contentStart; ++i)
|
|
4503
4503
|
value += lines[i][0].slice(trimIndent) + "\n";
|
|
@@ -4514,24 +4514,24 @@ var require_resolve_block_scalar = __commonJS({
|
|
|
4514
4514
|
indent = "";
|
|
4515
4515
|
}
|
|
4516
4516
|
if (type === Scalar.Scalar.BLOCK_LITERAL) {
|
|
4517
|
-
value +=
|
|
4518
|
-
|
|
4517
|
+
value += sep2 + indent.slice(trimIndent) + content;
|
|
4518
|
+
sep2 = "\n";
|
|
4519
4519
|
} else if (indent.length > trimIndent || content[0] === " ") {
|
|
4520
|
-
if (
|
|
4521
|
-
|
|
4522
|
-
else if (!prevMoreIndented &&
|
|
4523
|
-
|
|
4524
|
-
value +=
|
|
4525
|
-
|
|
4520
|
+
if (sep2 === " ")
|
|
4521
|
+
sep2 = "\n";
|
|
4522
|
+
else if (!prevMoreIndented && sep2 === "\n")
|
|
4523
|
+
sep2 = "\n\n";
|
|
4524
|
+
value += sep2 + indent.slice(trimIndent) + content;
|
|
4525
|
+
sep2 = "\n";
|
|
4526
4526
|
prevMoreIndented = true;
|
|
4527
4527
|
} else if (content === "") {
|
|
4528
|
-
if (
|
|
4528
|
+
if (sep2 === "\n")
|
|
4529
4529
|
value += "\n";
|
|
4530
4530
|
else
|
|
4531
|
-
|
|
4531
|
+
sep2 = "\n";
|
|
4532
4532
|
} else {
|
|
4533
|
-
value +=
|
|
4534
|
-
|
|
4533
|
+
value += sep2 + content;
|
|
4534
|
+
sep2 = " ";
|
|
4535
4535
|
prevMoreIndented = false;
|
|
4536
4536
|
}
|
|
4537
4537
|
}
|
|
@@ -4714,25 +4714,25 @@ var require_resolve_flow_scalar = __commonJS({
|
|
|
4714
4714
|
trimBoth = /^[ \t]+|[ \t]+$/g;
|
|
4715
4715
|
}
|
|
4716
4716
|
let res = match[1].replace(trimEnd, "");
|
|
4717
|
-
let
|
|
4717
|
+
let sep2 = " ";
|
|
4718
4718
|
let pos = line.lastIndex;
|
|
4719
4719
|
while (match = line.exec(source)) {
|
|
4720
4720
|
const lm = match[1].replace(trimBoth, "");
|
|
4721
4721
|
if (lm === "") {
|
|
4722
|
-
if (
|
|
4723
|
-
res +=
|
|
4722
|
+
if (sep2 === "\n")
|
|
4723
|
+
res += sep2;
|
|
4724
4724
|
else
|
|
4725
|
-
|
|
4725
|
+
sep2 = "\n";
|
|
4726
4726
|
} else {
|
|
4727
|
-
res +=
|
|
4728
|
-
|
|
4727
|
+
res += sep2 + lm;
|
|
4728
|
+
sep2 = " ";
|
|
4729
4729
|
}
|
|
4730
4730
|
pos = line.lastIndex;
|
|
4731
4731
|
}
|
|
4732
4732
|
const last = /[ \t]*(.*)/sy;
|
|
4733
4733
|
last.lastIndex = pos;
|
|
4734
4734
|
match = last.exec(source);
|
|
4735
|
-
return res +
|
|
4735
|
+
return res + sep2 + (match?.[1] ?? "");
|
|
4736
4736
|
}
|
|
4737
4737
|
function doubleQuotedValue(source, onError) {
|
|
4738
4738
|
let res = "";
|
|
@@ -5542,14 +5542,14 @@ var require_cst_stringify = __commonJS({
|
|
|
5542
5542
|
}
|
|
5543
5543
|
}
|
|
5544
5544
|
}
|
|
5545
|
-
function stringifyItem({ start, key, sep, value }) {
|
|
5545
|
+
function stringifyItem({ start, key, sep: sep2, value }) {
|
|
5546
5546
|
let res = "";
|
|
5547
5547
|
for (const st of start)
|
|
5548
5548
|
res += st.source;
|
|
5549
5549
|
if (key)
|
|
5550
5550
|
res += stringifyToken(key);
|
|
5551
|
-
if (
|
|
5552
|
-
for (const st of
|
|
5551
|
+
if (sep2)
|
|
5552
|
+
for (const st of sep2)
|
|
5553
5553
|
res += st.source;
|
|
5554
5554
|
if (value)
|
|
5555
5555
|
res += stringifyToken(value);
|
|
@@ -6716,18 +6716,18 @@ var require_parser = __commonJS({
|
|
|
6716
6716
|
if (this.type === "map-value-ind") {
|
|
6717
6717
|
const prev = getPrevProps(this.peek(2));
|
|
6718
6718
|
const start = getFirstKeyStartProps(prev);
|
|
6719
|
-
let
|
|
6719
|
+
let sep2;
|
|
6720
6720
|
if (scalar.end) {
|
|
6721
|
-
|
|
6722
|
-
|
|
6721
|
+
sep2 = scalar.end;
|
|
6722
|
+
sep2.push(this.sourceToken);
|
|
6723
6723
|
delete scalar.end;
|
|
6724
6724
|
} else
|
|
6725
|
-
|
|
6725
|
+
sep2 = [this.sourceToken];
|
|
6726
6726
|
const map = {
|
|
6727
6727
|
type: "block-map",
|
|
6728
6728
|
offset: scalar.offset,
|
|
6729
6729
|
indent: scalar.indent,
|
|
6730
|
-
items: [{ start, key: scalar, sep }]
|
|
6730
|
+
items: [{ start, key: scalar, sep: sep2 }]
|
|
6731
6731
|
};
|
|
6732
6732
|
this.onKeyLine = true;
|
|
6733
6733
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -6880,15 +6880,15 @@ var require_parser = __commonJS({
|
|
|
6880
6880
|
} else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
|
|
6881
6881
|
const start2 = getFirstKeyStartProps(it.start);
|
|
6882
6882
|
const key = it.key;
|
|
6883
|
-
const
|
|
6884
|
-
|
|
6883
|
+
const sep2 = it.sep;
|
|
6884
|
+
sep2.push(this.sourceToken);
|
|
6885
6885
|
delete it.key;
|
|
6886
6886
|
delete it.sep;
|
|
6887
6887
|
this.stack.push({
|
|
6888
6888
|
type: "block-map",
|
|
6889
6889
|
offset: this.offset,
|
|
6890
6890
|
indent: this.indent,
|
|
6891
|
-
items: [{ start: start2, key, sep }]
|
|
6891
|
+
items: [{ start: start2, key, sep: sep2 }]
|
|
6892
6892
|
});
|
|
6893
6893
|
} else if (start.length > 0) {
|
|
6894
6894
|
it.sep = it.sep.concat(start, this.sourceToken);
|
|
@@ -7082,13 +7082,13 @@ var require_parser = __commonJS({
|
|
|
7082
7082
|
const prev = getPrevProps(parent);
|
|
7083
7083
|
const start = getFirstKeyStartProps(prev);
|
|
7084
7084
|
fixFlowSeqItems(fc);
|
|
7085
|
-
const
|
|
7086
|
-
|
|
7085
|
+
const sep2 = fc.end.splice(1, fc.end.length);
|
|
7086
|
+
sep2.push(this.sourceToken);
|
|
7087
7087
|
const map = {
|
|
7088
7088
|
type: "block-map",
|
|
7089
7089
|
offset: fc.offset,
|
|
7090
7090
|
indent: fc.indent,
|
|
7091
|
-
items: [{ start, key: fc, sep }]
|
|
7091
|
+
items: [{ start, key: fc, sep: sep2 }]
|
|
7092
7092
|
};
|
|
7093
7093
|
this.onKeyLine = true;
|
|
7094
7094
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -7266,7 +7266,7 @@ var require_public_api = __commonJS({
|
|
|
7266
7266
|
}
|
|
7267
7267
|
return doc;
|
|
7268
7268
|
}
|
|
7269
|
-
function
|
|
7269
|
+
function parse2(src, reviver, options) {
|
|
7270
7270
|
let _reviver = void 0;
|
|
7271
7271
|
if (typeof reviver === "function") {
|
|
7272
7272
|
_reviver = reviver;
|
|
@@ -7307,7 +7307,7 @@ var require_public_api = __commonJS({
|
|
|
7307
7307
|
return value.toString(options);
|
|
7308
7308
|
return new Document.Document(value, _replacer, options).toString(options);
|
|
7309
7309
|
}
|
|
7310
|
-
exports.parse =
|
|
7310
|
+
exports.parse = parse2;
|
|
7311
7311
|
exports.parseAllDocuments = parseAllDocuments2;
|
|
7312
7312
|
exports.parseDocument = parseDocument;
|
|
7313
7313
|
exports.stringify = stringify;
|
|
@@ -7368,12 +7368,13 @@ var require_dist = __commonJS({
|
|
|
7368
7368
|
|
|
7369
7369
|
// src/index.ts
|
|
7370
7370
|
import { spawn } from "node:child_process";
|
|
7371
|
-
import { randomBytes as
|
|
7372
|
-
import { readFileSync as
|
|
7371
|
+
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
7372
|
+
import { readFileSync as readFileSync5 } from "node:fs";
|
|
7373
7373
|
import { hostname } from "node:os";
|
|
7374
|
-
import { dirname, join as
|
|
7374
|
+
import { dirname, isAbsolute as isAbsolute3, join as join4 } from "node:path";
|
|
7375
7375
|
import { fileURLToPath } from "node:url";
|
|
7376
7376
|
import {
|
|
7377
|
+
KEY_PRESETS,
|
|
7377
7378
|
NouterPlatform
|
|
7378
7379
|
} from "@nouter/platform";
|
|
7379
7380
|
|
|
@@ -7850,11 +7851,21 @@ function diffEnvironment(document, current) {
|
|
|
7850
7851
|
}
|
|
7851
7852
|
return changes;
|
|
7852
7853
|
}
|
|
7854
|
+
function hasMaskedValue(value) {
|
|
7855
|
+
return isObject(value) && Object.values(value).some((entry) => entry === "***");
|
|
7856
|
+
}
|
|
7857
|
+
function usesMaskedEnv(document) {
|
|
7858
|
+
if (document.kind !== "agent") return false;
|
|
7859
|
+
const servers = document.mcp_servers;
|
|
7860
|
+
if (Array.isArray(servers) && servers.some((server) => isObject(server) && hasMaskedValue(server.env))) {
|
|
7861
|
+
return true;
|
|
7862
|
+
}
|
|
7863
|
+
const oma = document._oma;
|
|
7864
|
+
return isObject(oma) && isObject(oma.acp) && isObject(oma.acp.agent) && hasMaskedValue(oma.acp.agent.env);
|
|
7865
|
+
}
|
|
7853
7866
|
function validateMaskedEnv(document, current) {
|
|
7854
7867
|
if (document.kind !== "agent") return;
|
|
7855
|
-
const maskedServers = Array.isArray(document.mcp_servers) ? document.mcp_servers.filter(
|
|
7856
|
-
(server) => isObject(server) && isObject(server.env) && Object.values(server.env).some((value) => value === "***")
|
|
7857
|
-
) : [];
|
|
7868
|
+
const maskedServers = Array.isArray(document.mcp_servers) ? document.mcp_servers.filter((server) => isObject(server) && hasMaskedValue(server.env)) : [];
|
|
7858
7869
|
for (const server of maskedServers) {
|
|
7859
7870
|
const name = typeof server.name === "string" ? server.name : "";
|
|
7860
7871
|
if (current === void 0) {
|
|
@@ -7872,7 +7883,7 @@ function validateMaskedEnv(document, current) {
|
|
|
7872
7883
|
}
|
|
7873
7884
|
const oma = document._oma;
|
|
7874
7885
|
if (!isObject(oma) || !isObject(oma.acp) || !isObject(oma.acp.agent) || !isObject(oma.acp.agent.env)) return;
|
|
7875
|
-
if (!
|
|
7886
|
+
if (!hasMaskedValue(oma.acp.agent.env)) return;
|
|
7876
7887
|
const previous = current?._oma?.acp?.agent?.env;
|
|
7877
7888
|
if (current === void 0) {
|
|
7878
7889
|
fail('The ACP agent env uses "***" but the agent does not exist yet; set its values with ${VAR}.');
|
|
@@ -8236,6 +8247,18 @@ function formatApplyResults(results) {
|
|
|
8236
8247
|
return lines;
|
|
8237
8248
|
}
|
|
8238
8249
|
|
|
8250
|
+
// src/printable.ts
|
|
8251
|
+
var UNSAFE_CHARACTERS = new RegExp(
|
|
8252
|
+
"[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u061c\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2069\\ufeff\\ufe00-\\ufe0f\\u{e0000}-\\u{e007f}]",
|
|
8253
|
+
"gu"
|
|
8254
|
+
);
|
|
8255
|
+
function printable(text) {
|
|
8256
|
+
return text.replace(UNSAFE_CHARACTERS, "\uFFFD");
|
|
8257
|
+
}
|
|
8258
|
+
function oneLine(text) {
|
|
8259
|
+
return printable(text.replace(/\r\n|\r|\n/g, " "));
|
|
8260
|
+
}
|
|
8261
|
+
|
|
8239
8262
|
// src/api-errors.ts
|
|
8240
8263
|
function describeApiFailure(error) {
|
|
8241
8264
|
const candidate = error;
|
|
@@ -8245,7 +8268,9 @@ function describeApiFailure(error) {
|
|
|
8245
8268
|
const code2 = candidate.error?.error?.details?.error_code ?? candidate.errorCode;
|
|
8246
8269
|
const detail = [type, code2].filter((part) => typeof part === "string" && part.length > 0).join(", ");
|
|
8247
8270
|
const requestId = candidate.request_id ?? candidate.error?.request_id ?? candidate.requestId ?? candidate.requestID;
|
|
8248
|
-
return
|
|
8271
|
+
return printable(
|
|
8272
|
+
`the server answered ${status}${detail ? ` (${detail})` : ""}${requestId ? `, request ${requestId}` : ""}`
|
|
8273
|
+
);
|
|
8249
8274
|
}
|
|
8250
8275
|
const name = error.name;
|
|
8251
8276
|
const causeName = candidate.cause?.name;
|
|
@@ -8263,15 +8288,6 @@ import { randomUUID } from "node:crypto";
|
|
|
8263
8288
|
import { closeSync, constants, fstatSync, openSync, readSync } from "node:fs";
|
|
8264
8289
|
import { createInterface } from "node:readline/promises";
|
|
8265
8290
|
|
|
8266
|
-
// src/printable.ts
|
|
8267
|
-
var UNSAFE_CHARACTERS = new RegExp(
|
|
8268
|
-
"[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u061c\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2069\\ufeff\\ufe00-\\ufe0f\\u{e0000}-\\u{e007f}]",
|
|
8269
|
-
"gu"
|
|
8270
|
-
);
|
|
8271
|
-
function printable(text) {
|
|
8272
|
-
return text.replace(UNSAFE_CHARACTERS, "\uFFFD");
|
|
8273
|
-
}
|
|
8274
|
-
|
|
8275
8291
|
// src/non-api-host.ts
|
|
8276
8292
|
function hostOf(url) {
|
|
8277
8293
|
try {
|
|
@@ -8306,10 +8322,20 @@ var FEEDBACK_COMMENT_VALUES = ["--body", "--body-file"];
|
|
|
8306
8322
|
var FEEDBACK_COMMENT_BOOLEANS = [];
|
|
8307
8323
|
var FEEDBACK_LIST_VALUES = ["--cursor"];
|
|
8308
8324
|
var FEEDBACK_LIST_BOOLEANS = ["--json"];
|
|
8325
|
+
var FEEDBACK_CREATE_FLAG_HELP = {
|
|
8326
|
+
"--title": "The title of the issue; read interactively when omitted.",
|
|
8327
|
+
"--field": "A form field as id=value; repeat for several.",
|
|
8328
|
+
"--fields": "A JSON or YAML file with the form fields by id.",
|
|
8329
|
+
"--yes": "Skip the confirmation and send the report.",
|
|
8330
|
+
"--confirm-duplicate": "Send even when a similar issue already exists."
|
|
8331
|
+
};
|
|
8309
8332
|
var FEEDBACK_COMMANDS = [
|
|
8310
8333
|
{
|
|
8311
8334
|
path: "feedback bug",
|
|
8312
8335
|
summary: "Report a bug to the Nouter feedback repository",
|
|
8336
|
+
description: "Opens a bug report in the Nouter feedback repository, with the fields of the form.",
|
|
8337
|
+
examples: ["feedback bug --title hang --field steps=open --yes", "feedback bug --json --yes"],
|
|
8338
|
+
flagHelp: FEEDBACK_CREATE_FLAG_HELP,
|
|
8313
8339
|
values: FEEDBACK_CREATE_VALUES,
|
|
8314
8340
|
booleans: FEEDBACK_CREATE_BOOLEANS,
|
|
8315
8341
|
positionals: []
|
|
@@ -8317,6 +8343,9 @@ var FEEDBACK_COMMANDS = [
|
|
|
8317
8343
|
{
|
|
8318
8344
|
path: "feedback feature",
|
|
8319
8345
|
summary: "Request a feature in the Nouter feedback repository",
|
|
8346
|
+
description: "Opens a feature request in the Nouter feedback repository, with the fields of the form.",
|
|
8347
|
+
examples: ["feedback feature --title dark-mode --yes", "feedback feature --json --yes"],
|
|
8348
|
+
flagHelp: FEEDBACK_CREATE_FLAG_HELP,
|
|
8320
8349
|
values: FEEDBACK_CREATE_VALUES,
|
|
8321
8350
|
booleans: FEEDBACK_CREATE_BOOLEANS,
|
|
8322
8351
|
positionals: []
|
|
@@ -8324,6 +8353,9 @@ var FEEDBACK_COMMANDS = [
|
|
|
8324
8353
|
{
|
|
8325
8354
|
path: "feedback question",
|
|
8326
8355
|
summary: "Ask a question in the Nouter feedback repository",
|
|
8356
|
+
description: "Opens a question in the Nouter feedback repository, with the fields of the form.",
|
|
8357
|
+
examples: ["feedback question --title config --yes", "feedback question --json --yes"],
|
|
8358
|
+
flagHelp: FEEDBACK_CREATE_FLAG_HELP,
|
|
8327
8359
|
values: FEEDBACK_CREATE_VALUES,
|
|
8328
8360
|
booleans: FEEDBACK_CREATE_BOOLEANS,
|
|
8329
8361
|
positionals: []
|
|
@@ -8331,6 +8363,8 @@ var FEEDBACK_COMMANDS = [
|
|
|
8331
8363
|
{
|
|
8332
8364
|
path: "feedback show",
|
|
8333
8365
|
summary: "Show one feedback issue, its body and its replies",
|
|
8366
|
+
description: "Prints one feedback issue with its body and its replies.",
|
|
8367
|
+
examples: ["feedback show <n>", "feedback show <n> --json"],
|
|
8334
8368
|
values: FEEDBACK_SHOW_VALUES,
|
|
8335
8369
|
booleans: FEEDBACK_SHOW_BOOLEANS,
|
|
8336
8370
|
positionals: ["<n>"]
|
|
@@ -8338,6 +8372,8 @@ var FEEDBACK_COMMANDS = [
|
|
|
8338
8372
|
{
|
|
8339
8373
|
path: "feedback vote",
|
|
8340
8374
|
summary: "Vote for a feedback issue",
|
|
8375
|
+
description: "Votes for one feedback issue.",
|
|
8376
|
+
examples: ["feedback vote <n>"],
|
|
8341
8377
|
values: FEEDBACK_VOTE_VALUES,
|
|
8342
8378
|
booleans: FEEDBACK_VOTE_BOOLEANS,
|
|
8343
8379
|
positionals: ["<n>"]
|
|
@@ -8345,6 +8381,12 @@ var FEEDBACK_COMMANDS = [
|
|
|
8345
8381
|
{
|
|
8346
8382
|
path: "feedback comment",
|
|
8347
8383
|
summary: "Comment on a feedback issue",
|
|
8384
|
+
description: "Comments on one feedback issue, with the text inline or from a file.",
|
|
8385
|
+
examples: ["feedback comment <n> --body thanks", "feedback comment <n> --body-file reply.md"],
|
|
8386
|
+
flagHelp: {
|
|
8387
|
+
"--body": "The comment text.",
|
|
8388
|
+
"--body-file": "A file with the comment text."
|
|
8389
|
+
},
|
|
8348
8390
|
values: FEEDBACK_COMMENT_VALUES,
|
|
8349
8391
|
booleans: FEEDBACK_COMMENT_BOOLEANS,
|
|
8350
8392
|
positionals: ["<n>"]
|
|
@@ -8352,6 +8394,9 @@ var FEEDBACK_COMMANDS = [
|
|
|
8352
8394
|
{
|
|
8353
8395
|
path: "feedback list",
|
|
8354
8396
|
summary: "List the feedback issues you opened, voted for or commented on",
|
|
8397
|
+
description: "Lists the feedback issues you opened, voted for or commented on.",
|
|
8398
|
+
examples: ["feedback list", "feedback list --cursor <cursor> --json"],
|
|
8399
|
+
flagHelp: { "--cursor": "The cursor of the next page." },
|
|
8355
8400
|
values: FEEDBACK_LIST_VALUES,
|
|
8356
8401
|
booleans: FEEDBACK_LIST_BOOLEANS,
|
|
8357
8402
|
positionals: []
|
|
@@ -8509,14 +8554,14 @@ async function feedbackRequest(auth, method, path, body, deps, headers = {}) {
|
|
|
8509
8554
|
if (notApi !== null) throw new deps.CliError(printable(notApi));
|
|
8510
8555
|
const text = await response.text();
|
|
8511
8556
|
let parsed;
|
|
8512
|
-
let
|
|
8557
|
+
let invalid2 = false;
|
|
8513
8558
|
try {
|
|
8514
8559
|
parsed = text === "" ? void 0 : JSON.parse(text);
|
|
8515
8560
|
} catch {
|
|
8516
|
-
|
|
8561
|
+
invalid2 = true;
|
|
8517
8562
|
}
|
|
8518
|
-
if (!response.ok) throw parseApiError(response.status,
|
|
8519
|
-
if (
|
|
8563
|
+
if (!response.ok) throw parseApiError(response.status, invalid2 ? void 0 : parsed, response.headers);
|
|
8564
|
+
if (invalid2) throw new deps.CliError("The feedback service answered with something that is not JSON.");
|
|
8520
8565
|
return parsed;
|
|
8521
8566
|
}
|
|
8522
8567
|
function parseFormFields(value) {
|
|
@@ -9067,17 +9112,32 @@ async function feedbackCommand(argv, deps) {
|
|
|
9067
9112
|
}
|
|
9068
9113
|
|
|
9069
9114
|
// src/commands.ts
|
|
9115
|
+
var FLAG_HELP = {
|
|
9116
|
+
"--json": "Print the raw JSON response.",
|
|
9117
|
+
"--include-archived": "Include archived records.",
|
|
9118
|
+
"--order": "Sort order: asc or desc."
|
|
9119
|
+
};
|
|
9070
9120
|
var COMMANDS = [
|
|
9071
9121
|
{
|
|
9072
9122
|
path: "login",
|
|
9073
9123
|
summary: "Log in through the browser or a pasted code, or store an API key from stdin",
|
|
9124
|
+
description: "Stores the CLI session from the console, or a machine API key read from stdin. With no flag it picks the browser or the pasted code by the session it detects.",
|
|
9125
|
+
examples: ["login", "login --api-key", "login --paste"],
|
|
9126
|
+
flagHelp: {
|
|
9127
|
+
"--api-key": "Read a machine API key from stdin instead of the console flow.",
|
|
9128
|
+
"--browser": "Open the console and wait for the code on a loopback server.",
|
|
9129
|
+
"--paste": "Print the console URL and read the pasted code#state from stdin."
|
|
9130
|
+
},
|
|
9074
9131
|
values: [],
|
|
9075
9132
|
booleans: ["--api-key", "--browser", "--paste"],
|
|
9076
9133
|
positionals: []
|
|
9077
9134
|
},
|
|
9078
9135
|
{
|
|
9079
9136
|
path: "logout",
|
|
9080
|
-
summary: "Revoke the CLI session and remove the
|
|
9137
|
+
summary: "Revoke the CLI session and remove the credential (--all: every session); an insecure config revokes only if NOUTER_PLATFORM_BASE_URL is set",
|
|
9138
|
+
description: "Revokes the session on the server and removes the stored credential from this machine.",
|
|
9139
|
+
examples: ["logout", "logout --all"],
|
|
9140
|
+
flagHelp: { "--all": "Revoke every CLI session of this user, not only the current one." },
|
|
9081
9141
|
values: [],
|
|
9082
9142
|
booleans: ["--all"],
|
|
9083
9143
|
positionals: []
|
|
@@ -9085,6 +9145,8 @@ var COMMANDS = [
|
|
|
9085
9145
|
{
|
|
9086
9146
|
path: "whoami",
|
|
9087
9147
|
summary: "Show the organization, the role, the scopes and the session",
|
|
9148
|
+
description: "Prints the organization, the role, the scopes and the session of the stored credential.",
|
|
9149
|
+
examples: ["whoami", "whoami --json"],
|
|
9088
9150
|
values: [],
|
|
9089
9151
|
booleans: ["--json"],
|
|
9090
9152
|
positionals: []
|
|
@@ -9092,6 +9154,8 @@ var COMMANDS = [
|
|
|
9092
9154
|
{
|
|
9093
9155
|
path: "auth status",
|
|
9094
9156
|
summary: "Show which credential the CLI would use, without printing it",
|
|
9157
|
+
description: "Names the credential that would win, from the environment and the stored config, without printing.",
|
|
9158
|
+
examples: ["auth status"],
|
|
9095
9159
|
values: [],
|
|
9096
9160
|
booleans: [],
|
|
9097
9161
|
positionals: []
|
|
@@ -9099,6 +9163,8 @@ var COMMANDS = [
|
|
|
9099
9163
|
{
|
|
9100
9164
|
path: "auth sessions list",
|
|
9101
9165
|
summary: "List the CLI sessions of the stored session",
|
|
9166
|
+
description: "Lists the CLI login sessions of this user, with their host, dates and status.",
|
|
9167
|
+
examples: ["auth sessions list", "auth sessions list --json"],
|
|
9102
9168
|
values: [],
|
|
9103
9169
|
booleans: ["--json"],
|
|
9104
9170
|
positionals: []
|
|
@@ -9106,6 +9172,8 @@ var COMMANDS = [
|
|
|
9106
9172
|
{
|
|
9107
9173
|
path: "auth sessions revoke",
|
|
9108
9174
|
summary: "Revoke one of the CLI sessions of this user",
|
|
9175
|
+
description: "Revokes one CLI session of this user by its id.",
|
|
9176
|
+
examples: ["auth sessions revoke <session-id>", "auth sessions revoke <session-id> --json"],
|
|
9109
9177
|
values: [],
|
|
9110
9178
|
booleans: ["--json"],
|
|
9111
9179
|
positionals: ["<session-id>"]
|
|
@@ -9113,6 +9181,8 @@ var COMMANDS = [
|
|
|
9113
9181
|
{
|
|
9114
9182
|
path: "version",
|
|
9115
9183
|
summary: "Show the CLI version and the version of the SDK it ships",
|
|
9184
|
+
description: "Prints the version of the CLI that runs and the version of the SDK it ships.",
|
|
9185
|
+
examples: ["version"],
|
|
9116
9186
|
values: [],
|
|
9117
9187
|
booleans: [],
|
|
9118
9188
|
positionals: []
|
|
@@ -9120,6 +9190,8 @@ var COMMANDS = [
|
|
|
9120
9190
|
{
|
|
9121
9191
|
path: "agents list",
|
|
9122
9192
|
summary: "List every agent",
|
|
9193
|
+
description: "Lists every agent of the organization.",
|
|
9194
|
+
examples: ["agents list", "agents list --json"],
|
|
9123
9195
|
values: [],
|
|
9124
9196
|
booleans: ["--json"],
|
|
9125
9197
|
positionals: []
|
|
@@ -9127,13 +9199,27 @@ var COMMANDS = [
|
|
|
9127
9199
|
{
|
|
9128
9200
|
path: "agents get",
|
|
9129
9201
|
summary: "Show one agent by id",
|
|
9202
|
+
description: "Prints the name, the model, the version and the id of one agent.",
|
|
9203
|
+
examples: ["agents get <agent-id>"],
|
|
9130
9204
|
values: [],
|
|
9131
|
-
booleans: [],
|
|
9205
|
+
booleans: ["--json"],
|
|
9206
|
+
positionals: ["<agent-id>"]
|
|
9207
|
+
},
|
|
9208
|
+
{
|
|
9209
|
+
path: "agents archive",
|
|
9210
|
+
summary: "Archive an agent, which can't be undone",
|
|
9211
|
+
description: "Archives one agent by id. It can't be undone: pass --yes to confirm, and --json to print the agent.",
|
|
9212
|
+
examples: ["agents archive agent_123 --yes", "agents archive agent_123 --yes --json"],
|
|
9213
|
+
flagHelp: { "--yes": "Confirm the archive; it can't be undone." },
|
|
9214
|
+
values: [],
|
|
9215
|
+
booleans: ["--yes", "--json"],
|
|
9132
9216
|
positionals: ["<agent-id>"]
|
|
9133
9217
|
},
|
|
9134
9218
|
{
|
|
9135
9219
|
path: "environments list",
|
|
9136
9220
|
summary: "List every environment",
|
|
9221
|
+
description: "Lists every environment of the organization.",
|
|
9222
|
+
examples: ["environments list", "environments list --json"],
|
|
9137
9223
|
values: [],
|
|
9138
9224
|
booleans: ["--json"],
|
|
9139
9225
|
positionals: []
|
|
@@ -9141,13 +9227,29 @@ var COMMANDS = [
|
|
|
9141
9227
|
{
|
|
9142
9228
|
path: "environments get",
|
|
9143
9229
|
summary: "Show one environment by id",
|
|
9230
|
+
description: "Prints the name, the id and the creation date of one environment.",
|
|
9231
|
+
examples: ["environments get <environment-id>"],
|
|
9144
9232
|
values: [],
|
|
9145
|
-
booleans: [],
|
|
9233
|
+
booleans: ["--json"],
|
|
9146
9234
|
positionals: ["<environment-id>"]
|
|
9147
9235
|
},
|
|
9148
9236
|
{
|
|
9149
9237
|
path: "sessions list",
|
|
9150
9238
|
summary: "List the sessions, with the filters the API accepts",
|
|
9239
|
+
description: "Lists the agent sessions, one row per session, with the filters the API accepts.",
|
|
9240
|
+
examples: [
|
|
9241
|
+
"sessions list",
|
|
9242
|
+
"sessions list --agent <agent-id> --status completed --json",
|
|
9243
|
+
"sessions list --since 2026-11-01 --order desc"
|
|
9244
|
+
],
|
|
9245
|
+
flagHelp: {
|
|
9246
|
+
"--agent": "Only the sessions of this agent.",
|
|
9247
|
+
"--agent-version": "Only this version of the agent; needs --agent.",
|
|
9248
|
+
"--user-profile": "Only the sessions of this person.",
|
|
9249
|
+
"--status": "Only these statuses; repeat or separate with commas.",
|
|
9250
|
+
"--since": "Created at or after this date, YYYY-MM-DD or RFC 3339.",
|
|
9251
|
+
"--until": "Created at or before this date, YYYY-MM-DD or RFC 3339."
|
|
9252
|
+
},
|
|
9151
9253
|
values: ["--agent", "--agent-version", "--user-profile", "--status", "--since", "--until", "--order"],
|
|
9152
9254
|
booleans: ["--include-archived", "--json"],
|
|
9153
9255
|
positionals: []
|
|
@@ -9155,6 +9257,8 @@ var COMMANDS = [
|
|
|
9155
9257
|
{
|
|
9156
9258
|
path: "sessions get",
|
|
9157
9259
|
summary: "Show one session by id",
|
|
9260
|
+
description: "Prints the detail of one session, with its stats and its cost.",
|
|
9261
|
+
examples: ["sessions get <session-id>", "sessions get <session-id> --json"],
|
|
9158
9262
|
values: [],
|
|
9159
9263
|
booleans: ["--json"],
|
|
9160
9264
|
positionals: ["<session-id>"]
|
|
@@ -9162,6 +9266,16 @@ var COMMANDS = [
|
|
|
9162
9266
|
{
|
|
9163
9267
|
path: "sessions events",
|
|
9164
9268
|
summary: "List the events and the traces of a session",
|
|
9269
|
+
description: "Lists the events and the traces of one session, one line per event.",
|
|
9270
|
+
examples: [
|
|
9271
|
+
"sessions events <session-id>",
|
|
9272
|
+
"sessions events <session-id> --type user.message,agent.message --order desc --json"
|
|
9273
|
+
],
|
|
9274
|
+
flagHelp: {
|
|
9275
|
+
"--type": "Only these event types; repeat or separate with commas.",
|
|
9276
|
+
"--since": "Created at or after this date, YYYY-MM-DD or RFC 3339.",
|
|
9277
|
+
"--until": "Created at or before this date, YYYY-MM-DD or RFC 3339."
|
|
9278
|
+
},
|
|
9165
9279
|
values: ["--type", "--since", "--until", "--order"],
|
|
9166
9280
|
booleans: ["--json"],
|
|
9167
9281
|
positionals: ["<session-id>"]
|
|
@@ -9169,13 +9283,102 @@ var COMMANDS = [
|
|
|
9169
9283
|
{
|
|
9170
9284
|
path: "usage",
|
|
9171
9285
|
summary: "Show the usage and the cost by day, model, agent, person or session",
|
|
9286
|
+
description: "Reads one page of the cost ledger, grouped by up to five dimensions.",
|
|
9287
|
+
examples: [
|
|
9288
|
+
"usage --days 7 --group-by day,model",
|
|
9289
|
+
"usage --since 2026-11-01 --until 2026-11-30 --json"
|
|
9290
|
+
],
|
|
9291
|
+
flagHelp: {
|
|
9292
|
+
"--days": "The window: 7, 30 or 90 (default 30).",
|
|
9293
|
+
"--since": "Start date, YYYY-MM-DD or RFC 3339.",
|
|
9294
|
+
"--until": "End date, YYYY-MM-DD or RFC 3339.",
|
|
9295
|
+
"--group-by": "A dimension, up to five; repeat or separate with commas.",
|
|
9296
|
+
"--user-profile": "Filter by person.",
|
|
9297
|
+
"--limit": "Rows per page, 1 to 10000 (default 1000).",
|
|
9298
|
+
"--page": "The cursor of the next page."
|
|
9299
|
+
},
|
|
9172
9300
|
values: ["--days", "--since", "--until", "--group-by", "--user-profile", "--limit", "--page"],
|
|
9173
9301
|
booleans: ["--json"],
|
|
9174
9302
|
positionals: []
|
|
9175
9303
|
},
|
|
9304
|
+
{
|
|
9305
|
+
path: "usage limits",
|
|
9306
|
+
summary: "Show the effective usage limits of the organization, or of an agent with --agent-id",
|
|
9307
|
+
description: "Prints the effective cost limits with their kind, amount and start date. It only reads: the console sets them.",
|
|
9308
|
+
examples: ["usage limits", "usage limits --agent-id agent_01J9F3K2M8 --json"],
|
|
9309
|
+
flagHelp: { "--agent-id": "Show the effective limits of this agent instead of the organization's." },
|
|
9310
|
+
values: ["--agent-id"],
|
|
9311
|
+
booleans: ["--json"],
|
|
9312
|
+
positionals: []
|
|
9313
|
+
},
|
|
9314
|
+
{
|
|
9315
|
+
path: "usage rate-limits",
|
|
9316
|
+
summary: "Show the deployment's request limits per minute and per day, and one entry per API key",
|
|
9317
|
+
description: "Prints the request ceilings of the deployment and the current counts, with one entry per active API key. It only reads: the deployment sets the values.",
|
|
9318
|
+
examples: ["usage rate-limits", "usage rate-limits --json"],
|
|
9319
|
+
values: [],
|
|
9320
|
+
booleans: ["--json"],
|
|
9321
|
+
positionals: []
|
|
9322
|
+
},
|
|
9323
|
+
{
|
|
9324
|
+
path: "keys list",
|
|
9325
|
+
summary: "List the API keys of the organization, without the key value",
|
|
9326
|
+
description: "Lists the API keys of the organization; the key value is never printed, only its prefix.",
|
|
9327
|
+
examples: ["keys list", "keys list --json"],
|
|
9328
|
+
values: [],
|
|
9329
|
+
booleans: ["--json"],
|
|
9330
|
+
positionals: []
|
|
9331
|
+
},
|
|
9332
|
+
{
|
|
9333
|
+
path: "keys create",
|
|
9334
|
+
summary: "Create an API key with scopes, expiry, agent or preset, and print the key once",
|
|
9335
|
+
description: "Creates an API key and prints the key value once on stdout; the metadata goes to stderr.",
|
|
9336
|
+
examples: [
|
|
9337
|
+
"keys create --name ci --preset ci",
|
|
9338
|
+
"keys create --name deploy --scopes agents:write,sessions:write --expires-at 2027-01-01T00:00:00Z"
|
|
9339
|
+
],
|
|
9340
|
+
flagHelp: {
|
|
9341
|
+
"--name": "A name for the key.",
|
|
9342
|
+
"--scopes": "The scopes, separated by commas; mutually exclusive with --preset.",
|
|
9343
|
+
"--preset": "backend or ci; mutually exclusive with --scopes.",
|
|
9344
|
+
"--expires-at": "Expiry date, RFC 3339.",
|
|
9345
|
+
"--agent-id": "Bind the key to one agent."
|
|
9346
|
+
},
|
|
9347
|
+
values: ["--name", "--scopes", "--expires-at", "--agent-id", "--preset"],
|
|
9348
|
+
booleans: ["--json"],
|
|
9349
|
+
positionals: []
|
|
9350
|
+
},
|
|
9351
|
+
{
|
|
9352
|
+
path: "keys rotate",
|
|
9353
|
+
summary: "Rotate an API key with a grace period and print the new key once",
|
|
9354
|
+
description: "Rotates the key, leaving the old one valid during the grace period, and prints the new key once. Before rotating it resolves the prefix with `keys list` and warns if it is the key this process authenticates with.",
|
|
9355
|
+
examples: [
|
|
9356
|
+
"keys rotate ak_0123456789abcdef --yes",
|
|
9357
|
+
"keys rotate ak_0123456789abcdef --grace-period-seconds 3600 --yes"
|
|
9358
|
+
],
|
|
9359
|
+
flagHelp: {
|
|
9360
|
+
"--grace-period-seconds": "How long the old key stays valid, in seconds; 0 if not given.",
|
|
9361
|
+
"--yes": "Rotate without asking for confirmation."
|
|
9362
|
+
},
|
|
9363
|
+
values: ["--grace-period-seconds"],
|
|
9364
|
+
booleans: ["--yes", "--json"],
|
|
9365
|
+
positionals: ["<key-id>"]
|
|
9366
|
+
},
|
|
9367
|
+
{
|
|
9368
|
+
path: "keys revoke",
|
|
9369
|
+
summary: "Revoke an API key, with a warning when it is this process's own key",
|
|
9370
|
+
description: "Revokes the key with `DELETE /v1/oma/api_keys/{id}`. Before revoking it resolves the prefix with `keys list` and warns if it is the key this process authenticates with.",
|
|
9371
|
+
examples: ["keys revoke ak_0123456789abcdef --yes"],
|
|
9372
|
+
flagHelp: { "--yes": "Revoke without asking for confirmation." },
|
|
9373
|
+
values: [],
|
|
9374
|
+
booleans: ["--yes", "--json"],
|
|
9375
|
+
positionals: ["<key-id>"]
|
|
9376
|
+
},
|
|
9176
9377
|
{
|
|
9177
9378
|
path: "service-accounts list",
|
|
9178
9379
|
summary: "List the service accounts",
|
|
9380
|
+
description: "Lists the service accounts of the organization, with their role and status.",
|
|
9381
|
+
examples: ["service-accounts list", "service-accounts list --include-archived --json"],
|
|
9179
9382
|
values: [],
|
|
9180
9383
|
booleans: ["--include-archived", "--json"],
|
|
9181
9384
|
positionals: []
|
|
@@ -9183,6 +9386,15 @@ var COMMANDS = [
|
|
|
9183
9386
|
{
|
|
9184
9387
|
path: "service-accounts create",
|
|
9185
9388
|
summary: "Create a service account",
|
|
9389
|
+
description: "Creates a service account with a name and an organization role.",
|
|
9390
|
+
examples: [
|
|
9391
|
+
"service-accounts create --name builder --organization-role developer",
|
|
9392
|
+
"service-accounts create --name admin-bot --organization-role admin --json"
|
|
9393
|
+
],
|
|
9394
|
+
flagHelp: {
|
|
9395
|
+
"--name": "The name of the service account.",
|
|
9396
|
+
"--organization-role": "developer or admin."
|
|
9397
|
+
},
|
|
9186
9398
|
values: ["--name", "--organization-role"],
|
|
9187
9399
|
booleans: ["--json"],
|
|
9188
9400
|
positionals: []
|
|
@@ -9190,6 +9402,8 @@ var COMMANDS = [
|
|
|
9190
9402
|
{
|
|
9191
9403
|
path: "service-accounts archive",
|
|
9192
9404
|
summary: "Archive a service account by id",
|
|
9405
|
+
description: "Archives one service account by id; an archived account stays readable but cannot be used.",
|
|
9406
|
+
examples: ["service-accounts archive <service-account-id>"],
|
|
9193
9407
|
values: [],
|
|
9194
9408
|
booleans: [],
|
|
9195
9409
|
positionals: ["<service-account-id>"]
|
|
@@ -9197,6 +9411,8 @@ var COMMANDS = [
|
|
|
9197
9411
|
{
|
|
9198
9412
|
path: "federation issuers list",
|
|
9199
9413
|
summary: "List the federation issuers",
|
|
9414
|
+
description: "Lists the federation issuers, with their provider, URL and status.",
|
|
9415
|
+
examples: ["federation issuers list", "federation issuers list --include-archived --json"],
|
|
9200
9416
|
values: [],
|
|
9201
9417
|
booleans: ["--include-archived", "--json"],
|
|
9202
9418
|
positionals: []
|
|
@@ -9204,6 +9420,19 @@ var COMMANDS = [
|
|
|
9204
9420
|
{
|
|
9205
9421
|
path: "federation issuers create",
|
|
9206
9422
|
summary: "Create a federation issuer",
|
|
9423
|
+
description: "Creates a federation issuer for github, gcp, aws or custom.",
|
|
9424
|
+
examples: [
|
|
9425
|
+
"federation issuers create --name github --provider github --issuer-url https://token.actions.githubusercontent.com",
|
|
9426
|
+
"federation issuers create --name gcp --provider gcp --issuer-url https://accounts.google.com --jwks-url https://www.googleapis.com/oauth2/v3/certs --json"
|
|
9427
|
+
],
|
|
9428
|
+
flagHelp: {
|
|
9429
|
+
"--name": "The name of the issuer.",
|
|
9430
|
+
"--provider": "github, gcp, aws or custom.",
|
|
9431
|
+
"--issuer-url": "The issuer URL, https.",
|
|
9432
|
+
"--jwks-url": "The explicit JWKS URL, when the provider does not serve discovery.",
|
|
9433
|
+
"--check-jti": "Require the token id to be unique; true or false.",
|
|
9434
|
+
"--max-token-lifetime": "The longest token lifetime accepted, in seconds (60 to 86400)."
|
|
9435
|
+
},
|
|
9207
9436
|
values: ["--name", "--provider", "--issuer-url", "--jwks-url", "--check-jti", "--max-token-lifetime"],
|
|
9208
9437
|
booleans: ["--json"],
|
|
9209
9438
|
positionals: []
|
|
@@ -9211,6 +9440,8 @@ var COMMANDS = [
|
|
|
9211
9440
|
{
|
|
9212
9441
|
path: "federation issuers archive",
|
|
9213
9442
|
summary: "Archive a federation issuer by id",
|
|
9443
|
+
description: "Archives one federation issuer by id.",
|
|
9444
|
+
examples: ["federation issuers archive <issuer-id>"],
|
|
9214
9445
|
values: [],
|
|
9215
9446
|
booleans: [],
|
|
9216
9447
|
positionals: ["<issuer-id>"]
|
|
@@ -9218,6 +9449,9 @@ var COMMANDS = [
|
|
|
9218
9449
|
{
|
|
9219
9450
|
path: "federation rules list",
|
|
9220
9451
|
summary: "List the federation rules, optionally by issuer",
|
|
9452
|
+
description: "Lists the federation rules, optionally filtered by issuer.",
|
|
9453
|
+
examples: ["federation rules list", "federation rules list --issuer <issuer-id> --json"],
|
|
9454
|
+
flagHelp: { "--issuer": "Only the rules of this issuer." },
|
|
9221
9455
|
values: ["--issuer"],
|
|
9222
9456
|
booleans: ["--include-archived", "--json"],
|
|
9223
9457
|
positionals: []
|
|
@@ -9225,6 +9459,23 @@ var COMMANDS = [
|
|
|
9225
9459
|
{
|
|
9226
9460
|
path: "federation rules create",
|
|
9227
9461
|
summary: "Create a federation rule",
|
|
9462
|
+
description: "Creates a rule that maps one issuer's identity to a service account, a workspace and a set of scopes.",
|
|
9463
|
+
examples: [
|
|
9464
|
+
"federation rules create --name ci --issuer <issuer-id> --service-account <service-account-id> --subject-prefix repo:acme/ --workspace <workspace-id> --scopes agents:read,agents:write",
|
|
9465
|
+
"federation rules create --name ci --issuer <issuer-id> --service-account <service-account-id> --claim sub=repo:acme/api:pull_request --all-workspaces --scopes agents:read --json"
|
|
9466
|
+
],
|
|
9467
|
+
flagHelp: {
|
|
9468
|
+
"--name": "The name of the rule.",
|
|
9469
|
+
"--issuer": "The id of the issuer the rule matches.",
|
|
9470
|
+
"--service-account": "The id of the service account the token targets.",
|
|
9471
|
+
"--subject-prefix": "Match tokens whose subject starts with this prefix.",
|
|
9472
|
+
"--audience": "Match tokens with this audience.",
|
|
9473
|
+
"--claim": "Match a claim as key=value; repeat for several.",
|
|
9474
|
+
"--workspace": "The workspace of the target; exclusive with --all-workspaces.",
|
|
9475
|
+
"--scopes": "The scopes of the token, comma separated.",
|
|
9476
|
+
"--token-lifetime": "The token lifetime in seconds (60 to 86400).",
|
|
9477
|
+
"--all-workspaces": "Let the rule apply to every workspace; exclusive with --workspace."
|
|
9478
|
+
},
|
|
9228
9479
|
values: [
|
|
9229
9480
|
"--name",
|
|
9230
9481
|
"--issuer",
|
|
@@ -9242,6 +9493,8 @@ var COMMANDS = [
|
|
|
9242
9493
|
{
|
|
9243
9494
|
path: "federation rules archive",
|
|
9244
9495
|
summary: "Archive a federation rule by id",
|
|
9496
|
+
description: "Archives one federation rule by id.",
|
|
9497
|
+
examples: ["federation rules archive <rule-id>"],
|
|
9245
9498
|
values: [],
|
|
9246
9499
|
booleans: [],
|
|
9247
9500
|
positionals: ["<rule-id>"]
|
|
@@ -9249,6 +9502,8 @@ var COMMANDS = [
|
|
|
9249
9502
|
{
|
|
9250
9503
|
path: "federation token",
|
|
9251
9504
|
summary: "Exchange the federated identity for a platform access token",
|
|
9505
|
+
description: "Exchanges the configured federated identity for a platform access token.",
|
|
9506
|
+
examples: ["federation token", "federation token --json"],
|
|
9252
9507
|
values: [],
|
|
9253
9508
|
booleans: ["--json"],
|
|
9254
9509
|
positionals: []
|
|
@@ -9256,6 +9511,12 @@ var COMMANDS = [
|
|
|
9256
9511
|
{
|
|
9257
9512
|
path: "elevate",
|
|
9258
9513
|
summary: "Confirm it's you for two hours, through the browser or a pasted code",
|
|
9514
|
+
description: "Confirms it is you for two hours, through the browser or a pasted code.",
|
|
9515
|
+
examples: ["elevate", "elevate --paste"],
|
|
9516
|
+
flagHelp: {
|
|
9517
|
+
"--browser": "Open the console and wait for the code on a loopback server.",
|
|
9518
|
+
"--paste": "Print the console URL and read the pasted code#state from stdin."
|
|
9519
|
+
},
|
|
9259
9520
|
values: [],
|
|
9260
9521
|
booleans: ["--browser", "--paste"],
|
|
9261
9522
|
positionals: []
|
|
@@ -9263,11 +9524,52 @@ var COMMANDS = [
|
|
|
9263
9524
|
{
|
|
9264
9525
|
path: "apply",
|
|
9265
9526
|
summary: "Apply agents and environments from files",
|
|
9266
|
-
|
|
9527
|
+
description: "Creates and updates agents and environments from YAML or JSON files, and tells what it would change.",
|
|
9528
|
+
examples: ["apply --file ./resources --dry-run", "apply -f ./agents.yaml -f ./environments.yaml"],
|
|
9529
|
+
flagHelp: {
|
|
9530
|
+
"--file": "The file or directory to read; repeat for several.",
|
|
9531
|
+
"--dry-run": "Print the plan without sending any change.",
|
|
9532
|
+
"--rotate-secrets": "Rotate the secrets of every agent that is updated.",
|
|
9533
|
+
"--require-eval": "Run an eval suite from a relative directory and stop the apply if it fails.",
|
|
9534
|
+
"-f": "Short form of --file; repeat for several."
|
|
9535
|
+
},
|
|
9536
|
+
values: ["--file", "--require-eval"],
|
|
9267
9537
|
booleans: ["--dry-run", "--rotate-secrets"],
|
|
9268
9538
|
positionals: [],
|
|
9269
9539
|
shortValues: ["-f"]
|
|
9270
9540
|
},
|
|
9541
|
+
{
|
|
9542
|
+
path: "eval",
|
|
9543
|
+
summary: "Run an eval suite against an agent",
|
|
9544
|
+
description: "Runs the suite of a directory against an agent: creates an ephemeral benchmark and run, prints the score and deletes them at the end unless --keep. The suite is suite.yaml; a relative directory is required.",
|
|
9545
|
+
examples: ["eval", "eval ./evals --runs 5 --json"],
|
|
9546
|
+
flagHelp: {
|
|
9547
|
+
"--agent": "The agent to evaluate; overrides the agent of suite.yaml.",
|
|
9548
|
+
"--environment": "The environment to run in; overrides the one of suite.yaml.",
|
|
9549
|
+
"--threshold": "The pass score, between 0 and 1; overrides suite.yaml (default 1).",
|
|
9550
|
+
"--runs": "How many runs per case, from 1 to 20; default 3 or the suite's.",
|
|
9551
|
+
"--concurrency": "How many runs at once, from 1 to 32; default 4 or the suite's.",
|
|
9552
|
+
"--case": "Only the cases whose path matches the glob; repeat for several.",
|
|
9553
|
+
"--tag": "Only the cases with the tag; repeat for several.",
|
|
9554
|
+
"--agent-version": "Pin the agent version instead of the current one.",
|
|
9555
|
+
"--wait-timeout": "Seconds to wait for the run, default 3600.",
|
|
9556
|
+
"--json": "Print the report as JSON instead of the table.",
|
|
9557
|
+
"--keep": "Keep the ephemeral benchmark and run instead of deleting them."
|
|
9558
|
+
},
|
|
9559
|
+
values: [
|
|
9560
|
+
"--agent",
|
|
9561
|
+
"--environment",
|
|
9562
|
+
"--threshold",
|
|
9563
|
+
"--runs",
|
|
9564
|
+
"--concurrency",
|
|
9565
|
+
"--case",
|
|
9566
|
+
"--tag",
|
|
9567
|
+
"--agent-version",
|
|
9568
|
+
"--wait-timeout"
|
|
9569
|
+
],
|
|
9570
|
+
booleans: ["--json", "--keep"],
|
|
9571
|
+
positionals: ["<dir>"]
|
|
9572
|
+
},
|
|
9271
9573
|
...FEEDBACK_COMMANDS
|
|
9272
9574
|
];
|
|
9273
9575
|
var BY_PATH = new Map(COMMANDS.map((command) => [command.path, command]));
|
|
@@ -9277,130 +9579,197 @@ function specFor(path) {
|
|
|
9277
9579
|
return spec;
|
|
9278
9580
|
}
|
|
9279
9581
|
|
|
9280
|
-
// src/
|
|
9582
|
+
// src/eval.ts
|
|
9281
9583
|
import { randomBytes } from "node:crypto";
|
|
9282
|
-
import {
|
|
9283
|
-
|
|
9284
|
-
|
|
9285
|
-
|
|
9286
|
-
|
|
9287
|
-
|
|
9288
|
-
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
9306
|
-
this.
|
|
9584
|
+
import { isAbsolute as isAbsolute2 } from "node:path";
|
|
9585
|
+
|
|
9586
|
+
// src/eval-signals.ts
|
|
9587
|
+
var SIGNAL_TIMEOUT_MS = 1e4;
|
|
9588
|
+
var SIGNALS = ["SIGINT", "SIGTERM"];
|
|
9589
|
+
var EvalSignalGuard = class {
|
|
9590
|
+
options;
|
|
9591
|
+
pending = /* @__PURE__ */ new Set();
|
|
9592
|
+
/** Los ids que ya se están archivando; `true` si los tomó el handler y `false` si los tomó el comando. */
|
|
9593
|
+
inFlight = /* @__PURE__ */ new Map();
|
|
9594
|
+
/** Los archivados que el comando ya empezó; el handler los espera antes de reportar y salir. */
|
|
9595
|
+
commandArchives = /* @__PURE__ */ new Map();
|
|
9596
|
+
listener = () => {
|
|
9597
|
+
void this.handleSignal();
|
|
9598
|
+
};
|
|
9599
|
+
controller = new AbortController();
|
|
9600
|
+
settledPromise;
|
|
9601
|
+
resolveSettled;
|
|
9602
|
+
runId;
|
|
9603
|
+
installed = false;
|
|
9604
|
+
handling = false;
|
|
9605
|
+
wasInterrupted = false;
|
|
9606
|
+
finished = false;
|
|
9607
|
+
constructor(options) {
|
|
9608
|
+
this.options = options;
|
|
9609
|
+
this.settledPromise = new Promise((resolve2) => {
|
|
9610
|
+
this.resolveSettled = resolve2;
|
|
9611
|
+
});
|
|
9307
9612
|
}
|
|
9308
|
-
|
|
9309
|
-
|
|
9310
|
-
|
|
9311
|
-
|
|
9312
|
-
|
|
9313
|
-
|
|
9314
|
-
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
|
|
9327
|
-
|
|
9613
|
+
/** El abort de la señal, para cortar el polling del run cuando el comando lo soporta. */
|
|
9614
|
+
get signal() {
|
|
9615
|
+
return this.controller.signal;
|
|
9616
|
+
}
|
|
9617
|
+
/** Si ya llegó una señal; el comando lo mira antes de escribir o de aplicar un plan. */
|
|
9618
|
+
get interrupted() {
|
|
9619
|
+
return this.wasInterrupted;
|
|
9620
|
+
}
|
|
9621
|
+
/** Se resuelve cuando la primera señal terminó de archivar y de avisar. */
|
|
9622
|
+
get settled() {
|
|
9623
|
+
return this.settledPromise;
|
|
9624
|
+
}
|
|
9625
|
+
/** El id del run que sigue en la plataforma; se usa en el aviso de la señal. */
|
|
9626
|
+
noteRun(id) {
|
|
9627
|
+
this.runId = id;
|
|
9628
|
+
}
|
|
9629
|
+
/** Un id que creó esta corrida; solo estos se archivan con una señal. */
|
|
9630
|
+
register(id) {
|
|
9631
|
+
this.inFlight.delete(id);
|
|
9632
|
+
this.commandArchives.delete(id);
|
|
9633
|
+
if (!this.finished) this.pending.add(id);
|
|
9634
|
+
}
|
|
9635
|
+
/**
|
|
9636
|
+
* El comando toma el id antes de archivarlo: una señal en esa ventana no lo archiva dos veces. Si el archivado
|
|
9637
|
+
* falla, el comando lo vuelve a registrar.
|
|
9638
|
+
*/
|
|
9639
|
+
claim(id) {
|
|
9640
|
+
return this.take(id, false);
|
|
9641
|
+
}
|
|
9642
|
+
/**
|
|
9643
|
+
* El comando ya arrancó el archivado de un id que reclamó. El handler espera esta promesa con el tope total antes
|
|
9644
|
+
* de reportar: una señal no puede cortar a mitad un archivado que ya estaba en curso.
|
|
9645
|
+
*/
|
|
9646
|
+
track(id, archive) {
|
|
9647
|
+
if (this.finished || this.inFlight.get(id) !== false) return;
|
|
9648
|
+
this.commandArchives.set(id, archive);
|
|
9649
|
+
}
|
|
9650
|
+
/** El archivado ya salió bien: el id no queda pendiente ni en vuelo. */
|
|
9651
|
+
markArchived(id) {
|
|
9652
|
+
this.pending.delete(id);
|
|
9653
|
+
this.inFlight.delete(id);
|
|
9654
|
+
this.commandArchives.delete(id);
|
|
9655
|
+
}
|
|
9656
|
+
/** Toma el id antes del await; `byHandler` decide si la segunda señal lo reporta. */
|
|
9657
|
+
take(id, byHandler) {
|
|
9658
|
+
if (this.finished) return false;
|
|
9659
|
+
if (!this.pending.delete(id)) return false;
|
|
9660
|
+
this.inFlight.set(id, byHandler);
|
|
9661
|
+
return true;
|
|
9662
|
+
}
|
|
9663
|
+
install() {
|
|
9664
|
+
if (this.installed) return;
|
|
9665
|
+
this.installed = true;
|
|
9666
|
+
for (const signal of SIGNALS) (this.options.signals ?? process).on(signal, this.listener);
|
|
9667
|
+
}
|
|
9668
|
+
uninstall() {
|
|
9669
|
+
if (!this.installed) return;
|
|
9670
|
+
this.installed = false;
|
|
9671
|
+
for (const signal of SIGNALS) (this.options.signals ?? process).off(signal, this.listener);
|
|
9672
|
+
}
|
|
9673
|
+
/**
|
|
9674
|
+
* La primera señal archiva lo pendiente con el tope total, avisa que el run sigue y sale con 130; la segunda no
|
|
9675
|
+
* espera: imprime lo que queda y sale enseguida. Es público para probarlo sin mandar señales reales.
|
|
9676
|
+
*/
|
|
9677
|
+
async handleSignal() {
|
|
9678
|
+
if (this.finished) return;
|
|
9679
|
+
if (this.handling) {
|
|
9680
|
+
this.reportPending(true);
|
|
9681
|
+
this.finish();
|
|
9682
|
+
this.resolveSettled();
|
|
9683
|
+
return;
|
|
9684
|
+
}
|
|
9685
|
+
this.handling = true;
|
|
9686
|
+
this.wasInterrupted = true;
|
|
9687
|
+
this.controller.abort();
|
|
9688
|
+
this.options.writeStderr(this.interruptedNotice());
|
|
9689
|
+
try {
|
|
9690
|
+
const deadline = Date.now() + (this.options.timeoutMs ?? SIGNAL_TIMEOUT_MS);
|
|
9691
|
+
for (const id of [...this.pending]) {
|
|
9692
|
+
const remaining = deadline - Date.now();
|
|
9693
|
+
if (remaining <= 0) break;
|
|
9694
|
+
if (!this.take(id, true)) continue;
|
|
9695
|
+
try {
|
|
9696
|
+
await withTimeout(this.options.archiveAgent(id), remaining);
|
|
9697
|
+
this.markArchived(id);
|
|
9698
|
+
} catch {
|
|
9699
|
+
this.register(id);
|
|
9700
|
+
}
|
|
9701
|
+
}
|
|
9702
|
+
await this.waitCommandArchives(deadline);
|
|
9703
|
+
this.reportPending();
|
|
9704
|
+
this.finish();
|
|
9705
|
+
} finally {
|
|
9706
|
+
this.resolveSettled();
|
|
9328
9707
|
}
|
|
9329
9708
|
}
|
|
9330
|
-
|
|
9331
|
-
const
|
|
9332
|
-
|
|
9333
|
-
|
|
9334
|
-
baseUrl: typeof parsed.baseUrl === "string" && parsed.baseUrl.length > 0 ? parsed.baseUrl : null,
|
|
9335
|
-
apiKey: parsed.apiKey
|
|
9336
|
-
};
|
|
9337
|
-
if (typeof parsed.iss === "string" && parsed.iss.length > 0) loaded.iss = parsed.iss;
|
|
9338
|
-
if (typeof parsed.clientId === "string" && parsed.clientId.length > 0) loaded.clientId = parsed.clientId;
|
|
9339
|
-
if (typeof parsed.sessionId === "string" && parsed.sessionId.length > 0) loaded.sessionId = parsed.sessionId;
|
|
9340
|
-
return loaded;
|
|
9341
|
-
} catch (error) {
|
|
9342
|
-
if (error instanceof ConfigStorageError) throw error;
|
|
9343
|
-
return null;
|
|
9709
|
+
interruptedNotice() {
|
|
9710
|
+
const run = this.runId === void 0 ? "the run" : `run ${this.runId}`;
|
|
9711
|
+
return `interrupted; ${run} keeps running on the platform
|
|
9712
|
+
`;
|
|
9344
9713
|
}
|
|
9345
|
-
|
|
9346
|
-
|
|
9347
|
-
|
|
9348
|
-
|
|
9349
|
-
|
|
9350
|
-
|
|
9351
|
-
|
|
9352
|
-
|
|
9714
|
+
/** Espera los archivados del comando con el mismo deadline total; los que no resuelven bien quedan pendientes. */
|
|
9715
|
+
async waitCommandArchives(deadline) {
|
|
9716
|
+
const entries = [...this.commandArchives];
|
|
9717
|
+
if (entries.length === 0) return;
|
|
9718
|
+
const remaining = deadline - Date.now();
|
|
9719
|
+
if (remaining <= 0) {
|
|
9720
|
+
for (const [id] of entries) this.register(id);
|
|
9721
|
+
return;
|
|
9722
|
+
}
|
|
9723
|
+
await Promise.all(
|
|
9724
|
+
entries.map(async ([id, archive]) => {
|
|
9725
|
+
try {
|
|
9726
|
+
await withTimeout(archive, remaining);
|
|
9727
|
+
} catch {
|
|
9728
|
+
this.register(id);
|
|
9729
|
+
}
|
|
9730
|
+
})
|
|
9731
|
+
);
|
|
9353
9732
|
}
|
|
9354
|
-
|
|
9355
|
-
|
|
9733
|
+
reportPending(includeCommandInFlight = false) {
|
|
9734
|
+
if (this.finished) return;
|
|
9735
|
+
const handlerInFlight = [...this.inFlight].filter(([, byHandler]) => byHandler).map(([id]) => id);
|
|
9736
|
+
const commandInFlight = includeCommandInFlight ? [...this.inFlight].filter(([, byHandler]) => !byHandler).map(([id]) => id) : [];
|
|
9737
|
+
const ids = [.../* @__PURE__ */ new Set([...this.pending, ...handlerInFlight, ...commandInFlight])];
|
|
9738
|
+
if (ids.length === 0) return;
|
|
9739
|
+
this.options.writeStderr(
|
|
9740
|
+
`warning: could not archive these eval agents: ${ids.join(", ")}; archive them manually.
|
|
9741
|
+
`
|
|
9742
|
+
);
|
|
9356
9743
|
}
|
|
9357
|
-
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
try {
|
|
9363
|
-
chmodSync(directory, 448);
|
|
9364
|
-
} catch {
|
|
9365
|
-
throw new Error(`Could not set the config directory ${directory} to 0700.`);
|
|
9744
|
+
finish() {
|
|
9745
|
+
if (this.finished) return;
|
|
9746
|
+
this.finished = true;
|
|
9747
|
+
this.uninstall();
|
|
9748
|
+
this.options.exit(130);
|
|
9366
9749
|
}
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
|
|
9373
|
-
|
|
9374
|
-
|
|
9375
|
-
|
|
9376
|
-
|
|
9377
|
-
|
|
9378
|
-
|
|
9379
|
-
`);
|
|
9380
|
-
closeSync2(fd);
|
|
9381
|
-
open = false;
|
|
9382
|
-
renameSync(temporary, path);
|
|
9383
|
-
} catch (error) {
|
|
9384
|
-
if (open) {
|
|
9385
|
-
try {
|
|
9386
|
-
closeSync2(fd);
|
|
9387
|
-
} catch {
|
|
9750
|
+
};
|
|
9751
|
+
function withTimeout(promise, ms) {
|
|
9752
|
+
return new Promise((resolve2, reject) => {
|
|
9753
|
+
const timer = setTimeout(() => reject(new Error("timeout")), ms);
|
|
9754
|
+
promise.then(
|
|
9755
|
+
(value) => {
|
|
9756
|
+
clearTimeout(timer);
|
|
9757
|
+
resolve2(value);
|
|
9758
|
+
},
|
|
9759
|
+
(error) => {
|
|
9760
|
+
clearTimeout(timer);
|
|
9761
|
+
reject(error);
|
|
9388
9762
|
}
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
unlinkSync(temporary);
|
|
9392
|
-
} catch {
|
|
9393
|
-
}
|
|
9394
|
-
throw error;
|
|
9395
|
-
}
|
|
9396
|
-
}
|
|
9397
|
-
function clearConfig() {
|
|
9398
|
-
const path = configPath();
|
|
9399
|
-
if (!existsSync(path)) return false;
|
|
9400
|
-
unlinkSync(path);
|
|
9401
|
-
return true;
|
|
9763
|
+
);
|
|
9764
|
+
});
|
|
9402
9765
|
}
|
|
9403
9766
|
|
|
9767
|
+
// src/eval-suite.ts
|
|
9768
|
+
var import_yaml3 = __toESM(require_dist(), 1);
|
|
9769
|
+
import { createHash } from "node:crypto";
|
|
9770
|
+
import { existsSync, readFileSync as readFileSync2, readdirSync as readdirSync2, realpathSync, statSync as statSync2 } from "node:fs";
|
|
9771
|
+
import { basename, isAbsolute, join as join2, relative, resolve, sep } from "node:path";
|
|
9772
|
+
|
|
9404
9773
|
// src/sessions-usage.ts
|
|
9405
9774
|
var SESSION_STATUSES = ["rescheduling", "running", "idle", "terminated"];
|
|
9406
9775
|
var USAGE_GROUP_BY = ["day", "model", "agent", "agent_version", "user_profile", "session"];
|
|
@@ -9543,8 +9912,9 @@ function eventRow(event) {
|
|
|
9543
9912
|
return [event.processed_at ?? "-", event.type, event.id, eventSummary(event)];
|
|
9544
9913
|
}
|
|
9545
9914
|
function table(rows) {
|
|
9546
|
-
const
|
|
9547
|
-
|
|
9915
|
+
const cells = rows.map((row) => row.map((cell) => (cell ?? "").replace(/[\n\r\t]/g, " ")));
|
|
9916
|
+
const widths = cells[0].map((_, column) => Math.max(...cells.map((row) => (row[column] ?? "").length)));
|
|
9917
|
+
return cells.map((row) => row.map((cell, column) => (cell ?? "").padEnd(widths[column])).join(" ").trimEnd()).join("\n");
|
|
9548
9918
|
}
|
|
9549
9919
|
var DIMENSIONS = {
|
|
9550
9920
|
day: { title: "DAY", value: (row) => row.day ?? "-" },
|
|
@@ -9592,50 +9962,1417 @@ function unpricedTotal(report) {
|
|
|
9592
9962
|
return report.rows.reduce((total, row) => total + row.unpriced_requests, 0);
|
|
9593
9963
|
}
|
|
9594
9964
|
|
|
9595
|
-
// src/
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
constructor(message) {
|
|
9965
|
+
// src/eval-suite.ts
|
|
9966
|
+
var EvalSuiteError = class extends Error {
|
|
9967
|
+
code;
|
|
9968
|
+
constructor(code, message) {
|
|
9599
9969
|
super(message);
|
|
9600
|
-
this.name = "
|
|
9970
|
+
this.name = "EvalSuiteError";
|
|
9971
|
+
this.code = code;
|
|
9601
9972
|
}
|
|
9602
9973
|
};
|
|
9603
|
-
var
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9974
|
+
var NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
9975
|
+
var SUITE_KEYS = /* @__PURE__ */ new Set([
|
|
9976
|
+
"schema_version",
|
|
9977
|
+
"name",
|
|
9978
|
+
"description",
|
|
9979
|
+
"agent",
|
|
9980
|
+
"environment",
|
|
9981
|
+
"threshold",
|
|
9982
|
+
"runs",
|
|
9983
|
+
"concurrency",
|
|
9984
|
+
"timeout_seconds",
|
|
9985
|
+
"budget_per_case"
|
|
9986
|
+
]);
|
|
9987
|
+
var PROMPT_KEYS = /* @__PURE__ */ new Set(["name", "description", "tags", "timeout_seconds"]);
|
|
9988
|
+
var CASE_KEYS = /* @__PURE__ */ new Set([
|
|
9989
|
+
"messages",
|
|
9990
|
+
"setup_files",
|
|
9991
|
+
"setup_script",
|
|
9992
|
+
"timeout_seconds",
|
|
9993
|
+
"canary",
|
|
9994
|
+
"budget",
|
|
9995
|
+
"tags",
|
|
9996
|
+
"description"
|
|
9997
|
+
]);
|
|
9998
|
+
var GRADER_TYPE_KEYS = {
|
|
9999
|
+
regex: /* @__PURE__ */ new Set(["type", "weight", "flags", "match"]),
|
|
10000
|
+
tool_used: /* @__PURE__ */ new Set(["type", "weight", "tool", "expect"]),
|
|
10001
|
+
file_exists: /* @__PURE__ */ new Set(["type", "weight", "path", "expect"]),
|
|
10002
|
+
script: /* @__PURE__ */ new Set(["type", "weight", "timeout_seconds"])
|
|
10003
|
+
};
|
|
10004
|
+
function loadEvalSuite(dir, cwd, options = {}) {
|
|
10005
|
+
const suiteDir = resolveSuiteDirectory(dir, cwd);
|
|
10006
|
+
const realSuiteDir = realpathSync(suiteDir);
|
|
10007
|
+
const files = [];
|
|
10008
|
+
const read = (path) => {
|
|
10009
|
+
const real = realpathSync(path);
|
|
10010
|
+
const inside = relative(realSuiteDir, real);
|
|
10011
|
+
const escapes = inside === ".." || inside.startsWith(`..${sep}`) || isAbsolute(inside);
|
|
10012
|
+
if (inside.length === 0 || escapes) {
|
|
10013
|
+
throw new EvalSuiteError(
|
|
10014
|
+
"SUITE_INVALID",
|
|
10015
|
+
`${displayPath(cwd, path)}: the file resolves outside ${displayPath(cwd, suiteDir)}; the eval suite only reads files inside its directory.`
|
|
10016
|
+
);
|
|
10017
|
+
}
|
|
10018
|
+
const contents = readFileSync2(real);
|
|
10019
|
+
files.push({ path: relative(suiteDir, path), contents });
|
|
10020
|
+
return contents.toString("utf8");
|
|
10021
|
+
};
|
|
10022
|
+
const manifestPath = join2(suiteDir, "suite.yaml");
|
|
10023
|
+
const manifest = existsSync(manifestPath) ? parseYaml2(read(manifestPath), displayPath(cwd, manifestPath)) : null;
|
|
10024
|
+
const manifestValues = manifest === null ? {} : asMapping(manifest, displayPath(cwd, manifestPath), "suite.yaml");
|
|
10025
|
+
rejectUnknownKeys(manifestValues, SUITE_KEYS, displayPath(cwd, manifestPath));
|
|
10026
|
+
if (manifestValues.schema_version !== void 0 && manifestValues.schema_version !== "1") {
|
|
10027
|
+
throw invalid(manifestPath, cwd, `"schema_version" must be "1".`);
|
|
10028
|
+
}
|
|
10029
|
+
const suite = {
|
|
10030
|
+
dir: suiteDir,
|
|
10031
|
+
displayDir: displayPath(cwd, suiteDir),
|
|
10032
|
+
name: manifestValues.name === void 0 ? basename(suiteDir) : nonEmptyString(manifestValues.name, manifestPath, cwd, "name"),
|
|
10033
|
+
caseCount: 0,
|
|
10034
|
+
cases: [],
|
|
10035
|
+
files
|
|
10036
|
+
};
|
|
10037
|
+
if (manifestValues.description !== void 0) {
|
|
10038
|
+
suite.description = stringValue(manifestValues.description, manifestPath, cwd, "description");
|
|
10039
|
+
}
|
|
10040
|
+
if (manifestValues.agent !== void 0) {
|
|
10041
|
+
suite.agent = nonEmptyString(manifestValues.agent, manifestPath, cwd, "agent");
|
|
10042
|
+
}
|
|
10043
|
+
if (manifestValues.environment !== void 0) {
|
|
10044
|
+
suite.environment = nonEmptyString(manifestValues.environment, manifestPath, cwd, "environment");
|
|
10045
|
+
}
|
|
10046
|
+
if (manifestValues.threshold !== void 0) {
|
|
10047
|
+
suite.threshold = numberInRange(manifestValues.threshold, manifestPath, cwd, "threshold", 0, 1);
|
|
10048
|
+
}
|
|
10049
|
+
if (manifestValues.runs !== void 0) {
|
|
10050
|
+
suite.runs = integerInRange(manifestValues.runs, manifestPath, cwd, "runs", 1, 20);
|
|
10051
|
+
}
|
|
10052
|
+
if (manifestValues.concurrency !== void 0) {
|
|
10053
|
+
suite.concurrency = integerInRange(manifestValues.concurrency, manifestPath, cwd, "concurrency", 1, 32);
|
|
10054
|
+
}
|
|
10055
|
+
if (manifestValues.timeout_seconds !== void 0) {
|
|
10056
|
+
suite.timeoutSeconds = positiveInteger(manifestValues.timeout_seconds, manifestPath, cwd, "timeout_seconds");
|
|
10057
|
+
}
|
|
10058
|
+
if (manifestValues.budget_per_case !== void 0) {
|
|
10059
|
+
suite.budgetPerCase = budgetValue(manifestValues.budget_per_case, manifestPath, cwd, "budget_per_case");
|
|
10060
|
+
}
|
|
10061
|
+
const caseEntries = readdirSync2(suiteDir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && entry.name !== "graders").sort((left, right) => compareNames(left.name, right.name));
|
|
10062
|
+
const cases = [];
|
|
10063
|
+
for (const entry of caseEntries) {
|
|
10064
|
+
const caseDir = join2(suiteDir, entry.name);
|
|
10065
|
+
const hasPrompt = existsSync(join2(caseDir, "prompt.md"));
|
|
10066
|
+
const hasCase = existsSync(join2(caseDir, "case.yaml"));
|
|
10067
|
+
if (!hasPrompt && !hasCase) continue;
|
|
10068
|
+
cases.push(loadCase(caseDir, entry.name, cwd, read));
|
|
10069
|
+
}
|
|
10070
|
+
const seen = /* @__PURE__ */ new Map();
|
|
10071
|
+
for (const entry of cases) {
|
|
10072
|
+
const previous = seen.get(entry.name);
|
|
10073
|
+
if (previous !== void 0) {
|
|
10074
|
+
throw new EvalSuiteError(
|
|
10075
|
+
"SUITE_INVALID",
|
|
10076
|
+
`${entry.dir}: the case name duplicates the one in ${previous}; names must be unique.`
|
|
10077
|
+
);
|
|
10078
|
+
}
|
|
10079
|
+
seen.set(entry.name, entry.dir);
|
|
9617
10080
|
}
|
|
9618
|
-
|
|
10081
|
+
suite.caseCount = cases.length;
|
|
10082
|
+
const selected = cases.filter((entry) => matchesFilters(entry, options));
|
|
10083
|
+
if (selected.length === 0) {
|
|
10084
|
+
if (cases.length === 0) {
|
|
10085
|
+
throw new EvalSuiteError("NO_CASES", `${displayPath(cwd, suiteDir)}: the eval suite has no cases.`);
|
|
10086
|
+
}
|
|
10087
|
+
throw new EvalSuiteError("NO_CASES", `${displayPath(cwd, suiteDir)}: ${describeFilters(options)}.`);
|
|
10088
|
+
}
|
|
10089
|
+
suite.cases = selected;
|
|
10090
|
+
return suite;
|
|
9619
10091
|
}
|
|
9620
|
-
function
|
|
9621
|
-
|
|
9622
|
-
|
|
10092
|
+
function suiteHash(suite) {
|
|
10093
|
+
const digest = createHash("sha256");
|
|
10094
|
+
const files = [...suite.files].sort((left, right) => compareNames(left.path, right.path));
|
|
10095
|
+
for (const file of files) {
|
|
10096
|
+
const fileHash = createHash("sha256").update(file.contents).digest("hex");
|
|
10097
|
+
digest.update(`${file.path}\0${fileHash}
|
|
10098
|
+
`);
|
|
9623
10099
|
}
|
|
9624
|
-
return
|
|
9625
|
-
|
|
9626
|
-
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
|
|
9630
|
-
|
|
10100
|
+
return digest.digest("hex");
|
|
10101
|
+
}
|
|
10102
|
+
function toMessagesCaseInputs(suite) {
|
|
10103
|
+
return suite.cases.map((entry) => {
|
|
10104
|
+
const input = {
|
|
10105
|
+
name: entry.name,
|
|
10106
|
+
messages: entry.messages,
|
|
10107
|
+
reward: {
|
|
10108
|
+
type: "composite",
|
|
10109
|
+
components: entry.graders.map((grader) => ({
|
|
10110
|
+
name: grader.name,
|
|
10111
|
+
weight: grader.weight,
|
|
10112
|
+
verifier: grader.verifier
|
|
10113
|
+
}))
|
|
9631
10114
|
}
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
10115
|
+
};
|
|
10116
|
+
if (entry.setupFiles !== void 0) input.setup_files = entry.setupFiles;
|
|
10117
|
+
if (entry.setupScript !== void 0) input.setup_script = entry.setupScript;
|
|
10118
|
+
const timeoutSeconds = entry.timeoutSeconds ?? suite.timeoutSeconds;
|
|
10119
|
+
if (timeoutSeconds !== void 0) input.timeout_ms = timeoutSeconds * 1e3;
|
|
10120
|
+
if (entry.canary !== void 0) input.canary = entry.canary;
|
|
10121
|
+
const budget = entry.budget ?? suite.budgetPerCase;
|
|
10122
|
+
if (budget !== void 0) input.budget = { max_list_cost: budget };
|
|
10123
|
+
return input;
|
|
10124
|
+
});
|
|
9635
10125
|
}
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
|
|
10126
|
+
function resolveSuiteDirectory(dir, cwd) {
|
|
10127
|
+
const relativeError = `The eval suite path must be relative, without ".." and without an absolute path.`;
|
|
10128
|
+
if (dir.length === 0 || isAbsolute(dir) || /^[A-Za-z]:[\\/]/.test(dir) || dir.split(/[\\/]/).includes("..")) {
|
|
10129
|
+
throw new EvalSuiteError("SUITE_INVALID", relativeError);
|
|
10130
|
+
}
|
|
10131
|
+
const resolved = resolve(cwd, dir);
|
|
10132
|
+
let stats;
|
|
10133
|
+
try {
|
|
10134
|
+
stats = statSync2(resolved);
|
|
10135
|
+
} catch (error) {
|
|
10136
|
+
const code = error.code;
|
|
10137
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
10138
|
+
throw new EvalSuiteError("SUITE_NOT_FOUND", `The eval suite ${dir} does not exist.`);
|
|
10139
|
+
}
|
|
10140
|
+
throw error;
|
|
10141
|
+
}
|
|
10142
|
+
if (!stats.isDirectory()) {
|
|
10143
|
+
throw new EvalSuiteError("SUITE_INVALID", `${dir}: the eval suite path is not a directory.`);
|
|
10144
|
+
}
|
|
10145
|
+
return resolved;
|
|
10146
|
+
}
|
|
10147
|
+
function loadCase(caseDir, entryName, cwd, read) {
|
|
10148
|
+
const dir = displayPath(cwd, caseDir);
|
|
10149
|
+
const promptPath = join2(caseDir, "prompt.md");
|
|
10150
|
+
const casePath = join2(caseDir, "case.yaml");
|
|
10151
|
+
let prompt;
|
|
10152
|
+
if (existsSync(promptPath)) {
|
|
10153
|
+
prompt = parseMarkdown(read(promptPath), displayPath(cwd, promptPath));
|
|
10154
|
+
rejectUnknownKeys(prompt.frontmatter, PROMPT_KEYS, displayPath(cwd, promptPath));
|
|
10155
|
+
}
|
|
10156
|
+
let caseValues = {};
|
|
10157
|
+
if (existsSync(casePath)) {
|
|
10158
|
+
const parsed = parseYaml2(read(casePath), displayPath(cwd, casePath));
|
|
10159
|
+
caseValues = parsed === null ? {} : asMapping(parsed, displayPath(cwd, casePath), "case.yaml");
|
|
10160
|
+
if (caseValues.runs !== void 0) {
|
|
10161
|
+
throw invalid(
|
|
10162
|
+
casePath,
|
|
10163
|
+
cwd,
|
|
10164
|
+
`"runs" is not supported inside a case: the reference allows runs per case, this stage does not (D11).`
|
|
10165
|
+
);
|
|
10166
|
+
}
|
|
10167
|
+
rejectUnknownKeys(caseValues, CASE_KEYS, displayPath(cwd, casePath));
|
|
10168
|
+
}
|
|
10169
|
+
const promptName = prompt?.frontmatter.name;
|
|
10170
|
+
const name = promptName === void 0 ? entryName : nonEmptyString(promptName, promptPath, cwd, "name");
|
|
10171
|
+
if (!NAME_PATTERN.test(name)) {
|
|
10172
|
+
throw invalid(promptName === void 0 ? caseDir : promptPath, cwd, `"name" must match ${NAME_PATTERN}.`);
|
|
10173
|
+
}
|
|
10174
|
+
const body = prompt?.body ?? "";
|
|
10175
|
+
const messagesValue = caseValues.messages;
|
|
10176
|
+
let messages;
|
|
10177
|
+
if (messagesValue !== void 0) {
|
|
10178
|
+
if (body.length > 0) {
|
|
10179
|
+
throw invalid(
|
|
10180
|
+
casePath,
|
|
10181
|
+
cwd,
|
|
10182
|
+
`prompt.md has a body and case.yaml has "messages"; pick one of the two.`
|
|
10183
|
+
);
|
|
10184
|
+
}
|
|
10185
|
+
messages = stringList(messagesValue, casePath, cwd, "messages", { nonEmpty: true });
|
|
10186
|
+
} else if (body.length > 0) {
|
|
10187
|
+
messages = [body];
|
|
10188
|
+
} else {
|
|
10189
|
+
throw invalid(caseDir, cwd, `the case has no messages (a prompt.md body or case.yaml "messages").`);
|
|
10190
|
+
}
|
|
10191
|
+
const graders = loadGraders(caseDir, cwd, read);
|
|
10192
|
+
const entry = { name, dir, messages, graders };
|
|
10193
|
+
const promptFrontmatter = prompt?.frontmatter ?? {};
|
|
10194
|
+
if (promptFrontmatter.description !== void 0) {
|
|
10195
|
+
entry.description = stringValue(
|
|
10196
|
+
promptFrontmatter.description,
|
|
10197
|
+
promptPath,
|
|
10198
|
+
cwd,
|
|
10199
|
+
"description"
|
|
10200
|
+
);
|
|
10201
|
+
}
|
|
10202
|
+
if (caseValues.description !== void 0) {
|
|
10203
|
+
entry.description = stringValue(caseValues.description, casePath, cwd, "description");
|
|
10204
|
+
}
|
|
10205
|
+
const promptTimeout = promptFrontmatter.timeout_seconds;
|
|
10206
|
+
if (promptTimeout !== void 0) {
|
|
10207
|
+
entry.timeoutSeconds = positiveInteger(promptTimeout, promptPath, cwd, "timeout_seconds");
|
|
10208
|
+
}
|
|
10209
|
+
if (caseValues.timeout_seconds !== void 0) {
|
|
10210
|
+
entry.timeoutSeconds = positiveInteger(caseValues.timeout_seconds, casePath, cwd, "timeout_seconds");
|
|
10211
|
+
}
|
|
10212
|
+
if (caseValues.canary !== void 0) {
|
|
10213
|
+
entry.canary = nonEmptyString(caseValues.canary, casePath, cwd, "canary");
|
|
10214
|
+
}
|
|
10215
|
+
if (caseValues.budget !== void 0) {
|
|
10216
|
+
entry.budget = budgetValue(caseValues.budget, casePath, cwd, "budget");
|
|
10217
|
+
}
|
|
10218
|
+
if (caseValues.setup_script !== void 0) {
|
|
10219
|
+
entry.setupScript = stringValue(caseValues.setup_script, casePath, cwd, "setup_script");
|
|
10220
|
+
}
|
|
10221
|
+
if (caseValues.setup_files !== void 0) {
|
|
10222
|
+
entry.setupFiles = setupFiles(caseValues.setup_files, casePath, cwd);
|
|
10223
|
+
}
|
|
10224
|
+
const tags = [
|
|
10225
|
+
...promptFrontmatter.tags === void 0 ? [] : stringList(promptFrontmatter.tags, promptPath, cwd, "tags"),
|
|
10226
|
+
...caseValues.tags === void 0 ? [] : stringList(caseValues.tags, casePath, cwd, "tags")
|
|
10227
|
+
];
|
|
10228
|
+
if (tags.length > 0) entry.tags = [...new Set(tags)];
|
|
10229
|
+
return entry;
|
|
10230
|
+
}
|
|
10231
|
+
function loadGraders(caseDir, cwd, read) {
|
|
10232
|
+
const gradersDir = join2(caseDir, "graders");
|
|
10233
|
+
let entries;
|
|
10234
|
+
try {
|
|
10235
|
+
entries = readdirSync2(gradersDir, { withFileTypes: true });
|
|
10236
|
+
} catch (error) {
|
|
10237
|
+
const code = error.code;
|
|
10238
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
10239
|
+
throw invalid(caseDir, cwd, `the case has no graders; add at least one file in graders/.`);
|
|
10240
|
+
}
|
|
10241
|
+
throw error;
|
|
10242
|
+
}
|
|
10243
|
+
const files = entries.filter(
|
|
10244
|
+
(entry) => (entry.isFile() || entry.isSymbolicLink() && existsSync(join2(gradersDir, entry.name))) && entry.name.endsWith(".md")
|
|
10245
|
+
).sort((left, right) => compareNames(left.name, right.name));
|
|
10246
|
+
if (files.length === 0) {
|
|
10247
|
+
throw invalid(caseDir, cwd, `the case has no graders; add at least one file in graders/.`);
|
|
10248
|
+
}
|
|
10249
|
+
return files.map((entry) => loadGrader(join2(gradersDir, entry.name), cwd, read));
|
|
10250
|
+
}
|
|
10251
|
+
function loadGrader(path, cwd, read) {
|
|
10252
|
+
const shown = displayPath(cwd, path);
|
|
10253
|
+
const name = basename(path).replace(/\.md$/, "");
|
|
10254
|
+
if (!NAME_PATTERN.test(name)) {
|
|
10255
|
+
throw invalid(path, cwd, `"name" must match ${NAME_PATTERN}.`);
|
|
10256
|
+
}
|
|
10257
|
+
const { frontmatter, body } = parseMarkdown(read(path), shown);
|
|
10258
|
+
const type = frontmatter.type;
|
|
10259
|
+
if (type === void 0) {
|
|
10260
|
+
throw invalid(path, cwd, `"type" is required.`);
|
|
10261
|
+
}
|
|
10262
|
+
if (typeof type !== "string" || !Object.hasOwn(GRADER_TYPE_KEYS, type)) {
|
|
10263
|
+
throw invalid(path, cwd, `"type" is not supported in this stage.`);
|
|
10264
|
+
}
|
|
10265
|
+
const graderType = type;
|
|
10266
|
+
rejectUnknownKeys(frontmatter, GRADER_TYPE_KEYS[graderType], shown);
|
|
10267
|
+
const weight = frontmatter.weight === void 0 ? 1 : positiveNumber(frontmatter.weight, path, cwd, "weight");
|
|
10268
|
+
switch (graderType) {
|
|
10269
|
+
case "regex": {
|
|
10270
|
+
const flags = frontmatter.flags === void 0 ? "" : stringValue(frontmatter.flags, path, cwd, "flags");
|
|
10271
|
+
if (!/^[imsu]*$/.test(flags) || new Set(flags).size !== flags.length) {
|
|
10272
|
+
throw invalid(path, cwd, `"flags" only accepts i, m, s and u, without repeats.`);
|
|
10273
|
+
}
|
|
10274
|
+
const match = frontmatter.match === void 0 ? "contains" : frontmatter.match;
|
|
10275
|
+
if (match !== "contains" && match !== "not_contains") {
|
|
10276
|
+
throw invalid(path, cwd, `"match" only accepts contains or not_contains.`);
|
|
10277
|
+
}
|
|
10278
|
+
if (body.length === 0) {
|
|
10279
|
+
throw invalid(path, cwd, `"pattern" is required in the body.`);
|
|
10280
|
+
}
|
|
10281
|
+
const pattern = match === "not_contains" ? `^(?![\\s\\S]*(?:${body}))[\\s\\S]*$` : body;
|
|
10282
|
+
try {
|
|
10283
|
+
new RegExp(pattern, flags);
|
|
10284
|
+
} catch {
|
|
10285
|
+
throw invalid(path, cwd, `"pattern" is not a valid regular expression.`);
|
|
10286
|
+
}
|
|
10287
|
+
return {
|
|
10288
|
+
name,
|
|
10289
|
+
type: graderType,
|
|
10290
|
+
weight,
|
|
10291
|
+
verifier: { type: "verifiable", scorer: "regex", opts: { pattern, flags } }
|
|
10292
|
+
};
|
|
10293
|
+
}
|
|
10294
|
+
case "tool_used": {
|
|
10295
|
+
const tool = nonEmptyString(frontmatter.tool, path, cwd, "tool");
|
|
10296
|
+
const expect = frontmatter.expect === void 0 ? "used" : frontmatter.expect;
|
|
10297
|
+
if (expect !== "used" && expect !== "not_used") {
|
|
10298
|
+
throw invalid(path, cwd, `"expect" only accepts used or not_used.`);
|
|
10299
|
+
}
|
|
10300
|
+
return {
|
|
10301
|
+
name,
|
|
10302
|
+
type: graderType,
|
|
10303
|
+
weight,
|
|
10304
|
+
verifier: {
|
|
10305
|
+
type: "verifiable",
|
|
10306
|
+
scorer: expect === "not_used" ? "toolNotUsed" : "toolUsed",
|
|
10307
|
+
opts: { name: tool }
|
|
10308
|
+
}
|
|
10309
|
+
};
|
|
10310
|
+
}
|
|
10311
|
+
case "file_exists": {
|
|
10312
|
+
const filePath = nonEmptyString(frontmatter.path, path, cwd, "path");
|
|
10313
|
+
if (frontmatter.expect !== void 0 && frontmatter.expect !== "exists") {
|
|
10314
|
+
throw invalid(path, cwd, `"expect" only supports "exists" in this stage.`);
|
|
10315
|
+
}
|
|
10316
|
+
return {
|
|
10317
|
+
name,
|
|
10318
|
+
type: graderType,
|
|
10319
|
+
weight,
|
|
10320
|
+
verifier: { type: "verifiable", scorer: "fileWritten", opts: { filePath } }
|
|
10321
|
+
};
|
|
10322
|
+
}
|
|
10323
|
+
case "script": {
|
|
10324
|
+
if (body.length === 0) {
|
|
10325
|
+
throw invalid(path, cwd, `"verify_script" is required in the body.`);
|
|
10326
|
+
}
|
|
10327
|
+
const verify = { type: "script", verify_script: body };
|
|
10328
|
+
if (frontmatter.timeout_seconds !== void 0) {
|
|
10329
|
+
verify.timeout_ms = positiveInteger(frontmatter.timeout_seconds, path, cwd, "timeout_seconds") * 1e3;
|
|
10330
|
+
}
|
|
10331
|
+
return { name, type: graderType, weight, verifier: verify };
|
|
10332
|
+
}
|
|
10333
|
+
}
|
|
10334
|
+
}
|
|
10335
|
+
function setupFiles(value, path, cwd) {
|
|
10336
|
+
if (!Array.isArray(value)) {
|
|
10337
|
+
throw invalid(path, cwd, `"setup_files" must be a list.`);
|
|
10338
|
+
}
|
|
10339
|
+
return value.map((entry, index) => {
|
|
10340
|
+
const mapping = asMapping(entry, displayPath(cwd, path), `setup_files[${index}]`);
|
|
10341
|
+
for (const key of Object.keys(mapping)) {
|
|
10342
|
+
if (key !== "path" && key !== "content") {
|
|
10343
|
+
throw invalid(path, cwd, `"setup_files[${index}]" has an unknown key "${key}".`);
|
|
10344
|
+
}
|
|
10345
|
+
}
|
|
10346
|
+
const filePath = nonEmptyString(mapping.path, path, cwd, `setup_files[${index}].path`);
|
|
10347
|
+
if (!isAbsolute(filePath)) {
|
|
10348
|
+
throw invalid(path, cwd, `"setup_files[${index}].path" must be absolute.`);
|
|
10349
|
+
}
|
|
10350
|
+
if (typeof mapping.content !== "string") {
|
|
10351
|
+
throw invalid(path, cwd, `"setup_files[${index}].content" must be a string.`);
|
|
10352
|
+
}
|
|
10353
|
+
return { path: filePath, content: mapping.content };
|
|
10354
|
+
});
|
|
10355
|
+
}
|
|
10356
|
+
function matchesFilters(entry, options) {
|
|
10357
|
+
const globs = options.caseGlobs ?? [];
|
|
10358
|
+
if (globs.length > 0 && !globs.some((glob) => globToRegExp(glob).test(entry.name))) return false;
|
|
10359
|
+
const tags = options.tags ?? [];
|
|
10360
|
+
if (tags.length > 0 && !(entry.tags ?? []).some((tag) => tags.includes(tag))) return false;
|
|
10361
|
+
return true;
|
|
10362
|
+
}
|
|
10363
|
+
function describeFilters(options) {
|
|
10364
|
+
const parts = [];
|
|
10365
|
+
if ((options.caseGlobs ?? []).length > 0) {
|
|
10366
|
+
parts.push(`--case ${options.caseGlobs.map((glob) => JSON.stringify(glob)).join(", ")}`);
|
|
10367
|
+
}
|
|
10368
|
+
if ((options.tags ?? []).length > 0) {
|
|
10369
|
+
parts.push(`--tag ${options.tags.map((tag) => JSON.stringify(tag)).join(", ")}`);
|
|
10370
|
+
}
|
|
10371
|
+
return `no case matches ${parts.join(" and ")}`;
|
|
10372
|
+
}
|
|
10373
|
+
function globToRegExp(glob) {
|
|
10374
|
+
const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
|
|
10375
|
+
return new RegExp(`^${escaped}$`);
|
|
10376
|
+
}
|
|
10377
|
+
function parseMarkdown(contents, path) {
|
|
10378
|
+
const text = contents.replace(/^\uFEFF/, "");
|
|
10379
|
+
const lines = text.split(/\r?\n/);
|
|
10380
|
+
if ((lines[0] ?? "").trimEnd() !== "---") {
|
|
10381
|
+
return { frontmatter: {}, body: normalizeBody(text) };
|
|
10382
|
+
}
|
|
10383
|
+
const end = lines.findIndex((line, index) => index > 0 && line.trimEnd() === "---");
|
|
10384
|
+
if (end === -1) {
|
|
10385
|
+
throw new EvalSuiteError("SUITE_INVALID", `${path}: unterminated YAML frontmatter.`);
|
|
10386
|
+
}
|
|
10387
|
+
const parsed = parseYaml2(lines.slice(1, end).join("\n"), path, 1);
|
|
10388
|
+
const frontmatter = parsed === null ? {} : asMapping(parsed, path, "frontmatter");
|
|
10389
|
+
return { frontmatter, body: normalizeBody(lines.slice(end + 1).join("\n")) };
|
|
10390
|
+
}
|
|
10391
|
+
function normalizeBody(body) {
|
|
10392
|
+
return body.replace(/^\r?\n/, "").trimEnd();
|
|
10393
|
+
}
|
|
10394
|
+
function parseYaml2(contents, path, lineOffset = 0) {
|
|
10395
|
+
try {
|
|
10396
|
+
return (0, import_yaml3.parse)(contents);
|
|
10397
|
+
} catch (error) {
|
|
10398
|
+
if (error instanceof import_yaml3.YAMLParseError) {
|
|
10399
|
+
const position = error.linePos?.[0];
|
|
10400
|
+
const at = position === void 0 ? "" : `:${position.line + lineOffset}:${position.col}`;
|
|
10401
|
+
throw new EvalSuiteError("SUITE_INVALID", `${path}${at}: ${error.code} (YAML parse error).`);
|
|
10402
|
+
}
|
|
10403
|
+
throw error;
|
|
10404
|
+
}
|
|
10405
|
+
}
|
|
10406
|
+
function asMapping(value, path, key) {
|
|
10407
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
10408
|
+
throw new EvalSuiteError("SUITE_INVALID", `${path}: "${key}" must be a mapping.`);
|
|
10409
|
+
}
|
|
10410
|
+
return value;
|
|
10411
|
+
}
|
|
10412
|
+
function rejectUnknownKeys(values, allowed, path) {
|
|
10413
|
+
for (const key of Object.keys(values)) {
|
|
10414
|
+
if (!allowed.has(key)) {
|
|
10415
|
+
throw new EvalSuiteError("SUITE_INVALID", `${path}: unknown key "${key}".`);
|
|
10416
|
+
}
|
|
10417
|
+
}
|
|
10418
|
+
}
|
|
10419
|
+
function nonEmptyString(value, path, cwd, key) {
|
|
10420
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
10421
|
+
throw invalid(path, cwd, `"${key}" must be a non-empty string.`);
|
|
10422
|
+
}
|
|
10423
|
+
return value;
|
|
10424
|
+
}
|
|
10425
|
+
function stringValue(value, path, cwd, key) {
|
|
10426
|
+
if (typeof value !== "string") {
|
|
10427
|
+
throw invalid(path, cwd, `"${key}" must be a string.`);
|
|
10428
|
+
}
|
|
10429
|
+
return value;
|
|
10430
|
+
}
|
|
10431
|
+
function stringList(value, path, cwd, key, options = {}) {
|
|
10432
|
+
if (!Array.isArray(value) || options.nonEmpty === true && value.length === 0) {
|
|
10433
|
+
throw invalid(path, cwd, `"${key}" must be a non-empty list of strings.`);
|
|
10434
|
+
}
|
|
10435
|
+
const result = [];
|
|
10436
|
+
for (const entry of value) {
|
|
10437
|
+
if (typeof entry !== "string" || entry.length === 0) {
|
|
10438
|
+
throw invalid(path, cwd, `"${key}" must be a list of non-empty strings.`);
|
|
10439
|
+
}
|
|
10440
|
+
result.push(entry);
|
|
10441
|
+
}
|
|
10442
|
+
return result;
|
|
10443
|
+
}
|
|
10444
|
+
function positiveInteger(value, path, cwd, key) {
|
|
10445
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
10446
|
+
throw invalid(path, cwd, `"${key}" must be a positive integer.`);
|
|
10447
|
+
}
|
|
10448
|
+
return value;
|
|
10449
|
+
}
|
|
10450
|
+
function integerInRange(value, path, cwd, key, min, max) {
|
|
10451
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < min || value > max) {
|
|
10452
|
+
throw invalid(path, cwd, `"${key}" must be an integer between ${min} and ${max}.`);
|
|
10453
|
+
}
|
|
10454
|
+
return value;
|
|
10455
|
+
}
|
|
10456
|
+
function positiveNumber(value, path, cwd, key) {
|
|
10457
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
10458
|
+
throw invalid(path, cwd, `"${key}" must be a positive number.`);
|
|
10459
|
+
}
|
|
10460
|
+
return value;
|
|
10461
|
+
}
|
|
10462
|
+
function numberInRange(value, path, cwd, key, min, max) {
|
|
10463
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max) {
|
|
10464
|
+
throw invalid(path, cwd, `"${key}" must be a number between ${min} and ${max}.`);
|
|
10465
|
+
}
|
|
10466
|
+
return value;
|
|
10467
|
+
}
|
|
10468
|
+
function budgetValue(value, path, cwd, key) {
|
|
10469
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) return String(value);
|
|
10470
|
+
if (typeof value === "string" && /^\d+$/.test(value)) return value;
|
|
10471
|
+
throw invalid(path, cwd, `"${key}" must be cents as a non-negative integer or a string of digits.`);
|
|
10472
|
+
}
|
|
10473
|
+
function invalid(path, cwd, detail) {
|
|
10474
|
+
return new EvalSuiteError("SUITE_INVALID", `${displayPath(cwd, path)}: ${detail}`);
|
|
10475
|
+
}
|
|
10476
|
+
function displayPath(cwd, path) {
|
|
10477
|
+
const shown = relative(cwd, path);
|
|
10478
|
+
return shown.length > 0 ? shown.split(sep).join("/") : ".";
|
|
10479
|
+
}
|
|
10480
|
+
function compareNames(left, right) {
|
|
10481
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
10482
|
+
}
|
|
10483
|
+
function scoreCell(value) {
|
|
10484
|
+
return value === null ? "\u2014" : value.toFixed(2);
|
|
10485
|
+
}
|
|
10486
|
+
function graderCell(value) {
|
|
10487
|
+
return Number.isInteger(value) ? String(value) : value.toFixed(2);
|
|
10488
|
+
}
|
|
10489
|
+
function lowestGrader(entry) {
|
|
10490
|
+
return entry.graders.filter((grader) => grader.value !== null).sort((left, right) => (left.value ?? 0) - (right.value ?? 0))[0];
|
|
10491
|
+
}
|
|
10492
|
+
function resultCell(entry) {
|
|
10493
|
+
if (entry.error !== null) return `ERROR (${entry.error})`;
|
|
10494
|
+
if (entry.passed) return "ok";
|
|
10495
|
+
const lowest = lowestGrader(entry);
|
|
10496
|
+
return lowest === void 0 ? "FAIL" : `FAIL (${lowest.name}=${graderCell(lowest.value ?? 0)})`;
|
|
10497
|
+
}
|
|
10498
|
+
function summaryLine(report) {
|
|
10499
|
+
const cases = report.cases.length;
|
|
10500
|
+
const below = report.cases.filter((entry) => entry.error === null && !entry.passed).length;
|
|
10501
|
+
const errored = report.cases.filter((entry) => entry.error !== null).length;
|
|
10502
|
+
const mean = scoreCell(report.aggregates.overallScore);
|
|
10503
|
+
const errors = `${errored} error${errored === 1 ? "" : "s"}`;
|
|
10504
|
+
return `${cases} cases: ${report.aggregates.casesPassed} passed, ${below} below ${report.threshold.toFixed(2)}, ${errors} \xB7 mean ${mean} \xB7 ${report.durationSeconds}s`;
|
|
10505
|
+
}
|
|
10506
|
+
function formatEvalReport(report) {
|
|
10507
|
+
const rows = [["CASE", "SCORE", "RUNS", "RESULT"]];
|
|
10508
|
+
for (const entry of report.cases) {
|
|
10509
|
+
rows.push([entry.name, scoreCell(entry.score), String(entry.runs), resultCell(entry)]);
|
|
10510
|
+
}
|
|
10511
|
+
return `${table(rows)}
|
|
10512
|
+
${summaryLine(report)}`;
|
|
10513
|
+
}
|
|
10514
|
+
function evalReportDocument(report) {
|
|
10515
|
+
return {
|
|
10516
|
+
schemaVersion: 1,
|
|
10517
|
+
suite: {
|
|
10518
|
+
name: report.suite.name,
|
|
10519
|
+
dir: report.suite.dir,
|
|
10520
|
+
hash: `sha256:${report.suite.hash}`,
|
|
10521
|
+
caseCount: report.suite.caseCount,
|
|
10522
|
+
selectedCount: report.suite.selectedCount
|
|
10523
|
+
},
|
|
10524
|
+
agent: report.agent,
|
|
10525
|
+
environment: report.environment,
|
|
10526
|
+
run: {
|
|
10527
|
+
id: report.run.id,
|
|
10528
|
+
benchmarkId: report.run.benchmarkId,
|
|
10529
|
+
concurrency: report.run.concurrency,
|
|
10530
|
+
runsPerCase: report.run.runsPerCase
|
|
10531
|
+
},
|
|
10532
|
+
threshold: report.threshold,
|
|
10533
|
+
startedAt: report.startedAt,
|
|
10534
|
+
durationSeconds: report.durationSeconds,
|
|
10535
|
+
partial: report.partial,
|
|
10536
|
+
aggregates: report.aggregates,
|
|
10537
|
+
cases: report.cases.map((entry) => ({
|
|
10538
|
+
name: entry.name,
|
|
10539
|
+
tags: entry.tags,
|
|
10540
|
+
score: entry.score,
|
|
10541
|
+
runs: entry.runs,
|
|
10542
|
+
passed: entry.passed,
|
|
10543
|
+
error: entry.error,
|
|
10544
|
+
graders: entry.graders
|
|
10545
|
+
}))
|
|
10546
|
+
};
|
|
10547
|
+
}
|
|
10548
|
+
|
|
10549
|
+
// src/eval.ts
|
|
10550
|
+
var EvalRunError = class extends Error {
|
|
10551
|
+
code;
|
|
10552
|
+
constructor(code, message) {
|
|
10553
|
+
super(message);
|
|
10554
|
+
this.name = "EvalRunError";
|
|
10555
|
+
this.code = code;
|
|
10556
|
+
}
|
|
10557
|
+
};
|
|
10558
|
+
var EvalInterruptedError = class extends Error {
|
|
10559
|
+
constructor() {
|
|
10560
|
+
super("interrupted; the run keeps running on the platform");
|
|
10561
|
+
this.name = "EvalInterruptedError";
|
|
10562
|
+
}
|
|
10563
|
+
};
|
|
10564
|
+
var DEFAULT_RUNS = 3;
|
|
10565
|
+
var DEFAULT_CONCURRENCY = 4;
|
|
10566
|
+
var DEFAULT_THRESHOLD = 1;
|
|
10567
|
+
var DEFAULT_WAIT_TIMEOUT_SECONDS = 3600;
|
|
10568
|
+
var POLL_INTERVAL_MS = 2e3;
|
|
10569
|
+
async function readAgentVersion(client, agentId) {
|
|
10570
|
+
const agent = await client.beta.agents.retrieve(agentId);
|
|
10571
|
+
const version = agent.version;
|
|
10572
|
+
if (typeof version !== "number" || !Number.isInteger(version)) {
|
|
10573
|
+
throw new EvalRunError(
|
|
10574
|
+
"API_ERROR",
|
|
10575
|
+
`The server did not report an integer version for agent ${agentId}.`
|
|
10576
|
+
);
|
|
10577
|
+
}
|
|
10578
|
+
const model = agent.model;
|
|
10579
|
+
return {
|
|
10580
|
+
id: agent.id,
|
|
10581
|
+
version,
|
|
10582
|
+
model: typeof model === "string" ? model : model?.id ?? ""
|
|
10583
|
+
};
|
|
10584
|
+
}
|
|
10585
|
+
async function runSuite(client, suite, options, deps = {}) {
|
|
10586
|
+
const runs = options.runs ?? DEFAULT_RUNS;
|
|
10587
|
+
const concurrency = options.concurrency ?? DEFAULT_CONCURRENCY;
|
|
10588
|
+
const threshold = options.threshold ?? DEFAULT_THRESHOLD;
|
|
10589
|
+
const waitTimeoutSeconds = options.waitTimeoutSeconds ?? DEFAULT_WAIT_TIMEOUT_SECONDS;
|
|
10590
|
+
if (!Number.isInteger(runs) || runs < 1 || runs > 20) {
|
|
10591
|
+
throw new RangeError("runs must be an integer between 1 and 20.");
|
|
10592
|
+
}
|
|
10593
|
+
if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 32) {
|
|
10594
|
+
throw new RangeError("concurrency must be an integer between 1 and 32.");
|
|
10595
|
+
}
|
|
10596
|
+
if (!Number.isFinite(threshold) || threshold < 0 || threshold > 1) {
|
|
10597
|
+
throw new RangeError("threshold must be a number between 0 and 1.");
|
|
10598
|
+
}
|
|
10599
|
+
if (!Number.isFinite(waitTimeoutSeconds) || waitTimeoutSeconds <= 0) {
|
|
10600
|
+
throw new RangeError("waitTimeoutSeconds must be a positive number.");
|
|
10601
|
+
}
|
|
10602
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
10603
|
+
const startedMs = Date.now();
|
|
10604
|
+
let before;
|
|
10605
|
+
try {
|
|
10606
|
+
before = await readAgentVersion(client, options.agentId);
|
|
10607
|
+
} catch (error) {
|
|
10608
|
+
if (error instanceof EvalRunError) throw error;
|
|
10609
|
+
throw new EvalRunError(
|
|
10610
|
+
"AGENT_NOT_FOUND",
|
|
10611
|
+
`Could not read agent ${options.agentId}: ${describeApiFailure(error)}`
|
|
10612
|
+
);
|
|
10613
|
+
}
|
|
10614
|
+
if (options.expectedAgentVersion !== void 0 && before.version !== options.expectedAgentVersion) {
|
|
10615
|
+
throw new EvalRunError(
|
|
10616
|
+
"AGENT_VERSION_CHANGED",
|
|
10617
|
+
`Agent ${options.agentId} is at version ${before.version}, expected ${options.expectedAgentVersion}; nothing was run.`
|
|
10618
|
+
);
|
|
10619
|
+
}
|
|
10620
|
+
deps.onPlanned?.({
|
|
10621
|
+
agent: before,
|
|
10622
|
+
cases: suite.cases.length,
|
|
10623
|
+
runs,
|
|
10624
|
+
concurrency,
|
|
10625
|
+
threshold
|
|
10626
|
+
});
|
|
10627
|
+
let benchmarkId;
|
|
10628
|
+
let runId;
|
|
10629
|
+
try {
|
|
10630
|
+
try {
|
|
10631
|
+
benchmarkId = (await client.platform.evals.benchmarks.create({
|
|
10632
|
+
kind: "messages",
|
|
10633
|
+
name: benchmarkName(suite),
|
|
10634
|
+
cases: toMessagesCaseInputs(suite)
|
|
10635
|
+
})).id;
|
|
10636
|
+
} catch (error) {
|
|
10637
|
+
throw new EvalRunError(
|
|
10638
|
+
"RUN_START_FAILED",
|
|
10639
|
+
`Could not create the eval benchmark: ${describeApiFailure(error)}`
|
|
10640
|
+
);
|
|
10641
|
+
}
|
|
10642
|
+
let created;
|
|
10643
|
+
try {
|
|
10644
|
+
created = await client.platform.evals.runs.create({
|
|
10645
|
+
benchmark_id: benchmarkId,
|
|
10646
|
+
agent_id: options.agentId,
|
|
10647
|
+
environment_id: options.environmentId,
|
|
10648
|
+
trials: runs,
|
|
10649
|
+
concurrency
|
|
10650
|
+
});
|
|
10651
|
+
} catch (error) {
|
|
10652
|
+
throw new EvalRunError(
|
|
10653
|
+
"RUN_START_FAILED",
|
|
10654
|
+
`Could not start the eval run: ${describeApiFailure(error)}`
|
|
10655
|
+
);
|
|
10656
|
+
}
|
|
10657
|
+
runId = created.run_id;
|
|
10658
|
+
deps.onRunCreated?.({ id: created.run_id, taskCount: created.task_count });
|
|
10659
|
+
let terminal;
|
|
10660
|
+
try {
|
|
10661
|
+
terminal = await client.platform.evals.runs.waitForRun(created.run_id, {
|
|
10662
|
+
intervalMs: POLL_INTERVAL_MS,
|
|
10663
|
+
timeoutMs: waitTimeoutSeconds * 1e3,
|
|
10664
|
+
...options.signal === void 0 ? {} : { signal: options.signal }
|
|
10665
|
+
});
|
|
10666
|
+
} catch (error) {
|
|
10667
|
+
if (options.signal?.aborted === true) throw error;
|
|
10668
|
+
if (error instanceof Error && error.message.startsWith("Timed out after ")) {
|
|
10669
|
+
throw new EvalRunError(
|
|
10670
|
+
"RUN_TIMEOUT",
|
|
10671
|
+
`The eval run ${created.run_id} did not finish within ${waitTimeoutSeconds} seconds.`
|
|
10672
|
+
);
|
|
10673
|
+
}
|
|
10674
|
+
throw new EvalRunError(
|
|
10675
|
+
"RUN_FAILED",
|
|
10676
|
+
`Could not wait for eval run ${created.run_id}: ${describeApiFailure(error)}`
|
|
10677
|
+
);
|
|
10678
|
+
}
|
|
10679
|
+
const after = await readAgentVersion(client, options.agentId);
|
|
10680
|
+
const versionChanged = after.version !== before.version;
|
|
10681
|
+
const cases = suite.cases.map(
|
|
10682
|
+
(entry) => scoreCase(entry, terminal.tasks.find((task) => task.id === entry.name), threshold)
|
|
10683
|
+
);
|
|
10684
|
+
if (versionChanged) {
|
|
10685
|
+
for (const entry of cases) {
|
|
10686
|
+
entry.score = null;
|
|
10687
|
+
entry.passed = false;
|
|
10688
|
+
entry.error = `the agent version changed during the run (${before.version} -> ${after.version}); the report is not comparable`;
|
|
10689
|
+
}
|
|
10690
|
+
}
|
|
10691
|
+
const scored = cases.filter((entry) => entry.score !== null);
|
|
10692
|
+
const overallScore = scored.length === 0 ? null : scored.reduce((total, entry) => total + (entry.score ?? 0), 0) / scored.length;
|
|
10693
|
+
const passed = terminal.status === "completed" && !versionChanged && cases.length > 0 && cases.every((entry) => entry.passed && entry.error === null);
|
|
10694
|
+
return {
|
|
10695
|
+
suite: {
|
|
10696
|
+
name: suite.name,
|
|
10697
|
+
dir: suite.displayDir,
|
|
10698
|
+
hash: suiteHash(suite),
|
|
10699
|
+
caseCount: suite.caseCount,
|
|
10700
|
+
selectedCount: suite.cases.length
|
|
10701
|
+
},
|
|
10702
|
+
agent: before,
|
|
10703
|
+
environment: { id: options.environmentId },
|
|
10704
|
+
run: {
|
|
10705
|
+
id: created.run_id,
|
|
10706
|
+
benchmarkId,
|
|
10707
|
+
concurrency,
|
|
10708
|
+
runsPerCase: runs,
|
|
10709
|
+
status: terminal.status
|
|
10710
|
+
},
|
|
10711
|
+
threshold,
|
|
10712
|
+
startedAt,
|
|
10713
|
+
durationSeconds: Math.round((Date.now() - startedMs) / 1e3),
|
|
10714
|
+
partial: false,
|
|
10715
|
+
passed,
|
|
10716
|
+
aggregates: {
|
|
10717
|
+
overallScore,
|
|
10718
|
+
casesPassed: cases.filter((entry) => entry.passed).length,
|
|
10719
|
+
casesTotal: cases.length,
|
|
10720
|
+
casesErrored: cases.filter((entry) => entry.error !== null).length
|
|
10721
|
+
},
|
|
10722
|
+
cases,
|
|
10723
|
+
...versionChanged ? { agentVersionChanged: { before: before.version, after: after.version } } : {}
|
|
10724
|
+
};
|
|
10725
|
+
} finally {
|
|
10726
|
+
if (options.keep !== true && benchmarkId !== void 0) {
|
|
10727
|
+
await deleteEphemeral(
|
|
10728
|
+
client,
|
|
10729
|
+
{ runId, benchmarkId },
|
|
10730
|
+
deps.writeStderr ?? ((message) => process.stderr.write(`${message}
|
|
10731
|
+
`))
|
|
10732
|
+
);
|
|
10733
|
+
}
|
|
10734
|
+
}
|
|
10735
|
+
}
|
|
10736
|
+
var SERVER_ERROR_LIMIT = 200;
|
|
10737
|
+
function serverError(text) {
|
|
10738
|
+
const safe = printable(text);
|
|
10739
|
+
return safe.length > SERVER_ERROR_LIMIT ? `${safe.slice(0, SERVER_ERROR_LIMIT)}\u2026` : safe;
|
|
10740
|
+
}
|
|
10741
|
+
function scoreCase(entry, task, threshold) {
|
|
10742
|
+
const graders = graderValues(entry, task);
|
|
10743
|
+
const base = { name: entry.name, tags: entry.tags ?? [], graders };
|
|
10744
|
+
if (task === void 0) {
|
|
10745
|
+
return {
|
|
10746
|
+
...base,
|
|
10747
|
+
score: null,
|
|
10748
|
+
runs: 0,
|
|
10749
|
+
passed: false,
|
|
10750
|
+
error: "the run did not report this case"
|
|
10751
|
+
};
|
|
10752
|
+
}
|
|
10753
|
+
let error = null;
|
|
10754
|
+
if (task.status !== "completed") {
|
|
10755
|
+
error = task.error === void 0 || task.error === null ? `the task ended ${task.status}` : serverError(task.error);
|
|
10756
|
+
} else {
|
|
10757
|
+
const trialError = task.trials.find(
|
|
10758
|
+
(trial) => typeof trial.error === "string" && trial.error.length > 0
|
|
10759
|
+
);
|
|
10760
|
+
if (trialError?.error !== void 0) {
|
|
10761
|
+
error = serverError(trialError.error);
|
|
10762
|
+
} else if (task.trials.length === 0) {
|
|
10763
|
+
error = "the task has no trials";
|
|
10764
|
+
} else if (task.trials.some((trial) => trial.status !== "completed" || typeof trial.reward !== "number")) {
|
|
10765
|
+
error = "a trial did not finish completed with a reward";
|
|
10766
|
+
} else if (typeof task.mean_reward !== "number") {
|
|
10767
|
+
error = "the task has no mean_reward";
|
|
10768
|
+
}
|
|
10769
|
+
}
|
|
10770
|
+
const score = error === null ? task.mean_reward ?? null : null;
|
|
10771
|
+
const runs = task.trials.length > 0 ? task.trials.length : task.trial_total;
|
|
10772
|
+
return {
|
|
10773
|
+
...base,
|
|
10774
|
+
score,
|
|
10775
|
+
runs,
|
|
10776
|
+
passed: error === null && score !== null && score >= threshold,
|
|
10777
|
+
error
|
|
10778
|
+
};
|
|
10779
|
+
}
|
|
10780
|
+
function graderValues(entry, task) {
|
|
10781
|
+
const completed = task?.trials.filter((trial) => trial.status === "completed") ?? [];
|
|
10782
|
+
return entry.graders.map((grader) => {
|
|
10783
|
+
const values = completed.map((trial) => trial.rewards?.[grader.name]).filter((value) => typeof value === "number");
|
|
10784
|
+
return {
|
|
10785
|
+
name: grader.name,
|
|
10786
|
+
type: grader.type,
|
|
10787
|
+
weight: grader.weight,
|
|
10788
|
+
value: values.length === 0 ? null : values.reduce((total, value) => total + value, 0) / values.length
|
|
10789
|
+
};
|
|
10790
|
+
});
|
|
10791
|
+
}
|
|
10792
|
+
async function deleteEphemeral(client, ids, writeStderr) {
|
|
10793
|
+
const problems = [];
|
|
10794
|
+
if (ids.runId !== void 0) {
|
|
10795
|
+
try {
|
|
10796
|
+
await client.platform.evals.runs.delete(ids.runId);
|
|
10797
|
+
} catch (error) {
|
|
10798
|
+
problems.push(`the run ${ids.runId}: ${describeApiFailure(error)}`);
|
|
10799
|
+
}
|
|
10800
|
+
}
|
|
10801
|
+
try {
|
|
10802
|
+
await client.platform.evals.benchmarks.delete(ids.benchmarkId);
|
|
10803
|
+
} catch (error) {
|
|
10804
|
+
problems.push(`the benchmark ${ids.benchmarkId}: ${describeApiFailure(error)}`);
|
|
10805
|
+
}
|
|
10806
|
+
if (problems.length > 0) {
|
|
10807
|
+
writeStderr(
|
|
10808
|
+
`warning: could not delete the ephemeral eval resources (run ${ids.runId ?? "-"}, benchmark ${ids.benchmarkId}): ${problems.join("; ")}; the result is unchanged.`
|
|
10809
|
+
);
|
|
10810
|
+
}
|
|
10811
|
+
}
|
|
10812
|
+
function benchmarkName(suite) {
|
|
10813
|
+
const slug = suite.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64);
|
|
10814
|
+
return `${slug.length > 0 ? slug : "eval"}-${Date.now()}-${randomBytes(4).toString("hex")}`;
|
|
10815
|
+
}
|
|
10816
|
+
var USAGE = "Usage: nouter-platform eval [<dir>] [options]";
|
|
10817
|
+
async function evalCommand(argv, deps) {
|
|
10818
|
+
const usage = (message, code) => new deps.CliError(`${USAGE}
|
|
10819
|
+
${message}`, 64, code);
|
|
10820
|
+
const spec = specFor("eval");
|
|
10821
|
+
const values = /* @__PURE__ */ new Map();
|
|
10822
|
+
const booleans = /* @__PURE__ */ new Set();
|
|
10823
|
+
const positionals = [];
|
|
10824
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
10825
|
+
const argument = argv[index];
|
|
10826
|
+
if (!argument.startsWith("--")) {
|
|
10827
|
+
positionals.push(argument);
|
|
10828
|
+
continue;
|
|
10829
|
+
}
|
|
10830
|
+
const equals = argument.indexOf("=");
|
|
10831
|
+
const name = equals === -1 ? argument : argument.slice(0, equals);
|
|
10832
|
+
const inline = equals === -1 ? void 0 : argument.slice(equals + 1);
|
|
10833
|
+
if (spec.booleans.includes(name)) {
|
|
10834
|
+
if (inline !== void 0) throw usage(`The option ${name} takes no value.`);
|
|
10835
|
+
booleans.add(name);
|
|
10836
|
+
continue;
|
|
10837
|
+
}
|
|
10838
|
+
if (!spec.values.includes(name)) throw usage(`Unknown option: ${name}.`);
|
|
10839
|
+
const value = inline ?? argv[index + 1];
|
|
10840
|
+
if (value === void 0) throw usage(`The option ${name} needs a value.`);
|
|
10841
|
+
if (inline === void 0) index += 1;
|
|
10842
|
+
const list = values.get(name) ?? [];
|
|
10843
|
+
list.push(value);
|
|
10844
|
+
values.set(name, list);
|
|
10845
|
+
}
|
|
10846
|
+
if (positionals.length > 1) throw usage("At most one suite directory is accepted.");
|
|
10847
|
+
const dir = positionals[0] ?? "evals";
|
|
10848
|
+
if (dir.length === 0 || isAbsolute2(dir) || dir.split(/[\\/]/).includes("..")) {
|
|
10849
|
+
throw usage("The suite directory must be relative and must not contain `..`.");
|
|
10850
|
+
}
|
|
10851
|
+
const last = (name) => values.get(name)?.at(-1);
|
|
10852
|
+
const numberValue = (name, min, max, integer) => {
|
|
10853
|
+
const raw = last(name);
|
|
10854
|
+
if (raw === void 0) return void 0;
|
|
10855
|
+
if (integer ? !/^\d+$/.test(raw) : !/^\d+(?:\.\d+)?$/.test(raw)) {
|
|
10856
|
+
throw usage(`The option ${name} must be ${integer ? "an integer" : "a number"}.`);
|
|
10857
|
+
}
|
|
10858
|
+
const value = Number(raw);
|
|
10859
|
+
if (!(value >= min && value <= max)) {
|
|
10860
|
+
throw usage(`The option ${name} must be between ${min} and ${max}.`);
|
|
10861
|
+
}
|
|
10862
|
+
return value;
|
|
10863
|
+
};
|
|
10864
|
+
const agent = last("--agent");
|
|
10865
|
+
const environment = last("--environment");
|
|
10866
|
+
if (agent !== void 0 && agent.length === 0) throw usage("The option --agent needs a value.");
|
|
10867
|
+
if (environment !== void 0 && environment.length === 0) {
|
|
10868
|
+
throw usage("The option --environment needs a value.");
|
|
10869
|
+
}
|
|
10870
|
+
const flags = {
|
|
10871
|
+
dir,
|
|
10872
|
+
caseGlobs: values.get("--case") ?? [],
|
|
10873
|
+
tags: values.get("--tag") ?? [],
|
|
10874
|
+
json: booleans.has("--json"),
|
|
10875
|
+
keep: booleans.has("--keep")
|
|
10876
|
+
};
|
|
10877
|
+
if (agent !== void 0) flags.agent = agent;
|
|
10878
|
+
if (environment !== void 0) flags.environment = environment;
|
|
10879
|
+
const threshold = numberValue("--threshold", 0, 1, false);
|
|
10880
|
+
const runs = numberValue("--runs", 1, 20, true);
|
|
10881
|
+
const concurrency = numberValue("--concurrency", 1, 32, true);
|
|
10882
|
+
const agentVersion = numberValue("--agent-version", 1, 1e9, true);
|
|
10883
|
+
const waitTimeout = numberValue("--wait-timeout", 1, 1e9, true);
|
|
10884
|
+
if (threshold !== void 0) flags.threshold = threshold;
|
|
10885
|
+
if (runs !== void 0) flags.runs = runs;
|
|
10886
|
+
if (concurrency !== void 0) flags.concurrency = concurrency;
|
|
10887
|
+
if (agentVersion !== void 0) flags.agentVersion = agentVersion;
|
|
10888
|
+
if (waitTimeout !== void 0) flags.waitTimeout = waitTimeout;
|
|
10889
|
+
let suite;
|
|
10890
|
+
try {
|
|
10891
|
+
suite = loadEvalSuite(dir, process.cwd(), {
|
|
10892
|
+
caseGlobs: flags.caseGlobs,
|
|
10893
|
+
tags: flags.tags
|
|
10894
|
+
});
|
|
10895
|
+
} catch (error) {
|
|
10896
|
+
if (error instanceof EvalSuiteError) throw new deps.CliError(error.message, 1, error.code);
|
|
10897
|
+
throw error;
|
|
10898
|
+
}
|
|
10899
|
+
const agentId = flags.agent ?? suite.agent;
|
|
10900
|
+
if (agentId === void 0 || agentId.length === 0) {
|
|
10901
|
+
throw usage(
|
|
10902
|
+
"The agent is required: pass --agent or set `agent` in suite.yaml.",
|
|
10903
|
+
"AGENT_REQUIRED"
|
|
10904
|
+
);
|
|
10905
|
+
}
|
|
10906
|
+
const environmentId = flags.environment ?? suite.environment;
|
|
10907
|
+
if (environmentId === void 0 || environmentId.length === 0) {
|
|
10908
|
+
throw usage(
|
|
10909
|
+
"The environment is required: pass --environment or set `environment` in suite.yaml.",
|
|
10910
|
+
"ENVIRONMENT_REQUIRED"
|
|
10911
|
+
);
|
|
10912
|
+
}
|
|
10913
|
+
const plannedRuns = flags.runs ?? suite.runs ?? 3;
|
|
10914
|
+
const plannedConcurrency = flags.concurrency ?? suite.concurrency ?? 4;
|
|
10915
|
+
const plannedThreshold = flags.threshold ?? suite.threshold ?? 1;
|
|
10916
|
+
const client = await deps.client();
|
|
10917
|
+
const signals = new EvalSignalGuard({
|
|
10918
|
+
archiveAgent: async () => {
|
|
10919
|
+
},
|
|
10920
|
+
writeStderr: deps.writeStderr,
|
|
10921
|
+
exit: deps.signals?.exit ?? ((code) => process.exit(code)),
|
|
10922
|
+
...deps.signals?.signals === void 0 ? {} : { signals: deps.signals.signals },
|
|
10923
|
+
...deps.signals?.timeoutMs === void 0 ? {} : { timeoutMs: deps.signals.timeoutMs }
|
|
10924
|
+
});
|
|
10925
|
+
signals.install();
|
|
10926
|
+
let report;
|
|
10927
|
+
try {
|
|
10928
|
+
report = await runSuite(
|
|
10929
|
+
client,
|
|
10930
|
+
suite,
|
|
10931
|
+
{
|
|
10932
|
+
agentId,
|
|
10933
|
+
environmentId,
|
|
10934
|
+
runs: plannedRuns,
|
|
10935
|
+
concurrency: plannedConcurrency,
|
|
10936
|
+
threshold: plannedThreshold,
|
|
10937
|
+
...flags.agentVersion === void 0 ? {} : { expectedAgentVersion: flags.agentVersion },
|
|
10938
|
+
...flags.waitTimeout === void 0 ? {} : { waitTimeoutSeconds: flags.waitTimeout },
|
|
10939
|
+
keep: flags.keep,
|
|
10940
|
+
signal: signals.signal
|
|
10941
|
+
},
|
|
10942
|
+
{
|
|
10943
|
+
writeStderr: deps.writeStderr,
|
|
10944
|
+
onPlanned: (plan) => {
|
|
10945
|
+
if (flags.json) return;
|
|
10946
|
+
deps.writeStdout(
|
|
10947
|
+
`eval ${suite.name}: ${plan.cases} cases \xD7 ${plan.runs} runs, agent ${plan.agent.id} v${plan.agent.version}, environment ${environmentId}, threshold ${plan.threshold.toFixed(2)}, concurrency ${plan.concurrency}
|
|
10948
|
+
`
|
|
10949
|
+
);
|
|
10950
|
+
},
|
|
10951
|
+
onRunCreated: (run) => {
|
|
10952
|
+
signals.noteRun(run.id);
|
|
10953
|
+
const line = `run ${run.id} created; ${run.taskCount} cases
|
|
10954
|
+
`;
|
|
10955
|
+
if (flags.json) deps.writeStderr(line);
|
|
10956
|
+
else deps.writeStdout(line);
|
|
10957
|
+
}
|
|
10958
|
+
}
|
|
10959
|
+
);
|
|
10960
|
+
} catch (error) {
|
|
10961
|
+
if (signals.interrupted) {
|
|
10962
|
+
await signals.settled;
|
|
10963
|
+
return 130;
|
|
10964
|
+
}
|
|
10965
|
+
if (error instanceof EvalRunError) throw new deps.CliError(error.message, 1, error.code);
|
|
10966
|
+
throw new deps.CliError(`The eval run failed: ${describeApiFailure(error)}`, 1, "API_ERROR");
|
|
10967
|
+
} finally {
|
|
10968
|
+
signals.uninstall();
|
|
10969
|
+
}
|
|
10970
|
+
if (signals.interrupted) {
|
|
10971
|
+
await signals.settled;
|
|
10972
|
+
return 130;
|
|
10973
|
+
}
|
|
10974
|
+
if (flags.json) {
|
|
10975
|
+
deps.writeStdout(`${JSON.stringify(evalReportDocument(report), null, 2)}
|
|
10976
|
+
`);
|
|
10977
|
+
} else {
|
|
10978
|
+
deps.writeStdout(`${formatEvalReport(report)}
|
|
10979
|
+
`);
|
|
10980
|
+
if (flags.keep) {
|
|
10981
|
+
deps.writeStdout(`kept run ${report.run.id} and benchmark ${report.run.benchmarkId}
|
|
10982
|
+
`);
|
|
10983
|
+
}
|
|
10984
|
+
}
|
|
10985
|
+
return report.passed ? 0 : 1;
|
|
10986
|
+
}
|
|
10987
|
+
async function runEvalGate(documents, plan, dir, client, deps) {
|
|
10988
|
+
const agents = documents.filter((document) => document.kind === "agent");
|
|
10989
|
+
if (agents.length !== 1) {
|
|
10990
|
+
throw new EvalRunError(
|
|
10991
|
+
"RUN_START_FAILED",
|
|
10992
|
+
"apply --require-eval needs exactly one agent document; nothing was written."
|
|
10993
|
+
);
|
|
10994
|
+
}
|
|
10995
|
+
const entry = plan.entries.find((candidate2) => candidate2.kind === "agent");
|
|
10996
|
+
if (entry === void 0) throw new Error("runEvalGate needs an agent entry in the plan");
|
|
10997
|
+
const suite = loadEvalSuite(dir, deps.cwd ?? process.cwd());
|
|
10998
|
+
const environmentId = suite.environment;
|
|
10999
|
+
if (environmentId === void 0 || environmentId.length === 0) {
|
|
11000
|
+
throw new EvalSuiteError(
|
|
11001
|
+
"SUITE_INVALID",
|
|
11002
|
+
`${suite.displayDir}: apply --require-eval needs "environment" in suite.yaml; nothing was written.`
|
|
11003
|
+
);
|
|
11004
|
+
}
|
|
11005
|
+
try {
|
|
11006
|
+
await client.apply.retrieveEnvironment(environmentId);
|
|
11007
|
+
} catch (error) {
|
|
11008
|
+
throw new EvalRunError(
|
|
11009
|
+
"API_ERROR",
|
|
11010
|
+
`Could not read environment ${environmentId}: ${describeApiFailure(error)}; nothing was written.`
|
|
11011
|
+
);
|
|
11012
|
+
}
|
|
11013
|
+
const signals = new EvalSignalGuard({
|
|
11014
|
+
archiveAgent: (id) => client.apply.archiveAgent(id),
|
|
11015
|
+
writeStderr: deps.writeStderr,
|
|
11016
|
+
exit: deps.signals?.exit ?? ((code) => process.exit(code)),
|
|
11017
|
+
...deps.signals?.signals === void 0 ? {} : { signals: deps.signals.signals },
|
|
11018
|
+
...deps.signals?.timeoutMs === void 0 ? {} : { timeoutMs: deps.signals.timeoutMs }
|
|
11019
|
+
});
|
|
11020
|
+
signals.install();
|
|
11021
|
+
const candidateName = `${entry.name.slice(0, 48)}-eval-${randomBytes(4).toString("hex")}`;
|
|
11022
|
+
let candidate;
|
|
11023
|
+
try {
|
|
11024
|
+
candidate = await client.apply.createAgent({ ...structuredClone(entry.body), name: candidateName });
|
|
11025
|
+
} catch (error) {
|
|
11026
|
+
signals.uninstall();
|
|
11027
|
+
throw new EvalRunError(
|
|
11028
|
+
"RUN_START_FAILED",
|
|
11029
|
+
`Could not create the candidate agent: ${describeApiFailure(error)}`
|
|
11030
|
+
);
|
|
11031
|
+
}
|
|
11032
|
+
if (signals.interrupted) {
|
|
11033
|
+
try {
|
|
11034
|
+
await client.apply.archiveAgent(candidate.id);
|
|
11035
|
+
} catch (error) {
|
|
11036
|
+
deps.writeStderr(
|
|
11037
|
+
`warning: could not archive the candidate agent ${candidate.id}: ${describeApiFailure(error)}; the result is unchanged.`
|
|
11038
|
+
);
|
|
11039
|
+
}
|
|
11040
|
+
signals.uninstall();
|
|
11041
|
+
await signals.settled;
|
|
11042
|
+
throw new EvalInterruptedError();
|
|
11043
|
+
}
|
|
11044
|
+
signals.register(candidate.id);
|
|
11045
|
+
let report;
|
|
11046
|
+
try {
|
|
11047
|
+
report = await runSuite(
|
|
11048
|
+
client.evals,
|
|
11049
|
+
suite,
|
|
11050
|
+
{
|
|
11051
|
+
agentId: candidate.id,
|
|
11052
|
+
environmentId,
|
|
11053
|
+
...suite.runs === void 0 ? {} : { runs: suite.runs },
|
|
11054
|
+
...suite.concurrency === void 0 ? {} : { concurrency: suite.concurrency },
|
|
11055
|
+
...suite.threshold === void 0 ? {} : { threshold: suite.threshold },
|
|
11056
|
+
signal: deps.signal === void 0 ? signals.signal : AbortSignal.any([deps.signal, signals.signal])
|
|
11057
|
+
},
|
|
11058
|
+
{
|
|
11059
|
+
writeStderr: deps.writeStderr,
|
|
11060
|
+
onPlanned: (planOfRun) => {
|
|
11061
|
+
deps.writeStdout(
|
|
11062
|
+
`eval ${suite.name}: ${planOfRun.cases} cases \xD7 ${planOfRun.runs} runs, candidate ${planOfRun.agent.id} v${planOfRun.agent.version}, environment ${environmentId}, threshold ${planOfRun.threshold.toFixed(2)}, concurrency ${planOfRun.concurrency}
|
|
11063
|
+
`
|
|
11064
|
+
);
|
|
11065
|
+
},
|
|
11066
|
+
onRunCreated: (run) => {
|
|
11067
|
+
signals.noteRun(run.id);
|
|
11068
|
+
deps.writeStdout(`run ${run.id} created; ${run.taskCount} cases
|
|
11069
|
+
`);
|
|
11070
|
+
}
|
|
11071
|
+
}
|
|
11072
|
+
);
|
|
11073
|
+
} catch (error) {
|
|
11074
|
+
if (!signals.interrupted) throw error;
|
|
11075
|
+
} finally {
|
|
11076
|
+
if (signals.claim(candidate.id)) {
|
|
11077
|
+
const archive = client.apply.archiveAgent(candidate.id);
|
|
11078
|
+
signals.track(candidate.id, archive);
|
|
11079
|
+
try {
|
|
11080
|
+
await archive;
|
|
11081
|
+
signals.markArchived(candidate.id);
|
|
11082
|
+
} catch (error) {
|
|
11083
|
+
signals.register(candidate.id);
|
|
11084
|
+
deps.writeStderr(
|
|
11085
|
+
`warning: could not archive the candidate agent ${candidate.id}: ${describeApiFailure(error)}; the result is unchanged.`
|
|
11086
|
+
);
|
|
11087
|
+
}
|
|
11088
|
+
}
|
|
11089
|
+
signals.uninstall();
|
|
11090
|
+
}
|
|
11091
|
+
if (signals.interrupted) {
|
|
11092
|
+
await signals.settled;
|
|
11093
|
+
throw new EvalInterruptedError();
|
|
11094
|
+
}
|
|
11095
|
+
if (report === void 0) throw new Error("runEvalGate did not produce a report");
|
|
11096
|
+
deps.writeStdout(`${formatEvalReport(report)}
|
|
11097
|
+
`);
|
|
11098
|
+
return report;
|
|
11099
|
+
}
|
|
11100
|
+
|
|
11101
|
+
// src/help.ts
|
|
11102
|
+
var HELP_FLAG = "-h, --help";
|
|
11103
|
+
var HELP_DESCRIPTION = "Show this help.";
|
|
11104
|
+
var GROUP_FOOTER = "Run `nouter-platform <command> --help` for the help of a command.";
|
|
11105
|
+
function usageLine(path, positionals) {
|
|
11106
|
+
return ["Usage: nouter-platform", path, ...positionals, "[options]"].join(" ");
|
|
11107
|
+
}
|
|
11108
|
+
function flagDescription(spec, sharedFlagHelp, flag) {
|
|
11109
|
+
return spec.flagHelp?.[flag] ?? sharedFlagHelp[flag] ?? "";
|
|
11110
|
+
}
|
|
11111
|
+
function formatRows(rows) {
|
|
11112
|
+
if (rows.length === 0) return [];
|
|
11113
|
+
const width = Math.max(...rows.map(([name]) => name.length));
|
|
11114
|
+
return rows.map(([name, description]) => ` ${name.padEnd(width)} ${description}`);
|
|
11115
|
+
}
|
|
11116
|
+
function optionRows(spec, sharedFlagHelp) {
|
|
11117
|
+
const rows = [];
|
|
11118
|
+
for (const flag of spec.values) rows.push([`${flag} <value>`, flagDescription(spec, sharedFlagHelp, flag)]);
|
|
11119
|
+
for (const flag of spec.booleans) rows.push([flag, flagDescription(spec, sharedFlagHelp, flag)]);
|
|
11120
|
+
for (const flag of spec.shortValues ?? []) {
|
|
11121
|
+
rows.push([`${flag} <value>`, flagDescription(spec, sharedFlagHelp, flag)]);
|
|
11122
|
+
}
|
|
11123
|
+
rows.push([HELP_FLAG, HELP_DESCRIPTION]);
|
|
11124
|
+
return rows;
|
|
11125
|
+
}
|
|
11126
|
+
function renderCommandHelp(spec, sharedFlagHelp = FLAG_HELP, children = []) {
|
|
11127
|
+
const lines = [usageLine(spec.path, spec.positionals), "", spec.summary];
|
|
11128
|
+
const description = spec.description?.trim();
|
|
11129
|
+
if (description !== void 0 && description.length > 0) lines.push("", description);
|
|
11130
|
+
lines.push("", "Options:", ...formatRows(optionRows(spec, sharedFlagHelp)));
|
|
11131
|
+
if ((spec.examples?.length ?? 0) > 0) {
|
|
11132
|
+
lines.push("", "Examples:", ...spec.examples.map((example) => ` nouter-platform ${example}`));
|
|
11133
|
+
}
|
|
11134
|
+
if (children.length > 0) {
|
|
11135
|
+
lines.push("", "Commands:", ...formatRows(children.map((child) => [child.path, child.summary])));
|
|
11136
|
+
}
|
|
11137
|
+
return lines.join("\n");
|
|
11138
|
+
}
|
|
11139
|
+
function childrenUnder(prefix, commands) {
|
|
11140
|
+
return commands.filter((command) => command.path.startsWith(`${prefix} `));
|
|
11141
|
+
}
|
|
11142
|
+
function resolveHelpPath(words, commands = COMMANDS) {
|
|
11143
|
+
const pathWords = [];
|
|
11144
|
+
for (const word of words) {
|
|
11145
|
+
if (word.startsWith("-")) break;
|
|
11146
|
+
pathWords.push(word);
|
|
11147
|
+
}
|
|
11148
|
+
for (let length = pathWords.length; length >= 1; length -= 1) {
|
|
11149
|
+
const candidate = pathWords.slice(0, length).join(" ");
|
|
11150
|
+
const exact = commands.find((command) => command.path === candidate);
|
|
11151
|
+
if (exact !== void 0) {
|
|
11152
|
+
const leftovers = pathWords.slice(length);
|
|
11153
|
+
const children2 = childrenUnder(candidate, commands);
|
|
11154
|
+
if (children2.length > 0 && leftovers.length > 0) return { kind: "unknown", word: leftovers[0] };
|
|
11155
|
+
return { kind: "command", path: exact.path, spec: exact, children: children2 };
|
|
11156
|
+
}
|
|
11157
|
+
const children = childrenUnder(candidate, commands);
|
|
11158
|
+
if (children.length > 0) {
|
|
11159
|
+
const leftover = pathWords.slice(length);
|
|
11160
|
+
if (leftover.length > 0) return { kind: "unknown", word: leftover[0] };
|
|
11161
|
+
return { kind: "group", prefix: candidate, children };
|
|
11162
|
+
}
|
|
11163
|
+
}
|
|
11164
|
+
return { kind: "unknown", word: pathWords[0] ?? "" };
|
|
11165
|
+
}
|
|
11166
|
+
function renderGroupHelp(prefix, specs) {
|
|
11167
|
+
const lines = [`Usage: nouter-platform ${prefix} <command> [options]`, "", "Commands:"];
|
|
11168
|
+
lines.push(...formatRows(specs.map((spec) => [spec.path, spec.summary])));
|
|
11169
|
+
lines.push("", GROUP_FOOTER);
|
|
11170
|
+
return lines.join("\n");
|
|
11171
|
+
}
|
|
11172
|
+
function helpRequest(argv, deps, env = process.env) {
|
|
11173
|
+
const words = argv[0] === "help" ? argv.slice(1) : argv;
|
|
11174
|
+
const pathWords = [];
|
|
11175
|
+
for (const word of words) {
|
|
11176
|
+
if (word.startsWith("-")) break;
|
|
11177
|
+
pathWords.push(word);
|
|
11178
|
+
}
|
|
11179
|
+
if (pathWords.length === 0) {
|
|
11180
|
+
deps.writeGlobalHelp();
|
|
11181
|
+
return 0;
|
|
11182
|
+
}
|
|
11183
|
+
if (pathWords[0] === "feedback" && !feedbackEnabled(env)) {
|
|
11184
|
+
deps.writeStderr(FEEDBACK_DISABLED_MESSAGE);
|
|
11185
|
+
return 1;
|
|
11186
|
+
}
|
|
11187
|
+
const resolution = resolveHelpPath(pathWords);
|
|
11188
|
+
if (resolution.kind === "unknown") {
|
|
11189
|
+
deps.writeStderr(`Unknown command: ${resolution.word}`);
|
|
11190
|
+
deps.writeStderr("Run `nouter-platform --help` for the command list.");
|
|
11191
|
+
return 1;
|
|
11192
|
+
}
|
|
11193
|
+
if (resolution.kind === "group") {
|
|
11194
|
+
deps.writeStdout(renderGroupHelp(resolution.prefix, resolution.children));
|
|
11195
|
+
return 0;
|
|
11196
|
+
}
|
|
11197
|
+
deps.writeStdout(renderCommandHelp(resolution.spec, FLAG_HELP, resolution.children));
|
|
11198
|
+
return 0;
|
|
11199
|
+
}
|
|
11200
|
+
|
|
11201
|
+
// src/config-file.ts
|
|
11202
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
11203
|
+
import {
|
|
11204
|
+
chmodSync,
|
|
11205
|
+
closeSync as closeSync2,
|
|
11206
|
+
existsSync as existsSync2,
|
|
11207
|
+
fchmodSync,
|
|
11208
|
+
lstatSync,
|
|
11209
|
+
mkdirSync,
|
|
11210
|
+
openSync as openSync2,
|
|
11211
|
+
readFileSync as readFileSync3,
|
|
11212
|
+
renameSync,
|
|
11213
|
+
statSync as statSync3,
|
|
11214
|
+
unlinkSync,
|
|
11215
|
+
writeSync
|
|
11216
|
+
} from "node:fs";
|
|
11217
|
+
import { homedir } from "node:os";
|
|
11218
|
+
import { join as join3 } from "node:path";
|
|
11219
|
+
var CONFIG_DIRECTORY = "nouter-platform";
|
|
11220
|
+
var CONFIG_FILE = "config.json";
|
|
11221
|
+
var CLI_CLIENT_ID = "nouter-platform";
|
|
11222
|
+
var ConfigStorageError = class extends Error {
|
|
11223
|
+
code = "STORAGE_INSECURE";
|
|
11224
|
+
exitCode = 77;
|
|
11225
|
+
constructor(message) {
|
|
11226
|
+
super(message);
|
|
11227
|
+
this.name = "ConfigStorageError";
|
|
11228
|
+
}
|
|
11229
|
+
};
|
|
11230
|
+
function configDirectory() {
|
|
11231
|
+
const xdg = process.env.XDG_CONFIG_HOME;
|
|
11232
|
+
const base = xdg && xdg.length > 0 ? xdg : join3(process.env.HOME ?? homedir(), ".config");
|
|
11233
|
+
return join3(base, CONFIG_DIRECTORY);
|
|
11234
|
+
}
|
|
11235
|
+
function configPath() {
|
|
11236
|
+
return join3(configDirectory(), CONFIG_FILE);
|
|
11237
|
+
}
|
|
11238
|
+
function parseConfig(path) {
|
|
11239
|
+
try {
|
|
11240
|
+
const parsed = JSON.parse(readFileSync3(path, "utf8"));
|
|
11241
|
+
if (typeof parsed.apiKey !== "string" || parsed.apiKey.length === 0) return null;
|
|
11242
|
+
const loaded = {
|
|
11243
|
+
baseUrl: typeof parsed.baseUrl === "string" && parsed.baseUrl.length > 0 ? parsed.baseUrl : null,
|
|
11244
|
+
apiKey: parsed.apiKey
|
|
11245
|
+
};
|
|
11246
|
+
if (typeof parsed.iss === "string" && parsed.iss.length > 0) loaded.iss = parsed.iss;
|
|
11247
|
+
if (typeof parsed.clientId === "string" && parsed.clientId.length > 0) loaded.clientId = parsed.clientId;
|
|
11248
|
+
if (typeof parsed.sessionId === "string" && parsed.sessionId.length > 0) loaded.sessionId = parsed.sessionId;
|
|
11249
|
+
return loaded;
|
|
11250
|
+
} catch {
|
|
11251
|
+
return null;
|
|
11252
|
+
}
|
|
11253
|
+
}
|
|
11254
|
+
function readConfig(options = {}) {
|
|
11255
|
+
const platform = options.platform ?? process.platform;
|
|
11256
|
+
const path = configPath();
|
|
11257
|
+
if (!existsSync2(path)) return null;
|
|
11258
|
+
if (platform !== "win32") {
|
|
11259
|
+
const mode = statSync3(path).mode;
|
|
11260
|
+
if ((mode & 63) !== 0) {
|
|
11261
|
+
const shown = (mode & 511).toString(8).padStart(3, "0");
|
|
11262
|
+
throw new ConfigStorageError(
|
|
11263
|
+
`The config file ${path} is readable by other users (mode ${shown}); run \`chmod 600 ${path}\` or \`nouter-platform logout\`.`
|
|
11264
|
+
);
|
|
11265
|
+
}
|
|
11266
|
+
}
|
|
11267
|
+
return parseConfig(path);
|
|
11268
|
+
}
|
|
11269
|
+
function readConfigForLogout() {
|
|
11270
|
+
const path = configPath();
|
|
11271
|
+
if (!existsSync2(path)) return null;
|
|
11272
|
+
return parseConfig(path);
|
|
11273
|
+
}
|
|
11274
|
+
function rejectSymlink(path, what) {
|
|
11275
|
+
let stats;
|
|
11276
|
+
try {
|
|
11277
|
+
stats = lstatSync(path);
|
|
11278
|
+
} catch (error) {
|
|
11279
|
+
if (error.code === "ENOENT") return;
|
|
11280
|
+
throw error;
|
|
11281
|
+
}
|
|
11282
|
+
if (stats.isSymbolicLink()) {
|
|
11283
|
+
throw new Error(`${what} is a symbolic link; refusing to follow it.`);
|
|
11284
|
+
}
|
|
11285
|
+
}
|
|
11286
|
+
function writeConfig(config) {
|
|
11287
|
+
const directory = configDirectory();
|
|
11288
|
+
mkdirSync(directory, { recursive: true, mode: 448 });
|
|
11289
|
+
rejectSymlink(directory, "The config directory");
|
|
11290
|
+
try {
|
|
11291
|
+
chmodSync(directory, 448);
|
|
11292
|
+
} catch {
|
|
11293
|
+
throw new Error(`Could not set the config directory ${directory} to 0700.`);
|
|
11294
|
+
}
|
|
11295
|
+
const path = configPath();
|
|
11296
|
+
rejectSymlink(path, "The config file");
|
|
11297
|
+
const temporary = join3(directory, `.config.json.${randomBytes2(6).toString("hex")}.tmp`);
|
|
11298
|
+
const fd = openSync2(temporary, "wx", 384);
|
|
11299
|
+
let open = true;
|
|
11300
|
+
try {
|
|
11301
|
+
try {
|
|
11302
|
+
fchmodSync(fd, 384);
|
|
11303
|
+
} catch {
|
|
11304
|
+
throw new Error("Could not set the config file to 0600.");
|
|
11305
|
+
}
|
|
11306
|
+
writeSync(fd, `${JSON.stringify(config, null, 2)}
|
|
11307
|
+
`);
|
|
11308
|
+
closeSync2(fd);
|
|
11309
|
+
open = false;
|
|
11310
|
+
renameSync(temporary, path);
|
|
11311
|
+
} catch (error) {
|
|
11312
|
+
if (open) {
|
|
11313
|
+
try {
|
|
11314
|
+
closeSync2(fd);
|
|
11315
|
+
} catch {
|
|
11316
|
+
}
|
|
11317
|
+
}
|
|
11318
|
+
try {
|
|
11319
|
+
unlinkSync(temporary);
|
|
11320
|
+
} catch {
|
|
11321
|
+
}
|
|
11322
|
+
throw error;
|
|
11323
|
+
}
|
|
11324
|
+
}
|
|
11325
|
+
function clearConfig() {
|
|
11326
|
+
const path = configPath();
|
|
11327
|
+
if (!existsSync2(path)) return false;
|
|
11328
|
+
unlinkSync(path);
|
|
11329
|
+
return true;
|
|
11330
|
+
}
|
|
11331
|
+
|
|
11332
|
+
// src/identity-token.ts
|
|
11333
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
11334
|
+
var IdentityTokenError = class extends Error {
|
|
11335
|
+
constructor(message) {
|
|
11336
|
+
super(message);
|
|
11337
|
+
this.name = "IdentityTokenError";
|
|
11338
|
+
}
|
|
11339
|
+
};
|
|
11340
|
+
var NON_EMPTY = (value) => typeof value === "string" && value.length > 0;
|
|
11341
|
+
function identityTokenSourceFromEnv(env = process.env) {
|
|
11342
|
+
const value = env.NOUTER_PLATFORM_IDENTITY_TOKEN;
|
|
11343
|
+
if (NON_EMPTY(value)) return { kind: "value", token: value };
|
|
11344
|
+
const path = env.NOUTER_PLATFORM_IDENTITY_TOKEN_FILE;
|
|
11345
|
+
if (NON_EMPTY(path)) return { kind: "file", path };
|
|
11346
|
+
return null;
|
|
11347
|
+
}
|
|
11348
|
+
var PRINTABLE = /^[\x21-\x7e]+$/u;
|
|
11349
|
+
function clean(token) {
|
|
11350
|
+
const trimmed = token.trim();
|
|
11351
|
+
if (trimmed.length === 0) throw new IdentityTokenError("The identity token is empty.");
|
|
11352
|
+
if (!PRINTABLE.test(trimmed)) {
|
|
11353
|
+
throw new IdentityTokenError("The identity token has characters the CLI cannot use.");
|
|
11354
|
+
}
|
|
11355
|
+
return trimmed;
|
|
11356
|
+
}
|
|
11357
|
+
function createIdentityTokenReader(source, read = (path) => readFileSync4(path, "utf8")) {
|
|
11358
|
+
if (source.kind === "value") {
|
|
11359
|
+
return { read: () => clean(source.token) };
|
|
11360
|
+
}
|
|
11361
|
+
return {
|
|
11362
|
+
read() {
|
|
11363
|
+
let contents;
|
|
11364
|
+
try {
|
|
11365
|
+
contents = read(source.path);
|
|
11366
|
+
} catch {
|
|
11367
|
+
throw new IdentityTokenError(`Could not read the identity token file ${source.path}.`);
|
|
11368
|
+
}
|
|
11369
|
+
return clean(contents);
|
|
11370
|
+
}
|
|
11371
|
+
};
|
|
11372
|
+
}
|
|
11373
|
+
|
|
11374
|
+
// src/federation.ts
|
|
11375
|
+
var FederationError = class extends Error {
|
|
9639
11376
|
constructor(message) {
|
|
9640
11377
|
super(message);
|
|
9641
11378
|
this.name = "FederationError";
|
|
@@ -9775,8 +11512,8 @@ function startLoginCallback(options) {
|
|
|
9775
11512
|
};
|
|
9776
11513
|
let rejectResult = () => {
|
|
9777
11514
|
};
|
|
9778
|
-
const result = new Promise((
|
|
9779
|
-
resolveResult =
|
|
11515
|
+
const result = new Promise((resolve2, reject) => {
|
|
11516
|
+
resolveResult = resolve2;
|
|
9780
11517
|
rejectResult = reject;
|
|
9781
11518
|
});
|
|
9782
11519
|
result.catch(() => {
|
|
@@ -9898,12 +11635,12 @@ async function readBody(request) {
|
|
|
9898
11635
|
}
|
|
9899
11636
|
|
|
9900
11637
|
// src/pkce.ts
|
|
9901
|
-
import { createHash, randomBytes as
|
|
11638
|
+
import { createHash as createHash2, randomBytes as randomBytes3 } from "node:crypto";
|
|
9902
11639
|
function generateCodeVerifier() {
|
|
9903
|
-
return
|
|
11640
|
+
return randomBytes3(32).toString("base64url");
|
|
9904
11641
|
}
|
|
9905
11642
|
function codeChallengeFor(verifier) {
|
|
9906
|
-
return
|
|
11643
|
+
return createHash2("sha256").update(verifier).digest("base64url");
|
|
9907
11644
|
}
|
|
9908
11645
|
|
|
9909
11646
|
// src/index.ts
|
|
@@ -10313,7 +12050,7 @@ async function loginWithCode(argv, deps) {
|
|
|
10313
12050
|
mode: choice.mode,
|
|
10314
12051
|
purpose: "login"
|
|
10315
12052
|
});
|
|
10316
|
-
const state =
|
|
12053
|
+
const state = randomBytes4(32).toString("base64url");
|
|
10317
12054
|
let code;
|
|
10318
12055
|
if (choice.mode === "loopback") {
|
|
10319
12056
|
const callback = await startLoginCallback({ state, timeoutMs: LOGIN_CALLBACK_TIMEOUT_MS });
|
|
@@ -10357,7 +12094,7 @@ async function loginWithCode(argv, deps) {
|
|
|
10357
12094
|
const previousBaseUrl = previousBaseUrlOf(previous);
|
|
10358
12095
|
if (previous !== null && previousBaseUrl === baseUrl && isCliSessionToken(previous.apiKey) && previous.apiKey !== outcome.token) {
|
|
10359
12096
|
await revokeStoredSession(previousBaseUrl, deps, previous.apiKey);
|
|
10360
|
-
} else if (previous !== null && previousBaseUrl !== null && previousBaseUrl !== baseUrl) {
|
|
12097
|
+
} else if (previous !== null && previousBaseUrl !== null && previousBaseUrl !== baseUrl && isCliSessionToken(previous.apiKey)) {
|
|
10361
12098
|
deps.writeStderr(
|
|
10362
12099
|
`The previous session of ${new URL(previousBaseUrl).host} was not revoked; revoke it from that console.`
|
|
10363
12100
|
);
|
|
@@ -10500,7 +12237,7 @@ async function elevateSession(auth, deps, choice) {
|
|
|
10500
12237
|
},
|
|
10501
12238
|
auth.credential
|
|
10502
12239
|
);
|
|
10503
|
-
const state =
|
|
12240
|
+
const state = randomBytes4(32).toString("base64url");
|
|
10504
12241
|
let code;
|
|
10505
12242
|
if (choice.mode === "loopback") {
|
|
10506
12243
|
const callback = await startLoginCallback({ state, timeoutMs: LOGIN_CALLBACK_TIMEOUT_MS });
|
|
@@ -10563,6 +12300,49 @@ function isDeadSessionBody(body) {
|
|
|
10563
12300
|
const type = bodyField(bodyField(body, "error"), "type");
|
|
10564
12301
|
return type === "SESSION_EXPIRED" || type === "SESSION_REVOKED";
|
|
10565
12302
|
}
|
|
12303
|
+
async function logoutInsecure(all, deps) {
|
|
12304
|
+
const stored = readConfigForLogout();
|
|
12305
|
+
let failure = stored === null;
|
|
12306
|
+
let otherSessionsNotRevoked = false;
|
|
12307
|
+
if (stored !== null && isCliSessionToken(stored.apiKey)) {
|
|
12308
|
+
const envBase = process.env.NOUTER_PLATFORM_BASE_URL;
|
|
12309
|
+
if (!envBase || envBase.length === 0) {
|
|
12310
|
+
failure = true;
|
|
12311
|
+
} else {
|
|
12312
|
+
const path = all ? "/v1/oma/cli/sessions" : "/v1/oma/cli/sessions/current";
|
|
12313
|
+
try {
|
|
12314
|
+
const baseUrl = normalizeBaseUrl(envBase);
|
|
12315
|
+
const answer = await cliJsonRequest(deps, `${baseUrl}${path}`, { method: "DELETE", token: stored.apiKey });
|
|
12316
|
+
if (answer.status === 401 && isDeadSessionBody(answer.body)) {
|
|
12317
|
+
if (all) otherSessionsNotRevoked = true;
|
|
12318
|
+
} else if (answer.status < 200 || answer.status >= 300) {
|
|
12319
|
+
failure = true;
|
|
12320
|
+
}
|
|
12321
|
+
} catch {
|
|
12322
|
+
failure = true;
|
|
12323
|
+
}
|
|
12324
|
+
}
|
|
12325
|
+
}
|
|
12326
|
+
clearConfig();
|
|
12327
|
+
if (otherSessionsNotRevoked) {
|
|
12328
|
+
deps.writeStderr(
|
|
12329
|
+
"Your stored session had already ended, so other CLI sessions were not revoked. Revoke them in the console (Settings \u2192 Profile \u2192 CLI sessions), or after logging in again."
|
|
12330
|
+
);
|
|
12331
|
+
return 2;
|
|
12332
|
+
}
|
|
12333
|
+
if (failure) {
|
|
12334
|
+
deps.writeStderr(
|
|
12335
|
+
"The stored session could not be revoked; the config file was readable by other users. Revoke it in the console (Settings \u2192 Profile \u2192 CLI sessions), or after logging in again."
|
|
12336
|
+
);
|
|
12337
|
+
return 2;
|
|
12338
|
+
}
|
|
12339
|
+
if (all && stored !== null && !isCliSessionToken(stored.apiKey)) {
|
|
12340
|
+
deps.writeStdout("Removed the stored machine key. Revoke it in the console when you no longer need it.");
|
|
12341
|
+
return 0;
|
|
12342
|
+
}
|
|
12343
|
+
deps.writeStdout(all ? "Logged out of every CLI session." : "Logged out.");
|
|
12344
|
+
return 0;
|
|
12345
|
+
}
|
|
10566
12346
|
async function logoutCommand(argv, deps) {
|
|
10567
12347
|
const options = parseOptions(argv, specFor("logout"));
|
|
10568
12348
|
if (options.positionals.length > 0) throw new CliError("Usage: nouter-platform logout [--all]");
|
|
@@ -10572,8 +12352,7 @@ async function logoutCommand(argv, deps) {
|
|
|
10572
12352
|
stored = readConfig();
|
|
10573
12353
|
} catch (error) {
|
|
10574
12354
|
if (!(error instanceof ConfigStorageError)) throw error;
|
|
10575
|
-
|
|
10576
|
-
throw error;
|
|
12355
|
+
return await logoutInsecure(all, deps);
|
|
10577
12356
|
}
|
|
10578
12357
|
if (stored === null) {
|
|
10579
12358
|
deps.writeStdout("No stored key.");
|
|
@@ -10598,7 +12377,7 @@ async function logoutCommand(argv, deps) {
|
|
|
10598
12377
|
clearConfig();
|
|
10599
12378
|
if (otherSessionsNotRevoked) {
|
|
10600
12379
|
deps.writeStderr(
|
|
10601
|
-
"Your stored session had already ended, so other CLI sessions were not revoked. Revoke them in the console (Settings \u2192 Profile \u2192 CLI sessions)."
|
|
12380
|
+
"Your stored session had already ended, so other CLI sessions were not revoked. Revoke them in the console (Settings \u2192 Profile \u2192 CLI sessions), or after logging in again."
|
|
10602
12381
|
);
|
|
10603
12382
|
return 2;
|
|
10604
12383
|
}
|
|
@@ -10688,19 +12467,51 @@ async function listAgents(deps, json) {
|
|
|
10688
12467
|
throw new CliError(`Could not list agents: ${describeApiFailure(error)}`);
|
|
10689
12468
|
}
|
|
10690
12469
|
}
|
|
10691
|
-
async function getAgent(id, deps) {
|
|
12470
|
+
async function getAgent(id, deps, json) {
|
|
10692
12471
|
const auth = await resolveAuth(deps);
|
|
10693
12472
|
try {
|
|
10694
12473
|
const client = clientFor(auth, deps);
|
|
10695
12474
|
const agent = await client.beta.agents.retrieve(id);
|
|
10696
|
-
|
|
10697
|
-
|
|
10698
|
-
|
|
10699
|
-
|
|
12475
|
+
if (json) {
|
|
12476
|
+
deps.writeStdout(JSON.stringify(agent, null, 2));
|
|
12477
|
+
return 0;
|
|
12478
|
+
}
|
|
12479
|
+
deps.writeStdout(`Name: ${oneLine(agent.name)}`);
|
|
12480
|
+
deps.writeStdout(`ID: ${oneLine(agent.id)}`);
|
|
12481
|
+
deps.writeStdout(`Model: ${oneLine(modelOf(agent))}`);
|
|
12482
|
+
deps.writeStdout(`Version: ${oneLine(String(agent.version ?? ""))}`);
|
|
12483
|
+
return 0;
|
|
12484
|
+
} catch (error) {
|
|
12485
|
+
if (error instanceof CliError) throw error;
|
|
12486
|
+
throw new CliError(`Could not read agent ${oneLine(id)}: ${describeApiFailure(error)}`);
|
|
12487
|
+
}
|
|
12488
|
+
}
|
|
12489
|
+
async function archiveAgent(args, deps) {
|
|
12490
|
+
const usage = "Usage: nouter-platform agents archive <agent-id> [--yes] [--json]";
|
|
12491
|
+
let options;
|
|
12492
|
+
try {
|
|
12493
|
+
options = parseOptions(args, specFor("agents archive"));
|
|
12494
|
+
} catch {
|
|
12495
|
+
throw new CliError(usage);
|
|
12496
|
+
}
|
|
12497
|
+
if (options.positionals.length !== 1) throw new CliError(usage);
|
|
12498
|
+
const id = options.positionals[0];
|
|
12499
|
+
const safeId = oneLine(id);
|
|
12500
|
+
if (!options.booleans.has("--yes")) {
|
|
12501
|
+
throw new CliError(`Archiving agent ${safeId} can't be undone; pass --yes to confirm.`);
|
|
12502
|
+
}
|
|
12503
|
+
const auth = await resolveAuth(deps);
|
|
12504
|
+
try {
|
|
12505
|
+
const agent = await elevatedRequest(auth, deps, (client) => client.beta.agents.archive(id));
|
|
12506
|
+
if (options.booleans.has("--json")) {
|
|
12507
|
+
deps.writeStdout(JSON.stringify(agent, null, 2));
|
|
12508
|
+
return 0;
|
|
12509
|
+
}
|
|
12510
|
+
deps.writeStdout(`Archived agent ${oneLine(agent.id)}.`);
|
|
10700
12511
|
return 0;
|
|
10701
12512
|
} catch (error) {
|
|
10702
12513
|
if (error instanceof CliError) throw error;
|
|
10703
|
-
throw
|
|
12514
|
+
throw apiFailure(error, `Could not archive agent ${safeId}`);
|
|
10704
12515
|
}
|
|
10705
12516
|
}
|
|
10706
12517
|
async function listEnvironments(deps, json) {
|
|
@@ -10733,14 +12544,18 @@ async function listEnvironments(deps, json) {
|
|
|
10733
12544
|
throw new CliError(`Could not list environments: ${describeApiFailure(error)}`);
|
|
10734
12545
|
}
|
|
10735
12546
|
}
|
|
10736
|
-
async function getEnvironment(id, deps) {
|
|
12547
|
+
async function getEnvironment(id, deps, json) {
|
|
10737
12548
|
const auth = await resolveAuth(deps);
|
|
10738
12549
|
try {
|
|
10739
12550
|
const client = clientFor(auth, deps);
|
|
10740
12551
|
const environment = await client.beta.environments.retrieve(id);
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
|
|
12552
|
+
if (json) {
|
|
12553
|
+
deps.writeStdout(JSON.stringify(environment, null, 2));
|
|
12554
|
+
return 0;
|
|
12555
|
+
}
|
|
12556
|
+
deps.writeStdout(`Name: ${oneLine(environment.name)}`);
|
|
12557
|
+
deps.writeStdout(`ID: ${oneLine(environment.id)}`);
|
|
12558
|
+
deps.writeStdout(`Created: ${oneLine(environment.created_at)}`);
|
|
10744
12559
|
return 0;
|
|
10745
12560
|
} catch (error) {
|
|
10746
12561
|
if (error instanceof CliError) throw error;
|
|
@@ -10909,7 +12724,88 @@ async function sessionsCommand(argv, deps) {
|
|
|
10909
12724
|
if (subcommand === "events") return await listSessionEvents(args, deps);
|
|
10910
12725
|
return usageError("sessions list|get <session-id>|events <session-id>", deps);
|
|
10911
12726
|
}
|
|
12727
|
+
async function usageLimitsCommand(argv, deps) {
|
|
12728
|
+
const options = parseOptions(argv, specFor("usage limits"));
|
|
12729
|
+
if (options.positionals.length > 0) {
|
|
12730
|
+
throw new CliError("Usage: nouter-platform usage limits [--agent-id <agent-id>] [--json]");
|
|
12731
|
+
}
|
|
12732
|
+
const agentId = lastOption(options, "--agent-id");
|
|
12733
|
+
const auth = await resolveAuth(deps);
|
|
12734
|
+
try {
|
|
12735
|
+
const limits = await clientFor(auth, deps).platform.usageLimits.get({
|
|
12736
|
+
...agentId !== void 0 && { agent_id: agentId }
|
|
12737
|
+
});
|
|
12738
|
+
if (options.booleans.has("--json")) {
|
|
12739
|
+
deps.writeStdout(JSON.stringify(limits, null, 2));
|
|
12740
|
+
return 0;
|
|
12741
|
+
}
|
|
12742
|
+
if (limits.data.length === 0) {
|
|
12743
|
+
deps.writeStdout("No usage limits.");
|
|
12744
|
+
return 0;
|
|
12745
|
+
}
|
|
12746
|
+
deps.writeStdout(
|
|
12747
|
+
table([
|
|
12748
|
+
["KIND", "EFFECTIVE MAX COST", "EFFECTIVE FROM"],
|
|
12749
|
+
...limits.data.map((row) => [
|
|
12750
|
+
printable(row.kind),
|
|
12751
|
+
printable(row.effective_max_cost_micros ?? ""),
|
|
12752
|
+
printable(row.effective_from ?? "")
|
|
12753
|
+
])
|
|
12754
|
+
])
|
|
12755
|
+
);
|
|
12756
|
+
return 0;
|
|
12757
|
+
} catch (error) {
|
|
12758
|
+
if (error instanceof CliError) throw error;
|
|
12759
|
+
throw new CliError(`Could not read the usage limits: ${describeApiFailure(error)}`);
|
|
12760
|
+
}
|
|
12761
|
+
}
|
|
12762
|
+
function rateLimitSubject(entry) {
|
|
12763
|
+
if (entry.scope === "api_key") return entry.api_key_id;
|
|
12764
|
+
if (entry.scope === "workspace") return entry.model;
|
|
12765
|
+
return "";
|
|
12766
|
+
}
|
|
12767
|
+
async function usageRateLimitsCommand(argv, deps) {
|
|
12768
|
+
const options = parseOptions(argv, specFor("usage rate-limits"));
|
|
12769
|
+
if (options.positionals.length > 0) {
|
|
12770
|
+
throw new CliError("Usage: nouter-platform usage rate-limits [--json]");
|
|
12771
|
+
}
|
|
12772
|
+
const auth = await resolveAuth(deps);
|
|
12773
|
+
try {
|
|
12774
|
+
const rateLimits = await clientFor(auth, deps).platform.rateLimits.list();
|
|
12775
|
+
if (options.booleans.has("--json")) {
|
|
12776
|
+
deps.writeStdout(JSON.stringify(rateLimits, null, 2));
|
|
12777
|
+
return 0;
|
|
12778
|
+
}
|
|
12779
|
+
if (rateLimits.data.length === 0) {
|
|
12780
|
+
deps.writeStdout("No rate limits.");
|
|
12781
|
+
return 0;
|
|
12782
|
+
}
|
|
12783
|
+
deps.writeStdout(
|
|
12784
|
+
table([
|
|
12785
|
+
["TYPE", "SCOPE", "SUBJECT", "WINDOW", "LIMIT", "CURRENT"],
|
|
12786
|
+
...rateLimits.data.map((entry) => [
|
|
12787
|
+
printable(entry.type),
|
|
12788
|
+
printable(entry.scope),
|
|
12789
|
+
printable(rateLimitSubject(entry)),
|
|
12790
|
+
printable(entry.window),
|
|
12791
|
+
entry.limit === null ? "" : String(entry.limit),
|
|
12792
|
+
String(entry.current.count)
|
|
12793
|
+
])
|
|
12794
|
+
])
|
|
12795
|
+
);
|
|
12796
|
+
return 0;
|
|
12797
|
+
} catch (error) {
|
|
12798
|
+
if (error instanceof CliError) throw error;
|
|
12799
|
+
throw new CliError(`Could not read the rate limits: ${describeApiFailure(error)}`);
|
|
12800
|
+
}
|
|
12801
|
+
}
|
|
10912
12802
|
async function usageCommand(argv, deps) {
|
|
12803
|
+
if (argv[0] === "rate-limits") {
|
|
12804
|
+
return await usageRateLimitsCommand(argv.slice(1), deps);
|
|
12805
|
+
}
|
|
12806
|
+
if (argv[0] === "limits") {
|
|
12807
|
+
return await usageLimitsCommand(argv.slice(1), deps);
|
|
12808
|
+
}
|
|
10913
12809
|
const options = parseOptions(argv, specFor("usage"));
|
|
10914
12810
|
if (options.positionals.length > 0) {
|
|
10915
12811
|
throw new CliError("Usage: nouter-platform usage [--days 7|30|90] [--group-by <dimension>] [--json]");
|
|
@@ -11001,16 +12897,215 @@ function nextPageCommand(params, cursor) {
|
|
|
11001
12897
|
return parts.join(" ");
|
|
11002
12898
|
}
|
|
11003
12899
|
function shellQuote(value) {
|
|
11004
|
-
if (/^[A-Za-z0-9._~:@%+=,/-]+$/.test(value)) return value;
|
|
12900
|
+
if (/^[A-Za-z0-9._~:@%+=,/-]+$/.test(value) && !/^[~=-]/.test(value)) return value;
|
|
11005
12901
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
11006
12902
|
}
|
|
12903
|
+
function formatLastUsed(milliseconds) {
|
|
12904
|
+
return milliseconds === null ? "" : new Date(milliseconds).toISOString();
|
|
12905
|
+
}
|
|
12906
|
+
function apiKeyPrefixLength(key) {
|
|
12907
|
+
return key.credential.type === "environment" ? 12 : 8;
|
|
12908
|
+
}
|
|
12909
|
+
async function warnAboutOwnKey(client, id, auth, deps, consequence) {
|
|
12910
|
+
if (auth.transport === "bearer") return;
|
|
12911
|
+
let keys;
|
|
12912
|
+
try {
|
|
12913
|
+
keys = await listAll(client, "/v1/oma/api_keys");
|
|
12914
|
+
} catch (error) {
|
|
12915
|
+
deps.writeStderr(
|
|
12916
|
+
`Could not read the API keys to check whether ${id} is this process's key (${describeApiFailure(error)}); continuing.`
|
|
12917
|
+
);
|
|
12918
|
+
return;
|
|
12919
|
+
}
|
|
12920
|
+
const target = keys.find((key) => key.id === id);
|
|
12921
|
+
if (target === void 0) return;
|
|
12922
|
+
if (target.prefix === auth.credential.slice(0, apiKeyPrefixLength(target))) {
|
|
12923
|
+
deps.writeStderr(`Warning: ${id} is the key this process uses to authenticate; ${consequence}`);
|
|
12924
|
+
}
|
|
12925
|
+
}
|
|
12926
|
+
async function keysCommand(argv, deps) {
|
|
12927
|
+
const [subcommand, ...args] = argv;
|
|
12928
|
+
if (subcommand === "list") {
|
|
12929
|
+
const options = parseOptions(args, specFor("keys list"));
|
|
12930
|
+
if (options.positionals.length > 0) throw new CliError("Usage: nouter-platform keys list [--json]");
|
|
12931
|
+
const auth = await resolveAuth(deps);
|
|
12932
|
+
try {
|
|
12933
|
+
const page = await clientFor(auth, deps).platform.apiKeys.list();
|
|
12934
|
+
if (options.booleans.has("--json")) {
|
|
12935
|
+
deps.writeStdout(JSON.stringify(page.data, null, 2));
|
|
12936
|
+
return 0;
|
|
12937
|
+
}
|
|
12938
|
+
if (page.data.length === 0) {
|
|
12939
|
+
deps.writeStdout("No API keys.");
|
|
12940
|
+
return 0;
|
|
12941
|
+
}
|
|
12942
|
+
deps.writeStdout(
|
|
12943
|
+
table([
|
|
12944
|
+
["ID", "NAME", "PREFIX", "STATUS", "SCOPES", "EXPIRES", "LAST USED"],
|
|
12945
|
+
// Todo lo que viene del servidor pasa por `printable()`: un nombre con CSI u OSC 52 mueve el terminal del
|
|
12946
|
+
// admin (escribe el portapapeles, borra la pantalla).
|
|
12947
|
+
...page.data.map((key) => [
|
|
12948
|
+
printable(key.id),
|
|
12949
|
+
printable(key.name),
|
|
12950
|
+
printable(key.prefix),
|
|
12951
|
+
printable(key.status),
|
|
12952
|
+
printable((key.scopes ?? []).join(", ")),
|
|
12953
|
+
printable(key.expires_at ?? ""),
|
|
12954
|
+
printable(formatLastUsed(key.last_used_at))
|
|
12955
|
+
])
|
|
12956
|
+
])
|
|
12957
|
+
);
|
|
12958
|
+
return 0;
|
|
12959
|
+
} catch (error) {
|
|
12960
|
+
if (error instanceof CliError) throw error;
|
|
12961
|
+
throw new CliError(`Could not list API keys: ${describeApiFailure(error)}`);
|
|
12962
|
+
}
|
|
12963
|
+
}
|
|
12964
|
+
if (subcommand === "create") {
|
|
12965
|
+
const options = parseOptions(args, specFor("keys create"));
|
|
12966
|
+
if (options.positionals.length > 0) {
|
|
12967
|
+
throw new CliError(
|
|
12968
|
+
"Usage: nouter-platform keys create [--name <name>] [--scopes <scopes>] [--preset backend|ci] [--expires-at <iso>] [--agent-id <agent-id>] [--json]"
|
|
12969
|
+
);
|
|
12970
|
+
}
|
|
12971
|
+
const preset = lastOption(options, "--preset");
|
|
12972
|
+
const scopesFlag = options.values.get("--scopes");
|
|
12973
|
+
if (preset !== void 0 && scopesFlag !== void 0) {
|
|
12974
|
+
throw new CliError("--preset and --scopes are mutually exclusive.");
|
|
12975
|
+
}
|
|
12976
|
+
let scopes;
|
|
12977
|
+
if (preset !== void 0) {
|
|
12978
|
+
if (preset !== "backend" && preset !== "ci") {
|
|
12979
|
+
throw new CliError(`The preset must be "backend" or "ci" (got "${preset}").`);
|
|
12980
|
+
}
|
|
12981
|
+
scopes = KEY_PRESETS[preset];
|
|
12982
|
+
} else if (scopesFlag !== void 0) {
|
|
12983
|
+
const parsed = scopesFlag.flatMap((value) => value.split(",")).map((scope) => scope.trim()).filter((scope) => scope.length > 0);
|
|
12984
|
+
if (parsed.length === 0) throw new CliError("The option --scopes needs at least one scope.");
|
|
12985
|
+
scopes = parsed;
|
|
12986
|
+
}
|
|
12987
|
+
const expiresAt = lastOption(options, "--expires-at");
|
|
12988
|
+
const agentId = lastOption(options, "--agent-id");
|
|
12989
|
+
const name = lastOption(options, "--name");
|
|
12990
|
+
const params = {
|
|
12991
|
+
...name !== void 0 && { name },
|
|
12992
|
+
...scopes !== void 0 && { scopes },
|
|
12993
|
+
...expiresAt !== void 0 && { expires_at: expiresAt },
|
|
12994
|
+
...agentId !== void 0 && { agent_id: agentId }
|
|
12995
|
+
};
|
|
12996
|
+
const auth = await resolveAuth(deps);
|
|
12997
|
+
try {
|
|
12998
|
+
const created = await clientFor(auth, deps).platform.apiKeys.create(params);
|
|
12999
|
+
if (options.booleans.has("--json")) {
|
|
13000
|
+
deps.writeStdout(JSON.stringify(created, null, 2));
|
|
13001
|
+
return 0;
|
|
13002
|
+
}
|
|
13003
|
+
deps.writeStdout(created.key);
|
|
13004
|
+
const detail = [
|
|
13005
|
+
`Created key ${printable(created.id)} (${printable(created.name)})`,
|
|
13006
|
+
`scopes: ${printable((created.scopes ?? []).join(", "))}`,
|
|
13007
|
+
...created.expires_at !== null ? [`expires at ${printable(created.expires_at)}`] : []
|
|
13008
|
+
];
|
|
13009
|
+
deps.writeStderr(`${detail.join("; ")}.`);
|
|
13010
|
+
return 0;
|
|
13011
|
+
} catch (error) {
|
|
13012
|
+
if (error instanceof CliError) throw error;
|
|
13013
|
+
throw new CliError(`Could not create the API key: ${describeApiFailure(error)}`);
|
|
13014
|
+
}
|
|
13015
|
+
}
|
|
13016
|
+
if (subcommand === "rotate") {
|
|
13017
|
+
const options = parseOptions(args, specFor("keys rotate"));
|
|
13018
|
+
if (options.positionals.length !== 1) {
|
|
13019
|
+
throw new CliError(
|
|
13020
|
+
"Usage: nouter-platform keys rotate <key-id> [--grace-period-seconds <seconds>] [--yes] [--json]"
|
|
13021
|
+
);
|
|
13022
|
+
}
|
|
13023
|
+
const id = options.positionals[0];
|
|
13024
|
+
if (!options.booleans.has("--yes")) {
|
|
13025
|
+
throw new CliError(`Rotating key ${id} would replace it; pass --yes to confirm.`);
|
|
13026
|
+
}
|
|
13027
|
+
const gracePeriodSeconds = integerOption(options, "--grace-period-seconds", 0, 86400);
|
|
13028
|
+
const auth = await resolveAuth(deps);
|
|
13029
|
+
const client = clientFor(auth, deps);
|
|
13030
|
+
try {
|
|
13031
|
+
await warnAboutOwnKey(
|
|
13032
|
+
client,
|
|
13033
|
+
id,
|
|
13034
|
+
auth,
|
|
13035
|
+
deps,
|
|
13036
|
+
"once its rotation grace ends the CLI will be left without a credential."
|
|
13037
|
+
);
|
|
13038
|
+
const rotated = await client.platform.apiKeys.rotate(id, {
|
|
13039
|
+
...gracePeriodSeconds !== void 0 && { grace_period_seconds: gracePeriodSeconds }
|
|
13040
|
+
});
|
|
13041
|
+
if (options.booleans.has("--json")) {
|
|
13042
|
+
deps.writeStdout(JSON.stringify(rotated, null, 2));
|
|
13043
|
+
return 0;
|
|
13044
|
+
}
|
|
13045
|
+
deps.writeStdout(rotated.key);
|
|
13046
|
+
const detail = [
|
|
13047
|
+
`Rotated key ${printable(rotated.id)} (${printable(rotated.name)})`,
|
|
13048
|
+
...rotated.rotated_from ? [`replaced ${printable(rotated.rotated_from)}`] : [],
|
|
13049
|
+
...rotated.expires_at !== null ? [`expires at ${printable(rotated.expires_at)}`] : []
|
|
13050
|
+
];
|
|
13051
|
+
deps.writeStderr(`${detail.join("; ")}.`);
|
|
13052
|
+
return 0;
|
|
13053
|
+
} catch (error) {
|
|
13054
|
+
if (error instanceof CliError) throw error;
|
|
13055
|
+
throw new CliError(`Could not rotate the API key: ${describeApiFailure(error)}`);
|
|
13056
|
+
}
|
|
13057
|
+
}
|
|
13058
|
+
if (subcommand === "revoke") {
|
|
13059
|
+
const options = parseOptions(args, specFor("keys revoke"));
|
|
13060
|
+
if (options.positionals.length !== 1) {
|
|
13061
|
+
throw new CliError("Usage: nouter-platform keys revoke <key-id> [--yes] [--json]");
|
|
13062
|
+
}
|
|
13063
|
+
const id = options.positionals[0];
|
|
13064
|
+
if (!options.booleans.has("--yes")) {
|
|
13065
|
+
throw new CliError(`Revoking key ${id} is permanent; pass --yes to confirm.`);
|
|
13066
|
+
}
|
|
13067
|
+
const auth = await resolveAuth(deps);
|
|
13068
|
+
const client = clientFor(auth, deps);
|
|
13069
|
+
try {
|
|
13070
|
+
await warnAboutOwnKey(
|
|
13071
|
+
client,
|
|
13072
|
+
id,
|
|
13073
|
+
auth,
|
|
13074
|
+
deps,
|
|
13075
|
+
"once revoked, the CLI will be left without a credential."
|
|
13076
|
+
);
|
|
13077
|
+
const revoked = await client.platform.apiKeys.revoke(id);
|
|
13078
|
+
if (options.booleans.has("--json")) {
|
|
13079
|
+
deps.writeStdout(JSON.stringify(revoked, null, 2));
|
|
13080
|
+
return 0;
|
|
13081
|
+
}
|
|
13082
|
+
deps.writeStdout(`Revoked API key ${printable(revoked.id)}.`);
|
|
13083
|
+
return 0;
|
|
13084
|
+
} catch (error) {
|
|
13085
|
+
if (error instanceof CliError) throw error;
|
|
13086
|
+
throw new CliError(`Could not revoke the API key: ${describeApiFailure(error)}`);
|
|
13087
|
+
}
|
|
13088
|
+
}
|
|
13089
|
+
return usageError("keys list|create|rotate|revoke", deps);
|
|
13090
|
+
}
|
|
11007
13091
|
var MANUAL_FLAGS = {
|
|
11008
13092
|
login: ["--api-key", "--browser", "--paste"],
|
|
11009
13093
|
"agents list": ["--json"],
|
|
11010
|
-
"agents get": [],
|
|
11011
13094
|
"environments list": ["--json"],
|
|
11012
|
-
"
|
|
11013
|
-
|
|
13095
|
+
apply: ["--file", "-f", "--dry-run", "--rotate-secrets", "--require-eval"],
|
|
13096
|
+
eval: [
|
|
13097
|
+
"--agent",
|
|
13098
|
+
"--environment",
|
|
13099
|
+
"--threshold",
|
|
13100
|
+
"--runs",
|
|
13101
|
+
"--concurrency",
|
|
13102
|
+
"--case",
|
|
13103
|
+
"--tag",
|
|
13104
|
+
"--agent-version",
|
|
13105
|
+
"--wait-timeout",
|
|
13106
|
+
"--json",
|
|
13107
|
+
"--keep"
|
|
13108
|
+
]
|
|
11014
13109
|
};
|
|
11015
13110
|
function parseOptions(args, spec) {
|
|
11016
13111
|
const values = /* @__PURE__ */ new Map();
|
|
@@ -11080,12 +13175,22 @@ async function listAll(client, path, query = {}) {
|
|
|
11080
13175
|
} while (page !== null && page !== void 0 && page.length > 0);
|
|
11081
13176
|
return items;
|
|
11082
13177
|
}
|
|
13178
|
+
async function listAllPages(fetchPage) {
|
|
13179
|
+
const items = [];
|
|
13180
|
+
let page;
|
|
13181
|
+
do {
|
|
13182
|
+
const response = await fetchPage(page);
|
|
13183
|
+
items.push(...response.data);
|
|
13184
|
+
page = response.next_page ?? void 0;
|
|
13185
|
+
} while (page !== void 0 && page.length > 0);
|
|
13186
|
+
return items;
|
|
13187
|
+
}
|
|
11083
13188
|
var statusOf = (record) => record.archived_at === null ? "active" : "archived";
|
|
11084
13189
|
function matchSummary(match) {
|
|
11085
13190
|
const parts = [];
|
|
11086
13191
|
if (match.subject_prefix !== void 0) parts.push(`subject:${match.subject_prefix}`);
|
|
11087
13192
|
if (match.audience !== void 0) parts.push(`aud:${match.audience}`);
|
|
11088
|
-
for (const [key, value] of Object.entries(match.claims ?? {})) parts.push(`${key}=${value}`);
|
|
13193
|
+
for (const [key, value] of Object.entries(match.claims ?? {})) parts.push(`${key}=${String(value)}`);
|
|
11089
13194
|
return parts.join(", ");
|
|
11090
13195
|
}
|
|
11091
13196
|
async function serviceAccountsCommand(argv, deps) {
|
|
@@ -11096,10 +13201,13 @@ async function serviceAccountsCommand(argv, deps) {
|
|
|
11096
13201
|
const auth = await resolveAuth(deps);
|
|
11097
13202
|
try {
|
|
11098
13203
|
const client = clientFor(auth, deps);
|
|
11099
|
-
const accounts = await
|
|
11100
|
-
client
|
|
11101
|
-
|
|
11102
|
-
|
|
13204
|
+
const accounts = await listAllPages(
|
|
13205
|
+
(page) => client.platform.serviceAccounts.list({
|
|
13206
|
+
query: {
|
|
13207
|
+
...options.booleans.has("--include-archived") ? { include_archived: true } : {},
|
|
13208
|
+
...page !== void 0 ? { page } : {}
|
|
13209
|
+
}
|
|
13210
|
+
})
|
|
11103
13211
|
);
|
|
11104
13212
|
if (options.booleans.has("--json")) {
|
|
11105
13213
|
deps.writeStdout(JSON.stringify(accounts, null, 2));
|
|
@@ -11178,10 +13286,13 @@ async function federationIssuersCommand(argv, deps) {
|
|
|
11178
13286
|
const auth = await resolveAuth(deps);
|
|
11179
13287
|
try {
|
|
11180
13288
|
const client = clientFor(auth, deps);
|
|
11181
|
-
const issuers = await
|
|
11182
|
-
client
|
|
11183
|
-
|
|
11184
|
-
|
|
13289
|
+
const issuers = await listAllPages(
|
|
13290
|
+
(page) => client.platform.federation.issuers.list({
|
|
13291
|
+
query: {
|
|
13292
|
+
...options.booleans.has("--include-archived") ? { include_archived: true } : {},
|
|
13293
|
+
...page !== void 0 ? { page } : {}
|
|
13294
|
+
}
|
|
13295
|
+
})
|
|
11185
13296
|
);
|
|
11186
13297
|
if (options.booleans.has("--json")) {
|
|
11187
13298
|
deps.writeStdout(JSON.stringify(issuers, null, 2));
|
|
@@ -11272,10 +13383,15 @@ async function federationRulesCommand(argv, deps) {
|
|
|
11272
13383
|
const auth = await resolveAuth(deps);
|
|
11273
13384
|
try {
|
|
11274
13385
|
const client = clientFor(auth, deps);
|
|
11275
|
-
const rules = await
|
|
11276
|
-
|
|
11277
|
-
|
|
11278
|
-
|
|
13386
|
+
const rules = await listAllPages(
|
|
13387
|
+
(page) => client.platform.federation.rules.list({
|
|
13388
|
+
query: {
|
|
13389
|
+
...options.booleans.has("--include-archived") ? { include_archived: true } : {},
|
|
13390
|
+
...issuerId !== void 0 ? { issuer_id: issuerId } : {},
|
|
13391
|
+
...page !== void 0 ? { page } : {}
|
|
13392
|
+
}
|
|
13393
|
+
})
|
|
13394
|
+
);
|
|
11279
13395
|
if (options.booleans.has("--json")) {
|
|
11280
13396
|
deps.writeStdout(JSON.stringify(rules, null, 2));
|
|
11281
13397
|
return 0;
|
|
@@ -11456,6 +13572,9 @@ function applyClientFor(client) {
|
|
|
11456
13572
|
createAgent: (body) => client.beta.agents.create(body),
|
|
11457
13573
|
updateAgent: (id, body) => client.beta.agents.update(id, body),
|
|
11458
13574
|
retrieveAgent: (id) => client.beta.agents.retrieve(id),
|
|
13575
|
+
archiveAgent: async (id) => {
|
|
13576
|
+
await client.beta.agents.archive(id);
|
|
13577
|
+
},
|
|
11459
13578
|
// Un entorno no lleva versión en el contrato: el update no manda `version`.
|
|
11460
13579
|
createEnvironment: async (body) => {
|
|
11461
13580
|
await client.beta.environments.create(body);
|
|
@@ -11468,9 +13587,10 @@ function applyClientFor(client) {
|
|
|
11468
13587
|
retrieveEnvironment: (id) => client.beta.environments.retrieve(id)
|
|
11469
13588
|
};
|
|
11470
13589
|
}
|
|
11471
|
-
function applyUsage(deps) {
|
|
13590
|
+
function applyUsage(deps, message) {
|
|
13591
|
+
if (message !== void 0) deps.writeStderr(message);
|
|
11472
13592
|
deps.writeStderr(
|
|
11473
|
-
"Usage: nouter-platform apply -f|--file <file|directory> [-f <file|directory> ...] [--dry-run] [--rotate-secrets]"
|
|
13593
|
+
"Usage: nouter-platform apply -f|--file <file|directory> [-f <file|directory> ...] [--dry-run] [--rotate-secrets] [--require-eval <suite>]"
|
|
11474
13594
|
);
|
|
11475
13595
|
return 1;
|
|
11476
13596
|
}
|
|
@@ -11478,7 +13598,8 @@ async function applyCommand(argv, deps) {
|
|
|
11478
13598
|
const inputs = [];
|
|
11479
13599
|
let dryRun = false;
|
|
11480
13600
|
let rotateSecrets = false;
|
|
11481
|
-
|
|
13601
|
+
let requireEval;
|
|
13602
|
+
const [fileFlag, shortFileFlag, dryRunFlag, rotateSecretsFlag, requireEvalFlag] = MANUAL_FLAGS.apply;
|
|
11482
13603
|
for (let index = 0; index < argv.length; index += 1) {
|
|
11483
13604
|
const argument = argv[index];
|
|
11484
13605
|
if (argument === shortFileFlag || argument === fileFlag) {
|
|
@@ -11490,11 +13611,22 @@ async function applyCommand(argv, deps) {
|
|
|
11490
13611
|
dryRun = true;
|
|
11491
13612
|
} else if (argument === rotateSecretsFlag) {
|
|
11492
13613
|
rotateSecrets = true;
|
|
13614
|
+
} else if (argument === requireEvalFlag) {
|
|
13615
|
+
const input = argv[index + 1];
|
|
13616
|
+
if (input === void 0 || input.startsWith("-")) return applyUsage(deps);
|
|
13617
|
+
requireEval = input;
|
|
13618
|
+
index += 1;
|
|
11493
13619
|
} else {
|
|
11494
13620
|
return applyUsage(deps);
|
|
11495
13621
|
}
|
|
11496
13622
|
}
|
|
11497
13623
|
if (inputs.length === 0) return applyUsage(deps);
|
|
13624
|
+
if (requireEval !== void 0 && dryRun) {
|
|
13625
|
+
return applyUsage(deps, "--dry-run does not combine with --require-eval; use `nouter-platform eval` instead.");
|
|
13626
|
+
}
|
|
13627
|
+
if (requireEval !== void 0 && (requireEval.length === 0 || isAbsolute3(requireEval) || requireEval.split(/[\\/]/).includes(".."))) {
|
|
13628
|
+
return applyUsage(deps, "The --require-eval suite directory must be relative and must not contain `..`.");
|
|
13629
|
+
}
|
|
11498
13630
|
let documents;
|
|
11499
13631
|
try {
|
|
11500
13632
|
documents = loadApplyDocuments(inputs, process.env);
|
|
@@ -11502,8 +13634,18 @@ async function applyCommand(argv, deps) {
|
|
|
11502
13634
|
if (error instanceof ApplyValidationError) throw new CliError(error.message);
|
|
11503
13635
|
throw error;
|
|
11504
13636
|
}
|
|
13637
|
+
if (requireEval !== void 0) {
|
|
13638
|
+
const agents = documents.filter((document) => document.kind === "agent");
|
|
13639
|
+
if (agents.length !== 1) {
|
|
13640
|
+
return applyUsage(
|
|
13641
|
+
deps,
|
|
13642
|
+
"--require-eval needs exactly one agent document in the input; nothing was written."
|
|
13643
|
+
);
|
|
13644
|
+
}
|
|
13645
|
+
}
|
|
11505
13646
|
const auth = await resolveAuth(deps);
|
|
11506
|
-
const
|
|
13647
|
+
const platform = clientFor(auth, deps, { maxRetries: 0 });
|
|
13648
|
+
const client = applyClientFor(platform);
|
|
11507
13649
|
let current;
|
|
11508
13650
|
try {
|
|
11509
13651
|
current = {
|
|
@@ -11525,6 +13667,32 @@ async function applyCommand(argv, deps) {
|
|
|
11525
13667
|
for (const line of formatApplyPlan(plan)) deps.writeStdout(line);
|
|
11526
13668
|
return 0;
|
|
11527
13669
|
}
|
|
13670
|
+
if (requireEval !== void 0) {
|
|
13671
|
+
const agentEntry = plan.entries.find((entry) => entry.kind === "agent");
|
|
13672
|
+
if (agentEntry !== void 0 && agentEntry.action !== "unchanged") {
|
|
13673
|
+
if (usesMaskedEnv(agentEntry.document)) {
|
|
13674
|
+
return applyUsage(deps, "--require-eval needs every env value via ${VAR}; nothing was written.");
|
|
13675
|
+
}
|
|
13676
|
+
let report;
|
|
13677
|
+
try {
|
|
13678
|
+
report = await runEvalGate(documents, plan, requireEval, {
|
|
13679
|
+
apply: client,
|
|
13680
|
+
evals: platform
|
|
13681
|
+
}, {
|
|
13682
|
+
writeStdout: deps.writeStdout,
|
|
13683
|
+
writeStderr: deps.writeStderr
|
|
13684
|
+
});
|
|
13685
|
+
} catch (error) {
|
|
13686
|
+
if (error instanceof EvalInterruptedError) return 130;
|
|
13687
|
+
if (error instanceof EvalSuiteError || error instanceof EvalRunError) {
|
|
13688
|
+
throw new CliError(error.message, 1, error.code);
|
|
13689
|
+
}
|
|
13690
|
+
if (error instanceof CliError) throw error;
|
|
13691
|
+
throw new CliError(`The eval gate failed: ${describeApiFailure(error)}`, 1, "API_ERROR");
|
|
13692
|
+
}
|
|
13693
|
+
if (!report.passed) return 1;
|
|
13694
|
+
}
|
|
13695
|
+
}
|
|
11528
13696
|
const results = await runApply(plan, client);
|
|
11529
13697
|
for (const line of formatApplyResults(results)) deps.writeStdout(line);
|
|
11530
13698
|
return results.some((result) => result.status === "failed") ? 1 : 0;
|
|
@@ -11536,23 +13704,27 @@ function printHelp(deps) {
|
|
|
11536
13704
|
"",
|
|
11537
13705
|
"Commands:",
|
|
11538
13706
|
" login Log in through the browser or a pasted code, or store an API key (--api-key)",
|
|
11539
|
-
" logout Revoke the CLI session and remove the
|
|
13707
|
+
" logout Revoke the CLI session and remove the credential (--all: every session);",
|
|
13708
|
+
" an insecure config revokes only if NOUTER_PLATFORM_BASE_URL is set",
|
|
11540
13709
|
" whoami Show the organization, role and scopes (--json)",
|
|
11541
13710
|
" auth status | sessions list|revoke <session-id>",
|
|
11542
13711
|
" version Show the CLI version and the SDK version it ships",
|
|
11543
13712
|
" agents list | get <agent-id>",
|
|
11544
13713
|
" environments list | get <environment-id>",
|
|
11545
13714
|
" sessions list | get <session-id> | events <session-id>",
|
|
11546
|
-
" usage
|
|
13715
|
+
" usage usage | limits | rate-limits",
|
|
13716
|
+
" keys list | create | rotate | revoke",
|
|
11547
13717
|
" service-accounts list | create | archive",
|
|
11548
13718
|
" federation issuers list|create|archive | rules list|create|archive | token",
|
|
11549
13719
|
" elevate Confirm it's you for two hours (--browser | --paste)",
|
|
11550
13720
|
" apply Apply agents and environments from files",
|
|
13721
|
+
" eval Run an eval suite against an agent",
|
|
11551
13722
|
...feedbackHelpLines(),
|
|
11552
13723
|
"",
|
|
11553
13724
|
"Options:",
|
|
11554
13725
|
" -h, --help Show this help",
|
|
11555
13726
|
" -v, --version Show the version",
|
|
13727
|
+
" Run `nouter-platform <command> --help` for the help of one command.",
|
|
11556
13728
|
"",
|
|
11557
13729
|
"Environment:",
|
|
11558
13730
|
" NOUTER_PLATFORM_API_KEY API key; wins over the stored key and the federation",
|
|
@@ -11568,7 +13740,7 @@ function printHelp(deps) {
|
|
|
11568
13740
|
}
|
|
11569
13741
|
function manifestAt(path) {
|
|
11570
13742
|
try {
|
|
11571
|
-
return JSON.parse(
|
|
13743
|
+
return JSON.parse(readFileSync5(path, "utf8"));
|
|
11572
13744
|
} catch {
|
|
11573
13745
|
return null;
|
|
11574
13746
|
}
|
|
@@ -11584,7 +13756,7 @@ function sdkVersion() {
|
|
|
11584
13756
|
return "unknown";
|
|
11585
13757
|
}
|
|
11586
13758
|
for (let depth = 0; depth < 8; depth += 1) {
|
|
11587
|
-
const manifest = manifestAt(
|
|
13759
|
+
const manifest = manifestAt(join4(directory, "package.json"));
|
|
11588
13760
|
if (manifest?.name === "@nouter/platform" && typeof manifest.version === "string") return manifest.version;
|
|
11589
13761
|
const parent = dirname(directory);
|
|
11590
13762
|
if (parent === directory) break;
|
|
@@ -11601,7 +13773,14 @@ function usageError(command, deps) {
|
|
|
11601
13773
|
}
|
|
11602
13774
|
async function dispatch(argv, deps) {
|
|
11603
13775
|
const [command, ...rest] = argv;
|
|
11604
|
-
if (
|
|
13776
|
+
if (command === "help" || argv.includes("--help") || argv.includes("-h")) {
|
|
13777
|
+
return helpRequest(argv, {
|
|
13778
|
+
writeStdout: deps.writeStdout,
|
|
13779
|
+
writeStderr: deps.writeStderr,
|
|
13780
|
+
writeGlobalHelp: () => printHelp(deps)
|
|
13781
|
+
});
|
|
13782
|
+
}
|
|
13783
|
+
if (!command) {
|
|
11605
13784
|
printHelp(deps);
|
|
11606
13785
|
return 0;
|
|
11607
13786
|
}
|
|
@@ -11620,18 +13799,37 @@ async function dispatch(argv, deps) {
|
|
|
11620
13799
|
return await elevateCommand(rest, deps);
|
|
11621
13800
|
case "agents": {
|
|
11622
13801
|
const [subcommand, ...args] = rest;
|
|
11623
|
-
|
|
11624
|
-
|
|
11625
|
-
|
|
11626
|
-
|
|
11627
|
-
|
|
13802
|
+
if (subcommand === "list") {
|
|
13803
|
+
const jsonFlag = MANUAL_FLAGS["agents list"][0];
|
|
13804
|
+
const json = args.includes(jsonFlag) || rest.includes(jsonFlag);
|
|
13805
|
+
return await listAgents(deps, json);
|
|
13806
|
+
}
|
|
13807
|
+
if (subcommand === "get") {
|
|
13808
|
+
const options = parseOptions(args, specFor("agents get"));
|
|
13809
|
+
if (options.positionals.length > 1) throw new CliError("Usage: nouter-platform agents get <agent-id>");
|
|
13810
|
+
const id = options.positionals[0];
|
|
13811
|
+
if (id === void 0) return usageError("agents get <agent-id>", deps);
|
|
13812
|
+
return await getAgent(id, deps, options.booleans.has("--json"));
|
|
13813
|
+
}
|
|
13814
|
+
if (subcommand === "archive") return await archiveAgent(args, deps);
|
|
13815
|
+
return usageError("agents list|get <agent-id>|archive <agent-id>", deps);
|
|
11628
13816
|
}
|
|
11629
13817
|
case "environments": {
|
|
11630
13818
|
const [subcommand, ...args] = rest;
|
|
11631
|
-
|
|
11632
|
-
|
|
11633
|
-
|
|
11634
|
-
|
|
13819
|
+
if (subcommand === "list") {
|
|
13820
|
+
const jsonFlag = MANUAL_FLAGS["environments list"][0];
|
|
13821
|
+
const json = args.includes(jsonFlag) || rest.includes(jsonFlag);
|
|
13822
|
+
return await listEnvironments(deps, json);
|
|
13823
|
+
}
|
|
13824
|
+
if (subcommand === "get") {
|
|
13825
|
+
const options = parseOptions(args, specFor("environments get"));
|
|
13826
|
+
if (options.positionals.length > 1) {
|
|
13827
|
+
throw new CliError("Usage: nouter-platform environments get <environment-id>");
|
|
13828
|
+
}
|
|
13829
|
+
const id = options.positionals[0];
|
|
13830
|
+
if (id === void 0) return usageError("environments get <environment-id>", deps);
|
|
13831
|
+
return await getEnvironment(id, deps, options.booleans.has("--json"));
|
|
13832
|
+
}
|
|
11635
13833
|
return usageError("environments list|get <environment-id>", deps);
|
|
11636
13834
|
}
|
|
11637
13835
|
case "auth": {
|
|
@@ -11647,6 +13845,8 @@ async function dispatch(argv, deps) {
|
|
|
11647
13845
|
if (rest.length > 0) return usageError("version", deps);
|
|
11648
13846
|
deps.writeStdout(versionLine());
|
|
11649
13847
|
return 0;
|
|
13848
|
+
case "keys":
|
|
13849
|
+
return await keysCommand(rest, deps);
|
|
11650
13850
|
case "service-accounts":
|
|
11651
13851
|
return await serviceAccountsCommand(rest, deps);
|
|
11652
13852
|
case "federation": {
|
|
@@ -11658,6 +13858,13 @@ async function dispatch(argv, deps) {
|
|
|
11658
13858
|
}
|
|
11659
13859
|
case "apply":
|
|
11660
13860
|
return await applyCommand(rest, deps);
|
|
13861
|
+
case "eval":
|
|
13862
|
+
return await evalCommand(rest, {
|
|
13863
|
+
CliError,
|
|
13864
|
+
client: async () => clientFor(await resolveAuth(deps), deps),
|
|
13865
|
+
writeStdout: deps.writeStdout,
|
|
13866
|
+
writeStderr: deps.writeStderr
|
|
13867
|
+
});
|
|
11661
13868
|
case "feedback":
|
|
11662
13869
|
return await feedbackCommand(rest, {
|
|
11663
13870
|
CliError,
|
|
@@ -11682,7 +13889,7 @@ async function readAllStdin() {
|
|
|
11682
13889
|
async function readSecretFromTty() {
|
|
11683
13890
|
const stdin = process.stdin;
|
|
11684
13891
|
if (!stdin.isTTY) return await readAllStdin();
|
|
11685
|
-
return await new Promise((
|
|
13892
|
+
return await new Promise((resolve2) => {
|
|
11686
13893
|
const wasRaw = Boolean(stdin.isRaw);
|
|
11687
13894
|
stdin.setRawMode(true);
|
|
11688
13895
|
stdin.resume();
|
|
@@ -11693,7 +13900,7 @@ async function readSecretFromTty() {
|
|
|
11693
13900
|
stdin.pause();
|
|
11694
13901
|
stdin.removeListener("data", onData);
|
|
11695
13902
|
process.stdout.write("\n");
|
|
11696
|
-
|
|
13903
|
+
resolve2(result);
|
|
11697
13904
|
};
|
|
11698
13905
|
const onData = (chunk) => {
|
|
11699
13906
|
for (const char of chunk) {
|