@neuroverseos/governance 0.4.0 → 0.4.2
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/adapters/autoresearch.d.cts +2 -1
- package/dist/adapters/autoresearch.d.ts +2 -1
- package/dist/adapters/autoresearch.js +2 -2
- package/dist/adapters/deep-agents.d.cts +3 -2
- package/dist/adapters/deep-agents.d.ts +3 -2
- package/dist/adapters/deep-agents.js +2 -2
- package/dist/adapters/express.d.cts +2 -1
- package/dist/adapters/express.d.ts +2 -1
- package/dist/adapters/express.js +2 -2
- package/dist/adapters/github.cjs +1697 -0
- package/dist/adapters/github.d.cts +225 -0
- package/dist/adapters/github.d.ts +225 -0
- package/dist/adapters/github.js +27 -0
- package/dist/adapters/index.cjs +66 -1
- package/dist/adapters/index.d.cts +4 -278
- package/dist/adapters/index.d.ts +4 -278
- package/dist/adapters/index.js +18 -18
- package/dist/adapters/langchain.d.cts +3 -2
- package/dist/adapters/langchain.d.ts +3 -2
- package/dist/adapters/langchain.js +2 -2
- package/dist/adapters/mentraos.cjs +2181 -0
- package/dist/adapters/mentraos.d.cts +319 -0
- package/dist/adapters/mentraos.d.ts +319 -0
- package/dist/{mentraos-YFS7FMJH.js → adapters/mentraos.js} +6 -6
- package/dist/adapters/openai.d.cts +3 -2
- package/dist/adapters/openai.d.ts +3 -2
- package/dist/adapters/openai.js +2 -2
- package/dist/adapters/openclaw.d.cts +3 -2
- package/dist/adapters/openclaw.d.ts +3 -2
- package/dist/adapters/openclaw.js +2 -2
- package/dist/{add-LYHDZ5RL.js → add-XSANI3FK.js} +1 -1
- package/dist/bootstrap-contract-DcV6t-8M.d.cts +216 -0
- package/dist/bootstrap-contract-DcV6t-8M.d.ts +216 -0
- package/dist/{build-THUEYMVT.js → build-EGBGZFIJ.js} +5 -5
- package/dist/{chunk-MFKHTE5R.js → chunk-3AYKQHYI.js} +1 -1
- package/dist/chunk-3S5AD4AB.js +421 -0
- package/dist/{chunk-V4FZHJQX.js → chunk-A7SHG75T.js} +1 -1
- package/dist/{chunk-JKGPSFGH.js → chunk-AV7XJJWK.js} +1 -1
- package/dist/{chunk-Y6WXAPKY.js → chunk-DA5MHFRR.js} +1 -1
- package/dist/{chunk-7D7PZLB7.js → chunk-FS2UUJJO.js} +3 -3
- package/dist/{chunk-TD5GKIHP.js → chunk-FVOGUCB6.js} +1 -1
- package/dist/{chunk-APU4OZIP.js → chunk-GTPV2XGO.js} +67 -2
- package/dist/{chunk-BXLTEUS4.js → chunk-I4RTIMLX.js} +2 -2
- package/dist/{chunk-5JUZ4HL7.js → chunk-J2IZBHXJ.js} +3 -3
- package/dist/{chunk-YNYCQECH.js → chunk-QMVQ6KPL.js} +1 -1
- package/dist/{chunk-25XHSTPT.js → chunk-RDA7ISWC.js} +1 -1
- package/dist/{chunk-DWHUZUEY.js → chunk-YJ34R5NB.js} +1 -1
- package/dist/{chunk-UTH7OXTM.js → chunk-ZEIT2QLM.js} +3 -3
- package/dist/cli/neuroverse.cjs +580 -28
- package/dist/cli/neuroverse.js +21 -21
- package/dist/cli/plan.js +2 -2
- package/dist/cli/run.js +2 -2
- package/dist/{demo-66MMJTEH.js → demo-6OQYWRR6.js} +3 -3
- package/dist/{derive-5LOMN7GO.js → derive-7Y7YWVLU.js} +4 -4
- package/dist/{doctor-WIO4FLA3.js → doctor-EC5OYTI3.js} +3 -2
- package/dist/engine/bootstrap-emitter.cjs +241 -0
- package/dist/engine/bootstrap-emitter.d.cts +27 -0
- package/dist/engine/bootstrap-emitter.d.ts +27 -0
- package/dist/{bootstrap-emitter-GIMOJFOC.js → engine/bootstrap-emitter.js} +2 -2
- package/dist/engine/bootstrap-parser.cjs +560 -0
- package/dist/engine/bootstrap-parser.d.cts +96 -0
- package/dist/engine/bootstrap-parser.d.ts +96 -0
- package/dist/{bootstrap-parser-LBLGVEMU.js → engine/bootstrap-parser.js} +2 -2
- package/dist/engine/guard-engine.cjs +1116 -0
- package/dist/engine/guard-engine.d.cts +60 -0
- package/dist/engine/guard-engine.d.ts +60 -0
- package/dist/{guard-engine-N7TUIUU7.js → engine/guard-engine.js} +3 -3
- package/dist/engine/simulate-engine.cjs +390 -0
- package/dist/engine/simulate-engine.d.cts +105 -0
- package/dist/engine/simulate-engine.d.ts +105 -0
- package/dist/engine/simulate-engine.js +9 -0
- package/dist/{equity-penalties-WWC7UDQD.js → equity-penalties-NVBAB5WL.js} +2 -2
- package/dist/{explain-MUSGDT67.js → explain-HDFN4ION.js} +1 -1
- package/dist/{guard-W3BMQPBJ.js → guard-6KSCWT2W.js} +2 -2
- package/dist/{guard-contract-CLBbTGK_.d.ts → guard-contract-ddiIPlOg.d.cts} +2 -369
- package/dist/{guard-contract-CLBbTGK_.d.cts → guard-contract-q6HJAq3Q.d.ts} +2 -369
- package/dist/{improve-PJDAWW4Q.js → improve-2PWGGO5B.js} +3 -3
- package/dist/index.cjs +452 -0
- package/dist/index.d.cts +12 -492
- package/dist/index.d.ts +12 -492
- package/dist/index.js +75 -54
- package/dist/{lens-IP6GIZ2Q.js → lens-MHMUDCMQ.js} +92 -25
- package/dist/{mcp-server-OG3PPVD2.js → mcp-server-TNIWZ7B5.js} +2 -2
- package/dist/{playground-4BK2XQ47.js → playground-3FLDGBET.js} +2 -2
- package/dist/{redteam-BRZALBPP.js → redteam-HV6LMKEH.js} +2 -2
- package/dist/{session-SGRUT2UH.js → session-XZP2754M.js} +2 -2
- package/dist/{shared-CwGpPheR.d.ts → shared-DAzdfWtU.d.ts} +1 -1
- package/dist/{shared-BGzmYP5g.d.cts → shared-PpalGKxc.d.cts} +1 -1
- package/dist/{simulate-FGXKIH7V.js → simulate-VT437EEL.js} +2 -2
- package/dist/spatial/index.cjs +682 -0
- package/dist/spatial/index.d.cts +517 -0
- package/dist/spatial/index.d.ts +517 -0
- package/dist/spatial/index.js +633 -0
- package/dist/{test-PT44BSYG.js → test-4WTX6RKQ.js} +2 -2
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +370 -0
- package/dist/types.d.ts +370 -0
- package/dist/types.js +0 -0
- package/dist/{validate-Q5O5TGLT.js → validate-M52DX22Y.js} +1 -1
- package/dist/{world-V52ZMH26.js → world-O4HTQPDP.js} +1 -1
- package/dist/{world-loader-C4D3VPP3.js → world-loader-YTYFOP7D.js} +1 -1
- package/dist/worlds/mentraos-spatial.nv-world.md +68 -0
- package/package.json +52 -3
- package/dist/{behavioral-SPWPGYXL.js → behavioral-SLW7ALEK.js} +3 -3
- package/dist/{bootstrap-IP5QMC3Q.js → bootstrap-2OW5ZLBL.js} +3 -3
- package/dist/{chunk-7QIAF377.js → chunk-CYDMUJVZ.js} +0 -0
- package/dist/{chunk-QZ666FCV.js → chunk-FHXXD2TI.js} +6 -6
- package/dist/{configure-ai-5MP5DWTT.js → configure-ai-LL3VAPQW.js} +3 -3
package/dist/index.cjs
CHANGED
|
@@ -949,6 +949,9 @@ __export(index_exports, {
|
|
|
949
949
|
DERIVE_EXIT_CODES: () => DERIVE_EXIT_CODES,
|
|
950
950
|
FileAuditLogger: () => FileAuditLogger,
|
|
951
951
|
GUARD_EXIT_CODES: () => GUARD_EXIT_CODES,
|
|
952
|
+
GitHubGovernanceBlockedError: () => GitHubGovernanceBlockedError,
|
|
953
|
+
GitHubGovernor: () => GitHubGovernor,
|
|
954
|
+
GitHubWebhookHandler: () => GitHubWebhookHandler,
|
|
952
955
|
McpGovernanceServer: () => McpGovernanceServer,
|
|
953
956
|
ModelAdapter: () => ModelAdapter,
|
|
954
957
|
PLAN_EXIT_CODES: () => PLAN_EXIT_CODES,
|
|
@@ -968,6 +971,10 @@ __export(index_exports, {
|
|
|
968
971
|
classifyIntent: () => classifyIntent,
|
|
969
972
|
classifyIntentWithAI: () => classifyIntentWithAI,
|
|
970
973
|
createAgentState: () => createAgentState,
|
|
974
|
+
createGitHubGovernor: () => createGitHubGovernor,
|
|
975
|
+
createGitHubGovernorFromWorld: () => createGitHubGovernorFromWorld,
|
|
976
|
+
createGitHubWebhookHandler: () => createGitHubWebhookHandler,
|
|
977
|
+
createGitHubWebhookHandlerFromWorld: () => createGitHubWebhookHandlerFromWorld,
|
|
971
978
|
createGovernanceEngine: () => createGovernanceEngine,
|
|
972
979
|
createGovernor: () => createGovernor,
|
|
973
980
|
deriveWorld: () => deriveWorld,
|
|
@@ -982,6 +989,8 @@ __export(index_exports, {
|
|
|
982
989
|
explainWorld: () => explainWorld,
|
|
983
990
|
extractContentFields: () => extractContentFields,
|
|
984
991
|
extractWorldMarkdown: () => extractWorldMarkdown,
|
|
992
|
+
formatForActions: () => formatForActions,
|
|
993
|
+
formatPRComment: () => formatPRComment,
|
|
985
994
|
formatVerdict: () => formatVerdict,
|
|
986
995
|
formatVerdictOneLine: () => formatVerdictOneLine,
|
|
987
996
|
generateAdaptationNarrative: () => generateAdaptationNarrative,
|
|
@@ -7803,6 +7812,440 @@ function round(n, decimals = 3) {
|
|
|
7803
7812
|
return Math.round(n * factor) / factor;
|
|
7804
7813
|
}
|
|
7805
7814
|
|
|
7815
|
+
// src/adapters/github.ts
|
|
7816
|
+
init_world_loader();
|
|
7817
|
+
|
|
7818
|
+
// src/adapters/shared.ts
|
|
7819
|
+
var GovernanceBlockedError = class extends Error {
|
|
7820
|
+
verdict;
|
|
7821
|
+
constructor(verdict, message) {
|
|
7822
|
+
super(message ?? `[NeuroVerse] BLOCKED: ${verdict.reason ?? verdict.ruleId ?? "governance rule"}`);
|
|
7823
|
+
this.name = "GovernanceBlockedError";
|
|
7824
|
+
this.verdict = verdict;
|
|
7825
|
+
}
|
|
7826
|
+
};
|
|
7827
|
+
function trackPlanProgress(event, state, callbacks) {
|
|
7828
|
+
if (!state.activePlan) return;
|
|
7829
|
+
const planVerdict = evaluatePlan(event, state.activePlan);
|
|
7830
|
+
if (planVerdict.matchedStep) {
|
|
7831
|
+
const advResult = advancePlan(state.activePlan, planVerdict.matchedStep);
|
|
7832
|
+
if (advResult.success && advResult.plan) {
|
|
7833
|
+
state.activePlan = advResult.plan;
|
|
7834
|
+
state.engineOptions.plan = state.activePlan;
|
|
7835
|
+
}
|
|
7836
|
+
const progress = getPlanProgress(state.activePlan);
|
|
7837
|
+
callbacks.onPlanProgress?.(progress);
|
|
7838
|
+
if (progress.completed === progress.total) {
|
|
7839
|
+
callbacks.onPlanComplete?.();
|
|
7840
|
+
}
|
|
7841
|
+
}
|
|
7842
|
+
}
|
|
7843
|
+
function buildEngineOptions(options, plan) {
|
|
7844
|
+
return {
|
|
7845
|
+
trace: options.trace ?? false,
|
|
7846
|
+
level: options.level,
|
|
7847
|
+
plan: plan ?? options.plan
|
|
7848
|
+
};
|
|
7849
|
+
}
|
|
7850
|
+
|
|
7851
|
+
// src/adapters/github.ts
|
|
7852
|
+
var GitHubGovernanceBlockedError = class extends GovernanceBlockedError {
|
|
7853
|
+
action;
|
|
7854
|
+
constructor(verdict, action) {
|
|
7855
|
+
super(verdict, `[NeuroVerse] GitHub action blocked: ${action.action} on ${action.repository}`);
|
|
7856
|
+
this.name = "GitHubGovernanceBlockedError";
|
|
7857
|
+
this.action = action;
|
|
7858
|
+
}
|
|
7859
|
+
};
|
|
7860
|
+
function extractBranch(ref) {
|
|
7861
|
+
if (!ref) return void 0;
|
|
7862
|
+
if (ref.startsWith("refs/heads/")) return ref.slice("refs/heads/".length);
|
|
7863
|
+
if (ref.startsWith("refs/tags/")) return ref.slice("refs/tags/".length);
|
|
7864
|
+
return ref;
|
|
7865
|
+
}
|
|
7866
|
+
function isProtectedBranch(branch, protectedBranches) {
|
|
7867
|
+
if (!branch) return false;
|
|
7868
|
+
return protectedBranches.some(
|
|
7869
|
+
(pb) => branch === pb || branch.startsWith(`${pb}/`)
|
|
7870
|
+
);
|
|
7871
|
+
}
|
|
7872
|
+
function defaultMapAction(action, protectedBranches, restrictedActors) {
|
|
7873
|
+
const branch = action.branch ?? extractBranch(action.ref);
|
|
7874
|
+
const isProtected = isProtectedBranch(branch, protectedBranches);
|
|
7875
|
+
const isRestricted = action.actor ? restrictedActors.some((ra) => action.actor === ra || action.actor?.endsWith("[bot]")) : false;
|
|
7876
|
+
let actionCategory = "other";
|
|
7877
|
+
const act = action.action.toLowerCase();
|
|
7878
|
+
if (act.includes("read") || act.includes("get") || act.includes("list") || act.includes("view")) {
|
|
7879
|
+
actionCategory = "read";
|
|
7880
|
+
} else if (act.includes("delete") || act.includes("remove") || act.includes("close")) {
|
|
7881
|
+
actionCategory = "delete";
|
|
7882
|
+
} else if (act.includes("deploy") || act.includes("run") || act.includes("execute") || act.includes("merge")) {
|
|
7883
|
+
actionCategory = "network";
|
|
7884
|
+
} else if (act.includes("create") || act.includes("push") || act.includes("write") || act.includes("update") || act.includes("edit")) {
|
|
7885
|
+
actionCategory = "write";
|
|
7886
|
+
} else if (act.includes("comment") || act.includes("review") || act.includes("notify")) {
|
|
7887
|
+
actionCategory = "other";
|
|
7888
|
+
}
|
|
7889
|
+
return {
|
|
7890
|
+
intent: action.action,
|
|
7891
|
+
tool: "github",
|
|
7892
|
+
scope: `${action.repository}${branch ? `@${branch}` : ""}`,
|
|
7893
|
+
actionCategory,
|
|
7894
|
+
direction: "input",
|
|
7895
|
+
args: {
|
|
7896
|
+
repository: action.repository,
|
|
7897
|
+
ref: action.ref,
|
|
7898
|
+
branch,
|
|
7899
|
+
actor: action.actor,
|
|
7900
|
+
protected_branch: isProtected,
|
|
7901
|
+
restricted_actor: isRestricted,
|
|
7902
|
+
...action.metadata
|
|
7903
|
+
}
|
|
7904
|
+
};
|
|
7905
|
+
}
|
|
7906
|
+
function defaultMapWebhook(eventType, payload) {
|
|
7907
|
+
const repo = payload.repository;
|
|
7908
|
+
const repoFullName = repo?.full_name ?? "unknown/unknown";
|
|
7909
|
+
const sender = payload.sender;
|
|
7910
|
+
const actor = sender?.login ?? void 0;
|
|
7911
|
+
const webhookAction = payload.action;
|
|
7912
|
+
switch (eventType) {
|
|
7913
|
+
case "push": {
|
|
7914
|
+
const ref = payload.ref;
|
|
7915
|
+
const branch = extractBranch(ref);
|
|
7916
|
+
const forced = payload.forced;
|
|
7917
|
+
return {
|
|
7918
|
+
action: forced ? "force_push" : `push_to_${branch ?? "branch"}`,
|
|
7919
|
+
repository: repoFullName,
|
|
7920
|
+
ref,
|
|
7921
|
+
branch,
|
|
7922
|
+
actor,
|
|
7923
|
+
metadata: {
|
|
7924
|
+
forced: forced ?? false,
|
|
7925
|
+
commits_count: payload.commits?.length ?? 0,
|
|
7926
|
+
head_commit: payload.head_commit?.id
|
|
7927
|
+
}
|
|
7928
|
+
};
|
|
7929
|
+
}
|
|
7930
|
+
case "pull_request": {
|
|
7931
|
+
const pr = payload.pull_request;
|
|
7932
|
+
const base = pr?.base;
|
|
7933
|
+
const baseBranch = base?.ref;
|
|
7934
|
+
const prNumber = pr?.number;
|
|
7935
|
+
const merged = pr?.merged;
|
|
7936
|
+
const labels = pr?.labels?.map((l) => l.name) ?? [];
|
|
7937
|
+
let action = `pull_request_${webhookAction ?? "unknown"}`;
|
|
7938
|
+
if (webhookAction === "closed" && merged) {
|
|
7939
|
+
action = "merge_pull_request";
|
|
7940
|
+
}
|
|
7941
|
+
return {
|
|
7942
|
+
action,
|
|
7943
|
+
repository: repoFullName,
|
|
7944
|
+
branch: baseBranch,
|
|
7945
|
+
actor,
|
|
7946
|
+
metadata: {
|
|
7947
|
+
pr_number: prNumber,
|
|
7948
|
+
labels,
|
|
7949
|
+
merged: merged ?? false,
|
|
7950
|
+
draft: pr?.draft ?? false,
|
|
7951
|
+
webhook_action: webhookAction
|
|
7952
|
+
}
|
|
7953
|
+
};
|
|
7954
|
+
}
|
|
7955
|
+
case "release": {
|
|
7956
|
+
const release = payload.release;
|
|
7957
|
+
return {
|
|
7958
|
+
action: `release_${webhookAction ?? "published"}`,
|
|
7959
|
+
repository: repoFullName,
|
|
7960
|
+
ref: release?.tag_name ? `refs/tags/${release.tag_name}` : void 0,
|
|
7961
|
+
actor,
|
|
7962
|
+
metadata: {
|
|
7963
|
+
tag: release?.tag_name,
|
|
7964
|
+
prerelease: release?.prerelease ?? false,
|
|
7965
|
+
draft: release?.draft ?? false,
|
|
7966
|
+
webhook_action: webhookAction
|
|
7967
|
+
}
|
|
7968
|
+
};
|
|
7969
|
+
}
|
|
7970
|
+
case "deployment":
|
|
7971
|
+
case "deployment_status": {
|
|
7972
|
+
const deployment = payload.deployment ?? payload;
|
|
7973
|
+
return {
|
|
7974
|
+
action: eventType === "deployment" ? "create_deployment" : "deployment_status_update",
|
|
7975
|
+
repository: repoFullName,
|
|
7976
|
+
ref: deployment.ref,
|
|
7977
|
+
actor,
|
|
7978
|
+
metadata: {
|
|
7979
|
+
environment: deployment.environment,
|
|
7980
|
+
status: payload.deployment_status?.state,
|
|
7981
|
+
webhook_action: webhookAction
|
|
7982
|
+
}
|
|
7983
|
+
};
|
|
7984
|
+
}
|
|
7985
|
+
case "workflow_run": {
|
|
7986
|
+
const run = payload.workflow_run;
|
|
7987
|
+
return {
|
|
7988
|
+
action: `workflow_${webhookAction ?? "completed"}`,
|
|
7989
|
+
repository: repoFullName,
|
|
7990
|
+
branch: run?.head_branch,
|
|
7991
|
+
actor,
|
|
7992
|
+
metadata: {
|
|
7993
|
+
workflow_name: run?.name,
|
|
7994
|
+
conclusion: run?.conclusion,
|
|
7995
|
+
status: run?.status,
|
|
7996
|
+
webhook_action: webhookAction
|
|
7997
|
+
}
|
|
7998
|
+
};
|
|
7999
|
+
}
|
|
8000
|
+
case "issues": {
|
|
8001
|
+
const issue = payload.issue;
|
|
8002
|
+
return {
|
|
8003
|
+
action: `issue_${webhookAction ?? "opened"}`,
|
|
8004
|
+
repository: repoFullName,
|
|
8005
|
+
actor,
|
|
8006
|
+
metadata: {
|
|
8007
|
+
issue_number: issue?.number,
|
|
8008
|
+
labels: issue?.labels?.map((l) => l.name) ?? [],
|
|
8009
|
+
webhook_action: webhookAction
|
|
8010
|
+
}
|
|
8011
|
+
};
|
|
8012
|
+
}
|
|
8013
|
+
case "issue_comment": {
|
|
8014
|
+
return {
|
|
8015
|
+
action: `issue_comment_${webhookAction ?? "created"}`,
|
|
8016
|
+
repository: repoFullName,
|
|
8017
|
+
actor,
|
|
8018
|
+
metadata: {
|
|
8019
|
+
issue_number: payload.issue?.number,
|
|
8020
|
+
webhook_action: webhookAction
|
|
8021
|
+
}
|
|
8022
|
+
};
|
|
8023
|
+
}
|
|
8024
|
+
case "delete": {
|
|
8025
|
+
return {
|
|
8026
|
+
action: `delete_${payload.ref_type ?? "ref"}`,
|
|
8027
|
+
repository: repoFullName,
|
|
8028
|
+
ref: payload.ref,
|
|
8029
|
+
actor,
|
|
8030
|
+
metadata: {
|
|
8031
|
+
ref_type: payload.ref_type
|
|
8032
|
+
}
|
|
8033
|
+
};
|
|
8034
|
+
}
|
|
8035
|
+
default: {
|
|
8036
|
+
return {
|
|
8037
|
+
action: webhookAction ? `${eventType}_${webhookAction}` : eventType,
|
|
8038
|
+
repository: repoFullName,
|
|
8039
|
+
actor,
|
|
8040
|
+
metadata: { webhook_action: webhookAction }
|
|
8041
|
+
};
|
|
8042
|
+
}
|
|
8043
|
+
}
|
|
8044
|
+
}
|
|
8045
|
+
var GitHubGovernor = class {
|
|
8046
|
+
world;
|
|
8047
|
+
options;
|
|
8048
|
+
engineOptions;
|
|
8049
|
+
activePlan;
|
|
8050
|
+
protectedBranches;
|
|
8051
|
+
restrictedActors;
|
|
8052
|
+
mapFn;
|
|
8053
|
+
constructor(world, options = {}) {
|
|
8054
|
+
this.world = world;
|
|
8055
|
+
this.options = options;
|
|
8056
|
+
this.activePlan = options.plan;
|
|
8057
|
+
this.engineOptions = buildEngineOptions(options, this.activePlan);
|
|
8058
|
+
this.protectedBranches = options.protectedBranches ?? ["main", "master", "production"];
|
|
8059
|
+
this.restrictedActors = options.restrictedActors ?? [];
|
|
8060
|
+
this.mapFn = options.mapAction ?? ((action) => defaultMapAction(action, this.protectedBranches, this.restrictedActors));
|
|
8061
|
+
}
|
|
8062
|
+
/**
|
|
8063
|
+
* Evaluate a GitHub action against governance rules.
|
|
8064
|
+
* Returns a full result with verdict, event, and the original action.
|
|
8065
|
+
*/
|
|
8066
|
+
evaluate(action) {
|
|
8067
|
+
const event = this.mapFn(action);
|
|
8068
|
+
this.engineOptions.plan = this.activePlan;
|
|
8069
|
+
const verdict = evaluateGuard(event, this.world, this.engineOptions);
|
|
8070
|
+
this.options.onEvaluate?.(verdict, event, action);
|
|
8071
|
+
if (verdict.status === "ALLOW") {
|
|
8072
|
+
trackPlanProgress(event, this, this.options);
|
|
8073
|
+
}
|
|
8074
|
+
return { verdict, event, action };
|
|
8075
|
+
}
|
|
8076
|
+
/**
|
|
8077
|
+
* Evaluate and enforce — throws GitHubGovernanceBlockedError on BLOCK/PAUSE.
|
|
8078
|
+
* Use this as a gate before executing GitHub API calls.
|
|
8079
|
+
*/
|
|
8080
|
+
enforce(action) {
|
|
8081
|
+
const result = this.evaluate(action);
|
|
8082
|
+
if (result.verdict.status === "BLOCK" || result.verdict.status === "PAUSE") {
|
|
8083
|
+
throw new GitHubGovernanceBlockedError(result.verdict, action);
|
|
8084
|
+
}
|
|
8085
|
+
return result;
|
|
8086
|
+
}
|
|
8087
|
+
/**
|
|
8088
|
+
* Check if pushing to a branch is allowed.
|
|
8089
|
+
* Convenience method for the most common governance check.
|
|
8090
|
+
*/
|
|
8091
|
+
canPush(repository, branch, actor) {
|
|
8092
|
+
return this.evaluate({
|
|
8093
|
+
action: `push_to_${branch}`,
|
|
8094
|
+
repository,
|
|
8095
|
+
ref: `refs/heads/${branch}`,
|
|
8096
|
+
branch,
|
|
8097
|
+
actor
|
|
8098
|
+
}).verdict;
|
|
8099
|
+
}
|
|
8100
|
+
/**
|
|
8101
|
+
* Check if merging a PR is allowed.
|
|
8102
|
+
*/
|
|
8103
|
+
canMerge(repository, targetBranch, prNumber, actor, labels) {
|
|
8104
|
+
return this.evaluate({
|
|
8105
|
+
action: "merge_pull_request",
|
|
8106
|
+
repository,
|
|
8107
|
+
branch: targetBranch,
|
|
8108
|
+
actor,
|
|
8109
|
+
metadata: { pr_number: prNumber, labels: labels ?? [] }
|
|
8110
|
+
}).verdict;
|
|
8111
|
+
}
|
|
8112
|
+
/**
|
|
8113
|
+
* Check if creating a release is allowed.
|
|
8114
|
+
*/
|
|
8115
|
+
canRelease(repository, tag, actor, prerelease) {
|
|
8116
|
+
return this.evaluate({
|
|
8117
|
+
action: "release_published",
|
|
8118
|
+
repository,
|
|
8119
|
+
ref: `refs/tags/${tag}`,
|
|
8120
|
+
actor,
|
|
8121
|
+
metadata: { tag, prerelease: prerelease ?? false }
|
|
8122
|
+
}).verdict;
|
|
8123
|
+
}
|
|
8124
|
+
/**
|
|
8125
|
+
* Check if deploying to an environment is allowed.
|
|
8126
|
+
*/
|
|
8127
|
+
canDeploy(repository, environment, ref, actor) {
|
|
8128
|
+
return this.evaluate({
|
|
8129
|
+
action: "create_deployment",
|
|
8130
|
+
repository,
|
|
8131
|
+
ref,
|
|
8132
|
+
actor,
|
|
8133
|
+
metadata: { environment }
|
|
8134
|
+
}).verdict;
|
|
8135
|
+
}
|
|
8136
|
+
};
|
|
8137
|
+
var GitHubWebhookHandler = class {
|
|
8138
|
+
governor;
|
|
8139
|
+
mapWebhookFn;
|
|
8140
|
+
webhookSecret;
|
|
8141
|
+
constructor(world, options = {}) {
|
|
8142
|
+
this.governor = new GitHubGovernor(world, options);
|
|
8143
|
+
this.mapWebhookFn = options.mapWebhook ?? defaultMapWebhook;
|
|
8144
|
+
this.webhookSecret = options.webhookSecret;
|
|
8145
|
+
}
|
|
8146
|
+
/**
|
|
8147
|
+
* Evaluate a webhook payload.
|
|
8148
|
+
*
|
|
8149
|
+
* @param eventType - The X-GitHub-Event header value
|
|
8150
|
+
* @param payload - The parsed webhook body
|
|
8151
|
+
*/
|
|
8152
|
+
evaluate(eventType, payload) {
|
|
8153
|
+
const action = this.mapWebhookFn(eventType, payload);
|
|
8154
|
+
const result = this.governor.evaluate(action);
|
|
8155
|
+
return {
|
|
8156
|
+
verdict: result.verdict,
|
|
8157
|
+
event: result.event,
|
|
8158
|
+
webhookEvent: eventType,
|
|
8159
|
+
webhookAction: payload.action
|
|
8160
|
+
};
|
|
8161
|
+
}
|
|
8162
|
+
/**
|
|
8163
|
+
* Evaluate and enforce — throws on BLOCK/PAUSE.
|
|
8164
|
+
*/
|
|
8165
|
+
enforce(eventType, payload) {
|
|
8166
|
+
const result = this.evaluate(eventType, payload);
|
|
8167
|
+
if (result.verdict.status === "BLOCK" || result.verdict.status === "PAUSE") {
|
|
8168
|
+
const action = this.mapWebhookFn(eventType, payload);
|
|
8169
|
+
throw new GitHubGovernanceBlockedError(result.verdict, action);
|
|
8170
|
+
}
|
|
8171
|
+
return result;
|
|
8172
|
+
}
|
|
8173
|
+
/** Access the underlying governor for direct action evaluation. */
|
|
8174
|
+
getGovernor() {
|
|
8175
|
+
return this.governor;
|
|
8176
|
+
}
|
|
8177
|
+
/** Get the configured webhook secret (for signature verification in your server). */
|
|
8178
|
+
getWebhookSecret() {
|
|
8179
|
+
return this.webhookSecret;
|
|
8180
|
+
}
|
|
8181
|
+
};
|
|
8182
|
+
function formatForActions(verdict) {
|
|
8183
|
+
const status = verdict.status === "ALLOW" ? "allowed" : verdict.status === "BLOCK" ? "blocked" : "paused";
|
|
8184
|
+
const reason = verdict.reason ?? "";
|
|
8185
|
+
const ruleId = verdict.ruleId ?? "";
|
|
8186
|
+
const lines = [
|
|
8187
|
+
`governance_status=${status}`,
|
|
8188
|
+
`verdict_status=${verdict.status}`,
|
|
8189
|
+
`reason=${reason}`,
|
|
8190
|
+
`rule_id=${ruleId}`
|
|
8191
|
+
].join("\n");
|
|
8192
|
+
return {
|
|
8193
|
+
governance_status: status,
|
|
8194
|
+
verdict_status: verdict.status,
|
|
8195
|
+
reason,
|
|
8196
|
+
rule_id: ruleId,
|
|
8197
|
+
outputLines: lines
|
|
8198
|
+
};
|
|
8199
|
+
}
|
|
8200
|
+
function formatPRComment(verdict, action) {
|
|
8201
|
+
const icon = verdict.status === "ALLOW" ? "\u2705" : verdict.status === "BLOCK" ? "\u{1F6AB}" : "\u23F8\uFE0F";
|
|
8202
|
+
const status = verdict.status;
|
|
8203
|
+
let body = `## ${icon} Governance: ${status}
|
|
8204
|
+
|
|
8205
|
+
`;
|
|
8206
|
+
body += `**Action:** \`${action.action}\`
|
|
8207
|
+
`;
|
|
8208
|
+
body += `**Repository:** \`${action.repository}\`
|
|
8209
|
+
`;
|
|
8210
|
+
if (action.branch) {
|
|
8211
|
+
body += `**Branch:** \`${action.branch}\`
|
|
8212
|
+
`;
|
|
8213
|
+
}
|
|
8214
|
+
if (action.actor) {
|
|
8215
|
+
body += `**Actor:** \`${action.actor}\`
|
|
8216
|
+
`;
|
|
8217
|
+
}
|
|
8218
|
+
body += "\n";
|
|
8219
|
+
if (verdict.reason) {
|
|
8220
|
+
body += `**Reason:** ${verdict.reason}
|
|
8221
|
+
`;
|
|
8222
|
+
}
|
|
8223
|
+
if (verdict.ruleId) {
|
|
8224
|
+
body += `**Rule:** \`${verdict.ruleId}\`
|
|
8225
|
+
`;
|
|
8226
|
+
}
|
|
8227
|
+
if (verdict.evidence?.invariantsSatisfied < verdict.evidence?.invariantsTotal) {
|
|
8228
|
+
body += `**Invariants:** ${verdict.evidence.invariantsSatisfied}/${verdict.evidence.invariantsTotal} satisfied
|
|
8229
|
+
`;
|
|
8230
|
+
}
|
|
8231
|
+
body += "\n---\n*Evaluated by [NeuroVerse Governance](https://github.com/NeuroverseOS/neuroverseos-governance)*";
|
|
8232
|
+
return body;
|
|
8233
|
+
}
|
|
8234
|
+
async function createGitHubGovernor(worldPath, options) {
|
|
8235
|
+
const world = await loadWorld(worldPath);
|
|
8236
|
+
return new GitHubGovernor(world, options);
|
|
8237
|
+
}
|
|
8238
|
+
function createGitHubGovernorFromWorld(world, options) {
|
|
8239
|
+
return new GitHubGovernor(world, options);
|
|
8240
|
+
}
|
|
8241
|
+
async function createGitHubWebhookHandler(worldPath, options) {
|
|
8242
|
+
const world = await loadWorld(worldPath);
|
|
8243
|
+
return new GitHubWebhookHandler(world, options);
|
|
8244
|
+
}
|
|
8245
|
+
function createGitHubWebhookHandlerFromWorld(world, options) {
|
|
8246
|
+
return new GitHubWebhookHandler(world, options);
|
|
8247
|
+
}
|
|
8248
|
+
|
|
7806
8249
|
// src/engine/api.ts
|
|
7807
8250
|
init_world_loader();
|
|
7808
8251
|
function handleHealthCheck() {
|
|
@@ -7879,6 +8322,9 @@ function handleCreateCapsule(body) {
|
|
|
7879
8322
|
DERIVE_EXIT_CODES,
|
|
7880
8323
|
FileAuditLogger,
|
|
7881
8324
|
GUARD_EXIT_CODES,
|
|
8325
|
+
GitHubGovernanceBlockedError,
|
|
8326
|
+
GitHubGovernor,
|
|
8327
|
+
GitHubWebhookHandler,
|
|
7882
8328
|
McpGovernanceServer,
|
|
7883
8329
|
ModelAdapter,
|
|
7884
8330
|
PLAN_EXIT_CODES,
|
|
@@ -7898,6 +8344,10 @@ function handleCreateCapsule(body) {
|
|
|
7898
8344
|
classifyIntent,
|
|
7899
8345
|
classifyIntentWithAI,
|
|
7900
8346
|
createAgentState,
|
|
8347
|
+
createGitHubGovernor,
|
|
8348
|
+
createGitHubGovernorFromWorld,
|
|
8349
|
+
createGitHubWebhookHandler,
|
|
8350
|
+
createGitHubWebhookHandlerFromWorld,
|
|
7901
8351
|
createGovernanceEngine,
|
|
7902
8352
|
createGovernor,
|
|
7903
8353
|
deriveWorld,
|
|
@@ -7912,6 +8362,8 @@ function handleCreateCapsule(body) {
|
|
|
7912
8362
|
explainWorld,
|
|
7913
8363
|
extractContentFields,
|
|
7914
8364
|
extractWorldMarkdown,
|
|
8365
|
+
formatForActions,
|
|
8366
|
+
formatPRComment,
|
|
7915
8367
|
formatVerdict,
|
|
7916
8368
|
formatVerdictOneLine,
|
|
7917
8369
|
generateAdaptationNarrative,
|