feat: M7 proper LLM integration with dual providers, caching, and parallel batching
- Add LLM client abstraction (src/llm-client.ts) with factory pattern - Add OpenAI-compatible external client (src/external-llm-client.ts) - Add Kimi.com client using Anthropic-based API (src/kimi-llm-client.ts) - Add Pi native LLM stub (src/pi-llm-client.ts) for future ExtensionAPI wiring - Add SHA-256 disk cache at ~/.cache/pi-project-map/ (src/llm-cache.ts) - Add parallel batching with p-limit, retry + exponential backoff (src/llm-batch.ts) - Rewrite llm-extract.ts to use real LLM calls with structured prompts - File-level: PURPOSE, DEPS, CONCEPTS - Package-level: ROLE, ARCH - Context truncation, 50KB skip, cache before LLM call - Wire CLI with --llm-provider, --llm-model, --llm-base-url flags - Update config.ts with llmProvider, llmBaseUrl fields - Update init.ts and patch.ts to accept optional LLMClient - Add sample project fixture for manual testing - Add tests: llm-cache (3), llm-batch (5), llm-integration (8 with real Kimi API), pi-extension (14 mocked) - All 56 tests pass
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
dist/
|
||||
node_modules/
|
||||
.pi-map.md
|
||||
.env
|
||||
@@ -0,0 +1,9 @@
|
||||
# Sample Project
|
||||
|
||||
A small test project for pi-project-map functionality.
|
||||
|
||||
## Structure
|
||||
|
||||
- `src/` — Source code
|
||||
- `tests/` — Test suites
|
||||
- `docs/` — Documentation
|
||||
@@ -0,0 +1,24 @@
|
||||
# API Documentation
|
||||
|
||||
## User Model
|
||||
|
||||
### `createUser(data)`
|
||||
|
||||
Creates a new user with auto-generated ID and timestamp.
|
||||
|
||||
**Parameters:**
|
||||
- `data` — Object with `email` and `name` fields
|
||||
|
||||
**Returns:** `User` object
|
||||
|
||||
**Throws:** `Error` if email is invalid
|
||||
|
||||
### `serializeUser(user)`
|
||||
|
||||
Serializes a user to JSON string.
|
||||
|
||||
## Validation Utilities
|
||||
|
||||
- `validateEmail(email)` — Validates email format
|
||||
- `validateNotEmpty(value)` — Checks string is not empty
|
||||
- `validateMinLength(value, min)` — Checks minimum string length
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "sample-project",
|
||||
"version": "1.0.0",
|
||||
"description": "Sample project for testing pi-project-map",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "vitest"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import React from "react";
|
||||
|
||||
export interface ButtonProps {
|
||||
label: string;
|
||||
variant?: "primary" | "secondary" | "danger";
|
||||
onClick?: () => void;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export function Button({
|
||||
label,
|
||||
variant = "primary",
|
||||
onClick,
|
||||
disabled = false,
|
||||
}: ButtonProps): JSX.Element {
|
||||
return (
|
||||
<button
|
||||
className={`btn btn--${variant}`}
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export default Button;
|
||||
@@ -0,0 +1,23 @@
|
||||
import React from "react";
|
||||
import type { User } from "../models/user.js";
|
||||
|
||||
export interface UserCardProps {
|
||||
user: User;
|
||||
onEdit?: (user: User) => void;
|
||||
onDelete?: (id: string) => void;
|
||||
}
|
||||
|
||||
export function UserCard({ user, onEdit, onDelete }: UserCardProps): JSX.Element {
|
||||
return (
|
||||
<div className="user-card">
|
||||
<h3>{user.name}</h3>
|
||||
<p>{user.email}</p>
|
||||
<div className="actions">
|
||||
{onEdit && <button onClick={() => onEdit(user)}>Edit</button>}
|
||||
{onDelete && <button onClick={() => onDelete(user.id)}>Delete</button>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default UserCard;
|
||||
@@ -0,0 +1,14 @@
|
||||
import { createUser } from "./models/user.js";
|
||||
import { validateEmail } from "./utils/validation.js";
|
||||
import { logger } from "./utils/logger.js";
|
||||
|
||||
export async function main() {
|
||||
const user = createUser({ email: "test@example.com", name: "Alice" });
|
||||
if (!validateEmail(user.email)) {
|
||||
logger.error("Invalid email");
|
||||
return;
|
||||
}
|
||||
logger.info(`User created: ${user.name}`);
|
||||
}
|
||||
|
||||
export { createUser, validateEmail, logger };
|
||||
@@ -0,0 +1,23 @@
|
||||
import { validateEmail } from "../utils/validation.js";
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export function createUser(data: Omit<User, "id" | "createdAt">): User {
|
||||
if (!validateEmail(data.email)) {
|
||||
throw new Error("Invalid email");
|
||||
}
|
||||
return {
|
||||
id: crypto.randomUUID(),
|
||||
...data,
|
||||
createdAt: new Date(),
|
||||
};
|
||||
}
|
||||
|
||||
export function serializeUser(user: User): string {
|
||||
return JSON.stringify(user);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
export type LogLevel = "debug" | "info" | "warn" | "error";
|
||||
|
||||
export function log(level: LogLevel, message: string): void {
|
||||
const timestamp = new Date().toISOString();
|
||||
console.log(`[${timestamp}] ${level.toUpperCase()}: ${message}`);
|
||||
}
|
||||
|
||||
export function debug(message: string): void {
|
||||
log("debug", message);
|
||||
}
|
||||
|
||||
export function info(message: string): void {
|
||||
log("info", message);
|
||||
}
|
||||
|
||||
export function warn(message: string): void {
|
||||
log("warn", message);
|
||||
}
|
||||
|
||||
export function error(message: string): void {
|
||||
log("error", message);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
|
||||
export function validateEmail(email: string): boolean {
|
||||
return EMAIL_REGEX.test(email);
|
||||
}
|
||||
|
||||
export function validateNotEmpty(value: string): boolean {
|
||||
return value.trim().length > 0;
|
||||
}
|
||||
|
||||
export function validateMinLength(value: string, min: number): boolean {
|
||||
return value.length >= min;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { createUser, serializeUser } from "../src/models/user.js";
|
||||
|
||||
describe("User model", () => {
|
||||
it("creates a user with valid email", () => {
|
||||
const user = createUser({ email: "alice@example.com", name: "Alice" });
|
||||
expect(user.email).toBe("alice@example.com");
|
||||
expect(user.name).toBe("Alice");
|
||||
expect(user.id).toBeDefined();
|
||||
expect(user.createdAt).toBeInstanceOf(Date);
|
||||
});
|
||||
|
||||
it("throws on invalid email", () => {
|
||||
expect(() =>
|
||||
createUser({ email: "not-an-email", name: "Bob" }),
|
||||
).toThrow("Invalid email");
|
||||
});
|
||||
|
||||
it("serializes to JSON", () => {
|
||||
const user = createUser({ email: "charlie@example.com", name: "Charlie" });
|
||||
const json = serializeUser(user);
|
||||
expect(JSON.parse(json).name).toBe("Charlie");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { validateEmail, validateNotEmpty, validateMinLength } from "../src/utils/validation.js";
|
||||
|
||||
describe("Validation utils", () => {
|
||||
it("validates email format", () => {
|
||||
expect(validateEmail("test@example.com")).toBe(true);
|
||||
expect(validateEmail("invalid")).toBe(false);
|
||||
expect(validateEmail("")).toBe(false);
|
||||
});
|
||||
|
||||
it("checks non-empty strings", () => {
|
||||
expect(validateNotEmpty("hello")).toBe(true);
|
||||
expect(validateNotEmpty(" ")).toBe(false);
|
||||
expect(validateNotEmpty("")).toBe(false);
|
||||
});
|
||||
|
||||
it("checks minimum length", () => {
|
||||
expect(validateMinLength("hello", 3)).toBe(true);
|
||||
expect(validateMinLength("hi", 3)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"strict": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user