@@ -63,13 +63,39 @@ function sortKeys<T>(obj: Record<string, T>): Record<string, T> {
6363 return sorted ;
6464}
6565
66+ /**
67+ * Register/update the current machine in machines.json.
68+ * Only writes the file when something meaningful changed:
69+ * - Machine is new (not in file yet)
70+ * - Machine name changed
71+ * - lastSeen is older than 1 day (UI only shows date, not time)
72+ * This avoids creating a git commit on every server startup.
73+ */
6674export function registerCurrentMachine ( ) : void {
6775 const data = readMachinesFile ( ) ;
68- data . machines [ config . machineId ] = {
69- name : config . machineName ,
70- lastSeen : new Date ( ) . toISOString ( ) ,
71- } ;
72- writeMachinesFile ( data ) ;
76+ const existing = data . machines [ config . machineId ] ;
77+ const now = new Date ( ) ;
78+
79+ let needsWrite = false ;
80+ if ( ! existing ) {
81+ needsWrite = true ;
82+ } else if ( existing . name !== config . machineName ) {
83+ needsWrite = true ;
84+ } else {
85+ const lastSeen = new Date ( existing . lastSeen ) ;
86+ const ageMs = now . getTime ( ) - lastSeen . getTime ( ) ;
87+ if ( ageMs > 24 * 60 * 60 * 1000 ) {
88+ needsWrite = true ;
89+ }
90+ }
91+
92+ if ( needsWrite ) {
93+ data . machines [ config . machineId ] = {
94+ name : config . machineName ,
95+ lastSeen : now . toISOString ( ) ,
96+ } ;
97+ writeMachinesFile ( data ) ;
98+ }
7399}
74100
75101export function setRepoMapping ( storePath : string , localPath : string ) : void {
0 commit comments