(options: {
flavor: string
startedBy: SessionStartedBy
workingDirectory: string
machineId: string
now?: number
metadataOverrides?: Partial<Metadata>
})
| 51 | } |
| 52 | |
| 53 | export function buildSessionMetadata(options: { |
| 54 | flavor: string |
| 55 | startedBy: SessionStartedBy |
| 56 | workingDirectory: string |
| 57 | machineId: string |
| 58 | now?: number |
| 59 | metadataOverrides?: Partial<Metadata> |
| 60 | }): Metadata { |
| 61 | const happyLibDir = runtimePath() |
| 62 | const worktreeInfo = readWorktreeEnv() |
| 63 | const now = options.now ?? Date.now() |
| 64 | |
| 65 | return { |
| 66 | path: options.workingDirectory, |
| 67 | host: process.env.HAPI_HOSTNAME || os.hostname(), |
| 68 | version: packageJson.version, |
| 69 | os: os.platform(), |
| 70 | machineId: options.machineId, |
| 71 | homeDir: os.homedir(), |
| 72 | happyHomeDir: configuration.happyHomeDir, |
| 73 | happyLibDir, |
| 74 | happyToolsDir: resolve(happyLibDir, 'tools', 'unpacked'), |
| 75 | startedFromRunner: options.startedBy === 'runner', |
| 76 | hostPid: process.pid, |
| 77 | startedBy: options.startedBy, |
| 78 | lifecycleState: 'running', |
| 79 | lifecycleStateSince: now, |
| 80 | flavor: options.flavor, |
| 81 | capabilities: { |
| 82 | terminal: true |
| 83 | }, |
| 84 | worktree: worktreeInfo ?? undefined, |
| 85 | ...options.metadataOverrides |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | function pickExistingSessionMetadata(metadata: Metadata | null | undefined): Partial<Metadata> { |
| 90 | if (!metadata) return {} |
no test coverage detected