0xray 2.1.4 → 2.2.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/dist/CHANGELOG.md +31 -0
- package/dist/cli/commands/govern.d.ts +29 -0
- package/dist/cli/commands/govern.js +152 -0
- package/dist/cli/index.js +29 -216
- package/dist/core/framework-logger.js +30 -1
- package/dist/delegation/index.d.ts +1 -2
- package/dist/delegation/index.js +1 -2
- package/dist/enforcement/enforcer-tools.js +1 -1
- package/dist/execution/proposal-applier.d.ts +1 -9
- package/dist/execution/proposal-applier.js +18 -173
- package/dist/governance/codex-policy.service.d.ts +7 -25
- package/dist/governance/codex-policy.service.js +8 -26
- package/dist/governance/governance-core.d.ts +22 -28
- package/dist/governance/governance-core.js +31 -101
- package/dist/governance/governance-service.d.ts +1 -0
- package/dist/governance/governance-service.js +67 -4
- package/dist/governance/governance-types.d.ts +5 -2
- package/dist/inference/index.d.ts +3 -4
- package/dist/inference/inference-accumulator.js +1 -1
- package/dist/inference/inference-cycle.d.ts +12 -18
- package/dist/inference/inference-cycle.js +120 -335
- package/dist/integrations/base/index.d.ts +0 -1
- package/dist/integrations/base/index.js +0 -2
- package/dist/integrations/grok/hooks/pre-tool-use.js +4 -18
- package/dist/integrations/hermes-agent/bridge.mjs +9 -0
- package/dist/mcps/config/server-config-registry.js +1 -1
- package/dist/mcps/governance.server.js +3 -4
- package/dist/mcps/knowledge-skills/api-design.server.js +10 -0
- package/dist/mcps/knowledge-skills/architecture-patterns.server.js +10 -0
- package/dist/mcps/knowledge-skills/bug-triage-specialist.server.js +10 -0
- package/dist/mcps/knowledge-skills/code-analyzer.server.js +10 -0
- package/dist/mcps/knowledge-skills/code-review.server.js +10 -0
- package/dist/mcps/knowledge-skills/content-creator.server.js +10 -0
- package/dist/mcps/knowledge-skills/database-design.server.js +10 -0
- package/dist/mcps/knowledge-skills/devops-deployment.server.js +10 -0
- package/dist/mcps/knowledge-skills/git-workflow.server.js +10 -0
- package/dist/mcps/knowledge-skills/growth-strategist.server.js +10 -0
- package/dist/mcps/knowledge-skills/log-monitor.server.js +10 -0
- package/dist/mcps/knowledge-skills/mobile-development.server.js +10 -0
- package/dist/mcps/knowledge-skills/multimodal-looker.server.js +10 -0
- package/dist/mcps/knowledge-skills/performance-optimization.server.js +10 -0
- package/dist/mcps/knowledge-skills/project-analysis.server.js +10 -0
- package/dist/mcps/knowledge-skills/refactoring-strategies.server.js +10 -0
- package/dist/mcps/knowledge-skills/security-audit.server.js +10 -0
- package/dist/mcps/knowledge-skills/seo-consultant.server.js +10 -0
- package/dist/mcps/knowledge-skills/skill-invocation.server.d.ts +4 -0
- package/dist/mcps/knowledge-skills/skill-invocation.server.js +33 -14
- package/dist/mcps/knowledge-skills/strategist.server.js +10 -0
- package/dist/mcps/knowledge-skills/tech-writer.server.js +10 -0
- package/dist/mcps/knowledge-skills/testing-strategy.server.js +10 -0
- package/dist/mcps/knowledge-skills/ui-ux-design.server.js +10 -0
- package/dist/metrics/agent-metrics.d.ts +2 -1
- package/dist/nucleus/govern-http.d.ts +59 -0
- package/dist/nucleus/govern-http.js +172 -0
- package/dist/nucleus/index.d.ts +14 -0
- package/dist/nucleus/index.js +9 -0
- package/dist/nucleus/kernel.d.ts +51 -0
- package/dist/nucleus/kernel.js +62 -0
- package/dist/nucleus/plugin-registry.d.ts +104 -0
- package/dist/nucleus/plugin-registry.js +147 -0
- package/dist/orchestrator/orchestrator.d.ts +0 -1
- package/dist/orchestrator/orchestrator.js +0 -21
- package/dist/postprocessor/PostProcessor.d.ts +13 -1
- package/dist/postprocessor/PostProcessor.js +41 -1
- package/dist/postprocessor/autofix/AutoFixEngine.d.ts +0 -8
- package/dist/postprocessor/autofix/AutoFixEngine.js +0 -54
- package/dist/postprocessor/metamorphosis/MetamorphosisEngine.d.ts +25 -0
- package/dist/postprocessor/metamorphosis/MetamorphosisEngine.js +10 -0
- package/dist/postprocessor/metamorphosis/SelfProposalEngine.d.ts +68 -0
- package/dist/postprocessor/metamorphosis/SelfProposalEngine.js +371 -0
- package/dist/skills/orchestrator/SKILL.md +1 -1
- package/dist/state/index.d.ts +0 -2
- package/package.json +4 -3
- package/scripts/node/universal-version-manager.js +2 -2
- package/src/mcps/config/__tests__/server-config-registry.test.ts +6 -15
- package/src/mcps/config/server-config-registry.ts +1 -1
- package/src/mcps/governance.server.ts +3 -5
- package/src/mcps/knowledge-skills/api-design.server.ts +9 -0
- package/src/mcps/knowledge-skills/architecture-patterns.server.ts +9 -0
- package/src/mcps/knowledge-skills/bug-triage-specialist.server.ts +9 -0
- package/src/mcps/knowledge-skills/code-analyzer.server.ts +9 -0
- package/src/mcps/knowledge-skills/code-review.server.ts +9 -0
- package/src/mcps/knowledge-skills/content-creator.server.ts +9 -0
- package/src/mcps/knowledge-skills/database-design.server.ts +9 -0
- package/src/mcps/knowledge-skills/devops-deployment.server.ts +9 -0
- package/src/mcps/knowledge-skills/git-workflow.server.ts +9 -0
- package/src/mcps/knowledge-skills/growth-strategist.server.ts +9 -0
- package/src/mcps/knowledge-skills/log-monitor.server.ts +9 -0
- package/src/mcps/knowledge-skills/mobile-development.server.ts +9 -0
- package/src/mcps/knowledge-skills/multimodal-looker.server.ts +9 -0
- package/src/mcps/knowledge-skills/performance-optimization.server.ts +9 -0
- package/src/mcps/knowledge-skills/project-analysis.server.ts +9 -0
- package/src/mcps/knowledge-skills/refactoring-strategies.server.ts +9 -0
- package/src/mcps/knowledge-skills/security-audit.server.ts +9 -0
- package/src/mcps/knowledge-skills/seo-consultant.server.ts +9 -0
- package/src/mcps/knowledge-skills/session-management.server.ts +1 -0
- package/src/mcps/knowledge-skills/skill-invocation.server.ts +44 -29
- package/src/mcps/knowledge-skills/strategist.server.ts +9 -0
- package/src/mcps/knowledge-skills/tech-writer.server.ts +9 -0
- package/src/mcps/knowledge-skills/testing-strategy.server.ts +9 -0
- package/src/mcps/knowledge-skills/ui-ux-design.server.ts +9 -0
- package/src/skills/orchestrator/SKILL.md +1 -1
- package/.opencode/agents/testing-best-practices.yml +0 -12
- package/dist/analytics/consent-manager.d.ts +0 -93
- package/dist/analytics/consent-manager.js +0 -258
- package/dist/analytics/simple-pattern-analyzer.d.ts +0 -80
- package/dist/analytics/simple-pattern-analyzer.js +0 -297
- package/dist/cli/commands/analytics-disable.d.ts +0 -9
- package/dist/cli/commands/analytics-disable.js +0 -72
- package/dist/cli/commands/analytics-enable-action.d.ts +0 -8
- package/dist/cli/commands/analytics-enable-action.js +0 -82
- package/dist/cli/commands/analytics-preview.d.ts +0 -9
- package/dist/cli/commands/analytics-preview.js +0 -106
- package/dist/cli/commands/analytics-status.d.ts +0 -9
- package/dist/cli/commands/analytics-status.js +0 -68
- package/dist/cli/server.d.ts +0 -1
- package/dist/cli/server.js +0 -147
- package/dist/core/errors.d.ts +0 -3
- package/dist/core/errors.js +0 -10
- package/dist/core/logging-config.d.ts +0 -11
- package/dist/core/logging-config.js +0 -43
- package/dist/core/trace-context.d.ts +0 -12
- package/dist/core/trace-context.js +0 -33
- package/dist/delegation/voting-coordinator.d.ts +0 -49
- package/dist/delegation/voting-coordinator.js +0 -375
- package/dist/enforcement/test-auto-healing.d.ts +0 -83
- package/dist/enforcement/test-auto-healing.js +0 -325
- package/dist/integrations/base/ExampleIntegration.d.ts +0 -47
- package/dist/integrations/base/ExampleIntegration.js +0 -181
- package/dist/mcps/knowledge-skills/testing-best-practices.server.d.ts +0 -34
- package/dist/mcps/knowledge-skills/testing-best-practices.server.js +0 -831
- package/dist/mcps/orchestrator.server.d.ts +0 -10
- package/dist/mcps/orchestrator.server.js +0 -19
- package/dist/orchestrator/self-direction-activation.d.ts +0 -109
- package/dist/orchestrator/self-direction-activation.js +0 -245
- package/dist/orchestrator/universal-librarian-consultation.d.ts +0 -98
- package/dist/orchestrator/universal-librarian-consultation.js +0 -216
- package/dist/orchestrator/universal-registry-bridge.d.ts +0 -85
- package/dist/orchestrator/universal-registry-bridge.js +0 -247
- package/dist/performance/performance-budget-enforcer.d.ts +0 -158
- package/dist/performance/performance-budget-enforcer.js +0 -434
- package/dist/performance/performance-regression-tester.d.ts +0 -108
- package/dist/performance/performance-regression-tester.js +0 -342
- package/dist/skills/testing-best-practices/SKILL.md +0 -37
- package/dist/state/context-providers.d.ts +0 -4
- package/dist/state/context-providers.js +0 -1
- package/dist/state/state-types.d.ts +0 -5
- package/dist/state/state-types.js +0 -1
- package/dist/utils/batch-operations.d.ts +0 -25
- package/dist/utils/batch-operations.js +0 -292
- package/dist/utils/test-template-generator.d.ts +0 -25
- package/dist/utils/test-template-generator.js +0 -178
- package/dist/utils/token-manager.d.ts +0 -48
- package/dist/utils/token-manager.js +0 -163
- package/src/mcps/knowledge-skills/testing-best-practices.server.test.ts +0 -136
- package/src/mcps/knowledge-skills/testing-best-practices.server.ts +0 -1183
- package/src/mcps/orchestrator.server.ts +0 -34
- package/src/opencode/agents/testing-best-practices.yml +0 -12
- package/src/skills/testing-best-practices/SKILL.md +0 -37
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
|
-
import { spawnSync } from "child_process";
|
|
4
3
|
import { frameworkLogger } from "../core/framework-logger.js";
|
|
5
|
-
function sanitizeGitArgument(s) {
|
|
6
|
-
if (!/^[a-zA-Z0-9 \-_.\/@]+$/.test(s)) {
|
|
7
|
-
throw new Error("Invalid git argument: contains disallowed characters");
|
|
8
|
-
}
|
|
9
|
-
return s;
|
|
10
|
-
}
|
|
11
4
|
export class ProposalApplier {
|
|
12
5
|
projectRoot;
|
|
13
|
-
|
|
14
|
-
reviewCallback;
|
|
15
|
-
constructor(projectRoot = process.cwd(), codeChangeCallback, reviewCallback) {
|
|
6
|
+
constructor(projectRoot = process.cwd()) {
|
|
16
7
|
this.projectRoot = projectRoot;
|
|
17
|
-
this.codeChangeCallback = codeChangeCallback;
|
|
18
|
-
this.reviewCallback = reviewCallback;
|
|
19
8
|
}
|
|
20
9
|
async applyProposals(proposals) {
|
|
21
10
|
frameworkLogger.log("execution", "proposal-applier-start", "info", {
|
|
@@ -23,112 +12,26 @@ export class ProposalApplier {
|
|
|
23
12
|
});
|
|
24
13
|
const results = [];
|
|
25
14
|
for (const proposal of proposals) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
return results;
|
|
30
|
-
}
|
|
31
|
-
async applyProposal(p) {
|
|
32
|
-
frameworkLogger.log("execution", "apply-proposal", "info", {
|
|
33
|
-
proposalId: p.id,
|
|
34
|
-
type: p.type,
|
|
35
|
-
});
|
|
36
|
-
if (p.type === "codify") {
|
|
37
|
-
return this.applyCodification(p);
|
|
38
|
-
}
|
|
39
|
-
const branchName = `inference/${p.type}-${Date.now()}`;
|
|
40
|
-
const isGit = this.isInsideGitRepo();
|
|
41
|
-
try {
|
|
42
|
-
this.recordAppliedProposal(p);
|
|
43
|
-
const changedFiles = [
|
|
44
|
-
path.relative(this.projectRoot, this.getAppliedMarkerPath(p)),
|
|
45
|
-
];
|
|
46
|
-
if (isGit) {
|
|
47
|
-
const branchR = spawnSync('git', ['checkout', '-b', branchName], { cwd: this.projectRoot, stdio: 'pipe' });
|
|
48
|
-
if (branchR.status !== 0) {
|
|
49
|
-
throw new Error(`git checkout -b failed: ${(branchR.stderr || '').toString().trim()}`);
|
|
50
|
-
}
|
|
15
|
+
if (proposal.type === "codify") {
|
|
16
|
+
results.push(this.applyCodification(proposal));
|
|
51
17
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
18
|
+
else {
|
|
19
|
+
this.recordAppliedProposal(proposal);
|
|
20
|
+
const changedFiles = [
|
|
21
|
+
path.relative(this.projectRoot, this.getAppliedMarkerPath(proposal)),
|
|
22
|
+
];
|
|
23
|
+
results.push({
|
|
24
|
+
proposalId: proposal.id,
|
|
25
|
+
success: true,
|
|
26
|
+
filesChanged: changedFiles,
|
|
27
|
+
details: [
|
|
28
|
+
"Proposal recorded by Autonomous Engine (ProposalApplier)",
|
|
29
|
+
`type=${proposal.type}`,
|
|
30
|
+
],
|
|
31
|
+
});
|
|
65
32
|
}
|
|
66
|
-
if (isGit) {
|
|
67
|
-
const addR = spawnSync('git', ['add', '-A'], { cwd: this.projectRoot, stdio: 'pipe' });
|
|
68
|
-
if (addR.status !== 0) {
|
|
69
|
-
throw new Error(`git add failed: ${(addR.stderr || '').toString().trim()}`);
|
|
70
|
-
}
|
|
71
|
-
const commitR = spawnSync('git', ['commit', '-m', p.title], { cwd: this.projectRoot, stdio: 'pipe' });
|
|
72
|
-
if (commitR.status !== 0) {
|
|
73
|
-
throw new Error(`git commit failed: ${(commitR.stderr || '').toString().trim()}`);
|
|
74
|
-
}
|
|
75
|
-
const prUrl = this.createPR(p, branchName);
|
|
76
|
-
if (prUrl) {
|
|
77
|
-
frameworkLogger.log("execution", "pr-created", "info", {
|
|
78
|
-
prUrl,
|
|
79
|
-
proposalId: p.id,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
if (this.reviewCallback && prUrl) {
|
|
83
|
-
const review = await this.reviewCallback(p, prUrl);
|
|
84
|
-
if (review === "no-go") {
|
|
85
|
-
frameworkLogger.log("execution", "review-no-go", "warning", {
|
|
86
|
-
proposalId: p.id,
|
|
87
|
-
prUrl,
|
|
88
|
-
});
|
|
89
|
-
spawnSync('git', ['checkout', 'master'], { cwd: this.projectRoot, stdio: 'pipe' });
|
|
90
|
-
spawnSync('git', ['branch', '-D', branchName], { cwd: this.projectRoot, stdio: 'pipe' });
|
|
91
|
-
return {
|
|
92
|
-
proposalId: p.id,
|
|
93
|
-
success: false,
|
|
94
|
-
error: "Researcher review rejected proposal",
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
spawnSync('git', ['checkout', 'master'], { cwd: this.projectRoot, stdio: 'pipe' });
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
proposalId: p.id,
|
|
102
|
-
success: true,
|
|
103
|
-
filesChanged: changedFiles,
|
|
104
|
-
details: [
|
|
105
|
-
"Proposal applied by Autonomous Engine (ProposalApplier)",
|
|
106
|
-
isGit ? `branch=${branchName}` : "non-git (marker only)",
|
|
107
|
-
`type=${p.type}`,
|
|
108
|
-
],
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
catch (err) {
|
|
112
|
-
const errorMsg = err.message;
|
|
113
|
-
frameworkLogger.log("execution", "apply-proposal-error", "error", {
|
|
114
|
-
proposalId: p.id,
|
|
115
|
-
error: errorMsg,
|
|
116
|
-
});
|
|
117
|
-
if (isGit) {
|
|
118
|
-
try {
|
|
119
|
-
spawnSync('git', ['checkout', 'master'], { cwd: this.projectRoot, stdio: 'pipe' });
|
|
120
|
-
spawnSync('git', ['branch', '-D', branchName], { cwd: this.projectRoot, stdio: 'pipe' });
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
// ignore cleanup
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
proposalId: p.id,
|
|
128
|
-
success: false,
|
|
129
|
-
error: errorMsg,
|
|
130
|
-
};
|
|
131
33
|
}
|
|
34
|
+
return results;
|
|
132
35
|
}
|
|
133
36
|
applyCodification(p) {
|
|
134
37
|
try {
|
|
@@ -159,19 +62,6 @@ export class ProposalApplier {
|
|
|
159
62
|
return { proposalId: p.id, success: false, error: errorMsg };
|
|
160
63
|
}
|
|
161
64
|
}
|
|
162
|
-
isInsideGitRepo() {
|
|
163
|
-
try {
|
|
164
|
-
const r = spawnSync('git', ['rev-parse', '--is-inside-work-tree'], {
|
|
165
|
-
cwd: this.projectRoot,
|
|
166
|
-
stdio: 'pipe',
|
|
167
|
-
timeout: 2000,
|
|
168
|
-
});
|
|
169
|
-
return r.status === 0;
|
|
170
|
-
}
|
|
171
|
-
catch {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
65
|
getAppliedMarkerPath(p) {
|
|
176
66
|
const appliedDir = path.join(this.projectRoot, "docs", "inference", "applied");
|
|
177
67
|
if (!fs.existsSync(appliedDir)) {
|
|
@@ -206,49 +96,4 @@ export class ProposalApplier {
|
|
|
206
96
|
module: "v2-refactor",
|
|
207
97
|
});
|
|
208
98
|
}
|
|
209
|
-
createPR(p, branchName) {
|
|
210
|
-
try {
|
|
211
|
-
sanitizeGitArgument(p.title);
|
|
212
|
-
sanitizeGitArgument(branchName);
|
|
213
|
-
const pushR = spawnSync('git', ['push', '-u', 'origin', branchName], {
|
|
214
|
-
cwd: this.projectRoot,
|
|
215
|
-
stdio: 'pipe',
|
|
216
|
-
timeout: 30000,
|
|
217
|
-
});
|
|
218
|
-
if (pushR.status !== 0) {
|
|
219
|
-
throw new Error(`git push failed: ${(pushR.stderr || '').toString().trim()}`);
|
|
220
|
-
}
|
|
221
|
-
const body = [
|
|
222
|
-
"## Inference Proposal (Autonomous Engine)",
|
|
223
|
-
"",
|
|
224
|
-
p.description,
|
|
225
|
-
"",
|
|
226
|
-
`**Type:** ${p.type} **Confidence:** ${(p.confidence * 100).toFixed(0)}%`,
|
|
227
|
-
"",
|
|
228
|
-
"## Evidence",
|
|
229
|
-
p.evidence.slice(0, 5).join("\n"),
|
|
230
|
-
"",
|
|
231
|
-
"Executed by ProposalApplier (Engine-owned) — V2 Phase 1.",
|
|
232
|
-
].join("\n");
|
|
233
|
-
const ghR = spawnSync('gh', ['pr', 'create', '--head', branchName, '--title', p.title, '--body', body], {
|
|
234
|
-
cwd: this.projectRoot,
|
|
235
|
-
encoding: 'utf-8',
|
|
236
|
-
stdio: 'pipe',
|
|
237
|
-
timeout: 30000,
|
|
238
|
-
});
|
|
239
|
-
if (ghR.status !== 0) {
|
|
240
|
-
throw new Error(`gh pr create failed: ${ghR.stderr || 'unknown error'}`);
|
|
241
|
-
}
|
|
242
|
-
return (ghR.stdout || '').trim();
|
|
243
|
-
}
|
|
244
|
-
catch (err) {
|
|
245
|
-
frameworkLogger.log("execution", "pr-create-failed", "warning", {
|
|
246
|
-
error: String(err),
|
|
247
|
-
proposalId: p.id,
|
|
248
|
-
module: "v2-refactor",
|
|
249
|
-
});
|
|
250
|
-
return "";
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
99
|
}
|
|
254
|
-
export const proposalApplier = new ProposalApplier();
|
|
@@ -1,32 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CodexPolicyService
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* This is the V2-P1-S02-REAL first concrete migration slice.
|
|
4
|
+
* Governance-owned Single Source of Truth (SSOT) for Codex / policy loading.
|
|
6
5
|
*
|
|
7
|
-
* Role
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* will eventually ask here instead of performing direct fs reads.
|
|
6
|
+
* Role: External Governance owns "what the policy is".
|
|
7
|
+
* Consumers (enforcers, injectors, formatters, MCPs, plugins) should ask here
|
|
8
|
+
* instead of direct fs reads or scattered loaders.
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* - Returns ActiveCodexSnapshot compatible with the existing get_active_codex MCP tool.
|
|
16
|
-
* - Provides getTermCount() with safe 60-term fallback (preserves prior behavior of bypasses).
|
|
17
|
-
* - Full frameworkLogger discipline on every load/decision/error.
|
|
18
|
-
* - No caching in v1 skeleton (additive later); no mutation; no enforcement.
|
|
19
|
-
*
|
|
20
|
-
* First wired consumer: src/mcps/enforcer-tools.server.ts (getCodexTermCount bypass removed;
|
|
21
|
-
* now delegates through this service).
|
|
22
|
-
*
|
|
23
|
-
* Next recommended slices (documented in researcher mapping append):
|
|
24
|
-
* - Wire governance.server.ts handleGetActiveCodex to delegate (remove its direct read).
|
|
25
|
-
* - S02b/S02c follow-ups: update codex-injector, context-loader, codex-formatter, plugin.
|
|
26
|
-
* - Make CodexLoader delegate its raw data load here, then re-export from governance.
|
|
27
|
-
*
|
|
28
|
-
* @module governance/codex-policy.service
|
|
29
|
-
* @version 2.0.0-s02-real
|
|
10
|
+
* Provides read-only ActiveCodexSnapshot and term count.
|
|
11
|
+
* Uses canonical resolveCodexPath.
|
|
12
|
+
* Full frameworkLogger on all paths.
|
|
30
13
|
*/
|
|
31
14
|
import type { ActiveCodexSnapshot, ICodexPolicyProvider } from './governance-types.js';
|
|
32
15
|
/**
|
|
@@ -54,4 +37,3 @@ export declare class CodexPolicyService implements ICodexPolicyProvider {
|
|
|
54
37
|
getTermCount(): Promise<number>;
|
|
55
38
|
}
|
|
56
39
|
export declare function getCodexPolicyService(): CodexPolicyService;
|
|
57
|
-
export { CodexPolicyService as default };
|
|
@@ -1,32 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CodexPolicyService
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* This is the V2-P1-S02-REAL first concrete migration slice.
|
|
4
|
+
* Governance-owned Single Source of Truth (SSOT) for Codex / policy loading.
|
|
6
5
|
*
|
|
7
|
-
* Role
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* will eventually ask here instead of performing direct fs reads.
|
|
6
|
+
* Role: External Governance owns "what the policy is".
|
|
7
|
+
* Consumers (enforcers, injectors, formatters, MCPs, plugins) should ask here
|
|
8
|
+
* instead of direct fs reads or scattered loaders.
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* - Returns ActiveCodexSnapshot compatible with the existing get_active_codex MCP tool.
|
|
16
|
-
* - Provides getTermCount() with safe 60-term fallback (preserves prior behavior of bypasses).
|
|
17
|
-
* - Full frameworkLogger discipline on every load/decision/error.
|
|
18
|
-
* - No caching in v1 skeleton (additive later); no mutation; no enforcement.
|
|
19
|
-
*
|
|
20
|
-
* First wired consumer: src/mcps/enforcer-tools.server.ts (getCodexTermCount bypass removed;
|
|
21
|
-
* now delegates through this service).
|
|
22
|
-
*
|
|
23
|
-
* Next recommended slices (documented in researcher mapping append):
|
|
24
|
-
* - Wire governance.server.ts handleGetActiveCodex to delegate (remove its direct read).
|
|
25
|
-
* - S02b/S02c follow-ups: update codex-injector, context-loader, codex-formatter, plugin.
|
|
26
|
-
* - Make CodexLoader delegate its raw data load here, then re-export from governance.
|
|
27
|
-
*
|
|
28
|
-
* @module governance/codex-policy.service
|
|
29
|
-
* @version 2.0.0-s02-real
|
|
10
|
+
* Provides read-only ActiveCodexSnapshot and term count.
|
|
11
|
+
* Uses canonical resolveCodexPath.
|
|
12
|
+
* Full frameworkLogger on all paths.
|
|
30
13
|
*/
|
|
31
14
|
import { frameworkLogger } from '../core/framework-logger.js';
|
|
32
15
|
import { resolveCodexPath } from '../core/config-paths.js';
|
|
@@ -120,7 +103,7 @@ export class CodexPolicyService {
|
|
|
120
103
|
is_fallback: isFallback,
|
|
121
104
|
note: isFallback
|
|
122
105
|
? 'Governance CodexPolicyService — builtin fallback (no external codex.json resolved)'
|
|
123
|
-
: 'Returned via Governance CodexPolicyService
|
|
106
|
+
: 'Returned via Governance CodexPolicyService',
|
|
124
107
|
dynamo_required: true,
|
|
125
108
|
...(includeRaw ? { codex: data } : {}),
|
|
126
109
|
};
|
|
@@ -164,4 +147,3 @@ export function getCodexPolicyService() {
|
|
|
164
147
|
return codexPolicyServiceInstance;
|
|
165
148
|
}
|
|
166
149
|
// Also export the class for direct construction in tests / advanced wiring
|
|
167
|
-
export { CodexPolicyService as default };
|
|
@@ -1,41 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pure governance decision logic.
|
|
3
|
-
* This module contains the
|
|
3
|
+
* This module contains the merging rules and metamorphosis scoring.
|
|
4
4
|
* It has no side effects and does not call any MCPs.
|
|
5
5
|
*
|
|
6
6
|
* This is the shared "pure logic" that both the Governance MCP
|
|
7
7
|
* and any HTTP deployment (Vercel) can use.
|
|
8
8
|
*/
|
|
9
9
|
import type { GovernanceVote, GovernanceResult } from './governance-types.js';
|
|
10
|
-
export interface DecisionMatrixInput {
|
|
11
|
-
resonance: number;
|
|
12
|
-
isotopicRatio: number;
|
|
13
|
-
vortexVolume?: number;
|
|
14
|
-
historicalCoherence?: number;
|
|
15
|
-
solarActivity?: 'quiet' | 'moderate' | 'active' | 'storm';
|
|
16
|
-
moralTension?: 'Aligned' | 'Mild' | 'Significant' | 'Critical';
|
|
17
|
-
moralScore?: number;
|
|
18
|
-
moralFusion?: number;
|
|
19
|
-
}
|
|
20
|
-
export interface DecisionMatrixOutput {
|
|
21
|
-
recommendation: 'PASS' | 'NEEDS_REVISION' | 'REJECT';
|
|
22
|
-
confidence: number;
|
|
23
|
-
voteWeight: number;
|
|
24
|
-
reasons: string[];
|
|
25
|
-
moralOverride?: 'rejected_critical' | 'downgraded_significant' | 'none';
|
|
26
|
-
}
|
|
27
|
-
export declare const MORAL_OVERRIDE_LEVELS: {
|
|
28
|
-
Critical: "rejected_critical";
|
|
29
|
-
Significant: "downgraded_significant";
|
|
30
|
-
Mild: "none";
|
|
31
|
-
Aligned: "none";
|
|
32
|
-
};
|
|
33
|
-
export type MoralOverrideThreshold = 'Critical' | 'Significant' | 'Mild' | 'Aligned' | 'disabled';
|
|
34
10
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
11
|
+
* Calculate metamorphosis resonance score for self-evolution proposals.
|
|
12
|
+
*
|
|
13
|
+
* Evaluates whether a proposal increases the system's capacity to govern
|
|
14
|
+
* complex future states. Uses the existing Dynamo resonance signal plus
|
|
15
|
+
* checks for self-improvement indicators.
|
|
16
|
+
*
|
|
17
|
+
* Scoring rubric (0-1):
|
|
18
|
+
* - Base: governance vote confidence (averageConfidence)
|
|
19
|
+
* - Boost: +0.1 if proposal adds new capacity (type=automate/codify)
|
|
20
|
+
* - Boost: +0.05 if historical coherence is strong (>0.8)
|
|
21
|
+
* - Penalty: -0.15 if proposal removes existing capacity (type=compliance-only)
|
|
22
|
+
* - Floor: 0.0, Ceiling: 1.0
|
|
23
|
+
* - Threshold for approval: ≥ 0.7 (configurable via GovernOptions.metamorphosisThreshold)
|
|
24
|
+
*
|
|
25
|
+
* Only meaningful when proposal.type === 'metamorphosis' or source === 'metamorphosis'.
|
|
37
26
|
*/
|
|
38
|
-
export declare function
|
|
27
|
+
export declare function calculateMetamorphosisScore(input: {
|
|
28
|
+
averageConfidence: number;
|
|
29
|
+
proposalType: string;
|
|
30
|
+
historicalCoherence?: number;
|
|
31
|
+
resonanceScore?: number;
|
|
32
|
+
}): number;
|
|
39
33
|
/**
|
|
40
34
|
* Simple weighted merge of votes from multiple servers + external.
|
|
41
35
|
*/
|
|
@@ -1,117 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pure governance decision logic.
|
|
3
|
-
* This module contains the
|
|
3
|
+
* This module contains the merging rules and metamorphosis scoring.
|
|
4
4
|
* It has no side effects and does not call any MCPs.
|
|
5
5
|
*
|
|
6
6
|
* This is the shared "pure logic" that both the Governance MCP
|
|
7
7
|
* and any HTTP deployment (Vercel) can use.
|
|
8
8
|
*/
|
|
9
|
-
// Blurrn constants (from chrono-warp-drive)
|
|
10
|
-
const PHI = 1.666;
|
|
11
|
-
const TAU = 0.865;
|
|
12
|
-
export const MORAL_OVERRIDE_LEVELS = {
|
|
13
|
-
Critical: 'rejected_critical',
|
|
14
|
-
Significant: 'downgraded_significant',
|
|
15
|
-
Mild: 'none',
|
|
16
|
-
Aligned: 'none',
|
|
17
|
-
};
|
|
18
9
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
10
|
+
* Calculate metamorphosis resonance score for self-evolution proposals.
|
|
11
|
+
*
|
|
12
|
+
* Evaluates whether a proposal increases the system's capacity to govern
|
|
13
|
+
* complex future states. Uses the existing Dynamo resonance signal plus
|
|
14
|
+
* checks for self-improvement indicators.
|
|
15
|
+
*
|
|
16
|
+
* Scoring rubric (0-1):
|
|
17
|
+
* - Base: governance vote confidence (averageConfidence)
|
|
18
|
+
* - Boost: +0.1 if proposal adds new capacity (type=automate/codify)
|
|
19
|
+
* - Boost: +0.05 if historical coherence is strong (>0.8)
|
|
20
|
+
* - Penalty: -0.15 if proposal removes existing capacity (type=compliance-only)
|
|
21
|
+
* - Floor: 0.0, Ceiling: 1.0
|
|
22
|
+
* - Threshold for approval: ≥ 0.7 (configurable via GovernOptions.metamorphosisThreshold)
|
|
23
|
+
*
|
|
24
|
+
* Only meaningful when proposal.type === 'metamorphosis' or source === 'metamorphosis'.
|
|
21
25
|
*/
|
|
22
|
-
export function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let confidence = 0.75;
|
|
28
|
-
let voteWeight = 1.0;
|
|
29
|
-
let moralOverride = 'none';
|
|
30
|
-
// Log moral fusion if present — weighted signal for transparency
|
|
31
|
-
if (moralFusion != null) {
|
|
32
|
-
reasons.push(`Moral-numerological fusion: ${(moralFusion * 100).toFixed(0)}%`);
|
|
26
|
+
export function calculateMetamorphosisScore(input) {
|
|
27
|
+
let score = input.averageConfidence;
|
|
28
|
+
// Self-improvement capacity: proposals that add automation or codification boost the score
|
|
29
|
+
if (input.proposalType === 'automate' || input.proposalType === 'codify') {
|
|
30
|
+
score += 0.10;
|
|
33
31
|
}
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
recommendation = 'REJECT';
|
|
38
|
-
confidence = 0.92;
|
|
39
|
-
voteWeight = 1.6;
|
|
40
|
-
moralOverride = 'rejected_critical';
|
|
41
|
-
reasons.push(`Critical moral tension — proposal violates moral alignment (score: ${moralScore != null ? (moralScore * 100).toFixed(0) + '%' : 'unknown'})`);
|
|
42
|
-
return {
|
|
43
|
-
recommendation,
|
|
44
|
-
confidence: Math.min(0.99, Math.max(0.5, confidence)),
|
|
45
|
-
voteWeight: Math.max(0.5, Math.min(1.8, voteWeight)),
|
|
46
|
-
reasons,
|
|
47
|
-
moralOverride,
|
|
48
|
-
};
|
|
32
|
+
// Compliance-only proposals (guard type with no new capacity) get a penalty
|
|
33
|
+
if (input.proposalType === 'compliance') {
|
|
34
|
+
score -= 0.15;
|
|
49
35
|
}
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
moralDowngrade = true;
|
|
54
|
-
moralOverride = 'downgraded_significant';
|
|
55
|
-
voteWeight *= 0.85;
|
|
56
|
-
reasons.push(`Significant moral tension — proceed with caution (score: ${moralScore != null ? (moralScore * 100).toFixed(0) + '%' : 'unknown'})`);
|
|
36
|
+
// Strong historical coherence means the system is stable enough for self-evolution
|
|
37
|
+
if (input.historicalCoherence != null && input.historicalCoherence > 0.8) {
|
|
38
|
+
score += 0.05;
|
|
57
39
|
}
|
|
58
|
-
//
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
voteWeight *= 1.05;
|
|
62
|
-
reasons.push(`Moral alignment confirmed (score: ${(moralScore * 100).toFixed(0)}%)`);
|
|
40
|
+
// High Dynamo resonance (Solar signal) supports self-evolution
|
|
41
|
+
if (input.resonanceScore != null && input.resonanceScore >= 0.82) {
|
|
42
|
+
score += 0.05;
|
|
63
43
|
}
|
|
64
|
-
|
|
65
|
-
recommendation = 'PASS';
|
|
66
|
-
confidence = 0.97;
|
|
67
|
-
voteWeight = 1.4;
|
|
68
|
-
reasons.push('High symbiotic resonance (PHI-aligned)');
|
|
69
|
-
}
|
|
70
|
-
else if (resonance >= 0.82 && isotopicRatio >= 0.88) {
|
|
71
|
-
recommendation = 'PASS';
|
|
72
|
-
confidence = 0.89;
|
|
73
|
-
voteWeight = 1.15;
|
|
74
|
-
reasons.push('Solid alignment above TAU threshold');
|
|
75
|
-
}
|
|
76
|
-
else if (resonance < 0.75 || isotopicRatio < 0.80) {
|
|
77
|
-
recommendation = 'REJECT';
|
|
78
|
-
confidence = 0.84;
|
|
79
|
-
reasons.push('Signal below critical threshold (1 - TAU)');
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
reasons.push('Moderate resonance - requires refinement');
|
|
83
|
-
}
|
|
84
|
-
// Moral downgrade: Significant tension demotes PASS → NEEDS_REVISION
|
|
85
|
-
if (moralDowngrade && recommendation === 'PASS') {
|
|
86
|
-
recommendation = 'NEEDS_REVISION';
|
|
87
|
-
reasons.push('Moral tension downgraded recommendation from PASS to NEEDS_REVISION');
|
|
88
|
-
}
|
|
89
|
-
if (vortexVolume < 2.5e25) {
|
|
90
|
-
reasons.push('Low inertial mass (W x M = V)');
|
|
91
|
-
if (recommendation === 'PASS')
|
|
92
|
-
recommendation = 'NEEDS_REVISION';
|
|
93
|
-
}
|
|
94
|
-
if (historicalCoherence < 0.70) {
|
|
95
|
-
reasons.push('Weak historical alignment with past decisions');
|
|
96
|
-
if (recommendation === 'PASS')
|
|
97
|
-
recommendation = 'NEEDS_REVISION';
|
|
98
|
-
}
|
|
99
|
-
else if (historicalCoherence > 0.90) {
|
|
100
|
-
reasons.push('Strong continuity with previous governance');
|
|
101
|
-
voteWeight *= 1.1;
|
|
102
|
-
}
|
|
103
|
-
// Solar adjustment (from chrono-warp-drive)
|
|
104
|
-
if (solarActivity === 'active' || solarActivity === 'storm') {
|
|
105
|
-
voteWeight *= 0.92;
|
|
106
|
-
reasons.push('Elevated solar activity - increased caution applied');
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
recommendation,
|
|
110
|
-
confidence: Math.min(0.99, Math.max(0.5, confidence)),
|
|
111
|
-
voteWeight: Math.max(0.5, Math.min(1.8, voteWeight)),
|
|
112
|
-
reasons,
|
|
113
|
-
moralOverride,
|
|
114
|
-
};
|
|
44
|
+
return Math.min(1.0, Math.max(0.0, Math.round(score * 100) / 100));
|
|
115
45
|
}
|
|
116
46
|
/**
|
|
117
47
|
* Simple weighted merge of votes from multiple servers + external.
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { mcpClientManager } from '../mcps/mcp-client.js';
|
|
19
19
|
import { callInProcessSkill } from '../mcps/in-process-skill-registry.js';
|
|
20
|
+
import { pluginRegistry } from '../nucleus/plugin-registry.js';
|
|
20
21
|
import { getGovernanceIntegration, } from '../integrations/governance/index.js';
|
|
21
|
-
import { mergeVotes } from './governance-core.js';
|
|
22
|
+
import { mergeVotes, calculateMetamorphosisScore } from './governance-core.js';
|
|
22
23
|
import { frameworkLogger } from '../core/framework-logger.js';
|
|
23
24
|
export class GovernanceService {
|
|
24
25
|
constructor() {
|
|
@@ -59,7 +60,7 @@ export class GovernanceService {
|
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
// Run governance with end-to-end timeout
|
|
62
|
-
const result = await this.runGovernanceWithTimeout(proposals, context, requireExternal, timeoutMs);
|
|
63
|
+
const result = await this.runGovernanceWithTimeout(proposals, context, requireExternal, timeoutMs, options?.metamorphosisThreshold);
|
|
63
64
|
// Check abstention threshold
|
|
64
65
|
if (result.results.length > 0 && maxAbstentionThreshold < 1.0) {
|
|
65
66
|
const totalVotes = result.results.reduce((sum, r) => sum + r.votes.length, 0);
|
|
@@ -91,7 +92,7 @@ export class GovernanceService {
|
|
|
91
92
|
},
|
|
92
93
|
};
|
|
93
94
|
}
|
|
94
|
-
async runGovernanceWithTimeout(proposals, context, requireExternal, timeoutMs) {
|
|
95
|
+
async runGovernanceWithTimeout(proposals, context, requireExternal, timeoutMs, metamorphosisThreshold) {
|
|
95
96
|
const controller = new AbortController();
|
|
96
97
|
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
97
98
|
try {
|
|
@@ -112,13 +113,33 @@ export class GovernanceService {
|
|
|
112
113
|
...(externalVotes[index] || []),
|
|
113
114
|
];
|
|
114
115
|
const merged = mergeVotes(votes);
|
|
115
|
-
|
|
116
|
+
const isMetamorphosis = proposal.type === 'metamorphosis' || proposal.source === 'metamorphosis';
|
|
117
|
+
const result = {
|
|
116
118
|
proposalId: proposal.id,
|
|
117
119
|
finalDecision: merged.finalDecision,
|
|
118
120
|
averageConfidence: merged.averageConfidence,
|
|
119
121
|
votes,
|
|
120
122
|
reasoningSummary: merged.reasoningSummary,
|
|
121
123
|
};
|
|
124
|
+
// Metamorphosis resonance scoring: only for self-evolution proposals
|
|
125
|
+
if (isMetamorphosis) {
|
|
126
|
+
const threshold = metamorphosisThreshold ?? 0.7;
|
|
127
|
+
const metaInput = {
|
|
128
|
+
averageConfidence: merged.averageConfidence,
|
|
129
|
+
proposalType: proposal.type,
|
|
130
|
+
};
|
|
131
|
+
const externalConfidence = externalVotes[index]?.[0]?.confidence;
|
|
132
|
+
if (externalConfidence !== undefined) {
|
|
133
|
+
metaInput.historicalCoherence = externalConfidence;
|
|
134
|
+
}
|
|
135
|
+
result.metamorphosisScore = calculateMetamorphosisScore(metaInput);
|
|
136
|
+
// Reject metamorphosis proposals that don't meet the threshold
|
|
137
|
+
if (result.metamorphosisScore < threshold && result.finalDecision === 'approve') {
|
|
138
|
+
result.finalDecision = 'needs_revision';
|
|
139
|
+
result.reasoningSummary += ` | Metamorphosis score ${result.metamorphosisScore} below threshold ${threshold}`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
122
143
|
});
|
|
123
144
|
return { results };
|
|
124
145
|
}
|
|
@@ -129,6 +150,45 @@ export class GovernanceService {
|
|
|
129
150
|
async callSkillServer(serverName, proposals, context) {
|
|
130
151
|
const votes = [];
|
|
131
152
|
const useInProcess = process.env.VERCEL === '1';
|
|
153
|
+
// v3: Try pluginRegistry first for dynamically registered skills.
|
|
154
|
+
// Built-in skills (code-review, security-audit, researcher) fall through
|
|
155
|
+
// to MCP or in-process paths. Custom plugins registered via
|
|
156
|
+
// pluginRegistry.register() are resolved here.
|
|
157
|
+
if (pluginRegistry.has(serverName) && !this.isBuiltInSkill(serverName)) {
|
|
158
|
+
frameworkLogger.log('governance-service', 'plugin-skill-resolved', 'info', {
|
|
159
|
+
server: serverName,
|
|
160
|
+
mode: 'plugin-registry',
|
|
161
|
+
});
|
|
162
|
+
for (const proposal of proposals) {
|
|
163
|
+
try {
|
|
164
|
+
const result = await pluginRegistry.callSkill(serverName, {
|
|
165
|
+
proposalTitle: proposal.title,
|
|
166
|
+
proposalDescription: proposal.description,
|
|
167
|
+
evidence: proposal.evidence || [],
|
|
168
|
+
proposalType: proposal.type,
|
|
169
|
+
});
|
|
170
|
+
const text = result?.content?.[0]?.text || '';
|
|
171
|
+
const vote = this.parseVoteFromText(serverName, text);
|
|
172
|
+
votes.push(vote);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
frameworkLogger.log('governance-service', 'plugin-skill-error', 'error', {
|
|
176
|
+
server: serverName,
|
|
177
|
+
proposal: proposal.title,
|
|
178
|
+
error: error instanceof Error ? error.message : String(error),
|
|
179
|
+
mode: 'plugin-registry',
|
|
180
|
+
});
|
|
181
|
+
votes.push({
|
|
182
|
+
server: serverName,
|
|
183
|
+
decision: 'abstain',
|
|
184
|
+
confidence: 0.3,
|
|
185
|
+
reasoning: `Plugin skill ${serverName} failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return votes;
|
|
190
|
+
}
|
|
191
|
+
// Built-in skills: use MCP (standard surface) or in-process (Vercel)
|
|
132
192
|
for (const proposal of proposals) {
|
|
133
193
|
try {
|
|
134
194
|
let text = '';
|
|
@@ -263,6 +323,9 @@ export class GovernanceService {
|
|
|
263
323
|
reasoning: reasoningMatch?.[1]?.trim() || 'No reasoning provided',
|
|
264
324
|
};
|
|
265
325
|
}
|
|
326
|
+
isBuiltInSkill(name) {
|
|
327
|
+
return name === 'code-review' || name === 'security-audit' || name === 'researcher';
|
|
328
|
+
}
|
|
266
329
|
}
|
|
267
330
|
// Singleton for convenience
|
|
268
331
|
let governanceServiceInstance = null;
|