Capture whole-computer idle time, even outside the browser
This token identifies you to the server. Keep it private — anyone with it can log idle time on your timesheet. Regenerating invalidates the old one.
No token yet — generate oneA tiny Windows PowerShell agent (no install). It reads your computer's real idle time and reports completed idle windows to this server — working even when the browser is closed.
How to run
trust-idle-agent.ps1 anywhere on your PC.powershell -ExecutionPolicy Bypass -File trust-idle-agent.ps1).To stop & remove it later, run powershell -ExecutionPolicy Bypass -File trust-idle-agent.ps1 -Uninstall. Threshold and min-block are set at the top of the file to match the admin settings.
# Trust Idle Agent - installer + background agent.
# RUN ONCE: right-click this file -> Run with PowerShell, or:
# powershell -ExecutionPolicy Bypass -File trust-idle-agent.ps1
# It installs a hidden task (starts at logon + daily) and starts immediately.
# Remove: powershell -ExecutionPolicy Bypass -File trust-idle-agent.ps1 -Uninstall
param([switch]$Run, [switch]$Uninstall)
$ApiUrl = "http://localhost:3000/api/idle"
$Token = "PASTE-YOUR-TOKEN"
$ThresholdSeconds = 60 # must match the admin idle threshold (minutes x 60)
$MinBlockMinutes = 1 # ignore idle windows shorter than this
$PollSeconds = 5
$TaskName = "TrustIdleAgent"
$InstallDir = Join-Path $env:LOCALAPPDATA "TrustIdleAgent"
$InstallPath = Join-Path $InstallDir "trust-idle-agent.ps1"
$ConfigPath = Join-Path $InstallDir "config.json"
if ($Uninstall) {
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
Get-CimInstance Win32_Process -Filter "Name='powershell.exe'" | Where-Object { $_.CommandLine -like "*trust-idle-agent.ps1*-Run*" } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }
Remove-Item -LiteralPath (Join-Path ([Environment]::GetFolderPath("Startup")) "TrustIdleAgent.vbs") -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $ConfigPath -ErrorAction SilentlyContinue
try { Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show("Trust Idle Agent removed.","Trust Idle Agent") | Out-Null } catch {}
return
}
if (-not $Run) {
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
if ([System.IO.Path]::GetFullPath($PSCommandPath) -ne [System.IO.Path]::GetFullPath($InstallPath)) { Copy-Item -LiteralPath $PSCommandPath -Destination $InstallPath -Force } # skip when already running from the install folder
# Resolve token: embedded (per-user build) > existing config > prompt once (signed shared build)
$effToken = $Token
if ($effToken -eq "PASTE-YOUR-TOKEN" -or [string]::IsNullOrWhiteSpace($effToken)) { if (Test-Path $ConfigPath) { try { $effToken = (Get-Content -Raw -LiteralPath $ConfigPath | ConvertFrom-Json).token } catch {} } }
if ($effToken -eq "PASTE-YOUR-TOKEN" -or [string]::IsNullOrWhiteSpace($effToken)) { try { Add-Type -AssemblyName Microsoft.VisualBasic; $effToken = [Microsoft.VisualBasic.Interaction]::InputBox("Paste your Trust agent token (from the Idle Agent page):", "Trust Idle Agent", "") } catch {} }
if ([string]::IsNullOrWhiteSpace($effToken)) { try { Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show("No token provided - setup cancelled.","Trust Idle Agent") | Out-Null } catch {}; return }
$Token = $effToken
@{ token = $Token; api = $ApiUrl } | ConvertTo-Json | Set-Content -LiteralPath $ConfigPath -Encoding UTF8
$arg = '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "' + $InstallPath + '" -Run'
$method = ""
# Preferred: Task Scheduler (logon + daily). Some PCs restrict this without admin.
try {
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $arg
$trigger = @( (New-ScheduledTaskTrigger -AtLogOn), (New-ScheduledTaskTrigger -Daily -At 7am) )
$princ = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive -RunLevel Limited
$set = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -MultipleInstances IgnoreNew -ExecutionTimeLimit ([TimeSpan]::Zero)
Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger -Principal $princ -Settings $set -Description "Trust idle-time capture agent" -Force -ErrorAction Stop | Out-Null
$method = "Task Scheduler (logon + daily)"
} catch {
# Fallback: Startup-folder launcher - no admin rights required
try {
$startup = [Environment]::GetFolderPath("Startup")
$vbs = Join-Path $startup "TrustIdleAgent.vbs"
$line = 'CreateObject("Wscript.Shell").Run "powershell -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File ""' + $InstallPath + '"" -Run", 0, False'
Set-Content -LiteralPath $vbs -Value $line -Encoding ASCII
$method = "Startup folder (hidden, at logon)"
} catch { $method = "" }
}
# Start immediately in the background regardless of autostart method
Start-Process powershell -WindowStyle Hidden -ArgumentList $arg
if ($method -ne "") { $msg = "Trust Idle Agent is running in the background and will auto-start via " + $method + ". No window will appear." }
else { $msg = "Trust Idle Agent is running now, but auto-start could not be set on this PC. Right-click the file and Run as administrator to enable auto-start (otherwise it must be started again after a reboot)." }
try { Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.MessageBox]::Show($msg,"Trust Idle Agent") | Out-Null } catch { Write-Host $msg }
return
}
# ---- config: prefer values saved at install (supports one signed build for everyone) ----
if (Test-Path $ConfigPath) { try { $cfg = Get-Content -Raw -LiteralPath $ConfigPath | ConvertFrom-Json; if ($cfg.token) { $Token = $cfg.token }; if ($cfg.api) { $ApiUrl = $cfg.api } } catch {} }
# ---- AGENT MODE (-Run): hidden idle loop ----
Add-Type @"
using System;
using System.Runtime.InteropServices;
public static class TrustIdle {
[DllImport("user32.dll")]
static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[StructLayout(LayoutKind.Sequential)]
public struct LASTINPUTINFO { public uint cbSize; public uint dwTime; }
public static uint IdleSeconds() {
LASTINPUTINFO lii = new LASTINPUTINFO();
lii.cbSize = (uint)Marshal.SizeOf(lii);
GetLastInputInfo(ref lii);
return (uint)((Environment.TickCount - (int)lii.dwTime) / 1000);
}
}
"@
# Durable offline queue: windows are appended locally, then flushed to the
# server whenever it is reachable (survives VPS downtime / no network / sleep).
$QueuePath = Join-Path $InstallDir "queue.jsonl"
function Send-Item($json) {
# $true = server was reached (drop item); $false = could not reach (retry later)
try {
Invoke-RestMethod -Uri $ApiUrl -Method Post -Body $json -ContentType "application/json" -TimeoutSec 15 | Out-Null
return $true
} catch {
$resp = $_.Exception.Response
if ($resp -ne $null) { $code = [int]$resp.StatusCode; if ($code -ge 500) { return $false } else { return $true } }
return $false
}
}
function Flush-Queue {
if (-not (Test-Path $QueuePath)) { return }
$lines = @(Get-Content -LiteralPath $QueuePath -ErrorAction SilentlyContinue | Where-Object { $_ -and $_.Trim() -ne "" })
if ($lines.Count -eq 0) { return }
$keep = New-Object System.Collections.Generic.List[string]
$cutoff = (Get-Date).AddDays(-60)
$blocked = $false
foreach ($l in $lines) {
if ($blocked) { $keep.Add($l); continue }
try { $d = ($l | ConvertFrom-Json).date; if ([datetime]$d -lt $cutoff) { continue } } catch {}
if (Send-Item $l) { } else { $keep.Add($l); $blocked = $true }
}
if ($keep.Count -eq 0) { Remove-Item -LiteralPath $QueuePath -ErrorAction SilentlyContinue }
else { Set-Content -LiteralPath $QueuePath -Value $keep }
}
function Send-Heartbeat($state) {
try { $r = Invoke-RestMethod -Uri $ApiUrl -Method Post -Body (@{ token = $Token; heartbeat = $true; state = $state } | ConvertTo-Json -Compress) -ContentType "application/json" -TimeoutSec 15; $script:AgentDisabled = [bool]$r.disabled } catch {}
}
$script:AgentDisabled = $false
Flush-Queue # drain any backlog left from a previous offline session
Send-Heartbeat "active" # check in immediately as active
$idleStart = $null
$cycle = 0
while ($true) {
if ($script:AgentDisabled) {
# An administrator has stopped this agent: drop any in-progress idle window,
# stand down, and poll about once a minute so it resumes automatically if re-enabled.
$idleStart = $null
Start-Sleep -Seconds 60
Send-Heartbeat "disabled"
continue
}
$idle = [TrustIdle]::IdleSeconds()
if ($idle -ge $ThresholdSeconds -and $null -eq $idleStart) {
$idleStart = (Get-Date).AddSeconds(-$idle)
Send-Heartbeat "idle"
}
elseif ($idle -lt $ThresholdSeconds -and $null -ne $idleStart) {
$end = Get-Date
$mins = [math]::Round((New-TimeSpan -Start $idleStart -End $end).TotalMinutes)
if ($mins -ge $MinBlockMinutes) {
$body = @{ token=$Token; date=$idleStart.ToString("yyyy-MM-dd"); start=$idleStart.ToString("HH:mm"); end=$end.ToString("HH:mm"); minutes=$mins } | ConvertTo-Json -Compress
Add-Content -LiteralPath $QueuePath -Value $body
Flush-Queue
}
$idleStart = $null
Send-Heartbeat "active"
}
$cycle++
if ($cycle % 12 -eq 0) { Flush-Queue } # periodic drain (~every minute)
if ($cycle % 36 -eq 0) { Send-Heartbeat $(if ($null -ne $idleStart) { "idle" } else { "active" }) } # keep-alive + live state (~every 3 min)
Start-Sleep -Seconds $PollSeconds
}
Organization-wide idle capture rules
0 live · 0 ever connected · 8 without an agent
| Employee | Department | Heart Beat | Live Status | Last contact | Agent |
|---|---|---|---|---|---|
| Adaeze Okonkwo | Civil | No agent | — | — | |
| Amara Banguraadmin | Civil | No agent | — | — | |
| Daniel Otieno | Architecture | No agent | — | — | |
| Faisal Al-Mansoori | Finance | No agent | — | — | |
| James Okoro | MEP | No agent | — | — | |
| Joseph Tubman | MEP | No agent | — | — | |
| Kofi Boateng | Architecture | No agent | — | — | |
| Tarek Bitar | Architecture | No agent | — | — |