ucn 3.7.5 → 3.7.6

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.
package/core/output.js CHANGED
@@ -2078,6 +2078,157 @@ function formatLineRanges(lineNums) {
2078
2078
  return ranges.join(', ');
2079
2079
  }
2080
2080
 
2081
+ /**
2082
+ * Format plan command output - JSON
2083
+ */
2084
+ function formatPlanJson(plan) {
2085
+ if (!plan) {
2086
+ return JSON.stringify({ found: false, error: 'Function not found' }, null, 2);
2087
+ }
2088
+ if (!plan.found) {
2089
+ return JSON.stringify({
2090
+ found: false,
2091
+ error: plan.error || `Function "${plan.function}" not found.`,
2092
+ ...(plan.currentParams && { currentParams: plan.currentParams })
2093
+ }, null, 2);
2094
+ }
2095
+
2096
+ return JSON.stringify({
2097
+ found: true,
2098
+ function: plan.function,
2099
+ file: plan.file,
2100
+ startLine: plan.startLine,
2101
+ operation: plan.operation,
2102
+ before: { signature: plan.before.signature },
2103
+ after: { signature: plan.after.signature },
2104
+ totalChanges: plan.totalChanges,
2105
+ filesAffected: plan.filesAffected,
2106
+ changes: plan.changes.map(c => ({
2107
+ file: c.file,
2108
+ line: c.line,
2109
+ expression: c.expression,
2110
+ suggestion: c.suggestion
2111
+ }))
2112
+ }, null, 2);
2113
+ }
2114
+
2115
+ /**
2116
+ * Format stack trace command output - JSON
2117
+ */
2118
+ function formatStackTraceJson(result) {
2119
+ if (!result || result.frameCount === 0) {
2120
+ return JSON.stringify({ frameCount: 0, frames: [] }, null, 2);
2121
+ }
2122
+
2123
+ return JSON.stringify({
2124
+ frameCount: result.frameCount,
2125
+ frames: result.frames.map(f => ({
2126
+ function: f.function || null,
2127
+ file: f.file,
2128
+ line: f.line,
2129
+ found: !!f.found,
2130
+ ...(f.resolvedFile && { resolvedFile: f.resolvedFile }),
2131
+ ...(f.context && { context: f.context.map(c => ({
2132
+ line: c.line,
2133
+ code: c.code,
2134
+ isCurrent: !!c.isCurrent
2135
+ })) }),
2136
+ ...(f.functionInfo && { functionInfo: {
2137
+ name: f.functionInfo.name,
2138
+ params: f.functionInfo.params || null,
2139
+ startLine: f.functionInfo.startLine,
2140
+ endLine: f.functionInfo.endLine
2141
+ } }),
2142
+ ...(f.raw && { raw: f.raw })
2143
+ }))
2144
+ }, null, 2);
2145
+ }
2146
+
2147
+ /**
2148
+ * Format verify command output - JSON
2149
+ */
2150
+ function formatVerifyJson(result) {
2151
+ if (!result) {
2152
+ return JSON.stringify({ found: false, error: 'Function not found' }, null, 2);
2153
+ }
2154
+ if (!result.found) {
2155
+ return JSON.stringify({ found: false, error: `Function "${result.function}" not found.` }, null, 2);
2156
+ }
2157
+
2158
+ return JSON.stringify({
2159
+ found: true,
2160
+ function: result.function,
2161
+ file: result.file,
2162
+ startLine: result.startLine,
2163
+ signature: result.signature,
2164
+ expectedArgs: result.expectedArgs,
2165
+ totalCalls: result.totalCalls,
2166
+ valid: result.valid,
2167
+ mismatches: result.mismatches,
2168
+ uncertain: result.uncertain,
2169
+ mismatchDetails: result.mismatchDetails.map(m => ({
2170
+ file: m.file,
2171
+ line: m.line,
2172
+ expression: m.expression,
2173
+ expected: m.expected,
2174
+ actual: m.actual,
2175
+ args: m.args || []
2176
+ })),
2177
+ uncertainDetails: result.uncertainDetails.map(u => ({
2178
+ file: u.file,
2179
+ line: u.line,
2180
+ expression: u.expression,
2181
+ reason: u.reason
2182
+ }))
2183
+ }, null, 2);
2184
+ }
2185
+
2186
+ /**
2187
+ * Format example command output - JSON
2188
+ */
2189
+ function formatExampleJson(result, name) {
2190
+ if (!result) {
2191
+ return JSON.stringify({ found: false, query: name, error: `No call examples found for "${name}"` }, null, 2);
2192
+ }
2193
+
2194
+ const best = result.best;
2195
+ return JSON.stringify({
2196
+ found: true,
2197
+ query: name,
2198
+ totalCalls: result.totalCalls,
2199
+ best: {
2200
+ file: best.relativePath || best.file,
2201
+ line: best.line,
2202
+ content: best.content,
2203
+ score: best.score,
2204
+ reasons: best.reasons || [],
2205
+ ...(best.before && best.before.length > 0 && { before: best.before }),
2206
+ ...(best.after && best.after.length > 0 && { after: best.after })
2207
+ }
2208
+ }, null, 2);
2209
+ }
2210
+
2211
+ /**
2212
+ * Format deadcode command output - JSON
2213
+ */
2214
+ function formatDeadcodeJson(results) {
2215
+ return JSON.stringify({
2216
+ count: results.length,
2217
+ ...(results.excludedExported > 0 && { excludedExported: results.excludedExported }),
2218
+ ...(results.excludedDecorated > 0 && { excludedDecorated: results.excludedDecorated }),
2219
+ symbols: results.map(item => ({
2220
+ name: item.name,
2221
+ type: item.type,
2222
+ file: item.file,
2223
+ startLine: item.startLine,
2224
+ endLine: item.endLine,
2225
+ ...(item.isExported && { isExported: true }),
2226
+ ...(item.decorators && item.decorators.length > 0 && { decorators: item.decorators }),
2227
+ ...(item.annotations && item.annotations.length > 0 && { annotations: item.annotations })
2228
+ }))
2229
+ }, null, 2);
2230
+ }
2231
+
2081
2232
  function formatDiffImpactJson(result) {
2082
2233
  return JSON.stringify(result, null, 2);
2083
2234
  }
@@ -2132,12 +2283,15 @@ module.exports = {
2132
2283
 
2133
2284
  // Plan command
2134
2285
  formatPlan,
2286
+ formatPlanJson,
2135
2287
 
2136
2288
  // Stack trace command
2137
2289
  formatStackTrace,
2290
+ formatStackTraceJson,
2138
2291
 
2139
2292
  // Verify command
2140
2293
  formatVerify,
2294
+ formatVerifyJson,
2141
2295
 
2142
2296
  // Trace command
2143
2297
  formatTrace,
@@ -2149,6 +2303,10 @@ module.exports = {
2149
2303
 
2150
2304
  // Example command
2151
2305
  formatExample,
2306
+ formatExampleJson,
2307
+
2308
+ // Deadcode command
2309
+ formatDeadcodeJson,
2152
2310
 
2153
2311
  // Shared text formatters (CLI + MCP)
2154
2312
  formatToc,