[{"data":1,"prerenderedAt":863,"buildId":864},["ShallowReactive",2],{"docs:\u002Fguide\u002Ffetching":3},{"page":4,"section":16,"document":17,"credits":10,"prev":855,"next":859},{"id":5,"path":6,"file":7,"title":8,"sourceTitle":8,"description":9,"tagline":9,"eyebrow":10,"credits":10,"keywords":11,"icon":12,"layout":13,"sidebar":14,"toc":14,"kind":10,"group":10,"navigation":14,"order":15},"fetching","\u002Fguide\u002Ffetching","guide\u002Ffetching.md","Fetching","Fetch git repositories through a cache that works offline, download npm packages with checked integrity and size limits, and hold the sync lock.",null,[],"i-lucide-download-cloud","article",true,4,"guide",{"nodes":18,"toc":842},[19,28,148,156,181,188,246,253,256,263,320,333,339,346,361,367,373,435,444,450,456,513,547,577,587,593,596,658,664,682,691,697,704,771,785,802,823,829],[20,21,22,23,27],"p",{},"The sync engine fetches its sources with the helpers in ",[24,25,26],"code",{},"skillrc\u002Fio",". You can call them on their own: a git cache that keeps working offline, an npm download that checks what it gets, and the lock that keeps two syncs apart.",[29,30,33],"pre",{"language":31,"class":32,"wrap":14},"ts","shiki shiki-themes github-light-default github-dark-default dark:github-dark-default",[24,34,36,59,60,59,74,59,76,59,142],{"class":35},"language-ts",[37,38,41,45,49,52,56],"span",{"class":39,"style":40},"line","display: inline",[37,42,44],{"style":43},"color:#CF222E;--shiki-dark:#FF7B72","import",[37,46,48],{"style":47},"color:#1F2328;--shiki-dark:#E6EDF3"," { fetchClone, gitUrl } ",[37,50,51],{"style":43},"from",[37,53,55],{"style":54},"color:#0A3069;--shiki-dark:#A5D6FF"," \"skillrc\u002Fio\"",[37,57,58],{"style":47},";","\n",[37,61,62,64,67,69,72],{"class":39,"style":40},[37,63,44],{"style":43},[37,65,66],{"style":47}," { placePaths } ",[37,68,51],{"style":43},[37,70,71],{"style":54}," \"fleethosts\u002Fplaces\"",[37,73,58],{"style":47},[37,75],{"class":39,"style":40},[37,77,78,81,85,88,91,95,98,101,104,107,110,113,116,119,122,124,127,130,133,136,139],{"class":39,"style":40},[37,79,80],{"style":43},"const",[37,82,84],{"style":83},"color:#0550AE;--shiki-dark:#79C0FF"," clone",[37,86,87],{"style":43}," =",[37,89,90],{"style":43}," await",[37,92,94],{"style":93},"color:#8250DF;--shiki-dark:#D2A8FF"," fetchClone",[37,96,97],{"style":47},"(places, ",[37,99,100],{"style":93},"gitUrl",[37,102,103],{"style":47},"(",[37,105,106],{"style":54},"\"acme\u002Fskills\"",[37,108,109],{"style":47},"), ",[37,111,112],{"style":54},"\"main\"",[37,114,115],{"style":47},", ",[37,117,118],{"style":54},"`${",[37,120,121],{"style":93},"placePaths",[37,123,103],{"style":54},[37,125,126],{"style":47},"places",[37,128,129],{"style":54},").",[37,131,132],{"style":93},"cache",[37,134,135],{"style":54},"()",[37,137,138],{"style":54},"}\u002Fgit`",[37,140,141],{"style":47},");",[37,143,144],{"class":39,"style":40},[37,145,147],{"style":146},"color:#6E7781;--shiki-dark:#8B949E","\u002F\u002F { dir: \"...\u002Fcache\u002Fgit\u002F3f9c...\", commit: \"9e1d...\", collisions: [], refused: [], submodules: [] }",[149,150,155],"h2",{"id":151,"anchor":152},"the-git-cache",{"label":153,"icon":154},"Section titled \"The git cache\"","#","The git cache",[20,157,158,161,162,165,166,169,170,172,173,176,177,180],{},[24,159,160],{},"fetchClone(places, url, ref, root, options?)"," returns the files of ",[24,163,164],{},"url"," at ",[24,167,168],{},"ref",", or at the default branch when ",[24,171,168],{}," is ",[24,174,175],{},"undefined",". It keeps them under ",[24,178,179],{},"root"," between runs, so a timer run stays cheap and an offline run still has them.",[20,182,183,184,187],{},"For each repository and ref, the cache keeps three entries, named by ",[24,185,186],{},"cloneKey(url, ref)",":",[189,190,191,204],"table",{},[192,193,194],"thead",{},[195,196,197,201],"tr",{},[198,199,200],"th",{},"Entry",[198,202,203],{},"What it holds",[205,206,207,222,236],"tbody",{},[195,208,209,215],{},[210,211,212],"td",{},[24,213,214],{},"\u003Ckey>.git",[210,216,217,218,221],{},"A bare repository. Fetches land under ",[24,219,220],{},"refs\u002F\u003Cprogram>\u002F",".",[195,223,224,229],{},[210,225,226],{},[24,227,228],{},"\u003Ckey>",[210,230,231,232,235],{},"The files of the current commit, with no ",[24,233,234],{},".git"," folder",[195,237,238,243],{},[210,239,240],{},[24,241,242],{},"\u003Ckey>.json",[210,244,245],{},"The commit, and the paths left out of the checkout",[20,247,248,249,252],{},"A fetch is shallow: ",[24,250,251],{},"git fetch --depth 1 --no-tags"," of the one ref. When the commit is new, its files are written to a fresh folder and renamed into place, so a killed fetch leaves the old tree or the new one, never half of one. The next call finishes what a killed one left.",[20,254,255],{},"A ref that is a commit id, 7 to 40 hex digits, is fetched once. A later call with a cached commit that starts with it doesn't fetch again. A short id the shallow fetch can't find falls back to fetching every branch and tag.",[257,258,262],"h3",{"id":259,"anchor":260},"offline-and-read-only",{"label":261,"icon":154},"Section titled \"Offline and read-only\"","Offline and read-only",[189,264,265,275],{},[192,266,267],{},[195,268,269,272],{},[198,270,271],{},"Option",[198,273,274],{},"What it does",[205,276,277,287,297,310],{},[195,278,279,284],{},[210,280,281],{},[24,282,283],{},"offline",[210,285,286],{},"Fetches nothing and returns the cached commit",[195,288,289,294],{},[210,290,291],{},[24,292,293],{},"readOnly",[210,295,296],{},"Runs no git at all. A dry run uses it.",[195,298,299,304],{},[210,300,301],{},[24,302,303],{},"check(url, cwd)",[210,305,306,307,309],{},"Returns why ",[24,308,164],{}," may not be fetched, asked right before each fetch. With it, git follows no redirects.",[195,311,312,317],{},[210,313,314],{},[24,315,316],{},"signal",[210,318,319],{},"Stops the fetch",[20,321,322,323,325,326,328,329,332],{},"Both ",[24,324,283],{}," and ",[24,327,293],{}," throw a ",[24,330,331],{},"UserError"," when the repository was never fetched.",[257,334,338],{"id":335,"anchor":336},"paths-left-out",{"label":337,"icon":154},"Section titled \"Paths left out\"","Paths left out",[20,340,341,342,345],{},"macOS and Windows store names that differ only in case or Unicode form in one folder. Two such paths in a repository would overwrite each other, so the cache keeps the first, byte by byte, and lists the rest under ",[24,343,344],{},"collisions"," on every system. Every machine then gets the same skills.",[20,347,348,349,352,353,356,357,360],{},"Paths Windows can't write, such as ",[24,350,351],{},"aux.txt"," or a name ending in a dot, are left out on Windows only and listed under ",[24,354,355],{},"refused",". Git submodules are listed under ",[24,358,359],{},"submodules","; their folders stay empty.",[20,362,363,364,221],{},"To read another commit already in the bare repository without publishing it, use ",[24,365,366],{},"withGitTree(repo, commit, read)",[257,368,372],{"id":369,"anchor":370},"repository-names",{"label":371,"icon":154},"Section titled \"Repository names\"","Repository names",[29,374,375],{"language":31,"class":32,"wrap":14},[24,376,377,59,390,59,392,59,406,59,420],{"class":35},[37,378,379,381,384,386,388],{"class":39,"style":40},[37,380,44],{"style":43},[37,382,383],{"style":47}," { gitUrl, repoKey } ",[37,385,51],{"style":43},[37,387,55],{"style":54},[37,389,58],{"style":47},[37,391],{"class":39,"style":40},[37,393,394,396,398,400,403],{"class":39,"style":40},[37,395,100],{"style":93},[37,397,103],{"style":47},[37,399,106],{"style":54},[37,401,402],{"style":47},"); ",[37,404,405],{"style":146},"\u002F\u002F \"https:\u002F\u002Fgithub.com\u002Facme\u002Fskills.git\"",[37,407,408,410,412,415,417],{"class":39,"style":40},[37,409,100],{"style":93},[37,411,103],{"style":47},[37,413,414],{"style":54},"\"gitlab:acme\u002Fskills\"",[37,416,402],{"style":47},[37,418,419],{"style":146},"\u002F\u002F \"https:\u002F\u002Fgitlab.com\u002Facme\u002Fskills.git\"",[37,421,422,425,427,430,432],{"class":39,"style":40},[37,423,424],{"style":93},"repoKey",[37,426,103],{"style":47},[37,428,429],{"style":54},"\"git@github.com:Acme\u002Fskills.git\"",[37,431,402],{"style":47},[37,433,434],{"style":146},"\u002F\u002F \"github.com\u002Facme\u002Fskills\"",[20,436,437,439,440,443],{},[24,438,424],{}," reduces a URL to host and path, so its https, ssh and ",[24,441,442],{},"owner\u002Frepo"," forms compare equal.",[149,445,449],{"id":446,"anchor":447},"npm-packages",{"label":448,"icon":154},"Section titled \"npm packages\"","npm packages",[20,451,452,455],{},[24,453,454],{},"fetchNpm(places, spec, registry, cacheRoot, options?)"," downloads a package and returns the folder it unpacked to. It never runs npm or an install script.",[29,457,458],{"language":31,"class":32,"wrap":14},[24,459,460,59,473,59,475],{"class":35},[37,461,462,464,467,469,471],{"class":39,"style":40},[37,463,44],{"style":43},[37,465,466],{"style":47}," { fetchNpm } ",[37,468,51],{"style":43},[37,470,55],{"style":54},[37,472,58],{"style":47},[37,474],{"class":39,"style":40},[37,476,477,479,482,485,487,490,493,496,498,501,503,506,508,510],{"class":39,"style":40},[37,478,80],{"style":43},[37,480,481],{"style":47}," { ",[37,483,484],{"style":83},"dir",[37,486,115],{"style":47},[37,488,489],{"style":83},"version",[37,491,492],{"style":47}," } ",[37,494,495],{"style":43},"=",[37,497,90],{"style":43},[37,499,500],{"style":93}," fetchNpm",[37,502,97],{"style":47},[37,504,505],{"style":54},"\"@acme\u002Fskills@2.1.0\"",[37,507,115],{"style":47},[37,509,175],{"style":83},[37,511,512],{"style":47},", cacheRoot);",[20,514,515,516,115,519,522,523,526,527,530,531,534,535,538,539,542,543,546],{},"The spec is ",[24,517,518],{},"name",[24,520,521],{},"name@version"," or ",[24,524,525],{},"name@tag",", with ",[24,528,529],{},"latest"," as the default. A range such as ",[24,532,533],{},"^2"," is not resolved. The folder is ",[24,536,537],{},"\u003CcacheRoot>\u002F\u003Cregistry hash>\u002F\u003Cname>@\u003Cversion>",", with a scoped name's ",[24,540,541],{},"\u002F"," written as ",[24,544,545],{},"+",". A spec with an exact version whose folder exists returns without a request.",[20,548,549,550,553,554,557,558,557,561,564,565,568,569,572,573,576],{},"The registry is the ",[24,551,552],{},"registry"," argument, then ",[24,555,556],{},"npm_config_registry",", then ",[24,559,560],{},"NPM_CONFIG_REGISTRY",[24,562,563],{},"https:\u002F\u002Fregistry.npmjs.org",". skillrc reads no ",[24,566,567],{},".npmrc",". ",[24,570,571],{},"NPM_TOKEN"," goes to the registry as a bearer token, and to the tarball only on the registry's own origin. Pass ",[24,574,575],{},"sendToken: false"," for a registry the user didn't name.",[20,578,579,580,522,583,586],{},"Each tarball is checked against the registry's ",[24,581,582],{},"integrity",[24,584,585],{},"shasum",", and refused without one. Links in the archive and paths that leave it are refused before their bodies are read.",[257,588,592],{"id":589,"anchor":590},"limits",{"label":591,"icon":154},"Section titled \"Limits\"","Limits",[20,594,595],{},"A server that stops answering would hold the sync and its lock forever, so every download has limits:",[189,597,598,608],{},[192,599,600],{},[195,601,602,605],{},[198,603,604],{},"Limit",[198,606,607],{},"Value",[205,609,610,618,626,634,642,650],{},[195,611,612,615],{},[210,613,614],{},"Wait for an answer, or for the next bytes",[210,616,617],{},"30 s",[195,619,620,623],{},[210,621,622],{},"One download",[210,624,625],{},"5 minutes",[195,627,628,631],{},[210,629,630],{},"All downloads of one source",[210,632,633],{},"15 minutes",[195,635,636,639],{},[210,637,638],{},"Downloads of one source at once",[210,640,641],{},"8",[195,643,644,647],{},[210,645,646],{},"A tarball, packed or unpacked",[210,648,649],{},"100 MB",[195,651,652,655],{},[210,653,654],{},"Entries in an archive",[210,656,657],{},"50,000",[20,659,660,663],{},[24,661,662],{},"\u003CPROGRAM>_FETCH_WAIT_MS"," shortens the 30-second wait, for tests.",[20,665,666,669,670,673,674,568,676,669,679,681],{},[24,667,668],{},"createCappedFetch(places, refused, budget?)"," returns a ",[24,671,672],{},"fetch"," with these limits, for code that downloads on its own. Failed downloads go into ",[24,675,355],{},[24,677,678],{},"guardedFetch(problem)",[24,680,672],{}," that checks every URL it would request, redirects included, and never requests one with a problem.",[20,683,684,325,687,690],{},[24,685,686],{},"tarFileSizes",[24,688,689],{},"zipEntries"," list an archive's files and sizes without reading their bodies.",[149,692,696],{"id":693,"anchor":694},"the-sync-lock",{"label":695,"icon":154},"Section titled \"The sync lock\"","The sync lock",[20,698,699,700,703],{},"One sync at a time may write a state folder. The lock is a file, ",[24,701,702],{},"\u003Cstate>\u002Fsync.lock",", that holds who took it: pid, command, start time, host, boot and pid namespace.",[29,705,706],{"language":31,"class":32,"wrap":14},[24,707,708,59,721,59,733,59,735],{"class":35},[37,709,710,712,715,717,719],{"class":39,"style":40},[37,711,44],{"style":43},[37,713,714],{"style":47}," { lockText, takeLock } ",[37,716,51],{"style":43},[37,718,55],{"style":54},[37,720,58],{"style":47},[37,722,723,725,727,729,731],{"class":39,"style":40},[37,724,44],{"style":43},[37,726,66],{"style":47},[37,728,51],{"style":43},[37,730,71],{"style":54},[37,732,58],{"style":47},[37,734],{"class":39,"style":40},[37,736,737,739,742,744,747,749,751,754,757,760,763,765,768],{"class":39,"style":40},[37,738,80],{"style":43},[37,740,741],{"style":83}," note",[37,743,87],{"style":43},[37,745,746],{"style":93}," takeLock",[37,748,97],{"style":47},[37,750,121],{"style":93},[37,752,753],{"style":47},"(places).",[37,755,756],{"style":93},"lock",[37,758,759],{"style":47},"(), ",[37,761,762],{"style":93},"lockText",[37,764,103],{"style":47},[37,766,767],{"style":54},"\"merge\"",[37,769,770],{"style":47},"));",[20,772,773,776,777,780,781,784],{},[24,774,775],{},"takeLock"," creates the file whole or not at all. While a live holder has it, it throws ",[24,778,779],{},"LockHeldError",", such as ",[24,782,783],{},"another mytool sync is running (pid 4182)",". A stale lock is broken, and the note says why:",[786,787,788,792,795],"ul",{},[789,790,791],"li",{},"its process is gone, or its pid now belongs to another program",[789,793,794],{},"the machine restarted since it was taken",[789,796,797,798,801],{},"it is more than two hours old (",[24,799,800],{},"LOCK_MAX_AGE_MS",")",[20,803,804,805,808,809,811,812,325,815,822],{},"A lock taken on another machine or in another container that shares the folder is held until it is two hours old, since its pid means nothing here. ",[24,806,807],{},"syncRunning(places)"," says whether a live holder has the lock now. Most programs never call ",[24,810,775],{},": ",[24,813,814],{},"sync",[816,817,819],"a",{"href":818},"\u002Fguide\u002Fsync#state",[24,820,821],{},"withSyncLock"," take it for you.",[149,824,828],{"id":825,"anchor":826},"hashes-and-trees",{"label":827,"icon":154},"Section titled \"Hashes and trees\"","Hashes and trees",[20,830,831,834,835,837,838,841],{},[24,832,833],{},"hashDir(places, dir)"," returns the sha256 of every file under a folder, by ",[24,836,541],{},"-separated path. A link hashes its target text. ",[24,839,840],{},"changedFiles(before, after)"," lists the paths whose hash differs. That is how a sync tells an upstream change from a local edit.",[843,850,853,854],{"id":151,"depth":844,"text":155,"children":845},2,[846,848,849],{"id":259,"depth":847,"text":262},3,{"id":335,"depth":847,"text":338},{"id":369,"depth":847,"text":372},{"id":446,"depth":844,"text":449,"children":851},[852],{"id":589,"depth":847,"text":592},{"id":693,"depth":844,"text":696},{"id":825,"depth":844,"text":828},{"path":856,"title":857,"description":858},"\u002Fguide\u002Fconfig-files","Config files","Edit JSON, JSONC and TOML files that agents and people also write, one key at a time, and keep every other byte.",{"path":860,"title":861,"description":862},"\u002Fguide\u002Fdefinitions","Definitions","Write MCP servers once and get each agent's own config entry, and check hook files against the format each agent reads.",1796390515979,"74c0e290-bf28-4a8a-b311-db0be1c3af18"]