File size: 4,178 Bytes
3436bdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
PROVIDER_SCRIPT="$ROOT/scripts/continuity_provider.sh"
VERSION_ID="${1:-hv-continuity-control-plane-v1}"
OPERATOR_CONFIG_PATH="$ROOT/build/system/continuity_operator.json"

if [ ! -x "$PROVIDER_SCRIPT" ]; then
  echo "continuity provider script not available: $PROVIDER_SCRIPT" >&2
  exit 1
fi

STATUS_JSON="$("$PROVIDER_SCRIPT" status)"
SURFACES_JSON="$("$PROVIDER_SCRIPT" surfaces)"
LINEAGE_JSON="$("$PROVIDER_SCRIPT" lineage "$VERSION_ID")"
if [ -f "$OPERATOR_CONFIG_PATH" ]; then
  OPERATOR_JSON="$(cat "$OPERATOR_CONFIG_PATH")"
else
  OPERATOR_JSON='{"active_cut":{"max_nodes":18,"preferred_surface_order":["provider_status","provider_lineage","provider_surfaces","local_fallback_pointer"]},"resume_defaults":{"preferred_active_surface":"history_navigation_surface_v1","next_packet_shape":["route","context","action","receipt"]},"invariants":[]}'
fi

jq -n \
  --arg version_id "$VERSION_ID" \
  --argjson status "$STATUS_JSON" \
  --argjson surfaces "$SURFACES_JSON" \
  --argjson lineage "$LINEAGE_JSON" \
  --argjson operator "$OPERATOR_JSON" \
  '{
    route:{
      lane:"memory",
      objective:"resume and operate continuity runtime through the smallest owned surfaces first",
      provider:($status.provider // "unknown"),
      continuity_version_id:($lineage.version_id // $status.items[0].version_id // $status.continuity_version_id // $version_id),
      active_cut:{
        max_nodes:($operator.active_cut.max_nodes // 18),
        preferred_surface_order:($operator.active_cut.preferred_surface_order // []),
        surfaces_used:[
          "provider_status",
          "provider_lineage",
          "provider_surfaces"
        ]
      }
    },
    context:{
      verified:($lineage.verified // $status.items[0].verified // false),
      promoted:($lineage.promoted // $status.items[0].promoted // false),
      predecessor:($lineage.predecessor // $status.items[0].predecessor // $status.predecessor_id // null),
      surfaces:($surfaces.items // []),
      graph_id:($lineage.graph_id // $status.items[0].graph_id // null),
      active_surface:(
        ($surfaces.items // [])
        | map(select(.activated == true))[0].surface_id
        // (($surfaces.items // [])
          | map(select(.surface_id == ($operator.resume_defaults.preferred_active_surface // "")))[0].surface_id)
        // (($surfaces.items // [])[0].surface_id)
        // null
      ),
      resume_rule:"resume from state, not raw history replay"
    },
    action:{
      next_step:"resume or activate one continuity surface",
      recommended_surface:(
        ($surfaces.items // [])
        | map(select(.activated == true))[0].surface_id
        // (($surfaces.items // [])
          | map(select(.surface_id == ($operator.resume_defaults.preferred_active_surface // "")))[0].surface_id)
        // (($surfaces.items // [])[0].surface_id)
        // null
      ),
      activate_command:(
        (($surfaces.items // [])
        | map(select(.activated == true))[0].surface_id
        // (($surfaces.items // [])[0].surface_id)
        // empty) as $surface
        | if $surface == "" then null
          else "./bin/bvtctl continuity-activate " + $surface + " " + ($lineage.version_id // $status.items[0].version_id // $status.continuity_version_id // $version_id)
          end
      ),
      resume_packet:{
        command:("./bin/bvtctl continuity-resume " + ($lineage.version_id // $status.items[0].version_id // $status.continuity_version_id // $version_id)),
        shape:($operator.resume_defaults.next_packet_shape // ["route","context","action","receipt"])
      }
    },
    receipt:{
      proof_surface:"continuity provider",
      lineage_verified:($lineage.verified // false),
      promotion_state:(
        if ($lineage.promoted // false) then "promoted"
        elif ($lineage.verified // false) then "verified"
        else "unverified"
        end
      ),
      evidence:[
        ($lineage.provider // $status.provider // "unknown"),
        ($lineage.graph_id // $status.items[0].graph_id // null),
        (($surfaces.items // []) | length)
      ]
    }
  }'