@miadi/connector 0.1.27 → 0.1.28

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.
@@ -470,7 +470,13 @@ export async function missionStatus(ref, records, deps) {
470
470
  ...(queue ? { queue } : {}),
471
471
  sessions,
472
472
  issues,
473
- steering: { grant: grantState, attempts_used: attempts, ...(grant?.max_attempts !== undefined ? { max_attempts: grant.max_attempts } : {}), ...(steers.length ? { steers } : {}) },
473
+ steering: {
474
+ grant: grantState,
475
+ attempts_used: attempts,
476
+ ...(grant?.max_attempts !== undefined ? { max_attempts: grant.max_attempts } : {}),
477
+ ...(steers.length ? { steers } : {}),
478
+ ...(deps.steeringSupportOf && (provider?.actual ?? provider?.resolved) ? { support: deps.steeringSupportOf(String(provider.actual ?? provider.resolved)) } : {}),
479
+ },
474
480
  ...(provider ? { provider } : {}),
475
481
  stage_truth: stageTruth,
476
482
  mission_stage: missionStage(standing ?? null, stageTruth),
@@ -31,15 +31,23 @@ export declare const CHOICE_TTL_MS: number;
31
31
  export declare function needsPersonChoice(provider: string | null | undefined): boolean;
32
32
  /** Whether a person id may make a choice or set a policy: a person, never a service token. */
33
33
  export declare function isPersonId(personId: string | undefined): boolean;
34
+ /** What may stand in for naming a provider. Codex never does: it runs only on a choice for one mission or an explicit policy (jgwill/Miadi#926). */
35
+ export declare const DEFAULT_PROVIDERS: readonly string[];
36
+ /** The value a person picks on /providers to mean no default of their own, whatever the operator set. */
37
+ export declare const HOST_ORDER = "host_order";
34
38
  export interface ProviderPolicy {
35
39
  person_id: string;
36
40
  codex: CodexPolicy;
37
41
  source: "default" | "person";
38
42
  record?: string;
39
43
  set_at?: string;
44
+ /** The provider a request of theirs runs on when it names none (jgwill/Miadi#942). Absent: the host's order. */
45
+ default_provider?: string;
46
+ /** Who said so: the person on /providers, or the operator's factory.json for this person. */
47
+ default_provider_source?: "person" | "host_config";
40
48
  }
41
49
  /** A person's provider policy: the latest one they set themself, else the default. */
42
- export declare function providerPolicyOf(records: ConnectorRecord[], personId: string): ProviderPolicy;
50
+ export declare function providerPolicyOf(records: ConnectorRecord[], personId: string, hostDefaults?: Record<string, string> | null): ProviderPolicy;
43
51
  export interface ProviderChoiceView {
44
52
  record: string;
45
53
  provider: string;
@@ -12,19 +12,29 @@ export function needsPersonChoice(provider) {
12
12
  export function isPersonId(personId) {
13
13
  return typeof personId === "string" && personId.length > 0 && !personId.startsWith("system:");
14
14
  }
15
+ /** What may stand in for naming a provider. Codex never does: it runs only on a choice for one mission or an explicit policy (jgwill/Miadi#926). */
16
+ export const DEFAULT_PROVIDERS = ["claude", "pi", "copilot"];
17
+ /** The value a person picks on /providers to mean no default of their own, whatever the operator set. */
18
+ export const HOST_ORDER = "host_order";
15
19
  /** A person's provider policy: the latest one they set themself, else the default. */
16
- export function providerPolicyOf(records, personId) {
20
+ export function providerPolicyOf(records, personId, hostDefaults) {
17
21
  let latest;
22
+ let chosenDefault;
18
23
  for (const r of records) {
19
24
  if (r.kind !== "provider_policy" || r.actor.person_id !== personId || !isPersonId(r.actor.person_id))
20
25
  continue;
21
- if (!CODEX_POLICIES.includes(String(r.body.codex)))
26
+ const body = r.body;
27
+ if (!CODEX_POLICIES.includes(String(body.codex)))
22
28
  continue;
23
29
  latest = r;
30
+ chosenDefault = typeof body.default_provider === "string" && body.default_provider ? body.default_provider : chosenDefault;
24
31
  }
32
+ const hostDefault = hostDefaults?.[personId];
33
+ const default_provider = chosenDefault === HOST_ORDER ? undefined : (chosenDefault ?? hostDefault);
34
+ const defaults = default_provider && DEFAULT_PROVIDERS.includes(default_provider) ? { default_provider, default_provider_source: (chosenDefault ? "person" : "host_config") } : {};
25
35
  if (!latest)
26
- return { person_id: personId, codex: DEFAULT_CODEX_POLICY, source: "default" };
27
- return { person_id: personId, codex: latest.body.codex, source: "person", record: latest.id, set_at: latest.created_at };
36
+ return { person_id: personId, codex: DEFAULT_CODEX_POLICY, source: "default", ...defaults };
37
+ return { person_id: personId, codex: latest.body.codex, source: "person", record: latest.id, set_at: latest.created_at, ...defaults };
28
38
  }
29
39
  function str(v) {
30
40
  return typeof v === "string" && v ? v : null;
@@ -45,7 +45,7 @@ export type ProviderResolution = {
45
45
  * preference order that may be selected by default wins. Codex and Claude Code
46
46
  * only ever by name; whether a named Codex may run is provider-policy.ts's answer.
47
47
  */
48
- export declare function resolveProvider(requested: string | undefined, found: ProviderAvailability[]): ProviderResolution;
48
+ export declare function resolveProvider(requested: string | undefined, found: ProviderAvailability[], personDefault?: string): ProviderResolution;
49
49
  /**
50
50
  * Where Jev is reached from this host (jgwill/Miadi#913 C1), by the names
51
51
  * smcraft's lane-check decider uses (examples/decision-gate/lane-check,
package/dist/providers.js CHANGED
@@ -68,8 +68,19 @@ export function discoverProviders(probe = {}, specs = PROVIDERS) {
68
68
  * preference order that may be selected by default wins. Codex and Claude Code
69
69
  * only ever by name; whether a named Codex may run is provider-policy.ts's answer.
70
70
  */
71
- export function resolveProvider(requested, found) {
71
+ export function resolveProvider(requested, found, personDefault) {
72
72
  const installed = found.filter((p) => p.installed);
73
+ // A person's own default stands in for naming it, and never silently becomes another provider (jgwill/Miadi#942).
74
+ if (!requested && personDefault) {
75
+ const avail = found.find((p) => p.id === personDefault);
76
+ if (avail?.installed)
77
+ return { state: "ok", provider: avail, explicit: false };
78
+ return {
79
+ state: "provider_unavailable",
80
+ message: `Your default provider, ${personDefault}, is not installed on the connector host. The mission is left unstarted; name an available provider.`,
81
+ available: installed,
82
+ };
83
+ }
73
84
  if (requested) {
74
85
  const spec = PROVIDERS.find((p) => p.id === requested || p.cli === requested);
75
86
  if (!spec) {
@@ -1,7 +1,9 @@
1
+ import { type InboxRoute, type SteerableProvider } from "./steering-adapters.js";
1
2
  export declare const STEER_PROTOCOL = 1;
2
3
  /** A correction no continuation consumed in a day is stale: the work has moved on. A grant's own expiry comes sooner when it has one. */
3
4
  export declare const ENVELOPE_TTL_MS: number;
4
5
  export declare const CLAUDE_ADAPTER = "miadi-session-observability 0.1.34 or later";
6
+ export { STEERING_CONTRACT_ID } from "./steering-adapters.js";
5
7
  export declare const DELIVERY_STATES: readonly ["authorized", "forwarded_to_runtime", "queued_at_runtime", "delivered_to_agent_context", "acknowledged", "behavior_adjusted", "unsupported", "expired", "blocked", "unknown"];
6
8
  export type DeliveryState = (typeof DELIVERY_STATES)[number];
7
9
  export interface RuntimeDeps {
@@ -23,24 +25,28 @@ export interface ClaudeSessionRecord {
23
25
  /** Claude Code's own record of a running session, `<claudeDir>/sessions/<pid>.json`, if its process lives. */
24
26
  export declare function readClaudeSession(deps: RuntimeDeps, sessionId: string): ClaudeSessionRecord | null;
25
27
  export type RuntimeRoute = {
26
- route: "claude_hook_inbox";
28
+ route: InboxRoute;
29
+ provider: SteerableProvider;
27
30
  session_id: string;
28
31
  seat: string;
32
+ self_wakes: boolean;
29
33
  transcript_path?: string;
34
+ adapter_version?: string;
30
35
  } | {
31
36
  route: "none";
32
37
  code: "unsupported" | "wrong_pane" | "stale_binding";
33
38
  reason: string;
34
39
  };
35
40
  /**
36
- * Mission → session → runtime, from what each one signed: the runner's receipt names the session,
37
- * Claude Code's registry says it runs and in which pane, and the adapter's file says this session
38
- * loaded its hooks. The inbox belongs to this Unix account alone or it is not used.
41
+ * Mission → session → runtime, from what each one signed: the runner's receipt names the session and
42
+ * pane, the agent's own record says it runs there, and the adapter's file says this session loaded
43
+ * its adapter. The inbox belongs to this Unix account alone or it is not used.
39
44
  */
40
45
  export declare function resolveRuntime(deps: RuntimeDeps, binding: {
41
46
  session_id?: string;
42
47
  pane_id?: string;
43
48
  provider?: string;
49
+ socket?: string | null;
44
50
  }): RuntimeRoute;
45
51
  export interface SteerEnvelope {
46
52
  protocol: number;
@@ -60,6 +66,8 @@ export interface SteerEnvelope {
60
66
  transcript_offset?: number;
61
67
  /** A person decided this exact steer: the grant it cites no longer speaks for it. */
62
68
  decided?: boolean;
69
+ /** The provider whose adapter this was addressed to. */
70
+ provider?: string;
63
71
  }
64
72
  /** The steer already on its way with these same words under this grant: one correction, one delivery. */
65
73
  export declare function sameInstructionInFlight(deps: RuntimeDeps, sessionId: string, grant: string, instruction: string): string | null;
@@ -76,6 +84,7 @@ export declare function enqueueSteer(deps: RuntimeDeps, args: {
76
84
  grant_expires_at?: string;
77
85
  decided?: boolean;
78
86
  transcript_path?: string;
87
+ provider?: string;
79
88
  now?: Date;
80
89
  }): {
81
90
  already: boolean;
@@ -95,22 +104,26 @@ export declare function revokeInInbox(deps: RuntimeDeps, sessionId: string, targ
95
104
  already_consumed: string[];
96
105
  };
97
106
  export interface DeliveryReceipt {
98
- state: DeliveryState | "runtime_hook_emitted" | "seat_was_idle" | "seat_woken";
107
+ state: DeliveryState | "runtime_hook_emitted" | "in_model_request" | "seat_was_idle" | "seat_woken" | "emit_failed" | "wake_not_submitted" | "left_provider_queue";
99
108
  at?: string;
100
- source: "connector" | "runtime_inbox" | "runtime_hook" | "claude_transcript" | "connector_clock" | "factory_runner";
109
+ source: "connector" | "runtime_inbox" | "runtime_hook" | "claude_transcript" | "pi_session" | "copilot_events" | "codex_rollout" | "connector_clock" | "factory_runner";
101
110
  detail?: Record<string, unknown>;
102
111
  }
103
112
  export interface SteerDelivery {
104
113
  state: DeliveryState;
105
114
  route: string;
115
+ provider?: string;
106
116
  session_id?: string;
107
117
  receipts: DeliveryReceipt[];
108
118
  /**
109
119
  * While it waits, what will carry it: `next_tool_or_turn_end` for a working seat;
110
120
  * `runner_wakes_idle_seat` for a seat already idle, which the factory runner's next pass prompts;
111
- * `session_not_running` until a person resumes it, or it expires.
121
+ * `session_not_running` until a person resumes it, or it expires;
122
+ * `provider_queue` once it sits in the provider's own queue, which drains at its next continuation.
112
123
  */
113
- continuation?: "next_tool_or_turn_end" | "runner_wakes_idle_seat" | "session_not_running";
124
+ continuation?: "next_tool_or_turn_end" | "runner_wakes_idle_seat" | "session_not_running" | "provider_queue";
125
+ /** It has waited longer than this route should take, or its door refused it: still on its way, and not on time. */
126
+ overdue?: boolean;
114
127
  /** What the agent did after it received it, from its transcript. Whether that follows the correction is a person's judgment unless the steer named what to look for. */
115
128
  next_actions?: {
116
129
  at?: string;
@@ -145,6 +158,8 @@ interface TranscriptEvidence {
145
158
  * results and the agent's quotes of the id do not count as delivery.
146
159
  */
147
160
  export declare function readTranscriptEvidence(path: string, offset: number, steer: string): TranscriptEvidence;
161
+ /** What a provider other than Claude Code recorded about this steer, by the same rule as readTranscriptEvidence. */
162
+ export declare function readAgentEvidence(provider: SteerableProvider, path: string, offset: number, steer: string): TranscriptEvidence;
148
163
  /** Whether a prompt typed into the bound pane reached the session: Claude Code's own user or queued-prompt record. A pane echo proves nothing. */
149
164
  export declare function typedLineInTranscript(path: string, offset: number, instruction: string): {
150
165
  at?: string;
@@ -179,4 +194,3 @@ export declare function settlementOf(deps: RuntimeDeps, record: {
179
194
  message: string;
180
195
  at?: string;
181
196
  } | null;
182
- export {};