@mtayfur/opencode-prompt-enhancer 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/plugins/prompt-enhancer.js +25 -1
- package/package.json +1 -1
- package/plugins/prompt-enhancer.tsx +28 -1
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ OpenCode TUI plugin that rewrites rough prompt drafts into clearer, stronger pro
|
|
|
7
7
|
- Rewrites rough prompt drafts into clearer, stronger prompts.
|
|
8
8
|
- Uses lightweight workspace context.
|
|
9
9
|
- Keeps the original intent and language, and does not read file contents.
|
|
10
|
+
- Preserves a leading OpenCode slash command while enhancing only its instructions.
|
|
10
11
|
- Supports canceling an active enhancement and reverting an unchanged enhanced prompt.
|
|
11
12
|
|
|
12
13
|
## Context used
|
|
@@ -34,6 +34,19 @@ const DIALOG_BACKDROP_OPACITY = 0.65;
|
|
|
34
34
|
const DIALOG_PLACEHOLDER = "Describe the task...";
|
|
35
35
|
const DIALOG_HINT = "Enter to enhance • Shift+Enter for newline • Esc to cancel";
|
|
36
36
|
const TOAST_TITLE = "Prompt enhancer";
|
|
37
|
+
function parseEnhancementInput(input) {
|
|
38
|
+
const match = input.trimEnd().match(/^(\/[A-Za-z0-9][A-Za-z0-9._:-]*(?:\/[A-Za-z0-9][A-Za-z0-9._:-]*)*)(?:(?: +|\n)([\s\S]*))?$/);
|
|
39
|
+
if (!match) return {
|
|
40
|
+
draft: input.trim()
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
command: match[1],
|
|
44
|
+
draft: match[2]?.trim() ?? ""
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function formatEnhancedInput(input, enhancedDraft) {
|
|
48
|
+
return input.command ? `${input.command} ${enhancedDraft}` : enhancedDraft;
|
|
49
|
+
}
|
|
37
50
|
function parseModelString(value) {
|
|
38
51
|
if (!value) return undefined;
|
|
39
52
|
const trimmed = value.trim();
|
|
@@ -487,6 +500,16 @@ function openEnhanceDialog(api, options, state, setEnhanceDialog, signal) {
|
|
|
487
500
|
closeDialog();
|
|
488
501
|
return;
|
|
489
502
|
}
|
|
503
|
+
const enhancementInput = parseEnhancementInput(value);
|
|
504
|
+
if (!enhancementInput.draft) {
|
|
505
|
+
api.ui.toast({
|
|
506
|
+
variant: "warning",
|
|
507
|
+
title: TOAST_TITLE,
|
|
508
|
+
message: "Enter instructions after the slash command."
|
|
509
|
+
});
|
|
510
|
+
closeDialog();
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
490
513
|
if (!isPromptHandleActive(api, state, handle)) {
|
|
491
514
|
api.ui.toast({
|
|
492
515
|
variant: "warning",
|
|
@@ -536,7 +559,8 @@ function openEnhanceDialog(api, options, state, setEnhanceDialog, signal) {
|
|
|
536
559
|
if (state.activeEnhancement) {
|
|
537
560
|
state.activeEnhancement.stopAnimation = stopAnimation;
|
|
538
561
|
}
|
|
539
|
-
const
|
|
562
|
+
const enhancedDraft = await enhanceWithModel(api, options, enhancementInput.draft, enhancementController.signal);
|
|
563
|
+
const enhanced = formatEnhancedInput(enhancementInput, enhancedDraft);
|
|
540
564
|
if (signal.aborted) return;
|
|
541
565
|
if (enhancementController.signal.aborted) {
|
|
542
566
|
throw errorFromReason(enhancementController.signal.reason, ENHANCEMENT_CANCELED_MESSAGE);
|
package/package.json
CHANGED
|
@@ -101,6 +101,25 @@ type EnhanceDialogState = {
|
|
|
101
101
|
|
|
102
102
|
type SetEnhanceDialog = (dialog: EnhanceDialogState | undefined) => void
|
|
103
103
|
|
|
104
|
+
type EnhancementInput = {
|
|
105
|
+
command?: string
|
|
106
|
+
draft: string
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parseEnhancementInput(input: string): EnhancementInput {
|
|
110
|
+
const match = input.trimEnd().match(/^(\/[A-Za-z0-9][A-Za-z0-9._:-]*(?:\/[A-Za-z0-9][A-Za-z0-9._:-]*)*)(?:(?: +|\n)([\s\S]*))?$/)
|
|
111
|
+
if (!match) return { draft: input.trim() }
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
command: match[1],
|
|
115
|
+
draft: match[2]?.trim() ?? "",
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function formatEnhancedInput(input: EnhancementInput, enhancedDraft: string): string {
|
|
120
|
+
return input.command ? `${input.command} ${enhancedDraft}` : enhancedDraft
|
|
121
|
+
}
|
|
122
|
+
|
|
104
123
|
function parseModelString(value: string | undefined): ModelRef | undefined {
|
|
105
124
|
if (!value) return undefined
|
|
106
125
|
const trimmed = value.trim()
|
|
@@ -593,6 +612,13 @@ function openEnhanceDialog(
|
|
|
593
612
|
return
|
|
594
613
|
}
|
|
595
614
|
|
|
615
|
+
const enhancementInput = parseEnhancementInput(value)
|
|
616
|
+
if (!enhancementInput.draft) {
|
|
617
|
+
api.ui.toast({ variant: "warning", title: TOAST_TITLE, message: "Enter instructions after the slash command." })
|
|
618
|
+
closeDialog()
|
|
619
|
+
return
|
|
620
|
+
}
|
|
621
|
+
|
|
596
622
|
if (!isPromptHandleActive(api, state, handle)) {
|
|
597
623
|
api.ui.toast({ variant: "warning", title: TOAST_TITLE, message: "Prompt changed while dialog was open." })
|
|
598
624
|
closeDialog()
|
|
@@ -641,7 +667,8 @@ function openEnhanceDialog(
|
|
|
641
667
|
state.activeEnhancement.stopAnimation = stopAnimation
|
|
642
668
|
}
|
|
643
669
|
|
|
644
|
-
const
|
|
670
|
+
const enhancedDraft = await enhanceWithModel(api, options, enhancementInput.draft, enhancementController.signal)
|
|
671
|
+
const enhanced = formatEnhancedInput(enhancementInput, enhancedDraft)
|
|
645
672
|
if (signal.aborted) return
|
|
646
673
|
if (enhancementController.signal.aborted) {
|
|
647
674
|
throw errorFromReason(enhancementController.signal.reason, ENHANCEMENT_CANCELED_MESSAGE)
|