@lumenflow/core 1.5.0 → 2.0.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 (74) hide show
  1. package/README.md +325 -1
  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/context/context-computer.d.ts +46 -0
  11. package/dist/context/context-computer.js +125 -0
  12. package/dist/context/git-state-reader.d.ts +51 -0
  13. package/dist/context/git-state-reader.js +61 -0
  14. package/dist/context/index.d.ts +17 -0
  15. package/dist/context/index.js +17 -0
  16. package/dist/context/location-resolver.d.ts +48 -0
  17. package/dist/context/location-resolver.js +175 -0
  18. package/dist/context/wu-state-reader.d.ts +37 -0
  19. package/dist/context/wu-state-reader.js +76 -0
  20. package/dist/context-di.d.ts +184 -0
  21. package/dist/context-di.js +178 -0
  22. package/dist/context-validation-integration.d.ts +77 -0
  23. package/dist/context-validation-integration.js +157 -0
  24. package/dist/domain/context.schemas.d.ts +147 -0
  25. package/dist/domain/context.schemas.js +126 -0
  26. package/dist/domain/index.d.ts +14 -0
  27. package/dist/domain/index.js +18 -0
  28. package/dist/domain/recovery.schemas.d.ts +115 -0
  29. package/dist/domain/recovery.schemas.js +83 -0
  30. package/dist/domain/validation.schemas.d.ts +146 -0
  31. package/dist/domain/validation.schemas.js +114 -0
  32. package/dist/index.d.ts +17 -0
  33. package/dist/index.js +43 -0
  34. package/dist/lumenflow-config-schema.d.ts +41 -0
  35. package/dist/lumenflow-config-schema.js +37 -0
  36. package/dist/ports/context.ports.d.ts +135 -0
  37. package/dist/ports/context.ports.js +21 -0
  38. package/dist/ports/core-tools.ports.d.ts +266 -0
  39. package/dist/ports/core-tools.ports.js +21 -0
  40. package/dist/ports/git-validator.ports.d.ts +314 -0
  41. package/dist/ports/git-validator.ports.js +12 -0
  42. package/dist/ports/index.d.ts +20 -0
  43. package/dist/ports/index.js +20 -0
  44. package/dist/ports/recovery.ports.d.ts +58 -0
  45. package/dist/ports/recovery.ports.js +17 -0
  46. package/dist/ports/validation.ports.d.ts +74 -0
  47. package/dist/ports/validation.ports.js +17 -0
  48. package/dist/ports/wu-helpers.ports.d.ts +224 -0
  49. package/dist/ports/wu-helpers.ports.js +12 -0
  50. package/dist/recovery/index.d.ts +11 -0
  51. package/dist/recovery/index.js +11 -0
  52. package/dist/recovery/recovery-analyzer.d.ts +66 -0
  53. package/dist/recovery/recovery-analyzer.js +129 -0
  54. package/dist/usecases/analyze-recovery.usecase.d.ts +42 -0
  55. package/dist/usecases/analyze-recovery.usecase.js +45 -0
  56. package/dist/usecases/compute-context.usecase.d.ts +62 -0
  57. package/dist/usecases/compute-context.usecase.js +101 -0
  58. package/dist/usecases/index.d.ts +14 -0
  59. package/dist/usecases/index.js +18 -0
  60. package/dist/usecases/validate-command.usecase.d.ts +55 -0
  61. package/dist/usecases/validate-command.usecase.js +154 -0
  62. package/dist/validation/command-registry.d.ts +38 -0
  63. package/dist/validation/command-registry.js +229 -0
  64. package/dist/validation/index.d.ts +15 -0
  65. package/dist/validation/index.js +15 -0
  66. package/dist/validation/types.d.ts +135 -0
  67. package/dist/validation/types.js +11 -0
  68. package/dist/validation/validate-command.d.ts +27 -0
  69. package/dist/validation/validate-command.js +160 -0
  70. package/dist/wu-constants.d.ts +136 -0
  71. package/dist/wu-constants.js +124 -0
  72. package/dist/wu-helpers.d.ts +5 -1
  73. package/dist/wu-helpers.js +12 -1
  74. package/package.json +4 -2
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Validation Schemas
3
+ *
4
+ * WU-1093: INIT-002 Phase 1 - Define ports and domain schemas
5
+ *
6
+ * Zod schemas for validation-related types in the context-aware validation system.
7
+ * Types are inferred from Zod schemas using z.infer<> for single source of truth.
8
+ *
9
+ * @module domain/validation.schemas
10
+ */
11
+ import { z } from 'zod';
12
+ import { LocationTypeSchema } from './context.schemas.js';
13
+ // Re-export LocationTypeSchema for command definitions
14
+ export { LocationTypeSchema };
15
+ /**
16
+ * Validation error code values
17
+ *
18
+ * Mirrors CONTEXT_VALIDATION.ERROR_CODES from wu-constants.ts
19
+ */
20
+ export const VALIDATION_ERROR_CODE_VALUES = [
21
+ 'WRONG_LOCATION',
22
+ 'WU_NOT_FOUND',
23
+ 'WU_ALREADY_EXISTS',
24
+ 'WRONG_WU_STATUS',
25
+ 'LANE_OCCUPIED',
26
+ 'WORKTREE_EXISTS',
27
+ 'WORKTREE_MISSING',
28
+ 'GATES_NOT_PASSED',
29
+ 'DIRTY_GIT',
30
+ 'REMOTE_UNAVAILABLE',
31
+ 'INCONSISTENT_STATE',
32
+ ];
33
+ /**
34
+ * Schema for validation error codes
35
+ */
36
+ export const ValidationErrorCodeSchema = z.enum(VALIDATION_ERROR_CODE_VALUES);
37
+ /**
38
+ * Severity values
39
+ *
40
+ * Mirrors CONTEXT_VALIDATION.SEVERITY from wu-constants.ts
41
+ */
42
+ export const PREDICATE_SEVERITY_VALUES = ['error', 'warning'];
43
+ /**
44
+ * Schema for predicate severity
45
+ */
46
+ export const PredicateSeveritySchema = z.enum(PREDICATE_SEVERITY_VALUES);
47
+ /**
48
+ * Schema for validation error with fix guidance
49
+ */
50
+ export const ValidationErrorSchema = z.object({
51
+ /** Error code */
52
+ code: ValidationErrorCodeSchema,
53
+ /** Human-readable message */
54
+ message: z.string(),
55
+ /** Copy-paste ready fix command (if available) */
56
+ fixCommand: z.string().nullable(),
57
+ /** Additional context for debugging */
58
+ context: z.record(z.string(), z.unknown()).optional(),
59
+ });
60
+ /**
61
+ * Schema for validation warning (non-blocking)
62
+ */
63
+ export const ValidationWarningSchema = z.object({
64
+ /** Warning ID */
65
+ id: z.string(),
66
+ /** Human-readable message */
67
+ message: z.string(),
68
+ });
69
+ /**
70
+ * Schema for validation result (partial, without context for serialization)
71
+ *
72
+ * Note: The full ValidationResult in types.ts includes the context object,
73
+ * but this schema is for serializable results without the context.
74
+ */
75
+ export const ValidationResultSchema = z.object({
76
+ /** Whether command can proceed */
77
+ valid: z.boolean(),
78
+ /** Errors that block execution */
79
+ errors: z.array(ValidationErrorSchema),
80
+ /** Warnings that don't block execution */
81
+ warnings: z.array(ValidationWarningSchema),
82
+ });
83
+ /**
84
+ * Schema for command predicate configuration (serializable)
85
+ *
86
+ * This schema represents the serializable configuration of a predicate,
87
+ * not the full CommandPredicate which includes the check function.
88
+ */
89
+ export const CommandPredicateConfigSchema = z.object({
90
+ /** Unique identifier for the predicate */
91
+ id: z.string(),
92
+ /** Human-readable description */
93
+ description: z.string(),
94
+ /** Severity: 'error' blocks execution, 'warning' allows with warning */
95
+ severity: PredicateSeveritySchema,
96
+ });
97
+ /**
98
+ * Schema for command definition configuration (serializable)
99
+ *
100
+ * This schema represents the serializable configuration of a command definition,
101
+ * not the full CommandDefinition which includes function references.
102
+ */
103
+ export const CommandDefinitionConfigSchema = z.object({
104
+ /** Command name (e.g., 'wu:create') */
105
+ name: z.string(),
106
+ /** Human-readable description */
107
+ description: z.string(),
108
+ /** Required location type (null = any location) */
109
+ requiredLocation: LocationTypeSchema.nullable(),
110
+ /** Required WU status (null = no status requirement) */
111
+ requiredWuStatus: z.string().nullable(),
112
+ /** Predicate IDs for additional checks */
113
+ predicateIds: z.array(z.string()),
114
+ });
package/dist/index.d.ts CHANGED
@@ -49,3 +49,20 @@ export * from './lumenflow-home.js';
49
49
  export * from './force-bypass-audit.js';
50
50
  export { LUMENFLOW_PATHS, BEACON_PATHS } from './wu-constants.js';
51
51
  export * from './color-support.js';
52
+ export * from './context/index.js';
53
+ export * from './validation/index.js';
54
+ export * from './recovery/index.js';
55
+ export * from './context-validation-integration.js';
56
+ export { CONTEXT_VALIDATION } from './wu-constants.js';
57
+ export type { LocationType, ValidationErrorCode, RecoveryActionType, RecoveryIssueCode, PredicateSeverity, ValidationMode, } from './wu-constants.js';
58
+ export type { ILocationResolver, IGitStateReader, IWuStateReader } from './ports/context.ports.js';
59
+ export type { ICommandRegistry } from './ports/validation.ports.js';
60
+ export type { IRecoveryAnalyzer } from './ports/recovery.ports.js';
61
+ export type { IWuGitAdapter, IWuStatusCheckResult, IBranchValidationResult, IWuYamlReader, IWuYamlWriter, IWuStateStore, IWuCheckpointManager, IWuPaths, } from './ports/wu-helpers.ports.js';
62
+ export type { IGitAdapter, IPhiScanner, PHIMatch, PHIScanResult, PHIScanOptions, MergeOptions, MergeResult, PushOptions, DeleteBranchOptions, WorktreeRemoveOptions, } from './ports/git-validator.ports.js';
63
+ export { LOCATION_TYPE_VALUES, LocationTypeSchema, LocationContextSchema, GitStateSchema, WuStateResultSchema, SessionStateSchema, WuContextSchema, } from './domain/context.schemas.js';
64
+ export { VALIDATION_ERROR_CODE_VALUES, ValidationErrorCodeSchema, PREDICATE_SEVERITY_VALUES, PredicateSeveritySchema, ValidationErrorSchema, ValidationWarningSchema, ValidationResultSchema, CommandPredicateConfigSchema, CommandDefinitionConfigSchema, type CommandPredicateConfig, type CommandDefinitionConfig, } from './domain/validation.schemas.js';
65
+ export { RECOVERY_ISSUE_CODE_VALUES, RecoveryIssueCodeSchema, RECOVERY_ACTION_TYPE_VALUES, RecoveryActionTypeSchema, RecoveryIssueSchema, RecoveryActionSchema, RecoveryAnalysisSchema, } from './domain/recovery.schemas.js';
66
+ export { SimpleGitLocationAdapter, SimpleGitStateAdapter, FileSystemWuStateAdapter, CommandRegistryAdapter, RecoveryAnalyzerAdapter, } from './adapters/index.js';
67
+ export { ComputeContextUseCase, type ComputeContextOptions, ValidateCommandUseCase, AnalyzeRecoveryUseCase, } from './usecases/index.js';
68
+ export { createContextAdapters, createValidationAdapters, createRecoveryAdapters, createComputeContextUseCase, createValidateCommandUseCase, createAnalyzeRecoveryUseCase, computeWuContext, validateCommand, analyzeRecoveryIssues, type ContextAdapters, type ValidationAdapters, type RecoveryAdapters, type CreateComputeContextOptions, type CreateValidateCommandOptions, type CreateAnalyzeRecoveryOptions, } from './context-di.js';
package/dist/index.js CHANGED
@@ -77,3 +77,46 @@ export * from './force-bypass-audit.js';
77
77
  export { LUMENFLOW_PATHS, BEACON_PATHS } from './wu-constants.js';
78
78
  // WU-1085: Color support for NO_COLOR/FORCE_COLOR/--no-color
79
79
  export * from './color-support.js';
80
+ // WU-1090: Context-aware state machine for WU lifecycle commands
81
+ export * from './context/index.js';
82
+ export * from './validation/index.js';
83
+ export * from './recovery/index.js';
84
+ export * from './context-validation-integration.js';
85
+ // WU-1090: Context validation constants
86
+ export { CONTEXT_VALIDATION } from './wu-constants.js';
87
+ // WU-1093: Domain schemas for context-aware validation (Zod schemas)
88
+ // Note: Types like LocationContext, GitState are already exported from context/index.js
89
+ // so we only export the Zod schemas, not the inferred types.
90
+ export {
91
+ // Context schemas
92
+ LOCATION_TYPE_VALUES, LocationTypeSchema, LocationContextSchema, GitStateSchema, WuStateResultSchema, SessionStateSchema, WuContextSchema, } from './domain/context.schemas.js';
93
+ export {
94
+ // Validation schemas
95
+ VALIDATION_ERROR_CODE_VALUES, ValidationErrorCodeSchema, PREDICATE_SEVERITY_VALUES, PredicateSeveritySchema, ValidationErrorSchema, ValidationWarningSchema, ValidationResultSchema, CommandPredicateConfigSchema, CommandDefinitionConfigSchema, } from './domain/validation.schemas.js';
96
+ export {
97
+ // Recovery schemas
98
+ RECOVERY_ISSUE_CODE_VALUES, RecoveryIssueCodeSchema, RECOVERY_ACTION_TYPE_VALUES, RecoveryActionTypeSchema, RecoveryIssueSchema, RecoveryActionSchema, RecoveryAnalysisSchema, } from './domain/recovery.schemas.js';
99
+ // WU-1094: Adapters - Concrete implementations of port interfaces
100
+ export {
101
+ // Context adapters
102
+ SimpleGitLocationAdapter, SimpleGitStateAdapter, FileSystemWuStateAdapter,
103
+ // Validation adapters
104
+ CommandRegistryAdapter,
105
+ // Recovery adapters
106
+ RecoveryAnalyzerAdapter, } from './adapters/index.js';
107
+ // WU-1094: Use Cases - Application layer business logic
108
+ export {
109
+ // Context use cases
110
+ ComputeContextUseCase,
111
+ // Validation use cases
112
+ ValidateCommandUseCase,
113
+ // Recovery use cases
114
+ AnalyzeRecoveryUseCase, } from './usecases/index.js';
115
+ // WU-1094: Dependency Injection - Factory functions for wiring
116
+ export {
117
+ // Adapter factory functions
118
+ createContextAdapters, createValidationAdapters, createRecoveryAdapters,
119
+ // Use case factory functions
120
+ createComputeContextUseCase, createValidateCommandUseCase, createAnalyzeRecoveryUseCase,
121
+ // Backwards compatible convenience functions
122
+ computeWuContext, validateCommand, analyzeRecoveryIssues, } from './context-di.js';
@@ -205,6 +205,29 @@ export declare const AgentsConfigSchema: z.ZodObject<{
205
205
  notes: z.ZodOptional<z.ZodString>;
206
206
  }, z.core.$strip>>;
207
207
  }, z.core.$strip>;
208
+ /**
209
+ * Validation mode for context-aware commands
210
+ * WU-1090: Context-aware state machine for WU lifecycle commands
211
+ */
212
+ export declare const ValidationModeSchema: z.ZodDefault<z.ZodEnum<{
213
+ error: "error";
214
+ off: "off";
215
+ warn: "warn";
216
+ }>>;
217
+ /**
218
+ * Experimental features configuration
219
+ * WU-1090: Feature flags for gradual rollout
220
+ */
221
+ export declare const ExperimentalConfigSchema: z.ZodObject<{
222
+ context_validation: z.ZodDefault<z.ZodBoolean>;
223
+ validation_mode: z.ZodDefault<z.ZodEnum<{
224
+ error: "error";
225
+ off: "off";
226
+ warn: "warn";
227
+ }>>;
228
+ show_next_steps: z.ZodDefault<z.ZodBoolean>;
229
+ recovery_command: z.ZodDefault<z.ZodBoolean>;
230
+ }, z.core.$strip>;
208
231
  /**
209
232
  * Complete LumenFlow configuration schema
210
233
  */
@@ -335,6 +358,16 @@ export declare const LumenFlowConfigSchema: z.ZodObject<{
335
358
  notes: z.ZodOptional<z.ZodString>;
336
359
  }, z.core.$strip>>;
337
360
  }, z.core.$strip>>;
361
+ experimental: z.ZodDefault<z.ZodObject<{
362
+ context_validation: z.ZodDefault<z.ZodBoolean>;
363
+ validation_mode: z.ZodDefault<z.ZodEnum<{
364
+ error: "error";
365
+ off: "off";
366
+ warn: "warn";
367
+ }>>;
368
+ show_next_steps: z.ZodDefault<z.ZodBoolean>;
369
+ recovery_command: z.ZodDefault<z.ZodBoolean>;
370
+ }, z.core.$strip>>;
338
371
  }, z.core.$strip>;
339
372
  /**
340
373
  * TypeScript types inferred from schemas
@@ -352,6 +385,8 @@ export type ClientBlock = z.infer<typeof ClientBlockSchema>;
352
385
  export type ClientSkills = z.infer<typeof ClientSkillsSchema>;
353
386
  export type ClientConfig = z.infer<typeof ClientConfigSchema>;
354
387
  export type AgentsConfig = z.infer<typeof AgentsConfigSchema>;
388
+ export type ExperimentalConfig = z.infer<typeof ExperimentalConfigSchema>;
389
+ export type ValidationMode = z.infer<typeof ValidationModeSchema>;
355
390
  export type LumenFlowConfig = z.infer<typeof LumenFlowConfigSchema>;
356
391
  /**
357
392
  * Validate configuration data
@@ -483,6 +518,12 @@ export declare function validateConfig(data: unknown): z.ZodSafeParseResult<{
483
518
  notes?: string;
484
519
  };
485
520
  };
521
+ experimental: {
522
+ context_validation: boolean;
523
+ validation_mode: "error" | "off" | "warn";
524
+ show_next_steps: boolean;
525
+ recovery_command: boolean;
526
+ };
486
527
  }>;
487
528
  /**
488
529
  * Parse configuration with defaults
@@ -281,6 +281,41 @@ export const AgentsConfigSchema = z.object({
281
281
  /** Project methodology defaults (agent-facing) */
282
282
  methodology: MethodologyDefaultsSchema.default(() => MethodologyDefaultsSchema.parse({})),
283
283
  });
284
+ /**
285
+ * Validation mode for context-aware commands
286
+ * WU-1090: Context-aware state machine for WU lifecycle commands
287
+ */
288
+ export const ValidationModeSchema = z.enum(['off', 'warn', 'error']).default('warn');
289
+ /**
290
+ * Experimental features configuration
291
+ * WU-1090: Feature flags for gradual rollout
292
+ */
293
+ export const ExperimentalConfigSchema = z.object({
294
+ /**
295
+ * Enable context-aware validation for wu:* commands
296
+ * When enabled, commands will check location, WU status, and predicates
297
+ * @default true
298
+ */
299
+ context_validation: z.boolean().default(true),
300
+ /**
301
+ * Validation behavior mode
302
+ * - 'off': No validation (legacy behavior)
303
+ * - 'warn': Show warnings but proceed
304
+ * - 'error': Block on validation failures
305
+ * @default 'warn'
306
+ */
307
+ validation_mode: ValidationModeSchema,
308
+ /**
309
+ * Show next steps guidance after successful command completion
310
+ * @default true
311
+ */
312
+ show_next_steps: z.boolean().default(true),
313
+ /**
314
+ * Enable wu:recover command for state recovery
315
+ * @default true
316
+ */
317
+ recovery_command: z.boolean().default(true),
318
+ });
284
319
  /**
285
320
  * Complete LumenFlow configuration schema
286
321
  */
@@ -305,6 +340,8 @@ export const LumenFlowConfigSchema = z.object({
305
340
  yaml: YamlConfigSchema.default(() => YamlConfigSchema.parse({})),
306
341
  /** Agents configuration */
307
342
  agents: AgentsConfigSchema.default(() => AgentsConfigSchema.parse({})),
343
+ /** Experimental features (WU-1090) */
344
+ experimental: ExperimentalConfigSchema.default(() => ExperimentalConfigSchema.parse({})),
308
345
  });
309
346
  /**
310
347
  * Validate configuration data
@@ -0,0 +1,135 @@
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
+ import type { LocationContext } from '../context/location-resolver.js';
22
+ import type { GitState } from '../context/git-state-reader.js';
23
+ import type { WuStateResult } from '../context/wu-state-reader.js';
24
+ /**
25
+ * Location Resolver Port Interface
26
+ *
27
+ * Resolves the current working directory context to determine:
28
+ * - Whether in main checkout or a worktree
29
+ * - Path to main checkout
30
+ * - Worktree name and associated WU ID (if applicable)
31
+ *
32
+ * @example
33
+ * // Custom implementation for testing
34
+ * const mockResolver: ILocationResolver = {
35
+ * resolveLocation: async (cwd) => ({
36
+ * type: 'main',
37
+ * cwd: cwd || '/repo',
38
+ * gitRoot: '/repo',
39
+ * mainCheckout: '/repo',
40
+ * worktreeName: null,
41
+ * worktreeWuId: null,
42
+ * }),
43
+ * };
44
+ *
45
+ * @example
46
+ * // Using default implementation
47
+ * import { resolveLocation } from './context/location-resolver.js';
48
+ * const resolver: ILocationResolver = { resolveLocation };
49
+ */
50
+ export interface ILocationResolver {
51
+ /**
52
+ * Resolve location context for the given working directory.
53
+ *
54
+ * @param cwd - Current working directory (defaults to process.cwd())
55
+ * @returns Promise<LocationContext> - Resolved location context
56
+ */
57
+ resolveLocation(cwd?: string): Promise<LocationContext>;
58
+ }
59
+ /**
60
+ * Git State Reader Port Interface
61
+ *
62
+ * Reads the current git state including:
63
+ * - Current branch name
64
+ * - Whether HEAD is detached
65
+ * - Dirty working tree (uncommitted changes)
66
+ * - Staged changes
67
+ * - Commits ahead/behind tracking branch
68
+ *
69
+ * @example
70
+ * // Custom implementation for testing
71
+ * const mockReader: IGitStateReader = {
72
+ * readGitState: async () => ({
73
+ * branch: 'main',
74
+ * isDetached: false,
75
+ * isDirty: false,
76
+ * hasStaged: false,
77
+ * ahead: 0,
78
+ * behind: 0,
79
+ * tracking: 'origin/main',
80
+ * modifiedFiles: [],
81
+ * hasError: false,
82
+ * errorMessage: null,
83
+ * }),
84
+ * };
85
+ *
86
+ * @example
87
+ * // Using default implementation
88
+ * import { readGitState } from './context/git-state-reader.js';
89
+ * const reader: IGitStateReader = { readGitState };
90
+ */
91
+ export interface IGitStateReader {
92
+ /**
93
+ * Read current git state for the given working directory.
94
+ *
95
+ * @param cwd - Current working directory (defaults to process.cwd())
96
+ * @returns Promise<GitState> - Current git state
97
+ */
98
+ readGitState(cwd?: string): Promise<GitState>;
99
+ }
100
+ /**
101
+ * WU State Reader Port Interface
102
+ *
103
+ * Reads WU state from YAML file and optionally cross-references
104
+ * with state store for inconsistency detection.
105
+ *
106
+ * @example
107
+ * // Custom implementation for testing
108
+ * const mockReader: IWuStateReader = {
109
+ * readWuState: async (wuId, repoRoot) => ({
110
+ * id: wuId,
111
+ * status: 'in_progress',
112
+ * lane: 'Framework: Core',
113
+ * title: 'Test WU',
114
+ * yamlPath: `${repoRoot}/docs/04-operations/tasks/wu/${wuId}.yaml`,
115
+ * isConsistent: true,
116
+ * inconsistencyReason: null,
117
+ * }),
118
+ * };
119
+ *
120
+ * @example
121
+ * // Using default implementation
122
+ * import { readWuState } from './context/wu-state-reader.js';
123
+ * const reader: IWuStateReader = { readWuState };
124
+ */
125
+ export interface IWuStateReader {
126
+ /**
127
+ * Read WU state from YAML and detect inconsistencies.
128
+ *
129
+ * @param wuId - WU ID (e.g., 'WU-1093' or 'wu-1093')
130
+ * @param repoRoot - Repository root path
131
+ * @returns Promise<WuStateResult | null> - WU state or null if not found
132
+ */
133
+ readWuState(wuId: string, repoRoot: string): Promise<WuStateResult | null>;
134
+ }
135
+ export type { LocationContext, GitState, WuStateResult };
@@ -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 {};