Calculation methods for selected-source reviews

This is the local Architecture reference used by the Governance Report intake. These are complete copyable calculation functions, not an installed service, native Agent tool or background detector. An authorized administrator must choose and verify an approved calculation environment separately. Do not run a method or record its output without actual approved source reads and complete input validation. No customer source grants or operational authority are included. Historical seller test fixtures and private QA links are excluded; no new runtime or full regression qualification is claimed.

Corporate Structure Graph — auditGraph

Select one relationship type, one ISO calendar date and a share class for SHAREHOLDING. Query the complete intended selection of original Ownership & Structure rows, exact UUIDs, endpoint relations, source/version and date fields. Stop on truncation, has_more, missing inputs or failed access. Filter the selected source set to one approved Synthetic/operational mode before calculation; this function does not enforce that mode itself. Preserve frozen query scope and input rows. Date ranges and timestamp inputs are rejected; End is inclusive for this comparison, not legal interpretation. Scope is caller-selected, never enterprise completeness.

function auditGraph(rows, asOf, type, shareClass) {
  const uuid = x => { const m = String(x || "").match(/([0-9a-f]{32}|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:[?/#]|$)/i); return m ? m[1].replace(/-/g,"").toLowerCase() : null; };
  const list = x => { try { const v = Array.isArray(x) ? x : JSON.parse(x || "[]"); return Array.isArray(v) ? v : []; } catch { return []; } };
  const day = x => typeof x === "string" && /^\d{4}-\d{2}-\d{2}$/.test(x) && !Number.isNaN(Date.parse(x)) && new Date(x).toISOString().slice(0,10) === x;
  if (!day(asOf) || !["LEGAL PARENT","SHAREHOLDING"].includes(type) || (type === "SHAREHOLDING" && !shareClass)) return {status:"INPUT GAPS",reason:"Invalid scope",edges:[],gaps:["scope"],components:[],cyclicNodes:0,overlaps:[]};
  const edges=[], gaps=[];
  for (const r of rows) {
    if (!r["Relationship Type"]) { gaps.push(r.url+": type"); continue; }
    if (r["Relationship Type"] !== type) continue;
    if (type === "SHAREHOLDING" && !r["Share Class"]) {gaps.push(r.url+": class");continue;}
    if (type === "SHAREHOLDING" && r["Share Class"] !== shareClass) continue;
    const start=r["date:Effective:start"], end=r["date:End:start"];
    if (!day(start) || (end && !day(end)) || (end && end<start) || r["date:Effective:end"] || r["date:End:end"] || r["date:Effective:is_datetime"] === 1 || r["date:End:is_datetime"] === 1) {gaps.push(r.url+": period");continue;}
    if (start>asOf || (end && end<asOf)) continue;
    const a=list(r.Entity), b=list(r["Parent Entity"]), child=uuid(a[0]), parent=uuid(b[0]);
    if(a.length!==1 || b.length!==1 || !child || !parent){gaps.push(r.url+": endpoints");continue;}
    if(r.Verification!=="VERIFIED" || !r["Structure Source"] || !r["Source of Truth"] || list(r.Evidence).length===0 || list(r.Owner).length===0) gaps.push(r.url+": source review");
    edges.push({id:uuid(r.url),url:r.url,child,parent,type,shareClass:type==="SHAREHOLDING"?shareClass:"",start,end:end||null});
  }
  const nodes=[...new Set(edges.flatMap(e=>[e.child,e.parent]))].sort(), adj=new Map(nodes.map(n=>[n,[]]));
  edges.forEach(e=>adj.get(e.child).push(e.parent));
  let index=0;const ix=new Map(),low=new Map(),stack=[],on=new Set(),components=[];
  function visit(v){ix.set(v,index);low.set(v,index++);stack.push(v);on.add(v);for(const w of adj.get(v)){if(!ix.has(w)){visit(w);low.set(v,Math.min(low.get(v),low.get(w)));}else if(on.has(w))low.set(v,Math.min(low.get(v),ix.get(w)));}if(low.get(v)===ix.get(v)){let c=[],w;do{w=stack.pop();on.delete(w);c.push(w);}while(w!==v);if(c.length>1||adj.get(v).includes(v))components.push(c.sort());}}
  nodes.forEach(v=>{if(!ix.has(v))visit(v);});
  const overlaps=[];for(let i=0;i<edges.length;i++)for(let j=i+1;j<edges.length;j++){const a=edges[i],b=edges[j];if(a.child===b.child&&a.parent===b.parent&&a.type===b.type&&a.shareClass===b.shareClass)overlaps.push([a.id,b.id].sort());}
  return {status:gaps.length?"INPUT GAPS":!edges.length?"EMPTY SCOPE":components.length||overlaps.length?"ISSUES FOUND":"SCOPED NO CYCLE",edges,gaps,components:components.sort((a,b)=>a[0].localeCompare(b[0])),cyclicNodes:components.reduce((n,c)=>n+c.length,0),overlaps};
}

Save original edge relations, Graph As Of, Graph Type/Class, exact captured native Graph Current Scope, actual run timestamp, input rows, calculated results and gap evidence in the Reports record. Do not guess UUID order. Scope change or later selected-source edit invalidates the snapshot; new/unselected records require fresh discovery. Keep Status DRAFT pending real human review. SCOPED NO CYCLE is only a result for this selection and cannot establish complete ownership, source authenticity or legal control. A source-review gap does not become valid merely because an edge was traversed.

Authority Conflict Radar — CG-AC-SNAPSHOT-1.1

Select exact native Authority Inputs, an explicit date-only as-of and one approved synthetic mode. Query complete selected records with actual relation/user IDs, source/version and date precision/ranges. This method validates adapter input shape and limits selection to100records. It does not authenticate identities, evidence or legal authority. Compare exact IDs, not names. Do not silently convert currencies, choose versions, revoke instruments or clear conflicts.

function authoritySnapshotV11(rows, asOf, syntheticMode) {
  if (!Array.isArray(rows)) throw Error("INPUT_ROWS_ARRAY_REQUIRED");
  if (rows.length > 100) throw Error("INPUT_LIMIT_100");
  if (typeof syntheticMode !== "boolean") throw Error("SYNTHETIC_MODE_REQUIRED");
  const id = value => {
    if (typeof value !== "string") return null;
    return value.replace(/-/g,"").match(/([0-9a-f]{32})(?:\?[^]*)?$/i)?.[1]?.toLowerCase() || null;
  };
  for (const row of rows) {
    if (!row || typeof row !== "object" || Array.isArray(row) || !id(row.url)) throw Error("INPUT_RECORD_ID_INVALID");
    for (const field of ["Entity","Grantee"]) {
      let values = row[field];
      if (values === null || values === undefined || values === "") values = [];
      else if (typeof values === "string") {
        try { values = JSON.parse(values); } catch { throw Error("INPUT_LIST_INVALID:" + field); }
      }
      if (!Array.isArray(values) || values.some(v => !id(v))) throw Error("INPUT_LIST_INVALID:" + field);
      if (new Set(values.map(id)).size !== values.length) throw Error("INPUT_LIST_DUPLICATE:" + field);
    }
    if (![null,undefined,"__YES__","__NO__"].includes(row.Synthetic)) throw Error("SYNTHETIC_FLAG_INVALID");
  }
  const core = function authoritySnapshot(rows, asOf, syntheticMode) {
  const validDay=s=> typeof s==="string" && /^\d{4}-\d{2}-\d{2}$/.test(s) && !isNaN(Date.parse(s)) && new Date(s).toISOString().slice(0,10)===s;
  if(!validDay(asOf)) throw Error("AS_OF_DATE_ONLY_REQUIRED");
  const list=x=>Array.isArray(x)?x:JSON.parse(x||"[]");
  const key=x=>String(x).replace(/-/g,"").match(/[0-9a-f]{32}/i)?.[0]?.toLowerCase()||String(x);
  const text=(r,k)=>String(r[k]??"").trim();
  const yes=(r,k)=>r[k]==="__YES__";
  if(rows.some(r=>yes(r,"Synthetic")!==syntheticMode)) throw Error("MIXED_SYNTHETIC_SCOPE");
  const ids=rows.map(r=>key(r.url));
  if(new Set(ids).size!==ids.length) throw Error("DUPLICATE_INPUT_ID");
  const ordered=[...rows].sort((a,b)=>key(a.url).localeCompare(key(b.url)));
  const terms=r=>JSON.stringify(["Authority Type","Limit Basis","Limit Confirmed","Limit","Currency","Reserved Matter","date:Effective:start","date:Expiry:start"].map(k=>r[k]??null));
  function pair(a,b){
    for(const field of ["Entity","Grantee"]) {
      const x=list(a[field]).map(key),y=list(b[field]).map(key);
      if(x.length!==1||y.length!==1) return "UNKNOWN_"+field.toUpperCase();
      if(x[0]!==y[0]) return "OUTSIDE_EXACT_"+field.toUpperCase();
    }
    for(const field of ["Action Class","Jurisdiction Scope"]){
      if(!text(a,field)||!text(b,field)) return "UNKNOWN_SCOPE_MISSING";
      if(text(a,field)!==text(b,field)) return "UNKNOWN_SCOPE_NONIDENTICAL";
    }
    for(const r of [a,b]) {
      for(const name of ["Effective","Expiry"]) {
        const s=r[`date:${name}:start`],end=r[`date:${name}:end`];
        if(!validDay(s)||r[`date:${name}:is_datetime`]===1||(end&&end!==s)) return "UNKNOWN_DATE";
      }
      if(r["date:Effective:start"]>r["date:Expiry:start"]) return "UNKNOWN_DATE_INVERTED";
    }
    if([a,b].some(r=>yes(r,"Revoked"))) return "INACTIVE_REVOKED";
    if([a,b].some(r=>r["date:Effective:start"]>asOf)) return "INACTIVE_FUTURE";
    if([a,b].some(r=>r["date:Expiry:start"]<asOf)) return "INACTIVE_EXPIRED";
    if([a,b].some(r=>!text(r,"Source Document")||!text(r,"Version"))) return "UNKNOWN_SOURCE_VERSION";
    if(text(a,"Source Document")===text(b,"Source Document")) {
      if(text(a,"Version")!==text(b,"Version")) return "VERSION_REVIEW";
      return terms(a)===terms(b)?"DUPLICATE_REVIEW":"DUPLICATE_CONTRADICTION_REVIEW";
    }
    if([a,b].some(r=>yes(r,"Reserved Matter")||r["Authority Type"]==="RESERVED MATTER")) return "RESERVED_REVIEW";
    if(!text(a,"Authority Type")||!text(b,"Authority Type")) return "UNKNOWN_TYPE";
    if(a["Authority Type"]!==b["Authority Type"]) return "AUTHORITY_TYPE_REVIEW";
    if(!["FIXED LIMIT","NON-MONETARY"].includes(a["Limit Basis"])||!["FIXED LIMIT","NON-MONETARY"].includes(b["Limit Basis"])) return "UNKNOWN_LIMIT_BASIS";
    if(a["Limit Basis"]!==b["Limit Basis"]) return "LIMIT_BASIS_REVIEW";
    if(a["Limit Basis"]==="FIXED LIMIT") {
      if([a,b].some(r=>!yes(r,"Limit Confirmed")||typeof r.Limit!=="number"||!Number.isFinite(r.Limit)||r.Limit<0||!text(r,"Currency"))) return "UNKNOWN_LIMIT_CURRENCY";
      if(text(a,"Currency")!==text(b,"Currency")) return "CURRENCY_REVIEW";
      if(a.Limit!==b.Limit) return "LIMIT_REVIEW";
    }
    return "OVERLAP_REVIEW";
  }
  const pairs=[];
  for(let i=0;i<ordered.length;i++)for(let j=i+1;j<ordered.length;j++)pairs.push({a:ordered[i].url,b:ordered[j].url,reason:pair(ordered[i],ordered[j])});
  const unknown=pairs.filter(p=>p.reason.startsWith("UNKNOWN_")).length;
  const review=pairs.filter(p=>p.reason.endsWith("_REVIEW")).length;
  return {method:"CG-AC-SNAPSHOT-1.0",asOf,synthetic:syntheticMode,inputIds:ids.sort(),pairs,pairCount:pairs.length,reviewPairs:review,unknownPairs:unknown,status:rows.length===0?"EMPTY SCOPE":rows.length<2?"INPUT GAPS":review?"REVIEW REQUIRED":unknown?"INPUT GAPS":"SCOPED NO FLAG"};
};
  const result = core(rows, asOf, syntheticMode);
  result.method = "CG-AC-SNAPSHOT-1.1";
  return result;
}

Retain the frozen queried inputs, pair reasons, input denominator and computed output in the report. Read the original instrument for every flag. Identical source/version means duplicate review; different versions require review without automatically preferring either. Nonidentical action/jurisdiction text remains UNKNOWN. Inclusive dates are this day-based method's policy, not a legal expiry ruling. Zero/one input and SCOPED NO FLAG never establish healthy governance.

Capture exact native Authority Current Scope, greatest queried Authority Source Updated epoch milliseconds and actual Run At. Preserve method1.1. Scope or freshness warnings require re-query and regeneration, never guard-resetting alone. A maximum timestamp cannot detect every same-timestamp, backdated, deletion, body-only or concurrent change. New/unselected records, co-signature/quorum, source authenticity and actual owner authority remain separate human checks.

Health and subsidiary oversight

Use the complete selected-source instructions in the local Governance Report intake. Map one exact Entity, one date-only Health As Of, source scope, method, reviewer and evidence. Preserve all six-domain findings, gaps and contradictions. Copy exact native Health Current Inputs into Health Captured Inputs only after actual query/review; record actual Health Run At. Native tokens are coarse and calendar/timezone-sensitive; they are not immutable source contents or completeness proof. No automated health, maturity, assurance or compliance score is supplied. Read current source-review warnings and Snapshot Guard; do not capture values merely to clear a warning.

Human decision boundary

This manual does not grant authority, complete a filing, approve a resolution, validate a delegation, interpret law, certify compliance or make a source complete. The original statutory registry, signed instrument and authorized governance/legal owner remain authoritative. Retained DEV, permission, runtime and full release gates remain applicable.