@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,43 @@
1
+ /**
2
+ * Recovery Adapters
3
+ *
4
+ * WU-1094: INIT-002 Phase 2 - Implement adapters and dependency injection
5
+ *
6
+ * Concrete adapter implementations for recovery-related port interfaces.
7
+ * These adapters wrap the existing implementation functions to conform
8
+ * to the port interfaces, enabling dependency injection.
9
+ *
10
+ * Adapters:
11
+ * - RecoveryAnalyzerAdapter - Implements IRecoveryAnalyzer
12
+ *
13
+ * @module adapters/recovery-adapters
14
+ */
15
+ // Import existing implementation
16
+ import { analyzeRecovery } from '../recovery/recovery-analyzer.js';
17
+ /**
18
+ * RecoveryAnalyzerAdapter
19
+ *
20
+ * Implements IRecoveryAnalyzer by delegating to the analyzeRecovery function.
21
+ * Analyzes WU context to detect state inconsistencies and suggests
22
+ * recovery actions.
23
+ *
24
+ * @example
25
+ * // Use default adapter
26
+ * const adapter = new RecoveryAnalyzerAdapter();
27
+ * const analysis = await adapter.analyzeRecovery(context);
28
+ *
29
+ * @example
30
+ * // Use as port interface
31
+ * const analyzer: IRecoveryAnalyzer = new RecoveryAnalyzerAdapter();
32
+ */
33
+ export class RecoveryAnalyzerAdapter {
34
+ /**
35
+ * Analyze context for recovery issues.
36
+ *
37
+ * @param context - Current WU context
38
+ * @returns Promise<RecoveryAnalysis> - Recovery analysis with issues and suggested actions
39
+ */
40
+ async analyzeRecovery(context) {
41
+ return analyzeRecovery(context);
42
+ }
43
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Validation Adapters
3
+ *
4
+ * WU-1094: INIT-002 Phase 2 - Implement adapters and dependency injection
5
+ *
6
+ * Concrete adapter implementations for validation-related port interfaces.
7
+ * These adapters wrap the existing implementation functions to conform
8
+ * to the port interfaces, enabling dependency injection.
9
+ *
10
+ * Adapters:
11
+ * - CommandRegistryAdapter - Implements ICommandRegistry
12
+ *
13
+ * @module adapters/validation-adapters
14
+ */
15
+ import type { ICommandRegistry, CommandDefinition, WuContext } from '../ports/validation.ports.js';
16
+ /**
17
+ * CommandRegistryAdapter
18
+ *
19
+ * Implements ICommandRegistry by delegating to the command registry functions.
20
+ * Provides access to command definitions and context-based validation.
21
+ *
22
+ * @example
23
+ * // Use default adapter
24
+ * const adapter = new CommandRegistryAdapter();
25
+ * const def = adapter.getCommandDefinition('wu:done');
26
+ *
27
+ * @example
28
+ * // Use as port interface
29
+ * const registry: ICommandRegistry = new CommandRegistryAdapter();
30
+ */
31
+ export declare class CommandRegistryAdapter implements ICommandRegistry {
32
+ /**
33
+ * Get command definition by name.
34
+ *
35
+ * @param command - Command name (e.g., 'wu:create', 'wu:done')
36
+ * @returns CommandDefinition or null if not found
37
+ */
38
+ getCommandDefinition(command: string): CommandDefinition | null;
39
+ /**
40
+ * Get all commands valid for the current context.
41
+ *
42
+ * @param context - Current WU context
43
+ * @returns Array of valid CommandDefinitions
44
+ */
45
+ getValidCommandsForContext(context: WuContext): CommandDefinition[];
46
+ /**
47
+ * Get all registered command definitions.
48
+ *
49
+ * @returns Array of all CommandDefinitions
50
+ */
51
+ getAllCommands(): CommandDefinition[];
52
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Validation Adapters
3
+ *
4
+ * WU-1094: INIT-002 Phase 2 - Implement adapters and dependency injection
5
+ *
6
+ * Concrete adapter implementations for validation-related port interfaces.
7
+ * These adapters wrap the existing implementation functions to conform
8
+ * to the port interfaces, enabling dependency injection.
9
+ *
10
+ * Adapters:
11
+ * - CommandRegistryAdapter - Implements ICommandRegistry
12
+ *
13
+ * @module adapters/validation-adapters
14
+ */
15
+ // Import existing implementations
16
+ import { COMMAND_REGISTRY, getCommandDefinition, getValidCommandsForContext, } from '../validation/command-registry.js';
17
+ /**
18
+ * CommandRegistryAdapter
19
+ *
20
+ * Implements ICommandRegistry by delegating to the command registry functions.
21
+ * Provides access to command definitions and context-based validation.
22
+ *
23
+ * @example
24
+ * // Use default adapter
25
+ * const adapter = new CommandRegistryAdapter();
26
+ * const def = adapter.getCommandDefinition('wu:done');
27
+ *
28
+ * @example
29
+ * // Use as port interface
30
+ * const registry: ICommandRegistry = new CommandRegistryAdapter();
31
+ */
32
+ export class CommandRegistryAdapter {
33
+ /**
34
+ * Get command definition by name.
35
+ *
36
+ * @param command - Command name (e.g., 'wu:create', 'wu:done')
37
+ * @returns CommandDefinition or null if not found
38
+ */
39
+ getCommandDefinition(command) {
40
+ return getCommandDefinition(command);
41
+ }
42
+ /**
43
+ * Get all commands valid for the current context.
44
+ *
45
+ * @param context - Current WU context
46
+ * @returns Array of valid CommandDefinitions
47
+ */
48
+ getValidCommandsForContext(context) {
49
+ return getValidCommandsForContext(context);
50
+ }
51
+ /**
52
+ * Get all registered command definitions.
53
+ *
54
+ * @returns Array of all CommandDefinitions
55
+ */
56
+ getAllCommands() {
57
+ return Array.from(COMMAND_REGISTRY.values());
58
+ }
59
+ }
@@ -5,6 +5,8 @@
5
5
  * that bypass worktree requirements. Static JSON served from lumenflow.dev,
6
6
  * cached locally for 7 days with fallback to defaults.
7
7
  *
8
+ * WU-1089: Added merge/override/airgapped modes via resolveAgentPatterns()
9
+ *
8
10
  * @module agent-patterns-registry
9
11
  */
10
12
  /** Default agent branch patterns (narrow: just agent/*) */
@@ -16,12 +18,48 @@ export declare const CACHE_TTL_MS: number;
16
18
  /**
17
19
  * Options for getAgentPatterns
18
20
  */
19
- interface GetAgentPatternsOptions {
21
+ export interface GetAgentPatternsOptions {
20
22
  /** Override cache directory (default: ~/.lumenflow/cache) */
21
23
  cacheDir?: string;
22
24
  /** Fetch timeout in milliseconds (default: 5000) */
23
25
  timeoutMs?: number;
24
26
  }
27
+ /**
28
+ * Source of agent patterns for observability
29
+ */
30
+ export type AgentPatternSource = 'registry' | 'merged' | 'override' | 'config' | 'defaults';
31
+ /**
32
+ * Result of resolveAgentPatterns with observability fields
33
+ */
34
+ export interface AgentPatternResult {
35
+ /** Resolved patterns to use for agent branch matching */
36
+ patterns: string[];
37
+ /** Source of the patterns for observability */
38
+ source: AgentPatternSource;
39
+ /** Whether the registry was successfully fetched */
40
+ registryFetched: boolean;
41
+ }
42
+ /**
43
+ * Type for injectable registry fetcher function
44
+ */
45
+ export type RegistryFetcher = (options: GetAgentPatternsOptions) => Promise<string[]>;
46
+ /**
47
+ * Options for resolveAgentPatterns (WU-1089)
48
+ */
49
+ export interface ResolveAgentPatternsOptions {
50
+ /** Injectable registry fetcher for testing (uses getAgentPatterns by default) */
51
+ registryFetcher?: RegistryFetcher;
52
+ /** Patterns from config.git.agentBranchPatterns (merged with registry by default) */
53
+ configPatterns?: string[];
54
+ /** Patterns from config.git.agentBranchPatternsOverride (replaces everything if set) */
55
+ overridePatterns?: string[];
56
+ /** config.git.disableAgentPatternRegistry - skips network fetch (airgapped mode) */
57
+ disableAgentPatternRegistry?: boolean;
58
+ /** Override cache directory (passed to fetcher) */
59
+ cacheDir?: string;
60
+ /** Fetch timeout in milliseconds (passed to fetcher) */
61
+ timeoutMs?: number;
62
+ }
25
63
  /**
26
64
  * Get the default cache directory
27
65
  *
@@ -44,10 +82,70 @@ export declare function getCacheDir(): string;
44
82
  * ```
45
83
  */
46
84
  export declare function getAgentPatterns(options?: GetAgentPatternsOptions): Promise<string[]>;
85
+ /**
86
+ * Resolve agent branch patterns based on config with merge/override/airgapped support
87
+ *
88
+ * Behavior matrix (WU-1089):
89
+ *
90
+ * | disableRegistry | override patterns | config patterns | Result | Source |
91
+ * |-----------------|-------------------|-----------------|------------------------|---------------|
92
+ * | false | undefined | undefined/[] | registry | 'registry' |
93
+ * | false | undefined | ['custom/*'] | config + registry | 'merged' |
94
+ * | false | ['only/*'] | any | override only | 'override' |
95
+ * | true | undefined | undefined/[] | defaults | 'defaults' |
96
+ * | true | undefined | ['custom/*'] | config only | 'config' |
97
+ * | true | ['only/*'] | any | override only | 'override' |
98
+ *
99
+ * When registry fetch fails:
100
+ * - Falls back to config patterns if provided, source = 'config'
101
+ * - Falls back to defaults if no config, source = 'defaults'
102
+ *
103
+ * @param options - Resolution options
104
+ * @returns Result with patterns, source, and registryFetched flag
105
+ *
106
+ * @example Default (fetch from registry)
107
+ * ```typescript
108
+ * const result = await resolveAgentPatterns({});
109
+ * // result.patterns = ['claude/*', 'codex/*', ...] (from registry)
110
+ * // result.source = 'registry'
111
+ * // result.registryFetched = true
112
+ * ```
113
+ *
114
+ * @example Merge mode (config + registry)
115
+ * ```typescript
116
+ * const result = await resolveAgentPatterns({
117
+ * configPatterns: ['my-agent/*'],
118
+ * });
119
+ * // result.patterns = ['my-agent/*', 'claude/*', 'codex/*', ...]
120
+ * // result.source = 'merged'
121
+ * // result.registryFetched = true
122
+ * ```
123
+ *
124
+ * @example Override mode (explicit replacement)
125
+ * ```typescript
126
+ * const result = await resolveAgentPatterns({
127
+ * overridePatterns: ['only-this/*'],
128
+ * });
129
+ * // result.patterns = ['only-this/*']
130
+ * // result.source = 'override'
131
+ * // result.registryFetched = false
132
+ * ```
133
+ *
134
+ * @example Airgapped mode (no network)
135
+ * ```typescript
136
+ * const result = await resolveAgentPatterns({
137
+ * disableAgentPatternRegistry: true,
138
+ * configPatterns: ['my-agent/*'],
139
+ * });
140
+ * // result.patterns = ['my-agent/*']
141
+ * // result.source = 'config'
142
+ * // result.registryFetched = false
143
+ * ```
144
+ */
145
+ export declare function resolveAgentPatterns(options?: ResolveAgentPatternsOptions): Promise<AgentPatternResult>;
47
146
  /**
48
147
  * Clear the in-memory cache
49
148
  *
50
149
  * Used primarily for testing.
51
150
  */
52
151
  export declare function clearCache(): void;
53
- export {};
@@ -5,6 +5,8 @@
5
5
  * that bypass worktree requirements. Static JSON served from lumenflow.dev,
6
6
  * cached locally for 7 days with fallback to defaults.
7
7
  *
8
+ * WU-1089: Added merge/override/airgapped modes via resolveAgentPatterns()
9
+ *
8
10
  * @module agent-patterns-registry
9
11
  */
10
12
  import * as fs from 'node:fs';
@@ -179,6 +181,128 @@ export async function getAgentPatterns(options = {}) {
179
181
  // No cache, no network - use defaults
180
182
  return DEFAULT_AGENT_PATTERNS;
181
183
  }
184
+ /**
185
+ * Resolve agent branch patterns based on config with merge/override/airgapped support
186
+ *
187
+ * Behavior matrix (WU-1089):
188
+ *
189
+ * | disableRegistry | override patterns | config patterns | Result | Source |
190
+ * |-----------------|-------------------|-----------------|------------------------|---------------|
191
+ * | false | undefined | undefined/[] | registry | 'registry' |
192
+ * | false | undefined | ['custom/*'] | config + registry | 'merged' |
193
+ * | false | ['only/*'] | any | override only | 'override' |
194
+ * | true | undefined | undefined/[] | defaults | 'defaults' |
195
+ * | true | undefined | ['custom/*'] | config only | 'config' |
196
+ * | true | ['only/*'] | any | override only | 'override' |
197
+ *
198
+ * When registry fetch fails:
199
+ * - Falls back to config patterns if provided, source = 'config'
200
+ * - Falls back to defaults if no config, source = 'defaults'
201
+ *
202
+ * @param options - Resolution options
203
+ * @returns Result with patterns, source, and registryFetched flag
204
+ *
205
+ * @example Default (fetch from registry)
206
+ * ```typescript
207
+ * const result = await resolveAgentPatterns({});
208
+ * // result.patterns = ['claude/*', 'codex/*', ...] (from registry)
209
+ * // result.source = 'registry'
210
+ * // result.registryFetched = true
211
+ * ```
212
+ *
213
+ * @example Merge mode (config + registry)
214
+ * ```typescript
215
+ * const result = await resolveAgentPatterns({
216
+ * configPatterns: ['my-agent/*'],
217
+ * });
218
+ * // result.patterns = ['my-agent/*', 'claude/*', 'codex/*', ...]
219
+ * // result.source = 'merged'
220
+ * // result.registryFetched = true
221
+ * ```
222
+ *
223
+ * @example Override mode (explicit replacement)
224
+ * ```typescript
225
+ * const result = await resolveAgentPatterns({
226
+ * overridePatterns: ['only-this/*'],
227
+ * });
228
+ * // result.patterns = ['only-this/*']
229
+ * // result.source = 'override'
230
+ * // result.registryFetched = false
231
+ * ```
232
+ *
233
+ * @example Airgapped mode (no network)
234
+ * ```typescript
235
+ * const result = await resolveAgentPatterns({
236
+ * disableAgentPatternRegistry: true,
237
+ * configPatterns: ['my-agent/*'],
238
+ * });
239
+ * // result.patterns = ['my-agent/*']
240
+ * // result.source = 'config'
241
+ * // result.registryFetched = false
242
+ * ```
243
+ */
244
+ export async function resolveAgentPatterns(options = {}) {
245
+ const { registryFetcher = getAgentPatterns, configPatterns, overridePatterns, disableAgentPatternRegistry = false, cacheDir, timeoutMs, } = options;
246
+ // Scenario 3/6: Override mode - overridePatterns replaces everything
247
+ if (overridePatterns && overridePatterns.length > 0) {
248
+ return {
249
+ patterns: overridePatterns,
250
+ source: 'override',
251
+ registryFetched: false,
252
+ };
253
+ }
254
+ // Scenario 4/5: Airgapped mode - disableAgentPatternRegistry skips network
255
+ if (disableAgentPatternRegistry) {
256
+ const hasConfigPatterns = configPatterns && configPatterns.length > 0;
257
+ return {
258
+ patterns: hasConfigPatterns ? configPatterns : DEFAULT_AGENT_PATTERNS,
259
+ source: hasConfigPatterns ? 'config' : 'defaults',
260
+ registryFetched: false,
261
+ };
262
+ }
263
+ // Scenario 1/2: Normal mode - fetch from registry, optionally merge with config
264
+ const hasConfigPatterns = configPatterns && configPatterns.length > 0;
265
+ // Try to fetch from registry
266
+ let registryPatterns = null;
267
+ let fetchedSuccessfully = false;
268
+ try {
269
+ registryPatterns = await registryFetcher({ cacheDir, timeoutMs });
270
+ fetchedSuccessfully = registryPatterns !== null && registryPatterns.length > 0;
271
+ }
272
+ catch {
273
+ // Fetch failed - will use fallback below
274
+ fetchedSuccessfully = false;
275
+ }
276
+ // If registry fetch succeeded
277
+ if (fetchedSuccessfully && registryPatterns) {
278
+ if (hasConfigPatterns) {
279
+ // Scenario 2: Merge mode - config first, then registry (deduplicated)
280
+ const merged = [...configPatterns];
281
+ for (const pattern of registryPatterns) {
282
+ if (!merged.includes(pattern)) {
283
+ merged.push(pattern);
284
+ }
285
+ }
286
+ return {
287
+ patterns: merged,
288
+ source: 'merged',
289
+ registryFetched: true,
290
+ };
291
+ }
292
+ // Scenario 1: Registry only
293
+ return {
294
+ patterns: registryPatterns,
295
+ source: 'registry',
296
+ registryFetched: true,
297
+ };
298
+ }
299
+ // Registry fetch failed - fallback to config or defaults
300
+ return {
301
+ patterns: hasConfigPatterns ? configPatterns : DEFAULT_AGENT_PATTERNS,
302
+ source: hasConfigPatterns ? 'config' : 'defaults',
303
+ registryFetched: false,
304
+ };
305
+ }
182
306
  /**
183
307
  * Clear the in-memory cache
184
308
  *
@@ -247,6 +247,13 @@ export const WU_OPTIONS = {
247
247
  flags: '--color',
248
248
  description: 'Enable colored output',
249
249
  },
250
+ // WU-1085: NO_COLOR standard support (https://no-color.org/)
251
+ noColor: {
252
+ name: 'noColor',
253
+ flags: '--no-color',
254
+ description: 'Disable colored output (respects NO_COLOR env var)',
255
+ isNegated: true,
256
+ },
250
257
  status: {
251
258
  name: 'status',
252
259
  flags: '--status <status>',
@@ -4,14 +4,19 @@
4
4
  * Provides functions to check if a branch is an agent branch that can
5
5
  * bypass worktree requirements, and if headless mode is allowed.
6
6
  *
7
+ * WU-1089: Updated to use resolveAgentPatterns with merge/override/airgapped support.
8
+ *
7
9
  * @module branch-check
8
10
  */
11
+ import { type AgentPatternResult } from './agent-patterns-registry.js';
9
12
  /**
10
13
  * Check if branch is an agent branch that can bypass worktree requirements.
11
14
  *
12
- * Uses the central registry for agent patterns (fetched from lumenflow.dev
13
- * with 7-day cache), falling back to config patterns if specified, then
14
- * to defaults.
15
+ * WU-1089: Now uses resolveAgentPatterns with proper merge/override/airgapped support:
16
+ * - Default: Fetches from registry (lumenflow.dev) with 7-day cache
17
+ * - Config patterns merge with registry patterns (config first)
18
+ * - Override patterns (agentBranchPatternsOverride) replace everything
19
+ * - Airgapped mode (disableAgentPatternRegistry) skips network fetch
15
20
  *
16
21
  * @param branch - Branch name to check
17
22
  * @returns Promise<true> if branch matches agent patterns
@@ -24,12 +29,36 @@
24
29
  * ```
25
30
  */
26
31
  export declare function isAgentBranch(branch: string | null | undefined): Promise<boolean>;
32
+ /**
33
+ * Check if branch is an agent branch with full result details.
34
+ *
35
+ * Same as isAgentBranch but returns the full AgentPatternResult
36
+ * for observability and debugging.
37
+ *
38
+ * @param branch - Branch name to check
39
+ * @returns Promise with match result and pattern resolution details
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const result = await isAgentBranchWithDetails('claude/session-123');
44
+ * if (result.isMatch) {
45
+ * console.log(`Matched via ${result.patternResult.source}`);
46
+ * console.log(`Registry fetched: ${result.patternResult.registryFetched}`);
47
+ * }
48
+ * ```
49
+ */
50
+ export declare function isAgentBranchWithDetails(branch: string | null | undefined): Promise<{
51
+ isMatch: boolean;
52
+ patternResult: AgentPatternResult;
53
+ }>;
27
54
  /**
28
55
  * Synchronous version of isAgentBranch for backwards compatibility.
29
56
  *
30
57
  * Uses only local config patterns or defaults - does NOT fetch from registry.
31
58
  * Prefer async isAgentBranch() when possible.
32
59
  *
60
+ * WU-1089: Updated to respect override and disable flags, but cannot fetch from registry.
61
+ *
33
62
  * @param branch - Branch name to check
34
63
  * @returns True if branch matches agent patterns
35
64
  *
@@ -4,11 +4,13 @@
4
4
  * Provides functions to check if a branch is an agent branch that can
5
5
  * bypass worktree requirements, and if headless mode is allowed.
6
6
  *
7
+ * WU-1089: Updated to use resolveAgentPatterns with merge/override/airgapped support.
8
+ *
7
9
  * @module branch-check
8
10
  */
9
11
  import micromatch from 'micromatch';
10
12
  import { getConfig } from './lumenflow-config.js';
11
- import { getAgentPatterns, DEFAULT_AGENT_PATTERNS } from './agent-patterns-registry.js';
13
+ import { resolveAgentPatterns, DEFAULT_AGENT_PATTERNS, } from './agent-patterns-registry.js';
12
14
  /** Legacy protected branch (always protected regardless of mainBranch setting) */
13
15
  const LEGACY_PROTECTED = 'master';
14
16
  /**
@@ -36,9 +38,11 @@ function getProtectedBranches() {
36
38
  /**
37
39
  * Check if branch is an agent branch that can bypass worktree requirements.
38
40
  *
39
- * Uses the central registry for agent patterns (fetched from lumenflow.dev
40
- * with 7-day cache), falling back to config patterns if specified, then
41
- * to defaults.
41
+ * WU-1089: Now uses resolveAgentPatterns with proper merge/override/airgapped support:
42
+ * - Default: Fetches from registry (lumenflow.dev) with 7-day cache
43
+ * - Config patterns merge with registry patterns (config first)
44
+ * - Override patterns (agentBranchPatternsOverride) replace everything
45
+ * - Airgapped mode (disableAgentPatternRegistry) skips network fetch
42
46
  *
43
47
  * @param branch - Branch name to check
44
48
  * @returns Promise<true> if branch matches agent patterns
@@ -66,18 +70,73 @@ export async function isAgentBranch(branch) {
66
70
  // LumenFlow lane branches require worktrees (uses config's laneBranchPrefix)
67
71
  if (getLaneBranchPattern().test(branch))
68
72
  return false;
69
- // Get patterns: prefer config override, then registry, then defaults
70
- let patterns;
71
- if (config?.git?.agentBranchPatterns?.length > 0) {
72
- // Config has explicit patterns - use those
73
- patterns = config.git.agentBranchPatterns;
73
+ // WU-1089: Use resolveAgentPatterns with full merge/override/airgapped support
74
+ const result = await resolveAgentPatterns({
75
+ configPatterns: config?.git?.agentBranchPatterns,
76
+ overridePatterns: config?.git?.agentBranchPatternsOverride,
77
+ disableAgentPatternRegistry: config?.git?.disableAgentPatternRegistry,
78
+ });
79
+ // Use micromatch for proper glob matching
80
+ return micromatch.isMatch(branch, result.patterns);
81
+ }
82
+ /**
83
+ * Check if branch is an agent branch with full result details.
84
+ *
85
+ * Same as isAgentBranch but returns the full AgentPatternResult
86
+ * for observability and debugging.
87
+ *
88
+ * @param branch - Branch name to check
89
+ * @returns Promise with match result and pattern resolution details
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const result = await isAgentBranchWithDetails('claude/session-123');
94
+ * if (result.isMatch) {
95
+ * console.log(`Matched via ${result.patternResult.source}`);
96
+ * console.log(`Registry fetched: ${result.patternResult.registryFetched}`);
97
+ * }
98
+ * ```
99
+ */
100
+ export async function isAgentBranchWithDetails(branch) {
101
+ // Fail-closed: no branch = protected
102
+ if (!branch) {
103
+ return {
104
+ isMatch: false,
105
+ patternResult: { patterns: [], source: 'defaults', registryFetched: false },
106
+ };
74
107
  }
75
- else {
76
- // Fetch from registry (with caching and fallback to defaults)
77
- patterns = await getAgentPatterns();
108
+ // Detached HEAD = protected (fail-closed)
109
+ if (branch === 'HEAD') {
110
+ return {
111
+ isMatch: false,
112
+ patternResult: { patterns: [], source: 'defaults', registryFetched: false },
113
+ };
78
114
  }
79
- // Use micromatch for proper glob matching
80
- return micromatch.isMatch(branch, patterns);
115
+ // Load config
116
+ const config = getConfig();
117
+ const protectedBranches = getProtectedBranches();
118
+ // Protected branches are NEVER bypassed
119
+ if (protectedBranches.includes(branch)) {
120
+ return {
121
+ isMatch: false,
122
+ patternResult: { patterns: [], source: 'defaults', registryFetched: false },
123
+ };
124
+ }
125
+ // Lane branches require worktrees
126
+ if (getLaneBranchPattern().test(branch)) {
127
+ return {
128
+ isMatch: false,
129
+ patternResult: { patterns: [], source: 'defaults', registryFetched: false },
130
+ };
131
+ }
132
+ // Resolve patterns with full details
133
+ const patternResult = await resolveAgentPatterns({
134
+ configPatterns: config?.git?.agentBranchPatterns,
135
+ overridePatterns: config?.git?.agentBranchPatternsOverride,
136
+ disableAgentPatternRegistry: config?.git?.disableAgentPatternRegistry,
137
+ });
138
+ const isMatch = micromatch.isMatch(branch, patternResult.patterns);
139
+ return { isMatch, patternResult };
81
140
  }
82
141
  /**
83
142
  * Synchronous version of isAgentBranch for backwards compatibility.
@@ -85,6 +144,8 @@ export async function isAgentBranch(branch) {
85
144
  * Uses only local config patterns or defaults - does NOT fetch from registry.
86
145
  * Prefer async isAgentBranch() when possible.
87
146
  *
147
+ * WU-1089: Updated to respect override and disable flags, but cannot fetch from registry.
148
+ *
88
149
  * @param branch - Branch name to check
89
150
  * @returns True if branch matches agent patterns
90
151
  *
@@ -106,7 +167,12 @@ export function isAgentBranchSync(branch) {
106
167
  // LumenFlow lane branches require worktrees (uses config's laneBranchPrefix)
107
168
  if (getLaneBranchPattern().test(branch))
108
169
  return false;
109
- // Use config patterns or defaults (no registry fetch in sync version)
170
+ // WU-1089: Check override first
171
+ if (config?.git?.agentBranchPatternsOverride?.length) {
172
+ return micromatch.isMatch(branch, config.git.agentBranchPatternsOverride);
173
+ }
174
+ // Use config patterns if provided, otherwise defaults
175
+ // Note: sync version cannot fetch from registry
110
176
  const patterns = config?.git?.agentBranchPatterns?.length > 0
111
177
  ? config.git.agentBranchPatterns
112
178
  : DEFAULT_AGENT_PATTERNS;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @file color-support.ts
3
+ * Color control for CLI commands (WU-1085)
4
+ *
5
+ * Respects standard environment variables and CLI flags:
6
+ * - NO_COLOR: Disable colors (https://no-color.org/)
7
+ * - FORCE_COLOR: Override color level 0-3 (chalk standard)
8
+ * - --no-color: CLI flag to disable colors
9
+ *
10
+ * @see https://no-color.org/
11
+ * @see https://github.com/chalk/chalk#supportscolor
12
+ */
13
+ /**
14
+ * Get the current color level.
15
+ * @returns Color level 0-3 (0 = no colors, 3 = full 16m colors)
16
+ */
17
+ export declare function getColorLevel(): number;
18
+ /**
19
+ * Initialize color support respecting NO_COLOR and FORCE_COLOR standards.
20
+ * Call this before any colored output.
21
+ *
22
+ * Priority order:
23
+ * 1. NO_COLOR env var (always wins, per spec)
24
+ * 2. --no-color CLI flag
25
+ * 3. FORCE_COLOR env var
26
+ * 4. Default chalk detection
27
+ *
28
+ * @param argv - Command line arguments (defaults to process.argv)
29
+ * @see https://no-color.org/
30
+ * @see https://github.com/chalk/chalk#supportscolor
31
+ */
32
+ export declare function initColorSupport(argv?: string[]): void;