@mtayfur/opencode-prompt-enhancer 0.0.7 → 0.0.8
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtayfur/opencode-prompt-enhancer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "OpenCode plugin that rewrites rough drafts into stronger prompts.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@opencode-ai/plugin": "*",
|
|
29
29
|
"@opencode-ai/sdk": "*",
|
|
30
|
+
"@opentui/core": "*",
|
|
30
31
|
"@opentui/solid": "*",
|
|
31
32
|
"solid-js": "*"
|
|
32
33
|
},
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
export const ENHANCER_SYSTEM_PROMPT = `You are a prompt editor for OpenCode, an AI coding assistant.
|
|
2
2
|
|
|
3
3
|
Goal:
|
|
4
|
-
|
|
4
|
+
Clean up the user's draft only when it improves clarity. Preserve intent, scope, priorities, language, and tone. Always fix typos and awkward phrasing; otherwise return the draft unchanged when it is already clear.
|
|
5
5
|
|
|
6
6
|
Capabilities:
|
|
7
|
-
OpenCode can inspect the workspace, edit files, run commands, and verify changes.
|
|
7
|
+
OpenCode can inspect the workspace, edit files, run commands, and verify changes. Respect the user's requested mode: if the draft asks for discussion, planning, or review, keep it that way.
|
|
8
8
|
|
|
9
9
|
Rewrite rules:
|
|
10
10
|
- Preserve the request form. Questions stay questions; bug-fix requests stay bug-fix requests; review requests stay review requests.
|
|
11
11
|
- Preserve the language of the draft. Do not translate.
|
|
12
|
-
- Preserve inline code, file paths, command strings, error messages, identifiers, and quoted phrases verbatim
|
|
12
|
+
- Preserve inline code, file paths, command strings, error messages, identifiers, and quoted phrases verbatim.
|
|
13
13
|
- Preserve explicit constraints, file names, commands, acceptance criteria, and user wording.
|
|
14
|
-
- Use workspace context only when it directly clarifies
|
|
15
|
-
- Resolve vague references like "this"
|
|
14
|
+
- Use workspace context only when it directly clarifies an ambiguous reference.
|
|
15
|
+
- Resolve vague references like "this" or "that bug" only when context makes them unambiguous.
|
|
16
16
|
- Do not invent details when context is ambiguous.
|
|
17
|
-
-
|
|
18
|
-
- Keep the rewrite proportional to the draft. Do not add background, motivation, or steps the draft did not imply.
|
|
17
|
+
- Do not add background, motivation, implementation steps, acceptance criteria, or structure the draft did not imply.
|
|
19
18
|
- Match the draft's structure and tone. Keep prose as prose and lists as lists.
|
|
20
|
-
- If the draft is already precise, make only minimal cleanup.
|
|
21
19
|
|
|
22
20
|
Hard constraints:
|
|
23
21
|
- Do not invent requirements, files, APIs, dependencies, bugs, or acceptance criteria.
|
|
24
|
-
- Do not broaden scope with extra features, refactors, tests, or docs
|
|
22
|
+
- Do not broaden scope with extra features, refactors, tests, or docs.
|
|
23
|
+
- Do not inject assistant-style directives (e.g., "identify root cause", "verify the changed path", "follow local conventions").
|
|
25
24
|
- Do not ask follow-up questions.
|
|
26
25
|
- Do not mention context, tags, instructions, or the rewriting process.
|
|
27
26
|
- Do not output explanations, markdown fences, or commentary.
|
|
@@ -27,6 +27,8 @@ type PluginState = {
|
|
|
27
27
|
enhancing: boolean
|
|
28
28
|
promptRef?: TuiPromptRef
|
|
29
29
|
promptTarget?: PromptTarget
|
|
30
|
+
lastOriginal?: TuiPromptInfo
|
|
31
|
+
lastEnhancedInput?: string
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
type PromptTarget =
|
|
@@ -193,6 +195,11 @@ function gatherContext(api: Api): string {
|
|
|
193
195
|
const dir = api.state.path.directory
|
|
194
196
|
sections.push(`Working directory: ${dir}`)
|
|
195
197
|
|
|
198
|
+
const branch = api.state.vcs?.branch
|
|
199
|
+
if (branch) {
|
|
200
|
+
sections.push(`Current branch: ${branch}`)
|
|
201
|
+
}
|
|
202
|
+
|
|
196
203
|
const route = api.route.current
|
|
197
204
|
if (isSessionRoute(route)) {
|
|
198
205
|
const sessionID = route.params.sessionID
|
|
@@ -341,7 +348,7 @@ function openEnhanceDialog(
|
|
|
341
348
|
variant: "info",
|
|
342
349
|
title: TOAST_TITLE,
|
|
343
350
|
message: "Enhancing prompt...",
|
|
344
|
-
duration:
|
|
351
|
+
duration: 8_000,
|
|
345
352
|
})
|
|
346
353
|
|
|
347
354
|
void (async () => {
|
|
@@ -369,6 +376,9 @@ function openEnhanceDialog(
|
|
|
369
376
|
return
|
|
370
377
|
}
|
|
371
378
|
|
|
379
|
+
state.lastOriginal = originalPrompt
|
|
380
|
+
state.lastEnhancedInput = enhanced
|
|
381
|
+
|
|
372
382
|
api.ui.toast({
|
|
373
383
|
variant: "success",
|
|
374
384
|
title: "Prompt enhanced",
|
|
@@ -397,7 +407,7 @@ function openEnhanceDialog(
|
|
|
397
407
|
const baseMessage = error instanceof Error ? error.message : "Prompt enhancement failed."
|
|
398
408
|
const message = restored
|
|
399
409
|
? baseMessage
|
|
400
|
-
: `${baseMessage} Original prompt could not be restored because the prompt changed.`
|
|
410
|
+
: `${baseMessage} Original prompt could not be restored because the prompt changed. Please re-enter your prompt manually.`
|
|
401
411
|
api.ui.toast({ variant: "error", title: TOAST_TITLE, message })
|
|
402
412
|
} finally {
|
|
403
413
|
state.enhancing = false
|
|
@@ -408,6 +418,72 @@ function openEnhanceDialog(
|
|
|
408
418
|
))
|
|
409
419
|
}
|
|
410
420
|
|
|
421
|
+
function revertEnhancement(
|
|
422
|
+
api: Api,
|
|
423
|
+
state: PluginState,
|
|
424
|
+
signal: AbortSignal,
|
|
425
|
+
): void {
|
|
426
|
+
if (!state.lastOriginal) {
|
|
427
|
+
api.ui.toast({ variant: "warning", title: TOAST_TITLE, message: "No enhancement to revert." })
|
|
428
|
+
return
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const target = state.promptTarget
|
|
432
|
+
if (!target) {
|
|
433
|
+
api.ui.toast({ variant: "warning", title: TOAST_TITLE, message: "Revert only works from a prompt." })
|
|
434
|
+
return
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const handle: PromptHandle = {
|
|
438
|
+
target,
|
|
439
|
+
directory: api.state.path.directory,
|
|
440
|
+
ref: state.promptRef,
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (!isPromptHandleActive(api, state, handle)) {
|
|
444
|
+
api.ui.toast({ variant: "warning", title: TOAST_TITLE, message: "Prompt changed since enhancement." })
|
|
445
|
+
return
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
const currentInput = handle.ref?.current.input ?? ""
|
|
449
|
+
if (currentInput !== state.lastEnhancedInput) {
|
|
450
|
+
api.ui.toast({
|
|
451
|
+
variant: "warning",
|
|
452
|
+
title: TOAST_TITLE,
|
|
453
|
+
message: "Prompt was manually changed after enhancement. Revert skipped.",
|
|
454
|
+
})
|
|
455
|
+
return
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
void (async () => {
|
|
459
|
+
try {
|
|
460
|
+
const wrote = await restorePrompt(api, state, handle, state.lastOriginal!, signal)
|
|
461
|
+
if (!wrote) {
|
|
462
|
+
api.ui.toast({
|
|
463
|
+
variant: "warning",
|
|
464
|
+
title: TOAST_TITLE,
|
|
465
|
+
message: "Prompt changed while reverting.",
|
|
466
|
+
})
|
|
467
|
+
return
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
state.lastOriginal = undefined
|
|
471
|
+
state.lastEnhancedInput = undefined
|
|
472
|
+
|
|
473
|
+
api.ui.toast({
|
|
474
|
+
variant: "success",
|
|
475
|
+
title: TOAST_TITLE,
|
|
476
|
+
message: "Reverted to original prompt.",
|
|
477
|
+
duration: 3000,
|
|
478
|
+
})
|
|
479
|
+
} catch (error) {
|
|
480
|
+
if (signal.aborted) return
|
|
481
|
+
const message = error instanceof Error ? error.message : "Revert failed."
|
|
482
|
+
api.ui.toast({ variant: "error", title: TOAST_TITLE, message })
|
|
483
|
+
}
|
|
484
|
+
})()
|
|
485
|
+
}
|
|
486
|
+
|
|
411
487
|
const tui: TuiPlugin = async (api, options) => {
|
|
412
488
|
const state: PluginState = { enhancing: false }
|
|
413
489
|
|
|
@@ -455,19 +531,36 @@ const tui: TuiPlugin = async (api, options) => {
|
|
|
455
531
|
openEnhanceDialog(api, options, state, api.lifecycle.signal)
|
|
456
532
|
},
|
|
457
533
|
},
|
|
534
|
+
{
|
|
535
|
+
title: "Revert Enhanced Prompt",
|
|
536
|
+
value: "prompt-enhancer.revert",
|
|
537
|
+
description: "Revert last prompt enhancement (Ctrl+Shift+E)",
|
|
538
|
+
category: "Prompt",
|
|
539
|
+
keybind: "ctrl+shift+e",
|
|
540
|
+
slash: {
|
|
541
|
+
name: "revert-enhance",
|
|
542
|
+
aliases: ["revert-enhancement"],
|
|
543
|
+
},
|
|
544
|
+
onSelect: () => {
|
|
545
|
+
revertEnhancement(api, state, api.lifecycle.signal)
|
|
546
|
+
},
|
|
547
|
+
},
|
|
458
548
|
])
|
|
459
549
|
|
|
460
550
|
api.lifecycle.onDispose(() => {
|
|
461
551
|
unregister()
|
|
552
|
+
api.ui.dialog.clear()
|
|
462
553
|
state.enhancing = false
|
|
463
554
|
state.promptRef = undefined
|
|
464
555
|
state.promptTarget = undefined
|
|
556
|
+
state.lastOriginal = undefined
|
|
557
|
+
state.lastEnhancedInput = undefined
|
|
465
558
|
})
|
|
466
559
|
}
|
|
467
560
|
|
|
468
|
-
const plugin
|
|
561
|
+
const plugin = {
|
|
469
562
|
id: "prompt-enhancer",
|
|
470
563
|
tui,
|
|
471
|
-
}
|
|
564
|
+
} satisfies TuiPluginModule & { id: string }
|
|
472
565
|
|
|
473
566
|
export default plugin
|