@bicorne/task-flow 0.1.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 (118) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +252 -0
  3. package/SKILL.md +250 -0
  4. package/assets/.harnessrc +10 -0
  5. package/assets/PHASE-task.json.example +50 -0
  6. package/assets/design.md +69 -0
  7. package/assets/hooks.json +15 -0
  8. package/assets/product-requirement.md +82 -0
  9. package/assets/schema.json +127 -0
  10. package/assets/tasks.md +26 -0
  11. package/dist/commands/analyze.d.ts +32 -0
  12. package/dist/commands/analyze.js +338 -0
  13. package/dist/commands/archive.d.ts +11 -0
  14. package/dist/commands/archive.js +53 -0
  15. package/dist/commands/design.d.ts +38 -0
  16. package/dist/commands/design.js +492 -0
  17. package/dist/commands/extract.d.ts +31 -0
  18. package/dist/commands/extract.js +477 -0
  19. package/dist/commands/init.d.ts +24 -0
  20. package/dist/commands/init.js +165 -0
  21. package/dist/commands/merge/index.d.ts +17 -0
  22. package/dist/commands/merge/index.js +322 -0
  23. package/dist/commands/merge/merger.d.ts +18 -0
  24. package/dist/commands/merge/merger.js +151 -0
  25. package/dist/commands/merge/types.d.ts +67 -0
  26. package/dist/commands/merge/types.js +6 -0
  27. package/dist/commands/merge/validators.d.ts +14 -0
  28. package/dist/commands/merge/validators.js +147 -0
  29. package/dist/commands/merge.d.ts +7 -0
  30. package/dist/commands/merge.js +15 -0
  31. package/dist/commands/start.d.ts +32 -0
  32. package/dist/commands/start.js +265 -0
  33. package/dist/commands/status.d.ts +15 -0
  34. package/dist/commands/status.js +143 -0
  35. package/dist/commands/sync.d.ts +11 -0
  36. package/dist/commands/sync.js +58 -0
  37. package/dist/commands/tasks-gen/doc-parser.d.ts +7 -0
  38. package/dist/commands/tasks-gen/doc-parser.js +259 -0
  39. package/dist/commands/tasks-gen/generators.d.ts +33 -0
  40. package/dist/commands/tasks-gen/generators.js +141 -0
  41. package/dist/commands/tasks-gen/index.d.ts +30 -0
  42. package/dist/commands/tasks-gen/index.js +345 -0
  43. package/dist/commands/tasks-gen/parsers.d.ts +29 -0
  44. package/dist/commands/tasks-gen/parsers.js +272 -0
  45. package/dist/commands/tasks-gen/templates.d.ts +8 -0
  46. package/dist/commands/tasks-gen/templates.js +37 -0
  47. package/dist/commands/tasks-gen/types.d.ts +71 -0
  48. package/dist/commands/tasks-gen/types.js +17 -0
  49. package/dist/commands/tasks-gen/validators.d.ts +14 -0
  50. package/dist/commands/tasks-gen/validators.js +54 -0
  51. package/dist/commands/tasks.d.ts +9 -0
  52. package/dist/commands/tasks.js +22 -0
  53. package/dist/commands/worktree.d.ts +28 -0
  54. package/dist/commands/worktree.js +275 -0
  55. package/dist/hooks/check-prd-exists.d.ts +20 -0
  56. package/dist/hooks/check-prd-exists.js +61 -0
  57. package/dist/hooks/check-worktree-conflict.d.ts +34 -0
  58. package/dist/hooks/check-worktree-conflict.js +107 -0
  59. package/dist/hooks/hook-runner/executor.d.ts +18 -0
  60. package/dist/hooks/hook-runner/executor.js +143 -0
  61. package/dist/hooks/hook-runner/index.d.ts +64 -0
  62. package/dist/hooks/hook-runner/index.js +220 -0
  63. package/dist/hooks/hook-runner/loader.d.ts +23 -0
  64. package/dist/hooks/hook-runner/loader.js +126 -0
  65. package/dist/hooks/hook-runner/types.d.ts +59 -0
  66. package/dist/hooks/hook-runner/types.js +6 -0
  67. package/dist/hooks/hook-runner.d.ts +9 -0
  68. package/dist/hooks/hook-runner.js +30 -0
  69. package/dist/hooks/phase-complete-detector.d.ts +35 -0
  70. package/dist/hooks/phase-complete-detector.js +203 -0
  71. package/dist/hooks/phase-gate-validator.d.ts +76 -0
  72. package/dist/hooks/phase-gate-validator.js +407 -0
  73. package/dist/hooks/save-checkpoint.d.ts +43 -0
  74. package/dist/hooks/save-checkpoint.js +144 -0
  75. package/dist/hooks/start-mcp-servers.d.ts +50 -0
  76. package/dist/hooks/start-mcp-servers.js +75 -0
  77. package/dist/hooks/stop-mcp-servers.d.ts +40 -0
  78. package/dist/hooks/stop-mcp-servers.js +58 -0
  79. package/dist/index.d.ts +29 -0
  80. package/dist/index.js +238 -0
  81. package/dist/lib/archive.d.ts +31 -0
  82. package/dist/lib/archive.js +226 -0
  83. package/dist/lib/config.d.ts +93 -0
  84. package/dist/lib/config.js +251 -0
  85. package/dist/lib/constants.d.ts +222 -0
  86. package/dist/lib/constants.js +247 -0
  87. package/dist/lib/interactive.d.ts +31 -0
  88. package/dist/lib/interactive.js +166 -0
  89. package/dist/lib/mcp-client.d.ts +156 -0
  90. package/dist/lib/mcp-client.js +370 -0
  91. package/dist/lib/state.d.ts +119 -0
  92. package/dist/lib/state.js +293 -0
  93. package/dist/slash/executor.d.ts +22 -0
  94. package/dist/slash/executor.js +259 -0
  95. package/dist/slash/index.d.ts +11 -0
  96. package/dist/slash/index.js +45 -0
  97. package/dist/slash/parser.d.ts +24 -0
  98. package/dist/slash/parser.js +101 -0
  99. package/dist/slash/registry.d.ts +22 -0
  100. package/dist/slash/registry.js +155 -0
  101. package/dist/spec/openspec-to-task/builders.d.ts +107 -0
  102. package/dist/spec/openspec-to-task/builders.js +138 -0
  103. package/dist/spec/openspec-to-task/index.d.ts +20 -0
  104. package/dist/spec/openspec-to-task/index.js +182 -0
  105. package/dist/spec/openspec-to-task/parsers.d.ts +65 -0
  106. package/dist/spec/openspec-to-task/parsers.js +232 -0
  107. package/dist/spec/openspec-to-task/types.d.ts +49 -0
  108. package/dist/spec/openspec-to-task/types.js +6 -0
  109. package/dist/spec/sync-openspec-to-task.d.ts +7 -0
  110. package/dist/spec/sync-openspec-to-task.js +21 -0
  111. package/dist/spec/sync-task-to-openspec.d.ts +27 -0
  112. package/dist/spec/sync-task-to-openspec.js +288 -0
  113. package/dist/types/ai-context.d.ts +108 -0
  114. package/dist/types/ai-context.js +9 -0
  115. package/package.json +66 -0
  116. package/references/AI-CONVERSATION-TUTORIAL.md +270 -0
  117. package/references/CLI-TUTORIAL.md +447 -0
  118. package/references/GIT-WORKTREE-SOP.md +109 -0
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ /**
3
+ * lib/constants.ts
4
+ * Shared constants and magic strings for task-flow
5
+ *
6
+ * Centralizes all magic strings, status values, phase names, and error codes
7
+ * to ensure consistency across the codebase.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.DEFAULTS = exports.ERROR_CODES = exports.EVENT_TYPES = exports.SKILL_FORMAT = exports.AGENT_TYPES = exports.VALIDATION_ALIASES = exports.GATE_VALIDATIONS = exports.HOOK_NAMES = exports.STATE_FILES = exports.DIR_NAMES = exports.FILE_PATTERNS = exports.ALLOWED_COMMANDS = exports.DEFAULT_MERGE_CONFIG = exports.MERGE_TYPE = exports.VALIDATED_STATUSES = exports.VALIDATION_STATUS = exports.REVIEW_CONCLUSION = exports.STATUS = exports.PHASE = void 0;
11
+ exports.isAllowedCommand = isAllowedCommand;
12
+ /**
13
+ * Phase names
14
+ */
15
+ exports.PHASE = {
16
+ PLANNING: 'planning',
17
+ IMPLEMENTATION: 'implementation',
18
+ REVIEW: 'review',
19
+ MERGE: 'merge',
20
+ };
21
+ /**
22
+ * Status values
23
+ */
24
+ exports.STATUS = {
25
+ PENDING: 'pending',
26
+ RUNNING: 'running',
27
+ COMPLETED: 'completed',
28
+ BLOCKED: 'blocked',
29
+ FAILED: 'failed',
30
+ SKIPPED: 'skipped',
31
+ ACTIVE: 'active',
32
+ };
33
+ /**
34
+ * Review conclusions
35
+ */
36
+ exports.REVIEW_CONCLUSION = {
37
+ PASS: 'PASS',
38
+ NEEDS_WORK: 'NEEDS_WORK',
39
+ FAIL: 'FAIL',
40
+ };
41
+ /**
42
+ * Validation status values
43
+ */
44
+ exports.VALIDATION_STATUS = {
45
+ PASS: 'pass',
46
+ PASSED: 'passed',
47
+ SUCCESS: 'success',
48
+ OK: 'ok',
49
+ TRUE: 'true',
50
+ FAIL: 'fail',
51
+ FAILED: 'failed',
52
+ };
53
+ /**
54
+ * Validated status values (for passed validations)
55
+ */
56
+ exports.VALIDATED_STATUSES = [
57
+ exports.VALIDATION_STATUS.PASS,
58
+ exports.VALIDATION_STATUS.PASSED,
59
+ exports.VALIDATION_STATUS.SUCCESS,
60
+ exports.VALIDATION_STATUS.OK,
61
+ exports.VALIDATION_STATUS.TRUE,
62
+ ];
63
+ /**
64
+ * Merge strategy types
65
+ */
66
+ exports.MERGE_TYPE = {
67
+ SQUASH: 'squash',
68
+ MERGE: 'merge',
69
+ REBASE: 'rebase',
70
+ };
71
+ /**
72
+ * Default merge configuration
73
+ */
74
+ exports.DEFAULT_MERGE_CONFIG = {
75
+ type: exports.MERGE_TYPE.SQUASH,
76
+ deleteBranch: true,
77
+ deleteWorktree: true,
78
+ };
79
+ /**
80
+ * Allowed commands for CLI execution (security whitelist)
81
+ */
82
+ exports.ALLOWED_COMMANDS = [
83
+ 'git',
84
+ 'node',
85
+ 'pnpm',
86
+ 'npm',
87
+ 'yarn',
88
+ 'tsc',
89
+ 'eslint',
90
+ 'prettier',
91
+ 'jest',
92
+ 'vitest',
93
+ 'mocha',
94
+ 'tsx',
95
+ 'ts-node',
96
+ ];
97
+ /**
98
+ * Check if a command is allowed
99
+ * @param cmd - Command to check
100
+ * @returns True if command is allowed
101
+ */
102
+ function isAllowedCommand(cmd) {
103
+ return exports.ALLOWED_COMMANDS.includes(cmd);
104
+ }
105
+ /**
106
+ * File patterns
107
+ */
108
+ exports.FILE_PATTERNS = {
109
+ TASK_JSON: /^.+\.json$/,
110
+ SNAPSHOT_JSON: /.+-impl\.json$/,
111
+ REVIEW_MD: /.+-review\.md$/,
112
+ PROPOSAL_MD: /^proposal\.md$/,
113
+ DESIGN_MD: /^design\.md$/,
114
+ TASKS_MD: /^tasks\.md$/,
115
+ EXECUTION_JSON: /^execution\.json$/,
116
+ MANIFEST_JSON: /^manifest\.json$/,
117
+ };
118
+ /**
119
+ * Directory names
120
+ */
121
+ exports.DIR_NAMES = {
122
+ HARNESS: '.harness',
123
+ SPEC: 'spec',
124
+ CHANGES: 'changes',
125
+ TASKS: 'tasks',
126
+ SNAPSHOTS: 'snapshots',
127
+ REPORTS: 'reports',
128
+ ARCHIVE: 'archive',
129
+ WORKTREES: '.worktrees',
130
+ SKILLS: 'skills',
131
+ };
132
+ /**
133
+ * State file names
134
+ */
135
+ exports.STATE_FILES = {
136
+ STATE: 'state.json',
137
+ CONFIG: '.harnessrc',
138
+ HOOKS: 'hooks.json',
139
+ MCP: 'mcp.json',
140
+ SKILLS: 'skills.json',
141
+ };
142
+ /**
143
+ * Hook names
144
+ */
145
+ exports.HOOK_NAMES = {
146
+ PRE_DESIGN: 'pre-design',
147
+ POST_DESIGN: 'post-design',
148
+ PRE_TASKS: 'pre-tasks',
149
+ POST_TASKS: 'post-tasks',
150
+ PRE_WORKTREE: 'pre-worktree',
151
+ POST_WORKTREE: 'post-worktree',
152
+ PRE_SNAPSHOT: 'pre-snapshot',
153
+ POST_SNAPSHOT: 'post-snapshot',
154
+ PRE_REVIEW: 'pre-review',
155
+ POST_REVIEW: 'post-review',
156
+ PRE_MERGE: 'pre-merge',
157
+ POST_MERGE: 'post-merge',
158
+ };
159
+ /**
160
+ * Gate validation names
161
+ */
162
+ exports.GATE_VALIDATIONS = {
163
+ BUILD_PASSES: 'build-passes',
164
+ TESTS_PASS: 'tests-pass',
165
+ TYPECHECK_PASSES: 'typecheck-passes',
166
+ LINT_PASSES: 'lint-passes',
167
+ SECURITY_CHECK: 'security-check',
168
+ COVERAGE_GE_80: 'coverage-ge-80',
169
+ REVIEW_CONCLUSION: 'review-conclusion',
170
+ PLANNING_READY: 'planning-ready',
171
+ };
172
+ /**
173
+ * Validation aliases (maps validation name to alternative names)
174
+ */
175
+ exports.VALIDATION_ALIASES = {
176
+ [exports.GATE_VALIDATIONS.BUILD_PASSES]: ['build-passes', 'build-pass', 'build', 'build-success'],
177
+ [exports.GATE_VALIDATIONS.TESTS_PASS]: ['tests-pass', 'test-pass', 'tests', 'test', 'unit-tests-pass'],
178
+ [exports.GATE_VALIDATIONS.TYPECHECK_PASSES]: ['typecheck-passes', 'type-check', 'typecheck', 'typescript-pass'],
179
+ [exports.GATE_VALIDATIONS.LINT_PASSES]: ['lint-passes', 'lint-pass', 'lint'],
180
+ [exports.GATE_VALIDATIONS.SECURITY_CHECK]: ['security-check', 'security-scan', 'security-review'],
181
+ [exports.GATE_VALIDATIONS.COVERAGE_GE_80]: ['coverage-ge-80', 'coverage-threshold', 'coverage-passes'],
182
+ [exports.GATE_VALIDATIONS.REVIEW_CONCLUSION]: ['review-conclusion', 'conclusion'],
183
+ };
184
+ /**
185
+ * Agent types
186
+ */
187
+ exports.AGENT_TYPES = {
188
+ CLAUDE_CODE: 'claude-code',
189
+ TRAE: 'trae',
190
+ QODER: 'qoder',
191
+ };
192
+ /**
193
+ * Skill formats
194
+ */
195
+ exports.SKILL_FORMAT = {
196
+ COPY_SKILL_MD: 'copy-skill-md',
197
+ COPY_DIRECTORY: 'copy-directory',
198
+ SYMLINK: 'symlink',
199
+ };
200
+ /**
201
+ * Event types for archiving
202
+ */
203
+ exports.EVENT_TYPES = {
204
+ TASK_STARTED: 'task_started',
205
+ PHASE_STARTED: 'phase_started',
206
+ PHASE_COMPLETED: 'phase_completed',
207
+ SNAPSHOT_CREATED: 'snapshot_created',
208
+ REVIEW_COMPLETED: 'review_completed',
209
+ TASK_MERGED: 'task_merged',
210
+ TASK_COMPLETED: 'task_completed',
211
+ GATE_BLOCKED: 'gate_blocked',
212
+ };
213
+ /**
214
+ * Error codes
215
+ */
216
+ exports.ERROR_CODES = {
217
+ MISSING_CHANGE: 'missing-change',
218
+ INVALID_CHANGE: 'invalid-change',
219
+ MISSING_TASK_ID: 'missing-task-id',
220
+ INVALID_TASK_ID: 'invalid-task-id',
221
+ MISSING_TASK_FILE: 'missing-task-file',
222
+ MISSING_SPEC: 'missing-spec',
223
+ MISSING_METADATA: 'missing-metadata',
224
+ ALREADY_EXISTS: 'already-exists',
225
+ NOT_FOUND: 'not-found',
226
+ VALIDATION_FAILED: 'validation-failed',
227
+ GATE_BLOCKED: 'gate-blocked',
228
+ MERGE_FAILED: 'merge-failed',
229
+ WORKTREE_CONFLICT: 'worktree-conflict',
230
+ REVIEW_NOT_PASSED: 'review-not-passed',
231
+ MISSING_REVIEW: 'missing-review',
232
+ MISSING_WORKTREE: 'missing-worktree',
233
+ MISSING_BRANCH: 'missing-branch',
234
+ DIRTY_WORKTREE: 'dirty-worktree',
235
+ CANCELLED: 'cancelled',
236
+ SYNC_FAILED: 'sync-failed',
237
+ UNKNOWN_ERROR: 'unknown-error',
238
+ };
239
+ /**
240
+ * Default values
241
+ */
242
+ exports.DEFAULTS = {
243
+ TIMEOUT: 300000, // 5 minutes
244
+ FORCE_KILL_TIMEOUT: 5000, // 5 seconds
245
+ MAX_HISTORY_ENTRIES: 100,
246
+ MAX_WORKTREES: 10,
247
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * lib/interactive.ts
3
+ * Interactive CLI utilities for user confirmation
4
+ */
5
+ export interface ConfirmOptions {
6
+ message: string;
7
+ defaultYes?: boolean;
8
+ }
9
+ export interface SelectOptions {
10
+ message: string;
11
+ choices: string[];
12
+ defaultIndex?: number;
13
+ }
14
+ export interface InputOptions {
15
+ message: string;
16
+ default?: string;
17
+ validator?: (input: string) => boolean | string;
18
+ }
19
+ export declare function confirm(options: ConfirmOptions): Promise<boolean>;
20
+ export declare function select(options: SelectOptions): Promise<string>;
21
+ export declare function input(options: InputOptions): Promise<string>;
22
+ export declare function confirmOrExit(message: string, defaultYes?: boolean): Promise<void>;
23
+ export declare function printPreview(title: string, items: Record<string, string | number | boolean>): void;
24
+ declare const _default: {
25
+ confirm: typeof confirm;
26
+ select: typeof select;
27
+ input: typeof input;
28
+ confirmOrExit: typeof confirmOrExit;
29
+ printPreview: typeof printPreview;
30
+ };
31
+ export default _default;
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ /**
3
+ * lib/interactive.ts
4
+ * Interactive CLI utilities for user confirmation
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.confirm = confirm;
41
+ exports.select = select;
42
+ exports.input = input;
43
+ exports.confirmOrExit = confirmOrExit;
44
+ exports.printPreview = printPreview;
45
+ const readline = __importStar(require("readline"));
46
+ function confirm(options) {
47
+ const rl = readline.createInterface({
48
+ input: process.stdin,
49
+ output: process.stdout,
50
+ });
51
+ const hint = options.defaultYes !== false ? '[Y/n]' : '[y/N]';
52
+ const prompt = `${options.message} ${hint}: `;
53
+ return new Promise((resolve) => {
54
+ rl.question(prompt, (answer) => {
55
+ rl.close();
56
+ const input = answer.trim().toLowerCase();
57
+ if (input === '') {
58
+ resolve(options.defaultYes !== false);
59
+ }
60
+ else if (input === 'y' || input === 'yes') {
61
+ resolve(true);
62
+ }
63
+ else if (input === 'n' || input === 'no') {
64
+ resolve(false);
65
+ }
66
+ else {
67
+ resolve(options.defaultYes !== false);
68
+ }
69
+ });
70
+ rl.on('error', () => {
71
+ rl.close();
72
+ resolve(options.defaultYes !== false);
73
+ });
74
+ });
75
+ }
76
+ function select(options) {
77
+ const rl = readline.createInterface({
78
+ input: process.stdin,
79
+ output: process.stdout,
80
+ });
81
+ const choicesDisplay = options.choices
82
+ .map((c, i) => ` ${i + 1}. ${c}`)
83
+ .join('\n');
84
+ const defaultHint = options.defaultIndex !== undefined
85
+ ? ` (default: ${options.defaultIndex + 1})`
86
+ : '';
87
+ const prompt = `${options.message}${defaultHint}\n${choicesDisplay}\nSelect: `;
88
+ return new Promise((resolve) => {
89
+ rl.question(prompt, (answer) => {
90
+ rl.close();
91
+ const input = answer.trim();
92
+ if (input === '' && options.defaultIndex !== undefined) {
93
+ resolve(options.choices[options.defaultIndex] || options.choices[0] || '');
94
+ return;
95
+ }
96
+ const index = parseInt(input, 10) - 1;
97
+ if (index >= 0 && index < options.choices.length) {
98
+ resolve(options.choices[index] || options.choices[0] || '');
99
+ }
100
+ else {
101
+ resolve(options.choices[0] || '');
102
+ }
103
+ });
104
+ rl.on('error', () => {
105
+ rl.close();
106
+ resolve(options.choices[0] || '');
107
+ });
108
+ });
109
+ }
110
+ function input(options) {
111
+ const rl = readline.createInterface({
112
+ input: process.stdin,
113
+ output: process.stdout,
114
+ });
115
+ const hint = options.default ? ` (default: ${options.default})` : '';
116
+ const prompt = `${options.message}${hint}: `;
117
+ return new Promise((resolve) => {
118
+ const ask = () => {
119
+ rl.question(prompt, (answer) => {
120
+ const value = answer.trim() || options.default || '';
121
+ if (options.validator) {
122
+ const result = options.validator(value);
123
+ if (result === true) {
124
+ rl.close();
125
+ resolve(value);
126
+ }
127
+ else {
128
+ const errorMsg = typeof result === 'string' ? result : 'Invalid input';
129
+ console.log(` Error: ${errorMsg}`);
130
+ ask();
131
+ }
132
+ }
133
+ else {
134
+ rl.close();
135
+ resolve(value);
136
+ }
137
+ });
138
+ };
139
+ ask();
140
+ rl.on('error', () => {
141
+ rl.close();
142
+ resolve(options.default || '');
143
+ });
144
+ });
145
+ }
146
+ async function confirmOrExit(message, defaultYes = false) {
147
+ const confirmed = await confirm({ message, defaultYes });
148
+ if (!confirmed) {
149
+ console.log('\nOperation cancelled.');
150
+ process.exit(0);
151
+ }
152
+ }
153
+ function printPreview(title, items) {
154
+ console.log(`\n${title}:`);
155
+ for (const [key, value] of Object.entries(items)) {
156
+ console.log(` ${key}: ${value}`);
157
+ }
158
+ console.log('');
159
+ }
160
+ exports.default = {
161
+ confirm,
162
+ select,
163
+ input,
164
+ confirmOrExit,
165
+ printPreview,
166
+ };
@@ -0,0 +1,156 @@
1
+ /**
2
+ * lib/mcp-client.ts
3
+ * MCP Server lifecycle management
4
+ *
5
+ * Features:
6
+ * - Start/stop MCP servers
7
+ * - Timeout control
8
+ * - State management
9
+ * - Connection info retrieval
10
+ */
11
+ import { ChildProcess } from 'child_process';
12
+ /**
13
+ * MCP Server configuration interface
14
+ */
15
+ export interface McpServerConfig {
16
+ name: string;
17
+ command: string;
18
+ args?: string[];
19
+ enabled?: boolean;
20
+ lifecycle?: {
21
+ autoStart?: boolean;
22
+ timeout?: number;
23
+ };
24
+ }
25
+ /**
26
+ * Server state interface
27
+ */
28
+ export interface ServerState {
29
+ name: string;
30
+ pid: number;
31
+ process: ChildProcess;
32
+ startedAt: Date;
33
+ status: string;
34
+ timeout: number;
35
+ config: McpServerConfig;
36
+ timeoutTimer?: NodeJS.Timeout;
37
+ forceKillTimer?: NodeJS.Timeout;
38
+ }
39
+ /**
40
+ * Start result interface
41
+ */
42
+ export interface StartResult {
43
+ name: string;
44
+ status: string;
45
+ pid?: number;
46
+ command?: string;
47
+ startedAt?: string;
48
+ reason?: string;
49
+ error?: string;
50
+ stack?: string;
51
+ }
52
+ /**
53
+ * Stop result interface
54
+ */
55
+ export interface StopResult {
56
+ name: string;
57
+ status: string;
58
+ pid?: number;
59
+ error?: string;
60
+ }
61
+ /**
62
+ * Status info interface
63
+ */
64
+ export interface StatusInfo {
65
+ name: string;
66
+ status: string;
67
+ pid: number;
68
+ startedAt: string;
69
+ uptime: number;
70
+ timeout: number;
71
+ }
72
+ /**
73
+ * Connection info interface
74
+ */
75
+ export interface ConnectionInfo {
76
+ name: string;
77
+ transportType: string;
78
+ pid: number;
79
+ status: string;
80
+ }
81
+ /**
82
+ * Start MCP Servers
83
+ * @param mcpServers - List of MCP server configurations
84
+ * @param projectRoot - Project root directory
85
+ * @returns Start result
86
+ */
87
+ export declare function startMcpServers(mcpServers: McpServerConfig[], projectRoot: string): {
88
+ success: boolean;
89
+ results: StartResult[];
90
+ };
91
+ /**
92
+ * Start single MCP Server
93
+ * @param mcp - MCP server configuration
94
+ * @param projectRoot - Project root directory
95
+ * @returns Start result
96
+ */
97
+ export declare function startMcpServer(mcp: McpServerConfig, projectRoot: string): StartResult;
98
+ /**
99
+ * Stop MCP Server
100
+ * @param name - Server name
101
+ * @returns Stop result
102
+ */
103
+ export declare function stopMcpServer(name: string): StopResult;
104
+ /**
105
+ * Stop all MCP Servers
106
+ * @returns Stop result
107
+ */
108
+ export declare function stopAllMcpServers(): {
109
+ success: boolean;
110
+ results: StopResult[];
111
+ stoppedCount: number;
112
+ };
113
+ /**
114
+ * Get MCP Server status
115
+ * @param name - Server name
116
+ * @returns Status info
117
+ */
118
+ export declare function getMcpStatus(name: string): StatusInfo;
119
+ /**
120
+ * Get all MCP Servers status
121
+ * @returns List of status info
122
+ */
123
+ export declare function getAllMcpStatus(): StatusInfo[];
124
+ /**
125
+ * Get MCP connection info (for injection to Agent)
126
+ * @returns List of connection info
127
+ */
128
+ export declare function getMcpConnectionInfo(): ConnectionInfo[];
129
+ /**
130
+ * Manually start MCP Server (for CLI commands)
131
+ * @param mcp - MCP server configuration
132
+ * @param projectRoot - Project root directory
133
+ * @returns Start result
134
+ */
135
+ export declare function startMcpServerManual(mcp: McpServerConfig, projectRoot: string): StartResult;
136
+ /**
137
+ * Get count of running MCP Servers
138
+ * @returns Running count
139
+ */
140
+ export declare function getRunningCount(): number;
141
+ /**
142
+ * Clean up all state (before process exit)
143
+ */
144
+ export declare function cleanup(): void;
145
+ declare const _default: {
146
+ startMcpServers: typeof startMcpServers;
147
+ stopMcpServer: typeof stopMcpServer;
148
+ stopAllMcpServers: typeof stopAllMcpServers;
149
+ getMcpStatus: typeof getMcpStatus;
150
+ getAllMcpStatus: typeof getAllMcpStatus;
151
+ getMcpConnectionInfo: typeof getMcpConnectionInfo;
152
+ getRunningCount: typeof getRunningCount;
153
+ startMcpServerManual: typeof startMcpServerManual;
154
+ cleanup: typeof cleanup;
155
+ };
156
+ export default _default;