Skip to content

Feature/563 template recommender - #736

Merged
Nanle-code merged 4 commits into
Nanle-code:masterfrom
mubking:feature/563-template-recommender
Jul 29, 2026
Merged

Feature/563 template recommender#736
Nanle-code merged 4 commits into
Nanle-code:masterfrom
mubking:feature/563-template-recommender

Conversation

@mubking

@mubking mubking commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements #563: an AI-enhanced contract template recommendation system for the
Stellar Dev Dashboard. Users describe what they want to build in plain language,
and the system ranks contract templates by fit, explains why each was suggested,
hands the chosen template to the existing customizer, and learns from which
templates users actually pick.

Closes #563.

What's included

  • Recommendation engine (src/lib/templateRecommendation.ts) — a pure,
    browser-safe scoring function that ranks templates against a requirement using
    tag overlap, category match, keyword hits, and a feedback boost. Every result
    carries a score and human-readable reasons.
  • Feedback store (src/lib/templateFeedbackStore.ts) — records which
    template a user chose for a given requirement (IndexedDB with in-memory
    fallback) and feeds that back into future rankings. This is the "improves with
    usage" mechanism.
  • Expanded template library (src/lib/templateManager.ts) — added tags,
    useCases, and a status field to ContractTemplate, plus a
    getReadyTemplates() helper. Grew the library from 4 to 27 templates.
  • UI (src/components/templates/TemplateRecommender.jsx) — requirement input,
    ranked suggestions with reasons, and handoff to the existing
    TemplateCustomizer.
  • Tests (src/lib/templateRecommendation.test.ts) — accuracy and
    feedback-loop coverage (details below).

Acceptance criteria

  • Suggests relevant templates 85% of the time — measured as strict top-1
    accuracy (the single highest-ranked template must be the expected one) across
    30 realistically-phrased requirements that avoid quoting template names. The
    suite asserts ≥85%; it currently passes at 100% on this set.
  • Templates are customizable — the recommender hands the chosen template to
    the existing TemplateCustomizer, reusing the current customization flow
    rather than duplicating it.
  • Recommendations improve with usage — a chosen template ranks higher for
    similar future requirements, verified by test; boosts do not leak across
    unrelated requirements.
  • Library includes 50+ contract patterns — see "Scope note" below.

Scope note (please read)

This PR ships 27 templates: 12 fully specified and 15 discovery-ready
work-in-progress stubs
(status: 'wip'), not the 50+ in the criteria. The WIP
stubs carry real tags and use-cases so the recommender surfaces them, but their
constructor/method detail is still to be written, and they are excluded from
deployment (getReadyTemplates() filters them out; the UI disables "Use this
template" for them). I chose depth over filler for this first pass and would
rather flag the gap than pad the count. Happy to complete the remaining stubs to
real templates in a follow-up, or in this PR if you'd prefer to hold it.

Design decisions worth flagging

  • Why not the existing src/ml/scoringEngine.js? It's Node-only
    (@tensorflow/tfjs-node) and scores transactions for fraud, so it can't run in
    the browser dashboard and doesn't address template fit. The recommender instead
    uses a transparent, deterministic scoring function — which also makes the 85%
    criterion provable in a unit test rather than flaky.
  • Which template system? TemplateLibrary.jsx loads contract templates from
    templateManager.ts, and the issue is about contract templates, so this builds
    on templateManager.ts. The separate transaction-template system
    (templateLibrary.ts) is untouched.

Also included

  • Pinned @tensorflow/tfjs-node to 4.22.0 in package.json (was ^5.0.0,
    which does not exist on npm and blocks npm install).

Testing

npm test src/lib/templateRecommendation.test.ts   # 6 tests, all passing
npm run type-check
npm run lint   # no new warnings/errors from these files

Follow-ups

  • Complete the 15 WIP stubs into fully-specified templates to reach 50+.

  • Mount TemplateRecommender into TemplateLibrary.jsx as a tab/panel (not yet
    wired — flagged for review since it touches existing UI).

    Closes AI-Enhanced Contract Template Library #563

@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

@mubking is attempting to deploy a commit to the nanle-code's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@mubking Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@mubking

mubking commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

hello

@Nanle-code
Nanle-code merged commit b54bc13 into Nanle-code:master Jul 29, 2026
7 of 27 checks passed
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.

AI-Enhanced Contract Template Library

2 participants