|
| 1 | +#!/usr/bin/env npx tsx |
| 2 | + |
| 3 | +import { renderSystemPrompt, renderNudge, type ToolFlags } from "../lib/prompts/index.js" |
| 4 | +import { |
| 5 | + wrapPrunableTools, |
| 6 | + wrapCompressContext, |
| 7 | + wrapCooldownMessage, |
| 8 | +} from "../lib/messages/inject.js" |
| 9 | + |
| 10 | +const args = process.argv.slice(2) |
| 11 | + |
| 12 | +const flags: ToolFlags = { |
| 13 | + prune: args.includes("-p") || args.includes("--prune"), |
| 14 | + distill: args.includes("-d") || args.includes("--distill"), |
| 15 | + compress: args.includes("-c") || args.includes("--compress"), |
| 16 | +} |
| 17 | + |
| 18 | +// Default to all enabled if none specified |
| 19 | +if (!flags.prune && !flags.distill && !flags.compress) { |
| 20 | + flags.prune = true |
| 21 | + flags.distill = true |
| 22 | + flags.compress = true |
| 23 | +} |
| 24 | + |
| 25 | +const showSystem = args.includes("--system") |
| 26 | +const showNudge = args.includes("--nudge") |
| 27 | +const showPruneList = args.includes("--prune-list") |
| 28 | +const showCompressContext = args.includes("--compress-context") |
| 29 | +const showCooldown = args.includes("--cooldown") |
| 30 | +const showHelp = args.includes("--help") || args.includes("-h") |
| 31 | + |
| 32 | +if ( |
| 33 | + showHelp || |
| 34 | + (!showSystem && !showNudge && !showPruneList && !showCompressContext && !showCooldown) |
| 35 | +) { |
| 36 | + console.log(` |
| 37 | +Usage: bun run dcp [TYPE] [-p] [-d] [-c] |
| 38 | +
|
| 39 | +Types: |
| 40 | + --system System prompt |
| 41 | + --nudge Nudge prompt |
| 42 | + --prune-list Example prunable tools list |
| 43 | + --compress-context Example compress context |
| 44 | + --cooldown Cooldown message after pruning |
| 45 | +
|
| 46 | +Tool flags (for --system and --nudge): |
| 47 | + -p, --prune Enable prune tool |
| 48 | + -d, --distill Enable distill tool |
| 49 | + -c, --compress Enable compress tool |
| 50 | +
|
| 51 | +If no tool flags specified, all are enabled. |
| 52 | +
|
| 53 | +Examples: |
| 54 | + bun run dcp --system -p -d -c # System prompt with all tools |
| 55 | + bun run dcp --system -p # System prompt with prune only |
| 56 | + bun run dcp --nudge -d -c # Nudge with distill and compress |
| 57 | + bun run dcp --prune-list # Example prunable tools list |
| 58 | +`) |
| 59 | + process.exit(0) |
| 60 | +} |
| 61 | + |
| 62 | +const header = (title: string) => { |
| 63 | + console.log() |
| 64 | + console.log("─".repeat(60)) |
| 65 | + console.log(title) |
| 66 | + console.log("─".repeat(60)) |
| 67 | +} |
| 68 | + |
| 69 | +if (showSystem) { |
| 70 | + const enabled = [ |
| 71 | + flags.prune && "prune", |
| 72 | + flags.distill && "distill", |
| 73 | + flags.compress && "compress", |
| 74 | + ] |
| 75 | + .filter(Boolean) |
| 76 | + .join(", ") |
| 77 | + header(`SYSTEM PROMPT (tools: ${enabled})`) |
| 78 | + console.log(renderSystemPrompt(flags)) |
| 79 | +} |
| 80 | + |
| 81 | +if (showNudge) { |
| 82 | + const enabled = [ |
| 83 | + flags.prune && "prune", |
| 84 | + flags.distill && "distill", |
| 85 | + flags.compress && "compress", |
| 86 | + ] |
| 87 | + .filter(Boolean) |
| 88 | + .join(", ") |
| 89 | + header(`NUDGE (tools: ${enabled})`) |
| 90 | + console.log(renderNudge(flags)) |
| 91 | +} |
| 92 | + |
| 93 | +if (showPruneList) { |
| 94 | + header("PRUNABLE TOOLS LIST (mock example)") |
| 95 | + const mockList = `5: read, /path/to/file.ts |
| 96 | +8: bash, npm run build |
| 97 | +12: glob, src/**/*.ts |
| 98 | +15: read, /path/to/another-file.ts` |
| 99 | + console.log(wrapPrunableTools(mockList)) |
| 100 | +} |
| 101 | + |
| 102 | +if (showCompressContext) { |
| 103 | + header("COMPRESS CONTEXT (mock example)") |
| 104 | + console.log(wrapCompressContext(45)) |
| 105 | +} |
| 106 | + |
| 107 | +if (showCooldown) { |
| 108 | + const enabled = [ |
| 109 | + flags.prune && "prune", |
| 110 | + flags.distill && "distill", |
| 111 | + flags.compress && "compress", |
| 112 | + ] |
| 113 | + .filter(Boolean) |
| 114 | + .join(", ") |
| 115 | + header(`COOLDOWN MESSAGE (tools: ${enabled})`) |
| 116 | + console.log(wrapCooldownMessage(flags)) |
| 117 | +} |
0 commit comments