Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/weather/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ async function fetchWeather() {
}
}

setInterval(fetchWeather, 5000);
clearInterval(window.__interval); window.__interval = setInterval(fetchWeather, 5000);
fetchWeather();

// Gauge does not expose a public setColor() method, so dynamic color
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function promptSelect<T = string>(options: SelectPromptOptions<T>): Promis
return;
}
const n = parseInt(trimmed, 10);
if (!isNaN(n) && n >= 1 && n <= choices.length) {
if (!Number.isNaN(n) && n >= 1 && n <= choices.length) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Validate the complete input before accepting a selection.

Number.isNaN(n) is equivalent to the previous check here because n is already a number from parseInt. It does not reject inputs with numeric prefixes. For example, 2abc and 2.5 both parse as 2, so the prompt can select the wrong option.

Parse the complete input and require an integer index. Add regression tests for malformed and decimal input.

Proposed fix
-                const n = parseInt(trimmed, 10);
-                if (!Number.isNaN(n) && n >= 1 && n <= choices.length) {
+                const n = Number(trimmed);
+                if (Number.isInteger(n) && n >= 1 && n <= choices.length) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/ui/src/prompts.ts` at line 116, Update the prompt selection
validation around the numeric parsing condition to validate the complete raw
input before accepting it, rather than relying on parseInt’s partial parsing.
Require a valid integer index within 1 through choices.length, rejecting values
such as “2abc” and “2.5”; add regression tests covering malformed-prefix and
decimal inputs.

rl.close();
resolve(choices[n - 1].value);
return;
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function collectDeps(content: string): string[] {
const deps = new Set<string>();
let m: RegExpExecArray | null;
while ((m = re.exec(content)) !== null) deps.add(m[1]!);
return [...deps].sort();
return [...deps].sort((a, b) => a - b);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | rg '(^|/)build-registry(\.test)?\.ts$' || true

echo "== build-registry.ts =="
if [ -f scripts/build-registry.ts ]; then
  nl -ba scripts/build-registry.ts | sed -n '1,90p'
fi

echo "== related tests =="
if [ -f scripts/build-registry.test.ts ]; then
  nl -ba scripts/build-registry.test.ts | sed -n '1,180p'
fi

echo "== tsconfig(s) =="
fd -a 'tsconfig.*\.json$' . -d 3 | sort | sed 's#^\./##' | while read -r f; do
  echo "--- $f"
  nl -ba "$f" | sed -n '1,140p'
done

echo "== TypeScript availability and arithmetic probe =="
if command -v tsc >/dev/null 2>&1; then
  echo "tsc version:"
  tsc --version
  tmp="$(mktemp -d)"
  cat > "$tmp/probe.ts" <<'TS'
const deps: string[] = ['apple', 'banana', 'apricot'];
deps.sort((a: string, b: string) => a - b);
TS
  (tsc --noEmit --strict "$tmp/probe.ts" 2>&1 | sed -n '1,120p') || true
else
  node - <<'JS'
const deps = ['apple', 'banana', 'apricot'];
const out = [...deps].sort((a, b) => a - b);
console.log(JSON.stringify(out));
JS
fi

Repository: Karanjot786/TermUI

Length of output: 289


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== build-registry.ts =="
if [ -f scripts/build-registry.ts ]; then
  cat -n scripts/build-registry.ts | sed -n '1,90p'
fi

echo "== related tests =="
if [ -f scripts/build-registry.test.ts ]; then
  cat -n scripts/build-registry.test.ts | sed -n '1,180p'
fi

echo "== tsconfig(s) =="
find . -maxdepth 3 -name 'tsconfig*.json' -print | sort | while read -r f; do
  echo "--- $f"
  cat -n "$f" | sed -n '1,160p'
done

echo "== TypeScript availability and arithmetic probe =="
if command -v tsc >/dev/null 2>&1; then
  echo "tsc version:"
  tsc --version
  tmp="$(mktemp -d)"
  cat > "$tmp/probe.ts" <<'TS'
const deps: string[] = ['apple', 'banana', 'apricot'];
deps.sort((a: string, b: string) => a - b);
TS
  (tsc --noEmit --strict "$tmp/probe.ts" 2>&1 | sed -n '1,120p') || true
else
  echo "tsc not available"
  node - <<'JS'
const deps = ['apple', 'banana', 'apricot'];
const out = [...deps].sort((a, b) => a - b);
console.log(JSON.stringify(out));
JS
fi

Repository: Karanjot786/TermUI

Length of output: 34283


Use a string comparator for dependency specifiers.

collectDeps() returns string[], but a - b is not valid TypeScript arithmetic for strings. If emitted, NaN values also leave the dependency array unsorted instead of matching the lexical order expected by scripts/build-registry.test.ts:127-139.

-  return [...deps].sort((a, b) => a - b);
+  return [...deps].sort((a, b) => a.localeCompare(b));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return [...deps].sort((a, b) => a - b);
return [...deps].sort((a, b) => a.localeCompare(b));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/build-registry.ts` at line 47, Update the sorting comparator in
collectDeps() to compare dependency specifier strings lexically rather than
subtracting them numerically. Preserve the returned string[] and ensure the
ordering matches the lexical order expected by the existing tests.

Source: Coding guidelines

}

export function toSlug(name: string): string {
Expand Down
Loading