Skip to content

Commit 08a4f65

Browse files
committed
Improve the corpus-viewer, and add a Claude slash-command for powering this loop.
1 parent 1e03587 commit 08a4f65

File tree

2 files changed

+55
-16
lines changed

2 files changed

+55
-16
lines changed

.claude/commands/corpus-loop.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
argument-hint: [corpus_slug]
3+
description: uses Playwright MCP and the `corpus:view` dev environment to help with parsing page elements
4+
---
5+
6+
- using Playwright MCP, navigate to `http://localhost:3001/corpus/$1/gitcasso`
7+
- the page will have a div with id `gitcasso-comment-spots`, wait 500ms for it to settle
8+
- inside the `gitcasso-comment-spots` div you will see something like this:
9+
10+
```json
11+
{
12+
"url": "https://github.com/diffplug/selfie/issues/523",
13+
"allTextAreas": [
14+
{
15+
"textarea": "id='feedback' name='feedback' className='form-control width-full mb-2'",
16+
"spot": "NO_SPOT"
17+
},
18+
{
19+
"textarea": "id=':rn:' name='' className='prc-Textarea-TextArea-13q4j overtype-input'",
20+
"spot": {
21+
"domain": "github.com",
22+
"number": 523,
23+
"slug": "diffplug/selfie",
24+
"title": "TODO_TITLE",
25+
"type": "GH_ISSUE_ADD_COMMENT",
26+
"unique_key": "github.com:diffplug/selfie:523"
27+
}
28+
}
29+
]
30+
}
31+
```
32+
33+
- this output means that this page is simulating the url `https://github.com/diffplug/selfie/issues/523`
34+
- every textarea on the page is represented
35+
- `NO_SPOT` means that the spot was not enhanced
36+
- `type: GH_ISSUE_ADD_COMMENT` means that it was enhanced by whichever implementation of `CommentEnhancer` returns the spot type `GH_ISSUE_ADD_COMMENT`
37+
- if you search for that string in `src/lib/enhancers` you will find the correct one
38+
- the `tryToEnhance` method returned a `CommentSpot`, and that whole data is splatted out above
39+
40+
If you make a change to the code of the enhancer, you can click the button with id `gitcasso-rebuild-btn`. It will trigger a rebuild of the browser extension, and then refresh the page. You'll be able to see the effects of your change in the `gitcasso-comment-spots` div described above.
41+
42+
When writing `tryToEnhance` methods, don't hedge your bets and write lots of fallback code or strings of `?.`. Have a specific piece of data you want to get, use non-null `!` assertions where necessary to be clear about getting. The data they are extracting is going to change over time, and it's easier to fix broken ones if you know exactly what used to work. If the code has lots of branching paths, it's harder to tell what it was doing.

tests/corpus-view.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -477,28 +477,28 @@ function createCommentSpotDisplayScript(urlParts: ReturnType<typeof getUrlParts>
477477
478478
function updateCommentSpotDisplay() {
479479
const textareas = document.querySelectorAll('textarea');
480-
const spotsFound = [];
480+
const allTextAreas = [];
481481
482482
for (const textarea of textareas) {
483-
const forValue = 'id=' + textarea.id + ' name=' + textarea.name + ' className=' + textarea.className;
483+
const forValue = "id='" + textarea.id + "' name='" + textarea.name + "' className='" + textarea.className + "'";
484484
const enhancedItem = window.gitcassoTextareaRegistry ? window.gitcassoTextareaRegistry.get(textarea) : undefined;
485485
if (enhancedItem) {
486-
spotsFound.push({
487-
for: forValue,
486+
allTextAreas.push({
487+
textarea: forValue,
488488
spot: enhancedItem.spot,
489-
title: enhancedItem.enhancer.tableTitle(enhancedItem.spot),
490489
});
491490
} else {
492-
spotsFound.push({
493-
for: forValue,
491+
allTextAreas.push({
492+
textarea: forValue,
494493
spot: 'NO_SPOT',
495494
});
496495
}
497496
}
498-
499-
console.log('Enhanced textareas:', spotsFound.filter(s => s.spot !== 'NO_SPOT').length);
500-
console.log('All textareas on page:', textareas.length);
501-
commentSpotDisplay.innerHTML = '<div style="' + styles.header + '"><pre>${urlParts.href}\\n' + JSON.stringify(spotsFound, null, 2) + '</pre></div>';
497+
const harness = {
498+
url: '${urlParts.href}',
499+
allTextAreas: allTextAreas
500+
}
501+
commentSpotDisplay.innerHTML = '<div style="' + styles.header + '"><pre>' + JSON.stringify(harness, null, 1) + '</pre></div>';
502502
}
503503
504504
// Initial update
@@ -508,9 +508,6 @@ function createCommentSpotDisplayScript(urlParts: ReturnType<typeof getUrlParts>
508508
setTimeout(updateCommentSpotDisplay, 400);
509509
setTimeout(updateCommentSpotDisplay, 800);
510510
511-
// Update display periodically
512-
setInterval(updateCommentSpotDisplay, 2000);
513-
514511
document.body.appendChild(commentSpotDisplay);
515512
`
516513
}
@@ -540,7 +537,7 @@ function createGitcassoScript(
540537
): string {
541538
const contentScriptSetup = contentScriptCode
542539
? // Direct embedding (for HTML corpus)
543-
`
540+
`
544541
// Set up mocked location
545542
window.gitcassoMockLocation = {
546543
host: '${urlParts.host}',
@@ -567,7 +564,7 @@ function createGitcassoScript(
567564
}
568565
`
569566
: // Fetch-based loading (for HAR corpus)
570-
`
567+
`
571568
// Fetch and patch the content script to remove webextension-polyfill issues
572569
fetch('/chrome-mv3-dev/content-scripts/content.js')
573570
.then(response => response.text())

0 commit comments

Comments
 (0)