@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/README.md
CHANGED
|
@@ -60,13 +60,13 @@ A mission is found by the issue it implements (jgwill/Miadi#913). `request_autho
|
|
|
60
60
|
|
|
61
61
|
**The agent's result (jgwill/Miadi#921).** An agent returns its work with `propose_session_completion` naming the mission in `mission`, from its bound session, with its evidence refs and, optionally, a structured `result`: `summary`, `outputs` (`ref`, `label`, `git_sha`), `tests` (`command`, `passed`, `failed`, `skipped`) and `blockers`. `mission_status` and `get_run_result` read it back by the mission id as `result`: the standing submission (the newest `verified` one: it names the mission, ends a bound session and was submitted with Miadi's write tier or the factory's writer token, which the connector records on the ending as `submitted_with_tier`; anything else naming the mission is `unverified_association` with an `association_code`, a mere citation `cited_only` and never a result), its summary, tests and blockers as the agent's claim, and each output typed and checked when read. A commit or file on GitHub is read through GitHub (`GITHUB_TOKEN` when the host has one): `verified` with its sha, `changed_since_submission` when its declared `git_sha` no longer matches or the file changed on its branch after the submission, `unverified` with the reason when GitHub cannot be read, never `not_found`. A connector record id the ledger does not hold is `not_found`. Bound sessions are taken from the factory's receipts for every reader, so the verdict is the same at every tier; below the write tier the session ids are left out. The completion decision stays the person's, and only a verified submission sets it: `stage_truth.completion` is `pending_approval`, `accepted`, `declined` or `revision_requested` (`none` for an unverified one, whose stage is `result_submitted_unverified`; an approved exit submitted below the write tier closes nothing), `pending_human_gates` lists what waits on a person with its approval page, and `mission_stage` names the furthest stage with evidence (`result_submitted_awaiting_completion_approval`, `completion_accepted`, `merged`, `released`, `closed`…). A duplicate submission (same session, ending and mission, still pending) is handed back with `replayed: true`, and `not_recorded` names what the second call carried that was not kept.
|
|
62
62
|
|
|
63
|
-
`request_session_steer` sends one person's correction to a running agent, within the steering grant an approved run carries (`steering: { max_attempts, expires_at, pane }` on `request_authorized_run`). Busy is the normal case (jgwill/Miadi#930).
|
|
63
|
+
`request_session_steer` sends one person's correction to a running agent, within the steering grant an approved run carries (`steering: { max_attempts, expires_at, pane }` on `request_authorized_run`). Busy is the normal case (jgwill/Miadi#930). [`STEERING.md`](STEERING.md) is the contract every provider's adapter keeps (`miadi.steering/1`, jgwill/Miadi#942), with what was shown on real sessions of Claude Code, Pi, Copilot and Codex and each one's limits. `get_capabilities.steering` and `provider_capabilities` serve the same matrix, with what this host would load into a new session.
|
|
64
64
|
|
|
65
65
|
| who | owns | never does |
|
|
66
66
|
|---|---|---|
|
|
67
67
|
| The person, through ChatGPT or any client | one correction, in scope | watch tools, wait for idle, send it again |
|
|
68
68
|
| The connector | who may send it, the grant, mission → session → runtime, idempotency, handing it to that session's inbox, reporting what happened | decide when the model reads it, type into a working agent's pane, call a forward a delivery |
|
|
69
|
-
| The runtime (
|
|
69
|
+
| The runtime (each provider's adapter, in jgwill/miadi-orchestration-kit) | the inbox, its order, the checks again at consumption, when its model reads it | deliver anything to a subagent or to another session |
|
|
70
70
|
| The model | reading it and changing what it does next | |
|
|
71
71
|
|
|
72
72
|
The route comes from what each part signed: the factory's receipt names the session, Claude Code's own registry says it runs and in which pane, and the adapter's `adapter.json` says this session loaded its hooks. A wrong session is `stale_binding`, a wrong pane `wrong_pane`. A provider with no adapter, or a Claude session started before the adapter (hooks load at session start), answers `unsupported` with the reason and uses no attempt. No Claude Code behaviour is assumed of Codex, Copilot or Pi, and `get_capabilities.steering.contract` names the adapters that exist.
|
|
@@ -75,15 +75,15 @@ The inbox is `$MIADI_STEERING_DIR` (default `<factory>/steering`), `<session_id>
|
|
|
75
75
|
|
|
76
76
|
Why hooks: Claude Code 2.1.318 has a native mid-turn queue, and `claude --help` offers no outside door to it. Typing reaches it through the keyboard, which is the terminal heuristic this replaces. The cross-session socket (`messagingSocketPath`) belongs to Claude sessions speaking to each other: its protocol is not published, and a connector speaking it would pose as a session. `PostToolUse.additionalContext` and `Stop` are its documented interface, so that is the adapter. Pi, Codex and Copilot have their own in-turn mechanisms, and none has an adapter here yet.
|
|
77
77
|
|
|
78
|
-
`delivery` in the answer, in `get_run_result` on the steer's id, and in `mission_status.steering.steers` (write tier) says where it stands, each state with its source and time:
|
|
78
|
+
`delivery` in the answer, in `get_run_result` on the steer's id (`steers` on its run), and in `mission_status.steering.steers` (write tier) says where it stands, each state with its source and time. The steer's approval page shows the same states and times, without tool inputs:
|
|
79
79
|
|
|
80
80
|
| state | means | source |
|
|
81
81
|
|---|---|---|
|
|
82
82
|
| `authorized` | the grant or a person's decision covered it | connector |
|
|
83
83
|
| `forwarded_to_runtime`, `queued_at_runtime` | it is in the session's inbox; the model has not necessarily read it | connector, runtime inbox |
|
|
84
|
-
| `delivered_to_agent_context` |
|
|
85
|
-
| `acknowledged` | the agent's own next text names `steer <id> received` |
|
|
86
|
-
| `behavior_adjusted` | a later tool input holds what the steer named in `expect_next_action`; without that, `behavior: not_judged` and the next actions are shown for a person to judge |
|
|
84
|
+
| `delivered_to_agent_context` | the agent recorded it among what it gave its model | its own record (Claude Code's transcript attachment, Pi's session file, Copilot's `events.jsonl`, Codex's rollout) |
|
|
85
|
+
| `acknowledged` | the agent's own next text names `steer <id> received` | its own record |
|
|
86
|
+
| `behavior_adjusted` | a later tool input holds what the steer named in `expect_next_action`; without that, `behavior: not_judged` and the next actions are shown for a person to judge | its own record |
|
|
87
87
|
| `unsupported`, `expired`, `blocked` | it never reached the model, with the reason | connector or runtime hook |
|
|
88
88
|
| `unknown` | claimed with no transcript record: ambiguous, and it is not sent again | |
|
|
89
89
|
|
|
@@ -91,9 +91,9 @@ The record itself moves with its evidence: `completed` once the model has it, `b
|
|
|
91
91
|
|
|
92
92
|
`revoke_session_steering` stops a run's steering or one steer. What is still pending moves out at once, a marker stops anything later, and the answer says exactly what was revoked and what the agent had already consumed. The same idempotency key gets the first answer back, and the same words under a new key answer `duplicate`. Only a typed or forwarded steer uses one of the grant's attempts.
|
|
93
93
|
|
|
94
|
-
An idle seat
|
|
94
|
+
An idle seat takes the same inbox, and the connector types into no session that has an adapter (jgwill/Miadi#942). Pi's and Copilot's adapters start a turn themselves. A Codex seat gets `codex queue` from the factory runner. A Claude Code seat gets one line from the factory runner, which holds none of the correction's words and waits for anyone's words at the prompt; the connector asks for that at once with `miadi-factory-runner wake` (`MIADI_FACTORY_RUNNER_BIN`), and the runner's timer is the net. The one case still typed by the connector is a Claude Code session from before its adapter, idle with an empty prompt: into the mission's bound pane, never whichever pane is active, with an exact tmux address (`=name:w.p`). It peeks first, presses Enter again while the words still sit at the prompt, and re-peeks after. Text already at the prompt, or a prompt box it cannot read, stops it. Any other provider without an adapter answers `unsupported`, and nothing is typed.
|
|
95
95
|
|
|
96
|
-
Rollback: run the connector version before this one (`git checkout` of its `dist`, then `systemctl --user restart miadi-connector`). A
|
|
96
|
+
Rollback: run the connector version before this one (`git checkout` of its `dist`, then `systemctl --user restart miadi-connector`). A steer to a Pi, Copilot or Codex session then answers `unsupported` again and nothing else changes. To stop an adapter, follow [`STEERING.md`](STEERING.md#rollback); a new session then has no `adapter.json` and answers `unsupported`. Envelopes already queued stay on disk, unread.
|
|
97
97
|
|
|
98
98
|
`request_authorized_run` may name a `provider` (`codex`, `pi`, `copilot`, `claude`). The connector verifies it is installed on the host before recording anything; an unknown or unavailable provider answers `provider_unavailable` and the mission stays unstarted. With no provider named, the first installed provider in the preference order that may be picked by default (Pi, then Copilot) is resolved and named in the brief; Codex and Claude Code are never chosen silently, each runs only when named. `provider_capabilities` (write tier) reports what the host has installed, the sign-in evidence, the preference order, and the read-only Jev check: `unconfigured` without `JEV_AI_API_KEY` or `TYPESAFE_API_KEY` in the connector's environment, else the models Jev lists for the key (no charge). A provider name inside a task's text selects nothing.
|
|
99
99
|
|
package/STEERING.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# The steering contract: `miadi.steering/1`
|
|
2
|
+
|
|
3
|
+
A person controlling a mission sends one correction. It reaches that mission's running agent at the earliest continuation that agent supports, and what the model received and did is read from the agent's own record. jgwill/Miadi#942 holds the evidence. #930 holds the correction this was built from: the runtime owns delivery to the model.
|
|
4
|
+
|
|
5
|
+
## Who owns what
|
|
6
|
+
|
|
7
|
+
| layer | owns | never does |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| Person, or the assistant they speak through | one correction, naming the mission | watch tools, wait for idle, retry |
|
|
10
|
+
| Connector (`runtime-steer.ts`, `steering-adapters.ts`) | admission, identity, grant, mission → session → provider, one durable envelope, reading delivery back | watch tools, type into an adapted session, choose the moment |
|
|
11
|
+
| Factory runner (`factory-runner/src/steering.js`, `adapters.js`) | the session's lifecycle: which session took a brief, and one prompt for an idle seat that cannot start a turn itself | read a correction's words |
|
|
12
|
+
| Adapter (jgwill/miadi-orchestration-kit) | the inbox, its order, every check again at consumption, the door into its agent | decide who may steer |
|
|
13
|
+
| The agent's own runtime | when its model reads it | |
|
|
14
|
+
|
|
15
|
+
## The states
|
|
16
|
+
|
|
17
|
+
`authorized → forwarded_to_runtime → queued_at_runtime → delivered_to_agent_context → acknowledged → behavior_adjusted`, or `unsupported`, `expired`, `blocked`, `unknown`.
|
|
18
|
+
|
|
19
|
+
| state | who says so | what it proves |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `queued_at_runtime` | the connector's write, the inbox file | the correction is durable. It proves nothing about the model |
|
|
22
|
+
| `delivered_to_agent_context` | the agent's own record | the agent wrote it among what it gave its model |
|
|
23
|
+
| `acknowledged` | the agent's own record | the model's later text names the steer back |
|
|
24
|
+
| `behavior_adjusted` | the agent's own record | one of the next five tool inputs after delivery holds the words the steer named in `expect_next_action`. Words are evidence, not intent: a `grep` for them reads the same, so the page shows the action for a person to read |
|
|
25
|
+
| `unknown` | the connector | a claim with no record. It is not sent again |
|
|
26
|
+
|
|
27
|
+
A pane echo, a spinner, an inbox file and a hook's stdout prove none of the middle three. Without `expect_next_action`, whether the next actions follow the correction is a person's judgment, and the state stays at `acknowledged` with `behavior: not_judged`.
|
|
28
|
+
|
|
29
|
+
`acknowledged` can be skipped. A Claude Code transcript does not always hold text written just before a tool call, as on the production baseline in jgwill/Miadi#942, where the model's "received" never reached the file and `behavior_adjusted` still did. Its absence shows nothing either way.
|
|
30
|
+
|
|
31
|
+
## The inbox
|
|
32
|
+
|
|
33
|
+
`<factory>/steering/<session_id>/`, owned by one Unix account, mode 0700.
|
|
34
|
+
|
|
35
|
+
| path | written by | meaning |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| `adapter.json` | adapter, at session start | this session loaded its adapter: `protocol`, `contract`, `provider`, `adapter`, `adapter_version`, `session_id`, `transcript_path`, `pid`, `pane`, `tmux_socket`, `guarantee` |
|
|
38
|
+
| `pending/<order>-<steer>.json` | connector, by one rename after fsync | the envelope: `protocol`, `steer`, `grant`, `session_id`, `provider`, `instruction`, `instruction_sha256`, `from`, `queued_at`, `expires_at`, `decided`, `transcript_path`, `transcript_offset` |
|
|
39
|
+
| `claimed/` | adapter, by one rename | taken for delivery, exactly once, never replayed |
|
|
40
|
+
| `expired/`, `withdrawn/`, `rejected/` | adapter or connector | never shown to the model, each with its receipt |
|
|
41
|
+
| `revoked/<id>` | connector | checked at consumption |
|
|
42
|
+
| `receipts.jsonl` | adapter, runner, connector | what each did, with source and time |
|
|
43
|
+
| `seat.json` | a hook adapter with no registry to read | `idle` or `busy`, for the runner |
|
|
44
|
+
|
|
45
|
+
What this keeps:
|
|
46
|
+
|
|
47
|
+
- **One address.** The runner's receipt names the session and pane. A provider with no registry is found by its pane on this tmux server, because a pane number is unique only within its server, among living adapters of that provider. None is `unsupported`, two is `wrong_pane`, a dead pid is `stale_binding`, another provider, another server or a moved pane is `wrong_pane`.
|
|
48
|
+
- **Nothing lost, nothing twice.** A steer's id keeps it single across a retry or a connector restart. A dropped client changes nothing. A session that dies keeps its pending envelopes until it resumes or they expire. A door that refuses the hand-off (Pi during compaction, a rejected Copilot send) returns the envelope to the inbox, and it is tried again. A claim whose fate is unknown is never replayed.
|
|
49
|
+
- **Whose mission.** A grant covers the person who asked for the run, the person who approved it and the host's service token. Anyone else with the write tier gets `awaiting_approval`, and a person decides that one steer.
|
|
50
|
+
- **Authority.** The grant and its budget are checked at admission. Expiry, revocation, session, protocol and hash are checked again at consumption. The text names who sent it, says it carries no new permissions, and cannot close its own delimiter.
|
|
51
|
+
- **Nothing interrupted.** No Ctrl+C, no raw keys into a working pane, no second agent.
|
|
52
|
+
|
|
53
|
+
## Providers
|
|
54
|
+
|
|
55
|
+
`steering-adapters.ts` holds this table as data, and `get_capabilities.steering` and `provider_capabilities` serve it. A CLI version no real session has passed on reads as `untested_cli_version`.
|
|
56
|
+
|
|
57
|
+
| provider | door while working | door when idle | model reads it as | evidence read | tested on |
|
|
58
|
+
|---|---|---|---|---|---|
|
|
59
|
+
| Claude Code | `PostToolUse`, `PostToolUseFailure` additionalContext, then `Stop` block | `asyncRewake` watcher for 30 s, then the runner's prompt and `UserPromptSubmit` | hook context | transcript attachment | 2.1.319 |
|
|
60
|
+
| Pi | its steering queue, `pi.sendUserMessage(text, { deliverAs: "steer" })` | the same call starts a run | user message | session JSONL | 1.4.0 |
|
|
61
|
+
| GitHub Copilot CLI | `session.send({ mode: "immediate" })`, held until tools in flight finish | the same call starts a turn | user message | `events.jsonl` | 1.0.107 |
|
|
62
|
+
| Codex CLI | `PostToolUse` additionalContext, then `Stop` block | `codex queue --thread` from the runner, then `UserPromptSubmit` | developer message | rollout JSONL | 0.166.0 |
|
|
63
|
+
| Gemini, others | none | none | | | answers `unsupported` |
|
|
64
|
+
|
|
65
|
+
### Limits seen on real sessions
|
|
66
|
+
|
|
67
|
+
- **Every provider:** a running tool finishes first, so a long tool delays the correction by its own length. Adapters load at session start, so a session started before its adapter answers `unsupported` and is never typed into.
|
|
68
|
+
- **Pi:** a person's abort returns queued words to their editor. The adapter then records `left_provider_queue`, delivery reads `unknown`, and nothing sends them again.
|
|
69
|
+
- **Copilot:** extensions load only when `enabledFeatureFlags.EXTENSIONS` is on, which its installer sets. The `--experimental` flag also turns them on, and writes `experimental: true` into `~/.copilot/settings.json` for every later session, so nothing here passes it. A shell command starting just as a correction arrives moves to the background and keeps running, so its line of work may finish after the corrected action. Copilot updates itself, so a newer version reads as untested until a real session passes on it.
|
|
70
|
+
- **Codex:** the correction arrives as developer-role context, because that is what its hook door writes. The text still names the person and claims no new permission. `turn/steer` on Codex's app-server would carry it as a user message, and is not built or tested here. Codex runs no untrusted hook, and its TUI stops at "Hooks need review" at start while any hook on the account is new or modified, which a brief typed into it would answer. `codex/miadi-steering/install.mjs` trusts its own hooks exactly, and `--also-trust-kit-plugin` covers the kit's plugin.
|
|
71
|
+
- **Claude Code:** a session from before its adapter, idle with an empty prompt, is the one case still typed by the connector. Its next state is `unknown` until the transcript shows the prompt. On 2.1.319 an Enter sent straight after the text left it at the prompt, so Enter is pressed again, at most three times.
|
|
72
|
+
|
|
73
|
+
## A new provider
|
|
74
|
+
|
|
75
|
+
1. Find its real door: a native queue, a lifecycle callback or a thread message. A tmux paste is not one.
|
|
76
|
+
2. Copy `steering_inbox.mjs` with `scripts/sync-steering-inbox.sh`, and write the adapter around it.
|
|
77
|
+
3. Add it to `ADAPTERS` and `LINE_READERS`, with fixtures in the shape a real session wrote.
|
|
78
|
+
4. Pass the kit's `tests/steering/conformance.test.mjs`, then `tests/steering/live-probe.mjs` for `busy`, `no_next_tool`, `idle`, `two`, `no_adapter` and `restart`.
|
|
79
|
+
5. Only then add its version to `tested_on`.
|
|
80
|
+
|
|
81
|
+
## Which provider a request runs on
|
|
82
|
+
|
|
83
|
+
A named provider is used, or the request is left unstarted. With none named, a person's own default from `/providers` applies, then one the operator set for them in `factory.json` (`person_default_provider`), then the host's order. A default that is not installed leaves the mission unstarted and is never replaced. Codex is never a default (#926). The answer to `request_authorized_run`, the decision card and `mission_status` say whether a session of that provider could be corrected before anyone depends on it.
|
|
84
|
+
|
|
85
|
+
## Rollback
|
|
86
|
+
|
|
87
|
+
Run the connector version before this one, and restart `miadi-connector`. A steer to a non-Claude session then answers `unsupported` again and nothing else changes. To stop an adapter: `pi/miadi-session-observability/package.json` without `steering-inbox.ts`, `copilot/miadi-steering/install.sh --remove`, `node codex/miadi-steering/install.mjs --remove`. A new session then answers `unsupported`. Envelopes already queued stay on disk, unread.
|
package/dist/approve.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { type MiadiPerson } from "./people.js";
|
|
|
17
17
|
import { type ConnectorRecord } from "./records.js";
|
|
18
18
|
import { type RequestProjection } from "./request-state.js";
|
|
19
19
|
import type { DraftReviewService } from "./draft-review.js";
|
|
20
|
-
import type
|
|
20
|
+
import { type RuntimeDeps } from "./runtime-steer.js";
|
|
21
21
|
import { type TmuxLike } from "./steer.js";
|
|
22
22
|
import { type FetchCaptions } from "./captions.js";
|
|
23
23
|
import { type ProviderAuthorization } from "./provider-policy.js";
|
|
@@ -32,6 +32,12 @@ export interface ApprovalDeps {
|
|
|
32
32
|
fetchImpl?: typeof fetch;
|
|
33
33
|
/** The factory directory holding queue/ (default /srv/miadi/factory). */
|
|
34
34
|
factoryDir?: string;
|
|
35
|
+
/** Whether a session of this provider could be corrected once it works: said before a person approves (jgwill/Miadi#942). */
|
|
36
|
+
steeringOf?: (provider: string) => {
|
|
37
|
+
steerable: boolean;
|
|
38
|
+
basis: string;
|
|
39
|
+
reason?: string;
|
|
40
|
+
};
|
|
35
41
|
tmuxSessions?: () => string[];
|
|
36
42
|
/** The steering surface (jgwill/Miadi#893); tests inject a fake, production uses tmux. */
|
|
37
43
|
tmux?: TmuxLike;
|
|
@@ -39,6 +45,8 @@ export interface ApprovalDeps {
|
|
|
39
45
|
steerSettleMs?: number;
|
|
40
46
|
/** Where sessions and their steering inboxes live (jgwill/Miadi#930). Absent, no runtime route is known. */
|
|
41
47
|
steeringRuntime?: RuntimeDeps;
|
|
48
|
+
/** Asks the factory runner for a pass now. Its timer is the net (jgwill/Miadi#942). */
|
|
49
|
+
wakeRunner?: () => void;
|
|
42
50
|
/** Reads a video's captions for an approved create; without it a create stores no transcript (tests, other embedders). */
|
|
43
51
|
captions?: FetchCaptions;
|
|
44
52
|
/** The link a named person decides a consent request on; set where the decision secret is held. */
|
|
@@ -81,6 +89,7 @@ export declare function episodeReferences(record: ConnectorRecord): string[];
|
|
|
81
89
|
/** Whether the owner of this video's source registered it as withheld. */
|
|
82
90
|
export declare function sourceWithheld(records: ConnectorRecord[], videoId: unknown): boolean;
|
|
83
91
|
export declare function executeApproved(record: ConnectorRecord, approver: MiadiPerson, deps: ApprovalDeps, instructions?: string): Promise<Record<string, unknown>>;
|
|
92
|
+
export declare function page(title: string, body: string): string;
|
|
84
93
|
/**
|
|
85
94
|
* Record a person's decision on a request and, when approved, run it once as
|
|
86
95
|
* them. The approval page and the in-chat approval card both decide here; the
|
|
@@ -170,7 +179,11 @@ export declare function rerun(r: ConnectorRecord, person: MiadiPerson, deps: App
|
|
|
170
179
|
}>;
|
|
171
180
|
export declare function isApprovable(r: ConnectorRecord | undefined): r is ConnectorRecord;
|
|
172
181
|
/** What approving a request does, in one sentence, for the card a person decides on. */
|
|
173
|
-
export declare function consequenceOf(r: ConnectorRecord, authorization?: ProviderAuthorization, records?: ConnectorRecord[]
|
|
182
|
+
export declare function consequenceOf(r: ConnectorRecord, authorization?: ProviderAuthorization, records?: ConnectorRecord[], steering?: {
|
|
183
|
+
steerable: boolean;
|
|
184
|
+
basis: string;
|
|
185
|
+
reason?: string;
|
|
186
|
+
}): string;
|
|
174
187
|
export declare function registerApprovalRoutes(app: Express, deps: ApprovalDeps): void;
|
|
175
188
|
/**
|
|
176
189
|
* The page a person named in a consent request decides on. Their link is the door: a person who never
|
|
@@ -193,6 +206,6 @@ export declare function requestProjection(record: ConnectorRecord, opts?: {
|
|
|
193
206
|
factoryDir?: string;
|
|
194
207
|
}): RequestProjection | null;
|
|
195
208
|
/** The person's own provider policy page: read and change it, signed in with their person token (jgwill/Miadi#926). */
|
|
196
|
-
export declare function registerProviderPolicyRoutes(app: Express, deps: Pick<ApprovalDeps, "ledger" | "identify" | "log">): void;
|
|
209
|
+
export declare function registerProviderPolicyRoutes(app: Express, deps: Pick<ApprovalDeps, "ledger" | "identify" | "log" | "factoryDir">): void;
|
|
197
210
|
/** How a request is named to a person. */
|
|
198
211
|
export declare const KIND_LABELS: Record<string, string>;
|
package/dist/approve.js
CHANGED
|
@@ -22,12 +22,14 @@ import { current, newRecordId } from "./records.js";
|
|
|
22
22
|
import { APPROVABLE, projectRequest } from "./request-state.js";
|
|
23
23
|
import { factoryDir, runBriefFile, readQueueState } from "./queue-state.js";
|
|
24
24
|
import { factoryLedgerPath, readFactoryReceipts, receiptsForRecord } from "./factory-receipt.js";
|
|
25
|
+
import { readSteerDelivery } from "./runtime-steer.js";
|
|
26
|
+
import { adapterOfRoute, readFactoryConfig } from "./steering-adapters.js";
|
|
25
27
|
import { steerAttempts, steerSession, tmuxAdapter } from "./steer.js";
|
|
26
28
|
import { contentHash, versionOf } from "./revisions.js";
|
|
27
29
|
import { TRANSCRIPT_RETRY_MS, transcriptStep } from "./captions.js";
|
|
28
30
|
import { ReviewClient } from "./reviews.js";
|
|
29
31
|
import { canReadReading } from "./reading/privacy.js";
|
|
30
|
-
import { authorizationReceipt, authorizeProvider, briefAttributes, CHOICE_TTL_MS, CODEX_POLICIES, isPersonId, needsPersonChoice, providerPolicyOf, } from "./provider-policy.js";
|
|
32
|
+
import { authorizationReceipt, authorizeProvider, briefAttributes, CHOICE_TTL_MS, CODEX_POLICIES, isPersonId, needsPersonChoice, HOST_ORDER, providerPolicyOf, } from "./provider-policy.js";
|
|
31
33
|
export { factoryDir, runBriefFile, readQueueState } from "./queue-state.js";
|
|
32
34
|
/**
|
|
33
35
|
* One line per step of a decision, for the journal: the request, a correlation id,
|
|
@@ -353,7 +355,7 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
353
355
|
return { outcome: "failed", message: "The run whose grant this steer cites is gone." };
|
|
354
356
|
// The pane the factory delivered the mission to, when it recorded one (jgwill/Miadi#909).
|
|
355
357
|
const bound = receiptsForRecord(readFactoryReceipts(factoryLedgerPath(deps.factoryDir ?? factoryDir())), grantRecord.id)[0];
|
|
356
|
-
const result = await steerSession({ tmux: deps.tmux ?? tmuxAdapter(), stateDir: deps.config.stateDir, ...(deps.steeringRuntime ? { runtime: deps.steeringRuntime } : {}), ...(deps.steerSettleMs !== undefined ? { settleMs: deps.steerSettleMs } : {}) }, {
|
|
358
|
+
const result = await steerSession({ tmux: deps.tmux ?? tmuxAdapter(), stateDir: deps.config.stateDir, ...(deps.steeringRuntime ? { runtime: deps.steeringRuntime } : {}), ...(deps.steerSettleMs !== undefined ? { settleMs: deps.steerSettleMs } : {}), ...(deps.wakeRunner ? { wakeRunner: deps.wakeRunner } : {}) }, {
|
|
357
359
|
record,
|
|
358
360
|
grantRecord,
|
|
359
361
|
priorAttempts: steerAttempts(current(deps.ledger.all()), grantRecord.id),
|
|
@@ -367,6 +369,7 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
367
369
|
typed: result.typed,
|
|
368
370
|
...(result.forwarded ? { forwarded: true } : {}),
|
|
369
371
|
...(result.route ? { route: result.route } : {}),
|
|
372
|
+
...(result.runtime_session_id ? { runtime_session_id: result.runtime_session_id } : {}),
|
|
370
373
|
...(result.transcript_offset !== undefined ? { transcript_offset: result.transcript_offset } : {}),
|
|
371
374
|
message: result.message,
|
|
372
375
|
...(result.target ? { target: result.target } : {}),
|
|
@@ -377,12 +380,12 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
377
380
|
return { outcome: "nothing_to_run" };
|
|
378
381
|
}
|
|
379
382
|
}
|
|
380
|
-
function page(title, body) {
|
|
383
|
+
export function page(title, body) {
|
|
381
384
|
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
382
385
|
<title>${escapeHtml(title)}</title>
|
|
383
386
|
<style>
|
|
384
387
|
:root{color-scheme:light dark;--bg:#fbfaf7;--fg:#1d1b18;--muted:#5b5650;--line:#d9d4cc;--accent:#7a4a00;--code:#f1ede6}
|
|
385
|
-
@media (prefers-color-scheme:dark){:root{--bg:#141311;--fg:#ece8e1;--muted:#b3ada4;--line:#3a3631;--accent:#ffd700;--code:#1f1d1a}}
|
|
388
|
+
@media (prefers-color-scheme:dark){:root{--bg:#141311;--fg:#ece8e1;--muted:#b3ada4;--line:#3a3631;--accent:#ffd700;--code:#1f1d1a;--err:#ff7b72}}
|
|
386
389
|
body{margin:0;background:var(--bg);color:var(--fg);font:16px/1.5 system-ui,sans-serif}
|
|
387
390
|
main{max-width:44rem;margin:0 auto;padding:2rem 1rem}
|
|
388
391
|
h1{font-size:1.35rem;margin:0 0 .5rem}
|
|
@@ -418,6 +421,36 @@ summary:focus-visible,.iconbtn:focus-visible{outline:2px solid var(--accent);out
|
|
|
418
421
|
.who{display:flex;gap:.5rem;align-items:center}
|
|
419
422
|
.iconbtn{width:34px;height:34px;flex:none;display:inline-grid;place-items:center;border:1px solid var(--line);border-radius:.4rem;color:var(--fg)}
|
|
420
423
|
.state{display:grid;grid-template-columns:1rem 1fr;gap:.5rem;color:var(--muted);font-size:.9rem}
|
|
424
|
+
.steer-delivery .now{display:grid;grid-template-columns:1rem 1fr;gap:.5rem;align-items:start;margin:.4rem 0}
|
|
425
|
+
.steer-delivery .glyph{color:var(--muted);margin-top:.25rem}
|
|
426
|
+
.steer-delivery.stopped .now .glyph,.steer-delivery li.stopped .glyph{color:var(--err,#b00020)}
|
|
427
|
+
.steer-delivery ol,.steer-delivery .actions{list-style:none;margin:.8rem 0 0;padding:0;display:grid;gap:.5rem}
|
|
428
|
+
.steer-delivery ol>li{display:grid;grid-template-columns:1rem 1fr;gap:.5rem;overflow-wrap:anywhere}
|
|
429
|
+
.steer-delivery li.ahead{color:var(--muted)}
|
|
430
|
+
.steer-delivery .facts{display:block;color:var(--muted);font-size:.85rem;font-family:ui-monospace,monospace}
|
|
431
|
+
.steer-delivery .facts>*{white-space:nowrap}
|
|
432
|
+
.steer-delivery .facts>*+*::before{content:" · "}
|
|
433
|
+
.steer-delivery .said{display:block;margin:.2rem 0;color:var(--muted);font-size:.9rem;overflow-wrap:anywhere}
|
|
434
|
+
.steer-delivery .did{display:block;margin:.2rem 0;padding:.3rem .5rem;background:var(--code);border-radius:.3rem;font-size:.85rem;overflow-wrap:anywhere;font-family:ui-monospace,monospace}
|
|
435
|
+
.steer-delivery h3{font-size:.95rem;margin:1rem 0 0}
|
|
436
|
+
.steer-delivery .outbound{display:flex;align-items:center;gap:.6rem;width:100%;min-height:40px;margin-top:.8rem;padding:3px 10px;border:1px solid var(--line);border-radius:.4rem;background:transparent;color:var(--fg);font:inherit;text-decoration:none;box-sizing:border-box;cursor:pointer}
|
|
437
|
+
.steer-delivery .outbound svg{flex:0 0 auto}
|
|
438
|
+
.steer-delivery .outbound .kind{display:inline-flex;align-items:center;gap:.4rem;color:var(--muted)}
|
|
439
|
+
.steer-delivery .outbound .identity{flex:1;text-align:left;color:var(--accent);font-family:ui-monospace,monospace;overflow:hidden;text-overflow:ellipsis}
|
|
440
|
+
.steer-delivery .again{display:flex;align-items:center;justify-content:space-between;gap:.6rem;margin-top:.8rem}
|
|
441
|
+
.steer-delivery .asked{margin:.4rem 0 .8rem;padding:.4rem .7rem;border-left:2px solid var(--line);overflow-wrap:anywhere}
|
|
442
|
+
details>summary{min-height:34px;padding:.3rem 0;box-sizing:border-box;cursor:pointer}
|
|
443
|
+
.steer-delivery .again button.iconbtn{padding:0}
|
|
444
|
+
.steer-delivery .outbound:hover,.steer-delivery .iconbtn:hover{background:color-mix(in srgb,var(--accent) 12%,transparent)}
|
|
445
|
+
.steer-delivery .outbound:active,.steer-delivery .iconbtn:active{transform:scale(.94)}
|
|
446
|
+
.steer-delivery .outbound:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
|
|
447
|
+
@media (prefers-reduced-motion:reduce){.steer-delivery .outbound:active,.steer-delivery .iconbtn:active{transform:none}}
|
|
448
|
+
.state.stopped{color:var(--fg);font-size:1rem}
|
|
449
|
+
.state.stopped .glyph{color:var(--err,#b00020)}
|
|
450
|
+
fieldset{border:1px solid var(--line);border-radius:.4rem;margin:1rem 0;padding:.5rem .8rem;min-width:0}
|
|
451
|
+
fieldset legend{float:left;width:100%;padding:0;margin-bottom:.3rem;font-size:.95rem}
|
|
452
|
+
fieldset label{clear:both;display:flex;align-items:flex-start;gap:.5rem;min-height:34px;margin:.45rem 0;font-weight:400}
|
|
453
|
+
input[type=radio]{accent-color:var(--accent);flex:0 0 auto;margin:.3rem 0 0}
|
|
421
454
|
.code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
|
|
422
455
|
.glyph{margin-top:.25rem;color:var(--muted)}
|
|
423
456
|
.wordsLabel{margin-bottom:.1rem}
|
|
@@ -796,13 +829,13 @@ export function isApprovable(r) {
|
|
|
796
829
|
return Boolean(r && APPROVABLE.has(r.kind));
|
|
797
830
|
}
|
|
798
831
|
/** What approving a request does, in one sentence, for the card a person decides on. */
|
|
799
|
-
export function consequenceOf(r, authorization, records = []) {
|
|
832
|
+
export function consequenceOf(r, authorization, records = [], steering) {
|
|
800
833
|
const b = r.body;
|
|
801
834
|
switch (r.kind) {
|
|
802
835
|
case "run_request":
|
|
803
836
|
return authorization && !authorization.authorized
|
|
804
837
|
? `Approving is refused until ${r.actor.name} chooses ${authorization.provider} for this mission on its approval page; approving does not choose it. Declining or sending it back stays possible.`
|
|
805
|
-
: `Approving queues a brief for the factory intake, which opens or reaches an agent session within minutes${authorization?.provider ? ` with ${authorization.provider}` : ""}
|
|
838
|
+
: `Approving queues a brief for the factory intake, which opens or reaches an agent session within minutes${authorization?.provider ? ` with ${authorization.provider}` : ""}.${!steering ? "" : !steering.steerable ? ` This session could not be corrected once it works: ${steering.reason ?? "no steering adapter."}` : steering.basis === "tested" ? " A person can correct it while it works." : " A person can correct it while it works, though this version of the agent has not been tested on it."}`;
|
|
806
839
|
case "work_proposal":
|
|
807
840
|
return "Approving starts the work: a brief written from the proposal and your instructions is queued for an agent session.";
|
|
808
841
|
case "review_operation_request":
|
|
@@ -1160,12 +1193,127 @@ function projectionOf(r, deps) {
|
|
|
1160
1193
|
return requestProjection(r, { reviewBase: deps.config.reviewUrl, factoryDir: deps.factoryDir });
|
|
1161
1194
|
}
|
|
1162
1195
|
/** Where a request stands, as a page shows it: the label, each line, the review it produced, and the receipt for audit. */
|
|
1196
|
+
/**
|
|
1197
|
+
* Where a correction stands, for the person who sent it: each state with its glyph, time and whose
|
|
1198
|
+
* record says so, and what is still ahead (jgwill/Miadi#942). The model's words and tool inputs are
|
|
1199
|
+
* operator detail, as mission_status has them, so only the write tier sees them here.
|
|
1200
|
+
*/
|
|
1201
|
+
function deliveryBlock(r, deps, o) {
|
|
1202
|
+
if (r.kind !== "session_steer_request" || !deps.steeringRuntime)
|
|
1203
|
+
return "";
|
|
1204
|
+
const delivery = readSteerDelivery(deps.steeringRuntime, r);
|
|
1205
|
+
if (!delivery)
|
|
1206
|
+
return "";
|
|
1207
|
+
const word = (state) => DELIVERY_WORDS[state] ?? state.replace(/_/g, " ");
|
|
1208
|
+
const isStop = (state) => state === "expired" || state === "blocked" || state === "unsupported";
|
|
1209
|
+
const operator = Boolean(o.token);
|
|
1210
|
+
const waiting = delivery.state === "queued_at_runtime" || delivery.state === "forwarded_to_runtime";
|
|
1211
|
+
const notFollowed = delivery.behavior === "expected_action_not_seen";
|
|
1212
|
+
const factsOf = (at, source) => `<span class="facts">${at ? `<time datetime="${escapeHtml(at)}">${escapeHtml(at.slice(0, 19).replace("T", " "))} UTC</time>` : ""}<span>${escapeHtml(source.replace(/_/g, " "))}</span></span>`;
|
|
1213
|
+
const rows = delivery.receipts
|
|
1214
|
+
// The connector's write and the inbox holding it are one fact to the person reading.
|
|
1215
|
+
.filter((x) => x.state !== "queued_at_runtime")
|
|
1216
|
+
.map((x) => {
|
|
1217
|
+
const warned = x.state === "emit_failed" || x.state === "wake_not_submitted" || x.state === "left_provider_queue";
|
|
1218
|
+
const icon = isStop(x.state) ? glyph("Stopped", CIRCLE_X_PATHS) : warned ? glyph("Did not go through", TRIANGLE_ALERT_PATHS) : glyph("Reached", CIRCLE_CHECK_PATHS);
|
|
1219
|
+
const said = operator && x.state === "acknowledged" && typeof x.detail?.text === "string" ? `<q class="said">${escapeHtml(x.detail.text.trim().slice(0, 300))}</q>` : "";
|
|
1220
|
+
const action = x.detail?.action;
|
|
1221
|
+
const did = operator && x.state === "behavior_adjusted" && action ? `<code class="did">${escapeHtml(actionWords(action.tool, action.input))}</code>` : "";
|
|
1222
|
+
return `<li class="${isStop(x.state) || warned ? "stopped" : ""}">${icon}<span>${escapeHtml(PAST_WORDS[x.state] ?? word(x.state))}${said}${did}${factsOf(x.at, x.source)}</span></li>`;
|
|
1223
|
+
})
|
|
1224
|
+
.join("");
|
|
1225
|
+
const waitRow = waiting ? `<li>${glyph("Waiting", DASHED_PATHS)}<span>${escapeHtml(word("queued_at_runtime"))}</span></li>` : "";
|
|
1226
|
+
// What has not happened yet, so the list shows the distance left. A stopped or unknown correction has none.
|
|
1227
|
+
const reached = new Set(delivery.receipts.map((x) => x.state));
|
|
1228
|
+
const named = typeof r.body.expect_next_action === "string";
|
|
1229
|
+
const ahead = isStop(delivery.state) || delivery.state === "unknown"
|
|
1230
|
+
? ""
|
|
1231
|
+
: ["delivered_to_agent_context", "acknowledged", ...(named ? ["behavior_adjusted"] : [])]
|
|
1232
|
+
.filter((state) => !reached.has(state) && !(notFollowed && state === "behavior_adjusted"))
|
|
1233
|
+
.map((state) => `<li class="ahead">${glyph("Not yet", CIRCLE_PATHS)}<span>${escapeHtml(word(state))}</span></li>`)
|
|
1234
|
+
.join("");
|
|
1235
|
+
const nextActions = operator && delivery.state !== "behavior_adjusted" && delivery.next_actions?.length
|
|
1236
|
+
? `<h3>What it did next</h3><ol>${delivery.next_actions
|
|
1237
|
+
.map((a) => `<li>${glyph("Action", TERMINAL_PATHS)}<span><code class="did">${escapeHtml(actionWords(a.tool, a.input))}</code>${factsOf(a.at, adapterOfRoute(delivery.route)?.evidence ?? "")}</span></li>`)
|
|
1238
|
+
.join("")}</ol>`
|
|
1239
|
+
: "";
|
|
1240
|
+
const stopped = isStop(delivery.state);
|
|
1241
|
+
const now = stopped
|
|
1242
|
+
? glyph("Stopped", CIRCLE_X_PATHS)
|
|
1243
|
+
: delivery.overdue
|
|
1244
|
+
? glyph("Waiting longer than it should", TRIANGLE_ALERT_PATHS)
|
|
1245
|
+
: notFollowed
|
|
1246
|
+
? glyph("Not followed yet", TRIANGLE_ALERT_PATHS)
|
|
1247
|
+
: delivery.state === "unknown"
|
|
1248
|
+
? glyph("Cannot be told", DASHED_PATHS)
|
|
1249
|
+
: waiting
|
|
1250
|
+
? glyph("Waiting", DASHED_PATHS)
|
|
1251
|
+
: glyph("Reached", CIRCLE_CHECK_PATHS);
|
|
1252
|
+
const headline = notFollowed ? "The model has it, and no later action holds what this correction named" : delivery.overdue ? "Still waiting, longer than it should" : word(delivery.state);
|
|
1253
|
+
const asked = String(r.body.instruction ?? "");
|
|
1254
|
+
const run = r.refs.find((x) => x.startsWith("run_request:") || x.startsWith("work_proposal:"));
|
|
1255
|
+
const token = o.token ?? o.chooserToken;
|
|
1256
|
+
const hidden = token ? `<input type="hidden" name="person_token" value="${escapeHtml(token)}">` : "";
|
|
1257
|
+
const readAt = new Date().toISOString();
|
|
1258
|
+
const again = token
|
|
1259
|
+
? `<form method="post" class="again">${hidden}<span class="facts"><span>read <time datetime="${readAt}">${readAt.slice(0, 19).replace("T", " ")} UTC</time></span></span><button class="iconbtn" type="submit" title="Read it again" aria-label="Read it again">${REFRESH_ICON}</button></form>`
|
|
1260
|
+
: "";
|
|
1261
|
+
// Signed in, the way there stays signed in: the same form as this page.
|
|
1262
|
+
const runLabel = run ? `<span class="kind">${TARGET_ICON}mission</span><span class="identity" title="${escapeHtml(run)}">${escapeHtml(run.replace(/^[a-z_]+:/, "").slice(0, 8))}</span>${ARROW_UP_RIGHT_ICON}` : "";
|
|
1263
|
+
const toRun = !run ? "" : token ? `<form method="post" action="/approve/${encodeURIComponent(run)}">${hidden}<button class="outbound" type="submit" aria-label="Open the mission this correction belongs to">${runLabel}</button></form>` : `<a class="outbound" href="/approve/${encodeURIComponent(run)}" aria-label="Open the mission this correction belongs to">${runLabel}</a>`;
|
|
1264
|
+
return `<section class="standard steer-delivery${stopped || notFollowed || delivery.overdue ? " stopped" : ""}" aria-label="Where this correction stands"><h2>Where this correction stands</h2><blockquote class="asked">${escapeHtml(asked.length > 280 ? `${asked.slice(0, 280)}…` : asked)}</blockquote><p class="now">${now}<strong>${escapeHtml(headline)}</strong></p><p class="muted">${escapeHtml(delivery.note)}</p><ol>${rows}${waitRow}${ahead}</ol>${nextActions}${toRun}${again}</section>`;
|
|
1265
|
+
}
|
|
1266
|
+
/** A tool call in the words a person reads: its command when it has one, else its input as recorded. */
|
|
1267
|
+
function actionWords(tool, input) {
|
|
1268
|
+
try {
|
|
1269
|
+
const command = JSON.parse(input ?? "").command;
|
|
1270
|
+
if (typeof command === "string")
|
|
1271
|
+
return command;
|
|
1272
|
+
}
|
|
1273
|
+
catch {
|
|
1274
|
+
// The input was cut to its first 200 characters, or was not JSON: shown as recorded.
|
|
1275
|
+
}
|
|
1276
|
+
return `${tool ?? ""} ${input ?? ""}`.trim();
|
|
1277
|
+
}
|
|
1278
|
+
/** The words for a step already passed, where they differ from the state's own. */
|
|
1279
|
+
const PAST_WORDS = {
|
|
1280
|
+
queued_at_runtime: "In the session's inbox",
|
|
1281
|
+
};
|
|
1282
|
+
const DELIVERY_WORDS = {
|
|
1283
|
+
authorized: "Authorized",
|
|
1284
|
+
forwarded_to_runtime: "Handed to the session's inbox",
|
|
1285
|
+
queued_at_runtime: "Waiting for the agent's next step",
|
|
1286
|
+
runtime_hook_emitted: "The agent's runtime took it",
|
|
1287
|
+
in_model_request: "Held in the request going to the model",
|
|
1288
|
+
delivered_to_agent_context: "The model has it",
|
|
1289
|
+
acknowledged: "The model says it received it",
|
|
1290
|
+
behavior_adjusted: "A later action holds what this correction named",
|
|
1291
|
+
emit_failed: "The agent refused it for now, and it goes back in the inbox",
|
|
1292
|
+
wake_not_submitted: "A line to wake the seat did not go in, and the next pass tries again",
|
|
1293
|
+
left_provider_queue: "The agent's run ended before the model read it",
|
|
1294
|
+
seat_was_idle: "The seat was idle",
|
|
1295
|
+
seat_woken: "The factory runner woke the seat",
|
|
1296
|
+
unsupported: "This session cannot be corrected",
|
|
1297
|
+
expired: "Expired before the model read it",
|
|
1298
|
+
blocked: "Stopped before the model read it",
|
|
1299
|
+
unknown: "Whether the model read it cannot be told",
|
|
1300
|
+
};
|
|
1301
|
+
/** Whether this run could be corrected once it works, as a state with its glyph, before and after it is decided (jgwill/Miadi#942). */
|
|
1302
|
+
function runSteeringLine(r, provider, deps) {
|
|
1303
|
+
if (r.kind !== "run_request" || !provider || !deps.steeringOf)
|
|
1304
|
+
return "";
|
|
1305
|
+
const s = deps.steeringOf(provider);
|
|
1306
|
+
if (!s.steerable)
|
|
1307
|
+
return `<p class="state stopped">${glyph("Cannot be corrected", CIRCLE_X_PATHS)}<span>A person could not correct this run while it works. ${escapeHtml(s.reason ?? "")}</span></p>`;
|
|
1308
|
+
return stateLine("Can be corrected", CIRCLE_CHECK_PATHS, s.basis === "tested" ? "A person can correct this run while it works." : "A person can correct this run while it works, though no real session of this version of the agent has been tested.");
|
|
1309
|
+
}
|
|
1310
|
+
const receiptBlock = (receipt) => (receipt ? `<details><summary>Receipt</summary><pre>${escapeHtml(JSON.stringify(receipt, null, 2))}</pre></details>` : "");
|
|
1163
1311
|
function projectionBlock(p, receipt) {
|
|
1164
1312
|
if (!p)
|
|
1165
1313
|
return "";
|
|
1166
1314
|
const lines = p.lines.map((l) => `<li>${escapeHtml(l)}</li>`).join("");
|
|
1167
1315
|
const review = p.receipt_url ? `<p><a href="${escapeHtml(p.receipt_url)}" rel="noopener">${escapeHtml(p.receipt_url)}</a></p>` : "";
|
|
1168
|
-
const audit =
|
|
1316
|
+
const audit = receiptBlock(receipt);
|
|
1169
1317
|
return `<section aria-label="Where it stands"><p><strong>${escapeHtml(p.label)}</strong></p>${lines ? `<ul>${lines}</ul>` : ""}${review}${audit}</section>`;
|
|
1170
1318
|
}
|
|
1171
1319
|
const SETTLER_WORDS = {
|
|
@@ -1174,6 +1322,15 @@ const SETTLER_WORDS = {
|
|
|
1174
1322
|
bystander: "Only the person deciding can answer this, in their instructions.",
|
|
1175
1323
|
local_agent: "A local agent can settle this from the running system.",
|
|
1176
1324
|
};
|
|
1325
|
+
const TRIANGLE_ALERT_PATHS = `<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/>`;
|
|
1326
|
+
const svgIcon = (paths) => `<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">${paths}</svg>`;
|
|
1327
|
+
const REFRESH_ICON = svgIcon(`<path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M8 16H3v5"/>`);
|
|
1328
|
+
const ARROW_UP_RIGHT_ICON = svgIcon(`<path d="M7 7h10v10"/><path d="M7 17 17 7"/>`);
|
|
1329
|
+
const TARGET_ICON = svgIcon(`<circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/>`);
|
|
1330
|
+
const CIRCLE_PATHS = `<circle cx="12" cy="12" r="10"/>`;
|
|
1331
|
+
const TERMINAL_PATHS = `<path d="M12 19h8"/><path d="m4 17 6-6-6-6"/>`;
|
|
1332
|
+
const CIRCLE_CHECK_PATHS = `<circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/>`;
|
|
1333
|
+
const CIRCLE_X_PATHS = `<circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/>`;
|
|
1177
1334
|
const DASHED_PATHS = `<path d="M10.1 2.182a10 10 0 0 1 3.8 0"/><path d="M13.9 21.818a10 10 0 0 1-3.8 0"/><path d="M17.609 3.721a10 10 0 0 1 2.69 2.7"/><path d="M2.182 13.9a10 10 0 0 1 0-3.8"/><path d="M20.279 17.609a10 10 0 0 1-2.7 2.69"/><path d="M21.818 10.1a10 10 0 0 1 0 3.8"/><path d="M3.721 6.391a10 10 0 0 1 2.7-2.69"/><path d="M6.391 20.279a10 10 0 0 1-2.69-2.7"/>`;
|
|
1178
1335
|
const EYE_PATHS = `<path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/>`;
|
|
1179
1336
|
const glyph = (label, paths) => `<svg class="glyph" role="img" aria-label="${label}" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">${paths}</svg>`;
|
|
@@ -1233,10 +1390,16 @@ function approvePage(deps, r, o = {}) {
|
|
|
1233
1390
|
// Signed in and able to decide: the decision comes before the record's details, and no line says it waits for someone else.
|
|
1234
1391
|
const asksSomeone = r.kind === "participant_consent_request";
|
|
1235
1392
|
const canDecideHere = Boolean(actionable && o.token && !asksSomeone);
|
|
1236
|
-
|
|
1393
|
+
// A correction's own evidence speaks for it, in its own section: the ledger's word may lag it until the next read settles it.
|
|
1394
|
+
const steerDecided = !open && r.kind === "session_steer_request" && Boolean(deps.steeringRuntime && readSteerDelivery(deps.steeringRuntime, r));
|
|
1395
|
+
const heading = canDecideHere ? "Not approved yet: decide here" : open ? "A request awaiting a decision" : steerDecided ? "A correction to a running agent" : (projectionOf(r, deps)?.label ?? "A decided request");
|
|
1237
1396
|
const details = canDecideHere
|
|
1238
1397
|
? `<details><summary>What exactly is asked</summary>${summary(r, { intention: false })}</details>`
|
|
1239
|
-
:
|
|
1398
|
+
: steerDecided
|
|
1399
|
+
? `${deliveryBlock(r, deps, o)}
|
|
1400
|
+
<details><summary>What exactly was sent</summary>${summary(r)}</details>
|
|
1401
|
+
${receiptBlock(r.completion_receipt)}`
|
|
1402
|
+
: `${summary(r)}
|
|
1240
1403
|
${open ? draftReviewSection(r, deps.draftReview?.stored(r), false) : ""}
|
|
1241
1404
|
${projectionBlock(projectionOf(r, deps), open ? undefined : r.completion_receipt)}`;
|
|
1242
1405
|
return page("Approve a Miadi request", `<h1>${escapeHtml(heading)}</h1>
|
|
@@ -1244,6 +1407,7 @@ ${canDecideHere ? `<p>You are signed in. Nothing is approved until you press a b
|
|
|
1244
1407
|
${asksSomeone && open && o.token && deps.consentLink ? consentMailSection(r, deps) : ""}
|
|
1245
1408
|
${asksSomeone && open && (o.token || o.chooserToken) && deps.consentLink ? `<p><strong>The link to send ${escapeHtml(String(r.body.decider_name))}:</strong><br><a href="${escapeHtml(deps.consentLink(r.id))}" rel="noreferrer">${escapeHtml(deps.consentLink(r.id))}</a></p>` : ""}
|
|
1246
1409
|
${actionable ? `<p>${escapeHtml(consequenceOf(r, authorization, current(deps.ledger.all())))} Declining records your refusal. Either is kept in the ledger with your name.</p>` : ""}
|
|
1410
|
+
${runSteeringLine(r, authorization?.provider ?? undefined, deps)}
|
|
1247
1411
|
${canDecideHere && r.intention ? `<p><strong>Intention:</strong> ${escapeHtml(r.intention)}</p>` : ""}
|
|
1248
1412
|
${authorization ? providerSection(r, authorization, actionable ? o.chooserToken : undefined) : ""}
|
|
1249
1413
|
${canDecideHere ? draftReviewSection(r, deps.draftReview?.stored(r), !blocked) : ""}
|
|
@@ -1309,6 +1473,7 @@ export function registerProviderPolicyRoutes(app, deps) {
|
|
|
1309
1473
|
${error ? `<p class="err" role="alert">${escapeHtml(error)}</p>` : ""}
|
|
1310
1474
|
<form method="post"><label for="t">Your Miadi person token</label><input id="t" name="person_token" type="password" autocomplete="off" required>
|
|
1311
1475
|
<div class="row"><button class="primary" type="submit">Read my policy</button></div></form>`);
|
|
1476
|
+
const policyOfPerson = (personId) => providerPolicyOf(deps.ledger.all(), personId, readFactoryConfig(deps.factoryDir ?? factoryDir())?.person_default_provider);
|
|
1312
1477
|
app.get("/providers", (_req, res) => void res.type("html").send(signIn()));
|
|
1313
1478
|
app.post("/providers", form, async (req, res) => {
|
|
1314
1479
|
const body = (req.body ?? {});
|
|
@@ -1330,7 +1495,13 @@ ${error ? `<p class="err" role="alert">${escapeHtml(error)}</p>` : ""}
|
|
|
1330
1495
|
if (body.codex !== undefined) {
|
|
1331
1496
|
if (!CODEX_POLICIES.includes(body.codex))
|
|
1332
1497
|
return void res.status(400).type("html").send(signIn("Unknown Codex policy."));
|
|
1333
|
-
if (
|
|
1498
|
+
if (body.default_provider && !["claude", "pi", "copilot", HOST_ORDER].includes(body.default_provider))
|
|
1499
|
+
return void res.status(400).type("html").send(signIn("Unknown default provider."));
|
|
1500
|
+
const before = policyOfPerson(person.id);
|
|
1501
|
+
const wanted = body.default_provider ?? "";
|
|
1502
|
+
const had = before.default_provider ?? HOST_ORDER;
|
|
1503
|
+
const changed = before.codex !== body.codex || Boolean(wanted && had !== wanted);
|
|
1504
|
+
if (changed) {
|
|
1334
1505
|
deps.ledger.append({
|
|
1335
1506
|
id: newRecordId("provider_policy"),
|
|
1336
1507
|
kind: "provider_policy",
|
|
@@ -1339,22 +1510,31 @@ ${error ? `<p class="err" role="alert">${escapeHtml(error)}</p>` : ""}
|
|
|
1339
1510
|
refs: [],
|
|
1340
1511
|
evidence_refs: [],
|
|
1341
1512
|
claim_category: "observed",
|
|
1342
|
-
body: { codex: body.codex },
|
|
1513
|
+
body: { codex: body.codex, ...(wanted ? { default_provider: wanted } : {}) },
|
|
1343
1514
|
});
|
|
1344
|
-
logDecision(deps, { phase: "provider_policy_set", person: person.id, codex: body.codex });
|
|
1515
|
+
logDecision(deps, { phase: "provider_policy_set", person: person.id, codex: body.codex, ...(wanted ? { default_provider: wanted } : {}) });
|
|
1345
1516
|
}
|
|
1346
|
-
saved = "<p>Saved. It applies to your requests from now on, including a failed run of yours that is run again. A per-mission choice you already made still covers its mission.</p>";
|
|
1517
|
+
saved = changed ? "<p>Saved. It applies to your requests from now on, including a failed run of yours that is run again. A per-mission choice you already made still covers its mission.</p>" : "<p>Nothing changed: this is already your policy.</p>";
|
|
1347
1518
|
}
|
|
1348
|
-
const policy =
|
|
1519
|
+
const policy = policyOfPerson(person.id);
|
|
1349
1520
|
const option = (value, label) => `<label><input type="radio" name="codex" value="${value}"${policy.codex === value ? " checked" : ""}> ${escapeHtml(label)}</label>`;
|
|
1521
|
+
const providerWord = (id) => (id === "claude" ? "Claude Code" : id === "copilot" ? "Copilot" : id === "pi" ? "Pi" : String(id ?? ""));
|
|
1522
|
+
const defaultOption = (value, label) => `<label><input type="radio" name="default_provider" value="${value}"${(policy.default_provider ?? HOST_ORDER) === value ? " checked" : ""}> ${escapeHtml(label)}</label>`;
|
|
1350
1523
|
res.type("html").send(page("Your provider policy", `<h1>${escapeHtml(person.name)}'s provider policy</h1>${saved}
|
|
1351
1524
|
<dl><dt>Codex</dt><dd>${escapeHtml(policy.codex.replace(/_/g, " "))}${policy.source === "default" ? " (the default)" : `, set ${escapeHtml(policy.set_at ?? "")}`}</dd>
|
|
1352
|
-
<dt>Other providers</dt><dd>Pi, Copilot and Claude Code run when a request names them and they are installed
|
|
1525
|
+
<dt>Other providers</dt><dd>Pi, Copilot and Claude Code run when a request names them and they are installed.</dd></dl>
|
|
1353
1526
|
<form method="post"><input type="hidden" name="person_token" value="${escapeHtml(token)}">
|
|
1354
1527
|
<fieldset><legend>When a request in my name names Codex</legend>
|
|
1355
1528
|
${option("per_mission_choice", "Codex runs only when I choose it for that mission on its approval page (default).")}
|
|
1356
1529
|
${option("selectable", "Codex may be named for my requests without a per-mission choice.")}
|
|
1357
1530
|
</fieldset>
|
|
1531
|
+
<fieldset class="provider-defaults"><legend>When a request in my name names no provider</legend>
|
|
1532
|
+
${defaultOption(HOST_ORDER, "The host's order, which starts with Pi")}
|
|
1533
|
+
${defaultOption("pi", "Pi")}
|
|
1534
|
+
${defaultOption("copilot", "Copilot")}
|
|
1535
|
+
${defaultOption("claude", "Claude Code")}
|
|
1536
|
+
${policy.default_provider_source === "host_config" ? `<p class="muted">The operator set ${escapeHtml(providerWord(policy.default_provider))} for you. Choosing another here replaces that.</p>` : ""}
|
|
1537
|
+
</fieldset>
|
|
1358
1538
|
<div class="row"><button class="primary" type="submit">Save my policy</button></div></form>`));
|
|
1359
1539
|
});
|
|
1360
1540
|
}
|
package/dist/bin.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
2
3
|
import { configFromEnv } from "./config.js";
|
|
3
4
|
import { createConnectorApp } from "./server.js";
|
|
4
5
|
import { identifyThroughMiadi } from "./people.js";
|
|
@@ -17,6 +18,10 @@ const { app } = createConnectorApp(config, {
|
|
|
17
18
|
tmuxSessions: () => tmux.listSessions(),
|
|
18
19
|
// Each session's own steering inbox and Claude Code's registry of running sessions (jgwill/Miadi#930).
|
|
19
20
|
steeringRuntime: defaultRuntime(),
|
|
21
|
+
// The factory runner's wake now, for an idle seat a correction just reached. Its timer is the net, so a failure here is nothing (jgwill/Miadi#942).
|
|
22
|
+
wakeRunner: () => {
|
|
23
|
+
execFile(process.env.MIADI_FACTORY_RUNNER_BIN ?? "miadi-factory-runner", ["wake"], { timeout: 60_000 }, () => { });
|
|
24
|
+
},
|
|
20
25
|
// An approved create stores the video's YouTube captions as the review's transcript, with no model call.
|
|
21
26
|
captions: youtubeCaptions,
|
|
22
27
|
});
|
package/dist/mission-status.d.ts
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
import type { ConnectorRecord } from "./records.js";
|
|
23
23
|
import type { RequestProjection } from "./request-state.js";
|
|
24
24
|
import type { SteerDelivery } from "./runtime-steer.js";
|
|
25
|
+
import type { SteeringSupport } from "./steering-adapters.js";
|
|
25
26
|
import type { FactoryReceipt } from "./factory-receipt.js";
|
|
26
27
|
import { type GithubGet, type MissionResult } from "./mission-result.js";
|
|
27
28
|
export interface MissionSession {
|
|
@@ -197,6 +198,8 @@ export interface MissionStatus {
|
|
|
197
198
|
route: string;
|
|
198
199
|
delivery: SteerDelivery;
|
|
199
200
|
}[];
|
|
201
|
+
/** What a session of this mission's provider can promise on this host, and how that is known. */
|
|
202
|
+
support?: SteeringSupport;
|
|
200
203
|
};
|
|
201
204
|
stage_truth?: MissionStageTruth;
|
|
202
205
|
/**
|
|
@@ -228,6 +231,8 @@ export interface MissionStatusDeps {
|
|
|
228
231
|
paneBusy?: (session: string, paneId?: string) => "busy" | "idle" | "unknown";
|
|
229
232
|
/** Where one steer stands, read from the runtime's inbox and the session's transcript (write tier only). */
|
|
230
233
|
steerDeliveryOf?: (steer: ConnectorRecord) => SteerDelivery | null;
|
|
234
|
+
/** The steering support of a provider on this host (write tier only). */
|
|
235
|
+
steeringSupportOf?: (provider: string) => SteeringSupport;
|
|
231
236
|
/** Whether the tmux session still holds the pane id (write tier only); undefined when it cannot be listed. */
|
|
232
237
|
panePresent?: (session: string, paneId: string) => boolean | undefined;
|
|
233
238
|
/** The factory runner's delivery receipts for one record, newest first (write tier only). */
|