@miadi/connector 0.1.36 → 0.1.38
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 +2 -1
- package/dist/approve.d.ts +1 -1
- package/dist/approve.js +58 -12
- package/dist/capabilities-html.d.ts +12 -0
- package/dist/capabilities-html.js +109 -0
- package/dist/capabilities.d.ts +262 -0
- package/dist/capabilities.js +429 -0
- package/dist/local-transcription.js +3 -3
- package/dist/mission-result.d.ts +15 -0
- package/dist/mission-result.js +18 -21
- package/dist/record-shares.d.ts +48 -0
- package/dist/record-shares.js +60 -0
- package/dist/research-shelf.d.ts +53 -14
- package/dist/research-shelf.js +83 -16
- package/dist/server.d.ts +4 -2
- package/dist/server.js +2 -1
- package/dist/tools.d.ts +2 -0
- package/dist/tools.js +101 -13
- package/dist/transcript-job.d.ts +7 -1
- package/dist/transcript-job.js +44 -9
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ Call `get_capabilities` first. It names the signed-in person, their Miadi API ti
|
|
|
29
29
|
- **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`.
|
|
30
30
|
- **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
31
|
- **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
|
+
- **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.
|
|
32
33
|
- **Requests** append a record that waits for a decision. The answer gives an `approval_url`; Miadi's `/research` page offers the same decisions to a signed-in person with the write tier, and `show_decisions` shows them as cards inside the conversation (below). The person approves, approves with changes (their instructions are carried into what runs), sends it back for revision with instructions (`revision_requested`, nothing runs, `get_run_result` returns the instructions), or declines. Only the approval door runs a request, once, as that person; a second decision on the same request, at the same time or later, is refused:
|
|
33
34
|
- a run becomes a brief in the factory queue, which the intake delivers to a session;
|
|
34
35
|
- a work proposal starts its work the same way, as a brief written from the proposal;
|
|
@@ -47,7 +48,7 @@ The model that asked cannot approve its own request.
|
|
|
47
48
|
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`.
|
|
48
49
|
|
|
49
50
|
- **`ensure_review_transcript`** starts one job per review. It needs a person who may contribute and who holds Miadi's write tier or registered the video's source. It asks no transcript decision and needs no pasted text: processing a review already carries that authority. It never overwrites, never creates a version and never publishes.
|
|
50
|
-
- **Order.** 1. The transcript the review service already holds is kept, read back and its digest recorded. 2. A source registered as withheld is held: nothing is read or stored until it is released. 3. The video's captions in its **spoken language** (the video's own `language`; YouTube auto-dubs a video into many languages and lists an `-orig` track for each dub, so the first `-orig` track is not taken, and a track in the wrong script is refused). 4. A transcription made on this host (`MIADI_TRANSCRIPT_LOCAL=faster-whisper`,
|
|
51
|
+
- **Order.** 1. The transcript the review service already holds is kept, read back and its digest recorded. 2. A source registered as withheld is held: nothing is read or stored until it is released. 3. The video's captions in its **spoken language** (the video's own `language`; YouTube auto-dubs a video into many languages and lists an `-orig` track for each dub, so the first `-orig` track is not taken, and a track in the wrong script is refused). 4. A transcription of the video's audio made on this host when the video has no usable caption track (`MIADI_TRANSCRIPT_LOCAL=faster-whisper`, one at a time, at most `MIADI_TRANSCRIPT_LOCAL_MAX_MINUTES` minutes). It runs for every review, because each job starts from an authority that covers processing it: the `review.created` fact, a person with the write tier or the source's registrant, or an approved mission. A withheld source is held before this step. Three attempts that produce no transcript end the job as `local_transcription_failed` with the last answer. On a host where it is off, the job keeps retrying and its failure names the operator. No model service is called and nothing costs money. 5. One `POST /api/reviews/{id}/transcript` with `overwrite: false` and the words' provenance. 6. A readback of the stored text, whose sha256 must match what was sent.
|
|
51
52
|
- **Progress and failure.** The answer comes within about 20 seconds with the job's state and goes on if it needs longer. `review_transcript_status` (read-only; `verify: true` reads the transcript back now) says `unknown`, `absent`, `acquiring`, `stored`, `held` or `failed`, with the stages, the attempts, `next_attempt_at` and `give_up_at`, the digest and coverage of what is stored, and for a failure its code, the remedy and who can do it (`operator`, `source_owner`). Captions that YouTube has not made yet are tried every 15 minutes for three days. A job a restart interrupted resumes from its receipt; a held job resumes when its source is released.
|
|
52
53
|
- **Links that need no card.** Every answer carries plain links: `status` (`/transcripts/<review id>`, a page that asks for a Miadi person token, or JSON with `Authorization: Bearer` and `?format=json`), `review`, `transcript_api` (the review service, with its token) and `job` (the job's record). `decision` is `null`: no decision stands between the request and the store. `review_lookup` and `review_versions` carry the same `transcript` state, and `show_decisions` and `get_run_result` answer with a line and a link for each request, so a client that draws no card still shows where things stand.
|
|
53
54
|
- **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.
|
package/dist/approve.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export interface ApprovalDeps {
|
|
|
53
53
|
modelRouting?: ModelRoutingDeps;
|
|
54
54
|
/** Reads a video's captions for an approved create; without it a create stores no transcript (tests, other embedders). */
|
|
55
55
|
captions?: FetchCaptions;
|
|
56
|
-
/** A transcription made on this host from the video's audio, tried
|
|
56
|
+
/** A transcription made on this host from the video's audio, tried when the video has no captions (jgwill/Miadi#995). */
|
|
57
57
|
localTranscription?: FetchCaptions;
|
|
58
58
|
/** The event folder (`MIADI_EVENTS_DIR`, default /srv/miadi/events): the ledger of facts and this connector's inbox. Absent, no fact is taken or announced. */
|
|
59
59
|
eventsDir?: string;
|
package/dist/approve.js
CHANGED
|
@@ -19,6 +19,7 @@ import { DEFAULT_DECISION_WAIT_MS } from "./config.js";
|
|
|
19
19
|
import { MiadiError } from "./miadi.js";
|
|
20
20
|
import { MiadiUnavailable } from "./people.js";
|
|
21
21
|
import { current, newRecordId } from "./records.js";
|
|
22
|
+
import { recordAccess, recordSharedWithACircle } from "./record-shares.js";
|
|
22
23
|
import { APPROVABLE, projectRequest } from "./request-state.js";
|
|
23
24
|
import { factoryDir, runBriefFile, readQueueState } from "./queue-state.js";
|
|
24
25
|
import { factoryLedgerPath, readFactoryReceipts, receiptsForRecord } from "./factory-receipt.js";
|
|
@@ -33,6 +34,8 @@ import { settleTranscriptRequests } from "./transcript-intake.js";
|
|
|
33
34
|
import { announceTranscriptOutcome, transcriptInbox } from "./review-events.js";
|
|
34
35
|
import { ReviewClient } from "./reviews.js";
|
|
35
36
|
import { sourceWordsOf } from "./source-words.js";
|
|
37
|
+
import { capabilitiesLine, changedOf, completionEffect, declaredOf, landHoldings } from "./capabilities.js";
|
|
38
|
+
import { CAPABILITY_CSS, capabilitiesSection } from "./capabilities-html.js";
|
|
36
39
|
import { canReadReading } from "./reading/privacy.js";
|
|
37
40
|
import { authorizationReceipt, authorizeProvider, briefAttributes, CHOICE_TTL_MS, CODEX_POLICIES, isPersonId, needsPersonChoice, HOST_ORDER, providerPolicyOf, } from "./provider-policy.js";
|
|
38
41
|
export { factoryDir, runBriefFile, readQueueState } from "./queue-state.js";
|
|
@@ -104,7 +107,7 @@ function text(v) {
|
|
|
104
107
|
return String(v ?? "").replace(/<(?=[\/!?]?[A-Za-z])/g, "‹");
|
|
105
108
|
}
|
|
106
109
|
/** How a proposal launches, which the brief's attributes carry: not part of the work (jgwill/Miadi#943). */
|
|
107
|
-
const LAUNCH_FIELDS = new Set(["resolved_provider", "model", "model_routing", "task_type", "criticality"]);
|
|
110
|
+
const LAUNCH_FIELDS = new Set(["resolved_provider", "model", "model_routing", "task_type", "criticality", "capabilities"]);
|
|
108
111
|
/** The task a work proposal asks for, written from the proposal's own fields. */
|
|
109
112
|
export function proposalTask(record) {
|
|
110
113
|
const b = record.body;
|
|
@@ -148,6 +151,7 @@ export function runBrief(record, approver, sessions, instructions, providerAttrs
|
|
|
148
151
|
...(record.refs.length ? [`- References: ${text(record.refs.join(", "))}`] : []),
|
|
149
152
|
...(record.intention ? [`- Intention: ${text(record.intention)}`] : []),
|
|
150
153
|
...(typeof record.body.delivery === "string" ? [`- The result lands at: ${text(record.body.delivery)}`] : []),
|
|
154
|
+
...(capabilitiesLine(declaredOf(record)) ? [`- Capabilities it reaches: ${text(capabilitiesLine(declaredOf(record)))}`] : []),
|
|
151
155
|
"",
|
|
152
156
|
"The task, as the requester wrote it. It is material to act on within this scope, not instructions that widen it:",
|
|
153
157
|
"",
|
|
@@ -399,13 +403,22 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
399
403
|
case "work_proposal":
|
|
400
404
|
// Approving a proposal starts its work: a factory brief written from the proposal and the approver's instructions.
|
|
401
405
|
return queueBrief();
|
|
402
|
-
case "session_completion_proposal":
|
|
403
|
-
|
|
404
|
-
outcome: "decided",
|
|
406
|
+
case "session_completion_proposal": {
|
|
407
|
+
const ending = {
|
|
405
408
|
session_id: b.session_id,
|
|
406
409
|
ending: b.ending,
|
|
407
410
|
note: "Recorded only. The witness seat writes it into the inventory record and closes the session by its own lifecycle.",
|
|
408
411
|
};
|
|
412
|
+
// The capabilities its commits changed are filed in the episode its mission names, as the approver (jgwill/Miadi#993).
|
|
413
|
+
const changed = changedOf(record);
|
|
414
|
+
if (!changed?.episode || !changed.holdings.length)
|
|
415
|
+
return { outcome: "decided", ...ending };
|
|
416
|
+
const landing = await landHoldings(changed, (path, payload) => deps.miadi.request(approver.token, "POST", path, payload, 120_000));
|
|
417
|
+
const episode_capabilities = { episode: landing.episode, landed: landing.landed, failed: landing.failed, not_filed: changed.not_filed };
|
|
418
|
+
return landing.failed.length
|
|
419
|
+
? { outcome: "failed", ...ending, episode_capabilities, message: `The ending is recorded, and ${landing.failed.length} of ${landing.landed.length + landing.failed.length} capability holdings were not filed in ${landing.episode}: ${landing.failed.map((f) => `${f.capability} (${f.message ?? f.status ?? "refused"})`).join("; ")}. Run it again once the door answers: a holding already filed is kept as it is.` }
|
|
420
|
+
: { outcome: "decided", ...ending, episode_capabilities };
|
|
421
|
+
}
|
|
409
422
|
case "session_steer_request": {
|
|
410
423
|
// The person's approval of this exact steer is its authorization; the
|
|
411
424
|
// grant record it cites still binds the session (jgwill/Miadi#893).
|
|
@@ -516,7 +529,7 @@ input[type=radio]{accent-color:var(--accent);flex:0 0 auto;margin:.3rem 0 0}
|
|
|
516
529
|
.wordsLabel{margin-bottom:.1rem}
|
|
517
530
|
blockquote{margin:.2rem 0 .6rem;padding-left:.8rem;border-left:2px solid var(--line);overflow-wrap:anywhere}
|
|
518
531
|
@media (prefers-color-scheme:dark){.err{color:#ff8a80}}
|
|
519
|
-
</style></head><body><main>${body}</main></body></html>`;
|
|
532
|
+
${CAPABILITY_CSS}</style></head><body><main>${body}</main></body></html>`;
|
|
520
533
|
}
|
|
521
534
|
function summary(r, o = {}) {
|
|
522
535
|
const shown = { ...r.body };
|
|
@@ -867,7 +880,10 @@ async function decideOnce(r, person, choice, deps, opts) {
|
|
|
867
880
|
};
|
|
868
881
|
let state = decision === "approved" ? "completed" : decision === "revision_requested" ? "pending" : "withdrawn";
|
|
869
882
|
if (decision === "approved") {
|
|
870
|
-
|
|
883
|
+
// An ending that files holdings in an episode lands one chronicle commit per holding: it is recorded as running first, so a restart
|
|
884
|
+
// mid-landing leaves a run a person may run again, never holdings filed under a decision nobody recorded (jgwill/Miadi#993).
|
|
885
|
+
const filesHoldings = r.kind === "session_completion_proposal" && Boolean(changedOf(r)?.episode && changedOf(r)?.holdings.length);
|
|
886
|
+
if (!RUNS_AT_ONCE.has(r.kind) || filesHoldings) {
|
|
871
887
|
// Written ahead of the run: the decision is in the ledger before anything is called, so a restart
|
|
872
888
|
// mid-run can never offer the request for a second approval, and every surface reads it as running (#924).
|
|
873
889
|
deps.ledger.append({
|
|
@@ -954,7 +970,7 @@ export function consequenceOf(r, authorization, records = [], steering) {
|
|
|
954
970
|
case "inquiry_episode_request":
|
|
955
971
|
return b.new_episode ? "Approving mints a new episode with the inquiry woven in." : `Approving weaves the inquiry into episode ${b.episode ?? "?"}.`;
|
|
956
972
|
case "session_completion_proposal":
|
|
957
|
-
return `Approving records the ending (${b.ending ?? "?"}) for the session. No pane is closed
|
|
973
|
+
return completionEffect(r, `Approving records the ending (${b.ending ?? "?"}) for the session. No pane is closed.`);
|
|
958
974
|
case "session_steer_request":
|
|
959
975
|
return `Approving types exactly this instruction into the bound agent session (${b.session ?? "the run's session"}), once, and records whether the agent accepted it.`;
|
|
960
976
|
default:
|
|
@@ -1129,7 +1145,8 @@ export function registerApprovalRoutes(app, deps) {
|
|
|
1129
1145
|
const again = replayed ? "<p>This decision was already recorded. Nothing ran again; here is where it stands.</p>" : "";
|
|
1130
1146
|
res.type("html").send(page("Recorded", `<h1>${heading}</h1>${again}${summary(find(r.id))}${projectionBlock(p, receipt)}${p?.stage === "recording" ? refreshForm(token) : ""}`));
|
|
1131
1147
|
});
|
|
1132
|
-
// A record's own page, for citations in ChatGPT
|
|
1148
|
+
// A record's own page, for citations in ChatGPT and for a click on its id: its author, the people and the
|
|
1149
|
+
// talking circles its author shared it with, and anyone with Miadi's read tier may read it (jgwill/Miadi#1005).
|
|
1133
1150
|
app.get("/records/:id", (req, res) => {
|
|
1134
1151
|
res.type("html").send(page("Miadi record", recordForm(String(req.params.id))));
|
|
1135
1152
|
});
|
|
@@ -1151,10 +1168,26 @@ export function registerApprovalRoutes(app, deps) {
|
|
|
1151
1168
|
if (!canReadReading(r, current(deps.ledger.all()), person)) {
|
|
1152
1169
|
return void res.status(403).type("html").send(page("Miadi record", recordForm(String(req.params.id), "This source and its reading are private to the source owner and factory operators.")));
|
|
1153
1170
|
}
|
|
1154
|
-
|
|
1155
|
-
|
|
1171
|
+
const ledger = current(deps.ledger.all());
|
|
1172
|
+
let circles;
|
|
1173
|
+
// The reader's circles are read only when a circle could admit them: the author and the read tier need none.
|
|
1174
|
+
if (r.actor.person_id !== person.id && !person.api_tier && recordSharedWithACircle(r, ledger)) {
|
|
1175
|
+
try {
|
|
1176
|
+
const b = (await deps.miadi.get(String((req.body ?? {}).person_token ?? "").trim(), "/api/circles"));
|
|
1177
|
+
circles = (b?.circles ?? []).filter((c) => c?.member === true && typeof c.id === "string").map((c) => c.id);
|
|
1178
|
+
}
|
|
1179
|
+
catch {
|
|
1180
|
+
return void res.status(503).type("html").send(page("Miadi record", recordForm(String(req.params.id), "Your talking circles could not be read from Miadi, so whether this record reaches you through one cannot be decided now. Try again in a minute.")));
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
const access = recordAccess(r, ledger, { id: person.id, api_tier: person.api_tier, circles });
|
|
1184
|
+
if (!access) {
|
|
1185
|
+
return void res.status(403).type("html").send(page("Miadi record", recordForm(String(req.params.id), `This record is read by its author, by the people and circles its author shares it with, and by Miadi's read tier; ${person.name} is none of these.`)));
|
|
1156
1186
|
}
|
|
1157
|
-
|
|
1187
|
+
const reached = access.as === "shared"
|
|
1188
|
+
? `<p>${access.routes.map((s) => escapeHtml(s.circle ? `Shared with the circle ${s.circle} by ${s.by}` : `Shared with you by ${s.by}`)).join("<br>")}</p>`
|
|
1189
|
+
: "";
|
|
1190
|
+
res.type("html").send(page("Miadi record", `<h1>${escapeHtml(r.kind)}</h1>${reached}${summary(r)}`));
|
|
1158
1191
|
});
|
|
1159
1192
|
}
|
|
1160
1193
|
/**
|
|
@@ -1479,6 +1512,18 @@ ${canAnswer && open.some((f) => f.settled_by === "drafter") ? `<p class="muted">
|
|
|
1479
1512
|
${canAnswer && open.length ? `<p class="muted">Approving as it stands starts the session, and the worker reads these questions with the task.</p>` : ""}
|
|
1480
1513
|
</section>`;
|
|
1481
1514
|
}
|
|
1515
|
+
const FILE_PLUS_PATHS = `<path d="M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/><path d="M14 19h6"/><path d="M17 16v6"/>`;
|
|
1516
|
+
/**
|
|
1517
|
+
* What approving does, then what declining does. An ending that files capability holdings in an episode says so on a line
|
|
1518
|
+
* of its own with its icon: it is the one consequence here that cannot be taken back (jgwill/Miadi#993).
|
|
1519
|
+
*/
|
|
1520
|
+
function effectParagraphs(effect) {
|
|
1521
|
+
const tail = "Declining records your refusal. Either is kept in the ledger with your name.";
|
|
1522
|
+
const at = effect.indexOf("Approving also files");
|
|
1523
|
+
if (at < 0)
|
|
1524
|
+
return `<p>${escapeHtml(effect)} ${tail}</p>`;
|
|
1525
|
+
return `<p>${escapeHtml(effect.slice(0, at).trim())}</p>${stateLine("Files holdings in an episode", FILE_PLUS_PATHS, `<strong>${escapeHtml(effect.slice(at))}</strong>`)}<p>${tail}</p>`;
|
|
1526
|
+
}
|
|
1482
1527
|
/** The request, and the decision form for a write-tier person (their token carried in the form they just signed into). */
|
|
1483
1528
|
function approvePage(deps, r, o = {}) {
|
|
1484
1529
|
const open = r.approval_state === "awaiting_approval";
|
|
@@ -1506,8 +1551,9 @@ ${projectionBlock(projectionOf(r, deps), open ? undefined : r.completion_receipt
|
|
|
1506
1551
|
${canDecideHere ? `<p>You are signed in. Nothing is approved until you press a button below.</p>` : ""}
|
|
1507
1552
|
${asksSomeone && open && o.token && deps.consentLink ? consentMailSection(r, deps) : ""}
|
|
1508
1553
|
${asksSomeone && open && (o.token || o.chooserToken) && deps.consentLink ? `<p><strong>The link to send ${escapeHtml(String(r.body.decider_name))}:</strong><br><a href="${escapeHtml(deps.consentLink(r.id))}" rel="noreferrer">${escapeHtml(deps.consentLink(r.id))}</a></p>` : ""}
|
|
1509
|
-
${actionable ?
|
|
1554
|
+
${actionable ? effectParagraphs(consequenceOf(r, authorization, current(deps.ledger.all()))) : ""}
|
|
1510
1555
|
${runSteeringLine(r, authorization?.provider ?? undefined, deps)}
|
|
1556
|
+
${capabilitiesSection(r, deps.config.miadiPublicUrl)}
|
|
1511
1557
|
${canDecideHere && r.intention ? `<p><strong>Intention:</strong> ${escapeHtml(r.intention)}</p>` : ""}
|
|
1512
1558
|
${authorization ? providerSection(r, authorization, actionable ? o.chooserToken : undefined) : ""}
|
|
1513
1559
|
${canDecideHere ? draftReviewSection(r, deps.draftReview?.stored(r), !blocked) : ""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ConnectorRecord } from "./records.js";
|
|
2
|
+
/** The rows' own rules, joined to the page's style block. */
|
|
3
|
+
export declare const CAPABILITY_CSS = "\n.caps{border:1px solid var(--line);border-radius:.4rem;padding:.8rem 1rem;margin:1rem 0}\n.caps h2{font-size:1rem;margin:0 0 .5rem}\n.caps h3{font-size:.95rem;font-weight:700;margin:1rem 0 .3rem}\n.caps ul{list-style:none;margin:.4rem 0;padding:0;display:grid;grid-template-columns:minmax(0,1fr);gap:.4rem}\n.caps li{min-width:0}\n.caps .row{display:flex;flex-wrap:nowrap;align-items:center;gap:.6rem;margin:0;min-height:40px;padding:3px 10px;border:1px solid var(--line);border-radius:.4rem;color:var(--fg);text-decoration:none;box-sizing:border-box}\n.caps .row svg{flex:0 0 auto}\n.caps .row .body{display:flex;flex-direction:column;flex:1;min-width:0}\n.caps .row .identity{color:var(--accent);font-family:ui-monospace,monospace;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n.caps .row.plain .identity{color:var(--muted)}\n.caps .row .how{display:flex;flex-wrap:wrap;column-gap:.5rem;color:var(--muted);font:.85rem ui-monospace,monospace;overflow-wrap:anywhere}\n.caps .row .how>*+*::before{content:\"\u00B7\";margin-right:.5rem;color:var(--muted);font-weight:400}\n.caps .row .how strong{color:var(--fg)}\n.caps a.row>svg:last-child{color:var(--accent)}\n.caps a.row:hover{background:color-mix(in srgb,var(--accent) 12%,transparent)}\n.caps a.row:active{transform:scale(.94)}\n.caps a.row:focus-visible{outline:2px solid var(--accent);outline-offset:2px}\n@media (prefers-reduced-motion:reduce){.caps a.row:active{transform:none}}\n.caps li.commit{display:grid;grid-template-columns:1rem 1fr;gap:.5rem;overflow-wrap:anywhere}\n.caps li.commit.unread .glyph,.caps li.commit.unread .facts,.caps p.warn .glyph{color:var(--err,#b00020)}\n.caps li.commit .facts{display:block;color:var(--muted);font-size:.85rem}\n.caps p.warn{display:grid;grid-template-columns:1rem 1fr;gap:.5rem;margin:.4rem 0}\n.caps .none{color:var(--muted);margin:.2rem 0}\n.state strong{color:var(--fg)}\n";
|
|
4
|
+
/** What a mission reaches, before the person decides. `base` is the address of Miadi that people open in a browser. */
|
|
5
|
+
export declare function missionCapabilitiesSection(r: ConnectorRecord, base: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* What a completion's commits changed, set against what its mission declared. What approving files is said once, in the
|
|
8
|
+
* sentence above the decision (consequenceOf); here only why nothing is filed, when nothing is.
|
|
9
|
+
*/
|
|
10
|
+
export declare function completionCapabilitiesSection(r: ConnectorRecord, base: string): string;
|
|
11
|
+
/** Both sections for the record's kind. */
|
|
12
|
+
export declare function capabilitiesSection(r: ConnectorRecord, base: string): string;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the approval page shows of capabilities (jgwill/Miadi#993, C7 and C8): the ones a mission
|
|
3
|
+
* reaches, each as a row that links its page with its relation, and for a completion the commits
|
|
4
|
+
* that were read and the three lists set against what the mission declared. Rows follow the
|
|
5
|
+
* signature of the other outbound rows on this page: a kind icon, the identity in the accent
|
|
6
|
+
* because it is the link, the arrow at the right edge. A capability the registry holds no row for
|
|
7
|
+
* is a row with no link: it opens nothing, so nothing in it is drawn as a link.
|
|
8
|
+
*/
|
|
9
|
+
import { escapeHtml } from "@miadi/node-service-kit/format";
|
|
10
|
+
import { changedOf, changedViewOf, chipsOf, declaredOf, } from "./capabilities.js";
|
|
11
|
+
const svg = (paths) => `<svg aria-hidden="true" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">${paths}</svg>`;
|
|
12
|
+
const glyph = (label, paths) => `<svg class="glyph" role="img" aria-label="${escapeHtml(label)}" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">${paths}</svg>`;
|
|
13
|
+
const ICONS = {
|
|
14
|
+
package: svg(`<path d="M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z"/><path d="M12 22V12"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="m7.5 4.27 9 5.15"/>`),
|
|
15
|
+
cli: svg(`<path d="M12 19h8"/><path d="m4 17 6-6-6-6"/>`),
|
|
16
|
+
skill: svg(`<path d="M12 7v14"/><path d="M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z"/>`),
|
|
17
|
+
};
|
|
18
|
+
const ARROW_UP_RIGHT = svg(`<path d="M7 7h10v10"/><path d="M7 17 17 7"/>`);
|
|
19
|
+
const ALERT = `<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/>`;
|
|
20
|
+
const STATE = {
|
|
21
|
+
read: { label: "Read", paths: `<circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/>` },
|
|
22
|
+
"no capability row": { label: "No capability row", paths: `<circle cx="12" cy="12" r="10"/><path d="M8 12h8"/>` },
|
|
23
|
+
unread: { label: "Unread", paths: ALERT },
|
|
24
|
+
};
|
|
25
|
+
/** The rows' own rules, joined to the page's style block. */
|
|
26
|
+
export const CAPABILITY_CSS = `
|
|
27
|
+
.caps{border:1px solid var(--line);border-radius:.4rem;padding:.8rem 1rem;margin:1rem 0}
|
|
28
|
+
.caps h2{font-size:1rem;margin:0 0 .5rem}
|
|
29
|
+
.caps h3{font-size:.95rem;font-weight:700;margin:1rem 0 .3rem}
|
|
30
|
+
.caps ul{list-style:none;margin:.4rem 0;padding:0;display:grid;grid-template-columns:minmax(0,1fr);gap:.4rem}
|
|
31
|
+
.caps li{min-width:0}
|
|
32
|
+
.caps .row{display:flex;flex-wrap:nowrap;align-items:center;gap:.6rem;margin:0;min-height:40px;padding:3px 10px;border:1px solid var(--line);border-radius:.4rem;color:var(--fg);text-decoration:none;box-sizing:border-box}
|
|
33
|
+
.caps .row svg{flex:0 0 auto}
|
|
34
|
+
.caps .row .body{display:flex;flex-direction:column;flex:1;min-width:0}
|
|
35
|
+
.caps .row .identity{color:var(--accent);font-family:ui-monospace,monospace;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
36
|
+
.caps .row.plain .identity{color:var(--muted)}
|
|
37
|
+
.caps .row .how{display:flex;flex-wrap:wrap;column-gap:.5rem;color:var(--muted);font:.85rem ui-monospace,monospace;overflow-wrap:anywhere}
|
|
38
|
+
.caps .row .how>*+*::before{content:"·";margin-right:.5rem;color:var(--muted);font-weight:400}
|
|
39
|
+
.caps .row .how strong{color:var(--fg)}
|
|
40
|
+
.caps a.row>svg:last-child{color:var(--accent)}
|
|
41
|
+
.caps a.row:hover{background:color-mix(in srgb,var(--accent) 12%,transparent)}
|
|
42
|
+
.caps a.row:active{transform:scale(.94)}
|
|
43
|
+
.caps a.row:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
|
|
44
|
+
@media (prefers-reduced-motion:reduce){.caps a.row:active{transform:none}}
|
|
45
|
+
.caps li.commit{display:grid;grid-template-columns:1rem 1fr;gap:.5rem;overflow-wrap:anywhere}
|
|
46
|
+
.caps li.commit.unread .glyph,.caps li.commit.unread .facts,.caps p.warn .glyph{color:var(--err,#b00020)}
|
|
47
|
+
.caps li.commit .facts{display:block;color:var(--muted);font-size:.85rem}
|
|
48
|
+
.caps p.warn{display:grid;grid-template-columns:1rem 1fr;gap:.5rem;margin:.4rem 0}
|
|
49
|
+
.caps .none{color:var(--muted);margin:.2rem 0}
|
|
50
|
+
.state strong{color:var(--fg)}
|
|
51
|
+
`;
|
|
52
|
+
const sha7 = (commit) => commit.replace(/@([0-9a-f]{7,40})$/i, (_, sha) => `@${sha.slice(0, 7)}`);
|
|
53
|
+
function row(chip, base, how) {
|
|
54
|
+
const facts = [chip.kind, ...(how ?? [chip.relation.replace(/-/g, " ")]), ...(chip.in_registry ? [] : ["no row yet"]), ...(chip.dependents !== undefined ? [`${chip.dependents} dependent${chip.dependents === 1 ? "" : "s"}`] : [])];
|
|
55
|
+
const inner = `${ICONS[chip.kind] ?? ICONS.package}<span class="body"><span class="identity">${escapeHtml(chip.name)}</span><span class="how">${facts.map((f) => (typeof f === "string" ? `<span>${escapeHtml(f)}</span>` : `<strong>${escapeHtml(f.strong)}</strong>`)).join("")}</span></span>`;
|
|
56
|
+
// A capability page opens in a new tab: the arrow says "open elsewhere", and a decision's typed words stay where they are.
|
|
57
|
+
return chip.in_registry
|
|
58
|
+
? `<li><a class="row" href="${escapeHtml(`${base}${chip.route}`)}" target="_blank" rel="noreferrer" title="${escapeHtml(chip.address)}">${inner}${ARROW_UP_RIGHT}</a></li>`
|
|
59
|
+
: `<li><span class="row plain" title="${escapeHtml(chip.address)}">${inner}</span></li>`;
|
|
60
|
+
}
|
|
61
|
+
function list(title, chips, base, how) {
|
|
62
|
+
return `<h3>${escapeHtml(title)} (${chips.length})</h3>${chips.length ? `<ul>${chips.map((c) => row(c, base, how(c))).join("")}</ul>` : `<p class="none">None.</p>`}`;
|
|
63
|
+
}
|
|
64
|
+
function commitItem(c) {
|
|
65
|
+
const s = STATE[c.state];
|
|
66
|
+
const what = c.state === "read" ? `${c.capabilities.length} capabilit${c.capabilities.length === 1 ? "y" : "ies"} changed` : c.state === "unread" ? `unread: ${c.reason ?? "it could not be read"}` : `no capability row: ${c.reason ?? "it changes no file that defines one"}`;
|
|
67
|
+
return `<li class="commit ${c.state === "unread" ? "unread" : ""}">${glyph(s.label, s.paths)}<span><span class="code">${escapeHtml(sha7(c.commit))}</span><span class="facts">${escapeHtml(what)}</span></span></li>`;
|
|
68
|
+
}
|
|
69
|
+
/** What a mission reaches, before the person decides. `base` is the address of Miadi that people open in a browser. */
|
|
70
|
+
export function missionCapabilitiesSection(r, base) {
|
|
71
|
+
const declared = declaredOf(r);
|
|
72
|
+
if (!declared.length)
|
|
73
|
+
return "";
|
|
74
|
+
const chips = chipsOf(declared);
|
|
75
|
+
return `<section class="caps" aria-label="Capabilities this mission reaches"><h2>Capabilities it reaches (${chips.length})</h2><ul>${chips.map((c) => row(c, base)).join("")}</ul></section>`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* What a completion's commits changed, set against what its mission declared. What approving files is said once, in the
|
|
79
|
+
* sentence above the decision (consequenceOf); here only why nothing is filed, when nothing is.
|
|
80
|
+
*/
|
|
81
|
+
export function completionCapabilitiesSection(r, base) {
|
|
82
|
+
const changed = changedOf(r);
|
|
83
|
+
if (!changed)
|
|
84
|
+
return "";
|
|
85
|
+
const v = changedViewOf(changed);
|
|
86
|
+
const unread = v.commits.filter((c) => c.state === "unread").length;
|
|
87
|
+
const notFiled = new Set(v.not_filed.map((c) => c.address));
|
|
88
|
+
const incomplete = unread > 0 || Boolean(v.partial_reason);
|
|
89
|
+
const summary = `${v.commits.length} commit${v.commits.length === 1 ? "" : "s"} named${unread ? `, ${unread} unread` : ", all read"}.`;
|
|
90
|
+
const warn = incomplete
|
|
91
|
+
? `<p class="warn">${glyph("Partial", ALERT)}<span>${escapeHtml(`${summary} ${v.partial_reason ?? "The lists leave out what an unread commit changed."}`)}</span></p>`
|
|
92
|
+
: `<p class="state">${glyph("All read", STATE.read.paths)}<span>${escapeHtml(summary)}</span></p>`;
|
|
93
|
+
return `<section class="caps" aria-label="What its commits changed"><h2>What its commits changed</h2>
|
|
94
|
+
${warn}
|
|
95
|
+
<ul>${v.commits.map(commitItem).join("")}</ul>
|
|
96
|
+
${list("Declared and changed", v.declared_and_changed, base, (c) => [`declared ${c.relation.replace(/-/g, " ")}`, c.relation === "uses" ? "changed, filed as revises" : "changed"])}
|
|
97
|
+
${list("Declared and not changed", v.declared_not_changed, base, (c) => [`declared ${c.relation.replace(/-/g, " ")}`, "unchanged", ...(notFiled.has(c.address) ? [{ strong: "not filed" }] : [])])}
|
|
98
|
+
${list("Changed and not declared", v.changed_not_declared, base, () => ["changed by a commit"])}
|
|
99
|
+
${v.episode_note ? `<p class="muted">${escapeHtml(`Nothing is filed in an episode: ${v.episode_note}.`)}</p>` : ""}
|
|
100
|
+
</section>`;
|
|
101
|
+
}
|
|
102
|
+
/** Both sections for the record's kind. */
|
|
103
|
+
export function capabilitiesSection(r, base) {
|
|
104
|
+
if (r.kind === "run_request" || r.kind === "work_proposal")
|
|
105
|
+
return missionCapabilitiesSection(r, base);
|
|
106
|
+
if (r.kind === "session_completion_proposal")
|
|
107
|
+
return completionCapabilitiesSection(r, base);
|
|
108
|
+
return "";
|
|
109
|
+
}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capabilities in a mission and in its completion (jgwill/Miadi#993, C6 to C10).
|
|
3
|
+
*
|
|
4
|
+
* A mission names the capabilities it reaches: `uses`, `revises`,
|
|
5
|
+
* `brings-into-being`, each by its `miadi-capability://` address, checked against
|
|
6
|
+
* the registry (`@miadi/relational-git-repository-mapper`'s `findCapability`).
|
|
7
|
+
* Its completion names the capabilities its commits changed, read from the
|
|
8
|
+
* commits themselves (`capabilitiesOfCommit` on a clone of the repository) and
|
|
9
|
+
* set against what the mission declared, never from the agent's own account.
|
|
10
|
+
* Approving a completion files the holdings in the episode the mission names.
|
|
11
|
+
*
|
|
12
|
+
* This file holds the pure parts: resolving, comparing, the sentences a person
|
|
13
|
+
* reads before the click, and the missions a capability has. The ledger and the
|
|
14
|
+
* Miadi door are the callers' (tools.ts, approve.ts, Miadi's /research).
|
|
15
|
+
*/
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import { type CommitCapabilities, type PackageReading } from "@miadi/relational-git-repository-mapper";
|
|
18
|
+
import type { ConnectorRecord } from "./records.js";
|
|
19
|
+
export declare const CAPABILITY_RELATIONS: readonly ["uses", "revises", "brings-into-being"];
|
|
20
|
+
export type CapabilityRelation = (typeof CAPABILITY_RELATIONS)[number];
|
|
21
|
+
export declare const MAX_CAPABILITIES = 20;
|
|
22
|
+
/** What a tool accepts: the address and how the mission reaches it. */
|
|
23
|
+
export declare const capabilitiesInput: z.ZodArray<z.ZodObject<{
|
|
24
|
+
address: z.ZodString;
|
|
25
|
+
relation: z.ZodEnum<{
|
|
26
|
+
uses: "uses";
|
|
27
|
+
revises: "revises";
|
|
28
|
+
"brings-into-being": "brings-into-being";
|
|
29
|
+
}>;
|
|
30
|
+
}, z.core.$strip>>;
|
|
31
|
+
/** A capability as a mission stores it. */
|
|
32
|
+
export interface DeclaredCapability {
|
|
33
|
+
/** `miadi-capability://<owner>/<repo>/<kind>/<name>` */
|
|
34
|
+
address: string;
|
|
35
|
+
relation: CapabilityRelation;
|
|
36
|
+
kind: string;
|
|
37
|
+
name: string;
|
|
38
|
+
/** whether the registry held a row for it when the mission named it */
|
|
39
|
+
in_registry: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface CapabilityRefusal {
|
|
42
|
+
address: string;
|
|
43
|
+
code: "not_an_address" | "not_in_registry" | "named_twice" | "registry_unreadable";
|
|
44
|
+
message: string;
|
|
45
|
+
}
|
|
46
|
+
type Parts = {
|
|
47
|
+
owner: string;
|
|
48
|
+
repo: string;
|
|
49
|
+
kind: string;
|
|
50
|
+
name: string;
|
|
51
|
+
};
|
|
52
|
+
export type CapabilityFinder = (parts: Parts) => unknown;
|
|
53
|
+
/** The key two spellings of one address share: owner and repository are case-folded, as the registry compares them. */
|
|
54
|
+
export declare function capabilityKey(address: string): string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Each declared address resolved against the registry. A refusal names the address;
|
|
57
|
+
* the caller stores nothing when any exists. A capability named twice is refused, so
|
|
58
|
+
* a mission says once how it reaches each.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveCapabilities(input: ReadonlyArray<{
|
|
61
|
+
address: string;
|
|
62
|
+
relation: CapabilityRelation;
|
|
63
|
+
}>, find?: CapabilityFinder): {
|
|
64
|
+
declared: DeclaredCapability[];
|
|
65
|
+
refused: CapabilityRefusal[];
|
|
66
|
+
};
|
|
67
|
+
/** The declared capabilities a request record stores, read back tolerantly. */
|
|
68
|
+
export declare function declaredOf(record: Pick<ConnectorRecord, "body"> | undefined): DeclaredCapability[];
|
|
69
|
+
/** The brief's line for the worker: how the mission reaches each capability. Undefined when it names none. */
|
|
70
|
+
export declare function capabilitiesLine(declared: readonly DeclaredCapability[]): string | undefined;
|
|
71
|
+
export interface CapabilityChip {
|
|
72
|
+
address: string;
|
|
73
|
+
relation: CapabilityRelation;
|
|
74
|
+
kind: string;
|
|
75
|
+
name: string;
|
|
76
|
+
/** `/capabilities/<owner>/<repo>/<kind>/<name>` */
|
|
77
|
+
route: string;
|
|
78
|
+
in_registry: boolean;
|
|
79
|
+
/** A package marked `revises`: the consumers `miadi-repomap impact <package> --bump minor` answers, at any depth. */
|
|
80
|
+
dependents?: number;
|
|
81
|
+
}
|
|
82
|
+
export declare function routeOf(address: string): string | undefined;
|
|
83
|
+
/** Each declared capability as a chip: its page, its relation and, for a revised package, its dependents. */
|
|
84
|
+
export declare function chipsOf(declared: readonly DeclaredCapability[], o?: {
|
|
85
|
+
packages?: () => readonly PackageReading[];
|
|
86
|
+
}): CapabilityChip[];
|
|
87
|
+
export type CommitState = "read" | "no capability row" | "unread";
|
|
88
|
+
export interface CommitReading {
|
|
89
|
+
/** the output as the agent submitted it */
|
|
90
|
+
ref: string;
|
|
91
|
+
/** `owner/repo@sha` */
|
|
92
|
+
commit: string;
|
|
93
|
+
/** the full sha, when the clone resolved it */
|
|
94
|
+
sha?: string;
|
|
95
|
+
state: CommitState;
|
|
96
|
+
/** why it was not read, in words that name no host path */
|
|
97
|
+
reason?: string;
|
|
98
|
+
reason_code?: string;
|
|
99
|
+
/** every file changed was a lockfile, or a package.json whose version and ranges alone moved */
|
|
100
|
+
skipped?: "versions-only";
|
|
101
|
+
files?: number;
|
|
102
|
+
capabilities: Array<{
|
|
103
|
+
address: string;
|
|
104
|
+
kind: string;
|
|
105
|
+
name: string;
|
|
106
|
+
version?: string; /** the commit moved this version */
|
|
107
|
+
version_changed?: boolean;
|
|
108
|
+
files: string[];
|
|
109
|
+
}>;
|
|
110
|
+
}
|
|
111
|
+
export interface HoldingPlan {
|
|
112
|
+
/** `miadi-capability://<owner>/<repo>/<kind>/<name>` */
|
|
113
|
+
capability: string;
|
|
114
|
+
relation: CapabilityRelation;
|
|
115
|
+
/** the version as read at the commit; absent when no commit read one */
|
|
116
|
+
version?: string;
|
|
117
|
+
/** `owner/repo@<sha>` of the commits that changed it, and `session:<uuid>` */
|
|
118
|
+
evidence: string[];
|
|
119
|
+
/** `changed`: a commit changed it. `declared`: the mission named it and no commit contradicts it. */
|
|
120
|
+
basis: "changed" | "declared";
|
|
121
|
+
}
|
|
122
|
+
export interface ChangedCapabilities {
|
|
123
|
+
read_at: string;
|
|
124
|
+
/** the mission record this completion closes, when it names one */
|
|
125
|
+
mission?: string;
|
|
126
|
+
commits: CommitReading[];
|
|
127
|
+
/** every commit was read: the three lists are whole. Otherwise a capability changed in an unread commit is missing from them. */
|
|
128
|
+
complete: boolean;
|
|
129
|
+
/** why the lists may be partial beyond an unread commit: a pull request names its commits through GitHub, which is not consulted */
|
|
130
|
+
partial_reason?: string;
|
|
131
|
+
declared_and_changed: Array<{
|
|
132
|
+
address: string;
|
|
133
|
+
relation: CapabilityRelation;
|
|
134
|
+
in_registry?: false;
|
|
135
|
+
}>;
|
|
136
|
+
declared_not_changed: Array<{
|
|
137
|
+
address: string;
|
|
138
|
+
relation: CapabilityRelation;
|
|
139
|
+
in_registry?: false;
|
|
140
|
+
}>;
|
|
141
|
+
changed_not_declared: Array<{
|
|
142
|
+
address: string;
|
|
143
|
+
}>;
|
|
144
|
+
/** `miadi-chronicle://<n>`: the one episode the mission names */
|
|
145
|
+
episode?: string;
|
|
146
|
+
/** why no holding is filed, when the mission names no episode or several */
|
|
147
|
+
episode_note?: string;
|
|
148
|
+
/** what approving files in the episode */
|
|
149
|
+
holdings: HoldingPlan[];
|
|
150
|
+
/** declared as revised or brought into being and shown by no commit: not filed */
|
|
151
|
+
not_filed: Array<{
|
|
152
|
+
address: string;
|
|
153
|
+
relation: CapabilityRelation;
|
|
154
|
+
in_registry?: false;
|
|
155
|
+
}>;
|
|
156
|
+
}
|
|
157
|
+
/** The outputs that name a commit: a commit URL (also one inside a pull request), `owner/repo@sha`, or a pull request or issue with the commit's sha in `git_sha`. A file's blob sha names no commit. */
|
|
158
|
+
export declare function commitOutputsOf(outputs: ReadonlyArray<{
|
|
159
|
+
ref: string;
|
|
160
|
+
git_sha?: string;
|
|
161
|
+
}>): Array<{
|
|
162
|
+
ref: string;
|
|
163
|
+
repository: string;
|
|
164
|
+
sha: string;
|
|
165
|
+
}>;
|
|
166
|
+
/** Where each repository's clone lives on this host: `MIADI_CONNECTOR_CLONES="owner/repo=/path,…"`; jgwill/Miadi defaults to `MIADI_SRC`, else the service's working folder. */
|
|
167
|
+
export declare function clonesFromEnv(env?: NodeJS.ProcessEnv): (repository: string) => string | undefined;
|
|
168
|
+
/** One submission reads at most this many commits: each is a handful of git calls on this host. */
|
|
169
|
+
export declare const MAX_COMMITS_READ = 10;
|
|
170
|
+
export interface ReadChangedInput {
|
|
171
|
+
outputs: ReadonlyArray<{
|
|
172
|
+
ref: string;
|
|
173
|
+
git_sha?: string;
|
|
174
|
+
}>;
|
|
175
|
+
sessionId: string;
|
|
176
|
+
/** the folded mission record, when the completion names one that exists */
|
|
177
|
+
mission?: ConnectorRecord;
|
|
178
|
+
missionId?: string;
|
|
179
|
+
clones: (repository: string) => string | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Whether holdings may be filed for this submission, with the reason when not. The caller decides by the rule a
|
|
182
|
+
* mission's result is read by: the mission is approved, the submission names it, ends a session it is bound to and
|
|
183
|
+
* was made with the write tier. Absent, filing is allowed (a caller that checked already).
|
|
184
|
+
*/
|
|
185
|
+
filing?: {
|
|
186
|
+
allowed: boolean;
|
|
187
|
+
reason?: string;
|
|
188
|
+
};
|
|
189
|
+
/** default: `capabilitiesOfCommit` over the registry's rows, read once, on a commit an origin branch holds */
|
|
190
|
+
readCommit?: (ref: string, clone: string) => CommitCapabilities;
|
|
191
|
+
now?: () => Date;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* What the commits of a completion changed, set against what its mission declared.
|
|
195
|
+
* Undefined when no output names a commit. Each commit is read by the mapper from the
|
|
196
|
+
* clone; a commit it cannot read is `unread` with the reason, and the comparison says
|
|
197
|
+
* it is not whole.
|
|
198
|
+
*/
|
|
199
|
+
export declare function readChangedCapabilities(i: ReadChangedInput): Promise<ChangedCapabilities | undefined>;
|
|
200
|
+
/** The stored `changed_capabilities` of a completion record, when it has a readable one. */
|
|
201
|
+
export declare function changedOf(record: Pick<ConnectorRecord, "body"> | undefined): ChangedCapabilities | undefined;
|
|
202
|
+
/** One sentence: what approving files in the episode, before the person clicks. Empty when nothing is filed. */
|
|
203
|
+
export declare function holdingsSentence(changed: ChangedCapabilities | undefined): string;
|
|
204
|
+
/** What approving a completion does, for the card, the approval page and /research. */
|
|
205
|
+
export declare function completionEffect(record: Pick<ConnectorRecord, "body">, base: string): string;
|
|
206
|
+
export interface CapabilityMission {
|
|
207
|
+
/** the record: a run request, a work proposal, or a session completion */
|
|
208
|
+
record: string;
|
|
209
|
+
kind: string;
|
|
210
|
+
title: string;
|
|
211
|
+
approval_state: string;
|
|
212
|
+
/** the record's state: `blocked` on an approved completion means its holdings were not all filed */
|
|
213
|
+
state?: string;
|
|
214
|
+
at: string;
|
|
215
|
+
/** how the mission declared it, for a run or a proposal */
|
|
216
|
+
declared?: CapabilityRelation;
|
|
217
|
+
/** a completion's commits changed it */
|
|
218
|
+
changed?: boolean;
|
|
219
|
+
/** the mission a completion closes */
|
|
220
|
+
mission?: string;
|
|
221
|
+
}
|
|
222
|
+
/** The connector's records that declared or changed one capability, newest first, each with its approval state. */
|
|
223
|
+
export declare function missionsOfCapability(records: readonly ConnectorRecord[], address: string): CapabilityMission[];
|
|
224
|
+
export interface ChangedView {
|
|
225
|
+
commits: CommitReading[];
|
|
226
|
+
complete: boolean;
|
|
227
|
+
declared_and_changed: CapabilityChip[];
|
|
228
|
+
declared_not_changed: CapabilityChip[];
|
|
229
|
+
changed_not_declared: CapabilityChip[];
|
|
230
|
+
episode?: string;
|
|
231
|
+
episode_note?: string;
|
|
232
|
+
holdings: HoldingPlan[];
|
|
233
|
+
/** declared as revised or brought into being and shown by no commit: listed, never filed */
|
|
234
|
+
not_filed: CapabilityChip[];
|
|
235
|
+
partial_reason?: string;
|
|
236
|
+
}
|
|
237
|
+
/** The three lists of a completion as chips, each with its page. */
|
|
238
|
+
export declare function changedViewOf(changed: ChangedCapabilities): ChangedView;
|
|
239
|
+
export interface LandedHolding {
|
|
240
|
+
capability: string;
|
|
241
|
+
relation: CapabilityRelation;
|
|
242
|
+
version?: string;
|
|
243
|
+
ok: boolean;
|
|
244
|
+
/** the door's answer: the HTTP status, or the failure */
|
|
245
|
+
status?: number;
|
|
246
|
+
message?: string;
|
|
247
|
+
}
|
|
248
|
+
/** A door's error as words a person below the write tier may read: a file path on this host is cut. */
|
|
249
|
+
export declare const plainDoorMessage: (text: string) => string;
|
|
250
|
+
/**
|
|
251
|
+
* Files each holding through POST /api/chronicle/episodes/<ref>/capabilities, one by one: the door
|
|
252
|
+
* lands each in the chronicle. `post` is the approver's own call to Miadi, so Miadi applies their
|
|
253
|
+
* permissions. A holding the door refuses is reported, the rest still land. The door answers 201 with
|
|
254
|
+
* `ok: false` when the holding is written and the wheel's node or edge is still pending: that is not landed,
|
|
255
|
+
* so the decision can be run again.
|
|
256
|
+
*/
|
|
257
|
+
export declare function landHoldings(changed: ChangedCapabilities, post: (path: string, body: Record<string, unknown>) => Promise<unknown>): Promise<{
|
|
258
|
+
episode?: string;
|
|
259
|
+
landed: LandedHolding[];
|
|
260
|
+
failed: LandedHolding[];
|
|
261
|
+
}>;
|
|
262
|
+
export {};
|