genesis-ai-cli 7.4.5
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/.env.example +78 -0
- package/README.md +282 -0
- package/dist/src/active-inference/actions.d.ts +75 -0
- package/dist/src/active-inference/actions.js +250 -0
- package/dist/src/active-inference/autonomous-loop.d.ts +103 -0
- package/dist/src/active-inference/autonomous-loop.js +289 -0
- package/dist/src/active-inference/core.d.ts +85 -0
- package/dist/src/active-inference/core.js +555 -0
- package/dist/src/active-inference/demo-autonomous-loop.d.ts +8 -0
- package/dist/src/active-inference/demo-autonomous-loop.js +338 -0
- package/dist/src/active-inference/demo-value-integration.d.ts +8 -0
- package/dist/src/active-inference/demo-value-integration.js +174 -0
- package/dist/src/active-inference/index.d.ts +32 -0
- package/dist/src/active-inference/index.js +88 -0
- package/dist/src/active-inference/integration.d.ts +114 -0
- package/dist/src/active-inference/integration.js +698 -0
- package/dist/src/active-inference/memory-integration.d.ts +51 -0
- package/dist/src/active-inference/memory-integration.js +232 -0
- package/dist/src/active-inference/observations.d.ts +67 -0
- package/dist/src/active-inference/observations.js +147 -0
- package/dist/src/active-inference/test-active-inference.d.ts +8 -0
- package/dist/src/active-inference/test-active-inference.js +320 -0
- package/dist/src/active-inference/test-value-integration.d.ts +6 -0
- package/dist/src/active-inference/test-value-integration.js +168 -0
- package/dist/src/active-inference/types.d.ts +150 -0
- package/dist/src/active-inference/types.js +59 -0
- package/dist/src/active-inference/value-integration.d.ts +164 -0
- package/dist/src/active-inference/value-integration.js +459 -0
- package/dist/src/agents/base-agent.d.ts +53 -0
- package/dist/src/agents/base-agent.js +178 -0
- package/dist/src/agents/builder.d.ts +67 -0
- package/dist/src/agents/builder.js +537 -0
- package/dist/src/agents/critic.d.ts +35 -0
- package/dist/src/agents/critic.js +322 -0
- package/dist/src/agents/ethicist.d.ts +54 -0
- package/dist/src/agents/ethicist.js +393 -0
- package/dist/src/agents/explorer.d.ts +26 -0
- package/dist/src/agents/explorer.js +216 -0
- package/dist/src/agents/feeling.d.ts +41 -0
- package/dist/src/agents/feeling.js +320 -0
- package/dist/src/agents/index.d.ts +111 -0
- package/dist/src/agents/index.js +222 -0
- package/dist/src/agents/memory.d.ts +69 -0
- package/dist/src/agents/memory.js +404 -0
- package/dist/src/agents/message-bus.d.ts +88 -0
- package/dist/src/agents/message-bus.js +267 -0
- package/dist/src/agents/narrator.d.ts +90 -0
- package/dist/src/agents/narrator.js +473 -0
- package/dist/src/agents/planner.d.ts +38 -0
- package/dist/src/agents/planner.js +341 -0
- package/dist/src/agents/predictor.d.ts +73 -0
- package/dist/src/agents/predictor.js +506 -0
- package/dist/src/agents/sensor.d.ts +88 -0
- package/dist/src/agents/sensor.js +377 -0
- package/dist/src/agents/test-agents.d.ts +6 -0
- package/dist/src/agents/test-agents.js +73 -0
- package/dist/src/agents/types.d.ts +194 -0
- package/dist/src/agents/types.js +7 -0
- package/dist/src/brain/index.d.ts +185 -0
- package/dist/src/brain/index.js +843 -0
- package/dist/src/brain/trace.d.ts +91 -0
- package/dist/src/brain/trace.js +327 -0
- package/dist/src/brain/types.d.ts +165 -0
- package/dist/src/brain/types.js +51 -0
- package/dist/src/cli/chat.d.ts +237 -0
- package/dist/src/cli/chat.js +1959 -0
- package/dist/src/cli/dispatcher.d.ts +182 -0
- package/dist/src/cli/dispatcher.js +718 -0
- package/dist/src/cli/human-loop.d.ts +170 -0
- package/dist/src/cli/human-loop.js +543 -0
- package/dist/src/cli/index.d.ts +12 -0
- package/dist/src/cli/index.js +28 -0
- package/dist/src/cli/interactive.d.ts +141 -0
- package/dist/src/cli/interactive.js +757 -0
- package/dist/src/cli/ui.d.ts +205 -0
- package/dist/src/cli/ui.js +632 -0
- package/dist/src/consciousness/attention-schema.d.ts +154 -0
- package/dist/src/consciousness/attention-schema.js +432 -0
- package/dist/src/consciousness/global-workspace.d.ts +149 -0
- package/dist/src/consciousness/global-workspace.js +422 -0
- package/dist/src/consciousness/index.d.ts +186 -0
- package/dist/src/consciousness/index.js +476 -0
- package/dist/src/consciousness/phi-calculator.d.ts +119 -0
- package/dist/src/consciousness/phi-calculator.js +445 -0
- package/dist/src/consciousness/phi-decisions.d.ts +169 -0
- package/dist/src/consciousness/phi-decisions.js +383 -0
- package/dist/src/consciousness/phi-monitor.d.ts +153 -0
- package/dist/src/consciousness/phi-monitor.js +465 -0
- package/dist/src/consciousness/types.d.ts +260 -0
- package/dist/src/consciousness/types.js +44 -0
- package/dist/src/daemon/dream-mode.d.ts +115 -0
- package/dist/src/daemon/dream-mode.js +470 -0
- package/dist/src/daemon/index.d.ts +162 -0
- package/dist/src/daemon/index.js +542 -0
- package/dist/src/daemon/maintenance.d.ts +139 -0
- package/dist/src/daemon/maintenance.js +549 -0
- package/dist/src/daemon/process.d.ts +82 -0
- package/dist/src/daemon/process.js +442 -0
- package/dist/src/daemon/scheduler.d.ts +90 -0
- package/dist/src/daemon/scheduler.js +494 -0
- package/dist/src/daemon/types.d.ts +213 -0
- package/dist/src/daemon/types.js +50 -0
- package/dist/src/epistemic/index.d.ts +74 -0
- package/dist/src/epistemic/index.js +225 -0
- package/dist/src/grounding/epistemic-stack.d.ts +100 -0
- package/dist/src/grounding/epistemic-stack.js +408 -0
- package/dist/src/grounding/feedback.d.ts +98 -0
- package/dist/src/grounding/feedback.js +276 -0
- package/dist/src/grounding/index.d.ts +123 -0
- package/dist/src/grounding/index.js +224 -0
- package/dist/src/grounding/verifier.d.ts +149 -0
- package/dist/src/grounding/verifier.js +484 -0
- package/dist/src/healing/detector.d.ts +110 -0
- package/dist/src/healing/detector.js +436 -0
- package/dist/src/healing/fixer.d.ts +138 -0
- package/dist/src/healing/fixer.js +572 -0
- package/dist/src/healing/index.d.ts +23 -0
- package/dist/src/healing/index.js +43 -0
- package/dist/src/hooks/index.d.ts +135 -0
- package/dist/src/hooks/index.js +317 -0
- package/dist/src/index.d.ts +23 -0
- package/dist/src/index.js +1266 -0
- package/dist/src/kernel/index.d.ts +155 -0
- package/dist/src/kernel/index.js +795 -0
- package/dist/src/kernel/invariants.d.ts +153 -0
- package/dist/src/kernel/invariants.js +355 -0
- package/dist/src/kernel/test-kernel.d.ts +6 -0
- package/dist/src/kernel/test-kernel.js +108 -0
- package/dist/src/kernel/test-real-mcp.d.ts +10 -0
- package/dist/src/kernel/test-real-mcp.js +295 -0
- package/dist/src/llm/index.d.ts +146 -0
- package/dist/src/llm/index.js +428 -0
- package/dist/src/llm/router.d.ts +136 -0
- package/dist/src/llm/router.js +510 -0
- package/dist/src/mcp/index.d.ts +85 -0
- package/dist/src/mcp/index.js +657 -0
- package/dist/src/mcp/resilient.d.ts +139 -0
- package/dist/src/mcp/resilient.js +417 -0
- package/dist/src/memory/cache.d.ts +118 -0
- package/dist/src/memory/cache.js +356 -0
- package/dist/src/memory/cognitive-workspace.d.ts +231 -0
- package/dist/src/memory/cognitive-workspace.js +521 -0
- package/dist/src/memory/consolidation.d.ts +99 -0
- package/dist/src/memory/consolidation.js +443 -0
- package/dist/src/memory/episodic.d.ts +114 -0
- package/dist/src/memory/episodic.js +394 -0
- package/dist/src/memory/forgetting.d.ts +134 -0
- package/dist/src/memory/forgetting.js +324 -0
- package/dist/src/memory/index.d.ts +211 -0
- package/dist/src/memory/index.js +367 -0
- package/dist/src/memory/indexer.d.ts +123 -0
- package/dist/src/memory/indexer.js +479 -0
- package/dist/src/memory/procedural.d.ts +136 -0
- package/dist/src/memory/procedural.js +479 -0
- package/dist/src/memory/semantic.d.ts +132 -0
- package/dist/src/memory/semantic.js +497 -0
- package/dist/src/memory/types.d.ts +193 -0
- package/dist/src/memory/types.js +15 -0
- package/dist/src/orchestrator.d.ts +65 -0
- package/dist/src/orchestrator.js +317 -0
- package/dist/src/persistence/index.d.ts +257 -0
- package/dist/src/persistence/index.js +763 -0
- package/dist/src/pipeline/executor.d.ts +51 -0
- package/dist/src/pipeline/executor.js +695 -0
- package/dist/src/pipeline/index.d.ts +7 -0
- package/dist/src/pipeline/index.js +11 -0
- package/dist/src/self-production.d.ts +67 -0
- package/dist/src/self-production.js +205 -0
- package/dist/src/subagents/executor.d.ts +58 -0
- package/dist/src/subagents/executor.js +283 -0
- package/dist/src/subagents/index.d.ts +37 -0
- package/dist/src/subagents/index.js +53 -0
- package/dist/src/subagents/registry.d.ts +23 -0
- package/dist/src/subagents/registry.js +167 -0
- package/dist/src/subagents/types.d.ts +79 -0
- package/dist/src/subagents/types.js +14 -0
- package/dist/src/tools/bash.d.ts +139 -0
- package/dist/src/tools/bash.js +583 -0
- package/dist/src/tools/edit.d.ts +125 -0
- package/dist/src/tools/edit.js +424 -0
- package/dist/src/tools/git.d.ts +179 -0
- package/dist/src/tools/git.js +504 -0
- package/dist/src/tools/index.d.ts +21 -0
- package/dist/src/tools/index.js +163 -0
- package/dist/src/types.d.ts +145 -0
- package/dist/src/types.js +7 -0
- package/dist/src/world-model/decoder.d.ts +163 -0
- package/dist/src/world-model/decoder.js +517 -0
- package/dist/src/world-model/digital-twin.d.ts +219 -0
- package/dist/src/world-model/digital-twin.js +695 -0
- package/dist/src/world-model/encoder.d.ts +141 -0
- package/dist/src/world-model/encoder.js +564 -0
- package/dist/src/world-model/index.d.ts +221 -0
- package/dist/src/world-model/index.js +772 -0
- package/dist/src/world-model/predictor.d.ts +161 -0
- package/dist/src/world-model/predictor.js +681 -0
- package/dist/src/world-model/test-value-jepa.d.ts +8 -0
- package/dist/src/world-model/test-value-jepa.js +430 -0
- package/dist/src/world-model/types.d.ts +341 -0
- package/dist/src/world-model/types.js +69 -0
- package/dist/src/world-model/value-jepa.d.ts +247 -0
- package/dist/src/world-model/value-jepa.js +622 -0
- package/dist/test/brain.test.d.ts +11 -0
- package/dist/test/brain.test.js +358 -0
- package/dist/test/cli/dispatcher.test.d.ts +4 -0
- package/dist/test/cli/dispatcher.test.js +332 -0
- package/dist/test/cli/human-loop.test.d.ts +4 -0
- package/dist/test/cli/human-loop.test.js +270 -0
- package/dist/test/grounding/feedback.test.d.ts +4 -0
- package/dist/test/grounding/feedback.test.js +462 -0
- package/dist/test/grounding/verifier.test.d.ts +4 -0
- package/dist/test/grounding/verifier.test.js +442 -0
- package/dist/test/grounding.test.d.ts +6 -0
- package/dist/test/grounding.test.js +246 -0
- package/dist/test/healing/detector.test.d.ts +4 -0
- package/dist/test/healing/detector.test.js +266 -0
- package/dist/test/healing/fixer.test.d.ts +4 -0
- package/dist/test/healing/fixer.test.js +369 -0
- package/dist/test/integration.test.d.ts +5 -0
- package/dist/test/integration.test.js +290 -0
- package/dist/test/tools/bash.test.d.ts +4 -0
- package/dist/test/tools/bash.test.js +348 -0
- package/dist/test/tools/edit.test.d.ts +4 -0
- package/dist/test/tools/edit.test.js +350 -0
- package/dist/test/tools/git.test.d.ts +4 -0
- package/dist/test/tools/git.test.js +350 -0
- package/package.json +60 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis 6.0 - φ-Aware Decision Making
|
|
3
|
+
*
|
|
4
|
+
* Decision-making that takes consciousness level into account.
|
|
5
|
+
*
|
|
6
|
+
* Key principle: When consciousness (φ) is low, the system should:
|
|
7
|
+
* - Defer important decisions to humans
|
|
8
|
+
* - Reduce action scope
|
|
9
|
+
* - Focus on recovery
|
|
10
|
+
* - Log uncertainty
|
|
11
|
+
*
|
|
12
|
+
* This implements a form of "cognitive humility" where the system
|
|
13
|
+
* knows when it doesn't know.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { createPhiDecisionMaker } from './consciousness/phi-decisions.js';
|
|
18
|
+
*
|
|
19
|
+
* const decider = createPhiDecisionMaker({
|
|
20
|
+
* phiThreshold: 0.3,
|
|
21
|
+
* deferToHuman: true,
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Weight options by consciousness
|
|
25
|
+
* const weighted = decider.weightByPhi(options);
|
|
26
|
+
*
|
|
27
|
+
* // Check if should defer
|
|
28
|
+
* if (decider.shouldDefer()) {
|
|
29
|
+
* return askHuman(question);
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* // Make a φ-aware decision
|
|
33
|
+
* const decision = decider.decide(options);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
import { ConsciousnessState } from './types.js';
|
|
37
|
+
import { PhiMonitor } from './phi-monitor.js';
|
|
38
|
+
export interface DecisionOption {
|
|
39
|
+
id: string;
|
|
40
|
+
label: string;
|
|
41
|
+
description?: string;
|
|
42
|
+
risk: number;
|
|
43
|
+
reversibility: number;
|
|
44
|
+
urgency: number;
|
|
45
|
+
confidence: number;
|
|
46
|
+
data?: unknown;
|
|
47
|
+
}
|
|
48
|
+
export interface WeightedOption extends DecisionOption {
|
|
49
|
+
phiWeight: number;
|
|
50
|
+
finalScore: number;
|
|
51
|
+
recommended: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface Decision {
|
|
54
|
+
id: string;
|
|
55
|
+
options: WeightedOption[];
|
|
56
|
+
selected: WeightedOption | null;
|
|
57
|
+
deferred: boolean;
|
|
58
|
+
deferReason?: string;
|
|
59
|
+
phiAtDecision: number;
|
|
60
|
+
stateAtDecision: ConsciousnessState;
|
|
61
|
+
timestamp: Date;
|
|
62
|
+
reasoning: string[];
|
|
63
|
+
}
|
|
64
|
+
export interface PhiSnapshot {
|
|
65
|
+
phi: number;
|
|
66
|
+
state: ConsciousnessState;
|
|
67
|
+
shouldDefer: boolean;
|
|
68
|
+
riskTolerance: number;
|
|
69
|
+
timestamp: Date;
|
|
70
|
+
}
|
|
71
|
+
export interface PhiDecisionConfig {
|
|
72
|
+
phiThreshold: number;
|
|
73
|
+
deferToHuman: boolean;
|
|
74
|
+
riskAversion: number;
|
|
75
|
+
minConfidenceForAction: number;
|
|
76
|
+
logDecisions: boolean;
|
|
77
|
+
urgencyOverride: number;
|
|
78
|
+
}
|
|
79
|
+
export declare const DEFAULT_PHI_DECISION_CONFIG: PhiDecisionConfig;
|
|
80
|
+
export type DecisionEventType = 'decision_made' | 'decision_deferred' | 'options_weighted' | 'risk_rejected';
|
|
81
|
+
export type DecisionEventHandler = (event: {
|
|
82
|
+
type: DecisionEventType;
|
|
83
|
+
data?: unknown;
|
|
84
|
+
}) => void;
|
|
85
|
+
export declare class PhiDecisionMaker {
|
|
86
|
+
private config;
|
|
87
|
+
private monitor;
|
|
88
|
+
private currentPhi;
|
|
89
|
+
private currentState;
|
|
90
|
+
private decisions;
|
|
91
|
+
private eventHandlers;
|
|
92
|
+
constructor(config?: Partial<PhiDecisionConfig>);
|
|
93
|
+
/**
|
|
94
|
+
* Set the φ monitor to track
|
|
95
|
+
*/
|
|
96
|
+
setMonitor(monitor: PhiMonitor): void;
|
|
97
|
+
/**
|
|
98
|
+
* Update current φ level (if not using monitor)
|
|
99
|
+
*/
|
|
100
|
+
updatePhi(phi: number, state: ConsciousnessState): void;
|
|
101
|
+
/**
|
|
102
|
+
* Make a φ-aware decision
|
|
103
|
+
*/
|
|
104
|
+
decide(options: DecisionOption[]): Decision;
|
|
105
|
+
/**
|
|
106
|
+
* Weight options by consciousness level
|
|
107
|
+
*/
|
|
108
|
+
weightByPhi(options: DecisionOption[]): WeightedOption[];
|
|
109
|
+
/**
|
|
110
|
+
* Calculate weight based on φ and option properties
|
|
111
|
+
*/
|
|
112
|
+
private calculatePhiWeight;
|
|
113
|
+
/**
|
|
114
|
+
* Calculate final score
|
|
115
|
+
*/
|
|
116
|
+
private calculateFinalScore;
|
|
117
|
+
/**
|
|
118
|
+
* Select the best option
|
|
119
|
+
*/
|
|
120
|
+
private selectBest;
|
|
121
|
+
/**
|
|
122
|
+
* Should we defer this decision to a human?
|
|
123
|
+
*/
|
|
124
|
+
shouldDefer(): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Get reason for deferral
|
|
127
|
+
*/
|
|
128
|
+
getDeferReason(): string;
|
|
129
|
+
/**
|
|
130
|
+
* Get current risk tolerance based on φ
|
|
131
|
+
*/
|
|
132
|
+
getRiskTolerance(): number;
|
|
133
|
+
/**
|
|
134
|
+
* Log current consciousness state for observability
|
|
135
|
+
*/
|
|
136
|
+
logPhiState(): PhiSnapshot;
|
|
137
|
+
/**
|
|
138
|
+
* Get decision history
|
|
139
|
+
*/
|
|
140
|
+
getDecisions(options?: {
|
|
141
|
+
limit?: number;
|
|
142
|
+
deferred?: boolean;
|
|
143
|
+
}): Decision[];
|
|
144
|
+
/**
|
|
145
|
+
* Get decision by ID
|
|
146
|
+
*/
|
|
147
|
+
getDecision(id: string): Decision | undefined;
|
|
148
|
+
on(handler: DecisionEventHandler): () => void;
|
|
149
|
+
private emit;
|
|
150
|
+
private syncWithMonitor;
|
|
151
|
+
private recordDecision;
|
|
152
|
+
private generateId;
|
|
153
|
+
stats(): {
|
|
154
|
+
totalDecisions: number;
|
|
155
|
+
deferredDecisions: number;
|
|
156
|
+
deferralRate: number;
|
|
157
|
+
avgPhiAtDecision: number;
|
|
158
|
+
recentDecisions: number;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export declare function createPhiDecisionMaker(config?: Partial<PhiDecisionConfig>): PhiDecisionMaker;
|
|
162
|
+
export declare function createDecisionOption(id: string, label: string, options?: {
|
|
163
|
+
description?: string;
|
|
164
|
+
risk?: number;
|
|
165
|
+
reversibility?: number;
|
|
166
|
+
urgency?: number;
|
|
167
|
+
confidence?: number;
|
|
168
|
+
data?: unknown;
|
|
169
|
+
}): DecisionOption;
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis 6.0 - φ-Aware Decision Making
|
|
4
|
+
*
|
|
5
|
+
* Decision-making that takes consciousness level into account.
|
|
6
|
+
*
|
|
7
|
+
* Key principle: When consciousness (φ) is low, the system should:
|
|
8
|
+
* - Defer important decisions to humans
|
|
9
|
+
* - Reduce action scope
|
|
10
|
+
* - Focus on recovery
|
|
11
|
+
* - Log uncertainty
|
|
12
|
+
*
|
|
13
|
+
* This implements a form of "cognitive humility" where the system
|
|
14
|
+
* knows when it doesn't know.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createPhiDecisionMaker } from './consciousness/phi-decisions.js';
|
|
19
|
+
*
|
|
20
|
+
* const decider = createPhiDecisionMaker({
|
|
21
|
+
* phiThreshold: 0.3,
|
|
22
|
+
* deferToHuman: true,
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Weight options by consciousness
|
|
26
|
+
* const weighted = decider.weightByPhi(options);
|
|
27
|
+
*
|
|
28
|
+
* // Check if should defer
|
|
29
|
+
* if (decider.shouldDefer()) {
|
|
30
|
+
* return askHuman(question);
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* // Make a φ-aware decision
|
|
34
|
+
* const decision = decider.decide(options);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.PhiDecisionMaker = exports.DEFAULT_PHI_DECISION_CONFIG = void 0;
|
|
39
|
+
exports.createPhiDecisionMaker = createPhiDecisionMaker;
|
|
40
|
+
exports.createDecisionOption = createDecisionOption;
|
|
41
|
+
exports.DEFAULT_PHI_DECISION_CONFIG = {
|
|
42
|
+
phiThreshold: 0.3,
|
|
43
|
+
deferToHuman: true,
|
|
44
|
+
riskAversion: 0.6,
|
|
45
|
+
minConfidenceForAction: 0.5,
|
|
46
|
+
logDecisions: true,
|
|
47
|
+
urgencyOverride: 0.9,
|
|
48
|
+
};
|
|
49
|
+
class PhiDecisionMaker {
|
|
50
|
+
config;
|
|
51
|
+
monitor = null;
|
|
52
|
+
currentPhi = 0.5;
|
|
53
|
+
currentState = 'aware';
|
|
54
|
+
decisions = [];
|
|
55
|
+
eventHandlers = new Set();
|
|
56
|
+
constructor(config = {}) {
|
|
57
|
+
this.config = { ...exports.DEFAULT_PHI_DECISION_CONFIG, ...config };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Set the φ monitor to track
|
|
61
|
+
*/
|
|
62
|
+
setMonitor(monitor) {
|
|
63
|
+
this.monitor = monitor;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Update current φ level (if not using monitor)
|
|
67
|
+
*/
|
|
68
|
+
updatePhi(phi, state) {
|
|
69
|
+
this.currentPhi = phi;
|
|
70
|
+
this.currentState = state;
|
|
71
|
+
}
|
|
72
|
+
// ============================================================================
|
|
73
|
+
// Decision Making
|
|
74
|
+
// ============================================================================
|
|
75
|
+
/**
|
|
76
|
+
* Make a φ-aware decision
|
|
77
|
+
*/
|
|
78
|
+
decide(options) {
|
|
79
|
+
// Get current consciousness level
|
|
80
|
+
this.syncWithMonitor();
|
|
81
|
+
const now = new Date();
|
|
82
|
+
const reasoning = [];
|
|
83
|
+
// Weight options
|
|
84
|
+
const weighted = this.weightByPhi(options);
|
|
85
|
+
reasoning.push(`Weighted ${options.length} options at φ=${this.currentPhi.toFixed(2)}`);
|
|
86
|
+
// Check if should defer
|
|
87
|
+
const urgentOptions = options.filter((o) => o.urgency >= this.config.urgencyOverride);
|
|
88
|
+
const shouldDeferDecision = this.shouldDefer() && urgentOptions.length === 0;
|
|
89
|
+
if (shouldDeferDecision) {
|
|
90
|
+
reasoning.push('Decision deferred due to low consciousness level');
|
|
91
|
+
const decision = {
|
|
92
|
+
id: this.generateId(),
|
|
93
|
+
options: weighted,
|
|
94
|
+
selected: null,
|
|
95
|
+
deferred: true,
|
|
96
|
+
deferReason: this.getDeferReason(),
|
|
97
|
+
phiAtDecision: this.currentPhi,
|
|
98
|
+
stateAtDecision: this.currentState,
|
|
99
|
+
timestamp: now,
|
|
100
|
+
reasoning,
|
|
101
|
+
};
|
|
102
|
+
this.recordDecision(decision);
|
|
103
|
+
this.emit({ type: 'decision_deferred', data: decision });
|
|
104
|
+
return decision;
|
|
105
|
+
}
|
|
106
|
+
// Select best option
|
|
107
|
+
const selected = this.selectBest(weighted, reasoning);
|
|
108
|
+
const decision = {
|
|
109
|
+
id: this.generateId(),
|
|
110
|
+
options: weighted,
|
|
111
|
+
selected,
|
|
112
|
+
deferred: false,
|
|
113
|
+
phiAtDecision: this.currentPhi,
|
|
114
|
+
stateAtDecision: this.currentState,
|
|
115
|
+
timestamp: now,
|
|
116
|
+
reasoning,
|
|
117
|
+
};
|
|
118
|
+
this.recordDecision(decision);
|
|
119
|
+
this.emit({ type: 'decision_made', data: decision });
|
|
120
|
+
return decision;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Weight options by consciousness level
|
|
124
|
+
*/
|
|
125
|
+
weightByPhi(options) {
|
|
126
|
+
this.syncWithMonitor();
|
|
127
|
+
const weighted = options.map((option) => {
|
|
128
|
+
// Calculate phi weight
|
|
129
|
+
const phiWeight = this.calculatePhiWeight(option);
|
|
130
|
+
// Calculate final score
|
|
131
|
+
const finalScore = this.calculateFinalScore(option, phiWeight);
|
|
132
|
+
return {
|
|
133
|
+
...option,
|
|
134
|
+
phiWeight,
|
|
135
|
+
finalScore,
|
|
136
|
+
recommended: false,
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
// Mark recommended
|
|
140
|
+
if (weighted.length > 0) {
|
|
141
|
+
weighted.sort((a, b) => b.finalScore - a.finalScore);
|
|
142
|
+
weighted[0].recommended = true;
|
|
143
|
+
}
|
|
144
|
+
this.emit({ type: 'options_weighted', data: weighted });
|
|
145
|
+
return weighted;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Calculate weight based on φ and option properties
|
|
149
|
+
*/
|
|
150
|
+
calculatePhiWeight(option) {
|
|
151
|
+
// Risk adjustment: lower φ = more risk aversion
|
|
152
|
+
const riskAdjustment = 1 - (option.risk * (1 - this.currentPhi) * this.config.riskAversion);
|
|
153
|
+
// Reversibility bonus: prefer reversible actions at low φ
|
|
154
|
+
const reversibilityBonus = option.reversibility * (1 - this.currentPhi) * 0.3;
|
|
155
|
+
// Urgency factor: urgent items get boosted
|
|
156
|
+
const urgencyFactor = option.urgency * 0.2;
|
|
157
|
+
// Confidence factor
|
|
158
|
+
const confidenceFactor = option.confidence;
|
|
159
|
+
return Math.min(1, Math.max(0, 0.3 * riskAdjustment +
|
|
160
|
+
0.2 * reversibilityBonus +
|
|
161
|
+
0.2 * urgencyFactor +
|
|
162
|
+
0.3 * confidenceFactor));
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Calculate final score
|
|
166
|
+
*/
|
|
167
|
+
calculateFinalScore(option, phiWeight) {
|
|
168
|
+
// Base score from option confidence
|
|
169
|
+
let score = option.confidence;
|
|
170
|
+
// Apply phi weight
|
|
171
|
+
score *= phiWeight;
|
|
172
|
+
// Penalize risky options at low φ
|
|
173
|
+
if (this.currentPhi < 0.5) {
|
|
174
|
+
score -= option.risk * (0.5 - this.currentPhi);
|
|
175
|
+
}
|
|
176
|
+
// Boost reversible options
|
|
177
|
+
score += option.reversibility * 0.1;
|
|
178
|
+
return Math.min(1, Math.max(0, score));
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Select the best option
|
|
182
|
+
*/
|
|
183
|
+
selectBest(options, reasoning) {
|
|
184
|
+
if (options.length === 0) {
|
|
185
|
+
reasoning.push('No options available');
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
// Sort by final score
|
|
189
|
+
const sorted = [...options].sort((a, b) => b.finalScore - a.finalScore);
|
|
190
|
+
const best = sorted[0];
|
|
191
|
+
// Check minimum confidence
|
|
192
|
+
if (best.confidence < this.config.minConfidenceForAction) {
|
|
193
|
+
reasoning.push(`Best option confidence (${best.confidence.toFixed(2)}) below threshold`);
|
|
194
|
+
// Fall back to safest option
|
|
195
|
+
const safest = [...options].sort((a, b) => {
|
|
196
|
+
const safetyA = a.reversibility * (1 - a.risk);
|
|
197
|
+
const safetyB = b.reversibility * (1 - b.risk);
|
|
198
|
+
return safetyB - safetyA;
|
|
199
|
+
})[0];
|
|
200
|
+
reasoning.push(`Selected safest option: ${safest.label}`);
|
|
201
|
+
return safest;
|
|
202
|
+
}
|
|
203
|
+
// Check risk threshold
|
|
204
|
+
if (best.risk > 0.8 && this.currentPhi < 0.5) {
|
|
205
|
+
reasoning.push(`Rejected high-risk option at low φ`);
|
|
206
|
+
this.emit({ type: 'risk_rejected', data: best });
|
|
207
|
+
// Find next best non-high-risk option
|
|
208
|
+
const safer = sorted.find((o) => o.risk <= 0.8);
|
|
209
|
+
if (safer) {
|
|
210
|
+
reasoning.push(`Selected safer alternative: ${safer.label}`);
|
|
211
|
+
return safer;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
reasoning.push(`Selected: ${best.label} (score: ${best.finalScore.toFixed(2)})`);
|
|
215
|
+
return best;
|
|
216
|
+
}
|
|
217
|
+
// ============================================================================
|
|
218
|
+
// Deferral Logic
|
|
219
|
+
// ============================================================================
|
|
220
|
+
/**
|
|
221
|
+
* Should we defer this decision to a human?
|
|
222
|
+
*/
|
|
223
|
+
shouldDefer() {
|
|
224
|
+
this.syncWithMonitor();
|
|
225
|
+
if (!this.config.deferToHuman)
|
|
226
|
+
return false;
|
|
227
|
+
// Defer if φ below threshold
|
|
228
|
+
if (this.currentPhi < this.config.phiThreshold)
|
|
229
|
+
return true;
|
|
230
|
+
// Defer if in fragmented state
|
|
231
|
+
if (this.currentState === 'fragmented')
|
|
232
|
+
return true;
|
|
233
|
+
// Defer if dormant (shouldn't be making decisions)
|
|
234
|
+
if (this.currentState === 'dormant')
|
|
235
|
+
return true;
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Get reason for deferral
|
|
240
|
+
*/
|
|
241
|
+
getDeferReason() {
|
|
242
|
+
if (this.currentPhi < this.config.phiThreshold) {
|
|
243
|
+
return `φ (${this.currentPhi.toFixed(2)}) below threshold (${this.config.phiThreshold})`;
|
|
244
|
+
}
|
|
245
|
+
if (this.currentState === 'fragmented') {
|
|
246
|
+
return 'System integration compromised';
|
|
247
|
+
}
|
|
248
|
+
if (this.currentState === 'dormant') {
|
|
249
|
+
return 'System in dormant state';
|
|
250
|
+
}
|
|
251
|
+
return 'Unknown deferral reason';
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get current risk tolerance based on φ
|
|
255
|
+
*/
|
|
256
|
+
getRiskTolerance() {
|
|
257
|
+
this.syncWithMonitor();
|
|
258
|
+
// High φ = can take more risks
|
|
259
|
+
// Low φ = play it safe
|
|
260
|
+
const baseTolerance = 1 - this.config.riskAversion;
|
|
261
|
+
return baseTolerance * this.currentPhi;
|
|
262
|
+
}
|
|
263
|
+
// ============================================================================
|
|
264
|
+
// State Logging
|
|
265
|
+
// ============================================================================
|
|
266
|
+
/**
|
|
267
|
+
* Log current consciousness state for observability
|
|
268
|
+
*/
|
|
269
|
+
logPhiState() {
|
|
270
|
+
this.syncWithMonitor();
|
|
271
|
+
return {
|
|
272
|
+
phi: this.currentPhi,
|
|
273
|
+
state: this.currentState,
|
|
274
|
+
shouldDefer: this.shouldDefer(),
|
|
275
|
+
riskTolerance: this.getRiskTolerance(),
|
|
276
|
+
timestamp: new Date(),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
// ============================================================================
|
|
280
|
+
// History
|
|
281
|
+
// ============================================================================
|
|
282
|
+
/**
|
|
283
|
+
* Get decision history
|
|
284
|
+
*/
|
|
285
|
+
getDecisions(options = {}) {
|
|
286
|
+
let result = [...this.decisions];
|
|
287
|
+
if (options.deferred !== undefined) {
|
|
288
|
+
result = result.filter((d) => d.deferred === options.deferred);
|
|
289
|
+
}
|
|
290
|
+
// Sort by timestamp (newest first)
|
|
291
|
+
result.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime());
|
|
292
|
+
if (options.limit) {
|
|
293
|
+
result = result.slice(0, options.limit);
|
|
294
|
+
}
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Get decision by ID
|
|
299
|
+
*/
|
|
300
|
+
getDecision(id) {
|
|
301
|
+
return this.decisions.find((d) => d.id === id);
|
|
302
|
+
}
|
|
303
|
+
// ============================================================================
|
|
304
|
+
// Events
|
|
305
|
+
// ============================================================================
|
|
306
|
+
on(handler) {
|
|
307
|
+
this.eventHandlers.add(handler);
|
|
308
|
+
return () => this.eventHandlers.delete(handler);
|
|
309
|
+
}
|
|
310
|
+
emit(event) {
|
|
311
|
+
for (const handler of this.eventHandlers) {
|
|
312
|
+
try {
|
|
313
|
+
handler(event);
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
console.error('Decision event handler error:', err);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// ============================================================================
|
|
321
|
+
// Helpers
|
|
322
|
+
// ============================================================================
|
|
323
|
+
syncWithMonitor() {
|
|
324
|
+
if (this.monitor) {
|
|
325
|
+
const level = this.monitor.getCurrentLevel();
|
|
326
|
+
this.currentPhi = level.phi;
|
|
327
|
+
this.currentState = this.monitor.getState();
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
recordDecision(decision) {
|
|
331
|
+
if (this.config.logDecisions) {
|
|
332
|
+
this.decisions.push(decision);
|
|
333
|
+
// Limit history
|
|
334
|
+
if (this.decisions.length > 1000) {
|
|
335
|
+
this.decisions = this.decisions.slice(-1000);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
generateId() {
|
|
340
|
+
return `decision-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
341
|
+
}
|
|
342
|
+
// ============================================================================
|
|
343
|
+
// Stats
|
|
344
|
+
// ============================================================================
|
|
345
|
+
stats() {
|
|
346
|
+
const total = this.decisions.length;
|
|
347
|
+
const deferred = this.decisions.filter((d) => d.deferred).length;
|
|
348
|
+
const avgPhi = total > 0
|
|
349
|
+
? this.decisions.reduce((sum, d) => sum + d.phiAtDecision, 0) / total
|
|
350
|
+
: 0;
|
|
351
|
+
const hourAgo = Date.now() - 3600000;
|
|
352
|
+
const recent = this.decisions.filter((d) => d.timestamp.getTime() > hourAgo).length;
|
|
353
|
+
return {
|
|
354
|
+
totalDecisions: total,
|
|
355
|
+
deferredDecisions: deferred,
|
|
356
|
+
deferralRate: total > 0 ? deferred / total : 0,
|
|
357
|
+
avgPhiAtDecision: avgPhi,
|
|
358
|
+
recentDecisions: recent,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
exports.PhiDecisionMaker = PhiDecisionMaker;
|
|
363
|
+
// ============================================================================
|
|
364
|
+
// Factory
|
|
365
|
+
// ============================================================================
|
|
366
|
+
function createPhiDecisionMaker(config) {
|
|
367
|
+
return new PhiDecisionMaker(config);
|
|
368
|
+
}
|
|
369
|
+
// ============================================================================
|
|
370
|
+
// Option Factory
|
|
371
|
+
// ============================================================================
|
|
372
|
+
function createDecisionOption(id, label, options = {}) {
|
|
373
|
+
return {
|
|
374
|
+
id,
|
|
375
|
+
label,
|
|
376
|
+
description: options.description,
|
|
377
|
+
risk: options.risk ?? 0.5,
|
|
378
|
+
reversibility: options.reversibility ?? 0.5,
|
|
379
|
+
urgency: options.urgency ?? 0.5,
|
|
380
|
+
confidence: options.confidence ?? 0.5,
|
|
381
|
+
data: options.data,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis 6.0 - φ Monitor
|
|
3
|
+
*
|
|
4
|
+
* Real-time monitoring of consciousness level (φ).
|
|
5
|
+
* Tracks φ over time, detects anomalies, and enforces INV-006.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Continuous φ tracking
|
|
9
|
+
* - Per-agent φ calculation
|
|
10
|
+
* - Trend analysis (rising/stable/falling)
|
|
11
|
+
* - Anomaly detection
|
|
12
|
+
* - Threshold alerts
|
|
13
|
+
* - Historical data
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { createPhiMonitor } from './consciousness/phi-monitor.js';
|
|
18
|
+
*
|
|
19
|
+
* const monitor = createPhiMonitor({
|
|
20
|
+
* minPhi: 0.1, // INV-006 threshold
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Start monitoring
|
|
24
|
+
* monitor.start();
|
|
25
|
+
*
|
|
26
|
+
* // Get current level
|
|
27
|
+
* const level = monitor.getCurrentLevel();
|
|
28
|
+
*
|
|
29
|
+
* // Check INV-006
|
|
30
|
+
* const satisfied = monitor.checkInvariant();
|
|
31
|
+
*
|
|
32
|
+
* // Subscribe to alerts
|
|
33
|
+
* monitor.onPhiDrop(0.2, () => console.warn('φ dropping!'));
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
import { ConsciousnessLevel, ConsciousnessState, ConsciousnessTrend, ConsciousnessAnomaly, AnomalyType, SystemState } from './types.js';
|
|
37
|
+
export interface PhiMonitorConfig {
|
|
38
|
+
updateIntervalMs: number;
|
|
39
|
+
historyLimit: number;
|
|
40
|
+
minPhi: number;
|
|
41
|
+
anomalyDetection: boolean;
|
|
42
|
+
dropThreshold: number;
|
|
43
|
+
spikeThreshold: number;
|
|
44
|
+
trendWindowSize: number;
|
|
45
|
+
}
|
|
46
|
+
export declare const DEFAULT_PHI_MONITOR_CONFIG: PhiMonitorConfig;
|
|
47
|
+
export type PhiMonitorEventType = 'phi_updated' | 'phi_threshold_crossed' | 'state_changed' | 'trend_changed' | 'anomaly_detected' | 'anomaly_resolved' | 'invariant_violated' | 'invariant_restored';
|
|
48
|
+
export type PhiMonitorEventHandler = (event: {
|
|
49
|
+
type: PhiMonitorEventType;
|
|
50
|
+
data?: unknown;
|
|
51
|
+
}) => void;
|
|
52
|
+
export declare class PhiMonitor {
|
|
53
|
+
private config;
|
|
54
|
+
private calculator;
|
|
55
|
+
private updateTimer;
|
|
56
|
+
private running;
|
|
57
|
+
private currentLevel;
|
|
58
|
+
private currentState;
|
|
59
|
+
private currentTrend;
|
|
60
|
+
private agentPhi;
|
|
61
|
+
private anomalies;
|
|
62
|
+
private history;
|
|
63
|
+
private eventHandlers;
|
|
64
|
+
private dropCallbacks;
|
|
65
|
+
private anomalyCallbacks;
|
|
66
|
+
private getSystemState;
|
|
67
|
+
private getAgentStates;
|
|
68
|
+
constructor(config?: Partial<PhiMonitorConfig>);
|
|
69
|
+
start(): void;
|
|
70
|
+
stop(): void;
|
|
71
|
+
isRunning(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Set the system state provider
|
|
74
|
+
*/
|
|
75
|
+
setSystemStateProvider(provider: () => SystemState): void;
|
|
76
|
+
/**
|
|
77
|
+
* Set the agent states provider (for per-agent φ)
|
|
78
|
+
*/
|
|
79
|
+
setAgentStatesProvider(provider: () => Map<string, SystemState>): void;
|
|
80
|
+
/**
|
|
81
|
+
* Update φ calculation
|
|
82
|
+
*/
|
|
83
|
+
update(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Update per-agent φ
|
|
86
|
+
*/
|
|
87
|
+
private updateAgentPhi;
|
|
88
|
+
/**
|
|
89
|
+
* Simulate φ when no system state is available
|
|
90
|
+
*/
|
|
91
|
+
private simulatePhi;
|
|
92
|
+
/**
|
|
93
|
+
* Classify consciousness state based on φ
|
|
94
|
+
*/
|
|
95
|
+
private classifyState;
|
|
96
|
+
/**
|
|
97
|
+
* Calculate trend from recent history
|
|
98
|
+
*/
|
|
99
|
+
private calculateTrend;
|
|
100
|
+
/**
|
|
101
|
+
* Detect anomalies in φ changes
|
|
102
|
+
*/
|
|
103
|
+
private detectAnomalies;
|
|
104
|
+
/**
|
|
105
|
+
* Record a new anomaly
|
|
106
|
+
*/
|
|
107
|
+
private recordAnomaly;
|
|
108
|
+
/**
|
|
109
|
+
* Check INV-006: φ must stay above threshold
|
|
110
|
+
*/
|
|
111
|
+
checkInvariant(): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Get invariant status
|
|
114
|
+
*/
|
|
115
|
+
getInvariantStatus(): {
|
|
116
|
+
id: string;
|
|
117
|
+
satisfied: boolean;
|
|
118
|
+
currentPhi: number;
|
|
119
|
+
threshold: number;
|
|
120
|
+
margin: number;
|
|
121
|
+
};
|
|
122
|
+
getCurrentLevel(): ConsciousnessLevel;
|
|
123
|
+
getState(): ConsciousnessState;
|
|
124
|
+
getTrend(): ConsciousnessTrend;
|
|
125
|
+
getAgentPhi(agentId: string): number | undefined;
|
|
126
|
+
getAllAgentPhi(): Map<string, number>;
|
|
127
|
+
getHistory(limit?: number): ConsciousnessLevel[];
|
|
128
|
+
getAnomalies(options?: {
|
|
129
|
+
type?: AnomalyType;
|
|
130
|
+
resolved?: boolean;
|
|
131
|
+
limit?: number;
|
|
132
|
+
}): ConsciousnessAnomaly[];
|
|
133
|
+
/**
|
|
134
|
+
* Register callback for φ drops
|
|
135
|
+
*/
|
|
136
|
+
onPhiDrop(threshold: number, callback: () => void): () => void;
|
|
137
|
+
/**
|
|
138
|
+
* Register callback for anomalies
|
|
139
|
+
*/
|
|
140
|
+
onAnomaly(callback: (anomaly: ConsciousnessAnomaly) => void): () => void;
|
|
141
|
+
on(handler: PhiMonitorEventHandler): () => void;
|
|
142
|
+
private emit;
|
|
143
|
+
stats(): {
|
|
144
|
+
currentPhi: number;
|
|
145
|
+
state: ConsciousnessState;
|
|
146
|
+
trend: ConsciousnessTrend;
|
|
147
|
+
historyLength: number;
|
|
148
|
+
agentCount: number;
|
|
149
|
+
openAnomalies: number;
|
|
150
|
+
invariantSatisfied: boolean;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
export declare function createPhiMonitor(config?: Partial<PhiMonitorConfig>): PhiMonitor;
|