Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/browser/generated.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Browser Structure Registry - Auto-generated
*
* Contains 11 daemons and 222 commands and 2 adapters and 28 widgets.
* Contains 11 daemons and 224 commands and 2 adapters and 28 widgets.
* Generated by scripts/generate-structure.ts - DO NOT EDIT MANUALLY
*/

Expand Down Expand Up @@ -127,6 +127,7 @@ import { FileSaveBrowserCommand } from './../commands/file/save/browser/FileSave
import { GenomeAcademyCompetitionBrowserCommand } from './../commands/genome/academy-competition/browser/GenomeAcademyCompetitionBrowserCommand';
import { GenomeAcademySessionBrowserCommand } from './../commands/genome/academy-session/browser/GenomeAcademySessionBrowserCommand';
import { GenomeBatchMicroTuneBrowserCommand } from './../commands/genome/batch-micro-tune/browser/GenomeBatchMicroTuneBrowserCommand';
import { GenomeConvertBrowserCommand } from './../commands/genome/convert/browser/GenomeConvertBrowserCommand';
import { GenomeDatasetPrepareBrowserCommand } from './../commands/genome/dataset-prepare/browser/GenomeDatasetPrepareBrowserCommand';
import { GenomeDatasetSynthesizeBrowserCommand } from './../commands/genome/dataset-synthesize/browser/GenomeDatasetSynthesizeBrowserCommand';
import { GenomeDemoRunBrowserCommand } from './../commands/genome/demo-run/browser/GenomeDemoRunBrowserCommand';
Expand Down Expand Up @@ -216,6 +217,7 @@ import { StateCreateBrowserCommand } from './../commands/state/create/browser/St
import { StateGetBrowserCommand } from './../commands/state/get/browser/StateGetBrowserCommand';
import { StateUpdateBrowserCommand } from './../commands/state/update/browser/StateUpdateBrowserCommand';
import { DaemonsBrowserCommand } from './../commands/system/daemons/browser/DaemonsBrowserCommand';
import { SystemResourcesBrowserCommand } from './../commands/system/resources/browser/SystemResourcesBrowserCommand';
import { ThemeGetBrowserCommand } from './../commands/theme/get/browser/ThemeGetBrowserCommand';
import { ThemeListBrowserCommand } from './../commands/theme/list/browser/ThemeListBrowserCommand';
import { ThemeSetBrowserCommand } from './../commands/theme/set/browser/ThemeSetBrowserCommand';
Expand Down Expand Up @@ -884,6 +886,11 @@ export const BROWSER_COMMANDS: CommandEntry[] = [
className: 'GenomeBatchMicroTuneBrowserCommand',
commandClass: GenomeBatchMicroTuneBrowserCommand
},
{
name: 'genome/convert',
className: 'GenomeConvertBrowserCommand',
commandClass: GenomeConvertBrowserCommand
},
{
name: 'genome/dataset-prepare',
className: 'GenomeDatasetPrepareBrowserCommand',
Expand Down Expand Up @@ -1329,6 +1336,11 @@ export const BROWSER_COMMANDS: CommandEntry[] = [
className: 'DaemonsBrowserCommand',
commandClass: DaemonsBrowserCommand
},
{
name: 'system/resources',
className: 'SystemResourcesBrowserCommand',
commandClass: SystemResourcesBrowserCommand
},
{
name: 'theme/get',
className: 'ThemeGetBrowserCommand',
Expand Down
20 changes: 20 additions & 0 deletions src/commands/genome/convert/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Development files
.eslintrc*
tsconfig*.json
vitest.config.ts

# Build artifacts
*.js.map
*.d.ts.map

# IDE
.vscode/
.idea/

# Logs
*.log
npm-debug.log*

# OS files
.DS_Store
Thumbs.db
172 changes: 172 additions & 0 deletions src/commands/genome/convert/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Genome Convert Command

Convert LoRA adapters between formats. Supports: merge LoRA into full-precision model, merge + quantize to GGUF, quantize base model to GGUF, and validate converted models. Uses convert-adapter.py via Rust sentinel for process isolation.

## Table of Contents

- [Usage](#usage)
- [CLI Usage](#cli-usage)
- [Tool Usage](#tool-usage)
- [Parameters](#parameters)
- [Result](#result)
- [Examples](#examples)
- [Testing](#testing)
- [Unit Tests](#unit-tests)
- [Integration Tests](#integration-tests)
- [Getting Help](#getting-help)
- [Access Level](#access-level)
- [Implementation Notes](#implementation-notes)

## Usage

### CLI Usage

From the command line using the jtag CLI:

```bash
./jtag genome/convert --operation=<value>
```

### Tool Usage

From Persona tools or programmatic access using `Commands.execute()`:

```typescript
import { Commands } from '@system/core/shared/Commands';

const result = await Commands.execute('genome/convert', {
// your parameters here
});
```

## Parameters

- **operation** (required): `string` - Conversion operation: 'merge-full' (LoRA → merged FP16), 'merge-and-quantize' (LoRA → merged GGUF), 'quantize-base' (HF → GGUF), 'validate' (sanity check)
- **adapterPath** (optional): `string` - Path to LoRA adapter directory (required for merge-full and merge-and-quantize)
- **baseModel** (optional): `string` - Base model name or HuggingFace ID (required for merge and quantize operations)
- **bits** (optional): `number` - Quantization bits: 4 or 8 (default: 4, only for quantize operations)
- **outputPath** (optional): `string` - Output directory. Default: sibling directory with format suffix
- **validate** (optional): `boolean` - Run validation inference after conversion (default: true)

## Result

Returns `GenomeConvertResult` with:

Returns CommandResult with:
- **outputPath**: `string` - Path to converted model/adapter
- **format**: `string` - Output format: 'safetensors-fp16', 'gguf-q4_0', 'gguf-q8_0'
- **sizeMB**: `number` - Output size in megabytes
- **durationSeconds**: `number` - Conversion duration in seconds
- **compressionRatio**: `number` - Original size / converted size (for quantize operations)
- **validation**: `object` - Validation result if --validate was run

## Examples

### Merge LoRA into full-precision model

```bash
./jtag genome/convert --operation=merge-full --adapterPath=.continuum/genome/adapters/helper-coding-123 --baseModel=unsloth/Llama-3.2-3B-Instruct
```

**Expected result:**
{ outputPath: '.continuum/genome/converted/...', format: 'safetensors-fp16', sizeMB: 6144 }

### Merge LoRA and quantize to 4-bit GGUF

```bash
./jtag genome/convert --operation=merge-and-quantize --adapterPath=.continuum/genome/adapters/helper-coding-123 --baseModel=unsloth/Llama-3.2-3B-Instruct --bits=4
```

**Expected result:**
{ outputPath: '.continuum/genome/converted/...', format: 'gguf-q4_0', sizeMB: 1800, compressionRatio: 3.4 }

## Getting Help

### Using the Help Tool

Get detailed usage information for this command:

**CLI:**
```bash
./jtag help genome/convert
```

**Tool:**
```typescript
// Use your help tool with command name 'genome/convert'
```

### Using the README Tool

Access this README programmatically:

**CLI:**
```bash
./jtag readme genome/convert
```

**Tool:**
```typescript
// Use your readme tool with command name 'genome/convert'
```

## Testing

### Unit Tests

Test command logic in isolation using mock dependencies:

```bash
# Run unit tests (no server required)
npx tsx commands/Genome Convert/test/unit/GenomeConvertCommand.test.ts
```

**What's tested:**
- Command structure and parameter validation
- Mock command execution patterns
- Required parameter validation (throws ValidationError)
- Optional parameter handling (sensible defaults)
- Performance requirements
- Assertion utility helpers

**TDD Workflow:**
1. Write/modify unit test first (test-driven development)
2. Run test, see it fail
3. Implement feature
4. Run test, see it pass
5. Refactor if needed

### Integration Tests

Test command with real client connections and system integration:

```bash
# Prerequisites: Server must be running
npm start # Wait 90+ seconds for deployment

# Run integration tests
npx tsx commands/Genome Convert/test/integration/GenomeConvertIntegration.test.ts
```

**What's tested:**
- Client connection to live system
- Real command execution via WebSocket
- ValidationError handling for missing params
- Optional parameter defaults
- Performance under load
- Various parameter combinations

**Best Practice:**
Run unit tests frequently during development (fast feedback). Run integration tests before committing (verify system integration).

## Access Level

**admin** - Unknown access level

## Implementation Notes

- **Shared Logic**: Core business logic in `shared/GenomeConvertTypes.ts`
- **Browser**: Browser-specific implementation in `browser/GenomeConvertBrowserCommand.ts`
- **Server**: Server-specific implementation in `server/GenomeConvertServerCommand.ts`
- **Unit Tests**: Isolated testing in `test/unit/GenomeConvertCommand.test.ts`
- **Integration Tests**: System testing in `test/integration/GenomeConvertIntegration.test.ts`
21 changes: 21 additions & 0 deletions src/commands/genome/convert/browser/GenomeConvertBrowserCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Genome Convert Command - Browser Implementation
*
* Convert LoRA adapters between formats. Supports: merge LoRA into full-precision model, merge + quantize to GGUF, quantize base model to GGUF, and validate converted models. Uses convert-adapter.py via Rust sentinel for process isolation.
*/

import { CommandBase, type ICommandDaemon } from '@daemons/command-daemon/shared/CommandBase';
import type { JTAGContext } from '@system/core/types/JTAGTypes';
import type { GenomeConvertParams, GenomeConvertResult } from '../shared/GenomeConvertTypes';

export class GenomeConvertBrowserCommand extends CommandBase<GenomeConvertParams, GenomeConvertResult> {

constructor(context: JTAGContext, subpath: string, commander: ICommandDaemon) {
super('genome/convert', context, subpath, commander);
}

async execute(params: GenomeConvertParams): Promise<GenomeConvertResult> {
console.log('🌐 BROWSER: Delegating Genome Convert to server');
return await this.remoteExecute(params);
}
}
35 changes: 35 additions & 0 deletions src/commands/genome/convert/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@jtag-commands/genome/convert",
"version": "1.0.0",
"description": "Convert LoRA adapters between formats. Supports: merge LoRA into full-precision model, merge + quantize to GGUF, quantize base model to GGUF, and validate converted models. Uses convert-adapter.py via Rust sentinel for process isolation.",
"main": "server/GenomeConvertServerCommand.ts",
"types": "shared/GenomeConvertTypes.ts",
"scripts": {
"test": "npm run test:unit && npm run test:integration",
"test:unit": "npx vitest run test/unit/*.test.ts",
"test:integration": "npx tsx test/integration/GenomeConvertIntegration.test.ts",
"lint": "npx eslint **/*.ts",
"typecheck": "npx tsc --noEmit"
},
"peerDependencies": {
"@jtag/core": "*"
},
"files": [
"shared/**/*.ts",
"browser/**/*.ts",
"server/**/*.ts",
"test/**/*.ts",
"README.md"
],
"keywords": [
"jtag",
"command",
"genome/convert"
],
"license": "MIT",
"author": "",
"repository": {
"type": "git",
"url": ""
}
}
Loading
Loading