@miadi/connector 0.1.20 → 0.1.21

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/dist/tools.js CHANGED
@@ -23,7 +23,9 @@ import { discoverProviders, jevConfigOf, resolveProvider, routerPreflight, PROVI
23
23
  import { authorizesActions, missionStatus, primaryIssueOf, resolveMissionSubject } from "./mission-status.js";
24
24
  import { authorizationReceipt, authorizeProvider, CHOICE_PROVIDERS, isPersonId, needsPersonChoice, providerPolicyOf } from "./provider-policy.js";
25
25
  import { candidatesFor, CRITICALITIES, jevAdapter, modelPreflight, PREFLIGHT_CONTRACT, PREFLIGHT_VERSION, TASK_TYPES, } from "./model-preflight.js";
26
- import { checkGrant, isBusy, steerAttempts, steeringGrantOf, steerSession } from "./steer.js";
26
+ import { ShelfRefusal, listShelfArtefacts, readShelfArtefact } from "./research-shelf.js";
27
+ import { CLAUDE_ADAPTER, DELIVERY_STATES, readSteerDelivery, revokeInInbox, settlementOf } from "./runtime-steer.js";
28
+ import { checkGrant, isBusy, steerAttempts, steeringGrantOf, steeringRevoked, steerSession } from "./steer.js";
27
29
  import { factoryLedgerPath, readFactoryReceipts, receiptsForRecord, recordsForSession } from "./factory-receipt.js";
28
30
  import { missionResult, redactResult } from "./mission-result.js";
29
31
  import { factoryDir as defaultFactoryDir } from "./queue-state.js";
@@ -150,6 +152,27 @@ export function githubGetter(fetchImpl = fetch, token = process.env.GITHUB_TOKEN
150
152
  };
151
153
  }
152
154
  /** Whether the steering transport works now: registered is not operational (jgwill/Miadi#909). */
155
+ /**
156
+ * The provider interface as a client reads it (jgwill/Miadi#930). A correction goes to the session's
157
+ * own runtime, and busy is normal. Only the adapter named here exists. No other provider is assumed
158
+ * to behave like Claude Code.
159
+ */
160
+ /** A steer being sent now, by its record: a retry arriving during it waits for this answer and sends nothing (jgwill/Miadi#930). */
161
+ const steersInFlight = new Map();
162
+ export const STEERING_CONTRACT = {
163
+ busy_is_normal: true,
164
+ 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.",
165
+ runtime: "The agent's own lifecycle presents it to its model at the next supported continuation in the same turn.",
166
+ delivery_states: DELIVERY_STATES,
167
+ provider_adapters: {
168
+ claude: { route: "claude_hook_inbox", continuation: "PostToolUse, PostToolUseFailure, then Stop if no tool follows", needs: `${CLAUDE_ADAPTER}, loaded when the session started` },
169
+ codex: { route: "unsupported" },
170
+ copilot: { route: "unsupported" },
171
+ pi: { route: "unsupported" },
172
+ gemini: { route: "unsupported" },
173
+ },
174
+ idle_seat: "An idle seat has no continuation coming, so its steer is typed into its bound pane once the prompt reads empty.",
175
+ };
153
176
  export function steeringTransport(tmux) {
154
177
  if (!tmux)
155
178
  return { tool: "registered", transport: "unavailable", reason: "The connector host was started without a steering surface." };
@@ -232,8 +255,40 @@ export function registerTools(server, ctx) {
232
255
  ...fields,
233
256
  });
234
257
  };
258
+ /**
259
+ * A forwarded steer's record moves when the runtime's evidence moves: done once the model has it,
260
+ * stopped once it never will. The ledger then agrees with its delivery on every surface that reads it
261
+ * (jgwill/Miadi#930). This only reads the inbox and the transcript, and appends when something changed.
262
+ */
263
+ const settleSteers = () => {
264
+ if (!ctx.steeringRuntime)
265
+ return;
266
+ for (const r of current(ledger.all())) {
267
+ if (r.kind !== "session_steer_request")
268
+ continue;
269
+ const settled = settlementOf(ctx.steeringRuntime, r);
270
+ if (!settled)
271
+ continue;
272
+ ledger.append({
273
+ id: newRecordId(r.kind),
274
+ kind: r.kind,
275
+ created_at: new Date().toISOString(),
276
+ actor: r.actor,
277
+ refs: r.refs,
278
+ evidence_refs: r.evidence_refs,
279
+ supersedes: r.id,
280
+ ...(r.approval_state ? { approval_state: r.approval_state } : {}),
281
+ state: settled.state,
282
+ completion_receipt: { ...r.completion_receipt, outcome: settled.outcome, delivery_state: settled.outcome, settled_at: new Date().toISOString(), ...(settled.at ? { delivered_at: settled.at } : {}), message: settled.message },
283
+ body: r.body,
284
+ });
285
+ }
286
+ };
235
287
  /** Every record, folded; for logic. What a tool returns goes through `shown`. */
236
- const all = () => current(ledger.all());
288
+ const all = () => {
289
+ settleSteers();
290
+ return current(ledger.all());
291
+ };
237
292
  const records = () => {
238
293
  const raw = all();
239
294
  // Completion results can contain exact drafts too. Hide their parent mission as
@@ -317,7 +372,7 @@ export function registerTools(server, ctx) {
317
372
  },
318
373
  tools: TOOL_STATUS,
319
374
  // Registered is not operational: whether a steer can reach a pane on this host now (jgwill/Miadi#909).
320
- steering: steeringTransport(ctx.tmux),
375
+ steering: { ...steeringTransport(ctx.tmux), runtime_route: ctx.steeringRuntime ? "configured" : "not_configured", contract: STEERING_CONTRACT },
321
376
  foundation_read: {
322
377
  permission: FOUNDATIONS_PERMISSION,
323
378
  held: foundations,
@@ -769,6 +824,8 @@ export function registerTools(server, ctx) {
769
824
  ...(versionOf(r) > 1 ? { history: "Earlier versions: get_request_history." } : {}),
770
825
  approval_url: r.approval_state === "awaiting_approval" ? approvalUrl(r.id) : undefined,
771
826
  queue: r.kind === "run_request" || r.kind === "work_proposal" ? readQueueState(r, ctx.factoryDir) : undefined,
827
+ // Where a steer stands, joined to its id: operator detail, as mission_status has it (jgwill/Miadi#930).
828
+ ...(r.kind === "session_steer_request" && ctx.steeringRuntime && person.api_tier === "write" ? { delivery: readSteerDelivery(ctx.steeringRuntime, all().find((x) => x.id === r.id) ?? r) ?? undefined } : {}),
772
829
  // Where the request stands, in the words every surface uses (jgwill/Miadi#889).
773
830
  projection: requestProjection(r, { reviewBase: ctx.approval?.config.reviewUrl, factoryDir: ctx.factoryDir }),
774
831
  ...(r.approval_state === "revision_requested"
@@ -794,6 +851,14 @@ export function registerTools(server, ctx) {
794
851
  return withProviderAuthorization(await missionStatus(ref.trim(), records(), {
795
852
  projectOf: (r) => requestProjection(r, { reviewBase: ctx.approval?.config.reviewUrl, factoryDir: ctx.factoryDir }),
796
853
  queueOf: (r) => (r.kind === "run_request" || r.kind === "work_proposal" ? readQueueState(r, ctx.factoryDir) : undefined),
854
+ ...(writeTier && ctx.steeringRuntime
855
+ ? {
856
+ steerDeliveryOf: (r) => {
857
+ const stored = all().find((x) => x.id === r.id) ?? r;
858
+ return readSteerDelivery(ctx.steeringRuntime, stored);
859
+ },
860
+ }
861
+ : {}),
797
862
  // Without a lister the host cannot say which sessions live: unknown, never "absent" (jgwill/Miadi#909).
798
863
  tmuxSessions: writeTier ? (ctx.tmuxSessions ?? (ctx.tmux?.listSessions ? () => ctx.tmux.listSessions() : undefined)) : undefined,
799
864
  paneBusy: writeTier && ctx.tmux
@@ -1656,10 +1721,11 @@ export function registerTools(server, ctx) {
1656
1721
  }));
1657
1722
  server.registerTool("request_session_steer", {
1658
1723
  title: "Send one authorized follow-up to a running agent",
1659
- description: "Steer one existing live agent session within an approved run's steering grant (jgwill/Miadi#893): the exact instruction is typed into the mission's bound pane — never whichever pane is active — after a peek, and a re-peek verifies the agent accepted it. When the approved run carries no steering grant covering this, the steer waits for one explicit scoped human decision on the returned approval_url. Every attempt leaves a durable artifact with its hash and both captures.",
1724
+ description: "Send one correction to a running agent within an approved run's steering grant (jgwill/Miadi#893, #930). Busy is normal: send it while the agent works, once, and do not watch its tools, wait for idle or retry. The connector hands it to the bound session's own inbox, and the agent's runtime presents it to its model at its next continuation in the same turn. The answer's delivery says which state it reached, each with its source and time: forwarded_to_runtime and queued_at_runtime do not show the model read it; delivered_to_agent_context, acknowledged and behavior_adjusted are read from the session's transcript. A provider with no adapter, or a session started before the adapter, answers unsupported with the reason and uses no attempt. An idle seat has no continuation coming, so its steer is typed into the mission's bound pane, never whichever pane is active. When the run's grant does not cover this, the steer waits for one explicit scoped human decision on the returned approval_url. Read it later with get_run_result on the steer's id or with mission_status.",
1660
1725
  inputSchema: {
1661
1726
  run_request: z.string().min(1).describe("The approved run_request or work_proposal whose steering grant covers this steer."),
1662
- instruction: z.string().min(1).max(4000).describe("The exact instruction typed into the session. It is material within the approved mission's scope, not new authority."),
1727
+ instruction: z.string().min(1).max(4000).describe("The exact instruction for the agent. It is material within the approved mission's scope, not new authority."),
1728
+ expect_next_action: z.string().min(1).max(200).optional().describe("Words to look for in the agent's next tool inputs. When they appear after delivery, the state becomes behavior_adjusted; without this, whether the next actions follow the correction is a person's judgment."),
1663
1729
  session: z.string().regex(/^[A-Za-z0-9._-]{3,80}$/).optional().describe("The session to steer; must be the one the grant binds."),
1664
1730
  pane: z.string().regex(/^\d+\.\d+$/).optional().describe("The pane (window.pane); default the grant's pane, else the session's first pane. The active pane is never used."),
1665
1731
  refs,
@@ -1683,15 +1749,36 @@ export function registerTools(server, ctx) {
1683
1749
  }
1684
1750
  const grant = steeringGrantOf(grantRecord);
1685
1751
  const priorAttempts = steerAttempts(all(), grantRecord.id);
1686
- const covered = checkGrant(grant, priorAttempts) === "ok";
1752
+ const deliveryOf = (rec) => (ctx.steeringRuntime ? readSteerDelivery(ctx.steeringRuntime, rec) ?? undefined : undefined);
1753
+ const wasSent = (rec) => {
1754
+ const receipt = rec.completion_receipt;
1755
+ return receipt?.typed === true || receipt?.forwarded === true;
1756
+ };
1757
+ const attemptsNow = (counted) => ({ used: steerAttempts(all(), grantRecord.id), ...(grant?.max_attempts !== undefined ? { max: grant.max_attempts } : {}), counted });
1758
+ // The same key after a client's retry or a dropped connection gets the first answer, whatever the grant says by now.
1759
+ if (a.idempotency_key) {
1760
+ const sameKey = all().find((x) => x.kind === "session_steer_request" && x.idempotency_key === a.idempotency_key && x.actor.person_id === person.id && x.refs.includes(grantRecord.id));
1761
+ if (sameKey && wasSent(sameKey))
1762
+ return { ...sameKey, delivery: deliveryOf(sameKey), attempts: attemptsNow(false) };
1763
+ if (sameKey && steersInFlight.has(sameKey.id)) {
1764
+ await steersInFlight.get(sameKey.id);
1765
+ const settled = all().find((x) => x.id === sameKey.id) ?? sameKey;
1766
+ return { ...settled, delivery: deliveryOf(settled), attempts: attemptsNow(false) };
1767
+ }
1768
+ }
1769
+ const revoked = steeringRevoked(all(), grantRecord.id);
1770
+ const covered = checkGrant(grant, priorAttempts, new Date(), revoked) === "ok";
1687
1771
  // The pane the factory delivered this mission to: the steer goes there and nowhere else (jgwill/Miadi#909).
1688
1772
  const bound = receiptsForRecord(receipts(), grantRecord.id)[0];
1689
- const binding = bound ? { session: bound.tmux_session, ...(bound.pane_id ? { pane_id: bound.pane_id } : {}) } : undefined;
1773
+ const binding = bound
1774
+ ? { session: bound.tmux_session, ...(bound.pane_id ? { pane_id: bound.pane_id } : {}), ...(bound.session_id ? { session_id: bound.session_id } : {}), ...(bound.provider ? { provider: bound.provider } : {}) }
1775
+ : undefined;
1690
1776
  const body = {
1691
1777
  instruction: a.instruction,
1692
1778
  session: a.session ?? bound?.tmux_session ?? grantRecord.body.session,
1693
1779
  pane: a.pane ?? grant?.pane,
1694
- ...(binding ? { binding: { ...binding, by: "factory_receipt", delivered_at: bound.at, ...(bound.session_id ? { session_id: bound.session_id } : {}) } } : {}),
1780
+ ...(a.expect_next_action ? { expect_next_action: a.expect_next_action } : {}),
1781
+ ...(binding ? { binding: { ...binding, by: "factory_receipt", delivered_at: bound.at } } : {}),
1695
1782
  };
1696
1783
  const fields = {
1697
1784
  circle: grantRecord.circle,
@@ -1709,42 +1796,113 @@ export function registerTools(server, ctx) {
1709
1796
  ...r,
1710
1797
  approval_url: approvalUrl(r.id),
1711
1798
  state: "awaiting_approval",
1712
- reason: !grant ? "no_grant" : checkGrant(grant, priorAttempts),
1799
+ reason: !grant ? "no_grant" : checkGrant(grant, priorAttempts, new Date(), revoked),
1713
1800
  message: "The approved run's steering grant does not cover this steer; a person's decision is requested, once, for exactly this instruction.",
1714
1801
  };
1715
1802
  }
1716
1803
  const r = append("session_steer_request", person, auth, { ...fields, approval_state: "not_required" });
1717
- const result = await steerSession({ tmux: ctx.tmux, stateDir: config.stateDir, ...(ctx.steerSettleMs !== undefined ? { settleMs: ctx.steerSettleMs } : {}) }, { record: r, grantRecord, priorAttempts, ...(binding ? { binding } : {}) });
1718
- // A typed steer is never "failed": failed is re-runnable, and that would type it twice (#922 R8).
1719
- const delivered = result.typed;
1720
- ledger.append({
1721
- id: newRecordId(r.kind),
1722
- kind: r.kind,
1723
- created_at: new Date().toISOString(),
1724
- actor: r.actor,
1725
- refs: r.refs,
1726
- evidence_refs: [],
1727
- supersedes: r.id,
1728
- approval_state: "not_required",
1729
- state: delivered ? "completed" : "blocked",
1730
- completion_receipt: {
1731
- decision: "covered_by_grant",
1732
- decided_by: { person_id: person.id, name: person.name },
1733
- decided_at: new Date().toISOString(),
1734
- outcome: delivered ? result.status : "failed",
1735
- steer_status: result.status,
1736
- typed: result.typed,
1737
- message: result.message,
1738
- ...(result.target ? { target: result.target } : {}),
1739
- ...(result.artifact ? { artifact: result.artifact } : {}),
1740
- },
1741
- body: r.body,
1804
+ const sameWords = all().find((x) => x.kind === "session_steer_request" && x.id !== r.id && x.refs.includes(grantRecord.id) && x.body.instruction === a.instruction && wasSent(x));
1805
+ let finishSend = () => { };
1806
+ steersInFlight.set(r.id, new Promise((resolve) => (finishSend = resolve)));
1807
+ try {
1808
+ 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 } : {}) });
1809
+ // A typed or forwarded steer is never "failed": failed is re-runnable, and that would send it twice (#922 R8).
1810
+ const delivered = result.typed || result.forwarded === true;
1811
+ ledger.append({
1812
+ id: newRecordId(r.kind),
1813
+ kind: r.kind,
1814
+ created_at: new Date().toISOString(),
1815
+ actor: r.actor,
1816
+ refs: r.refs,
1817
+ evidence_refs: [],
1818
+ supersedes: r.id,
1819
+ approval_state: "not_required",
1820
+ // Forwarded is under way: the runtime has not presented it yet, and delivery reads where it stands.
1821
+ state: result.forwarded ? "in_progress" : delivered ? "completed" : "blocked",
1822
+ completion_receipt: {
1823
+ decision: "covered_by_grant",
1824
+ decided_by: { person_id: person.id, name: person.name },
1825
+ decided_at: new Date().toISOString(),
1826
+ outcome: delivered ? result.status : "failed",
1827
+ steer_status: result.status,
1828
+ typed: result.typed,
1829
+ ...(result.forwarded ? { forwarded: true } : {}),
1830
+ ...(result.route ? { route: result.route } : {}),
1831
+ ...(result.transcript_offset !== undefined ? { transcript_offset: result.transcript_offset } : {}),
1832
+ message: result.message,
1833
+ ...(result.target ? { target: result.target } : {}),
1834
+ ...(result.artifact ? { artifact: result.artifact } : {}),
1835
+ },
1836
+ body: r.body,
1837
+ });
1838
+ const stored = all().find((x) => x.id === r.id) ?? r;
1839
+ return {
1840
+ ...(records().find((x) => x.id === r.id) ?? r),
1841
+ delivery: deliveryOf(stored),
1842
+ attempts: attemptsNow(delivered),
1843
+ };
1844
+ }
1845
+ finally {
1846
+ finishSend();
1847
+ steersInFlight.delete(r.id);
1848
+ }
1849
+ }));
1850
+ server.registerTool("revoke_session_steering", {
1851
+ title: "Stop a run's steering, or one steer still waiting",
1852
+ description: "A person stops a correction before its agent reads it (jgwill/Miadi#930). Name the run to stop all further steers under its grant and everything still waiting in its session's inbox, or add steer to stop only that one. The agent's runtime checks again when it would consume it. The answer says exactly what was revoked and what the agent already consumed: a correction already read cannot be taken back.",
1853
+ inputSchema: {
1854
+ run_request: z.string().min(1).describe("The run_request or work_proposal the steering belongs to."),
1855
+ steer: z.string().min(1).optional().describe("One session_steer_request to stop; without it, the run's whole steering grant is revoked."),
1856
+ reason: z.string().min(1).max(1000),
1857
+ refs,
1858
+ ...base,
1859
+ },
1860
+ annotations: WRITE,
1861
+ }, wrap(async (a, extra) => {
1862
+ const { person, auth } = who(extra);
1863
+ requireContribute(auth);
1864
+ requireTier(person, "write");
1865
+ const grantRecord = all().find((r) => r.id === a.run_request);
1866
+ if (!grantRecord || (grantRecord.kind !== "run_request" && grantRecord.kind !== "work_proposal")) {
1867
+ throw new ToolRefusal("invalid_ref", "Give the id of the run_request or work_proposal whose steering this stops.");
1868
+ }
1869
+ if (a.steer) {
1870
+ const steer = all().find((r) => r.id === a.steer);
1871
+ if (!steer || steer.kind !== "session_steer_request" || !steer.refs.includes(grantRecord.id))
1872
+ throw new ToolRefusal("invalid_ref", `${a.steer} is not a steer of ${grantRecord.id}.`);
1873
+ }
1874
+ const r = append("steering_revocation", person, auth, {
1875
+ circle: grantRecord.circle,
1876
+ refs: [grantRecord.id, ...(a.steer ? [a.steer] : []), ...a.refs],
1877
+ intention: a.intention,
1878
+ role: a.role,
1879
+ idempotency_key: a.idempotency_key,
1880
+ body: { reason: a.reason, ...(a.steer ? { steer: a.steer } : {}) },
1742
1881
  });
1743
- const after = steerAttempts(all(), grantRecord.id);
1744
- return {
1745
- ...(records().find((x) => x.id === r.id) ?? r),
1746
- attempts: { used: after, ...(grant?.max_attempts !== undefined ? { max: grant.max_attempts } : {}), counted: result.typed },
1747
- };
1882
+ // A steer still waiting for a person's decision is closed too, so approving it later cannot run it.
1883
+ if (a.steer) {
1884
+ const waiting = all().find((x) => x.id === a.steer);
1885
+ if (waiting?.approval_state === "awaiting_approval") {
1886
+ ledger.append({
1887
+ id: newRecordId(waiting.kind),
1888
+ kind: waiting.kind,
1889
+ created_at: new Date().toISOString(),
1890
+ actor: waiting.actor,
1891
+ refs: waiting.refs,
1892
+ evidence_refs: [],
1893
+ supersedes: waiting.id,
1894
+ approval_state: "declined",
1895
+ state: "withdrawn",
1896
+ completion_receipt: { decision: "revoked", decided_by: { person_id: person.id, name: person.name }, decided_at: new Date().toISOString(), outcome: "revoked", steer_status: "blocked", typed: false, message: a.reason },
1897
+ body: waiting.body,
1898
+ });
1899
+ }
1900
+ }
1901
+ const sessions = [...new Set(receiptsForRecord(receipts(), grantRecord.id).map((x) => x.session_id).filter((x) => Boolean(x)))];
1902
+ const inboxes = ctx.steeringRuntime
1903
+ ? sessions.map((session_id) => ({ session_id, ...revokeInInbox(ctx.steeringRuntime, session_id, { grant: grantRecord.id, ...(a.steer ? { steer: a.steer } : {}) }, a.reason) }))
1904
+ : [];
1905
+ return { ...r, inboxes, note: a.steer ? "This steer was stopped where it had not been consumed." : "No further steer runs under this grant without a person's decision on that exact steer." };
1748
1906
  }));
1749
1907
  server.registerTool("request_review_operation", {
1750
1908
  title: "Request a review operation",
@@ -1917,6 +2075,78 @@ export function registerTools(server, ctx) {
1917
2075
  research_url: `${config.miadiPublicUrl}/research`,
1918
2076
  };
1919
2077
  }));
2078
+ server.registerTool("list_research_artifacts", {
2079
+ title: "List what is on the inquiry shelf",
2080
+ description: "Reports and folders on Miadi's private inquiry shelf, as you may read them: each one's title, opening, words, sections, sources, files, date, owner, visibility, issue, episodes and, for a saved report, its sha256. All of it is computed from the files, never summarised. scope mine lists what you own; scope all, for Miadi's write tier, lists every folder. Search with query, narrow with kind, order with sort, and page with offset and next_offset. Read one with read_research_artifact. Read only: nothing is changed.",
2081
+ inputSchema: {
2082
+ scope: z.enum(["mine", "all"]).default("mine"),
2083
+ query: z.string().max(200).optional().describe("Words to find in a title, an opening, a heading or a folder's name."),
2084
+ kind: z.enum(["report", "folder", "notes"]).optional().describe("report: saved through a door. folder: holds a document. notes: agent instructions or unreadable files only."),
2085
+ sort: z.enum(["newest", "oldest", "longest", "title"]).default("newest"),
2086
+ limit: z.number().int().min(1).max(200).default(50),
2087
+ offset: z.number().int().min(0).default(0).describe("0, or next_offset from the previous page."),
2088
+ },
2089
+ annotations: READ,
2090
+ }, wrap(async (a, extra) => {
2091
+ const { person } = who(extra);
2092
+ if (!config.inquiryRoot)
2093
+ throw new ToolRefusal("unavailable", "This connector host has no inquiry shelf configured.");
2094
+ try {
2095
+ const { scope, query, kind, sort, limit, offset } = a;
2096
+ return await listShelfArtefacts(config.inquiryRoot, person, {
2097
+ ...(scope ? { scope } : {}),
2098
+ ...(query ? { query } : {}),
2099
+ ...(kind ? { kind } : {}),
2100
+ ...(sort ? { sort } : {}),
2101
+ ...(limit !== undefined ? { limit } : {}),
2102
+ ...(offset !== undefined ? { offset } : {}),
2103
+ });
2104
+ }
2105
+ catch (error) {
2106
+ if (error instanceof ShelfRefusal)
2107
+ throw new ToolRefusal(error.code, error.message);
2108
+ throw error;
2109
+ }
2110
+ }));
2111
+ server.registerTool("read_research_artifact", {
2112
+ title: "Read a document on the inquiry shelf",
2113
+ description: "Read back what is on Miadi's private inquiry shelf, as you: a folder's owner, visibility, its issue, its episodes, the commit that holds it, whether anything on disk differs from that commit, and every file with its bytes and sha256. With the folder's report, or the file you name, you also get its text, in pages when long: pass page.next back; joined, the pages hash to sha256. integrity says whether a saved report's bytes are still the bytes saved. Only the folder's owner or a person with Miadi's write tier can read it. Text files only; hidden files and links are never served. Read only: nothing is changed.",
2114
+ inputSchema: {
2115
+ artefact: z.string().min(1).max(300).describe("The shelf folder's name, inquiry-artefact:<name> or the research_artifact record id save_research returned."),
2116
+ file: z.string().min(1).max(500).optional().describe("A path in the folder, as files lists it. Default: its saved report, if it has one."),
2117
+ offset: z.number().int().min(0).optional().describe("0, or page.next.offset from the previous page."),
2118
+ revision: z.string().regex(/^[0-9a-f]{64}$/).optional().describe("page.next.revision from the previous page: refuses with changed if the file moved since."),
2119
+ max_bytes: z.number().int().min(MIN_PAGE_BYTES).max(MAX_TEXT_BYTES).optional().describe(`Page size in bytes (default ${DEFAULT_PAGE_BYTES}).`),
2120
+ },
2121
+ annotations: READ,
2122
+ }, wrap(async (a, extra) => {
2123
+ const { person } = who(extra);
2124
+ if (!config.inquiryRoot)
2125
+ throw new ToolRefusal("unavailable", "This connector host has no inquiry shelf configured.");
2126
+ const ref = a.artefact.trim();
2127
+ let name = ref.replace(/^inquiry-artefact:/, "");
2128
+ if (ref.startsWith("research_artifact:")) {
2129
+ const held = all().find((r) => r.id === ref && r.kind === "research_artifact");
2130
+ const artefact = held?.body?.artefact;
2131
+ if (typeof artefact !== "string")
2132
+ throw new ToolRefusal("not_found", `No research_artifact ${ref}.`);
2133
+ name = artefact;
2134
+ }
2135
+ try {
2136
+ const { file, offset, revision, max_bytes: maxBytes } = a;
2137
+ return await readShelfArtefact(config.inquiryRoot, name, person, {
2138
+ ...(file !== undefined ? { file } : {}),
2139
+ ...(offset !== undefined ? { offset } : {}),
2140
+ ...(revision !== undefined ? { revision } : {}),
2141
+ ...(maxBytes !== undefined ? { maxBytes } : {}),
2142
+ });
2143
+ }
2144
+ catch (error) {
2145
+ if (error instanceof ShelfRefusal)
2146
+ throw new ToolRefusal(error.code, error.message);
2147
+ throw error;
2148
+ }
2149
+ }));
1920
2150
  server.registerTool("request_inquiry_episode", {
1921
2151
  title: "Request that an inquiry be woven into an episode, or start one",
1922
2152
  description: "Ask that a folder on the inquiry shelf (from save_research) be woven into a Chronicle episode, or that a new episode be started from it. Weaving copies the folder into the episode, so the approval page shows its visibility. Waits for a person's approval; on approval it runs once through Miadi's episode doors.",
@@ -2234,13 +2464,16 @@ export const TOOL_STATUS = {
2234
2464
  revise_pending_request: "live, contribute (a waiting or sent-back run or proposal gets its next version; same id, same card)",
2235
2465
  get_request_history: "live (every version of a request, oldest first; whoever asked, or the write tier)",
2236
2466
  supersede_pending_requests: "live, contribute (retires named earlier requests still waiting and joins them as earlier versions of the one that stands)",
2237
- request_session_steer: "live, contribute, write tier (runs inside an approved run's steering grant, else one scoped human decision; get_capabilities.steering says whether the transport works now)",
2467
+ request_session_steer: "live, contribute, write tier (one correction to a working agent, forwarded to its runtime; runs inside an approved run's steering grant, else one scoped human decision; get_capabilities.steering says whether the transport works now and which providers have an adapter)",
2468
+ revoke_session_steering: "live, contribute, write tier (stops a run's steering, or one steer not yet consumed)",
2238
2469
  request_review_operation: "live, contribute, needs_approval",
2239
2470
  request_screenwalk_reading: "live, contribute, needs_approval (host provider adapter required; stops at editorial decision)",
2240
2471
  request_reading_import: "live, contribute, needs_approval (exact public import; atomic service contract required)",
2241
2472
  request_deep_diver: "live, contribute, needs_approval",
2242
2473
  link_review_to_episode: "live, contribute, needs_approval",
2243
2474
  save_research: "live, contribute (the whole report, in parts when long; saved on the inquiry shelf with its issue, pushed; private by default)",
2475
+ list_research_artifacts: "live (the shelf as you may read it: yours, or every folder for the write tier; searched, sorted, paged)",
2476
+ read_research_artifact: "live (a shelf folder's manifest and its text files, paged, with sha256 and the commit that holds them; its owner or Miadi's write tier)",
2244
2477
  request_inquiry_episode: "live, contribute, needs_approval (weaves a shelf folder into an episode or starts one)",
2245
2478
  show_decisions: "live (cards in the conversation; deciding on them needs the write tier and the miadi:approve sign-in)",
2246
2479
  decide_request: "card only: the person's click on a decisions card; not offered to the assistant",
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.20";
1
+ export declare const VERSION = "0.1.21";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.1.20";
1
+ export const VERSION = "0.1.21";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miadi/connector",
3
- "version": "0.1.20",
3
+ "version": "0.1.21",
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",
@@ -16,6 +16,18 @@
16
16
  "types": "./dist/records.d.ts",
17
17
  "import": "./dist/records.js"
18
18
  },
19
+ "./research-digest": {
20
+ "types": "./dist/research-digest.d.ts",
21
+ "import": "./dist/research-digest.js"
22
+ },
23
+ "./runtime-steer": {
24
+ "types": "./dist/runtime-steer.d.ts",
25
+ "import": "./dist/runtime-steer.js"
26
+ },
27
+ "./research-shelf": {
28
+ "types": "./dist/research-shelf.d.ts",
29
+ "import": "./dist/research-shelf.js"
30
+ },
19
31
  "./package.json": "./package.json"
20
32
  },
21
33
  "bin": {