Skip to content

feat(ai): YAML prompt templates with a Jinja2 dialect - #482

Merged
jmnote merged 9 commits into
mainfrom
feat/ai-template-editor
Nov 10, 2026
Merged

jmnote merged 9 commits into
mainfrom
feat/ai-template-editor

Conversation

@jmnote

@jmnote jmnote commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reworks AI edit prompt templates and their chains around YAML documents using a small Jinja2 dialect, and updates the chains tab editor.

Templates and the jinja2 dialect

  • A chain step and an AI edit prompt template are YAML documents with template_format: jinja2 and a template of <message role="system|user"> blocks.
  • goapp/prompts/jinja renders a small Jinja2 dialect: output with dotted names and character slices, if/elif/else, for with loop.*, raw, comments, - markers, with trim_blocks and lstrip_blocks on and nothing escaped. Where it overlaps Jinja2 the output matches Jinja2 3.1.
  • Wiki markup passes as text: {{ … }} is output only when its inside reads as an expression, so {{틀|a}}, {{{1}}}, {{#if:x}} and {{틀|{{ title }}}} keep working. A name the template is not given ({{ titel }}, {{PAGENAME}}) is an error on load and save; {% raw %} holds wiki markup that reads as a name.
  • Messages are split before values are filled in (prompts.ParseChat), so a value holding </message> stays in its message. A message that renders blank is not sent.

Chain files

  • snake_case keys: description, version, user_inputs, inputs, steps with template_format, template and output_variable (name, format).
  • A variable's value has a closed json_schema subset (string, string with enum, boolean, array of strings) and an optional ui with A2UI TextField names (variant: shortText|longText, placeholder). The API also sends the type read from them.
  • Function steps and derived inputs are gone. Lengths stand in the template ({{ wikitext[:1000] }}, {{ wikitext[:2000] }}). Backlinks are a run form value: the skin's run form has a fetch button calling GET /api/ai-edit/backlinks and lets the requester edit the list. Run form lists hold at most 20 items, and values at most 100,000 characters.
  • User messages of all four built-in chains list their variables in tags under # 변수 (<title>…</title>). Minor bumps only, so stored definitions, evaluations and rubrics stay current: doc-define and doc-eval v2.3, doc-create and doc-update v2.5.

Stored templates

  • A template is one YAML spec (aiedit_prompts.spec): name, description, template_format, template, input_variables picking the chain's variables by name. Saving checks it against the chain (Chain.WithTemplate). The model stays a setting of its own (aiedit_prompts.model), outside the spec, and does not bump the version.
  • Migration 202611100001 adds spec. tool migrate then converts templates saved before (aiedit.ConvertLegacyPrompts): instructions become the system message with {name} → {{ name }} and older names renamed, wiki markup that would read as template syntax goes in {% raw %}, and the user message lists the variables the instructions do not read. The old columns stay for now and will be dropped later.

Chains tab

  • The editor is the spec's YAML (left), with the template syntax the server read marked over it, beside preview values and the rendered messages (right). POST /api/ai-prompts/check takes request_type, spec and preview_values. Editing also offers the model and the version bump.
  • Clone opens a new template at the top with the source's spec renamed <source>-<user name> and the model the source runs on now.

Other

  • AI loop interval options gain 20 minutes.
  • docs/chain.md rewritten.

Verification

  • make checks GROUP=goapp (lint and tests) passes.
  • svelte-check: 0 errors (main and skin). ESLint passes on the changed main and skin files.
  • In the local dev environment, tool migrate converted all six stored templates. The chains tab and run form still need checking by hand.

- Templates pick their chain's user inputs by name (hint, useBacklinks,
  texts); each runs as the chain defines it, in the chain's order.
  Unknown names, repeats and attributes are refused on save; stored
  templates drop names the chain no longer has.
- Rename variables: doc-update wikitext -> body, backlinkTitles ->
  backlinks, readBacklinks -> useBacklinks. Built-in chains drop the
  request input. Stored templates and older run forms keep working
  through renames.
- User messages headed by variable names; the editor generates them
  from the picked inputs, with the system block first.
- Chains tab: one editor seen and edited in place, system and user rows
  beside their rendered messages, sample document and user input tables,
  inline clone, unsaved-change guard, model saved with the form.
- AI loop interval options gain 20 minutes.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T16:34:42.111507Z ae61f38 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb11cd44e3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread goapp/tasks/aiedit/request.go Resolved
…eal placeholders

- A template seen (not edited) previews the messages it runs with, rendered
  as they are (check with stored), instead of regenerated ones.
- Older variable names in stored templates are renamed only as {name}
  placeholders (prompts.RenamePlaceholders) and editor headings, leaving
  wiki markup such as {{wikitext}} intact.
@jmnote

jmnote commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8d067a4c23

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…n their live model

- The skin's clone sends input names; PickUserInputs also accepts an input
  sent exactly as the chain defines it, so skins loaded before this release
  still clone.
- Cloning a built-in chain reads its model live, and a model change in its
  open row updates the row.
@jmnote

jmnote commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 346558a2bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ving

- Store checks the editor's system-then-user order only for messages it
  builds (auto_messages); messages given as they are, as a skin's clone of
  an older template, are saved as they run.
- While a template saves, rows do not open, close or clone, and the editor
  reopens the saved template only if it is still the one shown.
@jmnote

jmnote commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: ffbc32392d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Chain steps and AI edit prompt templates are now Semantic Kernel style
prompt documents: a jinja2 template of <message role> blocks, rendered by
a small dialect (goapp/prompts/jinja) that leaves wiki markup such as
{{틀|a}} as text and reports unknown names on load and save.

- Chain files use snake_case keys, user_inputs and inputs with a closed
  json_schema subset and A2UI TextField ui hints, and output_variable.
  Function steps and derived inputs are gone: lengths stand in the
  template ({{ wikitext[:2000] }}), and backlinks are a run form value
  filled by GET /api/ai-edit/backlinks.
- User messages of every built-in chain list their variables in tags
  under "# 변수" (minor version bumps).
- A template is stored as one YAML spec (aiedit_prompts.spec); its model
  stays a setting of its own. tool migrate converts templates saved
  before specs.
- The chains tab edits the spec as YAML with the template syntax marked,
  beside preview values and the rendered messages.
@jmnote jmnote changed the title feat(ai): template editor with picked user inputs and paired previews feat(ai): Semantic Kernel style prompt templates with a jinja2 dialect Nov 10, 2026
@jmnote

jmnote commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 051d88d5e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread goapp/tasks/aiedit/legacy.go Resolved
Comment thread goapp/prompts/jinja/jinja.go Resolved
…ki parameters as text

- Legacy conversion keeps each stored message in its role and order, its if
  and each as blocks around it, so instructions saved in a user message
  (skin clones of content-only templates) survive. The variables' heading
  is sent only with a variable under it.
- {{{ is always text, so named wiki parameters ({{{title}}}) are not read
  as output.

jmnote commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac6eadca86

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread goapp/tasks/aiedit/legacy.go Resolved
Comment thread goapp/tasks/aiedit/legacy.go Resolved

jmnote commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08f5133996

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread goapp/tasks/aiedit/legacy.go Resolved

jmnote commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7c9173387

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread goapp/tasks/aiedit/legacy.go Resolved

jmnote commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: ae61f38724

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jmnote
jmnote merged commit 94d87cb into main Nov 10, 2026
5 checks passed
@jmnote
jmnote deleted the feat/ai-template-editor branch November 10, 2026 16:40
@jmnote jmnote changed the title feat(ai): Semantic Kernel style prompt templates with a jinja2 dialect feat(ai): YAML prompt templates with a Jinja2 dialect Nov 10, 2026
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