File size: 4,536 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
MANIFEST_PATH="${1:-}"
SCHEMA_PATH="$ROOT/schemas/continuity_slice_manifest_v0.json"

if [ -z "$MANIFEST_PATH" ]; then
  echo "usage: ./runtime/materialize_continuity_slice.sh <continuity_manifest.json>" >&2
  exit 1
fi

if [ ! -f "$MANIFEST_PATH" ]; then
  echo "continuity manifest not found: $MANIFEST_PATH" >&2
  exit 1
fi

if [ "$(jq -r '.version' "$MANIFEST_PATH")" != "continuity_slice_manifest_v0" ]; then
  echo "unsupported continuity manifest: $MANIFEST_PATH" >&2
  exit 1
fi

MANIFEST_ABS="$(cd "$(dirname "$MANIFEST_PATH")" && pwd)/$(basename "$MANIFEST_PATH")"
CONTINUITY_VERSION_ID="$(jq -r '.continuity_version_id' "$MANIFEST_ABS")"
PREDECESSOR_ID="$(jq -r '.predecessor_id' "$MANIFEST_ABS")"
ONE_LINER="$(jq -r '.one_liner' "$MANIFEST_ABS")"
DEFAULT_SURFACE="$(jq -r '.default_surface // (.surfaces[0].id // "")' "$MANIFEST_ABS")"
OUT_DIR="$ROOT/runs/continuity/$CONTINUITY_VERSION_ID"
WORK_MANIFEST_PATH="$OUT_DIR/work_manifest.json"
LINEAGE_REL="runs/continuity/$CONTINUITY_VERSION_ID/lineage.json"
SURFACES_REL="runs/continuity/$CONTINUITY_VERSION_ID/surface_registry.json"
POINTER_REL="runs/continuity/latest.json"
GENERATED_AT="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"

mkdir -p "$OUT_DIR"

ENDPOINTS_JSON="$(jq -c '.endpoints' "$MANIFEST_ABS")"
SURFACES_JSON="$(jq -c '.surfaces' "$MANIFEST_ABS")"
RECEIPTS_JSON="$(jq -c '.receipts_required // []' "$MANIFEST_ABS")"
EVAL_GATE_JSON="$(jq -c '.eval_gate // []' "$MANIFEST_ABS")"
SURFACE_IDS_JSON="$(jq -c '[.surfaces[].id]' "$MANIFEST_ABS")"
ENDPOINT_IDS_JSON="$(jq -c '[.endpoints[].id]' "$MANIFEST_ABS")"

LINEAGE_CONTENT="$(jq -n \
  --arg version "continuity_lineage_v0" \
  --arg generated_at "$GENERATED_AT" \
  --arg continuity_version_id "$CONTINUITY_VERSION_ID" \
  --arg predecessor_id "$PREDECESSOR_ID" \
  --arg one_liner "$ONE_LINER" \
  --arg manifest_path "$MANIFEST_ABS" \
  --argjson endpoints "$ENDPOINTS_JSON" \
  --argjson receipts_required "$RECEIPTS_JSON" \
  --argjson eval_gate "$EVAL_GATE_JSON" \
  '{
    version:$version,
    generated_at:$generated_at,
    continuity_version_id:$continuity_version_id,
    predecessor_id:$predecessor_id,
    one_liner:$one_liner,
    manifest_path:$manifest_path,
    endpoints:$endpoints,
    receipts_required:$receipts_required,
    eval_gate:$eval_gate
  }' | jq '.')"

SURFACES_CONTENT="$(jq -n \
  --arg version "continuity_surface_registry_v0" \
  --arg generated_at "$GENERATED_AT" \
  --arg continuity_version_id "$CONTINUITY_VERSION_ID" \
  --arg default_surface "$DEFAULT_SURFACE" \
  --argjson surfaces "$SURFACES_JSON" \
  '{
    version:$version,
    generated_at:$generated_at,
    continuity_version_id:$continuity_version_id,
    default_surface:$default_surface,
    surfaces:$surfaces
  }' | jq '.')"

POINTER_CONTENT="$(jq -n \
  --arg version "continuity_pointer_v0" \
  --arg updated_at "$GENERATED_AT" \
  --arg continuity_version_id "$CONTINUITY_VERSION_ID" \
  --arg predecessor_id "$PREDECESSOR_ID" \
  --arg lineage_path "$LINEAGE_REL" \
  --arg surface_registry_path "$SURFACES_REL" \
  --arg one_liner "$ONE_LINER" \
  --arg default_surface "$DEFAULT_SURFACE" \
  --argjson surface_ids "$SURFACE_IDS_JSON" \
  --argjson endpoint_ids "$ENDPOINT_IDS_JSON" \
  '{
    version:$version,
    updated_at:$updated_at,
    continuity_version_id:$continuity_version_id,
    predecessor_id:$predecessor_id,
    one_liner:$one_liner,
    default_surface:$default_surface,
    lineage_path:$lineage_path,
    surface_registry_path:$surface_registry_path,
    surface_ids:$surface_ids,
    endpoint_ids:$endpoint_ids,
    status:"materialized"
  }' | jq '.')"

jq -n \
  --arg manifest_id "materialize-$CONTINUITY_VERSION_ID" \
  --arg goal "materialize continuity slice $CONTINUITY_VERSION_ID" \
  --arg lineage_path "$LINEAGE_REL" \
  --arg surfaces_path "$SURFACES_REL" \
  --arg pointer_path "$POINTER_REL" \
  --arg lineage_content "$LINEAGE_CONTENT" \
  --arg surfaces_content "$SURFACES_CONTENT" \
  --arg pointer_content "$POINTER_CONTENT" \
  '{
    version:"work_manifest_v0",
    manifest_id:$manifest_id,
    goal:$goal,
    lane:"execution",
    execution_gate:true,
    receipt_required:true,
    actions:[
      {type:"write_file", path:$lineage_path, content:$lineage_content},
      {type:"write_file", path:$surfaces_path, content:$surfaces_content},
      {type:"write_file", path:$pointer_path, content:$pointer_content}
    ]
  }' > "$WORK_MANIFEST_PATH"

printf '%s\n' "$WORK_MANIFEST_PATH"