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,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis v7.4.5 - Hooks System
|
|
3
|
+
*
|
|
4
|
+
* Execute custom shell commands in response to Genesis events.
|
|
5
|
+
* Similar to git hooks or Claude Code hooks.
|
|
6
|
+
*
|
|
7
|
+
* Configuration (in ~/.genesis/hooks.json or .genesis-hooks.json):
|
|
8
|
+
* ```json
|
|
9
|
+
* {
|
|
10
|
+
* "hooks": {
|
|
11
|
+
* "pre-message": "echo 'Processing: $GENESIS_MESSAGE'",
|
|
12
|
+
* "post-message": "./scripts/log-response.sh",
|
|
13
|
+
* "pre-tool": "echo 'Calling tool: $GENESIS_TOOL_NAME'",
|
|
14
|
+
* "post-tool": "./scripts/audit-tool.sh",
|
|
15
|
+
* "session-start": "notify-send 'Genesis session started'",
|
|
16
|
+
* "session-end": "./scripts/summarize-session.sh"
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Environment variables passed to hooks:
|
|
22
|
+
* - GENESIS_EVENT: Event name
|
|
23
|
+
* - GENESIS_MESSAGE: User message (for message events)
|
|
24
|
+
* - GENESIS_RESPONSE: AI response (for post-message)
|
|
25
|
+
* - GENESIS_TOOL_NAME: Tool name (for tool events)
|
|
26
|
+
* - GENESIS_TOOL_RESULT: Tool result (for post-tool)
|
|
27
|
+
* - GENESIS_SESSION_ID: Current session ID
|
|
28
|
+
* - GENESIS_WORKING_DIR: Working directory
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Available hook events
|
|
32
|
+
*/
|
|
33
|
+
export type HookEvent = 'session-start' | 'session-end' | 'pre-message' | 'post-message' | 'pre-tool' | 'post-tool' | 'pre-subagent' | 'post-subagent' | 'error' | 'prompt-submit';
|
|
34
|
+
/**
|
|
35
|
+
* Hook configuration
|
|
36
|
+
*/
|
|
37
|
+
export interface HookConfig {
|
|
38
|
+
command: string;
|
|
39
|
+
blocking?: boolean;
|
|
40
|
+
timeout?: number;
|
|
41
|
+
silent?: boolean;
|
|
42
|
+
env?: Record<string, string>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Full hooks configuration file
|
|
46
|
+
*/
|
|
47
|
+
export interface HooksConfig {
|
|
48
|
+
hooks: Partial<Record<HookEvent, string | HookConfig>>;
|
|
49
|
+
defaults?: {
|
|
50
|
+
timeout?: number;
|
|
51
|
+
silent?: boolean;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Context passed to hook execution
|
|
56
|
+
*/
|
|
57
|
+
export interface HookContext {
|
|
58
|
+
event: HookEvent;
|
|
59
|
+
message?: string;
|
|
60
|
+
response?: string;
|
|
61
|
+
toolName?: string;
|
|
62
|
+
toolResult?: string;
|
|
63
|
+
subagentType?: string;
|
|
64
|
+
subagentResult?: string;
|
|
65
|
+
sessionId?: string;
|
|
66
|
+
workingDir?: string;
|
|
67
|
+
error?: string;
|
|
68
|
+
[key: string]: string | undefined;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Result of hook execution
|
|
72
|
+
*/
|
|
73
|
+
export interface HookResult {
|
|
74
|
+
event: HookEvent;
|
|
75
|
+
success: boolean;
|
|
76
|
+
blocked: boolean;
|
|
77
|
+
output?: string;
|
|
78
|
+
error?: string;
|
|
79
|
+
duration: number;
|
|
80
|
+
}
|
|
81
|
+
export declare class HooksManager {
|
|
82
|
+
private config;
|
|
83
|
+
private configPath;
|
|
84
|
+
private enabled;
|
|
85
|
+
constructor();
|
|
86
|
+
/**
|
|
87
|
+
* Load hooks configuration from file
|
|
88
|
+
* Priority: .genesis-hooks.json (local) > ~/.genesis/hooks.json (global)
|
|
89
|
+
*/
|
|
90
|
+
private loadConfig;
|
|
91
|
+
/**
|
|
92
|
+
* Reload configuration
|
|
93
|
+
*/
|
|
94
|
+
reload(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Enable/disable hooks
|
|
97
|
+
*/
|
|
98
|
+
setEnabled(enabled: boolean): void;
|
|
99
|
+
/**
|
|
100
|
+
* Check if hooks are configured
|
|
101
|
+
*/
|
|
102
|
+
hasHooks(): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Get configured hooks
|
|
105
|
+
*/
|
|
106
|
+
getConfiguredHooks(): HookEvent[];
|
|
107
|
+
/**
|
|
108
|
+
* Get config path
|
|
109
|
+
*/
|
|
110
|
+
getConfigPath(): string | null;
|
|
111
|
+
/**
|
|
112
|
+
* Execute hook for an event
|
|
113
|
+
* @param event - The event that triggered the hook
|
|
114
|
+
* @param context - Context data to pass to the hook
|
|
115
|
+
* @returns HookResult or null if no hook configured
|
|
116
|
+
*/
|
|
117
|
+
execute(event: HookEvent, context: HookContext): Promise<HookResult | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Execute multiple hooks for an event (if configured as array)
|
|
120
|
+
* Currently just executes single hook, but structure allows expansion
|
|
121
|
+
*/
|
|
122
|
+
executeAll(event: HookEvent, context: HookContext): Promise<HookResult[]>;
|
|
123
|
+
}
|
|
124
|
+
export declare function getHooksManager(): HooksManager;
|
|
125
|
+
/**
|
|
126
|
+
* Create a sample hooks configuration file
|
|
127
|
+
*/
|
|
128
|
+
export declare function createSampleHooksConfig(filePath?: string): void;
|
|
129
|
+
/**
|
|
130
|
+
* Validate hooks configuration
|
|
131
|
+
*/
|
|
132
|
+
export declare function validateHooksConfig(config: unknown): {
|
|
133
|
+
valid: boolean;
|
|
134
|
+
errors: string[];
|
|
135
|
+
};
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Genesis v7.4.5 - Hooks System
|
|
4
|
+
*
|
|
5
|
+
* Execute custom shell commands in response to Genesis events.
|
|
6
|
+
* Similar to git hooks or Claude Code hooks.
|
|
7
|
+
*
|
|
8
|
+
* Configuration (in ~/.genesis/hooks.json or .genesis-hooks.json):
|
|
9
|
+
* ```json
|
|
10
|
+
* {
|
|
11
|
+
* "hooks": {
|
|
12
|
+
* "pre-message": "echo 'Processing: $GENESIS_MESSAGE'",
|
|
13
|
+
* "post-message": "./scripts/log-response.sh",
|
|
14
|
+
* "pre-tool": "echo 'Calling tool: $GENESIS_TOOL_NAME'",
|
|
15
|
+
* "post-tool": "./scripts/audit-tool.sh",
|
|
16
|
+
* "session-start": "notify-send 'Genesis session started'",
|
|
17
|
+
* "session-end": "./scripts/summarize-session.sh"
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Environment variables passed to hooks:
|
|
23
|
+
* - GENESIS_EVENT: Event name
|
|
24
|
+
* - GENESIS_MESSAGE: User message (for message events)
|
|
25
|
+
* - GENESIS_RESPONSE: AI response (for post-message)
|
|
26
|
+
* - GENESIS_TOOL_NAME: Tool name (for tool events)
|
|
27
|
+
* - GENESIS_TOOL_RESULT: Tool result (for post-tool)
|
|
28
|
+
* - GENESIS_SESSION_ID: Current session ID
|
|
29
|
+
* - GENESIS_WORKING_DIR: Working directory
|
|
30
|
+
*/
|
|
31
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
32
|
+
if (k2 === undefined) k2 = k;
|
|
33
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
34
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
35
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(o, k2, desc);
|
|
38
|
+
}) : (function(o, m, k, k2) {
|
|
39
|
+
if (k2 === undefined) k2 = k;
|
|
40
|
+
o[k2] = m[k];
|
|
41
|
+
}));
|
|
42
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
43
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
44
|
+
}) : function(o, v) {
|
|
45
|
+
o["default"] = v;
|
|
46
|
+
});
|
|
47
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
48
|
+
var ownKeys = function(o) {
|
|
49
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
50
|
+
var ar = [];
|
|
51
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
return ownKeys(o);
|
|
55
|
+
};
|
|
56
|
+
return function (mod) {
|
|
57
|
+
if (mod && mod.__esModule) return mod;
|
|
58
|
+
var result = {};
|
|
59
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
60
|
+
__setModuleDefault(result, mod);
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.HooksManager = void 0;
|
|
66
|
+
exports.getHooksManager = getHooksManager;
|
|
67
|
+
exports.createSampleHooksConfig = createSampleHooksConfig;
|
|
68
|
+
exports.validateHooksConfig = validateHooksConfig;
|
|
69
|
+
const child_process_1 = require("child_process");
|
|
70
|
+
const fs = __importStar(require("fs"));
|
|
71
|
+
const path = __importStar(require("path"));
|
|
72
|
+
const os_1 = require("os");
|
|
73
|
+
// ============================================================================
|
|
74
|
+
// Hooks Manager
|
|
75
|
+
// ============================================================================
|
|
76
|
+
class HooksManager {
|
|
77
|
+
config = null;
|
|
78
|
+
configPath = null;
|
|
79
|
+
enabled = true;
|
|
80
|
+
constructor() {
|
|
81
|
+
this.loadConfig();
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Load hooks configuration from file
|
|
85
|
+
* Priority: .genesis-hooks.json (local) > ~/.genesis/hooks.json (global)
|
|
86
|
+
*/
|
|
87
|
+
loadConfig() {
|
|
88
|
+
const localPath = path.join(process.cwd(), '.genesis-hooks.json');
|
|
89
|
+
const globalPath = path.join((0, os_1.homedir)(), '.genesis', 'hooks.json');
|
|
90
|
+
// Try local first
|
|
91
|
+
if (fs.existsSync(localPath)) {
|
|
92
|
+
try {
|
|
93
|
+
const content = fs.readFileSync(localPath, 'utf-8');
|
|
94
|
+
this.config = JSON.parse(content);
|
|
95
|
+
this.configPath = localPath;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
console.warn(`[Hooks] Error loading ${localPath}: ${err}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Try global
|
|
103
|
+
if (fs.existsSync(globalPath)) {
|
|
104
|
+
try {
|
|
105
|
+
const content = fs.readFileSync(globalPath, 'utf-8');
|
|
106
|
+
this.config = JSON.parse(content);
|
|
107
|
+
this.configPath = globalPath;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
console.warn(`[Hooks] Error loading ${globalPath}: ${err}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// No config found - that's OK
|
|
115
|
+
this.config = null;
|
|
116
|
+
this.configPath = null;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Reload configuration
|
|
120
|
+
*/
|
|
121
|
+
reload() {
|
|
122
|
+
this.loadConfig();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Enable/disable hooks
|
|
126
|
+
*/
|
|
127
|
+
setEnabled(enabled) {
|
|
128
|
+
this.enabled = enabled;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check if hooks are configured
|
|
132
|
+
*/
|
|
133
|
+
hasHooks() {
|
|
134
|
+
return this.config !== null && Object.keys(this.config.hooks || {}).length > 0;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Get configured hooks
|
|
138
|
+
*/
|
|
139
|
+
getConfiguredHooks() {
|
|
140
|
+
if (!this.config?.hooks)
|
|
141
|
+
return [];
|
|
142
|
+
return Object.keys(this.config.hooks);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get config path
|
|
146
|
+
*/
|
|
147
|
+
getConfigPath() {
|
|
148
|
+
return this.configPath;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Execute hook for an event
|
|
152
|
+
* @param event - The event that triggered the hook
|
|
153
|
+
* @param context - Context data to pass to the hook
|
|
154
|
+
* @returns HookResult or null if no hook configured
|
|
155
|
+
*/
|
|
156
|
+
async execute(event, context) {
|
|
157
|
+
if (!this.enabled || !this.config?.hooks)
|
|
158
|
+
return null;
|
|
159
|
+
const hookDef = this.config.hooks[event];
|
|
160
|
+
if (!hookDef)
|
|
161
|
+
return null;
|
|
162
|
+
const startTime = Date.now();
|
|
163
|
+
// Normalize hook definition
|
|
164
|
+
const hook = typeof hookDef === 'string'
|
|
165
|
+
? { command: hookDef }
|
|
166
|
+
: hookDef;
|
|
167
|
+
// Determine if blocking
|
|
168
|
+
const isBlocking = hook.blocking ?? event.startsWith('pre-');
|
|
169
|
+
const timeout = hook.timeout ?? this.config.defaults?.timeout ?? 30000;
|
|
170
|
+
const silent = hook.silent ?? this.config.defaults?.silent ?? false;
|
|
171
|
+
// Build environment
|
|
172
|
+
const env = {
|
|
173
|
+
...process.env,
|
|
174
|
+
GENESIS_EVENT: event,
|
|
175
|
+
GENESIS_WORKING_DIR: context.workingDir || process.cwd(),
|
|
176
|
+
...(context.message && { GENESIS_MESSAGE: context.message }),
|
|
177
|
+
...(context.response && { GENESIS_RESPONSE: context.response }),
|
|
178
|
+
...(context.toolName && { GENESIS_TOOL_NAME: context.toolName }),
|
|
179
|
+
...(context.toolResult && { GENESIS_TOOL_RESULT: context.toolResult }),
|
|
180
|
+
...(context.subagentType && { GENESIS_SUBAGENT_TYPE: context.subagentType }),
|
|
181
|
+
...(context.subagentResult && { GENESIS_SUBAGENT_RESULT: context.subagentResult }),
|
|
182
|
+
...(context.sessionId && { GENESIS_SESSION_ID: context.sessionId }),
|
|
183
|
+
...(context.error && { GENESIS_ERROR: context.error }),
|
|
184
|
+
...hook.env,
|
|
185
|
+
};
|
|
186
|
+
try {
|
|
187
|
+
if (isBlocking) {
|
|
188
|
+
// Synchronous execution - waits for completion
|
|
189
|
+
const output = (0, child_process_1.execSync)(hook.command, {
|
|
190
|
+
env,
|
|
191
|
+
timeout,
|
|
192
|
+
stdio: silent ? 'pipe' : 'inherit',
|
|
193
|
+
encoding: 'utf-8',
|
|
194
|
+
shell: '/bin/sh', // Use explicit shell path for type safety
|
|
195
|
+
});
|
|
196
|
+
return {
|
|
197
|
+
event,
|
|
198
|
+
success: true,
|
|
199
|
+
blocked: false,
|
|
200
|
+
output: output || undefined,
|
|
201
|
+
duration: Date.now() - startTime,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
// Asynchronous execution - fire and forget
|
|
206
|
+
const child = (0, child_process_1.spawn)(hook.command, [], {
|
|
207
|
+
env,
|
|
208
|
+
stdio: silent ? 'ignore' : 'inherit',
|
|
209
|
+
shell: '/bin/sh', // Use explicit shell path for type safety
|
|
210
|
+
detached: true,
|
|
211
|
+
});
|
|
212
|
+
child.unref();
|
|
213
|
+
return {
|
|
214
|
+
event,
|
|
215
|
+
success: true,
|
|
216
|
+
blocked: false,
|
|
217
|
+
duration: Date.now() - startTime,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
223
|
+
// Check if hook explicitly blocked (exit code 77 = blocked)
|
|
224
|
+
const blocked = err instanceof Error && 'status' in err && err.status === 77;
|
|
225
|
+
return {
|
|
226
|
+
event,
|
|
227
|
+
success: false,
|
|
228
|
+
blocked,
|
|
229
|
+
error: blocked ? 'Hook blocked the action' : errorMessage,
|
|
230
|
+
duration: Date.now() - startTime,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Execute multiple hooks for an event (if configured as array)
|
|
236
|
+
* Currently just executes single hook, but structure allows expansion
|
|
237
|
+
*/
|
|
238
|
+
async executeAll(event, context) {
|
|
239
|
+
const result = await this.execute(event, context);
|
|
240
|
+
return result ? [result] : [];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.HooksManager = HooksManager;
|
|
244
|
+
// ============================================================================
|
|
245
|
+
// Singleton Instance
|
|
246
|
+
// ============================================================================
|
|
247
|
+
let _hooksManager = null;
|
|
248
|
+
function getHooksManager() {
|
|
249
|
+
if (!_hooksManager) {
|
|
250
|
+
_hooksManager = new HooksManager();
|
|
251
|
+
}
|
|
252
|
+
return _hooksManager;
|
|
253
|
+
}
|
|
254
|
+
// ============================================================================
|
|
255
|
+
// Helper Functions
|
|
256
|
+
// ============================================================================
|
|
257
|
+
/**
|
|
258
|
+
* Create a sample hooks configuration file
|
|
259
|
+
*/
|
|
260
|
+
function createSampleHooksConfig(filePath) {
|
|
261
|
+
const targetPath = filePath || path.join(process.cwd(), '.genesis-hooks.json');
|
|
262
|
+
const sampleConfig = {
|
|
263
|
+
hooks: {
|
|
264
|
+
'session-start': 'echo "Genesis session started at $(date)"',
|
|
265
|
+
'pre-message': {
|
|
266
|
+
command: 'echo "Processing message..."',
|
|
267
|
+
silent: true,
|
|
268
|
+
},
|
|
269
|
+
'post-tool': {
|
|
270
|
+
command: 'echo "Tool $GENESIS_TOOL_NAME executed"',
|
|
271
|
+
blocking: false,
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
defaults: {
|
|
275
|
+
timeout: 30000,
|
|
276
|
+
silent: false,
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
fs.writeFileSync(targetPath, JSON.stringify(sampleConfig, null, 2));
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Validate hooks configuration
|
|
283
|
+
*/
|
|
284
|
+
function validateHooksConfig(config) {
|
|
285
|
+
const errors = [];
|
|
286
|
+
if (!config || typeof config !== 'object') {
|
|
287
|
+
errors.push('Config must be an object');
|
|
288
|
+
return { valid: false, errors };
|
|
289
|
+
}
|
|
290
|
+
const cfg = config;
|
|
291
|
+
if (!cfg.hooks || typeof cfg.hooks !== 'object') {
|
|
292
|
+
errors.push('Config must have a "hooks" object');
|
|
293
|
+
return { valid: false, errors };
|
|
294
|
+
}
|
|
295
|
+
const validEvents = [
|
|
296
|
+
'session-start', 'session-end',
|
|
297
|
+
'pre-message', 'post-message',
|
|
298
|
+
'pre-tool', 'post-tool',
|
|
299
|
+
'pre-subagent', 'post-subagent',
|
|
300
|
+
'error', 'prompt-submit',
|
|
301
|
+
];
|
|
302
|
+
for (const [event, hook] of Object.entries(cfg.hooks)) {
|
|
303
|
+
if (!validEvents.includes(event)) {
|
|
304
|
+
errors.push(`Unknown hook event: ${event}`);
|
|
305
|
+
}
|
|
306
|
+
if (typeof hook !== 'string' && typeof hook !== 'object') {
|
|
307
|
+
errors.push(`Hook for ${event} must be a string or object`);
|
|
308
|
+
}
|
|
309
|
+
if (typeof hook === 'object' && hook !== null) {
|
|
310
|
+
const hookObj = hook;
|
|
311
|
+
if (!hookObj.command || typeof hookObj.command !== 'string') {
|
|
312
|
+
errors.push(`Hook for ${event} must have a "command" string`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return { valid: errors.length === 0, errors };
|
|
317
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Genesis - System Creator CLI
|
|
4
|
+
*
|
|
5
|
+
* Create systems powered by 13 MCP servers:
|
|
6
|
+
*
|
|
7
|
+
* KNOWLEDGE: arxiv, semantic-scholar, context7, wolfram
|
|
8
|
+
* RESEARCH: gemini, brave-search, exa, firecrawl
|
|
9
|
+
* CREATION: openai, github
|
|
10
|
+
* VISUAL: stability-ai
|
|
11
|
+
* STORAGE: memory, filesystem
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* genesis create <name> [options] Create a new system
|
|
15
|
+
* genesis research <topic> Research a topic
|
|
16
|
+
* genesis design <spec-file> Design architecture
|
|
17
|
+
* genesis generate <spec-file> Generate code
|
|
18
|
+
* genesis visualize <spec-file> Create visuals
|
|
19
|
+
* genesis publish <spec-file> Publish to GitHub
|
|
20
|
+
* genesis status Show MCP status
|
|
21
|
+
* genesis help Show help
|
|
22
|
+
*/
|
|
23
|
+
export {};
|