@artyfacts/claude 1.1.1 → 1.2.0

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/src/executor.ts CHANGED
@@ -3,9 +3,13 @@
3
3
  *
4
4
  * Executes tasks by shelling out to the Claude Code CLI (claude).
5
5
  * This uses the user's existing Claude Code authentication - no separate API key needed.
6
+ *
7
+ * Now supports fetching full context (organization, project, artifact, related sections)
8
+ * to provide Claude with the information needed to complete tasks effectively.
6
9
  */
7
10
 
8
11
  import { spawn } from 'child_process';
12
+ import { ContextFetcher, createContextFetcher, buildPromptWithContext, TaskFullContext } from './context';
9
13
 
10
14
  // ============================================================================
11
15
  // Types
@@ -37,6 +41,8 @@ export interface ExecutionResult {
37
41
  summary: string;
38
42
  /** Any error message if failed */
39
43
  error?: string;
44
+ /** The prompt that was used (for debugging) */
45
+ promptUsed?: string;
40
46
  }
41
47
 
42
48
  export interface ExecutorConfig {
@@ -46,6 +52,12 @@ export interface ExecutorConfig {
46
52
  timeout?: number;
47
53
  /** System prompt prefix */
48
54
  systemPromptPrefix?: string;
55
+ /** Artyfacts API base URL (for fetching context) */
56
+ baseUrl?: string;
57
+ /** Artyfacts API key (for fetching context) */
58
+ apiKey?: string;
59
+ /** Whether to use full context from API (default: true if apiKey provided) */
60
+ useFullContext?: boolean;
49
61
  }
50
62
 
51
63
  // ============================================================================
@@ -78,6 +90,7 @@ Format your response as follows:
78
90
 
79
91
  export class ClaudeExecutor {
80
92
  private config: Required<Pick<ExecutorConfig, 'timeout'>> & ExecutorConfig;
93
+ private contextFetcher: ContextFetcher | null = null;
81
94
 
82
95
  constructor(config: ExecutorConfig = {}) {
83
96
  this.config = {
@@ -85,15 +98,43 @@ export class ClaudeExecutor {
85
98
  timeout: config.timeout || DEFAULT_TIMEOUT,
86
99
  claudePath: config.claudePath || 'claude',
87
100
  };
101
+
102
+ // Initialize context fetcher if API credentials provided
103
+ if (config.baseUrl && config.apiKey) {
104
+ this.contextFetcher = createContextFetcher({
105
+ baseUrl: config.baseUrl,
106
+ apiKey: config.apiKey,
107
+ });
108
+ }
88
109
  }
89
110
 
90
111
  /**
91
112
  * Execute a task using Claude Code CLI
113
+ *
114
+ * If full context is available (baseUrl + apiKey configured), fetches
115
+ * organization, project, artifact, and related sections for a rich prompt.
92
116
  */
93
117
  async execute(task: TaskContext): Promise<ExecutionResult> {
94
118
  try {
95
- // Build the prompt
96
- const prompt = this.buildTaskPrompt(task);
119
+ let prompt: string;
120
+ let fullContext: TaskFullContext | null = null;
121
+
122
+ // Try to fetch full context if configured
123
+ const useFullContext = this.config.useFullContext !== false && this.contextFetcher;
124
+
125
+ if (useFullContext) {
126
+ try {
127
+ fullContext = await this.contextFetcher!.fetchTaskContext(task.taskId);
128
+ prompt = buildPromptWithContext(fullContext);
129
+ console.log(' 📚 Using full context (org, project, artifact, related sections)');
130
+ } catch (contextError) {
131
+ console.warn(' ⚠️ Could not fetch full context, using minimal prompt');
132
+ console.warn(` ${contextError instanceof Error ? contextError.message : contextError}`);
133
+ prompt = this.buildTaskPrompt(task);
134
+ }
135
+ } else {
136
+ prompt = this.buildTaskPrompt(task);
137
+ }
97
138
 
98
139
  // Execute via Claude Code CLI
99
140
  const output = await this.runClaude(prompt);
@@ -105,6 +146,7 @@ export class ClaudeExecutor {
105
146
  success: true,
106
147
  output: content,
107
148
  summary,
149
+ promptUsed: prompt,
108
150
  };
109
151
  } catch (error) {
110
152
  const errorMessage = error instanceof Error ? error.message : String(error);
package/src/index.ts CHANGED
@@ -84,3 +84,20 @@ export {
84
84
  ArtyfactsListener,
85
85
  createListener,
86
86
  } from './listener';
87
+
88
+ // Context Fetcher - Types
89
+ export type {
90
+ TaskFullContext,
91
+ OrganizationContext,
92
+ ProjectContext,
93
+ ArtifactContext,
94
+ SectionContext,
95
+ ContextFetcherConfig,
96
+ } from './context';
97
+
98
+ // Context Fetcher - Functions
99
+ export {
100
+ ContextFetcher,
101
+ createContextFetcher,
102
+ buildPromptWithContext,
103
+ } from './context';