create-heresay 0.1.0 → 0.2.2

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.
@@ -148,17 +148,21 @@
148
148
 
149
149
  function route() {
150
150
  stopTimer();
151
- var parts = location.hash.replace(/^#\/?/, '').split('/').filter(Boolean);
151
+ var hash = location.hash.replace(/^#\/?/, '');
152
+ var query = new URLSearchParams(hash.split('?')[1] || '');
153
+ var parts = hash.split('?')[0].split('/').filter(Boolean);
152
154
  document.querySelectorAll('[data-nav]').forEach(function (a) {
153
155
  a.setAttribute('aria-current', String((parts[0] === 'team') === (a.dataset.nav === 'team')));
154
156
  });
155
157
  var view = $('view');
156
158
  view.textContent = '';
157
159
  if (parts[0] === 'team') return teamView(view);
158
- if (parts[0] === 'new') return newAppView(view, parts[1]);
160
+ if (parts[0] === 'connect') return connectView(view, query);
161
+ if (parts[0] === 'new') return newAppView(view, parts[1], query);
159
162
  if (parts[0] === 'apps' && parts[1]) {
160
163
  return withProject(parts[1], function (p) {
161
164
  if (parts[2] === 'setup') setupView(view, p);
165
+ else if (parts[2] === 'delete') deleteView(view, p);
162
166
  else reportsView(view, p);
163
167
  });
164
168
  }
@@ -177,9 +181,9 @@
177
181
  var PLATFORMS = [
178
182
  { id: 'web', label: 'Web', note: 'Any site or web app', ready: true,
179
183
  icon: '<circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.6 3.8 5.6 3.8 9s-1.3 6.4-3.8 9c-2.5-2.6-3.8-5.6-3.8-9S9.5 5.6 12 3z"/>' },
180
- { id: 'ios', label: 'iOS', note: 'iPhone and iPad',
184
+ { id: 'ios', label: 'iOS', note: 'iPhone and iPad, SwiftUI', ready: true, apple: true,
181
185
  icon: '<rect x="6.5" y="2.5" width="11" height="19" rx="2.5"/><path d="M10.5 18.5h3"/>' },
182
- { id: 'macos', label: 'macOS', note: 'Mac apps',
186
+ { id: 'macos', label: 'macOS', note: 'Mac apps, SwiftUI', ready: true, apple: true,
183
187
  icon: '<rect x="3" y="4" width="18" height="12" rx="2"/><path d="M1.5 19.5h21"/>' },
184
188
  { id: 'android', label: 'Android', note: 'Phones and tablets',
185
189
  icon: '<rect x="5" y="8" width="14" height="11" rx="2"/><path d="M8 8a4 4 0 0 1 8 0M8.5 4.5l1 1.5M15.5 4.5l-1 1.5"/>' },
@@ -209,14 +213,17 @@
209
213
  var grid = el('div', { class: 'apps' });
210
214
  projects.forEach(function (p) {
211
215
  var count = el('span', { class: 'count', text: ' ' });
212
- grid.appendChild(el('a', { class: 'app-card', href: '#/apps/' + p.id }, [
216
+ var card = el('a', { class: 'app-card', href: '#/apps/' + p.id }, [
213
217
  icon(platformOf(p.platform)),
214
218
  el('div', {}, [el('b', { text: p.name }), el('span', { class: 'mute', text: platformOf(p.platform).label + (p.framework ? ' · ' + frameworkLabel(p.framework) : '') })]),
215
219
  count,
216
- ]));
220
+ ]);
221
+ grid.appendChild(card);
217
222
  api('GET', '/projects/' + p.id + '/reports').then(function (r) {
218
223
  var open = r.reports.filter(function (x) { return x.status === 'open'; }).length;
219
- count.textContent = r.reports.length ? (open ? open + ' open' : 'All answered') : 'No reports yet';
224
+ // No report yet means setup isn't proven: send them back to finish it.
225
+ if (!r.reports.length && !p.sdk_seen && !p.code_found) { card.href = '#/apps/' + p.id + '/setup'; count.textContent = 'Setup not finished'; count.className = 'count todo'; return; }
226
+ count.textContent = !r.reports.length ? 'No reports yet' : open ? open + ' open' : 'All answered';
220
227
  if (open) count.className = 'count on';
221
228
  });
222
229
  });
@@ -233,21 +240,39 @@
233
240
  ];
234
241
  function frameworkLabel(id) { var f = FRAMEWORKS.filter(function (x) { return x[0] === id; })[0]; return f ? f[1] : id; }
235
242
 
236
- function stepper(active) {
237
- var steps = ['Platform', 'Details', 'Install', 'Test'];
238
- return el('ol', { class: 'steps' }, steps.map(function (s, i) {
239
- return el('li', { class: i + 1 < active ? 'done' : i + 1 === active ? 'now' : '' }, [el('span', { text: String(i + 1) }), s]);
243
+ /**
244
+ * The four steps. Earlier ones are links, so you can go back and change things; later ones
245
+ * aren't, because each step needs the one before it. `tested` marks the last step done.
246
+ */
247
+ function stepper(active, p, tested) {
248
+ var q = p ? '?app=' + p.id : '';
249
+ var links = ['#/new' + q, p ? '#/new/' + p.platform + q : null, p ? '#/apps/' + p.id + '/setup' : null, null];
250
+ var names = ['Platform', 'Details', 'Install', 'Test'];
251
+ return el('ol', { class: 'steps' }, names.map(function (s, i) {
252
+ var n = i + 1;
253
+ var cls = n < active || (tested && n <= 4) ? 'done' : n === active ? 'now' : '';
254
+ var inner = [el('span', { text: tested && n <= 4 ? '✓' : String(n) }), s];
255
+ var back = n < active && links[i];
256
+ return el('li', { class: cls }, back ? [el('a', { href: links[i], 'aria-label': 'Back to ' + s }, inner)] : inner);
240
257
  }));
241
258
  }
242
259
 
243
- function newAppView(view, platform) {
260
+ /** Adding an app, or with ?app=<id>, going back to change one that already exists. */
261
+ function newAppView(view, platform, query) {
262
+ var editId = query && query.get('app');
263
+ if (editId) return withProject(editId, function (p) { drawNewApp(view, platform, p); });
264
+ drawNewApp(view, platform, null);
265
+ }
266
+
267
+ function drawNewApp(view, platform, editing) {
268
+ var q = editing ? '?app=' + editing.id : '';
244
269
  if (!platform) {
245
- view.appendChild(stepper(1));
270
+ view.appendChild(stepper(1, editing));
246
271
  view.appendChild(el('h1', { text: 'What are you adding Heresay to?' }));
247
272
  var grid = el('div', { class: 'platforms' });
248
273
  PLATFORMS.forEach(function (p) {
249
274
  grid.appendChild(el(p.ready ? 'a' : 'div', {
250
- class: 'platform' + (p.ready ? '' : ' soon'), href: p.ready ? '#/new/' + p.id : null,
275
+ class: 'platform' + (p.ready ? '' : ' soon') + (editing && editing.platform === p.id ? ' current' : ''), href: p.ready ? '#/new/' + p.id + q : null,
251
276
  'aria-disabled': p.ready ? null : 'true',
252
277
  }, [icon(p), el('b', { text: p.label }), el('span', { class: 'mute', text: p.note }), p.ready ? null : el('span', { class: 'tag', text: 'Soon' })]));
253
278
  });
@@ -256,10 +281,11 @@
256
281
  return;
257
282
  }
258
283
 
259
- view.appendChild(stepper(2));
260
- view.appendChild(el('h1', { text: 'About your web app' }));
284
+ view.appendChild(stepper(2, editing));
285
+ var native = !!platformOf(platform).apple;
286
+ view.appendChild(el('h1', { text: 'About your ' + platformOf(platform).label + ' app' }));
261
287
  var err = el('p', { class: 'err', role: 'alert' });
262
- var fw = 'unknown';
288
+ var fw = editing && editing.framework && !editing.framework_detected ? editing.framework : 'unknown';
263
289
  var chips = el('div', { class: 'chips', role: 'radiogroup', 'aria-label': 'Framework' });
264
290
  FRAMEWORKS.forEach(function (f) {
265
291
  chips.appendChild(el('button', {
@@ -270,24 +296,38 @@
270
296
  },
271
297
  }));
272
298
  });
273
- var form = el('form', { class: 'form' }, [
299
+ var form = el('form', { class: 'form' }, native ? [
300
+ el('label', {}, ['Name', el('input', { name: 'name', required: true, maxlength: '80', placeholder: 'Acme for ' + platformOf(platform).label, autocomplete: 'off' })]),
301
+ el('p', { class: 'hint', text: 'Native apps have no web address to lock the key to, so any copy of your app can send reports. The per-device, per-network and per-app rate limits still apply.' }),
302
+ el('div', { class: 'row' }, [el('a', { class: 'btn ghost', href: '#/new' + q, text: 'Back' }), el('button', { class: 'btn primary', text: editing ? 'Save and continue' : 'Create app' })]),
303
+ err,
304
+ ] : [
274
305
  el('label', {}, ['Name', el('input', { name: 'name', required: true, maxlength: '80', placeholder: 'Acme web', autocomplete: 'off' })]),
275
306
  el('div', { class: 'field' }, [el('span', { class: 'lbl' }, ['Built with ', el('span', { class: 'opt', text: 'optional' })]), chips,
276
307
  el('p', { class: 'hint', text: 'Only changes the install steps we show. Not sure? Leave it: your coding agent can work it out, and the general steps work everywhere.' })]),
277
308
  el('label', {}, ['Where it runs', el('textarea', { name: 'origins', rows: '3', placeholder: 'https://app.example.com\nhttp://localhost:3000' })]),
278
309
  el('p', { class: 'hint', text: 'One address per line: your live site and anywhere you test it. Only these sites can send reports with this app’s key. Leave it empty to allow any site while you try things out.' }),
279
- el('div', { class: 'row' }, [el('a', { class: 'btn ghost', href: '#/new', text: 'Back' }), el('button', { class: 'btn primary', text: 'Create app' })]),
310
+ el('div', { class: 'row' }, [el('a', { class: 'btn ghost', href: '#/new' + q, text: 'Back' }), el('button', { class: 'btn primary', text: editing ? 'Save and continue' : 'Create app' })]),
280
311
  err,
281
312
  ]);
282
313
  form.onsubmit = function (e) {
283
314
  e.preventDefault();
284
315
  err.textContent = '';
285
- var origins = form.origins.value.split(/[\s,]+/).map(function (s) { return s.trim(); }).filter(Boolean);
286
- api('POST', '/projects', { name: form.name.value, platform: platform, framework: fw === 'unknown' ? null : fw, allowed_origins: origins })
287
- .then(function (b) { projects.push(b.project); location.hash = '#/apps/' + b.project.id + '/setup'; })
316
+ var origins = native ? [] : form.origins.value.split(/[\s,]+/).map(function (s) { return s.trim(); }).filter(Boolean);
317
+ var body = { name: form.name.value, platform: platform, framework: native ? 'swiftui' : (fw === 'unknown' ? null : fw), allowed_origins: origins };
318
+ // Editing keeps the key, so a line already pasted into the app keeps working.
319
+ (editing ? api('PATCH', '/projects/' + editing.id, body) : api('POST', '/projects', body))
320
+ .then(function (b) {
321
+ projects = projects.filter(function (x) { return x.id !== b.project.id; }).concat([b.project]);
322
+ location.hash = '#/apps/' + b.project.id + '/setup';
323
+ })
288
324
  .catch(function (x) { err.textContent = x.message; });
289
325
  };
290
326
  view.appendChild(form);
327
+ if (editing) {
328
+ form.name.value = editing.name;
329
+ if (!native) form.origins.value = editing.allowed_origins.join('\n');
330
+ }
291
331
  form.name.focus();
292
332
  }
293
333
 
@@ -314,7 +354,35 @@
314
354
  }[fw] || 'Load this once on every page, as late as you can, for example before <code>&lt;/body&gt;</code>:', tag(p)];
315
355
  }
316
356
 
357
+ var SWIFT_PACKAGE = 'https://github.com/Sibhimanyu/heresay-swift';
358
+
359
+ function appleByHand(p) {
360
+ var mac = p.platform === 'macos';
361
+ var code = [
362
+ 'import SwiftUI',
363
+ 'import Heresay',
364
+ '',
365
+ '@main',
366
+ 'struct MyApp: App {',
367
+ ' init() {',
368
+ ' Heresay.configure(key: "' + p.key + '", url: URL(string: "' + location.origin + '")!)',
369
+ ' }',
370
+ ' var body: some Scene {',
371
+ ' WindowGroup {',
372
+ mac ? ' ContentView().heresay()' : ' ContentView().heresayReportButton()',
373
+ ' }',
374
+ ].concat(mac ? [' .commands { HeresayCommands() }'] : []).concat([' }', '}']).join('\n');
375
+ return [
376
+ el('p', { html: '<b>1.</b> In Xcode, choose <b>File › Add Package Dependencies…</b> and paste:' }),
377
+ codeBlock(SWIFT_PACKAGE),
378
+ el('p', { html: '<b>2.</b> Configure it once, where your app starts, and add the ' + (mac ? 'menu item (Help › Report a Problem…)' : 'Report button') + ':' }),
379
+ codeBlock(code),
380
+ el('p', { class: 'hint', html: 'Optional: <code>Heresay.identify(id:label:)</code> after sign-in, <code>Heresay.setScreen("Checkout")</code> as people move around, and <code>Heresay.present()</code> to open it from your own button. Needs iOS 16 or macOS 13.' }),
381
+ ];
382
+ }
383
+
317
384
  function byHand(p) {
385
+ if (platformOf(p.platform).apple) return appleByHand(p);
318
386
  var fw = p.framework;
319
387
  if (fw && fw !== 'other') {
320
388
  var one = placement(fw, p);
@@ -337,34 +405,67 @@
337
405
  ];
338
406
  }
339
407
 
340
- function agentPromptFor(p) {
408
+ /** One prompt that connects the repo, installs Heresay and waits for the test report. */
409
+ function onePrompt(p, token) {
410
+ var apple = platformOf(p.platform).apple;
341
411
  return [
342
- 'Add Heresay, an in-app feedback button, to this app.',
412
+ 'Set up Heresay, in-app feedback, in this repo. Do these steps in order.',
413
+ '',
414
+ '1. Connect this repo to Heresay. This adds .mcp.json, a Heresay skill and an AGENTS.md section, and saves the token in ~/.heresay, outside the repo. Do not copy the token into any file.',
415
+ '',
416
+ ' npx -y heresay@0 connect --url ' + location.origin + ' --token ' + token + ' --yes',
343
417
  '',
344
- '1. Load this script once on every page, as late as possible: before </body>, or the framework\'s equivalent (for Next.js, next/script with strategy="afterInteractive" in the root layout).',
418
+ '2. Print the install steps for this app and follow them. They include the app\'s key and exactly where the code goes' + (apple ? ' (a Swift package and one line of setup).' : ', for any framework.'),
345
419
  '',
346
- ' ' + tag(p),
420
+ ' npx -y heresay@0 install ' + p.id,
347
421
  '',
348
- '2. If the app has signed-in users, call window.Heresay?.identify({ id: user.id, label: user.name }) after sign-in, and window.Heresay?.identify() after sign-out.',
349
- '3. If the app has a version number (for example package.json "version"), add data-version="<version>" to the tag.',
350
- '4. If screens change without the URL changing, call window.Heresay?.setScreen("<screen name>") on each change.',
422
+ '3. Verify the install. This finds the app\'s key in the code and tells the Heresay dashboard, which is waiting for it:',
351
423
  '',
352
- 'Change nothing else. Reference: ' + location.origin + '/docs.html',
424
+ ' npx -y heresay@0 check ' + p.id,
425
+ '',
426
+ ' You are done when it prints "installed": true. If it doesn\'t, fix what it says and run it again.',
427
+ '',
428
+ 'Change nothing else in the app.',
353
429
  ].join('\n');
354
430
  }
355
431
 
356
432
  function setupView(view, p) {
357
- view.appendChild(stepper(3));
358
- view.appendChild(el('div', { class: 'head' }, [
359
- el('h1', { text: 'Put Heresay in ' + p.name }),
360
- el('a', { class: 'btn ghost', href: '#/apps/' + p.id, text: 'Go to reports' }),
361
- ]));
433
+ var apple = platformOf(p.platform).apple;
434
+ var steps = stepper(3, p, false);
435
+ view.appendChild(steps);
436
+ view.appendChild(el('div', { class: 'head' }, [el('h1', { text: 'Put Heresay in ' + p.name })]));
437
+
438
+ // The agent route: one prompt by default, with the same thing as two steps for people who
439
+ // would rather run the command themselves.
440
+ var promptBox = el('div');
441
+ var getPrompt = el('button', { class: 'btn primary', type: 'button', text: 'Get the prompt' });
442
+ getPrompt.onclick = function () {
443
+ getPrompt.disabled = true;
444
+ getPrompt.textContent = 'Making a token…';
445
+ // No repo yet: the token binds to whichever repo the agent runs it in.
446
+ api('POST', '/agent-tokens', { app_ids: [p.id] }).then(function (b) {
447
+ getPrompt.remove();
448
+ promptBox.appendChild(codeBlock(onePrompt(p, b.token)));
449
+ promptBox.appendChild(el('p', { class: 'hint', html: 'It carries a token for this app that works only in the first repo that uses it. You can revoke it under <a href="#/connect">Connected repos</a>.' }));
450
+ }).catch(function (x) {
451
+ getPrompt.disabled = false;
452
+ getPrompt.textContent = 'Get the prompt';
453
+ promptBox.appendChild(el('p', { class: 'err', text: x.message }));
454
+ });
455
+ };
456
+ promptBox.appendChild(getPrompt);
362
457
 
363
- // Without a known framework, the agent is the better default: it can see the code.
364
- var agentFirst = !p.framework || p.framework === 'other';
458
+ var agentFirst = !apple && (!p.framework || p.framework === 'other');
365
459
  var panes = { hand: el('div', { hidden: agentFirst }, byHand(p)), agent: el('div', { hidden: !agentFirst }, [
366
- el('p', { text: 'Paste this into Claude Code, Cursor or any coding agent, in your app’s folder:' }),
367
- codeBlock(agentPromptFor(p)),
460
+ el('p', { text: 'Paste one prompt into your coding agent (Claude Code, Cursor, Codex, …), opened in your app’s repo. It connects the repo, installs Heresay, and verifies it.' }),
461
+ promptBox,
462
+ el('details', { class: 'where' }, [el('summary', { text: 'Or do it in two steps' }),
463
+ el('ol', { class: 'agent-steps' }, [
464
+ el('li', {}, [el('b', { text: 'In your app’s repo, run:' }), codeBlock('npx heresay connect --url ' + location.origin),
465
+ el('p', { class: 'hint', text: 'It opens this dashboard to make a token for the repo, and adds the Heresay skill and MCP server for your agent. The token stays on your computer, not in the repo.' })]),
466
+ el('li', {}, [el('b', { text: 'Then tell your agent:' }), codeBlock('Add Heresay to this app'),
467
+ el('p', { class: 'hint', text: 'It installs Heresay in the right place and verifies it. Later, “Fix the next Heresay report” works the same way.' })]),
468
+ ])]),
368
469
  ]) };
369
470
  var tabs = el('div', { class: 'seg', role: 'tablist' });
370
471
  (agentFirst ? [['agent', 'Ask your coding agent'], ['hand', 'Add it yourself']] : [['hand', 'Add it yourself'], ['agent', 'Ask your coding agent']]).forEach(function (t, i) {
@@ -378,40 +479,75 @@
378
479
  });
379
480
  view.appendChild(el('section', { class: 'card' }, [
380
481
  tabs, panes.hand, panes.agent,
381
- el('p', { class: 'hint', html: 'Your key is meant to be public: it only lets the sites you listed send reports. Optional extras (who is signed in, your app version, your brand colour) are in the <a href="/docs.html#options" target="_blank">docs</a>.' }),
382
- el('div', { class: 'soon-note' }, [
383
- el('b', { text: 'Coming next: ' }),
384
- el('code', { text: 'npx heresay connect' }),
385
- ' links your repo to this app, so your coding agent can pick up the reports you accept and mark them fixed.',
386
- ]),
482
+ apple
483
+ ? el('p', { class: 'hint', text: 'Your key is meant to be public: it can only send reports, never read them. It is fine in your source code.' })
484
+ : el('p', { class: 'hint', html: 'Your key is meant to be public: it only lets the sites you listed send reports. Optional extras (who is signed in, your app version, your brand colour) are in the <a href="/docs.html#options" target="_blank">docs</a>.' }),
387
485
  ]));
388
486
 
389
- var status = el('div', { class: 'wait', role: 'status' });
390
- var tryIt = el('a', { class: 'btn', href: '/demo.html?key=' + encodeURIComponent(p.key), target: '_blank', rel: 'noopener', text: 'Send a test report' });
487
+ // Step 4 lives on this page and needs nobody to do anything: it completes when Heresay is
488
+ // found in the code (the agent's `heresay check`) or seen running in the app (any SDK call).
489
+ // Nothing moves on until then, because that is the proof the install works.
490
+ var rowCode = checkRow('In your code', 'Waiting for your agent to confirm it, or for your app to load it.');
491
+ var rowRun = checkRow('Running in your app', apple ? 'Waiting for your app to start with Heresay in it.' : 'Waiting for a page with Heresay on it to load, anywhere: your live site or localhost.');
492
+ var status = el('div', { class: 'wait', role: 'status', text: 'Checking automatically…' });
493
+ var feed = el('ul', { class: 'feed', 'aria-live': 'polite' });
494
+ var cont = el('button', { class: 'btn primary', type: 'button', disabled: true, text: 'Continue to reports' });
495
+ cont.onclick = function () { location.hash = '#/apps/' + p.id; };
496
+ var lockNote = el('span', { class: 'hint', text: 'Unlocks as soon as the install is verified.' });
391
497
  view.appendChild(el('section', { class: 'card test' }, [
392
- el('div', { class: 'test-head' }, [el('span', { class: 'stepnum', text: '4' }), el('h2', { text: 'Send your first report' })]),
393
- el('p', { class: 'mute', text: 'Open your app, tap Report in the corner and send anything. Or use our test page. It shows up here within a few seconds.' }),
498
+ el('div', { class: 'test-head' }, [el('span', { class: 'stepnum', text: '4' }), el('h2', { text: 'Verify' })]),
499
+ el('p', { class: 'mute', text: 'Heresay checks this by itself. No test report needed.' }),
500
+ el('ul', { class: 'checks-list' }, [rowCode.li, rowRun.li]),
394
501
  status,
395
- el('div', { class: 'row' }, [tryIt]),
502
+ feed,
503
+ el('div', { class: 'row split' }, [el('span', { class: 'spacer' }), lockNote, cont]),
396
504
  ]));
397
505
 
398
- var seen = null;
506
+ function checkRow(title, waiting) {
507
+ var mark = el('span', { class: 'mark', 'aria-hidden': 'true' });
508
+ var detail = el('span', { class: 'mute small', text: waiting });
509
+ var li = el('li', {}, [mark, el('div', {}, [el('b', { text: title }), detail])]);
510
+ return {
511
+ li: li,
512
+ set: function (text) { li.className = 'ok'; detail.textContent = text; },
513
+ // The other check proved it already; this one stops waiting and says it is optional.
514
+ settle: function (text) { if (li.className !== 'ok') { li.className = 'skip'; detail.textContent = text; } },
515
+ };
516
+ }
517
+
518
+ var known = {}, first = true;
519
+ function ago(iso) {
520
+ var s = Math.max(0, Math.round((Date.now() - Date.parse(iso)) / 1000));
521
+ return s < 60 ? 'just now' : s < 3600 ? Math.round(s / 60) + ' min ago' : new Date(iso).toLocaleString();
522
+ }
399
523
  function check() {
400
- api('GET', '/projects/' + p.id + '/reports').then(function (b) {
401
- if (seen === null) seen = b.reports.length;
402
- var fresh = b.reports.length > seen;
403
- if (!b.reports.length) {
404
- status.className = 'wait';
405
- status.textContent = 'Waiting for your first report…';
406
- return;
524
+ Promise.all([api('GET', '/projects/' + p.id), api('GET', '/projects/' + p.id + '/reports')]).then(function (x) {
525
+ var app = x[0].project, rs = x[1].reports.slice().sort(function (a, c) { return a.created_at < c.created_at ? 1 : -1; });
526
+ if (app.code_found) rowCode.set('Found in ' + app.code_found.file + ' (' + app.code_found.repo + '), ' + ago(app.code_found.at));
527
+ if (app.sdk_seen) rowRun.set('Seen on ' + app.sdk_seen.where + ', ' + ago(app.sdk_seen.at));
528
+ var ok = !!(app.code_found || app.sdk_seen || rs.length);
529
+ if (ok && cont.disabled) {
530
+ cont.disabled = false;
531
+ lockNote.remove();
532
+ status.className = 'wait ok';
533
+ status.textContent = 'Installed. Reports will arrive here and on the reports page.';
534
+ steps.replaceWith(steps = stepper(3, p, true));
407
535
  }
408
- var first = b.reports.slice().sort(function (a, c) { return a.created_at < c.created_at ? 1 : -1; })[0];
409
- status.className = 'wait ok';
410
- status.textContent = '';
411
- status.appendChild(el('b', { text: fresh || seen === 0 ? 'It works. ' : 'Reports are coming in. ' }));
412
- status.appendChild(document.createTextNode('Latest: “' + first.text.slice(0, 120) + '”'));
413
- status.appendChild(el('a', { class: 'btn primary', href: '#/apps/' + p.id, text: 'See reports' }));
414
- stopTimer();
536
+ if (ok) {
537
+ rowCode.settle('Optional. Your coding agent confirms it with npx heresay check.');
538
+ rowRun.settle('Optional. Shows here the first time your app loads Heresay.');
539
+ }
540
+ // Any reports that do come in show up live, so nobody has to leave the page to see one.
541
+ feed.textContent = '';
542
+ rs.slice(0, 5).forEach(function (r) {
543
+ feed.appendChild(el('li', { class: !first && !known[r.id] ? 'fresh' : '' }, [
544
+ el('span', { class: 'pill ' + r.type, text: TYPE_LABEL[r.type] }),
545
+ el('span', { class: 'feed-text', text: r.text }),
546
+ el('span', { class: 'mute small', text: [r.context.route, r.context.platform, new Date(r.created_at).toLocaleTimeString()].filter(Boolean).join(' · ') }),
547
+ ]));
548
+ known[r.id] = true;
549
+ });
550
+ first = false;
415
551
  }).catch(function () {});
416
552
  }
417
553
  check();
@@ -427,16 +563,33 @@
427
563
  var filters = el('nav', { class: 'filters', 'aria-label': 'Filter' });
428
564
  var list = el('div', { class: 'reports' });
429
565
  var empty = el('p', { class: 'empty' });
566
+ var ctx = { repos: [], briefs: {} };
567
+ var repoLine = el('p', { class: 'repos-line' });
430
568
  view.appendChild(el('div', { class: 'head' }, [
431
- el('div', { class: 'title' }, [icon(platformOf(p.platform)), el('h1', { text: p.name })]),
432
- el('a', { class: 'btn', href: '#/apps/' + p.id + '/setup', text: 'Install' }),
569
+ el('div', { class: 'title' }, [icon(platformOf(p.platform)), el('div', {}, [el('h1', { text: p.name }),
570
+ p.framework ? el('span', { class: 'mute small', text: frameworkLabel(p.framework) + (p.framework_detected ? ' (detected)' : '') }) : null])]),
571
+ el('div', { class: 'row tight' }, [
572
+ el('a', { class: 'btn', href: '#/apps/' + p.id + '/setup', text: 'Install' }),
573
+ el('a', { class: 'btn ghost', href: '#/apps/' + p.id + '/delete', text: 'Delete…' }),
574
+ ]),
433
575
  ]));
576
+ view.appendChild(repoLine);
434
577
  view.appendChild(filters);
435
578
  view.appendChild(list);
436
579
  view.appendChild(empty);
437
580
 
438
581
  function load() {
439
- return api('GET', '/projects/' + p.id + '/reports').then(function (b) { reports = b.reports; render(); });
582
+ return Promise.all([
583
+ api('GET', '/projects/' + p.id + '/reports'),
584
+ api('GET', '/projects/' + p.id + '/repos'),
585
+ ]).then(function (x) {
586
+ reports = x[0].reports; ctx.briefs = x[0].briefs || {}; ctx.repos = x[1].repos;
587
+ repoLine.textContent = '';
588
+ repoLine.appendChild(document.createTextNode(ctx.repos.length
589
+ ? 'Agents fix these in: ' + ctx.repos.join(', ') + ' · ' : 'No repo connected for agents yet · '));
590
+ repoLine.appendChild(el('a', { href: '#/connect?app=' + p.id, text: 'Connect a repo' }));
591
+ render();
592
+ });
440
593
  }
441
594
 
442
595
  function render() {
@@ -456,7 +609,7 @@
456
609
  empty.appendChild(document.createTextNode('No reports yet. '));
457
610
  empty.appendChild(el('a', { href: '#/apps/' + p.id + '/setup', text: 'Check the install' }));
458
611
  } else empty.textContent = filter === 'open' ? 'Nothing waiting. Every report has had its hearing.' : 'Nothing here.';
459
- shown.forEach(function (r) { list.appendChild(row(p, r, load)); });
612
+ shown.forEach(function (r) { list.appendChild(row(p, r, load, ctx)); });
460
613
  }
461
614
 
462
615
  load();
@@ -469,7 +622,8 @@
469
622
  .filter(Boolean).join(' · ');
470
623
  }
471
624
 
472
- function row(p, r, reload) {
625
+ function row(p, r, reload, ctx) {
626
+ var brief = ctx.briefs[r.id];
473
627
  var err = el('span', { class: 'err' });
474
628
  var actions = el('div', { class: 'actions' });
475
629
  var act = function (action, body) {
@@ -482,7 +636,13 @@
482
636
  function buttons() {
483
637
  actions.textContent = '';
484
638
  if (r.status === 'open') {
485
- actions.appendChild(el('button', { class: 'btn primary', text: 'Accept', onclick: function () { act('accept'); } }));
639
+ // Several repos hold this app's code: say where the fix goes, defaulting to the first.
640
+ var pick = ctx.repos.length > 1 ? el('select', { 'aria-label': 'Where the fix goes' },
641
+ ctx.repos.map(function (x) { return el('option', { value: x, text: 'Fix in ' + x }); })) : null;
642
+ actions.appendChild(el('button', { class: 'btn primary', text: 'Accept', onclick: function () {
643
+ act('accept', pick ? { repo: pick.value } : undefined);
644
+ } }));
645
+ if (pick) actions.appendChild(pick);
486
646
  actions.appendChild(el('button', { class: 'btn', text: 'Decline…', onclick: declineForm }));
487
647
  }
488
648
  if (r.status === 'accepted') {
@@ -496,11 +656,23 @@
496
656
  .catch(function (x) { err.textContent = x.message; });
497
657
  },
498
658
  }));
499
- actions.appendChild(el('button', { class: 'btn', text: 'Mark fixed', onclick: function () { act('fixed'); } }));
659
+ actions.appendChild(el('button', { class: 'btn', text: 'Mark fixed…', onclick: fixedForm }));
500
660
  }
501
661
  actions.appendChild(err);
502
662
  }
503
663
 
664
+ function fixedForm() {
665
+ actions.textContent = '';
666
+ var note = el('textarea', { placeholder: 'What changed, in their words. The person who sent this will read it. Optional.', 'aria-label': 'Note for the reporter' });
667
+ actions.appendChild(note);
668
+ actions.appendChild(el('button', { class: 'btn primary', text: 'Mark fixed', onclick: function () {
669
+ act('fixed', note.value.trim() ? { note: note.value } : undefined);
670
+ } }));
671
+ actions.appendChild(el('button', { class: 'btn ghost', text: 'Cancel', onclick: buttons }));
672
+ actions.appendChild(err);
673
+ note.focus();
674
+ }
675
+
504
676
  function declineForm() {
505
677
  actions.textContent = '';
506
678
  var reason = el('textarea', { placeholder: 'Why? The person who sent this will read it.', 'aria-label': 'Reason for declining' });
@@ -524,10 +696,154 @@
524
696
  el('p', { class: 'text', text: r.text }),
525
697
  el('div', { class: 'ctx', text: ctxLine(r.context) }),
526
698
  r.decline_reason ? el('div', { class: 'reason', text: 'Declined: ' + r.decline_reason }) : null,
699
+ r.fix_note ? el('div', { class: 'reason', text: 'Told them: ' + r.fix_note }) : null,
700
+ r.status === 'accepted' && brief ? el('div', { class: 'brief-line' }, [
701
+ brief.claimed_by ? el('b', { text: 'In progress in ' + brief.claimed_by }) : document.createTextNode(brief.repo ? 'Waiting for an agent in ' + brief.repo : 'Waiting for an agent in any connected repo'),
702
+ ]) : null,
703
+ brief && brief.notes.length ? el('details', { class: 'notes' }, [el('summary', { text: brief.notes.length + (brief.notes.length === 1 ? ' note' : ' notes') + ' from agents' })]
704
+ .concat(brief.notes.map(function (n) { return el('p', {}, [el('span', { class: 'mute', text: n.by.replace(/^agent:/, '') + ' · ' + new Date(n.at).toLocaleString() + ': ' }), n.text]); }))) : null,
527
705
  r.status === 'fixed' || r.status === 'declined' ? null : actions,
528
706
  ]);
529
707
  }
530
708
 
709
+ // ---- delete an app ---------------------------------------------------------------------
710
+
711
+ /** The prompt that takes Heresay back out of a repo: the code, then the agent files. */
712
+ function removePrompt(p) {
713
+ var apple = platformOf(p.platform).apple;
714
+ return [
715
+ 'Remove Heresay, an in-app feedback SDK, from this repo. Do these steps in order.',
716
+ '',
717
+ '1. Read the removal steps and follow them:',
718
+ '',
719
+ ' npx -y heresay@0 guide uninstall',
720
+ '',
721
+ '2. Remove it from the app\'s code. Search for the key ' + p.key + ' and for "' + (apple ? 'Heresay' : 'sdk/v1.js') + '". ' + (apple
722
+ ? 'Remove the Heresay Swift package dependency, `import Heresay`, the Heresay.configure(…) call, .heresayReportButton() / .heresay(), HeresayCommands, and any Heresay.identify / setScreen / present calls.'
723
+ : 'Remove the Heresay script tag (or its next/script, nuxt.config or layout entry) and any window.Heresay calls such as identify or setScreen.'),
724
+ '',
725
+ '3. Remove the agent files Heresay added (.mcp.json entry, skill, AGENTS.md section, saved token):',
726
+ '',
727
+ ' npx -y heresay@0 disconnect --yes',
728
+ '',
729
+ 'Change nothing else. Build and run the tests to make sure nothing else broke.',
730
+ ].join('\n');
731
+ }
732
+
733
+ function deleteView(view, p) {
734
+ var owner = me.role === 'owner';
735
+ view.appendChild(el('div', { class: 'head' }, [
736
+ el('div', { class: 'title' }, [icon(platformOf(p.platform)), el('h1', { text: 'Delete ' + p.name })]),
737
+ el('a', { class: 'btn ghost', href: '#/apps/' + p.id, text: 'Cancel' }),
738
+ ]));
739
+
740
+ view.appendChild(el('section', { class: 'card' }, [
741
+ el('h2', { text: '1. Take Heresay out of your code' }),
742
+ el('p', { class: 'mute', text: 'Do this first, so nothing in your app still points at Heresay. Paste this into your coding agent, in the app’s repo:' }),
743
+ codeBlock(removePrompt(p)),
744
+ el('details', { class: 'where' }, [el('summary', { text: 'Or remove it by hand' }), el('ol', { class: 'agent-steps' }, (platformOf(p.platform).apple ? [
745
+ 'In Xcode, remove the Heresay package from the target (Project › Package Dependencies).',
746
+ 'Delete import Heresay, the Heresay.configure(…) line, .heresayReportButton() or .heresay(), and HeresayCommands.',
747
+ 'Delete any Heresay.identify, setScreen, present or send calls.',
748
+ ] : [
749
+ 'Delete the Heresay script tag (search your code for ' + p.key + ' or sdk/v1.js). In Next.js it is a <Script> in the layout; in Nuxt an entry in nuxt.config.',
750
+ 'Delete any window.Heresay calls (identify, setScreen, open).',
751
+ 'If you set a Content Security Policy for Heresay, take its address out of script-src and connect-src.',
752
+ ]).concat(['In the repo, run npx heresay disconnect. It removes the .mcp.json entry, the Heresay skill, the AGENTS.md section and the saved token.']).map(function (t) { return el('li', { text: t }); }))]),
753
+ ]));
754
+
755
+ var err = el('p', { class: 'err', role: 'alert' });
756
+ var confirm = el('input', { name: 'confirm', autocomplete: 'off', placeholder: p.name, 'aria-label': 'Type the app’s name to confirm' });
757
+ var go = el('button', { class: 'btn danger', type: 'submit', disabled: true, text: 'Delete ' + p.name });
758
+ confirm.oninput = function () { go.disabled = confirm.value !== p.name; };
759
+ var form = el('form', { class: 'form' }, [
760
+ el('p', { text: 'This deletes the app and every report sent from it, for everyone on the team. People who sent reports can no longer see them, and the key stops working: any copy of the app still carrying it hides its Report button. Connected repos keep their tokens for their other apps.' }),
761
+ el('label', {}, ['Type ', el('b', { text: p.name }), ' to confirm', confirm]),
762
+ el('div', { class: 'row' }, [go]),
763
+ err,
764
+ ]);
765
+ form.onsubmit = function (e) {
766
+ e.preventDefault();
767
+ err.textContent = '';
768
+ go.disabled = true;
769
+ api('DELETE', '/projects/' + p.id, { confirm: confirm.value }).then(function () {
770
+ projects = projects.filter(function (x) { return x.id !== p.id; });
771
+ location.hash = '#/';
772
+ }).catch(function (x) { err.textContent = x.message; go.disabled = false; });
773
+ };
774
+ view.appendChild(el('section', { class: 'card' }, owner ? [el('h2', { text: '2. Delete the app from Heresay' }), form]
775
+ : [el('h2', { text: '2. Delete the app from Heresay' }), el('p', { class: 'mute', text: 'Only an owner can delete an app. Ask one of the owners on the Team page.' })]));
776
+ }
777
+
778
+ // ---- connect a repo for coding agents ----------------------------------------------------
779
+
780
+ function connectView(view, query) {
781
+ view.appendChild(el('div', { class: 'head' }, [el('h1', { text: 'Connect a repo for your coding agent' })]));
782
+ view.appendChild(el('p', { class: 'mute', text: 'A token lets agents working in one repo see the accepted reports for the apps whose code is there, claim them, and mark them fixed. They never see open reports, and never accept or decline.' }));
783
+ var err = el('p', { class: 'err', role: 'alert' });
784
+ var out = el('div');
785
+ var boxes = el('div', { class: 'checks' });
786
+ var repo = el('input', { name: 'repo', required: true, placeholder: 'github.com/acme/web', value: query.get('repo') || '', autocomplete: 'off', spellcheck: 'false' });
787
+ var form = el('form', { class: 'form' }, [
788
+ el('label', {}, ['Repo', repo]),
789
+ el('p', { class: 'hint', html: 'As git knows it. <code>npx heresay connect</code> fills this in for you.' }),
790
+ el('div', { class: 'field' }, [el('span', { class: 'lbl', text: 'Apps whose code is in this repo' }), boxes,
791
+ el('p', { class: 'hint', text: 'A monorepo can have several. An agent can also add a new app from the repo later.' })]),
792
+ el('div', { class: 'row' }, [el('button', { class: 'btn primary', text: 'Create token' })]),
793
+ err,
794
+ ]);
795
+ view.appendChild(el('section', { class: 'card' }, [form, out]));
796
+ var list = el('ul', { class: 'members' });
797
+ view.appendChild(el('section', { class: 'card' }, [el('h2', { text: 'Connected repos' }), list]));
798
+
799
+ api('GET', '/projects').then(function (b) {
800
+ projects = b.projects;
801
+ var want = query.get('app');
802
+ if (!projects.length) boxes.appendChild(el('p', { class: 'hint', text: 'No apps yet. Connect anyway: your agent can create the app from the repo.' }));
803
+ projects.forEach(function (p) {
804
+ boxes.appendChild(el('label', { class: 'check' }, [
805
+ el('input', { type: 'checkbox', value: p.id, checked: want ? p.id === want : projects.length === 1 }),
806
+ ' ' + p.name, el('span', { class: 'mute', text: ' · ' + platformOf(p.platform).label }),
807
+ ]));
808
+ });
809
+ drawTokens();
810
+ });
811
+
812
+ function drawTokens() {
813
+ api('GET', '/agent-tokens').then(function (b) {
814
+ list.textContent = '';
815
+ if (!b.tokens.length) list.appendChild(el('li', { class: 'mute', text: 'None yet.' }));
816
+ b.tokens.forEach(function (t) {
817
+ var names = t.app_ids.map(function (id) { var p = projects.filter(function (x) { return x.id === id; })[0]; return p ? p.name : id; });
818
+ list.appendChild(el('li', {}, [
819
+ el('span', { class: 'picon', html: '<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="6" cy="5" r="2"/><circle cx="6" cy="19" r="2"/><circle cx="18" cy="8" r="2"/><path d="M6 7v10M18 10c0 4-6 3-12 7"/></svg>' }),
820
+ el('div', {}, [el('b', { text: t.repo }), el('span', { class: 'mute', text: (names.join(', ') || 'no apps yet') + ' · by ' + t.created_by + ' · ' + (t.last_used_at ? 'last used ' + new Date(t.last_used_at).toLocaleDateString() : 'not used yet') })]),
821
+ el('button', { class: 'btn ghost', text: 'Revoke', onclick: function () {
822
+ api('DELETE', '/agent-tokens/' + t.id).then(drawTokens).catch(function (x) { err.textContent = x.message; });
823
+ } }),
824
+ ]));
825
+ });
826
+ });
827
+ }
828
+
829
+ form.onsubmit = function (e) {
830
+ e.preventDefault();
831
+ err.textContent = '';
832
+ var ids = [].slice.call(boxes.querySelectorAll('input:checked')).map(function (i) { return i.value; });
833
+ api('POST', '/agent-tokens', { repo: repo.value, app_ids: ids }).then(function (b) {
834
+ form.hidden = true;
835
+ out.appendChild(el('div', { class: 'token-out' }, [
836
+ el('h2', { text: 'Token for ' + b.agent.repo }),
837
+ el('p', { text: 'Paste it where npx heresay connect asks for it. It is shown only once.' }),
838
+ codeBlock(b.token),
839
+ el('p', { class: 'hint', html: 'Haven’t started it? In the repo, run <code>npx heresay connect --url ' + location.origin + '</code>.' }),
840
+ ]));
841
+ drawTokens();
842
+ }).catch(function (x) { err.textContent = x.message; });
843
+ };
844
+ repo.focus();
845
+ }
846
+
531
847
  // ---- team ------------------------------------------------------------------------------
532
848
 
533
849
  function teamView(view) {
@@ -536,6 +852,7 @@
536
852
  var err = el('p', { class: 'err', role: 'alert' });
537
853
  view.appendChild(el('div', { class: 'head' }, [el('h1', { text: 'Team' })]));
538
854
  view.appendChild(el('p', { class: 'mute', text: 'Everyone here can read and answer reports for every app. Owners can also change the team.' }));
855
+ view.appendChild(el('p', { class: 'mute' }, ['Coding agents get access per repo, not per person: ', el('a', { href: '#/connect', text: 'Connected repos' }), '.']));
539
856
 
540
857
  function draw(members) {
541
858
  list.textContent = '';