@neuroverseos/governance 0.5.0 → 0.6.0
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 +244 -0
- 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.d.cts +4 -316
- package/dist/adapters/index.d.ts +4 -316
- package/dist/adapters/index.js +23 -21
- 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-LLH7KEV4.js → adapters/mentraos.js} +12 -10
- 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/admin/index.cjs +2214 -0
- package/dist/admin/index.d.cts +362 -0
- package/dist/admin/index.d.ts +362 -0
- package/dist/admin/index.js +703 -0
- package/dist/bootstrap-contract-DcV6t-8M.d.cts +216 -0
- package/dist/bootstrap-contract-DcV6t-8M.d.ts +216 -0
- package/dist/{build-SCAWPA7E.js → build-UTVDGHB3.js} +5 -5
- package/dist/{chunk-JKGPSFGH.js → chunk-7FL3U7Z5.js} +3 -3
- package/dist/chunk-A2UZTLRV.js +421 -0
- package/dist/{chunk-TD5GKIHP.js → chunk-B3IIPTY3.js} +3 -3
- package/dist/chunk-EQR7BGFN.js +337 -0
- package/dist/{chunk-5JUZ4HL7.js → chunk-FDPPZLSQ.js} +3 -3
- package/dist/{chunk-MFKHTE5R.js → chunk-FKQCPRKI.js} +3 -3
- package/dist/{chunk-7D7PZLB7.js → chunk-FS2UUJJO.js} +3 -3
- package/dist/{chunk-U6FRAEQJ.js → chunk-GJ6LM4JZ.js} +1 -441
- package/dist/chunk-H3REGQRI.js +107 -0
- package/dist/{chunk-25XHSTPT.js → chunk-HDNDL6D5.js} +3 -3
- package/dist/{chunk-BXLTEUS4.js → chunk-I4RTIMLX.js} +2 -2
- package/dist/chunk-IOVXB6QN.js +447 -0
- package/dist/{chunk-Y6WXAPKY.js → chunk-NTHXZAW4.js} +3 -3
- package/dist/{chunk-UTH7OXTM.js → chunk-OTZU76DH.js} +22 -4
- package/dist/{chunk-DWHUZUEY.js → chunk-T6GMRZWC.js} +3 -3
- package/dist/{chunk-V4FZHJQX.js → chunk-TIXVEPS2.js} +3 -3
- package/dist/{chunk-YNYCQECH.js → chunk-TJ5L2UTE.js} +3 -3
- package/dist/chunk-UGTNKTHS.js +542 -0
- package/dist/cli/neuroverse.cjs +3372 -523
- package/dist/cli/neuroverse.js +53 -21
- package/dist/cli/plan.js +2 -2
- package/dist/cli/run.cjs +242 -139
- package/dist/cli/run.js +23 -3
- package/dist/cli/worldmodel.cjs +1624 -0
- package/dist/cli/worldmodel.d.cts +24 -0
- package/dist/cli/worldmodel.d.ts +24 -0
- package/dist/cli/worldmodel.js +742 -0
- package/dist/{demo-66MMJTEH.js → demo-6W3YXLAX.js} +4 -4
- package/dist/{derive-AUQE3L3P.js → derive-42IJW7JI.js} +4 -4
- package/dist/{doctor-EY7LKSYY.js → doctor-XEMLO6UA.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/engine/worldmodel-compiler.cjs +366 -0
- package/dist/engine/worldmodel-compiler.d.cts +46 -0
- package/dist/engine/worldmodel-compiler.d.ts +46 -0
- package/dist/engine/worldmodel-compiler.js +17 -0
- package/dist/engine/worldmodel-parser.cjs +566 -0
- package/dist/engine/worldmodel-parser.d.cts +22 -0
- package/dist/engine/worldmodel-parser.d.ts +22 -0
- package/dist/engine/worldmodel-parser.js +7 -0
- package/dist/{equity-penalties-WWC7UDQD.js → equity-penalties-CCO3GVHS.js} +6 -6
- package/dist/{explain-MUSGDT67.js → explain-HDFN4ION.js} +1 -1
- package/dist/{guard-W3BMQPBJ.js → guard-IHJEKHL2.js} +16 -4
- 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-LRORRYEX.js} +3 -3
- package/dist/index.cjs +471 -1
- package/dist/index.d.cts +14 -492
- package/dist/index.d.ts +14 -492
- package/dist/index.js +63 -42
- package/dist/keygen-BSZH3NM2.js +77 -0
- package/dist/{lens-IP6GIZ2Q.js → lens-TLDZQXBI.js} +152 -26
- package/dist/{mcp-server-OG3PPVD2.js → mcp-server-CKYBHXWK.js} +2 -2
- package/dist/migrate-NH5PVMX4.js +221 -0
- package/dist/{playground-4BK2XQ47.js → playground-3TTBN7XD.js} +5 -5
- package/dist/{redteam-BRZALBPP.js → redteam-W644UMWN.js} +3 -3
- package/dist/{session-SGRUT2UH.js → session-FMAROEIE.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/sign-RRELHKWM.js +11 -0
- package/dist/{simulate-FGXKIH7V.js → simulate-VT437EEL.js} +2 -2
- package/dist/{test-PT44BSYG.js → test-XDB2DH3L.js} +3 -3
- 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/verify-6AVTWX75.js +151 -0
- package/dist/{world-V52ZMH26.js → world-O4HTQPDP.js} +1 -1
- package/dist/{world-loader-C4D3VPP3.js → world-loader-YTYFOP7D.js} +1 -1
- package/dist/worldmodel-contract-BPGhiuW5.d.cts +221 -0
- package/dist/worldmodel-contract-BPGhiuW5.d.ts +221 -0
- package/dist/worlds/auki-vanguard.worldmodel.md +116 -0
- package/dist/worlds/behavioral-demo.nv-world.md +130 -0
- package/dist/worlds/neuroverse-governance.worldmodel.md +115 -0
- package/package.json +44 -3
- package/dist/{bootstrap-IP5QMC3Q.js → bootstrap-2OW5ZLBL.js} +3 -3
- package/dist/{chunk-4G6WHPLI.js → chunk-735Z3HA4.js} +6 -6
- package/dist/{chunk-7QIAF377.js → chunk-CYDMUJVZ.js} +0 -0
- package/dist/{configure-ai-LL3VAPQW.js → configure-ai-5MP5DWTT.js} +3 -3
- package/dist/{decision-flow-3K4D72G4.js → decision-flow-IJPNMVQK.js} +3 -3
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { G as GuardVerdict, a as GuardEvent, b as GuardEngineOptions, P as PlanDefinition, c as PlanProgress } from '../guard-contract-ddiIPlOg.cjs';
|
|
2
|
+
import { WorldDefinition } from '../types.cjs';
|
|
3
|
+
import { G as GovernanceBlockedError } from '../shared-PpalGKxc.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* NeuroVerse Adapter — GitHub
|
|
7
|
+
*
|
|
8
|
+
* Governance middleware for GitHub-driven workflows. Evaluates GitHub events
|
|
9
|
+
* (PRs, issues, comments, pushes, releases, workflow runs) against world rules
|
|
10
|
+
* before allowing actions to proceed.
|
|
11
|
+
*
|
|
12
|
+
* Two modes:
|
|
13
|
+
* 1. Webhook mode — receives GitHub webhook payloads, evaluates, returns verdict
|
|
14
|
+
* 2. Action mode — wraps Octokit/GitHub API calls with governance checks
|
|
15
|
+
*
|
|
16
|
+
* Usage (Webhook):
|
|
17
|
+
* import { createGitHubWebhookHandler } from 'neuroverse-governance/adapters/github';
|
|
18
|
+
*
|
|
19
|
+
* const handler = await createGitHubWebhookHandler('./world/');
|
|
20
|
+
* app.post('/webhook', async (req, res) => {
|
|
21
|
+
* const verdict = handler.evaluate(req.headers['x-github-event'], req.body);
|
|
22
|
+
* if (verdict.status === 'BLOCK') return res.status(403).json({ blocked: true });
|
|
23
|
+
* // proceed with webhook processing...
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* Usage (Action):
|
|
27
|
+
* import { createGitHubGovernor } from 'neuroverse-governance/adapters/github';
|
|
28
|
+
*
|
|
29
|
+
* const gov = await createGitHubGovernor('./world/');
|
|
30
|
+
*
|
|
31
|
+
* // Before merging a PR:
|
|
32
|
+
* const verdict = gov.evaluate({
|
|
33
|
+
* action: 'merge_pull_request',
|
|
34
|
+
* repository: 'myorg/myrepo',
|
|
35
|
+
* ref: 'refs/heads/main',
|
|
36
|
+
* actor: 'dependabot[bot]',
|
|
37
|
+
* metadata: { pr_number: 42, labels: ['auto-merge'] },
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* if (verdict.status === 'ALLOW') await octokit.pulls.merge(...);
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/** GitHub webhook event names the adapter understands. */
|
|
44
|
+
type GitHubWebhookEvent = 'push' | 'pull_request' | 'pull_request_review' | 'issues' | 'issue_comment' | 'release' | 'workflow_run' | 'workflow_dispatch' | 'check_run' | 'check_suite' | 'deployment' | 'deployment_status' | 'create' | 'delete' | 'fork' | 'member' | 'repository' | 'status' | string;
|
|
45
|
+
/** A structured GitHub action to evaluate against governance. */
|
|
46
|
+
interface GitHubAction {
|
|
47
|
+
/** What the actor wants to do (e.g., 'merge_pull_request', 'push_to_main', 'create_release'). */
|
|
48
|
+
action: string;
|
|
49
|
+
/** Full repository name (e.g., 'myorg/myrepo'). */
|
|
50
|
+
repository: string;
|
|
51
|
+
/** Git ref involved (e.g., 'refs/heads/main', 'refs/tags/v1.0.0'). */
|
|
52
|
+
ref?: string;
|
|
53
|
+
/** GitHub username or bot performing the action. */
|
|
54
|
+
actor?: string;
|
|
55
|
+
/** Branch being targeted (extracted from ref or PR base). */
|
|
56
|
+
branch?: string;
|
|
57
|
+
/** Additional context for guard evaluation. */
|
|
58
|
+
metadata?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/** Result of evaluating a GitHub action. */
|
|
61
|
+
interface GitHubGovernanceResult {
|
|
62
|
+
/** The guard verdict. */
|
|
63
|
+
verdict: GuardVerdict;
|
|
64
|
+
/** The GuardEvent that was evaluated (for audit/logging). */
|
|
65
|
+
event: GuardEvent;
|
|
66
|
+
/** The original action that triggered evaluation. */
|
|
67
|
+
action: GitHubAction;
|
|
68
|
+
}
|
|
69
|
+
/** Result of evaluating a webhook payload. */
|
|
70
|
+
interface WebhookGovernanceResult {
|
|
71
|
+
/** The guard verdict. */
|
|
72
|
+
verdict: GuardVerdict;
|
|
73
|
+
/** The GuardEvent that was evaluated. */
|
|
74
|
+
event: GuardEvent;
|
|
75
|
+
/** The webhook event type. */
|
|
76
|
+
webhookEvent: string;
|
|
77
|
+
/** The webhook action (e.g., 'opened', 'closed', 'merged'). */
|
|
78
|
+
webhookAction?: string;
|
|
79
|
+
}
|
|
80
|
+
interface GitHubGovernorOptions {
|
|
81
|
+
/** Include full evaluation trace in verdicts. Default: false. */
|
|
82
|
+
trace?: boolean;
|
|
83
|
+
/** Enforcement level override. */
|
|
84
|
+
level?: 'basic' | 'standard' | 'strict';
|
|
85
|
+
/** Called for every evaluation (logging/audit hook). */
|
|
86
|
+
onEvaluate?: (verdict: GuardVerdict, event: GuardEvent, action: GitHubAction) => void;
|
|
87
|
+
/** Custom mapping from GitHubAction to GuardEvent. */
|
|
88
|
+
mapAction?: (action: GitHubAction) => GuardEvent;
|
|
89
|
+
/** Active plan overlay for task-scoped governance. */
|
|
90
|
+
plan?: PlanDefinition;
|
|
91
|
+
/** Called when plan progress changes. */
|
|
92
|
+
onPlanProgress?: (progress: PlanProgress) => void;
|
|
93
|
+
/** Called when all plan steps are completed. */
|
|
94
|
+
onPlanComplete?: () => void;
|
|
95
|
+
/** Protected branches that require strict governance. Default: ['main', 'master', 'production']. */
|
|
96
|
+
protectedBranches?: string[];
|
|
97
|
+
/** Actors (bots, users) with restricted permissions. */
|
|
98
|
+
restrictedActors?: string[];
|
|
99
|
+
}
|
|
100
|
+
interface WebhookHandlerOptions extends GitHubGovernorOptions {
|
|
101
|
+
/** Webhook secret for signature verification (HMAC-SHA256). */
|
|
102
|
+
webhookSecret?: string;
|
|
103
|
+
/** Custom mapping from webhook payload to GitHubAction. */
|
|
104
|
+
mapWebhook?: (eventType: string, payload: Record<string, unknown>) => GitHubAction;
|
|
105
|
+
}
|
|
106
|
+
declare class GitHubGovernanceBlockedError extends GovernanceBlockedError {
|
|
107
|
+
readonly action: GitHubAction;
|
|
108
|
+
constructor(verdict: GuardVerdict, action: GitHubAction);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Evaluates GitHub actions against a NeuroVerse world.
|
|
112
|
+
* Use this when you're making GitHub API calls and want governance
|
|
113
|
+
* to approve/block them before execution.
|
|
114
|
+
*/
|
|
115
|
+
declare class GitHubGovernor {
|
|
116
|
+
private world;
|
|
117
|
+
private options;
|
|
118
|
+
engineOptions: GuardEngineOptions;
|
|
119
|
+
activePlan?: PlanDefinition;
|
|
120
|
+
private protectedBranches;
|
|
121
|
+
private restrictedActors;
|
|
122
|
+
private mapFn;
|
|
123
|
+
constructor(world: WorldDefinition, options?: GitHubGovernorOptions);
|
|
124
|
+
/**
|
|
125
|
+
* Evaluate a GitHub action against governance rules.
|
|
126
|
+
* Returns a full result with verdict, event, and the original action.
|
|
127
|
+
*/
|
|
128
|
+
evaluate(action: GitHubAction): GitHubGovernanceResult;
|
|
129
|
+
/**
|
|
130
|
+
* Evaluate and enforce — throws GitHubGovernanceBlockedError on BLOCK/PAUSE.
|
|
131
|
+
* Use this as a gate before executing GitHub API calls.
|
|
132
|
+
*/
|
|
133
|
+
enforce(action: GitHubAction): GitHubGovernanceResult;
|
|
134
|
+
/**
|
|
135
|
+
* Check if pushing to a branch is allowed.
|
|
136
|
+
* Convenience method for the most common governance check.
|
|
137
|
+
*/
|
|
138
|
+
canPush(repository: string, branch: string, actor?: string): GuardVerdict;
|
|
139
|
+
/**
|
|
140
|
+
* Check if merging a PR is allowed.
|
|
141
|
+
*/
|
|
142
|
+
canMerge(repository: string, targetBranch: string, prNumber: number, actor?: string, labels?: string[]): GuardVerdict;
|
|
143
|
+
/**
|
|
144
|
+
* Check if creating a release is allowed.
|
|
145
|
+
*/
|
|
146
|
+
canRelease(repository: string, tag: string, actor?: string, prerelease?: boolean): GuardVerdict;
|
|
147
|
+
/**
|
|
148
|
+
* Check if deploying to an environment is allowed.
|
|
149
|
+
*/
|
|
150
|
+
canDeploy(repository: string, environment: string, ref?: string, actor?: string): GuardVerdict;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Evaluates incoming GitHub webhook payloads against a NeuroVerse world.
|
|
154
|
+
* Use this in your webhook endpoint to govern repository events.
|
|
155
|
+
*/
|
|
156
|
+
declare class GitHubWebhookHandler {
|
|
157
|
+
private governor;
|
|
158
|
+
private mapWebhookFn;
|
|
159
|
+
private webhookSecret?;
|
|
160
|
+
constructor(world: WorldDefinition, options?: WebhookHandlerOptions);
|
|
161
|
+
/**
|
|
162
|
+
* Evaluate a webhook payload.
|
|
163
|
+
*
|
|
164
|
+
* @param eventType - The X-GitHub-Event header value
|
|
165
|
+
* @param payload - The parsed webhook body
|
|
166
|
+
*/
|
|
167
|
+
evaluate(eventType: string, payload: Record<string, unknown>): WebhookGovernanceResult;
|
|
168
|
+
/**
|
|
169
|
+
* Evaluate and enforce — throws on BLOCK/PAUSE.
|
|
170
|
+
*/
|
|
171
|
+
enforce(eventType: string, payload: Record<string, unknown>): WebhookGovernanceResult;
|
|
172
|
+
/** Access the underlying governor for direct action evaluation. */
|
|
173
|
+
getGovernor(): GitHubGovernor;
|
|
174
|
+
/** Get the configured webhook secret (for signature verification in your server). */
|
|
175
|
+
getWebhookSecret(): string | undefined;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Guard evaluation result formatted for GitHub Actions output.
|
|
179
|
+
* Set step outputs and write to $GITHUB_OUTPUT.
|
|
180
|
+
*/
|
|
181
|
+
interface ActionsOutput {
|
|
182
|
+
/** 'allowed' or 'blocked' or 'paused' — for use in step conditions */
|
|
183
|
+
governance_status: string;
|
|
184
|
+
/** The full verdict status */
|
|
185
|
+
verdict_status: string;
|
|
186
|
+
/** Reason for block/pause (empty string if allowed) */
|
|
187
|
+
reason: string;
|
|
188
|
+
/** Matched rule ID (empty string if none) */
|
|
189
|
+
rule_id: string;
|
|
190
|
+
/** Formatted as GITHUB_OUTPUT lines */
|
|
191
|
+
outputLines: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Format a verdict for GitHub Actions step outputs.
|
|
195
|
+
* Write the .outputLines to $GITHUB_OUTPUT in your action.
|
|
196
|
+
*
|
|
197
|
+
* Usage in a GitHub Action:
|
|
198
|
+
* const result = governor.evaluate(action);
|
|
199
|
+
* const output = formatForActions(result.verdict);
|
|
200
|
+
* fs.appendFileSync(process.env.GITHUB_OUTPUT!, output.outputLines);
|
|
201
|
+
*/
|
|
202
|
+
declare function formatForActions(verdict: GuardVerdict): ActionsOutput;
|
|
203
|
+
/**
|
|
204
|
+
* Create a PR comment body from a governance verdict.
|
|
205
|
+
* Useful for posting governance status as a PR comment.
|
|
206
|
+
*/
|
|
207
|
+
declare function formatPRComment(verdict: GuardVerdict, action: GitHubAction): string;
|
|
208
|
+
/**
|
|
209
|
+
* Create a GitHub Governor from a world path.
|
|
210
|
+
*/
|
|
211
|
+
declare function createGitHubGovernor(worldPath: string, options?: GitHubGovernorOptions): Promise<GitHubGovernor>;
|
|
212
|
+
/**
|
|
213
|
+
* Create a GitHub Governor from a pre-loaded world.
|
|
214
|
+
*/
|
|
215
|
+
declare function createGitHubGovernorFromWorld(world: WorldDefinition, options?: GitHubGovernorOptions): GitHubGovernor;
|
|
216
|
+
/**
|
|
217
|
+
* Create a GitHub Webhook Handler from a world path.
|
|
218
|
+
*/
|
|
219
|
+
declare function createGitHubWebhookHandler(worldPath: string, options?: WebhookHandlerOptions): Promise<GitHubWebhookHandler>;
|
|
220
|
+
/**
|
|
221
|
+
* Create a GitHub Webhook Handler from a pre-loaded world.
|
|
222
|
+
*/
|
|
223
|
+
declare function createGitHubWebhookHandlerFromWorld(world: WorldDefinition, options?: WebhookHandlerOptions): GitHubWebhookHandler;
|
|
224
|
+
|
|
225
|
+
export { type ActionsOutput, type GitHubAction, GitHubGovernanceBlockedError, type GitHubGovernanceResult, GitHubGovernor, type GitHubGovernorOptions, type GitHubWebhookEvent, GitHubWebhookHandler, type WebhookGovernanceResult, type WebhookHandlerOptions, createGitHubGovernor, createGitHubGovernorFromWorld, createGitHubWebhookHandler, createGitHubWebhookHandlerFromWorld, formatForActions, formatPRComment };
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { G as GuardVerdict, a as GuardEvent, b as GuardEngineOptions, P as PlanDefinition, c as PlanProgress } from '../guard-contract-q6HJAq3Q.js';
|
|
2
|
+
import { WorldDefinition } from '../types.js';
|
|
3
|
+
import { G as GovernanceBlockedError } from '../shared-DAzdfWtU.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* NeuroVerse Adapter — GitHub
|
|
7
|
+
*
|
|
8
|
+
* Governance middleware for GitHub-driven workflows. Evaluates GitHub events
|
|
9
|
+
* (PRs, issues, comments, pushes, releases, workflow runs) against world rules
|
|
10
|
+
* before allowing actions to proceed.
|
|
11
|
+
*
|
|
12
|
+
* Two modes:
|
|
13
|
+
* 1. Webhook mode — receives GitHub webhook payloads, evaluates, returns verdict
|
|
14
|
+
* 2. Action mode — wraps Octokit/GitHub API calls with governance checks
|
|
15
|
+
*
|
|
16
|
+
* Usage (Webhook):
|
|
17
|
+
* import { createGitHubWebhookHandler } from 'neuroverse-governance/adapters/github';
|
|
18
|
+
*
|
|
19
|
+
* const handler = await createGitHubWebhookHandler('./world/');
|
|
20
|
+
* app.post('/webhook', async (req, res) => {
|
|
21
|
+
* const verdict = handler.evaluate(req.headers['x-github-event'], req.body);
|
|
22
|
+
* if (verdict.status === 'BLOCK') return res.status(403).json({ blocked: true });
|
|
23
|
+
* // proceed with webhook processing...
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* Usage (Action):
|
|
27
|
+
* import { createGitHubGovernor } from 'neuroverse-governance/adapters/github';
|
|
28
|
+
*
|
|
29
|
+
* const gov = await createGitHubGovernor('./world/');
|
|
30
|
+
*
|
|
31
|
+
* // Before merging a PR:
|
|
32
|
+
* const verdict = gov.evaluate({
|
|
33
|
+
* action: 'merge_pull_request',
|
|
34
|
+
* repository: 'myorg/myrepo',
|
|
35
|
+
* ref: 'refs/heads/main',
|
|
36
|
+
* actor: 'dependabot[bot]',
|
|
37
|
+
* metadata: { pr_number: 42, labels: ['auto-merge'] },
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* if (verdict.status === 'ALLOW') await octokit.pulls.merge(...);
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/** GitHub webhook event names the adapter understands. */
|
|
44
|
+
type GitHubWebhookEvent = 'push' | 'pull_request' | 'pull_request_review' | 'issues' | 'issue_comment' | 'release' | 'workflow_run' | 'workflow_dispatch' | 'check_run' | 'check_suite' | 'deployment' | 'deployment_status' | 'create' | 'delete' | 'fork' | 'member' | 'repository' | 'status' | string;
|
|
45
|
+
/** A structured GitHub action to evaluate against governance. */
|
|
46
|
+
interface GitHubAction {
|
|
47
|
+
/** What the actor wants to do (e.g., 'merge_pull_request', 'push_to_main', 'create_release'). */
|
|
48
|
+
action: string;
|
|
49
|
+
/** Full repository name (e.g., 'myorg/myrepo'). */
|
|
50
|
+
repository: string;
|
|
51
|
+
/** Git ref involved (e.g., 'refs/heads/main', 'refs/tags/v1.0.0'). */
|
|
52
|
+
ref?: string;
|
|
53
|
+
/** GitHub username or bot performing the action. */
|
|
54
|
+
actor?: string;
|
|
55
|
+
/** Branch being targeted (extracted from ref or PR base). */
|
|
56
|
+
branch?: string;
|
|
57
|
+
/** Additional context for guard evaluation. */
|
|
58
|
+
metadata?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/** Result of evaluating a GitHub action. */
|
|
61
|
+
interface GitHubGovernanceResult {
|
|
62
|
+
/** The guard verdict. */
|
|
63
|
+
verdict: GuardVerdict;
|
|
64
|
+
/** The GuardEvent that was evaluated (for audit/logging). */
|
|
65
|
+
event: GuardEvent;
|
|
66
|
+
/** The original action that triggered evaluation. */
|
|
67
|
+
action: GitHubAction;
|
|
68
|
+
}
|
|
69
|
+
/** Result of evaluating a webhook payload. */
|
|
70
|
+
interface WebhookGovernanceResult {
|
|
71
|
+
/** The guard verdict. */
|
|
72
|
+
verdict: GuardVerdict;
|
|
73
|
+
/** The GuardEvent that was evaluated. */
|
|
74
|
+
event: GuardEvent;
|
|
75
|
+
/** The webhook event type. */
|
|
76
|
+
webhookEvent: string;
|
|
77
|
+
/** The webhook action (e.g., 'opened', 'closed', 'merged'). */
|
|
78
|
+
webhookAction?: string;
|
|
79
|
+
}
|
|
80
|
+
interface GitHubGovernorOptions {
|
|
81
|
+
/** Include full evaluation trace in verdicts. Default: false. */
|
|
82
|
+
trace?: boolean;
|
|
83
|
+
/** Enforcement level override. */
|
|
84
|
+
level?: 'basic' | 'standard' | 'strict';
|
|
85
|
+
/** Called for every evaluation (logging/audit hook). */
|
|
86
|
+
onEvaluate?: (verdict: GuardVerdict, event: GuardEvent, action: GitHubAction) => void;
|
|
87
|
+
/** Custom mapping from GitHubAction to GuardEvent. */
|
|
88
|
+
mapAction?: (action: GitHubAction) => GuardEvent;
|
|
89
|
+
/** Active plan overlay for task-scoped governance. */
|
|
90
|
+
plan?: PlanDefinition;
|
|
91
|
+
/** Called when plan progress changes. */
|
|
92
|
+
onPlanProgress?: (progress: PlanProgress) => void;
|
|
93
|
+
/** Called when all plan steps are completed. */
|
|
94
|
+
onPlanComplete?: () => void;
|
|
95
|
+
/** Protected branches that require strict governance. Default: ['main', 'master', 'production']. */
|
|
96
|
+
protectedBranches?: string[];
|
|
97
|
+
/** Actors (bots, users) with restricted permissions. */
|
|
98
|
+
restrictedActors?: string[];
|
|
99
|
+
}
|
|
100
|
+
interface WebhookHandlerOptions extends GitHubGovernorOptions {
|
|
101
|
+
/** Webhook secret for signature verification (HMAC-SHA256). */
|
|
102
|
+
webhookSecret?: string;
|
|
103
|
+
/** Custom mapping from webhook payload to GitHubAction. */
|
|
104
|
+
mapWebhook?: (eventType: string, payload: Record<string, unknown>) => GitHubAction;
|
|
105
|
+
}
|
|
106
|
+
declare class GitHubGovernanceBlockedError extends GovernanceBlockedError {
|
|
107
|
+
readonly action: GitHubAction;
|
|
108
|
+
constructor(verdict: GuardVerdict, action: GitHubAction);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Evaluates GitHub actions against a NeuroVerse world.
|
|
112
|
+
* Use this when you're making GitHub API calls and want governance
|
|
113
|
+
* to approve/block them before execution.
|
|
114
|
+
*/
|
|
115
|
+
declare class GitHubGovernor {
|
|
116
|
+
private world;
|
|
117
|
+
private options;
|
|
118
|
+
engineOptions: GuardEngineOptions;
|
|
119
|
+
activePlan?: PlanDefinition;
|
|
120
|
+
private protectedBranches;
|
|
121
|
+
private restrictedActors;
|
|
122
|
+
private mapFn;
|
|
123
|
+
constructor(world: WorldDefinition, options?: GitHubGovernorOptions);
|
|
124
|
+
/**
|
|
125
|
+
* Evaluate a GitHub action against governance rules.
|
|
126
|
+
* Returns a full result with verdict, event, and the original action.
|
|
127
|
+
*/
|
|
128
|
+
evaluate(action: GitHubAction): GitHubGovernanceResult;
|
|
129
|
+
/**
|
|
130
|
+
* Evaluate and enforce — throws GitHubGovernanceBlockedError on BLOCK/PAUSE.
|
|
131
|
+
* Use this as a gate before executing GitHub API calls.
|
|
132
|
+
*/
|
|
133
|
+
enforce(action: GitHubAction): GitHubGovernanceResult;
|
|
134
|
+
/**
|
|
135
|
+
* Check if pushing to a branch is allowed.
|
|
136
|
+
* Convenience method for the most common governance check.
|
|
137
|
+
*/
|
|
138
|
+
canPush(repository: string, branch: string, actor?: string): GuardVerdict;
|
|
139
|
+
/**
|
|
140
|
+
* Check if merging a PR is allowed.
|
|
141
|
+
*/
|
|
142
|
+
canMerge(repository: string, targetBranch: string, prNumber: number, actor?: string, labels?: string[]): GuardVerdict;
|
|
143
|
+
/**
|
|
144
|
+
* Check if creating a release is allowed.
|
|
145
|
+
*/
|
|
146
|
+
canRelease(repository: string, tag: string, actor?: string, prerelease?: boolean): GuardVerdict;
|
|
147
|
+
/**
|
|
148
|
+
* Check if deploying to an environment is allowed.
|
|
149
|
+
*/
|
|
150
|
+
canDeploy(repository: string, environment: string, ref?: string, actor?: string): GuardVerdict;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Evaluates incoming GitHub webhook payloads against a NeuroVerse world.
|
|
154
|
+
* Use this in your webhook endpoint to govern repository events.
|
|
155
|
+
*/
|
|
156
|
+
declare class GitHubWebhookHandler {
|
|
157
|
+
private governor;
|
|
158
|
+
private mapWebhookFn;
|
|
159
|
+
private webhookSecret?;
|
|
160
|
+
constructor(world: WorldDefinition, options?: WebhookHandlerOptions);
|
|
161
|
+
/**
|
|
162
|
+
* Evaluate a webhook payload.
|
|
163
|
+
*
|
|
164
|
+
* @param eventType - The X-GitHub-Event header value
|
|
165
|
+
* @param payload - The parsed webhook body
|
|
166
|
+
*/
|
|
167
|
+
evaluate(eventType: string, payload: Record<string, unknown>): WebhookGovernanceResult;
|
|
168
|
+
/**
|
|
169
|
+
* Evaluate and enforce — throws on BLOCK/PAUSE.
|
|
170
|
+
*/
|
|
171
|
+
enforce(eventType: string, payload: Record<string, unknown>): WebhookGovernanceResult;
|
|
172
|
+
/** Access the underlying governor for direct action evaluation. */
|
|
173
|
+
getGovernor(): GitHubGovernor;
|
|
174
|
+
/** Get the configured webhook secret (for signature verification in your server). */
|
|
175
|
+
getWebhookSecret(): string | undefined;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Guard evaluation result formatted for GitHub Actions output.
|
|
179
|
+
* Set step outputs and write to $GITHUB_OUTPUT.
|
|
180
|
+
*/
|
|
181
|
+
interface ActionsOutput {
|
|
182
|
+
/** 'allowed' or 'blocked' or 'paused' — for use in step conditions */
|
|
183
|
+
governance_status: string;
|
|
184
|
+
/** The full verdict status */
|
|
185
|
+
verdict_status: string;
|
|
186
|
+
/** Reason for block/pause (empty string if allowed) */
|
|
187
|
+
reason: string;
|
|
188
|
+
/** Matched rule ID (empty string if none) */
|
|
189
|
+
rule_id: string;
|
|
190
|
+
/** Formatted as GITHUB_OUTPUT lines */
|
|
191
|
+
outputLines: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Format a verdict for GitHub Actions step outputs.
|
|
195
|
+
* Write the .outputLines to $GITHUB_OUTPUT in your action.
|
|
196
|
+
*
|
|
197
|
+
* Usage in a GitHub Action:
|
|
198
|
+
* const result = governor.evaluate(action);
|
|
199
|
+
* const output = formatForActions(result.verdict);
|
|
200
|
+
* fs.appendFileSync(process.env.GITHUB_OUTPUT!, output.outputLines);
|
|
201
|
+
*/
|
|
202
|
+
declare function formatForActions(verdict: GuardVerdict): ActionsOutput;
|
|
203
|
+
/**
|
|
204
|
+
* Create a PR comment body from a governance verdict.
|
|
205
|
+
* Useful for posting governance status as a PR comment.
|
|
206
|
+
*/
|
|
207
|
+
declare function formatPRComment(verdict: GuardVerdict, action: GitHubAction): string;
|
|
208
|
+
/**
|
|
209
|
+
* Create a GitHub Governor from a world path.
|
|
210
|
+
*/
|
|
211
|
+
declare function createGitHubGovernor(worldPath: string, options?: GitHubGovernorOptions): Promise<GitHubGovernor>;
|
|
212
|
+
/**
|
|
213
|
+
* Create a GitHub Governor from a pre-loaded world.
|
|
214
|
+
*/
|
|
215
|
+
declare function createGitHubGovernorFromWorld(world: WorldDefinition, options?: GitHubGovernorOptions): GitHubGovernor;
|
|
216
|
+
/**
|
|
217
|
+
* Create a GitHub Webhook Handler from a world path.
|
|
218
|
+
*/
|
|
219
|
+
declare function createGitHubWebhookHandler(worldPath: string, options?: WebhookHandlerOptions): Promise<GitHubWebhookHandler>;
|
|
220
|
+
/**
|
|
221
|
+
* Create a GitHub Webhook Handler from a pre-loaded world.
|
|
222
|
+
*/
|
|
223
|
+
declare function createGitHubWebhookHandlerFromWorld(world: WorldDefinition, options?: WebhookHandlerOptions): GitHubWebhookHandler;
|
|
224
|
+
|
|
225
|
+
export { type ActionsOutput, type GitHubAction, GitHubGovernanceBlockedError, type GitHubGovernanceResult, GitHubGovernor, type GitHubGovernorOptions, type GitHubWebhookEvent, GitHubWebhookHandler, type WebhookGovernanceResult, type WebhookHandlerOptions, createGitHubGovernor, createGitHubGovernorFromWorld, createGitHubWebhookHandler, createGitHubWebhookHandlerFromWorld, formatForActions, formatPRComment };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GitHubGovernanceBlockedError,
|
|
3
|
+
GitHubGovernor,
|
|
4
|
+
GitHubWebhookHandler,
|
|
5
|
+
createGitHubGovernor,
|
|
6
|
+
createGitHubGovernorFromWorld,
|
|
7
|
+
createGitHubWebhookHandler,
|
|
8
|
+
createGitHubWebhookHandlerFromWorld,
|
|
9
|
+
formatForActions,
|
|
10
|
+
formatPRComment
|
|
11
|
+
} from "../chunk-A2UZTLRV.js";
|
|
12
|
+
import "../chunk-5U2MQO5P.js";
|
|
13
|
+
import "../chunk-I4RTIMLX.js";
|
|
14
|
+
import "../chunk-ZAF6JH23.js";
|
|
15
|
+
import "../chunk-QLPTHTVB.js";
|
|
16
|
+
import "../chunk-QWGCMQQD.js";
|
|
17
|
+
export {
|
|
18
|
+
GitHubGovernanceBlockedError,
|
|
19
|
+
GitHubGovernor,
|
|
20
|
+
GitHubWebhookHandler,
|
|
21
|
+
createGitHubGovernor,
|
|
22
|
+
createGitHubGovernorFromWorld,
|
|
23
|
+
createGitHubWebhookHandler,
|
|
24
|
+
createGitHubWebhookHandlerFromWorld,
|
|
25
|
+
formatForActions,
|
|
26
|
+
formatPRComment
|
|
27
|
+
};
|