| 1 | package control |
| 2 | |
| 3 | import "maps" |
| 4 | |
| 5 | // SessionAuthorizations is the same-session tool-grant, external-folder read |
| 6 | // access, and Plan-mode command trust a controller rebuild must carry forward; see |
| 7 | // Controller.SessionAuthorizations / RestoreSessionAuthorizations. |
| 8 | type SessionAuthorizations struct { |
| 9 | Grants []string |
| 10 | PlanModeReadOnlyCommands []string |
| 11 | WriteRoots []string |
| 12 | |
| 13 | // Keep exact session-issued aliases private and detached from controller state. |
| 14 | externalFolderRefs map[string]string |
| 15 | } |
| 16 | |
| 17 | // Snapshots retain the original aliases and canonical roots: re-registering |
| 18 | // filesystem paths could resolve changed symlinks or mint different tokens. |
| 19 | func (c *Controller) snapshotExternalFolderRefs() map[string]string { |
| 20 | c.externalFolderRefsMu.RLock() |
| 21 | defer c.externalFolderRefsMu.RUnlock() |
| 22 | return maps.Clone(c.externalFolderRefs) |
| 23 | } |
| 24 | |
| 25 | func (c *Controller) restoreExternalFolderRefs(refs map[string]string) { |
| 26 | if len(refs) == 0 { |
| 27 | return |
| 28 | } |
| 29 | c.externalFolderRefsMu.Lock() |
| 30 | if c.externalFolderRefs == nil { |
| 31 | c.externalFolderRefs = make(map[string]string, len(refs)) |
| 32 | } |
| 33 | maps.Copy(c.externalFolderRefs, refs) |
| 34 | c.externalFolderRefsMu.Unlock() |
| 35 | // Each replacement owns a fresh read-tool resolver. Controller aliases alone |
| 36 | // are insufficient; carry the same read-only roots to the assembled tools. |
| 37 | if c.externalFolderToolRefs != nil { |
| 38 | for token, root := range refs { |
| 39 | c.externalFolderToolRefs.RegisterReadRoot(token, root) |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 |