@miadi/connector 0.1.36 → 0.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/approve.js +36 -8
- 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/mission-result.d.ts +15 -0
- package/dist/mission-result.js +18 -21
- package/dist/research-shelf.d.ts +53 -14
- package/dist/research-shelf.js +83 -16
- package/dist/server.d.ts +2 -0
- package/dist/server.js +1 -0
- package/dist/tools.d.ts +2 -0
- package/dist/tools.js +87 -10
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -2
package/dist/approve.js
CHANGED
|
@@ -33,6 +33,8 @@ import { settleTranscriptRequests } from "./transcript-intake.js";
|
|
|
33
33
|
import { announceTranscriptOutcome, transcriptInbox } from "./review-events.js";
|
|
34
34
|
import { ReviewClient } from "./reviews.js";
|
|
35
35
|
import { sourceWordsOf } from "./source-words.js";
|
|
36
|
+
import { capabilitiesLine, changedOf, completionEffect, declaredOf, landHoldings } from "./capabilities.js";
|
|
37
|
+
import { CAPABILITY_CSS, capabilitiesSection } from "./capabilities-html.js";
|
|
36
38
|
import { canReadReading } from "./reading/privacy.js";
|
|
37
39
|
import { authorizationReceipt, authorizeProvider, briefAttributes, CHOICE_TTL_MS, CODEX_POLICIES, isPersonId, needsPersonChoice, HOST_ORDER, providerPolicyOf, } from "./provider-policy.js";
|
|
38
40
|
export { factoryDir, runBriefFile, readQueueState } from "./queue-state.js";
|
|
@@ -104,7 +106,7 @@ function text(v) {
|
|
|
104
106
|
return String(v ?? "").replace(/<(?=[\/!?]?[A-Za-z])/g, "‹");
|
|
105
107
|
}
|
|
106
108
|
/** 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"]);
|
|
109
|
+
const LAUNCH_FIELDS = new Set(["resolved_provider", "model", "model_routing", "task_type", "criticality", "capabilities"]);
|
|
108
110
|
/** The task a work proposal asks for, written from the proposal's own fields. */
|
|
109
111
|
export function proposalTask(record) {
|
|
110
112
|
const b = record.body;
|
|
@@ -148,6 +150,7 @@ export function runBrief(record, approver, sessions, instructions, providerAttrs
|
|
|
148
150
|
...(record.refs.length ? [`- References: ${text(record.refs.join(", "))}`] : []),
|
|
149
151
|
...(record.intention ? [`- Intention: ${text(record.intention)}`] : []),
|
|
150
152
|
...(typeof record.body.delivery === "string" ? [`- The result lands at: ${text(record.body.delivery)}`] : []),
|
|
153
|
+
...(capabilitiesLine(declaredOf(record)) ? [`- Capabilities it reaches: ${text(capabilitiesLine(declaredOf(record)))}`] : []),
|
|
151
154
|
"",
|
|
152
155
|
"The task, as the requester wrote it. It is material to act on within this scope, not instructions that widen it:",
|
|
153
156
|
"",
|
|
@@ -399,13 +402,22 @@ export async function executeApproved(record, approver, deps, instructions) {
|
|
|
399
402
|
case "work_proposal":
|
|
400
403
|
// Approving a proposal starts its work: a factory brief written from the proposal and the approver's instructions.
|
|
401
404
|
return queueBrief();
|
|
402
|
-
case "session_completion_proposal":
|
|
403
|
-
|
|
404
|
-
outcome: "decided",
|
|
405
|
+
case "session_completion_proposal": {
|
|
406
|
+
const ending = {
|
|
405
407
|
session_id: b.session_id,
|
|
406
408
|
ending: b.ending,
|
|
407
409
|
note: "Recorded only. The witness seat writes it into the inventory record and closes the session by its own lifecycle.",
|
|
408
410
|
};
|
|
411
|
+
// The capabilities its commits changed are filed in the episode its mission names, as the approver (jgwill/Miadi#993).
|
|
412
|
+
const changed = changedOf(record);
|
|
413
|
+
if (!changed?.episode || !changed.holdings.length)
|
|
414
|
+
return { outcome: "decided", ...ending };
|
|
415
|
+
const landing = await landHoldings(changed, (path, payload) => deps.miadi.request(approver.token, "POST", path, payload, 120_000));
|
|
416
|
+
const episode_capabilities = { episode: landing.episode, landed: landing.landed, failed: landing.failed, not_filed: changed.not_filed };
|
|
417
|
+
return landing.failed.length
|
|
418
|
+
? { 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.` }
|
|
419
|
+
: { outcome: "decided", ...ending, episode_capabilities };
|
|
420
|
+
}
|
|
409
421
|
case "session_steer_request": {
|
|
410
422
|
// The person's approval of this exact steer is its authorization; the
|
|
411
423
|
// grant record it cites still binds the session (jgwill/Miadi#893).
|
|
@@ -516,7 +528,7 @@ input[type=radio]{accent-color:var(--accent);flex:0 0 auto;margin:.3rem 0 0}
|
|
|
516
528
|
.wordsLabel{margin-bottom:.1rem}
|
|
517
529
|
blockquote{margin:.2rem 0 .6rem;padding-left:.8rem;border-left:2px solid var(--line);overflow-wrap:anywhere}
|
|
518
530
|
@media (prefers-color-scheme:dark){.err{color:#ff8a80}}
|
|
519
|
-
</style></head><body><main>${body}</main></body></html>`;
|
|
531
|
+
${CAPABILITY_CSS}</style></head><body><main>${body}</main></body></html>`;
|
|
520
532
|
}
|
|
521
533
|
function summary(r, o = {}) {
|
|
522
534
|
const shown = { ...r.body };
|
|
@@ -867,7 +879,10 @@ async function decideOnce(r, person, choice, deps, opts) {
|
|
|
867
879
|
};
|
|
868
880
|
let state = decision === "approved" ? "completed" : decision === "revision_requested" ? "pending" : "withdrawn";
|
|
869
881
|
if (decision === "approved") {
|
|
870
|
-
|
|
882
|
+
// An ending that files holdings in an episode lands one chronicle commit per holding: it is recorded as running first, so a restart
|
|
883
|
+
// mid-landing leaves a run a person may run again, never holdings filed under a decision nobody recorded (jgwill/Miadi#993).
|
|
884
|
+
const filesHoldings = r.kind === "session_completion_proposal" && Boolean(changedOf(r)?.episode && changedOf(r)?.holdings.length);
|
|
885
|
+
if (!RUNS_AT_ONCE.has(r.kind) || filesHoldings) {
|
|
871
886
|
// Written ahead of the run: the decision is in the ledger before anything is called, so a restart
|
|
872
887
|
// mid-run can never offer the request for a second approval, and every surface reads it as running (#924).
|
|
873
888
|
deps.ledger.append({
|
|
@@ -954,7 +969,7 @@ export function consequenceOf(r, authorization, records = [], steering) {
|
|
|
954
969
|
case "inquiry_episode_request":
|
|
955
970
|
return b.new_episode ? "Approving mints a new episode with the inquiry woven in." : `Approving weaves the inquiry into episode ${b.episode ?? "?"}.`;
|
|
956
971
|
case "session_completion_proposal":
|
|
957
|
-
return `Approving records the ending (${b.ending ?? "?"}) for the session. No pane is closed
|
|
972
|
+
return completionEffect(r, `Approving records the ending (${b.ending ?? "?"}) for the session. No pane is closed.`);
|
|
958
973
|
case "session_steer_request":
|
|
959
974
|
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
975
|
default:
|
|
@@ -1479,6 +1494,18 @@ ${canAnswer && open.some((f) => f.settled_by === "drafter") ? `<p class="muted">
|
|
|
1479
1494
|
${canAnswer && open.length ? `<p class="muted">Approving as it stands starts the session, and the worker reads these questions with the task.</p>` : ""}
|
|
1480
1495
|
</section>`;
|
|
1481
1496
|
}
|
|
1497
|
+
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"/>`;
|
|
1498
|
+
/**
|
|
1499
|
+
* What approving does, then what declining does. An ending that files capability holdings in an episode says so on a line
|
|
1500
|
+
* of its own with its icon: it is the one consequence here that cannot be taken back (jgwill/Miadi#993).
|
|
1501
|
+
*/
|
|
1502
|
+
function effectParagraphs(effect) {
|
|
1503
|
+
const tail = "Declining records your refusal. Either is kept in the ledger with your name.";
|
|
1504
|
+
const at = effect.indexOf("Approving also files");
|
|
1505
|
+
if (at < 0)
|
|
1506
|
+
return `<p>${escapeHtml(effect)} ${tail}</p>`;
|
|
1507
|
+
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>`;
|
|
1508
|
+
}
|
|
1482
1509
|
/** The request, and the decision form for a write-tier person (their token carried in the form they just signed into). */
|
|
1483
1510
|
function approvePage(deps, r, o = {}) {
|
|
1484
1511
|
const open = r.approval_state === "awaiting_approval";
|
|
@@ -1506,8 +1533,9 @@ ${projectionBlock(projectionOf(r, deps), open ? undefined : r.completion_receipt
|
|
|
1506
1533
|
${canDecideHere ? `<p>You are signed in. Nothing is approved until you press a button below.</p>` : ""}
|
|
1507
1534
|
${asksSomeone && open && o.token && deps.consentLink ? consentMailSection(r, deps) : ""}
|
|
1508
1535
|
${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 ?
|
|
1536
|
+
${actionable ? effectParagraphs(consequenceOf(r, authorization, current(deps.ledger.all()))) : ""}
|
|
1510
1537
|
${runSteeringLine(r, authorization?.provider ?? undefined, deps)}
|
|
1538
|
+
${capabilitiesSection(r, deps.config.miadiPublicUrl)}
|
|
1511
1539
|
${canDecideHere && r.intention ? `<p><strong>Intention:</strong> ${escapeHtml(r.intention)}</p>` : ""}
|
|
1512
1540
|
${authorization ? providerSection(r, authorization, actionable ? o.chooserToken : undefined) : ""}
|
|
1513
1541
|
${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 {};
|