Skip to content

Commit 2aaa285

Browse files
committed
fix(lint): sort-source-methods - reorder 20 src files + oxfmt drift
Mechanical alphabetical reorder within visibility groups (private then exports) across 20 src files flagged by socket(sort-source-methods), plus oxfmt formatting drift swept in by `pnpm run format` on the same files. No behavior change; tests pass (421 files / 6806 tests). Reordered files (sort-source-methods): - constants/paths.mts, flags.mts - commands/fix/{ghsa-tracker,git}.mts - commands/mcp/transport-http-helpers.mts - utils/{basics,dlx}/spawn.mts - utils/cli/with-subcommands.mts - utils/command/logger.mts - utils/config.mts - utils/dlx/{resolve-binary,vfs-extract}.mts - utils/git/{github,operations}.mts - utils/process/os.mts - utils/socket/{api,sdk}.mts - utils/telemetry/integration.mts - utils/terminal/{bordered-input,simple-output}.mts - utils/update/checker.mts Format-only drift (oxfmt): - commands/ask/{handle-ask,onnx-match,word-overlap-match}.mts - commands/fix/pull-request.mts - commands/optimize/add-overrides.mts - commands/raw-{npm,npx}/cmd-raw-*.mts - meow.mts - utils/command/builder.mts - utils/ecosystem/windows-shims.mts - utils/git/gitlab-provider.mts - utils/project/context.mts - utils/socket/{api-error-messages,api-wrapper,package-alert}.mts - utils/terminal/iocraft.mts
1 parent 45c05fe commit 2aaa285

37 files changed

Lines changed: 2215 additions & 2183 deletions

packages/cli/src/commands/ask/handle-ask.mts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,15 @@ export async function parseIntent(query: string): Promise<ParsedIntent> {
288288
}
289289

290290
// Match against patterns.
291-
let bestMatch: {
292-
action: string
293-
command: string[]
294-
explanation: string
295-
confidence: number
296-
score: number
297-
} | undefined = undefined
291+
let bestMatch:
292+
| {
293+
action: string
294+
command: string[]
295+
explanation: string
296+
confidence: number
297+
score: number
298+
}
299+
| undefined = undefined
298300

299301
for (const [action, pattern] of Object.entries(PATTERNS)) {
300302
if (!pattern) {

packages/cli/src/commands/ask/onnx-match.mts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export async function ensureCommandEmbeddings(): Promise<void> {
6868
* Get the embedding for a text string. Returns null when the pipeline is
6969
* unavailable or the underlying call throws.
7070
*/
71-
export async function getEmbedding(text: string): Promise<Float32Array | undefined> {
71+
export async function getEmbedding(
72+
text: string,
73+
): Promise<Float32Array | undefined> {
7274
const model = await getEmbeddingPipeline()
7375
if (!model) {
7476
return undefined
@@ -122,10 +124,13 @@ export async function getEmbeddingPipeline() {
122124
* embedding pipeline is unavailable, the query embeds to null, or no
123125
* command meets the threshold.
124126
*/
125-
export async function onnxSemanticMatch(query: string): Promise<{
126-
action: string
127-
confidence: number
128-
} | undefined> {
127+
export async function onnxSemanticMatch(query: string): Promise<
128+
| {
129+
action: string
130+
confidence: number
131+
}
132+
| undefined
133+
> {
129134
await ensureCommandEmbeddings()
130135

131136
const queryEmbedding = await getEmbedding(query)

packages/cli/src/commands/ask/word-overlap-match.mts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ export function wordOverlap(
105105
* when the index isn't loaded, the query has no scoring tokens, or no
106106
* command meets the threshold.
107107
*/
108-
export async function wordOverlapMatch(query: string): Promise<{
109-
action: string
110-
confidence: number
111-
} | undefined> {
108+
export async function wordOverlapMatch(query: string): Promise<
109+
| {
110+
action: string
111+
confidence: number
112+
}
113+
| undefined
114+
> {
112115
const index = await loadSemanticIndex()
113116
if (!index || !index.commands) {
114117
return undefined

packages/cli/src/commands/fix/ghsa-tracker.mts

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,52 @@ import {
1111

1212
import { getSocketFixBranchName } from './git.mts'
1313

14+
export type GhsaFixRecord = {
15+
branch: string
16+
fixedAt: string // ISO 8601
17+
ghsaId: string
18+
prNumber?: number
19+
}
20+
21+
export type GhsaTracker = {
22+
fixed: GhsaFixRecord[]
23+
version: 1
24+
}
25+
26+
const TRACKER_FILE = '.socket/fixed-ghsas.json'
27+
28+
/**
29+
* Get all fixed GHSA records from the tracker.
30+
*/
31+
export async function getFixedGhsas(cwd: string): Promise<GhsaFixRecord[]> {
32+
try {
33+
const tracker = await loadGhsaTracker(cwd)
34+
return tracker.fixed
35+
/* c8 ignore next 5 - loadGhsaTracker already returns a safe fallback on read failure */
36+
} catch (e) {
37+
debug('ghsa-tracker: failed to get fixed GHSAs')
38+
debugDir(e)
39+
return []
40+
}
41+
}
42+
43+
/**
44+
* Check if a GHSA has been fixed according to the tracker.
45+
*/
46+
export async function isGhsaFixed(
47+
cwd: string,
48+
ghsaId: string,
49+
): Promise<boolean> {
50+
try {
51+
const tracker = await loadGhsaTracker(cwd)
52+
return tracker.fixed.some(r => r.ghsaId === ghsaId)
53+
} catch (e) {
54+
debug(`ghsa-tracker: failed to check if ${ghsaId} is fixed`)
55+
debugDir(e)
56+
return false
57+
}
58+
}
59+
1460
/**
1561
* Check if a process with the given PID is still running.
1662
*/
@@ -28,20 +74,6 @@ export function isPidAlive(pid: number): boolean {
2874
}
2975
}
3076

31-
export type GhsaFixRecord = {
32-
branch: string
33-
fixedAt: string // ISO 8601
34-
ghsaId: string
35-
prNumber?: number
36-
}
37-
38-
export type GhsaTracker = {
39-
fixed: GhsaFixRecord[]
40-
version: 1
41-
}
42-
43-
const TRACKER_FILE = '.socket/fixed-ghsas.json'
44-
4577
/**
4678
* Load the GHSA tracker from the repository.
4779
* Creates a new tracker if the file doesn't exist.
@@ -58,23 +90,6 @@ export async function loadGhsaTracker(cwd: string): Promise<GhsaTracker> {
5890
}
5991
}
6092

61-
/**
62-
* Save the GHSA tracker to the repository.
63-
* Creates the .socket directory if it doesn't exist.
64-
*/
65-
export async function saveGhsaTracker(
66-
cwd: string,
67-
tracker: GhsaTracker,
68-
): Promise<void> {
69-
const trackerPath = path.join(cwd, TRACKER_FILE)
70-
71-
// Ensure .socket directory exists.
72-
await safeMkdir(path.dirname(trackerPath), { recursive: true })
73-
74-
await writeJson(trackerPath, tracker, { spaces: 2 })
75-
debug(`ghsa-tracker: saved ${tracker.fixed.length} records to ${trackerPath}`)
76-
}
77-
7893
/**
7994
* Mark a GHSA as fixed in the tracker.
8095
* Removes any existing record for the same GHSA before adding the new one.
@@ -161,33 +176,18 @@ export async function markGhsaFixed(
161176
}
162177

163178
/**
164-
* Check if a GHSA has been fixed according to the tracker.
179+
* Save the GHSA tracker to the repository.
180+
* Creates the .socket directory if it doesn't exist.
165181
*/
166-
export async function isGhsaFixed(
182+
export async function saveGhsaTracker(
167183
cwd: string,
168-
ghsaId: string,
169-
): Promise<boolean> {
170-
try {
171-
const tracker = await loadGhsaTracker(cwd)
172-
return tracker.fixed.some(r => r.ghsaId === ghsaId)
173-
} catch (e) {
174-
debug(`ghsa-tracker: failed to check if ${ghsaId} is fixed`)
175-
debugDir(e)
176-
return false
177-
}
178-
}
184+
tracker: GhsaTracker,
185+
): Promise<void> {
186+
const trackerPath = path.join(cwd, TRACKER_FILE)
179187

180-
/**
181-
* Get all fixed GHSA records from the tracker.
182-
*/
183-
export async function getFixedGhsas(cwd: string): Promise<GhsaFixRecord[]> {
184-
try {
185-
const tracker = await loadGhsaTracker(cwd)
186-
return tracker.fixed
187-
/* c8 ignore next 5 - loadGhsaTracker already returns a safe fallback on read failure */
188-
} catch (e) {
189-
debug('ghsa-tracker: failed to get fixed GHSAs')
190-
debugDir(e)
191-
return []
192-
}
188+
// Ensure .socket directory exists.
189+
await safeMkdir(path.dirname(trackerPath), { recursive: true })
190+
191+
await writeJson(trackerPath, tracker, { spaces: 2 })
192+
debug(`ghsa-tracker: saved ${tracker.fixed.length} records to ${trackerPath}`)
193193
}

packages/cli/src/commands/fix/git.mts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,10 @@ import type { GhsaDetails } from '../../utils/git/github.mts'
66

77
const GITHUB_ADVISORIES_URL = 'https://github.com/advisories'
88

9-
/**
10-
* Extract unique package names with ecosystems from vulnerability details.
11-
*/
12-
export function getUniquePackages(details: GhsaDetails): string[] {
13-
return [
14-
...new Set(
15-
details.vulnerabilities.nodes.map(
16-
v => `${v.package.name} (${v.package.ecosystem})`,
17-
),
18-
),
19-
]
20-
}
9+
export const genericSocketFixBranchParser = createSocketFixBranchParser()
10+
11+
// GHSA ID pattern: GHSA-xxxx-xxxx-xxxx (4 alphanumeric segments).
12+
const GHSA_ID_PATTERN = /^GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/i
2113

2214
export type SocketFixBranchParser = (
2315
branch: string,
@@ -43,15 +35,10 @@ export function createSocketFixBranchParser(
4335
}
4436
}
4537

46-
export const genericSocketFixBranchParser = createSocketFixBranchParser()
47-
4838
export function getSocketFixBranchName(ghsaId: string): string {
4939
return `socket/fix/${ghsaId}`
5040
}
5141

52-
// GHSA ID pattern: GHSA-xxxx-xxxx-xxxx (4 alphanumeric segments).
53-
const GHSA_ID_PATTERN = /^GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/i
54-
5542
export function getSocketFixBranchPattern(ghsaId?: string | undefined): RegExp {
5643
// Escape special regex characters to prevent ReDoS attacks.
5744
const pattern = ghsaId
@@ -118,3 +105,16 @@ export function getSocketFixPullRequestTitle(ghsaIds: string[]): string {
118105
? `Fix for ${firstGhsa}`
119106
: `Fixes for ${vulnCount} GHSAs`
120107
}
108+
109+
/**
110+
* Extract unique package names with ecosystems from vulnerability details.
111+
*/
112+
export function getUniquePackages(details: GhsaDetails): string[] {
113+
return [
114+
...new Set(
115+
details.vulnerabilities.nodes.map(
116+
v => `${v.package.name} (${v.package.ecosystem})`,
117+
),
118+
),
119+
]
120+
}

packages/cli/src/commands/fix/pull-request.mts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,18 +412,16 @@ export async function openSocketFixPr(
412412

413413
// Handle RequestError from Octokit/provider.
414414
if (e instanceof RequestError) {
415-
const errors = (
416-
e.response?.data as { errors?: unknown } | undefined
417-
)?.errors
415+
const errors = (e.response?.data as { errors?: unknown } | undefined)
416+
?.errors
418417
const errorMessages = Array.isArray(errors)
419418
? errors.map(
420419
(d: {
421420
message?: string
422421
resource?: string
423422
field?: string
424423
code?: string
425-
}) =>
426-
d.message?.trim() ?? `${d.resource}.${d.field} (${d.code})`,
424+
}) => d.message?.trim() ?? `${d.resource}.${d.field} (${d.code})`,
427425
)
428426
: []
429427

0 commit comments

Comments
 (0)