Skip to content

Commit 05eebff

Browse files
committed
Remove JSON export from bdg stop
- Remove session.json file write on stop - Remove offline session fallback from network commands - Delete unused output.ts module - Update skill to discourage premature stop calls - Remove 'save output' references from UI messages - Users should use bdg peek to inspect telemetry data
1 parent 937904f commit 05eebff

File tree

11 files changed

+19
-136
lines changed

11 files changed

+19
-136
lines changed

.claude/skills/bdg/SKILL.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ bdg <url> # Start session (1920x1080, headless if no display)
2020
bdg <url> --headless # Force headless mode
2121
bdg <url> --no-headless # Force visible browser window
2222
bdg status # Check session status
23-
bdg peek # Preview data without stopping
24-
bdg stop # Stop and save output
23+
bdg peek # Preview collected telemetry
24+
bdg stop # End session (use sparingly)
2525
bdg cleanup --force # Kill stale session
2626
bdg cleanup --aggressive # Kill all Chrome processes
2727
```
@@ -36,6 +36,8 @@ bdg peek # Preview collected data
3636
# No need to stop/restart - Chrome stays on the page
3737
```
3838

39+
**Don't stop sessions prematurely** - use `bdg peek` to inspect data. Only call `bdg stop` when completely done with browser automation.
40+
3941
## Screenshots
4042

4143
Always use `bdg dom screenshot` (raw CDP is blocked):

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/network/shared.ts

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* Contains getCookies and headers commands, plus shared data fetching utilities.
55
*/
66

7-
import * as fs from 'fs';
8-
97
import type { Command } from 'commander';
108

119
import { runCommand } from '@/commands/shared/CommandRunner.js';
@@ -16,12 +14,9 @@ import type {
1614
} from '@/commands/shared/optionTypes.js';
1715
import { getHARData, callCDP, getNetworkHeaders } from '@/ipc/client.js';
1816
import { validateIPCResponse } from '@/ipc/index.js';
19-
import { getSessionFilePath } from '@/session/paths.js';
20-
import type { BdgOutput, NetworkRequest } from '@/types.js';
21-
import { isDaemonConnectionError } from '@/ui/errors/utils.js';
17+
import type { NetworkRequest } from '@/types.js';
2218
import type { Cookie } from '@/ui/formatters/index.js';
2319
import { formatCookies, formatNetworkHeaders } from '@/ui/formatters/index.js';
24-
import { sessionNotActiveError } from '@/ui/messages/errors.js';
2520
import { EXIT_CODES } from '@/utils/exitCodes.js';
2621

2722
/**
@@ -42,63 +37,13 @@ export async function fetchFromLiveSession(): Promise<NetworkRequest[]> {
4237
}
4338

4439
/**
45-
* Fetch network requests from offline session.json file.
40+
* Get network requests from live daemon session.
4641
*
4742
* @returns Network requests array
48-
* @throws Error if session file not found or no network data available
49-
*/
50-
export function fetchFromOfflineSession(): NetworkRequest[] {
51-
const sessionPath = getSessionFilePath('OUTPUT');
52-
53-
if (!fs.existsSync(sessionPath)) {
54-
throw new Error(sessionNotActiveError('export network data'), {
55-
cause: { code: EXIT_CODES.RESOURCE_NOT_FOUND },
56-
});
57-
}
58-
59-
const sessionData = JSON.parse(fs.readFileSync(sessionPath, 'utf-8')) as BdgOutput;
60-
61-
if (!sessionData.data?.network) {
62-
throw new Error('No network data in session file', {
63-
cause: { code: EXIT_CODES.RESOURCE_NOT_FOUND },
64-
});
65-
}
66-
67-
return sessionData.data.network;
68-
}
69-
70-
/**
71-
* Check if error indicates daemon is unavailable.
72-
*
73-
* @param error - Error to check
74-
* @returns True if error indicates no active session or daemon connection failure
75-
*/
76-
export function isDaemonUnavailable(error: unknown): boolean {
77-
if (isDaemonConnectionError(error)) {
78-
return true;
79-
}
80-
81-
const errorMessage = error instanceof Error ? error.message : String(error);
82-
return errorMessage.includes('No active session');
83-
}
84-
85-
/**
86-
* Get network requests from live session or session.json.
87-
*
88-
* Tries live daemon first, falls back to offline session file.
89-
*
90-
* @returns Network requests array
91-
* @throws Error if no session available (live or offline)
43+
* @throws Error if daemon connection fails or no network data available
9244
*/
9345
export async function getNetworkRequests(): Promise<NetworkRequest[]> {
94-
try {
95-
return await fetchFromLiveSession();
96-
} catch (error) {
97-
if (isDaemonUnavailable(error)) {
98-
return fetchFromOfflineSession();
99-
}
100-
throw error;
101-
}
46+
return fetchFromLiveSession();
10247
}
10348

10449
/**

src/commands/stop.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type { StopResult } from '@/commands/types.js';
77
import { stopSession } from '@/ipc/client.js';
88
import { IPCErrorCode } from '@/ipc/index.js';
99
import { performSessionCleanup } from '@/session/cleanup.js';
10-
import { getSessionFilePath } from '@/session/paths.js';
1110
import { joinLines } from '@/ui/formatting.js';
1211
import { createLogger } from '@/ui/logging/index.js';
1312
import {
@@ -28,7 +27,7 @@ const log = createLogger('cleanup');
2827
* @param data - Stop result data
2928
*/
3029
function formatStop(data: StopResult): string {
31-
const outputLine = data.stopped.bdg ? sessionStopped(getSessionFilePath('OUTPUT')) : undefined;
30+
const outputLine = data.stopped.bdg ? sessionStopped() : undefined;
3231
const daemonsLine =
3332
data.stopped.daemons && data.orphanedDaemonsCount
3433
? orphanedDaemonsCleanedMessage(data.orphanedDaemonsCount)
@@ -50,13 +49,9 @@ function formatStop(data: StopResult): string {
5049
export function registerStopCommand(program: Command): void {
5150
program
5251
.command('stop')
53-
.description('Stop daemon and write collected telemetry to ~/.bdg/session.json')
52+
.description('Stop daemon and close browser session')
5453
.option('--kill-chrome', 'Also kill Chrome browser process', false)
5554
.addOption(jsonOption())
56-
.addHelpText(
57-
'after',
58-
'\nOutput Location:\n Default: ~/.bdg/session.json\n Tip: Copy to custom location with: cp ~/.bdg/session.json /path/to/output.json'
59-
)
6055
.action(async (options: StopCommandOptions) => {
6156
await runCommand<StopCommandOptions, StopResult>(
6257
async (opts) => {

src/daemon/lifecycle/workerCleanup.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
/**
22
* Worker Cleanup
33
*
4-
* Handles worker cleanup: DOM collection, CDP closure, Chrome termination, and output writing.
4+
* Handles worker cleanup: DOM collection, CDP closure, and Chrome termination.
55
*/
66

77
import type { CDPConnection } from '@/connection/cdp.js';
88
import type { TelemetryStore } from '@/daemon/worker/TelemetryStore.js';
99
import { writeChromePid } from '@/session/chrome.js';
10-
import { writeSessionOutput } from '@/session/output.js';
1110
import { collectDOM } from '@/telemetry/dom.js';
1211
import type { CleanupFunction, LaunchedChrome } from '@/types';
1312
import type { Logger } from '@/ui/logging/index.js';
@@ -19,7 +18,6 @@ import {
1918
workerRunningCleanup,
2019
workerClosingCDP,
2120
workerShutdownComplete,
22-
workerWritingOutput,
2321
} from '@/ui/messages/debug.js';
2422
import { delay } from '@/utils/async.js';
2523
import { getErrorMessage } from '@/utils/errors.js';
@@ -100,8 +98,6 @@ export async function cleanupWorker(
10098
}
10199
// If both chrome and cdp are null, Chrome launch failed - nothing to terminate
102100

103-
writeOutput(reason, telemetryStore, log);
104-
105101
log.debug(workerShutdownComplete());
106102
} catch (error) {
107103
console.error(`[worker] Error during cleanup: ${getErrorMessage(error)}`);
@@ -150,30 +146,3 @@ async function terminateChrome(
150146
console.error(`[worker] Error killing Chrome: ${getErrorMessage(error)}`);
151147
}
152148
}
153-
154-
/**
155-
* Write session output.
156-
*/
157-
function writeOutput(
158-
reason: 'normal' | 'crash' | 'timeout',
159-
telemetryStore: TelemetryStore,
160-
log: Logger
161-
): void {
162-
if (reason === 'normal') {
163-
try {
164-
log.debug(workerWritingOutput());
165-
const finalOutput = telemetryStore.buildOutput(false);
166-
writeSessionOutput(finalOutput);
167-
} catch (error) {
168-
console.error(`[worker] Error writing final output: ${getErrorMessage(error)}`);
169-
}
170-
} else {
171-
try {
172-
log.debug(`[worker] Writing partial output (reason: ${reason})`);
173-
const partialOutput = telemetryStore.buildOutput(true);
174-
writeSessionOutput(partialOutput);
175-
} catch (error) {
176-
console.error(`[worker] Error writing partial output: ${getErrorMessage(error)}`);
177-
}
178-
}
179-
}

src/ipc/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export async function startSession(
173173

174174
/**
175175
* Request session stop from the daemon.
176-
* Stops telemetry collection, closes Chrome, and writes output file.
176+
* Stops telemetry collection and closes Chrome.
177177
*
178178
* @returns Stop session response with termination status
179179
* @throws Error if connection fails, times out, or no active session

src/session/output.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/ui/formatters/sessionFormatters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function buildSessionManagementSection(): string {
8484
return section('Session Management:', [
8585
'bdg status Check session state',
8686
'bdg status --verbose Include Chrome diagnostics',
87-
'bdg stop End session & save output',
87+
'bdg stop End session',
8888
'bdg cleanup Clean stale sessions',
8989
]);
9090
}

src/ui/messages/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const PREVIEW_HEADERS = {
2121
* @returns Single-line tip for basic peek usage
2222
*/
2323
export function compactTipsMessage(): string {
24-
return 'Tip: bdg stop | bdg peek --last 50 | bdg peek --verbose';
24+
return 'Tip: bdg peek --last 50 | bdg peek --verbose';
2525
}
2626

2727
/**

src/ui/messages/session.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@ export function landingPage(options: LandingPageOptions): string {
7676
/**
7777
* Generate "session stopped" success message.
7878
*
79-
* @param outputPath - Path to session output file
8079
* @returns Formatted success message
8180
*/
82-
export function sessionStopped(outputPath: string): string {
83-
return `Session stopped. Output saved to: ${outputPath}`;
81+
export function sessionStopped(): string {
82+
return 'Session stopped';
8483
}
8584

8685
/**

0 commit comments

Comments
 (0)