getStagedKbcPatchInfo method

Future<KbcStagedPatchInfo?> getStagedKbcPatchInfo()

Describes the patch currently staged at the canonical persistence path — what tryApplyStagedKbcPatch would re-apply on the next cold boot. Returns null when no patch is staged. Does NOT touch the loader; safe to call from a dashboard / debug screen at any time. Reads metadata only — the KBC payload is not parsed.

Useful for "active version" displays, support flows ("paste the label of the patch you're running"), and the eventual server-side "what patches do my devices report?" rollup.

Implementation

Future<KbcStagedPatchInfo?> getStagedKbcPatchInfo() async {
  final docsDir = await getApplicationDocumentsDirectory();
  final patchPath =
      '${docsDir.path}/sankofa-deploy/patches/active/patch.skdp';
  final f = File(patchPath);
  if (!f.existsSync()) return null;
  try {
    final bytes = await f.readAsBytes();
    final parsed = parseKbcEnvelope(bytes);
    final stat = await f.stat();
    return KbcStagedPatchInfo(
      path: patchPath,
      sizeBytes: bytes.length,
      modifiedAt: stat.modified,
      label: parsed.metadata['label']?.toString(),
      engineCommit: parsed.metadata['engineCommit']?.toString(),
      dartVersion: parsed.metadata['dartVersion']?.toString(),
      targetBinaryVersion:
          parsed.metadata['targetBinaryVersion']?.toString(),
      signed: parsed.sigAlg == KbcSigAlg.ed25519,
    );
  } catch (_) {
    return KbcStagedPatchInfo(
      path: patchPath,
      sizeBytes: f.lengthSync(),
      modifiedAt: f.statSync().modified,
      label: null,
      engineCommit: null,
      dartVersion: null,
      targetBinaryVersion: null,
      signed: false,
      parseError: true,
    );
  }
}