DeepWiki is third-party and model-generated. Verify load-bearing answers against the source.Caveats
',
''
].join('');
@@ -72,6 +74,8 @@
var newChat = panel.querySelector('#dw-new');
var emptyTemplate = log.querySelector('.dw-empty').cloneNode(true);
var busy = false;
+ var history = [];
+ var controller = null;
function scroll() { log.scrollTop = log.scrollHeight; }
function openPanel() {
@@ -93,6 +97,8 @@
});
}
function resetChat() {
+ if (controller) { controller.abort(); controller = null; }
+ history = [];
while (log.firstChild) log.removeChild(log.firstChild);
var empty = emptyTemplate.cloneNode(true);
log.appendChild(empty);
@@ -240,18 +246,29 @@
function thinking() {
var row = document.createElement('div');
row.className = 'dw-msg dw-bot dw-thinking';
- row.innerHTML = 'DW
Searching the index\u2026
';
+ row.innerHTML = 'DW
Searching the index\u2026
';
log.appendChild(row);
scroll();
return row;
}
- function error(text) {
+ function error(text, question) {
var row = message('bot', text);
row.querySelector('.dw-bubble').classList.add('dw-error');
var link = document.createElement('p');
link.innerHTML = 'Open the DeepWiki page \u2197';
row.querySelector('.dw-md').appendChild(link);
+ if (question) {
+ var retry = document.createElement('button');
+ retry.type = 'button';
+ retry.className = 'dw-retry';
+ retry.textContent = 'Retry';
+ retry.addEventListener('click', function () {
+ row.remove();
+ ask(question);
+ });
+ row.querySelector('.dw-md').appendChild(retry);
+ }
scroll();
}
@@ -273,7 +290,7 @@
return last;
}
- function call(question) {
+ function call(question, signal) {
var body = {
jsonrpc: '2.0',
id: 1,
@@ -286,7 +303,8 @@
return fetch(ENDPOINT, {
method: 'POST',
headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream' },
- body: JSON.stringify(body)
+ body: JSON.stringify(body),
+ signal: signal
}).then(function (response) {
if (!response.ok) throw new Error('DeepWiki returned HTTP ' + response.status);
return response.text();
@@ -309,13 +327,35 @@
if (empty) empty.remove();
message('user', question);
var pending = thinking();
- call(question).then(function (result) {
+ var stop = pending.querySelector('.dw-stop');
+ if (stop) stop.addEventListener('click', function () {
+ if (controller) controller.abort();
+ });
+ var context = history.slice(-2).map(function (item) {
+ return 'Q: ' + item.q + '\nA: ' + item.a.slice(0, 900);
+ }).join('\n\n');
+ var prompt = context
+ ? 'Previous conversation for context:\n' + context + '\n\nNew question: ' + question
+ : question;
+ controller = ('AbortController' in window) ? new AbortController() : null;
+ call(prompt, controller ? controller.signal : undefined).then(function (result) {
if (pending.parentNode) pending.remove();
- if (result.ok) message('bot', result.text); else error(result.text);
+ if (result.ok) {
+ history.push({ q: question, a: result.text });
+ if (history.length > 4) history.shift();
+ message('bot', result.text);
+ } else {
+ error(result.text, question);
+ }
}).catch(function (failure) {
if (pending.parentNode) pending.remove();
- error('DeepWiki is unavailable right now: ' + failure.message);
+ if (failure && failure.name === 'AbortError') {
+ error('Stopped. Ask again when you are ready.', question);
+ } else {
+ error('DeepWiki is unavailable right now: ' + failure.message, question);
+ }
}).then(function () {
+ controller = null;
busy = false;
send.disabled = false;
input.focus();
From befe7053e08d4e46ed4bf6abbc4eaf7abf094ceb Mon Sep 17 00:00:00 2001
From: HugoXK
Date: Thu, 19 Nov 2026 10:00:35 +0000
Subject: [PATCH 2/2] fix(docs): derive the DeepWiki caveats link from the
script URL
GitHub Pages serves the docs under /agentdescent/, while CI and a local
build serve them at /. The chat panel's header info link and footer
"Caveats" link were root-absolute (/deepwiki/), so they 404 on Pages and
no local run can see it.
Take the site root from the loaded assets/deepwiki.js script instead and
build /deepwiki/ from it, so both links resolve under a subpath and
at the root. Without a script element there is no safe base, so the two
anchors are omitted rather than pointed at a literal that 404s.
Only the link base changes: no credentials are added, and the escaping
order in inline()/escapeHtml is untouched.
---
docs/assets/deepwiki.js | 13 +++++++++++--
tests/test_site_navigation.py | 11 +++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/docs/assets/deepwiki.js b/docs/assets/deepwiki.js
index fba64eff..0145b609 100644
--- a/docs/assets/deepwiki.js
+++ b/docs/assets/deepwiki.js
@@ -5,6 +5,15 @@
var REPO = 'ThinkFlowLab/agentdescent';
var ENDPOINT = 'https://mcp.deepwiki.com/mcp';
var PAGE = 'https://deepwiki.com/' + REPO;
+
+ // GitHub Pages serves this site under /agentdescent/, a local build sits at /,
+ // and only Pages punishes a root-absolute href. Derive the base from this
+ // script's own URL so the in-panel links resolve in both places. With no
+ // script element there is no safe base, so the two anchors are left out
+ // instead of falling back to a literal that 404s on Pages.
+ var SELF = document.currentScript || document.querySelector('script[src$="assets/deepwiki.js"]');
+ var GUIDE = SELF ? new URL('../deepwiki/', SELF.src).href : null;
+
var icons = {
chat: '',
logo: '',
@@ -36,7 +45,7 @@
'
DeepWiki is third-party and model-generated. Verify load-bearing answers against the source.Caveats
',
+ '
DeepWiki is third-party and model-generated. Verify load-bearing answers against the source.' + (GUIDE ? 'Caveats' : '') + '
',
''
].join('');
diff --git a/tests/test_site_navigation.py b/tests/test_site_navigation.py
index d5cb6cfd..a1ae7f48 100644
--- a/tests/test_site_navigation.py
+++ b/tests/test_site_navigation.py
@@ -56,6 +56,17 @@ def test_header_breakpoint_keeps_the_drawer_as_the_mobile_route():
assert '{{ nav.homepage.url | url }}#demo' in header
+def test_deepwiki_links_derive_their_base_from_the_script_url():
+ # The site is published under /agentdescent/ but served at / locally, so a
+ # root-absolute href works in CI and 404s on Pages. Both in-panel links must
+ # take the base from the loaded script instead, and with no script element
+ # they are left out rather than pointed at a literal that 404s.
+ js = (ROOT / "docs" / "assets" / "deepwiki.js").read_text()
+ assert 'href="/deepwiki/"' not in js
+ assert "new URL('../deepwiki/', SELF.src).href : null" in js
+ assert js.count('href="\' + GUIDE + \'"') == 2
+
+
def verify_rendered_site(site):
cfg = config()
destination = cfg["site_url"] + "#demo"