-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathait.js
More file actions
636 lines (581 loc) · 24.3 KB
/
Copy pathait.js
File metadata and controls
636 lines (581 loc) · 24.3 KB
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
// The Agentic Interface Test — app logic. Plain script, no dependencies,
// no network. All questions render on one page; results open in a modal.
(function () {
'use strict';
var DATA = window.AIT_DATA;
if (!DATA) return;
var root = document.getElementById('ait-app');
if (!root) return;
var STORE_KEY = 'ait-deep-session-v2';
var REDUCED = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// ---------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------
function questionsFor(mode) { return mode === 'q' ? DATA.quick : DATA.deep; }
function el(tag, className, text) {
var node = document.createElement(tag);
if (className) node.className = className;
if (text !== undefined && text !== null) node.textContent = text;
return node;
}
function storageGet() {
try { return JSON.parse(localStorage.getItem(STORE_KEY)); } catch (e) { return null; }
}
function storageSet(value) {
try { localStorage.setItem(STORE_KEY, JSON.stringify(value)); } catch (e) { /* private mode */ }
}
// ---------------------------------------------------------------
// Scoring (pure)
// ---------------------------------------------------------------
function scoreAnswers(mode, answers) {
var qs = questionsFor(mode);
var per = DATA.primitives.map(function (p, i) {
return { key: p.key, name: p.name, canonical: i, yes: 0, applicable: 0 };
});
var byKey = {};
per.forEach(function (o) { byKey[o.key] = o; });
qs.forEach(function (q, i) {
byKey[q.primitive].applicable += 1;
if (answers[i] === 'y') byKey[q.primitive].yes += 1;
});
per.forEach(function (o) {
o.pct = o.applicable ? o.yes / o.applicable : 0;
o.frac = o.yes + '/' + o.applicable;
});
var overall = Math.round(per.reduce(function (s, o) { return s + o.pct; }, 0) / per.length * 100);
return { per: per, overall: overall };
}
function levelFor(score) {
for (var i = 0; i < DATA.levels.length; i++) {
if (score <= DATA.levels[i].max) return DATA.levels[i];
}
return DATA.levels[DATA.levels.length - 1];
}
function weakestOf(per) {
return per.slice().sort(function (a, b) {
return (a.pct - b.pct) || (b.canonical - a.canonical);
});
}
// Title line shared by the modal and the canvas scorecard.
function scoreTitle(name, score) {
return (name ? name + '\u2019s Agentic Interface Score' : 'Your Agentic Interface Score') +
' : ' + score + '/100';
}
// ---------------------------------------------------------------
// Permalink parsing (read-only): #r={m}.{answers}.{name?}
// ---------------------------------------------------------------
function parseResult(hash) {
if (!hash || hash.indexOf('#r=') !== 0) return null;
var body = hash.slice(3);
if (body.length < 2 || (body[0] !== 'q' && body[0] !== 'd') || body[1] !== '.') return null;
var mode = body[0];
var rest = body.slice(2);
var dot = rest.indexOf('.');
var answersStr = dot === -1 ? rest : rest.slice(0, dot);
var nameEnc = dot === -1 ? null : rest.slice(dot + 1);
var qs = questionsFor(mode);
if (answersStr.length !== qs.length) return null;
if (!/^[yn]+$/.test(answersStr)) return null;
var name = '';
if (nameEnc) {
try { name = decodeURIComponent(nameEnc); } catch (e) { return null; }
}
return { mode: mode, answers: answersStr.split(''), name: name.slice(0, 60) };
}
// ---------------------------------------------------------------
// State
// ---------------------------------------------------------------
var state = {
mode: 'q',
name: '',
answers: {
q: new Array(DATA.quick.length).fill(null),
d: new Array(DATA.deep.length).fill(null)
}
};
var saved = storageGet();
if (saved && Array.isArray(saved.answers) && saved.answers.length === DATA.deep.length) {
state.answers.d = saved.answers.map(function (a) {
return a === 'y' || a === 'n' ? a : null;
});
if (saved.name) state.name = String(saved.name).slice(0, 60);
}
// Lives next to #ait-app (not inside), so render()'s wipe never
// recreates it and screen readers keep a stable live region.
var announcer = el('p', 'visually-hidden');
announcer.setAttribute('aria-live', 'polite');
root.parentNode.insertBefore(announcer, root);
function announce(text) { announcer.textContent = text; }
function persistDeep() {
storageSet({ answers: state.answers.d, name: state.name });
}
// ---------------------------------------------------------------
// Form (all questions on one page)
// ---------------------------------------------------------------
var formRefs = { count: null, status: null };
function render() {
root.textContent = '';
// Mode tabs
var tabs = el('div', 'ait-mode-tabs');
tabs.setAttribute('role', 'group');
tabs.setAttribute('aria-label', 'Test mode');
tabs.appendChild(modeTab('q', 'Quick test', '16 Qs'));
tabs.appendChild(modeTab('d', 'Deep dive', '48 Qs'));
root.appendChild(tabs);
// Question list
var list = el('div', 'ait-list');
// Question 0: product name, input where the answers usually sit
var nameRow = el('div', 'ait-row ait-name-row');
if (state.name) nameRow.classList.add('ait-answered');
var nameMain = el('label', 'ait-row-main');
var nameWrap = el('span', 'ait-row-textwrap');
var nameNum = el('span', 'numbox ait-row-num', '0');
nameNum.setAttribute('aria-hidden', 'true');
nameWrap.appendChild(nameNum);
nameWrap.appendChild(el('span', 'ait-row-text', 'Product name (optional, appears on your scorecard)'));
nameMain.appendChild(nameWrap);
var nameInput = el('input');
nameInput.type = 'text';
nameInput.maxLength = 60;
nameInput.autocomplete = 'off';
nameInput.value = state.name;
nameInput.className = 'input ait-name-input';
nameInput.addEventListener('input', function () {
state.name = nameInput.value.trim();
nameRow.classList.toggle('ait-answered', state.name.length > 0);
persistDeep();
});
nameMain.appendChild(nameInput);
nameRow.appendChild(nameMain);
list.appendChild(nameRow);
var qs = questionsFor(state.mode);
if (state.mode === 'q') {
var ol = el('ol', 'ait-rows');
qs.forEach(function (q, i) {
ol.appendChild(buildRow(q, i));
});
list.appendChild(ol);
} else {
DATA.primitives.forEach(function (p, s) {
var section = el('section', 'ait-section');
var headRow = el('div', 'ait-section-head');
headRow.appendChild(el('h2', 'ait-section-name', p.name));
headRow.appendChild(el('p', 'ait-section-def', p.def));
section.appendChild(headRow);
var ol2 = el('ol', 'ait-rows');
for (var i = s * 6; i < s * 6 + 6; i++) {
ol2.appendChild(buildRow(qs[i], i));
}
section.appendChild(ol2);
list.appendChild(section);
});
}
root.appendChild(list);
// Sticky generate bar
var bar = el('div', 'ait-genbar');
var progress = el('div', 'ait-genprogress');
var progressFill = el('div', 'ait-genprogress-fill');
progress.appendChild(progressFill);
formRefs.progressFill = progressFill;
var count = el('p', 'ait-gencount');
formRefs.count = count;
var status = el('p', 'ait-genstatus');
status.setAttribute('aria-live', 'polite');
formRefs.status = status;
var genBtn = el('button', 'btn ait-generate', 'Generate score');
genBtn.type = 'button';
genBtn.addEventListener('click', generate);
var left = el('div', 'ait-genleft');
left.appendChild(progress);
left.appendChild(count);
left.appendChild(status);
bar.appendChild(left);
bar.appendChild(genBtn);
root.appendChild(bar);
updateCount();
}
function modeTab(mode, title, chip) {
var b = el('button', 'ait-mode-tab' + (state.mode === mode ? ' active' : ''));
b.type = 'button';
b.setAttribute('aria-pressed', String(state.mode === mode));
b.appendChild(el('span', 'ait-mode-tab-title', title));
b.appendChild(el('span', 'ait-mode-tab-chip', chip));
b.addEventListener('click', function () {
if (state.mode === mode) return;
state.mode = mode;
render();
announce(mode === 'q' ? 'Quick test: 16 questions.' : 'Deep dive: 48 questions.');
});
return b;
}
function buildRow(q, i) {
var li = el('li', 'ait-row');
li.id = 'ait-row-' + state.mode + '-' + i;
if (state.answers[state.mode][i]) li.classList.add('ait-answered');
var main = el('div', 'ait-row-main');
var textWrap = el('div', 'ait-row-textwrap');
var textId = 'ait-qtext-' + state.mode + '-' + i;
var num = el('span', 'numbox ait-row-num', String(i + 1));
num.setAttribute('aria-hidden', 'true');
var text = el('span', 'ait-row-text', q.text);
text.id = textId;
textWrap.appendChild(num);
textWrap.appendChild(text);
main.appendChild(textWrap);
var controls = el('div', 'ait-row-controls');
if (q.tooltip) {
var tip = el('span', 'ait-tip');
var tipBtn = el('button', 'ait-tip-btn', '?');
tipBtn.type = 'button';
tipBtn.setAttribute('aria-label', 'Why this matters?');
tipBtn.setAttribute('aria-expanded', 'false');
var tipBody = el('span', 'ait-tip-body');
tipBody.appendChild(el('strong', 'ait-tip-title', 'Why this matters?'));
tipBody.appendChild(el('span', 'ait-tip-text', q.tooltip));
tipBody.id = 'ait-tip-' + q.id;
tipBtn.setAttribute('aria-controls', tipBody.id);
tipBtn.addEventListener('click', function () {
var open = tip.classList.toggle('open');
tipBtn.setAttribute('aria-expanded', String(open));
});
tip.addEventListener('keydown', function (e) {
if (e.key !== 'Escape') return;
e.stopPropagation();
tip.classList.remove('open');
tip.classList.add('dismissed');
tipBtn.setAttribute('aria-expanded', 'false');
});
['mouseleave', 'focusout'].forEach(function (ev) {
tip.addEventListener(ev, function () { tip.classList.remove('dismissed'); });
});
tip.appendChild(tipBtn);
tip.appendChild(tipBody);
controls.appendChild(tip);
}
var group = el('div', 'ait-seg-group');
group.setAttribute('role', 'radiogroup');
group.setAttribute('aria-labelledby', textId);
group.appendChild(segOption(i, 'y', 'Yes'));
group.appendChild(segOption(i, 'n', 'No'));
controls.appendChild(group);
main.appendChild(controls);
li.appendChild(main);
return li;
}
function segOption(i, value, label) {
var wrap = el('label', 'ait-seg');
var input = el('input');
input.type = 'radio';
input.name = 'ait-' + state.mode + '-' + i;
input.value = value;
input.checked = state.answers[state.mode][i] === value;
input.addEventListener('change', function () {
state.answers[state.mode][i] = value;
if (state.mode === 'd') persistDeep();
var row = document.getElementById('ait-row-' + state.mode + '-' + i);
if (row) {
row.classList.remove('ait-missing');
row.classList.add('ait-answered');
}
updateCount();
});
wrap.appendChild(input);
wrap.appendChild(el('span', 'ait-seg-label', label));
return wrap;
}
function updateCount() {
var answers = state.answers[state.mode];
var total = answers.length;
var done = answers.filter(Boolean).length;
if (formRefs.count) formRefs.count.textContent = done + ' of ' + total + ' answered';
if (formRefs.progressFill) formRefs.progressFill.style.width = (done / total * 100) + '%';
if (formRefs.status && formRefs.status.textContent) {
var left = total - done;
formRefs.status.textContent = left === 0 ? '' :
(left === 1 ? '1 question unanswered.' : left + ' questions unanswered.');
}
}
function generate() {
var answers = state.answers[state.mode];
var missing = [];
answers.forEach(function (a, i) { if (!a) missing.push(i); });
if (missing.length) {
missing.forEach(function (i) {
var row = document.getElementById('ait-row-' + state.mode + '-' + i);
if (row) row.classList.add('ait-missing');
});
var msg = missing.length === 1 ? '1 question unanswered.' : missing.length + ' questions unanswered.';
if (formRefs.status) formRefs.status.textContent = msg;
announce(msg);
var first = document.getElementById('ait-row-' + state.mode + '-' + missing[0]);
if (first) {
first.scrollIntoView({ block: 'center', behavior: REDUCED ? 'auto' : 'smooth' });
var input = first.querySelector('input');
if (input) input.focus({ preventScroll: true });
}
return;
}
openModal({ mode: state.mode, answers: answers.slice(), name: state.name, readOnly: false });
}
// ---------------------------------------------------------------
// Results modal
// ---------------------------------------------------------------
var modal = null, modalOpener = null, modalResize = null;
// keepHash: openModal replaces one modal with another (permalink ->
// permalink navigation) and must not strip the hash it is opening.
function closeModal(keepHash) {
if (!modal) return;
if (!keepHash && location.hash.indexOf('#r=') === 0) {
history.replaceState(null, '', location.pathname + location.search);
}
modal.remove();
modal = null;
document.documentElement.classList.remove('ait-modal-open');
document.removeEventListener('keydown', modalKeydown, true);
if (modalResize) { window.removeEventListener('resize', modalResize); modalResize = null; }
if (modalOpener && modalOpener.focus) modalOpener.focus();
modalOpener = null;
}
function modalKeydown(e) {
if (!modal) return;
if (e.key === 'Escape') { e.preventDefault(); closeModal(); return; }
if (e.key === 'Tab') {
var focusables = modal.querySelectorAll('button, a[href], input, [tabindex="0"]');
if (!focusables.length) return;
var first = focusables[0], last = focusables[focusables.length - 1];
if (!modal.contains(document.activeElement)) { e.preventDefault(); first.focus(); return; }
if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
}
}
function openModal(opts) {
closeModal(true);
modalOpener = document.activeElement;
var result = scoreAnswers(opts.mode, opts.answers);
var score = result.overall;
var level = levelFor(score);
modal = el('div', 'ait-modal-backdrop');
modal.addEventListener('mousedown', function (e) {
if (e.target === modal) closeModal();
});
var dialog = el('div', 'ait-modal');
dialog.setAttribute('role', 'dialog');
dialog.setAttribute('aria-modal', 'true');
dialog.setAttribute('aria-labelledby', 'ait-modal-title');
var closeBtn = el('button', 'ait-modal-close');
if (window.AIF) closeBtn.innerHTML = window.AIF.iconSVG('x', 16);
else closeBtn.textContent = '×';
closeBtn.type = 'button';
closeBtn.setAttribute('aria-label', 'Close results');
closeBtn.addEventListener('click', function () { closeModal(); });
dialog.appendChild(closeBtn);
var title = el('h2', 'ait-modal-title', scoreTitle(opts.name, score));
title.id = 'ait-modal-title';
title.setAttribute('tabindex', '-1');
dialog.appendChild(title);
// Landscape row: level stepper (left) + primitives radar (right)
var grid = el('div', 'ait-scoregrid');
grid.appendChild(buildStepper(level));
grid.appendChild(buildRadar(result.per));
dialog.appendChild(grid);
// Gaps / Native line
if (score === 100) {
dialog.appendChild(el('p', 'ait-level5-line', 'Level 5: Fully Agentic. Rare, by design. Re-test in 90 days to make sure it holds.'));
} else {
dialog.appendChild(buildGaps(result, opts));
}
// Quick-mode CTA
if (opts.mode === 'q' && !opts.readOnly) {
var cta = el('div', 'ait-deep-cta');
cta.appendChild(el('p', null, 'Your quick score is an estimate from two checks per primitive. The deep dive runs 48 checks and pinpoints exactly where you lose points.'));
var deepBtn = el('button', 'btn', 'Run the deep dive');
deepBtn.type = 'button';
deepBtn.addEventListener('click', function () {
closeModal();
state.mode = 'd';
render();
window.scrollTo(0, 0);
var tab = root.querySelector('.ait-mode-tab.active');
if (tab) tab.focus();
announce('Deep dive: 48 questions.');
});
cta.appendChild(deepBtn);
dialog.appendChild(cta);
}
// aria-modal hides content outside the dialog, so the score is
// announced from a live region inside it (registered before write).
var live = el('p', 'visually-hidden');
live.setAttribute('aria-live', 'polite');
dialog.appendChild(live);
modal.appendChild(dialog);
document.body.appendChild(modal);
document.documentElement.classList.add('ait-modal-open');
document.addEventListener('keydown', modalKeydown, true);
title.focus();
setTimeout(function () {
live.textContent = 'Score ' + score + ' out of 100. Level ' + level.n + ': ' + level.name + '.';
}, 60);
}
function buildStepper(level) {
var wrap = el('div', 'ait-stepper');
wrap.setAttribute('role', 'group');
wrap.setAttribute('aria-label', 'Level ' + level.n + ' of 5: ' + level.name + '.');
var track = el('div', 'ait-stepper-track');
track.appendChild(el('div', 'ait-stepper-fill'));
wrap.appendChild(track);
var steps = el('ol', 'ait-steps');
DATA.levels.forEach(function (l) {
var s = l.n < level.n ? 'passed' : (l.n === level.n ? 'current' : 'locked');
var li = el('li', 'ait-step ait-step-' + s);
if (s === 'current') li.setAttribute('aria-current', 'step');
var box = el('span', 'numbox ait-step-box', '');
box.setAttribute('aria-hidden', 'true');
li.appendChild(box);
var body = el('div', 'ait-step-body');
body.appendChild(el('span', 'ait-step-name', 'Level ' + l.n + ': ' + l.name));
body.appendChild(el('p', 'ait-step-desc', l.line));
li.appendChild(body);
steps.appendChild(li);
});
wrap.appendChild(steps);
// Position the track between node centers, then animate the fill to
// the achieved level. The timeout is the throttled-renderer fallback.
requestAnimationFrame(function () { positionStepper(wrap, level, false); });
setTimeout(function () { positionStepper(wrap, level, true); }, 1000);
// Level rows rewrap at other widths; keep the track aligned.
modalResize = function () { positionStepper(wrap, level, true); };
window.addEventListener('resize', modalResize);
return wrap;
}
function positionStepper(wrap, level, force) {
var boxes = wrap.querySelectorAll('.ait-step-box');
var track = wrap.querySelector('.ait-stepper-track');
var fill = wrap.querySelector('.ait-stepper-fill');
if (!boxes.length || !track || !fill) return;
var wrapTop = wrap.getBoundingClientRect().top;
function centerOf(i) {
var b = boxes[i].getBoundingClientRect();
return b.top - wrapTop + b.height / 2;
}
var top = centerOf(0);
track.style.top = top + 'px';
track.style.height = (centerOf(boxes.length - 1) - top) + 'px';
var target = centerOf(level.n - 1) - top;
if (force || REDUCED) {
fill.style.transition = 'none';
fill.style.height = target + 'px';
} else {
requestAnimationFrame(function () { fill.style.height = target + 'px'; });
}
}
function buildRadar(per) {
var NS = 'http://www.w3.org/2000/svg';
var W = 440, H = 340, cx = W / 2, cy = H / 2, R = 105;
var svg = document.createElementNS(NS, 'svg');
svg.setAttribute('viewBox', '0 0 ' + W + ' ' + H);
svg.setAttribute('class', 'ait-radar');
svg.setAttribute('role', 'img');
svg.setAttribute('aria-label', 'Primitive scores: ' + per.map(function (o) { return o.name + ' ' + o.frac; }).join(', ') + '.');
function pt(i, radius) {
var a = -Math.PI / 2 + i * Math.PI / 4;
return [cx + radius * Math.cos(a), cy + radius * Math.sin(a)];
}
[0.25, 0.5, 0.75, 1].forEach(function (f) {
var ring = document.createElementNS(NS, 'polygon');
ring.setAttribute('points', per.map(function (_, i) { return pt(i, R * f).join(','); }).join(' '));
ring.setAttribute('class', 'ait-radar-ring');
svg.appendChild(ring);
});
per.forEach(function (_, i) {
var axis = document.createElementNS(NS, 'line');
var p = pt(i, R);
axis.setAttribute('x1', cx); axis.setAttribute('y1', cy);
axis.setAttribute('x2', p[0]); axis.setAttribute('y2', p[1]);
axis.setAttribute('class', 'ait-radar-axis');
svg.appendChild(axis);
});
var data = document.createElementNS(NS, 'polygon');
data.setAttribute('points', per.map(function (o, i) { return pt(i, R * o.pct).join(','); }).join(' '));
data.setAttribute('class', 'ait-radar-data');
svg.appendChild(data);
per.forEach(function (o, i) {
var p = pt(i, R + 14);
var t = document.createElementNS(NS, 'text');
var anchor = 'middle', dx = 0, dy = 4;
if (i === 0) { dy = -2; }
else if (i === 4) { dy = 12; }
else if (i < 4) { anchor = 'start'; dx = 4; }
else { anchor = 'end'; dx = -4; }
t.setAttribute('x', p[0] + dx);
t.setAttribute('y', p[1] + dy);
t.setAttribute('text-anchor', anchor);
t.setAttribute('class', 'ait-radar-label');
t.textContent = o.name;
svg.appendChild(t);
});
var holder = el('div', 'ait-radar-wrap');
holder.appendChild(svg);
return holder;
}
function collectGapFixes(result, opts) {
var qs = questionsFor(opts.mode);
var keys = weakestOf(result.per).filter(function (o) { return o.pct < 1; }).slice(0, 3)
.map(function (o) { return o.key; });
var fixes = [];
qs.forEach(function (q, i) {
if (keys.indexOf(q.primitive) !== -1 && opts.answers[i] === 'n') fixes.push(q.fix);
});
return fixes;
}
function buildGaps(result, opts) {
var wrap = el('div', 'ait-gaps');
wrap.appendChild(el('h3', 'ait-block-title', 'Biggest gaps'));
var list = el('ol', 'ait-gap-list');
collectGapFixes(result, opts).forEach(function (fix, i) {
var li = el('li', 'ait-gap-item');
var num = el('span', 'numbox', String(i + 1));
num.setAttribute('aria-hidden', 'true');
li.appendChild(num);
li.appendChild(el('span', 'ait-gap-text', fix));
list.appendChild(li);
});
wrap.appendChild(list);
return wrap;
}
// ---------------------------------------------------------------
// Shared-result handling + boot
// ---------------------------------------------------------------
function tryShared() {
var parsed = parseResult(location.hash);
if (!parsed) return false;
openModal({ mode: parsed.mode, answers: parsed.answers, name: parsed.name, readOnly: true });
return true;
}
window.addEventListener('hashchange', function () {
if (!tryShared() && modal) closeModal();
});
// ---------------------------------------------------------------
// Dev sanity checks (?aitdev)
// ---------------------------------------------------------------
if (/[?&]aitdev\b/.test(location.search)) {
(function () {
var allYes = new Array(48).fill('y');
var allNo = new Array(48).fill('n');
var fixtureYes = { GI: 4, RP: 5, SDT: 5, KC: 3, ET: 4, EF: 2, MA: 4, BH: 3 };
var fixture = DATA.deep.map(function (q) {
if (fixtureYes[q.primitive] > 0) { fixtureYes[q.primitive] -= 1; return 'y'; }
return 'n';
});
var a = scoreAnswers('d', allYes), b = scoreAnswers('d', allNo), c = scoreAnswers('d', fixture);
var ok1 = a.overall === 100 && levelFor(a.overall).name === 'Fully Agentic';
var ok2 = b.overall === 0 && levelFor(b.overall).name === 'Chatbot';
var ok3 = c.overall === 63 && levelFor(c.overall).name === 'Copilot';
console.assert(ok1, 'AIT: all-yes deep must be 100 / Fully Agentic, got ' + a.overall);
console.assert(ok2, 'AIT: all-no deep must be 0 / Chatbot, got ' + b.overall);
console.assert(ok3, 'AIT: fixture deep must be 63 / Copilot, got ' + c.overall);
console.log('AIT dev: ' + [ok1, ok2, ok3].filter(Boolean).length + '/3 sanity checks passed');
})();
}
render();
tryShared();
})();