MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / writeBotIdentityFile

Function writeBotIdentityFile

services/kiloclaw/controller/src/bootstrap.ts:382–411  ·  view source on GitHub ↗
(
  env: EnvLike,
  deps: Pick<
    BootstrapDeps,
    'mkdirSync' | 'writeFileSync' | 'renameSync' | 'unlinkSync' | 'existsSync'
  > = defaultDeps
)

Source from the content-addressed store, hash-verified

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
402type UserProfileFields = {
403 timezone?: string;
404 location?: string;
405};
406
407function normalizeUserProfileFields(fields: string | UserProfileFields): UserProfileFields {
408 return typeof fields === 'string' ? { timezone: fields } : fields;
409}
410
411export function formatUserProfileMarkdown(fields: string | UserProfileFields): string {
412 const profile = normalizeUserProfileFields(fields);
413 const personalFields = [
414 '- Name:',

Callers 2

bootstrap.test.tsFile · 0.90
runOnboardOrDoctorFunction · 0.85

Calls 3

atomicWriteFunction · 0.90
warnMethod · 0.65

Tested by

no test coverage detected