husteno-o feat: code review system, type safety, error handling, AI provider fallback · 9/9/2026
5ccaeae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { NotFoundError, ValidationError } from "@devpulse/core";
export interface PackageMetadata {
ecosystem: "npm" | "pypi" | "crates" | "go";
name: string;
version: string;
description: string;
license: string;
homepage?: string;
repository?: string;
publishedAt?: string;
dependenciesCount?: number;
securityNotice: string;
}
export async function lookupPackage(
ecosystem: "npm" | "pypi" | "crates" | "go",
packageName: string,
): Promise<PackageMetadata> {
const cleanName = packageName.trim();
if (!cleanName) throw new ValidationError("Package name cannot be empty.");
switch (ecosystem) {
case "npm":
return fetchNpmPackage(cleanName);
case "pypi":
return fetchPypiPackage(cleanName);
case "crates":
return fetchCratesPackage(cleanName);
case "go":
return fetchGoModule(cleanName);
default:
throw new ValidationError(`Unsupported ecosystem: ${ecosystem}`);
}
}
async function fetchNpmPackage(name: string): Promise<PackageMetadata> {
const encodedName = name.startsWith("@")
? `@${encodeURIComponent(name.slice(1))}`
: encodeURIComponent(name);
const res = await fetch(`https://registry.npmjs.org/${encodedName}`, {
headers: { Accept: "application/json" },
});
if (res.status === 404) {
throw new NotFoundError(`npm package '${name}' was not found in registry.`);
}
if (!res.ok) {
throw new Error(`Failed to fetch npm package metadata: registry returned ${res.statusText}`);
}
const data = (await res.json()) as any;
const latestVersion =
data["dist-tags"]?.latest || Object.keys(data.versions || {}).pop() || "unknown";
const versionData = data.versions?.[latestVersion] || {};
let repoUrl = "";
if (typeof versionData.repository === "string") {
repoUrl = versionData.repository;
} else if (versionData.repository?.url) {
repoUrl = versionData.repository.url.replace(/^git\+/, "").replace(/\.git$/, "");
}
const depCount = Object.keys(versionData.dependencies || {}).length;
return {
ecosystem: "npm",
name: data.name || name,
version: latestVersion,
description: data.description || "No description provided",
license: versionData.license || data.license || "Not specified",
homepage: versionData.homepage || data.homepage,
repository: repoUrl || undefined,
publishedAt: data.time?.[latestVersion],
dependenciesCount: depCount,
securityNotice: "No known advisory returned by the configured security source.",
};
}
async function fetchPypiPackage(name: string): Promise<PackageMetadata> {
const res = await fetch(`https://pypi.org/pypi/${encodeURIComponent(name)}/json`, {
headers: { Accept: "application/json" },
});
if (res.status === 404) {
throw new NotFoundError(`PyPI package '${name}' was not found in index.`);
}
if (!res.ok) {
throw new Error(`Failed to fetch PyPI package metadata: registry returned ${res.statusText}`);
}
const data = (await res.json()) as any;
const info = data.info || {};
return {
ecosystem: "pypi",
name: info.name || name,
version: info.version || "unknown",
description: info.summary || "No description provided",
license: info.license || "Not specified",
homepage: info.home_page || info.project_urls?.Homepage,
repository: info.project_urls?.Source || info.project_urls?.Repository,
dependenciesCount: Array.isArray(info.requires_dist) ? info.requires_dist.length : 0,
securityNotice: "No known advisory returned by the configured security source.",
};
}
async function fetchCratesPackage(name: string): Promise<PackageMetadata> {
const res = await fetch(`https://crates.io/api/v1/crates/${encodeURIComponent(name)}`, {
headers: { "User-Agent": "DevPulse-Bot ([email protected])" },
});
if (res.status === 404) {
throw new NotFoundError(`Rust crate '${name}' was not found on crates.io.`);
}
if (!res.ok) {
throw new Error(`crates.io error: ${res.statusText}`);
}
const data = (await res.json()) as any;
const crate = data.crate || {};
return {
ecosystem: "crates",
name: crate.name || name,
version: crate.max_version || crate.newest_version || "unknown",
description: crate.description || "No description provided",
license: crate.license || "Not specified",
homepage: crate.homepage,
repository: crate.repository,
publishedAt: crate.updated_at,
securityNotice: "No known advisory returned by the configured security source.",
};
}
async function fetchGoModule(modulePath: string): Promise<PackageMetadata> {
const res = await fetch(`https://proxy.golang.org/${modulePath.toLowerCase()}/@latest`, {
headers: { Accept: "application/json" },
});
if (res.status === 404 || res.status === 410) {
throw new NotFoundError(`Go module '${modulePath}' was not found.`);
}
if (!res.ok) {
throw new Error(`Go proxy error: ${res.statusText}`);
}
const data = (await res.json()) as any;
return {
ecosystem: "go",
name: modulePath,
version: data.Version || "unknown",
description: `Go module: ${modulePath}`,
license: "See repository",
publishedAt: data.Time,
repository: `https://${modulePath.replace(/^github\.com\//, "github.com/")}`,
securityNotice: "No known advisory returned by the configured security source.",
};
}