Skip to content

Add prompt editing support for task files - #493

Draft
tninja wants to merge 2 commits into
mainfrom
kang_feat_11
Draft

Add prompt editing support for task files#493
tninja wants to merge 2 commits into
mainfrom
kang_feat_11

Conversation

@tninja

@tninja tninja commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Summary

Task files are becoming the main place I write prompts, so this adds editing support aimed at that workflow: @ reference gating, outline navigation, long-form writing helpers, and reuse of prompts already written.

The immediate motivation was that @ completion fired on every @ character. Prompt files routinely contain pasted Java or Python, where @ is an annotation, not a file reference, so pasting code triggered a blocking completion prompt repeatedly. A single guard, ai-code--prompt-reference-position-p, now decides: @ must be outside any literal Org block and must begin a word. Both the capf path and the post-self-insert-hook path call that one guard, so they cannot drift apart. The explicit C-c @ command deliberately bypasses it, so completion is still reachable inside a src block when you actually want it.

Changes

  • Reference gating — mode-agnostic literal-block detection (textual, not org-in-src-block-p, so it also holds in non-org buffers); rejects @Override and user@, accepts @ at word start. Opts the mode out of helm's completion-in-region via helm's own supported option rather than advising helm internals, and enables company-capf buffer-locally so global-company-mode stays off.
  • Navigation — jump to a heading by full outline path, focus/restore a subtree, and per-file startup folding. New task files get #+STARTUP: content; folding applies only to files under the task directory, so the global org-startup-folded setting is untouched.
  • Writing — flyspell skips literal blocks (pasted code and logs are not prose), C-c b wraps a region in a block, and an opt-in ai-code-prompt-writing-mode for visual wrapping. Display only; buffer text is never rewritten, so what gets sent to the agent is unchanged.
  • Reuse — search past task files as a prompt corpus, browse the existing snippets by descriptive name instead of terse key, plus small context helpers for file/branch/defun.

All new keybindings are bound at load time rather than inside the mode body, so describe-mode lists them before the mode has been activated. Every soft dependency (helm, company, visual-fill-column, yasnippet) degrades silently when absent, with tests on the missing-dependency path.

Verification

A gauntlet script (test/run_ai_code_prompt_editing_gauntlet.sh) runs eight layers as fail-closed gates: 62 focused tests green, full suite at 1482 tests with the 13 pre-existing failures unchanged (names verified identical to baseline), byte compilation clean, checkdoc clean, 6/6 mutants killed by failing assertions, a negative control proving the guard tests actually bite, and real execution against a live task file in a real Emacs.

Two findings worth flagging, both fixed: a void-variable on helm's option aborted mode activation entirely and was caught only by the real-execution layer — the unit tests had been masking it — and one mutant initially "killed" the suite by making the file unloadable rather than by being detected, so the gauntlet now treats an incomplete run as a failure instead of evidence.

Scope

Additive. No change to the backend send path, no new hard dependencies, and the existing snippets are untouched. The pre-existing version< bug in test/test_00-bootstrap.el is out of scope; the gauntlet works around it with an isolated package-user-dir.

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