@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/tools.js
CHANGED
|
@@ -25,7 +25,8 @@ import { authorizesActions, missionStatus, primaryIssueOf, resolveMissionSubject
|
|
|
25
25
|
import { authorizationReceipt, authorizeProvider, CHOICE_PROVIDERS, isPersonId, needsPersonChoice, providerPolicyOf } from "./provider-policy.js";
|
|
26
26
|
import { candidatesFor, CRITICALITIES, jevAdapter, modelPreflight, PREFLIGHT_CONTRACT, PREFLIGHT_VERSION, TASK_TYPES, } from "./model-preflight.js";
|
|
27
27
|
import { ShelfRefusal, listShelfArtefacts, readShelfArtefact } from "./research-shelf.js";
|
|
28
|
-
import {
|
|
28
|
+
import { DELIVERY_STATES, readSteerDelivery, revokeInInbox, settlementOf } from "./runtime-steer.js";
|
|
29
|
+
import { ADAPTERS, readFactoryConfig, runSteering, STEERING_CONTRACT_ID, steeringSupport } from "./steering-adapters.js";
|
|
29
30
|
import { checkGrant, isBusy, steerAttempts, steeringGrantOf, steeringRevoked, steerSession } from "./steer.js";
|
|
30
31
|
import { factoryLedgerPath, readFactoryReceipts, receiptsForRecord, recordsForSession } from "./factory-receipt.js";
|
|
31
32
|
import { missionResult, redactResult } from "./mission-result.js";
|
|
@@ -175,18 +176,15 @@ export function githubGetter(fetchImpl = fetch, token = process.env.GITHUB_TOKEN
|
|
|
175
176
|
/** A steer being sent now, by its record: a retry arriving during it waits for this answer and sends nothing (jgwill/Miadi#930). */
|
|
176
177
|
const steersInFlight = new Map();
|
|
177
178
|
export const STEERING_CONTRACT = {
|
|
179
|
+
contract: STEERING_CONTRACT_ID,
|
|
178
180
|
busy_is_normal: true,
|
|
179
181
|
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.",
|
|
180
|
-
runtime: "The agent's own lifecycle presents it to its model at the next supported continuation
|
|
182
|
+
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.",
|
|
181
183
|
delivery_states: DELIVERY_STATES,
|
|
182
184
|
provider_adapters: {
|
|
183
|
-
|
|
184
|
-
codex: { route: "unsupported" },
|
|
185
|
-
copilot: { route: "unsupported" },
|
|
186
|
-
pi: { route: "unsupported" },
|
|
185
|
+
...Object.fromEntries(Object.values(ADAPTERS).map((a) => [a.provider, { route: a.route, level: "same_turn", continuation: a.continuation, idle: a.idle, needs: a.needs, tested_on: a.tested_on, limits: a.limits }])),
|
|
187
186
|
gemini: { route: "unsupported" },
|
|
188
187
|
},
|
|
189
|
-
idle_seat: "An idle seat has no continuation coming, so its steer is typed into its bound pane once the prompt reads empty.",
|
|
190
188
|
};
|
|
191
189
|
export function steeringTransport(tmux) {
|
|
192
190
|
if (!tmux)
|
|
@@ -353,6 +351,16 @@ export function registerTools(server, ctx) {
|
|
|
353
351
|
const touching = (ref) => records().filter((r) => r.refs.includes(ref) || r.evidence_refs.includes(ref) || r.id === ref);
|
|
354
352
|
/** The factory runner's delivery receipts, read fresh: operator data, for the write tier only. */
|
|
355
353
|
const receipts = () => readFactoryReceipts(factoryLedgerPath(ctx.factoryDir ?? defaultFactoryDir()));
|
|
354
|
+
const factoryConfig = () => readFactoryConfig(ctx.factoryDir ?? defaultFactoryDir());
|
|
355
|
+
/** A person's policy with what the operator's factory.json says for them. */
|
|
356
|
+
const policyOf = (personId) => providerPolicyOf(ledger.all(), personId, factoryConfig()?.person_default_provider);
|
|
357
|
+
/** What a new session of this provider on this host can promise, before anyone depends on it. */
|
|
358
|
+
const steeringOf = (providerId, cliVersion) => steeringSupport(providerId, cliVersion, { factory: factoryConfig(), ...ctx.steeringProbe });
|
|
359
|
+
const steeringOfCard = runSteering(() => discoverProviders(ctx.providersProbe), () => ({ factory: factoryConfig(), ...ctx.steeringProbe }));
|
|
360
|
+
const runProvider = (r) => {
|
|
361
|
+
const b = r.body;
|
|
362
|
+
return r.kind === "run_request" && typeof (b.resolved_provider ?? b.provider) === "string" ? String(b.resolved_provider ?? b.provider) : undefined;
|
|
363
|
+
};
|
|
356
364
|
const github = githubGetter(ctx.approval?.fetchImpl ?? fetch);
|
|
357
365
|
// ── reads ──────────────────────────────────────────────────────────────
|
|
358
366
|
server.registerTool("get_capabilities", {
|
|
@@ -392,7 +400,13 @@ export function registerTools(server, ctx) {
|
|
|
392
400
|
tools: TOOL_STATUS,
|
|
393
401
|
mission_standard: ctx.draftReview ? await standardStatus(ctx.draftReview) : { state: "unavailable" },
|
|
394
402
|
// Registered is not operational: whether a steer can reach a pane on this host now (jgwill/Miadi#909).
|
|
395
|
-
steering: {
|
|
403
|
+
steering: {
|
|
404
|
+
...steeringTransport(ctx.tmux),
|
|
405
|
+
runtime_route: ctx.steeringRuntime ? "configured" : "not_configured",
|
|
406
|
+
contract: STEERING_CONTRACT,
|
|
407
|
+
// Host truth, as provider_capabilities is: what this host would load into a new session.
|
|
408
|
+
...(person.api_tier !== "write" ? {} : { on_this_host: Object.fromEntries(Object.values(ADAPTERS).map((a) => { const s = steeringOf(a.provider); return [a.provider, { steerable: s.steerable, adapter: s.adapter?.version ?? null, ...(s.reason ? { reason: s.reason } : {}) }]; })) }),
|
|
409
|
+
},
|
|
396
410
|
foundation_read: {
|
|
397
411
|
permission: FOUNDATIONS_PERMISSION,
|
|
398
412
|
held: foundations,
|
|
@@ -846,6 +860,17 @@ export function registerTools(server, ctx) {
|
|
|
846
860
|
queue: r.kind === "run_request" || r.kind === "work_proposal" ? readQueueState(r, ctx.factoryDir) : undefined,
|
|
847
861
|
// Where a steer stands, joined to its id: operator detail, as mission_status has it (jgwill/Miadi#930).
|
|
848
862
|
...(r.kind === "session_steer_request" && ctx.steeringRuntime && person.api_tier === "write" ? { delivery: readSteerDelivery(ctx.steeringRuntime, all().find((x) => x.id === r.id) ?? r) ?? undefined } : {}),
|
|
863
|
+
// A run's corrections, each with where it stands; mission_status has the same with every receipt (jgwill/Miadi#942).
|
|
864
|
+
...((r.kind === "run_request" || r.kind === "work_proposal") && ctx.steeringRuntime && person.api_tier === "write"
|
|
865
|
+
? {
|
|
866
|
+
steers: all()
|
|
867
|
+
.filter((x) => x.kind === "session_steer_request" && x.refs.includes(r.id))
|
|
868
|
+
.flatMap((x) => {
|
|
869
|
+
const delivery = readSteerDelivery(ctx.steeringRuntime, x);
|
|
870
|
+
return delivery ? [{ id: x.id, at: x.created_at, by: x.actor.name, state: delivery.state, ...(delivery.continuation ? { continuation: delivery.continuation } : {}), ...(delivery.behavior ? { behavior: delivery.behavior } : {}), note: delivery.note }] : [];
|
|
871
|
+
}),
|
|
872
|
+
}
|
|
873
|
+
: {}),
|
|
849
874
|
// Where the request stands, in the words every surface uses (jgwill/Miadi#889).
|
|
850
875
|
projection: requestProjection(r, { reviewBase: ctx.approval?.config.reviewUrl, factoryDir: ctx.factoryDir }),
|
|
851
876
|
...(r.kind === "run_request" || r.kind === "work_proposal" ? { draft_review: reviewShownTo(ctx.draftReview?.stored(r), r, person) } : {}),
|
|
@@ -874,6 +899,7 @@ export function registerTools(server, ctx) {
|
|
|
874
899
|
queueOf: (r) => (r.kind === "run_request" || r.kind === "work_proposal" ? readQueueState(r, ctx.factoryDir) : undefined),
|
|
875
900
|
...(writeTier && ctx.steeringRuntime
|
|
876
901
|
? {
|
|
902
|
+
steeringSupportOf: (providerId) => steeringOf(providerId, discoverProviders(ctx.providersProbe).find((p) => p.id === providerId)?.version),
|
|
877
903
|
steerDeliveryOf: (r) => {
|
|
878
904
|
const stored = all().find((x) => x.id === r.id) ?? r;
|
|
879
905
|
return readSteerDelivery(ctx.steeringRuntime, stored);
|
|
@@ -947,9 +973,9 @@ export function registerTools(server, ctx) {
|
|
|
947
973
|
preference_order: PROVIDERS.map((p) => p.id),
|
|
948
974
|
explicit_only: PROVIDERS.filter((p) => !p.selectable_by_default).map((p) => p.id),
|
|
949
975
|
needs_person_choice: [...CHOICE_PROVIDERS],
|
|
950
|
-
your_policy:
|
|
976
|
+
your_policy: policyOf(person.id),
|
|
951
977
|
policy_page: `${config.publicUrl}/providers`,
|
|
952
|
-
providers: discoverProviders(ctx.providersProbe),
|
|
978
|
+
providers: discoverProviders(ctx.providersProbe).map((p) => ({ ...p, steering: steeringOf(p.id, p.version) })),
|
|
953
979
|
router: await routerPreflight(process.env, ctx.approval?.fetchImpl ?? fetch),
|
|
954
980
|
note: "A provider name in a task's text selects nothing; request_authorized_run's provider field is verified against this list, and an unavailable provider leaves the mission unstarted. A request may name Codex, but it runs only when its requester chooses Codex for that mission on the approval page, or their own policy on the providers page says so; a generic approval, the assistant's provider field, the host's order or Jev never choose it.",
|
|
955
981
|
};
|
|
@@ -1489,7 +1515,7 @@ export function registerTools(server, ctx) {
|
|
|
1489
1515
|
const existing = all().find(r => r.kind === "run_request" && r.actor.person_id === person.id && r.body.workflow_id === id);
|
|
1490
1516
|
if (existing)
|
|
1491
1517
|
return { ...redact(existing), workflow_id: id, approval_url: approvalUrl(existing.id), replayed: true, note: "This video's bounded request already exists; read or resume it. The new scope was not substituted." };
|
|
1492
|
-
const resolution = resolveProvider(undefined, discoverProviders(ctx.providersProbe));
|
|
1518
|
+
const resolution = resolveProvider(undefined, discoverProviders(ctx.providersProbe), policyOf(person.id).default_provider);
|
|
1493
1519
|
if (resolution.state !== "ok")
|
|
1494
1520
|
return { state: resolution.state, note: "No runtime provider was verified; nothing was queued." };
|
|
1495
1521
|
const r = append("run_request", person, auth, {
|
|
@@ -1546,7 +1572,8 @@ export function registerTools(server, ctx) {
|
|
|
1546
1572
|
const { person, auth } = who(extra);
|
|
1547
1573
|
requireContribute(auth);
|
|
1548
1574
|
const found = discoverProviders(ctx.providersProbe);
|
|
1549
|
-
const
|
|
1575
|
+
const policy = policyOf(person.id);
|
|
1576
|
+
const resolution = resolveProvider(a.provider, found, policy.default_provider);
|
|
1550
1577
|
if (resolution.state === "provider_unknown")
|
|
1551
1578
|
throw new ToolRefusal("invalid_request", resolution.message, { available: resolution.available });
|
|
1552
1579
|
if (resolution.state !== "ok") {
|
|
@@ -1580,8 +1607,11 @@ export function registerTools(server, ctx) {
|
|
|
1580
1607
|
requested: a.provider ?? null,
|
|
1581
1608
|
resolved: resolution.provider.id,
|
|
1582
1609
|
explicit: resolution.explicit,
|
|
1610
|
+
...(!a.provider && policy.default_provider ? { default_source: policy.default_provider_source } : {}),
|
|
1583
1611
|
version: resolution.provider.version,
|
|
1584
1612
|
authorization: authorizationOut(authorization),
|
|
1613
|
+
// Known before anyone depends on it: whether a person can steer this run once it works (jgwill/Miadi#942).
|
|
1614
|
+
steering: steeringOf(resolution.provider.id, resolution.provider.version),
|
|
1585
1615
|
},
|
|
1586
1616
|
approval_url: approvalUrl(r.id),
|
|
1587
1617
|
...(authorization.authorized
|
|
@@ -1661,7 +1691,7 @@ export function registerTools(server, ctx) {
|
|
|
1661
1691
|
return { state: resolution.state, message: resolution.message, available: resolution.available, note: "Nothing was recorded; the request stays at its version." };
|
|
1662
1692
|
body.provider = c.provider;
|
|
1663
1693
|
body.resolved_provider = resolution.provider.id;
|
|
1664
|
-
provider = { requested: c.provider, resolved: resolution.provider.id, explicit: resolution.explicit, version: resolution.provider.version };
|
|
1694
|
+
provider = { requested: c.provider, resolved: resolution.provider.id, explicit: resolution.explicit, version: resolution.provider.version, steering: steeringOf(resolution.provider.id, resolution.provider.version) };
|
|
1665
1695
|
}
|
|
1666
1696
|
}
|
|
1667
1697
|
else if (live?.kind === "work_proposal") {
|
|
@@ -1823,7 +1853,11 @@ export function registerTools(server, ctx) {
|
|
|
1823
1853
|
}
|
|
1824
1854
|
}
|
|
1825
1855
|
const revoked = steeringRevoked(all(), grantRecord.id);
|
|
1826
|
-
|
|
1856
|
+
// A grant covers the person who asked for the run and the one who approved it, and the host's own service token.
|
|
1857
|
+
// Anyone else with the write tier asks: a person decides that one steer (jgwill/Miadi#942).
|
|
1858
|
+
const approver = (grantRecord.completion_receipt ?? {}).decided_by?.person_id;
|
|
1859
|
+
const theirs = person.id === grantRecord.actor.person_id || person.id === approver || !isPersonId(person.id);
|
|
1860
|
+
const covered = theirs && checkGrant(grant, priorAttempts, new Date(), revoked) === "ok";
|
|
1827
1861
|
// The pane the factory delivered this mission to: the steer goes there and nowhere else (jgwill/Miadi#909).
|
|
1828
1862
|
const bound = receiptsForRecord(receipts(), grantRecord.id)[0];
|
|
1829
1863
|
const binding = bound
|
|
@@ -1852,8 +1886,8 @@ export function registerTools(server, ctx) {
|
|
|
1852
1886
|
...r,
|
|
1853
1887
|
approval_url: approvalUrl(r.id),
|
|
1854
1888
|
state: "awaiting_approval",
|
|
1855
|
-
reason: !grant ? "no_grant" : checkGrant(grant, priorAttempts, new Date(), revoked),
|
|
1856
|
-
message: "The approved run's steering grant does not cover this steer; a person's decision is requested, once, for exactly this instruction.",
|
|
1889
|
+
reason: !grant ? "no_grant" : !theirs ? "another_persons_mission" : checkGrant(grant, priorAttempts, new Date(), revoked),
|
|
1890
|
+
message: !theirs ? "This mission belongs to someone else, so its steering grant does not cover you; a person's decision is requested, once, for exactly this instruction." : "The approved run's steering grant does not cover this steer; a person's decision is requested, once, for exactly this instruction.",
|
|
1857
1891
|
};
|
|
1858
1892
|
}
|
|
1859
1893
|
const r = append("session_steer_request", person, auth, { ...fields, approval_state: "not_required" });
|
|
@@ -1861,7 +1895,7 @@ export function registerTools(server, ctx) {
|
|
|
1861
1895
|
let finishSend = () => { };
|
|
1862
1896
|
steersInFlight.set(r.id, new Promise((resolve) => (finishSend = resolve)));
|
|
1863
1897
|
try {
|
|
1864
|
-
const result = await steerSession({ tmux: ctx.tmux, stateDir: config.stateDir, ...(ctx.steeringRuntime ? { runtime: ctx.steeringRuntime } : {}), ...(ctx.steerSettleMs !== undefined ? { settleMs: ctx.steerSettleMs } : {}) }, { record: r, grantRecord, priorAttempts, ...(binding ? { binding } : {}), ...(sameWords ? { sameInstructionSent: sameWords.id } : {}) });
|
|
1898
|
+
const result = await steerSession({ tmux: ctx.tmux, stateDir: config.stateDir, ...(ctx.steeringRuntime ? { runtime: ctx.steeringRuntime } : {}), ...(ctx.steerSettleMs !== undefined ? { settleMs: ctx.steerSettleMs } : {}), ...(ctx.wakeRunner ? { wakeRunner: ctx.wakeRunner } : {}) }, { record: r, grantRecord, priorAttempts, ...(binding ? { binding } : {}), ...(sameWords ? { sameInstructionSent: sameWords.id } : {}) });
|
|
1865
1899
|
// A typed or forwarded steer is never "failed": failed is re-runnable, and that would send it twice (#922 R8).
|
|
1866
1900
|
const delivered = result.typed || result.forwarded === true;
|
|
1867
1901
|
ledger.append({
|
|
@@ -1884,6 +1918,7 @@ export function registerTools(server, ctx) {
|
|
|
1884
1918
|
typed: result.typed,
|
|
1885
1919
|
...(result.forwarded ? { forwarded: true } : {}),
|
|
1886
1920
|
...(result.route ? { route: result.route } : {}),
|
|
1921
|
+
...(result.runtime_session_id ? { runtime_session_id: result.runtime_session_id } : {}),
|
|
1887
1922
|
...(result.transcript_offset !== undefined ? { transcript_offset: result.transcript_offset } : {}),
|
|
1888
1923
|
message: result.message,
|
|
1889
1924
|
...(result.target ? { target: result.target } : {}),
|
|
@@ -1954,7 +1989,9 @@ export function registerTools(server, ctx) {
|
|
|
1954
1989
|
});
|
|
1955
1990
|
}
|
|
1956
1991
|
}
|
|
1957
|
-
|
|
1992
|
+
// A session the runner could name only by its pane is known from the steers that reached it.
|
|
1993
|
+
const reached = all().filter((x) => x.kind === "session_steer_request" && x.refs.includes(grantRecord.id)).map((x) => x.completion_receipt?.runtime_session_id);
|
|
1994
|
+
const sessions = [...new Set([...receiptsForRecord(receipts(), grantRecord.id).map((x) => x.session_id), ...reached].filter((x) => typeof x === "string" && x.length > 0))];
|
|
1958
1995
|
const inboxes = ctx.steeringRuntime
|
|
1959
1996
|
? sessions.map((session_id) => ({ session_id, ...revokeInInbox(ctx.steeringRuntime, session_id, { grant: grantRecord.id, ...(a.steer ? { steer: a.steer } : {}) }, a.reason) }))
|
|
1960
1997
|
: [];
|
|
@@ -2363,7 +2400,7 @@ export function registerTools(server, ctx) {
|
|
|
2363
2400
|
created_at: r.created_at,
|
|
2364
2401
|
circle: r.circle,
|
|
2365
2402
|
intention: r.intention,
|
|
2366
|
-
consequence: consequenceOf(r, providerAuthorizationOf(r), records()),
|
|
2403
|
+
consequence: consequenceOf(r, providerAuthorizationOf(r), records(), runProvider(r) ? steeringOfCard(runProvider(r)) : undefined),
|
|
2367
2404
|
detail: detailOf(r),
|
|
2368
2405
|
...(r.kind === "run_request" || r.kind === "work_proposal"
|
|
2369
2406
|
? {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.28";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.28";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miadi/connector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"description": "The Miadi connector: one remote MCP service through which a person signed in with their Miadi person token, from ChatGPT or any MCP client, reads sessions, reviews, episodes and circles and records observations, inquiries, handoffs and proposals with their name on each record.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Miadi",
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"types": "./dist/runtime-steer.d.ts",
|
|
25
25
|
"import": "./dist/runtime-steer.js"
|
|
26
26
|
},
|
|
27
|
+
"./steering-adapters": {
|
|
28
|
+
"types": "./dist/steering-adapters.d.ts",
|
|
29
|
+
"import": "./dist/steering-adapters.js"
|
|
30
|
+
},
|
|
27
31
|
"./research-shelf": {
|
|
28
32
|
"types": "./dist/research-shelf.d.ts",
|
|
29
33
|
"import": "./dist/research-shelf.js"
|
|
@@ -35,7 +39,8 @@
|
|
|
35
39
|
},
|
|
36
40
|
"files": [
|
|
37
41
|
"dist",
|
|
38
|
-
"README.md"
|
|
42
|
+
"README.md",
|
|
43
|
+
"STEERING.md"
|
|
39
44
|
],
|
|
40
45
|
"dependencies": {
|
|
41
46
|
"@miadi/inquiry-weave": "0.18.10",
|