hub-proposal-create-augment.mjs
41 lines 1.7 KB
Raw
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor ⚠ breaking 1 day 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 2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd feat(calendar): enforce agent context tiers in retrieval AP… Human minor 1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6 docs: accept Calendar Events v0 spec with Phase 0 security … Human 2 days ago