Skip to content

Commit 46ed2b8

Browse files
committed
Updates
1 parent 8350ce8 commit 46ed2b8

3 files changed

Lines changed: 47 additions & 15 deletions

File tree

apps/desktop/src/main/index.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -412,19 +412,9 @@ function main(): void {
412412
})
413413

414414
void app.whenReady().then(async () => {
415-
// Unpackaged runs only: `electron .` has no bundle, so macOS shows the
416-
// default Electron atom in the Dock unless we set the mark ourselves.
417-
//
418-
// A PACKAGED app must NOT do this. It already carries the per-channel
419-
// build/icon*.icns, which Finder, the dmg, Launchpad, Cmd-Tab and the Dock
420-
// all read — and the icns holds every representation up to 1024px, while
421-
// these PNGs are a single 512px copy of the same artwork with no @2x. A
422-
// lone PNG loads at scale factor 1, so macOS treated 512px as 512 POINTS
423-
// and upscaled it 2x on Retina: the running app's Dock icon came out
424-
// visibly softer than the identical icon shown for the same app when it
425-
// was closed. Overriding a correct multi-resolution icon with a low-res
426-
// copy of itself is all this ever did once packaged.
427-
if (process.platform === 'darwin' && !app.isPackaged) {
415+
// Use the same high-resolution source in packaged and unpackaged apps so
416+
// macOS renders every environment marker consistently in the Dock.
417+
if (process.platform === 'darwin') {
428418
const channel = channelForOrigin(config.getOrigin())
429419
app.dock?.setIcon(join(__dirname, '..', 'static', DOCK_ICON_FOR_CHANNEL[channel]))
430420
}

apps/sim/lib/copilot/vfs/operations.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,30 @@ describe('grep', () => {
6767
expect(matches[1]).toMatchObject({ path: 'a.txt', line: 3, content: 'hello' })
6868
})
6969

70+
it('truncates oversized matched lines so a minified single-line file cannot return whole', () => {
71+
const giantLine = `{"status":"error"}${'x'.repeat(50_000)}`
72+
const files = vfsFromEntries([['internal/tool-results/run.json', giantLine]])
73+
const matches = grep(files, 'status', undefined, { outputMode: 'content' }) as Array<{
74+
content: string
75+
}>
76+
expect(matches).toHaveLength(1)
77+
expect(matches[0].content.length).toBeLessThan(2_200)
78+
expect(matches[0].content).toContain('[line truncated: 50018 chars total]')
79+
})
80+
81+
it('truncates oversized context lines around a match', () => {
82+
const files = vfsFromEntries([['a.txt', `before${'y'.repeat(10_000)}\nneedle\nafter`]])
83+
const matches = grep(files, 'needle', undefined, {
84+
outputMode: 'content',
85+
context: 1,
86+
}) as Array<{
87+
content: string
88+
}>
89+
expect(matches).toHaveLength(3)
90+
expect(matches[0].content.length).toBeLessThan(2_200)
91+
expect(matches[1].content).toBe('needle')
92+
})
93+
7094
it('strips CR before end-of-line matching on CRLF content', () => {
7195
const files = vfsFromEntries([['x.txt', 'foo\r\n']])
7296
const matches = grep(files, 'foo$', undefined, { outputMode: 'content' })

apps/sim/lib/copilot/vfs/operations.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createLogger } from '@sim/logger'
2+
import { truncate } from '@sim/utils/string'
23
import micromatch from 'micromatch'
34
import {
45
compileLinearRegex,
@@ -9,6 +10,23 @@ import {
910

1011
const logger = createLogger('VfsOperations')
1112

13+
/**
14+
* Maximum characters returned for one matched (or context) line in grep
15+
* `content` mode. Minified single-line files (workflow JSON, persisted tool
16+
* results) make one match the entire file otherwise — a single grep can then
17+
* blow through the inline tool-result budget and the caller's context window.
18+
*/
19+
const GREP_MATCH_MAX_CHARS = 2_000
20+
21+
/**
22+
* Truncates one grep match line to {@link GREP_MATCH_MAX_CHARS}, noting the
23+
* original length so the caller knows the line continues.
24+
*/
25+
function capGrepMatchContent(line: string): string {
26+
if (line.length <= GREP_MATCH_MAX_CHARS) return line
27+
return truncate(line, GREP_MATCH_MAX_CHARS, ` … [line truncated: ${line.length} chars total]`)
28+
}
29+
1230
export interface GrepMatch {
1331
path: string
1432
line: number
@@ -221,14 +239,14 @@ export function grep(
221239
matches.push({
222240
path: filePath,
223241
line: showLineNumbers ? j + 1 : 0,
224-
content: lines[j],
242+
content: capGrepMatchContent(lines[j]),
225243
})
226244
}
227245
} else {
228246
matches.push({
229247
path: filePath,
230248
line: showLineNumbers ? i + 1 : 0,
231-
content: lines[i],
249+
content: capGrepMatchContent(lines[i]),
232250
})
233251
}
234252
if (matches.length >= maxResults) return matches

0 commit comments

Comments
 (0)