File size: 11,952 Bytes
7311a16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import { useEffect, useMemo, useState } from "react";
import { Pause, Play, RotateCcw, SkipForward } from "lucide-react";
import {
  FLOW_ORDER,
  FRAMES,
  LEARNING_ORDER,
  PLANES,
  RUNTIME_ORDER,
  SAFETY_ORDER,
  STAGES,
  type StageId,
} from "../../data/autonomy";
import { FlowArrow, StageCard } from "./StageCard";
import { StageDetail } from "./StageDetail";

type Props = {
  openStage: StageId | null;
  onOpenStage: (id: StageId | null) => void;
};

const PHASES: { key: string; label: string; stages: StageId[] }[] = [
  { key: "sense", label: "Sense", stages: ["sensors", "fusion"] },
  { key: "understand", label: "Understand", stages: ["perception"] },
  { key: "predict", label: "Predict", stages: ["prediction"] },
  { key: "decide", label: "Decide", stages: ["behavior", "motion"] },
  { key: "act", label: "Act", stages: ["control", "actuators"] },
  { key: "verify", label: "Verify", stages: ["supervisor"] },
  { key: "learn", label: "Learn", stages: ["capture"] },
];

const TICK_MS = 1500;

const CYCLE: StageId[] = [...RUNTIME_ORDER, "world"];

export function AutonomyStack({ openStage, onOpenStage }: Props) {
  const [playing, setPlaying] = useState(true);
  const [tick, setTick] = useState(0);

  useEffect(() => {
    if (!playing) return;
    const id = window.setInterval(() => setTick((t) => t + 1), TICK_MS);
    return () => window.clearInterval(id);
  }, [playing]);

  const cycle = Math.floor(tick / CYCLE.length);
  const activeRuntime = CYCLE[tick % CYCLE.length]!;
  const frame = FRAMES[cycle % FRAMES.length]!;
  const activeLearning = LEARNING_ORDER[Math.floor(tick / 3) % LEARNING_ORDER.length]!;
  const overriding = frame.safety === "override";
  const gating = activeRuntime === "control" || activeRuntime === "actuators";

  const phase = useMemo(
    () => PHASES.find((item) => item.stages.includes(activeRuntime))?.key ?? "sense",
    [activeRuntime],
  );

  const activeIds = useMemo(() => {
    const set = new Set<StageId>([activeRuntime, activeLearning]);
    if (gating || overriding) set.add("supervisor");
    if (overriding) set.add("fallback");
    return set;
  }, [activeLearning, activeRuntime, gating, overriding]);

  const step = () => {
    setPlaying(false);
    setTick((t) => t + 1);
  };

  const detail = openStage ? STAGES[openStage] : null;
  const detailIndex = openStage ? FLOW_ORDER.indexOf(openStage) : -1;

  return (
    <section aria-label="Autonomy stack emulator" className="space-y-5">
      <div className="rounded-xl border border-white/10 bg-[#0e1624] p-4">
        <h2 className="font-mono text-[10px] tracking-[0.22em] text-cyan-200/80 uppercase">
          Closed loop
        </h2>
        <ol className="mt-3 flex flex-wrap items-center gap-x-2 gap-y-2">
          {PHASES.map((item, index) => (
            <li key={item.key} className="flex items-center gap-2">
              <span
                className={`rounded-md border px-2.5 py-1 text-xs transition-colors ${
                  phase === item.key
                    ? "border-cyan-300/70 bg-cyan-400/15 text-white"
                    : "border-white/10 text-slate-400"
                }`}
              >
                {item.label}
              </span>
              {index < PHASES.length - 1 ? (
                <span aria-hidden className="text-slate-600">
                  →
                </span>
              ) : null}
            </li>
          ))}
        </ol>
        <p className="mt-3 text-sm leading-relaxed text-slate-400">
          An autonomy stack is not a pipeline that ends. Every action changes
          the world, the sensors measure the change, and the loop runs again —
          typically ten to twenty times a second.
        </p>
      </div>

      <div className="sticky top-0 z-20 rounded-xl border border-white/10 bg-[#0b1220]/95 p-3 backdrop-blur-md sm:p-4">
        <div className="flex flex-wrap items-center justify-between gap-3">
          <div className="min-w-0">
            <p className="font-mono text-[10px] tracking-[0.22em] text-cyan-200/80 uppercase">
              Scenario · {frame.label} · cycle {cycle + 1}
            </p>
            <p className="text-sm font-medium text-white">{frame.headline}</p>
          </div>
          <div className="flex items-center gap-2">
            <span
              className={`rounded-md border px-2.5 py-1 font-mono text-[10px] tracking-wide uppercase ${
                overriding
                  ? "border-rose-400/60 bg-rose-500/15 text-rose-100"
                  : "border-emerald-400/40 bg-emerald-500/10 text-emerald-100"
              }`}
            >
              {overriding ? "Safety override" : "Nominal"}
            </span>
            <button
              type="button"
              onClick={() => setPlaying((value) => !value)}
              aria-label={playing ? "Pause emulator" : "Play emulator"}
              className="inline-flex min-h-11 items-center gap-1.5 rounded-md border border-white/15 bg-white/5 px-3 py-2 text-xs text-slate-100 hover:bg-white/10"
            >
              {playing ? <Pause className="h-3.5 w-3.5" /> : <Play className="h-3.5 w-3.5" />}
              {playing ? "Pause" : "Play"}
            </button>
            <button
              type="button"
              onClick={step}
              aria-label="Step one stage"
              className="inline-flex min-h-11 items-center gap-1.5 rounded-md border border-white/15 bg-white/5 px-3 py-2 text-xs text-slate-100 hover:bg-white/10"
            >
              <SkipForward className="h-3.5 w-3.5" />
              Step
            </button>
            <button
              type="button"
              onClick={() => {
                setTick(0);
                setPlaying(true);
              }}
              aria-label="Restart emulator"
              className="inline-flex min-h-11 items-center gap-1.5 rounded-md border border-white/15 bg-white/5 px-3 py-2 text-xs text-slate-100 hover:bg-white/10"
            >
              <RotateCcw className="h-3.5 w-3.5" />
              Restart
            </button>
          </div>
        </div>
      </div>

      <div className="grid gap-5 lg:grid-cols-[minmax(0,1.25fr)_minmax(15rem,0.85fr)]">
        <div className="min-w-0">
          <h3 className="mb-3 font-mono text-[10px] tracking-[0.22em] text-slate-500 uppercase">
            Autonomy runtime
          </h3>
          <StageCard
            stage={STAGES.mission}
            active={false}
            readout={frame.readouts.mission}
            alwaysShowReadout
            onOpen={() => onOpenStage("mission")}
          />
          <FlowArrow label="route + constraints" />
          {RUNTIME_ORDER.map((id, index) => (
            <div key={id}>
              <StageCard
                stage={STAGES[id]}
                active={activeIds.has(id)}
                alert={overriding && (id === "control" || id === "actuators")}
                readout={frame.readouts[id]}
                onOpen={() => onOpenStage(id)}
              />
              {index === RUNTIME_ORDER.length - 1 ? null : (
                <FlowArrow
                  label={
                    id === "motion" ? "proposed trajectory → safety check" : undefined
                  }
                />
              )}
            </div>
          ))}
          <FlowArrow label="force applied to the world" />
          <StageCard
            stage={STAGES.world}
            active={activeIds.has("world")}
            readout={frame.readouts.world}
            onOpen={() => onOpenStage("world")}
          />
          <p className="mt-3 rounded-lg border border-dashed border-cyan-300/30 bg-cyan-400/5 px-3 py-2.5 text-xs leading-relaxed text-cyan-100/90">
            ↺ The world feeds the sensor layer again. This edge is what turns a
            perception model into a control system.
          </p>
        </div>

        <div className="space-y-6">
          <div>
            <h3 className="mb-1 font-mono text-[10px] tracking-[0.22em] text-slate-500 uppercase">
              Safety &amp; supervision
            </h3>
            <p className="mb-3 text-xs leading-relaxed text-slate-500">
              Sits between the planner and the actuators with independent
              authority to say no.
            </p>
            <div className="space-y-2">
              {SAFETY_ORDER.map((id) => (
                <StageCard
                  key={id}
                  stage={STAGES[id]}
                  compact
                  active={activeIds.has(id)}
                  alert={overriding}
                  readout={frame.readouts[id]}
                  alwaysShowReadout={id === "health"}
                  onOpen={() => onOpenStage(id)}
                />
              ))}
            </div>
          </div>

          <div>
            <h3 className="mb-1 font-mono text-[10px] tracking-[0.22em] text-slate-500 uppercase">
              Data &amp; learning plane
            </h3>
            <p className="mb-3 text-xs leading-relaxed text-slate-500">
              Runs offline, on fleet time rather than frame time. This is the
              autonomy development stack.
            </p>
            {frame.capture ? (
              <p className="mb-3 rounded-md border border-emerald-400/40 bg-emerald-500/10 px-3 py-2 font-mono text-[11px] text-emerald-100">
                event captured · {frame.capture}
              </p>
            ) : null}
            <div className="space-y-2">
              {LEARNING_ORDER.map((id) => (
                <StageCard
                  key={id}
                  stage={STAGES[id]}
                  compact
                  active={activeIds.has(id)}
                  readout={frame.readouts[id]}
                  onOpen={() => onOpenStage(id)}
                />
              ))}
            </div>
            <p className="mt-3 rounded-lg border border-dashed border-emerald-300/30 bg-emerald-400/5 px-3 py-2.5 text-xs leading-relaxed text-emerald-100/90">
              ↺ Release feeds the runtime. The autonomy stack drives the car;
              this loop is what makes next month's car better.
            </p>
          </div>
        </div>
      </div>

      <div className="rounded-xl border border-white/10 bg-[#0e1624] p-4">
        <h3 className="font-mono text-[10px] tracking-[0.22em] text-slate-500 uppercase">
          Six interacting planes
        </h3>
        <div className="mt-3 grid gap-2 sm:grid-cols-2">
          {(Object.keys(PLANES) as (keyof typeof PLANES)[]).map((key) => (
            <div
              key={key}
              className="rounded-lg border border-white/10 px-3 py-2"
              style={{ boxShadow: `inset 3px 0 0 ${PLANES[key].accent}` }}
            >
              <p
                className="font-mono text-[10px] tracking-[0.18em] uppercase"
                style={{ color: PLANES[key].accent }}
              >
                {PLANES[key].label}
              </p>
              <p className="mt-1 text-xs leading-relaxed text-slate-400">
                {PLANES[key].blurb}
              </p>
            </div>
          ))}
        </div>
        <p className="mt-4 text-sm leading-relaxed text-slate-400">
          There is no single "AI" box. Learning shows up in perception, fusion,
          the world model, prediction, behavior, motion costs, simulation, and
          scenario mining — while safety stays deliberately deterministic around
          all of it.
        </p>
      </div>

      {detail ? (
        <StageDetail
          stage={detail}
          live={frame.readouts[detail.id]}
          neighbors={{
            prev: FLOW_ORDER[(detailIndex - 1 + FLOW_ORDER.length) % FLOW_ORDER.length]!,
            next: FLOW_ORDER[(detailIndex + 1) % FLOW_ORDER.length]!,
          }}
          onOpen={onOpenStage}
          onClose={() => onOpenStage(null)}
        />
      ) : null}
    </section>
  );
}