star-quest 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +128 -2
- package/THIRD_PARTY.md +124 -0
- package/docs/mocks/flow.js +523 -0
- package/docs/mocks/mock.css +2226 -0
- package/docs/mocks/mock.js +335 -0
- package/docs/mocks/money-v2-2.css +272 -0
- package/docs/mocks/money-v2.css +364 -0
- package/docs/mocks/stars.js +540 -0
- package/package.json +70 -4
- package/public/accent.js +88 -0
- package/public/backpack.html +220 -0
- package/public/backpack.js +336 -0
- package/public/billion.js +666 -0
- package/public/bulletin.html +77 -0
- package/public/bulletin.js +376 -0
- package/public/home.js +1440 -0
- package/public/index.html +127 -0
- package/public/infotip.js +79 -0
- package/public/map.html +75 -0
- package/public/map.js +93 -0
- package/public/md.js +173 -0
- package/public/money.css +753 -0
- package/public/party.html +60 -0
- package/public/party.js +90 -0
- package/public/purse.js +2616 -0
- package/public/quests.html +88 -0
- package/public/quests.js +222 -0
- package/public/readaloud.js +362 -0
- package/public/settings-money.js +247 -0
- package/public/settings.html +142 -0
- package/public/settings.js +365 -0
- package/public/skills.html +106 -0
- package/public/skills.js +838 -0
- package/public/term.js +184 -0
- package/public/theme-boot.js +105 -0
- package/public/voice.js +359 -0
- package/scripts/make-theme.js +63 -0
- package/scripts/theme-image.swift +537 -0
- package/scripts/theme-maker.js +277 -0
- package/server/agent-watch.js +195 -0
- package/server/backpack.js +248 -0
- package/server/billion.js +555 -0
- package/server/bulletin.js +449 -0
- package/server/chat.js +536 -0
- package/server/claude-trust.js +60 -0
- package/server/connectors.js +22 -0
- package/server/cron.js +235 -0
- package/server/doctor.js +85 -0
- package/server/env.js +45 -0
- package/server/first-start.js +237 -0
- package/server/guard.js +212 -0
- package/server/index.js +1135 -0
- package/server/install.js +62 -0
- package/server/keys.js +128 -0
- package/server/map.js +66 -0
- package/server/mcp.js +711 -0
- package/server/money/alerts.js +328 -0
- package/server/money/asset-stale.js +51 -0
- package/server/money/backup.js +69 -0
- package/server/money/bank-rows.js +56 -0
- package/server/money/budgets.js +794 -0
- package/server/money/detect.js +123 -0
- package/server/money/detectors/_prelude.sql +98 -0
- package/server/money/detectors/candidates/amount_outlier.sql +23 -0
- package/server/money/detectors/candidates/first_merchant.sql +11 -0
- package/server/money/detectors/candidates/new_category.sql +11 -0
- package/server/money/detectors/candidates/no_source.sql +11 -0
- package/server/money/detectors/candidates/recurring_changed.sql +24 -0
- package/server/money/detectors/candidates/unmatched_transfer.sql +18 -0
- package/server/money/detectors/rules/budget_pace.sql +74 -0
- package/server/money/detectors/rules/duplicate_charge.sql +45 -0
- package/server/money/detectors/rules/low_balance.sql +22 -0
- package/server/money/detectors/rules/new_recurring.sql +18 -0
- package/server/money/detectors/rules/recurring_price.sql +40 -0
- package/server/money/detectors/rules/sync_health.sql +20 -0
- package/server/money/difflib.js +68 -0
- package/server/money/finnamon-detectors.sha256 +15 -0
- package/server/money/finnamon-migrations.sha256 +17 -0
- package/server/money/import.js +474 -0
- package/server/money/imports.js +710 -0
- package/server/money/ledger.js +99 -0
- package/server/money/migrations/001_init.sql +197 -0
- package/server/money/migrations/002_properties.sql +6 -0
- package/server/money/migrations/003_properties_nocase.sql +11 -0
- package/server/money/migrations/004_manual_items.sql +5 -0
- package/server/money/migrations/005_tx_now_view.sql +51 -0
- package/server/money/migrations/006_recurring_is_active.sql +4 -0
- package/server/money/migrations/007_suppression_stream.sql +3 -0
- package/server/money/migrations/008_tx_flow.sql +96 -0
- package/server/money/migrations/009_alert_resolution.sql +5 -0
- package/server/money/migrations/010_account_type.sql +8 -0
- package/server/money/migrations/011_tx_category_override.sql +87 -0
- package/server/money/migrations/012_budget_selectors.sql +13 -0
- package/server/money/migrations/013_unmerge_owner.sql +2 -0
- package/server/money/migrations/014_budget_limit_history.sql +16 -0
- package/server/money/migrations/015_budget_period.sql +6 -0
- package/server/money/migrations/100_sq_account_prefs.sql +11 -0
- package/server/money/migrations/101_sq_items.sql +9 -0
- package/server/money/migrations/102_sq_by_hand.sql +25 -0
- package/server/money/migrations/103_sq_imports.sql +30 -0
- package/server/money/migrations/104_sq_alert_posts.sql +11 -0
- package/server/money/networth.js +209 -0
- package/server/money/plaid-link.js +530 -0
- package/server/money/plaid.js +122 -0
- package/server/money/properties.js +243 -0
- package/server/money/purse.js +419 -0
- package/server/money/pyjson.js +15 -0
- package/server/money/recurring.js +381 -0
- package/server/money/remove.js +42 -0
- package/server/money/repeats.js +159 -0
- package/server/money/secrets.js +206 -0
- package/server/money/simplefin.js +118 -0
- package/server/money/skill.js +29 -0
- package/server/money/store.js +318 -0
- package/server/money/sync-plaid.js +315 -0
- package/server/money/sync-simplefin.js +407 -0
- package/server/money/taxonomy.js +305 -0
- package/server/money/timer.js +241 -0
- package/server/money/tools.js +776 -0
- package/server/money/triage.js +58 -0
- package/server/quests.js +1110 -0
- package/server/reasons.js +28 -0
- package/server/remote-setup.js +199 -0
- package/server/remote.js +92 -0
- package/server/screen.js +279 -0
- package/server/service.js +539 -0
- package/server/skill-packages.js +443 -0
- package/server/skills.js +282 -0
- package/server/theme.js +196 -0
- package/server/tts-worker.js +40 -0
- package/server/tts.js +204 -0
- package/server/turns.js +184 -0
- package/server/update-cli.js +73 -0
- package/server/update-run.js +101 -0
- package/server/update.js +273 -0
- package/server/vega-hook.js +111 -0
- package/server/voice-setup.js +279 -0
- package/server/voice.js +118 -0
- package/server/wake.js +66 -0
- package/start.js +197 -0
- package/templates/billion/charter.md +391 -0
- package/templates/billion/rules.md +9 -0
- package/templates/billion/user.md +18 -0
- package/templates/finance/SKILL.md +133 -0
- package/templates/skill-catalog.json +714 -0
- package/templates/skill-families.json +355 -0
- package/templates/worker/charter.md +31 -0
- package/themes/library/billion.svg +198 -0
- package/themes/library/hall.svg +37 -0
- package/themes/library/theme.json +16 -0
- package/themes/space/ship.svg +75 -0
- package/themes/space/theme.json +16 -0
- package/themes/space/vega.svg +203 -0
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
// Mock only. Two scripted flows on one page: flow.html?flow=chat and ?flow=briefing. Nothing the player types is read; it is shown, then the next beat plays. Replay is a plain reload.
|
|
2
|
+
// Pacing is an LLM's: seconds of thinking, tens of seconds of work, in real time. A click on the room or any key skips the current wait.
|
|
3
|
+
const $ = s => document.querySelector(s);
|
|
4
|
+
const room = $('.room'), dlg = $('.dlg'), plate = $('.plate'), yours = $('.yours'), say = $('.say'), lineEl = $('.line'), subEl = $('.sub'), hint = $('.next');
|
|
5
|
+
const list = $('.choices'), also = $('.also'), form = $('.reply'), input = $('#say');
|
|
6
|
+
const papers = $('.papers'), card = $('.card'), ledger = $('.ledger'), rows = $('.ledger ol');
|
|
7
|
+
const quests = $('#quests'), foot = $('.foot'), count = $('#count');
|
|
8
|
+
const queue = $('.queue'), notes = $('.queue ol'), note = $('#note'), logbook = $('#log'), entries = $('#log .entries'), logTool = $('.tool[aria-controls=log]');
|
|
9
|
+
|
|
10
|
+
const moved = matchMedia('(prefers-reduced-motion: no-preference)').matches;
|
|
11
|
+
const phone = matchMedia('(max-width: 760px)');
|
|
12
|
+
const beat = moved ? 900 : 2200; // with no typing to watch, lines need longer on screen
|
|
13
|
+
const clock = s => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, '0')}`;
|
|
14
|
+
const wait = ms => new Promise(r => setTimeout(r, ms));
|
|
15
|
+
const typing = () => document.body.classList.contains('typing');
|
|
16
|
+
// A control that just appeared ignores presses for a moment: a held key or a double click meant for the last thing must not answer a decision.
|
|
17
|
+
const armed = () => { const at = Date.now() + 400; return () => Date.now() >= at; };
|
|
18
|
+
|
|
19
|
+
// A wait runs on the clock in real time. A click on the room or any key skips this one wait; typing to Vega or using a control doesn't.
|
|
20
|
+
function pause(ms, tick) {
|
|
21
|
+
return new Promise(done => {
|
|
22
|
+
const start = Date.now();
|
|
23
|
+
const run = setInterval(() => tick?.((Date.now() - start) / 1000), 200);
|
|
24
|
+
const stop = () => {
|
|
25
|
+
clearTimeout(end); clearTimeout(arm); clearInterval(run);
|
|
26
|
+
removeEventListener('click', onClick);
|
|
27
|
+
removeEventListener('keydown', onKey);
|
|
28
|
+
done();
|
|
29
|
+
};
|
|
30
|
+
const onClick = e => { if (!e.target.closest('a, button, textarea, .notice, .papers, .queue')) stop(); };
|
|
31
|
+
const onKey = e => {
|
|
32
|
+
if (e.repeat || e.metaKey || e.ctrlKey || e.altKey || e.target.matches('textarea') || reading()) return;
|
|
33
|
+
if (e.key.length > 1 && e.key !== 'Enter') return; // Shift, Tab, arrows, F5: not a press at the room
|
|
34
|
+
if (e.target.matches('a, button') && (e.key === 'Enter' || e.key === ' ')) return;
|
|
35
|
+
stop();
|
|
36
|
+
};
|
|
37
|
+
const end = setTimeout(stop, ms);
|
|
38
|
+
// Armed a task later, so the press that started this wait can't also skip it.
|
|
39
|
+
const arm = setTimeout(() => { addEventListener('click', onClick); addEventListener('keydown', onKey); });
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (!matchMedia('(hover: hover)').matches) hint.querySelector('kbd').textContent = 'Tap';
|
|
43
|
+
|
|
44
|
+
// The hint shows while more of Vega's message remains: a next page, or on a phone more of the line below
|
|
45
|
+
const cue = () => { mark(lineEl); hint.hidden = !(onMore || below(lineEl)); if (!onMore) hint.querySelector('.pg').textContent = ''; };
|
|
46
|
+
const forth = () => onward(lineEl) || onMore?.();
|
|
47
|
+
lineEl.addEventListener('scroll', cue);
|
|
48
|
+
document.fonts?.ready.then(() => cue());
|
|
49
|
+
addEventListener('resize', () => cue());
|
|
50
|
+
|
|
51
|
+
// ----- the views: Home and Bulletin are one room with different paper out. The menu marks Bulletin while it is out
|
|
52
|
+
function view(name) {
|
|
53
|
+
shut();
|
|
54
|
+
room.dataset.view = name;
|
|
55
|
+
room.classList.toggle('scene', name !== 'home'); // the Bulletin is the evidence stage: Vega aside, the notice in the paper's place, the full-width box
|
|
56
|
+
const dest = name === 'home' ? 'home' : 'bulletin';
|
|
57
|
+
document.querySelectorAll('.menu [data-dest]').forEach(t => t.dataset.dest === dest ? t.setAttribute('aria-current', 'page') : t.removeAttribute('aria-current'));
|
|
58
|
+
}
|
|
59
|
+
// The Bulletin's badge counts what is open on the bulletin, and goes when nothing is
|
|
60
|
+
const badge = n => { count.textContent = n; count.parentNode.hidden = !n; };
|
|
61
|
+
|
|
62
|
+
// ----- the Log: a letter like any other evidence. Vega steps aside and it takes the paper's place. Every message, oldest first and opened at the newest, each in full
|
|
63
|
+
const reading = () => room.classList.contains('reading');
|
|
64
|
+
function shut() {
|
|
65
|
+
if (!reading()) return;
|
|
66
|
+
room.classList.remove('reading');
|
|
67
|
+
logTool.setAttribute('aria-expanded', false);
|
|
68
|
+
}
|
|
69
|
+
logTool.addEventListener('click', () => {
|
|
70
|
+
if (reading()) return shut();
|
|
71
|
+
room.classList.add('reading');
|
|
72
|
+
logTool.setAttribute('aria-expanded', true);
|
|
73
|
+
logbook.scrollTop = logbook.scrollHeight; // the newest message is in view
|
|
74
|
+
logbook.focus({ preventScroll: true });
|
|
75
|
+
});
|
|
76
|
+
logbook.querySelector('.shut').addEventListener('click', shut);
|
|
77
|
+
addEventListener('keydown', e => { if (e.key === 'Escape') shut(); });
|
|
78
|
+
|
|
79
|
+
// User text is never parsed into markup: paragraphs and pipe tables are built from text nodes. Vega's scripted extras (an image, a file) are the script's own markup.
|
|
80
|
+
function md(text) {
|
|
81
|
+
const out = document.createDocumentFragment();
|
|
82
|
+
for (const block of text.split(/\n\s*\n/)) {
|
|
83
|
+
const lines = block.split('\n').filter(l => l.trim());
|
|
84
|
+
if (lines.length > 1 && lines.every(l => /^\s*\|.*\|\s*$/.test(l))) {
|
|
85
|
+
const [head, ...body] = lines.filter(l => !/^[\s|:-]+$/.test(l)).map(l => l.trim().slice(1, -1).split('|').map(c => c.trim()));
|
|
86
|
+
const table = document.createElement('table'), tbody = table.createTBody();
|
|
87
|
+
const row = (section, cells, tag) => {
|
|
88
|
+
const tr = section.insertRow();
|
|
89
|
+
cells.forEach((c, j) => { const cell = document.createElement(tag(j)); cell.textContent = c; tr.append(cell); });
|
|
90
|
+
};
|
|
91
|
+
row(table.createTHead(), head, () => 'th');
|
|
92
|
+
body.forEach(cells => row(tbody, cells, j => j ? 'td' : 'th'));
|
|
93
|
+
out.append(table);
|
|
94
|
+
} else if (lines.length) {
|
|
95
|
+
const p = document.createElement('p');
|
|
96
|
+
p.textContent = lines.join('\n');
|
|
97
|
+
out.append(p);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
function log(speaker, text, { at, extra = '' } = {}) {
|
|
103
|
+
const li = document.createElement('li');
|
|
104
|
+
li.className = speaker === 'Vega' ? 'said by' : 'said';
|
|
105
|
+
li.innerHTML = '<b><span></span><time></time></b><div class="body"></div>';
|
|
106
|
+
li.querySelector('span').textContent = speaker;
|
|
107
|
+
li.querySelector('time').textContent = at ?? new Date().toTimeString().slice(0, 5);
|
|
108
|
+
li.querySelector('.body').append(md(text));
|
|
109
|
+
li.querySelector('.body').insertAdjacentHTML('beforeend', extra);
|
|
110
|
+
entries.append(li);
|
|
111
|
+
return li;
|
|
112
|
+
}
|
|
113
|
+
// Yesterday, so the Log opens on a real history: an attachment, folded work details, a table and an image
|
|
114
|
+
[
|
|
115
|
+
['You', 'Yesterday 22:14', 'Ship dark mode for the settings page, and fix the login bug. Here\'s the error people see.', '<a class="file" href="#"><i class="i i-clip"></i>login-error.png</a>'],
|
|
116
|
+
['Vega', 'Yesterday 22:15', 'On it. Dark mode is mostly styles, so a worker can take it tonight. The login bug needs reading first: the screenshot shows a blank page after sign-in, which usually means a session check gone wrong. I\'ll have both ready for you to look at by morning.',
|
|
117
|
+
'<details><summary>Work details, 3 steps</summary><ol><li>Read the login code <time>0:41</time></li><li>Found the expired session check <time>1:12</time></li><li>Posted the quest <time>0:06</time></li></ol></details>'],
|
|
118
|
+
['Vega', 'Yesterday 23:02', 'Where the plate fix stands, screen by screen. Home and the Bulletin share one plate, so one fix covers both; the Voice screen is the one I\'d still check.\n\n| Screen | Status | Next step |\n| --- | --- | --- |\n| Home | Fixed in PR #5 | Merge it |\n| Bulletin | Fixed in PR #5 | Merge it |\n| Voice | Not checked yet | Wren checks it today |',
|
|
119
|
+
'<figure><img src="screenshots/you-plate-after-chat-desktop-long.png" alt="Home after the fix: the player\'s plate holds a long message at full width" width="1280" height="800" loading="lazy"><figcaption>Home after the fix, on a long message.</figcaption></figure>'],
|
|
120
|
+
].forEach(([who, at, text, extra]) => log(who, text, { at, extra }));
|
|
121
|
+
|
|
122
|
+
// ----- the input: Enter sends what you typed, Shift+Enter is a new line. Empty, Enter shows Vega's next page. It grows to six lines (four on a phone), then scrolls
|
|
123
|
+
let onSend = null, onMore = null, early = null, sentFrom = null;
|
|
124
|
+
// The top left of the text in the input, in the viewport
|
|
125
|
+
const words = () => { const r = input.getBoundingClientRect(), s = getComputedStyle(input); return { x: r.left + input.clientLeft + parseFloat(s.paddingLeft), y: r.top + input.clientTop + parseFloat(s.paddingTop) }; };
|
|
126
|
+
const clearInput = () => { input.value = ''; input.dispatchEvent(new Event('input')); };
|
|
127
|
+
function mine(yes, hint) {
|
|
128
|
+
form.classList.toggle('wait', !yes);
|
|
129
|
+
room.classList.toggle('asking', yes);
|
|
130
|
+
input.placeholder = hint || (yes ? 'Say something to Vega' : 'I\'ll read this when I look up');
|
|
131
|
+
}
|
|
132
|
+
input.addEventListener('keydown', e => {
|
|
133
|
+
if (e.key !== 'Enter' || e.shiftKey || e.isComposing) return;
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
if (input.value.trim()) form.requestSubmit();
|
|
136
|
+
else if (!typing()) forth();
|
|
137
|
+
});
|
|
138
|
+
form.addEventListener('submit', e => {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
const text = input.value.trim();
|
|
141
|
+
if (!text && !onSend) return;
|
|
142
|
+
sentFrom = { text, ...words() }; // where the words sat, measured before the input clears: your box is born there
|
|
143
|
+
clearInput();
|
|
144
|
+
if (onSend) return onSend(text);
|
|
145
|
+
if (room.classList.contains('busy')) { sentFrom = null; return enqueue(text); }
|
|
146
|
+
early = text; // said while Vega was mid-line: it answers once it has finished
|
|
147
|
+
});
|
|
148
|
+
const hears = () => {
|
|
149
|
+
if (early !== null) { const t = early; early = null; return Promise.resolve(t); }
|
|
150
|
+
return new Promise(r => { onSend = t => { onSend = null; r(t); }; });
|
|
151
|
+
};
|
|
152
|
+
// Vega has more to show. Empty input: Enter or Space, or a click outside the input, shows it. Text in the input: Enter sends it, and Vega's message skips to its end.
|
|
153
|
+
addEventListener('keydown', e => {
|
|
154
|
+
if (!(onMore || below(lineEl)) || typing() || e.repeat || e.metaKey || e.ctrlKey || e.altKey || reading()) return;
|
|
155
|
+
if (e.key !== 'Enter' && e.key !== ' ') return;
|
|
156
|
+
if (e.target.matches('textarea') && (e.key === 'Enter' || input.value)) return; // the input's own handler has Enter; a space with text is a space
|
|
157
|
+
if (e.target.closest('a, button, [contenteditable]')) return;
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
forth();
|
|
160
|
+
});
|
|
161
|
+
addEventListener('click', e => { if ((onMore || below(lineEl)) && !typing() && !e.target.closest('a, button, textarea, label, .papers, .notice, .queue')) forth(); });
|
|
162
|
+
hint.addEventListener('click', e => { e.stopPropagation(); forth(); });
|
|
163
|
+
// Resolves with nothing when the user asks for more, or with what they sent instead.
|
|
164
|
+
function more(pg = '') {
|
|
165
|
+
const ready = armed();
|
|
166
|
+
return new Promise(r => {
|
|
167
|
+
const go = text => {
|
|
168
|
+
onMore = onSend = null;
|
|
169
|
+
cue();
|
|
170
|
+
r(text);
|
|
171
|
+
};
|
|
172
|
+
onMore = () => { if (ready()) go(); };
|
|
173
|
+
hint.querySelector('.pg').textContent = pg;
|
|
174
|
+
cue();
|
|
175
|
+
if (early !== null) { const t = early; early = null; go(t); } else onSend = go;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ----- the queue: what you send while Vega works waits next to the input, oldest first. Remove one with ×; tap one to put it back in the input. Vega answers them in order when it looks up
|
|
180
|
+
function enqueue(text) {
|
|
181
|
+
const li = note.content.firstElementChild.cloneNode(true);
|
|
182
|
+
li.querySelector('.text').textContent = text;
|
|
183
|
+
li.title = text;
|
|
184
|
+
notes.append(li);
|
|
185
|
+
li.logged = log('You', text); // withdrawn, it was never said
|
|
186
|
+
tally();
|
|
187
|
+
}
|
|
188
|
+
function tally() {
|
|
189
|
+
const all = [...notes.children], now = all.findIndex(li => li.matches('.now'));
|
|
190
|
+
all.forEach((li, i) => li.querySelector('.n').textContent = i + 1);
|
|
191
|
+
queue.hidden = !all.length;
|
|
192
|
+
queue.classList.toggle('answering', now >= 0);
|
|
193
|
+
queue.querySelector('.waiting').textContent = now >= 0 ? `Answering ${now + 1} of ${all.length}.` : `${all.length} waiting. I'll read them when I look up.`;
|
|
194
|
+
}
|
|
195
|
+
notes.addEventListener('click', e => {
|
|
196
|
+
const li = e.target.closest('.memo');
|
|
197
|
+
if (!li || li.matches('.now')) return;
|
|
198
|
+
if (e.target.closest('.edit')) { input.value = li.querySelector('.text').textContent; input.dispatchEvent(new Event('input')); input.focus(); }
|
|
199
|
+
if (e.target.closest('.edit, .drop')) { li.logged.remove(); li.remove(); tally(); }
|
|
200
|
+
});
|
|
201
|
+
// At a stopping point, one reply per note, oldest first; an answered note leaves.
|
|
202
|
+
async function answerQueue() {
|
|
203
|
+
while (notes.children.length) {
|
|
204
|
+
const li = notes.firstElementChild, text = li.querySelector('.text').textContent;
|
|
205
|
+
li.classList.add('now');
|
|
206
|
+
li.setAttribute('aria-current', 'true');
|
|
207
|
+
tally();
|
|
208
|
+
const q = text.length > 70 ? text.slice(0, 68).trimEnd() + '…' : text;
|
|
209
|
+
await line(`About your note, “${q}”: I've written it into the quest, so the worker has it too. It doesn't change what I'll recommend, and nothing has shipped while you were waiting. If it turns out to matter more than it looks, I'll stop and ask you.`, '', text);
|
|
210
|
+
await more();
|
|
211
|
+
li.remove();
|
|
212
|
+
tally();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ----- send: one motion. Vega's whole box rises and fades, a beat ahead of yours; your words leave the input as your box and glide up into the place Vega's box held; then Vega's new box fades up below it with a short status
|
|
217
|
+
// The box that leaves is a copy of the plate above the input (frame, nameplate, tools, words); the real one waits, unframed and empty, until back() fades it in. Reduced motion crossfades.
|
|
218
|
+
const SEND = getComputedStyle(document.documentElement).getPropertyValue('--send').trim(); // the one curve every part of the send shares
|
|
219
|
+
function lift() {
|
|
220
|
+
if (!lineEl.textContent || lineEl.matches('.status')) return false;
|
|
221
|
+
const ghost = plate.cloneNode(true), bar = [form, list, also, $('.ctrl')].find(el => !el.hidden);
|
|
222
|
+
ghost.querySelectorAll('form, .choices, .also, .ctrl, template, .next').forEach(el => el.remove());
|
|
223
|
+
ghost.querySelectorAll('*').forEach(el => [...el.attributes].forEach(a => { if (/^(id|role|tabindex|aria-.*)$/.test(a.name)) el.removeAttribute(a.name); }));
|
|
224
|
+
ghost.querySelector('.line').className = 'was';
|
|
225
|
+
ghost.className = 'plate gone';
|
|
226
|
+
ghost.inert = true;
|
|
227
|
+
ghost.ariaHidden = 'true';
|
|
228
|
+
const h = bar ? plate.clientTop + bar.offsetTop + 1 : plate.offsetHeight; // down to the input, which stays
|
|
229
|
+
Object.assign(ghost.style, { left: `${plate.offsetLeft}px`, width: `${plate.offsetWidth}px`, height: `${h}px`, bottom: `${dlg.clientHeight - plate.offsetTop - h}px` }); // anchored at the bottom: your box arriving above doesn't move it
|
|
230
|
+
ghost.addEventListener('animationend', e => e.target === ghost && ghost.remove());
|
|
231
|
+
dlg.append(ghost);
|
|
232
|
+
plate.classList.add('away');
|
|
233
|
+
lineEl.textContent = subEl.textContent = '';
|
|
234
|
+
cue();
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
const back = () => plate.classList.remove('away');
|
|
238
|
+
const stagger = moved ? 320 : 0; // Vega speaking again: one box after another
|
|
239
|
+
const LEAD = 80, GLIDE = 480, REVEAL = 380; // ms: Vega's box leads yours by a beat; Vega's new box starts as yours settles, and is in by about 680
|
|
240
|
+
// Your box: what you said, its first lines, with Show all when there is more. Plain text, never parsed
|
|
241
|
+
function yourBox(text) {
|
|
242
|
+
const el = document.createElement('div');
|
|
243
|
+
el.className = 'you';
|
|
244
|
+
el.innerHTML = '<b>You</b><p></p><button class="more" type="button" aria-expanded="false" hidden>Show all</button>';
|
|
245
|
+
el.querySelector('p').textContent = text;
|
|
246
|
+
return el;
|
|
247
|
+
}
|
|
248
|
+
const clamped = el => { const p = el.querySelector('p'); el.querySelector('.more').hidden = p.scrollHeight <= p.clientHeight + 1; };
|
|
249
|
+
yours.addEventListener('click', e => {
|
|
250
|
+
const b = e.target.closest('.more');
|
|
251
|
+
if (!b) return;
|
|
252
|
+
const on = b.parentElement.classList.toggle('open');
|
|
253
|
+
b.setAttribute('aria-expanded', on);
|
|
254
|
+
b.textContent = on ? 'Show less' : 'Show all';
|
|
255
|
+
});
|
|
256
|
+
addEventListener('resize', () => yours.querySelectorAll('.you:not(.open)').forEach(clamped));
|
|
257
|
+
// The message Vega is working on stays pinned above Vega's box until Vega replies to it; then it rises and fades
|
|
258
|
+
let pinned = null;
|
|
259
|
+
const drop = el => { el.style.animation = ''; el.classList.add('leaving'); setTimeout(() => el.remove(), 800); }; // the CSS leave runs again once the glide's hold on it is let go
|
|
260
|
+
function unpin() { if (pinned) drop(pinned); pinned = null; }
|
|
261
|
+
// Vega picks up a queued note: it leaves the chips and becomes the pinned box
|
|
262
|
+
function pin(text) {
|
|
263
|
+
unpin();
|
|
264
|
+
pinned = yourBox(text);
|
|
265
|
+
yours.append(pinned);
|
|
266
|
+
clamped(pinned);
|
|
267
|
+
}
|
|
268
|
+
// keep: the question stays in the box, because it still needs an answer. Otherwise Vega's next box is laid out now, still hidden, so yours lands where it will stay and nothing jumps after
|
|
269
|
+
async function you(text, keep = false) {
|
|
270
|
+
log('You', text);
|
|
271
|
+
const from = sentFrom?.text === text ? sentFrom : words(); // a send Vega skipped past leaves no stale start behind
|
|
272
|
+
sentFrom = null;
|
|
273
|
+
pinned = null;
|
|
274
|
+
const lifted = !keep && lift();
|
|
275
|
+
if (!keep) status('On it…', false);
|
|
276
|
+
const el = yourBox(text);
|
|
277
|
+
yours.replaceChildren(el);
|
|
278
|
+
clamped(el);
|
|
279
|
+
if (moved) { // FLIP: the box is in its final place; it starts where the words were in the input and glides there
|
|
280
|
+
const p = el.querySelector('p').getBoundingClientRect();
|
|
281
|
+
el.style.animation = 'none';
|
|
282
|
+
el.animate([{ translate: `${from.x - p.left}px ${from.y - p.top}px`, opacity: .5 }, { opacity: 1, offset: .2 }, { translate: '0 0', opacity: 1 }],
|
|
283
|
+
{ duration: GLIDE, delay: lifted ? LEAD : 0, easing: SEND, fill: 'backwards' });
|
|
284
|
+
}
|
|
285
|
+
if (keep) { await wait(moved ? GLIDE + 1300 : 1300); drop(el); await wait(moved ? 350 : 300); return; } // the options come after it has gone, so it never jumps
|
|
286
|
+
pinned = el; // stays through the whole of the work, and leaves when Vega replies
|
|
287
|
+
await wait(moved ? REVEAL : 0);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// ----- Vega's words. A message pages in the box when it is longer than a paragraph; each page types in and Enter shows the next. On a phone the box scrolls instead. The Log takes the whole message at once
|
|
291
|
+
function pages(text) {
|
|
292
|
+
if (phone.matches) return [text];
|
|
293
|
+
lineEl.className = 'line';
|
|
294
|
+
const max = say.clientHeight - parseFloat(getComputedStyle(say).paddingTop) - parseFloat(getComputedStyle(say).paddingBottom);
|
|
295
|
+
const out = [];
|
|
296
|
+
let cur = '';
|
|
297
|
+
for (const s of text.match(/[^.?!]+[.?!]+[”’")]*\s*|[^.?!]+$/g)) {
|
|
298
|
+
lineEl.textContent = cur + s;
|
|
299
|
+
if (cur && lineEl.offsetHeight > max) { out.push(cur.trim()); cur = s; } else cur += s;
|
|
300
|
+
}
|
|
301
|
+
out.push(cur.trim());
|
|
302
|
+
lineEl.textContent = '';
|
|
303
|
+
return out;
|
|
304
|
+
}
|
|
305
|
+
// Resolves with what the user sent if they sent something before the end, so the caller answers that instead.
|
|
306
|
+
// note: Vega is answering a queued note, which takes the pinned place while it does. Otherwise this is Vega's reply, and your box leaves
|
|
307
|
+
async function line(text, sub = '', note) {
|
|
308
|
+
if (note) pin(note); else unpin();
|
|
309
|
+
if (lift() && stagger) await wait(stagger); // no wait at all with reduced motion: a question lands in the same task
|
|
310
|
+
back();
|
|
311
|
+
room.classList.remove('busy');
|
|
312
|
+
log('Vega', text);
|
|
313
|
+
const all = pages(text);
|
|
314
|
+
for (const [i, page] of all.entries()) {
|
|
315
|
+
lineEl.className = 'line';
|
|
316
|
+
lineEl.textContent = page;
|
|
317
|
+
subEl.textContent = i === all.length - 1 ? sub : '';
|
|
318
|
+
lineEl.scrollTop = 0;
|
|
319
|
+
await typeLine(lineEl);
|
|
320
|
+
cue();
|
|
321
|
+
if (i === all.length - 1) break;
|
|
322
|
+
const sent = await more(`${i + 1}/${all.length}`);
|
|
323
|
+
if (sent === undefined) continue;
|
|
324
|
+
finishLine?.(); // sent before the end: the box skips to the last page, written at once
|
|
325
|
+
lineEl.textContent = all.at(-1);
|
|
326
|
+
subEl.textContent = sub;
|
|
327
|
+
cue();
|
|
328
|
+
return sent;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
// What Vega is doing, in the box: a short status in Vega's own voice, set apart from speech. On it… until there is a real step to name.
|
|
332
|
+
function status(text, show = true) {
|
|
333
|
+
if (show) back();
|
|
334
|
+
room.classList.add('busy');
|
|
335
|
+
lineEl.className = 'line status';
|
|
336
|
+
lineEl.textContent = text;
|
|
337
|
+
subEl.innerHTML = '<time aria-hidden="true">0:00</time>';
|
|
338
|
+
cue();
|
|
339
|
+
}
|
|
340
|
+
// The beat before anything happens: several seconds, never the same twice.
|
|
341
|
+
async function think(text = 'On it…') {
|
|
342
|
+
status(text);
|
|
343
|
+
const t = subEl.querySelector('time');
|
|
344
|
+
await pause(4000 + Math.random() * 4000, s => { t.textContent = clock(s); });
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Dialog options. Number keys come from mock.js. Your own words count as the recommended answer: the mock doesn't read them.
|
|
348
|
+
async function ask({ text, sub, choices, dismiss }) {
|
|
349
|
+
mine(false);
|
|
350
|
+
const sent = await line(text, sub) ?? early; // sent as the question landed: it shows as said, and is not an answer
|
|
351
|
+
early = null;
|
|
352
|
+
if (sent) await you(sent, true);
|
|
353
|
+
mine(true);
|
|
354
|
+
form.hidden = true;
|
|
355
|
+
list.hidden = also.hidden = false;
|
|
356
|
+
list.innerHTML = choices.map((c, i) => `<li><button class="choice${i ? '' : ' rec'}" type="button"><kbd>${i + 1}</kbd><strong>${c.name}${i ? '' : ' <em class="rec-mark">Recommended</em>'}</strong><span>${c.does}</span></button></li>`).join('');
|
|
357
|
+
also.innerHTML = '<button class="btn" type="button">Reply in your own words</button>' + (dismiss ? '<button class="btn" type="button">Dismiss</button>' : '');
|
|
358
|
+
list.focus({ preventScroll: true }); // the list, not an option: the next keystroke must not press Merge
|
|
359
|
+
const ready = armed();
|
|
360
|
+
const chosen = await new Promise(r => {
|
|
361
|
+
list.querySelectorAll('.choice').forEach((b, i) => { b.onclick = () => { if (ready()) r(choices[i]); }; });
|
|
362
|
+
also.children[0].onclick = async () => {
|
|
363
|
+
if (!ready()) return;
|
|
364
|
+
also.hidden = true;
|
|
365
|
+
form.hidden = false;
|
|
366
|
+
mine(true, 'Say it your way');
|
|
367
|
+
input.focus();
|
|
368
|
+
let words;
|
|
369
|
+
while (!(words = await hears()));
|
|
370
|
+
input.blur();
|
|
371
|
+
r({ ...choices[0], words });
|
|
372
|
+
};
|
|
373
|
+
if (dismiss) also.children[1].onclick = () => { if (ready()) r(dismiss); };
|
|
374
|
+
});
|
|
375
|
+
onSend = null;
|
|
376
|
+
list.hidden = also.hidden = true;
|
|
377
|
+
list.innerHTML = '';
|
|
378
|
+
form.hidden = false;
|
|
379
|
+
mine(false);
|
|
380
|
+
await you(chosen.words || chosen.name);
|
|
381
|
+
await think();
|
|
382
|
+
return chosen;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// ----- paper: a quest is the same item on the Bulletin and on the stage card
|
|
386
|
+
function quest({ n, project, text, small = '' }, target) {
|
|
387
|
+
target.insertAdjacentHTML('beforeend', `<section class="quest"><h2>${project}</h2><ol><li class="item" data-item="${n}"><b>${n}</b><div><p>${text}</p><small>${small}</small></div></li></ol></section>`);
|
|
388
|
+
}
|
|
389
|
+
function post(item) {
|
|
390
|
+
quest(item, quests);
|
|
391
|
+
foot.hidden = true;
|
|
392
|
+
badge(+count.textContent + 1);
|
|
393
|
+
}
|
|
394
|
+
function clear(n, note) {
|
|
395
|
+
document.querySelectorAll(`[data-item="${n}"]`).forEach(li => {
|
|
396
|
+
li.classList.remove('now');
|
|
397
|
+
li.querySelector('small').textContent = note;
|
|
398
|
+
li.insertAdjacentHTML('beforeend', `<label class="done"><input type="checkbox" checked disabled><i class="i i-tick"></i><span class="on">Cleared</span><span class="vh"> item ${n}</span></label>`);
|
|
399
|
+
});
|
|
400
|
+
badge(+count.textContent - 1);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// One ledger row per step. The box names the step in Vega's voice with step n of m, the one status there is; the ledger keeps the clock in real time.
|
|
404
|
+
async function work(steps) {
|
|
405
|
+
papers.hidden = false;
|
|
406
|
+
for (const [i, [now, done, secs]] of steps.entries()) {
|
|
407
|
+
status(`${now}… (step ${i + 1} of ${steps.length})`);
|
|
408
|
+
subEl.textContent = ''; // the clock is on the ledger
|
|
409
|
+
const li = document.createElement('li');
|
|
410
|
+
li.className = 'now';
|
|
411
|
+
li.innerHTML = `<i class="nib"></i>${now}<time aria-hidden="true">0:00</time>`;
|
|
412
|
+
rows.append(li);
|
|
413
|
+
ledger.hidden = false;
|
|
414
|
+
const time = li.querySelector('time');
|
|
415
|
+
await pause(secs * 1000, s => time.textContent = clock(s));
|
|
416
|
+
li.className = '';
|
|
417
|
+
li.innerHTML = `<i class="i i-tick"></i>${done}<time>${clock(secs)}</time>`;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function end(other, name) {
|
|
422
|
+
form.hidden = true;
|
|
423
|
+
$('.ctrl').hidden = false;
|
|
424
|
+
$('#other').href = `flow.html?flow=${other}`;
|
|
425
|
+
$('#other').textContent = name;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Paper unfurls once; coming back from a tab or from behind the options doesn't replay it.
|
|
429
|
+
[card, ledger, logbook].forEach(el => el.addEventListener('animationend', () => { el.style.animation = 'none'; }, { once: true }));
|
|
430
|
+
// The paper column ends above the plate and your box over it, however tall they grow
|
|
431
|
+
const fit = () => { room.style.setProperty('--plate', `${dlg.offsetHeight}px`); room.style.setProperty('--yh', `${yours.offsetHeight}px`); }; // your pinned box included; on a phone on Bulletin it sits over the stage (--yh), as on evidence
|
|
432
|
+
const sized = new ResizeObserver(fit); sized.observe(dlg); sized.observe(yours);
|
|
433
|
+
|
|
434
|
+
// ----- Flow 1: Chat
|
|
435
|
+
async function chat() {
|
|
436
|
+
view('home');
|
|
437
|
+
mine(true, 'Try: fix the login bug on the website');
|
|
438
|
+
if (matchMedia('(hover: hover)').matches) input.focus();
|
|
439
|
+
let said = await line('Hello. I\'m Vega, your steward. I look after your projects, the workers who do the building, and the bulletin you get twice a day. Tell me what needs doing in plain words and I\'ll make it a quest, put a worker on it and see it through. You\'ll only hear from me when something needs your decision, like a merge that deploys or anything that spends money.');
|
|
440
|
+
said ??= await hears();
|
|
441
|
+
said ||= 'Fix the login bug on the website';
|
|
442
|
+
input.blur(); // keys skip again, and a phone's keyboard drops
|
|
443
|
+
mine(false);
|
|
444
|
+
await you(said);
|
|
445
|
+
await think();
|
|
446
|
+
|
|
447
|
+
room.classList.add('working');
|
|
448
|
+
const item = { n: 1, project: 'website', text: 'Fix the login bug', small: 'Posted just now. A worker will take it.' };
|
|
449
|
+
card.hidden = false;
|
|
450
|
+
quest(item, card);
|
|
451
|
+
post(item);
|
|
452
|
+
await work([
|
|
453
|
+
['Posting the quest', 'Posted the quest', 2],
|
|
454
|
+
['Starting a worker', 'Started a worker', 3],
|
|
455
|
+
['Reading the login code', 'Read the login code', 9],
|
|
456
|
+
['Fixing the expired session check', 'Fixed the expired session check', 14],
|
|
457
|
+
['Running the tests', 'Ran the tests: all 14 green', 8],
|
|
458
|
+
['Opening the PR', 'Opened PR #58', 2],
|
|
459
|
+
]);
|
|
460
|
+
await answerQueue();
|
|
461
|
+
|
|
462
|
+
const answer = await ask({
|
|
463
|
+
text: 'Done, and it was the expired session check. When a session ran out, the site threw it away but never sent people back to sign in, so they got a blank page instead. The worker fixed the check, added a test for the expired case and ran the whole suite. I also read the two other places that look at the session, and neither has the same mistake. I also checked the sign-in page itself, since that is where people land after the redirect, and it loads cleanly with and without a saved session. The worker ran it in a fresh browser as well, with the cookie cleared halfway through, and the page sent it back to sign in each time. All 14 checks are green, and the change is two files in PR #58. Merging deploys it to production straight away, so I\'d rather you said yes than I assumed it. Merge it?',
|
|
464
|
+
sub: 'Expired sessions now go back to sign in.',
|
|
465
|
+
choices: [
|
|
466
|
+
{ name: 'Merge it', does: 'Goes to production now.' },
|
|
467
|
+
{ name: 'Show me first', does: 'Stays open until you\'ve seen the change.' },
|
|
468
|
+
],
|
|
469
|
+
});
|
|
470
|
+
if (answer.name === 'Merge it') {
|
|
471
|
+
await work([
|
|
472
|
+
['Merging into main', 'Merged into main', 3],
|
|
473
|
+
['Watching the deploy', 'Deployed to production', 11],
|
|
474
|
+
]);
|
|
475
|
+
clear(1, 'Merged. PR #58 is live.');
|
|
476
|
+
await line('It\'s live, and the quest is cleared. I watched the deploy reach production, then signed in with an expired session myself: it goes straight back to the sign-in form now. Nothing else is open for the website, and I\'ll put the fix in this afternoon\'s bulletin so you have it in writing.');
|
|
477
|
+
} else {
|
|
478
|
+
await line('Here\'s the change. It\'s two files: the session check, where an expired session now goes back to sign in instead of a blank page, and its test, which covers exactly that case. Nothing else moved. PR #58 stays open and nothing deploys until you say so; I\'ll ask again on the 15:30 bulletin.');
|
|
479
|
+
}
|
|
480
|
+
end('briefing', 'Flow 2: Bulletin');
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// ----- Flow 2: Bulletin
|
|
484
|
+
async function briefing() {
|
|
485
|
+
const items = [
|
|
486
|
+
{ n: 1, project: 'Needs you now: website', text: 'Merge PR #42? It deploys to production.', small: 'Dark mode for the settings page. CI is green.',
|
|
487
|
+
choices: [
|
|
488
|
+
{ name: 'Merge', does: 'Goes to production now.', ack: 'Merged. I\'ll watch the deploy and tell you if anything on the settings page looks wrong. The release goes out at noon with it in.' },
|
|
489
|
+
{ name: 'Wait', does: 'Stays open. I\'ll ask again at 15:30.', ack: 'It stays open, and the noon release goes without it. I\'ll ask again at 15:30.' } ] },
|
|
490
|
+
{ n: 2, project: 'mobile app', text: 'The sample-app.test domain is free. Buy it?', small: 'It spends money, so it comes to you.',
|
|
491
|
+
choices: [
|
|
492
|
+
{ name: 'Buy it', does: 'Bought today, on the usual card.', ack: 'Bought, on the usual card. I\'ve put the login in the project notes and a worker will point it at the app today.' },
|
|
493
|
+
{ name: 'Not yet', does: 'I\'ll look again next week.', ack: 'Leaving it for now. I\'ll check it\'s still free next week and ask again then.' } ] },
|
|
494
|
+
{ n: 3, project: 'billing', text: 'Two tests are flaky on main. Fix them this week?', small: 'They failed three runs out of twenty.',
|
|
495
|
+
choices: [
|
|
496
|
+
{ name: 'Fix them', does: 'A worker starts on it today.', ack: 'A worker starts on them today. Both time out on the same slow call, so I expect one fix covers the pair.' },
|
|
497
|
+
{ name: 'Leave it', does: 'They stay flaky. I\'ll keep count.', ack: 'Leaving them. I\'ll keep count, and if they fail more than one run in five I\'ll bring them back.' } ] },
|
|
498
|
+
];
|
|
499
|
+
items.forEach(post);
|
|
500
|
+
view('bulletin');
|
|
501
|
+
mine(true);
|
|
502
|
+
let said = await line('Morning. Since last time, two things finished: dark mode for the settings page is done and waiting on your merge, and the login fix went out yesterday and has been quiet since. Overnight the domain search came back, and the billing tests flaked again. That makes three things that need you. The merge comes first, because the release is at noon and it can\'t go without your yes.');
|
|
503
|
+
said ??= await more();
|
|
504
|
+
if (said) { input.blur(); mine(false); await you(said); await think(); }
|
|
505
|
+
for (const item of items) {
|
|
506
|
+
const now = document.querySelector(`[data-item="${item.n}"]`);
|
|
507
|
+
now.classList.add('now');
|
|
508
|
+
const board = $('#bulletin'); // it scrolls inside its slot: the item being asked about goes to its top, since the box grows under it once the options are up. Only the board moves, never the page
|
|
509
|
+
board.scrollTop += now.getBoundingClientRect().top - board.getBoundingClientRect().top;
|
|
510
|
+
const answer = await ask({ text: item.text, sub: item.small, choices: item.choices, dismiss: { name: 'Dismiss', ack: 'Dismissed. It won\'t come back, and nobody will work on it.' } });
|
|
511
|
+
clear(item.n, `You chose ${answer.name}.`);
|
|
512
|
+
await line(answer.ack);
|
|
513
|
+
await pause(beat);
|
|
514
|
+
}
|
|
515
|
+
foot.hidden = false;
|
|
516
|
+
foot.textContent = 'All clear. Next at 15:30.';
|
|
517
|
+
await line('That\'s the bulletin cleared. Nothing else needs you before 15:30, and I\'ll keep the workers going until then. Whatever you decided this morning is in the Log, so you can check what you said. If something comes up that can\'t wait, I\'ll find you.');
|
|
518
|
+
end('chat', 'Flow 1: Chat');
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const flow = new URLSearchParams(location.search).get('flow') === 'briefing' ? 'briefing' : 'chat';
|
|
522
|
+
document.title = `${flow === 'chat' ? 'Flow 1: Chat' : 'Flow 2: Bulletin'} · Star Quest mock`;
|
|
523
|
+
if (flow === 'chat') chat(); else briefing();
|