docs: rewrite Semantic Querying concept with imperative-vs-declarative diagram

Reframe semantic-layer-internals.mdx around the contract the semantic
layer offers an agent: declare what you want (a Semantic Query), KTX
figures out how to compute it. Replaces the old "Context-Aware SQL"
framing with a clear imperative-vs-declarative narrative.

Adds a React Flow component (semantic-layer-flow.tsx) that contrasts a
buggy 4-table agent-authored SQL (chasm trap, LEFT-JOIN-in-WHERE,
hardcoded DATE_TRUNC) against the chasm-safe per-fact CTE SQL the
planner actually emits, including the outer GROUP BY over the requested
dimensions. Both lanes converge into a shared warehouse node and each
SQL card now has parallel bullet notes (failures on the left, KTX
behavior on the right).

Side fixes bundled in:
- include the /ktx basePath in the favicon metadata so the icon resolves
  under the production prefix
- migrate docs-site/middleware.ts to docs-site/proxy.ts (Next 16 rename)
- redirect / to /ktx/docs/getting-started/introduction so the apex docs
  URL works
- add tests covering the apex redirect, the favicon basePath, and the
  middleware-to-proxy rename
- propagate the Semantic Query terminology across the ktx-sl CLI
  reference, the context-layer concept page, and the agent-clients /
  primary-sources integration pages
This commit is contained in:
Andrey Avtomonov 2026-05-19 19:34:04 +02:00
parent 14c2567c14
commit 911cfdc741
11 changed files with 1081 additions and 232 deletions

View file

@ -112,6 +112,18 @@ test("/ktx/docs redirects to the docs introduction", async () => {
);
});
test("/ redirects into the /ktx docs site", async () => {
const response = await fetch(`${docsSiteUrl}/`, {
redirect: "manual",
});
assert.equal(response.status, 307);
assert.equal(
response.headers.get("location"),
`${docsBasePath}/docs/getting-started/introduction`,
);
});
test("/ktx/api/search returns docs search results", async () => {
const response = await fetch(
`${docsSiteUrl}${docsBasePath}/api/search?query=setup`,

View file

@ -1,5 +1,5 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { access, readFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
@ -17,6 +17,23 @@ test("root provider uses the base-path-aware search API", async () => {
assert.match(layout, /api:\s*"\/ktx\/api\/search"/);
});
test("metadata icons include the docs base path", async () => {
const layout = await readDocsFile("app/layout.tsx");
assert.match(layout, /icon:\s*"\/ktx\/brand\/ktx-mascot\.svg"/);
assert.match(layout, /shortcut:\s*"\/ktx\/brand\/ktx-mascot\.svg"/);
assert.doesNotMatch(layout, /:\s*"\/brand\/ktx-mascot\.svg"/);
});
test("markdown negotiation uses the Next proxy convention", async () => {
await assert.doesNotReject(access(join(docsSiteDir, "proxy.ts")));
await assert.rejects(access(join(docsSiteDir, "middleware.ts")));
const proxy = await readDocsFile("proxy.ts");
assert.match(proxy, /export function proxy/);
assert.doesNotMatch(proxy, /export function middleware/);
});
test("site background stacking does not target every body child", async () => {
const css = await readDocsFile("app/global.css");