Skip to content

fix(cli): fall back to stderr when stdout empty in agents list version probe#555

Closed
Nexu0ps wants to merge 4 commits into
profullstack:masterfrom
Nexu0ps:fix/agents-list-version-stderr
Closed

fix(cli): fall back to stderr when stdout empty in agents list version probe#555
Nexu0ps wants to merge 4 commits into
profullstack:masterfrom
Nexu0ps:fix/agents-list-version-stderr

Conversation

@Nexu0ps
Copy link
Copy Markdown
Contributor

@Nexu0ps Nexu0ps commented Jun 1, 2026

Bug

sh1pt agents list reports empty version for 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

// Before
const raw = (result.stdout ?? result.stderr ?? '').trim();

// After  
const raw = (result.stdout?.trim() || result.stderr?.trim() || '').trim();

Using || makes empty-string stdout fall through to stderr, so CLIs like claude that write to stderr are correctly detected.

Closes #546

Nexu0ps added 2 commits June 1, 2026 16:42
- 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-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 1, 2026

Greptile Summary

This PR fixes a legitimate bug in agents list version detection by switching from ?? (nullish coalescing) to || so that an empty stdout string correctly falls through to stderr. It also adds a safeFileStem sanitizer to prevent special characters in user-supplied config values from producing broken artifact file paths in browser-edge, chat-telegram, and mobile-android targets.

  • The core agents.ts fix and all three safeFileStem additions are correct.
  • Three packaging targets (pkg-flatpak, pkg-snap, pkg-winget) have incomplete function deletions: the old validator function headers were removed but their bodies remain as orphaned top-level statements referencing undeclared parameters, breaking TypeScript compilation for all three packages. Each file also contains a complete replacement validator lower down — only the dangling fragments need to be cleaned up.

Confidence Score: 2/5

Not 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

Filename Overview
packages/cli/src/commands/agents.ts Correct fix: switches ?? to
packages/targets/browser-edge/src/index.ts Adds safeFileStem helper and applies it to artifact path construction; function is well-formed and previous nfunction typo is gone.
packages/targets/chat-telegram/src/index.ts Adds safeFileStem to sanitize botUsername in the artifact path; function is correct and placed after the module export.
packages/targets/mobile-android/src/index.ts Adds safeFileStem and applies it to the AAB artifact filename; change is clean and correct.
packages/targets/pkg-flatpak/src/index.ts Partial deletion of validateAppId left its body (lines 36–50) as orphaned module-level statements referencing undeclared variable appId — TypeScript compile error; file is broken.
packages/targets/pkg-snap/src/index.ts Partial deletion of validateSnapName left its body (lines 41–50) as orphaned module-level code referencing undeclared snapName — TypeScript compile error.
packages/targets/pkg-winget/src/index.ts Partial deletion of validatePackageId left its body (lines 32–44) as orphaned module-level code referencing undeclared packageId — TypeScript compile error.

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]
Loading

Comments Outside Diff (1)

  1. packages/targets/pkg-flatpak/src/index.ts, line 36-50 (link)

    P0 Orphaned function body at module scope causes compile error

    Lines 36–50 are the remainder of the old validateAppId function after its declaration was partially deleted. The function header and early guards were removed, but the throw, const segments, and the rest of the body are left as top-level module statements that reference the undeclared variable appId. TypeScript will reject this with "Cannot find name 'appId'", and the stray } on line 50 is an unmatched brace. The same pattern breaks packages/targets/pkg-snap/src/index.ts (lines 41–50 reference undeclared snapName) and packages/targets/pkg-winget/src/index.ts (lines 32–44 reference undeclared packageId). All three files will fail to compile. The complete replacement validators already exist lower in each file (flatpak line 108, snap line 99, winget line 125) — the orphaned fragments need to be fully removed.

Reviews (3): Last reviewed commit: "fix: remove duplicate validatePackageId ..." | Re-trigger Greptile

Comment thread packages/targets/browser-edge/src/index.ts Outdated
Comment on lines +101 to +103
function safeFileStem(value: string): string {
return value.replace(/[^a-zA-Z0-9._-]+/g, '-').replace(/^-+|-+$/g, '') || 'telegram-bot';
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 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!

Nexu0ps added 2 commits June 1, 2026 20:31
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
@ralyodio ralyodio closed this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agents list drops versions printed to stderr

2 participants