clikit-plugin 0.3.12 → 0.3.13

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/dist/index.js CHANGED
@@ -18247,6 +18247,498 @@ async function cassMemoryReflect(params = {}) {
18247
18247
  return embeddedReflect(p);
18248
18248
  }
18249
18249
 
18250
+ // src/tools/augment.ts
18251
+ var REVIEW_RULE = {
18252
+ intent: "review",
18253
+ patterns: [
18254
+ /\breview\b/,
18255
+ /\baudit\b/,
18256
+ /\bsecurity issues?\b/,
18257
+ /\bfindings?\b/,
18258
+ /\bpr\b/
18259
+ ]
18260
+ };
18261
+ var DEBUG_RULE = {
18262
+ intent: "debug",
18263
+ patterns: [
18264
+ /\bdebug\b/,
18265
+ /\bfix\b/,
18266
+ /\bbug\b/,
18267
+ /\bbroken\b/,
18268
+ /\bfails?\b/,
18269
+ /\bfailing\b/,
18270
+ /\b404\b/,
18271
+ /\berrors?\b/,
18272
+ /\broot cause\b/
18273
+ ]
18274
+ };
18275
+ var REFACTOR_RULE = {
18276
+ intent: "refactor",
18277
+ patterns: [
18278
+ /\brefactor\b/,
18279
+ /\bclean\s+up\b/,
18280
+ /\bcleanup\b/,
18281
+ /\bsimplif(?:y|ication)\b/,
18282
+ /\bdedupe\b/,
18283
+ /\bdeduplicate\b/,
18284
+ /\brestructure\b/,
18285
+ /\breorganize\b/,
18286
+ /\bduplication\b/
18287
+ ]
18288
+ };
18289
+ var TEST_FIX_RULE = {
18290
+ intent: "test-fix",
18291
+ patterns: [
18292
+ /\btests?\b/,
18293
+ /\bregression\b/,
18294
+ /\bfix tests?\b/,
18295
+ /\badd tests?\b/,
18296
+ /\bupdate tests?\b/
18297
+ ]
18298
+ };
18299
+ var DOCS_RULE = {
18300
+ intent: "docs",
18301
+ patterns: [
18302
+ /\breadme\b/i,
18303
+ /\bdocs?\b/,
18304
+ /\bdocument(?:ation)?\b/,
18305
+ /\busage guide\b/
18306
+ ]
18307
+ };
18308
+ var RESEARCH_RULE = {
18309
+ intent: "research",
18310
+ patterns: [
18311
+ /\bresearch\b/,
18312
+ /\binvestigate\b/,
18313
+ /\blook up\b/,
18314
+ /\bcompare\b/,
18315
+ /\bevaluate\b/,
18316
+ /\bbest approach\b/
18317
+ ]
18318
+ };
18319
+ var EXPLAIN_RULE = {
18320
+ intent: "explain",
18321
+ patterns: [
18322
+ /^explain\b/,
18323
+ /^how\b/,
18324
+ /^why\b/,
18325
+ /\bwalk me through\b/,
18326
+ /\bhelp me understand\b/
18327
+ ]
18328
+ };
18329
+ var IMPLEMENT_RULE = {
18330
+ intent: "implement",
18331
+ patterns: [
18332
+ /\bimplement\b/,
18333
+ /\bbuild\b/,
18334
+ /\bcreate\b/,
18335
+ /\badd\b/,
18336
+ /\bintegrate\b/,
18337
+ /\bwire up\b/,
18338
+ /\bsupport\b/
18339
+ ]
18340
+ };
18341
+ var STRONG_INTENT_RULES = [
18342
+ REVIEW_RULE,
18343
+ DEBUG_RULE,
18344
+ REFACTOR_RULE,
18345
+ TEST_FIX_RULE,
18346
+ DOCS_RULE,
18347
+ RESEARCH_RULE,
18348
+ EXPLAIN_RULE,
18349
+ IMPLEMENT_RULE
18350
+ ];
18351
+ var EXECUTION_CONTRACT_INTENTS = new Set([
18352
+ "implement",
18353
+ "debug",
18354
+ "refactor",
18355
+ "review",
18356
+ "research",
18357
+ "docs",
18358
+ "test-fix"
18359
+ ]);
18360
+ var STANDARD_INTENTS = new Set([
18361
+ "implement",
18362
+ "debug",
18363
+ "refactor",
18364
+ "review",
18365
+ "research",
18366
+ "docs",
18367
+ "test-fix"
18368
+ ]);
18369
+ var DEEP_SIGNALS = [
18370
+ /\bcareful\b/,
18371
+ /\bdeep\b/,
18372
+ /\bthorough\b/,
18373
+ /\bhigh.?stakes?\b/,
18374
+ /\bproduction\b/,
18375
+ /\bcritical\b/,
18376
+ /\barchitecture\b/,
18377
+ /\bsecurity\b/
18378
+ ];
18379
+ function detectTaskIntent(draft) {
18380
+ const normalized = normalizeDraft(draft);
18381
+ if (!normalized) {
18382
+ return "general";
18383
+ }
18384
+ for (const rule of STRONG_INTENT_RULES) {
18385
+ if (rule.patterns.some((pattern) => pattern.test(normalized))) {
18386
+ return rule.intent;
18387
+ }
18388
+ }
18389
+ return "general";
18390
+ }
18391
+ function resolveRewriteMode(configuredMode, intent) {
18392
+ if (configuredMode === "plain" || configuredMode === "execution-contract") {
18393
+ return configuredMode;
18394
+ }
18395
+ return EXECUTION_CONTRACT_INTENTS.has(intent) ? "execution-contract" : "plain";
18396
+ }
18397
+ function inferIntensity(draft, intent) {
18398
+ const normalized = normalizeDraft(draft);
18399
+ if (DEEP_SIGNALS.some((pattern) => pattern.test(normalized))) {
18400
+ return "Deep";
18401
+ }
18402
+ return STANDARD_INTENTS.has(intent) ? "Standard" : "Light";
18403
+ }
18404
+ function buildPromptLeverageBlocks(draft, intent, intensity) {
18405
+ return {
18406
+ objective: buildObjective(draft),
18407
+ context: buildContext(intent),
18408
+ workStyle: buildWorkStyle(intent, intensity),
18409
+ toolRules: buildToolRules(intent),
18410
+ outputContract: buildOutputContract(intent),
18411
+ verification: buildVerification(intent),
18412
+ doneCriteria: buildDoneCriteria(intent)
18413
+ };
18414
+ }
18415
+ function augmentPrompt(draft, options2 = {}) {
18416
+ const normalized = collapseWhitespace(draft);
18417
+ if (!normalized) {
18418
+ throw new Error("Prompt is required.");
18419
+ }
18420
+ const intent = detectTaskIntent(normalized);
18421
+ const mode = resolveRewriteMode(options2.mode ?? "auto", intent);
18422
+ const intensity = inferIntensity(normalized, intent);
18423
+ const blocks = buildPromptLeverageBlocks(normalized, intent, intensity);
18424
+ return {
18425
+ original: normalized,
18426
+ intent,
18427
+ mode,
18428
+ intensity,
18429
+ blocks,
18430
+ enhanced: mode === "execution-contract" ? formatExecutionContract(normalized, blocks) : formatPlainRewrite(normalized, intent, blocks.outputContract),
18431
+ enhancementSource: "deterministic"
18432
+ };
18433
+ }
18434
+ async function augmentPromptWithRefinement(draft, options2 = {}) {
18435
+ const deterministic = augmentPrompt(draft, options2);
18436
+ if (!options2.refine) {
18437
+ return deterministic;
18438
+ }
18439
+ try {
18440
+ const refined = await options2.refine({
18441
+ original: deterministic.original,
18442
+ enhanced: deterministic.enhanced,
18443
+ intent: deterministic.intent,
18444
+ mode: deterministic.mode,
18445
+ intensity: deterministic.intensity,
18446
+ blocks: deterministic.blocks
18447
+ });
18448
+ const normalized = normalizeEnhancedPrompt(refined);
18449
+ if (!normalized) {
18450
+ return {
18451
+ ...deterministic,
18452
+ fallbackReason: "LLM refinement returned empty output."
18453
+ };
18454
+ }
18455
+ return {
18456
+ ...deterministic,
18457
+ enhanced: normalized,
18458
+ enhancementSource: "llm",
18459
+ fallbackReason: undefined
18460
+ };
18461
+ } catch (error45) {
18462
+ return {
18463
+ ...deterministic,
18464
+ fallbackReason: error45 instanceof Error ? error45.message : "LLM refinement failed."
18465
+ };
18466
+ }
18467
+ }
18468
+ function formatExecutionContract(draft, blocks) {
18469
+ const task = stripObjectivePrefix(blocks.objective) || toSentence(draft);
18470
+ return [
18471
+ wrapTag("task", task),
18472
+ wrapTag("context", bulletize(blocks.context)),
18473
+ wrapTag("constraints", bulletize([blocks.workStyle, blocks.toolRules].filter(Boolean).join(`
18474
+ `))),
18475
+ wrapTag("verification", bulletize(blocks.verification)),
18476
+ wrapTag("deliverable", [blocks.outputContract, blocks.doneCriteria].filter(Boolean).join(`
18477
+ `))
18478
+ ].join(`
18479
+
18480
+ `);
18481
+ }
18482
+ function formatPlainRewrite(draft, intent, outputContract) {
18483
+ const sentence = toSentence(draft);
18484
+ if (intent === "explain") {
18485
+ return [
18486
+ sentence,
18487
+ "Keep the explanation clear and well-structured without turning it into an execution plan."
18488
+ ].join(" ");
18489
+ }
18490
+ if (intent === "general") {
18491
+ return [
18492
+ sentence,
18493
+ "Return a clear, well-structured response matched to the task. Keep it concise unless extra detail is necessary."
18494
+ ].join(" ");
18495
+ }
18496
+ return [sentence, outputContract].join(" ");
18497
+ }
18498
+ function buildObjective(draft) {
18499
+ return `Complete this task: ${toSentence(draft)}`;
18500
+ }
18501
+ function buildContext(intent) {
18502
+ switch (intent) {
18503
+ case "implement":
18504
+ return [
18505
+ "Review the current code path and identify the narrowest safe integration point.",
18506
+ "Preserve existing behavior outside the requested change."
18507
+ ].join(`
18508
+ `);
18509
+ case "debug":
18510
+ return [
18511
+ "Reproduce the issue first and confirm the failing path before editing.",
18512
+ "Inspect the code and data flow around the suspected failure point."
18513
+ ].join(`
18514
+ `);
18515
+ case "refactor":
18516
+ return [
18517
+ "Map the current structure before extracting or consolidating logic.",
18518
+ "Identify duplication and branching that can be simplified without changing behavior."
18519
+ ].join(`
18520
+ `);
18521
+ case "review":
18522
+ return [
18523
+ "Read enough surrounding context to understand intent before critiquing.",
18524
+ "Focus on confirmed issues first, then call out plausible risks separately."
18525
+ ].join(`
18526
+ `);
18527
+ case "research":
18528
+ return [
18529
+ "Gather evidence from authoritative sources before concluding.",
18530
+ "Preserve uncertainty explicitly when the evidence is incomplete or conflicting."
18531
+ ].join(`
18532
+ `);
18533
+ case "docs":
18534
+ return [
18535
+ "Read the current behavior and documentation surface before rewriting anything.",
18536
+ "Keep commands, examples, and terminology aligned with the actual system."
18537
+ ].join(`
18538
+ `);
18539
+ case "test-fix":
18540
+ return [
18541
+ "Decide whether the test, the implementation, or both are wrong before changing anything.",
18542
+ "Keep regression coverage close to the observed failure mode."
18543
+ ].join(`
18544
+ `);
18545
+ case "explain":
18546
+ return [
18547
+ "Preserve the original question and answer it directly.",
18548
+ "Use structure only when it improves clarity."
18549
+ ].join(`
18550
+ `);
18551
+ case "general":
18552
+ default:
18553
+ return [
18554
+ "Preserve the user\u2019s intent and constraints.",
18555
+ "Add only enough structure to improve clarity and usefulness."
18556
+ ].join(`
18557
+ `);
18558
+ }
18559
+ }
18560
+ function buildWorkStyle(intent, intensity) {
18561
+ const guidance = [];
18562
+ switch (intent) {
18563
+ case "implement":
18564
+ guidance.push("Understand the problem broadly enough to avoid narrow mistakes, then go deep where the risk is highest.");
18565
+ guidance.push("Use first-principles reasoning before proposing changes.");
18566
+ break;
18567
+ case "debug":
18568
+ guidance.push("Inspect before editing and find the root cause, not just the symptom.");
18569
+ break;
18570
+ case "refactor":
18571
+ guidance.push("Preserve behavior while reducing duplication, branching, or complexity.");
18572
+ break;
18573
+ case "review":
18574
+ guidance.push("Distinguish confirmed issues from plausible risks and order them by impact.");
18575
+ break;
18576
+ case "research":
18577
+ guidance.push("Synthesize evidence into a recommendation instead of a raw note dump.");
18578
+ break;
18579
+ case "docs":
18580
+ guidance.push("Optimize for accuracy, clarity, and examples that match real behavior.");
18581
+ break;
18582
+ case "test-fix":
18583
+ guidance.push("Keep changes focused on the failing behavior and preserve useful coverage.");
18584
+ break;
18585
+ case "explain":
18586
+ guidance.push("Stay explanatory and avoid turning the answer into an execution plan.");
18587
+ break;
18588
+ case "general":
18589
+ guidance.push("Be specific, structured, and proportionate to the request.");
18590
+ break;
18591
+ }
18592
+ if (intensity === "Deep") {
18593
+ guidance.push("Review the result once with fresh eyes before finalizing.");
18594
+ }
18595
+ if (intensity === "Standard") {
18596
+ guidance.push("Cover the main edge cases before finalizing.");
18597
+ }
18598
+ return guidance.join(`
18599
+ `);
18600
+ }
18601
+ function buildToolRules(intent) {
18602
+ switch (intent) {
18603
+ case "implement":
18604
+ case "refactor":
18605
+ case "debug":
18606
+ case "test-fix":
18607
+ return "Inspect the relevant files and dependencies first. Validate the final change with the narrowest useful checks before broadening scope.";
18608
+ case "research":
18609
+ return "Retrieve evidence from reliable sources before concluding. Do not guess facts that can be checked.";
18610
+ case "review":
18611
+ return "Read enough surrounding context to understand intent before critiquing. Distinguish confirmed issues from plausible risks.";
18612
+ case "docs":
18613
+ return "Read the current documentation and runtime behavior before rewriting. Keep examples and commands accurate.";
18614
+ case "explain":
18615
+ case "general":
18616
+ default:
18617
+ return "Use extra tools or context only when they materially improve correctness or completeness.";
18618
+ }
18619
+ }
18620
+ function buildOutputContract(intent) {
18621
+ switch (intent) {
18622
+ case "implement":
18623
+ case "refactor":
18624
+ case "test-fix":
18625
+ return "Return a practical execution result: concise summary, concrete changes, validation notes, and any remaining risks.";
18626
+ case "debug":
18627
+ return "Return a diagnosis with root cause, the fix, validation steps, and regression notes.";
18628
+ case "research":
18629
+ return "Return a structured synthesis with key findings, supporting evidence, and a concise recommendation.";
18630
+ case "docs":
18631
+ return "Return polished documentation aligned with current runtime behavior and verified examples.";
18632
+ case "review":
18633
+ return "Return findings grouped by severity or importance, explain why each matters, and suggest the smallest credible next step.";
18634
+ case "explain":
18635
+ return "Return a clear, well-structured explanation matched to the question.";
18636
+ case "general":
18637
+ default:
18638
+ return "Return a clear, well-structured response matched to the task.";
18639
+ }
18640
+ }
18641
+ function buildVerification(intent) {
18642
+ switch (intent) {
18643
+ case "implement":
18644
+ case "refactor":
18645
+ case "test-fix":
18646
+ return [
18647
+ "Check correctness, completeness, and edge cases.",
18648
+ "Run relevant checks such as tests, lint, or typecheck when appropriate."
18649
+ ].join(`
18650
+ `);
18651
+ case "debug":
18652
+ return [
18653
+ "Check correctness, completeness, and edge cases.",
18654
+ "Confirm the root cause is addressed and add regression coverage when appropriate."
18655
+ ].join(`
18656
+ `);
18657
+ case "review":
18658
+ return [
18659
+ "Check correctness and completeness.",
18660
+ "Avoid speculative redesign unless it is necessary to explain a risk."
18661
+ ].join(`
18662
+ `);
18663
+ case "docs":
18664
+ return [
18665
+ "Check correctness and completeness.",
18666
+ "Verify commands, examples, and terminology against the current behavior."
18667
+ ].join(`
18668
+ `);
18669
+ case "research":
18670
+ return [
18671
+ "Check correctness, completeness, and edge cases.",
18672
+ "Call out uncertainty explicitly when evidence is incomplete or conflicting."
18673
+ ].join(`
18674
+ `);
18675
+ case "explain":
18676
+ case "general":
18677
+ default:
18678
+ return [
18679
+ "Check correctness, completeness, and edge cases.",
18680
+ "Improve obvious weaknesses if a better phrasing is available within scope."
18681
+ ].join(`
18682
+ `);
18683
+ }
18684
+ }
18685
+ function buildDoneCriteria(intent) {
18686
+ switch (intent) {
18687
+ case "implement":
18688
+ case "refactor":
18689
+ case "test-fix":
18690
+ return "Stop only when the change is complete, the important checks pass, and there are no known regressions.";
18691
+ case "debug":
18692
+ return "Stop only when the root cause is confirmed fixed and regression coverage is in place when appropriate.";
18693
+ case "review":
18694
+ return "Stop only when the findings are clear, prioritized, and actionable.";
18695
+ case "research":
18696
+ return "Stop only when the synthesis is grounded in evidence and ends with a recommended path.";
18697
+ case "docs":
18698
+ return "Stop only when the documentation matches the current behavior and examples are accurate.";
18699
+ case "explain":
18700
+ return "Stop only when the explanation clearly answers the question.";
18701
+ case "general":
18702
+ default:
18703
+ return "Stop only when the response satisfies the task and matches the requested format.";
18704
+ }
18705
+ }
18706
+ function bulletize(text) {
18707
+ return text.split(`
18708
+ `).map((line) => collapseWhitespace(line)).filter(Boolean).map((line) => `- ${line}`).join(`
18709
+ `);
18710
+ }
18711
+ function wrapTag(tagName, content) {
18712
+ return `<${tagName}>
18713
+ ${content}
18714
+ </${tagName}>`;
18715
+ }
18716
+ function stripObjectivePrefix(objective) {
18717
+ return objective.replace(/^Complete this task:\s*/i, "").trim();
18718
+ }
18719
+ function normalizeDraft(draft) {
18720
+ return collapseWhitespace(draft).toLowerCase();
18721
+ }
18722
+ function normalizeEnhancedPrompt(value) {
18723
+ return (value ?? "").replace(/\r\n/g, `
18724
+ `).trim();
18725
+ }
18726
+ function collapseWhitespace(value) {
18727
+ return value.replace(/\r\n/g, `
18728
+ `).replace(/\s+/g, " ").trim();
18729
+ }
18730
+ function toSentence(value) {
18731
+ const normalized = collapseWhitespace(value);
18732
+ if (!normalized) {
18733
+ return "";
18734
+ }
18735
+ const capitalized = normalized.charAt(0).toUpperCase() + normalized.slice(1);
18736
+ if (/[.!?]$/.test(capitalized)) {
18737
+ return capitalized;
18738
+ }
18739
+ return `${capitalized}.`;
18740
+ }
18741
+
18250
18742
  // src/tools/context-summary.ts
18251
18743
  function parseStringArray(value) {
18252
18744
  if (typeof value !== "string" || !value.trim()) {
@@ -18416,6 +18908,47 @@ var CliKitPlugin = async (ctx) => {
18416
18908
  function getToolInput(args) {
18417
18909
  return args && typeof args === "object" ? args : {};
18418
18910
  }
18911
+ function getSessionClient() {
18912
+ if (!ctx.client || typeof ctx.client !== "object") {
18913
+ return;
18914
+ }
18915
+ const clientRecord = ctx.client;
18916
+ const sessionValue = clientRecord.session;
18917
+ if (!sessionValue || typeof sessionValue !== "object") {
18918
+ return;
18919
+ }
18920
+ const sessionRecord = sessionValue;
18921
+ const create = sessionRecord.create;
18922
+ const prompt = sessionRecord.prompt;
18923
+ const deleteSession = sessionRecord.delete;
18924
+ if (typeof create !== "function" || typeof prompt !== "function") {
18925
+ return;
18926
+ }
18927
+ return {
18928
+ create,
18929
+ prompt,
18930
+ delete: typeof deleteSession === "function" ? deleteSession : undefined
18931
+ };
18932
+ }
18933
+ function getTuiClient() {
18934
+ if (!ctx.client || typeof ctx.client !== "object") {
18935
+ return;
18936
+ }
18937
+ const clientRecord = ctx.client;
18938
+ const tuiValue = clientRecord.tui;
18939
+ if (!tuiValue || typeof tuiValue !== "object") {
18940
+ return;
18941
+ }
18942
+ const tuiRecord = tuiValue;
18943
+ const showToastMethod = tuiRecord.showToast;
18944
+ const appendPromptMethod = tuiRecord.appendPrompt;
18945
+ const clearPromptMethod = tuiRecord.clearPrompt;
18946
+ return {
18947
+ showToast: typeof showToastMethod === "function" ? showToastMethod : undefined,
18948
+ appendPrompt: typeof appendPromptMethod === "function" ? appendPromptMethod : undefined,
18949
+ clearPrompt: typeof clearPromptMethod === "function" ? clearPromptMethod : undefined
18950
+ };
18951
+ }
18419
18952
  function blockToolExecution(reason) {
18420
18953
  throw new Error(`[CliKit] Blocked tool execution: ${reason}`);
18421
18954
  }
@@ -18434,6 +18967,32 @@ var CliKitPlugin = async (ctx) => {
18434
18967
  return false;
18435
18968
  }
18436
18969
  }
18970
+ async function injectPromptIntoTui(prompt) {
18971
+ const tuiClient = getTuiClient();
18972
+ if (!tuiClient?.appendPrompt) {
18973
+ return false;
18974
+ }
18975
+ try {
18976
+ if (tuiClient.clearPrompt) {
18977
+ await tuiClient.clearPrompt({
18978
+ query: {
18979
+ directory: ctx.directory
18980
+ }
18981
+ });
18982
+ }
18983
+ await tuiClient.appendPrompt({
18984
+ body: {
18985
+ text: prompt
18986
+ },
18987
+ query: {
18988
+ directory: ctx.directory
18989
+ }
18990
+ });
18991
+ return true;
18992
+ } catch {
18993
+ return false;
18994
+ }
18995
+ }
18437
18996
  function normalizeTodos(rawTodos) {
18438
18997
  if (!Array.isArray(rawTodos)) {
18439
18998
  return [];
@@ -18681,6 +19240,99 @@ ${(content || "").trim()}`.trim();
18681
19240
  }
18682
19241
  return {
18683
19242
  tool: {
19243
+ augment_prompt: tool({
19244
+ description: "Rewrite a draft prompt into a stronger, intent-aware prompt for user review.",
19245
+ args: {
19246
+ draft: tool.schema.string().describe("Draft prompt to enhance before sending to the model."),
19247
+ mode: tool.schema.enum(["auto", "plain", "execution-contract"]).optional().describe("Optional rewrite mode override (default: auto).")
19248
+ },
19249
+ async execute(args) {
19250
+ const draft = typeof args.draft === "string" ? args.draft.trim() : "";
19251
+ if (!draft) {
19252
+ return JSON.stringify({
19253
+ success: false,
19254
+ error: "Draft prompt is required."
19255
+ }, null, 2);
19256
+ }
19257
+ await showToast("Enhancing prompt\u2026", "info", "CliKit Augment");
19258
+ const mode = args.mode === "plain" || args.mode === "execution-contract" ? args.mode : "auto";
19259
+ const sessionClient = getSessionClient();
19260
+ const result = await augmentPromptWithRefinement(draft, {
19261
+ mode,
19262
+ refine: sessionClient ? async ({ enhanced, mode: resolvedMode, intent, intensity }) => {
19263
+ const createResult = await sessionClient.create({
19264
+ directory: ctx.directory,
19265
+ title: `augment:${intent}`
19266
+ });
19267
+ if (createResult.error || !createResult.data?.id) {
19268
+ throw new Error("Unable to create OpenCode session for prompt enhancement.");
19269
+ }
19270
+ const sessionID = createResult.data.id;
19271
+ try {
19272
+ const refinementPrompt = [
19273
+ "You are refining an already-structured prompt for OpenCode.",
19274
+ `Intent: ${intent}`,
19275
+ `Rewrite mode: ${resolvedMode}`,
19276
+ `Effort: ${intensity}`,
19277
+ "Preserve the original user request exactly.",
19278
+ "Keep the output as a single prompt only.",
19279
+ "Do not add commentary, preambles, markdown fences, or explanations.",
19280
+ "If the prompt is already strong, return a minimally polished version.",
19281
+ "Return only the final rewritten prompt.",
19282
+ "",
19283
+ enhanced
19284
+ ].join(`
19285
+ `);
19286
+ const promptResult = await sessionClient.prompt({
19287
+ sessionID,
19288
+ directory: ctx.directory,
19289
+ parts: [
19290
+ {
19291
+ type: "text",
19292
+ text: refinementPrompt
19293
+ }
19294
+ ]
19295
+ });
19296
+ if (promptResult.error) {
19297
+ throw new Error("OpenCode prompt enhancement request failed.");
19298
+ }
19299
+ const textPart = promptResult.data?.parts?.find((part) => part.type === "text");
19300
+ if (!textPart || !("text" in textPart) || typeof textPart.text !== "string") {
19301
+ throw new Error("OpenCode prompt enhancement returned no text output.");
19302
+ }
19303
+ return textPart.text;
19304
+ } finally {
19305
+ if (sessionClient.delete) {
19306
+ sessionClient.delete({
19307
+ sessionID,
19308
+ directory: ctx.directory
19309
+ }).catch(() => {
19310
+ return;
19311
+ });
19312
+ }
19313
+ }
19314
+ } : undefined
19315
+ });
19316
+ const injectedIntoTui = await injectPromptIntoTui(result.enhanced);
19317
+ const completionTitle = "CliKit Augment";
19318
+ if (result.fallbackReason) {
19319
+ await showToast(injectedIntoTui ? `Injected deterministic fallback. ${result.fallbackReason}` : `Using deterministic fallback. ${result.fallbackReason}`, "warning", completionTitle);
19320
+ } else {
19321
+ await showToast(injectedIntoTui ? `Enhanced prompt inserted (${result.enhancementSource ?? "deterministic"}).` : `Enhanced prompt ready (${result.enhancementSource ?? "deterministic"}).`, "success", completionTitle);
19322
+ }
19323
+ return JSON.stringify({
19324
+ success: true,
19325
+ original: result.original,
19326
+ enhanced: result.enhanced,
19327
+ intent: result.intent,
19328
+ mode: result.mode,
19329
+ intensity: result.intensity,
19330
+ injectedIntoTui,
19331
+ enhancementSource: result.enhancementSource,
19332
+ fallbackReason: result.fallbackReason
19333
+ }, null, 2);
19334
+ }
19335
+ }),
18684
19336
  context_summary: tool({
18685
19337
  description: "Summarize memory observations (decisions, learnings, blockers, progress) into a structured context digest. Useful for compaction or session handoff.",
18686
19338
  args: {