@compilr-dev/sdk 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # @compilr-dev/sdk
2
+
3
+ ```
4
+ \|/
5
+ ╭══════════╮ ___ ___ _ __ ___ _ __ (_) |_ __
6
+ ║' ▐▌ ▐▌ │ / __|/ _ \| '_ ` _ \| '_ \| | | '__|
7
+ ║ │ | (__| (_) | | | | | | |_) | | | |
8
+ ╰─═──────═─╯ \___|\___/|_| |_| |_| .__/|_|_|_|
9
+ \________\ | | .dev
10
+ |_| sdk
11
+ ```
12
+
13
+ > Universal agent runtime for building AI-powered applications
14
+
15
+ [![npm version](https://img.shields.io/npm/v/@compilr-dev/sdk.svg)](https://www.npmjs.com/package/@compilr-dev/sdk)
16
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
17
+
18
+ > [!WARNING]
19
+ > This package is in beta. APIs may change between minor versions.
20
+
21
+ ## Overview
22
+
23
+ The SDK sits on top of [@compilr-dev/agents](https://www.npmjs.com/package/@compilr-dev/agents) and [@compilr-dev/agents-coding](https://www.npmjs.com/package/@compilr-dev/agents-coding), providing a high-level API for agent creation, tool assembly, and multi-agent teams. It's the runtime that powers [@compilr-dev/cli](https://www.npmjs.com/package/@compilr-dev/cli).
24
+
25
+ ## Features
26
+
27
+ - **`createCompilrAgent()`** — three lines to a fully configured AI agent
28
+ - **`createTeam()`** — multi-agent teams with role identity and task handoff
29
+ - **Presets** — `coding` (40+ tools) and `read-only` out of the box
30
+ - **9 LLM Providers** — Claude, OpenAI, Gemini, Ollama, Together, Groq, Fireworks, Perplexity, OpenRouter
31
+ - **System Prompt Builder** — modular, token-aware prompt assembly
32
+ - **Full Re-exports** — use the SDK as your single dependency for the entire compilr-dev stack
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ npm install @compilr-dev/sdk
38
+ ```
39
+
40
+ Peer dependencies:
41
+
42
+ ```bash
43
+ npm install @compilr-dev/agents @compilr-dev/agents-coding
44
+ ```
45
+
46
+ ## Quick Start
47
+
48
+ ```typescript
49
+ import { createCompilrAgent } from '@compilr-dev/sdk';
50
+
51
+ const agent = createCompilrAgent({
52
+ provider: { type: 'anthropic' },
53
+ });
54
+
55
+ const result = await agent.run('Fix the failing tests in src/auth/');
56
+ console.log(result.response);
57
+ ```
58
+
59
+ ### Custom Domain (Non-Coding)
60
+
61
+ ```typescript
62
+ import { createCompilrAgent, defineTool, createSuccessResult } from '@compilr-dev/sdk';
63
+
64
+ const agent = createCompilrAgent({
65
+ preset: 'none',
66
+ systemPrompt: 'You are an HR assistant.',
67
+ tools: {
68
+ custom: [
69
+ defineTool({
70
+ name: 'search_kb',
71
+ description: 'Search the knowledge base',
72
+ parameters: { query: { type: 'string' } },
73
+ execute: async ({ query }) => createSuccessResult(`Results for: ${query}`),
74
+ }),
75
+ ],
76
+ },
77
+ });
78
+ ```
79
+
80
+ ### Multi-Agent Team
81
+
82
+ ```typescript
83
+ import { createTeam } from '@compilr-dev/sdk';
84
+
85
+ const team = createTeam({
86
+ agents: {
87
+ arch: { role: 'architect' },
88
+ dev: { role: 'developer' },
89
+ },
90
+ });
91
+
92
+ await team.run('Add rate limiting to the API');
93
+ ```
94
+
95
+ ## Supported Providers
96
+
97
+ | Provider | Type | Models |
98
+ |----------|------|--------|
99
+ | Anthropic | `anthropic` | Claude 4.5, Claude 4, Claude 3.5 |
100
+ | OpenAI | `openai` | GPT-4o, GPT-4, o1, o3 |
101
+ | Google | `gemini` | Gemini 2.5, Gemini 2.0 |
102
+ | Ollama | `ollama` | Any local model |
103
+ | Together AI | `together` | Llama, Qwen, DeepSeek |
104
+ | Groq | `groq` | Llama, Mixtral |
105
+ | Fireworks | `fireworks` | Llama, Qwen |
106
+ | Perplexity | `perplexity` | Sonar models |
107
+ | OpenRouter | `openrouter` | Multi-provider routing |
108
+
109
+ ## Requirements
110
+
111
+ - Node.js >= 18
112
+ - Peer dependencies: `@compilr-dev/agents` ^0.3.14, `@compilr-dev/agents-coding` ^1.0.2
113
+
114
+ ## Related Packages
115
+
116
+ | Package | Description |
117
+ |---------|-------------|
118
+ | [@compilr-dev/cli](https://www.npmjs.com/package/@compilr-dev/cli) | AI-powered coding assistant for your terminal |
119
+ | [@compilr-dev/agents](https://www.npmjs.com/package/@compilr-dev/agents) | Multi-LLM agent library |
120
+ | [@compilr-dev/agents-coding](https://www.npmjs.com/package/@compilr-dev/agents-coding) | Coding-specific tools and language analysis |
121
+
122
+ ## Links
123
+
124
+ - [Website](https://compilr.dev)
125
+ - [npm Package](https://www.npmjs.com/package/@compilr-dev/sdk)
126
+ - [Report Issues](https://github.com/compilr-dev/sdk/issues)
127
+
128
+ ## License
129
+
130
+ MIT - See [LICENSE](LICENSE) for details.
131
+
132
+ ---
133
+
134
+ <p align="center">
135
+ <strong>Built with care by <a href="https://compilr.dev">compilr.dev</a></strong>
136
+ </p>
package/dist/index.d.ts CHANGED
@@ -47,6 +47,9 @@ export { MetaToolsRegistry, createMetaTools, META_TOOLS_SYSTEM_PROMPT_PREFIX, }
47
47
  export type { MetaToolStats, MetaTools } from './meta-tools/index.js';
48
48
  export { SystemPromptBuilder, buildSystemPrompt, detectGitRepository, getModuleStats, ALL_MODULES, IDENTITY_MODULE, STYLE_MODULE, TASK_EXECUTION_MODULE, TODO_MANAGEMENT_MODULE, TOOL_USAGE_DIRECT_MODULE, TOOL_USAGE_META_MODULE, DELEGATION_MODULE, GIT_SAFETY_MODULE, SUGGEST_MODULE, IMPORTANT_RULES_MODULE, ENVIRONMENT_MODULE, shouldIncludeModule, getEstimatedTokensForConditions, getTotalEstimatedTokens, } from './system-prompt/index.js';
49
49
  export type { SystemPromptContext, BuildResult, SystemPromptModule, ModuleConditions, } from './system-prompt/index.js';
50
+ export type { ProjectType, ProjectStatus, RepoPattern, WorkflowMode, LifecycleState, WorkItemType, WorkItemStatus, WorkItemPriority, GuidedStep, DocumentType, PlanStatus, Project, WorkItem, ProjectDocument, Plan, PlanSummary, PlanWithWorkItem, HistoryEntry, CreateProjectInput, UpdateProjectInput, ProjectListOptions, CreateWorkItemInput, UpdateWorkItemInput, QueryWorkItemsInput, CreateDocumentInput, UpdateDocumentInput, CreatePlanInput, UpdatePlanInput, ListPlansOptions, WorkItemQueryResult, ProjectListResult, BulkCreateItem, IProjectRepository, IWorkItemRepository, IDocumentRepository, IPlanRepository, PlatformContext, PlatformToolsConfig, PlatformHooks, StepCriteria, } from './platform/index.js';
51
+ export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, } from './platform/index.js';
52
+ export { STEP_ORDER, GUIDED_STEP_CRITERIA, getNextStep, isValidTransition, getStepCriteria, formatStepDisplay, getStepNumber, } from './platform/index.js';
50
53
  export { defineTool, createSuccessResult, createErrorResult, mergeHooks, createLoggingHooks, createClaudeProvider, createOpenAIProvider, createGeminiNativeProvider, createOllamaProvider, createTogetherProvider, createGroqProvider, createFireworksProvider, createPerplexityProvider, createOpenRouterProvider, createMockProvider, MockProvider, Agent, ContextManager, DEFAULT_CONTEXT_CONFIG, createTaskTool, createSuggestTool, defaultAgentTypes, TOOL_SETS, BUILTIN_GUARDRAILS, TOOL_NAMES, getDefaultShellManager, builtinSkills, AnchorManager, MCPManager, AgentError, ProviderError, ToolError, ToolTimeoutError, MaxIterationsError, AbortError, } from '@compilr-dev/agents';
51
54
  export type { Tool, HooksConfig, AgentEvent, Message, LLMProvider, AnchorInput, ToolExecutionResult, AgentRunResult, PermissionHandler, ToolPermission, AgentTypeConfig, GuardrailTriggeredHandler, BeforeLLMHookResult, BeforeToolHook, BeforeToolHookResult, AfterToolHook, AgentState, AgentConfig, SessionInfo, Anchor, AnchorScope, AnchorClearOptions, AnchorPriority, AnchorQueryOptions, FileAccessType, FileAccess, GuardrailResult, GuardrailContext, MCPClient, MCPToolDefinition, } from '@compilr-dev/agents';
52
55
  export { readFileTool, writeFileTool, createBashTool, bashTool, bashOutputTool, killShellTool, grepTool, globTool, editTool, todoWriteTool, todoReadTool, createTodoTools, TodoStore, webFetchTool, suggestTool, } from '@compilr-dev/agents';
package/dist/index.js CHANGED
@@ -75,6 +75,14 @@ ALL_MODULES, IDENTITY_MODULE, STYLE_MODULE, TASK_EXECUTION_MODULE, TODO_MANAGEME
75
75
  // Module utilities
76
76
  shouldIncludeModule, getEstimatedTokensForConditions, getTotalEstimatedTokens, } from './system-prompt/index.js';
77
77
  // =============================================================================
78
+ // Platform Tools (runtime — createPlatformTools factory + individual factories)
79
+ // =============================================================================
80
+ export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, } from './platform/index.js';
81
+ // =============================================================================
82
+ // Platform Workflow (pure step-criteria logic)
83
+ // =============================================================================
84
+ export { STEP_ORDER, GUIDED_STEP_CRITERIA, getNextStep, isValidTransition, getStepCriteria, formatStepDisplay, getStepNumber, } from './platform/index.js';
85
+ // =============================================================================
78
86
  // Re-exports from @compilr-dev/agents (convenience — no need to install separately)
79
87
  // =============================================================================
80
88
  export {
@@ -0,0 +1,44 @@
1
+ /**
2
+ * PlatformContext — Unified access to all platform repositories.
3
+ *
4
+ * Provides a single entry point for data access, abstracting over the
5
+ * underlying storage backend (SQLite in CLI, PostgreSQL in web/API).
6
+ */
7
+ import type { IProjectRepository, IWorkItemRepository, IDocumentRepository, IPlanRepository } from './repositories.js';
8
+ export interface PlatformContext {
9
+ readonly projects: IProjectRepository;
10
+ readonly workItems: IWorkItemRepository;
11
+ readonly documents: IDocumentRepository;
12
+ readonly plans: IPlanRepository;
13
+ currentProjectId?: number;
14
+ }
15
+ export interface PlatformHooks {
16
+ /** Called when a project is resolved/selected as the current project */
17
+ onProjectResolved?: (project: {
18
+ id: number;
19
+ name: string;
20
+ displayName: string;
21
+ path: string;
22
+ }) => void;
23
+ /** Called when a work item is completed */
24
+ onWorkItemCompleted?: (item: {
25
+ id: number;
26
+ itemId: string;
27
+ title: string;
28
+ }) => void;
29
+ /** Called when the first project is created (for gamification) */
30
+ onFirstProject?: (project: {
31
+ id: number;
32
+ name: string;
33
+ }) => void;
34
+ /** Resolve owner aliases (e.g., 'self' → active agent ID) */
35
+ resolveOwner?: (alias: 'self') => string | undefined;
36
+ }
37
+ export interface PlatformToolsConfig {
38
+ /** Data access layer */
39
+ context: PlatformContext;
40
+ /** Working directory override (defaults to process.cwd()) */
41
+ cwd?: string;
42
+ /** Optional hooks for CLI-specific side effects */
43
+ hooks?: PlatformHooks;
44
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * PlatformContext — Unified access to all platform repositories.
3
+ *
4
+ * Provides a single entry point for data access, abstracting over the
5
+ * underlying storage backend (SQLite in CLI, PostgreSQL in web/API).
6
+ */
7
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Platform — Repository interfaces, data models, tools, and workflow.
3
+ */
4
+ export type { ProjectType, ProjectStatus, RepoPattern, WorkflowMode, LifecycleState, WorkItemType, WorkItemStatus, WorkItemPriority, GuidedStep, DocumentType, PlanStatus, Project, WorkItem, ProjectDocument, Plan, PlanSummary, PlanWithWorkItem, HistoryEntry, CreateProjectInput, UpdateProjectInput, ProjectListOptions, CreateWorkItemInput, UpdateWorkItemInput, QueryWorkItemsInput, CreateDocumentInput, UpdateDocumentInput, CreatePlanInput, UpdatePlanInput, ListPlansOptions, WorkItemQueryResult, ProjectListResult, BulkCreateItem, } from './types.js';
5
+ export type { IProjectRepository, IWorkItemRepository, IDocumentRepository, IPlanRepository, } from './repositories.js';
6
+ export type { PlatformContext, PlatformToolsConfig, PlatformHooks } from './context.js';
7
+ export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, } from './tools/index.js';
8
+ export { STEP_ORDER, GUIDED_STEP_CRITERIA, getNextStep, isValidTransition, getStepCriteria, formatStepDisplay, getStepNumber, } from './workflow.js';
9
+ export type { StepCriteria } from './workflow.js';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Platform — Repository interfaces, data models, tools, and workflow.
3
+ */
4
+ // Platform tools (runtime)
5
+ export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, } from './tools/index.js';
6
+ // Workflow (pure step-criteria logic)
7
+ export { STEP_ORDER, GUIDED_STEP_CRITERIA, getNextStep, isValidTransition, getStepCriteria, formatStepDisplay, getStepNumber, } from './workflow.js';
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Repository Interfaces — Storage-agnostic data access contracts.
3
+ *
4
+ * All methods return Promise<T> even though the current CLI implementation
5
+ * uses synchronous SQLite. This ensures compatibility with future async
6
+ * backends (PostgreSQL, HTTP APIs).
7
+ */
8
+ import type { Project, WorkItem, ProjectDocument, Plan, PlanSummary, PlanWithWorkItem, HistoryEntry, CreateProjectInput, UpdateProjectInput, ProjectListOptions, CreateWorkItemInput, UpdateWorkItemInput, QueryWorkItemsInput, CreateDocumentInput, UpdateDocumentInput, CreatePlanInput, UpdatePlanInput, ListPlansOptions, WorkItemQueryResult, ProjectListResult, BulkCreateItem, ProjectStatus, WorkItemType, WorkItemStatus, DocumentType, PlanStatus } from './types.js';
9
+ export interface IProjectRepository {
10
+ create(input: CreateProjectInput): Promise<Project>;
11
+ getById(id: number): Promise<Project | null>;
12
+ getByName(name: string): Promise<Project | null>;
13
+ getByPath(path: string): Promise<Project | null>;
14
+ getByDocsPath(docsPath: string): Promise<Project | null>;
15
+ findByPath(searchPath: string): Promise<Project | null>;
16
+ list(options?: ProjectListOptions): Promise<ProjectListResult>;
17
+ update(id: number, input: UpdateProjectInput): Promise<Project | null>;
18
+ touch(id: number): Promise<void>;
19
+ delete(id: number): Promise<boolean>;
20
+ archive(id: number): Promise<Project | null>;
21
+ isNameAvailable(name: string, excludeId?: number): Promise<boolean>;
22
+ getStatusCounts(): Promise<Record<ProjectStatus, number>>;
23
+ }
24
+ export interface IWorkItemRepository {
25
+ create(input: CreateWorkItemInput): Promise<WorkItem>;
26
+ getById(id: number): Promise<WorkItem | null>;
27
+ getByItemId(projectId: number, itemId: string): Promise<WorkItem | null>;
28
+ query(input: QueryWorkItemsInput): Promise<WorkItemQueryResult>;
29
+ getNext(projectId: number, type?: WorkItemType): Promise<WorkItem | null>;
30
+ update(id: number, input: UpdateWorkItemInput): Promise<WorkItem | null>;
31
+ delete(id: number): Promise<boolean>;
32
+ getByOwner(projectId: number, owner: string, status?: WorkItemStatus): Promise<WorkItem[]>;
33
+ getOwnerCounts(projectId: number): Promise<Record<string, number>>;
34
+ getStatusCounts(projectId: number): Promise<Record<WorkItemStatus, number>>;
35
+ getHistory(workItemId: number): Promise<HistoryEntry[]>;
36
+ bulkCreate(projectId: number, items: BulkCreateItem[]): Promise<WorkItem[]>;
37
+ }
38
+ export interface IDocumentRepository {
39
+ upsert(input: CreateDocumentInput): Promise<ProjectDocument>;
40
+ create(input: CreateDocumentInput): Promise<ProjectDocument>;
41
+ getById(id: number): Promise<ProjectDocument | null>;
42
+ getByType(projectId: number, docType: DocumentType): Promise<ProjectDocument | null>;
43
+ listByProject(projectId: number): Promise<ProjectDocument[]>;
44
+ update(id: number, input: UpdateDocumentInput): Promise<ProjectDocument | null>;
45
+ delete(id: number): Promise<boolean>;
46
+ deleteByType(projectId: number, docType: DocumentType): Promise<boolean>;
47
+ getTypeCounts(projectId: number): Promise<Record<DocumentType, number>>;
48
+ }
49
+ export interface IPlanRepository {
50
+ create(input: CreatePlanInput): Promise<Plan>;
51
+ getById(id: number): Promise<Plan | null>;
52
+ getByName(projectId: number, name: string): Promise<Plan | null>;
53
+ getWithWorkItem(id: number): Promise<PlanWithWorkItem | null>;
54
+ update(id: number, input: UpdatePlanInput): Promise<Plan | null>;
55
+ delete(id: number): Promise<boolean>;
56
+ list(projectId: number, options?: ListPlansOptions): Promise<PlanSummary[]>;
57
+ countByStatus(projectId: number): Promise<Record<PlanStatus, number>>;
58
+ getInProgress(projectId: number): Promise<PlanSummary[]>;
59
+ hasInProgress(projectId: number): Promise<boolean>;
60
+ linkWorkItem(planId: number, workItemId: number): Promise<Plan | null>;
61
+ unlinkWorkItem(planId: number): Promise<Plan | null>;
62
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Repository Interfaces — Storage-agnostic data access contracts.
3
+ *
4
+ * All methods return Promise<T> even though the current CLI implementation
5
+ * uses synchronous SQLite. This ensures compatibility with future async
6
+ * backends (PostgreSQL, HTTP APIs).
7
+ */
8
+ export {};
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Backlog Wrapper Tools — Library-compatible backlog interface over work items.
3
+ *
4
+ * 2 tools: backlog_read, backlog_write
5
+ *
6
+ * These wrappers provide `backlog_read` and `backlog_write` tools that skills expect,
7
+ * but internally delegate to the work item repository. This allows library skills
8
+ * (which reference backlog_*) to work seamlessly with the database-backed work items.
9
+ *
10
+ * Ported from CLI's src/tools/backlog-wrappers.ts.
11
+ */
12
+ import type { PlatformToolsConfig } from '../context.js';
13
+ export declare function createBacklogTools(config: PlatformToolsConfig): (import("@compilr-dev/agents").Tool<{
14
+ id?: string;
15
+ status?: string;
16
+ type?: string;
17
+ search?: string;
18
+ priority?: string;
19
+ limit?: number;
20
+ }> | import("@compilr-dev/agents").Tool<{
21
+ action: string;
22
+ item?: {
23
+ id?: string;
24
+ type?: string;
25
+ title?: string;
26
+ description?: string;
27
+ status?: string;
28
+ priority?: string;
29
+ owner?: string;
30
+ commit_hash?: string;
31
+ };
32
+ deleteId?: string;
33
+ items?: Array<{
34
+ id?: string;
35
+ type: string;
36
+ title: string;
37
+ description?: string;
38
+ status?: string;
39
+ priority?: string;
40
+ }>;
41
+ }>)[];