@mycompbox/compbox-cli 1.21.8 → 1.21.9
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/.tsbuildinfo +1 -1
- package/index.js +64 -9
- package/package.json +1 -1
- package/utils/agent-invoker.d.ts +16 -1
- package/utils/agent-invoker.d.ts.map +1 -1
- package/utils/agent-invoker.js +74 -9
- package/utils/agent-invoker.js.map +1 -1
- package/utils/package-manager-shims.d.ts +2 -0
- package/utils/package-manager-shims.d.ts.map +1 -1
- package/utils/package-manager-shims.js +1 -1
- package/utils/package-manager-shims.js.map +1 -1
package/index.js
CHANGED
|
@@ -6016,6 +6016,9 @@ def handler(event, context):
|
|
|
6016
6016
|
respond(event, False, reason=str(e))
|
|
6017
6017
|
`;
|
|
6018
6018
|
|
|
6019
|
+
// ../shared/dist/stack-cost.js
|
|
6020
|
+
var MONTH_SECONDS = 30 * 24 * 60 * 60;
|
|
6021
|
+
|
|
6019
6022
|
// src/utils/config-store.ts
|
|
6020
6023
|
var CONFIG_DIR_ENV = "COMPBOX_CONFIG_DIR";
|
|
6021
6024
|
var PROJECT_DIR_ENV = "COMPBOX_PROJECT_DIR";
|
|
@@ -8020,6 +8023,7 @@ import chalk9 from "chalk";
|
|
|
8020
8023
|
// src/utils/agent-invoker.ts
|
|
8021
8024
|
import Anthropic from "@anthropic-ai/sdk";
|
|
8022
8025
|
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
8026
|
+
import { randomUUID } from "node:crypto";
|
|
8023
8027
|
import { mkdirSync as mkdirSync5 } from "node:fs";
|
|
8024
8028
|
import { homedir as homedir5 } from "node:os";
|
|
8025
8029
|
import { join as join9 } from "node:path";
|
|
@@ -8970,10 +8974,13 @@ ${fix.instructions}`,
|
|
|
8970
8974
|
];
|
|
8971
8975
|
}
|
|
8972
8976
|
var ORCHESTRATOR_FINAL_TURN_MAX_CHARS = 4e3;
|
|
8973
|
-
function buildOrchestratorArgs(epicId) {
|
|
8977
|
+
function buildOrchestratorArgs(epicId, sessionId) {
|
|
8974
8978
|
return [
|
|
8975
8979
|
"-p",
|
|
8976
8980
|
`@orchestrator execute epic ${epicId} --non-interactive`,
|
|
8981
|
+
// A known session id lets the runner resume this same conversation when
|
|
8982
|
+
// the agent ends its turn early (see buildOrchestratorContinueArgs).
|
|
8983
|
+
...sessionId ? ["--session-id", sessionId] : [],
|
|
8977
8984
|
// H3 reminder: never background work in a print-mode run.
|
|
8978
8985
|
"--append-system-prompt",
|
|
8979
8986
|
HEADLESS_ORCHESTRATE_REMINDER,
|
|
@@ -8983,6 +8990,26 @@ function buildOrchestratorArgs(epicId) {
|
|
|
8983
8990
|
"bypassPermissions"
|
|
8984
8991
|
];
|
|
8985
8992
|
}
|
|
8993
|
+
var MAX_ORCHESTRATOR_CONTINUES = 5;
|
|
8994
|
+
function orchestratorContinuePrompt(epicId, done, total) {
|
|
8995
|
+
return [
|
|
8996
|
+
`Continue executing epic ${epicId} in non-interactive mode. CompBox shows ${String(done)} of ${String(total)} features done.`,
|
|
8997
|
+
"You ended your turn early, which stopped the run. Do not announce the next step: take it.",
|
|
8998
|
+
"Keep going until every feature is done and recorded in CompBox, or a hard gate stops the run."
|
|
8999
|
+
].join(" ");
|
|
9000
|
+
}
|
|
9001
|
+
function buildOrchestratorContinueArgs(sessionId, prompt) {
|
|
9002
|
+
return [
|
|
9003
|
+
"-p",
|
|
9004
|
+
prompt,
|
|
9005
|
+
"--resume",
|
|
9006
|
+
sessionId,
|
|
9007
|
+
"--append-system-prompt",
|
|
9008
|
+
HEADLESS_ORCHESTRATE_REMINDER,
|
|
9009
|
+
"--permission-mode",
|
|
9010
|
+
"bypassPermissions"
|
|
9011
|
+
];
|
|
9012
|
+
}
|
|
8986
9013
|
function orchestrateNotGitRepoMessage(dir) {
|
|
8987
9014
|
return [
|
|
8988
9015
|
`The configured CompBox project directory is not a git repository: ${dir}`,
|
|
@@ -9106,7 +9133,8 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
9106
9133
|
const runDir = workspace?.dir ?? projectDir;
|
|
9107
9134
|
const routing = await resolveRoutingImpl();
|
|
9108
9135
|
const command = resolveClaudeBinary() ?? "claude";
|
|
9109
|
-
const
|
|
9136
|
+
const sessionId = ctx.fix ? void 0 : (deps.newSessionId ?? randomUUID)();
|
|
9137
|
+
const runArgs = ctx.fix ? buildFixArgs(ctx.fix) : buildOrchestratorArgs(ctx.epicId, sessionId);
|
|
9110
9138
|
const args = ctx.keyRun ? keyRunArgs(runArgs) : runArgs;
|
|
9111
9139
|
const routedEnv = claudeSpawnEnv(process.env, routing);
|
|
9112
9140
|
const baseEnv = {
|
|
@@ -9126,11 +9154,11 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
9126
9154
|
);
|
|
9127
9155
|
} catch {
|
|
9128
9156
|
}
|
|
9129
|
-
const
|
|
9157
|
+
const runOnce = (runArgsNow, budgetMs) => new Promise((resolve3) => {
|
|
9130
9158
|
let stdout2 = "";
|
|
9131
9159
|
let stderr = "";
|
|
9132
9160
|
let settled = false;
|
|
9133
|
-
const child = spawnImpl(command,
|
|
9161
|
+
const child = spawnImpl(command, runArgsNow, {
|
|
9134
9162
|
cwd: runDir,
|
|
9135
9163
|
stdio: ["ignore", "pipe", "pipe"],
|
|
9136
9164
|
env: childEnv,
|
|
@@ -9169,7 +9197,7 @@ async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
9169
9197
|
error: `The orchestrator run timed out after ${String(Math.round(timeoutMs / 6e4))} minutes and was terminated.`
|
|
9170
9198
|
}
|
|
9171
9199
|
});
|
|
9172
|
-
},
|
|
9200
|
+
}, budgetMs);
|
|
9173
9201
|
child.stdout.on("data", (chunk) => {
|
|
9174
9202
|
stdout2 += chunk.toString("utf-8");
|
|
9175
9203
|
});
|
|
@@ -9224,6 +9252,8 @@ ${stderr}`;
|
|
|
9224
9252
|
});
|
|
9225
9253
|
});
|
|
9226
9254
|
});
|
|
9255
|
+
const deadline = Date.now() + timeoutMs;
|
|
9256
|
+
let outcome = await runOnce(args, timeoutMs);
|
|
9227
9257
|
if (outcome.status === "done" && !ctx.fix) {
|
|
9228
9258
|
const readProgress = deps.epicProgress ?? (async () => {
|
|
9229
9259
|
try {
|
|
@@ -9237,8 +9267,33 @@ ${stderr}`;
|
|
|
9237
9267
|
return null;
|
|
9238
9268
|
}
|
|
9239
9269
|
});
|
|
9240
|
-
const
|
|
9241
|
-
|
|
9270
|
+
const unfinished = (p) => p !== null && p.totalFeatures > 0 && p.completedFeatures < p.totalFeatures;
|
|
9271
|
+
let progress = await readProgress();
|
|
9272
|
+
const maxContinues = deps.maxContinues ?? MAX_ORCHESTRATOR_CONTINUES;
|
|
9273
|
+
let continues = 0;
|
|
9274
|
+
let stalls = 0;
|
|
9275
|
+
while (sessionId && unfinished(progress) && continues < maxContinues && !ctx.signal?.aborted && deadline - Date.now() > 6e4) {
|
|
9276
|
+
continues += 1;
|
|
9277
|
+
try {
|
|
9278
|
+
await ctx.mailboxClient.postTurn(
|
|
9279
|
+
ctx.machineToken,
|
|
9280
|
+
ctx.jobId,
|
|
9281
|
+
`The orchestrator stopped with ${String(progress.completedFeatures)} of ${String(progress.totalFeatures)} features done. Continuing automatically (${String(continues)} of ${String(maxContinues)})\u2026`
|
|
9282
|
+
);
|
|
9283
|
+
} catch {
|
|
9284
|
+
}
|
|
9285
|
+
const before = progress.completedFeatures;
|
|
9286
|
+
const continueArgs = buildOrchestratorContinueArgs(
|
|
9287
|
+
sessionId,
|
|
9288
|
+
orchestratorContinuePrompt(ctx.epicId, progress.completedFeatures, progress.totalFeatures)
|
|
9289
|
+
);
|
|
9290
|
+
outcome = await runOnce(ctx.keyRun ? keyRunArgs(continueArgs) : continueArgs, deadline - Date.now());
|
|
9291
|
+
if (outcome.status !== "done") break;
|
|
9292
|
+
progress = await readProgress();
|
|
9293
|
+
stalls = progress && progress.completedFeatures > before ? 0 : stalls + 1;
|
|
9294
|
+
if (stalls >= 2) break;
|
|
9295
|
+
}
|
|
9296
|
+
if (outcome.status === "done" && unfinished(progress)) {
|
|
9242
9297
|
outcome.status = "failed";
|
|
9243
9298
|
outcome.result = buildIncompleteRunResult(ctx.epicId, progress);
|
|
9244
9299
|
}
|
|
@@ -9982,7 +10037,7 @@ function shimScript(tool, nodeBinDir, npx) {
|
|
|
9982
10037
|
}
|
|
9983
10038
|
function ensurePackageManagerShims(opts = {}) {
|
|
9984
10039
|
if ((opts.platform ?? process.platform) === "win32") return null;
|
|
9985
|
-
const path3 = claudeChildEnvPath(opts.path ?? process.env.PATH);
|
|
10040
|
+
const path3 = (opts.searchPath ?? claudeChildEnvPath)(opts.path ?? process.env.PATH);
|
|
9986
10041
|
const missing = Object.keys(STAND_INS).filter((tool) => !isOnPath(tool, path3));
|
|
9987
10042
|
if (missing.length === 0) return null;
|
|
9988
10043
|
const nodeBinDir = opts.nodeBinDir ?? dirname6(process.execPath);
|
|
@@ -11179,7 +11234,7 @@ ${error instanceof Error ? error.message : String(error)}`));
|
|
|
11179
11234
|
// src/index.ts
|
|
11180
11235
|
function resolveCliVersion() {
|
|
11181
11236
|
if (true) {
|
|
11182
|
-
return "1.21.
|
|
11237
|
+
return "1.21.9";
|
|
11183
11238
|
}
|
|
11184
11239
|
const require2 = createRequire(import.meta.url);
|
|
11185
11240
|
const pkg = require2("../package.json");
|
package/package.json
CHANGED
package/utils/agent-invoker.d.ts
CHANGED
|
@@ -374,7 +374,18 @@ export declare function buildFixArgs(fix: Pick<StartExecutionFix, 'instructions'
|
|
|
374
374
|
* ANTHROPIC_BASE_URL, not the model name). `--non-interactive` is what engages
|
|
375
375
|
* the agent-side serial-in-process fallback (H3).
|
|
376
376
|
*/
|
|
377
|
-
export declare function buildOrchestratorArgs(epicId: string): string[];
|
|
377
|
+
export declare function buildOrchestratorArgs(epicId: string, sessionId?: string): string[];
|
|
378
|
+
/**
|
|
379
|
+
* How many times the runner resumes an orchestrator that ended its turn with
|
|
380
|
+
* features still outstanding. On long runs the agent sometimes writes "Next
|
|
381
|
+
* I'll send the next feature to a worker" and stops; in print mode that ends
|
|
382
|
+
* the process (ENG-E60/ENG-E61, 2026-10-22, each stopped after 1-2 features).
|
|
383
|
+
*/
|
|
384
|
+
export declare const MAX_ORCHESTRATOR_CONTINUES = 5;
|
|
385
|
+
/** The prompt that resumes a stopped orchestrator in the same session. */
|
|
386
|
+
export declare function orchestratorContinuePrompt(epicId: string, done: number, total: number): string;
|
|
387
|
+
/** Claude CLI args that resume the orchestrator's session with {@link orchestratorContinuePrompt}. */
|
|
388
|
+
export declare function buildOrchestratorContinueArgs(sessionId: string, prompt: string): string[];
|
|
378
389
|
/** Actionable failure when the configured project path is not a git repository. */
|
|
379
390
|
export declare function orchestrateNotGitRepoMessage(dir: string): string;
|
|
380
391
|
/** Actionable failure when `git worktree` is unavailable in the project dir. */
|
|
@@ -448,6 +459,10 @@ export interface StartExecutionOrchestrateDeps {
|
|
|
448
459
|
* Defaults to the progress CompBox returns with a status turn on the job.
|
|
449
460
|
*/
|
|
450
461
|
epicProgress?: () => Promise<EpicFeatureProgress | null>;
|
|
462
|
+
/** Resumes allowed when the run ends with features outstanding (default {@link MAX_ORCHESTRATOR_CONTINUES}). */
|
|
463
|
+
maxContinues?: number;
|
|
464
|
+
/** Session id for the orchestrator run; injectable so tests can assert the resume. */
|
|
465
|
+
newSessionId?: () => string;
|
|
451
466
|
}
|
|
452
467
|
/** How many of an epic's features are done. */
|
|
453
468
|
export interface EpicFeatureProgress {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-invoker.d.ts","sourceRoot":"","sources":["../../src/utils/agent-invoker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAa,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-invoker.d.ts","sourceRoot":"","sources":["../../src/utils/agent-invoker.ts"],"names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
import { randomUUID } from 'node:crypto';
|
|
21
22
|
import { mkdirSync } from 'node:fs';
|
|
22
23
|
import { homedir } from 'node:os';
|
|
23
24
|
import { join } from 'node:path';
|
|
@@ -1305,10 +1306,13 @@ const ORCHESTRATOR_FINAL_TURN_MAX_CHARS = 4_000;
|
|
|
1305
1306
|
* ANTHROPIC_BASE_URL, not the model name). `--non-interactive` is what engages
|
|
1306
1307
|
* the agent-side serial-in-process fallback (H3).
|
|
1307
1308
|
*/
|
|
1308
|
-
export function buildOrchestratorArgs(epicId) {
|
|
1309
|
+
export function buildOrchestratorArgs(epicId, sessionId) {
|
|
1309
1310
|
return [
|
|
1310
1311
|
'-p',
|
|
1311
1312
|
`@orchestrator execute epic ${epicId} --non-interactive`,
|
|
1313
|
+
// A known session id lets the runner resume this same conversation when
|
|
1314
|
+
// the agent ends its turn early (see buildOrchestratorContinueArgs).
|
|
1315
|
+
...(sessionId ? ['--session-id', sessionId] : []),
|
|
1312
1316
|
// H3 reminder: never background work in a print-mode run.
|
|
1313
1317
|
'--append-system-prompt',
|
|
1314
1318
|
HEADLESS_ORCHESTRATE_REMINDER,
|
|
@@ -1318,6 +1322,34 @@ export function buildOrchestratorArgs(epicId) {
|
|
|
1318
1322
|
'bypassPermissions',
|
|
1319
1323
|
];
|
|
1320
1324
|
}
|
|
1325
|
+
/**
|
|
1326
|
+
* How many times the runner resumes an orchestrator that ended its turn with
|
|
1327
|
+
* features still outstanding. On long runs the agent sometimes writes "Next
|
|
1328
|
+
* I'll send the next feature to a worker" and stops; in print mode that ends
|
|
1329
|
+
* the process (ENG-E60/ENG-E61, 2026-10-22, each stopped after 1-2 features).
|
|
1330
|
+
*/
|
|
1331
|
+
export const MAX_ORCHESTRATOR_CONTINUES = 5;
|
|
1332
|
+
/** The prompt that resumes a stopped orchestrator in the same session. */
|
|
1333
|
+
export function orchestratorContinuePrompt(epicId, done, total) {
|
|
1334
|
+
return [
|
|
1335
|
+
`Continue executing epic ${epicId} in non-interactive mode. CompBox shows ${String(done)} of ${String(total)} features done.`,
|
|
1336
|
+
'You ended your turn early, which stopped the run. Do not announce the next step: take it.',
|
|
1337
|
+
'Keep going until every feature is done and recorded in CompBox, or a hard gate stops the run.',
|
|
1338
|
+
].join(' ');
|
|
1339
|
+
}
|
|
1340
|
+
/** Claude CLI args that resume the orchestrator's session with {@link orchestratorContinuePrompt}. */
|
|
1341
|
+
export function buildOrchestratorContinueArgs(sessionId, prompt) {
|
|
1342
|
+
return [
|
|
1343
|
+
'-p',
|
|
1344
|
+
prompt,
|
|
1345
|
+
'--resume',
|
|
1346
|
+
sessionId,
|
|
1347
|
+
'--append-system-prompt',
|
|
1348
|
+
HEADLESS_ORCHESTRATE_REMINDER,
|
|
1349
|
+
'--permission-mode',
|
|
1350
|
+
'bypassPermissions',
|
|
1351
|
+
];
|
|
1352
|
+
}
|
|
1321
1353
|
/** Actionable failure when the configured project path is not a git repository. */
|
|
1322
1354
|
export function orchestrateNotGitRepoMessage(dir) {
|
|
1323
1355
|
return [
|
|
@@ -1507,7 +1539,9 @@ export async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
1507
1539
|
const runDir = workspace?.dir ?? projectDir;
|
|
1508
1540
|
const routing = await resolveRoutingImpl();
|
|
1509
1541
|
const command = resolveClaudeBinary() ?? 'claude';
|
|
1510
|
-
|
|
1542
|
+
// A fix run is one focused change, so only a build gets a resumable session.
|
|
1543
|
+
const sessionId = ctx.fix ? undefined : (deps.newSessionId ?? randomUUID)();
|
|
1544
|
+
const runArgs = ctx.fix ? buildFixArgs(ctx.fix) : buildOrchestratorArgs(ctx.epicId, sessionId);
|
|
1511
1545
|
const args = ctx.keyRun ? keyRunArgs(runArgs) : runArgs;
|
|
1512
1546
|
// pxpipe (ENG-136): inject ANTHROPIC_BASE_URL when routed. COMPBOX_NONINTERACTIVE
|
|
1513
1547
|
// forces the orchestrator's headless serial-in-process path (H3) even if the
|
|
@@ -1539,11 +1573,11 @@ export async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
1539
1573
|
catch {
|
|
1540
1574
|
// Best-effort start turn.
|
|
1541
1575
|
}
|
|
1542
|
-
const
|
|
1576
|
+
const runOnce = (runArgsNow, budgetMs) => new Promise((resolve) => {
|
|
1543
1577
|
let stdout = '';
|
|
1544
1578
|
let stderr = '';
|
|
1545
1579
|
let settled = false;
|
|
1546
|
-
const child = spawnImpl(command,
|
|
1580
|
+
const child = spawnImpl(command, runArgsNow, {
|
|
1547
1581
|
cwd: runDir,
|
|
1548
1582
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
1549
1583
|
env: childEnv,
|
|
@@ -1587,7 +1621,7 @@ export async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
1587
1621
|
error: `The orchestrator run timed out after ${String(Math.round(timeoutMs / 60_000))} minutes and was terminated.`,
|
|
1588
1622
|
},
|
|
1589
1623
|
});
|
|
1590
|
-
},
|
|
1624
|
+
}, budgetMs);
|
|
1591
1625
|
child.stdout.on('data', (chunk) => {
|
|
1592
1626
|
stdout += chunk.toString('utf-8');
|
|
1593
1627
|
});
|
|
@@ -1653,9 +1687,13 @@ export async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
1653
1687
|
});
|
|
1654
1688
|
});
|
|
1655
1689
|
});
|
|
1690
|
+
// The whole run, continues included, shares one time budget.
|
|
1691
|
+
const deadline = Date.now() + timeoutMs;
|
|
1692
|
+
let outcome = await runOnce(args, timeoutMs);
|
|
1656
1693
|
// A clean exit isn't proof the epic is finished: a headless run can end its
|
|
1657
|
-
// turn early (e.g. "waiting" on a background review). Check
|
|
1658
|
-
// the
|
|
1694
|
+
// turn early (e.g. "waiting" on a background review, or "Next I'll…"). Check
|
|
1695
|
+
// CompBox, resume the same session while features are outstanding and new
|
|
1696
|
+
// ones keep finishing, and flag the run for attention if it still isn't done.
|
|
1659
1697
|
// A fix run changes one pull request, not the epic's plan, so epic progress says nothing about it.
|
|
1660
1698
|
if (outcome.status === 'done' && !ctx.fix) {
|
|
1661
1699
|
const readProgress = deps.epicProgress ??
|
|
@@ -1668,8 +1706,35 @@ export async function invokeStartExecutionOrchestrate(ctx, deps = {}) {
|
|
|
1668
1706
|
return null;
|
|
1669
1707
|
}
|
|
1670
1708
|
});
|
|
1671
|
-
const
|
|
1672
|
-
|
|
1709
|
+
const unfinished = (p) => p !== null && p.totalFeatures > 0 && p.completedFeatures < p.totalFeatures;
|
|
1710
|
+
let progress = await readProgress();
|
|
1711
|
+
const maxContinues = deps.maxContinues ?? MAX_ORCHESTRATOR_CONTINUES;
|
|
1712
|
+
let continues = 0;
|
|
1713
|
+
let stalls = 0;
|
|
1714
|
+
while (sessionId &&
|
|
1715
|
+
unfinished(progress) &&
|
|
1716
|
+
continues < maxContinues &&
|
|
1717
|
+
!ctx.signal?.aborted &&
|
|
1718
|
+
deadline - Date.now() > 60_000) {
|
|
1719
|
+
continues += 1;
|
|
1720
|
+
try {
|
|
1721
|
+
await ctx.mailboxClient.postTurn(ctx.machineToken, ctx.jobId, `The orchestrator stopped with ${String(progress.completedFeatures)} of ${String(progress.totalFeatures)} features done. Continuing automatically (${String(continues)} of ${String(maxContinues)})…`);
|
|
1722
|
+
}
|
|
1723
|
+
catch {
|
|
1724
|
+
// Best-effort status turn.
|
|
1725
|
+
}
|
|
1726
|
+
const before = progress.completedFeatures;
|
|
1727
|
+
const continueArgs = buildOrchestratorContinueArgs(sessionId, orchestratorContinuePrompt(ctx.epicId, progress.completedFeatures, progress.totalFeatures));
|
|
1728
|
+
outcome = await runOnce(ctx.keyRun ? keyRunArgs(continueArgs) : continueArgs, deadline - Date.now());
|
|
1729
|
+
if (outcome.status !== 'done')
|
|
1730
|
+
break;
|
|
1731
|
+
progress = await readProgress();
|
|
1732
|
+
// Two resumes in a row without a newly finished feature: stop and ask a person.
|
|
1733
|
+
stalls = progress && progress.completedFeatures > before ? 0 : stalls + 1;
|
|
1734
|
+
if (stalls >= 2)
|
|
1735
|
+
break;
|
|
1736
|
+
}
|
|
1737
|
+
if (outcome.status === 'done' && unfinished(progress)) {
|
|
1673
1738
|
outcome.status = 'failed';
|
|
1674
1739
|
outcome.result = buildIncompleteRunResult(ctx.epicId, progress);
|
|
1675
1740
|
}
|