aiwcli 0.9.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 (204) hide show
  1. package/README.md +1248 -0
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +16 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +19 -0
  6. package/dist/commands/branch.d.ts +45 -0
  7. package/dist/commands/branch.js +488 -0
  8. package/dist/commands/clean.d.ts +34 -0
  9. package/dist/commands/clean.js +186 -0
  10. package/dist/commands/clear.d.ts +51 -0
  11. package/dist/commands/clear.js +835 -0
  12. package/dist/commands/init/index.d.ts +107 -0
  13. package/dist/commands/init/index.js +565 -0
  14. package/dist/commands/launch.d.ts +21 -0
  15. package/dist/commands/launch.js +108 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +1 -0
  18. package/dist/lib/base-command.d.ts +114 -0
  19. package/dist/lib/base-command.js +153 -0
  20. package/dist/lib/bmad-installer.d.ts +38 -0
  21. package/dist/lib/bmad-installer.js +145 -0
  22. package/dist/lib/claude-settings-types.d.ts +102 -0
  23. package/dist/lib/claude-settings-types.js +5 -0
  24. package/dist/lib/config.d.ts +25 -0
  25. package/dist/lib/config.js +46 -0
  26. package/dist/lib/debug.d.ts +39 -0
  27. package/dist/lib/debug.js +74 -0
  28. package/dist/lib/env-compat.d.ts +26 -0
  29. package/dist/lib/env-compat.js +35 -0
  30. package/dist/lib/errors.d.ts +126 -0
  31. package/dist/lib/errors.js +145 -0
  32. package/dist/lib/generic-merge.d.ts +74 -0
  33. package/dist/lib/generic-merge.js +105 -0
  34. package/dist/lib/git/branch.d.ts +67 -0
  35. package/dist/lib/git/branch.js +155 -0
  36. package/dist/lib/git/index.d.ts +11 -0
  37. package/dist/lib/git/index.js +13 -0
  38. package/dist/lib/git/safety-checks.d.ts +44 -0
  39. package/dist/lib/git/safety-checks.js +102 -0
  40. package/dist/lib/git/types.d.ts +31 -0
  41. package/dist/lib/git/types.js +6 -0
  42. package/dist/lib/git/worktree.d.ts +67 -0
  43. package/dist/lib/git/worktree.js +220 -0
  44. package/dist/lib/gitignore-manager.d.ts +10 -0
  45. package/dist/lib/gitignore-manager.js +60 -0
  46. package/dist/lib/hooks-merger.d.ts +28 -0
  47. package/dist/lib/hooks-merger.js +94 -0
  48. package/dist/lib/ide-path-resolver.d.ts +102 -0
  49. package/dist/lib/ide-path-resolver.js +129 -0
  50. package/dist/lib/index.d.ts +13 -0
  51. package/dist/lib/index.js +22 -0
  52. package/dist/lib/output.d.ts +51 -0
  53. package/dist/lib/output.js +76 -0
  54. package/dist/lib/paths.d.ts +66 -0
  55. package/dist/lib/paths.js +136 -0
  56. package/dist/lib/quiet.d.ts +12 -0
  57. package/dist/lib/quiet.js +17 -0
  58. package/dist/lib/settings-hierarchy.d.ts +42 -0
  59. package/dist/lib/settings-hierarchy.js +105 -0
  60. package/dist/lib/spawn.d.ts +105 -0
  61. package/dist/lib/spawn.js +157 -0
  62. package/dist/lib/spinner.d.ts +19 -0
  63. package/dist/lib/spinner.js +34 -0
  64. package/dist/lib/stdin.d.ts +48 -0
  65. package/dist/lib/stdin.js +60 -0
  66. package/dist/lib/template-installer.d.ts +92 -0
  67. package/dist/lib/template-installer.js +375 -0
  68. package/dist/lib/template-linter.d.ts +49 -0
  69. package/dist/lib/template-linter.js +173 -0
  70. package/dist/lib/template-merger.d.ts +47 -0
  71. package/dist/lib/template-merger.js +173 -0
  72. package/dist/lib/template-resolver.d.ts +20 -0
  73. package/dist/lib/template-resolver.js +60 -0
  74. package/dist/lib/terminal.d.ts +102 -0
  75. package/dist/lib/terminal.js +245 -0
  76. package/dist/lib/tty-detection.d.ts +62 -0
  77. package/dist/lib/tty-detection.js +83 -0
  78. package/dist/lib/user-utils.d.ts +5 -0
  79. package/dist/lib/user-utils.js +23 -0
  80. package/dist/lib/version.d.ts +99 -0
  81. package/dist/lib/version.js +144 -0
  82. package/dist/lib/watch-templates.d.ts +6 -0
  83. package/dist/lib/watch-templates.js +73 -0
  84. package/dist/lib/windsurf-hooks-hierarchy.d.ts +30 -0
  85. package/dist/lib/windsurf-hooks-hierarchy.js +66 -0
  86. package/dist/lib/windsurf-hooks-merger.d.ts +26 -0
  87. package/dist/lib/windsurf-hooks-merger.js +53 -0
  88. package/dist/lib/windsurf-hooks-types.d.ts +33 -0
  89. package/dist/lib/windsurf-hooks-types.js +5 -0
  90. package/dist/templates/CLAUDE.md +174 -0
  91. package/dist/templates/_shared/.claude/commands/handoff.md +14 -0
  92. package/dist/templates/_shared/.claude/settings.json +61 -0
  93. package/dist/templates/_shared/.codex/workflows/handoff.md +14 -0
  94. package/dist/templates/_shared/.windsurf/workflows/handoff.md +14 -0
  95. package/dist/templates/_shared/hooks/__init__.py +16 -0
  96. package/dist/templates/_shared/hooks/archive_plan.py +270 -0
  97. package/dist/templates/_shared/hooks/context_enforcer.py +621 -0
  98. package/dist/templates/_shared/hooks/context_monitor.py +322 -0
  99. package/dist/templates/_shared/hooks/file-suggestion.py +188 -0
  100. package/dist/templates/_shared/hooks/task_create_capture.py +194 -0
  101. package/dist/templates/_shared/hooks/task_update_capture.py +254 -0
  102. package/dist/templates/_shared/hooks/user_prompt_submit.py +157 -0
  103. package/dist/templates/_shared/lib/__init__.py +1 -0
  104. package/dist/templates/_shared/lib/base/__init__.py +49 -0
  105. package/dist/templates/_shared/lib/base/__pycache__/constants.cpython-313.pyc +0 -0
  106. package/dist/templates/_shared/lib/base/atomic_write.py +180 -0
  107. package/dist/templates/_shared/lib/base/constants.py +299 -0
  108. package/dist/templates/_shared/lib/base/inference.py +189 -0
  109. package/dist/templates/_shared/lib/base/utils.py +216 -0
  110. package/dist/templates/_shared/lib/context/__init__.py +119 -0
  111. package/dist/templates/_shared/lib/context/__pycache__/__init__.cpython-313.pyc +0 -0
  112. package/dist/templates/_shared/lib/context/__pycache__/cache.cpython-313.pyc +0 -0
  113. package/dist/templates/_shared/lib/context/__pycache__/context_manager.cpython-313.pyc +0 -0
  114. package/dist/templates/_shared/lib/context/__pycache__/event_log.cpython-313.pyc +0 -0
  115. package/dist/templates/_shared/lib/context/cache.py +446 -0
  116. package/dist/templates/_shared/lib/context/context_manager.py +1171 -0
  117. package/dist/templates/_shared/lib/context/discovery.py +486 -0
  118. package/dist/templates/_shared/lib/context/event_log.py +308 -0
  119. package/dist/templates/_shared/lib/context/plan_archive.py +247 -0
  120. package/dist/templates/_shared/lib/context/task_sync.py +367 -0
  121. package/dist/templates/_shared/lib/handoff/__init__.py +22 -0
  122. package/dist/templates/_shared/lib/handoff/document_generator.py +307 -0
  123. package/dist/templates/_shared/lib/templates/README.md +215 -0
  124. package/dist/templates/_shared/lib/templates/__init__.py +40 -0
  125. package/dist/templates/_shared/lib/templates/formatters.py +147 -0
  126. package/dist/templates/_shared/lib/templates/plan_context.py +119 -0
  127. package/dist/templates/_shared/scripts/save_handoff.py +99 -0
  128. package/dist/templates/_shared/workflows/handoff.md +212 -0
  129. package/dist/templates/cc-native/.claude/agents/cc-native/ACCESSIBILITY-TESTER.md +80 -0
  130. package/dist/templates/cc-native/.claude/agents/cc-native/ARCHITECT-REVIEWER.md +75 -0
  131. package/dist/templates/cc-native/.claude/agents/cc-native/ASSUMPTION-CHAIN-TRACER.md +239 -0
  132. package/dist/templates/cc-native/.claude/agents/cc-native/CLARITY-AUDITOR.md +109 -0
  133. package/dist/templates/cc-native/.claude/agents/cc-native/CODE-REVIEWER.md +71 -0
  134. package/dist/templates/cc-native/.claude/agents/cc-native/COMPLETENESS-CHECKER.md +104 -0
  135. package/dist/templates/cc-native/.claude/agents/cc-native/CONTEXT-EXTRACTOR.md +93 -0
  136. package/dist/templates/cc-native/.claude/agents/cc-native/DEVILS-ADVOCATE.md +223 -0
  137. package/dist/templates/cc-native/.claude/agents/cc-native/DOCUMENTATION-REVIEWER.md +73 -0
  138. package/dist/templates/cc-native/.claude/agents/cc-native/FEASIBILITY-ANALYST.md +93 -0
  139. package/dist/templates/cc-native/.claude/agents/cc-native/FRESH-PERSPECTIVE.md +103 -0
  140. package/dist/templates/cc-native/.claude/agents/cc-native/HANDOFF-READINESS.md +145 -0
  141. package/dist/templates/cc-native/.claude/agents/cc-native/HIDDEN-COMPLEXITY-DETECTOR.md +248 -0
  142. package/dist/templates/cc-native/.claude/agents/cc-native/INCENTIVE-MAPPER.md +235 -0
  143. package/dist/templates/cc-native/.claude/agents/cc-native/PENETRATION-TESTER.md +80 -0
  144. package/dist/templates/cc-native/.claude/agents/cc-native/PERFORMANCE-ENGINEER.md +76 -0
  145. package/dist/templates/cc-native/.claude/agents/cc-native/PLAN-ORCHESTRATOR.md +141 -0
  146. package/dist/templates/cc-native/.claude/agents/cc-native/PRECEDENT-FINDER.md +240 -0
  147. package/dist/templates/cc-native/.claude/agents/cc-native/REVERSIBILITY-ANALYST.md +211 -0
  148. package/dist/templates/cc-native/.claude/agents/cc-native/RISK-ASSESSOR.md +101 -0
  149. package/dist/templates/cc-native/.claude/agents/cc-native/SECOND-ORDER-ANALYST.md +197 -0
  150. package/dist/templates/cc-native/.claude/agents/cc-native/SIMPLICITY-GUARDIAN.md +97 -0
  151. package/dist/templates/cc-native/.claude/agents/cc-native/SKEPTIC.md +349 -0
  152. package/dist/templates/cc-native/.claude/agents/cc-native/STAKEHOLDER-ADVOCATE.md +106 -0
  153. package/dist/templates/cc-native/.claude/agents/cc-native/TRADE-OFF-ILLUMINATOR.md +205 -0
  154. package/dist/templates/cc-native/.claude/commands/cc-native/fresh-perspective.md +8 -0
  155. package/dist/templates/cc-native/.claude/commands/cc-native/specdev.md +10 -0
  156. package/dist/templates/cc-native/.claude/settings.json +119 -0
  157. package/dist/templates/cc-native/.windsurf/workflows/cc-native/fix.md +8 -0
  158. package/dist/templates/cc-native/.windsurf/workflows/cc-native/fresh-perspective.md +8 -0
  159. package/dist/templates/cc-native/.windsurf/workflows/cc-native/implement.md +8 -0
  160. package/dist/templates/cc-native/.windsurf/workflows/cc-native/research.md +8 -0
  161. package/dist/templates/cc-native/CC-NATIVE-README.md +192 -0
  162. package/dist/templates/cc-native/MIGRATION.md +86 -0
  163. package/dist/templates/cc-native/TEMPLATE-SCHEMA.md +331 -0
  164. package/dist/templates/cc-native/_cc-native/docs/PERMISSION_REQUEST_VERIFICATION.md +147 -0
  165. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/add_plan_context.cpython-313.pyc +0 -0
  166. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/archive_plan.cpython-313.pyc +0 -0
  167. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/cc-native-agent-review.cpython-313.pyc +0 -0
  168. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/cc-native-plan-review.cpython-313.pyc +0 -0
  169. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/test_permission_request.cpython-313.pyc +0 -0
  170. package/dist/templates/cc-native/_cc-native/hooks/add_plan_context.py +150 -0
  171. package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.py +746 -0
  172. package/dist/templates/cc-native/_cc-native/hooks/suggest-fresh-perspective.py +339 -0
  173. package/dist/templates/cc-native/_cc-native/lib/__init__.py +57 -0
  174. package/dist/templates/cc-native/_cc-native/lib/__pycache__/__init__.cpython-313.pyc +0 -0
  175. package/dist/templates/cc-native/_cc-native/lib/__pycache__/orchestrator.cpython-313.pyc +0 -0
  176. package/dist/templates/cc-native/_cc-native/lib/__pycache__/state.cpython-313.pyc +0 -0
  177. package/dist/templates/cc-native/_cc-native/lib/__pycache__/utils.cpython-313.pyc +0 -0
  178. package/dist/templates/cc-native/_cc-native/lib/async_archive.py +68 -0
  179. package/dist/templates/cc-native/_cc-native/lib/atomic_write.py +98 -0
  180. package/dist/templates/cc-native/_cc-native/lib/constants.py +45 -0
  181. package/dist/templates/cc-native/_cc-native/lib/orchestrator.py +273 -0
  182. package/dist/templates/cc-native/_cc-native/lib/reviewers/__init__.py +28 -0
  183. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/__init__.cpython-313.pyc +0 -0
  184. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/agent.cpython-313.pyc +0 -0
  185. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/base.cpython-313.pyc +0 -0
  186. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/codex.cpython-313.pyc +0 -0
  187. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/gemini.cpython-313.pyc +0 -0
  188. package/dist/templates/cc-native/_cc-native/lib/reviewers/agent.py +164 -0
  189. package/dist/templates/cc-native/_cc-native/lib/reviewers/base.py +89 -0
  190. package/dist/templates/cc-native/_cc-native/lib/reviewers/codex.py +119 -0
  191. package/dist/templates/cc-native/_cc-native/lib/reviewers/gemini.py +103 -0
  192. package/dist/templates/cc-native/_cc-native/lib/state.py +251 -0
  193. package/dist/templates/cc-native/_cc-native/lib/utils.py +830 -0
  194. package/dist/templates/cc-native/_cc-native/plan-review.config.json +76 -0
  195. package/dist/templates/cc-native/_cc-native/scripts/__pycache__/aggregate_agents.cpython-313.pyc +0 -0
  196. package/dist/templates/cc-native/_cc-native/scripts/aggregate_agents.py +151 -0
  197. package/dist/templates/cc-native/_cc-native/workflows/fresh-perspective.md +134 -0
  198. package/dist/templates/cc-native/_cc-native/workflows/specdev.md +9 -0
  199. package/dist/types/exit-codes.d.ts +11 -0
  200. package/dist/types/exit-codes.js +10 -0
  201. package/dist/types/index.d.ts +5 -0
  202. package/dist/types/index.js +7 -0
  203. package/oclif.manifest.json +405 -0
  204. package/package.json +109 -0
@@ -0,0 +1,5 @@
1
+ /**
2
+ * TypeScript interfaces for Claude Code settings.json structure
3
+ * Based on Claude Code documentation and research
4
+ */
5
+ export {};
@@ -0,0 +1,25 @@
1
+ /**
2
+ * AI Workflow CLI configuration interface.
3
+ * Contains all resolved paths for CLI operation.
4
+ */
5
+ export interface AiwcliConfig {
6
+ aiwDir: string;
7
+ claudeConfigPath: string;
8
+ settingsPath: string;
9
+ }
10
+ /**
11
+ * Resolve AI Workflow CLI home directory.
12
+ * Priority: AIW_DIR env var > ~/.aiw default
13
+ */
14
+ export declare function getAiwDir(): string;
15
+ /**
16
+ * Validate that AIW home directory exists.
17
+ * @throws {ConfigNotFoundError} When directory does not exist
18
+ */
19
+ export declare function validateAiwDir(aiwDir: string): void;
20
+ /**
21
+ * Load and validate AIW configuration.
22
+ * @returns Fully resolved AiwcliConfig with all paths
23
+ * @throws {ConfigNotFoundError} When AIW_DIR does not exist
24
+ */
25
+ export declare function loadConfig(): AiwcliConfig;
@@ -0,0 +1,46 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import { debug } from './debug.js';
5
+ import { getAiwDir as getAiwDirFromEnv } from './env-compat.js';
6
+ import { ConfigNotFoundError } from './errors.js';
7
+ /**
8
+ * Resolve AI Workflow CLI home directory.
9
+ * Priority: AIW_DIR env var > ~/.aiw default
10
+ */
11
+ export function getAiwDir() {
12
+ // Try env var first, then default
13
+ const envHome = getAiwDirFromEnv();
14
+ if (envHome) {
15
+ return envHome;
16
+ }
17
+ // Default to ~/.aiw
18
+ return join(homedir(), '.aiw');
19
+ }
20
+ /**
21
+ * Validate that AIW home directory exists.
22
+ * @throws {ConfigNotFoundError} When directory does not exist
23
+ */
24
+ export function validateAiwDir(aiwDir) {
25
+ if (!existsSync(aiwDir)) {
26
+ throw new ConfigNotFoundError(`AIW_DIR not found at ${aiwDir}. Run 'aiw setup' or set AIW_DIR env var.`);
27
+ }
28
+ }
29
+ /**
30
+ * Load and validate AIW configuration.
31
+ * @returns Fully resolved AiwcliConfig with all paths
32
+ * @throws {ConfigNotFoundError} When AIW_DIR does not exist
33
+ */
34
+ export function loadConfig() {
35
+ const aiwDir = getAiwDir();
36
+ debug(`Resolved AIW_DIR: ${aiwDir}`);
37
+ validateAiwDir(aiwDir);
38
+ const config = {
39
+ aiwDir,
40
+ claudeConfigPath: join(homedir(), '.claude'),
41
+ settingsPath: join(aiwDir, '.claude', 'settings.json'),
42
+ };
43
+ debug(`claudeConfigPath: ${config.claudeConfigPath}`);
44
+ debug(`settingsPath: ${config.settingsPath}`);
45
+ return config;
46
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Debug logging utilities for AI Workflow CLI.
3
+ * Provides conditional debug output with [debug] prefix.
4
+ */
5
+ /**
6
+ * Check if debug mode is enabled.
7
+ */
8
+ export declare function isDebugEnabled(): boolean;
9
+ /**
10
+ * Enable or disable debug mode.
11
+ */
12
+ export declare function setDebugEnabled(enabled: boolean): void;
13
+ /**
14
+ * Log a debug message if debug mode is enabled.
15
+ * Messages are prefixed with [debug] and output to stderr.
16
+ * @param message - The message to log
17
+ */
18
+ export declare function debug(message: string): void;
19
+ /**
20
+ * Log configuration details in debug mode.
21
+ * Only logs AIW_DIR path to avoid accidentally logging sensitive data.
22
+ * @param config - Configuration object
23
+ * @param config.aiwDir - AIW_DIR path
24
+ */
25
+ export declare function debugConfig(config: {
26
+ [key: string]: unknown;
27
+ aiwDir: string;
28
+ }): void;
29
+ /**
30
+ * Log process spawn details in debug mode.
31
+ * @param command - Command being spawned
32
+ * @param args - Arguments passed to command
33
+ */
34
+ export declare function debugSpawn(command: string, args: string[]): void;
35
+ /**
36
+ * Log version information in debug mode.
37
+ * Displays AI Workflow CLI version and Node.js version.
38
+ */
39
+ export declare function debugVersion(): void;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Debug logging utilities for AI Workflow CLI.
3
+ * Provides conditional debug output with [debug] prefix.
4
+ */
5
+ let debugEnabled = false;
6
+ /**
7
+ * Check if debug mode is enabled.
8
+ */
9
+ export function isDebugEnabled() {
10
+ return debugEnabled;
11
+ }
12
+ /**
13
+ * Enable or disable debug mode.
14
+ */
15
+ export function setDebugEnabled(enabled) {
16
+ debugEnabled = enabled;
17
+ }
18
+ /**
19
+ * Log a debug message if debug mode is enabled.
20
+ * Messages are prefixed with [debug] and output to stderr.
21
+ * @param message - The message to log
22
+ */
23
+ export function debug(message) {
24
+ if (debugEnabled) {
25
+ // Use dim color if terminal supports it, otherwise plain text
26
+ const supportsColor = process.stderr.isTTY;
27
+ if (supportsColor) {
28
+ // ANSI dim: \u001B[2m, reset: \u001B[0m
29
+ process.stderr.write(`\u001B[2m[debug] ${message}\u001B[0m\n`);
30
+ }
31
+ else {
32
+ process.stderr.write(`[debug] ${message}\n`);
33
+ }
34
+ }
35
+ }
36
+ /**
37
+ * Log configuration details in debug mode.
38
+ * Only logs AIW_DIR path to avoid accidentally logging sensitive data.
39
+ * @param config - Configuration object
40
+ * @param config.aiwDir - AIW_DIR path
41
+ */
42
+ export function debugConfig(config) {
43
+ debug(`AIW_DIR resolved to ${config.aiwDir}`);
44
+ // NOTE: Do NOT log full config - may contain API keys/tokens in future
45
+ }
46
+ /**
47
+ * Log process spawn details in debug mode.
48
+ * @param command - Command being spawned
49
+ * @param args - Arguments passed to command
50
+ */
51
+ export function debugSpawn(command, args) {
52
+ debug(`Spawning: ${command} ${args.join(' ')}`);
53
+ }
54
+ /**
55
+ * Log version information in debug mode.
56
+ * Displays AI Workflow CLI version and Node.js version.
57
+ */
58
+ export function debugVersion() {
59
+ // Read version from package.json
60
+ // Note: process.env.npm_package_version only works during npm scripts
61
+ // For production, we need to read package.json directly
62
+ let version = 'unknown';
63
+ try {
64
+ // In ESM, we can use import.meta.url to resolve relative to this file
65
+ // For now, use env var with fallback (will be 'unknown' in production until fixed properly)
66
+ version = process.env.npm_package_version || '0.1.0';
67
+ }
68
+ catch {
69
+ version = '0.1.0';
70
+ }
71
+ debug(`AI Workflow CLI v${version}`);
72
+ debug(`Node.js ${process.version}`);
73
+ debug(`Platform: ${process.platform} ${process.arch}`);
74
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Environment Variable Layer
3
+ *
4
+ * Provides environment variable resolution for AIW CLI.
5
+ *
6
+ * Environment variables:
7
+ * - AIW_DIR: Main installation directory
8
+ * - AIW_CONFIG: Configuration file path
9
+ */
10
+ /**
11
+ * Load environment variables.
12
+ * Call this early in application bootstrap.
13
+ */
14
+ export declare function loadEnvWithCompatibility(): void;
15
+ /**
16
+ * Get AIW_DIR environment variable
17
+ */
18
+ export declare function getAiwDir(): string | undefined;
19
+ /**
20
+ * Get AIW_CONFIG environment variable
21
+ */
22
+ export declare function getAiwConfig(): string | undefined;
23
+ /**
24
+ * Check if using legacy environment variables
25
+ */
26
+ export declare function isUsingLegacyEnvVars(): boolean;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Environment Variable Layer
3
+ *
4
+ * Provides environment variable resolution for AIW CLI.
5
+ *
6
+ * Environment variables:
7
+ * - AIW_DIR: Main installation directory
8
+ * - AIW_CONFIG: Configuration file path
9
+ */
10
+ /**
11
+ * Load environment variables.
12
+ * Call this early in application bootstrap.
13
+ */
14
+ export function loadEnvWithCompatibility() {
15
+ // DA (Assistant name) - Keep for backward compatibility, no warning
16
+ // This is commonly used and doesn't need migration
17
+ }
18
+ /**
19
+ * Get AIW_DIR environment variable
20
+ */
21
+ export function getAiwDir() {
22
+ return process.env['AIW_DIR'];
23
+ }
24
+ /**
25
+ * Get AIW_CONFIG environment variable
26
+ */
27
+ export function getAiwConfig() {
28
+ return process.env['AIW_CONFIG'];
29
+ }
30
+ /**
31
+ * Check if using legacy environment variables
32
+ */
33
+ export function isUsingLegacyEnvVars() {
34
+ return false;
35
+ }
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @file Error handling classes and utilities for AI Workflow CLI.
3
+ *
4
+ * This module provides:
5
+ * - Custom error classes with exit codes
6
+ * - Error message formatting utilities
7
+ * - Error handling patterns for commands
8
+ *
9
+ * ## Error Handling Patterns for Commands
10
+ *
11
+ * ### Basic Pattern (Recommended)
12
+ * ```typescript
13
+ * import {Command} from '@oclif/core'
14
+ * import {ConfigNotFoundError, InvalidUsageError} from '../lib/errors.js'
15
+ *
16
+ * export default class LaunchCommand extends Command {
17
+ * async run() {
18
+ * try {
19
+ * const config = await loadConfig()
20
+ * await launchClaude(config)
21
+ * } catch (error) {
22
+ * if (error instanceof ConfigNotFoundError) {
23
+ * this.error(error.message, {exit: error.exitCode})
24
+ * }
25
+ * if (error instanceof InvalidUsageError) {
26
+ * this.error(error.message, {exit: error.exitCode})
27
+ * }
28
+ * this.error(`Unexpected error: ${error.message}`, {exit: EXIT_CODES.GENERAL_ERROR})
29
+ * }
30
+ * }
31
+ * }
32
+ * ```
33
+ *
34
+ * ### Using this.error() vs throwing custom errors
35
+ * - **Throw custom errors** in library code (src/lib/) for business logic failures
36
+ * - **Catch and translate** in commands using this.error() for user-facing output
37
+ * - **this.error()** automatically outputs to stderr and exits with specified code
38
+ *
39
+ * ### Exit Code Guidelines
40
+ * - **EXIT_CODES.SUCCESS (0)**: Command completed successfully
41
+ * - **EXIT_CODES.GENERAL_ERROR (1)**: Unexpected errors, system failures, unhandled exceptions
42
+ * - **EXIT_CODES.INVALID_USAGE (2)**: User provided invalid arguments, flags, or usage patterns
43
+ * - **EXIT_CODES.ENVIRONMENT_ERROR (3)**: Missing prerequisites, config not found, environment setup issues
44
+ *
45
+ * @module lib/errors
46
+ */
47
+ import { type ExitCode } from '../types/index.js';
48
+ /**
49
+ * Base error class for AI Workflow CLI.
50
+ * All custom errors extend this class and include an exit code.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * throw new AiwError('Unexpected system error occurred. Check logs for details.', EXIT_CODES.GENERAL_ERROR)
55
+ * ```
56
+ */
57
+ export declare class AiwError extends Error {
58
+ readonly exitCode: ExitCode;
59
+ constructor(message: string, exitCode?: ExitCode);
60
+ }
61
+ /**
62
+ * Error thrown when AIW configuration cannot be found.
63
+ * Indicates AIW_DIR is not set or points to a non-existent directory.
64
+ * Exit code: 3 (ENVIRONMENT_ERROR)
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * throw new ConfigNotFoundError('AIW_DIR not found. Set AIW_DIR env var or run \'aiw setup\'.')
69
+ * ```
70
+ */
71
+ export declare class ConfigNotFoundError extends AiwError {
72
+ constructor(message: string);
73
+ }
74
+ /**
75
+ * Error thrown when environment prerequisites are missing.
76
+ * Used for missing dependencies, required tools not in PATH, or system requirements not met.
77
+ * Exit code: 3 (ENVIRONMENT_ERROR)
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * throw new EnvironmentError('Claude Code CLI not found in PATH. Install from https://claude.ai.')
82
+ * ```
83
+ */
84
+ export declare class EnvironmentError extends AiwError {
85
+ constructor(message: string);
86
+ }
87
+ /**
88
+ * Error thrown when user provides invalid arguments or usage.
89
+ * Used for user-fixable errors like invalid flags or missing required arguments.
90
+ * Exit code: 2 (INVALID_USAGE)
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * throw new InvalidUsageError('Invalid --format value \'xyz\'. Use \'json\' or \'text\'.')
95
+ * ```
96
+ */
97
+ export declare class InvalidUsageError extends AiwError {
98
+ constructor(message: string);
99
+ }
100
+ /**
101
+ * Error thrown when process spawning fails.
102
+ * Used for spawn errors like ENOENT (command not found) or EACCES (permission denied).
103
+ * Exit code: 3 (ENVIRONMENT_ERROR)
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * throw new ProcessSpawnError('Command not found: claude. Install Claude Code from https://claude.ai/download.')
108
+ * ```
109
+ */
110
+ export declare class ProcessSpawnError extends AiwError {
111
+ readonly code?: string | undefined;
112
+ constructor(message: string, code?: string | undefined);
113
+ }
114
+ /**
115
+ * Format error message following AI Workflow CLI convention.
116
+ * @param what - Description of what went wrong
117
+ * @param howToFix - Actionable steps to fix the problem
118
+ * @returns Formatted error message in format: "{what}. {howToFix}."
119
+ * @example
120
+ * formatErrorMessage(
121
+ * 'AIW_DIR directory not found',
122
+ * 'Set AIW_DIR env var or run "aiw setup"'
123
+ * )
124
+ * // Returns: "AIW_DIR directory not found. Set AIW_DIR env var or run \"aiw setup\"."
125
+ */
126
+ export declare function formatErrorMessage(what: string, howToFix: string): string;
@@ -0,0 +1,145 @@
1
+ /**
2
+ * @file Error handling classes and utilities for AI Workflow CLI.
3
+ *
4
+ * This module provides:
5
+ * - Custom error classes with exit codes
6
+ * - Error message formatting utilities
7
+ * - Error handling patterns for commands
8
+ *
9
+ * ## Error Handling Patterns for Commands
10
+ *
11
+ * ### Basic Pattern (Recommended)
12
+ * ```typescript
13
+ * import {Command} from '@oclif/core'
14
+ * import {ConfigNotFoundError, InvalidUsageError} from '../lib/errors.js'
15
+ *
16
+ * export default class LaunchCommand extends Command {
17
+ * async run() {
18
+ * try {
19
+ * const config = await loadConfig()
20
+ * await launchClaude(config)
21
+ * } catch (error) {
22
+ * if (error instanceof ConfigNotFoundError) {
23
+ * this.error(error.message, {exit: error.exitCode})
24
+ * }
25
+ * if (error instanceof InvalidUsageError) {
26
+ * this.error(error.message, {exit: error.exitCode})
27
+ * }
28
+ * this.error(`Unexpected error: ${error.message}`, {exit: EXIT_CODES.GENERAL_ERROR})
29
+ * }
30
+ * }
31
+ * }
32
+ * ```
33
+ *
34
+ * ### Using this.error() vs throwing custom errors
35
+ * - **Throw custom errors** in library code (src/lib/) for business logic failures
36
+ * - **Catch and translate** in commands using this.error() for user-facing output
37
+ * - **this.error()** automatically outputs to stderr and exits with specified code
38
+ *
39
+ * ### Exit Code Guidelines
40
+ * - **EXIT_CODES.SUCCESS (0)**: Command completed successfully
41
+ * - **EXIT_CODES.GENERAL_ERROR (1)**: Unexpected errors, system failures, unhandled exceptions
42
+ * - **EXIT_CODES.INVALID_USAGE (2)**: User provided invalid arguments, flags, or usage patterns
43
+ * - **EXIT_CODES.ENVIRONMENT_ERROR (3)**: Missing prerequisites, config not found, environment setup issues
44
+ *
45
+ * @module lib/errors
46
+ */
47
+ import { EXIT_CODES } from '../types/index.js';
48
+ /**
49
+ * Base error class for AI Workflow CLI.
50
+ * All custom errors extend this class and include an exit code.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * throw new AiwError('Unexpected system error occurred. Check logs for details.', EXIT_CODES.GENERAL_ERROR)
55
+ * ```
56
+ */
57
+ export class AiwError extends Error {
58
+ exitCode;
59
+ constructor(message, exitCode = EXIT_CODES.GENERAL_ERROR) {
60
+ super(message);
61
+ this.exitCode = exitCode;
62
+ this.name = 'AiwError';
63
+ }
64
+ }
65
+ /**
66
+ * Error thrown when AIW configuration cannot be found.
67
+ * Indicates AIW_DIR is not set or points to a non-existent directory.
68
+ * Exit code: 3 (ENVIRONMENT_ERROR)
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * throw new ConfigNotFoundError('AIW_DIR not found. Set AIW_DIR env var or run \'aiw setup\'.')
73
+ * ```
74
+ */
75
+ export class ConfigNotFoundError extends AiwError {
76
+ constructor(message) {
77
+ super(message, EXIT_CODES.ENVIRONMENT_ERROR);
78
+ this.name = 'ConfigNotFoundError';
79
+ }
80
+ }
81
+ /**
82
+ * Error thrown when environment prerequisites are missing.
83
+ * Used for missing dependencies, required tools not in PATH, or system requirements not met.
84
+ * Exit code: 3 (ENVIRONMENT_ERROR)
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * throw new EnvironmentError('Claude Code CLI not found in PATH. Install from https://claude.ai.')
89
+ * ```
90
+ */
91
+ export class EnvironmentError extends AiwError {
92
+ constructor(message) {
93
+ super(message, EXIT_CODES.ENVIRONMENT_ERROR);
94
+ this.name = 'EnvironmentError';
95
+ }
96
+ }
97
+ /**
98
+ * Error thrown when user provides invalid arguments or usage.
99
+ * Used for user-fixable errors like invalid flags or missing required arguments.
100
+ * Exit code: 2 (INVALID_USAGE)
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * throw new InvalidUsageError('Invalid --format value \'xyz\'. Use \'json\' or \'text\'.')
105
+ * ```
106
+ */
107
+ export class InvalidUsageError extends AiwError {
108
+ constructor(message) {
109
+ super(message, EXIT_CODES.INVALID_USAGE);
110
+ this.name = 'InvalidUsageError';
111
+ }
112
+ }
113
+ /**
114
+ * Error thrown when process spawning fails.
115
+ * Used for spawn errors like ENOENT (command not found) or EACCES (permission denied).
116
+ * Exit code: 3 (ENVIRONMENT_ERROR)
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * throw new ProcessSpawnError('Command not found: claude. Install Claude Code from https://claude.ai/download.')
121
+ * ```
122
+ */
123
+ export class ProcessSpawnError extends AiwError {
124
+ code;
125
+ constructor(message, code) {
126
+ super(message, EXIT_CODES.ENVIRONMENT_ERROR);
127
+ this.code = code;
128
+ this.name = 'ProcessSpawnError';
129
+ }
130
+ }
131
+ /**
132
+ * Format error message following AI Workflow CLI convention.
133
+ * @param what - Description of what went wrong
134
+ * @param howToFix - Actionable steps to fix the problem
135
+ * @returns Formatted error message in format: "{what}. {howToFix}."
136
+ * @example
137
+ * formatErrorMessage(
138
+ * 'AIW_DIR directory not found',
139
+ * 'Set AIW_DIR env var or run "aiw setup"'
140
+ * )
141
+ * // Returns: "AIW_DIR directory not found. Set AIW_DIR env var or run \"aiw setup\"."
142
+ */
143
+ export function formatErrorMessage(what, howToFix) {
144
+ return `${what}. ${howToFix}.`;
145
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @file Generic merge utilities for configuration merging.
3
+ *
4
+ * This module provides reusable utilities for merging arrays with deduplication
5
+ * and merging configuration objects by event type. Used by hook merger modules
6
+ * to eliminate code duplication.
7
+ *
8
+ * ## Usage
9
+ * ```typescript
10
+ * import { mergeArraysWithDedup, mergeConfigByEventType } from '../lib/generic-merge.js'
11
+ *
12
+ * // Merge arrays with custom equality
13
+ * const merged = mergeArraysWithDedup(existing, template, (a, b) => a.id === b.id)
14
+ *
15
+ * // Merge config objects by event type
16
+ * const mergedConfig = mergeConfigByEventType(
17
+ * existingConfig,
18
+ * templateConfig,
19
+ * (existing, template) => mergeArraysWithDedup(existing, template, areEqual)
20
+ * )
21
+ * ```
22
+ *
23
+ * @module lib/generic-merge
24
+ */
25
+ /**
26
+ * Merge two arrays with deduplication based on custom equality function.
27
+ *
28
+ * Items from the template array are appended to the existing array only if
29
+ * no equivalent item exists. Order is preserved: existing items first.
30
+ *
31
+ * @template T - Type of array elements
32
+ * @param existing - Existing array (preserved in order)
33
+ * @param template - Template array to merge (items appended if not duplicate)
34
+ * @param areEqual - Function to check if two items are equivalent
35
+ * @returns New merged array with duplicates removed
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const merged = mergeArraysWithDedup(
40
+ * [{id: 1, name: 'a'}],
41
+ * [{id: 1, name: 'b'}, {id: 2, name: 'c'}],
42
+ * (a, b) => a.id === b.id
43
+ * )
44
+ * // Result: [{id: 1, name: 'a'}, {id: 2, name: 'c'}]
45
+ * ```
46
+ */
47
+ export declare function mergeArraysWithDedup<T>(existing: T[], template: T[], areEqual: (a: T, b: T) => boolean): T[];
48
+ /**
49
+ * Merge configuration objects organized by event type.
50
+ *
51
+ * Each configuration maps event types to arrays of items. This function
52
+ * merges configurations by:
53
+ * 1. Collecting all event types from both configurations
54
+ * 2. For each event type, merging the arrays using the provided merge function
55
+ *
56
+ * @template TEventType - Type of event type keys (typically string union)
57
+ * @template TItem - Type of items in the arrays
58
+ * @template TConfig - Type of the configuration object
59
+ * @param existing - Existing configuration (may be undefined)
60
+ * @param template - Template configuration to merge (may be undefined)
61
+ * @param mergeArrays - Function to merge arrays for a single event type
62
+ * @returns New merged configuration
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const mergedConfig = mergeConfigByEventType(
67
+ * {click: [handler1], hover: [handler2]},
68
+ * {click: [handler3], focus: [handler4]},
69
+ * (existing, template) => mergeArraysWithDedup(existing, template, areEqual)
70
+ * )
71
+ * // Result: {click: [handler1, handler3], hover: [handler2], focus: [handler4]}
72
+ * ```
73
+ */
74
+ export declare function mergeConfigByEventType<TEventType extends string, TItem, TConfig extends Partial<Record<TEventType, TItem[]>>>(existing: TConfig | undefined, template: TConfig | undefined, mergeArrays: (existing: TItem[], template: TItem[]) => TItem[]): TConfig;