@compilr-dev/sdk 0.1.7 → 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 +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -0
- package/dist/platform/context.d.ts +44 -0
- package/dist/platform/context.js +7 -0
- package/dist/platform/index.d.ts +9 -0
- package/dist/platform/index.js +7 -0
- package/dist/platform/repositories.d.ts +62 -0
- package/dist/platform/repositories.js +8 -0
- package/dist/platform/tools/backlog-tools.d.ts +41 -0
- package/dist/platform/tools/backlog-tools.js +358 -0
- package/dist/platform/tools/document-tools.d.ts +15 -0
- package/dist/platform/tools/document-tools.js +217 -0
- package/dist/platform/tools/index.d.ts +135 -0
- package/dist/platform/tools/index.js +31 -0
- package/dist/platform/tools/plan-tools.d.ts +29 -0
- package/dist/platform/tools/plan-tools.js +325 -0
- package/dist/platform/tools/project-tools.d.ts +41 -0
- package/dist/platform/tools/project-tools.js +367 -0
- package/dist/platform/tools/workitem-tools.d.ts +56 -0
- package/dist/platform/tools/workitem-tools.js +715 -0
- package/dist/platform/types.d.ts +233 -0
- package/dist/platform/types.js +13 -0
- package/dist/platform/workflow.d.ts +37 -0
- package/dist/platform/workflow.js +108 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
[](https://www.npmjs.com/package/@compilr-dev/sdk)
|
|
16
16
|
[](https://opensource.org/licenses/MIT)
|
|
17
17
|
|
|
18
|
+
> [!WARNING]
|
|
19
|
+
> This package is in beta. APIs may change between minor versions.
|
|
20
|
+
|
|
18
21
|
## Overview
|
|
19
22
|
|
|
20
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).
|
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,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
|
+
}>)[];
|
|
@@ -0,0 +1,358 @@
|
|
|
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 { defineTool, createSuccessResult, createErrorResult } from '@compilr-dev/agents';
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// Type Mappings (Library ↔ CLI)
|
|
15
|
+
// =============================================================================
|
|
16
|
+
/** Library status → CLI status */
|
|
17
|
+
const STATUS_TO_CLI = {
|
|
18
|
+
backlog: 'backlog',
|
|
19
|
+
'in-progress': 'in_progress',
|
|
20
|
+
done: 'completed',
|
|
21
|
+
blocked: 'skipped',
|
|
22
|
+
};
|
|
23
|
+
/** CLI status → Library status */
|
|
24
|
+
const STATUS_TO_LIBRARY = {
|
|
25
|
+
backlog: 'backlog',
|
|
26
|
+
in_progress: 'in-progress',
|
|
27
|
+
completed: 'done',
|
|
28
|
+
skipped: 'blocked',
|
|
29
|
+
};
|
|
30
|
+
/** Library type → CLI type */
|
|
31
|
+
const TYPE_TO_CLI = {
|
|
32
|
+
feature: 'feature',
|
|
33
|
+
bug: 'bug',
|
|
34
|
+
chore: 'chore',
|
|
35
|
+
spike: 'tech-debt',
|
|
36
|
+
};
|
|
37
|
+
/** CLI type → Library type */
|
|
38
|
+
const TYPE_TO_LIBRARY = {
|
|
39
|
+
feature: 'feature',
|
|
40
|
+
bug: 'bug',
|
|
41
|
+
chore: 'chore',
|
|
42
|
+
'tech-debt': 'spike',
|
|
43
|
+
};
|
|
44
|
+
// =============================================================================
|
|
45
|
+
// Tool factory
|
|
46
|
+
// =============================================================================
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
48
|
+
export function createBacklogTools(config) {
|
|
49
|
+
const { context: ctx } = config;
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// backlog_read
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
const backlogReadTool = defineTool({
|
|
54
|
+
name: 'backlog_read',
|
|
55
|
+
description: 'Read backlog items from the project. ' +
|
|
56
|
+
'Use filters to narrow results. Use id parameter to get a specific item. ' +
|
|
57
|
+
'Returns items sorted by priority (critical first) then by creation date.',
|
|
58
|
+
inputSchema: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
id: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
description: 'Get a specific item by ID (e.g., "FEAT-001")',
|
|
64
|
+
},
|
|
65
|
+
status: {
|
|
66
|
+
type: 'string',
|
|
67
|
+
enum: ['backlog', 'in-progress', 'done', 'blocked'],
|
|
68
|
+
description: 'Filter by status',
|
|
69
|
+
},
|
|
70
|
+
type: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
enum: ['feature', 'bug', 'chore', 'spike'],
|
|
73
|
+
description: 'Filter by item type',
|
|
74
|
+
},
|
|
75
|
+
search: {
|
|
76
|
+
type: 'string',
|
|
77
|
+
description: 'Search in title and description',
|
|
78
|
+
},
|
|
79
|
+
priority: {
|
|
80
|
+
type: 'string',
|
|
81
|
+
enum: ['critical', 'high', 'medium', 'low'],
|
|
82
|
+
description: 'Filter by priority',
|
|
83
|
+
},
|
|
84
|
+
limit: {
|
|
85
|
+
type: 'number',
|
|
86
|
+
description: 'Maximum items to return (default: 20)',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
required: [],
|
|
90
|
+
},
|
|
91
|
+
execute: async (input) => {
|
|
92
|
+
try {
|
|
93
|
+
const projectId = ctx.currentProjectId;
|
|
94
|
+
if (!projectId) {
|
|
95
|
+
return createSuccessResult({
|
|
96
|
+
items: [],
|
|
97
|
+
total: 0,
|
|
98
|
+
filtered: 0,
|
|
99
|
+
message: 'No active project. Use /projects to select a project first.',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// If specific ID requested, look it up directly
|
|
103
|
+
if (input.id) {
|
|
104
|
+
const item = await ctx.workItems.getByItemId(projectId, input.id);
|
|
105
|
+
if (!item) {
|
|
106
|
+
return createErrorResult(`Item not found: ${input.id}`);
|
|
107
|
+
}
|
|
108
|
+
return createSuccessResult({
|
|
109
|
+
items: [
|
|
110
|
+
{
|
|
111
|
+
id: item.itemId,
|
|
112
|
+
type: TYPE_TO_LIBRARY[item.type],
|
|
113
|
+
title: item.title,
|
|
114
|
+
description: item.description ?? '',
|
|
115
|
+
status: STATUS_TO_LIBRARY[item.status],
|
|
116
|
+
priority: item.priority,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
total: 1,
|
|
120
|
+
filtered: 1,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// Build query
|
|
124
|
+
const queryInput = {
|
|
125
|
+
project_id: projectId,
|
|
126
|
+
status: input.status ? STATUS_TO_CLI[input.status] : 'all',
|
|
127
|
+
type: input.type ? TYPE_TO_CLI[input.type] : 'all',
|
|
128
|
+
priority: input.priority ? input.priority : 'all',
|
|
129
|
+
search: input.search,
|
|
130
|
+
limit: input.limit ?? 20,
|
|
131
|
+
offset: 0,
|
|
132
|
+
};
|
|
133
|
+
const result = await ctx.workItems.query(queryInput);
|
|
134
|
+
const items = result.items.map((item) => ({
|
|
135
|
+
id: item.itemId,
|
|
136
|
+
type: TYPE_TO_LIBRARY[item.type],
|
|
137
|
+
title: item.title,
|
|
138
|
+
description: item.description ?? '',
|
|
139
|
+
status: STATUS_TO_LIBRARY[item.status],
|
|
140
|
+
priority: item.priority,
|
|
141
|
+
createdAt: item.createdAt.toISOString(),
|
|
142
|
+
updatedAt: item.createdAt.toISOString(),
|
|
143
|
+
}));
|
|
144
|
+
return createSuccessResult({
|
|
145
|
+
items,
|
|
146
|
+
total: result.total,
|
|
147
|
+
filtered: items.length,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return createErrorResult(error instanceof Error ? error.message : String(error));
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
// backlog_write
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
const backlogWriteTool = defineTool({
|
|
159
|
+
name: 'backlog_write',
|
|
160
|
+
description: 'Create, update, or delete backlog items. ' +
|
|
161
|
+
'Actions: add (new item), update (modify existing), delete (remove), replace (full list). ' +
|
|
162
|
+
'IDs are auto-generated for new items based on type (e.g., FEAT-001, BUG-002).',
|
|
163
|
+
inputSchema: {
|
|
164
|
+
type: 'object',
|
|
165
|
+
properties: {
|
|
166
|
+
action: {
|
|
167
|
+
type: 'string',
|
|
168
|
+
enum: ['add', 'update', 'delete', 'replace'],
|
|
169
|
+
description: 'Action to perform',
|
|
170
|
+
},
|
|
171
|
+
item: {
|
|
172
|
+
type: 'object',
|
|
173
|
+
description: 'Item to add or update (for add/update actions)',
|
|
174
|
+
properties: {
|
|
175
|
+
id: { type: 'string', description: 'Item ID (required for update)' },
|
|
176
|
+
type: {
|
|
177
|
+
type: 'string',
|
|
178
|
+
enum: ['feature', 'bug', 'chore', 'spike'],
|
|
179
|
+
description: 'Item type (required for add)',
|
|
180
|
+
},
|
|
181
|
+
title: { type: 'string', description: 'Item title' },
|
|
182
|
+
description: { type: 'string', description: 'Detailed description' },
|
|
183
|
+
status: {
|
|
184
|
+
type: 'string',
|
|
185
|
+
enum: ['backlog', 'in-progress', 'done', 'blocked'],
|
|
186
|
+
description: 'Item status',
|
|
187
|
+
},
|
|
188
|
+
priority: {
|
|
189
|
+
type: 'string',
|
|
190
|
+
enum: ['critical', 'high', 'medium', 'low'],
|
|
191
|
+
description: 'Priority level',
|
|
192
|
+
},
|
|
193
|
+
owner: {
|
|
194
|
+
type: 'string',
|
|
195
|
+
description: 'Owner/assignee of the item',
|
|
196
|
+
},
|
|
197
|
+
commit_hash: {
|
|
198
|
+
type: 'string',
|
|
199
|
+
description: 'Git commit hash associated with the item (for update)',
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
deleteId: {
|
|
204
|
+
type: 'string',
|
|
205
|
+
description: 'Item ID to delete (for delete action)',
|
|
206
|
+
},
|
|
207
|
+
items: {
|
|
208
|
+
type: 'array',
|
|
209
|
+
description: 'Full list of items (for replace action)',
|
|
210
|
+
items: {
|
|
211
|
+
type: 'object',
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
required: ['action'],
|
|
216
|
+
},
|
|
217
|
+
execute: async (input) => {
|
|
218
|
+
try {
|
|
219
|
+
const projectId = ctx.currentProjectId;
|
|
220
|
+
if (!projectId) {
|
|
221
|
+
return createErrorResult('No active project. Use /projects to select a project first.');
|
|
222
|
+
}
|
|
223
|
+
switch (input.action) {
|
|
224
|
+
case 'add': {
|
|
225
|
+
if (!input.item) {
|
|
226
|
+
return createErrorResult('Item is required for add action');
|
|
227
|
+
}
|
|
228
|
+
if (!input.item.type) {
|
|
229
|
+
return createErrorResult('Item type is required for add action');
|
|
230
|
+
}
|
|
231
|
+
if (!input.item.title) {
|
|
232
|
+
return createErrorResult('Item title is required for add action');
|
|
233
|
+
}
|
|
234
|
+
const createInput = {
|
|
235
|
+
project_id: projectId,
|
|
236
|
+
type: TYPE_TO_CLI[input.item.type],
|
|
237
|
+
title: input.item.title,
|
|
238
|
+
description: input.item.description,
|
|
239
|
+
priority: input.item.priority,
|
|
240
|
+
owner: input.item.owner,
|
|
241
|
+
};
|
|
242
|
+
const item = await ctx.workItems.create(createInput);
|
|
243
|
+
return createSuccessResult({
|
|
244
|
+
success: true,
|
|
245
|
+
action: 'add',
|
|
246
|
+
itemId: item.itemId,
|
|
247
|
+
message: `Created ${item.itemId}: "${item.title}"`,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
case 'update': {
|
|
251
|
+
if (!input.item?.id) {
|
|
252
|
+
return createErrorResult('Item ID is required for update action');
|
|
253
|
+
}
|
|
254
|
+
const existingItem = await ctx.workItems.getByItemId(projectId, input.item.id);
|
|
255
|
+
if (!existingItem) {
|
|
256
|
+
return createErrorResult(`Item not found: ${input.item.id}`);
|
|
257
|
+
}
|
|
258
|
+
const updateInput = {};
|
|
259
|
+
if (input.item.status) {
|
|
260
|
+
updateInput.status = STATUS_TO_CLI[input.item.status];
|
|
261
|
+
}
|
|
262
|
+
if (input.item.priority) {
|
|
263
|
+
updateInput.priority = input.item.priority;
|
|
264
|
+
}
|
|
265
|
+
if (input.item.title) {
|
|
266
|
+
updateInput.title = input.item.title;
|
|
267
|
+
}
|
|
268
|
+
if (input.item.description !== undefined) {
|
|
269
|
+
updateInput.description = input.item.description;
|
|
270
|
+
}
|
|
271
|
+
if (input.item.owner !== undefined) {
|
|
272
|
+
updateInput.owner = input.item.owner;
|
|
273
|
+
}
|
|
274
|
+
if (input.item.commit_hash) {
|
|
275
|
+
updateInput.commit_hash = input.item.commit_hash;
|
|
276
|
+
}
|
|
277
|
+
const updated = await ctx.workItems.update(existingItem.id, updateInput);
|
|
278
|
+
if (!updated) {
|
|
279
|
+
return createErrorResult(`Failed to update item: ${input.item.id}`);
|
|
280
|
+
}
|
|
281
|
+
return createSuccessResult({
|
|
282
|
+
success: true,
|
|
283
|
+
action: 'update',
|
|
284
|
+
itemId: input.item.id,
|
|
285
|
+
message: `Updated ${input.item.id}`,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
case 'delete': {
|
|
289
|
+
const deleteId = input.deleteId ?? input.item?.id;
|
|
290
|
+
if (!deleteId) {
|
|
291
|
+
return createErrorResult('deleteId or item.id is required for delete action');
|
|
292
|
+
}
|
|
293
|
+
const existingItem = await ctx.workItems.getByItemId(projectId, deleteId);
|
|
294
|
+
if (!existingItem) {
|
|
295
|
+
return createErrorResult(`Item not found: ${deleteId}`);
|
|
296
|
+
}
|
|
297
|
+
const deleted = await ctx.workItems.delete(existingItem.id);
|
|
298
|
+
if (!deleted) {
|
|
299
|
+
return createErrorResult(`Failed to delete item: ${deleteId}`);
|
|
300
|
+
}
|
|
301
|
+
return createSuccessResult({
|
|
302
|
+
success: true,
|
|
303
|
+
action: 'delete',
|
|
304
|
+
itemId: deleteId,
|
|
305
|
+
message: `Deleted ${deleteId}`,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
case 'replace': {
|
|
309
|
+
if (!input.items) {
|
|
310
|
+
return createErrorResult('Items array is required for replace action');
|
|
311
|
+
}
|
|
312
|
+
// Delete all existing items
|
|
313
|
+
const existing = await ctx.workItems.query({
|
|
314
|
+
project_id: projectId,
|
|
315
|
+
limit: 1000,
|
|
316
|
+
offset: 0,
|
|
317
|
+
});
|
|
318
|
+
for (const item of existing.items) {
|
|
319
|
+
await ctx.workItems.delete(item.id);
|
|
320
|
+
}
|
|
321
|
+
// Add all new items
|
|
322
|
+
const newIds = [];
|
|
323
|
+
for (const newItem of input.items) {
|
|
324
|
+
const createInput = {
|
|
325
|
+
project_id: projectId,
|
|
326
|
+
type: TYPE_TO_CLI[newItem.type],
|
|
327
|
+
title: newItem.title,
|
|
328
|
+
description: newItem.description,
|
|
329
|
+
priority: newItem.priority,
|
|
330
|
+
};
|
|
331
|
+
const created = await ctx.workItems.create(createInput);
|
|
332
|
+
newIds.push(created.itemId);
|
|
333
|
+
// Update status if not backlog
|
|
334
|
+
if (newItem.status && newItem.status !== 'backlog') {
|
|
335
|
+
await ctx.workItems.update(created.id, {
|
|
336
|
+
status: STATUS_TO_CLI[newItem.status],
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return createSuccessResult({
|
|
341
|
+
success: true,
|
|
342
|
+
action: 'replace',
|
|
343
|
+
itemCount: input.items.length,
|
|
344
|
+
newIds,
|
|
345
|
+
message: `Replaced backlog with ${String(input.items.length)} items`,
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
default:
|
|
349
|
+
return createErrorResult(`Unknown action: ${input.action}`);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
catch (error) {
|
|
353
|
+
return createErrorResult(error instanceof Error ? error.message : String(error));
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
return [backlogReadTool, backlogWriteTool];
|
|
358
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document Tools — CRUD operations for project documents.
|
|
3
|
+
*
|
|
4
|
+
* 4 tools: project_document_add, project_document_get,
|
|
5
|
+
* project_document_list, project_document_delete
|
|
6
|
+
*
|
|
7
|
+
* Ported from CLI's src/tools/document-db.ts.
|
|
8
|
+
*/
|
|
9
|
+
import type { PlatformToolsConfig } from '../context.js';
|
|
10
|
+
export declare function createDocumentTools(config: PlatformToolsConfig): import("@compilr-dev/agents").Tool<{
|
|
11
|
+
project_id?: number;
|
|
12
|
+
doc_type: string;
|
|
13
|
+
title: string;
|
|
14
|
+
content: string;
|
|
15
|
+
}>[];
|