MCPcopy
hub / github.com/Fission-AI/OpenSpec / validateDirectItem

Method validateDirectItem

src/commands/validate.ts:119–179  ·  view source on GitHub ↗
(root: ResolvedOpenSpecRoot, itemName: string, opts: { typeOverride?: ItemType; strict: boolean; json: boolean })

Source from the content-addressed store, hash-verified

117 }
118
119 private async validateDirectItem(root: ResolvedOpenSpecRoot, itemName: string, opts: { typeOverride?: ItemType; strict: boolean; json: boolean }): Promise<void> {
120 const [changes, specs] = await Promise.all([getActiveChangeIds(root.path), getSpecIds(root.path)]);
121 const isChange = changes.includes(itemName);
122 const isSpec = specs.includes(itemName);
123
124 const type = opts.typeOverride ?? (isChange ? 'change' : isSpec ? 'spec' : undefined);
125
126 if (!type) {
127 const suggestions = nearestMatches(itemName, [...changes, ...specs]);
128 const message = suggestions.length
129 ? `Unknown item '${itemName}'. Did you mean: ${suggestions.join(', ')}?`
130 : `Unknown item '${itemName}'.`;
131 if (opts.json) {
132 console.log(
133 JSON.stringify(
134 { status: [{ severity: 'error', code: 'unknown_item', message }] },
135 null,
136 2
137 )
138 );
139 } else {
140 console.error(message);
141 }
142 process.exitCode = 1;
143 return;
144 }
145
146 if (!opts.typeOverride && isChange && isSpec) {
147 if (opts.json) {
148 console.log(
149 JSON.stringify(
150 {
151 status: [
152 {
153 severity: 'error',
154 code: 'ambiguous_item',
155 message: `Ambiguous item '${itemName}' matches both a change and a spec.`,
156 fix: 'Pass --type change|spec.',
157 },
158 ],
159 },
160 null,
161 2
162 )
163 );
164 process.exitCode = 1;
165 return;
166 }
167 console.error(`Ambiguous item '${itemName}' matches both a change and a spec.`);
168 // The noun-form commands are cwd-based and cannot reach a selected store.
169 if (isStoreSelectedRoot(root)) {
170 console.error('Pass --type change|spec.');
171 } else {
172 console.error('Pass --type change|spec, or use: openspec change validate / openspec spec validate');
173 }
174 process.exitCode = 1;
175 return;
176 }

Callers 1

executeMethod · 0.95

Calls 5

validateByTypeMethod · 0.95
getActiveChangeIdsFunction · 0.85
getSpecIdsFunction · 0.85
nearestMatchesFunction · 0.85
isStoreSelectedRootFunction · 0.85

Tested by

no test coverage detected