@@ -2,10 +2,10 @@ import net from 'node:net';
22import fs from 'node:fs' ;
33import os from 'node:os' ;
44import path from 'node:path' ;
5- import { fileURLToPath } from 'node:url' ;
65import { AppError } from './utils/errors.ts' ;
76import type { CommandFlags } from './core/dispatch.ts' ;
87import { runCmdDetached } from './utils/exec.ts' ;
8+ import { findProjectRoot , readVersion } from './utils/version.ts' ;
99
1010export type DaemonRequest = {
1111 token : string ;
@@ -134,33 +134,10 @@ async function sendRequest(info: DaemonInfo, req: DaemonRequest): Promise<Daemon
134134 } ) ;
135135}
136136
137- function readVersion ( ) : string {
138- try {
139- const root = findProjectRoot ( ) ;
140- const pkg = JSON . parse ( fs . readFileSync ( path . join ( root , 'package.json' ) , 'utf8' ) ) as {
141- version ?: string ;
142- } ;
143- return pkg . version ?? '0.0.0' ;
144- } catch {
145- return '0.0.0' ;
146- }
147- }
148-
149137function resolveRequestTimeoutMs ( ) : number {
150138 const raw = process . env . AGENT_DEVICE_DAEMON_TIMEOUT_MS ;
151139 if ( ! raw ) return 60000 ;
152140 const parsed = Number ( raw ) ;
153141 if ( ! Number . isFinite ( parsed ) ) return 60000 ;
154142 return Math . max ( 1000 , Math . floor ( parsed ) ) ;
155143}
156-
157- function findProjectRoot ( ) : string {
158- const start = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
159- let current = start ;
160- for ( let i = 0 ; i < 6 ; i += 1 ) {
161- const pkgPath = path . join ( current , 'package.json' ) ;
162- if ( fs . existsSync ( pkgPath ) ) return current ;
163- current = path . dirname ( current ) ;
164- }
165- return start ;
166- }
0 commit comments