@humwick/runner 0.130.4 → 0.130.6
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/LICENSE +661 -167
- package/agent-bin/humwick +2 -2
- package/agent-bin/humwick-browser +4 -0
- package/hooks/fff-search-redirect/fff-search-redirect.cjs +1 -1
- package/hooks/web-tools-redirect/web-tools-redirect.cjs +2 -2
- package/package.json +8 -11
- package/plugins/browser/skills/playwright-cli/SKILL.md +8 -6
- package/plugins/claude/.claude-plugin/plugin.json +3 -3
- package/plugins/claude/claude-statusline-probe.cjs +26 -16
- package/plugins/claude/hooks/gate-run-guard.provisioned.mjs +47 -17
- package/plugins/claude/hooks/gate-run-guard.sh +3 -3
- package/plugins/claude/hooks/gate-run-guard.ts +5 -5
- package/plugins/claude/hooks/kill-guard.provisioned.mjs +1 -1
- package/plugins/claude/hooks/kill-guard.sh +4 -4
- package/plugins/claude/hooks/kill-guard.ts +2 -2
- package/plugins/claude/hooks/permission-request.sh +1 -1
- package/plugins/claude/hooks/post-compact.sh +1 -1
- package/plugins/claude/hooks/post-tool-use.sh +3 -3
- package/plugins/claude/hooks/pre-compact.sh +2 -2
- package/plugins/claude/hooks/read-only-bash-guard.sh +4 -4
- package/plugins/claude/hooks/relay-status.sh +32 -32
- package/plugins/claude/hooks/session-end.sh +2 -2
- package/plugins/claude/hooks/session-start.sh +3 -3
- package/plugins/claude/hooks/shell-trust.ts +1 -1
- package/plugins/claude/hooks/stop-failure.sh +2 -2
- package/plugins/claude/hooks/stop.sh +6 -6
- package/plugins/claude/hooks/subagent-skill-policy.cjs +8 -6
- package/plugins/claude/hooks/subagent-stop.sh +3 -3
- package/plugins/claude/hooks/user-prompt-submit.sh +1 -1
- package/plugins/claude/hooks/wait-loop-guard.ts +3 -3
- package/plugins/claude/monitors/monitors.json +2 -2
- package/plugins/claude/monitors/relay-monitor.provisioned.mjs +96 -62
- package/plugins/claude/monitors/relay-monitor.ts +5 -5
- package/plugins/claude/skills/label/SKILL.md +3 -3
- package/plugins/claude/skills/message/SKILL.md +5 -5
- package/plugins/claude/skills/react/SKILL.md +1 -1
- package/plugins/claude/skills/read-message/SKILL.md +4 -4
- package/plugins/claude/skills/reply/SKILL.md +5 -5
- package/plugins/claude/skills/send-claimable/SKILL.md +5 -5
- package/plugins/claude/skills/slice-first/SKILL.md +5 -3
- package/plugins/claude/skills/slice-first/references/plan-recipe.md +30 -29
- package/plugins/claude/skills/status/SKILL.md +3 -3
- package/plugins/claude/skills/tags/SKILL.md +5 -5
- package/plugins/claude/skills/task/SKILL.md +10 -10
- package/plugins/claude-output-style/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-output-style/output-styles/{agent-relay.md → humwick.md} +1 -1
- package/plugins/codex/skills/guide/SKILL.md +3 -3
- package/plugins/codex/skills/label/SKILL.md +3 -3
- package/plugins/codex/skills/message/SKILL.md +5 -5
- package/plugins/codex/skills/react/SKILL.md +1 -1
- package/plugins/codex/skills/read-message/SKILL.md +4 -4
- package/plugins/codex/skills/reply/SKILL.md +5 -5
- package/plugins/codex/skills/send-claimable/SKILL.md +5 -5
- package/plugins/codex/skills/slice-first/SKILL.md +5 -3
- package/plugins/codex/skills/slice-first/references/plan-recipe.md +30 -29
- package/plugins/codex/skills/status/SKILL.md +3 -3
- package/plugins/codex/skills/tags/SKILL.md +5 -5
- package/plugins/codex/skills/task/SKILL.md +11 -10
- package/src/adapter.ts +95 -92
- package/src/adapters/claude-api.ts +8 -11
- package/src/adapters/claude-context-command.ts +1 -1
- package/src/adapters/claude-credentials.ts +7 -3
- package/src/adapters/claude-delivery-lanes.ts +2 -2
- package/src/adapters/claude-delivery.ts +16 -16
- package/src/adapters/claude-effort.ts +2 -2
- package/src/adapters/claude-exit.ts +2 -2
- package/src/adapters/claude-headless-mirror.ts +18 -2
- package/src/adapters/claude-headless-refusal.ts +3 -3
- package/src/adapters/claude-headless.ts +11 -10
- package/src/adapters/claude-launch-exit.ts +1 -1
- package/src/adapters/claude-monitor-delivery-plan.ts +36 -16
- package/src/adapters/claude-permission.ts +5 -5
- package/src/adapters/claude-prompt-gates.ts +9 -9
- package/src/adapters/claude-prompt-hook.ts +2 -2
- package/src/adapters/claude-session-capture.ts +6 -6
- package/src/adapters/claude-session-probe.ts +25 -25
- package/src/adapters/claude-shutdown.ts +11 -11
- package/src/adapters/claude-status-detectors.ts +31 -31
- package/src/adapters/claude-subagents.ts +7 -7
- package/src/adapters/claude-submit-confirmation.ts +6 -6
- package/src/adapters/claude-tmux.ts +43 -43
- package/src/adapters/claude-token-usage-capture.ts +5 -5
- package/src/adapters/claude-tool-policy.ts +7 -7
- package/src/adapters/claude-transcript.ts +24 -24
- package/src/adapters/claude.ts +100 -100
- package/src/adapters/codex-agent-message-capture.ts +26 -63
- package/src/adapters/codex-app-server.ts +1 -1
- package/src/adapters/codex-client.ts +9 -9
- package/src/adapters/codex-effective-config.ts +1 -1
- package/src/adapters/codex-launch-config.ts +5 -5
- package/src/adapters/codex-rollout-context.ts +2 -2
- package/src/adapters/codex-skill-discovery.ts +1 -1
- package/src/adapters/codex-token-usage-capture.ts +16 -16
- package/src/adapters/codex-tool-output.ts +4 -4
- package/src/adapters/codex-version.ts +3 -3
- package/src/adapters/codex.ts +64 -64
- package/src/adapters/opencode-api.ts +1 -1
- package/src/adapters/opencode-context.ts +20 -22
- package/src/adapters/opencode-model-registry.ts +7 -7
- package/src/adapters/opencode-provider.ts +8 -8
- package/src/adapters/opencode-provisioning.ts +30 -0
- package/src/adapters/opencode-server-retry.ts +1 -1
- package/src/adapters/opencode-soft-steer.ts +5 -5
- package/src/adapters/opencode-spawn.ts +18 -14
- package/src/adapters/opencode-token-usage-capture.ts +12 -12
- package/src/adapters/opencode-tool-events.ts +15 -15
- package/src/adapters/opencode.ts +232 -232
- package/src/adapters/project-shell.ts +11 -11
- package/src/adapters/service-access.ts +6 -6
- package/src/adapters/tmux-offload.ts +9 -9
- package/src/adapters/tool-summary.ts +5 -5
- package/src/agent-redact.ts +1 -1
- package/src/agent-runner/commands/dispatch.ts +10 -10
- package/src/agent-runner/commands/lifecycle.ts +2 -2
- package/src/agent-runner/commands/prompt.ts +19 -19
- package/src/agent-runner/credentials.ts +5 -5
- package/src/agent-runner/inbox.ts +1 -1
- package/src/agent-runner/lifecycle-milestones.ts +3 -3
- package/src/agent-runner/lifecycle-phase.ts +2 -2
- package/src/agent-runner/liveness-exchange.ts +4 -10
- package/src/agent-runner/registration.ts +8 -8
- package/src/agent-runner/runner-context.ts +9 -14
- package/src/agent-runner/session-mirror.ts +12 -12
- package/src/agent-runner/task-claims.ts +2 -2
- package/src/agent-runner/token-usage-coverage.ts +1 -1
- package/src/agent-runner/turn-report.ts +12 -12
- package/src/api-budget-accounting.ts +3 -3
- package/src/area-memory.ts +6 -6
- package/src/artifact-path-materialize.ts +1 -1
- package/src/async-guard.ts +5 -5
- package/src/attachment-cache.ts +17 -22
- package/src/background-script-reconcile.ts +6 -6
- package/src/bounded-log.ts +1 -1
- package/src/busy-reconciler.ts +22 -22
- package/src/claim-tracker.ts +3 -3
- package/src/claude-settings.ts +8 -8
- package/src/claude-system-prompt.ts +1 -1
- package/src/claude-workspace-trust.ts +1 -1
- package/src/config.ts +62 -61
- package/src/context-boundary.ts +5 -5
- package/src/context-command.ts +3 -3
- package/src/control-server.ts +32 -32
- package/src/delivery-result.ts +2 -2
- package/src/effort-command.ts +2 -2
- package/src/empty-turn.ts +22 -14
- package/src/free-port.ts +1 -1
- package/src/gate-run-config.ts +3 -3
- package/src/host-asset-plan.ts +24 -17
- package/src/host-claude-config-worker.ts +2 -2
- package/src/host-sources.ts +2 -2
- package/src/index.ts +16 -16
- package/src/launch-assembly.ts +94 -96
- package/src/liveness.ts +15 -15
- package/src/logger.ts +3 -3
- package/src/mcp-outbox.ts +3 -3
- package/src/mcp-preflight.ts +2 -2
- package/src/mcp-source-selection.ts +2 -2
- package/src/mcp-tool-deferral.ts +1 -1
- package/src/mcp-vault-env.ts +2 -2
- package/src/message-body-config/config.ts +4 -4
- package/src/mid-turn-delivery.ts +2 -2
- package/src/native-memory-lever.ts +8 -8
- package/src/outbox.ts +15 -15
- package/src/pending-permission-store.ts +1 -1
- package/src/profile-home.ts +19 -19
- package/src/profile-projection.ts +26 -24
- package/src/project-instructions.ts +5 -5
- package/src/provider-auth-warning.ts +17 -0
- package/src/provider-double.ts +1 -1
- package/src/provider-hold.ts +3 -3
- package/src/provider-home-marker.ts +1 -1
- package/src/provider-home-tombstone.ts +1 -1
- package/src/provider-input-queue.ts +2 -2
- package/src/provider-integration.ts +15 -13
- package/src/provider-setup.ts +15 -3
- package/src/providers.ts +1 -1
- package/src/provisioning.ts +37 -40
- package/src/question-decision.ts +2 -2
- package/src/quota.ts +0 -6
- package/src/rate-limit.ts +24 -13
- package/src/refused-prompt-store.ts +2 -2
- package/src/relay-injection-events.ts +2 -2
- package/src/relay-instructions.ts +5 -5
- package/src/relay-mcp-proxy.long-turn-e2e.ts +13 -13
- package/src/relay-mcp-proxy.ts +57 -58
- package/src/relay-mcp.ts +55 -69
- package/src/reply-obligation-cache.ts +9 -9
- package/src/response-capture-report.ts +9 -9
- package/src/response-routing.ts +1 -1
- package/src/runner-core.ts +209 -222
- package/src/runner-exit.ts +1 -1
- package/src/runner-helpers.ts +10 -10
- package/src/runner-insights.ts +4 -2
- package/src/runner-mcp-proxy.ts +3 -3
- package/src/runner-spawn-config.ts +3 -3
- package/src/runtime-token-file.ts +1 -1
- package/src/runtime-token-remint.ts +1 -1
- package/src/service-access.ts +2 -2
- package/src/session-destroy.ts +1 -1
- package/src/session-insights.ts +1 -1
- package/src/session-scratch.ts +24 -37
- package/src/spawn-input.ts +6 -6
- package/src/startup-config-fetch.ts +4 -4
- package/src/subreaper.ts +3 -5
- package/src/test-run-dedup.ts +13 -13
- package/src/transcript-context.ts +2 -2
- package/src/transport-errors.ts +1 -1
- package/src/turn-opener.ts +1 -1
- package/src/turn-reconcile-event.ts +2 -2
- package/src/vault-proxy-hop.ts +2 -2
- package/src/web-tools.ts +2 -2
- package/agent-bin/agent-relay-browser +0 -10
- package/plugins/claude/skills/disconnect/SKILL.md +0 -16
- package/plugins/claude/skills/pair/SKILL.md +0 -30
- package/plugins/codex/skills/disconnect/SKILL.md +0 -15
- package/plugins/codex/skills/pair/SKILL.md +0 -29
- package/src/adapters/provider-quota-harvest.ts +0 -76
package/src/vault-proxy-hop.ts
CHANGED
|
@@ -19,7 +19,7 @@ function basic(user: string, password: string): string {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* a running provider cannot take a new proxy URL, and Agent Vault sessions cannot be extended.
|
|
23
23
|
* The provider therefore talks to this loopback hop, which forwards each request to the Vault proxy with
|
|
24
24
|
* the current session token. Agent Vault authenticates at CONNECT, so rotation never touches open tunnels.
|
|
25
25
|
*/
|
|
@@ -36,7 +36,7 @@ export async function startVaultProxyHop(upstreamUrl: string, vault: string, tok
|
|
|
36
36
|
const [requestLine = "", ...headers] = head.split("\r\n");
|
|
37
37
|
const presented = Buffer.from(headers.find((line) => /^proxy-authorization:/i.test(line))?.slice(20).trim() ?? "");
|
|
38
38
|
if (presented.length !== expected.length || !timingSafeEqual(presented, expected)) {
|
|
39
|
-
client.end("HTTP/1.1 407 Proxy Authentication Required\r\nProxy-Authenticate: Basic realm=\"
|
|
39
|
+
client.end("HTTP/1.1 407 Proxy Authentication Required\r\nProxy-Authenticate: Basic realm=\"humwick\"\r\nContent-Length: 0\r\nConnection: close\r\n\r\n");
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
const tunnel = /^CONNECT\s/i.test(requestLine);
|
package/src/web-tools.ts
CHANGED
|
@@ -32,7 +32,7 @@ export function claudeWebToolsSteer(config: WebToolsConfig): string {
|
|
|
32
32
|
|
|
33
33
|
/** Always set, so a launch never inherits a parent agent's list. */
|
|
34
34
|
export function webToolsEnv(config: WebToolsConfig): Record<string, string> {
|
|
35
|
-
return writeChildEnv({}, { [WEB_TOOLS_ENV]: launchWebTools(config).join(","),
|
|
35
|
+
return writeChildEnv({}, { [WEB_TOOLS_ENV]: launchWebTools(config).join(","), HUMWICK_WEB_SEARCH: webSearchEnabledFromEnv() ? "1" : "0" }, []);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/** Codex hides switched-off tools on the flat bridge with its native per-server denylist. */
|
|
@@ -47,7 +47,7 @@ export function openCodeWebToolsConfig(config: WebToolsConfig): { tools?: Record
|
|
|
47
47
|
return disabled.length ? { tools: Object.fromEntries(disabled.map((tool) => [`${SHARED_MCP_SERVER_NAME}_${tool}`, false])) } : {};
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/**
|
|
50
|
+
/** Codex's one web_search tool also owns open/find; it cannot disable search and fetch separately. */
|
|
51
51
|
export function codexWebToolsConfigArgs(config: WebToolsConfig): string[] {
|
|
52
52
|
return launchWebTools(config).length ? ["-c", 'web_search="disabled"'] : [];
|
|
53
53
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
# Humwick #3489: `humwick browser` from the release this agent's runner belongs to, never an older
|
|
3
|
-
# install a login shell puts first on PATH. Checkout: <root>/runner/agent-bin -> <root>/src;
|
|
4
|
-
# npm: node_modules/@humwick/runner/agent-bin -> node_modules/@humwick/server/src.
|
|
5
|
-
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P) || exit 1
|
|
6
|
-
for cli in "$here/../../src/index.ts" "$here/../../server/src/index.ts"; do
|
|
7
|
-
if [ -f "$cli" ]; then exec "${AGENT_RELAY_BUN_BIN:-bun}" run --no-env-file "$cli" browser "$@"; fi
|
|
8
|
-
done
|
|
9
|
-
echo "agent-relay-browser: no Humwick CLI next to $here" >&2
|
|
10
|
-
exit 127
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: disconnect
|
|
3
|
-
description: End the current Humwick pair session. Use when the user invokes /disconnect or asks to hang up, unpair, or disconnect from a paired agent.
|
|
4
|
-
argument-hint: "[PAIR_ID]"
|
|
5
|
-
allowed-tools: [Bash]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Humwick Disconnect
|
|
9
|
-
|
|
10
|
-
Run:
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
agent-relay /disconnect $ARGUMENTS
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
If no pair id is supplied, the CLI ends the active pair for this session. Report the result briefly.
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pair
|
|
3
|
-
description: Start, inspect, accept, reject, or send messages in an Humwick two-agent pair session. Use when the user invokes /pair or asks to pair this agent with Codex, Claude, or another relay agent.
|
|
4
|
-
argument-hint: "<target|status|accept|reject|send> [args]"
|
|
5
|
-
allowed-tools: [Bash]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# Humwick Pair
|
|
9
|
-
|
|
10
|
-
Run the Humwick CLI with the user's arguments:
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
agent-relay /pair $ARGUMENTS
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Use this for pair-session commands such as:
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
agent-relay /pair codex "Debug flaky tests"
|
|
20
|
-
agent-relay /pair status
|
|
21
|
-
agent-relay /pair accept PAIR_ID
|
|
22
|
-
agent-relay /pair reject PAIR_ID
|
|
23
|
-
agent-relay /pair send PAIR_ID --stdin <<'EOF'
|
|
24
|
-
What do you see?
|
|
25
|
-
EOF
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
Report the command output briefly. If the CLI cannot detect this session's agent id, rerun with `--agent AGENT_ID` or `--from AGENT_ID` using the Humwick ID shown in session context.
|
|
29
|
-
|
|
30
|
-
Always pass the message body via a quoted heredoc into `--stdin` (or `--body-file PATH`), never inline in the shell command: backticks / `$(...)` in a body are otherwise command-substituted by your shell before `agent-relay` runs (#1263).
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: disconnect
|
|
3
|
-
description: End the current Humwick pair session. Use when the user invokes /disconnect or asks to hang up, unpair, or disconnect from a paired agent.
|
|
4
|
-
argument-hint: "[PAIR_ID]"
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Humwick Disconnect
|
|
8
|
-
|
|
9
|
-
Run:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
agent-relay /disconnect $ARGUMENTS
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
If no pair id is supplied, the CLI ends the active pair for this session. Report the result briefly.
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pair
|
|
3
|
-
description: Start, inspect, accept, reject, or send messages in an Humwick two-agent pair session. Use when the user invokes /pair or asks to pair this agent with Codex, Claude, or another relay agent.
|
|
4
|
-
argument-hint: "<target|status|accept|reject|send> [args]"
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Humwick Pair
|
|
8
|
-
|
|
9
|
-
Run the Humwick CLI with the user's arguments:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
agent-relay /pair $ARGUMENTS
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Use this for pair-session commands such as:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
agent-relay /pair codex "Debug flaky tests"
|
|
19
|
-
agent-relay /pair status
|
|
20
|
-
agent-relay /pair accept PAIR_ID
|
|
21
|
-
agent-relay /pair reject PAIR_ID
|
|
22
|
-
agent-relay /pair send PAIR_ID --stdin <<'EOF'
|
|
23
|
-
What do you see?
|
|
24
|
-
EOF
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Report the command output briefly. If the CLI cannot detect this session's agent id, rerun with `--agent AGENT_ID` or `--from AGENT_ID` using the Humwick ID shown in session context.
|
|
28
|
-
|
|
29
|
-
Always pass the message body via a quoted heredoc into `--stdin` (or `--body-file PATH`), never inline in the shell command: backticks / `$(...)` in a body are otherwise command-substituted by your shell before `agent-relay` runs (#1263).
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { writeChildEnv } from "@humwick/sdk/env";
|
|
2
|
-
import type { QuotaState, HeartbeatReport, HeartbeatResult } from "@humwick/sdk";
|
|
3
|
-
import { getManifest } from "@humwick/providers";
|
|
4
|
-
import { quotaStateFromProbeMetrics } from "@humwick/sdk/context-probe";
|
|
5
|
-
import { claudeQuotaGeneration, claudeQuotaUnavailableWindows } from "@humwick/sdk/provider-quota-order";
|
|
6
|
-
import { readRunnerContextProbeState } from "../context-probe-state";
|
|
7
|
-
import { providerHostConfigHome } from "../profile-home";
|
|
8
|
-
import { resolveClaudeStatuslineQuotaIdentity, type ProviderQuotaIdentity } from "../quota";
|
|
9
|
-
|
|
10
|
-
const PASSIVE_QUOTA_SAMPLE_STALE_MS = 10 * 60_000;
|
|
11
|
-
|
|
12
|
-
interface ProviderQuotaHarvestOptions {
|
|
13
|
-
agentId: string;
|
|
14
|
-
provider: string;
|
|
15
|
-
/** The runner's per-provider config env (central provider-config values), read lazily each publish. */
|
|
16
|
-
providerConfigEnv: () => Record<string, string>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class ProviderQuotaHarvest {
|
|
20
|
-
private lastReportedObservedAt?: number;
|
|
21
|
-
private nextAttemptAt = 0;
|
|
22
|
-
private lease?: { accountKey: string; leaseToken: string };
|
|
23
|
-
|
|
24
|
-
constructor(private readonly options: ProviderQuotaHarvestOptions) {}
|
|
25
|
-
|
|
26
|
-
async sample(): Promise<Pick<HeartbeatReport, "providerQuota" | "quotaLeaseToken"> | undefined> {
|
|
27
|
-
if (getManifest(this.options.provider)?.shim?.kind !== "claude-relay" || Date.now() < this.nextAttemptAt) return;
|
|
28
|
-
const metrics = readRunnerContextProbeState(this.options.agentId);
|
|
29
|
-
const quota = metrics ? freshQuotaFromProbeMetrics(metrics, Date.now()) : undefined;
|
|
30
|
-
if (!quota || (this.lastReportedObservedAt !== undefined && quota.updatedAt <= this.lastReportedObservedAt)) return;
|
|
31
|
-
const identity = await this.resolveIdentity();
|
|
32
|
-
if (!identity) return;
|
|
33
|
-
return {
|
|
34
|
-
providerQuota: { provider: this.options.provider, accountKey: identity.accountKey, quota,
|
|
35
|
-
unavailableWindows: claudeQuotaUnavailableWindows(quota), lastAttemptAt: Date.now(), sourceAgentId: this.options.agentId },
|
|
36
|
-
...(this.lease?.accountKey === identity.accountKey ? { quotaLeaseToken: this.lease.leaseToken } : {}),
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
accept(report: HeartbeatReport, result: HeartbeatResult["providerQuota"]): void {
|
|
41
|
-
if (!result || !report.providerQuota) return;
|
|
42
|
-
this.nextAttemptAt = Date.now() + result.retryAfterMs;
|
|
43
|
-
if (result.reported) this.lastReportedObservedAt = report.providerQuota.quota?.updatedAt;
|
|
44
|
-
if (result.leaseToken) this.lease = { accountKey: report.providerQuota.accountKey, leaseToken: result.leaseToken };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// #2514 — quota identity resolves exactly as the LAUNCH authenticates. The primary claude
|
|
48
|
-
// runner keeps the historical ambient-env read byte-for-byte. A claude-family provider with
|
|
49
|
-
// its own subscription (claude-b) must never inherit the ambient primary credential env
|
|
50
|
-
// (CLAUDE_CODE_OAUTH_TOKEN outranks the file credential, so the B quota would be keyed — and
|
|
51
|
-
// folded — under the A account): its identity comes from its OWN dedicated home plus its
|
|
52
|
-
// provider-scoped config env, mirroring the adapter launch scrub and the orchestrator's
|
|
53
|
-
// providerCredentialProbeEnv precedence.
|
|
54
|
-
private async resolveIdentity(): Promise<ProviderQuotaIdentity | undefined> {
|
|
55
|
-
if (this.options.provider === "claude") {
|
|
56
|
-
return resolveClaudeStatuslineQuotaIdentity({ env: process.env });
|
|
57
|
-
}
|
|
58
|
-
const providerEnv = this.options.providerConfigEnv();
|
|
59
|
-
return resolveClaudeStatuslineQuotaIdentity({
|
|
60
|
-
provider: this.options.provider,
|
|
61
|
-
env: writeChildEnv({}, { CLAUDE_CODE_OAUTH_TOKEN: providerEnv.CLAUDE_CODE_OAUTH_TOKEN }),
|
|
62
|
-
configDir: providerHostConfigHome(this.options.provider),
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function freshQuotaFromProbeMetrics(metrics: NonNullable<ReturnType<typeof readRunnerContextProbeState>>, now: number): QuotaState | undefined {
|
|
69
|
-
if (now - (metrics.quotaObservedAt ?? metrics.timestamp) > PASSIVE_QUOTA_SAMPLE_STALE_MS) return undefined;
|
|
70
|
-
const quota = quotaStateFromProbeMetrics(metrics);
|
|
71
|
-
if (!quota) return undefined;
|
|
72
|
-
const windows = quota.windows.filter((window) => window.resetsAt === undefined || window.resetsAt > now);
|
|
73
|
-
const live: QuotaState = { ...quota, windows };
|
|
74
|
-
// Do not turn an expired cached 5h reading into a fresh weekly-only observation (#3087).
|
|
75
|
-
return windows.length > 0 && (claudeQuotaGeneration(live) !== undefined || claudeQuotaUnavailableWindows(quota).length > 0) ? live : undefined;
|
|
76
|
-
}
|