Home /Modules/vm/SLVMComponentFetcher.sleela

SLVMComponentFetcher.sleela

lib/vm/SLVMComponentFetcher.sleela · 130 line(s) · sleela

<< lib/vm/SLVMComponentFetcher.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLVMComponentFetcher — the VM series' hook into the
     resilient support-downloader module (lib/operating-system/SLSupportDownloader). The VM
     sometimes needs to obtain an OS/runtime component at run time (a kernel
     source, a package index, a backend runtime); if the primary URL 404s, the
     VM must fall through to prioritized support/mirror URLs rather than fail.
     This fetcher wires an SLVM to an SLSupportDownloader: the VM asks it to
     resolve the first reachable support URL for a component kind, or to run the
     404-tolerant fallback fetch, so VM-driven component acquisition is resilient
     the same way the OS document's build-time acquisition is.
   
   This is the VM-side hook that complements the OS-document hook (SLDownloadSet
   composes the same SLSupportDownloader). Either path obtains components with
   the authoritative -> official -> college/edu -> archive fallback order.
   
   Family: vm. Composes SLVM + SLSupportDownloader; fetch/probe cross the osRun
     bridge (requires #sleela 1.5). >>
#sleela 2.5
material;
class SLVMComponentFetcher {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 11011;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-11";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  < the VM this fetcher serves >
  SLVM vm;
  < the shared resilient downloader >
  SLSupportDownloader support;
  int configured;

  < Wire the fetcher to a VM, creating a fresh support downloader. >
  void configure(SLVM targetVm) {
    vm = targetVm;
    support = new SLSupportDownloader(); support.configure();
    configured = 1;
  }
  < Wire to a VM AND an existing (OS-document-shared) support downloader, so the >
  < VM and the OS model use one and the same fallback policy. >
  void configureShared(SLVM targetVm, SLSupportDownloader shared) {
    vm = targetVm; support = shared; configured = 1;
  }

  SLSupportDownloader supportDownloader() { return support; }
  boolean ready() { return configured == 1; }

  < Resolve the first reachable support URL for a component kind (probes the >
  < mirrors in priority order), or "" if none respond. The VM calls this before >
  < acquiring a component so it binds to a live source. >
  String resolve(String kind) {
    if (configured != 1) { return ""; }
    return support.firstReachable(kind);
  }

  < Run the 404-tolerant fallback fetch for a component kind to a destination. >
  < Returns 0 on success (some tier succeeded), non-zero when every support URL >
  < (including the archive) failed. Uses osRun to execute the generated loop. >
  int fetch(String kind, String dest) {
    if (configured != 1) { return -1; }
    if (!support.knownKind(kind)) { return -2; }
    < Try each tier in priority order; stop at the first that succeeds. >
    < Tiers are 0..3 (authoritative, official-mirror, college, archive) as >
    < defined by SLSupportDownloader; a static constant is class-scoped, so the >
    < archive ordinal (3) is used directly as the loop bound. >
    int p = 0;
    while (p <= 3) {
      String url = support.supportUrl(kind, p);
      if (support.reachable(kind, url)) {
        int rc = runFetch(kind, url, dest);
        if (rc == 0) { return 0; }
      }
      p = p + 1;
    }
    < all support URLs failed >
    return 1;
  }

  < Execute one fetch of url -> dest with the right tool for the kind. >
  int runFetch(String kind, String url, String dest) {
    if (support.isGitKind(kind)) {
      return osRun("git clone --depth 1 " + url + " " + dest + " >/dev/null 2>&1");
    }
    return osRun("curl -fsSL --retry 2 -o " + dest + " \"" + url + "\" >/dev/null 2>&1");
  }

  < A VM-facing summary: which support URL each needed kind would resolve to. >
  String resolvedPlan(String kind) {
    String url = resolve(kind);
    if (url == "") { return kind + ": no reachable support URL"; }
    return kind + " -> " + url;
  }
}