@lobehub/cli 0.0.94 → 0.0.96
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/dist/acceptance-report.html +251 -251
- package/dist/index.js +905 -309
- package/man/man1/lh.1 +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { Buffer as Buffer$1 } from "node:buffer";
|
|
|
15
15
|
import * as net$1 from "node:net";
|
|
16
16
|
import net, { BlockList, connect, createServer, isIP } from "node:net";
|
|
17
17
|
import { scheduler, setImmediate as setImmediate$1, setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
18
|
-
import
|
|
18
|
+
import process$1, { cwd, execArgv, execPath, hrtime, platform as platform$1 } from "node:process";
|
|
19
19
|
import { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
|
|
20
20
|
import { finished, pipeline } from "node:stream/promises";
|
|
21
21
|
import { Duplex, PassThrough, Readable, Transform, Writable, getDefaultHighWaterMark, pipeline as pipeline$1 } from "node:stream";
|
|
@@ -8250,6 +8250,7 @@ var init_agentRuntime = __esmMin((() => {
|
|
|
8250
8250
|
RequestTrigger["Inbox"] = "inbox";
|
|
8251
8251
|
/** Chat input inline completion suggestions while the user is typing. */
|
|
8252
8252
|
RequestTrigger["InputCompletion"] = "input_completion";
|
|
8253
|
+
RequestTrigger["McpEvent"] = "mcp_event";
|
|
8253
8254
|
RequestTrigger["Memory"] = "memory";
|
|
8254
8255
|
RequestTrigger["MultimodalAnalysis"] = "multimodal_analysis";
|
|
8255
8256
|
/** Text-to-music generation from a music generation topic. */
|
|
@@ -11209,6 +11210,11 @@ var init_preference = __esmMin((() => {
|
|
|
11209
11210
|
uploadFileInKnowledgeBase: boolean().optional()
|
|
11210
11211
|
});
|
|
11211
11212
|
UserLabSchema = object$1({
|
|
11213
|
+
/**
|
|
11214
|
+
* one switch for the experiments that improve how agents write and work with
|
|
11215
|
+
* code; every coding-experience improvement reads this flag
|
|
11216
|
+
*/
|
|
11217
|
+
enableBetterCodingExperience: boolean().optional(),
|
|
11212
11218
|
/**
|
|
11213
11219
|
* enable agent identity: give an agent its own mail address
|
|
11214
11220
|
*/
|
|
@@ -12056,6 +12062,10 @@ var init_acceptanceReviewRound = __esmMin((() => {
|
|
|
12056
12062
|
});
|
|
12057
12063
|
}));
|
|
12058
12064
|
|
|
12065
|
+
//#endregion
|
|
12066
|
+
//#region ../../packages/types/src/artboard.ts
|
|
12067
|
+
var init_artboard = __esmMin((() => {}));
|
|
12068
|
+
|
|
12059
12069
|
//#endregion
|
|
12060
12070
|
//#region ../../packages/types/src/connector.ts
|
|
12061
12071
|
var init_connector = __esmMin((() => {}));
|
|
@@ -12067,7 +12077,8 @@ var init_inboundWebhook = __esmMin((() => {
|
|
|
12067
12077
|
init_zod$1();
|
|
12068
12078
|
McpEventsWebhookConfigSchema = object$1({
|
|
12069
12079
|
arguments: record(string(), unknown()),
|
|
12070
|
-
eventName: string().min(1)
|
|
12080
|
+
eventName: string().min(1),
|
|
12081
|
+
linkId: string().min(1).optional()
|
|
12071
12082
|
}).strict();
|
|
12072
12083
|
McpEventsWebhookStateSchema = object$1({
|
|
12073
12084
|
cursor: string().nullable().optional(),
|
|
@@ -12230,6 +12241,7 @@ var init_src$2 = __esmMin((() => {
|
|
|
12230
12241
|
init_acceptanceReview();
|
|
12231
12242
|
init_acceptanceReviewRound();
|
|
12232
12243
|
init_agentRuntime();
|
|
12244
|
+
init_artboard();
|
|
12233
12245
|
init_connector();
|
|
12234
12246
|
init_inboundWebhook();
|
|
12235
12247
|
init_oauthApp();
|
|
@@ -18101,6 +18113,7 @@ const TRPC_NAMESPACE_API_KEY_RULES = {
|
|
|
18101
18113
|
home: rw("chat:read", "chat:write"),
|
|
18102
18114
|
image: { any: "model:invoke" },
|
|
18103
18115
|
importer: "blocked",
|
|
18116
|
+
inboundWebhook: "blocked",
|
|
18104
18117
|
klavis: "blocked",
|
|
18105
18118
|
knowledge: rw("knowledge:read", "knowledge:write"),
|
|
18106
18119
|
knowledgeBase: rw("knowledge:read", "knowledge:write"),
|
|
@@ -21796,7 +21809,7 @@ var require_command = /* @__PURE__ */ __commonJSMin$2(((exports) => {
|
|
|
21796
21809
|
const childProcess$2 = __require("node:child_process");
|
|
21797
21810
|
const path$16 = __require("node:path");
|
|
21798
21811
|
const fs$17 = __require("node:fs");
|
|
21799
|
-
const process$
|
|
21812
|
+
const process$3 = __require("node:process");
|
|
21800
21813
|
const { Argument, humanReadableArgName } = require_argument();
|
|
21801
21814
|
const { CommanderError } = require_error$1();
|
|
21802
21815
|
const { Help, stripColor } = require_help();
|
|
@@ -21848,13 +21861,13 @@ var require_command = /* @__PURE__ */ __commonJSMin$2(((exports) => {
|
|
|
21848
21861
|
this._showSuggestionAfterError = true;
|
|
21849
21862
|
this._savedState = null;
|
|
21850
21863
|
this._outputConfiguration = {
|
|
21851
|
-
writeOut: (str) => process$
|
|
21852
|
-
writeErr: (str) => process$
|
|
21864
|
+
writeOut: (str) => process$3.stdout.write(str),
|
|
21865
|
+
writeErr: (str) => process$3.stderr.write(str),
|
|
21853
21866
|
outputError: (str, write) => write(str),
|
|
21854
|
-
getOutHelpWidth: () => process$
|
|
21855
|
-
getErrHelpWidth: () => process$
|
|
21856
|
-
getOutHasColors: () => useColor() ?? (process$
|
|
21857
|
-
getErrHasColors: () => useColor() ?? (process$
|
|
21867
|
+
getOutHelpWidth: () => process$3.stdout.isTTY ? process$3.stdout.columns : void 0,
|
|
21868
|
+
getErrHelpWidth: () => process$3.stderr.isTTY ? process$3.stderr.columns : void 0,
|
|
21869
|
+
getOutHasColors: () => useColor() ?? (process$3.stdout.isTTY && process$3.stdout.hasColors?.()),
|
|
21870
|
+
getErrHasColors: () => useColor() ?? (process$3.stderr.isTTY && process$3.stderr.hasColors?.()),
|
|
21858
21871
|
stripColor: (str) => stripColor(str)
|
|
21859
21872
|
};
|
|
21860
21873
|
this._hidden = false;
|
|
@@ -22212,7 +22225,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22212
22225
|
*/
|
|
22213
22226
|
_exit(exitCode, code, message) {
|
|
22214
22227
|
if (this._exitCallback) this._exitCallback(new CommanderError(exitCode, code, message));
|
|
22215
|
-
process$
|
|
22228
|
+
process$3.exit(exitCode);
|
|
22216
22229
|
}
|
|
22217
22230
|
/**
|
|
22218
22231
|
* Register callback `fn` for the command.
|
|
@@ -22551,11 +22564,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22551
22564
|
if (argv !== void 0 && !Array.isArray(argv)) throw new Error("first parameter to parse must be array or undefined");
|
|
22552
22565
|
parseOptions = parseOptions || {};
|
|
22553
22566
|
if (argv === void 0 && parseOptions.from === void 0) {
|
|
22554
|
-
if (process$
|
|
22555
|
-
const execArgv = process$
|
|
22567
|
+
if (process$3.versions?.electron) parseOptions.from = "electron";
|
|
22568
|
+
const execArgv = process$3.execArgv ?? [];
|
|
22556
22569
|
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) parseOptions.from = "eval";
|
|
22557
22570
|
}
|
|
22558
|
-
if (argv === void 0) argv = process$
|
|
22571
|
+
if (argv === void 0) argv = process$3.argv;
|
|
22559
22572
|
this.rawArgs = argv.slice();
|
|
22560
22573
|
let userArgs;
|
|
22561
22574
|
switch (parseOptions.from) {
|
|
@@ -22565,7 +22578,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22565
22578
|
userArgs = argv.slice(2);
|
|
22566
22579
|
break;
|
|
22567
22580
|
case "electron":
|
|
22568
|
-
if (process$
|
|
22581
|
+
if (process$3.defaultApp) {
|
|
22569
22582
|
this._scriptPath = argv[1];
|
|
22570
22583
|
userArgs = argv.slice(2);
|
|
22571
22584
|
} else userArgs = argv.slice(1);
|
|
@@ -22730,16 +22743,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22730
22743
|
}
|
|
22731
22744
|
launchWithNode = sourceExt.includes(path$16.extname(executableFile));
|
|
22732
22745
|
let proc;
|
|
22733
|
-
if (process$
|
|
22746
|
+
if (process$3.platform !== "win32") if (launchWithNode) {
|
|
22734
22747
|
args.unshift(executableFile);
|
|
22735
|
-
args = incrementNodeInspectorPort(process$
|
|
22736
|
-
proc = childProcess$2.spawn(process$
|
|
22748
|
+
args = incrementNodeInspectorPort(process$3.execArgv).concat(args);
|
|
22749
|
+
proc = childProcess$2.spawn(process$3.argv[0], args, { stdio: "inherit" });
|
|
22737
22750
|
} else proc = childProcess$2.spawn(executableFile, args, { stdio: "inherit" });
|
|
22738
22751
|
else {
|
|
22739
22752
|
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
22740
22753
|
args.unshift(executableFile);
|
|
22741
|
-
args = incrementNodeInspectorPort(process$
|
|
22742
|
-
proc = childProcess$2.spawn(process$
|
|
22754
|
+
args = incrementNodeInspectorPort(process$3.execArgv).concat(args);
|
|
22755
|
+
proc = childProcess$2.spawn(process$3.execPath, args, { stdio: "inherit" });
|
|
22743
22756
|
}
|
|
22744
22757
|
if (!proc.killed) [
|
|
22745
22758
|
"SIGUSR1",
|
|
@@ -22748,20 +22761,20 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
22748
22761
|
"SIGINT",
|
|
22749
22762
|
"SIGHUP"
|
|
22750
22763
|
].forEach((signal) => {
|
|
22751
|
-
process$
|
|
22764
|
+
process$3.on(signal, () => {
|
|
22752
22765
|
if (proc.killed === false && proc.exitCode === null) proc.kill(signal);
|
|
22753
22766
|
});
|
|
22754
22767
|
});
|
|
22755
22768
|
const exitCallback = this._exitCallback;
|
|
22756
22769
|
proc.on("close", (code) => {
|
|
22757
22770
|
code = code ?? 1;
|
|
22758
|
-
if (!exitCallback) process$
|
|
22771
|
+
if (!exitCallback) process$3.exit(code);
|
|
22759
22772
|
else exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
22760
22773
|
});
|
|
22761
22774
|
proc.on("error", (err) => {
|
|
22762
22775
|
if (err.code === "ENOENT") this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
22763
22776
|
else if (err.code === "EACCES") throw new Error(`'${executableFile}' not executable`);
|
|
22764
|
-
if (!exitCallback) process$
|
|
22777
|
+
if (!exitCallback) process$3.exit(1);
|
|
22765
22778
|
else {
|
|
22766
22779
|
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
22767
22780
|
wrappedError.nestedError = err;
|
|
@@ -23170,13 +23183,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
23170
23183
|
*/
|
|
23171
23184
|
_parseOptionsEnv() {
|
|
23172
23185
|
this.options.forEach((option) => {
|
|
23173
|
-
if (option.envVar && option.envVar in process$
|
|
23186
|
+
if (option.envVar && option.envVar in process$3.env) {
|
|
23174
23187
|
const optionKey = option.attributeName();
|
|
23175
23188
|
if (this.getOptionValue(optionKey) === void 0 || [
|
|
23176
23189
|
"default",
|
|
23177
23190
|
"config",
|
|
23178
23191
|
"env"
|
|
23179
|
-
].includes(this.getOptionValueSource(optionKey))) if (option.required || option.optional) this.emit(`optionEnv:${option.name()}`, process$
|
|
23192
|
+
].includes(this.getOptionValueSource(optionKey))) if (option.required || option.optional) this.emit(`optionEnv:${option.name()}`, process$3.env[option.envVar]);
|
|
23180
23193
|
else this.emit(`optionEnv:${option.name()}`);
|
|
23181
23194
|
}
|
|
23182
23195
|
});
|
|
@@ -23593,7 +23606,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
23593
23606
|
*/
|
|
23594
23607
|
help(contextOptions) {
|
|
23595
23608
|
this.outputHelp(contextOptions);
|
|
23596
|
-
let exitCode = Number(process$
|
|
23609
|
+
let exitCode = Number(process$3.exitCode ?? 0);
|
|
23597
23610
|
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) exitCode = 1;
|
|
23598
23611
|
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
23599
23612
|
}
|
|
@@ -23683,8 +23696,8 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
23683
23696
|
* @package
|
|
23684
23697
|
*/
|
|
23685
23698
|
function useColor() {
|
|
23686
|
-
if (process$
|
|
23687
|
-
if (process$
|
|
23699
|
+
if (process$3.env.NO_COLOR || process$3.env.FORCE_COLOR === "0" || process$3.env.FORCE_COLOR === "false") return false;
|
|
23700
|
+
if (process$3.env.FORCE_COLOR || process$3.env.CLICOLOR_FORCE !== void 0) return true;
|
|
23688
23701
|
}
|
|
23689
23702
|
exports.Command = Command;
|
|
23690
23703
|
exports.useColor = useColor;
|
|
@@ -24023,7 +24036,7 @@ const GOMS_KLM_TIMING_SECONDS = {
|
|
|
24023
24036
|
};
|
|
24024
24037
|
|
|
24025
24038
|
//#endregion
|
|
24026
|
-
//#region node_modules/.pnpm/@trpc+server@11.28.
|
|
24039
|
+
//#region node_modules/.pnpm/@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3/node_modules/@trpc/server/dist/observable-CodTG6Sf.mjs
|
|
24027
24040
|
/**
|
|
24028
24041
|
* Creates an observable. `subscribe` runs for each subscriber, and can
|
|
24029
24042
|
* return a function that cleans up when it unsubscribes.
|
|
@@ -24249,7 +24262,7 @@ function observableToAsyncIterable(observable, signal) {
|
|
|
24249
24262
|
}
|
|
24250
24263
|
|
|
24251
24264
|
//#endregion
|
|
24252
|
-
//#region node_modules/.pnpm/@trpc+server@11.28.
|
|
24265
|
+
//#region node_modules/.pnpm/@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3/node_modules/@trpc/server/dist/observable-BjUZYMQq.mjs
|
|
24253
24266
|
/**
|
|
24254
24267
|
* Shares one subscription to the source between all subscribers. It
|
|
24255
24268
|
* starts with the first subscriber and ends when the last unsubscribes.
|
|
@@ -24375,7 +24388,7 @@ function behaviorSubject(initialValue) {
|
|
|
24375
24388
|
}
|
|
24376
24389
|
|
|
24377
24390
|
//#endregion
|
|
24378
|
-
//#region node_modules/.pnpm/@trpc+client@11.28.
|
|
24391
|
+
//#region node_modules/.pnpm/@trpc+client@11.28.3_@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/splitLink-PFsRy7Mf.mjs
|
|
24379
24392
|
/** @internal */
|
|
24380
24393
|
function createChain(opts) {
|
|
24381
24394
|
return observable$1((observer) => {
|
|
@@ -24394,7 +24407,7 @@ function createChain(opts) {
|
|
|
24394
24407
|
}
|
|
24395
24408
|
|
|
24396
24409
|
//#endregion
|
|
24397
|
-
//#region node_modules/.pnpm/@trpc+client@11.28.
|
|
24410
|
+
//#region node_modules/.pnpm/@trpc+client@11.28.3_@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/objectSpread2-pyA4QVO4.mjs
|
|
24398
24411
|
function _typeof$1(o) {
|
|
24399
24412
|
"@babel/helpers - typeof";
|
|
24400
24413
|
return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -24448,7 +24461,7 @@ function _objectSpread2$1(e) {
|
|
|
24448
24461
|
}
|
|
24449
24462
|
|
|
24450
24463
|
//#endregion
|
|
24451
|
-
//#region node_modules/.pnpm/@trpc+server@11.28.
|
|
24464
|
+
//#region node_modules/.pnpm/@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3/node_modules/@trpc/server/dist/codes-BCsCCyMj.mjs
|
|
24452
24465
|
/**
|
|
24453
24466
|
* Check that value is object
|
|
24454
24467
|
* @internal
|
|
@@ -24511,7 +24524,7 @@ const retryableRpcCodes = [
|
|
|
24511
24524
|
];
|
|
24512
24525
|
|
|
24513
24526
|
//#endregion
|
|
24514
|
-
//#region node_modules/.pnpm/@trpc+server@11.28.
|
|
24527
|
+
//#region node_modules/.pnpm/@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3/node_modules/@trpc/server/dist/getErrorShape-CVrl8_-w.mjs
|
|
24515
24528
|
const noop$4 = () => {};
|
|
24516
24529
|
const freezeIfAvailable = (obj) => {
|
|
24517
24530
|
if (Object.freeze) Object.freeze(obj);
|
|
@@ -24616,7 +24629,7 @@ function _objectSpread2(e) {
|
|
|
24616
24629
|
}
|
|
24617
24630
|
|
|
24618
24631
|
//#endregion
|
|
24619
|
-
//#region node_modules/.pnpm/@trpc+server@11.28.
|
|
24632
|
+
//#region node_modules/.pnpm/@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3/node_modules/@trpc/server/dist/asyncGeneratorDelegate-BRQGtkYG.mjs
|
|
24620
24633
|
/** @internal */
|
|
24621
24634
|
function transformResultInner(response, transformer) {
|
|
24622
24635
|
if ("error" in response) {
|
|
@@ -24722,7 +24735,7 @@ AsyncGenerator$1.prototype["function" == typeof Symbol && Symbol.asyncIterator |
|
|
|
24722
24735
|
};
|
|
24723
24736
|
|
|
24724
24737
|
//#endregion
|
|
24725
|
-
//#region node_modules/.pnpm/@trpc+client@11.28.
|
|
24738
|
+
//#region node_modules/.pnpm/@trpc+client@11.28.3_@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/TRPCClientError-DE6-fd1n.mjs
|
|
24726
24739
|
/**
|
|
24727
24740
|
* Whether a value is a `TRPCClientError`, typed for a router or procedure.
|
|
24728
24741
|
* @see https://trpc.io/docs/client/vanilla/error-handling#catching-a-thrown-error
|
|
@@ -24778,7 +24791,7 @@ var TRPCClientError = class TRPCClientError extends Error {
|
|
|
24778
24791
|
};
|
|
24779
24792
|
|
|
24780
24793
|
//#endregion
|
|
24781
|
-
//#region node_modules/.pnpm/@trpc+client@11.28.
|
|
24794
|
+
//#region node_modules/.pnpm/@trpc+client@11.28.3_@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/unstable-internals.mjs
|
|
24782
24795
|
/**
|
|
24783
24796
|
* @internal
|
|
24784
24797
|
*/
|
|
@@ -24805,7 +24818,7 @@ function getTransformer(transformer) {
|
|
|
24805
24818
|
}
|
|
24806
24819
|
|
|
24807
24820
|
//#endregion
|
|
24808
|
-
//#region node_modules/.pnpm/@trpc+client@11.28.
|
|
24821
|
+
//#region node_modules/.pnpm/@trpc+client@11.28.3_@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/httpUtils-CtMuyl9j.mjs
|
|
24809
24822
|
const isFunction$1 = (fn) => typeof fn === "function";
|
|
24810
24823
|
/**
|
|
24811
24824
|
* The `fetch` to use: `customFetchImpl` if given, or else the global one.
|
|
@@ -24941,7 +24954,7 @@ async function httpRequest(opts) {
|
|
|
24941
24954
|
}
|
|
24942
24955
|
|
|
24943
24956
|
//#endregion
|
|
24944
|
-
//#region node_modules/.pnpm/@trpc+client@11.28.
|
|
24957
|
+
//#region node_modules/.pnpm/@trpc+client@11.28.3_@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/httpLink-B4UwXApa.mjs
|
|
24945
24958
|
/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */
|
|
24946
24959
|
function isOctetType(input) {
|
|
24947
24960
|
return input instanceof Uint8Array || input instanceof Blob;
|
|
@@ -25034,7 +25047,7 @@ function httpLink(opts) {
|
|
|
25034
25047
|
}
|
|
25035
25048
|
|
|
25036
25049
|
//#endregion
|
|
25037
|
-
//#region node_modules/.pnpm/@trpc+client@11.28.
|
|
25050
|
+
//#region node_modules/.pnpm/@trpc+client@11.28.3_@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/wsLink-BiIe_j6D.mjs
|
|
25038
25051
|
/**
|
|
25039
25052
|
* Get the result of a value or function that returns a value
|
|
25040
25053
|
* It also optionally accepts typesafe arguments for the function
|
|
@@ -25224,7 +25237,7 @@ var WsConnection = class WsConnection {
|
|
|
25224
25237
|
_defineProperty$1(WsConnection, "connectCount", 0);
|
|
25225
25238
|
|
|
25226
25239
|
//#endregion
|
|
25227
|
-
//#region node_modules/.pnpm/@trpc+client@11.28.
|
|
25240
|
+
//#region node_modules/.pnpm/@trpc+client@11.28.3_@trpc+server@11.28.3_@types+ws@8.18.2_typescript@6.0.3__typescript@6.0.3/node_modules/@trpc/client/dist/index.mjs
|
|
25228
25241
|
const observerKeys = [
|
|
25229
25242
|
"onStarted",
|
|
25230
25243
|
"onData",
|
|
@@ -26369,7 +26382,7 @@ const cliVersion = pkg.version;
|
|
|
26369
26382
|
const cliNodeEngine = pkg.engines?.node;
|
|
26370
26383
|
|
|
26371
26384
|
//#endregion
|
|
26372
|
-
//#region ../../node_modules/.pnpm/@trpc+server@11.28.
|
|
26385
|
+
//#region ../../node_modules/.pnpm/@trpc+server@11.28.3_@types+aws-lambda@8.10.164_@types+express@5.0.6_@types+ws@8.18.2_n_4faacf2dd8c5d7e32e12b289867122f6/node_modules/@trpc/server/dist/observable-CodTG6Sf.mjs
|
|
26373
26386
|
/**
|
|
26374
26387
|
* Creates an observable. `subscribe` runs for each subscriber, and can
|
|
26375
26388
|
* return a function that cleans up when it unsubscribes.
|
|
@@ -46559,7 +46572,7 @@ const ACCOUNT_KINDS = [
|
|
|
46559
46572
|
"wallet",
|
|
46560
46573
|
"service"
|
|
46561
46574
|
];
|
|
46562
|
-
const parseKind = (value) => {
|
|
46575
|
+
const parseKind$1 = (value) => {
|
|
46563
46576
|
if (!ACCOUNT_KINDS.includes(value)) throw new Error(`Unknown account kind: ${value}. Valid values: ${ACCOUNT_KINDS.join(", ")}.`);
|
|
46564
46577
|
return value;
|
|
46565
46578
|
};
|
|
@@ -46622,7 +46635,7 @@ const fenceUntrusted = (body) => [
|
|
|
46622
46635
|
].join("\n");
|
|
46623
46636
|
function registerAgentAccountCommand(agent) {
|
|
46624
46637
|
const account = agent.command("account").description("Manage the addresses an agent owns (its mail inbox, mounted logins)");
|
|
46625
|
-
account.command("list [agentId]").description("List an agent's accounts (or every account in scope with --all)").option("-s, --slug <slug>", "Agent slug").option("--all", "List accounts of every agent in scope").option("-k, --kind <kind>", `Filter by kind (${ACCOUNT_KINDS.join(", ")})`, parseKind).option("-p, --provider <provider>", "Filter by provider (e.g. agent-mail)").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(async (agentIdArg, options) => {
|
|
46638
|
+
account.command("list [agentId]").description("List an agent's accounts (or every account in scope with --all)").option("-s, --slug <slug>", "Agent slug").option("--all", "List accounts of every agent in scope").option("-k, --kind <kind>", `Filter by kind (${ACCOUNT_KINDS.join(", ")})`, parseKind$1).option("-p, --provider <provider>", "Filter by provider (e.g. agent-mail)").option("--json [fields]", "Output JSON, optionally specify fields (comma-separated)").action(async (agentIdArg, options) => {
|
|
46626
46639
|
const client = await getTrpcClient();
|
|
46627
46640
|
const agentId = options.all ? void 0 : await resolveAgentId$1(client, {
|
|
46628
46641
|
agentId: agentIdArg,
|
|
@@ -46702,7 +46715,7 @@ function registerAgentAccountCommand(agent) {
|
|
|
46702
46715
|
}
|
|
46703
46716
|
console.log(`${import_picocolors.default.green("✓")} Issued ${import_picocolors.default.bold(item.identifier)} ${import_picocolors.default.dim(item.id)}`);
|
|
46704
46717
|
});
|
|
46705
|
-
account.command("mount [agentId]").description("Attach an account the user already holds (e.g. a login). Provider-issued accounts go through `provision`.").option("-s, --slug <slug>", "Agent slug").requiredOption("-i, --identifier <identifier>", "Handle the outside world knows it by").requiredOption("-k, --kind <kind>", `Account kind (${ACCOUNT_KINDS.join(", ")})`, parseKind).option("-p, --provider <provider>", "Provider name", "user").option("-c, --capabilities <list>", "Comma-separated capabilities: receive, send, login, sign", parseCapabilities).option("-n, --display-name <name>", "Display name").option("--metadata-file <path>", "JSON object of non-secret metadata (\"-\" for stdin)").option("--json", "Output JSON").action(async (agentIdArg, options) => {
|
|
46718
|
+
account.command("mount [agentId]").description("Attach an account the user already holds (e.g. a login). Provider-issued accounts go through `provision`.").option("-s, --slug <slug>", "Agent slug").requiredOption("-i, --identifier <identifier>", "Handle the outside world knows it by").requiredOption("-k, --kind <kind>", `Account kind (${ACCOUNT_KINDS.join(", ")})`, parseKind$1).option("-p, --provider <provider>", "Provider name", "user").option("-c, --capabilities <list>", "Comma-separated capabilities: receive, send, login, sign", parseCapabilities).option("-n, --display-name <name>", "Display name").option("--metadata-file <path>", "JSON object of non-secret metadata (\"-\" for stdin)").option("--json", "Output JSON").action(async (agentIdArg, options) => {
|
|
46706
46719
|
const client = await getTrpcClient();
|
|
46707
46720
|
const agentId = await resolveAgentId$1(client, {
|
|
46708
46721
|
agentId: agentIdArg,
|
|
@@ -72380,6 +72393,259 @@ const prepareClaudeCodeLobeHubCli = async (prompt, args = [], options = {}) => {
|
|
|
72380
72393
|
};
|
|
72381
72394
|
};
|
|
72382
72395
|
|
|
72396
|
+
//#endregion
|
|
72397
|
+
//#region ../../packages/heterogeneous-agents/src/spawn/claudeCodeLiveInput.ts
|
|
72398
|
+
/**
|
|
72399
|
+
* How long the session may sit between turns with no stdout before stdin is
|
|
72400
|
+
* closed anyway. Background tasks that stream (sub-agents) keep resetting it;
|
|
72401
|
+
* a silent one (a long background shell) would otherwise hold the process open
|
|
72402
|
+
* forever, since Claude Code's own wind-down ceiling only starts once stdin is
|
|
72403
|
+
* closed.
|
|
72404
|
+
*/
|
|
72405
|
+
const DEFAULT_IDLE_CLOSE_MS = 1800 * 1e3;
|
|
72406
|
+
/**
|
|
72407
|
+
* How long a task that ends between turns may wait for the main-agent turn its
|
|
72408
|
+
* notification wakes. Claude Code opens that turn within milliseconds; the
|
|
72409
|
+
* grace only bounds an end that wakes nothing, such as a task killed between
|
|
72410
|
+
* turns.
|
|
72411
|
+
*/
|
|
72412
|
+
const DEFAULT_WAKE_UP_GRACE_MS = 30 * 1e3;
|
|
72413
|
+
const TERMINAL_TASK_STATUSES = new Set([
|
|
72414
|
+
"completed",
|
|
72415
|
+
"failed",
|
|
72416
|
+
"killed"
|
|
72417
|
+
]);
|
|
72418
|
+
const readIdleCloseMs = () => {
|
|
72419
|
+
const value = Number(process.env.LOBE_CLAUDE_CODE_LIVE_INPUT_IDLE_MS);
|
|
72420
|
+
return Number.isFinite(value) && value > 0 ? value : DEFAULT_IDLE_CLOSE_MS;
|
|
72421
|
+
};
|
|
72422
|
+
/** Stamp a stream-json `user` line with the uuid Claude Code replays it under. */
|
|
72423
|
+
const withUserMessageUuid = (stdinLine, uuid) => `${JSON.stringify({
|
|
72424
|
+
...JSON.parse(stdinLine),
|
|
72425
|
+
uuid
|
|
72426
|
+
})}\n`;
|
|
72427
|
+
const isAbortedResult = (message) => !!message.is_error && String(message.terminal_reason ?? "").startsWith("aborted");
|
|
72428
|
+
const SESSION_ENDED = {
|
|
72429
|
+
error: "The session ended before answering",
|
|
72430
|
+
subtype: "error"
|
|
72431
|
+
};
|
|
72432
|
+
/**
|
|
72433
|
+
* Keeps a Claude Code print-mode (`-p --input-format stream-json`) stdin open
|
|
72434
|
+
* for as long as the run can still use input, so the host can deliver a user
|
|
72435
|
+
* message into the running session or interrupt only the current turn.
|
|
72436
|
+
*
|
|
72437
|
+
* Closing stdin early is not neutral: once input is closed, print mode stops
|
|
72438
|
+
* waiting for background tasks after `CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS`
|
|
72439
|
+
* (10 minutes by default) and kills them. So stdin stays open until the session
|
|
72440
|
+
* is between turns with no running task and no delivered message it has not
|
|
72441
|
+
* picked up yet.
|
|
72442
|
+
*
|
|
72443
|
+
* A task that ends between turns does not make the session idle: its
|
|
72444
|
+
* notification wakes the main agent for a turn, and that turn can start a new
|
|
72445
|
+
* task or resume a finished sub-agent with `SendMessage`. Closing at the end
|
|
72446
|
+
* would put those tasks under the ceiling, so the decision waits for the
|
|
72447
|
+
* wake-up turn's result.
|
|
72448
|
+
*
|
|
72449
|
+
* Requires `--replay-user-messages`: the replayed `uuid` is how a delivered
|
|
72450
|
+
* message is known to have been picked up.
|
|
72451
|
+
*/
|
|
72452
|
+
var ClaudeCodeLiveInput = class {
|
|
72453
|
+
activeTasks = /* @__PURE__ */ new Set();
|
|
72454
|
+
closed = false;
|
|
72455
|
+
idleTimer;
|
|
72456
|
+
idleCloseMs;
|
|
72457
|
+
lastOutcome;
|
|
72458
|
+
lineBuffer = "";
|
|
72459
|
+
pendingControl = /* @__PURE__ */ new Map();
|
|
72460
|
+
turnOpen = true;
|
|
72461
|
+
unconsumed = /* @__PURE__ */ new Set();
|
|
72462
|
+
wakeUpGraceMs;
|
|
72463
|
+
wakeUpTimer;
|
|
72464
|
+
constructor(stdin, options = {}) {
|
|
72465
|
+
this.stdin = stdin;
|
|
72466
|
+
this.idleCloseMs = options.idleCloseMs ?? readIdleCloseMs();
|
|
72467
|
+
this.wakeUpGraceMs = options.wakeUpGraceMs ?? DEFAULT_WAKE_UP_GRACE_MS;
|
|
72468
|
+
stdin.on("error", () => this.markClosed());
|
|
72469
|
+
stdin.on("close", () => this.markClosed());
|
|
72470
|
+
}
|
|
72471
|
+
get isOpen() {
|
|
72472
|
+
return !this.closed;
|
|
72473
|
+
}
|
|
72474
|
+
/** How the last turn ended; undefined while the session has not finished one. */
|
|
72475
|
+
get lastTurn() {
|
|
72476
|
+
return this.lastOutcome;
|
|
72477
|
+
}
|
|
72478
|
+
/**
|
|
72479
|
+
* Deliver a `user` line into the session; it stays pending until Claude Code
|
|
72480
|
+
* replays it. Returns false once input has closed.
|
|
72481
|
+
*/
|
|
72482
|
+
send(stdinLine, uuid = randomUUID()) {
|
|
72483
|
+
if (this.closed) return false;
|
|
72484
|
+
this.unconsumed.add(uuid);
|
|
72485
|
+
this.clearIdleTimer();
|
|
72486
|
+
this.stdin.write(withUserMessageUuid(stdinLine, uuid));
|
|
72487
|
+
return true;
|
|
72488
|
+
}
|
|
72489
|
+
/** Stop the current turn without ending the process. Returns false once input has closed. */
|
|
72490
|
+
interrupt() {
|
|
72491
|
+
return !!this.sendControlRequest({ subtype: "interrupt" });
|
|
72492
|
+
}
|
|
72493
|
+
/**
|
|
72494
|
+
* Write a stream-json `control_request` into the session — the protocol
|
|
72495
|
+
* Claude Code's SDK uses to steer a live process (interrupt, stop a task,
|
|
72496
|
+
* change the model…).
|
|
72497
|
+
*
|
|
72498
|
+
* @returns the request and its answer, or `undefined` once input has closed
|
|
72499
|
+
*/
|
|
72500
|
+
sendControlRequest(request) {
|
|
72501
|
+
if (this.closed) return;
|
|
72502
|
+
const requestId = randomUUID();
|
|
72503
|
+
const response = new Promise((resolve) => {
|
|
72504
|
+
this.pendingControl.set(requestId, resolve);
|
|
72505
|
+
});
|
|
72506
|
+
this.stdin.write(`${JSON.stringify({
|
|
72507
|
+
request,
|
|
72508
|
+
request_id: requestId,
|
|
72509
|
+
type: "control_request"
|
|
72510
|
+
})}\n`);
|
|
72511
|
+
return {
|
|
72512
|
+
requestId,
|
|
72513
|
+
response
|
|
72514
|
+
};
|
|
72515
|
+
}
|
|
72516
|
+
/** Feed raw stdout so the session state tracks what Claude Code reports. */
|
|
72517
|
+
observe(chunk) {
|
|
72518
|
+
this.lineBuffer += chunk.toString();
|
|
72519
|
+
const lines = this.lineBuffer.split("\n");
|
|
72520
|
+
this.lineBuffer = lines.pop() ?? "";
|
|
72521
|
+
for (const line of lines) {
|
|
72522
|
+
if (!line.trim()) continue;
|
|
72523
|
+
try {
|
|
72524
|
+
const message = JSON.parse(line);
|
|
72525
|
+
if (message?.type === "result") this.lastOutcome = {
|
|
72526
|
+
aborted: isAbortedResult(message),
|
|
72527
|
+
terminalReason: message.terminal_reason
|
|
72528
|
+
};
|
|
72529
|
+
this.observeMessage(message);
|
|
72530
|
+
} catch {}
|
|
72531
|
+
}
|
|
72532
|
+
if (this.closed) return;
|
|
72533
|
+
if (this.turnOpen) this.clearIdleTimer();
|
|
72534
|
+
else this.armIdleTimer();
|
|
72535
|
+
}
|
|
72536
|
+
/**
|
|
72537
|
+
* stdout ended: take a final record left without a trailing newline, then
|
|
72538
|
+
* close input, since nothing can read it any more.
|
|
72539
|
+
*/
|
|
72540
|
+
finish() {
|
|
72541
|
+
if (this.lineBuffer.trim()) this.observe("\n");
|
|
72542
|
+
this.close();
|
|
72543
|
+
for (const resolve of this.pendingControl.values()) resolve(SESSION_ENDED);
|
|
72544
|
+
this.pendingControl.clear();
|
|
72545
|
+
}
|
|
72546
|
+
close() {
|
|
72547
|
+
if (this.closed) return;
|
|
72548
|
+
this.markClosed();
|
|
72549
|
+
this.stdin.end();
|
|
72550
|
+
}
|
|
72551
|
+
observeMessage(message) {
|
|
72552
|
+
if (message?.type === "control_response") {
|
|
72553
|
+
this.observeControlResponse(message.response);
|
|
72554
|
+
return;
|
|
72555
|
+
}
|
|
72556
|
+
if (message?.parent_tool_use_id && message.type !== "system") return;
|
|
72557
|
+
switch (message?.type) {
|
|
72558
|
+
case "user":
|
|
72559
|
+
if (message.isReplay && typeof message.uuid === "string") {
|
|
72560
|
+
this.unconsumed.delete(message.uuid);
|
|
72561
|
+
this.openTurn();
|
|
72562
|
+
}
|
|
72563
|
+
return;
|
|
72564
|
+
case "assistant":
|
|
72565
|
+
case "stream_event":
|
|
72566
|
+
this.openTurn();
|
|
72567
|
+
return;
|
|
72568
|
+
case "system":
|
|
72569
|
+
this.observeSystem(message);
|
|
72570
|
+
return;
|
|
72571
|
+
case "result":
|
|
72572
|
+
this.turnOpen = false;
|
|
72573
|
+
if (message.is_error && !isAbortedResult(message)) this.close();
|
|
72574
|
+
else this.closeIfIdle();
|
|
72575
|
+
return;
|
|
72576
|
+
}
|
|
72577
|
+
}
|
|
72578
|
+
/** Answers arrive even after input closed, for requests written before. */
|
|
72579
|
+
observeControlResponse(response) {
|
|
72580
|
+
const requestId = response?.request_id;
|
|
72581
|
+
const resolve = typeof requestId === "string" && this.pendingControl.get(requestId);
|
|
72582
|
+
if (!resolve) return;
|
|
72583
|
+
this.pendingControl.delete(requestId);
|
|
72584
|
+
resolve(response.subtype === "success" ? {
|
|
72585
|
+
response: response.response ?? void 0,
|
|
72586
|
+
subtype: "success"
|
|
72587
|
+
} : {
|
|
72588
|
+
error: String(response.error ?? "Control request failed"),
|
|
72589
|
+
subtype: "error"
|
|
72590
|
+
});
|
|
72591
|
+
}
|
|
72592
|
+
observeSystem(message) {
|
|
72593
|
+
if (message.subtype === "init") {
|
|
72594
|
+
this.openTurn();
|
|
72595
|
+
return;
|
|
72596
|
+
}
|
|
72597
|
+
if (message.subtype === "task_started" && message.task_id) {
|
|
72598
|
+
this.activeTasks.add(message.task_id);
|
|
72599
|
+
return;
|
|
72600
|
+
}
|
|
72601
|
+
if ((message.subtype === "task_notification" || message.subtype === "task_updated" && TERMINAL_TASK_STATUSES.has(message.patch?.status)) && message.task_id) {
|
|
72602
|
+
this.activeTasks.delete(message.task_id);
|
|
72603
|
+
this.awaitWakeUpTurn();
|
|
72604
|
+
}
|
|
72605
|
+
}
|
|
72606
|
+
/** A newer turn supersedes how the last one ended until it reports its own. */
|
|
72607
|
+
openTurn() {
|
|
72608
|
+
this.turnOpen = true;
|
|
72609
|
+
this.lastOutcome = void 0;
|
|
72610
|
+
this.clearWakeUpTimer();
|
|
72611
|
+
}
|
|
72612
|
+
closeIfIdle() {
|
|
72613
|
+
if (this.turnOpen || this.activeTasks.size > 0 || this.unconsumed.size > 0) return;
|
|
72614
|
+
this.close();
|
|
72615
|
+
}
|
|
72616
|
+
/**
|
|
72617
|
+
* The last task ended between turns. The turn its notification wakes decides
|
|
72618
|
+
* at its result; close here only if no turn opens within the grace.
|
|
72619
|
+
*/
|
|
72620
|
+
awaitWakeUpTurn() {
|
|
72621
|
+
if (this.closed) return;
|
|
72622
|
+
if (this.turnOpen || this.activeTasks.size > 0 || this.unconsumed.size > 0) return;
|
|
72623
|
+
this.clearWakeUpTimer();
|
|
72624
|
+
this.wakeUpTimer = setTimeout(() => this.closeIfIdle(), this.wakeUpGraceMs);
|
|
72625
|
+
this.wakeUpTimer.unref?.();
|
|
72626
|
+
}
|
|
72627
|
+
clearWakeUpTimer() {
|
|
72628
|
+
if (!this.wakeUpTimer) return;
|
|
72629
|
+
clearTimeout(this.wakeUpTimer);
|
|
72630
|
+
this.wakeUpTimer = void 0;
|
|
72631
|
+
}
|
|
72632
|
+
armIdleTimer() {
|
|
72633
|
+
this.clearIdleTimer();
|
|
72634
|
+
this.idleTimer = setTimeout(() => this.close(), this.idleCloseMs);
|
|
72635
|
+
this.idleTimer.unref?.();
|
|
72636
|
+
}
|
|
72637
|
+
clearIdleTimer() {
|
|
72638
|
+
if (!this.idleTimer) return;
|
|
72639
|
+
clearTimeout(this.idleTimer);
|
|
72640
|
+
this.idleTimer = void 0;
|
|
72641
|
+
}
|
|
72642
|
+
markClosed() {
|
|
72643
|
+
this.closed = true;
|
|
72644
|
+
this.clearIdleTimer();
|
|
72645
|
+
this.clearWakeUpTimer();
|
|
72646
|
+
}
|
|
72647
|
+
};
|
|
72648
|
+
|
|
72383
72649
|
//#endregion
|
|
72384
72650
|
//#region ../../packages/heterogeneous-agents/src/spawn/presetEnv.ts
|
|
72385
72651
|
/**
|
|
@@ -72792,217 +73058,6 @@ const spawnTraeAcpAgent = async (options) => {
|
|
|
72792
73058
|
return createAcpSpawnHandle(bridge, session, () => session.nativeSessionId);
|
|
72793
73059
|
};
|
|
72794
73060
|
|
|
72795
|
-
//#endregion
|
|
72796
|
-
//#region ../../packages/heterogeneous-agents/src/spawn/claudeCodeLiveInput.ts
|
|
72797
|
-
/**
|
|
72798
|
-
* How long the session may sit between turns with no stdout before stdin is
|
|
72799
|
-
* closed anyway. Background tasks that stream (sub-agents) keep resetting it;
|
|
72800
|
-
* a silent one (a long background shell) would otherwise hold the process open
|
|
72801
|
-
* forever, since Claude Code's own wind-down ceiling only starts once stdin is
|
|
72802
|
-
* closed.
|
|
72803
|
-
*/
|
|
72804
|
-
const DEFAULT_IDLE_CLOSE_MS = 1800 * 1e3;
|
|
72805
|
-
/**
|
|
72806
|
-
* How long a task that ends between turns may wait for the main-agent turn its
|
|
72807
|
-
* notification wakes. Claude Code opens that turn within milliseconds; the
|
|
72808
|
-
* grace only bounds an end that wakes nothing, such as a task killed between
|
|
72809
|
-
* turns.
|
|
72810
|
-
*/
|
|
72811
|
-
const DEFAULT_WAKE_UP_GRACE_MS = 30 * 1e3;
|
|
72812
|
-
const TERMINAL_TASK_STATUSES = new Set([
|
|
72813
|
-
"completed",
|
|
72814
|
-
"failed",
|
|
72815
|
-
"killed"
|
|
72816
|
-
]);
|
|
72817
|
-
const readIdleCloseMs = () => {
|
|
72818
|
-
const value = Number(process.env.LOBE_CLAUDE_CODE_LIVE_INPUT_IDLE_MS);
|
|
72819
|
-
return Number.isFinite(value) && value > 0 ? value : DEFAULT_IDLE_CLOSE_MS;
|
|
72820
|
-
};
|
|
72821
|
-
/** Stamp a stream-json `user` line with the uuid Claude Code replays it under. */
|
|
72822
|
-
const withUserMessageUuid = (stdinLine, uuid) => `${JSON.stringify({
|
|
72823
|
-
...JSON.parse(stdinLine),
|
|
72824
|
-
uuid
|
|
72825
|
-
})}\n`;
|
|
72826
|
-
const isAbortedResult = (message) => !!message.is_error && String(message.terminal_reason ?? "").startsWith("aborted");
|
|
72827
|
-
/**
|
|
72828
|
-
* Keeps a Claude Code print-mode (`-p --input-format stream-json`) stdin open
|
|
72829
|
-
* for as long as the run can still use input, so the host can deliver a user
|
|
72830
|
-
* message into the running session or interrupt only the current turn.
|
|
72831
|
-
*
|
|
72832
|
-
* Closing stdin early is not neutral: once input is closed, print mode stops
|
|
72833
|
-
* waiting for background tasks after `CLAUDE_CODE_PRINT_BG_WAIT_CEILING_MS`
|
|
72834
|
-
* (10 minutes by default) and kills them. So stdin stays open until the session
|
|
72835
|
-
* is between turns with no running task and no delivered message it has not
|
|
72836
|
-
* picked up yet.
|
|
72837
|
-
*
|
|
72838
|
-
* A task that ends between turns does not make the session idle: its
|
|
72839
|
-
* notification wakes the main agent for a turn, and that turn can start a new
|
|
72840
|
-
* task or resume a finished sub-agent with `SendMessage`. Closing at the end
|
|
72841
|
-
* would put those tasks under the ceiling, so the decision waits for the
|
|
72842
|
-
* wake-up turn's result.
|
|
72843
|
-
*
|
|
72844
|
-
* Requires `--replay-user-messages`: the replayed `uuid` is how a delivered
|
|
72845
|
-
* message is known to have been picked up.
|
|
72846
|
-
*/
|
|
72847
|
-
var ClaudeCodeLiveInput = class {
|
|
72848
|
-
activeTasks = /* @__PURE__ */ new Set();
|
|
72849
|
-
closed = false;
|
|
72850
|
-
idleTimer;
|
|
72851
|
-
idleCloseMs;
|
|
72852
|
-
lastOutcome;
|
|
72853
|
-
lineBuffer = "";
|
|
72854
|
-
turnOpen = true;
|
|
72855
|
-
unconsumed = /* @__PURE__ */ new Set();
|
|
72856
|
-
wakeUpGraceMs;
|
|
72857
|
-
wakeUpTimer;
|
|
72858
|
-
constructor(stdin, options = {}) {
|
|
72859
|
-
this.stdin = stdin;
|
|
72860
|
-
this.idleCloseMs = options.idleCloseMs ?? readIdleCloseMs();
|
|
72861
|
-
this.wakeUpGraceMs = options.wakeUpGraceMs ?? DEFAULT_WAKE_UP_GRACE_MS;
|
|
72862
|
-
stdin.on("error", () => this.markClosed());
|
|
72863
|
-
stdin.on("close", () => this.markClosed());
|
|
72864
|
-
}
|
|
72865
|
-
get isOpen() {
|
|
72866
|
-
return !this.closed;
|
|
72867
|
-
}
|
|
72868
|
-
/** How the last turn ended; undefined while the session has not finished one. */
|
|
72869
|
-
get lastTurn() {
|
|
72870
|
-
return this.lastOutcome;
|
|
72871
|
-
}
|
|
72872
|
-
/**
|
|
72873
|
-
* Deliver a `user` line into the session; it stays pending until Claude Code
|
|
72874
|
-
* replays it. Returns false once input has closed.
|
|
72875
|
-
*/
|
|
72876
|
-
send(stdinLine, uuid = randomUUID()) {
|
|
72877
|
-
if (this.closed) return false;
|
|
72878
|
-
this.unconsumed.add(uuid);
|
|
72879
|
-
this.clearIdleTimer();
|
|
72880
|
-
this.stdin.write(withUserMessageUuid(stdinLine, uuid));
|
|
72881
|
-
return true;
|
|
72882
|
-
}
|
|
72883
|
-
/** Stop the current turn without ending the process. Returns false once input has closed. */
|
|
72884
|
-
interrupt() {
|
|
72885
|
-
if (this.closed) return false;
|
|
72886
|
-
this.stdin.write(`${JSON.stringify({
|
|
72887
|
-
request: { subtype: "interrupt" },
|
|
72888
|
-
request_id: randomUUID(),
|
|
72889
|
-
type: "control_request"
|
|
72890
|
-
})}\n`);
|
|
72891
|
-
return true;
|
|
72892
|
-
}
|
|
72893
|
-
/** Feed raw stdout so the session state tracks what Claude Code reports. */
|
|
72894
|
-
observe(chunk) {
|
|
72895
|
-
this.lineBuffer += chunk.toString();
|
|
72896
|
-
const lines = this.lineBuffer.split("\n");
|
|
72897
|
-
this.lineBuffer = lines.pop() ?? "";
|
|
72898
|
-
for (const line of lines) {
|
|
72899
|
-
if (!line.trim()) continue;
|
|
72900
|
-
try {
|
|
72901
|
-
const message = JSON.parse(line);
|
|
72902
|
-
if (message?.type === "result") this.lastOutcome = {
|
|
72903
|
-
aborted: isAbortedResult(message),
|
|
72904
|
-
terminalReason: message.terminal_reason
|
|
72905
|
-
};
|
|
72906
|
-
this.observeMessage(message);
|
|
72907
|
-
} catch {}
|
|
72908
|
-
}
|
|
72909
|
-
if (this.closed) return;
|
|
72910
|
-
if (this.turnOpen) this.clearIdleTimer();
|
|
72911
|
-
else this.armIdleTimer();
|
|
72912
|
-
}
|
|
72913
|
-
/**
|
|
72914
|
-
* stdout ended: take a final record left without a trailing newline, then
|
|
72915
|
-
* close input, since nothing can read it any more.
|
|
72916
|
-
*/
|
|
72917
|
-
finish() {
|
|
72918
|
-
if (this.lineBuffer.trim()) this.observe("\n");
|
|
72919
|
-
this.close();
|
|
72920
|
-
}
|
|
72921
|
-
close() {
|
|
72922
|
-
if (this.closed) return;
|
|
72923
|
-
this.markClosed();
|
|
72924
|
-
this.stdin.end();
|
|
72925
|
-
}
|
|
72926
|
-
observeMessage(message) {
|
|
72927
|
-
if (message?.parent_tool_use_id && message.type !== "system") return;
|
|
72928
|
-
switch (message?.type) {
|
|
72929
|
-
case "user":
|
|
72930
|
-
if (message.isReplay && typeof message.uuid === "string") {
|
|
72931
|
-
this.unconsumed.delete(message.uuid);
|
|
72932
|
-
this.openTurn();
|
|
72933
|
-
}
|
|
72934
|
-
return;
|
|
72935
|
-
case "assistant":
|
|
72936
|
-
case "stream_event":
|
|
72937
|
-
this.openTurn();
|
|
72938
|
-
return;
|
|
72939
|
-
case "system":
|
|
72940
|
-
this.observeSystem(message);
|
|
72941
|
-
return;
|
|
72942
|
-
case "result":
|
|
72943
|
-
this.turnOpen = false;
|
|
72944
|
-
if (message.is_error && !isAbortedResult(message)) this.close();
|
|
72945
|
-
else this.closeIfIdle();
|
|
72946
|
-
return;
|
|
72947
|
-
}
|
|
72948
|
-
}
|
|
72949
|
-
observeSystem(message) {
|
|
72950
|
-
if (message.subtype === "init") {
|
|
72951
|
-
this.openTurn();
|
|
72952
|
-
return;
|
|
72953
|
-
}
|
|
72954
|
-
if (message.subtype === "task_started" && message.task_id) {
|
|
72955
|
-
this.activeTasks.add(message.task_id);
|
|
72956
|
-
return;
|
|
72957
|
-
}
|
|
72958
|
-
if ((message.subtype === "task_notification" || message.subtype === "task_updated" && TERMINAL_TASK_STATUSES.has(message.patch?.status)) && message.task_id) {
|
|
72959
|
-
this.activeTasks.delete(message.task_id);
|
|
72960
|
-
this.awaitWakeUpTurn();
|
|
72961
|
-
}
|
|
72962
|
-
}
|
|
72963
|
-
/** A newer turn supersedes how the last one ended until it reports its own. */
|
|
72964
|
-
openTurn() {
|
|
72965
|
-
this.turnOpen = true;
|
|
72966
|
-
this.lastOutcome = void 0;
|
|
72967
|
-
this.clearWakeUpTimer();
|
|
72968
|
-
}
|
|
72969
|
-
closeIfIdle() {
|
|
72970
|
-
if (this.turnOpen || this.activeTasks.size > 0 || this.unconsumed.size > 0) return;
|
|
72971
|
-
this.close();
|
|
72972
|
-
}
|
|
72973
|
-
/**
|
|
72974
|
-
* The last task ended between turns. The turn its notification wakes decides
|
|
72975
|
-
* at its result; close here only if no turn opens within the grace.
|
|
72976
|
-
*/
|
|
72977
|
-
awaitWakeUpTurn() {
|
|
72978
|
-
if (this.closed) return;
|
|
72979
|
-
if (this.turnOpen || this.activeTasks.size > 0 || this.unconsumed.size > 0) return;
|
|
72980
|
-
this.clearWakeUpTimer();
|
|
72981
|
-
this.wakeUpTimer = setTimeout(() => this.closeIfIdle(), this.wakeUpGraceMs);
|
|
72982
|
-
this.wakeUpTimer.unref?.();
|
|
72983
|
-
}
|
|
72984
|
-
clearWakeUpTimer() {
|
|
72985
|
-
if (!this.wakeUpTimer) return;
|
|
72986
|
-
clearTimeout(this.wakeUpTimer);
|
|
72987
|
-
this.wakeUpTimer = void 0;
|
|
72988
|
-
}
|
|
72989
|
-
armIdleTimer() {
|
|
72990
|
-
this.clearIdleTimer();
|
|
72991
|
-
this.idleTimer = setTimeout(() => this.close(), this.idleCloseMs);
|
|
72992
|
-
this.idleTimer.unref?.();
|
|
72993
|
-
}
|
|
72994
|
-
clearIdleTimer() {
|
|
72995
|
-
if (!this.idleTimer) return;
|
|
72996
|
-
clearTimeout(this.idleTimer);
|
|
72997
|
-
this.idleTimer = void 0;
|
|
72998
|
-
}
|
|
72999
|
-
markClosed() {
|
|
73000
|
-
this.closed = true;
|
|
73001
|
-
this.clearIdleTimer();
|
|
73002
|
-
this.clearWakeUpTimer();
|
|
73003
|
-
}
|
|
73004
|
-
};
|
|
73005
|
-
|
|
73006
73061
|
//#endregion
|
|
73007
73062
|
//#region ../../packages/heterogeneous-agents/src/spawn/spawnAgent.ts
|
|
73008
73063
|
init_config();
|
|
@@ -73419,6 +73474,7 @@ const spawnCliAgent = async (options, command, cwd, inputPlan, childEnv, codexJw
|
|
|
73419
73474
|
exit,
|
|
73420
73475
|
...live && {
|
|
73421
73476
|
interruptTurn: () => live.interrupt(),
|
|
73477
|
+
sendControlRequest: (request) => live.sendControlRequest(request),
|
|
73422
73478
|
sendUserMessage: async (prompt, sendOptions) => {
|
|
73423
73479
|
if (!live.isOpen) return false;
|
|
73424
73480
|
const plan = await buildAgentInput("claude-code", prompt, options.inputOptions);
|
|
@@ -330850,7 +330906,7 @@ var stdio_exports = /* @__PURE__ */ __exportAll$2({
|
|
|
330850
330906
|
function getDefaultEnvironment() {
|
|
330851
330907
|
const env = {};
|
|
330852
330908
|
for (const key of DEFAULT_INHERITED_ENV_VARS) {
|
|
330853
|
-
const value =
|
|
330909
|
+
const value = process$1.env[key];
|
|
330854
330910
|
if (value === void 0) continue;
|
|
330855
330911
|
if (value.startsWith("()")) continue;
|
|
330856
330912
|
env[key] = value;
|
|
@@ -330861,7 +330917,7 @@ var import_cross_spawn$1, DEFAULT_INHERITED_ENV_VARS, StdioClientTransport;
|
|
|
330861
330917
|
var init_stdio = __esmMin((() => {
|
|
330862
330918
|
init_src_CeKsbNLO();
|
|
330863
330919
|
import_cross_spawn$1 = /* @__PURE__ */ __toESM$2(require_cross_spawn(), 1);
|
|
330864
|
-
DEFAULT_INHERITED_ENV_VARS =
|
|
330920
|
+
DEFAULT_INHERITED_ENV_VARS = process$1.platform === "win32" ? [
|
|
330865
330921
|
"APPDATA",
|
|
330866
330922
|
"COMSPEC",
|
|
330867
330923
|
"HOMEDRIVE",
|
|
@@ -330918,7 +330974,7 @@ var init_stdio = __esmMin((() => {
|
|
|
330918
330974
|
this._serverParams.stderr ?? "inherit"
|
|
330919
330975
|
],
|
|
330920
330976
|
shell: false,
|
|
330921
|
-
windowsHide:
|
|
330977
|
+
windowsHide: process$1.platform === "win32",
|
|
330922
330978
|
cwd: this._serverParams.cwd
|
|
330923
330979
|
});
|
|
330924
330980
|
this._process.on("error", (error) => {
|
|
@@ -333952,9 +334008,9 @@ const getSubprocessResult = ({ stdout }) => {
|
|
|
333952
334008
|
//#region node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/utils/standard-stream.js
|
|
333953
334009
|
const isStandardStream = (stream) => STANDARD_STREAMS.includes(stream);
|
|
333954
334010
|
const STANDARD_STREAMS = [
|
|
333955
|
-
|
|
333956
|
-
|
|
333957
|
-
|
|
334011
|
+
process$1.stdin,
|
|
334012
|
+
process$1.stdout,
|
|
334013
|
+
process$1.stderr
|
|
333958
334014
|
];
|
|
333959
334015
|
const STANDARD_STREAMS_ALIASES = [
|
|
333960
334016
|
"stdin",
|
|
@@ -334079,9 +334135,9 @@ const NO_ESCAPE_REGEXP = /^[\w./-]+$/;
|
|
|
334079
334135
|
//#endregion
|
|
334080
334136
|
//#region node_modules/.pnpm/is-unicode-supported@2.1.0/node_modules/is-unicode-supported/index.js
|
|
334081
334137
|
function isUnicodeSupported() {
|
|
334082
|
-
const { env } =
|
|
334138
|
+
const { env } = process$1;
|
|
334083
334139
|
const { TERM, TERM_PROGRAM } = env;
|
|
334084
|
-
if (
|
|
334140
|
+
if (process$1.platform !== "win32") return TERM !== "linux";
|
|
334085
334141
|
return Boolean(env.WT_SESSION) || Boolean(env.TERMINUS_SUBLIME) || env.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
334086
334142
|
}
|
|
334087
334143
|
|
|
@@ -334616,7 +334672,7 @@ function traversePathUp(startPath) {
|
|
|
334616
334672
|
|
|
334617
334673
|
//#endregion
|
|
334618
334674
|
//#region node_modules/.pnpm/npm-run-path@6.0.0/node_modules/npm-run-path/index.js
|
|
334619
|
-
const npmRunPath = ({ cwd =
|
|
334675
|
+
const npmRunPath = ({ cwd = process$1.cwd(), path: pathOption = process$1.env[pathKey()], preferLocal = true, execPath = process$1.execPath, addExecPath = true } = {}) => {
|
|
334620
334676
|
const cwdPath = path.resolve(toPath(cwd));
|
|
334621
334677
|
const result = [];
|
|
334622
334678
|
const pathParts = pathOption.split(path.delimiter);
|
|
@@ -334634,7 +334690,7 @@ const applyExecPath = (result, pathParts, execPath, cwdPath) => {
|
|
|
334634
334690
|
const pathPart = path.resolve(cwdPath, toPath(execPath), "..");
|
|
334635
334691
|
if (!pathParts.includes(pathPart)) result.push(pathPart);
|
|
334636
334692
|
};
|
|
334637
|
-
const npmRunPathEnv = ({ env =
|
|
334693
|
+
const npmRunPathEnv = ({ env = process$1.env, ...options } = {}) => {
|
|
334638
334694
|
env = { ...env };
|
|
334639
334695
|
const pathName = pathKey({ env });
|
|
334640
334696
|
options.path = env[pathName];
|
|
@@ -335769,7 +335825,7 @@ const normalizeCwd = (cwd = getDefaultCwd()) => {
|
|
|
335769
335825
|
};
|
|
335770
335826
|
const getDefaultCwd = () => {
|
|
335771
335827
|
try {
|
|
335772
|
-
return
|
|
335828
|
+
return process$1.cwd();
|
|
335773
335829
|
} catch (error) {
|
|
335774
335830
|
error.message = `The current directory does not exist.\n${error.message}`;
|
|
335775
335831
|
throw error;
|
|
@@ -335805,7 +335861,7 @@ const normalizeOptions = (filePath, rawArguments, rawOptions) => {
|
|
|
335805
335861
|
options.killSignal = normalizeKillSignal(options.killSignal);
|
|
335806
335862
|
options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay);
|
|
335807
335863
|
options.lines = options.lines.map((lines, fdNumber) => lines && !BINARY_ENCODINGS.has(options.encoding) && options.buffer[fdNumber]);
|
|
335808
|
-
if (
|
|
335864
|
+
if (process$1.platform === "win32" && path.basename(file, ".exe") === "cmd") commandArguments.unshift("/q");
|
|
335809
335865
|
return {
|
|
335810
335866
|
file,
|
|
335811
335867
|
commandArguments,
|
|
@@ -335832,7 +335888,7 @@ const addDefaultOptions = ({ extendEnv = true, preferLocal = false, cwd, localDi
|
|
|
335832
335888
|
});
|
|
335833
335889
|
const getEnv = ({ env: envOption, extendEnv, preferLocal, node, localDirectory, nodePath }) => {
|
|
335834
335890
|
const env = extendEnv ? {
|
|
335835
|
-
...
|
|
335891
|
+
...process$1.env,
|
|
335836
335892
|
...envOption
|
|
335837
335893
|
} : envOption;
|
|
335838
335894
|
if (preferLocal || node) return npmRunPathEnv({
|
|
@@ -336834,12 +336890,12 @@ const guessStreamDirection = {
|
|
|
336834
336890
|
}
|
|
336835
336891
|
};
|
|
336836
336892
|
const getStandardStreamDirection = (value) => {
|
|
336837
|
-
if ([0,
|
|
336893
|
+
if ([0, process$1.stdin].includes(value)) return "input";
|
|
336838
336894
|
if ([
|
|
336839
336895
|
1,
|
|
336840
336896
|
2,
|
|
336841
|
-
|
|
336842
|
-
|
|
336897
|
+
process$1.stdout,
|
|
336898
|
+
process$1.stderr
|
|
336843
336899
|
].includes(value)) return "output";
|
|
336844
336900
|
};
|
|
336845
336901
|
const DEFAULT_DIRECTION = "output";
|
|
@@ -337903,9 +337959,9 @@ const addIpcMethods = (subprocess, { ipc }) => {
|
|
|
337903
337959
|
Object.assign(subprocess, getIpcMethods(subprocess, false, ipc));
|
|
337904
337960
|
};
|
|
337905
337961
|
const getIpcExport = () => {
|
|
337906
|
-
const anyProcess =
|
|
337962
|
+
const anyProcess = process$1;
|
|
337907
337963
|
const isSubprocess = true;
|
|
337908
|
-
const ipc =
|
|
337964
|
+
const ipc = process$1.channel !== void 0;
|
|
337909
337965
|
return {
|
|
337910
337966
|
...getIpcMethods(anyProcess, isSubprocess, ipc),
|
|
337911
337967
|
getCancelSignal: getCancelSignal$1.bind(void 0, {
|
|
@@ -338382,7 +338438,7 @@ var SignalExitFallback = class extends SignalExitBase {
|
|
|
338382
338438
|
};
|
|
338383
338439
|
var SignalExit = class extends SignalExitBase {
|
|
338384
338440
|
/* c8 ignore start */
|
|
338385
|
-
#hupSig = process$
|
|
338441
|
+
#hupSig = process$2.platform === "win32" ? "SIGINT" : "SIGHUP";
|
|
338386
338442
|
/* c8 ignore stop */
|
|
338387
338443
|
#emitter = new Emitter();
|
|
338388
338444
|
#process;
|
|
@@ -338477,8 +338533,8 @@ var SignalExit = class extends SignalExitBase {
|
|
|
338477
338533
|
} else return og.call(this.#process, ev, ...args);
|
|
338478
338534
|
}
|
|
338479
338535
|
};
|
|
338480
|
-
const process$
|
|
338481
|
-
const { onExit, load: load$1, unload } = signalExitWrap(processOk(process$
|
|
338536
|
+
const process$2 = globalThis.process;
|
|
338537
|
+
const { onExit, load: load$1, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());
|
|
338482
338538
|
|
|
338483
338539
|
//#endregion
|
|
338484
338540
|
//#region node_modules/.pnpm/execa@9.6.1/node_modules/execa/lib/terminate/cleanup.js
|
|
@@ -559529,6 +559585,71 @@ function registerGoalGraphEditCommands(goal) {
|
|
|
559529
559585
|
});
|
|
559530
559586
|
}
|
|
559531
559587
|
|
|
559588
|
+
//#endregion
|
|
559589
|
+
//#region src/commands/goal/graphGlyphs.ts
|
|
559590
|
+
/** The glyph `lh goal show` prints before each node of the graph. */
|
|
559591
|
+
const nodeIcon = {
|
|
559592
|
+
batch: "▦",
|
|
559593
|
+
dead_end: "✕",
|
|
559594
|
+
decision: "◆",
|
|
559595
|
+
experiment: "⚗",
|
|
559596
|
+
finding: "●",
|
|
559597
|
+
hazard: "⚠",
|
|
559598
|
+
pattern: "↻",
|
|
559599
|
+
problem: "◇",
|
|
559600
|
+
task: "▣",
|
|
559601
|
+
template: "▤",
|
|
559602
|
+
tool: "⚒"
|
|
559603
|
+
};
|
|
559604
|
+
/**
|
|
559605
|
+
* Every edge kind reads `source <kind> target`, so a row listing its INCOMING
|
|
559606
|
+
* edges by kind states the relationship backwards: an incoming `depends_on`
|
|
559607
|
+
* means the other node depends on THIS one, not the reverse. Render the inverse
|
|
559608
|
+
* verb instead, so each entry is a true sentence about the row it sits on.
|
|
559609
|
+
*/
|
|
559610
|
+
const inverseEdgeLabel = {
|
|
559611
|
+
answers: "answered by",
|
|
559612
|
+
confirms: "confirmed by",
|
|
559613
|
+
contains: "inside",
|
|
559614
|
+
contradicts: "contradicted by",
|
|
559615
|
+
decomposes: "part of",
|
|
559616
|
+
depends_on: "blocks",
|
|
559617
|
+
derived_from: "ancestor of",
|
|
559618
|
+
investigates: "investigated by",
|
|
559619
|
+
leads_to: "follows",
|
|
559620
|
+
produces: "produced by",
|
|
559621
|
+
refutes: "refuted by",
|
|
559622
|
+
supports: "supported by"
|
|
559623
|
+
};
|
|
559624
|
+
|
|
559625
|
+
//#endregion
|
|
559626
|
+
//#region ../../packages/const/src/goal.ts
|
|
559627
|
+
/**
|
|
559628
|
+
* The batch pattern-break gate's option ids. Shared by the server that opens the
|
|
559629
|
+
* gate and the client that localizes it, the same way `GOAL_CLARIFICATION_OPTION`
|
|
559630
|
+
* is; the human-facing labels live in the locale files, never in the payload.
|
|
559631
|
+
*/
|
|
559632
|
+
const GOAL_BATCH_BREAK_OPTION = {
|
|
559633
|
+
newClass: "new_class",
|
|
559634
|
+
revise: "revise"
|
|
559635
|
+
};
|
|
559636
|
+
/**
|
|
559637
|
+
* The release-approval gate's option ids. `revise` shares the pattern break's
|
|
559638
|
+
* id, but here the correction goes to the main Agent, whose rewritten plan
|
|
559639
|
+
* returns to the same review; the probes are not run again.
|
|
559640
|
+
*/
|
|
559641
|
+
const GOAL_BATCH_RELEASE_OPTION = {
|
|
559642
|
+
release: "release",
|
|
559643
|
+
revise: GOAL_BATCH_BREAK_OPTION.revise
|
|
559644
|
+
};
|
|
559645
|
+
/** Node kinds that are marks: Goal-wide, left by one Task for every later one. */
|
|
559646
|
+
const GOAL_MARK_KINDS = [
|
|
559647
|
+
"pattern",
|
|
559648
|
+
"tool",
|
|
559649
|
+
"hazard",
|
|
559650
|
+
"dead_end"
|
|
559651
|
+
];
|
|
559652
|
+
|
|
559532
559653
|
//#endregion
|
|
559533
559654
|
//#region src/commands/goal/reads.ts
|
|
559534
559655
|
/**
|
|
@@ -559571,6 +559692,86 @@ const goalReads = async () => {
|
|
|
559571
559692
|
};
|
|
559572
559693
|
};
|
|
559573
559694
|
|
|
559695
|
+
//#endregion
|
|
559696
|
+
//#region src/commands/goal/mark.ts
|
|
559697
|
+
const KINDS_HELP = `Kinds: ${GOAL_MARK_KINDS.join(", ")}.`;
|
|
559698
|
+
const parseKind = (kind) => {
|
|
559699
|
+
if (!GOAL_MARK_KINDS.includes(kind)) throw new Error(`Unknown mark kind "${kind}". ${KINDS_HELP}`);
|
|
559700
|
+
return kind;
|
|
559701
|
+
};
|
|
559702
|
+
const describeMark = (mark) => {
|
|
559703
|
+
const record = mark.confirms || mark.refutes ? `+${mark.confirms}/-${mark.refutes}` : import_picocolors.default.dim("unconfirmed");
|
|
559704
|
+
const retired = mark.status === "retired" ? import_picocolors.default.dim(" (retired)") : "";
|
|
559705
|
+
const lines = [`${import_picocolors.default.bold(`[${mark.kind}]`)} ${mark.title} ${record}${retired}`, import_picocolors.default.dim(` id: ${mark.id}`)];
|
|
559706
|
+
if (mark.description) lines.push(` ${mark.description.replaceAll("\n", "\n ")}`);
|
|
559707
|
+
return lines.join("\n");
|
|
559708
|
+
};
|
|
559709
|
+
/** Outside a Goal Task run there is no run to stand for, so the goal must be named. */
|
|
559710
|
+
const requireGoalId$1 = (goalId, command) => {
|
|
559711
|
+
if (!goalId) throw new Error(`Pass the goal id: \`lh goal ${command}\` outside a Goal Task run cannot tell which goal you mean.`);
|
|
559712
|
+
return goalId;
|
|
559713
|
+
};
|
|
559714
|
+
const RUN_ONLY = "Only a Goal Task run judges a mark: it records that this run relied on the mark. Run it from inside the Task run.";
|
|
559715
|
+
/**
|
|
559716
|
+
* Marks: the notes runs of one Goal leave for each other.
|
|
559717
|
+
*
|
|
559718
|
+
* Inside a Goal Task run (an operation token), every command acts for that
|
|
559719
|
+
* run's Goal and Task, so no ids are needed. With a person's login, `list`,
|
|
559720
|
+
* `add` and `retire` take the goal id; judging is for runs only.
|
|
559721
|
+
*/
|
|
559722
|
+
function registerGoalMarkCommands(goal) {
|
|
559723
|
+
const mark = goal.command("mark").summary("Notes runs of a goal leave for each other").description([
|
|
559724
|
+
"Marks are short notes one run of a goal leaves for every later run: a fix for a pitfall",
|
|
559725
|
+
"(pattern), a reusable script (tool), something not to touch (hazard), or an approach",
|
|
559726
|
+
"that failed (dead_end). Every Task run of the goal is handed the trusted ones.",
|
|
559727
|
+
KINDS_HELP
|
|
559728
|
+
].join("\n"));
|
|
559729
|
+
mark.command("add <kind> <title>").description(`Leave a mark for later runs. ${KINDS_HELP}`).option("-d, --description <text>", "The details: exact error, cause, fix, path, usage").option("--goal <id>", "The goal, when not run from inside one of its Task runs").action(async (kind, title, options) => {
|
|
559730
|
+
const input = {
|
|
559731
|
+
description: options.description,
|
|
559732
|
+
kind: parseKind(kind),
|
|
559733
|
+
title
|
|
559734
|
+
};
|
|
559735
|
+
const client = await getTrpcClient();
|
|
559736
|
+
const result = hasOperationToken() ? await client.goal.addMarkOperation.mutate(input) : await client.goal.addMark.mutate({
|
|
559737
|
+
...input,
|
|
559738
|
+
id: requireGoalId$1(options.goal, "mark add --goal <id>")
|
|
559739
|
+
});
|
|
559740
|
+
log$13.info(`Left ${input.kind} mark ${result.data.id}`);
|
|
559741
|
+
});
|
|
559742
|
+
mark.command("list [goal-id]").description("List the marks of a goal, newest first").option("--json", "Output JSON").action(async (goalId, options) => {
|
|
559743
|
+
const client = await getTrpcClient();
|
|
559744
|
+
const marks = hasOperationToken() ? (await client.goal.marksOperation.query()).data : (await client.goal.marks.query({ id: requireGoalId$1(goalId, "mark list <goal-id>") })).data;
|
|
559745
|
+
if (options.json) return outputJson(marks);
|
|
559746
|
+
if (marks.length === 0) return log$13.info("No marks yet.");
|
|
559747
|
+
console.log(marks.map(describeMark).join("\n\n"));
|
|
559748
|
+
});
|
|
559749
|
+
for (const [command, verdict, summary] of [[
|
|
559750
|
+
"confirm",
|
|
559751
|
+
"confirms",
|
|
559752
|
+
"Record that a mark this run relied on held"
|
|
559753
|
+
], [
|
|
559754
|
+
"refute",
|
|
559755
|
+
"refutes",
|
|
559756
|
+
"Record that a mark this run relied on was wrong"
|
|
559757
|
+
]]) mark.command(`${command} <mark-id>`).description(summary).action(async (markId) => {
|
|
559758
|
+
if (!hasOperationToken()) throw new Error(RUN_ONLY);
|
|
559759
|
+
const result = await (await getTrpcClient()).goal.judgeMarkOperation.mutate({
|
|
559760
|
+
markId,
|
|
559761
|
+
verdict
|
|
559762
|
+
});
|
|
559763
|
+
log$13.info(`Recorded: ${verdict} ${markId} (now +${result.data.confirms}/-${result.data.refutes})`);
|
|
559764
|
+
});
|
|
559765
|
+
mark.command("retire <goal-id> <mark-id>").description("Take a mark out of every later run; it stays on the goal graph").option("--reason <text>", "Why, kept on the audit trail").action(async (goalId, markId, options) => {
|
|
559766
|
+
const result = await (await getTrpcClient()).goal.retireMark.mutate({
|
|
559767
|
+
id: goalId,
|
|
559768
|
+
markId,
|
|
559769
|
+
reason: options.reason
|
|
559770
|
+
});
|
|
559771
|
+
log$13.info(result.message);
|
|
559772
|
+
});
|
|
559773
|
+
}
|
|
559774
|
+
|
|
559574
559775
|
//#endregion
|
|
559575
559776
|
//#region src/commands/goal/metric.ts
|
|
559576
559777
|
const comparisons = [
|
|
@@ -559665,6 +559866,345 @@ function registerGoalMetricCommands(goal) {
|
|
|
559665
559866
|
});
|
|
559666
559867
|
}
|
|
559667
559868
|
|
|
559869
|
+
//#endregion
|
|
559870
|
+
//#region ../../packages/utils/src/goalObjective.ts
|
|
559871
|
+
const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
559872
|
+
const numericMetrics = (value) => {
|
|
559873
|
+
if (!value || typeof value !== "object") return void 0;
|
|
559874
|
+
const entries = Object.entries(value).filter(([, v]) => isFiniteNumber(v));
|
|
559875
|
+
return entries.length > 0 ? Object.fromEntries(entries) : void 0;
|
|
559876
|
+
};
|
|
559877
|
+
const fromJson = (text) => {
|
|
559878
|
+
const candidates = text.match(/\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\}/g) ?? [];
|
|
559879
|
+
for (const raw of candidates.reverse()) try {
|
|
559880
|
+
const data = JSON.parse(raw);
|
|
559881
|
+
const score = isFiniteNumber(data.score) ? data.score : typeof data.score === "string" && data.score.trim() !== "" && Number.isFinite(Number(data.score)) ? Number(data.score) : void 0;
|
|
559882
|
+
if (score === void 0) continue;
|
|
559883
|
+
return {
|
|
559884
|
+
metrics: numericMetrics(data.metrics),
|
|
559885
|
+
score,
|
|
559886
|
+
summary: typeof data.summary === "string" && data.summary ? data.summary : void 0,
|
|
559887
|
+
valid: data.valid !== false
|
|
559888
|
+
};
|
|
559889
|
+
} catch {
|
|
559890
|
+
continue;
|
|
559891
|
+
}
|
|
559892
|
+
};
|
|
559893
|
+
const NUMBER = String.raw`[-+]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?`;
|
|
559894
|
+
/**
|
|
559895
|
+
* The score in an evaluator's output, or undefined when there is none.
|
|
559896
|
+
*
|
|
559897
|
+
* Accepted, most specific first: a JSON object with a numeric `score`
|
|
559898
|
+
* (optional `valid`, `summary`, `metrics`); a `TOTAL_SCORE <n>` line; a
|
|
559899
|
+
* `score: <n>` / `score = <n>` line; a last line that is a bare number. The
|
|
559900
|
+
* last match of a form wins, so a final result beats earlier progress output.
|
|
559901
|
+
*/
|
|
559902
|
+
const parseEvaluatorOutput = (output) => {
|
|
559903
|
+
const json = fromJson(output);
|
|
559904
|
+
if (json) return json;
|
|
559905
|
+
for (const pattern of [new RegExp(String.raw`^\s*TOTAL_SCORE\s+(${NUMBER})\s*$`, "gim"), new RegExp(String.raw`^\s*(?:final\s+)?score\s*[:=]\s*(${NUMBER})\s*$`, "gim")]) {
|
|
559906
|
+
const matches = [...output.matchAll(pattern)];
|
|
559907
|
+
if (matches.length > 0) return {
|
|
559908
|
+
score: Number(matches.at(-1)[1]),
|
|
559909
|
+
valid: true
|
|
559910
|
+
};
|
|
559911
|
+
}
|
|
559912
|
+
const last = output.trim().split("\n").at(-1)?.trim() ?? "";
|
|
559913
|
+
if (new RegExp(`^${NUMBER}$`).test(last)) return {
|
|
559914
|
+
score: Number(last),
|
|
559915
|
+
valid: true
|
|
559916
|
+
};
|
|
559917
|
+
};
|
|
559918
|
+
|
|
559919
|
+
//#endregion
|
|
559920
|
+
//#region src/commands/goal/objective.ts
|
|
559921
|
+
const DEFAULT_TIMEOUT_SECONDS = 1800;
|
|
559922
|
+
const OUTPUT_TAIL_LINES = 60;
|
|
559923
|
+
const LOCK_POLL_MS = 2e3;
|
|
559924
|
+
/** Only for locks written before a holder's deadline was recorded next to its pid. */
|
|
559925
|
+
const LOCK_STALE_GRACE_MS = 300;
|
|
559926
|
+
const formatScore = (value) => String(Number(value.toFixed(4)));
|
|
559927
|
+
const printLeaderboard = (board) => {
|
|
559928
|
+
const { direction, evaluator, title } = board.objective;
|
|
559929
|
+
console.log(`${import_picocolors.default.bold(title || "Objective")} — ${direction === "max" ? "higher" : "lower"} is better · evaluator: ${import_picocolors.default.dim(evaluator)}`);
|
|
559930
|
+
if (board.lanes.length === 0) return console.log(import_picocolors.default.dim(" No evaluation recorded yet."));
|
|
559931
|
+
board.lanes.forEach((lane, index) => {
|
|
559932
|
+
const you = lane.lane === board.you ? import_picocolors.default.cyan(" (your lane)") : "";
|
|
559933
|
+
console.log(` ${index + 1}. ${lane.title}${you} best ${import_picocolors.default.bold(formatScore(lane.best))} · latest ${formatScore(lane.latest)} · ${lane.evaluations} eval(s)`);
|
|
559934
|
+
});
|
|
559935
|
+
};
|
|
559936
|
+
/** Outside a Goal Task run there is no run to stand for, so the goal must be named. */
|
|
559937
|
+
const requireGoalId = (goalId, command) => {
|
|
559938
|
+
if (!goalId) throw new Error(`Pass the goal id: \`lh goal ${command}\` outside a Goal Task run cannot tell which goal you mean.`);
|
|
559939
|
+
return goalId;
|
|
559940
|
+
};
|
|
559941
|
+
const readLeaderboard = async (goalId) => {
|
|
559942
|
+
const client = await getTrpcClient();
|
|
559943
|
+
return hasOperationToken() ? (await client.goal.objectiveOperation.query()).data : (await client.goal.objective.query({ id: requireGoalId(goalId, "objective <goal-id>") })).data;
|
|
559944
|
+
};
|
|
559945
|
+
/**
|
|
559946
|
+
* One evaluation at a time per machine: evaluators are often heavy (a judge
|
|
559947
|
+
* that trains or replays a model), and lanes of one goal on the same host
|
|
559948
|
+
* would otherwise starve each other. A directory is the lock because `mkdir`
|
|
559949
|
+
* is atomic everywhere; a holder that died is detected by its pid or age.
|
|
559950
|
+
*/
|
|
559951
|
+
const withMachineLock = async (timeoutSeconds, run, { dir = path.join(tmpdir(), "lobehub-goal-evaluate.lock"), onWait = () => {}, pollMs = LOCK_POLL_MS } = {}) => {
|
|
559952
|
+
const owner = `${process.pid}-${Date.now().toString(36)}`;
|
|
559953
|
+
const staged = `${dir}.staging-${owner}`;
|
|
559954
|
+
let waited = false;
|
|
559955
|
+
for (;;) {
|
|
559956
|
+
await mkdir(staged, { recursive: true });
|
|
559957
|
+
await writeFile(path.join(staged, "pid"), String(process.pid));
|
|
559958
|
+
await writeFile(path.join(staged, "owner"), owner);
|
|
559959
|
+
await writeFile(path.join(staged, "deadline"), String(Date.now() + timeoutSeconds * 1e3));
|
|
559960
|
+
try {
|
|
559961
|
+
await rename(staged, dir);
|
|
559962
|
+
break;
|
|
559963
|
+
} catch (error) {
|
|
559964
|
+
await rm(staged, {
|
|
559965
|
+
force: true,
|
|
559966
|
+
recursive: true
|
|
559967
|
+
});
|
|
559968
|
+
const code = error.code;
|
|
559969
|
+
if (code !== "EEXIST" && code !== "ENOTEMPTY" && code !== "ENOTDIR") throw error;
|
|
559970
|
+
const holder = Number(await readFile(path.join(dir, "pid"), "utf8").catch(() => "0"));
|
|
559971
|
+
const deadline = Number(await readFile(path.join(dir, "deadline"), "utf8").catch(() => "0"));
|
|
559972
|
+
const age = Date.now() - (await stat(dir).catch(() => ({ mtimeMs: Date.now() }))).mtimeMs;
|
|
559973
|
+
const alive = holder > 0 && (() => {
|
|
559974
|
+
try {
|
|
559975
|
+
process.kill(holder, 0);
|
|
559976
|
+
return true;
|
|
559977
|
+
} catch {
|
|
559978
|
+
return false;
|
|
559979
|
+
}
|
|
559980
|
+
})();
|
|
559981
|
+
const expired = deadline > 0 ? Date.now() > deadline : age > LOCK_STALE_GRACE_MS * 1e3;
|
|
559982
|
+
if (!alive || expired) {
|
|
559983
|
+
await rm(dir, {
|
|
559984
|
+
force: true,
|
|
559985
|
+
recursive: true
|
|
559986
|
+
});
|
|
559987
|
+
continue;
|
|
559988
|
+
}
|
|
559989
|
+
if (!waited) onWait();
|
|
559990
|
+
waited = true;
|
|
559991
|
+
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
559992
|
+
}
|
|
559993
|
+
}
|
|
559994
|
+
try {
|
|
559995
|
+
return await run();
|
|
559996
|
+
} finally {
|
|
559997
|
+
if (await readFile(path.join(dir, "owner"), "utf8").catch(() => "") === owner) await rm(dir, {
|
|
559998
|
+
force: true,
|
|
559999
|
+
recursive: true
|
|
560000
|
+
});
|
|
560001
|
+
}
|
|
560002
|
+
};
|
|
560003
|
+
/** Hash of the working tree's committed state plus its uncommitted changes, in a git repo. */
|
|
560004
|
+
const workingTreeFingerprint = (cwd) => {
|
|
560005
|
+
const git = (...args) => spawnSync("git", args, {
|
|
560006
|
+
cwd,
|
|
560007
|
+
encoding: "utf8",
|
|
560008
|
+
maxBuffer: 64 * 1024 * 1024
|
|
560009
|
+
});
|
|
560010
|
+
const head = git("rev-parse", "HEAD");
|
|
560011
|
+
if (head.status !== 0) return void 0;
|
|
560012
|
+
const diff = git("diff", "HEAD");
|
|
560013
|
+
const untracked = git("ls-files", "--others", "--exclude-standard", "-z");
|
|
560014
|
+
return createHash("sha256").update(head.stdout).update(diff.stdout ?? "").update(untracked.stdout ?? "").digest("hex").slice(0, 16);
|
|
560015
|
+
};
|
|
560016
|
+
/**
|
|
560017
|
+
* Splits an evaluator command into an executable and its arguments.
|
|
560018
|
+
*
|
|
560019
|
+
* The evaluator string is stored on the goal and read back from the server, so other lane members
|
|
560020
|
+
* can write it. It is never handed to a shell: metacharacters stay literal, and only quoting (so
|
|
560021
|
+
* one argument can contain a space) keeps its meaning.
|
|
560022
|
+
*/
|
|
560023
|
+
const splitEvaluatorCommand = (command) => {
|
|
560024
|
+
const tokens = [];
|
|
560025
|
+
let current = "";
|
|
560026
|
+
let quoted;
|
|
560027
|
+
let started = false;
|
|
560028
|
+
for (const char of command) {
|
|
560029
|
+
if (quoted) {
|
|
560030
|
+
if (char === quoted) quoted = void 0;
|
|
560031
|
+
else current += char;
|
|
560032
|
+
continue;
|
|
560033
|
+
}
|
|
560034
|
+
if (char === "\"" || char === "'") {
|
|
560035
|
+
quoted = char;
|
|
560036
|
+
started = true;
|
|
560037
|
+
continue;
|
|
560038
|
+
}
|
|
560039
|
+
if (/\s/.test(char)) {
|
|
560040
|
+
if (started) tokens.push(current);
|
|
560041
|
+
current = "";
|
|
560042
|
+
started = false;
|
|
560043
|
+
continue;
|
|
560044
|
+
}
|
|
560045
|
+
current += char;
|
|
560046
|
+
started = true;
|
|
560047
|
+
}
|
|
560048
|
+
if (quoted) throw new Error(`Unbalanced ${quoted} in the evaluator command: ${command}`);
|
|
560049
|
+
if (started) tokens.push(current);
|
|
560050
|
+
return tokens;
|
|
560051
|
+
};
|
|
560052
|
+
/** Kills the evaluator and everything it started, not just the process we spawned. */
|
|
560053
|
+
const killEvaluatorTree = (child) => {
|
|
560054
|
+
const { pid } = child;
|
|
560055
|
+
if (pid && process.platform !== "win32") try {
|
|
560056
|
+
process.kill(-pid, "SIGKILL");
|
|
560057
|
+
return;
|
|
560058
|
+
} catch {}
|
|
560059
|
+
if (pid && process.platform === "win32") {
|
|
560060
|
+
if (spawnSync("taskkill", [
|
|
560061
|
+
"/pid",
|
|
560062
|
+
String(pid),
|
|
560063
|
+
"/T",
|
|
560064
|
+
"/F"
|
|
560065
|
+
]).status === 0) return;
|
|
560066
|
+
}
|
|
560067
|
+
try {
|
|
560068
|
+
child.kill("SIGKILL");
|
|
560069
|
+
} catch {}
|
|
560070
|
+
};
|
|
560071
|
+
/**
|
|
560072
|
+
* Run the evaluator in `cwd`; resolves with its combined output and whether it timed out.
|
|
560073
|
+
*
|
|
560074
|
+
* The timeout settles on its own: a helper that inherited stdout/stderr can keep the pipes open
|
|
560075
|
+
* long after the evaluator is gone, and waiting for `close` would hold the machine lock past the
|
|
560076
|
+
* deadline the user asked for.
|
|
560077
|
+
*/
|
|
560078
|
+
const runEvaluator = (command, cwd, timeoutSeconds) => new Promise((resolve) => {
|
|
560079
|
+
const [executable, ...args] = splitEvaluatorCommand(command);
|
|
560080
|
+
if (!executable) {
|
|
560081
|
+
resolve({
|
|
560082
|
+
code: null,
|
|
560083
|
+
output: "",
|
|
560084
|
+
timedOut: false
|
|
560085
|
+
});
|
|
560086
|
+
return;
|
|
560087
|
+
}
|
|
560088
|
+
const child = spawn(executable, args, {
|
|
560089
|
+
cwd,
|
|
560090
|
+
detached: process.platform !== "win32",
|
|
560091
|
+
shell: false,
|
|
560092
|
+
stdio: [
|
|
560093
|
+
"ignore",
|
|
560094
|
+
"pipe",
|
|
560095
|
+
"pipe"
|
|
560096
|
+
]
|
|
560097
|
+
});
|
|
560098
|
+
let output = "";
|
|
560099
|
+
let timedOut = false;
|
|
560100
|
+
let settled = false;
|
|
560101
|
+
const finish = (code) => {
|
|
560102
|
+
if (settled) return;
|
|
560103
|
+
settled = true;
|
|
560104
|
+
clearTimeout(timer);
|
|
560105
|
+
child.stdout.destroy();
|
|
560106
|
+
child.stderr.destroy();
|
|
560107
|
+
resolve({
|
|
560108
|
+
code,
|
|
560109
|
+
output,
|
|
560110
|
+
timedOut
|
|
560111
|
+
});
|
|
560112
|
+
};
|
|
560113
|
+
child.stdout.on("data", (chunk) => output += chunk);
|
|
560114
|
+
child.stderr.on("data", (chunk) => output += chunk);
|
|
560115
|
+
const timer = setTimeout(() => {
|
|
560116
|
+
timedOut = true;
|
|
560117
|
+
killEvaluatorTree(child);
|
|
560118
|
+
finish(null);
|
|
560119
|
+
}, timeoutSeconds * 1e3);
|
|
560120
|
+
child.on("error", (error) => {
|
|
560121
|
+
output += `${error.message}\n`;
|
|
560122
|
+
finish(null);
|
|
560123
|
+
});
|
|
560124
|
+
child.on("close", (code) => finish(code));
|
|
560125
|
+
});
|
|
560126
|
+
const tail = (text, lines) => text.trimEnd().split("\n").slice(-lines).join("\n");
|
|
560127
|
+
const printResult = (result) => {
|
|
560128
|
+
console.log("========================================");
|
|
560129
|
+
if (!result.valid) console.log(` Valid: ${import_picocolors.default.yellow("no (this evaluation does not count)")}`);
|
|
560130
|
+
console.log(` Score: ${import_picocolors.default.bold(formatScore(result.score))}`);
|
|
560131
|
+
if (result.summary) console.log(` Summary: ${result.summary}`);
|
|
560132
|
+
if (result.metrics) {
|
|
560133
|
+
console.log(" Metrics:");
|
|
560134
|
+
for (const [key, value] of Object.entries(result.metrics)) console.log(` ${key}: ${value}`);
|
|
560135
|
+
}
|
|
560136
|
+
console.log("========================================");
|
|
560137
|
+
};
|
|
560138
|
+
/**
|
|
560139
|
+
* Objectives: the score a goal optimises and the command that measures it.
|
|
560140
|
+
*
|
|
560141
|
+
* Inside a Goal Task run (an operation token) `evaluate` and `objective` act
|
|
560142
|
+
* for that run's goal and lane. With a person's login they take the goal id,
|
|
560143
|
+
* and an evaluation is recorded in the `manual` lane.
|
|
560144
|
+
*/
|
|
560145
|
+
function registerGoalObjectiveCommands(goal) {
|
|
560146
|
+
goal.command("set-objective <goal-id>").description("Set the score this goal optimises and the command that measures it").option("--evaluator <command>", "Command that prints the score, run in the working directory (no shell; quote arguments with spaces)").option("--direction <max|min>", "Whether higher or lower is better", "max").option("--key <key>", "Metric series key (default: objective)").option("--title <title>", "Name of the score").option("--timeout <seconds>", "Seconds before an evaluation is abandoned").option("--clear", "Remove the objective").action(async (goalId, options) => {
|
|
560147
|
+
if (!options.clear && !options.evaluator) throw new Error("Pass --evaluator <command>, or --clear to remove the objective.");
|
|
560148
|
+
if (options.direction !== "max" && options.direction !== "min") throw new Error("--direction must be max or min");
|
|
560149
|
+
const result = await (await getTrpcClient()).goal.setObjective.mutate({
|
|
560150
|
+
id: goalId,
|
|
560151
|
+
objective: options.clear ? null : {
|
|
560152
|
+
direction: options.direction,
|
|
560153
|
+
evaluator: options.evaluator,
|
|
560154
|
+
key: options.key,
|
|
560155
|
+
timeoutSeconds: options.timeout ? Number.parseInt(options.timeout, 10) : void 0,
|
|
560156
|
+
title: options.title
|
|
560157
|
+
}
|
|
560158
|
+
});
|
|
560159
|
+
log$13.info(result.message);
|
|
560160
|
+
});
|
|
560161
|
+
goal.command("objective [goal-id]").description("Show a goal's objective and the leaderboard of its lanes").option("--json", "Output JSON").action(async (goalId, options) => {
|
|
560162
|
+
const board = await readLeaderboard(goalId);
|
|
560163
|
+
if (options.json) return outputJson(board);
|
|
560164
|
+
if (!board) return log$13.info("This goal has no objective.");
|
|
560165
|
+
printLeaderboard(board);
|
|
560166
|
+
});
|
|
560167
|
+
goal.command("evaluate").description("Run the goal's evaluator in the current directory, record the score for your lane, and print it").option("-d, --details", "Also print the tail of the evaluator output").option("--goal <id>", "The goal, when not run from inside one of its Task runs").option("--timeout <seconds>", "Override the objective's evaluation timeout").action(async (options) => {
|
|
560168
|
+
const board = await readLeaderboard(options.goal);
|
|
560169
|
+
if (!board) throw new Error("This goal has no objective; set one with `lh goal set-objective`.");
|
|
560170
|
+
const timeoutSeconds = options.timeout ? Number.parseInt(options.timeout, 10) : board.objective.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS;
|
|
560171
|
+
const cwd = process.cwd();
|
|
560172
|
+
const started = Date.now();
|
|
560173
|
+
const run = await withMachineLock(timeoutSeconds, () => runEvaluator(board.objective.evaluator, cwd, timeoutSeconds), { onWait: () => log$13.info("Waiting for another evaluation on this machine to finish...") });
|
|
560174
|
+
const durationMs = Date.now() - started;
|
|
560175
|
+
const result = run.timedOut ? void 0 : parseEvaluatorOutput(run.output);
|
|
560176
|
+
if (!result) {
|
|
560177
|
+
console.log(run.timedOut ? `Evaluator timed out after ${timeoutSeconds}s.` : `Evaluator printed no score (exit code ${run.code}).`);
|
|
560178
|
+
console.log(tail(run.output, OUTPUT_TAIL_LINES));
|
|
560179
|
+
process.exitCode = 1;
|
|
560180
|
+
return;
|
|
560181
|
+
}
|
|
560182
|
+
printResult(result);
|
|
560183
|
+
if (options.details) console.log(import_picocolors.default.dim(tail(run.output, OUTPUT_TAIL_LINES)));
|
|
560184
|
+
const input = {
|
|
560185
|
+
durationMs,
|
|
560186
|
+
fingerprint: workingTreeFingerprint(cwd),
|
|
560187
|
+
metrics: result.metrics,
|
|
560188
|
+
score: result.score,
|
|
560189
|
+
summary: result.summary,
|
|
560190
|
+
valid: result.valid
|
|
560191
|
+
};
|
|
560192
|
+
const client = await getTrpcClient();
|
|
560193
|
+
const recorded = hasOperationToken() ? (await client.goal.recordEvaluationOperation.mutate(input)).data : (await client.goal.recordEvaluation.mutate({
|
|
560194
|
+
...input,
|
|
560195
|
+
id: options.goal
|
|
560196
|
+
})).data;
|
|
560197
|
+
if (recorded.recorded) {
|
|
560198
|
+
if (recorded.newBest) log$13.info(import_picocolors.default.green("New best score for this goal."));
|
|
560199
|
+
else if (recorded.newLaneBest) log$13.info(import_picocolors.default.green("New best score for your lane."));
|
|
560200
|
+
}
|
|
560201
|
+
if (recorded.leaderboard) printLeaderboard({
|
|
560202
|
+
...recorded.leaderboard,
|
|
560203
|
+
you: recorded.lane
|
|
560204
|
+
});
|
|
560205
|
+
});
|
|
560206
|
+
}
|
|
560207
|
+
|
|
559668
560208
|
//#endregion
|
|
559669
560209
|
//#region src/commands/goal/report.ts
|
|
559670
560210
|
/** `lh goal report`: the wrap-up run submits the Goal report it wrote. */
|
|
@@ -559734,32 +560274,6 @@ const parseVariant = (raw) => {
|
|
|
559734
560274
|
values
|
|
559735
560275
|
};
|
|
559736
560276
|
};
|
|
559737
|
-
const nodeIcon = {
|
|
559738
|
-
batch: "▦",
|
|
559739
|
-
decision: "◆",
|
|
559740
|
-
experiment: "⚗",
|
|
559741
|
-
finding: "●",
|
|
559742
|
-
problem: "◇",
|
|
559743
|
-
task: "▣"
|
|
559744
|
-
};
|
|
559745
|
-
/**
|
|
559746
|
-
* Every edge kind reads `source <kind> target`, so a row listing its INCOMING
|
|
559747
|
-
* edges by kind states the relationship backwards: an incoming `depends_on`
|
|
559748
|
-
* means the other node depends on THIS one, not the reverse. Render the inverse
|
|
559749
|
-
* verb instead, so each entry is a true sentence about the row it sits on.
|
|
559750
|
-
*/
|
|
559751
|
-
const inverseEdgeLabel = {
|
|
559752
|
-
answers: "answered by",
|
|
559753
|
-
contains: "inside",
|
|
559754
|
-
contradicts: "contradicted by",
|
|
559755
|
-
decomposes: "part of",
|
|
559756
|
-
depends_on: "blocks",
|
|
559757
|
-
derived_from: "ancestor of",
|
|
559758
|
-
investigates: "investigated by",
|
|
559759
|
-
leads_to: "follows",
|
|
559760
|
-
produces: "produced by",
|
|
559761
|
-
supports: "supported by"
|
|
559762
|
-
};
|
|
559763
560277
|
const terminalOutcomes = new Set([
|
|
559764
560278
|
"achieved",
|
|
559765
560279
|
"waiting_human",
|
|
@@ -560409,7 +560923,9 @@ function registerGoalCommand$1(program) {
|
|
|
560409
560923
|
log$13.info(result.message);
|
|
560410
560924
|
});
|
|
560411
560925
|
registerGoalGraphEditCommands(goal);
|
|
560926
|
+
registerGoalMarkCommands(goal);
|
|
560412
560927
|
registerGoalMetricCommands(goal);
|
|
560928
|
+
registerGoalObjectiveCommands(goal);
|
|
560413
560929
|
}
|
|
560414
560930
|
|
|
560415
560931
|
//#endregion
|
|
@@ -580434,6 +580950,36 @@ var CoalescingBatchIngester = class {
|
|
|
580434
580950
|
}
|
|
580435
580951
|
};
|
|
580436
580952
|
|
|
580953
|
+
//#endregion
|
|
580954
|
+
//#region src/utils/heteroControl.ts
|
|
580955
|
+
/**
|
|
580956
|
+
* Command handlers by command name. Empty until a command ships: an unknown
|
|
580957
|
+
* command is reported `unsupported`, so the server can tell "this `lh` does
|
|
580958
|
+
* not know it" from "it failed".
|
|
580959
|
+
*/
|
|
580960
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
580961
|
+
/** Run the handler for a control message and say how it went; never throws. */
|
|
580962
|
+
const dispatchHeteroControl = async (message, context) => {
|
|
580963
|
+
const handler = handlers.get(message.command);
|
|
580964
|
+
if (!handler) return { status: "unsupported" };
|
|
580965
|
+
try {
|
|
580966
|
+
const data = await handler({
|
|
580967
|
+
...context,
|
|
580968
|
+
controlId: message.id,
|
|
580969
|
+
params: message.params
|
|
580970
|
+
});
|
|
580971
|
+
return data === void 0 ? { status: "ok" } : {
|
|
580972
|
+
data,
|
|
580973
|
+
status: "ok"
|
|
580974
|
+
};
|
|
580975
|
+
} catch (error) {
|
|
580976
|
+
return {
|
|
580977
|
+
error: ((error instanceof Error ? error.message : String(error)) || "The control handler failed").slice(0, 4e3),
|
|
580978
|
+
status: "error"
|
|
580979
|
+
};
|
|
580980
|
+
}
|
|
580981
|
+
};
|
|
580982
|
+
|
|
580437
580983
|
//#endregion
|
|
580438
580984
|
//#region src/utils/heteroSteer.ts
|
|
580439
580985
|
/** The prompt a follow-up is typed in as: its text, then its images as image blocks. */
|
|
@@ -580453,6 +580999,9 @@ const buildSteerPrompt = (message) => {
|
|
|
580453
580999
|
}))];
|
|
580454
581000
|
};
|
|
580455
581001
|
const RETRY_MS = 2e3;
|
|
581002
|
+
const REPORT_ATTEMPTS = 3;
|
|
581003
|
+
/** How long the end of a run waits for control handlers still running. */
|
|
581004
|
+
const CONTROL_SETTLE_MS = 1e4;
|
|
580456
581005
|
/** The server predates steer delivery, or refuses it for this run: stop asking. */
|
|
580457
581006
|
const isPermanentRefusal = (error) => {
|
|
580458
581007
|
const code = error?.data?.code;
|
|
@@ -580473,6 +581022,12 @@ const isMainStreamStart = (event) => event.type === "stream_start" && !event.dat
|
|
|
580473
581022
|
* Once the server answered, the next main `stream_start` carries `liveSteer`
|
|
580474
581023
|
* so the client knows the run's queue no longer waits for the run to end.
|
|
580475
581024
|
*
|
|
581025
|
+
* The same poll carries the server's control messages (`acceptsControl`):
|
|
581026
|
+
* each goes to its handler in the `heteroControl` registry, which can write
|
|
581027
|
+
* control requests into the session, and its outcome goes back with
|
|
581028
|
+
* `aiAgent.reportHeteroControlResult`. A child run takes no follow-ups, but
|
|
581029
|
+
* keeps polling for control messages when the server delivers them.
|
|
581030
|
+
*
|
|
580476
581031
|
* Without a server context or a live session, events pass through unchanged.
|
|
580477
581032
|
*/
|
|
580478
581033
|
async function* withHeteroSteer(handle, context) {
|
|
@@ -580482,26 +581037,59 @@ async function* withHeteroSteer(handle, context) {
|
|
|
580482
581037
|
return;
|
|
580483
581038
|
}
|
|
580484
581039
|
const { operationId } = context;
|
|
581040
|
+
const sendControlRequest = handle.sendControlRequest;
|
|
580485
581041
|
const delivered = /* @__PURE__ */ new Set();
|
|
580486
581042
|
const abort = new AbortController();
|
|
581043
|
+
const handling = /* @__PURE__ */ new Set();
|
|
581044
|
+
let answered = false;
|
|
580487
581045
|
let supported = false;
|
|
580488
581046
|
let markedLive = false;
|
|
581047
|
+
const report = async (client, control, outcome) => {
|
|
581048
|
+
const reportResult = client.aiAgent.reportHeteroControlResult;
|
|
581049
|
+
if (!reportResult) return;
|
|
581050
|
+
for (let attempt = 1;; attempt++) try {
|
|
581051
|
+
await reportResult.mutate({
|
|
581052
|
+
controlId: control.id,
|
|
581053
|
+
operationId,
|
|
581054
|
+
...outcome
|
|
581055
|
+
});
|
|
581056
|
+
return;
|
|
581057
|
+
} catch (error) {
|
|
581058
|
+
if (isPermanentRefusal(error) || attempt >= REPORT_ATTEMPTS) {
|
|
581059
|
+
log$13.debug("Reporting control %s failed: %s", control.id, String(error));
|
|
581060
|
+
return;
|
|
581061
|
+
}
|
|
581062
|
+
await new Promise((resolve) => setTimeout(resolve, RETRY_MS));
|
|
581063
|
+
}
|
|
581064
|
+
};
|
|
581065
|
+
const handleControl = (client, control) => {
|
|
581066
|
+
const task = (async () => {
|
|
581067
|
+
log$13.debug("Control %s: %s", control.id, control.command);
|
|
581068
|
+
await report(client, control, await dispatchHeteroControl(control, {
|
|
581069
|
+
operationId,
|
|
581070
|
+
sendControlRequest,
|
|
581071
|
+
signal: abort.signal
|
|
581072
|
+
}));
|
|
581073
|
+
})().catch((error) => log$13.debug("Control %s failed: %s", control.id, String(error))).finally(() => handling.delete(task));
|
|
581074
|
+
handling.add(task);
|
|
581075
|
+
};
|
|
580489
581076
|
const poll = async () => {
|
|
580490
581077
|
const client = await context.getTrpcClient();
|
|
581078
|
+
const acceptsControl = !!sendControlRequest && !!client.aiAgent.reportHeteroControlResult;
|
|
580491
581079
|
while (!abort.signal.aborted) {
|
|
580492
581080
|
let message;
|
|
580493
581081
|
try {
|
|
580494
|
-
const res = await client.aiAgent.waitHeteroSteer.mutate(
|
|
580495
|
-
|
|
580496
|
-
operationId
|
|
580497
|
-
} : {
|
|
581082
|
+
const res = await client.aiAgent.waitHeteroSteer.mutate({
|
|
581083
|
+
...acceptsControl && { acceptsControl: true },
|
|
580498
581084
|
acceptsImages: true,
|
|
580499
|
-
blockMs: 1,
|
|
581085
|
+
...!answered && { blockMs: 1 },
|
|
580500
581086
|
operationId
|
|
580501
581087
|
}, { signal: abort.signal });
|
|
580502
|
-
if (res.steerable === false) return;
|
|
581088
|
+
if (res.steerable === false && !(acceptsControl && res.control !== void 0)) return;
|
|
581089
|
+
answered = true;
|
|
581090
|
+
if (res.steerable !== false) supported = true;
|
|
581091
|
+
if (res.control) handleControl(client, res.control);
|
|
580503
581092
|
message = res.message;
|
|
580504
|
-
supported = true;
|
|
580505
581093
|
} catch (error) {
|
|
580506
581094
|
if (abort.signal.aborted) return;
|
|
580507
581095
|
if (isPermanentRefusal(error)) {
|
|
@@ -580552,6 +581140,14 @@ async function* withHeteroSteer(handle, context) {
|
|
|
580552
581140
|
} finally {
|
|
580553
581141
|
abort.abort();
|
|
580554
581142
|
await polling;
|
|
581143
|
+
if (handling.size > 0) {
|
|
581144
|
+
let timer;
|
|
581145
|
+
await Promise.race([Promise.all(handling), new Promise((resolve) => {
|
|
581146
|
+
timer = setTimeout(resolve, CONTROL_SETTLE_MS);
|
|
581147
|
+
timer.unref?.();
|
|
581148
|
+
})]);
|
|
581149
|
+
clearTimeout(timer);
|
|
581150
|
+
}
|
|
580555
581151
|
}
|
|
580556
581152
|
}
|
|
580557
581153
|
|