swlive.bend relies on unsafe/foreign
raw source on the hub · import cswap-bend-cli@0.1.0.0/swlive.bend as Swlive
15 imports
import Base import ./json.bend as Json import ./fs.bend as Fs import ./act.bend as Act import ./store.bend as Store import ./lock.bend as Lock import ./dirlock.bend as Dirlock import ./b64.bend as B64 import ./swbase.bend as B import ./swcreds.bend as C import ./fs/write.bend as FsW import ./store/base.bend as SBase import ./store/io.bend as SIo import ./store/plan.bend as SPlan import ./store/seq.bend as SSeq
Types
type Oracle source · line 21 · raw
Data
OHttpOracle
OFile@path:String -> Oracle
ONoneOracle
type Opts source · line 26 · raw
Data
Opts@delay_ms:U32 -> @oracle:Oracle -> Opts
type Live source · line 30 · raw
Data
~/.claude.json and .credentials.json as they are right now.
Live@cfg_text:Maybe<&2, String> -> @cfg:Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/json.Json> -> @creds_text:Maybe<&2, String> -> Live
type Pre source · line 34 · raw
Data
The live credential as read before the locks, and what the oracle said of it.
Pre@live:String -> @prof:0x0717344745a30ebad1f19045228e8f18/store/plan.Prof -> Pre
Definitions
def ActM source · line 37 · raw
@-A:Type -> Type
def ActM.pure source · line 40 · raw
@-A:Type -> @x:A -> 0x0717344745a30ebad1f19045228e8f18/act.of(A)
def ActM.bind source · line 43 · raw
@-A:Type -> @-B:Type -> @m:0x0717344745a30ebad1f19045228e8f18/act.of(A) -> @f:(@_:A -> 0x0717344745a30ebad1f19045228e8f18/act.of(B)) -> 0x0717344745a30ebad1f19045228e8f18/act.of(B)
def opts_delay source · line 46 · raw
@+o:Opts -> U32
def opts_oracle source · line 51 · raw
@+o:Opts -> Oracle
def file_prof source · line 56 · raw
@r:0x0717344745a30ebad1f19045228e8f18/fs.Res(String) -> 0x0717344745a30ebad1f19045228e8f18/store/plan.Prof
def run_oracle source · line 65 · raw
@+o:Oracle -> @+token:String -> IO(0x0717344745a30ebad1f19045228e8f18/store/plan.Prof)
Ask the oracle whose token this is. OHttp is GET /api/oauth/profile; OFile answers from a JSON file (tests); ONone never resolves.
def read_text_opt2 source · line 74 · raw
@+ex:Bool -> @+path:String -> 0x0717344745a30ebad1f19045228e8f18/act.of(Maybe<&2, String>)
def read_text_opt source · line 84 · raw
@+path:String -> 0x0717344745a30ebad1f19045228e8f18/act.of(Maybe<&2, String>)
The file's text, None when it does not exist.
def parse_text2 source · line 89 · raw
@r:Result<&2, &2, String, 0x0717344745a30ebad1f19045228e8f18/json.Json> -> Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/json.Json>
def parse_text source · line 96 · raw
@+m:Maybe<&2, String> -> Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/json.Json>
def read_live source · line 103 · raw
@+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> 0x0717344745a30ebad1f19045228e8f18/act.of(Live)
def lv_cfg source · line 109 · raw
@+l:Live -> 0x0717344745a30ebad1f19045228e8f18/json.Json
def lv_cfg_text source · line 114 · raw
@+l:Live -> Maybe<&2, String>
def lv_cfg_ok source · line 119 · raw
@+l:Live -> Bool
def lv_creds_text source · line 124 · raw
@+l:Live -> Maybe<&2, String>
def lv_creds source · line 130 · raw
@+l:Live -> String
The live credential: the file, else a managed key in the config.
def lv_email source · line 134 · raw
@+l:Live -> String
(email, organizationUuid) the config names; "" email means logged out.
def lv_org source · line 137 · raw
@+l:Live -> String
def lv_slot2 source · line 140 · raw
@+has:Bool -> @+l:Live -> @+seq:0x0717344745a30ebad1f19045228e8f18/json.Json -> Maybe<&2, String>
def lv_slot source · line 148 · raw
@+l:Live -> @+seq:0x0717344745a30ebad1f19045228e8f18/json.Json -> Maybe<&2, String>
The slot the live login belongs to, if it is managed.
def sel_o source · line 151 · raw
@+c:Bool -> @+x:List<&2, 0x0717344745a30ebad1f19045228e8f18/swcreds.Other> -> @+y:List<&2, 0x0717344745a30ebad1f19045228e8f18/swcreds.Other> -> List<&2, 0x0717344745a30ebad1f19045228e8f18/swcreds.Other>
def other_creds source · line 158 · raw
@+root:String -> @+seq:0x0717344745a30ebad1f19045228e8f18/json.Json -> @+slots:List<&2, String> -> @+current:String -> 0x0717344745a30ebad1f19045228e8f18/act.of(List<&2, 0x0717344745a30ebad1f19045228e8f18/swcreds.Other>)
def archive_live source · line 168 · raw
@+root:String -> @+email:String -> @+creds:String -> @+ts:String -> 0x0717344745a30ebad1f19045228e8f18/act.of(Unit)
def archive_if source · line 174 · raw
@+needed:Bool -> @+root:String -> @+email:String -> @+creds:String -> @+ts:String -> 0x0717344745a30ebad1f19045228e8f18/act.of(Unit)
def write_live_creds2 source · line 177 · raw
@+api_key:Bool -> @+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> @+creds:String -> 0x0717344745a30ebad1f19045228e8f18/act.of(Unit)
def write_live_creds source · line 187 · raw
@+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> @+creds:String -> 0x0717344745a30ebad1f19045228e8f18/act.of(Unit)
Put the target's credential live. An API key leaves no .credentials.json.
def write_cfg source · line 190 · raw
@+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> @+j:0x0717344745a30ebad1f19045228e8f18/json.Json -> 0x0717344745a30ebad1f19045228e8f18/act.of(Unit)
def restore_text source · line 193 · raw
@+path:String -> @+m:Maybe<&2, String> -> 0x0717344745a30ebad1f19045228e8f18/act.of(Unit)
def restore source · line 201 · raw
@+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> @+root:String -> @+creds:Maybe<&2, String> -> @+cfg:Maybe<&2, String> -> @+seq_text:String -> 0x0717344745a30ebad1f19045228e8f18/act.of(Unit)
Undo a half-done switch: the three files go back to their old text.
def wrap_failure source · line 207 · raw
@r:0x0717344745a30ebad1f19045228e8f18/fs.Res(Unit) -> 0x0717344745a30ebad1f19045228e8f18/fs.Res(Unit)
def config_home_of source · line 214 · raw
@+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> String
def with_locks source · line 221 · raw
@-A:Type -> @+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> @act:0x0717344745a30ebad1f19045228e8f18/act.of(A) -> 0x0717344745a30ebad1f19045228e8f18/act.of(A)
Claude Code's lock directories and cswap's own flock, in the reference's order: .lock, then the credentials pair, then the config lock.
def sel_prof source · line 227 · raw
@+c:Bool -> @+x:0x0717344745a30ebad1f19045228e8f18/store/plan.Prof -> @+y:0x0717344745a30ebad1f19045228e8f18/store/plan.Prof -> 0x0717344745a30ebad1f19045228e8f18/store/plan.Prof
def pre_prof source · line 234 · raw
@+pre:Pre -> @+live:String -> 0x0717344745a30ebad1f19045228e8f18/store/plan.Prof
def no_pre source · line 239 · raw
Pre
def need_lookup source · line 242 · raw
@+slot:Maybe<&2, String> -> @+live:String -> @+backup:String -> Bool
def prefetch2 source · line 247 · raw
@+want:Bool -> @+o:Oracle -> @+live:String -> 0x0717344745a30ebad1f19045228e8f18/act.of(0x0717344745a30ebad1f19045228e8f18/store/plan.Prof)
_prefetch_live_identity: before any lock is taken, look the diverged live
credential up (the only network call of a switch).
def lookup_need source · line 250 · raw
@+l:Live -> @+seq:0x0717344745a30ebad1f19045228e8f18/json.Json -> @+backup:String -> Bool
def backup_of source · line 253 · raw
@+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> @+l:Live -> @+seq:0x0717344745a30ebad1f19045228e8f18/json.Json -> 0x0717344745a30ebad1f19045228e8f18/act.of(String)
def lookup_for source · line 256 · raw
@+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> @+o:Oracle -> @+l:Live -> @+seq:0x0717344745a30ebad1f19045228e8f18/json.Json -> 0x0717344745a30ebad1f19045228e8f18/act.of(0x0717344745a30ebad1f19045228e8f18/store/plan.Prof)
def prefetch3 source · line 261 · raw
@+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> @+o:Oracle -> @+l:Live -> @+m:Maybe<&2, 0x0717344745a30ebad1f19045228e8f18/json.Json> -> 0x0717344745a30ebad1f19045228e8f18/act.of(Pre)
def prefetch source · line 270 · raw
@+ctx:0x0717344745a30ebad1f19045228e8f18/store/base.Ctx -> @+o:Oracle -> 0x0717344745a30ebad1f19045228e8f18/act.of(Pre)