mindforge-cc 10.0.3 → 11.0.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/.mindforge/MINDFORGE-V2-SCHEMA.json +43 -10
- package/.mindforge/config.json +30 -2
- package/.mindforge/engine/cross-model-eval.md +74 -0
- package/.mindforge/engine/proactive/signal-detector.md +60 -0
- package/.mindforge/engine/proactive/suggestion-engine.md +100 -0
- package/.mindforge/personas/agent-architect.md +57 -0
- package/.mindforge/personas/agent-evaluator.md +162 -0
- package/.mindforge/personas/agent-memory-designer.md +157 -0
- package/.mindforge/personas/agent-ops-engineer.md +120 -0
- package/.mindforge/personas/agent-orchestrator.md +112 -0
- package/.mindforge/personas/ai-economist.md +57 -0
- package/.mindforge/personas/ai-safety-engineer.md +57 -0
- package/.mindforge/personas/analytics-engineer.md +57 -0
- package/.mindforge/personas/anti-pattern-hunter.md +61 -0
- package/.mindforge/personas/api-gateway-designer.md +132 -0
- package/.mindforge/personas/auth-engineer.md +112 -0
- package/.mindforge/personas/build-engineer.md +57 -0
- package/.mindforge/personas/business-analyst.md +56 -0
- package/.mindforge/personas/cache-architect.md +100 -0
- package/.mindforge/personas/causal-scientist.md +57 -0
- package/.mindforge/personas/cdn-architect.md +118 -0
- package/.mindforge/personas/change-agent.md +104 -0
- package/.mindforge/personas/code-narrator.md +52 -0
- package/.mindforge/personas/codegen-specialist.md +68 -0
- package/.mindforge/personas/communication-architect.md +102 -0
- package/.mindforge/personas/compliance-engineer.md +96 -0
- package/.mindforge/personas/consensus-engineer.md +116 -0
- package/.mindforge/personas/contract-tester.md +60 -192
- package/.mindforge/personas/data-architect.md +108 -0
- package/.mindforge/personas/data-mesh-architect.md +57 -0
- package/.mindforge/personas/data-pipeline-architect.md +120 -0
- package/.mindforge/personas/de-sloppifier.md +60 -0
- package/.mindforge/personas/debt-manager.md +66 -0
- package/.mindforge/personas/decision-architect.md +82 -51
- package/.mindforge/personas/deployment-captain.md +74 -0
- package/.mindforge/personas/design-system-lead.md +112 -0
- package/.mindforge/personas/dmux-orchestrator.md +75 -0
- package/.mindforge/personas/dx-engineer.md +96 -0
- package/.mindforge/personas/ecommerce-engineer.md +57 -0
- package/.mindforge/personas/edge-engineer.md +94 -0
- package/.mindforge/personas/edtech-architect.md +106 -0
- package/.mindforge/personas/embedding-architect.md +57 -0
- package/.mindforge/personas/environment-engineer.md +57 -0
- package/.mindforge/personas/eval-judge.md +55 -0
- package/.mindforge/personas/event-architect.md +102 -0
- package/.mindforge/personas/experiment-designer.md +138 -0
- package/.mindforge/personas/feature-store-engineer.md +57 -0
- package/.mindforge/personas/finops-analyst.md +66 -0
- package/.mindforge/personas/fintech-architect.md +57 -0
- package/.mindforge/personas/flutter-engineer.md +104 -0
- package/.mindforge/personas/gaming-engineer.md +57 -0
- package/.mindforge/personas/graphql-designer.md +73 -0
- package/.mindforge/personas/healthcare-engineer.md +57 -0
- package/.mindforge/personas/hiring-strategist.md +105 -0
- package/.mindforge/personas/hitl-architect.md +165 -0
- package/.mindforge/personas/i18n-architect.md +69 -0
- package/.mindforge/personas/iot-architect.md +105 -0
- package/.mindforge/personas/knowledge-curator.md +139 -0
- package/.mindforge/personas/knowledge-engineer.md +57 -0
- package/.mindforge/personas/lakehouse-architect.md +57 -0
- package/.mindforge/personas/llm-orchestrator.md +57 -0
- package/.mindforge/personas/logistics-architect.md +106 -0
- package/.mindforge/personas/market-analyst.md +53 -0
- package/.mindforge/personas/marketplace-engineer.md +105 -0
- package/.mindforge/personas/mcp-designer.md +54 -0
- package/.mindforge/personas/meeting-designer.md +104 -0
- package/.mindforge/personas/mentorship-lead.md +106 -0
- package/.mindforge/personas/migration-architect.md +57 -0
- package/.mindforge/personas/ml-ops-engineer.md +101 -0
- package/.mindforge/personas/mobile-architect.md +105 -0
- package/.mindforge/personas/mobile-security-engineer.md +106 -0
- package/.mindforge/personas/multi-tenancy-architect.md +71 -0
- package/.mindforge/personas/multimodal-engineer.md +57 -0
- package/.mindforge/personas/offline-specialist.md +105 -0
- package/.mindforge/personas/onboarding-navigator.md +63 -0
- package/.mindforge/personas/payments-engineer.md +135 -0
- package/.mindforge/personas/pipeline-engineer.md +115 -0
- package/.mindforge/personas/platform-engineer.md +97 -0
- package/.mindforge/personas/platform-lead.md +57 -0
- package/.mindforge/personas/privacy-engineer.md +57 -0
- package/.mindforge/personas/product-owner.md +56 -0
- package/.mindforge/personas/productivity-analyst.md +57 -0
- package/.mindforge/personas/prompt-architect.md +101 -0
- package/.mindforge/personas/proofreader.md +53 -0
- package/.mindforge/personas/pwa-architect.md +105 -0
- package/.mindforge/personas/quality-scorer.md +63 -0
- package/.mindforge/personas/react-native-engineer.md +106 -0
- package/.mindforge/personas/resilience-engineer.md +69 -0
- package/.mindforge/personas/rfc-architect.md +64 -0
- package/.mindforge/personas/saga-orchestrator.md +80 -0
- package/.mindforge/personas/secrets-engineer.md +57 -0
- package/.mindforge/personas/skill-smith.md +79 -0
- package/.mindforge/personas/sre-lead.md +107 -0
- package/.mindforge/personas/stream-engineer.md +57 -0
- package/.mindforge/personas/streaming-engineer.md +64 -0
- package/.mindforge/personas/swarm-templates.json +674 -44
- package/.mindforge/personas/system-designer.md +57 -0
- package/.mindforge/personas/team-coach.md +120 -0
- package/.mindforge/personas/tech-lead-coach.md +103 -0
- package/.mindforge/personas/technical-writer-lead.md +111 -0
- package/.mindforge/personas/vibe-checker.md +75 -0
- package/.mindforge/personas/worktree-manager.md +56 -0
- package/.mindforge/personas/zero-trust-engineer.md +113 -0
- package/.mindforge/skills/a11y-testing/SKILL.md +143 -0
- package/.mindforge/skills/agent-evaluation-framework/SKILL.md +227 -0
- package/.mindforge/skills/agent-memory-design/SKILL.md +199 -0
- package/.mindforge/skills/agent-orchestration-patterns/SKILL.md +129 -0
- package/.mindforge/skills/agent-tool-selection/SKILL.md +204 -0
- package/.mindforge/skills/ai-agent-deployment/SKILL.md +176 -0
- package/.mindforge/skills/ai-cost-management/SKILL.md +57 -0
- package/.mindforge/skills/ai-safety-alignment/SKILL.md +53 -0
- package/.mindforge/skills/analytics-instrumentation/SKILL.md +172 -0
- package/.mindforge/skills/api-gateway-patterns/SKILL.md +177 -0
- package/.mindforge/skills/api-marketplace/SKILL.md +56 -0
- package/.mindforge/skills/api-versioning/SKILL.md +100 -0
- package/.mindforge/skills/app-store-deployment/SKILL.md +44 -0
- package/.mindforge/skills/architecture-tradeoff-analysis/SKILL.md +97 -0
- package/.mindforge/skills/audit-logging/SKILL.md +140 -0
- package/.mindforge/skills/auth-patterns/SKILL.md +148 -0
- package/.mindforge/skills/autonomous-agent-harness/SKILL.md +218 -0
- package/.mindforge/skills/autonomous-agents/SKILL.md +59 -0
- package/.mindforge/skills/build-system-optimization/SKILL.md +54 -0
- package/.mindforge/skills/build-vs-buy/SKILL.md +80 -0
- package/.mindforge/skills/bundle-optimization/SKILL.md +174 -0
- package/.mindforge/skills/business-analyst/SKILL.md +82 -0
- package/.mindforge/skills/caching-strategies/SKILL.md +132 -0
- package/.mindforge/skills/capacity-planning/SKILL.md +96 -0
- package/.mindforge/skills/causal-inference/SKILL.md +42 -0
- package/.mindforge/skills/cdn-optimization/SKILL.md +212 -0
- package/.mindforge/skills/change-management/SKILL.md +106 -0
- package/.mindforge/skills/chaos-engineering/SKILL.md +99 -0
- package/.mindforge/skills/ci-cd-pipeline/SKILL.md +118 -0
- package/.mindforge/skills/cli-design/SKILL.md +118 -0
- package/.mindforge/skills/code-generation-patterns/SKILL.md +92 -0
- package/.mindforge/skills/code-review-methodology/SKILL.md +180 -0
- package/.mindforge/skills/code-tour/SKILL.md +145 -0
- package/.mindforge/skills/codebase-onboarding/SKILL.md +95 -0
- package/.mindforge/skills/compliance-as-code/SKILL.md +195 -0
- package/.mindforge/skills/conflict-resolution/SKILL.md +87 -0
- package/.mindforge/skills/connection-pooling/SKILL.md +151 -0
- package/.mindforge/skills/container-security/SKILL.md +151 -0
- package/.mindforge/skills/context-engineering/SKILL.md +114 -0
- package/.mindforge/skills/contract-testing/SKILL.md +85 -0
- package/.mindforge/skills/cost-estimation/SKILL.md +82 -0
- package/.mindforge/skills/cqrs-event-sourcing/SKILL.md +95 -0
- package/.mindforge/skills/cross-platform-testing/SKILL.md +43 -0
- package/.mindforge/skills/data-governance/SKILL.md +42 -0
- package/.mindforge/skills/data-lakehouse/SKILL.md +42 -0
- package/.mindforge/skills/data-mesh/SKILL.md +42 -0
- package/.mindforge/skills/data-modeling/SKILL.md +107 -0
- package/.mindforge/skills/data-pipeline-design/SKILL.md +171 -0
- package/.mindforge/skills/data-privacy-engineering/SKILL.md +42 -0
- package/.mindforge/skills/database-performance/SKILL.md +174 -0
- package/.mindforge/skills/database-sharding-advanced/SKILL.md +206 -0
- package/.mindforge/skills/de-sloppify/SKILL.md +120 -0
- package/.mindforge/skills/defense-in-depth/SKILL.md +84 -0
- package/.mindforge/skills/delegation-patterns/SKILL.md +123 -0
- package/.mindforge/skills/dependency-management/SKILL.md +94 -0
- package/.mindforge/skills/deployment-workflow/SKILL.md +135 -0
- package/.mindforge/skills/design-system/SKILL.md +113 -0
- package/.mindforge/skills/developer-onboarding/SKILL.md +99 -0
- package/.mindforge/skills/developer-productivity-metrics/SKILL.md +59 -0
- package/.mindforge/skills/distributed-consensus/SKILL.md +141 -0
- package/.mindforge/skills/dmux-workflows/SKILL.md +141 -0
- package/.mindforge/skills/dns-architecture/SKILL.md +167 -0
- package/.mindforge/skills/ecommerce-architecture/SKILL.md +41 -0
- package/.mindforge/skills/edge-computing/SKILL.md +91 -0
- package/.mindforge/skills/edtech-platform/SKILL.md +41 -0
- package/.mindforge/skills/email-deliverability/SKILL.md +177 -0
- package/.mindforge/skills/embedding-systems/SKILL.md +55 -0
- package/.mindforge/skills/environment-management/SKILL.md +54 -0
- package/.mindforge/skills/error-handling-architecture/SKILL.md +118 -0
- package/.mindforge/skills/estimation-techniques/SKILL.md +113 -0
- package/.mindforge/skills/eval-harness/SKILL.md +180 -0
- package/.mindforge/skills/event-driven-architecture/SKILL.md +162 -0
- package/.mindforge/skills/experiment-design/SKILL.md +139 -0
- package/.mindforge/skills/experiment-platform/SKILL.md +43 -0
- package/.mindforge/skills/feature-engineering/SKILL.md +42 -0
- package/.mindforge/skills/feature-flag-management/SKILL.md +183 -0
- package/.mindforge/skills/fine-tuning-workflow/SKILL.md +189 -0
- package/.mindforge/skills/fintech-patterns/SKILL.md +41 -0
- package/.mindforge/skills/flutter-architecture/SKILL.md +42 -0
- package/.mindforge/skills/gaming-backend/SKILL.md +41 -0
- package/.mindforge/skills/git-workflow-design/SKILL.md +129 -0
- package/.mindforge/skills/graceful-degradation/SKILL.md +95 -0
- package/.mindforge/skills/graphql-patterns/SKILL.md +243 -0
- package/.mindforge/skills/guardrails-and-safety/SKILL.md +137 -0
- package/.mindforge/skills/healthcare-systems/SKILL.md +40 -0
- package/.mindforge/skills/hiring-engineering/SKILL.md +119 -0
- package/.mindforge/skills/human-in-the-loop-design/SKILL.md +234 -0
- package/.mindforge/skills/i18n-architecture/SKILL.md +147 -0
- package/.mindforge/skills/idempotency-patterns/SKILL.md +84 -0
- package/.mindforge/skills/incident-communication/SKILL.md +96 -0
- package/.mindforge/skills/incident-management/SKILL.md +97 -0
- package/.mindforge/skills/infrastructure-as-code/SKILL.md +98 -0
- package/.mindforge/skills/instinct-clustering/SKILL.md +190 -0
- package/.mindforge/skills/internal-developer-platform/SKILL.md +51 -0
- package/.mindforge/skills/iot-platform/SKILL.md +41 -0
- package/.mindforge/skills/k8s-deployment/SKILL.md +358 -0
- package/.mindforge/skills/knowledge-graphs/SKILL.md +56 -0
- package/.mindforge/skills/knowledge-sharing-systems/SKILL.md +112 -0
- package/.mindforge/skills/llm-cost-optimization/SKILL.md +198 -0
- package/.mindforge/skills/llm-orchestration/SKILL.md +56 -0
- package/.mindforge/skills/load-testing/SKILL.md +84 -0
- package/.mindforge/skills/logistics-optimization/SKILL.md +40 -0
- package/.mindforge/skills/market-researcher/SKILL.md +99 -0
- package/.mindforge/skills/marketplace-trust/SKILL.md +40 -0
- package/.mindforge/skills/mcp-server-patterns/SKILL.md +264 -0
- package/.mindforge/skills/media-streaming/SKILL.md +41 -0
- package/.mindforge/skills/meeting-architecture/SKILL.md +146 -0
- package/.mindforge/skills/mentoring-patterns/SKILL.md +77 -0
- package/.mindforge/skills/microservices-patterns/SKILL.md +83 -0
- package/.mindforge/skills/migration-platform/SKILL.md +61 -0
- package/.mindforge/skills/migration-strategies/SKILL.md +129 -0
- package/.mindforge/skills/ml-feature-store/SKILL.md +56 -0
- package/.mindforge/skills/ml-monitoring/SKILL.md +42 -0
- package/.mindforge/skills/mobile-performance/SKILL.md +44 -0
- package/.mindforge/skills/mobile-security/SKILL.md +45 -0
- package/.mindforge/skills/model-evaluation/SKILL.md +53 -0
- package/.mindforge/skills/monorepo-management/SKILL.md +100 -0
- package/.mindforge/skills/multi-tenancy-patterns/SKILL.md +145 -0
- package/.mindforge/skills/multi-turn-conversation-design/SKILL.md +206 -0
- package/.mindforge/skills/multimodal-ai/SKILL.md +51 -0
- package/.mindforge/skills/mutation-testing/SKILL.md +97 -0
- package/.mindforge/skills/notification-system-design/SKILL.md +168 -0
- package/.mindforge/skills/observability-stack/SKILL.md +136 -0
- package/.mindforge/skills/offline-first-design/SKILL.md +43 -0
- package/.mindforge/skills/on-call-design/SKILL.md +111 -0
- package/.mindforge/skills/pagination-patterns/SKILL.md +230 -0
- package/.mindforge/skills/payment-integration/SKILL.md +176 -0
- package/.mindforge/skills/performance-reviews/SKILL.md +140 -0
- package/.mindforge/skills/platform-observability/SKILL.md +58 -0
- package/.mindforge/skills/platform-reliability/SKILL.md +52 -0
- package/.mindforge/skills/post-incident-learning/SKILL.md +96 -0
- package/.mindforge/skills/product-manager/SKILL.md +104 -0
- package/.mindforge/skills/progressive-web-app/SKILL.md +44 -0
- package/.mindforge/skills/prompt-engineering/SKILL.md +94 -0
- package/.mindforge/skills/proofreader/SKILL.md +158 -0
- package/.mindforge/skills/push-notification-architecture/SKILL.md +45 -0
- package/.mindforge/skills/python-performance/SKILL.md +183 -0
- package/.mindforge/skills/quality-audit/SKILL.md +171 -0
- package/.mindforge/skills/queue-design/SKILL.md +85 -0
- package/.mindforge/skills/rag-architecture/SKILL.md +176 -0
- package/.mindforge/skills/rate-limiting-design/SKILL.md +94 -0
- package/.mindforge/skills/react-native-patterns/SKILL.md +42 -0
- package/.mindforge/skills/react-performance/SKILL.md +229 -0
- package/.mindforge/skills/real-time-analytics/SKILL.md +42 -0
- package/.mindforge/skills/real-time-sync/SKILL.md +83 -0
- package/.mindforge/skills/responsive-native/SKILL.md +44 -0
- package/.mindforge/skills/responsive-patterns/SKILL.md +141 -0
- package/.mindforge/skills/rfc-pipeline/SKILL.md +114 -0
- package/.mindforge/skills/saas-multi-tenant/SKILL.md +41 -0
- package/.mindforge/skills/santa-method/SKILL.md +134 -0
- package/.mindforge/skills/search-implementation/SKILL.md +98 -0
- package/.mindforge/skills/secrets-platform/SKILL.md +56 -0
- package/.mindforge/skills/secrets-rotation/SKILL.md +173 -0
- package/.mindforge/skills/self-serve-infrastructure/SKILL.md +51 -0
- package/.mindforge/skills/serverless-patterns/SKILL.md +119 -0
- package/.mindforge/skills/skill-creator-meta/SKILL.md +146 -0
- package/.mindforge/skills/sprint-retrospective-facilitation/SKILL.md +112 -0
- package/.mindforge/skills/stakeholder-communication/SKILL.md +85 -0
- package/.mindforge/skills/state-management/SKILL.md +104 -0
- package/.mindforge/skills/stream-processing/SKILL.md +43 -0
- package/.mindforge/skills/streaming-architecture/SKILL.md +81 -0
- package/.mindforge/skills/supply-chain-security/SKILL.md +145 -0
- package/.mindforge/skills/synthetic-data-generation/SKILL.md +52 -0
- package/.mindforge/skills/system-design/SKILL.md +88 -0
- package/.mindforge/skills/team-topology-design/SKILL.md +107 -0
- package/.mindforge/skills/technical-debt-management/SKILL.md +86 -0
- package/.mindforge/skills/technical-interview-design/SKILL.md +98 -0
- package/.mindforge/skills/technical-leadership/SKILL.md +75 -0
- package/.mindforge/skills/technical-writing/SKILL.md +237 -0
- package/.mindforge/skills/technology-radar/SKILL.md +88 -0
- package/.mindforge/skills/testing-anti-patterns/SKILL.md +288 -0
- package/.mindforge/skills/tool-design/SKILL.md +138 -0
- package/.mindforge/skills/typescript-advanced/SKILL.md +198 -0
- package/.mindforge/skills/using-git-worktrees/SKILL.md +139 -0
- package/.mindforge/skills/verification-loop/SKILL.md +13 -1
- package/.mindforge/skills/vibe-security/SKILL.md +165 -0
- package/.mindforge/skills/visual-regression-testing/SKILL.md +97 -0
- package/.mindforge/skills/websocket-patterns/SKILL.md +203 -0
- package/.mindforge/skills/writing-plans/SKILL.md +170 -0
- package/.mindforge/skills/writing-skills/SKILL.md +216 -0
- package/.mindforge/skills/zero-trust-architecture/SKILL.md +166 -0
- package/CHANGELOG.md +240 -0
- package/MINDFORGE.md +4 -4
- package/README.md +49 -4
- package/RELEASENOTES.md +80 -0
- package/SECURITY.md +20 -8
- package/bin/autonomous/audit-writer.js +13 -0
- package/bin/autonomous/auto-runner.js +74 -16
- package/bin/autonomous/context-refactorer.js +26 -11
- package/bin/autonomous/state-manager.js +62 -6
- package/bin/autonomous/stuck-monitor.js +46 -7
- package/bin/autonomous/wave-executor.js +66 -25
- package/bin/dashboard/api-router.js +43 -0
- package/bin/dashboard/metrics-aggregator.js +28 -1
- package/bin/dashboard/server.js +67 -4
- package/bin/dashboard/sse-bridge.js +4 -4
- package/bin/engine/feedback-loop.js +8 -0
- package/bin/engine/intelligence-interlock.js +32 -15
- package/bin/engine/logic-drift-detector.js +2 -1
- package/bin/engine/nexus-tracer.js +3 -2
- package/bin/engine/remediation-engine.js +155 -32
- package/bin/engine/self-corrective-synthesizer.js +84 -10
- package/bin/engine/sre-manager.js +12 -4
- package/bin/engine/temporal-hub.js +131 -34
- package/bin/governance/approve.js +41 -5
- package/bin/governance/impact-analyzer.js +28 -0
- package/bin/governance/policy-engine.js +10 -3
- package/bin/governance/quantum-crypto.js +32 -19
- package/bin/governance/rbac-manager.js +74 -2
- package/bin/governance/ztai-manager.js +49 -7
- package/bin/hindsight-injector.js +3 -3
- package/bin/memory/eis-client.js +71 -34
- package/bin/memory/embedding-engine.js +61 -0
- package/bin/memory/knowledge-graph.js +58 -5
- package/bin/memory/knowledge-indexer.js +53 -6
- package/bin/memory/knowledge-store.js +22 -0
- package/bin/migrations/10.7.0-to-11.0.0.js +110 -0
- package/bin/migrations/schema-versions.js +13 -0
- package/bin/models/anthropic-provider.js +45 -0
- package/bin/models/cloud-broker.js +68 -20
- package/bin/models/gemini-provider.js +51 -0
- package/bin/models/model-client.js +20 -0
- package/bin/models/model-router.js +28 -8
- package/bin/models/openai-provider.js +44 -0
- package/bin/utils/file-io.js +63 -1
- package/bin/utils/index.js +58 -0
- package/docs/getting-started.md +1 -1
- package/docs/user-guide.md +2 -2
- package/package.json +2 -2
- package/.mindforge/personas/data-privacy-engineer.md +0 -187
|
@@ -6,10 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
const crypto = require('crypto');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
const ENCLAVE_PRIVATE_KEY = 'tier3-enclave-secret-key-sim'; // In production, this would be a TEE-bound private key
|
|
9
|
+
const EPHEMERAL_ENCLAVE_KEY = crypto.randomBytes(32).toString('hex');
|
|
11
10
|
const SYSTEM_DID = 'did:mindforge:enclave:0xenterprise';
|
|
12
11
|
|
|
12
|
+
let _enclaveWarningShown = false;
|
|
13
|
+
function warnNonTEE() {
|
|
14
|
+
if (!_enclaveWarningShown) {
|
|
15
|
+
console.warn('[SRE] Running in simulated enclave mode — not backed by hardware TEE');
|
|
16
|
+
_enclaveWarningShown = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
13
20
|
class SREManager {
|
|
14
21
|
constructor() {
|
|
15
22
|
this.activeEnclaves = new Map();
|
|
@@ -25,6 +32,7 @@ class SREManager {
|
|
|
25
32
|
throw new Error(`[SRE-DENY] Tier ${context.tier} principal is not authorized for Sovereign Reason Enclaves.`);
|
|
26
33
|
}
|
|
27
34
|
|
|
35
|
+
warnNonTEE();
|
|
28
36
|
const enclaveId = crypto.randomBytes(12).toString('hex');
|
|
29
37
|
this.activeEnclaves.set(enclaveId, {
|
|
30
38
|
startedAt: new Date().toISOString(),
|
|
@@ -67,7 +75,7 @@ class SREManager {
|
|
|
67
75
|
};
|
|
68
76
|
|
|
69
77
|
// Sign the proof with the Enclave Private Key
|
|
70
|
-
const signature = crypto.createHmac('sha256',
|
|
78
|
+
const signature = crypto.createHmac('sha256', EPHEMERAL_ENCLAVE_KEY)
|
|
71
79
|
.update(JSON.stringify(proofPayload))
|
|
72
80
|
.digest('hex');
|
|
73
81
|
|
|
@@ -93,7 +101,7 @@ class SREManager {
|
|
|
93
101
|
verifyZKProof(certificate) {
|
|
94
102
|
if (certificate.status !== 'SRE-ISOLATED') return false;
|
|
95
103
|
|
|
96
|
-
const expectedSignature = crypto.createHmac('sha256',
|
|
104
|
+
const expectedSignature = crypto.createHmac('sha256', EPHEMERAL_ENCLAVE_KEY)
|
|
97
105
|
.update(JSON.stringify(certificate.proof))
|
|
98
106
|
.digest('hex');
|
|
99
107
|
|
|
@@ -1,67 +1,99 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MindForge v3 — Temporal Hub (State Versioner)
|
|
3
3
|
* Managed high-fidelity snapshots of the .planning directory.
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* Design:
|
|
6
6
|
* - Each snapshot is identified by an audit_id.
|
|
7
7
|
* - Snapshots are stored in .planning/history/[audit_id]/
|
|
8
8
|
* - Atomic snapshots ensure time-travel debugging consistency.
|
|
9
|
+
* - HMAC integrity signatures on metadata for tamper detection.
|
|
9
10
|
*/
|
|
10
11
|
'use strict';
|
|
11
12
|
|
|
12
13
|
const fs = require('fs');
|
|
14
|
+
const fsPromises = require('fs/promises');
|
|
13
15
|
const path = require('path');
|
|
16
|
+
const crypto = require('crypto');
|
|
14
17
|
const { execSync } = require('child_process');
|
|
15
18
|
|
|
16
19
|
const PLANNING_DIR = path.join(process.cwd(), '.planning');
|
|
17
20
|
const HISTORY_DIR = path.join(PLANNING_DIR, 'history');
|
|
18
21
|
|
|
22
|
+
const HMAC_KEY = 'mindforge-temporal-v3';
|
|
23
|
+
|
|
19
24
|
class TemporalHub {
|
|
25
|
+
|
|
26
|
+
static _signMetadata(metadata) {
|
|
27
|
+
const content = JSON.stringify(metadata);
|
|
28
|
+
const hmac = crypto.createHmac('sha256', HMAC_KEY)
|
|
29
|
+
.update(content)
|
|
30
|
+
.digest('hex');
|
|
31
|
+
return { ...metadata, integrity: hmac };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static _verifyMetadata(metadata) {
|
|
35
|
+
if (!metadata.integrity) return false;
|
|
36
|
+
const { integrity, ...rest } = metadata;
|
|
37
|
+
const expected = crypto.createHmac('sha256', HMAC_KEY)
|
|
38
|
+
.update(JSON.stringify(rest))
|
|
39
|
+
.digest('hex');
|
|
40
|
+
return crypto.timingSafeEqual(Buffer.from(integrity), Buffer.from(expected));
|
|
41
|
+
}
|
|
42
|
+
|
|
20
43
|
/**
|
|
21
44
|
* Capture the current state of the .planning directory.
|
|
22
45
|
* @param {string} auditId - Unique identifier from AUDIT.jsonl
|
|
23
46
|
* @param {object} metadata - Optional context (task_name, session_id)
|
|
47
|
+
* @returns {Promise<string|null>} Path to snapshot dir, or null on failure
|
|
24
48
|
*/
|
|
25
|
-
static captureState(auditId, metadata = {}) {
|
|
49
|
+
static async captureState(auditId, metadata = {}) {
|
|
26
50
|
if (!/^[a-f0-9-]{8,40}$/.test(auditId)) {
|
|
27
51
|
throw new Error('Invalid audit ID format');
|
|
28
52
|
}
|
|
29
|
-
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
await fsPromises.access(PLANNING_DIR);
|
|
56
|
+
} catch {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
30
59
|
|
|
31
60
|
const snapshotDir = path.join(HISTORY_DIR, auditId);
|
|
32
61
|
if (!path.resolve(snapshotDir).startsWith(path.resolve(HISTORY_DIR))) {
|
|
33
62
|
throw new Error('Path traversal detected in audit ID');
|
|
34
63
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
64
|
+
|
|
65
|
+
await fsPromises.mkdir(snapshotDir, { recursive: true });
|
|
38
66
|
|
|
39
67
|
try {
|
|
40
|
-
|
|
41
|
-
const files =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const ext = path.extname(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
68
|
+
const allEntries = await fsPromises.readdir(PLANNING_DIR, { withFileTypes: true });
|
|
69
|
+
const files = [];
|
|
70
|
+
|
|
71
|
+
for (const entry of allEntries) {
|
|
72
|
+
if (entry.isDirectory()) continue;
|
|
73
|
+
const ext = path.extname(entry.name).toLowerCase();
|
|
74
|
+
if (['.md', '.json', '.yml', '.yaml', '.log'].includes(ext)) {
|
|
75
|
+
files.push(entry.name);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
await Promise.all(files.map(file =>
|
|
80
|
+
fsPromises.copyFile(
|
|
52
81
|
path.join(PLANNING_DIR, file),
|
|
53
82
|
path.join(snapshotDir, file)
|
|
54
|
-
)
|
|
55
|
-
|
|
83
|
+
)
|
|
84
|
+
));
|
|
56
85
|
|
|
57
|
-
// 3. Save snapshot metadata
|
|
58
86
|
const meta = {
|
|
59
87
|
id: auditId,
|
|
60
88
|
timestamp: new Date().toISOString(),
|
|
61
89
|
...metadata,
|
|
62
90
|
files: files
|
|
63
91
|
};
|
|
64
|
-
|
|
92
|
+
const signedMeta = TemporalHub._signMetadata(meta);
|
|
93
|
+
await fsPromises.writeFile(
|
|
94
|
+
path.join(snapshotDir, 'SNAPSHOT-META.json'),
|
|
95
|
+
JSON.stringify(signedMeta, null, 2)
|
|
96
|
+
);
|
|
65
97
|
|
|
66
98
|
return snapshotDir;
|
|
67
99
|
} catch (err) {
|
|
@@ -72,9 +104,11 @@ class TemporalHub {
|
|
|
72
104
|
|
|
73
105
|
/**
|
|
74
106
|
* Restore the .planning directory to a specific snapshot.
|
|
75
|
-
*
|
|
107
|
+
* Verifies HMAC integrity before restoring.
|
|
108
|
+
* @param {string} auditId
|
|
109
|
+
* @returns {Promise<boolean>}
|
|
76
110
|
*/
|
|
77
|
-
static rollbackTo(auditId) {
|
|
111
|
+
static async rollbackTo(auditId) {
|
|
78
112
|
if (!/^[a-f0-9-]{8,40}$/.test(auditId)) {
|
|
79
113
|
throw new Error('Invalid audit ID format');
|
|
80
114
|
}
|
|
@@ -82,20 +116,39 @@ class TemporalHub {
|
|
|
82
116
|
if (!path.resolve(snapshotDir).startsWith(path.resolve(HISTORY_DIR))) {
|
|
83
117
|
throw new Error('Path traversal detected in audit ID');
|
|
84
118
|
}
|
|
85
|
-
|
|
119
|
+
|
|
120
|
+
try {
|
|
121
|
+
await fsPromises.access(snapshotDir);
|
|
122
|
+
} catch {
|
|
86
123
|
throw new Error(`Snapshot ${auditId} not found in history.`);
|
|
87
124
|
}
|
|
88
125
|
|
|
126
|
+
const metaPath = path.join(snapshotDir, 'SNAPSHOT-META.json');
|
|
89
127
|
try {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
128
|
+
const metaRaw = await fsPromises.readFile(metaPath, 'utf8');
|
|
129
|
+
const metaData = JSON.parse(metaRaw);
|
|
130
|
+
if (!TemporalHub._verifyMetadata(metaData)) {
|
|
131
|
+
throw new Error(`Snapshot ${auditId} failed integrity verification — metadata may be tampered.`);
|
|
132
|
+
}
|
|
133
|
+
} catch (err) {
|
|
134
|
+
if (err.message.includes('integrity verification') || err.message.includes('tampered')) {
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
137
|
+
// Missing metadata file on legacy snapshots — allow rollback with warning
|
|
138
|
+
console.warn(`[temporal-hub] No verifiable metadata for ${auditId}, proceeding without integrity check.`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const allEntries = await fsPromises.readdir(snapshotDir);
|
|
143
|
+
const files = allEntries.filter(f => f !== 'SNAPSHOT-META.json');
|
|
144
|
+
|
|
145
|
+
await Promise.all(files.map(file =>
|
|
146
|
+
fsPromises.copyFile(
|
|
94
147
|
path.join(snapshotDir, file),
|
|
95
148
|
path.join(PLANNING_DIR, file)
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
|
|
149
|
+
)
|
|
150
|
+
));
|
|
151
|
+
|
|
99
152
|
return true;
|
|
100
153
|
} catch (err) {
|
|
101
154
|
console.error(`[temporal-hub] Rollback failed for ${auditId}:`, err.message);
|
|
@@ -108,7 +161,7 @@ class TemporalHub {
|
|
|
108
161
|
*/
|
|
109
162
|
static getHistory() {
|
|
110
163
|
if (!fs.existsSync(HISTORY_DIR)) return [];
|
|
111
|
-
|
|
164
|
+
|
|
112
165
|
try {
|
|
113
166
|
return fs.readdirSync(HISTORY_DIR)
|
|
114
167
|
.map(id => {
|
|
@@ -141,6 +194,50 @@ class TemporalHub {
|
|
|
141
194
|
return null;
|
|
142
195
|
}
|
|
143
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Garbage-collect old snapshots to prevent unbounded disk growth.
|
|
199
|
+
* Keeps the most recent `maxSnapshots` and deletes anything older than `maxAgeDays`.
|
|
200
|
+
*/
|
|
201
|
+
static async gc(options = {}) {
|
|
202
|
+
try {
|
|
203
|
+
const maxSnapshots = options.maxSnapshots || 50;
|
|
204
|
+
const maxAgeDays = options.maxAgeDays || 7;
|
|
205
|
+
const historyDir = path.join(process.cwd(), '.planning', 'history');
|
|
206
|
+
|
|
207
|
+
if (!fs.existsSync(historyDir)) return { deleted: 0, remaining: 0 };
|
|
208
|
+
|
|
209
|
+
const entries = fs.readdirSync(historyDir)
|
|
210
|
+
.filter(name => {
|
|
211
|
+
const fullPath = path.join(historyDir, name);
|
|
212
|
+
try { return fs.statSync(fullPath).isDirectory(); } catch { return false; }
|
|
213
|
+
})
|
|
214
|
+
.map(name => {
|
|
215
|
+
const fullPath = path.join(historyDir, name);
|
|
216
|
+
return { name, path: fullPath, mtime: fs.statSync(fullPath).mtime };
|
|
217
|
+
})
|
|
218
|
+
.sort((a, b) => b.mtime - a.mtime);
|
|
219
|
+
|
|
220
|
+
const now = Date.now();
|
|
221
|
+
const maxAgeMs = maxAgeDays * 24 * 60 * 60 * 1000;
|
|
222
|
+
let deleted = 0;
|
|
223
|
+
|
|
224
|
+
for (let i = 0; i < entries.length; i++) {
|
|
225
|
+
const entry = entries[i];
|
|
226
|
+
const isOverLimit = i >= maxSnapshots;
|
|
227
|
+
const isExpired = (now - entry.mtime.getTime()) > maxAgeMs;
|
|
228
|
+
|
|
229
|
+
if (isOverLimit || isExpired) {
|
|
230
|
+
fs.rmSync(entry.path, { recursive: true, force: true });
|
|
231
|
+
deleted++;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return { deleted, remaining: entries.length - deleted };
|
|
236
|
+
} catch (err) {
|
|
237
|
+
return { deleted: 0, remaining: 0, error: err.message };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
144
241
|
/**
|
|
145
242
|
* Capture terminal output for a command and associate with audit point.
|
|
146
243
|
*/
|
|
@@ -153,7 +250,7 @@ class TemporalHub {
|
|
|
153
250
|
throw new Error('Path traversal detected in audit ID');
|
|
154
251
|
}
|
|
155
252
|
if (!fs.existsSync(logDir)) fs.mkdirSync(logDir, { recursive: true });
|
|
156
|
-
|
|
253
|
+
|
|
157
254
|
if (stdout) fs.writeFileSync(path.join(logDir, 'stdout.log'), stdout);
|
|
158
255
|
if (stderr) fs.writeFileSync(path.join(logDir, 'stderr.log'), stderr);
|
|
159
256
|
}
|
|
@@ -10,6 +10,7 @@ const fs = require('fs');
|
|
|
10
10
|
const path = require('path');
|
|
11
11
|
const os = require('os');
|
|
12
12
|
const crypto = require('crypto');
|
|
13
|
+
const { execFileSync } = require('child_process');
|
|
13
14
|
|
|
14
15
|
const REASON = process.argv[2] || 'Manual approval for sensitive changes.';
|
|
15
16
|
const ROOT = path.resolve(__dirname, '../../');
|
|
@@ -19,14 +20,47 @@ if (!fs.existsSync(APPROVALS_DIR)) {
|
|
|
19
20
|
fs.mkdirSync(APPROVALS_DIR, { recursive: true });
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Attempts to retrieve the GPG signing key configured in git.
|
|
25
|
+
* Returns null if no key is configured or git is unavailable.
|
|
26
|
+
*/
|
|
27
|
+
function getGPGSigningKey() {
|
|
28
|
+
try {
|
|
29
|
+
const key = execFileSync('git', ['config', 'user.signingkey'], { encoding: 'utf8' }).trim();
|
|
30
|
+
return key || null;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Verifies the identity of the approver using GPG if available.
|
|
38
|
+
* Falls back to git identity only (with warning) if no GPG key is configured.
|
|
39
|
+
* @param {string} approver - The approver identity string
|
|
40
|
+
*/
|
|
41
|
+
function verifyApproverIdentity(approver) {
|
|
42
|
+
const gpgKey = getGPGSigningKey();
|
|
43
|
+
|
|
44
|
+
if (!gpgKey) {
|
|
45
|
+
console.warn('[GOVERNANCE] No GPG signing key configured — approval accepted with git identity only');
|
|
46
|
+
return { verified: false, method: 'git_identity', identity: approver };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { verified: true, method: 'gpg_key', identity: approver, keyId: gpgKey };
|
|
50
|
+
}
|
|
51
|
+
|
|
22
52
|
async function approve() {
|
|
23
53
|
const pkgPath = path.join(ROOT, 'package.json');
|
|
24
54
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
25
55
|
|
|
26
56
|
const id = `MF-AUTH-${Date.now().toString(36).toUpperCase()}`;
|
|
27
57
|
const timestamp = new Date().toISOString();
|
|
28
|
-
|
|
29
|
-
|
|
58
|
+
const approver = process.env.USER || 'MindForge User';
|
|
59
|
+
|
|
60
|
+
// Verify approver identity (GPG if available, git identity fallback)
|
|
61
|
+
const identityVerification = verifyApproverIdentity(approver);
|
|
62
|
+
|
|
63
|
+
// Calculate a signature based on current state
|
|
30
64
|
const signature = crypto.createHash('sha256')
|
|
31
65
|
.update(`${id}:${REASON}:${timestamp}:${os.hostname()}`)
|
|
32
66
|
.digest('hex');
|
|
@@ -36,20 +70,22 @@ async function approve() {
|
|
|
36
70
|
project: pkg.name,
|
|
37
71
|
version: pkg.version,
|
|
38
72
|
tier: 3,
|
|
39
|
-
approved_by:
|
|
73
|
+
approved_by: approver,
|
|
40
74
|
timestamp,
|
|
41
75
|
reason: REASON,
|
|
42
|
-
signature: `sha256:${signature}
|
|
76
|
+
signature: `sha256:${signature}`,
|
|
77
|
+
identity_verification: identityVerification
|
|
43
78
|
};
|
|
44
79
|
|
|
45
80
|
const filename = `approval-${id.toLowerCase()}.json`;
|
|
46
81
|
const filePath = path.join(APPROVALS_DIR, filename);
|
|
47
82
|
|
|
48
83
|
fs.writeFileSync(filePath, JSON.stringify(record, null, 2));
|
|
49
|
-
|
|
84
|
+
|
|
50
85
|
console.log('\n✅ Governance approval generated!\n');
|
|
51
86
|
console.log(`ID: ${id}`);
|
|
52
87
|
console.log(`Reason: ${REASON}`);
|
|
88
|
+
console.log(`Verified: ${identityVerification.verified ? 'GPG (' + identityVerification.keyId + ')' : 'git identity only (no GPG key)'}`);
|
|
53
89
|
console.log(`File: .planning/approvals/${filename}`);
|
|
54
90
|
console.log('\nCommit this file to unblock Tier 3 gates in CI.\n');
|
|
55
91
|
}
|
|
@@ -137,6 +137,34 @@ class ImpactAnalyzer {
|
|
|
137
137
|
static resetSession(sessionId) {
|
|
138
138
|
this.sessionState.delete(sessionId);
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Returns the current entropy count for a session without incrementing.
|
|
143
|
+
* Useful for diagnostics and monitoring.
|
|
144
|
+
*/
|
|
145
|
+
static getSessionEntropy(sessionId) {
|
|
146
|
+
return this.sessionState.get(sessionId) || 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Clears all session state entries. Use during process cleanup or testing.
|
|
151
|
+
*/
|
|
152
|
+
static clearAllSessions() {
|
|
153
|
+
this.sessionState.clear();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Clears sessions that have exceeded a given entropy threshold.
|
|
158
|
+
* Prevents unbounded memory growth from abandoned sessions.
|
|
159
|
+
* @param {number} maxEntropy - Sessions above this count are purged.
|
|
160
|
+
*/
|
|
161
|
+
static clearStaleSessions(maxEntropy = 50) {
|
|
162
|
+
for (const [sessionId, count] of this.sessionState.entries()) {
|
|
163
|
+
if (count > maxEntropy) {
|
|
164
|
+
this.sessionState.delete(sessionId);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
140
168
|
}
|
|
141
169
|
|
|
142
170
|
module.exports = ImpactAnalyzer;
|
|
@@ -95,14 +95,21 @@ class PolicyEngine {
|
|
|
95
95
|
// [ENTERPRISE] Tier 3 Reasoning/PQ Proof Bypass
|
|
96
96
|
if (intent.tier >= 3 && (intent.reasoning_proof || intent.pq_proof)) {
|
|
97
97
|
const quantumCrypto = require('./quantum-crypto');
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
let isProofValid = true;
|
|
99
|
+
|
|
100
|
+
if (intent.pq_proof) {
|
|
101
|
+
const zkResult = quantumCrypto.verifyZKProof(intent.pq_proof, intent.id);
|
|
102
|
+
isProofValid = zkResult.verified === true;
|
|
103
|
+
if (!isProofValid) {
|
|
104
|
+
console.log(`[APO-ZK] [${requestId}] ZK proof denied: ${zkResult.reason}${zkResult.simulated ? ' (simulated)' : ''}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
100
107
|
|
|
101
108
|
if (isProofValid) {
|
|
102
109
|
console.log(`[APO-BYPASS] [${requestId}] Tier 3 'Sovereign Proof' verified (${intent.pq_proof ? 'ZK-PQ' : 'Standard'}). Overriding Blast Radius limit.`);
|
|
103
110
|
// Continue to permit check
|
|
104
111
|
} else {
|
|
105
|
-
verdict = { verdict: 'DENY', reason: '
|
|
112
|
+
verdict = { verdict: 'DENY', reason: 'ZK proof verification failed. Configure a verifier module or provide a valid proof.', requestId };
|
|
106
113
|
this.logAudit(intent, impactScore, verdict);
|
|
107
114
|
return verdict;
|
|
108
115
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MindForge v7 — Post-Quantum Agentic Security (PQAS)
|
|
3
3
|
* Simulated Lattice-Based Cryptography (Dilithium-5 / Kyber-1024)
|
|
4
|
+
*
|
|
5
|
+
* @typedef {Object} ZKVerifierProvider
|
|
6
|
+
* @property {(proof: string, intentId: string) => {verified: boolean, reason?: string}} verify
|
|
4
7
|
*/
|
|
5
8
|
'use strict';
|
|
6
9
|
|
|
@@ -47,6 +50,7 @@ class QuantumCrypto {
|
|
|
47
50
|
|
|
48
51
|
/**
|
|
49
52
|
* Signs data using simulated Dilithium-5.
|
|
53
|
+
* @returns {{ signature: string, simulated: true, algorithm: string }}
|
|
50
54
|
*/
|
|
51
55
|
async signPQ(data, privateKey) {
|
|
52
56
|
if (!this.pqasEnabled) throw new Error('PQAS is disabled.');
|
|
@@ -54,14 +58,15 @@ class QuantumCrypto {
|
|
|
54
58
|
throw new Error('Invalid Post-Quantum private key format.');
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
// Simulate the lattice-based signature overhead
|
|
58
61
|
const hash = crypto.createHash('sha3-512').update(data).digest('hex');
|
|
59
62
|
const salt = crypto.randomBytes(16).toString('hex');
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const signature = `pqas_sig_d5_${Buffer.from(hash + salt).toString('base64')}_${crypto.randomBytes(128).toString('base64')}`;
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
signature,
|
|
67
|
+
simulated: true,
|
|
68
|
+
algorithm: 'Dilithium-5'
|
|
69
|
+
};
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
/**
|
|
@@ -69,10 +74,11 @@ class QuantumCrypto {
|
|
|
69
74
|
*/
|
|
70
75
|
verifyPQ(data, signature, publicKey) {
|
|
71
76
|
if (!publicKey.startsWith('mfq7_dilithium5_pub_')) return false;
|
|
72
|
-
|
|
77
|
+
const sig = typeof signature === 'object' && signature.signature ? signature.signature : signature;
|
|
78
|
+
if (!sig.startsWith('pqas_sig_d5_')) return false;
|
|
73
79
|
|
|
74
80
|
try {
|
|
75
|
-
const parts =
|
|
81
|
+
const parts = sig.split('_');
|
|
76
82
|
const blob = Buffer.from(parts[3], 'base64').toString('utf8');
|
|
77
83
|
const hashInSig = blob.slice(0, 128);
|
|
78
84
|
|
|
@@ -102,17 +108,24 @@ class QuantumCrypto {
|
|
|
102
108
|
}
|
|
103
109
|
|
|
104
110
|
verifyZKProof(proof, intentId) {
|
|
105
|
-
if (!proof.startsWith('zkp_v1_'))
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
)
|
|
111
|
+
if (!proof || !proof.startsWith('zkp_v1_')) {
|
|
112
|
+
return { verified: false, reason: 'invalid_proof_format' };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const verifierModule = configManager.get('security.zk_verifier_module');
|
|
117
|
+
if (verifierModule) {
|
|
118
|
+
const verifier = require(verifierModule);
|
|
119
|
+
return verifier.verify(proof, intentId);
|
|
120
|
+
}
|
|
121
|
+
} catch (e) { /* no external verifier configured */ }
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
verified: false,
|
|
125
|
+
reason: 'no_verifier_configured',
|
|
126
|
+
simulated: true,
|
|
127
|
+
message: 'ZK proof verification requires an external verifier module (e.g., snarkjs/circom). Configure via security.zk_verifier_module in config.json.'
|
|
128
|
+
};
|
|
116
129
|
}
|
|
117
130
|
}
|
|
118
131
|
|
|
@@ -18,6 +18,7 @@ class RBACManager {
|
|
|
18
18
|
'did:mindforge:researcher': ['knowledge-detective'],
|
|
19
19
|
'did:mindforge:tool': ['system-operator']
|
|
20
20
|
};
|
|
21
|
+
this.temporaryElevations = new Map(); // key: `${did}:${role}`, value: { timer, expiresAt }
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -84,10 +85,72 @@ class RBACManager {
|
|
|
84
85
|
fs.writeFileSync(this.rolesPath, JSON.stringify(current, null, 2));
|
|
85
86
|
}
|
|
86
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Temporarily elevates an agent to a role for a limited duration.
|
|
90
|
+
* The elevation auto-expires after ttlMs milliseconds.
|
|
91
|
+
* @param {string} did - Agent DID
|
|
92
|
+
* @param {string} role - Role to temporarily grant
|
|
93
|
+
* @param {number} ttlMs - Time-to-live in milliseconds (default: 1 hour)
|
|
94
|
+
*/
|
|
95
|
+
elevateRole(did, role, ttlMs = 3600000) {
|
|
96
|
+
const key = `${did}:${role}`;
|
|
97
|
+
|
|
98
|
+
// Clear existing elevation if any
|
|
99
|
+
if (this.temporaryElevations.has(key)) {
|
|
100
|
+
clearTimeout(this.temporaryElevations.get(key).timer);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const timer = setTimeout(() => {
|
|
104
|
+
this.temporaryElevations.delete(key);
|
|
105
|
+
}, ttlMs);
|
|
106
|
+
|
|
107
|
+
// Prevent timer from keeping process alive
|
|
108
|
+
if (timer.unref) timer.unref();
|
|
109
|
+
|
|
110
|
+
this.temporaryElevations.set(key, {
|
|
111
|
+
timer,
|
|
112
|
+
expiresAt: Date.now() + ttlMs
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return { did, role, expiresAt: Date.now() + ttlMs };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Checks if an agent currently has a temporary role elevation.
|
|
120
|
+
* @param {string} did - Agent DID
|
|
121
|
+
* @param {string} role - Role to check
|
|
122
|
+
*/
|
|
123
|
+
hasTemporaryElevation(did, role) {
|
|
124
|
+
const key = `${did}:${role}`;
|
|
125
|
+
const elevation = this.temporaryElevations.get(key);
|
|
126
|
+
if (!elevation) return false;
|
|
127
|
+
if (Date.now() > elevation.expiresAt) {
|
|
128
|
+
clearTimeout(elevation.timer);
|
|
129
|
+
this.temporaryElevations.delete(key);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Revokes a temporary elevation before its TTL expires.
|
|
137
|
+
* @param {string} did - Agent DID
|
|
138
|
+
* @param {string} role - Role to revoke
|
|
139
|
+
*/
|
|
140
|
+
revokeElevation(did, role) {
|
|
141
|
+
const key = `${did}:${role}`;
|
|
142
|
+
const elevation = this.temporaryElevations.get(key);
|
|
143
|
+
if (elevation) {
|
|
144
|
+
clearTimeout(elevation.timer);
|
|
145
|
+
this.temporaryElevations.delete(key);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
87
149
|
/**
|
|
88
150
|
* Checks if an agent has a specific permission based on their roles.
|
|
89
|
-
*
|
|
90
|
-
* @param {string}
|
|
151
|
+
* Also checks temporary elevations.
|
|
152
|
+
* @param {string} did
|
|
153
|
+
* @param {string} permission
|
|
91
154
|
*/
|
|
92
155
|
hasPermission(did, permission) {
|
|
93
156
|
const roles = this.getRoles(did);
|
|
@@ -99,9 +162,18 @@ class RBACManager {
|
|
|
99
162
|
'guest-agent': ['read_src']
|
|
100
163
|
};
|
|
101
164
|
|
|
165
|
+
// Check static roles first
|
|
102
166
|
for (const role of roles) {
|
|
103
167
|
if (PERMISSION_MAP[role]?.includes(permission)) return true;
|
|
104
168
|
}
|
|
169
|
+
|
|
170
|
+
// Check temporary elevations
|
|
171
|
+
for (const [role, permissions] of Object.entries(PERMISSION_MAP)) {
|
|
172
|
+
if (permissions.includes(permission) && this.hasTemporaryElevation(did, role)) {
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
105
177
|
return false;
|
|
106
178
|
}
|
|
107
179
|
}
|