hub-proposal-create-augment.mjs
41 lines 1.7 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 11 days ago
1 /**
2 * Merge org evaluation policy + deterministic review triggers into a proposal create payload.
3 * Used by self-hosted Hub and hosted gateway (POST /api/v1/proposals body).
4 */
5
6 import { getProposalEvaluationRequired } from './hub-proposal-policy.mjs';
7 import { loadReviewTriggers, applyReviewTriggers } from './hub-proposal-review-triggers.mjs';
8
9 /**
10 * @param {Record<string, unknown>} body - parsed JSON body (mutated copy returned)
11 * @param {string} dataDir
12 * @param {{ evaluationRequired?: boolean }} [policyOptions] - when `evaluationRequired` is boolean, skip file/env read
13 * @returns {Record<string, unknown>}
14 */
15 export function augmentProposalCreateRequestBody(body, dataDir, policyOptions = {}) {
16 if (!body || typeof body !== 'object' || Buffer.isBuffer(body)) return body;
17 const policyPending =
18 typeof policyOptions.evaluationRequired === 'boolean'
19 ? policyOptions.evaluationRequired
20 : getProposalEvaluationRequired(dataDir);
21 const triggers = loadReviewTriggers(dataDir);
22 const labels = Array.isArray(body.labels) ? body.labels : [];
23 const applied = applyReviewTriggers(triggers, {
24 path: String(body.path ?? ''),
25 body: String(body.body ?? ''),
26 intent: String(body.intent ?? ''),
27 labels,
28 });
29 const next = { ...body };
30 const needPending = policyPending || applied.forcePending;
31 if (needPending) {
32 const es = next.evaluation_status;
33 if (es == null || String(es).trim() === '') next.evaluation_status = 'pending';
34 }
35 if (applied.review_queue) next.review_queue = applied.review_queue;
36 if (applied.review_severity) next.review_severity = applied.review_severity;
37 if (applied.auto_flag_reasons.length) {
38 next.auto_flag_reasons_json = JSON.stringify(applied.auto_flag_reasons);
39 }
40 return next;
41 }
File History 4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 11 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 31 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 51 days ago