@sagentlab/navarch-runtime 0.1.148 → 0.1.150
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter-capacity.cjs +19 -4
- package/dist/agent-auth.cjs +7 -1
- package/dist/cli.cjs +2 -4
- package/dist/exit-conditions.cjs +18 -3
- package/dist/machine-store.cjs +5 -1
- package/dist/model-reference.cjs +25 -0
- package/dist/session.cjs +8 -0
- package/package.json +1 -1
|
@@ -5,6 +5,14 @@ const exit_conditions_cjs_1 = require("./exit-conditions.cjs");
|
|
|
5
5
|
const DEFAULT_CAPACITY_COOLDOWN_MS = 15 * 60 * 1000;
|
|
6
6
|
const RESET_GRACE_MS = 30 * 1000;
|
|
7
7
|
const MAX_RESET_SEARCH_MINUTES = 48 * 60;
|
|
8
|
+
/**
|
|
9
|
+
* Account capacity wording. Claude Code says "You've hit your session limit"
|
|
10
|
+
* or "You've hit your weekly limit · resets 11am (America/New_York)"; OpenCode
|
|
11
|
+
* and Codex say "usage limit" or "rate limit".
|
|
12
|
+
*/
|
|
13
|
+
const CAPACITY_PATTERN = /\b(?:session|usage|rate|weekly|daily|monthly|hourly|5-hour)\s+limit\b|\bhit your (?:[\w.-]+ ){0,3}limit\b|\btoo many requests\b/i;
|
|
14
|
+
/** Claude Code's account-limit lead: "You've hit your weekly limit". */
|
|
15
|
+
const CLAUDE_ACCOUNT_LIMIT = /^you(?:'|’)ve hit your (?:[\w.-]+ ){0,3}limit\b/i;
|
|
8
16
|
/**
|
|
9
17
|
* Detects a provider-side capacity response that applies beyond one task
|
|
10
18
|
* lease. Claude Code reports account session exhaustion as a successful CLI
|
|
@@ -14,15 +22,22 @@ const MAX_RESET_SEARCH_MINUTES = 48 * 60;
|
|
|
14
22
|
function detectAdapterCapacityLimit(result, nowMs = Date.now()) {
|
|
15
23
|
const parsed = (0, exit_conditions_cjs_1.parseClaudeJsonResult)(result.stdout) ??
|
|
16
24
|
(0, exit_conditions_cjs_1.parseClaudeJsonResult)(result.stderr);
|
|
17
|
-
|
|
25
|
+
// A structured error result is written by the CLI, not the agent. Claude
|
|
26
|
+
// Code does not mark every account limit with a 429 status, so a structured
|
|
27
|
+
// error result with no API status also counts when its text is Claude
|
|
28
|
+
// Code's own "You've hit your … limit". Another explicit status (401, 403)
|
|
29
|
+
// is a different failure.
|
|
30
|
+
const detail = (result.capacityError ?? (typeof parsed?.result === "string" ? parsed.result : "")).trim();
|
|
31
|
+
const structured = parsed?.api_error_status === 429 ||
|
|
32
|
+
(parsed?.is_error === true && parsed.api_error_status == null && CLAUDE_ACCOUNT_LIMIT.test(detail));
|
|
33
|
+
if (!result.capacityError && !structured)
|
|
18
34
|
return null;
|
|
19
|
-
|
|
20
|
-
if (!/\b(?:session|usage|rate)\s+limit\b|\btoo many requests\b/i.test(detail)) {
|
|
35
|
+
if (!CAPACITY_PATTERN.test(detail))
|
|
21
36
|
return null;
|
|
22
|
-
}
|
|
23
37
|
return {
|
|
24
38
|
retryAtMs: parseResetTime(detail, nowMs) ??
|
|
25
39
|
nowMs + DEFAULT_CAPACITY_COOLDOWN_MS,
|
|
40
|
+
detail: detail.length > 300 ? `${detail.slice(0, 299)}…` : detail,
|
|
26
41
|
};
|
|
27
42
|
}
|
|
28
43
|
/**
|
package/dist/agent-auth.cjs
CHANGED
|
@@ -10,7 +10,12 @@ const exit_conditions_cjs_1 = require("./exit-conditions.cjs");
|
|
|
10
10
|
*
|
|
11
11
|
* - Claude Code: "Failed to authenticate: OAuth session expired and could not
|
|
12
12
|
* be refreshed", "OAuth token has expired", "Invalid API key · Please run
|
|
13
|
-
* /login", "Not logged in · Please run /login", 401 authentication_error
|
|
13
|
+
* /login", "Not logged in · Please run /login", 401 authentication_error,
|
|
14
|
+
* and an organization that turned subscription access off: "Your
|
|
15
|
+
* organization has disabled Claude subscription access for Claude Code · Use
|
|
16
|
+
* an Anthropic API key instead, or ask your admin to enable access". No
|
|
17
|
+
* retry on the same machine can fix that either; a person must change the
|
|
18
|
+
* account or the login.
|
|
14
19
|
* - Codex: "Your access token could not be refreshed because your refresh
|
|
15
20
|
* token has expired/was already used", "Not logged in", "Please run `codex
|
|
16
21
|
* login`", token_expired / refresh_token_* error codes.
|
|
@@ -25,6 +30,7 @@ const AGENT_AUTH_PATTERNS = [
|
|
|
25
30
|
/\brefresh token (?:has expired|was already used|is invalid|expired)\b/i,
|
|
26
31
|
/\b(?:refresh_token_(?:expired|reused|invalidated)|token_expired)\b/i,
|
|
27
32
|
/\bauthentication_error\b/i,
|
|
33
|
+
/\bhas disabled claude subscription access\b/i,
|
|
28
34
|
];
|
|
29
35
|
function matchingLine(text) {
|
|
30
36
|
for (const line of text.split("\n")) {
|
package/dist/cli.cjs
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.main = main;
|
|
7
7
|
const config_cjs_1 = require("./config.cjs");
|
|
8
8
|
const node_crypto_1 = require("node:crypto");
|
|
9
|
+
const model_reference_cjs_1 = require("./model-reference.cjs");
|
|
9
10
|
const node_os_1 = __importDefault(require("node:os"));
|
|
10
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
12
|
const machine_store_cjs_1 = require("./machine-store.cjs");
|
|
@@ -126,10 +127,7 @@ function warnUnknownAdapters(config) {
|
|
|
126
127
|
/** Saved pins only apply to the adapter they were selected for. */
|
|
127
128
|
function modelFromFlags(flags, agentType, identity) {
|
|
128
129
|
const model = flags.model ?? (identity?.agent_type === agentType ? identity.model : undefined);
|
|
129
|
-
|
|
130
|
-
throw new Error("--model requires a non-empty model reference without whitespace.");
|
|
131
|
-
}
|
|
132
|
-
return model;
|
|
130
|
+
return model === undefined ? undefined : (0, model_reference_cjs_1.normalizeRuntimeModelReference)(model);
|
|
133
131
|
}
|
|
134
132
|
function parseArgs(argv) {
|
|
135
133
|
const [command, ...rest] = argv;
|
package/dist/exit-conditions.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AGENT_MODEL_UNAVAILABLE_PREFIX = exports.AGENT_AUTH_FAILURE_PREFIX = void 0;
|
|
3
|
+
exports.AGENT_MODEL_UNAVAILABLE_PREFIX = exports.AGENT_CAPACITY_FAILURE_PREFIX = exports.AGENT_AUTH_FAILURE_PREFIX = void 0;
|
|
4
|
+
exports.capacityFailureReport = capacityFailureReport;
|
|
4
5
|
exports.agentAuthFailureReport = agentAuthFailureReport;
|
|
5
6
|
exports.agentModelUnavailableReport = agentModelUnavailableReport;
|
|
6
7
|
exports.parseClaudeJsonResult = parseClaudeJsonResult;
|
|
@@ -22,6 +23,20 @@ exports.mapExitCondition = mapExitCondition;
|
|
|
22
23
|
* `provider.agent_auth`).
|
|
23
24
|
*/
|
|
24
25
|
exports.AGENT_AUTH_FAILURE_PREFIX = "Coding agent authentication failed";
|
|
26
|
+
/**
|
|
27
|
+
* Leading text of every report for a turn the provider refused because the
|
|
28
|
+
* account is out of capacity (a session, weekly or usage limit). The control
|
|
29
|
+
* plane recognizes it, requeues the task without spending a retry and pauses
|
|
30
|
+
* this machine's claims until the time after "until"
|
|
31
|
+
* (lib/navarch/failure-attribution.ts `provider.agent_capacity`).
|
|
32
|
+
*/
|
|
33
|
+
exports.AGENT_CAPACITY_FAILURE_PREFIX = "Session stopped: provider capacity exhausted";
|
|
34
|
+
function capacityFailureReport(detail, retryAtMs) {
|
|
35
|
+
const until = retryAtMs !== undefined && Number.isFinite(retryAtMs)
|
|
36
|
+
? ` until ${new Date(retryAtMs).toISOString()}`
|
|
37
|
+
: "";
|
|
38
|
+
return `${exports.AGENT_CAPACITY_FAILURE_PREFIX}${until}. ${detail}`;
|
|
39
|
+
}
|
|
25
40
|
function agentAuthFailureReport(detail) {
|
|
26
41
|
return `${exports.AGENT_AUTH_FAILURE_PREFIX}: ${detail} ` +
|
|
27
42
|
"Log the coding agent in again on this machine (`claude /login`, `codex login`, an interactive `agy` session, or open `muse` and run `/login`), then resume the agent.";
|
|
@@ -248,7 +263,7 @@ const REVIEW_FIX_MARKER_LINE = /^[ \t]*Review fix delivered: [a-f0-9]{40}(?=\s|$
|
|
|
248
263
|
* this package cannot import it. A report without a marker is unchanged.
|
|
249
264
|
*/
|
|
250
265
|
function leadWithReviewFixMarker(report) {
|
|
251
|
-
const marker = REVIEW_FIX_MARKER_LINE.exec(report);
|
|
266
|
+
const marker = REVIEW_FIX_MARKER_LINE.exec(report) ?? /^[ \t]*Review metadata delivered: [a-f0-9]{40} [1-9][0-9]*(?=\s|$)/im.exec(report);
|
|
252
267
|
if (!marker || !report.slice(0, marker.index).trim())
|
|
253
268
|
return report;
|
|
254
269
|
const lineEnd = report.indexOf("\n", marker.index);
|
|
@@ -386,7 +401,7 @@ function mapExitCondition(result) {
|
|
|
386
401
|
return {
|
|
387
402
|
leaseOutcome: "failed",
|
|
388
403
|
exitStatus: "failed",
|
|
389
|
-
reportSummary: summarize(
|
|
404
|
+
reportSummary: summarize(capacityFailureReport(result.capacityError, result.capacityRetryAtMs)) +
|
|
390
405
|
(result.checkpointPath ? ` Local recovery checkpoint: ${result.checkpointPath}` : "") +
|
|
391
406
|
(result.retainedWorktreePath ? ` Recovery worktree retained: ${result.retainedWorktreePath}` : ""),
|
|
392
407
|
evidenceUrls,
|
package/dist/machine-store.cjs
CHANGED
|
@@ -8,15 +8,19 @@ exports.loadMachineIdentity = loadMachineIdentity;
|
|
|
8
8
|
exports.resolveMachineIdentity = resolveMachineIdentity;
|
|
9
9
|
const node_fs_1 = require("node:fs");
|
|
10
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
+
const model_reference_cjs_1 = require("./model-reference.cjs");
|
|
11
12
|
const agent_types_cjs_1 = require("./agent-types.cjs");
|
|
12
13
|
function storePath(configDir) {
|
|
13
14
|
return node_path_1.default.join(configDir, "machine.json");
|
|
14
15
|
}
|
|
15
16
|
/** Persists the machine's long-lived auth token to `<configDir>/machine.json`, mode 0600. */
|
|
16
17
|
async function saveMachineIdentity(configDir, identity) {
|
|
18
|
+
const normalized = identity.model === undefined
|
|
19
|
+
? identity
|
|
20
|
+
: { ...identity, model: (0, model_reference_cjs_1.normalizeRuntimeModelReference)(identity.model) };
|
|
17
21
|
await node_fs_1.promises.mkdir(configDir, { recursive: true, mode: 0o700 });
|
|
18
22
|
const file = storePath(configDir);
|
|
19
|
-
await node_fs_1.promises.writeFile(file, `${JSON.stringify(
|
|
23
|
+
await node_fs_1.promises.writeFile(file, `${JSON.stringify(normalized, null, 2)}\n`, { mode: 0o600 });
|
|
20
24
|
await node_fs_1.promises.chmod(file, 0o600);
|
|
21
25
|
}
|
|
22
26
|
async function loadMachineIdentity(configDir) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeModelReference = normalizeModelReference;
|
|
4
|
+
exports.normalizeRuntimeModelReference = normalizeRuntimeModelReference;
|
|
5
|
+
/** Mirrors normalizeModelReference in lib/navarch/execution-policy.ts for this standalone package. */
|
|
6
|
+
function normalizeModelReference(value) {
|
|
7
|
+
if (typeof value !== "string")
|
|
8
|
+
return null;
|
|
9
|
+
let model = value.trim();
|
|
10
|
+
const pairs = { '"': '"', "'": "'", "`": "`", "‘": "’", "“": "”" };
|
|
11
|
+
if (model.length >= 2 && pairs[model[0]] === model.at(-1)) {
|
|
12
|
+
model = model.slice(1, -1).trim();
|
|
13
|
+
}
|
|
14
|
+
if (!model || model.length > 500 || /[\u0000-\u001f\u007f'"`‘’“”]/.test(model))
|
|
15
|
+
return null;
|
|
16
|
+
return model;
|
|
17
|
+
}
|
|
18
|
+
/** Validate both new CLI pins and saved identities before use or persistence. */
|
|
19
|
+
function normalizeRuntimeModelReference(value) {
|
|
20
|
+
const model = normalizeModelReference(value);
|
|
21
|
+
if (!model || model === "true" || /\s/.test(model)) {
|
|
22
|
+
throw new Error("--model requires a non-empty model reference without whitespace or embedded quotes.");
|
|
23
|
+
}
|
|
24
|
+
return model;
|
|
25
|
+
}
|
package/dist/session.cjs
CHANGED
|
@@ -1066,6 +1066,14 @@ async function runClaimedSession(deps, claimed, sessionId, lifecycle) {
|
|
|
1066
1066
|
reportActivity("finishing");
|
|
1067
1067
|
const capacityLimit = (0, adapter_capacity_cjs_1.detectAdapterCapacityLimit)(turnResult);
|
|
1068
1068
|
if (capacityLimit) {
|
|
1069
|
+
// Claude Code reports an account limit as a structured result, not as
|
|
1070
|
+
// an adapter capacity error. Name it in the report with the reset
|
|
1071
|
+
// time, so the control plane requeues the task without spending a
|
|
1072
|
+
// retry and pauses this machine until then.
|
|
1073
|
+
turnResult.capacityError ??= capacityLimit.detail;
|
|
1074
|
+
turnResult.capacityRetryAtMs = capacityLimit.retryAtMs;
|
|
1075
|
+
log.warn(`session ${leaseId}: provider capacity exhausted until ` +
|
|
1076
|
+
`${new Date(capacityLimit.retryAtMs).toISOString()}: ${capacityLimit.detail}`);
|
|
1069
1077
|
await checkpointForRecovery(turnResult);
|
|
1070
1078
|
sessionOutcome.claimCooldownUntil = Math.max(sessionOutcome.claimCooldownUntil ?? 0, capacityLimit.retryAtMs);
|
|
1071
1079
|
}
|
package/package.json
CHANGED