@lumenflow/core 1.4.0 → 1.6.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.
Files changed (79) hide show
  1. package/README.md +362 -7
  2. package/dist/adapters/context-adapters.d.ts +90 -0
  3. package/dist/adapters/context-adapters.js +99 -0
  4. package/dist/adapters/index.d.ts +14 -0
  5. package/dist/adapters/index.js +18 -0
  6. package/dist/adapters/recovery-adapters.d.ts +40 -0
  7. package/dist/adapters/recovery-adapters.js +43 -0
  8. package/dist/adapters/validation-adapters.d.ts +52 -0
  9. package/dist/adapters/validation-adapters.js +59 -0
  10. package/dist/agent-patterns-registry.d.ts +100 -2
  11. package/dist/agent-patterns-registry.js +124 -0
  12. package/dist/arg-parser.js +7 -0
  13. package/dist/branch-check.d.ts +32 -3
  14. package/dist/branch-check.js +81 -15
  15. package/dist/color-support.d.ts +32 -0
  16. package/dist/color-support.js +64 -0
  17. package/dist/context/context-computer.d.ts +46 -0
  18. package/dist/context/context-computer.js +125 -0
  19. package/dist/context/git-state-reader.d.ts +51 -0
  20. package/dist/context/git-state-reader.js +61 -0
  21. package/dist/context/index.d.ts +17 -0
  22. package/dist/context/index.js +17 -0
  23. package/dist/context/location-resolver.d.ts +48 -0
  24. package/dist/context/location-resolver.js +175 -0
  25. package/dist/context/wu-state-reader.d.ts +37 -0
  26. package/dist/context/wu-state-reader.js +76 -0
  27. package/dist/context-di.d.ts +184 -0
  28. package/dist/context-di.js +178 -0
  29. package/dist/context-validation-integration.d.ts +77 -0
  30. package/dist/context-validation-integration.js +157 -0
  31. package/dist/cycle-detector.d.ts +51 -0
  32. package/dist/cycle-detector.js +89 -0
  33. package/dist/dependency-graph.js +1 -11
  34. package/dist/domain/context.schemas.d.ts +147 -0
  35. package/dist/domain/context.schemas.js +126 -0
  36. package/dist/domain/index.d.ts +14 -0
  37. package/dist/domain/index.js +18 -0
  38. package/dist/domain/recovery.schemas.d.ts +115 -0
  39. package/dist/domain/recovery.schemas.js +83 -0
  40. package/dist/domain/validation.schemas.d.ts +146 -0
  41. package/dist/domain/validation.schemas.js +114 -0
  42. package/dist/index.d.ts +17 -0
  43. package/dist/index.js +47 -0
  44. package/dist/lumenflow-config-schema.d.ts +47 -0
  45. package/dist/lumenflow-config-schema.js +84 -4
  46. package/dist/ports/context.ports.d.ts +135 -0
  47. package/dist/ports/context.ports.js +21 -0
  48. package/dist/ports/index.d.ts +14 -0
  49. package/dist/ports/index.js +14 -0
  50. package/dist/ports/recovery.ports.d.ts +58 -0
  51. package/dist/ports/recovery.ports.js +17 -0
  52. package/dist/ports/validation.ports.d.ts +74 -0
  53. package/dist/ports/validation.ports.js +17 -0
  54. package/dist/recovery/index.d.ts +11 -0
  55. package/dist/recovery/index.js +11 -0
  56. package/dist/recovery/recovery-analyzer.d.ts +66 -0
  57. package/dist/recovery/recovery-analyzer.js +129 -0
  58. package/dist/usecases/analyze-recovery.usecase.d.ts +42 -0
  59. package/dist/usecases/analyze-recovery.usecase.js +45 -0
  60. package/dist/usecases/compute-context.usecase.d.ts +62 -0
  61. package/dist/usecases/compute-context.usecase.js +101 -0
  62. package/dist/usecases/index.d.ts +14 -0
  63. package/dist/usecases/index.js +18 -0
  64. package/dist/usecases/validate-command.usecase.d.ts +55 -0
  65. package/dist/usecases/validate-command.usecase.js +154 -0
  66. package/dist/validation/command-registry.d.ts +38 -0
  67. package/dist/validation/command-registry.js +229 -0
  68. package/dist/validation/index.d.ts +15 -0
  69. package/dist/validation/index.js +15 -0
  70. package/dist/validation/types.d.ts +135 -0
  71. package/dist/validation/types.js +11 -0
  72. package/dist/validation/validate-command.d.ts +27 -0
  73. package/dist/validation/validate-command.js +160 -0
  74. package/dist/wu-constants.d.ts +136 -0
  75. package/dist/wu-constants.js +124 -0
  76. package/dist/wu-done-preflight.js +8 -1
  77. package/dist/wu-helpers.d.ts +5 -1
  78. package/dist/wu-helpers.js +12 -1
  79. package/package.json +3 -6
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Context Ports
3
+ *
4
+ * WU-1093: INIT-002 Phase 1 - Define ports and domain schemas
5
+ *
6
+ * Port interfaces for context-aware validation system.
7
+ * These abstractions allow external users to inject custom implementations.
8
+ *
9
+ * Hexagonal Architecture - Input Ports:
10
+ * - ILocationResolver: Detect main checkout vs worktree
11
+ * - IGitStateReader: Read git branch, dirty state, ahead/behind
12
+ * - IWuStateReader: Read WU state from YAML and state store
13
+ *
14
+ * Current Implementations:
15
+ * - resolveLocation (location-resolver.ts)
16
+ * - readGitState (git-state-reader.ts)
17
+ * - readWuState (wu-state-reader.ts)
18
+ *
19
+ * @module ports/context
20
+ */
21
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Ports Index
3
+ *
4
+ * WU-1093: INIT-002 Phase 1 - Define ports and domain schemas
5
+ *
6
+ * Re-exports all port interfaces for the context-aware validation system.
7
+ *
8
+ * @module ports
9
+ */
10
+ export * from './context.ports.js';
11
+ export * from './validation.ports.js';
12
+ export * from './recovery.ports.js';
13
+ export * from './metrics-collector.port.js';
14
+ export * from './dashboard-renderer.port.js';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Ports Index
3
+ *
4
+ * WU-1093: INIT-002 Phase 1 - Define ports and domain schemas
5
+ *
6
+ * Re-exports all port interfaces for the context-aware validation system.
7
+ *
8
+ * @module ports
9
+ */
10
+ export * from './context.ports.js';
11
+ export * from './validation.ports.js';
12
+ export * from './recovery.ports.js';
13
+ export * from './metrics-collector.port.js';
14
+ export * from './dashboard-renderer.port.js';
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Recovery Ports
3
+ *
4
+ * WU-1093: INIT-002 Phase 1 - Define ports and domain schemas
5
+ *
6
+ * Port interfaces for recovery-related operations.
7
+ * These abstractions allow external users to inject custom implementations.
8
+ *
9
+ * Hexagonal Architecture - Input Ports:
10
+ * - IRecoveryAnalyzer: Analyze WU state issues and suggest recovery actions
11
+ *
12
+ * Current Implementations:
13
+ * - analyzeRecovery (recovery-analyzer.ts)
14
+ *
15
+ * @module ports/recovery
16
+ */
17
+ import type { WuContext } from '../validation/types.js';
18
+ import type { RecoveryAnalysis } from '../recovery/recovery-analyzer.js';
19
+ /**
20
+ * Recovery Analyzer Port Interface
21
+ *
22
+ * Analyzes WU context to detect state inconsistencies and suggests
23
+ * appropriate recovery actions.
24
+ *
25
+ * Issue types detected:
26
+ * - Partial claim: worktree exists but status is ready
27
+ * - Orphan claim: status is in_progress but worktree missing
28
+ * - Inconsistent state: YAML and state store disagree
29
+ * - Orphan branch: branch exists but worktree missing
30
+ * - Stale lock: lock file from old session
31
+ * - Leftover worktree: WU is done but worktree exists
32
+ *
33
+ * @example
34
+ * // Custom implementation for testing
35
+ * const mockAnalyzer: IRecoveryAnalyzer = {
36
+ * analyzeRecovery: async (context) => ({
37
+ * hasIssues: false,
38
+ * issues: [],
39
+ * actions: [],
40
+ * wuId: context.wu?.id ?? null,
41
+ * }),
42
+ * };
43
+ *
44
+ * @example
45
+ * // Using default implementation
46
+ * import { analyzeRecovery } from './recovery/recovery-analyzer.js';
47
+ * const analyzer: IRecoveryAnalyzer = { analyzeRecovery };
48
+ */
49
+ export interface IRecoveryAnalyzer {
50
+ /**
51
+ * Analyze context for recovery issues.
52
+ *
53
+ * @param context - Current WU context
54
+ * @returns Promise<RecoveryAnalysis> - Recovery analysis with issues and suggested actions
55
+ */
56
+ analyzeRecovery(context: WuContext): Promise<RecoveryAnalysis>;
57
+ }
58
+ export type { WuContext, RecoveryAnalysis };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Recovery Ports
3
+ *
4
+ * WU-1093: INIT-002 Phase 1 - Define ports and domain schemas
5
+ *
6
+ * Port interfaces for recovery-related operations.
7
+ * These abstractions allow external users to inject custom implementations.
8
+ *
9
+ * Hexagonal Architecture - Input Ports:
10
+ * - IRecoveryAnalyzer: Analyze WU state issues and suggest recovery actions
11
+ *
12
+ * Current Implementations:
13
+ * - analyzeRecovery (recovery-analyzer.ts)
14
+ *
15
+ * @module ports/recovery
16
+ */
17
+ export {};
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Validation Ports
3
+ *
4
+ * WU-1093: INIT-002 Phase 1 - Define ports and domain schemas
5
+ *
6
+ * Port interfaces for validation-related operations.
7
+ * These abstractions allow external users to inject custom implementations.
8
+ *
9
+ * Hexagonal Architecture - Input Ports:
10
+ * - ICommandRegistry: Lookup command definitions and validate commands
11
+ *
12
+ * Current Implementations:
13
+ * - COMMAND_REGISTRY, getCommandDefinition, getValidCommandsForContext (command-registry.ts)
14
+ *
15
+ * @module ports/validation
16
+ */
17
+ import type { CommandDefinition, WuContext } from '../validation/types.js';
18
+ /**
19
+ * Command Registry Port Interface
20
+ *
21
+ * Provides command definitions and validation logic for wu:* commands.
22
+ * Allows looking up command requirements and determining valid commands
23
+ * for a given context.
24
+ *
25
+ * @example
26
+ * // Custom implementation for testing
27
+ * const mockRegistry: ICommandRegistry = {
28
+ * getCommandDefinition: (cmd) => cmd === 'wu:done' ? {...} : null,
29
+ * getValidCommandsForContext: (ctx) => [...],
30
+ * getAllCommands: () => [...],
31
+ * };
32
+ *
33
+ * @example
34
+ * // Using default implementation
35
+ * import {
36
+ * getCommandDefinition,
37
+ * getValidCommandsForContext,
38
+ * COMMAND_REGISTRY,
39
+ * } from './validation/command-registry.js';
40
+ *
41
+ * const registry: ICommandRegistry = {
42
+ * getCommandDefinition,
43
+ * getValidCommandsForContext,
44
+ * getAllCommands: () => Array.from(COMMAND_REGISTRY.values()),
45
+ * };
46
+ */
47
+ export interface ICommandRegistry {
48
+ /**
49
+ * Get command definition by name.
50
+ *
51
+ * @param command - Command name (e.g., 'wu:create', 'wu:done')
52
+ * @returns CommandDefinition or null if not found
53
+ */
54
+ getCommandDefinition(command: string): CommandDefinition | null;
55
+ /**
56
+ * Get all commands valid for the current context.
57
+ *
58
+ * A command is valid if:
59
+ * - Location requirement is satisfied (or null = any)
60
+ * - WU status requirement is satisfied (or null = no WU required)
61
+ * - All error-severity predicates pass
62
+ *
63
+ * @param context - Current WU context
64
+ * @returns Array of valid CommandDefinitions
65
+ */
66
+ getValidCommandsForContext(context: WuContext): CommandDefinition[];
67
+ /**
68
+ * Get all registered command definitions.
69
+ *
70
+ * @returns Array of all CommandDefinitions
71
+ */
72
+ getAllCommands(): CommandDefinition[];
73
+ }
74
+ export type { CommandDefinition, WuContext };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Validation Ports
3
+ *
4
+ * WU-1093: INIT-002 Phase 1 - Define ports and domain schemas
5
+ *
6
+ * Port interfaces for validation-related operations.
7
+ * These abstractions allow external users to inject custom implementations.
8
+ *
9
+ * Hexagonal Architecture - Input Ports:
10
+ * - ICommandRegistry: Lookup command definitions and validate commands
11
+ *
12
+ * Current Implementations:
13
+ * - COMMAND_REGISTRY, getCommandDefinition, getValidCommandsForContext (command-registry.ts)
14
+ *
15
+ * @module ports/validation
16
+ */
17
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Recovery Module
3
+ *
4
+ * WU-1090: Context-aware state machine for WU lifecycle commands
5
+ *
6
+ * Exports:
7
+ * - Recovery analysis (detect issues, suggest actions)
8
+ *
9
+ * @module
10
+ */
11
+ export * from './recovery-analyzer.js';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Recovery Module
3
+ *
4
+ * WU-1090: Context-aware state machine for WU lifecycle commands
5
+ *
6
+ * Exports:
7
+ * - Recovery analysis (detect issues, suggest actions)
8
+ *
9
+ * @module
10
+ */
11
+ export * from './recovery-analyzer.js';
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Recovery Analyzer for WU State Issues
3
+ *
4
+ * WU-1090: Context-aware state machine for WU lifecycle commands
5
+ *
6
+ * Analyzes WU context to detect state inconsistencies and suggests
7
+ * appropriate recovery actions.
8
+ *
9
+ * Issue types detected:
10
+ * - Partial claim: worktree exists but status is ready
11
+ * - Orphan claim: status is in_progress but worktree missing
12
+ * - Inconsistent state: YAML and state store disagree
13
+ * - Orphan branch: branch exists but worktree missing
14
+ * - Stale lock: lock file from old session
15
+ * - Leftover worktree: WU is done but worktree exists
16
+ *
17
+ * @module
18
+ */
19
+ import { type RecoveryActionType, type RecoveryIssueCode } from '../wu-constants.js';
20
+ import type { WuContext } from '../validation/types.js';
21
+ /**
22
+ * Issue detected during recovery analysis.
23
+ */
24
+ export interface RecoveryIssue {
25
+ /** Issue code from RECOVERY_ISSUES */
26
+ code: RecoveryIssueCode;
27
+ /** Human-readable description */
28
+ description: string;
29
+ /** Additional context for the issue */
30
+ context?: Record<string, unknown>;
31
+ }
32
+ /**
33
+ * Suggested recovery action.
34
+ */
35
+ export interface WuRecoveryAction {
36
+ /** Action type from RECOVERY_ACTIONS */
37
+ type: RecoveryActionType;
38
+ /** Human-readable description of what this action does */
39
+ description: string;
40
+ /** Command to execute (copy-paste ready) */
41
+ command: string;
42
+ /** Whether this action requires --force flag */
43
+ requiresForce: boolean;
44
+ /** Warning message if any */
45
+ warning?: string;
46
+ }
47
+ /**
48
+ * Result of recovery analysis.
49
+ */
50
+ export interface RecoveryAnalysis {
51
+ /** Whether any issues were found */
52
+ hasIssues: boolean;
53
+ /** List of detected issues */
54
+ issues: RecoveryIssue[];
55
+ /** Suggested recovery actions */
56
+ actions: WuRecoveryAction[];
57
+ /** WU ID analyzed */
58
+ wuId: string | null;
59
+ }
60
+ /**
61
+ * Analyze context for recovery issues.
62
+ *
63
+ * @param context - Current WU context
64
+ * @returns Recovery analysis with issues and suggested actions
65
+ */
66
+ export declare function analyzeRecovery(context: WuContext): Promise<RecoveryAnalysis>;
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Recovery Analyzer for WU State Issues
3
+ *
4
+ * WU-1090: Context-aware state machine for WU lifecycle commands
5
+ *
6
+ * Analyzes WU context to detect state inconsistencies and suggests
7
+ * appropriate recovery actions.
8
+ *
9
+ * Issue types detected:
10
+ * - Partial claim: worktree exists but status is ready
11
+ * - Orphan claim: status is in_progress but worktree missing
12
+ * - Inconsistent state: YAML and state store disagree
13
+ * - Orphan branch: branch exists but worktree missing
14
+ * - Stale lock: lock file from old session
15
+ * - Leftover worktree: WU is done but worktree exists
16
+ *
17
+ * @module
18
+ */
19
+ import { existsSync } from 'node:fs';
20
+ import { join } from 'node:path';
21
+ import { CONTEXT_VALIDATION, WU_STATUS, DEFAULTS, toKebab, } from '../wu-constants.js';
22
+ const { RECOVERY_ISSUES, RECOVERY_ACTIONS } = CONTEXT_VALIDATION;
23
+ /**
24
+ * Get expected worktree path for a WU.
25
+ */
26
+ function getExpectedWorktreePath(mainCheckout, lane, wuId) {
27
+ const laneKebab = toKebab(lane);
28
+ const wuIdLower = wuId.toLowerCase();
29
+ return join(mainCheckout, DEFAULTS.WORKTREES_DIR, `${laneKebab}-${wuIdLower}`);
30
+ }
31
+ /**
32
+ * Check if worktree exists for a WU.
33
+ */
34
+ function worktreeExists(mainCheckout, lane, wuId) {
35
+ const worktreePath = getExpectedWorktreePath(mainCheckout, lane, wuId);
36
+ return existsSync(worktreePath);
37
+ }
38
+ /**
39
+ * Analyze context for recovery issues.
40
+ *
41
+ * @param context - Current WU context
42
+ * @returns Recovery analysis with issues and suggested actions
43
+ */
44
+ export async function analyzeRecovery(context) {
45
+ const issues = [];
46
+ const actions = [];
47
+ // No WU context means nothing to analyze
48
+ if (!context.wu) {
49
+ return {
50
+ hasIssues: false,
51
+ issues: [],
52
+ actions: [],
53
+ wuId: null,
54
+ };
55
+ }
56
+ const { wu } = context;
57
+ const mainCheckout = context.location.mainCheckout;
58
+ const hasWorktree = worktreeExists(mainCheckout, wu.lane, wu.id);
59
+ const worktreePath = getExpectedWorktreePath(mainCheckout, wu.lane, wu.id);
60
+ // Check for partial claim: worktree exists but status is ready
61
+ if (hasWorktree && wu.status === WU_STATUS.READY) {
62
+ issues.push({
63
+ code: RECOVERY_ISSUES.PARTIAL_CLAIM,
64
+ description: `Worktree exists for ${wu.id} but status is 'ready'. The claim may have been interrupted.`,
65
+ context: { worktreePath, status: wu.status },
66
+ });
67
+ actions.push({
68
+ type: RECOVERY_ACTIONS.RESUME,
69
+ description: 'Reconcile state and continue working (preserves work)',
70
+ command: `pnpm wu:recover --id ${wu.id} --action resume`,
71
+ requiresForce: false,
72
+ });
73
+ actions.push({
74
+ type: RECOVERY_ACTIONS.RESET,
75
+ description: 'Discard worktree and reset WU to ready',
76
+ command: `pnpm wu:recover --id ${wu.id} --action reset`,
77
+ requiresForce: false,
78
+ warning: 'This will discard any uncommitted work in the worktree',
79
+ });
80
+ }
81
+ // Check for orphan claim: status is in_progress but worktree missing
82
+ if (!hasWorktree && wu.status === WU_STATUS.IN_PROGRESS) {
83
+ issues.push({
84
+ code: RECOVERY_ISSUES.ORPHAN_CLAIM,
85
+ description: `${wu.id} is 'in_progress' but worktree is missing. The worktree may have been manually deleted.`,
86
+ context: { expectedPath: worktreePath, status: wu.status },
87
+ });
88
+ actions.push({
89
+ type: RECOVERY_ACTIONS.RESET,
90
+ description: 'Reset WU status back to ready for re-claiming',
91
+ command: `pnpm wu:recover --id ${wu.id} --action reset`,
92
+ requiresForce: false,
93
+ });
94
+ }
95
+ // Check for leftover worktree: WU is done but worktree exists
96
+ if (hasWorktree && wu.status === WU_STATUS.DONE) {
97
+ issues.push({
98
+ code: RECOVERY_ISSUES.LEFTOVER_WORKTREE,
99
+ description: `${wu.id} is 'done' but worktree still exists. The cleanup may have failed.`,
100
+ context: { worktreePath, status: wu.status },
101
+ });
102
+ actions.push({
103
+ type: RECOVERY_ACTIONS.CLEANUP,
104
+ description: 'Remove leftover worktree for completed WU',
105
+ command: `pnpm wu:recover --id ${wu.id} --action cleanup`,
106
+ requiresForce: false,
107
+ });
108
+ }
109
+ // Check for inconsistent state
110
+ if (!wu.isConsistent && wu.inconsistencyReason) {
111
+ issues.push({
112
+ code: RECOVERY_ISSUES.INCONSISTENT_STATE,
113
+ description: wu.inconsistencyReason,
114
+ context: { wuId: wu.id },
115
+ });
116
+ actions.push({
117
+ type: RECOVERY_ACTIONS.RESET,
118
+ description: 'Reconcile YAML and state store',
119
+ command: `pnpm wu:recover --id ${wu.id} --action reset`,
120
+ requiresForce: false,
121
+ });
122
+ }
123
+ return {
124
+ hasIssues: issues.length > 0,
125
+ issues,
126
+ actions,
127
+ wuId: wu.id,
128
+ };
129
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * AnalyzeRecoveryUseCase
3
+ *
4
+ * WU-1094: INIT-002 Phase 2 - Implement adapters and dependency injection
5
+ *
6
+ * Use case for analyzing WU state and suggesting recovery actions.
7
+ * Uses constructor injection for recovery analyzer dependency.
8
+ *
9
+ * Hexagonal Architecture - Application Layer
10
+ * - Depends on port interface (IRecoveryAnalyzer)
11
+ * - Does NOT import from infrastructure layer
12
+ *
13
+ * @module usecases/analyze-recovery.usecase
14
+ */
15
+ import type { IRecoveryAnalyzer, WuContext, RecoveryAnalysis } from '../ports/recovery.ports.js';
16
+ /**
17
+ * AnalyzeRecoveryUseCase
18
+ *
19
+ * Analyzes WU context to detect state inconsistencies and suggests
20
+ * recovery actions.
21
+ *
22
+ * @example
23
+ * // Using default analyzer via DI factory
24
+ * const useCase = createAnalyzeRecoveryUseCase();
25
+ * const analysis = await useCase.execute(context);
26
+ *
27
+ * @example
28
+ * // Using custom analyzer for testing
29
+ * const useCase = new AnalyzeRecoveryUseCase(mockAnalyzer);
30
+ * const analysis = await useCase.execute(context);
31
+ */
32
+ export declare class AnalyzeRecoveryUseCase {
33
+ private readonly recoveryAnalyzer;
34
+ constructor(recoveryAnalyzer: IRecoveryAnalyzer);
35
+ /**
36
+ * Execute the use case to analyze recovery issues.
37
+ *
38
+ * @param context - Current WU context
39
+ * @returns Promise<RecoveryAnalysis> - Analysis with issues and suggested actions
40
+ */
41
+ execute(context: WuContext): Promise<RecoveryAnalysis>;
42
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * AnalyzeRecoveryUseCase
3
+ *
4
+ * WU-1094: INIT-002 Phase 2 - Implement adapters and dependency injection
5
+ *
6
+ * Use case for analyzing WU state and suggesting recovery actions.
7
+ * Uses constructor injection for recovery analyzer dependency.
8
+ *
9
+ * Hexagonal Architecture - Application Layer
10
+ * - Depends on port interface (IRecoveryAnalyzer)
11
+ * - Does NOT import from infrastructure layer
12
+ *
13
+ * @module usecases/analyze-recovery.usecase
14
+ */
15
+ /**
16
+ * AnalyzeRecoveryUseCase
17
+ *
18
+ * Analyzes WU context to detect state inconsistencies and suggests
19
+ * recovery actions.
20
+ *
21
+ * @example
22
+ * // Using default analyzer via DI factory
23
+ * const useCase = createAnalyzeRecoveryUseCase();
24
+ * const analysis = await useCase.execute(context);
25
+ *
26
+ * @example
27
+ * // Using custom analyzer for testing
28
+ * const useCase = new AnalyzeRecoveryUseCase(mockAnalyzer);
29
+ * const analysis = await useCase.execute(context);
30
+ */
31
+ export class AnalyzeRecoveryUseCase {
32
+ recoveryAnalyzer;
33
+ constructor(recoveryAnalyzer) {
34
+ this.recoveryAnalyzer = recoveryAnalyzer;
35
+ }
36
+ /**
37
+ * Execute the use case to analyze recovery issues.
38
+ *
39
+ * @param context - Current WU context
40
+ * @returns Promise<RecoveryAnalysis> - Analysis with issues and suggested actions
41
+ */
42
+ async execute(context) {
43
+ return this.recoveryAnalyzer.analyzeRecovery(context);
44
+ }
45
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * ComputeContextUseCase
3
+ *
4
+ * WU-1094: INIT-002 Phase 2 - Implement adapters and dependency injection
5
+ *
6
+ * Use case for computing WU context by orchestrating multiple adapters.
7
+ * Uses constructor injection for all dependencies.
8
+ *
9
+ * Hexagonal Architecture - Application Layer
10
+ * - Depends on port interfaces (ILocationResolver, IGitStateReader, IWuStateReader)
11
+ * - Does NOT import from infrastructure layer
12
+ *
13
+ * @module usecases/compute-context.usecase
14
+ */
15
+ import type { ILocationResolver, IGitStateReader, IWuStateReader } from '../ports/context.ports.js';
16
+ import type { WuContext } from '../validation/types.js';
17
+ /**
18
+ * Options for computing WU context.
19
+ */
20
+ export interface ComputeContextOptions {
21
+ /** WU ID to look up (optional - will detect from worktree if not provided) */
22
+ wuId?: string;
23
+ /** Current working directory (defaults to process.cwd()) */
24
+ cwd?: string;
25
+ }
26
+ /**
27
+ * ComputeContextUseCase
28
+ *
29
+ * Orchestrates the computation of WU context by calling multiple adapters
30
+ * and assembling the unified context model.
31
+ *
32
+ * @example
33
+ * // Using default adapters via DI factory
34
+ * const useCase = createComputeContextUseCase();
35
+ * const context = await useCase.execute({ wuId: 'WU-1094' });
36
+ *
37
+ * @example
38
+ * // Using custom adapters for testing
39
+ * const useCase = new ComputeContextUseCase(
40
+ * mockLocationResolver,
41
+ * mockGitStateReader,
42
+ * mockWuStateReader,
43
+ * );
44
+ * const context = await useCase.execute({});
45
+ */
46
+ export declare class ComputeContextUseCase {
47
+ private readonly locationResolver;
48
+ private readonly gitStateReader;
49
+ private readonly wuStateReader;
50
+ constructor(locationResolver: ILocationResolver, gitStateReader: IGitStateReader, wuStateReader: IWuStateReader);
51
+ /**
52
+ * Execute the use case to compute WU context.
53
+ *
54
+ * @param options - Options including optional wuId and cwd
55
+ * @returns Promise<WuContext> - Computed WU context
56
+ */
57
+ execute(options?: ComputeContextOptions): Promise<WuContext>;
58
+ /**
59
+ * Get expected worktree path for a WU.
60
+ */
61
+ private getWorktreePath;
62
+ }