clikit-plugin 0.3.20 → 0.3.22
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 +4 -6
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -665
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/package.json +2 -6
- package/command/augment-chat.md +0 -34
- package/dist/tools/augment.d.ts +0 -45
- package/dist/tools/augment.d.ts.map +0 -1
- package/dist/tui.d.ts +0 -4
- package/dist/tui.d.ts.map +0 -1
- package/dist/tui.js +0 -804
package/dist/tui.js
DELETED
|
@@ -1,804 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
|
-
var __export = (target, all) => {
|
|
20
|
-
for (var name in all)
|
|
21
|
-
__defProp(target, name, {
|
|
22
|
-
get: all[name],
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
set: (newValue) => all[name] = () => newValue
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
var __require = import.meta.require;
|
|
29
|
-
|
|
30
|
-
// src/tools/augment.ts
|
|
31
|
-
var REVIEW_RULE = {
|
|
32
|
-
intent: "review",
|
|
33
|
-
patterns: [
|
|
34
|
-
/\breview\b/,
|
|
35
|
-
/\baudit\b/,
|
|
36
|
-
/\bsecurity issues?\b/,
|
|
37
|
-
/\bfindings?\b/,
|
|
38
|
-
/\bpr\b/
|
|
39
|
-
]
|
|
40
|
-
};
|
|
41
|
-
var DEBUG_RULE = {
|
|
42
|
-
intent: "debug",
|
|
43
|
-
patterns: [
|
|
44
|
-
/\bdebug\b/,
|
|
45
|
-
/\bfix\b/,
|
|
46
|
-
/\bbug\b/,
|
|
47
|
-
/\bbroken\b/,
|
|
48
|
-
/\bfails?\b/,
|
|
49
|
-
/\bfailing\b/,
|
|
50
|
-
/\b404\b/,
|
|
51
|
-
/\berrors?\b/,
|
|
52
|
-
/\broot cause\b/
|
|
53
|
-
]
|
|
54
|
-
};
|
|
55
|
-
var REFACTOR_RULE = {
|
|
56
|
-
intent: "refactor",
|
|
57
|
-
patterns: [
|
|
58
|
-
/\brefactor\b/,
|
|
59
|
-
/\bclean\s+up\b/,
|
|
60
|
-
/\bcleanup\b/,
|
|
61
|
-
/\bsimplif(?:y|ication)\b/,
|
|
62
|
-
/\bdedupe\b/,
|
|
63
|
-
/\bdeduplicate\b/,
|
|
64
|
-
/\brestructure\b/,
|
|
65
|
-
/\breorganize\b/,
|
|
66
|
-
/\bduplication\b/
|
|
67
|
-
]
|
|
68
|
-
};
|
|
69
|
-
var TEST_FIX_RULE = {
|
|
70
|
-
intent: "test-fix",
|
|
71
|
-
patterns: [
|
|
72
|
-
/\btests?\b/,
|
|
73
|
-
/\bregression\b/,
|
|
74
|
-
/\bfix tests?\b/,
|
|
75
|
-
/\badd tests?\b/,
|
|
76
|
-
/\bupdate tests?\b/
|
|
77
|
-
]
|
|
78
|
-
};
|
|
79
|
-
var DOCS_RULE = {
|
|
80
|
-
intent: "docs",
|
|
81
|
-
patterns: [
|
|
82
|
-
/\breadme\b/i,
|
|
83
|
-
/\bdocs?\b/,
|
|
84
|
-
/\bdocument(?:ation)?\b/,
|
|
85
|
-
/\busage guide\b/
|
|
86
|
-
]
|
|
87
|
-
};
|
|
88
|
-
var RESEARCH_RULE = {
|
|
89
|
-
intent: "research",
|
|
90
|
-
patterns: [
|
|
91
|
-
/\bresearch\b/,
|
|
92
|
-
/\binvestigate\b/,
|
|
93
|
-
/\blook up\b/,
|
|
94
|
-
/\bcompare\b/,
|
|
95
|
-
/\bevaluate\b/,
|
|
96
|
-
/\bbest approach\b/
|
|
97
|
-
]
|
|
98
|
-
};
|
|
99
|
-
var EXPLAIN_RULE = {
|
|
100
|
-
intent: "explain",
|
|
101
|
-
patterns: [
|
|
102
|
-
/^explain\b/,
|
|
103
|
-
/^how\b/,
|
|
104
|
-
/^why\b/,
|
|
105
|
-
/\bwalk me through\b/,
|
|
106
|
-
/\bhelp me understand\b/
|
|
107
|
-
]
|
|
108
|
-
};
|
|
109
|
-
var IMPLEMENT_RULE = {
|
|
110
|
-
intent: "implement",
|
|
111
|
-
patterns: [
|
|
112
|
-
/\bimplement\b/,
|
|
113
|
-
/\bbuild\b/,
|
|
114
|
-
/\bcreate\b/,
|
|
115
|
-
/\badd\b/,
|
|
116
|
-
/\bintegrate\b/,
|
|
117
|
-
/\bwire up\b/,
|
|
118
|
-
/\bsupport\b/
|
|
119
|
-
]
|
|
120
|
-
};
|
|
121
|
-
var STRONG_INTENT_RULES = [
|
|
122
|
-
REVIEW_RULE,
|
|
123
|
-
DEBUG_RULE,
|
|
124
|
-
REFACTOR_RULE,
|
|
125
|
-
TEST_FIX_RULE,
|
|
126
|
-
DOCS_RULE,
|
|
127
|
-
RESEARCH_RULE,
|
|
128
|
-
EXPLAIN_RULE,
|
|
129
|
-
IMPLEMENT_RULE
|
|
130
|
-
];
|
|
131
|
-
var EXECUTION_CONTRACT_INTENTS = new Set([
|
|
132
|
-
"implement",
|
|
133
|
-
"debug",
|
|
134
|
-
"refactor",
|
|
135
|
-
"review",
|
|
136
|
-
"research",
|
|
137
|
-
"docs",
|
|
138
|
-
"test-fix"
|
|
139
|
-
]);
|
|
140
|
-
var STANDARD_INTENTS = new Set([
|
|
141
|
-
"implement",
|
|
142
|
-
"debug",
|
|
143
|
-
"refactor",
|
|
144
|
-
"review",
|
|
145
|
-
"research",
|
|
146
|
-
"docs",
|
|
147
|
-
"test-fix"
|
|
148
|
-
]);
|
|
149
|
-
var DEEP_SIGNALS = [
|
|
150
|
-
/\bcareful\b/,
|
|
151
|
-
/\bdeep\b/,
|
|
152
|
-
/\bthorough\b/,
|
|
153
|
-
/\bhigh.?stakes?\b/,
|
|
154
|
-
/\bproduction\b/,
|
|
155
|
-
/\bcritical\b/,
|
|
156
|
-
/\barchitecture\b/,
|
|
157
|
-
/\bsecurity\b/
|
|
158
|
-
];
|
|
159
|
-
function detectTaskIntent(draft) {
|
|
160
|
-
const normalized = normalizeDraft(draft);
|
|
161
|
-
if (!normalized) {
|
|
162
|
-
return "general";
|
|
163
|
-
}
|
|
164
|
-
for (const rule of STRONG_INTENT_RULES) {
|
|
165
|
-
if (rule.patterns.some((pattern) => pattern.test(normalized))) {
|
|
166
|
-
return rule.intent;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return "general";
|
|
170
|
-
}
|
|
171
|
-
function resolveRewriteMode(configuredMode, intent) {
|
|
172
|
-
if (configuredMode === "plain" || configuredMode === "execution-contract") {
|
|
173
|
-
return configuredMode;
|
|
174
|
-
}
|
|
175
|
-
return EXECUTION_CONTRACT_INTENTS.has(intent) ? "execution-contract" : "plain";
|
|
176
|
-
}
|
|
177
|
-
function inferIntensity(draft, intent) {
|
|
178
|
-
const normalized = normalizeDraft(draft);
|
|
179
|
-
if (DEEP_SIGNALS.some((pattern) => pattern.test(normalized))) {
|
|
180
|
-
return "Deep";
|
|
181
|
-
}
|
|
182
|
-
return STANDARD_INTENTS.has(intent) ? "Standard" : "Light";
|
|
183
|
-
}
|
|
184
|
-
function buildPromptLeverageBlocks(draft, intent, intensity) {
|
|
185
|
-
return {
|
|
186
|
-
objective: buildObjective(draft),
|
|
187
|
-
context: buildContext(intent),
|
|
188
|
-
workStyle: buildWorkStyle(intent, intensity),
|
|
189
|
-
toolRules: buildToolRules(intent),
|
|
190
|
-
outputContract: buildOutputContract(intent),
|
|
191
|
-
verification: buildVerification(intent),
|
|
192
|
-
doneCriteria: buildDoneCriteria(intent)
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
function augmentPrompt(draft, options = {}) {
|
|
196
|
-
const normalized = collapseWhitespace(draft);
|
|
197
|
-
if (!normalized) {
|
|
198
|
-
throw new Error("Prompt is required.");
|
|
199
|
-
}
|
|
200
|
-
const intent = detectTaskIntent(normalized);
|
|
201
|
-
const mode = resolveRewriteMode(options.mode ?? "auto", intent);
|
|
202
|
-
const intensity = inferIntensity(normalized, intent);
|
|
203
|
-
const blocks = buildPromptLeverageBlocks(normalized, intent, intensity);
|
|
204
|
-
return {
|
|
205
|
-
original: normalized,
|
|
206
|
-
intent,
|
|
207
|
-
mode,
|
|
208
|
-
intensity,
|
|
209
|
-
blocks,
|
|
210
|
-
enhanced: mode === "execution-contract" ? formatExecutionContract(normalized, blocks) : formatPlainRewrite(normalized, intent, blocks.outputContract),
|
|
211
|
-
enhancementSource: "deterministic"
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
async function augmentPromptWithRefinement(draft, options = {}) {
|
|
215
|
-
const deterministic = augmentPrompt(draft, options);
|
|
216
|
-
if (!options.refine) {
|
|
217
|
-
return deterministic;
|
|
218
|
-
}
|
|
219
|
-
try {
|
|
220
|
-
const refined = await options.refine({
|
|
221
|
-
original: deterministic.original,
|
|
222
|
-
enhanced: deterministic.enhanced,
|
|
223
|
-
intent: deterministic.intent,
|
|
224
|
-
mode: deterministic.mode,
|
|
225
|
-
intensity: deterministic.intensity,
|
|
226
|
-
blocks: deterministic.blocks
|
|
227
|
-
});
|
|
228
|
-
const normalized = normalizeEnhancedPrompt(refined);
|
|
229
|
-
if (!normalized) {
|
|
230
|
-
return {
|
|
231
|
-
...deterministic,
|
|
232
|
-
fallbackReason: "LLM refinement returned empty output."
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
...deterministic,
|
|
237
|
-
enhanced: normalized,
|
|
238
|
-
enhancementSource: "llm",
|
|
239
|
-
fallbackReason: undefined
|
|
240
|
-
};
|
|
241
|
-
} catch (error) {
|
|
242
|
-
return {
|
|
243
|
-
...deterministic,
|
|
244
|
-
fallbackReason: error instanceof Error ? error.message : "LLM refinement failed."
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function formatExecutionContract(draft, blocks) {
|
|
249
|
-
const task = stripObjectivePrefix(blocks.objective) || toSentence(draft);
|
|
250
|
-
return [
|
|
251
|
-
wrapTag("task", task),
|
|
252
|
-
wrapTag("context", bulletize(blocks.context)),
|
|
253
|
-
wrapTag("constraints", bulletize([blocks.workStyle, blocks.toolRules].filter(Boolean).join(`
|
|
254
|
-
`))),
|
|
255
|
-
wrapTag("verification", bulletize(blocks.verification)),
|
|
256
|
-
wrapTag("deliverable", [blocks.outputContract, blocks.doneCriteria].filter(Boolean).join(`
|
|
257
|
-
`))
|
|
258
|
-
].join(`
|
|
259
|
-
|
|
260
|
-
`);
|
|
261
|
-
}
|
|
262
|
-
function formatPlainRewrite(draft, intent, outputContract) {
|
|
263
|
-
const sentence = toSentence(draft);
|
|
264
|
-
if (intent === "explain") {
|
|
265
|
-
return [
|
|
266
|
-
sentence,
|
|
267
|
-
"Keep the explanation clear and well-structured without turning it into an execution plan."
|
|
268
|
-
].join(" ");
|
|
269
|
-
}
|
|
270
|
-
if (intent === "general") {
|
|
271
|
-
return [
|
|
272
|
-
sentence,
|
|
273
|
-
"Return a clear, well-structured response matched to the task. Keep it concise unless extra detail is necessary."
|
|
274
|
-
].join(" ");
|
|
275
|
-
}
|
|
276
|
-
return [sentence, outputContract].join(" ");
|
|
277
|
-
}
|
|
278
|
-
function buildObjective(draft) {
|
|
279
|
-
return `Complete this task: ${toSentence(draft)}`;
|
|
280
|
-
}
|
|
281
|
-
function buildContext(intent) {
|
|
282
|
-
switch (intent) {
|
|
283
|
-
case "implement":
|
|
284
|
-
return [
|
|
285
|
-
"Review the current code path and identify the narrowest safe integration point.",
|
|
286
|
-
"Preserve existing behavior outside the requested change."
|
|
287
|
-
].join(`
|
|
288
|
-
`);
|
|
289
|
-
case "debug":
|
|
290
|
-
return [
|
|
291
|
-
"Reproduce the issue first and confirm the failing path before editing.",
|
|
292
|
-
"Inspect the code and data flow around the suspected failure point."
|
|
293
|
-
].join(`
|
|
294
|
-
`);
|
|
295
|
-
case "refactor":
|
|
296
|
-
return [
|
|
297
|
-
"Map the current structure before extracting or consolidating logic.",
|
|
298
|
-
"Identify duplication and branching that can be simplified without changing behavior."
|
|
299
|
-
].join(`
|
|
300
|
-
`);
|
|
301
|
-
case "review":
|
|
302
|
-
return [
|
|
303
|
-
"Read enough surrounding context to understand intent before critiquing.",
|
|
304
|
-
"Focus on confirmed issues first, then call out plausible risks separately."
|
|
305
|
-
].join(`
|
|
306
|
-
`);
|
|
307
|
-
case "research":
|
|
308
|
-
return [
|
|
309
|
-
"Gather evidence from authoritative sources before concluding.",
|
|
310
|
-
"Preserve uncertainty explicitly when the evidence is incomplete or conflicting."
|
|
311
|
-
].join(`
|
|
312
|
-
`);
|
|
313
|
-
case "docs":
|
|
314
|
-
return [
|
|
315
|
-
"Read the current behavior and documentation surface before rewriting anything.",
|
|
316
|
-
"Keep commands, examples, and terminology aligned with the actual system."
|
|
317
|
-
].join(`
|
|
318
|
-
`);
|
|
319
|
-
case "test-fix":
|
|
320
|
-
return [
|
|
321
|
-
"Decide whether the test, the implementation, or both are wrong before changing anything.",
|
|
322
|
-
"Keep regression coverage close to the observed failure mode."
|
|
323
|
-
].join(`
|
|
324
|
-
`);
|
|
325
|
-
case "explain":
|
|
326
|
-
return [
|
|
327
|
-
"Preserve the original question and answer it directly.",
|
|
328
|
-
"Use structure only when it improves clarity."
|
|
329
|
-
].join(`
|
|
330
|
-
`);
|
|
331
|
-
case "general":
|
|
332
|
-
default:
|
|
333
|
-
return [
|
|
334
|
-
"Preserve the user\u2019s intent and constraints.",
|
|
335
|
-
"Add only enough structure to improve clarity and usefulness."
|
|
336
|
-
].join(`
|
|
337
|
-
`);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
function buildWorkStyle(intent, intensity) {
|
|
341
|
-
const guidance = [];
|
|
342
|
-
switch (intent) {
|
|
343
|
-
case "implement":
|
|
344
|
-
guidance.push("Understand the problem broadly enough to avoid narrow mistakes, then go deep where the risk is highest.");
|
|
345
|
-
guidance.push("Use first-principles reasoning before proposing changes.");
|
|
346
|
-
break;
|
|
347
|
-
case "debug":
|
|
348
|
-
guidance.push("Inspect before editing and find the root cause, not just the symptom.");
|
|
349
|
-
break;
|
|
350
|
-
case "refactor":
|
|
351
|
-
guidance.push("Preserve behavior while reducing duplication, branching, or complexity.");
|
|
352
|
-
break;
|
|
353
|
-
case "review":
|
|
354
|
-
guidance.push("Distinguish confirmed issues from plausible risks and order them by impact.");
|
|
355
|
-
break;
|
|
356
|
-
case "research":
|
|
357
|
-
guidance.push("Synthesize evidence into a recommendation instead of a raw note dump.");
|
|
358
|
-
break;
|
|
359
|
-
case "docs":
|
|
360
|
-
guidance.push("Optimize for accuracy, clarity, and examples that match real behavior.");
|
|
361
|
-
break;
|
|
362
|
-
case "test-fix":
|
|
363
|
-
guidance.push("Keep changes focused on the failing behavior and preserve useful coverage.");
|
|
364
|
-
break;
|
|
365
|
-
case "explain":
|
|
366
|
-
guidance.push("Stay explanatory and avoid turning the answer into an execution plan.");
|
|
367
|
-
break;
|
|
368
|
-
case "general":
|
|
369
|
-
guidance.push("Be specific, structured, and proportionate to the request.");
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
if (intensity === "Deep") {
|
|
373
|
-
guidance.push("Review the result once with fresh eyes before finalizing.");
|
|
374
|
-
}
|
|
375
|
-
if (intensity === "Standard") {
|
|
376
|
-
guidance.push("Cover the main edge cases before finalizing.");
|
|
377
|
-
}
|
|
378
|
-
return guidance.join(`
|
|
379
|
-
`);
|
|
380
|
-
}
|
|
381
|
-
function buildToolRules(intent) {
|
|
382
|
-
switch (intent) {
|
|
383
|
-
case "implement":
|
|
384
|
-
case "refactor":
|
|
385
|
-
case "debug":
|
|
386
|
-
case "test-fix":
|
|
387
|
-
return "Inspect the relevant files and dependencies first. Validate the final change with the narrowest useful checks before broadening scope.";
|
|
388
|
-
case "research":
|
|
389
|
-
return "Retrieve evidence from reliable sources before concluding. Do not guess facts that can be checked.";
|
|
390
|
-
case "review":
|
|
391
|
-
return "Read enough surrounding context to understand intent before critiquing. Distinguish confirmed issues from plausible risks.";
|
|
392
|
-
case "docs":
|
|
393
|
-
return "Read the current documentation and runtime behavior before rewriting. Keep examples and commands accurate.";
|
|
394
|
-
case "explain":
|
|
395
|
-
case "general":
|
|
396
|
-
default:
|
|
397
|
-
return "Use extra tools or context only when they materially improve correctness or completeness.";
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
function buildOutputContract(intent) {
|
|
401
|
-
switch (intent) {
|
|
402
|
-
case "implement":
|
|
403
|
-
case "refactor":
|
|
404
|
-
case "test-fix":
|
|
405
|
-
return "Return a practical execution result: concise summary, concrete changes, validation notes, and any remaining risks.";
|
|
406
|
-
case "debug":
|
|
407
|
-
return "Return a diagnosis with root cause, the fix, validation steps, and regression notes.";
|
|
408
|
-
case "research":
|
|
409
|
-
return "Return a structured synthesis with key findings, supporting evidence, and a concise recommendation.";
|
|
410
|
-
case "docs":
|
|
411
|
-
return "Return polished documentation aligned with current runtime behavior and verified examples.";
|
|
412
|
-
case "review":
|
|
413
|
-
return "Return findings grouped by severity or importance, explain why each matters, and suggest the smallest credible next step.";
|
|
414
|
-
case "explain":
|
|
415
|
-
return "Return a clear, well-structured explanation matched to the question.";
|
|
416
|
-
case "general":
|
|
417
|
-
default:
|
|
418
|
-
return "Return a clear, well-structured response matched to the task.";
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
function buildVerification(intent) {
|
|
422
|
-
switch (intent) {
|
|
423
|
-
case "implement":
|
|
424
|
-
case "refactor":
|
|
425
|
-
case "test-fix":
|
|
426
|
-
return [
|
|
427
|
-
"Check correctness, completeness, and edge cases.",
|
|
428
|
-
"Run relevant checks such as tests, lint, or typecheck when appropriate."
|
|
429
|
-
].join(`
|
|
430
|
-
`);
|
|
431
|
-
case "debug":
|
|
432
|
-
return [
|
|
433
|
-
"Check correctness, completeness, and edge cases.",
|
|
434
|
-
"Confirm the root cause is addressed and add regression coverage when appropriate."
|
|
435
|
-
].join(`
|
|
436
|
-
`);
|
|
437
|
-
case "review":
|
|
438
|
-
return [
|
|
439
|
-
"Check correctness and completeness.",
|
|
440
|
-
"Avoid speculative redesign unless it is necessary to explain a risk."
|
|
441
|
-
].join(`
|
|
442
|
-
`);
|
|
443
|
-
case "docs":
|
|
444
|
-
return [
|
|
445
|
-
"Check correctness and completeness.",
|
|
446
|
-
"Verify commands, examples, and terminology against the current behavior."
|
|
447
|
-
].join(`
|
|
448
|
-
`);
|
|
449
|
-
case "research":
|
|
450
|
-
return [
|
|
451
|
-
"Check correctness, completeness, and edge cases.",
|
|
452
|
-
"Call out uncertainty explicitly when evidence is incomplete or conflicting."
|
|
453
|
-
].join(`
|
|
454
|
-
`);
|
|
455
|
-
case "explain":
|
|
456
|
-
case "general":
|
|
457
|
-
default:
|
|
458
|
-
return [
|
|
459
|
-
"Check correctness, completeness, and edge cases.",
|
|
460
|
-
"Improve obvious weaknesses if a better phrasing is available within scope."
|
|
461
|
-
].join(`
|
|
462
|
-
`);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
function buildDoneCriteria(intent) {
|
|
466
|
-
switch (intent) {
|
|
467
|
-
case "implement":
|
|
468
|
-
case "refactor":
|
|
469
|
-
case "test-fix":
|
|
470
|
-
return "Stop only when the change is complete, the important checks pass, and there are no known regressions.";
|
|
471
|
-
case "debug":
|
|
472
|
-
return "Stop only when the root cause is confirmed fixed and regression coverage is in place when appropriate.";
|
|
473
|
-
case "review":
|
|
474
|
-
return "Stop only when the findings are clear, prioritized, and actionable.";
|
|
475
|
-
case "research":
|
|
476
|
-
return "Stop only when the synthesis is grounded in evidence and ends with a recommended path.";
|
|
477
|
-
case "docs":
|
|
478
|
-
return "Stop only when the documentation matches the current behavior and examples are accurate.";
|
|
479
|
-
case "explain":
|
|
480
|
-
return "Stop only when the explanation clearly answers the question.";
|
|
481
|
-
case "general":
|
|
482
|
-
default:
|
|
483
|
-
return "Stop only when the response satisfies the task and matches the requested format.";
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
function bulletize(text) {
|
|
487
|
-
return text.split(`
|
|
488
|
-
`).map((line) => collapseWhitespace(line)).filter(Boolean).map((line) => `- ${line}`).join(`
|
|
489
|
-
`);
|
|
490
|
-
}
|
|
491
|
-
function wrapTag(tagName, content) {
|
|
492
|
-
return `<${tagName}>
|
|
493
|
-
${content}
|
|
494
|
-
</${tagName}>`;
|
|
495
|
-
}
|
|
496
|
-
function stripObjectivePrefix(objective) {
|
|
497
|
-
return objective.replace(/^Complete this task:\s*/i, "").trim();
|
|
498
|
-
}
|
|
499
|
-
function normalizeDraft(draft) {
|
|
500
|
-
return collapseWhitespace(draft).toLowerCase();
|
|
501
|
-
}
|
|
502
|
-
function normalizeEnhancedPrompt(value) {
|
|
503
|
-
return (value ?? "").replace(/\r\n/g, `
|
|
504
|
-
`).trim();
|
|
505
|
-
}
|
|
506
|
-
function collapseWhitespace(value) {
|
|
507
|
-
return value.replace(/\r\n/g, `
|
|
508
|
-
`).replace(/\s+/g, " ").trim();
|
|
509
|
-
}
|
|
510
|
-
function toSentence(value) {
|
|
511
|
-
const normalized = collapseWhitespace(value);
|
|
512
|
-
if (!normalized) {
|
|
513
|
-
return "";
|
|
514
|
-
}
|
|
515
|
-
const capitalized = normalized.charAt(0).toUpperCase() + normalized.slice(1);
|
|
516
|
-
if (/[.!?]$/.test(capitalized)) {
|
|
517
|
-
return capitalized;
|
|
518
|
-
}
|
|
519
|
-
return `${capitalized}.`;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// src/tui.ts
|
|
523
|
-
var PROMPT_LOADING_TEXT = "\u23F3 Enhancing prompt\u2026";
|
|
524
|
-
function buildRefinementPrompt(input) {
|
|
525
|
-
return [
|
|
526
|
-
"You are refining an already-structured prompt for OpenCode.",
|
|
527
|
-
`Intent: ${input.intent}`,
|
|
528
|
-
`Rewrite mode: ${input.mode}`,
|
|
529
|
-
`Effort: ${input.intensity}`,
|
|
530
|
-
"Preserve the original user request exactly.",
|
|
531
|
-
"Keep the output as a single prompt only.",
|
|
532
|
-
"Do not add commentary, preambles, markdown fences, or explanations.",
|
|
533
|
-
"If the prompt is already strong, return a minimally polished version.",
|
|
534
|
-
"Return only the final rewritten prompt.",
|
|
535
|
-
"",
|
|
536
|
-
input.enhanced
|
|
537
|
-
].join(`
|
|
538
|
-
`);
|
|
539
|
-
}
|
|
540
|
-
function clonePromptInfo(prompt) {
|
|
541
|
-
return {
|
|
542
|
-
input: prompt.input,
|
|
543
|
-
mode: prompt.mode,
|
|
544
|
-
parts: [...prompt.parts]
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
function updatePromptRef(promptRef, prompt) {
|
|
548
|
-
promptRef.set(clonePromptInfo(prompt));
|
|
549
|
-
}
|
|
550
|
-
function getActivePromptRef(api, promptRefs) {
|
|
551
|
-
const currentRoute = api.route.current;
|
|
552
|
-
if (currentRoute.name === "session") {
|
|
553
|
-
const sessionID = currentRoute.params?.sessionID;
|
|
554
|
-
return typeof sessionID === "string" ? promptRefs.sessions.get(sessionID) : undefined;
|
|
555
|
-
}
|
|
556
|
-
return promptRefs.home;
|
|
557
|
-
}
|
|
558
|
-
function registerPromptSlots(api, promptRefs) {
|
|
559
|
-
const registerSlots = api.slots?.register;
|
|
560
|
-
if (typeof registerSlots !== "function") {
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
registerSlots({
|
|
564
|
-
slots: {
|
|
565
|
-
home_prompt: (_ctx, props) => api.ui.Prompt({
|
|
566
|
-
workspaceID: props.workspace_id,
|
|
567
|
-
ref: (ref) => {
|
|
568
|
-
promptRefs.home = ref;
|
|
569
|
-
props.ref?.(ref);
|
|
570
|
-
}
|
|
571
|
-
}),
|
|
572
|
-
session_prompt: (_ctx, props) => api.ui.Prompt({
|
|
573
|
-
sessionID: props.session_id,
|
|
574
|
-
visible: props.visible,
|
|
575
|
-
disabled: props.disabled,
|
|
576
|
-
onSubmit: props.on_submit,
|
|
577
|
-
ref: (ref) => {
|
|
578
|
-
if (ref) {
|
|
579
|
-
promptRefs.sessions.set(props.session_id, ref);
|
|
580
|
-
} else {
|
|
581
|
-
promptRefs.sessions.delete(props.session_id);
|
|
582
|
-
}
|
|
583
|
-
props.ref?.(ref);
|
|
584
|
-
}
|
|
585
|
-
})
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
}
|
|
589
|
-
function showAugmentResultToast(api, deliveryMode, result) {
|
|
590
|
-
const source = result.enhancementSource ?? "deterministic";
|
|
591
|
-
const successPrefix = deliveryMode === "replaced" ? "Replaced" : deliveryMode === "injected" ? "Injected" : "Prepared";
|
|
592
|
-
if (result.fallbackReason) {
|
|
593
|
-
api.ui.toast({
|
|
594
|
-
variant: "warning",
|
|
595
|
-
title: "CliKit Augment",
|
|
596
|
-
message: `${successPrefix} deterministic fallback. ${result.fallbackReason}`,
|
|
597
|
-
duration: 3500
|
|
598
|
-
});
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
api.ui.toast({
|
|
602
|
-
variant: "success",
|
|
603
|
-
title: "CliKit Augment",
|
|
604
|
-
message: deliveryMode === "replaced" ? `Enhanced prompt replaced in composer (${source}).` : deliveryMode === "injected" ? `Enhanced prompt inserted (${source}).` : `Enhanced prompt ready (${source}).`,
|
|
605
|
-
duration: 3500
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
function showAugmentErrorToast(api, error) {
|
|
609
|
-
const message = error instanceof Error ? error.message : "Prompt enhancement failed.";
|
|
610
|
-
api.ui.toast({
|
|
611
|
-
variant: "error",
|
|
612
|
-
title: "CliKit Augment",
|
|
613
|
-
message,
|
|
614
|
-
duration: 3500
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
async function enhancePromptDraft(api, draft) {
|
|
618
|
-
const directory = api.state.path.directory;
|
|
619
|
-
const workspace = api.workspace.current();
|
|
620
|
-
const client = api.scopedClient(workspace);
|
|
621
|
-
return augmentPromptWithRefinement(draft, {
|
|
622
|
-
mode: "auto",
|
|
623
|
-
refine: async ({ enhanced, mode, intent, intensity }) => {
|
|
624
|
-
const createResult = await client.session.create({
|
|
625
|
-
directory,
|
|
626
|
-
workspace,
|
|
627
|
-
title: `augment:${intent}`
|
|
628
|
-
});
|
|
629
|
-
if (createResult.error || !createResult.data?.id) {
|
|
630
|
-
throw new Error("Unable to create OpenCode session for prompt enhancement.");
|
|
631
|
-
}
|
|
632
|
-
const sessionID = createResult.data.id;
|
|
633
|
-
try {
|
|
634
|
-
const promptResult = await client.session.prompt({
|
|
635
|
-
sessionID,
|
|
636
|
-
directory,
|
|
637
|
-
workspace,
|
|
638
|
-
parts: [
|
|
639
|
-
{
|
|
640
|
-
type: "text",
|
|
641
|
-
text: buildRefinementPrompt({
|
|
642
|
-
enhanced,
|
|
643
|
-
intent,
|
|
644
|
-
mode,
|
|
645
|
-
intensity
|
|
646
|
-
})
|
|
647
|
-
}
|
|
648
|
-
]
|
|
649
|
-
});
|
|
650
|
-
if (promptResult.error) {
|
|
651
|
-
throw new Error("OpenCode prompt enhancement request failed.");
|
|
652
|
-
}
|
|
653
|
-
const textPart = promptResult.data?.parts?.find((part) => part.type === "text");
|
|
654
|
-
if (!textPart || !("text" in textPart) || typeof textPart.text !== "string") {
|
|
655
|
-
throw new Error("OpenCode prompt enhancement returned no text output.");
|
|
656
|
-
}
|
|
657
|
-
return textPart.text;
|
|
658
|
-
} finally {
|
|
659
|
-
client.session.delete({
|
|
660
|
-
sessionID,
|
|
661
|
-
directory,
|
|
662
|
-
workspace
|
|
663
|
-
}).catch(() => {
|
|
664
|
-
return;
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
async function injectPrompt(api, prompt) {
|
|
671
|
-
const directory = api.state.path.directory;
|
|
672
|
-
const workspace = api.workspace.current();
|
|
673
|
-
const client = api.scopedClient(workspace);
|
|
674
|
-
try {
|
|
675
|
-
await client.tui.clearPrompt?.({ directory, workspace });
|
|
676
|
-
await client.tui.appendPrompt({ directory, workspace, text: prompt });
|
|
677
|
-
return true;
|
|
678
|
-
} catch {
|
|
679
|
-
return false;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
async function deliverPrompt(api, prompt) {
|
|
683
|
-
if (await injectPrompt(api, prompt)) {
|
|
684
|
-
return "injected";
|
|
685
|
-
}
|
|
686
|
-
return "ready";
|
|
687
|
-
}
|
|
688
|
-
function openAugmentDialog(api, initialValue) {
|
|
689
|
-
api.ui.dialog.replace(() => api.ui.DialogPrompt({
|
|
690
|
-
title: "CliKit Augment",
|
|
691
|
-
placeholder: "Paste or type the prompt draft to enhance",
|
|
692
|
-
value: initialValue,
|
|
693
|
-
onConfirm: async (value) => {
|
|
694
|
-
await runDialogAugment(api, value);
|
|
695
|
-
},
|
|
696
|
-
onCancel: () => {
|
|
697
|
-
api.ui.dialog.clear();
|
|
698
|
-
}
|
|
699
|
-
}));
|
|
700
|
-
}
|
|
701
|
-
async function runDialogAugment(api, draft) {
|
|
702
|
-
const normalized = draft.trim();
|
|
703
|
-
if (!normalized) {
|
|
704
|
-
api.ui.toast({
|
|
705
|
-
variant: "error",
|
|
706
|
-
title: "CliKit Augment",
|
|
707
|
-
message: "Prompt is required.",
|
|
708
|
-
duration: 2500
|
|
709
|
-
});
|
|
710
|
-
return;
|
|
711
|
-
}
|
|
712
|
-
api.ui.toast({
|
|
713
|
-
variant: "info",
|
|
714
|
-
title: "CliKit Augment",
|
|
715
|
-
message: "Enhancing prompt.",
|
|
716
|
-
duration: 2000
|
|
717
|
-
});
|
|
718
|
-
const directory = api.state.path.directory;
|
|
719
|
-
const workspace = api.workspace.current();
|
|
720
|
-
const client = api.scopedClient(workspace);
|
|
721
|
-
try {
|
|
722
|
-
const result = await enhancePromptDraft(api, normalized);
|
|
723
|
-
const deliveryMode = await deliverPrompt(api, result.enhanced);
|
|
724
|
-
api.ui.dialog.clear();
|
|
725
|
-
showAugmentResultToast(api, deliveryMode, result);
|
|
726
|
-
} catch (error) {
|
|
727
|
-
showAugmentErrorToast(api, error);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
async function runComposerAugment(api, promptRef) {
|
|
731
|
-
const originalPrompt = clonePromptInfo(promptRef.current);
|
|
732
|
-
const normalized = originalPrompt.input.trim();
|
|
733
|
-
if (!normalized) {
|
|
734
|
-
api.ui.toast({
|
|
735
|
-
variant: "error",
|
|
736
|
-
title: "CliKit Augment",
|
|
737
|
-
message: "Prompt is required.",
|
|
738
|
-
duration: 2500
|
|
739
|
-
});
|
|
740
|
-
return;
|
|
741
|
-
}
|
|
742
|
-
try {
|
|
743
|
-
promptRef.blur();
|
|
744
|
-
updatePromptRef(promptRef, {
|
|
745
|
-
...originalPrompt,
|
|
746
|
-
input: PROMPT_LOADING_TEXT
|
|
747
|
-
});
|
|
748
|
-
} catch {
|
|
749
|
-
openAugmentDialog(api, originalPrompt.input);
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
try {
|
|
753
|
-
const result = await enhancePromptDraft(api, normalized);
|
|
754
|
-
updatePromptRef(promptRef, {
|
|
755
|
-
...originalPrompt,
|
|
756
|
-
input: result.enhanced
|
|
757
|
-
});
|
|
758
|
-
promptRef.focus();
|
|
759
|
-
showAugmentResultToast(api, "replaced", result);
|
|
760
|
-
} catch (error) {
|
|
761
|
-
try {
|
|
762
|
-
updatePromptRef(promptRef, originalPrompt);
|
|
763
|
-
promptRef.focus();
|
|
764
|
-
} catch {}
|
|
765
|
-
showAugmentErrorToast(api, error);
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
var CliKitTuiPlugin = {
|
|
769
|
-
id: "clikit-tui",
|
|
770
|
-
async tui(api) {
|
|
771
|
-
const promptRefs = {
|
|
772
|
-
sessions: new Map
|
|
773
|
-
};
|
|
774
|
-
registerPromptSlots(api, promptRefs);
|
|
775
|
-
const unregister = api.command.register(() => [
|
|
776
|
-
{
|
|
777
|
-
title: "CliKit Augment",
|
|
778
|
-
value: "clikit.augment",
|
|
779
|
-
description: "Rewrite the current composer prompt when available, with dialog fallback on unsupported runtimes.",
|
|
780
|
-
category: "CliKit",
|
|
781
|
-
slash: {
|
|
782
|
-
name: "augment"
|
|
783
|
-
},
|
|
784
|
-
onSelect: () => {
|
|
785
|
-
const promptRef = getActivePromptRef(api, promptRefs);
|
|
786
|
-
if (promptRef) {
|
|
787
|
-
runComposerAugment(api, promptRef);
|
|
788
|
-
return;
|
|
789
|
-
}
|
|
790
|
-
openAugmentDialog(api);
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
]);
|
|
794
|
-
api.lifecycle.onDispose(() => {
|
|
795
|
-
promptRefs.home = undefined;
|
|
796
|
-
promptRefs.sessions.clear();
|
|
797
|
-
});
|
|
798
|
-
api.lifecycle.onDispose(unregister);
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
var tui_default = CliKitTuiPlugin;
|
|
802
|
-
export {
|
|
803
|
-
tui_default as default
|
|
804
|
-
};
|