@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.
- package/README.md +8 -8
- package/STEERING.md +87 -0
- package/dist/approve.d.ts +16 -3
- package/dist/approve.js +195 -15
- package/dist/bin.js +5 -0
- package/dist/mission-status.d.ts +5 -0
- package/dist/mission-status.js +7 -1
- package/dist/provider-policy.d.ts +9 -1
- package/dist/provider-policy.js +14 -4
- package/dist/providers.d.ts +1 -1
- package/dist/providers.js +12 -1
- package/dist/runtime-steer.d.ts +23 -9
- package/dist/runtime-steer.js +272 -35
- package/dist/server.d.ts +3 -1
- package/dist/server.js +16 -2
- package/dist/steer.d.ts +8 -1
- package/dist/steer.js +60 -32
- package/dist/steering-adapters.d.ts +78 -0
- package/dist/steering-adapters.js +214 -0
- package/dist/tools.d.ts +7 -16
- package/dist/tools.js +56 -19
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -2
package/dist/steer.js
CHANGED
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
* The active pane plays no part.
|
|
9
9
|
* - A working agent is the normal case (jgwill/Miadi#930). With a runtime route, the correction
|
|
10
10
|
* goes to that session's own inbox and the runtime decides when its model reads it
|
|
11
|
-
* (runtime-steer.ts). Without one,
|
|
12
|
-
* is typed into a working agent's pane.
|
|
13
|
-
* -
|
|
14
|
-
* pane: peek → scoped act → re-peek (jgwill/Miadi#345).
|
|
15
|
-
*
|
|
11
|
+
* (runtime-steer.ts, steering-adapters.ts). Without one, the steer answers unsupported with the
|
|
12
|
+
* reason; nothing is typed into a working agent's pane.
|
|
13
|
+
* - A Claude Code seat already idle has no continuation coming, so it is the one case still typed,
|
|
14
|
+
* into its bound pane: peek → scoped act → re-peek (jgwill/Miadi#345). Every other provider's
|
|
15
|
+
* adapter has a door without a keyboard (jgwill/Miadi#942). A pane echo is not acceptance; what
|
|
16
|
+
* reached the model is read from the agent's own record (readSteerDelivery).
|
|
16
17
|
* - Every attempt leaves a durable artifact: the instruction, its sha256, the
|
|
17
18
|
* grant it ran under, the target, the timestamps and both captures.
|
|
18
19
|
* - Pane content is evidence, never instruction: nothing an agent printed is
|
|
@@ -23,6 +24,7 @@ import { execFileSync } from "node:child_process";
|
|
|
23
24
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
24
25
|
import { join } from "node:path";
|
|
25
26
|
import { enqueueSteer, resolveRuntime, sameInstructionInFlight, transcriptPathOf } from "./runtime-steer.js";
|
|
27
|
+
import { adapterOf } from "./steering-adapters.js";
|
|
26
28
|
export const STEER_STATUSES = [
|
|
27
29
|
"prepared",
|
|
28
30
|
"submitted",
|
|
@@ -95,6 +97,14 @@ export function tmuxAdapter(exec = execFileSync) {
|
|
|
95
97
|
listSessions() {
|
|
96
98
|
return tmux(["list-sessions", "-F", "#{session_name}"]).split("\n").filter(Boolean);
|
|
97
99
|
},
|
|
100
|
+
socketPath() {
|
|
101
|
+
try {
|
|
102
|
+
return tmux(["list-sessions", "-F", "#{socket_path}"]).split("\n").filter(Boolean)[0] ?? null;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
98
108
|
};
|
|
99
109
|
}
|
|
100
110
|
/**
|
|
@@ -222,6 +232,7 @@ export async function steerSession(deps, args) {
|
|
|
222
232
|
let typed = false;
|
|
223
233
|
let forwarded = false;
|
|
224
234
|
let route;
|
|
235
|
+
let runtimeSession;
|
|
225
236
|
let transcript = {};
|
|
226
237
|
const finish = (status, message, extra = {}, target) => {
|
|
227
238
|
const artifact = persistArtifact(deps.stateDir, record.id, {
|
|
@@ -234,13 +245,14 @@ export async function steerSession(deps, args) {
|
|
|
234
245
|
typed,
|
|
235
246
|
...(forwarded ? { forwarded } : {}),
|
|
236
247
|
...(route ? { route } : {}),
|
|
248
|
+
...(runtimeSession ? { runtime_session_id: runtimeSession } : {}),
|
|
237
249
|
...transcript,
|
|
238
250
|
...(target ? { target } : {}),
|
|
239
251
|
...(args.binding ? { binding: args.binding } : {}),
|
|
240
252
|
at: now().toISOString(),
|
|
241
253
|
...extra,
|
|
242
254
|
});
|
|
243
|
-
return { status, message, typed, ...(forwarded ? { forwarded } : {}), ...(route ? { route } : {}), ...transcript, ...(target ? { target } : {}), artifact };
|
|
255
|
+
return { status, message, typed, ...(forwarded ? { forwarded } : {}), ...(route ? { route } : {}), ...(runtimeSession ? { runtime_session_id: runtimeSession } : {}), ...transcript, ...(target ? { target } : {}), artifact };
|
|
244
256
|
};
|
|
245
257
|
if (!instruction.trim())
|
|
246
258
|
return { status: "blocked", message: "The steer carries no instruction.", typed: false };
|
|
@@ -254,6 +266,7 @@ export async function steerSession(deps, args) {
|
|
|
254
266
|
typed: sent.typed === true,
|
|
255
267
|
...(sent.forwarded === true ? { forwarded: true } : {}),
|
|
256
268
|
...(earlierRoute ? { route: earlierRoute } : {}),
|
|
269
|
+
...(typeof sent.runtime_session_id === "string" ? { runtime_session_id: sent.runtime_session_id } : {}),
|
|
257
270
|
...(typeof sent.transcript_offset === "number" ? { transcript_offset: sent.transcript_offset } : {}),
|
|
258
271
|
...(typeof sent.target === "string" ? { target: sent.target } : {}),
|
|
259
272
|
artifact: { file: artifactPath(deps.stateDir, record.id), sha256: String(sent.instruction_sha256 ?? "") },
|
|
@@ -317,7 +330,7 @@ export async function steerSession(deps, args) {
|
|
|
317
330
|
// Code's registry and the adapter's file, never a reading of the pane (jgwill/Miadi#930).
|
|
318
331
|
const provider = args.binding?.provider ?? str(grantRecord.body.resolved_provider) ?? str(grantRecord.body.provider);
|
|
319
332
|
const runtime = deps.runtime
|
|
320
|
-
? resolveRuntime(deps.runtime, { session_id: args.binding?.session_id, pane_id: pane.id, provider })
|
|
333
|
+
? resolveRuntime(deps.runtime, { session_id: args.binding?.session_id, pane_id: pane.id, provider, socket: deps.tmux.socketPath?.() ?? null })
|
|
321
334
|
: { route: "none", code: "unsupported", reason: "This host has no runtime steering route configured." };
|
|
322
335
|
if (runtime.route === "none" && runtime.code !== "unsupported") {
|
|
323
336
|
return finish(runtime.code, `${runtime.reason} Nothing was sent.`, { pane: { ...pane } }, target);
|
|
@@ -339,19 +352,33 @@ export async function steerSession(deps, args) {
|
|
|
339
352
|
// A person's decision on this exact steer stands apart from the grant it cites: the grant's expiry and revocation do not stop it.
|
|
340
353
|
...(args.authorized ? { decided: true } : grant?.expires_at ? { grant_expires_at: grant.expires_at } : {}),
|
|
341
354
|
...(rt.transcript_path ? { transcript_path: rt.transcript_path } : {}),
|
|
355
|
+
provider: rt.provider,
|
|
342
356
|
now: now(),
|
|
343
357
|
});
|
|
344
358
|
forwarded = true;
|
|
345
|
-
route =
|
|
359
|
+
route = rt.route;
|
|
360
|
+
runtimeSession = rt.session_id;
|
|
346
361
|
transcript = envelope.transcript_offset !== undefined ? { transcript_offset: envelope.transcript_offset } : {};
|
|
347
|
-
return finish("queued_at_runtime", `Handed to the inbox of
|
|
362
|
+
return finish("queued_at_runtime", `Handed to the inbox of ${adapterOf(rt.provider).name} session ${rt.session_id}. Its adapter presents it to its model at its next continuation: ${adapterOf(rt.provider).continuation}. This is not yet proof the model read it.`, { inbox_file: file, already_queued: already, queued_at: envelope.queued_at, expires_at: envelope.expires_at, provider: rt.provider, ...(rt.adapter_version ? { adapter_version: rt.adapter_version } : {}) }, target);
|
|
348
363
|
}
|
|
349
364
|
catch (error) {
|
|
350
365
|
return finish("blocked", `The inbox of session ${rt.session_id} refused the steer (${error instanceof Error ? error.message : String(error)}); nothing was forwarded.`, {}, target);
|
|
351
366
|
}
|
|
352
367
|
};
|
|
353
|
-
|
|
354
|
-
|
|
368
|
+
// A session with an adapter is never typed into by the connector, idle or busy. An idle seat that
|
|
369
|
+
// cannot start a turn by itself gets its next prompt from the factory runner, which owns that seat's
|
|
370
|
+
// lifecycle and waits for someone's words at its prompt (jgwill/Miadi#942).
|
|
371
|
+
if (runtime.route !== "none") {
|
|
372
|
+
const handed = forward(runtime);
|
|
373
|
+
if (handed.forwarded && runtime.seat === "idle" && !runtime.self_wakes)
|
|
374
|
+
deps.wakeRunner?.();
|
|
375
|
+
return handed;
|
|
376
|
+
}
|
|
377
|
+
// The typed path below reads Claude Code's screen, so it is only ever for a seat known to be Claude Code.
|
|
378
|
+
if (provider !== "claude" && !(!provider && pane.command === "claude")) {
|
|
379
|
+
const reason = provider ? runtime.reason : `This mission names no provider, and ${target} runs "${pane.command}", so nothing tells which door it has.`;
|
|
380
|
+
return finish("unsupported", `${reason} Nothing was typed.`, { pane: { ...pane } }, target);
|
|
381
|
+
}
|
|
355
382
|
let before;
|
|
356
383
|
try {
|
|
357
384
|
before = deps.tmux.capture(target);
|
|
@@ -360,20 +387,13 @@ export async function steerSession(deps, args) {
|
|
|
360
387
|
return finish("blocked", `The pane could not be read (${error instanceof Error ? error.message : String(error)}); nothing was typed.`, {}, target);
|
|
361
388
|
}
|
|
362
389
|
if (isBusy(before)) {
|
|
363
|
-
|
|
364
|
-
return forward(runtime);
|
|
365
|
-
return finish("unsupported", `The agent in ${target} is working and has no runtime steering route: ${runtime.route === "none" ? runtime.reason : ""} Nothing was typed.`, { peek: before.split("\n").slice(-CAPTURE_LINES) }, target);
|
|
390
|
+
return finish("unsupported", `The agent in ${target} is working and has no runtime steering route: ${runtime.reason} Nothing was typed.`, { peek: before.split("\n").slice(-CAPTURE_LINES) }, target);
|
|
366
391
|
}
|
|
367
392
|
const composing = composingText(before);
|
|
368
393
|
if (composing === null) {
|
|
369
|
-
if (runtime.route === "claude_hook_inbox")
|
|
370
|
-
return forward(runtime);
|
|
371
394
|
return finish("blocked", `The prompt box of ${target} (${pane.command}) cannot be read, so whether someone is writing there cannot be told. Nothing was typed.`, { peek: before.split("\n").slice(-CAPTURE_LINES) }, target);
|
|
372
395
|
}
|
|
373
396
|
if (composing) {
|
|
374
|
-
// Someone's words are at the prompt: the inbox waits for their prompt and never touches them.
|
|
375
|
-
if (runtime.route === "claude_hook_inbox")
|
|
376
|
-
return forward(runtime);
|
|
377
397
|
return finish("composing", `Text already sits at the prompt in ${target}; someone may be writing. Nothing was typed and Enter was not pressed.`, { peek: before.split("\n").slice(-CAPTURE_LINES) }, target);
|
|
378
398
|
}
|
|
379
399
|
if (deps.runtime && args.binding?.session_id) {
|
|
@@ -392,19 +412,27 @@ export async function steerSession(deps, args) {
|
|
|
392
412
|
}
|
|
393
413
|
typed = true;
|
|
394
414
|
route = "tmux_exact_pane";
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
415
|
+
const firstWords = instruction.split("\n")[0].slice(0, 80);
|
|
416
|
+
let after = "";
|
|
417
|
+
// A TUI can take an Enter sent right after the text as part of a paste, and leave the words at its
|
|
418
|
+
// prompt: seen on Claude Code 2.1.319 (jgwill/Miadi#942). Enter again while they still sit there.
|
|
419
|
+
for (let press = 0; press < 3; press++) {
|
|
420
|
+
await sleep(press === 0 ? (deps.settleMs ?? 4000) / 4 : 1000);
|
|
421
|
+
try {
|
|
422
|
+
deps.tmux.sendEnter(target);
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
return finish("submitted", `Typed into ${target}, but Enter failed (${error instanceof Error ? error.message : String(error)}); the text may sit at the prompt.`, { peek: before.split("\n").slice(-CAPTURE_LINES) }, target);
|
|
426
|
+
}
|
|
427
|
+
await sleep(deps.settleMs ?? 4000);
|
|
428
|
+
try {
|
|
429
|
+
after = deps.tmux.capture(target);
|
|
430
|
+
}
|
|
431
|
+
catch (error) {
|
|
432
|
+
return finish("submitted", `Typed into ${target}, but the re-peek failed (${error instanceof Error ? error.message : String(error)}); acceptance is unconfirmed.`, { peek: before.split("\n").slice(-CAPTURE_LINES) }, target);
|
|
433
|
+
}
|
|
434
|
+
if (!(composingText(after) ?? "").includes(firstWords))
|
|
435
|
+
break;
|
|
408
436
|
}
|
|
409
437
|
let current;
|
|
410
438
|
try {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export declare const STEERING_CONTRACT_ID = "miadi.steering/1";
|
|
2
|
+
export declare const INBOX_ROUTES: readonly ["claude_hook_inbox", "pi_steer_queue", "copilot_session_send", "codex_hook_inbox"];
|
|
3
|
+
export type InboxRoute = (typeof INBOX_ROUTES)[number];
|
|
4
|
+
export declare const isInboxRoute: (route: unknown) => route is InboxRoute;
|
|
5
|
+
export type SteerableProvider = "claude" | "pi" | "copilot" | "codex";
|
|
6
|
+
export interface AdapterSpec {
|
|
7
|
+
provider: SteerableProvider;
|
|
8
|
+
name: string;
|
|
9
|
+
route: InboxRoute;
|
|
10
|
+
adapter: string;
|
|
11
|
+
min_adapter_version: string;
|
|
12
|
+
/** Where the correction enters while the agent works. */
|
|
13
|
+
continuation: string;
|
|
14
|
+
/** What happens when the agent is not working. */
|
|
15
|
+
idle: string;
|
|
16
|
+
/** True when the adapter starts a turn on an idle session itself, with nothing typed. */
|
|
17
|
+
self_wakes: boolean;
|
|
18
|
+
/** Which of the provider's own records shows what its model received. */
|
|
19
|
+
evidence: "claude_transcript" | "pi_session" | "copilot_events" | "codex_rollout";
|
|
20
|
+
/** The CLI versions a real session passed on, with the receipts' issue. */
|
|
21
|
+
tested_on: {
|
|
22
|
+
cli_version: string;
|
|
23
|
+
adapter_version: string;
|
|
24
|
+
at: string;
|
|
25
|
+
cases: string[];
|
|
26
|
+
}[];
|
|
27
|
+
/** What this route does not do. Each was observed on a real session. */
|
|
28
|
+
limits: string[];
|
|
29
|
+
needs: string;
|
|
30
|
+
}
|
|
31
|
+
export declare const ADAPTERS: Record<SteerableProvider, AdapterSpec>;
|
|
32
|
+
export declare const adapterOf: (provider: unknown) => AdapterSpec | undefined;
|
|
33
|
+
export declare const adapterOfRoute: (route: unknown) => AdapterSpec | undefined;
|
|
34
|
+
export interface AdapterProbe {
|
|
35
|
+
home?: string;
|
|
36
|
+
/** The factory's config. */
|
|
37
|
+
factory?: {
|
|
38
|
+
launchers?: Record<string, {
|
|
39
|
+
command?: string;
|
|
40
|
+
}>;
|
|
41
|
+
} | null;
|
|
42
|
+
}
|
|
43
|
+
/** The adapter this host would load into a new session of this provider: its version, or why not. */
|
|
44
|
+
export declare function installedAdapter(provider: SteerableProvider, probe?: AdapterProbe): {
|
|
45
|
+
version: string | null;
|
|
46
|
+
missing?: string;
|
|
47
|
+
};
|
|
48
|
+
export interface SteeringSupport {
|
|
49
|
+
contract: string;
|
|
50
|
+
provider: string;
|
|
51
|
+
steerable: boolean;
|
|
52
|
+
/** same_turn: a working agent's model reads it at its next continuation. none: it cannot be steered. */
|
|
53
|
+
level: "same_turn" | "none";
|
|
54
|
+
/** tested: a real session of this CLI version changed its next decision. untested_cli_version: the route exists and this version has not been shown. */
|
|
55
|
+
basis: "tested" | "untested_cli_version" | "no_adapter";
|
|
56
|
+
route?: InboxRoute;
|
|
57
|
+
cli_version?: string | null;
|
|
58
|
+
adapter?: {
|
|
59
|
+
name: string;
|
|
60
|
+
version: string | null;
|
|
61
|
+
};
|
|
62
|
+
continuation?: string;
|
|
63
|
+
idle?: string;
|
|
64
|
+
tested_on?: AdapterSpec["tested_on"];
|
|
65
|
+
limits?: string[];
|
|
66
|
+
needs?: string;
|
|
67
|
+
/** Why a new session of this provider would not be steerable. */
|
|
68
|
+
reason?: string;
|
|
69
|
+
}
|
|
70
|
+
/** What a new session of this provider on this host can promise, from what is installed and what was tested. */
|
|
71
|
+
export declare function steeringSupport(provider: string, cliVersion: string | null | undefined, probe?: AdapterProbe): SteeringSupport;
|
|
72
|
+
/** A provider's steering support as a request's decision shows it, with CLI versions read at most once in five minutes. */
|
|
73
|
+
export declare function runSteering(discover: () => {
|
|
74
|
+
id: string;
|
|
75
|
+
version?: string | null;
|
|
76
|
+
}[], probe: () => AdapterProbe): (provider: string) => SteeringSupport;
|
|
77
|
+
/** The factory's own config file, for the launchers it would use. */
|
|
78
|
+
export declare function readFactoryConfig(factoryDirectory: string): AdapterProbe["factory"];
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which terminal agents a correction can reach, and how that is known (jgwill/Miadi#942).
|
|
3
|
+
* STEERING.md beside this package holds the contract. This file holds the matrix and the host check.
|
|
4
|
+
*
|
|
5
|
+
* Every line of TESTED_ON came from a real disposable session of that provider, whose next decision
|
|
6
|
+
* changed after the correction. A provider is not listed as steerable from reading its documentation,
|
|
7
|
+
* and an installed CLI whose version is not listed reads as untested, not as supported.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
export const STEERING_CONTRACT_ID = "miadi.steering/1";
|
|
13
|
+
export const INBOX_ROUTES = ["claude_hook_inbox", "pi_steer_queue", "copilot_session_send", "codex_hook_inbox"];
|
|
14
|
+
export const isInboxRoute = (route) => INBOX_ROUTES.includes(route);
|
|
15
|
+
const CASES = ["busy", "no_next_tool", "idle", "two_sessions", "no_adapter", "restart"];
|
|
16
|
+
export const ADAPTERS = {
|
|
17
|
+
claude: {
|
|
18
|
+
provider: "claude",
|
|
19
|
+
name: "Claude Code",
|
|
20
|
+
route: "claude_hook_inbox",
|
|
21
|
+
adapter: "miadi-session-observability",
|
|
22
|
+
min_adapter_version: "0.1.34",
|
|
23
|
+
continuation: "PostToolUse and PostToolUseFailure additionalContext in the same turn, then Stop decision block when no tool follows",
|
|
24
|
+
idle: "The stop-watch hook wakes the model for 30 s after a turn ends. After that the factory runner types one line that holds none of the correction's words into its bound pane, unless someone's words sit at its prompt, and UserPromptSubmit presents the correction.",
|
|
25
|
+
self_wakes: false,
|
|
26
|
+
evidence: "claude_transcript",
|
|
27
|
+
tested_on: [{ cli_version: "2.1.319", adapter_version: "0.1.39", at: "2026-11-06", cases: CASES }],
|
|
28
|
+
limits: ["A running tool finishes first, so a long tool delays the correction by its own length.", "Hooks load at session start, so a session started before the adapter cannot be steered mid-turn."],
|
|
29
|
+
needs: "miadi-session-observability 0.1.34 or later, enabled when the session started",
|
|
30
|
+
},
|
|
31
|
+
pi: {
|
|
32
|
+
provider: "pi",
|
|
33
|
+
name: "Pi coding agent",
|
|
34
|
+
route: "pi_steer_queue",
|
|
35
|
+
adapter: "@miadi/pi-session-observability",
|
|
36
|
+
min_adapter_version: "0.1.2",
|
|
37
|
+
continuation: "Pi's own steering queue, through its extension API: after the current assistant turn has run its tool calls, before the next model request",
|
|
38
|
+
idle: "The adapter starts a run itself. Nothing is typed.",
|
|
39
|
+
self_wakes: true,
|
|
40
|
+
evidence: "pi_session",
|
|
41
|
+
tested_on: [{ cli_version: "1.4.0", adapter_version: "0.1.2", at: "2026-11-06", cases: CASES }],
|
|
42
|
+
limits: ["All of a turn's tool calls finish first, so a long batch delays the correction by its own length.", "Extensions load at session start or /reload, so a session started before the adapter cannot be steered."],
|
|
43
|
+
needs: "@miadi/pi-session-observability 0.1.2 or later in ~/.pi/agent/settings.json packages, loaded when the session started",
|
|
44
|
+
},
|
|
45
|
+
copilot: {
|
|
46
|
+
provider: "copilot",
|
|
47
|
+
name: "GitHub Copilot CLI",
|
|
48
|
+
route: "copilot_session_send",
|
|
49
|
+
adapter: "miadi-steering (Copilot extension)",
|
|
50
|
+
min_adapter_version: "0.1.0",
|
|
51
|
+
continuation: "session.send with mode immediate, the door a person's Enter uses, held until the tools in flight have finished",
|
|
52
|
+
idle: "The adapter starts a turn itself. Nothing is typed.",
|
|
53
|
+
self_wakes: true,
|
|
54
|
+
evidence: "copilot_events",
|
|
55
|
+
tested_on: [{ cli_version: "1.0.107", adapter_version: "0.1.0", at: "2026-11-06", cases: CASES }],
|
|
56
|
+
limits: [
|
|
57
|
+
"Copilot loads extensions only when enabledFeatureFlags.EXTENSIONS is on, which the installer sets, so a session started before that cannot be steered.",
|
|
58
|
+
"A shell command that starts just as the correction arrives is moved to the background and keeps running. Its line of work may finish after the corrected action.",
|
|
59
|
+
"Copilot updates itself, so the CLI that runs may be newer than the one tested. That reads as an untested version until a real session passes on it.",
|
|
60
|
+
],
|
|
61
|
+
needs: "~/.copilot/extensions/miadi-steering and enabledFeatureFlags.EXTENSIONS in ~/.copilot/settings.json (the kit's copilot/miadi-steering/install.sh does both)",
|
|
62
|
+
},
|
|
63
|
+
codex: {
|
|
64
|
+
provider: "codex",
|
|
65
|
+
name: "Codex CLI",
|
|
66
|
+
route: "codex_hook_inbox",
|
|
67
|
+
adapter: "miadi-steering (Codex hooks)",
|
|
68
|
+
min_adapter_version: "0.1.0",
|
|
69
|
+
continuation: "PostToolUse additionalContext in the same turn, then Stop decision block when no tool follows",
|
|
70
|
+
idle: "The factory runner's next pass runs codex queue on the thread, and UserPromptSubmit presents the correction. Nothing is typed.",
|
|
71
|
+
self_wakes: false,
|
|
72
|
+
evidence: "codex_rollout",
|
|
73
|
+
tested_on: [{ cli_version: "0.166.0", adapter_version: "0.1.0", at: "2026-11-06", cases: CASES }],
|
|
74
|
+
limits: [
|
|
75
|
+
"The correction reaches the model as developer-role context, because that is what the hook door writes. Its text names the person who sent it and claims no new permission.",
|
|
76
|
+
"A running tool finishes first, so a long tool delays the correction by its own length.",
|
|
77
|
+
"Hooks load at session start and Codex runs them only when trusted, so a session started before the adapter cannot be steered.",
|
|
78
|
+
],
|
|
79
|
+
needs: "miadi-steering in ~/.codex, its hooks in ~/.codex/hooks.json and trusted in ~/.codex/config.toml (the kit's codex/miadi-steering/install.mjs does all three)",
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
export const adapterOf = (provider) => (typeof provider === "string" && provider in ADAPTERS ? ADAPTERS[provider] : undefined);
|
|
83
|
+
export const adapterOfRoute = (route) => Object.values(ADAPTERS).find((a) => a.route === route);
|
|
84
|
+
const readJson = (path) => {
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function compareVersions(a, b) {
|
|
93
|
+
const parts = (v) => v.split(/[.-]/).map((x) => Number.parseInt(x, 10) || 0);
|
|
94
|
+
const [x, y] = [parts(a), parts(b)];
|
|
95
|
+
for (let i = 0; i < Math.max(x.length, y.length); i++) {
|
|
96
|
+
if ((x[i] ?? 0) !== (y[i] ?? 0))
|
|
97
|
+
return (x[i] ?? 0) - (y[i] ?? 0);
|
|
98
|
+
}
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
/** The adapter this host would load into a new session of this provider: its version, or why not. */
|
|
102
|
+
export function installedAdapter(provider, probe = {}) {
|
|
103
|
+
const home = probe.home ?? homedir();
|
|
104
|
+
if (provider === "claude") {
|
|
105
|
+
const cache = join(home, ".claude/plugins/cache");
|
|
106
|
+
const settings = readJson(join(home, ".claude/settings.json"));
|
|
107
|
+
const enabled = Object.entries((settings?.enabledPlugins ?? {})).some(([k, v]) => k.startsWith("miadi-session-observability@") && v === true);
|
|
108
|
+
if (!enabled)
|
|
109
|
+
return { version: null, missing: "miadi-session-observability is not enabled in ~/.claude/settings.json" };
|
|
110
|
+
const versions = [];
|
|
111
|
+
try {
|
|
112
|
+
for (const market of readdirSync(cache)) {
|
|
113
|
+
const dir = join(cache, market, "miadi-session-observability");
|
|
114
|
+
if (!existsSync(dir))
|
|
115
|
+
continue;
|
|
116
|
+
for (const v of readdirSync(dir))
|
|
117
|
+
if (existsSync(join(dir, v, "hooks/steering_inbox.mjs")))
|
|
118
|
+
versions.push(v);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// No plugin cache: the plugin is not installed.
|
|
123
|
+
}
|
|
124
|
+
const top = versions.sort(compareVersions).at(-1);
|
|
125
|
+
return top ? { version: top } : { version: null, missing: "no cached miadi-session-observability carries the steering hook" };
|
|
126
|
+
}
|
|
127
|
+
if (provider === "pi") {
|
|
128
|
+
const settings = readJson(join(home, ".pi/agent/settings.json"));
|
|
129
|
+
for (const pkg of (settings?.packages ?? [])) {
|
|
130
|
+
const source = typeof pkg === "string" ? pkg : pkg?.source;
|
|
131
|
+
if (typeof source !== "string")
|
|
132
|
+
continue;
|
|
133
|
+
// A published package lives in Pi's own npm folder, a checkout at its path.
|
|
134
|
+
const name = source.startsWith("npm:") ? source.slice(4).replace(/(.)@[^/]*$/, "$1") : null;
|
|
135
|
+
const manifest = readJson(join(name ? join(home, ".pi/agent/npm/node_modules", name) : source, "package.json"));
|
|
136
|
+
if ((manifest?.pi?.extensions ?? []).some((e) => e.includes("steering-inbox")))
|
|
137
|
+
return { version: String(manifest.version) };
|
|
138
|
+
}
|
|
139
|
+
return { version: null, missing: "no package in ~/.pi/agent/settings.json carries the steering extension" };
|
|
140
|
+
}
|
|
141
|
+
if (provider === "copilot") {
|
|
142
|
+
const copilotHome = process.env.COPILOT_HOME || join(home, ".copilot");
|
|
143
|
+
const manifest = readJson(join(copilotHome, "extensions/miadi-steering/package.json"));
|
|
144
|
+
if (!manifest)
|
|
145
|
+
return { version: null, missing: "~/.copilot/extensions/miadi-steering is not installed" };
|
|
146
|
+
// Copilot loads extensions only under this flag. --experimental also turns it on, and stays on for every later session.
|
|
147
|
+
const settings = readJson(join(copilotHome, "settings.json"));
|
|
148
|
+
if (settings?.enabledFeatureFlags?.EXTENSIONS !== true && settings?.experimental !== true)
|
|
149
|
+
return { version: String(manifest.version), missing: "~/.copilot/settings.json does not enable EXTENSIONS, so Copilot would not load the extension" };
|
|
150
|
+
return { version: String(manifest.version) };
|
|
151
|
+
}
|
|
152
|
+
const codexHome = process.env.CODEX_HOME || join(home, ".codex");
|
|
153
|
+
const hooks = readJson(join(codexHome, "hooks.json"));
|
|
154
|
+
if (!JSON.stringify(hooks?.hooks ?? {}).includes("miadi-steering/steering_inbox.sh"))
|
|
155
|
+
return { version: null, missing: "the steering hooks are not in ~/.codex/hooks.json" };
|
|
156
|
+
const version = readJson(join(codexHome, "miadi-steering/package.json"))?.version;
|
|
157
|
+
if (!version)
|
|
158
|
+
return { version: null, missing: "~/.codex/miadi-steering is not installed" };
|
|
159
|
+
// install.mjs recorded the hash Codex itself gave for each hook; the config must still trust that exact hash.
|
|
160
|
+
const trusted = Object.entries((readJson(join(codexHome, "miadi-steering/trusted.json")) ?? {}));
|
|
161
|
+
let config = "";
|
|
162
|
+
try {
|
|
163
|
+
config = readFileSync(join(codexHome, "config.toml"), "utf8");
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// No config: nothing trusted.
|
|
167
|
+
}
|
|
168
|
+
const held = trusted.filter(([key, hash]) => config.includes(`[hooks.state.${JSON.stringify(key)}]\ntrusted_hash = ${JSON.stringify(hash)}`));
|
|
169
|
+
if (trusted.length < 5 || held.length < trusted.length)
|
|
170
|
+
return { version: String(version), missing: "Codex does not trust the steering hooks as they stand, and it runs no untrusted hook" };
|
|
171
|
+
return { version: String(version) };
|
|
172
|
+
}
|
|
173
|
+
const versionWord = (raw) => raw?.match(/\d+\.\d+\.\d+/)?.[0] ?? null;
|
|
174
|
+
/** What a new session of this provider on this host can promise, from what is installed and what was tested. */
|
|
175
|
+
export function steeringSupport(provider, cliVersion, probe = {}) {
|
|
176
|
+
const spec = adapterOf(provider);
|
|
177
|
+
if (!spec) {
|
|
178
|
+
return { contract: STEERING_CONTRACT_ID, provider, steerable: false, level: "none", basis: "no_adapter", reason: `No steering adapter exists for provider "${provider}". A session of it cannot be steered.` };
|
|
179
|
+
}
|
|
180
|
+
const version = versionWord(cliVersion);
|
|
181
|
+
const { version: adapterVersion, missing } = installedAdapter(spec.provider, probe);
|
|
182
|
+
const tooOld = adapterVersion && compareVersions(adapterVersion, spec.min_adapter_version) < 0 ? `the adapter is ${adapterVersion}, older than ${spec.min_adapter_version}` : undefined;
|
|
183
|
+
const reason = missing ?? tooOld;
|
|
184
|
+
const tested = version ? spec.tested_on.some((t) => t.cli_version === version) : false;
|
|
185
|
+
return {
|
|
186
|
+
contract: STEERING_CONTRACT_ID,
|
|
187
|
+
provider: spec.provider,
|
|
188
|
+
steerable: !reason,
|
|
189
|
+
level: reason ? "none" : "same_turn",
|
|
190
|
+
basis: reason ? "no_adapter" : tested ? "tested" : "untested_cli_version",
|
|
191
|
+
route: spec.route,
|
|
192
|
+
cli_version: version,
|
|
193
|
+
adapter: { name: spec.adapter, version: adapterVersion },
|
|
194
|
+
continuation: spec.continuation,
|
|
195
|
+
idle: spec.idle,
|
|
196
|
+
tested_on: spec.tested_on,
|
|
197
|
+
limits: spec.limits,
|
|
198
|
+
needs: spec.needs,
|
|
199
|
+
...(reason ? { reason: `A new ${spec.name} session here could not be steered: ${reason}.` } : {}),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/** A provider's steering support as a request's decision shows it, with CLI versions read at most once in five minutes. */
|
|
203
|
+
export function runSteering(discover, probe) {
|
|
204
|
+
let versions;
|
|
205
|
+
return (provider) => {
|
|
206
|
+
if (!versions || Date.now() - versions.at > 300_000)
|
|
207
|
+
versions = { at: Date.now(), found: discover() };
|
|
208
|
+
return steeringSupport(provider, versions.found.find((p) => p.id === provider)?.version, probe());
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/** The factory's own config file, for the launchers it would use. */
|
|
212
|
+
export function readFactoryConfig(factoryDirectory) {
|
|
213
|
+
return readJson(join(factoryDirectory, "factory.json"));
|
|
214
|
+
}
|
package/dist/tools.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { type DiscoveryProbe, type ProviderId } from "./providers.js";
|
|
|
11
11
|
import type { DraftReviewService } from "./draft-review.js";
|
|
12
12
|
import { type JevAdapter } from "./model-preflight.js";
|
|
13
13
|
import { type RuntimeDeps } from "./runtime-steer.js";
|
|
14
|
+
import { type AdapterProbe } from "./steering-adapters.js";
|
|
14
15
|
import { type TmuxLike } from "./steer.js";
|
|
15
16
|
import { type GithubGet } from "./mission-result.js";
|
|
16
17
|
export interface ToolContext {
|
|
@@ -28,9 +29,13 @@ export interface ToolContext {
|
|
|
28
29
|
tmux?: TmuxLike;
|
|
29
30
|
/** Where sessions and their steering inboxes live (jgwill/Miadi#930). Absent, no runtime route is known. */
|
|
30
31
|
steeringRuntime?: RuntimeDeps;
|
|
32
|
+
/** Asks the factory runner for a pass now. Its timer is the net (jgwill/Miadi#942). */
|
|
33
|
+
wakeRunner?: () => void;
|
|
31
34
|
tmuxSessions?: () => string[];
|
|
32
35
|
/** Provider discovery probes; tests inject fakes (jgwill/Miadi#893). */
|
|
33
36
|
providersProbe?: DiscoveryProbe;
|
|
37
|
+
/** Where to read which steering adapters this host would load (jgwill/Miadi#942). Default: this account's home. */
|
|
38
|
+
steeringProbe?: AdapterProbe;
|
|
34
39
|
/** The configured default model of a provider; tests inject fakes (jgwill/Miadi#913). */
|
|
35
40
|
modelOf?: (provider: ProviderId) => string | null;
|
|
36
41
|
/** A Jev decider; tests inject a synthetic fixture. Absent, the connector's env decides (jgwill/Miadi#913). */
|
|
@@ -49,30 +54,16 @@ export declare function githubAccess(status: number, hasToken: boolean): string;
|
|
|
49
54
|
/** A GitHub REST read as the connector can make it: GITHUB_TOKEN when the host has one, else anonymous. */
|
|
50
55
|
export declare function githubGetter(fetchImpl?: typeof fetch, token?: string | undefined): GithubGet;
|
|
51
56
|
export declare const STEERING_CONTRACT: {
|
|
57
|
+
readonly contract: "miadi.steering/1";
|
|
52
58
|
readonly busy_is_normal: true;
|
|
53
59
|
readonly connector: "Admits the steer, resolves mission → session → runtime, hands it to that session's inbox and reports what the runtime accepted. It does not watch tools or wait for idle.";
|
|
54
|
-
readonly runtime: "The agent's own lifecycle presents it to its model at the next supported continuation
|
|
60
|
+
readonly runtime: "The agent's own lifecycle presents it to its model at the next supported continuation. Each provider's adapter says which one, and what it was shown to do on a real session.";
|
|
55
61
|
readonly delivery_states: readonly ["authorized", "forwarded_to_runtime", "queued_at_runtime", "delivered_to_agent_context", "acknowledged", "behavior_adjusted", "unsupported", "expired", "blocked", "unknown"];
|
|
56
62
|
readonly provider_adapters: {
|
|
57
|
-
readonly claude: {
|
|
58
|
-
readonly route: "claude_hook_inbox";
|
|
59
|
-
readonly continuation: "PostToolUse, PostToolUseFailure, then Stop if no tool follows";
|
|
60
|
-
readonly needs: "miadi-session-observability 0.1.34 or later, loaded when the session started";
|
|
61
|
-
};
|
|
62
|
-
readonly codex: {
|
|
63
|
-
readonly route: "unsupported";
|
|
64
|
-
};
|
|
65
|
-
readonly copilot: {
|
|
66
|
-
readonly route: "unsupported";
|
|
67
|
-
};
|
|
68
|
-
readonly pi: {
|
|
69
|
-
readonly route: "unsupported";
|
|
70
|
-
};
|
|
71
63
|
readonly gemini: {
|
|
72
64
|
readonly route: "unsupported";
|
|
73
65
|
};
|
|
74
66
|
};
|
|
75
|
-
readonly idle_seat: "An idle seat has no continuation coming, so its steer is typed into its bound pane once the prompt reads empty.";
|
|
76
67
|
};
|
|
77
68
|
export declare function steeringTransport(tmux: TmuxLike | undefined): {
|
|
78
69
|
tool: "registered";
|