pi-harness-runtime 1.1.506 → 1.1.507
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -0
- package/harness/provider-quota-reset.ts +53 -19
- package/harness/provider-recovery-runtime.ts +20 -0
- package/harness/quota-capture.ts +150 -0
- package/harness/quota-low-remaining.ts +75 -0
- package/harness/quota-reset-duration.ts +87 -0
- package/harness/quota-threshold.ts +117 -0
- package/harness/resume-scope.ts +85 -0
- package/harness/scope-expansion.ts +438 -0
- package/index.ts +212 -7
- package/mirror.ts +4 -0
- package/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/contracts/package.json +1 -1
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/notification/dist/adapters/detail-format.d.ts +5 -2
- package/packages/notification/dist/adapters/detail-format.d.ts.map +1 -1
- package/packages/notification/dist/adapters/detail-format.js +17 -0
- package/packages/notification/dist/adapters/detail-format.js.map +1 -1
- package/packages/notification/dist/adapters/email-adapter.d.ts.map +1 -1
- package/packages/notification/dist/adapters/email-adapter.js +1 -0
- package/packages/notification/dist/adapters/email-adapter.js.map +1 -1
- package/packages/notification/dist/adapters/line-adapter.d.ts.map +1 -1
- package/packages/notification/dist/adapters/line-adapter.js +1 -0
- package/packages/notification/dist/adapters/line-adapter.js.map +1 -1
- package/packages/notification/dist/adapters/ntfy-adapter.d.ts.map +1 -1
- package/packages/notification/dist/adapters/ntfy-adapter.js +1 -0
- package/packages/notification/dist/adapters/ntfy-adapter.js.map +1 -1
- package/packages/notification/dist/adapters/telegram-adapter.d.ts.map +1 -1
- package/packages/notification/dist/adapters/telegram-adapter.js +1 -0
- package/packages/notification/dist/adapters/telegram-adapter.js.map +1 -1
- package/packages/notification/dist/notification-center.d.ts.map +1 -1
- package/packages/notification/dist/notification-center.js +10 -0
- package/packages/notification/dist/notification-center.js.map +1 -1
- package/packages/notification/dist/types.d.ts +14 -1
- package/packages/notification/dist/types.d.ts.map +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/notification/src/adapters/detail-format.ts +29 -2
- package/packages/notification/src/adapters/email-adapter.ts +1 -0
- package/packages/notification/src/adapters/line-adapter.ts +1 -0
- package/packages/notification/src/adapters/ntfy-adapter.ts +1 -0
- package/packages/notification/src/adapters/telegram-adapter.ts +1 -0
- package/packages/notification/src/notification-center.ts +14 -0
- package/packages/notification/src/types.ts +14 -0
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/tooling-preference/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/two-phase-review/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/write-review/package.json +1 -1
package/index.ts
CHANGED
|
@@ -86,6 +86,15 @@ import {
|
|
|
86
86
|
} from "./harness/pi-retry-policy.ts";
|
|
87
87
|
import { ProviderRecoveryRuntime } from "./harness/provider-recovery-runtime.ts";
|
|
88
88
|
import { confirmedQuotaReset } from "./harness/provider-quota-reset.ts";
|
|
89
|
+
import { resetEpochFromDuration } from "./harness/quota-reset-duration.ts";
|
|
90
|
+
import { QuotaCaptureController } from "./harness/quota-capture.ts";
|
|
91
|
+
import { QuotaLowRemainingTracker } from "./harness/quota-low-remaining.ts";
|
|
92
|
+
import { remainingPctFromUsedPct } from "./harness/quota-threshold.ts";
|
|
93
|
+
import {
|
|
94
|
+
decideResumeScope,
|
|
95
|
+
RESUME_SCOPE_RULE,
|
|
96
|
+
type ResumeWorkState,
|
|
97
|
+
} from "./harness/resume-scope.ts";
|
|
89
98
|
import type { ProviderFailure } from "./harness/provider-failure.ts";
|
|
90
99
|
import {
|
|
91
100
|
createProviderRecoveryController,
|
|
@@ -130,6 +139,7 @@ import {
|
|
|
130
139
|
} from "./packages/quota-manager/src/tui-usage-monitor.ts";
|
|
131
140
|
import { QuotaManager } from "./packages/quota-manager/src/quota-manager.ts";
|
|
132
141
|
import { buildFooterStatusValue } from "./footer-status.ts";
|
|
142
|
+
import { getProviderLabel } from "./packages/types/src/ai-providers.ts";
|
|
133
143
|
import { registerGithubLoginCommand } from "./packages/clipboard/dist/src/github-login.js";
|
|
134
144
|
import {
|
|
135
145
|
MAX_PROACTIVE_COMPACT_FAILURES,
|
|
@@ -616,8 +626,55 @@ const sharedState = {
|
|
|
616
626
|
delegationHarness: null as any,
|
|
617
627
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
618
628
|
workspaceEnvMessage: null as string | null,
|
|
629
|
+
// The state of the work of the request that is running. The automatic
|
|
630
|
+
// resume reads it to know whether the work of the request remains.
|
|
631
|
+
workContext: null as unknown,
|
|
619
632
|
};
|
|
620
633
|
|
|
634
|
+
/**
|
|
635
|
+
* Was the suppressed resume of this request already reported?
|
|
636
|
+
*
|
|
637
|
+
* The report happens once per request: a suppressed resume is not an event
|
|
638
|
+
* the user has to read again and again.
|
|
639
|
+
*/
|
|
640
|
+
let suppressedResumeReported = false;
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Report that an automatic resume was suppressed.
|
|
644
|
+
*
|
|
645
|
+
* The work of the request is complete, so the resume is not sent and the
|
|
646
|
+
* agent is not told to look for other work. The user learns about it once.
|
|
647
|
+
*/
|
|
648
|
+
function reportSuppressedResume(report: string | undefined): void {
|
|
649
|
+
if (!report || suppressedResumeReported) return;
|
|
650
|
+
suppressedResumeReported = true;
|
|
651
|
+
logToFile("[resume-scope]", report);
|
|
652
|
+
void nc("Info", {
|
|
653
|
+
jobId: "resume-scope-complete",
|
|
654
|
+
requirement: report,
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* The state of the work of the request that is running.
|
|
660
|
+
*
|
|
661
|
+
* An automatic resume continues the request that is running, so it has to
|
|
662
|
+
* know whether that request still has work. An unknown state is not a
|
|
663
|
+
* completion: the uncertainty is preserved and the resume goes on.
|
|
664
|
+
*/
|
|
665
|
+
async function currentRequestWorkState(): Promise<ResumeWorkState> {
|
|
666
|
+
const accessor = sharedState.workContext as
|
|
667
|
+
| null
|
|
668
|
+
| (() => Promise<{ work: ResumeWorkState; scope: string[] }>);
|
|
669
|
+
if (typeof accessor !== "function") return "unknown";
|
|
670
|
+
try {
|
|
671
|
+
const context = await accessor();
|
|
672
|
+
return context.work;
|
|
673
|
+
} catch {
|
|
674
|
+
return "unknown";
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
621
678
|
/**
|
|
622
679
|
* The scope of the request that is running.
|
|
623
680
|
*
|
|
@@ -677,6 +734,9 @@ const requestScopeTracker = new RequestScopeTracker({
|
|
|
677
734
|
*/
|
|
678
735
|
function beginHumanRequest(): void {
|
|
679
736
|
requestScopeTracker.begin();
|
|
737
|
+
// A new request of the human has its own report: the completion of the
|
|
738
|
+
// previous one was already reported.
|
|
739
|
+
suppressedResumeReported = false;
|
|
680
740
|
}
|
|
681
741
|
|
|
682
742
|
/**
|
|
@@ -1438,6 +1498,10 @@ async function initAutoContinue(pi: ExtensionAPI): Promise<void> {
|
|
|
1438
1498
|
}
|
|
1439
1499
|
}
|
|
1440
1500
|
|
|
1501
|
+
// The automatic resume reads the state of the work from here: the
|
|
1502
|
+
// guard belongs to the code, not to the judge.
|
|
1503
|
+
sharedState.workContext = currentWorkContext;
|
|
1504
|
+
|
|
1441
1505
|
/**
|
|
1442
1506
|
* The state of the work of the current request.
|
|
1443
1507
|
*/
|
|
@@ -6684,6 +6748,9 @@ After completing ANY task or unit of work:
|
|
|
6684
6748
|
3. Only stop and report progress when ALL tasks are completed (or genuinely blocked)
|
|
6685
6749
|
4. If blocked (waiting on user input, CI, external dependency), THEN ask
|
|
6686
6750
|
|
|
6751
|
+
**The scope of the work:** the next task is the next task **of this request**.
|
|
6752
|
+
Pending issues in bd or another backlog are not pending work of this request.
|
|
6753
|
+
|
|
6687
6754
|
**Anti-pattern (WRONG):**
|
|
6688
6755
|
> [Task 1 done] → stops → "Done! What would you like me to do next?"
|
|
6689
6756
|
|
|
@@ -6691,12 +6758,15 @@ After completing ANY task or unit of work:
|
|
|
6691
6758
|
> [Task 1 done] → picks Task 2 → works → Task 3 → ... → all done → report
|
|
6692
6759
|
|
|
6693
6760
|
This applies to EVERY turn. Every time you finish something, check todos first.
|
|
6761
|
+
|
|
6762
|
+
${RESUME_SCOPE_RULE}
|
|
6694
6763
|
`;
|
|
6695
6764
|
|
|
6696
6765
|
const COMMIT_BUILD_CHECKLIST = `
|
|
6697
6766
|
|
|
6698
6767
|
BEFORE committing code or triggering builds, ALWAYS check:
|
|
6699
|
-
1. Run \`bd ready\` to see pending **bd issues**
|
|
6768
|
+
1. Run \`bd ready\` to see pending **bd issues** (bookkeeping only — a pending
|
|
6769
|
+
bd issue is not authorized work of the current request)
|
|
6700
6770
|
2. Mark completed issues with \`bd close <id> --reason "Done"\`
|
|
6701
6771
|
3. Acknowledge pending issues before proceeding
|
|
6702
6772
|
4. Never commit/build without acknowledging pending bd issues
|
|
@@ -6795,7 +6865,8 @@ Before running a build, ensure you update the current task status:
|
|
|
6795
6865
|
2. If tracking in **bd issues**: use \`bd update <id> --status in_progress\`
|
|
6796
6866
|
3. After build succeeds: mark completed in the appropriate tracker
|
|
6797
6867
|
|
|
6798
|
-
Run \`bd ready\` to see current bd issues
|
|
6868
|
+
Run \`bd ready\` to see current bd issues (bookkeeping only — a pending bd
|
|
6869
|
+
issue is not authorized work of the current request).
|
|
6799
6870
|
`;
|
|
6800
6871
|
|
|
6801
6872
|
// Detect build commands and log reminder (don't modify result.content)
|
|
@@ -6862,9 +6933,17 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6862
6933
|
sessionBusy: activeExtensionContext?.isIdle?.() === false,
|
|
6863
6934
|
}),
|
|
6864
6935
|
resetEvidence: (failure) => applicableResetEvidence(failure),
|
|
6865
|
-
quotaResetEvidence: (failure, provider) =>
|
|
6866
|
-
|
|
6867
|
-
|
|
6936
|
+
quotaResetEvidence: (failure, provider) => {
|
|
6937
|
+
// A capture that failed means that the row of the mirror is the
|
|
6938
|
+
// old one, and an old row cannot prove a deadline.
|
|
6939
|
+
if (quotaCaptureController.failed(provider)) return undefined;
|
|
6940
|
+
return confirmedQuotaReset(
|
|
6941
|
+
failure,
|
|
6942
|
+
provider,
|
|
6943
|
+
mirrorStore.readProvider(provider.toLowerCase()),
|
|
6944
|
+
Date.now(),
|
|
6945
|
+
);
|
|
6946
|
+
},
|
|
6868
6947
|
overloadDelayMs: () => getProviderOverloadResumeDelayMs(),
|
|
6869
6948
|
overloadMaxAttempts: PROVIDER_OVERLOAD_AUTO_RESUME_LIMIT,
|
|
6870
6949
|
dispatch: async (reason) => {
|
|
@@ -6906,7 +6985,7 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6906
6985
|
|
|
6907
6986
|
// The run settled: the internal retries of Pi are over, so a failure
|
|
6908
6987
|
// that waited for the boundary is final and the recovery starts now.
|
|
6909
|
-
pi.on("agent_settled", (event) => {
|
|
6988
|
+
pi.on("agent_settled", async (event) => {
|
|
6910
6989
|
// An aborted run is a decision of the user, not a failure of the
|
|
6911
6990
|
// provider: an automatic resume would fight the user.
|
|
6912
6991
|
//
|
|
@@ -6924,6 +7003,12 @@ Run \`bd ready\` to see current bd issues.
|
|
|
6924
7003
|
providerFailureAttemptsInRun = 0;
|
|
6925
7004
|
return;
|
|
6926
7005
|
}
|
|
7006
|
+
// A quota failure needs a fresh capture before the recovery picks a
|
|
7007
|
+
// deadline. The capture that the harness has can be hours old, and
|
|
7008
|
+
// a stale capture proves nothing about the reset that is coming.
|
|
7009
|
+
// The capture is not a scheduler: it only refreshes what the
|
|
7010
|
+
// recovery reads.
|
|
7011
|
+
await quotaCaptureController.wait();
|
|
6927
7012
|
providerRecoveryRuntime?.noteSettled();
|
|
6928
7013
|
// The run is over: the streak of its failures ends with it, so the
|
|
6929
7014
|
// next run starts its own count.
|
|
@@ -7049,6 +7134,14 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7049
7134
|
typeof m.errorMessage === "string" ? m.errorMessage : undefined,
|
|
7050
7135
|
),
|
|
7051
7136
|
});
|
|
7137
|
+
// A quota failure needs a fresh capture before the recovery
|
|
7138
|
+
// picks a deadline. The capture runs while Pi retries the
|
|
7139
|
+
// failed turn internally.
|
|
7140
|
+
const quotaCandidate =
|
|
7141
|
+
providerRecoveryRuntime?.pendingQuotaFailure();
|
|
7142
|
+
if (quotaCandidate) {
|
|
7143
|
+
quotaCaptureController.begin(quotaCandidate.provider);
|
|
7144
|
+
}
|
|
7052
7145
|
} else {
|
|
7053
7146
|
// No automatic retry can fix this failure: the row says that
|
|
7054
7147
|
// nothing is scheduled.
|
|
@@ -7089,7 +7182,9 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7089
7182
|
OUTPUT_LIMIT_CONTINUATION_ID,
|
|
7090
7183
|
"the output limit continues the turn",
|
|
7091
7184
|
);
|
|
7092
|
-
await queueAutoResume("output-limit", OUTPUT_LIMIT_RESUME_PROMPT, "steer"
|
|
7185
|
+
await queueAutoResume("output-limit", OUTPUT_LIMIT_RESUME_PROMPT, "steer", {
|
|
7186
|
+
scope: "turn",
|
|
7187
|
+
});
|
|
7093
7188
|
// Emit OutputLimitContinued to Telegram
|
|
7094
7189
|
await nc("OutputLimitContinued", {
|
|
7095
7190
|
requirement: "Session output",
|
|
@@ -7380,6 +7475,7 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7380
7475
|
// JSON.stringify(record),
|
|
7381
7476
|
// );
|
|
7382
7477
|
mirrorStore.writeProvider(provider, { ...record, provider });
|
|
7478
|
+
notifyQuotaLowRemaining(provider, record);
|
|
7383
7479
|
if (footerSetStatus) {
|
|
7384
7480
|
refreshFooterStatus(
|
|
7385
7481
|
footerSetStatus,
|
|
@@ -7391,6 +7487,43 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7391
7487
|
}
|
|
7392
7488
|
}
|
|
7393
7489
|
|
|
7490
|
+
/**
|
|
7491
|
+
* The alert of a low allowance.
|
|
7492
|
+
*
|
|
7493
|
+
* The alert is sent once per crossing: a capture of the same state
|
|
7494
|
+
* again does not send it again, and an allowance that recovers arms it
|
|
7495
|
+
* again. It needs no approval and it costs no attempt of the recovery.
|
|
7496
|
+
*/
|
|
7497
|
+
const quotaLowRemainingTracker = new QuotaLowRemainingTracker();
|
|
7498
|
+
|
|
7499
|
+
function notifyQuotaLowRemaining(
|
|
7500
|
+
provider: ProviderId,
|
|
7501
|
+
record: Omit<import("./mirror.js").ProviderMirrorRecord, "provider">,
|
|
7502
|
+
): void {
|
|
7503
|
+
// No channel, no message: an alert that cannot be sent is not an
|
|
7504
|
+
// alert that was sent.
|
|
7505
|
+
if (!_nc) return;
|
|
7506
|
+
const decision = quotaLowRemainingTracker.observe(
|
|
7507
|
+
provider,
|
|
7508
|
+
record.h5_used_pct,
|
|
7509
|
+
);
|
|
7510
|
+
if (decision !== "notify") return;
|
|
7511
|
+
const remainingPct = remainingPctFromUsedPct(record.h5_used_pct as number);
|
|
7512
|
+
const label = getProviderLabel(provider);
|
|
7513
|
+
const resetAt = record.h5_resets_at_epoch
|
|
7514
|
+
? new Date(record.h5_resets_at_epoch).toISOString()
|
|
7515
|
+
: record.h5_resets_at;
|
|
7516
|
+
void nc("QuotaLowRemaining", {
|
|
7517
|
+
jobId: `quota-low-${provider}`,
|
|
7518
|
+
requirement: `The 5h quota of ${label} is low`,
|
|
7519
|
+
provider: label,
|
|
7520
|
+
quotaWindow: "5h",
|
|
7521
|
+
remainingPct: Math.round(remainingPct * 10) / 10,
|
|
7522
|
+
...(resetAt ? { resetAt } : {}),
|
|
7523
|
+
reason: `The 5h window has ${Math.round(remainingPct * 10) / 10}% left`,
|
|
7524
|
+
});
|
|
7525
|
+
}
|
|
7526
|
+
|
|
7394
7527
|
async function hasBrowserProfileAutoFetchSource(): Promise<boolean> {
|
|
7395
7528
|
try {
|
|
7396
7529
|
const { getLiveSessionPath, getStatusPath } = await import(
|
|
@@ -7478,13 +7611,26 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7478
7611
|
return null;
|
|
7479
7612
|
}
|
|
7480
7613
|
|
|
7614
|
+
// The console writes the remaining time of a window as text. The
|
|
7615
|
+
// mirror needs an absolute moment, and the capture is the anchor
|
|
7616
|
+
// of the text.
|
|
7617
|
+
const observedAt = Date.parse(status.checked_at);
|
|
7618
|
+
|
|
7481
7619
|
return {
|
|
7482
7620
|
synced_at: status.checked_at,
|
|
7483
7621
|
provider: "minimax",
|
|
7484
7622
|
h5_used_pct: parsed.h5UsedPct,
|
|
7485
7623
|
h5_resets_at: parsed.h5ResetsAt,
|
|
7624
|
+
h5_resets_at_epoch: resetEpochFromDuration(
|
|
7625
|
+
parsed.h5ResetsAt,
|
|
7626
|
+
observedAt,
|
|
7627
|
+
),
|
|
7486
7628
|
weekly_used_pct: parsed.weeklyUsedPct,
|
|
7487
7629
|
weekly_resets_at: parsed.weeklyResetsAt,
|
|
7630
|
+
weekly_resets_at_epoch: resetEpochFromDuration(
|
|
7631
|
+
parsed.weeklyResetsAt,
|
|
7632
|
+
observedAt,
|
|
7633
|
+
),
|
|
7488
7634
|
};
|
|
7489
7635
|
} catch (error) {
|
|
7490
7636
|
if (!suppressErrors) {
|
|
@@ -7510,8 +7656,10 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7510
7656
|
model: profileRecord.model,
|
|
7511
7657
|
h5_used_pct: profileRecord.h5_used_pct,
|
|
7512
7658
|
h5_resets_at: profileRecord.h5_resets_at,
|
|
7659
|
+
h5_resets_at_epoch: profileRecord.h5_resets_at_epoch,
|
|
7513
7660
|
weekly_used_pct: profileRecord.weekly_used_pct,
|
|
7514
7661
|
weekly_resets_at: profileRecord.weekly_resets_at,
|
|
7662
|
+
weekly_resets_at_epoch: profileRecord.weekly_resets_at_epoch,
|
|
7515
7663
|
});
|
|
7516
7664
|
return true;
|
|
7517
7665
|
}
|
|
@@ -7676,6 +7824,35 @@ Run \`bd ready\` to see current bd issues.
|
|
|
7676
7824
|
}
|
|
7677
7825
|
}
|
|
7678
7826
|
|
|
7827
|
+
/**
|
|
7828
|
+
* The quota capture of a provider failure.
|
|
7829
|
+
*
|
|
7830
|
+
* The recovery decides when to continue from a capture of the quota,
|
|
7831
|
+
* and the row of the mirror can be hours old. The capture is the one of
|
|
7832
|
+
* the harness: it refreshes the mirror and nothing else, it never
|
|
7833
|
+
* charges an attempt of the recovery and it never schedules anything.
|
|
7834
|
+
*/
|
|
7835
|
+
const quotaCaptureController = new QuotaCaptureController({
|
|
7836
|
+
capture: (provider) => captureQuotaOf(provider),
|
|
7837
|
+
log: (message) => logToFile("[pi-harness]", message),
|
|
7838
|
+
});
|
|
7839
|
+
|
|
7840
|
+
/**
|
|
7841
|
+
* Capture the quota of a provider.
|
|
7842
|
+
*/
|
|
7843
|
+
async function captureQuotaOf(provider: string): Promise<boolean> {
|
|
7844
|
+
if (provider === "minimax") {
|
|
7845
|
+
return autoFetchQuota({ suppressErrors: true });
|
|
7846
|
+
}
|
|
7847
|
+
if (provider === "openai" || provider === "openai-codex") {
|
|
7848
|
+
return autoFetchOpenAIQuota({ suppressErrors: true });
|
|
7849
|
+
}
|
|
7850
|
+
if (provider === "glm") {
|
|
7851
|
+
return autoFetchGLMQuota({ suppressErrors: true });
|
|
7852
|
+
}
|
|
7853
|
+
return false;
|
|
7854
|
+
}
|
|
7855
|
+
|
|
7679
7856
|
async function maybeAutoFetchQuota(
|
|
7680
7857
|
modelId: string | null | undefined,
|
|
7681
7858
|
): Promise<void> {
|
|
@@ -8468,6 +8645,7 @@ Run \`bd ready\` to see current bd issues.
|
|
|
8468
8645
|
"output-limit-settled",
|
|
8469
8646
|
OUTPUT_LIMIT_RESUME_PROMPT,
|
|
8470
8647
|
"followUp",
|
|
8648
|
+
{ scope: "turn" },
|
|
8471
8649
|
);
|
|
8472
8650
|
}, 0);
|
|
8473
8651
|
});
|
|
@@ -8580,8 +8758,35 @@ Run \`bd ready\` to see current bd issues.
|
|
|
8580
8758
|
reason: string,
|
|
8581
8759
|
content: string,
|
|
8582
8760
|
deliverAs: "steer" | "followUp",
|
|
8761
|
+
options: {
|
|
8762
|
+
/**
|
|
8763
|
+
* What the resume continues: the request that is running, or a
|
|
8764
|
+
* turn that was cut off.
|
|
8765
|
+
*
|
|
8766
|
+
* A cut turn is unfinished by definition, so it is resumed
|
|
8767
|
+
* without the guard. A resume of the request is gated: it goes
|
|
8768
|
+
* on only while that request has work.
|
|
8769
|
+
*/
|
|
8770
|
+
scope?: "request" | "turn";
|
|
8771
|
+
} = {},
|
|
8583
8772
|
): Promise<void> {
|
|
8584
8773
|
try {
|
|
8774
|
+
if (options.scope !== "turn") {
|
|
8775
|
+
// An automatic resume continues the request that is running.
|
|
8776
|
+
// It is not an instruction to find more work: a resume that
|
|
8777
|
+
// was queued while the request ran and that is consumed
|
|
8778
|
+
// after it finished would send the agent to the backlog,
|
|
8779
|
+
// and the backlog is not work of this request.
|
|
8780
|
+
const decision = decideResumeScope({
|
|
8781
|
+
work: await currentRequestWorkState(),
|
|
8782
|
+
reason,
|
|
8783
|
+
});
|
|
8784
|
+
if (decision.action === "suppress") {
|
|
8785
|
+
logToFile("[resume-scope]", `Resume suppressed: ${decision.reason}`);
|
|
8786
|
+
reportSuppressedResume(decision.report);
|
|
8787
|
+
return;
|
|
8788
|
+
}
|
|
8789
|
+
}
|
|
8585
8790
|
pi.sendUserMessage(content, { deliverAs });
|
|
8586
8791
|
await nc("ResumeScheduled", {
|
|
8587
8792
|
requirement: "Session auto-resume",
|
package/mirror.ts
CHANGED
|
@@ -106,8 +106,12 @@ export interface MirrorRecord {
|
|
|
106
106
|
model?: string;
|
|
107
107
|
h5_used_pct?: number;
|
|
108
108
|
h5_resets_at?: string;
|
|
109
|
+
/** The absolute epoch of the reset of the five-hour window. */
|
|
110
|
+
h5_resets_at_epoch?: number;
|
|
109
111
|
weekly_used_pct?: number;
|
|
110
112
|
weekly_resets_at?: string;
|
|
113
|
+
/** The absolute epoch of the reset of the weekly window. */
|
|
114
|
+
weekly_resets_at_epoch?: number;
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
|
package/package.json
CHANGED
|
@@ -13,8 +13,11 @@ import type { NotificationEvent, NotificationPayload } from "../types.js";
|
|
|
13
13
|
export declare const ERROR_EVENTS: ReadonlySet<NotificationEvent>;
|
|
14
14
|
export declare function isErrorEvent(event: NotificationEvent): boolean;
|
|
15
15
|
export interface DetailLine {
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* "Error" for a real failure, "Trigger" for a resume trigger, "Reason"
|
|
18
|
+
* for a detail, and the quota labels for the allowance of a window.
|
|
19
|
+
*/
|
|
20
|
+
label: "Error" | "Reason" | "Trigger" | "Provider" | "Window" | "Remaining" | "Resets";
|
|
18
21
|
value: string;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detail-format.d.ts","sourceRoot":"","sources":["../../src/adapters/detail-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE1E,uDAAuD;AACvD,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,iBAAiB,CAItD,CAAC;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAE9D;AAED,MAAM,WAAW,UAAU;IAC1B
|
|
1
|
+
{"version":3,"file":"detail-format.d.ts","sourceRoot":"","sources":["../../src/adapters/detail-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE1E,uDAAuD;AACvD,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,iBAAiB,CAItD,CAAC;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAE9D;AAED,MAAM,WAAW,UAAU;IAC1B;;;OAGG;IACH,KAAK,EACF,OAAO,GACP,QAAQ,GACR,SAAS,GACT,UAAU,GACV,QAAQ,GACR,WAAW,GACX,QAAQ,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACd;AAmBD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUxD;AAQD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAChC,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,EACvC,KAAK,EAAE,iBAAiB,GACtB,UAAU,EAAE,CAkCd;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,EACvC,KAAK,EAAE,iBAAiB,GACtB,MAAM,CAIR"}
|
|
@@ -71,6 +71,10 @@ export function formatDetailLines(details, event) {
|
|
|
71
71
|
const trigger = readString(details?.trigger);
|
|
72
72
|
const reason = readString(details?.reason);
|
|
73
73
|
const error = readString(details?.error);
|
|
74
|
+
const provider = readString(details?.provider);
|
|
75
|
+
const quotaWindow = readString(details?.quotaWindow);
|
|
76
|
+
const resetAt = readString(details?.resetAt);
|
|
77
|
+
const remainingPct = details?.remainingPct;
|
|
74
78
|
if (trigger) {
|
|
75
79
|
lines.push({ label: "Trigger", value: formatTriggerValue(trigger) });
|
|
76
80
|
}
|
|
@@ -80,6 +84,19 @@ export function formatDetailLines(details, event) {
|
|
|
80
84
|
if (error) {
|
|
81
85
|
lines.push({ label: isErrorEvent(event) ? "Error" : "Reason", value: error });
|
|
82
86
|
}
|
|
87
|
+
// The quota of a window is a fact about the allowance, never a failure.
|
|
88
|
+
if (provider) {
|
|
89
|
+
lines.push({ label: "Provider", value: provider });
|
|
90
|
+
}
|
|
91
|
+
if (quotaWindow) {
|
|
92
|
+
lines.push({ label: "Window", value: quotaWindow });
|
|
93
|
+
}
|
|
94
|
+
if (typeof remainingPct === "number" && Number.isFinite(remainingPct)) {
|
|
95
|
+
lines.push({ label: "Remaining", value: `${remainingPct}%` });
|
|
96
|
+
}
|
|
97
|
+
if (resetAt) {
|
|
98
|
+
lines.push({ label: "Resets", value: resetAt });
|
|
99
|
+
}
|
|
83
100
|
return lines;
|
|
84
101
|
}
|
|
85
102
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detail-format.js","sourceRoot":"","sources":["../../src/adapters/detail-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,uDAAuD;AACvD,MAAM,CAAC,MAAM,YAAY,GAAmC,IAAI,GAAG,CAAoB;IACtF,YAAY;IACZ,WAAW;IACX,OAAO;CACP,CAAC,CAAC;AAEH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACpD,OAAO,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC;
|
|
1
|
+
{"version":3,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A4BxD,qBAAa,YAAa,SAAQ,kBAAkB;IACnD,QAAQ,CAAC,EAAE,WAAW;IACtB,QAAQ,CAAC,IAAI,WAAW;IAExB,YAAY,MAAM,EAAE,WAAW,EAE9B;IAEK,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAWnC;IAEK,IAAI,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA0BpE;IAED,OAAO,CAAC,UAAU;IAsBlB,OAAO,CAAC,QAAQ;
|
|
1
|
+
{"version":3,"file":"email-adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/email-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACX,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AA4BxD,qBAAa,YAAa,SAAQ,kBAAkB;IACnD,QAAQ,CAAC,EAAE,WAAW;IACtB,QAAQ,CAAC,IAAI,WAAW;IAExB,YAAY,MAAM,EAAE,WAAW,EAE9B;IAEK,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAWnC;IAEK,IAAI,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA0BpE;IAED,OAAO,CAAC,UAAU;IAsBlB,OAAO,CAAC,QAAQ;CAkBhB"}
|