feat: graph context injection — the session's prior knowledge, steered in at session start (vision-context-injection.md)
One shot per chat, fired at the first turn's onFinish: the session's topic (its only typed message) is embedded as an EmbeddingGemma retrieval query; the semantically closest graph propositions are selected under the session's token budget (pure budget, no similarity threshold — the decided doctrine) and delivered as a marker-only steer through the wake pipeline, queuing behind pending questions like every sub-agent result. - contracts: ChatSettings.graphContextTokens (default 1024, max 4096, step 128, 0 = off); GraphContextData + graphContextText; the graph-context JobKind + buildGraphContextSteer (id steer_ctx_<chatId>) - core/graph-context.ts: brute-force cosine top-K, greedy chars/4 fill under budget, most-recent UnderstandingLevel fold, count cap 64, parse-don't-cast at the marker seam - server: embedQuery (role-asymmetric query format, same warm singleton — vector-space parity by construction); the runner (startGraphContext- Injection one-shot gates; runGraphContextJob validates ledger parity); wake branches (chatIdOf/jobIdOf, finalizeJob done, recoverStaleJobs re-deliver or contextRespawn); abortJob kills context jobs SILENTLY (nothing was promised in the lesson); turn-service trigger seam - adapter: data-graph-context flattens to the canonical block (malformed parts have no model face) - UI: the budget slider (home dock + /chat/new draft, the session-data strip); the quiet SystemLine "~537 · 10 propositions"; dock kind "Knowledge context"; model-picker PUT now spreads settings (a model pick can no longer clear the sibling override) Live-smoked end to end on the real embedder + real GLM: seeded ledger (10 propositions), session on "modal logic: possible worlds and the necessity box" — job in the dock, queued behind the prober's question, delivered on the answer, SystemLine in the transcript, wake turn reads the block and continues the probe. Gates: tsc, lint, 459/459, build.
This commit is contained in:
+20
-2
@@ -21,7 +21,8 @@ import { SubagentSteerCard } from "@/components/artifacts/steer-card";
|
||||
import { Composer } from "@/components/composer";
|
||||
import { JobsContext } from "@/components/jobs-context";
|
||||
import { StatsBar } from "@/components/stats-bar";
|
||||
import type { ChatSettings } from "@/src/core";
|
||||
import { graphContextOfMessage, type ChatSettings } from "@/src/core";
|
||||
import { formatTokens } from "@/components/usage-format";
|
||||
import { PlanBlock, PlanPopup, latestTree } from "@/components/plan-block";
|
||||
import { PlanMarginalia } from "@/components/plan-window";
|
||||
import { WaypointsIcon } from "lucide-react";
|
||||
@@ -81,6 +82,16 @@ const useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayout
|
||||
|
||||
/** A wake-pipeline steer message: user-role delivery whose metadata marks it
|
||||
* as a sub-agent result — rendered as an artifact card, never a bubble. */
|
||||
/** The knowledge-context card's one-liner: the numbers the observability
|
||||
* doctrine wants visible at the seam — tokens and proposition count
|
||||
* (parse-don't-cast; a malformed part still renders a quiet generic line). */
|
||||
function graphContextLine(message: { parts: ReadonlyArray<{ type: string; data?: unknown }> }): string {
|
||||
const data = graphContextOfMessage(message);
|
||||
return data
|
||||
? `Knowledge context — ~${formatTokens(data.tokens)} · ${data.propositions.length} propositions`
|
||||
: "Knowledge context";
|
||||
}
|
||||
|
||||
/** The quiet system line (custom-message scheme rendering): centered, muted,
|
||||
* small — the transcript's voice for events that are not speech (wake
|
||||
* scaffolding, the learner's plan verdict). */
|
||||
@@ -540,7 +551,14 @@ export function Chat({
|
||||
// PROTOCOL" §4). Key fallback: legacy transcripts (pre id-hygiene)
|
||||
// can still hold empty ids — the index keeps keys unique for them.
|
||||
<SubagentSteerCard key={m.id || `m-${mi}`} message={m} />
|
||||
) : m.role === "user" && m.parts.some((p) => p.type === "data-probe-handoff") ? (
|
||||
) : m.role === "user" && m.parts.some((p) => p.type === "data-graph-context") ? (
|
||||
// The prior-knowledge injection's delivery (vision-context-injection.md):
|
||||
// quiet system line, the numbers only — the block itself was for the
|
||||
// model (adapter flattening); the part data stays the audit trail.
|
||||
<SystemLine key={m.id || `m-${mi}`} testId="graph-context">
|
||||
{graphContextLine(m)}
|
||||
</SystemLine>
|
||||
) : m.role === "user" && m.parts.some((p) => p.type === "data-probe-handoff") ? (
|
||||
// The probe→teach handoff wake (custom-message scheme): quiet
|
||||
// system line, never a user bubble — the wake is scaffolding,
|
||||
// the "Planning" divider marks the seam, and the model-facing
|
||||
|
||||
Reference in New Issue
Block a user