fix(cli): fall back to stderr when stdout empty in agents list version probe#555
fix(cli): fall back to stderr when stdout empty in agents list version probe#555Nexu0ps wants to merge 4 commits into
Conversation
- chat-telegram: safeFileStem(botUsername) prevents path traversal in
telegram-{username}.json artifact path (fixes profullstack#552)
- mobile-android: safeFileStem(packageName) prevents traversal in
{packageName}-{version}.aab artifact path (fixes profullstack#550)
- browser-edge: safeFileStem(productId) prevents traversal in
packageArtifact() zip path (fixes profullstack#548)
All three adopt the same safeFileStem helper used by browser-firefox:
replace non-alphanumeric characters (except . _ -) with hyphens.
The original values are preserved for API calls, logs, and store URLs.
…sion probe When an agent CLI prints version info to stderr instead of stdout (e.g. 'claude 1.2.3\n' on stderr, empty stdout), the old code result.stdout ?? result.stderr always used stdout because empty string is not null/undefined. Switching to the || operator makes empty-string stdout fall back to stderr, so version is correctly detected. Fixes profullstack#546
Greptile SummaryThis PR fixes a legitimate bug in
Confidence Score: 2/5Not safe to merge — three packaging targets will fail to compile due to orphaned function bodies left at module scope after incomplete deletions. The pkg-flatpak, pkg-snap, and pkg-winget files each have dangling code blocks at module scope that reference function-parameter variables (appId, snapName, packageId) which are never declared at that level. TypeScript will reject all three files. The bugs were introduced by removing only the function declaration line(s) while leaving the rest of the body in place; complete replacement validators already exist lower in each file, so the fix is simply deleting the orphaned fragments. packages/targets/pkg-flatpak/src/index.ts (lines 36–50), packages/targets/pkg-snap/src/index.ts (lines 41–50), packages/targets/pkg-winget/src/index.ts (lines 32–44) Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[probeAgent called] --> B[spawnSync binary --version]
B --> C{exit code 0?}
C -- No --> D[Return installed: false]
C -- Yes --> E["stdout?.trim() || stderr?.trim() || ''"]
E --> F{stdout non-empty after trim?}
F -- Yes --> G[Use stdout as raw]
F -- No --> H{stderr non-empty after trim?}
H -- Yes --> I[Use stderr as raw]
H -- No --> J[raw = empty string]
G & I & J --> K[regex match semver]
K -- Match --> L[version = matched semver]
K -- No match --> M[version = first line of raw]
L & M --> N[Return installed: true + version]
|
| function safeFileStem(value: string): string { | ||
| return value.replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'telegram-bot'; | ||
| } |
There was a problem hiding this comment.
Duplicated
safeFileStem utility across three packages
The same function body (differing only in the fallback string) now lives in browser-edge, chat-telegram, and mobile-android. Any future regex change will need to be made in three places. Consider extracting it into a shared utility in @profullstack/sh1pt-core or a dedicated @profullstack/sh1pt-utils package and importing it from there.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Same fixes as applied to PR profullstack#554 branch: - browser-edge: fix 'nfunction' -> proper newline + function - pkg-flatpak: remove duplicate validateAppId - pkg-snap: remove duplicate validateSnapName
Bug
sh1pt agents listreports emptyversionfor CLIs that print version to stderr (exit 0).Root cause:
result.stdout ?? result.stderr— the nullish coalescing operator doesn't fall back on empty string, only on null/undefined. An empty stdout string is still truthy for??.Fix
Using
||makes empty-string stdout fall through to stderr, so CLIs like claude that write to stderr are correctly detected.Closes #546