veycraft 2.8.2 → 2.8.4

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.
Files changed (136) hide show
  1. package/.agent/workflows/profile-update.md +8 -8
  2. package/.agents/skills/apply-url/SKILL.md +10 -10
  3. package/.agents/skills/contract-and-nda-auditor/SKILL.md +9 -9
  4. package/.agents/skills/daily-run/SKILL.md +10 -10
  5. package/.agents/skills/demo/SKILL.md +10 -10
  6. package/.agents/skills/github-cli-remote-manager/SKILL.md +10 -10
  7. package/.agents/skills/offer-negotiator/SKILL.md +9 -9
  8. package/.agents/skills/profile-intelligence-engine/SKILL.md +10 -10
  9. package/.agents/skills/recruiter-inbox-triage/SKILL.md +9 -9
  10. package/.agents/skills/rejection-pattern-analyzer/SKILL.md +9 -9
  11. package/.agents/skills/score-calibration/SKILL.md +9 -9
  12. package/.agents/skills/setup/SKILL.md +10 -10
  13. package/.agents/skills/tailor-cv/SKILL.md +10 -10
  14. package/.agents/skills/weekly-report/SKILL.md +10 -10
  15. package/.aiassistant/rules/AGENTS.md +11 -11
  16. package/.aider.conf.yml +5 -5
  17. package/.amazonq/rules/job-hunter.md +12 -12
  18. package/.augment/rules/job-hunter.md +17 -17
  19. package/.clinerules +14 -14
  20. package/.continue/rules/job-hunter.md +15 -15
  21. package/.cursor/rules/job-hunter.mdc +9 -9
  22. package/.github/CODEOWNERS +3 -3
  23. package/.github/copilot-instructions.md +5 -5
  24. package/.github/prompts/daily-run.prompt.md +10 -10
  25. package/.goosehints +12 -12
  26. package/.junie/guidelines.md +12 -12
  27. package/.kiro/steering/job-hunter.md +15 -15
  28. package/.openhands/microagents/repo.md +18 -18
  29. package/.roo/rules/job-hunter.md +12 -12
  30. package/.rules +12 -12
  31. package/.trae/rules/project_rules.md +10 -10
  32. package/.windsurfrules +14 -14
  33. package/AGENTS.md +126 -126
  34. package/AUTHORS.md +13 -13
  35. package/CHANGELOG.md +330 -320
  36. package/CLAUDE.md +22 -22
  37. package/CRUSH.md +12 -12
  38. package/GEMINI.md +42 -42
  39. package/HIRED.md +32 -32
  40. package/LICENSE +26 -26
  41. package/NOTICE +22 -22
  42. package/PLATFORMS.md +93 -93
  43. package/PROVENANCE.json +19 -19
  44. package/README.ar.md +5 -1
  45. package/README.md +5 -1
  46. package/WARP.md +12 -12
  47. package/adapters/apps/chatgpt-and-web-chats.md +18 -18
  48. package/adapters/apps/devin-desktop.md +13 -13
  49. package/adapters/apps/gemini-and-copilot.md +25 -25
  50. package/adapters/apps/hermes-pi-factory-openclaw.md +24 -24
  51. package/adapters/apps/openai-codex-cli.md +23 -23
  52. package/adapters/apps/opencode-and-kilocode.md +16 -16
  53. package/adapters/apps/qwen-mistral-kimi-deepseek.md +37 -37
  54. package/adapters/models/claude.md +28 -28
  55. package/adapters/models/gemini.md +16 -16
  56. package/adapters/models/grok-and-kimi.md +14 -14
  57. package/adapters/models/mistral-and-llama.md +13 -13
  58. package/adapters/models/openai.md +16 -16
  59. package/bin/cli.mjs +0 -0
  60. package/commands/profile-update.md +1 -1
  61. package/config/guardrails.yaml +67 -67
  62. package/config/invariants.txt +7 -7
  63. package/context/DROP_YOUR_FILES_HERE.md +9 -9
  64. package/context/cv.md.example +12 -12
  65. package/context/form-answers.yaml.example +45 -45
  66. package/context/preferences.yaml.example +15 -15
  67. package/context/profile.md.example +20 -20
  68. package/context/readiness-state.json.example +64 -64
  69. package/context/resume-data.json.example +29 -29
  70. package/context/resume-facts.json.example +1 -1
  71. package/context/targets.yaml.example +433 -433
  72. package/docs/ARCHITECTURE.md +106 -106
  73. package/docs/OPTIONAL_MCP_PLUGINS.md +49 -49
  74. package/docs/SKILL_CATALOG.md +73 -73
  75. package/docs/chat-commands.md +33 -33
  76. package/docs/demo-dashboard.html +646 -646
  77. package/docs/execution-safety.md +34 -34
  78. package/docs/index.html +637 -637
  79. package/docs/platform-registry.md +23 -23
  80. package/evals/PROMPT.md +31 -31
  81. package/evals/README.md +36 -36
  82. package/evals/RUBRIC.md +51 -51
  83. package/evals/fixtures/boards/bayt-mock.html +255 -255
  84. package/evals/fixtures/boards/gulftalent-mock.html +250 -250
  85. package/evals/fixtures/boards/naukri-mock.html +262 -262
  86. package/evals/fixtures/boards/stepstone-mock.html +245 -245
  87. package/evals/fixtures/forms/workday-mock.html +328 -328
  88. package/evals/fixtures/ground-truth.json +53 -53
  89. package/evals/journeys/journey-matrix.json +333 -333
  90. package/evals/results/baseline-verified-run.json +125 -125
  91. package/llms.txt +70 -70
  92. package/package.json +115 -115
  93. package/prompts/partials/pacing.md +8 -8
  94. package/prompts/partials/snapshot-first.md +4 -4
  95. package/prompts/partials/stop-conditions.md +5 -5
  96. package/schemas/profile-update-plan.schema.json +133 -133
  97. package/schemas/readiness.schema.json +484 -484
  98. package/schemas/resume-data.schema.json +171 -171
  99. package/scripts/install.sh +0 -0
  100. package/skills/00-interrogate-and-onboard.md +87 -87
  101. package/skills/02-discover-and-triage.md +121 -121
  102. package/skills/03-tailor-resume-and-verify.md +114 -114
  103. package/skills/04-fill-and-apply.md +108 -108
  104. package/skills/07-persona-switcher.md +61 -61
  105. package/skills/18-condition-based-browser-waiting.md +65 -65
  106. package/skills/20-skill-authoring-standard.md +61 -61
  107. package/skills/21-ats-keyword-heatmap.md +60 -60
  108. package/skills/27-universal-cv-builder.md +99 -99
  109. package/skills/28-recruiter-brand-and-domain-intelligence.md +99 -99
  110. package/skills/54-github-cli-remote-manager.md +144 -144
  111. package/skills/REGISTRY.md +98 -98
  112. package/skills/ats/ashby.md +54 -54
  113. package/skills/ats/breezyhr.md +54 -54
  114. package/skills/ats/greenhouse.md +54 -54
  115. package/skills/ats/lever.md +54 -54
  116. package/skills/ats/smartrecruiters.md +54 -54
  117. package/skills/ats/taleo.md +43 -43
  118. package/skills/ats/workday.md +49 -49
  119. package/skills/meta-context-compaction.md +88 -88
  120. package/skills/meta-dom-recovery.md +63 -63
  121. package/skills/meta-self-verification.md +75 -75
  122. package/skills/meta-structured-debugging.md +69 -69
  123. package/skills/platforms/_template.md +69 -69
  124. package/skills/platforms/ats-engines.md +67 -67
  125. package/skills/platforms/global-boards.md +122 -122
  126. package/skills/platforms/linkedin.md +162 -162
  127. package/skills/platforms/mena-boards.md +99 -99
  128. package/skills/platforms/remote-boards.md +64 -64
  129. package/skills/platforms/wellfound.md +59 -59
  130. package/skills/profile-intelligence-engine.md +98 -98
  131. package/skills/skills-manifest.json +1730 -1730
  132. package/templates/analytics-dashboard.html +1106 -1106
  133. package/templates/ats-cover-letter-template.html +29 -29
  134. package/templates/ats-resume-template.html +38 -38
  135. package/templates/ats-resume.html +3 -3
  136. package/ui/app.js +1113 -1113
package/ui/app.js CHANGED
@@ -1,1113 +1,1113 @@
1
- // Zero-dependency Veycraft Read-Only Local UI client.
2
- // Strictly uses document.createElement / textContent / replaceChildren only.
3
-
4
- const state = {
5
- activeTab: 'overview',
6
- studioSubtab: 'route',
7
- overview: null,
8
- applications: null,
9
- analytics: null,
10
- analyticsPeriod: 'all',
11
- skillsManifest: null,
12
- selectedSkillName: null,
13
- skillCache: new Map(),
14
- kanbanQuery: '',
15
- kanbanPlatform: 'all',
16
- kanbanCv: 'all',
17
- skillsQuery: '',
18
- skillsCategory: 'all',
19
- skillsMcp: 'all',
20
- };
21
-
22
- const SAFE_ATTRS = new Set([
23
- 'id', 'type', 'role', 'value', 'max', 'min', 'placeholder',
24
- 'aria-label', 'aria-selected', 'aria-live', 'for', 'name',
25
- 'rows', 'cols', 'disabled', 'selected', 'checked', 'title',
26
- ]);
27
-
28
- function h(tag, props = null, ...children) {
29
- const node = document.createElement(tag);
30
- if (props) {
31
- for (const [k, v] of Object.entries(props)) {
32
- if (v === undefined || v === null || v === false) continue;
33
- if (k === 'className') {
34
- node.className = String(v);
35
- } else if (k === 'text') {
36
- node.textContent = String(v);
37
- } else if (k === 'onClick') {
38
- node.addEventListener('click', v);
39
- } else if (k === 'onInput') {
40
- node.addEventListener('input', v);
41
- } else if (k === 'onChange') {
42
- node.addEventListener('change', v);
43
- } else if (k === 'href') {
44
- const str = String(v).trim();
45
- if (/^https?:\/\//i.test(str)) {
46
- node.setAttribute('href', str);
47
- node.setAttribute('target', '_blank');
48
- node.setAttribute('rel', 'noopener noreferrer');
49
- }
50
- } else if (k === 'dataset' && typeof v === 'object') {
51
- for (const [dk, dv] of Object.entries(v)) {
52
- node.dataset[dk] = String(dv);
53
- }
54
- } else if (SAFE_ATTRS.has(k)) {
55
- if (v === true) node.setAttribute(k, '');
56
- else node.setAttribute(k, String(v));
57
- }
58
- }
59
- }
60
- appendChildren(node, children);
61
- return node;
62
- }
63
-
64
- function appendChildren(parent, items) {
65
- for (const item of items) {
66
- if (item === null || item === undefined || item === false) continue;
67
- if (Array.isArray(item)) {
68
- appendChildren(parent, item);
69
- } else if (item instanceof Node) {
70
- parent.appendChild(item);
71
- } else {
72
- parent.appendChild(document.createTextNode(String(item)));
73
- }
74
- }
75
- }
76
-
77
- function renderInlineCodeSegments(text) {
78
- const str = String(text || '');
79
- const parts = str.split(/(`[^`]+`)/g);
80
- const frag = document.createDocumentFragment();
81
- for (const part of parts) {
82
- if (part.length >= 2 && part.startsWith('`') && part.endsWith('`')) {
83
- frag.appendChild(h('code', { className: 'md-inline-code', text: part.slice(1, -1) }));
84
- } else if (part) {
85
- frag.appendChild(document.createTextNode(part));
86
- }
87
- }
88
- return frag;
89
- }
90
-
91
- function renderMarkdownSafe(markdownText) {
92
- const container = h('div', { className: 'md-body' });
93
- const lines = String(markdownText || '').replace(/\r\n/g, '\n').split('\n');
94
- let i = 0;
95
-
96
- // Skip optional YAML frontmatter block cleanly into a compact metadata pre
97
- if (lines[0] === '---') {
98
- const endIdx = lines.indexOf('---', 1);
99
- if (endIdx > 0) {
100
- i = endIdx + 1;
101
- }
102
- }
103
-
104
- while (i < lines.length) {
105
- const line = lines[i];
106
- if (!line.trim()) {
107
- i++;
108
- continue;
109
- }
110
- if (line.startsWith('```')) {
111
- const codeLines = [];
112
- i++;
113
- while (i < lines.length && !lines[i].startsWith('```')) {
114
- codeLines.push(lines[i]);
115
- i++;
116
- }
117
- i++;
118
- container.appendChild(h('pre', { className: 'code-snippet', text: codeLines.join('\n') }));
119
- continue;
120
- }
121
- const headingMatch = line.match(/^(#{1,4})\s+(.+)$/);
122
- if (headingMatch) {
123
- const level = Math.min(4, headingMatch[1].length);
124
- container.appendChild(h(`h${level}`, null, renderInlineCodeSegments(headingMatch[2])));
125
- i++;
126
- continue;
127
- }
128
- if (line.startsWith('>')) {
129
- const quoteLines = [];
130
- while (i < lines.length && lines[i].startsWith('>')) {
131
- quoteLines.push(lines[i].replace(/^>\s?/, ''));
132
- i++;
133
- }
134
- container.appendChild(h('blockquote', null, renderInlineCodeSegments(quoteLines.join(' '))));
135
- continue;
136
- }
137
- if (/^\s*[-*]\s+/.test(line)) {
138
- const ul = h('ul');
139
- while (i < lines.length && /^\s*[-*]\s+/.test(lines[i])) {
140
- ul.appendChild(h('li', null, renderInlineCodeSegments(lines[i].replace(/^\s*[-*]\s+/, ''))));
141
- i++;
142
- }
143
- container.appendChild(ul);
144
- continue;
145
- }
146
- if (/^\s*\d+\.\s+/.test(line)) {
147
- const ol = h('ol');
148
- while (i < lines.length && /^\s*\d+\.\s+/.test(lines[i])) {
149
- ol.appendChild(h('li', null, renderInlineCodeSegments(lines[i].replace(/^\s*\d+\.\s+/, ''))));
150
- i++;
151
- }
152
- container.appendChild(ol);
153
- continue;
154
- }
155
- if (line.includes('|') && i + 1 < lines.length && /^\s*\|?[\s:-]+\|/.test(lines[i + 1])) {
156
- const parseCells = (row) => row.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map((c) => c.trim());
157
- const headers = parseCells(line);
158
- i += 2;
159
- const rows = [];
160
- while (i < lines.length && lines[i].includes('|') && lines[i].trim()) {
161
- rows.push(parseCells(lines[i]));
162
- i++;
163
- }
164
- const table = h('table', { className: 'data-table' },
165
- h('thead', null, h('tr', null, headers.map((hd) => h('th', { text: hd })))),
166
- h('tbody', null, rows.map((r) => h('tr', null, r.map((cell) => h('td', null, renderInlineCodeSegments(cell)))))),
167
- );
168
- container.appendChild(h('div', { className: 'table-wrap' }, table));
169
- continue;
170
- }
171
- container.appendChild(h('p', null, renderInlineCodeSegments(line)));
172
- i++;
173
- }
174
- return container;
175
- }
176
-
177
- let toastTimer = null;
178
- function showToast(msg) {
179
- const el = document.getElementById('global-toast');
180
- if (!el) return;
181
- el.textContent = msg;
182
- el.classList.remove('hidden');
183
- if (toastTimer) clearTimeout(toastTimer);
184
- toastTimer = setTimeout(() => el.classList.add('hidden'), 2600);
185
- }
186
-
187
- async function copyText(str, label = 'Copied to clipboard') {
188
- try {
189
- await navigator.clipboard.writeText(str);
190
- showToast(`${label}`);
191
- } catch {
192
- showToast(`Copy value: ${str}`);
193
- }
194
- }
195
-
196
- async function apiGet(url) {
197
- const res = await fetch(url, { headers: { Accept: 'application/json' } });
198
- const data = await res.json();
199
- if (!res.ok || !data.ok) {
200
- throw new Error(data?.error?.message || `HTTP ${res.status}`);
201
- }
202
- return data;
203
- }
204
-
205
- async function apiPost(url, bodyObj) {
206
- const res = await fetch(url, {
207
- method: 'POST',
208
- headers: {
209
- 'Content-Type': 'application/json',
210
- Accept: 'application/json',
211
- },
212
- body: JSON.stringify(bodyObj),
213
- });
214
- const data = await res.json();
215
- if (!res.ok || !data.ok) {
216
- throw new Error(data?.error?.message || `HTTP ${res.status}`);
217
- }
218
- return data;
219
- }
220
-
221
- function statusPillClass(levelOrStatus) {
222
- const s = String(levelOrStatus || '').toLowerCase();
223
- if (s === 'ok' || s === 'applied' || s === 'offer' || s === 'pass') return 'pill pill-emerald';
224
- if (s === 'interview' || s === 'assessment' || s === 'info' || s === 'prepared') return 'pill pill-blue';
225
- if (s === 'warn' || s === 'needs_review' || s === 'dry_run' || s === 'discovered') return 'pill pill-amber';
226
- if (s === 'fail' || s === 'failed' || s === 'aborted' || s === 'rejected') return 'pill pill-rose';
227
- return 'pill pill-slate';
228
- }
229
-
230
- function switchTab(tabName) {
231
- state.activeTab = tabName;
232
- for (const btn of document.querySelectorAll('.tab-btn')) {
233
- const active = btn.dataset.tab === tabName;
234
- btn.classList.toggle('active', active);
235
- btn.setAttribute('aria-selected', active ? 'true' : 'false');
236
- }
237
- for (const name of ['overview', 'kanban', 'analytics', 'studio', 'skills']) {
238
- const panel = document.getElementById(`view-${name}`);
239
- if (panel) panel.classList.toggle('hidden', name !== tabName);
240
- }
241
- if (tabName === 'kanban' && !state.applications) loadKanban();
242
- if (tabName === 'analytics' && !state.analytics) loadAnalytics(state.analyticsPeriod);
243
- if (tabName === 'studio') renderStudio();
244
- if (tabName === 'skills' && !state.skillsManifest) loadSkills();
245
- }
246
-
247
- // ---------------- VIEW 1: OVERVIEW ----------------
248
- function renderOverview() {
249
- const panel = document.getElementById('view-overview');
250
- if (!panel || !state.overview) return;
251
-
252
- const { meta, doctor, summary, next, ledger_health: ledgerHealth } = state.overview;
253
- const docPayload = doctor.payload;
254
- const gates = docPayload.gates || { passed: 0, total: 4 };
255
- const funnel = summary?.funnel || { total_tracked: 0, submitted_count: 0 };
256
-
257
- document.getElementById('version-badge').textContent = `v${meta.version}`;
258
- document.getElementById('workspace-subtitle').textContent = `${meta.workspace_root} (${meta.scope} workspace · ${meta.zero_dependencies.runtime}/${meta.zero_dependencies.dev} npm deps)`;
259
-
260
- const nodes = [];
261
-
262
- if (!docPayload.initialized) {
263
- nodes.push(
264
- h('div', { className: 'banner banner-onboarding' },
265
- h('div', { className: 'card-header' },
266
- h('strong', { text: 'Workspace Not Initialized Yet — Start Safely in 15 Seconds' }),
267
- h('span', { className: 'pill pill-blue', text: 'ZERO LOGIN NEEDED' }),
268
- ),
269
- h('p', { className: 'muted-text', text: 'Standalone tasks (/demo, /quick-tailor, CV hygiene audit, routing, and skill browsing) work right now with zero setup. Initialize ~/.veycraft whenever you want persistent tracking.' }),
270
- h('div', { className: 'filter-bar' },
271
- h('button', { className: 'btn btn-primary btn-sm', text: 'Copy: npx veycraft init --global', onClick: () => copyText('npx veycraft init --global', 'Copied init --global command') }),
272
- h('button', { className: 'btn btn-sm', text: 'Try Verification Studio', onClick: () => switchTab('studio') }),
273
- h('button', { className: 'btn btn-sm', text: 'Browse 56 Skills', onClick: () => switchTab('skills') }),
274
- ),
275
- ),
276
- );
277
- }
278
-
279
- if (ledgerHealth?.error) {
280
- nodes.push(h('div', { className: 'banner banner-error', text: `Ledger Notice: ${ledgerHealth.error}` }));
281
- }
282
-
283
- nodes.push(
284
- h('div', { className: 'kpi-grid' },
285
- h('div', { className: 'kpi-card' },
286
- h('div', { className: 'kpi-value', text: `${gates.passed}/${gates.total}` }),
287
- h('div', { className: 'kpi-label', text: 'Readiness Gates' }),
288
- h('div', { className: 'kpi-sub', text: docPayload.initialized ? 'Initialized workspace' : 'Standalone mode ready' }),
289
- ),
290
- h('div', { className: 'kpi-card' },
291
- h('div', { className: 'kpi-value', text: String(funnel.total_tracked || 0) }),
292
- h('div', { className: 'kpi-label', text: 'Owner Apps Tracked' }),
293
- h('div', { className: 'kpi-sub', text: `${funnel.submitted_count || 0} submitted` }),
294
- ),
295
- h('div', { className: 'kpi-card' },
296
- h('div', { className: 'kpi-value', text: String((summary?.active_interviews || 0) + (summary?.active_assessments || 0)) }),
297
- h('div', { className: 'kpi-label', text: 'Active Interviews / Tests' }),
298
- h('div', { className: 'kpi-sub', text: `${summary?.active_interviews || 0} interviews · ${summary?.active_assessments || 0} assessments` }),
299
- ),
300
- h('div', { className: 'kpi-card' },
301
- h('div', { className: 'kpi-value', text: String(summary?.overdue_follow_ups_count || 0) }),
302
- h('div', { className: 'kpi-label', text: 'Overdue Follow-Ups' }),
303
- h('div', { className: 'kpi-sub', text: `${docPayload.skills_count || 56} Markdown skills loaded` }),
304
- ),
305
- ),
306
- );
307
-
308
- const gateItems = [
309
- ['Gate 1 · CV & Profile', gates.cv_and_profile],
310
- ['Gate 2 · Target Preferences', gates.target_preferences],
311
- ['Gate 3/4 · Legal, Comp & Skills', gates.legal_comp_skills],
312
- ['Gate 5 · Enabled Job Targets', gates.enabled_targets],
313
- ['Browser Profile Directory', docPayload.browser_profile_present],
314
- ['Provenance & Attribution', docPayload.provenance_verified],
315
- ];
316
-
317
- const gatesCard = h('div', { className: 'card' },
318
- h('div', { className: 'card-header' },
319
- h('h2', { className: 'card-title', text: 'Readiness & Safety Gates' }),
320
- h('span', { className: docPayload.ok ? 'pill pill-emerald' : 'pill pill-amber', text: docPayload.ok ? 'DOCTOR OK' : `${docPayload.readiness_pending} PENDING` }),
321
- ),
322
- h('div', { className: 'list-stack' },
323
- gateItems.map(([label, ok]) =>
324
- h('div', { className: 'list-row' },
325
- h('span', { text: label }),
326
- h('span', { className: ok ? 'pill pill-emerald' : 'pill pill-amber', text: ok ? 'READY' : 'PENDING' }),
327
- ),
328
- ),
329
- ),
330
- );
331
-
332
- const actions = Array.isArray(next?.prioritized_actions) ? next.prioritized_actions.slice(0, 6) : [];
333
- const nextCard = h('div', { className: 'card' },
334
- h('div', { className: 'card-header' },
335
- h('h2', { className: 'card-title', text: 'Prioritized Next Actions' }),
336
- h('span', { className: 'pill pill-blue', text: `${actions.length} QUEUED` }),
337
- ),
338
- actions.length === 0
339
- ? h('p', { className: 'muted-text', text: 'No urgent blockers or overdue follow-ups. Start with /demo, /quick-tailor, or Verification Studio.' })
340
- : h('div', { className: 'list-stack' },
341
- actions.map((act) =>
342
- h('div', { className: 'list-row' },
343
- h('div', null,
344
- h('div', { text: act.title || act.summary || act.kind || 'Recommended Action' }),
345
- act.recommended_command ? h('div', { className: 'subtitle', text: act.recommended_command }) : null,
346
- ),
347
- act.recommended_command
348
- ? h('button', {
349
- className: 'btn btn-sm',
350
- text: 'Copy Cmd',
351
- onClick: () => copyText(act.recommended_command, 'Copied recommended command'),
352
- })
353
- : null,
354
- ),
355
- ),
356
- ),
357
- );
358
-
359
- nodes.push(h('div', { className: 'two-col' }, gatesCard, nextCard));
360
-
361
- const mcpSnippet = JSON.stringify({
362
- mcpServers: {
363
- veycraft: {
364
- command: 'npx',
365
- args: ['-y', 'veycraft', 'mcp'],
366
- },
367
- },
368
- }, null, 2);
369
-
370
- nodes.push(
371
- h('div', { className: 'card' },
372
- h('div', { className: 'card-header' },
373
- h('div', null,
374
- h('h2', { className: 'card-title', text: 'Connect Your IDE (Native MCP Server)' }),
375
- h('p', { className: 'muted-text', text: 'Expose 8 read-only offline tools and allowlisted veycraft:// skill resources over stdio.' }),
376
- ),
377
- h('div', { className: 'filter-bar' },
378
- h('button', {
379
- className: 'btn btn-primary btn-sm',
380
- text: 'Copy mcpServers JSON',
381
- onClick: () => copyText(mcpSnippet, 'Copied mcpServers JSON snippet'),
382
- }),
383
- h('button', {
384
- className: 'btn btn-sm',
385
- text: 'Copy: veycraft sync-mcp --with-veycraft',
386
- onClick: () => copyText('npx veycraft sync-mcp --with-veycraft', 'Copied sync-mcp --with-veycraft command'),
387
- }),
388
- ),
389
- ),
390
- h('pre', { className: 'code-snippet', text: mcpSnippet }),
391
- ),
392
- );
393
-
394
- nodes.push(
395
- h('div', { className: 'card' },
396
- h('div', { className: 'card-header' },
397
- h('h2', { className: 'card-title', text: 'Offline Doctor Diagnostic Events' }),
398
- h('span', { className: 'pill pill-slate', text: 'offline: true · readOnly: true' }),
399
- ),
400
- h('div', { className: 'list-stack' },
401
- (doctor.events || []).map((ev) =>
402
- h('div', { className: 'list-row' },
403
- h('span', { text: ev.message }),
404
- h('span', { className: statusPillClass(ev.level), text: String(ev.level).toUpperCase() }),
405
- ),
406
- ),
407
- ),
408
- ),
409
- );
410
-
411
- panel.replaceChildren(...nodes);
412
- }
413
-
414
- // ---------------- VIEW 2: KANBAN ----------------
415
- async function loadKanban() {
416
- const panel = document.getElementById('view-kanban');
417
- if (!panel) return;
418
- panel.replaceChildren(h('div', { className: 'card', text: 'Loading read-only application ledger...' }));
419
- try {
420
- state.applications = await apiGet('/api/applications');
421
- renderKanban();
422
- } catch (err) {
423
- panel.replaceChildren(h('div', { className: 'banner banner-error', text: `Failed loading applications: ${err.message}` }));
424
- }
425
- }
426
-
427
- function openApplicationDrawer(card) {
428
- const drawer = document.getElementById('detail-drawer');
429
- if (!drawer) return;
430
- drawer.classList.remove('hidden');
431
- drawer.replaceChildren(
432
- h('div', { className: 'card-header' },
433
- h('h2', { className: 'card-title', text: `${card.company} — ${card.role_title}` }),
434
- h('button', { className: 'btn btn-sm', text: 'Close', onClick: () => drawer.classList.add('hidden') }),
435
- ),
436
- h('div', { className: 'filter-bar' },
437
- h('span', { className: statusPillClass(card.status), text: card.status }),
438
- card.match_score !== null ? h('span', { className: 'pill pill-emerald', text: `Score: ${card.match_score}/10` }) : null,
439
- card.has_verified_receipt ? h('span', { className: 'pill pill-blue', text: 'Receipt Verified' }) : null,
440
- card.submission_uncertain ? h('span', { className: 'pill pill-amber', text: 'Submission Uncertain' }) : null,
441
- ),
442
- h('div', { className: 'list-stack' },
443
- h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'Application ID' }), h('code', { className: 'md-inline-code', text: card.application_id })),
444
- card.job_id ? h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'Job ID' }), h('code', { className: 'md-inline-code', text: card.job_id })) : null,
445
- h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'Platform / Channel' }), h('span', { text: `${card.platform} (${card.source_channel})` })),
446
- card.cv_version_id ? h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'CV Version' }), h('code', { className: 'md-inline-code', text: card.cv_version_id })) : null,
447
- card.applied_at ? h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'Applied At' }), h('span', { text: card.applied_at })) : null,
448
- card.url ? h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'Posting URL' }), h('a', { className: 'btn btn-sm', href: card.url, text: 'Open Posting' })) : null,
449
- ),
450
- card.matched_skills.length > 0
451
- ? h('div', { className: 'card', text: '' },
452
- h('h3', { className: 'card-title', text: 'Matched Skills' }),
453
- h('div', { className: 'filter-bar' }, card.matched_skills.map((s) => h('span', { className: 'pill pill-emerald', text: s }))),
454
- )
455
- : null,
456
- card.true_gaps.length > 0
457
- ? h('div', { className: 'card' },
458
- h('h3', { className: 'card-title', text: 'Isolated True Gaps' }),
459
- h('div', { className: 'filter-bar' }, card.true_gaps.map((s) => h('span', { className: 'pill pill-amber', text: s }))),
460
- )
461
- : null,
462
- card.notes
463
- ? h('div', { className: 'card' },
464
- h('h3', { className: 'card-title', text: 'Ledger Notes' }),
465
- h('pre', { className: 'code-snippet', text: card.notes }),
466
- )
467
- : null,
468
- );
469
- }
470
-
471
- function renderKanban() {
472
- const panel = document.getElementById('view-kanban');
473
- if (!panel || !state.applications) return;
474
-
475
- const { kanban, cv_versions: cvVersions, lock, transaction } = state.applications;
476
- const allItems = kanban.items || [];
477
- const platforms = [...new Set(allItems.map((i) => i.platform))].sort();
478
- const cvs = (cvVersions?.versions || []).map((v) => v.cv_version_id);
479
-
480
- const q = state.kanbanQuery.trim().toLowerCase();
481
- const matchesFilter = (item) => {
482
- if (state.kanbanPlatform !== 'all' && item.platform !== state.kanbanPlatform) return false;
483
- if (state.kanbanCv !== 'all' && item.cv_version_id !== state.kanbanCv) return false;
484
- if (!q) return true;
485
- return (
486
- item.company.toLowerCase().includes(q) ||
487
- item.role_title.toLowerCase().includes(q) ||
488
- (item.job_id || '').toLowerCase().includes(q) ||
489
- item.matched_skills.some((s) => s.toLowerCase().includes(q))
490
- );
491
- };
492
-
493
- const filterBar = h('div', { className: 'filter-bar' },
494
- h('input', {
495
- className: 'input',
496
- type: 'text',
497
- placeholder: 'Search company, role, job_id, skill...',
498
- value: state.kanbanQuery,
499
- onInput: (e) => {
500
- state.kanbanQuery = e.target.value;
501
- renderKanbanBoardOnly();
502
- },
503
- }),
504
- h('select', {
505
- className: 'select',
506
- onChange: (e) => {
507
- state.kanbanPlatform = e.target.value;
508
- renderKanbanBoardOnly();
509
- },
510
- },
511
- h('option', { value: 'all', text: 'All Platforms', selected: state.kanbanPlatform === 'all' }),
512
- platforms.map((p) => h('option', { value: p, text: p, selected: state.kanbanPlatform === p })),
513
- ),
514
- h('select', {
515
- className: 'select',
516
- onChange: (e) => {
517
- state.kanbanCv = e.target.value;
518
- renderKanbanBoardOnly();
519
- },
520
- },
521
- h('option', { value: 'all', text: 'All Owner CV Versions', selected: state.kanbanCv === 'all' }),
522
- cvs.map((id) => h('option', { value: id, text: id, selected: state.kanbanCv === id })),
523
- ),
524
- kanban.third_party_excluded > 0
525
- ? h('span', { className: 'pill pill-blue', text: `Isolated ${kanban.third_party_excluded} third-party record(s)` })
526
- : null,
527
- lock?.locked ? h('span', { className: 'pill pill-amber', text: 'Ledger Lock Active' }) : h('span', { className: 'pill pill-emerald', text: 'Ledger Lock Clear' }),
528
- transaction?.pending ? h('span', { className: 'pill pill-rose', text: 'Pending Journal Tx' }) : null,
529
- );
530
-
531
- const boardMount = h('div', { id: 'kanban-board-mount' });
532
- panel.replaceChildren(filterBar, boardMount);
533
-
534
- function renderKanbanBoardOnly() {
535
- const mount = document.getElementById('kanban-board-mount');
536
- if (!mount) return;
537
- if (allItems.length === 0) {
538
- mount.replaceChildren(
539
- h('div', { className: 'card' },
540
- h('h2', { className: 'card-title', text: 'No Owner Applications Logged Yet' }),
541
- h('p', { className: 'muted-text', text: 'logs/applications-log.json has 0 owner records in this workspace. Run /demo, /apply-url, or veycraft career record to populate your pipeline.' }),
542
- ),
543
- );
544
- return;
545
- }
546
-
547
- const cols = kanban.column_definitions.map((colDef) => {
548
- const colCards = (kanban.columns[colDef.id] || []).filter(matchesFilter);
549
- return h('div', { className: 'kanban-col' },
550
- h('div', { className: 'kanban-col-header' },
551
- h('span', { text: colDef.label }),
552
- h('span', { className: 'pill pill-slate', text: String(colCards.length) }),
553
- ),
554
- h('div', { className: 'kanban-cards' },
555
- colCards.map((card) =>
556
- h('button', { className: 'app-card', type: 'button', onClick: () => openApplicationDrawer(card) },
557
- h('div', { className: 'app-card-company', text: card.company }),
558
- h('div', { className: 'app-card-role', text: card.role_title }),
559
- h('div', { className: 'app-card-meta' },
560
- h('span', { className: statusPillClass(card.status), text: card.status }),
561
- h('span', { className: 'pill pill-slate', text: card.platform }),
562
- card.match_score !== null ? h('span', { className: 'pill pill-emerald', text: `${card.match_score}` }) : null,
563
- card.has_verified_receipt ? h('span', { className: 'pill pill-blue', text: 'Receipt' }) : null,
564
- ),
565
- ),
566
- ),
567
- ),
568
- );
569
- });
570
-
571
- mount.replaceChildren(h('div', { className: 'kanban-board' }, cols));
572
- }
573
-
574
- renderKanbanBoardOnly();
575
- }
576
-
577
- // ---------------- VIEW 3: ANALYTICS ----------------
578
- async function loadAnalytics(period = 'all') {
579
- const panel = document.getElementById('view-analytics');
580
- if (!panel) return;
581
- state.analyticsPeriod = period;
582
- panel.replaceChildren(h('div', { className: 'card', text: `Computing deterministic analytics (${period})...` }));
583
- try {
584
- const res = await apiGet(`/api/analytics?period=${encodeURIComponent(period)}`);
585
- state.analytics = res.analytics;
586
- renderAnalytics();
587
- } catch (err) {
588
- panel.replaceChildren(h('div', { className: 'banner banner-error', text: `Analytics error: ${err.message}` }));
589
- }
590
- }
591
-
592
- function formatRateCell(rateObj) {
593
- if (!rateObj || !rateObj.sample_sufficient || rateObj.rate_pct === null) {
594
- return `n=${rateObj?.denominator ?? 0} (< MIN_N)`;
595
- }
596
- return `${rateObj.rate_pct}% (${rateObj.numerator}/${rateObj.denominator})`;
597
- }
598
-
599
- function renderAnalytics() {
600
- const panel = document.getElementById('view-analytics');
601
- if (!panel || !state.analytics) return;
602
-
603
- const a = state.analytics;
604
- const f = a.funnel;
605
- const suff = a.sample_sufficiency;
606
- const monthlyPeriods = (a.timing?.activity?.monthly || []).map((m) => m.period).reverse();
607
-
608
- const periodBar = h('div', { className: 'filter-bar' },
609
- h('span', { className: 'field-label', text: 'Period:' }),
610
- h('button', {
611
- className: `subtab-btn ${state.analyticsPeriod === 'all' ? 'active' : ''}`,
612
- text: 'All-Time',
613
- onClick: () => loadAnalytics('all'),
614
- }),
615
- monthlyPeriods.slice(0, 6).map((p) =>
616
- h('button', {
617
- className: `subtab-btn ${state.analyticsPeriod === p ? 'active' : ''}`,
618
- text: p,
619
- onClick: () => loadAnalytics(p),
620
- }),
621
- ),
622
- );
623
-
624
- const sufficiencyBanner = h('div', { className: suff.sufficient ? 'banner' : 'banner banner-warn' },
625
- h('strong', {
626
- text: suff.sufficient
627
- ? `Sample Sufficiency Met: n=${suff.submitted_n} submitted applications (MIN_N = ${suff.min_threshold}).`
628
- : `Honest Sample Guard (MIN_N = ${suff.min_threshold}): Only ${suff.submitted_n} submitted application(s) in "${a.period}" — conversion percentages are suppressed until n >= ${suff.min_threshold}.`,
629
- }),
630
- );
631
-
632
- const kpis = h('div', { className: 'kpi-grid' },
633
- h('div', { className: 'kpi-card' },
634
- h('div', { className: 'kpi-value', text: String(f.total_tracked) }),
635
- h('div', { className: 'kpi-label', text: 'Tracked Roles' }),
636
- h('div', { className: 'kpi-sub', text: `${f.prepared_only_count} prepared/dry-run` }),
637
- ),
638
- h('div', { className: 'kpi-card' },
639
- h('div', { className: 'kpi-value', text: String(f.submitted_count) }),
640
- h('div', { className: 'kpi-label', text: 'Submitted' }),
641
- h('div', { className: 'kpi-sub', text: `${f.pending_active_count} active · ${f.silent_14d_count} silent >=14d (not counted as rejected)` }),
642
- ),
643
- h('div', { className: 'kpi-card' },
644
- h('div', { className: 'kpi-value', text: formatRateCell(f.rates.callback_rate) }),
645
- h('div', { className: 'kpi-label', text: 'Positive Callback Rate' }),
646
- h('div', { className: 'kpi-sub', text: `${f.ever_interviewed_count} interviews · ${f.offer_count} offers` }),
647
- ),
648
- h('div', { className: 'kpi-card' },
649
- h('div', { className: 'kpi-value', text: f.avg_match_score !== null ? `${f.avg_match_score}/10` : 'N/A' }),
650
- h('div', { className: 'kpi-label', text: 'Average Match Score' }),
651
- h('div', { className: 'kpi-sub', text: a.timing.response_time.sample_sufficient ? `Median reply: ${a.timing.response_time.median_days}d` : 'Median reply: n < 5' }),
652
- ),
653
- );
654
-
655
- const platformCard = h('div', { className: 'card' },
656
- h('div', { className: 'card-header' },
657
- h('h2', { className: 'card-title', text: 'Source Platform Breakdown' }),
658
- ),
659
- h('p', { className: 'muted-text', text: a.source_performance.causal_humility_note }),
660
- (a.source_performance.by_platform || []).length === 0
661
- ? h('p', { className: 'muted-text', text: 'No submitted platform records in this period.' })
662
- : h('div', { className: 'table-wrap' },
663
- h('table', { className: 'data-table' },
664
- h('thead', null, h('tr', null,
665
- h('th', { text: 'Platform' }),
666
- h('th', { text: 'Submitted' }),
667
- h('th', { text: 'Callbacks' }),
668
- h('th', { text: 'Callback Rate' }),
669
- h('th', { text: 'Avg Score' }),
670
- )),
671
- h('tbody', null, a.source_performance.by_platform.map((row) =>
672
- h('tr', null,
673
- h('td', { text: row.platform }),
674
- h('td', { text: String(row.submitted) }),
675
- h('td', { text: String(row.callbacks) }),
676
- h('td', { text: formatRateCell(row.callback_rate) }),
677
- h('td', { text: row.avg_match_score !== null ? String(row.avg_match_score) : '-' }),
678
- ),
679
- )),
680
- ),
681
- ),
682
- );
683
-
684
- const maxSkillCount = Math.max(1, ...(a.skills_summary.top_skills || []).map((s) => s.count), ...(a.skills_summary.skill_gaps || []).map((s) => s.count));
685
- const skillsCard = h('div', { className: 'two-col' },
686
- h('div', { className: 'card' },
687
- h('h2', { className: 'card-title', text: 'Top Matched Skills' }),
688
- (a.skills_summary.top_skills || []).length === 0
689
- ? h('p', { className: 'muted-text', text: 'No skill tags recorded yet.' })
690
- : (a.skills_summary.top_skills || []).map((s) =>
691
- h('div', { className: 'meter-row' },
692
- h('span', { className: 'meter-label', text: s.skill }),
693
- h('progress', { className: 'meter', max: String(maxSkillCount), value: String(s.count) }),
694
- h('span', { className: 'pill pill-emerald', text: String(s.count) }),
695
- ),
696
- ),
697
- ),
698
- h('div', { className: 'card' },
699
- h('h2', { className: 'card-title', text: 'Recurring True Skill Gaps' }),
700
- (a.skills_summary.skill_gaps || []).length === 0
701
- ? h('p', { className: 'muted-text', text: 'No recurring skill gaps recorded yet.' })
702
- : (a.skills_summary.skill_gaps || []).map((s) =>
703
- h('div', { className: 'meter-row' },
704
- h('span', { className: 'meter-label', text: s.skill }),
705
- h('progress', { className: 'meter', max: String(maxSkillCount), value: String(s.count) }),
706
- h('span', { className: 'pill pill-amber', text: String(s.count) }),
707
- ),
708
- ),
709
- ),
710
- );
711
-
712
- panel.replaceChildren(periodBar, sufficiencyBanner, kpis, platformCard, skillsCard);
713
- }
714
-
715
- // ---------------- VIEW 4: STUDIO (IN-MEMORY) ----------------
716
- function renderStudio() {
717
- const panel = document.getElementById('view-studio');
718
- if (!panel) return;
719
-
720
- const subtabs = [
721
- ['route', 'Intent Router'],
722
- ['audit', 'CV Hygiene Audit'],
723
- ['verify', 'Artifact Fact-Check'],
724
- ['presubmit', 'Pre-Submit Gate'],
725
- ];
726
-
727
- const subtabBar = h('div', { className: 'filter-bar' },
728
- subtabs.map(([id, label]) =>
729
- h('button', {
730
- className: `subtab-btn ${state.studioSubtab === id ? 'active' : ''}`,
731
- text: label,
732
- onClick: () => {
733
- state.studioSubtab = id;
734
- renderStudio();
735
- },
736
- }),
737
- ),
738
- h('span', { className: 'pill pill-slate', text: '100% In-Memory · Zero Disk Writes' }),
739
- );
740
-
741
- const bodyMount = h('div');
742
- const resultMount = h('div');
743
- const workspaceFiles = state.overview?.workspace_files || [];
744
-
745
- if (state.studioSubtab === 'route') {
746
- const queryInput = h('input', {
747
- className: 'input',
748
- type: 'text',
749
- value: 'Tailor my CV for this Senior Backend Engineer JD without inventing metrics',
750
- placeholder: 'Describe any career task in natural language...',
751
- });
752
- const runRoute = async () => {
753
- resultMount.replaceChildren(h('div', { className: 'card', text: 'Routing...' }));
754
- try {
755
- const { route } = await apiPost('/api/route', { query: queryInput.value });
756
- resultMount.replaceChildren(
757
- h('div', { className: 'card' },
758
- h('div', { className: 'card-header' },
759
- h('h3', { className: 'card-title', text: `Matched Intent: ${route.intent}` }),
760
- route.workflow ? h('code', { className: 'md-inline-code', text: route.workflow }) : null,
761
- ),
762
- h('p', { className: 'muted-text', text: `Readiness: ${route.readiness}` }),
763
- h('p', { className: 'muted-text', text: `Offline Fallback: ${route.fallback}` }),
764
- h('div', { className: 'filter-bar' },
765
- (route.skills || []).map((sk) =>
766
- h('button', {
767
- className: 'btn btn-sm',
768
- text: `Skill: ${sk}`,
769
- onClick: () => {
770
- state.selectedSkillName = sk;
771
- switchTab('skills');
772
- if (state.skillsManifest) selectAndLoadSkill(sk);
773
- },
774
- }),
775
- ),
776
- ),
777
- ),
778
- );
779
- } catch (err) {
780
- resultMount.replaceChildren(h('div', { className: 'banner banner-error', text: err.message }));
781
- }
782
- };
783
- bodyMount.replaceChildren(
784
- h('div', { className: 'card' },
785
- h('h2', { className: 'card-title', text: 'Deterministic Natural-Language Task Router' }),
786
- h('div', { className: 'field-group' },
787
- h('label', { className: 'field-label', text: 'Task Request' }),
788
- queryInput,
789
- ),
790
- h('div', { className: 'filter-bar' },
791
- h('button', { className: 'btn btn-primary', text: 'Route Request', onClick: runRoute }),
792
- ),
793
- ),
794
- resultMount,
795
- );
796
- } else if (state.studioSubtab === 'audit') {
797
- const cvTextarea = h('textarea', {
798
- className: 'textarea',
799
- placeholder: 'Paste Markdown, HTML, or plain-text CV here...',
800
- text: '# Backend Engineer\n\n- Built idempotent Node.js payment services handling 120k requests/day with 99.95% uptime.\n- Reduced PostgreSQL query p95 latency by 38% across 14 production services.\n- Automated CI validation pipelines saving 6 hours/week across 12 engineers.\n',
801
- });
802
- const fileSelect = h('select', { className: 'select' },
803
- h('option', { value: '', text: '-- Or audit an existing workspace file --' }),
804
- workspaceFiles.filter((f) => ['md', 'txt', 'html', 'doc', 'docx'].includes(f.ext)).map((f) =>
805
- h('option', { value: f.rel_path, text: f.rel_path }),
806
- ),
807
- );
808
- const runAudit = async () => {
809
- resultMount.replaceChildren(h('div', { className: 'card', text: 'Auditing CV hygiene...' }));
810
- try {
811
- const payload = fileSelect.value ? { path: fileSelect.value } : { text: cvTextarea.value, format: 'md' };
812
- const { audit } = await apiPost('/api/audit', payload);
813
- resultMount.replaceChildren(
814
- h('div', { className: 'card' },
815
- h('div', { className: 'card-header' },
816
- h('h3', { className: 'card-title', text: `CV Hygiene Score: ${audit.total_score}/100` }),
817
- h('span', { className: audit.total_score >= 75 ? 'pill pill-emerald' : 'pill pill-amber', text: audit.length_status }),
818
- ),
819
- h('div', { className: 'kpi-grid' },
820
- h('div', { className: 'kpi-card' }, h('div', { className: 'kpi-value', text: `${audit.tone_score}/25` }), h('div', { className: 'kpi-label', text: 'Tone & Anti-Slop' }), h('div', { className: 'kpi-sub', text: `${audit.cliches_found.length} cliches · ${audit.em_dash_count} em-dashes` })),
821
- h('div', { className: 'kpi-card' }, h('div', { className: 'kpi-value', text: `${audit.impact_score}/30` }), h('div', { className: 'kpi-label', text: 'Quantified Impact' }), h('div', { className: 'kpi-sub', text: `${audit.quantified_bullets}/${audit.bullet_count} bullets · ${audit.total_metrics} metrics` })),
822
- h('div', { className: 'kpi-card' }, h('div', { className: 'kpi-value', text: `${audit.length_score}/25` }), h('div', { className: 'kpi-label', text: '1-Page Fit' }), h('div', { className: 'kpi-sub', text: `${audit.word_count} words · ${audit.line_count} lines` })),
823
- h('div', { className: 'kpi-card' }, h('div', { className: 'kpi-value', text: `${audit.hygiene_score}/20` }), h('div', { className: 'kpi-label', text: 'Link & PII Hygiene' }), h('div', { className: 'kpi-sub', text: `Status: ${audit.hygiene_label}` })),
824
- ),
825
- audit.cliches_found.length > 0
826
- ? h('p', { className: 'muted-text', text: `Flagged AI Cliches: ${audit.cliches_found.join(', ')}` })
827
- : null,
828
- ),
829
- );
830
- } catch (err) {
831
- resultMount.replaceChildren(h('div', { className: 'banner banner-error', text: err.message }));
832
- }
833
- };
834
- bodyMount.replaceChildren(
835
- h('div', { className: 'card' },
836
- h('h2', { className: 'card-title', text: 'Offline CV Hygiene Audit' }),
837
- h('div', { className: 'filter-bar' }, fileSelect),
838
- cvTextarea,
839
- h('div', { className: 'filter-bar' },
840
- h('button', { className: 'btn btn-primary', text: 'Run CV Audit', onClick: runAudit }),
841
- ),
842
- ),
843
- resultMount,
844
- );
845
- } else if (state.studioSubtab === 'verify') {
846
- const artifactArea = h('textarea', {
847
- className: 'textarea',
848
- placeholder: 'Paste tailored HTML, Markdown, or TXT artifact...',
849
- text: '<!doctype html><html><body><h1>Resume</h1><p>Reduced payment webhook p95 latency by 38% across 3 regions.</p></body></html>',
850
- });
851
- const metricsInput = h('input', { className: 'input', type: 'text', value: '38%, 3', placeholder: 'Comma-separated allowed metrics (e.g. 38%, $4.2M)' });
852
- const forbiddenInput = h('input', { className: 'input', type: 'text', value: 'Kubernetes, Rust', placeholder: 'Comma-separated forbidden skills' });
853
-
854
- const runVerify = async () => {
855
- resultMount.replaceChildren(h('div', { className: 'card', text: 'Verifying artifact...' }));
856
- try {
857
- const allowed = metricsInput.value.split(',').map((s) => s.trim()).filter(Boolean);
858
- const forbidden = forbiddenInput.value.split(',').map((s) => s.trim()).filter(Boolean);
859
- const { verification } = await apiPost('/api/verify', {
860
- text: artifactArea.value,
861
- format: 'html',
862
- facts_json: { ground_truth_metrics: allowed, forbidden_skills: forbidden },
863
- });
864
- const first = verification.results[0];
865
- resultMount.replaceChildren(
866
- h('div', { className: 'card' },
867
- h('div', { className: 'card-header' },
868
- h('h3', { className: 'card-title', text: verification.ok ? 'Artifact Verification PASSED' : 'Artifact Verification BLOCKED' }),
869
- h('span', { className: verification.ok ? 'pill pill-emerald' : 'pill pill-rose', text: `${verification.error_count} error(s)` }),
870
- ),
871
- first.errors.length === 0
872
- ? h('p', { className: 'muted-text', text: '0 unresolved placeholders, 0 banned cliches, 0 prose em-dashes, and 0 unverified metrics or forbidden skills.' })
873
- : h('div', { className: 'list-stack' }, first.errors.map((e) => h('div', { className: 'banner banner-error', text: e }))),
874
- ),
875
- );
876
- } catch (err) {
877
- resultMount.replaceChildren(h('div', { className: 'banner banner-error', text: err.message }));
878
- }
879
- };
880
- bodyMount.replaceChildren(
881
- h('div', { className: 'card' },
882
- h('h2', { className: 'card-title', text: 'Anti-Hallucination & Placeholder Verifier' }),
883
- h('div', { className: 'form-grid' },
884
- h('div', { className: 'field-group' }, h('label', { className: 'field-label', text: 'Verified Metrics Allowlist' }), metricsInput),
885
- h('div', { className: 'field-group' }, h('label', { className: 'field-label', text: 'Forbidden / Unclaimed Skills' }), forbiddenInput),
886
- ),
887
- artifactArea,
888
- h('div', { className: 'filter-bar' },
889
- h('button', { className: 'btn btn-primary', text: 'Verify Artifact', onClick: runVerify }),
890
- ),
891
- ),
892
- resultMount,
893
- );
894
- } else {
895
- const companyIn = h('input', { className: 'input', type: 'text', placeholder: 'Company (e.g. Acme Payments)' });
896
- const titleIn = h('input', { className: 'input', type: 'text', placeholder: 'Role Title (e.g. Senior Backend Engineer)' });
897
- const platformIn = h('input', { className: 'input', type: 'text', value: 'greenhouse', placeholder: 'Platform (e.g. greenhouse, linkedin)' });
898
- const draftArea = h('textarea', {
899
- className: 'textarea',
900
- text: 'Hi hiring team, sharing my backend engineering application highlighting 38% webhook latency improvements on Node.js and PostgreSQL.',
901
- });
902
- const runPreSubmit = async () => {
903
- resultMount.replaceChildren(h('div', { className: 'card', text: 'Evaluating pre-submit guardrails...' }));
904
- try {
905
- const { evaluation } = await apiPost('/api/pre-submit', {
906
- company: companyIn.value,
907
- title: titleIn.value,
908
- platform: platformIn.value,
909
- text: draftArea.value,
910
- max_words: 75,
911
- });
912
- resultMount.replaceChildren(
913
- h('div', { className: 'card' },
914
- h('div', { className: 'card-header' },
915
- h('h3', { className: 'card-title', text: evaluation.allowed ? 'Pre-Submit Gate PASSED (Requires Human APPROVE)' : 'Pre-Submit Gate BLOCKED' }),
916
- h('span', { className: evaluation.allowed ? 'pill pill-emerald' : 'pill pill-rose', text: `dry_run: ${evaluation.dry_run}` }),
917
- ),
918
- evaluation.violations.length === 0
919
- ? h('p', { className: 'muted-text', text: `Daily cap OK (${evaluation.checks.daily_cap.today_counted}/${evaluation.checks.daily_cap.effective_cap}), deduplication OK, blacklist OK, draft ${evaluation.checks.draft?.word_count || 0}/75 words OK.` })
920
- : h('div', { className: 'list-stack' }, evaluation.violations.map((v) => h('div', { className: 'banner banner-error', text: `${v.code}: ${v.message}` }))),
921
- ),
922
- );
923
- } catch (err) {
924
- resultMount.replaceChildren(h('div', { className: 'banner banner-error', text: err.message }));
925
- }
926
- };
927
- bodyMount.replaceChildren(
928
- h('div', { className: 'card' },
929
- h('h2', { className: 'card-title', text: 'Pre-Submit Cap, Dedup & <= 75-Word Outreach Gate' }),
930
- h('div', { className: 'form-grid' },
931
- h('div', { className: 'field-group' }, h('label', { className: 'field-label', text: 'Company' }), companyIn),
932
- h('div', { className: 'field-group' }, h('label', { className: 'field-label', text: 'Role Title' }), titleIn),
933
- h('div', { className: 'field-group' }, h('label', { className: 'field-label', text: 'Platform' }), platformIn),
934
- ),
935
- draftArea,
936
- h('div', { className: 'filter-bar' },
937
- h('button', { className: 'btn btn-primary', text: 'Evaluate Pre-Submit Gate', onClick: runPreSubmit }),
938
- ),
939
- ),
940
- resultMount,
941
- );
942
- }
943
-
944
- panel.replaceChildren(subtabBar, bodyMount);
945
- }
946
-
947
- // ---------------- VIEW 5: SKILLS & GUARDRAILS ----------------
948
- async function loadSkills() {
949
- const panel = document.getElementById('view-skills');
950
- if (!panel) return;
951
- panel.replaceChildren(h('div', { className: 'card', text: 'Loading 56 Markdown skill playbooks...' }));
952
- try {
953
- state.skillsManifest = await apiGet('/api/skills');
954
- const initialSkill = state.selectedSkillName || state.skillsManifest.skills[0]?.name;
955
- renderSkillsShell();
956
- if (initialSkill) await selectAndLoadSkill(initialSkill);
957
- } catch (err) {
958
- panel.replaceChildren(h('div', { className: 'banner banner-error', text: `Failed loading skills: ${err.message}` }));
959
- }
960
- }
961
-
962
- async function selectAndLoadSkill(name) {
963
- state.selectedSkillName = name;
964
- for (const btn of document.querySelectorAll('.skill-item-btn')) {
965
- btn.classList.toggle('active', btn.dataset.skill === name);
966
- }
967
- const reader = document.getElementById('skill-reader-pane');
968
- if (!reader) return;
969
- reader.replaceChildren(h('p', { className: 'muted-text', text: `Loading veycraft://skill/${name}...` }));
970
-
971
- try {
972
- let payload = state.skillCache.get(name);
973
- if (!payload) {
974
- payload = await apiGet(`/api/skills/${encodeURIComponent(name)}`);
975
- state.skillCache.set(name, payload);
976
- }
977
- const sk = payload.skill;
978
- reader.replaceChildren(
979
- h('div', { className: 'card-header' },
980
- h('div', null,
981
- h('h2', { className: 'card-title', text: `${sk.name} (v${sk.version})` }),
982
- h('div', { className: 'subtitle', text: `${payload.uri} · ${sk.path}` }),
983
- ),
984
- h('button', { className: 'btn btn-sm', text: 'Copy URI', onClick: () => copyText(payload.uri, `Copied ${payload.uri}`) }),
985
- ),
986
- h('p', { className: 'muted-text', text: sk.description }),
987
- h('div', { className: 'filter-bar' },
988
- h('span', { className: 'pill pill-emerald', text: `category: ${sk.category || 'core'}` }),
989
- ...(sk.requires_mcp || []).map((m) => h('span', { className: 'pill pill-blue', text: `mcp: ${m}` })),
990
- ),
991
- renderMarkdownSafe(payload.content),
992
- );
993
- } catch (err) {
994
- reader.replaceChildren(h('div', { className: 'banner banner-error', text: err.message }));
995
- }
996
- }
997
-
998
- function renderSkillsShell() {
999
- const panel = document.getElementById('view-skills');
1000
- if (!panel || !state.skillsManifest) return;
1001
-
1002
- const allSkills = state.skillsManifest.skills || [];
1003
- const categories = [...new Set(allSkills.map((s) => s.category || 'core'))].sort();
1004
-
1005
- const filterBar = h('div', { className: 'filter-bar' },
1006
- h('input', {
1007
- className: 'input',
1008
- type: 'text',
1009
- placeholder: 'Search 56 skills by name, trigger, or keyword...',
1010
- value: state.skillsQuery,
1011
- onInput: (e) => {
1012
- state.skillsQuery = e.target.value;
1013
- renderSkillListItems();
1014
- },
1015
- }),
1016
- h('select', {
1017
- className: 'select',
1018
- onChange: (e) => {
1019
- state.skillsCategory = e.target.value;
1020
- renderSkillListItems();
1021
- },
1022
- },
1023
- h('option', { value: 'all', text: 'All Categories' }),
1024
- categories.map((c) => h('option', { value: c, text: c, selected: state.skillsCategory === c })),
1025
- ),
1026
- h('select', {
1027
- className: 'select',
1028
- onChange: (e) => {
1029
- state.skillsMcp = e.target.value;
1030
- renderSkillListItems();
1031
- },
1032
- },
1033
- h('option', { value: 'all', text: 'Any MCP Requirement' }),
1034
- h('option', { value: 'none', text: 'Offline Only (mcp: none)' }),
1035
- h('option', { value: 'playwright', text: 'Uses Playwright MCP' }),
1036
- ),
1037
- );
1038
-
1039
- const listPane = h('div', { id: 'skills-list-pane', className: 'skills-list-pane' });
1040
- const readerPane = h('div', { id: 'skill-reader-pane', className: 'card' });
1041
-
1042
- const invariantsCard = state.skillsManifest.invariants_text
1043
- ? h('div', { className: 'card' },
1044
- h('div', { className: 'card-header' },
1045
- h('h2', { className: 'card-title', text: 'Non-Negotiable Safety Invariants (config/invariants.txt)' }),
1046
- h('span', { className: 'pill pill-emerald', text: 'veycraft://invariants' }),
1047
- ),
1048
- h('pre', { className: 'code-snippet', text: state.skillsManifest.invariants_text }),
1049
- )
1050
- : null;
1051
-
1052
- panel.replaceChildren(filterBar, h('div', { className: 'skills-layout' }, listPane, readerPane), invariantsCard);
1053
-
1054
- function renderSkillListItems() {
1055
- const q = state.skillsQuery.trim().toLowerCase();
1056
- const filtered = allSkills.filter((s) => {
1057
- if (state.skillsCategory !== 'all' && (s.category || 'core') !== state.skillsCategory) return false;
1058
- if (state.skillsMcp !== 'all' && !(s.requires_mcp || []).includes(state.skillsMcp)) return false;
1059
- if (!q) return true;
1060
- return (
1061
- s.name.toLowerCase().includes(q) ||
1062
- (s.description || '').toLowerCase().includes(q) ||
1063
- (s.triggers || []).some((t) => t.toLowerCase().includes(q))
1064
- );
1065
- });
1066
-
1067
- listPane.replaceChildren(
1068
- ...filtered.map((s) =>
1069
- h('button', {
1070
- className: `skill-item-btn ${state.selectedSkillName === s.name ? 'active' : ''}`,
1071
- type: 'button',
1072
- dataset: { skill: s.name },
1073
- onClick: () => selectAndLoadSkill(s.name),
1074
- },
1075
- h('div', { className: 'app-card-role', text: s.name }),
1076
- h('div', { className: 'muted-text', text: (s.triggers || []).slice(0, 2).join(' · ') || s.path }),
1077
- ),
1078
- ),
1079
- );
1080
- }
1081
-
1082
- renderSkillListItems();
1083
- }
1084
-
1085
- // ---------------- BOOTSTRAP ----------------
1086
- async function refreshAll() {
1087
- try {
1088
- state.overview = await apiGet('/api/overview');
1089
- renderOverview();
1090
- if (state.activeTab === 'kanban') await loadKanban();
1091
- if (state.activeTab === 'analytics') await loadAnalytics(state.analyticsPeriod);
1092
- if (state.activeTab === 'skills') await loadSkills();
1093
- } catch (err) {
1094
- const panel = document.getElementById('view-overview');
1095
- if (panel) {
1096
- panel.replaceChildren(h('div', { className: 'banner banner-error', text: `Failed loading overview: ${err.message}` }));
1097
- }
1098
- }
1099
- }
1100
-
1101
- document.addEventListener('DOMContentLoaded', () => {
1102
- for (const btn of document.querySelectorAll('.tab-btn')) {
1103
- btn.addEventListener('click', () => switchTab(btn.dataset.tab));
1104
- }
1105
- const refreshBtn = document.getElementById('refresh-btn');
1106
- if (refreshBtn) {
1107
- refreshBtn.addEventListener('click', async () => {
1108
- await refreshAll();
1109
- showToast('Refreshed local workspace snapshot');
1110
- });
1111
- }
1112
- refreshAll();
1113
- });
1
+ // Zero-dependency Veycraft Read-Only Local UI client.
2
+ // Strictly uses document.createElement / textContent / replaceChildren only.
3
+
4
+ const state = {
5
+ activeTab: 'overview',
6
+ studioSubtab: 'route',
7
+ overview: null,
8
+ applications: null,
9
+ analytics: null,
10
+ analyticsPeriod: 'all',
11
+ skillsManifest: null,
12
+ selectedSkillName: null,
13
+ skillCache: new Map(),
14
+ kanbanQuery: '',
15
+ kanbanPlatform: 'all',
16
+ kanbanCv: 'all',
17
+ skillsQuery: '',
18
+ skillsCategory: 'all',
19
+ skillsMcp: 'all',
20
+ };
21
+
22
+ const SAFE_ATTRS = new Set([
23
+ 'id', 'type', 'role', 'value', 'max', 'min', 'placeholder',
24
+ 'aria-label', 'aria-selected', 'aria-live', 'for', 'name',
25
+ 'rows', 'cols', 'disabled', 'selected', 'checked', 'title',
26
+ ]);
27
+
28
+ function h(tag, props = null, ...children) {
29
+ const node = document.createElement(tag);
30
+ if (props) {
31
+ for (const [k, v] of Object.entries(props)) {
32
+ if (v === undefined || v === null || v === false) continue;
33
+ if (k === 'className') {
34
+ node.className = String(v);
35
+ } else if (k === 'text') {
36
+ node.textContent = String(v);
37
+ } else if (k === 'onClick') {
38
+ node.addEventListener('click', v);
39
+ } else if (k === 'onInput') {
40
+ node.addEventListener('input', v);
41
+ } else if (k === 'onChange') {
42
+ node.addEventListener('change', v);
43
+ } else if (k === 'href') {
44
+ const str = String(v).trim();
45
+ if (/^https?:\/\//i.test(str)) {
46
+ node.setAttribute('href', str);
47
+ node.setAttribute('target', '_blank');
48
+ node.setAttribute('rel', 'noopener noreferrer');
49
+ }
50
+ } else if (k === 'dataset' && typeof v === 'object') {
51
+ for (const [dk, dv] of Object.entries(v)) {
52
+ node.dataset[dk] = String(dv);
53
+ }
54
+ } else if (SAFE_ATTRS.has(k)) {
55
+ if (v === true) node.setAttribute(k, '');
56
+ else node.setAttribute(k, String(v));
57
+ }
58
+ }
59
+ }
60
+ appendChildren(node, children);
61
+ return node;
62
+ }
63
+
64
+ function appendChildren(parent, items) {
65
+ for (const item of items) {
66
+ if (item === null || item === undefined || item === false) continue;
67
+ if (Array.isArray(item)) {
68
+ appendChildren(parent, item);
69
+ } else if (item instanceof Node) {
70
+ parent.appendChild(item);
71
+ } else {
72
+ parent.appendChild(document.createTextNode(String(item)));
73
+ }
74
+ }
75
+ }
76
+
77
+ function renderInlineCodeSegments(text) {
78
+ const str = String(text || '');
79
+ const parts = str.split(/(`[^`]+`)/g);
80
+ const frag = document.createDocumentFragment();
81
+ for (const part of parts) {
82
+ if (part.length >= 2 && part.startsWith('`') && part.endsWith('`')) {
83
+ frag.appendChild(h('code', { className: 'md-inline-code', text: part.slice(1, -1) }));
84
+ } else if (part) {
85
+ frag.appendChild(document.createTextNode(part));
86
+ }
87
+ }
88
+ return frag;
89
+ }
90
+
91
+ function renderMarkdownSafe(markdownText) {
92
+ const container = h('div', { className: 'md-body' });
93
+ const lines = String(markdownText || '').replace(/\r\n/g, '\n').split('\n');
94
+ let i = 0;
95
+
96
+ // Skip optional YAML frontmatter block cleanly into a compact metadata pre
97
+ if (lines[0] === '---') {
98
+ const endIdx = lines.indexOf('---', 1);
99
+ if (endIdx > 0) {
100
+ i = endIdx + 1;
101
+ }
102
+ }
103
+
104
+ while (i < lines.length) {
105
+ const line = lines[i];
106
+ if (!line.trim()) {
107
+ i++;
108
+ continue;
109
+ }
110
+ if (line.startsWith('```')) {
111
+ const codeLines = [];
112
+ i++;
113
+ while (i < lines.length && !lines[i].startsWith('```')) {
114
+ codeLines.push(lines[i]);
115
+ i++;
116
+ }
117
+ i++;
118
+ container.appendChild(h('pre', { className: 'code-snippet', text: codeLines.join('\n') }));
119
+ continue;
120
+ }
121
+ const headingMatch = line.match(/^(#{1,4})\s+(.+)$/);
122
+ if (headingMatch) {
123
+ const level = Math.min(4, headingMatch[1].length);
124
+ container.appendChild(h(`h${level}`, null, renderInlineCodeSegments(headingMatch[2])));
125
+ i++;
126
+ continue;
127
+ }
128
+ if (line.startsWith('>')) {
129
+ const quoteLines = [];
130
+ while (i < lines.length && lines[i].startsWith('>')) {
131
+ quoteLines.push(lines[i].replace(/^>\s?/, ''));
132
+ i++;
133
+ }
134
+ container.appendChild(h('blockquote', null, renderInlineCodeSegments(quoteLines.join(' '))));
135
+ continue;
136
+ }
137
+ if (/^\s*[-*]\s+/.test(line)) {
138
+ const ul = h('ul');
139
+ while (i < lines.length && /^\s*[-*]\s+/.test(lines[i])) {
140
+ ul.appendChild(h('li', null, renderInlineCodeSegments(lines[i].replace(/^\s*[-*]\s+/, ''))));
141
+ i++;
142
+ }
143
+ container.appendChild(ul);
144
+ continue;
145
+ }
146
+ if (/^\s*\d+\.\s+/.test(line)) {
147
+ const ol = h('ol');
148
+ while (i < lines.length && /^\s*\d+\.\s+/.test(lines[i])) {
149
+ ol.appendChild(h('li', null, renderInlineCodeSegments(lines[i].replace(/^\s*\d+\.\s+/, ''))));
150
+ i++;
151
+ }
152
+ container.appendChild(ol);
153
+ continue;
154
+ }
155
+ if (line.includes('|') && i + 1 < lines.length && /^\s*\|?[\s:-]+\|/.test(lines[i + 1])) {
156
+ const parseCells = (row) => row.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map((c) => c.trim());
157
+ const headers = parseCells(line);
158
+ i += 2;
159
+ const rows = [];
160
+ while (i < lines.length && lines[i].includes('|') && lines[i].trim()) {
161
+ rows.push(parseCells(lines[i]));
162
+ i++;
163
+ }
164
+ const table = h('table', { className: 'data-table' },
165
+ h('thead', null, h('tr', null, headers.map((hd) => h('th', { text: hd })))),
166
+ h('tbody', null, rows.map((r) => h('tr', null, r.map((cell) => h('td', null, renderInlineCodeSegments(cell)))))),
167
+ );
168
+ container.appendChild(h('div', { className: 'table-wrap' }, table));
169
+ continue;
170
+ }
171
+ container.appendChild(h('p', null, renderInlineCodeSegments(line)));
172
+ i++;
173
+ }
174
+ return container;
175
+ }
176
+
177
+ let toastTimer = null;
178
+ function showToast(msg) {
179
+ const el = document.getElementById('global-toast');
180
+ if (!el) return;
181
+ el.textContent = msg;
182
+ el.classList.remove('hidden');
183
+ if (toastTimer) clearTimeout(toastTimer);
184
+ toastTimer = setTimeout(() => el.classList.add('hidden'), 2600);
185
+ }
186
+
187
+ async function copyText(str, label = 'Copied to clipboard') {
188
+ try {
189
+ await navigator.clipboard.writeText(str);
190
+ showToast(`${label}`);
191
+ } catch {
192
+ showToast(`Copy value: ${str}`);
193
+ }
194
+ }
195
+
196
+ async function apiGet(url) {
197
+ const res = await fetch(url, { headers: { Accept: 'application/json' } });
198
+ const data = await res.json();
199
+ if (!res.ok || !data.ok) {
200
+ throw new Error(data?.error?.message || `HTTP ${res.status}`);
201
+ }
202
+ return data;
203
+ }
204
+
205
+ async function apiPost(url, bodyObj) {
206
+ const res = await fetch(url, {
207
+ method: 'POST',
208
+ headers: {
209
+ 'Content-Type': 'application/json',
210
+ Accept: 'application/json',
211
+ },
212
+ body: JSON.stringify(bodyObj),
213
+ });
214
+ const data = await res.json();
215
+ if (!res.ok || !data.ok) {
216
+ throw new Error(data?.error?.message || `HTTP ${res.status}`);
217
+ }
218
+ return data;
219
+ }
220
+
221
+ function statusPillClass(levelOrStatus) {
222
+ const s = String(levelOrStatus || '').toLowerCase();
223
+ if (s === 'ok' || s === 'applied' || s === 'offer' || s === 'pass') return 'pill pill-emerald';
224
+ if (s === 'interview' || s === 'assessment' || s === 'info' || s === 'prepared') return 'pill pill-blue';
225
+ if (s === 'warn' || s === 'needs_review' || s === 'dry_run' || s === 'discovered') return 'pill pill-amber';
226
+ if (s === 'fail' || s === 'failed' || s === 'aborted' || s === 'rejected') return 'pill pill-rose';
227
+ return 'pill pill-slate';
228
+ }
229
+
230
+ function switchTab(tabName) {
231
+ state.activeTab = tabName;
232
+ for (const btn of document.querySelectorAll('.tab-btn')) {
233
+ const active = btn.dataset.tab === tabName;
234
+ btn.classList.toggle('active', active);
235
+ btn.setAttribute('aria-selected', active ? 'true' : 'false');
236
+ }
237
+ for (const name of ['overview', 'kanban', 'analytics', 'studio', 'skills']) {
238
+ const panel = document.getElementById(`view-${name}`);
239
+ if (panel) panel.classList.toggle('hidden', name !== tabName);
240
+ }
241
+ if (tabName === 'kanban' && !state.applications) loadKanban();
242
+ if (tabName === 'analytics' && !state.analytics) loadAnalytics(state.analyticsPeriod);
243
+ if (tabName === 'studio') renderStudio();
244
+ if (tabName === 'skills' && !state.skillsManifest) loadSkills();
245
+ }
246
+
247
+ // ---------------- VIEW 1: OVERVIEW ----------------
248
+ function renderOverview() {
249
+ const panel = document.getElementById('view-overview');
250
+ if (!panel || !state.overview) return;
251
+
252
+ const { meta, doctor, summary, next, ledger_health: ledgerHealth } = state.overview;
253
+ const docPayload = doctor.payload;
254
+ const gates = docPayload.gates || { passed: 0, total: 4 };
255
+ const funnel = summary?.funnel || { total_tracked: 0, submitted_count: 0 };
256
+
257
+ document.getElementById('version-badge').textContent = `v${meta.version}`;
258
+ document.getElementById('workspace-subtitle').textContent = `${meta.workspace_root} (${meta.scope} workspace · ${meta.zero_dependencies.runtime}/${meta.zero_dependencies.dev} npm deps)`;
259
+
260
+ const nodes = [];
261
+
262
+ if (!docPayload.initialized) {
263
+ nodes.push(
264
+ h('div', { className: 'banner banner-onboarding' },
265
+ h('div', { className: 'card-header' },
266
+ h('strong', { text: 'Workspace Not Initialized Yet — Start Safely in 15 Seconds' }),
267
+ h('span', { className: 'pill pill-blue', text: 'ZERO LOGIN NEEDED' }),
268
+ ),
269
+ h('p', { className: 'muted-text', text: 'Standalone tasks (/demo, /quick-tailor, CV hygiene audit, routing, and skill browsing) work right now with zero setup. Initialize ~/.veycraft whenever you want persistent tracking.' }),
270
+ h('div', { className: 'filter-bar' },
271
+ h('button', { className: 'btn btn-primary btn-sm', text: 'Copy: npx veycraft init --global', onClick: () => copyText('npx veycraft init --global', 'Copied init --global command') }),
272
+ h('button', { className: 'btn btn-sm', text: 'Try Verification Studio', onClick: () => switchTab('studio') }),
273
+ h('button', { className: 'btn btn-sm', text: 'Browse 56 Skills', onClick: () => switchTab('skills') }),
274
+ ),
275
+ ),
276
+ );
277
+ }
278
+
279
+ if (ledgerHealth?.error) {
280
+ nodes.push(h('div', { className: 'banner banner-error', text: `Ledger Notice: ${ledgerHealth.error}` }));
281
+ }
282
+
283
+ nodes.push(
284
+ h('div', { className: 'kpi-grid' },
285
+ h('div', { className: 'kpi-card' },
286
+ h('div', { className: 'kpi-value', text: `${gates.passed}/${gates.total}` }),
287
+ h('div', { className: 'kpi-label', text: 'Readiness Gates' }),
288
+ h('div', { className: 'kpi-sub', text: docPayload.initialized ? 'Initialized workspace' : 'Standalone mode ready' }),
289
+ ),
290
+ h('div', { className: 'kpi-card' },
291
+ h('div', { className: 'kpi-value', text: String(funnel.total_tracked || 0) }),
292
+ h('div', { className: 'kpi-label', text: 'Owner Apps Tracked' }),
293
+ h('div', { className: 'kpi-sub', text: `${funnel.submitted_count || 0} submitted` }),
294
+ ),
295
+ h('div', { className: 'kpi-card' },
296
+ h('div', { className: 'kpi-value', text: String((summary?.active_interviews || 0) + (summary?.active_assessments || 0)) }),
297
+ h('div', { className: 'kpi-label', text: 'Active Interviews / Tests' }),
298
+ h('div', { className: 'kpi-sub', text: `${summary?.active_interviews || 0} interviews · ${summary?.active_assessments || 0} assessments` }),
299
+ ),
300
+ h('div', { className: 'kpi-card' },
301
+ h('div', { className: 'kpi-value', text: String(summary?.overdue_follow_ups_count || 0) }),
302
+ h('div', { className: 'kpi-label', text: 'Overdue Follow-Ups' }),
303
+ h('div', { className: 'kpi-sub', text: `${docPayload.skills_count || 56} Markdown skills loaded` }),
304
+ ),
305
+ ),
306
+ );
307
+
308
+ const gateItems = [
309
+ ['Gate 1 · CV & Profile', gates.cv_and_profile],
310
+ ['Gate 2 · Target Preferences', gates.target_preferences],
311
+ ['Gate 3/4 · Legal, Comp & Skills', gates.legal_comp_skills],
312
+ ['Gate 5 · Enabled Job Targets', gates.enabled_targets],
313
+ ['Browser Profile Directory', docPayload.browser_profile_present],
314
+ ['Provenance & Attribution', docPayload.provenance_verified],
315
+ ];
316
+
317
+ const gatesCard = h('div', { className: 'card' },
318
+ h('div', { className: 'card-header' },
319
+ h('h2', { className: 'card-title', text: 'Readiness & Safety Gates' }),
320
+ h('span', { className: docPayload.ok ? 'pill pill-emerald' : 'pill pill-amber', text: docPayload.ok ? 'DOCTOR OK' : `${docPayload.readiness_pending} PENDING` }),
321
+ ),
322
+ h('div', { className: 'list-stack' },
323
+ gateItems.map(([label, ok]) =>
324
+ h('div', { className: 'list-row' },
325
+ h('span', { text: label }),
326
+ h('span', { className: ok ? 'pill pill-emerald' : 'pill pill-amber', text: ok ? 'READY' : 'PENDING' }),
327
+ ),
328
+ ),
329
+ ),
330
+ );
331
+
332
+ const actions = Array.isArray(next?.prioritized_actions) ? next.prioritized_actions.slice(0, 6) : [];
333
+ const nextCard = h('div', { className: 'card' },
334
+ h('div', { className: 'card-header' },
335
+ h('h2', { className: 'card-title', text: 'Prioritized Next Actions' }),
336
+ h('span', { className: 'pill pill-blue', text: `${actions.length} QUEUED` }),
337
+ ),
338
+ actions.length === 0
339
+ ? h('p', { className: 'muted-text', text: 'No urgent blockers or overdue follow-ups. Start with /demo, /quick-tailor, or Verification Studio.' })
340
+ : h('div', { className: 'list-stack' },
341
+ actions.map((act) =>
342
+ h('div', { className: 'list-row' },
343
+ h('div', null,
344
+ h('div', { text: act.title || act.summary || act.kind || 'Recommended Action' }),
345
+ act.recommended_command ? h('div', { className: 'subtitle', text: act.recommended_command }) : null,
346
+ ),
347
+ act.recommended_command
348
+ ? h('button', {
349
+ className: 'btn btn-sm',
350
+ text: 'Copy Cmd',
351
+ onClick: () => copyText(act.recommended_command, 'Copied recommended command'),
352
+ })
353
+ : null,
354
+ ),
355
+ ),
356
+ ),
357
+ );
358
+
359
+ nodes.push(h('div', { className: 'two-col' }, gatesCard, nextCard));
360
+
361
+ const mcpSnippet = JSON.stringify({
362
+ mcpServers: {
363
+ veycraft: {
364
+ command: 'npx',
365
+ args: ['-y', 'veycraft', 'mcp'],
366
+ },
367
+ },
368
+ }, null, 2);
369
+
370
+ nodes.push(
371
+ h('div', { className: 'card' },
372
+ h('div', { className: 'card-header' },
373
+ h('div', null,
374
+ h('h2', { className: 'card-title', text: 'Connect Your IDE (Native MCP Server)' }),
375
+ h('p', { className: 'muted-text', text: 'Expose 8 read-only offline tools and allowlisted veycraft:// skill resources over stdio.' }),
376
+ ),
377
+ h('div', { className: 'filter-bar' },
378
+ h('button', {
379
+ className: 'btn btn-primary btn-sm',
380
+ text: 'Copy mcpServers JSON',
381
+ onClick: () => copyText(mcpSnippet, 'Copied mcpServers JSON snippet'),
382
+ }),
383
+ h('button', {
384
+ className: 'btn btn-sm',
385
+ text: 'Copy: veycraft sync-mcp --with-veycraft',
386
+ onClick: () => copyText('npx veycraft sync-mcp --with-veycraft', 'Copied sync-mcp --with-veycraft command'),
387
+ }),
388
+ ),
389
+ ),
390
+ h('pre', { className: 'code-snippet', text: mcpSnippet }),
391
+ ),
392
+ );
393
+
394
+ nodes.push(
395
+ h('div', { className: 'card' },
396
+ h('div', { className: 'card-header' },
397
+ h('h2', { className: 'card-title', text: 'Offline Doctor Diagnostic Events' }),
398
+ h('span', { className: 'pill pill-slate', text: 'offline: true · readOnly: true' }),
399
+ ),
400
+ h('div', { className: 'list-stack' },
401
+ (doctor.events || []).map((ev) =>
402
+ h('div', { className: 'list-row' },
403
+ h('span', { text: ev.message }),
404
+ h('span', { className: statusPillClass(ev.level), text: String(ev.level).toUpperCase() }),
405
+ ),
406
+ ),
407
+ ),
408
+ ),
409
+ );
410
+
411
+ panel.replaceChildren(...nodes);
412
+ }
413
+
414
+ // ---------------- VIEW 2: KANBAN ----------------
415
+ async function loadKanban() {
416
+ const panel = document.getElementById('view-kanban');
417
+ if (!panel) return;
418
+ panel.replaceChildren(h('div', { className: 'card', text: 'Loading read-only application ledger...' }));
419
+ try {
420
+ state.applications = await apiGet('/api/applications');
421
+ renderKanban();
422
+ } catch (err) {
423
+ panel.replaceChildren(h('div', { className: 'banner banner-error', text: `Failed loading applications: ${err.message}` }));
424
+ }
425
+ }
426
+
427
+ function openApplicationDrawer(card) {
428
+ const drawer = document.getElementById('detail-drawer');
429
+ if (!drawer) return;
430
+ drawer.classList.remove('hidden');
431
+ drawer.replaceChildren(
432
+ h('div', { className: 'card-header' },
433
+ h('h2', { className: 'card-title', text: `${card.company} — ${card.role_title}` }),
434
+ h('button', { className: 'btn btn-sm', text: 'Close', onClick: () => drawer.classList.add('hidden') }),
435
+ ),
436
+ h('div', { className: 'filter-bar' },
437
+ h('span', { className: statusPillClass(card.status), text: card.status }),
438
+ card.match_score !== null ? h('span', { className: 'pill pill-emerald', text: `Score: ${card.match_score}/10` }) : null,
439
+ card.has_verified_receipt ? h('span', { className: 'pill pill-blue', text: 'Receipt Verified' }) : null,
440
+ card.submission_uncertain ? h('span', { className: 'pill pill-amber', text: 'Submission Uncertain' }) : null,
441
+ ),
442
+ h('div', { className: 'list-stack' },
443
+ h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'Application ID' }), h('code', { className: 'md-inline-code', text: card.application_id })),
444
+ card.job_id ? h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'Job ID' }), h('code', { className: 'md-inline-code', text: card.job_id })) : null,
445
+ h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'Platform / Channel' }), h('span', { text: `${card.platform} (${card.source_channel})` })),
446
+ card.cv_version_id ? h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'CV Version' }), h('code', { className: 'md-inline-code', text: card.cv_version_id })) : null,
447
+ card.applied_at ? h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'Applied At' }), h('span', { text: card.applied_at })) : null,
448
+ card.url ? h('div', { className: 'list-row' }, h('span', { className: 'muted-text', text: 'Posting URL' }), h('a', { className: 'btn btn-sm', href: card.url, text: 'Open Posting' })) : null,
449
+ ),
450
+ card.matched_skills.length > 0
451
+ ? h('div', { className: 'card', text: '' },
452
+ h('h3', { className: 'card-title', text: 'Matched Skills' }),
453
+ h('div', { className: 'filter-bar' }, card.matched_skills.map((s) => h('span', { className: 'pill pill-emerald', text: s }))),
454
+ )
455
+ : null,
456
+ card.true_gaps.length > 0
457
+ ? h('div', { className: 'card' },
458
+ h('h3', { className: 'card-title', text: 'Isolated True Gaps' }),
459
+ h('div', { className: 'filter-bar' }, card.true_gaps.map((s) => h('span', { className: 'pill pill-amber', text: s }))),
460
+ )
461
+ : null,
462
+ card.notes
463
+ ? h('div', { className: 'card' },
464
+ h('h3', { className: 'card-title', text: 'Ledger Notes' }),
465
+ h('pre', { className: 'code-snippet', text: card.notes }),
466
+ )
467
+ : null,
468
+ );
469
+ }
470
+
471
+ function renderKanban() {
472
+ const panel = document.getElementById('view-kanban');
473
+ if (!panel || !state.applications) return;
474
+
475
+ const { kanban, cv_versions: cvVersions, lock, transaction } = state.applications;
476
+ const allItems = kanban.items || [];
477
+ const platforms = [...new Set(allItems.map((i) => i.platform))].sort();
478
+ const cvs = (cvVersions?.versions || []).map((v) => v.cv_version_id);
479
+
480
+ const q = state.kanbanQuery.trim().toLowerCase();
481
+ const matchesFilter = (item) => {
482
+ if (state.kanbanPlatform !== 'all' && item.platform !== state.kanbanPlatform) return false;
483
+ if (state.kanbanCv !== 'all' && item.cv_version_id !== state.kanbanCv) return false;
484
+ if (!q) return true;
485
+ return (
486
+ item.company.toLowerCase().includes(q) ||
487
+ item.role_title.toLowerCase().includes(q) ||
488
+ (item.job_id || '').toLowerCase().includes(q) ||
489
+ item.matched_skills.some((s) => s.toLowerCase().includes(q))
490
+ );
491
+ };
492
+
493
+ const filterBar = h('div', { className: 'filter-bar' },
494
+ h('input', {
495
+ className: 'input',
496
+ type: 'text',
497
+ placeholder: 'Search company, role, job_id, skill...',
498
+ value: state.kanbanQuery,
499
+ onInput: (e) => {
500
+ state.kanbanQuery = e.target.value;
501
+ renderKanbanBoardOnly();
502
+ },
503
+ }),
504
+ h('select', {
505
+ className: 'select',
506
+ onChange: (e) => {
507
+ state.kanbanPlatform = e.target.value;
508
+ renderKanbanBoardOnly();
509
+ },
510
+ },
511
+ h('option', { value: 'all', text: 'All Platforms', selected: state.kanbanPlatform === 'all' }),
512
+ platforms.map((p) => h('option', { value: p, text: p, selected: state.kanbanPlatform === p })),
513
+ ),
514
+ h('select', {
515
+ className: 'select',
516
+ onChange: (e) => {
517
+ state.kanbanCv = e.target.value;
518
+ renderKanbanBoardOnly();
519
+ },
520
+ },
521
+ h('option', { value: 'all', text: 'All Owner CV Versions', selected: state.kanbanCv === 'all' }),
522
+ cvs.map((id) => h('option', { value: id, text: id, selected: state.kanbanCv === id })),
523
+ ),
524
+ kanban.third_party_excluded > 0
525
+ ? h('span', { className: 'pill pill-blue', text: `Isolated ${kanban.third_party_excluded} third-party record(s)` })
526
+ : null,
527
+ lock?.locked ? h('span', { className: 'pill pill-amber', text: 'Ledger Lock Active' }) : h('span', { className: 'pill pill-emerald', text: 'Ledger Lock Clear' }),
528
+ transaction?.pending ? h('span', { className: 'pill pill-rose', text: 'Pending Journal Tx' }) : null,
529
+ );
530
+
531
+ const boardMount = h('div', { id: 'kanban-board-mount' });
532
+ panel.replaceChildren(filterBar, boardMount);
533
+
534
+ function renderKanbanBoardOnly() {
535
+ const mount = document.getElementById('kanban-board-mount');
536
+ if (!mount) return;
537
+ if (allItems.length === 0) {
538
+ mount.replaceChildren(
539
+ h('div', { className: 'card' },
540
+ h('h2', { className: 'card-title', text: 'No Owner Applications Logged Yet' }),
541
+ h('p', { className: 'muted-text', text: 'logs/applications-log.json has 0 owner records in this workspace. Run /demo, /apply-url, or veycraft career record to populate your pipeline.' }),
542
+ ),
543
+ );
544
+ return;
545
+ }
546
+
547
+ const cols = kanban.column_definitions.map((colDef) => {
548
+ const colCards = (kanban.columns[colDef.id] || []).filter(matchesFilter);
549
+ return h('div', { className: 'kanban-col' },
550
+ h('div', { className: 'kanban-col-header' },
551
+ h('span', { text: colDef.label }),
552
+ h('span', { className: 'pill pill-slate', text: String(colCards.length) }),
553
+ ),
554
+ h('div', { className: 'kanban-cards' },
555
+ colCards.map((card) =>
556
+ h('button', { className: 'app-card', type: 'button', onClick: () => openApplicationDrawer(card) },
557
+ h('div', { className: 'app-card-company', text: card.company }),
558
+ h('div', { className: 'app-card-role', text: card.role_title }),
559
+ h('div', { className: 'app-card-meta' },
560
+ h('span', { className: statusPillClass(card.status), text: card.status }),
561
+ h('span', { className: 'pill pill-slate', text: card.platform }),
562
+ card.match_score !== null ? h('span', { className: 'pill pill-emerald', text: `${card.match_score}` }) : null,
563
+ card.has_verified_receipt ? h('span', { className: 'pill pill-blue', text: 'Receipt' }) : null,
564
+ ),
565
+ ),
566
+ ),
567
+ ),
568
+ );
569
+ });
570
+
571
+ mount.replaceChildren(h('div', { className: 'kanban-board' }, cols));
572
+ }
573
+
574
+ renderKanbanBoardOnly();
575
+ }
576
+
577
+ // ---------------- VIEW 3: ANALYTICS ----------------
578
+ async function loadAnalytics(period = 'all') {
579
+ const panel = document.getElementById('view-analytics');
580
+ if (!panel) return;
581
+ state.analyticsPeriod = period;
582
+ panel.replaceChildren(h('div', { className: 'card', text: `Computing deterministic analytics (${period})...` }));
583
+ try {
584
+ const res = await apiGet(`/api/analytics?period=${encodeURIComponent(period)}`);
585
+ state.analytics = res.analytics;
586
+ renderAnalytics();
587
+ } catch (err) {
588
+ panel.replaceChildren(h('div', { className: 'banner banner-error', text: `Analytics error: ${err.message}` }));
589
+ }
590
+ }
591
+
592
+ function formatRateCell(rateObj) {
593
+ if (!rateObj || !rateObj.sample_sufficient || rateObj.rate_pct === null) {
594
+ return `n=${rateObj?.denominator ?? 0} (< MIN_N)`;
595
+ }
596
+ return `${rateObj.rate_pct}% (${rateObj.numerator}/${rateObj.denominator})`;
597
+ }
598
+
599
+ function renderAnalytics() {
600
+ const panel = document.getElementById('view-analytics');
601
+ if (!panel || !state.analytics) return;
602
+
603
+ const a = state.analytics;
604
+ const f = a.funnel;
605
+ const suff = a.sample_sufficiency;
606
+ const monthlyPeriods = (a.timing?.activity?.monthly || []).map((m) => m.period).reverse();
607
+
608
+ const periodBar = h('div', { className: 'filter-bar' },
609
+ h('span', { className: 'field-label', text: 'Period:' }),
610
+ h('button', {
611
+ className: `subtab-btn ${state.analyticsPeriod === 'all' ? 'active' : ''}`,
612
+ text: 'All-Time',
613
+ onClick: () => loadAnalytics('all'),
614
+ }),
615
+ monthlyPeriods.slice(0, 6).map((p) =>
616
+ h('button', {
617
+ className: `subtab-btn ${state.analyticsPeriod === p ? 'active' : ''}`,
618
+ text: p,
619
+ onClick: () => loadAnalytics(p),
620
+ }),
621
+ ),
622
+ );
623
+
624
+ const sufficiencyBanner = h('div', { className: suff.sufficient ? 'banner' : 'banner banner-warn' },
625
+ h('strong', {
626
+ text: suff.sufficient
627
+ ? `Sample Sufficiency Met: n=${suff.submitted_n} submitted applications (MIN_N = ${suff.min_threshold}).`
628
+ : `Honest Sample Guard (MIN_N = ${suff.min_threshold}): Only ${suff.submitted_n} submitted application(s) in "${a.period}" — conversion percentages are suppressed until n >= ${suff.min_threshold}.`,
629
+ }),
630
+ );
631
+
632
+ const kpis = h('div', { className: 'kpi-grid' },
633
+ h('div', { className: 'kpi-card' },
634
+ h('div', { className: 'kpi-value', text: String(f.total_tracked) }),
635
+ h('div', { className: 'kpi-label', text: 'Tracked Roles' }),
636
+ h('div', { className: 'kpi-sub', text: `${f.prepared_only_count} prepared/dry-run` }),
637
+ ),
638
+ h('div', { className: 'kpi-card' },
639
+ h('div', { className: 'kpi-value', text: String(f.submitted_count) }),
640
+ h('div', { className: 'kpi-label', text: 'Submitted' }),
641
+ h('div', { className: 'kpi-sub', text: `${f.pending_active_count} active · ${f.silent_14d_count} silent >=14d (not counted as rejected)` }),
642
+ ),
643
+ h('div', { className: 'kpi-card' },
644
+ h('div', { className: 'kpi-value', text: formatRateCell(f.rates.callback_rate) }),
645
+ h('div', { className: 'kpi-label', text: 'Positive Callback Rate' }),
646
+ h('div', { className: 'kpi-sub', text: `${f.ever_interviewed_count} interviews · ${f.offer_count} offers` }),
647
+ ),
648
+ h('div', { className: 'kpi-card' },
649
+ h('div', { className: 'kpi-value', text: f.avg_match_score !== null ? `${f.avg_match_score}/10` : 'N/A' }),
650
+ h('div', { className: 'kpi-label', text: 'Average Match Score' }),
651
+ h('div', { className: 'kpi-sub', text: a.timing.response_time.sample_sufficient ? `Median reply: ${a.timing.response_time.median_days}d` : 'Median reply: n < 5' }),
652
+ ),
653
+ );
654
+
655
+ const platformCard = h('div', { className: 'card' },
656
+ h('div', { className: 'card-header' },
657
+ h('h2', { className: 'card-title', text: 'Source Platform Breakdown' }),
658
+ ),
659
+ h('p', { className: 'muted-text', text: a.source_performance.causal_humility_note }),
660
+ (a.source_performance.by_platform || []).length === 0
661
+ ? h('p', { className: 'muted-text', text: 'No submitted platform records in this period.' })
662
+ : h('div', { className: 'table-wrap' },
663
+ h('table', { className: 'data-table' },
664
+ h('thead', null, h('tr', null,
665
+ h('th', { text: 'Platform' }),
666
+ h('th', { text: 'Submitted' }),
667
+ h('th', { text: 'Callbacks' }),
668
+ h('th', { text: 'Callback Rate' }),
669
+ h('th', { text: 'Avg Score' }),
670
+ )),
671
+ h('tbody', null, a.source_performance.by_platform.map((row) =>
672
+ h('tr', null,
673
+ h('td', { text: row.platform }),
674
+ h('td', { text: String(row.submitted) }),
675
+ h('td', { text: String(row.callbacks) }),
676
+ h('td', { text: formatRateCell(row.callback_rate) }),
677
+ h('td', { text: row.avg_match_score !== null ? String(row.avg_match_score) : '-' }),
678
+ ),
679
+ )),
680
+ ),
681
+ ),
682
+ );
683
+
684
+ const maxSkillCount = Math.max(1, ...(a.skills_summary.top_skills || []).map((s) => s.count), ...(a.skills_summary.skill_gaps || []).map((s) => s.count));
685
+ const skillsCard = h('div', { className: 'two-col' },
686
+ h('div', { className: 'card' },
687
+ h('h2', { className: 'card-title', text: 'Top Matched Skills' }),
688
+ (a.skills_summary.top_skills || []).length === 0
689
+ ? h('p', { className: 'muted-text', text: 'No skill tags recorded yet.' })
690
+ : (a.skills_summary.top_skills || []).map((s) =>
691
+ h('div', { className: 'meter-row' },
692
+ h('span', { className: 'meter-label', text: s.skill }),
693
+ h('progress', { className: 'meter', max: String(maxSkillCount), value: String(s.count) }),
694
+ h('span', { className: 'pill pill-emerald', text: String(s.count) }),
695
+ ),
696
+ ),
697
+ ),
698
+ h('div', { className: 'card' },
699
+ h('h2', { className: 'card-title', text: 'Recurring True Skill Gaps' }),
700
+ (a.skills_summary.skill_gaps || []).length === 0
701
+ ? h('p', { className: 'muted-text', text: 'No recurring skill gaps recorded yet.' })
702
+ : (a.skills_summary.skill_gaps || []).map((s) =>
703
+ h('div', { className: 'meter-row' },
704
+ h('span', { className: 'meter-label', text: s.skill }),
705
+ h('progress', { className: 'meter', max: String(maxSkillCount), value: String(s.count) }),
706
+ h('span', { className: 'pill pill-amber', text: String(s.count) }),
707
+ ),
708
+ ),
709
+ ),
710
+ );
711
+
712
+ panel.replaceChildren(periodBar, sufficiencyBanner, kpis, platformCard, skillsCard);
713
+ }
714
+
715
+ // ---------------- VIEW 4: STUDIO (IN-MEMORY) ----------------
716
+ function renderStudio() {
717
+ const panel = document.getElementById('view-studio');
718
+ if (!panel) return;
719
+
720
+ const subtabs = [
721
+ ['route', 'Intent Router'],
722
+ ['audit', 'CV Hygiene Audit'],
723
+ ['verify', 'Artifact Fact-Check'],
724
+ ['presubmit', 'Pre-Submit Gate'],
725
+ ];
726
+
727
+ const subtabBar = h('div', { className: 'filter-bar' },
728
+ subtabs.map(([id, label]) =>
729
+ h('button', {
730
+ className: `subtab-btn ${state.studioSubtab === id ? 'active' : ''}`,
731
+ text: label,
732
+ onClick: () => {
733
+ state.studioSubtab = id;
734
+ renderStudio();
735
+ },
736
+ }),
737
+ ),
738
+ h('span', { className: 'pill pill-slate', text: '100% In-Memory · Zero Disk Writes' }),
739
+ );
740
+
741
+ const bodyMount = h('div');
742
+ const resultMount = h('div');
743
+ const workspaceFiles = state.overview?.workspace_files || [];
744
+
745
+ if (state.studioSubtab === 'route') {
746
+ const queryInput = h('input', {
747
+ className: 'input',
748
+ type: 'text',
749
+ value: 'Tailor my CV for this Senior Backend Engineer JD without inventing metrics',
750
+ placeholder: 'Describe any career task in natural language...',
751
+ });
752
+ const runRoute = async () => {
753
+ resultMount.replaceChildren(h('div', { className: 'card', text: 'Routing...' }));
754
+ try {
755
+ const { route } = await apiPost('/api/route', { query: queryInput.value });
756
+ resultMount.replaceChildren(
757
+ h('div', { className: 'card' },
758
+ h('div', { className: 'card-header' },
759
+ h('h3', { className: 'card-title', text: `Matched Intent: ${route.intent}` }),
760
+ route.workflow ? h('code', { className: 'md-inline-code', text: route.workflow }) : null,
761
+ ),
762
+ h('p', { className: 'muted-text', text: `Readiness: ${route.readiness}` }),
763
+ h('p', { className: 'muted-text', text: `Offline Fallback: ${route.fallback}` }),
764
+ h('div', { className: 'filter-bar' },
765
+ (route.skills || []).map((sk) =>
766
+ h('button', {
767
+ className: 'btn btn-sm',
768
+ text: `Skill: ${sk}`,
769
+ onClick: () => {
770
+ state.selectedSkillName = sk;
771
+ switchTab('skills');
772
+ if (state.skillsManifest) selectAndLoadSkill(sk);
773
+ },
774
+ }),
775
+ ),
776
+ ),
777
+ ),
778
+ );
779
+ } catch (err) {
780
+ resultMount.replaceChildren(h('div', { className: 'banner banner-error', text: err.message }));
781
+ }
782
+ };
783
+ bodyMount.replaceChildren(
784
+ h('div', { className: 'card' },
785
+ h('h2', { className: 'card-title', text: 'Deterministic Natural-Language Task Router' }),
786
+ h('div', { className: 'field-group' },
787
+ h('label', { className: 'field-label', text: 'Task Request' }),
788
+ queryInput,
789
+ ),
790
+ h('div', { className: 'filter-bar' },
791
+ h('button', { className: 'btn btn-primary', text: 'Route Request', onClick: runRoute }),
792
+ ),
793
+ ),
794
+ resultMount,
795
+ );
796
+ } else if (state.studioSubtab === 'audit') {
797
+ const cvTextarea = h('textarea', {
798
+ className: 'textarea',
799
+ placeholder: 'Paste Markdown, HTML, or plain-text CV here...',
800
+ text: '# Backend Engineer\n\n- Built idempotent Node.js payment services handling 120k requests/day with 99.95% uptime.\n- Reduced PostgreSQL query p95 latency by 38% across 14 production services.\n- Automated CI validation pipelines saving 6 hours/week across 12 engineers.\n',
801
+ });
802
+ const fileSelect = h('select', { className: 'select' },
803
+ h('option', { value: '', text: '-- Or audit an existing workspace file --' }),
804
+ workspaceFiles.filter((f) => ['md', 'txt', 'html', 'doc', 'docx'].includes(f.ext)).map((f) =>
805
+ h('option', { value: f.rel_path, text: f.rel_path }),
806
+ ),
807
+ );
808
+ const runAudit = async () => {
809
+ resultMount.replaceChildren(h('div', { className: 'card', text: 'Auditing CV hygiene...' }));
810
+ try {
811
+ const payload = fileSelect.value ? { path: fileSelect.value } : { text: cvTextarea.value, format: 'md' };
812
+ const { audit } = await apiPost('/api/audit', payload);
813
+ resultMount.replaceChildren(
814
+ h('div', { className: 'card' },
815
+ h('div', { className: 'card-header' },
816
+ h('h3', { className: 'card-title', text: `CV Hygiene Score: ${audit.total_score}/100` }),
817
+ h('span', { className: audit.total_score >= 75 ? 'pill pill-emerald' : 'pill pill-amber', text: audit.length_status }),
818
+ ),
819
+ h('div', { className: 'kpi-grid' },
820
+ h('div', { className: 'kpi-card' }, h('div', { className: 'kpi-value', text: `${audit.tone_score}/25` }), h('div', { className: 'kpi-label', text: 'Tone & Anti-Slop' }), h('div', { className: 'kpi-sub', text: `${audit.cliches_found.length} cliches · ${audit.em_dash_count} em-dashes` })),
821
+ h('div', { className: 'kpi-card' }, h('div', { className: 'kpi-value', text: `${audit.impact_score}/30` }), h('div', { className: 'kpi-label', text: 'Quantified Impact' }), h('div', { className: 'kpi-sub', text: `${audit.quantified_bullets}/${audit.bullet_count} bullets · ${audit.total_metrics} metrics` })),
822
+ h('div', { className: 'kpi-card' }, h('div', { className: 'kpi-value', text: `${audit.length_score}/25` }), h('div', { className: 'kpi-label', text: '1-Page Fit' }), h('div', { className: 'kpi-sub', text: `${audit.word_count} words · ${audit.line_count} lines` })),
823
+ h('div', { className: 'kpi-card' }, h('div', { className: 'kpi-value', text: `${audit.hygiene_score}/20` }), h('div', { className: 'kpi-label', text: 'Link & PII Hygiene' }), h('div', { className: 'kpi-sub', text: `Status: ${audit.hygiene_label}` })),
824
+ ),
825
+ audit.cliches_found.length > 0
826
+ ? h('p', { className: 'muted-text', text: `Flagged AI Cliches: ${audit.cliches_found.join(', ')}` })
827
+ : null,
828
+ ),
829
+ );
830
+ } catch (err) {
831
+ resultMount.replaceChildren(h('div', { className: 'banner banner-error', text: err.message }));
832
+ }
833
+ };
834
+ bodyMount.replaceChildren(
835
+ h('div', { className: 'card' },
836
+ h('h2', { className: 'card-title', text: 'Offline CV Hygiene Audit' }),
837
+ h('div', { className: 'filter-bar' }, fileSelect),
838
+ cvTextarea,
839
+ h('div', { className: 'filter-bar' },
840
+ h('button', { className: 'btn btn-primary', text: 'Run CV Audit', onClick: runAudit }),
841
+ ),
842
+ ),
843
+ resultMount,
844
+ );
845
+ } else if (state.studioSubtab === 'verify') {
846
+ const artifactArea = h('textarea', {
847
+ className: 'textarea',
848
+ placeholder: 'Paste tailored HTML, Markdown, or TXT artifact...',
849
+ text: '<!doctype html><html><body><h1>Resume</h1><p>Reduced payment webhook p95 latency by 38% across 3 regions.</p></body></html>',
850
+ });
851
+ const metricsInput = h('input', { className: 'input', type: 'text', value: '38%, 3', placeholder: 'Comma-separated allowed metrics (e.g. 38%, $4.2M)' });
852
+ const forbiddenInput = h('input', { className: 'input', type: 'text', value: 'Kubernetes, Rust', placeholder: 'Comma-separated forbidden skills' });
853
+
854
+ const runVerify = async () => {
855
+ resultMount.replaceChildren(h('div', { className: 'card', text: 'Verifying artifact...' }));
856
+ try {
857
+ const allowed = metricsInput.value.split(',').map((s) => s.trim()).filter(Boolean);
858
+ const forbidden = forbiddenInput.value.split(',').map((s) => s.trim()).filter(Boolean);
859
+ const { verification } = await apiPost('/api/verify', {
860
+ text: artifactArea.value,
861
+ format: 'html',
862
+ facts_json: { ground_truth_metrics: allowed, forbidden_skills: forbidden },
863
+ });
864
+ const first = verification.results[0];
865
+ resultMount.replaceChildren(
866
+ h('div', { className: 'card' },
867
+ h('div', { className: 'card-header' },
868
+ h('h3', { className: 'card-title', text: verification.ok ? 'Artifact Verification PASSED' : 'Artifact Verification BLOCKED' }),
869
+ h('span', { className: verification.ok ? 'pill pill-emerald' : 'pill pill-rose', text: `${verification.error_count} error(s)` }),
870
+ ),
871
+ first.errors.length === 0
872
+ ? h('p', { className: 'muted-text', text: '0 unresolved placeholders, 0 banned cliches, 0 prose em-dashes, and 0 unverified metrics or forbidden skills.' })
873
+ : h('div', { className: 'list-stack' }, first.errors.map((e) => h('div', { className: 'banner banner-error', text: e }))),
874
+ ),
875
+ );
876
+ } catch (err) {
877
+ resultMount.replaceChildren(h('div', { className: 'banner banner-error', text: err.message }));
878
+ }
879
+ };
880
+ bodyMount.replaceChildren(
881
+ h('div', { className: 'card' },
882
+ h('h2', { className: 'card-title', text: 'Anti-Hallucination & Placeholder Verifier' }),
883
+ h('div', { className: 'form-grid' },
884
+ h('div', { className: 'field-group' }, h('label', { className: 'field-label', text: 'Verified Metrics Allowlist' }), metricsInput),
885
+ h('div', { className: 'field-group' }, h('label', { className: 'field-label', text: 'Forbidden / Unclaimed Skills' }), forbiddenInput),
886
+ ),
887
+ artifactArea,
888
+ h('div', { className: 'filter-bar' },
889
+ h('button', { className: 'btn btn-primary', text: 'Verify Artifact', onClick: runVerify }),
890
+ ),
891
+ ),
892
+ resultMount,
893
+ );
894
+ } else {
895
+ const companyIn = h('input', { className: 'input', type: 'text', placeholder: 'Company (e.g. Acme Payments)' });
896
+ const titleIn = h('input', { className: 'input', type: 'text', placeholder: 'Role Title (e.g. Senior Backend Engineer)' });
897
+ const platformIn = h('input', { className: 'input', type: 'text', value: 'greenhouse', placeholder: 'Platform (e.g. greenhouse, linkedin)' });
898
+ const draftArea = h('textarea', {
899
+ className: 'textarea',
900
+ text: 'Hi hiring team, sharing my backend engineering application highlighting 38% webhook latency improvements on Node.js and PostgreSQL.',
901
+ });
902
+ const runPreSubmit = async () => {
903
+ resultMount.replaceChildren(h('div', { className: 'card', text: 'Evaluating pre-submit guardrails...' }));
904
+ try {
905
+ const { evaluation } = await apiPost('/api/pre-submit', {
906
+ company: companyIn.value,
907
+ title: titleIn.value,
908
+ platform: platformIn.value,
909
+ text: draftArea.value,
910
+ max_words: 75,
911
+ });
912
+ resultMount.replaceChildren(
913
+ h('div', { className: 'card' },
914
+ h('div', { className: 'card-header' },
915
+ h('h3', { className: 'card-title', text: evaluation.allowed ? 'Pre-Submit Gate PASSED (Requires Human APPROVE)' : 'Pre-Submit Gate BLOCKED' }),
916
+ h('span', { className: evaluation.allowed ? 'pill pill-emerald' : 'pill pill-rose', text: `dry_run: ${evaluation.dry_run}` }),
917
+ ),
918
+ evaluation.violations.length === 0
919
+ ? h('p', { className: 'muted-text', text: `Daily cap OK (${evaluation.checks.daily_cap.today_counted}/${evaluation.checks.daily_cap.effective_cap}), deduplication OK, blacklist OK, draft ${evaluation.checks.draft?.word_count || 0}/75 words OK.` })
920
+ : h('div', { className: 'list-stack' }, evaluation.violations.map((v) => h('div', { className: 'banner banner-error', text: `${v.code}: ${v.message}` }))),
921
+ ),
922
+ );
923
+ } catch (err) {
924
+ resultMount.replaceChildren(h('div', { className: 'banner banner-error', text: err.message }));
925
+ }
926
+ };
927
+ bodyMount.replaceChildren(
928
+ h('div', { className: 'card' },
929
+ h('h2', { className: 'card-title', text: 'Pre-Submit Cap, Dedup & <= 75-Word Outreach Gate' }),
930
+ h('div', { className: 'form-grid' },
931
+ h('div', { className: 'field-group' }, h('label', { className: 'field-label', text: 'Company' }), companyIn),
932
+ h('div', { className: 'field-group' }, h('label', { className: 'field-label', text: 'Role Title' }), titleIn),
933
+ h('div', { className: 'field-group' }, h('label', { className: 'field-label', text: 'Platform' }), platformIn),
934
+ ),
935
+ draftArea,
936
+ h('div', { className: 'filter-bar' },
937
+ h('button', { className: 'btn btn-primary', text: 'Evaluate Pre-Submit Gate', onClick: runPreSubmit }),
938
+ ),
939
+ ),
940
+ resultMount,
941
+ );
942
+ }
943
+
944
+ panel.replaceChildren(subtabBar, bodyMount);
945
+ }
946
+
947
+ // ---------------- VIEW 5: SKILLS & GUARDRAILS ----------------
948
+ async function loadSkills() {
949
+ const panel = document.getElementById('view-skills');
950
+ if (!panel) return;
951
+ panel.replaceChildren(h('div', { className: 'card', text: 'Loading 56 Markdown skill playbooks...' }));
952
+ try {
953
+ state.skillsManifest = await apiGet('/api/skills');
954
+ const initialSkill = state.selectedSkillName || state.skillsManifest.skills[0]?.name;
955
+ renderSkillsShell();
956
+ if (initialSkill) await selectAndLoadSkill(initialSkill);
957
+ } catch (err) {
958
+ panel.replaceChildren(h('div', { className: 'banner banner-error', text: `Failed loading skills: ${err.message}` }));
959
+ }
960
+ }
961
+
962
+ async function selectAndLoadSkill(name) {
963
+ state.selectedSkillName = name;
964
+ for (const btn of document.querySelectorAll('.skill-item-btn')) {
965
+ btn.classList.toggle('active', btn.dataset.skill === name);
966
+ }
967
+ const reader = document.getElementById('skill-reader-pane');
968
+ if (!reader) return;
969
+ reader.replaceChildren(h('p', { className: 'muted-text', text: `Loading veycraft://skill/${name}...` }));
970
+
971
+ try {
972
+ let payload = state.skillCache.get(name);
973
+ if (!payload) {
974
+ payload = await apiGet(`/api/skills/${encodeURIComponent(name)}`);
975
+ state.skillCache.set(name, payload);
976
+ }
977
+ const sk = payload.skill;
978
+ reader.replaceChildren(
979
+ h('div', { className: 'card-header' },
980
+ h('div', null,
981
+ h('h2', { className: 'card-title', text: `${sk.name} (v${sk.version})` }),
982
+ h('div', { className: 'subtitle', text: `${payload.uri} · ${sk.path}` }),
983
+ ),
984
+ h('button', { className: 'btn btn-sm', text: 'Copy URI', onClick: () => copyText(payload.uri, `Copied ${payload.uri}`) }),
985
+ ),
986
+ h('p', { className: 'muted-text', text: sk.description }),
987
+ h('div', { className: 'filter-bar' },
988
+ h('span', { className: 'pill pill-emerald', text: `category: ${sk.category || 'core'}` }),
989
+ ...(sk.requires_mcp || []).map((m) => h('span', { className: 'pill pill-blue', text: `mcp: ${m}` })),
990
+ ),
991
+ renderMarkdownSafe(payload.content),
992
+ );
993
+ } catch (err) {
994
+ reader.replaceChildren(h('div', { className: 'banner banner-error', text: err.message }));
995
+ }
996
+ }
997
+
998
+ function renderSkillsShell() {
999
+ const panel = document.getElementById('view-skills');
1000
+ if (!panel || !state.skillsManifest) return;
1001
+
1002
+ const allSkills = state.skillsManifest.skills || [];
1003
+ const categories = [...new Set(allSkills.map((s) => s.category || 'core'))].sort();
1004
+
1005
+ const filterBar = h('div', { className: 'filter-bar' },
1006
+ h('input', {
1007
+ className: 'input',
1008
+ type: 'text',
1009
+ placeholder: 'Search 56 skills by name, trigger, or keyword...',
1010
+ value: state.skillsQuery,
1011
+ onInput: (e) => {
1012
+ state.skillsQuery = e.target.value;
1013
+ renderSkillListItems();
1014
+ },
1015
+ }),
1016
+ h('select', {
1017
+ className: 'select',
1018
+ onChange: (e) => {
1019
+ state.skillsCategory = e.target.value;
1020
+ renderSkillListItems();
1021
+ },
1022
+ },
1023
+ h('option', { value: 'all', text: 'All Categories' }),
1024
+ categories.map((c) => h('option', { value: c, text: c, selected: state.skillsCategory === c })),
1025
+ ),
1026
+ h('select', {
1027
+ className: 'select',
1028
+ onChange: (e) => {
1029
+ state.skillsMcp = e.target.value;
1030
+ renderSkillListItems();
1031
+ },
1032
+ },
1033
+ h('option', { value: 'all', text: 'Any MCP Requirement' }),
1034
+ h('option', { value: 'none', text: 'Offline Only (mcp: none)' }),
1035
+ h('option', { value: 'playwright', text: 'Uses Playwright MCP' }),
1036
+ ),
1037
+ );
1038
+
1039
+ const listPane = h('div', { id: 'skills-list-pane', className: 'skills-list-pane' });
1040
+ const readerPane = h('div', { id: 'skill-reader-pane', className: 'card' });
1041
+
1042
+ const invariantsCard = state.skillsManifest.invariants_text
1043
+ ? h('div', { className: 'card' },
1044
+ h('div', { className: 'card-header' },
1045
+ h('h2', { className: 'card-title', text: 'Non-Negotiable Safety Invariants (config/invariants.txt)' }),
1046
+ h('span', { className: 'pill pill-emerald', text: 'veycraft://invariants' }),
1047
+ ),
1048
+ h('pre', { className: 'code-snippet', text: state.skillsManifest.invariants_text }),
1049
+ )
1050
+ : null;
1051
+
1052
+ panel.replaceChildren(filterBar, h('div', { className: 'skills-layout' }, listPane, readerPane), invariantsCard);
1053
+
1054
+ function renderSkillListItems() {
1055
+ const q = state.skillsQuery.trim().toLowerCase();
1056
+ const filtered = allSkills.filter((s) => {
1057
+ if (state.skillsCategory !== 'all' && (s.category || 'core') !== state.skillsCategory) return false;
1058
+ if (state.skillsMcp !== 'all' && !(s.requires_mcp || []).includes(state.skillsMcp)) return false;
1059
+ if (!q) return true;
1060
+ return (
1061
+ s.name.toLowerCase().includes(q) ||
1062
+ (s.description || '').toLowerCase().includes(q) ||
1063
+ (s.triggers || []).some((t) => t.toLowerCase().includes(q))
1064
+ );
1065
+ });
1066
+
1067
+ listPane.replaceChildren(
1068
+ ...filtered.map((s) =>
1069
+ h('button', {
1070
+ className: `skill-item-btn ${state.selectedSkillName === s.name ? 'active' : ''}`,
1071
+ type: 'button',
1072
+ dataset: { skill: s.name },
1073
+ onClick: () => selectAndLoadSkill(s.name),
1074
+ },
1075
+ h('div', { className: 'app-card-role', text: s.name }),
1076
+ h('div', { className: 'muted-text', text: (s.triggers || []).slice(0, 2).join(' · ') || s.path }),
1077
+ ),
1078
+ ),
1079
+ );
1080
+ }
1081
+
1082
+ renderSkillListItems();
1083
+ }
1084
+
1085
+ // ---------------- BOOTSTRAP ----------------
1086
+ async function refreshAll() {
1087
+ try {
1088
+ state.overview = await apiGet('/api/overview');
1089
+ renderOverview();
1090
+ if (state.activeTab === 'kanban') await loadKanban();
1091
+ if (state.activeTab === 'analytics') await loadAnalytics(state.analyticsPeriod);
1092
+ if (state.activeTab === 'skills') await loadSkills();
1093
+ } catch (err) {
1094
+ const panel = document.getElementById('view-overview');
1095
+ if (panel) {
1096
+ panel.replaceChildren(h('div', { className: 'banner banner-error', text: `Failed loading overview: ${err.message}` }));
1097
+ }
1098
+ }
1099
+ }
1100
+
1101
+ document.addEventListener('DOMContentLoaded', () => {
1102
+ for (const btn of document.querySelectorAll('.tab-btn')) {
1103
+ btn.addEventListener('click', () => switchTab(btn.dataset.tab));
1104
+ }
1105
+ const refreshBtn = document.getElementById('refresh-btn');
1106
+ if (refreshBtn) {
1107
+ refreshBtn.addEventListener('click', async () => {
1108
+ await refreshAll();
1109
+ showToast('Refreshed local workspace snapshot');
1110
+ });
1111
+ }
1112
+ refreshAll();
1113
+ });