@skrr-ai/cli 0.1.189 → 0.1.191

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.
@@ -51,9 +51,9 @@
51
51
  * ESM and CJS are both emitted because the daemon is ESM and the CLI is CJS, and
52
52
  * this package exists precisely so both can host the broker.
53
53
  */
54
- export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_INPUT_ENVELOPE_ENV, managedInputEnvelopeValue, parseManagedInputEnvelope, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, type ManagedSessionStatus, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, supportsOpenAIExplicitPromptCache, type GatewayCredential, type ManagedCapabilityRefresh, type ManagedCapabilityRefreshResult, type ManagedInferenceBrokerOptions, type ManagedInferenceBrokerSession, type ManagedInferenceBrokerTransport, type ManagedInferenceEndpoint, type ManagedInferenceLoopbackSession, type ManagedInferenceInputTokenAccounting, type ManagedInputEnvelope, type ManagedInferenceModelScope, type ManagedInferenceRequestEnvelope, type ManagedReasoningPolicy, CREDENTIAL_UNAVAILABLE_STATUS, type ManagedInferenceLocalRefusal, type ManagedInferenceUpstreamTransport, } from './managed-inference-broker.js';
54
+ export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_INPUT_ENVELOPE_ENV, managedInputEnvelopeValue, parseManagedInputEnvelope, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, type ManagedSessionStatus, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, supportsOpenAIExplicitPromptCache, type GatewayCredential, type ManagedCapabilityRefresh, type ManagedCapabilityRefreshResult, type ManagedInferenceBrokerOptions, type ManagedInferenceBrokerSession, type ManagedInferenceBrokerTransport, type ManagedInferenceEndpoint, type ManagedInferenceLoopbackSession, type ManagedInferenceInputTokenAccounting, type ManagedInputEnvelope, type ManagedInferenceModelScope, type ManagedInferenceRequestEnvelope, type ManagedReasoningPolicy, CREDENTIAL_UNAVAILABLE_STATUS, type ManagedInferenceLocalRefusal, MANAGED_LEASE_REFUSAL_CODES, managedLeaseRefusalOf, type ManagedInferenceLeaseRefusal, type ManagedInferenceLeaseRefusalCode, type ManagedInferenceUpstreamTransport, } from './managed-inference-broker.js';
55
55
  export { minimumCapabilityWindowMs, scheduleRenewalDelay, startRenewalLoop, type CapabilityRefreshOutcome, type RenewalLoop, type RenewalLoopOptions, type RenewalOutcome, type RenewalStopReason, } from './managed-inference-renewal.js';
56
56
  export { ModelProxyLoopbackServer, type ModelProxyForwarder } from './loopback-server.js';
57
57
  export * from './contract.js';
58
- export { OVERLOAD_SMOKE_PLAN, overloadSmokePrompt, overloadSmokeNativePayload, boundedOverloadSmokeBody, readOverloadSmokeNativeReceipt, boundedOverloadSmokeResponse, overloadSmokeError, countAnthropicSmokeInputUnits } from './overload-smoke.js';
58
+ export { OVERLOAD_SMOKE_PLAN, overloadSmokePrompt, overloadSmokeNativePayload, boundedOverloadSmokeBody, readOverloadSmokeNativeReceipt, boundedOverloadSmokeResponse, overloadSmokeError, countAnthropicSmokeInputUnits, } from './overload-smoke.js';
59
59
  export { projectManagedHaiku45None } from './managed-haiku-none.js';
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  INFERENCE_BROKER_SOCKET_ENV: () => import_managed_inference_broker.INFERENCE_BROKER_SOCKET_ENV,
26
26
  LOOPBACK_BROKER_NO_PROXY_HOSTS: () => import_managed_inference_broker.LOOPBACK_BROKER_NO_PROXY_HOSTS,
27
27
  MANAGED_INPUT_ENVELOPE_ENV: () => import_managed_inference_broker.MANAGED_INPUT_ENVELOPE_ENV,
28
+ MANAGED_LEASE_REFUSAL_CODES: () => import_managed_inference_broker.MANAGED_LEASE_REFUSAL_CODES,
28
29
  MANAGED_PROMPT_CACHING_ENV: () => import_managed_inference_broker.MANAGED_PROMPT_CACHING_ENV,
29
30
  MANAGED_SESSION_ENV: () => import_managed_inference_broker.MANAGED_SESSION_ENV,
30
31
  MANAGED_STATUS_PATH: () => import_managed_inference_broker.MANAGED_STATUS_PATH,
@@ -37,6 +38,7 @@ __export(index_exports, {
37
38
  inferenceBrokerNoProxyEnv: () => import_managed_inference_broker.inferenceBrokerNoProxyEnv,
38
39
  isManagedInferenceModelScope: () => import_managed_inference_broker.isManagedInferenceModelScope,
39
40
  managedInputEnvelopeValue: () => import_managed_inference_broker.managedInputEnvelopeValue,
41
+ managedLeaseRefusalOf: () => import_managed_inference_broker.managedLeaseRefusalOf,
40
42
  minimumCapabilityWindowMs: () => import_managed_inference_renewal.minimumCapabilityWindowMs,
41
43
  noProxyEnvWithHosts: () => import_managed_inference_broker.noProxyEnvWithHosts,
42
44
  overloadSmokeError: () => import_overload_smoke.overloadSmokeError,
@@ -65,6 +67,7 @@ var import_managed_haiku_none = require("./managed-haiku-none.js");
65
67
  INFERENCE_BROKER_SOCKET_ENV,
66
68
  LOOPBACK_BROKER_NO_PROXY_HOSTS,
67
69
  MANAGED_INPUT_ENVELOPE_ENV,
70
+ MANAGED_LEASE_REFUSAL_CODES,
68
71
  MANAGED_PROMPT_CACHING_ENV,
69
72
  MANAGED_SESSION_ENV,
70
73
  MANAGED_STATUS_PATH,
@@ -77,6 +80,7 @@ var import_managed_haiku_none = require("./managed-haiku-none.js");
77
80
  inferenceBrokerNoProxyEnv,
78
81
  isManagedInferenceModelScope,
79
82
  managedInputEnvelopeValue,
83
+ managedLeaseRefusalOf,
80
84
  minimumCapabilityWindowMs,
81
85
  noProxyEnvWithHosts,
82
86
  overloadSmokeError,
@@ -108,6 +108,30 @@ export interface ManagedInferenceLocalRefusal {
108
108
  code: typeof MODEL_PROXY_ERROR.CREDENTIAL_UNAVAILABLE | typeof MODEL_PROXY_ERROR.REQUEST_TOO_LARGE;
109
109
  message: string;
110
110
  }
111
+ /**
112
+ * OSK-32148 — the relay's refusals that mean the PLATFORM ended this session's authority, not that
113
+ * a credential was wrong.
114
+ *
115
+ * `lease-revoked` (401): the reservation behind the session was revoked, reaped or expired.
116
+ * `scope-denied` (403, or 401 when the relay's authority watchdog ends a request it had not yet
117
+ * answered): the session no longer has a live reservation or scope. The harness sees only an HTTP
118
+ * 401/403 from its "provider" and reads it as a bad key, so its host would tell a person to sign
119
+ * in again, which does nothing for a turn the platform pays for. The broker is the one place that
120
+ * reads the relay's own answer, so it keeps the typed refusal for its host to name.
121
+ */
122
+ export declare const MANAGED_LEASE_REFUSAL_CODES: readonly ["lease-revoked", "scope-denied"];
123
+ export type ManagedInferenceLeaseRefusalCode = (typeof MANAGED_LEASE_REFUSAL_CODES)[number];
124
+ /** The latest platform lease refusal a session's relay answered, as the broker read it. */
125
+ export interface ManagedInferenceLeaseRefusal {
126
+ code: ManagedInferenceLeaseRefusalCode;
127
+ /** The HTTP status the relay answered it with (401 or 403). */
128
+ status: number;
129
+ }
130
+ /**
131
+ * A lease refusal from an untrusted value (a readout a host fetched, a field it was handed), or
132
+ * null. Exactly the codes and statuses above; nothing is inferred from anything else.
133
+ */
134
+ export declare function managedLeaseRefusalOf(value: unknown): ManagedInferenceLeaseRefusal | null;
111
135
  export interface ManagedInferenceBrokerOptions {
112
136
  credential: GatewayCredential;
113
137
  /**
@@ -216,6 +240,13 @@ export interface ManagedInferenceBrokerSession {
216
240
  * daemon's tests build several) need not grow one.
217
241
  */
218
242
  localRefusal?(): ManagedInferenceLocalRefusal | null;
243
+ /**
244
+ * The latest platform lease refusal the relay answered a forwarded request with
245
+ * (`lease-revoked`, `scope-denied`), or null (OSK-32148). Read off the relay's own answer; the
246
+ * bytes the harness received are unchanged. Kept after `stop()`, so a host can still name the
247
+ * cause while it settles the turn. Optional for the same reason as `localRefusal`.
248
+ */
249
+ leaseRefusal?(): ManagedInferenceLeaseRefusal | null;
219
250
  stop(): Promise<void>;
220
251
  }
221
252
  /** A `loopback-tcp` broker: no socket, and no bearer in `env`. */
@@ -266,6 +297,13 @@ export interface ManagedSessionStatus {
266
297
  reason: string;
267
298
  detail?: string;
268
299
  };
300
+ /**
301
+ * OSK-32148 — the latest platform lease refusal the relay answered (see
302
+ * {@link ManagedInferenceBrokerSession.leaseRefusal}). This readout is how a host in ANOTHER
303
+ * process learns it: a daemon's session wrapper runs the harness backend, and only the daemon
304
+ * holds the broker. Absent until the relay has refused a request this way.
305
+ */
306
+ leaseRefusal?: ManagedInferenceLeaseRefusal;
269
307
  }
270
308
  export declare const INFERENCE_BROKER_ORIGIN = "http://oversky-inference-broker.invalid";
271
309
  /** The synthetic host inside {@link INFERENCE_BROKER_ORIGIN}. Never resolved. */
@@ -25,6 +25,7 @@ __export(managed_inference_broker_exports, {
25
25
  LOOPBACK_BROKER_NO_PROXY_HOSTS: () => LOOPBACK_BROKER_NO_PROXY_HOSTS,
26
26
  MANAGED_FORWARDED_PATHS: () => MANAGED_FORWARDED_PATHS,
27
27
  MANAGED_INPUT_ENVELOPE_ENV: () => MANAGED_INPUT_ENVELOPE_ENV,
28
+ MANAGED_LEASE_REFUSAL_CODES: () => MANAGED_LEASE_REFUSAL_CODES,
28
29
  MANAGED_PROMPT_CACHING_ENV: () => MANAGED_PROMPT_CACHING_ENV,
29
30
  MANAGED_SESSION_ENV: () => MANAGED_SESSION_ENV,
30
31
  MANAGED_STATUS_PATH: () => MANAGED_STATUS_PATH,
@@ -36,6 +37,7 @@ __export(managed_inference_broker_exports, {
36
37
  isManagedInferenceModelScope: () => isManagedInferenceModelScope,
37
38
  managedClientModelId: () => managedClientModelId,
38
39
  managedInputEnvelopeValue: () => managedInputEnvelopeValue,
40
+ managedLeaseRefusalOf: () => managedLeaseRefusalOf,
39
41
  noProxyEnvWithHosts: () => noProxyEnvWithHosts,
40
42
  parseManagedInputEnvelope: () => parseManagedInputEnvelope,
41
43
  startManagedInferenceBroker: () => startManagedInferenceBroker,
@@ -65,6 +67,18 @@ function supportsOpenAIExplicitPromptCache(modelId) {
65
67
  const model = modelId.trim().toLowerCase().replace(/^(?:openai\/|(?:(?:bedrock_mantle|bedrock|amazon-bedrock)\/)?openai\.)/, "");
66
68
  return /(?:^|[/.])gpt-5\.6(?:-|$)/.test(model) || CURRENT_OPENAI_CACHE_MODELS.has(model);
67
69
  }
70
+ const MANAGED_LEASE_REFUSAL_CODES = ["lease-revoked", "scope-denied"];
71
+ const LEASE_REFUSAL_STATUSES = /* @__PURE__ */ new Set([401, 403]);
72
+ function managedLeaseRefusalOf(value) {
73
+ if (!value || typeof value !== "object")
74
+ return null;
75
+ const { code, status } = value;
76
+ if (!MANAGED_LEASE_REFUSAL_CODES.includes(code))
77
+ return null;
78
+ if (typeof status !== "number" || !LEASE_REFUSAL_STATUSES.has(status))
79
+ return null;
80
+ return { code, status };
81
+ }
68
82
  const MANAGED_STATUS_PATH = "/oversky/managed-status";
69
83
  const INFERENCE_BROKER_ORIGIN = "http://oversky-inference-broker.invalid";
70
84
  const INFERENCE_BROKER_HOST = new URL(INFERENCE_BROKER_ORIGIN).hostname;
@@ -278,6 +292,7 @@ async function startManagedInferenceBroker(options) {
278
292
  throw new Error("managed inference broker maxRequestBytes must be a positive integer");
279
293
  }
280
294
  let localRefusal = null;
295
+ let leaseRefusal = null;
281
296
  let origin;
282
297
  try {
283
298
  origin = new URL(gatewayBase).origin;
@@ -301,7 +316,8 @@ async function startManagedInferenceBroker(options) {
301
316
  authorizedUsd: status.authorizedUsd,
302
317
  ...status.budgetState ? { budgetState: status.budgetState } : {},
303
318
  renewals: status.renewals,
304
- ...status.stopped ? { stopped: status.stopped } : {}
319
+ ...status.stopped ? { stopped: status.stopped } : {},
320
+ ...leaseRefusal ? { leaseRefusal: { ...leaseRefusal } } : {}
305
321
  };
306
322
  const encoded = new TextEncoder().encode(JSON.stringify(payload));
307
323
  return {
@@ -415,10 +431,16 @@ async function startManagedInferenceBroker(options) {
415
431
  response = await fetchImpl(url.toString(), init);
416
432
  }
417
433
  readBudgetHeaders(response.headers);
434
+ const relayed = responseBody(response, envelope?.maxResponseBytes, releaseSlot);
418
435
  return {
419
436
  status: response.status,
420
437
  headers: responseHeaders(response.headers),
421
- body: responseBody(response, envelope?.maxResponseBytes, releaseSlot)
438
+ // OSK-32148 — a 401/403 may be the relay ending the session's authority. Its body is read
439
+ // here, before the harness sees a byte, so the host can name the cause; the harness still
440
+ // receives exactly these bytes.
441
+ body: LEASE_REFUSAL_STATUSES.has(response.status) ? observeLeaseRefusal(relayed, response.status, (refusal) => {
442
+ leaseRefusal = refusal;
443
+ }) : relayed
422
444
  };
423
445
  } catch (error) {
424
446
  releaseSlot();
@@ -535,6 +557,7 @@ async function startManagedInferenceBroker(options) {
535
557
  };
536
558
  const leaseFields = {
537
559
  localRefusal: () => localRefusal,
560
+ leaseRefusal: () => leaseRefusal,
538
561
  ...modelScope ? { clientModelId: managedClientModelId(modelScope) } : {},
539
562
  ...envelope ? {
540
563
  reasoningPolicy: {
@@ -634,22 +657,62 @@ async function classifyLeaseRenewalRefusal(response) {
634
657
  reason: refusal.code ?? `renewal HTTP ${response.status}`
635
658
  };
636
659
  }
660
+ const RELAY_REFUSAL_BODY_LIMIT = 2048;
637
661
  async function readRenewalRefusal(response) {
638
662
  try {
639
- const raw = (await response.text()).slice(0, 2048);
640
- const parsed = JSON.parse(raw);
641
- const code = parsed?.error?.code;
642
- const maxExpiresAt = parsed?.maxExpiresAt;
643
- const resetAt = parsed?.resetAt;
644
- return {
645
- ...typeof code === "string" && code ? { code } : {},
646
- ...typeof maxExpiresAt === "string" && maxExpiresAt ? { maxExpiresAt } : {},
647
- ...typeof resetAt === "string" && resetAt ? { resetAt } : {}
648
- };
663
+ return parseRelayRefusal((await response.text()).slice(0, RELAY_REFUSAL_BODY_LIMIT));
649
664
  } catch {
650
665
  return {};
651
666
  }
652
667
  }
668
+ async function* observeLeaseRefusal(body, status, record) {
669
+ const head = [];
670
+ let headBytes = 0;
671
+ let passing = false;
672
+ for await (const chunk of body) {
673
+ if (passing) {
674
+ yield chunk;
675
+ continue;
676
+ }
677
+ head.push(chunk);
678
+ headBytes += chunk.byteLength;
679
+ if (headBytes > RELAY_REFUSAL_BODY_LIMIT) {
680
+ passing = true;
681
+ for (const held of head.splice(0))
682
+ yield held;
683
+ }
684
+ }
685
+ if (passing)
686
+ return;
687
+ const refusal = leaseRefusalFromBody(status, head);
688
+ if (refusal)
689
+ record(refusal);
690
+ for (const held of head)
691
+ yield held;
692
+ }
693
+ function leaseRefusalFromBody(status, chunks) {
694
+ try {
695
+ const decoder = new TextDecoder();
696
+ let raw = "";
697
+ for (const chunk of chunks)
698
+ raw += decoder.decode(chunk, { stream: true });
699
+ raw += decoder.decode();
700
+ return managedLeaseRefusalOf({ code: parseRelayRefusal(raw).code, status });
701
+ } catch {
702
+ return null;
703
+ }
704
+ }
705
+ function parseRelayRefusal(raw) {
706
+ const parsed = JSON.parse(raw);
707
+ const code = parsed?.error?.code;
708
+ const maxExpiresAt = parsed?.maxExpiresAt;
709
+ const resetAt = parsed?.resetAt;
710
+ return {
711
+ ...typeof code === "string" && code ? { code } : {},
712
+ ...typeof maxExpiresAt === "string" && maxExpiresAt ? { maxExpiresAt } : {},
713
+ ...typeof resetAt === "string" && resetAt ? { resetAt } : {}
714
+ };
715
+ }
653
716
  function resolveGatewayUrl(base, allowedOrigin, path) {
654
717
  let url;
655
718
  try {
@@ -1043,6 +1106,7 @@ async function* responseBody(response, maxBytes, onComplete = () => {
1043
1106
  LOOPBACK_BROKER_NO_PROXY_HOSTS,
1044
1107
  MANAGED_FORWARDED_PATHS,
1045
1108
  MANAGED_INPUT_ENVELOPE_ENV,
1109
+ MANAGED_LEASE_REFUSAL_CODES,
1046
1110
  MANAGED_PROMPT_CACHING_ENV,
1047
1111
  MANAGED_SESSION_ENV,
1048
1112
  MANAGED_STATUS_PATH,
@@ -1054,6 +1118,7 @@ async function* responseBody(response, maxBytes, onComplete = () => {
1054
1118
  isManagedInferenceModelScope,
1055
1119
  managedClientModelId,
1056
1120
  managedInputEnvelopeValue,
1121
+ managedLeaseRefusalOf,
1057
1122
  noProxyEnvWithHosts,
1058
1123
  parseManagedInputEnvelope,
1059
1124
  startManagedInferenceBroker,
@@ -51,9 +51,9 @@
51
51
  * ESM and CJS are both emitted because the daemon is ESM and the CLI is CJS, and
52
52
  * this package exists precisely so both can host the broker.
53
53
  */
54
- export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_INPUT_ENVELOPE_ENV, managedInputEnvelopeValue, parseManagedInputEnvelope, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, type ManagedSessionStatus, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, supportsOpenAIExplicitPromptCache, type GatewayCredential, type ManagedCapabilityRefresh, type ManagedCapabilityRefreshResult, type ManagedInferenceBrokerOptions, type ManagedInferenceBrokerSession, type ManagedInferenceBrokerTransport, type ManagedInferenceEndpoint, type ManagedInferenceLoopbackSession, type ManagedInferenceInputTokenAccounting, type ManagedInputEnvelope, type ManagedInferenceModelScope, type ManagedInferenceRequestEnvelope, type ManagedReasoningPolicy, CREDENTIAL_UNAVAILABLE_STATUS, type ManagedInferenceLocalRefusal, type ManagedInferenceUpstreamTransport, } from './managed-inference-broker.js';
54
+ export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_INPUT_ENVELOPE_ENV, managedInputEnvelopeValue, parseManagedInputEnvelope, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, type ManagedSessionStatus, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, supportsOpenAIExplicitPromptCache, type GatewayCredential, type ManagedCapabilityRefresh, type ManagedCapabilityRefreshResult, type ManagedInferenceBrokerOptions, type ManagedInferenceBrokerSession, type ManagedInferenceBrokerTransport, type ManagedInferenceEndpoint, type ManagedInferenceLoopbackSession, type ManagedInferenceInputTokenAccounting, type ManagedInputEnvelope, type ManagedInferenceModelScope, type ManagedInferenceRequestEnvelope, type ManagedReasoningPolicy, CREDENTIAL_UNAVAILABLE_STATUS, type ManagedInferenceLocalRefusal, MANAGED_LEASE_REFUSAL_CODES, managedLeaseRefusalOf, type ManagedInferenceLeaseRefusal, type ManagedInferenceLeaseRefusalCode, type ManagedInferenceUpstreamTransport, } from './managed-inference-broker.js';
55
55
  export { minimumCapabilityWindowMs, scheduleRenewalDelay, startRenewalLoop, type CapabilityRefreshOutcome, type RenewalLoop, type RenewalLoopOptions, type RenewalOutcome, type RenewalStopReason, } from './managed-inference-renewal.js';
56
56
  export { ModelProxyLoopbackServer, type ModelProxyForwarder } from './loopback-server.js';
57
57
  export * from './contract.js';
58
- export { OVERLOAD_SMOKE_PLAN, overloadSmokePrompt, overloadSmokeNativePayload, boundedOverloadSmokeBody, readOverloadSmokeNativeReceipt, boundedOverloadSmokeResponse, overloadSmokeError, countAnthropicSmokeInputUnits } from './overload-smoke.js';
58
+ export { OVERLOAD_SMOKE_PLAN, overloadSmokePrompt, overloadSmokeNativePayload, boundedOverloadSmokeBody, readOverloadSmokeNativeReceipt, boundedOverloadSmokeResponse, overloadSmokeError, countAnthropicSmokeInputUnits, } from './overload-smoke.js';
59
59
  export { projectManagedHaiku45None } from './managed-haiku-none.js';
@@ -51,12 +51,12 @@
51
51
  * ESM and CJS are both emitted because the daemon is ESM and the CLI is CJS, and
52
52
  * this package exists precisely so both can host the broker.
53
53
  */
54
- export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_INPUT_ENVELOPE_ENV, managedInputEnvelopeValue, parseManagedInputEnvelope, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, supportsOpenAIExplicitPromptCache, CREDENTIAL_UNAVAILABLE_STATUS, } from './managed-inference-broker.js';
54
+ export { INFERENCE_BROKER_ORIGIN, INFERENCE_BROKER_SOCKET_ENV, MANAGED_SESSION_ENV, MANAGED_PROMPT_CACHING_ENV, MANAGED_INPUT_ENVELOPE_ENV, managedInputEnvelopeValue, parseManagedInputEnvelope, MANAGED_STATUS_PATH, INFERENCE_BROKER_HOST, inferenceBrokerNoProxyEnv, LOOPBACK_BROKER_NO_PROXY_HOSTS, noProxyEnvWithHosts, buildManagedInferenceRelayCredential, startManagedInferenceBroker, isManagedInferenceModelScope, supportsOpenAIExplicitPromptCache, CREDENTIAL_UNAVAILABLE_STATUS, MANAGED_LEASE_REFUSAL_CODES, managedLeaseRefusalOf, } from './managed-inference-broker.js';
55
55
  export { minimumCapabilityWindowMs, scheduleRenewalDelay, startRenewalLoop, } from './managed-inference-renewal.js';
56
56
  export { ModelProxyLoopbackServer } from './loopback-server.js';
57
57
  // Re-exported in full because `daemon/src/model-proxy/contract.ts` becomes a
58
58
  // pure re-export of this module: 23 daemon files import that path today, and
59
59
  // keeping it a re-export means none of them change.
60
60
  export * from './contract.js';
61
- export { OVERLOAD_SMOKE_PLAN, overloadSmokePrompt, overloadSmokeNativePayload, boundedOverloadSmokeBody, readOverloadSmokeNativeReceipt, boundedOverloadSmokeResponse, overloadSmokeError, countAnthropicSmokeInputUnits } from './overload-smoke.js';
61
+ export { OVERLOAD_SMOKE_PLAN, overloadSmokePrompt, overloadSmokeNativePayload, boundedOverloadSmokeBody, readOverloadSmokeNativeReceipt, boundedOverloadSmokeResponse, overloadSmokeError, countAnthropicSmokeInputUnits, } from './overload-smoke.js';
62
62
  export { projectManagedHaiku45None } from './managed-haiku-none.js';
@@ -108,6 +108,30 @@ export interface ManagedInferenceLocalRefusal {
108
108
  code: typeof MODEL_PROXY_ERROR.CREDENTIAL_UNAVAILABLE | typeof MODEL_PROXY_ERROR.REQUEST_TOO_LARGE;
109
109
  message: string;
110
110
  }
111
+ /**
112
+ * OSK-32148 — the relay's refusals that mean the PLATFORM ended this session's authority, not that
113
+ * a credential was wrong.
114
+ *
115
+ * `lease-revoked` (401): the reservation behind the session was revoked, reaped or expired.
116
+ * `scope-denied` (403, or 401 when the relay's authority watchdog ends a request it had not yet
117
+ * answered): the session no longer has a live reservation or scope. The harness sees only an HTTP
118
+ * 401/403 from its "provider" and reads it as a bad key, so its host would tell a person to sign
119
+ * in again, which does nothing for a turn the platform pays for. The broker is the one place that
120
+ * reads the relay's own answer, so it keeps the typed refusal for its host to name.
121
+ */
122
+ export declare const MANAGED_LEASE_REFUSAL_CODES: readonly ["lease-revoked", "scope-denied"];
123
+ export type ManagedInferenceLeaseRefusalCode = (typeof MANAGED_LEASE_REFUSAL_CODES)[number];
124
+ /** The latest platform lease refusal a session's relay answered, as the broker read it. */
125
+ export interface ManagedInferenceLeaseRefusal {
126
+ code: ManagedInferenceLeaseRefusalCode;
127
+ /** The HTTP status the relay answered it with (401 or 403). */
128
+ status: number;
129
+ }
130
+ /**
131
+ * A lease refusal from an untrusted value (a readout a host fetched, a field it was handed), or
132
+ * null. Exactly the codes and statuses above; nothing is inferred from anything else.
133
+ */
134
+ export declare function managedLeaseRefusalOf(value: unknown): ManagedInferenceLeaseRefusal | null;
111
135
  export interface ManagedInferenceBrokerOptions {
112
136
  credential: GatewayCredential;
113
137
  /**
@@ -216,6 +240,13 @@ export interface ManagedInferenceBrokerSession {
216
240
  * daemon's tests build several) need not grow one.
217
241
  */
218
242
  localRefusal?(): ManagedInferenceLocalRefusal | null;
243
+ /**
244
+ * The latest platform lease refusal the relay answered a forwarded request with
245
+ * (`lease-revoked`, `scope-denied`), or null (OSK-32148). Read off the relay's own answer; the
246
+ * bytes the harness received are unchanged. Kept after `stop()`, so a host can still name the
247
+ * cause while it settles the turn. Optional for the same reason as `localRefusal`.
248
+ */
249
+ leaseRefusal?(): ManagedInferenceLeaseRefusal | null;
219
250
  stop(): Promise<void>;
220
251
  }
221
252
  /** A `loopback-tcp` broker: no socket, and no bearer in `env`. */
@@ -266,6 +297,13 @@ export interface ManagedSessionStatus {
266
297
  reason: string;
267
298
  detail?: string;
268
299
  };
300
+ /**
301
+ * OSK-32148 — the latest platform lease refusal the relay answered (see
302
+ * {@link ManagedInferenceBrokerSession.leaseRefusal}). This readout is how a host in ANOTHER
303
+ * process learns it: a daemon's session wrapper runs the harness backend, and only the daemon
304
+ * holds the broker. Absent until the relay has refused a request this way.
305
+ */
306
+ leaseRefusal?: ManagedInferenceLeaseRefusal;
269
307
  }
270
308
  export declare const INFERENCE_BROKER_ORIGIN = "http://oversky-inference-broker.invalid";
271
309
  /** The synthetic host inside {@link INFERENCE_BROKER_ORIGIN}. Never resolved. */
@@ -36,6 +36,34 @@ export function supportsOpenAIExplicitPromptCache(modelId) {
36
36
  .replace(/^(?:openai\/|(?:(?:bedrock_mantle|bedrock|amazon-bedrock)\/)?openai\.)/, '');
37
37
  return /(?:^|[/.])gpt-5\.6(?:-|$)/.test(model) || CURRENT_OPENAI_CACHE_MODELS.has(model);
38
38
  }
39
+ /**
40
+ * OSK-32148 — the relay's refusals that mean the PLATFORM ended this session's authority, not that
41
+ * a credential was wrong.
42
+ *
43
+ * `lease-revoked` (401): the reservation behind the session was revoked, reaped or expired.
44
+ * `scope-denied` (403, or 401 when the relay's authority watchdog ends a request it had not yet
45
+ * answered): the session no longer has a live reservation or scope. The harness sees only an HTTP
46
+ * 401/403 from its "provider" and reads it as a bad key, so its host would tell a person to sign
47
+ * in again, which does nothing for a turn the platform pays for. The broker is the one place that
48
+ * reads the relay's own answer, so it keeps the typed refusal for its host to name.
49
+ */
50
+ export const MANAGED_LEASE_REFUSAL_CODES = ['lease-revoked', 'scope-denied'];
51
+ /** The statuses the relay sends those refusals with. Anything else is not one of them. */
52
+ const LEASE_REFUSAL_STATUSES = new Set([401, 403]);
53
+ /**
54
+ * A lease refusal from an untrusted value (a readout a host fetched, a field it was handed), or
55
+ * null. Exactly the codes and statuses above; nothing is inferred from anything else.
56
+ */
57
+ export function managedLeaseRefusalOf(value) {
58
+ if (!value || typeof value !== 'object')
59
+ return null;
60
+ const { code, status } = value;
61
+ if (!MANAGED_LEASE_REFUSAL_CODES.includes(code))
62
+ return null;
63
+ if (typeof status !== 'number' || !LEASE_REFUSAL_STATUSES.has(status))
64
+ return null;
65
+ return { code: code, status };
66
+ }
39
67
  // A synthetic origin is required by URL-oriented provider SDKs. skrr Code pairs
40
68
  // it with OVERSKY_INFERENCE_BROKER_SOCKET and Bun's `fetch({ unix })`; it is
41
69
  // never resolved through DNS or connected over TCP.
@@ -399,6 +427,8 @@ export async function startManagedInferenceBroker(options) {
399
427
  }
400
428
  /** OSK-24521 — the latest request answered here without reaching upstream. */
401
429
  let localRefusal = null;
430
+ /** OSK-32148 — the latest platform lease refusal the relay answered a forwarded request with. */
431
+ let leaseRefusal = null;
402
432
  let origin;
403
433
  try {
404
434
  origin = new URL(gatewayBase).origin;
@@ -445,6 +475,7 @@ export async function startManagedInferenceBroker(options) {
445
475
  ...(status.budgetState ? { budgetState: status.budgetState } : {}),
446
476
  renewals: status.renewals,
447
477
  ...(status.stopped ? { stopped: status.stopped } : {}),
478
+ ...(leaseRefusal ? { leaseRefusal: { ...leaseRefusal } } : {}),
448
479
  };
449
480
  const encoded = new TextEncoder().encode(JSON.stringify(payload));
450
481
  return {
@@ -594,10 +625,18 @@ export async function startManagedInferenceBroker(options) {
594
625
  // all. Every inference call carries one now, which is the one channel a
595
626
  // session cannot be too short to use.
596
627
  readBudgetHeaders(response.headers);
628
+ const relayed = responseBody(response, envelope?.maxResponseBytes, releaseSlot);
597
629
  return {
598
630
  status: response.status,
599
631
  headers: responseHeaders(response.headers),
600
- body: responseBody(response, envelope?.maxResponseBytes, releaseSlot),
632
+ // OSK-32148 — a 401/403 may be the relay ending the session's authority. Its body is read
633
+ // here, before the harness sees a byte, so the host can name the cause; the harness still
634
+ // receives exactly these bytes.
635
+ body: LEASE_REFUSAL_STATUSES.has(response.status)
636
+ ? observeLeaseRefusal(relayed, response.status, (refusal) => {
637
+ leaseRefusal = refusal;
638
+ })
639
+ : relayed,
601
640
  };
602
641
  }
603
642
  catch (error) {
@@ -767,6 +806,7 @@ export async function startManagedInferenceBroker(options) {
767
806
  };
768
807
  const leaseFields = {
769
808
  localRefusal: () => localRefusal,
809
+ leaseRefusal: () => leaseRefusal,
770
810
  ...(modelScope ? { clientModelId: managedClientModelId(modelScope) } : {}),
771
811
  ...(envelope
772
812
  ? {
@@ -929,29 +969,89 @@ export async function classifyLeaseRenewalRefusal(response) {
929
969
  reason: refusal.code ?? `renewal HTTP ${response.status}`,
930
970
  };
931
971
  }
972
+ /**
973
+ * The most of a relay refusal's body either reader parses. A refusal is a short JSON object; a body
974
+ * longer than this is not one, and is never buffered past it.
975
+ */
976
+ const RELAY_REFUSAL_BODY_LIMIT = 2048;
932
977
  /**
933
978
  * Read `{error: {code}, maxExpiresAt}` without letting a hostile or huge body
934
979
  * matter, and without letting a malformed one throw on a teardown-adjacent path.
935
980
  */
936
981
  async function readRenewalRefusal(response) {
937
982
  try {
938
- const raw = (await response.text()).slice(0, 2048);
939
- const parsed = JSON.parse(raw);
940
- const code = parsed?.error?.code;
941
- const maxExpiresAt = parsed?.maxExpiresAt;
942
- // Present only when waiting can actually help — a spent account window
943
- // refills, a spent session authorization does not. Absent is meaningful.
944
- const resetAt = parsed?.resetAt;
945
- return {
946
- ...(typeof code === 'string' && code ? { code } : {}),
947
- ...(typeof maxExpiresAt === 'string' && maxExpiresAt ? { maxExpiresAt } : {}),
948
- ...(typeof resetAt === 'string' && resetAt ? { resetAt } : {}),
949
- };
983
+ return parseRelayRefusal((await response.text()).slice(0, RELAY_REFUSAL_BODY_LIMIT));
950
984
  }
951
985
  catch {
952
986
  return {};
953
987
  }
954
988
  }
989
+ /**
990
+ * OSK-32148 — pass a relayed 401/403 body through to the harness unchanged, and record the
991
+ * platform lease refusal it carries.
992
+ *
993
+ * The head is read BEFORE any of it is released, so the refusal is on record before the harness
994
+ * can have parsed the answer and reported a failure: its host then finds the cause whenever it
995
+ * asks. A body longer than {@link RELAY_REFUSAL_BODY_LIMIT} is not a relay refusal; what was held
996
+ * is released as it arrived and the rest streams straight through. The chunks are the ones the
997
+ * relay sent, in order, never re-encoded.
998
+ */
999
+ async function* observeLeaseRefusal(body, status, record) {
1000
+ const head = [];
1001
+ let headBytes = 0;
1002
+ let passing = false;
1003
+ for await (const chunk of body) {
1004
+ if (passing) {
1005
+ yield chunk;
1006
+ continue;
1007
+ }
1008
+ head.push(chunk);
1009
+ headBytes += chunk.byteLength;
1010
+ if (headBytes > RELAY_REFUSAL_BODY_LIMIT) {
1011
+ passing = true;
1012
+ for (const held of head.splice(0))
1013
+ yield held;
1014
+ }
1015
+ }
1016
+ if (passing)
1017
+ return;
1018
+ const refusal = leaseRefusalFromBody(status, head);
1019
+ if (refusal)
1020
+ record(refusal);
1021
+ for (const held of head)
1022
+ yield held;
1023
+ }
1024
+ function leaseRefusalFromBody(status, chunks) {
1025
+ try {
1026
+ const decoder = new TextDecoder();
1027
+ let raw = '';
1028
+ for (const chunk of chunks)
1029
+ raw += decoder.decode(chunk, { stream: true });
1030
+ raw += decoder.decode();
1031
+ return managedLeaseRefusalOf({ code: parseRelayRefusal(raw).code, status });
1032
+ }
1033
+ catch {
1034
+ return null;
1035
+ }
1036
+ }
1037
+ /**
1038
+ * The ONE parser of a relay refusal's JSON (`{error: {code}, maxExpiresAt, resetAt}`), shared by
1039
+ * the renewal refusal and the forwarded-request refusal. Throws on a body that is not JSON; each
1040
+ * caller decides what an unreadable body means for it.
1041
+ */
1042
+ function parseRelayRefusal(raw) {
1043
+ const parsed = JSON.parse(raw);
1044
+ const code = parsed?.error?.code;
1045
+ const maxExpiresAt = parsed?.maxExpiresAt;
1046
+ // Present only when waiting can actually help — a spent account window
1047
+ // refills, a spent session authorization does not. Absent is meaningful.
1048
+ const resetAt = parsed?.resetAt;
1049
+ return {
1050
+ ...(typeof code === 'string' && code ? { code } : {}),
1051
+ ...(typeof maxExpiresAt === 'string' && maxExpiresAt ? { maxExpiresAt } : {}),
1052
+ ...(typeof resetAt === 'string' && resetAt ? { resetAt } : {}),
1053
+ };
1054
+ }
955
1055
  function resolveGatewayUrl(base, allowedOrigin, path) {
956
1056
  let url;
957
1057
  try {
@@ -18495,11 +18495,13 @@
18495
18495
  },
18496
18496
  "description": "Manage this Agent’s chat follow-through, inspect current state, or schedule a condition check.",
18497
18497
  "examples": [
18498
+ "<%= config.bin %> agents supervision <agent-id> preflight",
18498
18499
  "<%= config.bin %> agents supervision <agent-id> preflight --json",
18499
18500
  "<%= config.bin %> agents supervision <agent-id> enable --revision 0 --request-id <stable-key> --json",
18500
18501
  "<%= config.bin %> agents supervision <agent-id> disable --revision 1 --request-id <new-stable-key> --json",
18501
18502
  "<%= config.bin %> agents supervision <agent-id> exclude --watch <watch-id> --plan-revision 2 --json",
18502
18503
  "<%= config.bin %> agents supervision <agent-id> explain --watch <watch-id> --json",
18504
+ "<%= config.bin %> agents supervision <agent-id> check-now",
18503
18505
  "<%= config.bin %> agents supervision <agent-id> check-now --json",
18504
18506
  "<%= config.bin %> agents supervision <agent-id> chats --json",
18505
18507
  "<%= config.bin %> agents supervision <agent-id> inspect --watch <watch-id> --json",
@@ -18575,7 +18577,7 @@
18575
18577
  "type": "option"
18576
18578
  },
18577
18579
  "mode": {
18578
- "description": "Policy for enable/disable: recover (default) or observation-only shadow",
18580
+ "description": "Use recover or monitoring-only shadow. By default, enable uses monitoring when recovery is unconfirmed or unavailable, and disable keeps the saved mode.",
18579
18581
  "name": "mode",
18580
18582
  "hasDynamicHelp": false,
18581
18583
  "multiple": false,
@@ -36441,7 +36443,7 @@
36441
36443
  "description": "Fork a conversation from a specific message",
36442
36444
  "examples": [
36443
36445
  "<%= config.bin %> convos fork <id> --message <messageId>",
36444
- "<%= config.bin %> convos fork <id> --message <messageId> --split-at-target",
36446
+ "<%= config.bin %> convos fork <id> --message <messageId> --split-at-target --latest-message <latestMessageId>",
36445
36447
  "<%= config.bin %> convos fork <id> --message <messageId> --option target --json"
36446
36448
  ],
36447
36449
  "flags": {
@@ -36494,13 +36496,23 @@
36494
36496
  "type": "option"
36495
36497
  },
36496
36498
  "option": {
36497
- "description": "Fork option (e.g. \"target\", \"branch\")",
36499
+ "description": "Fork option (target includes the target level; branch includes siblings)",
36498
36500
  "name": "option",
36499
36501
  "hasDynamicHelp": false,
36500
36502
  "multiple": false,
36503
+ "options": [
36504
+ "target",
36505
+ "branch",
36506
+ "directPath",
36507
+ "includeBranches",
36508
+ "targetLevel"
36509
+ ],
36501
36510
  "type": "option"
36502
36511
  },
36503
36512
  "split-at-target": {
36513
+ "dependsOn": [
36514
+ "latest-message"
36515
+ ],
36504
36516
  "description": "Split the conversation at the target message",
36505
36517
  "name": "split-at-target",
36506
36518
  "allowNo": false,
@@ -36542,7 +36554,7 @@
36542
36554
  "required": true
36543
36555
  }
36544
36556
  },
36545
- "description": "Hand a conversation over to another agent, carrying its context",
36557
+ "description": "Copy saved chat history to a new conversation with another agent. The source chat and any live turn continue independently.",
36546
36558
  "examples": [
36547
36559
  "<%= config.bin %> convos handover <id> --to <agentId>",
36548
36560
  "<%= config.bin %> convos handover <id> --to <agentId> --reason \"frontend problem\"",
@@ -36597,7 +36609,7 @@
36597
36609
  "type": "option"
36598
36610
  },
36599
36611
  "up-to": {
36600
- "description": "Carry history up to this message ID (default: the whole thread)",
36612
+ "description": "Carry saved history up to this message ID (default: the latest saved turn)",
36601
36613
  "name": "up-to",
36602
36614
  "hasDynamicHelp": false,
36603
36615
  "multiple": false,
@@ -151482,5 +151494,5 @@
151482
151494
  ]
151483
151495
  }
151484
151496
  },
151485
- "version": "0.1.189"
151497
+ "version": "0.1.191"
151486
151498
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skrr-ai/cli",
3
- "version": "0.1.189",
3
+ "version": "0.1.191",
4
4
  "description": "Command-line interface for skrr",
5
5
  "license": "ISC",
6
6
  "author": "skrr",
@@ -606,7 +606,7 @@
606
606
  "description": "Your Agent Manager (HR Agent): create it, or repair an incomplete one"
607
607
  },
608
608
  "followups": {
609
- "description": "Schedule agent follow-ups and bounded lookback plans"
609
+ "description": "Schedule agent follow-ups and bounded lookback plans. For chat monitoring, use skrr agents supervision."
610
610
  },
611
611
  "followups:plans": {
612
612
  "description": "Schedule and manage bounded plans of 1–10 lookbacks"
@@ -707,5 +707,5 @@
707
707
  "engines": {
708
708
  "node": ">=20.0.0"
709
709
  },
710
- "gitHead": "a00225b9f6d5ca1b2b1f6bc5acf7285a05382653"
710
+ "gitHead": "55ae4f7f5b7c77cd7589f153508d506b090caa3c"
711
711
  }