@miadi/connector 0.1.39 → 0.1.41
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 +62 -23
- package/STEERING.md +7 -3
- package/dist/comments.d.ts +80 -0
- package/dist/comments.js +119 -0
- package/dist/config.d.ts +2 -2
- package/dist/config.js +4 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/refs.d.ts +22 -0
- package/dist/refs.js +56 -0
- package/dist/tools.js +207 -18
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
One remote MCP service through which a person reaches Miadi from ChatGPT, Claude or any MCP client. Each person signs in with their own Miadi person token. They read agent sessions, Miadi reviews, Chronicle episodes and circles, and record observations, inquiries, handoffs and proposals. Every record carries the person's name.
|
|
4
4
|
|
|
5
|
-
The
|
|
5
|
+
The session reads use Miadi's `GET /api/session` and `GET /api/session/{id}`.
|
|
6
6
|
|
|
7
7
|
## Connect
|
|
8
8
|
|
|
9
|
+
A connector answers at `$MIADI_CONNECTOR_PUBLIC_URL/mcp`, the public address the host that runs it sets ([Run it](#run-it)). Ask that host's operator for the address. On a machine set up with the `miadi-config` apt package, `miadi-config get MIADI_CONNECTOR_PUBLIC_URL` prints it.
|
|
10
|
+
|
|
9
11
|
| client | how |
|
|
10
12
|
|---|---|
|
|
11
|
-
| ChatGPT | Add a custom connector (an app with an MCP server) with the URL
|
|
12
|
-
| Claude Code | `claude mcp add --transport http miadi
|
|
13
|
+
| ChatGPT | Add a custom connector (an app with an MCP server) with the URL `$MIADI_CONNECTOR_PUBLIC_URL/mcp`, written out, and OAuth authentication. ChatGPT registers itself; the sign-in page then asks for your Miadi person token once. |
|
|
14
|
+
| Claude Code | `claude mcp add --transport http miadi "$MIADI_CONNECTOR_PUBLIC_URL/mcp" --header "Authorization: Bearer <your Miadi person token>"` |
|
|
13
15
|
| any MCP client | Streamable HTTP at `/mcp`, OAuth 2.1 with dynamic client registration and PKCE, or a Miadi person token as Bearer. |
|
|
14
16
|
|
|
15
17
|
A person token comes from `/me` on Miadi (or an admin, under /admin → People).
|
|
@@ -20,13 +22,14 @@ Call `get_capabilities` first. It names the signed-in person, their Miadi API ti
|
|
|
20
22
|
|
|
21
23
|
| kind | tools |
|
|
22
24
|
|---|---|
|
|
23
|
-
| reads | `get_capabilities` `get_context` `list_circles` `get_circle` `list_sessions` `search_sessions` `get_session` `get_evidence` `read_episode_file` `get_evaluations` `get_narrative_beats` `review_lookup` `review_versions` `review_transcript_status` `handoff_status` `list_records` `get_run_result` `mission_status` `provider_capabilities` `mission_model_preflight` `search` `fetch` `list_research_artifacts` `read_research_artifact` |
|
|
24
|
-
| contributions | `ensure_review_transcript` `append_observation` `open_inquiry` `link_records` `propose_narrative_beat` `record_evaluation` `register_source_intent` `record_handoff` `update_handoff` `prepare_calendar_event` `save_research` |
|
|
25
|
+
| reads | `get_capabilities` `get_context` `list_circles` `get_circle` `list_sessions` `search_sessions` `get_session` `get_evidence` `list_episode_comments` `read_episode_file` `get_evaluations` `get_narrative_beats` `review_lookup` `review_versions` `review_transcript_status` `handoff_status` `list_records` `get_run_result` `mission_status` `provider_capabilities` `mission_model_preflight` `search` `fetch` `list_research_artifacts` `read_research_artifact` |
|
|
26
|
+
| contributions | `ensure_review_transcript` `append_observation` `comment_on_episode` `open_inquiry` `link_records` `propose_narrative_beat` `record_evaluation` `register_source_intent` `record_handoff` `update_handoff` `prepare_calendar_event` `save_research` |
|
|
25
27
|
| requests (approved by a person) | `propose_work` `propose_session_completion` `request_authorized_run` `request_session_steer` `revoke_session_steering` `request_review_operation` `request_deep_diver` `link_review_to_episode` `request_inquiry_episode` |
|
|
26
28
|
| decisions in the conversation | `show_decisions` (cards), `decide_request` (called by the card only) |
|
|
27
29
|
|
|
28
30
|
- **Reads** need Miadi's read tier and stay within it. A person Miadi gives no API tier reaches only `get_capabilities`. Sessions need the write tier, because a session's name and pane are operator data. For the same reason, below the write tier a record someone else made shows no session, working folder or seat, and no long bodies.
|
|
29
31
|
- **Episode files.** `get_evidence` lists an episode's files; each text file Miadi can preview carries a `read_ref` (`miadi-chronicle://<n>/<path>`). `read_episode_file` (or `fetch` with that ref) returns the file's whole UTF-8 text, read as the person through Miadi's file door, so Miadi's audience and room rules apply. The answer names the episode, the path, the content type, the byte count and the sha256, and `verified` says whether the text received hashes to what Miadi read. Only md, txt, yaml, yml and json files up to 512 KiB are read. A traversal, absolute, hidden or encoded path is refused before any URL is built. A longer text comes in pages cut on character boundaries: pass `page.next` back, and the joined pages hash to `sha256`. Other kinds answer `unsupported`, a file over the limit `too_large`, a missing one `not_found`, a ceremony note below the write gate `forbidden`.
|
|
32
|
+
- **Comments on an episode.** `comment_on_episode` publishes what a person says about an episode, in their name, optionally at a position of one of its media files (`media`, `at_seconds`, `until_seconds`). The comment is an observation that carries an `anchor`: the episode as Miadi resolved it, the media file's path and the position. `list_episode_comments` reads an episode's comments, by media file and by span of positions. Miadi's episode page shows them to a signed-in person who may open the episode. When the commenter sits in the episode's Root Circle, the comment is also said there as a turn, with their own token, and its record keeps the turn's id. The same `idempotency_key` returns the first comment and speaks no second turn. An episode's address is read under any written form: `miadi-chronicle://92` and `miadi-chronicle://092` name one episode in `get_context`, `get_evidence`, `list_records`, `handoff_status` and the comment tools. The comments Gérico's Space « Banque d'épisodes » published with `append_observation` (key `banque-episodes-…`) stay comments, and the media file and position are read from the sentence in their `intention` (jgwill/Miadi#1093).
|
|
30
33
|
- **One narrow grant.** A person with no Miadi API tier who holds `chronicle_foundations_read` (ticked by an admin under /admin → People → Additional permissions; admins hold it through their role) reaches `read_episode_file` for foundation documents only: `foundations/<topic>/*.md`, read through Miadi's `GET /api/chronicle/episodes/<ref>/foundations/<topic>/<file>.md`, which checks the permission on every read. Naming the episode alone lists them. Every other file and every other tool stays refused, and the permission gives no API tier. Unticking it refuses the next read. `get_capabilities` reports it under `foundation_read`, from Miadi's answer at that moment.
|
|
31
34
|
- **Contributions** need Miadi's read tier and the `miadi:contribute` scope, chosen at sign-in. A record is moved on (`update_handoff`) only by its author or the write tier, and a request's receipt comes only from its decision. They append a record to the ledger and change nothing else, except `save_research`: it saves a report on the inquiry shelf as a new folder (the Markdown exactly as given, owner and visibility recorded, private by default), opens the folder's inquiry issue, and commits and pushes the folder in the shelf's repository. A long report is sent in parts (`part`, `parts`, `upload_id`) and saved when the last part arrives; the answer returns its bytes, sha256 and first and last lines.
|
|
32
35
|
- **Sharing a record.** A record's author shares it with a talking circle or one person by linking from it: `link_records` with `from` the record's id, `to` `miadi-circle:<circle id>` or the person's id, and `relation` `shared_with`. `share_withdrawn`, from the same record to the same reader, ends the share. Only the author's links count, and `link_records` refuses a share from anyone else. The record's page (`/records/<id>`) admits its author, the people and members of the circles it is shared with (their circles read from Miadi on every read), and the read tier, and it says how the reader was admitted. Miadi's `/research` lists what is shared with a person under Shared.
|
|
@@ -43,7 +46,7 @@ The model that asked cannot approve its own request.
|
|
|
43
46
|
|
|
44
47
|
`get_run_result` returns one `projection` of the decision, dispatch/completion state, receipt link and outstanding instructions. The in-chat card, approval page and Miadi's research page use that same read model. Asking `show_decisions` for an already-decided `record_id` shows its receipt without issuing another decision token. An in-flight card can refresh status without repeating the operation. A completed basic review with unapplied approval instructions remains open as **changes outstanding**, not falsely finished.
|
|
45
48
|
|
|
46
|
-
### A review's transcript
|
|
49
|
+
### A review's transcript
|
|
47
50
|
|
|
48
51
|
A review is processed from the words of its video, so the connector acquires them itself, for a review made anywhere: the review service's own page, a manual edit, another client, or this connector's `create`.
|
|
49
52
|
|
|
@@ -54,11 +57,11 @@ A review is processed from the words of its video, so the connector acquires the
|
|
|
54
57
|
- **Every review, however it was made.** The review service announces `review.created` for each review it creates (its site, its API, a Shortcut, this connector), built with `@miadi/hooks-core`'s `buildReviewCreatedEvent` and signed like its other factory webhooks. Miadi's `/api/factory/review-events` normalizes it, records it in the event ledger (`@miadi/hooks-gateway`, `MIADI_EVENTS_DIR`, default `/srv/miadi/events`) and hands it to this connector's inbox, `inbox/connector-transcripts/`. Every 15 seconds the connector takes up to three: it asks the review service for the review again, starts the review's transcript job (a review that already holds one stores nothing, a withheld source is held), records the fact as the job's authority, and moves the file to `done/` or, with the reason, to `rejected/`. A fact waits in the inbox while the connector is down or the review service cannot be asked.
|
|
55
58
|
- **Endings are facts too.** When a job reaches `stored`, `held` or `failed`, the connector records `review.transcript.stored`, `review.transcript.held` or `review.transcript.failed` in the same ledger, on the review's trace (`miadi-review:<id>`) and naming the fact that caused it. The same ending recorded twice is one fact.
|
|
56
59
|
- **A worker's door.** A factory worker's account holds no Miadi API tier, so it cannot call the tools. `node packages/connector/scripts/ensure-transcript.mjs <review id> --mission run_request:<id> [--verify]` runs the same job under an approved run or work proposal that names the review (a person with the write tier approved it, and the job records the mission and who approved it). `--status` reads the state without a mission. A second process's attempt is left alone until it has written no stage for five minutes.
|
|
57
|
-
- **The host's reading runtime.** `get_capabilities` loads the module `MIADI_READING_ADAPTER` names (`scripts/host-reading-runtime.mjs`
|
|
60
|
+
- **The host's reading runtime.** `get_capabilities` loads the module `MIADI_READING_ADAPTER` names (`scripts/host-reading-runtime.mjs` in the source tree) and reports `reading_workflow.provider_runtime` from what it finds: `verified_transcript_only` while only caption acquisition has a provider. A reading acquires its transcript with the same reader and the same language rule, keeps durable stage receipts, and stops at the generation stages with a named blocker. Acquiring a transcript does not depend on the review service's import handshake.
|
|
58
61
|
|
|
59
62
|
### Revising a mission before it is decided
|
|
60
63
|
|
|
61
|
-
A mission is revised, never re-requested
|
|
64
|
+
A mission is revised, never re-requested. `revise_pending_request` changes an agent run or work proposal that still awaits a decision, or that its approver sent back, and gives it its next version. Pass the version you read as `expected_version` and only the fields that change. The request keeps its id, its approval page and its one card. A change of `provider` is verified on the host again. Each revision is a record in the ledger carrying the whole new content, its reason, author, changed fields and `sha256` content hash, so every earlier version stays readable verbatim with `get_request_history`. A request already approved, queued or declined is refused: a change after a decision is a new request or a steer.
|
|
62
65
|
|
|
63
66
|
A decision names the version it decides. The approval page carries the version it shows, and each card's decision token is bound to its version. A page or card that showed an earlier version is refused as `stale_version`, so no brief is queued for a version the person did not read. The receipt and the brief (`version="N"`, and the hash) name the version approved.
|
|
64
67
|
|
|
@@ -68,13 +71,13 @@ Requests made before this, one new request per revision, are joined with `supers
|
|
|
68
71
|
|
|
69
72
|
`mission_status` joins one mission read-only: its source request and decision, the sessions bound to it (each with how it is bound — a signed `session:` ref, the delivered brief's target, or the requested name), its issues and PRs, its steering grant, and where it stands stage by stage — approved, queued, delivered, running, merged, released, closed — each by its evidence, so an idle pane or a merge is never read as completion. Live panes and Miadi's session view are joined only for the write tier.
|
|
70
73
|
|
|
71
|
-
A mission is found by the issue it implements
|
|
74
|
+
A mission is found by the issue it implements. `request_authorized_run` and `propose_work` take `primary_issue`; older requests are read by their first issue ref, as an inference. An issue held as primary by several requests answers `ambiguous_mission` with the candidates, an issue only cited answers `related_only`, and only a record id or a declared primary that no older request holds by inference (`contested`) authorizes a steer, release or closure (`identity.authorizes_actions`). A release receipt names artifact, target, production check and check time; record it as `completion_receipt.release` on a handoff that cites the mission. `released` is `verified` only when the connector confirms it itself (the target is `miadi-connector` and the running version is the one released); any other complete receipt within seven days is `receipt_recorded`, with who recorded it and whether that was the approver. Old checks are `stale`; a version string, a future date or an incomplete receipt is `claimed_unverified`. `closed` needs an approved `propose_session_completion` ending (`exit` or `complete_then_exit`) that names the mission in its `mission` field and ends one of the mission's sessions; a completed request is `request_completed`. A GitHub reference the connector cannot read is `unverified`, with the reason (`no_github_token`, `not_visible_to_token`…), never `not_found`.
|
|
72
75
|
|
|
73
|
-
**The factory binding
|
|
76
|
+
**The factory binding.** The factory runner records every brief it hands to a seat in `delivered.jsonl`: the record, the tmux session, the pane id and the Claude Code session id that took the line. `mission_status` reads that receipt (write tier) and checks it against Miadi's session registry: `binding` is `verified` when both agree on session, tmux session and pane, `receipt_only` when the registry cannot confirm it, `unverified_association` when the registry places the session elsewhere or the pane is gone. Busy or idle comes from the registry when the binding is verified, else from a read-only peek of the bound pane, and is never read as completion. `mission_status` with `session:<uuid>` finds the one mission the factory delivered to that session (`factory_bound`); two are `ambiguous_mission`. `provider` names the provider requested, resolved and actually run, and `match: false` when they differ; nothing is re-run because of it. `get_session` lists the missions the factory delivered to the session (`binding: "factory_receipt"`), then the miadi-run missions Miadi links to it from their records and its inventory record (`binding: "miadi_run"`).
|
|
74
77
|
|
|
75
|
-
**The agent's result
|
|
78
|
+
**The agent's result.** 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.
|
|
76
79
|
|
|
77
|
-
`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
|
|
80
|
+
`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. [`STEERING.md`](STEERING.md) is the contract every provider's adapter keeps (`miadi.steering/1`), 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.
|
|
78
81
|
|
|
79
82
|
| who | owns | never does |
|
|
80
83
|
|---|---|---|
|
|
@@ -105,13 +108,13 @@ The record itself moves with its evidence: `completed` once the model has it, `b
|
|
|
105
108
|
|
|
106
109
|
`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.
|
|
107
110
|
|
|
108
|
-
An idle seat takes the same inbox, and the connector types into no session that has an adapter
|
|
111
|
+
An idle seat takes the same inbox, and the connector types into no session that has an adapter. 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.
|
|
109
112
|
|
|
110
113
|
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.
|
|
111
114
|
|
|
112
115
|
`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, a person's own default applies, then one the operator set for them, then Claude Code, and the result is named in the brief. A default that is missing or shows no sign-in leaves the mission unstarted, and no other provider stands in for it. Pi, Copilot and Codex otherwise run 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.
|
|
113
116
|
|
|
114
|
-
**Codex runs only on its requester's own choice
|
|
117
|
+
**Codex runs only on its requester's own choice.** The provider field is the caller's: the connector cannot read the chat, so `provider: "codex"` chooses nothing for the person. A run that names Codex is recorded, and its answer says it `needs_person_choice`. The approval page then shows no Approve button. Only the requester, signed in there with their own Miadi person token, can tick and send "Choose codex for this mission". That `provider_choice` record is bound to the request id, its version and its content hash, must be under 24 hours old when the request is approved, and covers that one mission. A revision makes it stale. A generic Approve, on the page or on a card, is refused as `provider_choice_required`, and so is a choice by any other person or by a service token. The requester can instead set their own policy at `/providers` so their requests may name Codex without a per-mission choice; that policy is theirs only and revisable. The check runs at request, revision, approval, and where the brief is written (approval and every rerun). The brief carries `provider_authorization` and `provider_choice` (or `provider_policy`), and the factory runner refuses to launch Codex for a connector brief without them. `request_authorized_run`, `revise_pending_request`, `mission_status`, `show_decisions` and `mission_model_preflight` show `provider_authorization`; after approval it is also in the request's `completion_receipt`, which `get_run_result` returns. A Codex launch without it is named on the mission and fails the preflight closed as `provider_not_authorized`. A brief the runner refuses goes to `queue/refused/` with its reason, and the request shows it. Other providers keep their regular policy, and nothing falls back to Codex. What this does not cover: anyone who can write `/srv/miadi/factory/queue` or the connector's state directory can forge a brief or a record (the folder's permissions are the boundary); a configured launcher that runs Codex behind a wrapper whose name does not say codex is trusted as configured; a brief to an existing session reaches only an idle Claude Code agent today, so it is not checked; and an agent that starts `codex` itself from inside its session is outside the connector's reach.
|
|
115
118
|
|
|
116
119
|
**Which Claude Code model a run launches on.** `request_authorized_run` and `propose_work` may name a `model`, and that model is used. It must be on the host's permitted list, and a model named with any other provider is refused, so a model never moves a mission to a provider nobody chose. With none named, Jev chooses among the permitted models once, when the run is approved. It is sent the task type and criticality (`task_type`, `criticality`; default `implementation`, `normal`) and the candidates, never task text, a mission id or a repository name, and its choice authorizes nothing. If Jev has no key, is down, abstains, answers below the 0.8 floor or breaks the answer contract, the launch uses the configured Claude Code model, and the receipt's `fallback_reasons` says why. Jev knows these models only through the fit notes in `claude-models.ts`, which are the Factory's reading of Anthropic's descriptions and not a measurement: `implementation` fits Sonnet, `file_relevance` and normal `review` fit Opus, `architecture_refactor` and anything `security_critical` fit Fable. Its confidence is uncalibrated. A request that fills no `task_type` counts as `implementation`, so it goes to Sonnet even where Claude Code's own setting says Opus; the draft review flags that absence (aspect S7), and the approval page and the receipt (`model_routing.labels`) say which label was a default and which the requester or the approver set.
|
|
117
120
|
|
|
@@ -125,12 +128,12 @@ A session already running keeps its model: Jev is not asked, and a named model f
|
|
|
125
128
|
|
|
126
129
|
### The mission standard
|
|
127
130
|
|
|
128
|
-
A new or revised run or work proposal answers with `draft_review`, the report on that version against the mission standard
|
|
131
|
+
A new or revised run or work proposal answers with `draft_review`, the report on that version against the mission standard. It lists aspects to revise, each with `aspect`, `name`, `checked_by`, `why`, `ask`, `settled_by` and sometimes `span`, in `needs_revision`, and what it did not judge in `not_checked`. `running_missions` lists what a person approved in the last 48 hours that has not finished, `preferences` holds the requester's standing preferences, and `next_action` says what to do. It carries no overall verdict, it advises and blocks nothing, and a failure in it never refuses a request. The report is also in `get_run_result`, and the open aspects are on the decision card and the approval page. The worker reads `delivery`, `person_words` and any aspect still open at approval in its brief.
|
|
129
132
|
|
|
130
133
|
| aspect | requires | checked by | settled by |
|
|
131
134
|
|---|---|---|---|
|
|
132
135
|
| S1 | one exact place the result lands, in `delivery` | code for an address, an issue, a uuid or a path; Jev below 0.3 otherwise | drafter |
|
|
133
|
-
| S2 | who may release, deploy or start a session | not checked yet:
|
|
136
|
+
| S2 | who may release, deploy or start a session | not checked yet: a local reviewer is planned | person |
|
|
134
137
|
| S3 | running work on the same ground | code, on a shared issue only; the local reviewer judges the rest | drafter |
|
|
135
138
|
| S4 | a mechanism the mission dictates | Jev at 0.8 or above | drafter |
|
|
136
139
|
| S5 | the person's words for what is credited to them, in `person_words` | Jev at 0.8 or above notices the credit; only the drafter can answer | drafter |
|
|
@@ -142,7 +145,7 @@ The drafter gets two rounds: a report and a revision, twice. The third report's
|
|
|
142
145
|
|
|
143
146
|
**The standard is a document.** A text prompt named `mission-standard`, label `production`, in the prompt store's Engineering domain, read at most once per ten minutes, holding `{ jev_model, aspects, preferences }`. Revising it needs no release, and a report names the version that judged it. An aspect with a Jev check and a new code runs as written, so an aspect can be added there. `S1`, `S3` and `S6` have code behind them. A failed read keeps the last good version and says so, and with none the built-in copy answers and says why. A person's preferences live only in the store, because this package is published.
|
|
144
147
|
|
|
145
|
-
**What leaves the host.** The mission's text and its `delivery`, with ids, paths, hashes, URLs and repository names removed, to Jev, when the connector's environment holds a key. `mission_model_preflight` still sends no task text. Keys go in an environment file only the connector's user can read (`EnvironmentFile=-%h/.config/miadi/connector.env`): `JEV_AI_API_KEY` or `TYPESAFE_API_KEY`, and `ENG_LANGFUSE_PUBLIC_KEY`, `ENG_LANGFUSE_SECRET_KEY`, `ENG_LANGFUSE_BASE_URL`. Without them the report says what went unchecked, and code's findings stand. The bars are uncalibrated.
|
|
148
|
+
**What leaves the host.** The mission's text and its `delivery`, with ids, paths, hashes, URLs and repository names removed, to Jev, when the connector's environment holds a key. `mission_model_preflight` still sends no task text. Keys go in an environment file only the connector's user can read (`EnvironmentFile=-%h/.config/miadi/connector.env`): `JEV_AI_API_KEY` or `TYPESAFE_API_KEY`, and `ENG_LANGFUSE_PUBLIC_KEY`, `ENG_LANGFUSE_SECRET_KEY`, `ENG_LANGFUSE_BASE_URL`. Without them the report says what went unchecked, and code's findings stand. The bars are uncalibrated.
|
|
146
149
|
|
|
147
150
|
### Deciding inside the conversation
|
|
148
151
|
|
|
@@ -161,11 +164,11 @@ Earned 2026-11-06: 0.1.22 moved the card to `decisions-v2.html` and stopped serv
|
|
|
161
164
|
|
|
162
165
|
A decision is recorded once. An approved run that calls another service (a review operation, Deep Diver, an episode door, a steer) is written to the ledger as approved and running before the call, so a restart can never offer the request for a second approval; a run the connector was recording when it stopped reads as failed and may be run again. A decision whose run takes longer than `MIADI_CONNECTOR_DECISION_WAIT_MS` is answered as recorded and running, and the card reads `get_run_result` every 3 seconds until the outcome is in. The same decision sent again (a host retrying a call, a second click, the page form sent twice) answers with the first one's receipt, marked `replayed`, and runs nothing. A different decision is refused as `decision_conflict`, with where the request stands. When the host gives up on a call, the card reads where the request stands before it offers the buttons again.
|
|
163
166
|
|
|
164
|
-
**A person mentioned and a person on the record
|
|
167
|
+
**A person mentioned and a person on the record.** A person mentioned, by name or as a kind of user, holds nothing back: a spoken name is never a reason to withhold a source or to ask anyone. A person on the record, meaning filmed or with their own voice, words or screens shown, has a release agreed at the start of the production. Nothing but the owner's `withheld` registration holds a source back, and no code counts names. `request_participant_consent` is the door for a person on the record who has no release yet.
|
|
165
168
|
|
|
166
|
-
**An approved create or new version sends the person's words
|
|
169
|
+
**An approved create or new version sends the person's words.** `POST /api/reviews` and `POST /api/reviews/:id/versions` carry `source: { title, description, boundaries }` from the `source_intent`: its own fields, or the `TITLE:`, `DESCRIPTION` and `Review boundaries:` lines of its intention. The service keeps none of it, so each generation sends it again, and a new version finds its source through the review's video. The receipt's `source_words.title_taken` reads from the answer whether the service used them. A video already reviewed answers with the existing review, so a `create` on it uses nothing.
|
|
167
170
|
|
|
168
|
-
**A created review gets its transcript
|
|
171
|
+
**A created review gets its transcript.** An approved `create` calls the review service, then reads the video's original-language YouTube captions with a local `uvx yt-dlp` and stores them on the review as `[mm:ss] text`, so an agent reads them through `fetch` and the factory's kind briefs find them with `miadi_review.py transcript`. No model is called for the transcript. The service answers an empty `POST /api/reviews/:id/transcript` by asking Gemini, so an empty one is never sent. `completion_receipt.transcript` says where it stands, and the card and the approval page say the same:
|
|
169
172
|
|
|
170
173
|
| outcome | meaning |
|
|
171
174
|
|---|---|
|
|
@@ -193,14 +196,23 @@ Every record has a claim category: `observed`, `hypothesis`, `desired_future`, `
|
|
|
193
196
|
|
|
194
197
|
```bash
|
|
195
198
|
pnpm --filter @miadi/connector build
|
|
196
|
-
MIADI_CONNECTOR_PUBLIC_URL=https://
|
|
199
|
+
MIADI_CONNECTOR_PUBLIC_URL=https://connector.example.org node packages/connector/dist/bin.js
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
`MIADI_CONNECTOR_PUBLIC_URL` is the connector's one address: the OAuth issuer, the base of the links in its answers, and what people add to their client as `$MIADI_CONNECTOR_PUBLIC_URL/mcp`. Unset, the connector is reachable only from its own host, at `http://127.0.0.1:<port>`. On a host set up with the `miadi-config` apt package, set it once in `/etc/miadi/miadi.env`:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
sudo miadi-config set MIADI_CONNECTOR_PUBLIC_URL https://connector.example.org
|
|
197
206
|
```
|
|
198
207
|
|
|
208
|
+
A service reads the same file with `EnvironmentFile=-/etc/miadi/miadi.env`, and login shells get it, so the `claude mcp add` line under [Connect](#connect) works as written. A person's own machine with `miadi-config` takes the same setting, with the address of the connector they use.
|
|
209
|
+
|
|
199
210
|
| variable | default | meaning |
|
|
200
211
|
|---|---|---|
|
|
201
|
-
| `MIADI_CONNECTOR_PUBLIC_URL` | `http://127.0.0.1:<port>` | the address clients use
|
|
212
|
+
| `MIADI_CONNECTOR_PUBLIC_URL` | `http://127.0.0.1:<port>` | the address clients use, without `/mcp`; the OAuth issuer |
|
|
202
213
|
| `MIADI_CONNECTOR_PORT` / `MIADI_CONNECTOR_HOST` | `3337` / `127.0.0.1` | where it listens |
|
|
203
214
|
| `MIADI_CONNECTOR_MIADI_URL` | `http://127.0.0.1:3335` | the Miadi app it calls, as the person |
|
|
215
|
+
| `MIADI_PUBLIC_URL` | `MIADI_URL_BASE`, else `MIADI_CONNECTOR_MIADI_URL` | the Miadi app's address in the links people open from an answer (`/chronicle/…`, `/research`) |
|
|
204
216
|
| `MIADI_CONNECTOR_STATE_DIR` | `/srv/miadi/connector` | `oauth.json` (token digests, clients) and `ledger.jsonl` (records), mode 0700 |
|
|
205
217
|
| `MIADI_REVIEW_BASE_URL` | `https://miadi-review-service.vercel.app` | the review service |
|
|
206
218
|
| `MIADI_REVIEW_TOKEN` | read from `~/.env` | review search and approved review operations |
|
|
@@ -210,7 +222,7 @@ MIADI_CONNECTOR_PUBLIC_URL=https://mcp.sanctuaireagentique.com node packages/con
|
|
|
210
222
|
| `MIADI_CONNECTOR_DECISION_TOKEN_TTL` | `604800` (7 days) | seconds a card's decision token stays usable, held between 300 and 2592000 |
|
|
211
223
|
| `MIADI_CONNECTOR_DECISION_WAIT_MS` | `20000` | how long a decision answer waits for its run before answering it as recorded and running, at most 50000 |
|
|
212
224
|
|
|
213
|
-
|
|
225
|
+
It listens on loopback by default, and a tunnel or reverse proxy on the same host serves `MIADI_CONNECTOR_PUBLIC_URL` from it.
|
|
214
226
|
|
|
215
227
|
## Security
|
|
216
228
|
|
|
@@ -228,3 +240,30 @@ On gaia it runs as the user service `miadi-connector.service`, and the Cloudflar
|
|
|
228
240
|
```bash
|
|
229
241
|
pnpm --filter @miadi/connector test
|
|
230
242
|
```
|
|
243
|
+
|
|
244
|
+
## Related
|
|
245
|
+
|
|
246
|
+
The issues and the episode behind each part. `jgwill/Miadi` is a private repository.
|
|
247
|
+
|
|
248
|
+
| part | where it was decided |
|
|
249
|
+
|---|---|
|
|
250
|
+
| the contract: three domains, five accountable circles | jgwill/Miadi#815 |
|
|
251
|
+
| the review bridge | jgwill/Miadi#816 |
|
|
252
|
+
| the session reads | jgwill/Miadi#746 |
|
|
253
|
+
| a review's transcript, its jobs and its facts | jgwill/Miadi#995 |
|
|
254
|
+
| a created review's transcript from its captions | jgwill/Miadi#925 |
|
|
255
|
+
| the person's words on an approved create or version | jgwill/Miadi#963 |
|
|
256
|
+
| a person mentioned and a person on the record | jgwill/Miadi#962 |
|
|
257
|
+
| revising a mission before it is decided | jgwill/Miadi#919 |
|
|
258
|
+
| a mission found by its issue | jgwill/Miadi#913 |
|
|
259
|
+
| the factory binding | jgwill/Miadi#909 |
|
|
260
|
+
| the agent's result | jgwill/Miadi#921 |
|
|
261
|
+
| miadi-run missions on a session | jgwill/Miadi#993 |
|
|
262
|
+
| steering a busy agent | jgwill/Miadi#930 |
|
|
263
|
+
| `miadi.steering/1` and the adapters | jgwill/Miadi#942 |
|
|
264
|
+
| Codex on its requester's own choice | jgwill/Miadi#926 |
|
|
265
|
+
| the mission standard, and the local reviewer that will check S2 (A3) | jgwill/Miadi#939 |
|
|
266
|
+
| the tests the standard's bars were read from | Episode 564 (miadi-chronicle://564), `mission-draft-review-261105/` |
|
|
267
|
+
| what a published README holds | jgwill/Miadi#685 |
|
|
268
|
+
|
|
269
|
+
On the factory host (gaia) the connector runs as the user service `miadi-connector.service`, installed from the Miadi repository's `scripts/ops/etc/miadi-connector.user.service`. That host's `/etc/miadi/miadi.env` sets `MIADI_CONNECTOR_PUBLIC_URL`, and the Cloudflare tunnel `gaia` serves that address from the loopback port. Its reading runtime is `packages/connector/scripts/host-reading-runtime.mjs`.
|
package/STEERING.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# The steering contract: `miadi.steering/1`
|
|
2
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.
|
|
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. The runtime owns delivery to the model.
|
|
4
4
|
|
|
5
5
|
## Who owns what
|
|
6
6
|
|
|
@@ -26,7 +26,7 @@ A person controlling a mission sends one correction. It reaches that mission's r
|
|
|
26
26
|
|
|
27
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
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
|
|
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 (see Related), where the model's "received" never reached the file and `behavior_adjusted` still did. Its absence shows nothing either way.
|
|
30
30
|
|
|
31
31
|
## The inbox
|
|
32
32
|
|
|
@@ -80,8 +80,12 @@ What this keeps:
|
|
|
80
80
|
|
|
81
81
|
## Which provider a request runs on
|
|
82
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 Claude Code. A default that is not installed or shows no sign-in leaves the mission unstarted and is never replaced. Codex is never a default
|
|
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 Claude Code. A default that is not installed or shows no sign-in leaves the mission unstarted and is never replaced. Codex is never a default. 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
84
|
|
|
85
85
|
## Rollback
|
|
86
86
|
|
|
87
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.
|
|
88
|
+
|
|
89
|
+
## Related
|
|
90
|
+
|
|
91
|
+
`jgwill/Miadi` is a private repository. jgwill/Miadi#942 holds the evidence for this contract, its production baseline included. jgwill/Miadi#930 holds the correction it was built from: the runtime owns delivery to the model. jgwill/Miadi#926 is why Codex is never a default.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The comments of an episode, read from the ledger (jgwill/Miadi#1093; P1 of
|
|
3
|
+
* rispecs/episode-participants/SPEC.md). One read model for the connector's
|
|
4
|
+
* tools and for Miadi's pages, so both answer the same comments.
|
|
5
|
+
*
|
|
6
|
+
* A comment is an observation that carries an anchor (`body.anchor`, written
|
|
7
|
+
* by comment_on_episode): the episode, and optionally a media file and a
|
|
8
|
+
* position in it. The first comments were published before the anchor existed,
|
|
9
|
+
* by Gérico's Space « Banque d'épisodes », with append_observation: their key
|
|
10
|
+
* starts with `banque-episodes-` and the media file and position are in the
|
|
11
|
+
* sentence of their `intention`. They stay comments, and that one sentence is
|
|
12
|
+
* read for them. Nothing is read from a comment's own text. The other
|
|
13
|
+
* observations that cite an episode are reports, and are not comments.
|
|
14
|
+
*/
|
|
15
|
+
import type { ConnectorRecord } from "./records.js";
|
|
16
|
+
export interface CommentAnchor {
|
|
17
|
+
/** The episode as the connector resolved it when the comment was published; null on a Space's first comments. */
|
|
18
|
+
episode: {
|
|
19
|
+
folder: string | null;
|
|
20
|
+
number: number | null;
|
|
21
|
+
} | null;
|
|
22
|
+
/** The media file: its path inside the episode, or the bare name a Space stated. Null for the whole episode. */
|
|
23
|
+
media: string | null;
|
|
24
|
+
at_seconds: number | null;
|
|
25
|
+
until_seconds: number | null;
|
|
26
|
+
/** `fields`: the record carries the anchor. `intention`: read from the sentence the Space wrote. */
|
|
27
|
+
stated_in: "fields" | "intention";
|
|
28
|
+
}
|
|
29
|
+
/** The turn a comment also became in the episode's Root Circle, when its author sat there. */
|
|
30
|
+
export interface CircleTurn {
|
|
31
|
+
ceremony_id: string;
|
|
32
|
+
beat_id: string;
|
|
33
|
+
circle_id?: string;
|
|
34
|
+
circle_name?: string;
|
|
35
|
+
at?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface EpisodeComment {
|
|
38
|
+
id: string;
|
|
39
|
+
/** When it was published. */
|
|
40
|
+
at: string;
|
|
41
|
+
text: string;
|
|
42
|
+
author: {
|
|
43
|
+
person_id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
};
|
|
46
|
+
/** The client it came through, when that client registered a name. */
|
|
47
|
+
client: string | null;
|
|
48
|
+
claim_category: string | null;
|
|
49
|
+
intention: string | null;
|
|
50
|
+
anchor: CommentAnchor | null;
|
|
51
|
+
circle_turn: CircleTurn | null;
|
|
52
|
+
}
|
|
53
|
+
export interface CommentEpisode {
|
|
54
|
+
number?: number | null;
|
|
55
|
+
folder?: string | null;
|
|
56
|
+
/** Another folder carries the same number: a comment that names the number alone is then shown on neither. */
|
|
57
|
+
number_shared?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface CommentFilter {
|
|
60
|
+
media?: string;
|
|
61
|
+
from_seconds?: number;
|
|
62
|
+
to_seconds?: number;
|
|
63
|
+
person_id?: string;
|
|
64
|
+
}
|
|
65
|
+
/** The key Gérico's Space « Banque d'épisodes » gives a comment it publishes with append_observation. */
|
|
66
|
+
export declare const SPACE_COMMENT_KEY: RegExp;
|
|
67
|
+
/** Where a comment points, from its fields, else from the Space's sentence; null for the whole episode. */
|
|
68
|
+
export declare function anchorOf(r: ConnectorRecord): CommentAnchor | null;
|
|
69
|
+
export declare function isComment(r: ConnectorRecord): boolean;
|
|
70
|
+
export declare function commentOf(r: ConnectorRecord): EpisodeComment;
|
|
71
|
+
/** A listed path and a bare file name agree when the name is the path's last segment. */
|
|
72
|
+
export declare function sameMedia(a: string, b: string): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The comments on one episode, from the folded ledger (`current()`), in order
|
|
75
|
+
* of media file, then position, then time. A comment on the whole episode
|
|
76
|
+
* comes before the comments at a position.
|
|
77
|
+
*/
|
|
78
|
+
export declare function commentsOf(records: readonly ConnectorRecord[], episode: CommentEpisode, filter?: CommentFilter): EpisodeComment[];
|
|
79
|
+
/** 105 → "1:45", 3725 → "1:02:05". */
|
|
80
|
+
export declare function formatPosition(seconds: number): string;
|
package/dist/comments.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { parseChronicleAddress } from "./refs.js";
|
|
2
|
+
/** The key Gérico's Space « Banque d'épisodes » gives a comment it publishes with append_observation. */
|
|
3
|
+
export const SPACE_COMMENT_KEY = /^banque-episodes-/;
|
|
4
|
+
/** The sentence that Space writes in `intention`: sur « <file> », à <n> s du média. */
|
|
5
|
+
const SPACE_SENTENCE = /sur\s+«[\s\u00a0\u202f]*(.+?)[\s\u00a0\u202f]*»,?\s+à\s+(\d+(?:[.,]\d+)?)\s*s\b/;
|
|
6
|
+
const finite = (v) => (typeof v === "number" && Number.isFinite(v) && v >= 0 ? v : null);
|
|
7
|
+
const text = (v) => (typeof v === "string" && v.trim() ? v.trim() : null);
|
|
8
|
+
/** Where a comment points, from its fields, else from the Space's sentence; null for the whole episode. */
|
|
9
|
+
export function anchorOf(r) {
|
|
10
|
+
const a = r.body.anchor;
|
|
11
|
+
if (a && typeof a === "object") {
|
|
12
|
+
const anchor = a;
|
|
13
|
+
const episode = anchor.episode && typeof anchor.episode === "object" ? anchor.episode : null;
|
|
14
|
+
const at = finite(anchor.at_seconds);
|
|
15
|
+
const until = finite(anchor.until_seconds);
|
|
16
|
+
return {
|
|
17
|
+
episode: episode ? { folder: text(episode.folder), number: finite(episode.number) } : null,
|
|
18
|
+
media: text(anchor.media),
|
|
19
|
+
at_seconds: at,
|
|
20
|
+
until_seconds: at !== null && until !== null && until > at ? until : null,
|
|
21
|
+
stated_in: "fields",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (!SPACE_COMMENT_KEY.test(r.idempotency_key ?? ""))
|
|
25
|
+
return null;
|
|
26
|
+
const said = SPACE_SENTENCE.exec(r.intention ?? "");
|
|
27
|
+
if (!said)
|
|
28
|
+
return null;
|
|
29
|
+
return { episode: null, media: said[1].trim(), at_seconds: Number(said[2].replace(",", ".")), until_seconds: null, stated_in: "intention" };
|
|
30
|
+
}
|
|
31
|
+
export function isComment(r) {
|
|
32
|
+
if (r.kind !== "observation" || r.state === "withdrawn")
|
|
33
|
+
return false;
|
|
34
|
+
const body = r.body;
|
|
35
|
+
if (body.reading || !text(body.text))
|
|
36
|
+
return false;
|
|
37
|
+
return Boolean(body.anchor && typeof body.anchor === "object") || SPACE_COMMENT_KEY.test(r.idempotency_key ?? "");
|
|
38
|
+
}
|
|
39
|
+
export function commentOf(r) {
|
|
40
|
+
const turn = r.completion_receipt?.circle_turn;
|
|
41
|
+
return {
|
|
42
|
+
id: r.id,
|
|
43
|
+
at: r.created_at,
|
|
44
|
+
text: String(r.body.text ?? ""),
|
|
45
|
+
author: { person_id: r.actor.person_id, name: r.actor.name },
|
|
46
|
+
client: r.actor.client_name ?? null,
|
|
47
|
+
claim_category: r.claim_category ?? null,
|
|
48
|
+
intention: r.intention ?? null,
|
|
49
|
+
anchor: anchorOf(r),
|
|
50
|
+
circle_turn: turn && typeof turn.ceremony_id === "string" && typeof turn.beat_id === "string" ? turn : null,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** A listed path and a bare file name agree when the name is the path's last segment. */
|
|
54
|
+
export function sameMedia(a, b) {
|
|
55
|
+
if (a === b)
|
|
56
|
+
return true;
|
|
57
|
+
const last = (p) => p.slice(p.lastIndexOf("/") + 1);
|
|
58
|
+
return (!a.includes("/") || !b.includes("/")) && last(a) === last(b);
|
|
59
|
+
}
|
|
60
|
+
function namesEpisode(r, anchor, episode) {
|
|
61
|
+
const byNumber = (n) => !episode.number_shared && n !== null && episode.number !== null && episode.number !== undefined && n === episode.number;
|
|
62
|
+
if (anchor?.episode?.folder && episode.folder)
|
|
63
|
+
return anchor.episode.folder === episode.folder;
|
|
64
|
+
if (anchor?.episode && byNumber(anchor.episode.number))
|
|
65
|
+
return true;
|
|
66
|
+
for (const ref of r.refs) {
|
|
67
|
+
const address = parseChronicleAddress(ref);
|
|
68
|
+
if (!address)
|
|
69
|
+
continue;
|
|
70
|
+
if (address.folder && episode.folder) {
|
|
71
|
+
if (address.folder === episode.folder)
|
|
72
|
+
return true;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (byNumber(address.number))
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The comments on one episode, from the folded ledger (`current()`), in order
|
|
82
|
+
* of media file, then position, then time. A comment on the whole episode
|
|
83
|
+
* comes before the comments at a position.
|
|
84
|
+
*/
|
|
85
|
+
export function commentsOf(records, episode, filter = {}) {
|
|
86
|
+
const out = [];
|
|
87
|
+
for (const r of records) {
|
|
88
|
+
if (!isComment(r))
|
|
89
|
+
continue;
|
|
90
|
+
const anchor = anchorOf(r);
|
|
91
|
+
if (!namesEpisode(r, anchor, episode))
|
|
92
|
+
continue;
|
|
93
|
+
if (filter.person_id && r.actor.person_id !== filter.person_id)
|
|
94
|
+
continue;
|
|
95
|
+
if (filter.media && !(anchor?.media && sameMedia(anchor.media, filter.media)))
|
|
96
|
+
continue;
|
|
97
|
+
if (filter.from_seconds !== undefined && !(anchor?.at_seconds != null && anchor.at_seconds >= filter.from_seconds))
|
|
98
|
+
continue;
|
|
99
|
+
if (filter.to_seconds !== undefined && !(anchor?.at_seconds != null && anchor.at_seconds <= filter.to_seconds))
|
|
100
|
+
continue;
|
|
101
|
+
out.push(commentOf(r));
|
|
102
|
+
}
|
|
103
|
+
// By the file's own name, so a Space's bare name and the listed path of one file read as one sequence.
|
|
104
|
+
const name = (media) => media.slice(media.lastIndexOf("/") + 1);
|
|
105
|
+
const key = (c) => [c.anchor?.media ? name(c.anchor.media) : "", c.anchor?.at_seconds ?? -1];
|
|
106
|
+
return out.sort((a, b) => {
|
|
107
|
+
const [am, ap] = key(a);
|
|
108
|
+
const [bm, bp] = key(b);
|
|
109
|
+
return am < bm ? -1 : am > bm ? 1 : ap - bp || (a.at < b.at ? -1 : a.at > b.at ? 1 : 0);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/** 105 → "1:45", 3725 → "1:02:05". */
|
|
113
|
+
export function formatPosition(seconds) {
|
|
114
|
+
const whole = Math.floor(seconds);
|
|
115
|
+
const h = Math.floor(whole / 3600);
|
|
116
|
+
const m = Math.floor((whole % 3600) / 60);
|
|
117
|
+
const s = whole % 60;
|
|
118
|
+
return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}` : `${m}:${String(s).padStart(2, "0")}`;
|
|
119
|
+
}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export interface ConnectorConfig {
|
|
2
|
-
/** The address people and ChatGPT use, e.g. https://connector.
|
|
2
|
+
/** The address people and ChatGPT use, without /mcp (MIADI_CONNECTOR_PUBLIC_URL), e.g. https://connector.example.org */
|
|
3
3
|
publicUrl: string;
|
|
4
4
|
host: string;
|
|
5
5
|
port: number;
|
|
6
6
|
/** The Miadi app the connector reads and writes through. */
|
|
7
7
|
miadiUrl: string;
|
|
8
|
-
/** The address of Miadi that people open in a browser (links in answers). */
|
|
8
|
+
/** The address of Miadi that people open in a browser (links in answers): MIADI_PUBLIC_URL, else MIADI_URL_BASE, else miadiUrl. */
|
|
9
9
|
miadiPublicUrl: string;
|
|
10
10
|
reviewUrl: string;
|
|
11
11
|
reviewToken?: string;
|
package/dist/config.js
CHANGED
|
@@ -12,12 +12,14 @@ function bounded(raw, fallback, min, max) {
|
|
|
12
12
|
export function configFromEnv(env = process.env) {
|
|
13
13
|
const port = Number(env.MIADI_CONNECTOR_PORT || 3337);
|
|
14
14
|
const shelf = resolveEnv({}, env);
|
|
15
|
+
const miadiUrl = (env.MIADI_CONNECTOR_MIADI_URL || "http://127.0.0.1:3335").replace(/\/$/, "");
|
|
15
16
|
return {
|
|
16
17
|
publicUrl: (env.MIADI_CONNECTOR_PUBLIC_URL || `http://127.0.0.1:${port}`).replace(/\/$/, ""),
|
|
17
18
|
host: env.MIADI_CONNECTOR_HOST || "127.0.0.1",
|
|
18
19
|
port,
|
|
19
|
-
miadiUrl
|
|
20
|
-
|
|
20
|
+
miadiUrl,
|
|
21
|
+
// A host's own front, from /etc/miadi/miadi.env (miadi-config); never another host's address.
|
|
22
|
+
miadiPublicUrl: (env.MIADI_PUBLIC_URL || env.MIADI_URL_BASE || miadiUrl).replace(/\/$/, ""),
|
|
21
23
|
reviewUrl: (env.MIADI_REVIEW_BASE_URL || "https://miadi-review-service.vercel.app").replace(/\/$/, ""),
|
|
22
24
|
reviewToken: reviewToken(env),
|
|
23
25
|
stateDir: env.MIADI_CONNECTOR_STATE_DIR || "/srv/miadi/connector",
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { identifyThroughMiadi, MiadiUnavailable, type MiadiPerson, type ApiTier
|
|
|
4
4
|
export { MiadiOAuthProvider, SCOPES, SCOPE_READ, SCOPE_CONTRIBUTE, type Person } from "./oauth.js";
|
|
5
5
|
export { CIRCLES, CIRCLE_IDS, CLAIM_CATEGORIES, DOMAINS, HANDOFF_STATES, RECORD_KINDS, current, type ConnectorRecord, type CircleId, type ClaimCategory, type RecordKind, } from "./records.js";
|
|
6
6
|
export { TOOL_STATUS, githubGetter, steeringTransport } from "./tools.js";
|
|
7
|
+
export { cites, parseChronicleAddress, refMatcher, sameRef, type ChronicleAddress } from "./refs.js";
|
|
8
|
+
export { SPACE_COMMENT_KEY, anchorOf, commentOf, commentsOf, formatPosition, isComment, sameMedia, type CircleTurn, type CommentAnchor, type CommentEpisode, type CommentFilter, type EpisodeComment, } from "./comments.js";
|
|
7
9
|
export { factoryLedgerPath, readFactoryReceipts, receiptsForRecord, recordsForSession, type FactoryReceipt } from "./factory-receipt.js";
|
|
8
10
|
export { classifyOutput, missionResult, type GithubAnswer, type GithubGet, type MissionOutput, type MissionResult, type OutputCheck, type ResultSubmission, } from "./mission-result.js";
|
|
9
11
|
export { runBrief, readQueueState } from "./approve.js";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,8 @@ export { identifyThroughMiadi, MiadiUnavailable } from "./people.js";
|
|
|
4
4
|
export { MiadiOAuthProvider, SCOPES, SCOPE_READ, SCOPE_CONTRIBUTE } from "./oauth.js";
|
|
5
5
|
export { CIRCLES, CIRCLE_IDS, CLAIM_CATEGORIES, DOMAINS, HANDOFF_STATES, RECORD_KINDS, current, } from "./records.js";
|
|
6
6
|
export { TOOL_STATUS, githubGetter, steeringTransport } from "./tools.js";
|
|
7
|
+
export { cites, parseChronicleAddress, refMatcher, sameRef } from "./refs.js";
|
|
8
|
+
export { SPACE_COMMENT_KEY, anchorOf, commentOf, commentsOf, formatPosition, isComment, sameMedia, } from "./comments.js";
|
|
7
9
|
export { factoryLedgerPath, readFactoryReceipts, receiptsForRecord, recordsForSession } from "./factory-receipt.js";
|
|
8
10
|
export { classifyOutput, missionResult, } from "./mission-result.js";
|
|
9
11
|
export { runBrief, readQueueState } from "./approve.js";
|
package/dist/refs.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ChronicleAddress {
|
|
2
|
+
/** The episode's number: from a numeric form, or from the folder's own name. */
|
|
3
|
+
number: number | null;
|
|
4
|
+
/** The folder, when the address names the episode by it. */
|
|
5
|
+
folder: string | null;
|
|
6
|
+
/** What follows the episode (a file path, a query, a fragment), as written. */
|
|
7
|
+
rest: string;
|
|
8
|
+
}
|
|
9
|
+
/** A chronicle address as the episode it names and what follows; null for any other reference. */
|
|
10
|
+
export declare function parseChronicleAddress(ref: string): ChronicleAddress | null;
|
|
11
|
+
/**
|
|
12
|
+
* A test for "this reference names the same thing as `ref`". Two folders are
|
|
13
|
+
* compared as folders, because numbers collide and the folder is the key.
|
|
14
|
+
* A number and a folder agree when the folder carries that number.
|
|
15
|
+
*/
|
|
16
|
+
export declare function refMatcher(ref: string): (other: string) => boolean;
|
|
17
|
+
export declare function sameRef(a: string, b: string): boolean;
|
|
18
|
+
/** True when a record cites `ref`, in what it is about or in its evidence. */
|
|
19
|
+
export declare function cites(record: {
|
|
20
|
+
refs: readonly string[];
|
|
21
|
+
evidence_refs: readonly string[];
|
|
22
|
+
}, ref: string | ((other: string) => boolean)): boolean;
|
package/dist/refs.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One comparison of references, for every read (jgwill/Miadi#1093; W1 and C1 of
|
|
3
|
+
* rispecs/episode-participants/SPEC.md).
|
|
4
|
+
*
|
|
5
|
+
* The ledger keeps a reference as its author wrote it, and one episode has
|
|
6
|
+
* several written forms: `miadi-chronicle://92`, `miadi-chronicle://092`,
|
|
7
|
+
* `miadi-chronicle:92`, `chronicle:<folder>`. Miadi reads them as one episode
|
|
8
|
+
* (`matchSegment` in @miadi/inquiry-weave's chronicle-dsl). A read here does the
|
|
9
|
+
* same: a chronicle address is compared by the episode it names and by what
|
|
10
|
+
* follows the episode, never by its spelling. Every other reference is
|
|
11
|
+
* compared as written. Nothing in the ledger is rewritten.
|
|
12
|
+
*/
|
|
13
|
+
import { episodeNumberOf } from "./episode-files.js";
|
|
14
|
+
const CHRONICLE = /^(?:miadi-chronicle|chronicle):(?:\/\/)?([^/?#\s]+)\/?(\S*)$/i;
|
|
15
|
+
/** The numeric forms Miadi's file door takes: 92, 092, ep92, episode-092. */
|
|
16
|
+
const NUMBERED = /^(?:ep(?:isode)?[-_]?)?0*(\d{1,5})$/i;
|
|
17
|
+
/** A chronicle address as the episode it names and what follows; null for any other reference. */
|
|
18
|
+
export function parseChronicleAddress(ref) {
|
|
19
|
+
const m = CHRONICLE.exec(ref.trim());
|
|
20
|
+
if (!m)
|
|
21
|
+
return null;
|
|
22
|
+
const head = m[1];
|
|
23
|
+
const rest = m[2].replace(/\/$/, "");
|
|
24
|
+
const numbered = NUMBERED.exec(head);
|
|
25
|
+
if (numbered)
|
|
26
|
+
return { number: Number.parseInt(numbered[1], 10), folder: null, rest };
|
|
27
|
+
return { number: episodeNumberOf(head), folder: head, rest };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A test for "this reference names the same thing as `ref`". Two folders are
|
|
31
|
+
* compared as folders, because numbers collide and the folder is the key.
|
|
32
|
+
* A number and a folder agree when the folder carries that number.
|
|
33
|
+
*/
|
|
34
|
+
export function refMatcher(ref) {
|
|
35
|
+
const wanted = parseChronicleAddress(ref);
|
|
36
|
+
if (!wanted)
|
|
37
|
+
return (other) => other === ref;
|
|
38
|
+
return (other) => {
|
|
39
|
+
if (other === ref)
|
|
40
|
+
return true;
|
|
41
|
+
const found = parseChronicleAddress(other);
|
|
42
|
+
if (!found || found.rest !== wanted.rest)
|
|
43
|
+
return false;
|
|
44
|
+
if (wanted.folder && found.folder)
|
|
45
|
+
return wanted.folder === found.folder;
|
|
46
|
+
return wanted.number !== null && wanted.number === found.number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function sameRef(a, b) {
|
|
50
|
+
return refMatcher(a)(b);
|
|
51
|
+
}
|
|
52
|
+
/** True when a record cites `ref`, in what it is about or in its evidence. */
|
|
53
|
+
export function cites(record, ref) {
|
|
54
|
+
const is = typeof ref === "string" ? refMatcher(ref) : ref;
|
|
55
|
+
return record.refs.some(is) || record.evidence_refs.some(is);
|
|
56
|
+
}
|
package/dist/tools.js
CHANGED
|
@@ -30,6 +30,8 @@ import { authorizationReceipt, authorizeProvider, CHOICE_PROVIDERS, isPersonId,
|
|
|
30
30
|
import { candidatesFor, CRITICALITIES, jevAdapter, modelPreflight, PREFLIGHT_CONTRACT, PREFLIGHT_VERSION, TASK_TYPES, } from "./model-preflight.js";
|
|
31
31
|
import { ShelfRefusal, listShelfArtefacts, readShelfArtefact } from "./research-shelf.js";
|
|
32
32
|
import { isShareRelation, shareTarget } from "./record-shares.js";
|
|
33
|
+
import { cites, parseChronicleAddress, refMatcher } from "./refs.js";
|
|
34
|
+
import { commentOf, commentsOf, formatPosition, isComment, sameMedia } from "./comments.js";
|
|
33
35
|
import { DELIVERY_STATES, readSteerDelivery, revokeInInbox, settlementOf, transcriptPathOf } from "./runtime-steer.js";
|
|
34
36
|
import { ADAPTERS, readFactoryConfig, runSteering, STEERING_CONTRACT_ID, steeringSupport } from "./steering-adapters.js";
|
|
35
37
|
import { checkGrant, isBusy, steerAttempts, steeringGrantOf, steeringRevoked, steerSession } from "./steer.js";
|
|
@@ -293,16 +295,18 @@ export function registerTools(server, ctx) {
|
|
|
293
295
|
return { person_id: person.id, name: person.name, client_id: auth.clientId, ...(client?.client_name ? { client_name: client.client_name } : {}) };
|
|
294
296
|
};
|
|
295
297
|
const approvalUrl = (id) => `${config.publicUrl}/approve/${encodeURIComponent(id)}`;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
r.idempotency_key ===
|
|
298
|
+
/** The record this person already made with this key, which the same key hands back instead of a duplicate. */
|
|
299
|
+
const priorOf = (kind, person, key) => key
|
|
300
|
+
? // A request already decided (approved, declined, sent back) is not handed back: the same key makes a new one.
|
|
301
|
+
all().find((r) => r.kind === kind &&
|
|
302
|
+
r.idempotency_key === key &&
|
|
301
303
|
r.actor.person_id === person.id &&
|
|
302
|
-
(r.approval_state === undefined || r.approval_state === "awaiting_approval" || r.approval_state === "not_required"))
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
304
|
+
(r.approval_state === undefined || r.approval_state === "awaiting_approval" || r.approval_state === "not_required"))
|
|
305
|
+
: undefined;
|
|
306
|
+
const append = (kind, person, auth, fields) => {
|
|
307
|
+
const prior = priorOf(kind, person, fields.idempotency_key);
|
|
308
|
+
if (prior)
|
|
309
|
+
return prior;
|
|
306
310
|
return ledger.append({
|
|
307
311
|
id: newRecordId(kind),
|
|
308
312
|
kind,
|
|
@@ -393,7 +397,11 @@ export function registerTools(server, ctx) {
|
|
|
393
397
|
};
|
|
394
398
|
};
|
|
395
399
|
const uploads = new ResearchUploads(join(config.stateDir, "uploads"));
|
|
396
|
-
|
|
400
|
+
/** The records that cite a reference. An episode's address is compared by the episode it names, whatever its written form (./refs.ts, jgwill/Miadi#1093). */
|
|
401
|
+
const touching = (ref) => {
|
|
402
|
+
const is = refMatcher(ref);
|
|
403
|
+
return records().filter((r) => cites(r, is) || r.id === ref);
|
|
404
|
+
};
|
|
397
405
|
/** The factory runner's delivery receipts, read fresh: operator data, for the write tier only. */
|
|
398
406
|
const receipts = () => readFactoryReceipts(factoryLedgerPath(ctx.factoryDir ?? defaultFactoryDir()));
|
|
399
407
|
/** The Claude Code models this host permits, and the one it falls back to (jgwill/Miadi#943). */
|
|
@@ -769,6 +777,113 @@ export function registerTools(server, ctx) {
|
|
|
769
777
|
count: docs.length,
|
|
770
778
|
};
|
|
771
779
|
};
|
|
780
|
+
// ── the comments of an episode (jgwill/Miadi#1093, rispecs/episode-participants) ──
|
|
781
|
+
/** Who reads a published comment, in words (D2's recommendation: what the ledger gives today). */
|
|
782
|
+
const COMMENT_READERS = "Every person signed in to Miadi who may open this episode reads it, on the episode's page and through this connector. A visitor does not.";
|
|
783
|
+
/**
|
|
784
|
+
* One episode as Miadi resolves it for this person: its folder (the key), its number, the address
|
|
785
|
+
* this connector emits for it, its page and its media files. Any written form names the same
|
|
786
|
+
* episode, and Miadi answers its own 404 for an episode the person may not open.
|
|
787
|
+
*/
|
|
788
|
+
const episodeFor = async (person, episode) => {
|
|
789
|
+
const listing = await miadi.get(person.token, `/api/chronicle/episodes/${checkedEpisodeRef(episode)}/files`);
|
|
790
|
+
const folder = typeof listing?.episode?.path === "string" ? listing.episode.path : null;
|
|
791
|
+
if (!folder)
|
|
792
|
+
throw new ToolRefusal("not_found", `No episode answers to ${episode}.`);
|
|
793
|
+
const number = typeof listing.episode.number === "number" ? listing.episode.number : episodeNumberOf(folder);
|
|
794
|
+
return {
|
|
795
|
+
folder,
|
|
796
|
+
number,
|
|
797
|
+
title: typeof listing.episode.title === "string" ? listing.episode.title : null,
|
|
798
|
+
route: encodeURIComponent(folder),
|
|
799
|
+
ref: number === null ? `chronicle:${folder}` : `miadi-chronicle://${number}`,
|
|
800
|
+
label: number === null ? folder : `Episode ${number}`,
|
|
801
|
+
page: `${config.miadiPublicUrl}/chronicle/${encodeURIComponent(folder)}#comments`,
|
|
802
|
+
media: (Array.isArray(listing.files) ? listing.files : []).filter((f) => f?.kind === "media").map((f) => String(f.relativePath)),
|
|
803
|
+
};
|
|
804
|
+
};
|
|
805
|
+
/**
|
|
806
|
+
* A comment by a person seated in the episode's Root Circle is also a turn in its main ceremony
|
|
807
|
+
* (D12; Guillaume, 2026-11-23: "When a user comments, does that go on a talking circle for the
|
|
808
|
+
* episode? That could make sense."). It is said with the commenter's own token at the door a seated
|
|
809
|
+
* person speaks at, so Miadi applies its own seat rule, and the arrival wall shows it to the members.
|
|
810
|
+
* The comment stays the record and keeps the turn's id, so a repeated key never speaks twice.
|
|
811
|
+
* Nobody is seated and no circle is opened here. Whatever cannot happen is answered with its
|
|
812
|
+
* reason, and the comment stands.
|
|
813
|
+
*/
|
|
814
|
+
const sayInRootCircle = async (person, auth, record, episode) => {
|
|
815
|
+
try {
|
|
816
|
+
const comment = commentOf(record);
|
|
817
|
+
if (comment.circle_turn)
|
|
818
|
+
return { said: true, ...comment.circle_turn };
|
|
819
|
+
const circle = await miadi.request(person.token, "GET", `/api/chronicle/episodes/${episode.route}/circle`, undefined, 15_000);
|
|
820
|
+
const main = circle?.main;
|
|
821
|
+
const seated = Array.isArray(main?.circle?.members) && main.circle.members.some((m) => m?.person_id === person.id);
|
|
822
|
+
if (!main || !seated)
|
|
823
|
+
return { said: false, reason: `You do not sit in a Root Circle of ${episode.label}, so the comment is read on the episode's page and not in a circle.` };
|
|
824
|
+
const ceremonyId = typeof main.ceremony?.id === "string" ? main.ceremony.id : null;
|
|
825
|
+
if (!ceremonyId)
|
|
826
|
+
return { said: false, reason: `${main.circle.name ?? "The Root Circle"} has no open ceremony to speak in.` };
|
|
827
|
+
const at = comment.anchor?.at_seconds ?? null;
|
|
828
|
+
const where = [episode.ref, comment.anchor?.media ? `${comment.anchor.media}${at === null ? "" : ` at ${formatPosition(at)}`}` : null].filter(Boolean).join(" · ");
|
|
829
|
+
const answer = await miadi.post(person.token, `/api/ceremony/${encodeURIComponent(ceremonyId)}/turns`, {
|
|
830
|
+
said: [comment.text, where, record.id].join("\n\n"),
|
|
831
|
+
title: `${person.name} comments on ${episode.label}`.slice(0, 120),
|
|
832
|
+
});
|
|
833
|
+
const beatId = typeof answer?.turn?.id === "string" ? answer.turn.id : null;
|
|
834
|
+
if (!beatId)
|
|
835
|
+
return { said: false, reason: "The circle answered without a turn." };
|
|
836
|
+
const turn = {
|
|
837
|
+
ceremony_id: ceremonyId,
|
|
838
|
+
beat_id: beatId,
|
|
839
|
+
...(typeof main.circle.id === "string" ? { circle_id: main.circle.id } : {}),
|
|
840
|
+
...(typeof main.circle.name === "string" ? { circle_name: main.circle.name } : {}),
|
|
841
|
+
at: typeof answer.turn.timestamp === "string" ? answer.turn.timestamp : new Date().toISOString(),
|
|
842
|
+
};
|
|
843
|
+
ledger.append({
|
|
844
|
+
id: newRecordId("observation"),
|
|
845
|
+
kind: "observation",
|
|
846
|
+
created_at: new Date().toISOString(),
|
|
847
|
+
actor: actorOf(person, auth),
|
|
848
|
+
refs: record.refs,
|
|
849
|
+
evidence_refs: record.evidence_refs,
|
|
850
|
+
supersedes: record.id,
|
|
851
|
+
completion_receipt: { ...(record.completion_receipt ?? {}), circle_turn: turn },
|
|
852
|
+
body: {},
|
|
853
|
+
});
|
|
854
|
+
return { said: true, ...turn };
|
|
855
|
+
}
|
|
856
|
+
catch (error) {
|
|
857
|
+
const refused = error instanceof MiadiError && error.body && typeof error.body === "object" ? error.body.error : undefined;
|
|
858
|
+
return { said: false, reason: `The Root Circle did not take the turn: ${typeof refused === "string" ? refused : asState(error).state}.` };
|
|
859
|
+
}
|
|
860
|
+
};
|
|
861
|
+
server.registerTool("list_episode_comments", {
|
|
862
|
+
title: "The comments on an episode",
|
|
863
|
+
description: "The comments people published on one Chronicle episode: each with its author, its text, when it was published and where it points (the media file and the position in seconds, when it has them), and the turn it became in the episode's Root Circle when its author sits there. Narrow it to one media file, a span of positions or one author. Ordered by media file, then position, then time. A comment is published with comment_on_episode; the comments a Space published earlier with append_observation are read too.",
|
|
864
|
+
inputSchema: {
|
|
865
|
+
episode: z.string().min(1).describe("miadi-chronicle://<n>, an episode number or its folder. Every written form names the same episode."),
|
|
866
|
+
media: z.string().max(500).optional().describe("One media file, by its path inside the episode as get_evidence lists it."),
|
|
867
|
+
from_seconds: z.number().min(0).optional(),
|
|
868
|
+
to_seconds: z.number().min(0).optional(),
|
|
869
|
+
person_id: z.string().optional().describe("Only this person's comments."),
|
|
870
|
+
limit: z.number().int().min(1).max(200).optional(),
|
|
871
|
+
},
|
|
872
|
+
annotations: READ,
|
|
873
|
+
}, wrap(async (a, extra) => {
|
|
874
|
+
const { person } = who(extra);
|
|
875
|
+
const ep = await episodeFor(person, a.episode);
|
|
876
|
+
const found = commentsOf(records(), { number: ep.number, folder: ep.folder }, { media: a.media, from_seconds: a.from_seconds, to_seconds: a.to_seconds, person_id: a.person_id });
|
|
877
|
+
const comments = found.slice(0, a.limit ?? 100);
|
|
878
|
+
return {
|
|
879
|
+
episode: { ref: ep.ref, number: ep.number, folder: ep.folder, title: ep.title },
|
|
880
|
+
comments,
|
|
881
|
+
count: comments.length,
|
|
882
|
+
total: found.length,
|
|
883
|
+
shown_at: ep.page,
|
|
884
|
+
readable_by: COMMENT_READERS,
|
|
885
|
+
};
|
|
886
|
+
}));
|
|
772
887
|
const readEpisodeFile = async (person, a) => {
|
|
773
888
|
const path = a.path.trim();
|
|
774
889
|
const segments = checkRelativePath(path);
|
|
@@ -885,7 +1000,7 @@ export function registerTools(server, ctx) {
|
|
|
885
1000
|
}, wrap(async ({ episode, subject_ref }, extra) => {
|
|
886
1001
|
const { person } = who(extra);
|
|
887
1002
|
const evals = records().filter((r) => r.kind === "observation" && typeof r.body?.assessment === "string");
|
|
888
|
-
const scoped = subject_ref ? evals.filter((r) => r.refs.
|
|
1003
|
+
const scoped = subject_ref ? evals.filter((r) => r.refs.some(refMatcher(subject_ref))) : evals;
|
|
889
1004
|
return {
|
|
890
1005
|
tracing: episode ? await miadi.get(person.token, `/api/chronicle/episodes/${episodeRef(episode)}/tracing`).catch(asState) : "give an episode to read its tracing records",
|
|
891
1006
|
operational: scoped.filter((r) => r.body.assessment === "operational"),
|
|
@@ -1011,8 +1126,10 @@ export function registerTools(server, ctx) {
|
|
|
1011
1126
|
}, wrap(async ({ ref, circle: c, state }, extra) => {
|
|
1012
1127
|
who(extra);
|
|
1013
1128
|
let list = records().filter((r) => r.kind === "handoff" || r.kind === "source_intent");
|
|
1014
|
-
if (ref)
|
|
1015
|
-
|
|
1129
|
+
if (ref) {
|
|
1130
|
+
const is = refMatcher(ref);
|
|
1131
|
+
list = list.filter((r) => r.id === ref || cites(r, is));
|
|
1132
|
+
}
|
|
1016
1133
|
if (c)
|
|
1017
1134
|
list = list.filter((r) => r.to_circle === c || r.circle === c);
|
|
1018
1135
|
if (state)
|
|
@@ -1026,7 +1143,7 @@ export function registerTools(server, ctx) {
|
|
|
1026
1143
|
inputSchema: {
|
|
1027
1144
|
kind: z.string().optional(),
|
|
1028
1145
|
circle: circle.optional(),
|
|
1029
|
-
ref: z.string().optional(),
|
|
1146
|
+
ref: z.string().optional().describe("A reference the records cite. An episode's address finds them under any written form: miadi-chronicle://92 and miadi-chronicle://092 name one episode."),
|
|
1030
1147
|
person_id: z.string().optional(),
|
|
1031
1148
|
limit: z.number().int().min(1).max(200).optional(),
|
|
1032
1149
|
},
|
|
@@ -1038,8 +1155,10 @@ export function registerTools(server, ctx) {
|
|
|
1038
1155
|
list = list.filter((r) => r.kind === a.kind);
|
|
1039
1156
|
if (a.circle)
|
|
1040
1157
|
list = list.filter((r) => r.circle === a.circle || r.to_circle === a.circle);
|
|
1041
|
-
if (a.ref)
|
|
1042
|
-
|
|
1158
|
+
if (a.ref) {
|
|
1159
|
+
const is = refMatcher(a.ref);
|
|
1160
|
+
list = list.filter((r) => cites(r, is));
|
|
1161
|
+
}
|
|
1043
1162
|
if (a.person_id)
|
|
1044
1163
|
list = list.filter((r) => r.actor.person_id === a.person_id);
|
|
1045
1164
|
const out = list.reverse().slice(0, a.limit ?? 50);
|
|
@@ -1353,7 +1472,7 @@ export function registerTools(server, ctx) {
|
|
|
1353
1472
|
};
|
|
1354
1473
|
server.registerTool("append_observation", {
|
|
1355
1474
|
title: "Record an observation",
|
|
1356
|
-
description: "Record what was observed (or hypothesised, desired, imagined) about a source, in your name, with its claim category and the circle it concerns. Fiction and desired futures stay labelled as such.",
|
|
1475
|
+
description: "Record what was observed (or hypothesised, desired, imagined) about a source, in your name, with its claim category and the circle it concerns. Fiction and desired futures stay labelled as such. To comment on a Chronicle episode at a moment of its media, use comment_on_episode.",
|
|
1357
1476
|
inputSchema: {
|
|
1358
1477
|
text: z.string().min(1).max(20000),
|
|
1359
1478
|
claim_category: claim,
|
|
@@ -1368,7 +1487,7 @@ export function registerTools(server, ctx) {
|
|
|
1368
1487
|
}, wrap(async (a, extra) => {
|
|
1369
1488
|
const { person, auth } = who(extra);
|
|
1370
1489
|
requireContribute(auth);
|
|
1371
|
-
|
|
1490
|
+
const record = append("observation", person, auth, {
|
|
1372
1491
|
claim_category: a.claim_category,
|
|
1373
1492
|
circle: a.circle,
|
|
1374
1493
|
domain: a.domain,
|
|
@@ -1380,6 +1499,74 @@ export function registerTools(server, ctx) {
|
|
|
1380
1499
|
idempotency_key: a.idempotency_key,
|
|
1381
1500
|
body: { text: a.text },
|
|
1382
1501
|
});
|
|
1502
|
+
// A comment a Space publishes this way (./comments.ts) follows comment_on_episode's circle rule (jgwill/Miadi#1093).
|
|
1503
|
+
if (!isComment(record))
|
|
1504
|
+
return record;
|
|
1505
|
+
const address = record.refs.map(parseChronicleAddress).find((x) => x !== null);
|
|
1506
|
+
if (!address)
|
|
1507
|
+
return record;
|
|
1508
|
+
const head = address.folder ?? String(address.number);
|
|
1509
|
+
await sayInRootCircle(person, auth, record, {
|
|
1510
|
+
route: encodeURIComponent(head),
|
|
1511
|
+
ref: address.folder ? `chronicle:${address.folder}` : `miadi-chronicle://${address.number}`,
|
|
1512
|
+
label: address.number === null ? head : `Episode ${address.number}`,
|
|
1513
|
+
});
|
|
1514
|
+
return all().find((r) => r.id === record.id) ?? record;
|
|
1515
|
+
}));
|
|
1516
|
+
server.registerTool("comment_on_episode", {
|
|
1517
|
+
title: "Publish a comment on an episode",
|
|
1518
|
+
description: "Publishes a comment on one Chronicle episode, in your name: what you say about it, optionally at a position of one of its media files. It is read by every person signed in to Miadi who may open the episode, on the episode's page and with list_episode_comments. When you sit in the episode's Root Circle, it is also said there as a turn, in your name, and the circle's members see it on their arrival wall. Nothing is kept that is not published: a call either publishes the comment or refuses and writes nothing. Publish only on the person's own request to publish at Miadi.",
|
|
1519
|
+
inputSchema: {
|
|
1520
|
+
episode: z.string().min(1).describe("miadi-chronicle://<n>, an episode number or its folder. Every written form names the same episode."),
|
|
1521
|
+
text: z.string().min(1).max(20000),
|
|
1522
|
+
media: z.string().max(500).optional().describe("The media file the comment is about, by its path inside the episode as get_evidence lists it (audio/…mp3). Leave it out for a comment on the whole episode."),
|
|
1523
|
+
at_seconds: z.number().min(0).optional().describe("The position in that media file, in seconds."),
|
|
1524
|
+
until_seconds: z.number().min(0).optional().describe("The end of the span, when the comment is about more than a moment."),
|
|
1525
|
+
claim_category: claim.optional().describe("observed (the default), hypothesis, desired_future, fiction or verified_implementation."),
|
|
1526
|
+
...base,
|
|
1527
|
+
},
|
|
1528
|
+
annotations: WRITE,
|
|
1529
|
+
}, wrap(async (a, extra) => {
|
|
1530
|
+
const { person, auth } = who(extra);
|
|
1531
|
+
requireContribute(auth);
|
|
1532
|
+
const ep = await episodeFor(person, a.episode);
|
|
1533
|
+
let media = null;
|
|
1534
|
+
if (a.media !== undefined) {
|
|
1535
|
+
const named = String(a.media).trim();
|
|
1536
|
+
checkRelativePath(named);
|
|
1537
|
+
const found = ep.media.filter((path) => sameMedia(path, named));
|
|
1538
|
+
if (found.length !== 1) {
|
|
1539
|
+
throw new ToolRefusal("invalid_path", found.length ? `${named} names ${found.length} media files of ${ep.label}. Give the whole path of one.` : `${named} is not a media file of ${ep.label}.`, { media: ep.media });
|
|
1540
|
+
}
|
|
1541
|
+
media = found[0];
|
|
1542
|
+
}
|
|
1543
|
+
const seconds = (v) => (typeof v === "number" ? Math.round(v * 1000) / 1000 : null);
|
|
1544
|
+
const at = seconds(a.at_seconds);
|
|
1545
|
+
const until = seconds(a.until_seconds);
|
|
1546
|
+
if (at !== null && !media)
|
|
1547
|
+
throw new ToolRefusal("invalid_position", "A position is a moment of one media file: name the file in media. A comment on the whole episode has neither.", { media: ep.media });
|
|
1548
|
+
if (until !== null && (at === null || until <= at))
|
|
1549
|
+
throw new ToolRefusal("invalid_position", "until_seconds ends a span that at_seconds starts, and is greater than it.");
|
|
1550
|
+
const repeated = Boolean(priorOf("observation", person, a.idempotency_key));
|
|
1551
|
+
const record = append("observation", person, auth, {
|
|
1552
|
+
claim_category: a.claim_category ?? "observed",
|
|
1553
|
+
refs: [ep.ref],
|
|
1554
|
+
intention: a.intention,
|
|
1555
|
+
role: a.role,
|
|
1556
|
+
idempotency_key: a.idempotency_key,
|
|
1557
|
+
body: { text: a.text, anchor: { episode: { folder: ep.folder, number: ep.number }, media, at_seconds: at, until_seconds: until } },
|
|
1558
|
+
});
|
|
1559
|
+
const circle_turn = await sayInRootCircle(person, auth, record, ep);
|
|
1560
|
+
const stored = all().find((r) => r.id === record.id) ?? record;
|
|
1561
|
+
return {
|
|
1562
|
+
published: true,
|
|
1563
|
+
...(repeated ? { repeated: true, note: "This key was already published. This is that comment; nothing new was written." } : {}),
|
|
1564
|
+
record: stored,
|
|
1565
|
+
comment: commentOf(stored),
|
|
1566
|
+
shows_at: ep.page,
|
|
1567
|
+
readable_by: COMMENT_READERS,
|
|
1568
|
+
circle_turn,
|
|
1569
|
+
};
|
|
1383
1570
|
}));
|
|
1384
1571
|
server.registerTool("open_inquiry", {
|
|
1385
1572
|
title: "Open an inquiry",
|
|
@@ -2987,6 +3174,8 @@ export const TOOL_STATUS = {
|
|
|
2987
3174
|
search: "live",
|
|
2988
3175
|
fetch: "live",
|
|
2989
3176
|
append_observation: "live, contribute",
|
|
3177
|
+
list_episode_comments: "live (the comments published on one episode, by media file and position; any written form of the episode's address)",
|
|
3178
|
+
comment_on_episode: "live, contribute (publishes a comment in your name on an episode, at a position of a media file when given; when you sit in the episode's Root Circle it is also said there as a turn)",
|
|
2990
3179
|
open_inquiry: "live, contribute",
|
|
2991
3180
|
link_records: "live, contribute",
|
|
2992
3181
|
propose_narrative_beat: "live, contribute",
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.
|
|
1
|
+
export declare const VERSION = "0.1.41";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.41";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miadi/connector",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
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",
|
|
@@ -40,6 +40,14 @@
|
|
|
40
40
|
"types": "./dist/record-shares.d.ts",
|
|
41
41
|
"import": "./dist/record-shares.js"
|
|
42
42
|
},
|
|
43
|
+
"./comments": {
|
|
44
|
+
"types": "./dist/comments.d.ts",
|
|
45
|
+
"import": "./dist/comments.js"
|
|
46
|
+
},
|
|
47
|
+
"./refs": {
|
|
48
|
+
"types": "./dist/refs.d.ts",
|
|
49
|
+
"import": "./dist/refs.js"
|
|
50
|
+
},
|
|
43
51
|
"./package.json": "./package.json"
|
|
44
52
|
},
|
|
45
53
|
"bin": {
|
|
@@ -53,9 +61,9 @@
|
|
|
53
61
|
"dependencies": {
|
|
54
62
|
"@miadi/hooks-core": "^0.6.2",
|
|
55
63
|
"@miadi/hooks-gateway": "^0.2.1",
|
|
56
|
-
"@miadi/inquiry-weave": "0.
|
|
64
|
+
"@miadi/inquiry-weave": "0.19.1",
|
|
57
65
|
"@miadi/node-service-kit": "0.1.2",
|
|
58
|
-
"@miadi/relational-git-repository-mapper": "^0.
|
|
66
|
+
"@miadi/relational-git-repository-mapper": "^0.8.0",
|
|
59
67
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
60
68
|
"express": "^5.2.1",
|
|
61
69
|
"express-rate-limit": "^8.2.1",
|