@compilr-dev/sdk 0.9.6 → 0.9.7

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/dist/index.d.ts CHANGED
@@ -58,8 +58,8 @@ export { createSQLiteRepositories, SQLiteProjectRepository, SQLiteWorkItemReposi
58
58
  export type { SQLiteRepositories, CreateSQLiteRepositoriesOptions, ProjectDeleteHooks, ProjectRecord, WorkItemRecord, ProjectDocumentRecord, WorkItemCommentRecord, } from './platform/index.js';
59
59
  export { createAskUserTool, createAskUserSimpleTool } from './tools/index.js';
60
60
  export type { AskUserQuestion, AskUserInput, AskUserResult, AskUserHandler, AskUserSimpleInput, AskUserSimpleResult, AskUserSimpleHandler, } from './tools/index.js';
61
- export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, createAnchorTools, createArtifactTools, createEpisodeTools, ProjectAnchorStore, } from './platform/index.js';
62
- export type { ProjectAnchorStoreConfig } from './platform/index.js';
61
+ export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, createAnchorTools, createArtifactTools, createEpisodeTools, createImageTools, ProjectAnchorStore, } from './platform/index.js';
62
+ export type { ProjectAnchorStoreConfig, ImageToolsConfig, ImageResizer } from './platform/index.js';
63
63
  export { STEP_ORDER, GUIDED_STEP_CRITERIA, getNextStep, isValidTransition, getStepCriteria, formatStepDisplay, getStepNumber, } from './platform/index.js';
64
64
  export { platformSkills, designSkill, sketchSkill, prdSkill, refineSkill, refineItemSkill, architectureSkill, sessionNotesSkill, buildSkill, scaffoldSkill, outlineSkill, literatureReviewSkill, draftSectionSkill, peerReviewSkill, researchScaffoldSkill, businessVisionSkill, marketAnalysisSkill, competitorAnalysisSkill, financialModelSkill, pitchOutlineSkill, businessReviewSkill, brandSetupSkill, contentStrategySkill, contentCalendarSkill, createContentSkill, contentReviewSkill, curriculumDesignSkill, lessonPlanSkill, assessmentDesignSkill, courseReviewSkill, bookOutlineSkill, characterDesignSkill, plotThreadsSkill, sceneBreakdownSkill, bookReviewSkill, } from './skills/index.js';
65
65
  export { ACTION_REGISTRY, getActionsForContext, getActionById, resolveActionPrompt, buildContextSummary, getSuggestedRole, } from './actions/index.js';
package/dist/index.js CHANGED
@@ -131,7 +131,7 @@ export { createAskUserTool, createAskUserSimpleTool } from './tools/index.js';
131
131
  // =============================================================================
132
132
  // Platform Tools (runtime — createPlatformTools factory + individual factories)
133
133
  // =============================================================================
134
- export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, createAnchorTools, createArtifactTools, createEpisodeTools, ProjectAnchorStore, } from './platform/index.js';
134
+ export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, createAnchorTools, createArtifactTools, createEpisodeTools, createImageTools, ProjectAnchorStore, } from './platform/index.js';
135
135
  // =============================================================================
136
136
  // Platform Workflow (pure step-criteria logic)
137
137
  // =============================================================================
@@ -5,7 +5,8 @@ export type { ProjectType, ProjectStatus, RepoPattern, WorkflowMode, LifecycleSt
5
5
  export type { IProjectRepository, IWorkItemRepository, IDocumentRepository, IPlanRepository, ICommentRepository, } from './repositories.js';
6
6
  export type { IAnchorService, IArtifactService, IEpisodeService, AnchorData, ArtifactType, ArtifactData, ArtifactSummaryData, WorkEpisode, ProjectWorkSummary, } from './services.js';
7
7
  export type { PlatformContext, PlatformToolsConfig, PlatformHooks } from './context.js';
8
- export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, createAnchorTools, createArtifactTools, createEpisodeTools, } from './tools/index.js';
8
+ export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, createAnchorTools, createArtifactTools, createEpisodeTools, createImageTools, } from './tools/index.js';
9
+ export type { ImageToolsConfig, ImageResizer } from './tools/index.js';
9
10
  export { createSQLiteRepositories, SQLiteProjectRepository, SQLiteWorkItemRepository, SQLiteDocumentRepository, SQLitePlanRepository, SQLiteCommentRepository, getDatabase, closeDatabase, closeAllDatabases, databaseExists, SCHEMA_VERSION, SCHEMA_SQL, } from './sqlite/index.js';
10
11
  export type { SQLiteRepositories, CreateSQLiteRepositoriesOptions, ProjectDeleteHooks, ProjectRecord, WorkItemRecord, ProjectDocumentRecord, WorkItemCommentRecord, } from './sqlite/index.js';
11
12
  export { ProjectAnchorStore } from './file-anchor-service.js';
@@ -2,7 +2,7 @@
2
2
  * Platform — Repository interfaces, data models, tools, and workflow.
3
3
  */
4
4
  // Platform tools (runtime)
5
- export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, createAnchorTools, createArtifactTools, createEpisodeTools, } from './tools/index.js';
5
+ export { createPlatformTools, createProjectTools, createWorkItemTools, createDocumentTools, createPlanTools, createBacklogTools, createAnchorTools, createArtifactTools, createEpisodeTools, createImageTools, } from './tools/index.js';
6
6
  // SQLite implementations (concrete repositories)
7
7
  export { createSQLiteRepositories, SQLiteProjectRepository, SQLiteWorkItemRepository, SQLiteDocumentRepository, SQLitePlanRepository, SQLiteCommentRepository, getDatabase, closeDatabase, closeAllDatabases, databaseExists, SCHEMA_VERSION, SCHEMA_SQL, } from './sqlite/index.js';
8
8
  // File-based anchor service (shared by CLI and Desktop)
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Image Tools — View image files for visual analysis.
3
+ *
4
+ * 1 tool: view_image
5
+ *
6
+ * Returns image data as imageBlocks on ToolExecutionResult, which the agent
7
+ * injects as sibling content blocks alongside the tool_result message.
8
+ * This lets vision-capable LLMs see the image.
9
+ */
10
+ /**
11
+ * Max dimension for resizing. Claude recommends 1568px max.
12
+ * Resizing is optional — only applied if a resizer function is provided.
13
+ */
14
+ export declare const DEFAULT_MAX_DIMENSION = 1568;
15
+ /**
16
+ * Optional image resizer function. Provided by the host environment
17
+ * (e.g., Electron's nativeImage, sharp, etc.)
18
+ */
19
+ export interface ImageResizer {
20
+ resize(data: Uint8Array, maxDimension: number): Promise<{
21
+ data: Uint8Array;
22
+ width: number;
23
+ height: number;
24
+ mediaType: string;
25
+ }>;
26
+ }
27
+ export interface ImageToolsConfig {
28
+ /** Working directory for resolving relative paths */
29
+ cwd?: string;
30
+ /** Optional image resizer (e.g., nativeImage in Electron) */
31
+ resizer?: ImageResizer;
32
+ /** Max dimension for resize (default: 1568) */
33
+ maxDimension?: number;
34
+ }
35
+ export declare function createImageTools(config?: ImageToolsConfig): readonly [import("@compilr-dev/agents").Tool<{
36
+ path: string;
37
+ }>];
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Image Tools — View image files for visual analysis.
3
+ *
4
+ * 1 tool: view_image
5
+ *
6
+ * Returns image data as imageBlocks on ToolExecutionResult, which the agent
7
+ * injects as sibling content blocks alongside the tool_result message.
8
+ * This lets vision-capable LLMs see the image.
9
+ */
10
+ import * as fs from 'node:fs';
11
+ import * as path from 'node:path';
12
+ import { defineTool, createErrorResult } from '@compilr-dev/agents';
13
+ /** Supported image MIME types */
14
+ const IMAGE_EXTENSIONS = {
15
+ '.png': 'image/png',
16
+ '.jpg': 'image/jpeg',
17
+ '.jpeg': 'image/jpeg',
18
+ '.gif': 'image/gif',
19
+ '.webp': 'image/webp',
20
+ };
21
+ /** Max file size: 10MB (base64 will be ~13MB, well within API limits) */
22
+ const MAX_FILE_SIZE = 10 * 1024 * 1024;
23
+ /**
24
+ * Max dimension for resizing. Claude recommends 1568px max.
25
+ * Resizing is optional — only applied if a resizer function is provided.
26
+ */
27
+ export const DEFAULT_MAX_DIMENSION = 1568;
28
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
29
+ export function createImageTools(config = {}) {
30
+ const cwd = config.cwd ?? process.cwd();
31
+ const maxDimension = config.maxDimension ?? DEFAULT_MAX_DIMENSION;
32
+ const viewImageTool = defineTool({
33
+ name: 'view_image',
34
+ description: 'View an image file for visual analysis. Returns the image so you can see it. ' +
35
+ 'Supports PNG, JPEG, GIF, and WebP formats.',
36
+ inputSchema: {
37
+ type: 'object',
38
+ properties: {
39
+ path: {
40
+ type: 'string',
41
+ description: 'Path to the image file (absolute or relative to working directory)',
42
+ },
43
+ },
44
+ required: ['path'],
45
+ },
46
+ execute: async (input) => {
47
+ // Resolve path
48
+ const filePath = path.isAbsolute(input.path) ? input.path : path.resolve(cwd, input.path);
49
+ // Validate file exists
50
+ if (!fs.existsSync(filePath)) {
51
+ return createErrorResult(`File not found: ${input.path}`);
52
+ }
53
+ // Validate extension
54
+ const ext = path.extname(filePath).toLowerCase();
55
+ const mediaType = IMAGE_EXTENSIONS[ext];
56
+ if (!mediaType) {
57
+ const supported = Object.keys(IMAGE_EXTENSIONS).join(', ');
58
+ return createErrorResult(`Unsupported image format: ${ext}. Supported formats: ${supported}`);
59
+ }
60
+ // Check file size
61
+ const stat = fs.statSync(filePath);
62
+ if (stat.size > MAX_FILE_SIZE) {
63
+ const sizeMB = (stat.size / (1024 * 1024)).toFixed(1);
64
+ return createErrorResult(`Image too large: ${sizeMB}MB (max 10MB)`);
65
+ }
66
+ // Read file
67
+ let imageData = fs.readFileSync(filePath);
68
+ let finalMediaType = mediaType;
69
+ let width;
70
+ let height;
71
+ // Optional resize
72
+ if (config.resizer) {
73
+ try {
74
+ const resized = await config.resizer.resize(imageData, maxDimension);
75
+ imageData = resized.data;
76
+ width = resized.width;
77
+ height = resized.height;
78
+ finalMediaType = resized.mediaType;
79
+ }
80
+ catch {
81
+ // Resize failed — use original data
82
+ }
83
+ }
84
+ const base64 = Buffer.from(imageData).toString('base64');
85
+ const filename = path.basename(filePath);
86
+ return {
87
+ success: true,
88
+ result: `Image loaded: ${filename} (${finalMediaType})`,
89
+ imageBlocks: [
90
+ {
91
+ data: base64,
92
+ mediaType: finalMediaType,
93
+ filename,
94
+ width,
95
+ height,
96
+ },
97
+ ],
98
+ };
99
+ },
100
+ });
101
+ return [viewImageTool];
102
+ }
@@ -1,20 +1,22 @@
1
1
  /**
2
2
  * Platform Tools — Factory function for all platform tools.
3
3
  *
4
- * Returns up to 33 tool definitions operating against async PlatformContext.
4
+ * Returns up to 34 tool definitions operating against async PlatformContext.
5
5
  * - 25 DB tools (always): project, workitem (incl. comment), document, plan, backlog
6
+ * - 1 image tool (always): view_image
6
7
  * - 3 anchor tools (if ctx.anchors provided)
7
8
  * - 4 artifact tools (if ctx.artifacts provided)
8
9
  * - 1 episode tool (if ctx.episodes provided)
9
10
  */
10
11
  import type { Tool } from '@compilr-dev/agents';
11
12
  import type { PlatformToolsConfig } from '../context.js';
13
+ import type { ImageToolsConfig } from './image-tools.js';
12
14
  /**
13
15
  * Create all platform tools operating against the given context.
14
- * Returns 24 DB tools unconditionally, plus up to 8 service-based tools
15
- * if the optional anchors/artifacts/episodes services are provided.
16
+ * Returns 25 DB tools + 1 image tool unconditionally, plus up to 8 service-based
17
+ * tools if the optional anchors/artifacts/episodes services are provided.
16
18
  */
17
- export declare function createPlatformTools(config: PlatformToolsConfig): Tool<never>[];
19
+ export declare function createPlatformTools(config: PlatformToolsConfig, imageConfig?: ImageToolsConfig): Tool<never>[];
18
20
  export { createProjectTools } from './project-tools.js';
19
21
  export { createWorkItemTools } from './workitem-tools.js';
20
22
  export { createDocumentTools } from './document-tools.js';
@@ -23,3 +25,5 @@ export { createBacklogTools } from './backlog-tools.js';
23
25
  export { createAnchorTools } from './anchor-tools.js';
24
26
  export { createArtifactTools } from './artifact-tools.js';
25
27
  export { createEpisodeTools } from './episode-tools.js';
28
+ export { createImageTools } from './image-tools.js';
29
+ export type { ImageToolsConfig, ImageResizer } from './image-tools.js';
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Platform Tools — Factory function for all platform tools.
3
3
  *
4
- * Returns up to 33 tool definitions operating against async PlatformContext.
4
+ * Returns up to 34 tool definitions operating against async PlatformContext.
5
5
  * - 25 DB tools (always): project, workitem (incl. comment), document, plan, backlog
6
+ * - 1 image tool (always): view_image
6
7
  * - 3 anchor tools (if ctx.anchors provided)
7
8
  * - 4 artifact tools (if ctx.artifacts provided)
8
9
  * - 1 episode tool (if ctx.episodes provided)
@@ -15,13 +16,14 @@ import { createBacklogTools } from './backlog-tools.js';
15
16
  import { createAnchorTools } from './anchor-tools.js';
16
17
  import { createArtifactTools } from './artifact-tools.js';
17
18
  import { createEpisodeTools } from './episode-tools.js';
19
+ import { createImageTools } from './image-tools.js';
18
20
  /**
19
21
  * Create all platform tools operating against the given context.
20
- * Returns 24 DB tools unconditionally, plus up to 8 service-based tools
21
- * if the optional anchors/artifacts/episodes services are provided.
22
+ * Returns 25 DB tools + 1 image tool unconditionally, plus up to 8 service-based
23
+ * tools if the optional anchors/artifacts/episodes services are provided.
22
24
  */
23
25
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
24
- export function createPlatformTools(config) {
26
+ export function createPlatformTools(config, imageConfig) {
25
27
  // Use Tool<never>[] to accept any Tool<T> — the generic parameter is only
26
28
  // relevant to execute() callers, not to the registry that stores them.
27
29
  const tools = [
@@ -30,6 +32,7 @@ export function createPlatformTools(config) {
30
32
  ...createDocumentTools(config),
31
33
  ...createPlanTools(config),
32
34
  ...createBacklogTools(config),
35
+ ...createImageTools({ cwd: config.cwd, ...imageConfig }),
33
36
  ];
34
37
  if (config.context.anchors) {
35
38
  tools.push(...createAnchorTools(config));
@@ -51,3 +54,4 @@ export { createBacklogTools } from './backlog-tools.js';
51
54
  export { createAnchorTools } from './anchor-tools.js';
52
55
  export { createArtifactTools } from './artifact-tools.js';
53
56
  export { createEpisodeTools } from './episode-tools.js';
57
+ export { createImageTools } from './image-tools.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilr-dev/sdk",
3
- "version": "0.9.6",
3
+ "version": "0.9.7",
4
4
  "description": "Universal agent runtime for building AI-powered applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",