MCPcopy Create free account
hub / github.com/tiann/hapi / buildSessionMetadata

Function buildSessionMetadata

cli/src/agent/sessionFactory.ts:53–87  ·  view source on GitHub ↗
(options: {
    flavor: string
    startedBy: SessionStartedBy
    workingDirectory: string
    machineId: string
    now?: number
    metadataOverrides?: Partial<Metadata>
})

Source from the content-addressed store, hash-verified

51}
52
53export 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
89function pickExistingSessionMetadata(metadata: Metadata | null | undefined): Partial<Metadata> {
90 if (!metadata) return {}

Callers 3

bootstrapSessionFunction · 0.85
bootstrapExistingSessionFunction · 0.85

Calls 2

runtimePathFunction · 0.90
readWorktreeEnvFunction · 0.90

Tested by

no test coverage detected