clikit-plugin 0.3.21 → 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 +0 -706
- 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 -827
package/dist/index.js
CHANGED
|
@@ -18247,518 +18247,6 @@ async function cassMemoryReflect(params = {}) {
|
|
|
18247
18247
|
return embeddedReflect(p);
|
|
18248
18248
|
}
|
|
18249
18249
|
|
|
18250
|
-
// src/tools/augment.ts
|
|
18251
|
-
var EMPTY_PROMPT_BLOCKS = {
|
|
18252
|
-
objective: "",
|
|
18253
|
-
context: "",
|
|
18254
|
-
workStyle: "",
|
|
18255
|
-
toolRules: "",
|
|
18256
|
-
outputContract: "",
|
|
18257
|
-
verification: "",
|
|
18258
|
-
doneCriteria: ""
|
|
18259
|
-
};
|
|
18260
|
-
var REVIEW_RULE = {
|
|
18261
|
-
intent: "review",
|
|
18262
|
-
patterns: [
|
|
18263
|
-
/\breview\b/,
|
|
18264
|
-
/\baudit\b/,
|
|
18265
|
-
/\bsecurity issues?\b/,
|
|
18266
|
-
/\bfindings?\b/,
|
|
18267
|
-
/\bpr\b/
|
|
18268
|
-
]
|
|
18269
|
-
};
|
|
18270
|
-
var DEBUG_RULE = {
|
|
18271
|
-
intent: "debug",
|
|
18272
|
-
patterns: [
|
|
18273
|
-
/\bdebug\b/,
|
|
18274
|
-
/\bfix\b/,
|
|
18275
|
-
/\bbug\b/,
|
|
18276
|
-
/\bbroken\b/,
|
|
18277
|
-
/\bfails?\b/,
|
|
18278
|
-
/\bfailing\b/,
|
|
18279
|
-
/\b404\b/,
|
|
18280
|
-
/\berrors?\b/,
|
|
18281
|
-
/\broot cause\b/
|
|
18282
|
-
]
|
|
18283
|
-
};
|
|
18284
|
-
var REFACTOR_RULE = {
|
|
18285
|
-
intent: "refactor",
|
|
18286
|
-
patterns: [
|
|
18287
|
-
/\brefactor\b/,
|
|
18288
|
-
/\bclean\s+up\b/,
|
|
18289
|
-
/\bcleanup\b/,
|
|
18290
|
-
/\bsimplif(?:y|ication)\b/,
|
|
18291
|
-
/\bdedupe\b/,
|
|
18292
|
-
/\bdeduplicate\b/,
|
|
18293
|
-
/\brestructure\b/,
|
|
18294
|
-
/\breorganize\b/,
|
|
18295
|
-
/\bduplication\b/
|
|
18296
|
-
]
|
|
18297
|
-
};
|
|
18298
|
-
var TEST_FIX_RULE = {
|
|
18299
|
-
intent: "test-fix",
|
|
18300
|
-
patterns: [
|
|
18301
|
-
/\btests?\b/,
|
|
18302
|
-
/\bregression\b/,
|
|
18303
|
-
/\bfix tests?\b/,
|
|
18304
|
-
/\badd tests?\b/,
|
|
18305
|
-
/\bupdate tests?\b/
|
|
18306
|
-
]
|
|
18307
|
-
};
|
|
18308
|
-
var DOCS_RULE = {
|
|
18309
|
-
intent: "docs",
|
|
18310
|
-
patterns: [
|
|
18311
|
-
/\breadme\b/i,
|
|
18312
|
-
/\bdocs?\b/,
|
|
18313
|
-
/\bdocument(?:ation)?\b/,
|
|
18314
|
-
/\busage guide\b/
|
|
18315
|
-
]
|
|
18316
|
-
};
|
|
18317
|
-
var RESEARCH_RULE = {
|
|
18318
|
-
intent: "research",
|
|
18319
|
-
patterns: [
|
|
18320
|
-
/\bresearch\b/,
|
|
18321
|
-
/\binvestigate\b/,
|
|
18322
|
-
/\blook up\b/,
|
|
18323
|
-
/\bcompare\b/,
|
|
18324
|
-
/\bevaluate\b/,
|
|
18325
|
-
/\bbest approach\b/
|
|
18326
|
-
]
|
|
18327
|
-
};
|
|
18328
|
-
var EXPLAIN_RULE = {
|
|
18329
|
-
intent: "explain",
|
|
18330
|
-
patterns: [
|
|
18331
|
-
/^explain\b/,
|
|
18332
|
-
/^how\b/,
|
|
18333
|
-
/^why\b/,
|
|
18334
|
-
/\bwalk me through\b/,
|
|
18335
|
-
/\bhelp me understand\b/
|
|
18336
|
-
]
|
|
18337
|
-
};
|
|
18338
|
-
var IMPLEMENT_RULE = {
|
|
18339
|
-
intent: "implement",
|
|
18340
|
-
patterns: [
|
|
18341
|
-
/\bimplement\b/,
|
|
18342
|
-
/\bbuild\b/,
|
|
18343
|
-
/\bcreate\b/,
|
|
18344
|
-
/\badd\b/,
|
|
18345
|
-
/\bintegrate\b/,
|
|
18346
|
-
/\bwire up\b/,
|
|
18347
|
-
/\bsupport\b/
|
|
18348
|
-
]
|
|
18349
|
-
};
|
|
18350
|
-
var STRONG_INTENT_RULES = [
|
|
18351
|
-
REVIEW_RULE,
|
|
18352
|
-
DEBUG_RULE,
|
|
18353
|
-
REFACTOR_RULE,
|
|
18354
|
-
TEST_FIX_RULE,
|
|
18355
|
-
DOCS_RULE,
|
|
18356
|
-
RESEARCH_RULE,
|
|
18357
|
-
EXPLAIN_RULE,
|
|
18358
|
-
IMPLEMENT_RULE
|
|
18359
|
-
];
|
|
18360
|
-
var EXECUTION_CONTRACT_INTENTS = new Set([
|
|
18361
|
-
"implement",
|
|
18362
|
-
"debug",
|
|
18363
|
-
"refactor",
|
|
18364
|
-
"review",
|
|
18365
|
-
"research",
|
|
18366
|
-
"docs",
|
|
18367
|
-
"test-fix"
|
|
18368
|
-
]);
|
|
18369
|
-
var STANDARD_INTENTS = new Set([
|
|
18370
|
-
"implement",
|
|
18371
|
-
"debug",
|
|
18372
|
-
"refactor",
|
|
18373
|
-
"review",
|
|
18374
|
-
"research",
|
|
18375
|
-
"docs",
|
|
18376
|
-
"test-fix"
|
|
18377
|
-
]);
|
|
18378
|
-
var DEEP_SIGNALS = [
|
|
18379
|
-
/\bcareful\b/,
|
|
18380
|
-
/\bdeep\b/,
|
|
18381
|
-
/\bthorough\b/,
|
|
18382
|
-
/\bhigh.?stakes?\b/,
|
|
18383
|
-
/\bproduction\b/,
|
|
18384
|
-
/\bcritical\b/,
|
|
18385
|
-
/\barchitecture\b/,
|
|
18386
|
-
/\bsecurity\b/
|
|
18387
|
-
];
|
|
18388
|
-
function detectTaskIntent(draft) {
|
|
18389
|
-
const normalized = normalizeDraft(draft);
|
|
18390
|
-
if (!normalized) {
|
|
18391
|
-
return "general";
|
|
18392
|
-
}
|
|
18393
|
-
for (const rule of STRONG_INTENT_RULES) {
|
|
18394
|
-
if (rule.patterns.some((pattern) => pattern.test(normalized))) {
|
|
18395
|
-
return rule.intent;
|
|
18396
|
-
}
|
|
18397
|
-
}
|
|
18398
|
-
return "general";
|
|
18399
|
-
}
|
|
18400
|
-
function resolveRewriteMode(configuredMode, intent) {
|
|
18401
|
-
if (configuredMode === "plain" || configuredMode === "execution-contract") {
|
|
18402
|
-
return configuredMode;
|
|
18403
|
-
}
|
|
18404
|
-
return EXECUTION_CONTRACT_INTENTS.has(intent) ? "execution-contract" : "plain";
|
|
18405
|
-
}
|
|
18406
|
-
function inferIntensity(draft, intent) {
|
|
18407
|
-
const normalized = normalizeDraft(draft);
|
|
18408
|
-
if (DEEP_SIGNALS.some((pattern) => pattern.test(normalized))) {
|
|
18409
|
-
return "Deep";
|
|
18410
|
-
}
|
|
18411
|
-
return STANDARD_INTENTS.has(intent) ? "Standard" : "Light";
|
|
18412
|
-
}
|
|
18413
|
-
function buildPromptLeverageBlocks(draft, intent, intensity) {
|
|
18414
|
-
return {
|
|
18415
|
-
objective: buildObjective(draft),
|
|
18416
|
-
context: buildContext(intent),
|
|
18417
|
-
workStyle: buildWorkStyle(intent, intensity),
|
|
18418
|
-
toolRules: buildToolRules(intent),
|
|
18419
|
-
outputContract: buildOutputContract(intent),
|
|
18420
|
-
verification: buildVerification(intent),
|
|
18421
|
-
doneCriteria: buildDoneCriteria(intent)
|
|
18422
|
-
};
|
|
18423
|
-
}
|
|
18424
|
-
function augmentPrompt(draft, options2 = {}) {
|
|
18425
|
-
const normalized = collapseWhitespace(draft);
|
|
18426
|
-
if (!normalized) {
|
|
18427
|
-
return {
|
|
18428
|
-
original: "",
|
|
18429
|
-
enhanced: "",
|
|
18430
|
-
intent: "general",
|
|
18431
|
-
mode: resolveRewriteMode(options2.mode ?? "auto", "general"),
|
|
18432
|
-
intensity: "Light",
|
|
18433
|
-
blocks: EMPTY_PROMPT_BLOCKS,
|
|
18434
|
-
enhancementSource: "deterministic"
|
|
18435
|
-
};
|
|
18436
|
-
}
|
|
18437
|
-
const intent = detectTaskIntent(normalized);
|
|
18438
|
-
const mode = resolveRewriteMode(options2.mode ?? "auto", intent);
|
|
18439
|
-
const intensity = inferIntensity(normalized, intent);
|
|
18440
|
-
const blocks = buildPromptLeverageBlocks(normalized, intent, intensity);
|
|
18441
|
-
return {
|
|
18442
|
-
original: normalized,
|
|
18443
|
-
intent,
|
|
18444
|
-
mode,
|
|
18445
|
-
intensity,
|
|
18446
|
-
blocks,
|
|
18447
|
-
enhanced: mode === "execution-contract" ? formatExecutionContract(normalized, blocks) : formatPlainRewrite(normalized, intent, blocks.outputContract),
|
|
18448
|
-
enhancementSource: "deterministic"
|
|
18449
|
-
};
|
|
18450
|
-
}
|
|
18451
|
-
async function augmentPromptWithRefinement(draft, options2 = {}) {
|
|
18452
|
-
const deterministic = augmentPrompt(draft, options2);
|
|
18453
|
-
if (!deterministic.original) {
|
|
18454
|
-
return deterministic;
|
|
18455
|
-
}
|
|
18456
|
-
if (!options2.refine) {
|
|
18457
|
-
return deterministic;
|
|
18458
|
-
}
|
|
18459
|
-
try {
|
|
18460
|
-
const refined = await options2.refine({
|
|
18461
|
-
original: deterministic.original,
|
|
18462
|
-
enhanced: deterministic.enhanced,
|
|
18463
|
-
intent: deterministic.intent,
|
|
18464
|
-
mode: deterministic.mode,
|
|
18465
|
-
intensity: deterministic.intensity,
|
|
18466
|
-
blocks: deterministic.blocks
|
|
18467
|
-
});
|
|
18468
|
-
const normalized = normalizeEnhancedPrompt(refined);
|
|
18469
|
-
if (!normalized) {
|
|
18470
|
-
return {
|
|
18471
|
-
...deterministic,
|
|
18472
|
-
fallbackReason: "LLM refinement returned empty output."
|
|
18473
|
-
};
|
|
18474
|
-
}
|
|
18475
|
-
return {
|
|
18476
|
-
...deterministic,
|
|
18477
|
-
enhanced: normalized,
|
|
18478
|
-
enhancementSource: "llm",
|
|
18479
|
-
fallbackReason: undefined
|
|
18480
|
-
};
|
|
18481
|
-
} catch (error45) {
|
|
18482
|
-
return {
|
|
18483
|
-
...deterministic,
|
|
18484
|
-
fallbackReason: error45 instanceof Error ? error45.message : "LLM refinement failed."
|
|
18485
|
-
};
|
|
18486
|
-
}
|
|
18487
|
-
}
|
|
18488
|
-
function formatExecutionContract(draft, blocks) {
|
|
18489
|
-
const task = stripObjectivePrefix(blocks.objective) || toSentence(draft);
|
|
18490
|
-
return [
|
|
18491
|
-
wrapTag("task", task),
|
|
18492
|
-
wrapTag("context", bulletize(blocks.context)),
|
|
18493
|
-
wrapTag("constraints", bulletize([blocks.workStyle, blocks.toolRules].filter(Boolean).join(`
|
|
18494
|
-
`))),
|
|
18495
|
-
wrapTag("verification", bulletize(blocks.verification)),
|
|
18496
|
-
wrapTag("deliverable", [blocks.outputContract, blocks.doneCriteria].filter(Boolean).join(`
|
|
18497
|
-
`))
|
|
18498
|
-
].join(`
|
|
18499
|
-
|
|
18500
|
-
`);
|
|
18501
|
-
}
|
|
18502
|
-
function formatPlainRewrite(draft, intent, outputContract) {
|
|
18503
|
-
const sentence = toSentence(draft);
|
|
18504
|
-
if (intent === "explain") {
|
|
18505
|
-
return [
|
|
18506
|
-
sentence,
|
|
18507
|
-
"Keep the explanation clear and well-structured without turning it into an execution plan."
|
|
18508
|
-
].join(" ");
|
|
18509
|
-
}
|
|
18510
|
-
if (intent === "general") {
|
|
18511
|
-
return [
|
|
18512
|
-
sentence,
|
|
18513
|
-
"Return a clear, well-structured response matched to the task. Keep it concise unless extra detail is necessary."
|
|
18514
|
-
].join(" ");
|
|
18515
|
-
}
|
|
18516
|
-
return [sentence, outputContract].join(" ");
|
|
18517
|
-
}
|
|
18518
|
-
function buildObjective(draft) {
|
|
18519
|
-
return `Complete this task: ${toSentence(draft)}`;
|
|
18520
|
-
}
|
|
18521
|
-
function buildContext(intent) {
|
|
18522
|
-
switch (intent) {
|
|
18523
|
-
case "implement":
|
|
18524
|
-
return [
|
|
18525
|
-
"Review the current code path and identify the narrowest safe integration point.",
|
|
18526
|
-
"Preserve existing behavior outside the requested change."
|
|
18527
|
-
].join(`
|
|
18528
|
-
`);
|
|
18529
|
-
case "debug":
|
|
18530
|
-
return [
|
|
18531
|
-
"Reproduce the issue first and confirm the failing path before editing.",
|
|
18532
|
-
"Inspect the code and data flow around the suspected failure point."
|
|
18533
|
-
].join(`
|
|
18534
|
-
`);
|
|
18535
|
-
case "refactor":
|
|
18536
|
-
return [
|
|
18537
|
-
"Map the current structure before extracting or consolidating logic.",
|
|
18538
|
-
"Identify duplication and branching that can be simplified without changing behavior."
|
|
18539
|
-
].join(`
|
|
18540
|
-
`);
|
|
18541
|
-
case "review":
|
|
18542
|
-
return [
|
|
18543
|
-
"Read enough surrounding context to understand intent before critiquing.",
|
|
18544
|
-
"Focus on confirmed issues first, then call out plausible risks separately."
|
|
18545
|
-
].join(`
|
|
18546
|
-
`);
|
|
18547
|
-
case "research":
|
|
18548
|
-
return [
|
|
18549
|
-
"Gather evidence from authoritative sources before concluding.",
|
|
18550
|
-
"Preserve uncertainty explicitly when the evidence is incomplete or conflicting."
|
|
18551
|
-
].join(`
|
|
18552
|
-
`);
|
|
18553
|
-
case "docs":
|
|
18554
|
-
return [
|
|
18555
|
-
"Read the current behavior and documentation surface before rewriting anything.",
|
|
18556
|
-
"Keep commands, examples, and terminology aligned with the actual system."
|
|
18557
|
-
].join(`
|
|
18558
|
-
`);
|
|
18559
|
-
case "test-fix":
|
|
18560
|
-
return [
|
|
18561
|
-
"Decide whether the test, the implementation, or both are wrong before changing anything.",
|
|
18562
|
-
"Keep regression coverage close to the observed failure mode."
|
|
18563
|
-
].join(`
|
|
18564
|
-
`);
|
|
18565
|
-
case "explain":
|
|
18566
|
-
return [
|
|
18567
|
-
"Preserve the original question and answer it directly.",
|
|
18568
|
-
"Use structure only when it improves clarity."
|
|
18569
|
-
].join(`
|
|
18570
|
-
`);
|
|
18571
|
-
case "general":
|
|
18572
|
-
default:
|
|
18573
|
-
return [
|
|
18574
|
-
"Preserve the user\u2019s intent and constraints.",
|
|
18575
|
-
"Add only enough structure to improve clarity and usefulness."
|
|
18576
|
-
].join(`
|
|
18577
|
-
`);
|
|
18578
|
-
}
|
|
18579
|
-
}
|
|
18580
|
-
function buildWorkStyle(intent, intensity) {
|
|
18581
|
-
const guidance = [];
|
|
18582
|
-
switch (intent) {
|
|
18583
|
-
case "implement":
|
|
18584
|
-
guidance.push("Understand the problem broadly enough to avoid narrow mistakes, then go deep where the risk is highest.");
|
|
18585
|
-
guidance.push("Use first-principles reasoning before proposing changes.");
|
|
18586
|
-
break;
|
|
18587
|
-
case "debug":
|
|
18588
|
-
guidance.push("Inspect before editing and find the root cause, not just the symptom.");
|
|
18589
|
-
break;
|
|
18590
|
-
case "refactor":
|
|
18591
|
-
guidance.push("Preserve behavior while reducing duplication, branching, or complexity.");
|
|
18592
|
-
break;
|
|
18593
|
-
case "review":
|
|
18594
|
-
guidance.push("Distinguish confirmed issues from plausible risks and order them by impact.");
|
|
18595
|
-
break;
|
|
18596
|
-
case "research":
|
|
18597
|
-
guidance.push("Synthesize evidence into a recommendation instead of a raw note dump.");
|
|
18598
|
-
break;
|
|
18599
|
-
case "docs":
|
|
18600
|
-
guidance.push("Optimize for accuracy, clarity, and examples that match real behavior.");
|
|
18601
|
-
break;
|
|
18602
|
-
case "test-fix":
|
|
18603
|
-
guidance.push("Keep changes focused on the failing behavior and preserve useful coverage.");
|
|
18604
|
-
break;
|
|
18605
|
-
case "explain":
|
|
18606
|
-
guidance.push("Stay explanatory and avoid turning the answer into an execution plan.");
|
|
18607
|
-
break;
|
|
18608
|
-
case "general":
|
|
18609
|
-
guidance.push("Be specific, structured, and proportionate to the request.");
|
|
18610
|
-
break;
|
|
18611
|
-
}
|
|
18612
|
-
if (intensity === "Deep") {
|
|
18613
|
-
guidance.push("Review the result once with fresh eyes before finalizing.");
|
|
18614
|
-
}
|
|
18615
|
-
if (intensity === "Standard") {
|
|
18616
|
-
guidance.push("Cover the main edge cases before finalizing.");
|
|
18617
|
-
}
|
|
18618
|
-
return guidance.join(`
|
|
18619
|
-
`);
|
|
18620
|
-
}
|
|
18621
|
-
function buildToolRules(intent) {
|
|
18622
|
-
switch (intent) {
|
|
18623
|
-
case "implement":
|
|
18624
|
-
case "refactor":
|
|
18625
|
-
case "debug":
|
|
18626
|
-
case "test-fix":
|
|
18627
|
-
return "Inspect the relevant files and dependencies first. Validate the final change with the narrowest useful checks before broadening scope.";
|
|
18628
|
-
case "research":
|
|
18629
|
-
return "Retrieve evidence from reliable sources before concluding. Do not guess facts that can be checked.";
|
|
18630
|
-
case "review":
|
|
18631
|
-
return "Read enough surrounding context to understand intent before critiquing. Distinguish confirmed issues from plausible risks.";
|
|
18632
|
-
case "docs":
|
|
18633
|
-
return "Read the current documentation and runtime behavior before rewriting. Keep examples and commands accurate.";
|
|
18634
|
-
case "explain":
|
|
18635
|
-
case "general":
|
|
18636
|
-
default:
|
|
18637
|
-
return "Use extra tools or context only when they materially improve correctness or completeness.";
|
|
18638
|
-
}
|
|
18639
|
-
}
|
|
18640
|
-
function buildOutputContract(intent) {
|
|
18641
|
-
switch (intent) {
|
|
18642
|
-
case "implement":
|
|
18643
|
-
case "refactor":
|
|
18644
|
-
case "test-fix":
|
|
18645
|
-
return "Return a practical execution result: concise summary, concrete changes, validation notes, and any remaining risks.";
|
|
18646
|
-
case "debug":
|
|
18647
|
-
return "Return a diagnosis with root cause, the fix, validation steps, and regression notes.";
|
|
18648
|
-
case "research":
|
|
18649
|
-
return "Return a structured synthesis with key findings, supporting evidence, and a concise recommendation.";
|
|
18650
|
-
case "docs":
|
|
18651
|
-
return "Return polished documentation aligned with current runtime behavior and verified examples.";
|
|
18652
|
-
case "review":
|
|
18653
|
-
return "Return findings grouped by severity or importance, explain why each matters, and suggest the smallest credible next step.";
|
|
18654
|
-
case "explain":
|
|
18655
|
-
return "Return a clear, well-structured explanation matched to the question.";
|
|
18656
|
-
case "general":
|
|
18657
|
-
default:
|
|
18658
|
-
return "Return a clear, well-structured response matched to the task.";
|
|
18659
|
-
}
|
|
18660
|
-
}
|
|
18661
|
-
function buildVerification(intent) {
|
|
18662
|
-
switch (intent) {
|
|
18663
|
-
case "implement":
|
|
18664
|
-
case "refactor":
|
|
18665
|
-
case "test-fix":
|
|
18666
|
-
return [
|
|
18667
|
-
"Check correctness, completeness, and edge cases.",
|
|
18668
|
-
"Run relevant checks such as tests, lint, or typecheck when appropriate."
|
|
18669
|
-
].join(`
|
|
18670
|
-
`);
|
|
18671
|
-
case "debug":
|
|
18672
|
-
return [
|
|
18673
|
-
"Check correctness, completeness, and edge cases.",
|
|
18674
|
-
"Confirm the root cause is addressed and add regression coverage when appropriate."
|
|
18675
|
-
].join(`
|
|
18676
|
-
`);
|
|
18677
|
-
case "review":
|
|
18678
|
-
return [
|
|
18679
|
-
"Check correctness and completeness.",
|
|
18680
|
-
"Avoid speculative redesign unless it is necessary to explain a risk."
|
|
18681
|
-
].join(`
|
|
18682
|
-
`);
|
|
18683
|
-
case "docs":
|
|
18684
|
-
return [
|
|
18685
|
-
"Check correctness and completeness.",
|
|
18686
|
-
"Verify commands, examples, and terminology against the current behavior."
|
|
18687
|
-
].join(`
|
|
18688
|
-
`);
|
|
18689
|
-
case "research":
|
|
18690
|
-
return [
|
|
18691
|
-
"Check correctness, completeness, and edge cases.",
|
|
18692
|
-
"Call out uncertainty explicitly when evidence is incomplete or conflicting."
|
|
18693
|
-
].join(`
|
|
18694
|
-
`);
|
|
18695
|
-
case "explain":
|
|
18696
|
-
case "general":
|
|
18697
|
-
default:
|
|
18698
|
-
return [
|
|
18699
|
-
"Check correctness, completeness, and edge cases.",
|
|
18700
|
-
"Improve obvious weaknesses if a better phrasing is available within scope."
|
|
18701
|
-
].join(`
|
|
18702
|
-
`);
|
|
18703
|
-
}
|
|
18704
|
-
}
|
|
18705
|
-
function buildDoneCriteria(intent) {
|
|
18706
|
-
switch (intent) {
|
|
18707
|
-
case "implement":
|
|
18708
|
-
case "refactor":
|
|
18709
|
-
case "test-fix":
|
|
18710
|
-
return "Stop only when the change is complete, the important checks pass, and there are no known regressions.";
|
|
18711
|
-
case "debug":
|
|
18712
|
-
return "Stop only when the root cause is confirmed fixed and regression coverage is in place when appropriate.";
|
|
18713
|
-
case "review":
|
|
18714
|
-
return "Stop only when the findings are clear, prioritized, and actionable.";
|
|
18715
|
-
case "research":
|
|
18716
|
-
return "Stop only when the synthesis is grounded in evidence and ends with a recommended path.";
|
|
18717
|
-
case "docs":
|
|
18718
|
-
return "Stop only when the documentation matches the current behavior and examples are accurate.";
|
|
18719
|
-
case "explain":
|
|
18720
|
-
return "Stop only when the explanation clearly answers the question.";
|
|
18721
|
-
case "general":
|
|
18722
|
-
default:
|
|
18723
|
-
return "Stop only when the response satisfies the task and matches the requested format.";
|
|
18724
|
-
}
|
|
18725
|
-
}
|
|
18726
|
-
function bulletize(text) {
|
|
18727
|
-
return text.split(`
|
|
18728
|
-
`).map((line) => collapseWhitespace(line)).filter(Boolean).map((line) => `- ${line}`).join(`
|
|
18729
|
-
`);
|
|
18730
|
-
}
|
|
18731
|
-
function wrapTag(tagName, content) {
|
|
18732
|
-
return `<${tagName}>
|
|
18733
|
-
${content}
|
|
18734
|
-
</${tagName}>`;
|
|
18735
|
-
}
|
|
18736
|
-
function stripObjectivePrefix(objective) {
|
|
18737
|
-
return objective.replace(/^Complete this task:\s*/i, "").trim();
|
|
18738
|
-
}
|
|
18739
|
-
function normalizeDraft(draft) {
|
|
18740
|
-
return collapseWhitespace(draft).toLowerCase();
|
|
18741
|
-
}
|
|
18742
|
-
function normalizeEnhancedPrompt(value) {
|
|
18743
|
-
return (value ?? "").replace(/\r\n/g, `
|
|
18744
|
-
`).trim();
|
|
18745
|
-
}
|
|
18746
|
-
function collapseWhitespace(value) {
|
|
18747
|
-
return value.replace(/\r\n/g, `
|
|
18748
|
-
`).replace(/\s+/g, " ").trim();
|
|
18749
|
-
}
|
|
18750
|
-
function toSentence(value) {
|
|
18751
|
-
const normalized = collapseWhitespace(value);
|
|
18752
|
-
if (!normalized) {
|
|
18753
|
-
return "";
|
|
18754
|
-
}
|
|
18755
|
-
const capitalized = normalized.charAt(0).toUpperCase() + normalized.slice(1);
|
|
18756
|
-
if (/[.!?]$/.test(capitalized)) {
|
|
18757
|
-
return capitalized;
|
|
18758
|
-
}
|
|
18759
|
-
return `${capitalized}.`;
|
|
18760
|
-
}
|
|
18761
|
-
|
|
18762
18250
|
// src/tools/context-summary.ts
|
|
18763
18251
|
function parseStringArray(value) {
|
|
18764
18252
|
if (typeof value !== "string" || !value.trim()) {
|
|
@@ -18857,7 +18345,6 @@ function buildSummary(sections, maxTokens) {
|
|
|
18857
18345
|
var execFileAsync3 = promisify3(execFile3);
|
|
18858
18346
|
var DCP_PLUGIN_ENTRY2 = "@tarquinen/opencode-dcp@beta";
|
|
18859
18347
|
var DCP_PLUGIN_BASE = "@tarquinen/opencode-dcp";
|
|
18860
|
-
var AUGMENT_LOADING_TEXT = "Enhancing prompt.";
|
|
18861
18348
|
function ensureDcpInConfig() {
|
|
18862
18349
|
try {
|
|
18863
18350
|
const configDir = (() => {
|
|
@@ -18995,115 +18482,6 @@ var CliKitPlugin = async (ctx) => {
|
|
|
18995
18482
|
return false;
|
|
18996
18483
|
}
|
|
18997
18484
|
}
|
|
18998
|
-
function getWorkspaceFromPayload(payload) {
|
|
18999
|
-
if (!payload || typeof payload !== "object") {
|
|
19000
|
-
return;
|
|
19001
|
-
}
|
|
19002
|
-
const workspace = payload.workspace;
|
|
19003
|
-
return typeof workspace === "string" && workspace.trim() ? workspace : undefined;
|
|
19004
|
-
}
|
|
19005
|
-
function stripAugmentSlashCommand(value) {
|
|
19006
|
-
const normalized = value.replace(/\r\n/g, `
|
|
19007
|
-
`).trim();
|
|
19008
|
-
return normalized.replace(/^\/augment(?:\s+|$)/i, "").trim();
|
|
19009
|
-
}
|
|
19010
|
-
async function injectPromptIntoTuiDetailed(prompt, workspace) {
|
|
19011
|
-
const tuiClient = getTuiClient();
|
|
19012
|
-
if (!tuiClient?.appendPrompt) {
|
|
19013
|
-
return { ok: false };
|
|
19014
|
-
}
|
|
19015
|
-
try {
|
|
19016
|
-
if (tuiClient.clearPrompt) {
|
|
19017
|
-
await tuiClient.clearPrompt({
|
|
19018
|
-
directory: ctx.directory,
|
|
19019
|
-
workspace
|
|
19020
|
-
});
|
|
19021
|
-
}
|
|
19022
|
-
await tuiClient.appendPrompt({
|
|
19023
|
-
directory: ctx.directory,
|
|
19024
|
-
workspace,
|
|
19025
|
-
text: prompt
|
|
19026
|
-
});
|
|
19027
|
-
return { ok: true };
|
|
19028
|
-
} catch (error45) {
|
|
19029
|
-
return {
|
|
19030
|
-
ok: false,
|
|
19031
|
-
error: error45 instanceof Error ? error45.message : "Unable to update the TUI composer."
|
|
19032
|
-
};
|
|
19033
|
-
}
|
|
19034
|
-
}
|
|
19035
|
-
async function injectPromptIntoTui(prompt, workspace) {
|
|
19036
|
-
const result = await injectPromptIntoTuiDetailed(prompt, workspace);
|
|
19037
|
-
return result.ok;
|
|
19038
|
-
}
|
|
19039
|
-
function replaceCommandTextPart(parts, text) {
|
|
19040
|
-
const firstTextPart = parts.find((part) => part.type === "text");
|
|
19041
|
-
if (!firstTextPart || typeof firstTextPart.text !== "string") {
|
|
19042
|
-
return false;
|
|
19043
|
-
}
|
|
19044
|
-
firstTextPart.text = text;
|
|
19045
|
-
parts.splice(0, parts.length, firstTextPart);
|
|
19046
|
-
return true;
|
|
19047
|
-
}
|
|
19048
|
-
async function enhanceDraftPrompt(draft, mode = "auto") {
|
|
19049
|
-
const sessionClient = getSessionClient();
|
|
19050
|
-
return augmentPromptWithRefinement(draft, {
|
|
19051
|
-
mode,
|
|
19052
|
-
refine: sessionClient ? async ({ enhanced, mode: resolvedMode, intent, intensity }) => {
|
|
19053
|
-
const createResult = await sessionClient.create({
|
|
19054
|
-
directory: ctx.directory,
|
|
19055
|
-
title: `augment:${intent}`
|
|
19056
|
-
});
|
|
19057
|
-
if (createResult.error || !createResult.data?.id) {
|
|
19058
|
-
throw new Error("Unable to create OpenCode session for prompt enhancement.");
|
|
19059
|
-
}
|
|
19060
|
-
const sessionID = createResult.data.id;
|
|
19061
|
-
try {
|
|
19062
|
-
const refinementPrompt = [
|
|
19063
|
-
"You are refining an already-structured prompt for OpenCode.",
|
|
19064
|
-
`Intent: ${intent}`,
|
|
19065
|
-
`Rewrite mode: ${resolvedMode}`,
|
|
19066
|
-
`Effort: ${intensity}`,
|
|
19067
|
-
"Preserve the original user request exactly.",
|
|
19068
|
-
"Keep the output as a single prompt only.",
|
|
19069
|
-
"Do not add commentary, preambles, markdown fences, or explanations.",
|
|
19070
|
-
"If the prompt is already strong, return a minimally polished version.",
|
|
19071
|
-
"Return only the final rewritten prompt.",
|
|
19072
|
-
"",
|
|
19073
|
-
enhanced
|
|
19074
|
-
].join(`
|
|
19075
|
-
`);
|
|
19076
|
-
const promptResult = await sessionClient.prompt({
|
|
19077
|
-
sessionID,
|
|
19078
|
-
directory: ctx.directory,
|
|
19079
|
-
parts: [
|
|
19080
|
-
{
|
|
19081
|
-
type: "text",
|
|
19082
|
-
text: refinementPrompt
|
|
19083
|
-
}
|
|
19084
|
-
]
|
|
19085
|
-
});
|
|
19086
|
-
if (promptResult.error) {
|
|
19087
|
-
throw new Error("OpenCode prompt enhancement request failed.");
|
|
19088
|
-
}
|
|
19089
|
-
const textPart = promptResult.data?.parts?.find((part) => part.type === "text");
|
|
19090
|
-
if (!textPart || !("text" in textPart) || typeof textPart.text !== "string") {
|
|
19091
|
-
throw new Error("OpenCode prompt enhancement returned no text output.");
|
|
19092
|
-
}
|
|
19093
|
-
return textPart.text;
|
|
19094
|
-
} finally {
|
|
19095
|
-
if (sessionClient.delete) {
|
|
19096
|
-
sessionClient.delete({
|
|
19097
|
-
sessionID,
|
|
19098
|
-
directory: ctx.directory
|
|
19099
|
-
}).catch(() => {
|
|
19100
|
-
return;
|
|
19101
|
-
});
|
|
19102
|
-
}
|
|
19103
|
-
}
|
|
19104
|
-
} : undefined
|
|
19105
|
-
});
|
|
19106
|
-
}
|
|
19107
18485
|
function normalizeTodos(rawTodos) {
|
|
19108
18486
|
if (!Array.isArray(rawTodos)) {
|
|
19109
18487
|
return [];
|
|
@@ -19351,49 +18729,6 @@ ${(content || "").trim()}`.trim();
|
|
|
19351
18729
|
}
|
|
19352
18730
|
return {
|
|
19353
18731
|
tool: {
|
|
19354
|
-
augment_prompt: tool({
|
|
19355
|
-
description: "Rewrite a draft prompt into a stronger, intent-aware prompt for user review.",
|
|
19356
|
-
args: {
|
|
19357
|
-
draft: tool.schema.string().optional().describe("Draft prompt to enhance before sending to the model."),
|
|
19358
|
-
mode: tool.schema.enum(["auto", "plain", "execution-contract"]).optional().describe("Optional rewrite mode override (default: auto).")
|
|
19359
|
-
},
|
|
19360
|
-
async execute(args) {
|
|
19361
|
-
const draft = typeof args.draft === "string" ? stripAugmentSlashCommand(args.draft) : "";
|
|
19362
|
-
if (!draft) {
|
|
19363
|
-
return JSON.stringify({
|
|
19364
|
-
success: true,
|
|
19365
|
-
skipped: true,
|
|
19366
|
-
original: "",
|
|
19367
|
-
enhanced: "",
|
|
19368
|
-
intent: "general",
|
|
19369
|
-
mode: "plain",
|
|
19370
|
-
intensity: "Light",
|
|
19371
|
-
injectedIntoTui: false
|
|
19372
|
-
}, null, 2);
|
|
19373
|
-
}
|
|
19374
|
-
await showToast("Enhancing prompt\u2026", "info", "CliKit Augment");
|
|
19375
|
-
const mode = args.mode === "plain" || args.mode === "execution-contract" ? args.mode : "auto";
|
|
19376
|
-
const result = await enhanceDraftPrompt(draft, mode);
|
|
19377
|
-
const injectedIntoTui = await injectPromptIntoTui(result.enhanced);
|
|
19378
|
-
const completionTitle = "CliKit Augment";
|
|
19379
|
-
if (result.fallbackReason) {
|
|
19380
|
-
await showToast(injectedIntoTui ? `Injected deterministic fallback. ${result.fallbackReason}` : `Using deterministic fallback. ${result.fallbackReason}`, "warning", completionTitle);
|
|
19381
|
-
} else {
|
|
19382
|
-
await showToast(injectedIntoTui ? `Enhanced prompt inserted (${result.enhancementSource ?? "deterministic"}).` : `Enhanced prompt ready (${result.enhancementSource ?? "deterministic"}).`, "success", completionTitle);
|
|
19383
|
-
}
|
|
19384
|
-
return JSON.stringify({
|
|
19385
|
-
success: true,
|
|
19386
|
-
original: result.original,
|
|
19387
|
-
enhanced: result.enhanced,
|
|
19388
|
-
intent: result.intent,
|
|
19389
|
-
mode: result.mode,
|
|
19390
|
-
intensity: result.intensity,
|
|
19391
|
-
injectedIntoTui,
|
|
19392
|
-
enhancementSource: result.enhancementSource,
|
|
19393
|
-
fallbackReason: result.fallbackReason
|
|
19394
|
-
}, null, 2);
|
|
19395
|
-
}
|
|
19396
|
-
}),
|
|
19397
18732
|
context_summary: tool({
|
|
19398
18733
|
description: "Summarize memory observations (decisions, learnings, blockers, progress) into a structured context digest. Useful for compaction or session handoff.",
|
|
19399
18734
|
args: {
|
|
@@ -19619,47 +18954,6 @@ ${(content || "").trim()}`.trim();
|
|
|
19619
18954
|
}
|
|
19620
18955
|
}
|
|
19621
18956
|
},
|
|
19622
|
-
"command.execute.before": async (input, output) => {
|
|
19623
|
-
if (!isToolNamed(input.command, "augment")) {
|
|
19624
|
-
return;
|
|
19625
|
-
}
|
|
19626
|
-
const workspace = getWorkspaceFromPayload(input);
|
|
19627
|
-
const draft = stripAugmentSlashCommand(input.arguments);
|
|
19628
|
-
if (!draft) {
|
|
19629
|
-
return;
|
|
19630
|
-
}
|
|
19631
|
-
await showToastForWorkspace(AUGMENT_LOADING_TEXT, "info", "CliKit Augment", workspace);
|
|
19632
|
-
const loadingInjection = await injectPromptIntoTuiDetailed(AUGMENT_LOADING_TEXT, workspace);
|
|
19633
|
-
const showedComposerLoading = loadingInjection.ok;
|
|
19634
|
-
try {
|
|
19635
|
-
const result = await enhanceDraftPrompt(draft, "auto");
|
|
19636
|
-
const finalInjection = await injectPromptIntoTuiDetailed(result.enhanced, workspace);
|
|
19637
|
-
const injectedIntoTui = finalInjection.ok;
|
|
19638
|
-
if (showedComposerLoading && !injectedIntoTui) {
|
|
19639
|
-
await injectPromptIntoTui(draft, workspace);
|
|
19640
|
-
await showToastForWorkspace(finalInjection.error ?? "Unable to replace the composer with the enhanced prompt.", "error", "CliKit Augment", workspace);
|
|
19641
|
-
return;
|
|
19642
|
-
}
|
|
19643
|
-
if (result.fallbackReason) {
|
|
19644
|
-
await showToastForWorkspace(injectedIntoTui ? `Replaced composer with deterministic fallback. ${result.fallbackReason}` : `Using deterministic fallback. ${result.fallbackReason}`, "warning", "CliKit Augment", workspace);
|
|
19645
|
-
} else {
|
|
19646
|
-
await showToastForWorkspace(injectedIntoTui ? `Enhanced prompt replaced in composer (${result.enhancementSource ?? "deterministic"}).` : `Enhanced prompt ready (${result.enhancementSource ?? "deterministic"}).`, "success", "CliKit Augment", workspace);
|
|
19647
|
-
}
|
|
19648
|
-
const replacementText = injectedIntoTui ? [
|
|
19649
|
-
"CliKit already handled the /augment command locally and updated the composer.",
|
|
19650
|
-
"Do not execute the original user request.",
|
|
19651
|
-
"Reply with exactly: Composer updated."
|
|
19652
|
-
].join(`
|
|
19653
|
-
`) : result.enhanced;
|
|
19654
|
-
replaceCommandTextPart(output.parts, replacementText);
|
|
19655
|
-
} catch (error45) {
|
|
19656
|
-
if (showedComposerLoading) {
|
|
19657
|
-
await injectPromptIntoTui(draft, workspace);
|
|
19658
|
-
}
|
|
19659
|
-
const message = error45 instanceof Error ? error45.message : "Prompt enhancement failed.";
|
|
19660
|
-
await showToastForWorkspace(message, "error", "CliKit Augment", workspace);
|
|
19661
|
-
}
|
|
19662
|
-
},
|
|
19663
18957
|
"tool.execute.before": async (input, output) => {
|
|
19664
18958
|
const toolName = input.tool;
|
|
19665
18959
|
const sessionID = input.sessionID;
|