Repository navigation
feat(bootstrap): inject per-user app_profile into agent context (profile Phase 3) - #68
Merged
Merged
Conversation
…e 3) For app-user sessions, surface the chatting user's app_profile section as a synthetic APP_PROFILE.md bootstrap context file injected into the system prompt every turn, so the agent always knows who it is talking to without being reminded (the per-user-profile plan, Phase 3). - New src/agents/app-profile-context.ts: extractAppProfileSection (fail-closed marker extractor), clampAppProfile (UTF-8 byte-safe 2KB cap, mirrors the writer + dashboard caps), buildAppProfileContextFile (pure), and appendAppProfileBootstrapFile (app-session-only via isAppUserSession + resolveAppUserId; reads the canonical users/<appUserId>.md). - bootstrap-files.ts: append the synthetic file after hook overrides and before the buildBootstrapContextFiles clamp, so it is budgeted and survives compaction (compact.ts uses the same resolver). First-class in bootstrap assembly (not a config-gated host hook): zero-config, app-session-only, byte-bounded, resolved per-turn (no cross-session caching, so no cross-user leak). Telegram / no-appUserId sessions are no-ops. Reaches the live agent on the next gateway image roll. Gate: vitest app-profile-context 14/14; tsgo clean on the touched files; oxfmt. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Owner
Author
|
@codex review Phase 3 of the per-user-profile plan — first-class gateway injection of the per-user
Gate: vitest app-profile-context 14/14; tsgo clean on the touched files (repo-wide |
cryptolir
added a commit
that referenced
this pull request
Jun 17, 2026
Record the per-user-profile Phase 3 deploy: PR #68 (app_profile context injection) + #69 (CI gate fix) merged; gateway image v2026.06.17.1 (sourceSha 50f6c2d) built and pinned to the life agent only on 2ndClaw; life workspace AGENTS.md gained the app_profile writable section + rules. Note the intentional life-ahead image drift on the US host. Co-authored-by: Liran Peretz <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
cryptolir
added a commit
that referenced
this pull request
Jun 17, 2026
…sion (#71) resolveAppUserId reads appUserId from the persisted session entry, but chat.send only writes it onto an EXISTING entry (updateSessionStoreEntry no-ops when the entry is missing). On the first turn of a brand-new session the entry doesn't exist yet, so the id isn't available and the APP_PROFILE.md injection no-ops — the agent asks the user their name even though we know it. Every new app conversation (e.g. a page refresh / new chat) starts a fresh session and hit this; from turn 2 on the entry exists and the profile injects correctly. Fix: add appUserIdFromSessionKey() as a fallback. When the persisted entry has no appUserId yet, derive it from the session key itself — the second-to-last ":"-segment after ":app:", valid for both the namespaced 4-part form (app:havaya:<userId>:<conv>) and the legacy 3-part form (app:<userId>:<conv>), since the conversationId is always the final colon-free segment. Read-only and same-user (the id comes from this very session's key) — it cannot surface another user's profile, and it leaves the shared resolveAppUserId (and thus the workspace jail + save_user_section) untouched. Also brace the guard-returns in this file to satisfy oxlint `curly` — it was the only file with project lint errors (pre-existing from #68's --admin merge), so this greens `pnpm lint` repo-wide. Tests: appUserIdFromSessionKey unit cases (4-part / 3-part / bare / lowercasing / non-app / no-userId / undefined) + a first-turn fallback integration test (temp users/<id>.md, no persisted entry). vitest 22/22, lint 0, format clean. Co-authored-by: Liran Peretz <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
cryptolir
added a commit
that referenced
this pull request
Jun 18, 2026
…oad_skill #74) (#75) Record the load_skill roll: #74 merged, gateway v2026.06.18.1 (sourceSha 09a99e4) pinned to life only — ships the full per-user stack to prod (writer #65/#66 + injection #68 + first-turn #71 + load_skill #74). Bump the INFRASTRUCTURE life-ahead tag to v2026.06.18.1 and note the US-host disk cleanup (97% to 67%, removed 8 unused/unreferenced gateway tags). Co-authored-by: Liran Peretz <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per-user-profile plan — Phase 3: inject
app_profileinto the agent's context every turn. The capstone — the agent now always knows the user's name and running summary without being reminded. Built from the design investigation against the actual bootstrap-assembly code (plan #64).What
For an app-user session, the chatting user's
app_profilesection (seeded by the Havaya app, maintained by the agent viasave_user_section) is surfaced as a syntheticAPP_PROFILE.mdbootstrap context file injected into the system prompt every turn.src/agents/app-profile-context.ts(pure + one IO wrapper):extractAppProfileSection— fail-closed marker extractor (null on absent / malformed / duplicate). Cross-repo contract with the writer'supsertSectionand the dashboard'sextractSection.clampAppProfile— UTF-8 byte-safe 2 KB cap (mirrorsSECTION_CONTENT_BYTE_CAPS.app_profileand the dashboardAPP_PROFILE_MAX_BYTES). Defense-in-depth: admin/raw-edited files bypass the writer cap, so clamp again before injecting.appendAppProfileBootstrapFile— app-session-only (isAppUserSession+resolveAppUserId), reads the canonicalusers/<appUserId>.md, no-op otherwise.src/agents/bootstrap-files.ts(3-line wrap): append the synthetic file after hook overrides (so user hooks can't strip it) and beforebuildBootstrapContextFiles(so the existing per-file / total budget clamps apply). The model sees it as## APP_PROFILE.md— a bare filename, so the on-diskusers/<id>.mdpath never leaks.Why first-class (not a host hook)
The
agent:bootstrapbundled-hook path is gated behindhooks.internal.enabled+ a per-hook config entry — incompatible with "always-on, app-session-only, zero-config." A direct step in bootstrap assembly is simpler and matches codex's guidance on plan #64.Safety
runAttempt—loadWorkspaceBootstrapFilesre-reads disk andresolveAppUserIdre-reads the session entry every call; no per-agent memoization. Different sessions resolve differentappUserIds independently.compact.tsuses the same resolver, so the profile stays injected after compaction.appUserId/ missing-file / empty-section → no-op.Gate
vitest src/agents/app-profile-context.test.ts→ 14/14 (extractor incl. fail-closed dup, byte-safe clamp incl. multi-byte straddle, synthetic-file shape, non-app no-op).tsgo --noEmit→ clean on the touched files.checkis red on pre-existing tsgo errors (chat.ts:417, two test files — none mine), tracked separately; this PR adds none.Not in this PR
Agent SOUL.md/AGENTS.md prose so the agent maintains the running summary (host-side,
2ndclaw), and the gateway image roll that ships this + the Phase-1/2 writer to the livelifeagent.🤖 Generated with Claude Code