Commit cf0de5e
authored
fix: prevent false 'already configured' detection for tools (#239)
* fix: prevent false "already configured" detection for tools
Fixes #195
## Problem
Users with existing tool config files (like CLAUDE.md) would see those
tools marked as "already configured" even when running `openspec init`
for the first time. This caused confusion as users thought OpenSpec was
already set up when it wasn't.
Root causes:
1. Tool detection checked only for file existence, not OpenSpec ownership
2. Detection ran even in fresh projects without openspec/ folder
## Solution
Two-part fix:
1. **Conditional detection**: Only check tool configuration when in extend
mode (when openspec/ directory already exists). Fresh initializations
skip the check entirely, treating all tools as unconfigured.
2. **Marker-based validation**: For tools to be considered "configured by
OpenSpec", their files must contain OpenSpec markers (<!-- OPENSPEC:START -->
and <!-- OPENSPEC:END -->). For tools with both config files and slash
commands (like Claude Code), BOTH must have markers.
## Changes
- Modified getExistingToolStates() to accept extendMode parameter
- Rewrote isToolConfigured() to verify OpenSpec markers in files
- Added OPENSPEC_MARKERS to imports
- Added 4 comprehensive test cases covering the new behavior
## Test Coverage
- Fresh init with existing CLAUDE.md → NOT shown as configured ✅
- Fresh init with existing slash commands → NOT shown as configured ✅
- Extend mode with OpenSpec files → shown as configured ✅
- Fresh init with global Codex prompts → NOT shown as configured ✅
All 240 tests pass.
* refactor: optimize tool state detection and improve code clarity
Address code review feedback:
1. **Parallelize tool state checks**: Changed from sequential `for` loop to
`Promise.all()` for checking multiple tools simultaneously. This reduces
I/O latency during extend mode initialization.
2. **Extract marker validation helper**: Created `fileHasMarkers()` helper
function to eliminate code duplication between config file and slash
command checks. Makes the logic clearer and more maintainable.
3. **Clarify slash command policy**: Added explicit comment that "at least
one file with markers is sufficient" (not all required) for slash commands.
This is correct because OpenSpec creates all files together - if any
exists with markers, the tool was configured by OpenSpec.
4. **Simplify fresh init path**: Use `Object.fromEntries()` for cleaner
initialization of all-false states.
Performance improvement: Extend mode now checks tools in parallel instead
of serially, reducing init time especially for projects with many tools.1 parent 92b4546 commit cf0de5e
2 files changed
+143
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
388 | 389 | | |
389 | 390 | | |
390 | 391 | | |
391 | | - | |
| 392 | + | |
392 | 393 | | |
393 | 394 | | |
394 | 395 | | |
| |||
627 | 628 | | |
628 | 629 | | |
629 | 630 | | |
630 | | - | |
| 631 | + | |
| 632 | + | |
631 | 633 | | |
632 | | - | |
633 | | - | |
634 | | - | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
635 | 637 | | |
636 | | - | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
637 | 644 | | |
638 | 645 | | |
639 | 646 | | |
640 | 647 | | |
641 | 648 | | |
642 | 649 | | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
643 | 668 | | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
649 | 673 | | |
| 674 | + | |
650 | 675 | | |
651 | | - | |
652 | | - | |
653 | | - | |
654 | | - | |
655 | | - | |
656 | | - | |
657 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
658 | 701 | | |
| 702 | + | |
659 | 703 | | |
660 | 704 | | |
661 | 705 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1051 | 1051 | | |
1052 | 1052 | | |
1053 | 1053 | | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
1054 | 1135 | | |
1055 | 1136 | | |
1056 | 1137 | | |
| |||
0 commit comments