[**@s4ai/core Documentation v0.3.23**](../../../README.md)

***

[@s4ai/core Documentation](../../../modules.md) / [autonomous/self-modification-engine](../README.md) / default

# Class: default

Defined in: autonomous/self-modification-engine.js:23

## Extends

- [`Revenue`](../../../@s4ai/core/business/variables/Revenue.md)

## Constructors

### Constructor

> **new default**(`config?`): `SelfModificationEngine`

Defined in: autonomous/self-modification-engine.js:24

#### Parameters

##### config?

#### Returns

`SelfModificationEngine`

#### Overrides

`EventEmitter.constructor`

## Properties

### config

> **config**: `object`

Defined in: autonomous/self-modification-engine.js:27

#### allowedPaths

> **allowedPaths**: `any`

#### autoCommit

> **autoCommit**: `boolean` = `true`

#### autoRollback

> **autoRollback**: `boolean`

#### backupDir

> **backupDir**: `any`

#### forbiddenPaths

> **forbiddenPaths**: `any`

#### healthCheckAfterModification

> **healthCheckAfterModification**: `boolean`

#### maxBackups

> **maxBackups**: `any`

#### safeMode

> **safeMode**: `boolean` = `false`

***

### healthBeforeModification

> **healthBeforeModification**: \{ `checks`: \{ `importsResolved`: `boolean`; `serverResponsive`: `boolean`; `syntaxValid`: `boolean`; \}; `error?`: `undefined`; `healthy`: `boolean`; \} \| \{ `checks?`: `undefined`; `error`: `any`; `healthy`: `boolean`; \} \| `null`

Defined in: autonomous/self-modification-engine.js:51

***

### modifications

> **modifications**: `any`[]

Defined in: autonomous/self-modification-engine.js:49

***

### moduleCache

> **moduleCache**: `Map`\<`any`, `any`\>

Defined in: autonomous/self-modification-engine.js:50

## Methods

### cleanOldBackups()

> **cleanOldBackups**(): `Promise`\<`void`\>

Defined in: autonomous/self-modification-engine.js:105

Clean old backups to prevent disk bloat

#### Returns

`Promise`\<`void`\>

***

### commitToGit()

> **commitToGit**(`message`, `files`): `Promise`\<\{ `files`: `any`; `hash`: `any`; `message`: `any`; \} \| `null`\>

Defined in: autonomous/self-modification-engine.js:277

Commit modifications to git using GitHub API (internal)

#### Parameters

##### message

`any`

##### files

`any`

#### Returns

`Promise`\<\{ `files`: `any`; `hash`: `any`; `message`: `any`; \} \| `null`\>

***

### createBackup()

> **createBackup**(`filePath`): `Promise`\<`any`\>

Defined in: autonomous/self-modification-engine.js:82

Create backup of file before modification

#### Parameters

##### filePath

`any`

#### Returns

`Promise`\<`any`\>

***

### getHistory()

> **getHistory**(): `any`[]

Defined in: autonomous/self-modification-engine.js:372

Get modification history

#### Returns

`any`[]

***

### getMetrics()

> **getMetrics**(): `object`

Defined in: autonomous/self-modification-engine.js:379

Get metrics

#### Returns

`object`

##### backupsCreated

> **backupsCreated**: `number`

##### failed

> **failed**: `number`

##### modulesReloaded

> **modulesReloaded**: `number`

##### successful

> **successful**: `number`

##### successRate

> **successRate**: `number`

##### totalModifications

> **totalModifications**: `number` = `total`

***

### hotReloadModule()

> **hotReloadModule**(`modulePath`): `Promise`\<`any`\>

Defined in: autonomous/self-modification-engine.js:186

Hot-reload a module (invalidate cache and re-import)

#### Parameters

##### modulePath

`any`

#### Returns

`Promise`\<`any`\>

***

### isSafeToModify()

> **isSafeToModify**(`filePath`): `boolean`

Defined in: autonomous/self-modification-engine.js:57

Check if a file path is safe to modify

#### Parameters

##### filePath

`any`

#### Returns

`boolean`

***

### modifyFile()

> **modifyFile**(`filePath`, `modifications`): `Promise`\<\{ `backupPath`: `any`; `filePath`: `any`; `newContent`: `any`; `originalContent`: `any`; `status`: `string`; `timestamp`: `number`; \}\>

Defined in: autonomous/self-modification-engine.js:133

Modify a source file

#### Parameters

##### filePath

`any`

##### modifications

`any`

#### Returns

`Promise`\<\{ `backupPath`: `any`; `filePath`: `any`; `newContent`: `any`; `originalContent`: `any`; `status`: `string`; `timestamp`: `number`; \}\>

***

### performHealthCheck()

> **performHealthCheck**(): `Promise`\<\{ `checks`: \{ `importsResolved`: `boolean`; `serverResponsive`: `boolean`; `syntaxValid`: `boolean`; \}; `error?`: `undefined`; `healthy`: `boolean`; \} \| \{ `checks?`: `undefined`; `error`: `any`; `healthy`: `boolean`; \}\>

Defined in: autonomous/self-modification-engine.js:237

Perform health check after modification

#### Returns

`Promise`\<\{ `checks`: \{ `importsResolved`: `boolean`; `serverResponsive`: `boolean`; `syntaxValid`: `boolean`; \}; `error?`: `undefined`; `healthy`: `boolean`; \} \| \{ `checks?`: `undefined`; `error`: `any`; `healthy`: `boolean`; \}\>

***

### rollbackModification()

> **rollbackModification**(`filePath`, `backupPath`): `Promise`\<`void`\>

Defined in: autonomous/self-modification-engine.js:219

Rollback a modification using backup

#### Parameters

##### filePath

`any`

##### backupPath

`any`

#### Returns

`Promise`\<`void`\>

***

### selfModify()

> **selfModify**(`filePath`, `modifications`, `options?`): `Promise`\<\{ `backupPath`: `any`; `filePath`: `any`; `newContent`: `any`; `originalContent`: `any`; `status`: `string`; `timestamp`: `number`; \}\>

Defined in: autonomous/self-modification-engine.js:317

High-level self-modification workflow
1. Backup
2. Modify
3. Hot-reload
4. Health check
5. Commit (if healthy)
6. Rollback (if unhealthy)

#### Parameters

##### filePath

`any`

##### modifications

`any`

##### options?

#### Returns

`Promise`\<\{ `backupPath`: `any`; `filePath`: `any`; `newContent`: `any`; `originalContent`: `any`; `status`: `string`; `timestamp`: `number`; \}\>
