(
env: EnvLike,
deps: Pick<
BootstrapDeps,
'mkdirSync' | 'writeFileSync' | 'renameSync' | 'unlinkSync' | 'existsSync'
> = defaultDeps
)
| 380 | // Only seed IDENTITY.md on the initial boot. After that it's agent/user-owned |
| 381 | // content — we must not clobber edits on subsequent reboots. Bot-identity env |
| 382 | // var changes (KILOCLAW_BOT_NAME etc.) therefore only take effect on a fresh |
| 383 | // instance; existing instances keep whatever IDENTITY.md currently contains. |
| 384 | if (!deps.existsSync(IDENTITY_MD_DEST)) { |
| 385 | atomicWrite(IDENTITY_MD_DEST, formatBotIdentityMarkdown(env), { |
| 386 | writeFileSync: deps.writeFileSync, |
| 387 | renameSync: deps.renameSync, |
| 388 | unlinkSync: deps.unlinkSync, |
| 389 | }); |
| 390 | } |
| 391 | |
| 392 | for (const legacyPath of LEGACY_BOT_IDENTITY_DESTS) { |
| 393 | if (!deps.existsSync(legacyPath)) continue; |
| 394 | try { |
| 395 | deps.unlinkSync(legacyPath); |
| 396 | } catch (error) { |
| 397 | console.warn(`[controller] Failed to remove legacy bot identity file ${legacyPath}:`, error); |
| 398 | } |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | type UserProfileFields = { |
| 403 | timezone?: string; |
| 404 | location?: string; |
| 405 | }; |
| 406 | |
| 407 | function normalizeUserProfileFields(fields: string | UserProfileFields): UserProfileFields { |
| 408 | return typeof fields === 'string' ? { timezone: fields } : fields; |
| 409 | } |
| 410 | |
| 411 | export function formatUserProfileMarkdown(fields: string | UserProfileFields): string { |
| 412 | const profile = normalizeUserProfileFields(fields); |
| 413 | const personalFields = [ |
| 414 | '- Name:', |
no test coverage detected