Skip to content

Commit c10de58

Browse files
acn-ericlawclaude
andcommitted
chore(quality): the local SonarQube findings of 2026-11-29, no behaviour change
A local SonarQube round over this release's code, before 4.12.31: 127 rows in eight files, 107 fixed and 20 kept with their reason on the line. In lockstep with the Python pack. Cognitive complexity (29 rows): each function over 15 is split along its seams, every check in the order it ran and with the message it wrote - 15 in the agent tools (the glob walk, the search, the page ranges, the HTML reader's start tag and tokenizer, the host rules, the address ranges, the crawl, the value renderer, the ingest plan, the schema, the boot, describe's states), 6 in rest-automation.ts, 3 in rest-routing.ts, toMap, the attachments loader, and the validators of ask-person and agent-question. LLM helper: the 21 functions that used nothing of createLlmHelper are functions of the module - the 16 the scan named and five that used only those. Expressions: five whose time could grow with the square of their input are linear and answer the same on every input - the trailing slashes of a base URL (ask-person, agent-question) and four small scans in the agent tools (the trailing dots of a host name, the newlines around preformatted text, a robots.txt comment, the tag at a "<"); two over the complexity limit are built from their parts with the same source text. The rest: explicit code-unit comparators on ask-person's sorts, class fields, Number.parseInt, String.raw, replaceAll, toReversed, .at(), an optional chain, Boolean as a filter, a dead initial value, an unused import. CRAWL_RESULT_MAX_CHARS is a constant; its test hook sets a private variable behind it. Kept, each with "// NOSONAR - <reason>" on its line: 16 awaits that are sequential by design, the helper's JSON form of a content block, and the two bindings of agent-question that reset() replaces. npm test: 888 tests, 812 passed, 76 skipped, 0 failed, as before. The IDE's own analyzer, run headless, reproduces every row of the scan on the files as they were and reports none on them now outside the 19 marked lines. CHANGELOG Unreleased Changed 12. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 778c0ef commit c10de58

9 files changed

Lines changed: 1805 additions & 1240 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,27 @@
421421
write after that is dropped as any write after `close()`. Beside it, `connected` (above) asks the question
422422
before a write.
423423

424+
12. **Code quality: the findings of a local SonarQube round (2026-11-29) on this release's code, with no behaviour
425+
change** - in lockstep with the Python pack. The 29 functions above the cognitive-complexity threshold of 15 are
426+
split along their natural seams, every check in the order it ran and with the message it wrote, so the shared
427+
vector files pass unchanged: in the built-in agent tools the glob walk, the file search, the page ranges, the
428+
HTML reader's start tag and tokenizer, the host rules, the address ranges, the crawl, the value renderer, the
429+
ingest plan, the schema, the boot and `describe`'s states; in REST automation the stages of a request (its
430+
trace, its body, its request model), an interceptor's reply, a stream's head and segments, a built-in's wait and
431+
headers, the static-content filter, an entry's service and methods and the response mapping;
432+
`AsyncHttpRequest.toMap`; the attachments loader; the ask-person and agent-question validators. The 21 functions
433+
of the LLM helper that use nothing of the helper they were nested in are functions of the module. Five
434+
expressions whose time could grow with the square of their input are linear and answer the same on every input:
435+
the trailing slashes of a base URL (ask-person, agent-question) and, in the agent tools, the trailing dots of a
436+
host name, the newlines around preformatted text, a robots.txt comment and the tag at a `<`. The sorts of
437+
ask-person take the explicit code-unit comparator the other extensions use, so a ticket's canonical JSON is byte
438+
for byte what it was. The idiom findings are taken where they mean the same (`Number.parseInt`, `String.raw`,
439+
`replaceAll`, `toReversed`, `.at()`, an optional chain, class fields). A finding kept on purpose says why on its
440+
line (`// NOSONAR - ...`): an `await` that is sequential by design - a running total, the statements of one
441+
transaction, a paced scan, a cursor - the helper's JSON form of a content block, and the two bindings `reset()`
442+
replaces in agent-question. **Upgrade note:** none - `CRAWL_RESULT_MAX_CHARS` of the agent tools is a constant
443+
now; its test hook `setCrawlResultMaxChars` works as before.
444+
424445
### Documentation
425446

426447
1. **The documentation site gains the REST Automation guide, and the references follow, in lockstep with the Python

‎extensions/agent-question/agent-question.mjs‎

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ export const PAGE_TITLE = 'question.page.title';
9797
export const MISSING_POSTGRES = 'question.store is postgres but the pg driver is not installed - npm install pg';
9898
const DURATION = /^(\d+)\s*(ms|s|m|h|d)?$/;
9999
const UNIT_MS = { ms: 1, s: 1000, m: 60_000, h: 3_600_000, d: 86_400_000 };
100+
// the slashes a base URL ends with; the lookbehind starts a match only at a run's first slash, so the scan stays linear
101+
const TRAILING_SLASHES = /(?<!\/)\/+$/;
100102

101103
/** A configuration the application cannot start with - the boot fails by name. */
102104
export class QuestionError extends Error {}
@@ -158,7 +160,7 @@ export function loadSettings(config) {
158160
if (!['memory', 'postgres'].includes(store)) throw new QuestionError(`${STORE} must be memory or postgres`);
159161
const auth = text(config, AUTH, 'none').toLowerCase();
160162
if (!AUTH_MODES.includes(auth)) throw new QuestionError(`${AUTH} must be one of ${AUTH_MODES.join(', ')}`);
161-
const issuer = text(config, OAUTH2_ISSUER).replace(/\/+$/, '');
163+
const issuer = text(config, OAUTH2_ISSUER).replace(TRAILING_SLASHES, '');
162164
const jwksUrl = text(config, OAUTH2_JWKS_URL);
163165
const clientId = text(config, OAUTH2_CLIENT_ID);
164166
if (auth === 'oauth2') {
@@ -224,6 +226,17 @@ export function publicRow(row) {
224226
};
225227
}
226228

229+
/** What a wait carries beyond an advice - its turn, its ticket, link and expiry, its calls - or an AppException(400). */
230+
function validateWait(event, turn) {
231+
if (turn === undefined || turn === null) throw new AppException(400, 'turn is required for an approval or a question');
232+
for (const name of ['ticket', 'link', 'expires_at']) {
233+
if (!isText(event[name]) || !event[name]) throw new AppException(400, `${name} is required for an approval or a question`);
234+
}
235+
if (!Array.isArray(event.calls) || event.calls.length === 0) {
236+
throw new AppException(400, 'calls must be a non-empty list for an approval or a question');
237+
}
238+
}
239+
227240
/** The message event the main flow sends, checked for what a channel needs - or an AppException(400). */
228241
export function validateEvent(event) {
229242
if (!isMap(event)) throw new AppException(400, 'the inbox takes the message event as a map');
@@ -235,15 +248,7 @@ export function validateEvent(event) {
235248
}
236249
const turn = event.turn;
237250
if (turn !== undefined && turn !== null && (!isWhole(turn) || turn < 0)) throw new AppException(400, 'turn must be a whole number >= 0');
238-
if (WAIT_KINDS.includes(kind)) {
239-
if (turn === undefined || turn === null) throw new AppException(400, 'turn is required for an approval or a question');
240-
for (const name of ['ticket', 'link', 'expires_at']) {
241-
if (!isText(event[name]) || !event[name]) throw new AppException(400, `${name} is required for an approval or a question`);
242-
}
243-
if (!Array.isArray(event.calls) || event.calls.length === 0) {
244-
throw new AppException(400, 'calls must be a non-empty list for an approval or a question');
245-
}
246-
}
251+
if (WAIT_KINDS.includes(kind)) validateWait(event, turn);
247252
for (const name of ['details', 'requested_at']) {
248253
if (event[name] !== undefined && event[name] !== null && !isText(event[name])) throw new AppException(400, `${name} must be text`);
249254
}
@@ -287,9 +292,13 @@ export class MemoryReader {
287292
this.turnRows = new Map();
288293
}
289294

290-
async open() {}
295+
async open() {
296+
// nothing to open: the rows are held in this process
297+
}
291298

292-
async close() {}
299+
async close() {
300+
// nothing to close: no connection is held
301+
}
293302

294303
put(row) {
295304
this.rows.set(row.id, row);
@@ -562,13 +571,11 @@ export class Wakeups {
562571
* wake-up from the intake or a click, whichever comes first.
563572
*/
564573
export class Feed {
565-
constructor() {
566-
this.cursor = 0;
567-
this.wake = null;
568-
this.pending = false;
569-
this.loop = null;
570-
this.stopped = false;
571-
}
574+
cursor = 0;
575+
wake = null;
576+
pending = false;
577+
loop = null;
578+
stopped = false;
572579

573580
kick() {
574581
if (this.wake) {
@@ -610,20 +617,20 @@ export class Feed {
610617
}
611618
this.pending = false;
612619
if (this.stopped) break;
613-
await this.pollOnce();
620+
await this.pollOnce(); // NOSONAR - sequential: each poll reads from the cursor the last one moved
614621
}
615622
}
616623

617624
start(pollMs) {
618-
if (this.loop) return;
625+
if (this.loop !== null) return;
619626
this.stopped = false;
620627
this.loop = this.run(pollMs);
621628
}
622629

623630
async stop() {
624631
this.stopped = true;
625632
this.kick();
626-
if (this.loop) await this.loop;
633+
if (this.loop !== null) await this.loop;
627634
this.loop = null;
628635
}
629636

@@ -633,8 +640,8 @@ export class Feed {
633640
}
634641

635642
let theReader = null;
636-
export let wakeups = new Wakeups();
637-
export let feed = new Feed();
643+
export let wakeups = new Wakeups(); // NOSONAR - reset() replaces it, and an importer reads the live binding
644+
export let feed = new Feed(); // NOSONAR - reset() replaces it, and an importer reads the live binding
638645

639646
export function reader() {
640647
theReader ??= new MemoryReader();
@@ -850,8 +857,7 @@ export function keepAliveMs() {
850857
if (['0', '0s', '0ms', '0m'].includes(raw)) return 0;
851858
const match = /^(\d+)(ms|s|m)?$/.exec(raw);
852859
if (!match) return 30_000;
853-
const unit = match[2] ?? 's';
854-
return Number.parseInt(match[1], 10) * (unit === 'ms' ? 1 : unit === 'm' ? 60_000 : 1000);
860+
return Number.parseInt(match[1], 10) * UNIT_MS[match[2] ?? 's'];
855861
}
856862

857863
/** A changed row as the `question` event's data: serialized here, so a null stays a null. */

0 commit comments

Comments
 (0)