Repository navigation
feat(profiles): bind the active profile to the parent session (#1064 1/2) #1557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
barbatdev
merged 7 commits into
Gentleman-Programming:main
from
danielgap:feat/1064-session-bind
Oct 3, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a941993
feat(profiles): bind the active profile to the parent session
danielgap 6da3a5c
fix(profiles): narrow the profiles store read in the panel tests
danielgap f1acb9e
docs(profiles): cover the touched functions the docstring gate flags
danielgap 723a7a4
Merge remote-tracking branch 'origin/main' into refresh-1557
danielgap 9b7896c
Merge remote-tracking branch 'origin/main' into ws/1557-fix
danielgap 97a3726
test(profiles): confirm the global apply dialog in the legacy panel test
danielgap f23f578
fix(profiles): keep the slice-1 session-binding copy truthful about l…
danielgap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Session-bound active profiles (gentle-shell#1064, slice 1). | ||
| // | ||
| // One parent Pi session may bind one saved profile for its own launches without | ||
| // touching any shared state: no clone pin (`p`), no repository declaration (`P`), | ||
| // no global routing, no materialized stores, no agent frontmatter, no Pi default | ||
| // settings. The binding is an in-process map keyed by the parent session id, so | ||
| // concurrent Pi processes are isolated by construction and a resumed session | ||
| // starts from the shared layers (`p → P → global`) until it binds again. | ||
| // Persistence across resume and reload semantics are deliberate follow-up | ||
| // slices; this module never writes a file. | ||
| import type { AgentModelConfig } from "./model-routing-authority.ts"; | ||
|
|
||
| /** A session's bound profile: its saved name plus the routing snapshot taken at bind time. */ | ||
| export interface SessionProfileBinding { | ||
| readonly name: string; | ||
| readonly modelProfiles: AgentModelConfig; | ||
| } | ||
|
|
||
| const bindingsBySession = new Map<string, SessionProfileBinding>(); | ||
|
|
||
| /** Copy one routing snapshot level deep — the layer a defensive copy needs, so a binding never aliases its source or its readers. */ | ||
| function cloneProfiles(profiles: AgentModelConfig): AgentModelConfig { | ||
| return Object.fromEntries(Object.entries(profiles).map(([agent, entry]) => [agent, { ...entry }])); | ||
| } | ||
|
|
||
| /** | ||
| * Bind (or rebind) one parent session to a profile. The routing snapshot is | ||
| * copied, so later edits to the caller's object or to the saved profile | ||
| * definition never mutate a session that already bound it; refreshing a bound | ||
| * session requires an explicit re-selection. | ||
| */ | ||
| export function bindSessionProfile(sessionId: string, name: string, modelProfiles: AgentModelConfig): void { | ||
| bindingsBySession.set(sessionId, { name, modelProfiles: cloneProfiles(modelProfiles) }); | ||
| } | ||
|
|
||
| /** | ||
| * Read a session's binding as a private copy. Returns `undefined` for unknown, | ||
| * cleared, or undefined session ids: an unbound session keeps resolving the | ||
| * shared layers exactly as before. | ||
| */ | ||
| export function readSessionProfileBinding(sessionId: string | undefined): SessionProfileBinding | undefined { | ||
| if (sessionId === undefined) return undefined; | ||
| const binding = bindingsBySession.get(sessionId); | ||
| return binding === undefined ? undefined : { name: binding.name, modelProfiles: cloneProfiles(binding.modelProfiles) }; | ||
| } | ||
|
|
||
| /** Remove one session's binding without touching any other session's. */ | ||
| export function clearSessionProfileBinding(sessionId: string): void { | ||
| bindingsBySession.delete(sessionId); | ||
| } | ||
|
|
||
| /** Testing-only reset of every binding. */ | ||
| export function resetSessionProfileBindingsForTesting(): void { | ||
| bindingsBySession.clear(); | ||
| } | ||
|
|
||
| /** | ||
| * The launch-time precedence for wholesale routing replacement: a session | ||
| * binding outranks a winning pin, a pin alone still replaces, and neither | ||
| * leaves today's routing untouched. Named so the precedence rule a launch and | ||
| * the status display agree on lives in exactly one place. | ||
| */ | ||
| export function sessionOrPinModelProfiles( | ||
| session: AgentModelConfig | undefined, | ||
| pin: AgentModelConfig | undefined, | ||
| ): AgentModelConfig | undefined { | ||
| return session ?? pin; | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
rg -n 'refreshListItems|buildProfileListItems|sessionBoundName' extensions/gentle-ai.tsRepository: Gentleman-Programming/gentle-shell
Length of output: 1113
🏁 Script executed:
Repository: Gentleman-Programming/gentle-shell
Length of output: 13172
🏁 Script executed:
Repository: Gentleman-Programming/gentle-shell
Length of output: 25599
🏁 Script executed:
rg -n -C 8 'function buildProfileListItems|const buildProfileListItems|buildProfileListItems =|sessionBoundName' extensions/gentle-ai.tsRepository: Gentleman-Programming/gentle-shell
Length of output: 5720
🏁 Script executed:
Repository: Gentleman-Programming/gentle-shell
Length of output: 5739
🏁 Script executed:
rg -n -C 16 'buildProfileListItems|sessionBoundName' lib/model-routing-authority.tsRepository: Gentleman-Programming/gentle-shell
Length of output: 172
🏁 Script executed:
Repository: Gentleman-Programming/gentle-shell
Length of output: 2901
Pass the session-bound name when refreshing profile list items.
When
sis pressed,refreshListItemsrebuilds the list withoutthis.sessionBoundName. The session-bound profile can then lose its(session)marker, while the detail pane still shows the session row.Suggested fix
🤖 Prompt for AI Agents