@compilr-dev/sdk 0.9.14 → 0.9.16

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.
@@ -53,7 +53,7 @@ export const CAPABILITY_PACKS = {
53
53
  interaction: {
54
54
  id: 'interaction',
55
55
  label: 'User Interaction',
56
- tools: ['ask_user', 'ask_user_simple', 'suggest'],
56
+ tools: ['ask_user', 'ask_user_simple', 'propose_alternatives', 'suggest'],
57
57
  readOnly: true,
58
58
  promptModules: [],
59
59
  estimatedPromptTokens: 0,
@@ -43,7 +43,8 @@ export function createCompressorHook(config) {
43
43
  if (compressed !== null && compressed.length < stdout.length) {
44
44
  const saved = stdout.length - compressed.length;
45
45
  const pct = Math.round((saved / stdout.length) * 100);
46
- console.log(`[compressor] bash "${command.slice(0, 40)}" ${String(stdout.length)} → ${String(compressed.length)} chars (${String(pct)}% saved)`); // eslint-disable-line no-console
46
+ // eslint-disable-next-line no-console
47
+ console.log(`[compressor] bash "${command.slice(0, 40)}" ${String(stdout.length)} → ${String(compressed.length)} chars (${String(pct)}% saved)`);
47
48
  return {
48
49
  result: {
49
50
  ...ctx.result,
package/dist/index.d.ts CHANGED
@@ -56,8 +56,8 @@ export type { SystemPromptContext, BuildResult, SystemPromptModule, ModuleCondit
56
56
  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, WorkItemComment, CreateCommentInput, UpdateCommentInput, IProjectRepository, IWorkItemRepository, IDocumentRepository, IPlanRepository, ICommentRepository, IAnchorService, IArtifactService, IEpisodeService, AnchorData, ArtifactType, ArtifactData, ArtifactSummaryData, WorkEpisode, ProjectWorkSummary, PlatformContext, PlatformToolsConfig, PlatformHooks, StepCriteria, } from './platform/index.js';
57
57
  export { createSQLiteRepositories, SQLiteProjectRepository, SQLiteWorkItemRepository, SQLiteDocumentRepository, SQLitePlanRepository, SQLiteCommentRepository, getDatabase, closeDatabase, closeAllDatabases, databaseExists, SCHEMA_VERSION, SCHEMA_SQL, } from './platform/index.js';
58
58
  export type { SQLiteRepositories, CreateSQLiteRepositoriesOptions, ProjectDeleteHooks, ProjectRecord, WorkItemRecord, ProjectDocumentRecord, WorkItemCommentRecord, } from './platform/index.js';
59
- export { createAskUserTool, createAskUserSimpleTool } from './tools/index.js';
60
- export type { AskUserQuestion, AskUserInput, AskUserResult, AskUserHandler, AskUserSimpleInput, AskUserSimpleResult, AskUserSimpleHandler, } from './tools/index.js';
59
+ export { createAskUserTool, createAskUserSimpleTool, createProposeAlternativesTool } from './tools/index.js';
60
+ export type { AskUserQuestion, AskUserInput, AskUserResult, AskUserHandler, AskUserSimpleInput, AskUserSimpleResult, AskUserSimpleHandler, Alternative, ProposeAlternativesInput, ProposeAlternativesResult, ProposeAlternativesHandler, } from './tools/index.js';
61
61
  export { detectProject, suggestProjectType, detectCommon } from './detection/index.js';
62
62
  export type { DetectProjectOptions, DetectionResult, ContentSummary } from './detection/index.js';
63
63
  export { createGuideTool, SHARED_GUIDE_ENTRIES, searchGuideEntries, topicToGuideEntry, } from './guide/index.js';
package/dist/index.js CHANGED
@@ -131,7 +131,7 @@ export { createSQLiteRepositories, SQLiteProjectRepository, SQLiteWorkItemReposi
131
131
  // =============================================================================
132
132
  // User Interaction Tools (ask_user, ask_user_simple)
133
133
  // =============================================================================
134
- export { createAskUserTool, createAskUserSimpleTool } from './tools/index.js';
134
+ export { createAskUserTool, createAskUserSimpleTool, createProposeAlternativesTool } from './tools/index.js';
135
135
  // =============================================================================
136
136
  // Project Detection (universal project content detection)
137
137
  // =============================================================================
@@ -105,6 +105,12 @@ export function createPlanTools(config, planModeCallbacks) {
105
105
  },
106
106
  execute: async (input) => {
107
107
  try {
108
+ // Guard: prevent agent from self-approving plans during plan mode
109
+ if (input.status === 'approved' &&
110
+ planModeCallbacks?.isPlanModeActive?.()) {
111
+ return createErrorResult('Cannot set status to "approved" directly during plan mode. ' +
112
+ 'Use plan_submit to submit your plan for user approval instead.');
113
+ }
108
114
  const updateInput = {};
109
115
  if (input.content !== undefined) {
110
116
  updateInput.content = input.content;
@@ -363,7 +369,8 @@ export function createPlanTools(config, planModeCallbacks) {
363
369
  // ---------------------------------------------------------------------------
364
370
  // plan_submit (requires callback from host app)
365
371
  // ---------------------------------------------------------------------------
366
- const planSubmitTool = planModeCallbacks
372
+ const onPlanSubmitFn = planModeCallbacks?.onPlanSubmit;
373
+ const planSubmitTool = onPlanSubmitFn
367
374
  ? defineTool({
368
375
  name: 'plan_submit',
369
376
  description: 'Submit a plan for user approval. Call this when your plan is ready for review. ' +
@@ -390,7 +397,7 @@ export function createPlanTools(config, planModeCallbacks) {
390
397
  return createErrorResult(`Plan ${String(input.plan_id)} not found`);
391
398
  }
392
399
  // Call host app's approval UI
393
- const result = await planModeCallbacks.onPlanSubmit({
400
+ const result = await onPlanSubmitFn({
394
401
  planId: input.plan_id,
395
402
  summary: input.summary,
396
403
  });
@@ -414,7 +421,8 @@ export function createPlanTools(config, planModeCallbacks) {
414
421
  // ---------------------------------------------------------------------------
415
422
  // plan_mode_exit (requires callback from host app)
416
423
  // ---------------------------------------------------------------------------
417
- const planModeExitTool = planModeCallbacks
424
+ const onPlanModeExitFn = planModeCallbacks?.onPlanModeExit;
425
+ const planModeExitTool = onPlanModeExitFn
418
426
  ? defineTool({
419
427
  name: 'plan_mode_exit',
420
428
  description: 'Exit plan mode without submitting a plan. Use this when the task is simple enough ' +
@@ -430,7 +438,7 @@ export function createPlanTools(config, planModeCallbacks) {
430
438
  required: ['reason'],
431
439
  },
432
440
  execute: async (input) => {
433
- await planModeCallbacks.onPlanModeExit({ reason: input.reason });
441
+ await onPlanModeExitFn({ reason: input.reason });
434
442
  return createSuccessResult({
435
443
  message: `Exited plan mode: ${input.reason}. Full tools now available.`,
436
444
  });
@@ -112,10 +112,10 @@ Suggest delegation when a task would benefit from focused expertise.`,
112
112
  // =============================================================================
113
113
  export const generalConfig = {
114
114
  id: 'general',
115
- label: 'General',
116
- description: 'Blank project — define your own workflow',
115
+ label: 'General Purpose',
116
+ description: 'Any project — define your own workflow',
117
117
  icon: 'FolderOpen',
118
- category: 'software',
118
+ category: 'general',
119
119
  phases: [],
120
120
  suggestedAgents: [],
121
121
  documentTemplates: [
@@ -76,7 +76,7 @@ export interface ProjectTypeConfig {
76
76
  /** Lucide icon name */
77
77
  icon: string;
78
78
  /** Category for grouping in type selector */
79
- category: 'software' | 'writing' | 'business' | 'education';
79
+ category: 'general' | 'software' | 'writing' | 'business' | 'education';
80
80
  /** Workflow phases (shown in project panel lifecycle) */
81
81
  phases: ProjectPhase[];
82
82
  /** Suggested agent roles (shown first in "Add Agent" dialog) */
@@ -140,7 +140,7 @@ IMPORTANT: Tool names are lowercase with underscores.
140
140
  - **File operations**: read_file, write_file, edit, glob, grep
141
141
  - **Shell**: bash (use run_in_background=true for long-running), bash_output, kill_shell
142
142
  - **Task management**: todo_write, todo_read
143
- - **User interaction**: ask_user, ask_user_simple
143
+ - **User interaction**: ask_user, ask_user_simple, propose_alternatives (present 2-3 options for comparison)
144
144
  - **Sub-agents**: task (types: explore, code-review, plan, debug, test-runner, refactor, security-audit, general)`,
145
145
  };
146
146
  /**
@@ -38,9 +38,11 @@ export interface PlanModeExitInfo {
38
38
  */
39
39
  export interface PlanModeCallbacks {
40
40
  /** Called when agent submits a plan for approval (shows approval UI) */
41
- onPlanSubmit: (info: PlanSubmitInfo) => Promise<PlanSubmitResult>;
41
+ onPlanSubmit?: (info: PlanSubmitInfo) => Promise<PlanSubmitResult>;
42
42
  /** Called when agent wants to exit plan mode without a plan */
43
- onPlanModeExit: (info: PlanModeExitInfo) => Promise<void>;
43
+ onPlanModeExit?: (info: PlanModeExitInfo) => Promise<void>;
44
+ /** Check if plan mode is currently active (used to guard plan_update from self-approval) */
45
+ isPlanModeActive?: () => boolean;
44
46
  }
45
47
  /**
46
48
  * System prompt section injected when plan mode is active.
@@ -51,7 +51,7 @@ export const SKILL_REQUIREMENTS = {
51
51
  },
52
52
  design: {
53
53
  required: ['ask_user', 'workitem_add'],
54
- optional: ['detect_project', 'document_save', 'edit'],
54
+ optional: ['propose_alternatives', 'detect_project', 'document_save', 'edit'],
55
55
  reason: 'Needs to gather requirements and create backlog',
56
56
  },
57
57
  refine: {
@@ -72,7 +72,7 @@ export const SKILL_REQUIREMENTS = {
72
72
  // Documentation skills
73
73
  architecture: {
74
74
  required: ['read_file', 'write_file', 'edit'],
75
- optional: ['backlog_read', 'ask_user', 'glob'],
75
+ optional: ['backlog_read', 'ask_user', 'propose_alternatives', 'glob'],
76
76
  reason: 'Creates architecture documents',
77
77
  },
78
78
  prd: {
@@ -21,6 +21,7 @@ const TOOL_NAMES = {
21
21
  // User interaction
22
22
  ASK_USER: 'ask_user',
23
23
  ASK_USER_SIMPLE: 'ask_user_simple',
24
+ PROPOSE_ALTERNATIVES: 'propose_alternatives',
24
25
  // Delegation
25
26
  DELEGATE: 'delegate',
26
27
  DELEGATE_BACKGROUND: 'delegate_background',
@@ -147,7 +148,7 @@ export const TOOL_GROUPS = {
147
148
  },
148
149
  interaction: {
149
150
  label: 'User Interaction',
150
- tools: [TOOL_NAMES.ASK_USER, TOOL_NAMES.ASK_USER_SIMPLE, TOOL_NAMES.SUGGEST],
151
+ tools: [TOOL_NAMES.ASK_USER, TOOL_NAMES.ASK_USER_SIMPLE, TOOL_NAMES.PROPOSE_ALTERNATIVES, TOOL_NAMES.SUGGEST],
151
152
  readOnly: true,
152
153
  tier: 'direct',
153
154
  },
@@ -5,4 +5,6 @@
5
5
  * The SDK defines schemas and types; consumers provide the UI.
6
6
  */
7
7
  export { createAskUserTool, createAskUserSimpleTool } from './ask-user-tools.js';
8
+ export { createProposeAlternativesTool } from './propose-alternatives-tool.js';
8
9
  export type { AskUserQuestion, AskUserInput, AskUserResult, AskUserHandler, AskUserSimpleInput, AskUserSimpleResult, AskUserSimpleHandler, } from './ask-user-tools.js';
10
+ export type { Alternative, ProposeAlternativesInput, ProposeAlternativesResult, ProposeAlternativesHandler, } from './propose-alternatives-tool.js';
@@ -5,3 +5,4 @@
5
5
  * The SDK defines schemas and types; consumers provide the UI.
6
6
  */
7
7
  export { createAskUserTool, createAskUserSimpleTool } from './ask-user-tools.js';
8
+ export { createProposeAlternativesTool } from './propose-alternatives-tool.js';
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Propose Alternatives Tool — Present 2-3 options for the user to compare and choose.
3
+ *
4
+ * Unlike ask_user (open-ended questions), this tool presents concrete alternatives
5
+ * with rich previews (code, markdown, mermaid) for side-by-side comparison.
6
+ *
7
+ * Factory pattern: the consumer (CLI, desktop) provides a handler callback that
8
+ * implements the UI. The SDK defines the tool schema and types.
9
+ */
10
+ import type { Tool } from '@compilr-dev/agents';
11
+ /** A single alternative to present */
12
+ export interface Alternative {
13
+ /** Short title: "Card Layout", "REST API" */
14
+ title: string;
15
+ /** 1-2 sentence explanation */
16
+ description: string;
17
+ /** Optional rich content for preview */
18
+ content?: string;
19
+ /** Content format for rendering */
20
+ contentType?: 'markdown' | 'code' | 'mermaid';
21
+ /** Language hint for code syntax highlighting (e.g., 'typescript', 'html') */
22
+ language?: string;
23
+ /** Pros of this alternative */
24
+ pros?: string[];
25
+ /** Cons of this alternative */
26
+ cons?: string[];
27
+ }
28
+ /** Input parameters for propose_alternatives tool */
29
+ export interface ProposeAlternativesInput {
30
+ /** What decision is being made */
31
+ question: string;
32
+ /** Optional context paragraph */
33
+ context?: string;
34
+ /** 2-3 alternatives to present */
35
+ alternatives: Alternative[];
36
+ }
37
+ /** Result from propose_alternatives tool */
38
+ export interface ProposeAlternativesResult {
39
+ /** 0-based index of chosen alternative */
40
+ chosenIndex: number;
41
+ /** Title of chosen alternative */
42
+ chosenTitle: string;
43
+ /** Optional user notes */
44
+ notes?: string;
45
+ /** User rejected all alternatives */
46
+ rejected: boolean;
47
+ }
48
+ /**
49
+ * Handler callback for propose_alternatives tool.
50
+ * The consumer provides the UI implementation.
51
+ */
52
+ export type ProposeAlternativesHandler = (input: ProposeAlternativesInput) => Promise<ProposeAlternativesResult>;
53
+ /**
54
+ * Create a propose_alternatives tool with a custom UI handler.
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const tool = createProposeAlternativesTool(async (input) => {
59
+ * // Show side-by-side dialog, wait for user choice
60
+ * return { chosenIndex: 0, chosenTitle: input.alternatives[0].title, rejected: false };
61
+ * });
62
+ * ```
63
+ */
64
+ export declare function createProposeAlternativesTool(handler: ProposeAlternativesHandler): Tool<ProposeAlternativesInput>;
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Propose Alternatives Tool — Present 2-3 options for the user to compare and choose.
3
+ *
4
+ * Unlike ask_user (open-ended questions), this tool presents concrete alternatives
5
+ * with rich previews (code, markdown, mermaid) for side-by-side comparison.
6
+ *
7
+ * Factory pattern: the consumer (CLI, desktop) provides a handler callback that
8
+ * implements the UI. The SDK defines the tool schema and types.
9
+ */
10
+ import { defineTool } from '@compilr-dev/agents';
11
+ // =============================================================================
12
+ // Factory
13
+ // =============================================================================
14
+ /**
15
+ * Create a propose_alternatives tool with a custom UI handler.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const tool = createProposeAlternativesTool(async (input) => {
20
+ * // Show side-by-side dialog, wait for user choice
21
+ * return { chosenIndex: 0, chosenTitle: input.alternatives[0].title, rejected: false };
22
+ * });
23
+ * ```
24
+ */
25
+ export function createProposeAlternativesTool(handler) {
26
+ return defineTool({
27
+ name: 'propose_alternatives',
28
+ description: 'Present 2-3 alternatives for the user to compare and choose from. ' +
29
+ 'Use when there are multiple valid approaches and the user\'s preference matters. ' +
30
+ 'Each alternative can include rich content (code, markdown, mermaid diagrams) for visual comparison. ' +
31
+ 'Include pros and cons to help the user decide. The user picks one or provides feedback.',
32
+ inputSchema: {
33
+ type: 'object',
34
+ properties: {
35
+ question: {
36
+ type: 'string',
37
+ description: 'What decision is being made (e.g., "Dashboard layout approach")',
38
+ },
39
+ context: {
40
+ type: 'string',
41
+ description: 'Optional background context for the decision',
42
+ },
43
+ alternatives: {
44
+ type: 'array',
45
+ description: '2-3 alternatives to present',
46
+ minItems: 2,
47
+ maxItems: 3,
48
+ items: {
49
+ type: 'object',
50
+ properties: {
51
+ title: {
52
+ type: 'string',
53
+ description: 'Short title (e.g., "Card Grid", "Data Table")',
54
+ },
55
+ description: {
56
+ type: 'string',
57
+ description: '1-2 sentence explanation of this approach',
58
+ },
59
+ content: {
60
+ type: 'string',
61
+ description: 'Optional rich content for preview (code, markdown, or mermaid source)',
62
+ },
63
+ contentType: {
64
+ type: 'string',
65
+ enum: ['markdown', 'code', 'mermaid'],
66
+ description: 'Content format for rendering',
67
+ },
68
+ language: {
69
+ type: 'string',
70
+ description: 'Language hint for code syntax highlighting (e.g., "typescript", "html")',
71
+ },
72
+ pros: {
73
+ type: 'array',
74
+ items: { type: 'string' },
75
+ description: 'Advantages of this alternative',
76
+ },
77
+ cons: {
78
+ type: 'array',
79
+ items: { type: 'string' },
80
+ description: 'Disadvantages of this alternative',
81
+ },
82
+ },
83
+ required: ['title', 'description'],
84
+ },
85
+ },
86
+ },
87
+ required: ['question', 'alternatives'],
88
+ },
89
+ execute: async (input) => {
90
+ try {
91
+ if (input.alternatives.length < 2) {
92
+ return { success: false, error: 'At least 2 alternatives are required' };
93
+ }
94
+ if (input.alternatives.length > 3) {
95
+ return { success: false, error: 'Maximum 3 alternatives allowed' };
96
+ }
97
+ const result = await handler(input);
98
+ if (result.rejected) {
99
+ return {
100
+ success: true,
101
+ result: {
102
+ chosen: null,
103
+ rejected: true,
104
+ feedback: result.notes ?? 'User rejected all alternatives',
105
+ },
106
+ };
107
+ }
108
+ return {
109
+ success: true,
110
+ result: {
111
+ chosen: result.chosenTitle,
112
+ chosenIndex: result.chosenIndex,
113
+ notes: result.notes,
114
+ rejected: false,
115
+ },
116
+ };
117
+ }
118
+ catch (err) {
119
+ return {
120
+ success: false,
121
+ error: `Failed to propose alternatives: ${err instanceof Error ? err.message : String(err)}`,
122
+ };
123
+ }
124
+ },
125
+ // Not silent — show in tool call history (this is substantive, not meta)
126
+ silent: false,
127
+ });
128
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compilr-dev/sdk",
3
- "version": "0.9.14",
3
+ "version": "0.9.16",
4
4
  "description": "Universal agent runtime for building AI-powered applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -62,6 +62,9 @@
62
62
  "better-sqlite3": "^11.0.0 || ^12.0.0"
63
63
  },
64
64
  "peerDependenciesMeta": {
65
+ "@compilr-dev/agents-coding": {
66
+ "optional": true
67
+ },
65
68
  "better-sqlite3": {
66
69
  "optional": true
67
70
  }