@raysonmeng/agentbridge 0.1.13 → 0.1.15
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/.claude-plugin/marketplace.json +1 -1
- package/README.md +2 -1
- package/README.zh-CN.md +2 -1
- package/dist/cli.js +391 -108
- package/dist/daemon.js +148 -13
- package/package.json +1 -1
- package/plugins/agentbridge/.claude-plugin/plugin.json +1 -1
- package/plugins/agentbridge/server/bridge-server.js +133 -6
- package/plugins/agentbridge/server/daemon.js +148 -13
package/dist/daemon.js
CHANGED
|
@@ -26,11 +26,11 @@ function defineNumber(value, fallback) {
|
|
|
26
26
|
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
27
27
|
}
|
|
28
28
|
var BUILD_INFO = Object.freeze({
|
|
29
|
-
version: defineString("0.1.
|
|
30
|
-
commit: defineString("
|
|
29
|
+
version: defineString("0.1.15", "0.0.0-source"),
|
|
30
|
+
commit: defineString("89d4c9a", "source"),
|
|
31
31
|
bundle: defineBundle("dist"),
|
|
32
32
|
contractVersion: defineNumber(1, CONTRACT_VERSION),
|
|
33
|
-
codeHash: defineString("
|
|
33
|
+
codeHash: defineString("71ce81854ec9", "source")
|
|
34
34
|
});
|
|
35
35
|
function daemonStatusBuildInfo() {
|
|
36
36
|
return { ...BUILD_INFO };
|
|
@@ -3401,7 +3401,8 @@ var DEFAULT_BUDGET_CONFIG = {
|
|
|
3401
3401
|
full: null,
|
|
3402
3402
|
balanced: { effort: "medium" },
|
|
3403
3403
|
eco: { effort: "low" }
|
|
3404
|
-
}
|
|
3404
|
+
},
|
|
3405
|
+
strategy: "conserve"
|
|
3405
3406
|
};
|
|
3406
3407
|
var DEFAULT_CONFIG = {
|
|
3407
3408
|
version: "1.0",
|
|
@@ -3479,6 +3480,9 @@ function normalizeBoundedInteger(value, fallback, min, max) {
|
|
|
3479
3480
|
return fallback;
|
|
3480
3481
|
return parsed;
|
|
3481
3482
|
}
|
|
3483
|
+
function normalizeStrategy(value, fallback) {
|
|
3484
|
+
return value === "conserve" || value === "maximize" ? value : fallback;
|
|
3485
|
+
}
|
|
3482
3486
|
function normalizeBoolean(value, fallback) {
|
|
3483
3487
|
if (typeof value === "boolean")
|
|
3484
3488
|
return value;
|
|
@@ -3527,7 +3531,8 @@ function normalizeBudgetConfig(raw, fallback = DEFAULT_BUDGET_CONFIG) {
|
|
|
3527
3531
|
timeWindowSec: normalizeBoundedInteger(parallel.timeWindowSec, fallback.parallel.timeWindowSec, 60, 604800)
|
|
3528
3532
|
},
|
|
3529
3533
|
codexTierControl: normalizeBoolean(budget.codexTierControl, fallback.codexTierControl) && codexTiers.full !== null,
|
|
3530
|
-
codexTiers
|
|
3534
|
+
codexTiers,
|
|
3535
|
+
strategy: normalizeStrategy(budget.strategy, fallback.strategy)
|
|
3531
3536
|
};
|
|
3532
3537
|
}
|
|
3533
3538
|
function applyBudgetEnvOverrides(budget, env = process.env) {
|
|
@@ -3542,7 +3547,8 @@ function applyBudgetEnvOverrides(budget, env = process.env) {
|
|
|
3542
3547
|
timeWindowSec: env.AGENTBRIDGE_BUDGET_PARALLEL_TIME_WINDOW_SEC ?? budget.parallel.timeWindowSec
|
|
3543
3548
|
},
|
|
3544
3549
|
codexTierControl: env.AGENTBRIDGE_BUDGET_CODEX_TIER_CONTROL ?? budget.codexTierControl,
|
|
3545
|
-
codexTiers: budget.codexTiers
|
|
3550
|
+
codexTiers: budget.codexTiers,
|
|
3551
|
+
strategy: env.AGENTBRIDGE_BUDGET_STRATEGY ?? budget.strategy
|
|
3546
3552
|
};
|
|
3547
3553
|
return normalizeBudgetConfig(overlay, budget);
|
|
3548
3554
|
}
|
|
@@ -4038,6 +4044,54 @@ function classifyPoll(prev, state, cfg) {
|
|
|
4038
4044
|
return { next: prev, effect: { kind: "none" } };
|
|
4039
4045
|
}
|
|
4040
4046
|
|
|
4047
|
+
// src/budget/burn-view.ts
|
|
4048
|
+
function windowBurnRate(window) {
|
|
4049
|
+
if (!window || window.burnRate === undefined)
|
|
4050
|
+
return null;
|
|
4051
|
+
return {
|
|
4052
|
+
pctPerHour: window.burnRate,
|
|
4053
|
+
confident: window.burnConfident === true
|
|
4054
|
+
};
|
|
4055
|
+
}
|
|
4056
|
+
function agentBurnRates(usage) {
|
|
4057
|
+
if (!usage)
|
|
4058
|
+
return { fiveHour: null, weekly: null };
|
|
4059
|
+
return {
|
|
4060
|
+
fiveHour: windowBurnRate(usage.fiveHour),
|
|
4061
|
+
weekly: windowBurnRate(usage.weekly)
|
|
4062
|
+
};
|
|
4063
|
+
}
|
|
4064
|
+
function agentRunway(usage, now) {
|
|
4065
|
+
if (!usage || usage.stale || !usage.ok)
|
|
4066
|
+
return null;
|
|
4067
|
+
if (!isDecisionGrade(usage, now))
|
|
4068
|
+
return null;
|
|
4069
|
+
let best = null;
|
|
4070
|
+
const candidates = [
|
|
4071
|
+
["fiveHour", usage.fiveHour],
|
|
4072
|
+
["weekly", usage.weekly]
|
|
4073
|
+
];
|
|
4074
|
+
for (const [basis, window] of candidates) {
|
|
4075
|
+
if (!window || window.resetEpoch <= now)
|
|
4076
|
+
continue;
|
|
4077
|
+
if (window.burnConfident !== true)
|
|
4078
|
+
continue;
|
|
4079
|
+
if (window.runwaySeconds === undefined)
|
|
4080
|
+
continue;
|
|
4081
|
+
if (best === null || window.runwaySeconds < best.seconds) {
|
|
4082
|
+
best = {
|
|
4083
|
+
seconds: window.runwaySeconds,
|
|
4084
|
+
basis,
|
|
4085
|
+
depletedAtEpoch: window.depletedAtEpoch ?? null
|
|
4086
|
+
};
|
|
4087
|
+
}
|
|
4088
|
+
}
|
|
4089
|
+
return best;
|
|
4090
|
+
}
|
|
4091
|
+
function hasAnyBurnSignal(rates, runway) {
|
|
4092
|
+
return rates.claude.fiveHour !== null || rates.claude.weekly !== null || rates.codex.fiveHour !== null || rates.codex.weekly !== null || runway.claude !== null || runway.codex !== null;
|
|
4093
|
+
}
|
|
4094
|
+
|
|
4041
4095
|
// src/budget/budget-coordinator.ts
|
|
4042
4096
|
var LOW_UTIL_PCT = 50;
|
|
4043
4097
|
var NEAR_PAUSE_MARGIN_PCT = 10;
|
|
@@ -4348,8 +4402,22 @@ class BudgetCoordinator {
|
|
|
4348
4402
|
resumeAfterEpoch: paused ? this.fpState.resumeEpoch ?? state.pause.resumeAfterEpoch : null,
|
|
4349
4403
|
parallelRecommended: paused ? false : state.parallel.recommended,
|
|
4350
4404
|
codexTier: state.effort.codexTier,
|
|
4351
|
-
claudeAdvice: state.effort.claudeAdvice
|
|
4405
|
+
claudeAdvice: state.effort.claudeAdvice,
|
|
4406
|
+
...this.burnRateSnapshotFields(state)
|
|
4407
|
+
};
|
|
4408
|
+
}
|
|
4409
|
+
burnRateSnapshotFields(state) {
|
|
4410
|
+
const rates = {
|
|
4411
|
+
claude: agentBurnRates(state.perAgent.claude),
|
|
4412
|
+
codex: agentBurnRates(state.perAgent.codex)
|
|
4413
|
+
};
|
|
4414
|
+
const runway = {
|
|
4415
|
+
claude: agentRunway(state.perAgent.claude, state.now),
|
|
4416
|
+
codex: agentRunway(state.perAgent.codex, state.now)
|
|
4352
4417
|
};
|
|
4418
|
+
if (!hasAnyBurnSignal(rates, runway))
|
|
4419
|
+
return {};
|
|
4420
|
+
return { burnRate: rates, runway };
|
|
4353
4421
|
}
|
|
4354
4422
|
}
|
|
4355
4423
|
|
|
@@ -4358,6 +4426,57 @@ import { execFile } from "child_process";
|
|
|
4358
4426
|
import { existsSync as existsSync5 } from "fs";
|
|
4359
4427
|
import { homedir as homedir2 } from "os";
|
|
4360
4428
|
import { basename, join as join5 } from "path";
|
|
4429
|
+
function parseBurnFields(record) {
|
|
4430
|
+
const group = {};
|
|
4431
|
+
let any = false;
|
|
4432
|
+
const takeNumber = (value, min) => {
|
|
4433
|
+
if (value === undefined)
|
|
4434
|
+
return "absent";
|
|
4435
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
4436
|
+
return "invalid";
|
|
4437
|
+
if (min === "zero" && value < 0)
|
|
4438
|
+
return "invalid";
|
|
4439
|
+
if (min === "positive" && value <= 0)
|
|
4440
|
+
return "invalid";
|
|
4441
|
+
return value;
|
|
4442
|
+
};
|
|
4443
|
+
const burnRate = takeNumber(record.burn_rate_pct_per_hour ?? record.burnRatePctPerHour, "zero");
|
|
4444
|
+
if (burnRate === "invalid")
|
|
4445
|
+
return null;
|
|
4446
|
+
if (burnRate !== "absent") {
|
|
4447
|
+
group.burnRate = burnRate;
|
|
4448
|
+
any = true;
|
|
4449
|
+
}
|
|
4450
|
+
const confidentRaw = record.burn_confident ?? record.burnConfident;
|
|
4451
|
+
if (confidentRaw !== undefined) {
|
|
4452
|
+
if (typeof confidentRaw !== "boolean")
|
|
4453
|
+
return null;
|
|
4454
|
+
group.burnConfident = confidentRaw;
|
|
4455
|
+
any = true;
|
|
4456
|
+
}
|
|
4457
|
+
const runwaySeconds = takeNumber(record.runway_seconds ?? record.runwaySeconds, "zero");
|
|
4458
|
+
if (runwaySeconds === "invalid")
|
|
4459
|
+
return null;
|
|
4460
|
+
if (runwaySeconds !== "absent") {
|
|
4461
|
+
group.runwaySeconds = runwaySeconds;
|
|
4462
|
+
any = true;
|
|
4463
|
+
}
|
|
4464
|
+
const depletedAtEpoch = takeNumber(record.depleted_at_epoch ?? record.depletedAtEpoch, "positive");
|
|
4465
|
+
if (depletedAtEpoch === "invalid")
|
|
4466
|
+
return null;
|
|
4467
|
+
if (depletedAtEpoch !== "absent") {
|
|
4468
|
+
group.depletedAtEpoch = depletedAtEpoch;
|
|
4469
|
+
any = true;
|
|
4470
|
+
}
|
|
4471
|
+
const fiveHourWindowsLeft = takeNumber(record.five_hour_windows_left ?? record.fiveHourWindowsLeft, "zero");
|
|
4472
|
+
if (fiveHourWindowsLeft === "invalid")
|
|
4473
|
+
return null;
|
|
4474
|
+
if (fiveHourWindowsLeft !== "absent") {
|
|
4475
|
+
group.fiveHourWindowsLeft = fiveHourWindowsLeft;
|
|
4476
|
+
any = true;
|
|
4477
|
+
}
|
|
4478
|
+
return any ? group : null;
|
|
4479
|
+
}
|
|
4361
4480
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
4362
4481
|
var MAX_BUFFER = 1024 * 1024;
|
|
4363
4482
|
function defaultRunner(command, args, options) {
|
|
@@ -4419,7 +4538,8 @@ function normalizeBucket(value, fetchedAt) {
|
|
|
4419
4538
|
id,
|
|
4420
4539
|
util: clamp(util, 0, 100),
|
|
4421
4540
|
resetEpoch: Math.max(0, resetEpoch),
|
|
4422
|
-
resetAfterSeconds: resetAfter === null ? null : Math.max(0, resetAfter)
|
|
4541
|
+
resetAfterSeconds: resetAfter === null ? null : Math.max(0, resetAfter),
|
|
4542
|
+
burn: parseBurnFields(bucket)
|
|
4423
4543
|
};
|
|
4424
4544
|
}
|
|
4425
4545
|
function normalizeTopLevelBucket(record, util, fetchedAt) {
|
|
@@ -4432,13 +4552,27 @@ function normalizeTopLevelBucket(record, util, fetchedAt) {
|
|
|
4432
4552
|
id: "top_level",
|
|
4433
4553
|
util: clamp(util, 0, 100),
|
|
4434
4554
|
resetEpoch: Math.max(0, resetEpoch),
|
|
4435
|
-
resetAfterSeconds: resetAfter === null ? null : Math.max(0, resetAfter)
|
|
4555
|
+
resetAfterSeconds: resetAfter === null ? null : Math.max(0, resetAfter),
|
|
4556
|
+
burn: parseBurnFields(record)
|
|
4436
4557
|
};
|
|
4437
4558
|
}
|
|
4438
4559
|
function toWindow(bucket) {
|
|
4439
4560
|
if (!bucket)
|
|
4440
4561
|
return null;
|
|
4441
|
-
|
|
4562
|
+
const window = { util: bucket.util, resetEpoch: bucket.resetEpoch };
|
|
4563
|
+
if (bucket.burn) {
|
|
4564
|
+
if (bucket.burn.burnRate !== undefined)
|
|
4565
|
+
window.burnRate = bucket.burn.burnRate;
|
|
4566
|
+
if (bucket.burn.burnConfident !== undefined)
|
|
4567
|
+
window.burnConfident = bucket.burn.burnConfident;
|
|
4568
|
+
if (bucket.burn.runwaySeconds !== undefined)
|
|
4569
|
+
window.runwaySeconds = bucket.burn.runwaySeconds;
|
|
4570
|
+
if (bucket.burn.depletedAtEpoch !== undefined)
|
|
4571
|
+
window.depletedAtEpoch = bucket.burn.depletedAtEpoch;
|
|
4572
|
+
if (bucket.burn.fiveHourWindowsLeft !== undefined)
|
|
4573
|
+
window.fiveHourWindowsLeft = bucket.burn.fiveHourWindowsLeft;
|
|
4574
|
+
}
|
|
4575
|
+
return window;
|
|
4442
4576
|
}
|
|
4443
4577
|
function bucketSortKey(bucket) {
|
|
4444
4578
|
if (bucket.resetAfterSeconds !== null)
|
|
@@ -4518,10 +4652,11 @@ function normalizeTolerantProbeRecord(record) {
|
|
|
4518
4652
|
};
|
|
4519
4653
|
}
|
|
4520
4654
|
var PROBE_SCHEMA_PARSERS = {
|
|
4521
|
-
"1": normalizeTolerantProbeRecord
|
|
4655
|
+
"1": normalizeTolerantProbeRecord,
|
|
4656
|
+
"2": normalizeTolerantProbeRecord
|
|
4522
4657
|
};
|
|
4523
4658
|
function schemaVersionKey(record) {
|
|
4524
|
-
const value = record.schema_version ?? record.schemaVersion;
|
|
4659
|
+
const value = record.schema_version ?? record.schemaVersion ?? record.probe_schema ?? record.probeSchema;
|
|
4525
4660
|
if (typeof value === "number" && Number.isFinite(value))
|
|
4526
4661
|
return String(value);
|
|
4527
4662
|
if (typeof value === "string" && value.trim() !== "")
|
|
@@ -5119,7 +5254,7 @@ function ensureBudgetCoordinatorStarted() {
|
|
|
5119
5254
|
if (!BUDGET_CONFIG.enabled)
|
|
5120
5255
|
return;
|
|
5121
5256
|
if (!budgetCoordinator) {
|
|
5122
|
-
log(`Budget coordinator config: pollSeconds=${BUDGET_CONFIG.pollSeconds} pauseAt=${BUDGET_CONFIG.pauseAt} ` + `resumeBelow=${BUDGET_CONFIG.resumeBelow} syncDriftPct=${BUDGET_CONFIG.syncDriftPct} ` + `parallel=${BUDGET_CONFIG.parallel.minRemainingPct}%/${BUDGET_CONFIG.parallel.timeWindowSec}s ` + `codexTierControl=${BUDGET_CONFIG.codexTierControl} ` + `codexTiersFull=${BUDGET_CONFIG.codexTiers.full ? "configured" : "missing"}`);
|
|
5257
|
+
log(`Budget coordinator config: pollSeconds=${BUDGET_CONFIG.pollSeconds} pauseAt=${BUDGET_CONFIG.pauseAt} ` + `resumeBelow=${BUDGET_CONFIG.resumeBelow} syncDriftPct=${BUDGET_CONFIG.syncDriftPct} ` + `parallel=${BUDGET_CONFIG.parallel.minRemainingPct}%/${BUDGET_CONFIG.parallel.timeWindowSec}s ` + `codexTierControl=${BUDGET_CONFIG.codexTierControl} ` + `codexTiersFull=${BUDGET_CONFIG.codexTiers.full ? "configured" : "missing"} ` + `strategy=${BUDGET_CONFIG.strategy}`);
|
|
5123
5258
|
budgetCoordinator = new BudgetCoordinator({
|
|
5124
5259
|
source: createQuotaSource({ log }),
|
|
5125
5260
|
config: BUDGET_CONFIG,
|
package/package.json
CHANGED
|
@@ -13863,7 +13863,48 @@ class StateDirResolver {
|
|
|
13863
13863
|
}
|
|
13864
13864
|
}
|
|
13865
13865
|
|
|
13866
|
+
// src/budget/types.ts
|
|
13867
|
+
var STALE_MAX_AGE_SEC = 600;
|
|
13868
|
+
|
|
13869
|
+
// src/budget/budget-state.ts
|
|
13870
|
+
function isDecisionGrade(usage, now) {
|
|
13871
|
+
if (!usage)
|
|
13872
|
+
return false;
|
|
13873
|
+
const freshWindow = usage.fiveHour !== null && usage.fiveHour.resetEpoch > now || usage.weekly !== null && usage.weekly.resetEpoch > now;
|
|
13874
|
+
if (!freshWindow)
|
|
13875
|
+
return false;
|
|
13876
|
+
if (usage.fetchedAt > 0 && now - usage.fetchedAt > STALE_MAX_AGE_SEC)
|
|
13877
|
+
return false;
|
|
13878
|
+
return true;
|
|
13879
|
+
}
|
|
13880
|
+
|
|
13881
|
+
// src/budget/burn-view.ts
|
|
13882
|
+
function agentWeeklyFiveHourWindowsLeft(usage, now) {
|
|
13883
|
+
if (!usage || usage.stale || !usage.ok)
|
|
13884
|
+
return null;
|
|
13885
|
+
if (!isDecisionGrade(usage, now))
|
|
13886
|
+
return null;
|
|
13887
|
+
const weekly = usage.weekly;
|
|
13888
|
+
if (!weekly || weekly.resetEpoch <= now)
|
|
13889
|
+
return null;
|
|
13890
|
+
if (weekly.burnConfident !== true)
|
|
13891
|
+
return null;
|
|
13892
|
+
if (weekly.runwaySeconds === undefined)
|
|
13893
|
+
return null;
|
|
13894
|
+
return weekly.fiveHourWindowsLeft ?? null;
|
|
13895
|
+
}
|
|
13896
|
+
|
|
13866
13897
|
// src/budget/render.ts
|
|
13898
|
+
var DEFAULT_GUARD_HARD_PCT = 92;
|
|
13899
|
+
function resolveGuardHardHint(env = process.env) {
|
|
13900
|
+
const raw = env.AGENTBRIDGE_GUARD_HARD_HINT;
|
|
13901
|
+
if (raw === undefined || raw.trim() === "")
|
|
13902
|
+
return DEFAULT_GUARD_HARD_PCT;
|
|
13903
|
+
const parsed = Number(raw);
|
|
13904
|
+
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 100)
|
|
13905
|
+
return DEFAULT_GUARD_HARD_PCT;
|
|
13906
|
+
return parsed;
|
|
13907
|
+
}
|
|
13867
13908
|
function formatEpoch(epochSeconds) {
|
|
13868
13909
|
if (!epochSeconds || epochSeconds <= 0)
|
|
13869
13910
|
return "\u672A\u77E5";
|
|
@@ -13897,17 +13938,98 @@ function formatAgent(name, usage, snapshotAt) {
|
|
|
13897
13938
|
}
|
|
13898
13939
|
return `${name}\uFF1A${parts.join(" \xB7 ")}`;
|
|
13899
13940
|
}
|
|
13941
|
+
var WINDOW_LABELS = {
|
|
13942
|
+
fiveHour: "5h \u7A97\u53E3",
|
|
13943
|
+
weekly: "\u5468\u7A97\u53E3"
|
|
13944
|
+
};
|
|
13945
|
+
var RESET_TRUNCATION_EPSILON_SEC = 60;
|
|
13946
|
+
function formatDuration(seconds) {
|
|
13947
|
+
const totalMinutes = Math.max(0, Math.round(seconds / 60));
|
|
13948
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
13949
|
+
const minutes = totalMinutes % 60;
|
|
13950
|
+
if (hours === 0)
|
|
13951
|
+
return `${minutes}\u5206\u949F`;
|
|
13952
|
+
return `${hours}\u5C0F\u65F6${minutes}\u5206\u949F`;
|
|
13953
|
+
}
|
|
13954
|
+
function formatClockTime(epochSeconds) {
|
|
13955
|
+
const date4 = new Date(epochSeconds * 1000);
|
|
13956
|
+
const hh = String(date4.getHours()).padStart(2, "0");
|
|
13957
|
+
const mm = String(date4.getMinutes()).padStart(2, "0");
|
|
13958
|
+
return `${hh}:${mm}`;
|
|
13959
|
+
}
|
|
13960
|
+
function formatWindowRate(label, rate) {
|
|
13961
|
+
if (!rate)
|
|
13962
|
+
return null;
|
|
13963
|
+
if (!rate.confident)
|
|
13964
|
+
return `${label} \u91C7\u6837\u4E2D`;
|
|
13965
|
+
return `${label} \u2248${rate.pctPerHour.toFixed(2)}%/h`;
|
|
13966
|
+
}
|
|
13967
|
+
function formatRunwaySegment(runway, basisWindow, snapshotAt) {
|
|
13968
|
+
const truncatedByReset = basisWindow !== null && basisWindow.resetEpoch > 0 && snapshotAt + runway.seconds >= basisWindow.resetEpoch - RESET_TRUNCATION_EPSILON_SEC;
|
|
13969
|
+
const clock = runway.depletedAtEpoch ? formatClockTime(runway.depletedAtEpoch) : null;
|
|
13970
|
+
let clockNote;
|
|
13971
|
+
if (clock) {
|
|
13972
|
+
clockNote = truncatedByReset ? `\u81F3 ${clock} \u7A97\u53E3\u5237\u65B0\u5373\u622A\u65AD\uFF0C` : `\u81F3 ${clock}\uFF0C`;
|
|
13973
|
+
} else {
|
|
13974
|
+
clockNote = truncatedByReset ? "\u7A97\u53E3\u5237\u65B0\u5373\u622A\u65AD\uFF0C" : "";
|
|
13975
|
+
}
|
|
13976
|
+
return `\u7EA6\u53EF\u518D\u5DE5\u4F5C ${formatDuration(runway.seconds)}\uFF08${clockNote}${WINDOW_LABELS[runway.basis]}\u4E3A\u7EA6\u675F\uFF09`;
|
|
13977
|
+
}
|
|
13978
|
+
function formatBurnRateLine(name, usage, rates, runway, snapshotAt, guardHardPct) {
|
|
13979
|
+
const parts = [
|
|
13980
|
+
formatWindowRate("5h", rates.fiveHour),
|
|
13981
|
+
formatWindowRate("\u5468", rates.weekly)
|
|
13982
|
+
].filter((part) => part !== null);
|
|
13983
|
+
if (parts.length === 0 && !runway)
|
|
13984
|
+
return null;
|
|
13985
|
+
if (runway) {
|
|
13986
|
+
const basisWindow = usage ? usage[runway.basis] : null;
|
|
13987
|
+
parts.push(formatRunwaySegment(runway, basisWindow, snapshotAt));
|
|
13988
|
+
}
|
|
13989
|
+
if (guardHardPct !== null) {
|
|
13990
|
+
parts.push(`\u5916\u5C42 guard \u786C\u7EBF ${guardHardPct}%\uFF08v3 \u4E0D\u53EF\u8D8A\u8FC7\uFF1Brunway \u4E3A\u4E2D\u6027\u53E3\u5F84\uFF0CClaude \u4F1A\u5148\u5728\u786C\u7EBF\u88AB\u5916\u5C42\u505C\u4F4F\uFF09`);
|
|
13991
|
+
}
|
|
13992
|
+
return `${name} \u71C3\u5C3D\u7387\uFF1A${parts.join(" \xB7 ")}`;
|
|
13993
|
+
}
|
|
13994
|
+
function formatFiveHourWindowsLeftLine(snapshot) {
|
|
13995
|
+
const values = [];
|
|
13996
|
+
const claude = agentWeeklyFiveHourWindowsLeft(snapshot.claude, snapshot.updatedAt);
|
|
13997
|
+
const codex = agentWeeklyFiveHourWindowsLeft(snapshot.codex, snapshot.updatedAt);
|
|
13998
|
+
if (claude !== null)
|
|
13999
|
+
values.push(["Claude", claude]);
|
|
14000
|
+
if (codex !== null)
|
|
14001
|
+
values.push(["Codex", codex]);
|
|
14002
|
+
if (values.length === 0)
|
|
14003
|
+
return null;
|
|
14004
|
+
const unique = [...new Set(values.map(([, value]) => value.toFixed(1)))];
|
|
14005
|
+
if (unique.length === 1)
|
|
14006
|
+
return `\u6309\u5F53\u524D\u8282\u594F\uFF0C\u5468\u989D\u5EA6\u8FD8\u591F ~${unique[0]} \u4E2A 5h \u7A97\u53E3`;
|
|
14007
|
+
const byAgent = values.map(([name, value]) => `${name} ~${value.toFixed(1)}`).join(" / ");
|
|
14008
|
+
return `\u6309\u5F53\u524D\u8282\u594F\uFF0C\u5468\u989D\u5EA6\u8FD8\u591F ${byAgent} \u4E2A 5h \u7A97\u53E3`;
|
|
14009
|
+
}
|
|
13900
14010
|
var PHASE_LABELS = {
|
|
13901
14011
|
normal: "normal\uFF08\u6B63\u5E38\uFF09",
|
|
13902
14012
|
balance: "balance\uFF08\u9700\u5747\u8861\uFF09",
|
|
13903
14013
|
parallel: "parallel\uFF08\u5EFA\u8BAE\u5E76\u884C\u63D0\u901F\uFF09",
|
|
13904
14014
|
paused: "paused\uFF08\u9884\u7B97\u5E72\u9884\u4E2D\uFF09"
|
|
13905
14015
|
};
|
|
13906
|
-
function renderBudgetSnapshot(snapshot) {
|
|
14016
|
+
function renderBudgetSnapshot(snapshot, options = {}) {
|
|
14017
|
+
const guardHardPct = options.guardHardPct ?? resolveGuardHardHint();
|
|
13907
14018
|
const lines = [];
|
|
13908
14019
|
lines.push(`\u3010\u9884\u7B97\u5FEB\u7167 \xB7 \u8D26\u53F7\u7EA7\u3011\u9636\u6BB5\uFF1A${PHASE_LABELS[snapshot.phase]} \xB7 \u66F4\u65B0\u4E8E ${formatEpoch(snapshot.updatedAt)}`);
|
|
13909
14020
|
lines.push(formatAgent("Claude", snapshot.claude, snapshot.updatedAt));
|
|
13910
14021
|
lines.push(formatAgent("Codex", snapshot.codex, snapshot.updatedAt));
|
|
14022
|
+
if (snapshot.burnRate) {
|
|
14023
|
+
const claudeLine = formatBurnRateLine("Claude", snapshot.claude, snapshot.burnRate.claude, snapshot.runway?.claude ?? null, snapshot.updatedAt, guardHardPct);
|
|
14024
|
+
if (claudeLine)
|
|
14025
|
+
lines.push(claudeLine);
|
|
14026
|
+
const codexLine = formatBurnRateLine("Codex", snapshot.codex, snapshot.burnRate.codex, snapshot.runway?.codex ?? null, snapshot.updatedAt, null);
|
|
14027
|
+
if (codexLine)
|
|
14028
|
+
lines.push(codexLine);
|
|
14029
|
+
}
|
|
14030
|
+
const fiveHourWindowsLeftLine = formatFiveHourWindowsLeftLine(snapshot);
|
|
14031
|
+
if (fiveHourWindowsLeftLine)
|
|
14032
|
+
lines.push(fiveHourWindowsLeftLine);
|
|
13911
14033
|
if (snapshot.claude && snapshot.codex) {
|
|
13912
14034
|
const abs = Math.abs(snapshot.driftPct);
|
|
13913
14035
|
if (abs > 0) {
|
|
@@ -14389,11 +14511,11 @@ function defineNumber(value, fallback) {
|
|
|
14389
14511
|
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
14390
14512
|
}
|
|
14391
14513
|
var BUILD_INFO = Object.freeze({
|
|
14392
|
-
version: defineString("0.1.
|
|
14393
|
-
commit: defineString("
|
|
14514
|
+
version: defineString("0.1.15", "0.0.0-source"),
|
|
14515
|
+
commit: defineString("89d4c9a", "source"),
|
|
14394
14516
|
bundle: defineBundle("plugin"),
|
|
14395
14517
|
contractVersion: defineNumber(1, CONTRACT_VERSION),
|
|
14396
|
-
codeHash: defineString("
|
|
14518
|
+
codeHash: defineString("71ce81854ec9", "source")
|
|
14397
14519
|
});
|
|
14398
14520
|
function sameRuntimeContract(a, b) {
|
|
14399
14521
|
if (!a || !b)
|
|
@@ -15424,7 +15546,8 @@ var DEFAULT_BUDGET_CONFIG = {
|
|
|
15424
15546
|
full: null,
|
|
15425
15547
|
balanced: { effort: "medium" },
|
|
15426
15548
|
eco: { effort: "low" }
|
|
15427
|
-
}
|
|
15549
|
+
},
|
|
15550
|
+
strategy: "conserve"
|
|
15428
15551
|
};
|
|
15429
15552
|
var DEFAULT_CONFIG = {
|
|
15430
15553
|
version: "1.0",
|
|
@@ -15502,6 +15625,9 @@ function normalizeBoundedInteger(value, fallback, min, max) {
|
|
|
15502
15625
|
return fallback;
|
|
15503
15626
|
return parsed;
|
|
15504
15627
|
}
|
|
15628
|
+
function normalizeStrategy(value, fallback) {
|
|
15629
|
+
return value === "conserve" || value === "maximize" ? value : fallback;
|
|
15630
|
+
}
|
|
15505
15631
|
function normalizeBoolean(value, fallback) {
|
|
15506
15632
|
if (typeof value === "boolean")
|
|
15507
15633
|
return value;
|
|
@@ -15550,7 +15676,8 @@ function normalizeBudgetConfig(raw, fallback = DEFAULT_BUDGET_CONFIG) {
|
|
|
15550
15676
|
timeWindowSec: normalizeBoundedInteger(parallel.timeWindowSec, fallback.parallel.timeWindowSec, 60, 604800)
|
|
15551
15677
|
},
|
|
15552
15678
|
codexTierControl: normalizeBoolean(budget.codexTierControl, fallback.codexTierControl) && codexTiers.full !== null,
|
|
15553
|
-
codexTiers
|
|
15679
|
+
codexTiers,
|
|
15680
|
+
strategy: normalizeStrategy(budget.strategy, fallback.strategy)
|
|
15554
15681
|
};
|
|
15555
15682
|
}
|
|
15556
15683
|
function normalizeConfig(raw) {
|