Skip to content

Commit 0048df1

Browse files
author
William Bakst
committed
refactor(cli): extract and unify types in cli (ts/py)
1 parent bc485d3 commit 0048df1

File tree

10 files changed

+189
-87
lines changed

10 files changed

+189
-87
lines changed
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1-
"""Registry client for fetching items from the Mirascope registry."""
1+
"""Registry client and types for the Mirascope registry."""
22

33
from mirascope.cli.registry.client import RegistryClient
4+
from mirascope.cli.registry.schemas import (
5+
MirascopeConfig,
6+
RegistryDependencies,
7+
RegistryFile,
8+
RegistryIndex,
9+
RegistryIndexItem,
10+
RegistryItem,
11+
RegistryVersionConstraint,
12+
)
413

5-
__all__ = ["RegistryClient"]
14+
__all__ = [
15+
"MirascopeConfig",
16+
"RegistryClient",
17+
"RegistryDependencies",
18+
"RegistryFile",
19+
"RegistryIndex",
20+
"RegistryIndexItem",
21+
"RegistryItem",
22+
"RegistryVersionConstraint",
23+
]
Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,68 @@
1-
"""Pydantic schemas for registry items."""
1+
"""Pydantic schemas for registry items and configuration."""
22

33
from __future__ import annotations
44

55
from typing import Any
66

7-
from pydantic import BaseModel
7+
from pydantic import BaseModel, ConfigDict
88

99

1010
class RegistryFile(BaseModel):
11-
"""A file in a registry item."""
11+
"""A file within a registry item."""
1212

1313
path: str
14+
"""Source path within the registry item."""
1415
target: str
16+
"""Target path where the file will be written."""
1517
content: str = ""
18+
"""File content (populated in built registry items)."""
1619
type: str = ""
20+
"""Optional file type annotation."""
1721

1822

1923
class RegistryDependencies(BaseModel):
20-
"""Dependencies for a registry item."""
24+
"""Dependencies required by a registry item."""
2125

2226
pip: list[str] = []
27+
"""Python pip packages."""
2328
npm: list[str] = []
29+
"""npm packages."""
2430

2531

2632
class RegistryVersionConstraint(BaseModel):
27-
"""Version constraints for a registry item."""
33+
"""Version constraints for Mirascope compatibility."""
2834

2935
minVersion: str | None = None
36+
"""Minimum compatible version."""
3037
maxVersion: str | None = None
38+
"""Maximum compatible version."""
3139

3240

3341
class RegistryItem(BaseModel):
34-
"""A registry item."""
42+
"""A registry item (tool, agent, prompt, or integration)."""
3543

3644
name: str
45+
"""Unique item name."""
3746
type: str
47+
"""Item type (e.g., 'registry:tool', 'registry:agent')."""
3848
title: str = ""
49+
"""Human-readable title."""
3950
description: str = ""
51+
"""Description of the item."""
4052
version: str = "1.0.0"
53+
"""Item version."""
4154
language: str = ""
55+
"""Language this item is for (python or typescript)."""
4256
categories: list[str] = []
57+
"""Categories for filtering/searching."""
4358
mirascope: dict[str, RegistryVersionConstraint] = {}
59+
"""Mirascope version constraints by language."""
4460
files: list[RegistryFile] = []
61+
"""Files included in this item."""
4562
dependencies: RegistryDependencies = RegistryDependencies()
63+
"""External dependencies."""
4664
registryDependencies: list[str] = []
65+
"""Other registry items this depends on."""
4766

4867
@classmethod
4968
def from_dict(cls, data: dict[str, Any]) -> RegistryItem:
@@ -52,23 +71,46 @@ def from_dict(cls, data: dict[str, Any]) -> RegistryItem:
5271

5372

5473
class RegistryIndexItem(BaseModel):
55-
"""An item in the registry index."""
74+
"""An item entry in the registry index."""
5675

5776
name: str
77+
"""Item name."""
5878
type: str
79+
"""Item type."""
5980
path: str
81+
"""Path within the registry."""
6082
description: str = ""
83+
"""Optional description."""
6184

6285

6386
class RegistryIndex(BaseModel):
64-
"""The registry index."""
87+
"""The registry index containing all available items."""
6588

6689
name: str
90+
"""Registry name."""
6791
version: str
92+
"""Registry version."""
6893
homepage: str = ""
94+
"""Registry homepage URL."""
6995
items: list[RegistryIndexItem] = []
96+
"""All items in the registry."""
7097

7198
@classmethod
7299
def from_dict(cls, data: dict[str, Any]) -> RegistryIndex:
73100
"""Create a RegistryIndex from a dictionary."""
74101
return cls.model_validate(data)
102+
103+
104+
class MirascopeConfig(BaseModel):
105+
"""Mirascope project configuration (mirascope.json)."""
106+
107+
model_config = ConfigDict(populate_by_name=True, extra="allow")
108+
109+
schema_: str | None = None
110+
"""JSON schema URL."""
111+
language: str = "python"
112+
"""Project language (python or typescript)."""
113+
registry: str = "https://mirascope.com/registry"
114+
"""Registry URL."""
115+
paths: dict[str, str] = {}
116+
"""Path mappings for item types."""

typescript/src/cli/commands/add.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
*/
44

55
import { join } from 'path';
6-
import { RegistryClient } from '../registry/client';
7-
import { loadConfig } from '../utils/config';
8-
import { writeFile } from '../utils/file-ops';
6+
import { RegistryClient } from '@/cli/registry/client';
7+
import type { RegistryItem } from '@/cli/registry/types';
8+
import { loadConfig } from '@/cli/utils/config';
9+
import { writeFile } from '@/cli/utils/file-ops';
910

1011
interface AddOptions {
1112
items: string[];
@@ -14,22 +15,6 @@ interface AddOptions {
1415
registryUrl: string;
1516
}
1617

17-
interface RegistryFile {
18-
path: string;
19-
target: string;
20-
content: string;
21-
}
22-
23-
interface RegistryItem {
24-
name: string;
25-
type: string;
26-
files: RegistryFile[];
27-
dependencies: {
28-
pip: string[];
29-
npm: string[];
30-
};
31-
}
32-
3318
async function loadLocalItem(itemPath: string): Promise<RegistryItem | null> {
3419
try {
3520
// eslint-disable-next-line no-undef

typescript/src/cli/commands/init.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,7 @@
33
*/
44

55
import { join } from 'path';
6-
7-
interface MirascopeConfig {
8-
$schema: string;
9-
language: string;
10-
registry: string;
11-
paths: {
12-
tools: string;
13-
agents: string;
14-
prompts: string;
15-
integrations: string;
16-
};
17-
}
6+
import type { MirascopeConfig } from '@/cli/registry/types';
187

198
export async function runInit(): Promise<number> {
209
const configPath = join(process.cwd(), 'mirascope.json');

typescript/src/cli/commands/list.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,14 @@
22
* List command - List available registry items.
33
*/
44

5-
import { RegistryClient } from '../registry/client';
5+
import { RegistryClient } from '@/cli/registry/client';
6+
import type { RegistryIndex, RegistryIndexItem } from '@/cli/registry/types';
67

78
interface ListOptions {
89
itemType?: string;
910
registryUrl: string;
1011
}
1112

12-
interface RegistryIndexItem {
13-
name: string;
14-
type: string;
15-
description?: string;
16-
}
17-
18-
interface RegistryIndex {
19-
items: RegistryIndexItem[];
20-
}
21-
2213
export async function runList(options: ListOptions): Promise<number> {
2314
const { itemType, registryUrl } = options;
2415

typescript/src/cli/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*/
55

66
import { parseArgs } from 'util';
7-
import { runAdd } from './commands/add';
8-
import { runInit } from './commands/init';
9-
import { runList } from './commands/list';
7+
import { runAdd } from '@/cli/commands/add';
8+
import { runInit } from '@/cli/commands/init';
9+
import { runList } from '@/cli/commands/list';
1010

1111
const VERSION = '0.1.0';
1212
const DEFAULT_REGISTRY = 'https://mirascope.com/registry';

typescript/src/cli/registry/client.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,7 @@
22
* HTTP client for the Mirascope registry.
33
*/
44

5-
interface RegistryItem {
6-
name: string;
7-
type: string;
8-
files: Array<{
9-
path: string;
10-
target: string;
11-
content: string;
12-
}>;
13-
dependencies: {
14-
pip: string[];
15-
npm: string[];
16-
};
17-
}
18-
19-
interface RegistryIndex {
20-
name: string;
21-
version: string;
22-
homepage: string;
23-
items: Array<{
24-
name: string;
25-
type: string;
26-
path: string;
27-
description?: string;
28-
}>;
29-
}
5+
import type { RegistryIndex, RegistryItem } from '@/cli/registry/types';
306

317
export class RegistryClient {
328
private baseUrl: string;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Registry module exports.
3+
*/
4+
5+
export { RegistryClient } from '@/cli/registry/client';
6+
export type {
7+
MirascopeConfig,
8+
RegistryDependencies,
9+
RegistryFile,
10+
RegistryIndex,
11+
RegistryIndexItem,
12+
RegistryItem,
13+
RegistryVersionConstraint,
14+
} from '@/cli/registry/types';
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* Shared types for the Mirascope CLI and registry.
3+
*/
4+
5+
/** A file within a registry item. */
6+
export interface RegistryFile {
7+
/** Source path within the registry item. */
8+
path: string;
9+
/** Target path where the file will be written. */
10+
target: string;
11+
/** File content (populated in built registry items). */
12+
content: string;
13+
/** Optional file type annotation. */
14+
type?: string;
15+
}
16+
17+
/** Dependencies required by a registry item. */
18+
export interface RegistryDependencies {
19+
/** Python pip packages. */
20+
pip: string[];
21+
/** npm packages. */
22+
npm: string[];
23+
}
24+
25+
/** Version constraints for Mirascope compatibility. */
26+
export interface RegistryVersionConstraint {
27+
/** Minimum compatible version. */
28+
minVersion?: string;
29+
/** Maximum compatible version. */
30+
maxVersion?: string;
31+
}
32+
33+
/** A registry item (tool, agent, prompt, or integration). */
34+
export interface RegistryItem {
35+
/** Unique item name. */
36+
name: string;
37+
/** Item type (e.g., "registry:tool", "registry:agent"). */
38+
type: string;
39+
/** Human-readable title. */
40+
title?: string;
41+
/** Description of the item. */
42+
description?: string;
43+
/** Item version. */
44+
version?: string;
45+
/** Language this item is for (python or typescript). */
46+
language?: string;
47+
/** Categories for filtering/searching. */
48+
categories?: string[];
49+
/** Mirascope version constraints by language. */
50+
mirascope?: Record<string, RegistryVersionConstraint>;
51+
/** Files included in this item. */
52+
files: RegistryFile[];
53+
/** External dependencies. */
54+
dependencies: RegistryDependencies;
55+
/** Other registry items this depends on. */
56+
registryDependencies?: string[];
57+
}
58+
59+
/** An item entry in the registry index. */
60+
export interface RegistryIndexItem {
61+
/** Item name. */
62+
name: string;
63+
/** Item type. */
64+
type: string;
65+
/** Path within the registry. */
66+
path: string;
67+
/** Optional description. */
68+
description?: string;
69+
}
70+
71+
/** The registry index containing all available items. */
72+
export interface RegistryIndex {
73+
/** Registry name. */
74+
name: string;
75+
/** Registry version. */
76+
version: string;
77+
/** Registry homepage URL. */
78+
homepage?: string;
79+
/** All items in the registry. */
80+
items: RegistryIndexItem[];
81+
}
82+
83+
/** Mirascope project configuration (mirascope.json). */
84+
export interface MirascopeConfig {
85+
/** JSON schema URL. */
86+
$schema?: string;
87+
/** Project language (python or typescript). */
88+
language?: string;
89+
/** Registry URL. */
90+
registry?: string;
91+
/** Path mappings for item types. */
92+
paths?: Record<string, string>;
93+
}

0 commit comments

Comments
 (0)