Skip to content

feat(context): auto user-preference modeling — match the project's code style#22

Merged
QodeXcli merged 1 commit into
mainfrom
feat/style-preference-modeling
Jun 25, 2026
Merged

feat(context): auto user-preference modeling — match the project's code style#22
QodeXcli merged 1 commit into
mainfrom
feat/style-preference-modeling

Conversation

@QodeXcli

Copy link
Copy Markdown
Owner

The agent now learns your code style automatically — no explicit remember needed. It infers the project's conventions deterministically from its own source (+ .editorconfig when present) and injects a compact "Code style" block into the system prompt, so generated code blends in.

How

  • src/context/style-profile.ts (pure inference + thin scan):
    • inferIndent (tab vs space + width, from the most common indent step between lines), inferQuotes, inferSemicolons, inferNaming (camelCase vs snake_case).
    • profileFromSamples — majority vote across files + a confidence from sample size.
    • scanProjectStyle samples up to 25 source files (skips node_modules/dist/…); a root .editorconfig overrides the inferred indent (authoritative).
  • Loop: computed once per session (cached), injected at run start. On by default, off via context.styleProfile: false, skipped in plan mode.

This is the one genuinely-new item

From the latest review, this is the only gap that didn't already exist. The others — auto-eval after capture, skill stats, failure-driven learning, confidence scoring — all shipped earlier this session and are on main.

Live-verified

Ran it on this repo: inferred 2-space / single-quote / semicolons / camelCase at confidence 1.0 across 25 files — exactly QodeX's house style.

Tests

10 — each inference dimension (incl. tabs, 4-space, double quotes, snake_case), the majority-vote profile + confidence scaling, and the block builder's confidence floor. ✅ typecheck · ✅ full suite (1183) · ✅ build.

…de style

The agent now learns the user's code style WITHOUT an explicit `remember`: it
infers the project's conventions deterministically from its own source (plus
.editorconfig when present) and injects a compact "Code style" block into the
system prompt, so generated code blends in.

- src/context/style-profile.ts (pure inference + thin scan): inferIndent (tab vs
  space + width, from the most common indent step), inferQuotes, inferSemicolons,
  inferNaming (camelCase vs snake_case); profileFromSamples (majority vote +
  confidence); scanProjectStyle samples up to 25 source files (skipping
  node_modules/dist/…) and lets a root .editorconfig override the indent.
- Loop: computed ONCE per session (cached), injected at run start. On by default;
  off via context.styleProfile:false; skipped in plan mode.

This is the "User Preference Modeling" gap (Phase 3) — the only genuinely-new item
from the latest review; the others (auto-eval, stats, failure-learning, confidence)
already shipped earlier this session.

Live-verified on this repo: inferred 2-space / single-quote / semicolons /
camelCase at confidence 1.0 across 25 files — exactly QodeX's house style.

Tests: 10 (each inference dimension incl. tabs + 4-space + double + snake_case,
the majority-vote profile + confidence scaling, and the block builder's floor).
typecheck + full suite (1183) + build green.
@QodeXcli QodeXcli merged commit 5a7b522 into main Jun 25, 2026
2 checks passed
@QodeXcli QodeXcli deleted the feat/style-preference-modeling branch June 25, 2026 14:19
QodeXcli added a commit that referenced this pull request Jun 25, 2026
… before (#23)

Companion to user-preference modeling (#22). Instead of rediscovering a recurring
job, QodeX records a lean episode after each objectively-successful task and, at
the start of a new one, recalls the most SIMILAR past task on this project and
injects a one-line reminder of what worked. Off by default
(learning.episodicMemory.enabled).

Clean + lightweight, same discipline as #22:
- src/context/episodic-memory.ts (pure rank + thin I/O): records to
  ~/.qodex/episodes/<project>.jsonl; rankEpisodes scores a query against past
  episodes by lexical TF-cosine (reuses the tested similarity primitives — no
  embedding dependency), excludes near-identical re-runs (score ≥ 0.98), returns
  top-K above a similarity threshold; buildEpisodeBlock renders a concise block.
- SMART, not always-on: an unrelated task injects nothing (below threshold), and
  only a one-line summary is injected, never full transcripts.
- Loop hooks: record at the objective-success point (alongside capture/dataset);
  inject the recalled block into the system prompt at run start.
- The lexical ranker is a pure function, so an embedding-backed variant can be
  swapped in later without touching call sites.

Also: completed the README Self-learning section with the episodic-memory step,
its config, and a worked end-to-end example.

Live-verified: recorded two episodes, a pagination-shaped query recalled the
pagination episode (with files), an unrelated k8s query recalled nothing.
Tests: 6 (similar-retrieval, unrelated→empty, self-match excluded, topK/sort,
empty guards). typecheck + full suite (1189) + build green.

Co-authored-by: Louise Lau <QodeXcli@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant