mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-03-19 10:43:08 +00:00
Add quick-add feature with improved workflows (#802)
* Changes from feature/quick-add * feat: Clarify system prompt and improve error handling across services. Address PR Feedback * feat: Improve PR description parsing and refactor event handling * feat: Add context options to pipeline orchestrator initialization * fix: Deduplicate React and handle CJS interop for use-sync-external-store Resolve "Cannot read properties of null (reading 'useState')" errors by deduplicating React/react-dom and ensuring use-sync-external-store is bundled together with React to prevent CJS packages from resolving to different React instances.
This commit is contained in:
@@ -64,6 +64,8 @@ interface AutoModeEventPayload {
|
||||
error?: string;
|
||||
errorType?: string;
|
||||
projectPath?: string;
|
||||
/** Status field present when type === 'feature_status_changed' */
|
||||
status?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,6 +77,28 @@ interface FeatureCreatedPayload {
|
||||
projectPath: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Feature status changed event payload structure
|
||||
*/
|
||||
interface FeatureStatusChangedPayload {
|
||||
featureId: string;
|
||||
projectPath: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to safely narrow AutoModeEventPayload to FeatureStatusChangedPayload
|
||||
*/
|
||||
function isFeatureStatusChangedPayload(
|
||||
payload: AutoModeEventPayload
|
||||
): payload is AutoModeEventPayload & FeatureStatusChangedPayload {
|
||||
return (
|
||||
typeof payload.featureId === 'string' &&
|
||||
typeof payload.projectPath === 'string' &&
|
||||
typeof payload.status === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event Hook Service
|
||||
*
|
||||
@@ -82,12 +106,30 @@ interface FeatureCreatedPayload {
|
||||
* Also stores events to history for debugging and replay.
|
||||
*/
|
||||
export class EventHookService {
|
||||
/** Feature status that indicates agent work is done and awaiting human review (tests skipped) */
|
||||
private static readonly STATUS_WAITING_APPROVAL = 'waiting_approval';
|
||||
/** Feature status that indicates agent work passed automated verification */
|
||||
private static readonly STATUS_VERIFIED = 'verified';
|
||||
|
||||
private emitter: EventEmitter | null = null;
|
||||
private settingsService: SettingsService | null = null;
|
||||
private eventHistoryService: EventHistoryService | null = null;
|
||||
private featureLoader: FeatureLoader | null = null;
|
||||
private unsubscribe: (() => void) | null = null;
|
||||
|
||||
/**
|
||||
* Track feature IDs that have already had hooks fired via auto_mode_feature_complete
|
||||
* to prevent double-firing when feature_status_changed also fires for the same feature.
|
||||
* Entries are automatically cleaned up after 30 seconds.
|
||||
*/
|
||||
private recentlyHandledFeatures = new Set<string>();
|
||||
|
||||
/**
|
||||
* Timer IDs for pending cleanup of recentlyHandledFeatures entries,
|
||||
* keyed by featureId. Stored so they can be cancelled in destroy().
|
||||
*/
|
||||
private recentlyHandledTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
||||
|
||||
/**
|
||||
* Initialize the service with event emitter, settings service, event history service, and feature loader
|
||||
*/
|
||||
@@ -122,6 +164,12 @@ export class EventHookService {
|
||||
this.unsubscribe();
|
||||
this.unsubscribe = null;
|
||||
}
|
||||
// Cancel all pending cleanup timers to avoid cross-session mutations
|
||||
for (const timerId of this.recentlyHandledTimers.values()) {
|
||||
clearTimeout(timerId);
|
||||
}
|
||||
this.recentlyHandledTimers.clear();
|
||||
this.recentlyHandledFeatures.clear();
|
||||
this.emitter = null;
|
||||
this.settingsService = null;
|
||||
this.eventHistoryService = null;
|
||||
@@ -140,14 +188,27 @@ export class EventHookService {
|
||||
switch (payload.type) {
|
||||
case 'auto_mode_feature_complete':
|
||||
trigger = payload.passes ? 'feature_success' : 'feature_error';
|
||||
// Track this feature so feature_status_changed doesn't double-fire hooks
|
||||
if (payload.featureId) {
|
||||
this.markFeatureHandled(payload.featureId);
|
||||
}
|
||||
break;
|
||||
case 'auto_mode_error':
|
||||
// Feature-level error (has featureId) vs auto-mode level error
|
||||
trigger = payload.featureId ? 'feature_error' : 'auto_mode_error';
|
||||
// Track this feature so feature_status_changed doesn't double-fire hooks
|
||||
if (payload.featureId) {
|
||||
this.markFeatureHandled(payload.featureId);
|
||||
}
|
||||
break;
|
||||
case 'auto_mode_idle':
|
||||
trigger = 'auto_mode_complete';
|
||||
break;
|
||||
case 'feature_status_changed':
|
||||
if (isFeatureStatusChangedPayload(payload)) {
|
||||
this.handleFeatureStatusChanged(payload);
|
||||
}
|
||||
return;
|
||||
default:
|
||||
// Other event types don't trigger hooks
|
||||
return;
|
||||
@@ -203,6 +264,74 @@ export class EventHookService {
|
||||
await this.executeHooksForTrigger('feature_created', context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle feature_status_changed events for non-auto-mode feature completion.
|
||||
*
|
||||
* Auto-mode features already emit auto_mode_feature_complete which triggers hooks.
|
||||
* This handler catches manual (non-auto-mode) feature completions by detecting
|
||||
* status transitions to completion states (verified, waiting_approval).
|
||||
*/
|
||||
private async handleFeatureStatusChanged(payload: FeatureStatusChangedPayload): Promise<void> {
|
||||
// Skip if this feature was already handled via auto_mode_feature_complete
|
||||
if (this.recentlyHandledFeatures.has(payload.featureId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let trigger: EventHookTrigger | null = null;
|
||||
|
||||
if (
|
||||
payload.status === EventHookService.STATUS_VERIFIED ||
|
||||
payload.status === EventHookService.STATUS_WAITING_APPROVAL
|
||||
) {
|
||||
trigger = 'feature_success';
|
||||
} else {
|
||||
// Only completion statuses trigger hooks from status changes
|
||||
return;
|
||||
}
|
||||
|
||||
// Load feature name
|
||||
let featureName: string | undefined = undefined;
|
||||
if (this.featureLoader) {
|
||||
try {
|
||||
const feature = await this.featureLoader.get(payload.projectPath, payload.featureId);
|
||||
if (feature?.title) {
|
||||
featureName = feature.title;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.warn(`Failed to load feature ${payload.featureId} for status change hook:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
const context: HookContext = {
|
||||
featureId: payload.featureId,
|
||||
featureName,
|
||||
projectPath: payload.projectPath,
|
||||
projectName: this.extractProjectName(payload.projectPath),
|
||||
timestamp: new Date().toISOString(),
|
||||
eventType: trigger,
|
||||
};
|
||||
|
||||
await this.executeHooksForTrigger(trigger, context, { passes: true });
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a feature as recently handled to prevent double-firing hooks.
|
||||
* Entries are cleaned up after 30 seconds.
|
||||
*/
|
||||
private markFeatureHandled(featureId: string): void {
|
||||
// Cancel any existing timer for this feature before setting a new one
|
||||
const existing = this.recentlyHandledTimers.get(featureId);
|
||||
if (existing !== undefined) {
|
||||
clearTimeout(existing);
|
||||
}
|
||||
this.recentlyHandledFeatures.add(featureId);
|
||||
const timerId = setTimeout(() => {
|
||||
this.recentlyHandledFeatures.delete(featureId);
|
||||
this.recentlyHandledTimers.delete(featureId);
|
||||
}, 30000);
|
||||
this.recentlyHandledTimers.set(featureId, timerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute all enabled hooks matching the given trigger and store event to history
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user